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