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.
8 * Copyright 2008-2009 Johannes Berg <johannes@sipsolutions.net>
11 #include <linux/wireless.h>
12 #include <linux/nl80211.h>
13 #include <linux/if_arp.h>
14 #include <linux/etherdevice.h>
15 #include <net/iw_handler.h>
16 #include <net/cfg80211.h>
17 #include "wext-compat.h"
20 int cfg80211_wext_giwname(struct net_device *dev,
21 struct iw_request_info *info,
22 char *name, char *extra)
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;
31 sband = wdev->wiphy->bands[IEEE80211_BAND_5GHZ];
34 is_ht |= sband->ht_cap.ht_supported;
37 sband = wdev->wiphy->bands[IEEE80211_BAND_2GHZ];
40 /* Check for mandatory rates */
41 for (i = 0; i < sband->n_bitrates; i++) {
42 if (sband->bitrates[i].bitrate == 10)
44 if (sband->bitrates[i].bitrate == 60)
47 is_ht |= sband->ht_cap.ht_supported;
50 strcpy(name, "IEEE 802.11");
62 EXPORT_SYMBOL_GPL(cfg80211_wext_giwname);
64 int cfg80211_wext_siwmode(struct net_device *dev, struct iw_request_info *info,
65 u32 *mode, char *extra)
67 struct wireless_dev *wdev = dev->ieee80211_ptr;
68 struct cfg80211_registered_device *rdev;
69 struct vif_params vifparams;
70 enum nl80211_iftype type;
76 rdev = wiphy_to_dev(wdev->wiphy);
78 if (!rdev->ops->change_virtual_intf)
81 /* don't support changing VLANs, you just re-create them */
82 if (wdev->iftype == NL80211_IFTYPE_AP_VLAN)
87 type = NL80211_IFTYPE_STATION;
90 type = NL80211_IFTYPE_ADHOC;
93 type = NL80211_IFTYPE_WDS;
96 type = NL80211_IFTYPE_MONITOR;
102 if (type == wdev->iftype)
105 memset(&vifparams, 0, sizeof(vifparams));
107 ret = rdev->ops->change_virtual_intf(wdev->wiphy, dev, type,
109 WARN_ON(!ret && wdev->iftype != type);
113 EXPORT_SYMBOL_GPL(cfg80211_wext_siwmode);
115 int cfg80211_wext_giwmode(struct net_device *dev, struct iw_request_info *info,
116 u32 *mode, char *extra)
118 struct wireless_dev *wdev = dev->ieee80211_ptr;
123 switch (wdev->iftype) {
124 case NL80211_IFTYPE_AP:
125 *mode = IW_MODE_MASTER;
127 case NL80211_IFTYPE_STATION:
128 *mode = IW_MODE_INFRA;
130 case NL80211_IFTYPE_ADHOC:
131 *mode = IW_MODE_ADHOC;
133 case NL80211_IFTYPE_MONITOR:
134 *mode = IW_MODE_MONITOR;
136 case NL80211_IFTYPE_WDS:
137 *mode = IW_MODE_REPEAT;
139 case NL80211_IFTYPE_AP_VLAN:
140 *mode = IW_MODE_SECOND; /* FIXME */
143 *mode = IW_MODE_AUTO;
148 EXPORT_SYMBOL_GPL(cfg80211_wext_giwmode);
151 int cfg80211_wext_giwrange(struct net_device *dev,
152 struct iw_request_info *info,
153 struct iw_point *data, char *extra)
155 struct wireless_dev *wdev = dev->ieee80211_ptr;
156 struct iw_range *range = (struct iw_range *) extra;
157 enum ieee80211_band band;
163 data->length = sizeof(struct iw_range);
164 memset(range, 0, sizeof(struct iw_range));
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;
173 range->max_rts = 2347;
174 range->min_frag = 256;
175 range->max_frag = 2346;
177 range->max_encoding_tokens = 4;
179 range->max_qual.updated = IW_QUAL_NOISE_INVALID;
181 switch (wdev->wiphy->signal_type) {
182 case CFG80211_SIGNAL_TYPE_NONE:
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;
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;
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;
205 for (i = 0; i < wdev->wiphy->n_cipher_suites; i++) {
206 switch (wdev->wiphy->cipher_suites[i]) {
207 case WLAN_CIPHER_SUITE_TKIP:
208 range->enc_capa |= (IW_ENC_CAPA_CIPHER_TKIP |
212 case WLAN_CIPHER_SUITE_CCMP:
213 range->enc_capa |= (IW_ENC_CAPA_CIPHER_CCMP |
217 case WLAN_CIPHER_SUITE_WEP40:
218 range->encoding_size[range->num_encoding_sizes++] =
222 case WLAN_CIPHER_SUITE_WEP104:
223 range->encoding_size[range->num_encoding_sizes++] =
229 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
230 struct ieee80211_supported_band *sband;
232 sband = wdev->wiphy->bands[band];
237 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
238 struct ieee80211_channel *chan = &sband->channels[i];
240 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
242 ieee80211_frequency_to_channel(
244 range->freq[c].m = chan->center_freq;
245 range->freq[c].e = 6;
250 range->num_channels = c;
251 range->num_frequency = c;
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);
257 if (wdev->wiphy->max_scan_ssids > 0)
258 range->scan_capa |= IW_SCAN_CAPA_ESSID;
262 EXPORT_SYMBOL_GPL(cfg80211_wext_giwrange);
266 * cfg80211_wext_freq - get wext frequency for non-"auto"
268 * @freq: the wext freq encoding
270 * Returns a frequency, or a negative error code, or 0 for auto.
272 int cfg80211_wext_freq(struct wiphy *wiphy, struct iw_freq *freq)
275 * Parse frequency - return 0 for auto and
276 * -EINVAL for impossible things.
281 return ieee80211_channel_to_frequency(freq->m);
283 int i, div = 1000000;
284 for (i = 0; i < freq->e; i++)
288 return freq->m / div;
292 int cfg80211_wext_siwrts(struct net_device *dev,
293 struct iw_request_info *info,
294 struct iw_param *rts, char *extra)
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;
301 if (rts->disabled || !rts->fixed)
302 wdev->wiphy->rts_threshold = (u32) -1;
303 else if (rts->value < 0)
306 wdev->wiphy->rts_threshold = rts->value;
308 err = rdev->ops->set_wiphy_params(wdev->wiphy,
309 WIPHY_PARAM_RTS_THRESHOLD);
311 wdev->wiphy->rts_threshold = orts;
315 EXPORT_SYMBOL_GPL(cfg80211_wext_siwrts);
317 int cfg80211_wext_giwrts(struct net_device *dev,
318 struct iw_request_info *info,
319 struct iw_param *rts, char *extra)
321 struct wireless_dev *wdev = dev->ieee80211_ptr;
323 rts->value = wdev->wiphy->rts_threshold;
324 rts->disabled = rts->value == (u32) -1;
329 EXPORT_SYMBOL_GPL(cfg80211_wext_giwrts);
331 int cfg80211_wext_siwfrag(struct net_device *dev,
332 struct iw_request_info *info,
333 struct iw_param *frag, char *extra)
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;
340 if (frag->disabled || !frag->fixed)
341 wdev->wiphy->frag_threshold = (u32) -1;
342 else if (frag->value < 256)
345 /* Fragment length must be even, so strip LSB. */
346 wdev->wiphy->frag_threshold = frag->value & ~0x1;
349 err = rdev->ops->set_wiphy_params(wdev->wiphy,
350 WIPHY_PARAM_FRAG_THRESHOLD);
352 wdev->wiphy->frag_threshold = ofrag;
356 EXPORT_SYMBOL_GPL(cfg80211_wext_siwfrag);
358 int cfg80211_wext_giwfrag(struct net_device *dev,
359 struct iw_request_info *info,
360 struct iw_param *frag, char *extra)
362 struct wireless_dev *wdev = dev->ieee80211_ptr;
364 frag->value = wdev->wiphy->frag_threshold;
365 frag->disabled = frag->value == (u32) -1;
370 EXPORT_SYMBOL_GPL(cfg80211_wext_giwfrag);
372 int cfg80211_wext_siwretry(struct net_device *dev,
373 struct iw_request_info *info,
374 struct iw_param *retry, char *extra)
376 struct wireless_dev *wdev = dev->ieee80211_ptr;
377 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
379 u8 olong = wdev->wiphy->retry_long;
380 u8 oshort = wdev->wiphy->retry_short;
383 if (retry->disabled ||
384 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
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;
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;
403 err = rdev->ops->set_wiphy_params(wdev->wiphy, changed);
405 wdev->wiphy->retry_short = oshort;
406 wdev->wiphy->retry_long = olong;
411 EXPORT_SYMBOL_GPL(cfg80211_wext_siwretry);
413 int cfg80211_wext_giwretry(struct net_device *dev,
414 struct iw_request_info *info,
415 struct iw_param *retry, char *extra)
417 struct wireless_dev *wdev = dev->ieee80211_ptr;
421 if (retry->flags == 0 || (retry->flags & IW_RETRY_SHORT)) {
423 * First return short value, iwconfig will ask long value
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;
434 if (retry->flags & IW_RETRY_LONG) {
435 retry->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
436 retry->value = wdev->wiphy->retry_long;
441 EXPORT_SYMBOL_GPL(cfg80211_wext_giwretry);
443 static 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)
448 struct wireless_dev *wdev = dev->ieee80211_ptr;
451 if (!wdev->wext.keys) {
452 wdev->wext.keys = kzalloc(sizeof(*wdev->wext.keys),
454 if (!wdev->wext.keys)
456 for (i = 0; i < 6; i++)
457 wdev->wext.keys->params[i].key =
458 wdev->wext.keys->data[i];
461 if (wdev->iftype != NL80211_IFTYPE_ADHOC &&
462 wdev->iftype != NL80211_IFTYPE_STATION)
465 if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
466 if (!wdev->current_bss)
469 if (!rdev->ops->set_default_mgmt_key)
472 if (idx < 4 || idx > 5)
474 } else if (idx < 0 || idx > 3)
479 if (wdev->current_bss)
480 err = rdev->ops->del_key(&rdev->wiphy, dev, idx, addr);
483 wdev->wext.keys->params[idx].key_len = 0;
484 wdev->wext.keys->params[idx].cipher = 0;
486 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;
492 * Applications using wireless extensions expect to be
493 * able to delete keys that don't exist, so allow that.
504 if (cfg80211_validate_key_settings(rdev, params, idx, addr))
508 if (wdev->current_bss)
509 err = rdev->ops->add_key(&rdev->wiphy, dev, idx, addr, params);
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];
521 if ((params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
522 params->cipher == WLAN_CIPHER_SUITE_WEP104) &&
523 (tx_key || (!addr && wdev->wext.default_key == -1))) {
524 if (wdev->current_bss)
525 err = rdev->ops->set_default_key(&rdev->wiphy,
528 wdev->wext.default_key = idx;
532 if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC &&
533 (tx_key || (!addr && wdev->wext.default_mgmt_key == -1))) {
534 if (wdev->current_bss)
535 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
538 wdev->wext.default_mgmt_key = idx;
545 static 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)
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);
560 int cfg80211_wext_siwencode(struct net_device *dev,
561 struct iw_request_info *info,
562 struct iw_point *erq, char *keybuf)
564 struct wireless_dev *wdev = dev->ieee80211_ptr;
565 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
568 struct key_params params;
570 if (wdev->iftype != NL80211_IFTYPE_STATION &&
571 wdev->iftype != NL80211_IFTYPE_ADHOC)
574 /* 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)
580 idx = erq->flags & IW_ENCODE_INDEX;
582 idx = wdev->wext.default_key;
585 } else if (idx < 1 || idx > 4)
590 if (erq->flags & IW_ENCODE_DISABLED)
592 else if (erq->length == 0) {
593 /* No key data - just set the default TX key index */
596 if (wdev->current_bss)
597 err = rdev->ops->set_default_key(&rdev->wiphy,
600 wdev->wext.default_key = idx;
605 memset(¶ms, 0, sizeof(params));
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;
615 return cfg80211_set_encryption(rdev, dev, NULL, remove,
616 wdev->wext.default_key == -1,
619 EXPORT_SYMBOL_GPL(cfg80211_wext_siwencode);
621 int cfg80211_wext_siwencodeext(struct net_device *dev,
622 struct iw_request_info *info,
623 struct iw_point *erq, char *extra)
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;
631 struct key_params params;
634 if (wdev->iftype != NL80211_IFTYPE_STATION &&
635 wdev->iftype != NL80211_IFTYPE_ADHOC)
638 /* 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)
645 case IW_ENCODE_ALG_NONE:
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;
657 case IW_ENCODE_ALG_TKIP:
658 cipher = WLAN_CIPHER_SUITE_TKIP;
660 case IW_ENCODE_ALG_CCMP:
661 cipher = WLAN_CIPHER_SUITE_CCMP;
663 case IW_ENCODE_ALG_AES_CMAC:
664 cipher = WLAN_CIPHER_SUITE_AES_CMAC;
670 if (erq->flags & IW_ENCODE_DISABLED)
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;
682 if (idx < 1 || idx > 4) {
683 idx = wdev->wext.default_key;
690 addr = ext->addr.sa_data;
691 if (is_broadcast_ether_addr(addr))
694 memset(¶ms, 0, sizeof(params));
695 params.key = ext->key;
696 params.key_len = ext->key_len;
697 params.cipher = cipher;
699 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
700 params.seq = ext->rx_seq;
704 return cfg80211_set_encryption(
705 rdev, dev, addr, remove,
706 ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
709 EXPORT_SYMBOL_GPL(cfg80211_wext_siwencodeext);
711 int cfg80211_wext_giwencode(struct net_device *dev,
712 struct iw_request_info *info,
713 struct iw_point *erq, char *keybuf)
715 struct wireless_dev *wdev = dev->ieee80211_ptr;
718 if (wdev->iftype != NL80211_IFTYPE_STATION &&
719 wdev->iftype != NL80211_IFTYPE_ADHOC)
722 idx = erq->flags & IW_ENCODE_INDEX;
724 idx = wdev->wext.default_key;
727 } else if (idx < 1 || idx > 4)
732 erq->flags = idx + 1;
734 if (!wdev->wext.keys || !wdev->wext.keys->params[idx].cipher) {
735 erq->flags |= IW_ENCODE_DISABLED;
740 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;
747 EXPORT_SYMBOL_GPL(cfg80211_wext_giwencode);
749 int cfg80211_wext_siwfreq(struct net_device *dev,
750 struct iw_request_info *info,
751 struct iw_freq *wextfreq, char *extra)
753 struct wireless_dev *wdev = dev->ieee80211_ptr;
754 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
757 switch (wdev->iftype) {
758 case NL80211_IFTYPE_STATION:
759 return cfg80211_mgd_wext_siwfreq(dev, info, wextfreq, extra);
760 case NL80211_IFTYPE_ADHOC:
761 return cfg80211_ibss_wext_siwfreq(dev, info, wextfreq, extra);
763 freq = cfg80211_wext_freq(wdev->wiphy, wextfreq);
768 mutex_lock(&rdev->devlist_mtx);
769 err = rdev_set_freq(rdev, NULL, freq, NL80211_CHAN_NO_HT);
770 mutex_unlock(&rdev->devlist_mtx);
775 int cfg80211_wext_giwfreq(struct net_device *dev,
776 struct iw_request_info *info,
777 struct iw_freq *freq, char *extra)
779 struct wireless_dev *wdev = dev->ieee80211_ptr;
780 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
782 switch (wdev->iftype) {
783 case NL80211_IFTYPE_STATION:
784 return cfg80211_mgd_wext_giwfreq(dev, info, freq, extra);
785 case NL80211_IFTYPE_ADHOC:
786 return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra);
790 freq->m = rdev->channel->center_freq;
795 EXPORT_SYMBOL_GPL(cfg80211_wext_giwfreq);
797 int cfg80211_wext_siwtxpower(struct net_device *dev,
798 struct iw_request_info *info,
799 union iwreq_data *data, char *extra)
801 struct wireless_dev *wdev = dev->ieee80211_ptr;
802 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
803 enum tx_power_setting type;
806 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
808 if (data->txpower.flags & IW_TXPOW_RANGE)
811 if (!rdev->ops->set_tx_power)
814 /* only change when not disabling */
815 if (!data->txpower.disabled) {
816 rfkill_set_sw_state(rdev->rfkill, false);
818 if (data->txpower.fixed) {
820 * wext doesn't support negative values, see
821 * below where it's for automatic
823 if (data->txpower.value < 0)
825 dbm = data->txpower.value;
826 type = TX_POWER_FIXED;
827 /* TODO: do regulatory check! */
830 * Automatic power level setting, max being the value
831 * passed in from userland.
833 if (data->txpower.value < 0) {
834 type = TX_POWER_AUTOMATIC;
836 dbm = data->txpower.value;
837 type = TX_POWER_LIMITED;
841 rfkill_set_sw_state(rdev->rfkill, true);
842 schedule_work(&rdev->rfkill_sync);
846 return rdev->ops->set_tx_power(wdev->wiphy, type, dbm);;
848 EXPORT_SYMBOL_GPL(cfg80211_wext_siwtxpower);
850 int cfg80211_wext_giwtxpower(struct net_device *dev,
851 struct iw_request_info *info,
852 union iwreq_data *data, char *extra)
854 struct wireless_dev *wdev = dev->ieee80211_ptr;
855 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
858 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
860 if (data->txpower.flags & IW_TXPOW_RANGE)
863 if (!rdev->ops->get_tx_power)
866 err = rdev->ops->get_tx_power(wdev->wiphy, &val);
870 /* well... oh well */
871 data->txpower.fixed = 1;
872 data->txpower.disabled = rfkill_blocked(rdev->rfkill);
873 data->txpower.value = val;
874 data->txpower.flags = IW_TXPOW_DBM;
878 EXPORT_SYMBOL_GPL(cfg80211_wext_giwtxpower);
880 static int cfg80211_set_auth_alg(struct wireless_dev *wdev,
888 if (auth_alg & ~(IW_AUTH_ALG_OPEN_SYSTEM |
889 IW_AUTH_ALG_SHARED_KEY |
893 if (auth_alg & IW_AUTH_ALG_OPEN_SYSTEM) {
895 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
898 if (auth_alg & IW_AUTH_ALG_SHARED_KEY) {
900 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_SHARED_KEY;
903 if (auth_alg & IW_AUTH_ALG_LEAP) {
905 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_NETWORK_EAP;
909 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
914 static int cfg80211_set_wpa_version(struct wireless_dev *wdev, u32 wpa_versions)
916 wdev->wext.connect.crypto.wpa_versions = 0;
918 if (wpa_versions & ~(IW_AUTH_WPA_VERSION_WPA |
919 IW_AUTH_WPA_VERSION_WPA2|
920 IW_AUTH_WPA_VERSION_DISABLED))
923 if ((wpa_versions & IW_AUTH_WPA_VERSION_DISABLED) &&
924 (wpa_versions & (IW_AUTH_WPA_VERSION_WPA|
925 IW_AUTH_WPA_VERSION_WPA2)))
928 if (wpa_versions & IW_AUTH_WPA_VERSION_DISABLED)
929 wdev->wext.connect.crypto.wpa_versions &=
930 ~(NL80211_WPA_VERSION_1|NL80211_WPA_VERSION_2);
932 if (wpa_versions & IW_AUTH_WPA_VERSION_WPA)
933 wdev->wext.connect.crypto.wpa_versions |=
934 NL80211_WPA_VERSION_1;
936 if (wpa_versions & IW_AUTH_WPA_VERSION_WPA2)
937 wdev->wext.connect.crypto.wpa_versions |=
938 NL80211_WPA_VERSION_2;
943 static int cfg80211_set_cipher_group(struct wireless_dev *wdev, u32 cipher)
945 wdev->wext.connect.crypto.cipher_group = 0;
947 if (cipher & IW_AUTH_CIPHER_WEP40)
948 wdev->wext.connect.crypto.cipher_group =
949 WLAN_CIPHER_SUITE_WEP40;
950 else if (cipher & IW_AUTH_CIPHER_WEP104)
951 wdev->wext.connect.crypto.cipher_group =
952 WLAN_CIPHER_SUITE_WEP104;
953 else if (cipher & IW_AUTH_CIPHER_TKIP)
954 wdev->wext.connect.crypto.cipher_group =
955 WLAN_CIPHER_SUITE_TKIP;
956 else if (cipher & IW_AUTH_CIPHER_CCMP)
957 wdev->wext.connect.crypto.cipher_group =
958 WLAN_CIPHER_SUITE_CCMP;
959 else if (cipher & IW_AUTH_CIPHER_AES_CMAC)
960 wdev->wext.connect.crypto.cipher_group =
961 WLAN_CIPHER_SUITE_AES_CMAC;
968 static int cfg80211_set_cipher_pairwise(struct wireless_dev *wdev, u32 cipher)
971 u32 *ciphers_pairwise = wdev->wext.connect.crypto.ciphers_pairwise;
973 if (cipher & IW_AUTH_CIPHER_WEP40) {
974 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP40;
978 if (cipher & IW_AUTH_CIPHER_WEP104) {
979 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP104;
983 if (cipher & IW_AUTH_CIPHER_TKIP) {
984 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_TKIP;
988 if (cipher & IW_AUTH_CIPHER_CCMP) {
989 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_CCMP;
993 if (cipher & IW_AUTH_CIPHER_AES_CMAC) {
994 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_AES_CMAC;
998 BUILD_BUG_ON(NL80211_MAX_NR_CIPHER_SUITES < 5);
1000 wdev->wext.connect.crypto.n_ciphers_pairwise = nr_ciphers;
1006 static int cfg80211_set_key_mgt(struct wireless_dev *wdev, u32 key_mgt)
1008 int nr_akm_suites = 0;
1010 if (key_mgt & ~(IW_AUTH_KEY_MGMT_802_1X |
1011 IW_AUTH_KEY_MGMT_PSK))
1014 if (key_mgt & IW_AUTH_KEY_MGMT_802_1X) {
1015 wdev->wext.connect.crypto.akm_suites[nr_akm_suites] =
1016 WLAN_AKM_SUITE_8021X;
1020 if (key_mgt & IW_AUTH_KEY_MGMT_PSK) {
1021 wdev->wext.connect.crypto.akm_suites[nr_akm_suites] =
1026 wdev->wext.connect.crypto.n_akm_suites = nr_akm_suites;
1031 int cfg80211_wext_siwauth(struct net_device *dev,
1032 struct iw_request_info *info,
1033 struct iw_param *data, char *extra)
1035 struct wireless_dev *wdev = dev->ieee80211_ptr;
1037 if (wdev->iftype != NL80211_IFTYPE_STATION)
1040 switch (data->flags & IW_AUTH_INDEX) {
1041 case IW_AUTH_PRIVACY_INVOKED:
1042 wdev->wext.connect.privacy = data->value;
1044 case IW_AUTH_WPA_VERSION:
1045 return cfg80211_set_wpa_version(wdev, data->value);
1046 case IW_AUTH_CIPHER_GROUP:
1047 return cfg80211_set_cipher_group(wdev, data->value);
1048 case IW_AUTH_KEY_MGMT:
1049 return cfg80211_set_key_mgt(wdev, data->value);
1050 case IW_AUTH_CIPHER_PAIRWISE:
1051 return cfg80211_set_cipher_pairwise(wdev, data->value);
1052 case IW_AUTH_80211_AUTH_ALG:
1053 return cfg80211_set_auth_alg(wdev, data->value);
1054 case IW_AUTH_WPA_ENABLED:
1055 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1056 case IW_AUTH_DROP_UNENCRYPTED:
1063 EXPORT_SYMBOL_GPL(cfg80211_wext_siwauth);
1065 int cfg80211_wext_giwauth(struct net_device *dev,
1066 struct iw_request_info *info,
1067 struct iw_param *data, char *extra)
1069 /* XXX: what do we need? */
1073 EXPORT_SYMBOL_GPL(cfg80211_wext_giwauth);
1075 int cfg80211_wext_siwpower(struct net_device *dev,
1076 struct iw_request_info *info,
1077 struct iw_param *wrq, char *extra)
1079 struct wireless_dev *wdev = dev->ieee80211_ptr;
1080 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1081 bool ps = wdev->wext.ps;
1082 int timeout = wdev->wext.ps_timeout;
1085 if (wdev->iftype != NL80211_IFTYPE_STATION)
1088 if (!rdev->ops->set_power_mgmt)
1091 if (wrq->disabled) {
1094 switch (wrq->flags & IW_POWER_MODE) {
1095 case IW_POWER_ON: /* If not specified */
1096 case IW_POWER_MODE: /* If set all mask */
1097 case IW_POWER_ALL_R: /* If explicitely state all */
1100 default: /* Otherwise we ignore */
1104 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
1107 if (wrq->flags & IW_POWER_TIMEOUT)
1108 timeout = wrq->value / 1000;
1111 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, ps, timeout);
1116 wdev->wext.ps_timeout = timeout;
1121 EXPORT_SYMBOL_GPL(cfg80211_wext_siwpower);
1123 int cfg80211_wext_giwpower(struct net_device *dev,
1124 struct iw_request_info *info,
1125 struct iw_param *wrq, char *extra)
1127 struct wireless_dev *wdev = dev->ieee80211_ptr;
1129 wrq->disabled = !wdev->wext.ps;
1133 EXPORT_SYMBOL_GPL(cfg80211_wext_giwpower);
1135 static int cfg80211_wds_wext_siwap(struct net_device *dev,
1136 struct iw_request_info *info,
1137 struct sockaddr *addr, char *extra)
1139 struct wireless_dev *wdev = dev->ieee80211_ptr;
1140 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1143 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS))
1146 if (addr->sa_family != ARPHRD_ETHER)
1149 if (netif_running(dev))
1152 if (!rdev->ops->set_wds_peer)
1155 err = rdev->ops->set_wds_peer(wdev->wiphy, dev, (u8 *) &addr->sa_data);
1159 memcpy(&wdev->wext.bssid, (u8 *) &addr->sa_data, ETH_ALEN);
1164 static int cfg80211_wds_wext_giwap(struct net_device *dev,
1165 struct iw_request_info *info,
1166 struct sockaddr *addr, char *extra)
1168 struct wireless_dev *wdev = dev->ieee80211_ptr;
1170 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS))
1173 addr->sa_family = ARPHRD_ETHER;
1174 memcpy(&addr->sa_data, wdev->wext.bssid, ETH_ALEN);
1179 int cfg80211_wext_siwrate(struct net_device *dev,
1180 struct iw_request_info *info,
1181 struct iw_param *rate, char *extra)
1183 struct wireless_dev *wdev = dev->ieee80211_ptr;
1184 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1185 struct cfg80211_bitrate_mask mask;
1187 if (!rdev->ops->set_bitrate_mask)
1193 if (rate->value < 0) {
1195 } else if (rate->fixed) {
1196 mask.fixed = rate->value / 1000; /* kbps */
1198 mask.maxrate = rate->value / 1000; /* kbps */
1201 return rdev->ops->set_bitrate_mask(wdev->wiphy, dev, NULL, &mask);
1203 EXPORT_SYMBOL_GPL(cfg80211_wext_siwrate);
1205 int cfg80211_wext_giwrate(struct net_device *dev,
1206 struct iw_request_info *info,
1207 struct iw_param *rate, char *extra)
1209 struct wireless_dev *wdev = dev->ieee80211_ptr;
1210 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1211 /* we are under RTNL - globally locked - so can use a static struct */
1212 static struct station_info sinfo;
1216 if (wdev->iftype != NL80211_IFTYPE_STATION)
1219 if (!rdev->ops->get_station)
1224 if (wdev->current_bss)
1225 memcpy(addr, wdev->current_bss->pub.bssid, ETH_ALEN);
1232 err = rdev->ops->get_station(&rdev->wiphy, dev, addr, &sinfo);
1236 if (!(sinfo.filled & STATION_INFO_TX_BITRATE))
1241 if (!(sinfo.txrate.flags & RATE_INFO_FLAGS_MCS))
1242 rate->value = 100000 * sinfo.txrate.legacy;
1246 EXPORT_SYMBOL_GPL(cfg80211_wext_giwrate);
1248 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
1249 struct iw_statistics *cfg80211_wireless_stats(struct net_device *dev)
1251 struct wireless_dev *wdev = dev->ieee80211_ptr;
1252 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1253 /* we are under RTNL - globally locked - so can use static structs */
1254 static struct iw_statistics wstats;
1255 static struct station_info sinfo;
1258 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION)
1261 if (!rdev->ops->get_station)
1264 /* Grab BSSID of current BSS, if any */
1266 if (!wdev->current_bss) {
1270 memcpy(bssid, wdev->current_bss->pub.bssid, ETH_ALEN);
1273 if (rdev->ops->get_station(&rdev->wiphy, dev, bssid, &sinfo))
1276 memset(&wstats, 0, sizeof(wstats));
1278 switch (rdev->wiphy.signal_type) {
1279 case CFG80211_SIGNAL_TYPE_MBM:
1280 if (sinfo.filled & STATION_INFO_SIGNAL) {
1281 int sig = sinfo.signal;
1282 wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
1283 wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
1284 wstats.qual.updated |= IW_QUAL_DBM;
1285 wstats.qual.level = sig;
1290 wstats.qual.qual = sig + 110;
1293 case CFG80211_SIGNAL_TYPE_UNSPEC:
1294 if (sinfo.filled & STATION_INFO_SIGNAL) {
1295 wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
1296 wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
1297 wstats.qual.level = sinfo.signal;
1298 wstats.qual.qual = sinfo.signal;
1302 wstats.qual.updated |= IW_QUAL_LEVEL_INVALID;
1303 wstats.qual.updated |= IW_QUAL_QUAL_INVALID;
1306 wstats.qual.updated |= IW_QUAL_NOISE_INVALID;
1310 EXPORT_SYMBOL_GPL(cfg80211_wireless_stats);
1312 int cfg80211_wext_siwap(struct net_device *dev,
1313 struct iw_request_info *info,
1314 struct sockaddr *ap_addr, char *extra)
1316 struct wireless_dev *wdev = dev->ieee80211_ptr;
1318 switch (wdev->iftype) {
1319 case NL80211_IFTYPE_ADHOC:
1320 return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra);
1321 case NL80211_IFTYPE_STATION:
1322 return cfg80211_mgd_wext_siwap(dev, info, ap_addr, extra);
1323 case NL80211_IFTYPE_WDS:
1324 return cfg80211_wds_wext_siwap(dev, info, ap_addr, extra);
1329 EXPORT_SYMBOL_GPL(cfg80211_wext_siwap);
1331 int cfg80211_wext_giwap(struct net_device *dev,
1332 struct iw_request_info *info,
1333 struct sockaddr *ap_addr, char *extra)
1335 struct wireless_dev *wdev = dev->ieee80211_ptr;
1337 switch (wdev->iftype) {
1338 case NL80211_IFTYPE_ADHOC:
1339 return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra);
1340 case NL80211_IFTYPE_STATION:
1341 return cfg80211_mgd_wext_giwap(dev, info, ap_addr, extra);
1342 case NL80211_IFTYPE_WDS:
1343 return cfg80211_wds_wext_giwap(dev, info, ap_addr, extra);
1348 EXPORT_SYMBOL_GPL(cfg80211_wext_giwap);
1350 int cfg80211_wext_siwessid(struct net_device *dev,
1351 struct iw_request_info *info,
1352 struct iw_point *data, char *ssid)
1354 struct wireless_dev *wdev = dev->ieee80211_ptr;
1356 switch (wdev->iftype) {
1357 case NL80211_IFTYPE_ADHOC:
1358 return cfg80211_ibss_wext_siwessid(dev, info, data, ssid);
1359 case NL80211_IFTYPE_STATION:
1360 return cfg80211_mgd_wext_siwessid(dev, info, data, ssid);
1365 EXPORT_SYMBOL_GPL(cfg80211_wext_siwessid);
1367 int cfg80211_wext_giwessid(struct net_device *dev,
1368 struct iw_request_info *info,
1369 struct iw_point *data, char *ssid)
1371 struct wireless_dev *wdev = dev->ieee80211_ptr;
1373 switch (wdev->iftype) {
1374 case NL80211_IFTYPE_ADHOC:
1375 return cfg80211_ibss_wext_giwessid(dev, info, data, ssid);
1376 case NL80211_IFTYPE_STATION:
1377 return cfg80211_mgd_wext_giwessid(dev, info, data, ssid);
1382 EXPORT_SYMBOL_GPL(cfg80211_wext_giwessid);
1384 static const iw_handler cfg80211_handlers[] = {
1385 [IW_IOCTL_IDX(SIOCGIWNAME)] = (iw_handler) cfg80211_wext_giwname,
1386 [IW_IOCTL_IDX(SIOCSIWFREQ)] = (iw_handler) cfg80211_wext_siwfreq,
1387 [IW_IOCTL_IDX(SIOCGIWFREQ)] = (iw_handler) cfg80211_wext_giwfreq,
1388 [IW_IOCTL_IDX(SIOCSIWMODE)] = (iw_handler) cfg80211_wext_siwmode,
1389 [IW_IOCTL_IDX(SIOCGIWMODE)] = (iw_handler) cfg80211_wext_giwmode,
1390 [IW_IOCTL_IDX(SIOCGIWRANGE)] = (iw_handler) cfg80211_wext_giwrange,
1391 [IW_IOCTL_IDX(SIOCSIWAP)] = (iw_handler) cfg80211_wext_siwap,
1392 [IW_IOCTL_IDX(SIOCGIWAP)] = (iw_handler) cfg80211_wext_giwap,
1393 [IW_IOCTL_IDX(SIOCSIWMLME)] = (iw_handler) cfg80211_wext_siwmlme,
1394 [IW_IOCTL_IDX(SIOCSIWSCAN)] = (iw_handler) cfg80211_wext_siwscan,
1395 [IW_IOCTL_IDX(SIOCGIWSCAN)] = (iw_handler) cfg80211_wext_giwscan,
1396 [IW_IOCTL_IDX(SIOCSIWESSID)] = (iw_handler) cfg80211_wext_siwessid,
1397 [IW_IOCTL_IDX(SIOCGIWESSID)] = (iw_handler) cfg80211_wext_giwessid,
1398 [IW_IOCTL_IDX(SIOCSIWRATE)] = (iw_handler) cfg80211_wext_siwrate,
1399 [IW_IOCTL_IDX(SIOCGIWRATE)] = (iw_handler) cfg80211_wext_giwrate,
1400 [IW_IOCTL_IDX(SIOCSIWRTS)] = (iw_handler) cfg80211_wext_siwrts,
1401 [IW_IOCTL_IDX(SIOCGIWRTS)] = (iw_handler) cfg80211_wext_giwrts,
1402 [IW_IOCTL_IDX(SIOCSIWFRAG)] = (iw_handler) cfg80211_wext_siwfrag,
1403 [IW_IOCTL_IDX(SIOCGIWFRAG)] = (iw_handler) cfg80211_wext_giwfrag,
1404 [IW_IOCTL_IDX(SIOCSIWTXPOW)] = (iw_handler) cfg80211_wext_siwtxpower,
1405 [IW_IOCTL_IDX(SIOCGIWTXPOW)] = (iw_handler) cfg80211_wext_giwtxpower,
1406 [IW_IOCTL_IDX(SIOCSIWRETRY)] = (iw_handler) cfg80211_wext_siwretry,
1407 [IW_IOCTL_IDX(SIOCGIWRETRY)] = (iw_handler) cfg80211_wext_giwretry,
1408 [IW_IOCTL_IDX(SIOCSIWENCODE)] = (iw_handler) cfg80211_wext_siwencode,
1409 [IW_IOCTL_IDX(SIOCGIWENCODE)] = (iw_handler) cfg80211_wext_giwencode,
1410 [IW_IOCTL_IDX(SIOCSIWPOWER)] = (iw_handler) cfg80211_wext_siwpower,
1411 [IW_IOCTL_IDX(SIOCGIWPOWER)] = (iw_handler) cfg80211_wext_giwpower,
1412 [IW_IOCTL_IDX(SIOCSIWGENIE)] = (iw_handler) cfg80211_wext_siwgenie,
1413 [IW_IOCTL_IDX(SIOCSIWAUTH)] = (iw_handler) cfg80211_wext_siwauth,
1414 [IW_IOCTL_IDX(SIOCGIWAUTH)] = (iw_handler) cfg80211_wext_giwauth,
1415 [IW_IOCTL_IDX(SIOCSIWENCODEEXT)]= (iw_handler) cfg80211_wext_siwencodeext,
1418 const struct iw_handler_def cfg80211_wext_handler = {
1419 .num_standard = ARRAY_SIZE(cfg80211_handlers),
1420 .standard = cfg80211_handlers,
1421 .get_wireless_stats = cfg80211_wireless_stats,