blob: 10bf040a0982d2f7859f98399c24de26a7fd5383 [file] [log] [blame]
Johannes Berg04a773a2009-04-19 21:24:32 +02001/*
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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09009#include <linux/slab.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040010#include <linux/export.h>
Johannes Berg04a773a2009-04-19 21:24:32 +020011#include <net/cfg80211.h>
Johannes Berg0e82ffe2009-07-27 12:01:50 +020012#include "wext-compat.h"
Johannes Berg04a773a2009-04-19 21:24:32 +020013#include "nl80211.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030014#include "rdev-ops.h"
Johannes Berg04a773a2009-04-19 21:24:32 +020015
16
Antonio Quartullife94f3a2014-01-29 17:53:43 +010017void __cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid,
18 struct ieee80211_channel *channel)
Johannes Berg04a773a2009-04-19 21:24:32 +020019{
20 struct wireless_dev *wdev = dev->ieee80211_ptr;
21 struct cfg80211_bss *bss;
Johannes Berg3d23e342009-09-29 23:27:28 +020022#ifdef CONFIG_CFG80211_WEXT
Johannes Berg04a773a2009-04-19 21:24:32 +020023 union iwreq_data wrqu;
24#endif
25
26 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
27 return;
28
Johannes Bergf7969962009-08-21 12:23:49 +020029 if (!wdev->ssid_len)
Johannes Berg04a773a2009-04-19 21:24:32 +020030 return;
31
Antonio Quartullife94f3a2014-01-29 17:53:43 +010032 bss = cfg80211_get_bss(wdev->wiphy, channel, bssid, NULL, 0,
Dedy Lansky6eb18132015-02-08 15:52:03 +020033 IEEE80211_BSS_TYPE_IBSS, IEEE80211_PRIVACY_ANY);
Johannes Berg04a773a2009-04-19 21:24:32 +020034
35 if (WARN_ON(!bss))
36 return;
37
38 if (wdev->current_bss) {
39 cfg80211_unhold_bss(wdev->current_bss);
Johannes Berg5b112d32013-02-01 01:49:58 +010040 cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub);
Johannes Berg04a773a2009-04-19 21:24:32 +020041 }
42
Johannes Berg19957bb2009-07-02 17:20:43 +020043 cfg80211_hold_bss(bss_from_pub(bss));
44 wdev->current_bss = bss_from_pub(bss);
Johannes Berg04a773a2009-04-19 21:24:32 +020045
David Spinadelb8676222016-09-22 23:16:50 +030046 if (!(wdev->wiphy->flags & WIPHY_FLAG_HAS_STATIC_WEP))
47 cfg80211_upload_connect_keys(wdev);
Johannes Bergfffd0932009-07-08 14:22:54 +020048
Zhao, Gangf26cbf42014-04-21 12:53:03 +080049 nl80211_send_ibss_bssid(wiphy_to_rdev(wdev->wiphy), dev, bssid,
Johannes Berg667503d2009-07-07 03:56:11 +020050 GFP_KERNEL);
Johannes Berg3d23e342009-09-29 23:27:28 +020051#ifdef CONFIG_CFG80211_WEXT
Johannes Berg04a773a2009-04-19 21:24:32 +020052 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}
Johannes Berg667503d2009-07-07 03:56:11 +020057
Antonio Quartullife94f3a2014-01-29 17:53:43 +010058void cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid,
59 struct ieee80211_channel *channel, gfp_t gfp)
Johannes Berg667503d2009-07-07 03:56:11 +020060{
61 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080062 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg667503d2009-07-07 03:56:11 +020063 struct cfg80211_event *ev;
64 unsigned long flags;
65
Antonio Quartullife94f3a2014-01-29 17:53:43 +010066 trace_cfg80211_ibss_joined(dev, bssid, channel);
67
68 if (WARN_ON(!channel))
69 return;
Beni Lev4ee3e062012-08-27 12:49:39 +030070
Johannes Berg667503d2009-07-07 03:56:11 +020071 ev = kzalloc(sizeof(*ev), gfp);
72 if (!ev)
73 return;
74
75 ev->type = EVENT_IBSS_JOINED;
Antonio Quartullife94f3a2014-01-29 17:53:43 +010076 memcpy(ev->ij.bssid, bssid, ETH_ALEN);
77 ev->ij.channel = channel;
Johannes Berg667503d2009-07-07 03:56:11 +020078
79 spin_lock_irqsave(&wdev->event_lock, flags);
80 list_add_tail(&ev->list, &wdev->event_list);
81 spin_unlock_irqrestore(&wdev->event_lock, flags);
Alban Browaeyse60d7442009-11-25 15:13:00 +010082 queue_work(cfg80211_wq, &rdev->event_work);
Johannes Berg667503d2009-07-07 03:56:11 +020083}
Johannes Berg04a773a2009-04-19 21:24:32 +020084EXPORT_SYMBOL(cfg80211_ibss_joined);
85
Zhao, Gang2316d7b2014-03-08 11:01:24 +080086static int __cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
87 struct net_device *dev,
88 struct cfg80211_ibss_params *params,
89 struct cfg80211_cached_keys *connkeys)
Johannes Berg04a773a2009-04-19 21:24:32 +020090{
91 struct wireless_dev *wdev = dev->ieee80211_ptr;
92 int err;
93
Johannes Berg667503d2009-07-07 03:56:11 +020094 ASSERT_WDEV_LOCK(wdev);
95
Johannes Berg04a773a2009-04-19 21:24:32 +020096 if (wdev->ssid_len)
97 return -EALREADY;
98
Johannes Berg93b05232010-09-28 12:53:14 +020099 if (!params->basic_rates) {
100 /*
101 * If no rates were explicitly configured,
102 * use the mandatory rate set for 11b or
103 * 11a for maximum compatibility.
104 */
105 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +0100106 rdev->wiphy.bands[params->chandef.chan->band];
Johannes Berg93b05232010-09-28 12:53:14 +0200107 int j;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200108 u32 flag = params->chandef.chan->band == NL80211_BAND_5GHZ ?
Johannes Berg93b05232010-09-28 12:53:14 +0200109 IEEE80211_RATE_MANDATORY_A :
110 IEEE80211_RATE_MANDATORY_B;
111
112 for (j = 0; j < sband->n_bitrates; j++) {
113 if (sband->bitrates[j].flags & flag)
114 params->basic_rates |= BIT(j);
115 }
116 }
117
Johannes Bergf1c1f172016-09-13 17:08:23 +0200118 if (WARN_ON(connkeys && connkeys->def < 0))
119 return -EINVAL;
120
Johannes Bergfffd0932009-07-08 14:22:54 +0200121 if (WARN_ON(wdev->connect_keys))
Johannes Bergb47f6102014-09-10 13:39:54 +0300122 kzfree(wdev->connect_keys);
Johannes Bergfffd0932009-07-08 14:22:54 +0200123 wdev->connect_keys = connkeys;
124
Michal Kaziorc30a3d32012-06-29 12:46:59 +0200125 wdev->ibss_fixed = params->channel_fixed;
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200126 wdev->ibss_dfs_possible = params->userspace_handles_dfs;
Michal Kazior9e0e2962014-01-29 14:22:27 +0100127 wdev->chandef = params->chandef;
Johannes Berg3d23e342009-09-29 23:27:28 +0200128#ifdef CONFIG_CFG80211_WEXT
Johannes Berg683b6d32012-11-08 21:25:48 +0100129 wdev->wext.ibss.chandef = params->chandef;
Johannes Berg04a773a2009-04-19 21:24:32 +0200130#endif
Hila Gonene35e4d22012-06-27 17:19:42 +0300131 err = rdev_join_ibss(rdev, dev, params);
Johannes Bergfffd0932009-07-08 14:22:54 +0200132 if (err) {
133 wdev->connect_keys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +0200134 return err;
Johannes Bergfffd0932009-07-08 14:22:54 +0200135 }
Johannes Berg04a773a2009-04-19 21:24:32 +0200136
137 memcpy(wdev->ssid, params->ssid, params->ssid_len);
138 wdev->ssid_len = params->ssid_len;
139
140 return 0;
141}
142
Johannes Berg667503d2009-07-07 03:56:11 +0200143int cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
144 struct net_device *dev,
Johannes Bergfffd0932009-07-08 14:22:54 +0200145 struct cfg80211_ibss_params *params,
146 struct cfg80211_cached_keys *connkeys)
Johannes Berg04a773a2009-04-19 21:24:32 +0200147{
148 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg667503d2009-07-07 03:56:11 +0200149 int err;
150
Johannes Berg5fe231e2013-05-08 21:45:15 +0200151 ASSERT_RTNL();
152
Johannes Berg667503d2009-07-07 03:56:11 +0200153 wdev_lock(wdev);
Johannes Bergfffd0932009-07-08 14:22:54 +0200154 err = __cfg80211_join_ibss(rdev, dev, params, connkeys);
Johannes Berg667503d2009-07-07 03:56:11 +0200155 wdev_unlock(wdev);
156
157 return err;
158}
159
160static void __cfg80211_clear_ibss(struct net_device *dev, bool nowext)
161{
162 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800163 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergfffd0932009-07-08 14:22:54 +0200164 int i;
Johannes Berg667503d2009-07-07 03:56:11 +0200165
166 ASSERT_WDEV_LOCK(wdev);
Johannes Berg04a773a2009-04-19 21:24:32 +0200167
Johannes Bergb47f6102014-09-10 13:39:54 +0300168 kzfree(wdev->connect_keys);
Johannes Bergfffd0932009-07-08 14:22:54 +0200169 wdev->connect_keys = NULL;
170
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800171 rdev_set_qos_map(rdev, dev, NULL);
172
Johannes Bergfffd0932009-07-08 14:22:54 +0200173 /*
174 * Delete all the keys ... pairwise keys can't really
175 * exist any more anyway, but default keys might.
176 */
177 if (rdev->ops->del_key)
178 for (i = 0; i < 6; i++)
Hila Gonene35e4d22012-06-27 17:19:42 +0300179 rdev_del_key(rdev, dev, i, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200180
Johannes Berg04a773a2009-04-19 21:24:32 +0200181 if (wdev->current_bss) {
182 cfg80211_unhold_bss(wdev->current_bss);
Johannes Berg5b112d32013-02-01 01:49:58 +0100183 cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub);
Johannes Berg04a773a2009-04-19 21:24:32 +0200184 }
185
186 wdev->current_bss = NULL;
187 wdev->ssid_len = 0;
Michal Kazior9e0e2962014-01-29 14:22:27 +0100188 memset(&wdev->chandef, 0, sizeof(wdev->chandef));
Johannes Berg3d23e342009-09-29 23:27:28 +0200189#ifdef CONFIG_CFG80211_WEXT
Johannes Berg9d308422009-04-20 18:43:46 +0200190 if (!nowext)
Johannes Bergcbe8fa92009-05-09 20:09:03 +0200191 wdev->wext.ibss.ssid_len = 0;
Johannes Berg9d308422009-04-20 18:43:46 +0200192#endif
Vasanthakumar Thiagarajanb35a51c2017-02-27 17:04:33 +0530193 cfg80211_sched_dfs_chan_update(rdev);
Johannes Berg04a773a2009-04-19 21:24:32 +0200194}
195
Johannes Berg667503d2009-07-07 03:56:11 +0200196void cfg80211_clear_ibss(struct net_device *dev, bool nowext)
197{
198 struct wireless_dev *wdev = dev->ieee80211_ptr;
199
200 wdev_lock(wdev);
201 __cfg80211_clear_ibss(dev, nowext);
202 wdev_unlock(wdev);
203}
204
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100205int __cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
206 struct net_device *dev, bool nowext)
Johannes Berg04a773a2009-04-19 21:24:32 +0200207{
Johannes Berg78485472009-07-07 03:56:05 +0200208 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg04a773a2009-04-19 21:24:32 +0200209 int err;
210
Johannes Berg667503d2009-07-07 03:56:11 +0200211 ASSERT_WDEV_LOCK(wdev);
212
Johannes Berg78485472009-07-07 03:56:05 +0200213 if (!wdev->ssid_len)
214 return -ENOLINK;
215
Hila Gonene35e4d22012-06-27 17:19:42 +0300216 err = rdev_leave_ibss(rdev, dev);
Johannes Berg04a773a2009-04-19 21:24:32 +0200217
218 if (err)
219 return err;
220
Johannes Berg667503d2009-07-07 03:56:11 +0200221 __cfg80211_clear_ibss(dev, nowext);
Johannes Berg04a773a2009-04-19 21:24:32 +0200222
223 return 0;
224}
225
Johannes Berg667503d2009-07-07 03:56:11 +0200226int cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
227 struct net_device *dev, bool nowext)
228{
229 struct wireless_dev *wdev = dev->ieee80211_ptr;
230 int err;
231
232 wdev_lock(wdev);
233 err = __cfg80211_leave_ibss(rdev, dev, nowext);
234 wdev_unlock(wdev);
235
236 return err;
237}
238
Johannes Berg3d23e342009-09-29 23:27:28 +0200239#ifdef CONFIG_CFG80211_WEXT
Johannes Bergfffd0932009-07-08 14:22:54 +0200240int cfg80211_ibss_wext_join(struct cfg80211_registered_device *rdev,
241 struct wireless_dev *wdev)
Johannes Berg04a773a2009-04-19 21:24:32 +0200242{
Johannes Bergfffd0932009-07-08 14:22:54 +0200243 struct cfg80211_cached_keys *ck = NULL;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200244 enum nl80211_band band;
Johannes Bergfffd0932009-07-08 14:22:54 +0200245 int i, err;
246
247 ASSERT_WDEV_LOCK(wdev);
Johannes Berg04a773a2009-04-19 21:24:32 +0200248
Johannes Bergcbe8fa92009-05-09 20:09:03 +0200249 if (!wdev->wext.ibss.beacon_interval)
250 wdev->wext.ibss.beacon_interval = 100;
Johannes Berg8e30bc52009-04-22 17:45:38 +0200251
Johannes Berg04a773a2009-04-19 21:24:32 +0200252 /* try to find an IBSS channel if none requested ... */
Johannes Berg683b6d32012-11-08 21:25:48 +0100253 if (!wdev->wext.ibss.chandef.chan) {
Simon Wunderlich1fe45172013-10-30 16:09:33 +0100254 struct ieee80211_channel *new_chan = NULL;
Johannes Berg683b6d32012-11-08 21:25:48 +0100255
Johannes Berg57fbcce2016-04-12 15:56:15 +0200256 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg04a773a2009-04-19 21:24:32 +0200257 struct ieee80211_supported_band *sband;
258 struct ieee80211_channel *chan;
259
260 sband = rdev->wiphy.bands[band];
261 if (!sband)
262 continue;
263
264 for (i = 0; i < sband->n_channels; i++) {
265 chan = &sband->channels[i];
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200266 if (chan->flags & IEEE80211_CHAN_NO_IR)
Johannes Berg04a773a2009-04-19 21:24:32 +0200267 continue;
268 if (chan->flags & IEEE80211_CHAN_DISABLED)
269 continue;
Simon Wunderlich1fe45172013-10-30 16:09:33 +0100270 new_chan = chan;
Johannes Berg04a773a2009-04-19 21:24:32 +0200271 break;
272 }
273
Simon Wunderlich1fe45172013-10-30 16:09:33 +0100274 if (new_chan)
Johannes Berg04a773a2009-04-19 21:24:32 +0200275 break;
276 }
277
Simon Wunderlich1fe45172013-10-30 16:09:33 +0100278 if (!new_chan)
Johannes Berg04a773a2009-04-19 21:24:32 +0200279 return -EINVAL;
Simon Wunderlich1fe45172013-10-30 16:09:33 +0100280
281 cfg80211_chandef_create(&wdev->wext.ibss.chandef, new_chan,
282 NL80211_CHAN_NO_HT);
Johannes Berg04a773a2009-04-19 21:24:32 +0200283 }
284
285 /* don't join -- SSID is not there */
Johannes Bergcbe8fa92009-05-09 20:09:03 +0200286 if (!wdev->wext.ibss.ssid_len)
Johannes Berg04a773a2009-04-19 21:24:32 +0200287 return 0;
288
289 if (!netif_running(wdev->netdev))
290 return 0;
291
Johannes Berg89b706f2016-09-13 16:39:38 +0200292 if (wdev->wext.keys)
Johannes Bergfffd0932009-07-08 14:22:54 +0200293 wdev->wext.keys->def = wdev->wext.default_key;
294
295 wdev->wext.ibss.privacy = wdev->wext.default_key != -1;
296
Johannes Bergf1c1f172016-09-13 17:08:23 +0200297 if (wdev->wext.keys && wdev->wext.keys->def != -1) {
Johannes Bergfffd0932009-07-08 14:22:54 +0200298 ck = kmemdup(wdev->wext.keys, sizeof(*ck), GFP_KERNEL);
299 if (!ck)
300 return -ENOMEM;
David Spinadelb8676222016-09-22 23:16:50 +0300301 for (i = 0; i < CFG80211_MAX_WEP_KEYS; i++)
Johannes Bergfffd0932009-07-08 14:22:54 +0200302 ck->params[i].key = ck->data[i];
303 }
304 err = __cfg80211_join_ibss(rdev, wdev->netdev,
305 &wdev->wext.ibss, ck);
306 if (err)
307 kfree(ck);
308
309 return err;
Johannes Berg04a773a2009-04-19 21:24:32 +0200310}
311
312int cfg80211_ibss_wext_siwfreq(struct net_device *dev,
313 struct iw_request_info *info,
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200314 struct iw_freq *wextfreq, char *extra)
Johannes Berg04a773a2009-04-19 21:24:32 +0200315{
316 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800317 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200318 struct ieee80211_channel *chan = NULL;
319 int err, freq;
Johannes Berg04a773a2009-04-19 21:24:32 +0200320
321 /* call only for ibss! */
322 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
323 return -EINVAL;
324
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200325 if (!rdev->ops->join_ibss)
Johannes Berg04a773a2009-04-19 21:24:32 +0200326 return -EOPNOTSUPP;
327
Zhao, Gang96998e32014-04-09 09:28:06 +0800328 freq = cfg80211_wext_freq(wextfreq);
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200329 if (freq < 0)
330 return freq;
Johannes Berg04a773a2009-04-19 21:24:32 +0200331
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200332 if (freq) {
333 chan = ieee80211_get_channel(wdev->wiphy, freq);
334 if (!chan)
335 return -EINVAL;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200336 if (chan->flags & IEEE80211_CHAN_NO_IR ||
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200337 chan->flags & IEEE80211_CHAN_DISABLED)
338 return -EINVAL;
339 }
Johannes Berg04a773a2009-04-19 21:24:32 +0200340
Johannes Berg683b6d32012-11-08 21:25:48 +0100341 if (wdev->wext.ibss.chandef.chan == chan)
Johannes Berg04a773a2009-04-19 21:24:32 +0200342 return 0;
343
Johannes Berg667503d2009-07-07 03:56:11 +0200344 wdev_lock(wdev);
345 err = 0;
346 if (wdev->ssid_len)
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200347 err = __cfg80211_leave_ibss(rdev, dev, true);
Johannes Berg667503d2009-07-07 03:56:11 +0200348 wdev_unlock(wdev);
349
350 if (err)
351 return err;
Johannes Berg04a773a2009-04-19 21:24:32 +0200352
353 if (chan) {
Simon Wunderlich1fe45172013-10-30 16:09:33 +0100354 cfg80211_chandef_create(&wdev->wext.ibss.chandef, chan,
355 NL80211_CHAN_NO_HT);
Johannes Bergcbe8fa92009-05-09 20:09:03 +0200356 wdev->wext.ibss.channel_fixed = true;
Johannes Berg04a773a2009-04-19 21:24:32 +0200357 } else {
358 /* cfg80211_ibss_wext_join will pick one if needed */
Johannes Bergcbe8fa92009-05-09 20:09:03 +0200359 wdev->wext.ibss.channel_fixed = false;
Johannes Berg04a773a2009-04-19 21:24:32 +0200360 }
361
Johannes Bergfffd0932009-07-08 14:22:54 +0200362 wdev_lock(wdev);
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200363 err = cfg80211_ibss_wext_join(rdev, wdev);
Johannes Bergfffd0932009-07-08 14:22:54 +0200364 wdev_unlock(wdev);
365
366 return err;
Johannes Berg04a773a2009-04-19 21:24:32 +0200367}
Johannes Berg04a773a2009-04-19 21:24:32 +0200368
369int cfg80211_ibss_wext_giwfreq(struct net_device *dev,
370 struct iw_request_info *info,
371 struct iw_freq *freq, char *extra)
372{
373 struct wireless_dev *wdev = dev->ieee80211_ptr;
374 struct ieee80211_channel *chan = NULL;
375
376 /* call only for ibss! */
377 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
378 return -EINVAL;
379
Johannes Berg667503d2009-07-07 03:56:11 +0200380 wdev_lock(wdev);
Johannes Berg04a773a2009-04-19 21:24:32 +0200381 if (wdev->current_bss)
Johannes Berg19957bb2009-07-02 17:20:43 +0200382 chan = wdev->current_bss->pub.channel;
Johannes Berg683b6d32012-11-08 21:25:48 +0100383 else if (wdev->wext.ibss.chandef.chan)
384 chan = wdev->wext.ibss.chandef.chan;
Johannes Berg667503d2009-07-07 03:56:11 +0200385 wdev_unlock(wdev);
Johannes Berg04a773a2009-04-19 21:24:32 +0200386
387 if (chan) {
388 freq->m = chan->center_freq;
389 freq->e = 6;
390 return 0;
391 }
392
393 /* no channel if not joining */
394 return -EINVAL;
395}
Johannes Berg04a773a2009-04-19 21:24:32 +0200396
397int cfg80211_ibss_wext_siwessid(struct net_device *dev,
398 struct iw_request_info *info,
399 struct iw_point *data, char *ssid)
400{
401 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800402 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg04a773a2009-04-19 21:24:32 +0200403 size_t len = data->length;
404 int err;
405
406 /* call only for ibss! */
407 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
408 return -EINVAL;
409
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200410 if (!rdev->ops->join_ibss)
Johannes Berg04a773a2009-04-19 21:24:32 +0200411 return -EOPNOTSUPP;
412
Johannes Berg667503d2009-07-07 03:56:11 +0200413 wdev_lock(wdev);
414 err = 0;
415 if (wdev->ssid_len)
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200416 err = __cfg80211_leave_ibss(rdev, dev, true);
Johannes Berg667503d2009-07-07 03:56:11 +0200417 wdev_unlock(wdev);
418
419 if (err)
420 return err;
Johannes Berg04a773a2009-04-19 21:24:32 +0200421
422 /* iwconfig uses nul termination in SSID.. */
423 if (len > 0 && ssid[len - 1] == '\0')
424 len--;
425
Johannes Bergc1e5f472014-05-19 17:53:16 +0200426 memcpy(wdev->ssid, ssid, len);
Johannes Bergcbe8fa92009-05-09 20:09:03 +0200427 wdev->wext.ibss.ssid = wdev->ssid;
Johannes Bergcbe8fa92009-05-09 20:09:03 +0200428 wdev->wext.ibss.ssid_len = len;
Johannes Berg04a773a2009-04-19 21:24:32 +0200429
Johannes Bergfffd0932009-07-08 14:22:54 +0200430 wdev_lock(wdev);
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200431 err = cfg80211_ibss_wext_join(rdev, wdev);
Johannes Bergfffd0932009-07-08 14:22:54 +0200432 wdev_unlock(wdev);
433
434 return err;
Johannes Berg04a773a2009-04-19 21:24:32 +0200435}
Johannes Berg04a773a2009-04-19 21:24:32 +0200436
437int cfg80211_ibss_wext_giwessid(struct net_device *dev,
438 struct iw_request_info *info,
439 struct iw_point *data, char *ssid)
440{
441 struct wireless_dev *wdev = dev->ieee80211_ptr;
442
443 /* call only for ibss! */
444 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
445 return -EINVAL;
446
447 data->flags = 0;
448
Johannes Berg667503d2009-07-07 03:56:11 +0200449 wdev_lock(wdev);
Johannes Berg04a773a2009-04-19 21:24:32 +0200450 if (wdev->ssid_len) {
451 data->flags = 1;
452 data->length = wdev->ssid_len;
453 memcpy(ssid, wdev->ssid, data->length);
Johannes Bergcbe8fa92009-05-09 20:09:03 +0200454 } else if (wdev->wext.ibss.ssid && wdev->wext.ibss.ssid_len) {
Johannes Berg04a773a2009-04-19 21:24:32 +0200455 data->flags = 1;
Johannes Bergcbe8fa92009-05-09 20:09:03 +0200456 data->length = wdev->wext.ibss.ssid_len;
457 memcpy(ssid, wdev->wext.ibss.ssid, data->length);
Johannes Berg04a773a2009-04-19 21:24:32 +0200458 }
Johannes Berg667503d2009-07-07 03:56:11 +0200459 wdev_unlock(wdev);
Johannes Berg04a773a2009-04-19 21:24:32 +0200460
461 return 0;
462}
Johannes Berg04a773a2009-04-19 21:24:32 +0200463
464int cfg80211_ibss_wext_siwap(struct net_device *dev,
465 struct iw_request_info *info,
466 struct sockaddr *ap_addr, char *extra)
467{
468 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800469 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg04a773a2009-04-19 21:24:32 +0200470 u8 *bssid = ap_addr->sa_data;
471 int err;
472
473 /* call only for ibss! */
474 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
475 return -EINVAL;
476
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200477 if (!rdev->ops->join_ibss)
Johannes Berg04a773a2009-04-19 21:24:32 +0200478 return -EOPNOTSUPP;
479
480 if (ap_addr->sa_family != ARPHRD_ETHER)
481 return -EINVAL;
482
483 /* automatic mode */
484 if (is_zero_ether_addr(bssid) || is_broadcast_ether_addr(bssid))
485 bssid = NULL;
486
Johannes Berg74f82742014-04-09 22:32:16 +0200487 if (bssid && !is_valid_ether_addr(bssid))
488 return -EINVAL;
489
Johannes Berg04a773a2009-04-19 21:24:32 +0200490 /* both automatic */
Johannes Bergcbe8fa92009-05-09 20:09:03 +0200491 if (!bssid && !wdev->wext.ibss.bssid)
Johannes Berg04a773a2009-04-19 21:24:32 +0200492 return 0;
493
494 /* fixed already - and no change */
Johannes Bergcbe8fa92009-05-09 20:09:03 +0200495 if (wdev->wext.ibss.bssid && bssid &&
Joe Perchesac422d32012-05-08 18:56:55 +0000496 ether_addr_equal(bssid, wdev->wext.ibss.bssid))
Johannes Berg04a773a2009-04-19 21:24:32 +0200497 return 0;
498
Johannes Berg667503d2009-07-07 03:56:11 +0200499 wdev_lock(wdev);
500 err = 0;
501 if (wdev->ssid_len)
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200502 err = __cfg80211_leave_ibss(rdev, dev, true);
Johannes Berg667503d2009-07-07 03:56:11 +0200503 wdev_unlock(wdev);
504
505 if (err)
506 return err;
Johannes Berg04a773a2009-04-19 21:24:32 +0200507
508 if (bssid) {
Johannes Bergcbe8fa92009-05-09 20:09:03 +0200509 memcpy(wdev->wext.bssid, bssid, ETH_ALEN);
510 wdev->wext.ibss.bssid = wdev->wext.bssid;
Johannes Berg04a773a2009-04-19 21:24:32 +0200511 } else
Johannes Bergcbe8fa92009-05-09 20:09:03 +0200512 wdev->wext.ibss.bssid = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +0200513
Johannes Bergfffd0932009-07-08 14:22:54 +0200514 wdev_lock(wdev);
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200515 err = cfg80211_ibss_wext_join(rdev, wdev);
Johannes Bergfffd0932009-07-08 14:22:54 +0200516 wdev_unlock(wdev);
517
518 return err;
Johannes Berg04a773a2009-04-19 21:24:32 +0200519}
Johannes Berg04a773a2009-04-19 21:24:32 +0200520
521int cfg80211_ibss_wext_giwap(struct net_device *dev,
522 struct iw_request_info *info,
523 struct sockaddr *ap_addr, char *extra)
524{
525 struct wireless_dev *wdev = dev->ieee80211_ptr;
526
527 /* call only for ibss! */
528 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
529 return -EINVAL;
530
531 ap_addr->sa_family = ARPHRD_ETHER;
532
Johannes Berg667503d2009-07-07 03:56:11 +0200533 wdev_lock(wdev);
Johannes Berg7ebbe6b2009-07-01 21:26:48 +0200534 if (wdev->current_bss)
Johannes Berg19957bb2009-07-02 17:20:43 +0200535 memcpy(ap_addr->sa_data, wdev->current_bss->pub.bssid, ETH_ALEN);
Zhu Yi80e5b062009-07-09 16:59:49 +0800536 else if (wdev->wext.ibss.bssid)
Johannes Bergcbe8fa92009-05-09 20:09:03 +0200537 memcpy(ap_addr->sa_data, wdev->wext.ibss.bssid, ETH_ALEN);
Zhu Yi80e5b062009-07-09 16:59:49 +0800538 else
Joe Perchesd2beae12015-03-02 19:54:58 -0800539 eth_zero_addr(ap_addr->sa_data);
Zhu Yi80e5b062009-07-09 16:59:49 +0800540
Johannes Berg667503d2009-07-07 03:56:11 +0200541 wdev_unlock(wdev);
542
Johannes Berg04a773a2009-04-19 21:24:32 +0200543 return 0;
544}
Johannes Berg04a773a2009-04-19 21:24:32 +0200545#endif