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