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 return cfg80211_ibss_wext_siwfreq(dev, info, freq, extra);
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_STATION)
160 sdata->u.mgd.flags |=
161 IEEE80211_STA_AUTO_CHANNEL_SEL;
164 return ieee80211_set_freq(sdata,
165 ieee80211_channel_to_frequency(freq->m));
167 int i, div = 1000000;
168 for (i = 0; i < freq->e; i++)
171 return ieee80211_set_freq(sdata, freq->m / div);
178 static int ieee80211_ioctl_giwfreq(struct net_device *dev,
179 struct iw_request_info *info,
180 struct iw_freq *freq, char *extra)
182 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
183 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
185 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
186 return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra);
188 freq->m = local->hw.conf.channel->center_freq;
195 static int ieee80211_ioctl_siwessid(struct net_device *dev,
196 struct iw_request_info *info,
197 struct iw_point *data, char *ssid)
199 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
200 size_t len = data->length;
203 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
204 return cfg80211_ibss_wext_siwessid(dev, info, data, ssid);
206 /* iwconfig uses nul termination in SSID.. */
207 if (len > 0 && ssid[len - 1] == '\0')
210 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
212 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
214 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL;
216 ret = ieee80211_sta_set_ssid(sdata, ssid, len);
220 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
221 ieee80211_sta_req_auth(sdata);
229 static int ieee80211_ioctl_giwessid(struct net_device *dev,
230 struct iw_request_info *info,
231 struct iw_point *data, char *ssid)
234 struct ieee80211_sub_if_data *sdata;
236 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
238 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
239 return cfg80211_ibss_wext_giwessid(dev, info, data, ssid);
241 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
242 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
255 static int ieee80211_ioctl_siwap(struct net_device *dev,
256 struct iw_request_info *info,
257 struct sockaddr *ap_addr, char *extra)
259 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
261 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
262 return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra);
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_WDS) {
282 * If it is necessary to update the WDS peer address
283 * while the interface is running, then we need to do
284 * more work here, namely if it is running we need to
285 * add a new and remove the old STA entry, this is
286 * normally handled by _open() and _stop().
288 if (netif_running(dev))
291 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
301 static int ieee80211_ioctl_giwap(struct net_device *dev,
302 struct iw_request_info *info,
303 struct sockaddr *ap_addr, char *extra)
305 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
307 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
308 return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra);
310 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
311 if (sdata->u.mgd.state == IEEE80211_STA_MLME_ASSOCIATED) {
312 ap_addr->sa_family = ARPHRD_ETHER;
313 memcpy(&ap_addr->sa_data, sdata->u.mgd.bssid, ETH_ALEN);
315 memset(&ap_addr->sa_data, 0, ETH_ALEN);
317 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
318 ap_addr->sa_family = ARPHRD_ETHER;
319 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
327 static int ieee80211_ioctl_siwrate(struct net_device *dev,
328 struct iw_request_info *info,
329 struct iw_param *rate, char *extra)
331 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
332 int i, err = -EINVAL;
333 u32 target_rate = rate->value / 100000;
334 struct ieee80211_sub_if_data *sdata;
335 struct ieee80211_supported_band *sband;
337 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
339 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
341 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
342 * target_rate = X, rate->fixed = 1 means only rate X
343 * target_rate = X, rate->fixed = 0 means all rates <= X */
344 sdata->max_ratectrl_rateidx = -1;
345 sdata->force_unicast_rateidx = -1;
349 for (i=0; i< sband->n_bitrates; i++) {
350 struct ieee80211_rate *brate = &sband->bitrates[i];
351 int this_rate = brate->bitrate;
353 if (target_rate == this_rate) {
354 sdata->max_ratectrl_rateidx = i;
356 sdata->force_unicast_rateidx = i;
364 static int ieee80211_ioctl_giwrate(struct net_device *dev,
365 struct iw_request_info *info,
366 struct iw_param *rate, char *extra)
368 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
369 struct sta_info *sta;
370 struct ieee80211_sub_if_data *sdata;
371 struct ieee80211_supported_band *sband;
373 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
375 if (sdata->vif.type != NL80211_IFTYPE_STATION)
378 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
382 sta = sta_info_get(local, sdata->u.mgd.bssid);
384 if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
385 rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
394 rate->value *= 100000;
399 static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
400 struct iw_request_info *info,
401 union iwreq_data *data, char *extra)
403 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
404 struct ieee80211_channel* chan = local->hw.conf.channel;
406 u32 reconf_flags = 0;
409 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
411 if (data->txpower.flags & IW_TXPOW_RANGE)
416 /* only change when not disabling */
417 if (!data->txpower.disabled) {
418 if (data->txpower.fixed) {
419 if (data->txpower.value < 0)
421 new_power_level = data->txpower.value;
423 * Debatable, but we cannot do a fixed power
424 * level above the regulatory constraint.
425 * Use "iwconfig wlan0 txpower 15dBm" instead.
427 if (new_power_level > chan->max_power)
431 * Automatic power level setting, max being the value
432 * passed in from userland.
434 if (data->txpower.value < 0)
435 new_power_level = -1;
437 new_power_level = data->txpower.value;
443 * ieee80211_hw_config() will limit to the channel's
444 * max power and possibly power constraint from AP.
446 local->user_power_level = new_power_level;
449 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
450 local->hw.conf.radio_enabled = !(data->txpower.disabled);
451 reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
452 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
455 if (reconf || reconf_flags)
456 ieee80211_hw_config(local, reconf_flags);
461 static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
462 struct iw_request_info *info,
463 union iwreq_data *data, char *extra)
465 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
467 data->txpower.fixed = 1;
468 data->txpower.disabled = !(local->hw.conf.radio_enabled);
469 data->txpower.value = local->hw.conf.power_level;
470 data->txpower.flags = IW_TXPOW_DBM;
475 static int ieee80211_ioctl_siwrts(struct net_device *dev,
476 struct iw_request_info *info,
477 struct iw_param *rts, char *extra)
479 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
482 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
483 else if (!rts->fixed)
484 /* if the rts value is not fixed, then take default */
485 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
486 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
489 local->rts_threshold = rts->value;
491 /* If the wlan card performs RTS/CTS in hardware/firmware,
492 * configure it here */
494 if (local->ops->set_rts_threshold)
495 local->ops->set_rts_threshold(local_to_hw(local),
496 local->rts_threshold);
501 static int ieee80211_ioctl_giwrts(struct net_device *dev,
502 struct iw_request_info *info,
503 struct iw_param *rts, char *extra)
505 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
507 rts->value = local->rts_threshold;
508 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
515 static int ieee80211_ioctl_siwfrag(struct net_device *dev,
516 struct iw_request_info *info,
517 struct iw_param *frag, char *extra)
519 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
522 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
523 else if (!frag->fixed)
524 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
525 else if (frag->value < 256 ||
526 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
529 /* Fragment length must be even, so strip LSB. */
530 local->fragmentation_threshold = frag->value & ~0x1;
536 static int ieee80211_ioctl_giwfrag(struct net_device *dev,
537 struct iw_request_info *info,
538 struct iw_param *frag, char *extra)
540 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
542 frag->value = local->fragmentation_threshold;
543 frag->disabled = (frag->value >= IEEE80211_MAX_FRAG_THRESHOLD);
550 static int ieee80211_ioctl_siwretry(struct net_device *dev,
551 struct iw_request_info *info,
552 struct iw_param *retry, char *extra)
554 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
556 if (retry->disabled ||
557 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
560 if (retry->flags & IW_RETRY_MAX) {
561 local->hw.conf.long_frame_max_tx_count = retry->value;
562 } else if (retry->flags & IW_RETRY_MIN) {
563 local->hw.conf.short_frame_max_tx_count = retry->value;
565 local->hw.conf.long_frame_max_tx_count = retry->value;
566 local->hw.conf.short_frame_max_tx_count = retry->value;
569 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
575 static int ieee80211_ioctl_giwretry(struct net_device *dev,
576 struct iw_request_info *info,
577 struct iw_param *retry, char *extra)
579 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
582 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
583 /* first return min value, iwconfig will ask max value
585 retry->flags |= IW_RETRY_LIMIT;
586 retry->value = local->hw.conf.short_frame_max_tx_count;
587 if (local->hw.conf.long_frame_max_tx_count !=
588 local->hw.conf.short_frame_max_tx_count)
589 retry->flags |= IW_RETRY_MIN;
592 if (retry->flags & IW_RETRY_MAX) {
593 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
594 retry->value = local->hw.conf.long_frame_max_tx_count;
601 static int ieee80211_ioctl_siwencode(struct net_device *dev,
602 struct iw_request_info *info,
603 struct iw_point *erq, char *keybuf)
605 struct ieee80211_sub_if_data *sdata;
606 int idx, i, alg = ALG_WEP;
607 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
610 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
612 idx = erq->flags & IW_ENCODE_INDEX;
614 if (sdata->default_key)
615 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
616 if (sdata->default_key == sdata->keys[i]) {
621 } else if (idx < 1 || idx > 4)
626 if (erq->flags & IW_ENCODE_DISABLED)
628 else if (erq->length == 0) {
629 /* No key data - just set the default TX key index */
630 ieee80211_set_default_key(sdata, idx);
634 ret = ieee80211_set_encryption(
638 keybuf, erq->length);
640 if (!ret && sdata->vif.type == NL80211_IFTYPE_STATION) {
642 sdata->u.mgd.flags &= ~IEEE80211_STA_TKIP_WEP_USED;
644 sdata->u.mgd.flags |= IEEE80211_STA_TKIP_WEP_USED;
651 static int ieee80211_ioctl_giwencode(struct net_device *dev,
652 struct iw_request_info *info,
653 struct iw_point *erq, char *key)
655 struct ieee80211_sub_if_data *sdata;
658 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
660 idx = erq->flags & IW_ENCODE_INDEX;
661 if (idx < 1 || idx > 4) {
663 if (!sdata->default_key)
665 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
666 if (sdata->default_key == sdata->keys[i]) {
676 erq->flags = idx + 1;
678 if (!sdata->keys[idx]) {
680 erq->flags |= IW_ENCODE_DISABLED;
684 memcpy(key, sdata->keys[idx]->conf.key,
685 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
686 erq->length = sdata->keys[idx]->conf.keylen;
687 erq->flags |= IW_ENCODE_ENABLED;
689 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
690 switch (sdata->u.mgd.auth_alg) {
693 erq->flags |= IW_ENCODE_OPEN;
695 case WLAN_AUTH_SHARED_KEY:
696 erq->flags |= IW_ENCODE_RESTRICTED;
704 static int ieee80211_ioctl_siwpower(struct net_device *dev,
705 struct iw_request_info *info,
706 struct iw_param *wrq,
709 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
710 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
711 struct ieee80211_conf *conf = &local->hw.conf;
715 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
718 if (sdata->vif.type != NL80211_IFTYPE_STATION)
727 switch (wrq->flags & IW_POWER_MODE) {
728 case IW_POWER_ON: /* If not specified */
729 case IW_POWER_MODE: /* If set all mask */
730 case IW_POWER_ALL_R: /* If explicitely state all */
733 default: /* Otherwise we ignore */
737 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
740 if (wrq->flags & IW_POWER_TIMEOUT)
741 timeout = wrq->value / 1000;
744 if (ps == sdata->u.mgd.powersave && timeout == conf->dynamic_ps_timeout)
747 sdata->u.mgd.powersave = ps;
748 conf->dynamic_ps_timeout = timeout;
750 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
751 ieee80211_hw_config(local,
752 IEEE80211_CONF_CHANGE_DYNPS_TIMEOUT);
754 ieee80211_recalc_ps(local, -1);
759 static int ieee80211_ioctl_giwpower(struct net_device *dev,
760 struct iw_request_info *info,
761 union iwreq_data *wrqu,
764 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
766 wrqu->power.disabled = !sdata->u.mgd.powersave;
771 static int ieee80211_ioctl_siwauth(struct net_device *dev,
772 struct iw_request_info *info,
773 struct iw_param *data, char *extra)
775 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
778 switch (data->flags & IW_AUTH_INDEX) {
779 case IW_AUTH_WPA_VERSION:
780 case IW_AUTH_CIPHER_GROUP:
781 case IW_AUTH_WPA_ENABLED:
782 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
783 case IW_AUTH_KEY_MGMT:
784 case IW_AUTH_CIPHER_GROUP_MGMT:
786 case IW_AUTH_CIPHER_PAIRWISE:
787 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
788 if (data->value & (IW_AUTH_CIPHER_WEP40 |
789 IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP))
790 sdata->u.mgd.flags |=
791 IEEE80211_STA_TKIP_WEP_USED;
793 sdata->u.mgd.flags &=
794 ~IEEE80211_STA_TKIP_WEP_USED;
797 case IW_AUTH_DROP_UNENCRYPTED:
798 sdata->drop_unencrypted = !!data->value;
800 case IW_AUTH_PRIVACY_INVOKED:
801 if (sdata->vif.type != NL80211_IFTYPE_STATION)
804 sdata->u.mgd.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
806 * Privacy invoked by wpa_supplicant, store the
807 * value and allow associating to a protected
808 * network without having a key up front.
811 sdata->u.mgd.flags |=
812 IEEE80211_STA_PRIVACY_INVOKED;
815 case IW_AUTH_80211_AUTH_ALG:
816 if (sdata->vif.type == NL80211_IFTYPE_STATION)
817 sdata->u.mgd.auth_algs = data->value;
822 if (!(sdata->local->hw.flags & IEEE80211_HW_MFP_CAPABLE)) {
826 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
827 switch (data->value) {
828 case IW_AUTH_MFP_DISABLED:
829 sdata->u.mgd.mfp = IEEE80211_MFP_DISABLED;
831 case IW_AUTH_MFP_OPTIONAL:
832 sdata->u.mgd.mfp = IEEE80211_MFP_OPTIONAL;
834 case IW_AUTH_MFP_REQUIRED:
835 sdata->u.mgd.mfp = IEEE80211_MFP_REQUIRED;
850 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
851 static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
853 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
854 struct iw_statistics *wstats = &local->wstats;
855 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
856 struct sta_info *sta = NULL;
860 if (sdata->vif.type == NL80211_IFTYPE_STATION)
861 sta = sta_info_get(local, sdata->u.mgd.bssid);
864 wstats->discard.fragment = 0;
865 wstats->discard.misc = 0;
866 wstats->qual.qual = 0;
867 wstats->qual.level = 0;
868 wstats->qual.noise = 0;
869 wstats->qual.updated = IW_QUAL_ALL_INVALID;
871 wstats->qual.updated = 0;
873 * mirror what cfg80211 does for iwrange/scan results,
874 * otherwise userspace gets confused.
876 if (local->hw.flags & (IEEE80211_HW_SIGNAL_UNSPEC |
877 IEEE80211_HW_SIGNAL_DBM)) {
878 wstats->qual.updated |= IW_QUAL_LEVEL_UPDATED;
879 wstats->qual.updated |= IW_QUAL_QUAL_UPDATED;
881 wstats->qual.updated |= IW_QUAL_LEVEL_INVALID;
882 wstats->qual.updated |= IW_QUAL_QUAL_INVALID;
885 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) {
886 wstats->qual.level = sta->last_signal;
887 wstats->qual.qual = sta->last_signal;
888 } else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
889 int sig = sta->last_signal;
891 wstats->qual.updated |= IW_QUAL_DBM;
892 wstats->qual.level = sig;
897 wstats->qual.qual = sig + 110;
900 if (local->hw.flags & IEEE80211_HW_NOISE_DBM) {
902 * This assumes that if driver reports noise, it also
903 * reports signal in dBm.
905 wstats->qual.noise = sta->last_noise;
906 wstats->qual.updated |= IW_QUAL_NOISE_UPDATED;
908 wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
917 static int ieee80211_ioctl_giwauth(struct net_device *dev,
918 struct iw_request_info *info,
919 struct iw_param *data, char *extra)
921 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
924 switch (data->flags & IW_AUTH_INDEX) {
925 case IW_AUTH_80211_AUTH_ALG:
926 if (sdata->vif.type == NL80211_IFTYPE_STATION)
927 data->value = sdata->u.mgd.auth_algs;
939 static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
940 struct iw_request_info *info,
941 struct iw_point *erq, char *extra)
943 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
944 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
945 int uninitialized_var(alg), idx, i, remove = 0;
948 case IW_ENCODE_ALG_NONE:
951 case IW_ENCODE_ALG_WEP:
954 case IW_ENCODE_ALG_TKIP:
957 case IW_ENCODE_ALG_CCMP:
960 case IW_ENCODE_ALG_AES_CMAC:
967 if (erq->flags & IW_ENCODE_DISABLED)
970 idx = erq->flags & IW_ENCODE_INDEX;
971 if (alg == ALG_AES_CMAC) {
972 if (idx < NUM_DEFAULT_KEYS + 1 ||
973 idx > NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) {
975 if (!sdata->default_mgmt_key)
977 else for (i = NUM_DEFAULT_KEYS;
978 i < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS;
980 if (sdata->default_mgmt_key == sdata->keys[i])
991 if (idx < 1 || idx > 4) {
993 if (!sdata->default_key)
995 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
996 if (sdata->default_key == sdata->keys[i]) {
1007 return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg,
1010 IW_ENCODE_EXT_SET_TX_KEY,
1011 ext->key, ext->key_len);
1015 /* Structures to export the Wireless Handlers */
1017 static const iw_handler ieee80211_handler[] =
1019 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1020 (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */
1021 (iw_handler) NULL, /* SIOCSIWNWID */
1022 (iw_handler) NULL, /* SIOCGIWNWID */
1023 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1024 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1025 (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */
1026 (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */
1027 (iw_handler) NULL, /* SIOCSIWSENS */
1028 (iw_handler) NULL, /* SIOCGIWSENS */
1029 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1030 (iw_handler) cfg80211_wext_giwrange, /* SIOCGIWRANGE */
1031 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1032 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1033 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1034 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
1035 (iw_handler) NULL, /* SIOCSIWSPY */
1036 (iw_handler) NULL, /* SIOCGIWSPY */
1037 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1038 (iw_handler) NULL, /* SIOCGIWTHRSPY */
1039 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1040 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1041 (iw_handler) cfg80211_wext_siwmlme, /* SIOCSIWMLME */
1042 (iw_handler) NULL, /* SIOCGIWAPLIST */
1043 (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */
1044 (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */
1045 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1046 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1047 (iw_handler) NULL, /* SIOCSIWNICKN */
1048 (iw_handler) NULL, /* SIOCGIWNICKN */
1049 (iw_handler) NULL, /* -- hole -- */
1050 (iw_handler) NULL, /* -- hole -- */
1051 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
1052 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
1053 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1054 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1055 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1056 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
1057 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
1058 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
1059 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1060 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1061 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1062 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
1063 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
1064 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
1065 (iw_handler) NULL, /* -- hole -- */
1066 (iw_handler) NULL, /* -- hole -- */
1067 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1068 (iw_handler) NULL, /* SIOCGIWGENIE */
1069 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1070 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1071 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1072 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1073 (iw_handler) NULL, /* SIOCSIWPMKSA */
1074 (iw_handler) NULL, /* -- hole -- */
1077 const struct iw_handler_def ieee80211_iw_handler_def =
1079 .num_standard = ARRAY_SIZE(ieee80211_handler),
1080 .standard = (iw_handler *) ieee80211_handler,
1081 .get_wireless_stats = ieee80211_get_wireless_stats,