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 <net/d80211_mgmt.h>
30 #include "ieee80211_i.h"
31 #include "ieee80211_rate.h"
32 #include "hostapd_ioctl.h"
34 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
35 #define IEEE80211_AUTH_MAX_TRIES 3
36 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
37 #define IEEE80211_ASSOC_MAX_TRIES 3
38 #define IEEE80211_MONITORING_INTERVAL (2 * HZ)
39 #define IEEE80211_PROBE_INTERVAL (60 * HZ)
40 #define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
41 #define IEEE80211_SCAN_INTERVAL (2 * HZ)
42 #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ)
43 #define IEEE80211_IBSS_JOIN_TIMEOUT (20 * HZ)
45 #define IEEE80211_PROBE_DELAY (HZ / 33)
46 #define IEEE80211_CHANNEL_TIME (HZ / 33)
47 #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5)
48 #define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ)
49 #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
50 #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
52 #define IEEE80211_IBSS_MAX_STA_ENTRIES 128
55 #define IEEE80211_FC(type, stype) cpu_to_le16(type | stype)
57 #define ERP_INFO_USE_PROTECTION BIT(1)
59 static void ieee80211_send_probe_req(struct net_device
*dev
, u8
*dst
,
60 u8
*ssid
, size_t ssid_len
);
61 static struct ieee80211_sta_bss
*
62 ieee80211_rx_bss_get(struct net_device
*dev
, u8
*bssid
);
63 static void ieee80211_rx_bss_put(struct net_device
*dev
,
64 struct ieee80211_sta_bss
*bss
);
65 static int ieee80211_sta_find_ibss(struct net_device
*dev
,
66 struct ieee80211_if_sta
*ifsta
);
67 static int ieee80211_sta_wep_configured(struct net_device
*dev
);
70 /* Parsed Information Elements */
71 struct ieee802_11_elems
{
95 u8 ext_supp_rates_len
;
102 typedef enum { ParseOK
= 0, ParseUnknown
= 1, ParseFailed
= -1 } ParseRes
;
105 static ParseRes
ieee802_11_parse_elems(u8
*start
, size_t len
,
106 struct ieee802_11_elems
*elems
)
112 memset(elems
, 0, sizeof(*elems
));
124 printk(KERN_DEBUG
"IEEE 802.11 element parse "
125 "failed (id=%d elen=%d left=%d)\n",
134 elems
->ssid_len
= elen
;
136 case WLAN_EID_SUPP_RATES
:
137 elems
->supp_rates
= pos
;
138 elems
->supp_rates_len
= elen
;
140 case WLAN_EID_FH_PARAMS
:
141 elems
->fh_params
= pos
;
142 elems
->fh_params_len
= elen
;
144 case WLAN_EID_DS_PARAMS
:
145 elems
->ds_params
= pos
;
146 elems
->ds_params_len
= elen
;
148 case WLAN_EID_CF_PARAMS
:
149 elems
->cf_params
= pos
;
150 elems
->cf_params_len
= elen
;
154 elems
->tim_len
= elen
;
156 case WLAN_EID_IBSS_PARAMS
:
157 elems
->ibss_params
= pos
;
158 elems
->ibss_params_len
= elen
;
160 case WLAN_EID_CHALLENGE
:
161 elems
->challenge
= pos
;
162 elems
->challenge_len
= elen
;
165 if (elen
>= 4 && pos
[0] == 0x00 && pos
[1] == 0x50 &&
167 /* Microsoft OUI (00:50:F2) */
169 /* OUI Type 1 - WPA IE */
171 elems
->wpa_len
= elen
;
172 } else if (elen
>= 5 && pos
[3] == 2) {
174 elems
->wmm_info
= pos
;
175 elems
->wmm_info_len
= elen
;
176 } else if (pos
[4] == 1) {
177 elems
->wmm_param
= pos
;
178 elems
->wmm_param_len
= elen
;
185 elems
->rsn_len
= elen
;
187 case WLAN_EID_ERP_INFO
:
188 elems
->erp_info
= pos
;
189 elems
->erp_info_len
= elen
;
191 case WLAN_EID_EXT_SUPP_RATES
:
192 elems
->ext_supp_rates
= pos
;
193 elems
->ext_supp_rates_len
= elen
;
197 printk(KERN_DEBUG
"IEEE 802.11 element parse ignored "
198 "unknown element (id=%d elen=%d)\n",
209 /* Do not trigger error if left == 1 as Apple Airport base stations
210 * send AssocResps that are one spurious byte too long. */
212 return unknown
? ParseUnknown
: ParseOK
;
218 static int ecw2cw(int ecw
)
229 static void ieee80211_sta_wmm_params(struct net_device
*dev
,
230 struct ieee80211_if_sta
*ifsta
,
231 u8
*wmm_param
, size_t wmm_param_len
)
233 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
234 struct ieee80211_tx_queue_params params
;
239 if (wmm_param_len
< 8 || wmm_param
[5] /* version */ != 1)
241 count
= wmm_param
[6] & 0x0f;
242 if (count
== ifsta
->wmm_last_param_set
)
244 ifsta
->wmm_last_param_set
= count
;
247 left
= wmm_param_len
- 8;
249 memset(¶ms
, 0, sizeof(params
));
251 if (!local
->ops
->conf_tx
)
255 for (; left
>= 4; left
-= 4, pos
+= 4) {
256 int aci
= (pos
[0] >> 5) & 0x03;
257 int acm
= (pos
[0] >> 4) & 0x01;
262 queue
= IEEE80211_TX_QUEUE_DATA3
;
264 local
->wmm_acm
|= BIT(1) | BIT(2);
268 queue
= IEEE80211_TX_QUEUE_DATA1
;
270 local
->wmm_acm
|= BIT(4) | BIT(5);
274 queue
= IEEE80211_TX_QUEUE_DATA0
;
276 local
->wmm_acm
|= BIT(6) | BIT(7);
281 queue
= IEEE80211_TX_QUEUE_DATA2
;
283 local
->wmm_acm
|= BIT(0) | BIT(3);
288 params
.aifs
= pos
[0] & 0x0f;
289 params
.cw_max
= ecw2cw((pos
[1] & 0xf0) >> 4);
290 params
.cw_min
= ecw2cw(pos
[1] & 0x0f);
291 /* TXOP is in units of 32 usec; burst_time in 0.1 ms */
292 params
.burst_time
= (pos
[2] | (pos
[3] << 8)) * 32 / 100;
293 printk(KERN_DEBUG
"%s: WMM queue=%d aci=%d acm=%d aifs=%d "
294 "cWmin=%d cWmax=%d burst=%d\n",
295 dev
->name
, queue
, aci
, acm
, params
.aifs
, params
.cw_min
,
296 params
.cw_max
, params
.burst_time
);
297 /* TODO: handle ACM (block TX, fallback to next lowest allowed
299 if (local
->ops
->conf_tx(local_to_hw(local
), queue
, ¶ms
)) {
300 printk(KERN_DEBUG
"%s: failed to set TX queue "
301 "parameters for queue %d\n", dev
->name
, queue
);
307 static void ieee80211_sta_send_associnfo(struct net_device
*dev
,
308 struct ieee80211_if_sta
*ifsta
)
313 union iwreq_data wrqu
;
315 if (!ifsta
->assocreq_ies
&& !ifsta
->assocresp_ies
)
318 buf
= kmalloc(50 + 2 * (ifsta
->assocreq_ies_len
+
319 ifsta
->assocresp_ies_len
), GFP_ATOMIC
);
323 len
= sprintf(buf
, "ASSOCINFO(");
324 if (ifsta
->assocreq_ies
) {
325 len
+= sprintf(buf
+ len
, "ReqIEs=");
326 for (i
= 0; i
< ifsta
->assocreq_ies_len
; i
++) {
327 len
+= sprintf(buf
+ len
, "%02x",
328 ifsta
->assocreq_ies
[i
]);
331 if (ifsta
->assocresp_ies
) {
332 if (ifsta
->assocreq_ies
)
333 len
+= sprintf(buf
+ len
, " ");
334 len
+= sprintf(buf
+ len
, "RespIEs=");
335 for (i
= 0; i
< ifsta
->assocresp_ies_len
; i
++) {
336 len
+= sprintf(buf
+ len
, "%02x",
337 ifsta
->assocresp_ies
[i
]);
340 len
+= sprintf(buf
+ len
, ")");
342 if (len
> IW_CUSTOM_MAX
) {
343 len
= sprintf(buf
, "ASSOCRESPIE=");
344 for (i
= 0; i
< ifsta
->assocresp_ies_len
; i
++) {
345 len
+= sprintf(buf
+ len
, "%02x",
346 ifsta
->assocresp_ies
[i
]);
350 memset(&wrqu
, 0, sizeof(wrqu
));
351 wrqu
.data
.length
= len
;
352 wireless_send_event(dev
, IWEVCUSTOM
, &wrqu
, buf
);
358 static void ieee80211_set_associated(struct net_device
*dev
,
359 struct ieee80211_if_sta
*ifsta
, int assoc
)
361 union iwreq_data wrqu
;
363 if (ifsta
->associated
== assoc
)
366 ifsta
->associated
= assoc
;
369 struct ieee80211_sub_if_data
*sdata
;
370 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
371 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
373 ifsta
->prev_bssid_set
= 1;
374 memcpy(ifsta
->prev_bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
375 memcpy(wrqu
.ap_addr
.sa_data
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
376 ieee80211_sta_send_associnfo(dev
, ifsta
);
378 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
380 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
381 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
382 ifsta
->last_probe
= jiffies
;
385 static void ieee80211_set_disassoc(struct net_device
*dev
,
386 struct ieee80211_if_sta
*ifsta
, int deauth
)
389 ifsta
->auth_tries
= 0;
390 ifsta
->assoc_tries
= 0;
391 ieee80211_set_associated(dev
, ifsta
, 0);
394 static void ieee80211_sta_tx(struct net_device
*dev
, struct sk_buff
*skb
,
395 int encrypt
, int probe_resp
)
397 struct ieee80211_sub_if_data
*sdata
;
398 struct ieee80211_tx_packet_data
*pkt_data
;
400 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
401 skb
->dev
= sdata
->local
->mdev
;
402 skb
->mac
.raw
= skb
->nh
.raw
= skb
->h
.raw
= skb
->data
;
404 pkt_data
= (struct ieee80211_tx_packet_data
*) skb
->cb
;
405 memset(pkt_data
, 0, sizeof(struct ieee80211_tx_packet_data
));
406 pkt_data
->ifindex
= sdata
->dev
->ifindex
;
407 pkt_data
->mgmt_iface
= (sdata
->type
== IEEE80211_IF_TYPE_MGMT
);
408 pkt_data
->do_not_encrypt
= !encrypt
;
410 pkt_data
->pkt_probe_resp
= 1;
416 static void ieee80211_send_auth(struct net_device
*dev
,
417 struct ieee80211_if_sta
*ifsta
,
418 int transaction
, u8
*extra
, size_t extra_len
,
422 struct ieee80211_mgmt
*mgmt
;
424 skb
= dev_alloc_skb(sizeof(*mgmt
) + 6 + extra_len
);
426 printk(KERN_DEBUG
"%s: failed to allocate buffer for auth "
427 "frame\n", dev
->name
);
431 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24 + 6);
432 memset(mgmt
, 0, 24 + 6);
433 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
434 IEEE80211_STYPE_AUTH
);
436 mgmt
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PROTECTED
);
437 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
438 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
439 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
440 mgmt
->u
.auth
.auth_alg
= cpu_to_le16(ifsta
->auth_alg
);
441 mgmt
->u
.auth
.auth_transaction
= cpu_to_le16(transaction
);
442 ifsta
->auth_transaction
= transaction
+ 1;
443 mgmt
->u
.auth
.status_code
= cpu_to_le16(0);
445 memcpy(skb_put(skb
, extra_len
), extra
, extra_len
);
447 ieee80211_sta_tx(dev
, skb
, encrypt
, 0);
451 static void ieee80211_authenticate(struct net_device
*dev
,
452 struct ieee80211_if_sta
*ifsta
)
455 if (ifsta
->auth_tries
> IEEE80211_AUTH_MAX_TRIES
) {
456 printk(KERN_DEBUG
"%s: authentication with AP " MAC_FMT
458 dev
->name
, MAC_ARG(ifsta
->bssid
));
462 ifsta
->state
= IEEE80211_AUTHENTICATE
;
463 printk(KERN_DEBUG
"%s: authenticate with AP " MAC_FMT
"\n",
464 dev
->name
, MAC_ARG(ifsta
->bssid
));
466 ieee80211_send_auth(dev
, ifsta
, 1, NULL
, 0, 0);
468 schedule_delayed_work(&ifsta
->work
, IEEE80211_AUTH_TIMEOUT
);
472 static void ieee80211_send_assoc(struct net_device
*dev
,
473 struct ieee80211_if_sta
*ifsta
)
475 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
477 struct ieee80211_mgmt
*mgmt
;
481 struct ieee80211_sta_bss
*bss
;
484 skb
= dev_alloc_skb(sizeof(*mgmt
) + 200 + ifsta
->extra_ie_len
+
487 printk(KERN_DEBUG
"%s: failed to allocate buffer for assoc "
488 "frame\n", dev
->name
);
492 capab
= ifsta
->capab
;
493 if (local
->hw
.conf
.phymode
== MODE_IEEE80211G
) {
494 capab
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
|
495 WLAN_CAPABILITY_SHORT_PREAMBLE
;
497 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
);
499 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
500 capab
|= WLAN_CAPABILITY_PRIVACY
;
504 ieee80211_rx_bss_put(dev
, bss
);
507 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
509 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
510 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
511 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
513 if (ifsta
->prev_bssid_set
) {
515 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
516 IEEE80211_STYPE_REASSOC_REQ
);
517 mgmt
->u
.reassoc_req
.capab_info
= cpu_to_le16(capab
);
518 mgmt
->u
.reassoc_req
.listen_interval
= cpu_to_le16(1);
519 memcpy(mgmt
->u
.reassoc_req
.current_ap
, ifsta
->prev_bssid
,
523 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
524 IEEE80211_STYPE_ASSOC_REQ
);
525 mgmt
->u
.assoc_req
.capab_info
= cpu_to_le16(capab
);
526 mgmt
->u
.assoc_req
.listen_interval
= cpu_to_le16(1);
530 ies
= pos
= skb_put(skb
, 2 + ifsta
->ssid_len
);
531 *pos
++ = WLAN_EID_SSID
;
532 *pos
++ = ifsta
->ssid_len
;
533 memcpy(pos
, ifsta
->ssid
, ifsta
->ssid_len
);
535 len
= local
->num_curr_rates
;
538 pos
= skb_put(skb
, len
+ 2);
539 *pos
++ = WLAN_EID_SUPP_RATES
;
541 for (i
= 0; i
< len
; i
++) {
542 int rate
= local
->curr_rates
[i
].rate
;
543 if (local
->hw
.conf
.phymode
== MODE_ATHEROS_TURBO
)
545 *pos
++ = (u8
) (rate
/ 5);
548 if (local
->num_curr_rates
> len
) {
549 pos
= skb_put(skb
, local
->num_curr_rates
- len
+ 2);
550 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
551 *pos
++ = local
->num_curr_rates
- len
;
552 for (i
= len
; i
< local
->num_curr_rates
; i
++) {
553 int rate
= local
->curr_rates
[i
].rate
;
554 if (local
->hw
.conf
.phymode
== MODE_ATHEROS_TURBO
)
556 *pos
++ = (u8
) (rate
/ 5);
560 if (ifsta
->extra_ie
) {
561 pos
= skb_put(skb
, ifsta
->extra_ie_len
);
562 memcpy(pos
, ifsta
->extra_ie
, ifsta
->extra_ie_len
);
565 if (wmm
&& ifsta
->wmm_enabled
) {
566 pos
= skb_put(skb
, 9);
567 *pos
++ = WLAN_EID_VENDOR_SPECIFIC
;
568 *pos
++ = 7; /* len */
569 *pos
++ = 0x00; /* Microsoft OUI 00:50:F2 */
572 *pos
++ = 2; /* WME */
573 *pos
++ = 0; /* WME info */
574 *pos
++ = 1; /* WME ver */
578 kfree(ifsta
->assocreq_ies
);
579 ifsta
->assocreq_ies_len
= (skb
->data
+ skb
->len
) - ies
;
580 ifsta
->assocreq_ies
= kmalloc(ifsta
->assocreq_ies_len
, GFP_ATOMIC
);
581 if (ifsta
->assocreq_ies
)
582 memcpy(ifsta
->assocreq_ies
, ies
, ifsta
->assocreq_ies_len
);
584 ieee80211_sta_tx(dev
, skb
, 0, 0);
588 static void ieee80211_send_deauth(struct net_device
*dev
,
589 struct ieee80211_if_sta
*ifsta
, u16 reason
)
592 struct ieee80211_mgmt
*mgmt
;
594 skb
= dev_alloc_skb(sizeof(*mgmt
));
596 printk(KERN_DEBUG
"%s: failed to allocate buffer for deauth "
597 "frame\n", dev
->name
);
601 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
603 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
604 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
605 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
606 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
607 IEEE80211_STYPE_DEAUTH
);
609 mgmt
->u
.deauth
.reason_code
= cpu_to_le16(reason
);
611 ieee80211_sta_tx(dev
, skb
, 0, 0);
615 static void ieee80211_send_disassoc(struct net_device
*dev
,
616 struct ieee80211_if_sta
*ifsta
, u16 reason
)
619 struct ieee80211_mgmt
*mgmt
;
621 skb
= dev_alloc_skb(sizeof(*mgmt
));
623 printk(KERN_DEBUG
"%s: failed to allocate buffer for disassoc "
624 "frame\n", dev
->name
);
628 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
630 memcpy(mgmt
->da
, ifsta
->bssid
, ETH_ALEN
);
631 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
632 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
633 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
634 IEEE80211_STYPE_DISASSOC
);
636 mgmt
->u
.disassoc
.reason_code
= cpu_to_le16(reason
);
638 ieee80211_sta_tx(dev
, skb
, 0, 0);
642 static int ieee80211_privacy_mismatch(struct net_device
*dev
,
643 struct ieee80211_if_sta
*ifsta
)
645 struct ieee80211_sta_bss
*bss
;
648 if (!ifsta
|| ifsta
->mixed_cell
||
649 ifsta
->key_mgmt
!= IEEE80211_KEY_MGMT_NONE
)
652 bss
= ieee80211_rx_bss_get(dev
, ifsta
->bssid
);
656 if (ieee80211_sta_wep_configured(dev
) !=
657 !!(bss
->capability
& WLAN_CAPABILITY_PRIVACY
))
660 ieee80211_rx_bss_put(dev
, bss
);
666 static void ieee80211_associate(struct net_device
*dev
,
667 struct ieee80211_if_sta
*ifsta
)
669 ifsta
->assoc_tries
++;
670 if (ifsta
->assoc_tries
> IEEE80211_ASSOC_MAX_TRIES
) {
671 printk(KERN_DEBUG
"%s: association with AP " MAC_FMT
673 dev
->name
, MAC_ARG(ifsta
->bssid
));
677 ifsta
->state
= IEEE80211_ASSOCIATE
;
678 printk(KERN_DEBUG
"%s: associate with AP " MAC_FMT
"\n",
679 dev
->name
, MAC_ARG(ifsta
->bssid
));
680 if (ieee80211_privacy_mismatch(dev
, ifsta
)) {
681 printk(KERN_DEBUG
"%s: mismatch in privacy configuration and "
682 "mixed-cell disabled - abort association\n", dev
->name
);
686 ieee80211_send_assoc(dev
, ifsta
);
688 schedule_delayed_work(&ifsta
->work
, IEEE80211_ASSOC_TIMEOUT
);
692 static void ieee80211_associated(struct net_device
*dev
,
693 struct ieee80211_if_sta
*ifsta
)
695 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
696 struct sta_info
*sta
;
699 /* TODO: start monitoring current AP signal quality and number of
700 * missed beacons. Scan other channels every now and then and search
702 /* TODO: remove expired BSSes */
704 ifsta
->state
= IEEE80211_ASSOCIATED
;
706 sta
= sta_info_get(local
, ifsta
->bssid
);
708 printk(KERN_DEBUG
"%s: No STA entry for own AP " MAC_FMT
"\n",
709 dev
->name
, MAC_ARG(ifsta
->bssid
));
713 if (time_after(jiffies
,
714 sta
->last_rx
+ IEEE80211_MONITORING_INTERVAL
)) {
715 if (ifsta
->probereq_poll
) {
716 printk(KERN_DEBUG
"%s: No ProbeResp from "
717 "current AP " MAC_FMT
" - assume out of "
719 dev
->name
, MAC_ARG(ifsta
->bssid
));
721 sta_info_free(sta
, 0);
722 ifsta
->probereq_poll
= 0;
724 ieee80211_send_probe_req(dev
, ifsta
->bssid
,
726 local
->scan_ssid_len
);
727 ifsta
->probereq_poll
= 1;
730 ifsta
->probereq_poll
= 0;
731 if (time_after(jiffies
, ifsta
->last_probe
+
732 IEEE80211_PROBE_INTERVAL
)) {
733 ifsta
->last_probe
= jiffies
;
734 ieee80211_send_probe_req(dev
, ifsta
->bssid
,
742 union iwreq_data wrqu
;
743 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
744 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
745 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
746 schedule_delayed_work(&ifsta
->work
,
747 IEEE80211_MONITORING_INTERVAL
+ 30 * HZ
);
749 schedule_delayed_work(&ifsta
->work
,
750 IEEE80211_MONITORING_INTERVAL
);
755 static void ieee80211_send_probe_req(struct net_device
*dev
, u8
*dst
,
756 u8
*ssid
, size_t ssid_len
)
758 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
760 struct ieee80211_mgmt
*mgmt
;
761 u8
*pos
, *supp_rates
, *esupp_rates
= NULL
;
764 skb
= dev_alloc_skb(sizeof(*mgmt
) + 200);
766 printk(KERN_DEBUG
"%s: failed to allocate buffer for probe "
767 "request\n", dev
->name
);
771 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
773 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
774 IEEE80211_STYPE_PROBE_REQ
);
775 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
777 memcpy(mgmt
->da
, dst
, ETH_ALEN
);
778 memcpy(mgmt
->bssid
, dst
, ETH_ALEN
);
780 memset(mgmt
->da
, 0xff, ETH_ALEN
);
781 memset(mgmt
->bssid
, 0xff, ETH_ALEN
);
783 pos
= skb_put(skb
, 2 + ssid_len
);
784 *pos
++ = WLAN_EID_SSID
;
786 memcpy(pos
, ssid
, ssid_len
);
788 supp_rates
= skb_put(skb
, 2);
789 supp_rates
[0] = WLAN_EID_SUPP_RATES
;
791 for (i
= 0; i
< local
->num_curr_rates
; i
++) {
792 struct ieee80211_rate
*rate
= &local
->curr_rates
[i
];
793 if (!(rate
->flags
& IEEE80211_RATE_SUPPORTED
))
796 pos
= skb_put(skb
, 1);
798 } else if (supp_rates
[1] == 8) {
799 esupp_rates
= skb_put(skb
, 3);
800 esupp_rates
[0] = WLAN_EID_EXT_SUPP_RATES
;
802 pos
= &esupp_rates
[2];
804 pos
= skb_put(skb
, 1);
807 if (local
->hw
.conf
.phymode
== MODE_ATHEROS_TURBO
)
808 *pos
= rate
->rate
/ 10;
810 *pos
= rate
->rate
/ 5;
813 ieee80211_sta_tx(dev
, skb
, 0, 0);
817 static int ieee80211_sta_wep_configured(struct net_device
*dev
)
819 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
820 if (!sdata
|| !sdata
->default_key
||
821 sdata
->default_key
->alg
!= ALG_WEP
)
827 static void ieee80211_auth_completed(struct net_device
*dev
,
828 struct ieee80211_if_sta
*ifsta
)
830 printk(KERN_DEBUG
"%s: authenticated\n", dev
->name
);
831 ifsta
->authenticated
= 1;
832 ieee80211_associate(dev
, ifsta
);
836 static void ieee80211_auth_challenge(struct net_device
*dev
,
837 struct ieee80211_if_sta
*ifsta
,
838 struct ieee80211_mgmt
*mgmt
,
840 struct ieee80211_rx_status
*rx_status
)
843 struct ieee802_11_elems elems
;
845 printk(KERN_DEBUG
"%s: replying to auth challenge\n", dev
->name
);
846 pos
= mgmt
->u
.auth
.variable
;
847 if (ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
)
849 printk(KERN_DEBUG
"%s: failed to parse Auth(challenge)\n",
853 if (!elems
.challenge
) {
854 printk(KERN_DEBUG
"%s: no challenge IE in shared key auth "
855 "frame\n", dev
->name
);
858 ieee80211_send_auth(dev
, ifsta
, 3, elems
.challenge
- 2,
859 elems
.challenge_len
+ 2, 1);
863 static void ieee80211_rx_mgmt_auth(struct net_device
*dev
,
864 struct ieee80211_if_sta
*ifsta
,
865 struct ieee80211_mgmt
*mgmt
,
867 struct ieee80211_rx_status
*rx_status
)
869 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
870 u16 auth_alg
, auth_transaction
, status_code
;
872 if (ifsta
->state
!= IEEE80211_AUTHENTICATE
&&
873 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
) {
874 printk(KERN_DEBUG
"%s: authentication frame received from "
875 MAC_FMT
", but not in authenticate state - ignored\n",
876 dev
->name
, MAC_ARG(mgmt
->sa
));
881 printk(KERN_DEBUG
"%s: too short (%zd) authentication frame "
882 "received from " MAC_FMT
" - ignored\n",
883 dev
->name
, len
, MAC_ARG(mgmt
->sa
));
887 if (sdata
->type
!= IEEE80211_IF_TYPE_IBSS
&&
888 memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
889 printk(KERN_DEBUG
"%s: authentication frame received from "
890 "unknown AP (SA=" MAC_FMT
" BSSID=" MAC_FMT
") - "
891 "ignored\n", dev
->name
, MAC_ARG(mgmt
->sa
),
892 MAC_ARG(mgmt
->bssid
));
896 if (sdata
->type
!= IEEE80211_IF_TYPE_IBSS
&&
897 memcmp(ifsta
->bssid
, mgmt
->bssid
, ETH_ALEN
) != 0) {
898 printk(KERN_DEBUG
"%s: authentication frame received from "
899 "unknown BSSID (SA=" MAC_FMT
" BSSID=" MAC_FMT
") - "
900 "ignored\n", dev
->name
, MAC_ARG(mgmt
->sa
),
901 MAC_ARG(mgmt
->bssid
));
905 auth_alg
= le16_to_cpu(mgmt
->u
.auth
.auth_alg
);
906 auth_transaction
= le16_to_cpu(mgmt
->u
.auth
.auth_transaction
);
907 status_code
= le16_to_cpu(mgmt
->u
.auth
.status_code
);
909 printk(KERN_DEBUG
"%s: RX authentication from " MAC_FMT
" (alg=%d "
910 "transaction=%d status=%d)\n",
911 dev
->name
, MAC_ARG(mgmt
->sa
), auth_alg
,
912 auth_transaction
, status_code
);
914 if (sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
915 /* IEEE 802.11 standard does not require authentication in IBSS
916 * networks and most implementations do not seem to use it.
917 * However, try to reply to authentication attempts if someone
918 * has actually implemented this.
919 * TODO: Could implement shared key authentication. */
920 if (auth_alg
!= WLAN_AUTH_OPEN
|| auth_transaction
!= 1) {
921 printk(KERN_DEBUG
"%s: unexpected IBSS authentication "
922 "frame (alg=%d transaction=%d)\n",
923 dev
->name
, auth_alg
, auth_transaction
);
926 ieee80211_send_auth(dev
, ifsta
, 2, NULL
, 0, 0);
929 if (auth_alg
!= ifsta
->auth_alg
||
930 auth_transaction
!= ifsta
->auth_transaction
) {
931 printk(KERN_DEBUG
"%s: unexpected authentication frame "
932 "(alg=%d transaction=%d)\n",
933 dev
->name
, auth_alg
, auth_transaction
);
937 if (status_code
!= WLAN_STATUS_SUCCESS
) {
938 printk(KERN_DEBUG
"%s: AP denied authentication (auth_alg=%d "
939 "code=%d)\n", dev
->name
, ifsta
->auth_alg
, status_code
);
940 if (status_code
== WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
) {
942 const int num_algs
= ARRAY_SIZE(algs
);
944 algs
[0] = algs
[1] = algs
[2] = 0xff;
945 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_OPEN
)
946 algs
[0] = WLAN_AUTH_OPEN
;
947 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_SHARED_KEY
)
948 algs
[1] = WLAN_AUTH_SHARED_KEY
;
949 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_LEAP
)
950 algs
[2] = WLAN_AUTH_LEAP
;
951 if (ifsta
->auth_alg
== WLAN_AUTH_OPEN
)
953 else if (ifsta
->auth_alg
== WLAN_AUTH_SHARED_KEY
)
957 for (i
= 0; i
< num_algs
; i
++) {
961 if (algs
[pos
] == ifsta
->auth_alg
||
964 if (algs
[pos
] == WLAN_AUTH_SHARED_KEY
&&
965 !ieee80211_sta_wep_configured(dev
))
967 ifsta
->auth_alg
= algs
[pos
];
968 printk(KERN_DEBUG
"%s: set auth_alg=%d for "
970 dev
->name
, ifsta
->auth_alg
);
977 switch (ifsta
->auth_alg
) {
980 ieee80211_auth_completed(dev
, ifsta
);
982 case WLAN_AUTH_SHARED_KEY
:
983 if (ifsta
->auth_transaction
== 4)
984 ieee80211_auth_completed(dev
, ifsta
);
986 ieee80211_auth_challenge(dev
, ifsta
, mgmt
, len
,
993 static void ieee80211_rx_mgmt_deauth(struct net_device
*dev
,
994 struct ieee80211_if_sta
*ifsta
,
995 struct ieee80211_mgmt
*mgmt
,
997 struct ieee80211_rx_status
*rx_status
)
1002 printk(KERN_DEBUG
"%s: too short (%zd) deauthentication frame "
1003 "received from " MAC_FMT
" - ignored\n",
1004 dev
->name
, len
, MAC_ARG(mgmt
->sa
));
1008 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1009 printk(KERN_DEBUG
"%s: deauthentication frame received from "
1010 "unknown AP (SA=" MAC_FMT
" BSSID=" MAC_FMT
") - "
1011 "ignored\n", dev
->name
, MAC_ARG(mgmt
->sa
),
1012 MAC_ARG(mgmt
->bssid
));
1016 reason_code
= le16_to_cpu(mgmt
->u
.deauth
.reason_code
);
1018 printk(KERN_DEBUG
"%s: RX deauthentication from " MAC_FMT
1020 dev
->name
, MAC_ARG(mgmt
->sa
), reason_code
);
1022 if (ifsta
->authenticated
) {
1023 printk(KERN_DEBUG
"%s: deauthenticated\n", dev
->name
);
1026 if (ifsta
->state
== IEEE80211_AUTHENTICATE
||
1027 ifsta
->state
== IEEE80211_ASSOCIATE
||
1028 ifsta
->state
== IEEE80211_ASSOCIATED
) {
1029 ifsta
->state
= IEEE80211_AUTHENTICATE
;
1030 schedule_delayed_work(&ifsta
->work
,
1031 IEEE80211_RETRY_AUTH_INTERVAL
);
1034 ieee80211_set_disassoc(dev
, ifsta
, 1);
1035 ifsta
->authenticated
= 0;
1039 static void ieee80211_rx_mgmt_disassoc(struct net_device
*dev
,
1040 struct ieee80211_if_sta
*ifsta
,
1041 struct ieee80211_mgmt
*mgmt
,
1043 struct ieee80211_rx_status
*rx_status
)
1048 printk(KERN_DEBUG
"%s: too short (%zd) disassociation frame "
1049 "received from " MAC_FMT
" - ignored\n",
1050 dev
->name
, len
, MAC_ARG(mgmt
->sa
));
1054 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1055 printk(KERN_DEBUG
"%s: disassociation frame received from "
1056 "unknown AP (SA=" MAC_FMT
" BSSID=" MAC_FMT
") - "
1057 "ignored\n", dev
->name
, MAC_ARG(mgmt
->sa
),
1058 MAC_ARG(mgmt
->bssid
));
1062 reason_code
= le16_to_cpu(mgmt
->u
.disassoc
.reason_code
);
1064 printk(KERN_DEBUG
"%s: RX disassociation from " MAC_FMT
1066 dev
->name
, MAC_ARG(mgmt
->sa
), reason_code
);
1068 if (ifsta
->associated
)
1069 printk(KERN_DEBUG
"%s: disassociated\n", dev
->name
);
1071 if (ifsta
->state
== IEEE80211_ASSOCIATED
) {
1072 ifsta
->state
= IEEE80211_ASSOCIATE
;
1073 schedule_delayed_work(&ifsta
->work
,
1074 IEEE80211_RETRY_AUTH_INTERVAL
);
1077 ieee80211_set_disassoc(dev
, ifsta
, 0);
1081 static void ieee80211_rx_mgmt_assoc_resp(struct net_device
*dev
,
1082 struct ieee80211_if_sta
*ifsta
,
1083 struct ieee80211_mgmt
*mgmt
,
1085 struct ieee80211_rx_status
*rx_status
,
1088 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1089 struct sta_info
*sta
;
1091 u16 capab_info
, status_code
, aid
;
1092 struct ieee802_11_elems elems
;
1096 /* AssocResp and ReassocResp have identical structure, so process both
1097 * of them in this function. */
1099 if (ifsta
->state
!= IEEE80211_ASSOCIATE
) {
1100 printk(KERN_DEBUG
"%s: association frame received from "
1101 MAC_FMT
", but not in associate state - ignored\n",
1102 dev
->name
, MAC_ARG(mgmt
->sa
));
1107 printk(KERN_DEBUG
"%s: too short (%zd) association frame "
1108 "received from " MAC_FMT
" - ignored\n",
1109 dev
->name
, len
, MAC_ARG(mgmt
->sa
));
1113 if (memcmp(ifsta
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1114 printk(KERN_DEBUG
"%s: association frame received from "
1115 "unknown AP (SA=" MAC_FMT
" BSSID=" MAC_FMT
") - "
1116 "ignored\n", dev
->name
, MAC_ARG(mgmt
->sa
),
1117 MAC_ARG(mgmt
->bssid
));
1121 capab_info
= le16_to_cpu(mgmt
->u
.assoc_resp
.capab_info
);
1122 status_code
= le16_to_cpu(mgmt
->u
.assoc_resp
.status_code
);
1123 aid
= le16_to_cpu(mgmt
->u
.assoc_resp
.aid
);
1124 if ((aid
& (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1125 printk(KERN_DEBUG
"%s: invalid aid value %d; bits 15:14 not "
1126 "set\n", dev
->name
, aid
);
1127 aid
&= ~(BIT(15) | BIT(14));
1129 printk(KERN_DEBUG
"%s: RX %sssocResp from " MAC_FMT
" (capab=0x%x "
1130 "status=%d aid=%d)\n",
1131 dev
->name
, reassoc
? "Rea" : "A", MAC_ARG(mgmt
->sa
),
1132 capab_info
, status_code
, aid
);
1134 if (status_code
!= WLAN_STATUS_SUCCESS
) {
1135 printk(KERN_DEBUG
"%s: AP denied association (code=%d)\n",
1136 dev
->name
, status_code
);
1140 pos
= mgmt
->u
.assoc_resp
.variable
;
1141 if (ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
)
1143 printk(KERN_DEBUG
"%s: failed to parse AssocResp\n",
1148 if (!elems
.supp_rates
) {
1149 printk(KERN_DEBUG
"%s: no SuppRates element in AssocResp\n",
1154 printk(KERN_DEBUG
"%s: associated\n", dev
->name
);
1156 ifsta
->ap_capab
= capab_info
;
1158 kfree(ifsta
->assocresp_ies
);
1159 ifsta
->assocresp_ies_len
= len
- (pos
- (u8
*) mgmt
);
1160 ifsta
->assocresp_ies
= kmalloc(ifsta
->assocresp_ies_len
, GFP_ATOMIC
);
1161 if (ifsta
->assocresp_ies
)
1162 memcpy(ifsta
->assocresp_ies
, pos
, ifsta
->assocresp_ies_len
);
1164 ieee80211_set_associated(dev
, ifsta
, 1);
1166 /* Add STA entry for the AP */
1167 sta
= sta_info_get(local
, ifsta
->bssid
);
1169 sta
= sta_info_add(local
, dev
, ifsta
->bssid
, GFP_ATOMIC
);
1171 printk(KERN_DEBUG
"%s: failed to add STA entry for the"
1172 " AP\n", dev
->name
);
1178 sta
->flags
|= WLAN_STA_AUTH
| WLAN_STA_ASSOC
;
1182 for (i
= 0; i
< elems
.supp_rates_len
; i
++) {
1183 int rate
= (elems
.supp_rates
[i
] & 0x7f) * 5;
1184 if (local
->hw
.conf
.phymode
== MODE_ATHEROS_TURBO
)
1186 for (j
= 0; j
< local
->num_curr_rates
; j
++)
1187 if (local
->curr_rates
[j
].rate
== rate
)
1190 for (i
= 0; i
< elems
.ext_supp_rates_len
; i
++) {
1191 int rate
= (elems
.ext_supp_rates
[i
] & 0x7f) * 5;
1192 if (local
->hw
.conf
.phymode
== MODE_ATHEROS_TURBO
)
1194 for (j
= 0; j
< local
->num_curr_rates
; j
++)
1195 if (local
->curr_rates
[j
].rate
== rate
)
1198 sta
->supp_rates
= rates
;
1200 rate_control_rate_init(sta
, local
);
1202 if (elems
.wmm_param
&& ifsta
->wmm_enabled
) {
1203 sta
->flags
|= WLAN_STA_WME
;
1204 ieee80211_sta_wmm_params(dev
, ifsta
, elems
.wmm_param
,
1205 elems
.wmm_param_len
);
1211 ieee80211_associated(dev
, ifsta
);
1215 /* Caller must hold local->sta_bss_lock */
1216 static void __ieee80211_rx_bss_hash_add(struct net_device
*dev
,
1217 struct ieee80211_sta_bss
*bss
)
1219 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1220 bss
->hnext
= local
->sta_bss_hash
[STA_HASH(bss
->bssid
)];
1221 local
->sta_bss_hash
[STA_HASH(bss
->bssid
)] = bss
;
1225 /* Caller must hold local->sta_bss_lock */
1226 static void __ieee80211_rx_bss_hash_del(struct net_device
*dev
,
1227 struct ieee80211_sta_bss
*bss
)
1229 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1230 struct ieee80211_sta_bss
*b
, *prev
= NULL
;
1231 b
= local
->sta_bss_hash
[STA_HASH(bss
->bssid
)];
1235 local
->sta_bss_hash
[STA_HASH(bss
->bssid
)] =
1238 prev
->hnext
= bss
->hnext
;
1247 static struct ieee80211_sta_bss
*
1248 ieee80211_rx_bss_add(struct net_device
*dev
, u8
*bssid
)
1250 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1251 struct ieee80211_sta_bss
*bss
;
1253 bss
= kmalloc(sizeof(*bss
), GFP_ATOMIC
);
1256 memset(bss
, 0, sizeof(*bss
));
1257 atomic_inc(&bss
->users
);
1258 atomic_inc(&bss
->users
);
1259 memcpy(bss
->bssid
, bssid
, ETH_ALEN
);
1261 spin_lock_bh(&local
->sta_bss_lock
);
1262 /* TODO: order by RSSI? */
1263 list_add_tail(&bss
->list
, &local
->sta_bss_list
);
1264 __ieee80211_rx_bss_hash_add(dev
, bss
);
1265 spin_unlock_bh(&local
->sta_bss_lock
);
1270 static struct ieee80211_sta_bss
*
1271 ieee80211_rx_bss_get(struct net_device
*dev
, u8
*bssid
)
1273 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1274 struct ieee80211_sta_bss
*bss
;
1276 spin_lock_bh(&local
->sta_bss_lock
);
1277 bss
= local
->sta_bss_hash
[STA_HASH(bssid
)];
1279 if (memcmp(bss
->bssid
, bssid
, ETH_ALEN
) == 0) {
1280 atomic_inc(&bss
->users
);
1285 spin_unlock_bh(&local
->sta_bss_lock
);
1290 static void ieee80211_rx_bss_free(struct ieee80211_sta_bss
*bss
)
1299 static void ieee80211_rx_bss_put(struct net_device
*dev
,
1300 struct ieee80211_sta_bss
*bss
)
1302 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1303 if (!atomic_dec_and_test(&bss
->users
))
1306 spin_lock_bh(&local
->sta_bss_lock
);
1307 __ieee80211_rx_bss_hash_del(dev
, bss
);
1308 list_del(&bss
->list
);
1309 spin_unlock_bh(&local
->sta_bss_lock
);
1310 ieee80211_rx_bss_free(bss
);
1314 void ieee80211_rx_bss_list_init(struct net_device
*dev
)
1316 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1317 spin_lock_init(&local
->sta_bss_lock
);
1318 INIT_LIST_HEAD(&local
->sta_bss_list
);
1322 void ieee80211_rx_bss_list_deinit(struct net_device
*dev
)
1324 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1325 struct ieee80211_sta_bss
*bss
, *tmp
;
1327 list_for_each_entry_safe(bss
, tmp
, &local
->sta_bss_list
, list
)
1328 ieee80211_rx_bss_put(dev
, bss
);
1332 static void ieee80211_rx_bss_info(struct net_device
*dev
,
1333 struct ieee80211_mgmt
*mgmt
,
1335 struct ieee80211_rx_status
*rx_status
,
1338 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1339 struct ieee802_11_elems elems
;
1341 int channel
, invalid
= 0, clen
;
1342 struct ieee80211_sta_bss
*bss
;
1343 struct sta_info
*sta
;
1344 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1347 if (!beacon
&& memcmp(mgmt
->da
, dev
->dev_addr
, ETH_ALEN
))
1348 return; /* ignore ProbeResp to foreign address */
1351 printk(KERN_DEBUG
"%s: RX %s from " MAC_FMT
" to " MAC_FMT
"\n",
1352 dev
->name
, beacon
? "Beacon" : "Probe Response",
1353 MAC_ARG(mgmt
->sa
), MAC_ARG(mgmt
->da
));
1356 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
1360 timestamp
= le64_to_cpu(mgmt
->u
.beacon
.timestamp
);
1362 if (sdata
->type
== IEEE80211_IF_TYPE_IBSS
&& beacon
&&
1363 memcmp(mgmt
->bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
) == 0) {
1364 #ifdef CONFIG_D80211_IBSS_DEBUG
1365 static unsigned long last_tsf_debug
= 0;
1367 if (local
->ops
->get_tsf
)
1368 tsf
= local
->ops
->get_tsf(local
->mdev
);
1371 if (time_after(jiffies
, last_tsf_debug
+ 5 * HZ
)) {
1372 printk(KERN_DEBUG
"RX beacon SA=" MAC_FMT
" BSSID="
1373 MAC_FMT
" TSF=0x%llx BCN=0x%llx diff=%lld "
1375 MAC_ARG(mgmt
->sa
), MAC_ARG(mgmt
->bssid
),
1376 tsf
, timestamp
, tsf
- timestamp
, jiffies
);
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_rate
*rates
;
1391 u32 supp_rates
, prev_rates
;
1392 int i
, j
, oper_mode
;
1394 rates
= local
->curr_rates
;
1395 num_rates
= local
->num_curr_rates
;
1396 oper_mode
= local
->sta_scanning
? local
->scan_oper_phymode
:
1397 local
->hw
.conf
.phymode
;
1398 for (i
= 0; i
< local
->hw
.num_modes
; i
++) {
1399 struct ieee80211_hw_modes
*mode
= &local
->hw
.modes
[i
];
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, 1);
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(void *ptr
)
1848 struct net_device
*dev
= ptr
;
1849 struct ieee80211_sub_if_data
*sdata
;
1850 struct ieee80211_if_sta
*ifsta
;
1852 if (!netif_running(dev
))
1855 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1856 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
1857 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
) {
1858 printk(KERN_DEBUG
"%s: ieee80211_sta_work: non-STA interface "
1859 "(type=%d)\n", dev
->name
, sdata
->type
);
1862 ifsta
= &sdata
->u
.sta
;
1864 switch (ifsta
->state
) {
1865 case IEEE80211_DISABLED
:
1867 case IEEE80211_AUTHENTICATE
:
1868 ieee80211_authenticate(dev
, ifsta
);
1870 case IEEE80211_ASSOCIATE
:
1871 ieee80211_associate(dev
, ifsta
);
1873 case IEEE80211_ASSOCIATED
:
1874 ieee80211_associated(dev
, ifsta
);
1876 case IEEE80211_IBSS_SEARCH
:
1877 ieee80211_sta_find_ibss(dev
, ifsta
);
1879 case IEEE80211_IBSS_JOINED
:
1880 ieee80211_sta_merge_ibss(dev
, ifsta
);
1883 printk(KERN_DEBUG
"ieee80211_sta_work: Unknown state %d\n",
1888 if (ieee80211_privacy_mismatch(dev
, ifsta
)) {
1889 printk(KERN_DEBUG
"%s: privacy configuration mismatch and "
1890 "mixed-cell disabled - disassociate\n", dev
->name
);
1892 ieee80211_send_disassoc(dev
, ifsta
, WLAN_REASON_UNSPECIFIED
);
1893 ieee80211_set_disassoc(dev
, ifsta
, 0);
1898 static void ieee80211_sta_new_auth(struct net_device
*dev
,
1899 struct ieee80211_if_sta
*ifsta
)
1901 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1902 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1904 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
1907 if (local
->ops
->reset_tsf
) {
1908 /* Reset own TSF to allow time synchronization work. */
1909 local
->ops
->reset_tsf(local_to_hw(local
));
1912 ifsta
->wmm_last_param_set
= -1; /* allow any WMM update */
1915 if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_OPEN
)
1916 ifsta
->auth_alg
= WLAN_AUTH_OPEN
;
1917 else if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_SHARED_KEY
)
1918 ifsta
->auth_alg
= WLAN_AUTH_SHARED_KEY
;
1919 else if (ifsta
->auth_algs
& IEEE80211_AUTH_ALG_LEAP
)
1920 ifsta
->auth_alg
= WLAN_AUTH_LEAP
;
1922 ifsta
->auth_alg
= WLAN_AUTH_OPEN
;
1923 printk(KERN_DEBUG
"%s: Initial auth_alg=%d\n", dev
->name
,
1925 ifsta
->auth_transaction
= -1;
1926 ifsta
->auth_tries
= ifsta
->assoc_tries
= 0;
1927 ieee80211_authenticate(dev
, ifsta
);
1931 static int ieee80211_ibss_allowed(struct ieee80211_local
*local
)
1935 for (m
= 0; m
< local
->hw
.num_modes
; m
++) {
1936 struct ieee80211_hw_modes
*mode
= &local
->hw
.modes
[m
];
1937 if (mode
->mode
!= local
->hw
.conf
.phymode
)
1939 for (c
= 0; c
< mode
->num_channels
; c
++) {
1940 struct ieee80211_channel
*chan
= &mode
->channels
[c
];
1941 if (chan
->flag
& IEEE80211_CHAN_W_SCAN
&&
1942 chan
->chan
== local
->hw
.conf
.channel
) {
1943 if (chan
->flag
& IEEE80211_CHAN_W_IBSS
)
1954 extern int ieee80211_ioctl_siwfreq(struct net_device
*dev
,
1955 struct iw_request_info
*info
,
1956 struct iw_freq
*freq
, char *extra
);
1958 static int ieee80211_sta_join_ibss(struct net_device
*dev
,
1959 struct ieee80211_if_sta
*ifsta
,
1960 struct ieee80211_sta_bss
*bss
)
1962 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1964 int res
, rates
, i
, j
;
1965 struct sk_buff
*skb
;
1966 struct ieee80211_mgmt
*mgmt
;
1967 struct ieee80211_tx_control control
;
1968 struct ieee80211_rate
*rate
;
1969 struct rate_control_extra extra
;
1971 struct ieee80211_sub_if_data
*sdata
;
1973 /* Remove possible STA entries from other IBSS networks. */
1974 sta_info_flush(local
, NULL
);
1976 if (local
->ops
->reset_tsf
) {
1977 /* Reset own TSF to allow time synchronization work. */
1978 local
->ops
->reset_tsf(local_to_hw(local
));
1980 memcpy(ifsta
->bssid
, bss
->bssid
, ETH_ALEN
);
1981 res
= ieee80211_if_config(dev
);
1985 local
->hw
.conf
.beacon_int
= bss
->beacon_int
>= 10 ? bss
->beacon_int
: 10;
1987 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1988 sdata
->drop_unencrypted
= bss
->capability
&
1989 WLAN_CAPABILITY_PRIVACY
? 1 : 0;
1991 memset(&rq
, 0, sizeof(rq
));
1992 rq
.m
= bss
->freq
* 100000;
1994 res
= ieee80211_ioctl_siwfreq(dev
, NULL
, &rq
, NULL
);
1996 if (!ieee80211_ibss_allowed(local
)) {
1997 printk(KERN_DEBUG
"%s: IBSS not allowed on channel %d "
1998 "(%d MHz)\n", dev
->name
, local
->hw
.conf
.channel
,
1999 local
->hw
.conf
.freq
);
2003 /* Set beacon template based on scan results */
2004 skb
= dev_alloc_skb(400);
2009 mgmt
= (struct ieee80211_mgmt
*)
2010 skb_put(skb
, 24 + sizeof(mgmt
->u
.beacon
));
2011 memset(mgmt
, 0, 24 + sizeof(mgmt
->u
.beacon
));
2012 mgmt
->frame_control
= IEEE80211_FC(IEEE80211_FTYPE_MGMT
,
2013 IEEE80211_STYPE_BEACON
);
2014 memset(mgmt
->da
, 0xff, ETH_ALEN
);
2015 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
2016 memcpy(mgmt
->bssid
, ifsta
->bssid
, ETH_ALEN
);
2017 mgmt
->u
.beacon
.beacon_int
=
2018 cpu_to_le16(local
->hw
.conf
.beacon_int
);
2019 mgmt
->u
.beacon
.capab_info
= cpu_to_le16(bss
->capability
);
2021 pos
= skb_put(skb
, 2 + ifsta
->ssid_len
);
2022 *pos
++ = WLAN_EID_SSID
;
2023 *pos
++ = ifsta
->ssid_len
;
2024 memcpy(pos
, ifsta
->ssid
, ifsta
->ssid_len
);
2026 rates
= bss
->supp_rates_len
;
2029 pos
= skb_put(skb
, 2 + rates
);
2030 *pos
++ = WLAN_EID_SUPP_RATES
;
2032 memcpy(pos
, bss
->supp_rates
, rates
);
2034 pos
= skb_put(skb
, 2 + 1);
2035 *pos
++ = WLAN_EID_DS_PARAMS
;
2037 *pos
++ = bss
->channel
;
2039 pos
= skb_put(skb
, 2 + 2);
2040 *pos
++ = WLAN_EID_IBSS_PARAMS
;
2042 /* FIX: set ATIM window based on scan results */
2046 if (bss
->supp_rates_len
> 8) {
2047 rates
= bss
->supp_rates_len
- 8;
2048 pos
= skb_put(skb
, 2 + rates
);
2049 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
2051 memcpy(pos
, &bss
->supp_rates
[8], rates
);
2054 memset(&control
, 0, sizeof(control
));
2055 control
.pkt_type
= PKT_PROBE_RESP
;
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
)
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
)
2394 for (m
= 0; m
< local
->hw
.num_modes
; m
++) {
2395 struct ieee80211_hw_modes
*mode
= &local
->hw
.modes
[m
];
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_work
.data
;
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 static void ieee80211_sta_scan_work(void *ptr
)
2439 struct net_device
*dev
= ptr
;
2440 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2441 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2442 struct ieee80211_hw_modes
*mode
;
2443 struct ieee80211_channel
*chan
;
2445 unsigned long next_delay
= 0;
2447 if (!local
->sta_scanning
)
2450 switch (local
->scan_state
) {
2451 case SCAN_SET_CHANNEL
:
2452 mode
= &local
->hw
.modes
[local
->scan_hw_mode_idx
];
2453 if (local
->scan_hw_mode_idx
>= local
->hw
.num_modes
||
2454 (local
->scan_hw_mode_idx
+ 1 == local
->hw
.num_modes
&&
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
>=
2496 local
->hw
.modes
[local
->scan_hw_mode_idx
].num_channels
) {
2497 local
->scan_hw_mode_idx
++;
2498 local
->scan_channel_idx
= 0;
2504 next_delay
= IEEE80211_PROBE_DELAY
+
2505 usecs_to_jiffies(local
->hw
.channel_change_time
);
2506 local
->scan_state
= SCAN_SEND_PROBE
;
2508 case SCAN_SEND_PROBE
:
2509 if (ieee80211_active_scan(local
)) {
2510 ieee80211_send_probe_req(dev
, NULL
, local
->scan_ssid
,
2511 local
->scan_ssid_len
);
2512 next_delay
= IEEE80211_CHANNEL_TIME
;
2514 next_delay
= IEEE80211_PASSIVE_CHANNEL_TIME
;
2515 local
->scan_state
= SCAN_SET_CHANNEL
;
2519 if (local
->sta_scanning
) {
2521 schedule_delayed_work(&local
->scan_work
, next_delay
);
2523 schedule_work(&local
->scan_work
);
2528 int ieee80211_sta_req_scan(struct net_device
*dev
, u8
*ssid
, size_t ssid_len
)
2530 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2532 if (ssid_len
> IEEE80211_MAX_SSID_LEN
)
2535 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
2536 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
2539 * ScanType: ACTIVE, PASSIVE
2540 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
2541 * a Probe frame during active scanning
2543 * MinChannelTime (>= ProbeDelay), in TU
2544 * MaxChannelTime: (>= MinChannelTime), in TU
2547 /* MLME-SCAN.confirm
2549 * ResultCode: SUCCESS, INVALID_PARAMETERS
2552 /* TODO: if assoc, move to power save mode for the duration of the
2555 if (local
->sta_scanning
) {
2556 if (local
->scan_work
.data
== dev
)
2561 printk(KERN_DEBUG
"%s: starting scan\n", dev
->name
);
2563 if (local
->ops
->hw_scan
) {
2564 int rc
= local
->ops
->hw_scan(local_to_hw(local
),
2567 local
->sta_scanning
= 1;
2568 local
->scan_work
.data
= dev
;
2573 ieee80211_sta_save_oper_chan(dev
);
2575 local
->sta_scanning
= 1;
2576 /* TODO: stop TX queue? */
2579 local
->scan_ssid_len
= ssid_len
;
2580 memcpy(local
->scan_ssid
, ssid
, ssid_len
);
2582 local
->scan_ssid_len
= 0;
2583 local
->scan_state
= SCAN_SET_CHANNEL
;
2584 local
->scan_hw_mode_idx
= 0;
2585 local
->scan_channel_idx
= 0;
2586 INIT_WORK(&local
->scan_work
, ieee80211_sta_scan_work
, dev
);
2587 schedule_work(&local
->scan_work
);
2594 ieee80211_sta_scan_result(struct net_device
*dev
,
2595 struct ieee80211_sta_bss
*bss
,
2596 char *current_ev
, char *end_buf
)
2598 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2599 struct iw_event iwe
;
2601 if (time_after(jiffies
,
2602 bss
->last_update
+ IEEE80211_SCAN_RESULT_EXPIRE
))
2605 if (!(local
->enabled_modes
& (1 << bss
->hw_mode
)))
2608 if (local
->scan_flags
& IEEE80211_SCAN_WPA_ONLY
&&
2609 !bss
->wpa_ie
&& !bss
->rsn_ie
)
2612 if (local
->scan_flags
& IEEE80211_SCAN_MATCH_SSID
&&
2613 (local
->scan_ssid_len
!= bss
->ssid_len
||
2614 memcmp(local
->scan_ssid
, bss
->ssid
, bss
->ssid_len
) != 0))
2617 memset(&iwe
, 0, sizeof(iwe
));
2618 iwe
.cmd
= SIOCGIWAP
;
2619 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
2620 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->bssid
, ETH_ALEN
);
2621 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
2624 memset(&iwe
, 0, sizeof(iwe
));
2625 iwe
.cmd
= SIOCGIWESSID
;
2626 iwe
.u
.data
.length
= bss
->ssid_len
;
2627 iwe
.u
.data
.flags
= 1;
2628 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
2631 if (bss
->capability
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
)) {
2632 memset(&iwe
, 0, sizeof(iwe
));
2633 iwe
.cmd
= SIOCGIWMODE
;
2634 if (bss
->capability
& WLAN_CAPABILITY_ESS
)
2635 iwe
.u
.mode
= IW_MODE_MASTER
;
2637 iwe
.u
.mode
= IW_MODE_ADHOC
;
2638 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
2642 memset(&iwe
, 0, sizeof(iwe
));
2643 iwe
.cmd
= SIOCGIWFREQ
;
2644 iwe
.u
.freq
.m
= bss
->freq
* 100000;
2646 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
,
2649 memset(&iwe
, 0, sizeof(iwe
));
2650 iwe
.cmd
= SIOCGIWENCODE
;
2651 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
2652 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
2654 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
2655 iwe
.u
.data
.length
= 0;
2656 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
, "");
2658 if (bss
&& bss
->wpa_ie
) {
2661 buf
= kmalloc(30 + bss
->wpa_ie_len
* 2, GFP_ATOMIC
);
2664 p
+= sprintf(p
, "wpa_ie=");
2665 for (i
= 0; i
< bss
->wpa_ie_len
; i
++)
2666 p
+= sprintf(p
, "%02x", bss
->wpa_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
,
2676 if (bss
&& bss
->rsn_ie
) {
2679 buf
= kmalloc(30 + bss
->rsn_ie_len
* 2, GFP_ATOMIC
);
2682 p
+= sprintf(p
, "rsn_ie=");
2683 for (i
= 0; i
< bss
->rsn_ie_len
; i
++)
2684 p
+= sprintf(p
, "%02x", bss
->rsn_ie
[i
]);
2685 memset(&iwe
, 0, sizeof(iwe
));
2686 iwe
.cmd
= IWEVCUSTOM
;
2687 iwe
.u
.data
.length
= strlen(buf
);
2688 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
2696 buf
= kmalloc(30, GFP_ATOMIC
);
2698 memset(&iwe
, 0, sizeof(iwe
));
2699 iwe
.cmd
= IWEVCUSTOM
;
2700 sprintf(buf
, "tsf=%016llx", bss
->timestamp
);
2701 iwe
.u
.data
.length
= strlen(buf
);
2702 current_ev
= iwe_stream_add_point(current_ev
, end_buf
,
2712 if (!(local
->scan_flags
& IEEE80211_SCAN_EXTRA_INFO
))
2715 buf
= kmalloc(100, GFP_ATOMIC
);
2719 memset(&iwe
, 0, sizeof(iwe
));
2720 iwe
.cmd
= IWEVCUSTOM
;
2721 sprintf(buf
, "bcn_int=%d", bss
->beacon_int
);
2722 iwe
.u
.data
.length
= strlen(buf
);
2723 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
2726 memset(&iwe
, 0, sizeof(iwe
));
2727 iwe
.cmd
= IWEVCUSTOM
;
2728 sprintf(buf
, "rssi=%d", bss
->rssi
);
2729 iwe
.u
.data
.length
= strlen(buf
);
2730 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
2733 memset(&iwe
, 0, sizeof(iwe
));
2734 iwe
.cmd
= IWEVCUSTOM
;
2735 sprintf(buf
, "capab=0x%04x", bss
->capability
);
2736 iwe
.u
.data
.length
= strlen(buf
);
2737 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
,
2740 /* dispaly all support rates in readable format */
2741 p
= current_ev
+ IW_EV_LCP_LEN
;
2742 iwe
.cmd
= SIOCGIWRATE
;
2743 /* Those two flags are ignored... */
2744 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
2746 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
2747 iwe
.u
.bitrate
.value
= ((bss
->supp_rates
[i
] &
2749 p
= iwe_stream_add_value(current_ev
, p
,
2750 end_buf
, &iwe
, IW_EV_PARAM_LEN
);
2752 /* Check if we added any rate */
2753 if((p
- current_ev
) > IW_EV_LCP_LEN
)
2764 int ieee80211_sta_scan_results(struct net_device
*dev
, char *buf
, size_t len
)
2766 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2767 char *current_ev
= buf
;
2768 char *end_buf
= buf
+ len
;
2769 struct ieee80211_sta_bss
*bss
;
2771 spin_lock_bh(&local
->sta_bss_lock
);
2772 list_for_each_entry(bss
, &local
->sta_bss_list
, list
) {
2773 if (buf
+ len
- current_ev
<= IW_EV_ADDR_LEN
) {
2774 spin_unlock_bh(&local
->sta_bss_lock
);
2777 current_ev
= ieee80211_sta_scan_result(dev
, bss
, current_ev
,
2780 spin_unlock_bh(&local
->sta_bss_lock
);
2781 return current_ev
- buf
;
2785 int ieee80211_sta_set_extra_ie(struct net_device
*dev
, char *ie
, size_t len
)
2787 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2788 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
2789 kfree(ifsta
->extra_ie
);
2791 ifsta
->extra_ie
= NULL
;
2792 ifsta
->extra_ie_len
= 0;
2795 ifsta
->extra_ie
= kmalloc(len
, GFP_KERNEL
);
2796 if (!ifsta
->extra_ie
) {
2797 ifsta
->extra_ie_len
= 0;
2800 memcpy(ifsta
->extra_ie
, ie
, len
);
2801 ifsta
->extra_ie_len
= len
;
2802 if (ifsta
->bssid_set
&& ifsta
->ssid_set
&&
2803 ifsta
->state
!= IEEE80211_AUTHENTICATE
)
2804 ieee80211_sta_new_auth(dev
, ifsta
);
2809 struct sta_info
* ieee80211_ibss_add_sta(struct net_device
*dev
,
2810 struct sk_buff
*skb
, u8
*bssid
,
2813 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2814 struct sta_info
*sta
;
2815 struct ieee80211_sub_if_data
*sdata
= NULL
;
2816 struct net_device
*sta_dev
= NULL
;
2818 /* TODO: Could consider removing the least recently used entry and
2819 * allow new one to be added. */
2820 if (local
->num_sta
>= IEEE80211_IBSS_MAX_STA_ENTRIES
) {
2821 if (net_ratelimit()) {
2822 printk(KERN_DEBUG
"%s: No room for a new IBSS STA "
2823 "entry " MAC_FMT
"\n", dev
->name
, MAC_ARG(addr
));
2828 spin_lock_bh(&local
->sub_if_lock
);
2829 list_for_each_entry(sdata
, &local
->sub_if_list
, list
)
2830 if (sdata
->type
== IEEE80211_IF_TYPE_IBSS
&&
2831 memcmp(bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
) == 0) {
2832 sta_dev
= sdata
->dev
;
2835 spin_unlock_bh(&local
->sub_if_lock
);
2840 printk(KERN_DEBUG
"%s: Adding new IBSS station " MAC_FMT
" (dev=%s)\n",
2841 dev
->name
, MAC_ARG(addr
), sta_dev
->name
);
2843 sta
= sta_info_add(local
, dev
, addr
, GFP_ATOMIC
);
2848 sta
->supp_rates
= sdata
->u
.sta
.supp_rates_bits
;
2850 rate_control_rate_init(sta
, local
);
2852 return sta
; /* caller will call sta_info_put() */
2856 int ieee80211_sta_deauthenticate(struct net_device
*dev
, u16 reason
)
2858 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2859 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
2861 printk(KERN_DEBUG
"%s: deauthenticate(reason=%d)\n",
2864 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
2865 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
2868 ieee80211_send_deauth(dev
, ifsta
, reason
);
2869 ieee80211_set_disassoc(dev
, ifsta
, 1);
2874 int ieee80211_sta_disassociate(struct net_device
*dev
, u16 reason
)
2876 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2877 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
2879 printk(KERN_DEBUG
"%s: disassociate(reason=%d)\n",
2882 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
2885 if (!ifsta
->associated
)
2888 ieee80211_send_disassoc(dev
, ifsta
, reason
);
2889 ieee80211_set_disassoc(dev
, ifsta
, 0);