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 int ieee80211_regdom
= 0x10; /* FCC */
31 module_param(ieee80211_regdom
, int, 0444);
32 MODULE_PARM_DESC(ieee80211_regdom
, "IEEE 802.11 regulatory domain; 64=MKK");
35 * If firmware is upgraded by the vendor, additional channels can be used based
36 * on the new Japanese regulatory rules. This is indicated by setting
37 * ieee80211_japan_5ghz module parameter to one when loading the 80211 kernel
40 static int ieee80211_japan_5ghz
/* = 0 */;
41 module_param(ieee80211_japan_5ghz
, int, 0444);
42 MODULE_PARM_DESC(ieee80211_japan_5ghz
, "Vendor-updated firmware for 5 GHz");
44 static void ieee80211_set_hw_encryption(struct net_device
*dev
,
45 struct sta_info
*sta
, u8 addr
[ETH_ALEN
],
46 struct ieee80211_key
*key
)
48 struct ieee80211_key_conf
*keyconf
= NULL
;
49 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
51 /* default to sw encryption; this will be cleared by low-level
52 * driver if the hw supports requested encryption */
54 key
->force_sw_encrypt
= 1;
56 if (key
&& local
->ops
->set_key
&&
57 (keyconf
= ieee80211_key_data2conf(local
, key
))) {
58 if (local
->ops
->set_key(local_to_hw(local
), SET_KEY
, addr
,
59 keyconf
, sta
? sta
->aid
: 0)) {
60 key
->force_sw_encrypt
= 1;
61 key
->hw_key_idx
= HW_KEY_IDX_INVALID
;
63 key
->force_sw_encrypt
=
64 !!(keyconf
->flags
& IEEE80211_KEY_FORCE_SW_ENCRYPT
);
74 static int ieee80211_set_encryption(struct net_device
*dev
, u8
*sta_addr
,
75 int idx
, int alg
, int set_tx_key
,
76 const u8
*_key
, size_t key_len
)
78 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
81 struct ieee80211_key
*key
, *old_key
;
83 struct ieee80211_key_conf
*keyconf
;
84 struct ieee80211_sub_if_data
*sdata
;
86 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
88 if (is_broadcast_ether_addr(sta_addr
)) {
90 if (idx
>= NUM_DEFAULT_KEYS
) {
91 printk(KERN_DEBUG
"%s: set_encrypt - invalid idx=%d\n",
95 key
= sdata
->keys
[idx
];
97 /* TODO: consider adding hwaccel support for these; at least
98 * Atheros key cache should be able to handle this since AP is
99 * only transmitting frames with default keys. */
100 /* FIX: hw key cache can be used when only one virtual
101 * STA is associated with each AP. If more than one STA
102 * is associated to the same AP, software encryption
103 * must be used. This should be done automatically
104 * based on configured station devices. For the time
105 * being, this can be only set at compile time. */
109 printk(KERN_DEBUG
"%s: set_encrypt - non-zero idx for "
110 "individual key\n", dev
->name
);
114 sta
= sta_info_get(local
, sta_addr
);
116 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
117 printk(KERN_DEBUG
"%s: set_encrypt - unknown addr "
119 dev
->name
, MAC_ARG(sta_addr
));
120 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
129 * Cannot configure default hwaccel keys with WEP algorithm, if
130 * any of the virtual interfaces is using static WEP
131 * configuration because hwaccel would otherwise try to decrypt
134 * For now, just disable WEP hwaccel for broadcast when there is
135 * possibility of conflict with default keys. This can maybe later be
136 * optimized by using non-default keys (at least with Atheros ar521x).
138 if (!sta
&& alg
== ALG_WEP
&& !local
->default_wep_only
&&
139 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
&&
140 sdata
->type
!= IEEE80211_IF_TYPE_AP
) {
144 if (local
->hw
.flags
& IEEE80211_HW_DEVICE_HIDES_WEP
) {
145 /* Software encryption cannot be used with devices that hide
146 * encryption from the host system, so always try to use
147 * hardware acceleration with such devices. */
151 if ((local
->hw
.flags
& IEEE80211_HW_NO_TKIP_WMM_HWACCEL
) &&
153 if (sta
&& (sta
->flags
& WLAN_STA_WME
)) {
154 /* Hardware does not support hwaccel with TKIP when using WMM.
158 else if (sdata
->type
== IEEE80211_IF_TYPE_STA
) {
159 sta
= sta_info_get(local
, sdata
->u
.sta
.bssid
);
161 if (sta
->flags
& WLAN_STA_WME
) {
170 if (alg
== ALG_NONE
) {
172 if (try_hwaccel
&& key
&&
173 key
->hw_key_idx
!= HW_KEY_IDX_INVALID
&&
174 local
->ops
->set_key
&&
175 (keyconf
= ieee80211_key_data2conf(local
, key
)) != NULL
&&
176 local
->ops
->set_key(local_to_hw(local
), DISABLE_KEY
,
177 sta_addr
, keyconf
, sta
? sta
->aid
: 0)) {
178 printk(KERN_DEBUG
"%s: set_encrypt - low-level disable"
179 " failed\n", dev
->name
);
184 if (set_tx_key
|| sdata
->default_key
== key
) {
185 ieee80211_debugfs_key_remove_default(sdata
);
186 sdata
->default_key
= NULL
;
188 ieee80211_debugfs_key_remove(key
);
192 sdata
->keys
[idx
] = NULL
;
193 ieee80211_key_free(key
);
197 key
= ieee80211_key_alloc(sta
? NULL
: sdata
, idx
, key_len
,
204 /* default to sw encryption; low-level driver sets these if the
205 * requested encryption is supported */
206 key
->hw_key_idx
= HW_KEY_IDX_INVALID
;
207 key
->force_sw_encrypt
= 1;
211 key
->keylen
= key_len
;
212 memcpy(key
->key
, _key
, key_len
);
214 key
->default_tx_key
= 1;
216 if (alg
== ALG_CCMP
) {
217 /* Initialize AES key state here as an optimization
218 * so that it does not need to be initialized for every
220 key
->u
.ccmp
.tfm
= ieee80211_aes_key_setup_encrypt(
222 if (!key
->u
.ccmp
.tfm
) {
228 if (set_tx_key
|| sdata
->default_key
== old_key
) {
229 ieee80211_debugfs_key_remove_default(sdata
);
230 sdata
->default_key
= NULL
;
232 ieee80211_debugfs_key_remove(old_key
);
236 sdata
->keys
[idx
] = key
;
237 ieee80211_key_free(old_key
);
238 ieee80211_debugfs_key_add(local
, key
);
240 ieee80211_debugfs_key_sta_link(key
, sta
);
243 (alg
== ALG_WEP
|| alg
== ALG_TKIP
|| alg
== ALG_CCMP
))
244 ieee80211_set_hw_encryption(dev
, sta
, sta_addr
, key
);
247 if (set_tx_key
|| (!sta
&& !sdata
->default_key
&& key
)) {
248 sdata
->default_key
= key
;
250 ieee80211_debugfs_key_add_default(sdata
);
252 if (local
->ops
->set_key_idx
&&
253 local
->ops
->set_key_idx(local_to_hw(local
), idx
))
254 printk(KERN_DEBUG
"%s: failed to set TX key idx for "
255 "low-level driver\n", dev
->name
);
264 ieee80211_key_free(key
);
271 static int ieee80211_ioctl_siwgenie(struct net_device
*dev
,
272 struct iw_request_info
*info
,
273 struct iw_point
*data
, char *extra
)
275 struct ieee80211_sub_if_data
*sdata
;
276 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
278 if (local
->user_space_mlme
)
281 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
282 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
283 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
284 int ret
= ieee80211_sta_set_extra_ie(dev
, extra
, data
->length
);
287 sdata
->u
.sta
.auto_bssid_sel
= 0;
288 ieee80211_sta_req_auth(dev
, &sdata
->u
.sta
);
292 if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
293 kfree(sdata
->u
.ap
.generic_elem
);
294 sdata
->u
.ap
.generic_elem
= kmalloc(data
->length
, GFP_KERNEL
);
295 if (!sdata
->u
.ap
.generic_elem
)
297 memcpy(sdata
->u
.ap
.generic_elem
, extra
, data
->length
);
298 sdata
->u
.ap
.generic_elem_len
= data
->length
;
299 return ieee80211_if_config(dev
);
304 static int ieee80211_ioctl_set_radio_enabled(struct net_device
*dev
,
307 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
308 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
310 conf
->radio_enabled
= val
;
311 return ieee80211_hw_config(wdev_priv(dev
->ieee80211_ptr
));
314 static int ieee80211_ioctl_giwname(struct net_device
*dev
,
315 struct iw_request_info
*info
,
316 char *name
, char *extra
)
318 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
320 switch (local
->hw
.conf
.phymode
) {
321 case MODE_IEEE80211A
:
322 strcpy(name
, "IEEE 802.11a");
324 case MODE_IEEE80211B
:
325 strcpy(name
, "IEEE 802.11b");
327 case MODE_IEEE80211G
:
328 strcpy(name
, "IEEE 802.11g");
330 case MODE_ATHEROS_TURBO
:
331 strcpy(name
, "5GHz Turbo");
334 strcpy(name
, "IEEE 802.11");
342 static int ieee80211_ioctl_giwrange(struct net_device
*dev
,
343 struct iw_request_info
*info
,
344 struct iw_point
*data
, char *extra
)
346 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
347 struct iw_range
*range
= (struct iw_range
*) extra
;
348 struct ieee80211_hw_mode
*mode
= NULL
;
351 data
->length
= sizeof(struct iw_range
);
352 memset(range
, 0, sizeof(struct iw_range
));
354 range
->we_version_compiled
= WIRELESS_EXT
;
355 range
->we_version_source
= 21;
356 range
->retry_capa
= IW_RETRY_LIMIT
;
357 range
->retry_flags
= IW_RETRY_LIMIT
;
358 range
->min_retry
= 0;
359 range
->max_retry
= 255;
361 range
->max_rts
= 2347;
362 range
->min_frag
= 256;
363 range
->max_frag
= 2346;
365 range
->encoding_size
[0] = 5;
366 range
->encoding_size
[1] = 13;
367 range
->num_encoding_sizes
= 2;
368 range
->max_encoding_tokens
= NUM_DEFAULT_KEYS
;
370 range
->max_qual
.qual
= local
->hw
.max_signal
;
371 range
->max_qual
.level
= local
->hw
.max_rssi
;
372 range
->max_qual
.noise
= local
->hw
.max_noise
;
373 range
->max_qual
.updated
= local
->wstats_flags
;
375 range
->avg_qual
.qual
= local
->hw
.max_signal
/2;
376 range
->avg_qual
.level
= 0;
377 range
->avg_qual
.noise
= 0;
378 range
->avg_qual
.updated
= local
->wstats_flags
;
380 range
->enc_capa
= IW_ENC_CAPA_WPA
| IW_ENC_CAPA_WPA2
|
381 IW_ENC_CAPA_CIPHER_TKIP
| IW_ENC_CAPA_CIPHER_CCMP
;
383 list_for_each_entry(mode
, &local
->modes_list
, list
) {
386 if (!(local
->enabled_modes
& (1 << mode
->mode
)) ||
387 (local
->hw_modes
& local
->enabled_modes
&
388 (1 << MODE_IEEE80211G
) && mode
->mode
== MODE_IEEE80211B
))
391 while (i
< mode
->num_channels
&& c
< IW_MAX_FREQUENCIES
) {
392 struct ieee80211_channel
*chan
= &mode
->channels
[i
];
394 if (chan
->flag
& IEEE80211_CHAN_W_SCAN
) {
395 range
->freq
[c
].i
= chan
->chan
;
396 range
->freq
[c
].m
= chan
->freq
* 100000;
397 range
->freq
[c
].e
= 1;
403 range
->num_channels
= c
;
404 range
->num_frequency
= c
;
406 IW_EVENT_CAPA_SET_KERNEL(range
->event_capa
);
407 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWTHRSPY
);
408 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWAP
);
409 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWSCAN
);
415 struct ieee80211_channel_range
{
418 unsigned char power_level
;
419 unsigned char antenna_max
;
422 static const struct ieee80211_channel_range ieee80211_fcc_channels
[] = {
423 { 2412, 2462, 27, 6 } /* IEEE 802.11b/g, channels 1..11 */,
424 { 5180, 5240, 17, 6 } /* IEEE 802.11a, channels 36..48 */,
425 { 5260, 5320, 23, 6 } /* IEEE 802.11a, channels 52..64 */,
426 { 5745, 5825, 30, 6 } /* IEEE 802.11a, channels 149..165, outdoor */,
430 static const struct ieee80211_channel_range ieee80211_mkk_channels
[] = {
431 { 2412, 2472, 20, 6 } /* IEEE 802.11b/g, channels 1..13 */,
432 { 5170, 5240, 20, 6 } /* IEEE 802.11a, channels 34..48 */,
433 { 5260, 5320, 20, 6 } /* IEEE 802.11a, channels 52..64 */,
438 static const struct ieee80211_channel_range
*channel_range
=
439 ieee80211_fcc_channels
;
442 static void ieee80211_unmask_channel(struct net_device
*dev
, int mode
,
443 struct ieee80211_channel
*chan
)
449 if (ieee80211_regdom
== 64 &&
450 (mode
== MODE_ATHEROS_TURBO
|| mode
== MODE_ATHEROS_TURBOG
)) {
451 /* Do not allow Turbo modes in Japan. */
455 for (i
= 0; channel_range
[i
].start_freq
; i
++) {
456 const struct ieee80211_channel_range
*r
= &channel_range
[i
];
457 if (r
->start_freq
<= chan
->freq
&& r
->end_freq
>= chan
->freq
) {
458 if (ieee80211_regdom
== 64 && !ieee80211_japan_5ghz
&&
459 chan
->freq
>= 5260 && chan
->freq
<= 5320) {
461 * Skip new channels in Japan since the
462 * firmware was not marked having been upgraded
468 if (ieee80211_regdom
== 0x10 &&
469 (chan
->freq
== 5190 || chan
->freq
== 5210 ||
470 chan
->freq
== 5230)) {
471 /* Skip MKK channels when in FCC domain. */
475 chan
->flag
|= IEEE80211_CHAN_W_SCAN
|
476 IEEE80211_CHAN_W_ACTIVE_SCAN
|
477 IEEE80211_CHAN_W_IBSS
;
478 chan
->power_level
= r
->power_level
;
479 chan
->antenna_max
= r
->antenna_max
;
481 if (ieee80211_regdom
== 64 &&
482 (chan
->freq
== 5170 || chan
->freq
== 5190 ||
483 chan
->freq
== 5210 || chan
->freq
== 5230)) {
485 * New regulatory rules in Japan have backwards
486 * compatibility with old channels in 5.15-5.25
487 * GHz band, but the station is not allowed to
488 * use active scan on these old channels.
490 chan
->flag
&= ~IEEE80211_CHAN_W_ACTIVE_SCAN
;
493 if (ieee80211_regdom
== 64 &&
494 (chan
->freq
== 5260 || chan
->freq
== 5280 ||
495 chan
->freq
== 5300 || chan
->freq
== 5320)) {
497 * IBSS is not allowed on 5.25-5.35 GHz band
498 * due to radar detection requirements.
500 chan
->flag
&= ~IEEE80211_CHAN_W_IBSS
;
509 static int ieee80211_unmask_channels(struct net_device
*dev
)
511 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
512 struct ieee80211_hw_mode
*mode
;
515 list_for_each_entry(mode
, &local
->modes_list
, list
) {
516 for (c
= 0; c
< mode
->num_channels
; c
++) {
517 ieee80211_unmask_channel(dev
, mode
->mode
,
525 int ieee80211_init_client(struct net_device
*dev
)
527 if (ieee80211_regdom
== 0x40)
528 channel_range
= ieee80211_mkk_channels
;
529 ieee80211_unmask_channels(dev
);
534 static int ieee80211_ioctl_siwmode(struct net_device
*dev
,
535 struct iw_request_info
*info
,
536 __u32
*mode
, char *extra
)
538 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
541 if (sdata
->type
== IEEE80211_IF_TYPE_VLAN
)
546 type
= IEEE80211_IF_TYPE_STA
;
549 type
= IEEE80211_IF_TYPE_IBSS
;
551 case IW_MODE_MONITOR
:
552 type
= IEEE80211_IF_TYPE_MNTR
;
558 if (type
== sdata
->type
)
560 if (netif_running(dev
))
563 ieee80211_if_reinit(dev
);
564 ieee80211_if_set_type(dev
, type
);
570 static int ieee80211_ioctl_giwmode(struct net_device
*dev
,
571 struct iw_request_info
*info
,
572 __u32
*mode
, char *extra
)
574 struct ieee80211_sub_if_data
*sdata
;
576 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
577 switch (sdata
->type
) {
578 case IEEE80211_IF_TYPE_AP
:
579 *mode
= IW_MODE_MASTER
;
581 case IEEE80211_IF_TYPE_STA
:
582 *mode
= IW_MODE_INFRA
;
584 case IEEE80211_IF_TYPE_IBSS
:
585 *mode
= IW_MODE_ADHOC
;
587 case IEEE80211_IF_TYPE_MNTR
:
588 *mode
= IW_MODE_MONITOR
;
590 case IEEE80211_IF_TYPE_WDS
:
591 *mode
= IW_MODE_REPEAT
;
593 case IEEE80211_IF_TYPE_VLAN
:
594 *mode
= IW_MODE_SECOND
; /* FIXME */
597 *mode
= IW_MODE_AUTO
;
603 int ieee80211_set_channel(struct ieee80211_local
*local
, int channel
, int freq
)
605 struct ieee80211_hw_mode
*mode
;
609 list_for_each_entry(mode
, &local
->modes_list
, list
) {
610 if (!(local
->enabled_modes
& (1 << mode
->mode
)))
612 for (c
= 0; c
< mode
->num_channels
; c
++) {
613 struct ieee80211_channel
*chan
= &mode
->channels
[c
];
614 if (chan
->flag
& IEEE80211_CHAN_W_SCAN
&&
615 ((chan
->chan
== channel
) || (chan
->freq
== freq
))) {
616 /* Use next_mode as the mode preference to
617 * resolve non-unique channel numbers. */
618 if (set
&& mode
->mode
!= local
->next_mode
)
621 local
->oper_channel
= chan
;
622 local
->oper_hw_mode
= mode
;
629 if (local
->sta_scanning
)
632 ret
= ieee80211_hw_config(local
);
634 rate_control_clear(local
);
640 static int ieee80211_ioctl_siwfreq(struct net_device
*dev
,
641 struct iw_request_info
*info
,
642 struct iw_freq
*freq
, char *extra
)
644 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
645 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
647 if (sdata
->type
== IEEE80211_IF_TYPE_STA
)
648 sdata
->u
.sta
.auto_channel_sel
= 0;
650 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
653 if (sdata
->type
== IEEE80211_IF_TYPE_STA
)
654 sdata
->u
.sta
.auto_channel_sel
= 1;
657 return ieee80211_set_channel(local
, freq
->m
, -1);
659 int i
, div
= 1000000;
660 for (i
= 0; i
< freq
->e
; i
++)
663 return ieee80211_set_channel(local
, -1, freq
->m
/ div
);
670 static int ieee80211_ioctl_giwfreq(struct net_device
*dev
,
671 struct iw_request_info
*info
,
672 struct iw_freq
*freq
, char *extra
)
674 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
676 /* TODO: in station mode (Managed/Ad-hoc) might need to poll low-level
677 * driver for the current channel with firmware-based management */
679 freq
->m
= local
->hw
.conf
.freq
;
686 static int ieee80211_ioctl_siwessid(struct net_device
*dev
,
687 struct iw_request_info
*info
,
688 struct iw_point
*data
, char *ssid
)
690 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
691 struct ieee80211_sub_if_data
*sdata
;
692 size_t len
= data
->length
;
694 /* iwconfig uses nul termination in SSID.. */
695 if (len
> 0 && ssid
[len
- 1] == '\0')
698 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
699 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
700 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
702 if (local
->user_space_mlme
) {
703 if (len
> IEEE80211_MAX_SSID_LEN
)
705 memcpy(sdata
->u
.sta
.ssid
, ssid
, len
);
706 sdata
->u
.sta
.ssid_len
= len
;
709 sdata
->u
.sta
.auto_ssid_sel
= !data
->flags
;
710 ret
= ieee80211_sta_set_ssid(dev
, ssid
, len
);
713 ieee80211_sta_req_auth(dev
, &sdata
->u
.sta
);
717 if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
718 memcpy(sdata
->u
.ap
.ssid
, ssid
, len
);
719 memset(sdata
->u
.ap
.ssid
+ len
, 0,
720 IEEE80211_MAX_SSID_LEN
- len
);
721 sdata
->u
.ap
.ssid_len
= len
;
722 return ieee80211_if_config(dev
);
728 static int ieee80211_ioctl_giwessid(struct net_device
*dev
,
729 struct iw_request_info
*info
,
730 struct iw_point
*data
, char *ssid
)
734 struct ieee80211_sub_if_data
*sdata
;
735 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
736 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
737 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
738 int res
= ieee80211_sta_get_ssid(dev
, ssid
, &len
);
747 if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
748 len
= sdata
->u
.ap
.ssid_len
;
749 if (len
> IW_ESSID_MAX_SIZE
)
750 len
= IW_ESSID_MAX_SIZE
;
751 memcpy(ssid
, sdata
->u
.ap
.ssid
, len
);
760 static int ieee80211_ioctl_siwap(struct net_device
*dev
,
761 struct iw_request_info
*info
,
762 struct sockaddr
*ap_addr
, char *extra
)
764 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
765 struct ieee80211_sub_if_data
*sdata
;
767 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
768 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
769 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
771 if (local
->user_space_mlme
) {
772 memcpy(sdata
->u
.sta
.bssid
, (u8
*) &ap_addr
->sa_data
,
776 if (is_zero_ether_addr((u8
*) &ap_addr
->sa_data
)) {
777 sdata
->u
.sta
.auto_bssid_sel
= 1;
778 sdata
->u
.sta
.auto_channel_sel
= 1;
779 } else if (is_broadcast_ether_addr((u8
*) &ap_addr
->sa_data
))
780 sdata
->u
.sta
.auto_bssid_sel
= 1;
782 sdata
->u
.sta
.auto_bssid_sel
= 0;
783 ret
= ieee80211_sta_set_bssid(dev
, (u8
*) &ap_addr
->sa_data
);
786 ieee80211_sta_req_auth(dev
, &sdata
->u
.sta
);
788 } else if (sdata
->type
== IEEE80211_IF_TYPE_WDS
) {
789 if (memcmp(sdata
->u
.wds
.remote_addr
, (u8
*) &ap_addr
->sa_data
,
792 return ieee80211_if_update_wds(dev
, (u8
*) &ap_addr
->sa_data
);
799 static int ieee80211_ioctl_giwap(struct net_device
*dev
,
800 struct iw_request_info
*info
,
801 struct sockaddr
*ap_addr
, char *extra
)
803 struct ieee80211_sub_if_data
*sdata
;
805 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
806 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
807 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
808 ap_addr
->sa_family
= ARPHRD_ETHER
;
809 memcpy(&ap_addr
->sa_data
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
811 } else if (sdata
->type
== IEEE80211_IF_TYPE_WDS
) {
812 ap_addr
->sa_family
= ARPHRD_ETHER
;
813 memcpy(&ap_addr
->sa_data
, sdata
->u
.wds
.remote_addr
, ETH_ALEN
);
821 static int ieee80211_ioctl_siwscan(struct net_device
*dev
,
822 struct iw_request_info
*info
,
823 struct iw_point
*data
, char *extra
)
825 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
826 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
830 if (!netif_running(dev
))
833 if (local
->scan_flags
& IEEE80211_SCAN_MATCH_SSID
) {
834 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
835 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
836 ssid
= sdata
->u
.sta
.ssid
;
837 ssid_len
= sdata
->u
.sta
.ssid_len
;
838 } else if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
839 ssid
= sdata
->u
.ap
.ssid
;
840 ssid_len
= sdata
->u
.ap
.ssid_len
;
844 return ieee80211_sta_req_scan(dev
, ssid
, ssid_len
);
848 static int ieee80211_ioctl_giwscan(struct net_device
*dev
,
849 struct iw_request_info
*info
,
850 struct iw_point
*data
, char *extra
)
853 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
854 if (local
->sta_scanning
)
856 res
= ieee80211_sta_scan_results(dev
, extra
, data
->length
);
866 static int ieee80211_ioctl_siwrate(struct net_device
*dev
,
867 struct iw_request_info
*info
,
868 struct iw_param
*rate
, char *extra
)
870 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
871 struct ieee80211_hw_mode
*mode
;
873 u32 target_rate
= rate
->value
/ 100000;
874 struct ieee80211_sub_if_data
*sdata
;
876 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
879 mode
= local
->oper_hw_mode
;
880 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
881 * target_rate = X, rate->fixed = 1 means only rate X
882 * target_rate = X, rate->fixed = 0 means all rates <= X */
883 sdata
->bss
->max_ratectrl_rateidx
= -1;
884 sdata
->bss
->force_unicast_rateidx
= -1;
887 for (i
=0; i
< mode
->num_rates
; i
++) {
888 struct ieee80211_rate
*rates
= &mode
->rates
[i
];
889 int this_rate
= rates
->rate
;
891 if (mode
->mode
== MODE_ATHEROS_TURBO
||
892 mode
->mode
== MODE_ATHEROS_TURBOG
)
894 if (target_rate
== this_rate
) {
895 sdata
->bss
->max_ratectrl_rateidx
= i
;
897 sdata
->bss
->force_unicast_rateidx
= i
;
904 static int ieee80211_ioctl_giwrate(struct net_device
*dev
,
905 struct iw_request_info
*info
,
906 struct iw_param
*rate
, char *extra
)
908 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
909 struct sta_info
*sta
;
910 struct ieee80211_sub_if_data
*sdata
;
912 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
913 if (sdata
->type
== IEEE80211_IF_TYPE_STA
)
914 sta
= sta_info_get(local
, sdata
->u
.sta
.bssid
);
919 if (sta
->txrate
< local
->oper_hw_mode
->num_rates
)
920 rate
->value
= local
->oper_hw_mode
->rates
[sta
->txrate
].rate
* 100000;
927 static int ieee80211_ioctl_siwrts(struct net_device
*dev
,
928 struct iw_request_info
*info
,
929 struct iw_param
*rts
, char *extra
)
931 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
934 local
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
935 else if (rts
->value
< 0 || rts
->value
> IEEE80211_MAX_RTS_THRESHOLD
)
938 local
->rts_threshold
= rts
->value
;
940 /* If the wlan card performs RTS/CTS in hardware/firmware,
941 * configure it here */
943 if (local
->ops
->set_rts_threshold
)
944 local
->ops
->set_rts_threshold(local_to_hw(local
),
945 local
->rts_threshold
);
950 static int ieee80211_ioctl_giwrts(struct net_device
*dev
,
951 struct iw_request_info
*info
,
952 struct iw_param
*rts
, char *extra
)
954 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
956 rts
->value
= local
->rts_threshold
;
957 rts
->disabled
= (rts
->value
>= IEEE80211_MAX_RTS_THRESHOLD
);
964 static int ieee80211_ioctl_siwfrag(struct net_device
*dev
,
965 struct iw_request_info
*info
,
966 struct iw_param
*frag
, char *extra
)
968 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
971 local
->fragmentation_threshold
= IEEE80211_MAX_FRAG_THRESHOLD
;
972 else if (frag
->value
< 256 ||
973 frag
->value
> IEEE80211_MAX_FRAG_THRESHOLD
)
976 /* Fragment length must be even, so strip LSB. */
977 local
->fragmentation_threshold
= frag
->value
& ~0x1;
980 /* If the wlan card performs fragmentation in hardware/firmware,
981 * configure it here */
983 if (local
->ops
->set_frag_threshold
)
984 local
->ops
->set_frag_threshold(
986 local
->fragmentation_threshold
);
991 static int ieee80211_ioctl_giwfrag(struct net_device
*dev
,
992 struct iw_request_info
*info
,
993 struct iw_param
*frag
, char *extra
)
995 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
997 frag
->value
= local
->fragmentation_threshold
;
998 frag
->disabled
= (frag
->value
>= IEEE80211_MAX_RTS_THRESHOLD
);
1005 static int ieee80211_ioctl_siwretry(struct net_device
*dev
,
1006 struct iw_request_info
*info
,
1007 struct iw_param
*retry
, char *extra
)
1009 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1011 if (retry
->disabled
||
1012 (retry
->flags
& IW_RETRY_TYPE
) != IW_RETRY_LIMIT
)
1015 if (retry
->flags
& IW_RETRY_MAX
)
1016 local
->long_retry_limit
= retry
->value
;
1017 else if (retry
->flags
& IW_RETRY_MIN
)
1018 local
->short_retry_limit
= retry
->value
;
1020 local
->long_retry_limit
= retry
->value
;
1021 local
->short_retry_limit
= retry
->value
;
1024 if (local
->ops
->set_retry_limit
) {
1025 return local
->ops
->set_retry_limit(
1027 local
->short_retry_limit
,
1028 local
->long_retry_limit
);
1035 static int ieee80211_ioctl_giwretry(struct net_device
*dev
,
1036 struct iw_request_info
*info
,
1037 struct iw_param
*retry
, char *extra
)
1039 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1041 retry
->disabled
= 0;
1042 if (retry
->flags
== 0 || retry
->flags
& IW_RETRY_MIN
) {
1043 /* first return min value, iwconfig will ask max value
1044 * later if needed */
1045 retry
->flags
|= IW_RETRY_LIMIT
;
1046 retry
->value
= local
->short_retry_limit
;
1047 if (local
->long_retry_limit
!= local
->short_retry_limit
)
1048 retry
->flags
|= IW_RETRY_MIN
;
1051 if (retry
->flags
& IW_RETRY_MAX
) {
1052 retry
->flags
= IW_RETRY_LIMIT
| IW_RETRY_MAX
;
1053 retry
->value
= local
->long_retry_limit
;
1059 static void ieee80211_key_enable_hwaccel(struct ieee80211_local
*local
,
1060 struct ieee80211_key
*key
)
1062 struct ieee80211_key_conf
*keyconf
;
1065 if (!key
|| key
->alg
!= ALG_WEP
|| !key
->force_sw_encrypt
||
1066 (local
->hw
.flags
& IEEE80211_HW_DEVICE_HIDES_WEP
))
1069 memset(addr
, 0xff, ETH_ALEN
);
1070 keyconf
= ieee80211_key_data2conf(local
, key
);
1071 if (keyconf
&& local
->ops
->set_key
&&
1072 local
->ops
->set_key(local_to_hw(local
),
1073 SET_KEY
, addr
, keyconf
, 0) == 0) {
1074 key
->force_sw_encrypt
=
1075 !!(keyconf
->flags
& IEEE80211_KEY_FORCE_SW_ENCRYPT
);
1076 key
->hw_key_idx
= keyconf
->hw_key_idx
;
1082 static void ieee80211_key_disable_hwaccel(struct ieee80211_local
*local
,
1083 struct ieee80211_key
*key
)
1085 struct ieee80211_key_conf
*keyconf
;
1088 if (!key
|| key
->alg
!= ALG_WEP
|| key
->force_sw_encrypt
||
1089 (local
->hw
.flags
& IEEE80211_HW_DEVICE_HIDES_WEP
))
1092 memset(addr
, 0xff, ETH_ALEN
);
1093 keyconf
= ieee80211_key_data2conf(local
, key
);
1094 if (keyconf
&& local
->ops
->set_key
)
1095 local
->ops
->set_key(local_to_hw(local
), DISABLE_KEY
,
1098 key
->force_sw_encrypt
= 1;
1102 static int ieee80211_ioctl_default_wep_only(struct ieee80211_local
*local
,
1106 struct ieee80211_sub_if_data
*sdata
;
1108 local
->default_wep_only
= value
;
1109 read_lock(&local
->sub_if_lock
);
1110 list_for_each_entry(sdata
, &local
->sub_if_list
, list
)
1111 for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++)
1113 ieee80211_key_enable_hwaccel(local
,
1116 ieee80211_key_disable_hwaccel(local
,
1118 read_unlock(&local
->sub_if_lock
);
1124 void ieee80211_update_default_wep_only(struct ieee80211_local
*local
)
1127 struct ieee80211_sub_if_data
*sdata
;
1129 read_lock(&local
->sub_if_lock
);
1130 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
1132 if (sdata
->dev
== local
->mdev
)
1135 /* If there is an AP interface then depend on userspace to
1136 set default_wep_only correctly. */
1137 if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
1138 read_unlock(&local
->sub_if_lock
);
1145 read_unlock(&local
->sub_if_lock
);
1148 ieee80211_ioctl_default_wep_only(local
, 1);
1150 ieee80211_ioctl_default_wep_only(local
, 0);
1154 static int ieee80211_ioctl_prism2_param(struct net_device
*dev
,
1155 struct iw_request_info
*info
,
1156 void *wrqu
, char *extra
)
1158 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1159 struct ieee80211_sub_if_data
*sdata
;
1160 int *i
= (int *) extra
;
1162 int value
= *(i
+ 1);
1165 if (!capable(CAP_NET_ADMIN
))
1168 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1171 case PRISM2_PARAM_IEEE_802_1X
:
1172 if (local
->ops
->set_ieee8021x
)
1173 ret
= local
->ops
->set_ieee8021x(local_to_hw(local
),
1176 printk(KERN_DEBUG
"%s: failed to set IEEE 802.1X (%d) "
1177 "for low-level driver\n", dev
->name
, value
);
1179 sdata
->ieee802_1x
= value
;
1182 case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES
:
1183 if (sdata
->type
!= IEEE80211_IF_TYPE_AP
)
1186 sdata
->use_protection
= value
;
1189 case PRISM2_PARAM_PREAMBLE
:
1190 local
->short_preamble
= value
;
1193 case PRISM2_PARAM_STAT_TIME
:
1194 if (!local
->stat_time
&& value
) {
1195 local
->stat_timer
.expires
= jiffies
+ HZ
* value
/ 100;
1196 add_timer(&local
->stat_timer
);
1197 } else if (local
->stat_time
&& !value
) {
1198 del_timer_sync(&local
->stat_timer
);
1200 local
->stat_time
= value
;
1202 case PRISM2_PARAM_SHORT_SLOT_TIME
:
1204 local
->hw
.conf
.flags
|= IEEE80211_CONF_SHORT_SLOT_TIME
;
1206 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_SHORT_SLOT_TIME
;
1207 if (ieee80211_hw_config(local
))
1211 case PRISM2_PARAM_NEXT_MODE
:
1212 local
->next_mode
= value
;
1215 case PRISM2_PARAM_RADIO_ENABLED
:
1216 ret
= ieee80211_ioctl_set_radio_enabled(dev
, value
);
1219 case PRISM2_PARAM_ANTENNA_MODE
:
1220 local
->hw
.conf
.antenna_mode
= value
;
1221 if (ieee80211_hw_config(local
))
1225 case PRISM2_PARAM_STA_ANTENNA_SEL
:
1226 local
->sta_antenna_sel
= value
;
1229 case PRISM2_PARAM_TX_POWER_REDUCTION
:
1233 local
->hw
.conf
.tx_power_reduction
= value
;
1236 case PRISM2_PARAM_KEY_TX_RX_THRESHOLD
:
1237 local
->key_tx_rx_threshold
= value
;
1240 case PRISM2_PARAM_DEFAULT_WEP_ONLY
:
1241 ret
= ieee80211_ioctl_default_wep_only(local
, value
);
1244 case PRISM2_PARAM_WIFI_WME_NOACK_TEST
:
1245 local
->wifi_wme_noack_test
= value
;
1248 case PRISM2_PARAM_SCAN_FLAGS
:
1249 local
->scan_flags
= value
;
1252 case PRISM2_PARAM_MIXED_CELL
:
1253 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
1254 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
1257 sdata
->u
.sta
.mixed_cell
= !!value
;
1260 case PRISM2_PARAM_HW_MODES
:
1261 local
->enabled_modes
= value
;
1264 case PRISM2_PARAM_CREATE_IBSS
:
1265 if (sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
1268 sdata
->u
.sta
.create_ibss
= !!value
;
1270 case PRISM2_PARAM_WMM_ENABLED
:
1271 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
1272 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
1275 sdata
->u
.sta
.wmm_enabled
= !!value
;
1277 case PRISM2_PARAM_RADAR_DETECT
:
1278 local
->hw
.conf
.radar_detect
= value
;
1280 case PRISM2_PARAM_SPECTRUM_MGMT
:
1281 local
->hw
.conf
.spect_mgmt
= value
;
1292 static int ieee80211_ioctl_get_prism2_param(struct net_device
*dev
,
1293 struct iw_request_info
*info
,
1294 void *wrqu
, char *extra
)
1296 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1297 struct ieee80211_sub_if_data
*sdata
;
1298 int *param
= (int *) extra
;
1301 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1304 case PRISM2_PARAM_IEEE_802_1X
:
1305 *param
= sdata
->ieee802_1x
;
1308 case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES
:
1309 *param
= sdata
->use_protection
;
1312 case PRISM2_PARAM_PREAMBLE
:
1313 *param
= local
->short_preamble
;
1316 case PRISM2_PARAM_STAT_TIME
:
1317 *param
= local
->stat_time
;
1319 case PRISM2_PARAM_SHORT_SLOT_TIME
:
1320 *param
= !!(local
->hw
.conf
.flags
& IEEE80211_CONF_SHORT_SLOT_TIME
);
1323 case PRISM2_PARAM_NEXT_MODE
:
1324 *param
= local
->next_mode
;
1327 case PRISM2_PARAM_ANTENNA_MODE
:
1328 *param
= local
->hw
.conf
.antenna_mode
;
1331 case PRISM2_PARAM_STA_ANTENNA_SEL
:
1332 *param
= local
->sta_antenna_sel
;
1335 case PRISM2_PARAM_TX_POWER_REDUCTION
:
1336 *param
= local
->hw
.conf
.tx_power_reduction
;
1339 case PRISM2_PARAM_KEY_TX_RX_THRESHOLD
:
1340 *param
= local
->key_tx_rx_threshold
;
1343 case PRISM2_PARAM_DEFAULT_WEP_ONLY
:
1344 *param
= local
->default_wep_only
;
1347 case PRISM2_PARAM_WIFI_WME_NOACK_TEST
:
1348 *param
= local
->wifi_wme_noack_test
;
1351 case PRISM2_PARAM_SCAN_FLAGS
:
1352 *param
= local
->scan_flags
;
1355 case PRISM2_PARAM_HW_MODES
:
1356 *param
= local
->enabled_modes
;
1359 case PRISM2_PARAM_CREATE_IBSS
:
1360 if (sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
1363 *param
= !!sdata
->u
.sta
.create_ibss
;
1366 case PRISM2_PARAM_MIXED_CELL
:
1367 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
1368 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
1371 *param
= !!sdata
->u
.sta
.mixed_cell
;
1373 case PRISM2_PARAM_WMM_ENABLED
:
1374 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
1375 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
1378 *param
= !!sdata
->u
.sta
.wmm_enabled
;
1388 static int ieee80211_ioctl_siwmlme(struct net_device
*dev
,
1389 struct iw_request_info
*info
,
1390 struct iw_point
*data
, char *extra
)
1392 struct ieee80211_sub_if_data
*sdata
;
1393 struct iw_mlme
*mlme
= (struct iw_mlme
*) extra
;
1395 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1396 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
1397 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
1400 switch (mlme
->cmd
) {
1401 case IW_MLME_DEAUTH
:
1402 /* TODO: mlme->addr.sa_data */
1403 return ieee80211_sta_deauthenticate(dev
, mlme
->reason_code
);
1404 case IW_MLME_DISASSOC
:
1405 /* TODO: mlme->addr.sa_data */
1406 return ieee80211_sta_disassociate(dev
, mlme
->reason_code
);
1413 static int ieee80211_ioctl_siwencode(struct net_device
*dev
,
1414 struct iw_request_info
*info
,
1415 struct iw_point
*erq
, char *keybuf
)
1417 struct ieee80211_sub_if_data
*sdata
;
1418 int idx
, i
, alg
= ALG_WEP
;
1419 u8 bcaddr
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1421 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1423 idx
= erq
->flags
& IW_ENCODE_INDEX
;
1425 if (sdata
->default_key
)
1426 for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
1427 if (sdata
->default_key
== sdata
->keys
[i
]) {
1432 } else if (idx
< 1 || idx
> 4)
1437 if (erq
->flags
& IW_ENCODE_DISABLED
)
1439 else if (erq
->length
== 0) {
1440 /* No key data - just set the default TX key index */
1441 if (sdata
->default_key
!= sdata
->keys
[idx
]) {
1442 ieee80211_debugfs_key_remove_default(sdata
);
1443 sdata
->default_key
= sdata
->keys
[idx
];
1444 if (sdata
->default_key
)
1445 ieee80211_debugfs_key_add_default(sdata
);
1450 return ieee80211_set_encryption(
1453 !sdata
->default_key
,
1454 keybuf
, erq
->length
);
1458 static int ieee80211_ioctl_giwencode(struct net_device
*dev
,
1459 struct iw_request_info
*info
,
1460 struct iw_point
*erq
, char *key
)
1462 struct ieee80211_sub_if_data
*sdata
;
1465 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1467 idx
= erq
->flags
& IW_ENCODE_INDEX
;
1468 if (idx
< 1 || idx
> 4) {
1470 if (!sdata
->default_key
)
1472 else for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
1473 if (sdata
->default_key
== sdata
->keys
[i
]) {
1483 erq
->flags
= idx
+ 1;
1485 if (!sdata
->keys
[idx
]) {
1487 erq
->flags
|= IW_ENCODE_DISABLED
;
1491 memcpy(key
, sdata
->keys
[idx
]->key
,
1492 min((int)erq
->length
, sdata
->keys
[idx
]->keylen
));
1493 erq
->length
= sdata
->keys
[idx
]->keylen
;
1494 erq
->flags
|= IW_ENCODE_ENABLED
;
1499 static int ieee80211_ioctl_siwauth(struct net_device
*dev
,
1500 struct iw_request_info
*info
,
1501 struct iw_param
*data
, char *extra
)
1503 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1504 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1507 switch (data
->flags
& IW_AUTH_INDEX
) {
1508 case IW_AUTH_WPA_VERSION
:
1509 case IW_AUTH_CIPHER_PAIRWISE
:
1510 case IW_AUTH_CIPHER_GROUP
:
1511 case IW_AUTH_WPA_ENABLED
:
1512 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
1514 case IW_AUTH_KEY_MGMT
:
1515 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
1519 * TODO: sdata->u.sta.key_mgmt does not match with WE18
1520 * value completely; could consider modifying this to
1521 * be closer to WE18. For now, this value is not really
1522 * used for anything else than Privacy matching, so the
1523 * current code here should be more or less OK.
1525 if (data
->value
& IW_AUTH_KEY_MGMT_802_1X
) {
1526 sdata
->u
.sta
.key_mgmt
=
1527 IEEE80211_KEY_MGMT_WPA_EAP
;
1528 } else if (data
->value
& IW_AUTH_KEY_MGMT_PSK
) {
1529 sdata
->u
.sta
.key_mgmt
=
1530 IEEE80211_KEY_MGMT_WPA_PSK
;
1532 sdata
->u
.sta
.key_mgmt
=
1533 IEEE80211_KEY_MGMT_NONE
;
1537 case IW_AUTH_80211_AUTH_ALG
:
1538 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
1539 sdata
->type
== IEEE80211_IF_TYPE_IBSS
)
1540 sdata
->u
.sta
.auth_algs
= data
->value
;
1544 case IW_AUTH_PRIVACY_INVOKED
:
1545 if (local
->ops
->set_privacy_invoked
)
1546 ret
= local
->ops
->set_privacy_invoked(
1547 local_to_hw(local
), data
->value
);
1556 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
1557 static struct iw_statistics
*ieee80211_get_wireless_stats(struct net_device
*dev
)
1559 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1560 struct iw_statistics
*wstats
= &local
->wstats
;
1561 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1562 struct sta_info
*sta
= NULL
;
1564 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
1565 sdata
->type
== IEEE80211_IF_TYPE_IBSS
)
1566 sta
= sta_info_get(local
, sdata
->u
.sta
.bssid
);
1568 wstats
->discard
.fragment
= 0;
1569 wstats
->discard
.misc
= 0;
1570 wstats
->qual
.qual
= 0;
1571 wstats
->qual
.level
= 0;
1572 wstats
->qual
.noise
= 0;
1573 wstats
->qual
.updated
= IW_QUAL_ALL_INVALID
;
1575 wstats
->qual
.level
= sta
->last_rssi
;
1576 wstats
->qual
.qual
= sta
->last_signal
;
1577 wstats
->qual
.noise
= sta
->last_noise
;
1578 wstats
->qual
.updated
= local
->wstats_flags
;
1584 static int ieee80211_ioctl_giwauth(struct net_device
*dev
,
1585 struct iw_request_info
*info
,
1586 struct iw_param
*data
, char *extra
)
1588 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1591 switch (data
->flags
& IW_AUTH_INDEX
) {
1592 case IW_AUTH_80211_AUTH_ALG
:
1593 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
1594 sdata
->type
== IEEE80211_IF_TYPE_IBSS
)
1595 data
->value
= sdata
->u
.sta
.auth_algs
;
1607 static int ieee80211_ioctl_siwencodeext(struct net_device
*dev
,
1608 struct iw_request_info
*info
,
1609 struct iw_point
*erq
, char *extra
)
1611 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1612 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*) extra
;
1616 case IW_ENCODE_ALG_NONE
:
1619 case IW_ENCODE_ALG_WEP
:
1622 case IW_ENCODE_ALG_TKIP
:
1625 case IW_ENCODE_ALG_CCMP
:
1632 if (erq
->flags
& IW_ENCODE_DISABLED
)
1635 idx
= erq
->flags
& IW_ENCODE_INDEX
;
1636 if (idx
< 1 || idx
> 4) {
1638 if (!sdata
->default_key
)
1640 else for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
1641 if (sdata
->default_key
== sdata
->keys
[i
]) {
1651 return ieee80211_set_encryption(dev
, ext
->addr
.sa_data
, idx
, alg
,
1653 IW_ENCODE_EXT_SET_TX_KEY
,
1654 ext
->key
, ext
->key_len
);
1658 static const struct iw_priv_args ieee80211_ioctl_priv
[] = {
1659 { PRISM2_IOCTL_PRISM2_PARAM
,
1660 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 2, 0, "param" },
1661 { PRISM2_IOCTL_GET_PRISM2_PARAM
,
1662 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
1663 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1, "get_param" },
1666 /* Structures to export the Wireless Handlers */
1668 static const iw_handler ieee80211_handler
[] =
1670 (iw_handler
) NULL
, /* SIOCSIWCOMMIT */
1671 (iw_handler
) ieee80211_ioctl_giwname
, /* SIOCGIWNAME */
1672 (iw_handler
) NULL
, /* SIOCSIWNWID */
1673 (iw_handler
) NULL
, /* SIOCGIWNWID */
1674 (iw_handler
) ieee80211_ioctl_siwfreq
, /* SIOCSIWFREQ */
1675 (iw_handler
) ieee80211_ioctl_giwfreq
, /* SIOCGIWFREQ */
1676 (iw_handler
) ieee80211_ioctl_siwmode
, /* SIOCSIWMODE */
1677 (iw_handler
) ieee80211_ioctl_giwmode
, /* SIOCGIWMODE */
1678 (iw_handler
) NULL
, /* SIOCSIWSENS */
1679 (iw_handler
) NULL
, /* SIOCGIWSENS */
1680 (iw_handler
) NULL
/* not used */, /* SIOCSIWRANGE */
1681 (iw_handler
) ieee80211_ioctl_giwrange
, /* SIOCGIWRANGE */
1682 (iw_handler
) NULL
/* not used */, /* SIOCSIWPRIV */
1683 (iw_handler
) NULL
/* kernel code */, /* SIOCGIWPRIV */
1684 (iw_handler
) NULL
/* not used */, /* SIOCSIWSTATS */
1685 (iw_handler
) NULL
/* kernel code */, /* SIOCGIWSTATS */
1686 iw_handler_set_spy
, /* SIOCSIWSPY */
1687 iw_handler_get_spy
, /* SIOCGIWSPY */
1688 iw_handler_set_thrspy
, /* SIOCSIWTHRSPY */
1689 iw_handler_get_thrspy
, /* SIOCGIWTHRSPY */
1690 (iw_handler
) ieee80211_ioctl_siwap
, /* SIOCSIWAP */
1691 (iw_handler
) ieee80211_ioctl_giwap
, /* SIOCGIWAP */
1692 (iw_handler
) ieee80211_ioctl_siwmlme
, /* SIOCSIWMLME */
1693 (iw_handler
) NULL
, /* SIOCGIWAPLIST */
1694 (iw_handler
) ieee80211_ioctl_siwscan
, /* SIOCSIWSCAN */
1695 (iw_handler
) ieee80211_ioctl_giwscan
, /* SIOCGIWSCAN */
1696 (iw_handler
) ieee80211_ioctl_siwessid
, /* SIOCSIWESSID */
1697 (iw_handler
) ieee80211_ioctl_giwessid
, /* SIOCGIWESSID */
1698 (iw_handler
) NULL
, /* SIOCSIWNICKN */
1699 (iw_handler
) NULL
, /* SIOCGIWNICKN */
1700 (iw_handler
) NULL
, /* -- hole -- */
1701 (iw_handler
) NULL
, /* -- hole -- */
1702 (iw_handler
) ieee80211_ioctl_siwrate
, /* SIOCSIWRATE */
1703 (iw_handler
) ieee80211_ioctl_giwrate
, /* SIOCGIWRATE */
1704 (iw_handler
) ieee80211_ioctl_siwrts
, /* SIOCSIWRTS */
1705 (iw_handler
) ieee80211_ioctl_giwrts
, /* SIOCGIWRTS */
1706 (iw_handler
) ieee80211_ioctl_siwfrag
, /* SIOCSIWFRAG */
1707 (iw_handler
) ieee80211_ioctl_giwfrag
, /* SIOCGIWFRAG */
1708 (iw_handler
) NULL
, /* SIOCSIWTXPOW */
1709 (iw_handler
) NULL
, /* SIOCGIWTXPOW */
1710 (iw_handler
) ieee80211_ioctl_siwretry
, /* SIOCSIWRETRY */
1711 (iw_handler
) ieee80211_ioctl_giwretry
, /* SIOCGIWRETRY */
1712 (iw_handler
) ieee80211_ioctl_siwencode
, /* SIOCSIWENCODE */
1713 (iw_handler
) ieee80211_ioctl_giwencode
, /* SIOCGIWENCODE */
1714 (iw_handler
) NULL
, /* SIOCSIWPOWER */
1715 (iw_handler
) NULL
, /* SIOCGIWPOWER */
1716 (iw_handler
) NULL
, /* -- hole -- */
1717 (iw_handler
) NULL
, /* -- hole -- */
1718 (iw_handler
) ieee80211_ioctl_siwgenie
, /* SIOCSIWGENIE */
1719 (iw_handler
) NULL
, /* SIOCGIWGENIE */
1720 (iw_handler
) ieee80211_ioctl_siwauth
, /* SIOCSIWAUTH */
1721 (iw_handler
) ieee80211_ioctl_giwauth
, /* SIOCGIWAUTH */
1722 (iw_handler
) ieee80211_ioctl_siwencodeext
, /* SIOCSIWENCODEEXT */
1723 (iw_handler
) NULL
, /* SIOCGIWENCODEEXT */
1724 (iw_handler
) NULL
, /* SIOCSIWPMKSA */
1725 (iw_handler
) NULL
, /* -- hole -- */
1728 static const iw_handler ieee80211_private_handler
[] =
1729 { /* SIOCIWFIRSTPRIV + */
1730 (iw_handler
) ieee80211_ioctl_prism2_param
, /* 0 */
1731 (iw_handler
) ieee80211_ioctl_get_prism2_param
, /* 1 */
1734 const struct iw_handler_def ieee80211_iw_handler_def
=
1736 .num_standard
= ARRAY_SIZE(ieee80211_handler
),
1737 .num_private
= ARRAY_SIZE(ieee80211_private_handler
),
1738 .num_private_args
= ARRAY_SIZE(ieee80211_ioctl_priv
),
1739 .standard
= (iw_handler
*) ieee80211_handler
,
1740 .private = (iw_handler
*) ieee80211_private_handler
,
1741 .private_args
= (struct iw_priv_args
*) ieee80211_ioctl_priv
,
1742 .get_wireless_stats
= ieee80211_get_wireless_stats
,