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->flags & IEEE80211_SDATA_USERSPACE_MLME)
135 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
136 int ret = ieee80211_sta_set_extra_ie(sdata, extra, data->length);
139 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
140 ieee80211_sta_req_auth(sdata);
147 static int ieee80211_ioctl_siwfreq(struct net_device *dev,
148 struct iw_request_info *info,
149 struct iw_freq *freq, char *extra)
151 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
153 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
154 sdata->u.ibss.flags &= ~IEEE80211_IBSS_AUTO_CHANNEL_SEL;
155 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
156 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
158 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
161 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
162 sdata->u.ibss.flags |=
163 IEEE80211_IBSS_AUTO_CHANNEL_SEL;
164 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
165 sdata->u.mgd.flags |=
166 IEEE80211_STA_AUTO_CHANNEL_SEL;
169 return ieee80211_set_freq(sdata,
170 ieee80211_channel_to_frequency(freq->m));
172 int i, div = 1000000;
173 for (i = 0; i < freq->e; i++)
176 return ieee80211_set_freq(sdata, freq->m / div);
183 static int ieee80211_ioctl_giwfreq(struct net_device *dev,
184 struct iw_request_info *info,
185 struct iw_freq *freq, char *extra)
187 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
189 freq->m = local->hw.conf.channel->center_freq;
196 static int ieee80211_ioctl_siwessid(struct net_device *dev,
197 struct iw_request_info *info,
198 struct iw_point *data, char *ssid)
200 struct ieee80211_sub_if_data *sdata;
201 size_t len = data->length;
204 /* iwconfig uses nul termination in SSID.. */
205 if (len > 0 && ssid[len - 1] == '\0')
208 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
209 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
210 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
211 if (len > IEEE80211_MAX_SSID_LEN)
213 memcpy(sdata->u.mgd.ssid, ssid, len);
214 sdata->u.mgd.ssid_len = len;
219 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
221 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL;
223 ret = ieee80211_sta_set_ssid(sdata, ssid, len);
227 ieee80211_sta_req_auth(sdata);
229 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
230 return ieee80211_ibss_set_ssid(sdata, ssid, len);
236 static int ieee80211_ioctl_giwessid(struct net_device *dev,
237 struct iw_request_info *info,
238 struct iw_point *data, char *ssid)
242 struct ieee80211_sub_if_data *sdata;
243 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
244 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
245 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
252 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
253 int res = ieee80211_ibss_get_ssid(sdata, ssid, &len);
266 static int ieee80211_ioctl_siwap(struct net_device *dev,
267 struct iw_request_info *info,
268 struct sockaddr *ap_addr, char *extra)
270 struct ieee80211_sub_if_data *sdata;
272 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
273 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
275 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
276 memcpy(sdata->u.mgd.bssid, (u8 *) &ap_addr->sa_data,
280 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
281 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
282 IEEE80211_STA_AUTO_CHANNEL_SEL;
283 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
284 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
286 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
287 ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
290 ieee80211_sta_req_auth(sdata);
292 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
293 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
294 sdata->u.ibss.flags |= IEEE80211_IBSS_AUTO_BSSID_SEL |
295 IEEE80211_IBSS_AUTO_CHANNEL_SEL;
296 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
297 sdata->u.ibss.flags |= IEEE80211_IBSS_AUTO_BSSID_SEL;
299 sdata->u.ibss.flags &= ~IEEE80211_IBSS_AUTO_BSSID_SEL;
301 return ieee80211_ibss_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
302 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
304 * If it is necessary to update the WDS peer address
305 * while the interface is running, then we need to do
306 * more work here, namely if it is running we need to
307 * add a new and remove the old STA entry, this is
308 * normally handled by _open() and _stop().
310 if (netif_running(dev))
313 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
323 static int ieee80211_ioctl_giwap(struct net_device *dev,
324 struct iw_request_info *info,
325 struct sockaddr *ap_addr, char *extra)
327 struct ieee80211_sub_if_data *sdata;
329 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
330 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
331 if (sdata->u.mgd.state == IEEE80211_STA_MLME_ASSOCIATED) {
332 ap_addr->sa_family = ARPHRD_ETHER;
333 memcpy(&ap_addr->sa_data, sdata->u.mgd.bssid, ETH_ALEN);
335 memset(&ap_addr->sa_data, 0, ETH_ALEN);
337 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
338 if (sdata->u.ibss.state == IEEE80211_IBSS_MLME_JOINED) {
339 ap_addr->sa_family = ARPHRD_ETHER;
340 memcpy(&ap_addr->sa_data, sdata->u.ibss.bssid, ETH_ALEN);
342 memset(&ap_addr->sa_data, 0, ETH_ALEN);
344 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
345 ap_addr->sa_family = ARPHRD_ETHER;
346 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
354 static int ieee80211_ioctl_siwrate(struct net_device *dev,
355 struct iw_request_info *info,
356 struct iw_param *rate, char *extra)
358 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
359 int i, err = -EINVAL;
360 u32 target_rate = rate->value / 100000;
361 struct ieee80211_sub_if_data *sdata;
362 struct ieee80211_supported_band *sband;
364 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
366 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
368 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
369 * target_rate = X, rate->fixed = 1 means only rate X
370 * target_rate = X, rate->fixed = 0 means all rates <= X */
371 sdata->max_ratectrl_rateidx = -1;
372 sdata->force_unicast_rateidx = -1;
376 for (i=0; i< sband->n_bitrates; i++) {
377 struct ieee80211_rate *brate = &sband->bitrates[i];
378 int this_rate = brate->bitrate;
380 if (target_rate == this_rate) {
381 sdata->max_ratectrl_rateidx = i;
383 sdata->force_unicast_rateidx = i;
391 static int ieee80211_ioctl_giwrate(struct net_device *dev,
392 struct iw_request_info *info,
393 struct iw_param *rate, char *extra)
395 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
396 struct sta_info *sta;
397 struct ieee80211_sub_if_data *sdata;
398 struct ieee80211_supported_band *sband;
400 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
402 if (sdata->vif.type != NL80211_IFTYPE_STATION)
405 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
409 sta = sta_info_get(local, sdata->u.mgd.bssid);
411 if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
412 rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
421 rate->value *= 100000;
426 static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
427 struct iw_request_info *info,
428 union iwreq_data *data, char *extra)
430 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
431 struct ieee80211_channel* chan = local->hw.conf.channel;
432 u32 reconf_flags = 0;
435 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
437 if (data->txpower.flags & IW_TXPOW_RANGE)
442 if (data->txpower.fixed)
443 new_power_level = min(data->txpower.value, chan->max_power);
444 else /* Automatic power level setting */
445 new_power_level = chan->max_power;
447 local->user_power_level = new_power_level;
448 if (local->hw.conf.power_level != new_power_level)
449 reconf_flags |= IEEE80211_CONF_CHANGE_POWER;
451 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
452 local->hw.conf.radio_enabled = !(data->txpower.disabled);
453 reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
454 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
458 ieee80211_hw_config(local, reconf_flags);
463 static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
464 struct iw_request_info *info,
465 union iwreq_data *data, char *extra)
467 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
469 data->txpower.fixed = 1;
470 data->txpower.disabled = !(local->hw.conf.radio_enabled);
471 data->txpower.value = local->hw.conf.power_level;
472 data->txpower.flags = IW_TXPOW_DBM;
477 static int ieee80211_ioctl_siwrts(struct net_device *dev,
478 struct iw_request_info *info,
479 struct iw_param *rts, char *extra)
481 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
484 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
485 else if (!rts->fixed)
486 /* if the rts value is not fixed, then take default */
487 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
488 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
491 local->rts_threshold = rts->value;
493 /* If the wlan card performs RTS/CTS in hardware/firmware,
494 * configure it here */
496 if (local->ops->set_rts_threshold)
497 local->ops->set_rts_threshold(local_to_hw(local),
498 local->rts_threshold);
503 static int ieee80211_ioctl_giwrts(struct net_device *dev,
504 struct iw_request_info *info,
505 struct iw_param *rts, char *extra)
507 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
509 rts->value = local->rts_threshold;
510 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
517 static int ieee80211_ioctl_siwfrag(struct net_device *dev,
518 struct iw_request_info *info,
519 struct iw_param *frag, char *extra)
521 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
524 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
525 else if (!frag->fixed)
526 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
527 else if (frag->value < 256 ||
528 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
531 /* Fragment length must be even, so strip LSB. */
532 local->fragmentation_threshold = frag->value & ~0x1;
538 static int ieee80211_ioctl_giwfrag(struct net_device *dev,
539 struct iw_request_info *info,
540 struct iw_param *frag, char *extra)
542 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
544 frag->value = local->fragmentation_threshold;
545 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
552 static int ieee80211_ioctl_siwretry(struct net_device *dev,
553 struct iw_request_info *info,
554 struct iw_param *retry, char *extra)
556 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
558 if (retry->disabled ||
559 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
562 if (retry->flags & IW_RETRY_MAX) {
563 local->hw.conf.long_frame_max_tx_count = retry->value;
564 } else if (retry->flags & IW_RETRY_MIN) {
565 local->hw.conf.short_frame_max_tx_count = retry->value;
567 local->hw.conf.long_frame_max_tx_count = retry->value;
568 local->hw.conf.short_frame_max_tx_count = retry->value;
571 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
577 static int ieee80211_ioctl_giwretry(struct net_device *dev,
578 struct iw_request_info *info,
579 struct iw_param *retry, char *extra)
581 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
584 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
585 /* first return min value, iwconfig will ask max value
587 retry->flags |= IW_RETRY_LIMIT;
588 retry->value = local->hw.conf.short_frame_max_tx_count;
589 if (local->hw.conf.long_frame_max_tx_count !=
590 local->hw.conf.short_frame_max_tx_count)
591 retry->flags |= IW_RETRY_MIN;
594 if (retry->flags & IW_RETRY_MAX) {
595 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
596 retry->value = local->hw.conf.long_frame_max_tx_count;
602 static int ieee80211_ioctl_siwmlme(struct net_device *dev,
603 struct iw_request_info *info,
604 struct iw_point *data, char *extra)
606 struct ieee80211_sub_if_data *sdata;
607 struct iw_mlme *mlme = (struct iw_mlme *) extra;
609 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
610 if (!(sdata->vif.type == NL80211_IFTYPE_STATION))
615 /* TODO: mlme->addr.sa_data */
616 return ieee80211_sta_deauthenticate(sdata, mlme->reason_code);
617 case IW_MLME_DISASSOC:
618 /* TODO: mlme->addr.sa_data */
619 return ieee80211_sta_disassociate(sdata, mlme->reason_code);
626 static int ieee80211_ioctl_siwencode(struct net_device *dev,
627 struct iw_request_info *info,
628 struct iw_point *erq, char *keybuf)
630 struct ieee80211_sub_if_data *sdata;
631 int idx, i, alg = ALG_WEP;
632 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
635 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
637 idx = erq->flags & IW_ENCODE_INDEX;
639 if (sdata->default_key)
640 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
641 if (sdata->default_key == sdata->keys[i]) {
646 } else if (idx < 1 || idx > 4)
651 if (erq->flags & IW_ENCODE_DISABLED)
653 else if (erq->length == 0) {
654 /* No key data - just set the default TX key index */
655 ieee80211_set_default_key(sdata, idx);
659 ret = ieee80211_set_encryption(
663 keybuf, erq->length);
667 sdata->u.mgd.flags &= ~IEEE80211_STA_TKIP_WEP_USED;
669 sdata->u.mgd.flags |= IEEE80211_STA_TKIP_WEP_USED;
676 static int ieee80211_ioctl_giwencode(struct net_device *dev,
677 struct iw_request_info *info,
678 struct iw_point *erq, char *key)
680 struct ieee80211_sub_if_data *sdata;
683 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
685 idx = erq->flags & IW_ENCODE_INDEX;
686 if (idx < 1 || idx > 4) {
688 if (!sdata->default_key)
690 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
691 if (sdata->default_key == sdata->keys[i]) {
701 erq->flags = idx + 1;
703 if (!sdata->keys[idx]) {
705 erq->flags |= IW_ENCODE_DISABLED;
709 memcpy(key, sdata->keys[idx]->conf.key,
710 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
711 erq->length = sdata->keys[idx]->conf.keylen;
712 erq->flags |= IW_ENCODE_ENABLED;
714 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
715 switch (sdata->u.mgd.auth_alg) {
718 erq->flags |= IW_ENCODE_OPEN;
720 case WLAN_AUTH_SHARED_KEY:
721 erq->flags |= IW_ENCODE_RESTRICTED;
729 static int ieee80211_ioctl_siwpower(struct net_device *dev,
730 struct iw_request_info *info,
731 struct iw_param *wrq,
734 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
735 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
736 struct ieee80211_conf *conf = &local->hw.conf;
737 int ret = 0, timeout = 0;
740 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
743 if (sdata->vif.type != NL80211_IFTYPE_STATION)
752 switch (wrq->flags & IW_POWER_MODE) {
753 case IW_POWER_ON: /* If not specified */
754 case IW_POWER_MODE: /* If set all mask */
755 case IW_POWER_ALL_R: /* If explicitely state all */
758 default: /* Otherwise we ignore */
762 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
765 if (wrq->flags & IW_POWER_TIMEOUT)
766 timeout = wrq->value / 1000;
769 if (ps == local->powersave && timeout == conf->dynamic_ps_timeout)
772 local->powersave = ps;
773 conf->dynamic_ps_timeout = timeout;
775 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
776 ret = ieee80211_hw_config(local,
777 IEEE80211_CONF_CHANGE_DYNPS_TIMEOUT);
779 if (!(sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED))
782 if (conf->dynamic_ps_timeout > 0 &&
783 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
784 mod_timer(&local->dynamic_ps_timer, jiffies +
785 msecs_to_jiffies(conf->dynamic_ps_timeout));
787 if (local->powersave) {
788 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
789 ieee80211_send_nullfunc(local, sdata, 1);
790 conf->flags |= IEEE80211_CONF_PS;
791 ret = ieee80211_hw_config(local,
792 IEEE80211_CONF_CHANGE_PS);
794 conf->flags &= ~IEEE80211_CONF_PS;
795 ret = ieee80211_hw_config(local,
796 IEEE80211_CONF_CHANGE_PS);
797 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
798 ieee80211_send_nullfunc(local, sdata, 0);
799 del_timer_sync(&local->dynamic_ps_timer);
800 cancel_work_sync(&local->dynamic_ps_enable_work);
807 static int ieee80211_ioctl_giwpower(struct net_device *dev,
808 struct iw_request_info *info,
809 union iwreq_data *wrqu,
812 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
814 wrqu->power.disabled = !local->powersave;
819 static int ieee80211_ioctl_siwauth(struct net_device *dev,
820 struct iw_request_info *info,
821 struct iw_param *data, char *extra)
823 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
826 switch (data->flags & IW_AUTH_INDEX) {
827 case IW_AUTH_WPA_VERSION:
828 case IW_AUTH_CIPHER_GROUP:
829 case IW_AUTH_WPA_ENABLED:
830 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
831 case IW_AUTH_KEY_MGMT:
832 case IW_AUTH_CIPHER_GROUP_MGMT:
834 case IW_AUTH_CIPHER_PAIRWISE:
835 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
836 if (data->value & (IW_AUTH_CIPHER_WEP40 |
837 IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP))
838 sdata->u.mgd.flags |=
839 IEEE80211_STA_TKIP_WEP_USED;
841 sdata->u.mgd.flags &=
842 ~IEEE80211_STA_TKIP_WEP_USED;
845 case IW_AUTH_DROP_UNENCRYPTED:
846 sdata->drop_unencrypted = !!data->value;
848 case IW_AUTH_PRIVACY_INVOKED:
849 if (sdata->vif.type != NL80211_IFTYPE_STATION)
852 sdata->u.mgd.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
854 * Privacy invoked by wpa_supplicant, store the
855 * value and allow associating to a protected
856 * network without having a key up front.
859 sdata->u.mgd.flags |=
860 IEEE80211_STA_PRIVACY_INVOKED;
863 case IW_AUTH_80211_AUTH_ALG:
864 if (sdata->vif.type == NL80211_IFTYPE_STATION)
865 sdata->u.mgd.auth_algs = data->value;
870 if (!(sdata->local->hw.flags & IEEE80211_HW_MFP_CAPABLE)) {
874 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
875 switch (data->value) {
876 case IW_AUTH_MFP_DISABLED:
877 sdata->u.mgd.mfp = IEEE80211_MFP_DISABLED;
879 case IW_AUTH_MFP_OPTIONAL:
880 sdata->u.mgd.mfp = IEEE80211_MFP_OPTIONAL;
882 case IW_AUTH_MFP_REQUIRED:
883 sdata->u.mgd.mfp = IEEE80211_MFP_REQUIRED;
898 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
899 static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
901 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
902 struct iw_statistics *wstats = &local->wstats;
903 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
904 struct sta_info *sta = NULL;
908 if (sdata->vif.type == NL80211_IFTYPE_STATION)
909 sta = sta_info_get(local, sdata->u.mgd.bssid);
912 wstats->discard.fragment = 0;
913 wstats->discard.misc = 0;
914 wstats->qual.qual = 0;
915 wstats->qual.level = 0;
916 wstats->qual.noise = 0;
917 wstats->qual.updated = IW_QUAL_ALL_INVALID;
919 wstats->qual.updated = 0;
921 * mirror what cfg80211 does for iwrange/scan results,
922 * otherwise userspace gets confused.
924 if (local->hw.flags & (IEEE80211_HW_SIGNAL_UNSPEC |
925 IEEE80211_HW_SIGNAL_DBM)) {
926 wstats->qual.updated |= IW_QUAL_LEVEL_UPDATED;
927 wstats->qual.updated |= IW_QUAL_QUAL_UPDATED;
929 wstats->qual.updated |= IW_QUAL_LEVEL_INVALID;
930 wstats->qual.updated |= IW_QUAL_QUAL_INVALID;
933 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) {
934 wstats->qual.level = sta->last_signal;
935 wstats->qual.qual = sta->last_signal;
936 } else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
937 int sig = sta->last_signal;
939 wstats->qual.updated |= IW_QUAL_DBM;
940 wstats->qual.level = sig;
945 wstats->qual.qual = sig + 110;
948 if (local->hw.flags & IEEE80211_HW_NOISE_DBM) {
950 * This assumes that if driver reports noise, it also
951 * reports signal in dBm.
953 wstats->qual.noise = sta->last_noise;
954 wstats->qual.updated |= IW_QUAL_NOISE_UPDATED;
956 wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
965 static int ieee80211_ioctl_giwauth(struct net_device *dev,
966 struct iw_request_info *info,
967 struct iw_param *data, char *extra)
969 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
972 switch (data->flags & IW_AUTH_INDEX) {
973 case IW_AUTH_80211_AUTH_ALG:
974 if (sdata->vif.type == NL80211_IFTYPE_STATION)
975 data->value = sdata->u.mgd.auth_algs;
987 static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
988 struct iw_request_info *info,
989 struct iw_point *erq, char *extra)
991 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
992 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
993 int uninitialized_var(alg), idx, i, remove = 0;
996 case IW_ENCODE_ALG_NONE:
999 case IW_ENCODE_ALG_WEP:
1002 case IW_ENCODE_ALG_TKIP:
1005 case IW_ENCODE_ALG_CCMP:
1008 case IW_ENCODE_ALG_AES_CMAC:
1015 if (erq->flags & IW_ENCODE_DISABLED)
1018 idx = erq->flags & IW_ENCODE_INDEX;
1019 if (alg == ALG_AES_CMAC) {
1020 if (idx < NUM_DEFAULT_KEYS + 1 ||
1021 idx > NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) {
1023 if (!sdata->default_mgmt_key)
1025 else for (i = NUM_DEFAULT_KEYS;
1026 i < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS;
1028 if (sdata->default_mgmt_key == sdata->keys[i])
1039 if (idx < 1 || idx > 4) {
1041 if (!sdata->default_key)
1043 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1044 if (sdata->default_key == sdata->keys[i]) {
1055 return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg,
1058 IW_ENCODE_EXT_SET_TX_KEY,
1059 ext->key, ext->key_len);
1063 /* Structures to export the Wireless Handlers */
1065 static const iw_handler ieee80211_handler[] =
1067 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1068 (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */
1069 (iw_handler) NULL, /* SIOCSIWNWID */
1070 (iw_handler) NULL, /* SIOCGIWNWID */
1071 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1072 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1073 (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */
1074 (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */
1075 (iw_handler) NULL, /* SIOCSIWSENS */
1076 (iw_handler) NULL, /* SIOCGIWSENS */
1077 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1078 (iw_handler) cfg80211_wext_giwrange, /* SIOCGIWRANGE */
1079 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1080 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1081 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1082 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
1083 (iw_handler) NULL, /* SIOCSIWSPY */
1084 (iw_handler) NULL, /* SIOCGIWSPY */
1085 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1086 (iw_handler) NULL, /* SIOCGIWTHRSPY */
1087 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1088 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1089 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1090 (iw_handler) NULL, /* SIOCGIWAPLIST */
1091 (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */
1092 (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */
1093 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1094 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1095 (iw_handler) NULL, /* SIOCSIWNICKN */
1096 (iw_handler) NULL, /* SIOCGIWNICKN */
1097 (iw_handler) NULL, /* -- hole -- */
1098 (iw_handler) NULL, /* -- hole -- */
1099 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
1100 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
1101 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1102 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1103 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1104 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
1105 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
1106 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
1107 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1108 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1109 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1110 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
1111 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
1112 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
1113 (iw_handler) NULL, /* -- hole -- */
1114 (iw_handler) NULL, /* -- hole -- */
1115 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1116 (iw_handler) NULL, /* SIOCGIWGENIE */
1117 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1118 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1119 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1120 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1121 (iw_handler) NULL, /* SIOCSIWPMKSA */
1122 (iw_handler) NULL, /* -- hole -- */
1125 const struct iw_handler_def ieee80211_iw_handler_def =
1127 .num_standard = ARRAY_SIZE(ieee80211_handler),
1128 .standard = (iw_handler *) ieee80211_handler,
1129 .get_wireless_stats = ieee80211_get_wireless_stats,