2 * cfg80211 - wext compat code
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.
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"
24 int cfg80211_wext_giwname(struct net_device *dev,
25 struct iw_request_info *info,
26 char *name, char *extra)
28 strcpy(name, "IEEE 802.11");
31 EXPORT_WEXT_HANDLER(cfg80211_wext_giwname);
33 int cfg80211_wext_siwmode(struct net_device *dev, struct iw_request_info *info,
34 u32 *mode, char *extra)
36 struct wireless_dev *wdev = dev->ieee80211_ptr;
37 struct cfg80211_registered_device *rdev;
38 struct vif_params vifparams;
39 enum nl80211_iftype type;
41 rdev = wiphy_to_rdev(wdev->wiphy);
45 type = NL80211_IFTYPE_STATION;
48 type = NL80211_IFTYPE_ADHOC;
51 type = NL80211_IFTYPE_WDS;
54 type = NL80211_IFTYPE_MONITOR;
60 if (type == wdev->iftype)
63 memset(&vifparams, 0, sizeof(vifparams));
65 return cfg80211_change_iface(rdev, dev, type, NULL, &vifparams);
67 EXPORT_WEXT_HANDLER(cfg80211_wext_siwmode);
69 int cfg80211_wext_giwmode(struct net_device *dev, struct iw_request_info *info,
70 u32 *mode, char *extra)
72 struct wireless_dev *wdev = dev->ieee80211_ptr;
77 switch (wdev->iftype) {
78 case NL80211_IFTYPE_AP:
79 *mode = IW_MODE_MASTER;
81 case NL80211_IFTYPE_STATION:
82 *mode = IW_MODE_INFRA;
84 case NL80211_IFTYPE_ADHOC:
85 *mode = IW_MODE_ADHOC;
87 case NL80211_IFTYPE_MONITOR:
88 *mode = IW_MODE_MONITOR;
90 case NL80211_IFTYPE_WDS:
91 *mode = IW_MODE_REPEAT;
93 case NL80211_IFTYPE_AP_VLAN:
94 *mode = IW_MODE_SECOND; /* FIXME */
102 EXPORT_WEXT_HANDLER(cfg80211_wext_giwmode);
105 int cfg80211_wext_giwrange(struct net_device *dev,
106 struct iw_request_info *info,
107 struct iw_point *data, char *extra)
109 struct wireless_dev *wdev = dev->ieee80211_ptr;
110 struct iw_range *range = (struct iw_range *) extra;
111 enum nl80211_band band;
117 data->length = sizeof(struct iw_range);
118 memset(range, 0, sizeof(struct iw_range));
120 range->we_version_compiled = WIRELESS_EXT;
121 range->we_version_source = 21;
122 range->retry_capa = IW_RETRY_LIMIT;
123 range->retry_flags = IW_RETRY_LIMIT;
124 range->min_retry = 0;
125 range->max_retry = 255;
127 range->max_rts = 2347;
128 range->min_frag = 256;
129 range->max_frag = 2346;
131 range->max_encoding_tokens = 4;
133 range->max_qual.updated = IW_QUAL_NOISE_INVALID;
135 switch (wdev->wiphy->signal_type) {
136 case CFG80211_SIGNAL_TYPE_NONE:
138 case CFG80211_SIGNAL_TYPE_MBM:
139 range->max_qual.level = (u8)-110;
140 range->max_qual.qual = 70;
141 range->avg_qual.qual = 35;
142 range->max_qual.updated |= IW_QUAL_DBM;
143 range->max_qual.updated |= IW_QUAL_QUAL_UPDATED;
144 range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED;
146 case CFG80211_SIGNAL_TYPE_UNSPEC:
147 range->max_qual.level = 100;
148 range->max_qual.qual = 100;
149 range->avg_qual.qual = 50;
150 range->max_qual.updated |= IW_QUAL_QUAL_UPDATED;
151 range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED;
155 range->avg_qual.level = range->max_qual.level / 2;
156 range->avg_qual.noise = range->max_qual.noise / 2;
157 range->avg_qual.updated = range->max_qual.updated;
159 for (i = 0; i < wdev->wiphy->n_cipher_suites; i++) {
160 switch (wdev->wiphy->cipher_suites[i]) {
161 case WLAN_CIPHER_SUITE_TKIP:
162 range->enc_capa |= (IW_ENC_CAPA_CIPHER_TKIP |
166 case WLAN_CIPHER_SUITE_CCMP:
167 range->enc_capa |= (IW_ENC_CAPA_CIPHER_CCMP |
171 case WLAN_CIPHER_SUITE_WEP40:
172 range->encoding_size[range->num_encoding_sizes++] =
176 case WLAN_CIPHER_SUITE_WEP104:
177 range->encoding_size[range->num_encoding_sizes++] =
183 for (band = 0; band < NUM_NL80211_BANDS; band ++) {
184 struct ieee80211_supported_band *sband;
186 sband = wdev->wiphy->bands[band];
191 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
192 struct ieee80211_channel *chan = &sband->channels[i];
194 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
196 ieee80211_frequency_to_channel(
198 range->freq[c].m = chan->center_freq;
199 range->freq[c].e = 6;
204 range->num_channels = c;
205 range->num_frequency = c;
207 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
208 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
209 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
211 if (wdev->wiphy->max_scan_ssids > 0)
212 range->scan_capa |= IW_SCAN_CAPA_ESSID;
216 EXPORT_WEXT_HANDLER(cfg80211_wext_giwrange);
220 * cfg80211_wext_freq - get wext frequency for non-"auto"
221 * @dev: the net device
222 * @freq: the wext freq encoding
224 * Returns a frequency, or a negative error code, or 0 for auto.
226 int cfg80211_wext_freq(struct iw_freq *freq)
229 * Parse frequency - return 0 for auto and
230 * -EINVAL for impossible things.
233 enum nl80211_band band = NL80211_BAND_2GHZ;
237 band = NL80211_BAND_5GHZ;
238 return ieee80211_channel_to_frequency(freq->m, band);
240 int i, div = 1000000;
241 for (i = 0; i < freq->e; i++)
245 return freq->m / div;
249 int cfg80211_wext_siwrts(struct net_device *dev,
250 struct iw_request_info *info,
251 struct iw_param *rts, char *extra)
253 struct wireless_dev *wdev = dev->ieee80211_ptr;
254 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
255 u32 orts = wdev->wiphy->rts_threshold;
258 if (rts->disabled || !rts->fixed)
259 wdev->wiphy->rts_threshold = (u32) -1;
260 else if (rts->value < 0)
263 wdev->wiphy->rts_threshold = rts->value;
265 err = rdev_set_wiphy_params(rdev, WIPHY_PARAM_RTS_THRESHOLD);
267 wdev->wiphy->rts_threshold = orts;
271 EXPORT_WEXT_HANDLER(cfg80211_wext_siwrts);
273 int cfg80211_wext_giwrts(struct net_device *dev,
274 struct iw_request_info *info,
275 struct iw_param *rts, char *extra)
277 struct wireless_dev *wdev = dev->ieee80211_ptr;
279 rts->value = wdev->wiphy->rts_threshold;
280 rts->disabled = rts->value == (u32) -1;
285 EXPORT_WEXT_HANDLER(cfg80211_wext_giwrts);
287 int cfg80211_wext_siwfrag(struct net_device *dev,
288 struct iw_request_info *info,
289 struct iw_param *frag, char *extra)
291 struct wireless_dev *wdev = dev->ieee80211_ptr;
292 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
293 u32 ofrag = wdev->wiphy->frag_threshold;
296 if (frag->disabled || !frag->fixed)
297 wdev->wiphy->frag_threshold = (u32) -1;
298 else if (frag->value < 256)
301 /* Fragment length must be even, so strip LSB. */
302 wdev->wiphy->frag_threshold = frag->value & ~0x1;
305 err = rdev_set_wiphy_params(rdev, WIPHY_PARAM_FRAG_THRESHOLD);
307 wdev->wiphy->frag_threshold = ofrag;
311 EXPORT_WEXT_HANDLER(cfg80211_wext_siwfrag);
313 int cfg80211_wext_giwfrag(struct net_device *dev,
314 struct iw_request_info *info,
315 struct iw_param *frag, char *extra)
317 struct wireless_dev *wdev = dev->ieee80211_ptr;
319 frag->value = wdev->wiphy->frag_threshold;
320 frag->disabled = frag->value == (u32) -1;
325 EXPORT_WEXT_HANDLER(cfg80211_wext_giwfrag);
327 static int cfg80211_wext_siwretry(struct net_device *dev,
328 struct iw_request_info *info,
329 struct iw_param *retry, char *extra)
331 struct wireless_dev *wdev = dev->ieee80211_ptr;
332 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
334 u8 olong = wdev->wiphy->retry_long;
335 u8 oshort = wdev->wiphy->retry_short;
338 if (retry->disabled || retry->value < 1 || retry->value > 255 ||
339 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
342 if (retry->flags & IW_RETRY_LONG) {
343 wdev->wiphy->retry_long = retry->value;
344 changed |= WIPHY_PARAM_RETRY_LONG;
345 } else if (retry->flags & IW_RETRY_SHORT) {
346 wdev->wiphy->retry_short = retry->value;
347 changed |= WIPHY_PARAM_RETRY_SHORT;
349 wdev->wiphy->retry_short = retry->value;
350 wdev->wiphy->retry_long = retry->value;
351 changed |= WIPHY_PARAM_RETRY_LONG;
352 changed |= WIPHY_PARAM_RETRY_SHORT;
358 err = rdev_set_wiphy_params(rdev, changed);
360 wdev->wiphy->retry_short = oshort;
361 wdev->wiphy->retry_long = olong;
367 int cfg80211_wext_giwretry(struct net_device *dev,
368 struct iw_request_info *info,
369 struct iw_param *retry, char *extra)
371 struct wireless_dev *wdev = dev->ieee80211_ptr;
375 if (retry->flags == 0 || (retry->flags & IW_RETRY_SHORT)) {
377 * First return short value, iwconfig will ask long value
380 retry->flags |= IW_RETRY_LIMIT | IW_RETRY_SHORT;
381 retry->value = wdev->wiphy->retry_short;
382 if (wdev->wiphy->retry_long == wdev->wiphy->retry_short)
383 retry->flags |= IW_RETRY_LONG;
388 if (retry->flags & IW_RETRY_LONG) {
389 retry->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
390 retry->value = wdev->wiphy->retry_long;
395 EXPORT_WEXT_HANDLER(cfg80211_wext_giwretry);
397 static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
398 struct net_device *dev, bool pairwise,
399 const u8 *addr, bool remove, bool tx_key,
400 int idx, struct key_params *params)
402 struct wireless_dev *wdev = dev->ieee80211_ptr;
406 if (pairwise && !addr)
410 * In many cases we won't actually need this, but it's better
411 * to do it first in case the allocation fails. Don't use wext.
413 if (!wdev->wext.keys) {
414 wdev->wext.keys = kzalloc(sizeof(*wdev->wext.keys),
416 if (!wdev->wext.keys)
418 for (i = 0; i < CFG80211_MAX_WEP_KEYS; i++)
419 wdev->wext.keys->params[i].key =
420 wdev->wext.keys->data[i];
423 if (wdev->iftype != NL80211_IFTYPE_ADHOC &&
424 wdev->iftype != NL80211_IFTYPE_STATION)
427 if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
428 if (!wdev->current_bss)
431 if (!rdev->ops->set_default_mgmt_key)
434 if (idx < 4 || idx > 5)
436 } else if (idx < 0 || idx > 3)
441 if (wdev->current_bss) {
443 * If removing the current TX key, we will need to
444 * join a new IBSS without the privacy bit clear.
446 if (idx == wdev->wext.default_key &&
447 wdev->iftype == NL80211_IFTYPE_ADHOC) {
448 __cfg80211_leave_ibss(rdev, wdev->netdev, true);
452 if (!pairwise && addr &&
453 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
456 err = rdev_del_key(rdev, dev, idx, pairwise,
459 wdev->wext.connect.privacy = false;
461 * Applications using wireless extensions expect to be
462 * able to delete keys that don't exist, so allow that.
467 if (!addr && idx < 4) {
468 memset(wdev->wext.keys->data[idx], 0,
469 sizeof(wdev->wext.keys->data[idx]));
470 wdev->wext.keys->params[idx].key_len = 0;
471 wdev->wext.keys->params[idx].cipher = 0;
473 if (idx == wdev->wext.default_key)
474 wdev->wext.default_key = -1;
475 else if (idx == wdev->wext.default_mgmt_key)
476 wdev->wext.default_mgmt_key = -1;
480 err = cfg80211_ibss_wext_join(rdev, wdev);
488 if (cfg80211_validate_key_settings(rdev, params, idx, pairwise, addr))
492 if (wdev->current_bss)
493 err = rdev_add_key(rdev, dev, idx, pairwise, addr, params);
494 else if (params->cipher != WLAN_CIPHER_SUITE_WEP40 &&
495 params->cipher != WLAN_CIPHER_SUITE_WEP104)
501 * We only need to store WEP keys, since they're the only keys that
502 * can be be set before a connection is established and persist after
505 if (!addr && (params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
506 params->cipher == WLAN_CIPHER_SUITE_WEP104)) {
507 wdev->wext.keys->params[idx] = *params;
508 memcpy(wdev->wext.keys->data[idx],
509 params->key, params->key_len);
510 wdev->wext.keys->params[idx].key =
511 wdev->wext.keys->data[idx];
514 if ((params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
515 params->cipher == WLAN_CIPHER_SUITE_WEP104) &&
516 (tx_key || (!addr && wdev->wext.default_key == -1))) {
517 if (wdev->current_bss) {
519 * If we are getting a new TX key from not having
520 * had one before we need to join a new IBSS with
521 * the privacy bit set.
523 if (wdev->iftype == NL80211_IFTYPE_ADHOC &&
524 wdev->wext.default_key == -1) {
525 __cfg80211_leave_ibss(rdev, wdev->netdev, true);
528 err = rdev_set_default_key(rdev, dev, idx, true, true);
531 wdev->wext.default_key = idx;
533 err = cfg80211_ibss_wext_join(rdev, wdev);
538 if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC &&
539 (tx_key || (!addr && wdev->wext.default_mgmt_key == -1))) {
540 if (wdev->current_bss)
541 err = rdev_set_default_mgmt_key(rdev, dev, idx);
543 wdev->wext.default_mgmt_key = idx;
550 static int cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
551 struct net_device *dev, bool pairwise,
552 const u8 *addr, bool remove, bool tx_key,
553 int idx, struct key_params *params)
557 wdev_lock(dev->ieee80211_ptr);
558 err = __cfg80211_set_encryption(rdev, dev, pairwise, addr,
559 remove, tx_key, idx, params);
560 wdev_unlock(dev->ieee80211_ptr);
565 static int cfg80211_wext_siwencode(struct net_device *dev,
566 struct iw_request_info *info,
567 struct iw_point *erq, char *keybuf)
569 struct wireless_dev *wdev = dev->ieee80211_ptr;
570 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
573 struct key_params params;
575 if (wdev->iftype != NL80211_IFTYPE_STATION &&
576 wdev->iftype != NL80211_IFTYPE_ADHOC)
579 /* no use -- only MFP (set_default_mgmt_key) is optional */
580 if (!rdev->ops->del_key ||
581 !rdev->ops->add_key ||
582 !rdev->ops->set_default_key)
585 idx = erq->flags & IW_ENCODE_INDEX;
587 idx = wdev->wext.default_key;
590 } else if (idx < 1 || idx > 4)
595 if (erq->flags & IW_ENCODE_DISABLED)
597 else if (erq->length == 0) {
598 /* No key data - just set the default TX key index */
601 if (wdev->current_bss)
602 err = rdev_set_default_key(rdev, dev, idx, true,
605 wdev->wext.default_key = idx;
610 memset(¶ms, 0, sizeof(params));
612 params.key_len = erq->length;
613 if (erq->length == 5)
614 params.cipher = WLAN_CIPHER_SUITE_WEP40;
615 else if (erq->length == 13)
616 params.cipher = WLAN_CIPHER_SUITE_WEP104;
620 return cfg80211_set_encryption(rdev, dev, false, NULL, remove,
621 wdev->wext.default_key == -1,
625 static int cfg80211_wext_siwencodeext(struct net_device *dev,
626 struct iw_request_info *info,
627 struct iw_point *erq, char *extra)
629 struct wireless_dev *wdev = dev->ieee80211_ptr;
630 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
631 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
635 struct key_params params;
638 if (wdev->iftype != NL80211_IFTYPE_STATION &&
639 wdev->iftype != NL80211_IFTYPE_ADHOC)
642 /* no use -- only MFP (set_default_mgmt_key) is optional */
643 if (!rdev->ops->del_key ||
644 !rdev->ops->add_key ||
645 !rdev->ops->set_default_key)
649 case IW_ENCODE_ALG_NONE:
653 case IW_ENCODE_ALG_WEP:
654 if (ext->key_len == 5)
655 cipher = WLAN_CIPHER_SUITE_WEP40;
656 else if (ext->key_len == 13)
657 cipher = WLAN_CIPHER_SUITE_WEP104;
661 case IW_ENCODE_ALG_TKIP:
662 cipher = WLAN_CIPHER_SUITE_TKIP;
664 case IW_ENCODE_ALG_CCMP:
665 cipher = WLAN_CIPHER_SUITE_CCMP;
667 case IW_ENCODE_ALG_AES_CMAC:
668 cipher = WLAN_CIPHER_SUITE_AES_CMAC;
674 if (erq->flags & IW_ENCODE_DISABLED)
677 idx = erq->flags & IW_ENCODE_INDEX;
678 if (cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
679 if (idx < 4 || idx > 5) {
680 idx = wdev->wext.default_mgmt_key;
686 if (idx < 1 || idx > 4) {
687 idx = wdev->wext.default_key;
694 addr = ext->addr.sa_data;
695 if (is_broadcast_ether_addr(addr))
698 memset(¶ms, 0, sizeof(params));
699 params.key = ext->key;
700 params.key_len = ext->key_len;
701 params.cipher = cipher;
703 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
704 params.seq = ext->rx_seq;
708 return cfg80211_set_encryption(
710 !(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY),
712 ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
716 static int cfg80211_wext_giwencode(struct net_device *dev,
717 struct iw_request_info *info,
718 struct iw_point *erq, char *keybuf)
720 struct wireless_dev *wdev = dev->ieee80211_ptr;
723 if (wdev->iftype != NL80211_IFTYPE_STATION &&
724 wdev->iftype != NL80211_IFTYPE_ADHOC)
727 idx = erq->flags & IW_ENCODE_INDEX;
729 idx = wdev->wext.default_key;
732 } else if (idx < 1 || idx > 4)
737 erq->flags = idx + 1;
739 if (!wdev->wext.keys || !wdev->wext.keys->params[idx].cipher) {
740 erq->flags |= IW_ENCODE_DISABLED;
745 erq->length = min_t(size_t, erq->length,
746 wdev->wext.keys->params[idx].key_len);
747 memcpy(keybuf, wdev->wext.keys->params[idx].key, erq->length);
748 erq->flags |= IW_ENCODE_ENABLED;
753 static int cfg80211_wext_siwfreq(struct net_device *dev,
754 struct iw_request_info *info,
755 struct iw_freq *wextfreq, char *extra)
757 struct wireless_dev *wdev = dev->ieee80211_ptr;
758 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
759 struct cfg80211_chan_def chandef = {
760 .width = NL80211_CHAN_WIDTH_20_NOHT,
764 switch (wdev->iftype) {
765 case NL80211_IFTYPE_STATION:
766 return cfg80211_mgd_wext_siwfreq(dev, info, wextfreq, extra);
767 case NL80211_IFTYPE_ADHOC:
768 return cfg80211_ibss_wext_siwfreq(dev, info, wextfreq, extra);
769 case NL80211_IFTYPE_MONITOR:
770 freq = cfg80211_wext_freq(wextfreq);
775 chandef.center_freq1 = freq;
776 chandef.chan = ieee80211_get_channel(&rdev->wiphy, freq);
779 return cfg80211_set_monitor_channel(rdev, &chandef);
780 case NL80211_IFTYPE_MESH_POINT:
781 freq = cfg80211_wext_freq(wextfreq);
786 chandef.center_freq1 = freq;
787 chandef.chan = ieee80211_get_channel(&rdev->wiphy, freq);
790 return cfg80211_set_mesh_channel(rdev, wdev, &chandef);
796 static int cfg80211_wext_giwfreq(struct net_device *dev,
797 struct iw_request_info *info,
798 struct iw_freq *freq, char *extra)
800 struct wireless_dev *wdev = dev->ieee80211_ptr;
801 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
802 struct cfg80211_chan_def chandef;
805 switch (wdev->iftype) {
806 case NL80211_IFTYPE_STATION:
807 return cfg80211_mgd_wext_giwfreq(dev, info, freq, extra);
808 case NL80211_IFTYPE_ADHOC:
809 return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra);
810 case NL80211_IFTYPE_MONITOR:
811 if (!rdev->ops->get_channel)
814 ret = rdev_get_channel(rdev, wdev, &chandef);
817 freq->m = chandef.chan->center_freq;
825 static int cfg80211_wext_siwtxpower(struct net_device *dev,
826 struct iw_request_info *info,
827 union iwreq_data *data, char *extra)
829 struct wireless_dev *wdev = dev->ieee80211_ptr;
830 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
831 enum nl80211_tx_power_setting type;
834 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
836 if (data->txpower.flags & IW_TXPOW_RANGE)
839 if (!rdev->ops->set_tx_power)
842 /* only change when not disabling */
843 if (!data->txpower.disabled) {
844 rfkill_set_sw_state(rdev->rfkill, false);
846 if (data->txpower.fixed) {
848 * wext doesn't support negative values, see
849 * below where it's for automatic
851 if (data->txpower.value < 0)
853 dbm = data->txpower.value;
854 type = NL80211_TX_POWER_FIXED;
855 /* TODO: do regulatory check! */
858 * Automatic power level setting, max being the value
859 * passed in from userland.
861 if (data->txpower.value < 0) {
862 type = NL80211_TX_POWER_AUTOMATIC;
864 dbm = data->txpower.value;
865 type = NL80211_TX_POWER_LIMITED;
869 rfkill_set_sw_state(rdev->rfkill, true);
870 schedule_work(&rdev->rfkill_sync);
874 return rdev_set_tx_power(rdev, wdev, type, DBM_TO_MBM(dbm));
877 static int cfg80211_wext_giwtxpower(struct net_device *dev,
878 struct iw_request_info *info,
879 union iwreq_data *data, char *extra)
881 struct wireless_dev *wdev = dev->ieee80211_ptr;
882 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
885 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
887 if (data->txpower.flags & IW_TXPOW_RANGE)
890 if (!rdev->ops->get_tx_power)
893 err = rdev_get_tx_power(rdev, wdev, &val);
897 /* well... oh well */
898 data->txpower.fixed = 1;
899 data->txpower.disabled = rfkill_blocked(rdev->rfkill);
900 data->txpower.value = val;
901 data->txpower.flags = IW_TXPOW_DBM;
906 static int cfg80211_set_auth_alg(struct wireless_dev *wdev,
914 if (auth_alg & ~(IW_AUTH_ALG_OPEN_SYSTEM |
915 IW_AUTH_ALG_SHARED_KEY |
919 if (auth_alg & IW_AUTH_ALG_OPEN_SYSTEM) {
921 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
924 if (auth_alg & IW_AUTH_ALG_SHARED_KEY) {
926 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_SHARED_KEY;
929 if (auth_alg & IW_AUTH_ALG_LEAP) {
931 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_NETWORK_EAP;
935 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
940 static int cfg80211_set_wpa_version(struct wireless_dev *wdev, u32 wpa_versions)
942 if (wpa_versions & ~(IW_AUTH_WPA_VERSION_WPA |
943 IW_AUTH_WPA_VERSION_WPA2|
944 IW_AUTH_WPA_VERSION_DISABLED))
947 if ((wpa_versions & IW_AUTH_WPA_VERSION_DISABLED) &&
948 (wpa_versions & (IW_AUTH_WPA_VERSION_WPA|
949 IW_AUTH_WPA_VERSION_WPA2)))
952 if (wpa_versions & IW_AUTH_WPA_VERSION_DISABLED)
953 wdev->wext.connect.crypto.wpa_versions &=
954 ~(NL80211_WPA_VERSION_1|NL80211_WPA_VERSION_2);
956 if (wpa_versions & IW_AUTH_WPA_VERSION_WPA)
957 wdev->wext.connect.crypto.wpa_versions |=
958 NL80211_WPA_VERSION_1;
960 if (wpa_versions & IW_AUTH_WPA_VERSION_WPA2)
961 wdev->wext.connect.crypto.wpa_versions |=
962 NL80211_WPA_VERSION_2;
967 static int cfg80211_set_cipher_group(struct wireless_dev *wdev, u32 cipher)
969 if (cipher & IW_AUTH_CIPHER_WEP40)
970 wdev->wext.connect.crypto.cipher_group =
971 WLAN_CIPHER_SUITE_WEP40;
972 else if (cipher & IW_AUTH_CIPHER_WEP104)
973 wdev->wext.connect.crypto.cipher_group =
974 WLAN_CIPHER_SUITE_WEP104;
975 else if (cipher & IW_AUTH_CIPHER_TKIP)
976 wdev->wext.connect.crypto.cipher_group =
977 WLAN_CIPHER_SUITE_TKIP;
978 else if (cipher & IW_AUTH_CIPHER_CCMP)
979 wdev->wext.connect.crypto.cipher_group =
980 WLAN_CIPHER_SUITE_CCMP;
981 else if (cipher & IW_AUTH_CIPHER_AES_CMAC)
982 wdev->wext.connect.crypto.cipher_group =
983 WLAN_CIPHER_SUITE_AES_CMAC;
984 else if (cipher & IW_AUTH_CIPHER_NONE)
985 wdev->wext.connect.crypto.cipher_group = 0;
992 static int cfg80211_set_cipher_pairwise(struct wireless_dev *wdev, u32 cipher)
995 u32 *ciphers_pairwise = wdev->wext.connect.crypto.ciphers_pairwise;
997 if (cipher & IW_AUTH_CIPHER_WEP40) {
998 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP40;
1002 if (cipher & IW_AUTH_CIPHER_WEP104) {
1003 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP104;
1007 if (cipher & IW_AUTH_CIPHER_TKIP) {
1008 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_TKIP;
1012 if (cipher & IW_AUTH_CIPHER_CCMP) {
1013 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_CCMP;
1017 if (cipher & IW_AUTH_CIPHER_AES_CMAC) {
1018 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_AES_CMAC;
1022 BUILD_BUG_ON(NL80211_MAX_NR_CIPHER_SUITES < 5);
1024 wdev->wext.connect.crypto.n_ciphers_pairwise = nr_ciphers;
1030 static int cfg80211_set_key_mgt(struct wireless_dev *wdev, u32 key_mgt)
1032 int nr_akm_suites = 0;
1034 if (key_mgt & ~(IW_AUTH_KEY_MGMT_802_1X |
1035 IW_AUTH_KEY_MGMT_PSK))
1038 if (key_mgt & IW_AUTH_KEY_MGMT_802_1X) {
1039 wdev->wext.connect.crypto.akm_suites[nr_akm_suites] =
1040 WLAN_AKM_SUITE_8021X;
1044 if (key_mgt & IW_AUTH_KEY_MGMT_PSK) {
1045 wdev->wext.connect.crypto.akm_suites[nr_akm_suites] =
1050 wdev->wext.connect.crypto.n_akm_suites = nr_akm_suites;
1055 static int cfg80211_wext_siwauth(struct net_device *dev,
1056 struct iw_request_info *info,
1057 struct iw_param *data, char *extra)
1059 struct wireless_dev *wdev = dev->ieee80211_ptr;
1061 if (wdev->iftype != NL80211_IFTYPE_STATION)
1064 switch (data->flags & IW_AUTH_INDEX) {
1065 case IW_AUTH_PRIVACY_INVOKED:
1066 wdev->wext.connect.privacy = data->value;
1068 case IW_AUTH_WPA_VERSION:
1069 return cfg80211_set_wpa_version(wdev, data->value);
1070 case IW_AUTH_CIPHER_GROUP:
1071 return cfg80211_set_cipher_group(wdev, data->value);
1072 case IW_AUTH_KEY_MGMT:
1073 return cfg80211_set_key_mgt(wdev, data->value);
1074 case IW_AUTH_CIPHER_PAIRWISE:
1075 return cfg80211_set_cipher_pairwise(wdev, data->value);
1076 case IW_AUTH_80211_AUTH_ALG:
1077 return cfg80211_set_auth_alg(wdev, data->value);
1078 case IW_AUTH_WPA_ENABLED:
1079 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1080 case IW_AUTH_DROP_UNENCRYPTED:
1088 static int cfg80211_wext_giwauth(struct net_device *dev,
1089 struct iw_request_info *info,
1090 struct iw_param *data, char *extra)
1092 /* XXX: what do we need? */
1097 static int cfg80211_wext_siwpower(struct net_device *dev,
1098 struct iw_request_info *info,
1099 struct iw_param *wrq, char *extra)
1101 struct wireless_dev *wdev = dev->ieee80211_ptr;
1102 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
1104 int timeout = wdev->ps_timeout;
1107 if (wdev->iftype != NL80211_IFTYPE_STATION)
1110 if (!rdev->ops->set_power_mgmt)
1113 if (wrq->disabled) {
1116 switch (wrq->flags & IW_POWER_MODE) {
1117 case IW_POWER_ON: /* If not specified */
1118 case IW_POWER_MODE: /* If set all mask */
1119 case IW_POWER_ALL_R: /* If explicitely state all */
1122 default: /* Otherwise we ignore */
1126 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
1129 if (wrq->flags & IW_POWER_TIMEOUT)
1130 timeout = wrq->value / 1000;
1133 err = rdev_set_power_mgmt(rdev, dev, ps, timeout);
1138 wdev->ps_timeout = timeout;
1144 static int cfg80211_wext_giwpower(struct net_device *dev,
1145 struct iw_request_info *info,
1146 struct iw_param *wrq, char *extra)
1148 struct wireless_dev *wdev = dev->ieee80211_ptr;
1150 wrq->disabled = !wdev->ps;
1155 static int cfg80211_wds_wext_siwap(struct net_device *dev,
1156 struct iw_request_info *info,
1157 struct sockaddr *addr, char *extra)
1159 struct wireless_dev *wdev = dev->ieee80211_ptr;
1160 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
1163 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS))
1166 if (addr->sa_family != ARPHRD_ETHER)
1169 if (netif_running(dev))
1172 if (!rdev->ops->set_wds_peer)
1175 err = rdev_set_wds_peer(rdev, dev, (u8 *)&addr->sa_data);
1179 memcpy(&wdev->wext.bssid, (u8 *) &addr->sa_data, ETH_ALEN);
1184 static int cfg80211_wds_wext_giwap(struct net_device *dev,
1185 struct iw_request_info *info,
1186 struct sockaddr *addr, char *extra)
1188 struct wireless_dev *wdev = dev->ieee80211_ptr;
1190 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS))
1193 addr->sa_family = ARPHRD_ETHER;
1194 memcpy(&addr->sa_data, wdev->wext.bssid, ETH_ALEN);
1199 static int cfg80211_wext_siwrate(struct net_device *dev,
1200 struct iw_request_info *info,
1201 struct iw_param *rate, char *extra)
1203 struct wireless_dev *wdev = dev->ieee80211_ptr;
1204 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
1205 struct cfg80211_bitrate_mask mask;
1207 struct ieee80211_supported_band *sband;
1211 if (!rdev->ops->set_bitrate_mask)
1214 memset(&mask, 0, sizeof(mask));
1218 if (rate->value < 0) {
1220 } else if (rate->fixed) {
1221 fixed = rate->value / 100000;
1223 maxrate = rate->value / 100000;
1226 for (band = 0; band < NUM_NL80211_BANDS; band++) {
1227 sband = wdev->wiphy->bands[band];
1230 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
1231 struct ieee80211_rate *srate = &sband->bitrates[ridx];
1232 if (fixed == srate->bitrate) {
1233 mask.control[band].legacy = 1 << ridx;
1237 if (srate->bitrate <= maxrate) {
1238 mask.control[band].legacy |= 1 << ridx;
1247 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
1250 static int cfg80211_wext_giwrate(struct net_device *dev,
1251 struct iw_request_info *info,
1252 struct iw_param *rate, char *extra)
1254 struct wireless_dev *wdev = dev->ieee80211_ptr;
1255 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
1256 /* we are under RTNL - globally locked - so can use a static struct */
1257 static struct station_info sinfo;
1261 if (wdev->iftype != NL80211_IFTYPE_STATION)
1264 if (!rdev->ops->get_station)
1269 if (wdev->current_bss)
1270 memcpy(addr, wdev->current_bss->pub.bssid, ETH_ALEN);
1277 err = rdev_get_station(rdev, dev, addr, &sinfo);
1281 if (!(sinfo.filled & BIT(NL80211_STA_INFO_TX_BITRATE)))
1284 rate->value = 100000 * cfg80211_calculate_bitrate(&sinfo.txrate);
1289 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
1290 static struct iw_statistics *cfg80211_wireless_stats(struct net_device *dev)
1292 struct wireless_dev *wdev = dev->ieee80211_ptr;
1293 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
1294 /* we are under RTNL - globally locked - so can use static structs */
1295 static struct iw_statistics wstats;
1296 static struct station_info sinfo;
1299 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION)
1302 if (!rdev->ops->get_station)
1305 /* Grab BSSID of current BSS, if any */
1307 if (!wdev->current_bss) {
1311 memcpy(bssid, wdev->current_bss->pub.bssid, ETH_ALEN);
1314 memset(&sinfo, 0, sizeof(sinfo));
1316 if (rdev_get_station(rdev, dev, bssid, &sinfo))
1319 memset(&wstats, 0, sizeof(wstats));
1321 switch (rdev->wiphy.signal_type) {
1322 case CFG80211_SIGNAL_TYPE_MBM:
1323 if (sinfo.filled & BIT(NL80211_STA_INFO_SIGNAL)) {
1324 int sig = sinfo.signal;
1325 wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
1326 wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
1327 wstats.qual.updated |= IW_QUAL_DBM;
1328 wstats.qual.level = sig;
1333 wstats.qual.qual = sig + 110;
1336 case CFG80211_SIGNAL_TYPE_UNSPEC:
1337 if (sinfo.filled & BIT(NL80211_STA_INFO_SIGNAL)) {
1338 wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
1339 wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
1340 wstats.qual.level = sinfo.signal;
1341 wstats.qual.qual = sinfo.signal;
1345 wstats.qual.updated |= IW_QUAL_LEVEL_INVALID;
1346 wstats.qual.updated |= IW_QUAL_QUAL_INVALID;
1349 wstats.qual.updated |= IW_QUAL_NOISE_INVALID;
1350 if (sinfo.filled & BIT(NL80211_STA_INFO_RX_DROP_MISC))
1351 wstats.discard.misc = sinfo.rx_dropped_misc;
1352 if (sinfo.filled & BIT(NL80211_STA_INFO_TX_FAILED))
1353 wstats.discard.retries = sinfo.tx_failed;
1358 static int cfg80211_wext_siwap(struct net_device *dev,
1359 struct iw_request_info *info,
1360 struct sockaddr *ap_addr, char *extra)
1362 struct wireless_dev *wdev = dev->ieee80211_ptr;
1364 switch (wdev->iftype) {
1365 case NL80211_IFTYPE_ADHOC:
1366 return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra);
1367 case NL80211_IFTYPE_STATION:
1368 return cfg80211_mgd_wext_siwap(dev, info, ap_addr, extra);
1369 case NL80211_IFTYPE_WDS:
1370 return cfg80211_wds_wext_siwap(dev, info, ap_addr, extra);
1376 static int cfg80211_wext_giwap(struct net_device *dev,
1377 struct iw_request_info *info,
1378 struct sockaddr *ap_addr, char *extra)
1380 struct wireless_dev *wdev = dev->ieee80211_ptr;
1382 switch (wdev->iftype) {
1383 case NL80211_IFTYPE_ADHOC:
1384 return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra);
1385 case NL80211_IFTYPE_STATION:
1386 return cfg80211_mgd_wext_giwap(dev, info, ap_addr, extra);
1387 case NL80211_IFTYPE_WDS:
1388 return cfg80211_wds_wext_giwap(dev, info, ap_addr, extra);
1394 static int cfg80211_wext_siwessid(struct net_device *dev,
1395 struct iw_request_info *info,
1396 struct iw_point *data, char *ssid)
1398 struct wireless_dev *wdev = dev->ieee80211_ptr;
1400 switch (wdev->iftype) {
1401 case NL80211_IFTYPE_ADHOC:
1402 return cfg80211_ibss_wext_siwessid(dev, info, data, ssid);
1403 case NL80211_IFTYPE_STATION:
1404 return cfg80211_mgd_wext_siwessid(dev, info, data, ssid);
1410 static int cfg80211_wext_giwessid(struct net_device *dev,
1411 struct iw_request_info *info,
1412 struct iw_point *data, char *ssid)
1414 struct wireless_dev *wdev = dev->ieee80211_ptr;
1419 switch (wdev->iftype) {
1420 case NL80211_IFTYPE_ADHOC:
1421 return cfg80211_ibss_wext_giwessid(dev, info, data, ssid);
1422 case NL80211_IFTYPE_STATION:
1423 return cfg80211_mgd_wext_giwessid(dev, info, data, ssid);
1429 static int cfg80211_wext_siwpmksa(struct net_device *dev,
1430 struct iw_request_info *info,
1431 struct iw_point *data, char *extra)
1433 struct wireless_dev *wdev = dev->ieee80211_ptr;
1434 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
1435 struct cfg80211_pmksa cfg_pmksa;
1436 struct iw_pmksa *pmksa = (struct iw_pmksa *)extra;
1438 memset(&cfg_pmksa, 0, sizeof(struct cfg80211_pmksa));
1440 if (wdev->iftype != NL80211_IFTYPE_STATION)
1443 cfg_pmksa.bssid = pmksa->bssid.sa_data;
1444 cfg_pmksa.pmkid = pmksa->pmkid;
1446 switch (pmksa->cmd) {
1448 if (!rdev->ops->set_pmksa)
1451 return rdev_set_pmksa(rdev, dev, &cfg_pmksa);
1453 case IW_PMKSA_REMOVE:
1454 if (!rdev->ops->del_pmksa)
1457 return rdev_del_pmksa(rdev, dev, &cfg_pmksa);
1459 case IW_PMKSA_FLUSH:
1460 if (!rdev->ops->flush_pmksa)
1463 return rdev_flush_pmksa(rdev, dev);
1470 static const iw_handler cfg80211_handlers[] = {
1471 [IW_IOCTL_IDX(SIOCGIWNAME)] = (iw_handler) cfg80211_wext_giwname,
1472 [IW_IOCTL_IDX(SIOCSIWFREQ)] = (iw_handler) cfg80211_wext_siwfreq,
1473 [IW_IOCTL_IDX(SIOCGIWFREQ)] = (iw_handler) cfg80211_wext_giwfreq,
1474 [IW_IOCTL_IDX(SIOCSIWMODE)] = (iw_handler) cfg80211_wext_siwmode,
1475 [IW_IOCTL_IDX(SIOCGIWMODE)] = (iw_handler) cfg80211_wext_giwmode,
1476 [IW_IOCTL_IDX(SIOCGIWRANGE)] = (iw_handler) cfg80211_wext_giwrange,
1477 [IW_IOCTL_IDX(SIOCSIWAP)] = (iw_handler) cfg80211_wext_siwap,
1478 [IW_IOCTL_IDX(SIOCGIWAP)] = (iw_handler) cfg80211_wext_giwap,
1479 [IW_IOCTL_IDX(SIOCSIWMLME)] = (iw_handler) cfg80211_wext_siwmlme,
1480 [IW_IOCTL_IDX(SIOCSIWSCAN)] = (iw_handler) cfg80211_wext_siwscan,
1481 [IW_IOCTL_IDX(SIOCGIWSCAN)] = (iw_handler) cfg80211_wext_giwscan,
1482 [IW_IOCTL_IDX(SIOCSIWESSID)] = (iw_handler) cfg80211_wext_siwessid,
1483 [IW_IOCTL_IDX(SIOCGIWESSID)] = (iw_handler) cfg80211_wext_giwessid,
1484 [IW_IOCTL_IDX(SIOCSIWRATE)] = (iw_handler) cfg80211_wext_siwrate,
1485 [IW_IOCTL_IDX(SIOCGIWRATE)] = (iw_handler) cfg80211_wext_giwrate,
1486 [IW_IOCTL_IDX(SIOCSIWRTS)] = (iw_handler) cfg80211_wext_siwrts,
1487 [IW_IOCTL_IDX(SIOCGIWRTS)] = (iw_handler) cfg80211_wext_giwrts,
1488 [IW_IOCTL_IDX(SIOCSIWFRAG)] = (iw_handler) cfg80211_wext_siwfrag,
1489 [IW_IOCTL_IDX(SIOCGIWFRAG)] = (iw_handler) cfg80211_wext_giwfrag,
1490 [IW_IOCTL_IDX(SIOCSIWTXPOW)] = (iw_handler) cfg80211_wext_siwtxpower,
1491 [IW_IOCTL_IDX(SIOCGIWTXPOW)] = (iw_handler) cfg80211_wext_giwtxpower,
1492 [IW_IOCTL_IDX(SIOCSIWRETRY)] = (iw_handler) cfg80211_wext_siwretry,
1493 [IW_IOCTL_IDX(SIOCGIWRETRY)] = (iw_handler) cfg80211_wext_giwretry,
1494 [IW_IOCTL_IDX(SIOCSIWENCODE)] = (iw_handler) cfg80211_wext_siwencode,
1495 [IW_IOCTL_IDX(SIOCGIWENCODE)] = (iw_handler) cfg80211_wext_giwencode,
1496 [IW_IOCTL_IDX(SIOCSIWPOWER)] = (iw_handler) cfg80211_wext_siwpower,
1497 [IW_IOCTL_IDX(SIOCGIWPOWER)] = (iw_handler) cfg80211_wext_giwpower,
1498 [IW_IOCTL_IDX(SIOCSIWGENIE)] = (iw_handler) cfg80211_wext_siwgenie,
1499 [IW_IOCTL_IDX(SIOCSIWAUTH)] = (iw_handler) cfg80211_wext_siwauth,
1500 [IW_IOCTL_IDX(SIOCGIWAUTH)] = (iw_handler) cfg80211_wext_giwauth,
1501 [IW_IOCTL_IDX(SIOCSIWENCODEEXT)]= (iw_handler) cfg80211_wext_siwencodeext,
1502 [IW_IOCTL_IDX(SIOCSIWPMKSA)] = (iw_handler) cfg80211_wext_siwpmksa,
1505 const struct iw_handler_def cfg80211_wext_handler = {
1506 .num_standard = ARRAY_SIZE(cfg80211_handlers),
1507 .standard = cfg80211_handlers,
1508 .get_wireless_stats = cfg80211_wireless_stats,