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_rate.h"
29 static int ieee80211_set_encryption(struct net_device
*dev
, u8
*sta_addr
,
30 int idx
, int alg
, int remove
,
31 int set_tx_key
, const u8
*_key
,
34 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",
48 if (is_broadcast_ether_addr(sta_addr
)) {
50 key
= sdata
->keys
[idx
];
54 * According to the standard, the key index of a pairwise
55 * key must be zero. However, some AP are broken when it
56 * comes to WEP key indices, so we work around this.
58 if (idx
!= 0 && alg
!= ALG_WEP
) {
59 printk(KERN_DEBUG
"%s: set_encrypt - non-zero idx for "
60 "individual key\n", dev
->name
);
64 sta
= sta_info_get(local
, sta_addr
);
66 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
68 printk(KERN_DEBUG
"%s: set_encrypt - unknown addr "
70 dev
->name
, print_mac(mac
, sta_addr
));
71 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
80 ieee80211_key_free(key
);
84 * Automatically frees any old key if present.
86 key
= ieee80211_key_alloc(sdata
, sta
, alg
, idx
, key_len
, _key
);
93 if (set_tx_key
|| (!sta
&& !sdata
->default_key
&& key
))
94 ieee80211_set_default_key(sdata
, idx
);
103 static int ieee80211_ioctl_siwgenie(struct net_device
*dev
,
104 struct iw_request_info
*info
,
105 struct iw_point
*data
, char *extra
)
107 struct ieee80211_sub_if_data
*sdata
;
109 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
111 if (sdata
->flags
& IEEE80211_SDATA_USERSPACE_MLME
)
114 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
115 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
116 int ret
= ieee80211_sta_set_extra_ie(dev
, extra
, data
->length
);
119 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_AUTO_BSSID_SEL
;
120 ieee80211_sta_req_auth(dev
, &sdata
->u
.sta
);
127 static int ieee80211_ioctl_giwname(struct net_device
*dev
,
128 struct iw_request_info
*info
,
129 char *name
, char *extra
)
131 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
133 switch (local
->hw
.conf
.phymode
) {
134 case MODE_IEEE80211A
:
135 strcpy(name
, "IEEE 802.11a");
137 case MODE_IEEE80211B
:
138 strcpy(name
, "IEEE 802.11b");
140 case MODE_IEEE80211G
:
141 strcpy(name
, "IEEE 802.11g");
144 strcpy(name
, "IEEE 802.11");
152 static int ieee80211_ioctl_giwrange(struct net_device
*dev
,
153 struct iw_request_info
*info
,
154 struct iw_point
*data
, char *extra
)
156 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
157 struct iw_range
*range
= (struct iw_range
*) extra
;
158 struct ieee80211_hw_mode
*mode
= NULL
;
161 data
->length
= sizeof(struct iw_range
);
162 memset(range
, 0, sizeof(struct iw_range
));
164 range
->we_version_compiled
= WIRELESS_EXT
;
165 range
->we_version_source
= 21;
166 range
->retry_capa
= IW_RETRY_LIMIT
;
167 range
->retry_flags
= IW_RETRY_LIMIT
;
168 range
->min_retry
= 0;
169 range
->max_retry
= 255;
171 range
->max_rts
= 2347;
172 range
->min_frag
= 256;
173 range
->max_frag
= 2346;
175 range
->encoding_size
[0] = 5;
176 range
->encoding_size
[1] = 13;
177 range
->num_encoding_sizes
= 2;
178 range
->max_encoding_tokens
= NUM_DEFAULT_KEYS
;
180 range
->max_qual
.qual
= local
->hw
.max_signal
;
181 range
->max_qual
.level
= local
->hw
.max_rssi
;
182 range
->max_qual
.noise
= local
->hw
.max_noise
;
183 range
->max_qual
.updated
= local
->wstats_flags
;
185 range
->avg_qual
.qual
= local
->hw
.max_signal
/2;
186 range
->avg_qual
.level
= 0;
187 range
->avg_qual
.noise
= 0;
188 range
->avg_qual
.updated
= local
->wstats_flags
;
190 range
->enc_capa
= IW_ENC_CAPA_WPA
| IW_ENC_CAPA_WPA2
|
191 IW_ENC_CAPA_CIPHER_TKIP
| IW_ENC_CAPA_CIPHER_CCMP
;
193 list_for_each_entry(mode
, &local
->modes_list
, list
) {
196 if (!(local
->enabled_modes
& (1 << mode
->mode
)) ||
197 (local
->hw_modes
& local
->enabled_modes
&
198 (1 << MODE_IEEE80211G
) && mode
->mode
== MODE_IEEE80211B
))
201 while (i
< mode
->num_channels
&& c
< IW_MAX_FREQUENCIES
) {
202 struct ieee80211_channel
*chan
= &mode
->channels
[i
];
204 if (chan
->flag
& IEEE80211_CHAN_W_SCAN
) {
205 range
->freq
[c
].i
= chan
->chan
;
206 range
->freq
[c
].m
= chan
->freq
* 100000;
207 range
->freq
[c
].e
= 1;
213 range
->num_channels
= c
;
214 range
->num_frequency
= c
;
216 IW_EVENT_CAPA_SET_KERNEL(range
->event_capa
);
217 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWTHRSPY
);
218 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWAP
);
219 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWSCAN
);
225 static int ieee80211_ioctl_siwmode(struct net_device
*dev
,
226 struct iw_request_info
*info
,
227 __u32
*mode
, char *extra
)
229 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
232 if (sdata
->type
== IEEE80211_IF_TYPE_VLAN
)
237 type
= IEEE80211_IF_TYPE_STA
;
240 type
= IEEE80211_IF_TYPE_IBSS
;
242 case IW_MODE_MONITOR
:
243 type
= IEEE80211_IF_TYPE_MNTR
;
249 if (type
== sdata
->type
)
251 if (netif_running(dev
))
254 ieee80211_if_reinit(dev
);
255 ieee80211_if_set_type(dev
, type
);
261 static int ieee80211_ioctl_giwmode(struct net_device
*dev
,
262 struct iw_request_info
*info
,
263 __u32
*mode
, char *extra
)
265 struct ieee80211_sub_if_data
*sdata
;
267 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
268 switch (sdata
->type
) {
269 case IEEE80211_IF_TYPE_AP
:
270 *mode
= IW_MODE_MASTER
;
272 case IEEE80211_IF_TYPE_STA
:
273 *mode
= IW_MODE_INFRA
;
275 case IEEE80211_IF_TYPE_IBSS
:
276 *mode
= IW_MODE_ADHOC
;
278 case IEEE80211_IF_TYPE_MNTR
:
279 *mode
= IW_MODE_MONITOR
;
281 case IEEE80211_IF_TYPE_WDS
:
282 *mode
= IW_MODE_REPEAT
;
284 case IEEE80211_IF_TYPE_VLAN
:
285 *mode
= IW_MODE_SECOND
; /* FIXME */
288 *mode
= IW_MODE_AUTO
;
294 int ieee80211_set_channel(struct ieee80211_local
*local
, int channel
, int freq
)
296 struct ieee80211_hw_mode
*mode
;
300 list_for_each_entry(mode
, &local
->modes_list
, list
) {
301 if (!(local
->enabled_modes
& (1 << mode
->mode
)))
303 for (c
= 0; c
< mode
->num_channels
; c
++) {
304 struct ieee80211_channel
*chan
= &mode
->channels
[c
];
305 if (chan
->flag
& IEEE80211_CHAN_W_SCAN
&&
306 ((chan
->chan
== channel
) || (chan
->freq
== freq
))) {
307 local
->oper_channel
= chan
;
308 local
->oper_hw_mode
= mode
;
318 if (local
->sta_scanning
)
321 ret
= ieee80211_hw_config(local
);
323 rate_control_clear(local
);
329 static int ieee80211_ioctl_siwfreq(struct net_device
*dev
,
330 struct iw_request_info
*info
,
331 struct iw_freq
*freq
, char *extra
)
333 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
334 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
336 if (sdata
->type
== IEEE80211_IF_TYPE_STA
)
337 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_AUTO_CHANNEL_SEL
;
339 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
342 if (sdata
->type
== IEEE80211_IF_TYPE_STA
)
343 sdata
->u
.sta
.flags
|=
344 IEEE80211_STA_AUTO_CHANNEL_SEL
;
347 return ieee80211_set_channel(local
, freq
->m
, -1);
349 int i
, div
= 1000000;
350 for (i
= 0; i
< freq
->e
; i
++)
353 return ieee80211_set_channel(local
, -1, freq
->m
/ div
);
360 static int ieee80211_ioctl_giwfreq(struct net_device
*dev
,
361 struct iw_request_info
*info
,
362 struct iw_freq
*freq
, char *extra
)
364 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
366 /* TODO: in station mode (Managed/Ad-hoc) might need to poll low-level
367 * driver for the current channel with firmware-based management */
369 freq
->m
= local
->hw
.conf
.freq
;
376 static int ieee80211_ioctl_siwessid(struct net_device
*dev
,
377 struct iw_request_info
*info
,
378 struct iw_point
*data
, char *ssid
)
380 struct ieee80211_sub_if_data
*sdata
;
381 size_t len
= data
->length
;
383 /* iwconfig uses nul termination in SSID.. */
384 if (len
> 0 && ssid
[len
- 1] == '\0')
387 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
388 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
389 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
391 if (sdata
->flags
& IEEE80211_SDATA_USERSPACE_MLME
) {
392 if (len
> IEEE80211_MAX_SSID_LEN
)
394 memcpy(sdata
->u
.sta
.ssid
, ssid
, len
);
395 sdata
->u
.sta
.ssid_len
= len
;
399 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_AUTO_SSID_SEL
;
401 sdata
->u
.sta
.flags
|= IEEE80211_STA_AUTO_SSID_SEL
;
402 ret
= ieee80211_sta_set_ssid(dev
, ssid
, len
);
405 ieee80211_sta_req_auth(dev
, &sdata
->u
.sta
);
409 if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
410 memcpy(sdata
->u
.ap
.ssid
, ssid
, len
);
411 memset(sdata
->u
.ap
.ssid
+ len
, 0,
412 IEEE80211_MAX_SSID_LEN
- len
);
413 sdata
->u
.ap
.ssid_len
= len
;
414 return ieee80211_if_config(dev
);
420 static int ieee80211_ioctl_giwessid(struct net_device
*dev
,
421 struct iw_request_info
*info
,
422 struct iw_point
*data
, char *ssid
)
426 struct ieee80211_sub_if_data
*sdata
;
427 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
428 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
429 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
430 int res
= ieee80211_sta_get_ssid(dev
, ssid
, &len
);
439 if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
440 len
= sdata
->u
.ap
.ssid_len
;
441 if (len
> IW_ESSID_MAX_SIZE
)
442 len
= IW_ESSID_MAX_SIZE
;
443 memcpy(ssid
, sdata
->u
.ap
.ssid
, len
);
452 static int ieee80211_ioctl_siwap(struct net_device
*dev
,
453 struct iw_request_info
*info
,
454 struct sockaddr
*ap_addr
, char *extra
)
456 struct ieee80211_sub_if_data
*sdata
;
458 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
459 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
460 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
462 if (sdata
->flags
& IEEE80211_SDATA_USERSPACE_MLME
) {
463 memcpy(sdata
->u
.sta
.bssid
, (u8
*) &ap_addr
->sa_data
,
467 if (is_zero_ether_addr((u8
*) &ap_addr
->sa_data
))
468 sdata
->u
.sta
.flags
|= IEEE80211_STA_AUTO_BSSID_SEL
|
469 IEEE80211_STA_AUTO_CHANNEL_SEL
;
470 else if (is_broadcast_ether_addr((u8
*) &ap_addr
->sa_data
))
471 sdata
->u
.sta
.flags
|= IEEE80211_STA_AUTO_BSSID_SEL
;
473 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_AUTO_BSSID_SEL
;
474 ret
= ieee80211_sta_set_bssid(dev
, (u8
*) &ap_addr
->sa_data
);
477 ieee80211_sta_req_auth(dev
, &sdata
->u
.sta
);
479 } else if (sdata
->type
== IEEE80211_IF_TYPE_WDS
) {
480 if (memcmp(sdata
->u
.wds
.remote_addr
, (u8
*) &ap_addr
->sa_data
,
483 return ieee80211_if_update_wds(dev
, (u8
*) &ap_addr
->sa_data
);
490 static int ieee80211_ioctl_giwap(struct net_device
*dev
,
491 struct iw_request_info
*info
,
492 struct sockaddr
*ap_addr
, char *extra
)
494 struct ieee80211_sub_if_data
*sdata
;
496 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
497 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
498 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
499 ap_addr
->sa_family
= ARPHRD_ETHER
;
500 memcpy(&ap_addr
->sa_data
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
502 } else if (sdata
->type
== IEEE80211_IF_TYPE_WDS
) {
503 ap_addr
->sa_family
= ARPHRD_ETHER
;
504 memcpy(&ap_addr
->sa_data
, sdata
->u
.wds
.remote_addr
, ETH_ALEN
);
512 static int ieee80211_ioctl_siwscan(struct net_device
*dev
,
513 struct iw_request_info
*info
,
514 union iwreq_data
*wrqu
, char *extra
)
516 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
517 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
518 struct iw_scan_req
*req
= NULL
;
522 if (!netif_running(dev
))
525 switch (sdata
->type
) {
526 case IEEE80211_IF_TYPE_STA
:
527 case IEEE80211_IF_TYPE_IBSS
:
528 if (local
->scan_flags
& IEEE80211_SCAN_MATCH_SSID
) {
529 ssid
= sdata
->u
.sta
.ssid
;
530 ssid_len
= sdata
->u
.sta
.ssid_len
;
533 case IEEE80211_IF_TYPE_AP
:
534 if (local
->scan_flags
& IEEE80211_SCAN_MATCH_SSID
) {
535 ssid
= sdata
->u
.ap
.ssid
;
536 ssid_len
= sdata
->u
.ap
.ssid_len
;
543 /* if SSID was specified explicitly then use that */
544 if (wrqu
->data
.length
== sizeof(struct iw_scan_req
) &&
545 wrqu
->data
.flags
& IW_SCAN_THIS_ESSID
) {
546 req
= (struct iw_scan_req
*)extra
;
548 ssid_len
= req
->essid_len
;
551 return ieee80211_sta_req_scan(dev
, ssid
, ssid_len
);
555 static int ieee80211_ioctl_giwscan(struct net_device
*dev
,
556 struct iw_request_info
*info
,
557 struct iw_point
*data
, char *extra
)
560 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
561 if (local
->sta_scanning
)
563 res
= ieee80211_sta_scan_results(dev
, extra
, data
->length
);
573 static int ieee80211_ioctl_siwrate(struct net_device
*dev
,
574 struct iw_request_info
*info
,
575 struct iw_param
*rate
, char *extra
)
577 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
578 struct ieee80211_hw_mode
*mode
;
580 u32 target_rate
= rate
->value
/ 100000;
581 struct ieee80211_sub_if_data
*sdata
;
583 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
586 mode
= local
->oper_hw_mode
;
587 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
588 * target_rate = X, rate->fixed = 1 means only rate X
589 * target_rate = X, rate->fixed = 0 means all rates <= X */
590 sdata
->bss
->max_ratectrl_rateidx
= -1;
591 sdata
->bss
->force_unicast_rateidx
= -1;
594 for (i
=0; i
< mode
->num_rates
; i
++) {
595 struct ieee80211_rate
*rates
= &mode
->rates
[i
];
596 int this_rate
= rates
->rate
;
598 if (target_rate
== this_rate
) {
599 sdata
->bss
->max_ratectrl_rateidx
= i
;
601 sdata
->bss
->force_unicast_rateidx
= i
;
608 static int ieee80211_ioctl_giwrate(struct net_device
*dev
,
609 struct iw_request_info
*info
,
610 struct iw_param
*rate
, char *extra
)
612 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
613 struct sta_info
*sta
;
614 struct ieee80211_sub_if_data
*sdata
;
616 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
617 if (sdata
->type
== IEEE80211_IF_TYPE_STA
)
618 sta
= sta_info_get(local
, sdata
->u
.sta
.bssid
);
623 if (sta
->txrate
< local
->oper_hw_mode
->num_rates
)
624 rate
->value
= local
->oper_hw_mode
->rates
[sta
->txrate
].rate
* 100000;
631 static int ieee80211_ioctl_siwtxpower(struct net_device
*dev
,
632 struct iw_request_info
*info
,
633 union iwreq_data
*data
, char *extra
)
635 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
636 bool need_reconfig
= 0;
638 if ((data
->txpower
.flags
& IW_TXPOW_TYPE
) != IW_TXPOW_DBM
)
640 if (data
->txpower
.flags
& IW_TXPOW_RANGE
)
642 if (!data
->txpower
.fixed
)
645 if (local
->hw
.conf
.power_level
!= data
->txpower
.value
) {
646 local
->hw
.conf
.power_level
= data
->txpower
.value
;
649 if (local
->hw
.conf
.radio_enabled
!= !(data
->txpower
.disabled
)) {
650 local
->hw
.conf
.radio_enabled
= !(data
->txpower
.disabled
);
654 ieee80211_hw_config(local
);
655 /* The return value of hw_config is not of big interest here,
656 * as it doesn't say that it failed because of _this_ config
657 * change or something else. Ignore it. */
663 static int ieee80211_ioctl_giwtxpower(struct net_device
*dev
,
664 struct iw_request_info
*info
,
665 union iwreq_data
*data
, char *extra
)
667 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
669 data
->txpower
.fixed
= 1;
670 data
->txpower
.disabled
= !(local
->hw
.conf
.radio_enabled
);
671 data
->txpower
.value
= local
->hw
.conf
.power_level
;
672 data
->txpower
.flags
= IW_TXPOW_DBM
;
677 static int ieee80211_ioctl_siwrts(struct net_device
*dev
,
678 struct iw_request_info
*info
,
679 struct iw_param
*rts
, char *extra
)
681 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
684 local
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
685 else if (rts
->value
< 0 || rts
->value
> IEEE80211_MAX_RTS_THRESHOLD
)
688 local
->rts_threshold
= rts
->value
;
690 /* If the wlan card performs RTS/CTS in hardware/firmware,
691 * configure it here */
693 if (local
->ops
->set_rts_threshold
)
694 local
->ops
->set_rts_threshold(local_to_hw(local
),
695 local
->rts_threshold
);
700 static int ieee80211_ioctl_giwrts(struct net_device
*dev
,
701 struct iw_request_info
*info
,
702 struct iw_param
*rts
, char *extra
)
704 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
706 rts
->value
= local
->rts_threshold
;
707 rts
->disabled
= (rts
->value
>= IEEE80211_MAX_RTS_THRESHOLD
);
714 static int ieee80211_ioctl_siwfrag(struct net_device
*dev
,
715 struct iw_request_info
*info
,
716 struct iw_param
*frag
, char *extra
)
718 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
721 local
->fragmentation_threshold
= IEEE80211_MAX_FRAG_THRESHOLD
;
722 else if (frag
->value
< 256 ||
723 frag
->value
> IEEE80211_MAX_FRAG_THRESHOLD
)
726 /* Fragment length must be even, so strip LSB. */
727 local
->fragmentation_threshold
= frag
->value
& ~0x1;
730 /* If the wlan card performs fragmentation in hardware/firmware,
731 * configure it here */
733 if (local
->ops
->set_frag_threshold
)
734 local
->ops
->set_frag_threshold(
736 local
->fragmentation_threshold
);
741 static int ieee80211_ioctl_giwfrag(struct net_device
*dev
,
742 struct iw_request_info
*info
,
743 struct iw_param
*frag
, char *extra
)
745 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
747 frag
->value
= local
->fragmentation_threshold
;
748 frag
->disabled
= (frag
->value
>= IEEE80211_MAX_RTS_THRESHOLD
);
755 static int ieee80211_ioctl_siwretry(struct net_device
*dev
,
756 struct iw_request_info
*info
,
757 struct iw_param
*retry
, char *extra
)
759 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
761 if (retry
->disabled
||
762 (retry
->flags
& IW_RETRY_TYPE
) != IW_RETRY_LIMIT
)
765 if (retry
->flags
& IW_RETRY_MAX
)
766 local
->long_retry_limit
= retry
->value
;
767 else if (retry
->flags
& IW_RETRY_MIN
)
768 local
->short_retry_limit
= retry
->value
;
770 local
->long_retry_limit
= retry
->value
;
771 local
->short_retry_limit
= retry
->value
;
774 if (local
->ops
->set_retry_limit
) {
775 return local
->ops
->set_retry_limit(
777 local
->short_retry_limit
,
778 local
->long_retry_limit
);
785 static int ieee80211_ioctl_giwretry(struct net_device
*dev
,
786 struct iw_request_info
*info
,
787 struct iw_param
*retry
, char *extra
)
789 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
792 if (retry
->flags
== 0 || retry
->flags
& IW_RETRY_MIN
) {
793 /* first return min value, iwconfig will ask max value
795 retry
->flags
|= IW_RETRY_LIMIT
;
796 retry
->value
= local
->short_retry_limit
;
797 if (local
->long_retry_limit
!= local
->short_retry_limit
)
798 retry
->flags
|= IW_RETRY_MIN
;
801 if (retry
->flags
& IW_RETRY_MAX
) {
802 retry
->flags
= IW_RETRY_LIMIT
| IW_RETRY_MAX
;
803 retry
->value
= local
->long_retry_limit
;
809 static int ieee80211_ioctl_siwmlme(struct net_device
*dev
,
810 struct iw_request_info
*info
,
811 struct iw_point
*data
, char *extra
)
813 struct ieee80211_sub_if_data
*sdata
;
814 struct iw_mlme
*mlme
= (struct iw_mlme
*) extra
;
816 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
817 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
818 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
823 /* TODO: mlme->addr.sa_data */
824 return ieee80211_sta_deauthenticate(dev
, mlme
->reason_code
);
825 case IW_MLME_DISASSOC
:
826 /* TODO: mlme->addr.sa_data */
827 return ieee80211_sta_disassociate(dev
, mlme
->reason_code
);
834 static int ieee80211_ioctl_siwencode(struct net_device
*dev
,
835 struct iw_request_info
*info
,
836 struct iw_point
*erq
, char *keybuf
)
838 struct ieee80211_sub_if_data
*sdata
;
839 int idx
, i
, alg
= ALG_WEP
;
840 u8 bcaddr
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
843 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
845 idx
= erq
->flags
& IW_ENCODE_INDEX
;
847 if (sdata
->default_key
)
848 for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
849 if (sdata
->default_key
== sdata
->keys
[i
]) {
854 } else if (idx
< 1 || idx
> 4)
859 if (erq
->flags
& IW_ENCODE_DISABLED
)
861 else if (erq
->length
== 0) {
862 /* No key data - just set the default TX key index */
863 ieee80211_set_default_key(sdata
, idx
);
867 return ieee80211_set_encryption(
871 keybuf
, erq
->length
);
875 static int ieee80211_ioctl_giwencode(struct net_device
*dev
,
876 struct iw_request_info
*info
,
877 struct iw_point
*erq
, char *key
)
879 struct ieee80211_sub_if_data
*sdata
;
882 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
884 idx
= erq
->flags
& IW_ENCODE_INDEX
;
885 if (idx
< 1 || idx
> 4) {
887 if (!sdata
->default_key
)
889 else for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
890 if (sdata
->default_key
== sdata
->keys
[i
]) {
900 erq
->flags
= idx
+ 1;
902 if (!sdata
->keys
[idx
]) {
904 erq
->flags
|= IW_ENCODE_DISABLED
;
908 memcpy(key
, sdata
->keys
[idx
]->conf
.key
,
909 min_t(int, erq
->length
, sdata
->keys
[idx
]->conf
.keylen
));
910 erq
->length
= sdata
->keys
[idx
]->conf
.keylen
;
911 erq
->flags
|= IW_ENCODE_ENABLED
;
916 static int ieee80211_ioctl_siwauth(struct net_device
*dev
,
917 struct iw_request_info
*info
,
918 struct iw_param
*data
, char *extra
)
920 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
923 switch (data
->flags
& IW_AUTH_INDEX
) {
924 case IW_AUTH_WPA_VERSION
:
925 case IW_AUTH_CIPHER_PAIRWISE
:
926 case IW_AUTH_CIPHER_GROUP
:
927 case IW_AUTH_WPA_ENABLED
:
928 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
929 case IW_AUTH_KEY_MGMT
:
931 case IW_AUTH_PRIVACY_INVOKED
:
932 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
935 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_PRIVACY_INVOKED
;
937 * Privacy invoked by wpa_supplicant, store the
938 * value and allow associating to a protected
939 * network without having a key up front.
942 sdata
->u
.sta
.flags
|=
943 IEEE80211_STA_PRIVACY_INVOKED
;
946 case IW_AUTH_80211_AUTH_ALG
:
947 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
948 sdata
->type
== IEEE80211_IF_TYPE_IBSS
)
949 sdata
->u
.sta
.auth_algs
= data
->value
;
960 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
961 static struct iw_statistics
*ieee80211_get_wireless_stats(struct net_device
*dev
)
963 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
964 struct iw_statistics
*wstats
= &local
->wstats
;
965 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
966 struct sta_info
*sta
= NULL
;
968 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
969 sdata
->type
== IEEE80211_IF_TYPE_IBSS
)
970 sta
= sta_info_get(local
, sdata
->u
.sta
.bssid
);
972 wstats
->discard
.fragment
= 0;
973 wstats
->discard
.misc
= 0;
974 wstats
->qual
.qual
= 0;
975 wstats
->qual
.level
= 0;
976 wstats
->qual
.noise
= 0;
977 wstats
->qual
.updated
= IW_QUAL_ALL_INVALID
;
979 wstats
->qual
.level
= sta
->last_rssi
;
980 wstats
->qual
.qual
= sta
->last_signal
;
981 wstats
->qual
.noise
= sta
->last_noise
;
982 wstats
->qual
.updated
= local
->wstats_flags
;
988 static int ieee80211_ioctl_giwauth(struct net_device
*dev
,
989 struct iw_request_info
*info
,
990 struct iw_param
*data
, char *extra
)
992 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
995 switch (data
->flags
& IW_AUTH_INDEX
) {
996 case IW_AUTH_80211_AUTH_ALG
:
997 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
998 sdata
->type
== IEEE80211_IF_TYPE_IBSS
)
999 data
->value
= sdata
->u
.sta
.auth_algs
;
1011 static int ieee80211_ioctl_siwencodeext(struct net_device
*dev
,
1012 struct iw_request_info
*info
,
1013 struct iw_point
*erq
, char *extra
)
1015 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1016 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*) extra
;
1017 int uninitialized_var(alg
), idx
, i
, remove
= 0;
1020 case IW_ENCODE_ALG_NONE
:
1023 case IW_ENCODE_ALG_WEP
:
1026 case IW_ENCODE_ALG_TKIP
:
1029 case IW_ENCODE_ALG_CCMP
:
1036 if (erq
->flags
& IW_ENCODE_DISABLED
)
1039 idx
= erq
->flags
& IW_ENCODE_INDEX
;
1040 if (idx
< 1 || idx
> 4) {
1042 if (!sdata
->default_key
)
1044 else for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
1045 if (sdata
->default_key
== sdata
->keys
[i
]) {
1055 return ieee80211_set_encryption(dev
, ext
->addr
.sa_data
, idx
, alg
,
1058 IW_ENCODE_EXT_SET_TX_KEY
,
1059 ext
->key
, ext
->key_len
);
1063 /* Structures to export the Wireless Handlers */
1065 static const iw_handler ieee80211_handler
[] =
1067 (iw_handler
) NULL
, /* SIOCSIWCOMMIT */
1068 (iw_handler
) ieee80211_ioctl_giwname
, /* SIOCGIWNAME */
1069 (iw_handler
) NULL
, /* SIOCSIWNWID */
1070 (iw_handler
) NULL
, /* SIOCGIWNWID */
1071 (iw_handler
) ieee80211_ioctl_siwfreq
, /* SIOCSIWFREQ */
1072 (iw_handler
) ieee80211_ioctl_giwfreq
, /* SIOCGIWFREQ */
1073 (iw_handler
) ieee80211_ioctl_siwmode
, /* SIOCSIWMODE */
1074 (iw_handler
) ieee80211_ioctl_giwmode
, /* SIOCGIWMODE */
1075 (iw_handler
) NULL
, /* SIOCSIWSENS */
1076 (iw_handler
) NULL
, /* SIOCGIWSENS */
1077 (iw_handler
) NULL
/* not used */, /* SIOCSIWRANGE */
1078 (iw_handler
) ieee80211_ioctl_giwrange
, /* SIOCGIWRANGE */
1079 (iw_handler
) NULL
/* not used */, /* SIOCSIWPRIV */
1080 (iw_handler
) NULL
/* kernel code */, /* SIOCGIWPRIV */
1081 (iw_handler
) NULL
/* not used */, /* SIOCSIWSTATS */
1082 (iw_handler
) NULL
/* kernel code */, /* SIOCGIWSTATS */
1083 (iw_handler
) NULL
, /* SIOCSIWSPY */
1084 (iw_handler
) NULL
, /* SIOCGIWSPY */
1085 (iw_handler
) NULL
, /* SIOCSIWTHRSPY */
1086 (iw_handler
) NULL
, /* SIOCGIWTHRSPY */
1087 (iw_handler
) ieee80211_ioctl_siwap
, /* SIOCSIWAP */
1088 (iw_handler
) ieee80211_ioctl_giwap
, /* SIOCGIWAP */
1089 (iw_handler
) ieee80211_ioctl_siwmlme
, /* SIOCSIWMLME */
1090 (iw_handler
) NULL
, /* SIOCGIWAPLIST */
1091 (iw_handler
) ieee80211_ioctl_siwscan
, /* SIOCSIWSCAN */
1092 (iw_handler
) ieee80211_ioctl_giwscan
, /* SIOCGIWSCAN */
1093 (iw_handler
) ieee80211_ioctl_siwessid
, /* SIOCSIWESSID */
1094 (iw_handler
) ieee80211_ioctl_giwessid
, /* SIOCGIWESSID */
1095 (iw_handler
) NULL
, /* SIOCSIWNICKN */
1096 (iw_handler
) NULL
, /* SIOCGIWNICKN */
1097 (iw_handler
) NULL
, /* -- hole -- */
1098 (iw_handler
) NULL
, /* -- hole -- */
1099 (iw_handler
) ieee80211_ioctl_siwrate
, /* SIOCSIWRATE */
1100 (iw_handler
) ieee80211_ioctl_giwrate
, /* SIOCGIWRATE */
1101 (iw_handler
) ieee80211_ioctl_siwrts
, /* SIOCSIWRTS */
1102 (iw_handler
) ieee80211_ioctl_giwrts
, /* SIOCGIWRTS */
1103 (iw_handler
) ieee80211_ioctl_siwfrag
, /* SIOCSIWFRAG */
1104 (iw_handler
) ieee80211_ioctl_giwfrag
, /* SIOCGIWFRAG */
1105 (iw_handler
) ieee80211_ioctl_siwtxpower
, /* SIOCSIWTXPOW */
1106 (iw_handler
) ieee80211_ioctl_giwtxpower
, /* SIOCGIWTXPOW */
1107 (iw_handler
) ieee80211_ioctl_siwretry
, /* SIOCSIWRETRY */
1108 (iw_handler
) ieee80211_ioctl_giwretry
, /* SIOCGIWRETRY */
1109 (iw_handler
) ieee80211_ioctl_siwencode
, /* SIOCSIWENCODE */
1110 (iw_handler
) ieee80211_ioctl_giwencode
, /* SIOCGIWENCODE */
1111 (iw_handler
) NULL
, /* SIOCSIWPOWER */
1112 (iw_handler
) NULL
, /* SIOCGIWPOWER */
1113 (iw_handler
) NULL
, /* -- hole -- */
1114 (iw_handler
) NULL
, /* -- hole -- */
1115 (iw_handler
) ieee80211_ioctl_siwgenie
, /* SIOCSIWGENIE */
1116 (iw_handler
) NULL
, /* SIOCGIWGENIE */
1117 (iw_handler
) ieee80211_ioctl_siwauth
, /* SIOCSIWAUTH */
1118 (iw_handler
) ieee80211_ioctl_giwauth
, /* SIOCGIWAUTH */
1119 (iw_handler
) ieee80211_ioctl_siwencodeext
, /* SIOCSIWENCODEEXT */
1120 (iw_handler
) NULL
, /* SIOCGIWENCODEEXT */
1121 (iw_handler
) NULL
, /* SIOCSIWPMKSA */
1122 (iw_handler
) NULL
, /* -- hole -- */
1125 const struct iw_handler_def ieee80211_iw_handler_def
=
1127 .num_standard
= ARRAY_SIZE(ieee80211_handler
),
1128 .standard
= (iw_handler
*) ieee80211_handler
,
1129 .get_wireless_stats
= ieee80211_get_wireless_stats
,