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/if_ether.h>
19 #include <linux/skbuff.h>
20 #include <linux/netdevice.h>
21 #include <linux/if_arp.h>
22 #include <linux/wireless.h>
23 #include <linux/random.h>
24 #include <net/iw_handler.h>
25 #include <asm/types.h>
26 #include <asm/delay.h>
28 #include <net/d80211.h>
29 #include "ieee80211_i.h"
30 #include "ieee80211_rate.h"
31 #include "hostapd_ioctl.h"
33 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
34 #define IEEE80211_AUTH_MAX_TRIES 3
35 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
36 #define IEEE80211_ASSOC_MAX_TRIES 3
37 #define IEEE80211_MONITORING_INTERVAL (2 * HZ)
38 #define IEEE80211_PROBE_INTERVAL (60 * HZ)
39 #define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
40 #define IEEE80211_SCAN_INTERVAL (2 * HZ)
41 #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ)
42 #define IEEE80211_IBSS_JOIN_TIMEOUT (20 * HZ)
44 #define IEEE80211_PROBE_DELAY (HZ / 33)
45 #define IEEE80211_CHANNEL_TIME (HZ / 33)
46 #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5)
47 #define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ)
48 #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
49 #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
51 #define IEEE80211_IBSS_MAX_STA_ENTRIES 128
54 #define IEEE80211_FC(type, stype) cpu_to_le16(type | stype)
56 #define ERP_INFO_USE_PROTECTION BIT(1)
58 static void ieee80211_send_probe_req(struct net_device
*dev
, u8
*dst
,
59 u8
*ssid
, size_t ssid_len
);
60 static struct ieee80211_sta_bss
*
61 ieee80211_rx_bss_get(struct net_device
*dev
, u8
*bssid
);
62 static void ieee80211_rx_bss_put(struct net_device
*dev
,
63 struct ieee80211_sta_bss
*bss
);
64 static int ieee80211_sta_find_ibss(struct net_device
*dev
,
65 struct ieee80211_if_sta
*ifsta
);
66 static int ieee80211_sta_wep_configured(struct net_device
*dev
);
69 /* Parsed Information Elements */
70 struct ieee802_11_elems
{
94 u8 ext_supp_rates_len
;
101 typedef enum { ParseOK
= 0, ParseUnknown
= 1, ParseFailed
= -1 } ParseRes
;
104 static ParseRes
ieee802_11_parse_elems(u8
*start
, size_t len
,
105 struct ieee802_11_elems
*elems
)
111 memset(elems
, 0, sizeof(*elems
));
123 printk(KERN_DEBUG
"IEEE 802.11 element parse "
124 "failed (id=%d elen=%d left=%d)\n",
133 elems
->ssid_len
= elen
;
135 case WLAN_EID_SUPP_RATES
:
136 elems
->supp_rates
= pos
;
137 elems
->supp_rates_len
= elen
;
139 case WLAN_EID_FH_PARAMS
:
140 elems
->fh_params
= pos
;
141 elems
->fh_params_len
= elen
;
143 case WLAN_EID_DS_PARAMS
:
144 elems
->ds_params
= pos
;
145 elems
->ds_params_len
= elen
;
147 case WLAN_EID_CF_PARAMS
:
148 elems
->cf_params
= pos
;
149 elems
->cf_params_len
= elen
;
153 elems
->tim_len
= elen
;
155 case WLAN_EID_IBSS_PARAMS
:
156 elems
->ibss_params
= pos
;
157 elems
->ibss_params_len
= elen
;
159 case WLAN_EID_CHALLENGE
:
160 elems
->challenge
= pos
;
161 elems
->challenge_len
= elen
;
164 if (elen
>= 4 && pos
[0] == 0x00 && pos
[1] == 0x50 &&
166 /* Microsoft OUI (00:50:F2) */
168 /* OUI Type 1 - WPA IE */
170 elems
->wpa_len
= elen
;
171 } else if (elen
>= 5 && pos
[3] == 2) {
173 elems
->wmm_info
= pos
;
174 elems
->wmm_info_len
= elen
;
175 } else if (pos
[4] == 1) {
176 elems
->wmm_param
= pos
;
177 elems
->wmm_param_len
= elen
;
184 elems
->rsn_len
= elen
;
186 case WLAN_EID_ERP_INFO
:
187 elems
->erp_info
= pos
;
188 elems
->erp_info_len
= elen
;
190 case WLAN_EID_EXT_SUPP_RATES
:
191 elems
->ext_supp_rates
= pos
;
192 elems
->ext_supp_rates_len
= elen
;
196 printk(KERN_DEBUG
"IEEE 802.11 element parse ignored "
197 "unknown element (id=%d elen=%d)\n",
208 /* Do not trigger error if left == 1 as Apple Airport base stations
209 * send AssocResps that are one spurious byte too long. */
211 return unknown
? ParseUnknown
: ParseOK
;
217 static int ecw2cw(int ecw
)
228 static void ieee80211_sta_wmm_params(struct net_device
*dev
,
229 struct ieee80211_if_sta
*ifsta
,
230 u8
*wmm_param
, size_t wmm_param_len
)
232 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
233 struct ieee80211_tx_queue_params params
;
238 if (wmm_param_len
< 8 || wmm_param
[5] /* version */ != 1)
240 count
= wmm_param
[6] & 0x0f;
241 if (count
== ifsta
->wmm_last_param_set
)
243 ifsta
->wmm_last_param_set
= count
;
246 left
= wmm_param_len
- 8;
248 memset(¶ms
, 0, sizeof(params
));
250 if (!local
->ops
->conf_tx
)
254 for (; left
>= 4; left
-= 4, pos
+= 4) {
255 int aci
= (pos
[0] >> 5) & 0x03;
256 int acm
= (pos
[0] >> 4) & 0x01;
261 queue
= IEEE80211_TX_QUEUE_DATA3
;
263 local
->wmm_acm
|= BIT(1) | BIT(2);
267 queue
= IEEE80211_TX_QUEUE_DATA1
;
269 local
->wmm_acm
|= BIT(4) | BIT(5);
273 queue
= IEEE80211_TX_QUEUE_DATA0
;
275 local
->wmm_acm
|= BIT(6) | BIT(7);
280 queue
= IEEE80211_TX_QUEUE_DATA2
;
282 local
->wmm_acm
|= BIT(0) | BIT(3);
287 params
.aifs
= pos
[0] & 0x0f;
288 params
.cw_max
= ecw2cw((pos
[1] & 0xf0) >> 4);
289 params
.cw_min
= ecw2cw(pos
[1] & 0x0f);
290 /* TXOP is in units of 32 usec; burst_time in 0.1 ms */
291 params
.burst_time
= (pos
[2] | (pos
[3] << 8)) * 32 / 100;
292 printk(KERN_DEBUG
"%s: WMM queue=%d aci=%d acm=%d aifs=%d "
293 "cWmin=%d cWmax=%d burst=%d\n",
294 dev
->name
, queue
, aci
, acm
, params
.aifs
, params
.cw_min
,
295 params
.cw_max
, params
.burst_time
);
296 /* TODO: handle ACM (block TX, fallback to next lowest allowed
298 if (local
->ops
->conf_tx(local_to_hw(local
), queue
, ¶ms
)) {
299 printk(KERN_DEBUG
"%s: failed to set TX queue "
300 "parameters for queue %d\n", dev
->name
, queue
);
306 static void ieee80211_sta_send_associnfo(struct net_device
*dev
,
307 struct ieee80211_if_sta
*ifsta
)
312 union iwreq_data wrqu
;
314 if (!ifsta
->assocreq_ies
&& !ifsta
->assocresp_ies
)
317 buf
= kmalloc(50 + 2 * (ifsta
->assocreq_ies_len
+
318 ifsta
->assocresp_ies_len
), GFP_ATOMIC
);
322 len
= sprintf(buf
, "ASSOCINFO(");
323 if (ifsta
->assocreq_ies
) {
324 len
+= sprintf(buf
+ len
, "ReqIEs=");
325 for (i
= 0; i
< ifsta
->assocreq_ies_len
; i
++) {
326 len
+= sprintf(buf
+ len
, "%02x",
327 ifsta
->assocreq_ies
[i
]);
330 if (ifsta
->assocresp_ies
) {
331 if (ifsta
->assocreq_ies
)
332 len
+= sprintf(buf
+ len
, " ");
333 len
+= sprintf(buf
+ len
, "RespIEs=");
334 for (i
= 0; i
< ifsta
->assocresp_ies_len
; i
++) {
335 len
+= sprintf(buf
+ len
, "%02x",
336 ifsta
->assocresp_ies
[i
]);
339 len
+= sprintf(buf
+ len
, ")");
341 if (len
> IW_CUSTOM_MAX
) {
342 len
= sprintf(buf
, "ASSOCRESPIE=");
343 for (i
= 0; i
< ifsta
->assocresp_ies_len
; i
++) {
344 len
+= sprintf(buf
+ len
, "%02x",
345 ifsta
->assocresp_ies
[i
]);
349 memset(&wrqu
, 0, sizeof(wrqu
));
350 wrqu
.data
.length
= len
;
351 wireless_send_event(dev
, IWEVCUSTOM
, &wrqu
, buf
);
357 static void ieee80211_set_associated(struct net_device
*dev
,
358 struct ieee80211_if_sta
*ifsta
, int assoc
)
360 union iwreq_data wrqu
;
362 if (ifsta
->associated
== assoc
)
365 ifsta
->associated
= assoc
;
368 struct ieee80211_sub_if_data
*sdata
;
369 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
370 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
372 ifsta
->prev_bssid_set
= 1;
373 memcpy(ifsta
->prev_bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
374 memcpy(wrqu
.ap_addr
.sa_data
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
375 ieee80211_sta_send_associnfo(dev
, ifsta
);
377 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
379 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
380 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
381 ifsta
->last_probe
= jiffies
;
384 static void ieee80211_set_disassoc(struct net_device
*dev
,
385 struct ieee80211_if_sta
*ifsta
, int deauth
)
388 ifsta
->auth_tries
= 0;
389 ifsta
->assoc_tries
= 0;
390 ieee80211_set_associated(dev
, ifsta
, 0);
393 static void ieee80211_sta_tx(struct net_device
*dev
, struct sk_buff
*skb
,
396 struct ieee80211_sub_if_data
*sdata
;
397 struct ieee80211_tx_packet_data
*pkt_data
;
399 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
400 skb
->dev
= sdata
->local
->mdev
;
401 skb
->mac
.raw
= skb
->nh
.raw
= skb
->h
.raw
= skb
->data
;
403 pkt_data
= (struct ieee80211_tx_packet_data
*) skb
->cb
;
404 memset(pkt_data
, 0, sizeof(struct ieee80211_tx_packet_data
));
405 pkt_data
->ifindex
= sdata
->dev
->ifindex
;
406 pkt_data
->mgmt_iface
= (sdata
->type
== IEEE80211_IF_TYPE_MGMT
);
407 pkt_data
->do_not_encrypt
= !encrypt
;
413 static void ieee80211_send_auth(struct net_device
*dev
,
414 struct ieee80211_if_sta
*ifsta
,
415 int transaction
, u8
*extra
, size_t extra_len
,
419 struct ieee80211_mgmt
*mgmt
;
421 skb
= dev_alloc_skb(sizeof(*mgmt
) + 6 + extra_len
);
423 printk(KERN_DEBUG
"%s: failed to allocate buffer for auth "
424 "frame\n", dev
->name
);
428 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24 + 6);
429 memset(mgmt
, 0, 24 + 6);
430 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
431 IEEE80211_STYPE_AUTH
);
433 mgmt
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PROTECTED
);
434 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
435 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
436 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
437 mgmt
->u
.auth
.auth_alg
= cpu_to_le16(ifsta
->auth_alg
);
438 mgmt
->u
.auth
.auth_transaction
= cpu_to_le16(transaction
);
439 ifsta
->auth_transaction
= transaction
+ 1;
440 mgmt
->u
.auth
.status_code
= cpu_to_le16(0);
442 memcpy(skb_put(skb
, extra_len
), extra
, extra_len
);
444 ieee80211_sta_tx(dev
, skb
, encrypt
);
448 static void ieee80211_authenticate(struct net_device
*dev
,
449 struct ieee80211_if_sta
*ifsta
)
452 if (ifsta
->auth_tries
> IEEE80211_AUTH_MAX_TRIES
) {
453 printk(KERN_DEBUG
"%s: authentication with AP " MAC_FMT
455 dev
->name
, MAC_ARG(ifsta
->bssid
));
459 ifsta
->state
= IEEE80211_AUTHENTICATE
;
460 printk(KERN_DEBUG
"%s: authenticate with AP " MAC_FMT
"\n",
461 dev
->name
, MAC_ARG(ifsta
->bssid
));
463 ieee80211_send_auth(dev
, ifsta
, 1, NULL
, 0, 0);
465 schedule_delayed_work(&ifsta
->work
, IEEE80211_AUTH_TIMEOUT
);
469 static void ieee80211_send_assoc(struct net_device
*dev
,
470 struct ieee80211_if_sta
*ifsta
)
472 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
474 struct ieee80211_mgmt
*mgmt
;
478 struct ieee80211_sta_bss
*bss
;
481 skb
= dev_alloc_skb(sizeof(*mgmt
) + 200 + ifsta
->extra_ie_len
+
484 printk(KERN_DEBUG
"%s: failed to allocate buffer for assoc "
485 "frame\n", dev
->name
);
489 capab
= ifsta
->capab
;
490 if (local
->hw
.conf
.phymode
== MODE_IEEE80211G
) {
491 capab
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
|
492 WLAN_CAPABILITY_SHORT_PREAMBLE
;
494 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
);
496 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
497 capab
|= WLAN_CAPABILITY_PRIVACY
;
501 ieee80211_rx_bss_put(dev
, bss
);
504 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
506 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
507 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
508 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
510 if (ifsta
->prev_bssid_set
) {
512 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
513 IEEE80211_STYPE_REASSOC_REQ
);
514 mgmt
->u
.reassoc_req
.capab_info
= cpu_to_le16(capab
);
515 mgmt
->u
.reassoc_req
.listen_interval
= cpu_to_le16(1);
516 memcpy(mgmt
->u
.reassoc_req
.current_ap
, ifsta
->prev_bssid
,
520 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
521 IEEE80211_STYPE_ASSOC_REQ
);
522 mgmt
->u
.assoc_req
.capab_info
= cpu_to_le16(capab
);
523 mgmt
->u
.assoc_req
.listen_interval
= cpu_to_le16(1);
527 ies
= pos
= skb_put(skb
, 2 + ifsta
->ssid_len
);
528 *pos
++ = WLAN_EID_SSID
;
529 *pos
++ = ifsta
->ssid_len
;
530 memcpy(pos
, ifsta
->ssid
, ifsta
->ssid_len
);
532 len
= local
->num_curr_rates
;
535 pos
= skb_put(skb
, len
+ 2);
536 *pos
++ = WLAN_EID_SUPP_RATES
;
538 for (i
= 0; i
< len
; i
++) {
539 int rate
= local
->curr_rates
[i
].rate
;
540 if (local
->hw
.conf
.phymode
== MODE_ATHEROS_TURBO
)
542 *pos
++ = (u8
) (rate
/ 5);
545 if (local
->num_curr_rates
> len
) {
546 pos
= skb_put(skb
, local
->num_curr_rates
- len
+ 2);
547 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
548 *pos
++ = local
->num_curr_rates
- len
;
549 for (i
= len
; i
< local
->num_curr_rates
; i
++) {
550 int rate
= local
->curr_rates
[i
].rate
;
551 if (local
->hw
.conf
.phymode
== MODE_ATHEROS_TURBO
)
553 *pos
++ = (u8
) (rate
/ 5);
557 if (ifsta
->extra_ie
) {
558 pos
= skb_put(skb
, ifsta
->extra_ie_len
);
559 memcpy(pos
, ifsta
->extra_ie
, ifsta
->extra_ie_len
);
562 if (wmm
&& ifsta
->wmm_enabled
) {
563 pos
= skb_put(skb
, 9);
564 *pos
++ = WLAN_EID_VENDOR_SPECIFIC
;
565 *pos
++ = 7; /* len */
566 *pos
++ = 0x00; /* Microsoft OUI 00:50:F2 */
569 *pos
++ = 2; /* WME */
570 *pos
++ = 0; /* WME info */
571 *pos
++ = 1; /* WME ver */
575 kfree(ifsta
->assocreq_ies
);
576 ifsta
->assocreq_ies_len
= (skb
->data
+ skb
->len
) - ies
;
577 ifsta
->assocreq_ies
= kmalloc(ifsta
->assocreq_ies_len
, GFP_ATOMIC
);
578 if (ifsta
->assocreq_ies
)
579 memcpy(ifsta
->assocreq_ies
, ies
, ifsta
->assocreq_ies_len
);
581 ieee80211_sta_tx(dev
, skb
, 0);
585 static void ieee80211_send_deauth(struct net_device
*dev
,
586 struct ieee80211_if_sta
*ifsta
, u16 reason
)
589 struct ieee80211_mgmt
*mgmt
;
591 skb
= dev_alloc_skb(sizeof(*mgmt
));
593 printk(KERN_DEBUG
"%s: failed to allocate buffer for deauth "
594 "frame\n", dev
->name
);
598 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
600 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
601 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
602 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
603 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
604 IEEE80211_STYPE_DEAUTH
);
606 mgmt
->u
.deauth
.reason_code
= cpu_to_le16(reason
);
608 ieee80211_sta_tx(dev
, skb
, 0);
612 static void ieee80211_send_disassoc(struct net_device
*dev
,
613 struct ieee80211_if_sta
*ifsta
, u16 reason
)
616 struct ieee80211_mgmt
*mgmt
;
618 skb
= dev_alloc_skb(sizeof(*mgmt
));
620 printk(KERN_DEBUG
"%s: failed to allocate buffer for disassoc "
621 "frame\n", dev
->name
);
625 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
627 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
628 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
629 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
630 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
631 IEEE80211_STYPE_DISASSOC
);
633 mgmt
->u
.disassoc
.reason_code
= cpu_to_le16(reason
);
635 ieee80211_sta_tx(dev
, skb
, 0);
639 static int ieee80211_privacy_mismatch(struct net_device
*dev
,
640 struct ieee80211_if_sta
*ifsta
)
642 struct ieee80211_sta_bss
*bss
;
645 if (!ifsta
|| ifsta
->mixed_cell
||
646 ifsta
->key_mgmt
!= IEEE80211_KEY_MGMT_NONE
)
649 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
);
653 if (ieee80211_sta_wep_configured(dev
) !=
654 !!(bss
->capability
& WLAN_CAPABILITY_PRIVACY
))
657 ieee80211_rx_bss_put(dev
, bss
);
663 static void ieee80211_associate(struct net_device
*dev
,
664 struct ieee80211_if_sta
*ifsta
)
666 ifsta
->assoc_tries
++;
667 if (ifsta
->assoc_tries
> IEEE80211_ASSOC_MAX_TRIES
) {
668 printk(KERN_DEBUG
"%s: association with AP " MAC_FMT
670 dev
->name
, MAC_ARG(ifsta
->bssid
));
674 ifsta
->state
= IEEE80211_ASSOCIATE
;
675 printk(KERN_DEBUG
"%s: associate with AP " MAC_FMT
"\n",
676 dev
->name
, MAC_ARG(ifsta
->bssid
));
677 if (ieee80211_privacy_mismatch(dev
, ifsta
)) {
678 printk(KERN_DEBUG
"%s: mismatch in privacy configuration and "
679 "mixed-cell disabled - abort association\n", dev
->name
);
683 ieee80211_send_assoc(dev
, ifsta
);
685 schedule_delayed_work(&ifsta
->work
, IEEE80211_ASSOC_TIMEOUT
);
689 static void ieee80211_associated(struct net_device
*dev
,
690 struct ieee80211_if_sta
*ifsta
)
692 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
693 struct sta_info
*sta
;
696 /* TODO: start monitoring current AP signal quality and number of
697 * missed beacons. Scan other channels every now and then and search
699 /* TODO: remove expired BSSes */
701 ifsta
->state
= IEEE80211_ASSOCIATED
;
703 sta
= sta_info_get(local
, ifsta
->bssid
);
705 printk(KERN_DEBUG
"%s: No STA entry for own AP " MAC_FMT
"\n",
706 dev
->name
, MAC_ARG(ifsta
->bssid
));
710 if (time_after(jiffies
,
711 sta
->last_rx
+ IEEE80211_MONITORING_INTERVAL
)) {
712 if (ifsta
->probereq_poll
) {
713 printk(KERN_DEBUG
"%s: No ProbeResp from "
714 "current AP " MAC_FMT
" - assume out of "
716 dev
->name
, MAC_ARG(ifsta
->bssid
));
718 sta_info_free(sta
, 0);
719 ifsta
->probereq_poll
= 0;
721 ieee80211_send_probe_req(dev
, ifsta
->bssid
,
723 local
->scan_ssid_len
);
724 ifsta
->probereq_poll
= 1;
727 ifsta
->probereq_poll
= 0;
728 if (time_after(jiffies
, ifsta
->last_probe
+
729 IEEE80211_PROBE_INTERVAL
)) {
730 ifsta
->last_probe
= jiffies
;
731 ieee80211_send_probe_req(dev
, ifsta
->bssid
,
739 union iwreq_data wrqu
;
740 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
741 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
742 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
743 schedule_delayed_work(&ifsta
->work
,
744 IEEE80211_MONITORING_INTERVAL
+ 30 * HZ
);
746 schedule_delayed_work(&ifsta
->work
,
747 IEEE80211_MONITORING_INTERVAL
);
752 static void ieee80211_send_probe_req(struct net_device
*dev
, u8
*dst
,
753 u8
*ssid
, size_t ssid_len
)
755 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
757 struct ieee80211_mgmt
*mgmt
;
758 u8
*pos
, *supp_rates
, *esupp_rates
= NULL
;
761 skb
= dev_alloc_skb(sizeof(*mgmt
) + 200);
763 printk(KERN_DEBUG
"%s: failed to allocate buffer for probe "
764 "request\n", dev
->name
);
768 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
770 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
771 IEEE80211_STYPE_PROBE_REQ
);
772 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
774 memcpy(mgmt
->da
, dst
, ETH_ALEN
);
775 memcpy(mgmt
->bssid
, dst
, ETH_ALEN
);
777 memset(mgmt
->da
, 0xff, ETH_ALEN
);
778 memset(mgmt
->bssid
, 0xff, ETH_ALEN
);
780 pos
= skb_put(skb
, 2 + ssid_len
);
781 *pos
++ = WLAN_EID_SSID
;
783 memcpy(pos
, ssid
, ssid_len
);
785 supp_rates
= skb_put(skb
, 2);
786 supp_rates
[0] = WLAN_EID_SUPP_RATES
;
788 for (i
= 0; i
< local
->num_curr_rates
; i
++) {
789 struct ieee80211_rate
*rate
= &local
->curr_rates
[i
];
790 if (!(rate
->flags
& IEEE80211_RATE_SUPPORTED
))
793 pos
= skb_put(skb
, 1);
795 } else if (supp_rates
[1] == 8) {
796 esupp_rates
= skb_put(skb
, 3);
797 esupp_rates
[0] = WLAN_EID_EXT_SUPP_RATES
;
799 pos
= &esupp_rates
[2];
801 pos
= skb_put(skb
, 1);
804 if (local
->hw
.conf
.phymode
== MODE_ATHEROS_TURBO
)
805 *pos
= rate
->rate
/ 10;
807 *pos
= rate
->rate
/ 5;
810 ieee80211_sta_tx(dev
, skb
, 0);
814 static int ieee80211_sta_wep_configured(struct net_device
*dev
)
816 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
817 if (!sdata
|| !sdata
->default_key
||
818 sdata
->default_key
->alg
!= ALG_WEP
)
824 static void ieee80211_auth_completed(struct net_device
*dev
,
825 struct ieee80211_if_sta
*ifsta
)
827 printk(KERN_DEBUG
"%s: authenticated\n", dev
->name
);
828 ifsta
->authenticated
= 1;
829 ieee80211_associate(dev
, ifsta
);
833 static void ieee80211_auth_challenge(struct net_device
*dev
,
834 struct ieee80211_if_sta
*ifsta
,
835 struct ieee80211_mgmt
*mgmt
,
837 struct ieee80211_rx_status
*rx_status
)
840 struct ieee802_11_elems elems
;
842 printk(KERN_DEBUG
"%s: replying to auth challenge\n", dev
->name
);
843 pos
= mgmt
->u
.auth
.variable
;
844 if (ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
)
846 printk(KERN_DEBUG
"%s: failed to parse Auth(challenge)\n",
850 if (!elems
.challenge
) {
851 printk(KERN_DEBUG
"%s: no challenge IE in shared key auth "
852 "frame\n", dev
->name
);
855 ieee80211_send_auth(dev
, ifsta
, 3, elems
.challenge
- 2,
856 elems
.challenge_len
+ 2, 1);
860 static void ieee80211_rx_mgmt_auth(struct net_device
*dev
,
861 struct ieee80211_if_sta
*ifsta
,
862 struct ieee80211_mgmt
*mgmt
,
864 struct ieee80211_rx_status
*rx_status
)
866 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
867 u16 auth_alg
, auth_transaction
, status_code
;
869 if (ifsta
->state
!= IEEE80211_AUTHENTICATE
&&
870 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
) {
871 printk(KERN_DEBUG
"%s: authentication frame received from "
872 MAC_FMT
", but not in authenticate state - ignored\n",
873 dev
->name
, MAC_ARG(mgmt
->sa
));
878 printk(KERN_DEBUG
"%s: too short (%zd) authentication frame "
879 "received from " MAC_FMT
" - ignored\n",
880 dev
->name
, len
, MAC_ARG(mgmt
->sa
));
884 if (sdata
->type
!= IEEE80211_IF_TYPE_IBSS
&&
885 memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
886 printk(KERN_DEBUG
"%s: authentication frame received from "
887 "unknown AP (SA=" MAC_FMT
" BSSID=" MAC_FMT
") - "
888 "ignored\n", dev
->name
, MAC_ARG(mgmt
->sa
),
889 MAC_ARG(mgmt
->bssid
));
893 if (sdata
->type
!= IEEE80211_IF_TYPE_IBSS
&&
894 memcmp(ifsta
->bssid
, mgmt
->bssid
, ETH_ALEN
) != 0) {
895 printk(KERN_DEBUG
"%s: authentication frame received from "
896 "unknown BSSID (SA=" MAC_FMT
" BSSID=" MAC_FMT
") - "
897 "ignored\n", dev
->name
, MAC_ARG(mgmt
->sa
),
898 MAC_ARG(mgmt
->bssid
));
902 auth_alg
= le16_to_cpu(mgmt
->u
.auth
.auth_alg
);
903 auth_transaction
= le16_to_cpu(mgmt
->u
.auth
.auth_transaction
);
904 status_code
= le16_to_cpu(mgmt
->u
.auth
.status_code
);
906 printk(KERN_DEBUG
"%s: RX authentication from " MAC_FMT
" (alg=%d "
907 "transaction=%d status=%d)\n",
908 dev
->name
, MAC_ARG(mgmt
->sa
), auth_alg
,
909 auth_transaction
, status_code
);
911 if (sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
912 /* IEEE 802.11 standard does not require authentication in IBSS
913 * networks and most implementations do not seem to use it.
914 * However, try to reply to authentication attempts if someone
915 * has actually implemented this.
916 * TODO: Could implement shared key authentication. */
917 if (auth_alg
!= WLAN_AUTH_OPEN
|| auth_transaction
!= 1) {
918 printk(KERN_DEBUG
"%s: unexpected IBSS authentication "
919 "frame (alg=%d transaction=%d)\n",
920 dev
->name
, auth_alg
, auth_transaction
);
923 ieee80211_send_auth(dev
, ifsta
, 2, NULL
, 0, 0);
926 if (auth_alg
!= ifsta
->auth_alg
||
927 auth_transaction
!= ifsta
->auth_transaction
) {
928 printk(KERN_DEBUG
"%s: unexpected authentication frame "
929 "(alg=%d transaction=%d)\n",
930 dev
->name
, auth_alg
, auth_transaction
);
934 if (status_code
!= WLAN_STATUS_SUCCESS
) {
935 printk(KERN_DEBUG
"%s: AP denied authentication (auth_alg=%d "
936 "code=%d)\n", dev
->name
, ifsta
->auth_alg
, status_code
);
937 if (status_code
== WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
) {
939 const int num_algs
= ARRAY_SIZE(algs
);
941 algs
[0] = algs
[1] = algs
[2] = 0xff;
942 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_OPEN
)
943 algs
[0] = WLAN_AUTH_OPEN
;
944 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_SHARED_KEY
)
945 algs
[1] = WLAN_AUTH_SHARED_KEY
;
946 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_LEAP
)
947 algs
[2] = WLAN_AUTH_LEAP
;
948 if (ifsta
->auth_alg
== WLAN_AUTH_OPEN
)
950 else if (ifsta
->auth_alg
== WLAN_AUTH_SHARED_KEY
)
954 for (i
= 0; i
< num_algs
; i
++) {
958 if (algs
[pos
] == ifsta
->auth_alg
||
961 if (algs
[pos
] == WLAN_AUTH_SHARED_KEY
&&
962 !ieee80211_sta_wep_configured(dev
))
964 ifsta
->auth_alg
= algs
[pos
];
965 printk(KERN_DEBUG
"%s: set auth_alg=%d for "
967 dev
->name
, ifsta
->auth_alg
);
974 switch (ifsta
->auth_alg
) {
977 ieee80211_auth_completed(dev
, ifsta
);
979 case WLAN_AUTH_SHARED_KEY
:
980 if (ifsta
->auth_transaction
== 4)
981 ieee80211_auth_completed(dev
, ifsta
);
983 ieee80211_auth_challenge(dev
, ifsta
, mgmt
, len
,
990 static void ieee80211_rx_mgmt_deauth(struct net_device
*dev
,
991 struct ieee80211_if_sta
*ifsta
,
992 struct ieee80211_mgmt
*mgmt
,
994 struct ieee80211_rx_status
*rx_status
)
999 printk(KERN_DEBUG
"%s: too short (%zd) deauthentication frame "
1000 "received from " MAC_FMT
" - ignored\n",
1001 dev
->name
, len
, MAC_ARG(mgmt
->sa
));
1005 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1006 printk(KERN_DEBUG
"%s: deauthentication frame received from "
1007 "unknown AP (SA=" MAC_FMT
" BSSID=" MAC_FMT
") - "
1008 "ignored\n", dev
->name
, MAC_ARG(mgmt
->sa
),
1009 MAC_ARG(mgmt
->bssid
));
1013 reason_code
= le16_to_cpu(mgmt
->u
.deauth
.reason_code
);
1015 printk(KERN_DEBUG
"%s: RX deauthentication from " MAC_FMT
1017 dev
->name
, MAC_ARG(mgmt
->sa
), reason_code
);
1019 if (ifsta
->authenticated
) {
1020 printk(KERN_DEBUG
"%s: deauthenticated\n", dev
->name
);
1023 if (ifsta
->state
== IEEE80211_AUTHENTICATE
||
1024 ifsta
->state
== IEEE80211_ASSOCIATE
||
1025 ifsta
->state
== IEEE80211_ASSOCIATED
) {
1026 ifsta
->state
= IEEE80211_AUTHENTICATE
;
1027 schedule_delayed_work(&ifsta
->work
,
1028 IEEE80211_RETRY_AUTH_INTERVAL
);
1031 ieee80211_set_disassoc(dev
, ifsta
, 1);
1032 ifsta
->authenticated
= 0;
1036 static void ieee80211_rx_mgmt_disassoc(struct net_device
*dev
,
1037 struct ieee80211_if_sta
*ifsta
,
1038 struct ieee80211_mgmt
*mgmt
,
1040 struct ieee80211_rx_status
*rx_status
)
1045 printk(KERN_DEBUG
"%s: too short (%zd) disassociation frame "
1046 "received from " MAC_FMT
" - ignored\n",
1047 dev
->name
, len
, MAC_ARG(mgmt
->sa
));
1051 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1052 printk(KERN_DEBUG
"%s: disassociation frame received from "
1053 "unknown AP (SA=" MAC_FMT
" BSSID=" MAC_FMT
") - "
1054 "ignored\n", dev
->name
, MAC_ARG(mgmt
->sa
),
1055 MAC_ARG(mgmt
->bssid
));
1059 reason_code
= le16_to_cpu(mgmt
->u
.disassoc
.reason_code
);
1061 printk(KERN_DEBUG
"%s: RX disassociation from " MAC_FMT
1063 dev
->name
, MAC_ARG(mgmt
->sa
), reason_code
);
1065 if (ifsta
->associated
)
1066 printk(KERN_DEBUG
"%s: disassociated\n", dev
->name
);
1068 if (ifsta
->state
== IEEE80211_ASSOCIATED
) {
1069 ifsta
->state
= IEEE80211_ASSOCIATE
;
1070 schedule_delayed_work(&ifsta
->work
,
1071 IEEE80211_RETRY_AUTH_INTERVAL
);
1074 ieee80211_set_disassoc(dev
, ifsta
, 0);
1078 static void ieee80211_rx_mgmt_assoc_resp(struct net_device
*dev
,
1079 struct ieee80211_if_sta
*ifsta
,
1080 struct ieee80211_mgmt
*mgmt
,
1082 struct ieee80211_rx_status
*rx_status
,
1085 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1086 struct sta_info
*sta
;
1088 u16 capab_info
, status_code
, aid
;
1089 struct ieee802_11_elems elems
;
1093 /* AssocResp and ReassocResp have identical structure, so process both
1094 * of them in this function. */
1096 if (ifsta
->state
!= IEEE80211_ASSOCIATE
) {
1097 printk(KERN_DEBUG
"%s: association frame received from "
1098 MAC_FMT
", but not in associate state - ignored\n",
1099 dev
->name
, MAC_ARG(mgmt
->sa
));
1104 printk(KERN_DEBUG
"%s: too short (%zd) association frame "
1105 "received from " MAC_FMT
" - ignored\n",
1106 dev
->name
, len
, MAC_ARG(mgmt
->sa
));
1110 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1111 printk(KERN_DEBUG
"%s: association frame received from "
1112 "unknown AP (SA=" MAC_FMT
" BSSID=" MAC_FMT
") - "
1113 "ignored\n", dev
->name
, MAC_ARG(mgmt
->sa
),
1114 MAC_ARG(mgmt
->bssid
));
1118 capab_info
= le16_to_cpu(mgmt
->u
.assoc_resp
.capab_info
);
1119 status_code
= le16_to_cpu(mgmt
->u
.assoc_resp
.status_code
);
1120 aid
= le16_to_cpu(mgmt
->u
.assoc_resp
.aid
);
1121 if ((aid
& (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1122 printk(KERN_DEBUG
"%s: invalid aid value %d; bits 15:14 not "
1123 "set\n", dev
->name
, aid
);
1124 aid
&= ~(BIT(15) | BIT(14));
1126 printk(KERN_DEBUG
"%s: RX %sssocResp from " MAC_FMT
" (capab=0x%x "
1127 "status=%d aid=%d)\n",
1128 dev
->name
, reassoc
? "Rea" : "A", MAC_ARG(mgmt
->sa
),
1129 capab_info
, status_code
, aid
);
1131 if (status_code
!= WLAN_STATUS_SUCCESS
) {
1132 printk(KERN_DEBUG
"%s: AP denied association (code=%d)\n",
1133 dev
->name
, status_code
);
1137 pos
= mgmt
->u
.assoc_resp
.variable
;
1138 if (ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
)
1140 printk(KERN_DEBUG
"%s: failed to parse AssocResp\n",
1145 if (!elems
.supp_rates
) {
1146 printk(KERN_DEBUG
"%s: no SuppRates element in AssocResp\n",
1151 printk(KERN_DEBUG
"%s: associated\n", dev
->name
);
1153 ifsta
->ap_capab
= capab_info
;
1155 kfree(ifsta
->assocresp_ies
);
1156 ifsta
->assocresp_ies_len
= len
- (pos
- (u8
*) mgmt
);
1157 ifsta
->assocresp_ies
= kmalloc(ifsta
->assocresp_ies_len
, GFP_ATOMIC
);
1158 if (ifsta
->assocresp_ies
)
1159 memcpy(ifsta
->assocresp_ies
, pos
, ifsta
->assocresp_ies_len
);
1161 ieee80211_set_associated(dev
, ifsta
, 1);
1163 /* Add STA entry for the AP */
1164 sta
= sta_info_get(local
, ifsta
->bssid
);
1166 sta
= sta_info_add(local
, dev
, ifsta
->bssid
, GFP_ATOMIC
);
1168 printk(KERN_DEBUG
"%s: failed to add STA entry for the"
1169 " AP\n", dev
->name
);
1175 sta
->flags
|= WLAN_STA_AUTH
| WLAN_STA_ASSOC
;
1179 for (i
= 0; i
< elems
.supp_rates_len
; i
++) {
1180 int rate
= (elems
.supp_rates
[i
] & 0x7f) * 5;
1181 if (local
->hw
.conf
.phymode
== MODE_ATHEROS_TURBO
)
1183 for (j
= 0; j
< local
->num_curr_rates
; j
++)
1184 if (local
->curr_rates
[j
].rate
== rate
)
1187 for (i
= 0; i
< elems
.ext_supp_rates_len
; i
++) {
1188 int rate
= (elems
.ext_supp_rates
[i
] & 0x7f) * 5;
1189 if (local
->hw
.conf
.phymode
== MODE_ATHEROS_TURBO
)
1191 for (j
= 0; j
< local
->num_curr_rates
; j
++)
1192 if (local
->curr_rates
[j
].rate
== rate
)
1195 sta
->supp_rates
= rates
;
1197 rate_control_rate_init(sta
, local
);
1199 if (elems
.wmm_param
&& ifsta
->wmm_enabled
) {
1200 sta
->flags
|= WLAN_STA_WME
;
1201 ieee80211_sta_wmm_params(dev
, ifsta
, elems
.wmm_param
,
1202 elems
.wmm_param_len
);
1208 ieee80211_associated(dev
, ifsta
);
1212 /* Caller must hold local->sta_bss_lock */
1213 static void __ieee80211_rx_bss_hash_add(struct net_device
*dev
,
1214 struct ieee80211_sta_bss
*bss
)
1216 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1217 bss
->hnext
= local
->sta_bss_hash
[STA_HASH(bss
->bssid
)];
1218 local
->sta_bss_hash
[STA_HASH(bss
->bssid
)] = bss
;
1222 /* Caller must hold local->sta_bss_lock */
1223 static void __ieee80211_rx_bss_hash_del(struct net_device
*dev
,
1224 struct ieee80211_sta_bss
*bss
)
1226 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1227 struct ieee80211_sta_bss
*b
, *prev
= NULL
;
1228 b
= local
->sta_bss_hash
[STA_HASH(bss
->bssid
)];
1232 local
->sta_bss_hash
[STA_HASH(bss
->bssid
)] =
1235 prev
->hnext
= bss
->hnext
;
1244 static struct ieee80211_sta_bss
*
1245 ieee80211_rx_bss_add(struct net_device
*dev
, u8
*bssid
)
1247 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1248 struct ieee80211_sta_bss
*bss
;
1250 bss
= kmalloc(sizeof(*bss
), GFP_ATOMIC
);
1253 memset(bss
, 0, sizeof(*bss
));
1254 atomic_inc(&bss
->users
);
1255 atomic_inc(&bss
->users
);
1256 memcpy(bss
->bssid
, bssid
, ETH_ALEN
);
1258 spin_lock_bh(&local
->sta_bss_lock
);
1259 /* TODO: order by RSSI? */
1260 list_add_tail(&bss
->list
, &local
->sta_bss_list
);
1261 __ieee80211_rx_bss_hash_add(dev
, bss
);
1262 spin_unlock_bh(&local
->sta_bss_lock
);
1267 static struct ieee80211_sta_bss
*
1268 ieee80211_rx_bss_get(struct net_device
*dev
, u8
*bssid
)
1270 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1271 struct ieee80211_sta_bss
*bss
;
1273 spin_lock_bh(&local
->sta_bss_lock
);
1274 bss
= local
->sta_bss_hash
[STA_HASH(bssid
)];
1276 if (memcmp(bss
->bssid
, bssid
, ETH_ALEN
) == 0) {
1277 atomic_inc(&bss
->users
);
1282 spin_unlock_bh(&local
->sta_bss_lock
);
1287 static void ieee80211_rx_bss_free(struct ieee80211_sta_bss
*bss
)
1296 static void ieee80211_rx_bss_put(struct net_device
*dev
,
1297 struct ieee80211_sta_bss
*bss
)
1299 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1300 if (!atomic_dec_and_test(&bss
->users
))
1303 spin_lock_bh(&local
->sta_bss_lock
);
1304 __ieee80211_rx_bss_hash_del(dev
, bss
);
1305 list_del(&bss
->list
);
1306 spin_unlock_bh(&local
->sta_bss_lock
);
1307 ieee80211_rx_bss_free(bss
);
1311 void ieee80211_rx_bss_list_init(struct net_device
*dev
)
1313 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1314 spin_lock_init(&local
->sta_bss_lock
);
1315 INIT_LIST_HEAD(&local
->sta_bss_list
);
1319 void ieee80211_rx_bss_list_deinit(struct net_device
*dev
)
1321 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1322 struct ieee80211_sta_bss
*bss
, *tmp
;
1324 list_for_each_entry_safe(bss
, tmp
, &local
->sta_bss_list
, list
)
1325 ieee80211_rx_bss_put(dev
, bss
);
1329 static void ieee80211_rx_bss_info(struct net_device
*dev
,
1330 struct ieee80211_mgmt
*mgmt
,
1332 struct ieee80211_rx_status
*rx_status
,
1335 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1336 struct ieee802_11_elems elems
;
1338 int channel
, invalid
= 0, clen
;
1339 struct ieee80211_sta_bss
*bss
;
1340 struct sta_info
*sta
;
1341 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1344 if (!beacon
&& memcmp(mgmt
->da
, dev
->dev_addr
, ETH_ALEN
))
1345 return; /* ignore ProbeResp to foreign address */
1348 printk(KERN_DEBUG
"%s: RX %s from " MAC_FMT
" to " MAC_FMT
"\n",
1349 dev
->name
, beacon
? "Beacon" : "Probe Response",
1350 MAC_ARG(mgmt
->sa
), MAC_ARG(mgmt
->da
));
1353 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
1357 timestamp
= le64_to_cpu(mgmt
->u
.beacon
.timestamp
);
1359 if (sdata
->type
== IEEE80211_IF_TYPE_IBSS
&& beacon
&&
1360 memcmp(mgmt
->bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
) == 0) {
1361 #ifdef CONFIG_D80211_IBSS_DEBUG
1362 static unsigned long last_tsf_debug
= 0;
1364 if (local
->ops
->get_tsf
)
1365 tsf
= local
->ops
->get_tsf(local_to_hw(local
));
1368 if (time_after(jiffies
, last_tsf_debug
+ 5 * HZ
)) {
1369 printk(KERN_DEBUG
"RX beacon SA=" MAC_FMT
" BSSID="
1370 MAC_FMT
" TSF=0x%llx BCN=0x%llx diff=%lld "
1372 MAC_ARG(mgmt
->sa
), MAC_ARG(mgmt
->bssid
),
1373 (unsigned long long)tsf
,
1374 (unsigned long long)timestamp
,
1375 (unsigned long long)(tsf
- timestamp
),
1377 last_tsf_debug
= jiffies
;
1379 #endif /* CONFIG_D80211_IBSS_DEBUG */
1382 if (ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
, len
- baselen
,
1383 &elems
) == ParseFailed
)
1386 if (sdata
->type
== IEEE80211_IF_TYPE_IBSS
&& elems
.supp_rates
&&
1387 memcmp(mgmt
->bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
) == 0 &&
1388 (sta
= sta_info_get(local
, mgmt
->sa
))) {
1389 struct ieee80211_hw_mode
*mode
;
1390 struct ieee80211_rate
*rates
;
1392 u32 supp_rates
, prev_rates
;
1393 int i
, j
, oper_mode
;
1395 rates
= local
->curr_rates
;
1396 num_rates
= local
->num_curr_rates
;
1397 oper_mode
= local
->sta_scanning
? local
->scan_oper_phymode
:
1398 local
->hw
.conf
.phymode
;
1399 list_for_each_entry(mode
, &local
->modes_list
, list
) {
1400 if (oper_mode
== mode
->mode
) {
1401 rates
= mode
->rates
;
1402 num_rates
= mode
->num_rates
;
1408 for (i
= 0; i
< elems
.supp_rates_len
+
1409 elems
.ext_supp_rates_len
; i
++) {
1412 if (i
< elems
.supp_rates_len
)
1413 rate
= elems
.supp_rates
[i
];
1414 else if (elems
.ext_supp_rates
)
1415 rate
= elems
.ext_supp_rates
1416 [i
- elems
.supp_rates_len
];
1417 own_rate
= 5 * (rate
& 0x7f);
1418 if (oper_mode
== MODE_ATHEROS_TURBO
)
1420 for (j
= 0; j
< num_rates
; j
++)
1421 if (rates
[j
].rate
== own_rate
)
1422 supp_rates
|= BIT(j
);
1425 prev_rates
= sta
->supp_rates
;
1426 sta
->supp_rates
&= supp_rates
;
1427 if (sta
->supp_rates
== 0) {
1428 /* No matching rates - this should not really happen.
1429 * Make sure that at least one rate is marked
1430 * supported to avoid issues with TX rate ctrl. */
1431 sta
->supp_rates
= sdata
->u
.sta
.supp_rates_bits
;
1433 if (sta
->supp_rates
!= prev_rates
) {
1434 printk(KERN_DEBUG
"%s: updated supp_rates set for "
1435 MAC_FMT
" based on beacon info (0x%x & 0x%x -> "
1437 dev
->name
, MAC_ARG(sta
->addr
), prev_rates
,
1438 supp_rates
, sta
->supp_rates
);
1446 if (elems
.ds_params
&& elems
.ds_params_len
== 1)
1447 channel
= elems
.ds_params
[0];
1449 channel
= rx_status
->channel
;
1451 bss
= ieee80211_rx_bss_get(dev
, mgmt
->bssid
);
1453 bss
= ieee80211_rx_bss_add(dev
, mgmt
->bssid
);
1458 /* TODO: order by RSSI? */
1459 spin_lock_bh(&local
->sta_bss_lock
);
1460 list_move_tail(&bss
->list
, &local
->sta_bss_list
);
1461 spin_unlock_bh(&local
->sta_bss_lock
);
1465 if (bss
->probe_resp
&& beacon
) {
1466 /* Do not allow beacon to override data from Probe Response. */
1467 ieee80211_rx_bss_put(dev
, bss
);
1471 bss
->beacon_int
= le16_to_cpu(mgmt
->u
.beacon
.beacon_int
);
1472 bss
->capability
= le16_to_cpu(mgmt
->u
.beacon
.capab_info
);
1473 if (elems
.ssid
&& elems
.ssid_len
<= IEEE80211_MAX_SSID_LEN
) {
1474 memcpy(bss
->ssid
, elems
.ssid
, elems
.ssid_len
);
1475 bss
->ssid_len
= elems
.ssid_len
;
1478 bss
->supp_rates_len
= 0;
1479 if (elems
.supp_rates
) {
1480 clen
= IEEE80211_MAX_SUPP_RATES
- bss
->supp_rates_len
;
1481 if (clen
> elems
.supp_rates_len
)
1482 clen
= elems
.supp_rates_len
;
1483 memcpy(&bss
->supp_rates
[bss
->supp_rates_len
], elems
.supp_rates
,
1485 bss
->supp_rates_len
+= clen
;
1487 if (elems
.ext_supp_rates
) {
1488 clen
= IEEE80211_MAX_SUPP_RATES
- bss
->supp_rates_len
;
1489 if (clen
> elems
.ext_supp_rates_len
)
1490 clen
= elems
.ext_supp_rates_len
;
1491 memcpy(&bss
->supp_rates
[bss
->supp_rates_len
],
1492 elems
.ext_supp_rates
, clen
);
1493 bss
->supp_rates_len
+= clen
;
1497 (!bss
->wpa_ie
|| bss
->wpa_ie_len
!= elems
.wpa_len
||
1498 memcmp(bss
->wpa_ie
, elems
.wpa
, elems
.wpa_len
))) {
1500 bss
->wpa_ie
= kmalloc(elems
.wpa_len
+ 2, GFP_ATOMIC
);
1502 memcpy(bss
->wpa_ie
, elems
.wpa
- 2, elems
.wpa_len
+ 2);
1503 bss
->wpa_ie_len
= elems
.wpa_len
+ 2;
1505 bss
->wpa_ie_len
= 0;
1506 } else if (!elems
.wpa
&& bss
->wpa_ie
) {
1509 bss
->wpa_ie_len
= 0;
1513 (!bss
->rsn_ie
|| bss
->rsn_ie_len
!= elems
.rsn_len
||
1514 memcmp(bss
->rsn_ie
, elems
.rsn
, elems
.rsn_len
))) {
1516 bss
->rsn_ie
= kmalloc(elems
.rsn_len
+ 2, GFP_ATOMIC
);
1518 memcpy(bss
->rsn_ie
, elems
.rsn
- 2, elems
.rsn_len
+ 2);
1519 bss
->rsn_ie_len
= elems
.rsn_len
+ 2;
1521 bss
->rsn_ie_len
= 0;
1522 } else if (!elems
.rsn
&& bss
->rsn_ie
) {
1525 bss
->rsn_ie_len
= 0;
1528 if (elems
.wmm_param
&&
1529 (!bss
->wmm_ie
|| bss
->wmm_ie_len
!= elems
.wmm_param_len
||
1530 memcmp(bss
->wmm_ie
, elems
.wmm_param
, elems
.wmm_param_len
))) {
1532 bss
->wmm_ie
= kmalloc(elems
.wmm_param_len
+ 2, GFP_ATOMIC
);
1534 memcpy(bss
->wmm_ie
, elems
.wmm_param
- 2,
1535 elems
.wmm_param_len
+ 2);
1536 bss
->wmm_ie_len
= elems
.wmm_param_len
+ 2;
1538 bss
->wmm_ie_len
= 0;
1539 } else if (!elems
.wmm_param
&& bss
->wmm_ie
) {
1542 bss
->wmm_ie_len
= 0;
1546 bss
->hw_mode
= rx_status
->phymode
;
1547 bss
->channel
= channel
;
1548 bss
->freq
= rx_status
->freq
;
1549 if (channel
!= rx_status
->channel
&&
1550 (bss
->hw_mode
== MODE_IEEE80211G
||
1551 bss
->hw_mode
== MODE_IEEE80211B
) &&
1552 channel
>= 1 && channel
<= 14) {
1553 static const int freq_list
[] = {
1554 2412, 2417, 2422, 2427, 2432, 2437, 2442,
1555 2447, 2452, 2457, 2462, 2467, 2472, 2484
1557 /* IEEE 802.11g/b mode can receive packets from neighboring
1558 * channels, so map the channel into frequency. */
1559 bss
->freq
= freq_list
[channel
- 1];
1561 bss
->timestamp
= timestamp
;
1562 bss
->last_update
= jiffies
;
1563 bss
->rssi
= rx_status
->ssi
;
1566 ieee80211_rx_bss_put(dev
, bss
);
1570 static void ieee80211_rx_mgmt_probe_resp(struct net_device
*dev
,
1571 struct ieee80211_mgmt
*mgmt
,
1573 struct ieee80211_rx_status
*rx_status
)
1575 ieee80211_rx_bss_info(dev
, mgmt
, len
, rx_status
, 0);
1579 static void ieee80211_rx_mgmt_beacon(struct net_device
*dev
,
1580 struct ieee80211_mgmt
*mgmt
,
1582 struct ieee80211_rx_status
*rx_status
)
1584 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1585 struct ieee80211_sub_if_data
*sdata
;
1586 struct ieee80211_if_sta
*ifsta
;
1589 struct ieee802_11_elems elems
;
1591 ieee80211_rx_bss_info(dev
, mgmt
, len
, rx_status
, 1);
1593 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1594 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
1596 ifsta
= &sdata
->u
.sta
;
1598 if (!ifsta
->associated
||
1599 memcmp(ifsta
->bssid
, mgmt
->bssid
, ETH_ALEN
) != 0)
1602 /* Process beacon from the current BSS */
1603 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
1607 if (ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
, len
- baselen
,
1608 &elems
) == ParseFailed
)
1612 if (elems
.erp_info
&& elems
.erp_info_len
>= 1) {
1614 (elems
.erp_info
[0] & ERP_INFO_USE_PROTECTION
) != 0;
1617 if (use_protection
!= !!ifsta
->use_protection
) {
1618 if (net_ratelimit()) {
1619 printk(KERN_DEBUG
"%s: CTS protection %s (BSSID="
1622 use_protection
? "enabled" : "disabled",
1623 MAC_ARG(ifsta
->bssid
));
1625 ifsta
->use_protection
= use_protection
? 1 : 0;
1626 local
->cts_protect_erp_frames
= use_protection
;
1629 if (elems
.wmm_param
&& ifsta
->wmm_enabled
) {
1630 ieee80211_sta_wmm_params(dev
, ifsta
, elems
.wmm_param
,
1631 elems
.wmm_param_len
);
1636 static void ieee80211_rx_mgmt_probe_req(struct net_device
*dev
,
1637 struct ieee80211_if_sta
*ifsta
,
1638 struct ieee80211_mgmt
*mgmt
,
1640 struct ieee80211_rx_status
*rx_status
)
1642 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1643 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1645 struct sk_buff
*skb
;
1646 struct ieee80211_mgmt
*resp
;
1649 if (sdata
->type
!= IEEE80211_IF_TYPE_IBSS
||
1650 ifsta
->state
!= IEEE80211_IBSS_JOINED
||
1651 len
< 24 + 2 || !ifsta
->probe_resp
)
1654 if (local
->ops
->tx_last_beacon
)
1655 tx_last_beacon
= local
->ops
->tx_last_beacon(local_to_hw(local
));
1659 #ifdef CONFIG_D80211_IBSS_DEBUG
1660 printk(KERN_DEBUG
"%s: RX ProbeReq SA=" MAC_FMT
" DA=" MAC_FMT
" BSSID="
1661 MAC_FMT
" (tx_last_beacon=%d)\n",
1662 dev
->name
, MAC_ARG(mgmt
->sa
), MAC_ARG(mgmt
->da
),
1663 MAC_ARG(mgmt
->bssid
), tx_last_beacon
);
1664 #endif /* CONFIG_D80211_IBSS_DEBUG */
1666 if (!tx_last_beacon
)
1669 if (memcmp(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
) != 0 &&
1670 memcmp(mgmt
->bssid
, "\xff\xff\xff\xff\xff\xff", ETH_ALEN
) != 0)
1673 end
= ((u8
*) mgmt
) + len
;
1674 pos
= mgmt
->u
.probe_req
.variable
;
1675 if (pos
[0] != WLAN_EID_SSID
||
1676 pos
+ 2 + pos
[1] > end
) {
1677 if (net_ratelimit()) {
1678 printk(KERN_DEBUG
"%s: Invalid SSID IE in ProbeReq "
1679 "from " MAC_FMT
"\n",
1680 dev
->name
, MAC_ARG(mgmt
->sa
));
1685 (pos
[1] != ifsta
->ssid_len
||
1686 memcmp(pos
+ 2, ifsta
->ssid
, ifsta
->ssid_len
) != 0)) {
1687 /* Ignore ProbeReq for foreign SSID */
1691 /* Reply with ProbeResp */
1692 skb
= skb_copy(ifsta
->probe_resp
, GFP_ATOMIC
);
1696 resp
= (struct ieee80211_mgmt
*) skb
->data
;
1697 memcpy(resp
->da
, mgmt
->sa
, ETH_ALEN
);
1698 #ifdef CONFIG_D80211_IBSS_DEBUG
1699 printk(KERN_DEBUG
"%s: Sending ProbeResp to " MAC_FMT
"\n",
1700 dev
->name
, MAC_ARG(resp
->da
));
1701 #endif /* CONFIG_D80211_IBSS_DEBUG */
1702 ieee80211_sta_tx(dev
, skb
, 0);
1706 void ieee80211_sta_rx_mgmt(struct net_device
*dev
, struct sk_buff
*skb
,
1707 struct ieee80211_rx_status
*rx_status
)
1709 struct ieee80211_sub_if_data
*sdata
;
1710 struct ieee80211_if_sta
*ifsta
;
1711 struct ieee80211_mgmt
*mgmt
;
1717 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1718 ifsta
= &sdata
->u
.sta
;
1720 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
1721 fc
= le16_to_cpu(mgmt
->frame_control
);
1723 switch (fc
& IEEE80211_FCTL_STYPE
) {
1724 case IEEE80211_STYPE_PROBE_REQ
:
1725 ieee80211_rx_mgmt_probe_req(dev
, ifsta
, mgmt
, skb
->len
,
1728 case IEEE80211_STYPE_PROBE_RESP
:
1729 ieee80211_rx_mgmt_probe_resp(dev
, mgmt
, skb
->len
, rx_status
);
1731 case IEEE80211_STYPE_BEACON
:
1732 ieee80211_rx_mgmt_beacon(dev
, mgmt
, skb
->len
, rx_status
);
1734 case IEEE80211_STYPE_AUTH
:
1735 ieee80211_rx_mgmt_auth(dev
, ifsta
, mgmt
, skb
->len
, rx_status
);
1737 case IEEE80211_STYPE_ASSOC_RESP
:
1738 ieee80211_rx_mgmt_assoc_resp(dev
, ifsta
, mgmt
, skb
->len
,
1741 case IEEE80211_STYPE_REASSOC_RESP
:
1742 ieee80211_rx_mgmt_assoc_resp(dev
, ifsta
, mgmt
, skb
->len
,
1745 case IEEE80211_STYPE_DEAUTH
:
1746 ieee80211_rx_mgmt_deauth(dev
, ifsta
, mgmt
, skb
->len
,
1749 case IEEE80211_STYPE_DISASSOC
:
1750 ieee80211_rx_mgmt_disassoc(dev
, ifsta
, mgmt
, skb
->len
,
1754 printk(KERN_DEBUG
"%s: received unknown management frame - "
1755 "stype=%d\n", dev
->name
,
1756 (fc
& IEEE80211_FCTL_STYPE
) >> 4);
1765 void ieee80211_sta_rx_scan(struct net_device
*dev
, struct sk_buff
*skb
,
1766 struct ieee80211_rx_status
*rx_status
)
1768 struct ieee80211_mgmt
*mgmt
;
1771 if (skb
->len
< 24) {
1776 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
1777 fc
= le16_to_cpu(mgmt
->frame_control
);
1779 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
) {
1780 if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_PROBE_RESP
) {
1781 ieee80211_rx_mgmt_probe_resp(dev
, mgmt
,
1782 skb
->len
, rx_status
);
1783 } else if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_BEACON
) {
1784 ieee80211_rx_mgmt_beacon(dev
, mgmt
, skb
->len
,
1793 static int ieee80211_sta_active_ibss(struct net_device
*dev
)
1795 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1797 struct sta_info
*sta
;
1799 spin_lock_bh(&local
->sta_lock
);
1800 list_for_each_entry(sta
, &local
->sta_list
, list
) {
1801 if (sta
->dev
== dev
&&
1802 time_after(sta
->last_rx
+ IEEE80211_IBSS_MERGE_INTERVAL
,
1808 spin_unlock_bh(&local
->sta_lock
);
1814 static void ieee80211_sta_expire(struct net_device
*dev
)
1816 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1817 struct sta_info
*sta
, *tmp
;
1819 spin_lock_bh(&local
->sta_lock
);
1820 list_for_each_entry_safe(sta
, tmp
, &local
->sta_list
, list
)
1821 if (time_after(jiffies
, sta
->last_rx
+
1822 IEEE80211_IBSS_INACTIVITY_LIMIT
)) {
1823 printk(KERN_DEBUG
"%s: expiring inactive STA " MAC_FMT
1824 "\n", dev
->name
, MAC_ARG(sta
->addr
));
1825 sta_info_free(sta
, 1);
1827 spin_unlock_bh(&local
->sta_lock
);
1831 static void ieee80211_sta_merge_ibss(struct net_device
*dev
,
1832 struct ieee80211_if_sta
*ifsta
)
1834 schedule_delayed_work(&ifsta
->work
, IEEE80211_IBSS_MERGE_INTERVAL
);
1836 ieee80211_sta_expire(dev
);
1837 if (ieee80211_sta_active_ibss(dev
))
1840 printk(KERN_DEBUG
"%s: No active IBSS STAs - trying to scan for other "
1841 "IBSS networks with same SSID (merge)\n", dev
->name
);
1842 ieee80211_sta_req_scan(dev
, ifsta
->ssid
, ifsta
->ssid_len
);
1846 void ieee80211_sta_work(struct work_struct
*work
)
1848 struct ieee80211_sub_if_data
*sdata
=
1849 container_of(work
, struct ieee80211_sub_if_data
, u
.sta
.work
.work
);
1850 struct net_device
*dev
= sdata
->dev
;
1851 struct ieee80211_if_sta
*ifsta
;
1853 if (!netif_running(dev
))
1856 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1857 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
1858 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
) {
1859 printk(KERN_DEBUG
"%s: ieee80211_sta_work: non-STA interface "
1860 "(type=%d)\n", dev
->name
, sdata
->type
);
1863 ifsta
= &sdata
->u
.sta
;
1865 switch (ifsta
->state
) {
1866 case IEEE80211_DISABLED
:
1868 case IEEE80211_AUTHENTICATE
:
1869 ieee80211_authenticate(dev
, ifsta
);
1871 case IEEE80211_ASSOCIATE
:
1872 ieee80211_associate(dev
, ifsta
);
1874 case IEEE80211_ASSOCIATED
:
1875 ieee80211_associated(dev
, ifsta
);
1877 case IEEE80211_IBSS_SEARCH
:
1878 ieee80211_sta_find_ibss(dev
, ifsta
);
1880 case IEEE80211_IBSS_JOINED
:
1881 ieee80211_sta_merge_ibss(dev
, ifsta
);
1884 printk(KERN_DEBUG
"ieee80211_sta_work: Unknown state %d\n",
1889 if (ieee80211_privacy_mismatch(dev
, ifsta
)) {
1890 printk(KERN_DEBUG
"%s: privacy configuration mismatch and "
1891 "mixed-cell disabled - disassociate\n", dev
->name
);
1893 ieee80211_send_disassoc(dev
, ifsta
, WLAN_REASON_UNSPECIFIED
);
1894 ieee80211_set_disassoc(dev
, ifsta
, 0);
1899 static void ieee80211_sta_new_auth(struct net_device
*dev
,
1900 struct ieee80211_if_sta
*ifsta
)
1902 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1903 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1905 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
1908 if (local
->ops
->reset_tsf
) {
1909 /* Reset own TSF to allow time synchronization work. */
1910 local
->ops
->reset_tsf(local_to_hw(local
));
1913 ifsta
->wmm_last_param_set
= -1; /* allow any WMM update */
1916 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_OPEN
)
1917 ifsta
->auth_alg
= WLAN_AUTH_OPEN
;
1918 else if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_SHARED_KEY
)
1919 ifsta
->auth_alg
= WLAN_AUTH_SHARED_KEY
;
1920 else if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_LEAP
)
1921 ifsta
->auth_alg
= WLAN_AUTH_LEAP
;
1923 ifsta
->auth_alg
= WLAN_AUTH_OPEN
;
1924 printk(KERN_DEBUG
"%s: Initial auth_alg=%d\n", dev
->name
,
1926 ifsta
->auth_transaction
= -1;
1927 ifsta
->associated
= ifsta
->auth_tries
= ifsta
->assoc_tries
= 0;
1928 ieee80211_authenticate(dev
, ifsta
);
1932 static int ieee80211_ibss_allowed(struct ieee80211_local
*local
)
1934 struct ieee80211_hw_mode
*mode
;
1937 list_for_each_entry(mode
, &local
->modes_list
, list
) {
1938 if (mode
->mode
!= local
->hw
.conf
.phymode
)
1940 for (c
= 0; c
< mode
->num_channels
; c
++) {
1941 struct ieee80211_channel
*chan
= &mode
->channels
[c
];
1942 if (chan
->flag
& IEEE80211_CHAN_W_SCAN
&&
1943 chan
->chan
== local
->hw
.conf
.channel
) {
1944 if (chan
->flag
& IEEE80211_CHAN_W_IBSS
)
1955 extern int ieee80211_ioctl_siwfreq(struct net_device
*dev
,
1956 struct iw_request_info
*info
,
1957 struct iw_freq
*freq
, char *extra
);
1959 static int ieee80211_sta_join_ibss(struct net_device
*dev
,
1960 struct ieee80211_if_sta
*ifsta
,
1961 struct ieee80211_sta_bss
*bss
)
1963 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1965 int res
, rates
, i
, j
;
1966 struct sk_buff
*skb
;
1967 struct ieee80211_mgmt
*mgmt
;
1968 struct ieee80211_tx_control control
;
1969 struct ieee80211_rate
*rate
;
1970 struct rate_control_extra extra
;
1972 struct ieee80211_sub_if_data
*sdata
;
1974 /* Remove possible STA entries from other IBSS networks. */
1975 sta_info_flush(local
, NULL
);
1977 if (local
->ops
->reset_tsf
) {
1978 /* Reset own TSF to allow time synchronization work. */
1979 local
->ops
->reset_tsf(local_to_hw(local
));
1981 memcpy(ifsta
->bssid
, bss
->bssid
, ETH_ALEN
);
1982 res
= ieee80211_if_config(dev
);
1986 local
->hw
.conf
.beacon_int
= bss
->beacon_int
>= 10 ? bss
->beacon_int
: 10;
1988 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1989 sdata
->drop_unencrypted
= bss
->capability
&
1990 WLAN_CAPABILITY_PRIVACY
? 1 : 0;
1992 memset(&rq
, 0, sizeof(rq
));
1993 rq
.m
= bss
->freq
* 100000;
1995 res
= ieee80211_ioctl_siwfreq(dev
, NULL
, &rq
, NULL
);
1997 if (!ieee80211_ibss_allowed(local
)) {
1998 printk(KERN_DEBUG
"%s: IBSS not allowed on channel %d "
1999 "(%d MHz)\n", dev
->name
, local
->hw
.conf
.channel
,
2000 local
->hw
.conf
.freq
);
2004 /* Set beacon template based on scan results */
2005 skb
= dev_alloc_skb(400);
2010 mgmt
= (struct ieee80211_mgmt
*)
2011 skb_put(skb
, 24 + sizeof(mgmt
->u
.beacon
));
2012 memset(mgmt
, 0, 24 + sizeof(mgmt
->u
.beacon
));
2013 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
2014 IEEE80211_STYPE_BEACON
);
2015 memset(mgmt
->da
, 0xff, ETH_ALEN
);
2016 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
2017 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
2018 mgmt
->u
.beacon
.beacon_int
=
2019 cpu_to_le16(local
->hw
.conf
.beacon_int
);
2020 mgmt
->u
.beacon
.capab_info
= cpu_to_le16(bss
->capability
);
2022 pos
= skb_put(skb
, 2 + ifsta
->ssid_len
);
2023 *pos
++ = WLAN_EID_SSID
;
2024 *pos
++ = ifsta
->ssid_len
;
2025 memcpy(pos
, ifsta
->ssid
, ifsta
->ssid_len
);
2027 rates
= bss
->supp_rates_len
;
2030 pos
= skb_put(skb
, 2 + rates
);
2031 *pos
++ = WLAN_EID_SUPP_RATES
;
2033 memcpy(pos
, bss
->supp_rates
, rates
);
2035 pos
= skb_put(skb
, 2 + 1);
2036 *pos
++ = WLAN_EID_DS_PARAMS
;
2038 *pos
++ = bss
->channel
;
2040 pos
= skb_put(skb
, 2 + 2);
2041 *pos
++ = WLAN_EID_IBSS_PARAMS
;
2043 /* FIX: set ATIM window based on scan results */
2047 if (bss
->supp_rates_len
> 8) {
2048 rates
= bss
->supp_rates_len
- 8;
2049 pos
= skb_put(skb
, 2 + rates
);
2050 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
2052 memcpy(pos
, &bss
->supp_rates
[8], rates
);
2055 memset(&control
, 0, sizeof(control
));
2056 memset(&extra
, 0, sizeof(extra
));
2057 extra
.endidx
= local
->num_curr_rates
;
2058 rate
= rate_control_get_rate(local
, dev
, skb
, &extra
);
2060 printk(KERN_DEBUG
"%s: Failed to determine TX rate "
2061 "for IBSS beacon\n", dev
->name
);
2064 control
.tx_rate
= (local
->short_preamble
&&
2065 (rate
->flags
& IEEE80211_RATE_PREAMBLE2
)) ?
2066 rate
->val2
: rate
->val
;
2067 control
.antenna_sel
= local
->hw
.conf
.antenna_sel
;
2068 control
.power_level
= local
->hw
.conf
.power_level
;
2069 control
.flags
|= IEEE80211_TXCTL_NO_ACK
;
2070 control
.retry_limit
= 1;
2071 control
.rts_cts_duration
= 0;
2073 ifsta
->probe_resp
= skb_copy(skb
, GFP_ATOMIC
);
2074 if (ifsta
->probe_resp
) {
2075 mgmt
= (struct ieee80211_mgmt
*)
2076 ifsta
->probe_resp
->data
;
2077 mgmt
->frame_control
=
2078 IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
2079 IEEE80211_STYPE_PROBE_RESP
);
2081 printk(KERN_DEBUG
"%s: Could not allocate ProbeResp "
2082 "template for IBSS\n", dev
->name
);
2085 if (local
->ops
->beacon_update
&&
2086 local
->ops
->beacon_update(local_to_hw(local
),
2087 skb
, &control
) == 0) {
2088 printk(KERN_DEBUG
"%s: Configured IBSS beacon "
2089 "template based on scan results\n", dev
->name
);
2094 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
2095 int rate
= (bss
->supp_rates
[i
] & 0x7f) * 5;
2096 if (local
->hw
.conf
.phymode
== MODE_ATHEROS_TURBO
)
2098 for (j
= 0; j
< local
->num_curr_rates
; j
++)
2099 if (local
->curr_rates
[j
].rate
== rate
)
2102 ifsta
->supp_rates_bits
= rates
;
2106 printk(KERN_DEBUG
"%s: Failed to configure IBSS beacon "
2107 "template\n", dev
->name
);
2111 ifsta
->state
= IEEE80211_IBSS_JOINED
;
2112 schedule_delayed_work(&ifsta
->work
, IEEE80211_IBSS_MERGE_INTERVAL
);
2114 ieee80211_rx_bss_put(dev
, bss
);
2120 static int ieee80211_sta_create_ibss(struct net_device
*dev
,
2121 struct ieee80211_if_sta
*ifsta
)
2123 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2124 struct ieee80211_sta_bss
*bss
;
2125 struct ieee80211_sub_if_data
*sdata
;
2126 u8 bssid
[ETH_ALEN
], *pos
;
2130 /* Easier testing, use fixed BSSID. */
2131 memset(bssid
, 0xfe, ETH_ALEN
);
2133 /* Generate random, not broadcast, locally administered BSSID. Mix in
2134 * own MAC address to make sure that devices that do not have proper
2135 * random number generator get different BSSID. */
2136 get_random_bytes(bssid
, ETH_ALEN
);
2137 for (i
= 0; i
< ETH_ALEN
; i
++)
2138 bssid
[i
] ^= dev
->dev_addr
[i
];
2143 printk(KERN_DEBUG
"%s: Creating new IBSS network, BSSID " MAC_FMT
"\n",
2144 dev
->name
, MAC_ARG(bssid
));
2146 bss
= ieee80211_rx_bss_add(dev
, bssid
);
2150 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2152 if (local
->hw
.conf
.beacon_int
== 0)
2153 local
->hw
.conf
.beacon_int
= 100;
2154 bss
->beacon_int
= local
->hw
.conf
.beacon_int
;
2155 bss
->hw_mode
= local
->hw
.conf
.phymode
;
2156 bss
->channel
= local
->hw
.conf
.channel
;
2157 bss
->freq
= local
->hw
.conf
.freq
;
2158 bss
->last_update
= jiffies
;
2159 bss
->capability
= WLAN_CAPABILITY_IBSS
;
2160 if (sdata
->default_key
) {
2161 bss
->capability
|= WLAN_CAPABILITY_PRIVACY
;
2163 sdata
->drop_unencrypted
= 0;
2164 bss
->supp_rates_len
= local
->num_curr_rates
;
2165 pos
= bss
->supp_rates
;
2166 for (i
= 0; i
< local
->num_curr_rates
; i
++) {
2167 int rate
= local
->curr_rates
[i
].rate
;
2168 if (local
->hw
.conf
.phymode
== MODE_ATHEROS_TURBO
)
2170 *pos
++ = (u8
) (rate
/ 5);
2173 return ieee80211_sta_join_ibss(dev
, ifsta
, bss
);
2177 static int ieee80211_sta_find_ibss(struct net_device
*dev
,
2178 struct ieee80211_if_sta
*ifsta
)
2180 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2181 struct ieee80211_sta_bss
*bss
;
2186 if (ifsta
->ssid_len
== 0)
2189 active_ibss
= ieee80211_sta_active_ibss(dev
);
2190 #ifdef CONFIG_D80211_IBSS_DEBUG
2191 printk(KERN_DEBUG
"%s: sta_find_ibss (active_ibss=%d)\n",
2192 dev
->name
, active_ibss
);
2193 #endif /* CONFIG_D80211_IBSS_DEBUG */
2194 spin_lock_bh(&local
->sta_bss_lock
);
2195 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
2196 if (ifsta
->ssid_len
!= bss
->ssid_len
||
2197 memcmp(ifsta
->ssid
, bss
->ssid
, bss
->ssid_len
) != 0
2198 || !(bss
->capability
& WLAN_CAPABILITY_IBSS
))
2200 #ifdef CONFIG_D80211_IBSS_DEBUG
2201 printk(KERN_DEBUG
" bssid=" MAC_FMT
" found\n",
2202 MAC_ARG(bss
->bssid
));
2203 #endif /* CONFIG_D80211_IBSS_DEBUG */
2204 memcpy(bssid
, bss
->bssid
, ETH_ALEN
);
2206 if (active_ibss
|| memcmp(bssid
, ifsta
->bssid
, ETH_ALEN
) != 0)
2209 spin_unlock_bh(&local
->sta_bss_lock
);
2211 #ifdef CONFIG_D80211_IBSS_DEBUG
2212 printk(KERN_DEBUG
" sta_find_ibss: selected " MAC_FMT
" current "
2213 MAC_FMT
"\n", MAC_ARG(bssid
), MAC_ARG(ifsta
->bssid
));
2214 #endif /* CONFIG_D80211_IBSS_DEBUG */
2215 if (found
&& memcmp(ifsta
->bssid
, bssid
, ETH_ALEN
) != 0 &&
2216 (bss
= ieee80211_rx_bss_get(dev
, bssid
))) {
2217 printk(KERN_DEBUG
"%s: Selected IBSS BSSID " MAC_FMT
2218 " based on configured SSID\n",
2219 dev
->name
, MAC_ARG(bssid
));
2220 return ieee80211_sta_join_ibss(dev
, ifsta
, bss
);
2222 #ifdef CONFIG_D80211_IBSS_DEBUG
2223 printk(KERN_DEBUG
" did not try to join ibss\n");
2224 #endif /* CONFIG_D80211_IBSS_DEBUG */
2226 /* Selected IBSS not found in current scan results - try to scan */
2227 if (ifsta
->state
== IEEE80211_IBSS_JOINED
&&
2228 !ieee80211_sta_active_ibss(dev
)) {
2229 schedule_delayed_work(&ifsta
->work
,
2230 IEEE80211_IBSS_MERGE_INTERVAL
);
2231 } else if (time_after(jiffies
, local
->last_scan_completed
+
2232 IEEE80211_SCAN_INTERVAL
)) {
2233 printk(KERN_DEBUG
"%s: Trigger new scan to find an IBSS to "
2234 "join\n", dev
->name
);
2235 return ieee80211_sta_req_scan(dev
, ifsta
->ssid
,
2237 } else if (ifsta
->state
!= IEEE80211_IBSS_JOINED
) {
2238 int interval
= IEEE80211_SCAN_INTERVAL
;
2240 if (time_after(jiffies
, ifsta
->ibss_join_req
+
2241 IEEE80211_IBSS_JOIN_TIMEOUT
)) {
2242 if (ifsta
->create_ibss
&&
2243 ieee80211_ibss_allowed(local
))
2244 return ieee80211_sta_create_ibss(dev
, ifsta
);
2245 if (ifsta
->create_ibss
) {
2246 printk(KERN_DEBUG
"%s: IBSS not allowed on the"
2247 " configured channel %d (%d MHz)\n",
2248 dev
->name
, local
->hw
.conf
.channel
,
2249 local
->hw
.conf
.freq
);
2252 /* No IBSS found - decrease scan interval and continue
2254 interval
= IEEE80211_SCAN_INTERVAL_SLOW
;
2257 ifsta
->state
= IEEE80211_IBSS_SEARCH
;
2258 schedule_delayed_work(&ifsta
->work
, interval
);
2266 int ieee80211_sta_set_ssid(struct net_device
*dev
, char *ssid
, size_t len
)
2268 struct ieee80211_sub_if_data
*sdata
;
2269 struct ieee80211_if_sta
*ifsta
;
2270 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2272 if (len
> IEEE80211_MAX_SSID_LEN
)
2275 /* TODO: This should always be done for IBSS, even if IEEE80211_QOS is
2277 if (local
->ops
->conf_tx
) {
2278 struct ieee80211_tx_queue_params qparam
;
2281 memset(&qparam
, 0, sizeof(qparam
));
2282 /* TODO: are these ok defaults for all hw_modes? */
2285 local
->hw
.conf
.phymode
== MODE_IEEE80211B
? 31 : 15;
2286 qparam
.cw_max
= 1023;
2287 qparam
.burst_time
= 0;
2288 for (i
= IEEE80211_TX_QUEUE_DATA0
; i
< NUM_TX_DATA_QUEUES
; i
++)
2290 local
->ops
->conf_tx(local_to_hw(local
),
2291 i
+ IEEE80211_TX_QUEUE_DATA0
,
2294 /* IBSS uses different parameters for Beacon sending */
2298 local
->ops
->conf_tx(local_to_hw(local
),
2299 IEEE80211_TX_QUEUE_BEACON
, &qparam
);
2302 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2303 ifsta
= &sdata
->u
.sta
;
2305 if (ifsta
->ssid_len
!= len
|| memcmp(ifsta
->ssid
, ssid
, len
) != 0)
2306 ifsta
->prev_bssid_set
= 0;
2307 memcpy(ifsta
->ssid
, ssid
, len
);
2308 memset(ifsta
->ssid
+ len
, 0, IEEE80211_MAX_SSID_LEN
- len
);
2309 ifsta
->ssid_len
= len
;
2311 ifsta
->ssid_set
= 1;
2312 if (sdata
->type
== IEEE80211_IF_TYPE_IBSS
&& !ifsta
->bssid_set
) {
2313 ifsta
->ibss_join_req
= jiffies
;
2314 ifsta
->state
= IEEE80211_IBSS_SEARCH
;
2315 return ieee80211_sta_find_ibss(dev
, ifsta
);
2318 if (ifsta
->bssid_set
&& ifsta
->state
!= IEEE80211_AUTHENTICATE
)
2319 ieee80211_sta_new_auth(dev
, ifsta
);
2325 int ieee80211_sta_get_ssid(struct net_device
*dev
, char *ssid
, size_t *len
)
2327 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2328 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
2329 memcpy(ssid
, ifsta
->ssid
, ifsta
->ssid_len
);
2330 *len
= ifsta
->ssid_len
;
2335 int ieee80211_sta_set_bssid(struct net_device
*dev
, u8
*bssid
)
2337 struct ieee80211_sub_if_data
*sdata
;
2338 struct ieee80211_if_sta
*ifsta
;
2341 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2342 ifsta
= &sdata
->u
.sta
;
2344 if (memcmp(ifsta
->bssid
, bssid
, ETH_ALEN
) != 0) {
2345 memcpy(ifsta
->bssid
, bssid
, ETH_ALEN
);
2346 res
= ieee80211_if_config(dev
);
2348 printk(KERN_DEBUG
"%s: Failed to config new BSSID to "
2349 "the low-level driver\n", dev
->name
);
2354 if (memcmp(bssid
, "\x00\x00\x00\x00\x00\x00", ETH_ALEN
) == 0)
2355 ifsta
->bssid_set
= 0;
2357 ifsta
->bssid_set
= 1;
2358 if (ifsta
->ssid_set
&& ifsta
->state
!= IEEE80211_AUTHENTICATE
)
2359 ieee80211_sta_new_auth(dev
, ifsta
);
2365 static void ieee80211_sta_save_oper_chan(struct net_device
*dev
)
2367 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2368 local
->scan_oper_channel
= local
->hw
.conf
.channel
;
2369 local
->scan_oper_channel_val
= local
->hw
.conf
.channel_val
;
2370 local
->scan_oper_power_level
= local
->hw
.conf
.power_level
;
2371 local
->scan_oper_freq
= local
->hw
.conf
.freq
;
2372 local
->scan_oper_phymode
= local
->hw
.conf
.phymode
;
2373 local
->scan_oper_antenna_max
= local
->hw
.conf
.antenna_max
;
2377 static int ieee80211_sta_restore_oper_chan(struct net_device
*dev
)
2379 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2380 local
->hw
.conf
.channel
= local
->scan_oper_channel
;
2381 local
->hw
.conf
.channel_val
= local
->scan_oper_channel_val
;
2382 local
->hw
.conf
.power_level
= local
->scan_oper_power_level
;
2383 local
->hw
.conf
.freq
= local
->scan_oper_freq
;
2384 local
->hw
.conf
.phymode
= local
->scan_oper_phymode
;
2385 local
->hw
.conf
.antenna_max
= local
->scan_oper_antenna_max
;
2386 return ieee80211_hw_config(local
);
2390 static int ieee80211_active_scan(struct ieee80211_local
*local
)
2392 struct ieee80211_hw_mode
*mode
;
2395 list_for_each_entry(mode
, &local
->modes_list
, list
) {
2396 if (mode
->mode
!= local
->hw
.conf
.phymode
)
2398 for (c
= 0; c
< mode
->num_channels
; c
++) {
2399 struct ieee80211_channel
*chan
= &mode
->channels
[c
];
2400 if (chan
->flag
& IEEE80211_CHAN_W_SCAN
&&
2401 chan
->chan
== local
->hw
.conf
.channel
) {
2402 if (chan
->flag
& IEEE80211_CHAN_W_ACTIVE_SCAN
)
2413 void ieee80211_scan_completed(struct ieee80211_hw
*hw
)
2415 struct ieee80211_local
*local
= hw_to_local(hw
);
2416 struct net_device
*dev
= local
->scan_dev
;
2417 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2418 union iwreq_data wrqu
;
2420 printk(KERN_DEBUG
"%s: scan completed\n", dev
->name
);
2421 local
->sta_scanning
= 0;
2422 local
->last_scan_completed
= jiffies
;
2424 memset(&wrqu
, 0, sizeof(wrqu
));
2425 wireless_send_event(dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
2427 if (sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
2428 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
2429 if (!ifsta
->bssid_set
||
2430 (!ifsta
->state
== IEEE80211_IBSS_JOINED
&&
2431 !ieee80211_sta_active_ibss(dev
)))
2432 ieee80211_sta_find_ibss(dev
, ifsta
);
2435 EXPORT_SYMBOL(ieee80211_scan_completed
);
2437 void ieee80211_sta_scan_work(struct work_struct
*work
)
2439 struct ieee80211_local
*local
=
2440 container_of(work
, struct ieee80211_local
, scan_work
.work
);
2441 struct net_device
*dev
= local
->scan_dev
;
2442 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2443 struct ieee80211_hw_mode
*mode
;
2444 struct ieee80211_channel
*chan
;
2446 unsigned long next_delay
= 0;
2448 if (!local
->sta_scanning
)
2451 switch (local
->scan_state
) {
2452 case SCAN_SET_CHANNEL
:
2453 mode
= local
->scan_hw_mode
;
2454 if (local
->scan_hw_mode
->list
.next
== &local
->modes_list
&&
2455 local
->scan_channel_idx
>= mode
->num_channels
) {
2456 if (ieee80211_sta_restore_oper_chan(dev
)) {
2457 printk(KERN_DEBUG
"%s: failed to restore "
2458 "operational channel after scan\n",
2462 ieee80211_scan_completed(local_to_hw(local
));
2465 skip
= !(local
->enabled_modes
& (1 << mode
->mode
));
2466 chan
= &mode
->channels
[local
->scan_channel_idx
];
2467 if (!(chan
->flag
& IEEE80211_CHAN_W_SCAN
) ||
2468 (sdata
->type
== IEEE80211_IF_TYPE_IBSS
&&
2469 !(chan
->flag
& IEEE80211_CHAN_W_IBSS
)) ||
2470 (local
->hw_modes
& local
->enabled_modes
&
2471 (1 << MODE_IEEE80211G
) && mode
->mode
== MODE_IEEE80211B
))
2476 printk(KERN_DEBUG
"%s: scan channel %d (%d MHz)\n",
2477 dev
->name
, chan
->chan
, chan
->freq
);
2480 local
->hw
.conf
.channel
= chan
->chan
;
2481 local
->hw
.conf
.channel_val
= chan
->val
;
2482 local
->hw
.conf
.power_level
= chan
->power_level
;
2483 local
->hw
.conf
.freq
= chan
->freq
;
2484 local
->hw
.conf
.phymode
= mode
->mode
;
2485 local
->hw
.conf
.antenna_max
= chan
->antenna_max
;
2486 if (ieee80211_hw_config(local
)) {
2487 printk(KERN_DEBUG
"%s: failed to set channel "
2488 "%d (%d MHz) for scan\n", dev
->name
,
2489 chan
->chan
, chan
->freq
);
2494 local
->scan_channel_idx
++;
2495 if (local
->scan_channel_idx
>= local
->scan_hw_mode
->num_channels
) {
2496 if (local
->scan_hw_mode
->list
.next
!= &local
->modes_list
) {
2497 local
->scan_hw_mode
= list_entry(local
->scan_hw_mode
->list
.next
,
2498 struct ieee80211_hw_mode
,
2500 local
->scan_channel_idx
= 0;
2507 next_delay
= IEEE80211_PROBE_DELAY
+
2508 usecs_to_jiffies(local
->hw
.channel_change_time
);
2509 local
->scan_state
= SCAN_SEND_PROBE
;
2511 case SCAN_SEND_PROBE
:
2512 if (ieee80211_active_scan(local
)) {
2513 ieee80211_send_probe_req(dev
, NULL
, local
->scan_ssid
,
2514 local
->scan_ssid_len
);
2515 next_delay
= IEEE80211_CHANNEL_TIME
;
2517 next_delay
= IEEE80211_PASSIVE_CHANNEL_TIME
;
2518 local
->scan_state
= SCAN_SET_CHANNEL
;
2522 if (local
->sta_scanning
) {
2524 schedule_delayed_work(&local
->scan_work
, next_delay
);
2526 schedule_work(&local
->scan_work
.work
);
2531 int ieee80211_sta_req_scan(struct net_device
*dev
, u8
*ssid
, size_t ssid_len
)
2533 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2535 if (ssid_len
> IEEE80211_MAX_SSID_LEN
)
2538 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
2539 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
2542 * ScanType: ACTIVE, PASSIVE
2543 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
2544 * a Probe frame during active scanning
2546 * MinChannelTime (>= ProbeDelay), in TU
2547 * MaxChannelTime: (>= MinChannelTime), in TU
2550 /* MLME-SCAN.confirm
2552 * ResultCode: SUCCESS, INVALID_PARAMETERS
2555 /* TODO: if assoc, move to power save mode for the duration of the
2558 if (local
->sta_scanning
) {
2559 if (local
->scan_dev
== dev
)
2564 printk(KERN_DEBUG
"%s: starting scan\n", dev
->name
);
2566 if (local
->ops
->hw_scan
) {
2567 int rc
= local
->ops
->hw_scan(local_to_hw(local
),
2570 local
->sta_scanning
= 1;
2571 local
->scan_dev
= dev
;
2576 ieee80211_sta_save_oper_chan(dev
);
2578 local
->sta_scanning
= 1;
2579 /* TODO: stop TX queue? */
2582 local
->scan_ssid_len
= ssid_len
;
2583 memcpy(local
->scan_ssid
, ssid
, ssid_len
);
2585 local
->scan_ssid_len
= 0;
2586 local
->scan_state
= SCAN_SET_CHANNEL
;
2587 local
->scan_hw_mode
= list_entry(local
->modes_list
.next
,
2588 struct ieee80211_hw_mode
,
2590 local
->scan_channel_idx
= 0;
2591 local
->scan_dev
= dev
;
2592 schedule_work(&local
->scan_work
.work
);
2599 ieee80211_sta_scan_result(struct net_device
*dev
,
2600 struct ieee80211_sta_bss
*bss
,
2601 char *current_ev
, char *end_buf
)
2603 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2604 struct iw_event iwe
;
2606 if (time_after(jiffies
,
2607 bss
->last_update
+ IEEE80211_SCAN_RESULT_EXPIRE
))
2610 if (!(local
->enabled_modes
& (1 << bss
->hw_mode
)))
2613 if (local
->scan_flags
& IEEE80211_SCAN_WPA_ONLY
&&
2614 !bss
->wpa_ie
&& !bss
->rsn_ie
)
2617 if (local
->scan_flags
& IEEE80211_SCAN_MATCH_SSID
&&
2618 (local
->scan_ssid_len
!= bss
->ssid_len
||
2619 memcmp(local
->scan_ssid
, bss
->ssid
, bss
->ssid_len
) != 0))
2622 memset(&iwe
, 0, sizeof(iwe
));
2623 iwe
.cmd
= SIOCGIWAP
;
2624 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
2625 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->bssid
, ETH_ALEN
);
2626 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
2629 memset(&iwe
, 0, sizeof(iwe
));
2630 iwe
.cmd
= SIOCGIWESSID
;
2631 iwe
.u
.data
.length
= bss
->ssid_len
;
2632 iwe
.u
.data
.flags
= 1;
2633 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
2636 if (bss
->capability
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
)) {
2637 memset(&iwe
, 0, sizeof(iwe
));
2638 iwe
.cmd
= SIOCGIWMODE
;
2639 if (bss
->capability
& WLAN_CAPABILITY_ESS
)
2640 iwe
.u
.mode
= IW_MODE_MASTER
;
2642 iwe
.u
.mode
= IW_MODE_ADHOC
;
2643 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
2647 memset(&iwe
, 0, sizeof(iwe
));
2648 iwe
.cmd
= SIOCGIWFREQ
;
2649 iwe
.u
.freq
.m
= bss
->freq
* 100000;
2651 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
2654 memset(&iwe
, 0, sizeof(iwe
));
2655 iwe
.cmd
= SIOCGIWENCODE
;
2656 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
2657 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
2659 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
2660 iwe
.u
.data
.length
= 0;
2661 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
, "");
2663 if (bss
&& bss
->wpa_ie
) {
2666 buf
= kmalloc(30 + bss
->wpa_ie_len
* 2, GFP_ATOMIC
);
2669 p
+= sprintf(p
, "wpa_ie=");
2670 for (i
= 0; i
< bss
->wpa_ie_len
; i
++)
2671 p
+= sprintf(p
, "%02x", bss
->wpa_ie
[i
]);
2672 memset(&iwe
, 0, sizeof(iwe
));
2673 iwe
.cmd
= IWEVCUSTOM
;
2674 iwe
.u
.data
.length
= strlen(buf
);
2675 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
2681 if (bss
&& bss
->rsn_ie
) {
2684 buf
= kmalloc(30 + bss
->rsn_ie_len
* 2, GFP_ATOMIC
);
2687 p
+= sprintf(p
, "rsn_ie=");
2688 for (i
= 0; i
< bss
->rsn_ie_len
; i
++)
2689 p
+= sprintf(p
, "%02x", bss
->rsn_ie
[i
]);
2690 memset(&iwe
, 0, sizeof(iwe
));
2691 iwe
.cmd
= IWEVCUSTOM
;
2692 iwe
.u
.data
.length
= strlen(buf
);
2693 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
2701 buf
= kmalloc(30, GFP_ATOMIC
);
2703 memset(&iwe
, 0, sizeof(iwe
));
2704 iwe
.cmd
= IWEVCUSTOM
;
2705 sprintf(buf
, "tsf=%016llx", (unsigned long long)(bss
->timestamp
));
2706 iwe
.u
.data
.length
= strlen(buf
);
2707 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
2717 if (!(local
->scan_flags
& IEEE80211_SCAN_EXTRA_INFO
))
2720 buf
= kmalloc(100, GFP_ATOMIC
);
2724 memset(&iwe
, 0, sizeof(iwe
));
2725 iwe
.cmd
= IWEVCUSTOM
;
2726 sprintf(buf
, "bcn_int=%d", bss
->beacon_int
);
2727 iwe
.u
.data
.length
= strlen(buf
);
2728 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
2731 memset(&iwe
, 0, sizeof(iwe
));
2732 iwe
.cmd
= IWEVCUSTOM
;
2733 sprintf(buf
, "rssi=%d", bss
->rssi
);
2734 iwe
.u
.data
.length
= strlen(buf
);
2735 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
2738 memset(&iwe
, 0, sizeof(iwe
));
2739 iwe
.cmd
= IWEVCUSTOM
;
2740 sprintf(buf
, "capab=0x%04x", bss
->capability
);
2741 iwe
.u
.data
.length
= strlen(buf
);
2742 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
2745 /* dispaly all support rates in readable format */
2746 p
= current_ev
+ IW_EV_LCP_LEN
;
2747 iwe
.cmd
= SIOCGIWRATE
;
2748 /* Those two flags are ignored... */
2749 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
2751 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
2752 iwe
.u
.bitrate
.value
= ((bss
->supp_rates
[i
] &
2754 p
= iwe_stream_add_value(current_ev
, p
,
2755 end_buf
, &iwe
, IW_EV_PARAM_LEN
);
2757 /* Check if we added any rate */
2758 if((p
- current_ev
) > IW_EV_LCP_LEN
)
2769 int ieee80211_sta_scan_results(struct net_device
*dev
, char *buf
, size_t len
)
2771 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2772 char *current_ev
= buf
;
2773 char *end_buf
= buf
+ len
;
2774 struct ieee80211_sta_bss
*bss
;
2776 spin_lock_bh(&local
->sta_bss_lock
);
2777 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
2778 if (buf
+ len
- current_ev
<= IW_EV_ADDR_LEN
) {
2779 spin_unlock_bh(&local
->sta_bss_lock
);
2782 current_ev
= ieee80211_sta_scan_result(dev
, bss
, current_ev
,
2785 spin_unlock_bh(&local
->sta_bss_lock
);
2786 return current_ev
- buf
;
2790 int ieee80211_sta_set_extra_ie(struct net_device
*dev
, char *ie
, size_t len
)
2792 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2793 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
2794 kfree(ifsta
->extra_ie
);
2796 ifsta
->extra_ie
= NULL
;
2797 ifsta
->extra_ie_len
= 0;
2800 ifsta
->extra_ie
= kmalloc(len
, GFP_KERNEL
);
2801 if (!ifsta
->extra_ie
) {
2802 ifsta
->extra_ie_len
= 0;
2805 memcpy(ifsta
->extra_ie
, ie
, len
);
2806 ifsta
->extra_ie_len
= len
;
2807 if (ifsta
->bssid_set
&& ifsta
->ssid_set
&&
2808 ifsta
->state
!= IEEE80211_AUTHENTICATE
)
2809 ieee80211_sta_new_auth(dev
, ifsta
);
2814 struct sta_info
* ieee80211_ibss_add_sta(struct net_device
*dev
,
2815 struct sk_buff
*skb
, u8
*bssid
,
2818 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2819 struct sta_info
*sta
;
2820 struct ieee80211_sub_if_data
*sdata
= NULL
;
2821 struct net_device
*sta_dev
= NULL
;
2823 /* TODO: Could consider removing the least recently used entry and
2824 * allow new one to be added. */
2825 if (local
->num_sta
>= IEEE80211_IBSS_MAX_STA_ENTRIES
) {
2826 if (net_ratelimit()) {
2827 printk(KERN_DEBUG
"%s: No room for a new IBSS STA "
2828 "entry " MAC_FMT
"\n", dev
->name
, MAC_ARG(addr
));
2833 spin_lock_bh(&local
->sub_if_lock
);
2834 list_for_each_entry(sdata
, &local
->sub_if_list
, list
)
2835 if (sdata
->type
== IEEE80211_IF_TYPE_IBSS
&&
2836 memcmp(bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
) == 0) {
2837 sta_dev
= sdata
->dev
;
2840 spin_unlock_bh(&local
->sub_if_lock
);
2845 printk(KERN_DEBUG
"%s: Adding new IBSS station " MAC_FMT
" (dev=%s)\n",
2846 dev
->name
, MAC_ARG(addr
), sta_dev
->name
);
2848 sta
= sta_info_add(local
, dev
, addr
, GFP_ATOMIC
);
2853 sta
->supp_rates
= sdata
->u
.sta
.supp_rates_bits
;
2855 rate_control_rate_init(sta
, local
);
2857 return sta
; /* caller will call sta_info_put() */
2861 int ieee80211_sta_deauthenticate(struct net_device
*dev
, u16 reason
)
2863 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2864 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
2866 printk(KERN_DEBUG
"%s: deauthenticate(reason=%d)\n",
2869 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
2870 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
2873 ieee80211_send_deauth(dev
, ifsta
, reason
);
2874 ieee80211_set_disassoc(dev
, ifsta
, 1);
2879 int ieee80211_sta_disassociate(struct net_device
*dev
, u16 reason
)
2881 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2882 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
2884 printk(KERN_DEBUG
"%s: disassociate(reason=%d)\n",
2887 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
2890 if (!ifsta
->associated
)
2893 ieee80211_send_disassoc(dev
, ifsta
, reason
);
2894 ieee80211_set_disassoc(dev
, ifsta
, 0);