Commit | Line | Data |
---|---|---|
04a773ad JB |
1 | /* |
2 | * Some IBSS support code for cfg80211. | |
3 | * | |
4 | * Copyright 2009 Johannes Berg <johannes@sipsolutions.net> | |
5 | */ | |
6 | ||
7 | #include <linux/etherdevice.h> | |
8 | #include <linux/if_arp.h> | |
5a0e3ad6 | 9 | #include <linux/slab.h> |
bc3b2d7f | 10 | #include <linux/export.h> |
04a773ad | 11 | #include <net/cfg80211.h> |
0e82ffe3 | 12 | #include "wext-compat.h" |
04a773ad | 13 | #include "nl80211.h" |
e35e4d28 | 14 | #include "rdev-ops.h" |
04a773ad JB |
15 | |
16 | ||
667503dd | 17 | void __cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid) |
04a773ad JB |
18 | { |
19 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
20 | struct cfg80211_bss *bss; | |
3d23e349 | 21 | #ifdef CONFIG_CFG80211_WEXT |
04a773ad JB |
22 | union iwreq_data wrqu; |
23 | #endif | |
24 | ||
25 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) | |
26 | return; | |
27 | ||
f7969969 | 28 | if (!wdev->ssid_len) |
04a773ad JB |
29 | return; |
30 | ||
04a773ad JB |
31 | bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid, |
32 | wdev->ssid, wdev->ssid_len, | |
33 | WLAN_CAPABILITY_IBSS, WLAN_CAPABILITY_IBSS); | |
34 | ||
35 | if (WARN_ON(!bss)) | |
36 | return; | |
37 | ||
38 | if (wdev->current_bss) { | |
39 | cfg80211_unhold_bss(wdev->current_bss); | |
5b112d3d | 40 | cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub); |
04a773ad JB |
41 | } |
42 | ||
19957bb3 JB |
43 | cfg80211_hold_bss(bss_from_pub(bss)); |
44 | wdev->current_bss = bss_from_pub(bss); | |
04a773ad | 45 | |
28f33366 | 46 | wdev->sme_state = CFG80211_SME_CONNECTED; |
fffd0934 JB |
47 | cfg80211_upload_connect_keys(wdev); |
48 | ||
667503dd JB |
49 | nl80211_send_ibss_bssid(wiphy_to_dev(wdev->wiphy), dev, bssid, |
50 | GFP_KERNEL); | |
3d23e349 | 51 | #ifdef CONFIG_CFG80211_WEXT |
04a773ad JB |
52 | memset(&wrqu, 0, sizeof(wrqu)); |
53 | memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN); | |
54 | wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); | |
55 | #endif | |
56 | } | |
667503dd JB |
57 | |
58 | void cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid, gfp_t gfp) | |
59 | { | |
60 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
61 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
62 | struct cfg80211_event *ev; | |
63 | unsigned long flags; | |
64 | ||
4ee3e063 BL |
65 | trace_cfg80211_ibss_joined(dev, bssid); |
66 | ||
28f33366 | 67 | CFG80211_DEV_WARN_ON(wdev->sme_state != CFG80211_SME_CONNECTING); |
f7969969 | 68 | |
667503dd JB |
69 | ev = kzalloc(sizeof(*ev), gfp); |
70 | if (!ev) | |
71 | return; | |
72 | ||
73 | ev->type = EVENT_IBSS_JOINED; | |
74 | memcpy(ev->cr.bssid, bssid, ETH_ALEN); | |
75 | ||
76 | spin_lock_irqsave(&wdev->event_lock, flags); | |
77 | list_add_tail(&ev->list, &wdev->event_list); | |
78 | spin_unlock_irqrestore(&wdev->event_lock, flags); | |
e60d7443 | 79 | queue_work(cfg80211_wq, &rdev->event_work); |
667503dd | 80 | } |
04a773ad JB |
81 | EXPORT_SYMBOL(cfg80211_ibss_joined); |
82 | ||
667503dd JB |
83 | int __cfg80211_join_ibss(struct cfg80211_registered_device *rdev, |
84 | struct net_device *dev, | |
fffd0934 JB |
85 | struct cfg80211_ibss_params *params, |
86 | struct cfg80211_cached_keys *connkeys) | |
04a773ad JB |
87 | { |
88 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
89 | int err; | |
90 | ||
667503dd JB |
91 | ASSERT_WDEV_LOCK(wdev); |
92 | ||
04a773ad JB |
93 | if (wdev->ssid_len) |
94 | return -EALREADY; | |
95 | ||
93b05238 JB |
96 | if (!params->basic_rates) { |
97 | /* | |
98 | * If no rates were explicitly configured, | |
99 | * use the mandatory rate set for 11b or | |
100 | * 11a for maximum compatibility. | |
101 | */ | |
102 | struct ieee80211_supported_band *sband = | |
683b6d3b | 103 | rdev->wiphy.bands[params->chandef.chan->band]; |
93b05238 | 104 | int j; |
683b6d3b | 105 | u32 flag = params->chandef.chan->band == IEEE80211_BAND_5GHZ ? |
93b05238 JB |
106 | IEEE80211_RATE_MANDATORY_A : |
107 | IEEE80211_RATE_MANDATORY_B; | |
108 | ||
109 | for (j = 0; j < sband->n_bitrates; j++) { | |
110 | if (sband->bitrates[j].flags & flag) | |
111 | params->basic_rates |= BIT(j); | |
112 | } | |
113 | } | |
114 | ||
fffd0934 JB |
115 | if (WARN_ON(wdev->connect_keys)) |
116 | kfree(wdev->connect_keys); | |
117 | wdev->connect_keys = connkeys; | |
118 | ||
c30a3d38 | 119 | wdev->ibss_fixed = params->channel_fixed; |
3d23e349 | 120 | #ifdef CONFIG_CFG80211_WEXT |
683b6d3b | 121 | wdev->wext.ibss.chandef = params->chandef; |
04a773ad | 122 | #endif |
28f33366 | 123 | wdev->sme_state = CFG80211_SME_CONNECTING; |
e4e32459 | 124 | |
683b6d3b | 125 | err = cfg80211_can_use_chan(rdev, wdev, params->chandef.chan, |
e4e32459 MK |
126 | params->channel_fixed |
127 | ? CHAN_MODE_SHARED | |
128 | : CHAN_MODE_EXCLUSIVE); | |
129 | if (err) { | |
130 | wdev->connect_keys = NULL; | |
131 | return err; | |
132 | } | |
133 | ||
e35e4d28 | 134 | err = rdev_join_ibss(rdev, dev, params); |
fffd0934 JB |
135 | if (err) { |
136 | wdev->connect_keys = NULL; | |
28f33366 | 137 | wdev->sme_state = CFG80211_SME_IDLE; |
04a773ad | 138 | return err; |
fffd0934 | 139 | } |
04a773ad JB |
140 | |
141 | memcpy(wdev->ssid, params->ssid, params->ssid_len); | |
142 | wdev->ssid_len = params->ssid_len; | |
143 | ||
144 | return 0; | |
145 | } | |
146 | ||
667503dd JB |
147 | int cfg80211_join_ibss(struct cfg80211_registered_device *rdev, |
148 | struct net_device *dev, | |
fffd0934 JB |
149 | struct cfg80211_ibss_params *params, |
150 | struct cfg80211_cached_keys *connkeys) | |
667503dd JB |
151 | { |
152 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
153 | int err; | |
154 | ||
59bbb6f7 | 155 | mutex_lock(&rdev->devlist_mtx); |
667503dd | 156 | wdev_lock(wdev); |
fffd0934 | 157 | err = __cfg80211_join_ibss(rdev, dev, params, connkeys); |
667503dd | 158 | wdev_unlock(wdev); |
59bbb6f7 | 159 | mutex_unlock(&rdev->devlist_mtx); |
667503dd JB |
160 | |
161 | return err; | |
162 | } | |
163 | ||
164 | static void __cfg80211_clear_ibss(struct net_device *dev, bool nowext) | |
04a773ad JB |
165 | { |
166 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
fffd0934 JB |
167 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
168 | int i; | |
04a773ad | 169 | |
667503dd JB |
170 | ASSERT_WDEV_LOCK(wdev); |
171 | ||
fffd0934 JB |
172 | kfree(wdev->connect_keys); |
173 | wdev->connect_keys = NULL; | |
174 | ||
175 | /* | |
176 | * Delete all the keys ... pairwise keys can't really | |
177 | * exist any more anyway, but default keys might. | |
178 | */ | |
179 | if (rdev->ops->del_key) | |
180 | for (i = 0; i < 6; i++) | |
e35e4d28 | 181 | rdev_del_key(rdev, dev, i, false, NULL); |
fffd0934 | 182 | |
04a773ad JB |
183 | if (wdev->current_bss) { |
184 | cfg80211_unhold_bss(wdev->current_bss); | |
5b112d3d | 185 | cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub); |
04a773ad JB |
186 | } |
187 | ||
188 | wdev->current_bss = NULL; | |
28f33366 | 189 | wdev->sme_state = CFG80211_SME_IDLE; |
04a773ad | 190 | wdev->ssid_len = 0; |
3d23e349 | 191 | #ifdef CONFIG_CFG80211_WEXT |
9d308429 | 192 | if (!nowext) |
cbe8fa9c | 193 | wdev->wext.ibss.ssid_len = 0; |
9d308429 | 194 | #endif |
04a773ad JB |
195 | } |
196 | ||
667503dd JB |
197 | void cfg80211_clear_ibss(struct net_device *dev, bool nowext) |
198 | { | |
199 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
200 | ||
201 | wdev_lock(wdev); | |
202 | __cfg80211_clear_ibss(dev, nowext); | |
203 | wdev_unlock(wdev); | |
204 | } | |
205 | ||
98d3a7ca JB |
206 | int __cfg80211_leave_ibss(struct cfg80211_registered_device *rdev, |
207 | struct net_device *dev, bool nowext) | |
04a773ad | 208 | { |
78485475 | 209 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
04a773ad JB |
210 | int err; |
211 | ||
667503dd JB |
212 | ASSERT_WDEV_LOCK(wdev); |
213 | ||
78485475 JB |
214 | if (!wdev->ssid_len) |
215 | return -ENOLINK; | |
216 | ||
e35e4d28 | 217 | err = rdev_leave_ibss(rdev, dev); |
04a773ad JB |
218 | |
219 | if (err) | |
220 | return err; | |
221 | ||
667503dd | 222 | __cfg80211_clear_ibss(dev, nowext); |
04a773ad JB |
223 | |
224 | return 0; | |
225 | } | |
226 | ||
667503dd JB |
227 | int cfg80211_leave_ibss(struct cfg80211_registered_device *rdev, |
228 | struct net_device *dev, bool nowext) | |
229 | { | |
230 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
231 | int err; | |
232 | ||
233 | wdev_lock(wdev); | |
234 | err = __cfg80211_leave_ibss(rdev, dev, nowext); | |
235 | wdev_unlock(wdev); | |
236 | ||
237 | return err; | |
238 | } | |
239 | ||
3d23e349 | 240 | #ifdef CONFIG_CFG80211_WEXT |
fffd0934 JB |
241 | int cfg80211_ibss_wext_join(struct cfg80211_registered_device *rdev, |
242 | struct wireless_dev *wdev) | |
04a773ad | 243 | { |
fffd0934 | 244 | struct cfg80211_cached_keys *ck = NULL; |
04a773ad | 245 | enum ieee80211_band band; |
fffd0934 JB |
246 | int i, err; |
247 | ||
248 | ASSERT_WDEV_LOCK(wdev); | |
04a773ad | 249 | |
cbe8fa9c JB |
250 | if (!wdev->wext.ibss.beacon_interval) |
251 | wdev->wext.ibss.beacon_interval = 100; | |
8e30bc55 | 252 | |
04a773ad | 253 | /* try to find an IBSS channel if none requested ... */ |
683b6d3b | 254 | if (!wdev->wext.ibss.chandef.chan) { |
3d9d1d66 | 255 | wdev->wext.ibss.chandef.width = NL80211_CHAN_WIDTH_20_NOHT; |
683b6d3b | 256 | |
04a773ad JB |
257 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
258 | struct ieee80211_supported_band *sband; | |
259 | struct ieee80211_channel *chan; | |
260 | ||
261 | sband = rdev->wiphy.bands[band]; | |
262 | if (!sband) | |
263 | continue; | |
264 | ||
265 | for (i = 0; i < sband->n_channels; i++) { | |
266 | chan = &sband->channels[i]; | |
267 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) | |
268 | continue; | |
269 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
270 | continue; | |
683b6d3b | 271 | wdev->wext.ibss.chandef.chan = chan; |
e83301f8 BR |
272 | wdev->wext.ibss.chandef.center_freq1 = |
273 | chan->center_freq; | |
04a773ad JB |
274 | break; |
275 | } | |
276 | ||
683b6d3b | 277 | if (wdev->wext.ibss.chandef.chan) |
04a773ad JB |
278 | break; |
279 | } | |
280 | ||
683b6d3b | 281 | if (!wdev->wext.ibss.chandef.chan) |
04a773ad JB |
282 | return -EINVAL; |
283 | } | |
284 | ||
285 | /* don't join -- SSID is not there */ | |
cbe8fa9c | 286 | if (!wdev->wext.ibss.ssid_len) |
04a773ad JB |
287 | return 0; |
288 | ||
289 | if (!netif_running(wdev->netdev)) | |
290 | return 0; | |
291 | ||
3be61a38 | 292 | if (wdev->wext.keys) { |
fffd0934 | 293 | wdev->wext.keys->def = wdev->wext.default_key; |
3be61a38 JB |
294 | wdev->wext.keys->defmgmt = wdev->wext.default_mgmt_key; |
295 | } | |
fffd0934 JB |
296 | |
297 | wdev->wext.ibss.privacy = wdev->wext.default_key != -1; | |
298 | ||
299 | if (wdev->wext.keys) { | |
300 | ck = kmemdup(wdev->wext.keys, sizeof(*ck), GFP_KERNEL); | |
301 | if (!ck) | |
302 | return -ENOMEM; | |
303 | for (i = 0; i < 6; i++) | |
304 | ck->params[i].key = ck->data[i]; | |
305 | } | |
306 | err = __cfg80211_join_ibss(rdev, wdev->netdev, | |
307 | &wdev->wext.ibss, ck); | |
308 | if (err) | |
309 | kfree(ck); | |
310 | ||
311 | return err; | |
04a773ad JB |
312 | } |
313 | ||
314 | int cfg80211_ibss_wext_siwfreq(struct net_device *dev, | |
315 | struct iw_request_info *info, | |
59bbb6f7 | 316 | struct iw_freq *wextfreq, char *extra) |
04a773ad JB |
317 | { |
318 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
59bbb6f7 JB |
319 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
320 | struct ieee80211_channel *chan = NULL; | |
321 | int err, freq; | |
04a773ad JB |
322 | |
323 | /* call only for ibss! */ | |
324 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) | |
325 | return -EINVAL; | |
326 | ||
59bbb6f7 | 327 | if (!rdev->ops->join_ibss) |
04a773ad JB |
328 | return -EOPNOTSUPP; |
329 | ||
59bbb6f7 JB |
330 | freq = cfg80211_wext_freq(wdev->wiphy, wextfreq); |
331 | if (freq < 0) | |
332 | return freq; | |
04a773ad | 333 | |
59bbb6f7 JB |
334 | if (freq) { |
335 | chan = ieee80211_get_channel(wdev->wiphy, freq); | |
336 | if (!chan) | |
337 | return -EINVAL; | |
338 | if (chan->flags & IEEE80211_CHAN_NO_IBSS || | |
339 | chan->flags & IEEE80211_CHAN_DISABLED) | |
340 | return -EINVAL; | |
341 | } | |
04a773ad | 342 | |
683b6d3b | 343 | if (wdev->wext.ibss.chandef.chan == chan) |
04a773ad JB |
344 | return 0; |
345 | ||
667503dd JB |
346 | wdev_lock(wdev); |
347 | err = 0; | |
348 | if (wdev->ssid_len) | |
59bbb6f7 | 349 | err = __cfg80211_leave_ibss(rdev, dev, true); |
667503dd JB |
350 | wdev_unlock(wdev); |
351 | ||
352 | if (err) | |
353 | return err; | |
04a773ad JB |
354 | |
355 | if (chan) { | |
683b6d3b | 356 | wdev->wext.ibss.chandef.chan = chan; |
3d9d1d66 | 357 | wdev->wext.ibss.chandef.width = NL80211_CHAN_WIDTH_20_NOHT; |
e83301f8 | 358 | wdev->wext.ibss.chandef.center_freq1 = freq; |
cbe8fa9c | 359 | wdev->wext.ibss.channel_fixed = true; |
04a773ad JB |
360 | } else { |
361 | /* cfg80211_ibss_wext_join will pick one if needed */ | |
cbe8fa9c | 362 | wdev->wext.ibss.channel_fixed = false; |
04a773ad JB |
363 | } |
364 | ||
59bbb6f7 | 365 | mutex_lock(&rdev->devlist_mtx); |
fffd0934 | 366 | wdev_lock(wdev); |
59bbb6f7 | 367 | err = cfg80211_ibss_wext_join(rdev, wdev); |
fffd0934 | 368 | wdev_unlock(wdev); |
59bbb6f7 | 369 | mutex_unlock(&rdev->devlist_mtx); |
fffd0934 JB |
370 | |
371 | return err; | |
04a773ad | 372 | } |
04a773ad JB |
373 | |
374 | int cfg80211_ibss_wext_giwfreq(struct net_device *dev, | |
375 | struct iw_request_info *info, | |
376 | struct iw_freq *freq, char *extra) | |
377 | { | |
378 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
379 | struct ieee80211_channel *chan = NULL; | |
380 | ||
381 | /* call only for ibss! */ | |
382 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) | |
383 | return -EINVAL; | |
384 | ||
667503dd | 385 | wdev_lock(wdev); |
04a773ad | 386 | if (wdev->current_bss) |
19957bb3 | 387 | chan = wdev->current_bss->pub.channel; |
683b6d3b JB |
388 | else if (wdev->wext.ibss.chandef.chan) |
389 | chan = wdev->wext.ibss.chandef.chan; | |
667503dd | 390 | wdev_unlock(wdev); |
04a773ad JB |
391 | |
392 | if (chan) { | |
393 | freq->m = chan->center_freq; | |
394 | freq->e = 6; | |
395 | return 0; | |
396 | } | |
397 | ||
398 | /* no channel if not joining */ | |
399 | return -EINVAL; | |
400 | } | |
04a773ad JB |
401 | |
402 | int cfg80211_ibss_wext_siwessid(struct net_device *dev, | |
403 | struct iw_request_info *info, | |
404 | struct iw_point *data, char *ssid) | |
405 | { | |
406 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
59bbb6f7 | 407 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
04a773ad JB |
408 | size_t len = data->length; |
409 | int err; | |
410 | ||
411 | /* call only for ibss! */ | |
412 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) | |
413 | return -EINVAL; | |
414 | ||
59bbb6f7 | 415 | if (!rdev->ops->join_ibss) |
04a773ad JB |
416 | return -EOPNOTSUPP; |
417 | ||
667503dd JB |
418 | wdev_lock(wdev); |
419 | err = 0; | |
420 | if (wdev->ssid_len) | |
59bbb6f7 | 421 | err = __cfg80211_leave_ibss(rdev, dev, true); |
667503dd JB |
422 | wdev_unlock(wdev); |
423 | ||
424 | if (err) | |
425 | return err; | |
04a773ad JB |
426 | |
427 | /* iwconfig uses nul termination in SSID.. */ | |
428 | if (len > 0 && ssid[len - 1] == '\0') | |
429 | len--; | |
430 | ||
cbe8fa9c JB |
431 | wdev->wext.ibss.ssid = wdev->ssid; |
432 | memcpy(wdev->wext.ibss.ssid, ssid, len); | |
433 | wdev->wext.ibss.ssid_len = len; | |
04a773ad | 434 | |
59bbb6f7 | 435 | mutex_lock(&rdev->devlist_mtx); |
fffd0934 | 436 | wdev_lock(wdev); |
59bbb6f7 | 437 | err = cfg80211_ibss_wext_join(rdev, wdev); |
fffd0934 | 438 | wdev_unlock(wdev); |
59bbb6f7 | 439 | mutex_unlock(&rdev->devlist_mtx); |
fffd0934 JB |
440 | |
441 | return err; | |
04a773ad | 442 | } |
04a773ad JB |
443 | |
444 | int cfg80211_ibss_wext_giwessid(struct net_device *dev, | |
445 | struct iw_request_info *info, | |
446 | struct iw_point *data, char *ssid) | |
447 | { | |
448 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
449 | ||
450 | /* call only for ibss! */ | |
451 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) | |
452 | return -EINVAL; | |
453 | ||
454 | data->flags = 0; | |
455 | ||
667503dd | 456 | wdev_lock(wdev); |
04a773ad JB |
457 | if (wdev->ssid_len) { |
458 | data->flags = 1; | |
459 | data->length = wdev->ssid_len; | |
460 | memcpy(ssid, wdev->ssid, data->length); | |
cbe8fa9c | 461 | } else if (wdev->wext.ibss.ssid && wdev->wext.ibss.ssid_len) { |
04a773ad | 462 | data->flags = 1; |
cbe8fa9c JB |
463 | data->length = wdev->wext.ibss.ssid_len; |
464 | memcpy(ssid, wdev->wext.ibss.ssid, data->length); | |
04a773ad | 465 | } |
667503dd | 466 | wdev_unlock(wdev); |
04a773ad JB |
467 | |
468 | return 0; | |
469 | } | |
04a773ad JB |
470 | |
471 | int cfg80211_ibss_wext_siwap(struct net_device *dev, | |
472 | struct iw_request_info *info, | |
473 | struct sockaddr *ap_addr, char *extra) | |
474 | { | |
475 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
59bbb6f7 | 476 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
04a773ad JB |
477 | u8 *bssid = ap_addr->sa_data; |
478 | int err; | |
479 | ||
480 | /* call only for ibss! */ | |
481 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) | |
482 | return -EINVAL; | |
483 | ||
59bbb6f7 | 484 | if (!rdev->ops->join_ibss) |
04a773ad JB |
485 | return -EOPNOTSUPP; |
486 | ||
487 | if (ap_addr->sa_family != ARPHRD_ETHER) | |
488 | return -EINVAL; | |
489 | ||
490 | /* automatic mode */ | |
491 | if (is_zero_ether_addr(bssid) || is_broadcast_ether_addr(bssid)) | |
492 | bssid = NULL; | |
493 | ||
494 | /* both automatic */ | |
cbe8fa9c | 495 | if (!bssid && !wdev->wext.ibss.bssid) |
04a773ad JB |
496 | return 0; |
497 | ||
498 | /* fixed already - and no change */ | |
cbe8fa9c | 499 | if (wdev->wext.ibss.bssid && bssid && |
ac422d3c | 500 | ether_addr_equal(bssid, wdev->wext.ibss.bssid)) |
04a773ad JB |
501 | return 0; |
502 | ||
667503dd JB |
503 | wdev_lock(wdev); |
504 | err = 0; | |
505 | if (wdev->ssid_len) | |
59bbb6f7 | 506 | err = __cfg80211_leave_ibss(rdev, dev, true); |
667503dd JB |
507 | wdev_unlock(wdev); |
508 | ||
509 | if (err) | |
510 | return err; | |
04a773ad JB |
511 | |
512 | if (bssid) { | |
cbe8fa9c JB |
513 | memcpy(wdev->wext.bssid, bssid, ETH_ALEN); |
514 | wdev->wext.ibss.bssid = wdev->wext.bssid; | |
04a773ad | 515 | } else |
cbe8fa9c | 516 | wdev->wext.ibss.bssid = NULL; |
04a773ad | 517 | |
59bbb6f7 | 518 | mutex_lock(&rdev->devlist_mtx); |
fffd0934 | 519 | wdev_lock(wdev); |
59bbb6f7 | 520 | err = cfg80211_ibss_wext_join(rdev, wdev); |
fffd0934 | 521 | wdev_unlock(wdev); |
59bbb6f7 | 522 | mutex_unlock(&rdev->devlist_mtx); |
fffd0934 JB |
523 | |
524 | return err; | |
04a773ad | 525 | } |
04a773ad JB |
526 | |
527 | int cfg80211_ibss_wext_giwap(struct net_device *dev, | |
528 | struct iw_request_info *info, | |
529 | struct sockaddr *ap_addr, char *extra) | |
530 | { | |
531 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
532 | ||
533 | /* call only for ibss! */ | |
534 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC)) | |
535 | return -EINVAL; | |
536 | ||
537 | ap_addr->sa_family = ARPHRD_ETHER; | |
538 | ||
667503dd | 539 | wdev_lock(wdev); |
7ebbe6bd | 540 | if (wdev->current_bss) |
19957bb3 | 541 | memcpy(ap_addr->sa_data, wdev->current_bss->pub.bssid, ETH_ALEN); |
80e5b06a | 542 | else if (wdev->wext.ibss.bssid) |
cbe8fa9c | 543 | memcpy(ap_addr->sa_data, wdev->wext.ibss.bssid, ETH_ALEN); |
80e5b06a ZY |
544 | else |
545 | memset(ap_addr->sa_data, 0, ETH_ALEN); | |
546 | ||
667503dd JB |
547 | wdev_unlock(wdev); |
548 | ||
04a773ad JB |
549 | return 0; |
550 | } | |
04a773ad | 551 | #endif |