blob: a220156cf2175a459727fcf67e1291036dca21ae [file] [log] [blame]
Johannes Bergfee52672008-11-26 22:36:31 +01001/*
2 * cfg80211 - wext compat code
3 *
4 * This is temporary code until all wireless functionality is migrated
5 * into cfg80211, when that happens all the exports here go away and
6 * we directly assign the wireless handlers of wireless interfaces.
7 *
Johannes Berg08645122009-05-11 13:54:58 +02008 * Copyright 2008-2009 Johannes Berg <johannes@sipsolutions.net>
Johannes Bergfee52672008-11-26 22:36:31 +01009 */
10
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040011#include <linux/export.h>
Johannes Bergfee52672008-11-26 22:36:31 +010012#include <linux/wireless.h>
13#include <linux/nl80211.h>
Johannes Berg691597c2009-04-19 19:57:45 +020014#include <linux/if_arp.h>
Johannes Berg08645122009-05-11 13:54:58 +020015#include <linux/etherdevice.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090016#include <linux/slab.h>
Johannes Bergfee52672008-11-26 22:36:31 +010017#include <net/iw_handler.h>
Johannes Bergfee52672008-11-26 22:36:31 +010018#include <net/cfg80211.h>
Johannes Berg262eb9b22011-07-13 10:39:09 +020019#include <net/cfg80211-wext.h>
Johannes Berg0e82ffe2009-07-27 12:01:50 +020020#include "wext-compat.h"
Johannes Bergfee52672008-11-26 22:36:31 +010021#include "core.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030022#include "rdev-ops.h"
Johannes Bergfee52672008-11-26 22:36:31 +010023
24int cfg80211_wext_giwname(struct net_device *dev,
25 struct iw_request_info *info,
26 char *name, char *extra)
27{
Johannes Bergfee52672008-11-26 22:36:31 +010028 strcpy(name, "IEEE 802.11");
Johannes Bergfee52672008-11-26 22:36:31 +010029 return 0;
30}
Johannes Berg2afe38d2015-01-06 14:00:53 +010031EXPORT_WEXT_HANDLER(cfg80211_wext_giwname);
Johannes Berge60c7742008-11-26 23:31:40 +010032
33int cfg80211_wext_siwmode(struct net_device *dev, struct iw_request_info *info,
34 u32 *mode, char *extra)
35{
36 struct wireless_dev *wdev = dev->ieee80211_ptr;
37 struct cfg80211_registered_device *rdev;
38 struct vif_params vifparams;
39 enum nl80211_iftype type;
40
Zhao, Gangf26cbf42014-04-21 12:53:03 +080041 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berge60c7742008-11-26 23:31:40 +010042
Johannes Berge60c7742008-11-26 23:31:40 +010043 switch (*mode) {
44 case IW_MODE_INFRA:
45 type = NL80211_IFTYPE_STATION;
46 break;
47 case IW_MODE_ADHOC:
48 type = NL80211_IFTYPE_ADHOC;
49 break;
50 case IW_MODE_REPEAT:
51 type = NL80211_IFTYPE_WDS;
52 break;
53 case IW_MODE_MONITOR:
54 type = NL80211_IFTYPE_MONITOR;
55 break;
56 default:
57 return -EINVAL;
58 }
59
Johannes Bergac7f9cf2009-03-21 17:07:59 +010060 if (type == wdev->iftype)
61 return 0;
62
Johannes Berge60c7742008-11-26 23:31:40 +010063 memset(&vifparams, 0, sizeof(vifparams));
64
Johannes Berg5fe231e2013-05-08 21:45:15 +020065 return cfg80211_change_iface(rdev, dev, type, NULL, &vifparams);
Johannes Berge60c7742008-11-26 23:31:40 +010066}
Johannes Berg2afe38d2015-01-06 14:00:53 +010067EXPORT_WEXT_HANDLER(cfg80211_wext_siwmode);
Johannes Berge60c7742008-11-26 23:31:40 +010068
69int cfg80211_wext_giwmode(struct net_device *dev, struct iw_request_info *info,
70 u32 *mode, char *extra)
71{
72 struct wireless_dev *wdev = dev->ieee80211_ptr;
73
74 if (!wdev)
75 return -EOPNOTSUPP;
76
77 switch (wdev->iftype) {
78 case NL80211_IFTYPE_AP:
79 *mode = IW_MODE_MASTER;
80 break;
81 case NL80211_IFTYPE_STATION:
82 *mode = IW_MODE_INFRA;
83 break;
84 case NL80211_IFTYPE_ADHOC:
85 *mode = IW_MODE_ADHOC;
86 break;
87 case NL80211_IFTYPE_MONITOR:
88 *mode = IW_MODE_MONITOR;
89 break;
90 case NL80211_IFTYPE_WDS:
91 *mode = IW_MODE_REPEAT;
92 break;
93 case NL80211_IFTYPE_AP_VLAN:
94 *mode = IW_MODE_SECOND; /* FIXME */
95 break;
96 default:
97 *mode = IW_MODE_AUTO;
98 break;
99 }
100 return 0;
101}
Johannes Berg2afe38d2015-01-06 14:00:53 +0100102EXPORT_WEXT_HANDLER(cfg80211_wext_giwmode);
Johannes Berg4aa188e2009-02-18 19:32:08 +0100103
104
105int cfg80211_wext_giwrange(struct net_device *dev,
106 struct iw_request_info *info,
107 struct iw_point *data, char *extra)
108{
109 struct wireless_dev *wdev = dev->ieee80211_ptr;
110 struct iw_range *range = (struct iw_range *) extra;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200111 enum nl80211_band band;
Johannes Berg9834c072009-07-06 19:40:51 +0200112 int i, c = 0;
Johannes Berg4aa188e2009-02-18 19:32:08 +0100113
114 if (!wdev)
115 return -EOPNOTSUPP;
116
117 data->length = sizeof(struct iw_range);
118 memset(range, 0, sizeof(struct iw_range));
119
120 range->we_version_compiled = WIRELESS_EXT;
121 range->we_version_source = 21;
122 range->retry_capa = IW_RETRY_LIMIT;
123 range->retry_flags = IW_RETRY_LIMIT;
124 range->min_retry = 0;
125 range->max_retry = 255;
126 range->min_rts = 0;
127 range->max_rts = 2347;
128 range->min_frag = 256;
129 range->max_frag = 2346;
130
Johannes Berg4aa188e2009-02-18 19:32:08 +0100131 range->max_encoding_tokens = 4;
132
133 range->max_qual.updated = IW_QUAL_NOISE_INVALID;
134
135 switch (wdev->wiphy->signal_type) {
136 case CFG80211_SIGNAL_TYPE_NONE:
137 break;
138 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berge7d83ed2012-12-07 11:58:26 +0100139 range->max_qual.level = (u8)-110;
Johannes Berg4aa188e2009-02-18 19:32:08 +0100140 range->max_qual.qual = 70;
141 range->avg_qual.qual = 35;
142 range->max_qual.updated |= IW_QUAL_DBM;
143 range->max_qual.updated |= IW_QUAL_QUAL_UPDATED;
144 range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED;
145 break;
146 case CFG80211_SIGNAL_TYPE_UNSPEC:
147 range->max_qual.level = 100;
148 range->max_qual.qual = 100;
149 range->avg_qual.qual = 50;
150 range->max_qual.updated |= IW_QUAL_QUAL_UPDATED;
151 range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED;
152 break;
153 }
154
155 range->avg_qual.level = range->max_qual.level / 2;
156 range->avg_qual.noise = range->max_qual.noise / 2;
157 range->avg_qual.updated = range->max_qual.updated;
158
Johannes Berg9834c072009-07-06 19:40:51 +0200159 for (i = 0; i < wdev->wiphy->n_cipher_suites; i++) {
160 switch (wdev->wiphy->cipher_suites[i]) {
David Kilroy3daf0972009-06-18 23:21:14 +0100161 case WLAN_CIPHER_SUITE_TKIP:
David Kilroy27bea662009-06-18 23:21:17 +0100162 range->enc_capa |= (IW_ENC_CAPA_CIPHER_TKIP |
163 IW_ENC_CAPA_WPA);
David Kilroy3daf0972009-06-18 23:21:14 +0100164 break;
165
166 case WLAN_CIPHER_SUITE_CCMP:
David Kilroy27bea662009-06-18 23:21:17 +0100167 range->enc_capa |= (IW_ENC_CAPA_CIPHER_CCMP |
168 IW_ENC_CAPA_WPA2);
David Kilroy3daf0972009-06-18 23:21:14 +0100169 break;
David Kilroy2ab658f2009-06-18 23:21:16 +0100170
171 case WLAN_CIPHER_SUITE_WEP40:
172 range->encoding_size[range->num_encoding_sizes++] =
173 WLAN_KEY_LEN_WEP40;
174 break;
175
176 case WLAN_CIPHER_SUITE_WEP104:
177 range->encoding_size[range->num_encoding_sizes++] =
178 WLAN_KEY_LEN_WEP104;
179 break;
David Kilroy3daf0972009-06-18 23:21:14 +0100180 }
181 }
Johannes Berg4aa188e2009-02-18 19:32:08 +0100182
Johannes Berg57fbcce2016-04-12 15:56:15 +0200183 for (band = 0; band < NUM_NL80211_BANDS; band ++) {
Johannes Berg4aa188e2009-02-18 19:32:08 +0100184 struct ieee80211_supported_band *sband;
185
186 sband = wdev->wiphy->bands[band];
187
188 if (!sband)
189 continue;
190
191 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
192 struct ieee80211_channel *chan = &sband->channels[i];
193
194 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
195 range->freq[c].i =
196 ieee80211_frequency_to_channel(
197 chan->center_freq);
198 range->freq[c].m = chan->center_freq;
199 range->freq[c].e = 6;
200 c++;
201 }
202 }
203 }
204 range->num_channels = c;
205 range->num_frequency = c;
206
207 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
208 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
209 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
210
David Kilroy51cd4aa2009-06-18 23:21:15 +0100211 if (wdev->wiphy->max_scan_ssids > 0)
212 range->scan_capa |= IW_SCAN_CAPA_ESSID;
Johannes Berg4aa188e2009-02-18 19:32:08 +0100213
214 return 0;
215}
Johannes Berg2afe38d2015-01-06 14:00:53 +0100216EXPORT_WEXT_HANDLER(cfg80211_wext_giwrange);
Johannes Berg691597c2009-04-19 19:57:45 +0200217
Johannes Berg04a773a2009-04-19 21:24:32 +0200218
219/**
220 * cfg80211_wext_freq - get wext frequency for non-"auto"
Zhao, Gang96998e32014-04-09 09:28:06 +0800221 * @dev: the net device
Johannes Berg04a773a2009-04-19 21:24:32 +0200222 * @freq: the wext freq encoding
223 *
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200224 * Returns a frequency, or a negative error code, or 0 for auto.
Johannes Berg04a773a2009-04-19 21:24:32 +0200225 */
Zhao, Gang96998e32014-04-09 09:28:06 +0800226int cfg80211_wext_freq(struct iw_freq *freq)
Johannes Berg04a773a2009-04-19 21:24:32 +0200227{
Johannes Berg0b258582009-05-08 09:42:33 +0200228 /*
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200229 * Parse frequency - return 0 for auto and
Johannes Berg0b258582009-05-08 09:42:33 +0200230 * -EINVAL for impossible things.
231 */
Johannes Berg04a773a2009-04-19 21:24:32 +0200232 if (freq->e == 0) {
Johannes Berg57fbcce2016-04-12 15:56:15 +0200233 enum nl80211_band band = NL80211_BAND_2GHZ;
Johannes Berg04a773a2009-04-19 21:24:32 +0200234 if (freq->m < 0)
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200235 return 0;
Bruno Randolf59eb21a2011-01-17 13:37:28 +0900236 if (freq->m > 14)
Johannes Berg57fbcce2016-04-12 15:56:15 +0200237 band = NL80211_BAND_5GHZ;
Bruno Randolf59eb21a2011-01-17 13:37:28 +0900238 return ieee80211_channel_to_frequency(freq->m, band);
Johannes Berg04a773a2009-04-19 21:24:32 +0200239 } else {
240 int i, div = 1000000;
241 for (i = 0; i < freq->e; i++)
242 div /= 10;
Johannes Berg0b258582009-05-08 09:42:33 +0200243 if (div <= 0)
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200244 return -EINVAL;
245 return freq->m / div;
Johannes Berg04a773a2009-04-19 21:24:32 +0200246 }
Johannes Berg04a773a2009-04-19 21:24:32 +0200247}
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200248
249int cfg80211_wext_siwrts(struct net_device *dev,
250 struct iw_request_info *info,
251 struct iw_param *rts, char *extra)
252{
253 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800254 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200255 u32 orts = wdev->wiphy->rts_threshold;
256 int err;
257
258 if (rts->disabled || !rts->fixed)
259 wdev->wiphy->rts_threshold = (u32) -1;
260 else if (rts->value < 0)
261 return -EINVAL;
262 else
263 wdev->wiphy->rts_threshold = rts->value;
264
Hila Gonene35e4d22012-06-27 17:19:42 +0300265 err = rdev_set_wiphy_params(rdev, WIPHY_PARAM_RTS_THRESHOLD);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200266 if (err)
267 wdev->wiphy->rts_threshold = orts;
268
269 return err;
270}
Johannes Berg2afe38d2015-01-06 14:00:53 +0100271EXPORT_WEXT_HANDLER(cfg80211_wext_siwrts);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200272
273int cfg80211_wext_giwrts(struct net_device *dev,
274 struct iw_request_info *info,
275 struct iw_param *rts, char *extra)
276{
277 struct wireless_dev *wdev = dev->ieee80211_ptr;
278
279 rts->value = wdev->wiphy->rts_threshold;
280 rts->disabled = rts->value == (u32) -1;
281 rts->fixed = 1;
282
283 return 0;
284}
Johannes Berg2afe38d2015-01-06 14:00:53 +0100285EXPORT_WEXT_HANDLER(cfg80211_wext_giwrts);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200286
287int cfg80211_wext_siwfrag(struct net_device *dev,
288 struct iw_request_info *info,
289 struct iw_param *frag, char *extra)
290{
291 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800292 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200293 u32 ofrag = wdev->wiphy->frag_threshold;
294 int err;
295
296 if (frag->disabled || !frag->fixed)
297 wdev->wiphy->frag_threshold = (u32) -1;
298 else if (frag->value < 256)
299 return -EINVAL;
300 else {
301 /* Fragment length must be even, so strip LSB. */
302 wdev->wiphy->frag_threshold = frag->value & ~0x1;
303 }
304
Hila Gonene35e4d22012-06-27 17:19:42 +0300305 err = rdev_set_wiphy_params(rdev, WIPHY_PARAM_FRAG_THRESHOLD);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200306 if (err)
307 wdev->wiphy->frag_threshold = ofrag;
308
309 return err;
310}
Johannes Berg2afe38d2015-01-06 14:00:53 +0100311EXPORT_WEXT_HANDLER(cfg80211_wext_siwfrag);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200312
313int cfg80211_wext_giwfrag(struct net_device *dev,
314 struct iw_request_info *info,
315 struct iw_param *frag, char *extra)
316{
317 struct wireless_dev *wdev = dev->ieee80211_ptr;
318
319 frag->value = wdev->wiphy->frag_threshold;
320 frag->disabled = frag->value == (u32) -1;
321 frag->fixed = 1;
322
323 return 0;
324}
Johannes Berg2afe38d2015-01-06 14:00:53 +0100325EXPORT_WEXT_HANDLER(cfg80211_wext_giwfrag);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200326
Johannes Berg04b0c5c2011-07-15 13:01:38 +0200327static int cfg80211_wext_siwretry(struct net_device *dev,
328 struct iw_request_info *info,
329 struct iw_param *retry, char *extra)
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200330{
331 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800332 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200333 u32 changed = 0;
334 u8 olong = wdev->wiphy->retry_long;
335 u8 oshort = wdev->wiphy->retry_short;
336 int err;
337
Ujjal Royf5aa0d22014-01-09 21:16:14 +0530338 if (retry->disabled || retry->value < 1 || retry->value > 255 ||
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200339 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
340 return -EINVAL;
341
342 if (retry->flags & IW_RETRY_LONG) {
343 wdev->wiphy->retry_long = retry->value;
344 changed |= WIPHY_PARAM_RETRY_LONG;
345 } else if (retry->flags & IW_RETRY_SHORT) {
346 wdev->wiphy->retry_short = retry->value;
347 changed |= WIPHY_PARAM_RETRY_SHORT;
348 } else {
349 wdev->wiphy->retry_short = retry->value;
350 wdev->wiphy->retry_long = retry->value;
351 changed |= WIPHY_PARAM_RETRY_LONG;
352 changed |= WIPHY_PARAM_RETRY_SHORT;
353 }
354
355 if (!changed)
356 return 0;
357
Hila Gonene35e4d22012-06-27 17:19:42 +0300358 err = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200359 if (err) {
360 wdev->wiphy->retry_short = oshort;
361 wdev->wiphy->retry_long = olong;
362 }
363
364 return err;
365}
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200366
367int cfg80211_wext_giwretry(struct net_device *dev,
368 struct iw_request_info *info,
369 struct iw_param *retry, char *extra)
370{
371 struct wireless_dev *wdev = dev->ieee80211_ptr;
372
373 retry->disabled = 0;
374
375 if (retry->flags == 0 || (retry->flags & IW_RETRY_SHORT)) {
376 /*
377 * First return short value, iwconfig will ask long value
378 * later if needed
379 */
Ujjal Roy60a4fe02014-01-06 21:56:11 +0530380 retry->flags |= IW_RETRY_LIMIT | IW_RETRY_SHORT;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200381 retry->value = wdev->wiphy->retry_short;
Ujjal Roy60a4fe02014-01-06 21:56:11 +0530382 if (wdev->wiphy->retry_long == wdev->wiphy->retry_short)
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200383 retry->flags |= IW_RETRY_LONG;
384
385 return 0;
386 }
387
388 if (retry->flags & IW_RETRY_LONG) {
389 retry->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
390 retry->value = wdev->wiphy->retry_long;
391 }
392
393 return 0;
394}
Johannes Berg2afe38d2015-01-06 14:00:53 +0100395EXPORT_WEXT_HANDLER(cfg80211_wext_giwretry);
Johannes Berg08645122009-05-11 13:54:58 +0200396
Johannes Bergfffd0932009-07-08 14:22:54 +0200397static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
Johannes Berge31b8212010-10-05 19:39:30 +0200398 struct net_device *dev, bool pairwise,
399 const u8 *addr, bool remove, bool tx_key,
400 int idx, struct key_params *params)
Johannes Berg08645122009-05-11 13:54:58 +0200401{
402 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergfffd0932009-07-08 14:22:54 +0200403 int err, i;
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100404 bool rejoin = false;
Johannes Bergfffd0932009-07-08 14:22:54 +0200405
Johannes Berge31b8212010-10-05 19:39:30 +0200406 if (pairwise && !addr)
407 return -EINVAL;
408
Johannes Berg8f7d99b2016-09-28 23:44:57 +0200409 /*
410 * In many cases we won't actually need this, but it's better
411 * to do it first in case the allocation fails. Don't use wext.
412 */
Johannes Bergfffd0932009-07-08 14:22:54 +0200413 if (!wdev->wext.keys) {
414 wdev->wext.keys = kzalloc(sizeof(*wdev->wext.keys),
Johannes Berg89b706f2016-09-13 16:39:38 +0200415 GFP_KERNEL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200416 if (!wdev->wext.keys)
417 return -ENOMEM;
David Spinadelb8676222016-09-22 23:16:50 +0300418 for (i = 0; i < CFG80211_MAX_WEP_KEYS; i++)
Johannes Bergfffd0932009-07-08 14:22:54 +0200419 wdev->wext.keys->params[i].key =
420 wdev->wext.keys->data[i];
421 }
422
423 if (wdev->iftype != NL80211_IFTYPE_ADHOC &&
424 wdev->iftype != NL80211_IFTYPE_STATION)
425 return -EOPNOTSUPP;
Johannes Berg08645122009-05-11 13:54:58 +0200426
427 if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
Johannes Bergfffd0932009-07-08 14:22:54 +0200428 if (!wdev->current_bss)
429 return -ENOLINK;
430
Johannes Berg08645122009-05-11 13:54:58 +0200431 if (!rdev->ops->set_default_mgmt_key)
432 return -EOPNOTSUPP;
433
434 if (idx < 4 || idx > 5)
435 return -EINVAL;
436 } else if (idx < 0 || idx > 3)
437 return -EINVAL;
438
439 if (remove) {
Johannes Bergfffd0932009-07-08 14:22:54 +0200440 err = 0;
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100441 if (wdev->current_bss) {
442 /*
443 * If removing the current TX key, we will need to
444 * join a new IBSS without the privacy bit clear.
445 */
446 if (idx == wdev->wext.default_key &&
447 wdev->iftype == NL80211_IFTYPE_ADHOC) {
448 __cfg80211_leave_ibss(rdev, wdev->netdev, true);
449 rejoin = true;
450 }
Johannes Berge31b8212010-10-05 19:39:30 +0200451
452 if (!pairwise && addr &&
453 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
454 err = -ENOENT;
455 else
Hila Gonene35e4d22012-06-27 17:19:42 +0300456 err = rdev_del_key(rdev, dev, idx, pairwise,
457 addr);
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100458 }
Vivek Natarajand55fb892009-11-24 11:54:10 -0500459 wdev->wext.connect.privacy = false;
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100460 /*
461 * Applications using wireless extensions expect to be
462 * able to delete keys that don't exist, so allow that.
463 */
464 if (err == -ENOENT)
465 err = 0;
Johannes Berg08645122009-05-11 13:54:58 +0200466 if (!err) {
Johannes Berg89b706f2016-09-13 16:39:38 +0200467 if (!addr && idx < 4) {
Johannes Berg538c9eb2014-09-10 13:39:56 +0300468 memset(wdev->wext.keys->data[idx], 0,
469 sizeof(wdev->wext.keys->data[idx]));
Johannes Bergfffd0932009-07-08 14:22:54 +0200470 wdev->wext.keys->params[idx].key_len = 0;
471 wdev->wext.keys->params[idx].cipher = 0;
472 }
Johannes Berg08645122009-05-11 13:54:58 +0200473 if (idx == wdev->wext.default_key)
474 wdev->wext.default_key = -1;
475 else if (idx == wdev->wext.default_mgmt_key)
476 wdev->wext.default_mgmt_key = -1;
477 }
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100478
479 if (!err && rejoin)
480 err = cfg80211_ibss_wext_join(rdev, wdev);
Johannes Berge3da5742009-05-18 19:56:36 +0200481
Johannes Berg08645122009-05-11 13:54:58 +0200482 return err;
Johannes Bergfffd0932009-07-08 14:22:54 +0200483 }
Johannes Berg08645122009-05-11 13:54:58 +0200484
Johannes Bergfffd0932009-07-08 14:22:54 +0200485 if (addr)
486 tx_key = false;
Johannes Berg08645122009-05-11 13:54:58 +0200487
Johannes Berge31b8212010-10-05 19:39:30 +0200488 if (cfg80211_validate_key_settings(rdev, params, idx, pairwise, addr))
Johannes Bergfffd0932009-07-08 14:22:54 +0200489 return -EINVAL;
490
491 err = 0;
492 if (wdev->current_bss)
Hila Gonene35e4d22012-06-27 17:19:42 +0300493 err = rdev_add_key(rdev, dev, idx, pairwise, addr, params);
Johannes Berg9381e262016-09-13 16:11:32 +0200494 else if (params->cipher != WLAN_CIPHER_SUITE_WEP40 &&
495 params->cipher != WLAN_CIPHER_SUITE_WEP104)
496 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +0200497 if (err)
498 return err;
Johannes Berg08645122009-05-11 13:54:58 +0200499
Johannes Berg8f7d99b2016-09-28 23:44:57 +0200500 /*
501 * We only need to store WEP keys, since they're the only keys that
502 * can be be set before a connection is established and persist after
503 * disconnecting.
504 */
505 if (!addr && (params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
506 params->cipher == WLAN_CIPHER_SUITE_WEP104)) {
Johannes Bergfffd0932009-07-08 14:22:54 +0200507 wdev->wext.keys->params[idx] = *params;
508 memcpy(wdev->wext.keys->data[idx],
509 params->key, params->key_len);
510 wdev->wext.keys->params[idx].key =
511 wdev->wext.keys->data[idx];
512 }
513
Zhu Yi1f00fca2009-07-20 11:47:43 +0800514 if ((params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
515 params->cipher == WLAN_CIPHER_SUITE_WEP104) &&
Johannes Bergfffd0932009-07-08 14:22:54 +0200516 (tx_key || (!addr && wdev->wext.default_key == -1))) {
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100517 if (wdev->current_bss) {
518 /*
519 * If we are getting a new TX key from not having
520 * had one before we need to join a new IBSS with
521 * the privacy bit set.
522 */
523 if (wdev->iftype == NL80211_IFTYPE_ADHOC &&
524 wdev->wext.default_key == -1) {
525 __cfg80211_leave_ibss(rdev, wdev->netdev, true);
526 rejoin = true;
527 }
Hila Gonene35e4d22012-06-27 17:19:42 +0300528 err = rdev_set_default_key(rdev, dev, idx, true, true);
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100529 }
530 if (!err) {
Johannes Bergfffd0932009-07-08 14:22:54 +0200531 wdev->wext.default_key = idx;
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100532 if (rejoin)
533 err = cfg80211_ibss_wext_join(rdev, wdev);
534 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200535 return err;
536 }
Johannes Berg08645122009-05-11 13:54:58 +0200537
Johannes Bergfffd0932009-07-08 14:22:54 +0200538 if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC &&
539 (tx_key || (!addr && wdev->wext.default_mgmt_key == -1))) {
540 if (wdev->current_bss)
Hila Gonene35e4d22012-06-27 17:19:42 +0300541 err = rdev_set_default_mgmt_key(rdev, dev, idx);
Johannes Bergfffd0932009-07-08 14:22:54 +0200542 if (!err)
543 wdev->wext.default_mgmt_key = idx;
544 return err;
Johannes Berg08645122009-05-11 13:54:58 +0200545 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200546
547 return 0;
548}
549
550static int cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
Johannes Berge31b8212010-10-05 19:39:30 +0200551 struct net_device *dev, bool pairwise,
552 const u8 *addr, bool remove, bool tx_key,
553 int idx, struct key_params *params)
Johannes Bergfffd0932009-07-08 14:22:54 +0200554{
555 int err;
556
557 wdev_lock(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +0200558 err = __cfg80211_set_encryption(rdev, dev, pairwise, addr,
559 remove, tx_key, idx, params);
Johannes Bergfffd0932009-07-08 14:22:54 +0200560 wdev_unlock(dev->ieee80211_ptr);
561
562 return err;
Johannes Berg08645122009-05-11 13:54:58 +0200563}
564
Johannes Berg04b0c5c2011-07-15 13:01:38 +0200565static int cfg80211_wext_siwencode(struct net_device *dev,
566 struct iw_request_info *info,
567 struct iw_point *erq, char *keybuf)
Johannes Berg08645122009-05-11 13:54:58 +0200568{
569 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800570 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg08645122009-05-11 13:54:58 +0200571 int idx, err;
572 bool remove = false;
573 struct key_params params;
574
Johannes Bergfffd0932009-07-08 14:22:54 +0200575 if (wdev->iftype != NL80211_IFTYPE_STATION &&
576 wdev->iftype != NL80211_IFTYPE_ADHOC)
577 return -EOPNOTSUPP;
578
Johannes Berg08645122009-05-11 13:54:58 +0200579 /* no use -- only MFP (set_default_mgmt_key) is optional */
580 if (!rdev->ops->del_key ||
581 !rdev->ops->add_key ||
582 !rdev->ops->set_default_key)
583 return -EOPNOTSUPP;
584
585 idx = erq->flags & IW_ENCODE_INDEX;
586 if (idx == 0) {
587 idx = wdev->wext.default_key;
588 if (idx < 0)
589 idx = 0;
590 } else if (idx < 1 || idx > 4)
591 return -EINVAL;
592 else
593 idx--;
594
595 if (erq->flags & IW_ENCODE_DISABLED)
596 remove = true;
597 else if (erq->length == 0) {
598 /* No key data - just set the default TX key index */
Johannes Bergfffd0932009-07-08 14:22:54 +0200599 err = 0;
600 wdev_lock(wdev);
601 if (wdev->current_bss)
Hila Gonene35e4d22012-06-27 17:19:42 +0300602 err = rdev_set_default_key(rdev, dev, idx, true,
603 true);
Johannes Berg08645122009-05-11 13:54:58 +0200604 if (!err)
605 wdev->wext.default_key = idx;
Johannes Bergfffd0932009-07-08 14:22:54 +0200606 wdev_unlock(wdev);
Johannes Berg08645122009-05-11 13:54:58 +0200607 return err;
608 }
609
610 memset(&params, 0, sizeof(params));
611 params.key = keybuf;
612 params.key_len = erq->length;
613 if (erq->length == 5)
614 params.cipher = WLAN_CIPHER_SUITE_WEP40;
615 else if (erq->length == 13)
616 params.cipher = WLAN_CIPHER_SUITE_WEP104;
617 else if (!remove)
618 return -EINVAL;
619
Johannes Berge31b8212010-10-05 19:39:30 +0200620 return cfg80211_set_encryption(rdev, dev, false, NULL, remove,
Johannes Berg08645122009-05-11 13:54:58 +0200621 wdev->wext.default_key == -1,
622 idx, &params);
623}
Johannes Berg08645122009-05-11 13:54:58 +0200624
Johannes Berg04b0c5c2011-07-15 13:01:38 +0200625static int cfg80211_wext_siwencodeext(struct net_device *dev,
626 struct iw_request_info *info,
627 struct iw_point *erq, char *extra)
Johannes Berg08645122009-05-11 13:54:58 +0200628{
629 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800630 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg08645122009-05-11 13:54:58 +0200631 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
632 const u8 *addr;
633 int idx;
634 bool remove = false;
635 struct key_params params;
636 u32 cipher;
637
Johannes Bergfffd0932009-07-08 14:22:54 +0200638 if (wdev->iftype != NL80211_IFTYPE_STATION &&
639 wdev->iftype != NL80211_IFTYPE_ADHOC)
640 return -EOPNOTSUPP;
641
Johannes Berg08645122009-05-11 13:54:58 +0200642 /* no use -- only MFP (set_default_mgmt_key) is optional */
643 if (!rdev->ops->del_key ||
644 !rdev->ops->add_key ||
645 !rdev->ops->set_default_key)
646 return -EOPNOTSUPP;
647
648 switch (ext->alg) {
649 case IW_ENCODE_ALG_NONE:
650 remove = true;
651 cipher = 0;
652 break;
653 case IW_ENCODE_ALG_WEP:
654 if (ext->key_len == 5)
655 cipher = WLAN_CIPHER_SUITE_WEP40;
656 else if (ext->key_len == 13)
657 cipher = WLAN_CIPHER_SUITE_WEP104;
658 else
659 return -EINVAL;
660 break;
661 case IW_ENCODE_ALG_TKIP:
662 cipher = WLAN_CIPHER_SUITE_TKIP;
663 break;
664 case IW_ENCODE_ALG_CCMP:
665 cipher = WLAN_CIPHER_SUITE_CCMP;
666 break;
667 case IW_ENCODE_ALG_AES_CMAC:
668 cipher = WLAN_CIPHER_SUITE_AES_CMAC;
669 break;
670 default:
671 return -EOPNOTSUPP;
672 }
673
674 if (erq->flags & IW_ENCODE_DISABLED)
675 remove = true;
676
677 idx = erq->flags & IW_ENCODE_INDEX;
678 if (cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
679 if (idx < 4 || idx > 5) {
680 idx = wdev->wext.default_mgmt_key;
681 if (idx < 0)
682 return -EINVAL;
683 } else
684 idx--;
685 } else {
686 if (idx < 1 || idx > 4) {
687 idx = wdev->wext.default_key;
688 if (idx < 0)
689 return -EINVAL;
690 } else
691 idx--;
692 }
693
694 addr = ext->addr.sa_data;
695 if (is_broadcast_ether_addr(addr))
696 addr = NULL;
697
698 memset(&params, 0, sizeof(params));
699 params.key = ext->key;
700 params.key_len = ext->key_len;
701 params.cipher = cipher;
702
Jouni Malinenfaa8fdc2009-05-11 21:57:58 +0300703 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
704 params.seq = ext->rx_seq;
705 params.seq_len = 6;
706 }
707
Johannes Berg08645122009-05-11 13:54:58 +0200708 return cfg80211_set_encryption(
Johannes Berge31b8212010-10-05 19:39:30 +0200709 rdev, dev,
710 !(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY),
711 addr, remove,
Johannes Berg08645122009-05-11 13:54:58 +0200712 ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
713 idx, &params);
714}
Johannes Berg08645122009-05-11 13:54:58 +0200715
Johannes Berg04b0c5c2011-07-15 13:01:38 +0200716static int cfg80211_wext_giwencode(struct net_device *dev,
717 struct iw_request_info *info,
718 struct iw_point *erq, char *keybuf)
Johannes Berg08645122009-05-11 13:54:58 +0200719{
720 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergfffd0932009-07-08 14:22:54 +0200721 int idx;
Johannes Berg08645122009-05-11 13:54:58 +0200722
Johannes Bergfffd0932009-07-08 14:22:54 +0200723 if (wdev->iftype != NL80211_IFTYPE_STATION &&
724 wdev->iftype != NL80211_IFTYPE_ADHOC)
Johannes Berg08645122009-05-11 13:54:58 +0200725 return -EOPNOTSUPP;
726
727 idx = erq->flags & IW_ENCODE_INDEX;
728 if (idx == 0) {
729 idx = wdev->wext.default_key;
730 if (idx < 0)
731 idx = 0;
732 } else if (idx < 1 || idx > 4)
733 return -EINVAL;
734 else
735 idx--;
736
737 erq->flags = idx + 1;
738
Johannes Bergfffd0932009-07-08 14:22:54 +0200739 if (!wdev->wext.keys || !wdev->wext.keys->params[idx].cipher) {
Johannes Berg08645122009-05-11 13:54:58 +0200740 erq->flags |= IW_ENCODE_DISABLED;
741 erq->length = 0;
742 return 0;
743 }
744
Johannes Bergfffd0932009-07-08 14:22:54 +0200745 erq->length = min_t(size_t, erq->length,
746 wdev->wext.keys->params[idx].key_len);
747 memcpy(keybuf, wdev->wext.keys->params[idx].key, erq->length);
748 erq->flags |= IW_ENCODE_ENABLED;
749
750 return 0;
Johannes Berg08645122009-05-11 13:54:58 +0200751}
Johannes Berg7643a2c2009-06-02 13:01:39 +0200752
Johannes Berg04b0c5c2011-07-15 13:01:38 +0200753static int cfg80211_wext_siwfreq(struct net_device *dev,
754 struct iw_request_info *info,
755 struct iw_freq *wextfreq, char *extra)
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200756{
757 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800758 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg683b6d32012-11-08 21:25:48 +0100759 struct cfg80211_chan_def chandef = {
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100760 .width = NL80211_CHAN_WIDTH_20_NOHT,
Johannes Berg683b6d32012-11-08 21:25:48 +0100761 };
Johannes Berg5fe231e2013-05-08 21:45:15 +0200762 int freq;
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200763
764 switch (wdev->iftype) {
765 case NL80211_IFTYPE_STATION:
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200766 return cfg80211_mgd_wext_siwfreq(dev, info, wextfreq, extra);
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200767 case NL80211_IFTYPE_ADHOC:
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200768 return cfg80211_ibss_wext_siwfreq(dev, info, wextfreq, extra);
Johannes Bergf444de02010-05-05 15:25:02 +0200769 case NL80211_IFTYPE_MONITOR:
Zhao, Gang96998e32014-04-09 09:28:06 +0800770 freq = cfg80211_wext_freq(wextfreq);
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200771 if (freq < 0)
772 return freq;
773 if (freq == 0)
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200774 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100775 chandef.center_freq1 = freq;
Johannes Berg683b6d32012-11-08 21:25:48 +0100776 chandef.chan = ieee80211_get_channel(&rdev->wiphy, freq);
777 if (!chandef.chan)
778 return -EINVAL;
Johannes Berg5fe231e2013-05-08 21:45:15 +0200779 return cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +0200780 case NL80211_IFTYPE_MESH_POINT:
Zhao, Gang96998e32014-04-09 09:28:06 +0800781 freq = cfg80211_wext_freq(wextfreq);
Johannes Bergcc1d2802012-05-16 23:50:20 +0200782 if (freq < 0)
783 return freq;
784 if (freq == 0)
785 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100786 chandef.center_freq1 = freq;
Johannes Berg683b6d32012-11-08 21:25:48 +0100787 chandef.chan = ieee80211_get_channel(&rdev->wiphy, freq);
788 if (!chandef.chan)
789 return -EINVAL;
Johannes Berg5fe231e2013-05-08 21:45:15 +0200790 return cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergf444de02010-05-05 15:25:02 +0200791 default:
792 return -EOPNOTSUPP;
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200793 }
794}
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200795
Johannes Berg04b0c5c2011-07-15 13:01:38 +0200796static int cfg80211_wext_giwfreq(struct net_device *dev,
797 struct iw_request_info *info,
798 struct iw_freq *freq, char *extra)
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200799{
800 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800801 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg683b6d32012-11-08 21:25:48 +0100802 struct cfg80211_chan_def chandef;
803 int ret;
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200804
805 switch (wdev->iftype) {
806 case NL80211_IFTYPE_STATION:
807 return cfg80211_mgd_wext_giwfreq(dev, info, freq, extra);
808 case NL80211_IFTYPE_ADHOC:
809 return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra);
Johannes Berge9998822011-11-09 10:30:21 +0100810 case NL80211_IFTYPE_MONITOR:
Johannes Berg5b7ccaf2012-07-12 19:45:08 +0200811 if (!rdev->ops->get_channel)
Johannes Berge9998822011-11-09 10:30:21 +0100812 return -EINVAL;
813
Johannes Berg683b6d32012-11-08 21:25:48 +0100814 ret = rdev_get_channel(rdev, wdev, &chandef);
815 if (ret)
816 return ret;
817 freq->m = chandef.chan->center_freq;
Johannes Berge9998822011-11-09 10:30:21 +0100818 freq->e = 6;
819 return 0;
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200820 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +0200821 return -EINVAL;
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200822 }
823}
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200824
Johannes Berg04b0c5c2011-07-15 13:01:38 +0200825static int cfg80211_wext_siwtxpower(struct net_device *dev,
826 struct iw_request_info *info,
827 union iwreq_data *data, char *extra)
Johannes Berg7643a2c2009-06-02 13:01:39 +0200828{
829 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800830 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +0300831 enum nl80211_tx_power_setting type;
Johannes Berg7643a2c2009-06-02 13:01:39 +0200832 int dbm = 0;
833
834 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
835 return -EINVAL;
836 if (data->txpower.flags & IW_TXPOW_RANGE)
837 return -EINVAL;
838
839 if (!rdev->ops->set_tx_power)
840 return -EOPNOTSUPP;
841
842 /* only change when not disabling */
843 if (!data->txpower.disabled) {
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200844 rfkill_set_sw_state(rdev->rfkill, false);
845
Johannes Berg7643a2c2009-06-02 13:01:39 +0200846 if (data->txpower.fixed) {
847 /*
848 * wext doesn't support negative values, see
849 * below where it's for automatic
850 */
851 if (data->txpower.value < 0)
852 return -EINVAL;
853 dbm = data->txpower.value;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +0300854 type = NL80211_TX_POWER_FIXED;
Johannes Berg7643a2c2009-06-02 13:01:39 +0200855 /* TODO: do regulatory check! */
856 } else {
857 /*
858 * Automatic power level setting, max being the value
859 * passed in from userland.
860 */
861 if (data->txpower.value < 0) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +0300862 type = NL80211_TX_POWER_AUTOMATIC;
Johannes Berg7643a2c2009-06-02 13:01:39 +0200863 } else {
864 dbm = data->txpower.value;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +0300865 type = NL80211_TX_POWER_LIMITED;
Johannes Berg7643a2c2009-06-02 13:01:39 +0200866 }
867 }
868 } else {
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200869 rfkill_set_sw_state(rdev->rfkill, true);
870 schedule_work(&rdev->rfkill_sync);
871 return 0;
Johannes Berg7643a2c2009-06-02 13:01:39 +0200872 }
873
Johannes Bergc8442112012-10-24 10:17:18 +0200874 return rdev_set_tx_power(rdev, wdev, type, DBM_TO_MBM(dbm));
Johannes Berg7643a2c2009-06-02 13:01:39 +0200875}
Johannes Berg7643a2c2009-06-02 13:01:39 +0200876
Johannes Berg04b0c5c2011-07-15 13:01:38 +0200877static int cfg80211_wext_giwtxpower(struct net_device *dev,
878 struct iw_request_info *info,
879 union iwreq_data *data, char *extra)
Johannes Berg7643a2c2009-06-02 13:01:39 +0200880{
881 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800882 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7643a2c2009-06-02 13:01:39 +0200883 int err, val;
884
885 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
886 return -EINVAL;
887 if (data->txpower.flags & IW_TXPOW_RANGE)
888 return -EINVAL;
889
890 if (!rdev->ops->get_tx_power)
891 return -EOPNOTSUPP;
892
Johannes Bergc8442112012-10-24 10:17:18 +0200893 err = rdev_get_tx_power(rdev, wdev, &val);
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200894 if (err)
Johannes Berg7643a2c2009-06-02 13:01:39 +0200895 return err;
896
897 /* well... oh well */
898 data->txpower.fixed = 1;
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200899 data->txpower.disabled = rfkill_blocked(rdev->rfkill);
Johannes Berg7643a2c2009-06-02 13:01:39 +0200900 data->txpower.value = val;
901 data->txpower.flags = IW_TXPOW_DBM;
902
903 return 0;
904}
Johannes Bergf2129352009-07-01 21:26:56 +0200905
906static int cfg80211_set_auth_alg(struct wireless_dev *wdev,
907 s32 auth_alg)
908{
909 int nr_alg = 0;
910
911 if (!auth_alg)
912 return -EINVAL;
913
914 if (auth_alg & ~(IW_AUTH_ALG_OPEN_SYSTEM |
915 IW_AUTH_ALG_SHARED_KEY |
916 IW_AUTH_ALG_LEAP))
917 return -EINVAL;
918
919 if (auth_alg & IW_AUTH_ALG_OPEN_SYSTEM) {
920 nr_alg++;
921 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
922 }
923
924 if (auth_alg & IW_AUTH_ALG_SHARED_KEY) {
925 nr_alg++;
926 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_SHARED_KEY;
927 }
928
929 if (auth_alg & IW_AUTH_ALG_LEAP) {
930 nr_alg++;
931 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_NETWORK_EAP;
932 }
933
934 if (nr_alg > 1)
935 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
936
937 return 0;
938}
939
940static int cfg80211_set_wpa_version(struct wireless_dev *wdev, u32 wpa_versions)
941{
Johannes Bergf2129352009-07-01 21:26:56 +0200942 if (wpa_versions & ~(IW_AUTH_WPA_VERSION_WPA |
Gábor Stefanik323d5662009-07-12 02:03:48 +0200943 IW_AUTH_WPA_VERSION_WPA2|
944 IW_AUTH_WPA_VERSION_DISABLED))
Johannes Bergf2129352009-07-01 21:26:56 +0200945 return -EINVAL;
946
Gábor Stefanik323d5662009-07-12 02:03:48 +0200947 if ((wpa_versions & IW_AUTH_WPA_VERSION_DISABLED) &&
948 (wpa_versions & (IW_AUTH_WPA_VERSION_WPA|
949 IW_AUTH_WPA_VERSION_WPA2)))
950 return -EINVAL;
951
952 if (wpa_versions & IW_AUTH_WPA_VERSION_DISABLED)
953 wdev->wext.connect.crypto.wpa_versions &=
954 ~(NL80211_WPA_VERSION_1|NL80211_WPA_VERSION_2);
955
Johannes Bergf2129352009-07-01 21:26:56 +0200956 if (wpa_versions & IW_AUTH_WPA_VERSION_WPA)
957 wdev->wext.connect.crypto.wpa_versions |=
958 NL80211_WPA_VERSION_1;
959
960 if (wpa_versions & IW_AUTH_WPA_VERSION_WPA2)
961 wdev->wext.connect.crypto.wpa_versions |=
962 NL80211_WPA_VERSION_2;
963
964 return 0;
965}
966
Johannes Berg4f5dadc2009-07-07 03:56:10 +0200967static int cfg80211_set_cipher_group(struct wireless_dev *wdev, u32 cipher)
Johannes Bergf2129352009-07-01 21:26:56 +0200968{
Johannes Bergf2129352009-07-01 21:26:56 +0200969 if (cipher & IW_AUTH_CIPHER_WEP40)
970 wdev->wext.connect.crypto.cipher_group =
971 WLAN_CIPHER_SUITE_WEP40;
972 else if (cipher & IW_AUTH_CIPHER_WEP104)
973 wdev->wext.connect.crypto.cipher_group =
974 WLAN_CIPHER_SUITE_WEP104;
975 else if (cipher & IW_AUTH_CIPHER_TKIP)
976 wdev->wext.connect.crypto.cipher_group =
977 WLAN_CIPHER_SUITE_TKIP;
978 else if (cipher & IW_AUTH_CIPHER_CCMP)
979 wdev->wext.connect.crypto.cipher_group =
980 WLAN_CIPHER_SUITE_CCMP;
981 else if (cipher & IW_AUTH_CIPHER_AES_CMAC)
982 wdev->wext.connect.crypto.cipher_group =
983 WLAN_CIPHER_SUITE_AES_CMAC;
Jouni Malinenc5f82892009-11-01 11:18:49 +0200984 else if (cipher & IW_AUTH_CIPHER_NONE)
985 wdev->wext.connect.crypto.cipher_group = 0;
Johannes Bergf2129352009-07-01 21:26:56 +0200986 else
987 return -EINVAL;
988
989 return 0;
990}
991
Johannes Berg4f5dadc2009-07-07 03:56:10 +0200992static int cfg80211_set_cipher_pairwise(struct wireless_dev *wdev, u32 cipher)
Johannes Bergf2129352009-07-01 21:26:56 +0200993{
994 int nr_ciphers = 0;
995 u32 *ciphers_pairwise = wdev->wext.connect.crypto.ciphers_pairwise;
996
997 if (cipher & IW_AUTH_CIPHER_WEP40) {
998 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP40;
999 nr_ciphers++;
1000 }
1001
1002 if (cipher & IW_AUTH_CIPHER_WEP104) {
1003 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP104;
1004 nr_ciphers++;
1005 }
1006
1007 if (cipher & IW_AUTH_CIPHER_TKIP) {
1008 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_TKIP;
1009 nr_ciphers++;
1010 }
1011
1012 if (cipher & IW_AUTH_CIPHER_CCMP) {
1013 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_CCMP;
1014 nr_ciphers++;
1015 }
1016
1017 if (cipher & IW_AUTH_CIPHER_AES_CMAC) {
1018 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_AES_CMAC;
1019 nr_ciphers++;
1020 }
1021
1022 BUILD_BUG_ON(NL80211_MAX_NR_CIPHER_SUITES < 5);
1023
1024 wdev->wext.connect.crypto.n_ciphers_pairwise = nr_ciphers;
1025
1026 return 0;
1027}
1028
1029
Johannes Berg4f5dadc2009-07-07 03:56:10 +02001030static int cfg80211_set_key_mgt(struct wireless_dev *wdev, u32 key_mgt)
Johannes Bergf2129352009-07-01 21:26:56 +02001031{
1032 int nr_akm_suites = 0;
1033
1034 if (key_mgt & ~(IW_AUTH_KEY_MGMT_802_1X |
1035 IW_AUTH_KEY_MGMT_PSK))
1036 return -EINVAL;
1037
1038 if (key_mgt & IW_AUTH_KEY_MGMT_802_1X) {
1039 wdev->wext.connect.crypto.akm_suites[nr_akm_suites] =
1040 WLAN_AKM_SUITE_8021X;
1041 nr_akm_suites++;
1042 }
1043
1044 if (key_mgt & IW_AUTH_KEY_MGMT_PSK) {
1045 wdev->wext.connect.crypto.akm_suites[nr_akm_suites] =
1046 WLAN_AKM_SUITE_PSK;
1047 nr_akm_suites++;
1048 }
1049
1050 wdev->wext.connect.crypto.n_akm_suites = nr_akm_suites;
1051
1052 return 0;
1053}
1054
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001055static int cfg80211_wext_siwauth(struct net_device *dev,
1056 struct iw_request_info *info,
1057 struct iw_param *data, char *extra)
Johannes Bergf2129352009-07-01 21:26:56 +02001058{
1059 struct wireless_dev *wdev = dev->ieee80211_ptr;
1060
1061 if (wdev->iftype != NL80211_IFTYPE_STATION)
1062 return -EOPNOTSUPP;
1063
1064 switch (data->flags & IW_AUTH_INDEX) {
1065 case IW_AUTH_PRIVACY_INVOKED:
1066 wdev->wext.connect.privacy = data->value;
1067 return 0;
1068 case IW_AUTH_WPA_VERSION:
1069 return cfg80211_set_wpa_version(wdev, data->value);
1070 case IW_AUTH_CIPHER_GROUP:
1071 return cfg80211_set_cipher_group(wdev, data->value);
1072 case IW_AUTH_KEY_MGMT:
1073 return cfg80211_set_key_mgt(wdev, data->value);
1074 case IW_AUTH_CIPHER_PAIRWISE:
1075 return cfg80211_set_cipher_pairwise(wdev, data->value);
1076 case IW_AUTH_80211_AUTH_ALG:
1077 return cfg80211_set_auth_alg(wdev, data->value);
1078 case IW_AUTH_WPA_ENABLED:
1079 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1080 case IW_AUTH_DROP_UNENCRYPTED:
1081 case IW_AUTH_MFP:
1082 return 0;
1083 default:
1084 return -EOPNOTSUPP;
1085 }
1086}
Johannes Bergf2129352009-07-01 21:26:56 +02001087
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001088static int cfg80211_wext_giwauth(struct net_device *dev,
1089 struct iw_request_info *info,
1090 struct iw_param *data, char *extra)
Johannes Bergf2129352009-07-01 21:26:56 +02001091{
1092 /* XXX: what do we need? */
1093
1094 return -EOPNOTSUPP;
1095}
Johannes Bergbc92afd2009-07-01 21:26:57 +02001096
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001097static int cfg80211_wext_siwpower(struct net_device *dev,
1098 struct iw_request_info *info,
1099 struct iw_param *wrq, char *extra)
Johannes Bergbc92afd2009-07-01 21:26:57 +02001100{
1101 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001102 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Kalle Valoffb9eb32010-02-17 17:58:10 +02001103 bool ps = wdev->ps;
1104 int timeout = wdev->ps_timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02001105 int err;
1106
1107 if (wdev->iftype != NL80211_IFTYPE_STATION)
1108 return -EINVAL;
1109
1110 if (!rdev->ops->set_power_mgmt)
1111 return -EOPNOTSUPP;
1112
1113 if (wrq->disabled) {
1114 ps = false;
1115 } else {
1116 switch (wrq->flags & IW_POWER_MODE) {
1117 case IW_POWER_ON: /* If not specified */
1118 case IW_POWER_MODE: /* If set all mask */
1119 case IW_POWER_ALL_R: /* If explicitely state all */
1120 ps = true;
1121 break;
1122 default: /* Otherwise we ignore */
1123 return -EINVAL;
1124 }
1125
1126 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
1127 return -EINVAL;
1128
1129 if (wrq->flags & IW_POWER_TIMEOUT)
1130 timeout = wrq->value / 1000;
1131 }
1132
Hila Gonene35e4d22012-06-27 17:19:42 +03001133 err = rdev_set_power_mgmt(rdev, dev, ps, timeout);
Johannes Bergbc92afd2009-07-01 21:26:57 +02001134 if (err)
1135 return err;
1136
Kalle Valoffb9eb32010-02-17 17:58:10 +02001137 wdev->ps = ps;
1138 wdev->ps_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02001139
1140 return 0;
1141
1142}
Johannes Bergbc92afd2009-07-01 21:26:57 +02001143
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001144static int cfg80211_wext_giwpower(struct net_device *dev,
1145 struct iw_request_info *info,
1146 struct iw_param *wrq, char *extra)
Johannes Bergbc92afd2009-07-01 21:26:57 +02001147{
1148 struct wireless_dev *wdev = dev->ieee80211_ptr;
1149
Kalle Valoffb9eb32010-02-17 17:58:10 +02001150 wrq->disabled = !wdev->ps;
Johannes Bergbc92afd2009-07-01 21:26:57 +02001151
1152 return 0;
1153}
Johannes Bergab737a42009-07-01 21:26:58 +02001154
Johannes Berg562e4822009-07-27 12:01:51 +02001155static int cfg80211_wds_wext_siwap(struct net_device *dev,
1156 struct iw_request_info *info,
1157 struct sockaddr *addr, char *extra)
Johannes Bergab737a42009-07-01 21:26:58 +02001158{
1159 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001160 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergab737a42009-07-01 21:26:58 +02001161 int err;
1162
1163 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS))
1164 return -EINVAL;
1165
1166 if (addr->sa_family != ARPHRD_ETHER)
1167 return -EINVAL;
1168
1169 if (netif_running(dev))
1170 return -EBUSY;
1171
1172 if (!rdev->ops->set_wds_peer)
1173 return -EOPNOTSUPP;
1174
Hila Gonene35e4d22012-06-27 17:19:42 +03001175 err = rdev_set_wds_peer(rdev, dev, (u8 *)&addr->sa_data);
Johannes Bergab737a42009-07-01 21:26:58 +02001176 if (err)
1177 return err;
1178
1179 memcpy(&wdev->wext.bssid, (u8 *) &addr->sa_data, ETH_ALEN);
1180
1181 return 0;
1182}
Johannes Bergab737a42009-07-01 21:26:58 +02001183
Johannes Berg562e4822009-07-27 12:01:51 +02001184static int cfg80211_wds_wext_giwap(struct net_device *dev,
1185 struct iw_request_info *info,
1186 struct sockaddr *addr, char *extra)
Johannes Bergab737a42009-07-01 21:26:58 +02001187{
1188 struct wireless_dev *wdev = dev->ieee80211_ptr;
1189
1190 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS))
1191 return -EINVAL;
1192
1193 addr->sa_family = ARPHRD_ETHER;
1194 memcpy(&addr->sa_data, wdev->wext.bssid, ETH_ALEN);
1195
1196 return 0;
1197}
Johannes Berg99303802009-07-01 21:26:59 +02001198
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001199static int cfg80211_wext_siwrate(struct net_device *dev,
1200 struct iw_request_info *info,
1201 struct iw_param *rate, char *extra)
Johannes Berg99303802009-07-01 21:26:59 +02001202{
1203 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001204 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg99303802009-07-01 21:26:59 +02001205 struct cfg80211_bitrate_mask mask;
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001206 u32 fixed, maxrate;
1207 struct ieee80211_supported_band *sband;
1208 int band, ridx;
1209 bool match = false;
Johannes Berg99303802009-07-01 21:26:59 +02001210
1211 if (!rdev->ops->set_bitrate_mask)
1212 return -EOPNOTSUPP;
1213
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001214 memset(&mask, 0, sizeof(mask));
1215 fixed = 0;
John W. Linville54233262010-01-27 09:44:48 -05001216 maxrate = (u32)-1;
Johannes Berg99303802009-07-01 21:26:59 +02001217
1218 if (rate->value < 0) {
1219 /* nothing */
1220 } else if (rate->fixed) {
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001221 fixed = rate->value / 100000;
Johannes Berg99303802009-07-01 21:26:59 +02001222 } else {
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001223 maxrate = rate->value / 100000;
Johannes Berg99303802009-07-01 21:26:59 +02001224 }
1225
Johannes Berg57fbcce2016-04-12 15:56:15 +02001226 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001227 sband = wdev->wiphy->bands[band];
1228 if (sband == NULL)
1229 continue;
1230 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
1231 struct ieee80211_rate *srate = &sband->bitrates[ridx];
1232 if (fixed == srate->bitrate) {
1233 mask.control[band].legacy = 1 << ridx;
1234 match = true;
1235 break;
1236 }
1237 if (srate->bitrate <= maxrate) {
1238 mask.control[band].legacy |= 1 << ridx;
1239 match = true;
1240 }
1241 }
1242 }
1243
1244 if (!match)
1245 return -EINVAL;
1246
Hila Gonene35e4d22012-06-27 17:19:42 +03001247 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Johannes Berg99303802009-07-01 21:26:59 +02001248}
Johannes Berg99303802009-07-01 21:26:59 +02001249
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001250static int cfg80211_wext_giwrate(struct net_device *dev,
1251 struct iw_request_info *info,
1252 struct iw_param *rate, char *extra)
Johannes Berg99303802009-07-01 21:26:59 +02001253{
1254 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001255 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg99303802009-07-01 21:26:59 +02001256 /* we are under RTNL - globally locked - so can use a static struct */
1257 static struct station_info sinfo;
Johannes Berga71d62d2009-07-07 23:41:27 +02001258 u8 addr[ETH_ALEN];
Johannes Berg99303802009-07-01 21:26:59 +02001259 int err;
1260
1261 if (wdev->iftype != NL80211_IFTYPE_STATION)
1262 return -EOPNOTSUPP;
1263
1264 if (!rdev->ops->get_station)
1265 return -EOPNOTSUPP;
1266
Johannes Berga71d62d2009-07-07 23:41:27 +02001267 err = 0;
1268 wdev_lock(wdev);
Samuel Ortiz6c230c02009-07-03 02:00:48 +02001269 if (wdev->current_bss)
Johannes Berga71d62d2009-07-07 23:41:27 +02001270 memcpy(addr, wdev->current_bss->pub.bssid, ETH_ALEN);
Samuel Ortiz6c230c02009-07-03 02:00:48 +02001271 else
Johannes Berga71d62d2009-07-07 23:41:27 +02001272 err = -EOPNOTSUPP;
1273 wdev_unlock(wdev);
1274 if (err)
1275 return err;
Johannes Berg99303802009-07-01 21:26:59 +02001276
Hila Gonene35e4d22012-06-27 17:19:42 +03001277 err = rdev_get_station(rdev, dev, addr, &sinfo);
Johannes Berg99303802009-07-01 21:26:59 +02001278 if (err)
1279 return err;
1280
Johannes Berg319090b2014-11-17 14:08:11 +01001281 if (!(sinfo.filled & BIT(NL80211_STA_INFO_TX_BITRATE)))
Johannes Berg99303802009-07-01 21:26:59 +02001282 return -EOPNOTSUPP;
1283
John W. Linville254416a2009-12-09 16:43:52 -05001284 rate->value = 100000 * cfg80211_calculate_bitrate(&sinfo.txrate);
Johannes Berg99303802009-07-01 21:26:59 +02001285
1286 return 0;
1287}
Johannes Berg89906462009-07-01 21:27:00 +02001288
1289/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001290static struct iw_statistics *cfg80211_wireless_stats(struct net_device *dev)
Johannes Berg89906462009-07-01 21:27:00 +02001291{
1292 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001293 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89906462009-07-01 21:27:00 +02001294 /* we are under RTNL - globally locked - so can use static structs */
1295 static struct iw_statistics wstats;
1296 static struct station_info sinfo;
Johannes Bergc56c5712009-07-10 16:54:07 +02001297 u8 bssid[ETH_ALEN];
Johannes Berg89906462009-07-01 21:27:00 +02001298
1299 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION)
1300 return NULL;
1301
1302 if (!rdev->ops->get_station)
1303 return NULL;
1304
Johannes Bergc56c5712009-07-10 16:54:07 +02001305 /* Grab BSSID of current BSS, if any */
1306 wdev_lock(wdev);
1307 if (!wdev->current_bss) {
1308 wdev_unlock(wdev);
Johannes Berg89906462009-07-01 21:27:00 +02001309 return NULL;
Johannes Bergc56c5712009-07-10 16:54:07 +02001310 }
1311 memcpy(bssid, wdev->current_bss->pub.bssid, ETH_ALEN);
1312 wdev_unlock(wdev);
Johannes Berg89906462009-07-01 21:27:00 +02001313
Johannes Berg9c5a18a2015-06-09 21:35:44 +02001314 memset(&sinfo, 0, sizeof(sinfo));
1315
Hila Gonene35e4d22012-06-27 17:19:42 +03001316 if (rdev_get_station(rdev, dev, bssid, &sinfo))
Johannes Berg89906462009-07-01 21:27:00 +02001317 return NULL;
1318
1319 memset(&wstats, 0, sizeof(wstats));
1320
1321 switch (rdev->wiphy.signal_type) {
1322 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01001323 if (sinfo.filled & BIT(NL80211_STA_INFO_SIGNAL)) {
Johannes Berg89906462009-07-01 21:27:00 +02001324 int sig = sinfo.signal;
1325 wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
1326 wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
1327 wstats.qual.updated |= IW_QUAL_DBM;
1328 wstats.qual.level = sig;
1329 if (sig < -110)
1330 sig = -110;
1331 else if (sig > -40)
1332 sig = -40;
1333 wstats.qual.qual = sig + 110;
1334 break;
1335 }
1336 case CFG80211_SIGNAL_TYPE_UNSPEC:
Johannes Berg319090b2014-11-17 14:08:11 +01001337 if (sinfo.filled & BIT(NL80211_STA_INFO_SIGNAL)) {
Johannes Berg89906462009-07-01 21:27:00 +02001338 wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
1339 wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
1340 wstats.qual.level = sinfo.signal;
1341 wstats.qual.qual = sinfo.signal;
1342 break;
1343 }
1344 default:
1345 wstats.qual.updated |= IW_QUAL_LEVEL_INVALID;
1346 wstats.qual.updated |= IW_QUAL_QUAL_INVALID;
1347 }
1348
1349 wstats.qual.updated |= IW_QUAL_NOISE_INVALID;
Johannes Berg319090b2014-11-17 14:08:11 +01001350 if (sinfo.filled & BIT(NL80211_STA_INFO_RX_DROP_MISC))
Ben Greear5a5c7312010-10-07 16:39:20 -07001351 wstats.discard.misc = sinfo.rx_dropped_misc;
Johannes Berg319090b2014-11-17 14:08:11 +01001352 if (sinfo.filled & BIT(NL80211_STA_INFO_TX_FAILED))
Ben Greear5a5c7312010-10-07 16:39:20 -07001353 wstats.discard.retries = sinfo.tx_failed;
Johannes Berg89906462009-07-01 21:27:00 +02001354
1355 return &wstats;
1356}
Johannes Berg562e4822009-07-27 12:01:51 +02001357
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001358static int cfg80211_wext_siwap(struct net_device *dev,
1359 struct iw_request_info *info,
1360 struct sockaddr *ap_addr, char *extra)
Johannes Berg562e4822009-07-27 12:01:51 +02001361{
1362 struct wireless_dev *wdev = dev->ieee80211_ptr;
1363
1364 switch (wdev->iftype) {
1365 case NL80211_IFTYPE_ADHOC:
1366 return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra);
1367 case NL80211_IFTYPE_STATION:
1368 return cfg80211_mgd_wext_siwap(dev, info, ap_addr, extra);
1369 case NL80211_IFTYPE_WDS:
1370 return cfg80211_wds_wext_siwap(dev, info, ap_addr, extra);
1371 default:
1372 return -EOPNOTSUPP;
1373 }
1374}
Johannes Berg562e4822009-07-27 12:01:51 +02001375
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001376static int cfg80211_wext_giwap(struct net_device *dev,
1377 struct iw_request_info *info,
1378 struct sockaddr *ap_addr, char *extra)
Johannes Berg562e4822009-07-27 12:01:51 +02001379{
1380 struct wireless_dev *wdev = dev->ieee80211_ptr;
1381
1382 switch (wdev->iftype) {
1383 case NL80211_IFTYPE_ADHOC:
1384 return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra);
1385 case NL80211_IFTYPE_STATION:
1386 return cfg80211_mgd_wext_giwap(dev, info, ap_addr, extra);
1387 case NL80211_IFTYPE_WDS:
1388 return cfg80211_wds_wext_giwap(dev, info, ap_addr, extra);
1389 default:
1390 return -EOPNOTSUPP;
1391 }
1392}
Johannes Berg1f9298f2009-07-27 12:01:52 +02001393
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001394static int cfg80211_wext_siwessid(struct net_device *dev,
1395 struct iw_request_info *info,
1396 struct iw_point *data, char *ssid)
Johannes Berg1f9298f2009-07-27 12:01:52 +02001397{
1398 struct wireless_dev *wdev = dev->ieee80211_ptr;
1399
1400 switch (wdev->iftype) {
1401 case NL80211_IFTYPE_ADHOC:
1402 return cfg80211_ibss_wext_siwessid(dev, info, data, ssid);
1403 case NL80211_IFTYPE_STATION:
1404 return cfg80211_mgd_wext_siwessid(dev, info, data, ssid);
1405 default:
1406 return -EOPNOTSUPP;
1407 }
1408}
Johannes Berg1f9298f2009-07-27 12:01:52 +02001409
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001410static int cfg80211_wext_giwessid(struct net_device *dev,
1411 struct iw_request_info *info,
1412 struct iw_point *data, char *ssid)
Johannes Berg1f9298f2009-07-27 12:01:52 +02001413{
1414 struct wireless_dev *wdev = dev->ieee80211_ptr;
1415
Johannes Berg42da2f92010-08-30 12:24:54 +02001416 data->flags = 0;
1417 data->length = 0;
1418
Johannes Berg1f9298f2009-07-27 12:01:52 +02001419 switch (wdev->iftype) {
1420 case NL80211_IFTYPE_ADHOC:
1421 return cfg80211_ibss_wext_giwessid(dev, info, data, ssid);
1422 case NL80211_IFTYPE_STATION:
1423 return cfg80211_mgd_wext_giwessid(dev, info, data, ssid);
1424 default:
1425 return -EOPNOTSUPP;
1426 }
1427}
Johannes Berga9a11622009-07-27 12:01:53 +02001428
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001429static int cfg80211_wext_siwpmksa(struct net_device *dev,
1430 struct iw_request_info *info,
1431 struct iw_point *data, char *extra)
Samuel Ortiz2944b2c2009-11-25 00:01:01 +01001432{
1433 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001434 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Samuel Ortiz2944b2c2009-11-25 00:01:01 +01001435 struct cfg80211_pmksa cfg_pmksa;
1436 struct iw_pmksa *pmksa = (struct iw_pmksa *)extra;
1437
1438 memset(&cfg_pmksa, 0, sizeof(struct cfg80211_pmksa));
1439
1440 if (wdev->iftype != NL80211_IFTYPE_STATION)
1441 return -EINVAL;
1442
1443 cfg_pmksa.bssid = pmksa->bssid.sa_data;
1444 cfg_pmksa.pmkid = pmksa->pmkid;
1445
1446 switch (pmksa->cmd) {
1447 case IW_PMKSA_ADD:
1448 if (!rdev->ops->set_pmksa)
1449 return -EOPNOTSUPP;
1450
Hila Gonene35e4d22012-06-27 17:19:42 +03001451 return rdev_set_pmksa(rdev, dev, &cfg_pmksa);
Samuel Ortiz2944b2c2009-11-25 00:01:01 +01001452
1453 case IW_PMKSA_REMOVE:
1454 if (!rdev->ops->del_pmksa)
1455 return -EOPNOTSUPP;
1456
Hila Gonene35e4d22012-06-27 17:19:42 +03001457 return rdev_del_pmksa(rdev, dev, &cfg_pmksa);
Samuel Ortiz2944b2c2009-11-25 00:01:01 +01001458
1459 case IW_PMKSA_FLUSH:
1460 if (!rdev->ops->flush_pmksa)
1461 return -EOPNOTSUPP;
1462
Hila Gonene35e4d22012-06-27 17:19:42 +03001463 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz2944b2c2009-11-25 00:01:01 +01001464
1465 default:
1466 return -EOPNOTSUPP;
1467 }
1468}
1469
Johannes Berga9a11622009-07-27 12:01:53 +02001470static const iw_handler cfg80211_handlers[] = {
1471 [IW_IOCTL_IDX(SIOCGIWNAME)] = (iw_handler) cfg80211_wext_giwname,
1472 [IW_IOCTL_IDX(SIOCSIWFREQ)] = (iw_handler) cfg80211_wext_siwfreq,
1473 [IW_IOCTL_IDX(SIOCGIWFREQ)] = (iw_handler) cfg80211_wext_giwfreq,
1474 [IW_IOCTL_IDX(SIOCSIWMODE)] = (iw_handler) cfg80211_wext_siwmode,
1475 [IW_IOCTL_IDX(SIOCGIWMODE)] = (iw_handler) cfg80211_wext_giwmode,
1476 [IW_IOCTL_IDX(SIOCGIWRANGE)] = (iw_handler) cfg80211_wext_giwrange,
1477 [IW_IOCTL_IDX(SIOCSIWAP)] = (iw_handler) cfg80211_wext_siwap,
1478 [IW_IOCTL_IDX(SIOCGIWAP)] = (iw_handler) cfg80211_wext_giwap,
1479 [IW_IOCTL_IDX(SIOCSIWMLME)] = (iw_handler) cfg80211_wext_siwmlme,
1480 [IW_IOCTL_IDX(SIOCSIWSCAN)] = (iw_handler) cfg80211_wext_siwscan,
1481 [IW_IOCTL_IDX(SIOCGIWSCAN)] = (iw_handler) cfg80211_wext_giwscan,
1482 [IW_IOCTL_IDX(SIOCSIWESSID)] = (iw_handler) cfg80211_wext_siwessid,
1483 [IW_IOCTL_IDX(SIOCGIWESSID)] = (iw_handler) cfg80211_wext_giwessid,
1484 [IW_IOCTL_IDX(SIOCSIWRATE)] = (iw_handler) cfg80211_wext_siwrate,
1485 [IW_IOCTL_IDX(SIOCGIWRATE)] = (iw_handler) cfg80211_wext_giwrate,
1486 [IW_IOCTL_IDX(SIOCSIWRTS)] = (iw_handler) cfg80211_wext_siwrts,
1487 [IW_IOCTL_IDX(SIOCGIWRTS)] = (iw_handler) cfg80211_wext_giwrts,
1488 [IW_IOCTL_IDX(SIOCSIWFRAG)] = (iw_handler) cfg80211_wext_siwfrag,
1489 [IW_IOCTL_IDX(SIOCGIWFRAG)] = (iw_handler) cfg80211_wext_giwfrag,
1490 [IW_IOCTL_IDX(SIOCSIWTXPOW)] = (iw_handler) cfg80211_wext_siwtxpower,
1491 [IW_IOCTL_IDX(SIOCGIWTXPOW)] = (iw_handler) cfg80211_wext_giwtxpower,
1492 [IW_IOCTL_IDX(SIOCSIWRETRY)] = (iw_handler) cfg80211_wext_siwretry,
1493 [IW_IOCTL_IDX(SIOCGIWRETRY)] = (iw_handler) cfg80211_wext_giwretry,
1494 [IW_IOCTL_IDX(SIOCSIWENCODE)] = (iw_handler) cfg80211_wext_siwencode,
1495 [IW_IOCTL_IDX(SIOCGIWENCODE)] = (iw_handler) cfg80211_wext_giwencode,
1496 [IW_IOCTL_IDX(SIOCSIWPOWER)] = (iw_handler) cfg80211_wext_siwpower,
1497 [IW_IOCTL_IDX(SIOCGIWPOWER)] = (iw_handler) cfg80211_wext_giwpower,
1498 [IW_IOCTL_IDX(SIOCSIWGENIE)] = (iw_handler) cfg80211_wext_siwgenie,
1499 [IW_IOCTL_IDX(SIOCSIWAUTH)] = (iw_handler) cfg80211_wext_siwauth,
1500 [IW_IOCTL_IDX(SIOCGIWAUTH)] = (iw_handler) cfg80211_wext_giwauth,
1501 [IW_IOCTL_IDX(SIOCSIWENCODEEXT)]= (iw_handler) cfg80211_wext_siwencodeext,
Samuel Ortiz2944b2c2009-11-25 00:01:01 +01001502 [IW_IOCTL_IDX(SIOCSIWPMKSA)] = (iw_handler) cfg80211_wext_siwpmksa,
Johannes Berga9a11622009-07-27 12:01:53 +02001503};
1504
1505const struct iw_handler_def cfg80211_wext_handler = {
1506 .num_standard = ARRAY_SIZE(cfg80211_handlers),
1507 .standard = cfg80211_handlers,
1508 .get_wireless_stats = cfg80211_wireless_stats,
1509};