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/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)
409 if (!wdev->wext.keys) {
410 wdev->wext.keys = kzalloc(sizeof(*wdev->wext.keys),
412 if (!wdev->wext.keys)
414 for (i = 0; i < 6; i++)
415 wdev->wext.keys->params[i].key =
416 wdev->wext.keys->data[i];
419 if (wdev->iftype != NL80211_IFTYPE_ADHOC &&
420 wdev->iftype != NL80211_IFTYPE_STATION)
423 if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
424 if (!wdev->current_bss)
427 if (!rdev->ops->set_default_mgmt_key)
430 if (idx < 4 || idx > 5)
432 } else if (idx < 0 || idx > 3)
437 if (wdev->current_bss) {
439 * If removing the current TX key, we will need to
440 * join a new IBSS without the privacy bit clear.
442 if (idx == wdev->wext.default_key &&
443 wdev->iftype == NL80211_IFTYPE_ADHOC) {
444 __cfg80211_leave_ibss(rdev, wdev->netdev, true);
448 if (!pairwise && addr &&
449 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
452 err = rdev_del_key(rdev, dev, idx, pairwise,
455 wdev->wext.connect.privacy = false;
457 * Applications using wireless extensions expect to be
458 * able to delete keys that don't exist, so allow that.
464 memset(wdev->wext.keys->data[idx], 0,
465 sizeof(wdev->wext.keys->data[idx]));
466 wdev->wext.keys->params[idx].key_len = 0;
467 wdev->wext.keys->params[idx].cipher = 0;
469 if (idx == wdev->wext.default_key)
470 wdev->wext.default_key = -1;
471 else if (idx == wdev->wext.default_mgmt_key)
472 wdev->wext.default_mgmt_key = -1;
476 err = cfg80211_ibss_wext_join(rdev, wdev);
484 if (cfg80211_validate_key_settings(rdev, params, idx, pairwise, addr))
488 if (wdev->current_bss)
489 err = rdev_add_key(rdev, dev, idx, pairwise, addr, params);
490 else if (params->cipher != WLAN_CIPHER_SUITE_WEP40 &&
491 params->cipher != WLAN_CIPHER_SUITE_WEP104)
497 wdev->wext.keys->params[idx] = *params;
498 memcpy(wdev->wext.keys->data[idx],
499 params->key, params->key_len);
500 wdev->wext.keys->params[idx].key =
501 wdev->wext.keys->data[idx];
504 if ((params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
505 params->cipher == WLAN_CIPHER_SUITE_WEP104) &&
506 (tx_key || (!addr && wdev->wext.default_key == -1))) {
507 if (wdev->current_bss) {
509 * If we are getting a new TX key from not having
510 * had one before we need to join a new IBSS with
511 * the privacy bit set.
513 if (wdev->iftype == NL80211_IFTYPE_ADHOC &&
514 wdev->wext.default_key == -1) {
515 __cfg80211_leave_ibss(rdev, wdev->netdev, true);
518 err = rdev_set_default_key(rdev, dev, idx, true, true);
521 wdev->wext.default_key = idx;
523 err = cfg80211_ibss_wext_join(rdev, wdev);
528 if (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC &&
529 (tx_key || (!addr && wdev->wext.default_mgmt_key == -1))) {
530 if (wdev->current_bss)
531 err = rdev_set_default_mgmt_key(rdev, dev, idx);
533 wdev->wext.default_mgmt_key = idx;
540 static int cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
541 struct net_device *dev, bool pairwise,
542 const u8 *addr, bool remove, bool tx_key,
543 int idx, struct key_params *params)
547 wdev_lock(dev->ieee80211_ptr);
548 err = __cfg80211_set_encryption(rdev, dev, pairwise, addr,
549 remove, tx_key, idx, params);
550 wdev_unlock(dev->ieee80211_ptr);
555 static int cfg80211_wext_siwencode(struct net_device *dev,
556 struct iw_request_info *info,
557 struct iw_point *erq, char *keybuf)
559 struct wireless_dev *wdev = dev->ieee80211_ptr;
560 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
563 struct key_params params;
565 if (wdev->iftype != NL80211_IFTYPE_STATION &&
566 wdev->iftype != NL80211_IFTYPE_ADHOC)
569 /* no use -- only MFP (set_default_mgmt_key) is optional */
570 if (!rdev->ops->del_key ||
571 !rdev->ops->add_key ||
572 !rdev->ops->set_default_key)
575 idx = erq->flags & IW_ENCODE_INDEX;
577 idx = wdev->wext.default_key;
580 } else if (idx < 1 || idx > 4)
585 if (erq->flags & IW_ENCODE_DISABLED)
587 else if (erq->length == 0) {
588 /* No key data - just set the default TX key index */
591 if (wdev->current_bss)
592 err = rdev_set_default_key(rdev, dev, idx, true,
595 wdev->wext.default_key = idx;
600 memset(¶ms, 0, sizeof(params));
602 params.key_len = erq->length;
603 if (erq->length == 5)
604 params.cipher = WLAN_CIPHER_SUITE_WEP40;
605 else if (erq->length == 13)
606 params.cipher = WLAN_CIPHER_SUITE_WEP104;
610 return cfg80211_set_encryption(rdev, dev, false, NULL, remove,
611 wdev->wext.default_key == -1,
615 static int cfg80211_wext_siwencodeext(struct net_device *dev,
616 struct iw_request_info *info,
617 struct iw_point *erq, char *extra)
619 struct wireless_dev *wdev = dev->ieee80211_ptr;
620 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
621 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
625 struct key_params params;
628 if (wdev->iftype != NL80211_IFTYPE_STATION &&
629 wdev->iftype != NL80211_IFTYPE_ADHOC)
632 /* no use -- only MFP (set_default_mgmt_key) is optional */
633 if (!rdev->ops->del_key ||
634 !rdev->ops->add_key ||
635 !rdev->ops->set_default_key)
639 case IW_ENCODE_ALG_NONE:
643 case IW_ENCODE_ALG_WEP:
644 if (ext->key_len == 5)
645 cipher = WLAN_CIPHER_SUITE_WEP40;
646 else if (ext->key_len == 13)
647 cipher = WLAN_CIPHER_SUITE_WEP104;
651 case IW_ENCODE_ALG_TKIP:
652 cipher = WLAN_CIPHER_SUITE_TKIP;
654 case IW_ENCODE_ALG_CCMP:
655 cipher = WLAN_CIPHER_SUITE_CCMP;
657 case IW_ENCODE_ALG_AES_CMAC:
658 cipher = WLAN_CIPHER_SUITE_AES_CMAC;
664 if (erq->flags & IW_ENCODE_DISABLED)
667 idx = erq->flags & IW_ENCODE_INDEX;
668 if (cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
669 if (idx < 4 || idx > 5) {
670 idx = wdev->wext.default_mgmt_key;
676 if (idx < 1 || idx > 4) {
677 idx = wdev->wext.default_key;
684 addr = ext->addr.sa_data;
685 if (is_broadcast_ether_addr(addr))
688 memset(¶ms, 0, sizeof(params));
689 params.key = ext->key;
690 params.key_len = ext->key_len;
691 params.cipher = cipher;
693 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
694 params.seq = ext->rx_seq;
698 return cfg80211_set_encryption(
700 !(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY),
702 ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
706 static int cfg80211_wext_giwencode(struct net_device *dev,
707 struct iw_request_info *info,
708 struct iw_point *erq, char *keybuf)
710 struct wireless_dev *wdev = dev->ieee80211_ptr;
713 if (wdev->iftype != NL80211_IFTYPE_STATION &&
714 wdev->iftype != NL80211_IFTYPE_ADHOC)
717 idx = erq->flags & IW_ENCODE_INDEX;
719 idx = wdev->wext.default_key;
722 } else if (idx < 1 || idx > 4)
727 erq->flags = idx + 1;
729 if (!wdev->wext.keys || !wdev->wext.keys->params[idx].cipher) {
730 erq->flags |= IW_ENCODE_DISABLED;
735 erq->length = min_t(size_t, erq->length,
736 wdev->wext.keys->params[idx].key_len);
737 memcpy(keybuf, wdev->wext.keys->params[idx].key, erq->length);
738 erq->flags |= IW_ENCODE_ENABLED;
743 static int cfg80211_wext_siwfreq(struct net_device *dev,
744 struct iw_request_info *info,
745 struct iw_freq *wextfreq, char *extra)
747 struct wireless_dev *wdev = dev->ieee80211_ptr;
748 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
749 struct cfg80211_chan_def chandef = {
750 .width = NL80211_CHAN_WIDTH_20_NOHT,
754 switch (wdev->iftype) {
755 case NL80211_IFTYPE_STATION:
756 return cfg80211_mgd_wext_siwfreq(dev, info, wextfreq, extra);
757 case NL80211_IFTYPE_ADHOC:
758 return cfg80211_ibss_wext_siwfreq(dev, info, wextfreq, extra);
759 case NL80211_IFTYPE_MONITOR:
760 freq = cfg80211_wext_freq(wextfreq);
765 chandef.center_freq1 = freq;
766 chandef.chan = ieee80211_get_channel(&rdev->wiphy, freq);
769 return cfg80211_set_monitor_channel(rdev, &chandef);
770 case NL80211_IFTYPE_MESH_POINT:
771 freq = cfg80211_wext_freq(wextfreq);
776 chandef.center_freq1 = freq;
777 chandef.chan = ieee80211_get_channel(&rdev->wiphy, freq);
780 return cfg80211_set_mesh_channel(rdev, wdev, &chandef);
786 static int cfg80211_wext_giwfreq(struct net_device *dev,
787 struct iw_request_info *info,
788 struct iw_freq *freq, char *extra)
790 struct wireless_dev *wdev = dev->ieee80211_ptr;
791 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
792 struct cfg80211_chan_def chandef;
795 switch (wdev->iftype) {
796 case NL80211_IFTYPE_STATION:
797 return cfg80211_mgd_wext_giwfreq(dev, info, freq, extra);
798 case NL80211_IFTYPE_ADHOC:
799 return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra);
800 case NL80211_IFTYPE_MONITOR:
801 if (!rdev->ops->get_channel)
804 ret = rdev_get_channel(rdev, wdev, &chandef);
807 freq->m = chandef.chan->center_freq;
815 static int cfg80211_wext_siwtxpower(struct net_device *dev,
816 struct iw_request_info *info,
817 union iwreq_data *data, char *extra)
819 struct wireless_dev *wdev = dev->ieee80211_ptr;
820 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
821 enum nl80211_tx_power_setting type;
824 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
826 if (data->txpower.flags & IW_TXPOW_RANGE)
829 if (!rdev->ops->set_tx_power)
832 /* only change when not disabling */
833 if (!data->txpower.disabled) {
834 rfkill_set_sw_state(rdev->rfkill, false);
836 if (data->txpower.fixed) {
838 * wext doesn't support negative values, see
839 * below where it's for automatic
841 if (data->txpower.value < 0)
843 dbm = data->txpower.value;
844 type = NL80211_TX_POWER_FIXED;
845 /* TODO: do regulatory check! */
848 * Automatic power level setting, max being the value
849 * passed in from userland.
851 if (data->txpower.value < 0) {
852 type = NL80211_TX_POWER_AUTOMATIC;
854 dbm = data->txpower.value;
855 type = NL80211_TX_POWER_LIMITED;
859 rfkill_set_sw_state(rdev->rfkill, true);
860 schedule_work(&rdev->rfkill_sync);
864 return rdev_set_tx_power(rdev, wdev, type, DBM_TO_MBM(dbm));
867 static int cfg80211_wext_giwtxpower(struct net_device *dev,
868 struct iw_request_info *info,
869 union iwreq_data *data, char *extra)
871 struct wireless_dev *wdev = dev->ieee80211_ptr;
872 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
875 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
877 if (data->txpower.flags & IW_TXPOW_RANGE)
880 if (!rdev->ops->get_tx_power)
883 err = rdev_get_tx_power(rdev, wdev, &val);
887 /* well... oh well */
888 data->txpower.fixed = 1;
889 data->txpower.disabled = rfkill_blocked(rdev->rfkill);
890 data->txpower.value = val;
891 data->txpower.flags = IW_TXPOW_DBM;
896 static int cfg80211_set_auth_alg(struct wireless_dev *wdev,
904 if (auth_alg & ~(IW_AUTH_ALG_OPEN_SYSTEM |
905 IW_AUTH_ALG_SHARED_KEY |
909 if (auth_alg & IW_AUTH_ALG_OPEN_SYSTEM) {
911 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
914 if (auth_alg & IW_AUTH_ALG_SHARED_KEY) {
916 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_SHARED_KEY;
919 if (auth_alg & IW_AUTH_ALG_LEAP) {
921 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_NETWORK_EAP;
925 wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
930 static int cfg80211_set_wpa_version(struct wireless_dev *wdev, u32 wpa_versions)
932 if (wpa_versions & ~(IW_AUTH_WPA_VERSION_WPA |
933 IW_AUTH_WPA_VERSION_WPA2|
934 IW_AUTH_WPA_VERSION_DISABLED))
937 if ((wpa_versions & IW_AUTH_WPA_VERSION_DISABLED) &&
938 (wpa_versions & (IW_AUTH_WPA_VERSION_WPA|
939 IW_AUTH_WPA_VERSION_WPA2)))
942 if (wpa_versions & IW_AUTH_WPA_VERSION_DISABLED)
943 wdev->wext.connect.crypto.wpa_versions &=
944 ~(NL80211_WPA_VERSION_1|NL80211_WPA_VERSION_2);
946 if (wpa_versions & IW_AUTH_WPA_VERSION_WPA)
947 wdev->wext.connect.crypto.wpa_versions |=
948 NL80211_WPA_VERSION_1;
950 if (wpa_versions & IW_AUTH_WPA_VERSION_WPA2)
951 wdev->wext.connect.crypto.wpa_versions |=
952 NL80211_WPA_VERSION_2;
957 static int cfg80211_set_cipher_group(struct wireless_dev *wdev, u32 cipher)
959 if (cipher & IW_AUTH_CIPHER_WEP40)
960 wdev->wext.connect.crypto.cipher_group =
961 WLAN_CIPHER_SUITE_WEP40;
962 else if (cipher & IW_AUTH_CIPHER_WEP104)
963 wdev->wext.connect.crypto.cipher_group =
964 WLAN_CIPHER_SUITE_WEP104;
965 else if (cipher & IW_AUTH_CIPHER_TKIP)
966 wdev->wext.connect.crypto.cipher_group =
967 WLAN_CIPHER_SUITE_TKIP;
968 else if (cipher & IW_AUTH_CIPHER_CCMP)
969 wdev->wext.connect.crypto.cipher_group =
970 WLAN_CIPHER_SUITE_CCMP;
971 else if (cipher & IW_AUTH_CIPHER_AES_CMAC)
972 wdev->wext.connect.crypto.cipher_group =
973 WLAN_CIPHER_SUITE_AES_CMAC;
974 else if (cipher & IW_AUTH_CIPHER_NONE)
975 wdev->wext.connect.crypto.cipher_group = 0;
982 static int cfg80211_set_cipher_pairwise(struct wireless_dev *wdev, u32 cipher)
985 u32 *ciphers_pairwise = wdev->wext.connect.crypto.ciphers_pairwise;
987 if (cipher & IW_AUTH_CIPHER_WEP40) {
988 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP40;
992 if (cipher & IW_AUTH_CIPHER_WEP104) {
993 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_WEP104;
997 if (cipher & IW_AUTH_CIPHER_TKIP) {
998 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_TKIP;
1002 if (cipher & IW_AUTH_CIPHER_CCMP) {
1003 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_CCMP;
1007 if (cipher & IW_AUTH_CIPHER_AES_CMAC) {
1008 ciphers_pairwise[nr_ciphers] = WLAN_CIPHER_SUITE_AES_CMAC;
1012 BUILD_BUG_ON(NL80211_MAX_NR_CIPHER_SUITES < 5);
1014 wdev->wext.connect.crypto.n_ciphers_pairwise = nr_ciphers;
1020 static int cfg80211_set_key_mgt(struct wireless_dev *wdev, u32 key_mgt)
1022 int nr_akm_suites = 0;
1024 if (key_mgt & ~(IW_AUTH_KEY_MGMT_802_1X |
1025 IW_AUTH_KEY_MGMT_PSK))
1028 if (key_mgt & IW_AUTH_KEY_MGMT_802_1X) {
1029 wdev->wext.connect.crypto.akm_suites[nr_akm_suites] =
1030 WLAN_AKM_SUITE_8021X;
1034 if (key_mgt & IW_AUTH_KEY_MGMT_PSK) {
1035 wdev->wext.connect.crypto.akm_suites[nr_akm_suites] =
1040 wdev->wext.connect.crypto.n_akm_suites = nr_akm_suites;
1045 static int cfg80211_wext_siwauth(struct net_device *dev,
1046 struct iw_request_info *info,
1047 struct iw_param *data, char *extra)
1049 struct wireless_dev *wdev = dev->ieee80211_ptr;
1051 if (wdev->iftype != NL80211_IFTYPE_STATION)
1054 switch (data->flags & IW_AUTH_INDEX) {
1055 case IW_AUTH_PRIVACY_INVOKED:
1056 wdev->wext.connect.privacy = data->value;
1058 case IW_AUTH_WPA_VERSION:
1059 return cfg80211_set_wpa_version(wdev, data->value);
1060 case IW_AUTH_CIPHER_GROUP:
1061 return cfg80211_set_cipher_group(wdev, data->value);
1062 case IW_AUTH_KEY_MGMT:
1063 return cfg80211_set_key_mgt(wdev, data->value);
1064 case IW_AUTH_CIPHER_PAIRWISE:
1065 return cfg80211_set_cipher_pairwise(wdev, data->value);
1066 case IW_AUTH_80211_AUTH_ALG:
1067 return cfg80211_set_auth_alg(wdev, data->value);
1068 case IW_AUTH_WPA_ENABLED:
1069 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1070 case IW_AUTH_DROP_UNENCRYPTED:
1078 static int cfg80211_wext_giwauth(struct net_device *dev,
1079 struct iw_request_info *info,
1080 struct iw_param *data, char *extra)
1082 /* XXX: what do we need? */
1087 static int cfg80211_wext_siwpower(struct net_device *dev,
1088 struct iw_request_info *info,
1089 struct iw_param *wrq, char *extra)
1091 struct wireless_dev *wdev = dev->ieee80211_ptr;
1092 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
1094 int timeout = wdev->ps_timeout;
1097 if (wdev->iftype != NL80211_IFTYPE_STATION)
1100 if (!rdev->ops->set_power_mgmt)
1103 if (wrq->disabled) {
1106 switch (wrq->flags & IW_POWER_MODE) {
1107 case IW_POWER_ON: /* If not specified */
1108 case IW_POWER_MODE: /* If set all mask */
1109 case IW_POWER_ALL_R: /* If explicitely state all */
1112 default: /* Otherwise we ignore */
1116 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
1119 if (wrq->flags & IW_POWER_TIMEOUT)
1120 timeout = wrq->value / 1000;
1123 err = rdev_set_power_mgmt(rdev, dev, ps, timeout);
1128 wdev->ps_timeout = timeout;
1134 static int cfg80211_wext_giwpower(struct net_device *dev,
1135 struct iw_request_info *info,
1136 struct iw_param *wrq, char *extra)
1138 struct wireless_dev *wdev = dev->ieee80211_ptr;
1140 wrq->disabled = !wdev->ps;
1145 static int cfg80211_wds_wext_siwap(struct net_device *dev,
1146 struct iw_request_info *info,
1147 struct sockaddr *addr, char *extra)
1149 struct wireless_dev *wdev = dev->ieee80211_ptr;
1150 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
1153 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS))
1156 if (addr->sa_family != ARPHRD_ETHER)
1159 if (netif_running(dev))
1162 if (!rdev->ops->set_wds_peer)
1165 err = rdev_set_wds_peer(rdev, dev, (u8 *)&addr->sa_data);
1169 memcpy(&wdev->wext.bssid, (u8 *) &addr->sa_data, ETH_ALEN);
1174 static int cfg80211_wds_wext_giwap(struct net_device *dev,
1175 struct iw_request_info *info,
1176 struct sockaddr *addr, char *extra)
1178 struct wireless_dev *wdev = dev->ieee80211_ptr;
1180 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_WDS))
1183 addr->sa_family = ARPHRD_ETHER;
1184 memcpy(&addr->sa_data, wdev->wext.bssid, ETH_ALEN);
1189 static int cfg80211_wext_siwrate(struct net_device *dev,
1190 struct iw_request_info *info,
1191 struct iw_param *rate, char *extra)
1193 struct wireless_dev *wdev = dev->ieee80211_ptr;
1194 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
1195 struct cfg80211_bitrate_mask mask;
1197 struct ieee80211_supported_band *sband;
1201 if (!rdev->ops->set_bitrate_mask)
1204 memset(&mask, 0, sizeof(mask));
1208 if (rate->value < 0) {
1210 } else if (rate->fixed) {
1211 fixed = rate->value / 100000;
1213 maxrate = rate->value / 100000;
1216 for (band = 0; band < NUM_NL80211_BANDS; band++) {
1217 sband = wdev->wiphy->bands[band];
1220 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
1221 struct ieee80211_rate *srate = &sband->bitrates[ridx];
1222 if (fixed == srate->bitrate) {
1223 mask.control[band].legacy = 1 << ridx;
1227 if (srate->bitrate <= maxrate) {
1228 mask.control[band].legacy |= 1 << ridx;
1237 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
1240 static int cfg80211_wext_giwrate(struct net_device *dev,
1241 struct iw_request_info *info,
1242 struct iw_param *rate, char *extra)
1244 struct wireless_dev *wdev = dev->ieee80211_ptr;
1245 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
1246 /* we are under RTNL - globally locked - so can use a static struct */
1247 static struct station_info sinfo;
1251 if (wdev->iftype != NL80211_IFTYPE_STATION)
1254 if (!rdev->ops->get_station)
1259 if (wdev->current_bss)
1260 memcpy(addr, wdev->current_bss->pub.bssid, ETH_ALEN);
1267 err = rdev_get_station(rdev, dev, addr, &sinfo);
1271 if (!(sinfo.filled & BIT(NL80211_STA_INFO_TX_BITRATE)))
1274 rate->value = 100000 * cfg80211_calculate_bitrate(&sinfo.txrate);
1279 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
1280 static struct iw_statistics *cfg80211_wireless_stats(struct net_device *dev)
1282 struct wireless_dev *wdev = dev->ieee80211_ptr;
1283 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
1284 /* we are under RTNL - globally locked - so can use static structs */
1285 static struct iw_statistics wstats;
1286 static struct station_info sinfo;
1289 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION)
1292 if (!rdev->ops->get_station)
1295 /* Grab BSSID of current BSS, if any */
1297 if (!wdev->current_bss) {
1301 memcpy(bssid, wdev->current_bss->pub.bssid, ETH_ALEN);
1304 memset(&sinfo, 0, sizeof(sinfo));
1306 if (rdev_get_station(rdev, dev, bssid, &sinfo))
1309 memset(&wstats, 0, sizeof(wstats));
1311 switch (rdev->wiphy.signal_type) {
1312 case CFG80211_SIGNAL_TYPE_MBM:
1313 if (sinfo.filled & BIT(NL80211_STA_INFO_SIGNAL)) {
1314 int sig = sinfo.signal;
1315 wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
1316 wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
1317 wstats.qual.updated |= IW_QUAL_DBM;
1318 wstats.qual.level = sig;
1323 wstats.qual.qual = sig + 110;
1326 case CFG80211_SIGNAL_TYPE_UNSPEC:
1327 if (sinfo.filled & BIT(NL80211_STA_INFO_SIGNAL)) {
1328 wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
1329 wstats.qual.updated |= IW_QUAL_QUAL_UPDATED;
1330 wstats.qual.level = sinfo.signal;
1331 wstats.qual.qual = sinfo.signal;
1335 wstats.qual.updated |= IW_QUAL_LEVEL_INVALID;
1336 wstats.qual.updated |= IW_QUAL_QUAL_INVALID;
1339 wstats.qual.updated |= IW_QUAL_NOISE_INVALID;
1340 if (sinfo.filled & BIT(NL80211_STA_INFO_RX_DROP_MISC))
1341 wstats.discard.misc = sinfo.rx_dropped_misc;
1342 if (sinfo.filled & BIT(NL80211_STA_INFO_TX_FAILED))
1343 wstats.discard.retries = sinfo.tx_failed;
1348 static int cfg80211_wext_siwap(struct net_device *dev,
1349 struct iw_request_info *info,
1350 struct sockaddr *ap_addr, char *extra)
1352 struct wireless_dev *wdev = dev->ieee80211_ptr;
1354 switch (wdev->iftype) {
1355 case NL80211_IFTYPE_ADHOC:
1356 return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra);
1357 case NL80211_IFTYPE_STATION:
1358 return cfg80211_mgd_wext_siwap(dev, info, ap_addr, extra);
1359 case NL80211_IFTYPE_WDS:
1360 return cfg80211_wds_wext_siwap(dev, info, ap_addr, extra);
1366 static int cfg80211_wext_giwap(struct net_device *dev,
1367 struct iw_request_info *info,
1368 struct sockaddr *ap_addr, char *extra)
1370 struct wireless_dev *wdev = dev->ieee80211_ptr;
1372 switch (wdev->iftype) {
1373 case NL80211_IFTYPE_ADHOC:
1374 return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra);
1375 case NL80211_IFTYPE_STATION:
1376 return cfg80211_mgd_wext_giwap(dev, info, ap_addr, extra);
1377 case NL80211_IFTYPE_WDS:
1378 return cfg80211_wds_wext_giwap(dev, info, ap_addr, extra);
1384 static int cfg80211_wext_siwessid(struct net_device *dev,
1385 struct iw_request_info *info,
1386 struct iw_point *data, char *ssid)
1388 struct wireless_dev *wdev = dev->ieee80211_ptr;
1390 switch (wdev->iftype) {
1391 case NL80211_IFTYPE_ADHOC:
1392 return cfg80211_ibss_wext_siwessid(dev, info, data, ssid);
1393 case NL80211_IFTYPE_STATION:
1394 return cfg80211_mgd_wext_siwessid(dev, info, data, ssid);
1400 static int cfg80211_wext_giwessid(struct net_device *dev,
1401 struct iw_request_info *info,
1402 struct iw_point *data, char *ssid)
1404 struct wireless_dev *wdev = dev->ieee80211_ptr;
1409 switch (wdev->iftype) {
1410 case NL80211_IFTYPE_ADHOC:
1411 return cfg80211_ibss_wext_giwessid(dev, info, data, ssid);
1412 case NL80211_IFTYPE_STATION:
1413 return cfg80211_mgd_wext_giwessid(dev, info, data, ssid);
1419 static int cfg80211_wext_siwpmksa(struct net_device *dev,
1420 struct iw_request_info *info,
1421 struct iw_point *data, char *extra)
1423 struct wireless_dev *wdev = dev->ieee80211_ptr;
1424 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
1425 struct cfg80211_pmksa cfg_pmksa;
1426 struct iw_pmksa *pmksa = (struct iw_pmksa *)extra;
1428 memset(&cfg_pmksa, 0, sizeof(struct cfg80211_pmksa));
1430 if (wdev->iftype != NL80211_IFTYPE_STATION)
1433 cfg_pmksa.bssid = pmksa->bssid.sa_data;
1434 cfg_pmksa.pmkid = pmksa->pmkid;
1436 switch (pmksa->cmd) {
1438 if (!rdev->ops->set_pmksa)
1441 return rdev_set_pmksa(rdev, dev, &cfg_pmksa);
1443 case IW_PMKSA_REMOVE:
1444 if (!rdev->ops->del_pmksa)
1447 return rdev_del_pmksa(rdev, dev, &cfg_pmksa);
1449 case IW_PMKSA_FLUSH:
1450 if (!rdev->ops->flush_pmksa)
1453 return rdev_flush_pmksa(rdev, dev);
1460 static const iw_handler cfg80211_handlers[] = {
1461 [IW_IOCTL_IDX(SIOCGIWNAME)] = (iw_handler) cfg80211_wext_giwname,
1462 [IW_IOCTL_IDX(SIOCSIWFREQ)] = (iw_handler) cfg80211_wext_siwfreq,
1463 [IW_IOCTL_IDX(SIOCGIWFREQ)] = (iw_handler) cfg80211_wext_giwfreq,
1464 [IW_IOCTL_IDX(SIOCSIWMODE)] = (iw_handler) cfg80211_wext_siwmode,
1465 [IW_IOCTL_IDX(SIOCGIWMODE)] = (iw_handler) cfg80211_wext_giwmode,
1466 [IW_IOCTL_IDX(SIOCGIWRANGE)] = (iw_handler) cfg80211_wext_giwrange,
1467 [IW_IOCTL_IDX(SIOCSIWAP)] = (iw_handler) cfg80211_wext_siwap,
1468 [IW_IOCTL_IDX(SIOCGIWAP)] = (iw_handler) cfg80211_wext_giwap,
1469 [IW_IOCTL_IDX(SIOCSIWMLME)] = (iw_handler) cfg80211_wext_siwmlme,
1470 [IW_IOCTL_IDX(SIOCSIWSCAN)] = (iw_handler) cfg80211_wext_siwscan,
1471 [IW_IOCTL_IDX(SIOCGIWSCAN)] = (iw_handler) cfg80211_wext_giwscan,
1472 [IW_IOCTL_IDX(SIOCSIWESSID)] = (iw_handler) cfg80211_wext_siwessid,
1473 [IW_IOCTL_IDX(SIOCGIWESSID)] = (iw_handler) cfg80211_wext_giwessid,
1474 [IW_IOCTL_IDX(SIOCSIWRATE)] = (iw_handler) cfg80211_wext_siwrate,
1475 [IW_IOCTL_IDX(SIOCGIWRATE)] = (iw_handler) cfg80211_wext_giwrate,
1476 [IW_IOCTL_IDX(SIOCSIWRTS)] = (iw_handler) cfg80211_wext_siwrts,
1477 [IW_IOCTL_IDX(SIOCGIWRTS)] = (iw_handler) cfg80211_wext_giwrts,
1478 [IW_IOCTL_IDX(SIOCSIWFRAG)] = (iw_handler) cfg80211_wext_siwfrag,
1479 [IW_IOCTL_IDX(SIOCGIWFRAG)] = (iw_handler) cfg80211_wext_giwfrag,
1480 [IW_IOCTL_IDX(SIOCSIWTXPOW)] = (iw_handler) cfg80211_wext_siwtxpower,
1481 [IW_IOCTL_IDX(SIOCGIWTXPOW)] = (iw_handler) cfg80211_wext_giwtxpower,
1482 [IW_IOCTL_IDX(SIOCSIWRETRY)] = (iw_handler) cfg80211_wext_siwretry,
1483 [IW_IOCTL_IDX(SIOCGIWRETRY)] = (iw_handler) cfg80211_wext_giwretry,
1484 [IW_IOCTL_IDX(SIOCSIWENCODE)] = (iw_handler) cfg80211_wext_siwencode,
1485 [IW_IOCTL_IDX(SIOCGIWENCODE)] = (iw_handler) cfg80211_wext_giwencode,
1486 [IW_IOCTL_IDX(SIOCSIWPOWER)] = (iw_handler) cfg80211_wext_siwpower,
1487 [IW_IOCTL_IDX(SIOCGIWPOWER)] = (iw_handler) cfg80211_wext_giwpower,
1488 [IW_IOCTL_IDX(SIOCSIWGENIE)] = (iw_handler) cfg80211_wext_siwgenie,
1489 [IW_IOCTL_IDX(SIOCSIWAUTH)] = (iw_handler) cfg80211_wext_siwauth,
1490 [IW_IOCTL_IDX(SIOCGIWAUTH)] = (iw_handler) cfg80211_wext_giwauth,
1491 [IW_IOCTL_IDX(SIOCSIWENCODEEXT)]= (iw_handler) cfg80211_wext_siwencodeext,
1492 [IW_IOCTL_IDX(SIOCSIWPMKSA)] = (iw_handler) cfg80211_wext_siwpmksa,
1495 const struct iw_handler_def cfg80211_wext_handler = {
1496 .num_standard = ARRAY_SIZE(cfg80211_handlers),
1497 .standard = cfg80211_handlers,
1498 .get_wireless_stats = cfg80211_wireless_stats,