2 * IBSS mode implementation
3 * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
4 * Copyright 2004, Instant802 Networks, Inc.
5 * Copyright 2005, Devicescape Software, Inc.
6 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
7 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
8 * Copyright 2009, Johannes Berg <johannes@sipsolutions.net>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/delay.h>
16 #include <linux/if_ether.h>
17 #include <linux/skbuff.h>
18 #include <linux/if_arp.h>
19 #include <linux/etherdevice.h>
20 #include <linux/rtnetlink.h>
21 #include <net/mac80211.h>
22 #include <asm/unaligned.h>
24 #include "ieee80211_i.h"
27 #define IEEE80211_SCAN_INTERVAL (2 * HZ)
28 #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ)
29 #define IEEE80211_IBSS_JOIN_TIMEOUT (7 * HZ)
31 #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
32 #define IEEE80211_IBSS_MERGE_DELAY 0x400000
33 #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
35 #define IEEE80211_IBSS_MAX_STA_ENTRIES 128
38 static void ieee80211_rx_mgmt_auth_ibss(struct ieee80211_sub_if_data
*sdata
,
39 struct ieee80211_mgmt
*mgmt
,
42 u16 auth_alg
, auth_transaction
, status_code
;
47 auth_alg
= le16_to_cpu(mgmt
->u
.auth
.auth_alg
);
48 auth_transaction
= le16_to_cpu(mgmt
->u
.auth
.auth_transaction
);
49 status_code
= le16_to_cpu(mgmt
->u
.auth
.status_code
);
52 * IEEE 802.11 standard does not require authentication in IBSS
53 * networks and most implementations do not seem to use it.
54 * However, try to reply to authentication attempts if someone
55 * has actually implemented this.
57 if (auth_alg
== WLAN_AUTH_OPEN
&& auth_transaction
== 1)
58 ieee80211_send_auth(sdata
, 2, WLAN_AUTH_OPEN
, NULL
, 0,
59 sdata
->u
.ibss
.bssid
, 0);
62 static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data
*sdata
,
63 const u8
*bssid
, const int beacon_int
,
64 struct ieee80211_channel
*chan
,
65 const size_t supp_rates_len
,
67 const u16 capability
, u64 tsf
)
69 struct ieee80211_if_ibss
*ifibss
= &sdata
->u
.ibss
;
70 struct ieee80211_local
*local
= sdata
->local
;
73 struct ieee80211_mgmt
*mgmt
;
75 struct ieee80211_supported_band
*sband
;
77 if (local
->ops
->reset_tsf
) {
78 /* Reset own TSF to allow time synchronization work. */
79 local
->ops
->reset_tsf(local_to_hw(local
));
83 rcu_assign_pointer(ifibss
->presp
, NULL
);
85 skb
->data
= skb
->head
;
87 skb_reset_tail_pointer(skb
);
88 skb_reserve(skb
, sdata
->local
->hw
.extra_tx_headroom
);
90 if (memcmp(ifibss
->bssid
, bssid
, ETH_ALEN
))
91 sta_info_flush(sdata
->local
, sdata
);
93 memcpy(ifibss
->bssid
, bssid
, ETH_ALEN
);
95 local
->hw
.conf
.beacon_int
= beacon_int
>= 10 ? beacon_int
: 10;
97 sdata
->drop_unencrypted
= capability
& WLAN_CAPABILITY_PRIVACY
? 1 : 0;
99 ieee80211_if_config(sdata
, IEEE80211_IFCC_BSSID
);
101 local
->oper_channel
= chan
;
102 local
->oper_channel_type
= NL80211_CHAN_NO_HT
;
103 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_CHANNEL
);
104 sband
= local
->hw
.wiphy
->bands
[chan
->band
];
106 /* Build IBSS probe response */
107 mgmt
= (void *) skb_put(skb
, 24 + sizeof(mgmt
->u
.beacon
));
108 memset(mgmt
, 0, 24 + sizeof(mgmt
->u
.beacon
));
109 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
110 IEEE80211_STYPE_PROBE_RESP
);
111 memset(mgmt
->da
, 0xff, ETH_ALEN
);
112 memcpy(mgmt
->sa
, sdata
->dev
->dev_addr
, ETH_ALEN
);
113 memcpy(mgmt
->bssid
, ifibss
->bssid
, ETH_ALEN
);
114 mgmt
->u
.beacon
.beacon_int
= cpu_to_le16(local
->hw
.conf
.beacon_int
);
115 mgmt
->u
.beacon
.timestamp
= cpu_to_le64(tsf
);
116 mgmt
->u
.beacon
.capab_info
= cpu_to_le16(capability
);
118 pos
= skb_put(skb
, 2 + ifibss
->ssid_len
);
119 *pos
++ = WLAN_EID_SSID
;
120 *pos
++ = ifibss
->ssid_len
;
121 memcpy(pos
, ifibss
->ssid
, ifibss
->ssid_len
);
123 rates
= supp_rates_len
;
126 pos
= skb_put(skb
, 2 + rates
);
127 *pos
++ = WLAN_EID_SUPP_RATES
;
129 memcpy(pos
, supp_rates
, rates
);
131 if (sband
->band
== IEEE80211_BAND_2GHZ
) {
132 pos
= skb_put(skb
, 2 + 1);
133 *pos
++ = WLAN_EID_DS_PARAMS
;
135 *pos
++ = ieee80211_frequency_to_channel(chan
->center_freq
);
138 pos
= skb_put(skb
, 2 + 2);
139 *pos
++ = WLAN_EID_IBSS_PARAMS
;
141 /* FIX: set ATIM window based on scan results */
145 if (supp_rates_len
> 8) {
146 rates
= supp_rates_len
- 8;
147 pos
= skb_put(skb
, 2 + rates
);
148 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
150 memcpy(pos
, &supp_rates
[8], rates
);
154 memcpy(skb_put(skb
, ifibss
->ie_len
),
155 ifibss
->ie
, ifibss
->ie_len
);
157 rcu_assign_pointer(ifibss
->presp
, skb
);
159 ieee80211_if_config(sdata
, IEEE80211_IFCC_BEACON
|
160 IEEE80211_IFCC_BEACON_ENABLED
);
163 for (i
= 0; i
< supp_rates_len
; i
++) {
164 int bitrate
= (supp_rates
[i
] & 0x7f) * 5;
165 for (j
= 0; j
< sband
->n_bitrates
; j
++)
166 if (sband
->bitrates
[j
].bitrate
== bitrate
)
170 ieee80211_sta_def_wmm_params(sdata
, supp_rates_len
, supp_rates
);
172 ifibss
->state
= IEEE80211_IBSS_MLME_JOINED
;
173 mod_timer(&ifibss
->timer
,
174 round_jiffies(jiffies
+ IEEE80211_IBSS_MERGE_INTERVAL
));
176 cfg80211_inform_bss_frame(local
->hw
.wiphy
, local
->hw
.conf
.channel
,
177 mgmt
, skb
->len
, 0, GFP_KERNEL
);
178 cfg80211_ibss_joined(sdata
->dev
, ifibss
->bssid
, GFP_KERNEL
);
181 static void ieee80211_sta_join_ibss(struct ieee80211_sub_if_data
*sdata
,
182 struct ieee80211_bss
*bss
)
184 __ieee80211_sta_join_ibss(sdata
, bss
->cbss
.bssid
,
185 bss
->cbss
.beacon_interval
,
187 bss
->supp_rates_len
, bss
->supp_rates
,
188 bss
->cbss
.capability
,
192 static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data
*sdata
,
193 struct ieee80211_mgmt
*mgmt
,
195 struct ieee80211_rx_status
*rx_status
,
196 struct ieee802_11_elems
*elems
,
199 struct ieee80211_local
*local
= sdata
->local
;
201 struct ieee80211_bss
*bss
;
202 struct sta_info
*sta
;
203 struct ieee80211_channel
*channel
;
204 u64 beacon_timestamp
, rx_timestamp
;
206 enum ieee80211_band band
= rx_status
->band
;
208 if (elems
->ds_params
&& elems
->ds_params_len
== 1)
209 freq
= ieee80211_channel_to_frequency(elems
->ds_params
[0]);
211 freq
= rx_status
->freq
;
213 channel
= ieee80211_get_channel(local
->hw
.wiphy
, freq
);
215 if (!channel
|| channel
->flags
& IEEE80211_CHAN_DISABLED
)
218 if (sdata
->vif
.type
== NL80211_IFTYPE_ADHOC
&& elems
->supp_rates
&&
219 memcmp(mgmt
->bssid
, sdata
->u
.ibss
.bssid
, ETH_ALEN
) == 0) {
220 supp_rates
= ieee80211_sta_get_rates(local
, elems
, band
);
224 sta
= sta_info_get(local
, mgmt
->sa
);
228 prev_rates
= sta
->sta
.supp_rates
[band
];
229 /* make sure mandatory rates are always added */
230 sta
->sta
.supp_rates
[band
] = supp_rates
|
231 ieee80211_mandatory_rates(local
, band
);
233 #ifdef CONFIG_MAC80211_IBSS_DEBUG
234 if (sta
->sta
.supp_rates
[band
] != prev_rates
)
235 printk(KERN_DEBUG
"%s: updated supp_rates set "
236 "for %pM based on beacon info (0x%llx | "
237 "0x%llx -> 0x%llx)\n",
240 (unsigned long long) prev_rates
,
241 (unsigned long long) supp_rates
,
242 (unsigned long long) sta
->sta
.supp_rates
[band
]);
245 ieee80211_ibss_add_sta(sdata
, mgmt
->bssid
, mgmt
->sa
, supp_rates
);
250 bss
= ieee80211_bss_info_update(local
, rx_status
, mgmt
, len
, elems
,
255 /* was just updated in ieee80211_bss_info_update */
256 beacon_timestamp
= bss
->cbss
.tsf
;
258 /* check if we need to merge IBSS */
260 /* merge only on beacons (???) */
264 /* we use a fixed BSSID */
265 if (sdata
->u
.ibss
.bssid
)
269 if (!(bss
->cbss
.capability
& WLAN_CAPABILITY_IBSS
))
272 /* different channel */
273 if (bss
->cbss
.channel
!= local
->oper_channel
)
277 if (elems
->ssid_len
!= sdata
->u
.ibss
.ssid_len
||
278 memcmp(elems
->ssid
, sdata
->u
.ibss
.ssid
,
279 sdata
->u
.ibss
.ssid_len
))
283 if (memcmp(bss
->cbss
.bssid
, sdata
->u
.ibss
.bssid
, ETH_ALEN
) == 0)
286 if (rx_status
->flag
& RX_FLAG_TSFT
) {
288 * For correct IBSS merging we need mactime; since mactime is
289 * defined as the time the first data symbol of the frame hits
290 * the PHY, and the timestamp of the beacon is defined as "the
291 * time that the data symbol containing the first bit of the
292 * timestamp is transmitted to the PHY plus the transmitting
293 * STA's delays through its local PHY from the MAC-PHY
294 * interface to its interface with the WM" (802.11 11.1.2)
295 * - equals the time this bit arrives at the receiver - we have
296 * to take into account the offset between the two.
298 * E.g. at 1 MBit that means mactime is 192 usec earlier
299 * (=24 bytes * 8 usecs/byte) than the beacon timestamp.
303 if (rx_status
->flag
& RX_FLAG_HT
)
304 rate
= 65; /* TODO: HT rates */
306 rate
= local
->hw
.wiphy
->bands
[band
]->
307 bitrates
[rx_status
->rate_idx
].bitrate
;
309 rx_timestamp
= rx_status
->mactime
+ (24 * 8 * 10 / rate
);
310 } else if (local
&& local
->ops
&& local
->ops
->get_tsf
)
311 /* second best option: get current TSF */
312 rx_timestamp
= local
->ops
->get_tsf(local_to_hw(local
));
314 /* can't merge without knowing the TSF */
315 rx_timestamp
= -1LLU;
317 #ifdef CONFIG_MAC80211_IBSS_DEBUG
318 printk(KERN_DEBUG
"RX beacon SA=%pM BSSID="
319 "%pM TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
320 mgmt
->sa
, mgmt
->bssid
,
321 (unsigned long long)rx_timestamp
,
322 (unsigned long long)beacon_timestamp
,
323 (unsigned long long)(rx_timestamp
- beacon_timestamp
),
327 /* give slow hardware some time to do the TSF sync */
328 if (rx_timestamp
< IEEE80211_IBSS_MERGE_DELAY
)
331 if (beacon_timestamp
> rx_timestamp
) {
332 #ifdef CONFIG_MAC80211_IBSS_DEBUG
333 printk(KERN_DEBUG
"%s: beacon TSF higher than "
334 "local TSF - IBSS merge with BSSID %pM\n",
335 sdata
->dev
->name
, mgmt
->bssid
);
337 ieee80211_sta_join_ibss(sdata
, bss
);
338 ieee80211_ibss_add_sta(sdata
, mgmt
->bssid
, mgmt
->sa
, supp_rates
);
342 ieee80211_rx_bss_put(local
, bss
);
346 * Add a new IBSS station, will also be called by the RX code when,
347 * in IBSS mode, receiving a frame from a yet-unknown station, hence
348 * must be callable in atomic context.
350 struct sta_info
*ieee80211_ibss_add_sta(struct ieee80211_sub_if_data
*sdata
,
351 u8
*bssid
,u8
*addr
, u32 supp_rates
)
353 struct ieee80211_local
*local
= sdata
->local
;
354 struct sta_info
*sta
;
355 int band
= local
->hw
.conf
.channel
->band
;
358 * XXX: Consider removing the least recently used entry and
359 * allow new one to be added.
361 if (local
->num_sta
>= IEEE80211_IBSS_MAX_STA_ENTRIES
) {
363 printk(KERN_DEBUG
"%s: No room for a new IBSS STA entry %pM\n",
364 sdata
->dev
->name
, addr
);
368 if (compare_ether_addr(bssid
, sdata
->u
.ibss
.bssid
))
371 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
372 printk(KERN_DEBUG
"%s: Adding new IBSS station %pM (dev=%s)\n",
373 wiphy_name(local
->hw
.wiphy
), addr
, sdata
->dev
->name
);
376 sta
= sta_info_alloc(sdata
, addr
, GFP_ATOMIC
);
380 set_sta_flags(sta
, WLAN_STA_AUTHORIZED
);
382 /* make sure mandatory rates are always added */
383 sta
->sta
.supp_rates
[band
] = supp_rates
|
384 ieee80211_mandatory_rates(local
, band
);
386 rate_control_rate_init(sta
);
388 if (sta_info_insert(sta
))
394 static int ieee80211_sta_active_ibss(struct ieee80211_sub_if_data
*sdata
)
396 struct ieee80211_local
*local
= sdata
->local
;
398 struct sta_info
*sta
;
402 list_for_each_entry_rcu(sta
, &local
->sta_list
, list
) {
403 if (sta
->sdata
== sdata
&&
404 time_after(sta
->last_rx
+ IEEE80211_IBSS_MERGE_INTERVAL
,
417 static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data
*sdata
)
419 struct ieee80211_if_ibss
*ifibss
= &sdata
->u
.ibss
;
421 mod_timer(&ifibss
->timer
,
422 round_jiffies(jiffies
+ IEEE80211_IBSS_MERGE_INTERVAL
));
424 ieee80211_sta_expire(sdata
, IEEE80211_IBSS_INACTIVITY_LIMIT
);
426 if (ieee80211_sta_active_ibss(sdata
))
429 if (ifibss
->fixed_channel
)
432 printk(KERN_DEBUG
"%s: No active IBSS STAs - trying to scan for other "
433 "IBSS networks with same SSID (merge)\n", sdata
->dev
->name
);
435 /* XXX maybe racy? */
436 if (sdata
->local
->scan_req
)
439 memcpy(sdata
->local
->int_scan_req
.ssids
[0].ssid
,
440 ifibss
->ssid
, IEEE80211_MAX_SSID_LEN
);
441 sdata
->local
->int_scan_req
.ssids
[0].ssid_len
= ifibss
->ssid_len
;
442 ieee80211_request_scan(sdata
, &sdata
->local
->int_scan_req
);
445 static void ieee80211_sta_create_ibss(struct ieee80211_sub_if_data
*sdata
)
447 struct ieee80211_if_ibss
*ifibss
= &sdata
->u
.ibss
;
448 struct ieee80211_local
*local
= sdata
->local
;
449 struct ieee80211_supported_band
*sband
;
452 u8 supp_rates
[IEEE80211_MAX_SUPP_RATES
];
456 if (ifibss
->fixed_bssid
) {
457 memcpy(bssid
, ifibss
->bssid
, ETH_ALEN
);
459 /* Generate random, not broadcast, locally administered BSSID. Mix in
460 * own MAC address to make sure that devices that do not have proper
461 * random number generator get different BSSID. */
462 get_random_bytes(bssid
, ETH_ALEN
);
463 for (i
= 0; i
< ETH_ALEN
; i
++)
464 bssid
[i
] ^= sdata
->dev
->dev_addr
[i
];
469 printk(KERN_DEBUG
"%s: Creating new IBSS network, BSSID %pM\n",
470 sdata
->dev
->name
, bssid
);
472 sband
= local
->hw
.wiphy
->bands
[ifibss
->channel
->band
];
474 if (local
->hw
.conf
.beacon_int
== 0)
475 local
->hw
.conf
.beacon_int
= 100;
477 capability
= WLAN_CAPABILITY_IBSS
;
479 if (sdata
->default_key
)
480 capability
|= WLAN_CAPABILITY_PRIVACY
;
482 sdata
->drop_unencrypted
= 0;
485 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
486 int rate
= sband
->bitrates
[i
].bitrate
;
487 *pos
++ = (u8
) (rate
/ 5);
490 __ieee80211_sta_join_ibss(sdata
, bssid
, local
->hw
.conf
.beacon_int
,
491 ifibss
->channel
, sband
->n_bitrates
,
492 supp_rates
, capability
, 0);
495 static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data
*sdata
)
497 struct ieee80211_if_ibss
*ifibss
= &sdata
->u
.ibss
;
498 struct ieee80211_local
*local
= sdata
->local
;
499 struct ieee80211_bss
*bss
;
500 struct ieee80211_channel
*chan
= NULL
;
501 const u8
*bssid
= NULL
;
504 active_ibss
= ieee80211_sta_active_ibss(sdata
);
505 #ifdef CONFIG_MAC80211_IBSS_DEBUG
506 printk(KERN_DEBUG
"%s: sta_find_ibss (active_ibss=%d)\n",
507 sdata
->dev
->name
, active_ibss
);
508 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
513 if (ifibss
->fixed_bssid
)
514 bssid
= ifibss
->bssid
;
515 if (ifibss
->fixed_channel
)
516 chan
= ifibss
->channel
;
517 if (!is_zero_ether_addr(ifibss
->bssid
))
518 bssid
= ifibss
->bssid
;
519 bss
= (void *)cfg80211_get_bss(local
->hw
.wiphy
, chan
, bssid
,
520 ifibss
->ssid
, ifibss
->ssid_len
,
521 WLAN_CAPABILITY_IBSS
,
522 WLAN_CAPABILITY_IBSS
);
524 #ifdef CONFIG_MAC80211_IBSS_DEBUG
526 printk(KERN_DEBUG
" sta_find_ibss: selected %pM current "
527 "%pM\n", bss
->cbss
.bssid
, ifibss
->bssid
);
528 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
530 if (bss
&& memcmp(ifibss
->bssid
, bss
->cbss
.bssid
, ETH_ALEN
)) {
531 printk(KERN_DEBUG
"%s: Selected IBSS BSSID %pM"
532 " based on configured SSID\n",
533 sdata
->dev
->name
, bss
->cbss
.bssid
);
535 ieee80211_sta_join_ibss(sdata
, bss
);
536 ieee80211_rx_bss_put(local
, bss
);
539 ieee80211_rx_bss_put(local
, bss
);
541 #ifdef CONFIG_MAC80211_IBSS_DEBUG
542 printk(KERN_DEBUG
" did not try to join ibss\n");
543 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
545 /* Selected IBSS not found in current scan results - try to scan */
546 if (ifibss
->state
== IEEE80211_IBSS_MLME_JOINED
&&
547 !ieee80211_sta_active_ibss(sdata
)) {
548 mod_timer(&ifibss
->timer
,
549 round_jiffies(jiffies
+ IEEE80211_IBSS_MERGE_INTERVAL
));
550 } else if (time_after(jiffies
, ifibss
->last_scan_completed
+
551 IEEE80211_SCAN_INTERVAL
)) {
552 printk(KERN_DEBUG
"%s: Trigger new scan to find an IBSS to "
553 "join\n", sdata
->dev
->name
);
555 /* XXX maybe racy? */
559 memcpy(local
->int_scan_req
.ssids
[0].ssid
,
560 ifibss
->ssid
, IEEE80211_MAX_SSID_LEN
);
561 local
->int_scan_req
.ssids
[0].ssid_len
=
563 ieee80211_request_scan(sdata
, &local
->int_scan_req
);
564 } else if (ifibss
->state
!= IEEE80211_IBSS_MLME_JOINED
) {
565 int interval
= IEEE80211_SCAN_INTERVAL
;
567 if (time_after(jiffies
, ifibss
->ibss_join_req
+
568 IEEE80211_IBSS_JOIN_TIMEOUT
)) {
569 if (!(local
->oper_channel
->flags
& IEEE80211_CHAN_NO_IBSS
)) {
570 ieee80211_sta_create_ibss(sdata
);
573 printk(KERN_DEBUG
"%s: IBSS not allowed on"
574 " %d MHz\n", sdata
->dev
->name
,
575 local
->hw
.conf
.channel
->center_freq
);
577 /* No IBSS found - decrease scan interval and continue
579 interval
= IEEE80211_SCAN_INTERVAL_SLOW
;
582 ifibss
->state
= IEEE80211_IBSS_MLME_SEARCH
;
583 mod_timer(&ifibss
->timer
,
584 round_jiffies(jiffies
+ interval
));
588 static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data
*sdata
,
589 struct ieee80211_mgmt
*mgmt
,
592 struct ieee80211_if_ibss
*ifibss
= &sdata
->u
.ibss
;
593 struct ieee80211_local
*local
= sdata
->local
;
596 struct ieee80211_mgmt
*resp
;
599 if (ifibss
->state
!= IEEE80211_IBSS_MLME_JOINED
||
600 len
< 24 + 2 || !ifibss
->presp
)
603 if (local
->ops
->tx_last_beacon
)
604 tx_last_beacon
= local
->ops
->tx_last_beacon(local_to_hw(local
));
608 #ifdef CONFIG_MAC80211_IBSS_DEBUG
609 printk(KERN_DEBUG
"%s: RX ProbeReq SA=%pM DA=%pM BSSID=%pM"
610 " (tx_last_beacon=%d)\n",
611 sdata
->dev
->name
, mgmt
->sa
, mgmt
->da
,
612 mgmt
->bssid
, tx_last_beacon
);
613 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
618 if (memcmp(mgmt
->bssid
, ifibss
->bssid
, ETH_ALEN
) != 0 &&
619 memcmp(mgmt
->bssid
, "\xff\xff\xff\xff\xff\xff", ETH_ALEN
) != 0)
622 end
= ((u8
*) mgmt
) + len
;
623 pos
= mgmt
->u
.probe_req
.variable
;
624 if (pos
[0] != WLAN_EID_SSID
||
625 pos
+ 2 + pos
[1] > end
) {
626 #ifdef CONFIG_MAC80211_IBSS_DEBUG
627 printk(KERN_DEBUG
"%s: Invalid SSID IE in ProbeReq "
629 sdata
->dev
->name
, mgmt
->sa
);
634 (pos
[1] != ifibss
->ssid_len
||
635 !memcmp(pos
+ 2, ifibss
->ssid
, ifibss
->ssid_len
))) {
636 /* Ignore ProbeReq for foreign SSID */
640 /* Reply with ProbeResp */
641 skb
= skb_copy(ifibss
->presp
, GFP_KERNEL
);
645 resp
= (struct ieee80211_mgmt
*) skb
->data
;
646 memcpy(resp
->da
, mgmt
->sa
, ETH_ALEN
);
647 #ifdef CONFIG_MAC80211_IBSS_DEBUG
648 printk(KERN_DEBUG
"%s: Sending ProbeResp to %pM\n",
649 sdata
->dev
->name
, resp
->da
);
650 #endif /* CONFIG_MAC80211_IBSS_DEBUG */
651 ieee80211_tx_skb(sdata
, skb
, 0);
654 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data
*sdata
,
655 struct ieee80211_mgmt
*mgmt
,
657 struct ieee80211_rx_status
*rx_status
)
660 struct ieee802_11_elems elems
;
662 if (memcmp(mgmt
->da
, sdata
->dev
->dev_addr
, ETH_ALEN
))
663 return; /* ignore ProbeResp to foreign address */
665 baselen
= (u8
*) mgmt
->u
.probe_resp
.variable
- (u8
*) mgmt
;
669 ieee802_11_parse_elems(mgmt
->u
.probe_resp
.variable
, len
- baselen
,
672 ieee80211_rx_bss_info(sdata
, mgmt
, len
, rx_status
, &elems
, false);
675 static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data
*sdata
,
676 struct ieee80211_mgmt
*mgmt
,
678 struct ieee80211_rx_status
*rx_status
)
681 struct ieee802_11_elems elems
;
683 /* Process beacon from the current BSS */
684 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
688 ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
, len
- baselen
, &elems
);
690 ieee80211_rx_bss_info(sdata
, mgmt
, len
, rx_status
, &elems
, true);
693 static void ieee80211_ibss_rx_queued_mgmt(struct ieee80211_sub_if_data
*sdata
,
696 struct ieee80211_rx_status
*rx_status
;
697 struct ieee80211_mgmt
*mgmt
;
700 rx_status
= (struct ieee80211_rx_status
*) skb
->cb
;
701 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
702 fc
= le16_to_cpu(mgmt
->frame_control
);
704 switch (fc
& IEEE80211_FCTL_STYPE
) {
705 case IEEE80211_STYPE_PROBE_REQ
:
706 ieee80211_rx_mgmt_probe_req(sdata
, mgmt
, skb
->len
);
708 case IEEE80211_STYPE_PROBE_RESP
:
709 ieee80211_rx_mgmt_probe_resp(sdata
, mgmt
, skb
->len
,
712 case IEEE80211_STYPE_BEACON
:
713 ieee80211_rx_mgmt_beacon(sdata
, mgmt
, skb
->len
,
716 case IEEE80211_STYPE_AUTH
:
717 ieee80211_rx_mgmt_auth_ibss(sdata
, mgmt
, skb
->len
);
724 static void ieee80211_ibss_work(struct work_struct
*work
)
726 struct ieee80211_sub_if_data
*sdata
=
727 container_of(work
, struct ieee80211_sub_if_data
, u
.ibss
.work
);
728 struct ieee80211_local
*local
= sdata
->local
;
729 struct ieee80211_if_ibss
*ifibss
;
732 if (!netif_running(sdata
->dev
))
735 if (local
->sw_scanning
|| local
->hw_scanning
)
738 if (WARN_ON(sdata
->vif
.type
!= NL80211_IFTYPE_ADHOC
))
740 ifibss
= &sdata
->u
.ibss
;
742 while ((skb
= skb_dequeue(&ifibss
->skb_queue
)))
743 ieee80211_ibss_rx_queued_mgmt(sdata
, skb
);
745 if (!test_and_clear_bit(IEEE80211_IBSS_REQ_RUN
, &ifibss
->request
))
748 switch (ifibss
->state
) {
749 case IEEE80211_IBSS_MLME_SEARCH
:
750 ieee80211_sta_find_ibss(sdata
);
752 case IEEE80211_IBSS_MLME_JOINED
:
753 ieee80211_sta_merge_ibss(sdata
);
761 static void ieee80211_ibss_timer(unsigned long data
)
763 struct ieee80211_sub_if_data
*sdata
=
764 (struct ieee80211_sub_if_data
*) data
;
765 struct ieee80211_if_ibss
*ifibss
= &sdata
->u
.ibss
;
766 struct ieee80211_local
*local
= sdata
->local
;
768 set_bit(IEEE80211_IBSS_REQ_RUN
, &ifibss
->request
);
769 queue_work(local
->hw
.workqueue
, &ifibss
->work
);
772 void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data
*sdata
)
774 struct ieee80211_if_ibss
*ifibss
= &sdata
->u
.ibss
;
776 INIT_WORK(&ifibss
->work
, ieee80211_ibss_work
);
777 setup_timer(&ifibss
->timer
, ieee80211_ibss_timer
,
778 (unsigned long) sdata
);
779 skb_queue_head_init(&ifibss
->skb_queue
);
782 /* scan finished notification */
783 void ieee80211_ibss_notify_scan_completed(struct ieee80211_local
*local
)
785 struct ieee80211_sub_if_data
*sdata
;
788 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
789 if (sdata
->vif
.type
!= NL80211_IFTYPE_ADHOC
)
791 sdata
->u
.ibss
.last_scan_completed
= jiffies
;
792 ieee80211_sta_find_ibss(sdata
);
798 ieee80211_ibss_rx_mgmt(struct ieee80211_sub_if_data
*sdata
, struct sk_buff
*skb
,
799 struct ieee80211_rx_status
*rx_status
)
801 struct ieee80211_local
*local
= sdata
->local
;
802 struct ieee80211_mgmt
*mgmt
;
806 return RX_DROP_MONITOR
;
808 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
809 fc
= le16_to_cpu(mgmt
->frame_control
);
811 switch (fc
& IEEE80211_FCTL_STYPE
) {
812 case IEEE80211_STYPE_PROBE_RESP
:
813 case IEEE80211_STYPE_BEACON
:
814 memcpy(skb
->cb
, rx_status
, sizeof(*rx_status
));
815 case IEEE80211_STYPE_PROBE_REQ
:
816 case IEEE80211_STYPE_AUTH
:
817 skb_queue_tail(&sdata
->u
.ibss
.skb_queue
, skb
);
818 queue_work(local
->hw
.workqueue
, &sdata
->u
.ibss
.work
);
822 return RX_DROP_MONITOR
;
825 int ieee80211_ibss_join(struct ieee80211_sub_if_data
*sdata
,
826 struct cfg80211_ibss_params
*params
)
830 memcpy(sdata
->u
.ibss
.ssid
, params
->ssid
, IEEE80211_MAX_SSID_LEN
);
831 sdata
->u
.ibss
.ssid_len
= params
->ssid_len
;
834 memcpy(sdata
->u
.ibss
.bssid
, params
->bssid
, ETH_ALEN
);
835 sdata
->u
.ibss
.fixed_bssid
= true;
837 sdata
->u
.ibss
.fixed_bssid
= false;
839 sdata
->u
.ibss
.channel
= params
->channel
;
840 sdata
->u
.ibss
.fixed_channel
= params
->channel_fixed
;
843 sdata
->u
.ibss
.ie
= kmemdup(params
->ie
, params
->ie_len
,
845 if (sdata
->u
.ibss
.ie
)
846 sdata
->u
.ibss
.ie_len
= params
->ie_len
;
849 skb
= dev_alloc_skb(sdata
->local
->hw
.extra_tx_headroom
+
853 4 /* IBSS params */ +
858 sdata
->u
.ibss
.skb
= skb
;
859 sdata
->u
.ibss
.state
= IEEE80211_IBSS_MLME_SEARCH
;
860 sdata
->u
.ibss
.ibss_join_req
= jiffies
;
862 set_bit(IEEE80211_IBSS_REQ_RUN
, &sdata
->u
.ibss
.request
);
863 queue_work(sdata
->local
->hw
.workqueue
, &sdata
->u
.ibss
.work
);
868 int ieee80211_ibss_leave(struct ieee80211_sub_if_data
*sdata
)
872 del_timer_sync(&sdata
->u
.ibss
.timer
);
873 clear_bit(IEEE80211_IBSS_REQ_RUN
, &sdata
->u
.ibss
.request
);
874 cancel_work_sync(&sdata
->u
.ibss
.work
);
875 clear_bit(IEEE80211_IBSS_REQ_RUN
, &sdata
->u
.ibss
.request
);
877 sta_info_flush(sdata
->local
, sdata
);
880 kfree(sdata
->u
.ibss
.ie
);
881 skb
= sdata
->u
.ibss
.presp
;
882 rcu_assign_pointer(sdata
->u
.ibss
.presp
, NULL
);
883 ieee80211_if_config(sdata
, IEEE80211_IFCC_BEACON_ENABLED
);
887 skb_queue_purge(&sdata
->u
.ibss
.skb_queue
);
888 memset(sdata
->u
.ibss
.bssid
, 0, ETH_ALEN
);