2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
10 #include <linux/module.h>
11 #include <linux/init.h>
12 #include <linux/netdevice.h>
13 #include <linux/types.h>
14 #include <linux/slab.h>
15 #include <linux/skbuff.h>
16 #include <linux/etherdevice.h>
17 #include <linux/if_arp.h>
18 #include <linux/wireless.h>
19 #include <net/iw_handler.h>
20 #include <asm/uaccess.h>
22 #include <net/mac80211.h>
23 #include "ieee80211_i.h"
30 static int ieee80211_set_encryption(struct ieee80211_sub_if_data *sdata, u8 *sta_addr,
31 int idx, int alg, int remove,
32 int set_tx_key, const u8 *_key,
35 struct ieee80211_local *local = sdata->local;
37 struct ieee80211_key *key;
40 if (alg == ALG_AES_CMAC) {
41 if (idx < NUM_DEFAULT_KEYS ||
42 idx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) {
43 printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d "
44 "(BIP)\n", sdata->dev->name, idx);
47 } else if (idx < 0 || idx >= NUM_DEFAULT_KEYS) {
48 printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
49 sdata->dev->name, idx);
58 if (is_broadcast_ether_addr(sta_addr)) {
59 key = sdata->keys[idx];
61 sta = sta_info_get(local, sta_addr);
69 ieee80211_key_free(key);
71 key = ieee80211_key_alloc(alg, idx, key_len, _key);
80 if (!is_broadcast_ether_addr(sta_addr)) {
83 * According to the standard, the key index of a
84 * pairwise key must be zero. However, some AP are
85 * broken when it comes to WEP key indices, so we
88 if (idx != 0 && alg != ALG_WEP) {
89 ieee80211_key_free(key);
94 sta = sta_info_get(local, sta_addr);
96 ieee80211_key_free(key);
102 if (alg == ALG_WEP &&
103 key_len != LEN_WEP40 && key_len != LEN_WEP104) {
104 ieee80211_key_free(key);
109 ieee80211_key_link(key, sdata, sta);
111 if (set_tx_key || (!sta && !sdata->default_key && key))
112 ieee80211_set_default_key(sdata, idx);
113 if (alg == ALG_AES_CMAC &&
114 (set_tx_key || (!sta && !sdata->default_mgmt_key && key)))
115 ieee80211_set_default_mgmt_key(sdata, idx);
124 static int ieee80211_ioctl_siwgenie(struct net_device *dev,
125 struct iw_request_info *info,
126 struct iw_point *data, char *extra)
128 struct ieee80211_sub_if_data *sdata;
130 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
132 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
133 int ret = ieee80211_sta_set_extra_ie(sdata, extra, data->length);
136 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
137 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
138 ieee80211_sta_req_auth(sdata);
145 static int ieee80211_ioctl_siwfreq(struct net_device *dev,
146 struct iw_request_info *info,
147 struct iw_freq *freq, char *extra)
149 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
151 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
152 sdata->u.ibss.flags &= ~IEEE80211_IBSS_AUTO_CHANNEL_SEL;
153 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
154 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
156 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
159 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
160 sdata->u.ibss.flags |=
161 IEEE80211_IBSS_AUTO_CHANNEL_SEL;
162 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
163 sdata->u.mgd.flags |=
164 IEEE80211_STA_AUTO_CHANNEL_SEL;
167 return ieee80211_set_freq(sdata,
168 ieee80211_channel_to_frequency(freq->m));
170 int i, div = 1000000;
171 for (i = 0; i < freq->e; i++)
174 return ieee80211_set_freq(sdata, freq->m / div);
181 static int ieee80211_ioctl_giwfreq(struct net_device *dev,
182 struct iw_request_info *info,
183 struct iw_freq *freq, char *extra)
185 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
187 freq->m = local->hw.conf.channel->center_freq;
194 static int ieee80211_ioctl_siwessid(struct net_device *dev,
195 struct iw_request_info *info,
196 struct iw_point *data, char *ssid)
198 struct ieee80211_sub_if_data *sdata;
199 size_t len = data->length;
202 /* iwconfig uses nul termination in SSID.. */
203 if (len > 0 && ssid[len - 1] == '\0')
206 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
207 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
209 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
211 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL;
213 ret = ieee80211_sta_set_ssid(sdata, ssid, len);
217 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
218 ieee80211_sta_req_auth(sdata);
220 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
221 return ieee80211_ibss_set_ssid(sdata, ssid, len);
227 static int ieee80211_ioctl_giwessid(struct net_device *dev,
228 struct iw_request_info *info,
229 struct iw_point *data, char *ssid)
233 struct ieee80211_sub_if_data *sdata;
234 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
235 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
236 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
243 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
244 int res = ieee80211_ibss_get_ssid(sdata, ssid, &len);
257 static int ieee80211_ioctl_siwap(struct net_device *dev,
258 struct iw_request_info *info,
259 struct sockaddr *ap_addr, char *extra)
261 struct ieee80211_sub_if_data *sdata;
263 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
264 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
267 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
268 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
269 IEEE80211_STA_AUTO_CHANNEL_SEL;
270 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
271 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
273 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
274 ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
277 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
278 ieee80211_sta_req_auth(sdata);
280 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
281 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
282 sdata->u.ibss.flags |= IEEE80211_IBSS_AUTO_BSSID_SEL |
283 IEEE80211_IBSS_AUTO_CHANNEL_SEL;
284 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
285 sdata->u.ibss.flags |= IEEE80211_IBSS_AUTO_BSSID_SEL;
287 sdata->u.ibss.flags &= ~IEEE80211_IBSS_AUTO_BSSID_SEL;
289 return ieee80211_ibss_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
290 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
292 * If it is necessary to update the WDS peer address
293 * while the interface is running, then we need to do
294 * more work here, namely if it is running we need to
295 * add a new and remove the old STA entry, this is
296 * normally handled by _open() and _stop().
298 if (netif_running(dev))
301 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
311 static int ieee80211_ioctl_giwap(struct net_device *dev,
312 struct iw_request_info *info,
313 struct sockaddr *ap_addr, char *extra)
315 struct ieee80211_sub_if_data *sdata;
317 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
318 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
319 if (sdata->u.mgd.state == IEEE80211_STA_MLME_ASSOCIATED) {
320 ap_addr->sa_family = ARPHRD_ETHER;
321 memcpy(&ap_addr->sa_data, sdata->u.mgd.bssid, ETH_ALEN);
323 memset(&ap_addr->sa_data, 0, ETH_ALEN);
325 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
326 if (sdata->u.ibss.state == IEEE80211_IBSS_MLME_JOINED) {
327 ap_addr->sa_family = ARPHRD_ETHER;
328 memcpy(&ap_addr->sa_data, sdata->u.ibss.bssid, ETH_ALEN);
330 memset(&ap_addr->sa_data, 0, ETH_ALEN);
332 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
333 ap_addr->sa_family = ARPHRD_ETHER;
334 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
342 static int ieee80211_ioctl_siwrate(struct net_device *dev,
343 struct iw_request_info *info,
344 struct iw_param *rate, char *extra)
346 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
347 int i, err = -EINVAL;
348 u32 target_rate = rate->value / 100000;
349 struct ieee80211_sub_if_data *sdata;
350 struct ieee80211_supported_band *sband;
352 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
354 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
356 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
357 * target_rate = X, rate->fixed = 1 means only rate X
358 * target_rate = X, rate->fixed = 0 means all rates <= X */
359 sdata->max_ratectrl_rateidx = -1;
360 sdata->force_unicast_rateidx = -1;
364 for (i=0; i< sband->n_bitrates; i++) {
365 struct ieee80211_rate *brate = &sband->bitrates[i];
366 int this_rate = brate->bitrate;
368 if (target_rate == this_rate) {
369 sdata->max_ratectrl_rateidx = i;
371 sdata->force_unicast_rateidx = i;
379 static int ieee80211_ioctl_giwrate(struct net_device *dev,
380 struct iw_request_info *info,
381 struct iw_param *rate, char *extra)
383 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
384 struct sta_info *sta;
385 struct ieee80211_sub_if_data *sdata;
386 struct ieee80211_supported_band *sband;
388 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
390 if (sdata->vif.type != NL80211_IFTYPE_STATION)
393 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
397 sta = sta_info_get(local, sdata->u.mgd.bssid);
399 if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
400 rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
409 rate->value *= 100000;
414 static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
415 struct iw_request_info *info,
416 union iwreq_data *data, char *extra)
418 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
419 struct ieee80211_channel* chan = local->hw.conf.channel;
421 u32 reconf_flags = 0;
424 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
426 if (data->txpower.flags & IW_TXPOW_RANGE)
431 /* only change when not disabling */
432 if (!data->txpower.disabled) {
433 if (data->txpower.fixed) {
434 if (data->txpower.value < 0)
436 new_power_level = data->txpower.value;
438 * Debatable, but we cannot do a fixed power
439 * level above the regulatory constraint.
440 * Use "iwconfig wlan0 txpower 15dBm" instead.
442 if (new_power_level > chan->max_power)
446 * Automatic power level setting, max being the value
447 * passed in from userland.
449 if (data->txpower.value < 0)
450 new_power_level = -1;
452 new_power_level = data->txpower.value;
458 * ieee80211_hw_config() will limit to the channel's
459 * max power and possibly power constraint from AP.
461 local->user_power_level = new_power_level;
464 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
465 local->hw.conf.radio_enabled = !(data->txpower.disabled);
466 reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
467 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
470 if (reconf || reconf_flags)
471 ieee80211_hw_config(local, reconf_flags);
476 static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
477 struct iw_request_info *info,
478 union iwreq_data *data, char *extra)
480 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
482 data->txpower.fixed = 1;
483 data->txpower.disabled = !(local->hw.conf.radio_enabled);
484 data->txpower.value = local->hw.conf.power_level;
485 data->txpower.flags = IW_TXPOW_DBM;
490 static int ieee80211_ioctl_siwrts(struct net_device *dev,
491 struct iw_request_info *info,
492 struct iw_param *rts, char *extra)
494 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
497 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
498 else if (!rts->fixed)
499 /* if the rts value is not fixed, then take default */
500 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
501 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
504 local->rts_threshold = rts->value;
506 /* If the wlan card performs RTS/CTS in hardware/firmware,
507 * configure it here */
509 if (local->ops->set_rts_threshold)
510 local->ops->set_rts_threshold(local_to_hw(local),
511 local->rts_threshold);
516 static int ieee80211_ioctl_giwrts(struct net_device *dev,
517 struct iw_request_info *info,
518 struct iw_param *rts, char *extra)
520 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
522 rts->value = local->rts_threshold;
523 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
530 static int ieee80211_ioctl_siwfrag(struct net_device *dev,
531 struct iw_request_info *info,
532 struct iw_param *frag, char *extra)
534 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
537 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
538 else if (!frag->fixed)
539 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
540 else if (frag->value < 256 ||
541 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
544 /* Fragment length must be even, so strip LSB. */
545 local->fragmentation_threshold = frag->value & ~0x1;
551 static int ieee80211_ioctl_giwfrag(struct net_device *dev,
552 struct iw_request_info *info,
553 struct iw_param *frag, char *extra)
555 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
557 frag->value = local->fragmentation_threshold;
558 frag->disabled = (frag->value >= IEEE80211_MAX_FRAG_THRESHOLD);
565 static int ieee80211_ioctl_siwretry(struct net_device *dev,
566 struct iw_request_info *info,
567 struct iw_param *retry, char *extra)
569 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
571 if (retry->disabled ||
572 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
575 if (retry->flags & IW_RETRY_MAX) {
576 local->hw.conf.long_frame_max_tx_count = retry->value;
577 } else if (retry->flags & IW_RETRY_MIN) {
578 local->hw.conf.short_frame_max_tx_count = retry->value;
580 local->hw.conf.long_frame_max_tx_count = retry->value;
581 local->hw.conf.short_frame_max_tx_count = retry->value;
584 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
590 static int ieee80211_ioctl_giwretry(struct net_device *dev,
591 struct iw_request_info *info,
592 struct iw_param *retry, char *extra)
594 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
597 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
598 /* first return min value, iwconfig will ask max value
600 retry->flags |= IW_RETRY_LIMIT;
601 retry->value = local->hw.conf.short_frame_max_tx_count;
602 if (local->hw.conf.long_frame_max_tx_count !=
603 local->hw.conf.short_frame_max_tx_count)
604 retry->flags |= IW_RETRY_MIN;
607 if (retry->flags & IW_RETRY_MAX) {
608 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
609 retry->value = local->hw.conf.long_frame_max_tx_count;
616 static int ieee80211_ioctl_siwencode(struct net_device *dev,
617 struct iw_request_info *info,
618 struct iw_point *erq, char *keybuf)
620 struct ieee80211_sub_if_data *sdata;
621 int idx, i, alg = ALG_WEP;
622 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
625 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
627 idx = erq->flags & IW_ENCODE_INDEX;
629 if (sdata->default_key)
630 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
631 if (sdata->default_key == sdata->keys[i]) {
636 } else if (idx < 1 || idx > 4)
641 if (erq->flags & IW_ENCODE_DISABLED)
643 else if (erq->length == 0) {
644 /* No key data - just set the default TX key index */
645 ieee80211_set_default_key(sdata, idx);
649 ret = ieee80211_set_encryption(
653 keybuf, erq->length);
655 if (!ret && sdata->vif.type == NL80211_IFTYPE_STATION) {
657 sdata->u.mgd.flags &= ~IEEE80211_STA_TKIP_WEP_USED;
659 sdata->u.mgd.flags |= IEEE80211_STA_TKIP_WEP_USED;
666 static int ieee80211_ioctl_giwencode(struct net_device *dev,
667 struct iw_request_info *info,
668 struct iw_point *erq, char *key)
670 struct ieee80211_sub_if_data *sdata;
673 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
675 idx = erq->flags & IW_ENCODE_INDEX;
676 if (idx < 1 || idx > 4) {
678 if (!sdata->default_key)
680 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
681 if (sdata->default_key == sdata->keys[i]) {
691 erq->flags = idx + 1;
693 if (!sdata->keys[idx]) {
695 erq->flags |= IW_ENCODE_DISABLED;
699 memcpy(key, sdata->keys[idx]->conf.key,
700 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
701 erq->length = sdata->keys[idx]->conf.keylen;
702 erq->flags |= IW_ENCODE_ENABLED;
704 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
705 switch (sdata->u.mgd.auth_alg) {
708 erq->flags |= IW_ENCODE_OPEN;
710 case WLAN_AUTH_SHARED_KEY:
711 erq->flags |= IW_ENCODE_RESTRICTED;
719 static int ieee80211_ioctl_siwpower(struct net_device *dev,
720 struct iw_request_info *info,
721 struct iw_param *wrq,
724 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
725 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
726 struct ieee80211_conf *conf = &local->hw.conf;
730 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
733 if (sdata->vif.type != NL80211_IFTYPE_STATION)
742 switch (wrq->flags & IW_POWER_MODE) {
743 case IW_POWER_ON: /* If not specified */
744 case IW_POWER_MODE: /* If set all mask */
745 case IW_POWER_ALL_R: /* If explicitely state all */
748 default: /* Otherwise we ignore */
752 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
755 if (wrq->flags & IW_POWER_TIMEOUT)
756 timeout = wrq->value / 1000;
759 if (ps == sdata->u.mgd.powersave && timeout == conf->dynamic_ps_timeout)
762 sdata->u.mgd.powersave = ps;
763 conf->dynamic_ps_timeout = timeout;
765 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
766 ieee80211_hw_config(local,
767 IEEE80211_CONF_CHANGE_DYNPS_TIMEOUT);
769 ieee80211_recalc_ps(local, -1);
774 static int ieee80211_ioctl_giwpower(struct net_device *dev,
775 struct iw_request_info *info,
776 union iwreq_data *wrqu,
779 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
781 wrqu->power.disabled = !sdata->u.mgd.powersave;
786 static int ieee80211_ioctl_siwauth(struct net_device *dev,
787 struct iw_request_info *info,
788 struct iw_param *data, char *extra)
790 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
793 switch (data->flags & IW_AUTH_INDEX) {
794 case IW_AUTH_WPA_VERSION:
795 case IW_AUTH_CIPHER_GROUP:
796 case IW_AUTH_WPA_ENABLED:
797 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
798 case IW_AUTH_KEY_MGMT:
799 case IW_AUTH_CIPHER_GROUP_MGMT:
801 case IW_AUTH_CIPHER_PAIRWISE:
802 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
803 if (data->value & (IW_AUTH_CIPHER_WEP40 |
804 IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP))
805 sdata->u.mgd.flags |=
806 IEEE80211_STA_TKIP_WEP_USED;
808 sdata->u.mgd.flags &=
809 ~IEEE80211_STA_TKIP_WEP_USED;
812 case IW_AUTH_DROP_UNENCRYPTED:
813 sdata->drop_unencrypted = !!data->value;
815 case IW_AUTH_PRIVACY_INVOKED:
816 if (sdata->vif.type != NL80211_IFTYPE_STATION)
819 sdata->u.mgd.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
821 * Privacy invoked by wpa_supplicant, store the
822 * value and allow associating to a protected
823 * network without having a key up front.
826 sdata->u.mgd.flags |=
827 IEEE80211_STA_PRIVACY_INVOKED;
830 case IW_AUTH_80211_AUTH_ALG:
831 if (sdata->vif.type == NL80211_IFTYPE_STATION)
832 sdata->u.mgd.auth_algs = data->value;
837 if (!(sdata->local->hw.flags & IEEE80211_HW_MFP_CAPABLE)) {
841 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
842 switch (data->value) {
843 case IW_AUTH_MFP_DISABLED:
844 sdata->u.mgd.mfp = IEEE80211_MFP_DISABLED;
846 case IW_AUTH_MFP_OPTIONAL:
847 sdata->u.mgd.mfp = IEEE80211_MFP_OPTIONAL;
849 case IW_AUTH_MFP_REQUIRED:
850 sdata->u.mgd.mfp = IEEE80211_MFP_REQUIRED;
865 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
866 static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
868 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
869 struct iw_statistics *wstats = &local->wstats;
870 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
871 struct sta_info *sta = NULL;
875 if (sdata->vif.type == NL80211_IFTYPE_STATION)
876 sta = sta_info_get(local, sdata->u.mgd.bssid);
879 wstats->discard.fragment = 0;
880 wstats->discard.misc = 0;
881 wstats->qual.qual = 0;
882 wstats->qual.level = 0;
883 wstats->qual.noise = 0;
884 wstats->qual.updated = IW_QUAL_ALL_INVALID;
886 wstats->qual.updated = 0;
888 * mirror what cfg80211 does for iwrange/scan results,
889 * otherwise userspace gets confused.
891 if (local->hw.flags & (IEEE80211_HW_SIGNAL_UNSPEC |
892 IEEE80211_HW_SIGNAL_DBM)) {
893 wstats->qual.updated |= IW_QUAL_LEVEL_UPDATED;
894 wstats->qual.updated |= IW_QUAL_QUAL_UPDATED;
896 wstats->qual.updated |= IW_QUAL_LEVEL_INVALID;
897 wstats->qual.updated |= IW_QUAL_QUAL_INVALID;
900 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) {
901 wstats->qual.level = sta->last_signal;
902 wstats->qual.qual = sta->last_signal;
903 } else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
904 int sig = sta->last_signal;
906 wstats->qual.updated |= IW_QUAL_DBM;
907 wstats->qual.level = sig;
912 wstats->qual.qual = sig + 110;
915 if (local->hw.flags & IEEE80211_HW_NOISE_DBM) {
917 * This assumes that if driver reports noise, it also
918 * reports signal in dBm.
920 wstats->qual.noise = sta->last_noise;
921 wstats->qual.updated |= IW_QUAL_NOISE_UPDATED;
923 wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
932 static int ieee80211_ioctl_giwauth(struct net_device *dev,
933 struct iw_request_info *info,
934 struct iw_param *data, char *extra)
936 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
939 switch (data->flags & IW_AUTH_INDEX) {
940 case IW_AUTH_80211_AUTH_ALG:
941 if (sdata->vif.type == NL80211_IFTYPE_STATION)
942 data->value = sdata->u.mgd.auth_algs;
954 static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
955 struct iw_request_info *info,
956 struct iw_point *erq, char *extra)
958 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
959 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
960 int uninitialized_var(alg), idx, i, remove = 0;
963 case IW_ENCODE_ALG_NONE:
966 case IW_ENCODE_ALG_WEP:
969 case IW_ENCODE_ALG_TKIP:
972 case IW_ENCODE_ALG_CCMP:
975 case IW_ENCODE_ALG_AES_CMAC:
982 if (erq->flags & IW_ENCODE_DISABLED)
985 idx = erq->flags & IW_ENCODE_INDEX;
986 if (alg == ALG_AES_CMAC) {
987 if (idx < NUM_DEFAULT_KEYS + 1 ||
988 idx > NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) {
990 if (!sdata->default_mgmt_key)
992 else for (i = NUM_DEFAULT_KEYS;
993 i < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS;
995 if (sdata->default_mgmt_key == sdata->keys[i])
1006 if (idx < 1 || idx > 4) {
1008 if (!sdata->default_key)
1010 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1011 if (sdata->default_key == sdata->keys[i]) {
1022 return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg,
1025 IW_ENCODE_EXT_SET_TX_KEY,
1026 ext->key, ext->key_len);
1030 /* Structures to export the Wireless Handlers */
1032 static const iw_handler ieee80211_handler[] =
1034 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1035 (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */
1036 (iw_handler) NULL, /* SIOCSIWNWID */
1037 (iw_handler) NULL, /* SIOCGIWNWID */
1038 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1039 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1040 (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */
1041 (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */
1042 (iw_handler) NULL, /* SIOCSIWSENS */
1043 (iw_handler) NULL, /* SIOCGIWSENS */
1044 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1045 (iw_handler) cfg80211_wext_giwrange, /* SIOCGIWRANGE */
1046 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1047 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1048 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1049 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
1050 (iw_handler) NULL, /* SIOCSIWSPY */
1051 (iw_handler) NULL, /* SIOCGIWSPY */
1052 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1053 (iw_handler) NULL, /* SIOCGIWTHRSPY */
1054 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1055 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1056 (iw_handler) cfg80211_wext_siwmlme, /* SIOCSIWMLME */
1057 (iw_handler) NULL, /* SIOCGIWAPLIST */
1058 (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */
1059 (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */
1060 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1061 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1062 (iw_handler) NULL, /* SIOCSIWNICKN */
1063 (iw_handler) NULL, /* SIOCGIWNICKN */
1064 (iw_handler) NULL, /* -- hole -- */
1065 (iw_handler) NULL, /* -- hole -- */
1066 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
1067 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
1068 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1069 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1070 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1071 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
1072 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
1073 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
1074 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1075 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1076 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1077 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
1078 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
1079 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
1080 (iw_handler) NULL, /* -- hole -- */
1081 (iw_handler) NULL, /* -- hole -- */
1082 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1083 (iw_handler) NULL, /* SIOCGIWGENIE */
1084 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1085 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1086 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1087 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1088 (iw_handler) NULL, /* SIOCSIWPMKSA */
1089 (iw_handler) NULL, /* -- hole -- */
1092 const struct iw_handler_def ieee80211_iw_handler_def =
1094 .num_standard = ARRAY_SIZE(ieee80211_handler),
1095 .standard = (iw_handler *) ieee80211_handler,
1096 .get_wireless_stats = ieee80211_get_wireless_stats,