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");
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
= wdev_priv(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
;
168 static int ieee80211_ioctl_flush(struct net_device
*dev
,
169 struct prism2_hostapd_param
*param
)
171 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
172 sta_info_flush(local
, NULL
);
177 /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
178 struct iapp_layer2_update
{
179 u8 da
[ETH_ALEN
]; /* broadcast */
180 u8 sa
[ETH_ALEN
]; /* STA addr */
186 } __attribute__ ((packed
));
188 static void ieee80211_send_layer2_update(struct net_device
*dev
,
191 struct iapp_layer2_update
*msg
;
194 /* Send Level 2 Update Frame to update forwarding tables in layer 2
197 skb
= dev_alloc_skb(sizeof(*msg
));
200 msg
= (struct iapp_layer2_update
*) skb_put(skb
, sizeof(*msg
));
202 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
203 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
205 memset(msg
->da
, 0xff, ETH_ALEN
);
206 memcpy(msg
->sa
, addr
, ETH_ALEN
);
209 msg
->ssap
= 0x01; /* NULL LSAP, CR Bit: Response */
210 msg
->control
= 0xaf; /* XID response lsb.1111F101.
211 * F=0 (no poll command; unsolicited frame) */
212 msg
->xid_info
[0] = 0x81; /* XID format identifier */
213 msg
->xid_info
[1] = 1; /* LLC types/classes: Type 1 LLC */
214 msg
->xid_info
[2] = 0; /* XID sender's receive window size (RW) */
217 skb
->protocol
= eth_type_trans(skb
, dev
);
218 memset(skb
->cb
, 0, sizeof(skb
->cb
));
223 static int ieee80211_ioctl_add_sta(struct net_device
*dev
,
224 struct prism2_hostapd_param
*param
)
226 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
227 struct sta_info
*sta
;
230 struct ieee80211_sub_if_data
*sdata
;
231 struct ieee80211_hw_mode
*mode
;
232 int add_key_entry
= 1;
234 /* Prevent a race with changing the rate control algorithm */
235 if (!netif_running(dev
))
238 sta
= sta_info_get(local
, param
->sta_addr
);
241 sta
= sta_info_add(local
, dev
, param
->sta_addr
, GFP_KERNEL
);
246 if (sta
->dev
!= dev
) {
247 /* Binding STA to a new interface, so remove all references to
249 spin_lock_bh(&local
->sta_lock
);
250 sta_info_remove_aid_ptr(sta
);
251 spin_unlock_bh(&local
->sta_lock
);
255 * We "steal" the device in case someone owns it
256 * This will hurt WDS links and such when we have a
257 * WDS link and a client associating from the same station
260 sdata
= IEEE80211_DEV_TO_SUB_IF(sta
->dev
);
262 sta
->flags
|= WLAN_STA_AUTH
| WLAN_STA_ASSOC
;
263 sta
->aid
= param
->u
.add_sta
.aid
;
264 if (sta
->aid
> IEEE80211_MAX_AID
)
266 sta
->listen_interval
= param
->u
.add_sta
.listen_interval
;
269 mode
= local
->oper_hw_mode
;
270 for (i
= 0; i
< sizeof(param
->u
.add_sta
.supp_rates
); i
++) {
271 int rate
= (param
->u
.add_sta
.supp_rates
[i
] & 0x7f) * 5;
272 if (mode
->mode
== MODE_ATHEROS_TURBO
||
273 mode
->mode
== MODE_ATHEROS_TURBOG
)
275 for (j
= 0; j
< mode
->num_rates
; j
++) {
276 if (mode
->rates
[j
].rate
== rate
)
281 sta
->supp_rates
= rates
;
283 rate_control_rate_init(sta
, local
);
285 if (param
->u
.add_sta
.wds_flags
& 0x01)
286 sta
->flags
|= WLAN_STA_WDS
;
288 sta
->flags
&= ~WLAN_STA_WDS
;
290 if (add_key_entry
&& !sta
->key
&& !sdata
->default_key
&&
291 local
->ops
->set_key
) {
292 struct ieee80211_key_conf conf
;
293 /* Add key cache entry with NULL key type because this may used
294 * for TX filtering. */
295 memset(&conf
, 0, sizeof(conf
));
296 conf
.hw_key_idx
= HW_KEY_IDX_INVALID
;
298 conf
.flags
|= IEEE80211_KEY_FORCE_SW_ENCRYPT
;
299 if (local
->ops
->set_key(local_to_hw(local
), SET_KEY
,
300 sta
->addr
, &conf
, sta
->aid
)) {
301 sta
->key_idx_compression
= HW_KEY_IDX_INVALID
;
303 sta
->key_idx_compression
= conf
.hw_key_idx
;
309 if (sdata
->type
== IEEE80211_IF_TYPE_AP
||
310 sdata
->type
== IEEE80211_IF_TYPE_VLAN
)
311 ieee80211_send_layer2_update(dev
, param
->sta_addr
);
317 static int ieee80211_ioctl_remove_sta(struct net_device
*dev
,
318 struct prism2_hostapd_param
*param
)
320 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
321 struct sta_info
*sta
;
323 sta
= sta_info_get(local
, param
->sta_addr
);
326 sta_info_free(sta
, 0);
329 return sta
? 0 : -ENOENT
;
333 static int ieee80211_ioctl_get_dot11counterstable(struct net_device
*dev
,
334 struct prism2_hostapd_param
*param
)
336 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
337 struct ieee80211_low_level_stats stats
;
339 memset(&stats
, 0, sizeof(stats
));
340 if (local
->ops
->get_stats
)
341 local
->ops
->get_stats(local_to_hw(local
), &stats
);
342 param
->u
.dot11CountersTable
.dot11TransmittedFragmentCount
=
343 local
->dot11TransmittedFragmentCount
;
344 param
->u
.dot11CountersTable
.dot11MulticastTransmittedFrameCount
=
345 local
->dot11MulticastTransmittedFrameCount
;
346 param
->u
.dot11CountersTable
.dot11ReceivedFragmentCount
=
347 local
->dot11ReceivedFragmentCount
;
348 param
->u
.dot11CountersTable
.dot11MulticastReceivedFrameCount
=
349 local
->dot11MulticastReceivedFrameCount
;
350 param
->u
.dot11CountersTable
.dot11TransmittedFrameCount
=
351 local
->dot11TransmittedFrameCount
;
352 param
->u
.dot11CountersTable
.dot11FCSErrorCount
=
353 stats
.dot11FCSErrorCount
;
354 param
->u
.dot11CountersTable
.dot11ACKFailureCount
=
355 stats
.dot11ACKFailureCount
;
356 param
->u
.dot11CountersTable
.dot11RTSFailureCount
=
357 stats
.dot11RTSFailureCount
;
358 param
->u
.dot11CountersTable
.dot11RTSSuccessCount
=
359 stats
.dot11RTSSuccessCount
;
365 static int ieee80211_ioctl_get_info_sta(struct net_device
*dev
,
366 struct prism2_hostapd_param
*param
)
368 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
369 struct ieee80211_hw_mode
*mode
;
370 struct sta_info
*sta
;
372 if (is_broadcast_ether_addr(param
->sta_addr
)) {
373 struct net_device_stats
*stats
;
375 stats
= ieee80211_dev_stats(local
->mdev
);
376 param
->u
.get_info_sta
.rx_bytes
= stats
->rx_bytes
;
377 param
->u
.get_info_sta
.tx_bytes
= stats
->tx_bytes
;
378 /* go through all STAs and get STA with lowest max. rate */
379 param
->u
.get_info_sta
.current_tx_rate
=
380 sta_info_min_txrate_get(local
);
384 sta
= sta_info_get(local
, param
->sta_addr
);
389 param
->u
.get_info_sta
.inactive_msec
=
390 jiffies_to_msecs(jiffies
- sta
->last_rx
);
391 param
->u
.get_info_sta
.rx_packets
= sta
->rx_packets
;
392 param
->u
.get_info_sta
.tx_packets
= sta
->tx_packets
;
393 param
->u
.get_info_sta
.rx_bytes
= sta
->rx_bytes
;
394 param
->u
.get_info_sta
.tx_bytes
= sta
->tx_bytes
;
395 param
->u
.get_info_sta
.channel_use
= sta
->channel_use
;
396 param
->u
.get_info_sta
.flags
= sta
->flags
;
397 mode
= local
->oper_hw_mode
;
398 if (sta
->txrate
>= 0 && sta
->txrate
< mode
->num_rates
)
399 param
->u
.get_info_sta
.current_tx_rate
=
400 mode
->rates
[sta
->txrate
].rate
;
401 param
->u
.get_info_sta
.num_ps_buf_frames
=
402 skb_queue_len(&sta
->ps_tx_buf
);
403 param
->u
.get_info_sta
.tx_retry_failed
= sta
->tx_retry_failed
;
404 param
->u
.get_info_sta
.tx_retry_count
= sta
->tx_retry_count
;
405 param
->u
.get_info_sta
.last_rssi
= sta
->last_rssi
;
406 param
->u
.get_info_sta
.last_ack_rssi
= sta
->last_ack_rssi
[2];
414 static int ieee80211_ioctl_set_flags_sta(struct net_device
*dev
,
415 struct prism2_hostapd_param
*param
)
417 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
418 struct sta_info
*sta
;
420 sta
= sta_info_get(local
, param
->sta_addr
);
422 sta
->flags
|= param
->u
.set_flags_sta
.flags_or
;
423 sta
->flags
&= param
->u
.set_flags_sta
.flags_and
;
424 if (local
->ops
->set_port_auth
&&
425 (param
->u
.set_flags_sta
.flags_or
& WLAN_STA_AUTHORIZED
) &&
426 local
->ops
->set_port_auth(local_to_hw(local
), sta
->addr
, 1))
427 printk(KERN_DEBUG
"%s: failed to set low-level driver "
428 "PAE state (authorized) for " MAC_FMT
"\n",
429 dev
->name
, MAC_ARG(sta
->addr
));
430 if (local
->ops
->set_port_auth
&&
431 !(param
->u
.set_flags_sta
.flags_and
& WLAN_STA_AUTHORIZED
) &&
432 local
->ops
->set_port_auth(local_to_hw(local
), sta
->addr
, 0))
433 printk(KERN_DEBUG
"%s: failed to set low-level driver "
434 "PAE state (unauthorized) for " MAC_FMT
"\n",
435 dev
->name
, MAC_ARG(sta
->addr
));
439 return sta
? 0 : -ENOENT
;
443 int ieee80211_set_hw_encryption(struct net_device
*dev
,
444 struct sta_info
*sta
, u8 addr
[ETH_ALEN
],
445 struct ieee80211_key
*key
)
447 struct ieee80211_key_conf
*keyconf
= NULL
;
448 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
451 /* default to sw encryption; this will be cleared by low-level
452 * driver if the hw supports requested encryption */
454 key
->force_sw_encrypt
= 1;
456 if (key
&& local
->ops
->set_key
&&
457 (keyconf
= ieee80211_key_data2conf(local
, key
))) {
458 if (local
->ops
->set_key(local_to_hw(local
), SET_KEY
, addr
,
459 keyconf
, sta
? sta
->aid
: 0)) {
460 rc
= HOSTAP_CRYPT_ERR_KEY_SET_FAILED
;
461 key
->force_sw_encrypt
= 1;
462 key
->hw_key_idx
= HW_KEY_IDX_INVALID
;
464 key
->force_sw_encrypt
=
465 !!(keyconf
->flags
& IEEE80211_KEY_FORCE_SW_ENCRYPT
);
477 static int ieee80211_set_encryption(struct net_device
*dev
, u8
*sta_addr
,
478 int idx
, int alg
, int set_tx_key
, u32
*err
,
479 const u8
*_key
, size_t key_len
)
481 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
483 struct sta_info
*sta
;
484 struct ieee80211_key
*key
, *old_key
;
486 struct ieee80211_key_conf
*keyconf
;
487 struct ieee80211_sub_if_data
*sdata
;
489 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
491 if (is_broadcast_ether_addr(sta_addr
)) {
493 if (idx
>= NUM_DEFAULT_KEYS
) {
494 printk(KERN_DEBUG
"%s: set_encrypt - invalid idx=%d\n",
498 key
= sdata
->keys
[idx
];
500 /* TODO: consider adding hwaccel support for these; at least
501 * Atheros key cache should be able to handle this since AP is
502 * only transmitting frames with default keys. */
503 /* FIX: hw key cache can be used when only one virtual
504 * STA is associated with each AP. If more than one STA
505 * is associated to the same AP, software encryption
506 * must be used. This should be done automatically
507 * based on configured station devices. For the time
508 * being, this can be only set at compile time. */
512 printk(KERN_DEBUG
"%s: set_encrypt - non-zero idx for "
513 "individual key\n", dev
->name
);
517 sta
= sta_info_get(local
, sta_addr
);
520 *err
= HOSTAP_CRYPT_ERR_UNKNOWN_ADDR
;
521 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
522 printk(KERN_DEBUG
"%s: set_encrypt - unknown addr "
524 dev
->name
, MAC_ARG(sta_addr
));
525 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
534 * Cannot configure default hwaccel keys with WEP algorithm, if
535 * any of the virtual interfaces is using static WEP
536 * configuration because hwaccel would otherwise try to decrypt
539 * For now, just disable WEP hwaccel for broadcast when there is
540 * possibility of conflict with default keys. This can maybe later be
541 * optimized by using non-default keys (at least with Atheros ar521x).
543 if (!sta
&& alg
== ALG_WEP
&& !local
->default_wep_only
&&
544 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
&&
545 sdata
->type
!= IEEE80211_IF_TYPE_AP
) {
549 if (local
->hw
.flags
& IEEE80211_HW_DEVICE_HIDES_WEP
) {
550 /* Software encryption cannot be used with devices that hide
551 * encryption from the host system, so always try to use
552 * hardware acceleration with such devices. */
556 if ((local
->hw
.flags
& IEEE80211_HW_NO_TKIP_WMM_HWACCEL
) &&
558 if (sta
&& (sta
->flags
& WLAN_STA_WME
)) {
559 /* Hardware does not support hwaccel with TKIP when using WMM.
563 else if (sdata
->type
== IEEE80211_IF_TYPE_STA
) {
564 sta
= sta_info_get(local
, sdata
->u
.sta
.bssid
);
566 if (sta
->flags
& WLAN_STA_WME
) {
575 if (alg
== ALG_NONE
) {
577 if (try_hwaccel
&& key
&&
578 key
->hw_key_idx
!= HW_KEY_IDX_INVALID
&&
579 local
->ops
->set_key
&&
580 (keyconf
= ieee80211_key_data2conf(local
, key
)) != NULL
&&
581 local
->ops
->set_key(local_to_hw(local
), DISABLE_KEY
,
582 sta_addr
, keyconf
, sta
? sta
->aid
: 0)) {
584 *err
= HOSTAP_CRYPT_ERR_KEY_SET_FAILED
;
585 printk(KERN_DEBUG
"%s: set_encrypt - low-level disable"
586 " failed\n", dev
->name
);
591 if (set_tx_key
|| sdata
->default_key
== key
) {
592 ieee80211_debugfs_key_remove_default(sdata
);
593 sdata
->default_key
= NULL
;
595 ieee80211_debugfs_key_remove(key
);
599 sdata
->keys
[idx
] = NULL
;
600 ieee80211_key_free(key
);
604 key
= ieee80211_key_alloc(sta
? NULL
: sdata
, idx
, key_len
,
611 /* default to sw encryption; low-level driver sets these if the
612 * requested encryption is supported */
613 key
->hw_key_idx
= HW_KEY_IDX_INVALID
;
614 key
->force_sw_encrypt
= 1;
618 key
->keylen
= key_len
;
619 memcpy(key
->key
, _key
, key_len
);
621 key
->default_tx_key
= 1;
623 if (alg
== ALG_CCMP
) {
624 /* Initialize AES key state here as an optimization
625 * so that it does not need to be initialized for every
627 key
->u
.ccmp
.tfm
= ieee80211_aes_key_setup_encrypt(
629 if (!key
->u
.ccmp
.tfm
) {
635 if (set_tx_key
|| sdata
->default_key
== old_key
) {
636 ieee80211_debugfs_key_remove_default(sdata
);
637 sdata
->default_key
= NULL
;
639 ieee80211_debugfs_key_remove(old_key
);
643 sdata
->keys
[idx
] = key
;
644 ieee80211_key_free(old_key
);
645 ieee80211_debugfs_key_add(local
, key
);
647 ieee80211_debugfs_key_sta_link(key
, sta
);
650 (alg
== ALG_WEP
|| alg
== ALG_TKIP
|| alg
== ALG_CCMP
)) {
651 int e
= ieee80211_set_hw_encryption(dev
, sta
, sta_addr
,
658 if (set_tx_key
|| (!sta
&& !sdata
->default_key
&& key
)) {
659 sdata
->default_key
= key
;
661 ieee80211_debugfs_key_add_default(sdata
);
663 if (local
->ops
->set_key_idx
&&
664 local
->ops
->set_key_idx(local_to_hw(local
), idx
))
665 printk(KERN_DEBUG
"%s: failed to set TX key idx for "
666 "low-level driver\n", dev
->name
);
675 ieee80211_key_free(key
);
683 static int ieee80211_ioctl_set_encryption(struct net_device
*dev
,
684 struct prism2_hostapd_param
*param
,
689 param
->u
.crypt
.err
= 0;
690 param
->u
.crypt
.alg
[HOSTAP_CRYPT_ALG_NAME_LEN
- 1] = '\0';
693 (int) ((char *) param
->u
.crypt
.key
- (char *) param
) +
694 param
->u
.crypt
.key_len
) {
695 printk(KERN_DEBUG
"%s: set_encrypt - invalid param_lem\n",
700 if (strcmp(param
->u
.crypt
.alg
, "none") == 0)
702 else if (strcmp(param
->u
.crypt
.alg
, "WEP") == 0)
704 else if (strcmp(param
->u
.crypt
.alg
, "TKIP") == 0) {
705 if (param
->u
.crypt
.key_len
!= ALG_TKIP_KEY_LEN
) {
706 printk(KERN_DEBUG
"%s: set_encrypt - invalid TKIP key "
707 "length %d\n", dev
->name
,
708 param
->u
.crypt
.key_len
);
712 } else if (strcmp(param
->u
.crypt
.alg
, "CCMP") == 0) {
713 if (param
->u
.crypt
.key_len
!= ALG_CCMP_KEY_LEN
) {
714 printk(KERN_DEBUG
"%s: set_encrypt - invalid CCMP key "
715 "length %d\n", dev
->name
,
716 param
->u
.crypt
.key_len
);
721 param
->u
.crypt
.err
= HOSTAP_CRYPT_ERR_UNKNOWN_ALG
;
722 printk(KERN_DEBUG
"%s: set_encrypt - unknown alg\n",
727 return ieee80211_set_encryption(
728 dev
, param
->sta_addr
,
729 param
->u
.crypt
.idx
, alg
,
730 param
->u
.crypt
.flags
& HOSTAP_CRYPT_FLAG_SET_TX_KEY
,
731 ¶m
->u
.crypt
.err
, param
->u
.crypt
.key
,
732 param
->u
.crypt
.key_len
);
736 static int ieee80211_ioctl_get_encryption(struct net_device
*dev
,
737 struct prism2_hostapd_param
*param
,
740 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
742 struct sta_info
*sta
;
743 struct ieee80211_key
**key
;
745 struct ieee80211_sub_if_data
*sdata
;
748 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
750 param
->u
.crypt
.err
= 0;
752 max_key_len
= param_len
-
753 (int) ((char *) param
->u
.crypt
.key
- (char *) param
);
757 if (is_broadcast_ether_addr(param
->sta_addr
)) {
759 if (param
->u
.crypt
.idx
>= NUM_DEFAULT_KEYS
) {
760 param
->u
.crypt
.idx
= sdata
->default_key
?
761 sdata
->default_key
->keyidx
: 0;
764 key
= &sdata
->keys
[param
->u
.crypt
.idx
];
766 sta
= sta_info_get(local
, param
->sta_addr
);
768 param
->u
.crypt
.err
= HOSTAP_CRYPT_ERR_UNKNOWN_ADDR
;
775 memset(param
->u
.crypt
.seq_counter
, 0, HOSTAP_SEQ_COUNTER_SIZE
);
777 memcpy(param
->u
.crypt
.alg
, "none", 5);
778 param
->u
.crypt
.key_len
= 0;
779 param
->u
.crypt
.idx
= 0xff;
781 switch ((*key
)->alg
) {
783 memcpy(param
->u
.crypt
.alg
, "WEP", 4);
790 memcpy(param
->u
.crypt
.alg
, "TKIP", 5);
791 if (local
->ops
->get_sequence_counter
) {
792 /* Get transmit counter from low level driver */
793 if (local
->ops
->get_sequence_counter(
797 IEEE80211_SEQ_COUNTER_TX
,
800 /* Error getting value from device */
804 /* Get it from our own local data */
805 iv32
= (*key
)->u
.tkip
.iv32
;
806 iv16
= (*key
)->u
.tkip
.iv16
;
808 pos
= param
->u
.crypt
.seq_counter
;
809 *pos
++ = iv16
& 0xff;
810 *pos
++ = (iv16
>> 8) & 0xff;
811 *pos
++ = iv32
& 0xff;
812 *pos
++ = (iv32
>> 8) & 0xff;
813 *pos
++ = (iv32
>> 16) & 0xff;
814 *pos
++ = (iv32
>> 24) & 0xff;
820 memcpy(param
->u
.crypt
.alg
, "CCMP", 5);
821 pos
= param
->u
.crypt
.seq_counter
;
822 pn
= (*key
)->u
.ccmp
.tx_pn
;
832 memcpy(param
->u
.crypt
.alg
, "unknown", 8);
836 if (max_key_len
< (*key
)->keylen
)
839 param
->u
.crypt
.key_len
= (*key
)->keylen
;
840 memcpy(param
->u
.crypt
.key
, (*key
)->key
,
852 #ifdef CONFIG_HOSTAPD_WPA_TESTING
853 static int ieee80211_ioctl_wpa_trigger(struct net_device
*dev
,
854 struct prism2_hostapd_param
*param
)
856 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
857 struct sta_info
*sta
;
859 if (is_broadcast_ether_addr(param
->sta_addr
)) {
860 local
->wpa_trigger
= param
->u
.wpa_trigger
.trigger
;
864 sta
= sta_info_get(local
, param
->sta_addr
);
866 printk(KERN_DEBUG
"%s: wpa_trigger - unknown addr\n",
871 sta
->wpa_trigger
= param
->u
.wpa_trigger
.trigger
;
876 #endif /* CONFIG_HOSTAPD_WPA_TESTING */
879 static int ieee80211_ioctl_set_rate_sets(struct net_device
*dev
,
880 struct prism2_hostapd_param
*param
,
883 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
884 u16
*pos
= (u16
*) param
->u
.set_rate_sets
.data
;
885 int left
= param_len
- ((u8
*) pos
- (u8
*) param
);
886 int i
, mode
, num_supp
, num_basic
, *supp
, *basic
, *prev
;
887 struct ieee80211_hw_mode
*hw_mode
;
889 mode
= param
->u
.set_rate_sets
.mode
;
890 num_supp
= param
->u
.set_rate_sets
.num_supported_rates
;
891 num_basic
= param
->u
.set_rate_sets
.num_basic_rates
;
893 if (left
< (num_supp
+ num_basic
) * 2) {
894 printk(KERN_WARNING
"%s: invalid length in hostapd set rate "
895 "sets ioctl (%d != %d)\n", dev
->name
, left
,
896 (num_supp
+ num_basic
) * 2);
900 supp
= (int *) kmalloc((num_supp
+ 1) * sizeof(int), GFP_KERNEL
);
901 basic
= (int *) kmalloc((num_basic
+ 1) * sizeof(int), GFP_KERNEL
);
903 if (!supp
|| !basic
) {
909 for (i
= 0; i
< num_supp
; i
++)
913 for (i
= 0; i
< num_basic
; i
++)
922 if (num_basic
== 0) {
927 prev
= local
->supp_rates
[mode
];
928 local
->supp_rates
[mode
] = supp
;
931 prev
= local
->basic_rates
[mode
];
932 local
->basic_rates
[mode
] = basic
;
935 /* TODO: should update STA TX rates and remove STAs if they
936 * do not have any remaining supported rates after the change
938 list_for_each_entry(hw_mode
, &local
->modes_list
, list
)
939 if (hw_mode
->mode
== mode
)
940 ieee80211_prepare_rates(local
, hw_mode
);
946 static int ieee80211_ioctl_add_if(struct net_device
*dev
,
947 struct prism2_hostapd_param
*param
,
950 u8
*pos
= param
->u
.if_info
.data
;
951 int left
= param_len
- ((u8
*) pos
- (u8
*) param
);
952 struct net_device
*new_dev
;
954 struct hostapd_if_wds
*wds
;
955 struct hostapd_if_bss
*bss
;
957 printk(KERN_WARNING
"PRISM2_HOSTAPD_ADD_IF ioctl is deprecated!");
958 switch (param
->u
.if_info
.type
) {
960 wds
= (struct hostapd_if_wds
*) param
->u
.if_info
.data
;
962 if (left
< sizeof(struct hostapd_if_wds
))
965 res
= ieee80211_if_add(dev
, param
->u
.if_info
.name
, &new_dev
,
966 IEEE80211_IF_TYPE_WDS
);
969 res
= ieee80211_if_update_wds(new_dev
, wds
->remote_addr
);
971 struct ieee80211_local
*local
=
972 wdev_priv(dev
->ieee80211_ptr
);
973 struct ieee80211_sub_if_data
*sdata
=
974 IEEE80211_DEV_TO_SUB_IF(new_dev
);
975 write_lock_bh(&local
->sub_if_lock
);
976 list_del(&sdata
->list
);
977 write_unlock_bh(&local
->sub_if_lock
);
978 __ieee80211_if_del(local
, sdata
);
982 if (left
< sizeof(struct hostapd_if_vlan
))
985 res
= ieee80211_if_add(dev
, param
->u
.if_info
.name
, NULL
,
986 IEEE80211_IF_TYPE_VLAN
);
989 bss
= (struct hostapd_if_bss
*) param
->u
.if_info
.data
;
991 if (left
< sizeof(struct hostapd_if_bss
))
994 res
= ieee80211_if_add(dev
, param
->u
.if_info
.name
, &new_dev
,
995 IEEE80211_IF_TYPE_AP
);
998 memcpy(new_dev
->dev_addr
, bss
->bssid
, ETH_ALEN
);
1001 if (left
< sizeof(struct hostapd_if_sta
))
1004 res
= ieee80211_if_add(dev
, param
->u
.if_info
.name
, NULL
,
1005 IEEE80211_IF_TYPE_STA
);
1014 static int ieee80211_ioctl_remove_if(struct net_device
*dev
,
1015 struct prism2_hostapd_param
*param
)
1019 switch (param
->u
.if_info
.type
) {
1021 type
= IEEE80211_IF_TYPE_WDS
;
1023 case HOSTAP_IF_VLAN
:
1024 type
= IEEE80211_IF_TYPE_VLAN
;
1027 type
= IEEE80211_IF_TYPE_AP
;
1030 type
= IEEE80211_IF_TYPE_STA
;
1036 return ieee80211_if_remove(dev
, param
->u
.if_info
.name
, type
);
1039 static int ieee80211_ioctl_update_if(struct net_device
*dev
,
1040 struct prism2_hostapd_param
*param
,
1043 u8
*pos
= param
->u
.if_info
.data
;
1044 int left
= param_len
- ((u8
*) pos
- (u8
*) param
);
1046 if (param
->u
.if_info
.type
== HOSTAP_IF_WDS
) {
1047 struct hostapd_if_wds
*wds
=
1048 (struct hostapd_if_wds
*) param
->u
.if_info
.data
;
1049 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1050 struct net_device
*wds_dev
= NULL
;
1051 struct ieee80211_sub_if_data
*sdata
;
1053 if (left
< sizeof(struct ieee80211_if_wds
))
1056 read_lock(&local
->sub_if_lock
);
1057 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
1058 if (strcmp(param
->u
.if_info
.name
,
1059 sdata
->dev
->name
) == 0) {
1060 wds_dev
= sdata
->dev
;
1064 read_unlock(&local
->sub_if_lock
);
1066 if (!wds_dev
|| sdata
->type
!= IEEE80211_IF_TYPE_WDS
)
1069 return ieee80211_if_update_wds(wds_dev
, wds
->remote_addr
);
1076 static int ieee80211_ioctl_scan_req(struct net_device
*dev
,
1077 struct prism2_hostapd_param
*param
,
1080 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1081 u8
*pos
= param
->u
.scan_req
.ssid
;
1082 int left
= param_len
- ((u8
*) pos
- (u8
*) param
);
1083 int len
= param
->u
.scan_req
.ssid_len
;
1085 if (local
->user_space_mlme
)
1088 if (!netif_running(dev
))
1091 if (left
< len
|| len
> IEEE80211_MAX_SSID_LEN
)
1094 return ieee80211_sta_req_scan(dev
, pos
, len
);
1098 static int ieee80211_ioctl_sta_get_state(struct net_device
*dev
,
1099 struct prism2_hostapd_param
*param
)
1101 struct ieee80211_sub_if_data
*sdata
;
1103 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1104 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
1105 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
1107 param
->u
.sta_get_state
.state
= sdata
->u
.sta
.state
;
1112 static int ieee80211_ioctl_mlme(struct net_device
*dev
,
1113 struct prism2_hostapd_param
*param
)
1115 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1116 struct ieee80211_sub_if_data
*sdata
;
1118 if (local
->user_space_mlme
)
1121 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1122 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
1123 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
1125 switch (param
->u
.mlme
.cmd
) {
1126 case MLME_STA_DEAUTH
:
1127 return ieee80211_sta_deauthenticate(dev
, param
->u
.mlme
.reason_code
);
1128 case MLME_STA_DISASSOC
:
1129 return ieee80211_sta_disassociate(dev
, param
->u
.mlme
.reason_code
);
1135 static int ieee80211_ioctl_get_load_stats(struct net_device
*dev
,
1136 struct prism2_hostapd_param
*param
)
1138 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1140 param
->u
.get_load_stats
.channel_use
= local
->channel_use
;
1141 /* if (param->u.get_load_stats.flags & LOAD_STATS_CLEAR)
1142 local->channel_use = 0; */ /* now it's not raw counter */
1148 static int ieee80211_ioctl_set_sta_vlan(struct net_device
*dev
,
1149 struct prism2_hostapd_param
*param
)
1151 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1152 struct sta_info
*sta
;
1154 sta
= sta_info_get(local
, param
->sta_addr
);
1156 struct net_device
*new_vlan_dev
;
1158 dev_get_by_name(param
->u
.set_sta_vlan
.vlan_name
);
1161 printk("%s: Station " MAC_FMT
" moved to vlan: %s\n",
1162 dev
->name
, MAC_ARG(param
->sta_addr
),
1163 new_vlan_dev
->name
);
1165 if (sta
->dev
!= new_vlan_dev
) {
1166 ieee80211_send_layer2_update(new_vlan_dev
,
1169 sta
->dev
= new_vlan_dev
;
1170 sta
->vlan_id
= param
->u
.set_sta_vlan
.vlan_id
;
1171 dev_put(new_vlan_dev
);
1176 return sta
? 0 : -ENOENT
;
1180 static int ieee80211_set_gen_ie(struct net_device
*dev
, u8
*ie
, size_t len
)
1182 struct ieee80211_sub_if_data
*sdata
;
1183 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1185 if (local
->user_space_mlme
)
1188 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1189 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
1190 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
1191 int ret
= ieee80211_sta_set_extra_ie(dev
, ie
, len
);
1194 sdata
->u
.sta
.auto_bssid_sel
= 0;
1195 ieee80211_sta_req_auth(dev
, &sdata
->u
.sta
);
1199 if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
1200 kfree(sdata
->u
.ap
.generic_elem
);
1201 sdata
->u
.ap
.generic_elem
= kmalloc(len
, GFP_KERNEL
);
1202 if (!sdata
->u
.ap
.generic_elem
)
1204 memcpy(sdata
->u
.ap
.generic_elem
, ie
, len
);
1205 sdata
->u
.ap
.generic_elem_len
= len
;
1206 return ieee80211_if_config(dev
);
1213 ieee80211_ioctl_set_generic_info_elem(struct net_device
*dev
,
1214 struct prism2_hostapd_param
*param
,
1217 u8
*pos
= param
->u
.set_generic_info_elem
.data
;
1218 int left
= param_len
- ((u8
*) pos
- (u8
*) param
);
1219 int len
= param
->u
.set_generic_info_elem
.len
;
1224 return ieee80211_set_gen_ie(dev
, pos
, len
);
1228 static int ieee80211_ioctl_set_regulatory_domain(struct net_device
*dev
,
1229 struct prism2_hostapd_param
*param
)
1231 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1232 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
1233 conf
->regulatory_domain
= param
->u
.set_regulatory_domain
.rd
;
1238 static int ieee80211_ioctl_set_radio_enabled(struct net_device
*dev
,
1241 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1242 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
1244 conf
->radio_enabled
= val
;
1245 return ieee80211_hw_config(wdev_priv(dev
->ieee80211_ptr
));
1249 ieee80211_ioctl_set_tx_queue_params(struct net_device
*dev
,
1250 struct prism2_hostapd_param
*param
)
1252 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1253 struct ieee80211_tx_queue_params qparam
;
1255 if (!local
->ops
->conf_tx
) {
1256 printk(KERN_DEBUG
"%s: low-level driver does not support TX "
1257 "queue configuration\n", dev
->name
);
1261 memset(&qparam
, 0, sizeof(qparam
));
1262 qparam
.aifs
= param
->u
.tx_queue_params
.aifs
;
1263 qparam
.cw_min
= param
->u
.tx_queue_params
.cw_min
;
1264 qparam
.cw_max
= param
->u
.tx_queue_params
.cw_max
;
1265 qparam
.burst_time
= param
->u
.tx_queue_params
.burst_time
;
1267 return local
->ops
->conf_tx(local_to_hw(local
),
1268 param
->u
.tx_queue_params
.queue
,
1273 static int ieee80211_ioctl_get_tx_stats(struct net_device
*dev
,
1274 struct prism2_hostapd_param
*param
)
1276 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1277 struct ieee80211_tx_queue_stats stats
;
1280 if (!local
->ops
->get_tx_stats
)
1283 memset(&stats
, 0, sizeof(stats
));
1284 ret
= local
->ops
->get_tx_stats(local_to_hw(local
), &stats
);
1288 for (i
= 0; i
< 4; i
++) {
1289 param
->u
.get_tx_stats
.data
[i
].len
= stats
.data
[i
].len
;
1290 param
->u
.get_tx_stats
.data
[i
].limit
= stats
.data
[i
].limit
;
1291 param
->u
.get_tx_stats
.data
[i
].count
= stats
.data
[i
].count
;
1298 static int ieee80211_ioctl_set_channel_flag(struct net_device
*dev
,
1299 struct prism2_hostapd_param
*param
)
1301 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1302 struct ieee80211_hw_mode
*mode
;
1303 struct ieee80211_channel
*chan
= NULL
;
1306 list_for_each_entry(mode
, &local
->modes_list
, list
) {
1307 if (mode
->mode
== param
->u
.set_channel_flag
.mode
)
1313 for (i
= 0; i
< mode
->num_channels
; i
++) {
1314 chan
= &mode
->channels
[i
];
1315 if (chan
->chan
== param
->u
.set_channel_flag
.chan
)
1323 chan
->flag
= param
->u
.set_channel_flag
.flag
;
1324 chan
->power_level
= param
->u
.set_channel_flag
.power_level
;
1325 chan
->antenna_max
= param
->u
.set_channel_flag
.antenna_max
;
1331 static int ieee80211_ioctl_set_quiet_params(struct net_device
*dev
,
1332 struct prism2_hostapd_param
*param
)
1334 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1335 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
1337 conf
->quiet_duration
= param
->u
.quiet
.duration
;
1338 conf
->quiet_offset
= param
->u
.quiet
.offset
;
1339 conf
->quiet_period
= param
->u
.quiet
.period
;
1344 static int ieee80211_ioctl_set_radar_params(struct net_device
*dev
,
1345 struct prism2_hostapd_param
*param
)
1347 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1348 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
1350 conf
->radar_firpwr_threshold
= param
->u
.radar
.radar_firpwr_threshold
;
1351 conf
->radar_rssi_threshold
= param
->u
.radar
.radar_rssi_threshold
;
1352 conf
->pulse_height_threshold
= param
->u
.radar
.pulse_height_threshold
;
1353 conf
->pulse_rssi_threshold
= param
->u
.radar
.pulse_rssi_threshold
;
1354 conf
->pulse_inband_threshold
= param
->u
.radar
.pulse_inband_threshold
;
1359 static int ieee80211_ioctl_priv_hostapd(struct net_device
*dev
,
1362 struct prism2_hostapd_param
*param
;
1365 if (p
->length
< sizeof(struct prism2_hostapd_param
) ||
1366 p
->length
> PRISM2_HOSTAPD_MAX_BUF_SIZE
|| !p
->pointer
) {
1367 printk(KERN_DEBUG
"%s: hostapd ioctl: ptr=%p len=%d min=%d "
1368 "max=%d\n", dev
->name
, p
->pointer
, p
->length
,
1369 (int)sizeof(struct prism2_hostapd_param
),
1370 PRISM2_HOSTAPD_MAX_BUF_SIZE
);
1374 param
= (struct prism2_hostapd_param
*) kmalloc(p
->length
, GFP_KERNEL
);
1378 if (copy_from_user(param
, p
->pointer
, p
->length
)) {
1383 switch (param
->cmd
) {
1384 case PRISM2_HOSTAPD_FLUSH
:
1385 ret
= ieee80211_ioctl_flush(dev
, param
);
1387 case PRISM2_HOSTAPD_ADD_STA
:
1388 ret
= ieee80211_ioctl_add_sta(dev
, param
);
1390 case PRISM2_HOSTAPD_REMOVE_STA
:
1391 ret
= ieee80211_ioctl_remove_sta(dev
, param
);
1393 case PRISM2_HOSTAPD_GET_INFO_STA
:
1394 ret
= ieee80211_ioctl_get_info_sta(dev
, param
);
1396 case PRISM2_SET_ENCRYPTION
:
1397 ret
= ieee80211_ioctl_set_encryption(dev
, param
, p
->length
);
1399 case PRISM2_GET_ENCRYPTION
:
1400 ret
= ieee80211_ioctl_get_encryption(dev
, param
, p
->length
);
1402 case PRISM2_HOSTAPD_SET_FLAGS_STA
:
1403 ret
= ieee80211_ioctl_set_flags_sta(dev
, param
);
1405 case PRISM2_HOSTAPD_SET_BEACON
:
1406 ret
= ieee80211_ioctl_set_beacon(dev
, param
, p
->length
, 0);
1408 case PRISM2_HOSTAPD_GET_HW_FEATURES
:
1409 ret
= ieee80211_ioctl_get_hw_features(dev
, param
, p
->length
);
1411 #ifdef CONFIG_HOSTAPD_WPA_TESTING
1412 case PRISM2_HOSTAPD_WPA_TRIGGER
:
1413 ret
= ieee80211_ioctl_wpa_trigger(dev
, param
);
1415 #endif /* CONFIG_HOSTAPD_WPA_TESTING */
1416 case PRISM2_HOSTAPD_SET_RATE_SETS
:
1417 ret
= ieee80211_ioctl_set_rate_sets(dev
, param
, p
->length
);
1419 case PRISM2_HOSTAPD_ADD_IF
:
1420 ret
= ieee80211_ioctl_add_if(dev
, param
, p
->length
);
1422 case PRISM2_HOSTAPD_REMOVE_IF
:
1423 ret
= ieee80211_ioctl_remove_if(dev
, param
);
1425 case PRISM2_HOSTAPD_GET_DOT11COUNTERSTABLE
:
1426 ret
= ieee80211_ioctl_get_dot11counterstable(dev
, param
);
1428 case PRISM2_HOSTAPD_GET_LOAD_STATS
:
1429 ret
= ieee80211_ioctl_get_load_stats(dev
, param
);
1431 case PRISM2_HOSTAPD_SET_STA_VLAN
:
1432 ret
= ieee80211_ioctl_set_sta_vlan(dev
, param
);
1434 case PRISM2_HOSTAPD_SET_GENERIC_INFO_ELEM
:
1435 ret
= ieee80211_ioctl_set_generic_info_elem(dev
, param
,
1438 case PRISM2_HOSTAPD_SET_CHANNEL_FLAG
:
1439 ret
= ieee80211_ioctl_set_channel_flag(dev
, param
);
1441 case PRISM2_HOSTAPD_SET_REGULATORY_DOMAIN
:
1442 ret
= ieee80211_ioctl_set_regulatory_domain(dev
, param
);
1444 case PRISM2_HOSTAPD_SET_TX_QUEUE_PARAMS
:
1445 ret
= ieee80211_ioctl_set_tx_queue_params(dev
, param
);
1447 case PRISM2_HOSTAPD_GET_TX_STATS
:
1448 ret
= ieee80211_ioctl_get_tx_stats(dev
, param
);
1450 case PRISM2_HOSTAPD_UPDATE_IF
:
1451 ret
= ieee80211_ioctl_update_if(dev
, param
, p
->length
);
1453 case PRISM2_HOSTAPD_SCAN_REQ
:
1454 ret
= ieee80211_ioctl_scan_req(dev
, param
, p
->length
);
1456 case PRISM2_STA_GET_STATE
:
1457 ret
= ieee80211_ioctl_sta_get_state(dev
, param
);
1459 case PRISM2_HOSTAPD_MLME
:
1460 ret
= ieee80211_ioctl_mlme(dev
, param
);
1462 case PRISM2_HOSTAPD_SET_RADAR_PARAMS
:
1463 ret
= ieee80211_ioctl_set_radar_params(dev
, param
);
1465 case PRISM2_HOSTAPD_SET_QUIET_PARAMS
:
1466 ret
= ieee80211_ioctl_set_quiet_params(dev
, param
);
1473 if (copy_to_user(p
->pointer
, param
, p
->length
))
1483 static int ieee80211_ioctl_giwname(struct net_device
*dev
,
1484 struct iw_request_info
*info
,
1485 char *name
, char *extra
)
1487 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1489 switch (local
->hw
.conf
.phymode
) {
1490 case MODE_IEEE80211A
:
1491 strcpy(name
, "IEEE 802.11a");
1493 case MODE_IEEE80211B
:
1494 strcpy(name
, "IEEE 802.11b");
1496 case MODE_IEEE80211G
:
1497 strcpy(name
, "IEEE 802.11g");
1499 case MODE_ATHEROS_TURBO
:
1500 strcpy(name
, "5GHz Turbo");
1503 strcpy(name
, "IEEE 802.11");
1511 static int ieee80211_ioctl_giwrange(struct net_device
*dev
,
1512 struct iw_request_info
*info
,
1513 struct iw_point
*data
, char *extra
)
1515 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1516 struct iw_range
*range
= (struct iw_range
*) extra
;
1518 data
->length
= sizeof(struct iw_range
);
1519 memset(range
, 0, sizeof(struct iw_range
));
1521 range
->we_version_compiled
= WIRELESS_EXT
;
1522 range
->we_version_source
= 21;
1523 range
->retry_capa
= IW_RETRY_LIMIT
;
1524 range
->retry_flags
= IW_RETRY_LIMIT
;
1525 range
->min_retry
= 0;
1526 range
->max_retry
= 255;
1528 range
->max_rts
= 2347;
1529 range
->min_frag
= 256;
1530 range
->max_frag
= 2346;
1532 range
->encoding_size
[0] = 5;
1533 range
->encoding_size
[1] = 13;
1534 range
->num_encoding_sizes
= 2;
1535 range
->max_encoding_tokens
= NUM_DEFAULT_KEYS
;
1537 range
->max_qual
.qual
= local
->hw
.max_signal
;
1538 range
->max_qual
.level
= local
->hw
.max_rssi
;
1539 range
->max_qual
.noise
= local
->hw
.max_noise
;
1540 range
->max_qual
.updated
= local
->wstats_flags
;
1542 range
->avg_qual
.qual
= local
->hw
.max_signal
/2;
1543 range
->avg_qual
.level
= 0;
1544 range
->avg_qual
.noise
= 0;
1545 range
->avg_qual
.updated
= local
->wstats_flags
;
1547 range
->enc_capa
= IW_ENC_CAPA_WPA
| IW_ENC_CAPA_WPA2
|
1548 IW_ENC_CAPA_CIPHER_TKIP
| IW_ENC_CAPA_CIPHER_CCMP
;
1550 IW_EVENT_CAPA_SET_KERNEL(range
->event_capa
);
1551 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWTHRSPY
);
1552 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWAP
);
1553 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWSCAN
);
1559 struct ieee80211_channel_range
{
1562 unsigned char power_level
;
1563 unsigned char antenna_max
;
1566 static const struct ieee80211_channel_range ieee80211_fcc_channels
[] = {
1567 { 2412, 2462, 27, 6 } /* IEEE 802.11b/g, channels 1..11 */,
1568 { 5180, 5240, 17, 6 } /* IEEE 802.11a, channels 36..48 */,
1569 { 5260, 5320, 23, 6 } /* IEEE 802.11a, channels 52..64 */,
1570 { 5745, 5825, 30, 6 } /* IEEE 802.11a, channels 149..165, outdoor */,
1574 static const struct ieee80211_channel_range ieee80211_mkk_channels
[] = {
1575 { 2412, 2472, 20, 6 } /* IEEE 802.11b/g, channels 1..13 */,
1576 { 5170, 5240, 20, 6 } /* IEEE 802.11a, channels 34..48 */,
1577 { 5260, 5320, 20, 6 } /* IEEE 802.11a, channels 52..64 */,
1582 static const struct ieee80211_channel_range
*channel_range
=
1583 ieee80211_fcc_channels
;
1586 static void ieee80211_unmask_channel(struct net_device
*dev
, int mode
,
1587 struct ieee80211_channel
*chan
)
1593 if (ieee80211_regdom
== 64 &&
1594 (mode
== MODE_ATHEROS_TURBO
|| mode
== MODE_ATHEROS_TURBOG
)) {
1595 /* Do not allow Turbo modes in Japan. */
1599 for (i
= 0; channel_range
[i
].start_freq
; i
++) {
1600 const struct ieee80211_channel_range
*r
= &channel_range
[i
];
1601 if (r
->start_freq
<= chan
->freq
&& r
->end_freq
>= chan
->freq
) {
1602 if (ieee80211_regdom
== 64 && !ieee80211_japan_5ghz
&&
1603 chan
->freq
>= 5260 && chan
->freq
<= 5320) {
1605 * Skip new channels in Japan since the
1606 * firmware was not marked having been upgraded
1612 if (ieee80211_regdom
== 0x10 &&
1613 (chan
->freq
== 5190 || chan
->freq
== 5210 ||
1614 chan
->freq
== 5230)) {
1615 /* Skip MKK channels when in FCC domain. */
1619 chan
->flag
|= IEEE80211_CHAN_W_SCAN
|
1620 IEEE80211_CHAN_W_ACTIVE_SCAN
|
1621 IEEE80211_CHAN_W_IBSS
;
1622 chan
->power_level
= r
->power_level
;
1623 chan
->antenna_max
= r
->antenna_max
;
1625 if (ieee80211_regdom
== 64 &&
1626 (chan
->freq
== 5170 || chan
->freq
== 5190 ||
1627 chan
->freq
== 5210 || chan
->freq
== 5230)) {
1629 * New regulatory rules in Japan have backwards
1630 * compatibility with old channels in 5.15-5.25
1631 * GHz band, but the station is not allowed to
1632 * use active scan on these old channels.
1634 chan
->flag
&= ~IEEE80211_CHAN_W_ACTIVE_SCAN
;
1637 if (ieee80211_regdom
== 64 &&
1638 (chan
->freq
== 5260 || chan
->freq
== 5280 ||
1639 chan
->freq
== 5300 || chan
->freq
== 5320)) {
1641 * IBSS is not allowed on 5.25-5.35 GHz band
1642 * due to radar detection requirements.
1644 chan
->flag
&= ~IEEE80211_CHAN_W_IBSS
;
1653 static int ieee80211_unmask_channels(struct net_device
*dev
)
1655 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1656 struct ieee80211_hw_mode
*mode
;
1659 list_for_each_entry(mode
, &local
->modes_list
, list
) {
1660 for (c
= 0; c
< mode
->num_channels
; c
++) {
1661 ieee80211_unmask_channel(dev
, mode
->mode
,
1662 &mode
->channels
[c
]);
1669 int ieee80211_init_client(struct net_device
*dev
)
1671 if (ieee80211_regdom
== 0x40)
1672 channel_range
= ieee80211_mkk_channels
;
1673 ieee80211_unmask_channels(dev
);
1678 static int ieee80211_ioctl_siwmode(struct net_device
*dev
,
1679 struct iw_request_info
*info
,
1680 __u32
*mode
, char *extra
)
1682 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1685 if (sdata
->type
== IEEE80211_IF_TYPE_VLAN
)
1689 case IW_MODE_MASTER
:
1690 type
= IEEE80211_IF_TYPE_AP
;
1693 type
= IEEE80211_IF_TYPE_STA
;
1696 type
= IEEE80211_IF_TYPE_IBSS
;
1698 case IW_MODE_MONITOR
:
1699 type
= IEEE80211_IF_TYPE_MNTR
;
1701 case IW_MODE_REPEAT
:
1702 type
= IEEE80211_IF_TYPE_WDS
;
1708 if (type
== sdata
->type
)
1710 if (netif_running(dev
))
1713 ieee80211_if_reinit(dev
);
1714 ieee80211_if_set_type(dev
, type
);
1720 static int ieee80211_ioctl_giwmode(struct net_device
*dev
,
1721 struct iw_request_info
*info
,
1722 __u32
*mode
, char *extra
)
1724 struct ieee80211_sub_if_data
*sdata
;
1726 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1727 switch (sdata
->type
) {
1728 case IEEE80211_IF_TYPE_AP
:
1729 *mode
= IW_MODE_MASTER
;
1731 case IEEE80211_IF_TYPE_STA
:
1732 *mode
= IW_MODE_INFRA
;
1734 case IEEE80211_IF_TYPE_IBSS
:
1735 *mode
= IW_MODE_ADHOC
;
1737 case IEEE80211_IF_TYPE_MNTR
:
1738 *mode
= IW_MODE_MONITOR
;
1740 case IEEE80211_IF_TYPE_WDS
:
1741 *mode
= IW_MODE_REPEAT
;
1743 case IEEE80211_IF_TYPE_VLAN
:
1744 *mode
= IW_MODE_SECOND
; /* FIXME */
1747 *mode
= IW_MODE_AUTO
;
1753 int ieee80211_set_channel(struct ieee80211_local
*local
, int channel
, int freq
)
1755 struct ieee80211_hw_mode
*mode
;
1759 list_for_each_entry(mode
, &local
->modes_list
, list
) {
1760 if (!(local
->enabled_modes
& (1 << mode
->mode
)))
1762 for (c
= 0; c
< mode
->num_channels
; c
++) {
1763 struct ieee80211_channel
*chan
= &mode
->channels
[c
];
1764 if (chan
->flag
& IEEE80211_CHAN_W_SCAN
&&
1765 ((chan
->chan
== channel
) || (chan
->freq
== freq
))) {
1766 /* Use next_mode as the mode preference to
1767 * resolve non-unique channel numbers. */
1768 if (set
&& mode
->mode
!= local
->next_mode
)
1771 local
->oper_channel
= chan
;
1772 local
->oper_hw_mode
= mode
;
1779 if (local
->sta_scanning
)
1782 ret
= ieee80211_hw_config(local
);
1784 rate_control_clear(local
);
1790 static int ieee80211_ioctl_siwfreq(struct net_device
*dev
,
1791 struct iw_request_info
*info
,
1792 struct iw_freq
*freq
, char *extra
)
1794 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1795 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1797 if (sdata
->type
== IEEE80211_IF_TYPE_STA
)
1798 sdata
->u
.sta
.auto_channel_sel
= 0;
1800 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
1803 if (sdata
->type
== IEEE80211_IF_TYPE_STA
)
1804 sdata
->u
.sta
.auto_channel_sel
= 1;
1807 return ieee80211_set_channel(local
, freq
->m
, -1);
1809 int i
, div
= 1000000;
1810 for (i
= 0; i
< freq
->e
; i
++)
1813 return ieee80211_set_channel(local
, -1, freq
->m
/ div
);
1820 static int ieee80211_ioctl_giwfreq(struct net_device
*dev
,
1821 struct iw_request_info
*info
,
1822 struct iw_freq
*freq
, char *extra
)
1824 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1826 /* TODO: in station mode (Managed/Ad-hoc) might need to poll low-level
1827 * driver for the current channel with firmware-based management */
1829 freq
->m
= local
->hw
.conf
.freq
;
1836 static int ieee80211_ioctl_siwessid(struct net_device
*dev
,
1837 struct iw_request_info
*info
,
1838 struct iw_point
*data
, char *ssid
)
1840 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1841 struct ieee80211_sub_if_data
*sdata
;
1842 size_t len
= data
->length
;
1844 /* iwconfig uses nul termination in SSID.. */
1845 if (len
> 0 && ssid
[len
- 1] == '\0')
1848 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1849 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
1850 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
1852 if (local
->user_space_mlme
) {
1853 if (len
> IEEE80211_MAX_SSID_LEN
)
1855 memcpy(sdata
->u
.sta
.ssid
, ssid
, len
);
1856 sdata
->u
.sta
.ssid_len
= len
;
1859 sdata
->u
.sta
.auto_ssid_sel
= !data
->flags
;
1860 ret
= ieee80211_sta_set_ssid(dev
, ssid
, len
);
1863 ieee80211_sta_req_auth(dev
, &sdata
->u
.sta
);
1867 if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
1868 memcpy(sdata
->u
.ap
.ssid
, ssid
, len
);
1869 memset(sdata
->u
.ap
.ssid
+ len
, 0,
1870 IEEE80211_MAX_SSID_LEN
- len
);
1871 sdata
->u
.ap
.ssid_len
= len
;
1872 return ieee80211_if_config(dev
);
1878 static int ieee80211_ioctl_giwessid(struct net_device
*dev
,
1879 struct iw_request_info
*info
,
1880 struct iw_point
*data
, char *ssid
)
1884 struct ieee80211_sub_if_data
*sdata
;
1885 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1886 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
1887 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
1888 int res
= ieee80211_sta_get_ssid(dev
, ssid
, &len
);
1897 if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
1898 len
= sdata
->u
.ap
.ssid_len
;
1899 if (len
> IW_ESSID_MAX_SIZE
)
1900 len
= IW_ESSID_MAX_SIZE
;
1901 memcpy(ssid
, sdata
->u
.ap
.ssid
, len
);
1910 static int ieee80211_ioctl_siwap(struct net_device
*dev
,
1911 struct iw_request_info
*info
,
1912 struct sockaddr
*ap_addr
, char *extra
)
1914 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1915 struct ieee80211_sub_if_data
*sdata
;
1917 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1918 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
1919 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
1921 if (local
->user_space_mlme
) {
1922 memcpy(sdata
->u
.sta
.bssid
, (u8
*) &ap_addr
->sa_data
,
1926 if (is_zero_ether_addr((u8
*) &ap_addr
->sa_data
)) {
1927 sdata
->u
.sta
.auto_bssid_sel
= 1;
1928 sdata
->u
.sta
.auto_channel_sel
= 1;
1929 } else if (is_broadcast_ether_addr((u8
*) &ap_addr
->sa_data
))
1930 sdata
->u
.sta
.auto_bssid_sel
= 1;
1932 sdata
->u
.sta
.auto_bssid_sel
= 0;
1933 ret
= ieee80211_sta_set_bssid(dev
, (u8
*) &ap_addr
->sa_data
);
1936 ieee80211_sta_req_auth(dev
, &sdata
->u
.sta
);
1938 } else if (sdata
->type
== IEEE80211_IF_TYPE_WDS
) {
1939 if (memcmp(sdata
->u
.wds
.remote_addr
, (u8
*) &ap_addr
->sa_data
,
1942 return ieee80211_if_update_wds(dev
, (u8
*) &ap_addr
->sa_data
);
1949 static int ieee80211_ioctl_giwap(struct net_device
*dev
,
1950 struct iw_request_info
*info
,
1951 struct sockaddr
*ap_addr
, char *extra
)
1953 struct ieee80211_sub_if_data
*sdata
;
1955 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1956 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
1957 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
1958 ap_addr
->sa_family
= ARPHRD_ETHER
;
1959 memcpy(&ap_addr
->sa_data
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
1961 } else if (sdata
->type
== IEEE80211_IF_TYPE_WDS
) {
1962 ap_addr
->sa_family
= ARPHRD_ETHER
;
1963 memcpy(&ap_addr
->sa_data
, sdata
->u
.wds
.remote_addr
, ETH_ALEN
);
1971 static int ieee80211_ioctl_siwscan(struct net_device
*dev
,
1972 struct iw_request_info
*info
,
1973 struct iw_point
*data
, char *extra
)
1975 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1976 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1978 size_t ssid_len
= 0;
1980 if (!netif_running(dev
))
1983 if (local
->scan_flags
& IEEE80211_SCAN_MATCH_SSID
) {
1984 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
1985 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
1986 ssid
= sdata
->u
.sta
.ssid
;
1987 ssid_len
= sdata
->u
.sta
.ssid_len
;
1988 } else if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
1989 ssid
= sdata
->u
.ap
.ssid
;
1990 ssid_len
= sdata
->u
.ap
.ssid_len
;
1994 return ieee80211_sta_req_scan(dev
, ssid
, ssid_len
);
1998 static int ieee80211_ioctl_giwscan(struct net_device
*dev
,
1999 struct iw_request_info
*info
,
2000 struct iw_point
*data
, char *extra
)
2003 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2004 if (local
->sta_scanning
)
2006 res
= ieee80211_sta_scan_results(dev
, extra
, data
->length
);
2016 static int ieee80211_ioctl_giwrate(struct net_device
*dev
,
2017 struct iw_request_info
*info
,
2018 struct iw_param
*rate
, char *extra
)
2020 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2021 struct sta_info
*sta
;
2022 struct ieee80211_sub_if_data
*sdata
;
2024 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2025 if (sdata
->type
== IEEE80211_IF_TYPE_STA
)
2026 sta
= sta_info_get(local
, sdata
->u
.sta
.bssid
);
2031 if (sta
->txrate
< local
->oper_hw_mode
->num_rates
)
2032 rate
->value
= local
->oper_hw_mode
->rates
[sta
->txrate
].rate
* 100000;
2039 static int ieee80211_ioctl_siwrts(struct net_device
*dev
,
2040 struct iw_request_info
*info
,
2041 struct iw_param
*rts
, char *extra
)
2043 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2046 local
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
2047 else if (rts
->value
< 0 || rts
->value
> IEEE80211_MAX_RTS_THRESHOLD
)
2050 local
->rts_threshold
= rts
->value
;
2052 /* If the wlan card performs RTS/CTS in hardware/firmware,
2053 * configure it here */
2055 if (local
->ops
->set_rts_threshold
)
2056 local
->ops
->set_rts_threshold(local_to_hw(local
),
2057 local
->rts_threshold
);
2062 static int ieee80211_ioctl_giwrts(struct net_device
*dev
,
2063 struct iw_request_info
*info
,
2064 struct iw_param
*rts
, char *extra
)
2066 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2068 rts
->value
= local
->rts_threshold
;
2069 rts
->disabled
= (rts
->value
>= IEEE80211_MAX_RTS_THRESHOLD
);
2076 static int ieee80211_ioctl_siwfrag(struct net_device
*dev
,
2077 struct iw_request_info
*info
,
2078 struct iw_param
*frag
, char *extra
)
2080 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2083 local
->fragmentation_threshold
= IEEE80211_MAX_FRAG_THRESHOLD
;
2084 else if (frag
->value
< 256 ||
2085 frag
->value
> IEEE80211_MAX_FRAG_THRESHOLD
)
2088 /* Fragment length must be even, so strip LSB. */
2089 local
->fragmentation_threshold
= frag
->value
& ~0x1;
2092 /* If the wlan card performs fragmentation in hardware/firmware,
2093 * configure it here */
2095 if (local
->ops
->set_frag_threshold
)
2096 local
->ops
->set_frag_threshold(
2098 local
->fragmentation_threshold
);
2103 static int ieee80211_ioctl_giwfrag(struct net_device
*dev
,
2104 struct iw_request_info
*info
,
2105 struct iw_param
*frag
, char *extra
)
2107 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2109 frag
->value
= local
->fragmentation_threshold
;
2110 frag
->disabled
= (frag
->value
>= IEEE80211_MAX_RTS_THRESHOLD
);
2117 static int ieee80211_ioctl_siwretry(struct net_device
*dev
,
2118 struct iw_request_info
*info
,
2119 struct iw_param
*retry
, char *extra
)
2121 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2123 if (retry
->disabled
||
2124 (retry
->flags
& IW_RETRY_TYPE
) != IW_RETRY_LIMIT
)
2127 if (retry
->flags
& IW_RETRY_MAX
)
2128 local
->long_retry_limit
= retry
->value
;
2129 else if (retry
->flags
& IW_RETRY_MIN
)
2130 local
->short_retry_limit
= retry
->value
;
2132 local
->long_retry_limit
= retry
->value
;
2133 local
->short_retry_limit
= retry
->value
;
2136 if (local
->ops
->set_retry_limit
) {
2137 return local
->ops
->set_retry_limit(
2139 local
->short_retry_limit
,
2140 local
->long_retry_limit
);
2147 static int ieee80211_ioctl_giwretry(struct net_device
*dev
,
2148 struct iw_request_info
*info
,
2149 struct iw_param
*retry
, char *extra
)
2151 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2153 retry
->disabled
= 0;
2154 if (retry
->flags
== 0 || retry
->flags
& IW_RETRY_MIN
) {
2155 /* first return min value, iwconfig will ask max value
2156 * later if needed */
2157 retry
->flags
|= IW_RETRY_LIMIT
;
2158 retry
->value
= local
->short_retry_limit
;
2159 if (local
->long_retry_limit
!= local
->short_retry_limit
)
2160 retry
->flags
|= IW_RETRY_MIN
;
2163 if (retry
->flags
& IW_RETRY_MAX
) {
2164 retry
->flags
= IW_RETRY_LIMIT
| IW_RETRY_MAX
;
2165 retry
->value
= local
->long_retry_limit
;
2171 static int ieee80211_ioctl_clear_keys(struct net_device
*dev
)
2173 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2174 struct ieee80211_key_conf key
;
2177 struct ieee80211_key_conf
*keyconf
;
2178 struct ieee80211_sub_if_data
*sdata
;
2179 struct sta_info
*sta
;
2181 memset(addr
, 0xff, ETH_ALEN
);
2182 read_lock(&local
->sub_if_lock
);
2183 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
2184 for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
2186 if (sdata
->keys
[i
] &&
2187 !sdata
->keys
[i
]->force_sw_encrypt
&&
2188 local
->ops
->set_key
&&
2189 (keyconf
= ieee80211_key_data2conf(local
,
2191 local
->ops
->set_key(local_to_hw(local
),
2195 ieee80211_key_free(sdata
->keys
[i
]);
2196 sdata
->keys
[i
] = NULL
;
2198 sdata
->default_key
= NULL
;
2200 read_unlock(&local
->sub_if_lock
);
2202 spin_lock_bh(&local
->sta_lock
);
2203 list_for_each_entry(sta
, &local
->sta_list
, list
) {
2205 if (sta
->key
&& !sta
->key
->force_sw_encrypt
&&
2206 local
->ops
->set_key
&&
2207 (keyconf
= ieee80211_key_data2conf(local
, sta
->key
)))
2208 local
->ops
->set_key(local_to_hw(local
), DISABLE_KEY
,
2209 sta
->addr
, keyconf
, sta
->aid
);
2211 ieee80211_key_free(sta
->key
);
2214 spin_unlock_bh(&local
->sta_lock
);
2216 memset(&key
, 0, sizeof(key
));
2217 if (local
->ops
->set_key
&&
2218 local
->ops
->set_key(local_to_hw(local
), REMOVE_ALL_KEYS
,
2220 printk(KERN_DEBUG
"%s: failed to remove hwaccel keys\n",
2228 ieee80211_ioctl_force_unicast_rate(struct net_device
*dev
,
2229 struct ieee80211_sub_if_data
*sdata
,
2232 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2233 struct ieee80211_hw_mode
*mode
;
2236 if (sdata
->type
!= IEEE80211_IF_TYPE_AP
)
2240 sdata
->u
.ap
.force_unicast_rateidx
= -1;
2244 mode
= local
->oper_hw_mode
;
2245 for (i
= 0; i
< mode
->num_rates
; i
++) {
2246 if (mode
->rates
[i
].rate
== rate
) {
2247 sdata
->u
.ap
.force_unicast_rateidx
= i
;
2256 ieee80211_ioctl_max_ratectrl_rate(struct net_device
*dev
,
2257 struct ieee80211_sub_if_data
*sdata
,
2260 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2261 struct ieee80211_hw_mode
*mode
;
2264 if (sdata
->type
!= IEEE80211_IF_TYPE_AP
)
2268 sdata
->u
.ap
.max_ratectrl_rateidx
= -1;
2272 mode
= local
->oper_hw_mode
;
2273 for (i
= 0; i
< mode
->num_rates
; i
++) {
2274 if (mode
->rates
[i
].rate
== rate
) {
2275 sdata
->u
.ap
.max_ratectrl_rateidx
= i
;
2283 static void ieee80211_key_enable_hwaccel(struct ieee80211_local
*local
,
2284 struct ieee80211_key
*key
)
2286 struct ieee80211_key_conf
*keyconf
;
2289 if (!key
|| key
->alg
!= ALG_WEP
|| !key
->force_sw_encrypt
||
2290 (local
->hw
.flags
& IEEE80211_HW_DEVICE_HIDES_WEP
))
2293 memset(addr
, 0xff, ETH_ALEN
);
2294 keyconf
= ieee80211_key_data2conf(local
, key
);
2295 if (keyconf
&& local
->ops
->set_key
&&
2296 local
->ops
->set_key(local_to_hw(local
),
2297 SET_KEY
, addr
, keyconf
, 0) == 0) {
2298 key
->force_sw_encrypt
=
2299 !!(keyconf
->flags
& IEEE80211_KEY_FORCE_SW_ENCRYPT
);
2300 key
->hw_key_idx
= keyconf
->hw_key_idx
;
2306 static void ieee80211_key_disable_hwaccel(struct ieee80211_local
*local
,
2307 struct ieee80211_key
*key
)
2309 struct ieee80211_key_conf
*keyconf
;
2312 if (!key
|| key
->alg
!= ALG_WEP
|| key
->force_sw_encrypt
||
2313 (local
->hw
.flags
& IEEE80211_HW_DEVICE_HIDES_WEP
))
2316 memset(addr
, 0xff, ETH_ALEN
);
2317 keyconf
= ieee80211_key_data2conf(local
, key
);
2318 if (keyconf
&& local
->ops
->set_key
)
2319 local
->ops
->set_key(local_to_hw(local
), DISABLE_KEY
,
2322 key
->force_sw_encrypt
= 1;
2326 static int ieee80211_ioctl_default_wep_only(struct ieee80211_local
*local
,
2330 struct ieee80211_sub_if_data
*sdata
;
2332 local
->default_wep_only
= value
;
2333 read_lock(&local
->sub_if_lock
);
2334 list_for_each_entry(sdata
, &local
->sub_if_list
, list
)
2335 for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++)
2337 ieee80211_key_enable_hwaccel(local
,
2340 ieee80211_key_disable_hwaccel(local
,
2342 read_unlock(&local
->sub_if_lock
);
2348 void ieee80211_update_default_wep_only(struct ieee80211_local
*local
)
2351 struct ieee80211_sub_if_data
*sdata
;
2353 read_lock(&local
->sub_if_lock
);
2354 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
2356 if (sdata
->dev
== local
->mdev
)
2359 /* If there is an AP interface then depend on userspace to
2360 set default_wep_only correctly. */
2361 if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
2362 read_unlock(&local
->sub_if_lock
);
2369 read_unlock(&local
->sub_if_lock
);
2372 ieee80211_ioctl_default_wep_only(local
, 1);
2374 ieee80211_ioctl_default_wep_only(local
, 0);
2378 static int ieee80211_ioctl_prism2_param(struct net_device
*dev
,
2379 struct iw_request_info
*info
,
2380 void *wrqu
, char *extra
)
2382 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2383 struct ieee80211_sub_if_data
*sdata
;
2384 int *i
= (int *) extra
;
2386 int value
= *(i
+ 1);
2389 if (!capable(CAP_NET_ADMIN
))
2392 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2395 case PRISM2_PARAM_HOST_ENCRYPT
:
2396 case PRISM2_PARAM_HOST_DECRYPT
:
2397 /* TODO: implement these; return success now to prevent
2398 * hostapd from aborting */
2401 case PRISM2_PARAM_BEACON_INT
:
2402 local
->hw
.conf
.beacon_int
= value
;
2403 if (ieee80211_hw_config(local
))
2407 case PRISM2_PARAM_AP_BRIDGE_PACKETS
:
2408 local
->bridge_packets
= value
;
2411 case PRISM2_PARAM_AP_AUTH_ALGS
:
2412 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
2413 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
2414 sdata
->u
.sta
.auth_algs
= value
;
2419 case PRISM2_PARAM_DTIM_PERIOD
:
2422 else if (sdata
->type
!= IEEE80211_IF_TYPE_AP
)
2425 sdata
->u
.ap
.dtim_period
= value
;
2428 case PRISM2_PARAM_IEEE_802_1X
:
2429 if (local
->ops
->set_ieee8021x
)
2430 ret
= local
->ops
->set_ieee8021x(local_to_hw(local
),
2433 printk(KERN_DEBUG
"%s: failed to set IEEE 802.1X (%d) "
2434 "for low-level driver\n", dev
->name
, value
);
2436 sdata
->ieee802_1x
= value
;
2439 case PRISM2_PARAM_ANTSEL_TX
:
2440 local
->hw
.conf
.antenna_sel_tx
= value
;
2441 if (ieee80211_hw_config(local
))
2445 case PRISM2_PARAM_ANTSEL_RX
:
2446 local
->hw
.conf
.antenna_sel_rx
= value
;
2447 if (ieee80211_hw_config(local
))
2451 case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES
:
2452 local
->cts_protect_erp_frames
= value
;
2455 case PRISM2_PARAM_DROP_UNENCRYPTED
:
2456 sdata
->drop_unencrypted
= value
;
2459 case PRISM2_PARAM_PREAMBLE
:
2460 local
->short_preamble
= value
;
2463 case PRISM2_PARAM_STAT_TIME
:
2464 if (!local
->stat_time
&& value
) {
2465 local
->stat_timer
.expires
= jiffies
+ HZ
* value
/ 100;
2466 add_timer(&local
->stat_timer
);
2467 } else if (local
->stat_time
&& !value
) {
2468 del_timer_sync(&local
->stat_timer
);
2470 local
->stat_time
= value
;
2472 case PRISM2_PARAM_SHORT_SLOT_TIME
:
2474 local
->hw
.conf
.flags
|= IEEE80211_CONF_SHORT_SLOT_TIME
;
2476 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_SHORT_SLOT_TIME
;
2477 if (ieee80211_hw_config(local
))
2481 case PRISM2_PARAM_PRIVACY_INVOKED
:
2482 if (local
->ops
->set_privacy_invoked
)
2483 ret
= local
->ops
->set_privacy_invoked(
2484 local_to_hw(local
), value
);
2487 case PRISM2_PARAM_NEXT_MODE
:
2488 local
->next_mode
= value
;
2491 case PRISM2_PARAM_CLEAR_KEYS
:
2492 ret
= ieee80211_ioctl_clear_keys(dev
);
2495 case PRISM2_PARAM_RADIO_ENABLED
:
2496 ret
= ieee80211_ioctl_set_radio_enabled(dev
, value
);
2499 case PRISM2_PARAM_ANTENNA_MODE
:
2500 local
->hw
.conf
.antenna_mode
= value
;
2501 if (ieee80211_hw_config(local
))
2505 case PRISM2_PARAM_BROADCAST_SSID
:
2506 if ((value
< 0) || (value
> 1))
2509 local
->hw
.conf
.flags
|= IEEE80211_CONF_SSID_HIDDEN
;
2511 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_SSID_HIDDEN
;
2514 case PRISM2_PARAM_STA_ANTENNA_SEL
:
2515 local
->sta_antenna_sel
= value
;
2518 case PRISM2_PARAM_FORCE_UNICAST_RATE
:
2519 ret
= ieee80211_ioctl_force_unicast_rate(dev
, sdata
, value
);
2522 case PRISM2_PARAM_MAX_RATECTRL_RATE
:
2523 ret
= ieee80211_ioctl_max_ratectrl_rate(dev
, sdata
, value
);
2526 case PRISM2_PARAM_RATE_CTRL_NUM_UP
:
2527 local
->rate_ctrl_num_up
= value
;
2530 case PRISM2_PARAM_RATE_CTRL_NUM_DOWN
:
2531 local
->rate_ctrl_num_down
= value
;
2534 case PRISM2_PARAM_TX_POWER_REDUCTION
:
2538 local
->hw
.conf
.tx_power_reduction
= value
;
2541 case PRISM2_PARAM_EAPOL
:
2542 sdata
->eapol
= value
;
2545 case PRISM2_PARAM_KEY_TX_RX_THRESHOLD
:
2546 local
->key_tx_rx_threshold
= value
;
2549 case PRISM2_PARAM_KEY_INDEX
:
2550 if (value
< 0 || value
>= NUM_DEFAULT_KEYS
)
2552 else if (!sdata
->keys
[value
])
2555 sdata
->default_key
= sdata
->keys
[value
];
2558 case PRISM2_PARAM_DEFAULT_WEP_ONLY
:
2559 ret
= ieee80211_ioctl_default_wep_only(local
, value
);
2562 case PRISM2_PARAM_WIFI_WME_NOACK_TEST
:
2563 local
->wifi_wme_noack_test
= value
;
2566 case PRISM2_PARAM_ALLOW_BROADCAST_ALWAYS
:
2567 local
->allow_broadcast_always
= value
;
2570 case PRISM2_PARAM_SCAN_FLAGS
:
2571 local
->scan_flags
= value
;
2574 case PRISM2_PARAM_MIXED_CELL
:
2575 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
2576 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
2579 sdata
->u
.sta
.mixed_cell
= !!value
;
2582 case PRISM2_PARAM_KEY_MGMT
:
2583 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
2586 sdata
->u
.sta
.key_mgmt
= value
;
2589 case PRISM2_PARAM_HW_MODES
:
2590 local
->enabled_modes
= value
;
2593 case PRISM2_PARAM_CREATE_IBSS
:
2594 if (sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
2597 sdata
->u
.sta
.create_ibss
= !!value
;
2599 case PRISM2_PARAM_WMM_ENABLED
:
2600 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
2601 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
2604 sdata
->u
.sta
.wmm_enabled
= !!value
;
2606 case PRISM2_PARAM_RADAR_DETECT
:
2607 local
->hw
.conf
.radar_detect
= value
;
2609 case PRISM2_PARAM_SPECTRUM_MGMT
:
2610 local
->hw
.conf
.spect_mgmt
= value
;
2612 case PRISM2_PARAM_MGMT_IF
:
2615 ret
= ieee80211_if_add_mgmt(local
);
2616 } else if (value
== 0) {
2618 ieee80211_if_del_mgmt(local
);
2622 case PRISM2_PARAM_USER_SPACE_MLME
:
2623 local
->user_space_mlme
= value
;
2634 static int ieee80211_ioctl_get_prism2_param(struct net_device
*dev
,
2635 struct iw_request_info
*info
,
2636 void *wrqu
, char *extra
)
2638 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2639 struct ieee80211_sub_if_data
*sdata
;
2640 int *param
= (int *) extra
;
2643 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2646 case PRISM2_PARAM_BEACON_INT
:
2647 *param
= local
->hw
.conf
.beacon_int
;
2650 case PRISM2_PARAM_AP_BRIDGE_PACKETS
:
2651 *param
= local
->bridge_packets
;
2654 case PRISM2_PARAM_AP_AUTH_ALGS
:
2655 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
2656 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
2657 *param
= sdata
->u
.sta
.auth_algs
;
2662 case PRISM2_PARAM_DTIM_PERIOD
:
2663 if (sdata
->type
!= IEEE80211_IF_TYPE_AP
)
2666 *param
= sdata
->u
.ap
.dtim_period
;
2669 case PRISM2_PARAM_IEEE_802_1X
:
2670 *param
= sdata
->ieee802_1x
;
2673 case PRISM2_PARAM_ANTSEL_TX
:
2674 *param
= local
->hw
.conf
.antenna_sel_tx
;
2677 case PRISM2_PARAM_ANTSEL_RX
:
2678 *param
= local
->hw
.conf
.antenna_sel_rx
;
2681 case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES
:
2682 *param
= local
->cts_protect_erp_frames
;
2685 case PRISM2_PARAM_DROP_UNENCRYPTED
:
2686 *param
= sdata
->drop_unencrypted
;
2689 case PRISM2_PARAM_PREAMBLE
:
2690 *param
= local
->short_preamble
;
2693 case PRISM2_PARAM_STAT_TIME
:
2694 *param
= local
->stat_time
;
2696 case PRISM2_PARAM_SHORT_SLOT_TIME
:
2697 *param
= !!(local
->hw
.conf
.flags
& IEEE80211_CONF_SHORT_SLOT_TIME
);
2700 case PRISM2_PARAM_NEXT_MODE
:
2701 *param
= local
->next_mode
;
2704 case PRISM2_PARAM_ANTENNA_MODE
:
2705 *param
= local
->hw
.conf
.antenna_mode
;
2708 case PRISM2_PARAM_BROADCAST_SSID
:
2709 *param
= !!(local
->hw
.conf
.flags
& IEEE80211_CONF_SSID_HIDDEN
);
2712 case PRISM2_PARAM_STA_ANTENNA_SEL
:
2713 *param
= local
->sta_antenna_sel
;
2716 case PRISM2_PARAM_RATE_CTRL_NUM_UP
:
2717 *param
= local
->rate_ctrl_num_up
;
2720 case PRISM2_PARAM_RATE_CTRL_NUM_DOWN
:
2721 *param
= local
->rate_ctrl_num_down
;
2724 case PRISM2_PARAM_TX_POWER_REDUCTION
:
2725 *param
= local
->hw
.conf
.tx_power_reduction
;
2728 case PRISM2_PARAM_EAPOL
:
2729 *param
= sdata
->eapol
;
2732 case PRISM2_PARAM_KEY_TX_RX_THRESHOLD
:
2733 *param
= local
->key_tx_rx_threshold
;
2736 case PRISM2_PARAM_KEY_INDEX
:
2737 if (!sdata
->default_key
)
2739 else if (sdata
->default_key
== sdata
->keys
[0])
2741 else if (sdata
->default_key
== sdata
->keys
[1])
2743 else if (sdata
->default_key
== sdata
->keys
[2])
2745 else if (sdata
->default_key
== sdata
->keys
[3])
2751 case PRISM2_PARAM_DEFAULT_WEP_ONLY
:
2752 *param
= local
->default_wep_only
;
2755 case PRISM2_PARAM_WIFI_WME_NOACK_TEST
:
2756 *param
= local
->wifi_wme_noack_test
;
2759 case PRISM2_PARAM_ALLOW_BROADCAST_ALWAYS
:
2760 *param
= local
->allow_broadcast_always
;
2763 case PRISM2_PARAM_SCAN_FLAGS
:
2764 *param
= local
->scan_flags
;
2767 case PRISM2_PARAM_HW_MODES
:
2768 *param
= local
->enabled_modes
;
2771 case PRISM2_PARAM_CREATE_IBSS
:
2772 if (sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
2775 *param
= !!sdata
->u
.sta
.create_ibss
;
2778 case PRISM2_PARAM_MIXED_CELL
:
2779 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
2780 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
2783 *param
= !!sdata
->u
.sta
.mixed_cell
;
2786 case PRISM2_PARAM_KEY_MGMT
:
2787 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
2790 *param
= sdata
->u
.sta
.key_mgmt
;
2792 case PRISM2_PARAM_WMM_ENABLED
:
2793 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
2794 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
2797 *param
= !!sdata
->u
.sta
.wmm_enabled
;
2799 case PRISM2_PARAM_MGMT_IF
:
2801 *param
= local
->apdev
->ifindex
;
2805 case PRISM2_PARAM_USER_SPACE_MLME
:
2806 *param
= local
->user_space_mlme
;
2817 static int ieee80211_ioctl_siwmlme(struct net_device
*dev
,
2818 struct iw_request_info
*info
,
2819 struct iw_point
*data
, char *extra
)
2821 struct ieee80211_sub_if_data
*sdata
;
2822 struct iw_mlme
*mlme
= (struct iw_mlme
*) extra
;
2824 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2825 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
2826 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
2829 switch (mlme
->cmd
) {
2830 case IW_MLME_DEAUTH
:
2831 /* TODO: mlme->addr.sa_data */
2832 return ieee80211_sta_deauthenticate(dev
, mlme
->reason_code
);
2833 case IW_MLME_DISASSOC
:
2834 /* TODO: mlme->addr.sa_data */
2835 return ieee80211_sta_disassociate(dev
, mlme
->reason_code
);
2842 static int ieee80211_ioctl_siwencode(struct net_device
*dev
,
2843 struct iw_request_info
*info
,
2844 struct iw_point
*erq
, char *keybuf
)
2846 struct ieee80211_sub_if_data
*sdata
;
2847 int idx
, i
, alg
= ALG_WEP
;
2848 u8 bcaddr
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2850 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2852 idx
= erq
->flags
& IW_ENCODE_INDEX
;
2854 if (sdata
->default_key
)
2855 for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
2856 if (sdata
->default_key
== sdata
->keys
[i
]) {
2861 } else if (idx
< 1 || idx
> 4)
2866 if (erq
->flags
& IW_ENCODE_DISABLED
)
2868 else if (erq
->length
== 0) {
2869 /* No key data - just set the default TX key index */
2870 if (sdata
->default_key
!= sdata
->keys
[idx
]) {
2871 ieee80211_debugfs_key_remove_default(sdata
);
2872 sdata
->default_key
= sdata
->keys
[idx
];
2873 if (sdata
->default_key
)
2874 ieee80211_debugfs_key_add_default(sdata
);
2879 return ieee80211_set_encryption(
2882 !sdata
->default_key
,
2883 NULL
, keybuf
, erq
->length
);
2887 static int ieee80211_ioctl_giwencode(struct net_device
*dev
,
2888 struct iw_request_info
*info
,
2889 struct iw_point
*erq
, char *key
)
2891 struct ieee80211_sub_if_data
*sdata
;
2894 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2896 idx
= erq
->flags
& IW_ENCODE_INDEX
;
2897 if (idx
< 1 || idx
> 4) {
2899 if (!sdata
->default_key
)
2901 else for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
2902 if (sdata
->default_key
== sdata
->keys
[i
]) {
2912 erq
->flags
= idx
+ 1;
2914 if (!sdata
->keys
[idx
]) {
2916 erq
->flags
|= IW_ENCODE_DISABLED
;
2920 memcpy(key
, sdata
->keys
[idx
]->key
,
2921 min((int)erq
->length
, sdata
->keys
[idx
]->keylen
));
2922 erq
->length
= sdata
->keys
[idx
]->keylen
;
2923 erq
->flags
|= IW_ENCODE_ENABLED
;
2929 static int ieee80211_ioctl_siwgenie(struct net_device
*dev
,
2930 struct iw_request_info
*info
,
2931 struct iw_point
*data
, char *extra
)
2933 return ieee80211_set_gen_ie(dev
, extra
, data
->length
);
2937 static int ieee80211_ioctl_siwauth(struct net_device
*dev
,
2938 struct iw_request_info
*info
,
2939 struct iw_param
*data
, char *extra
)
2941 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2942 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2945 switch (data
->flags
& IW_AUTH_INDEX
) {
2946 case IW_AUTH_WPA_VERSION
:
2947 case IW_AUTH_CIPHER_PAIRWISE
:
2948 case IW_AUTH_CIPHER_GROUP
:
2949 case IW_AUTH_WPA_ENABLED
:
2950 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
2952 case IW_AUTH_KEY_MGMT
:
2953 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
2957 * TODO: sdata->u.sta.key_mgmt does not match with WE18
2958 * value completely; could consider modifying this to
2959 * be closer to WE18. For now, this value is not really
2960 * used for anything else than Privacy matching, so the
2961 * current code here should be more or less OK.
2963 if (data
->value
& IW_AUTH_KEY_MGMT_802_1X
) {
2964 sdata
->u
.sta
.key_mgmt
=
2965 IEEE80211_KEY_MGMT_WPA_EAP
;
2966 } else if (data
->value
& IW_AUTH_KEY_MGMT_PSK
) {
2967 sdata
->u
.sta
.key_mgmt
=
2968 IEEE80211_KEY_MGMT_WPA_PSK
;
2970 sdata
->u
.sta
.key_mgmt
=
2971 IEEE80211_KEY_MGMT_NONE
;
2975 case IW_AUTH_80211_AUTH_ALG
:
2976 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
2977 sdata
->type
== IEEE80211_IF_TYPE_IBSS
)
2978 sdata
->u
.sta
.auth_algs
= data
->value
;
2982 case IW_AUTH_PRIVACY_INVOKED
:
2983 if (local
->ops
->set_privacy_invoked
)
2984 ret
= local
->ops
->set_privacy_invoked(
2985 local_to_hw(local
), data
->value
);
2994 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
2995 static struct iw_statistics
*ieee80211_get_wireless_stats(struct net_device
*dev
)
2997 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2998 struct iw_statistics
*wstats
= &local
->wstats
;
2999 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3000 struct sta_info
*sta
= NULL
;
3002 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
3003 sdata
->type
== IEEE80211_IF_TYPE_IBSS
)
3004 sta
= sta_info_get(local
, sdata
->u
.sta
.bssid
);
3006 wstats
->discard
.fragment
= 0;
3007 wstats
->discard
.misc
= 0;
3008 wstats
->qual
.qual
= 0;
3009 wstats
->qual
.level
= 0;
3010 wstats
->qual
.noise
= 0;
3011 wstats
->qual
.updated
= IW_QUAL_ALL_INVALID
;
3013 wstats
->qual
.level
= sta
->last_rssi
;
3014 wstats
->qual
.qual
= sta
->last_signal
;
3015 wstats
->qual
.noise
= sta
->last_noise
;
3016 wstats
->qual
.updated
= local
->wstats_flags
;
3022 static int ieee80211_ioctl_giwauth(struct net_device
*dev
,
3023 struct iw_request_info
*info
,
3024 struct iw_param
*data
, char *extra
)
3026 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3029 switch (data
->flags
& IW_AUTH_INDEX
) {
3030 case IW_AUTH_80211_AUTH_ALG
:
3031 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
3032 sdata
->type
== IEEE80211_IF_TYPE_IBSS
)
3033 data
->value
= sdata
->u
.sta
.auth_algs
;
3045 static int ieee80211_ioctl_siwencodeext(struct net_device
*dev
,
3046 struct iw_request_info
*info
,
3047 struct iw_point
*erq
, char *extra
)
3049 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3050 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*) extra
;
3054 case IW_ENCODE_ALG_NONE
:
3057 case IW_ENCODE_ALG_WEP
:
3060 case IW_ENCODE_ALG_TKIP
:
3063 case IW_ENCODE_ALG_CCMP
:
3070 if (erq
->flags
& IW_ENCODE_DISABLED
)
3073 idx
= erq
->flags
& IW_ENCODE_INDEX
;
3074 if (idx
< 1 || idx
> 4) {
3076 if (!sdata
->default_key
)
3078 else for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
3079 if (sdata
->default_key
== sdata
->keys
[i
]) {
3089 return ieee80211_set_encryption(dev
, ext
->addr
.sa_data
, idx
, alg
,
3091 IW_ENCODE_EXT_SET_TX_KEY
,
3092 NULL
, ext
->key
, ext
->key_len
);
3096 static const struct iw_priv_args ieee80211_ioctl_priv
[] = {
3097 { PRISM2_IOCTL_PRISM2_PARAM
,
3098 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 2, 0, "param" },
3099 { PRISM2_IOCTL_GET_PRISM2_PARAM
,
3100 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
3101 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1, "get_param" },
3105 int ieee80211_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
3107 struct iwreq
*wrq
= (struct iwreq
*) rq
;
3111 /* Private ioctls (iwpriv) that have not yet been converted
3112 * into new wireless extensions API */
3113 case PRISM2_IOCTL_HOSTAPD
:
3114 if (!capable(CAP_NET_ADMIN
)) ret
= -EPERM
;
3115 else ret
= ieee80211_ioctl_priv_hostapd(dev
, &wrq
->u
.data
);
3126 /* Structures to export the Wireless Handlers */
3128 static const iw_handler ieee80211_handler
[] =
3130 (iw_handler
) NULL
, /* SIOCSIWCOMMIT */
3131 (iw_handler
) ieee80211_ioctl_giwname
, /* SIOCGIWNAME */
3132 (iw_handler
) NULL
, /* SIOCSIWNWID */
3133 (iw_handler
) NULL
, /* SIOCGIWNWID */
3134 (iw_handler
) ieee80211_ioctl_siwfreq
, /* SIOCSIWFREQ */
3135 (iw_handler
) ieee80211_ioctl_giwfreq
, /* SIOCGIWFREQ */
3136 (iw_handler
) ieee80211_ioctl_siwmode
, /* SIOCSIWMODE */
3137 (iw_handler
) ieee80211_ioctl_giwmode
, /* SIOCGIWMODE */
3138 (iw_handler
) NULL
, /* SIOCSIWSENS */
3139 (iw_handler
) NULL
, /* SIOCGIWSENS */
3140 (iw_handler
) NULL
/* not used */, /* SIOCSIWRANGE */
3141 (iw_handler
) ieee80211_ioctl_giwrange
, /* SIOCGIWRANGE */
3142 (iw_handler
) NULL
/* not used */, /* SIOCSIWPRIV */
3143 (iw_handler
) NULL
/* kernel code */, /* SIOCGIWPRIV */
3144 (iw_handler
) NULL
/* not used */, /* SIOCSIWSTATS */
3145 (iw_handler
) NULL
/* kernel code */, /* SIOCGIWSTATS */
3146 iw_handler_set_spy
, /* SIOCSIWSPY */
3147 iw_handler_get_spy
, /* SIOCGIWSPY */
3148 iw_handler_set_thrspy
, /* SIOCSIWTHRSPY */
3149 iw_handler_get_thrspy
, /* SIOCGIWTHRSPY */
3150 (iw_handler
) ieee80211_ioctl_siwap
, /* SIOCSIWAP */
3151 (iw_handler
) ieee80211_ioctl_giwap
, /* SIOCGIWAP */
3152 (iw_handler
) ieee80211_ioctl_siwmlme
, /* SIOCSIWMLME */
3153 (iw_handler
) NULL
, /* SIOCGIWAPLIST */
3154 (iw_handler
) ieee80211_ioctl_siwscan
, /* SIOCSIWSCAN */
3155 (iw_handler
) ieee80211_ioctl_giwscan
, /* SIOCGIWSCAN */
3156 (iw_handler
) ieee80211_ioctl_siwessid
, /* SIOCSIWESSID */
3157 (iw_handler
) ieee80211_ioctl_giwessid
, /* SIOCGIWESSID */
3158 (iw_handler
) NULL
, /* SIOCSIWNICKN */
3159 (iw_handler
) NULL
, /* SIOCGIWNICKN */
3160 (iw_handler
) NULL
, /* -- hole -- */
3161 (iw_handler
) NULL
, /* -- hole -- */
3162 (iw_handler
) NULL
, /* SIOCSIWRATE */
3163 (iw_handler
) ieee80211_ioctl_giwrate
, /* SIOCGIWRATE */
3164 (iw_handler
) ieee80211_ioctl_siwrts
, /* SIOCSIWRTS */
3165 (iw_handler
) ieee80211_ioctl_giwrts
, /* SIOCGIWRTS */
3166 (iw_handler
) ieee80211_ioctl_siwfrag
, /* SIOCSIWFRAG */
3167 (iw_handler
) ieee80211_ioctl_giwfrag
, /* SIOCGIWFRAG */
3168 (iw_handler
) NULL
, /* SIOCSIWTXPOW */
3169 (iw_handler
) NULL
, /* SIOCGIWTXPOW */
3170 (iw_handler
) ieee80211_ioctl_siwretry
, /* SIOCSIWRETRY */
3171 (iw_handler
) ieee80211_ioctl_giwretry
, /* SIOCGIWRETRY */
3172 (iw_handler
) ieee80211_ioctl_siwencode
, /* SIOCSIWENCODE */
3173 (iw_handler
) ieee80211_ioctl_giwencode
, /* SIOCGIWENCODE */
3174 (iw_handler
) NULL
, /* SIOCSIWPOWER */
3175 (iw_handler
) NULL
, /* SIOCGIWPOWER */
3176 (iw_handler
) NULL
, /* -- hole -- */
3177 (iw_handler
) NULL
, /* -- hole -- */
3178 (iw_handler
) ieee80211_ioctl_siwgenie
, /* SIOCSIWGENIE */
3179 (iw_handler
) NULL
, /* SIOCGIWGENIE */
3180 (iw_handler
) ieee80211_ioctl_siwauth
, /* SIOCSIWAUTH */
3181 (iw_handler
) ieee80211_ioctl_giwauth
, /* SIOCGIWAUTH */
3182 (iw_handler
) ieee80211_ioctl_siwencodeext
, /* SIOCSIWENCODEEXT */
3183 (iw_handler
) NULL
, /* SIOCGIWENCODEEXT */
3184 (iw_handler
) NULL
, /* SIOCSIWPMKSA */
3185 (iw_handler
) NULL
, /* -- hole -- */
3188 static const iw_handler ieee80211_private_handler
[] =
3189 { /* SIOCIWFIRSTPRIV + */
3190 (iw_handler
) ieee80211_ioctl_prism2_param
, /* 0 */
3191 (iw_handler
) ieee80211_ioctl_get_prism2_param
, /* 1 */
3194 const struct iw_handler_def ieee80211_iw_handler_def
=
3196 .num_standard
= ARRAY_SIZE(ieee80211_handler
),
3197 .num_private
= ARRAY_SIZE(ieee80211_private_handler
),
3198 .num_private_args
= ARRAY_SIZE(ieee80211_ioctl_priv
),
3199 .standard
= (iw_handler
*) ieee80211_handler
,
3200 .private = (iw_handler
*) ieee80211_private_handler
,
3201 .private_args
= (struct iw_priv_args
*) ieee80211_ioctl_priv
,
3202 .get_wireless_stats
= ieee80211_get_wireless_stats
,