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"
24 #include "ieee80211_led.h"
25 #include "ieee80211_rate.h"
30 static int ieee80211_set_encryption(struct net_device
*dev
, u8
*sta_addr
,
31 int idx
, int alg
, int remove
,
32 int set_tx_key
, const u8
*_key
,
35 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
37 struct ieee80211_key
*key
;
38 struct ieee80211_sub_if_data
*sdata
;
40 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
42 if (idx
< 0 || idx
>= NUM_DEFAULT_KEYS
) {
43 printk(KERN_DEBUG
"%s: set_encrypt - invalid idx=%d\n",
49 if (is_broadcast_ether_addr(sta_addr
)) {
50 key
= sdata
->keys
[idx
];
52 sta
= sta_info_get(local
, sta_addr
);
58 ieee80211_key_free(key
);
61 key
= ieee80211_key_alloc(alg
, idx
, key_len
, _key
);
67 if (!is_broadcast_ether_addr(sta_addr
)) {
70 * According to the standard, the key index of a
71 * pairwise key must be zero. However, some AP are
72 * broken when it comes to WEP key indices, so we
75 if (idx
!= 0 && alg
!= ALG_WEP
) {
76 ieee80211_key_free(key
);
80 sta
= sta_info_get(local
, sta_addr
);
82 ieee80211_key_free(key
);
87 ieee80211_key_link(key
, sdata
, sta
);
89 if (set_tx_key
|| (!sta
&& !sdata
->default_key
&& key
))
90 ieee80211_set_default_key(sdata
, idx
);
96 static int ieee80211_ioctl_siwgenie(struct net_device
*dev
,
97 struct iw_request_info
*info
,
98 struct iw_point
*data
, char *extra
)
100 struct ieee80211_sub_if_data
*sdata
;
102 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
104 if (sdata
->flags
& IEEE80211_SDATA_USERSPACE_MLME
)
107 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
108 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
109 int ret
= ieee80211_sta_set_extra_ie(dev
, extra
, data
->length
);
112 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_AUTO_BSSID_SEL
;
113 ieee80211_sta_req_auth(dev
, &sdata
->u
.sta
);
120 static int ieee80211_ioctl_giwname(struct net_device
*dev
,
121 struct iw_request_info
*info
,
122 char *name
, char *extra
)
124 strcpy(name
, "IEEE 802.11");
130 static int ieee80211_ioctl_giwrange(struct net_device
*dev
,
131 struct iw_request_info
*info
,
132 struct iw_point
*data
, char *extra
)
134 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
135 struct iw_range
*range
= (struct iw_range
*) extra
;
136 enum ieee80211_band band
;
139 data
->length
= sizeof(struct iw_range
);
140 memset(range
, 0, sizeof(struct iw_range
));
142 range
->we_version_compiled
= WIRELESS_EXT
;
143 range
->we_version_source
= 21;
144 range
->retry_capa
= IW_RETRY_LIMIT
;
145 range
->retry_flags
= IW_RETRY_LIMIT
;
146 range
->min_retry
= 0;
147 range
->max_retry
= 255;
149 range
->max_rts
= 2347;
150 range
->min_frag
= 256;
151 range
->max_frag
= 2346;
153 range
->encoding_size
[0] = 5;
154 range
->encoding_size
[1] = 13;
155 range
->num_encoding_sizes
= 2;
156 range
->max_encoding_tokens
= NUM_DEFAULT_KEYS
;
158 range
->max_qual
.qual
= local
->hw
.max_signal
;
159 range
->max_qual
.level
= local
->hw
.max_rssi
;
160 range
->max_qual
.noise
= local
->hw
.max_noise
;
161 range
->max_qual
.updated
= local
->wstats_flags
;
163 range
->avg_qual
.qual
= local
->hw
.max_signal
/2;
164 range
->avg_qual
.level
= 0;
165 range
->avg_qual
.noise
= 0;
166 range
->avg_qual
.updated
= local
->wstats_flags
;
168 range
->enc_capa
= IW_ENC_CAPA_WPA
| IW_ENC_CAPA_WPA2
|
169 IW_ENC_CAPA_CIPHER_TKIP
| IW_ENC_CAPA_CIPHER_CCMP
;
172 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
174 struct ieee80211_supported_band
*sband
;
176 sband
= local
->hw
.wiphy
->bands
[band
];
181 for (i
= 0; i
< sband
->n_channels
&& c
< IW_MAX_FREQUENCIES
; i
++) {
182 struct ieee80211_channel
*chan
= &sband
->channels
[i
];
184 if (!(chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
186 ieee80211_frequency_to_channel(
188 range
->freq
[c
].m
= chan
->center_freq
;
189 range
->freq
[c
].e
= 6;
194 range
->num_channels
= c
;
195 range
->num_frequency
= c
;
197 IW_EVENT_CAPA_SET_KERNEL(range
->event_capa
);
198 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWTHRSPY
);
199 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWAP
);
200 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWSCAN
);
202 range
->scan_capa
|= IW_SCAN_CAPA_ESSID
;
208 static int ieee80211_ioctl_siwmode(struct net_device
*dev
,
209 struct iw_request_info
*info
,
210 __u32
*mode
, char *extra
)
212 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
215 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_VLAN
)
220 type
= IEEE80211_IF_TYPE_STA
;
223 type
= IEEE80211_IF_TYPE_IBSS
;
225 case IW_MODE_MONITOR
:
226 type
= IEEE80211_IF_TYPE_MNTR
;
232 if (type
== sdata
->vif
.type
)
234 if (netif_running(dev
))
237 ieee80211_if_reinit(dev
);
238 ieee80211_if_set_type(dev
, type
);
244 static int ieee80211_ioctl_giwmode(struct net_device
*dev
,
245 struct iw_request_info
*info
,
246 __u32
*mode
, char *extra
)
248 struct ieee80211_sub_if_data
*sdata
;
250 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
251 switch (sdata
->vif
.type
) {
252 case IEEE80211_IF_TYPE_AP
:
253 *mode
= IW_MODE_MASTER
;
255 case IEEE80211_IF_TYPE_STA
:
256 *mode
= IW_MODE_INFRA
;
258 case IEEE80211_IF_TYPE_IBSS
:
259 *mode
= IW_MODE_ADHOC
;
261 case IEEE80211_IF_TYPE_MNTR
:
262 *mode
= IW_MODE_MONITOR
;
264 case IEEE80211_IF_TYPE_WDS
:
265 *mode
= IW_MODE_REPEAT
;
267 case IEEE80211_IF_TYPE_VLAN
:
268 *mode
= IW_MODE_SECOND
; /* FIXME */
271 *mode
= IW_MODE_AUTO
;
277 int ieee80211_set_freq(struct ieee80211_local
*local
, int freqMHz
)
280 struct ieee80211_channel
*chan
;
282 chan
= ieee80211_get_channel(local
->hw
.wiphy
, freqMHz
);
284 if (chan
&& !(chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
285 local
->oper_channel
= chan
;
287 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
)
290 ret
= ieee80211_hw_config(local
);
292 rate_control_clear(local
);
298 static int ieee80211_ioctl_siwfreq(struct net_device
*dev
,
299 struct iw_request_info
*info
,
300 struct iw_freq
*freq
, char *extra
)
302 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
303 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
305 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
)
306 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_AUTO_CHANNEL_SEL
;
308 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
311 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
)
312 sdata
->u
.sta
.flags
|=
313 IEEE80211_STA_AUTO_CHANNEL_SEL
;
316 return ieee80211_set_freq(local
,
317 ieee80211_channel_to_frequency(freq
->m
));
319 int i
, div
= 1000000;
320 for (i
= 0; i
< freq
->e
; i
++)
323 return ieee80211_set_freq(local
, freq
->m
/ div
);
330 static int ieee80211_ioctl_giwfreq(struct net_device
*dev
,
331 struct iw_request_info
*info
,
332 struct iw_freq
*freq
, char *extra
)
334 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
336 freq
->m
= local
->hw
.conf
.channel
->center_freq
;
343 static int ieee80211_ioctl_siwessid(struct net_device
*dev
,
344 struct iw_request_info
*info
,
345 struct iw_point
*data
, char *ssid
)
347 struct ieee80211_sub_if_data
*sdata
;
348 size_t len
= data
->length
;
350 /* iwconfig uses nul termination in SSID.. */
351 if (len
> 0 && ssid
[len
- 1] == '\0')
354 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
355 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
356 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
358 if (sdata
->flags
& IEEE80211_SDATA_USERSPACE_MLME
) {
359 if (len
> IEEE80211_MAX_SSID_LEN
)
361 memcpy(sdata
->u
.sta
.ssid
, ssid
, len
);
362 sdata
->u
.sta
.ssid_len
= len
;
366 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_AUTO_SSID_SEL
;
368 sdata
->u
.sta
.flags
|= IEEE80211_STA_AUTO_SSID_SEL
;
369 ret
= ieee80211_sta_set_ssid(dev
, ssid
, len
);
372 ieee80211_sta_req_auth(dev
, &sdata
->u
.sta
);
376 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
) {
377 memcpy(sdata
->u
.ap
.ssid
, ssid
, len
);
378 memset(sdata
->u
.ap
.ssid
+ len
, 0,
379 IEEE80211_MAX_SSID_LEN
- len
);
380 sdata
->u
.ap
.ssid_len
= len
;
381 return ieee80211_if_config(dev
);
387 static int ieee80211_ioctl_giwessid(struct net_device
*dev
,
388 struct iw_request_info
*info
,
389 struct iw_point
*data
, char *ssid
)
393 struct ieee80211_sub_if_data
*sdata
;
394 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
395 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
396 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
397 int res
= ieee80211_sta_get_ssid(dev
, ssid
, &len
);
406 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_AP
) {
407 len
= sdata
->u
.ap
.ssid_len
;
408 if (len
> IW_ESSID_MAX_SIZE
)
409 len
= IW_ESSID_MAX_SIZE
;
410 memcpy(ssid
, sdata
->u
.ap
.ssid
, len
);
419 static int ieee80211_ioctl_siwap(struct net_device
*dev
,
420 struct iw_request_info
*info
,
421 struct sockaddr
*ap_addr
, char *extra
)
423 struct ieee80211_sub_if_data
*sdata
;
425 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
426 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
427 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
429 if (sdata
->flags
& IEEE80211_SDATA_USERSPACE_MLME
) {
430 memcpy(sdata
->u
.sta
.bssid
, (u8
*) &ap_addr
->sa_data
,
434 if (is_zero_ether_addr((u8
*) &ap_addr
->sa_data
))
435 sdata
->u
.sta
.flags
|= IEEE80211_STA_AUTO_BSSID_SEL
|
436 IEEE80211_STA_AUTO_CHANNEL_SEL
;
437 else if (is_broadcast_ether_addr((u8
*) &ap_addr
->sa_data
))
438 sdata
->u
.sta
.flags
|= IEEE80211_STA_AUTO_BSSID_SEL
;
440 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_AUTO_BSSID_SEL
;
441 ret
= ieee80211_sta_set_bssid(dev
, (u8
*) &ap_addr
->sa_data
);
444 ieee80211_sta_req_auth(dev
, &sdata
->u
.sta
);
446 } else if (sdata
->vif
.type
== IEEE80211_IF_TYPE_WDS
) {
448 * If it is necessary to update the WDS peer address
449 * while the interface is running, then we need to do
450 * more work here, namely if it is running we need to
451 * add a new and remove the old STA entry, this is
452 * normally handled by _open() and _stop().
454 if (netif_running(dev
))
457 memcpy(&sdata
->u
.wds
.remote_addr
, (u8
*) &ap_addr
->sa_data
,
467 static int ieee80211_ioctl_giwap(struct net_device
*dev
,
468 struct iw_request_info
*info
,
469 struct sockaddr
*ap_addr
, char *extra
)
471 struct ieee80211_sub_if_data
*sdata
;
473 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
474 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
475 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
476 ap_addr
->sa_family
= ARPHRD_ETHER
;
477 memcpy(&ap_addr
->sa_data
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
479 } else if (sdata
->vif
.type
== IEEE80211_IF_TYPE_WDS
) {
480 ap_addr
->sa_family
= ARPHRD_ETHER
;
481 memcpy(&ap_addr
->sa_data
, sdata
->u
.wds
.remote_addr
, ETH_ALEN
);
489 static int ieee80211_ioctl_siwscan(struct net_device
*dev
,
490 struct iw_request_info
*info
,
491 union iwreq_data
*wrqu
, char *extra
)
493 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
494 struct iw_scan_req
*req
= NULL
;
498 if (!netif_running(dev
))
501 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
&&
502 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
503 sdata
->vif
.type
!= IEEE80211_IF_TYPE_MESH_POINT
&&
504 sdata
->vif
.type
!= IEEE80211_IF_TYPE_AP
)
507 /* if SSID was specified explicitly then use that */
508 if (wrqu
->data
.length
== sizeof(struct iw_scan_req
) &&
509 wrqu
->data
.flags
& IW_SCAN_THIS_ESSID
) {
510 req
= (struct iw_scan_req
*)extra
;
512 ssid_len
= req
->essid_len
;
515 return ieee80211_sta_req_scan(dev
, ssid
, ssid_len
);
519 static int ieee80211_ioctl_giwscan(struct net_device
*dev
,
520 struct iw_request_info
*info
,
521 struct iw_point
*data
, char *extra
)
524 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
526 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
)
529 res
= ieee80211_sta_scan_results(dev
, extra
, data
->length
);
539 static int ieee80211_ioctl_siwrate(struct net_device
*dev
,
540 struct iw_request_info
*info
,
541 struct iw_param
*rate
, char *extra
)
543 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
544 int i
, err
= -EINVAL
;
545 u32 target_rate
= rate
->value
/ 100000;
546 struct ieee80211_sub_if_data
*sdata
;
547 struct ieee80211_supported_band
*sband
;
549 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
553 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
555 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
556 * target_rate = X, rate->fixed = 1 means only rate X
557 * target_rate = X, rate->fixed = 0 means all rates <= X */
558 sdata
->bss
->max_ratectrl_rateidx
= -1;
559 sdata
->bss
->force_unicast_rateidx
= -1;
563 for (i
=0; i
< sband
->n_bitrates
; i
++) {
564 struct ieee80211_rate
*brate
= &sband
->bitrates
[i
];
565 int this_rate
= brate
->bitrate
;
567 if (target_rate
== this_rate
) {
568 sdata
->bss
->max_ratectrl_rateidx
= i
;
570 sdata
->bss
->force_unicast_rateidx
= i
;
578 static int ieee80211_ioctl_giwrate(struct net_device
*dev
,
579 struct iw_request_info
*info
,
580 struct iw_param
*rate
, char *extra
)
582 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
583 struct sta_info
*sta
;
584 struct ieee80211_sub_if_data
*sdata
;
585 struct ieee80211_supported_band
*sband
;
587 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
589 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
)
590 sta
= sta_info_get(local
, sdata
->u
.sta
.bssid
);
596 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
598 if (sta
->txrate_idx
< sband
->n_bitrates
)
599 rate
->value
= sband
->bitrates
[sta
->txrate_idx
].bitrate
;
602 rate
->value
*= 100000;
607 static int ieee80211_ioctl_siwtxpower(struct net_device
*dev
,
608 struct iw_request_info
*info
,
609 union iwreq_data
*data
, char *extra
)
611 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
612 bool need_reconfig
= 0;
615 if ((data
->txpower
.flags
& IW_TXPOW_TYPE
) != IW_TXPOW_DBM
)
617 if (data
->txpower
.flags
& IW_TXPOW_RANGE
)
620 if (data
->txpower
.fixed
) {
621 new_power_level
= data
->txpower
.value
;
624 * Automatic power level. Use maximum power for the current
625 * channel. Should be part of rate control.
627 struct ieee80211_channel
* chan
= local
->hw
.conf
.channel
;
631 new_power_level
= chan
->max_power
;
634 if (local
->hw
.conf
.power_level
!= new_power_level
) {
635 local
->hw
.conf
.power_level
= new_power_level
;
639 if (local
->hw
.conf
.radio_enabled
!= !(data
->txpower
.disabled
)) {
640 local
->hw
.conf
.radio_enabled
= !(data
->txpower
.disabled
);
642 ieee80211_led_radio(local
, local
->hw
.conf
.radio_enabled
);
646 ieee80211_hw_config(local
);
647 /* The return value of hw_config is not of big interest here,
648 * as it doesn't say that it failed because of _this_ config
649 * change or something else. Ignore it. */
655 static int ieee80211_ioctl_giwtxpower(struct net_device
*dev
,
656 struct iw_request_info
*info
,
657 union iwreq_data
*data
, char *extra
)
659 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
661 data
->txpower
.fixed
= 1;
662 data
->txpower
.disabled
= !(local
->hw
.conf
.radio_enabled
);
663 data
->txpower
.value
= local
->hw
.conf
.power_level
;
664 data
->txpower
.flags
= IW_TXPOW_DBM
;
669 static int ieee80211_ioctl_siwrts(struct net_device
*dev
,
670 struct iw_request_info
*info
,
671 struct iw_param
*rts
, char *extra
)
673 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
676 local
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
677 else if (rts
->value
< 0 || rts
->value
> IEEE80211_MAX_RTS_THRESHOLD
)
680 local
->rts_threshold
= rts
->value
;
682 /* If the wlan card performs RTS/CTS in hardware/firmware,
683 * configure it here */
685 if (local
->ops
->set_rts_threshold
)
686 local
->ops
->set_rts_threshold(local_to_hw(local
),
687 local
->rts_threshold
);
692 static int ieee80211_ioctl_giwrts(struct net_device
*dev
,
693 struct iw_request_info
*info
,
694 struct iw_param
*rts
, char *extra
)
696 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
698 rts
->value
= local
->rts_threshold
;
699 rts
->disabled
= (rts
->value
>= IEEE80211_MAX_RTS_THRESHOLD
);
706 static int ieee80211_ioctl_siwfrag(struct net_device
*dev
,
707 struct iw_request_info
*info
,
708 struct iw_param
*frag
, char *extra
)
710 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
713 local
->fragmentation_threshold
= IEEE80211_MAX_FRAG_THRESHOLD
;
714 else if (frag
->value
< 256 ||
715 frag
->value
> IEEE80211_MAX_FRAG_THRESHOLD
)
718 /* Fragment length must be even, so strip LSB. */
719 local
->fragmentation_threshold
= frag
->value
& ~0x1;
722 /* If the wlan card performs fragmentation in hardware/firmware,
723 * configure it here */
725 if (local
->ops
->set_frag_threshold
)
726 local
->ops
->set_frag_threshold(
728 local
->fragmentation_threshold
);
733 static int ieee80211_ioctl_giwfrag(struct net_device
*dev
,
734 struct iw_request_info
*info
,
735 struct iw_param
*frag
, char *extra
)
737 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
739 frag
->value
= local
->fragmentation_threshold
;
740 frag
->disabled
= (frag
->value
>= IEEE80211_MAX_RTS_THRESHOLD
);
747 static int ieee80211_ioctl_siwretry(struct net_device
*dev
,
748 struct iw_request_info
*info
,
749 struct iw_param
*retry
, char *extra
)
751 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
753 if (retry
->disabled
||
754 (retry
->flags
& IW_RETRY_TYPE
) != IW_RETRY_LIMIT
)
757 if (retry
->flags
& IW_RETRY_MAX
)
758 local
->long_retry_limit
= retry
->value
;
759 else if (retry
->flags
& IW_RETRY_MIN
)
760 local
->short_retry_limit
= retry
->value
;
762 local
->long_retry_limit
= retry
->value
;
763 local
->short_retry_limit
= retry
->value
;
766 if (local
->ops
->set_retry_limit
) {
767 return local
->ops
->set_retry_limit(
769 local
->short_retry_limit
,
770 local
->long_retry_limit
);
777 static int ieee80211_ioctl_giwretry(struct net_device
*dev
,
778 struct iw_request_info
*info
,
779 struct iw_param
*retry
, char *extra
)
781 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
784 if (retry
->flags
== 0 || retry
->flags
& IW_RETRY_MIN
) {
785 /* first return min value, iwconfig will ask max value
787 retry
->flags
|= IW_RETRY_LIMIT
;
788 retry
->value
= local
->short_retry_limit
;
789 if (local
->long_retry_limit
!= local
->short_retry_limit
)
790 retry
->flags
|= IW_RETRY_MIN
;
793 if (retry
->flags
& IW_RETRY_MAX
) {
794 retry
->flags
= IW_RETRY_LIMIT
| IW_RETRY_MAX
;
795 retry
->value
= local
->long_retry_limit
;
801 static int ieee80211_ioctl_siwmlme(struct net_device
*dev
,
802 struct iw_request_info
*info
,
803 struct iw_point
*data
, char *extra
)
805 struct ieee80211_sub_if_data
*sdata
;
806 struct iw_mlme
*mlme
= (struct iw_mlme
*) extra
;
808 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
809 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
&&
810 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
)
815 /* TODO: mlme->addr.sa_data */
816 return ieee80211_sta_deauthenticate(dev
, mlme
->reason_code
);
817 case IW_MLME_DISASSOC
:
818 /* TODO: mlme->addr.sa_data */
819 return ieee80211_sta_disassociate(dev
, mlme
->reason_code
);
826 static int ieee80211_ioctl_siwencode(struct net_device
*dev
,
827 struct iw_request_info
*info
,
828 struct iw_point
*erq
, char *keybuf
)
830 struct ieee80211_sub_if_data
*sdata
;
831 int idx
, i
, alg
= ALG_WEP
;
832 u8 bcaddr
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
835 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
837 idx
= erq
->flags
& IW_ENCODE_INDEX
;
839 if (sdata
->default_key
)
840 for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
841 if (sdata
->default_key
== sdata
->keys
[i
]) {
846 } else if (idx
< 1 || idx
> 4)
851 if (erq
->flags
& IW_ENCODE_DISABLED
)
853 else if (erq
->length
== 0) {
854 /* No key data - just set the default TX key index */
855 ieee80211_set_default_key(sdata
, idx
);
859 return ieee80211_set_encryption(
863 keybuf
, erq
->length
);
867 static int ieee80211_ioctl_giwencode(struct net_device
*dev
,
868 struct iw_request_info
*info
,
869 struct iw_point
*erq
, char *key
)
871 struct ieee80211_sub_if_data
*sdata
;
874 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
876 idx
= erq
->flags
& IW_ENCODE_INDEX
;
877 if (idx
< 1 || idx
> 4) {
879 if (!sdata
->default_key
)
881 else for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
882 if (sdata
->default_key
== sdata
->keys
[i
]) {
892 erq
->flags
= idx
+ 1;
894 if (!sdata
->keys
[idx
]) {
896 erq
->flags
|= IW_ENCODE_DISABLED
;
900 memcpy(key
, sdata
->keys
[idx
]->conf
.key
,
901 min_t(int, erq
->length
, sdata
->keys
[idx
]->conf
.keylen
));
902 erq
->length
= sdata
->keys
[idx
]->conf
.keylen
;
903 erq
->flags
|= IW_ENCODE_ENABLED
;
908 static int ieee80211_ioctl_siwauth(struct net_device
*dev
,
909 struct iw_request_info
*info
,
910 struct iw_param
*data
, char *extra
)
912 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
915 switch (data
->flags
& IW_AUTH_INDEX
) {
916 case IW_AUTH_WPA_VERSION
:
917 case IW_AUTH_CIPHER_PAIRWISE
:
918 case IW_AUTH_CIPHER_GROUP
:
919 case IW_AUTH_WPA_ENABLED
:
920 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
921 case IW_AUTH_KEY_MGMT
:
923 case IW_AUTH_DROP_UNENCRYPTED
:
924 sdata
->drop_unencrypted
= !!data
->value
;
926 case IW_AUTH_PRIVACY_INVOKED
:
927 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
930 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_PRIVACY_INVOKED
;
932 * Privacy invoked by wpa_supplicant, store the
933 * value and allow associating to a protected
934 * network without having a key up front.
937 sdata
->u
.sta
.flags
|=
938 IEEE80211_STA_PRIVACY_INVOKED
;
941 case IW_AUTH_80211_AUTH_ALG
:
942 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
943 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
)
944 sdata
->u
.sta
.auth_algs
= data
->value
;
955 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
956 static struct iw_statistics
*ieee80211_get_wireless_stats(struct net_device
*dev
)
958 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
959 struct iw_statistics
*wstats
= &local
->wstats
;
960 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
961 struct sta_info
*sta
= NULL
;
963 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
964 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
)
965 sta
= sta_info_get(local
, sdata
->u
.sta
.bssid
);
967 wstats
->discard
.fragment
= 0;
968 wstats
->discard
.misc
= 0;
969 wstats
->qual
.qual
= 0;
970 wstats
->qual
.level
= 0;
971 wstats
->qual
.noise
= 0;
972 wstats
->qual
.updated
= IW_QUAL_ALL_INVALID
;
974 wstats
->qual
.level
= sta
->last_rssi
;
975 wstats
->qual
.qual
= sta
->last_signal
;
976 wstats
->qual
.noise
= sta
->last_noise
;
977 wstats
->qual
.updated
= local
->wstats_flags
;
982 static int ieee80211_ioctl_giwauth(struct net_device
*dev
,
983 struct iw_request_info
*info
,
984 struct iw_param
*data
, char *extra
)
986 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
989 switch (data
->flags
& IW_AUTH_INDEX
) {
990 case IW_AUTH_80211_AUTH_ALG
:
991 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
992 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
)
993 data
->value
= sdata
->u
.sta
.auth_algs
;
1005 static int ieee80211_ioctl_siwencodeext(struct net_device
*dev
,
1006 struct iw_request_info
*info
,
1007 struct iw_point
*erq
, char *extra
)
1009 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1010 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*) extra
;
1011 int uninitialized_var(alg
), idx
, i
, remove
= 0;
1014 case IW_ENCODE_ALG_NONE
:
1017 case IW_ENCODE_ALG_WEP
:
1020 case IW_ENCODE_ALG_TKIP
:
1023 case IW_ENCODE_ALG_CCMP
:
1030 if (erq
->flags
& IW_ENCODE_DISABLED
)
1033 idx
= erq
->flags
& IW_ENCODE_INDEX
;
1034 if (idx
< 1 || idx
> 4) {
1036 if (!sdata
->default_key
)
1038 else for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
1039 if (sdata
->default_key
== sdata
->keys
[i
]) {
1049 return ieee80211_set_encryption(dev
, ext
->addr
.sa_data
, idx
, alg
,
1052 IW_ENCODE_EXT_SET_TX_KEY
,
1053 ext
->key
, ext
->key_len
);
1057 /* Structures to export the Wireless Handlers */
1059 static const iw_handler ieee80211_handler
[] =
1061 (iw_handler
) NULL
, /* SIOCSIWCOMMIT */
1062 (iw_handler
) ieee80211_ioctl_giwname
, /* SIOCGIWNAME */
1063 (iw_handler
) NULL
, /* SIOCSIWNWID */
1064 (iw_handler
) NULL
, /* SIOCGIWNWID */
1065 (iw_handler
) ieee80211_ioctl_siwfreq
, /* SIOCSIWFREQ */
1066 (iw_handler
) ieee80211_ioctl_giwfreq
, /* SIOCGIWFREQ */
1067 (iw_handler
) ieee80211_ioctl_siwmode
, /* SIOCSIWMODE */
1068 (iw_handler
) ieee80211_ioctl_giwmode
, /* SIOCGIWMODE */
1069 (iw_handler
) NULL
, /* SIOCSIWSENS */
1070 (iw_handler
) NULL
, /* SIOCGIWSENS */
1071 (iw_handler
) NULL
/* not used */, /* SIOCSIWRANGE */
1072 (iw_handler
) ieee80211_ioctl_giwrange
, /* SIOCGIWRANGE */
1073 (iw_handler
) NULL
/* not used */, /* SIOCSIWPRIV */
1074 (iw_handler
) NULL
/* kernel code */, /* SIOCGIWPRIV */
1075 (iw_handler
) NULL
/* not used */, /* SIOCSIWSTATS */
1076 (iw_handler
) NULL
/* kernel code */, /* SIOCGIWSTATS */
1077 (iw_handler
) NULL
, /* SIOCSIWSPY */
1078 (iw_handler
) NULL
, /* SIOCGIWSPY */
1079 (iw_handler
) NULL
, /* SIOCSIWTHRSPY */
1080 (iw_handler
) NULL
, /* SIOCGIWTHRSPY */
1081 (iw_handler
) ieee80211_ioctl_siwap
, /* SIOCSIWAP */
1082 (iw_handler
) ieee80211_ioctl_giwap
, /* SIOCGIWAP */
1083 (iw_handler
) ieee80211_ioctl_siwmlme
, /* SIOCSIWMLME */
1084 (iw_handler
) NULL
, /* SIOCGIWAPLIST */
1085 (iw_handler
) ieee80211_ioctl_siwscan
, /* SIOCSIWSCAN */
1086 (iw_handler
) ieee80211_ioctl_giwscan
, /* SIOCGIWSCAN */
1087 (iw_handler
) ieee80211_ioctl_siwessid
, /* SIOCSIWESSID */
1088 (iw_handler
) ieee80211_ioctl_giwessid
, /* SIOCGIWESSID */
1089 (iw_handler
) NULL
, /* SIOCSIWNICKN */
1090 (iw_handler
) NULL
, /* SIOCGIWNICKN */
1091 (iw_handler
) NULL
, /* -- hole -- */
1092 (iw_handler
) NULL
, /* -- hole -- */
1093 (iw_handler
) ieee80211_ioctl_siwrate
, /* SIOCSIWRATE */
1094 (iw_handler
) ieee80211_ioctl_giwrate
, /* SIOCGIWRATE */
1095 (iw_handler
) ieee80211_ioctl_siwrts
, /* SIOCSIWRTS */
1096 (iw_handler
) ieee80211_ioctl_giwrts
, /* SIOCGIWRTS */
1097 (iw_handler
) ieee80211_ioctl_siwfrag
, /* SIOCSIWFRAG */
1098 (iw_handler
) ieee80211_ioctl_giwfrag
, /* SIOCGIWFRAG */
1099 (iw_handler
) ieee80211_ioctl_siwtxpower
, /* SIOCSIWTXPOW */
1100 (iw_handler
) ieee80211_ioctl_giwtxpower
, /* SIOCGIWTXPOW */
1101 (iw_handler
) ieee80211_ioctl_siwretry
, /* SIOCSIWRETRY */
1102 (iw_handler
) ieee80211_ioctl_giwretry
, /* SIOCGIWRETRY */
1103 (iw_handler
) ieee80211_ioctl_siwencode
, /* SIOCSIWENCODE */
1104 (iw_handler
) ieee80211_ioctl_giwencode
, /* SIOCGIWENCODE */
1105 (iw_handler
) NULL
, /* SIOCSIWPOWER */
1106 (iw_handler
) NULL
, /* SIOCGIWPOWER */
1107 (iw_handler
) NULL
, /* -- hole -- */
1108 (iw_handler
) NULL
, /* -- hole -- */
1109 (iw_handler
) ieee80211_ioctl_siwgenie
, /* SIOCSIWGENIE */
1110 (iw_handler
) NULL
, /* SIOCGIWGENIE */
1111 (iw_handler
) ieee80211_ioctl_siwauth
, /* SIOCSIWAUTH */
1112 (iw_handler
) ieee80211_ioctl_giwauth
, /* SIOCGIWAUTH */
1113 (iw_handler
) ieee80211_ioctl_siwencodeext
, /* SIOCSIWENCODEEXT */
1114 (iw_handler
) NULL
, /* SIOCGIWENCODEEXT */
1115 (iw_handler
) NULL
, /* SIOCSIWPMKSA */
1116 (iw_handler
) NULL
, /* -- hole -- */
1119 const struct iw_handler_def ieee80211_iw_handler_def
=
1121 .num_standard
= ARRAY_SIZE(ieee80211_handler
),
1122 .standard
= (iw_handler
*) ieee80211_handler
,
1123 .get_wireless_stats
= ieee80211_get_wireless_stats
,