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
;
315 if (local
->sta_scanning
)
318 ret
= ieee80211_hw_config(local
);
320 rate_control_clear(local
);
326 static int ieee80211_ioctl_siwfreq(struct net_device
*dev
,
327 struct iw_request_info
*info
,
328 struct iw_freq
*freq
, char *extra
)
330 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
331 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
333 if (sdata
->type
== IEEE80211_IF_TYPE_STA
)
334 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_AUTO_CHANNEL_SEL
;
336 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
339 if (sdata
->type
== IEEE80211_IF_TYPE_STA
)
340 sdata
->u
.sta
.flags
|=
341 IEEE80211_STA_AUTO_CHANNEL_SEL
;
344 return ieee80211_set_channel(local
, freq
->m
, -1);
346 int i
, div
= 1000000;
347 for (i
= 0; i
< freq
->e
; i
++)
350 return ieee80211_set_channel(local
, -1, freq
->m
/ div
);
357 static int ieee80211_ioctl_giwfreq(struct net_device
*dev
,
358 struct iw_request_info
*info
,
359 struct iw_freq
*freq
, char *extra
)
361 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
363 /* TODO: in station mode (Managed/Ad-hoc) might need to poll low-level
364 * driver for the current channel with firmware-based management */
366 freq
->m
= local
->hw
.conf
.freq
;
373 static int ieee80211_ioctl_siwessid(struct net_device
*dev
,
374 struct iw_request_info
*info
,
375 struct iw_point
*data
, char *ssid
)
377 struct ieee80211_sub_if_data
*sdata
;
378 size_t len
= data
->length
;
380 /* iwconfig uses nul termination in SSID.. */
381 if (len
> 0 && ssid
[len
- 1] == '\0')
384 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
385 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
386 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
388 if (sdata
->flags
& IEEE80211_SDATA_USERSPACE_MLME
) {
389 if (len
> IEEE80211_MAX_SSID_LEN
)
391 memcpy(sdata
->u
.sta
.ssid
, ssid
, len
);
392 sdata
->u
.sta
.ssid_len
= len
;
396 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_AUTO_SSID_SEL
;
398 sdata
->u
.sta
.flags
|= IEEE80211_STA_AUTO_SSID_SEL
;
399 ret
= ieee80211_sta_set_ssid(dev
, ssid
, len
);
402 ieee80211_sta_req_auth(dev
, &sdata
->u
.sta
);
406 if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
407 memcpy(sdata
->u
.ap
.ssid
, ssid
, len
);
408 memset(sdata
->u
.ap
.ssid
+ len
, 0,
409 IEEE80211_MAX_SSID_LEN
- len
);
410 sdata
->u
.ap
.ssid_len
= len
;
411 return ieee80211_if_config(dev
);
417 static int ieee80211_ioctl_giwessid(struct net_device
*dev
,
418 struct iw_request_info
*info
,
419 struct iw_point
*data
, char *ssid
)
423 struct ieee80211_sub_if_data
*sdata
;
424 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
425 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
426 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
427 int res
= ieee80211_sta_get_ssid(dev
, ssid
, &len
);
436 if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
437 len
= sdata
->u
.ap
.ssid_len
;
438 if (len
> IW_ESSID_MAX_SIZE
)
439 len
= IW_ESSID_MAX_SIZE
;
440 memcpy(ssid
, sdata
->u
.ap
.ssid
, len
);
449 static int ieee80211_ioctl_siwap(struct net_device
*dev
,
450 struct iw_request_info
*info
,
451 struct sockaddr
*ap_addr
, char *extra
)
453 struct ieee80211_sub_if_data
*sdata
;
455 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
456 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
457 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
459 if (sdata
->flags
& IEEE80211_SDATA_USERSPACE_MLME
) {
460 memcpy(sdata
->u
.sta
.bssid
, (u8
*) &ap_addr
->sa_data
,
464 if (is_zero_ether_addr((u8
*) &ap_addr
->sa_data
))
465 sdata
->u
.sta
.flags
|= IEEE80211_STA_AUTO_BSSID_SEL
|
466 IEEE80211_STA_AUTO_CHANNEL_SEL
;
467 else if (is_broadcast_ether_addr((u8
*) &ap_addr
->sa_data
))
468 sdata
->u
.sta
.flags
|= IEEE80211_STA_AUTO_BSSID_SEL
;
470 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_AUTO_BSSID_SEL
;
471 ret
= ieee80211_sta_set_bssid(dev
, (u8
*) &ap_addr
->sa_data
);
474 ieee80211_sta_req_auth(dev
, &sdata
->u
.sta
);
476 } else if (sdata
->type
== IEEE80211_IF_TYPE_WDS
) {
477 if (memcmp(sdata
->u
.wds
.remote_addr
, (u8
*) &ap_addr
->sa_data
,
480 return ieee80211_if_update_wds(dev
, (u8
*) &ap_addr
->sa_data
);
487 static int ieee80211_ioctl_giwap(struct net_device
*dev
,
488 struct iw_request_info
*info
,
489 struct sockaddr
*ap_addr
, char *extra
)
491 struct ieee80211_sub_if_data
*sdata
;
493 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
494 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
495 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
496 ap_addr
->sa_family
= ARPHRD_ETHER
;
497 memcpy(&ap_addr
->sa_data
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
499 } else if (sdata
->type
== IEEE80211_IF_TYPE_WDS
) {
500 ap_addr
->sa_family
= ARPHRD_ETHER
;
501 memcpy(&ap_addr
->sa_data
, sdata
->u
.wds
.remote_addr
, ETH_ALEN
);
509 static int ieee80211_ioctl_siwscan(struct net_device
*dev
,
510 struct iw_request_info
*info
,
511 struct iw_point
*data
, char *extra
)
513 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
514 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
518 if (!netif_running(dev
))
521 switch (sdata
->type
) {
522 case IEEE80211_IF_TYPE_STA
:
523 case IEEE80211_IF_TYPE_IBSS
:
524 if (local
->scan_flags
& IEEE80211_SCAN_MATCH_SSID
) {
525 ssid
= sdata
->u
.sta
.ssid
;
526 ssid_len
= sdata
->u
.sta
.ssid_len
;
529 case IEEE80211_IF_TYPE_AP
:
530 if (local
->scan_flags
& IEEE80211_SCAN_MATCH_SSID
) {
531 ssid
= sdata
->u
.ap
.ssid
;
532 ssid_len
= sdata
->u
.ap
.ssid_len
;
539 return ieee80211_sta_req_scan(dev
, ssid
, ssid_len
);
543 static int ieee80211_ioctl_giwscan(struct net_device
*dev
,
544 struct iw_request_info
*info
,
545 struct iw_point
*data
, char *extra
)
548 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
549 if (local
->sta_scanning
)
551 res
= ieee80211_sta_scan_results(dev
, extra
, data
->length
);
561 static int ieee80211_ioctl_siwrate(struct net_device
*dev
,
562 struct iw_request_info
*info
,
563 struct iw_param
*rate
, char *extra
)
565 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
566 struct ieee80211_hw_mode
*mode
;
568 u32 target_rate
= rate
->value
/ 100000;
569 struct ieee80211_sub_if_data
*sdata
;
571 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
574 mode
= local
->oper_hw_mode
;
575 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
576 * target_rate = X, rate->fixed = 1 means only rate X
577 * target_rate = X, rate->fixed = 0 means all rates <= X */
578 sdata
->bss
->max_ratectrl_rateidx
= -1;
579 sdata
->bss
->force_unicast_rateidx
= -1;
582 for (i
=0; i
< mode
->num_rates
; i
++) {
583 struct ieee80211_rate
*rates
= &mode
->rates
[i
];
584 int this_rate
= rates
->rate
;
586 if (target_rate
== this_rate
) {
587 sdata
->bss
->max_ratectrl_rateidx
= i
;
589 sdata
->bss
->force_unicast_rateidx
= i
;
596 static int ieee80211_ioctl_giwrate(struct net_device
*dev
,
597 struct iw_request_info
*info
,
598 struct iw_param
*rate
, char *extra
)
600 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
601 struct sta_info
*sta
;
602 struct ieee80211_sub_if_data
*sdata
;
604 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
605 if (sdata
->type
== IEEE80211_IF_TYPE_STA
)
606 sta
= sta_info_get(local
, sdata
->u
.sta
.bssid
);
611 if (sta
->txrate
< local
->oper_hw_mode
->num_rates
)
612 rate
->value
= local
->oper_hw_mode
->rates
[sta
->txrate
].rate
* 100000;
619 static int ieee80211_ioctl_siwtxpower(struct net_device
*dev
,
620 struct iw_request_info
*info
,
621 union iwreq_data
*data
, char *extra
)
623 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
624 bool need_reconfig
= 0;
626 if ((data
->txpower
.flags
& IW_TXPOW_TYPE
) != IW_TXPOW_DBM
)
628 if (data
->txpower
.flags
& IW_TXPOW_RANGE
)
630 if (!data
->txpower
.fixed
)
633 if (local
->hw
.conf
.power_level
!= data
->txpower
.value
) {
634 local
->hw
.conf
.power_level
= data
->txpower
.value
;
637 if (local
->hw
.conf
.radio_enabled
!= !(data
->txpower
.disabled
)) {
638 local
->hw
.conf
.radio_enabled
= !(data
->txpower
.disabled
);
642 ieee80211_hw_config(local
);
643 /* The return value of hw_config is not of big interest here,
644 * as it doesn't say that it failed because of _this_ config
645 * change or something else. Ignore it. */
651 static int ieee80211_ioctl_giwtxpower(struct net_device
*dev
,
652 struct iw_request_info
*info
,
653 union iwreq_data
*data
, char *extra
)
655 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
657 data
->txpower
.fixed
= 1;
658 data
->txpower
.disabled
= !(local
->hw
.conf
.radio_enabled
);
659 data
->txpower
.value
= local
->hw
.conf
.power_level
;
660 data
->txpower
.flags
= IW_TXPOW_DBM
;
665 static int ieee80211_ioctl_siwrts(struct net_device
*dev
,
666 struct iw_request_info
*info
,
667 struct iw_param
*rts
, char *extra
)
669 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
672 local
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
673 else if (rts
->value
< 0 || rts
->value
> IEEE80211_MAX_RTS_THRESHOLD
)
676 local
->rts_threshold
= rts
->value
;
678 /* If the wlan card performs RTS/CTS in hardware/firmware,
679 * configure it here */
681 if (local
->ops
->set_rts_threshold
)
682 local
->ops
->set_rts_threshold(local_to_hw(local
),
683 local
->rts_threshold
);
688 static int ieee80211_ioctl_giwrts(struct net_device
*dev
,
689 struct iw_request_info
*info
,
690 struct iw_param
*rts
, char *extra
)
692 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
694 rts
->value
= local
->rts_threshold
;
695 rts
->disabled
= (rts
->value
>= IEEE80211_MAX_RTS_THRESHOLD
);
702 static int ieee80211_ioctl_siwfrag(struct net_device
*dev
,
703 struct iw_request_info
*info
,
704 struct iw_param
*frag
, char *extra
)
706 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
709 local
->fragmentation_threshold
= IEEE80211_MAX_FRAG_THRESHOLD
;
710 else if (frag
->value
< 256 ||
711 frag
->value
> IEEE80211_MAX_FRAG_THRESHOLD
)
714 /* Fragment length must be even, so strip LSB. */
715 local
->fragmentation_threshold
= frag
->value
& ~0x1;
718 /* If the wlan card performs fragmentation in hardware/firmware,
719 * configure it here */
721 if (local
->ops
->set_frag_threshold
)
722 local
->ops
->set_frag_threshold(
724 local
->fragmentation_threshold
);
729 static int ieee80211_ioctl_giwfrag(struct net_device
*dev
,
730 struct iw_request_info
*info
,
731 struct iw_param
*frag
, char *extra
)
733 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
735 frag
->value
= local
->fragmentation_threshold
;
736 frag
->disabled
= (frag
->value
>= IEEE80211_MAX_RTS_THRESHOLD
);
743 static int ieee80211_ioctl_siwretry(struct net_device
*dev
,
744 struct iw_request_info
*info
,
745 struct iw_param
*retry
, char *extra
)
747 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
749 if (retry
->disabled
||
750 (retry
->flags
& IW_RETRY_TYPE
) != IW_RETRY_LIMIT
)
753 if (retry
->flags
& IW_RETRY_MAX
)
754 local
->long_retry_limit
= retry
->value
;
755 else if (retry
->flags
& IW_RETRY_MIN
)
756 local
->short_retry_limit
= retry
->value
;
758 local
->long_retry_limit
= retry
->value
;
759 local
->short_retry_limit
= retry
->value
;
762 if (local
->ops
->set_retry_limit
) {
763 return local
->ops
->set_retry_limit(
765 local
->short_retry_limit
,
766 local
->long_retry_limit
);
773 static int ieee80211_ioctl_giwretry(struct net_device
*dev
,
774 struct iw_request_info
*info
,
775 struct iw_param
*retry
, char *extra
)
777 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
780 if (retry
->flags
== 0 || retry
->flags
& IW_RETRY_MIN
) {
781 /* first return min value, iwconfig will ask max value
783 retry
->flags
|= IW_RETRY_LIMIT
;
784 retry
->value
= local
->short_retry_limit
;
785 if (local
->long_retry_limit
!= local
->short_retry_limit
)
786 retry
->flags
|= IW_RETRY_MIN
;
789 if (retry
->flags
& IW_RETRY_MAX
) {
790 retry
->flags
= IW_RETRY_LIMIT
| IW_RETRY_MAX
;
791 retry
->value
= local
->long_retry_limit
;
797 static int ieee80211_ioctl_siwmlme(struct net_device
*dev
,
798 struct iw_request_info
*info
,
799 struct iw_point
*data
, char *extra
)
801 struct ieee80211_sub_if_data
*sdata
;
802 struct iw_mlme
*mlme
= (struct iw_mlme
*) extra
;
804 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
805 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
806 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
811 /* TODO: mlme->addr.sa_data */
812 return ieee80211_sta_deauthenticate(dev
, mlme
->reason_code
);
813 case IW_MLME_DISASSOC
:
814 /* TODO: mlme->addr.sa_data */
815 return ieee80211_sta_disassociate(dev
, mlme
->reason_code
);
822 static int ieee80211_ioctl_siwencode(struct net_device
*dev
,
823 struct iw_request_info
*info
,
824 struct iw_point
*erq
, char *keybuf
)
826 struct ieee80211_sub_if_data
*sdata
;
827 int idx
, i
, alg
= ALG_WEP
;
828 u8 bcaddr
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
831 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
833 idx
= erq
->flags
& IW_ENCODE_INDEX
;
835 if (sdata
->default_key
)
836 for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
837 if (sdata
->default_key
== sdata
->keys
[i
]) {
842 } else if (idx
< 1 || idx
> 4)
847 if (erq
->flags
& IW_ENCODE_DISABLED
)
849 else if (erq
->length
== 0) {
850 /* No key data - just set the default TX key index */
851 ieee80211_set_default_key(sdata
, idx
);
855 return ieee80211_set_encryption(
859 keybuf
, erq
->length
);
863 static int ieee80211_ioctl_giwencode(struct net_device
*dev
,
864 struct iw_request_info
*info
,
865 struct iw_point
*erq
, char *key
)
867 struct ieee80211_sub_if_data
*sdata
;
870 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
872 idx
= erq
->flags
& IW_ENCODE_INDEX
;
873 if (idx
< 1 || idx
> 4) {
875 if (!sdata
->default_key
)
877 else for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
878 if (sdata
->default_key
== sdata
->keys
[i
]) {
888 erq
->flags
= idx
+ 1;
890 if (!sdata
->keys
[idx
]) {
892 erq
->flags
|= IW_ENCODE_DISABLED
;
896 memcpy(key
, sdata
->keys
[idx
]->conf
.key
,
897 min_t(int, erq
->length
, sdata
->keys
[idx
]->conf
.keylen
));
898 erq
->length
= sdata
->keys
[idx
]->conf
.keylen
;
899 erq
->flags
|= IW_ENCODE_ENABLED
;
904 static int ieee80211_ioctl_siwauth(struct net_device
*dev
,
905 struct iw_request_info
*info
,
906 struct iw_param
*data
, char *extra
)
908 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
909 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
912 switch (data
->flags
& IW_AUTH_INDEX
) {
913 case IW_AUTH_WPA_VERSION
:
914 case IW_AUTH_CIPHER_PAIRWISE
:
915 case IW_AUTH_CIPHER_GROUP
:
916 case IW_AUTH_WPA_ENABLED
:
917 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
919 case IW_AUTH_KEY_MGMT
:
920 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
924 * Key management was set by wpa_supplicant,
925 * we only need this to associate to a network
926 * that has privacy enabled regardless of not
929 sdata
->u
.sta
.key_management_enabled
= !!data
->value
;
932 case IW_AUTH_80211_AUTH_ALG
:
933 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
934 sdata
->type
== IEEE80211_IF_TYPE_IBSS
)
935 sdata
->u
.sta
.auth_algs
= data
->value
;
939 case IW_AUTH_PRIVACY_INVOKED
:
940 if (local
->ops
->set_privacy_invoked
)
941 ret
= local
->ops
->set_privacy_invoked(
942 local_to_hw(local
), data
->value
);
951 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
952 static struct iw_statistics
*ieee80211_get_wireless_stats(struct net_device
*dev
)
954 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
955 struct iw_statistics
*wstats
= &local
->wstats
;
956 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
957 struct sta_info
*sta
= NULL
;
959 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
960 sdata
->type
== IEEE80211_IF_TYPE_IBSS
)
961 sta
= sta_info_get(local
, sdata
->u
.sta
.bssid
);
963 wstats
->discard
.fragment
= 0;
964 wstats
->discard
.misc
= 0;
965 wstats
->qual
.qual
= 0;
966 wstats
->qual
.level
= 0;
967 wstats
->qual
.noise
= 0;
968 wstats
->qual
.updated
= IW_QUAL_ALL_INVALID
;
970 wstats
->qual
.level
= sta
->last_rssi
;
971 wstats
->qual
.qual
= sta
->last_signal
;
972 wstats
->qual
.noise
= sta
->last_noise
;
973 wstats
->qual
.updated
= local
->wstats_flags
;
979 static int ieee80211_ioctl_giwauth(struct net_device
*dev
,
980 struct iw_request_info
*info
,
981 struct iw_param
*data
, char *extra
)
983 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
986 switch (data
->flags
& IW_AUTH_INDEX
) {
987 case IW_AUTH_80211_AUTH_ALG
:
988 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
989 sdata
->type
== IEEE80211_IF_TYPE_IBSS
)
990 data
->value
= sdata
->u
.sta
.auth_algs
;
1002 static int ieee80211_ioctl_siwencodeext(struct net_device
*dev
,
1003 struct iw_request_info
*info
,
1004 struct iw_point
*erq
, char *extra
)
1006 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1007 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*) extra
;
1008 int uninitialized_var(alg
), idx
, i
, remove
= 0;
1011 case IW_ENCODE_ALG_NONE
:
1014 case IW_ENCODE_ALG_WEP
:
1017 case IW_ENCODE_ALG_TKIP
:
1020 case IW_ENCODE_ALG_CCMP
:
1027 if (erq
->flags
& IW_ENCODE_DISABLED
)
1030 idx
= erq
->flags
& IW_ENCODE_INDEX
;
1031 if (idx
< 1 || idx
> 4) {
1033 if (!sdata
->default_key
)
1035 else for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
1036 if (sdata
->default_key
== sdata
->keys
[i
]) {
1046 return ieee80211_set_encryption(dev
, ext
->addr
.sa_data
, idx
, alg
,
1049 IW_ENCODE_EXT_SET_TX_KEY
,
1050 ext
->key
, ext
->key_len
);
1054 /* Structures to export the Wireless Handlers */
1056 static const iw_handler ieee80211_handler
[] =
1058 (iw_handler
) NULL
, /* SIOCSIWCOMMIT */
1059 (iw_handler
) ieee80211_ioctl_giwname
, /* SIOCGIWNAME */
1060 (iw_handler
) NULL
, /* SIOCSIWNWID */
1061 (iw_handler
) NULL
, /* SIOCGIWNWID */
1062 (iw_handler
) ieee80211_ioctl_siwfreq
, /* SIOCSIWFREQ */
1063 (iw_handler
) ieee80211_ioctl_giwfreq
, /* SIOCGIWFREQ */
1064 (iw_handler
) ieee80211_ioctl_siwmode
, /* SIOCSIWMODE */
1065 (iw_handler
) ieee80211_ioctl_giwmode
, /* SIOCGIWMODE */
1066 (iw_handler
) NULL
, /* SIOCSIWSENS */
1067 (iw_handler
) NULL
, /* SIOCGIWSENS */
1068 (iw_handler
) NULL
/* not used */, /* SIOCSIWRANGE */
1069 (iw_handler
) ieee80211_ioctl_giwrange
, /* SIOCGIWRANGE */
1070 (iw_handler
) NULL
/* not used */, /* SIOCSIWPRIV */
1071 (iw_handler
) NULL
/* kernel code */, /* SIOCGIWPRIV */
1072 (iw_handler
) NULL
/* not used */, /* SIOCSIWSTATS */
1073 (iw_handler
) NULL
/* kernel code */, /* SIOCGIWSTATS */
1074 (iw_handler
) NULL
, /* SIOCSIWSPY */
1075 (iw_handler
) NULL
, /* SIOCGIWSPY */
1076 (iw_handler
) NULL
, /* SIOCSIWTHRSPY */
1077 (iw_handler
) NULL
, /* SIOCGIWTHRSPY */
1078 (iw_handler
) ieee80211_ioctl_siwap
, /* SIOCSIWAP */
1079 (iw_handler
) ieee80211_ioctl_giwap
, /* SIOCGIWAP */
1080 (iw_handler
) ieee80211_ioctl_siwmlme
, /* SIOCSIWMLME */
1081 (iw_handler
) NULL
, /* SIOCGIWAPLIST */
1082 (iw_handler
) ieee80211_ioctl_siwscan
, /* SIOCSIWSCAN */
1083 (iw_handler
) ieee80211_ioctl_giwscan
, /* SIOCGIWSCAN */
1084 (iw_handler
) ieee80211_ioctl_siwessid
, /* SIOCSIWESSID */
1085 (iw_handler
) ieee80211_ioctl_giwessid
, /* SIOCGIWESSID */
1086 (iw_handler
) NULL
, /* SIOCSIWNICKN */
1087 (iw_handler
) NULL
, /* SIOCGIWNICKN */
1088 (iw_handler
) NULL
, /* -- hole -- */
1089 (iw_handler
) NULL
, /* -- hole -- */
1090 (iw_handler
) ieee80211_ioctl_siwrate
, /* SIOCSIWRATE */
1091 (iw_handler
) ieee80211_ioctl_giwrate
, /* SIOCGIWRATE */
1092 (iw_handler
) ieee80211_ioctl_siwrts
, /* SIOCSIWRTS */
1093 (iw_handler
) ieee80211_ioctl_giwrts
, /* SIOCGIWRTS */
1094 (iw_handler
) ieee80211_ioctl_siwfrag
, /* SIOCSIWFRAG */
1095 (iw_handler
) ieee80211_ioctl_giwfrag
, /* SIOCGIWFRAG */
1096 (iw_handler
) ieee80211_ioctl_siwtxpower
, /* SIOCSIWTXPOW */
1097 (iw_handler
) ieee80211_ioctl_giwtxpower
, /* SIOCGIWTXPOW */
1098 (iw_handler
) ieee80211_ioctl_siwretry
, /* SIOCSIWRETRY */
1099 (iw_handler
) ieee80211_ioctl_giwretry
, /* SIOCGIWRETRY */
1100 (iw_handler
) ieee80211_ioctl_siwencode
, /* SIOCSIWENCODE */
1101 (iw_handler
) ieee80211_ioctl_giwencode
, /* SIOCGIWENCODE */
1102 (iw_handler
) NULL
, /* SIOCSIWPOWER */
1103 (iw_handler
) NULL
, /* SIOCGIWPOWER */
1104 (iw_handler
) NULL
, /* -- hole -- */
1105 (iw_handler
) NULL
, /* -- hole -- */
1106 (iw_handler
) ieee80211_ioctl_siwgenie
, /* SIOCSIWGENIE */
1107 (iw_handler
) NULL
, /* SIOCGIWGENIE */
1108 (iw_handler
) ieee80211_ioctl_siwauth
, /* SIOCSIWAUTH */
1109 (iw_handler
) ieee80211_ioctl_giwauth
, /* SIOCGIWAUTH */
1110 (iw_handler
) ieee80211_ioctl_siwencodeext
, /* SIOCSIWENCODEEXT */
1111 (iw_handler
) NULL
, /* SIOCGIWENCODEEXT */
1112 (iw_handler
) NULL
, /* SIOCSIWPMKSA */
1113 (iw_handler
) NULL
, /* -- hole -- */
1116 const struct iw_handler_def ieee80211_iw_handler_def
=
1118 .num_standard
= ARRAY_SIZE(ieee80211_handler
),
1119 .standard
= (iw_handler
*) ieee80211_handler
,
1120 .get_wireless_stats
= ieee80211_get_wireless_stats
,