blob: 98bb409076d15a1909084f177806ac05f47c3264 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/*
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 *
8 * Copyright 2008-2009 Johannes Berg <johannes@sipsolutions.net>
9 */
10
11#include <linux/export.h>
12#include <linux/wireless.h>
13#include <linux/nl80211.h>
14#include <linux/if_arp.h>
15#include <linux/etherdevice.h>
16#include <linux/slab.h>
17#include <net/iw_handler.h>
18#include <net/cfg80211.h>
19#include <net/cfg80211-wext.h>
20#include "wext-compat.h"
21#include "core.h"
22
23int cfg80211_wext_giwname(struct net_device *dev,
24 struct iw_request_info *info,
25 char *name, char *extra)
26{
27 struct wireless_dev *wdev = dev->ieee80211_ptr;
28 struct ieee80211_supported_band *sband;
29 bool is_ht = false, is_a = false, is_b = false, is_g = false;
30
31 if (!wdev)
32 return -EOPNOTSUPP;
33
34 sband = wdev->wiphy->bands[IEEE80211_BAND_5GHZ];
35 if (sband) {
36 is_a = true;
37 is_ht |= sband->ht_cap.ht_supported;
38 }
39
40 sband = wdev->wiphy->bands[IEEE80211_BAND_2GHZ];
41 if (sband) {
42 int i;
43 /* Check for mandatory rates */
44 for (i = 0; i < sband->n_bitrates; i++) {
45 if (sband->bitrates[i].bitrate == 10)
46 is_b = true;
47 if (sband->bitrates[i].bitrate == 60)
48 is_g = true;
49 }
50 is_ht |= sband->ht_cap.ht_supported;
51 }
52
53 strcpy(name, "IEEE 802.11");
54 if (is_a)
55 strcat(name, "a");
56 if (is_b)
57 strcat(name, "b");
58 if (is_g)
59 strcat(name, "g");
60 if (is_ht)
61 strcat(name, "n");
62
63 return 0;
64}
65EXPORT_SYMBOL_GPL(cfg80211_wext_giwname);
66
67int cfg80211_wext_siwmode(struct net_device *dev, struct iw_request_info *info,
68 u32 *mode, char *extra)
69{
70 struct wireless_dev *wdev = dev->ieee80211_ptr;
71 struct cfg80211_registered_device *rdev;
72 struct vif_params vifparams;
73 enum nl80211_iftype type;
74 int ret;
75
76 rdev = wiphy_to_dev(wdev->wiphy);
77
78 switch (*mode) {
79 //add by zhouti
80 case IW_MODE_MASTER:
81 type = NL80211_IFTYPE_AP;
82 break;
83 //end
84 case IW_MODE_INFRA:
85 type = NL80211_IFTYPE_STATION;
86 break;
87 case IW_MODE_ADHOC:
88 type = NL80211_IFTYPE_ADHOC;
89 break;
90 case IW_MODE_REPEAT:
91 type = NL80211_IFTYPE_WDS;
92 break;
93 case IW_MODE_MONITOR:
94 type = NL80211_IFTYPE_MONITOR;
95 break;
96 default:
97 return -EINVAL;
98 }
99
100 if (type == wdev->iftype)
101 return 0;
102
103 memset(&vifparams, 0, sizeof(vifparams));
104
105 cfg80211_lock_rdev(rdev);
106 ret = cfg80211_change_iface(rdev, dev, type, NULL, &vifparams);
107 cfg80211_unlock_rdev(rdev);
108
109 return ret;
110}
111EXPORT_SYMBOL_GPL(cfg80211_wext_siwmode);
112
113int cfg80211_wext_giwmode(struct net_device *dev, struct iw_request_info *info,
114 u32 *mode, char *extra)
115{
116 struct wireless_dev *wdev = dev->ieee80211_ptr;
117
118 if (!wdev)
119 return -EOPNOTSUPP;
120
121 switch (wdev->iftype) {
122 case NL80211_IFTYPE_AP:
123 *mode = IW_MODE_MASTER;
124 break;
125 case NL80211_IFTYPE_STATION:
126 *mode = IW_MODE_INFRA;
127 break;
128 case NL80211_IFTYPE_ADHOC:
129 *mode = IW_MODE_ADHOC;
130 break;
131 case NL80211_IFTYPE_MONITOR:
132 *mode = IW_MODE_MONITOR;
133 break;
134 case NL80211_IFTYPE_WDS:
135 *mode = IW_MODE_REPEAT;
136 break;
137 case NL80211_IFTYPE_AP_VLAN:
138 *mode = IW_MODE_SECOND; /* FIXME */
139 break;
140 default:
141 *mode = IW_MODE_AUTO;
142 break;
143 }
144 return 0;
145}
146EXPORT_SYMBOL_GPL(cfg80211_wext_giwmode);
147
148
149int cfg80211_wext_giwrange(struct net_device *dev,
150 struct iw_request_info *info,
151 struct iw_point *data, char *extra)
152{
153 struct wireless_dev *wdev = dev->ieee80211_ptr;
154 struct iw_range *range = (struct iw_range *) extra;
155 enum ieee80211_band band;
156 int i, c = 0;
157
158 if (!wdev)
159 return -EOPNOTSUPP;
160
161 data->length = sizeof(struct iw_range);
162 memset(range, 0, sizeof(struct iw_range));
163
164 range->we_version_compiled = WIRELESS_EXT;
165 range->we_version_source = 21;
166 range->retry_capa = IW_RETRY_LIMIT;
167 range->retry_flags = IW_RETRY_LIMIT;
168 range->min_retry = 0;
169 range->max_retry = 255;
170 range->min_rts = 0;
171 range->max_rts = 2347;
172 range->min_frag = 256;
173 range->max_frag = 2346;
174
175 range->max_encoding_tokens = 4;
176
177 range->max_qual.updated = IW_QUAL_NOISE_INVALID;
178
179 switch (wdev->wiphy->signal_type) {
180 case CFG80211_SIGNAL_TYPE_NONE:
181 break;
182 case CFG80211_SIGNAL_TYPE_MBM:
183 range->max_qual.level = -110;
184 range->max_qual.qual = 70;
185 range->avg_qual.qual = 35;
186 range->max_qual.updated |= IW_QUAL_DBM;
187 range->max_qual.updated |= IW_QUAL_QUAL_UPDATED;
188 range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED;
189 break;
190 case CFG80211_SIGNAL_TYPE_UNSPEC:
191 range->max_qual.level = 100;
192 range->max_qual.qual = 100;
193 range->avg_qual.qual = 50;
194 range->max_qual.updated |= IW_QUAL_QUAL_UPDATED;
195 range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED;
196 break;
197 }
198
199 range->avg_qual.level = range->max_qual.level / 2;
200 range->avg_qual.noise = range->max_qual.noise / 2;
201 range->avg_qual.updated = range->max_qual.updated;
202
203 for (i = 0; i < wdev->wiphy->n_cipher_suites; i++) {
204 switch (wdev->wiphy->cipher_suites[i]) {
205 case WLAN_CIPHER_SUITE_TKIP:
206 range->enc_capa |= (IW_ENC_CAPA_CIPHER_TKIP |
207 IW_ENC_CAPA_WPA);
208 break;
209
210 case WLAN_CIPHER_SUITE_CCMP:
211 range->enc_capa |= (IW_ENC_CAPA_CIPHER_CCMP |
212 IW_ENC_CAPA_WPA2);
213 break;
214
215 case WLAN_CIPHER_SUITE_WEP40:
216 range->encoding_size[range->num_encoding_sizes++] =
217 WLAN_KEY_LEN_WEP40;
218 break;
219
220 case WLAN_CIPHER_SUITE_WEP104:
221 range->encoding_size[range->num_encoding_sizes++] =
222 WLAN_KEY_LEN_WEP104;
223 break;
224 }
225 }
226
227 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
228 struct ieee80211_supported_band *sband;
229
230 sband = wdev->wiphy->bands[band];
231
232 if (!sband)
233 continue;
234
235 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
236 struct ieee80211_channel *chan = &sband->channels[i];
237
238 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
239 range->freq[c].i =
240 ieee80211_frequency_to_channel(
241 chan->center_freq);
242 range->freq[c].m = chan->center_freq;
243 range->freq[c].e = 6;
244 c++;
245 }
246 }
247 }
248 range->num_channels = c;
249 range->num_frequency = c;
250
251 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
252 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
253 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
254
255 if (wdev->wiphy->max_scan_ssids > 0)
256 range->scan_capa |= IW_SCAN_CAPA_ESSID;
257
258 return 0;
259}
260EXPORT_SYMBOL_GPL(cfg80211_wext_giwrange);
261
262
263/**
264 * cfg80211_wext_freq - get wext frequency for non-"auto"
265 * @wiphy: the wiphy
266 * @freq: the wext freq encoding
267 *
268 * Returns a frequency, or a negative error code, or 0 for auto.
269 */
270int cfg80211_wext_freq(struct wiphy *wiphy, struct iw_freq *freq)
271{
272 /*
273 * Parse frequency - return 0 for auto and
274 * -EINVAL for impossible things.
275 */
276 if (freq->e == 0) {
277 enum ieee80211_band band = IEEE80211_BAND_2GHZ;
278 if (freq->m < 0)
279 return 0;
280 if (freq->m > 14)
281 band = IEEE80211_BAND_5GHZ;
282 return ieee80211_channel_to_frequency(freq->m, band);
283 } else {
284 int i, div = 1000000;
285 for (i = 0; i < freq->e; i++)
286 div /= 10;
287 if (div <= 0)
288 return -EINVAL;
289 return freq->m / div;
290 }
291}
292
293int cfg80211_wext_siwrts(struct net_device *dev,
294 struct iw_request_info *info,
295 struct iw_param *rts, char *extra)
296{
297 struct wireless_dev *wdev = dev->ieee80211_ptr;
298 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
299 u32 orts = wdev->wiphy->rts_threshold;
300 int err;
301
302 if (rts->disabled || !rts->fixed)
303 wdev->wiphy->rts_threshold = (u32) -1;
304 else if (rts->value < 0)
305 return -EINVAL;
306 else
307 wdev->wiphy->rts_threshold = rts->value;
308
309 err = rdev->ops->set_wiphy_params(wdev->wiphy,
310 WIPHY_PARAM_RTS_THRESHOLD);
311 if (err)
312 wdev->wiphy->rts_threshold = orts;
313
314 return err;
315}
316EXPORT_SYMBOL_GPL(cfg80211_wext_siwrts);
317
318int cfg80211_wext_giwrts(struct net_device *dev,
319 struct iw_request_info *info,
320 struct iw_param *rts, char *extra)
321{
322 struct wireless_dev *wdev = dev->ieee80211_ptr;
323
324 rts->value = wdev->wiphy->rts_threshold;
325 rts->disabled = rts->value == (u32) -1;
326 rts->fixed = 1;
327
328 return 0;
329}
330EXPORT_SYMBOL_GPL(cfg80211_wext_giwrts);
331
332int cfg80211_wext_siwfrag(struct net_device *dev,
333 struct iw_request_info *info,
334 struct iw_param *frag, char *extra)
335{
336 struct wireless_dev *wdev = dev->ieee80211_ptr;
337 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
338 u32 ofrag = wdev->wiphy->frag_threshold;
339 int err;
340
341 if (frag->disabled || !frag->fixed)
342 wdev->wiphy->frag_threshold = (u32) -1;
343 else if (frag->value < 256)
344 return -EINVAL;
345 else {
346 /* Fragment length must be even, so strip LSB. */
347 wdev->wiphy->frag_threshold = frag->value & ~0x1;
348 }
349
350 err = rdev->ops->set_wiphy_params(wdev->wiphy,
351 WIPHY_PARAM_FRAG_THRESHOLD);
352 if (err)
353 wdev->wiphy->frag_threshold = ofrag;
354
355 return err;
356}
357EXPORT_SYMBOL_GPL(cfg80211_wext_siwfrag);
358
359int cfg80211_wext_giwfrag(struct net_device *dev,
360 struct iw_request_info *info,
361 struct iw_param *frag, char *extra)
362{
363 struct wireless_dev *wdev = dev->ieee80211_ptr;
364
365 frag->value = wdev->wiphy->frag_threshold;
366 frag->disabled = frag->value == (u32) -1;
367 frag->fixed = 1;
368
369 return 0;
370}
371EXPORT_SYMBOL_GPL(cfg80211_wext_giwfrag);
372
373static int cfg80211_wext_siwretry(struct net_device *dev,
374 struct iw_request_info *info,
375 struct iw_param *retry, char *extra)
376{
377 struct wireless_dev *wdev = dev->ieee80211_ptr;
378 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
379 u32 changed = 0;
380 u8 olong = wdev->wiphy->retry_long;
381 u8 oshort = wdev->wiphy->retry_short;
382 int err;
383
384 if (retry->disabled ||
385 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
386 return -EINVAL;
387
388 if (retry->flags & IW_RETRY_LONG) {
389 wdev->wiphy->retry_long = retry->value;
390 changed |= WIPHY_PARAM_RETRY_LONG;
391 } else if (retry->flags & IW_RETRY_SHORT) {
392 wdev->wiphy->retry_short = retry->value;
393 changed |= WIPHY_PARAM_RETRY_SHORT;
394 } else {
395 wdev->wiphy->retry_short = retry->value;
396 wdev->wiphy->retry_long = retry->value;
397 changed |= WIPHY_PARAM_RETRY_LONG;
398 changed |= WIPHY_PARAM_RETRY_SHORT;
399 }
400
401 if (!changed)
402 return 0;
403
404 err = rdev->ops->set_wiphy_params(wdev->wiphy, changed);
405 if (err) {
406 wdev->wiphy->retry_short = oshort;
407 wdev->wiphy->retry_long = olong;
408 }
409
410 return err;
411}
412
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}
441EXPORT_SYMBOL_GPL(cfg80211_wext_giwretry);
442
443static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
444 struct net_device *dev, bool pairwise,
445 const u8 *addr, bool remove, bool tx_key,
446 int idx, struct key_params *params)
447{
448 struct wireless_dev *wdev = dev->ieee80211_ptr;
449 int err, i;
450 bool rejoin = false;
451
452 if (pairwise && !addr)
453 return -EINVAL;
454
455 if (!wdev->wext.keys) {
456 wdev->wext.keys = kzalloc(sizeof(*wdev->wext.keys),
457 GFP_KERNEL);
458 if (!wdev->wext.keys)
459 return -ENOMEM;
460 for (i = 0; i < 6; i++)
461 wdev->wext.keys->params[i].key =
462 wdev->wext.keys->data[i];
463 }
464
465 if (wdev->iftype != NL80211_IFTYPE_ADHOC &&
466 wdev->iftype != NL80211_IFTYPE_STATION)
467 return -EOPNOTSUPP;
468
469 if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
470 if (!wdev->current_bss)
471 return -ENOLINK;
472
473 if (!rdev->ops->set_default_mgmt_key)
474 return -EOPNOTSUPP;
475
476 if (idx < 4 || idx > 5)
477 return -EINVAL;
478 } else if (idx < 0 || idx > 3)
479 return -EINVAL;
480
481 if (remove) {
482 err = 0;
483 if (wdev->current_bss) {
484 /*
485 * If removing the current TX key, we will need to
486 * join a new IBSS without the privacy bit clear.
487 */
488 if (idx == wdev->wext.default_key &&
489 wdev->iftype == NL80211_IFTYPE_ADHOC) {
490 __cfg80211_leave_ibss(rdev, wdev->netdev, true);
491 rejoin = true;
492 }
493
494 if (!pairwise && addr &&
495 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
496 err = -ENOENT;
497 else
498 err = rdev->ops->del_key(&rdev->wiphy, dev, idx,
499 pairwise, addr);
500 }
501 wdev->wext.connect.privacy = false;
502 /*
503 * Applications using wireless extensions expect to be
504 * able to delete keys that don't exist, so allow that.
505 */
506 if (err == -ENOENT)
507 err = 0;
508 if (!err) {
509 if (!addr) {
510 wdev->wext.keys->params[idx].key_len = 0;
511 wdev->wext.keys->params[idx].cipher = 0;
512 }
513 if (idx == wdev->wext.default_key)
514 wdev->wext.default_key = -1;
515 else if (idx == wdev->wext.default_mgmt_key)
516 wdev->wext.default_mgmt_key = -1;
517 }
518
519 if (!err && rejoin)
520 err = cfg80211_ibss_wext_join(rdev, wdev);
521
522 return err;
523 }
524
525 if (addr)
526 tx_key = false;
527
528 if (cfg80211_validate_key_settings(rdev, params, idx, pairwise, addr))
529 return -EINVAL;
530
531 err = 0;
532 if (wdev->current_bss)
533 err = rdev->ops->add_key(&rdev->wiphy, dev, idx,
534 pairwise, addr, params);
535 if (err)
536 return err;
537
538 if (!addr) {
539 wdev->wext.keys->params[idx] = *params;
540 memcpy(wdev->wext.keys->data[idx],
541 params->key, params->key_len);
542 wdev->wext.keys->params[idx].key =
543 wdev->wext.keys->data[idx];
544 }
545
546 if ((params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
547 params->cipher == WLAN_CIPHER_SUITE_WEP104) &&
548 (tx_key || (!addr && wdev->wext.default_key == -1))) {
549 if (wdev->current_bss) {
550 /*
551 * If we are getting a new TX key from not having
552 * had one before we need to join a new IBSS with
553 * the privacy bit set.
554 */
555 if (wdev->iftype == NL80211_IFTYPE_ADHOC &&
556 wdev->wext.default_key == -1) {
557 __cfg80211_leave_ibss(rdev, wdev->netdev, true);
558 rejoin = true;
559 }
560 err = rdev->ops->set_default_key(&rdev->wiphy, dev,
561 idx, true, true);
562 }
563 if (!err) {
564 wdev->wext.default_key = idx;
565 if (rejoin)
566 err = cfg80211_ibss_wext_join(rdev, wdev);
567 }
568 return err;
569 }
570
571 if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC &&
572 (tx_key || (!addr && wdev->wext.default_mgmt_key == -1))) {
573 if (wdev->current_bss)
574 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
575 dev, idx);
576 if (!err)
577 wdev->wext.default_mgmt_key = idx;
578 return err;
579 }
580
581 return 0;
582}
583
584static int cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
585 struct net_device *dev, bool pairwise,
586 const u8 *addr, bool remove, bool tx_key,
587 int idx, struct key_params *params)
588{
589 int err;
590
591 /* devlist mutex needed for possible IBSS re-join */
592 mutex_lock(&rdev->devlist_mtx);
593 wdev_lock(dev->ieee80211_ptr);
594 err = __cfg80211_set_encryption(rdev, dev, pairwise, addr,
595 remove, tx_key, idx, params);
596 wdev_unlock(dev->ieee80211_ptr);
597 mutex_unlock(&rdev->devlist_mtx);
598
599 return err;
600}
601
602static int cfg80211_wext_siwencode(struct net_device *dev,
603 struct iw_request_info *info,
604 struct iw_point *erq, char *keybuf)
605{
606 struct wireless_dev *wdev = dev->ieee80211_ptr;
607 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
608 int idx, err;
609 bool remove = false;
610 struct key_params params;
611
612 if (wdev->iftype != NL80211_IFTYPE_STATION &&
613 wdev->iftype != NL80211_IFTYPE_ADHOC)
614 return -EOPNOTSUPP;
615
616 /* no use -- only MFP (set_default_mgmt_key) is optional */
617 if (!rdev->ops->del_key ||
618 !rdev->ops->add_key ||
619 !rdev->ops->set_default_key)
620 return -EOPNOTSUPP;
621
622 idx = erq->flags & IW_ENCODE_INDEX;
623 if (idx == 0) {
624 idx = wdev->wext.default_key;
625 if (idx < 0)
626 idx = 0;
627 } else if (idx < 1 || idx > 4)
628 return -EINVAL;
629 else
630 idx--;
631
632 if (erq->flags & IW_ENCODE_DISABLED)
633 remove = true;
634 else if (erq->length == 0) {
635 /* No key data - just set the default TX key index */
636 err = 0;
637 wdev_lock(wdev);
638 if (wdev->current_bss)
639 err = rdev->ops->set_default_key(&rdev->wiphy, dev,
640 idx, true, true);
641 if (!err)
642 wdev->wext.default_key = idx;
643 wdev_unlock(wdev);
644 return err;
645 }
646
647 memset(&params, 0, sizeof(params));
648 params.key = keybuf;
649 params.key_len = erq->length;
650 if (erq->length == 5)
651 params.cipher = WLAN_CIPHER_SUITE_WEP40;
652 else if (erq->length == 13)
653 params.cipher = WLAN_CIPHER_SUITE_WEP104;
654 else if (!remove)
655 return -EINVAL;
656
657 return cfg80211_set_encryption(rdev, dev, false, NULL, remove,
658 wdev->wext.default_key == -1,
659 idx, &params);
660}
661
662static int cfg80211_wext_siwencodeext(struct net_device *dev,
663 struct iw_request_info *info,
664 struct iw_point *erq, char *extra)
665{
666 struct wireless_dev *wdev = dev->ieee80211_ptr;
667 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
668 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
669 const u8 *addr;
670 int idx;
671 bool remove = false;
672 struct key_params params;
673 u32 cipher;
674
675 if (wdev->iftype != NL80211_IFTYPE_STATION &&
676 wdev->iftype != NL80211_IFTYPE_ADHOC)
677 return -EOPNOTSUPP;
678
679 /* no use -- only MFP (set_default_mgmt_key) is optional */
680 if (!rdev->ops->del_key ||
681 !rdev->ops->add_key ||
682 !rdev->ops->set_default_key)
683 return -EOPNOTSUPP;
684
685 switch (ext->alg) {
686 case IW_ENCODE_ALG_NONE:
687 remove = true;
688 cipher = 0;
689 break;
690 case IW_ENCODE_ALG_WEP:
691 if (ext->key_len == 5)
692 cipher = WLAN_CIPHER_SUITE_WEP40;
693 else if (ext->key_len == 13)
694 cipher = WLAN_CIPHER_SUITE_WEP104;
695 else
696 return -EINVAL;
697 break;
698 case IW_ENCODE_ALG_TKIP:
699 cipher = WLAN_CIPHER_SUITE_TKIP;
700 break;
701 case IW_ENCODE_ALG_CCMP:
702 cipher = WLAN_CIPHER_SUITE_CCMP;
703 break;
704 case IW_ENCODE_ALG_AES_CMAC:
705 cipher = WLAN_CIPHER_SUITE_AES_CMAC;
706 break;
707 default:
708 return -EOPNOTSUPP;
709 }
710
711 if (erq->flags & IW_ENCODE_DISABLED)
712 remove = true;
713
714 idx = erq->flags & IW_ENCODE_INDEX;
715 if (cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
716 if (idx < 4 || idx > 5) {
717 idx = wdev->wext.default_mgmt_key;
718 if (idx < 0)
719 return -EINVAL;
720 } else
721 idx--;
722 } else {
723 if (idx < 1 || idx > 4) {
724 idx = wdev->wext.default_key;
725 if (idx < 0)
726 return -EINVAL;
727 } else
728 idx--;
729 }
730
731 addr = ext->addr.sa_data;
732 if (is_broadcast_ether_addr(addr))
733 addr = NULL;
734
735 memset(&params, 0, sizeof(params));
736 params.key = ext->key;
737 params.key_len = ext->key_len;
738 params.cipher = cipher;
739
740 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
741 params.seq = ext->rx_seq;
742 params.seq_len = 6;
743 }
744
745 return cfg80211_set_encryption(
746 rdev, dev,
747 !(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY),
748 addr, remove,
749 ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
750 idx, &params);
751}
752
753static int cfg80211_wext_giwencode(struct net_device *dev,
754 struct iw_request_info *info,
755 struct iw_point *erq, char *keybuf)
756{
757 struct wireless_dev *wdev = dev->ieee80211_ptr;
758 int idx;
759
760 if (wdev->iftype != NL80211_IFTYPE_STATION &&
761 wdev->iftype != NL80211_IFTYPE_ADHOC)
762 return -EOPNOTSUPP;
763
764 idx = erq->flags & IW_ENCODE_INDEX;
765 if (idx == 0) {
766 idx = wdev->wext.default_key;
767 if (idx < 0)
768 idx = 0;
769 } else if (idx < 1 || idx > 4)
770 return -EINVAL;
771 else
772 idx--;
773
774 erq->flags = idx + 1;
775
776 if (!wdev->wext.keys || !wdev->wext.keys->params[idx].cipher) {
777 erq->flags |= IW_ENCODE_DISABLED;
778 erq->length = 0;
779 return 0;
780 }
781
782 erq->length = min_t(size_t, erq->length,
783 wdev->wext.keys->params[idx].key_len);
784 memcpy(keybuf, wdev->wext.keys->params[idx].key, erq->length);
785 erq->flags |= IW_ENCODE_ENABLED;
786
787 return 0;
788}
789
790static int cfg80211_wext_siwfreq(struct net_device *dev,
791 struct iw_request_info *info,
792 struct iw_freq *wextfreq, char *extra)
793{
794 struct wireless_dev *wdev = dev->ieee80211_ptr;
795 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
796 int freq, err;
797
798 switch (wdev->iftype) {
799 case NL80211_IFTYPE_STATION:
800 return cfg80211_mgd_wext_siwfreq(dev, info, wextfreq, extra);
801 case NL80211_IFTYPE_ADHOC:
802 return cfg80211_ibss_wext_siwfreq(dev, info, wextfreq, extra);
803 case NL80211_IFTYPE_MONITOR:
804 case NL80211_IFTYPE_WDS:
805 case NL80211_IFTYPE_MESH_POINT:
806 freq = cfg80211_wext_freq(wdev->wiphy, wextfreq);
807 if (freq < 0)
808 return freq;
809 if (freq == 0)
810 return -EINVAL;
811 mutex_lock(&rdev->devlist_mtx);
812 wdev_lock(wdev);
813 err = cfg80211_set_freq(rdev, wdev, freq, NL80211_CHAN_NO_HT);
814 wdev_unlock(wdev);
815 mutex_unlock(&rdev->devlist_mtx);
816 return err;
817 default:
818 return -EOPNOTSUPP;
819 }
820}
821
822static int cfg80211_wext_giwfreq(struct net_device *dev,
823 struct iw_request_info *info,
824 struct iw_freq *freq, char *extra)
825{
826 struct wireless_dev *wdev = dev->ieee80211_ptr;
827 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
828 struct ieee80211_channel *chan;
829
830 switch (wdev->iftype) {
831 case NL80211_IFTYPE_STATION:
832 return cfg80211_mgd_wext_giwfreq(dev, info, freq, extra);
833 case NL80211_IFTYPE_ADHOC:
834 return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra);
835 case NL80211_IFTYPE_MONITOR:
836 if (!rdev->ops->get_channel)
837 return -EINVAL;
838
839 chan = rdev->ops->get_channel(wdev->wiphy);
840 if (!chan)
841 return -EINVAL;
842 freq->m = chan->center_freq;
843 freq->e = 6;
844 return 0;
845 default:
846 if (!wdev->channel)
847 return -EINVAL;
848 freq->m = wdev->channel->center_freq;
849 freq->e = 6;
850 return 0;
851 }
852}
853
854static int cfg80211_wext_siwtxpower(struct net_device *dev,
855 struct iw_request_info *info,
856 union iwreq_data *data, char *extra)
857{
858 struct wireless_dev *wdev = dev->ieee80211_ptr;
859 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
860 enum nl80211_tx_power_setting type;
861 int dbm = 0;
862
863 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
864 return -EINVAL;
865 if (data->txpower.flags & IW_TXPOW_RANGE)
866 return -EINVAL;
867
868 if (!rdev->ops->set_tx_power)
869 return -EOPNOTSUPP;
870
871 /* only change when not disabling */
872 if (!data->txpower.disabled) {
873 rfkill_set_sw_state(rdev->rfkill, false);
874
875 if (data->txpower.fixed) {
876 /*
877 * wext doesn't support negative values, see
878 * below where it's for automatic
879 */
880 if (data->txpower.value < 0)
881 return -EINVAL;
882 dbm = data->txpower.value;
883 type = NL80211_TX_POWER_FIXED;
884 /* TODO: do regulatory check! */
885 } else {
886 /*
887 * Automatic power level setting, max being the value
888 * passed in from userland.
889 */
890 if (data->txpower.value < 0) {
891 type = NL80211_TX_POWER_AUTOMATIC;
892 } else {
893 dbm = data->txpower.value;
894 type = NL80211_TX_POWER_LIMITED;
895 }
896 }
897 } else {
898 rfkill_set_sw_state(rdev->rfkill, true);
899 schedule_work(&rdev->rfkill_sync);
900 return 0;
901 }
902
903 return rdev->ops->set_tx_power(wdev->wiphy, type, DBM_TO_MBM(dbm));
904}
905
906static int cfg80211_wext_giwtxpower(struct net_device *dev,
907 struct iw_request_info *info,
908 union iwreq_data *data, char *extra)
909{
910 struct wireless_dev *wdev = dev->ieee80211_ptr;
911 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
912 int err, val;
913
914 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
915 return -EINVAL;
916 if (data->txpower.flags & IW_TXPOW_RANGE)
917 return -EINVAL;
918
919 if (!rdev->ops->get_tx_power)
920 return -EOPNOTSUPP;
921
922 err = rdev->ops->get_tx_power(wdev->wiphy, &val);
923 if (err)
924 return err;
925
926 /* well... oh well */
927 data->txpower.fixed = 1;
928 data->txpower.disabled = rfkill_blocked(rdev->rfkill);
929 data->txpower.value = val;
930 data->txpower.flags = IW_TXPOW_DBM;
931
932 return 0;
933}
934
935static int cfg80211_set_auth_alg(struct wireless_dev *wdev,
936 s32 auth_alg)
937{
938 int nr_alg = 0;
939
940 if (!auth_alg)
941 return -EINVAL;
942
943 if (auth_alg & ~(IW_AUTH_ALG_OPEN_SYSTEM |
944 IW_AUTH_ALG_SHARED_KEY |
945 IW_AUTH_ALG_LEAP))
946 return -EINVAL;
947
948 if (auth_alg & IW_AUTH_ALG_OPEN_SYSTEM) {
949 nr_alg++;
950 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
951 }
952
953 if (auth_alg & IW_AUTH_ALG_SHARED_KEY) {
954 nr_alg++;
955 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_SHARED_KEY;
956 }
957
958 if (auth_alg & IW_AUTH_ALG_LEAP) {
959 nr_alg++;
960 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_NETWORK_EAP;
961 }
962
963 if (nr_alg > 1)
964 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
965
966 return 0;
967}
968
969static int cfg80211_set_wpa_version(struct wireless_dev *wdev, u32 wpa_versions)
970{
971 if (wpa_versions & ~(IW_AUTH_WPA_VERSION_WPA |
972 IW_AUTH_WPA_VERSION_WPA2|
973 IW_AUTH_WPA_VERSION_DISABLED))
974 return -EINVAL;
975
976 if ((wpa_versions & IW_AUTH_WPA_VERSION_DISABLED) &&
977 (wpa_versions & (IW_AUTH_WPA_VERSION_WPA|
978 IW_AUTH_WPA_VERSION_WPA2)))
979 return -EINVAL;
980
981 if (wpa_versions & IW_AUTH_WPA_VERSION_DISABLED)
982 wdev->wext.connect.crypto.wpa_versions &=
983 ~(NL80211_WPA_VERSION_1|NL80211_WPA_VERSION_2);
984
985 if (wpa_versions & IW_AUTH_WPA_VERSION_WPA)
986 wdev->wext.connect.crypto.wpa_versions |=
987 NL80211_WPA_VERSION_1;
988
989 if (wpa_versions & IW_AUTH_WPA_VERSION_WPA2)
990 wdev->wext.connect.crypto.wpa_versions |=
991 NL80211_WPA_VERSION_2;
992
993 return 0;
994}
995
996static int cfg80211_set_cipher_group(struct wireless_dev *wdev, u32 cipher)
997{
998 if (cipher & IW_AUTH_CIPHER_WEP40)
999 wdev->wext.connect.crypto.cipher_group =
1000 WLAN_CIPHER_SUITE_WEP40;
1001 else if (cipher & IW_AUTH_CIPHER_WEP104)
1002 wdev->wext.connect.crypto.cipher_group =
1003 WLAN_CIPHER_SUITE_WEP104;
1004 else if (cipher & IW_AUTH_CIPHER_TKIP)
1005 wdev->wext.connect.crypto.cipher_group =
1006 WLAN_CIPHER_SUITE_TKIP;
1007 else if (cipher & IW_AUTH_CIPHER_CCMP)
1008 wdev->wext.connect.crypto.cipher_group =
1009 WLAN_CIPHER_SUITE_CCMP;
1010 else if (cipher & IW_AUTH_CIPHER_AES_CMAC)
1011 wdev->wext.connect.crypto.cipher_group =
1012 WLAN_CIPHER_SUITE_AES_CMAC;
1013 else if (cipher & IW_AUTH_CIPHER_NONE)
1014 wdev->wext.connect.crypto.cipher_group = 0;
1015 else
1016 return -EINVAL;
1017
1018 return 0;
1019}
1020
1021static int cfg80211_set_cipher_pairwise(struct wireless_dev *wdev, u32 cipher)
1022{
1023 int nr_ciphers = 0;
1024 u32 *ciphers_pairwise = wdev->wext.connect.crypto.ciphers_pairwise;
1025
1026 if (cipher & IW_AUTH_CIPHER_WEP40) {
1027 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP40;
1028 nr_ciphers++;
1029 }
1030
1031 if (cipher & IW_AUTH_CIPHER_WEP104) {
1032 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP104;
1033 nr_ciphers++;
1034 }
1035
1036 if (cipher & IW_AUTH_CIPHER_TKIP) {
1037 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_TKIP;
1038 nr_ciphers++;
1039 }
1040
1041 if (cipher & IW_AUTH_CIPHER_CCMP) {
1042 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_CCMP;
1043 nr_ciphers++;
1044 }
1045
1046 if (cipher & IW_AUTH_CIPHER_AES_CMAC) {
1047 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_AES_CMAC;
1048 nr_ciphers++;
1049 }
1050
1051 BUILD_BUG_ON(NL80211_MAX_NR_CIPHER_SUITES < 5);
1052
1053 wdev->wext.connect.crypto.n_ciphers_pairwise = nr_ciphers;
1054
1055 return 0;
1056}
1057
1058
1059static int cfg80211_set_key_mgt(struct wireless_dev *wdev, u32 key_mgt)
1060{
1061 int nr_akm_suites = 0;
1062
1063 if (key_mgt & ~(IW_AUTH_KEY_MGMT_802_1X |
1064 IW_AUTH_KEY_MGMT_PSK))
1065 return -EINVAL;
1066
1067 if (key_mgt & IW_AUTH_KEY_MGMT_802_1X) {
1068 wdev->wext.connect.crypto.akm_suites[nr_akm_suites] =
1069 WLAN_AKM_SUITE_8021X;
1070 nr_akm_suites++;
1071 }
1072
1073 if (key_mgt & IW_AUTH_KEY_MGMT_PSK) {
1074 wdev->wext.connect.crypto.akm_suites[nr_akm_suites] =
1075 WLAN_AKM_SUITE_PSK;
1076 nr_akm_suites++;
1077 }
1078
1079 wdev->wext.connect.crypto.n_akm_suites = nr_akm_suites;
1080
1081 return 0;
1082}
1083
1084static int cfg80211_wext_siwauth(struct net_device *dev,
1085 struct iw_request_info *info,
1086 struct iw_param *data, char *extra)
1087{
1088 struct wireless_dev *wdev = dev->ieee80211_ptr;
1089
1090 if (wdev->iftype != NL80211_IFTYPE_STATION)
1091 return -EOPNOTSUPP;
1092
1093 switch (data->flags & IW_AUTH_INDEX) {
1094 case IW_AUTH_PRIVACY_INVOKED:
1095 wdev->wext.connect.privacy = data->value;
1096 return 0;
1097 case IW_AUTH_WPA_VERSION:
1098 return cfg80211_set_wpa_version(wdev, data->value);
1099 case IW_AUTH_CIPHER_GROUP:
1100 return cfg80211_set_cipher_group(wdev, data->value);
1101 case IW_AUTH_KEY_MGMT:
1102 return cfg80211_set_key_mgt(wdev, data->value);
1103 case IW_AUTH_CIPHER_PAIRWISE:
1104 return cfg80211_set_cipher_pairwise(wdev, data->value);
1105 case IW_AUTH_80211_AUTH_ALG:
1106 return cfg80211_set_auth_alg(wdev, data->value);
1107 case IW_AUTH_WPA_ENABLED:
1108 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1109 case IW_AUTH_DROP_UNENCRYPTED:
1110 case IW_AUTH_MFP:
1111 return 0;
1112 default:
1113 return -EOPNOTSUPP;
1114 }
1115}
1116
1117static int cfg80211_wext_giwauth(struct net_device *dev,
1118 struct iw_request_info *info,
1119 struct iw_param *data, char *extra)
1120{
1121 /* XXX: what do we need? */
1122
1123 return -EOPNOTSUPP;
1124}
1125
1126static int cfg80211_wext_siwpower(struct net_device *dev,
1127 struct iw_request_info *info,
1128 struct iw_param *wrq, char *extra)
1129{
1130 struct wireless_dev *wdev = dev->ieee80211_ptr;
1131 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1132 bool ps = wdev->ps;
1133 int timeout = wdev->ps_timeout;
1134 int err;
1135
1136 if (wdev->iftype != NL80211_IFTYPE_STATION)
1137 return -EINVAL;
1138
1139 if (!rdev->ops->set_power_mgmt)
1140 return -EOPNOTSUPP;
1141
1142 if (wrq->disabled) {
1143 ps = false;
1144 } else {
1145 switch (wrq->flags & IW_POWER_MODE) {
1146 case IW_POWER_ON: /* If not specified */
1147 case IW_POWER_MODE: /* If set all mask */
1148 case IW_POWER_ALL_R: /* If explicitely state all */
1149 ps = true;
1150 break;
1151 default: /* Otherwise we ignore */
1152 return -EINVAL;
1153 }
1154
1155 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
1156 return -EINVAL;
1157
1158 if (wrq->flags & IW_POWER_TIMEOUT)
1159 timeout = wrq->value / 1000;
1160 }
1161
1162 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, ps, timeout);
1163 if (err)
1164 return err;
1165
1166 wdev->ps = ps;
1167 wdev->ps_timeout = timeout;
1168
1169 return 0;
1170
1171}
1172
1173static int cfg80211_wext_giwpower(struct net_device *dev,
1174 struct iw_request_info *info,
1175 struct iw_param *wrq, char *extra)
1176{
1177 struct wireless_dev *wdev = dev->ieee80211_ptr;
1178
1179 wrq->disabled = !wdev->ps;
1180
1181 return 0;
1182}
1183
1184static int cfg80211_wds_wext_siwap(struct net_device *dev,
1185 struct iw_request_info *info,
1186 struct sockaddr *addr, char *extra)
1187{
1188 struct wireless_dev *wdev = dev->ieee80211_ptr;
1189 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1190 int err;
1191
1192 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS))
1193 return -EINVAL;
1194
1195 if (addr->sa_family != ARPHRD_ETHER)
1196 return -EINVAL;
1197
1198 if (netif_running(dev))
1199 return -EBUSY;
1200
1201 if (!rdev->ops->set_wds_peer)
1202 return -EOPNOTSUPP;
1203
1204 err = rdev->ops->set_wds_peer(wdev->wiphy, dev, (u8 *) &addr->sa_data);
1205 if (err)
1206 return err;
1207
1208 memcpy(&wdev->wext.bssid, (u8 *) &addr->sa_data, ETH_ALEN);
1209
1210 return 0;
1211}
1212
1213static int cfg80211_wds_wext_giwap(struct net_device *dev,
1214 struct iw_request_info *info,
1215 struct sockaddr *addr, char *extra)
1216{
1217 struct wireless_dev *wdev = dev->ieee80211_ptr;
1218
1219 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS))
1220 return -EINVAL;
1221
1222 addr->sa_family = ARPHRD_ETHER;
1223 memcpy(&addr->sa_data, wdev->wext.bssid, ETH_ALEN);
1224
1225 return 0;
1226}
1227
1228static int cfg80211_wext_siwrate(struct net_device *dev,
1229 struct iw_request_info *info,
1230 struct iw_param *rate, char *extra)
1231{
1232 struct wireless_dev *wdev = dev->ieee80211_ptr;
1233 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1234 struct cfg80211_bitrate_mask mask;
1235 u32 fixed, maxrate;
1236 struct ieee80211_supported_band *sband;
1237 int band, ridx;
1238 bool match = false;
1239
1240 if (!rdev->ops->set_bitrate_mask)
1241 return -EOPNOTSUPP;
1242
1243 memset(&mask, 0, sizeof(mask));
1244 fixed = 0;
1245 maxrate = (u32)-1;
1246
1247 if (rate->value < 0) {
1248 /* nothing */
1249 } else if (rate->fixed) {
1250 fixed = rate->value / 100000;
1251 } else {
1252 maxrate = rate->value / 100000;
1253 }
1254
1255 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1256 sband = wdev->wiphy->bands[band];
1257 if (sband == NULL)
1258 continue;
1259 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
1260 struct ieee80211_rate *srate = &sband->bitrates[ridx];
1261 if (fixed == srate->bitrate) {
1262 mask.control[band].legacy = 1 << ridx;
1263 match = true;
1264 break;
1265 }
1266 if (srate->bitrate <= maxrate) {
1267 mask.control[band].legacy |= 1 << ridx;
1268 match = true;
1269 }
1270 }
1271 }
1272
1273 if (!match)
1274 return -EINVAL;
1275
1276 return rdev->ops->set_bitrate_mask(wdev->wiphy, dev, NULL, &mask);
1277}
1278
1279static int cfg80211_wext_giwrate(struct net_device *dev,
1280 struct iw_request_info *info,
1281 struct iw_param *rate, char *extra)
1282{
1283 struct wireless_dev *wdev = dev->ieee80211_ptr;
1284 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1285 /* we are under RTNL - globally locked - so can use a static struct */
1286 static struct station_info sinfo;
1287 u8 addr[ETH_ALEN];
1288 int err;
1289
1290 if (wdev->iftype != NL80211_IFTYPE_STATION)
1291 return -EOPNOTSUPP;
1292
1293 if (!rdev->ops->get_station)
1294 return -EOPNOTSUPP;
1295
1296 err = 0;
1297 wdev_lock(wdev);
1298 if (wdev->current_bss)
1299 memcpy(addr, wdev->current_bss->pub.bssid, ETH_ALEN);
1300 else
1301 err = -EOPNOTSUPP;
1302 wdev_unlock(wdev);
1303 if (err)
1304 return err;
1305
1306 err = rdev->ops->get_station(&rdev->wiphy, dev, addr, &sinfo);
1307 if (err)
1308 return err;
1309
1310 if (!(sinfo.filled & STATION_INFO_TX_BITRATE))
1311 return -EOPNOTSUPP;
1312
1313 rate->value = 100000 * cfg80211_calculate_bitrate(&sinfo.txrate);
1314
1315 return 0;
1316}
1317
1318/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
1319static struct iw_statistics *cfg80211_wireless_stats(struct net_device *dev)
1320{
1321 struct wireless_dev *wdev = dev->ieee80211_ptr;
1322 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1323 /* we are under RTNL - globally locked - so can use static structs */
1324 static struct iw_statistics wstats;
1325 static struct station_info sinfo;
1326 u8 bssid[ETH_ALEN];
1327
1328 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION)
1329 return NULL;
1330
1331 if (!rdev->ops->get_station)
1332 return NULL;
1333
1334 /* Grab BSSID of current BSS, if any */
1335 wdev_lock(wdev);
1336 if (!wdev->current_bss) {
1337 wdev_unlock(wdev);
1338 return NULL;
1339 }
1340 memcpy(bssid, wdev->current_bss->pub.bssid, ETH_ALEN);
1341 wdev_unlock(wdev);
1342
1343 if (rdev->ops->get_station(&rdev->wiphy, dev, bssid, &sinfo))
1344 return NULL;
1345
1346 memset(&wstats, 0, sizeof(wstats));
1347
1348 switch (rdev->wiphy.signal_type) {
1349 case CFG80211_SIGNAL_TYPE_MBM:
1350 if (sinfo.filled & STATION_INFO_SIGNAL) {
1351 int sig = sinfo.signal;
1352 wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
1353 wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
1354 wstats.qual.updated |= IW_QUAL_DBM;
1355 wstats.qual.level = sig;
1356 if (sig < -110)
1357 sig = -110;
1358 else if (sig > -40)
1359 sig = -40;
1360 wstats.qual.qual = sig + 110;
1361 break;
1362 }
1363 case CFG80211_SIGNAL_TYPE_UNSPEC:
1364 if (sinfo.filled & STATION_INFO_SIGNAL) {
1365 wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
1366 wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
1367 wstats.qual.level = sinfo.signal;
1368 wstats.qual.qual = sinfo.signal;
1369 break;
1370 }
1371 default:
1372 wstats.qual.updated |= IW_QUAL_LEVEL_INVALID;
1373 wstats.qual.updated |= IW_QUAL_QUAL_INVALID;
1374 }
1375
1376 wstats.qual.updated |= IW_QUAL_NOISE_INVALID;
1377 if (sinfo.filled & STATION_INFO_RX_DROP_MISC)
1378 wstats.discard.misc = sinfo.rx_dropped_misc;
1379 if (sinfo.filled & STATION_INFO_TX_FAILED)
1380 wstats.discard.retries = sinfo.tx_failed;
1381
1382 return &wstats;
1383}
1384
1385static int cfg80211_wext_siwap(struct net_device *dev,
1386 struct iw_request_info *info,
1387 struct sockaddr *ap_addr, char *extra)
1388{
1389 struct wireless_dev *wdev = dev->ieee80211_ptr;
1390
1391 switch (wdev->iftype) {
1392 case NL80211_IFTYPE_ADHOC:
1393 return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra);
1394 case NL80211_IFTYPE_STATION:
1395 return cfg80211_mgd_wext_siwap(dev, info, ap_addr, extra);
1396 case NL80211_IFTYPE_WDS:
1397 return cfg80211_wds_wext_siwap(dev, info, ap_addr, extra);
1398 default:
1399 return -EOPNOTSUPP;
1400 }
1401}
1402
1403static int cfg80211_wext_giwap(struct net_device *dev,
1404 struct iw_request_info *info,
1405 struct sockaddr *ap_addr, char *extra)
1406{
1407 struct wireless_dev *wdev = dev->ieee80211_ptr;
1408
1409 switch (wdev->iftype) {
1410 case NL80211_IFTYPE_ADHOC:
1411 return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra);
1412 case NL80211_IFTYPE_STATION:
1413 return cfg80211_mgd_wext_giwap(dev, info, ap_addr, extra);
1414 case NL80211_IFTYPE_WDS:
1415 return cfg80211_wds_wext_giwap(dev, info, ap_addr, extra);
1416 default:
1417 return -EOPNOTSUPP;
1418 }
1419}
1420
1421static int cfg80211_wext_siwessid(struct net_device *dev,
1422 struct iw_request_info *info,
1423 struct iw_point *data, char *ssid)
1424{
1425 struct wireless_dev *wdev = dev->ieee80211_ptr;
1426
1427 switch (wdev->iftype) {
1428 case NL80211_IFTYPE_ADHOC:
1429 return cfg80211_ibss_wext_siwessid(dev, info, data, ssid);
1430 case NL80211_IFTYPE_STATION:
1431 return cfg80211_mgd_wext_siwessid(dev, info, data, ssid);
1432 default:
1433 return -EOPNOTSUPP;
1434 }
1435}
1436
1437static int cfg80211_wext_giwessid(struct net_device *dev,
1438 struct iw_request_info *info,
1439 struct iw_point *data, char *ssid)
1440{
1441 struct wireless_dev *wdev = dev->ieee80211_ptr;
1442
1443 data->flags = 0;
1444 data->length = 0;
1445
1446 switch (wdev->iftype) {
1447 case NL80211_IFTYPE_ADHOC:
1448 return cfg80211_ibss_wext_giwessid(dev, info, data, ssid);
1449 case NL80211_IFTYPE_STATION:
1450 return cfg80211_mgd_wext_giwessid(dev, info, data, ssid);
1451 default:
1452 return -EOPNOTSUPP;
1453 }
1454}
1455
1456static int 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}
1496
1497static const iw_handler cfg80211_handlers[] = {
1498 [IW_IOCTL_IDX(SIOCGIWNAME)] = (iw_handler) cfg80211_wext_giwname,
1499 [IW_IOCTL_IDX(SIOCSIWFREQ)] = (iw_handler) cfg80211_wext_siwfreq,
1500 [IW_IOCTL_IDX(SIOCGIWFREQ)] = (iw_handler) cfg80211_wext_giwfreq,
1501 [IW_IOCTL_IDX(SIOCSIWMODE)] = (iw_handler) cfg80211_wext_siwmode,
1502 [IW_IOCTL_IDX(SIOCGIWMODE)] = (iw_handler) cfg80211_wext_giwmode,
1503 [IW_IOCTL_IDX(SIOCGIWRANGE)] = (iw_handler) cfg80211_wext_giwrange,
1504 [IW_IOCTL_IDX(SIOCSIWAP)] = (iw_handler) cfg80211_wext_siwap,
1505 [IW_IOCTL_IDX(SIOCGIWAP)] = (iw_handler) cfg80211_wext_giwap,
1506 [IW_IOCTL_IDX(SIOCSIWMLME)] = (iw_handler) cfg80211_wext_siwmlme,
1507 [IW_IOCTL_IDX(SIOCSIWSCAN)] = (iw_handler) cfg80211_wext_siwscan,
1508 [IW_IOCTL_IDX(SIOCGIWSCAN)] = (iw_handler) cfg80211_wext_giwscan,
1509 [IW_IOCTL_IDX(SIOCSIWESSID)] = (iw_handler) cfg80211_wext_siwessid,
1510 [IW_IOCTL_IDX(SIOCGIWESSID)] = (iw_handler) cfg80211_wext_giwessid,
1511 [IW_IOCTL_IDX(SIOCSIWRATE)] = (iw_handler) cfg80211_wext_siwrate,
1512 [IW_IOCTL_IDX(SIOCGIWRATE)] = (iw_handler) cfg80211_wext_giwrate,
1513 [IW_IOCTL_IDX(SIOCSIWRTS)] = (iw_handler) cfg80211_wext_siwrts,
1514 [IW_IOCTL_IDX(SIOCGIWRTS)] = (iw_handler) cfg80211_wext_giwrts,
1515 [IW_IOCTL_IDX(SIOCSIWFRAG)] = (iw_handler) cfg80211_wext_siwfrag,
1516 [IW_IOCTL_IDX(SIOCGIWFRAG)] = (iw_handler) cfg80211_wext_giwfrag,
1517 [IW_IOCTL_IDX(SIOCSIWTXPOW)] = (iw_handler) cfg80211_wext_siwtxpower,
1518 [IW_IOCTL_IDX(SIOCGIWTXPOW)] = (iw_handler) cfg80211_wext_giwtxpower,
1519 [IW_IOCTL_IDX(SIOCSIWRETRY)] = (iw_handler) cfg80211_wext_siwretry,
1520 [IW_IOCTL_IDX(SIOCGIWRETRY)] = (iw_handler) cfg80211_wext_giwretry,
1521 [IW_IOCTL_IDX(SIOCSIWENCODE)] = (iw_handler) cfg80211_wext_siwencode,
1522 [IW_IOCTL_IDX(SIOCGIWENCODE)] = (iw_handler) cfg80211_wext_giwencode,
1523 [IW_IOCTL_IDX(SIOCSIWPOWER)] = (iw_handler) cfg80211_wext_siwpower,
1524 [IW_IOCTL_IDX(SIOCGIWPOWER)] = (iw_handler) cfg80211_wext_giwpower,
1525 [IW_IOCTL_IDX(SIOCSIWGENIE)] = (iw_handler) cfg80211_wext_siwgenie,
1526 [IW_IOCTL_IDX(SIOCSIWAUTH)] = (iw_handler) cfg80211_wext_siwauth,
1527 [IW_IOCTL_IDX(SIOCGIWAUTH)] = (iw_handler) cfg80211_wext_giwauth,
1528 [IW_IOCTL_IDX(SIOCSIWENCODEEXT)]= (iw_handler) cfg80211_wext_siwencodeext,
1529 [IW_IOCTL_IDX(SIOCSIWPMKSA)] = (iw_handler) cfg80211_wext_siwpmksa,
1530};
1531
1532const struct iw_handler_def cfg80211_wext_handler = {
1533 .num_standard = ARRAY_SIZE(cfg80211_handlers),
1534 .standard = cfg80211_handlers,
1535 .get_wireless_stats = cfg80211_wireless_stats,
1536};