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
->oper_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_siwencode(struct net_device
*dev
,
476 struct iw_request_info
*info
,
477 struct iw_point
*erq
, char *keybuf
)
479 struct ieee80211_sub_if_data
*sdata
;
480 int idx
, i
, alg
= ALG_WEP
;
481 u8 bcaddr
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
484 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
486 idx
= erq
->flags
& IW_ENCODE_INDEX
;
488 if (sdata
->default_key
)
489 for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
490 if (sdata
->default_key
== sdata
->keys
[i
]) {
495 } else if (idx
< 1 || idx
> 4)
500 if (erq
->flags
& IW_ENCODE_DISABLED
)
502 else if (erq
->length
== 0) {
503 /* No key data - just set the default TX key index */
504 ieee80211_set_default_key(sdata
, idx
);
508 ret
= ieee80211_set_encryption(
512 keybuf
, erq
->length
);
514 if (!ret
&& sdata
->vif
.type
== NL80211_IFTYPE_STATION
) {
516 sdata
->u
.mgd
.flags
&= ~IEEE80211_STA_TKIP_WEP_USED
;
518 sdata
->u
.mgd
.flags
|= IEEE80211_STA_TKIP_WEP_USED
;
525 static int ieee80211_ioctl_giwencode(struct net_device
*dev
,
526 struct iw_request_info
*info
,
527 struct iw_point
*erq
, char *key
)
529 struct ieee80211_sub_if_data
*sdata
;
532 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
534 idx
= erq
->flags
& IW_ENCODE_INDEX
;
535 if (idx
< 1 || idx
> 4) {
537 if (!sdata
->default_key
)
539 else for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
540 if (sdata
->default_key
== sdata
->keys
[i
]) {
550 erq
->flags
= idx
+ 1;
552 if (!sdata
->keys
[idx
]) {
554 erq
->flags
|= IW_ENCODE_DISABLED
;
558 memcpy(key
, sdata
->keys
[idx
]->conf
.key
,
559 min_t(int, erq
->length
, sdata
->keys
[idx
]->conf
.keylen
));
560 erq
->length
= sdata
->keys
[idx
]->conf
.keylen
;
561 erq
->flags
|= IW_ENCODE_ENABLED
;
563 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
) {
564 switch (sdata
->u
.mgd
.auth_alg
) {
567 erq
->flags
|= IW_ENCODE_OPEN
;
569 case WLAN_AUTH_SHARED_KEY
:
570 erq
->flags
|= IW_ENCODE_RESTRICTED
;
578 static int ieee80211_ioctl_siwpower(struct net_device
*dev
,
579 struct iw_request_info
*info
,
580 struct iw_param
*wrq
,
583 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
584 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
585 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
589 if (!(local
->hw
.flags
& IEEE80211_HW_SUPPORTS_PS
))
592 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
601 switch (wrq
->flags
& IW_POWER_MODE
) {
602 case IW_POWER_ON
: /* If not specified */
603 case IW_POWER_MODE
: /* If set all mask */
604 case IW_POWER_ALL_R
: /* If explicitely state all */
607 default: /* Otherwise we ignore */
611 if (wrq
->flags
& ~(IW_POWER_MODE
| IW_POWER_TIMEOUT
))
614 if (wrq
->flags
& IW_POWER_TIMEOUT
)
615 timeout
= wrq
->value
/ 1000;
618 if (ps
== sdata
->u
.mgd
.powersave
&& timeout
== conf
->dynamic_ps_timeout
)
621 sdata
->u
.mgd
.powersave
= ps
;
622 conf
->dynamic_ps_timeout
= timeout
;
624 if (local
->hw
.flags
& IEEE80211_HW_SUPPORTS_DYNAMIC_PS
)
625 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
627 ieee80211_recalc_ps(local
, -1);
632 static int ieee80211_ioctl_giwpower(struct net_device
*dev
,
633 struct iw_request_info
*info
,
634 union iwreq_data
*wrqu
,
637 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
639 wrqu
->power
.disabled
= !sdata
->u
.mgd
.powersave
;
644 static int ieee80211_ioctl_siwauth(struct net_device
*dev
,
645 struct iw_request_info
*info
,
646 struct iw_param
*data
, char *extra
)
648 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
651 switch (data
->flags
& IW_AUTH_INDEX
) {
652 case IW_AUTH_WPA_VERSION
:
653 case IW_AUTH_CIPHER_GROUP
:
654 case IW_AUTH_WPA_ENABLED
:
655 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
656 case IW_AUTH_KEY_MGMT
:
657 case IW_AUTH_CIPHER_GROUP_MGMT
:
659 case IW_AUTH_CIPHER_PAIRWISE
:
660 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
) {
661 if (data
->value
& (IW_AUTH_CIPHER_WEP40
|
662 IW_AUTH_CIPHER_WEP104
| IW_AUTH_CIPHER_TKIP
))
663 sdata
->u
.mgd
.flags
|=
664 IEEE80211_STA_TKIP_WEP_USED
;
666 sdata
->u
.mgd
.flags
&=
667 ~IEEE80211_STA_TKIP_WEP_USED
;
670 case IW_AUTH_DROP_UNENCRYPTED
:
671 sdata
->drop_unencrypted
= !!data
->value
;
673 case IW_AUTH_PRIVACY_INVOKED
:
674 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
677 sdata
->u
.mgd
.flags
&= ~IEEE80211_STA_PRIVACY_INVOKED
;
679 * Privacy invoked by wpa_supplicant, store the
680 * value and allow associating to a protected
681 * network without having a key up front.
684 sdata
->u
.mgd
.flags
|=
685 IEEE80211_STA_PRIVACY_INVOKED
;
688 case IW_AUTH_80211_AUTH_ALG
:
689 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
)
690 sdata
->u
.mgd
.auth_algs
= data
->value
;
695 if (!(sdata
->local
->hw
.flags
& IEEE80211_HW_MFP_CAPABLE
)) {
699 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
) {
700 switch (data
->value
) {
701 case IW_AUTH_MFP_DISABLED
:
702 sdata
->u
.mgd
.mfp
= IEEE80211_MFP_DISABLED
;
704 case IW_AUTH_MFP_OPTIONAL
:
705 sdata
->u
.mgd
.mfp
= IEEE80211_MFP_OPTIONAL
;
707 case IW_AUTH_MFP_REQUIRED
:
708 sdata
->u
.mgd
.mfp
= IEEE80211_MFP_REQUIRED
;
723 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
724 static struct iw_statistics
*ieee80211_get_wireless_stats(struct net_device
*dev
)
726 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
727 struct iw_statistics
*wstats
= &local
->wstats
;
728 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
729 struct sta_info
*sta
= NULL
;
733 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
)
734 sta
= sta_info_get(local
, sdata
->u
.mgd
.bssid
);
737 wstats
->discard
.fragment
= 0;
738 wstats
->discard
.misc
= 0;
739 wstats
->qual
.qual
= 0;
740 wstats
->qual
.level
= 0;
741 wstats
->qual
.noise
= 0;
742 wstats
->qual
.updated
= IW_QUAL_ALL_INVALID
;
744 wstats
->qual
.updated
= 0;
746 * mirror what cfg80211 does for iwrange/scan results,
747 * otherwise userspace gets confused.
749 if (local
->hw
.flags
& (IEEE80211_HW_SIGNAL_UNSPEC
|
750 IEEE80211_HW_SIGNAL_DBM
)) {
751 wstats
->qual
.updated
|= IW_QUAL_LEVEL_UPDATED
;
752 wstats
->qual
.updated
|= IW_QUAL_QUAL_UPDATED
;
754 wstats
->qual
.updated
|= IW_QUAL_LEVEL_INVALID
;
755 wstats
->qual
.updated
|= IW_QUAL_QUAL_INVALID
;
758 if (local
->hw
.flags
& IEEE80211_HW_SIGNAL_UNSPEC
) {
759 wstats
->qual
.level
= sta
->last_signal
;
760 wstats
->qual
.qual
= sta
->last_signal
;
761 } else if (local
->hw
.flags
& IEEE80211_HW_SIGNAL_DBM
) {
762 int sig
= sta
->last_signal
;
764 wstats
->qual
.updated
|= IW_QUAL_DBM
;
765 wstats
->qual
.level
= sig
;
770 wstats
->qual
.qual
= sig
+ 110;
773 if (local
->hw
.flags
& IEEE80211_HW_NOISE_DBM
) {
775 * This assumes that if driver reports noise, it also
776 * reports signal in dBm.
778 wstats
->qual
.noise
= sta
->last_noise
;
779 wstats
->qual
.updated
|= IW_QUAL_NOISE_UPDATED
;
781 wstats
->qual
.updated
|= IW_QUAL_NOISE_INVALID
;
790 static int ieee80211_ioctl_giwauth(struct net_device
*dev
,
791 struct iw_request_info
*info
,
792 struct iw_param
*data
, char *extra
)
794 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
797 switch (data
->flags
& IW_AUTH_INDEX
) {
798 case IW_AUTH_80211_AUTH_ALG
:
799 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
)
800 data
->value
= sdata
->u
.mgd
.auth_algs
;
812 static int ieee80211_ioctl_siwencodeext(struct net_device
*dev
,
813 struct iw_request_info
*info
,
814 struct iw_point
*erq
, char *extra
)
816 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
817 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*) extra
;
818 int uninitialized_var(alg
), idx
, i
, remove
= 0;
821 case IW_ENCODE_ALG_NONE
:
824 case IW_ENCODE_ALG_WEP
:
827 case IW_ENCODE_ALG_TKIP
:
830 case IW_ENCODE_ALG_CCMP
:
833 case IW_ENCODE_ALG_AES_CMAC
:
840 if (erq
->flags
& IW_ENCODE_DISABLED
)
843 idx
= erq
->flags
& IW_ENCODE_INDEX
;
844 if (alg
== ALG_AES_CMAC
) {
845 if (idx
< NUM_DEFAULT_KEYS
+ 1 ||
846 idx
> NUM_DEFAULT_KEYS
+ NUM_DEFAULT_MGMT_KEYS
) {
848 if (!sdata
->default_mgmt_key
)
850 else for (i
= NUM_DEFAULT_KEYS
;
851 i
< NUM_DEFAULT_KEYS
+ NUM_DEFAULT_MGMT_KEYS
;
853 if (sdata
->default_mgmt_key
== sdata
->keys
[i
])
864 if (idx
< 1 || idx
> 4) {
866 if (!sdata
->default_key
)
868 else for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
869 if (sdata
->default_key
== sdata
->keys
[i
]) {
880 return ieee80211_set_encryption(sdata
, ext
->addr
.sa_data
, idx
, alg
,
883 IW_ENCODE_EXT_SET_TX_KEY
,
884 ext
->key
, ext
->key_len
);
888 /* Structures to export the Wireless Handlers */
890 static const iw_handler ieee80211_handler
[] =
892 (iw_handler
) NULL
, /* SIOCSIWCOMMIT */
893 (iw_handler
) cfg80211_wext_giwname
, /* SIOCGIWNAME */
894 (iw_handler
) NULL
, /* SIOCSIWNWID */
895 (iw_handler
) NULL
, /* SIOCGIWNWID */
896 (iw_handler
) ieee80211_ioctl_siwfreq
, /* SIOCSIWFREQ */
897 (iw_handler
) ieee80211_ioctl_giwfreq
, /* SIOCGIWFREQ */
898 (iw_handler
) cfg80211_wext_siwmode
, /* SIOCSIWMODE */
899 (iw_handler
) cfg80211_wext_giwmode
, /* SIOCGIWMODE */
900 (iw_handler
) NULL
, /* SIOCSIWSENS */
901 (iw_handler
) NULL
, /* SIOCGIWSENS */
902 (iw_handler
) NULL
/* not used */, /* SIOCSIWRANGE */
903 (iw_handler
) cfg80211_wext_giwrange
, /* SIOCGIWRANGE */
904 (iw_handler
) NULL
/* not used */, /* SIOCSIWPRIV */
905 (iw_handler
) NULL
/* kernel code */, /* SIOCGIWPRIV */
906 (iw_handler
) NULL
/* not used */, /* SIOCSIWSTATS */
907 (iw_handler
) NULL
/* kernel code */, /* SIOCGIWSTATS */
908 (iw_handler
) NULL
, /* SIOCSIWSPY */
909 (iw_handler
) NULL
, /* SIOCGIWSPY */
910 (iw_handler
) NULL
, /* SIOCSIWTHRSPY */
911 (iw_handler
) NULL
, /* SIOCGIWTHRSPY */
912 (iw_handler
) ieee80211_ioctl_siwap
, /* SIOCSIWAP */
913 (iw_handler
) ieee80211_ioctl_giwap
, /* SIOCGIWAP */
914 (iw_handler
) cfg80211_wext_siwmlme
, /* SIOCSIWMLME */
915 (iw_handler
) NULL
, /* SIOCGIWAPLIST */
916 (iw_handler
) cfg80211_wext_siwscan
, /* SIOCSIWSCAN */
917 (iw_handler
) cfg80211_wext_giwscan
, /* SIOCGIWSCAN */
918 (iw_handler
) ieee80211_ioctl_siwessid
, /* SIOCSIWESSID */
919 (iw_handler
) ieee80211_ioctl_giwessid
, /* SIOCGIWESSID */
920 (iw_handler
) NULL
, /* SIOCSIWNICKN */
921 (iw_handler
) NULL
, /* SIOCGIWNICKN */
922 (iw_handler
) NULL
, /* -- hole -- */
923 (iw_handler
) NULL
, /* -- hole -- */
924 (iw_handler
) ieee80211_ioctl_siwrate
, /* SIOCSIWRATE */
925 (iw_handler
) ieee80211_ioctl_giwrate
, /* SIOCGIWRATE */
926 (iw_handler
) cfg80211_wext_siwrts
, /* SIOCSIWRTS */
927 (iw_handler
) cfg80211_wext_giwrts
, /* SIOCGIWRTS */
928 (iw_handler
) cfg80211_wext_siwfrag
, /* SIOCSIWFRAG */
929 (iw_handler
) cfg80211_wext_giwfrag
, /* SIOCGIWFRAG */
930 (iw_handler
) ieee80211_ioctl_siwtxpower
, /* SIOCSIWTXPOW */
931 (iw_handler
) ieee80211_ioctl_giwtxpower
, /* SIOCGIWTXPOW */
932 (iw_handler
) cfg80211_wext_siwretry
, /* SIOCSIWRETRY */
933 (iw_handler
) cfg80211_wext_giwretry
, /* SIOCGIWRETRY */
934 (iw_handler
) ieee80211_ioctl_siwencode
, /* SIOCSIWENCODE */
935 (iw_handler
) ieee80211_ioctl_giwencode
, /* SIOCGIWENCODE */
936 (iw_handler
) ieee80211_ioctl_siwpower
, /* SIOCSIWPOWER */
937 (iw_handler
) ieee80211_ioctl_giwpower
, /* SIOCGIWPOWER */
938 (iw_handler
) NULL
, /* -- hole -- */
939 (iw_handler
) NULL
, /* -- hole -- */
940 (iw_handler
) ieee80211_ioctl_siwgenie
, /* SIOCSIWGENIE */
941 (iw_handler
) NULL
, /* SIOCGIWGENIE */
942 (iw_handler
) ieee80211_ioctl_siwauth
, /* SIOCSIWAUTH */
943 (iw_handler
) ieee80211_ioctl_giwauth
, /* SIOCGIWAUTH */
944 (iw_handler
) ieee80211_ioctl_siwencodeext
, /* SIOCSIWENCODEEXT */
945 (iw_handler
) NULL
, /* SIOCGIWENCODEEXT */
946 (iw_handler
) NULL
, /* SIOCSIWPMKSA */
947 (iw_handler
) NULL
, /* -- hole -- */
950 const struct iw_handler_def ieee80211_iw_handler_def
=
952 .num_standard
= ARRAY_SIZE(ieee80211_handler
),
953 .standard
= (iw_handler
*) ieee80211_handler
,
954 .get_wireless_stats
= ieee80211_get_wireless_stats
,