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