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/d80211.h>
23 #include "ieee80211_i.h"
24 #include "hostapd_ioctl.h"
25 #include "ieee80211_rate.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");
45 static int ieee80211_ioctl_set_beacon(struct net_device
*dev
,
46 struct prism2_hostapd_param
*param
,
50 struct ieee80211_sub_if_data
*sdata
;
51 struct ieee80211_if_ap
*ap
;
52 u8
**b_head
, **b_tail
;
53 int *b_head_len
, *b_tail_len
;
56 len
= ((char *) param
->u
.beacon
.data
- (char *) param
) +
57 param
->u
.beacon
.head_len
+ param
->u
.beacon
.tail_len
;
61 else if (param_len
!= len
)
64 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
65 if (sdata
->type
!= IEEE80211_IF_TYPE_AP
)
71 b_head
= &ap
->beacon_head
;
72 b_tail
= &ap
->beacon_tail
;
73 b_head_len
= &ap
->beacon_head_len
;
74 b_tail_len
= &ap
->beacon_tail_len
;
77 printk(KERN_DEBUG
"%s: unknown beacon flag %d\n",
87 *b_head_len
= param
->u
.beacon
.head_len
;
88 *b_tail_len
= param
->u
.beacon
.tail_len
;
90 *b_head
= kmalloc(*b_head_len
, GFP_KERNEL
);
92 memcpy(*b_head
, param
->u
.beacon
.data
, *b_head_len
);
94 printk(KERN_DEBUG
"%s: failed to allocate beacon_head\n",
99 if (*b_tail_len
> 0) {
100 *b_tail
= kmalloc(*b_tail_len
, GFP_KERNEL
);
102 memcpy(*b_tail
, param
->u
.beacon
.data
+ (*b_head_len
),
105 printk(KERN_DEBUG
"%s: failed to allocate "
106 "beacon_tail\n", dev
->name
);
111 return ieee80211_if_config_beacon(dev
);
115 static int ieee80211_ioctl_get_hw_features(struct net_device
*dev
,
116 struct prism2_hostapd_param
*param
,
119 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
120 u8
*pos
= param
->u
.hw_features
.data
;
121 int left
= param_len
- (pos
- (u8
*) param
);
123 struct hostapd_ioctl_hw_modes_hdr
*hdr
;
124 struct ieee80211_rate_data
*rate
;
125 struct ieee80211_channel_data
*chan
;
126 struct ieee80211_hw_mode
*mode
;
128 param
->u
.hw_features
.flags
= 0;
129 if (local
->hw
.flags
& IEEE80211_HW_DATA_NULLFUNC_ACK
)
130 param
->u
.hw_features
.flags
|= HOSTAP_HW_FLAG_NULLFUNC_OK
;
132 param
->u
.hw_features
.num_modes
= 0;
133 list_for_each_entry(mode
, &local
->modes_list
, list
) {
136 param
->u
.hw_features
.num_modes
++;
137 clen
= mode
->num_channels
* sizeof(struct ieee80211_channel_data
);
138 rlen
= mode
->num_rates
* sizeof(struct ieee80211_rate_data
);
139 if (left
< sizeof(*hdr
) + clen
+ rlen
)
141 left
-= sizeof(*hdr
) + clen
+ rlen
;
143 hdr
= (struct hostapd_ioctl_hw_modes_hdr
*) pos
;
144 hdr
->mode
= mode
->mode
;
145 hdr
->num_channels
= mode
->num_channels
;
146 hdr
->num_rates
= mode
->num_rates
;
148 pos
= (u8
*) (hdr
+ 1);
149 chan
= (struct ieee80211_channel_data
*) pos
;
150 for (i
= 0; i
< mode
->num_channels
; i
++) {
151 chan
[i
].chan
= mode
->channels
[i
].chan
;
152 chan
[i
].freq
= mode
->channels
[i
].freq
;
153 chan
[i
].flag
= mode
->channels
[i
].flag
;
157 rate
= (struct ieee80211_rate_data
*) pos
;
158 for (i
= 0; i
< mode
->num_rates
; i
++) {
159 rate
[i
].rate
= mode
->rates
[i
].rate
;
160 rate
[i
].flags
= mode
->rates
[i
].flags
;
169 static int ieee80211_ioctl_scan(struct net_device
*dev
,
170 struct prism2_hostapd_param
*param
)
172 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
174 if (!local
->ops
->passive_scan
)
177 if ((param
->u
.scan
.now
== 1) && (local
->scan
.in_scan
== 1))
180 if (param
->u
.scan
.our_mode_only
>= 0)
181 local
->scan
.our_mode_only
= param
->u
.scan
.our_mode_only
;
182 if (param
->u
.scan
.interval
>= 0)
183 local
->scan
.interval
= param
->u
.scan
.interval
;
184 if (param
->u
.scan
.listen
>= 0)
185 local
->scan
.time
= param
->u
.scan
.listen
;
186 if (param
->u
.scan
.channel
> 0)
187 local
->scan
.channel
= param
->u
.scan
.channel
;
188 if (param
->u
.scan
.now
== 1) {
189 local
->scan
.in_scan
= 0;
190 mod_timer(&local
->scan
.timer
, jiffies
);
193 param
->u
.scan
.our_mode_only
= local
->scan
.our_mode_only
;
194 param
->u
.scan
.interval
= local
->scan
.interval
;
195 param
->u
.scan
.listen
= local
->scan
.time
;
196 if (local
->scan
.in_scan
== 1)
197 param
->u
.scan
.last_rx
= -1;
199 param
->u
.scan
.last_rx
= local
->scan
.rx_packets
;
200 local
->scan
.rx_packets
= -1;
202 param
->u
.scan
.channel
=
203 local
->scan
.mode
->channels
[local
->scan
.chan_idx
].chan
;
209 static int ieee80211_ioctl_flush(struct net_device
*dev
,
210 struct prism2_hostapd_param
*param
)
212 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
213 sta_info_flush(local
, NULL
);
218 /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
219 struct iapp_layer2_update
{
220 u8 da
[ETH_ALEN
]; /* broadcast */
221 u8 sa
[ETH_ALEN
]; /* STA addr */
227 } __attribute__ ((packed
));
229 static void ieee80211_send_layer2_update(struct net_device
*dev
,
232 struct iapp_layer2_update
*msg
;
235 /* Send Level 2 Update Frame to update forwarding tables in layer 2
238 skb
= dev_alloc_skb(sizeof(*msg
));
241 msg
= (struct iapp_layer2_update
*) skb_put(skb
, sizeof(*msg
));
243 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
244 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
246 memset(msg
->da
, 0xff, ETH_ALEN
);
247 memcpy(msg
->sa
, addr
, ETH_ALEN
);
250 msg
->ssap
= 0x01; /* NULL LSAP, CR Bit: Response */
251 msg
->control
= 0xaf; /* XID response lsb.1111F101.
252 * F=0 (no poll command; unsolicited frame) */
253 msg
->xid_info
[0] = 0x81; /* XID format identifier */
254 msg
->xid_info
[1] = 1; /* LLC types/classes: Type 1 LLC */
255 msg
->xid_info
[2] = 0; /* XID sender's receive window size (RW) */
258 skb
->protocol
= eth_type_trans(skb
, dev
);
259 memset(skb
->cb
, 0, sizeof(skb
->cb
));
264 static int ieee80211_ioctl_add_sta(struct net_device
*dev
,
265 struct prism2_hostapd_param
*param
)
267 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
268 struct sta_info
*sta
;
271 struct ieee80211_sub_if_data
*sdata
;
272 int add_key_entry
= 1;
274 /* Prevent a race with changing the rate control algorithm */
275 if (!netif_running(dev
))
278 sta
= sta_info_get(local
, param
->sta_addr
);
281 sta
= sta_info_add(local
, dev
, param
->sta_addr
, GFP_KERNEL
);
286 if (sta
->dev
!= dev
) {
287 /* Binding STA to a new interface, so remove all references to
289 spin_lock_bh(&local
->sta_lock
);
290 sta_info_remove_aid_ptr(sta
);
291 spin_unlock_bh(&local
->sta_lock
);
295 * We "steal" the device in case someone owns it
296 * This will hurt WDS links and such when we have a
297 * WDS link and a client associating from the same station
300 sdata
= IEEE80211_DEV_TO_SUB_IF(sta
->dev
);
302 sta
->flags
|= WLAN_STA_AUTH
| WLAN_STA_ASSOC
;
303 sta
->aid
= param
->u
.add_sta
.aid
;
304 if (sta
->aid
> IEEE80211_MAX_AID
)
306 sta
->listen_interval
= param
->u
.add_sta
.listen_interval
;
309 for (i
= 0; i
< sizeof(param
->u
.add_sta
.supp_rates
); i
++) {
310 int rate
= (param
->u
.add_sta
.supp_rates
[i
] & 0x7f) * 5;
311 if (local
->hw
.conf
.phymode
== MODE_ATHEROS_TURBO
||
312 local
->hw
.conf
.phymode
== MODE_ATHEROS_TURBOG
)
314 for (j
= 0; j
< local
->num_curr_rates
; j
++) {
315 if (local
->curr_rates
[j
].rate
== rate
)
320 sta
->supp_rates
= rates
;
322 rate_control_rate_init(sta
, local
);
324 if (param
->u
.add_sta
.wds_flags
& 0x01)
325 sta
->flags
|= WLAN_STA_WDS
;
327 sta
->flags
&= ~WLAN_STA_WDS
;
329 if (add_key_entry
&& !sta
->key
&& !sdata
->default_key
&&
330 local
->ops
->set_key
) {
331 struct ieee80211_key_conf conf
;
332 /* Add key cache entry with NULL key type because this may used
333 * for TX filtering. */
334 memset(&conf
, 0, sizeof(conf
));
335 conf
.hw_key_idx
= HW_KEY_IDX_INVALID
;
337 conf
.flags
|= IEEE80211_KEY_FORCE_SW_ENCRYPT
;
338 if (local
->ops
->set_key(local_to_hw(local
), SET_KEY
,
339 sta
->addr
, &conf
, sta
->aid
)) {
340 sta
->key_idx_compression
= HW_KEY_IDX_INVALID
;
342 sta
->key_idx_compression
= conf
.hw_key_idx
;
348 if (sdata
->type
== IEEE80211_IF_TYPE_AP
||
349 sdata
->type
== IEEE80211_IF_TYPE_VLAN
)
350 ieee80211_send_layer2_update(dev
, param
->sta_addr
);
356 static int ieee80211_ioctl_remove_sta(struct net_device
*dev
,
357 struct prism2_hostapd_param
*param
)
359 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
360 struct sta_info
*sta
;
362 sta
= sta_info_get(local
, param
->sta_addr
);
365 sta_info_free(sta
, 0);
368 return sta
? 0 : -ENOENT
;
372 static int ieee80211_ioctl_get_dot11counterstable(struct net_device
*dev
,
373 struct prism2_hostapd_param
*param
)
375 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
376 struct ieee80211_low_level_stats stats
;
378 memset(&stats
, 0, sizeof(stats
));
379 if (local
->ops
->get_stats
)
380 local
->ops
->get_stats(local_to_hw(local
), &stats
);
381 param
->u
.dot11CountersTable
.dot11TransmittedFragmentCount
=
382 local
->dot11TransmittedFragmentCount
;
383 param
->u
.dot11CountersTable
.dot11MulticastTransmittedFrameCount
=
384 local
->dot11MulticastTransmittedFrameCount
;
385 param
->u
.dot11CountersTable
.dot11ReceivedFragmentCount
=
386 local
->dot11ReceivedFragmentCount
;
387 param
->u
.dot11CountersTable
.dot11MulticastReceivedFrameCount
=
388 local
->dot11MulticastReceivedFrameCount
;
389 param
->u
.dot11CountersTable
.dot11TransmittedFrameCount
=
390 local
->dot11TransmittedFrameCount
;
391 param
->u
.dot11CountersTable
.dot11FCSErrorCount
=
392 stats
.dot11FCSErrorCount
;
393 param
->u
.dot11CountersTable
.dot11ACKFailureCount
=
394 stats
.dot11ACKFailureCount
;
395 param
->u
.dot11CountersTable
.dot11RTSFailureCount
=
396 stats
.dot11RTSFailureCount
;
397 param
->u
.dot11CountersTable
.dot11RTSSuccessCount
=
398 stats
.dot11RTSSuccessCount
;
404 static int ieee80211_ioctl_get_info_sta(struct net_device
*dev
,
405 struct prism2_hostapd_param
*param
)
407 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
408 struct sta_info
*sta
;
410 if (param
->sta_addr
[0] == 0xff && param
->sta_addr
[1] == 0xff &&
411 param
->sta_addr
[2] == 0xff && param
->sta_addr
[3] == 0xff &&
412 param
->sta_addr
[4] == 0xff && param
->sta_addr
[5] == 0xff) {
413 struct net_device_stats
*stats
;
415 stats
= ieee80211_dev_stats(local
->mdev
);
416 param
->u
.get_info_sta
.rx_bytes
= stats
->rx_bytes
;
417 param
->u
.get_info_sta
.tx_bytes
= stats
->tx_bytes
;
418 /* go through all STAs and get STA with lowest max. rate */
419 param
->u
.get_info_sta
.current_tx_rate
=
420 local
->curr_rates
[sta_info_min_txrate_get(local
)].rate
;
424 sta
= sta_info_get(local
, param
->sta_addr
);
429 param
->u
.get_info_sta
.inactive_msec
=
430 jiffies_to_msecs(jiffies
- sta
->last_rx
);
431 param
->u
.get_info_sta
.rx_packets
= sta
->rx_packets
;
432 param
->u
.get_info_sta
.tx_packets
= sta
->tx_packets
;
433 param
->u
.get_info_sta
.rx_bytes
= sta
->rx_bytes
;
434 param
->u
.get_info_sta
.tx_bytes
= sta
->tx_bytes
;
435 param
->u
.get_info_sta
.channel_use
= sta
->channel_use
;
436 param
->u
.get_info_sta
.flags
= sta
->flags
;
437 if (sta
->txrate
>= 0 && sta
->txrate
< local
->num_curr_rates
)
438 param
->u
.get_info_sta
.current_tx_rate
=
439 local
->curr_rates
[sta
->txrate
].rate
;
440 param
->u
.get_info_sta
.num_ps_buf_frames
=
441 skb_queue_len(&sta
->ps_tx_buf
);
442 param
->u
.get_info_sta
.tx_retry_failed
= sta
->tx_retry_failed
;
443 param
->u
.get_info_sta
.tx_retry_count
= sta
->tx_retry_count
;
444 param
->u
.get_info_sta
.last_rssi
= sta
->last_rssi
;
445 param
->u
.get_info_sta
.last_ack_rssi
= sta
->last_ack_rssi
[2];
453 static int ieee80211_ioctl_set_flags_sta(struct net_device
*dev
,
454 struct prism2_hostapd_param
*param
)
456 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
457 struct sta_info
*sta
;
459 sta
= sta_info_get(local
, param
->sta_addr
);
461 sta
->flags
|= param
->u
.set_flags_sta
.flags_or
;
462 sta
->flags
&= param
->u
.set_flags_sta
.flags_and
;
463 if (local
->ops
->set_port_auth
&&
464 (param
->u
.set_flags_sta
.flags_or
& WLAN_STA_AUTHORIZED
) &&
465 local
->ops
->set_port_auth(local_to_hw(local
), sta
->addr
, 1))
466 printk(KERN_DEBUG
"%s: failed to set low-level driver "
467 "PAE state (authorized) for " MAC_FMT
"\n",
468 dev
->name
, MAC_ARG(sta
->addr
));
469 if (local
->ops
->set_port_auth
&&
470 !(param
->u
.set_flags_sta
.flags_and
& WLAN_STA_AUTHORIZED
) &&
471 local
->ops
->set_port_auth(local_to_hw(local
), sta
->addr
, 0))
472 printk(KERN_DEBUG
"%s: failed to set low-level driver "
473 "PAE state (unauthorized) for " MAC_FMT
"\n",
474 dev
->name
, MAC_ARG(sta
->addr
));
478 return sta
? 0 : -ENOENT
;
482 int ieee80211_set_hw_encryption(struct net_device
*dev
,
483 struct sta_info
*sta
, u8 addr
[ETH_ALEN
],
484 struct ieee80211_key
*key
)
486 struct ieee80211_key_conf
*keyconf
= NULL
;
487 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
490 /* default to sw encryption; this will be cleared by low-level
491 * driver if the hw supports requested encryption */
493 key
->force_sw_encrypt
= 1;
495 if (key
&& local
->ops
->set_key
&&
496 (keyconf
= ieee80211_key_data2conf(local
, key
))) {
497 if (local
->ops
->set_key(local_to_hw(local
), SET_KEY
, addr
,
498 keyconf
, sta
? sta
->aid
: 0)) {
499 rc
= HOSTAP_CRYPT_ERR_KEY_SET_FAILED
;
500 key
->force_sw_encrypt
= 1;
501 key
->hw_key_idx
= HW_KEY_IDX_INVALID
;
503 key
->force_sw_encrypt
=
504 !!(keyconf
->flags
& IEEE80211_KEY_FORCE_SW_ENCRYPT
);
516 static int ieee80211_set_encryption(struct net_device
*dev
, u8
*sta_addr
,
517 int idx
, int alg
, int set_tx_key
, int *err
,
518 const u8
*_key
, size_t key_len
)
520 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
522 struct sta_info
*sta
;
523 struct ieee80211_key
*key
, *old_key
;
525 struct ieee80211_key_conf
*keyconf
;
526 struct ieee80211_sub_if_data
*sdata
;
528 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
530 if (sta_addr
[0] == 0xff && sta_addr
[1] == 0xff &&
531 sta_addr
[2] == 0xff && sta_addr
[3] == 0xff &&
532 sta_addr
[4] == 0xff && sta_addr
[5] == 0xff) {
534 if (idx
>= NUM_DEFAULT_KEYS
) {
535 printk(KERN_DEBUG
"%s: set_encrypt - invalid idx=%d\n",
539 key
= sdata
->keys
[idx
];
541 /* TODO: consider adding hwaccel support for these; at least
542 * Atheros key cache should be able to handle this since AP is
543 * only transmitting frames with default keys. */
544 /* FIX: hw key cache can be used when only one virtual
545 * STA is associated with each AP. If more than one STA
546 * is associated to the same AP, software encryption
547 * must be used. This should be done automatically
548 * based on configured station devices. For the time
549 * being, this can be only set at compile time. */
553 printk(KERN_DEBUG
"%s: set_encrypt - non-zero idx for "
554 "individual key\n", dev
->name
);
558 sta
= sta_info_get(local
, sta_addr
);
561 *err
= HOSTAP_CRYPT_ERR_UNKNOWN_ADDR
;
562 #ifdef CONFIG_D80211_VERBOSE_DEBUG
563 printk(KERN_DEBUG
"%s: set_encrypt - unknown addr "
565 dev
->name
, MAC_ARG(sta_addr
));
566 #endif /* CONFIG_D80211_VERBOSE_DEBUG */
575 * Cannot configure default hwaccel keys with WEP algorithm, if
576 * any of the virtual interfaces is using static WEP
577 * configuration because hwaccel would otherwise try to decrypt
580 * For now, just disable WEP hwaccel for broadcast when there is
581 * possibility of conflict with default keys. This can maybe later be
582 * optimized by using non-default keys (at least with Atheros ar521x).
584 if (!sta
&& alg
== ALG_WEP
&& !local
->default_wep_only
&&
585 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
&&
586 sdata
->type
!= IEEE80211_IF_TYPE_AP
) {
590 if (local
->hw
.flags
& IEEE80211_HW_DEVICE_HIDES_WEP
) {
591 /* Software encryption cannot be used with devices that hide
592 * encryption from the host system, so always try to use
593 * hardware acceleration with such devices. */
597 if ((local
->hw
.flags
& IEEE80211_HW_NO_TKIP_WMM_HWACCEL
) &&
599 if (sta
&& (sta
->flags
& WLAN_STA_WME
)) {
600 /* Hardware does not support hwaccel with TKIP when using WMM.
604 else if (sdata
->type
== IEEE80211_IF_TYPE_STA
) {
605 sta
= sta_info_get(local
, sdata
->u
.sta
.bssid
);
607 if (sta
->flags
& WLAN_STA_WME
) {
616 if (alg
== ALG_NONE
) {
618 if (try_hwaccel
&& key
&&
619 key
->hw_key_idx
!= HW_KEY_IDX_INVALID
&&
620 local
->ops
->set_key
&&
621 (keyconf
= ieee80211_key_data2conf(local
, key
)) != NULL
&&
622 local
->ops
->set_key(local_to_hw(local
), DISABLE_KEY
,
623 sta_addr
, keyconf
, sta
? sta
->aid
: 0)) {
625 *err
= HOSTAP_CRYPT_ERR_KEY_SET_FAILED
;
626 printk(KERN_DEBUG
"%s: set_encrypt - low-level disable"
627 " failed\n", dev
->name
);
632 if (key
&& sdata
->default_key
== key
) {
633 ieee80211_key_sysfs_remove_default(sdata
);
634 sdata
->default_key
= NULL
;
636 ieee80211_key_sysfs_remove(key
);
640 sdata
->keys
[idx
] = NULL
;
641 ieee80211_key_free(key
);
645 key
= ieee80211_key_alloc(sta
? NULL
: sdata
, idx
, key_len
,
652 /* default to sw encryption; low-level driver sets these if the
653 * requested encryption is supported */
654 key
->hw_key_idx
= HW_KEY_IDX_INVALID
;
655 key
->force_sw_encrypt
= 1;
659 key
->keylen
= key_len
;
660 memcpy(key
->key
, _key
, key_len
);
662 key
->default_tx_key
= 1;
664 if (alg
== ALG_CCMP
) {
665 /* Initialize AES key state here as an optimization
666 * so that it does not need to be initialized for every
668 key
->u
.ccmp
.tfm
= ieee80211_aes_key_setup_encrypt(
670 if (!key
->u
.ccmp
.tfm
) {
676 if (old_key
&& sdata
->default_key
== old_key
) {
677 ieee80211_key_sysfs_remove_default(sdata
);
678 sdata
->default_key
= NULL
;
680 ieee80211_key_sysfs_remove(old_key
);
684 sdata
->keys
[idx
] = key
;
685 ieee80211_key_free(old_key
);
687 key
->kobj
.parent
= &sta
->kobj
;
688 ret
= ieee80211_key_sysfs_add(key
);
693 (alg
== ALG_WEP
|| alg
== ALG_TKIP
|| alg
== ALG_CCMP
)) {
694 int e
= ieee80211_set_hw_encryption(dev
, sta
, sta_addr
,
701 if (set_tx_key
|| (!sta
&& !sdata
->default_key
&& key
)) {
702 sdata
->default_key
= key
;
703 if (ieee80211_key_sysfs_add_default(sdata
))
704 printk(KERN_WARNING
"%s: cannot create symlink to "
705 "default key\n", dev
->name
);
706 if (local
->ops
->set_key_idx
&&
707 local
->ops
->set_key_idx(local_to_hw(local
), idx
))
708 printk(KERN_DEBUG
"%s: failed to set TX key idx for "
709 "low-level driver\n", dev
->name
);
721 sdata
->keys
[idx
] = NULL
;
723 ieee80211_key_free(key
);
731 static int ieee80211_ioctl_set_encryption(struct net_device
*dev
,
732 struct prism2_hostapd_param
*param
,
737 param
->u
.crypt
.err
= 0;
738 param
->u
.crypt
.alg
[HOSTAP_CRYPT_ALG_NAME_LEN
- 1] = '\0';
741 (int) ((char *) param
->u
.crypt
.key
- (char *) param
) +
742 param
->u
.crypt
.key_len
) {
743 printk(KERN_DEBUG
"%s: set_encrypt - invalid param_lem\n",
748 if (strcmp(param
->u
.crypt
.alg
, "none") == 0)
750 else if (strcmp(param
->u
.crypt
.alg
, "WEP") == 0)
752 else if (strcmp(param
->u
.crypt
.alg
, "TKIP") == 0) {
753 if (param
->u
.crypt
.key_len
!= ALG_TKIP_KEY_LEN
) {
754 printk(KERN_DEBUG
"%s: set_encrypt - invalid TKIP key "
755 "length %d\n", dev
->name
,
756 param
->u
.crypt
.key_len
);
760 } else if (strcmp(param
->u
.crypt
.alg
, "CCMP") == 0) {
761 if (param
->u
.crypt
.key_len
!= ALG_CCMP_KEY_LEN
) {
762 printk(KERN_DEBUG
"%s: set_encrypt - invalid CCMP key "
763 "length %d\n", dev
->name
,
764 param
->u
.crypt
.key_len
);
769 param
->u
.crypt
.err
= HOSTAP_CRYPT_ERR_UNKNOWN_ALG
;
770 printk(KERN_DEBUG
"%s: set_encrypt - unknown alg\n",
775 return ieee80211_set_encryption(
776 dev
, param
->sta_addr
,
777 param
->u
.crypt
.idx
, alg
,
778 param
->u
.crypt
.flags
& HOSTAP_CRYPT_FLAG_SET_TX_KEY
,
779 ¶m
->u
.crypt
.err
, param
->u
.crypt
.key
,
780 param
->u
.crypt
.key_len
);
784 static int ieee80211_ioctl_get_encryption(struct net_device
*dev
,
785 struct prism2_hostapd_param
*param
,
788 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
790 struct sta_info
*sta
;
791 struct ieee80211_key
**key
;
793 struct ieee80211_sub_if_data
*sdata
;
796 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
798 param
->u
.crypt
.err
= 0;
800 max_key_len
= param_len
-
801 (int) ((char *) param
->u
.crypt
.key
- (char *) param
);
805 if (param
->sta_addr
[0] == 0xff && param
->sta_addr
[1] == 0xff &&
806 param
->sta_addr
[2] == 0xff && param
->sta_addr
[3] == 0xff &&
807 param
->sta_addr
[4] == 0xff && param
->sta_addr
[5] == 0xff) {
809 if (param
->u
.crypt
.idx
>= NUM_DEFAULT_KEYS
) {
810 param
->u
.crypt
.idx
= sdata
->default_key
?
811 sdata
->default_key
->keyidx
: 0;
814 key
= &sdata
->keys
[param
->u
.crypt
.idx
];
816 sta
= sta_info_get(local
, param
->sta_addr
);
818 param
->u
.crypt
.err
= HOSTAP_CRYPT_ERR_UNKNOWN_ADDR
;
825 memset(param
->u
.crypt
.seq_counter
, 0, HOSTAP_SEQ_COUNTER_SIZE
);
827 memcpy(param
->u
.crypt
.alg
, "none", 5);
828 param
->u
.crypt
.key_len
= 0;
829 param
->u
.crypt
.idx
= 0xff;
831 switch ((*key
)->alg
) {
833 memcpy(param
->u
.crypt
.alg
, "WEP", 4);
840 memcpy(param
->u
.crypt
.alg
, "TKIP", 5);
841 if (local
->ops
->get_sequence_counter
) {
842 /* Get transmit counter from low level driver */
843 if (local
->ops
->get_sequence_counter(
847 IEEE80211_SEQ_COUNTER_TX
,
850 /* Error getting value from device */
854 /* Get it from our own local data */
855 iv32
= (*key
)->u
.tkip
.iv32
;
856 iv16
= (*key
)->u
.tkip
.iv16
;
858 pos
= param
->u
.crypt
.seq_counter
;
859 *pos
++ = iv16
& 0xff;
860 *pos
++ = (iv16
>> 8) & 0xff;
861 *pos
++ = iv32
& 0xff;
862 *pos
++ = (iv32
>> 8) & 0xff;
863 *pos
++ = (iv32
>> 16) & 0xff;
864 *pos
++ = (iv32
>> 24) & 0xff;
870 memcpy(param
->u
.crypt
.alg
, "CCMP", 5);
871 pos
= param
->u
.crypt
.seq_counter
;
872 pn
= (*key
)->u
.ccmp
.tx_pn
;
882 memcpy(param
->u
.crypt
.alg
, "unknown", 8);
886 if (max_key_len
< (*key
)->keylen
)
889 param
->u
.crypt
.key_len
= (*key
)->keylen
;
890 memcpy(param
->u
.crypt
.key
, (*key
)->key
,
902 #ifdef CONFIG_HOSTAPD_WPA_TESTING
903 static int ieee80211_ioctl_wpa_trigger(struct net_device
*dev
,
904 struct prism2_hostapd_param
*param
)
906 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
907 struct sta_info
*sta
;
909 if (param
->sta_addr
[0] == 0xff && param
->sta_addr
[1] == 0xff &&
910 param
->sta_addr
[2] == 0xff && param
->sta_addr
[3] == 0xff &&
911 param
->sta_addr
[4] == 0xff && param
->sta_addr
[5] == 0xff) {
912 local
->wpa_trigger
= param
->u
.wpa_trigger
.trigger
;
916 sta
= sta_info_get(local
, param
->sta_addr
);
918 printk(KERN_DEBUG
"%s: wpa_trigger - unknown addr\n",
923 sta
->wpa_trigger
= param
->u
.wpa_trigger
.trigger
;
928 #endif /* CONFIG_HOSTAPD_WPA_TESTING */
931 static int ieee80211_ioctl_set_rate_sets(struct net_device
*dev
,
932 struct prism2_hostapd_param
*param
,
935 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
936 u16
*pos
= (u16
*) param
->u
.set_rate_sets
.data
;
937 int left
= param_len
- ((u8
*) pos
- (u8
*) param
);
938 int i
, mode
, num_supp
, num_basic
, *supp
, *basic
, *prev
;
940 mode
= param
->u
.set_rate_sets
.mode
;
941 num_supp
= param
->u
.set_rate_sets
.num_supported_rates
;
942 num_basic
= param
->u
.set_rate_sets
.num_basic_rates
;
944 if (left
< (num_supp
+ num_basic
) * 2) {
945 printk(KERN_WARNING
"%s: invalid length in hostapd set rate "
946 "sets ioctl (%d != %d)\n", dev
->name
, left
,
947 (num_supp
+ num_basic
) * 2);
951 supp
= (int *) kmalloc((num_supp
+ 1) * sizeof(int), GFP_KERNEL
);
952 basic
= (int *) kmalloc((num_basic
+ 1) * sizeof(int), GFP_KERNEL
);
954 if (!supp
|| !basic
) {
960 for (i
= 0; i
< num_supp
; i
++)
964 for (i
= 0; i
< num_basic
; i
++)
973 if (num_basic
== 0) {
978 prev
= local
->supp_rates
[mode
];
979 local
->supp_rates
[mode
] = supp
;
982 prev
= local
->basic_rates
[mode
];
983 local
->basic_rates
[mode
] = basic
;
986 if (mode
== local
->hw
.conf
.phymode
) {
987 /* TODO: should update STA TX rates and remove STAs if they
988 * do not have any remaining supported rates after the change
990 ieee80211_prepare_rates(local
);
997 static int ieee80211_ioctl_add_if(struct net_device
*dev
,
998 struct prism2_hostapd_param
*param
,
1001 u8
*pos
= param
->u
.if_info
.data
;
1002 int left
= param_len
- ((u8
*) pos
- (u8
*) param
);
1003 struct net_device
*new_dev
;
1005 struct hostapd_if_wds
*wds
;
1006 struct hostapd_if_bss
*bss
;
1008 printk(KERN_WARNING
"PRISM2_HOSTAPD_ADD_IF ioctl is deprecated!");
1009 switch (param
->u
.if_info
.type
) {
1011 wds
= (struct hostapd_if_wds
*) param
->u
.if_info
.data
;
1013 if (left
< sizeof(struct hostapd_if_wds
))
1016 res
= ieee80211_if_add(dev
, param
->u
.if_info
.name
, 0, &new_dev
);
1019 ieee80211_if_set_type(new_dev
, IEEE80211_IF_TYPE_WDS
);
1020 res
= ieee80211_if_update_wds(new_dev
, wds
->remote_addr
);
1022 __ieee80211_if_del(dev
->ieee80211_ptr
,
1023 IEEE80211_DEV_TO_SUB_IF(new_dev
));
1025 case HOSTAP_IF_VLAN
:
1026 if (left
< sizeof(struct hostapd_if_vlan
))
1029 res
= ieee80211_if_add(dev
, param
->u
.if_info
.name
, 0, &new_dev
);
1032 ieee80211_if_set_type(new_dev
, IEEE80211_IF_TYPE_VLAN
);
1034 res
= ieee80211_if_update_vlan(new_dev
, vlan
->id
);
1036 __ieee80211_if_del(dev
->ieee80211_ptr
,
1037 IEEE80211_DEV_TO_SUB_IF(new_dev
));
1041 bss
= (struct hostapd_if_bss
*) param
->u
.if_info
.data
;
1043 if (left
< sizeof(struct hostapd_if_bss
))
1046 res
= ieee80211_if_add(dev
, param
->u
.if_info
.name
, 0, &new_dev
);
1049 ieee80211_if_set_type(new_dev
, IEEE80211_IF_TYPE_AP
);
1050 memcpy(new_dev
->dev_addr
, bss
->bssid
, ETH_ALEN
);
1053 if (left
< sizeof(struct hostapd_if_sta
))
1056 res
= ieee80211_if_add(dev
, param
->u
.if_info
.name
, 0, &new_dev
);
1059 ieee80211_if_set_type(new_dev
, IEEE80211_IF_TYPE_STA
);
1068 static int ieee80211_ioctl_remove_if(struct net_device
*dev
,
1069 struct prism2_hostapd_param
*param
)
1073 switch (param
->u
.if_info
.type
) {
1075 type
= IEEE80211_IF_TYPE_WDS
;
1077 case HOSTAP_IF_VLAN
:
1078 type
= IEEE80211_IF_TYPE_VLAN
;
1081 type
= IEEE80211_IF_TYPE_AP
;
1084 type
= IEEE80211_IF_TYPE_STA
;
1090 return ieee80211_if_remove(dev
, param
->u
.if_info
.name
, type
);
1093 static int ieee80211_ioctl_update_if(struct net_device
*dev
,
1094 struct prism2_hostapd_param
*param
,
1097 u8
*pos
= param
->u
.if_info
.data
;
1098 int left
= param_len
- ((u8
*) pos
- (u8
*) param
);
1100 if (param
->u
.if_info
.type
== HOSTAP_IF_WDS
) {
1101 struct hostapd_if_wds
*wds
=
1102 (struct hostapd_if_wds
*) param
->u
.if_info
.data
;
1103 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1104 struct net_device
*wds_dev
= NULL
;
1105 struct ieee80211_sub_if_data
*sdata
;
1107 if (left
< sizeof(struct ieee80211_if_wds
))
1110 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
1111 if (strcmp(param
->u
.if_info
.name
,
1112 sdata
->dev
->name
) == 0) {
1113 wds_dev
= sdata
->dev
;
1118 if (!wds_dev
|| sdata
->type
!= IEEE80211_IF_TYPE_WDS
)
1121 return ieee80211_if_update_wds(wds_dev
, wds
->remote_addr
);
1128 static int ieee80211_ioctl_flush_ifs(struct net_device
*dev
,
1129 struct prism2_hostapd_param
*param
)
1131 ieee80211_if_flush(dev
);
1136 static int ieee80211_ioctl_scan_req(struct net_device
*dev
,
1137 struct prism2_hostapd_param
*param
,
1140 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1141 u8
*pos
= param
->u
.scan_req
.ssid
;
1142 int left
= param_len
- ((u8
*) pos
- (u8
*) param
);
1143 int len
= param
->u
.scan_req
.ssid_len
;
1145 if (local
->user_space_mlme
)
1148 if (!netif_running(dev
))
1151 if (left
< len
|| len
> IEEE80211_MAX_SSID_LEN
)
1154 return ieee80211_sta_req_scan(dev
, pos
, len
);
1158 static int ieee80211_ioctl_sta_get_state(struct net_device
*dev
,
1159 struct prism2_hostapd_param
*param
)
1161 struct ieee80211_sub_if_data
*sdata
;
1163 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1164 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
1165 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
1167 param
->u
.sta_get_state
.state
= sdata
->u
.sta
.state
;
1172 static int ieee80211_ioctl_mlme(struct net_device
*dev
,
1173 struct prism2_hostapd_param
*param
)
1175 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1176 struct ieee80211_sub_if_data
*sdata
;
1178 if (local
->user_space_mlme
)
1181 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1182 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
1183 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
1185 switch (param
->u
.mlme
.cmd
) {
1186 case MLME_STA_DEAUTH
:
1187 return ieee80211_sta_deauthenticate(dev
, param
->u
.mlme
.reason_code
);
1188 case MLME_STA_DISASSOC
:
1189 return ieee80211_sta_disassociate(dev
, param
->u
.mlme
.reason_code
);
1195 static int ieee80211_ioctl_get_load_stats(struct net_device
*dev
,
1196 struct prism2_hostapd_param
*param
)
1198 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1200 param
->u
.get_load_stats
.channel_use
= local
->channel_use
;
1201 /* if (param->u.get_load_stats.flags & LOAD_STATS_CLEAR)
1202 local->channel_use = 0; */ /* now it's not raw counter */
1208 static int ieee80211_ioctl_set_sta_vlan(struct net_device
*dev
,
1209 struct prism2_hostapd_param
*param
)
1211 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1212 struct sta_info
*sta
;
1214 sta
= sta_info_get(local
, param
->sta_addr
);
1216 struct net_device
*new_vlan_dev
;
1218 dev_get_by_name(param
->u
.set_sta_vlan
.vlan_name
);
1221 printk("%s: Station " MAC_FMT
" moved to vlan: %s\n",
1222 dev
->name
, MAC_ARG(param
->sta_addr
),
1223 new_vlan_dev
->name
);
1225 if (sta
->dev
!= new_vlan_dev
) {
1226 ieee80211_send_layer2_update(new_vlan_dev
,
1229 sta
->dev
= new_vlan_dev
;
1230 sta
->vlan_id
= param
->u
.set_sta_vlan
.vlan_id
;
1231 dev_put(new_vlan_dev
);
1236 return sta
? 0 : -ENOENT
;
1240 static int ieee80211_set_gen_ie(struct net_device
*dev
, u8
*ie
, size_t len
)
1242 struct ieee80211_sub_if_data
*sdata
;
1243 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1245 if (local
->user_space_mlme
)
1248 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1249 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
1250 sdata
->type
== IEEE80211_IF_TYPE_IBSS
)
1251 return ieee80211_sta_set_extra_ie(dev
, ie
, len
);
1253 if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
1254 kfree(sdata
->u
.ap
.generic_elem
);
1255 sdata
->u
.ap
.generic_elem
= kmalloc(len
, GFP_KERNEL
);
1256 if (!sdata
->u
.ap
.generic_elem
)
1258 memcpy(sdata
->u
.ap
.generic_elem
, ie
, len
);
1259 sdata
->u
.ap
.generic_elem_len
= len
;
1260 return ieee80211_if_config(dev
);
1267 ieee80211_ioctl_set_generic_info_elem(struct net_device
*dev
,
1268 struct prism2_hostapd_param
*param
,
1271 u8
*pos
= param
->u
.set_generic_info_elem
.data
;
1272 int left
= param_len
- ((u8
*) pos
- (u8
*) param
);
1273 int len
= param
->u
.set_generic_info_elem
.len
;
1278 return ieee80211_set_gen_ie(dev
, pos
, len
);
1282 static int ieee80211_ioctl_set_regulatory_domain(struct net_device
*dev
,
1283 struct prism2_hostapd_param
*param
)
1285 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1286 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
1287 conf
->regulatory_domain
= param
->u
.set_regulatory_domain
.rd
;
1292 static int ieee80211_ioctl_set_radio_enabled(struct net_device
*dev
,
1295 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1296 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
1298 conf
->radio_enabled
= val
;
1299 return ieee80211_hw_config(dev
->ieee80211_ptr
);
1303 ieee80211_ioctl_set_tx_queue_params(struct net_device
*dev
,
1304 struct prism2_hostapd_param
*param
)
1306 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1307 struct ieee80211_tx_queue_params qparam
;
1309 if (!local
->ops
->conf_tx
) {
1310 printk(KERN_DEBUG
"%s: low-level driver does not support TX "
1311 "queue configuration\n", dev
->name
);
1315 memset(&qparam
, 0, sizeof(qparam
));
1316 qparam
.aifs
= param
->u
.tx_queue_params
.aifs
;
1317 qparam
.cw_min
= param
->u
.tx_queue_params
.cw_min
;
1318 qparam
.cw_max
= param
->u
.tx_queue_params
.cw_max
;
1319 qparam
.burst_time
= param
->u
.tx_queue_params
.burst_time
;
1321 return local
->ops
->conf_tx(local_to_hw(local
),
1322 param
->u
.tx_queue_params
.queue
,
1327 static int ieee80211_ioctl_get_tx_stats(struct net_device
*dev
,
1328 struct prism2_hostapd_param
*param
)
1330 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1331 struct ieee80211_tx_queue_stats stats
;
1334 if (!local
->ops
->get_tx_stats
)
1337 memset(&stats
, 0, sizeof(stats
));
1338 ret
= local
->ops
->get_tx_stats(local_to_hw(local
), &stats
);
1342 for (i
= 0; i
< 4; i
++) {
1343 param
->u
.get_tx_stats
.data
[i
].len
= stats
.data
[i
].len
;
1344 param
->u
.get_tx_stats
.data
[i
].limit
= stats
.data
[i
].limit
;
1345 param
->u
.get_tx_stats
.data
[i
].count
= stats
.data
[i
].count
;
1352 static int ieee80211_ioctl_set_channel_flag(struct net_device
*dev
,
1353 struct prism2_hostapd_param
*param
)
1355 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1356 struct ieee80211_hw_mode
*mode
;
1357 struct ieee80211_channel
*chan
= NULL
;
1360 list_for_each_entry(mode
, &local
->modes_list
, list
) {
1361 if (mode
->mode
== param
->u
.set_channel_flag
.mode
)
1367 for (i
= 0; i
< mode
->num_channels
; i
++) {
1368 chan
= &mode
->channels
[i
];
1369 if (chan
->chan
== param
->u
.set_channel_flag
.chan
)
1377 chan
->flag
= param
->u
.set_channel_flag
.flag
;
1378 chan
->power_level
= param
->u
.set_channel_flag
.power_level
;
1379 chan
->antenna_max
= param
->u
.set_channel_flag
.antenna_max
;
1385 static int ieee80211_ioctl_set_quiet_params(struct net_device
*dev
,
1386 struct prism2_hostapd_param
*param
)
1388 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1389 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
1391 conf
->quiet_duration
= param
->u
.quiet
.duration
;
1392 conf
->quiet_offset
= param
->u
.quiet
.offset
;
1393 conf
->quiet_period
= param
->u
.quiet
.period
;
1398 static int ieee80211_ioctl_set_radar_params(struct net_device
*dev
,
1399 struct prism2_hostapd_param
*param
)
1401 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1402 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
1404 conf
->radar_firpwr_threshold
= param
->u
.radar
.radar_firpwr_threshold
;
1405 conf
->radar_rssi_threshold
= param
->u
.radar
.radar_rssi_threshold
;
1406 conf
->pulse_height_threshold
= param
->u
.radar
.pulse_height_threshold
;
1407 conf
->pulse_rssi_threshold
= param
->u
.radar
.pulse_rssi_threshold
;
1408 conf
->pulse_inband_threshold
= param
->u
.radar
.pulse_inband_threshold
;
1413 static int ieee80211_ioctl_priv_hostapd(struct net_device
*dev
,
1416 struct prism2_hostapd_param
*param
;
1419 if (p
->length
< sizeof(struct prism2_hostapd_param
) ||
1420 p
->length
> PRISM2_HOSTAPD_MAX_BUF_SIZE
|| !p
->pointer
) {
1421 printk(KERN_DEBUG
"%s: hostapd ioctl: ptr=%p len=%d min=%d "
1422 "max=%d\n", dev
->name
, p
->pointer
, p
->length
,
1423 (int)sizeof(struct prism2_hostapd_param
),
1424 PRISM2_HOSTAPD_MAX_BUF_SIZE
);
1428 param
= (struct prism2_hostapd_param
*) kmalloc(p
->length
, GFP_KERNEL
);
1432 if (copy_from_user(param
, p
->pointer
, p
->length
)) {
1437 switch (param
->cmd
) {
1438 case PRISM2_HOSTAPD_FLUSH
:
1439 ret
= ieee80211_ioctl_flush(dev
, param
);
1441 case PRISM2_HOSTAPD_ADD_STA
:
1442 ret
= ieee80211_ioctl_add_sta(dev
, param
);
1444 case PRISM2_HOSTAPD_REMOVE_STA
:
1445 ret
= ieee80211_ioctl_remove_sta(dev
, param
);
1447 case PRISM2_HOSTAPD_GET_INFO_STA
:
1448 ret
= ieee80211_ioctl_get_info_sta(dev
, param
);
1450 case PRISM2_SET_ENCRYPTION
:
1451 ret
= ieee80211_ioctl_set_encryption(dev
, param
, p
->length
);
1453 case PRISM2_GET_ENCRYPTION
:
1454 ret
= ieee80211_ioctl_get_encryption(dev
, param
, p
->length
);
1456 case PRISM2_HOSTAPD_SET_FLAGS_STA
:
1457 ret
= ieee80211_ioctl_set_flags_sta(dev
, param
);
1459 case PRISM2_HOSTAPD_SET_BEACON
:
1460 ret
= ieee80211_ioctl_set_beacon(dev
, param
, p
->length
, 0);
1462 case PRISM2_HOSTAPD_GET_HW_FEATURES
:
1463 ret
= ieee80211_ioctl_get_hw_features(dev
, param
, p
->length
);
1465 case PRISM2_HOSTAPD_SCAN
:
1466 ret
= ieee80211_ioctl_scan(dev
, param
);
1468 #ifdef CONFIG_HOSTAPD_WPA_TESTING
1469 case PRISM2_HOSTAPD_WPA_TRIGGER
:
1470 ret
= ieee80211_ioctl_wpa_trigger(dev
, param
);
1472 #endif /* CONFIG_HOSTAPD_WPA_TESTING */
1473 case PRISM2_HOSTAPD_SET_RATE_SETS
:
1474 ret
= ieee80211_ioctl_set_rate_sets(dev
, param
, p
->length
);
1476 case PRISM2_HOSTAPD_ADD_IF
:
1477 ret
= ieee80211_ioctl_add_if(dev
, param
, p
->length
);
1479 case PRISM2_HOSTAPD_REMOVE_IF
:
1480 ret
= ieee80211_ioctl_remove_if(dev
, param
);
1482 case PRISM2_HOSTAPD_GET_DOT11COUNTERSTABLE
:
1483 ret
= ieee80211_ioctl_get_dot11counterstable(dev
, param
);
1485 case PRISM2_HOSTAPD_GET_LOAD_STATS
:
1486 ret
= ieee80211_ioctl_get_load_stats(dev
, param
);
1488 case PRISM2_HOSTAPD_SET_STA_VLAN
:
1489 ret
= ieee80211_ioctl_set_sta_vlan(dev
, param
);
1491 case PRISM2_HOSTAPD_SET_GENERIC_INFO_ELEM
:
1492 ret
= ieee80211_ioctl_set_generic_info_elem(dev
, param
,
1495 case PRISM2_HOSTAPD_SET_CHANNEL_FLAG
:
1496 ret
= ieee80211_ioctl_set_channel_flag(dev
, param
);
1498 case PRISM2_HOSTAPD_SET_REGULATORY_DOMAIN
:
1499 ret
= ieee80211_ioctl_set_regulatory_domain(dev
, param
);
1501 case PRISM2_HOSTAPD_SET_TX_QUEUE_PARAMS
:
1502 ret
= ieee80211_ioctl_set_tx_queue_params(dev
, param
);
1504 case PRISM2_HOSTAPD_GET_TX_STATS
:
1505 ret
= ieee80211_ioctl_get_tx_stats(dev
, param
);
1507 case PRISM2_HOSTAPD_UPDATE_IF
:
1508 ret
= ieee80211_ioctl_update_if(dev
, param
, p
->length
);
1510 case PRISM2_HOSTAPD_SCAN_REQ
:
1511 ret
= ieee80211_ioctl_scan_req(dev
, param
, p
->length
);
1513 case PRISM2_STA_GET_STATE
:
1514 ret
= ieee80211_ioctl_sta_get_state(dev
, param
);
1516 case PRISM2_HOSTAPD_MLME
:
1517 ret
= ieee80211_ioctl_mlme(dev
, param
);
1519 case PRISM2_HOSTAPD_FLUSH_IFS
:
1520 ret
= ieee80211_ioctl_flush_ifs(dev
, param
);
1522 case PRISM2_HOSTAPD_SET_RADAR_PARAMS
:
1523 ret
= ieee80211_ioctl_set_radar_params(dev
, param
);
1525 case PRISM2_HOSTAPD_SET_QUIET_PARAMS
:
1526 ret
= ieee80211_ioctl_set_quiet_params(dev
, param
);
1533 if (copy_to_user(p
->pointer
, param
, p
->length
))
1543 static int ieee80211_ioctl_giwname(struct net_device
*dev
,
1544 struct iw_request_info
*info
,
1545 char *name
, char *extra
)
1547 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1549 switch (local
->hw
.conf
.phymode
) {
1550 case MODE_IEEE80211A
:
1551 strcpy(name
, "IEEE 802.11a");
1553 case MODE_IEEE80211B
:
1554 strcpy(name
, "IEEE 802.11b");
1556 case MODE_IEEE80211G
:
1557 strcpy(name
, "IEEE 802.11g");
1559 case MODE_ATHEROS_TURBO
:
1560 strcpy(name
, "5GHz Turbo");
1563 strcpy(name
, "IEEE 802.11");
1571 static int ieee80211_ioctl_giwrange(struct net_device
*dev
,
1572 struct iw_request_info
*info
,
1573 struct iw_point
*data
, char *extra
)
1575 struct iw_range
*range
= (struct iw_range
*) extra
;
1577 data
->length
= sizeof(struct iw_range
);
1578 memset(range
, 0, sizeof(struct iw_range
));
1580 range
->we_version_compiled
= WIRELESS_EXT
;
1581 range
->we_version_source
= 14;
1582 range
->retry_capa
= IW_RETRY_LIMIT
;
1583 range
->retry_flags
= IW_RETRY_LIMIT
;
1584 range
->min_retry
= 0;
1585 range
->max_retry
= 255;
1587 range
->max_rts
= 2347;
1588 range
->min_frag
= 256;
1589 range
->max_frag
= 2346;
1591 range
->max_qual
.qual
= 100;
1592 range
->max_qual
.level
= 146; /* set floor at -110 dBm (146 - 256) */
1593 range
->max_qual
.noise
= 146;
1594 range
->max_qual
.updated
= IW_QUAL_ALL_UPDATED
;
1596 range
->avg_qual
.qual
= 50;
1597 range
->avg_qual
.level
= 0;
1598 range
->avg_qual
.noise
= 0;
1599 range
->avg_qual
.updated
= IW_QUAL_ALL_UPDATED
;
1605 struct ieee80211_channel_range
{
1608 unsigned char power_level
;
1609 unsigned char antenna_max
;
1612 static const struct ieee80211_channel_range ieee80211_fcc_channels
[] = {
1613 { 2412, 2462, 27, 6 } /* IEEE 802.11b/g, channels 1..11 */,
1614 { 5180, 5240, 17, 6 } /* IEEE 802.11a, channels 36..48 */,
1615 { 5260, 5320, 23, 6 } /* IEEE 802.11a, channels 52..64 */,
1616 { 5745, 5825, 30, 6 } /* IEEE 802.11a, channels 149..165, outdoor */,
1620 static const struct ieee80211_channel_range ieee80211_mkk_channels
[] = {
1621 { 2412, 2472, 20, 6 } /* IEEE 802.11b/g, channels 1..13 */,
1622 { 5170, 5240, 20, 6 } /* IEEE 802.11a, channels 34..48 */,
1623 { 5260, 5320, 20, 6 } /* IEEE 802.11a, channels 52..64 */,
1628 static const struct ieee80211_channel_range
*channel_range
=
1629 ieee80211_fcc_channels
;
1632 static void ieee80211_unmask_channel(struct net_device
*dev
, int mode
,
1633 struct ieee80211_channel
*chan
)
1639 if (ieee80211_regdom
== 64 &&
1640 (mode
== MODE_ATHEROS_TURBO
|| mode
== MODE_ATHEROS_TURBOG
)) {
1641 /* Do not allow Turbo modes in Japan. */
1645 for (i
= 0; channel_range
[i
].start_freq
; i
++) {
1646 const struct ieee80211_channel_range
*r
= &channel_range
[i
];
1647 if (r
->start_freq
<= chan
->freq
&& r
->end_freq
>= chan
->freq
) {
1648 if (ieee80211_regdom
== 64 && !ieee80211_japan_5ghz
&&
1649 chan
->freq
>= 5260 && chan
->freq
<= 5320) {
1651 * Skip new channels in Japan since the
1652 * firmware was not marked having been upgraded
1658 if (ieee80211_regdom
== 0x10 &&
1659 (chan
->freq
== 5190 || chan
->freq
== 5210 ||
1660 chan
->freq
== 5230)) {
1661 /* Skip MKK channels when in FCC domain. */
1665 chan
->flag
|= IEEE80211_CHAN_W_SCAN
|
1666 IEEE80211_CHAN_W_ACTIVE_SCAN
|
1667 IEEE80211_CHAN_W_IBSS
;
1668 chan
->power_level
= r
->power_level
;
1669 chan
->antenna_max
= r
->antenna_max
;
1671 if (ieee80211_regdom
== 64 &&
1672 (chan
->freq
== 5170 || chan
->freq
== 5190 ||
1673 chan
->freq
== 5210 || chan
->freq
== 5230)) {
1675 * New regulatory rules in Japan have backwards
1676 * compatibility with old channels in 5.15-5.25
1677 * GHz band, but the station is not allowed to
1678 * use active scan on these old channels.
1680 chan
->flag
&= ~IEEE80211_CHAN_W_ACTIVE_SCAN
;
1683 if (ieee80211_regdom
== 64 &&
1684 (chan
->freq
== 5260 || chan
->freq
== 5280 ||
1685 chan
->freq
== 5300 || chan
->freq
== 5320)) {
1687 * IBSS is not allowed on 5.25-5.35 GHz band
1688 * due to radar detection requirements.
1690 chan
->flag
&= ~IEEE80211_CHAN_W_IBSS
;
1699 static int ieee80211_unmask_channels(struct net_device
*dev
)
1701 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1702 struct ieee80211_hw_mode
*mode
;
1705 list_for_each_entry(mode
, &local
->modes_list
, list
) {
1706 for (c
= 0; c
< mode
->num_channels
; c
++) {
1707 ieee80211_unmask_channel(dev
, mode
->mode
,
1708 &mode
->channels
[c
]);
1715 int ieee80211_init_client(struct net_device
*dev
)
1717 if (ieee80211_regdom
== 0x40)
1718 channel_range
= ieee80211_mkk_channels
;
1719 ieee80211_unmask_channels(dev
);
1724 static int ieee80211_ioctl_siwmode(struct net_device
*dev
,
1725 struct iw_request_info
*info
,
1726 __u32
*mode
, char *extra
)
1728 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1731 if (sdata
->type
== IEEE80211_IF_TYPE_VLAN
)
1733 if (netif_running(dev
))
1737 case IW_MODE_MASTER
:
1738 type
= IEEE80211_IF_TYPE_AP
;
1741 type
= IEEE80211_IF_TYPE_STA
;
1744 type
= IEEE80211_IF_TYPE_IBSS
;
1746 case IW_MODE_MONITOR
:
1747 type
= IEEE80211_IF_TYPE_MNTR
;
1749 case IW_MODE_REPEAT
:
1750 type
= IEEE80211_IF_TYPE_WDS
;
1756 if (type
!= sdata
->type
) {
1757 ieee80211_if_reinit(dev
);
1758 ieee80211_if_set_type(dev
, type
);
1764 static int ieee80211_ioctl_giwmode(struct net_device
*dev
,
1765 struct iw_request_info
*info
,
1766 __u32
*mode
, char *extra
)
1768 struct ieee80211_sub_if_data
*sdata
;
1770 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1771 switch (sdata
->type
) {
1772 case IEEE80211_IF_TYPE_AP
:
1773 *mode
= IW_MODE_MASTER
;
1775 case IEEE80211_IF_TYPE_STA
:
1776 *mode
= IW_MODE_INFRA
;
1778 case IEEE80211_IF_TYPE_IBSS
:
1779 *mode
= IW_MODE_ADHOC
;
1781 case IEEE80211_IF_TYPE_MNTR
:
1782 *mode
= IW_MODE_MONITOR
;
1784 case IEEE80211_IF_TYPE_WDS
:
1785 *mode
= IW_MODE_REPEAT
;
1787 case IEEE80211_IF_TYPE_VLAN
:
1788 *mode
= IW_MODE_SECOND
; /* FIXME */
1791 *mode
= IW_MODE_AUTO
;
1798 int ieee80211_ioctl_siwfreq(struct net_device
*dev
,
1799 struct iw_request_info
*info
,
1800 struct iw_freq
*freq
, char *extra
)
1802 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1803 struct ieee80211_hw_mode
*mode
;
1804 int c
, nfreq
, set
= 0;
1806 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
1810 int i
, div
= 1000000;
1811 for (i
= 0; i
< freq
->e
; i
++)
1814 nfreq
= freq
->m
/ div
;
1819 list_for_each_entry(mode
, &local
->modes_list
, list
) {
1820 for (c
= 0; c
< mode
->num_channels
; c
++) {
1821 struct ieee80211_channel
*chan
= &mode
->channels
[c
];
1822 if (chan
->flag
& IEEE80211_CHAN_W_SCAN
&&
1823 ((freq
->e
== 0 && chan
->chan
== freq
->m
) ||
1824 (freq
->e
> 0 && nfreq
== chan
->freq
)) &&
1825 (local
->enabled_modes
& (1 << mode
->mode
))) {
1826 /* Use next_mode as the mode preference to
1827 * resolve non-unique channel numbers. */
1828 if (set
&& mode
->mode
!= local
->next_mode
)
1831 local
->hw
.conf
.channel
= chan
->chan
;
1832 local
->hw
.conf
.channel_val
= chan
->val
;
1833 local
->hw
.conf
.power_level
= chan
->power_level
;
1834 local
->hw
.conf
.freq
= chan
->freq
;
1835 local
->hw
.conf
.phymode
= mode
->mode
;
1836 local
->hw
.conf
.antenna_max
= chan
->antenna_max
;
1843 local
->sta_scanning
= 0; /* Abort possible scan */
1844 return ieee80211_hw_config(local
);
1851 static int ieee80211_ioctl_giwfreq(struct net_device
*dev
,
1852 struct iw_request_info
*info
,
1853 struct iw_freq
*freq
, char *extra
)
1855 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1857 /* TODO: in station mode (Managed/Ad-hoc) might need to poll low-level
1858 * driver for the current channel with firmware-based management */
1860 freq
->m
= local
->hw
.conf
.freq
;
1867 static int ieee80211_ioctl_siwessid(struct net_device
*dev
,
1868 struct iw_request_info
*info
,
1869 struct iw_point
*data
, char *ssid
)
1871 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1872 struct ieee80211_sub_if_data
*sdata
;
1873 size_t len
= data
->length
;
1875 /* iwconfig uses nul termination in SSID.. */
1876 if (len
> 0 && ssid
[len
- 1] == '\0')
1879 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1880 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
1881 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
1882 if (local
->user_space_mlme
) {
1883 if (len
> IEEE80211_MAX_SSID_LEN
)
1885 memcpy(sdata
->u
.sta
.ssid
, ssid
, len
);
1886 sdata
->u
.sta
.ssid_len
= len
;
1889 return ieee80211_sta_set_ssid(dev
, ssid
, len
);
1892 if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
1893 memcpy(sdata
->u
.ap
.ssid
, ssid
, len
);
1894 memset(sdata
->u
.ap
.ssid
+ len
, 0,
1895 IEEE80211_MAX_SSID_LEN
- len
);
1896 sdata
->u
.ap
.ssid_len
= len
;
1897 return ieee80211_if_config(dev
);
1903 static int ieee80211_ioctl_giwessid(struct net_device
*dev
,
1904 struct iw_request_info
*info
,
1905 struct iw_point
*data
, char *ssid
)
1909 struct ieee80211_sub_if_data
*sdata
;
1910 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1911 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
1912 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
1913 int res
= ieee80211_sta_get_ssid(dev
, ssid
, &len
);
1922 if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
1923 len
= sdata
->u
.ap
.ssid_len
;
1924 if (len
> IW_ESSID_MAX_SIZE
)
1925 len
= IW_ESSID_MAX_SIZE
;
1926 memcpy(ssid
, sdata
->u
.ap
.ssid
, len
);
1935 static int ieee80211_ioctl_siwap(struct net_device
*dev
,
1936 struct iw_request_info
*info
,
1937 struct sockaddr
*ap_addr
, char *extra
)
1939 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1940 struct ieee80211_sub_if_data
*sdata
;
1942 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1943 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
1944 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
1945 if (local
->user_space_mlme
) {
1946 memcpy(sdata
->u
.sta
.bssid
, (u8
*) &ap_addr
->sa_data
,
1950 return ieee80211_sta_set_bssid(dev
, (u8
*) &ap_addr
->sa_data
);
1951 } else if (sdata
->type
== IEEE80211_IF_TYPE_WDS
) {
1952 if (memcmp(sdata
->u
.wds
.remote_addr
, (u8
*) &ap_addr
->sa_data
,
1955 return ieee80211_if_update_wds(dev
, (u8
*) &ap_addr
->sa_data
);
1962 static int ieee80211_ioctl_giwap(struct net_device
*dev
,
1963 struct iw_request_info
*info
,
1964 struct sockaddr
*ap_addr
, char *extra
)
1966 struct ieee80211_sub_if_data
*sdata
;
1968 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1969 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
1970 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
1971 ap_addr
->sa_family
= ARPHRD_ETHER
;
1972 memcpy(&ap_addr
->sa_data
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
1974 } else if (sdata
->type
== IEEE80211_IF_TYPE_WDS
) {
1975 ap_addr
->sa_family
= ARPHRD_ETHER
;
1976 memcpy(&ap_addr
->sa_data
, sdata
->u
.wds
.remote_addr
, ETH_ALEN
);
1984 static int ieee80211_ioctl_siwscan(struct net_device
*dev
,
1985 struct iw_request_info
*info
,
1986 struct iw_point
*data
, char *extra
)
1988 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1989 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1991 size_t ssid_len
= 0;
1993 if (!netif_running(dev
))
1996 if (local
->scan_flags
& IEEE80211_SCAN_MATCH_SSID
) {
1997 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
1998 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
1999 ssid
= sdata
->u
.sta
.ssid
;
2000 ssid_len
= sdata
->u
.sta
.ssid_len
;
2001 } else if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
2002 ssid
= sdata
->u
.ap
.ssid
;
2003 ssid_len
= sdata
->u
.ap
.ssid_len
;
2007 return ieee80211_sta_req_scan(dev
, ssid
, ssid_len
);
2011 static int ieee80211_ioctl_giwscan(struct net_device
*dev
,
2012 struct iw_request_info
*info
,
2013 struct iw_point
*data
, char *extra
)
2016 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2017 if (local
->sta_scanning
)
2019 res
= ieee80211_sta_scan_results(dev
, extra
, data
->length
);
2029 static int ieee80211_ioctl_siwrts(struct net_device
*dev
,
2030 struct iw_request_info
*info
,
2031 struct iw_param
*rts
, char *extra
)
2033 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2036 local
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
2037 else if (rts
->value
< 0 || rts
->value
> IEEE80211_MAX_RTS_THRESHOLD
)
2040 local
->rts_threshold
= rts
->value
;
2042 /* If the wlan card performs RTS/CTS in hardware/firmware,
2043 * configure it here */
2045 if (local
->ops
->set_rts_threshold
)
2046 local
->ops
->set_rts_threshold(local_to_hw(local
),
2047 local
->rts_threshold
);
2052 static int ieee80211_ioctl_giwrts(struct net_device
*dev
,
2053 struct iw_request_info
*info
,
2054 struct iw_param
*rts
, char *extra
)
2056 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2058 rts
->value
= local
->rts_threshold
;
2059 rts
->disabled
= (rts
->value
>= IEEE80211_MAX_RTS_THRESHOLD
);
2066 static int ieee80211_ioctl_siwfrag(struct net_device
*dev
,
2067 struct iw_request_info
*info
,
2068 struct iw_param
*frag
, char *extra
)
2070 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2073 local
->fragmentation_threshold
= IEEE80211_MAX_FRAG_THRESHOLD
;
2074 else if (frag
->value
< 256 ||
2075 frag
->value
> IEEE80211_MAX_FRAG_THRESHOLD
)
2078 /* Fragment length must be even, so strip LSB. */
2079 local
->fragmentation_threshold
= frag
->value
& ~0x1;
2082 /* If the wlan card performs fragmentation in hardware/firmware,
2083 * configure it here */
2085 if (local
->ops
->set_frag_threshold
)
2086 local
->ops
->set_frag_threshold(
2088 local
->fragmentation_threshold
);
2093 static int ieee80211_ioctl_giwfrag(struct net_device
*dev
,
2094 struct iw_request_info
*info
,
2095 struct iw_param
*frag
, char *extra
)
2097 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2099 frag
->value
= local
->fragmentation_threshold
;
2100 frag
->disabled
= (frag
->value
>= IEEE80211_MAX_RTS_THRESHOLD
);
2107 static int ieee80211_ioctl_siwretry(struct net_device
*dev
,
2108 struct iw_request_info
*info
,
2109 struct iw_param
*retry
, char *extra
)
2111 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2113 if (retry
->disabled
||
2114 (retry
->flags
& IW_RETRY_TYPE
) != IW_RETRY_LIMIT
)
2117 if (retry
->flags
& IW_RETRY_MAX
)
2118 local
->long_retry_limit
= retry
->value
;
2119 else if (retry
->flags
& IW_RETRY_MIN
)
2120 local
->short_retry_limit
= retry
->value
;
2122 local
->long_retry_limit
= retry
->value
;
2123 local
->short_retry_limit
= retry
->value
;
2126 if (local
->ops
->set_retry_limit
) {
2127 return local
->ops
->set_retry_limit(
2129 local
->short_retry_limit
,
2130 local
->long_retry_limit
);
2137 static int ieee80211_ioctl_giwretry(struct net_device
*dev
,
2138 struct iw_request_info
*info
,
2139 struct iw_param
*retry
, char *extra
)
2141 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2143 retry
->disabled
= 0;
2144 if ((retry
->flags
& IW_RETRY_TYPE
) != IW_RETRY_LIMIT
)
2146 if (retry
->flags
& IW_RETRY_MAX
) {
2147 retry
->flags
= IW_RETRY_LIMIT
| IW_RETRY_MAX
;
2148 retry
->value
= local
->long_retry_limit
;
2150 retry
->flags
= IW_RETRY_LIMIT
;
2151 retry
->value
= local
->short_retry_limit
;
2152 if (local
->long_retry_limit
!= local
->short_retry_limit
)
2153 retry
->flags
|= IW_RETRY_MIN
;
2160 static void ieee80211_ioctl_unmask_channels(struct ieee80211_local
*local
)
2162 struct ieee80211_hw_mode
*mode
;
2165 list_for_each_entry(mode
, &local
->modes_list
, list
) {
2166 for (c
= 0; c
< mode
->num_channels
; c
++) {
2167 struct ieee80211_channel
*chan
= &mode
->channels
[c
];
2168 chan
->flag
|= IEEE80211_CHAN_W_SCAN
;
2174 static int ieee80211_ioctl_test_mode(struct net_device
*dev
, int mode
)
2176 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2177 int ret
= -EOPNOTSUPP
;
2179 if (mode
== IEEE80211_TEST_UNMASK_CHANNELS
) {
2180 ieee80211_ioctl_unmask_channels(local
);
2184 if (local
->ops
->test_mode
)
2185 ret
= local
->ops
->test_mode(local_to_hw(local
), mode
);
2191 static int ieee80211_ioctl_clear_keys(struct net_device
*dev
)
2193 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2194 struct ieee80211_key_conf key
;
2197 struct ieee80211_key_conf
*keyconf
;
2198 struct ieee80211_sub_if_data
*sdata
;
2199 struct sta_info
*sta
;
2201 memset(addr
, 0xff, ETH_ALEN
);
2202 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
2203 for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
2205 if (sdata
->keys
[i
] &&
2206 !sdata
->keys
[i
]->force_sw_encrypt
&&
2207 local
->ops
->set_key
&&
2208 (keyconf
= ieee80211_key_data2conf(local
,
2210 local
->ops
->set_key(local_to_hw(local
),
2214 ieee80211_key_free(sdata
->keys
[i
]);
2215 sdata
->keys
[i
] = NULL
;
2217 sdata
->default_key
= NULL
;
2220 spin_lock_bh(&local
->sta_lock
);
2221 list_for_each_entry(sta
, &local
->sta_list
, list
) {
2223 if (sta
->key
&& !sta
->key
->force_sw_encrypt
&&
2224 local
->ops
->set_key
&&
2225 (keyconf
= ieee80211_key_data2conf(local
, sta
->key
)))
2226 local
->ops
->set_key(local_to_hw(local
), DISABLE_KEY
,
2227 sta
->addr
, keyconf
, sta
->aid
);
2229 ieee80211_key_free(sta
->key
);
2232 spin_unlock_bh(&local
->sta_lock
);
2234 memset(&key
, 0, sizeof(key
));
2235 if (local
->ops
->set_key
&&
2236 local
->ops
->set_key(local_to_hw(local
), REMOVE_ALL_KEYS
,
2238 printk(KERN_DEBUG
"%s: failed to remove hwaccel keys\n",
2246 ieee80211_ioctl_force_unicast_rate(struct net_device
*dev
,
2247 struct ieee80211_sub_if_data
*sdata
,
2250 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2253 if (sdata
->type
!= IEEE80211_IF_TYPE_AP
)
2257 sdata
->u
.ap
.force_unicast_rateidx
= -1;
2261 for (i
= 0; i
< local
->num_curr_rates
; i
++) {
2262 if (local
->curr_rates
[i
].rate
== rate
) {
2263 sdata
->u
.ap
.force_unicast_rateidx
= i
;
2272 ieee80211_ioctl_max_ratectrl_rate(struct net_device
*dev
,
2273 struct ieee80211_sub_if_data
*sdata
,
2276 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2279 if (sdata
->type
!= IEEE80211_IF_TYPE_AP
)
2283 sdata
->u
.ap
.max_ratectrl_rateidx
= -1;
2287 for (i
= 0; i
< local
->num_curr_rates
; i
++) {
2288 if (local
->curr_rates
[i
].rate
== rate
) {
2289 sdata
->u
.ap
.max_ratectrl_rateidx
= i
;
2297 static void ieee80211_key_enable_hwaccel(struct ieee80211_local
*local
,
2298 struct ieee80211_key
*key
)
2300 struct ieee80211_key_conf
*keyconf
;
2303 if (!key
|| key
->alg
!= ALG_WEP
|| !key
->force_sw_encrypt
||
2304 (local
->hw
.flags
& IEEE80211_HW_DEVICE_HIDES_WEP
))
2307 memset(addr
, 0xff, ETH_ALEN
);
2308 keyconf
= ieee80211_key_data2conf(local
, key
);
2309 if (keyconf
&& local
->ops
->set_key
&&
2310 local
->ops
->set_key(local_to_hw(local
),
2311 SET_KEY
, addr
, keyconf
, 0) == 0) {
2312 key
->force_sw_encrypt
=
2313 !!(keyconf
->flags
& IEEE80211_KEY_FORCE_SW_ENCRYPT
);
2314 key
->hw_key_idx
= keyconf
->hw_key_idx
;
2320 static void ieee80211_key_disable_hwaccel(struct ieee80211_local
*local
,
2321 struct ieee80211_key
*key
)
2323 struct ieee80211_key_conf
*keyconf
;
2326 if (!key
|| key
->alg
!= ALG_WEP
|| key
->force_sw_encrypt
||
2327 (local
->hw
.flags
& IEEE80211_HW_DEVICE_HIDES_WEP
))
2330 memset(addr
, 0xff, ETH_ALEN
);
2331 keyconf
= ieee80211_key_data2conf(local
, key
);
2332 if (keyconf
&& local
->ops
->set_key
)
2333 local
->ops
->set_key(local_to_hw(local
), DISABLE_KEY
,
2336 key
->force_sw_encrypt
= 1;
2340 static int ieee80211_ioctl_default_wep_only(struct ieee80211_local
*local
,
2344 struct ieee80211_sub_if_data
*sdata
;
2346 local
->default_wep_only
= value
;
2347 list_for_each_entry(sdata
, &local
->sub_if_list
, list
)
2348 for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++)
2350 ieee80211_key_enable_hwaccel(local
,
2353 ieee80211_key_disable_hwaccel(local
,
2360 void ieee80211_update_default_wep_only(struct ieee80211_local
*local
)
2363 struct ieee80211_sub_if_data
*sdata
;
2365 spin_lock_bh(&local
->sub_if_lock
);
2366 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
2368 if (sdata
->dev
== local
->mdev
)
2371 /* If there is an AP interface then depend on userspace to
2372 set default_wep_only correctly. */
2373 if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
2374 spin_unlock_bh(&local
->sub_if_lock
);
2382 ieee80211_ioctl_default_wep_only(local
, 1);
2384 ieee80211_ioctl_default_wep_only(local
, 0);
2386 spin_unlock_bh(&local
->sub_if_lock
);
2390 static int ieee80211_ioctl_prism2_param(struct net_device
*dev
,
2391 struct iw_request_info
*info
,
2392 void *wrqu
, char *extra
)
2394 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2395 struct ieee80211_sub_if_data
*sdata
;
2396 int *i
= (int *) extra
;
2398 int value
= *(i
+ 1);
2401 if (!capable(CAP_NET_ADMIN
))
2404 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2407 case PRISM2_PARAM_HOST_ENCRYPT
:
2408 case PRISM2_PARAM_HOST_DECRYPT
:
2409 /* TODO: implement these; return success now to prevent
2410 * hostapd from aborting */
2413 case PRISM2_PARAM_BEACON_INT
:
2414 local
->hw
.conf
.beacon_int
= value
;
2415 if (ieee80211_hw_config(local
))
2419 case PRISM2_PARAM_AP_BRIDGE_PACKETS
:
2420 local
->bridge_packets
= value
;
2423 case PRISM2_PARAM_AP_AUTH_ALGS
:
2424 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
2425 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
2426 sdata
->u
.sta
.auth_algs
= value
;
2431 case PRISM2_PARAM_DTIM_PERIOD
:
2434 else if (sdata
->type
!= IEEE80211_IF_TYPE_AP
)
2437 sdata
->u
.ap
.dtim_period
= value
;
2440 case PRISM2_PARAM_IEEE_802_1X
:
2441 sdata
->ieee802_1x
= value
;
2442 if (local
->ops
->set_ieee8021x
&&
2443 local
->ops
->set_ieee8021x(local_to_hw(local
), value
))
2444 printk(KERN_DEBUG
"%s: failed to set IEEE 802.1X (%d) "
2445 "for low-level driver\n", dev
->name
, value
);
2448 case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES
:
2449 local
->cts_protect_erp_frames
= value
;
2452 case PRISM2_PARAM_DROP_UNENCRYPTED
:
2453 sdata
->drop_unencrypted
= value
;
2456 case PRISM2_PARAM_PREAMBLE
:
2457 local
->short_preamble
= value
;
2460 case PRISM2_PARAM_STAT_TIME
:
2461 if (!local
->stat_time
&& value
) {
2462 local
->stat_timer
.expires
= jiffies
+ HZ
* value
/ 100;
2463 add_timer(&local
->stat_timer
);
2464 } else if (local
->stat_time
&& !value
) {
2465 del_timer_sync(&local
->stat_timer
);
2467 local
->stat_time
= value
;
2469 case PRISM2_PARAM_SHORT_SLOT_TIME
:
2471 local
->hw
.conf
.flags
|= IEEE80211_CONF_SHORT_SLOT_TIME
;
2473 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_SHORT_SLOT_TIME
;
2474 if (ieee80211_hw_config(local
))
2478 case PRISM2_PARAM_PRIVACY_INVOKED
:
2479 if (local
->ops
->set_privacy_invoked
)
2480 ret
= local
->ops
->set_privacy_invoked(
2481 local_to_hw(local
), value
);
2484 case PRISM2_PARAM_TEST_MODE
:
2485 ret
= ieee80211_ioctl_test_mode(dev
, value
);
2488 case PRISM2_PARAM_NEXT_MODE
:
2489 local
->next_mode
= value
;
2492 case PRISM2_PARAM_CLEAR_KEYS
:
2493 ret
= ieee80211_ioctl_clear_keys(dev
);
2496 case PRISM2_PARAM_RADIO_ENABLED
:
2497 ret
= ieee80211_ioctl_set_radio_enabled(dev
, value
);
2500 case PRISM2_PARAM_ANTENNA_SEL
:
2501 local
->hw
.conf
.antenna_sel
= value
;
2502 if (ieee80211_hw_config(local
))
2506 case PRISM2_PARAM_ANTENNA_MODE
:
2507 local
->hw
.conf
.antenna_mode
= value
;
2508 if (ieee80211_hw_config(local
))
2512 case PRISM2_PARAM_BROADCAST_SSID
:
2513 if ((value
< 0) || (value
> 1))
2516 local
->hw
.conf
.flags
|= IEEE80211_CONF_SSID_HIDDEN
;
2518 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_SSID_HIDDEN
;
2521 case PRISM2_PARAM_STA_ANTENNA_SEL
:
2522 local
->sta_antenna_sel
= value
;
2525 case PRISM2_PARAM_FORCE_UNICAST_RATE
:
2526 ret
= ieee80211_ioctl_force_unicast_rate(dev
, sdata
, value
);
2529 case PRISM2_PARAM_MAX_RATECTRL_RATE
:
2530 ret
= ieee80211_ioctl_max_ratectrl_rate(dev
, sdata
, value
);
2533 case PRISM2_PARAM_RATE_CTRL_NUM_UP
:
2534 local
->rate_ctrl_num_up
= value
;
2537 case PRISM2_PARAM_RATE_CTRL_NUM_DOWN
:
2538 local
->rate_ctrl_num_down
= value
;
2541 case PRISM2_PARAM_TX_POWER_REDUCTION
:
2545 local
->hw
.conf
.tx_power_reduction
= value
;
2548 case PRISM2_PARAM_EAPOL
:
2549 sdata
->eapol
= value
;
2552 case PRISM2_PARAM_KEY_TX_RX_THRESHOLD
:
2553 local
->key_tx_rx_threshold
= value
;
2556 case PRISM2_PARAM_KEY_INDEX
:
2557 if (value
< 0 || value
>= NUM_DEFAULT_KEYS
)
2559 else if (!sdata
->keys
[value
])
2562 sdata
->default_key
= sdata
->keys
[value
];
2565 case PRISM2_PARAM_DEFAULT_WEP_ONLY
:
2566 ret
= ieee80211_ioctl_default_wep_only(local
, value
);
2569 case PRISM2_PARAM_WIFI_WME_NOACK_TEST
:
2570 local
->wifi_wme_noack_test
= value
;
2573 case PRISM2_PARAM_ALLOW_BROADCAST_ALWAYS
:
2574 local
->allow_broadcast_always
= value
;
2577 case PRISM2_PARAM_SCAN_FLAGS
:
2578 local
->scan_flags
= value
;
2581 case PRISM2_PARAM_MIXED_CELL
:
2582 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
2583 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
2586 sdata
->u
.sta
.mixed_cell
= !!value
;
2589 case PRISM2_PARAM_KEY_MGMT
:
2590 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
2593 sdata
->u
.sta
.key_mgmt
= value
;
2596 case PRISM2_PARAM_HW_MODES
:
2597 local
->enabled_modes
= value
;
2600 case PRISM2_PARAM_CREATE_IBSS
:
2601 if (sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
2604 sdata
->u
.sta
.create_ibss
= !!value
;
2606 case PRISM2_PARAM_WMM_ENABLED
:
2607 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
2608 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
2611 sdata
->u
.sta
.wmm_enabled
= !!value
;
2613 case PRISM2_PARAM_RADAR_DETECT
:
2614 local
->hw
.conf
.radar_detect
= value
;
2616 case PRISM2_PARAM_SPECTRUM_MGMT
:
2617 local
->hw
.conf
.spect_mgmt
= value
;
2619 case PRISM2_PARAM_MGMT_IF
:
2622 ret
= ieee80211_if_add_mgmt(local
);
2623 } else if (value
== 0) {
2625 ieee80211_if_del_mgmt(local
);
2629 case PRISM2_PARAM_USER_SPACE_MLME
:
2630 local
->user_space_mlme
= value
;
2641 static int ieee80211_ioctl_get_prism2_param(struct net_device
*dev
,
2642 struct iw_request_info
*info
,
2643 void *wrqu
, char *extra
)
2645 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2646 struct ieee80211_sub_if_data
*sdata
;
2647 int *param
= (int *) extra
;
2650 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2653 case PRISM2_PARAM_BEACON_INT
:
2654 *param
= local
->hw
.conf
.beacon_int
;
2657 case PRISM2_PARAM_AP_BRIDGE_PACKETS
:
2658 *param
= local
->bridge_packets
;
2661 case PRISM2_PARAM_AP_AUTH_ALGS
:
2662 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
2663 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
2664 *param
= sdata
->u
.sta
.auth_algs
;
2669 case PRISM2_PARAM_DTIM_PERIOD
:
2670 if (sdata
->type
!= IEEE80211_IF_TYPE_AP
)
2673 *param
= sdata
->u
.ap
.dtim_period
;
2676 case PRISM2_PARAM_IEEE_802_1X
:
2677 *param
= sdata
->ieee802_1x
;
2680 case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES
:
2681 *param
= local
->cts_protect_erp_frames
;
2684 case PRISM2_PARAM_DROP_UNENCRYPTED
:
2685 *param
= sdata
->drop_unencrypted
;
2688 case PRISM2_PARAM_PREAMBLE
:
2689 *param
= local
->short_preamble
;
2692 case PRISM2_PARAM_STAT_TIME
:
2693 *param
= local
->stat_time
;
2695 case PRISM2_PARAM_SHORT_SLOT_TIME
:
2696 *param
= !!(local
->hw
.conf
.flags
& IEEE80211_CONF_SHORT_SLOT_TIME
);
2699 case PRISM2_PARAM_NEXT_MODE
:
2700 *param
= local
->next_mode
;
2703 case PRISM2_PARAM_ANTENNA_SEL
:
2704 *param
= local
->hw
.conf
.antenna_sel
;
2707 case PRISM2_PARAM_ANTENNA_MODE
:
2708 *param
= local
->hw
.conf
.antenna_mode
;
2711 case PRISM2_PARAM_BROADCAST_SSID
:
2712 *param
= !!(local
->hw
.conf
.flags
& IEEE80211_CONF_SSID_HIDDEN
);
2715 case PRISM2_PARAM_STA_ANTENNA_SEL
:
2716 *param
= local
->sta_antenna_sel
;
2719 case PRISM2_PARAM_RATE_CTRL_NUM_UP
:
2720 *param
= local
->rate_ctrl_num_up
;
2723 case PRISM2_PARAM_RATE_CTRL_NUM_DOWN
:
2724 *param
= local
->rate_ctrl_num_down
;
2727 case PRISM2_PARAM_TX_POWER_REDUCTION
:
2728 *param
= local
->hw
.conf
.tx_power_reduction
;
2731 case PRISM2_PARAM_EAPOL
:
2732 *param
= sdata
->eapol
;
2735 case PRISM2_PARAM_KEY_TX_RX_THRESHOLD
:
2736 *param
= local
->key_tx_rx_threshold
;
2739 case PRISM2_PARAM_KEY_INDEX
:
2740 if (!sdata
->default_key
)
2742 else if (sdata
->default_key
== sdata
->keys
[0])
2744 else if (sdata
->default_key
== sdata
->keys
[1])
2746 else if (sdata
->default_key
== sdata
->keys
[2])
2748 else if (sdata
->default_key
== sdata
->keys
[3])
2754 case PRISM2_PARAM_DEFAULT_WEP_ONLY
:
2755 *param
= local
->default_wep_only
;
2758 case PRISM2_PARAM_WIFI_WME_NOACK_TEST
:
2759 *param
= local
->wifi_wme_noack_test
;
2762 case PRISM2_PARAM_ALLOW_BROADCAST_ALWAYS
:
2763 *param
= local
->allow_broadcast_always
;
2766 case PRISM2_PARAM_SCAN_FLAGS
:
2767 *param
= local
->scan_flags
;
2770 case PRISM2_PARAM_HW_MODES
:
2771 *param
= local
->enabled_modes
;
2774 case PRISM2_PARAM_CREATE_IBSS
:
2775 if (sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
2778 *param
= !!sdata
->u
.sta
.create_ibss
;
2781 case PRISM2_PARAM_MIXED_CELL
:
2782 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
2783 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
2786 *param
= !!sdata
->u
.sta
.mixed_cell
;
2789 case PRISM2_PARAM_KEY_MGMT
:
2790 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
2793 *param
= sdata
->u
.sta
.key_mgmt
;
2795 case PRISM2_PARAM_WMM_ENABLED
:
2796 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
2797 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
2800 *param
= !!sdata
->u
.sta
.wmm_enabled
;
2802 case PRISM2_PARAM_MGMT_IF
:
2804 *param
= local
->apdev
->ifindex
;
2808 case PRISM2_PARAM_USER_SPACE_MLME
:
2809 *param
= local
->user_space_mlme
;
2821 static int ieee80211_ioctl_test_param(struct net_device
*dev
,
2822 struct iw_request_info
*info
,
2823 void *wrqu
, char *extra
)
2825 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2826 int *i
= (int *) extra
;
2828 int value
= *(i
+ 1);
2830 if (!capable(CAP_NET_ADMIN
))
2833 if (local
->ops
->test_param
)
2834 return local
->ops
->test_param(local_to_hw(local
),
2841 static int ieee80211_ioctl_siwmlme(struct net_device
*dev
,
2842 struct iw_request_info
*info
,
2843 struct iw_point
*data
, char *extra
)
2845 struct ieee80211_sub_if_data
*sdata
;
2846 struct iw_mlme
*mlme
= (struct iw_mlme
*) extra
;
2848 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2849 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
2850 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
2853 switch (mlme
->cmd
) {
2854 case IW_MLME_DEAUTH
:
2855 /* TODO: mlme->addr.sa_data */
2856 return ieee80211_sta_deauthenticate(dev
, mlme
->reason_code
);
2857 case IW_MLME_DISASSOC
:
2858 /* TODO: mlme->addr.sa_data */
2859 return ieee80211_sta_disassociate(dev
, mlme
->reason_code
);
2866 static int ieee80211_ioctl_siwencode(struct net_device
*dev
,
2867 struct iw_request_info
*info
,
2868 struct iw_point
*erq
, char *keybuf
)
2870 struct ieee80211_sub_if_data
*sdata
;
2871 int idx
, i
, alg
= ALG_WEP
;
2872 u8 bcaddr
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2874 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2876 idx
= erq
->flags
& IW_ENCODE_INDEX
;
2877 if (idx
< 1 || idx
> 4) {
2879 if (!sdata
->default_key
)
2881 else for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
2882 if (sdata
->default_key
== sdata
->keys
[i
]) {
2892 if (erq
->flags
& IW_ENCODE_DISABLED
)
2894 else if (erq
->length
== 0) {
2895 /* No key data - just set the default TX key index */
2896 if (sdata
->default_key
!= sdata
->keys
[idx
]) {
2897 if (sdata
->default_key
)
2898 ieee80211_key_sysfs_remove_default(sdata
);
2899 sdata
->default_key
= sdata
->keys
[idx
];
2900 if (sdata
->default_key
)
2901 ieee80211_key_sysfs_add_default(sdata
);
2906 return ieee80211_set_encryption(
2909 !sdata
->default_key
,
2910 NULL
, keybuf
, erq
->length
);
2914 static int ieee80211_ioctl_giwencode(struct net_device
*dev
,
2915 struct iw_request_info
*info
,
2916 struct iw_point
*erq
, char *key
)
2918 struct ieee80211_sub_if_data
*sdata
;
2921 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2923 idx
= erq
->flags
& IW_ENCODE_INDEX
;
2924 if (idx
< 1 || idx
> 4) {
2926 if (!sdata
->default_key
)
2928 else for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
2929 if (sdata
->default_key
== sdata
->keys
[i
]) {
2939 erq
->flags
= idx
+ 1;
2941 if (!sdata
->keys
[idx
]) {
2943 erq
->flags
|= IW_ENCODE_DISABLED
;
2947 memcpy(key
, sdata
->keys
[idx
]->key
,
2948 min((int)erq
->length
, sdata
->keys
[idx
]->keylen
));
2949 erq
->length
= sdata
->keys
[idx
]->keylen
;
2950 erq
->flags
|= IW_ENCODE_ENABLED
;
2956 static int ieee80211_ioctl_siwgenie(struct net_device
*dev
,
2957 struct iw_request_info
*info
,
2958 struct iw_point
*data
, char *extra
)
2960 return ieee80211_set_gen_ie(dev
, extra
, data
->length
);
2964 static int ieee80211_ioctl_siwauth(struct net_device
*dev
,
2965 struct iw_request_info
*info
,
2966 struct iw_param
*data
, char *extra
)
2968 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2969 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2972 switch (data
->flags
& IW_AUTH_INDEX
) {
2973 case IW_AUTH_WPA_VERSION
:
2974 case IW_AUTH_CIPHER_PAIRWISE
:
2975 case IW_AUTH_CIPHER_GROUP
:
2976 case IW_AUTH_WPA_ENABLED
:
2977 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
2979 case IW_AUTH_KEY_MGMT
:
2980 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
2984 * TODO: sdata->u.sta.key_mgmt does not match with WE18
2985 * value completely; could consider modifying this to
2986 * be closer to WE18. For now, this value is not really
2987 * used for anything else than Privacy matching, so the
2988 * current code here should be more or less OK.
2990 if (data
->value
& IW_AUTH_KEY_MGMT_802_1X
) {
2991 sdata
->u
.sta
.key_mgmt
=
2992 IEEE80211_KEY_MGMT_WPA_EAP
;
2993 } else if (data
->value
& IW_AUTH_KEY_MGMT_PSK
) {
2994 sdata
->u
.sta
.key_mgmt
=
2995 IEEE80211_KEY_MGMT_WPA_PSK
;
2997 sdata
->u
.sta
.key_mgmt
=
2998 IEEE80211_KEY_MGMT_NONE
;
3002 case IW_AUTH_80211_AUTH_ALG
:
3003 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
3004 sdata
->type
== IEEE80211_IF_TYPE_IBSS
)
3005 sdata
->u
.sta
.auth_algs
= data
->value
;
3009 case IW_AUTH_PRIVACY_INVOKED
:
3010 if (local
->ops
->set_privacy_invoked
)
3011 ret
= local
->ops
->set_privacy_invoked(
3012 local_to_hw(local
), data
->value
);
3021 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
3022 static struct iw_statistics
*ieee80211_get_wireless_stats(struct net_device
*net_dev
)
3024 struct ieee80211_local
*local
= net_dev
->ieee80211_ptr
;
3025 struct iw_statistics
* wstats
= &local
->wstats
;
3026 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(net_dev
);
3027 struct sta_info
*sta
;
3028 static int tmp_level
= 0;
3029 static int tmp_qual
= 0;
3031 sta
= sta_info_get(local
, sdata
->u
.sta
.bssid
);
3033 wstats
->discard
.fragment
= 0;
3034 wstats
->discard
.misc
= 0;
3035 wstats
->qual
.qual
= 0;
3036 wstats
->qual
.level
= 0;
3037 wstats
->qual
.noise
= 0;
3038 wstats
->qual
.updated
= IW_QUAL_ALL_INVALID
;
3040 if (!tmp_level
) { /* get initial values */
3041 tmp_level
= sta
->last_signal
;
3042 tmp_qual
= sta
->last_rssi
;
3043 } else { /* smooth results */
3044 tmp_level
= (15 * tmp_level
+ sta
->last_signal
)/16;
3045 tmp_qual
= (15 * tmp_qual
+ sta
->last_rssi
)/16;
3047 wstats
->qual
.level
= tmp_level
;
3048 wstats
->qual
.qual
= 100*tmp_qual
/local
->hw
.maxssi
;
3049 wstats
->qual
.noise
= sta
->last_noise
;
3050 wstats
->qual
.updated
= IW_QUAL_ALL_UPDATED
| IW_QUAL_DBM
;
3056 static int ieee80211_ioctl_giwauth(struct net_device
*dev
,
3057 struct iw_request_info
*info
,
3058 struct iw_param
*data
, char *extra
)
3060 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3063 switch (data
->flags
& IW_AUTH_INDEX
) {
3064 case IW_AUTH_80211_AUTH_ALG
:
3065 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
3066 sdata
->type
== IEEE80211_IF_TYPE_IBSS
)
3067 data
->value
= sdata
->u
.sta
.auth_algs
;
3079 static int ieee80211_ioctl_siwencodeext(struct net_device
*dev
,
3080 struct iw_request_info
*info
,
3081 struct iw_point
*erq
, char *extra
)
3083 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3084 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*) extra
;
3088 case IW_ENCODE_ALG_NONE
:
3091 case IW_ENCODE_ALG_WEP
:
3094 case IW_ENCODE_ALG_TKIP
:
3097 case IW_ENCODE_ALG_CCMP
:
3104 if (erq
->flags
& IW_ENCODE_DISABLED
)
3107 idx
= erq
->flags
& IW_ENCODE_INDEX
;
3108 if (idx
< 1 || idx
> 4) {
3110 if (!sdata
->default_key
)
3112 else for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
3113 if (sdata
->default_key
== sdata
->keys
[i
]) {
3123 return ieee80211_set_encryption(dev
, ext
->addr
.sa_data
, idx
, alg
,
3125 IW_ENCODE_EXT_SET_TX_KEY
,
3126 NULL
, ext
->key
, ext
->key_len
);
3130 static const struct iw_priv_args ieee80211_ioctl_priv
[] = {
3131 { PRISM2_IOCTL_PRISM2_PARAM
,
3132 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 2, 0, "param" },
3133 { PRISM2_IOCTL_GET_PRISM2_PARAM
,
3134 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
3135 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1, "get_param" },
3136 { PRISM2_IOCTL_TEST_PARAM
,
3137 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 2, 0, "test_param" },
3141 int ieee80211_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
3143 struct iwreq
*wrq
= (struct iwreq
*) rq
;
3147 /* Private ioctls (iwpriv) that have not yet been converted
3148 * into new wireless extensions API */
3149 case PRISM2_IOCTL_TEST_PARAM
:
3150 ret
= ieee80211_ioctl_test_param(dev
, NULL
, &wrq
->u
,
3153 case PRISM2_IOCTL_HOSTAPD
:
3154 if (!capable(CAP_NET_ADMIN
)) ret
= -EPERM
;
3155 else ret
= ieee80211_ioctl_priv_hostapd(dev
, &wrq
->u
.data
);
3166 /* Structures to export the Wireless Handlers */
3168 static const iw_handler ieee80211_handler
[] =
3170 (iw_handler
) NULL
, /* SIOCSIWCOMMIT */
3171 (iw_handler
) ieee80211_ioctl_giwname
, /* SIOCGIWNAME */
3172 (iw_handler
) NULL
, /* SIOCSIWNWID */
3173 (iw_handler
) NULL
, /* SIOCGIWNWID */
3174 (iw_handler
) ieee80211_ioctl_siwfreq
, /* SIOCSIWFREQ */
3175 (iw_handler
) ieee80211_ioctl_giwfreq
, /* SIOCGIWFREQ */
3176 (iw_handler
) ieee80211_ioctl_siwmode
, /* SIOCSIWMODE */
3177 (iw_handler
) ieee80211_ioctl_giwmode
, /* SIOCGIWMODE */
3178 (iw_handler
) NULL
, /* SIOCSIWSENS */
3179 (iw_handler
) NULL
, /* SIOCGIWSENS */
3180 (iw_handler
) NULL
/* not used */, /* SIOCSIWRANGE */
3181 (iw_handler
) ieee80211_ioctl_giwrange
, /* SIOCGIWRANGE */
3182 (iw_handler
) NULL
/* not used */, /* SIOCSIWPRIV */
3183 (iw_handler
) NULL
/* kernel code */, /* SIOCGIWPRIV */
3184 (iw_handler
) NULL
/* not used */, /* SIOCSIWSTATS */
3185 (iw_handler
) NULL
/* kernel code */, /* SIOCGIWSTATS */
3186 iw_handler_set_spy
, /* SIOCSIWSPY */
3187 iw_handler_get_spy
, /* SIOCGIWSPY */
3188 iw_handler_set_thrspy
, /* SIOCSIWTHRSPY */
3189 iw_handler_get_thrspy
, /* SIOCGIWTHRSPY */
3190 (iw_handler
) ieee80211_ioctl_siwap
, /* SIOCSIWAP */
3191 (iw_handler
) ieee80211_ioctl_giwap
, /* SIOCGIWAP */
3192 (iw_handler
) ieee80211_ioctl_siwmlme
, /* SIOCSIWMLME */
3193 (iw_handler
) NULL
, /* SIOCGIWAPLIST */
3194 (iw_handler
) ieee80211_ioctl_siwscan
, /* SIOCSIWSCAN */
3195 (iw_handler
) ieee80211_ioctl_giwscan
, /* SIOCGIWSCAN */
3196 (iw_handler
) ieee80211_ioctl_siwessid
, /* SIOCSIWESSID */
3197 (iw_handler
) ieee80211_ioctl_giwessid
, /* SIOCGIWESSID */
3198 (iw_handler
) NULL
, /* SIOCSIWNICKN */
3199 (iw_handler
) NULL
, /* SIOCGIWNICKN */
3200 (iw_handler
) NULL
, /* -- hole -- */
3201 (iw_handler
) NULL
, /* -- hole -- */
3202 (iw_handler
) NULL
, /* SIOCSIWRATE */
3203 (iw_handler
) NULL
, /* SIOCGIWRATE */
3204 (iw_handler
) ieee80211_ioctl_siwrts
, /* SIOCSIWRTS */
3205 (iw_handler
) ieee80211_ioctl_giwrts
, /* SIOCGIWRTS */
3206 (iw_handler
) ieee80211_ioctl_siwfrag
, /* SIOCSIWFRAG */
3207 (iw_handler
) ieee80211_ioctl_giwfrag
, /* SIOCGIWFRAG */
3208 (iw_handler
) NULL
, /* SIOCSIWTXPOW */
3209 (iw_handler
) NULL
, /* SIOCGIWTXPOW */
3210 (iw_handler
) ieee80211_ioctl_siwretry
, /* SIOCSIWRETRY */
3211 (iw_handler
) ieee80211_ioctl_giwretry
, /* SIOCGIWRETRY */
3212 (iw_handler
) ieee80211_ioctl_siwencode
, /* SIOCSIWENCODE */
3213 (iw_handler
) ieee80211_ioctl_giwencode
, /* SIOCGIWENCODE */
3214 (iw_handler
) NULL
, /* SIOCSIWPOWER */
3215 (iw_handler
) NULL
, /* SIOCGIWPOWER */
3216 (iw_handler
) NULL
, /* -- hole -- */
3217 (iw_handler
) NULL
, /* -- hole -- */
3218 (iw_handler
) ieee80211_ioctl_siwgenie
, /* SIOCSIWGENIE */
3219 (iw_handler
) NULL
, /* SIOCGIWGENIE */
3220 (iw_handler
) ieee80211_ioctl_siwauth
, /* SIOCSIWAUTH */
3221 (iw_handler
) ieee80211_ioctl_giwauth
, /* SIOCGIWAUTH */
3222 (iw_handler
) ieee80211_ioctl_siwencodeext
, /* SIOCSIWENCODEEXT */
3223 (iw_handler
) NULL
, /* SIOCGIWENCODEEXT */
3224 (iw_handler
) NULL
, /* SIOCSIWPMKSA */
3225 (iw_handler
) NULL
, /* -- hole -- */
3228 static const iw_handler ieee80211_private_handler
[] =
3229 { /* SIOCIWFIRSTPRIV + */
3230 (iw_handler
) ieee80211_ioctl_prism2_param
, /* 0 */
3231 (iw_handler
) ieee80211_ioctl_get_prism2_param
, /* 1 */
3234 const struct iw_handler_def ieee80211_iw_handler_def
=
3236 .num_standard
= sizeof(ieee80211_handler
) / sizeof(iw_handler
),
3237 .num_private
= sizeof(ieee80211_private_handler
) /
3239 .num_private_args
= sizeof(ieee80211_ioctl_priv
) /
3240 sizeof(struct iw_priv_args
),
3241 .standard
= (iw_handler
*) ieee80211_handler
,
3242 .private = (iw_handler
*) ieee80211_private_handler
,
3243 .private_args
= (struct iw_priv_args
*) ieee80211_ioctl_priv
,
3244 .get_wireless_stats
= ieee80211_get_wireless_stats
,
3247 /* Wireless handlers for master interface */
3249 static const iw_handler ieee80211_master_handler
[] =
3251 [SIOCGIWNAME
- SIOCIWFIRST
] = (iw_handler
) ieee80211_ioctl_giwname
,
3252 [SIOCSIWFREQ
- SIOCIWFIRST
] = (iw_handler
) ieee80211_ioctl_siwfreq
,
3253 [SIOCGIWFREQ
- SIOCIWFIRST
] = (iw_handler
) ieee80211_ioctl_giwfreq
,
3254 [SIOCGIWRANGE
- SIOCIWFIRST
] = (iw_handler
) ieee80211_ioctl_giwrange
,
3255 [SIOCSIWRTS
- SIOCIWFIRST
] = (iw_handler
) ieee80211_ioctl_siwrts
,
3256 [SIOCGIWRTS
- SIOCIWFIRST
] = (iw_handler
) ieee80211_ioctl_giwrts
,
3257 [SIOCSIWFRAG
- SIOCIWFIRST
] = (iw_handler
) ieee80211_ioctl_siwfrag
,
3258 [SIOCGIWFRAG
- SIOCIWFIRST
] = (iw_handler
) ieee80211_ioctl_giwfrag
,
3259 [SIOCSIWRETRY
- SIOCIWFIRST
] = (iw_handler
) ieee80211_ioctl_siwretry
,
3260 [SIOCGIWRETRY
- SIOCIWFIRST
] = (iw_handler
) ieee80211_ioctl_giwretry
,
3263 const struct iw_handler_def ieee80211_iw_master_handler_def
=
3265 .num_standard
= sizeof(ieee80211_master_handler
) / sizeof(iw_handler
),
3266 .standard
= ieee80211_master_handler
,