blob: fd9ad74972fb0041b9aa912dbc7fd2df9d2b7da0 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Johannes Bergfee52672008-11-26 22:36:31 +01002/*
3 * cfg80211 - wext compat code
4 *
5 * This is temporary code until all wireless functionality is migrated
6 * into cfg80211, when that happens all the exports here go away and
7 * we directly assign the wireless handlers of wireless interfaces.
8 *
Johannes Berg08645122009-05-11 13:54:58 +02009 * Copyright 2008-2009 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg3cfe91c2019-08-30 14:24:44 +030010 * Copyright (C) 2019 Intel Corporation
Johannes Bergfee52672008-11-26 22:36:31 +010011 */
12
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040013#include <linux/export.h>
Johannes Bergfee52672008-11-26 22:36:31 +010014#include <linux/wireless.h>
15#include <linux/nl80211.h>
Johannes Berg691597c2009-04-19 19:57:45 +020016#include <linux/if_arp.h>
Johannes Berg08645122009-05-11 13:54:58 +020017#include <linux/etherdevice.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090018#include <linux/slab.h>
Johannes Bergfee52672008-11-26 22:36:31 +010019#include <net/iw_handler.h>
Johannes Bergfee52672008-11-26 22:36:31 +010020#include <net/cfg80211.h>
Johannes Berg262eb9b22011-07-13 10:39:09 +020021#include <net/cfg80211-wext.h>
Johannes Berg0e82ffe2009-07-27 12:01:50 +020022#include "wext-compat.h"
Johannes Bergfee52672008-11-26 22:36:31 +010023#include "core.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030024#include "rdev-ops.h"
Johannes Bergfee52672008-11-26 22:36:31 +010025
26int cfg80211_wext_giwname(struct net_device *dev,
27 struct iw_request_info *info,
28 char *name, char *extra)
29{
Johannes Bergfee52672008-11-26 22:36:31 +010030 strcpy(name, "IEEE 802.11");
Johannes Bergfee52672008-11-26 22:36:31 +010031 return 0;
32}
Johannes Berg2afe38d2015-01-06 14:00:53 +010033EXPORT_WEXT_HANDLER(cfg80211_wext_giwname);
Johannes Berge60c7742008-11-26 23:31:40 +010034
35int cfg80211_wext_siwmode(struct net_device *dev, struct iw_request_info *info,
36 u32 *mode, char *extra)
37{
38 struct wireless_dev *wdev = dev->ieee80211_ptr;
39 struct cfg80211_registered_device *rdev;
40 struct vif_params vifparams;
41 enum nl80211_iftype type;
42
Zhao, Gangf26cbf42014-04-21 12:53:03 +080043 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berge60c7742008-11-26 23:31:40 +010044
Johannes Berge60c7742008-11-26 23:31:40 +010045 switch (*mode) {
46 case IW_MODE_INFRA:
47 type = NL80211_IFTYPE_STATION;
48 break;
49 case IW_MODE_ADHOC:
50 type = NL80211_IFTYPE_ADHOC;
51 break;
Johannes Berge60c7742008-11-26 23:31:40 +010052 case IW_MODE_MONITOR:
53 type = NL80211_IFTYPE_MONITOR;
54 break;
55 default:
56 return -EINVAL;
57 }
58
Johannes Bergac7f9cf2009-03-21 17:07:59 +010059 if (type == wdev->iftype)
60 return 0;
61
Johannes Berge60c7742008-11-26 23:31:40 +010062 memset(&vifparams, 0, sizeof(vifparams));
63
Johannes Berg818a9862017-04-12 11:23:28 +020064 return cfg80211_change_iface(rdev, dev, type, &vifparams);
Johannes Berge60c7742008-11-26 23:31:40 +010065}
Johannes Berg2afe38d2015-01-06 14:00:53 +010066EXPORT_WEXT_HANDLER(cfg80211_wext_siwmode);
Johannes Berge60c7742008-11-26 23:31:40 +010067
68int cfg80211_wext_giwmode(struct net_device *dev, struct iw_request_info *info,
69 u32 *mode, char *extra)
70{
71 struct wireless_dev *wdev = dev->ieee80211_ptr;
72
73 if (!wdev)
74 return -EOPNOTSUPP;
75
76 switch (wdev->iftype) {
77 case NL80211_IFTYPE_AP:
78 *mode = IW_MODE_MASTER;
79 break;
80 case NL80211_IFTYPE_STATION:
81 *mode = IW_MODE_INFRA;
82 break;
83 case NL80211_IFTYPE_ADHOC:
84 *mode = IW_MODE_ADHOC;
85 break;
86 case NL80211_IFTYPE_MONITOR:
87 *mode = IW_MODE_MONITOR;
88 break;
89 case NL80211_IFTYPE_WDS:
90 *mode = IW_MODE_REPEAT;
91 break;
92 case NL80211_IFTYPE_AP_VLAN:
93 *mode = IW_MODE_SECOND; /* FIXME */
94 break;
95 default:
96 *mode = IW_MODE_AUTO;
97 break;
98 }
99 return 0;
100}
Johannes Berg2afe38d2015-01-06 14:00:53 +0100101EXPORT_WEXT_HANDLER(cfg80211_wext_giwmode);
Johannes Berg4aa188e2009-02-18 19:32:08 +0100102
103
104int cfg80211_wext_giwrange(struct net_device *dev,
105 struct iw_request_info *info,
106 struct iw_point *data, char *extra)
107{
108 struct wireless_dev *wdev = dev->ieee80211_ptr;
109 struct iw_range *range = (struct iw_range *) extra;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200110 enum nl80211_band band;
Johannes Berg9834c072009-07-06 19:40:51 +0200111 int i, c = 0;
Johannes Berg4aa188e2009-02-18 19:32:08 +0100112
113 if (!wdev)
114 return -EOPNOTSUPP;
115
116 data->length = sizeof(struct iw_range);
117 memset(range, 0, sizeof(struct iw_range));
118
119 range->we_version_compiled = WIRELESS_EXT;
120 range->we_version_source = 21;
121 range->retry_capa = IW_RETRY_LIMIT;
122 range->retry_flags = IW_RETRY_LIMIT;
123 range->min_retry = 0;
124 range->max_retry = 255;
125 range->min_rts = 0;
126 range->max_rts = 2347;
127 range->min_frag = 256;
128 range->max_frag = 2346;
129
Johannes Berg4aa188e2009-02-18 19:32:08 +0100130 range->max_encoding_tokens = 4;
131
132 range->max_qual.updated = IW_QUAL_NOISE_INVALID;
133
134 switch (wdev->wiphy->signal_type) {
135 case CFG80211_SIGNAL_TYPE_NONE:
136 break;
137 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berge7d83ed2012-12-07 11:58:26 +0100138 range->max_qual.level = (u8)-110;
Johannes Berg4aa188e2009-02-18 19:32:08 +0100139 range->max_qual.qual = 70;
140 range->avg_qual.qual = 35;
141 range->max_qual.updated |= IW_QUAL_DBM;
142 range->max_qual.updated |= IW_QUAL_QUAL_UPDATED;
143 range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED;
144 break;
145 case CFG80211_SIGNAL_TYPE_UNSPEC:
146 range->max_qual.level = 100;
147 range->max_qual.qual = 100;
148 range->avg_qual.qual = 50;
149 range->max_qual.updated |= IW_QUAL_QUAL_UPDATED;
150 range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED;
151 break;
152 }
153
154 range->avg_qual.level = range->max_qual.level / 2;
155 range->avg_qual.noise = range->max_qual.noise / 2;
156 range->avg_qual.updated = range->max_qual.updated;
157
Johannes Berg9834c072009-07-06 19:40:51 +0200158 for (i = 0; i < wdev->wiphy->n_cipher_suites; i++) {
159 switch (wdev->wiphy->cipher_suites[i]) {
David Kilroy3daf0972009-06-18 23:21:14 +0100160 case WLAN_CIPHER_SUITE_TKIP:
David Kilroy27bea662009-06-18 23:21:17 +0100161 range->enc_capa |= (IW_ENC_CAPA_CIPHER_TKIP |
162 IW_ENC_CAPA_WPA);
David Kilroy3daf0972009-06-18 23:21:14 +0100163 break;
164
165 case WLAN_CIPHER_SUITE_CCMP:
David Kilroy27bea662009-06-18 23:21:17 +0100166 range->enc_capa |= (IW_ENC_CAPA_CIPHER_CCMP |
167 IW_ENC_CAPA_WPA2);
David Kilroy3daf0972009-06-18 23:21:14 +0100168 break;
David Kilroy2ab658f2009-06-18 23:21:16 +0100169
170 case WLAN_CIPHER_SUITE_WEP40:
171 range->encoding_size[range->num_encoding_sizes++] =
172 WLAN_KEY_LEN_WEP40;
173 break;
174
175 case WLAN_CIPHER_SUITE_WEP104:
176 range->encoding_size[range->num_encoding_sizes++] =
177 WLAN_KEY_LEN_WEP104;
178 break;
David Kilroy3daf0972009-06-18 23:21:14 +0100179 }
180 }
Johannes Berg4aa188e2009-02-18 19:32:08 +0100181
Johannes Berg57fbcce2016-04-12 15:56:15 +0200182 for (band = 0; band < NUM_NL80211_BANDS; band ++) {
Johannes Berg4aa188e2009-02-18 19:32:08 +0100183 struct ieee80211_supported_band *sband;
184
185 sband = wdev->wiphy->bands[band];
186
187 if (!sband)
188 continue;
189
190 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
191 struct ieee80211_channel *chan = &sband->channels[i];
192
193 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
194 range->freq[c].i =
195 ieee80211_frequency_to_channel(
196 chan->center_freq);
197 range->freq[c].m = chan->center_freq;
198 range->freq[c].e = 6;
199 c++;
200 }
201 }
202 }
203 range->num_channels = c;
204 range->num_frequency = c;
205
206 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
207 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
208 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
209
David Kilroy51cd4aa2009-06-18 23:21:15 +0100210 if (wdev->wiphy->max_scan_ssids > 0)
211 range->scan_capa |= IW_SCAN_CAPA_ESSID;
Johannes Berg4aa188e2009-02-18 19:32:08 +0100212
213 return 0;
214}
Johannes Berg2afe38d2015-01-06 14:00:53 +0100215EXPORT_WEXT_HANDLER(cfg80211_wext_giwrange);
Johannes Berg691597c2009-04-19 19:57:45 +0200216
Johannes Berg04a773a2009-04-19 21:24:32 +0200217
218/**
219 * cfg80211_wext_freq - get wext frequency for non-"auto"
Johannes Berg04a773a2009-04-19 21:24:32 +0200220 * @freq: the wext freq encoding
221 *
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200222 * Returns a frequency, or a negative error code, or 0 for auto.
Johannes Berg04a773a2009-04-19 21:24:32 +0200223 */
Zhao, Gang96998e32014-04-09 09:28:06 +0800224int cfg80211_wext_freq(struct iw_freq *freq)
Johannes Berg04a773a2009-04-19 21:24:32 +0200225{
Johannes Berg0b258582009-05-08 09:42:33 +0200226 /*
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200227 * Parse frequency - return 0 for auto and
Johannes Berg0b258582009-05-08 09:42:33 +0200228 * -EINVAL for impossible things.
229 */
Johannes Berg04a773a2009-04-19 21:24:32 +0200230 if (freq->e == 0) {
Johannes Berg57fbcce2016-04-12 15:56:15 +0200231 enum nl80211_band band = NL80211_BAND_2GHZ;
Johannes Berg04a773a2009-04-19 21:24:32 +0200232 if (freq->m < 0)
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200233 return 0;
Bruno Randolf59eb21a2011-01-17 13:37:28 +0900234 if (freq->m > 14)
Johannes Berg57fbcce2016-04-12 15:56:15 +0200235 band = NL80211_BAND_5GHZ;
Bruno Randolf59eb21a2011-01-17 13:37:28 +0900236 return ieee80211_channel_to_frequency(freq->m, band);
Johannes Berg04a773a2009-04-19 21:24:32 +0200237 } else {
238 int i, div = 1000000;
239 for (i = 0; i < freq->e; i++)
240 div /= 10;
Johannes Berg0b258582009-05-08 09:42:33 +0200241 if (div <= 0)
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200242 return -EINVAL;
243 return freq->m / div;
Johannes Berg04a773a2009-04-19 21:24:32 +0200244 }
Johannes Berg04a773a2009-04-19 21:24:32 +0200245}
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200246
247int cfg80211_wext_siwrts(struct net_device *dev,
248 struct iw_request_info *info,
249 struct iw_param *rts, char *extra)
250{
251 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800252 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200253 u32 orts = wdev->wiphy->rts_threshold;
254 int err;
255
256 if (rts->disabled || !rts->fixed)
257 wdev->wiphy->rts_threshold = (u32) -1;
258 else if (rts->value < 0)
259 return -EINVAL;
260 else
261 wdev->wiphy->rts_threshold = rts->value;
262
Hila Gonene35e4d22012-06-27 17:19:42 +0300263 err = rdev_set_wiphy_params(rdev, WIPHY_PARAM_RTS_THRESHOLD);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200264 if (err)
265 wdev->wiphy->rts_threshold = orts;
266
267 return err;
268}
Johannes Berg2afe38d2015-01-06 14:00:53 +0100269EXPORT_WEXT_HANDLER(cfg80211_wext_siwrts);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200270
271int cfg80211_wext_giwrts(struct net_device *dev,
272 struct iw_request_info *info,
273 struct iw_param *rts, char *extra)
274{
275 struct wireless_dev *wdev = dev->ieee80211_ptr;
276
277 rts->value = wdev->wiphy->rts_threshold;
278 rts->disabled = rts->value == (u32) -1;
279 rts->fixed = 1;
280
281 return 0;
282}
Johannes Berg2afe38d2015-01-06 14:00:53 +0100283EXPORT_WEXT_HANDLER(cfg80211_wext_giwrts);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200284
285int cfg80211_wext_siwfrag(struct net_device *dev,
286 struct iw_request_info *info,
287 struct iw_param *frag, char *extra)
288{
289 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800290 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200291 u32 ofrag = wdev->wiphy->frag_threshold;
292 int err;
293
294 if (frag->disabled || !frag->fixed)
295 wdev->wiphy->frag_threshold = (u32) -1;
296 else if (frag->value < 256)
297 return -EINVAL;
298 else {
299 /* Fragment length must be even, so strip LSB. */
300 wdev->wiphy->frag_threshold = frag->value & ~0x1;
301 }
302
Hila Gonene35e4d22012-06-27 17:19:42 +0300303 err = rdev_set_wiphy_params(rdev, WIPHY_PARAM_FRAG_THRESHOLD);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200304 if (err)
305 wdev->wiphy->frag_threshold = ofrag;
306
307 return err;
308}
Johannes Berg2afe38d2015-01-06 14:00:53 +0100309EXPORT_WEXT_HANDLER(cfg80211_wext_siwfrag);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200310
311int cfg80211_wext_giwfrag(struct net_device *dev,
312 struct iw_request_info *info,
313 struct iw_param *frag, char *extra)
314{
315 struct wireless_dev *wdev = dev->ieee80211_ptr;
316
317 frag->value = wdev->wiphy->frag_threshold;
318 frag->disabled = frag->value == (u32) -1;
319 frag->fixed = 1;
320
321 return 0;
322}
Johannes Berg2afe38d2015-01-06 14:00:53 +0100323EXPORT_WEXT_HANDLER(cfg80211_wext_giwfrag);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200324
Johannes Berg04b0c5c2011-07-15 13:01:38 +0200325static int cfg80211_wext_siwretry(struct net_device *dev,
326 struct iw_request_info *info,
327 struct iw_param *retry, char *extra)
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200328{
329 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800330 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200331 u32 changed = 0;
332 u8 olong = wdev->wiphy->retry_long;
333 u8 oshort = wdev->wiphy->retry_short;
334 int err;
335
Ujjal Royf5aa0d22014-01-09 21:16:14 +0530336 if (retry->disabled || retry->value < 1 || retry->value > 255 ||
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200337 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
338 return -EINVAL;
339
340 if (retry->flags & IW_RETRY_LONG) {
341 wdev->wiphy->retry_long = retry->value;
342 changed |= WIPHY_PARAM_RETRY_LONG;
343 } else if (retry->flags & IW_RETRY_SHORT) {
344 wdev->wiphy->retry_short = retry->value;
345 changed |= WIPHY_PARAM_RETRY_SHORT;
346 } else {
347 wdev->wiphy->retry_short = retry->value;
348 wdev->wiphy->retry_long = retry->value;
349 changed |= WIPHY_PARAM_RETRY_LONG;
350 changed |= WIPHY_PARAM_RETRY_SHORT;
351 }
352
Hila Gonene35e4d22012-06-27 17:19:42 +0300353 err = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200354 if (err) {
355 wdev->wiphy->retry_short = oshort;
356 wdev->wiphy->retry_long = olong;
357 }
358
359 return err;
360}
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200361
362int cfg80211_wext_giwretry(struct net_device *dev,
363 struct iw_request_info *info,
364 struct iw_param *retry, char *extra)
365{
366 struct wireless_dev *wdev = dev->ieee80211_ptr;
367
368 retry->disabled = 0;
369
370 if (retry->flags == 0 || (retry->flags & IW_RETRY_SHORT)) {
371 /*
372 * First return short value, iwconfig will ask long value
373 * later if needed
374 */
Ujjal Roy60a4fe02014-01-06 21:56:11 +0530375 retry->flags |= IW_RETRY_LIMIT | IW_RETRY_SHORT;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200376 retry->value = wdev->wiphy->retry_short;
Ujjal Roy60a4fe02014-01-06 21:56:11 +0530377 if (wdev->wiphy->retry_long == wdev->wiphy->retry_short)
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200378 retry->flags |= IW_RETRY_LONG;
379
380 return 0;
381 }
382
383 if (retry->flags & IW_RETRY_LONG) {
384 retry->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
385 retry->value = wdev->wiphy->retry_long;
386 }
387
388 return 0;
389}
Johannes Berg2afe38d2015-01-06 14:00:53 +0100390EXPORT_WEXT_HANDLER(cfg80211_wext_giwretry);
Johannes Berg08645122009-05-11 13:54:58 +0200391
Johannes Bergfffd0932009-07-08 14:22:54 +0200392static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
Johannes Berge31b8212010-10-05 19:39:30 +0200393 struct net_device *dev, bool pairwise,
394 const u8 *addr, bool remove, bool tx_key,
395 int idx, struct key_params *params)
Johannes Berg08645122009-05-11 13:54:58 +0200396{
397 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergfffd0932009-07-08 14:22:54 +0200398 int err, i;
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100399 bool rejoin = false;
Johannes Bergfffd0932009-07-08 14:22:54 +0200400
Johannes Berge31b8212010-10-05 19:39:30 +0200401 if (pairwise && !addr)
402 return -EINVAL;
403
Johannes Berg8f7d99b2016-09-28 23:44:57 +0200404 /*
405 * In many cases we won't actually need this, but it's better
406 * to do it first in case the allocation fails. Don't use wext.
407 */
Johannes Bergfffd0932009-07-08 14:22:54 +0200408 if (!wdev->wext.keys) {
409 wdev->wext.keys = kzalloc(sizeof(*wdev->wext.keys),
Johannes Berg89b706f2016-09-13 16:39:38 +0200410 GFP_KERNEL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200411 if (!wdev->wext.keys)
412 return -ENOMEM;
David Spinadelb8676222016-09-22 23:16:50 +0300413 for (i = 0; i < CFG80211_MAX_WEP_KEYS; i++)
Johannes Bergfffd0932009-07-08 14:22:54 +0200414 wdev->wext.keys->params[i].key =
415 wdev->wext.keys->data[i];
416 }
417
418 if (wdev->iftype != NL80211_IFTYPE_ADHOC &&
419 wdev->iftype != NL80211_IFTYPE_STATION)
420 return -EOPNOTSUPP;
Johannes Berg08645122009-05-11 13:54:58 +0200421
422 if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
Johannes Bergfffd0932009-07-08 14:22:54 +0200423 if (!wdev->current_bss)
424 return -ENOLINK;
425
Johannes Berg08645122009-05-11 13:54:58 +0200426 if (!rdev->ops->set_default_mgmt_key)
427 return -EOPNOTSUPP;
428
429 if (idx < 4 || idx > 5)
430 return -EINVAL;
431 } else if (idx < 0 || idx > 3)
432 return -EINVAL;
433
434 if (remove) {
Johannes Bergfffd0932009-07-08 14:22:54 +0200435 err = 0;
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100436 if (wdev->current_bss) {
437 /*
438 * If removing the current TX key, we will need to
439 * join a new IBSS without the privacy bit clear.
440 */
441 if (idx == wdev->wext.default_key &&
442 wdev->iftype == NL80211_IFTYPE_ADHOC) {
443 __cfg80211_leave_ibss(rdev, wdev->netdev, true);
444 rejoin = true;
445 }
Johannes Berge31b8212010-10-05 19:39:30 +0200446
447 if (!pairwise && addr &&
448 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
449 err = -ENOENT;
450 else
Hila Gonene35e4d22012-06-27 17:19:42 +0300451 err = rdev_del_key(rdev, dev, idx, pairwise,
452 addr);
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100453 }
Vivek Natarajand55fb892009-11-24 11:54:10 -0500454 wdev->wext.connect.privacy = false;
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100455 /*
456 * Applications using wireless extensions expect to be
457 * able to delete keys that don't exist, so allow that.
458 */
459 if (err == -ENOENT)
460 err = 0;
Johannes Berg08645122009-05-11 13:54:58 +0200461 if (!err) {
Johannes Berg89b706f2016-09-13 16:39:38 +0200462 if (!addr && idx < 4) {
Johannes Berg538c9eb2014-09-10 13:39:56 +0300463 memset(wdev->wext.keys->data[idx], 0,
464 sizeof(wdev->wext.keys->data[idx]));
Johannes Bergfffd0932009-07-08 14:22:54 +0200465 wdev->wext.keys->params[idx].key_len = 0;
466 wdev->wext.keys->params[idx].cipher = 0;
467 }
Johannes Berg08645122009-05-11 13:54:58 +0200468 if (idx == wdev->wext.default_key)
469 wdev->wext.default_key = -1;
470 else if (idx == wdev->wext.default_mgmt_key)
471 wdev->wext.default_mgmt_key = -1;
472 }
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100473
474 if (!err && rejoin)
475 err = cfg80211_ibss_wext_join(rdev, wdev);
Johannes Berge3da5742009-05-18 19:56:36 +0200476
Johannes Berg08645122009-05-11 13:54:58 +0200477 return err;
Johannes Bergfffd0932009-07-08 14:22:54 +0200478 }
Johannes Berg08645122009-05-11 13:54:58 +0200479
Johannes Bergfffd0932009-07-08 14:22:54 +0200480 if (addr)
481 tx_key = false;
Johannes Berg08645122009-05-11 13:54:58 +0200482
Johannes Berge31b8212010-10-05 19:39:30 +0200483 if (cfg80211_validate_key_settings(rdev, params, idx, pairwise, addr))
Johannes Bergfffd0932009-07-08 14:22:54 +0200484 return -EINVAL;
485
486 err = 0;
487 if (wdev->current_bss)
Hila Gonene35e4d22012-06-27 17:19:42 +0300488 err = rdev_add_key(rdev, dev, idx, pairwise, addr, params);
Johannes Berg9381e262016-09-13 16:11:32 +0200489 else if (params->cipher != WLAN_CIPHER_SUITE_WEP40 &&
490 params->cipher != WLAN_CIPHER_SUITE_WEP104)
491 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +0200492 if (err)
493 return err;
Johannes Berg08645122009-05-11 13:54:58 +0200494
Johannes Berg8f7d99b2016-09-28 23:44:57 +0200495 /*
496 * We only need to store WEP keys, since they're the only keys that
Randy Dunlapeee79f82020-08-22 16:19:53 -0700497 * can be set before a connection is established and persist after
Johannes Berg8f7d99b2016-09-28 23:44:57 +0200498 * disconnecting.
499 */
500 if (!addr && (params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
501 params->cipher == WLAN_CIPHER_SUITE_WEP104)) {
Johannes Bergfffd0932009-07-08 14:22:54 +0200502 wdev->wext.keys->params[idx] = *params;
503 memcpy(wdev->wext.keys->data[idx],
504 params->key, params->key_len);
505 wdev->wext.keys->params[idx].key =
506 wdev->wext.keys->data[idx];
507 }
508
Zhu Yi1f00fca2009-07-20 11:47:43 +0800509 if ((params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
510 params->cipher == WLAN_CIPHER_SUITE_WEP104) &&
Johannes Bergfffd0932009-07-08 14:22:54 +0200511 (tx_key || (!addr && wdev->wext.default_key == -1))) {
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100512 if (wdev->current_bss) {
513 /*
514 * If we are getting a new TX key from not having
515 * had one before we need to join a new IBSS with
516 * the privacy bit set.
517 */
518 if (wdev->iftype == NL80211_IFTYPE_ADHOC &&
519 wdev->wext.default_key == -1) {
520 __cfg80211_leave_ibss(rdev, wdev->netdev, true);
521 rejoin = true;
522 }
Hila Gonene35e4d22012-06-27 17:19:42 +0300523 err = rdev_set_default_key(rdev, dev, idx, true, true);
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100524 }
525 if (!err) {
Johannes Bergfffd0932009-07-08 14:22:54 +0200526 wdev->wext.default_key = idx;
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100527 if (rejoin)
528 err = cfg80211_ibss_wext_join(rdev, wdev);
529 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200530 return err;
531 }
Johannes Berg08645122009-05-11 13:54:58 +0200532
Johannes Bergfffd0932009-07-08 14:22:54 +0200533 if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC &&
534 (tx_key || (!addr && wdev->wext.default_mgmt_key == -1))) {
535 if (wdev->current_bss)
Hila Gonene35e4d22012-06-27 17:19:42 +0300536 err = rdev_set_default_mgmt_key(rdev, dev, idx);
Johannes Bergfffd0932009-07-08 14:22:54 +0200537 if (!err)
538 wdev->wext.default_mgmt_key = idx;
539 return err;
Johannes Berg08645122009-05-11 13:54:58 +0200540 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200541
542 return 0;
543}
544
545static int cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
Johannes Berge31b8212010-10-05 19:39:30 +0200546 struct net_device *dev, bool pairwise,
547 const u8 *addr, bool remove, bool tx_key,
548 int idx, struct key_params *params)
Johannes Bergfffd0932009-07-08 14:22:54 +0200549{
550 int err;
551
552 wdev_lock(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +0200553 err = __cfg80211_set_encryption(rdev, dev, pairwise, addr,
554 remove, tx_key, idx, params);
Johannes Bergfffd0932009-07-08 14:22:54 +0200555 wdev_unlock(dev->ieee80211_ptr);
556
557 return err;
Johannes Berg08645122009-05-11 13:54:58 +0200558}
559
Johannes Berg04b0c5c2011-07-15 13:01:38 +0200560static int cfg80211_wext_siwencode(struct net_device *dev,
561 struct iw_request_info *info,
562 struct iw_point *erq, char *keybuf)
Johannes Berg08645122009-05-11 13:54:58 +0200563{
564 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800565 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg08645122009-05-11 13:54:58 +0200566 int idx, err;
567 bool remove = false;
568 struct key_params params;
569
Johannes Bergfffd0932009-07-08 14:22:54 +0200570 if (wdev->iftype != NL80211_IFTYPE_STATION &&
571 wdev->iftype != NL80211_IFTYPE_ADHOC)
572 return -EOPNOTSUPP;
573
Johannes Berg08645122009-05-11 13:54:58 +0200574 /* no use -- only MFP (set_default_mgmt_key) is optional */
575 if (!rdev->ops->del_key ||
576 !rdev->ops->add_key ||
577 !rdev->ops->set_default_key)
578 return -EOPNOTSUPP;
579
580 idx = erq->flags & IW_ENCODE_INDEX;
581 if (idx == 0) {
582 idx = wdev->wext.default_key;
583 if (idx < 0)
584 idx = 0;
585 } else if (idx < 1 || idx > 4)
586 return -EINVAL;
587 else
588 idx--;
589
590 if (erq->flags & IW_ENCODE_DISABLED)
591 remove = true;
592 else if (erq->length == 0) {
593 /* No key data - just set the default TX key index */
Johannes Bergfffd0932009-07-08 14:22:54 +0200594 err = 0;
595 wdev_lock(wdev);
596 if (wdev->current_bss)
Hila Gonene35e4d22012-06-27 17:19:42 +0300597 err = rdev_set_default_key(rdev, dev, idx, true,
598 true);
Johannes Berg08645122009-05-11 13:54:58 +0200599 if (!err)
600 wdev->wext.default_key = idx;
Johannes Bergfffd0932009-07-08 14:22:54 +0200601 wdev_unlock(wdev);
Johannes Berg08645122009-05-11 13:54:58 +0200602 return err;
603 }
604
605 memset(&params, 0, sizeof(params));
606 params.key = keybuf;
607 params.key_len = erq->length;
608 if (erq->length == 5)
609 params.cipher = WLAN_CIPHER_SUITE_WEP40;
610 else if (erq->length == 13)
611 params.cipher = WLAN_CIPHER_SUITE_WEP104;
612 else if (!remove)
613 return -EINVAL;
614
Johannes Berge31b8212010-10-05 19:39:30 +0200615 return cfg80211_set_encryption(rdev, dev, false, NULL, remove,
Johannes Berg08645122009-05-11 13:54:58 +0200616 wdev->wext.default_key == -1,
617 idx, &params);
618}
Johannes Berg08645122009-05-11 13:54:58 +0200619
Johannes Berg04b0c5c2011-07-15 13:01:38 +0200620static int cfg80211_wext_siwencodeext(struct net_device *dev,
621 struct iw_request_info *info,
622 struct iw_point *erq, char *extra)
Johannes Berg08645122009-05-11 13:54:58 +0200623{
624 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800625 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg08645122009-05-11 13:54:58 +0200626 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
627 const u8 *addr;
628 int idx;
629 bool remove = false;
630 struct key_params params;
631 u32 cipher;
632
Johannes Bergfffd0932009-07-08 14:22:54 +0200633 if (wdev->iftype != NL80211_IFTYPE_STATION &&
634 wdev->iftype != NL80211_IFTYPE_ADHOC)
635 return -EOPNOTSUPP;
636
Johannes Berg08645122009-05-11 13:54:58 +0200637 /* no use -- only MFP (set_default_mgmt_key) is optional */
638 if (!rdev->ops->del_key ||
639 !rdev->ops->add_key ||
640 !rdev->ops->set_default_key)
641 return -EOPNOTSUPP;
642
643 switch (ext->alg) {
644 case IW_ENCODE_ALG_NONE:
645 remove = true;
646 cipher = 0;
647 break;
648 case IW_ENCODE_ALG_WEP:
649 if (ext->key_len == 5)
650 cipher = WLAN_CIPHER_SUITE_WEP40;
651 else if (ext->key_len == 13)
652 cipher = WLAN_CIPHER_SUITE_WEP104;
653 else
654 return -EINVAL;
655 break;
656 case IW_ENCODE_ALG_TKIP:
657 cipher = WLAN_CIPHER_SUITE_TKIP;
658 break;
659 case IW_ENCODE_ALG_CCMP:
660 cipher = WLAN_CIPHER_SUITE_CCMP;
661 break;
662 case IW_ENCODE_ALG_AES_CMAC:
663 cipher = WLAN_CIPHER_SUITE_AES_CMAC;
664 break;
665 default:
666 return -EOPNOTSUPP;
667 }
668
669 if (erq->flags & IW_ENCODE_DISABLED)
670 remove = true;
671
672 idx = erq->flags & IW_ENCODE_INDEX;
673 if (cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
674 if (idx < 4 || idx > 5) {
675 idx = wdev->wext.default_mgmt_key;
676 if (idx < 0)
677 return -EINVAL;
678 } else
679 idx--;
680 } else {
681 if (idx < 1 || idx > 4) {
682 idx = wdev->wext.default_key;
683 if (idx < 0)
684 return -EINVAL;
685 } else
686 idx--;
687 }
688
689 addr = ext->addr.sa_data;
690 if (is_broadcast_ether_addr(addr))
691 addr = NULL;
692
693 memset(&params, 0, sizeof(params));
694 params.key = ext->key;
695 params.key_len = ext->key_len;
696 params.cipher = cipher;
697
Jouni Malinenfaa8fdc2009-05-11 21:57:58 +0300698 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
699 params.seq = ext->rx_seq;
700 params.seq_len = 6;
701 }
702
Johannes Berg08645122009-05-11 13:54:58 +0200703 return cfg80211_set_encryption(
Johannes Berge31b8212010-10-05 19:39:30 +0200704 rdev, dev,
705 !(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY),
706 addr, remove,
Johannes Berg08645122009-05-11 13:54:58 +0200707 ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
708 idx, &params);
709}
Johannes Berg08645122009-05-11 13:54:58 +0200710
Johannes Berg04b0c5c2011-07-15 13:01:38 +0200711static int cfg80211_wext_giwencode(struct net_device *dev,
712 struct iw_request_info *info,
713 struct iw_point *erq, char *keybuf)
Johannes Berg08645122009-05-11 13:54:58 +0200714{
715 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergfffd0932009-07-08 14:22:54 +0200716 int idx;
Johannes Berg08645122009-05-11 13:54:58 +0200717
Johannes Bergfffd0932009-07-08 14:22:54 +0200718 if (wdev->iftype != NL80211_IFTYPE_STATION &&
719 wdev->iftype != NL80211_IFTYPE_ADHOC)
Johannes Berg08645122009-05-11 13:54:58 +0200720 return -EOPNOTSUPP;
721
722 idx = erq->flags & IW_ENCODE_INDEX;
723 if (idx == 0) {
724 idx = wdev->wext.default_key;
725 if (idx < 0)
726 idx = 0;
727 } else if (idx < 1 || idx > 4)
728 return -EINVAL;
729 else
730 idx--;
731
732 erq->flags = idx + 1;
733
Johannes Bergfffd0932009-07-08 14:22:54 +0200734 if (!wdev->wext.keys || !wdev->wext.keys->params[idx].cipher) {
Johannes Berg08645122009-05-11 13:54:58 +0200735 erq->flags |= IW_ENCODE_DISABLED;
736 erq->length = 0;
737 return 0;
738 }
739
Johannes Bergfffd0932009-07-08 14:22:54 +0200740 erq->length = min_t(size_t, erq->length,
741 wdev->wext.keys->params[idx].key_len);
742 memcpy(keybuf, wdev->wext.keys->params[idx].key, erq->length);
743 erq->flags |= IW_ENCODE_ENABLED;
744
745 return 0;
Johannes Berg08645122009-05-11 13:54:58 +0200746}
Johannes Berg7643a2c2009-06-02 13:01:39 +0200747
Johannes Berg04b0c5c2011-07-15 13:01:38 +0200748static int cfg80211_wext_siwfreq(struct net_device *dev,
749 struct iw_request_info *info,
750 struct iw_freq *wextfreq, char *extra)
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200751{
752 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800753 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg683b6d32012-11-08 21:25:48 +0100754 struct cfg80211_chan_def chandef = {
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100755 .width = NL80211_CHAN_WIDTH_20_NOHT,
Johannes Berg683b6d32012-11-08 21:25:48 +0100756 };
Johannes Berg5fe231e2013-05-08 21:45:15 +0200757 int freq;
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200758
759 switch (wdev->iftype) {
760 case NL80211_IFTYPE_STATION:
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200761 return cfg80211_mgd_wext_siwfreq(dev, info, wextfreq, extra);
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200762 case NL80211_IFTYPE_ADHOC:
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200763 return cfg80211_ibss_wext_siwfreq(dev, info, wextfreq, extra);
Johannes Bergf444de02010-05-05 15:25:02 +0200764 case NL80211_IFTYPE_MONITOR:
Zhao, Gang96998e32014-04-09 09:28:06 +0800765 freq = cfg80211_wext_freq(wextfreq);
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200766 if (freq < 0)
767 return freq;
768 if (freq == 0)
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200769 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100770 chandef.center_freq1 = freq;
Johannes Berg683b6d32012-11-08 21:25:48 +0100771 chandef.chan = ieee80211_get_channel(&rdev->wiphy, freq);
772 if (!chandef.chan)
773 return -EINVAL;
Johannes Berg5fe231e2013-05-08 21:45:15 +0200774 return cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +0200775 case NL80211_IFTYPE_MESH_POINT:
Zhao, Gang96998e32014-04-09 09:28:06 +0800776 freq = cfg80211_wext_freq(wextfreq);
Johannes Bergcc1d2802012-05-16 23:50:20 +0200777 if (freq < 0)
778 return freq;
779 if (freq == 0)
780 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100781 chandef.center_freq1 = freq;
Johannes Berg683b6d32012-11-08 21:25:48 +0100782 chandef.chan = ieee80211_get_channel(&rdev->wiphy, freq);
783 if (!chandef.chan)
784 return -EINVAL;
Johannes Berg5fe231e2013-05-08 21:45:15 +0200785 return cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergf444de02010-05-05 15:25:02 +0200786 default:
787 return -EOPNOTSUPP;
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200788 }
789}
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200790
Johannes Berg04b0c5c2011-07-15 13:01:38 +0200791static int cfg80211_wext_giwfreq(struct net_device *dev,
792 struct iw_request_info *info,
793 struct iw_freq *freq, char *extra)
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200794{
795 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800796 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergf43e5212019-09-23 13:51:16 +0200797 struct cfg80211_chan_def chandef = {};
Johannes Berg683b6d32012-11-08 21:25:48 +0100798 int ret;
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200799
800 switch (wdev->iftype) {
801 case NL80211_IFTYPE_STATION:
802 return cfg80211_mgd_wext_giwfreq(dev, info, freq, extra);
803 case NL80211_IFTYPE_ADHOC:
804 return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra);
Johannes Berge9998822011-11-09 10:30:21 +0100805 case NL80211_IFTYPE_MONITOR:
Johannes Berg5b7ccaf2012-07-12 19:45:08 +0200806 if (!rdev->ops->get_channel)
Johannes Berge9998822011-11-09 10:30:21 +0100807 return -EINVAL;
808
Johannes Berg683b6d32012-11-08 21:25:48 +0100809 ret = rdev_get_channel(rdev, wdev, &chandef);
810 if (ret)
811 return ret;
812 freq->m = chandef.chan->center_freq;
Johannes Berge9998822011-11-09 10:30:21 +0100813 freq->e = 6;
814 return 0;
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200815 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +0200816 return -EINVAL;
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200817 }
818}
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200819
Johannes Berg04b0c5c2011-07-15 13:01:38 +0200820static int cfg80211_wext_siwtxpower(struct net_device *dev,
821 struct iw_request_info *info,
822 union iwreq_data *data, char *extra)
Johannes Berg7643a2c2009-06-02 13:01:39 +0200823{
824 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800825 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +0300826 enum nl80211_tx_power_setting type;
Johannes Berg7643a2c2009-06-02 13:01:39 +0200827 int dbm = 0;
828
829 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
830 return -EINVAL;
831 if (data->txpower.flags & IW_TXPOW_RANGE)
832 return -EINVAL;
833
834 if (!rdev->ops->set_tx_power)
835 return -EOPNOTSUPP;
836
837 /* only change when not disabling */
838 if (!data->txpower.disabled) {
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200839 rfkill_set_sw_state(rdev->rfkill, false);
840
Johannes Berg7643a2c2009-06-02 13:01:39 +0200841 if (data->txpower.fixed) {
842 /*
843 * wext doesn't support negative values, see
844 * below where it's for automatic
845 */
846 if (data->txpower.value < 0)
847 return -EINVAL;
848 dbm = data->txpower.value;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +0300849 type = NL80211_TX_POWER_FIXED;
Johannes Berg7643a2c2009-06-02 13:01:39 +0200850 /* TODO: do regulatory check! */
851 } else {
852 /*
853 * Automatic power level setting, max being the value
854 * passed in from userland.
855 */
856 if (data->txpower.value < 0) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +0300857 type = NL80211_TX_POWER_AUTOMATIC;
Johannes Berg7643a2c2009-06-02 13:01:39 +0200858 } else {
859 dbm = data->txpower.value;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +0300860 type = NL80211_TX_POWER_LIMITED;
Johannes Berg7643a2c2009-06-02 13:01:39 +0200861 }
862 }
863 } else {
Johannes Berg3cfe91c2019-08-30 14:24:44 +0300864 if (rfkill_set_sw_state(rdev->rfkill, true))
865 schedule_work(&rdev->rfkill_block);
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200866 return 0;
Johannes Berg7643a2c2009-06-02 13:01:39 +0200867 }
868
Johannes Bergc8442112012-10-24 10:17:18 +0200869 return rdev_set_tx_power(rdev, wdev, type, DBM_TO_MBM(dbm));
Johannes Berg7643a2c2009-06-02 13:01:39 +0200870}
Johannes Berg7643a2c2009-06-02 13:01:39 +0200871
Johannes Berg04b0c5c2011-07-15 13:01:38 +0200872static int cfg80211_wext_giwtxpower(struct net_device *dev,
873 struct iw_request_info *info,
874 union iwreq_data *data, char *extra)
Johannes Berg7643a2c2009-06-02 13:01:39 +0200875{
876 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800877 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7643a2c2009-06-02 13:01:39 +0200878 int err, val;
879
880 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
881 return -EINVAL;
882 if (data->txpower.flags & IW_TXPOW_RANGE)
883 return -EINVAL;
884
885 if (!rdev->ops->get_tx_power)
886 return -EOPNOTSUPP;
887
Johannes Bergc8442112012-10-24 10:17:18 +0200888 err = rdev_get_tx_power(rdev, wdev, &val);
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200889 if (err)
Johannes Berg7643a2c2009-06-02 13:01:39 +0200890 return err;
891
892 /* well... oh well */
893 data->txpower.fixed = 1;
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200894 data->txpower.disabled = rfkill_blocked(rdev->rfkill);
Johannes Berg7643a2c2009-06-02 13:01:39 +0200895 data->txpower.value = val;
896 data->txpower.flags = IW_TXPOW_DBM;
897
898 return 0;
899}
Johannes Bergf2129352009-07-01 21:26:56 +0200900
901static int cfg80211_set_auth_alg(struct wireless_dev *wdev,
902 s32 auth_alg)
903{
904 int nr_alg = 0;
905
906 if (!auth_alg)
907 return -EINVAL;
908
909 if (auth_alg & ~(IW_AUTH_ALG_OPEN_SYSTEM |
910 IW_AUTH_ALG_SHARED_KEY |
911 IW_AUTH_ALG_LEAP))
912 return -EINVAL;
913
914 if (auth_alg & IW_AUTH_ALG_OPEN_SYSTEM) {
915 nr_alg++;
916 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
917 }
918
919 if (auth_alg & IW_AUTH_ALG_SHARED_KEY) {
920 nr_alg++;
921 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_SHARED_KEY;
922 }
923
924 if (auth_alg & IW_AUTH_ALG_LEAP) {
925 nr_alg++;
926 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_NETWORK_EAP;
927 }
928
929 if (nr_alg > 1)
930 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
931
932 return 0;
933}
934
935static int cfg80211_set_wpa_version(struct wireless_dev *wdev, u32 wpa_versions)
936{
Johannes Bergf2129352009-07-01 21:26:56 +0200937 if (wpa_versions & ~(IW_AUTH_WPA_VERSION_WPA |
Gábor Stefanik323d5662009-07-12 02:03:48 +0200938 IW_AUTH_WPA_VERSION_WPA2|
939 IW_AUTH_WPA_VERSION_DISABLED))
Johannes Bergf2129352009-07-01 21:26:56 +0200940 return -EINVAL;
941
Gábor Stefanik323d5662009-07-12 02:03:48 +0200942 if ((wpa_versions & IW_AUTH_WPA_VERSION_DISABLED) &&
943 (wpa_versions & (IW_AUTH_WPA_VERSION_WPA|
944 IW_AUTH_WPA_VERSION_WPA2)))
945 return -EINVAL;
946
947 if (wpa_versions & IW_AUTH_WPA_VERSION_DISABLED)
948 wdev->wext.connect.crypto.wpa_versions &=
949 ~(NL80211_WPA_VERSION_1|NL80211_WPA_VERSION_2);
950
Johannes Bergf2129352009-07-01 21:26:56 +0200951 if (wpa_versions & IW_AUTH_WPA_VERSION_WPA)
952 wdev->wext.connect.crypto.wpa_versions |=
953 NL80211_WPA_VERSION_1;
954
955 if (wpa_versions & IW_AUTH_WPA_VERSION_WPA2)
956 wdev->wext.connect.crypto.wpa_versions |=
957 NL80211_WPA_VERSION_2;
958
959 return 0;
960}
961
Johannes Berg4f5dadc2009-07-07 03:56:10 +0200962static int cfg80211_set_cipher_group(struct wireless_dev *wdev, u32 cipher)
Johannes Bergf2129352009-07-01 21:26:56 +0200963{
Johannes Bergf2129352009-07-01 21:26:56 +0200964 if (cipher & IW_AUTH_CIPHER_WEP40)
965 wdev->wext.connect.crypto.cipher_group =
966 WLAN_CIPHER_SUITE_WEP40;
967 else if (cipher & IW_AUTH_CIPHER_WEP104)
968 wdev->wext.connect.crypto.cipher_group =
969 WLAN_CIPHER_SUITE_WEP104;
970 else if (cipher & IW_AUTH_CIPHER_TKIP)
971 wdev->wext.connect.crypto.cipher_group =
972 WLAN_CIPHER_SUITE_TKIP;
973 else if (cipher & IW_AUTH_CIPHER_CCMP)
974 wdev->wext.connect.crypto.cipher_group =
975 WLAN_CIPHER_SUITE_CCMP;
976 else if (cipher & IW_AUTH_CIPHER_AES_CMAC)
977 wdev->wext.connect.crypto.cipher_group =
978 WLAN_CIPHER_SUITE_AES_CMAC;
Jouni Malinenc5f82892009-11-01 11:18:49 +0200979 else if (cipher & IW_AUTH_CIPHER_NONE)
980 wdev->wext.connect.crypto.cipher_group = 0;
Johannes Bergf2129352009-07-01 21:26:56 +0200981 else
982 return -EINVAL;
983
984 return 0;
985}
986
Johannes Berg4f5dadc2009-07-07 03:56:10 +0200987static int cfg80211_set_cipher_pairwise(struct wireless_dev *wdev, u32 cipher)
Johannes Bergf2129352009-07-01 21:26:56 +0200988{
989 int nr_ciphers = 0;
990 u32 *ciphers_pairwise = wdev->wext.connect.crypto.ciphers_pairwise;
991
992 if (cipher & IW_AUTH_CIPHER_WEP40) {
993 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP40;
994 nr_ciphers++;
995 }
996
997 if (cipher & IW_AUTH_CIPHER_WEP104) {
998 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP104;
999 nr_ciphers++;
1000 }
1001
1002 if (cipher & IW_AUTH_CIPHER_TKIP) {
1003 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_TKIP;
1004 nr_ciphers++;
1005 }
1006
1007 if (cipher & IW_AUTH_CIPHER_CCMP) {
1008 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_CCMP;
1009 nr_ciphers++;
1010 }
1011
1012 if (cipher & IW_AUTH_CIPHER_AES_CMAC) {
1013 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_AES_CMAC;
1014 nr_ciphers++;
1015 }
1016
1017 BUILD_BUG_ON(NL80211_MAX_NR_CIPHER_SUITES < 5);
1018
1019 wdev->wext.connect.crypto.n_ciphers_pairwise = nr_ciphers;
1020
1021 return 0;
1022}
1023
1024
Johannes Berg4f5dadc2009-07-07 03:56:10 +02001025static int cfg80211_set_key_mgt(struct wireless_dev *wdev, u32 key_mgt)
Johannes Bergf2129352009-07-01 21:26:56 +02001026{
1027 int nr_akm_suites = 0;
1028
1029 if (key_mgt & ~(IW_AUTH_KEY_MGMT_802_1X |
1030 IW_AUTH_KEY_MGMT_PSK))
1031 return -EINVAL;
1032
1033 if (key_mgt & IW_AUTH_KEY_MGMT_802_1X) {
1034 wdev->wext.connect.crypto.akm_suites[nr_akm_suites] =
1035 WLAN_AKM_SUITE_8021X;
1036 nr_akm_suites++;
1037 }
1038
1039 if (key_mgt & IW_AUTH_KEY_MGMT_PSK) {
1040 wdev->wext.connect.crypto.akm_suites[nr_akm_suites] =
1041 WLAN_AKM_SUITE_PSK;
1042 nr_akm_suites++;
1043 }
1044
1045 wdev->wext.connect.crypto.n_akm_suites = nr_akm_suites;
1046
1047 return 0;
1048}
1049
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001050static int cfg80211_wext_siwauth(struct net_device *dev,
1051 struct iw_request_info *info,
1052 struct iw_param *data, char *extra)
Johannes Bergf2129352009-07-01 21:26:56 +02001053{
1054 struct wireless_dev *wdev = dev->ieee80211_ptr;
1055
1056 if (wdev->iftype != NL80211_IFTYPE_STATION)
1057 return -EOPNOTSUPP;
1058
1059 switch (data->flags & IW_AUTH_INDEX) {
1060 case IW_AUTH_PRIVACY_INVOKED:
1061 wdev->wext.connect.privacy = data->value;
1062 return 0;
1063 case IW_AUTH_WPA_VERSION:
1064 return cfg80211_set_wpa_version(wdev, data->value);
1065 case IW_AUTH_CIPHER_GROUP:
1066 return cfg80211_set_cipher_group(wdev, data->value);
1067 case IW_AUTH_KEY_MGMT:
1068 return cfg80211_set_key_mgt(wdev, data->value);
1069 case IW_AUTH_CIPHER_PAIRWISE:
1070 return cfg80211_set_cipher_pairwise(wdev, data->value);
1071 case IW_AUTH_80211_AUTH_ALG:
1072 return cfg80211_set_auth_alg(wdev, data->value);
1073 case IW_AUTH_WPA_ENABLED:
1074 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1075 case IW_AUTH_DROP_UNENCRYPTED:
1076 case IW_AUTH_MFP:
1077 return 0;
1078 default:
1079 return -EOPNOTSUPP;
1080 }
1081}
Johannes Bergf2129352009-07-01 21:26:56 +02001082
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001083static int cfg80211_wext_giwauth(struct net_device *dev,
1084 struct iw_request_info *info,
1085 struct iw_param *data, char *extra)
Johannes Bergf2129352009-07-01 21:26:56 +02001086{
1087 /* XXX: what do we need? */
1088
1089 return -EOPNOTSUPP;
1090}
Johannes Bergbc92afd2009-07-01 21:26:57 +02001091
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001092static int cfg80211_wext_siwpower(struct net_device *dev,
1093 struct iw_request_info *info,
1094 struct iw_param *wrq, char *extra)
Johannes Bergbc92afd2009-07-01 21:26:57 +02001095{
1096 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001097 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Kalle Valoffb9eb32010-02-17 17:58:10 +02001098 bool ps = wdev->ps;
1099 int timeout = wdev->ps_timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02001100 int err;
1101
1102 if (wdev->iftype != NL80211_IFTYPE_STATION)
1103 return -EINVAL;
1104
1105 if (!rdev->ops->set_power_mgmt)
1106 return -EOPNOTSUPP;
1107
1108 if (wrq->disabled) {
1109 ps = false;
1110 } else {
1111 switch (wrq->flags & IW_POWER_MODE) {
1112 case IW_POWER_ON: /* If not specified */
1113 case IW_POWER_MODE: /* If set all mask */
1114 case IW_POWER_ALL_R: /* If explicitely state all */
1115 ps = true;
1116 break;
1117 default: /* Otherwise we ignore */
1118 return -EINVAL;
1119 }
1120
1121 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
1122 return -EINVAL;
1123
1124 if (wrq->flags & IW_POWER_TIMEOUT)
1125 timeout = wrq->value / 1000;
1126 }
1127
Hila Gonene35e4d22012-06-27 17:19:42 +03001128 err = rdev_set_power_mgmt(rdev, dev, ps, timeout);
Johannes Bergbc92afd2009-07-01 21:26:57 +02001129 if (err)
1130 return err;
1131
Kalle Valoffb9eb32010-02-17 17:58:10 +02001132 wdev->ps = ps;
1133 wdev->ps_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02001134
1135 return 0;
1136
1137}
Johannes Bergbc92afd2009-07-01 21:26:57 +02001138
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001139static int cfg80211_wext_giwpower(struct net_device *dev,
1140 struct iw_request_info *info,
1141 struct iw_param *wrq, char *extra)
Johannes Bergbc92afd2009-07-01 21:26:57 +02001142{
1143 struct wireless_dev *wdev = dev->ieee80211_ptr;
1144
Kalle Valoffb9eb32010-02-17 17:58:10 +02001145 wrq->disabled = !wdev->ps;
Johannes Bergbc92afd2009-07-01 21:26:57 +02001146
1147 return 0;
1148}
Johannes Bergab737a42009-07-01 21:26:58 +02001149
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001150static int cfg80211_wext_siwrate(struct net_device *dev,
1151 struct iw_request_info *info,
1152 struct iw_param *rate, char *extra)
Johannes Berg99303802009-07-01 21:26:59 +02001153{
1154 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001155 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg99303802009-07-01 21:26:59 +02001156 struct cfg80211_bitrate_mask mask;
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001157 u32 fixed, maxrate;
1158 struct ieee80211_supported_band *sband;
1159 int band, ridx;
1160 bool match = false;
Johannes Berg99303802009-07-01 21:26:59 +02001161
1162 if (!rdev->ops->set_bitrate_mask)
1163 return -EOPNOTSUPP;
1164
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001165 memset(&mask, 0, sizeof(mask));
1166 fixed = 0;
John W. Linville54233262010-01-27 09:44:48 -05001167 maxrate = (u32)-1;
Johannes Berg99303802009-07-01 21:26:59 +02001168
1169 if (rate->value < 0) {
1170 /* nothing */
1171 } else if (rate->fixed) {
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001172 fixed = rate->value / 100000;
Johannes Berg99303802009-07-01 21:26:59 +02001173 } else {
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001174 maxrate = rate->value / 100000;
Johannes Berg99303802009-07-01 21:26:59 +02001175 }
1176
Johannes Berg57fbcce2016-04-12 15:56:15 +02001177 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001178 sband = wdev->wiphy->bands[band];
1179 if (sband == NULL)
1180 continue;
1181 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
1182 struct ieee80211_rate *srate = &sband->bitrates[ridx];
1183 if (fixed == srate->bitrate) {
1184 mask.control[band].legacy = 1 << ridx;
1185 match = true;
1186 break;
1187 }
1188 if (srate->bitrate <= maxrate) {
1189 mask.control[band].legacy |= 1 << ridx;
1190 match = true;
1191 }
1192 }
1193 }
1194
1195 if (!match)
1196 return -EINVAL;
1197
Hila Gonene35e4d22012-06-27 17:19:42 +03001198 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Johannes Berg99303802009-07-01 21:26:59 +02001199}
Johannes Berg99303802009-07-01 21:26:59 +02001200
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001201static int cfg80211_wext_giwrate(struct net_device *dev,
1202 struct iw_request_info *info,
1203 struct iw_param *rate, char *extra)
Johannes Berg99303802009-07-01 21:26:59 +02001204{
1205 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001206 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg5762d7d2018-01-16 23:20:22 +01001207 struct station_info sinfo = {};
Johannes Berga71d62d2009-07-07 23:41:27 +02001208 u8 addr[ETH_ALEN];
Johannes Berg99303802009-07-01 21:26:59 +02001209 int err;
1210
1211 if (wdev->iftype != NL80211_IFTYPE_STATION)
1212 return -EOPNOTSUPP;
1213
1214 if (!rdev->ops->get_station)
1215 return -EOPNOTSUPP;
1216
Johannes Berga71d62d2009-07-07 23:41:27 +02001217 err = 0;
1218 wdev_lock(wdev);
Samuel Ortiz6c230c02009-07-03 02:00:48 +02001219 if (wdev->current_bss)
Johannes Berga71d62d2009-07-07 23:41:27 +02001220 memcpy(addr, wdev->current_bss->pub.bssid, ETH_ALEN);
Samuel Ortiz6c230c02009-07-03 02:00:48 +02001221 else
Johannes Berga71d62d2009-07-07 23:41:27 +02001222 err = -EOPNOTSUPP;
1223 wdev_unlock(wdev);
1224 if (err)
1225 return err;
Johannes Berg99303802009-07-01 21:26:59 +02001226
Hila Gonene35e4d22012-06-27 17:19:42 +03001227 err = rdev_get_station(rdev, dev, addr, &sinfo);
Johannes Berg99303802009-07-01 21:26:59 +02001228 if (err)
1229 return err;
1230
Stefan Seyfried848e6162018-09-30 12:53:00 +02001231 if (!(sinfo.filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE))) {
1232 err = -EOPNOTSUPP;
1233 goto free;
1234 }
Johannes Berg99303802009-07-01 21:26:59 +02001235
John W. Linville254416a2009-12-09 16:43:52 -05001236 rate->value = 100000 * cfg80211_calculate_bitrate(&sinfo.txrate);
Johannes Berg99303802009-07-01 21:26:59 +02001237
Stefan Seyfried848e6162018-09-30 12:53:00 +02001238free:
1239 cfg80211_sinfo_release_content(&sinfo);
1240 return err;
Johannes Berg99303802009-07-01 21:26:59 +02001241}
Johannes Berg89906462009-07-01 21:27:00 +02001242
1243/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001244static struct iw_statistics *cfg80211_wireless_stats(struct net_device *dev)
Johannes Berg89906462009-07-01 21:27:00 +02001245{
1246 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001247 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89906462009-07-01 21:27:00 +02001248 /* we are under RTNL - globally locked - so can use static structs */
1249 static struct iw_statistics wstats;
Stefan Seyfried848e6162018-09-30 12:53:00 +02001250 static struct station_info sinfo = {};
Johannes Bergc56c5712009-07-10 16:54:07 +02001251 u8 bssid[ETH_ALEN];
Johannes Berg89906462009-07-01 21:27:00 +02001252
1253 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION)
1254 return NULL;
1255
1256 if (!rdev->ops->get_station)
1257 return NULL;
1258
Johannes Bergc56c5712009-07-10 16:54:07 +02001259 /* Grab BSSID of current BSS, if any */
1260 wdev_lock(wdev);
1261 if (!wdev->current_bss) {
1262 wdev_unlock(wdev);
Johannes Berg89906462009-07-01 21:27:00 +02001263 return NULL;
Johannes Bergc56c5712009-07-10 16:54:07 +02001264 }
1265 memcpy(bssid, wdev->current_bss->pub.bssid, ETH_ALEN);
1266 wdev_unlock(wdev);
Johannes Berg89906462009-07-01 21:27:00 +02001267
Johannes Berg9c5a18a2015-06-09 21:35:44 +02001268 memset(&sinfo, 0, sizeof(sinfo));
1269
Hila Gonene35e4d22012-06-27 17:19:42 +03001270 if (rdev_get_station(rdev, dev, bssid, &sinfo))
Johannes Berg89906462009-07-01 21:27:00 +02001271 return NULL;
1272
1273 memset(&wstats, 0, sizeof(wstats));
1274
1275 switch (rdev->wiphy.signal_type) {
1276 case CFG80211_SIGNAL_TYPE_MBM:
Omer Efrat397c6572018-06-17 13:06:14 +03001277 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_SIGNAL)) {
Johannes Berg89906462009-07-01 21:27:00 +02001278 int sig = sinfo.signal;
1279 wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
1280 wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
1281 wstats.qual.updated |= IW_QUAL_DBM;
1282 wstats.qual.level = sig;
1283 if (sig < -110)
1284 sig = -110;
1285 else if (sig > -40)
1286 sig = -40;
1287 wstats.qual.qual = sig + 110;
1288 break;
1289 }
Miaohe Lin7b506ff2020-08-22 04:23:23 -04001290 fallthrough;
Johannes Berg89906462009-07-01 21:27:00 +02001291 case CFG80211_SIGNAL_TYPE_UNSPEC:
Omer Efrat397c6572018-06-17 13:06:14 +03001292 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_SIGNAL)) {
Johannes Berg89906462009-07-01 21:27:00 +02001293 wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
1294 wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
1295 wstats.qual.level = sinfo.signal;
1296 wstats.qual.qual = sinfo.signal;
1297 break;
1298 }
Miaohe Lin7b506ff2020-08-22 04:23:23 -04001299 fallthrough;
Johannes Berg89906462009-07-01 21:27:00 +02001300 default:
1301 wstats.qual.updated |= IW_QUAL_LEVEL_INVALID;
1302 wstats.qual.updated |= IW_QUAL_QUAL_INVALID;
1303 }
1304
1305 wstats.qual.updated |= IW_QUAL_NOISE_INVALID;
Omer Efrat397c6572018-06-17 13:06:14 +03001306 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_RX_DROP_MISC))
Ben Greear5a5c7312010-10-07 16:39:20 -07001307 wstats.discard.misc = sinfo.rx_dropped_misc;
Omer Efrat397c6572018-06-17 13:06:14 +03001308 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_TX_FAILED))
Ben Greear5a5c7312010-10-07 16:39:20 -07001309 wstats.discard.retries = sinfo.tx_failed;
Johannes Berg89906462009-07-01 21:27:00 +02001310
Stefan Seyfried848e6162018-09-30 12:53:00 +02001311 cfg80211_sinfo_release_content(&sinfo);
1312
Johannes Berg89906462009-07-01 21:27:00 +02001313 return &wstats;
1314}
Johannes Berg562e4822009-07-27 12:01:51 +02001315
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001316static int cfg80211_wext_siwap(struct net_device *dev,
1317 struct iw_request_info *info,
1318 struct sockaddr *ap_addr, char *extra)
Johannes Berg562e4822009-07-27 12:01:51 +02001319{
1320 struct wireless_dev *wdev = dev->ieee80211_ptr;
1321
1322 switch (wdev->iftype) {
1323 case NL80211_IFTYPE_ADHOC:
1324 return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra);
1325 case NL80211_IFTYPE_STATION:
1326 return cfg80211_mgd_wext_siwap(dev, info, ap_addr, extra);
Johannes Berg562e4822009-07-27 12:01:51 +02001327 default:
1328 return -EOPNOTSUPP;
1329 }
1330}
Johannes Berg562e4822009-07-27 12:01:51 +02001331
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001332static int cfg80211_wext_giwap(struct net_device *dev,
1333 struct iw_request_info *info,
1334 struct sockaddr *ap_addr, char *extra)
Johannes Berg562e4822009-07-27 12:01:51 +02001335{
1336 struct wireless_dev *wdev = dev->ieee80211_ptr;
1337
1338 switch (wdev->iftype) {
1339 case NL80211_IFTYPE_ADHOC:
1340 return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra);
1341 case NL80211_IFTYPE_STATION:
1342 return cfg80211_mgd_wext_giwap(dev, info, ap_addr, extra);
Johannes Berg562e4822009-07-27 12:01:51 +02001343 default:
1344 return -EOPNOTSUPP;
1345 }
1346}
Johannes Berg1f9298f2009-07-27 12:01:52 +02001347
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001348static int cfg80211_wext_siwessid(struct net_device *dev,
1349 struct iw_request_info *info,
1350 struct iw_point *data, char *ssid)
Johannes Berg1f9298f2009-07-27 12:01:52 +02001351{
1352 struct wireless_dev *wdev = dev->ieee80211_ptr;
1353
1354 switch (wdev->iftype) {
1355 case NL80211_IFTYPE_ADHOC:
1356 return cfg80211_ibss_wext_siwessid(dev, info, data, ssid);
1357 case NL80211_IFTYPE_STATION:
1358 return cfg80211_mgd_wext_siwessid(dev, info, data, ssid);
1359 default:
1360 return -EOPNOTSUPP;
1361 }
1362}
Johannes Berg1f9298f2009-07-27 12:01:52 +02001363
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001364static int cfg80211_wext_giwessid(struct net_device *dev,
1365 struct iw_request_info *info,
1366 struct iw_point *data, char *ssid)
Johannes Berg1f9298f2009-07-27 12:01:52 +02001367{
1368 struct wireless_dev *wdev = dev->ieee80211_ptr;
1369
Johannes Berg42da2f92010-08-30 12:24:54 +02001370 data->flags = 0;
1371 data->length = 0;
1372
Johannes Berg1f9298f2009-07-27 12:01:52 +02001373 switch (wdev->iftype) {
1374 case NL80211_IFTYPE_ADHOC:
1375 return cfg80211_ibss_wext_giwessid(dev, info, data, ssid);
1376 case NL80211_IFTYPE_STATION:
1377 return cfg80211_mgd_wext_giwessid(dev, info, data, ssid);
1378 default:
1379 return -EOPNOTSUPP;
1380 }
1381}
Johannes Berga9a11622009-07-27 12:01:53 +02001382
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001383static int cfg80211_wext_siwpmksa(struct net_device *dev,
1384 struct iw_request_info *info,
1385 struct iw_point *data, char *extra)
Samuel Ortiz2944b2c2009-11-25 00:01:01 +01001386{
1387 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001388 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Samuel Ortiz2944b2c2009-11-25 00:01:01 +01001389 struct cfg80211_pmksa cfg_pmksa;
1390 struct iw_pmksa *pmksa = (struct iw_pmksa *)extra;
1391
1392 memset(&cfg_pmksa, 0, sizeof(struct cfg80211_pmksa));
1393
1394 if (wdev->iftype != NL80211_IFTYPE_STATION)
1395 return -EINVAL;
1396
1397 cfg_pmksa.bssid = pmksa->bssid.sa_data;
1398 cfg_pmksa.pmkid = pmksa->pmkid;
1399
1400 switch (pmksa->cmd) {
1401 case IW_PMKSA_ADD:
1402 if (!rdev->ops->set_pmksa)
1403 return -EOPNOTSUPP;
1404
Hila Gonene35e4d22012-06-27 17:19:42 +03001405 return rdev_set_pmksa(rdev, dev, &cfg_pmksa);
Samuel Ortiz2944b2c2009-11-25 00:01:01 +01001406
1407 case IW_PMKSA_REMOVE:
1408 if (!rdev->ops->del_pmksa)
1409 return -EOPNOTSUPP;
1410
Hila Gonene35e4d22012-06-27 17:19:42 +03001411 return rdev_del_pmksa(rdev, dev, &cfg_pmksa);
Samuel Ortiz2944b2c2009-11-25 00:01:01 +01001412
1413 case IW_PMKSA_FLUSH:
1414 if (!rdev->ops->flush_pmksa)
1415 return -EOPNOTSUPP;
1416
Hila Gonene35e4d22012-06-27 17:19:42 +03001417 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz2944b2c2009-11-25 00:01:01 +01001418
1419 default:
1420 return -EOPNOTSUPP;
1421 }
1422}
1423
Sami Tolvanen32fc4a92020-11-17 12:59:02 -08001424#define DEFINE_WEXT_COMPAT_STUB(func, type) \
1425 static int __ ## func(struct net_device *dev, \
1426 struct iw_request_info *info, \
1427 union iwreq_data *wrqu, \
1428 char *extra) \
1429 { \
1430 return func(dev, info, (type *)wrqu, extra); \
1431 }
1432
1433DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_giwname, char)
1434DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_siwfreq, struct iw_freq)
1435DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_giwfreq, struct iw_freq)
1436DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_siwmode, u32)
1437DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_giwmode, u32)
1438DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_giwrange, struct iw_point)
1439DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_siwap, struct sockaddr)
1440DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_giwap, struct sockaddr)
1441DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_siwmlme, struct iw_point)
1442DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_giwscan, struct iw_point)
1443DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_siwessid, struct iw_point)
1444DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_giwessid, struct iw_point)
1445DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_siwrate, struct iw_param)
1446DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_giwrate, struct iw_param)
1447DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_siwrts, struct iw_param)
1448DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_giwrts, struct iw_param)
1449DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_siwfrag, struct iw_param)
1450DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_giwfrag, struct iw_param)
1451DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_siwretry, struct iw_param)
1452DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_giwretry, struct iw_param)
1453DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_siwencode, struct iw_point)
1454DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_giwencode, struct iw_point)
1455DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_giwpower, struct iw_param)
1456DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_siwpower, struct iw_param)
1457DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_siwgenie, struct iw_point)
1458DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_giwauth, struct iw_param)
1459DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_siwauth, struct iw_param)
1460DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_siwencodeext, struct iw_point)
1461DEFINE_WEXT_COMPAT_STUB(cfg80211_wext_siwpmksa, struct iw_point)
1462
Johannes Berga9a11622009-07-27 12:01:53 +02001463static const iw_handler cfg80211_handlers[] = {
Sami Tolvanen32fc4a92020-11-17 12:59:02 -08001464 [IW_IOCTL_IDX(SIOCGIWNAME)] = __cfg80211_wext_giwname,
1465 [IW_IOCTL_IDX(SIOCSIWFREQ)] = __cfg80211_wext_siwfreq,
1466 [IW_IOCTL_IDX(SIOCGIWFREQ)] = __cfg80211_wext_giwfreq,
1467 [IW_IOCTL_IDX(SIOCSIWMODE)] = __cfg80211_wext_siwmode,
1468 [IW_IOCTL_IDX(SIOCGIWMODE)] = __cfg80211_wext_giwmode,
1469 [IW_IOCTL_IDX(SIOCGIWRANGE)] = __cfg80211_wext_giwrange,
1470 [IW_IOCTL_IDX(SIOCSIWAP)] = __cfg80211_wext_siwap,
1471 [IW_IOCTL_IDX(SIOCGIWAP)] = __cfg80211_wext_giwap,
1472 [IW_IOCTL_IDX(SIOCSIWMLME)] = __cfg80211_wext_siwmlme,
1473 [IW_IOCTL_IDX(SIOCSIWSCAN)] = cfg80211_wext_siwscan,
1474 [IW_IOCTL_IDX(SIOCGIWSCAN)] = __cfg80211_wext_giwscan,
1475 [IW_IOCTL_IDX(SIOCSIWESSID)] = __cfg80211_wext_siwessid,
1476 [IW_IOCTL_IDX(SIOCGIWESSID)] = __cfg80211_wext_giwessid,
1477 [IW_IOCTL_IDX(SIOCSIWRATE)] = __cfg80211_wext_siwrate,
1478 [IW_IOCTL_IDX(SIOCGIWRATE)] = __cfg80211_wext_giwrate,
1479 [IW_IOCTL_IDX(SIOCSIWRTS)] = __cfg80211_wext_siwrts,
1480 [IW_IOCTL_IDX(SIOCGIWRTS)] = __cfg80211_wext_giwrts,
1481 [IW_IOCTL_IDX(SIOCSIWFRAG)] = __cfg80211_wext_siwfrag,
1482 [IW_IOCTL_IDX(SIOCGIWFRAG)] = __cfg80211_wext_giwfrag,
1483 [IW_IOCTL_IDX(SIOCSIWTXPOW)] = cfg80211_wext_siwtxpower,
1484 [IW_IOCTL_IDX(SIOCGIWTXPOW)] = cfg80211_wext_giwtxpower,
1485 [IW_IOCTL_IDX(SIOCSIWRETRY)] = __cfg80211_wext_siwretry,
1486 [IW_IOCTL_IDX(SIOCGIWRETRY)] = __cfg80211_wext_giwretry,
1487 [IW_IOCTL_IDX(SIOCSIWENCODE)] = __cfg80211_wext_siwencode,
1488 [IW_IOCTL_IDX(SIOCGIWENCODE)] = __cfg80211_wext_giwencode,
1489 [IW_IOCTL_IDX(SIOCSIWPOWER)] = __cfg80211_wext_siwpower,
1490 [IW_IOCTL_IDX(SIOCGIWPOWER)] = __cfg80211_wext_giwpower,
1491 [IW_IOCTL_IDX(SIOCSIWGENIE)] = __cfg80211_wext_siwgenie,
1492 [IW_IOCTL_IDX(SIOCSIWAUTH)] = __cfg80211_wext_siwauth,
1493 [IW_IOCTL_IDX(SIOCGIWAUTH)] = __cfg80211_wext_giwauth,
1494 [IW_IOCTL_IDX(SIOCSIWENCODEEXT)]= __cfg80211_wext_siwencodeext,
1495 [IW_IOCTL_IDX(SIOCSIWPMKSA)] = __cfg80211_wext_siwpmksa,
Johannes Berga9a11622009-07-27 12:01:53 +02001496};
1497
1498const struct iw_handler_def cfg80211_wext_handler = {
1499 .num_standard = ARRAY_SIZE(cfg80211_handlers),
1500 .standard = cfg80211_handlers,
1501 .get_wireless_stats = cfg80211_wireless_stats,
1502};