Commit | Line | Data |
---|---|---|
46900298 JB |
1 | /* |
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> | |
9 | * | |
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. | |
13 | */ | |
14 | ||
15 | #include <linux/delay.h> | |
5a0e3ad6 | 16 | #include <linux/slab.h> |
46900298 JB |
17 | #include <linux/if_ether.h> |
18 | #include <linux/skbuff.h> | |
19 | #include <linux/if_arp.h> | |
20 | #include <linux/etherdevice.h> | |
21 | #include <linux/rtnetlink.h> | |
22 | #include <net/mac80211.h> | |
23 | #include <asm/unaligned.h> | |
24 | ||
25 | #include "ieee80211_i.h" | |
24487981 | 26 | #include "driver-ops.h" |
46900298 JB |
27 | #include "rate.h" |
28 | ||
29 | #define IEEE80211_SCAN_INTERVAL (2 * HZ) | |
30 | #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ) | |
31 | #define IEEE80211_IBSS_JOIN_TIMEOUT (7 * HZ) | |
32 | ||
33 | #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ) | |
4a332a38 | 34 | #define IEEE80211_IBSS_MERGE_DELAY 0x400000 |
46900298 JB |
35 | #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ) |
36 | ||
37 | #define IEEE80211_IBSS_MAX_STA_ENTRIES 128 | |
38 | ||
39 | ||
40 | static void ieee80211_rx_mgmt_auth_ibss(struct ieee80211_sub_if_data *sdata, | |
41 | struct ieee80211_mgmt *mgmt, | |
42 | size_t len) | |
43 | { | |
44 | u16 auth_alg, auth_transaction, status_code; | |
45 | ||
7a17a33c JB |
46 | lockdep_assert_held(&sdata->u.ibss.mtx); |
47 | ||
46900298 JB |
48 | if (len < 24 + 6) |
49 | return; | |
50 | ||
51 | auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg); | |
52 | auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); | |
53 | status_code = le16_to_cpu(mgmt->u.auth.status_code); | |
54 | ||
55 | /* | |
56 | * IEEE 802.11 standard does not require authentication in IBSS | |
57 | * networks and most implementations do not seem to use it. | |
58 | * However, try to reply to authentication attempts if someone | |
59 | * has actually implemented this. | |
60 | */ | |
61 | if (auth_alg == WLAN_AUTH_OPEN && auth_transaction == 1) | |
62 | ieee80211_send_auth(sdata, 2, WLAN_AUTH_OPEN, NULL, 0, | |
fffd0934 | 63 | sdata->u.ibss.bssid, NULL, 0, 0); |
46900298 JB |
64 | } |
65 | ||
af8cdcd8 JB |
66 | static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata, |
67 | const u8 *bssid, const int beacon_int, | |
68 | struct ieee80211_channel *chan, | |
b59066a2 | 69 | const u32 basic_rates, |
af8cdcd8 | 70 | const u16 capability, u64 tsf) |
46900298 JB |
71 | { |
72 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; | |
73 | struct ieee80211_local *local = sdata->local; | |
b59066a2 | 74 | int rates, i; |
46900298 JB |
75 | struct sk_buff *skb; |
76 | struct ieee80211_mgmt *mgmt; | |
77 | u8 *pos; | |
78 | struct ieee80211_supported_band *sband; | |
f446d10f | 79 | struct cfg80211_bss *bss; |
57c4d7b4 | 80 | u32 bss_change; |
b59066a2 | 81 | u8 supp_rates[IEEE80211_MAX_SUPP_RATES]; |
24487981 | 82 | |
7a17a33c JB |
83 | lockdep_assert_held(&ifibss->mtx); |
84 | ||
24487981 JB |
85 | /* Reset own TSF to allow time synchronization work. */ |
86 | drv_reset_tsf(local); | |
46900298 | 87 | |
af8cdcd8 JB |
88 | skb = ifibss->skb; |
89 | rcu_assign_pointer(ifibss->presp, NULL); | |
90 | synchronize_rcu(); | |
91 | skb->data = skb->head; | |
92 | skb->len = 0; | |
93 | skb_reset_tail_pointer(skb); | |
94 | skb_reserve(skb, sdata->local->hw.extra_tx_headroom); | |
46900298 | 95 | |
af8cdcd8 JB |
96 | if (memcmp(ifibss->bssid, bssid, ETH_ALEN)) |
97 | sta_info_flush(sdata->local, sdata); | |
46900298 | 98 | |
49b5c7f4 JB |
99 | /* if merging, indicate to driver that we leave the old IBSS */ |
100 | if (sdata->vif.bss_conf.ibss_joined) { | |
101 | sdata->vif.bss_conf.ibss_joined = false; | |
102 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_IBSS); | |
103 | } | |
104 | ||
46900298 | 105 | memcpy(ifibss->bssid, bssid, ETH_ALEN); |
46900298 | 106 | |
af8cdcd8 | 107 | sdata->drop_unencrypted = capability & WLAN_CAPABILITY_PRIVACY ? 1 : 0; |
46900298 | 108 | |
af8cdcd8 | 109 | local->oper_channel = chan; |
0aaffa9b | 110 | WARN_ON(!ieee80211_set_channel_type(local, sdata, NL80211_CHAN_NO_HT)); |
af8cdcd8 | 111 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL); |
57c4d7b4 | 112 | |
af8cdcd8 | 113 | sband = local->hw.wiphy->bands[chan->band]; |
46900298 | 114 | |
b59066a2 JB |
115 | /* build supported rates array */ |
116 | pos = supp_rates; | |
117 | for (i = 0; i < sband->n_bitrates; i++) { | |
118 | int rate = sband->bitrates[i].bitrate; | |
119 | u8 basic = 0; | |
120 | if (basic_rates & BIT(i)) | |
121 | basic = 0x80; | |
122 | *pos++ = basic | (u8) (rate / 5); | |
123 | } | |
124 | ||
46900298 | 125 | /* Build IBSS probe response */ |
af8cdcd8 | 126 | mgmt = (void *) skb_put(skb, 24 + sizeof(mgmt->u.beacon)); |
46900298 JB |
127 | memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon)); |
128 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | |
129 | IEEE80211_STYPE_PROBE_RESP); | |
130 | memset(mgmt->da, 0xff, ETH_ALEN); | |
47846c9b | 131 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); |
46900298 | 132 | memcpy(mgmt->bssid, ifibss->bssid, ETH_ALEN); |
57c4d7b4 | 133 | mgmt->u.beacon.beacon_int = cpu_to_le16(beacon_int); |
707c1b4e | 134 | mgmt->u.beacon.timestamp = cpu_to_le64(tsf); |
46900298 JB |
135 | mgmt->u.beacon.capab_info = cpu_to_le16(capability); |
136 | ||
137 | pos = skb_put(skb, 2 + ifibss->ssid_len); | |
138 | *pos++ = WLAN_EID_SSID; | |
139 | *pos++ = ifibss->ssid_len; | |
140 | memcpy(pos, ifibss->ssid, ifibss->ssid_len); | |
141 | ||
b59066a2 | 142 | rates = sband->n_bitrates; |
46900298 JB |
143 | if (rates > 8) |
144 | rates = 8; | |
145 | pos = skb_put(skb, 2 + rates); | |
146 | *pos++ = WLAN_EID_SUPP_RATES; | |
147 | *pos++ = rates; | |
148 | memcpy(pos, supp_rates, rates); | |
149 | ||
150 | if (sband->band == IEEE80211_BAND_2GHZ) { | |
151 | pos = skb_put(skb, 2 + 1); | |
152 | *pos++ = WLAN_EID_DS_PARAMS; | |
153 | *pos++ = 1; | |
af8cdcd8 | 154 | *pos++ = ieee80211_frequency_to_channel(chan->center_freq); |
46900298 JB |
155 | } |
156 | ||
157 | pos = skb_put(skb, 2 + 2); | |
158 | *pos++ = WLAN_EID_IBSS_PARAMS; | |
159 | *pos++ = 2; | |
160 | /* FIX: set ATIM window based on scan results */ | |
161 | *pos++ = 0; | |
162 | *pos++ = 0; | |
163 | ||
b59066a2 JB |
164 | if (sband->n_bitrates > 8) { |
165 | rates = sband->n_bitrates - 8; | |
46900298 JB |
166 | pos = skb_put(skb, 2 + rates); |
167 | *pos++ = WLAN_EID_EXT_SUPP_RATES; | |
168 | *pos++ = rates; | |
169 | memcpy(pos, &supp_rates[8], rates); | |
170 | } | |
171 | ||
af8cdcd8 JB |
172 | if (ifibss->ie_len) |
173 | memcpy(skb_put(skb, ifibss->ie_len), | |
174 | ifibss->ie, ifibss->ie_len); | |
175 | ||
9eba6125 BR |
176 | if (local->hw.queues >= 4) { |
177 | pos = skb_put(skb, 9); | |
178 | *pos++ = WLAN_EID_VENDOR_SPECIFIC; | |
179 | *pos++ = 7; /* len */ | |
180 | *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */ | |
181 | *pos++ = 0x50; | |
182 | *pos++ = 0xf2; | |
183 | *pos++ = 2; /* WME */ | |
184 | *pos++ = 0; /* WME info */ | |
185 | *pos++ = 1; /* WME ver */ | |
186 | *pos++ = 0; /* U-APSD no in use */ | |
187 | } | |
188 | ||
af8cdcd8 | 189 | rcu_assign_pointer(ifibss->presp, skb); |
46900298 | 190 | |
2d0ddec5 | 191 | sdata->vif.bss_conf.beacon_int = beacon_int; |
fbd2c8dc | 192 | sdata->vif.bss_conf.basic_rates = basic_rates; |
2d0ddec5 JB |
193 | bss_change = BSS_CHANGED_BEACON_INT; |
194 | bss_change |= ieee80211_reset_erp_info(sdata); | |
195 | bss_change |= BSS_CHANGED_BSSID; | |
196 | bss_change |= BSS_CHANGED_BEACON; | |
197 | bss_change |= BSS_CHANGED_BEACON_ENABLED; | |
392cfdb1 | 198 | bss_change |= BSS_CHANGED_BASIC_RATES; |
8fc214ba JB |
199 | bss_change |= BSS_CHANGED_IBSS; |
200 | sdata->vif.bss_conf.ibss_joined = true; | |
2d0ddec5 | 201 | ieee80211_bss_info_change_notify(sdata, bss_change); |
46900298 | 202 | |
b59066a2 | 203 | ieee80211_sta_def_wmm_params(sdata, sband->n_bitrates, supp_rates); |
46900298 | 204 | |
46900298 | 205 | ifibss->state = IEEE80211_IBSS_MLME_JOINED; |
af8cdcd8 JB |
206 | mod_timer(&ifibss->timer, |
207 | round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL)); | |
46900298 | 208 | |
f446d10f JB |
209 | bss = cfg80211_inform_bss_frame(local->hw.wiphy, local->hw.conf.channel, |
210 | mgmt, skb->len, 0, GFP_KERNEL); | |
211 | cfg80211_put_bss(bss); | |
af8cdcd8 | 212 | cfg80211_ibss_joined(sdata->dev, ifibss->bssid, GFP_KERNEL); |
46900298 JB |
213 | } |
214 | ||
af8cdcd8 JB |
215 | static void ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata, |
216 | struct ieee80211_bss *bss) | |
46900298 | 217 | { |
0c1ad2ca JB |
218 | struct cfg80211_bss *cbss = |
219 | container_of((void *)bss, struct cfg80211_bss, priv); | |
b59066a2 JB |
220 | struct ieee80211_supported_band *sband; |
221 | u32 basic_rates; | |
222 | int i, j; | |
0c1ad2ca | 223 | u16 beacon_int = cbss->beacon_interval; |
57c4d7b4 | 224 | |
7a17a33c JB |
225 | lockdep_assert_held(&sdata->u.ibss.mtx); |
226 | ||
57c4d7b4 JB |
227 | if (beacon_int < 10) |
228 | beacon_int = 10; | |
229 | ||
0c1ad2ca | 230 | sband = sdata->local->hw.wiphy->bands[cbss->channel->band]; |
b59066a2 JB |
231 | |
232 | basic_rates = 0; | |
233 | ||
234 | for (i = 0; i < bss->supp_rates_len; i++) { | |
235 | int rate = (bss->supp_rates[i] & 0x7f) * 5; | |
236 | bool is_basic = !!(bss->supp_rates[i] & 0x80); | |
237 | ||
238 | for (j = 0; j < sband->n_bitrates; j++) { | |
239 | if (sband->bitrates[j].bitrate == rate) { | |
240 | if (is_basic) | |
241 | basic_rates |= BIT(j); | |
242 | break; | |
243 | } | |
244 | } | |
245 | } | |
246 | ||
0c1ad2ca | 247 | __ieee80211_sta_join_ibss(sdata, cbss->bssid, |
57c4d7b4 | 248 | beacon_int, |
0c1ad2ca | 249 | cbss->channel, |
b59066a2 | 250 | basic_rates, |
0c1ad2ca JB |
251 | cbss->capability, |
252 | cbss->tsf); | |
46900298 JB |
253 | } |
254 | ||
255 | static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, | |
256 | struct ieee80211_mgmt *mgmt, | |
257 | size_t len, | |
258 | struct ieee80211_rx_status *rx_status, | |
259 | struct ieee802_11_elems *elems, | |
260 | bool beacon) | |
261 | { | |
262 | struct ieee80211_local *local = sdata->local; | |
263 | int freq; | |
0c1ad2ca | 264 | struct cfg80211_bss *cbss; |
46900298 JB |
265 | struct ieee80211_bss *bss; |
266 | struct sta_info *sta; | |
267 | struct ieee80211_channel *channel; | |
268 | u64 beacon_timestamp, rx_timestamp; | |
269 | u32 supp_rates = 0; | |
270 | enum ieee80211_band band = rx_status->band; | |
271 | ||
272 | if (elems->ds_params && elems->ds_params_len == 1) | |
273 | freq = ieee80211_channel_to_frequency(elems->ds_params[0]); | |
274 | else | |
275 | freq = rx_status->freq; | |
276 | ||
277 | channel = ieee80211_get_channel(local->hw.wiphy, freq); | |
278 | ||
279 | if (!channel || channel->flags & IEEE80211_CHAN_DISABLED) | |
280 | return; | |
281 | ||
9eba6125 | 282 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC && |
46900298 | 283 | memcmp(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN) == 0) { |
46900298 JB |
284 | |
285 | rcu_read_lock(); | |
abe60632 | 286 | sta = sta_info_get(sdata, mgmt->sa); |
46900298 | 287 | |
9eba6125 BR |
288 | if (elems->supp_rates) { |
289 | supp_rates = ieee80211_sta_get_rates(local, elems, | |
290 | band); | |
291 | if (sta) { | |
292 | u32 prev_rates; | |
293 | ||
294 | prev_rates = sta->sta.supp_rates[band]; | |
295 | /* make sure mandatory rates are always added */ | |
296 | sta->sta.supp_rates[band] = supp_rates | | |
297 | ieee80211_mandatory_rates(local, band); | |
46900298 | 298 | |
9eba6125 | 299 | if (sta->sta.supp_rates[band] != prev_rates) { |
46900298 | 300 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
9eba6125 BR |
301 | printk(KERN_DEBUG |
302 | "%s: updated supp_rates set " | |
303 | "for %pM based on beacon" | |
304 | "/probe_resp (0x%x -> 0x%x)\n", | |
305 | sdata->name, sta->sta.addr, | |
306 | prev_rates, | |
307 | sta->sta.supp_rates[band]); | |
46900298 | 308 | #endif |
9eba6125 BR |
309 | rate_control_rate_init(sta); |
310 | } | |
311 | } else | |
312 | sta = ieee80211_ibss_add_sta(sdata, mgmt->bssid, | |
313 | mgmt->sa, supp_rates, | |
314 | GFP_ATOMIC); | |
34e89507 | 315 | } |
9eba6125 BR |
316 | |
317 | if (sta && elems->wmm_info) | |
318 | set_sta_flags(sta, WLAN_STA_WME); | |
319 | ||
320 | rcu_read_unlock(); | |
46900298 JB |
321 | } |
322 | ||
323 | bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems, | |
324 | channel, beacon); | |
325 | if (!bss) | |
326 | return; | |
327 | ||
0c1ad2ca JB |
328 | cbss = container_of((void *)bss, struct cfg80211_bss, priv); |
329 | ||
46900298 | 330 | /* was just updated in ieee80211_bss_info_update */ |
0c1ad2ca | 331 | beacon_timestamp = cbss->tsf; |
46900298 JB |
332 | |
333 | /* check if we need to merge IBSS */ | |
334 | ||
46900298 | 335 | /* we use a fixed BSSID */ |
a98bfec2 | 336 | if (sdata->u.ibss.fixed_bssid) |
46900298 JB |
337 | goto put_bss; |
338 | ||
339 | /* not an IBSS */ | |
0c1ad2ca | 340 | if (!(cbss->capability & WLAN_CAPABILITY_IBSS)) |
46900298 JB |
341 | goto put_bss; |
342 | ||
343 | /* different channel */ | |
0c1ad2ca | 344 | if (cbss->channel != local->oper_channel) |
46900298 JB |
345 | goto put_bss; |
346 | ||
347 | /* different SSID */ | |
348 | if (elems->ssid_len != sdata->u.ibss.ssid_len || | |
349 | memcmp(elems->ssid, sdata->u.ibss.ssid, | |
350 | sdata->u.ibss.ssid_len)) | |
351 | goto put_bss; | |
352 | ||
34e8f082 | 353 | /* same BSSID */ |
0c1ad2ca | 354 | if (memcmp(cbss->bssid, sdata->u.ibss.bssid, ETH_ALEN) == 0) |
34e8f082 AF |
355 | goto put_bss; |
356 | ||
46900298 JB |
357 | if (rx_status->flag & RX_FLAG_TSFT) { |
358 | /* | |
359 | * For correct IBSS merging we need mactime; since mactime is | |
360 | * defined as the time the first data symbol of the frame hits | |
361 | * the PHY, and the timestamp of the beacon is defined as "the | |
362 | * time that the data symbol containing the first bit of the | |
363 | * timestamp is transmitted to the PHY plus the transmitting | |
364 | * STA's delays through its local PHY from the MAC-PHY | |
365 | * interface to its interface with the WM" (802.11 11.1.2) | |
366 | * - equals the time this bit arrives at the receiver - we have | |
367 | * to take into account the offset between the two. | |
368 | * | |
369 | * E.g. at 1 MBit that means mactime is 192 usec earlier | |
370 | * (=24 bytes * 8 usecs/byte) than the beacon timestamp. | |
371 | */ | |
372 | int rate; | |
373 | ||
374 | if (rx_status->flag & RX_FLAG_HT) | |
375 | rate = 65; /* TODO: HT rates */ | |
376 | else | |
377 | rate = local->hw.wiphy->bands[band]-> | |
378 | bitrates[rx_status->rate_idx].bitrate; | |
379 | ||
380 | rx_timestamp = rx_status->mactime + (24 * 8 * 10 / rate); | |
24487981 JB |
381 | } else { |
382 | /* | |
383 | * second best option: get current TSF | |
384 | * (will return -1 if not supported) | |
385 | */ | |
386 | rx_timestamp = drv_get_tsf(local); | |
387 | } | |
46900298 JB |
388 | |
389 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | |
390 | printk(KERN_DEBUG "RX beacon SA=%pM BSSID=" | |
391 | "%pM TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n", | |
392 | mgmt->sa, mgmt->bssid, | |
393 | (unsigned long long)rx_timestamp, | |
394 | (unsigned long long)beacon_timestamp, | |
395 | (unsigned long long)(rx_timestamp - beacon_timestamp), | |
396 | jiffies); | |
397 | #endif | |
398 | ||
4a332a38 AF |
399 | /* give slow hardware some time to do the TSF sync */ |
400 | if (rx_timestamp < IEEE80211_IBSS_MERGE_DELAY) | |
401 | goto put_bss; | |
402 | ||
46900298 JB |
403 | if (beacon_timestamp > rx_timestamp) { |
404 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | |
405 | printk(KERN_DEBUG "%s: beacon TSF higher than " | |
406 | "local TSF - IBSS merge with BSSID %pM\n", | |
47846c9b | 407 | sdata->name, mgmt->bssid); |
46900298 JB |
408 | #endif |
409 | ieee80211_sta_join_ibss(sdata, bss); | |
09a08cff | 410 | supp_rates = ieee80211_sta_get_rates(local, elems, band); |
34e89507 JB |
411 | ieee80211_ibss_add_sta(sdata, mgmt->bssid, mgmt->sa, |
412 | supp_rates, GFP_KERNEL); | |
46900298 JB |
413 | } |
414 | ||
415 | put_bss: | |
416 | ieee80211_rx_bss_put(local, bss); | |
417 | } | |
418 | ||
419 | /* | |
420 | * Add a new IBSS station, will also be called by the RX code when, | |
421 | * in IBSS mode, receiving a frame from a yet-unknown station, hence | |
422 | * must be callable in atomic context. | |
423 | */ | |
424 | struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata, | |
34e89507 JB |
425 | u8 *bssid,u8 *addr, u32 supp_rates, |
426 | gfp_t gfp) | |
46900298 | 427 | { |
2e10d330 | 428 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
46900298 JB |
429 | struct ieee80211_local *local = sdata->local; |
430 | struct sta_info *sta; | |
431 | int band = local->hw.conf.channel->band; | |
432 | ||
af8cdcd8 JB |
433 | /* |
434 | * XXX: Consider removing the least recently used entry and | |
435 | * allow new one to be added. | |
436 | */ | |
46900298 | 437 | if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) { |
af8cdcd8 JB |
438 | if (net_ratelimit()) |
439 | printk(KERN_DEBUG "%s: No room for a new IBSS STA entry %pM\n", | |
47846c9b | 440 | sdata->name, addr); |
46900298 JB |
441 | return NULL; |
442 | } | |
443 | ||
2e10d330 FF |
444 | if (ifibss->state == IEEE80211_IBSS_MLME_SEARCH) |
445 | return NULL; | |
446 | ||
46900298 JB |
447 | if (compare_ether_addr(bssid, sdata->u.ibss.bssid)) |
448 | return NULL; | |
449 | ||
450 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG | |
0fb9a9ec JP |
451 | wiphy_debug(local->hw.wiphy, "Adding new IBSS station %pM (dev=%s)\n", |
452 | addr, sdata->name); | |
46900298 JB |
453 | #endif |
454 | ||
34e89507 | 455 | sta = sta_info_alloc(sdata, addr, gfp); |
46900298 JB |
456 | if (!sta) |
457 | return NULL; | |
458 | ||
459 | set_sta_flags(sta, WLAN_STA_AUTHORIZED); | |
460 | ||
461 | /* make sure mandatory rates are always added */ | |
462 | sta->sta.supp_rates[band] = supp_rates | | |
463 | ieee80211_mandatory_rates(local, band); | |
464 | ||
465 | rate_control_rate_init(sta); | |
466 | ||
34e89507 | 467 | /* If it fails, maybe we raced another insertion? */ |
46900298 | 468 | if (sta_info_insert(sta)) |
34e89507 | 469 | return sta_info_get(sdata, addr); |
46900298 JB |
470 | return sta; |
471 | } | |
472 | ||
473 | static int ieee80211_sta_active_ibss(struct ieee80211_sub_if_data *sdata) | |
474 | { | |
475 | struct ieee80211_local *local = sdata->local; | |
476 | int active = 0; | |
477 | struct sta_info *sta; | |
478 | ||
7a17a33c JB |
479 | lockdep_assert_held(&sdata->u.ibss.mtx); |
480 | ||
46900298 JB |
481 | rcu_read_lock(); |
482 | ||
483 | list_for_each_entry_rcu(sta, &local->sta_list, list) { | |
484 | if (sta->sdata == sdata && | |
485 | time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL, | |
486 | jiffies)) { | |
487 | active++; | |
488 | break; | |
489 | } | |
490 | } | |
491 | ||
492 | rcu_read_unlock(); | |
493 | ||
494 | return active; | |
495 | } | |
496 | ||
ce9058ae BP |
497 | /* |
498 | * This function is called with state == IEEE80211_IBSS_MLME_JOINED | |
499 | */ | |
46900298 JB |
500 | |
501 | static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata) | |
502 | { | |
503 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; | |
504 | ||
7a17a33c JB |
505 | lockdep_assert_held(&ifibss->mtx); |
506 | ||
af8cdcd8 JB |
507 | mod_timer(&ifibss->timer, |
508 | round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL)); | |
46900298 JB |
509 | |
510 | ieee80211_sta_expire(sdata, IEEE80211_IBSS_INACTIVITY_LIMIT); | |
af8cdcd8 | 511 | |
450aae3d S |
512 | if (time_before(jiffies, ifibss->last_scan_completed + |
513 | IEEE80211_IBSS_MERGE_INTERVAL)) | |
514 | return; | |
515 | ||
46900298 JB |
516 | if (ieee80211_sta_active_ibss(sdata)) |
517 | return; | |
518 | ||
af8cdcd8 | 519 | if (ifibss->fixed_channel) |
46900298 JB |
520 | return; |
521 | ||
522 | printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other " | |
47846c9b | 523 | "IBSS networks with same SSID (merge)\n", sdata->name); |
46900298 | 524 | |
be4a4b6a JB |
525 | ieee80211_request_internal_scan(sdata, |
526 | ifibss->ssid, ifibss->ssid_len, | |
527 | ifibss->fixed_channel ? ifibss->channel : NULL); | |
46900298 JB |
528 | } |
529 | ||
af8cdcd8 | 530 | static void ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata) |
46900298 JB |
531 | { |
532 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; | |
533 | struct ieee80211_local *local = sdata->local; | |
534 | struct ieee80211_supported_band *sband; | |
46900298 | 535 | u8 bssid[ETH_ALEN]; |
46900298 JB |
536 | u16 capability; |
537 | int i; | |
538 | ||
7a17a33c JB |
539 | lockdep_assert_held(&ifibss->mtx); |
540 | ||
af8cdcd8 | 541 | if (ifibss->fixed_bssid) { |
46900298 JB |
542 | memcpy(bssid, ifibss->bssid, ETH_ALEN); |
543 | } else { | |
544 | /* Generate random, not broadcast, locally administered BSSID. Mix in | |
545 | * own MAC address to make sure that devices that do not have proper | |
546 | * random number generator get different BSSID. */ | |
547 | get_random_bytes(bssid, ETH_ALEN); | |
548 | for (i = 0; i < ETH_ALEN; i++) | |
47846c9b | 549 | bssid[i] ^= sdata->vif.addr[i]; |
46900298 JB |
550 | bssid[0] &= ~0x01; |
551 | bssid[0] |= 0x02; | |
552 | } | |
553 | ||
554 | printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %pM\n", | |
47846c9b | 555 | sdata->name, bssid); |
46900298 | 556 | |
af8cdcd8 | 557 | sband = local->hw.wiphy->bands[ifibss->channel->band]; |
46900298 | 558 | |
46900298 JB |
559 | capability = WLAN_CAPABILITY_IBSS; |
560 | ||
fffd0934 | 561 | if (ifibss->privacy) |
46900298 JB |
562 | capability |= WLAN_CAPABILITY_PRIVACY; |
563 | else | |
564 | sdata->drop_unencrypted = 0; | |
565 | ||
57c4d7b4 | 566 | __ieee80211_sta_join_ibss(sdata, bssid, sdata->vif.bss_conf.beacon_int, |
fbd2c8dc | 567 | ifibss->channel, ifibss->basic_rates, |
b59066a2 | 568 | capability, 0); |
46900298 JB |
569 | } |
570 | ||
ce9058ae BP |
571 | /* |
572 | * This function is called with state == IEEE80211_IBSS_MLME_SEARCH | |
573 | */ | |
574 | ||
af8cdcd8 | 575 | static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata) |
46900298 JB |
576 | { |
577 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; | |
578 | struct ieee80211_local *local = sdata->local; | |
0c1ad2ca | 579 | struct cfg80211_bss *cbss; |
af8cdcd8 | 580 | struct ieee80211_channel *chan = NULL; |
46900298 JB |
581 | const u8 *bssid = NULL; |
582 | int active_ibss; | |
e0d61887 | 583 | u16 capability; |
46900298 | 584 | |
7a17a33c JB |
585 | lockdep_assert_held(&ifibss->mtx); |
586 | ||
46900298 JB |
587 | active_ibss = ieee80211_sta_active_ibss(sdata); |
588 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | |
589 | printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n", | |
47846c9b | 590 | sdata->name, active_ibss); |
46900298 JB |
591 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
592 | ||
593 | if (active_ibss) | |
af8cdcd8 | 594 | return; |
46900298 | 595 | |
e0d61887 | 596 | capability = WLAN_CAPABILITY_IBSS; |
fffd0934 | 597 | if (ifibss->privacy) |
e0d61887 | 598 | capability |= WLAN_CAPABILITY_PRIVACY; |
af8cdcd8 JB |
599 | if (ifibss->fixed_bssid) |
600 | bssid = ifibss->bssid; | |
601 | if (ifibss->fixed_channel) | |
602 | chan = ifibss->channel; | |
603 | if (!is_zero_ether_addr(ifibss->bssid)) | |
46900298 | 604 | bssid = ifibss->bssid; |
0c1ad2ca JB |
605 | cbss = cfg80211_get_bss(local->hw.wiphy, chan, bssid, |
606 | ifibss->ssid, ifibss->ssid_len, | |
607 | WLAN_CAPABILITY_IBSS | WLAN_CAPABILITY_PRIVACY, | |
608 | capability); | |
609 | ||
610 | if (cbss) { | |
611 | struct ieee80211_bss *bss; | |
46900298 | 612 | |
0c1ad2ca | 613 | bss = (void *)cbss->priv; |
46900298 | 614 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
46900298 | 615 | printk(KERN_DEBUG " sta_find_ibss: selected %pM current " |
0c1ad2ca | 616 | "%pM\n", cbss->bssid, ifibss->bssid); |
46900298 JB |
617 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
618 | ||
46900298 JB |
619 | printk(KERN_DEBUG "%s: Selected IBSS BSSID %pM" |
620 | " based on configured SSID\n", | |
0c1ad2ca | 621 | sdata->name, cbss->bssid); |
46900298 | 622 | |
af8cdcd8 | 623 | ieee80211_sta_join_ibss(sdata, bss); |
46900298 | 624 | ieee80211_rx_bss_put(local, bss); |
af8cdcd8 | 625 | return; |
d419b9f0 | 626 | } |
46900298 JB |
627 | |
628 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | |
629 | printk(KERN_DEBUG " did not try to join ibss\n"); | |
630 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ | |
631 | ||
632 | /* Selected IBSS not found in current scan results - try to scan */ | |
ce9058ae | 633 | if (time_after(jiffies, ifibss->last_scan_completed + |
46900298 JB |
634 | IEEE80211_SCAN_INTERVAL)) { |
635 | printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to " | |
47846c9b | 636 | "join\n", sdata->name); |
46900298 | 637 | |
be4a4b6a JB |
638 | ieee80211_request_internal_scan(sdata, |
639 | ifibss->ssid, ifibss->ssid_len, | |
640 | ifibss->fixed_channel ? ifibss->channel : NULL); | |
ce9058ae | 641 | } else { |
46900298 JB |
642 | int interval = IEEE80211_SCAN_INTERVAL; |
643 | ||
644 | if (time_after(jiffies, ifibss->ibss_join_req + | |
645 | IEEE80211_IBSS_JOIN_TIMEOUT)) { | |
af8cdcd8 JB |
646 | if (!(local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS)) { |
647 | ieee80211_sta_create_ibss(sdata); | |
648 | return; | |
649 | } | |
46900298 | 650 | printk(KERN_DEBUG "%s: IBSS not allowed on" |
47846c9b | 651 | " %d MHz\n", sdata->name, |
46900298 JB |
652 | local->hw.conf.channel->center_freq); |
653 | ||
654 | /* No IBSS found - decrease scan interval and continue | |
655 | * scanning. */ | |
656 | interval = IEEE80211_SCAN_INTERVAL_SLOW; | |
657 | } | |
658 | ||
af8cdcd8 JB |
659 | mod_timer(&ifibss->timer, |
660 | round_jiffies(jiffies + interval)); | |
46900298 | 661 | } |
46900298 JB |
662 | } |
663 | ||
664 | static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata, | |
665 | struct ieee80211_mgmt *mgmt, | |
666 | size_t len) | |
667 | { | |
668 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; | |
669 | struct ieee80211_local *local = sdata->local; | |
670 | int tx_last_beacon; | |
671 | struct sk_buff *skb; | |
672 | struct ieee80211_mgmt *resp; | |
673 | u8 *pos, *end; | |
674 | ||
7a17a33c JB |
675 | lockdep_assert_held(&ifibss->mtx); |
676 | ||
46900298 | 677 | if (ifibss->state != IEEE80211_IBSS_MLME_JOINED || |
af8cdcd8 | 678 | len < 24 + 2 || !ifibss->presp) |
46900298 JB |
679 | return; |
680 | ||
24487981 | 681 | tx_last_beacon = drv_tx_last_beacon(local); |
46900298 JB |
682 | |
683 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | |
684 | printk(KERN_DEBUG "%s: RX ProbeReq SA=%pM DA=%pM BSSID=%pM" | |
685 | " (tx_last_beacon=%d)\n", | |
47846c9b | 686 | sdata->name, mgmt->sa, mgmt->da, |
46900298 JB |
687 | mgmt->bssid, tx_last_beacon); |
688 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ | |
689 | ||
690 | if (!tx_last_beacon) | |
691 | return; | |
692 | ||
693 | if (memcmp(mgmt->bssid, ifibss->bssid, ETH_ALEN) != 0 && | |
694 | memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0) | |
695 | return; | |
696 | ||
697 | end = ((u8 *) mgmt) + len; | |
698 | pos = mgmt->u.probe_req.variable; | |
699 | if (pos[0] != WLAN_EID_SSID || | |
700 | pos + 2 + pos[1] > end) { | |
701 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | |
702 | printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq " | |
703 | "from %pM\n", | |
47846c9b | 704 | sdata->name, mgmt->sa); |
46900298 JB |
705 | #endif |
706 | return; | |
707 | } | |
708 | if (pos[1] != 0 && | |
709 | (pos[1] != ifibss->ssid_len || | |
0da780c2 | 710 | memcmp(pos + 2, ifibss->ssid, ifibss->ssid_len))) { |
46900298 JB |
711 | /* Ignore ProbeReq for foreign SSID */ |
712 | return; | |
713 | } | |
714 | ||
715 | /* Reply with ProbeResp */ | |
af8cdcd8 | 716 | skb = skb_copy(ifibss->presp, GFP_KERNEL); |
46900298 JB |
717 | if (!skb) |
718 | return; | |
719 | ||
720 | resp = (struct ieee80211_mgmt *) skb->data; | |
721 | memcpy(resp->da, mgmt->sa, ETH_ALEN); | |
722 | #ifdef CONFIG_MAC80211_IBSS_DEBUG | |
723 | printk(KERN_DEBUG "%s: Sending ProbeResp to %pM\n", | |
47846c9b | 724 | sdata->name, resp->da); |
46900298 | 725 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
62ae67be JB |
726 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
727 | ieee80211_tx_skb(sdata, skb); | |
46900298 JB |
728 | } |
729 | ||
730 | static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata, | |
731 | struct ieee80211_mgmt *mgmt, | |
732 | size_t len, | |
733 | struct ieee80211_rx_status *rx_status) | |
734 | { | |
735 | size_t baselen; | |
736 | struct ieee802_11_elems elems; | |
737 | ||
47846c9b | 738 | if (memcmp(mgmt->da, sdata->vif.addr, ETH_ALEN)) |
46900298 JB |
739 | return; /* ignore ProbeResp to foreign address */ |
740 | ||
741 | baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; | |
742 | if (baselen > len) | |
743 | return; | |
744 | ||
745 | ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen, | |
746 | &elems); | |
747 | ||
748 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false); | |
749 | } | |
750 | ||
751 | static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata, | |
752 | struct ieee80211_mgmt *mgmt, | |
753 | size_t len, | |
754 | struct ieee80211_rx_status *rx_status) | |
755 | { | |
756 | size_t baselen; | |
757 | struct ieee802_11_elems elems; | |
758 | ||
759 | /* Process beacon from the current BSS */ | |
760 | baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; | |
761 | if (baselen > len) | |
762 | return; | |
763 | ||
764 | ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems); | |
765 | ||
766 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true); | |
767 | } | |
768 | ||
1fa57d01 JB |
769 | void ieee80211_ibss_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, |
770 | struct sk_buff *skb) | |
46900298 JB |
771 | { |
772 | struct ieee80211_rx_status *rx_status; | |
773 | struct ieee80211_mgmt *mgmt; | |
774 | u16 fc; | |
775 | ||
f1d58c25 | 776 | rx_status = IEEE80211_SKB_RXCB(skb); |
46900298 JB |
777 | mgmt = (struct ieee80211_mgmt *) skb->data; |
778 | fc = le16_to_cpu(mgmt->frame_control); | |
779 | ||
7a17a33c JB |
780 | mutex_lock(&sdata->u.ibss.mtx); |
781 | ||
46900298 JB |
782 | switch (fc & IEEE80211_FCTL_STYPE) { |
783 | case IEEE80211_STYPE_PROBE_REQ: | |
784 | ieee80211_rx_mgmt_probe_req(sdata, mgmt, skb->len); | |
785 | break; | |
786 | case IEEE80211_STYPE_PROBE_RESP: | |
787 | ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len, | |
788 | rx_status); | |
789 | break; | |
790 | case IEEE80211_STYPE_BEACON: | |
791 | ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, | |
792 | rx_status); | |
793 | break; | |
794 | case IEEE80211_STYPE_AUTH: | |
795 | ieee80211_rx_mgmt_auth_ibss(sdata, mgmt, skb->len); | |
796 | break; | |
797 | } | |
7a17a33c JB |
798 | |
799 | mutex_unlock(&sdata->u.ibss.mtx); | |
46900298 JB |
800 | } |
801 | ||
1fa57d01 | 802 | void ieee80211_ibss_work(struct ieee80211_sub_if_data *sdata) |
46900298 | 803 | { |
1fa57d01 | 804 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
46900298 | 805 | |
7a17a33c JB |
806 | mutex_lock(&ifibss->mtx); |
807 | ||
808 | /* | |
809 | * Work could be scheduled after scan or similar | |
810 | * when we aren't even joined (or trying) with a | |
811 | * network. | |
812 | */ | |
813 | if (!ifibss->ssid_len) | |
814 | goto out; | |
46900298 JB |
815 | |
816 | switch (ifibss->state) { | |
817 | case IEEE80211_IBSS_MLME_SEARCH: | |
818 | ieee80211_sta_find_ibss(sdata); | |
819 | break; | |
820 | case IEEE80211_IBSS_MLME_JOINED: | |
821 | ieee80211_sta_merge_ibss(sdata); | |
822 | break; | |
823 | default: | |
824 | WARN_ON(1); | |
825 | break; | |
826 | } | |
46900298 | 827 | |
7a17a33c JB |
828 | out: |
829 | mutex_unlock(&ifibss->mtx); | |
3a4d4aa2 JB |
830 | } |
831 | ||
46900298 JB |
832 | static void ieee80211_ibss_timer(unsigned long data) |
833 | { | |
834 | struct ieee80211_sub_if_data *sdata = | |
835 | (struct ieee80211_sub_if_data *) data; | |
836 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; | |
837 | struct ieee80211_local *local = sdata->local; | |
838 | ||
5bb644a0 JB |
839 | if (local->quiescing) { |
840 | ifibss->timer_running = true; | |
841 | return; | |
842 | } | |
843 | ||
7a17a33c | 844 | ieee80211_queue_work(&local->hw, &sdata->work); |
46900298 JB |
845 | } |
846 | ||
5bb644a0 JB |
847 | #ifdef CONFIG_PM |
848 | void ieee80211_ibss_quiesce(struct ieee80211_sub_if_data *sdata) | |
849 | { | |
850 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; | |
851 | ||
5bb644a0 JB |
852 | if (del_timer_sync(&ifibss->timer)) |
853 | ifibss->timer_running = true; | |
854 | } | |
855 | ||
856 | void ieee80211_ibss_restart(struct ieee80211_sub_if_data *sdata) | |
857 | { | |
858 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; | |
859 | ||
860 | if (ifibss->timer_running) { | |
861 | add_timer(&ifibss->timer); | |
862 | ifibss->timer_running = false; | |
863 | } | |
864 | } | |
865 | #endif | |
866 | ||
46900298 JB |
867 | void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata) |
868 | { | |
869 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; | |
870 | ||
46900298 JB |
871 | setup_timer(&ifibss->timer, ieee80211_ibss_timer, |
872 | (unsigned long) sdata); | |
7a17a33c | 873 | mutex_init(&ifibss->mtx); |
46900298 JB |
874 | } |
875 | ||
876 | /* scan finished notification */ | |
877 | void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local) | |
878 | { | |
af8cdcd8 | 879 | struct ieee80211_sub_if_data *sdata; |
46900298 | 880 | |
29b4a4f7 JB |
881 | mutex_lock(&local->iflist_mtx); |
882 | list_for_each_entry(sdata, &local->interfaces, list) { | |
9607e6b6 | 883 | if (!ieee80211_sdata_running(sdata)) |
0e41f715 | 884 | continue; |
af8cdcd8 JB |
885 | if (sdata->vif.type != NL80211_IFTYPE_ADHOC) |
886 | continue; | |
887 | sdata->u.ibss.last_scan_completed = jiffies; | |
7a17a33c | 888 | ieee80211_queue_work(&local->hw, &sdata->work); |
46900298 | 889 | } |
29b4a4f7 | 890 | mutex_unlock(&local->iflist_mtx); |
46900298 JB |
891 | } |
892 | ||
af8cdcd8 JB |
893 | int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata, |
894 | struct cfg80211_ibss_params *params) | |
895 | { | |
896 | struct sk_buff *skb; | |
897 | ||
7a17a33c JB |
898 | skb = dev_alloc_skb(sdata->local->hw.extra_tx_headroom + |
899 | 36 /* bitrates */ + | |
900 | 34 /* SSID */ + | |
901 | 3 /* DS params */ + | |
902 | 4 /* IBSS params */ + | |
903 | params->ie_len); | |
904 | if (!skb) | |
905 | return -ENOMEM; | |
906 | ||
907 | mutex_lock(&sdata->u.ibss.mtx); | |
908 | ||
af8cdcd8 JB |
909 | if (params->bssid) { |
910 | memcpy(sdata->u.ibss.bssid, params->bssid, ETH_ALEN); | |
911 | sdata->u.ibss.fixed_bssid = true; | |
912 | } else | |
913 | sdata->u.ibss.fixed_bssid = false; | |
914 | ||
fffd0934 | 915 | sdata->u.ibss.privacy = params->privacy; |
fbd2c8dc | 916 | sdata->u.ibss.basic_rates = params->basic_rates; |
fffd0934 | 917 | |
57c4d7b4 JB |
918 | sdata->vif.bss_conf.beacon_int = params->beacon_interval; |
919 | ||
af8cdcd8 JB |
920 | sdata->u.ibss.channel = params->channel; |
921 | sdata->u.ibss.fixed_channel = params->channel_fixed; | |
922 | ||
adfba3c7 JB |
923 | /* fix ourselves to that channel now already */ |
924 | if (params->channel_fixed) { | |
925 | sdata->local->oper_channel = params->channel; | |
0aaffa9b JB |
926 | WARN_ON(!ieee80211_set_channel_type(sdata->local, sdata, |
927 | NL80211_CHAN_NO_HT)); | |
adfba3c7 JB |
928 | } |
929 | ||
af8cdcd8 JB |
930 | if (params->ie) { |
931 | sdata->u.ibss.ie = kmemdup(params->ie, params->ie_len, | |
932 | GFP_KERNEL); | |
933 | if (sdata->u.ibss.ie) | |
934 | sdata->u.ibss.ie_len = params->ie_len; | |
935 | } | |
936 | ||
af8cdcd8 JB |
937 | sdata->u.ibss.skb = skb; |
938 | sdata->u.ibss.state = IEEE80211_IBSS_MLME_SEARCH; | |
939 | sdata->u.ibss.ibss_join_req = jiffies; | |
940 | ||
0e41f715 | 941 | memcpy(sdata->u.ibss.ssid, params->ssid, IEEE80211_MAX_SSID_LEN); |
0e41f715 JB |
942 | sdata->u.ibss.ssid_len = params->ssid_len; |
943 | ||
7da7cc1d JB |
944 | mutex_unlock(&sdata->u.ibss.mtx); |
945 | ||
946 | mutex_lock(&sdata->local->mtx); | |
5cff20e6 | 947 | ieee80211_recalc_idle(sdata->local); |
7da7cc1d | 948 | mutex_unlock(&sdata->local->mtx); |
5cff20e6 | 949 | |
64592c8f | 950 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); |
af8cdcd8 JB |
951 | |
952 | return 0; | |
953 | } | |
954 | ||
955 | int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata) | |
956 | { | |
957 | struct sk_buff *skb; | |
5ea096c0 TP |
958 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
959 | struct ieee80211_local *local = sdata->local; | |
960 | struct cfg80211_bss *cbss; | |
961 | u16 capability; | |
7a17a33c JB |
962 | int active_ibss; |
963 | ||
964 | mutex_lock(&sdata->u.ibss.mtx); | |
5ea096c0 TP |
965 | |
966 | active_ibss = ieee80211_sta_active_ibss(sdata); | |
967 | ||
968 | if (!active_ibss && !is_zero_ether_addr(ifibss->bssid)) { | |
969 | capability = WLAN_CAPABILITY_IBSS; | |
970 | ||
971 | if (ifibss->privacy) | |
972 | capability |= WLAN_CAPABILITY_PRIVACY; | |
973 | ||
974 | cbss = cfg80211_get_bss(local->hw.wiphy, ifibss->channel, | |
975 | ifibss->bssid, ifibss->ssid, | |
976 | ifibss->ssid_len, WLAN_CAPABILITY_IBSS | | |
977 | WLAN_CAPABILITY_PRIVACY, | |
978 | capability); | |
979 | ||
980 | if (cbss) { | |
981 | cfg80211_unlink_bss(local->hw.wiphy, cbss); | |
982 | cfg80211_put_bss(cbss); | |
983 | } | |
984 | } | |
af8cdcd8 | 985 | |
af8cdcd8 JB |
986 | sta_info_flush(sdata->local, sdata); |
987 | ||
988 | /* remove beacon */ | |
989 | kfree(sdata->u.ibss.ie); | |
990 | skb = sdata->u.ibss.presp; | |
991 | rcu_assign_pointer(sdata->u.ibss.presp, NULL); | |
8fc214ba JB |
992 | sdata->vif.bss_conf.ibss_joined = false; |
993 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED | | |
994 | BSS_CHANGED_IBSS); | |
af8cdcd8 JB |
995 | synchronize_rcu(); |
996 | kfree_skb(skb); | |
997 | ||
35f20c14 | 998 | skb_queue_purge(&sdata->skb_queue); |
af8cdcd8 | 999 | memset(sdata->u.ibss.bssid, 0, ETH_ALEN); |
5cff20e6 JB |
1000 | sdata->u.ibss.ssid_len = 0; |
1001 | ||
bc05d19f | 1002 | del_timer_sync(&sdata->u.ibss.timer); |
7a17a33c JB |
1003 | |
1004 | mutex_unlock(&sdata->u.ibss.mtx); | |
bc05d19f | 1005 | |
7da7cc1d | 1006 | mutex_lock(&local->mtx); |
5cff20e6 | 1007 | ieee80211_recalc_idle(sdata->local); |
7da7cc1d | 1008 | mutex_unlock(&local->mtx); |
af8cdcd8 JB |
1009 | |
1010 | return 0; | |
1011 | } |