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