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>
19 int cfg80211_wext_giwname(struct net_device *dev,
20 struct iw_request_info *info,
21 char *name, char *extra)
23 struct wireless_dev *wdev = dev->ieee80211_ptr;
24 struct ieee80211_supported_band *sband;
25 bool is_ht = false, is_a = false, is_b = false, is_g = false;
30 sband = wdev->wiphy->bands[IEEE80211_BAND_5GHZ];
33 is_ht |= sband->ht_cap.ht_supported;
36 sband = wdev->wiphy->bands[IEEE80211_BAND_2GHZ];
39 /* Check for mandatory rates */
40 for (i = 0; i < sband->n_bitrates; i++) {
41 if (sband->bitrates[i].bitrate == 10)
43 if (sband->bitrates[i].bitrate == 60)
46 is_ht |= sband->ht_cap.ht_supported;
49 strcpy(name, "IEEE 802.11");
61 EXPORT_SYMBOL_GPL(cfg80211_wext_giwname);
63 int cfg80211_wext_siwmode(struct net_device *dev, struct iw_request_info *info,
64 u32 *mode, char *extra)
66 struct wireless_dev *wdev = dev->ieee80211_ptr;
67 struct cfg80211_registered_device *rdev;
68 struct vif_params vifparams;
69 enum nl80211_iftype type;
75 rdev = wiphy_to_dev(wdev->wiphy);
77 if (!rdev->ops->change_virtual_intf)
80 /* don't support changing VLANs, you just re-create them */
81 if (wdev->iftype == NL80211_IFTYPE_AP_VLAN)
86 type = NL80211_IFTYPE_STATION;
89 type = NL80211_IFTYPE_ADHOC;
92 type = NL80211_IFTYPE_WDS;
95 type = NL80211_IFTYPE_MONITOR;
101 if (type == wdev->iftype)
104 memset(&vifparams, 0, sizeof(vifparams));
106 ret = rdev->ops->change_virtual_intf(wdev->wiphy, dev, type,
108 WARN_ON(!ret && wdev->iftype != type);
112 EXPORT_SYMBOL_GPL(cfg80211_wext_siwmode);
114 int cfg80211_wext_giwmode(struct net_device *dev, struct iw_request_info *info,
115 u32 *mode, char *extra)
117 struct wireless_dev *wdev = dev->ieee80211_ptr;
122 switch (wdev->iftype) {
123 case NL80211_IFTYPE_AP:
124 *mode = IW_MODE_MASTER;
126 case NL80211_IFTYPE_STATION:
127 *mode = IW_MODE_INFRA;
129 case NL80211_IFTYPE_ADHOC:
130 *mode = IW_MODE_ADHOC;
132 case NL80211_IFTYPE_MONITOR:
133 *mode = IW_MODE_MONITOR;
135 case NL80211_IFTYPE_WDS:
136 *mode = IW_MODE_REPEAT;
138 case NL80211_IFTYPE_AP_VLAN:
139 *mode = IW_MODE_SECOND; /* FIXME */
142 *mode = IW_MODE_AUTO;
147 EXPORT_SYMBOL_GPL(cfg80211_wext_giwmode);
150 int cfg80211_wext_giwrange(struct net_device *dev,
151 struct iw_request_info *info,
152 struct iw_point *data, char *extra)
154 struct wireless_dev *wdev = dev->ieee80211_ptr;
155 struct iw_range *range = (struct iw_range *) extra;
156 enum ieee80211_band band;
162 data->length = sizeof(struct iw_range);
163 memset(range, 0, sizeof(struct iw_range));
165 range->we_version_compiled = WIRELESS_EXT;
166 range->we_version_source = 21;
167 range->retry_capa = IW_RETRY_LIMIT;
168 range->retry_flags = IW_RETRY_LIMIT;
169 range->min_retry = 0;
170 range->max_retry = 255;
172 range->max_rts = 2347;
173 range->min_frag = 256;
174 range->max_frag = 2346;
176 range->max_encoding_tokens = 4;
178 range->max_qual.updated = IW_QUAL_NOISE_INVALID;
180 switch (wdev->wiphy->signal_type) {
181 case CFG80211_SIGNAL_TYPE_NONE:
183 case CFG80211_SIGNAL_TYPE_MBM:
184 range->max_qual.level = -110;
185 range->max_qual.qual = 70;
186 range->avg_qual.qual = 35;
187 range->max_qual.updated |= IW_QUAL_DBM;
188 range->max_qual.updated |= IW_QUAL_QUAL_UPDATED;
189 range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED;
191 case CFG80211_SIGNAL_TYPE_UNSPEC:
192 range->max_qual.level = 100;
193 range->max_qual.qual = 100;
194 range->avg_qual.qual = 50;
195 range->max_qual.updated |= IW_QUAL_QUAL_UPDATED;
196 range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED;
200 range->avg_qual.level = range->max_qual.level / 2;
201 range->avg_qual.noise = range->max_qual.noise / 2;
202 range->avg_qual.updated = range->max_qual.updated;
204 for (i = 0; i < wdev->wiphy->n_cipher_suites; i++) {
205 switch (wdev->wiphy->cipher_suites[i]) {
206 case WLAN_CIPHER_SUITE_TKIP:
207 range->enc_capa |= (IW_ENC_CAPA_CIPHER_TKIP |
211 case WLAN_CIPHER_SUITE_CCMP:
212 range->enc_capa |= (IW_ENC_CAPA_CIPHER_CCMP |
216 case WLAN_CIPHER_SUITE_WEP40:
217 range->encoding_size[range->num_encoding_sizes++] =
221 case WLAN_CIPHER_SUITE_WEP104:
222 range->encoding_size[range->num_encoding_sizes++] =
228 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
229 struct ieee80211_supported_band *sband;
231 sband = wdev->wiphy->bands[band];
236 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
237 struct ieee80211_channel *chan = &sband->channels[i];
239 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
241 ieee80211_frequency_to_channel(
243 range->freq[c].m = chan->center_freq;
244 range->freq[c].e = 6;
249 range->num_channels = c;
250 range->num_frequency = c;
252 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
253 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
254 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
256 if (wdev->wiphy->max_scan_ssids > 0)
257 range->scan_capa |= IW_SCAN_CAPA_ESSID;
261 EXPORT_SYMBOL_GPL(cfg80211_wext_giwrange);
265 * cfg80211_wext_freq - get wext frequency for non-"auto"
267 * @freq: the wext freq encoding
269 * Returns a channel, %NULL for auto, or an ERR_PTR for errors!
271 struct ieee80211_channel *cfg80211_wext_freq(struct wiphy *wiphy,
272 struct iw_freq *freq)
274 struct ieee80211_channel *chan;
278 * Parse frequency - return NULL for auto and
279 * -EINVAL for impossible things.
284 f = ieee80211_channel_to_frequency(freq->m);
286 int i, div = 1000000;
287 for (i = 0; i < freq->e; i++)
290 return ERR_PTR(-EINVAL);
295 * Look up channel struct and return -EINVAL when
296 * it cannot be found.
298 chan = ieee80211_get_channel(wiphy, f);
300 return ERR_PTR(-EINVAL);
303 EXPORT_SYMBOL_GPL(cfg80211_wext_freq);
305 int cfg80211_wext_siwrts(struct net_device *dev,
306 struct iw_request_info *info,
307 struct iw_param *rts, char *extra)
309 struct wireless_dev *wdev = dev->ieee80211_ptr;
310 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
311 u32 orts = wdev->wiphy->rts_threshold;
314 if (rts->disabled || !rts->fixed)
315 wdev->wiphy->rts_threshold = (u32) -1;
316 else if (rts->value < 0)
319 wdev->wiphy->rts_threshold = rts->value;
321 err = rdev->ops->set_wiphy_params(wdev->wiphy,
322 WIPHY_PARAM_RTS_THRESHOLD);
324 wdev->wiphy->rts_threshold = orts;
328 EXPORT_SYMBOL_GPL(cfg80211_wext_siwrts);
330 int cfg80211_wext_giwrts(struct net_device *dev,
331 struct iw_request_info *info,
332 struct iw_param *rts, char *extra)
334 struct wireless_dev *wdev = dev->ieee80211_ptr;
336 rts->value = wdev->wiphy->rts_threshold;
337 rts->disabled = rts->value == (u32) -1;
342 EXPORT_SYMBOL_GPL(cfg80211_wext_giwrts);
344 int cfg80211_wext_siwfrag(struct net_device *dev,
345 struct iw_request_info *info,
346 struct iw_param *frag, char *extra)
348 struct wireless_dev *wdev = dev->ieee80211_ptr;
349 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
350 u32 ofrag = wdev->wiphy->frag_threshold;
353 if (frag->disabled || !frag->fixed)
354 wdev->wiphy->frag_threshold = (u32) -1;
355 else if (frag->value < 256)
358 /* Fragment length must be even, so strip LSB. */
359 wdev->wiphy->frag_threshold = frag->value & ~0x1;
362 err = rdev->ops->set_wiphy_params(wdev->wiphy,
363 WIPHY_PARAM_FRAG_THRESHOLD);
365 wdev->wiphy->frag_threshold = ofrag;
369 EXPORT_SYMBOL_GPL(cfg80211_wext_siwfrag);
371 int cfg80211_wext_giwfrag(struct net_device *dev,
372 struct iw_request_info *info,
373 struct iw_param *frag, char *extra)
375 struct wireless_dev *wdev = dev->ieee80211_ptr;
377 frag->value = wdev->wiphy->frag_threshold;
378 frag->disabled = frag->value == (u32) -1;
383 EXPORT_SYMBOL_GPL(cfg80211_wext_giwfrag);
385 int cfg80211_wext_siwretry(struct net_device *dev,
386 struct iw_request_info *info,
387 struct iw_param *retry, char *extra)
389 struct wireless_dev *wdev = dev->ieee80211_ptr;
390 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
392 u8 olong = wdev->wiphy->retry_long;
393 u8 oshort = wdev->wiphy->retry_short;
396 if (retry->disabled ||
397 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
400 if (retry->flags & IW_RETRY_LONG) {
401 wdev->wiphy->retry_long = retry->value;
402 changed |= WIPHY_PARAM_RETRY_LONG;
403 } else if (retry->flags & IW_RETRY_SHORT) {
404 wdev->wiphy->retry_short = retry->value;
405 changed |= WIPHY_PARAM_RETRY_SHORT;
407 wdev->wiphy->retry_short = retry->value;
408 wdev->wiphy->retry_long = retry->value;
409 changed |= WIPHY_PARAM_RETRY_LONG;
410 changed |= WIPHY_PARAM_RETRY_SHORT;
416 err = rdev->ops->set_wiphy_params(wdev->wiphy, changed);
418 wdev->wiphy->retry_short = oshort;
419 wdev->wiphy->retry_long = olong;
424 EXPORT_SYMBOL_GPL(cfg80211_wext_siwretry);
426 int cfg80211_wext_giwretry(struct net_device *dev,
427 struct iw_request_info *info,
428 struct iw_param *retry, char *extra)
430 struct wireless_dev *wdev = dev->ieee80211_ptr;
434 if (retry->flags == 0 || (retry->flags & IW_RETRY_SHORT)) {
436 * First return short value, iwconfig will ask long value
439 retry->flags |= IW_RETRY_LIMIT;
440 retry->value = wdev->wiphy->retry_short;
441 if (wdev->wiphy->retry_long != wdev->wiphy->retry_short)
442 retry->flags |= IW_RETRY_LONG;
447 if (retry->flags & IW_RETRY_LONG) {
448 retry->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
449 retry->value = wdev->wiphy->retry_long;
454 EXPORT_SYMBOL_GPL(cfg80211_wext_giwretry);
456 static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
457 struct net_device *dev, const u8 *addr,
458 bool remove, bool tx_key, int idx,
459 struct key_params *params)
461 struct wireless_dev *wdev = dev->ieee80211_ptr;
464 if (!wdev->wext.keys) {
465 wdev->wext.keys = kzalloc(sizeof(*wdev->wext.keys),
467 if (!wdev->wext.keys)
469 for (i = 0; i < 6; i++)
470 wdev->wext.keys->params[i].key =
471 wdev->wext.keys->data[i];
474 if (wdev->iftype != NL80211_IFTYPE_ADHOC &&
475 wdev->iftype != NL80211_IFTYPE_STATION)
478 if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
479 if (!wdev->current_bss)
482 if (!rdev->ops->set_default_mgmt_key)
485 if (idx < 4 || idx > 5)
487 } else if (idx < 0 || idx > 3)
492 if (wdev->current_bss)
493 err = rdev->ops->del_key(&rdev->wiphy, dev, idx, addr);
496 wdev->wext.keys->params[idx].key_len = 0;
497 wdev->wext.keys->params[idx].cipher = 0;
499 if (idx == wdev->wext.default_key)
500 wdev->wext.default_key = -1;
501 else if (idx == wdev->wext.default_mgmt_key)
502 wdev->wext.default_mgmt_key = -1;
505 * Applications using wireless extensions expect to be
506 * able to delete keys that don't exist, so allow that.
517 if (cfg80211_validate_key_settings(rdev, params, idx, addr))
521 if (wdev->current_bss)
522 err = rdev->ops->add_key(&rdev->wiphy, dev, idx, addr, params);
527 wdev->wext.keys->params[idx] = *params;
528 memcpy(wdev->wext.keys->data[idx],
529 params->key, params->key_len);
530 wdev->wext.keys->params[idx].key =
531 wdev->wext.keys->data[idx];
534 if (params->cipher != WLAN_CIPHER_SUITE_AES_CMAC &&
535 (tx_key || (!addr && wdev->wext.default_key == -1))) {
536 if (wdev->current_bss)
537 err = rdev->ops->set_default_key(&rdev->wiphy,
540 wdev->wext.default_key = idx;
544 if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC &&
545 (tx_key || (!addr && wdev->wext.default_mgmt_key == -1))) {
546 if (wdev->current_bss)
547 err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
550 wdev->wext.default_mgmt_key = idx;
557 static int cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
558 struct net_device *dev, const u8 *addr,
559 bool remove, bool tx_key, int idx,
560 struct key_params *params)
564 wdev_lock(dev->ieee80211_ptr);
565 err = __cfg80211_set_encryption(rdev, dev, addr, remove,
566 tx_key, idx, params);
567 wdev_unlock(dev->ieee80211_ptr);
572 int cfg80211_wext_siwencode(struct net_device *dev,
573 struct iw_request_info *info,
574 struct iw_point *erq, char *keybuf)
576 struct wireless_dev *wdev = dev->ieee80211_ptr;
577 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
580 struct key_params params;
582 if (wdev->iftype != NL80211_IFTYPE_STATION &&
583 wdev->iftype != NL80211_IFTYPE_ADHOC)
586 /* no use -- only MFP (set_default_mgmt_key) is optional */
587 if (!rdev->ops->del_key ||
588 !rdev->ops->add_key ||
589 !rdev->ops->set_default_key)
592 idx = erq->flags & IW_ENCODE_INDEX;
594 idx = wdev->wext.default_key;
597 } else if (idx < 1 || idx > 4)
602 if (erq->flags & IW_ENCODE_DISABLED)
604 else if (erq->length == 0) {
605 /* No key data - just set the default TX key index */
608 if (wdev->current_bss)
609 err = rdev->ops->set_default_key(&rdev->wiphy,
612 wdev->wext.default_key = idx;
617 memset(¶ms, 0, sizeof(params));
619 params.key_len = erq->length;
620 if (erq->length == 5)
621 params.cipher = WLAN_CIPHER_SUITE_WEP40;
622 else if (erq->length == 13)
623 params.cipher = WLAN_CIPHER_SUITE_WEP104;
627 return cfg80211_set_encryption(rdev, dev, NULL, remove,
628 wdev->wext.default_key == -1,
631 EXPORT_SYMBOL_GPL(cfg80211_wext_siwencode);
633 int cfg80211_wext_siwencodeext(struct net_device *dev,
634 struct iw_request_info *info,
635 struct iw_point *erq, char *extra)
637 struct wireless_dev *wdev = dev->ieee80211_ptr;
638 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
639 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
643 struct key_params params;
646 if (wdev->iftype != NL80211_IFTYPE_STATION &&
647 wdev->iftype != NL80211_IFTYPE_ADHOC)
650 /* no use -- only MFP (set_default_mgmt_key) is optional */
651 if (!rdev->ops->del_key ||
652 !rdev->ops->add_key ||
653 !rdev->ops->set_default_key)
657 case IW_ENCODE_ALG_NONE:
661 case IW_ENCODE_ALG_WEP:
662 if (ext->key_len == 5)
663 cipher = WLAN_CIPHER_SUITE_WEP40;
664 else if (ext->key_len == 13)
665 cipher = WLAN_CIPHER_SUITE_WEP104;
669 case IW_ENCODE_ALG_TKIP:
670 cipher = WLAN_CIPHER_SUITE_TKIP;
672 case IW_ENCODE_ALG_CCMP:
673 cipher = WLAN_CIPHER_SUITE_CCMP;
675 case IW_ENCODE_ALG_AES_CMAC:
676 cipher = WLAN_CIPHER_SUITE_AES_CMAC;
682 if (erq->flags & IW_ENCODE_DISABLED)
685 idx = erq->flags & IW_ENCODE_INDEX;
686 if (cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
687 if (idx < 4 || idx > 5) {
688 idx = wdev->wext.default_mgmt_key;
694 if (idx < 1 || idx > 4) {
695 idx = wdev->wext.default_key;
702 addr = ext->addr.sa_data;
703 if (is_broadcast_ether_addr(addr))
706 memset(¶ms, 0, sizeof(params));
707 params.key = ext->key;
708 params.key_len = ext->key_len;
709 params.cipher = cipher;
711 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
712 params.seq = ext->rx_seq;
716 return cfg80211_set_encryption(
717 rdev, dev, addr, remove,
718 ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
721 EXPORT_SYMBOL_GPL(cfg80211_wext_siwencodeext);
723 int cfg80211_wext_giwencode(struct net_device *dev,
724 struct iw_request_info *info,
725 struct iw_point *erq, char *keybuf)
727 struct wireless_dev *wdev = dev->ieee80211_ptr;
730 if (wdev->iftype != NL80211_IFTYPE_STATION &&
731 wdev->iftype != NL80211_IFTYPE_ADHOC)
734 idx = erq->flags & IW_ENCODE_INDEX;
736 idx = wdev->wext.default_key;
739 } else if (idx < 1 || idx > 4)
744 erq->flags = idx + 1;
746 if (!wdev->wext.keys || !wdev->wext.keys->params[idx].cipher) {
747 erq->flags |= IW_ENCODE_DISABLED;
752 erq->length = min_t(size_t, erq->length,
753 wdev->wext.keys->params[idx].key_len);
754 memcpy(keybuf, wdev->wext.keys->params[idx].key, erq->length);
755 erq->flags |= IW_ENCODE_ENABLED;
759 EXPORT_SYMBOL_GPL(cfg80211_wext_giwencode);
761 int cfg80211_wext_siwtxpower(struct net_device *dev,
762 struct iw_request_info *info,
763 union iwreq_data *data, char *extra)
765 struct wireless_dev *wdev = dev->ieee80211_ptr;
766 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
767 enum tx_power_setting type;
770 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
772 if (data->txpower.flags & IW_TXPOW_RANGE)
775 if (!rdev->ops->set_tx_power)
778 /* only change when not disabling */
779 if (!data->txpower.disabled) {
780 rfkill_set_sw_state(rdev->rfkill, false);
782 if (data->txpower.fixed) {
784 * wext doesn't support negative values, see
785 * below where it's for automatic
787 if (data->txpower.value < 0)
789 dbm = data->txpower.value;
790 type = TX_POWER_FIXED;
791 /* TODO: do regulatory check! */
794 * Automatic power level setting, max being the value
795 * passed in from userland.
797 if (data->txpower.value < 0) {
798 type = TX_POWER_AUTOMATIC;
800 dbm = data->txpower.value;
801 type = TX_POWER_LIMITED;
805 rfkill_set_sw_state(rdev->rfkill, true);
806 schedule_work(&rdev->rfkill_sync);
810 return rdev->ops->set_tx_power(wdev->wiphy, type, dbm);;
812 EXPORT_SYMBOL_GPL(cfg80211_wext_siwtxpower);
814 int cfg80211_wext_giwtxpower(struct net_device *dev,
815 struct iw_request_info *info,
816 union iwreq_data *data, char *extra)
818 struct wireless_dev *wdev = dev->ieee80211_ptr;
819 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
822 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
824 if (data->txpower.flags & IW_TXPOW_RANGE)
827 if (!rdev->ops->get_tx_power)
830 err = rdev->ops->get_tx_power(wdev->wiphy, &val);
834 /* well... oh well */
835 data->txpower.fixed = 1;
836 data->txpower.disabled = rfkill_blocked(rdev->rfkill);
837 data->txpower.value = val;
838 data->txpower.flags = IW_TXPOW_DBM;
842 EXPORT_SYMBOL_GPL(cfg80211_wext_giwtxpower);
844 static int cfg80211_set_auth_alg(struct wireless_dev *wdev,
852 if (auth_alg & ~(IW_AUTH_ALG_OPEN_SYSTEM |
853 IW_AUTH_ALG_SHARED_KEY |
857 if (auth_alg & IW_AUTH_ALG_OPEN_SYSTEM) {
859 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
862 if (auth_alg & IW_AUTH_ALG_SHARED_KEY) {
864 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_SHARED_KEY;
867 if (auth_alg & IW_AUTH_ALG_LEAP) {
869 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_NETWORK_EAP;
873 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
878 static int cfg80211_set_wpa_version(struct wireless_dev *wdev, u32 wpa_versions)
880 wdev->wext.connect.crypto.wpa_versions = 0;
882 if (wpa_versions & ~(IW_AUTH_WPA_VERSION_WPA |
883 IW_AUTH_WPA_VERSION_WPA2))
886 if (wpa_versions & IW_AUTH_WPA_VERSION_WPA)
887 wdev->wext.connect.crypto.wpa_versions |=
888 NL80211_WPA_VERSION_1;
890 if (wpa_versions & IW_AUTH_WPA_VERSION_WPA2)
891 wdev->wext.connect.crypto.wpa_versions |=
892 NL80211_WPA_VERSION_2;
897 static int cfg80211_set_cipher_group(struct wireless_dev *wdev, u32 cipher)
899 wdev->wext.connect.crypto.cipher_group = 0;
901 if (cipher & IW_AUTH_CIPHER_WEP40)
902 wdev->wext.connect.crypto.cipher_group =
903 WLAN_CIPHER_SUITE_WEP40;
904 else if (cipher & IW_AUTH_CIPHER_WEP104)
905 wdev->wext.connect.crypto.cipher_group =
906 WLAN_CIPHER_SUITE_WEP104;
907 else if (cipher & IW_AUTH_CIPHER_TKIP)
908 wdev->wext.connect.crypto.cipher_group =
909 WLAN_CIPHER_SUITE_TKIP;
910 else if (cipher & IW_AUTH_CIPHER_CCMP)
911 wdev->wext.connect.crypto.cipher_group =
912 WLAN_CIPHER_SUITE_CCMP;
913 else if (cipher & IW_AUTH_CIPHER_AES_CMAC)
914 wdev->wext.connect.crypto.cipher_group =
915 WLAN_CIPHER_SUITE_AES_CMAC;
922 static int cfg80211_set_cipher_pairwise(struct wireless_dev *wdev, u32 cipher)
925 u32 *ciphers_pairwise = wdev->wext.connect.crypto.ciphers_pairwise;
927 if (cipher & IW_AUTH_CIPHER_WEP40) {
928 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP40;
932 if (cipher & IW_AUTH_CIPHER_WEP104) {
933 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP104;
937 if (cipher & IW_AUTH_CIPHER_TKIP) {
938 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_TKIP;
942 if (cipher & IW_AUTH_CIPHER_CCMP) {
943 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_CCMP;
947 if (cipher & IW_AUTH_CIPHER_AES_CMAC) {
948 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_AES_CMAC;
952 BUILD_BUG_ON(NL80211_MAX_NR_CIPHER_SUITES < 5);
954 wdev->wext.connect.crypto.n_ciphers_pairwise = nr_ciphers;
960 static int cfg80211_set_key_mgt(struct wireless_dev *wdev, u32 key_mgt)
962 int nr_akm_suites = 0;
964 if (key_mgt & ~(IW_AUTH_KEY_MGMT_802_1X |
965 IW_AUTH_KEY_MGMT_PSK))
968 if (key_mgt & IW_AUTH_KEY_MGMT_802_1X) {
969 wdev->wext.connect.crypto.akm_suites[nr_akm_suites] =
970 WLAN_AKM_SUITE_8021X;
974 if (key_mgt & IW_AUTH_KEY_MGMT_PSK) {
975 wdev->wext.connect.crypto.akm_suites[nr_akm_suites] =
980 wdev->wext.connect.crypto.n_akm_suites = nr_akm_suites;
985 int cfg80211_wext_siwauth(struct net_device *dev,
986 struct iw_request_info *info,
987 struct iw_param *data, char *extra)
989 struct wireless_dev *wdev = dev->ieee80211_ptr;
991 if (wdev->iftype != NL80211_IFTYPE_STATION)
994 switch (data->flags & IW_AUTH_INDEX) {
995 case IW_AUTH_PRIVACY_INVOKED:
996 wdev->wext.connect.privacy = data->value;
998 case IW_AUTH_WPA_VERSION:
999 return cfg80211_set_wpa_version(wdev, data->value);
1000 case IW_AUTH_CIPHER_GROUP:
1001 return cfg80211_set_cipher_group(wdev, data->value);
1002 case IW_AUTH_KEY_MGMT:
1003 return cfg80211_set_key_mgt(wdev, data->value);
1004 case IW_AUTH_CIPHER_PAIRWISE:
1005 return cfg80211_set_cipher_pairwise(wdev, data->value);
1006 case IW_AUTH_80211_AUTH_ALG:
1007 return cfg80211_set_auth_alg(wdev, data->value);
1008 case IW_AUTH_WPA_ENABLED:
1009 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1010 case IW_AUTH_DROP_UNENCRYPTED:
1017 EXPORT_SYMBOL_GPL(cfg80211_wext_siwauth);
1019 int cfg80211_wext_giwauth(struct net_device *dev,
1020 struct iw_request_info *info,
1021 struct iw_param *data, char *extra)
1023 /* XXX: what do we need? */
1027 EXPORT_SYMBOL_GPL(cfg80211_wext_giwauth);
1029 int cfg80211_wext_siwpower(struct net_device *dev,
1030 struct iw_request_info *info,
1031 struct iw_param *wrq, char *extra)
1033 struct wireless_dev *wdev = dev->ieee80211_ptr;
1034 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1035 bool ps = wdev->wext.ps;
1036 int timeout = wdev->wext.ps_timeout;
1039 if (wdev->iftype != NL80211_IFTYPE_STATION)
1042 if (!rdev->ops->set_power_mgmt)
1045 if (wrq->disabled) {
1048 switch (wrq->flags & IW_POWER_MODE) {
1049 case IW_POWER_ON: /* If not specified */
1050 case IW_POWER_MODE: /* If set all mask */
1051 case IW_POWER_ALL_R: /* If explicitely state all */
1054 default: /* Otherwise we ignore */
1058 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
1061 if (wrq->flags & IW_POWER_TIMEOUT)
1062 timeout = wrq->value / 1000;
1065 err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, ps, timeout);
1070 wdev->wext.ps_timeout = timeout;
1075 EXPORT_SYMBOL_GPL(cfg80211_wext_siwpower);
1077 int cfg80211_wext_giwpower(struct net_device *dev,
1078 struct iw_request_info *info,
1079 struct iw_param *wrq, char *extra)
1081 struct wireless_dev *wdev = dev->ieee80211_ptr;
1083 wrq->disabled = !wdev->wext.ps;
1087 EXPORT_SYMBOL_GPL(cfg80211_wext_giwpower);
1089 int cfg80211_wds_wext_siwap(struct net_device *dev,
1090 struct iw_request_info *info,
1091 struct sockaddr *addr, char *extra)
1093 struct wireless_dev *wdev = dev->ieee80211_ptr;
1094 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1097 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS))
1100 if (addr->sa_family != ARPHRD_ETHER)
1103 if (netif_running(dev))
1106 if (!rdev->ops->set_wds_peer)
1109 err = rdev->ops->set_wds_peer(wdev->wiphy, dev, (u8 *) &addr->sa_data);
1113 memcpy(&wdev->wext.bssid, (u8 *) &addr->sa_data, ETH_ALEN);
1117 EXPORT_SYMBOL_GPL(cfg80211_wds_wext_siwap);
1119 int cfg80211_wds_wext_giwap(struct net_device *dev,
1120 struct iw_request_info *info,
1121 struct sockaddr *addr, char *extra)
1123 struct wireless_dev *wdev = dev->ieee80211_ptr;
1125 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS))
1128 addr->sa_family = ARPHRD_ETHER;
1129 memcpy(&addr->sa_data, wdev->wext.bssid, ETH_ALEN);
1133 EXPORT_SYMBOL_GPL(cfg80211_wds_wext_giwap);
1135 int cfg80211_wext_siwrate(struct net_device *dev,
1136 struct iw_request_info *info,
1137 struct iw_param *rate, char *extra)
1139 struct wireless_dev *wdev = dev->ieee80211_ptr;
1140 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1141 struct cfg80211_bitrate_mask mask;
1143 if (!rdev->ops->set_bitrate_mask)
1149 if (rate->value < 0) {
1151 } else if (rate->fixed) {
1152 mask.fixed = rate->value / 1000; /* kbps */
1154 mask.maxrate = rate->value / 1000; /* kbps */
1157 return rdev->ops->set_bitrate_mask(wdev->wiphy, dev, NULL, &mask);
1159 EXPORT_SYMBOL_GPL(cfg80211_wext_siwrate);
1161 int cfg80211_wext_giwrate(struct net_device *dev,
1162 struct iw_request_info *info,
1163 struct iw_param *rate, char *extra)
1165 struct wireless_dev *wdev = dev->ieee80211_ptr;
1166 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1167 /* we are under RTNL - globally locked - so can use a static struct */
1168 static struct station_info sinfo;
1172 if (wdev->iftype != NL80211_IFTYPE_STATION)
1175 if (!rdev->ops->get_station)
1180 if (wdev->current_bss)
1181 memcpy(addr, wdev->current_bss->pub.bssid, ETH_ALEN);
1188 err = rdev->ops->get_station(&rdev->wiphy, dev, addr, &sinfo);
1192 if (!(sinfo.filled & STATION_INFO_TX_BITRATE))
1197 if (!(sinfo.txrate.flags & RATE_INFO_FLAGS_MCS))
1198 rate->value = 100000 * sinfo.txrate.legacy;
1202 EXPORT_SYMBOL_GPL(cfg80211_wext_giwrate);
1204 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
1205 struct iw_statistics *cfg80211_wireless_stats(struct net_device *dev)
1207 struct wireless_dev *wdev = dev->ieee80211_ptr;
1208 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1209 /* we are under RTNL - globally locked - so can use static structs */
1210 static struct iw_statistics wstats;
1211 static struct station_info sinfo;
1214 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION)
1217 if (!rdev->ops->get_station)
1220 addr = wdev->wext.connect.bssid;
1224 if (rdev->ops->get_station(&rdev->wiphy, dev, addr, &sinfo))
1227 memset(&wstats, 0, sizeof(wstats));
1229 switch (rdev->wiphy.signal_type) {
1230 case CFG80211_SIGNAL_TYPE_MBM:
1231 if (sinfo.filled & STATION_INFO_SIGNAL) {
1232 int sig = sinfo.signal;
1233 wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
1234 wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
1235 wstats.qual.updated |= IW_QUAL_DBM;
1236 wstats.qual.level = sig;
1241 wstats.qual.qual = sig + 110;
1244 case CFG80211_SIGNAL_TYPE_UNSPEC:
1245 if (sinfo.filled & STATION_INFO_SIGNAL) {
1246 wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
1247 wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
1248 wstats.qual.level = sinfo.signal;
1249 wstats.qual.qual = sinfo.signal;
1253 wstats.qual.updated |= IW_QUAL_LEVEL_INVALID;
1254 wstats.qual.updated |= IW_QUAL_QUAL_INVALID;
1257 wstats.qual.updated |= IW_QUAL_NOISE_INVALID;
1261 EXPORT_SYMBOL_GPL(cfg80211_wireless_stats);