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 "hostapd_ioctl.h"
25 #include "ieee80211_rate.h"
28 #include "debugfs_key.h"
30 static void ieee80211_set_hw_encryption(struct net_device
*dev
,
31 struct sta_info
*sta
, u8 addr
[ETH_ALEN
],
32 struct ieee80211_key
*key
)
34 struct ieee80211_key_conf
*keyconf
= NULL
;
35 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
37 /* default to sw encryption; this will be cleared by low-level
38 * driver if the hw supports requested encryption */
40 key
->force_sw_encrypt
= 1;
42 if (key
&& local
->ops
->set_key
&&
43 (keyconf
= ieee80211_key_data2conf(local
, key
))) {
44 if (local
->ops
->set_key(local_to_hw(local
), SET_KEY
, addr
,
45 keyconf
, sta
? sta
->aid
: 0)) {
46 key
->force_sw_encrypt
= 1;
47 key
->hw_key_idx
= HW_KEY_IDX_INVALID
;
49 key
->force_sw_encrypt
=
50 !!(keyconf
->flags
& IEEE80211_KEY_FORCE_SW_ENCRYPT
);
60 static int ieee80211_set_encryption(struct net_device
*dev
, u8
*sta_addr
,
61 int idx
, int alg
, int set_tx_key
,
62 const u8
*_key
, size_t key_len
)
64 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
67 struct ieee80211_key
*key
, *old_key
;
69 struct ieee80211_key_conf
*keyconf
;
70 struct ieee80211_sub_if_data
*sdata
;
72 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
74 if (is_broadcast_ether_addr(sta_addr
)) {
76 if (idx
>= NUM_DEFAULT_KEYS
) {
77 printk(KERN_DEBUG
"%s: set_encrypt - invalid idx=%d\n",
81 key
= sdata
->keys
[idx
];
83 /* TODO: consider adding hwaccel support for these; at least
84 * Atheros key cache should be able to handle this since AP is
85 * only transmitting frames with default keys. */
86 /* FIX: hw key cache can be used when only one virtual
87 * STA is associated with each AP. If more than one STA
88 * is associated to the same AP, software encryption
89 * must be used. This should be done automatically
90 * based on configured station devices. For the time
91 * being, this can be only set at compile time. */
95 printk(KERN_DEBUG
"%s: set_encrypt - non-zero idx for "
96 "individual key\n", dev
->name
);
100 sta
= sta_info_get(local
, sta_addr
);
102 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
103 printk(KERN_DEBUG
"%s: set_encrypt - unknown addr "
105 dev
->name
, MAC_ARG(sta_addr
));
106 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
115 * Cannot configure default hwaccel keys with WEP algorithm, if
116 * any of the virtual interfaces is using static WEP
117 * configuration because hwaccel would otherwise try to decrypt
120 * For now, just disable WEP hwaccel for broadcast when there is
121 * possibility of conflict with default keys. This can maybe later be
122 * optimized by using non-default keys (at least with Atheros ar521x).
124 if (!sta
&& alg
== ALG_WEP
&& !local
->default_wep_only
&&
125 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
&&
126 sdata
->type
!= IEEE80211_IF_TYPE_AP
) {
130 if (local
->hw
.flags
& IEEE80211_HW_DEVICE_HIDES_WEP
) {
131 /* Software encryption cannot be used with devices that hide
132 * encryption from the host system, so always try to use
133 * hardware acceleration with such devices. */
137 if ((local
->hw
.flags
& IEEE80211_HW_NO_TKIP_WMM_HWACCEL
) &&
139 if (sta
&& (sta
->flags
& WLAN_STA_WME
)) {
140 /* Hardware does not support hwaccel with TKIP when using WMM.
144 else if (sdata
->type
== IEEE80211_IF_TYPE_STA
) {
145 sta
= sta_info_get(local
, sdata
->u
.sta
.bssid
);
147 if (sta
->flags
& WLAN_STA_WME
) {
156 if (alg
== ALG_NONE
) {
158 if (try_hwaccel
&& key
&&
159 key
->hw_key_idx
!= HW_KEY_IDX_INVALID
&&
160 local
->ops
->set_key
&&
161 (keyconf
= ieee80211_key_data2conf(local
, key
)) != NULL
&&
162 local
->ops
->set_key(local_to_hw(local
), DISABLE_KEY
,
163 sta_addr
, keyconf
, sta
? sta
->aid
: 0)) {
164 printk(KERN_DEBUG
"%s: set_encrypt - low-level disable"
165 " failed\n", dev
->name
);
170 if (set_tx_key
|| sdata
->default_key
== key
) {
171 ieee80211_debugfs_key_remove_default(sdata
);
172 sdata
->default_key
= NULL
;
174 ieee80211_debugfs_key_remove(key
);
178 sdata
->keys
[idx
] = NULL
;
179 ieee80211_key_free(key
);
183 key
= ieee80211_key_alloc(sta
? NULL
: sdata
, idx
, key_len
,
190 /* default to sw encryption; low-level driver sets these if the
191 * requested encryption is supported */
192 key
->hw_key_idx
= HW_KEY_IDX_INVALID
;
193 key
->force_sw_encrypt
= 1;
197 key
->keylen
= key_len
;
198 memcpy(key
->key
, _key
, key_len
);
200 key
->default_tx_key
= 1;
202 if (alg
== ALG_CCMP
) {
203 /* Initialize AES key state here as an optimization
204 * so that it does not need to be initialized for every
206 key
->u
.ccmp
.tfm
= ieee80211_aes_key_setup_encrypt(
208 if (!key
->u
.ccmp
.tfm
) {
214 if (set_tx_key
|| sdata
->default_key
== old_key
) {
215 ieee80211_debugfs_key_remove_default(sdata
);
216 sdata
->default_key
= NULL
;
218 ieee80211_debugfs_key_remove(old_key
);
222 sdata
->keys
[idx
] = key
;
223 ieee80211_key_free(old_key
);
224 ieee80211_debugfs_key_add(local
, key
);
226 ieee80211_debugfs_key_sta_link(key
, sta
);
229 (alg
== ALG_WEP
|| alg
== ALG_TKIP
|| alg
== ALG_CCMP
))
230 ieee80211_set_hw_encryption(dev
, sta
, sta_addr
, key
);
233 if (set_tx_key
|| (!sta
&& !sdata
->default_key
&& key
)) {
234 sdata
->default_key
= key
;
236 ieee80211_debugfs_key_add_default(sdata
);
238 if (local
->ops
->set_key_idx
&&
239 local
->ops
->set_key_idx(local_to_hw(local
), idx
))
240 printk(KERN_DEBUG
"%s: failed to set TX key idx for "
241 "low-level driver\n", dev
->name
);
250 ieee80211_key_free(key
);
257 static int ieee80211_ioctl_siwgenie(struct net_device
*dev
,
258 struct iw_request_info
*info
,
259 struct iw_point
*data
, char *extra
)
261 struct ieee80211_sub_if_data
*sdata
;
262 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
264 if (local
->user_space_mlme
)
267 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
268 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
269 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
270 int ret
= ieee80211_sta_set_extra_ie(dev
, extra
, data
->length
);
273 sdata
->u
.sta
.auto_bssid_sel
= 0;
274 ieee80211_sta_req_auth(dev
, &sdata
->u
.sta
);
278 if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
279 kfree(sdata
->u
.ap
.generic_elem
);
280 sdata
->u
.ap
.generic_elem
= kmalloc(data
->length
, GFP_KERNEL
);
281 if (!sdata
->u
.ap
.generic_elem
)
283 memcpy(sdata
->u
.ap
.generic_elem
, extra
, data
->length
);
284 sdata
->u
.ap
.generic_elem_len
= data
->length
;
285 return ieee80211_if_config(dev
);
290 static int ieee80211_ioctl_set_radio_enabled(struct net_device
*dev
,
293 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
294 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
296 conf
->radio_enabled
= val
;
297 return ieee80211_hw_config(wdev_priv(dev
->ieee80211_ptr
));
300 static int ieee80211_ioctl_giwname(struct net_device
*dev
,
301 struct iw_request_info
*info
,
302 char *name
, char *extra
)
304 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
306 switch (local
->hw
.conf
.phymode
) {
307 case MODE_IEEE80211A
:
308 strcpy(name
, "IEEE 802.11a");
310 case MODE_IEEE80211B
:
311 strcpy(name
, "IEEE 802.11b");
313 case MODE_IEEE80211G
:
314 strcpy(name
, "IEEE 802.11g");
316 case MODE_ATHEROS_TURBO
:
317 strcpy(name
, "5GHz Turbo");
320 strcpy(name
, "IEEE 802.11");
328 static int ieee80211_ioctl_giwrange(struct net_device
*dev
,
329 struct iw_request_info
*info
,
330 struct iw_point
*data
, char *extra
)
332 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
333 struct iw_range
*range
= (struct iw_range
*) extra
;
334 struct ieee80211_hw_mode
*mode
= NULL
;
337 data
->length
= sizeof(struct iw_range
);
338 memset(range
, 0, sizeof(struct iw_range
));
340 range
->we_version_compiled
= WIRELESS_EXT
;
341 range
->we_version_source
= 21;
342 range
->retry_capa
= IW_RETRY_LIMIT
;
343 range
->retry_flags
= IW_RETRY_LIMIT
;
344 range
->min_retry
= 0;
345 range
->max_retry
= 255;
347 range
->max_rts
= 2347;
348 range
->min_frag
= 256;
349 range
->max_frag
= 2346;
351 range
->encoding_size
[0] = 5;
352 range
->encoding_size
[1] = 13;
353 range
->num_encoding_sizes
= 2;
354 range
->max_encoding_tokens
= NUM_DEFAULT_KEYS
;
356 range
->max_qual
.qual
= local
->hw
.max_signal
;
357 range
->max_qual
.level
= local
->hw
.max_rssi
;
358 range
->max_qual
.noise
= local
->hw
.max_noise
;
359 range
->max_qual
.updated
= local
->wstats_flags
;
361 range
->avg_qual
.qual
= local
->hw
.max_signal
/2;
362 range
->avg_qual
.level
= 0;
363 range
->avg_qual
.noise
= 0;
364 range
->avg_qual
.updated
= local
->wstats_flags
;
366 range
->enc_capa
= IW_ENC_CAPA_WPA
| IW_ENC_CAPA_WPA2
|
367 IW_ENC_CAPA_CIPHER_TKIP
| IW_ENC_CAPA_CIPHER_CCMP
;
369 list_for_each_entry(mode
, &local
->modes_list
, list
) {
372 if (!(local
->enabled_modes
& (1 << mode
->mode
)) ||
373 (local
->hw_modes
& local
->enabled_modes
&
374 (1 << MODE_IEEE80211G
) && mode
->mode
== MODE_IEEE80211B
))
377 while (i
< mode
->num_channels
&& c
< IW_MAX_FREQUENCIES
) {
378 struct ieee80211_channel
*chan
= &mode
->channels
[i
];
380 if (chan
->flag
& IEEE80211_CHAN_W_SCAN
) {
381 range
->freq
[c
].i
= chan
->chan
;
382 range
->freq
[c
].m
= chan
->freq
* 100000;
383 range
->freq
[c
].e
= 1;
389 range
->num_channels
= c
;
390 range
->num_frequency
= c
;
392 IW_EVENT_CAPA_SET_KERNEL(range
->event_capa
);
393 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWTHRSPY
);
394 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWAP
);
395 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWSCAN
);
401 static int ieee80211_ioctl_siwmode(struct net_device
*dev
,
402 struct iw_request_info
*info
,
403 __u32
*mode
, char *extra
)
405 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
408 if (sdata
->type
== IEEE80211_IF_TYPE_VLAN
)
413 type
= IEEE80211_IF_TYPE_STA
;
416 type
= IEEE80211_IF_TYPE_IBSS
;
418 case IW_MODE_MONITOR
:
419 type
= IEEE80211_IF_TYPE_MNTR
;
425 if (type
== sdata
->type
)
427 if (netif_running(dev
))
430 ieee80211_if_reinit(dev
);
431 ieee80211_if_set_type(dev
, type
);
437 static int ieee80211_ioctl_giwmode(struct net_device
*dev
,
438 struct iw_request_info
*info
,
439 __u32
*mode
, char *extra
)
441 struct ieee80211_sub_if_data
*sdata
;
443 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
444 switch (sdata
->type
) {
445 case IEEE80211_IF_TYPE_AP
:
446 *mode
= IW_MODE_MASTER
;
448 case IEEE80211_IF_TYPE_STA
:
449 *mode
= IW_MODE_INFRA
;
451 case IEEE80211_IF_TYPE_IBSS
:
452 *mode
= IW_MODE_ADHOC
;
454 case IEEE80211_IF_TYPE_MNTR
:
455 *mode
= IW_MODE_MONITOR
;
457 case IEEE80211_IF_TYPE_WDS
:
458 *mode
= IW_MODE_REPEAT
;
460 case IEEE80211_IF_TYPE_VLAN
:
461 *mode
= IW_MODE_SECOND
; /* FIXME */
464 *mode
= IW_MODE_AUTO
;
470 int ieee80211_set_channel(struct ieee80211_local
*local
, int channel
, int freq
)
472 struct ieee80211_hw_mode
*mode
;
476 list_for_each_entry(mode
, &local
->modes_list
, list
) {
477 if (!(local
->enabled_modes
& (1 << mode
->mode
)))
479 for (c
= 0; c
< mode
->num_channels
; c
++) {
480 struct ieee80211_channel
*chan
= &mode
->channels
[c
];
481 if (chan
->flag
& IEEE80211_CHAN_W_SCAN
&&
482 ((chan
->chan
== channel
) || (chan
->freq
== freq
))) {
483 /* Use next_mode as the mode preference to
484 * resolve non-unique channel numbers. */
485 if (set
&& mode
->mode
!= local
->next_mode
)
488 local
->oper_channel
= chan
;
489 local
->oper_hw_mode
= mode
;
496 if (local
->sta_scanning
)
499 ret
= ieee80211_hw_config(local
);
501 rate_control_clear(local
);
507 static int ieee80211_ioctl_siwfreq(struct net_device
*dev
,
508 struct iw_request_info
*info
,
509 struct iw_freq
*freq
, char *extra
)
511 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
512 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
514 if (sdata
->type
== IEEE80211_IF_TYPE_STA
)
515 sdata
->u
.sta
.auto_channel_sel
= 0;
517 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
520 if (sdata
->type
== IEEE80211_IF_TYPE_STA
)
521 sdata
->u
.sta
.auto_channel_sel
= 1;
524 return ieee80211_set_channel(local
, freq
->m
, -1);
526 int i
, div
= 1000000;
527 for (i
= 0; i
< freq
->e
; i
++)
530 return ieee80211_set_channel(local
, -1, freq
->m
/ div
);
537 static int ieee80211_ioctl_giwfreq(struct net_device
*dev
,
538 struct iw_request_info
*info
,
539 struct iw_freq
*freq
, char *extra
)
541 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
543 /* TODO: in station mode (Managed/Ad-hoc) might need to poll low-level
544 * driver for the current channel with firmware-based management */
546 freq
->m
= local
->hw
.conf
.freq
;
553 static int ieee80211_ioctl_siwessid(struct net_device
*dev
,
554 struct iw_request_info
*info
,
555 struct iw_point
*data
, char *ssid
)
557 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
558 struct ieee80211_sub_if_data
*sdata
;
559 size_t len
= data
->length
;
561 /* iwconfig uses nul termination in SSID.. */
562 if (len
> 0 && ssid
[len
- 1] == '\0')
565 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
566 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
567 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
569 if (local
->user_space_mlme
) {
570 if (len
> IEEE80211_MAX_SSID_LEN
)
572 memcpy(sdata
->u
.sta
.ssid
, ssid
, len
);
573 sdata
->u
.sta
.ssid_len
= len
;
576 sdata
->u
.sta
.auto_ssid_sel
= !data
->flags
;
577 ret
= ieee80211_sta_set_ssid(dev
, ssid
, len
);
580 ieee80211_sta_req_auth(dev
, &sdata
->u
.sta
);
584 if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
585 memcpy(sdata
->u
.ap
.ssid
, ssid
, len
);
586 memset(sdata
->u
.ap
.ssid
+ len
, 0,
587 IEEE80211_MAX_SSID_LEN
- len
);
588 sdata
->u
.ap
.ssid_len
= len
;
589 return ieee80211_if_config(dev
);
595 static int ieee80211_ioctl_giwessid(struct net_device
*dev
,
596 struct iw_request_info
*info
,
597 struct iw_point
*data
, char *ssid
)
601 struct ieee80211_sub_if_data
*sdata
;
602 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
603 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
604 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
605 int res
= ieee80211_sta_get_ssid(dev
, ssid
, &len
);
614 if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
615 len
= sdata
->u
.ap
.ssid_len
;
616 if (len
> IW_ESSID_MAX_SIZE
)
617 len
= IW_ESSID_MAX_SIZE
;
618 memcpy(ssid
, sdata
->u
.ap
.ssid
, len
);
627 static int ieee80211_ioctl_siwap(struct net_device
*dev
,
628 struct iw_request_info
*info
,
629 struct sockaddr
*ap_addr
, char *extra
)
631 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
632 struct ieee80211_sub_if_data
*sdata
;
634 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
635 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
636 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
638 if (local
->user_space_mlme
) {
639 memcpy(sdata
->u
.sta
.bssid
, (u8
*) &ap_addr
->sa_data
,
643 if (is_zero_ether_addr((u8
*) &ap_addr
->sa_data
)) {
644 sdata
->u
.sta
.auto_bssid_sel
= 1;
645 sdata
->u
.sta
.auto_channel_sel
= 1;
646 } else if (is_broadcast_ether_addr((u8
*) &ap_addr
->sa_data
))
647 sdata
->u
.sta
.auto_bssid_sel
= 1;
649 sdata
->u
.sta
.auto_bssid_sel
= 0;
650 ret
= ieee80211_sta_set_bssid(dev
, (u8
*) &ap_addr
->sa_data
);
653 ieee80211_sta_req_auth(dev
, &sdata
->u
.sta
);
655 } else if (sdata
->type
== IEEE80211_IF_TYPE_WDS
) {
656 if (memcmp(sdata
->u
.wds
.remote_addr
, (u8
*) &ap_addr
->sa_data
,
659 return ieee80211_if_update_wds(dev
, (u8
*) &ap_addr
->sa_data
);
666 static int ieee80211_ioctl_giwap(struct net_device
*dev
,
667 struct iw_request_info
*info
,
668 struct sockaddr
*ap_addr
, char *extra
)
670 struct ieee80211_sub_if_data
*sdata
;
672 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
673 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
674 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
675 ap_addr
->sa_family
= ARPHRD_ETHER
;
676 memcpy(&ap_addr
->sa_data
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
678 } else if (sdata
->type
== IEEE80211_IF_TYPE_WDS
) {
679 ap_addr
->sa_family
= ARPHRD_ETHER
;
680 memcpy(&ap_addr
->sa_data
, sdata
->u
.wds
.remote_addr
, ETH_ALEN
);
688 static int ieee80211_ioctl_siwscan(struct net_device
*dev
,
689 struct iw_request_info
*info
,
690 union iwreq_data
*wrqu
, char *extra
)
692 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
693 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
694 struct iw_scan_req
*req
= NULL
;
698 if (!netif_running(dev
))
701 switch (sdata
->type
) {
702 case IEEE80211_IF_TYPE_STA
:
703 case IEEE80211_IF_TYPE_IBSS
:
704 if (local
->scan_flags
& IEEE80211_SCAN_MATCH_SSID
) {
705 ssid
= sdata
->u
.sta
.ssid
;
706 ssid_len
= sdata
->u
.sta
.ssid_len
;
709 case IEEE80211_IF_TYPE_AP
:
710 if (local
->scan_flags
& IEEE80211_SCAN_MATCH_SSID
) {
711 ssid
= sdata
->u
.ap
.ssid
;
712 ssid_len
= sdata
->u
.ap
.ssid_len
;
719 /* if SSID was specified explicitly then use that */
720 if (wrqu
->data
.length
== sizeof(struct iw_scan_req
) &&
721 wrqu
->data
.flags
& IW_SCAN_THIS_ESSID
) {
722 req
= (struct iw_scan_req
*)extra
;
724 ssid_len
= req
->essid_len
;
727 return ieee80211_sta_req_scan(dev
, ssid
, ssid_len
);
731 static int ieee80211_ioctl_giwscan(struct net_device
*dev
,
732 struct iw_request_info
*info
,
733 struct iw_point
*data
, char *extra
)
736 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
737 if (local
->sta_scanning
)
739 res
= ieee80211_sta_scan_results(dev
, extra
, data
->length
);
749 static int ieee80211_ioctl_siwrate(struct net_device
*dev
,
750 struct iw_request_info
*info
,
751 struct iw_param
*rate
, char *extra
)
753 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
754 struct ieee80211_hw_mode
*mode
;
756 u32 target_rate
= rate
->value
/ 100000;
757 struct ieee80211_sub_if_data
*sdata
;
759 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
762 mode
= local
->oper_hw_mode
;
763 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
764 * target_rate = X, rate->fixed = 1 means only rate X
765 * target_rate = X, rate->fixed = 0 means all rates <= X */
766 sdata
->bss
->max_ratectrl_rateidx
= -1;
767 sdata
->bss
->force_unicast_rateidx
= -1;
770 for (i
=0; i
< mode
->num_rates
; i
++) {
771 struct ieee80211_rate
*rates
= &mode
->rates
[i
];
772 int this_rate
= rates
->rate
;
774 if (mode
->mode
== MODE_ATHEROS_TURBO
||
775 mode
->mode
== MODE_ATHEROS_TURBOG
)
777 if (target_rate
== this_rate
) {
778 sdata
->bss
->max_ratectrl_rateidx
= i
;
780 sdata
->bss
->force_unicast_rateidx
= i
;
787 static int ieee80211_ioctl_giwrate(struct net_device
*dev
,
788 struct iw_request_info
*info
,
789 struct iw_param
*rate
, char *extra
)
791 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
792 struct sta_info
*sta
;
793 struct ieee80211_sub_if_data
*sdata
;
795 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
796 if (sdata
->type
== IEEE80211_IF_TYPE_STA
)
797 sta
= sta_info_get(local
, sdata
->u
.sta
.bssid
);
802 if (sta
->txrate
< local
->oper_hw_mode
->num_rates
)
803 rate
->value
= local
->oper_hw_mode
->rates
[sta
->txrate
].rate
* 100000;
810 static int ieee80211_ioctl_siwrts(struct net_device
*dev
,
811 struct iw_request_info
*info
,
812 struct iw_param
*rts
, char *extra
)
814 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
817 local
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
818 else if (rts
->value
< 0 || rts
->value
> IEEE80211_MAX_RTS_THRESHOLD
)
821 local
->rts_threshold
= rts
->value
;
823 /* If the wlan card performs RTS/CTS in hardware/firmware,
824 * configure it here */
826 if (local
->ops
->set_rts_threshold
)
827 local
->ops
->set_rts_threshold(local_to_hw(local
),
828 local
->rts_threshold
);
833 static int ieee80211_ioctl_giwrts(struct net_device
*dev
,
834 struct iw_request_info
*info
,
835 struct iw_param
*rts
, char *extra
)
837 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
839 rts
->value
= local
->rts_threshold
;
840 rts
->disabled
= (rts
->value
>= IEEE80211_MAX_RTS_THRESHOLD
);
847 static int ieee80211_ioctl_siwfrag(struct net_device
*dev
,
848 struct iw_request_info
*info
,
849 struct iw_param
*frag
, char *extra
)
851 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
854 local
->fragmentation_threshold
= IEEE80211_MAX_FRAG_THRESHOLD
;
855 else if (frag
->value
< 256 ||
856 frag
->value
> IEEE80211_MAX_FRAG_THRESHOLD
)
859 /* Fragment length must be even, so strip LSB. */
860 local
->fragmentation_threshold
= frag
->value
& ~0x1;
863 /* If the wlan card performs fragmentation in hardware/firmware,
864 * configure it here */
866 if (local
->ops
->set_frag_threshold
)
867 local
->ops
->set_frag_threshold(
869 local
->fragmentation_threshold
);
874 static int ieee80211_ioctl_giwfrag(struct net_device
*dev
,
875 struct iw_request_info
*info
,
876 struct iw_param
*frag
, char *extra
)
878 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
880 frag
->value
= local
->fragmentation_threshold
;
881 frag
->disabled
= (frag
->value
>= IEEE80211_MAX_RTS_THRESHOLD
);
888 static int ieee80211_ioctl_siwretry(struct net_device
*dev
,
889 struct iw_request_info
*info
,
890 struct iw_param
*retry
, char *extra
)
892 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
894 if (retry
->disabled
||
895 (retry
->flags
& IW_RETRY_TYPE
) != IW_RETRY_LIMIT
)
898 if (retry
->flags
& IW_RETRY_MAX
)
899 local
->long_retry_limit
= retry
->value
;
900 else if (retry
->flags
& IW_RETRY_MIN
)
901 local
->short_retry_limit
= retry
->value
;
903 local
->long_retry_limit
= retry
->value
;
904 local
->short_retry_limit
= retry
->value
;
907 if (local
->ops
->set_retry_limit
) {
908 return local
->ops
->set_retry_limit(
910 local
->short_retry_limit
,
911 local
->long_retry_limit
);
918 static int ieee80211_ioctl_giwretry(struct net_device
*dev
,
919 struct iw_request_info
*info
,
920 struct iw_param
*retry
, char *extra
)
922 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
925 if (retry
->flags
== 0 || retry
->flags
& IW_RETRY_MIN
) {
926 /* first return min value, iwconfig will ask max value
928 retry
->flags
|= IW_RETRY_LIMIT
;
929 retry
->value
= local
->short_retry_limit
;
930 if (local
->long_retry_limit
!= local
->short_retry_limit
)
931 retry
->flags
|= IW_RETRY_MIN
;
934 if (retry
->flags
& IW_RETRY_MAX
) {
935 retry
->flags
= IW_RETRY_LIMIT
| IW_RETRY_MAX
;
936 retry
->value
= local
->long_retry_limit
;
942 static void ieee80211_key_enable_hwaccel(struct ieee80211_local
*local
,
943 struct ieee80211_key
*key
)
945 struct ieee80211_key_conf
*keyconf
;
948 if (!key
|| key
->alg
!= ALG_WEP
|| !key
->force_sw_encrypt
||
949 (local
->hw
.flags
& IEEE80211_HW_DEVICE_HIDES_WEP
))
952 memset(addr
, 0xff, ETH_ALEN
);
953 keyconf
= ieee80211_key_data2conf(local
, key
);
954 if (keyconf
&& local
->ops
->set_key
&&
955 local
->ops
->set_key(local_to_hw(local
),
956 SET_KEY
, addr
, keyconf
, 0) == 0) {
957 key
->force_sw_encrypt
=
958 !!(keyconf
->flags
& IEEE80211_KEY_FORCE_SW_ENCRYPT
);
959 key
->hw_key_idx
= keyconf
->hw_key_idx
;
965 static void ieee80211_key_disable_hwaccel(struct ieee80211_local
*local
,
966 struct ieee80211_key
*key
)
968 struct ieee80211_key_conf
*keyconf
;
971 if (!key
|| key
->alg
!= ALG_WEP
|| key
->force_sw_encrypt
||
972 (local
->hw
.flags
& IEEE80211_HW_DEVICE_HIDES_WEP
))
975 memset(addr
, 0xff, ETH_ALEN
);
976 keyconf
= ieee80211_key_data2conf(local
, key
);
977 if (keyconf
&& local
->ops
->set_key
)
978 local
->ops
->set_key(local_to_hw(local
), DISABLE_KEY
,
981 key
->force_sw_encrypt
= 1;
985 static int ieee80211_ioctl_default_wep_only(struct ieee80211_local
*local
,
989 struct ieee80211_sub_if_data
*sdata
;
991 local
->default_wep_only
= value
;
992 read_lock(&local
->sub_if_lock
);
993 list_for_each_entry(sdata
, &local
->sub_if_list
, list
)
994 for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++)
996 ieee80211_key_enable_hwaccel(local
,
999 ieee80211_key_disable_hwaccel(local
,
1001 read_unlock(&local
->sub_if_lock
);
1007 void ieee80211_update_default_wep_only(struct ieee80211_local
*local
)
1010 struct ieee80211_sub_if_data
*sdata
;
1012 read_lock(&local
->sub_if_lock
);
1013 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
1015 if (sdata
->dev
== local
->mdev
)
1018 /* If there is an AP interface then depend on userspace to
1019 set default_wep_only correctly. */
1020 if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
1021 read_unlock(&local
->sub_if_lock
);
1028 read_unlock(&local
->sub_if_lock
);
1031 ieee80211_ioctl_default_wep_only(local
, 1);
1033 ieee80211_ioctl_default_wep_only(local
, 0);
1037 static int ieee80211_ioctl_prism2_param(struct net_device
*dev
,
1038 struct iw_request_info
*info
,
1039 void *wrqu
, char *extra
)
1041 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1042 struct ieee80211_sub_if_data
*sdata
;
1043 int *i
= (int *) extra
;
1045 int value
= *(i
+ 1);
1048 if (!capable(CAP_NET_ADMIN
))
1051 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1054 case PRISM2_PARAM_IEEE_802_1X
:
1055 if (local
->ops
->set_ieee8021x
)
1056 ret
= local
->ops
->set_ieee8021x(local_to_hw(local
),
1059 printk(KERN_DEBUG
"%s: failed to set IEEE 802.1X (%d) "
1060 "for low-level driver\n", dev
->name
, value
);
1062 sdata
->ieee802_1x
= value
;
1065 case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES
:
1066 if (sdata
->type
!= IEEE80211_IF_TYPE_AP
)
1069 sdata
->use_protection
= value
;
1072 case PRISM2_PARAM_PREAMBLE
:
1073 local
->short_preamble
= value
;
1076 case PRISM2_PARAM_STAT_TIME
:
1077 if (!local
->stat_time
&& value
) {
1078 local
->stat_timer
.expires
= jiffies
+ HZ
* value
/ 100;
1079 add_timer(&local
->stat_timer
);
1080 } else if (local
->stat_time
&& !value
) {
1081 del_timer_sync(&local
->stat_timer
);
1083 local
->stat_time
= value
;
1085 case PRISM2_PARAM_SHORT_SLOT_TIME
:
1087 local
->hw
.conf
.flags
|= IEEE80211_CONF_SHORT_SLOT_TIME
;
1089 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_SHORT_SLOT_TIME
;
1090 if (ieee80211_hw_config(local
))
1094 case PRISM2_PARAM_NEXT_MODE
:
1095 local
->next_mode
= value
;
1098 case PRISM2_PARAM_RADIO_ENABLED
:
1099 ret
= ieee80211_ioctl_set_radio_enabled(dev
, value
);
1102 case PRISM2_PARAM_ANTENNA_MODE
:
1103 local
->hw
.conf
.antenna_mode
= value
;
1104 if (ieee80211_hw_config(local
))
1108 case PRISM2_PARAM_STA_ANTENNA_SEL
:
1109 local
->sta_antenna_sel
= value
;
1112 case PRISM2_PARAM_TX_POWER_REDUCTION
:
1116 local
->hw
.conf
.tx_power_reduction
= value
;
1119 case PRISM2_PARAM_KEY_TX_RX_THRESHOLD
:
1120 local
->key_tx_rx_threshold
= value
;
1123 case PRISM2_PARAM_DEFAULT_WEP_ONLY
:
1124 ret
= ieee80211_ioctl_default_wep_only(local
, value
);
1127 case PRISM2_PARAM_WIFI_WME_NOACK_TEST
:
1128 local
->wifi_wme_noack_test
= value
;
1131 case PRISM2_PARAM_SCAN_FLAGS
:
1132 local
->scan_flags
= value
;
1135 case PRISM2_PARAM_MIXED_CELL
:
1136 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
1137 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
1140 sdata
->u
.sta
.mixed_cell
= !!value
;
1143 case PRISM2_PARAM_HW_MODES
:
1144 local
->enabled_modes
= value
;
1147 case PRISM2_PARAM_CREATE_IBSS
:
1148 if (sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
1151 sdata
->u
.sta
.create_ibss
= !!value
;
1153 case PRISM2_PARAM_WMM_ENABLED
:
1154 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
1155 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
1158 sdata
->u
.sta
.wmm_enabled
= !!value
;
1160 case PRISM2_PARAM_RADAR_DETECT
:
1161 local
->hw
.conf
.radar_detect
= value
;
1163 case PRISM2_PARAM_SPECTRUM_MGMT
:
1164 local
->hw
.conf
.spect_mgmt
= value
;
1175 static int ieee80211_ioctl_get_prism2_param(struct net_device
*dev
,
1176 struct iw_request_info
*info
,
1177 void *wrqu
, char *extra
)
1179 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1180 struct ieee80211_sub_if_data
*sdata
;
1181 int *param
= (int *) extra
;
1184 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1187 case PRISM2_PARAM_IEEE_802_1X
:
1188 *param
= sdata
->ieee802_1x
;
1191 case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES
:
1192 *param
= sdata
->use_protection
;
1195 case PRISM2_PARAM_PREAMBLE
:
1196 *param
= local
->short_preamble
;
1199 case PRISM2_PARAM_STAT_TIME
:
1200 *param
= local
->stat_time
;
1202 case PRISM2_PARAM_SHORT_SLOT_TIME
:
1203 *param
= !!(local
->hw
.conf
.flags
& IEEE80211_CONF_SHORT_SLOT_TIME
);
1206 case PRISM2_PARAM_NEXT_MODE
:
1207 *param
= local
->next_mode
;
1210 case PRISM2_PARAM_ANTENNA_MODE
:
1211 *param
= local
->hw
.conf
.antenna_mode
;
1214 case PRISM2_PARAM_STA_ANTENNA_SEL
:
1215 *param
= local
->sta_antenna_sel
;
1218 case PRISM2_PARAM_TX_POWER_REDUCTION
:
1219 *param
= local
->hw
.conf
.tx_power_reduction
;
1222 case PRISM2_PARAM_KEY_TX_RX_THRESHOLD
:
1223 *param
= local
->key_tx_rx_threshold
;
1226 case PRISM2_PARAM_DEFAULT_WEP_ONLY
:
1227 *param
= local
->default_wep_only
;
1230 case PRISM2_PARAM_WIFI_WME_NOACK_TEST
:
1231 *param
= local
->wifi_wme_noack_test
;
1234 case PRISM2_PARAM_SCAN_FLAGS
:
1235 *param
= local
->scan_flags
;
1238 case PRISM2_PARAM_HW_MODES
:
1239 *param
= local
->enabled_modes
;
1242 case PRISM2_PARAM_CREATE_IBSS
:
1243 if (sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
1246 *param
= !!sdata
->u
.sta
.create_ibss
;
1249 case PRISM2_PARAM_MIXED_CELL
:
1250 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
1251 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
1254 *param
= !!sdata
->u
.sta
.mixed_cell
;
1256 case PRISM2_PARAM_WMM_ENABLED
:
1257 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
1258 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
1261 *param
= !!sdata
->u
.sta
.wmm_enabled
;
1271 static int ieee80211_ioctl_siwmlme(struct net_device
*dev
,
1272 struct iw_request_info
*info
,
1273 struct iw_point
*data
, char *extra
)
1275 struct ieee80211_sub_if_data
*sdata
;
1276 struct iw_mlme
*mlme
= (struct iw_mlme
*) extra
;
1278 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1279 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
1280 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
1283 switch (mlme
->cmd
) {
1284 case IW_MLME_DEAUTH
:
1285 /* TODO: mlme->addr.sa_data */
1286 return ieee80211_sta_deauthenticate(dev
, mlme
->reason_code
);
1287 case IW_MLME_DISASSOC
:
1288 /* TODO: mlme->addr.sa_data */
1289 return ieee80211_sta_disassociate(dev
, mlme
->reason_code
);
1296 static int ieee80211_ioctl_siwencode(struct net_device
*dev
,
1297 struct iw_request_info
*info
,
1298 struct iw_point
*erq
, char *keybuf
)
1300 struct ieee80211_sub_if_data
*sdata
;
1301 int idx
, i
, alg
= ALG_WEP
;
1302 u8 bcaddr
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1304 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1306 idx
= erq
->flags
& IW_ENCODE_INDEX
;
1308 if (sdata
->default_key
)
1309 for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
1310 if (sdata
->default_key
== sdata
->keys
[i
]) {
1315 } else if (idx
< 1 || idx
> 4)
1320 if (erq
->flags
& IW_ENCODE_DISABLED
)
1322 else if (erq
->length
== 0) {
1323 /* No key data - just set the default TX key index */
1324 if (sdata
->default_key
!= sdata
->keys
[idx
]) {
1325 ieee80211_debugfs_key_remove_default(sdata
);
1326 sdata
->default_key
= sdata
->keys
[idx
];
1327 if (sdata
->default_key
)
1328 ieee80211_debugfs_key_add_default(sdata
);
1333 return ieee80211_set_encryption(
1336 !sdata
->default_key
,
1337 keybuf
, erq
->length
);
1341 static int ieee80211_ioctl_giwencode(struct net_device
*dev
,
1342 struct iw_request_info
*info
,
1343 struct iw_point
*erq
, char *key
)
1345 struct ieee80211_sub_if_data
*sdata
;
1348 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1350 idx
= erq
->flags
& IW_ENCODE_INDEX
;
1351 if (idx
< 1 || idx
> 4) {
1353 if (!sdata
->default_key
)
1355 else for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
1356 if (sdata
->default_key
== sdata
->keys
[i
]) {
1366 erq
->flags
= idx
+ 1;
1368 if (!sdata
->keys
[idx
]) {
1370 erq
->flags
|= IW_ENCODE_DISABLED
;
1374 memcpy(key
, sdata
->keys
[idx
]->key
,
1375 min((int)erq
->length
, sdata
->keys
[idx
]->keylen
));
1376 erq
->length
= sdata
->keys
[idx
]->keylen
;
1377 erq
->flags
|= IW_ENCODE_ENABLED
;
1382 static int ieee80211_ioctl_siwauth(struct net_device
*dev
,
1383 struct iw_request_info
*info
,
1384 struct iw_param
*data
, char *extra
)
1386 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1387 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1390 switch (data
->flags
& IW_AUTH_INDEX
) {
1391 case IW_AUTH_WPA_VERSION
:
1392 case IW_AUTH_CIPHER_PAIRWISE
:
1393 case IW_AUTH_CIPHER_GROUP
:
1394 case IW_AUTH_WPA_ENABLED
:
1395 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
1397 case IW_AUTH_KEY_MGMT
:
1398 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
1402 * TODO: sdata->u.sta.key_mgmt does not match with WE18
1403 * value completely; could consider modifying this to
1404 * be closer to WE18. For now, this value is not really
1405 * used for anything else than Privacy matching, so the
1406 * current code here should be more or less OK.
1408 if (data
->value
& IW_AUTH_KEY_MGMT_802_1X
) {
1409 sdata
->u
.sta
.key_mgmt
=
1410 IEEE80211_KEY_MGMT_WPA_EAP
;
1411 } else if (data
->value
& IW_AUTH_KEY_MGMT_PSK
) {
1412 sdata
->u
.sta
.key_mgmt
=
1413 IEEE80211_KEY_MGMT_WPA_PSK
;
1415 sdata
->u
.sta
.key_mgmt
=
1416 IEEE80211_KEY_MGMT_NONE
;
1420 case IW_AUTH_80211_AUTH_ALG
:
1421 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
1422 sdata
->type
== IEEE80211_IF_TYPE_IBSS
)
1423 sdata
->u
.sta
.auth_algs
= data
->value
;
1427 case IW_AUTH_PRIVACY_INVOKED
:
1428 if (local
->ops
->set_privacy_invoked
)
1429 ret
= local
->ops
->set_privacy_invoked(
1430 local_to_hw(local
), data
->value
);
1439 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
1440 static struct iw_statistics
*ieee80211_get_wireless_stats(struct net_device
*dev
)
1442 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1443 struct iw_statistics
*wstats
= &local
->wstats
;
1444 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1445 struct sta_info
*sta
= NULL
;
1447 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
1448 sdata
->type
== IEEE80211_IF_TYPE_IBSS
)
1449 sta
= sta_info_get(local
, sdata
->u
.sta
.bssid
);
1451 wstats
->discard
.fragment
= 0;
1452 wstats
->discard
.misc
= 0;
1453 wstats
->qual
.qual
= 0;
1454 wstats
->qual
.level
= 0;
1455 wstats
->qual
.noise
= 0;
1456 wstats
->qual
.updated
= IW_QUAL_ALL_INVALID
;
1458 wstats
->qual
.level
= sta
->last_rssi
;
1459 wstats
->qual
.qual
= sta
->last_signal
;
1460 wstats
->qual
.noise
= sta
->last_noise
;
1461 wstats
->qual
.updated
= local
->wstats_flags
;
1467 static int ieee80211_ioctl_giwauth(struct net_device
*dev
,
1468 struct iw_request_info
*info
,
1469 struct iw_param
*data
, char *extra
)
1471 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1474 switch (data
->flags
& IW_AUTH_INDEX
) {
1475 case IW_AUTH_80211_AUTH_ALG
:
1476 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
1477 sdata
->type
== IEEE80211_IF_TYPE_IBSS
)
1478 data
->value
= sdata
->u
.sta
.auth_algs
;
1490 static int ieee80211_ioctl_siwencodeext(struct net_device
*dev
,
1491 struct iw_request_info
*info
,
1492 struct iw_point
*erq
, char *extra
)
1494 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1495 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*) extra
;
1499 case IW_ENCODE_ALG_NONE
:
1502 case IW_ENCODE_ALG_WEP
:
1505 case IW_ENCODE_ALG_TKIP
:
1508 case IW_ENCODE_ALG_CCMP
:
1515 if (erq
->flags
& IW_ENCODE_DISABLED
)
1518 idx
= erq
->flags
& IW_ENCODE_INDEX
;
1519 if (idx
< 1 || idx
> 4) {
1521 if (!sdata
->default_key
)
1523 else for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
1524 if (sdata
->default_key
== sdata
->keys
[i
]) {
1534 return ieee80211_set_encryption(dev
, ext
->addr
.sa_data
, idx
, alg
,
1536 IW_ENCODE_EXT_SET_TX_KEY
,
1537 ext
->key
, ext
->key_len
);
1541 static const struct iw_priv_args ieee80211_ioctl_priv
[] = {
1542 { PRISM2_IOCTL_PRISM2_PARAM
,
1543 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 2, 0, "param" },
1544 { PRISM2_IOCTL_GET_PRISM2_PARAM
,
1545 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
1546 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1, "get_param" },
1549 /* Structures to export the Wireless Handlers */
1551 static const iw_handler ieee80211_handler
[] =
1553 (iw_handler
) NULL
, /* SIOCSIWCOMMIT */
1554 (iw_handler
) ieee80211_ioctl_giwname
, /* SIOCGIWNAME */
1555 (iw_handler
) NULL
, /* SIOCSIWNWID */
1556 (iw_handler
) NULL
, /* SIOCGIWNWID */
1557 (iw_handler
) ieee80211_ioctl_siwfreq
, /* SIOCSIWFREQ */
1558 (iw_handler
) ieee80211_ioctl_giwfreq
, /* SIOCGIWFREQ */
1559 (iw_handler
) ieee80211_ioctl_siwmode
, /* SIOCSIWMODE */
1560 (iw_handler
) ieee80211_ioctl_giwmode
, /* SIOCGIWMODE */
1561 (iw_handler
) NULL
, /* SIOCSIWSENS */
1562 (iw_handler
) NULL
, /* SIOCGIWSENS */
1563 (iw_handler
) NULL
/* not used */, /* SIOCSIWRANGE */
1564 (iw_handler
) ieee80211_ioctl_giwrange
, /* SIOCGIWRANGE */
1565 (iw_handler
) NULL
/* not used */, /* SIOCSIWPRIV */
1566 (iw_handler
) NULL
/* kernel code */, /* SIOCGIWPRIV */
1567 (iw_handler
) NULL
/* not used */, /* SIOCSIWSTATS */
1568 (iw_handler
) NULL
/* kernel code */, /* SIOCGIWSTATS */
1569 iw_handler_set_spy
, /* SIOCSIWSPY */
1570 iw_handler_get_spy
, /* SIOCGIWSPY */
1571 iw_handler_set_thrspy
, /* SIOCSIWTHRSPY */
1572 iw_handler_get_thrspy
, /* SIOCGIWTHRSPY */
1573 (iw_handler
) ieee80211_ioctl_siwap
, /* SIOCSIWAP */
1574 (iw_handler
) ieee80211_ioctl_giwap
, /* SIOCGIWAP */
1575 (iw_handler
) ieee80211_ioctl_siwmlme
, /* SIOCSIWMLME */
1576 (iw_handler
) NULL
, /* SIOCGIWAPLIST */
1577 (iw_handler
) ieee80211_ioctl_siwscan
, /* SIOCSIWSCAN */
1578 (iw_handler
) ieee80211_ioctl_giwscan
, /* SIOCGIWSCAN */
1579 (iw_handler
) ieee80211_ioctl_siwessid
, /* SIOCSIWESSID */
1580 (iw_handler
) ieee80211_ioctl_giwessid
, /* SIOCGIWESSID */
1581 (iw_handler
) NULL
, /* SIOCSIWNICKN */
1582 (iw_handler
) NULL
, /* SIOCGIWNICKN */
1583 (iw_handler
) NULL
, /* -- hole -- */
1584 (iw_handler
) NULL
, /* -- hole -- */
1585 (iw_handler
) ieee80211_ioctl_siwrate
, /* SIOCSIWRATE */
1586 (iw_handler
) ieee80211_ioctl_giwrate
, /* SIOCGIWRATE */
1587 (iw_handler
) ieee80211_ioctl_siwrts
, /* SIOCSIWRTS */
1588 (iw_handler
) ieee80211_ioctl_giwrts
, /* SIOCGIWRTS */
1589 (iw_handler
) ieee80211_ioctl_siwfrag
, /* SIOCSIWFRAG */
1590 (iw_handler
) ieee80211_ioctl_giwfrag
, /* SIOCGIWFRAG */
1591 (iw_handler
) NULL
, /* SIOCSIWTXPOW */
1592 (iw_handler
) NULL
, /* SIOCGIWTXPOW */
1593 (iw_handler
) ieee80211_ioctl_siwretry
, /* SIOCSIWRETRY */
1594 (iw_handler
) ieee80211_ioctl_giwretry
, /* SIOCGIWRETRY */
1595 (iw_handler
) ieee80211_ioctl_siwencode
, /* SIOCSIWENCODE */
1596 (iw_handler
) ieee80211_ioctl_giwencode
, /* SIOCGIWENCODE */
1597 (iw_handler
) NULL
, /* SIOCSIWPOWER */
1598 (iw_handler
) NULL
, /* SIOCGIWPOWER */
1599 (iw_handler
) NULL
, /* -- hole -- */
1600 (iw_handler
) NULL
, /* -- hole -- */
1601 (iw_handler
) ieee80211_ioctl_siwgenie
, /* SIOCSIWGENIE */
1602 (iw_handler
) NULL
, /* SIOCGIWGENIE */
1603 (iw_handler
) ieee80211_ioctl_siwauth
, /* SIOCSIWAUTH */
1604 (iw_handler
) ieee80211_ioctl_giwauth
, /* SIOCGIWAUTH */
1605 (iw_handler
) ieee80211_ioctl_siwencodeext
, /* SIOCSIWENCODEEXT */
1606 (iw_handler
) NULL
, /* SIOCGIWENCODEEXT */
1607 (iw_handler
) NULL
, /* SIOCSIWPMKSA */
1608 (iw_handler
) NULL
, /* -- hole -- */
1611 static const iw_handler ieee80211_private_handler
[] =
1612 { /* SIOCIWFIRSTPRIV + */
1613 (iw_handler
) ieee80211_ioctl_prism2_param
, /* 0 */
1614 (iw_handler
) ieee80211_ioctl_get_prism2_param
, /* 1 */
1617 const struct iw_handler_def ieee80211_iw_handler_def
=
1619 .num_standard
= ARRAY_SIZE(ieee80211_handler
),
1620 .num_private
= ARRAY_SIZE(ieee80211_private_handler
),
1621 .num_private_args
= ARRAY_SIZE(ieee80211_ioctl_priv
),
1622 .standard
= (iw_handler
*) ieee80211_handler
,
1623 .private = (iw_handler
*) ieee80211_private_handler
,
1624 .private_args
= (struct iw_priv_args
*) ieee80211_ioctl_priv
,
1625 .get_wireless_stats
= ieee80211_get_wireless_stats
,