blob: 364f900a3dc4d2810c90fa3f613d1b9a08cb5e71 [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 Berg667503dd2009-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 Berg667503dd2009-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 Berg667503dd2009-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 Berg667503dd2009-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 Berg667503dd2009-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 Berg667503dd2009-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 Berg667503dd2009-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 Berg667503dd2009-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 Berg667503dd2009-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 Berg667503dd2009-07-07 03:56:11 +0200149 int err;
150
Johannes Berg5fe231e2013-05-08 21:45:15 +0200151 ASSERT_RTNL();
152
Johannes Berg667503dd2009-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 Berg667503dd2009-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 Berg667503dd2009-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
Johannes Berg04a773a2009-04-19 21:24:32 +0200193}
194
Johannes Berg667503dd2009-07-07 03:56:11 +0200195void cfg80211_clear_ibss(struct net_device *dev, bool nowext)
196{
197 struct wireless_dev *wdev = dev->ieee80211_ptr;
198
199 wdev_lock(wdev);
200 __cfg80211_clear_ibss(dev, nowext);
201 wdev_unlock(wdev);
202}
203
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100204int __cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
205 struct net_device *dev, bool nowext)
Johannes Berg04a773a2009-04-19 21:24:32 +0200206{
Johannes Berg78485472009-07-07 03:56:05 +0200207 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg04a773a2009-04-19 21:24:32 +0200208 int err;
209
Johannes Berg667503dd2009-07-07 03:56:11 +0200210 ASSERT_WDEV_LOCK(wdev);
211
Johannes Berg78485472009-07-07 03:56:05 +0200212 if (!wdev->ssid_len)
213 return -ENOLINK;
214
Hila Gonene35e4d22012-06-27 17:19:42 +0300215 err = rdev_leave_ibss(rdev, dev);
Johannes Berg04a773a2009-04-19 21:24:32 +0200216
217 if (err)
218 return err;
219
Johannes Berg667503dd2009-07-07 03:56:11 +0200220 __cfg80211_clear_ibss(dev, nowext);
Johannes Berg04a773a2009-04-19 21:24:32 +0200221
222 return 0;
223}
224
Johannes Berg667503dd2009-07-07 03:56:11 +0200225int cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
226 struct net_device *dev, bool nowext)
227{
228 struct wireless_dev *wdev = dev->ieee80211_ptr;
229 int err;
230
231 wdev_lock(wdev);
232 err = __cfg80211_leave_ibss(rdev, dev, nowext);
233 wdev_unlock(wdev);
234
235 return err;
236}
237
Johannes Berg3d23e342009-09-29 23:27:28 +0200238#ifdef CONFIG_CFG80211_WEXT
Johannes Bergfffd0932009-07-08 14:22:54 +0200239int cfg80211_ibss_wext_join(struct cfg80211_registered_device *rdev,
240 struct wireless_dev *wdev)
Johannes Berg04a773a2009-04-19 21:24:32 +0200241{
Johannes Bergfffd0932009-07-08 14:22:54 +0200242 struct cfg80211_cached_keys *ck = NULL;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200243 enum nl80211_band band;
Johannes Bergfffd0932009-07-08 14:22:54 +0200244 int i, err;
245
246 ASSERT_WDEV_LOCK(wdev);
Johannes Berg04a773a2009-04-19 21:24:32 +0200247
Johannes Bergcbe8fa92009-05-09 20:09:03 +0200248 if (!wdev->wext.ibss.beacon_interval)
249 wdev->wext.ibss.beacon_interval = 100;
Johannes Berg8e30bc52009-04-22 17:45:38 +0200250
Johannes Berg04a773a2009-04-19 21:24:32 +0200251 /* try to find an IBSS channel if none requested ... */
Johannes Berg683b6d32012-11-08 21:25:48 +0100252 if (!wdev->wext.ibss.chandef.chan) {
Simon Wunderlich1fe45172013-10-30 16:09:33 +0100253 struct ieee80211_channel *new_chan = NULL;
Johannes Berg683b6d32012-11-08 21:25:48 +0100254
Johannes Berg57fbcce2016-04-12 15:56:15 +0200255 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg04a773a2009-04-19 21:24:32 +0200256 struct ieee80211_supported_band *sband;
257 struct ieee80211_channel *chan;
258
259 sband = rdev->wiphy.bands[band];
260 if (!sband)
261 continue;
262
263 for (i = 0; i < sband->n_channels; i++) {
264 chan = &sband->channels[i];
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200265 if (chan->flags & IEEE80211_CHAN_NO_IR)
Johannes Berg04a773a2009-04-19 21:24:32 +0200266 continue;
267 if (chan->flags & IEEE80211_CHAN_DISABLED)
268 continue;
Simon Wunderlich1fe45172013-10-30 16:09:33 +0100269 new_chan = chan;
Johannes Berg04a773a2009-04-19 21:24:32 +0200270 break;
271 }
272
Simon Wunderlich1fe45172013-10-30 16:09:33 +0100273 if (new_chan)
Johannes Berg04a773a2009-04-19 21:24:32 +0200274 break;
275 }
276
Simon Wunderlich1fe45172013-10-30 16:09:33 +0100277 if (!new_chan)
Johannes Berg04a773a2009-04-19 21:24:32 +0200278 return -EINVAL;
Simon Wunderlich1fe45172013-10-30 16:09:33 +0100279
280 cfg80211_chandef_create(&wdev->wext.ibss.chandef, new_chan,
281 NL80211_CHAN_NO_HT);
Johannes Berg04a773a2009-04-19 21:24:32 +0200282 }
283
284 /* don't join -- SSID is not there */
Johannes Bergcbe8fa92009-05-09 20:09:03 +0200285 if (!wdev->wext.ibss.ssid_len)
Johannes Berg04a773a2009-04-19 21:24:32 +0200286 return 0;
287
288 if (!netif_running(wdev->netdev))
289 return 0;
290
Johannes Berg89b706f2016-09-13 16:39:38 +0200291 if (wdev->wext.keys)
Johannes Bergfffd0932009-07-08 14:22:54 +0200292 wdev->wext.keys->def = wdev->wext.default_key;
293
294 wdev->wext.ibss.privacy = wdev->wext.default_key != -1;
295
Johannes Bergf1c1f172016-09-13 17:08:23 +0200296 if (wdev->wext.keys && wdev->wext.keys->def != -1) {
Johannes Bergfffd0932009-07-08 14:22:54 +0200297 ck = kmemdup(wdev->wext.keys, sizeof(*ck), GFP_KERNEL);
298 if (!ck)
299 return -ENOMEM;
David Spinadelb8676222016-09-22 23:16:50 +0300300 for (i = 0; i < CFG80211_MAX_WEP_KEYS; i++)
Johannes Bergfffd0932009-07-08 14:22:54 +0200301 ck->params[i].key = ck->data[i];
302 }
303 err = __cfg80211_join_ibss(rdev, wdev->netdev,
304 &wdev->wext.ibss, ck);
305 if (err)
306 kfree(ck);
307
308 return err;
Johannes Berg04a773a2009-04-19 21:24:32 +0200309}
310
311int cfg80211_ibss_wext_siwfreq(struct net_device *dev,
312 struct iw_request_info *info,
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200313 struct iw_freq *wextfreq, char *extra)
Johannes Berg04a773a2009-04-19 21:24:32 +0200314{
315 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800316 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200317 struct ieee80211_channel *chan = NULL;
318 int err, freq;
Johannes Berg04a773a2009-04-19 21:24:32 +0200319
320 /* call only for ibss! */
321 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
322 return -EINVAL;
323
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200324 if (!rdev->ops->join_ibss)
Johannes Berg04a773a2009-04-19 21:24:32 +0200325 return -EOPNOTSUPP;
326
Zhao, Gang96998e32014-04-09 09:28:06 +0800327 freq = cfg80211_wext_freq(wextfreq);
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200328 if (freq < 0)
329 return freq;
Johannes Berg04a773a2009-04-19 21:24:32 +0200330
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200331 if (freq) {
332 chan = ieee80211_get_channel(wdev->wiphy, freq);
333 if (!chan)
334 return -EINVAL;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200335 if (chan->flags & IEEE80211_CHAN_NO_IR ||
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200336 chan->flags & IEEE80211_CHAN_DISABLED)
337 return -EINVAL;
338 }
Johannes Berg04a773a2009-04-19 21:24:32 +0200339
Johannes Berg683b6d32012-11-08 21:25:48 +0100340 if (wdev->wext.ibss.chandef.chan == chan)
Johannes Berg04a773a2009-04-19 21:24:32 +0200341 return 0;
342
Johannes Berg667503dd2009-07-07 03:56:11 +0200343 wdev_lock(wdev);
344 err = 0;
345 if (wdev->ssid_len)
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200346 err = __cfg80211_leave_ibss(rdev, dev, true);
Johannes Berg667503dd2009-07-07 03:56:11 +0200347 wdev_unlock(wdev);
348
349 if (err)
350 return err;
Johannes Berg04a773a2009-04-19 21:24:32 +0200351
352 if (chan) {
Simon Wunderlich1fe45172013-10-30 16:09:33 +0100353 cfg80211_chandef_create(&wdev->wext.ibss.chandef, chan,
354 NL80211_CHAN_NO_HT);
Johannes Bergcbe8fa92009-05-09 20:09:03 +0200355 wdev->wext.ibss.channel_fixed = true;
Johannes Berg04a773a2009-04-19 21:24:32 +0200356 } else {
357 /* cfg80211_ibss_wext_join will pick one if needed */
Johannes Bergcbe8fa92009-05-09 20:09:03 +0200358 wdev->wext.ibss.channel_fixed = false;
Johannes Berg04a773a2009-04-19 21:24:32 +0200359 }
360
Johannes Bergfffd0932009-07-08 14:22:54 +0200361 wdev_lock(wdev);
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200362 err = cfg80211_ibss_wext_join(rdev, wdev);
Johannes Bergfffd0932009-07-08 14:22:54 +0200363 wdev_unlock(wdev);
364
365 return err;
Johannes Berg04a773a2009-04-19 21:24:32 +0200366}
Johannes Berg04a773a2009-04-19 21:24:32 +0200367
368int cfg80211_ibss_wext_giwfreq(struct net_device *dev,
369 struct iw_request_info *info,
370 struct iw_freq *freq, char *extra)
371{
372 struct wireless_dev *wdev = dev->ieee80211_ptr;
373 struct ieee80211_channel *chan = NULL;
374
375 /* call only for ibss! */
376 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
377 return -EINVAL;
378
Johannes Berg667503dd2009-07-07 03:56:11 +0200379 wdev_lock(wdev);
Johannes Berg04a773a2009-04-19 21:24:32 +0200380 if (wdev->current_bss)
Johannes Berg19957bb2009-07-02 17:20:43 +0200381 chan = wdev->current_bss->pub.channel;
Johannes Berg683b6d32012-11-08 21:25:48 +0100382 else if (wdev->wext.ibss.chandef.chan)
383 chan = wdev->wext.ibss.chandef.chan;
Johannes Berg667503dd2009-07-07 03:56:11 +0200384 wdev_unlock(wdev);
Johannes Berg04a773a2009-04-19 21:24:32 +0200385
386 if (chan) {
387 freq->m = chan->center_freq;
388 freq->e = 6;
389 return 0;
390 }
391
392 /* no channel if not joining */
393 return -EINVAL;
394}
Johannes Berg04a773a2009-04-19 21:24:32 +0200395
396int cfg80211_ibss_wext_siwessid(struct net_device *dev,
397 struct iw_request_info *info,
398 struct iw_point *data, char *ssid)
399{
400 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800401 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg04a773a2009-04-19 21:24:32 +0200402 size_t len = data->length;
403 int err;
404
405 /* call only for ibss! */
406 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
407 return -EINVAL;
408
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200409 if (!rdev->ops->join_ibss)
Johannes Berg04a773a2009-04-19 21:24:32 +0200410 return -EOPNOTSUPP;
411
Johannes Berg667503dd2009-07-07 03:56:11 +0200412 wdev_lock(wdev);
413 err = 0;
414 if (wdev->ssid_len)
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200415 err = __cfg80211_leave_ibss(rdev, dev, true);
Johannes Berg667503dd2009-07-07 03:56:11 +0200416 wdev_unlock(wdev);
417
418 if (err)
419 return err;
Johannes Berg04a773a2009-04-19 21:24:32 +0200420
421 /* iwconfig uses nul termination in SSID.. */
422 if (len > 0 && ssid[len - 1] == '\0')
423 len--;
424
Johannes Bergc1e5f472014-05-19 17:53:16 +0200425 memcpy(wdev->ssid, ssid, len);
Johannes Bergcbe8fa92009-05-09 20:09:03 +0200426 wdev->wext.ibss.ssid = wdev->ssid;
Johannes Bergcbe8fa92009-05-09 20:09:03 +0200427 wdev->wext.ibss.ssid_len = len;
Johannes Berg04a773a2009-04-19 21:24:32 +0200428
Johannes Bergfffd0932009-07-08 14:22:54 +0200429 wdev_lock(wdev);
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200430 err = cfg80211_ibss_wext_join(rdev, wdev);
Johannes Bergfffd0932009-07-08 14:22:54 +0200431 wdev_unlock(wdev);
432
433 return err;
Johannes Berg04a773a2009-04-19 21:24:32 +0200434}
Johannes Berg04a773a2009-04-19 21:24:32 +0200435
436int cfg80211_ibss_wext_giwessid(struct net_device *dev,
437 struct iw_request_info *info,
438 struct iw_point *data, char *ssid)
439{
440 struct wireless_dev *wdev = dev->ieee80211_ptr;
441
442 /* call only for ibss! */
443 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
444 return -EINVAL;
445
446 data->flags = 0;
447
Johannes Berg667503dd2009-07-07 03:56:11 +0200448 wdev_lock(wdev);
Johannes Berg04a773a2009-04-19 21:24:32 +0200449 if (wdev->ssid_len) {
450 data->flags = 1;
451 data->length = wdev->ssid_len;
452 memcpy(ssid, wdev->ssid, data->length);
Johannes Bergcbe8fa92009-05-09 20:09:03 +0200453 } else if (wdev->wext.ibss.ssid && wdev->wext.ibss.ssid_len) {
Johannes Berg04a773a2009-04-19 21:24:32 +0200454 data->flags = 1;
Johannes Bergcbe8fa92009-05-09 20:09:03 +0200455 data->length = wdev->wext.ibss.ssid_len;
456 memcpy(ssid, wdev->wext.ibss.ssid, data->length);
Johannes Berg04a773a2009-04-19 21:24:32 +0200457 }
Johannes Berg667503dd2009-07-07 03:56:11 +0200458 wdev_unlock(wdev);
Johannes Berg04a773a2009-04-19 21:24:32 +0200459
460 return 0;
461}
Johannes Berg04a773a2009-04-19 21:24:32 +0200462
463int cfg80211_ibss_wext_siwap(struct net_device *dev,
464 struct iw_request_info *info,
465 struct sockaddr *ap_addr, char *extra)
466{
467 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800468 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg04a773a2009-04-19 21:24:32 +0200469 u8 *bssid = ap_addr->sa_data;
470 int err;
471
472 /* call only for ibss! */
473 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
474 return -EINVAL;
475
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200476 if (!rdev->ops->join_ibss)
Johannes Berg04a773a2009-04-19 21:24:32 +0200477 return -EOPNOTSUPP;
478
479 if (ap_addr->sa_family != ARPHRD_ETHER)
480 return -EINVAL;
481
482 /* automatic mode */
483 if (is_zero_ether_addr(bssid) || is_broadcast_ether_addr(bssid))
484 bssid = NULL;
485
Johannes Berg74f82742014-04-09 22:32:16 +0200486 if (bssid && !is_valid_ether_addr(bssid))
487 return -EINVAL;
488
Johannes Berg04a773a2009-04-19 21:24:32 +0200489 /* both automatic */
Johannes Bergcbe8fa92009-05-09 20:09:03 +0200490 if (!bssid && !wdev->wext.ibss.bssid)
Johannes Berg04a773a2009-04-19 21:24:32 +0200491 return 0;
492
493 /* fixed already - and no change */
Johannes Bergcbe8fa92009-05-09 20:09:03 +0200494 if (wdev->wext.ibss.bssid && bssid &&
Joe Perchesac422d32012-05-08 18:56:55 +0000495 ether_addr_equal(bssid, wdev->wext.ibss.bssid))
Johannes Berg04a773a2009-04-19 21:24:32 +0200496 return 0;
497
Johannes Berg667503dd2009-07-07 03:56:11 +0200498 wdev_lock(wdev);
499 err = 0;
500 if (wdev->ssid_len)
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200501 err = __cfg80211_leave_ibss(rdev, dev, true);
Johannes Berg667503dd2009-07-07 03:56:11 +0200502 wdev_unlock(wdev);
503
504 if (err)
505 return err;
Johannes Berg04a773a2009-04-19 21:24:32 +0200506
507 if (bssid) {
Johannes Bergcbe8fa92009-05-09 20:09:03 +0200508 memcpy(wdev->wext.bssid, bssid, ETH_ALEN);
509 wdev->wext.ibss.bssid = wdev->wext.bssid;
Johannes Berg04a773a2009-04-19 21:24:32 +0200510 } else
Johannes Bergcbe8fa92009-05-09 20:09:03 +0200511 wdev->wext.ibss.bssid = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +0200512
Johannes Bergfffd0932009-07-08 14:22:54 +0200513 wdev_lock(wdev);
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200514 err = cfg80211_ibss_wext_join(rdev, wdev);
Johannes Bergfffd0932009-07-08 14:22:54 +0200515 wdev_unlock(wdev);
516
517 return err;
Johannes Berg04a773a2009-04-19 21:24:32 +0200518}
Johannes Berg04a773a2009-04-19 21:24:32 +0200519
520int cfg80211_ibss_wext_giwap(struct net_device *dev,
521 struct iw_request_info *info,
522 struct sockaddr *ap_addr, char *extra)
523{
524 struct wireless_dev *wdev = dev->ieee80211_ptr;
525
526 /* call only for ibss! */
527 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
528 return -EINVAL;
529
530 ap_addr->sa_family = ARPHRD_ETHER;
531
Johannes Berg667503dd2009-07-07 03:56:11 +0200532 wdev_lock(wdev);
Johannes Berg7ebbe6b2009-07-01 21:26:48 +0200533 if (wdev->current_bss)
Johannes Berg19957bb2009-07-02 17:20:43 +0200534 memcpy(ap_addr->sa_data, wdev->current_bss->pub.bssid, ETH_ALEN);
Zhu Yi80e5b062009-07-09 16:59:49 +0800535 else if (wdev->wext.ibss.bssid)
Johannes Bergcbe8fa92009-05-09 20:09:03 +0200536 memcpy(ap_addr->sa_data, wdev->wext.ibss.bssid, ETH_ALEN);
Zhu Yi80e5b062009-07-09 16:59:49 +0800537 else
Joe Perchesd2beae12015-03-02 19:54:58 -0800538 eth_zero_addr(ap_addr->sa_data);
Zhu Yi80e5b062009-07-09 16:59:49 +0800539
Johannes Berg667503dd2009-07-07 03:56:11 +0200540 wdev_unlock(wdev);
541
Johannes Berg04a773a2009-04-19 21:24:32 +0200542 return 0;
543}
Johannes Berg04a773a2009-04-19 21:24:32 +0200544#endif