blob: 0bf169bb770ed695b9829b234511ba0ce576cb58 [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
11#include <linux/wireless.h>
12#include <linux/nl80211.h>
Johannes Berg691597c2009-04-19 19:57:45 +020013#include <linux/if_arp.h>
Johannes Berg08645122009-05-11 13:54:58 +020014#include <linux/etherdevice.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/slab.h>
Johannes Bergfee52672008-11-26 22:36:31 +010016#include <net/iw_handler.h>
Johannes Bergfee52672008-11-26 22:36:31 +010017#include <net/cfg80211.h>
Johannes Berg0e82ffe2009-07-27 12:01:50 +020018#include "wext-compat.h"
Johannes Bergfee52672008-11-26 22:36:31 +010019#include "core.h"
20
21int cfg80211_wext_giwname(struct net_device *dev,
22 struct iw_request_info *info,
23 char *name, char *extra)
24{
25 struct wireless_dev *wdev = dev->ieee80211_ptr;
26 struct ieee80211_supported_band *sband;
27 bool is_ht = false, is_a = false, is_b = false, is_g = false;
28
29 if (!wdev)
30 return -EOPNOTSUPP;
31
32 sband = wdev->wiphy->bands[IEEE80211_BAND_5GHZ];
33 if (sband) {
34 is_a = true;
35 is_ht |= sband->ht_cap.ht_supported;
36 }
37
38 sband = wdev->wiphy->bands[IEEE80211_BAND_2GHZ];
39 if (sband) {
40 int i;
41 /* Check for mandatory rates */
42 for (i = 0; i < sband->n_bitrates; i++) {
43 if (sband->bitrates[i].bitrate == 10)
44 is_b = true;
45 if (sband->bitrates[i].bitrate == 60)
46 is_g = true;
47 }
48 is_ht |= sband->ht_cap.ht_supported;
49 }
50
51 strcpy(name, "IEEE 802.11");
52 if (is_a)
53 strcat(name, "a");
54 if (is_b)
55 strcat(name, "b");
56 if (is_g)
57 strcat(name, "g");
58 if (is_ht)
59 strcat(name, "n");
60
61 return 0;
62}
Johannes Bergba44cb72009-04-20 18:49:39 +020063EXPORT_SYMBOL_GPL(cfg80211_wext_giwname);
Johannes Berge60c7742008-11-26 23:31:40 +010064
65int cfg80211_wext_siwmode(struct net_device *dev, struct iw_request_info *info,
66 u32 *mode, char *extra)
67{
68 struct wireless_dev *wdev = dev->ieee80211_ptr;
69 struct cfg80211_registered_device *rdev;
70 struct vif_params vifparams;
71 enum nl80211_iftype type;
Johannes Bergac7f9cf2009-03-21 17:07:59 +010072 int ret;
Johannes Berge60c7742008-11-26 23:31:40 +010073
Johannes Berge60c7742008-11-26 23:31:40 +010074 rdev = wiphy_to_dev(wdev->wiphy);
75
Johannes Berge60c7742008-11-26 23:31:40 +010076 switch (*mode) {
77 case IW_MODE_INFRA:
78 type = NL80211_IFTYPE_STATION;
79 break;
80 case IW_MODE_ADHOC:
81 type = NL80211_IFTYPE_ADHOC;
82 break;
83 case IW_MODE_REPEAT:
84 type = NL80211_IFTYPE_WDS;
85 break;
86 case IW_MODE_MONITOR:
87 type = NL80211_IFTYPE_MONITOR;
88 break;
89 default:
90 return -EINVAL;
91 }
92
Johannes Bergac7f9cf2009-03-21 17:07:59 +010093 if (type == wdev->iftype)
94 return 0;
95
Johannes Berge60c7742008-11-26 23:31:40 +010096 memset(&vifparams, 0, sizeof(vifparams));
97
Johannes Berg3d54d252009-08-21 14:51:05 +020098 cfg80211_lock_rdev(rdev);
99 ret = cfg80211_change_iface(rdev, dev, type, NULL, &vifparams);
100 cfg80211_unlock_rdev(rdev);
Johannes Bergac7f9cf2009-03-21 17:07:59 +0100101
102 return ret;
Johannes Berge60c7742008-11-26 23:31:40 +0100103}
Johannes Bergba44cb72009-04-20 18:49:39 +0200104EXPORT_SYMBOL_GPL(cfg80211_wext_siwmode);
Johannes Berge60c7742008-11-26 23:31:40 +0100105
106int cfg80211_wext_giwmode(struct net_device *dev, struct iw_request_info *info,
107 u32 *mode, char *extra)
108{
109 struct wireless_dev *wdev = dev->ieee80211_ptr;
110
111 if (!wdev)
112 return -EOPNOTSUPP;
113
114 switch (wdev->iftype) {
115 case NL80211_IFTYPE_AP:
116 *mode = IW_MODE_MASTER;
117 break;
118 case NL80211_IFTYPE_STATION:
119 *mode = IW_MODE_INFRA;
120 break;
121 case NL80211_IFTYPE_ADHOC:
122 *mode = IW_MODE_ADHOC;
123 break;
124 case NL80211_IFTYPE_MONITOR:
125 *mode = IW_MODE_MONITOR;
126 break;
127 case NL80211_IFTYPE_WDS:
128 *mode = IW_MODE_REPEAT;
129 break;
130 case NL80211_IFTYPE_AP_VLAN:
131 *mode = IW_MODE_SECOND; /* FIXME */
132 break;
133 default:
134 *mode = IW_MODE_AUTO;
135 break;
136 }
137 return 0;
138}
Johannes Bergba44cb72009-04-20 18:49:39 +0200139EXPORT_SYMBOL_GPL(cfg80211_wext_giwmode);
Johannes Berg4aa188e2009-02-18 19:32:08 +0100140
141
142int cfg80211_wext_giwrange(struct net_device *dev,
143 struct iw_request_info *info,
144 struct iw_point *data, char *extra)
145{
146 struct wireless_dev *wdev = dev->ieee80211_ptr;
147 struct iw_range *range = (struct iw_range *) extra;
148 enum ieee80211_band band;
Johannes Berg9834c072009-07-06 19:40:51 +0200149 int i, c = 0;
Johannes Berg4aa188e2009-02-18 19:32:08 +0100150
151 if (!wdev)
152 return -EOPNOTSUPP;
153
154 data->length = sizeof(struct iw_range);
155 memset(range, 0, sizeof(struct iw_range));
156
157 range->we_version_compiled = WIRELESS_EXT;
158 range->we_version_source = 21;
159 range->retry_capa = IW_RETRY_LIMIT;
160 range->retry_flags = IW_RETRY_LIMIT;
161 range->min_retry = 0;
162 range->max_retry = 255;
163 range->min_rts = 0;
164 range->max_rts = 2347;
165 range->min_frag = 256;
166 range->max_frag = 2346;
167
Johannes Berg4aa188e2009-02-18 19:32:08 +0100168 range->max_encoding_tokens = 4;
169
170 range->max_qual.updated = IW_QUAL_NOISE_INVALID;
171
172 switch (wdev->wiphy->signal_type) {
173 case CFG80211_SIGNAL_TYPE_NONE:
174 break;
175 case CFG80211_SIGNAL_TYPE_MBM:
176 range->max_qual.level = -110;
177 range->max_qual.qual = 70;
178 range->avg_qual.qual = 35;
179 range->max_qual.updated |= IW_QUAL_DBM;
180 range->max_qual.updated |= IW_QUAL_QUAL_UPDATED;
181 range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED;
182 break;
183 case CFG80211_SIGNAL_TYPE_UNSPEC:
184 range->max_qual.level = 100;
185 range->max_qual.qual = 100;
186 range->avg_qual.qual = 50;
187 range->max_qual.updated |= IW_QUAL_QUAL_UPDATED;
188 range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED;
189 break;
190 }
191
192 range->avg_qual.level = range->max_qual.level / 2;
193 range->avg_qual.noise = range->max_qual.noise / 2;
194 range->avg_qual.updated = range->max_qual.updated;
195
Johannes Berg9834c072009-07-06 19:40:51 +0200196 for (i = 0; i < wdev->wiphy->n_cipher_suites; i++) {
197 switch (wdev->wiphy->cipher_suites[i]) {
David Kilroy3daf0972009-06-18 23:21:14 +0100198 case WLAN_CIPHER_SUITE_TKIP:
David Kilroy27bea662009-06-18 23:21:17 +0100199 range->enc_capa |= (IW_ENC_CAPA_CIPHER_TKIP |
200 IW_ENC_CAPA_WPA);
David Kilroy3daf0972009-06-18 23:21:14 +0100201 break;
202
203 case WLAN_CIPHER_SUITE_CCMP:
David Kilroy27bea662009-06-18 23:21:17 +0100204 range->enc_capa |= (IW_ENC_CAPA_CIPHER_CCMP |
205 IW_ENC_CAPA_WPA2);
David Kilroy3daf0972009-06-18 23:21:14 +0100206 break;
David Kilroy2ab658f2009-06-18 23:21:16 +0100207
208 case WLAN_CIPHER_SUITE_WEP40:
209 range->encoding_size[range->num_encoding_sizes++] =
210 WLAN_KEY_LEN_WEP40;
211 break;
212
213 case WLAN_CIPHER_SUITE_WEP104:
214 range->encoding_size[range->num_encoding_sizes++] =
215 WLAN_KEY_LEN_WEP104;
216 break;
David Kilroy3daf0972009-06-18 23:21:14 +0100217 }
218 }
Johannes Berg4aa188e2009-02-18 19:32:08 +0100219
Johannes Berg4aa188e2009-02-18 19:32:08 +0100220 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
Johannes Berg4aa188e2009-02-18 19:32:08 +0100221 struct ieee80211_supported_band *sband;
222
223 sband = wdev->wiphy->bands[band];
224
225 if (!sband)
226 continue;
227
228 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
229 struct ieee80211_channel *chan = &sband->channels[i];
230
231 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
232 range->freq[c].i =
233 ieee80211_frequency_to_channel(
234 chan->center_freq);
235 range->freq[c].m = chan->center_freq;
236 range->freq[c].e = 6;
237 c++;
238 }
239 }
240 }
241 range->num_channels = c;
242 range->num_frequency = c;
243
244 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
245 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
246 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
247
David Kilroy51cd4aa2009-06-18 23:21:15 +0100248 if (wdev->wiphy->max_scan_ssids > 0)
249 range->scan_capa |= IW_SCAN_CAPA_ESSID;
Johannes Berg4aa188e2009-02-18 19:32:08 +0100250
251 return 0;
252}
Johannes Bergba44cb72009-04-20 18:49:39 +0200253EXPORT_SYMBOL_GPL(cfg80211_wext_giwrange);
Johannes Berg691597c2009-04-19 19:57:45 +0200254
Johannes Berg04a773a2009-04-19 21:24:32 +0200255
256/**
257 * cfg80211_wext_freq - get wext frequency for non-"auto"
258 * @wiphy: the wiphy
259 * @freq: the wext freq encoding
260 *
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200261 * Returns a frequency, or a negative error code, or 0 for auto.
Johannes Berg04a773a2009-04-19 21:24:32 +0200262 */
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200263int cfg80211_wext_freq(struct wiphy *wiphy, struct iw_freq *freq)
Johannes Berg04a773a2009-04-19 21:24:32 +0200264{
Johannes Berg0b258582009-05-08 09:42:33 +0200265 /*
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200266 * Parse frequency - return 0 for auto and
Johannes Berg0b258582009-05-08 09:42:33 +0200267 * -EINVAL for impossible things.
268 */
Johannes Berg04a773a2009-04-19 21:24:32 +0200269 if (freq->e == 0) {
Bruno Randolf59eb21a2011-01-17 13:37:28 +0900270 enum ieee80211_band band = IEEE80211_BAND_2GHZ;
Johannes Berg04a773a2009-04-19 21:24:32 +0200271 if (freq->m < 0)
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200272 return 0;
Bruno Randolf59eb21a2011-01-17 13:37:28 +0900273 if (freq->m > 14)
274 band = IEEE80211_BAND_5GHZ;
275 return ieee80211_channel_to_frequency(freq->m, band);
Johannes Berg04a773a2009-04-19 21:24:32 +0200276 } else {
277 int i, div = 1000000;
278 for (i = 0; i < freq->e; i++)
279 div /= 10;
Johannes Berg0b258582009-05-08 09:42:33 +0200280 if (div <= 0)
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200281 return -EINVAL;
282 return freq->m / div;
Johannes Berg04a773a2009-04-19 21:24:32 +0200283 }
Johannes Berg04a773a2009-04-19 21:24:32 +0200284}
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200285
286int cfg80211_wext_siwrts(struct net_device *dev,
287 struct iw_request_info *info,
288 struct iw_param *rts, char *extra)
289{
290 struct wireless_dev *wdev = dev->ieee80211_ptr;
291 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
292 u32 orts = wdev->wiphy->rts_threshold;
293 int err;
294
295 if (rts->disabled || !rts->fixed)
296 wdev->wiphy->rts_threshold = (u32) -1;
297 else if (rts->value < 0)
298 return -EINVAL;
299 else
300 wdev->wiphy->rts_threshold = rts->value;
301
302 err = rdev->ops->set_wiphy_params(wdev->wiphy,
303 WIPHY_PARAM_RTS_THRESHOLD);
304 if (err)
305 wdev->wiphy->rts_threshold = orts;
306
307 return err;
308}
Johannes Bergba44cb72009-04-20 18:49:39 +0200309EXPORT_SYMBOL_GPL(cfg80211_wext_siwrts);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200310
311int cfg80211_wext_giwrts(struct net_device *dev,
312 struct iw_request_info *info,
313 struct iw_param *rts, char *extra)
314{
315 struct wireless_dev *wdev = dev->ieee80211_ptr;
316
317 rts->value = wdev->wiphy->rts_threshold;
318 rts->disabled = rts->value == (u32) -1;
319 rts->fixed = 1;
320
321 return 0;
322}
Johannes Bergba44cb72009-04-20 18:49:39 +0200323EXPORT_SYMBOL_GPL(cfg80211_wext_giwrts);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200324
325int cfg80211_wext_siwfrag(struct net_device *dev,
326 struct iw_request_info *info,
327 struct iw_param *frag, char *extra)
328{
329 struct wireless_dev *wdev = dev->ieee80211_ptr;
330 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
331 u32 ofrag = wdev->wiphy->frag_threshold;
332 int err;
333
334 if (frag->disabled || !frag->fixed)
335 wdev->wiphy->frag_threshold = (u32) -1;
336 else if (frag->value < 256)
337 return -EINVAL;
338 else {
339 /* Fragment length must be even, so strip LSB. */
340 wdev->wiphy->frag_threshold = frag->value & ~0x1;
341 }
342
343 err = rdev->ops->set_wiphy_params(wdev->wiphy,
344 WIPHY_PARAM_FRAG_THRESHOLD);
345 if (err)
346 wdev->wiphy->frag_threshold = ofrag;
347
348 return err;
349}
Johannes Bergba44cb72009-04-20 18:49:39 +0200350EXPORT_SYMBOL_GPL(cfg80211_wext_siwfrag);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200351
352int cfg80211_wext_giwfrag(struct net_device *dev,
353 struct iw_request_info *info,
354 struct iw_param *frag, char *extra)
355{
356 struct wireless_dev *wdev = dev->ieee80211_ptr;
357
358 frag->value = wdev->wiphy->frag_threshold;
359 frag->disabled = frag->value == (u32) -1;
360 frag->fixed = 1;
361
362 return 0;
363}
Johannes Bergba44cb72009-04-20 18:49:39 +0200364EXPORT_SYMBOL_GPL(cfg80211_wext_giwfrag);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200365
366int cfg80211_wext_siwretry(struct net_device *dev,
367 struct iw_request_info *info,
368 struct iw_param *retry, char *extra)
369{
370 struct wireless_dev *wdev = dev->ieee80211_ptr;
371 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
372 u32 changed = 0;
373 u8 olong = wdev->wiphy->retry_long;
374 u8 oshort = wdev->wiphy->retry_short;
375 int err;
376
377 if (retry->disabled ||
378 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
379 return -EINVAL;
380
381 if (retry->flags & IW_RETRY_LONG) {
382 wdev->wiphy->retry_long = retry->value;
383 changed |= WIPHY_PARAM_RETRY_LONG;
384 } else if (retry->flags & IW_RETRY_SHORT) {
385 wdev->wiphy->retry_short = retry->value;
386 changed |= WIPHY_PARAM_RETRY_SHORT;
387 } else {
388 wdev->wiphy->retry_short = retry->value;
389 wdev->wiphy->retry_long = retry->value;
390 changed |= WIPHY_PARAM_RETRY_LONG;
391 changed |= WIPHY_PARAM_RETRY_SHORT;
392 }
393
394 if (!changed)
395 return 0;
396
397 err = rdev->ops->set_wiphy_params(wdev->wiphy, changed);
398 if (err) {
399 wdev->wiphy->retry_short = oshort;
400 wdev->wiphy->retry_long = olong;
401 }
402
403 return err;
404}
Johannes Bergba44cb72009-04-20 18:49:39 +0200405EXPORT_SYMBOL_GPL(cfg80211_wext_siwretry);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200406
407int cfg80211_wext_giwretry(struct net_device *dev,
408 struct iw_request_info *info,
409 struct iw_param *retry, char *extra)
410{
411 struct wireless_dev *wdev = dev->ieee80211_ptr;
412
413 retry->disabled = 0;
414
415 if (retry->flags == 0 || (retry->flags & IW_RETRY_SHORT)) {
416 /*
417 * First return short value, iwconfig will ask long value
418 * later if needed
419 */
420 retry->flags |= IW_RETRY_LIMIT;
421 retry->value = wdev->wiphy->retry_short;
422 if (wdev->wiphy->retry_long != wdev->wiphy->retry_short)
423 retry->flags |= IW_RETRY_LONG;
424
425 return 0;
426 }
427
428 if (retry->flags & IW_RETRY_LONG) {
429 retry->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
430 retry->value = wdev->wiphy->retry_long;
431 }
432
433 return 0;
434}
Johannes Bergba44cb72009-04-20 18:49:39 +0200435EXPORT_SYMBOL_GPL(cfg80211_wext_giwretry);
Johannes Berg08645122009-05-11 13:54:58 +0200436
Johannes Bergfffd0932009-07-08 14:22:54 +0200437static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
Johannes Berge31b8212010-10-05 19:39:30 +0200438 struct net_device *dev, bool pairwise,
439 const u8 *addr, bool remove, bool tx_key,
440 int idx, struct key_params *params)
Johannes Berg08645122009-05-11 13:54:58 +0200441{
442 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergfffd0932009-07-08 14:22:54 +0200443 int err, i;
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100444 bool rejoin = false;
Johannes Bergfffd0932009-07-08 14:22:54 +0200445
Johannes Berge31b8212010-10-05 19:39:30 +0200446 if (pairwise && !addr)
447 return -EINVAL;
448
Johannes Bergfffd0932009-07-08 14:22:54 +0200449 if (!wdev->wext.keys) {
450 wdev->wext.keys = kzalloc(sizeof(*wdev->wext.keys),
451 GFP_KERNEL);
452 if (!wdev->wext.keys)
453 return -ENOMEM;
454 for (i = 0; i < 6; i++)
455 wdev->wext.keys->params[i].key =
456 wdev->wext.keys->data[i];
457 }
458
459 if (wdev->iftype != NL80211_IFTYPE_ADHOC &&
460 wdev->iftype != NL80211_IFTYPE_STATION)
461 return -EOPNOTSUPP;
Johannes Berg08645122009-05-11 13:54:58 +0200462
463 if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
Johannes Bergfffd0932009-07-08 14:22:54 +0200464 if (!wdev->current_bss)
465 return -ENOLINK;
466
Johannes Berg08645122009-05-11 13:54:58 +0200467 if (!rdev->ops->set_default_mgmt_key)
468 return -EOPNOTSUPP;
469
470 if (idx < 4 || idx > 5)
471 return -EINVAL;
472 } else if (idx < 0 || idx > 3)
473 return -EINVAL;
474
475 if (remove) {
Johannes Bergfffd0932009-07-08 14:22:54 +0200476 err = 0;
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100477 if (wdev->current_bss) {
478 /*
479 * If removing the current TX key, we will need to
480 * join a new IBSS without the privacy bit clear.
481 */
482 if (idx == wdev->wext.default_key &&
483 wdev->iftype == NL80211_IFTYPE_ADHOC) {
484 __cfg80211_leave_ibss(rdev, wdev->netdev, true);
485 rejoin = true;
486 }
Johannes Berge31b8212010-10-05 19:39:30 +0200487
488 if (!pairwise && addr &&
489 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
490 err = -ENOENT;
491 else
492 err = rdev->ops->del_key(&rdev->wiphy, dev, idx,
493 pairwise, addr);
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100494 }
Vivek Natarajand55fb892009-11-24 11:54:10 -0500495 wdev->wext.connect.privacy = false;
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100496 /*
497 * Applications using wireless extensions expect to be
498 * able to delete keys that don't exist, so allow that.
499 */
500 if (err == -ENOENT)
501 err = 0;
Johannes Berg08645122009-05-11 13:54:58 +0200502 if (!err) {
Johannes Bergfffd0932009-07-08 14:22:54 +0200503 if (!addr) {
504 wdev->wext.keys->params[idx].key_len = 0;
505 wdev->wext.keys->params[idx].cipher = 0;
506 }
Johannes Berg08645122009-05-11 13:54:58 +0200507 if (idx == wdev->wext.default_key)
508 wdev->wext.default_key = -1;
509 else if (idx == wdev->wext.default_mgmt_key)
510 wdev->wext.default_mgmt_key = -1;
511 }
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100512
513 if (!err && rejoin)
514 err = cfg80211_ibss_wext_join(rdev, wdev);
Johannes Berge3da5742009-05-18 19:56:36 +0200515
Johannes Berg08645122009-05-11 13:54:58 +0200516 return err;
Johannes Bergfffd0932009-07-08 14:22:54 +0200517 }
Johannes Berg08645122009-05-11 13:54:58 +0200518
Johannes Bergfffd0932009-07-08 14:22:54 +0200519 if (addr)
520 tx_key = false;
Johannes Berg08645122009-05-11 13:54:58 +0200521
Johannes Berge31b8212010-10-05 19:39:30 +0200522 if (cfg80211_validate_key_settings(rdev, params, idx, pairwise, addr))
Johannes Bergfffd0932009-07-08 14:22:54 +0200523 return -EINVAL;
524
525 err = 0;
526 if (wdev->current_bss)
Johannes Berge31b8212010-10-05 19:39:30 +0200527 err = rdev->ops->add_key(&rdev->wiphy, dev, idx,
528 pairwise, addr, params);
Johannes Bergfffd0932009-07-08 14:22:54 +0200529 if (err)
530 return err;
Johannes Berg08645122009-05-11 13:54:58 +0200531
Johannes Bergfffd0932009-07-08 14:22:54 +0200532 if (!addr) {
533 wdev->wext.keys->params[idx] = *params;
534 memcpy(wdev->wext.keys->data[idx],
535 params->key, params->key_len);
536 wdev->wext.keys->params[idx].key =
537 wdev->wext.keys->data[idx];
538 }
539
Zhu Yi1f00fca2009-07-20 11:47:43 +0800540 if ((params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
541 params->cipher == WLAN_CIPHER_SUITE_WEP104) &&
Johannes Bergfffd0932009-07-08 14:22:54 +0200542 (tx_key || (!addr && wdev->wext.default_key == -1))) {
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100543 if (wdev->current_bss) {
544 /*
545 * If we are getting a new TX key from not having
546 * had one before we need to join a new IBSS with
547 * the privacy bit set.
548 */
549 if (wdev->iftype == NL80211_IFTYPE_ADHOC &&
550 wdev->wext.default_key == -1) {
551 __cfg80211_leave_ibss(rdev, wdev->netdev, true);
552 rejoin = true;
553 }
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100554 err = rdev->ops->set_default_key(&rdev->wiphy, dev,
555 idx, true, true);
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100556 }
557 if (!err) {
Johannes Bergfffd0932009-07-08 14:22:54 +0200558 wdev->wext.default_key = idx;
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100559 if (rejoin)
560 err = cfg80211_ibss_wext_join(rdev, wdev);
561 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200562 return err;
563 }
Johannes Berg08645122009-05-11 13:54:58 +0200564
Johannes Bergfffd0932009-07-08 14:22:54 +0200565 if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC &&
566 (tx_key || (!addr && wdev->wext.default_mgmt_key == -1))) {
567 if (wdev->current_bss)
Johannes Berg08645122009-05-11 13:54:58 +0200568 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
569 dev, idx);
Johannes Bergfffd0932009-07-08 14:22:54 +0200570 if (!err)
571 wdev->wext.default_mgmt_key = idx;
572 return err;
Johannes Berg08645122009-05-11 13:54:58 +0200573 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200574
575 return 0;
576}
577
578static int cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
Johannes Berge31b8212010-10-05 19:39:30 +0200579 struct net_device *dev, bool pairwise,
580 const u8 *addr, bool remove, bool tx_key,
581 int idx, struct key_params *params)
Johannes Bergfffd0932009-07-08 14:22:54 +0200582{
583 int err;
584
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100585 /* devlist mutex needed for possible IBSS re-join */
586 mutex_lock(&rdev->devlist_mtx);
Johannes Bergfffd0932009-07-08 14:22:54 +0200587 wdev_lock(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +0200588 err = __cfg80211_set_encryption(rdev, dev, pairwise, addr,
589 remove, tx_key, idx, params);
Johannes Bergfffd0932009-07-08 14:22:54 +0200590 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg98d3a7c2009-11-18 13:03:43 +0100591 mutex_unlock(&rdev->devlist_mtx);
Johannes Bergfffd0932009-07-08 14:22:54 +0200592
593 return err;
Johannes Berg08645122009-05-11 13:54:58 +0200594}
595
596int cfg80211_wext_siwencode(struct net_device *dev,
597 struct iw_request_info *info,
598 struct iw_point *erq, char *keybuf)
599{
600 struct wireless_dev *wdev = dev->ieee80211_ptr;
601 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
602 int idx, err;
603 bool remove = false;
604 struct key_params params;
605
Johannes Bergfffd0932009-07-08 14:22:54 +0200606 if (wdev->iftype != NL80211_IFTYPE_STATION &&
607 wdev->iftype != NL80211_IFTYPE_ADHOC)
608 return -EOPNOTSUPP;
609
Johannes Berg08645122009-05-11 13:54:58 +0200610 /* no use -- only MFP (set_default_mgmt_key) is optional */
611 if (!rdev->ops->del_key ||
612 !rdev->ops->add_key ||
613 !rdev->ops->set_default_key)
614 return -EOPNOTSUPP;
615
616 idx = erq->flags & IW_ENCODE_INDEX;
617 if (idx == 0) {
618 idx = wdev->wext.default_key;
619 if (idx < 0)
620 idx = 0;
621 } else if (idx < 1 || idx > 4)
622 return -EINVAL;
623 else
624 idx--;
625
626 if (erq->flags & IW_ENCODE_DISABLED)
627 remove = true;
628 else if (erq->length == 0) {
629 /* No key data - just set the default TX key index */
Johannes Bergfffd0932009-07-08 14:22:54 +0200630 err = 0;
631 wdev_lock(wdev);
632 if (wdev->current_bss)
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100633 err = rdev->ops->set_default_key(&rdev->wiphy, dev,
634 idx, true, true);
Johannes Berg08645122009-05-11 13:54:58 +0200635 if (!err)
636 wdev->wext.default_key = idx;
Johannes Bergfffd0932009-07-08 14:22:54 +0200637 wdev_unlock(wdev);
Johannes Berg08645122009-05-11 13:54:58 +0200638 return err;
639 }
640
641 memset(&params, 0, sizeof(params));
642 params.key = keybuf;
643 params.key_len = erq->length;
644 if (erq->length == 5)
645 params.cipher = WLAN_CIPHER_SUITE_WEP40;
646 else if (erq->length == 13)
647 params.cipher = WLAN_CIPHER_SUITE_WEP104;
648 else if (!remove)
649 return -EINVAL;
650
Johannes Berge31b8212010-10-05 19:39:30 +0200651 return cfg80211_set_encryption(rdev, dev, false, NULL, remove,
Johannes Berg08645122009-05-11 13:54:58 +0200652 wdev->wext.default_key == -1,
653 idx, &params);
654}
655EXPORT_SYMBOL_GPL(cfg80211_wext_siwencode);
656
657int cfg80211_wext_siwencodeext(struct net_device *dev,
658 struct iw_request_info *info,
659 struct iw_point *erq, char *extra)
660{
661 struct wireless_dev *wdev = dev->ieee80211_ptr;
662 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
663 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
664 const u8 *addr;
665 int idx;
666 bool remove = false;
667 struct key_params params;
668 u32 cipher;
669
Johannes Bergfffd0932009-07-08 14:22:54 +0200670 if (wdev->iftype != NL80211_IFTYPE_STATION &&
671 wdev->iftype != NL80211_IFTYPE_ADHOC)
672 return -EOPNOTSUPP;
673
Johannes Berg08645122009-05-11 13:54:58 +0200674 /* no use -- only MFP (set_default_mgmt_key) is optional */
675 if (!rdev->ops->del_key ||
676 !rdev->ops->add_key ||
677 !rdev->ops->set_default_key)
678 return -EOPNOTSUPP;
679
680 switch (ext->alg) {
681 case IW_ENCODE_ALG_NONE:
682 remove = true;
683 cipher = 0;
684 break;
685 case IW_ENCODE_ALG_WEP:
686 if (ext->key_len == 5)
687 cipher = WLAN_CIPHER_SUITE_WEP40;
688 else if (ext->key_len == 13)
689 cipher = WLAN_CIPHER_SUITE_WEP104;
690 else
691 return -EINVAL;
692 break;
693 case IW_ENCODE_ALG_TKIP:
694 cipher = WLAN_CIPHER_SUITE_TKIP;
695 break;
696 case IW_ENCODE_ALG_CCMP:
697 cipher = WLAN_CIPHER_SUITE_CCMP;
698 break;
699 case IW_ENCODE_ALG_AES_CMAC:
700 cipher = WLAN_CIPHER_SUITE_AES_CMAC;
701 break;
702 default:
703 return -EOPNOTSUPP;
704 }
705
706 if (erq->flags & IW_ENCODE_DISABLED)
707 remove = true;
708
709 idx = erq->flags & IW_ENCODE_INDEX;
710 if (cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
711 if (idx < 4 || idx > 5) {
712 idx = wdev->wext.default_mgmt_key;
713 if (idx < 0)
714 return -EINVAL;
715 } else
716 idx--;
717 } else {
718 if (idx < 1 || idx > 4) {
719 idx = wdev->wext.default_key;
720 if (idx < 0)
721 return -EINVAL;
722 } else
723 idx--;
724 }
725
726 addr = ext->addr.sa_data;
727 if (is_broadcast_ether_addr(addr))
728 addr = NULL;
729
730 memset(&params, 0, sizeof(params));
731 params.key = ext->key;
732 params.key_len = ext->key_len;
733 params.cipher = cipher;
734
Jouni Malinenfaa8fdc2009-05-11 21:57:58 +0300735 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
736 params.seq = ext->rx_seq;
737 params.seq_len = 6;
738 }
739
Johannes Berg08645122009-05-11 13:54:58 +0200740 return cfg80211_set_encryption(
Johannes Berge31b8212010-10-05 19:39:30 +0200741 rdev, dev,
742 !(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY),
743 addr, remove,
Johannes Berg08645122009-05-11 13:54:58 +0200744 ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
745 idx, &params);
746}
747EXPORT_SYMBOL_GPL(cfg80211_wext_siwencodeext);
748
Johannes Berg08645122009-05-11 13:54:58 +0200749int cfg80211_wext_giwencode(struct net_device *dev,
750 struct iw_request_info *info,
751 struct iw_point *erq, char *keybuf)
752{
753 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergfffd0932009-07-08 14:22:54 +0200754 int idx;
Johannes Berg08645122009-05-11 13:54:58 +0200755
Johannes Bergfffd0932009-07-08 14:22:54 +0200756 if (wdev->iftype != NL80211_IFTYPE_STATION &&
757 wdev->iftype != NL80211_IFTYPE_ADHOC)
Johannes Berg08645122009-05-11 13:54:58 +0200758 return -EOPNOTSUPP;
759
760 idx = erq->flags & IW_ENCODE_INDEX;
761 if (idx == 0) {
762 idx = wdev->wext.default_key;
763 if (idx < 0)
764 idx = 0;
765 } else if (idx < 1 || idx > 4)
766 return -EINVAL;
767 else
768 idx--;
769
770 erq->flags = idx + 1;
771
Johannes Bergfffd0932009-07-08 14:22:54 +0200772 if (!wdev->wext.keys || !wdev->wext.keys->params[idx].cipher) {
Johannes Berg08645122009-05-11 13:54:58 +0200773 erq->flags |= IW_ENCODE_DISABLED;
774 erq->length = 0;
775 return 0;
776 }
777
Johannes Bergfffd0932009-07-08 14:22:54 +0200778 erq->length = min_t(size_t, erq->length,
779 wdev->wext.keys->params[idx].key_len);
780 memcpy(keybuf, wdev->wext.keys->params[idx].key, erq->length);
781 erq->flags |= IW_ENCODE_ENABLED;
782
783 return 0;
Johannes Berg08645122009-05-11 13:54:58 +0200784}
785EXPORT_SYMBOL_GPL(cfg80211_wext_giwencode);
Johannes Berg7643a2c2009-06-02 13:01:39 +0200786
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200787int cfg80211_wext_siwfreq(struct net_device *dev,
788 struct iw_request_info *info,
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200789 struct iw_freq *wextfreq, char *extra)
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200790{
791 struct wireless_dev *wdev = dev->ieee80211_ptr;
792 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200793 int freq, err;
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200794
795 switch (wdev->iftype) {
796 case NL80211_IFTYPE_STATION:
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200797 return cfg80211_mgd_wext_siwfreq(dev, info, wextfreq, extra);
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200798 case NL80211_IFTYPE_ADHOC:
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200799 return cfg80211_ibss_wext_siwfreq(dev, info, wextfreq, extra);
Johannes Bergf444de02010-05-05 15:25:02 +0200800 case NL80211_IFTYPE_MONITOR:
801 case NL80211_IFTYPE_WDS:
802 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200803 freq = cfg80211_wext_freq(wdev->wiphy, wextfreq);
804 if (freq < 0)
805 return freq;
806 if (freq == 0)
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200807 return -EINVAL;
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200808 mutex_lock(&rdev->devlist_mtx);
Daniel J Blueman4f919a32011-02-22 00:11:06 +0800809 wdev_lock(wdev);
Johannes Bergf444de02010-05-05 15:25:02 +0200810 err = cfg80211_set_freq(rdev, wdev, freq, NL80211_CHAN_NO_HT);
Johannes Bergf444de02010-05-05 15:25:02 +0200811 wdev_unlock(wdev);
Daniel J Blueman4f919a32011-02-22 00:11:06 +0800812 mutex_unlock(&rdev->devlist_mtx);
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200813 return err;
Johannes Bergf444de02010-05-05 15:25:02 +0200814 default:
815 return -EOPNOTSUPP;
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200816 }
817}
Jussi Kivilinnaa8b875e2009-08-13 20:39:31 +0300818EXPORT_SYMBOL_GPL(cfg80211_wext_siwfreq);
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200819
820int cfg80211_wext_giwfreq(struct net_device *dev,
821 struct iw_request_info *info,
822 struct iw_freq *freq, char *extra)
823{
824 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200825
826 switch (wdev->iftype) {
827 case NL80211_IFTYPE_STATION:
828 return cfg80211_mgd_wext_giwfreq(dev, info, freq, extra);
829 case NL80211_IFTYPE_ADHOC:
830 return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra);
831 default:
Johannes Bergf444de02010-05-05 15:25:02 +0200832 if (!wdev->channel)
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200833 return -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +0200834 freq->m = wdev->channel->center_freq;
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200835 freq->e = 6;
836 return 0;
837 }
838}
839EXPORT_SYMBOL_GPL(cfg80211_wext_giwfreq);
840
Johannes Berg7643a2c2009-06-02 13:01:39 +0200841int cfg80211_wext_siwtxpower(struct net_device *dev,
842 struct iw_request_info *info,
843 union iwreq_data *data, char *extra)
844{
845 struct wireless_dev *wdev = dev->ieee80211_ptr;
846 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +0300847 enum nl80211_tx_power_setting type;
Johannes Berg7643a2c2009-06-02 13:01:39 +0200848 int dbm = 0;
849
850 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
851 return -EINVAL;
852 if (data->txpower.flags & IW_TXPOW_RANGE)
853 return -EINVAL;
854
855 if (!rdev->ops->set_tx_power)
856 return -EOPNOTSUPP;
857
858 /* only change when not disabling */
859 if (!data->txpower.disabled) {
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200860 rfkill_set_sw_state(rdev->rfkill, false);
861
Johannes Berg7643a2c2009-06-02 13:01:39 +0200862 if (data->txpower.fixed) {
863 /*
864 * wext doesn't support negative values, see
865 * below where it's for automatic
866 */
867 if (data->txpower.value < 0)
868 return -EINVAL;
869 dbm = data->txpower.value;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +0300870 type = NL80211_TX_POWER_FIXED;
Johannes Berg7643a2c2009-06-02 13:01:39 +0200871 /* TODO: do regulatory check! */
872 } else {
873 /*
874 * Automatic power level setting, max being the value
875 * passed in from userland.
876 */
877 if (data->txpower.value < 0) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +0300878 type = NL80211_TX_POWER_AUTOMATIC;
Johannes Berg7643a2c2009-06-02 13:01:39 +0200879 } else {
880 dbm = data->txpower.value;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +0300881 type = NL80211_TX_POWER_LIMITED;
Johannes Berg7643a2c2009-06-02 13:01:39 +0200882 }
883 }
884 } else {
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200885 rfkill_set_sw_state(rdev->rfkill, true);
886 schedule_work(&rdev->rfkill_sync);
887 return 0;
Johannes Berg7643a2c2009-06-02 13:01:39 +0200888 }
889
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +0300890 return rdev->ops->set_tx_power(wdev->wiphy, type, DBM_TO_MBM(dbm));
Johannes Berg7643a2c2009-06-02 13:01:39 +0200891}
892EXPORT_SYMBOL_GPL(cfg80211_wext_siwtxpower);
893
894int cfg80211_wext_giwtxpower(struct net_device *dev,
895 struct iw_request_info *info,
896 union iwreq_data *data, char *extra)
897{
898 struct wireless_dev *wdev = dev->ieee80211_ptr;
899 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
900 int err, val;
901
902 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
903 return -EINVAL;
904 if (data->txpower.flags & IW_TXPOW_RANGE)
905 return -EINVAL;
906
907 if (!rdev->ops->get_tx_power)
908 return -EOPNOTSUPP;
909
910 err = rdev->ops->get_tx_power(wdev->wiphy, &val);
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200911 if (err)
Johannes Berg7643a2c2009-06-02 13:01:39 +0200912 return err;
913
914 /* well... oh well */
915 data->txpower.fixed = 1;
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200916 data->txpower.disabled = rfkill_blocked(rdev->rfkill);
Johannes Berg7643a2c2009-06-02 13:01:39 +0200917 data->txpower.value = val;
918 data->txpower.flags = IW_TXPOW_DBM;
919
920 return 0;
921}
922EXPORT_SYMBOL_GPL(cfg80211_wext_giwtxpower);
Johannes Bergf2129352009-07-01 21:26:56 +0200923
924static int cfg80211_set_auth_alg(struct wireless_dev *wdev,
925 s32 auth_alg)
926{
927 int nr_alg = 0;
928
929 if (!auth_alg)
930 return -EINVAL;
931
932 if (auth_alg & ~(IW_AUTH_ALG_OPEN_SYSTEM |
933 IW_AUTH_ALG_SHARED_KEY |
934 IW_AUTH_ALG_LEAP))
935 return -EINVAL;
936
937 if (auth_alg & IW_AUTH_ALG_OPEN_SYSTEM) {
938 nr_alg++;
939 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
940 }
941
942 if (auth_alg & IW_AUTH_ALG_SHARED_KEY) {
943 nr_alg++;
944 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_SHARED_KEY;
945 }
946
947 if (auth_alg & IW_AUTH_ALG_LEAP) {
948 nr_alg++;
949 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_NETWORK_EAP;
950 }
951
952 if (nr_alg > 1)
953 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
954
955 return 0;
956}
957
958static int cfg80211_set_wpa_version(struct wireless_dev *wdev, u32 wpa_versions)
959{
Johannes Bergf2129352009-07-01 21:26:56 +0200960 if (wpa_versions & ~(IW_AUTH_WPA_VERSION_WPA |
Gábor Stefanik323d5662009-07-12 02:03:48 +0200961 IW_AUTH_WPA_VERSION_WPA2|
962 IW_AUTH_WPA_VERSION_DISABLED))
Johannes Bergf2129352009-07-01 21:26:56 +0200963 return -EINVAL;
964
Gábor Stefanik323d5662009-07-12 02:03:48 +0200965 if ((wpa_versions & IW_AUTH_WPA_VERSION_DISABLED) &&
966 (wpa_versions & (IW_AUTH_WPA_VERSION_WPA|
967 IW_AUTH_WPA_VERSION_WPA2)))
968 return -EINVAL;
969
970 if (wpa_versions & IW_AUTH_WPA_VERSION_DISABLED)
971 wdev->wext.connect.crypto.wpa_versions &=
972 ~(NL80211_WPA_VERSION_1|NL80211_WPA_VERSION_2);
973
Johannes Bergf2129352009-07-01 21:26:56 +0200974 if (wpa_versions & IW_AUTH_WPA_VERSION_WPA)
975 wdev->wext.connect.crypto.wpa_versions |=
976 NL80211_WPA_VERSION_1;
977
978 if (wpa_versions & IW_AUTH_WPA_VERSION_WPA2)
979 wdev->wext.connect.crypto.wpa_versions |=
980 NL80211_WPA_VERSION_2;
981
982 return 0;
983}
984
Johannes Berg4f5dadc2009-07-07 03:56:10 +0200985static int cfg80211_set_cipher_group(struct wireless_dev *wdev, u32 cipher)
Johannes Bergf2129352009-07-01 21:26:56 +0200986{
Johannes Bergf2129352009-07-01 21:26:56 +0200987 if (cipher & IW_AUTH_CIPHER_WEP40)
988 wdev->wext.connect.crypto.cipher_group =
989 WLAN_CIPHER_SUITE_WEP40;
990 else if (cipher & IW_AUTH_CIPHER_WEP104)
991 wdev->wext.connect.crypto.cipher_group =
992 WLAN_CIPHER_SUITE_WEP104;
993 else if (cipher & IW_AUTH_CIPHER_TKIP)
994 wdev->wext.connect.crypto.cipher_group =
995 WLAN_CIPHER_SUITE_TKIP;
996 else if (cipher & IW_AUTH_CIPHER_CCMP)
997 wdev->wext.connect.crypto.cipher_group =
998 WLAN_CIPHER_SUITE_CCMP;
999 else if (cipher & IW_AUTH_CIPHER_AES_CMAC)
1000 wdev->wext.connect.crypto.cipher_group =
1001 WLAN_CIPHER_SUITE_AES_CMAC;
Jouni Malinenc5f82892009-11-01 11:18:49 +02001002 else if (cipher & IW_AUTH_CIPHER_NONE)
1003 wdev->wext.connect.crypto.cipher_group = 0;
Johannes Bergf2129352009-07-01 21:26:56 +02001004 else
1005 return -EINVAL;
1006
1007 return 0;
1008}
1009
Johannes Berg4f5dadc2009-07-07 03:56:10 +02001010static int cfg80211_set_cipher_pairwise(struct wireless_dev *wdev, u32 cipher)
Johannes Bergf2129352009-07-01 21:26:56 +02001011{
1012 int nr_ciphers = 0;
1013 u32 *ciphers_pairwise = wdev->wext.connect.crypto.ciphers_pairwise;
1014
1015 if (cipher & IW_AUTH_CIPHER_WEP40) {
1016 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP40;
1017 nr_ciphers++;
1018 }
1019
1020 if (cipher & IW_AUTH_CIPHER_WEP104) {
1021 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP104;
1022 nr_ciphers++;
1023 }
1024
1025 if (cipher & IW_AUTH_CIPHER_TKIP) {
1026 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_TKIP;
1027 nr_ciphers++;
1028 }
1029
1030 if (cipher & IW_AUTH_CIPHER_CCMP) {
1031 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_CCMP;
1032 nr_ciphers++;
1033 }
1034
1035 if (cipher & IW_AUTH_CIPHER_AES_CMAC) {
1036 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_AES_CMAC;
1037 nr_ciphers++;
1038 }
1039
1040 BUILD_BUG_ON(NL80211_MAX_NR_CIPHER_SUITES < 5);
1041
1042 wdev->wext.connect.crypto.n_ciphers_pairwise = nr_ciphers;
1043
1044 return 0;
1045}
1046
1047
Johannes Berg4f5dadc2009-07-07 03:56:10 +02001048static int cfg80211_set_key_mgt(struct wireless_dev *wdev, u32 key_mgt)
Johannes Bergf2129352009-07-01 21:26:56 +02001049{
1050 int nr_akm_suites = 0;
1051
1052 if (key_mgt & ~(IW_AUTH_KEY_MGMT_802_1X |
1053 IW_AUTH_KEY_MGMT_PSK))
1054 return -EINVAL;
1055
1056 if (key_mgt & IW_AUTH_KEY_MGMT_802_1X) {
1057 wdev->wext.connect.crypto.akm_suites[nr_akm_suites] =
1058 WLAN_AKM_SUITE_8021X;
1059 nr_akm_suites++;
1060 }
1061
1062 if (key_mgt & IW_AUTH_KEY_MGMT_PSK) {
1063 wdev->wext.connect.crypto.akm_suites[nr_akm_suites] =
1064 WLAN_AKM_SUITE_PSK;
1065 nr_akm_suites++;
1066 }
1067
1068 wdev->wext.connect.crypto.n_akm_suites = nr_akm_suites;
1069
1070 return 0;
1071}
1072
1073int cfg80211_wext_siwauth(struct net_device *dev,
1074 struct iw_request_info *info,
1075 struct iw_param *data, char *extra)
1076{
1077 struct wireless_dev *wdev = dev->ieee80211_ptr;
1078
1079 if (wdev->iftype != NL80211_IFTYPE_STATION)
1080 return -EOPNOTSUPP;
1081
1082 switch (data->flags & IW_AUTH_INDEX) {
1083 case IW_AUTH_PRIVACY_INVOKED:
1084 wdev->wext.connect.privacy = data->value;
1085 return 0;
1086 case IW_AUTH_WPA_VERSION:
1087 return cfg80211_set_wpa_version(wdev, data->value);
1088 case IW_AUTH_CIPHER_GROUP:
1089 return cfg80211_set_cipher_group(wdev, data->value);
1090 case IW_AUTH_KEY_MGMT:
1091 return cfg80211_set_key_mgt(wdev, data->value);
1092 case IW_AUTH_CIPHER_PAIRWISE:
1093 return cfg80211_set_cipher_pairwise(wdev, data->value);
1094 case IW_AUTH_80211_AUTH_ALG:
1095 return cfg80211_set_auth_alg(wdev, data->value);
1096 case IW_AUTH_WPA_ENABLED:
1097 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1098 case IW_AUTH_DROP_UNENCRYPTED:
1099 case IW_AUTH_MFP:
1100 return 0;
1101 default:
1102 return -EOPNOTSUPP;
1103 }
1104}
1105EXPORT_SYMBOL_GPL(cfg80211_wext_siwauth);
1106
1107int cfg80211_wext_giwauth(struct net_device *dev,
1108 struct iw_request_info *info,
1109 struct iw_param *data, char *extra)
1110{
1111 /* XXX: what do we need? */
1112
1113 return -EOPNOTSUPP;
1114}
1115EXPORT_SYMBOL_GPL(cfg80211_wext_giwauth);
Johannes Bergbc92afd2009-07-01 21:26:57 +02001116
1117int cfg80211_wext_siwpower(struct net_device *dev,
1118 struct iw_request_info *info,
1119 struct iw_param *wrq, char *extra)
1120{
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
1153 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, ps, timeout);
1154 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}
1163EXPORT_SYMBOL_GPL(cfg80211_wext_siwpower);
1164
1165int cfg80211_wext_giwpower(struct net_device *dev,
1166 struct iw_request_info *info,
1167 struct iw_param *wrq, char *extra)
1168{
1169 struct wireless_dev *wdev = dev->ieee80211_ptr;
1170
Kalle Valoffb9eb32010-02-17 17:58:10 +02001171 wrq->disabled = !wdev->ps;
Johannes Bergbc92afd2009-07-01 21:26:57 +02001172
1173 return 0;
1174}
1175EXPORT_SYMBOL_GPL(cfg80211_wext_giwpower);
Johannes Bergab737a42009-07-01 21:26:58 +02001176
Johannes Berg562e4822009-07-27 12:01:51 +02001177static int cfg80211_wds_wext_siwap(struct net_device *dev,
1178 struct iw_request_info *info,
1179 struct sockaddr *addr, char *extra)
Johannes Bergab737a42009-07-01 21:26:58 +02001180{
1181 struct wireless_dev *wdev = dev->ieee80211_ptr;
1182 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1183 int err;
1184
1185 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS))
1186 return -EINVAL;
1187
1188 if (addr->sa_family != ARPHRD_ETHER)
1189 return -EINVAL;
1190
1191 if (netif_running(dev))
1192 return -EBUSY;
1193
1194 if (!rdev->ops->set_wds_peer)
1195 return -EOPNOTSUPP;
1196
1197 err = rdev->ops->set_wds_peer(wdev->wiphy, dev, (u8 *) &addr->sa_data);
1198 if (err)
1199 return err;
1200
1201 memcpy(&wdev->wext.bssid, (u8 *) &addr->sa_data, ETH_ALEN);
1202
1203 return 0;
1204}
Johannes Bergab737a42009-07-01 21:26:58 +02001205
Johannes Berg562e4822009-07-27 12:01:51 +02001206static int cfg80211_wds_wext_giwap(struct net_device *dev,
1207 struct iw_request_info *info,
1208 struct sockaddr *addr, char *extra)
Johannes Bergab737a42009-07-01 21:26:58 +02001209{
1210 struct wireless_dev *wdev = dev->ieee80211_ptr;
1211
1212 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS))
1213 return -EINVAL;
1214
1215 addr->sa_family = ARPHRD_ETHER;
1216 memcpy(&addr->sa_data, wdev->wext.bssid, ETH_ALEN);
1217
1218 return 0;
1219}
Johannes Berg99303802009-07-01 21:26:59 +02001220
1221int cfg80211_wext_siwrate(struct net_device *dev,
1222 struct iw_request_info *info,
1223 struct iw_param *rate, char *extra)
1224{
1225 struct wireless_dev *wdev = dev->ieee80211_ptr;
1226 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1227 struct cfg80211_bitrate_mask mask;
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001228 u32 fixed, maxrate;
1229 struct ieee80211_supported_band *sband;
1230 int band, ridx;
1231 bool match = false;
Johannes Berg99303802009-07-01 21:26:59 +02001232
1233 if (!rdev->ops->set_bitrate_mask)
1234 return -EOPNOTSUPP;
1235
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001236 memset(&mask, 0, sizeof(mask));
1237 fixed = 0;
John W. Linville54233262010-01-27 09:44:48 -05001238 maxrate = (u32)-1;
Johannes Berg99303802009-07-01 21:26:59 +02001239
1240 if (rate->value < 0) {
1241 /* nothing */
1242 } else if (rate->fixed) {
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001243 fixed = rate->value / 100000;
Johannes Berg99303802009-07-01 21:26:59 +02001244 } else {
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001245 maxrate = rate->value / 100000;
Johannes Berg99303802009-07-01 21:26:59 +02001246 }
1247
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001248 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1249 sband = wdev->wiphy->bands[band];
1250 if (sband == NULL)
1251 continue;
1252 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
1253 struct ieee80211_rate *srate = &sband->bitrates[ridx];
1254 if (fixed == srate->bitrate) {
1255 mask.control[band].legacy = 1 << ridx;
1256 match = true;
1257 break;
1258 }
1259 if (srate->bitrate <= maxrate) {
1260 mask.control[band].legacy |= 1 << ridx;
1261 match = true;
1262 }
1263 }
1264 }
1265
1266 if (!match)
1267 return -EINVAL;
1268
Johannes Berg99303802009-07-01 21:26:59 +02001269 return rdev->ops->set_bitrate_mask(wdev->wiphy, dev, NULL, &mask);
1270}
1271EXPORT_SYMBOL_GPL(cfg80211_wext_siwrate);
1272
1273int cfg80211_wext_giwrate(struct net_device *dev,
1274 struct iw_request_info *info,
1275 struct iw_param *rate, char *extra)
1276{
1277 struct wireless_dev *wdev = dev->ieee80211_ptr;
1278 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1279 /* we are under RTNL - globally locked - so can use a static struct */
1280 static struct station_info sinfo;
Johannes Berga71d62d2009-07-07 23:41:27 +02001281 u8 addr[ETH_ALEN];
Johannes Berg99303802009-07-01 21:26:59 +02001282 int err;
1283
1284 if (wdev->iftype != NL80211_IFTYPE_STATION)
1285 return -EOPNOTSUPP;
1286
1287 if (!rdev->ops->get_station)
1288 return -EOPNOTSUPP;
1289
Johannes Berga71d62d2009-07-07 23:41:27 +02001290 err = 0;
1291 wdev_lock(wdev);
Samuel Ortiz6c230c02009-07-03 02:00:48 +02001292 if (wdev->current_bss)
Johannes Berga71d62d2009-07-07 23:41:27 +02001293 memcpy(addr, wdev->current_bss->pub.bssid, ETH_ALEN);
Samuel Ortiz6c230c02009-07-03 02:00:48 +02001294 else
Johannes Berga71d62d2009-07-07 23:41:27 +02001295 err = -EOPNOTSUPP;
1296 wdev_unlock(wdev);
1297 if (err)
1298 return err;
Johannes Berg99303802009-07-01 21:26:59 +02001299
1300 err = rdev->ops->get_station(&rdev->wiphy, dev, addr, &sinfo);
1301 if (err)
1302 return err;
1303
1304 if (!(sinfo.filled & STATION_INFO_TX_BITRATE))
1305 return -EOPNOTSUPP;
1306
John W. Linville254416a2009-12-09 16:43:52 -05001307 rate->value = 100000 * cfg80211_calculate_bitrate(&sinfo.txrate);
Johannes Berg99303802009-07-01 21:26:59 +02001308
1309 return 0;
1310}
1311EXPORT_SYMBOL_GPL(cfg80211_wext_giwrate);
Johannes Berg89906462009-07-01 21:27:00 +02001312
1313/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
1314struct iw_statistics *cfg80211_wireless_stats(struct net_device *dev)
1315{
1316 struct wireless_dev *wdev = dev->ieee80211_ptr;
1317 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1318 /* we are under RTNL - globally locked - so can use static structs */
1319 static struct iw_statistics wstats;
1320 static struct station_info sinfo;
Johannes Bergc56c5712009-07-10 16:54:07 +02001321 u8 bssid[ETH_ALEN];
Johannes Berg89906462009-07-01 21:27:00 +02001322
1323 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION)
1324 return NULL;
1325
1326 if (!rdev->ops->get_station)
1327 return NULL;
1328
Johannes Bergc56c5712009-07-10 16:54:07 +02001329 /* Grab BSSID of current BSS, if any */
1330 wdev_lock(wdev);
1331 if (!wdev->current_bss) {
1332 wdev_unlock(wdev);
Johannes Berg89906462009-07-01 21:27:00 +02001333 return NULL;
Johannes Bergc56c5712009-07-10 16:54:07 +02001334 }
1335 memcpy(bssid, wdev->current_bss->pub.bssid, ETH_ALEN);
1336 wdev_unlock(wdev);
Johannes Berg89906462009-07-01 21:27:00 +02001337
Johannes Bergc56c5712009-07-10 16:54:07 +02001338 if (rdev->ops->get_station(&rdev->wiphy, dev, bssid, &sinfo))
Johannes Berg89906462009-07-01 21:27:00 +02001339 return NULL;
1340
1341 memset(&wstats, 0, sizeof(wstats));
1342
1343 switch (rdev->wiphy.signal_type) {
1344 case CFG80211_SIGNAL_TYPE_MBM:
1345 if (sinfo.filled & STATION_INFO_SIGNAL) {
1346 int sig = sinfo.signal;
1347 wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
1348 wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
1349 wstats.qual.updated |= IW_QUAL_DBM;
1350 wstats.qual.level = sig;
1351 if (sig < -110)
1352 sig = -110;
1353 else if (sig > -40)
1354 sig = -40;
1355 wstats.qual.qual = sig + 110;
1356 break;
1357 }
1358 case CFG80211_SIGNAL_TYPE_UNSPEC:
1359 if (sinfo.filled & STATION_INFO_SIGNAL) {
1360 wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
1361 wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
1362 wstats.qual.level = sinfo.signal;
1363 wstats.qual.qual = sinfo.signal;
1364 break;
1365 }
1366 default:
1367 wstats.qual.updated |= IW_QUAL_LEVEL_INVALID;
1368 wstats.qual.updated |= IW_QUAL_QUAL_INVALID;
1369 }
1370
1371 wstats.qual.updated |= IW_QUAL_NOISE_INVALID;
Ben Greear5a5c7312010-10-07 16:39:20 -07001372 if (sinfo.filled & STATION_INFO_RX_DROP_MISC)
1373 wstats.discard.misc = sinfo.rx_dropped_misc;
1374 if (sinfo.filled & STATION_INFO_TX_FAILED)
1375 wstats.discard.retries = sinfo.tx_failed;
Johannes Berg89906462009-07-01 21:27:00 +02001376
1377 return &wstats;
1378}
1379EXPORT_SYMBOL_GPL(cfg80211_wireless_stats);
Johannes Berg562e4822009-07-27 12:01:51 +02001380
1381int cfg80211_wext_siwap(struct net_device *dev,
1382 struct iw_request_info *info,
1383 struct sockaddr *ap_addr, char *extra)
1384{
1385 struct wireless_dev *wdev = dev->ieee80211_ptr;
1386
1387 switch (wdev->iftype) {
1388 case NL80211_IFTYPE_ADHOC:
1389 return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra);
1390 case NL80211_IFTYPE_STATION:
1391 return cfg80211_mgd_wext_siwap(dev, info, ap_addr, extra);
1392 case NL80211_IFTYPE_WDS:
1393 return cfg80211_wds_wext_siwap(dev, info, ap_addr, extra);
1394 default:
1395 return -EOPNOTSUPP;
1396 }
1397}
1398EXPORT_SYMBOL_GPL(cfg80211_wext_siwap);
1399
1400int cfg80211_wext_giwap(struct net_device *dev,
1401 struct iw_request_info *info,
1402 struct sockaddr *ap_addr, char *extra)
1403{
1404 struct wireless_dev *wdev = dev->ieee80211_ptr;
1405
1406 switch (wdev->iftype) {
1407 case NL80211_IFTYPE_ADHOC:
1408 return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra);
1409 case NL80211_IFTYPE_STATION:
1410 return cfg80211_mgd_wext_giwap(dev, info, ap_addr, extra);
1411 case NL80211_IFTYPE_WDS:
1412 return cfg80211_wds_wext_giwap(dev, info, ap_addr, extra);
1413 default:
1414 return -EOPNOTSUPP;
1415 }
1416}
1417EXPORT_SYMBOL_GPL(cfg80211_wext_giwap);
Johannes Berg1f9298f2009-07-27 12:01:52 +02001418
1419int cfg80211_wext_siwessid(struct net_device *dev,
1420 struct iw_request_info *info,
1421 struct iw_point *data, char *ssid)
1422{
1423 struct wireless_dev *wdev = dev->ieee80211_ptr;
1424
1425 switch (wdev->iftype) {
1426 case NL80211_IFTYPE_ADHOC:
1427 return cfg80211_ibss_wext_siwessid(dev, info, data, ssid);
1428 case NL80211_IFTYPE_STATION:
1429 return cfg80211_mgd_wext_siwessid(dev, info, data, ssid);
1430 default:
1431 return -EOPNOTSUPP;
1432 }
1433}
1434EXPORT_SYMBOL_GPL(cfg80211_wext_siwessid);
1435
1436int cfg80211_wext_giwessid(struct net_device *dev,
1437 struct iw_request_info *info,
1438 struct iw_point *data, char *ssid)
1439{
1440 struct wireless_dev *wdev = dev->ieee80211_ptr;
1441
Johannes Berg42da2f92010-08-30 12:24:54 +02001442 data->flags = 0;
1443 data->length = 0;
1444
Johannes Berg1f9298f2009-07-27 12:01:52 +02001445 switch (wdev->iftype) {
1446 case NL80211_IFTYPE_ADHOC:
1447 return cfg80211_ibss_wext_giwessid(dev, info, data, ssid);
1448 case NL80211_IFTYPE_STATION:
1449 return cfg80211_mgd_wext_giwessid(dev, info, data, ssid);
1450 default:
1451 return -EOPNOTSUPP;
1452 }
1453}
1454EXPORT_SYMBOL_GPL(cfg80211_wext_giwessid);
Johannes Berga9a11622009-07-27 12:01:53 +02001455
Samuel Ortiz2944b2c2009-11-25 00:01:01 +01001456int cfg80211_wext_siwpmksa(struct net_device *dev,
1457 struct iw_request_info *info,
1458 struct iw_point *data, char *extra)
1459{
1460 struct wireless_dev *wdev = dev->ieee80211_ptr;
1461 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1462 struct cfg80211_pmksa cfg_pmksa;
1463 struct iw_pmksa *pmksa = (struct iw_pmksa *)extra;
1464
1465 memset(&cfg_pmksa, 0, sizeof(struct cfg80211_pmksa));
1466
1467 if (wdev->iftype != NL80211_IFTYPE_STATION)
1468 return -EINVAL;
1469
1470 cfg_pmksa.bssid = pmksa->bssid.sa_data;
1471 cfg_pmksa.pmkid = pmksa->pmkid;
1472
1473 switch (pmksa->cmd) {
1474 case IW_PMKSA_ADD:
1475 if (!rdev->ops->set_pmksa)
1476 return -EOPNOTSUPP;
1477
1478 return rdev->ops->set_pmksa(&rdev->wiphy, dev, &cfg_pmksa);
1479
1480 case IW_PMKSA_REMOVE:
1481 if (!rdev->ops->del_pmksa)
1482 return -EOPNOTSUPP;
1483
1484 return rdev->ops->del_pmksa(&rdev->wiphy, dev, &cfg_pmksa);
1485
1486 case IW_PMKSA_FLUSH:
1487 if (!rdev->ops->flush_pmksa)
1488 return -EOPNOTSUPP;
1489
1490 return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
1491
1492 default:
1493 return -EOPNOTSUPP;
1494 }
1495}
John W. Linvillec28991a2010-07-20 12:22:40 -04001496EXPORT_SYMBOL_GPL(cfg80211_wext_siwpmksa);
Samuel Ortiz2944b2c2009-11-25 00:01:01 +01001497
Johannes Berga9a11622009-07-27 12:01:53 +02001498static const iw_handler cfg80211_handlers[] = {
1499 [IW_IOCTL_IDX(SIOCGIWNAME)] = (iw_handler) cfg80211_wext_giwname,
1500 [IW_IOCTL_IDX(SIOCSIWFREQ)] = (iw_handler) cfg80211_wext_siwfreq,
1501 [IW_IOCTL_IDX(SIOCGIWFREQ)] = (iw_handler) cfg80211_wext_giwfreq,
1502 [IW_IOCTL_IDX(SIOCSIWMODE)] = (iw_handler) cfg80211_wext_siwmode,
1503 [IW_IOCTL_IDX(SIOCGIWMODE)] = (iw_handler) cfg80211_wext_giwmode,
1504 [IW_IOCTL_IDX(SIOCGIWRANGE)] = (iw_handler) cfg80211_wext_giwrange,
1505 [IW_IOCTL_IDX(SIOCSIWAP)] = (iw_handler) cfg80211_wext_siwap,
1506 [IW_IOCTL_IDX(SIOCGIWAP)] = (iw_handler) cfg80211_wext_giwap,
1507 [IW_IOCTL_IDX(SIOCSIWMLME)] = (iw_handler) cfg80211_wext_siwmlme,
1508 [IW_IOCTL_IDX(SIOCSIWSCAN)] = (iw_handler) cfg80211_wext_siwscan,
1509 [IW_IOCTL_IDX(SIOCGIWSCAN)] = (iw_handler) cfg80211_wext_giwscan,
1510 [IW_IOCTL_IDX(SIOCSIWESSID)] = (iw_handler) cfg80211_wext_siwessid,
1511 [IW_IOCTL_IDX(SIOCGIWESSID)] = (iw_handler) cfg80211_wext_giwessid,
1512 [IW_IOCTL_IDX(SIOCSIWRATE)] = (iw_handler) cfg80211_wext_siwrate,
1513 [IW_IOCTL_IDX(SIOCGIWRATE)] = (iw_handler) cfg80211_wext_giwrate,
1514 [IW_IOCTL_IDX(SIOCSIWRTS)] = (iw_handler) cfg80211_wext_siwrts,
1515 [IW_IOCTL_IDX(SIOCGIWRTS)] = (iw_handler) cfg80211_wext_giwrts,
1516 [IW_IOCTL_IDX(SIOCSIWFRAG)] = (iw_handler) cfg80211_wext_siwfrag,
1517 [IW_IOCTL_IDX(SIOCGIWFRAG)] = (iw_handler) cfg80211_wext_giwfrag,
1518 [IW_IOCTL_IDX(SIOCSIWTXPOW)] = (iw_handler) cfg80211_wext_siwtxpower,
1519 [IW_IOCTL_IDX(SIOCGIWTXPOW)] = (iw_handler) cfg80211_wext_giwtxpower,
1520 [IW_IOCTL_IDX(SIOCSIWRETRY)] = (iw_handler) cfg80211_wext_siwretry,
1521 [IW_IOCTL_IDX(SIOCGIWRETRY)] = (iw_handler) cfg80211_wext_giwretry,
1522 [IW_IOCTL_IDX(SIOCSIWENCODE)] = (iw_handler) cfg80211_wext_siwencode,
1523 [IW_IOCTL_IDX(SIOCGIWENCODE)] = (iw_handler) cfg80211_wext_giwencode,
1524 [IW_IOCTL_IDX(SIOCSIWPOWER)] = (iw_handler) cfg80211_wext_siwpower,
1525 [IW_IOCTL_IDX(SIOCGIWPOWER)] = (iw_handler) cfg80211_wext_giwpower,
1526 [IW_IOCTL_IDX(SIOCSIWGENIE)] = (iw_handler) cfg80211_wext_siwgenie,
1527 [IW_IOCTL_IDX(SIOCSIWAUTH)] = (iw_handler) cfg80211_wext_siwauth,
1528 [IW_IOCTL_IDX(SIOCGIWAUTH)] = (iw_handler) cfg80211_wext_giwauth,
1529 [IW_IOCTL_IDX(SIOCSIWENCODEEXT)]= (iw_handler) cfg80211_wext_siwencodeext,
Samuel Ortiz2944b2c2009-11-25 00:01:01 +01001530 [IW_IOCTL_IDX(SIOCSIWPMKSA)] = (iw_handler) cfg80211_wext_siwpmksa,
Johannes Berga9a11622009-07-27 12:01:53 +02001531};
1532
1533const struct iw_handler_def cfg80211_wext_handler = {
1534 .num_standard = ARRAY_SIZE(cfg80211_handlers),
1535 .standard = cfg80211_handlers,
1536 .get_wireless_stats = cfg80211_wireless_stats,
1537};