blob: e7c6e862580dcf64df32b4f499f7ae1c42c67609 [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{
28 struct wireless_dev *wdev = dev->ieee80211_ptr;
29 struct ieee80211_supported_band *sband;
30 bool is_ht = false, is_a = false, is_b = false, is_g = false;
31
32 if (!wdev)
33 return -EOPNOTSUPP;
34
35 sband = wdev->wiphy->bands[IEEE80211_BAND_5GHZ];
36 if (sband) {
37 is_a = true;
38 is_ht |= sband->ht_cap.ht_supported;
39 }
40
41 sband = wdev->wiphy->bands[IEEE80211_BAND_2GHZ];
42 if (sband) {
43 int i;
44 /* Check for mandatory rates */
45 for (i = 0; i < sband->n_bitrates; i++) {
46 if (sband->bitrates[i].bitrate == 10)
47 is_b = true;
48 if (sband->bitrates[i].bitrate == 60)
49 is_g = true;
50 }
51 is_ht |= sband->ht_cap.ht_supported;
52 }
53
54 strcpy(name, "IEEE 802.11");
55 if (is_a)
56 strcat(name, "a");
57 if (is_b)
58 strcat(name, "b");
59 if (is_g)
60 strcat(name, "g");
61 if (is_ht)
62 strcat(name, "n");
63
64 return 0;
65}
Johannes Bergba44cb72009-04-20 18:49:39 +020066EXPORT_SYMBOL_GPL(cfg80211_wext_giwname);
Johannes Berge60c7742008-11-26 23:31:40 +010067
68int cfg80211_wext_siwmode(struct net_device *dev, struct iw_request_info *info,
69 u32 *mode, char *extra)
70{
71 struct wireless_dev *wdev = dev->ieee80211_ptr;
72 struct cfg80211_registered_device *rdev;
73 struct vif_params vifparams;
74 enum nl80211_iftype type;
75
Johannes Berge60c7742008-11-26 23:31:40 +010076 rdev = wiphy_to_dev(wdev->wiphy);
77
Johannes Berge60c7742008-11-26 23:31:40 +010078 switch (*mode) {
79 case IW_MODE_INFRA:
80 type = NL80211_IFTYPE_STATION;
81 break;
82 case IW_MODE_ADHOC:
83 type = NL80211_IFTYPE_ADHOC;
84 break;
85 case IW_MODE_REPEAT:
86 type = NL80211_IFTYPE_WDS;
87 break;
88 case IW_MODE_MONITOR:
89 type = NL80211_IFTYPE_MONITOR;
90 break;
91 default:
92 return -EINVAL;
93 }
94
Johannes Bergac7f9cf2009-03-21 17:07:59 +010095 if (type == wdev->iftype)
96 return 0;
97
Johannes Berge60c7742008-11-26 23:31:40 +010098 memset(&vifparams, 0, sizeof(vifparams));
99
Johannes Berg5fe231e2013-05-08 21:45:15 +0200100 return cfg80211_change_iface(rdev, dev, type, NULL, &vifparams);
Johannes Berge60c7742008-11-26 23:31:40 +0100101}
Johannes Bergba44cb72009-04-20 18:49:39 +0200102EXPORT_SYMBOL_GPL(cfg80211_wext_siwmode);
Johannes Berge60c7742008-11-26 23:31:40 +0100103
104int cfg80211_wext_giwmode(struct net_device *dev, struct iw_request_info *info,
105 u32 *mode, char *extra)
106{
107 struct wireless_dev *wdev = dev->ieee80211_ptr;
108
109 if (!wdev)
110 return -EOPNOTSUPP;
111
112 switch (wdev->iftype) {
113 case NL80211_IFTYPE_AP:
114 *mode = IW_MODE_MASTER;
115 break;
116 case NL80211_IFTYPE_STATION:
117 *mode = IW_MODE_INFRA;
118 break;
119 case NL80211_IFTYPE_ADHOC:
120 *mode = IW_MODE_ADHOC;
121 break;
122 case NL80211_IFTYPE_MONITOR:
123 *mode = IW_MODE_MONITOR;
124 break;
125 case NL80211_IFTYPE_WDS:
126 *mode = IW_MODE_REPEAT;
127 break;
128 case NL80211_IFTYPE_AP_VLAN:
129 *mode = IW_MODE_SECOND; /* FIXME */
130 break;
131 default:
132 *mode = IW_MODE_AUTO;
133 break;
134 }
135 return 0;
136}
Johannes Bergba44cb72009-04-20 18:49:39 +0200137EXPORT_SYMBOL_GPL(cfg80211_wext_giwmode);
Johannes Berg4aa188e2009-02-18 19:32:08 +0100138
139
140int cfg80211_wext_giwrange(struct net_device *dev,
141 struct iw_request_info *info,
142 struct iw_point *data, char *extra)
143{
144 struct wireless_dev *wdev = dev->ieee80211_ptr;
145 struct iw_range *range = (struct iw_range *) extra;
146 enum ieee80211_band band;
Johannes Berg9834c072009-07-06 19:40:51 +0200147 int i, c = 0;
Johannes Berg4aa188e2009-02-18 19:32:08 +0100148
149 if (!wdev)
150 return -EOPNOTSUPP;
151
152 data->length = sizeof(struct iw_range);
153 memset(range, 0, sizeof(struct iw_range));
154
155 range->we_version_compiled = WIRELESS_EXT;
156 range->we_version_source = 21;
157 range->retry_capa = IW_RETRY_LIMIT;
158 range->retry_flags = IW_RETRY_LIMIT;
159 range->min_retry = 0;
160 range->max_retry = 255;
161 range->min_rts = 0;
162 range->max_rts = 2347;
163 range->min_frag = 256;
164 range->max_frag = 2346;
165
Johannes Berg4aa188e2009-02-18 19:32:08 +0100166 range->max_encoding_tokens = 4;
167
168 range->max_qual.updated = IW_QUAL_NOISE_INVALID;
169
170 switch (wdev->wiphy->signal_type) {
171 case CFG80211_SIGNAL_TYPE_NONE:
172 break;
173 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berge7d83ed2012-12-07 11:58:26 +0100174 range->max_qual.level = (u8)-110;
Johannes Berg4aa188e2009-02-18 19:32:08 +0100175 range->max_qual.qual = 70;
176 range->avg_qual.qual = 35;
177 range->max_qual.updated |= IW_QUAL_DBM;
178 range->max_qual.updated |= IW_QUAL_QUAL_UPDATED;
179 range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED;
180 break;
181 case CFG80211_SIGNAL_TYPE_UNSPEC:
182 range->max_qual.level = 100;
183 range->max_qual.qual = 100;
184 range->avg_qual.qual = 50;
185 range->max_qual.updated |= IW_QUAL_QUAL_UPDATED;
186 range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED;
187 break;
188 }
189
190 range->avg_qual.level = range->max_qual.level / 2;
191 range->avg_qual.noise = range->max_qual.noise / 2;
192 range->avg_qual.updated = range->max_qual.updated;
193
Johannes Berg9834c072009-07-06 19:40:51 +0200194 for (i = 0; i < wdev->wiphy->n_cipher_suites; i++) {
195 switch (wdev->wiphy->cipher_suites[i]) {
David Kilroy3daf0972009-06-18 23:21:14 +0100196 case WLAN_CIPHER_SUITE_TKIP:
David Kilroy27bea662009-06-18 23:21:17 +0100197 range->enc_capa |= (IW_ENC_CAPA_CIPHER_TKIP |
198 IW_ENC_CAPA_WPA);
David Kilroy3daf0972009-06-18 23:21:14 +0100199 break;
200
201 case WLAN_CIPHER_SUITE_CCMP:
David Kilroy27bea662009-06-18 23:21:17 +0100202 range->enc_capa |= (IW_ENC_CAPA_CIPHER_CCMP |
203 IW_ENC_CAPA_WPA2);
David Kilroy3daf0972009-06-18 23:21:14 +0100204 break;
David Kilroy2ab658f2009-06-18 23:21:16 +0100205
206 case WLAN_CIPHER_SUITE_WEP40:
207 range->encoding_size[range->num_encoding_sizes++] =
208 WLAN_KEY_LEN_WEP40;
209 break;
210
211 case WLAN_CIPHER_SUITE_WEP104:
212 range->encoding_size[range->num_encoding_sizes++] =
213 WLAN_KEY_LEN_WEP104;
214 break;
David Kilroy3daf0972009-06-18 23:21:14 +0100215 }
216 }
Johannes Berg4aa188e2009-02-18 19:32:08 +0100217
Johannes Berg4aa188e2009-02-18 19:32:08 +0100218 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
Johannes Berg4aa188e2009-02-18 19:32:08 +0100219 struct ieee80211_supported_band *sband;
220
221 sband = wdev->wiphy->bands[band];
222
223 if (!sband)
224 continue;
225
226 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
227 struct ieee80211_channel *chan = &sband->channels[i];
228
229 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
230 range->freq[c].i =
231 ieee80211_frequency_to_channel(
232 chan->center_freq);
233 range->freq[c].m = chan->center_freq;
234 range->freq[c].e = 6;
235 c++;
236 }
237 }
238 }
239 range->num_channels = c;
240 range->num_frequency = c;
241
242 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
243 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
244 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
245
David Kilroy51cd4aa2009-06-18 23:21:15 +0100246 if (wdev->wiphy->max_scan_ssids > 0)
247 range->scan_capa |= IW_SCAN_CAPA_ESSID;
Johannes Berg4aa188e2009-02-18 19:32:08 +0100248
249 return 0;
250}
Johannes Bergba44cb72009-04-20 18:49:39 +0200251EXPORT_SYMBOL_GPL(cfg80211_wext_giwrange);
Johannes Berg691597c2009-04-19 19:57:45 +0200252
Johannes Berg04a773a2009-04-19 21:24:32 +0200253
254/**
255 * cfg80211_wext_freq - get wext frequency for non-"auto"
256 * @wiphy: the wiphy
257 * @freq: the wext freq encoding
258 *
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200259 * Returns a frequency, or a negative error code, or 0 for auto.
Johannes Berg04a773a2009-04-19 21:24:32 +0200260 */
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200261int cfg80211_wext_freq(struct wiphy *wiphy, struct iw_freq *freq)
Johannes Berg04a773a2009-04-19 21:24:32 +0200262{
Johannes Berg0b258582009-05-08 09:42:33 +0200263 /*
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200264 * Parse frequency - return 0 for auto and
Johannes Berg0b258582009-05-08 09:42:33 +0200265 * -EINVAL for impossible things.
266 */
Johannes Berg04a773a2009-04-19 21:24:32 +0200267 if (freq->e == 0) {
Bruno Randolf59eb21a2011-01-17 13:37:28 +0900268 enum ieee80211_band band = IEEE80211_BAND_2GHZ;
Johannes Berg04a773a2009-04-19 21:24:32 +0200269 if (freq->m < 0)
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200270 return 0;
Bruno Randolf59eb21a2011-01-17 13:37:28 +0900271 if (freq->m > 14)
272 band = IEEE80211_BAND_5GHZ;
273 return ieee80211_channel_to_frequency(freq->m, band);
Johannes Berg04a773a2009-04-19 21:24:32 +0200274 } else {
275 int i, div = 1000000;
276 for (i = 0; i < freq->e; i++)
277 div /= 10;
Johannes Berg0b258582009-05-08 09:42:33 +0200278 if (div <= 0)
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200279 return -EINVAL;
280 return freq->m / div;
Johannes Berg04a773a2009-04-19 21:24:32 +0200281 }
Johannes Berg04a773a2009-04-19 21:24:32 +0200282}
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200283
284int cfg80211_wext_siwrts(struct net_device *dev,
285 struct iw_request_info *info,
286 struct iw_param *rts, char *extra)
287{
288 struct wireless_dev *wdev = dev->ieee80211_ptr;
289 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
290 u32 orts = wdev->wiphy->rts_threshold;
291 int err;
292
293 if (rts->disabled || !rts->fixed)
294 wdev->wiphy->rts_threshold = (u32) -1;
295 else if (rts->value < 0)
296 return -EINVAL;
297 else
298 wdev->wiphy->rts_threshold = rts->value;
299
Hila Gonene35e4d22012-06-27 17:19:42 +0300300 err = rdev_set_wiphy_params(rdev, WIPHY_PARAM_RTS_THRESHOLD);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200301 if (err)
302 wdev->wiphy->rts_threshold = orts;
303
304 return err;
305}
Johannes Bergba44cb72009-04-20 18:49:39 +0200306EXPORT_SYMBOL_GPL(cfg80211_wext_siwrts);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200307
308int cfg80211_wext_giwrts(struct net_device *dev,
309 struct iw_request_info *info,
310 struct iw_param *rts, char *extra)
311{
312 struct wireless_dev *wdev = dev->ieee80211_ptr;
313
314 rts->value = wdev->wiphy->rts_threshold;
315 rts->disabled = rts->value == (u32) -1;
316 rts->fixed = 1;
317
318 return 0;
319}
Johannes Bergba44cb72009-04-20 18:49:39 +0200320EXPORT_SYMBOL_GPL(cfg80211_wext_giwrts);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200321
322int cfg80211_wext_siwfrag(struct net_device *dev,
323 struct iw_request_info *info,
324 struct iw_param *frag, char *extra)
325{
326 struct wireless_dev *wdev = dev->ieee80211_ptr;
327 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
328 u32 ofrag = wdev->wiphy->frag_threshold;
329 int err;
330
331 if (frag->disabled || !frag->fixed)
332 wdev->wiphy->frag_threshold = (u32) -1;
333 else if (frag->value < 256)
334 return -EINVAL;
335 else {
336 /* Fragment length must be even, so strip LSB. */
337 wdev->wiphy->frag_threshold = frag->value & ~0x1;
338 }
339
Hila Gonene35e4d22012-06-27 17:19:42 +0300340 err = rdev_set_wiphy_params(rdev, WIPHY_PARAM_FRAG_THRESHOLD);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200341 if (err)
342 wdev->wiphy->frag_threshold = ofrag;
343
344 return err;
345}
Johannes Bergba44cb72009-04-20 18:49:39 +0200346EXPORT_SYMBOL_GPL(cfg80211_wext_siwfrag);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200347
348int cfg80211_wext_giwfrag(struct net_device *dev,
349 struct iw_request_info *info,
350 struct iw_param *frag, char *extra)
351{
352 struct wireless_dev *wdev = dev->ieee80211_ptr;
353
354 frag->value = wdev->wiphy->frag_threshold;
355 frag->disabled = frag->value == (u32) -1;
356 frag->fixed = 1;
357
358 return 0;
359}
Johannes Bergba44cb72009-04-20 18:49:39 +0200360EXPORT_SYMBOL_GPL(cfg80211_wext_giwfrag);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200361
Johannes Berg04b0c5c2011-07-15 13:01:38 +0200362static int cfg80211_wext_siwretry(struct net_device *dev,
363 struct iw_request_info *info,
364 struct iw_param *retry, char *extra)
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200365{
366 struct wireless_dev *wdev = dev->ieee80211_ptr;
367 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
368 u32 changed = 0;
369 u8 olong = wdev->wiphy->retry_long;
370 u8 oshort = wdev->wiphy->retry_short;
371 int err;
372
373 if (retry->disabled ||
374 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
375 return -EINVAL;
376
377 if (retry->flags & IW_RETRY_LONG) {
378 wdev->wiphy->retry_long = retry->value;
379 changed |= WIPHY_PARAM_RETRY_LONG;
380 } else if (retry->flags & IW_RETRY_SHORT) {
381 wdev->wiphy->retry_short = retry->value;
382 changed |= WIPHY_PARAM_RETRY_SHORT;
383 } else {
384 wdev->wiphy->retry_short = retry->value;
385 wdev->wiphy->retry_long = retry->value;
386 changed |= WIPHY_PARAM_RETRY_LONG;
387 changed |= WIPHY_PARAM_RETRY_SHORT;
388 }
389
390 if (!changed)
391 return 0;
392
Hila Gonene35e4d22012-06-27 17:19:42 +0300393 err = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200394 if (err) {
395 wdev->wiphy->retry_short = oshort;
396 wdev->wiphy->retry_long = olong;
397 }
398
399 return err;
400}
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200401
402int cfg80211_wext_giwretry(struct net_device *dev,
403 struct iw_request_info *info,
404 struct iw_param *retry, char *extra)
405{
406 struct wireless_dev *wdev = dev->ieee80211_ptr;
407
408 retry->disabled = 0;
409
410 if (retry->flags == 0 || (retry->flags & IW_RETRY_SHORT)) {
411 /*
412 * First return short value, iwconfig will ask long value
413 * later if needed
414 */
415 retry->flags |= IW_RETRY_LIMIT;
416 retry->value = wdev->wiphy->retry_short;
417 if (wdev->wiphy->retry_long != wdev->wiphy->retry_short)
418 retry->flags |= IW_RETRY_LONG;
419
420 return 0;
421 }
422
423 if (retry->flags & IW_RETRY_LONG) {
424 retry->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
425 retry->value = wdev->wiphy->retry_long;
426 }
427
428 return 0;
429}
Johannes Bergba44cb72009-04-20 18:49:39 +0200430EXPORT_SYMBOL_GPL(cfg80211_wext_giwretry);
Johannes Berg08645122009-05-11 13:54:58 +0200431
Johannes Bergfffd0932009-07-08 14:22:54 +0200432static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
Johannes Berge31b8212010-10-05 19:39:30 +0200433 struct net_device *dev, bool pairwise,
434 const u8 *addr, bool remove, bool tx_key,
435 int idx, struct key_params *params)
Johannes Berg08645122009-05-11 13:54:58 +0200436{
437 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergfffd0932009-07-08 14:22:54 +0200438 int err, i;
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100439 bool rejoin = false;
Johannes Bergfffd0932009-07-08 14:22:54 +0200440
Johannes Berge31b8212010-10-05 19:39:30 +0200441 if (pairwise && !addr)
442 return -EINVAL;
443
Johannes Bergfffd0932009-07-08 14:22:54 +0200444 if (!wdev->wext.keys) {
445 wdev->wext.keys = kzalloc(sizeof(*wdev->wext.keys),
446 GFP_KERNEL);
447 if (!wdev->wext.keys)
448 return -ENOMEM;
449 for (i = 0; i < 6; i++)
450 wdev->wext.keys->params[i].key =
451 wdev->wext.keys->data[i];
452 }
453
454 if (wdev->iftype != NL80211_IFTYPE_ADHOC &&
455 wdev->iftype != NL80211_IFTYPE_STATION)
456 return -EOPNOTSUPP;
Johannes Berg08645122009-05-11 13:54:58 +0200457
458 if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
Johannes Bergfffd0932009-07-08 14:22:54 +0200459 if (!wdev->current_bss)
460 return -ENOLINK;
461
Johannes Berg08645122009-05-11 13:54:58 +0200462 if (!rdev->ops->set_default_mgmt_key)
463 return -EOPNOTSUPP;
464
465 if (idx < 4 || idx > 5)
466 return -EINVAL;
467 } else if (idx < 0 || idx > 3)
468 return -EINVAL;
469
470 if (remove) {
Johannes Bergfffd0932009-07-08 14:22:54 +0200471 err = 0;
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100472 if (wdev->current_bss) {
473 /*
474 * If removing the current TX key, we will need to
475 * join a new IBSS without the privacy bit clear.
476 */
477 if (idx == wdev->wext.default_key &&
478 wdev->iftype == NL80211_IFTYPE_ADHOC) {
479 __cfg80211_leave_ibss(rdev, wdev->netdev, true);
480 rejoin = true;
481 }
Johannes Berge31b8212010-10-05 19:39:30 +0200482
483 if (!pairwise && addr &&
484 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
485 err = -ENOENT;
486 else
Hila Gonene35e4d22012-06-27 17:19:42 +0300487 err = rdev_del_key(rdev, dev, idx, pairwise,
488 addr);
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100489 }
Vivek Natarajand55fb892009-11-24 11:54:10 -0500490 wdev->wext.connect.privacy = false;
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100491 /*
492 * Applications using wireless extensions expect to be
493 * able to delete keys that don't exist, so allow that.
494 */
495 if (err == -ENOENT)
496 err = 0;
Johannes Berg08645122009-05-11 13:54:58 +0200497 if (!err) {
Johannes Bergfffd0932009-07-08 14:22:54 +0200498 if (!addr) {
499 wdev->wext.keys->params[idx].key_len = 0;
500 wdev->wext.keys->params[idx].cipher = 0;
501 }
Johannes Berg08645122009-05-11 13:54:58 +0200502 if (idx == wdev->wext.default_key)
503 wdev->wext.default_key = -1;
504 else if (idx == wdev->wext.default_mgmt_key)
505 wdev->wext.default_mgmt_key = -1;
506 }
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100507
508 if (!err && rejoin)
509 err = cfg80211_ibss_wext_join(rdev, wdev);
Johannes Berge3da5742009-05-18 19:56:36 +0200510
Johannes Berg08645122009-05-11 13:54:58 +0200511 return err;
Johannes Bergfffd0932009-07-08 14:22:54 +0200512 }
Johannes Berg08645122009-05-11 13:54:58 +0200513
Johannes Bergfffd0932009-07-08 14:22:54 +0200514 if (addr)
515 tx_key = false;
Johannes Berg08645122009-05-11 13:54:58 +0200516
Johannes Berge31b8212010-10-05 19:39:30 +0200517 if (cfg80211_validate_key_settings(rdev, params, idx, pairwise, addr))
Johannes Bergfffd0932009-07-08 14:22:54 +0200518 return -EINVAL;
519
520 err = 0;
521 if (wdev->current_bss)
Hila Gonene35e4d22012-06-27 17:19:42 +0300522 err = rdev_add_key(rdev, dev, idx, pairwise, addr, params);
Johannes Bergfffd0932009-07-08 14:22:54 +0200523 if (err)
524 return err;
Johannes Berg08645122009-05-11 13:54:58 +0200525
Johannes Bergfffd0932009-07-08 14:22:54 +0200526 if (!addr) {
527 wdev->wext.keys->params[idx] = *params;
528 memcpy(wdev->wext.keys->data[idx],
529 params->key, params->key_len);
530 wdev->wext.keys->params[idx].key =
531 wdev->wext.keys->data[idx];
532 }
533
Zhu Yi1f00fca2009-07-20 11:47:43 +0800534 if ((params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
535 params->cipher == WLAN_CIPHER_SUITE_WEP104) &&
Johannes Bergfffd0932009-07-08 14:22:54 +0200536 (tx_key || (!addr && wdev->wext.default_key == -1))) {
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100537 if (wdev->current_bss) {
538 /*
539 * If we are getting a new TX key from not having
540 * had one before we need to join a new IBSS with
541 * the privacy bit set.
542 */
543 if (wdev->iftype == NL80211_IFTYPE_ADHOC &&
544 wdev->wext.default_key == -1) {
545 __cfg80211_leave_ibss(rdev, wdev->netdev, true);
546 rejoin = true;
547 }
Hila Gonene35e4d22012-06-27 17:19:42 +0300548 err = rdev_set_default_key(rdev, dev, idx, true, true);
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100549 }
550 if (!err) {
Johannes Bergfffd0932009-07-08 14:22:54 +0200551 wdev->wext.default_key = idx;
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100552 if (rejoin)
553 err = cfg80211_ibss_wext_join(rdev, wdev);
554 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200555 return err;
556 }
Johannes Berg08645122009-05-11 13:54:58 +0200557
Johannes Bergfffd0932009-07-08 14:22:54 +0200558 if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC &&
559 (tx_key || (!addr && wdev->wext.default_mgmt_key == -1))) {
560 if (wdev->current_bss)
Hila Gonene35e4d22012-06-27 17:19:42 +0300561 err = rdev_set_default_mgmt_key(rdev, dev, idx);
Johannes Bergfffd0932009-07-08 14:22:54 +0200562 if (!err)
563 wdev->wext.default_mgmt_key = idx;
564 return err;
Johannes Berg08645122009-05-11 13:54:58 +0200565 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200566
567 return 0;
568}
569
570static int cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
Johannes Berge31b8212010-10-05 19:39:30 +0200571 struct net_device *dev, bool pairwise,
572 const u8 *addr, bool remove, bool tx_key,
573 int idx, struct key_params *params)
Johannes Bergfffd0932009-07-08 14:22:54 +0200574{
575 int err;
576
577 wdev_lock(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +0200578 err = __cfg80211_set_encryption(rdev, dev, pairwise, addr,
579 remove, tx_key, idx, params);
Johannes Bergfffd0932009-07-08 14:22:54 +0200580 wdev_unlock(dev->ieee80211_ptr);
581
582 return err;
Johannes Berg08645122009-05-11 13:54:58 +0200583}
584
Johannes Berg04b0c5c2011-07-15 13:01:38 +0200585static int cfg80211_wext_siwencode(struct net_device *dev,
586 struct iw_request_info *info,
587 struct iw_point *erq, char *keybuf)
Johannes Berg08645122009-05-11 13:54:58 +0200588{
589 struct wireless_dev *wdev = dev->ieee80211_ptr;
590 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
591 int idx, err;
592 bool remove = false;
593 struct key_params params;
594
Johannes Bergfffd0932009-07-08 14:22:54 +0200595 if (wdev->iftype != NL80211_IFTYPE_STATION &&
596 wdev->iftype != NL80211_IFTYPE_ADHOC)
597 return -EOPNOTSUPP;
598
Johannes Berg08645122009-05-11 13:54:58 +0200599 /* no use -- only MFP (set_default_mgmt_key) is optional */
600 if (!rdev->ops->del_key ||
601 !rdev->ops->add_key ||
602 !rdev->ops->set_default_key)
603 return -EOPNOTSUPP;
604
605 idx = erq->flags & IW_ENCODE_INDEX;
606 if (idx == 0) {
607 idx = wdev->wext.default_key;
608 if (idx < 0)
609 idx = 0;
610 } else if (idx < 1 || idx > 4)
611 return -EINVAL;
612 else
613 idx--;
614
615 if (erq->flags & IW_ENCODE_DISABLED)
616 remove = true;
617 else if (erq->length == 0) {
618 /* No key data - just set the default TX key index */
Johannes Bergfffd0932009-07-08 14:22:54 +0200619 err = 0;
620 wdev_lock(wdev);
621 if (wdev->current_bss)
Hila Gonene35e4d22012-06-27 17:19:42 +0300622 err = rdev_set_default_key(rdev, dev, idx, true,
623 true);
Johannes Berg08645122009-05-11 13:54:58 +0200624 if (!err)
625 wdev->wext.default_key = idx;
Johannes Bergfffd0932009-07-08 14:22:54 +0200626 wdev_unlock(wdev);
Johannes Berg08645122009-05-11 13:54:58 +0200627 return err;
628 }
629
630 memset(&params, 0, sizeof(params));
631 params.key = keybuf;
632 params.key_len = erq->length;
633 if (erq->length == 5)
634 params.cipher = WLAN_CIPHER_SUITE_WEP40;
635 else if (erq->length == 13)
636 params.cipher = WLAN_CIPHER_SUITE_WEP104;
637 else if (!remove)
638 return -EINVAL;
639
Johannes Berge31b8212010-10-05 19:39:30 +0200640 return cfg80211_set_encryption(rdev, dev, false, NULL, remove,
Johannes Berg08645122009-05-11 13:54:58 +0200641 wdev->wext.default_key == -1,
642 idx, &params);
643}
Johannes Berg08645122009-05-11 13:54:58 +0200644
Johannes Berg04b0c5c2011-07-15 13:01:38 +0200645static int cfg80211_wext_siwencodeext(struct net_device *dev,
646 struct iw_request_info *info,
647 struct iw_point *erq, char *extra)
Johannes Berg08645122009-05-11 13:54:58 +0200648{
649 struct wireless_dev *wdev = dev->ieee80211_ptr;
650 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
651 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
652 const u8 *addr;
653 int idx;
654 bool remove = false;
655 struct key_params params;
656 u32 cipher;
657
Johannes Bergfffd0932009-07-08 14:22:54 +0200658 if (wdev->iftype != NL80211_IFTYPE_STATION &&
659 wdev->iftype != NL80211_IFTYPE_ADHOC)
660 return -EOPNOTSUPP;
661
Johannes Berg08645122009-05-11 13:54:58 +0200662 /* no use -- only MFP (set_default_mgmt_key) is optional */
663 if (!rdev->ops->del_key ||
664 !rdev->ops->add_key ||
665 !rdev->ops->set_default_key)
666 return -EOPNOTSUPP;
667
668 switch (ext->alg) {
669 case IW_ENCODE_ALG_NONE:
670 remove = true;
671 cipher = 0;
672 break;
673 case IW_ENCODE_ALG_WEP:
674 if (ext->key_len == 5)
675 cipher = WLAN_CIPHER_SUITE_WEP40;
676 else if (ext->key_len == 13)
677 cipher = WLAN_CIPHER_SUITE_WEP104;
678 else
679 return -EINVAL;
680 break;
681 case IW_ENCODE_ALG_TKIP:
682 cipher = WLAN_CIPHER_SUITE_TKIP;
683 break;
684 case IW_ENCODE_ALG_CCMP:
685 cipher = WLAN_CIPHER_SUITE_CCMP;
686 break;
687 case IW_ENCODE_ALG_AES_CMAC:
688 cipher = WLAN_CIPHER_SUITE_AES_CMAC;
689 break;
690 default:
691 return -EOPNOTSUPP;
692 }
693
694 if (erq->flags & IW_ENCODE_DISABLED)
695 remove = true;
696
697 idx = erq->flags & IW_ENCODE_INDEX;
698 if (cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
699 if (idx < 4 || idx > 5) {
700 idx = wdev->wext.default_mgmt_key;
701 if (idx < 0)
702 return -EINVAL;
703 } else
704 idx--;
705 } else {
706 if (idx < 1 || idx > 4) {
707 idx = wdev->wext.default_key;
708 if (idx < 0)
709 return -EINVAL;
710 } else
711 idx--;
712 }
713
714 addr = ext->addr.sa_data;
715 if (is_broadcast_ether_addr(addr))
716 addr = NULL;
717
718 memset(&params, 0, sizeof(params));
719 params.key = ext->key;
720 params.key_len = ext->key_len;
721 params.cipher = cipher;
722
Jouni Malinenfaa8fdc2009-05-11 21:57:58 +0300723 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
724 params.seq = ext->rx_seq;
725 params.seq_len = 6;
726 }
727
Johannes Berg08645122009-05-11 13:54:58 +0200728 return cfg80211_set_encryption(
Johannes Berge31b8212010-10-05 19:39:30 +0200729 rdev, dev,
730 !(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY),
731 addr, remove,
Johannes Berg08645122009-05-11 13:54:58 +0200732 ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
733 idx, &params);
734}
Johannes Berg08645122009-05-11 13:54:58 +0200735
Johannes Berg04b0c5c2011-07-15 13:01:38 +0200736static int cfg80211_wext_giwencode(struct net_device *dev,
737 struct iw_request_info *info,
738 struct iw_point *erq, char *keybuf)
Johannes Berg08645122009-05-11 13:54:58 +0200739{
740 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergfffd0932009-07-08 14:22:54 +0200741 int idx;
Johannes Berg08645122009-05-11 13:54:58 +0200742
Johannes Bergfffd0932009-07-08 14:22:54 +0200743 if (wdev->iftype != NL80211_IFTYPE_STATION &&
744 wdev->iftype != NL80211_IFTYPE_ADHOC)
Johannes Berg08645122009-05-11 13:54:58 +0200745 return -EOPNOTSUPP;
746
747 idx = erq->flags & IW_ENCODE_INDEX;
748 if (idx == 0) {
749 idx = wdev->wext.default_key;
750 if (idx < 0)
751 idx = 0;
752 } else if (idx < 1 || idx > 4)
753 return -EINVAL;
754 else
755 idx--;
756
757 erq->flags = idx + 1;
758
Johannes Bergfffd0932009-07-08 14:22:54 +0200759 if (!wdev->wext.keys || !wdev->wext.keys->params[idx].cipher) {
Johannes Berg08645122009-05-11 13:54:58 +0200760 erq->flags |= IW_ENCODE_DISABLED;
761 erq->length = 0;
762 return 0;
763 }
764
Johannes Bergfffd0932009-07-08 14:22:54 +0200765 erq->length = min_t(size_t, erq->length,
766 wdev->wext.keys->params[idx].key_len);
767 memcpy(keybuf, wdev->wext.keys->params[idx].key, erq->length);
768 erq->flags |= IW_ENCODE_ENABLED;
769
770 return 0;
Johannes Berg08645122009-05-11 13:54:58 +0200771}
Johannes Berg7643a2c2009-06-02 13:01:39 +0200772
Johannes Berg04b0c5c2011-07-15 13:01:38 +0200773static int cfg80211_wext_siwfreq(struct net_device *dev,
774 struct iw_request_info *info,
775 struct iw_freq *wextfreq, char *extra)
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200776{
777 struct wireless_dev *wdev = dev->ieee80211_ptr;
778 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Johannes Berg683b6d32012-11-08 21:25:48 +0100779 struct cfg80211_chan_def chandef = {
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100780 .width = NL80211_CHAN_WIDTH_20_NOHT,
Johannes Berg683b6d32012-11-08 21:25:48 +0100781 };
Johannes Berg5fe231e2013-05-08 21:45:15 +0200782 int freq;
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200783
784 switch (wdev->iftype) {
785 case NL80211_IFTYPE_STATION:
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200786 return cfg80211_mgd_wext_siwfreq(dev, info, wextfreq, extra);
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200787 case NL80211_IFTYPE_ADHOC:
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200788 return cfg80211_ibss_wext_siwfreq(dev, info, wextfreq, extra);
Johannes Bergf444de02010-05-05 15:25:02 +0200789 case NL80211_IFTYPE_MONITOR:
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200790 freq = cfg80211_wext_freq(wdev->wiphy, wextfreq);
791 if (freq < 0)
792 return freq;
793 if (freq == 0)
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200794 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100795 chandef.center_freq1 = freq;
Johannes Berg683b6d32012-11-08 21:25:48 +0100796 chandef.chan = ieee80211_get_channel(&rdev->wiphy, freq);
797 if (!chandef.chan)
798 return -EINVAL;
Johannes Berg5fe231e2013-05-08 21:45:15 +0200799 return cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +0200800 case NL80211_IFTYPE_MESH_POINT:
801 freq = cfg80211_wext_freq(wdev->wiphy, wextfreq);
802 if (freq < 0)
803 return freq;
804 if (freq == 0)
805 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100806 chandef.center_freq1 = freq;
Johannes Berg683b6d32012-11-08 21:25:48 +0100807 chandef.chan = ieee80211_get_channel(&rdev->wiphy, freq);
808 if (!chandef.chan)
809 return -EINVAL;
Johannes Berg5fe231e2013-05-08 21:45:15 +0200810 return cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergf444de02010-05-05 15:25:02 +0200811 default:
812 return -EOPNOTSUPP;
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200813 }
814}
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200815
Johannes Berg04b0c5c2011-07-15 13:01:38 +0200816static int cfg80211_wext_giwfreq(struct net_device *dev,
817 struct iw_request_info *info,
818 struct iw_freq *freq, char *extra)
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200819{
820 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berge9998822011-11-09 10:30:21 +0100821 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Johannes Berg683b6d32012-11-08 21:25:48 +0100822 struct cfg80211_chan_def chandef;
823 int ret;
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200824
825 switch (wdev->iftype) {
826 case NL80211_IFTYPE_STATION:
827 return cfg80211_mgd_wext_giwfreq(dev, info, freq, extra);
828 case NL80211_IFTYPE_ADHOC:
829 return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra);
Johannes Berge9998822011-11-09 10:30:21 +0100830 case NL80211_IFTYPE_MONITOR:
Johannes Berg5b7ccaf2012-07-12 19:45:08 +0200831 if (!rdev->ops->get_channel)
Johannes Berge9998822011-11-09 10:30:21 +0100832 return -EINVAL;
833
Johannes Berg683b6d32012-11-08 21:25:48 +0100834 ret = rdev_get_channel(rdev, wdev, &chandef);
835 if (ret)
836 return ret;
837 freq->m = chandef.chan->center_freq;
Johannes Berge9998822011-11-09 10:30:21 +0100838 freq->e = 6;
839 return 0;
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200840 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +0200841 return -EINVAL;
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200842 }
843}
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200844
Johannes Berg04b0c5c2011-07-15 13:01:38 +0200845static int cfg80211_wext_siwtxpower(struct net_device *dev,
846 struct iw_request_info *info,
847 union iwreq_data *data, char *extra)
Johannes Berg7643a2c2009-06-02 13:01:39 +0200848{
849 struct wireless_dev *wdev = dev->ieee80211_ptr;
850 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +0300851 enum nl80211_tx_power_setting type;
Johannes Berg7643a2c2009-06-02 13:01:39 +0200852 int dbm = 0;
853
854 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
855 return -EINVAL;
856 if (data->txpower.flags & IW_TXPOW_RANGE)
857 return -EINVAL;
858
859 if (!rdev->ops->set_tx_power)
860 return -EOPNOTSUPP;
861
862 /* only change when not disabling */
863 if (!data->txpower.disabled) {
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200864 rfkill_set_sw_state(rdev->rfkill, false);
865
Johannes Berg7643a2c2009-06-02 13:01:39 +0200866 if (data->txpower.fixed) {
867 /*
868 * wext doesn't support negative values, see
869 * below where it's for automatic
870 */
871 if (data->txpower.value < 0)
872 return -EINVAL;
873 dbm = data->txpower.value;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +0300874 type = NL80211_TX_POWER_FIXED;
Johannes Berg7643a2c2009-06-02 13:01:39 +0200875 /* TODO: do regulatory check! */
876 } else {
877 /*
878 * Automatic power level setting, max being the value
879 * passed in from userland.
880 */
881 if (data->txpower.value < 0) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +0300882 type = NL80211_TX_POWER_AUTOMATIC;
Johannes Berg7643a2c2009-06-02 13:01:39 +0200883 } else {
884 dbm = data->txpower.value;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +0300885 type = NL80211_TX_POWER_LIMITED;
Johannes Berg7643a2c2009-06-02 13:01:39 +0200886 }
887 }
888 } else {
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200889 rfkill_set_sw_state(rdev->rfkill, true);
890 schedule_work(&rdev->rfkill_sync);
891 return 0;
Johannes Berg7643a2c2009-06-02 13:01:39 +0200892 }
893
Johannes Bergc8442112012-10-24 10:17:18 +0200894 return rdev_set_tx_power(rdev, wdev, type, DBM_TO_MBM(dbm));
Johannes Berg7643a2c2009-06-02 13:01:39 +0200895}
Johannes Berg7643a2c2009-06-02 13:01:39 +0200896
Johannes Berg04b0c5c2011-07-15 13:01:38 +0200897static int cfg80211_wext_giwtxpower(struct net_device *dev,
898 struct iw_request_info *info,
899 union iwreq_data *data, char *extra)
Johannes Berg7643a2c2009-06-02 13:01:39 +0200900{
901 struct wireless_dev *wdev = dev->ieee80211_ptr;
902 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
903 int err, val;
904
905 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
906 return -EINVAL;
907 if (data->txpower.flags & IW_TXPOW_RANGE)
908 return -EINVAL;
909
910 if (!rdev->ops->get_tx_power)
911 return -EOPNOTSUPP;
912
Johannes Bergc8442112012-10-24 10:17:18 +0200913 err = rdev_get_tx_power(rdev, wdev, &val);
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200914 if (err)
Johannes Berg7643a2c2009-06-02 13:01:39 +0200915 return err;
916
917 /* well... oh well */
918 data->txpower.fixed = 1;
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200919 data->txpower.disabled = rfkill_blocked(rdev->rfkill);
Johannes Berg7643a2c2009-06-02 13:01:39 +0200920 data->txpower.value = val;
921 data->txpower.flags = IW_TXPOW_DBM;
922
923 return 0;
924}
Johannes Bergf2129352009-07-01 21:26:56 +0200925
926static int cfg80211_set_auth_alg(struct wireless_dev *wdev,
927 s32 auth_alg)
928{
929 int nr_alg = 0;
930
931 if (!auth_alg)
932 return -EINVAL;
933
934 if (auth_alg & ~(IW_AUTH_ALG_OPEN_SYSTEM |
935 IW_AUTH_ALG_SHARED_KEY |
936 IW_AUTH_ALG_LEAP))
937 return -EINVAL;
938
939 if (auth_alg & IW_AUTH_ALG_OPEN_SYSTEM) {
940 nr_alg++;
941 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
942 }
943
944 if (auth_alg & IW_AUTH_ALG_SHARED_KEY) {
945 nr_alg++;
946 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_SHARED_KEY;
947 }
948
949 if (auth_alg & IW_AUTH_ALG_LEAP) {
950 nr_alg++;
951 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_NETWORK_EAP;
952 }
953
954 if (nr_alg > 1)
955 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
956
957 return 0;
958}
959
960static int cfg80211_set_wpa_version(struct wireless_dev *wdev, u32 wpa_versions)
961{
Johannes Bergf2129352009-07-01 21:26:56 +0200962 if (wpa_versions & ~(IW_AUTH_WPA_VERSION_WPA |
Gábor Stefanik323d5662009-07-12 02:03:48 +0200963 IW_AUTH_WPA_VERSION_WPA2|
964 IW_AUTH_WPA_VERSION_DISABLED))
Johannes Bergf2129352009-07-01 21:26:56 +0200965 return -EINVAL;
966
Gábor Stefanik323d5662009-07-12 02:03:48 +0200967 if ((wpa_versions & IW_AUTH_WPA_VERSION_DISABLED) &&
968 (wpa_versions & (IW_AUTH_WPA_VERSION_WPA|
969 IW_AUTH_WPA_VERSION_WPA2)))
970 return -EINVAL;
971
972 if (wpa_versions & IW_AUTH_WPA_VERSION_DISABLED)
973 wdev->wext.connect.crypto.wpa_versions &=
974 ~(NL80211_WPA_VERSION_1|NL80211_WPA_VERSION_2);
975
Johannes Bergf2129352009-07-01 21:26:56 +0200976 if (wpa_versions & IW_AUTH_WPA_VERSION_WPA)
977 wdev->wext.connect.crypto.wpa_versions |=
978 NL80211_WPA_VERSION_1;
979
980 if (wpa_versions & IW_AUTH_WPA_VERSION_WPA2)
981 wdev->wext.connect.crypto.wpa_versions |=
982 NL80211_WPA_VERSION_2;
983
984 return 0;
985}
986
Johannes Berg4f5dadc2009-07-07 03:56:10 +0200987static int cfg80211_set_cipher_group(struct wireless_dev *wdev, u32 cipher)
Johannes Bergf2129352009-07-01 21:26:56 +0200988{
Johannes Bergf2129352009-07-01 21:26:56 +0200989 if (cipher & IW_AUTH_CIPHER_WEP40)
990 wdev->wext.connect.crypto.cipher_group =
991 WLAN_CIPHER_SUITE_WEP40;
992 else if (cipher & IW_AUTH_CIPHER_WEP104)
993 wdev->wext.connect.crypto.cipher_group =
994 WLAN_CIPHER_SUITE_WEP104;
995 else if (cipher & IW_AUTH_CIPHER_TKIP)
996 wdev->wext.connect.crypto.cipher_group =
997 WLAN_CIPHER_SUITE_TKIP;
998 else if (cipher & IW_AUTH_CIPHER_CCMP)
999 wdev->wext.connect.crypto.cipher_group =
1000 WLAN_CIPHER_SUITE_CCMP;
1001 else if (cipher & IW_AUTH_CIPHER_AES_CMAC)
1002 wdev->wext.connect.crypto.cipher_group =
1003 WLAN_CIPHER_SUITE_AES_CMAC;
Jouni Malinenc5f82892009-11-01 11:18:49 +02001004 else if (cipher & IW_AUTH_CIPHER_NONE)
1005 wdev->wext.connect.crypto.cipher_group = 0;
Johannes Bergf2129352009-07-01 21:26:56 +02001006 else
1007 return -EINVAL;
1008
1009 return 0;
1010}
1011
Johannes Berg4f5dadc2009-07-07 03:56:10 +02001012static int cfg80211_set_cipher_pairwise(struct wireless_dev *wdev, u32 cipher)
Johannes Bergf2129352009-07-01 21:26:56 +02001013{
1014 int nr_ciphers = 0;
1015 u32 *ciphers_pairwise = wdev->wext.connect.crypto.ciphers_pairwise;
1016
1017 if (cipher & IW_AUTH_CIPHER_WEP40) {
1018 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP40;
1019 nr_ciphers++;
1020 }
1021
1022 if (cipher & IW_AUTH_CIPHER_WEP104) {
1023 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP104;
1024 nr_ciphers++;
1025 }
1026
1027 if (cipher & IW_AUTH_CIPHER_TKIP) {
1028 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_TKIP;
1029 nr_ciphers++;
1030 }
1031
1032 if (cipher & IW_AUTH_CIPHER_CCMP) {
1033 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_CCMP;
1034 nr_ciphers++;
1035 }
1036
1037 if (cipher & IW_AUTH_CIPHER_AES_CMAC) {
1038 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_AES_CMAC;
1039 nr_ciphers++;
1040 }
1041
1042 BUILD_BUG_ON(NL80211_MAX_NR_CIPHER_SUITES < 5);
1043
1044 wdev->wext.connect.crypto.n_ciphers_pairwise = nr_ciphers;
1045
1046 return 0;
1047}
1048
1049
Johannes Berg4f5dadc2009-07-07 03:56:10 +02001050static int cfg80211_set_key_mgt(struct wireless_dev *wdev, u32 key_mgt)
Johannes Bergf2129352009-07-01 21:26:56 +02001051{
1052 int nr_akm_suites = 0;
1053
1054 if (key_mgt & ~(IW_AUTH_KEY_MGMT_802_1X |
1055 IW_AUTH_KEY_MGMT_PSK))
1056 return -EINVAL;
1057
1058 if (key_mgt & IW_AUTH_KEY_MGMT_802_1X) {
1059 wdev->wext.connect.crypto.akm_suites[nr_akm_suites] =
1060 WLAN_AKM_SUITE_8021X;
1061 nr_akm_suites++;
1062 }
1063
1064 if (key_mgt & IW_AUTH_KEY_MGMT_PSK) {
1065 wdev->wext.connect.crypto.akm_suites[nr_akm_suites] =
1066 WLAN_AKM_SUITE_PSK;
1067 nr_akm_suites++;
1068 }
1069
1070 wdev->wext.connect.crypto.n_akm_suites = nr_akm_suites;
1071
1072 return 0;
1073}
1074
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001075static int cfg80211_wext_siwauth(struct net_device *dev,
1076 struct iw_request_info *info,
1077 struct iw_param *data, char *extra)
Johannes Bergf2129352009-07-01 21:26:56 +02001078{
1079 struct wireless_dev *wdev = dev->ieee80211_ptr;
1080
1081 if (wdev->iftype != NL80211_IFTYPE_STATION)
1082 return -EOPNOTSUPP;
1083
1084 switch (data->flags & IW_AUTH_INDEX) {
1085 case IW_AUTH_PRIVACY_INVOKED:
1086 wdev->wext.connect.privacy = data->value;
1087 return 0;
1088 case IW_AUTH_WPA_VERSION:
1089 return cfg80211_set_wpa_version(wdev, data->value);
1090 case IW_AUTH_CIPHER_GROUP:
1091 return cfg80211_set_cipher_group(wdev, data->value);
1092 case IW_AUTH_KEY_MGMT:
1093 return cfg80211_set_key_mgt(wdev, data->value);
1094 case IW_AUTH_CIPHER_PAIRWISE:
1095 return cfg80211_set_cipher_pairwise(wdev, data->value);
1096 case IW_AUTH_80211_AUTH_ALG:
1097 return cfg80211_set_auth_alg(wdev, data->value);
1098 case IW_AUTH_WPA_ENABLED:
1099 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1100 case IW_AUTH_DROP_UNENCRYPTED:
1101 case IW_AUTH_MFP:
1102 return 0;
1103 default:
1104 return -EOPNOTSUPP;
1105 }
1106}
Johannes Bergf2129352009-07-01 21:26:56 +02001107
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001108static int cfg80211_wext_giwauth(struct net_device *dev,
1109 struct iw_request_info *info,
1110 struct iw_param *data, char *extra)
Johannes Bergf2129352009-07-01 21:26:56 +02001111{
1112 /* XXX: what do we need? */
1113
1114 return -EOPNOTSUPP;
1115}
Johannes Bergbc92afd2009-07-01 21:26:57 +02001116
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001117static int cfg80211_wext_siwpower(struct net_device *dev,
1118 struct iw_request_info *info,
1119 struct iw_param *wrq, char *extra)
Johannes Bergbc92afd2009-07-01 21:26:57 +02001120{
1121 struct wireless_dev *wdev = dev->ieee80211_ptr;
1122 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Kalle Valoffb9eb32010-02-17 17:58:10 +02001123 bool ps = wdev->ps;
1124 int timeout = wdev->ps_timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02001125 int err;
1126
1127 if (wdev->iftype != NL80211_IFTYPE_STATION)
1128 return -EINVAL;
1129
1130 if (!rdev->ops->set_power_mgmt)
1131 return -EOPNOTSUPP;
1132
1133 if (wrq->disabled) {
1134 ps = false;
1135 } else {
1136 switch (wrq->flags & IW_POWER_MODE) {
1137 case IW_POWER_ON: /* If not specified */
1138 case IW_POWER_MODE: /* If set all mask */
1139 case IW_POWER_ALL_R: /* If explicitely state all */
1140 ps = true;
1141 break;
1142 default: /* Otherwise we ignore */
1143 return -EINVAL;
1144 }
1145
1146 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
1147 return -EINVAL;
1148
1149 if (wrq->flags & IW_POWER_TIMEOUT)
1150 timeout = wrq->value / 1000;
1151 }
1152
Hila Gonene35e4d22012-06-27 17:19:42 +03001153 err = rdev_set_power_mgmt(rdev, dev, ps, timeout);
Johannes Bergbc92afd2009-07-01 21:26:57 +02001154 if (err)
1155 return err;
1156
Kalle Valoffb9eb32010-02-17 17:58:10 +02001157 wdev->ps = ps;
1158 wdev->ps_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02001159
1160 return 0;
1161
1162}
Johannes Bergbc92afd2009-07-01 21:26:57 +02001163
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001164static int cfg80211_wext_giwpower(struct net_device *dev,
1165 struct iw_request_info *info,
1166 struct iw_param *wrq, char *extra)
Johannes Bergbc92afd2009-07-01 21:26:57 +02001167{
1168 struct wireless_dev *wdev = dev->ieee80211_ptr;
1169
Kalle Valoffb9eb32010-02-17 17:58:10 +02001170 wrq->disabled = !wdev->ps;
Johannes Bergbc92afd2009-07-01 21:26:57 +02001171
1172 return 0;
1173}
Johannes Bergab737a42009-07-01 21:26:58 +02001174
Johannes Berg562e4822009-07-27 12:01:51 +02001175static int cfg80211_wds_wext_siwap(struct net_device *dev,
1176 struct iw_request_info *info,
1177 struct sockaddr *addr, char *extra)
Johannes Bergab737a42009-07-01 21:26:58 +02001178{
1179 struct wireless_dev *wdev = dev->ieee80211_ptr;
1180 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1181 int err;
1182
1183 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS))
1184 return -EINVAL;
1185
1186 if (addr->sa_family != ARPHRD_ETHER)
1187 return -EINVAL;
1188
1189 if (netif_running(dev))
1190 return -EBUSY;
1191
1192 if (!rdev->ops->set_wds_peer)
1193 return -EOPNOTSUPP;
1194
Hila Gonene35e4d22012-06-27 17:19:42 +03001195 err = rdev_set_wds_peer(rdev, dev, (u8 *)&addr->sa_data);
Johannes Bergab737a42009-07-01 21:26:58 +02001196 if (err)
1197 return err;
1198
1199 memcpy(&wdev->wext.bssid, (u8 *) &addr->sa_data, ETH_ALEN);
1200
1201 return 0;
1202}
Johannes Bergab737a42009-07-01 21:26:58 +02001203
Johannes Berg562e4822009-07-27 12:01:51 +02001204static int cfg80211_wds_wext_giwap(struct net_device *dev,
1205 struct iw_request_info *info,
1206 struct sockaddr *addr, char *extra)
Johannes Bergab737a42009-07-01 21:26:58 +02001207{
1208 struct wireless_dev *wdev = dev->ieee80211_ptr;
1209
1210 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS))
1211 return -EINVAL;
1212
1213 addr->sa_family = ARPHRD_ETHER;
1214 memcpy(&addr->sa_data, wdev->wext.bssid, ETH_ALEN);
1215
1216 return 0;
1217}
Johannes Berg99303802009-07-01 21:26:59 +02001218
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001219static int cfg80211_wext_siwrate(struct net_device *dev,
1220 struct iw_request_info *info,
1221 struct iw_param *rate, char *extra)
Johannes Berg99303802009-07-01 21:26:59 +02001222{
1223 struct wireless_dev *wdev = dev->ieee80211_ptr;
1224 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1225 struct cfg80211_bitrate_mask mask;
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001226 u32 fixed, maxrate;
1227 struct ieee80211_supported_band *sband;
1228 int band, ridx;
1229 bool match = false;
Johannes Berg99303802009-07-01 21:26:59 +02001230
1231 if (!rdev->ops->set_bitrate_mask)
1232 return -EOPNOTSUPP;
1233
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001234 memset(&mask, 0, sizeof(mask));
1235 fixed = 0;
John W. Linville54233262010-01-27 09:44:48 -05001236 maxrate = (u32)-1;
Johannes Berg99303802009-07-01 21:26:59 +02001237
1238 if (rate->value < 0) {
1239 /* nothing */
1240 } else if (rate->fixed) {
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001241 fixed = rate->value / 100000;
Johannes Berg99303802009-07-01 21:26:59 +02001242 } else {
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001243 maxrate = rate->value / 100000;
Johannes Berg99303802009-07-01 21:26:59 +02001244 }
1245
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001246 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1247 sband = wdev->wiphy->bands[band];
1248 if (sband == NULL)
1249 continue;
1250 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
1251 struct ieee80211_rate *srate = &sband->bitrates[ridx];
1252 if (fixed == srate->bitrate) {
1253 mask.control[band].legacy = 1 << ridx;
1254 match = true;
1255 break;
1256 }
1257 if (srate->bitrate <= maxrate) {
1258 mask.control[band].legacy |= 1 << ridx;
1259 match = true;
1260 }
1261 }
1262 }
1263
1264 if (!match)
1265 return -EINVAL;
1266
Hila Gonene35e4d22012-06-27 17:19:42 +03001267 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Johannes Berg99303802009-07-01 21:26:59 +02001268}
Johannes Berg99303802009-07-01 21:26:59 +02001269
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001270static int cfg80211_wext_giwrate(struct net_device *dev,
1271 struct iw_request_info *info,
1272 struct iw_param *rate, char *extra)
Johannes Berg99303802009-07-01 21:26:59 +02001273{
1274 struct wireless_dev *wdev = dev->ieee80211_ptr;
1275 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1276 /* we are under RTNL - globally locked - so can use a static struct */
1277 static struct station_info sinfo;
Johannes Berga71d62d2009-07-07 23:41:27 +02001278 u8 addr[ETH_ALEN];
Johannes Berg99303802009-07-01 21:26:59 +02001279 int err;
1280
1281 if (wdev->iftype != NL80211_IFTYPE_STATION)
1282 return -EOPNOTSUPP;
1283
1284 if (!rdev->ops->get_station)
1285 return -EOPNOTSUPP;
1286
Johannes Berga71d62d2009-07-07 23:41:27 +02001287 err = 0;
1288 wdev_lock(wdev);
Samuel Ortiz6c230c02009-07-03 02:00:48 +02001289 if (wdev->current_bss)
Johannes Berga71d62d2009-07-07 23:41:27 +02001290 memcpy(addr, wdev->current_bss->pub.bssid, ETH_ALEN);
Samuel Ortiz6c230c02009-07-03 02:00:48 +02001291 else
Johannes Berga71d62d2009-07-07 23:41:27 +02001292 err = -EOPNOTSUPP;
1293 wdev_unlock(wdev);
1294 if (err)
1295 return err;
Johannes Berg99303802009-07-01 21:26:59 +02001296
Hila Gonene35e4d22012-06-27 17:19:42 +03001297 err = rdev_get_station(rdev, dev, addr, &sinfo);
Johannes Berg99303802009-07-01 21:26:59 +02001298 if (err)
1299 return err;
1300
1301 if (!(sinfo.filled & STATION_INFO_TX_BITRATE))
1302 return -EOPNOTSUPP;
1303
John W. Linville254416a2009-12-09 16:43:52 -05001304 rate->value = 100000 * cfg80211_calculate_bitrate(&sinfo.txrate);
Johannes Berg99303802009-07-01 21:26:59 +02001305
1306 return 0;
1307}
Johannes Berg89906462009-07-01 21:27:00 +02001308
1309/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001310static struct iw_statistics *cfg80211_wireless_stats(struct net_device *dev)
Johannes Berg89906462009-07-01 21:27:00 +02001311{
1312 struct wireless_dev *wdev = dev->ieee80211_ptr;
1313 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1314 /* we are under RTNL - globally locked - so can use static structs */
1315 static struct iw_statistics wstats;
1316 static struct station_info sinfo;
Johannes Bergc56c5712009-07-10 16:54:07 +02001317 u8 bssid[ETH_ALEN];
Johannes Berg89906462009-07-01 21:27:00 +02001318
1319 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION)
1320 return NULL;
1321
1322 if (!rdev->ops->get_station)
1323 return NULL;
1324
Johannes Bergc56c5712009-07-10 16:54:07 +02001325 /* Grab BSSID of current BSS, if any */
1326 wdev_lock(wdev);
1327 if (!wdev->current_bss) {
1328 wdev_unlock(wdev);
Johannes Berg89906462009-07-01 21:27:00 +02001329 return NULL;
Johannes Bergc56c5712009-07-10 16:54:07 +02001330 }
1331 memcpy(bssid, wdev->current_bss->pub.bssid, ETH_ALEN);
1332 wdev_unlock(wdev);
Johannes Berg89906462009-07-01 21:27:00 +02001333
Hila Gonene35e4d22012-06-27 17:19:42 +03001334 if (rdev_get_station(rdev, dev, bssid, &sinfo))
Johannes Berg89906462009-07-01 21:27:00 +02001335 return NULL;
1336
1337 memset(&wstats, 0, sizeof(wstats));
1338
1339 switch (rdev->wiphy.signal_type) {
1340 case CFG80211_SIGNAL_TYPE_MBM:
1341 if (sinfo.filled & STATION_INFO_SIGNAL) {
1342 int sig = sinfo.signal;
1343 wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
1344 wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
1345 wstats.qual.updated |= IW_QUAL_DBM;
1346 wstats.qual.level = sig;
1347 if (sig < -110)
1348 sig = -110;
1349 else if (sig > -40)
1350 sig = -40;
1351 wstats.qual.qual = sig + 110;
1352 break;
1353 }
1354 case CFG80211_SIGNAL_TYPE_UNSPEC:
1355 if (sinfo.filled & STATION_INFO_SIGNAL) {
1356 wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
1357 wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
1358 wstats.qual.level = sinfo.signal;
1359 wstats.qual.qual = sinfo.signal;
1360 break;
1361 }
1362 default:
1363 wstats.qual.updated |= IW_QUAL_LEVEL_INVALID;
1364 wstats.qual.updated |= IW_QUAL_QUAL_INVALID;
1365 }
1366
1367 wstats.qual.updated |= IW_QUAL_NOISE_INVALID;
Ben Greear5a5c7312010-10-07 16:39:20 -07001368 if (sinfo.filled & STATION_INFO_RX_DROP_MISC)
1369 wstats.discard.misc = sinfo.rx_dropped_misc;
1370 if (sinfo.filled & STATION_INFO_TX_FAILED)
1371 wstats.discard.retries = sinfo.tx_failed;
Johannes Berg89906462009-07-01 21:27:00 +02001372
1373 return &wstats;
1374}
Johannes Berg562e4822009-07-27 12:01:51 +02001375
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001376static int cfg80211_wext_siwap(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_siwap(dev, info, ap_addr, extra);
1385 case NL80211_IFTYPE_STATION:
1386 return cfg80211_mgd_wext_siwap(dev, info, ap_addr, extra);
1387 case NL80211_IFTYPE_WDS:
1388 return cfg80211_wds_wext_siwap(dev, info, ap_addr, extra);
1389 default:
1390 return -EOPNOTSUPP;
1391 }
1392}
Johannes Berg562e4822009-07-27 12:01:51 +02001393
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001394static int cfg80211_wext_giwap(struct net_device *dev,
1395 struct iw_request_info *info,
1396 struct sockaddr *ap_addr, char *extra)
Johannes Berg562e4822009-07-27 12:01:51 +02001397{
1398 struct wireless_dev *wdev = dev->ieee80211_ptr;
1399
1400 switch (wdev->iftype) {
1401 case NL80211_IFTYPE_ADHOC:
1402 return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra);
1403 case NL80211_IFTYPE_STATION:
1404 return cfg80211_mgd_wext_giwap(dev, info, ap_addr, extra);
1405 case NL80211_IFTYPE_WDS:
1406 return cfg80211_wds_wext_giwap(dev, info, ap_addr, extra);
1407 default:
1408 return -EOPNOTSUPP;
1409 }
1410}
Johannes Berg1f9298f2009-07-27 12:01:52 +02001411
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001412static int cfg80211_wext_siwessid(struct net_device *dev,
1413 struct iw_request_info *info,
1414 struct iw_point *data, char *ssid)
Johannes Berg1f9298f2009-07-27 12:01:52 +02001415{
1416 struct wireless_dev *wdev = dev->ieee80211_ptr;
1417
1418 switch (wdev->iftype) {
1419 case NL80211_IFTYPE_ADHOC:
1420 return cfg80211_ibss_wext_siwessid(dev, info, data, ssid);
1421 case NL80211_IFTYPE_STATION:
1422 return cfg80211_mgd_wext_siwessid(dev, info, data, ssid);
1423 default:
1424 return -EOPNOTSUPP;
1425 }
1426}
Johannes Berg1f9298f2009-07-27 12:01:52 +02001427
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001428static int cfg80211_wext_giwessid(struct net_device *dev,
1429 struct iw_request_info *info,
1430 struct iw_point *data, char *ssid)
Johannes Berg1f9298f2009-07-27 12:01:52 +02001431{
1432 struct wireless_dev *wdev = dev->ieee80211_ptr;
1433
Johannes Berg42da2f92010-08-30 12:24:54 +02001434 data->flags = 0;
1435 data->length = 0;
1436
Johannes Berg1f9298f2009-07-27 12:01:52 +02001437 switch (wdev->iftype) {
1438 case NL80211_IFTYPE_ADHOC:
1439 return cfg80211_ibss_wext_giwessid(dev, info, data, ssid);
1440 case NL80211_IFTYPE_STATION:
1441 return cfg80211_mgd_wext_giwessid(dev, info, data, ssid);
1442 default:
1443 return -EOPNOTSUPP;
1444 }
1445}
Johannes Berga9a11622009-07-27 12:01:53 +02001446
Johannes Berg04b0c5c2011-07-15 13:01:38 +02001447static int cfg80211_wext_siwpmksa(struct net_device *dev,
1448 struct iw_request_info *info,
1449 struct iw_point *data, char *extra)
Samuel Ortiz2944b2c2009-11-25 00:01:01 +01001450{
1451 struct wireless_dev *wdev = dev->ieee80211_ptr;
1452 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1453 struct cfg80211_pmksa cfg_pmksa;
1454 struct iw_pmksa *pmksa = (struct iw_pmksa *)extra;
1455
1456 memset(&cfg_pmksa, 0, sizeof(struct cfg80211_pmksa));
1457
1458 if (wdev->iftype != NL80211_IFTYPE_STATION)
1459 return -EINVAL;
1460
1461 cfg_pmksa.bssid = pmksa->bssid.sa_data;
1462 cfg_pmksa.pmkid = pmksa->pmkid;
1463
1464 switch (pmksa->cmd) {
1465 case IW_PMKSA_ADD:
1466 if (!rdev->ops->set_pmksa)
1467 return -EOPNOTSUPP;
1468
Hila Gonene35e4d22012-06-27 17:19:42 +03001469 return rdev_set_pmksa(rdev, dev, &cfg_pmksa);
Samuel Ortiz2944b2c2009-11-25 00:01:01 +01001470
1471 case IW_PMKSA_REMOVE:
1472 if (!rdev->ops->del_pmksa)
1473 return -EOPNOTSUPP;
1474
Hila Gonene35e4d22012-06-27 17:19:42 +03001475 return rdev_del_pmksa(rdev, dev, &cfg_pmksa);
Samuel Ortiz2944b2c2009-11-25 00:01:01 +01001476
1477 case IW_PMKSA_FLUSH:
1478 if (!rdev->ops->flush_pmksa)
1479 return -EOPNOTSUPP;
1480
Hila Gonene35e4d22012-06-27 17:19:42 +03001481 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz2944b2c2009-11-25 00:01:01 +01001482
1483 default:
1484 return -EOPNOTSUPP;
1485 }
1486}
1487
Johannes Berga9a11622009-07-27 12:01:53 +02001488static const iw_handler cfg80211_handlers[] = {
1489 [IW_IOCTL_IDX(SIOCGIWNAME)] = (iw_handler) cfg80211_wext_giwname,
1490 [IW_IOCTL_IDX(SIOCSIWFREQ)] = (iw_handler) cfg80211_wext_siwfreq,
1491 [IW_IOCTL_IDX(SIOCGIWFREQ)] = (iw_handler) cfg80211_wext_giwfreq,
1492 [IW_IOCTL_IDX(SIOCSIWMODE)] = (iw_handler) cfg80211_wext_siwmode,
1493 [IW_IOCTL_IDX(SIOCGIWMODE)] = (iw_handler) cfg80211_wext_giwmode,
1494 [IW_IOCTL_IDX(SIOCGIWRANGE)] = (iw_handler) cfg80211_wext_giwrange,
1495 [IW_IOCTL_IDX(SIOCSIWAP)] = (iw_handler) cfg80211_wext_siwap,
1496 [IW_IOCTL_IDX(SIOCGIWAP)] = (iw_handler) cfg80211_wext_giwap,
1497 [IW_IOCTL_IDX(SIOCSIWMLME)] = (iw_handler) cfg80211_wext_siwmlme,
1498 [IW_IOCTL_IDX(SIOCSIWSCAN)] = (iw_handler) cfg80211_wext_siwscan,
1499 [IW_IOCTL_IDX(SIOCGIWSCAN)] = (iw_handler) cfg80211_wext_giwscan,
1500 [IW_IOCTL_IDX(SIOCSIWESSID)] = (iw_handler) cfg80211_wext_siwessid,
1501 [IW_IOCTL_IDX(SIOCGIWESSID)] = (iw_handler) cfg80211_wext_giwessid,
1502 [IW_IOCTL_IDX(SIOCSIWRATE)] = (iw_handler) cfg80211_wext_siwrate,
1503 [IW_IOCTL_IDX(SIOCGIWRATE)] = (iw_handler) cfg80211_wext_giwrate,
1504 [IW_IOCTL_IDX(SIOCSIWRTS)] = (iw_handler) cfg80211_wext_siwrts,
1505 [IW_IOCTL_IDX(SIOCGIWRTS)] = (iw_handler) cfg80211_wext_giwrts,
1506 [IW_IOCTL_IDX(SIOCSIWFRAG)] = (iw_handler) cfg80211_wext_siwfrag,
1507 [IW_IOCTL_IDX(SIOCGIWFRAG)] = (iw_handler) cfg80211_wext_giwfrag,
1508 [IW_IOCTL_IDX(SIOCSIWTXPOW)] = (iw_handler) cfg80211_wext_siwtxpower,
1509 [IW_IOCTL_IDX(SIOCGIWTXPOW)] = (iw_handler) cfg80211_wext_giwtxpower,
1510 [IW_IOCTL_IDX(SIOCSIWRETRY)] = (iw_handler) cfg80211_wext_siwretry,
1511 [IW_IOCTL_IDX(SIOCGIWRETRY)] = (iw_handler) cfg80211_wext_giwretry,
1512 [IW_IOCTL_IDX(SIOCSIWENCODE)] = (iw_handler) cfg80211_wext_siwencode,
1513 [IW_IOCTL_IDX(SIOCGIWENCODE)] = (iw_handler) cfg80211_wext_giwencode,
1514 [IW_IOCTL_IDX(SIOCSIWPOWER)] = (iw_handler) cfg80211_wext_siwpower,
1515 [IW_IOCTL_IDX(SIOCGIWPOWER)] = (iw_handler) cfg80211_wext_giwpower,
1516 [IW_IOCTL_IDX(SIOCSIWGENIE)] = (iw_handler) cfg80211_wext_siwgenie,
1517 [IW_IOCTL_IDX(SIOCSIWAUTH)] = (iw_handler) cfg80211_wext_siwauth,
1518 [IW_IOCTL_IDX(SIOCGIWAUTH)] = (iw_handler) cfg80211_wext_giwauth,
1519 [IW_IOCTL_IDX(SIOCSIWENCODEEXT)]= (iw_handler) cfg80211_wext_siwencodeext,
Samuel Ortiz2944b2c2009-11-25 00:01:01 +01001520 [IW_IOCTL_IDX(SIOCSIWPMKSA)] = (iw_handler) cfg80211_wext_siwpmksa,
Johannes Berga9a11622009-07-27 12:01:53 +02001521};
1522
1523const struct iw_handler_def cfg80211_wext_handler = {
1524 .num_standard = ARRAY_SIZE(cfg80211_handlers),
1525 .standard = cfg80211_handlers,
1526 .get_wireless_stats = cfg80211_wireless_stats,
1527};