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 (idx
< 0 || idx
>= NUM_DEFAULT_KEYS
) {
41 printk(KERN_DEBUG
"%s: set_encrypt - invalid idx=%d\n",
42 sdata
->dev
->name
, idx
);
51 if (is_broadcast_ether_addr(sta_addr
)) {
52 key
= sdata
->keys
[idx
];
54 sta
= sta_info_get(local
, sta_addr
);
62 ieee80211_key_free(key
);
64 key
= ieee80211_key_alloc(alg
, idx
, key_len
, _key
);
73 if (!is_broadcast_ether_addr(sta_addr
)) {
76 * According to the standard, the key index of a
77 * pairwise key must be zero. However, some AP are
78 * broken when it comes to WEP key indices, so we
81 if (idx
!= 0 && alg
!= ALG_WEP
) {
82 ieee80211_key_free(key
);
87 sta
= sta_info_get(local
, sta_addr
);
89 ieee80211_key_free(key
);
96 key_len
!= LEN_WEP40
&& key_len
!= LEN_WEP104
) {
97 ieee80211_key_free(key
);
102 ieee80211_key_link(key
, sdata
, sta
);
104 if (set_tx_key
|| (!sta
&& !sdata
->default_key
&& key
))
105 ieee80211_set_default_key(sdata
, idx
);
114 static int ieee80211_ioctl_siwgenie(struct net_device
*dev
,
115 struct iw_request_info
*info
,
116 struct iw_point
*data
, char *extra
)
118 struct ieee80211_sub_if_data
*sdata
;
120 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
122 if (sdata
->flags
& IEEE80211_SDATA_USERSPACE_MLME
)
125 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
126 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
127 int ret
= ieee80211_sta_set_extra_ie(sdata
, extra
, data
->length
);
130 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_AUTO_BSSID_SEL
;
131 ieee80211_sta_req_auth(sdata
, &sdata
->u
.sta
);
138 static int ieee80211_ioctl_giwname(struct net_device
*dev
,
139 struct iw_request_info
*info
,
140 char *name
, char *extra
)
142 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
143 struct ieee80211_supported_band
*sband
;
144 u8 is_ht
= 0, is_a
= 0, is_b
= 0, is_g
= 0;
147 sband
= local
->hw
.wiphy
->bands
[IEEE80211_BAND_5GHZ
];
150 is_ht
|= sband
->ht_info
.ht_supported
;
153 sband
= local
->hw
.wiphy
->bands
[IEEE80211_BAND_2GHZ
];
156 /* Check for mandatory rates */
157 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
158 if (sband
->bitrates
[i
].bitrate
== 10)
160 if (sband
->bitrates
[i
].bitrate
== 60)
163 is_ht
|= sband
->ht_info
.ht_supported
;
166 strcpy(name
, "IEEE 802.11");
180 static int ieee80211_ioctl_giwrange(struct net_device
*dev
,
181 struct iw_request_info
*info
,
182 struct iw_point
*data
, char *extra
)
184 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
185 struct iw_range
*range
= (struct iw_range
*) extra
;
186 enum ieee80211_band band
;
189 data
->length
= sizeof(struct iw_range
);
190 memset(range
, 0, sizeof(struct iw_range
));
192 range
->we_version_compiled
= WIRELESS_EXT
;
193 range
->we_version_source
= 21;
194 range
->retry_capa
= IW_RETRY_LIMIT
;
195 range
->retry_flags
= IW_RETRY_LIMIT
;
196 range
->min_retry
= 0;
197 range
->max_retry
= 255;
199 range
->max_rts
= 2347;
200 range
->min_frag
= 256;
201 range
->max_frag
= 2346;
203 range
->encoding_size
[0] = 5;
204 range
->encoding_size
[1] = 13;
205 range
->num_encoding_sizes
= 2;
206 range
->max_encoding_tokens
= NUM_DEFAULT_KEYS
;
208 if (local
->hw
.flags
& IEEE80211_HW_SIGNAL_UNSPEC
||
209 local
->hw
.flags
& IEEE80211_HW_SIGNAL_DB
)
210 range
->max_qual
.level
= local
->hw
.max_signal
;
211 else if (local
->hw
.flags
& IEEE80211_HW_SIGNAL_DBM
)
212 range
->max_qual
.level
= -110;
214 range
->max_qual
.level
= 0;
216 if (local
->hw
.flags
& IEEE80211_HW_NOISE_DBM
)
217 range
->max_qual
.noise
= -110;
219 range
->max_qual
.noise
= 0;
221 range
->max_qual
.qual
= 100;
222 range
->max_qual
.updated
= local
->wstats_flags
;
224 range
->avg_qual
.qual
= 50;
225 /* not always true but better than nothing */
226 range
->avg_qual
.level
= range
->max_qual
.level
/ 2;
227 range
->avg_qual
.noise
= range
->max_qual
.noise
/ 2;
228 range
->avg_qual
.updated
= local
->wstats_flags
;
230 range
->enc_capa
= IW_ENC_CAPA_WPA
| IW_ENC_CAPA_WPA2
|
231 IW_ENC_CAPA_CIPHER_TKIP
| IW_ENC_CAPA_CIPHER_CCMP
;
234 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
236 struct ieee80211_supported_band
*sband
;
238 sband
= local
->hw
.wiphy
->bands
[band
];
243 for (i
= 0; i
< sband
->n_channels
&& c
< IW_MAX_FREQUENCIES
; i
++) {
244 struct ieee80211_channel
*chan
= &sband
->channels
[i
];
246 if (!(chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
248 ieee80211_frequency_to_channel(
250 range
->freq
[c
].m
= chan
->center_freq
;
251 range
->freq
[c
].e
= 6;
256 range
->num_channels
= c
;
257 range
->num_frequency
= c
;
259 IW_EVENT_CAPA_SET_KERNEL(range
->event_capa
);
260 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWAP
);
261 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWSCAN
);
263 range
->scan_capa
|= IW_SCAN_CAPA_ESSID
;
269 static int ieee80211_ioctl_siwmode(struct net_device
*dev
,
270 struct iw_request_info
*info
,
271 __u32
*mode
, char *extra
)
273 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
276 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_VLAN
)
281 type
= IEEE80211_IF_TYPE_STA
;
284 type
= IEEE80211_IF_TYPE_IBSS
;
287 type
= IEEE80211_IF_TYPE_WDS
;
289 case IW_MODE_MONITOR
:
290 type
= IEEE80211_IF_TYPE_MNTR
;
296 return ieee80211_if_change_type(sdata
, type
);
300 static int ieee80211_ioctl_giwmode(struct net_device
*dev
,
301 struct iw_request_info
*info
,
302 __u32
*mode
, char *extra
)
304 struct ieee80211_sub_if_data
*sdata
;
306 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
307 switch (sdata
->vif
.type
) {
308 case IEEE80211_IF_TYPE_AP
:
309 *mode
= IW_MODE_MASTER
;
311 case IEEE80211_IF_TYPE_STA
:
312 *mode
= IW_MODE_INFRA
;
314 case IEEE80211_IF_TYPE_IBSS
:
315 *mode
= IW_MODE_ADHOC
;
317 case IEEE80211_IF_TYPE_MNTR
:
318 *mode
= IW_MODE_MONITOR
;
320 case IEEE80211_IF_TYPE_WDS
:
321 *mode
= IW_MODE_REPEAT
;
323 case IEEE80211_IF_TYPE_VLAN
:
324 *mode
= IW_MODE_SECOND
; /* FIXME */
327 *mode
= IW_MODE_AUTO
;
333 int ieee80211_set_freq(struct ieee80211_sub_if_data
*sdata
, int freqMHz
)
336 struct ieee80211_channel
*chan
;
337 struct ieee80211_local
*local
= sdata
->local
;
339 chan
= ieee80211_get_channel(local
->hw
.wiphy
, freqMHz
);
341 if (chan
&& !(chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
342 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&&
343 chan
->flags
& IEEE80211_CHAN_NO_IBSS
) {
344 printk(KERN_DEBUG
"%s: IBSS not allowed on frequency "
345 "%d MHz\n", sdata
->dev
->name
, chan
->center_freq
);
348 local
->oper_channel
= chan
;
350 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
)
353 ret
= ieee80211_hw_config(local
);
355 rate_control_clear(local
);
361 static int ieee80211_ioctl_siwfreq(struct net_device
*dev
,
362 struct iw_request_info
*info
,
363 struct iw_freq
*freq
, char *extra
)
365 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
367 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
)
368 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_AUTO_CHANNEL_SEL
;
370 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
373 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
)
374 sdata
->u
.sta
.flags
|=
375 IEEE80211_STA_AUTO_CHANNEL_SEL
;
378 return ieee80211_set_freq(sdata
,
379 ieee80211_channel_to_frequency(freq
->m
));
381 int i
, div
= 1000000;
382 for (i
= 0; i
< freq
->e
; i
++)
385 return ieee80211_set_freq(sdata
, freq
->m
/ div
);
392 static int ieee80211_ioctl_giwfreq(struct net_device
*dev
,
393 struct iw_request_info
*info
,
394 struct iw_freq
*freq
, char *extra
)
396 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
398 freq
->m
= local
->hw
.conf
.channel
->center_freq
;
405 static int ieee80211_ioctl_siwessid(struct net_device
*dev
,
406 struct iw_request_info
*info
,
407 struct iw_point
*data
, char *ssid
)
409 struct ieee80211_sub_if_data
*sdata
;
410 size_t len
= data
->length
;
412 /* iwconfig uses nul termination in SSID.. */
413 if (len
> 0 && ssid
[len
- 1] == '\0')
416 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
417 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
418 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
420 if (sdata
->flags
& IEEE80211_SDATA_USERSPACE_MLME
) {
421 if (len
> IEEE80211_MAX_SSID_LEN
)
423 memcpy(sdata
->u
.sta
.ssid
, ssid
, len
);
424 sdata
->u
.sta
.ssid_len
= len
;
428 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_AUTO_SSID_SEL
;
430 sdata
->u
.sta
.flags
|= IEEE80211_STA_AUTO_SSID_SEL
;
431 ret
= ieee80211_sta_set_ssid(sdata
, ssid
, len
);
434 ieee80211_sta_req_auth(sdata
, &sdata
->u
.sta
);
438 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
) {
439 memcpy(sdata
->u
.ap
.ssid
, ssid
, len
);
440 memset(sdata
->u
.ap
.ssid
+ len
, 0,
441 IEEE80211_MAX_SSID_LEN
- len
);
442 sdata
->u
.ap
.ssid_len
= len
;
443 return ieee80211_if_config(sdata
, IEEE80211_IFCC_SSID
);
449 static int ieee80211_ioctl_giwessid(struct net_device
*dev
,
450 struct iw_request_info
*info
,
451 struct iw_point
*data
, char *ssid
)
455 struct ieee80211_sub_if_data
*sdata
;
456 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
457 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
458 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
459 int res
= ieee80211_sta_get_ssid(sdata
, ssid
, &len
);
468 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
) {
469 len
= sdata
->u
.ap
.ssid_len
;
470 if (len
> IW_ESSID_MAX_SIZE
)
471 len
= IW_ESSID_MAX_SIZE
;
472 memcpy(ssid
, sdata
->u
.ap
.ssid
, len
);
481 static int ieee80211_ioctl_siwap(struct net_device
*dev
,
482 struct iw_request_info
*info
,
483 struct sockaddr
*ap_addr
, char *extra
)
485 struct ieee80211_sub_if_data
*sdata
;
487 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
488 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
489 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
491 if (sdata
->flags
& IEEE80211_SDATA_USERSPACE_MLME
) {
492 memcpy(sdata
->u
.sta
.bssid
, (u8
*) &ap_addr
->sa_data
,
496 if (is_zero_ether_addr((u8
*) &ap_addr
->sa_data
))
497 sdata
->u
.sta
.flags
|= IEEE80211_STA_AUTO_BSSID_SEL
|
498 IEEE80211_STA_AUTO_CHANNEL_SEL
;
499 else if (is_broadcast_ether_addr((u8
*) &ap_addr
->sa_data
))
500 sdata
->u
.sta
.flags
|= IEEE80211_STA_AUTO_BSSID_SEL
;
502 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_AUTO_BSSID_SEL
;
503 ret
= ieee80211_sta_set_bssid(sdata
, (u8
*) &ap_addr
->sa_data
);
506 ieee80211_sta_req_auth(sdata
, &sdata
->u
.sta
);
508 } else if (sdata
->vif
.type
== IEEE80211_IF_TYPE_WDS
) {
510 * If it is necessary to update the WDS peer address
511 * while the interface is running, then we need to do
512 * more work here, namely if it is running we need to
513 * add a new and remove the old STA entry, this is
514 * normally handled by _open() and _stop().
516 if (netif_running(dev
))
519 memcpy(&sdata
->u
.wds
.remote_addr
, (u8
*) &ap_addr
->sa_data
,
529 static int ieee80211_ioctl_giwap(struct net_device
*dev
,
530 struct iw_request_info
*info
,
531 struct sockaddr
*ap_addr
, char *extra
)
533 struct ieee80211_sub_if_data
*sdata
;
535 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
536 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
537 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
538 if (sdata
->u
.sta
.state
== IEEE80211_ASSOCIATED
||
539 sdata
->u
.sta
.state
== IEEE80211_IBSS_JOINED
) {
540 ap_addr
->sa_family
= ARPHRD_ETHER
;
541 memcpy(&ap_addr
->sa_data
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
544 memset(&ap_addr
->sa_data
, 0, ETH_ALEN
);
547 } else if (sdata
->vif
.type
== IEEE80211_IF_TYPE_WDS
) {
548 ap_addr
->sa_family
= ARPHRD_ETHER
;
549 memcpy(&ap_addr
->sa_data
, sdata
->u
.wds
.remote_addr
, ETH_ALEN
);
557 static int ieee80211_ioctl_siwscan(struct net_device
*dev
,
558 struct iw_request_info
*info
,
559 union iwreq_data
*wrqu
, char *extra
)
561 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
562 struct iw_scan_req
*req
= NULL
;
566 if (!netif_running(dev
))
569 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
&&
570 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
571 sdata
->vif
.type
!= IEEE80211_IF_TYPE_MESH_POINT
&&
572 sdata
->vif
.type
!= IEEE80211_IF_TYPE_AP
)
575 /* if SSID was specified explicitly then use that */
576 if (wrqu
->data
.length
== sizeof(struct iw_scan_req
) &&
577 wrqu
->data
.flags
& IW_SCAN_THIS_ESSID
) {
578 req
= (struct iw_scan_req
*)extra
;
580 ssid_len
= req
->essid_len
;
583 return ieee80211_sta_req_scan(sdata
, ssid
, ssid_len
);
587 static int ieee80211_ioctl_giwscan(struct net_device
*dev
,
588 struct iw_request_info
*info
,
589 struct iw_point
*data
, char *extra
)
592 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
593 struct ieee80211_sub_if_data
*sdata
;
595 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
597 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
)
600 res
= ieee80211_sta_scan_results(local
, info
, extra
, data
->length
);
610 static int ieee80211_ioctl_siwrate(struct net_device
*dev
,
611 struct iw_request_info
*info
,
612 struct iw_param
*rate
, char *extra
)
614 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
615 int i
, err
= -EINVAL
;
616 u32 target_rate
= rate
->value
/ 100000;
617 struct ieee80211_sub_if_data
*sdata
;
618 struct ieee80211_supported_band
*sband
;
620 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
622 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
624 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
625 * target_rate = X, rate->fixed = 1 means only rate X
626 * target_rate = X, rate->fixed = 0 means all rates <= X */
627 sdata
->max_ratectrl_rateidx
= -1;
628 sdata
->force_unicast_rateidx
= -1;
632 for (i
=0; i
< sband
->n_bitrates
; i
++) {
633 struct ieee80211_rate
*brate
= &sband
->bitrates
[i
];
634 int this_rate
= brate
->bitrate
;
636 if (target_rate
== this_rate
) {
637 sdata
->max_ratectrl_rateidx
= i
;
639 sdata
->force_unicast_rateidx
= i
;
647 static int ieee80211_ioctl_giwrate(struct net_device
*dev
,
648 struct iw_request_info
*info
,
649 struct iw_param
*rate
, char *extra
)
651 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
652 struct sta_info
*sta
;
653 struct ieee80211_sub_if_data
*sdata
;
654 struct ieee80211_supported_band
*sband
;
656 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
658 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
661 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
665 sta
= sta_info_get(local
, sdata
->u
.sta
.bssid
);
667 if (sta
&& sta
->txrate_idx
< sband
->n_bitrates
)
668 rate
->value
= sband
->bitrates
[sta
->txrate_idx
].bitrate
;
677 rate
->value
*= 100000;
682 static int ieee80211_ioctl_siwtxpower(struct net_device
*dev
,
683 struct iw_request_info
*info
,
684 union iwreq_data
*data
, char *extra
)
686 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
687 bool need_reconfig
= 0;
690 if ((data
->txpower
.flags
& IW_TXPOW_TYPE
) != IW_TXPOW_DBM
)
692 if (data
->txpower
.flags
& IW_TXPOW_RANGE
)
695 if (data
->txpower
.fixed
) {
696 new_power_level
= data
->txpower
.value
;
699 * Automatic power level. Use maximum power for the current
700 * channel. Should be part of rate control.
702 struct ieee80211_channel
* chan
= local
->hw
.conf
.channel
;
706 new_power_level
= chan
->max_power
;
709 if (local
->hw
.conf
.power_level
!= new_power_level
) {
710 local
->hw
.conf
.power_level
= new_power_level
;
714 if (local
->hw
.conf
.radio_enabled
!= !(data
->txpower
.disabled
)) {
715 local
->hw
.conf
.radio_enabled
= !(data
->txpower
.disabled
);
717 ieee80211_led_radio(local
, local
->hw
.conf
.radio_enabled
);
721 ieee80211_hw_config(local
);
722 /* The return value of hw_config is not of big interest here,
723 * as it doesn't say that it failed because of _this_ config
724 * change or something else. Ignore it. */
730 static int ieee80211_ioctl_giwtxpower(struct net_device
*dev
,
731 struct iw_request_info
*info
,
732 union iwreq_data
*data
, char *extra
)
734 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
736 data
->txpower
.fixed
= 1;
737 data
->txpower
.disabled
= !(local
->hw
.conf
.radio_enabled
);
738 data
->txpower
.value
= local
->hw
.conf
.power_level
;
739 data
->txpower
.flags
= IW_TXPOW_DBM
;
744 static int ieee80211_ioctl_siwrts(struct net_device
*dev
,
745 struct iw_request_info
*info
,
746 struct iw_param
*rts
, char *extra
)
748 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
751 local
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
752 else if (!rts
->fixed
)
753 /* if the rts value is not fixed, then take default */
754 local
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
755 else if (rts
->value
< 0 || rts
->value
> IEEE80211_MAX_RTS_THRESHOLD
)
758 local
->rts_threshold
= rts
->value
;
760 /* If the wlan card performs RTS/CTS in hardware/firmware,
761 * configure it here */
763 if (local
->ops
->set_rts_threshold
)
764 local
->ops
->set_rts_threshold(local_to_hw(local
),
765 local
->rts_threshold
);
770 static int ieee80211_ioctl_giwrts(struct net_device
*dev
,
771 struct iw_request_info
*info
,
772 struct iw_param
*rts
, char *extra
)
774 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
776 rts
->value
= local
->rts_threshold
;
777 rts
->disabled
= (rts
->value
>= IEEE80211_MAX_RTS_THRESHOLD
);
784 static int ieee80211_ioctl_siwfrag(struct net_device
*dev
,
785 struct iw_request_info
*info
,
786 struct iw_param
*frag
, char *extra
)
788 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
791 local
->fragmentation_threshold
= IEEE80211_MAX_FRAG_THRESHOLD
;
792 else if (!frag
->fixed
)
793 local
->fragmentation_threshold
= IEEE80211_MAX_FRAG_THRESHOLD
;
794 else if (frag
->value
< 256 ||
795 frag
->value
> IEEE80211_MAX_FRAG_THRESHOLD
)
798 /* Fragment length must be even, so strip LSB. */
799 local
->fragmentation_threshold
= frag
->value
& ~0x1;
802 /* If the wlan card performs fragmentation in hardware/firmware,
803 * configure it here */
805 if (local
->ops
->set_frag_threshold
)
806 local
->ops
->set_frag_threshold(
808 local
->fragmentation_threshold
);
813 static int ieee80211_ioctl_giwfrag(struct net_device
*dev
,
814 struct iw_request_info
*info
,
815 struct iw_param
*frag
, char *extra
)
817 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
819 frag
->value
= local
->fragmentation_threshold
;
820 frag
->disabled
= (frag
->value
>= IEEE80211_MAX_RTS_THRESHOLD
);
827 static int ieee80211_ioctl_siwretry(struct net_device
*dev
,
828 struct iw_request_info
*info
,
829 struct iw_param
*retry
, char *extra
)
831 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
833 if (retry
->disabled
||
834 (retry
->flags
& IW_RETRY_TYPE
) != IW_RETRY_LIMIT
)
837 if (retry
->flags
& IW_RETRY_MAX
)
838 local
->long_retry_limit
= retry
->value
;
839 else if (retry
->flags
& IW_RETRY_MIN
)
840 local
->short_retry_limit
= retry
->value
;
842 local
->long_retry_limit
= retry
->value
;
843 local
->short_retry_limit
= retry
->value
;
846 if (local
->ops
->set_retry_limit
) {
847 return local
->ops
->set_retry_limit(
849 local
->short_retry_limit
,
850 local
->long_retry_limit
);
857 static int ieee80211_ioctl_giwretry(struct net_device
*dev
,
858 struct iw_request_info
*info
,
859 struct iw_param
*retry
, char *extra
)
861 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
864 if (retry
->flags
== 0 || retry
->flags
& IW_RETRY_MIN
) {
865 /* first return min value, iwconfig will ask max value
867 retry
->flags
|= IW_RETRY_LIMIT
;
868 retry
->value
= local
->short_retry_limit
;
869 if (local
->long_retry_limit
!= local
->short_retry_limit
)
870 retry
->flags
|= IW_RETRY_MIN
;
873 if (retry
->flags
& IW_RETRY_MAX
) {
874 retry
->flags
= IW_RETRY_LIMIT
| IW_RETRY_MAX
;
875 retry
->value
= local
->long_retry_limit
;
881 static int ieee80211_ioctl_siwmlme(struct net_device
*dev
,
882 struct iw_request_info
*info
,
883 struct iw_point
*data
, char *extra
)
885 struct ieee80211_sub_if_data
*sdata
;
886 struct iw_mlme
*mlme
= (struct iw_mlme
*) extra
;
888 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
889 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
&&
890 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
)
895 /* TODO: mlme->addr.sa_data */
896 return ieee80211_sta_deauthenticate(sdata
, mlme
->reason_code
);
897 case IW_MLME_DISASSOC
:
898 /* TODO: mlme->addr.sa_data */
899 return ieee80211_sta_disassociate(sdata
, mlme
->reason_code
);
906 static int ieee80211_ioctl_siwencode(struct net_device
*dev
,
907 struct iw_request_info
*info
,
908 struct iw_point
*erq
, char *keybuf
)
910 struct ieee80211_sub_if_data
*sdata
;
911 int idx
, i
, alg
= ALG_WEP
;
912 u8 bcaddr
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
915 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
917 idx
= erq
->flags
& IW_ENCODE_INDEX
;
919 if (sdata
->default_key
)
920 for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
921 if (sdata
->default_key
== sdata
->keys
[i
]) {
926 } else if (idx
< 1 || idx
> 4)
931 if (erq
->flags
& IW_ENCODE_DISABLED
)
933 else if (erq
->length
== 0) {
934 /* No key data - just set the default TX key index */
935 ieee80211_set_default_key(sdata
, idx
);
939 return ieee80211_set_encryption(
943 keybuf
, erq
->length
);
947 static int ieee80211_ioctl_giwencode(struct net_device
*dev
,
948 struct iw_request_info
*info
,
949 struct iw_point
*erq
, char *key
)
951 struct ieee80211_sub_if_data
*sdata
;
954 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
956 idx
= erq
->flags
& IW_ENCODE_INDEX
;
957 if (idx
< 1 || idx
> 4) {
959 if (!sdata
->default_key
)
961 else for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
962 if (sdata
->default_key
== sdata
->keys
[i
]) {
972 erq
->flags
= idx
+ 1;
974 if (!sdata
->keys
[idx
]) {
976 erq
->flags
|= IW_ENCODE_DISABLED
;
980 memcpy(key
, sdata
->keys
[idx
]->conf
.key
,
981 min_t(int, erq
->length
, sdata
->keys
[idx
]->conf
.keylen
));
982 erq
->length
= sdata
->keys
[idx
]->conf
.keylen
;
983 erq
->flags
|= IW_ENCODE_ENABLED
;
985 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
) {
986 struct ieee80211_if_sta
*ifsta
= &sdata
->u
.sta
;
987 switch (ifsta
->auth_alg
) {
990 erq
->flags
|= IW_ENCODE_OPEN
;
992 case WLAN_AUTH_SHARED_KEY
:
993 erq
->flags
|= IW_ENCODE_RESTRICTED
;
1001 static int ieee80211_ioctl_siwpower(struct net_device
*dev
,
1002 struct iw_request_info
*info
,
1003 struct iw_param
*wrq
,
1006 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1007 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
1009 if (wrq
->disabled
) {
1010 conf
->flags
&= ~IEEE80211_CONF_PS
;
1011 return ieee80211_hw_config(local
);
1014 switch (wrq
->flags
& IW_POWER_MODE
) {
1015 case IW_POWER_ON
: /* If not specified */
1016 case IW_POWER_MODE
: /* If set all mask */
1017 case IW_POWER_ALL_R
: /* If explicitely state all */
1018 conf
->flags
|= IEEE80211_CONF_PS
;
1020 default: /* Otherwise we don't support it */
1024 return ieee80211_hw_config(local
);
1027 static int ieee80211_ioctl_giwpower(struct net_device
*dev
,
1028 struct iw_request_info
*info
,
1029 union iwreq_data
*wrqu
,
1032 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1033 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
1035 wrqu
->power
.disabled
= !(conf
->flags
& IEEE80211_CONF_PS
);
1040 static int ieee80211_ioctl_siwauth(struct net_device
*dev
,
1041 struct iw_request_info
*info
,
1042 struct iw_param
*data
, char *extra
)
1044 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1047 switch (data
->flags
& IW_AUTH_INDEX
) {
1048 case IW_AUTH_WPA_VERSION
:
1049 case IW_AUTH_CIPHER_PAIRWISE
:
1050 case IW_AUTH_CIPHER_GROUP
:
1051 case IW_AUTH_WPA_ENABLED
:
1052 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
1053 case IW_AUTH_KEY_MGMT
:
1055 case IW_AUTH_DROP_UNENCRYPTED
:
1056 sdata
->drop_unencrypted
= !!data
->value
;
1058 case IW_AUTH_PRIVACY_INVOKED
:
1059 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
1062 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_PRIVACY_INVOKED
;
1064 * Privacy invoked by wpa_supplicant, store the
1065 * value and allow associating to a protected
1066 * network without having a key up front.
1069 sdata
->u
.sta
.flags
|=
1070 IEEE80211_STA_PRIVACY_INVOKED
;
1073 case IW_AUTH_80211_AUTH_ALG
:
1074 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
1075 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
)
1076 sdata
->u
.sta
.auth_algs
= data
->value
;
1087 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
1088 static struct iw_statistics
*ieee80211_get_wireless_stats(struct net_device
*dev
)
1090 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1091 struct iw_statistics
*wstats
= &local
->wstats
;
1092 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1093 struct sta_info
*sta
= NULL
;
1097 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
1098 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
)
1099 sta
= sta_info_get(local
, sdata
->u
.sta
.bssid
);
1101 wstats
->discard
.fragment
= 0;
1102 wstats
->discard
.misc
= 0;
1103 wstats
->qual
.qual
= 0;
1104 wstats
->qual
.level
= 0;
1105 wstats
->qual
.noise
= 0;
1106 wstats
->qual
.updated
= IW_QUAL_ALL_INVALID
;
1108 wstats
->qual
.level
= sta
->last_signal
;
1109 wstats
->qual
.qual
= sta
->last_qual
;
1110 wstats
->qual
.noise
= sta
->last_noise
;
1111 wstats
->qual
.updated
= local
->wstats_flags
;
1119 static int ieee80211_ioctl_giwauth(struct net_device
*dev
,
1120 struct iw_request_info
*info
,
1121 struct iw_param
*data
, char *extra
)
1123 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1126 switch (data
->flags
& IW_AUTH_INDEX
) {
1127 case IW_AUTH_80211_AUTH_ALG
:
1128 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
1129 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
)
1130 data
->value
= sdata
->u
.sta
.auth_algs
;
1142 static int ieee80211_ioctl_siwencodeext(struct net_device
*dev
,
1143 struct iw_request_info
*info
,
1144 struct iw_point
*erq
, char *extra
)
1146 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1147 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*) extra
;
1148 int uninitialized_var(alg
), idx
, i
, remove
= 0;
1151 case IW_ENCODE_ALG_NONE
:
1154 case IW_ENCODE_ALG_WEP
:
1157 case IW_ENCODE_ALG_TKIP
:
1160 case IW_ENCODE_ALG_CCMP
:
1167 if (erq
->flags
& IW_ENCODE_DISABLED
)
1170 idx
= erq
->flags
& IW_ENCODE_INDEX
;
1171 if (idx
< 1 || idx
> 4) {
1173 if (!sdata
->default_key
)
1175 else for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
1176 if (sdata
->default_key
== sdata
->keys
[i
]) {
1186 return ieee80211_set_encryption(sdata
, ext
->addr
.sa_data
, idx
, alg
,
1189 IW_ENCODE_EXT_SET_TX_KEY
,
1190 ext
->key
, ext
->key_len
);
1194 /* Structures to export the Wireless Handlers */
1196 static const iw_handler ieee80211_handler
[] =
1198 (iw_handler
) NULL
, /* SIOCSIWCOMMIT */
1199 (iw_handler
) ieee80211_ioctl_giwname
, /* SIOCGIWNAME */
1200 (iw_handler
) NULL
, /* SIOCSIWNWID */
1201 (iw_handler
) NULL
, /* SIOCGIWNWID */
1202 (iw_handler
) ieee80211_ioctl_siwfreq
, /* SIOCSIWFREQ */
1203 (iw_handler
) ieee80211_ioctl_giwfreq
, /* SIOCGIWFREQ */
1204 (iw_handler
) ieee80211_ioctl_siwmode
, /* SIOCSIWMODE */
1205 (iw_handler
) ieee80211_ioctl_giwmode
, /* SIOCGIWMODE */
1206 (iw_handler
) NULL
, /* SIOCSIWSENS */
1207 (iw_handler
) NULL
, /* SIOCGIWSENS */
1208 (iw_handler
) NULL
/* not used */, /* SIOCSIWRANGE */
1209 (iw_handler
) ieee80211_ioctl_giwrange
, /* SIOCGIWRANGE */
1210 (iw_handler
) NULL
/* not used */, /* SIOCSIWPRIV */
1211 (iw_handler
) NULL
/* kernel code */, /* SIOCGIWPRIV */
1212 (iw_handler
) NULL
/* not used */, /* SIOCSIWSTATS */
1213 (iw_handler
) NULL
/* kernel code */, /* SIOCGIWSTATS */
1214 (iw_handler
) NULL
, /* SIOCSIWSPY */
1215 (iw_handler
) NULL
, /* SIOCGIWSPY */
1216 (iw_handler
) NULL
, /* SIOCSIWTHRSPY */
1217 (iw_handler
) NULL
, /* SIOCGIWTHRSPY */
1218 (iw_handler
) ieee80211_ioctl_siwap
, /* SIOCSIWAP */
1219 (iw_handler
) ieee80211_ioctl_giwap
, /* SIOCGIWAP */
1220 (iw_handler
) ieee80211_ioctl_siwmlme
, /* SIOCSIWMLME */
1221 (iw_handler
) NULL
, /* SIOCGIWAPLIST */
1222 (iw_handler
) ieee80211_ioctl_siwscan
, /* SIOCSIWSCAN */
1223 (iw_handler
) ieee80211_ioctl_giwscan
, /* SIOCGIWSCAN */
1224 (iw_handler
) ieee80211_ioctl_siwessid
, /* SIOCSIWESSID */
1225 (iw_handler
) ieee80211_ioctl_giwessid
, /* SIOCGIWESSID */
1226 (iw_handler
) NULL
, /* SIOCSIWNICKN */
1227 (iw_handler
) NULL
, /* SIOCGIWNICKN */
1228 (iw_handler
) NULL
, /* -- hole -- */
1229 (iw_handler
) NULL
, /* -- hole -- */
1230 (iw_handler
) ieee80211_ioctl_siwrate
, /* SIOCSIWRATE */
1231 (iw_handler
) ieee80211_ioctl_giwrate
, /* SIOCGIWRATE */
1232 (iw_handler
) ieee80211_ioctl_siwrts
, /* SIOCSIWRTS */
1233 (iw_handler
) ieee80211_ioctl_giwrts
, /* SIOCGIWRTS */
1234 (iw_handler
) ieee80211_ioctl_siwfrag
, /* SIOCSIWFRAG */
1235 (iw_handler
) ieee80211_ioctl_giwfrag
, /* SIOCGIWFRAG */
1236 (iw_handler
) ieee80211_ioctl_siwtxpower
, /* SIOCSIWTXPOW */
1237 (iw_handler
) ieee80211_ioctl_giwtxpower
, /* SIOCGIWTXPOW */
1238 (iw_handler
) ieee80211_ioctl_siwretry
, /* SIOCSIWRETRY */
1239 (iw_handler
) ieee80211_ioctl_giwretry
, /* SIOCGIWRETRY */
1240 (iw_handler
) ieee80211_ioctl_siwencode
, /* SIOCSIWENCODE */
1241 (iw_handler
) ieee80211_ioctl_giwencode
, /* SIOCGIWENCODE */
1242 (iw_handler
) ieee80211_ioctl_siwpower
, /* SIOCSIWPOWER */
1243 (iw_handler
) ieee80211_ioctl_giwpower
, /* SIOCGIWPOWER */
1244 (iw_handler
) NULL
, /* -- hole -- */
1245 (iw_handler
) NULL
, /* -- hole -- */
1246 (iw_handler
) ieee80211_ioctl_siwgenie
, /* SIOCSIWGENIE */
1247 (iw_handler
) NULL
, /* SIOCGIWGENIE */
1248 (iw_handler
) ieee80211_ioctl_siwauth
, /* SIOCSIWAUTH */
1249 (iw_handler
) ieee80211_ioctl_giwauth
, /* SIOCGIWAUTH */
1250 (iw_handler
) ieee80211_ioctl_siwencodeext
, /* SIOCSIWENCODEEXT */
1251 (iw_handler
) NULL
, /* SIOCGIWENCODEEXT */
1252 (iw_handler
) NULL
, /* SIOCSIWPMKSA */
1253 (iw_handler
) NULL
, /* -- hole -- */
1256 const struct iw_handler_def ieee80211_iw_handler_def
=
1258 .num_standard
= ARRAY_SIZE(ieee80211_handler
),
1259 .standard
= (iw_handler
*) ieee80211_handler
,
1260 .get_wireless_stats
= ieee80211_get_wireless_stats
,