blob: c12029b1def063650ebe51c02045a7581a4db308 [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>
Johannes Bergfee52672008-11-26 22:36:31 +010015#include <net/iw_handler.h>
Johannes Bergfee52672008-11-26 22:36:31 +010016#include <net/cfg80211.h>
Johannes Berg0e82ffe2009-07-27 12:01:50 +020017#include "wext-compat.h"
Johannes Bergfee52672008-11-26 22:36:31 +010018#include "core.h"
19
20int cfg80211_wext_giwname(struct net_device *dev,
21 struct iw_request_info *info,
22 char *name, char *extra)
23{
24 struct wireless_dev *wdev = dev->ieee80211_ptr;
25 struct ieee80211_supported_band *sband;
26 bool is_ht = false, is_a = false, is_b = false, is_g = false;
27
28 if (!wdev)
29 return -EOPNOTSUPP;
30
31 sband = wdev->wiphy->bands[IEEE80211_BAND_5GHZ];
32 if (sband) {
33 is_a = true;
34 is_ht |= sband->ht_cap.ht_supported;
35 }
36
37 sband = wdev->wiphy->bands[IEEE80211_BAND_2GHZ];
38 if (sband) {
39 int i;
40 /* Check for mandatory rates */
41 for (i = 0; i < sband->n_bitrates; i++) {
42 if (sband->bitrates[i].bitrate == 10)
43 is_b = true;
44 if (sband->bitrates[i].bitrate == 60)
45 is_g = true;
46 }
47 is_ht |= sband->ht_cap.ht_supported;
48 }
49
50 strcpy(name, "IEEE 802.11");
51 if (is_a)
52 strcat(name, "a");
53 if (is_b)
54 strcat(name, "b");
55 if (is_g)
56 strcat(name, "g");
57 if (is_ht)
58 strcat(name, "n");
59
60 return 0;
61}
Johannes Bergba44cb72009-04-20 18:49:39 +020062EXPORT_SYMBOL_GPL(cfg80211_wext_giwname);
Johannes Berge60c7742008-11-26 23:31:40 +010063
64int cfg80211_wext_siwmode(struct net_device *dev, struct iw_request_info *info,
65 u32 *mode, char *extra)
66{
67 struct wireless_dev *wdev = dev->ieee80211_ptr;
68 struct cfg80211_registered_device *rdev;
69 struct vif_params vifparams;
70 enum nl80211_iftype type;
Johannes Bergac7f9cf2009-03-21 17:07:59 +010071 int ret;
Johannes Berge60c7742008-11-26 23:31:40 +010072
73 if (!wdev)
74 return -EOPNOTSUPP;
75
76 rdev = wiphy_to_dev(wdev->wiphy);
77
78 if (!rdev->ops->change_virtual_intf)
79 return -EOPNOTSUPP;
80
81 /* don't support changing VLANs, you just re-create them */
82 if (wdev->iftype == NL80211_IFTYPE_AP_VLAN)
83 return -EOPNOTSUPP;
84
85 switch (*mode) {
86 case IW_MODE_INFRA:
87 type = NL80211_IFTYPE_STATION;
88 break;
89 case IW_MODE_ADHOC:
90 type = NL80211_IFTYPE_ADHOC;
91 break;
92 case IW_MODE_REPEAT:
93 type = NL80211_IFTYPE_WDS;
94 break;
95 case IW_MODE_MONITOR:
96 type = NL80211_IFTYPE_MONITOR;
97 break;
98 default:
99 return -EINVAL;
100 }
101
Johannes Bergac7f9cf2009-03-21 17:07:59 +0100102 if (type == wdev->iftype)
103 return 0;
104
Johannes Berge60c7742008-11-26 23:31:40 +0100105 memset(&vifparams, 0, sizeof(vifparams));
106
Johannes Berge36d56b2009-06-09 21:04:43 +0200107 ret = rdev->ops->change_virtual_intf(wdev->wiphy, dev, type,
Johannes Bergac7f9cf2009-03-21 17:07:59 +0100108 NULL, &vifparams);
109 WARN_ON(!ret && wdev->iftype != type);
110
111 return ret;
Johannes Berge60c7742008-11-26 23:31:40 +0100112}
Johannes Bergba44cb72009-04-20 18:49:39 +0200113EXPORT_SYMBOL_GPL(cfg80211_wext_siwmode);
Johannes Berge60c7742008-11-26 23:31:40 +0100114
115int cfg80211_wext_giwmode(struct net_device *dev, struct iw_request_info *info,
116 u32 *mode, char *extra)
117{
118 struct wireless_dev *wdev = dev->ieee80211_ptr;
119
120 if (!wdev)
121 return -EOPNOTSUPP;
122
123 switch (wdev->iftype) {
124 case NL80211_IFTYPE_AP:
125 *mode = IW_MODE_MASTER;
126 break;
127 case NL80211_IFTYPE_STATION:
128 *mode = IW_MODE_INFRA;
129 break;
130 case NL80211_IFTYPE_ADHOC:
131 *mode = IW_MODE_ADHOC;
132 break;
133 case NL80211_IFTYPE_MONITOR:
134 *mode = IW_MODE_MONITOR;
135 break;
136 case NL80211_IFTYPE_WDS:
137 *mode = IW_MODE_REPEAT;
138 break;
139 case NL80211_IFTYPE_AP_VLAN:
140 *mode = IW_MODE_SECOND; /* FIXME */
141 break;
142 default:
143 *mode = IW_MODE_AUTO;
144 break;
145 }
146 return 0;
147}
Johannes Bergba44cb72009-04-20 18:49:39 +0200148EXPORT_SYMBOL_GPL(cfg80211_wext_giwmode);
Johannes Berg4aa188e2009-02-18 19:32:08 +0100149
150
151int cfg80211_wext_giwrange(struct net_device *dev,
152 struct iw_request_info *info,
153 struct iw_point *data, char *extra)
154{
155 struct wireless_dev *wdev = dev->ieee80211_ptr;
156 struct iw_range *range = (struct iw_range *) extra;
157 enum ieee80211_band band;
Johannes Berg9834c072009-07-06 19:40:51 +0200158 int i, c = 0;
Johannes Berg4aa188e2009-02-18 19:32:08 +0100159
160 if (!wdev)
161 return -EOPNOTSUPP;
162
163 data->length = sizeof(struct iw_range);
164 memset(range, 0, sizeof(struct iw_range));
165
166 range->we_version_compiled = WIRELESS_EXT;
167 range->we_version_source = 21;
168 range->retry_capa = IW_RETRY_LIMIT;
169 range->retry_flags = IW_RETRY_LIMIT;
170 range->min_retry = 0;
171 range->max_retry = 255;
172 range->min_rts = 0;
173 range->max_rts = 2347;
174 range->min_frag = 256;
175 range->max_frag = 2346;
176
Johannes Berg4aa188e2009-02-18 19:32:08 +0100177 range->max_encoding_tokens = 4;
178
179 range->max_qual.updated = IW_QUAL_NOISE_INVALID;
180
181 switch (wdev->wiphy->signal_type) {
182 case CFG80211_SIGNAL_TYPE_NONE:
183 break;
184 case CFG80211_SIGNAL_TYPE_MBM:
185 range->max_qual.level = -110;
186 range->max_qual.qual = 70;
187 range->avg_qual.qual = 35;
188 range->max_qual.updated |= IW_QUAL_DBM;
189 range->max_qual.updated |= IW_QUAL_QUAL_UPDATED;
190 range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED;
191 break;
192 case CFG80211_SIGNAL_TYPE_UNSPEC:
193 range->max_qual.level = 100;
194 range->max_qual.qual = 100;
195 range->avg_qual.qual = 50;
196 range->max_qual.updated |= IW_QUAL_QUAL_UPDATED;
197 range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED;
198 break;
199 }
200
201 range->avg_qual.level = range->max_qual.level / 2;
202 range->avg_qual.noise = range->max_qual.noise / 2;
203 range->avg_qual.updated = range->max_qual.updated;
204
Johannes Berg9834c072009-07-06 19:40:51 +0200205 for (i = 0; i < wdev->wiphy->n_cipher_suites; i++) {
206 switch (wdev->wiphy->cipher_suites[i]) {
David Kilroy3daf0972009-06-18 23:21:14 +0100207 case WLAN_CIPHER_SUITE_TKIP:
David Kilroy27bea662009-06-18 23:21:17 +0100208 range->enc_capa |= (IW_ENC_CAPA_CIPHER_TKIP |
209 IW_ENC_CAPA_WPA);
David Kilroy3daf0972009-06-18 23:21:14 +0100210 break;
211
212 case WLAN_CIPHER_SUITE_CCMP:
David Kilroy27bea662009-06-18 23:21:17 +0100213 range->enc_capa |= (IW_ENC_CAPA_CIPHER_CCMP |
214 IW_ENC_CAPA_WPA2);
David Kilroy3daf0972009-06-18 23:21:14 +0100215 break;
David Kilroy2ab658f2009-06-18 23:21:16 +0100216
217 case WLAN_CIPHER_SUITE_WEP40:
218 range->encoding_size[range->num_encoding_sizes++] =
219 WLAN_KEY_LEN_WEP40;
220 break;
221
222 case WLAN_CIPHER_SUITE_WEP104:
223 range->encoding_size[range->num_encoding_sizes++] =
224 WLAN_KEY_LEN_WEP104;
225 break;
David Kilroy3daf0972009-06-18 23:21:14 +0100226 }
227 }
Johannes Berg4aa188e2009-02-18 19:32:08 +0100228
Johannes Berg4aa188e2009-02-18 19:32:08 +0100229 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
Johannes Berg4aa188e2009-02-18 19:32:08 +0100230 struct ieee80211_supported_band *sband;
231
232 sband = wdev->wiphy->bands[band];
233
234 if (!sband)
235 continue;
236
237 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
238 struct ieee80211_channel *chan = &sband->channels[i];
239
240 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
241 range->freq[c].i =
242 ieee80211_frequency_to_channel(
243 chan->center_freq);
244 range->freq[c].m = chan->center_freq;
245 range->freq[c].e = 6;
246 c++;
247 }
248 }
249 }
250 range->num_channels = c;
251 range->num_frequency = c;
252
253 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
254 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
255 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
256
David Kilroy51cd4aa2009-06-18 23:21:15 +0100257 if (wdev->wiphy->max_scan_ssids > 0)
258 range->scan_capa |= IW_SCAN_CAPA_ESSID;
Johannes Berg4aa188e2009-02-18 19:32:08 +0100259
260 return 0;
261}
Johannes Bergba44cb72009-04-20 18:49:39 +0200262EXPORT_SYMBOL_GPL(cfg80211_wext_giwrange);
Johannes Berg691597c2009-04-19 19:57:45 +0200263
Johannes Berg04a773a2009-04-19 21:24:32 +0200264
265/**
266 * cfg80211_wext_freq - get wext frequency for non-"auto"
267 * @wiphy: the wiphy
268 * @freq: the wext freq encoding
269 *
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200270 * Returns a frequency, or a negative error code, or 0 for auto.
Johannes Berg04a773a2009-04-19 21:24:32 +0200271 */
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200272int cfg80211_wext_freq(struct wiphy *wiphy, struct iw_freq *freq)
Johannes Berg04a773a2009-04-19 21:24:32 +0200273{
Johannes Berg0b258582009-05-08 09:42:33 +0200274 /*
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200275 * Parse frequency - return 0 for auto and
Johannes Berg0b258582009-05-08 09:42:33 +0200276 * -EINVAL for impossible things.
277 */
Johannes Berg04a773a2009-04-19 21:24:32 +0200278 if (freq->e == 0) {
279 if (freq->m < 0)
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200280 return 0;
281 return ieee80211_channel_to_frequency(freq->m);
Johannes Berg04a773a2009-04-19 21:24:32 +0200282 } else {
283 int i, div = 1000000;
284 for (i = 0; i < freq->e; i++)
285 div /= 10;
Johannes Berg0b258582009-05-08 09:42:33 +0200286 if (div <= 0)
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200287 return -EINVAL;
288 return freq->m / div;
Johannes Berg04a773a2009-04-19 21:24:32 +0200289 }
Johannes Berg04a773a2009-04-19 21:24:32 +0200290}
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200291
292int cfg80211_wext_siwrts(struct net_device *dev,
293 struct iw_request_info *info,
294 struct iw_param *rts, char *extra)
295{
296 struct wireless_dev *wdev = dev->ieee80211_ptr;
297 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
298 u32 orts = wdev->wiphy->rts_threshold;
299 int err;
300
301 if (rts->disabled || !rts->fixed)
302 wdev->wiphy->rts_threshold = (u32) -1;
303 else if (rts->value < 0)
304 return -EINVAL;
305 else
306 wdev->wiphy->rts_threshold = rts->value;
307
308 err = rdev->ops->set_wiphy_params(wdev->wiphy,
309 WIPHY_PARAM_RTS_THRESHOLD);
310 if (err)
311 wdev->wiphy->rts_threshold = orts;
312
313 return err;
314}
Johannes Bergba44cb72009-04-20 18:49:39 +0200315EXPORT_SYMBOL_GPL(cfg80211_wext_siwrts);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200316
317int cfg80211_wext_giwrts(struct net_device *dev,
318 struct iw_request_info *info,
319 struct iw_param *rts, char *extra)
320{
321 struct wireless_dev *wdev = dev->ieee80211_ptr;
322
323 rts->value = wdev->wiphy->rts_threshold;
324 rts->disabled = rts->value == (u32) -1;
325 rts->fixed = 1;
326
327 return 0;
328}
Johannes Bergba44cb72009-04-20 18:49:39 +0200329EXPORT_SYMBOL_GPL(cfg80211_wext_giwrts);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200330
331int cfg80211_wext_siwfrag(struct net_device *dev,
332 struct iw_request_info *info,
333 struct iw_param *frag, char *extra)
334{
335 struct wireless_dev *wdev = dev->ieee80211_ptr;
336 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
337 u32 ofrag = wdev->wiphy->frag_threshold;
338 int err;
339
340 if (frag->disabled || !frag->fixed)
341 wdev->wiphy->frag_threshold = (u32) -1;
342 else if (frag->value < 256)
343 return -EINVAL;
344 else {
345 /* Fragment length must be even, so strip LSB. */
346 wdev->wiphy->frag_threshold = frag->value & ~0x1;
347 }
348
349 err = rdev->ops->set_wiphy_params(wdev->wiphy,
350 WIPHY_PARAM_FRAG_THRESHOLD);
351 if (err)
352 wdev->wiphy->frag_threshold = ofrag;
353
354 return err;
355}
Johannes Bergba44cb72009-04-20 18:49:39 +0200356EXPORT_SYMBOL_GPL(cfg80211_wext_siwfrag);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200357
358int cfg80211_wext_giwfrag(struct net_device *dev,
359 struct iw_request_info *info,
360 struct iw_param *frag, char *extra)
361{
362 struct wireless_dev *wdev = dev->ieee80211_ptr;
363
364 frag->value = wdev->wiphy->frag_threshold;
365 frag->disabled = frag->value == (u32) -1;
366 frag->fixed = 1;
367
368 return 0;
369}
Johannes Bergba44cb72009-04-20 18:49:39 +0200370EXPORT_SYMBOL_GPL(cfg80211_wext_giwfrag);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200371
372int cfg80211_wext_siwretry(struct net_device *dev,
373 struct iw_request_info *info,
374 struct iw_param *retry, char *extra)
375{
376 struct wireless_dev *wdev = dev->ieee80211_ptr;
377 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
378 u32 changed = 0;
379 u8 olong = wdev->wiphy->retry_long;
380 u8 oshort = wdev->wiphy->retry_short;
381 int err;
382
383 if (retry->disabled ||
384 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
385 return -EINVAL;
386
387 if (retry->flags & IW_RETRY_LONG) {
388 wdev->wiphy->retry_long = retry->value;
389 changed |= WIPHY_PARAM_RETRY_LONG;
390 } else if (retry->flags & IW_RETRY_SHORT) {
391 wdev->wiphy->retry_short = retry->value;
392 changed |= WIPHY_PARAM_RETRY_SHORT;
393 } else {
394 wdev->wiphy->retry_short = retry->value;
395 wdev->wiphy->retry_long = retry->value;
396 changed |= WIPHY_PARAM_RETRY_LONG;
397 changed |= WIPHY_PARAM_RETRY_SHORT;
398 }
399
400 if (!changed)
401 return 0;
402
403 err = rdev->ops->set_wiphy_params(wdev->wiphy, changed);
404 if (err) {
405 wdev->wiphy->retry_short = oshort;
406 wdev->wiphy->retry_long = olong;
407 }
408
409 return err;
410}
Johannes Bergba44cb72009-04-20 18:49:39 +0200411EXPORT_SYMBOL_GPL(cfg80211_wext_siwretry);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200412
413int cfg80211_wext_giwretry(struct net_device *dev,
414 struct iw_request_info *info,
415 struct iw_param *retry, char *extra)
416{
417 struct wireless_dev *wdev = dev->ieee80211_ptr;
418
419 retry->disabled = 0;
420
421 if (retry->flags == 0 || (retry->flags & IW_RETRY_SHORT)) {
422 /*
423 * First return short value, iwconfig will ask long value
424 * later if needed
425 */
426 retry->flags |= IW_RETRY_LIMIT;
427 retry->value = wdev->wiphy->retry_short;
428 if (wdev->wiphy->retry_long != wdev->wiphy->retry_short)
429 retry->flags |= IW_RETRY_LONG;
430
431 return 0;
432 }
433
434 if (retry->flags & IW_RETRY_LONG) {
435 retry->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
436 retry->value = wdev->wiphy->retry_long;
437 }
438
439 return 0;
440}
Johannes Bergba44cb72009-04-20 18:49:39 +0200441EXPORT_SYMBOL_GPL(cfg80211_wext_giwretry);
Johannes Berg08645122009-05-11 13:54:58 +0200442
Johannes Bergfffd0932009-07-08 14:22:54 +0200443static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
444 struct net_device *dev, const u8 *addr,
445 bool remove, bool tx_key, int idx,
446 struct key_params *params)
Johannes Berg08645122009-05-11 13:54:58 +0200447{
448 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergfffd0932009-07-08 14:22:54 +0200449 int err, i;
450
451 if (!wdev->wext.keys) {
452 wdev->wext.keys = kzalloc(sizeof(*wdev->wext.keys),
453 GFP_KERNEL);
454 if (!wdev->wext.keys)
455 return -ENOMEM;
456 for (i = 0; i < 6; i++)
457 wdev->wext.keys->params[i].key =
458 wdev->wext.keys->data[i];
459 }
460
461 if (wdev->iftype != NL80211_IFTYPE_ADHOC &&
462 wdev->iftype != NL80211_IFTYPE_STATION)
463 return -EOPNOTSUPP;
Johannes Berg08645122009-05-11 13:54:58 +0200464
465 if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
Johannes Bergfffd0932009-07-08 14:22:54 +0200466 if (!wdev->current_bss)
467 return -ENOLINK;
468
Johannes Berg08645122009-05-11 13:54:58 +0200469 if (!rdev->ops->set_default_mgmt_key)
470 return -EOPNOTSUPP;
471
472 if (idx < 4 || idx > 5)
473 return -EINVAL;
474 } else if (idx < 0 || idx > 3)
475 return -EINVAL;
476
477 if (remove) {
Johannes Bergfffd0932009-07-08 14:22:54 +0200478 err = 0;
479 if (wdev->current_bss)
480 err = rdev->ops->del_key(&rdev->wiphy, dev, idx, addr);
Johannes Berg08645122009-05-11 13:54:58 +0200481 if (!err) {
Johannes Bergfffd0932009-07-08 14:22:54 +0200482 if (!addr) {
483 wdev->wext.keys->params[idx].key_len = 0;
484 wdev->wext.keys->params[idx].cipher = 0;
485 }
Johannes Berg08645122009-05-11 13:54:58 +0200486 if (idx == wdev->wext.default_key)
487 wdev->wext.default_key = -1;
488 else if (idx == wdev->wext.default_mgmt_key)
489 wdev->wext.default_mgmt_key = -1;
490 }
Johannes Berge3da5742009-05-18 19:56:36 +0200491 /*
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 return 0;
497
Johannes Berg08645122009-05-11 13:54:58 +0200498 return err;
Johannes Bergfffd0932009-07-08 14:22:54 +0200499 }
Johannes Berg08645122009-05-11 13:54:58 +0200500
Johannes Bergfffd0932009-07-08 14:22:54 +0200501 if (addr)
502 tx_key = false;
Johannes Berg08645122009-05-11 13:54:58 +0200503
Johannes Bergfffd0932009-07-08 14:22:54 +0200504 if (cfg80211_validate_key_settings(rdev, params, idx, addr))
505 return -EINVAL;
506
507 err = 0;
508 if (wdev->current_bss)
Johannes Berg08645122009-05-11 13:54:58 +0200509 err = rdev->ops->add_key(&rdev->wiphy, dev, idx, addr, params);
Johannes Bergfffd0932009-07-08 14:22:54 +0200510 if (err)
511 return err;
Johannes Berg08645122009-05-11 13:54:58 +0200512
Johannes Bergfffd0932009-07-08 14:22:54 +0200513 if (!addr) {
514 wdev->wext.keys->params[idx] = *params;
515 memcpy(wdev->wext.keys->data[idx],
516 params->key, params->key_len);
517 wdev->wext.keys->params[idx].key =
518 wdev->wext.keys->data[idx];
519 }
520
Zhu Yi1f00fca2009-07-20 11:47:43 +0800521 if ((params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
522 params->cipher == WLAN_CIPHER_SUITE_WEP104) &&
Johannes Bergfffd0932009-07-08 14:22:54 +0200523 (tx_key || (!addr && wdev->wext.default_key == -1))) {
524 if (wdev->current_bss)
Johannes Berg08645122009-05-11 13:54:58 +0200525 err = rdev->ops->set_default_key(&rdev->wiphy,
526 dev, idx);
Johannes Bergfffd0932009-07-08 14:22:54 +0200527 if (!err)
528 wdev->wext.default_key = idx;
529 return err;
530 }
Johannes Berg08645122009-05-11 13:54:58 +0200531
Johannes Bergfffd0932009-07-08 14:22:54 +0200532 if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC &&
533 (tx_key || (!addr && wdev->wext.default_mgmt_key == -1))) {
534 if (wdev->current_bss)
Johannes Berg08645122009-05-11 13:54:58 +0200535 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
536 dev, idx);
Johannes Bergfffd0932009-07-08 14:22:54 +0200537 if (!err)
538 wdev->wext.default_mgmt_key = idx;
539 return err;
Johannes Berg08645122009-05-11 13:54:58 +0200540 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200541
542 return 0;
543}
544
545static int cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
546 struct net_device *dev, const u8 *addr,
547 bool remove, bool tx_key, int idx,
548 struct key_params *params)
549{
550 int err;
551
552 wdev_lock(dev->ieee80211_ptr);
553 err = __cfg80211_set_encryption(rdev, dev, addr, remove,
554 tx_key, idx, params);
555 wdev_unlock(dev->ieee80211_ptr);
556
557 return err;
Johannes Berg08645122009-05-11 13:54:58 +0200558}
559
560int cfg80211_wext_siwencode(struct net_device *dev,
561 struct iw_request_info *info,
562 struct iw_point *erq, char *keybuf)
563{
564 struct wireless_dev *wdev = dev->ieee80211_ptr;
565 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
566 int idx, err;
567 bool remove = false;
568 struct key_params params;
569
Johannes Bergfffd0932009-07-08 14:22:54 +0200570 if (wdev->iftype != NL80211_IFTYPE_STATION &&
571 wdev->iftype != NL80211_IFTYPE_ADHOC)
572 return -EOPNOTSUPP;
573
Johannes Berg08645122009-05-11 13:54:58 +0200574 /* no use -- only MFP (set_default_mgmt_key) is optional */
575 if (!rdev->ops->del_key ||
576 !rdev->ops->add_key ||
577 !rdev->ops->set_default_key)
578 return -EOPNOTSUPP;
579
580 idx = erq->flags & IW_ENCODE_INDEX;
581 if (idx == 0) {
582 idx = wdev->wext.default_key;
583 if (idx < 0)
584 idx = 0;
585 } else if (idx < 1 || idx > 4)
586 return -EINVAL;
587 else
588 idx--;
589
590 if (erq->flags & IW_ENCODE_DISABLED)
591 remove = true;
592 else if (erq->length == 0) {
593 /* No key data - just set the default TX key index */
Johannes Bergfffd0932009-07-08 14:22:54 +0200594 err = 0;
595 wdev_lock(wdev);
596 if (wdev->current_bss)
597 err = rdev->ops->set_default_key(&rdev->wiphy,
598 dev, idx);
Johannes Berg08645122009-05-11 13:54:58 +0200599 if (!err)
600 wdev->wext.default_key = idx;
Johannes Bergfffd0932009-07-08 14:22:54 +0200601 wdev_unlock(wdev);
Johannes Berg08645122009-05-11 13:54:58 +0200602 return err;
603 }
604
605 memset(&params, 0, sizeof(params));
606 params.key = keybuf;
607 params.key_len = erq->length;
608 if (erq->length == 5)
609 params.cipher = WLAN_CIPHER_SUITE_WEP40;
610 else if (erq->length == 13)
611 params.cipher = WLAN_CIPHER_SUITE_WEP104;
612 else if (!remove)
613 return -EINVAL;
614
615 return cfg80211_set_encryption(rdev, dev, NULL, remove,
616 wdev->wext.default_key == -1,
617 idx, &params);
618}
619EXPORT_SYMBOL_GPL(cfg80211_wext_siwencode);
620
621int cfg80211_wext_siwencodeext(struct net_device *dev,
622 struct iw_request_info *info,
623 struct iw_point *erq, char *extra)
624{
625 struct wireless_dev *wdev = dev->ieee80211_ptr;
626 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
627 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
628 const u8 *addr;
629 int idx;
630 bool remove = false;
631 struct key_params params;
632 u32 cipher;
633
Johannes Bergfffd0932009-07-08 14:22:54 +0200634 if (wdev->iftype != NL80211_IFTYPE_STATION &&
635 wdev->iftype != NL80211_IFTYPE_ADHOC)
636 return -EOPNOTSUPP;
637
Johannes Berg08645122009-05-11 13:54:58 +0200638 /* no use -- only MFP (set_default_mgmt_key) is optional */
639 if (!rdev->ops->del_key ||
640 !rdev->ops->add_key ||
641 !rdev->ops->set_default_key)
642 return -EOPNOTSUPP;
643
644 switch (ext->alg) {
645 case IW_ENCODE_ALG_NONE:
646 remove = true;
647 cipher = 0;
648 break;
649 case IW_ENCODE_ALG_WEP:
650 if (ext->key_len == 5)
651 cipher = WLAN_CIPHER_SUITE_WEP40;
652 else if (ext->key_len == 13)
653 cipher = WLAN_CIPHER_SUITE_WEP104;
654 else
655 return -EINVAL;
656 break;
657 case IW_ENCODE_ALG_TKIP:
658 cipher = WLAN_CIPHER_SUITE_TKIP;
659 break;
660 case IW_ENCODE_ALG_CCMP:
661 cipher = WLAN_CIPHER_SUITE_CCMP;
662 break;
663 case IW_ENCODE_ALG_AES_CMAC:
664 cipher = WLAN_CIPHER_SUITE_AES_CMAC;
665 break;
666 default:
667 return -EOPNOTSUPP;
668 }
669
670 if (erq->flags & IW_ENCODE_DISABLED)
671 remove = true;
672
673 idx = erq->flags & IW_ENCODE_INDEX;
674 if (cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
675 if (idx < 4 || idx > 5) {
676 idx = wdev->wext.default_mgmt_key;
677 if (idx < 0)
678 return -EINVAL;
679 } else
680 idx--;
681 } else {
682 if (idx < 1 || idx > 4) {
683 idx = wdev->wext.default_key;
684 if (idx < 0)
685 return -EINVAL;
686 } else
687 idx--;
688 }
689
690 addr = ext->addr.sa_data;
691 if (is_broadcast_ether_addr(addr))
692 addr = NULL;
693
694 memset(&params, 0, sizeof(params));
695 params.key = ext->key;
696 params.key_len = ext->key_len;
697 params.cipher = cipher;
698
Jouni Malinenfaa8fdc2009-05-11 21:57:58 +0300699 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
700 params.seq = ext->rx_seq;
701 params.seq_len = 6;
702 }
703
Johannes Berg08645122009-05-11 13:54:58 +0200704 return cfg80211_set_encryption(
705 rdev, dev, addr, remove,
706 ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
707 idx, &params);
708}
709EXPORT_SYMBOL_GPL(cfg80211_wext_siwencodeext);
710
Johannes Berg08645122009-05-11 13:54:58 +0200711int cfg80211_wext_giwencode(struct net_device *dev,
712 struct iw_request_info *info,
713 struct iw_point *erq, char *keybuf)
714{
715 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergfffd0932009-07-08 14:22:54 +0200716 int idx;
Johannes Berg08645122009-05-11 13:54:58 +0200717
Johannes Bergfffd0932009-07-08 14:22:54 +0200718 if (wdev->iftype != NL80211_IFTYPE_STATION &&
719 wdev->iftype != NL80211_IFTYPE_ADHOC)
Johannes Berg08645122009-05-11 13:54:58 +0200720 return -EOPNOTSUPP;
721
722 idx = erq->flags & IW_ENCODE_INDEX;
723 if (idx == 0) {
724 idx = wdev->wext.default_key;
725 if (idx < 0)
726 idx = 0;
727 } else if (idx < 1 || idx > 4)
728 return -EINVAL;
729 else
730 idx--;
731
732 erq->flags = idx + 1;
733
Johannes Bergfffd0932009-07-08 14:22:54 +0200734 if (!wdev->wext.keys || !wdev->wext.keys->params[idx].cipher) {
Johannes Berg08645122009-05-11 13:54:58 +0200735 erq->flags |= IW_ENCODE_DISABLED;
736 erq->length = 0;
737 return 0;
738 }
739
Johannes Bergfffd0932009-07-08 14:22:54 +0200740 erq->length = min_t(size_t, erq->length,
741 wdev->wext.keys->params[idx].key_len);
742 memcpy(keybuf, wdev->wext.keys->params[idx].key, erq->length);
743 erq->flags |= IW_ENCODE_ENABLED;
744
745 return 0;
Johannes Berg08645122009-05-11 13:54:58 +0200746}
747EXPORT_SYMBOL_GPL(cfg80211_wext_giwencode);
Johannes Berg7643a2c2009-06-02 13:01:39 +0200748
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200749int cfg80211_wext_siwfreq(struct net_device *dev,
750 struct iw_request_info *info,
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200751 struct iw_freq *wextfreq, char *extra)
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200752{
753 struct wireless_dev *wdev = dev->ieee80211_ptr;
754 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200755 int freq, err;
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200756
757 switch (wdev->iftype) {
758 case NL80211_IFTYPE_STATION:
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200759 return cfg80211_mgd_wext_siwfreq(dev, info, wextfreq, extra);
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200760 case NL80211_IFTYPE_ADHOC:
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200761 return cfg80211_ibss_wext_siwfreq(dev, info, wextfreq, extra);
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200762 default:
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200763 freq = cfg80211_wext_freq(wdev->wiphy, wextfreq);
764 if (freq < 0)
765 return freq;
766 if (freq == 0)
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200767 return -EINVAL;
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200768 mutex_lock(&rdev->devlist_mtx);
Johannes Berg4b181142009-08-08 11:03:58 +0200769 err = rdev_set_freq(rdev, NULL, freq, NL80211_CHAN_NO_HT);
Johannes Berg59bbb6f2009-08-07 17:22:35 +0200770 mutex_unlock(&rdev->devlist_mtx);
771 return err;
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200772 }
773}
Jussi Kivilinnaa8b875e2009-08-13 20:39:31 +0300774EXPORT_SYMBOL_GPL(cfg80211_wext_siwfreq);
Johannes Berg0e82ffe2009-07-27 12:01:50 +0200775
776int cfg80211_wext_giwfreq(struct net_device *dev,
777 struct iw_request_info *info,
778 struct iw_freq *freq, char *extra)
779{
780 struct wireless_dev *wdev = dev->ieee80211_ptr;
781 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
782
783 switch (wdev->iftype) {
784 case NL80211_IFTYPE_STATION:
785 return cfg80211_mgd_wext_giwfreq(dev, info, freq, extra);
786 case NL80211_IFTYPE_ADHOC:
787 return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra);
788 default:
789 if (!rdev->channel)
790 return -EINVAL;
791 freq->m = rdev->channel->center_freq;
792 freq->e = 6;
793 return 0;
794 }
795}
796EXPORT_SYMBOL_GPL(cfg80211_wext_giwfreq);
797
Johannes Berg7643a2c2009-06-02 13:01:39 +0200798int cfg80211_wext_siwtxpower(struct net_device *dev,
799 struct iw_request_info *info,
800 union iwreq_data *data, char *extra)
801{
802 struct wireless_dev *wdev = dev->ieee80211_ptr;
803 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
804 enum tx_power_setting type;
805 int dbm = 0;
806
807 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
808 return -EINVAL;
809 if (data->txpower.flags & IW_TXPOW_RANGE)
810 return -EINVAL;
811
812 if (!rdev->ops->set_tx_power)
813 return -EOPNOTSUPP;
814
815 /* only change when not disabling */
816 if (!data->txpower.disabled) {
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200817 rfkill_set_sw_state(rdev->rfkill, false);
818
Johannes Berg7643a2c2009-06-02 13:01:39 +0200819 if (data->txpower.fixed) {
820 /*
821 * wext doesn't support negative values, see
822 * below where it's for automatic
823 */
824 if (data->txpower.value < 0)
825 return -EINVAL;
826 dbm = data->txpower.value;
827 type = TX_POWER_FIXED;
828 /* TODO: do regulatory check! */
829 } else {
830 /*
831 * Automatic power level setting, max being the value
832 * passed in from userland.
833 */
834 if (data->txpower.value < 0) {
835 type = TX_POWER_AUTOMATIC;
836 } else {
837 dbm = data->txpower.value;
838 type = TX_POWER_LIMITED;
839 }
840 }
841 } else {
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200842 rfkill_set_sw_state(rdev->rfkill, true);
843 schedule_work(&rdev->rfkill_sync);
844 return 0;
Johannes Berg7643a2c2009-06-02 13:01:39 +0200845 }
846
847 return rdev->ops->set_tx_power(wdev->wiphy, type, dbm);;
848}
849EXPORT_SYMBOL_GPL(cfg80211_wext_siwtxpower);
850
851int cfg80211_wext_giwtxpower(struct net_device *dev,
852 struct iw_request_info *info,
853 union iwreq_data *data, char *extra)
854{
855 struct wireless_dev *wdev = dev->ieee80211_ptr;
856 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
857 int err, val;
858
859 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
860 return -EINVAL;
861 if (data->txpower.flags & IW_TXPOW_RANGE)
862 return -EINVAL;
863
864 if (!rdev->ops->get_tx_power)
865 return -EOPNOTSUPP;
866
867 err = rdev->ops->get_tx_power(wdev->wiphy, &val);
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200868 if (err)
Johannes Berg7643a2c2009-06-02 13:01:39 +0200869 return err;
870
871 /* well... oh well */
872 data->txpower.fixed = 1;
Johannes Berg1f87f7d2009-06-02 13:01:41 +0200873 data->txpower.disabled = rfkill_blocked(rdev->rfkill);
Johannes Berg7643a2c2009-06-02 13:01:39 +0200874 data->txpower.value = val;
875 data->txpower.flags = IW_TXPOW_DBM;
876
877 return 0;
878}
879EXPORT_SYMBOL_GPL(cfg80211_wext_giwtxpower);
Johannes Bergf2129352009-07-01 21:26:56 +0200880
881static int cfg80211_set_auth_alg(struct wireless_dev *wdev,
882 s32 auth_alg)
883{
884 int nr_alg = 0;
885
886 if (!auth_alg)
887 return -EINVAL;
888
889 if (auth_alg & ~(IW_AUTH_ALG_OPEN_SYSTEM |
890 IW_AUTH_ALG_SHARED_KEY |
891 IW_AUTH_ALG_LEAP))
892 return -EINVAL;
893
894 if (auth_alg & IW_AUTH_ALG_OPEN_SYSTEM) {
895 nr_alg++;
896 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
897 }
898
899 if (auth_alg & IW_AUTH_ALG_SHARED_KEY) {
900 nr_alg++;
901 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_SHARED_KEY;
902 }
903
904 if (auth_alg & IW_AUTH_ALG_LEAP) {
905 nr_alg++;
906 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_NETWORK_EAP;
907 }
908
909 if (nr_alg > 1)
910 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
911
912 return 0;
913}
914
915static int cfg80211_set_wpa_version(struct wireless_dev *wdev, u32 wpa_versions)
916{
917 wdev->wext.connect.crypto.wpa_versions = 0;
918
919 if (wpa_versions & ~(IW_AUTH_WPA_VERSION_WPA |
Gábor Stefanik323d5662009-07-12 02:03:48 +0200920 IW_AUTH_WPA_VERSION_WPA2|
921 IW_AUTH_WPA_VERSION_DISABLED))
Johannes Bergf2129352009-07-01 21:26:56 +0200922 return -EINVAL;
923
Gábor Stefanik323d5662009-07-12 02:03:48 +0200924 if ((wpa_versions & IW_AUTH_WPA_VERSION_DISABLED) &&
925 (wpa_versions & (IW_AUTH_WPA_VERSION_WPA|
926 IW_AUTH_WPA_VERSION_WPA2)))
927 return -EINVAL;
928
929 if (wpa_versions & IW_AUTH_WPA_VERSION_DISABLED)
930 wdev->wext.connect.crypto.wpa_versions &=
931 ~(NL80211_WPA_VERSION_1|NL80211_WPA_VERSION_2);
932
Johannes Bergf2129352009-07-01 21:26:56 +0200933 if (wpa_versions & IW_AUTH_WPA_VERSION_WPA)
934 wdev->wext.connect.crypto.wpa_versions |=
935 NL80211_WPA_VERSION_1;
936
937 if (wpa_versions & IW_AUTH_WPA_VERSION_WPA2)
938 wdev->wext.connect.crypto.wpa_versions |=
939 NL80211_WPA_VERSION_2;
940
941 return 0;
942}
943
Johannes Berg4f5dadc2009-07-07 03:56:10 +0200944static int cfg80211_set_cipher_group(struct wireless_dev *wdev, u32 cipher)
Johannes Bergf2129352009-07-01 21:26:56 +0200945{
946 wdev->wext.connect.crypto.cipher_group = 0;
947
948 if (cipher & IW_AUTH_CIPHER_WEP40)
949 wdev->wext.connect.crypto.cipher_group =
950 WLAN_CIPHER_SUITE_WEP40;
951 else if (cipher & IW_AUTH_CIPHER_WEP104)
952 wdev->wext.connect.crypto.cipher_group =
953 WLAN_CIPHER_SUITE_WEP104;
954 else if (cipher & IW_AUTH_CIPHER_TKIP)
955 wdev->wext.connect.crypto.cipher_group =
956 WLAN_CIPHER_SUITE_TKIP;
957 else if (cipher & IW_AUTH_CIPHER_CCMP)
958 wdev->wext.connect.crypto.cipher_group =
959 WLAN_CIPHER_SUITE_CCMP;
960 else if (cipher & IW_AUTH_CIPHER_AES_CMAC)
961 wdev->wext.connect.crypto.cipher_group =
962 WLAN_CIPHER_SUITE_AES_CMAC;
963 else
964 return -EINVAL;
965
966 return 0;
967}
968
Johannes Berg4f5dadc2009-07-07 03:56:10 +0200969static int cfg80211_set_cipher_pairwise(struct wireless_dev *wdev, u32 cipher)
Johannes Bergf2129352009-07-01 21:26:56 +0200970{
971 int nr_ciphers = 0;
972 u32 *ciphers_pairwise = wdev->wext.connect.crypto.ciphers_pairwise;
973
974 if (cipher & IW_AUTH_CIPHER_WEP40) {
975 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP40;
976 nr_ciphers++;
977 }
978
979 if (cipher & IW_AUTH_CIPHER_WEP104) {
980 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP104;
981 nr_ciphers++;
982 }
983
984 if (cipher & IW_AUTH_CIPHER_TKIP) {
985 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_TKIP;
986 nr_ciphers++;
987 }
988
989 if (cipher & IW_AUTH_CIPHER_CCMP) {
990 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_CCMP;
991 nr_ciphers++;
992 }
993
994 if (cipher & IW_AUTH_CIPHER_AES_CMAC) {
995 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_AES_CMAC;
996 nr_ciphers++;
997 }
998
999 BUILD_BUG_ON(NL80211_MAX_NR_CIPHER_SUITES < 5);
1000
1001 wdev->wext.connect.crypto.n_ciphers_pairwise = nr_ciphers;
1002
1003 return 0;
1004}
1005
1006
Johannes Berg4f5dadc2009-07-07 03:56:10 +02001007static int cfg80211_set_key_mgt(struct wireless_dev *wdev, u32 key_mgt)
Johannes Bergf2129352009-07-01 21:26:56 +02001008{
1009 int nr_akm_suites = 0;
1010
1011 if (key_mgt & ~(IW_AUTH_KEY_MGMT_802_1X |
1012 IW_AUTH_KEY_MGMT_PSK))
1013 return -EINVAL;
1014
1015 if (key_mgt & IW_AUTH_KEY_MGMT_802_1X) {
1016 wdev->wext.connect.crypto.akm_suites[nr_akm_suites] =
1017 WLAN_AKM_SUITE_8021X;
1018 nr_akm_suites++;
1019 }
1020
1021 if (key_mgt & IW_AUTH_KEY_MGMT_PSK) {
1022 wdev->wext.connect.crypto.akm_suites[nr_akm_suites] =
1023 WLAN_AKM_SUITE_PSK;
1024 nr_akm_suites++;
1025 }
1026
1027 wdev->wext.connect.crypto.n_akm_suites = nr_akm_suites;
1028
1029 return 0;
1030}
1031
1032int cfg80211_wext_siwauth(struct net_device *dev,
1033 struct iw_request_info *info,
1034 struct iw_param *data, char *extra)
1035{
1036 struct wireless_dev *wdev = dev->ieee80211_ptr;
1037
1038 if (wdev->iftype != NL80211_IFTYPE_STATION)
1039 return -EOPNOTSUPP;
1040
1041 switch (data->flags & IW_AUTH_INDEX) {
1042 case IW_AUTH_PRIVACY_INVOKED:
1043 wdev->wext.connect.privacy = data->value;
1044 return 0;
1045 case IW_AUTH_WPA_VERSION:
1046 return cfg80211_set_wpa_version(wdev, data->value);
1047 case IW_AUTH_CIPHER_GROUP:
1048 return cfg80211_set_cipher_group(wdev, data->value);
1049 case IW_AUTH_KEY_MGMT:
1050 return cfg80211_set_key_mgt(wdev, data->value);
1051 case IW_AUTH_CIPHER_PAIRWISE:
1052 return cfg80211_set_cipher_pairwise(wdev, data->value);
1053 case IW_AUTH_80211_AUTH_ALG:
1054 return cfg80211_set_auth_alg(wdev, data->value);
1055 case IW_AUTH_WPA_ENABLED:
1056 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1057 case IW_AUTH_DROP_UNENCRYPTED:
1058 case IW_AUTH_MFP:
1059 return 0;
1060 default:
1061 return -EOPNOTSUPP;
1062 }
1063}
1064EXPORT_SYMBOL_GPL(cfg80211_wext_siwauth);
1065
1066int cfg80211_wext_giwauth(struct net_device *dev,
1067 struct iw_request_info *info,
1068 struct iw_param *data, char *extra)
1069{
1070 /* XXX: what do we need? */
1071
1072 return -EOPNOTSUPP;
1073}
1074EXPORT_SYMBOL_GPL(cfg80211_wext_giwauth);
Johannes Bergbc92afd2009-07-01 21:26:57 +02001075
1076int cfg80211_wext_siwpower(struct net_device *dev,
1077 struct iw_request_info *info,
1078 struct iw_param *wrq, char *extra)
1079{
1080 struct wireless_dev *wdev = dev->ieee80211_ptr;
1081 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1082 bool ps = wdev->wext.ps;
1083 int timeout = wdev->wext.ps_timeout;
1084 int err;
1085
1086 if (wdev->iftype != NL80211_IFTYPE_STATION)
1087 return -EINVAL;
1088
1089 if (!rdev->ops->set_power_mgmt)
1090 return -EOPNOTSUPP;
1091
1092 if (wrq->disabled) {
1093 ps = false;
1094 } else {
1095 switch (wrq->flags & IW_POWER_MODE) {
1096 case IW_POWER_ON: /* If not specified */
1097 case IW_POWER_MODE: /* If set all mask */
1098 case IW_POWER_ALL_R: /* If explicitely state all */
1099 ps = true;
1100 break;
1101 default: /* Otherwise we ignore */
1102 return -EINVAL;
1103 }
1104
1105 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
1106 return -EINVAL;
1107
1108 if (wrq->flags & IW_POWER_TIMEOUT)
1109 timeout = wrq->value / 1000;
1110 }
1111
1112 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, ps, timeout);
1113 if (err)
1114 return err;
1115
1116 wdev->wext.ps = ps;
1117 wdev->wext.ps_timeout = timeout;
1118
1119 return 0;
1120
1121}
1122EXPORT_SYMBOL_GPL(cfg80211_wext_siwpower);
1123
1124int cfg80211_wext_giwpower(struct net_device *dev,
1125 struct iw_request_info *info,
1126 struct iw_param *wrq, char *extra)
1127{
1128 struct wireless_dev *wdev = dev->ieee80211_ptr;
1129
1130 wrq->disabled = !wdev->wext.ps;
1131
1132 return 0;
1133}
1134EXPORT_SYMBOL_GPL(cfg80211_wext_giwpower);
Johannes Bergab737a42009-07-01 21:26:58 +02001135
Johannes Berg562e4822009-07-27 12:01:51 +02001136static int cfg80211_wds_wext_siwap(struct net_device *dev,
1137 struct iw_request_info *info,
1138 struct sockaddr *addr, char *extra)
Johannes Bergab737a42009-07-01 21:26:58 +02001139{
1140 struct wireless_dev *wdev = dev->ieee80211_ptr;
1141 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1142 int err;
1143
1144 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS))
1145 return -EINVAL;
1146
1147 if (addr->sa_family != ARPHRD_ETHER)
1148 return -EINVAL;
1149
1150 if (netif_running(dev))
1151 return -EBUSY;
1152
1153 if (!rdev->ops->set_wds_peer)
1154 return -EOPNOTSUPP;
1155
1156 err = rdev->ops->set_wds_peer(wdev->wiphy, dev, (u8 *) &addr->sa_data);
1157 if (err)
1158 return err;
1159
1160 memcpy(&wdev->wext.bssid, (u8 *) &addr->sa_data, ETH_ALEN);
1161
1162 return 0;
1163}
Johannes Bergab737a42009-07-01 21:26:58 +02001164
Johannes Berg562e4822009-07-27 12:01:51 +02001165static int cfg80211_wds_wext_giwap(struct net_device *dev,
1166 struct iw_request_info *info,
1167 struct sockaddr *addr, char *extra)
Johannes Bergab737a42009-07-01 21:26:58 +02001168{
1169 struct wireless_dev *wdev = dev->ieee80211_ptr;
1170
1171 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS))
1172 return -EINVAL;
1173
1174 addr->sa_family = ARPHRD_ETHER;
1175 memcpy(&addr->sa_data, wdev->wext.bssid, ETH_ALEN);
1176
1177 return 0;
1178}
Johannes Berg99303802009-07-01 21:26:59 +02001179
1180int cfg80211_wext_siwrate(struct net_device *dev,
1181 struct iw_request_info *info,
1182 struct iw_param *rate, char *extra)
1183{
1184 struct wireless_dev *wdev = dev->ieee80211_ptr;
1185 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1186 struct cfg80211_bitrate_mask mask;
1187
1188 if (!rdev->ops->set_bitrate_mask)
1189 return -EOPNOTSUPP;
1190
1191 mask.fixed = 0;
1192 mask.maxrate = 0;
1193
1194 if (rate->value < 0) {
1195 /* nothing */
1196 } else if (rate->fixed) {
1197 mask.fixed = rate->value / 1000; /* kbps */
1198 } else {
1199 mask.maxrate = rate->value / 1000; /* kbps */
1200 }
1201
1202 return rdev->ops->set_bitrate_mask(wdev->wiphy, dev, NULL, &mask);
1203}
1204EXPORT_SYMBOL_GPL(cfg80211_wext_siwrate);
1205
1206int cfg80211_wext_giwrate(struct net_device *dev,
1207 struct iw_request_info *info,
1208 struct iw_param *rate, char *extra)
1209{
1210 struct wireless_dev *wdev = dev->ieee80211_ptr;
1211 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1212 /* we are under RTNL - globally locked - so can use a static struct */
1213 static struct station_info sinfo;
Johannes Berga71d62d2009-07-07 23:41:27 +02001214 u8 addr[ETH_ALEN];
Johannes Berg99303802009-07-01 21:26:59 +02001215 int err;
1216
1217 if (wdev->iftype != NL80211_IFTYPE_STATION)
1218 return -EOPNOTSUPP;
1219
1220 if (!rdev->ops->get_station)
1221 return -EOPNOTSUPP;
1222
Johannes Berga71d62d2009-07-07 23:41:27 +02001223 err = 0;
1224 wdev_lock(wdev);
Samuel Ortiz6c230c02009-07-03 02:00:48 +02001225 if (wdev->current_bss)
Johannes Berga71d62d2009-07-07 23:41:27 +02001226 memcpy(addr, wdev->current_bss->pub.bssid, ETH_ALEN);
Samuel Ortiz6c230c02009-07-03 02:00:48 +02001227 else
Johannes Berga71d62d2009-07-07 23:41:27 +02001228 err = -EOPNOTSUPP;
1229 wdev_unlock(wdev);
1230 if (err)
1231 return err;
Johannes Berg99303802009-07-01 21:26:59 +02001232
1233 err = rdev->ops->get_station(&rdev->wiphy, dev, addr, &sinfo);
1234 if (err)
1235 return err;
1236
1237 if (!(sinfo.filled & STATION_INFO_TX_BITRATE))
1238 return -EOPNOTSUPP;
1239
1240 rate->value = 0;
1241
1242 if (!(sinfo.txrate.flags & RATE_INFO_FLAGS_MCS))
1243 rate->value = 100000 * sinfo.txrate.legacy;
1244
1245 return 0;
1246}
1247EXPORT_SYMBOL_GPL(cfg80211_wext_giwrate);
Johannes Berg89906462009-07-01 21:27:00 +02001248
1249/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
1250struct iw_statistics *cfg80211_wireless_stats(struct net_device *dev)
1251{
1252 struct wireless_dev *wdev = dev->ieee80211_ptr;
1253 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1254 /* we are under RTNL - globally locked - so can use static structs */
1255 static struct iw_statistics wstats;
1256 static struct station_info sinfo;
Johannes Bergc56c5712009-07-10 16:54:07 +02001257 u8 bssid[ETH_ALEN];
Johannes Berg89906462009-07-01 21:27:00 +02001258
1259 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION)
1260 return NULL;
1261
1262 if (!rdev->ops->get_station)
1263 return NULL;
1264
Johannes Bergc56c5712009-07-10 16:54:07 +02001265 /* Grab BSSID of current BSS, if any */
1266 wdev_lock(wdev);
1267 if (!wdev->current_bss) {
1268 wdev_unlock(wdev);
Johannes Berg89906462009-07-01 21:27:00 +02001269 return NULL;
Johannes Bergc56c5712009-07-10 16:54:07 +02001270 }
1271 memcpy(bssid, wdev->current_bss->pub.bssid, ETH_ALEN);
1272 wdev_unlock(wdev);
Johannes Berg89906462009-07-01 21:27:00 +02001273
Johannes Bergc56c5712009-07-10 16:54:07 +02001274 if (rdev->ops->get_station(&rdev->wiphy, dev, bssid, &sinfo))
Johannes Berg89906462009-07-01 21:27:00 +02001275 return NULL;
1276
1277 memset(&wstats, 0, sizeof(wstats));
1278
1279 switch (rdev->wiphy.signal_type) {
1280 case CFG80211_SIGNAL_TYPE_MBM:
1281 if (sinfo.filled & STATION_INFO_SIGNAL) {
1282 int sig = sinfo.signal;
1283 wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
1284 wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
1285 wstats.qual.updated |= IW_QUAL_DBM;
1286 wstats.qual.level = sig;
1287 if (sig < -110)
1288 sig = -110;
1289 else if (sig > -40)
1290 sig = -40;
1291 wstats.qual.qual = sig + 110;
1292 break;
1293 }
1294 case CFG80211_SIGNAL_TYPE_UNSPEC:
1295 if (sinfo.filled & STATION_INFO_SIGNAL) {
1296 wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
1297 wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
1298 wstats.qual.level = sinfo.signal;
1299 wstats.qual.qual = sinfo.signal;
1300 break;
1301 }
1302 default:
1303 wstats.qual.updated |= IW_QUAL_LEVEL_INVALID;
1304 wstats.qual.updated |= IW_QUAL_QUAL_INVALID;
1305 }
1306
1307 wstats.qual.updated |= IW_QUAL_NOISE_INVALID;
1308
1309 return &wstats;
1310}
1311EXPORT_SYMBOL_GPL(cfg80211_wireless_stats);
Johannes Berg562e4822009-07-27 12:01:51 +02001312
1313int cfg80211_wext_siwap(struct net_device *dev,
1314 struct iw_request_info *info,
1315 struct sockaddr *ap_addr, char *extra)
1316{
1317 struct wireless_dev *wdev = dev->ieee80211_ptr;
1318
1319 switch (wdev->iftype) {
1320 case NL80211_IFTYPE_ADHOC:
1321 return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra);
1322 case NL80211_IFTYPE_STATION:
1323 return cfg80211_mgd_wext_siwap(dev, info, ap_addr, extra);
1324 case NL80211_IFTYPE_WDS:
1325 return cfg80211_wds_wext_siwap(dev, info, ap_addr, extra);
1326 default:
1327 return -EOPNOTSUPP;
1328 }
1329}
1330EXPORT_SYMBOL_GPL(cfg80211_wext_siwap);
1331
1332int cfg80211_wext_giwap(struct net_device *dev,
1333 struct iw_request_info *info,
1334 struct sockaddr *ap_addr, char *extra)
1335{
1336 struct wireless_dev *wdev = dev->ieee80211_ptr;
1337
1338 switch (wdev->iftype) {
1339 case NL80211_IFTYPE_ADHOC:
1340 return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra);
1341 case NL80211_IFTYPE_STATION:
1342 return cfg80211_mgd_wext_giwap(dev, info, ap_addr, extra);
1343 case NL80211_IFTYPE_WDS:
1344 return cfg80211_wds_wext_giwap(dev, info, ap_addr, extra);
1345 default:
1346 return -EOPNOTSUPP;
1347 }
1348}
1349EXPORT_SYMBOL_GPL(cfg80211_wext_giwap);
Johannes Berg1f9298f2009-07-27 12:01:52 +02001350
1351int cfg80211_wext_siwessid(struct net_device *dev,
1352 struct iw_request_info *info,
1353 struct iw_point *data, char *ssid)
1354{
1355 struct wireless_dev *wdev = dev->ieee80211_ptr;
1356
1357 switch (wdev->iftype) {
1358 case NL80211_IFTYPE_ADHOC:
1359 return cfg80211_ibss_wext_siwessid(dev, info, data, ssid);
1360 case NL80211_IFTYPE_STATION:
1361 return cfg80211_mgd_wext_siwessid(dev, info, data, ssid);
1362 default:
1363 return -EOPNOTSUPP;
1364 }
1365}
1366EXPORT_SYMBOL_GPL(cfg80211_wext_siwessid);
1367
1368int cfg80211_wext_giwessid(struct net_device *dev,
1369 struct iw_request_info *info,
1370 struct iw_point *data, char *ssid)
1371{
1372 struct wireless_dev *wdev = dev->ieee80211_ptr;
1373
1374 switch (wdev->iftype) {
1375 case NL80211_IFTYPE_ADHOC:
1376 return cfg80211_ibss_wext_giwessid(dev, info, data, ssid);
1377 case NL80211_IFTYPE_STATION:
1378 return cfg80211_mgd_wext_giwessid(dev, info, data, ssid);
1379 default:
1380 return -EOPNOTSUPP;
1381 }
1382}
1383EXPORT_SYMBOL_GPL(cfg80211_wext_giwessid);
Johannes Berga9a11622009-07-27 12:01:53 +02001384
1385static const iw_handler cfg80211_handlers[] = {
1386 [IW_IOCTL_IDX(SIOCGIWNAME)] = (iw_handler) cfg80211_wext_giwname,
1387 [IW_IOCTL_IDX(SIOCSIWFREQ)] = (iw_handler) cfg80211_wext_siwfreq,
1388 [IW_IOCTL_IDX(SIOCGIWFREQ)] = (iw_handler) cfg80211_wext_giwfreq,
1389 [IW_IOCTL_IDX(SIOCSIWMODE)] = (iw_handler) cfg80211_wext_siwmode,
1390 [IW_IOCTL_IDX(SIOCGIWMODE)] = (iw_handler) cfg80211_wext_giwmode,
1391 [IW_IOCTL_IDX(SIOCGIWRANGE)] = (iw_handler) cfg80211_wext_giwrange,
1392 [IW_IOCTL_IDX(SIOCSIWAP)] = (iw_handler) cfg80211_wext_siwap,
1393 [IW_IOCTL_IDX(SIOCGIWAP)] = (iw_handler) cfg80211_wext_giwap,
1394 [IW_IOCTL_IDX(SIOCSIWMLME)] = (iw_handler) cfg80211_wext_siwmlme,
1395 [IW_IOCTL_IDX(SIOCSIWSCAN)] = (iw_handler) cfg80211_wext_siwscan,
1396 [IW_IOCTL_IDX(SIOCGIWSCAN)] = (iw_handler) cfg80211_wext_giwscan,
1397 [IW_IOCTL_IDX(SIOCSIWESSID)] = (iw_handler) cfg80211_wext_siwessid,
1398 [IW_IOCTL_IDX(SIOCGIWESSID)] = (iw_handler) cfg80211_wext_giwessid,
1399 [IW_IOCTL_IDX(SIOCSIWRATE)] = (iw_handler) cfg80211_wext_siwrate,
1400 [IW_IOCTL_IDX(SIOCGIWRATE)] = (iw_handler) cfg80211_wext_giwrate,
1401 [IW_IOCTL_IDX(SIOCSIWRTS)] = (iw_handler) cfg80211_wext_siwrts,
1402 [IW_IOCTL_IDX(SIOCGIWRTS)] = (iw_handler) cfg80211_wext_giwrts,
1403 [IW_IOCTL_IDX(SIOCSIWFRAG)] = (iw_handler) cfg80211_wext_siwfrag,
1404 [IW_IOCTL_IDX(SIOCGIWFRAG)] = (iw_handler) cfg80211_wext_giwfrag,
1405 [IW_IOCTL_IDX(SIOCSIWTXPOW)] = (iw_handler) cfg80211_wext_siwtxpower,
1406 [IW_IOCTL_IDX(SIOCGIWTXPOW)] = (iw_handler) cfg80211_wext_giwtxpower,
1407 [IW_IOCTL_IDX(SIOCSIWRETRY)] = (iw_handler) cfg80211_wext_siwretry,
1408 [IW_IOCTL_IDX(SIOCGIWRETRY)] = (iw_handler) cfg80211_wext_giwretry,
1409 [IW_IOCTL_IDX(SIOCSIWENCODE)] = (iw_handler) cfg80211_wext_siwencode,
1410 [IW_IOCTL_IDX(SIOCGIWENCODE)] = (iw_handler) cfg80211_wext_giwencode,
1411 [IW_IOCTL_IDX(SIOCSIWPOWER)] = (iw_handler) cfg80211_wext_siwpower,
1412 [IW_IOCTL_IDX(SIOCGIWPOWER)] = (iw_handler) cfg80211_wext_giwpower,
1413 [IW_IOCTL_IDX(SIOCSIWGENIE)] = (iw_handler) cfg80211_wext_siwgenie,
1414 [IW_IOCTL_IDX(SIOCSIWAUTH)] = (iw_handler) cfg80211_wext_siwauth,
1415 [IW_IOCTL_IDX(SIOCGIWAUTH)] = (iw_handler) cfg80211_wext_giwauth,
1416 [IW_IOCTL_IDX(SIOCSIWENCODEEXT)]= (iw_handler) cfg80211_wext_siwencodeext,
1417};
1418
1419const struct iw_handler_def cfg80211_wext_handler = {
1420 .num_standard = ARRAY_SIZE(cfg80211_handlers),
1421 .standard = cfg80211_handlers,
1422 .get_wireless_stats = cfg80211_wireless_stats,
1423};