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 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
;
41 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
43 if (idx
< 0 || idx
>= NUM_DEFAULT_KEYS
) {
44 printk(KERN_DEBUG
"%s: set_encrypt - invalid idx=%d\n",
54 if (is_broadcast_ether_addr(sta_addr
)) {
55 key
= sdata
->keys
[idx
];
57 sta
= sta_info_get(local
, sta_addr
);
65 ieee80211_key_free(key
);
67 key
= ieee80211_key_alloc(alg
, idx
, key_len
, _key
);
76 if (!is_broadcast_ether_addr(sta_addr
)) {
79 * According to the standard, the key index of a
80 * pairwise key must be zero. However, some AP are
81 * broken when it comes to WEP key indices, so we
84 if (idx
!= 0 && alg
!= ALG_WEP
) {
85 ieee80211_key_free(key
);
90 sta
= sta_info_get(local
, sta_addr
);
92 ieee80211_key_free(key
);
99 key_len
!= LEN_WEP40
&& key_len
!= LEN_WEP104
) {
100 ieee80211_key_free(key
);
105 ieee80211_key_link(key
, sdata
, sta
);
107 if (set_tx_key
|| (!sta
&& !sdata
->default_key
&& key
))
108 ieee80211_set_default_key(sdata
, idx
);
117 static int ieee80211_ioctl_siwgenie(struct net_device
*dev
,
118 struct iw_request_info
*info
,
119 struct iw_point
*data
, char *extra
)
121 struct ieee80211_sub_if_data
*sdata
;
123 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
125 if (sdata
->flags
& IEEE80211_SDATA_USERSPACE_MLME
)
128 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
129 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
130 int ret
= ieee80211_sta_set_extra_ie(dev
, extra
, data
->length
);
133 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_AUTO_BSSID_SEL
;
134 ieee80211_sta_req_auth(dev
, &sdata
->u
.sta
);
141 static int ieee80211_ioctl_giwname(struct net_device
*dev
,
142 struct iw_request_info
*info
,
143 char *name
, char *extra
)
145 strcpy(name
, "IEEE 802.11");
151 static int ieee80211_ioctl_giwrange(struct net_device
*dev
,
152 struct iw_request_info
*info
,
153 struct iw_point
*data
, char *extra
)
155 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
156 struct iw_range
*range
= (struct iw_range
*) extra
;
157 enum ieee80211_band band
;
160 data
->length
= sizeof(struct iw_range
);
161 memset(range
, 0, sizeof(struct iw_range
));
163 range
->we_version_compiled
= WIRELESS_EXT
;
164 range
->we_version_source
= 21;
165 range
->retry_capa
= IW_RETRY_LIMIT
;
166 range
->retry_flags
= IW_RETRY_LIMIT
;
167 range
->min_retry
= 0;
168 range
->max_retry
= 255;
170 range
->max_rts
= 2347;
171 range
->min_frag
= 256;
172 range
->max_frag
= 2346;
174 range
->encoding_size
[0] = 5;
175 range
->encoding_size
[1] = 13;
176 range
->num_encoding_sizes
= 2;
177 range
->max_encoding_tokens
= NUM_DEFAULT_KEYS
;
179 range
->max_qual
.qual
= local
->hw
.max_signal
;
180 range
->max_qual
.level
= local
->hw
.max_rssi
;
181 range
->max_qual
.noise
= local
->hw
.max_noise
;
182 range
->max_qual
.updated
= local
->wstats_flags
;
184 range
->avg_qual
.qual
= local
->hw
.max_signal
/2;
185 range
->avg_qual
.level
= 0;
186 range
->avg_qual
.noise
= 0;
187 range
->avg_qual
.updated
= local
->wstats_flags
;
189 range
->enc_capa
= IW_ENC_CAPA_WPA
| IW_ENC_CAPA_WPA2
|
190 IW_ENC_CAPA_CIPHER_TKIP
| IW_ENC_CAPA_CIPHER_CCMP
;
193 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
195 struct ieee80211_supported_band
*sband
;
197 sband
= local
->hw
.wiphy
->bands
[band
];
202 for (i
= 0; i
< sband
->n_channels
&& c
< IW_MAX_FREQUENCIES
; i
++) {
203 struct ieee80211_channel
*chan
= &sband
->channels
[i
];
205 if (!(chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
207 ieee80211_frequency_to_channel(
209 range
->freq
[c
].m
= chan
->center_freq
;
210 range
->freq
[c
].e
= 6;
215 range
->num_channels
= c
;
216 range
->num_frequency
= c
;
218 IW_EVENT_CAPA_SET_KERNEL(range
->event_capa
);
219 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWAP
);
220 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWSCAN
);
222 range
->scan_capa
|= IW_SCAN_CAPA_ESSID
;
228 static int ieee80211_ioctl_siwmode(struct net_device
*dev
,
229 struct iw_request_info
*info
,
230 __u32
*mode
, char *extra
)
232 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
235 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_VLAN
)
240 type
= IEEE80211_IF_TYPE_STA
;
243 type
= IEEE80211_IF_TYPE_IBSS
;
246 type
= IEEE80211_IF_TYPE_WDS
;
248 case IW_MODE_MONITOR
:
249 type
= IEEE80211_IF_TYPE_MNTR
;
255 if (type
== sdata
->vif
.type
)
257 if (netif_running(dev
))
260 ieee80211_if_reinit(dev
);
261 ieee80211_if_set_type(dev
, type
);
267 static int ieee80211_ioctl_giwmode(struct net_device
*dev
,
268 struct iw_request_info
*info
,
269 __u32
*mode
, char *extra
)
271 struct ieee80211_sub_if_data
*sdata
;
273 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
274 switch (sdata
->vif
.type
) {
275 case IEEE80211_IF_TYPE_AP
:
276 *mode
= IW_MODE_MASTER
;
278 case IEEE80211_IF_TYPE_STA
:
279 *mode
= IW_MODE_INFRA
;
281 case IEEE80211_IF_TYPE_IBSS
:
282 *mode
= IW_MODE_ADHOC
;
284 case IEEE80211_IF_TYPE_MNTR
:
285 *mode
= IW_MODE_MONITOR
;
287 case IEEE80211_IF_TYPE_WDS
:
288 *mode
= IW_MODE_REPEAT
;
290 case IEEE80211_IF_TYPE_VLAN
:
291 *mode
= IW_MODE_SECOND
; /* FIXME */
294 *mode
= IW_MODE_AUTO
;
300 int ieee80211_set_freq(struct net_device
*dev
, int freqMHz
)
303 struct ieee80211_channel
*chan
;
304 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
305 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
307 chan
= ieee80211_get_channel(local
->hw
.wiphy
, freqMHz
);
309 if (chan
&& !(chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
310 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
&&
311 chan
->flags
& IEEE80211_CHAN_NO_IBSS
) {
312 printk(KERN_DEBUG
"%s: IBSS not allowed on frequency "
313 "%d MHz\n", dev
->name
, chan
->center_freq
);
316 local
->oper_channel
= chan
;
318 if (local
->sta_sw_scanning
|| local
->sta_hw_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_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
335 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
)
336 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_AUTO_CHANNEL_SEL
;
338 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
341 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
)
342 sdata
->u
.sta
.flags
|=
343 IEEE80211_STA_AUTO_CHANNEL_SEL
;
346 return ieee80211_set_freq(dev
,
347 ieee80211_channel_to_frequency(freq
->m
));
349 int i
, div
= 1000000;
350 for (i
= 0; i
< freq
->e
; i
++)
353 return ieee80211_set_freq(dev
, 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 freq
->m
= local
->hw
.conf
.channel
->center_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
->vif
.type
== IEEE80211_IF_TYPE_STA
||
386 sdata
->vif
.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
->vif
.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
->vif
.type
== IEEE80211_IF_TYPE_STA
||
426 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
427 int res
= ieee80211_sta_get_ssid(dev
, ssid
, &len
);
436 if (sdata
->vif
.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
->vif
.type
== IEEE80211_IF_TYPE_STA
||
457 sdata
->vif
.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
->vif
.type
== IEEE80211_IF_TYPE_WDS
) {
478 * If it is necessary to update the WDS peer address
479 * while the interface is running, then we need to do
480 * more work here, namely if it is running we need to
481 * add a new and remove the old STA entry, this is
482 * normally handled by _open() and _stop().
484 if (netif_running(dev
))
487 memcpy(&sdata
->u
.wds
.remote_addr
, (u8
*) &ap_addr
->sa_data
,
497 static int ieee80211_ioctl_giwap(struct net_device
*dev
,
498 struct iw_request_info
*info
,
499 struct sockaddr
*ap_addr
, char *extra
)
501 struct ieee80211_sub_if_data
*sdata
;
503 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
504 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
505 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
) {
506 if (sdata
->u
.sta
.state
== IEEE80211_ASSOCIATED
||
507 sdata
->u
.sta
.state
== IEEE80211_IBSS_JOINED
) {
508 ap_addr
->sa_family
= ARPHRD_ETHER
;
509 memcpy(&ap_addr
->sa_data
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
512 memset(&ap_addr
->sa_data
, 0, ETH_ALEN
);
515 } else if (sdata
->vif
.type
== IEEE80211_IF_TYPE_WDS
) {
516 ap_addr
->sa_family
= ARPHRD_ETHER
;
517 memcpy(&ap_addr
->sa_data
, sdata
->u
.wds
.remote_addr
, ETH_ALEN
);
525 static int ieee80211_ioctl_siwscan(struct net_device
*dev
,
526 struct iw_request_info
*info
,
527 union iwreq_data
*wrqu
, char *extra
)
529 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
530 struct iw_scan_req
*req
= NULL
;
534 if (!netif_running(dev
))
537 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
&&
538 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
&&
539 sdata
->vif
.type
!= IEEE80211_IF_TYPE_MESH_POINT
&&
540 sdata
->vif
.type
!= IEEE80211_IF_TYPE_AP
)
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
);
562 if (local
->sta_sw_scanning
|| local
->sta_hw_scanning
)
565 res
= ieee80211_sta_scan_results(dev
, extra
, data
->length
);
575 static int ieee80211_ioctl_siwrate(struct net_device
*dev
,
576 struct iw_request_info
*info
,
577 struct iw_param
*rate
, char *extra
)
579 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
580 int i
, err
= -EINVAL
;
581 u32 target_rate
= rate
->value
/ 100000;
582 struct ieee80211_sub_if_data
*sdata
;
583 struct ieee80211_supported_band
*sband
;
585 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
589 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
591 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
592 * target_rate = X, rate->fixed = 1 means only rate X
593 * target_rate = X, rate->fixed = 0 means all rates <= X */
594 sdata
->bss
->max_ratectrl_rateidx
= -1;
595 sdata
->bss
->force_unicast_rateidx
= -1;
599 for (i
=0; i
< sband
->n_bitrates
; i
++) {
600 struct ieee80211_rate
*brate
= &sband
->bitrates
[i
];
601 int this_rate
= brate
->bitrate
;
603 if (target_rate
== this_rate
) {
604 sdata
->bss
->max_ratectrl_rateidx
= i
;
606 sdata
->bss
->force_unicast_rateidx
= i
;
614 static int ieee80211_ioctl_giwrate(struct net_device
*dev
,
615 struct iw_request_info
*info
,
616 struct iw_param
*rate
, char *extra
)
618 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
619 struct sta_info
*sta
;
620 struct ieee80211_sub_if_data
*sdata
;
621 struct ieee80211_supported_band
*sband
;
623 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
625 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
628 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
632 sta
= sta_info_get(local
, sdata
->u
.sta
.bssid
);
634 if (sta
&& sta
->txrate_idx
< sband
->n_bitrates
)
635 rate
->value
= sband
->bitrates
[sta
->txrate_idx
].bitrate
;
644 rate
->value
*= 100000;
649 static int ieee80211_ioctl_siwtxpower(struct net_device
*dev
,
650 struct iw_request_info
*info
,
651 union iwreq_data
*data
, char *extra
)
653 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
654 bool need_reconfig
= 0;
657 if ((data
->txpower
.flags
& IW_TXPOW_TYPE
) != IW_TXPOW_DBM
)
659 if (data
->txpower
.flags
& IW_TXPOW_RANGE
)
662 if (data
->txpower
.fixed
) {
663 new_power_level
= data
->txpower
.value
;
666 * Automatic power level. Use maximum power for the current
667 * channel. Should be part of rate control.
669 struct ieee80211_channel
* chan
= local
->hw
.conf
.channel
;
673 new_power_level
= chan
->max_power
;
676 if (local
->hw
.conf
.power_level
!= new_power_level
) {
677 local
->hw
.conf
.power_level
= new_power_level
;
681 if (local
->hw
.conf
.radio_enabled
!= !(data
->txpower
.disabled
)) {
682 local
->hw
.conf
.radio_enabled
= !(data
->txpower
.disabled
);
684 ieee80211_led_radio(local
, local
->hw
.conf
.radio_enabled
);
688 ieee80211_hw_config(local
);
689 /* The return value of hw_config is not of big interest here,
690 * as it doesn't say that it failed because of _this_ config
691 * change or something else. Ignore it. */
697 static int ieee80211_ioctl_giwtxpower(struct net_device
*dev
,
698 struct iw_request_info
*info
,
699 union iwreq_data
*data
, char *extra
)
701 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
703 data
->txpower
.fixed
= 1;
704 data
->txpower
.disabled
= !(local
->hw
.conf
.radio_enabled
);
705 data
->txpower
.value
= local
->hw
.conf
.power_level
;
706 data
->txpower
.flags
= IW_TXPOW_DBM
;
711 static int ieee80211_ioctl_siwrts(struct net_device
*dev
,
712 struct iw_request_info
*info
,
713 struct iw_param
*rts
, char *extra
)
715 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
718 local
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
719 else if (rts
->value
< 0 || rts
->value
> IEEE80211_MAX_RTS_THRESHOLD
)
722 local
->rts_threshold
= rts
->value
;
724 /* If the wlan card performs RTS/CTS in hardware/firmware,
725 * configure it here */
727 if (local
->ops
->set_rts_threshold
)
728 local
->ops
->set_rts_threshold(local_to_hw(local
),
729 local
->rts_threshold
);
734 static int ieee80211_ioctl_giwrts(struct net_device
*dev
,
735 struct iw_request_info
*info
,
736 struct iw_param
*rts
, char *extra
)
738 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
740 rts
->value
= local
->rts_threshold
;
741 rts
->disabled
= (rts
->value
>= IEEE80211_MAX_RTS_THRESHOLD
);
748 static int ieee80211_ioctl_siwfrag(struct net_device
*dev
,
749 struct iw_request_info
*info
,
750 struct iw_param
*frag
, char *extra
)
752 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
755 local
->fragmentation_threshold
= IEEE80211_MAX_FRAG_THRESHOLD
;
756 else if (frag
->value
< 256 ||
757 frag
->value
> IEEE80211_MAX_FRAG_THRESHOLD
)
760 /* Fragment length must be even, so strip LSB. */
761 local
->fragmentation_threshold
= frag
->value
& ~0x1;
764 /* If the wlan card performs fragmentation in hardware/firmware,
765 * configure it here */
767 if (local
->ops
->set_frag_threshold
)
768 local
->ops
->set_frag_threshold(
770 local
->fragmentation_threshold
);
775 static int ieee80211_ioctl_giwfrag(struct net_device
*dev
,
776 struct iw_request_info
*info
,
777 struct iw_param
*frag
, char *extra
)
779 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
781 frag
->value
= local
->fragmentation_threshold
;
782 frag
->disabled
= (frag
->value
>= IEEE80211_MAX_RTS_THRESHOLD
);
789 static int ieee80211_ioctl_siwretry(struct net_device
*dev
,
790 struct iw_request_info
*info
,
791 struct iw_param
*retry
, char *extra
)
793 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
795 if (retry
->disabled
||
796 (retry
->flags
& IW_RETRY_TYPE
) != IW_RETRY_LIMIT
)
799 if (retry
->flags
& IW_RETRY_MAX
)
800 local
->long_retry_limit
= retry
->value
;
801 else if (retry
->flags
& IW_RETRY_MIN
)
802 local
->short_retry_limit
= retry
->value
;
804 local
->long_retry_limit
= retry
->value
;
805 local
->short_retry_limit
= retry
->value
;
808 if (local
->ops
->set_retry_limit
) {
809 return local
->ops
->set_retry_limit(
811 local
->short_retry_limit
,
812 local
->long_retry_limit
);
819 static int ieee80211_ioctl_giwretry(struct net_device
*dev
,
820 struct iw_request_info
*info
,
821 struct iw_param
*retry
, char *extra
)
823 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
826 if (retry
->flags
== 0 || retry
->flags
& IW_RETRY_MIN
) {
827 /* first return min value, iwconfig will ask max value
829 retry
->flags
|= IW_RETRY_LIMIT
;
830 retry
->value
= local
->short_retry_limit
;
831 if (local
->long_retry_limit
!= local
->short_retry_limit
)
832 retry
->flags
|= IW_RETRY_MIN
;
835 if (retry
->flags
& IW_RETRY_MAX
) {
836 retry
->flags
= IW_RETRY_LIMIT
| IW_RETRY_MAX
;
837 retry
->value
= local
->long_retry_limit
;
843 static int ieee80211_ioctl_siwmlme(struct net_device
*dev
,
844 struct iw_request_info
*info
,
845 struct iw_point
*data
, char *extra
)
847 struct ieee80211_sub_if_data
*sdata
;
848 struct iw_mlme
*mlme
= (struct iw_mlme
*) extra
;
850 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
851 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
&&
852 sdata
->vif
.type
!= IEEE80211_IF_TYPE_IBSS
)
857 /* TODO: mlme->addr.sa_data */
858 return ieee80211_sta_deauthenticate(dev
, mlme
->reason_code
);
859 case IW_MLME_DISASSOC
:
860 /* TODO: mlme->addr.sa_data */
861 return ieee80211_sta_disassociate(dev
, mlme
->reason_code
);
868 static int ieee80211_ioctl_siwencode(struct net_device
*dev
,
869 struct iw_request_info
*info
,
870 struct iw_point
*erq
, char *keybuf
)
872 struct ieee80211_sub_if_data
*sdata
;
873 int idx
, i
, alg
= ALG_WEP
;
874 u8 bcaddr
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
877 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
879 idx
= erq
->flags
& IW_ENCODE_INDEX
;
881 if (sdata
->default_key
)
882 for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
883 if (sdata
->default_key
== sdata
->keys
[i
]) {
888 } else if (idx
< 1 || idx
> 4)
893 if (erq
->flags
& IW_ENCODE_DISABLED
)
895 else if (erq
->length
== 0) {
896 /* No key data - just set the default TX key index */
897 ieee80211_set_default_key(sdata
, idx
);
901 return ieee80211_set_encryption(
905 keybuf
, erq
->length
);
909 static int ieee80211_ioctl_giwencode(struct net_device
*dev
,
910 struct iw_request_info
*info
,
911 struct iw_point
*erq
, char *key
)
913 struct ieee80211_sub_if_data
*sdata
;
916 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
918 idx
= erq
->flags
& IW_ENCODE_INDEX
;
919 if (idx
< 1 || idx
> 4) {
921 if (!sdata
->default_key
)
923 else for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
924 if (sdata
->default_key
== sdata
->keys
[i
]) {
934 erq
->flags
= idx
+ 1;
936 if (!sdata
->keys
[idx
]) {
938 erq
->flags
|= IW_ENCODE_DISABLED
;
942 memcpy(key
, sdata
->keys
[idx
]->conf
.key
,
943 min_t(int, erq
->length
, sdata
->keys
[idx
]->conf
.keylen
));
944 erq
->length
= sdata
->keys
[idx
]->conf
.keylen
;
945 erq
->flags
|= IW_ENCODE_ENABLED
;
950 static int ieee80211_ioctl_siwauth(struct net_device
*dev
,
951 struct iw_request_info
*info
,
952 struct iw_param
*data
, char *extra
)
954 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
957 switch (data
->flags
& IW_AUTH_INDEX
) {
958 case IW_AUTH_WPA_VERSION
:
959 case IW_AUTH_CIPHER_PAIRWISE
:
960 case IW_AUTH_CIPHER_GROUP
:
961 case IW_AUTH_WPA_ENABLED
:
962 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
963 case IW_AUTH_KEY_MGMT
:
965 case IW_AUTH_DROP_UNENCRYPTED
:
966 sdata
->drop_unencrypted
= !!data
->value
;
968 case IW_AUTH_PRIVACY_INVOKED
:
969 if (sdata
->vif
.type
!= IEEE80211_IF_TYPE_STA
)
972 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_PRIVACY_INVOKED
;
974 * Privacy invoked by wpa_supplicant, store the
975 * value and allow associating to a protected
976 * network without having a key up front.
979 sdata
->u
.sta
.flags
|=
980 IEEE80211_STA_PRIVACY_INVOKED
;
983 case IW_AUTH_80211_AUTH_ALG
:
984 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
985 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
)
986 sdata
->u
.sta
.auth_algs
= data
->value
;
997 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
998 static struct iw_statistics
*ieee80211_get_wireless_stats(struct net_device
*dev
)
1000 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1001 struct iw_statistics
*wstats
= &local
->wstats
;
1002 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1003 struct sta_info
*sta
= NULL
;
1007 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
1008 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
)
1009 sta
= sta_info_get(local
, sdata
->u
.sta
.bssid
);
1011 wstats
->discard
.fragment
= 0;
1012 wstats
->discard
.misc
= 0;
1013 wstats
->qual
.qual
= 0;
1014 wstats
->qual
.level
= 0;
1015 wstats
->qual
.noise
= 0;
1016 wstats
->qual
.updated
= IW_QUAL_ALL_INVALID
;
1018 wstats
->qual
.level
= sta
->last_rssi
;
1019 wstats
->qual
.qual
= sta
->last_signal
;
1020 wstats
->qual
.noise
= sta
->last_noise
;
1021 wstats
->qual
.updated
= local
->wstats_flags
;
1029 static int ieee80211_ioctl_giwauth(struct net_device
*dev
,
1030 struct iw_request_info
*info
,
1031 struct iw_param
*data
, char *extra
)
1033 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1036 switch (data
->flags
& IW_AUTH_INDEX
) {
1037 case IW_AUTH_80211_AUTH_ALG
:
1038 if (sdata
->vif
.type
== IEEE80211_IF_TYPE_STA
||
1039 sdata
->vif
.type
== IEEE80211_IF_TYPE_IBSS
)
1040 data
->value
= sdata
->u
.sta
.auth_algs
;
1052 static int ieee80211_ioctl_siwencodeext(struct net_device
*dev
,
1053 struct iw_request_info
*info
,
1054 struct iw_point
*erq
, char *extra
)
1056 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1057 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*) extra
;
1058 int uninitialized_var(alg
), idx
, i
, remove
= 0;
1061 case IW_ENCODE_ALG_NONE
:
1064 case IW_ENCODE_ALG_WEP
:
1067 case IW_ENCODE_ALG_TKIP
:
1070 case IW_ENCODE_ALG_CCMP
:
1077 if (erq
->flags
& IW_ENCODE_DISABLED
)
1080 idx
= erq
->flags
& IW_ENCODE_INDEX
;
1081 if (idx
< 1 || idx
> 4) {
1083 if (!sdata
->default_key
)
1085 else for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
1086 if (sdata
->default_key
== sdata
->keys
[i
]) {
1096 return ieee80211_set_encryption(dev
, ext
->addr
.sa_data
, idx
, alg
,
1099 IW_ENCODE_EXT_SET_TX_KEY
,
1100 ext
->key
, ext
->key_len
);
1104 /* Structures to export the Wireless Handlers */
1106 static const iw_handler ieee80211_handler
[] =
1108 (iw_handler
) NULL
, /* SIOCSIWCOMMIT */
1109 (iw_handler
) ieee80211_ioctl_giwname
, /* SIOCGIWNAME */
1110 (iw_handler
) NULL
, /* SIOCSIWNWID */
1111 (iw_handler
) NULL
, /* SIOCGIWNWID */
1112 (iw_handler
) ieee80211_ioctl_siwfreq
, /* SIOCSIWFREQ */
1113 (iw_handler
) ieee80211_ioctl_giwfreq
, /* SIOCGIWFREQ */
1114 (iw_handler
) ieee80211_ioctl_siwmode
, /* SIOCSIWMODE */
1115 (iw_handler
) ieee80211_ioctl_giwmode
, /* SIOCGIWMODE */
1116 (iw_handler
) NULL
, /* SIOCSIWSENS */
1117 (iw_handler
) NULL
, /* SIOCGIWSENS */
1118 (iw_handler
) NULL
/* not used */, /* SIOCSIWRANGE */
1119 (iw_handler
) ieee80211_ioctl_giwrange
, /* SIOCGIWRANGE */
1120 (iw_handler
) NULL
/* not used */, /* SIOCSIWPRIV */
1121 (iw_handler
) NULL
/* kernel code */, /* SIOCGIWPRIV */
1122 (iw_handler
) NULL
/* not used */, /* SIOCSIWSTATS */
1123 (iw_handler
) NULL
/* kernel code */, /* SIOCGIWSTATS */
1124 (iw_handler
) NULL
, /* SIOCSIWSPY */
1125 (iw_handler
) NULL
, /* SIOCGIWSPY */
1126 (iw_handler
) NULL
, /* SIOCSIWTHRSPY */
1127 (iw_handler
) NULL
, /* SIOCGIWTHRSPY */
1128 (iw_handler
) ieee80211_ioctl_siwap
, /* SIOCSIWAP */
1129 (iw_handler
) ieee80211_ioctl_giwap
, /* SIOCGIWAP */
1130 (iw_handler
) ieee80211_ioctl_siwmlme
, /* SIOCSIWMLME */
1131 (iw_handler
) NULL
, /* SIOCGIWAPLIST */
1132 (iw_handler
) ieee80211_ioctl_siwscan
, /* SIOCSIWSCAN */
1133 (iw_handler
) ieee80211_ioctl_giwscan
, /* SIOCGIWSCAN */
1134 (iw_handler
) ieee80211_ioctl_siwessid
, /* SIOCSIWESSID */
1135 (iw_handler
) ieee80211_ioctl_giwessid
, /* SIOCGIWESSID */
1136 (iw_handler
) NULL
, /* SIOCSIWNICKN */
1137 (iw_handler
) NULL
, /* SIOCGIWNICKN */
1138 (iw_handler
) NULL
, /* -- hole -- */
1139 (iw_handler
) NULL
, /* -- hole -- */
1140 (iw_handler
) ieee80211_ioctl_siwrate
, /* SIOCSIWRATE */
1141 (iw_handler
) ieee80211_ioctl_giwrate
, /* SIOCGIWRATE */
1142 (iw_handler
) ieee80211_ioctl_siwrts
, /* SIOCSIWRTS */
1143 (iw_handler
) ieee80211_ioctl_giwrts
, /* SIOCGIWRTS */
1144 (iw_handler
) ieee80211_ioctl_siwfrag
, /* SIOCSIWFRAG */
1145 (iw_handler
) ieee80211_ioctl_giwfrag
, /* SIOCGIWFRAG */
1146 (iw_handler
) ieee80211_ioctl_siwtxpower
, /* SIOCSIWTXPOW */
1147 (iw_handler
) ieee80211_ioctl_giwtxpower
, /* SIOCGIWTXPOW */
1148 (iw_handler
) ieee80211_ioctl_siwretry
, /* SIOCSIWRETRY */
1149 (iw_handler
) ieee80211_ioctl_giwretry
, /* SIOCGIWRETRY */
1150 (iw_handler
) ieee80211_ioctl_siwencode
, /* SIOCSIWENCODE */
1151 (iw_handler
) ieee80211_ioctl_giwencode
, /* SIOCGIWENCODE */
1152 (iw_handler
) NULL
, /* SIOCSIWPOWER */
1153 (iw_handler
) NULL
, /* SIOCGIWPOWER */
1154 (iw_handler
) NULL
, /* -- hole -- */
1155 (iw_handler
) NULL
, /* -- hole -- */
1156 (iw_handler
) ieee80211_ioctl_siwgenie
, /* SIOCSIWGENIE */
1157 (iw_handler
) NULL
, /* SIOCGIWGENIE */
1158 (iw_handler
) ieee80211_ioctl_siwauth
, /* SIOCSIWAUTH */
1159 (iw_handler
) ieee80211_ioctl_giwauth
, /* SIOCGIWAUTH */
1160 (iw_handler
) ieee80211_ioctl_siwencodeext
, /* SIOCSIWENCODEEXT */
1161 (iw_handler
) NULL
, /* SIOCGIWENCODEEXT */
1162 (iw_handler
) NULL
, /* SIOCSIWPMKSA */
1163 (iw_handler
) NULL
, /* -- hole -- */
1166 const struct iw_handler_def ieee80211_iw_handler_def
=
1168 .num_standard
= ARRAY_SIZE(ieee80211_handler
),
1169 .standard
= (iw_handler
*) ieee80211_handler
,
1170 .get_wireless_stats
= ieee80211_get_wireless_stats
,