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 <net/d80211_mgmt.h>
24 #include "ieee80211_i.h"
25 #include "hostapd_ioctl.h"
26 #include "ieee80211_rate.h"
31 static int ieee80211_regdom
= 0x10; /* FCC */
32 module_param(ieee80211_regdom
, int, 0444);
33 MODULE_PARM_DESC(ieee80211_regdom
, "IEEE 802.11 regulatory domain; 64=MKK");
36 * If firmware is upgraded by the vendor, additional channels can be used based
37 * on the new Japanese regulatory rules. This is indicated by setting
38 * ieee80211_japan_5ghz module parameter to one when loading the 80211 kernel
41 static int ieee80211_japan_5ghz
/* = 0 */;
42 module_param(ieee80211_japan_5ghz
, int, 0444);
43 MODULE_PARM_DESC(ieee80211_japan_5ghz
, "Vendor-updated firmware for 5 GHz");
46 static int ieee80211_ioctl_set_beacon(struct net_device
*dev
,
47 struct prism2_hostapd_param
*param
,
51 struct ieee80211_sub_if_data
*sdata
;
52 struct ieee80211_if_ap
*ap
;
53 u8
**b_head
, **b_tail
;
54 int *b_head_len
, *b_tail_len
;
57 len
= ((char *) param
->u
.beacon
.data
- (char *) param
) +
58 param
->u
.beacon
.head_len
+ param
->u
.beacon
.tail_len
;
62 else if (param_len
!= len
)
65 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
66 if (sdata
->type
!= IEEE80211_IF_TYPE_AP
)
72 b_head
= &ap
->beacon_head
;
73 b_tail
= &ap
->beacon_tail
;
74 b_head_len
= &ap
->beacon_head_len
;
75 b_tail_len
= &ap
->beacon_tail_len
;
78 printk(KERN_DEBUG
"%s: unknown beacon flag %d\n",
88 *b_head_len
= param
->u
.beacon
.head_len
;
89 *b_tail_len
= param
->u
.beacon
.tail_len
;
91 *b_head
= kmalloc(*b_head_len
, GFP_KERNEL
);
93 memcpy(*b_head
, param
->u
.beacon
.data
, *b_head_len
);
95 printk(KERN_DEBUG
"%s: failed to allocate beacon_head\n",
100 if (*b_tail_len
> 0) {
101 *b_tail
= kmalloc(*b_tail_len
, GFP_KERNEL
);
103 memcpy(*b_tail
, param
->u
.beacon
.data
+ (*b_head_len
),
106 printk(KERN_DEBUG
"%s: failed to allocate "
107 "beacon_tail\n", dev
->name
);
112 return ieee80211_if_config_beacon(dev
);
116 static int ieee80211_ioctl_get_hw_features(struct net_device
*dev
,
117 struct prism2_hostapd_param
*param
,
120 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
121 u8
*pos
= param
->u
.hw_features
.data
;
122 int left
= param_len
- (pos
- (u8
*) param
);
124 struct hostapd_ioctl_hw_modes_hdr
*hdr
;
125 struct ieee80211_rate_data
*rate
;
126 struct ieee80211_channel_data
*chan
;
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
= local
->hw
.num_modes
;
133 for (mode
= 0; mode
< local
->hw
.num_modes
; mode
++) {
135 struct ieee80211_hw_modes
*m
= &local
->hw
.modes
[mode
];
136 clen
= m
->num_channels
* sizeof(struct ieee80211_channel_data
);
137 rlen
= m
->num_rates
* sizeof(struct ieee80211_rate_data
);
138 if (left
< sizeof(*hdr
) + clen
+ rlen
)
140 left
-= sizeof(*hdr
) + clen
+ rlen
;
142 hdr
= (struct hostapd_ioctl_hw_modes_hdr
*) pos
;
144 hdr
->num_channels
= m
->num_channels
;
145 hdr
->num_rates
= m
->num_rates
;
147 pos
= (u8
*) (hdr
+ 1);
148 chan
= (struct ieee80211_channel_data
*) pos
;
149 for (i
= 0; i
< m
->num_channels
; i
++) {
150 chan
[i
].chan
= m
->channels
[i
].chan
;
151 chan
[i
].freq
= m
->channels
[i
].freq
;
152 chan
[i
].flag
= m
->channels
[i
].flag
;
156 rate
= (struct ieee80211_rate_data
*) pos
;
157 for (i
= 0; i
< m
->num_rates
; i
++) {
158 rate
[i
].rate
= m
->rates
[i
].rate
;
159 rate
[i
].flags
= m
->rates
[i
].flags
;
168 static int ieee80211_ioctl_scan(struct net_device
*dev
,
169 struct prism2_hostapd_param
*param
)
171 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
173 if (!local
->ops
->passive_scan
)
176 if ((param
->u
.scan
.now
== 1) && (local
->scan
.in_scan
== 1))
179 if (param
->u
.scan
.our_mode_only
>= 0)
180 local
->scan
.our_mode_only
= param
->u
.scan
.our_mode_only
;
181 if (param
->u
.scan
.interval
>= 0)
182 local
->scan
.interval
= param
->u
.scan
.interval
;
183 if (param
->u
.scan
.listen
>= 0)
184 local
->scan
.time
= param
->u
.scan
.listen
;
185 if (param
->u
.scan
.channel
> 0)
186 local
->scan
.channel
= param
->u
.scan
.channel
;
187 if (param
->u
.scan
.now
== 1) {
188 local
->scan
.in_scan
= 0;
189 mod_timer(&local
->scan
.timer
, jiffies
);
192 param
->u
.scan
.our_mode_only
= local
->scan
.our_mode_only
;
193 param
->u
.scan
.interval
= local
->scan
.interval
;
194 param
->u
.scan
.listen
= local
->scan
.time
;
195 if (local
->scan
.in_scan
== 1)
196 param
->u
.scan
.last_rx
= -1;
198 param
->u
.scan
.last_rx
= local
->scan
.rx_packets
;
199 local
->scan
.rx_packets
= -1;
201 param
->u
.scan
.channel
= local
->hw
.modes
[local
->scan
.mode_idx
].
202 channels
[local
->scan
.chan_idx
].chan
;
208 static int ieee80211_ioctl_flush(struct net_device
*dev
,
209 struct prism2_hostapd_param
*param
)
211 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
212 sta_info_flush(local
, NULL
);
217 /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
218 struct iapp_layer2_update
{
219 u8 da
[ETH_ALEN
]; /* broadcast */
220 u8 sa
[ETH_ALEN
]; /* STA addr */
226 } __attribute__ ((packed
));
228 static void ieee80211_send_layer2_update(struct net_device
*dev
,
231 struct iapp_layer2_update
*msg
;
234 /* Send Level 2 Update Frame to update forwarding tables in layer 2
237 skb
= dev_alloc_skb(sizeof(*msg
));
240 msg
= (struct iapp_layer2_update
*) skb_put(skb
, sizeof(*msg
));
242 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
243 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
245 memset(msg
->da
, 0xff, ETH_ALEN
);
246 memcpy(msg
->sa
, addr
, ETH_ALEN
);
249 msg
->ssap
= 0x01; /* NULL LSAP, CR Bit: Response */
250 msg
->control
= 0xaf; /* XID response lsb.1111F101.
251 * F=0 (no poll command; unsolicited frame) */
252 msg
->xid_info
[0] = 0x81; /* XID format identifier */
253 msg
->xid_info
[1] = 1; /* LLC types/classes: Type 1 LLC */
254 msg
->xid_info
[2] = 0; /* XID sender's receive window size (RW) */
257 skb
->protocol
= eth_type_trans(skb
, dev
);
258 memset(skb
->cb
, 0, sizeof(skb
->cb
));
263 static int ieee80211_ioctl_add_sta(struct net_device
*dev
,
264 struct prism2_hostapd_param
*param
)
266 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
267 struct sta_info
*sta
;
270 struct ieee80211_sub_if_data
*sdata
;
271 int add_key_entry
= 1;
273 /* Prevent a race with changing the rate control algorithm */
274 if (!netif_running(dev
))
277 sta
= sta_info_get(local
, param
->sta_addr
);
280 sta
= sta_info_add(local
, dev
, param
->sta_addr
, GFP_KERNEL
);
285 if (sta
->dev
!= dev
) {
286 /* Binding STA to a new interface, so remove all references to
288 sta_info_remove_aid_ptr(sta
);
292 * We "steal" the device in case someone owns it
293 * This will hurt WDS links and such when we have a
294 * WDS link and a client associating from the same station
297 sdata
= IEEE80211_DEV_TO_SUB_IF(sta
->dev
);
299 sta
->flags
|= WLAN_STA_AUTH
| WLAN_STA_ASSOC
;
300 sta
->aid
= param
->u
.add_sta
.aid
;
301 if (sta
->aid
> IEEE80211_MAX_AID
)
303 sta
->listen_interval
= param
->u
.add_sta
.listen_interval
;
306 for (i
= 0; i
< sizeof(param
->u
.add_sta
.supp_rates
); i
++) {
307 int rate
= (param
->u
.add_sta
.supp_rates
[i
] & 0x7f) * 5;
308 if (local
->hw
.conf
.phymode
== MODE_ATHEROS_TURBO
||
309 local
->hw
.conf
.phymode
== MODE_ATHEROS_TURBOG
)
311 for (j
= 0; j
< local
->num_curr_rates
; j
++) {
312 if (local
->curr_rates
[j
].rate
== rate
)
317 sta
->supp_rates
= rates
;
319 rate_control_rate_init(sta
, local
);
321 if (param
->u
.add_sta
.wds_flags
& 0x01)
322 sta
->flags
|= WLAN_STA_WDS
;
324 sta
->flags
&= ~WLAN_STA_WDS
;
326 if (add_key_entry
&& !sta
->key
&& !sdata
->default_key
&&
327 local
->ops
->set_key
) {
328 struct ieee80211_key_conf conf
;
329 /* Add key cache entry with NULL key type because this may used
330 * for TX filtering. */
331 memset(&conf
, 0, sizeof(conf
));
332 conf
.hw_key_idx
= HW_KEY_IDX_INVALID
;
334 conf
.flags
|= IEEE80211_KEY_FORCE_SW_ENCRYPT
;
335 if (local
->ops
->set_key(local_to_hw(local
), SET_KEY
,
336 sta
->addr
, &conf
, sta
->aid
)) {
337 sta
->key_idx_compression
= HW_KEY_IDX_INVALID
;
339 sta
->key_idx_compression
= conf
.hw_key_idx
;
345 if (sdata
->type
== IEEE80211_IF_TYPE_AP
||
346 sdata
->type
== IEEE80211_IF_TYPE_VLAN
)
347 ieee80211_send_layer2_update(dev
, param
->sta_addr
);
353 static int ieee80211_ioctl_remove_sta(struct net_device
*dev
,
354 struct prism2_hostapd_param
*param
)
356 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
357 struct sta_info
*sta
;
359 sta
= sta_info_get(local
, param
->sta_addr
);
362 sta_info_free(sta
, 1);
365 return sta
? 0 : -ENOENT
;
369 static int ieee80211_ioctl_get_dot11counterstable(struct net_device
*dev
,
370 struct prism2_hostapd_param
*param
)
372 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
373 struct ieee80211_low_level_stats stats
;
375 memset(&stats
, 0, sizeof(stats
));
376 if (local
->ops
->get_stats
)
377 local
->ops
->get_stats(local_to_hw(local
), &stats
);
378 param
->u
.dot11CountersTable
.dot11TransmittedFragmentCount
=
379 local
->dot11TransmittedFragmentCount
;
380 param
->u
.dot11CountersTable
.dot11MulticastTransmittedFrameCount
=
381 local
->dot11MulticastTransmittedFrameCount
;
382 param
->u
.dot11CountersTable
.dot11ReceivedFragmentCount
=
383 local
->dot11ReceivedFragmentCount
;
384 param
->u
.dot11CountersTable
.dot11MulticastReceivedFrameCount
=
385 local
->dot11MulticastReceivedFrameCount
;
386 param
->u
.dot11CountersTable
.dot11TransmittedFrameCount
=
387 local
->dot11TransmittedFrameCount
;
388 param
->u
.dot11CountersTable
.dot11FCSErrorCount
=
389 stats
.dot11FCSErrorCount
;
390 param
->u
.dot11CountersTable
.dot11ACKFailureCount
=
391 stats
.dot11ACKFailureCount
;
392 param
->u
.dot11CountersTable
.dot11RTSFailureCount
=
393 stats
.dot11RTSFailureCount
;
394 param
->u
.dot11CountersTable
.dot11RTSSuccessCount
=
395 stats
.dot11RTSSuccessCount
;
401 static int ieee80211_ioctl_get_info_sta(struct net_device
*dev
,
402 struct prism2_hostapd_param
*param
)
404 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
405 struct sta_info
*sta
;
407 if (param
->sta_addr
[0] == 0xff && param
->sta_addr
[1] == 0xff &&
408 param
->sta_addr
[2] == 0xff && param
->sta_addr
[3] == 0xff &&
409 param
->sta_addr
[4] == 0xff && param
->sta_addr
[5] == 0xff) {
410 struct ieee80211_sub_if_data
*sdata
;
411 struct net_device_stats
*stats
;
413 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
414 stats
= ieee80211_dev_stats(local
->mdev
);
415 param
->u
.get_info_sta
.rx_bytes
= stats
->rx_bytes
;
416 param
->u
.get_info_sta
.tx_bytes
= stats
->tx_bytes
;
417 /* go through all STAs and get STA with lowest max. rate */
418 param
->u
.get_info_sta
.current_tx_rate
=
419 local
->curr_rates
[sta_info_min_txrate_get(local
)].rate
;
423 sta
= sta_info_get(local
, param
->sta_addr
);
428 param
->u
.get_info_sta
.inactive_msec
=
429 jiffies_to_msecs(jiffies
- sta
->last_rx
);
430 param
->u
.get_info_sta
.rx_packets
= sta
->rx_packets
;
431 param
->u
.get_info_sta
.tx_packets
= sta
->tx_packets
;
432 param
->u
.get_info_sta
.rx_bytes
= sta
->rx_bytes
;
433 param
->u
.get_info_sta
.tx_bytes
= sta
->tx_bytes
;
434 param
->u
.get_info_sta
.channel_use
= sta
->channel_use
;
435 param
->u
.get_info_sta
.flags
= sta
->flags
;
436 if (sta
->txrate
>= 0 && sta
->txrate
< local
->num_curr_rates
)
437 param
->u
.get_info_sta
.current_tx_rate
=
438 local
->curr_rates
[sta
->txrate
].rate
;
439 param
->u
.get_info_sta
.num_ps_buf_frames
=
440 skb_queue_len(&sta
->ps_tx_buf
);
441 param
->u
.get_info_sta
.tx_retry_failed
= sta
->tx_retry_failed
;
442 param
->u
.get_info_sta
.tx_retry_count
= sta
->tx_retry_count
;
443 param
->u
.get_info_sta
.last_rssi
= sta
->last_rssi
;
444 param
->u
.get_info_sta
.last_ack_rssi
= sta
->last_ack_rssi
[2];
452 static int ieee80211_ioctl_set_flags_sta(struct net_device
*dev
,
453 struct prism2_hostapd_param
*param
)
455 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
456 struct sta_info
*sta
;
458 sta
= sta_info_get(local
, param
->sta_addr
);
460 sta
->flags
|= param
->u
.set_flags_sta
.flags_or
;
461 sta
->flags
&= param
->u
.set_flags_sta
.flags_and
;
462 if (local
->ops
->set_port_auth
&&
463 (param
->u
.set_flags_sta
.flags_or
& WLAN_STA_AUTHORIZED
) &&
464 local
->ops
->set_port_auth(local_to_hw(local
), sta
->addr
, 1))
465 printk(KERN_DEBUG
"%s: failed to set low-level driver "
466 "PAE state (authorized) for " MAC_FMT
"\n",
467 dev
->name
, MAC_ARG(sta
->addr
));
468 if (local
->ops
->set_port_auth
&&
469 !(param
->u
.set_flags_sta
.flags_and
& WLAN_STA_AUTHORIZED
) &&
470 local
->ops
->set_port_auth(local_to_hw(local
), sta
->addr
, 0))
471 printk(KERN_DEBUG
"%s: failed to set low-level driver "
472 "PAE state (unauthorized) for " MAC_FMT
"\n",
473 dev
->name
, MAC_ARG(sta
->addr
));
477 return sta
? 0 : -ENOENT
;
481 int ieee80211_set_hw_encryption(struct net_device
*dev
,
482 struct sta_info
*sta
, u8 addr
[ETH_ALEN
],
483 struct ieee80211_key
*key
)
485 struct ieee80211_key_conf
*keyconf
= NULL
;
486 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
489 /* default to sw encryption; this will be cleared by low-level
490 * driver if the hw supports requested encryption */
492 key
->force_sw_encrypt
= 1;
494 if (key
&& local
->ops
->set_key
&&
495 (keyconf
= ieee80211_key_data2conf(local
, key
))) {
496 if (local
->ops
->set_key(local_to_hw(local
), SET_KEY
, addr
,
497 keyconf
, sta
? sta
->aid
: 0)) {
498 rc
= HOSTAP_CRYPT_ERR_KEY_SET_FAILED
;
499 key
->force_sw_encrypt
= 1;
500 key
->hw_key_idx
= HW_KEY_IDX_INVALID
;
502 key
->force_sw_encrypt
=
503 !!(keyconf
->flags
& IEEE80211_KEY_FORCE_SW_ENCRYPT
);
515 static int ieee80211_set_encryption(struct net_device
*dev
, u8
*sta_addr
,
516 int idx
, int alg
, int set_tx_key
, int *err
,
517 const u8
*_key
, size_t key_len
)
519 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
521 struct sta_info
*sta
;
522 struct ieee80211_key
*key
, *old_key
;
524 struct ieee80211_key_conf
*keyconf
;
525 struct ieee80211_sub_if_data
*sdata
;
527 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
529 if (sta_addr
[0] == 0xff && sta_addr
[1] == 0xff &&
530 sta_addr
[2] == 0xff && sta_addr
[3] == 0xff &&
531 sta_addr
[4] == 0xff && sta_addr
[5] == 0xff) {
533 if (idx
>= NUM_DEFAULT_KEYS
) {
534 printk(KERN_DEBUG
"%s: set_encrypt - invalid idx=%d\n",
538 key
= sdata
->keys
[idx
];
540 /* Disable hwaccel for default keys when the interface is not
542 * TODO: consider adding hwaccel support for these; at least
543 * Atheros key cache should be able to handle this since AP is
544 * only transmitting frames with default keys. */
545 /* FIX: hw key cache can be used when only one virtual
546 * STA is associated with each AP. If more than one STA
547 * is associated to the same AP, software encryption
548 * must be used. This should be done automatically
549 * based on configured station devices. For the time
550 * being, this can be only set at compile time. */
551 /* FIXME: There is no more anything like "default
552 * interface". We should try hwaccel if there is just one
553 * interface - for now, hwaccel is unconditionaly
559 printk(KERN_DEBUG
"%s: set_encrypt - non-zero idx for "
560 "individual key\n", dev
->name
);
564 sta
= sta_info_get(local
, sta_addr
);
567 *err
= HOSTAP_CRYPT_ERR_UNKNOWN_ADDR
;
568 #ifdef CONFIG_D80211_VERBOSE_DEBUG
569 printk(KERN_DEBUG
"%s: set_encrypt - unknown addr "
571 dev
->name
, MAC_ARG(sta_addr
));
572 #endif /* CONFIG_D80211_VERBOSE_DEBUG */
581 * Cannot configure default hwaccel keys with WEP algorithm, if
582 * any of the virtual interfaces is using static WEP
583 * configuration because hwaccel would otherwise try to decrypt
586 * For now, just disable WEP hwaccel for broadcast when there is
587 * possibility of conflict with default keys. This can maybe later be
588 * optimized by using non-default keys (at least with Atheros ar521x).
590 if (!sta
&& alg
== ALG_WEP
&& !local
->default_wep_only
&&
591 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
&&
592 sdata
->type
!= IEEE80211_IF_TYPE_AP
) {
596 if (local
->hw
.flags
& IEEE80211_HW_DEVICE_HIDES_WEP
) {
597 /* Software encryption cannot be used with devices that hide
598 * encryption from the host system, so always try to use
599 * hardware acceleration with such devices. */
603 if ((local
->hw
.flags
& IEEE80211_HW_NO_TKIP_WMM_HWACCEL
) &&
605 if (sta
&& (sta
->flags
& WLAN_STA_WME
)) {
606 /* Hardware does not support hwaccel with TKIP when using WMM.
610 else if (sdata
->type
== IEEE80211_IF_TYPE_STA
) {
611 sta
= sta_info_get(local
, sdata
->u
.sta
.bssid
);
613 if (sta
->flags
& WLAN_STA_WME
) {
622 if (alg
== ALG_NONE
) {
624 if (try_hwaccel
&& key
&& local
->ops
->set_key
&&
625 (keyconf
= ieee80211_key_data2conf(local
, key
)) != NULL
&&
626 local
->ops
->set_key(local_to_hw(local
), DISABLE_KEY
,
627 sta_addr
, keyconf
, sta
? sta
->aid
: 0)) {
629 *err
= HOSTAP_CRYPT_ERR_KEY_SET_FAILED
;
630 printk(KERN_DEBUG
"%s: set_encrypt - low-level disable"
631 " failed\n", dev
->name
);
636 if (key
&& sdata
->default_key
== key
) {
637 ieee80211_key_sysfs_remove_default(sdata
);
638 sdata
->default_key
= NULL
;
640 ieee80211_key_sysfs_remove(key
);
644 sdata
->keys
[idx
] = NULL
;
645 ieee80211_key_free(key
);
649 key
= ieee80211_key_alloc(sta
? NULL
: sdata
, idx
, key_len
,
656 /* default to sw encryption; low-level driver sets these if the
657 * requested encryption is supported */
658 key
->hw_key_idx
= HW_KEY_IDX_INVALID
;
659 key
->force_sw_encrypt
= 1;
663 key
->keylen
= key_len
;
664 memcpy(key
->key
, _key
, key_len
);
666 key
->default_tx_key
= 1;
668 if (alg
== ALG_CCMP
) {
669 /* Initialize AES key state here as an optimization
670 * so that it does not need to be initialized for every
672 key
->u
.ccmp
.tfm
= ieee80211_aes_key_setup_encrypt(
674 if (!key
->u
.ccmp
.tfm
) {
680 if (old_key
&& sdata
->default_key
== old_key
) {
681 ieee80211_key_sysfs_remove_default(sdata
);
682 sdata
->default_key
= NULL
;
684 ieee80211_key_sysfs_remove(old_key
);
688 sdata
->keys
[idx
] = key
;
689 ieee80211_key_free(old_key
);
691 key
->kobj
.parent
= &sta
->kobj
;
692 ret
= ieee80211_key_sysfs_add(key
);
697 (alg
== ALG_WEP
|| alg
== ALG_TKIP
|| alg
== ALG_CCMP
)) {
698 int e
= ieee80211_set_hw_encryption(dev
, sta
, sta_addr
,
705 if (set_tx_key
|| (!sta
&& !sdata
->default_key
&& key
)) {
706 sdata
->default_key
= key
;
707 if (ieee80211_key_sysfs_add_default(sdata
))
708 printk(KERN_WARNING
"%s: cannot create symlink to "
709 "default key\n", dev
->name
);
710 if (local
->ops
->set_key_idx
&&
711 local
->ops
->set_key_idx(local_to_hw(local
), idx
))
712 printk(KERN_DEBUG
"%s: failed to set TX key idx for "
713 "low-level driver\n", dev
->name
);
725 sdata
->keys
[idx
] = NULL
;
727 ieee80211_key_free(key
);
735 static int ieee80211_ioctl_set_encryption(struct net_device
*dev
,
736 struct prism2_hostapd_param
*param
,
741 param
->u
.crypt
.err
= 0;
742 param
->u
.crypt
.alg
[HOSTAP_CRYPT_ALG_NAME_LEN
- 1] = '\0';
745 (int) ((char *) param
->u
.crypt
.key
- (char *) param
) +
746 param
->u
.crypt
.key_len
) {
747 printk(KERN_DEBUG
"%s: set_encrypt - invalid param_lem\n",
752 if (strcmp(param
->u
.crypt
.alg
, "none") == 0)
754 else if (strcmp(param
->u
.crypt
.alg
, "WEP") == 0)
756 else if (strcmp(param
->u
.crypt
.alg
, "TKIP") == 0) {
757 if (param
->u
.crypt
.key_len
!= ALG_TKIP_KEY_LEN
) {
758 printk(KERN_DEBUG
"%s: set_encrypt - invalid TKIP key "
759 "length %d\n", dev
->name
,
760 param
->u
.crypt
.key_len
);
764 } else if (strcmp(param
->u
.crypt
.alg
, "CCMP") == 0) {
765 if (param
->u
.crypt
.key_len
!= ALG_CCMP_KEY_LEN
) {
766 printk(KERN_DEBUG
"%s: set_encrypt - invalid CCMP key "
767 "length %d\n", dev
->name
,
768 param
->u
.crypt
.key_len
);
773 param
->u
.crypt
.err
= HOSTAP_CRYPT_ERR_UNKNOWN_ALG
;
774 printk(KERN_DEBUG
"%s: set_encrypt - unknown alg\n",
779 return ieee80211_set_encryption(
780 dev
, param
->sta_addr
,
781 param
->u
.crypt
.idx
, alg
,
782 param
->u
.crypt
.flags
& HOSTAP_CRYPT_FLAG_SET_TX_KEY
,
783 ¶m
->u
.crypt
.err
, param
->u
.crypt
.key
,
784 param
->u
.crypt
.key_len
);
788 static int ieee80211_ioctl_get_encryption(struct net_device
*dev
,
789 struct prism2_hostapd_param
*param
,
792 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
794 struct sta_info
*sta
;
795 struct ieee80211_key
**key
;
797 struct ieee80211_sub_if_data
*sdata
;
800 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
802 param
->u
.crypt
.err
= 0;
804 max_key_len
= param_len
-
805 (int) ((char *) param
->u
.crypt
.key
- (char *) param
);
809 if (param
->sta_addr
[0] == 0xff && param
->sta_addr
[1] == 0xff &&
810 param
->sta_addr
[2] == 0xff && param
->sta_addr
[3] == 0xff &&
811 param
->sta_addr
[4] == 0xff && param
->sta_addr
[5] == 0xff) {
813 if (param
->u
.crypt
.idx
> NUM_DEFAULT_KEYS
) {
814 param
->u
.crypt
.idx
= sdata
->default_key
?
815 sdata
->default_key
->keyidx
: 0;
818 key
= &sdata
->keys
[param
->u
.crypt
.idx
];
820 sta
= sta_info_get(local
, param
->sta_addr
);
822 param
->u
.crypt
.err
= HOSTAP_CRYPT_ERR_UNKNOWN_ADDR
;
829 memset(param
->u
.crypt
.seq_counter
, 0, HOSTAP_SEQ_COUNTER_SIZE
);
831 memcpy(param
->u
.crypt
.alg
, "none", 5);
832 param
->u
.crypt
.key_len
= 0;
833 param
->u
.crypt
.idx
= 0xff;
835 switch ((*key
)->alg
) {
837 memcpy(param
->u
.crypt
.alg
, "WEP", 4);
844 memcpy(param
->u
.crypt
.alg
, "TKIP", 5);
845 if (local
->ops
->get_sequence_counter
) {
846 /* Get transmit counter from low level driver */
847 if (local
->ops
->get_sequence_counter(
851 IEEE80211_SEQ_COUNTER_TX
,
854 /* Error getting value from device */
858 /* Get it from our own local data */
859 iv32
= (*key
)->u
.tkip
.iv32
;
860 iv16
= (*key
)->u
.tkip
.iv16
;
862 pos
= param
->u
.crypt
.seq_counter
;
863 *pos
++ = iv16
& 0xff;
864 *pos
++ = (iv16
>> 8) & 0xff;
865 *pos
++ = iv32
& 0xff;
866 *pos
++ = (iv32
>> 8) & 0xff;
867 *pos
++ = (iv32
>> 16) & 0xff;
868 *pos
++ = (iv32
>> 24) & 0xff;
874 memcpy(param
->u
.crypt
.alg
, "CCMP", 5);
875 pos
= param
->u
.crypt
.seq_counter
;
876 pn
= (*key
)->u
.ccmp
.tx_pn
;
886 memcpy(param
->u
.crypt
.alg
, "unknown", 8);
890 if (max_key_len
< (*key
)->keylen
)
893 param
->u
.crypt
.key_len
= (*key
)->keylen
;
894 memcpy(param
->u
.crypt
.key
, (*key
)->key
,
906 #ifdef CONFIG_HOSTAPD_WPA_TESTING
907 static int ieee80211_ioctl_wpa_trigger(struct net_device
*dev
,
908 struct prism2_hostapd_param
*param
)
910 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
911 struct sta_info
*sta
;
913 if (param
->sta_addr
[0] == 0xff && param
->sta_addr
[1] == 0xff &&
914 param
->sta_addr
[2] == 0xff && param
->sta_addr
[3] == 0xff &&
915 param
->sta_addr
[4] == 0xff && param
->sta_addr
[5] == 0xff) {
916 local
->wpa_trigger
= param
->u
.wpa_trigger
.trigger
;
920 sta
= sta_info_get(local
, param
->sta_addr
);
922 printk(KERN_DEBUG
"%s: wpa_trigger - unknown addr\n",
927 sta
->wpa_trigger
= param
->u
.wpa_trigger
.trigger
;
932 #endif /* CONFIG_HOSTAPD_WPA_TESTING */
935 static int ieee80211_ioctl_set_rate_sets(struct net_device
*dev
,
936 struct prism2_hostapd_param
*param
,
939 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
940 u16
*pos
= (u16
*) param
->u
.set_rate_sets
.data
;
941 int left
= param_len
- ((u8
*) pos
- (u8
*) param
);
942 int i
, mode
, num_supp
, num_basic
, *supp
, *basic
, *prev
;
944 mode
= param
->u
.set_rate_sets
.mode
;
945 num_supp
= param
->u
.set_rate_sets
.num_supported_rates
;
946 num_basic
= param
->u
.set_rate_sets
.num_basic_rates
;
948 if (left
< (num_supp
+ num_basic
) * 2) {
949 printk(KERN_WARNING
"%s: invalid length in hostapd set rate "
950 "sets ioctl (%d != %d)\n", dev
->name
, left
,
951 (num_supp
+ num_basic
) * 2);
955 supp
= (int *) kmalloc((num_supp
+ 1) * sizeof(int), GFP_KERNEL
);
956 basic
= (int *) kmalloc((num_basic
+ 1) * sizeof(int), GFP_KERNEL
);
958 if (!supp
|| !basic
) {
964 for (i
= 0; i
< num_supp
; i
++)
968 for (i
= 0; i
< num_basic
; i
++)
977 if (num_basic
== 0) {
982 prev
= local
->supp_rates
[mode
];
983 local
->supp_rates
[mode
] = supp
;
986 prev
= local
->basic_rates
[mode
];
987 local
->basic_rates
[mode
] = basic
;
990 if (mode
== local
->hw
.conf
.phymode
) {
991 /* TODO: should update STA TX rates and remove STAs if they
992 * do not have any remaining supported rates after the change
994 ieee80211_prepare_rates(local
);
1001 static int ieee80211_ioctl_add_if(struct net_device
*dev
,
1002 struct prism2_hostapd_param
*param
,
1005 u8
*pos
= param
->u
.if_info
.data
;
1006 int left
= param_len
- ((u8
*) pos
- (u8
*) param
);
1007 struct net_device
*new_dev
;
1009 struct hostapd_if_wds
*wds
;
1010 struct hostapd_if_bss
*bss
;
1012 printk(KERN_WARNING
"PRISM2_HOSTAPD_ADD_IF ioctl is deprecated!");
1013 switch (param
->u
.if_info
.type
) {
1015 wds
= (struct hostapd_if_wds
*) param
->u
.if_info
.data
;
1017 if (left
< sizeof(struct hostapd_if_wds
))
1020 res
= ieee80211_if_add(dev
, param
->u
.if_info
.name
, 0, &new_dev
);
1023 ieee80211_if_set_type(new_dev
, IEEE80211_IF_TYPE_WDS
);
1024 res
= ieee80211_if_update_wds(new_dev
, wds
->remote_addr
);
1026 __ieee80211_if_del(dev
->ieee80211_ptr
,
1027 IEEE80211_DEV_TO_SUB_IF(new_dev
));
1029 case HOSTAP_IF_VLAN
:
1030 if (left
< sizeof(struct hostapd_if_vlan
))
1033 res
= ieee80211_if_add(dev
, param
->u
.if_info
.name
, 0, &new_dev
);
1036 ieee80211_if_set_type(new_dev
, IEEE80211_IF_TYPE_VLAN
);
1038 res
= ieee80211_if_update_vlan(new_dev
, vlan
->id
);
1040 __ieee80211_if_del(dev
->ieee80211_ptr
,
1041 IEEE80211_DEV_TO_SUB_IF(new_dev
));
1045 bss
= (struct hostapd_if_bss
*) param
->u
.if_info
.data
;
1047 if (left
< sizeof(struct hostapd_if_bss
))
1050 res
= ieee80211_if_add(dev
, param
->u
.if_info
.name
, 0, &new_dev
);
1053 ieee80211_if_set_type(new_dev
, IEEE80211_IF_TYPE_AP
);
1054 memcpy(new_dev
->dev_addr
, bss
->bssid
, ETH_ALEN
);
1057 if (left
< sizeof(struct hostapd_if_sta
))
1060 res
= ieee80211_if_add(dev
, param
->u
.if_info
.name
, 0, &new_dev
);
1063 ieee80211_if_set_type(new_dev
, IEEE80211_IF_TYPE_STA
);
1072 static int ieee80211_ioctl_remove_if(struct net_device
*dev
,
1073 struct prism2_hostapd_param
*param
)
1077 switch (param
->u
.if_info
.type
) {
1079 type
= IEEE80211_IF_TYPE_WDS
;
1081 case HOSTAP_IF_VLAN
:
1082 type
= IEEE80211_IF_TYPE_VLAN
;
1085 type
= IEEE80211_IF_TYPE_AP
;
1088 type
= IEEE80211_IF_TYPE_STA
;
1094 return ieee80211_if_remove(dev
, param
->u
.if_info
.name
, type
);
1097 static int ieee80211_ioctl_update_if(struct net_device
*dev
,
1098 struct prism2_hostapd_param
*param
,
1101 u8
*pos
= param
->u
.if_info
.data
;
1102 int left
= param_len
- ((u8
*) pos
- (u8
*) param
);
1104 if (param
->u
.if_info
.type
== HOSTAP_IF_WDS
) {
1105 struct hostapd_if_wds
*wds
=
1106 (struct hostapd_if_wds
*) param
->u
.if_info
.data
;
1107 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1108 struct net_device
*wds_dev
= NULL
;
1109 struct ieee80211_sub_if_data
*sdata
;
1111 if (left
< sizeof(struct ieee80211_if_wds
))
1114 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
1115 if (strcmp(param
->u
.if_info
.name
,
1116 sdata
->dev
->name
) == 0) {
1117 wds_dev
= sdata
->dev
;
1122 if (!wds_dev
|| sdata
->type
!= IEEE80211_IF_TYPE_WDS
)
1125 return ieee80211_if_update_wds(wds_dev
, wds
->remote_addr
);
1132 static int ieee80211_ioctl_flush_ifs(struct net_device
*dev
,
1133 struct prism2_hostapd_param
*param
)
1135 ieee80211_if_flush(dev
);
1140 static int ieee80211_ioctl_scan_req(struct net_device
*dev
,
1141 struct prism2_hostapd_param
*param
,
1144 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1145 u8
*pos
= param
->u
.scan_req
.ssid
;
1146 int left
= param_len
- ((u8
*) pos
- (u8
*) param
);
1147 int len
= param
->u
.scan_req
.ssid_len
;
1149 if (local
->user_space_mlme
)
1152 if (!netif_running(dev
))
1155 if (left
< len
|| len
> IEEE80211_MAX_SSID_LEN
)
1158 return ieee80211_sta_req_scan(dev
, pos
, len
);
1162 static int ieee80211_ioctl_sta_get_state(struct net_device
*dev
,
1163 struct prism2_hostapd_param
*param
)
1165 struct ieee80211_sub_if_data
*sdata
;
1167 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1168 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
1169 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
1171 param
->u
.sta_get_state
.state
= sdata
->u
.sta
.state
;
1176 static int ieee80211_ioctl_mlme(struct net_device
*dev
,
1177 struct prism2_hostapd_param
*param
)
1179 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1180 struct ieee80211_sub_if_data
*sdata
;
1182 if (local
->user_space_mlme
)
1185 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1186 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
1187 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
1189 switch (param
->u
.mlme
.cmd
) {
1190 case MLME_STA_DEAUTH
:
1191 return ieee80211_sta_deauthenticate(dev
, param
->u
.mlme
.reason_code
);
1192 case MLME_STA_DISASSOC
:
1193 return ieee80211_sta_disassociate(dev
, param
->u
.mlme
.reason_code
);
1199 static int ieee80211_ioctl_get_load_stats(struct net_device
*dev
,
1200 struct prism2_hostapd_param
*param
)
1202 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1204 param
->u
.get_load_stats
.channel_use
= local
->channel_use
;
1205 /* if (param->u.get_load_stats.flags & LOAD_STATS_CLEAR)
1206 local->channel_use = 0; */ /* now it's not raw counter */
1212 static int ieee80211_ioctl_set_sta_vlan(struct net_device
*dev
,
1213 struct prism2_hostapd_param
*param
)
1215 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1216 struct sta_info
*sta
;
1218 sta
= sta_info_get(local
, param
->sta_addr
);
1220 struct net_device
*new_vlan_dev
;
1222 dev_get_by_name(param
->u
.set_sta_vlan
.vlan_name
);
1225 printk("%s: Station " MAC_FMT
" moved to vlan: %s\n",
1226 dev
->name
, MAC_ARG(param
->sta_addr
),
1227 new_vlan_dev
->name
);
1229 if (sta
->dev
!= new_vlan_dev
) {
1230 ieee80211_send_layer2_update(new_vlan_dev
,
1233 sta
->dev
= new_vlan_dev
;
1234 sta
->vlan_id
= param
->u
.set_sta_vlan
.vlan_id
;
1235 dev_put(new_vlan_dev
);
1240 return sta
? 0 : -ENOENT
;
1244 static int ieee80211_set_gen_ie(struct net_device
*dev
, u8
*ie
, size_t len
)
1246 struct ieee80211_sub_if_data
*sdata
;
1247 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1249 if (local
->user_space_mlme
)
1252 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1253 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
1254 sdata
->type
== IEEE80211_IF_TYPE_IBSS
)
1255 return ieee80211_sta_set_extra_ie(dev
, ie
, len
);
1257 if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
1258 kfree(sdata
->u
.ap
.generic_elem
);
1259 sdata
->u
.ap
.generic_elem
= kmalloc(len
, GFP_KERNEL
);
1260 if (!sdata
->u
.ap
.generic_elem
)
1262 memcpy(sdata
->u
.ap
.generic_elem
, ie
, len
);
1263 sdata
->u
.ap
.generic_elem_len
= len
;
1264 return ieee80211_if_config(dev
);
1271 ieee80211_ioctl_set_generic_info_elem(struct net_device
*dev
,
1272 struct prism2_hostapd_param
*param
,
1275 u8
*pos
= param
->u
.set_generic_info_elem
.data
;
1276 int left
= param_len
- ((u8
*) pos
- (u8
*) param
);
1277 int len
= param
->u
.set_generic_info_elem
.len
;
1282 return ieee80211_set_gen_ie(dev
, pos
, len
);
1286 static int ieee80211_ioctl_set_regulatory_domain(struct net_device
*dev
,
1287 struct prism2_hostapd_param
*param
)
1289 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1290 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
1291 conf
->regulatory_domain
= param
->u
.set_regulatory_domain
.rd
;
1296 static int ieee80211_ioctl_set_radio_enabled(struct net_device
*dev
,
1299 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1300 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
1302 conf
->radio_enabled
= val
;
1303 return ieee80211_hw_config(dev
->ieee80211_ptr
);
1307 ieee80211_ioctl_set_tx_queue_params(struct net_device
*dev
,
1308 struct prism2_hostapd_param
*param
)
1310 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1311 struct ieee80211_tx_queue_params qparam
;
1313 if (!local
->ops
->conf_tx
) {
1314 printk(KERN_DEBUG
"%s: low-level driver does not support TX "
1315 "queue configuration\n", dev
->name
);
1319 memset(&qparam
, 0, sizeof(qparam
));
1320 qparam
.aifs
= param
->u
.tx_queue_params
.aifs
;
1321 qparam
.cw_min
= param
->u
.tx_queue_params
.cw_min
;
1322 qparam
.cw_max
= param
->u
.tx_queue_params
.cw_max
;
1323 qparam
.burst_time
= param
->u
.tx_queue_params
.burst_time
;
1325 return local
->ops
->conf_tx(local_to_hw(local
),
1326 param
->u
.tx_queue_params
.queue
,
1331 static int ieee80211_ioctl_get_tx_stats(struct net_device
*dev
,
1332 struct prism2_hostapd_param
*param
)
1334 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1335 struct ieee80211_tx_queue_stats stats
;
1338 if (!local
->ops
->get_tx_stats
)
1341 memset(&stats
, 0, sizeof(stats
));
1342 ret
= local
->ops
->get_tx_stats(local_to_hw(local
), &stats
);
1346 for (i
= 0; i
< 4; i
++) {
1347 param
->u
.get_tx_stats
.data
[i
].len
= stats
.data
[i
].len
;
1348 param
->u
.get_tx_stats
.data
[i
].limit
= stats
.data
[i
].limit
;
1349 param
->u
.get_tx_stats
.data
[i
].count
= stats
.data
[i
].count
;
1356 static int ieee80211_ioctl_set_channel_flag(struct net_device
*dev
,
1357 struct prism2_hostapd_param
*param
)
1359 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1360 struct ieee80211_hw_modes
*mode
= NULL
;
1361 struct ieee80211_channel
*chan
= NULL
;
1364 for (i
= 0; i
< local
->hw
.num_modes
; i
++) {
1365 mode
= &local
->hw
.modes
[i
];
1366 if (mode
->mode
== param
->u
.set_channel_flag
.mode
)
1374 for (i
= 0; i
< mode
->num_channels
; i
++) {
1375 chan
= &mode
->channels
[i
];
1376 if (chan
->chan
== param
->u
.set_channel_flag
.chan
)
1384 chan
->flag
= param
->u
.set_channel_flag
.flag
;
1385 chan
->power_level
= param
->u
.set_channel_flag
.power_level
;
1386 chan
->antenna_max
= param
->u
.set_channel_flag
.antenna_max
;
1392 static int ieee80211_ioctl_set_quiet_params(struct net_device
*dev
,
1393 struct prism2_hostapd_param
*param
)
1395 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1396 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
1398 conf
->quiet_duration
= param
->u
.quiet
.duration
;
1399 conf
->quiet_offset
= param
->u
.quiet
.offset
;
1400 conf
->quiet_period
= param
->u
.quiet
.period
;
1405 static int ieee80211_ioctl_set_radar_params(struct net_device
*dev
,
1406 struct prism2_hostapd_param
*param
)
1408 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1409 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
1411 conf
->radar_firpwr_threshold
= param
->u
.radar
.radar_firpwr_threshold
;
1412 conf
->radar_rssi_threshold
= param
->u
.radar
.radar_rssi_threshold
;
1413 conf
->pulse_height_threshold
= param
->u
.radar
.pulse_height_threshold
;
1414 conf
->pulse_rssi_threshold
= param
->u
.radar
.pulse_rssi_threshold
;
1415 conf
->pulse_inband_threshold
= param
->u
.radar
.pulse_inband_threshold
;
1420 static int ieee80211_ioctl_priv_hostapd(struct net_device
*dev
,
1423 struct prism2_hostapd_param
*param
;
1426 if (p
->length
< sizeof(struct prism2_hostapd_param
) ||
1427 p
->length
> PRISM2_HOSTAPD_MAX_BUF_SIZE
|| !p
->pointer
) {
1428 printk(KERN_DEBUG
"%s: hostapd ioctl: ptr=%p len=%d min=%d "
1429 "max=%d\n", dev
->name
, p
->pointer
, p
->length
,
1430 (int)sizeof(struct prism2_hostapd_param
),
1431 PRISM2_HOSTAPD_MAX_BUF_SIZE
);
1435 param
= (struct prism2_hostapd_param
*) kmalloc(p
->length
, GFP_KERNEL
);
1439 if (copy_from_user(param
, p
->pointer
, p
->length
)) {
1444 switch (param
->cmd
) {
1445 case PRISM2_HOSTAPD_FLUSH
:
1446 ret
= ieee80211_ioctl_flush(dev
, param
);
1448 case PRISM2_HOSTAPD_ADD_STA
:
1449 ret
= ieee80211_ioctl_add_sta(dev
, param
);
1451 case PRISM2_HOSTAPD_REMOVE_STA
:
1452 ret
= ieee80211_ioctl_remove_sta(dev
, param
);
1454 case PRISM2_HOSTAPD_GET_INFO_STA
:
1455 ret
= ieee80211_ioctl_get_info_sta(dev
, param
);
1457 case PRISM2_SET_ENCRYPTION
:
1458 ret
= ieee80211_ioctl_set_encryption(dev
, param
, p
->length
);
1460 case PRISM2_GET_ENCRYPTION
:
1461 ret
= ieee80211_ioctl_get_encryption(dev
, param
, p
->length
);
1463 case PRISM2_HOSTAPD_SET_FLAGS_STA
:
1464 ret
= ieee80211_ioctl_set_flags_sta(dev
, param
);
1466 case PRISM2_HOSTAPD_SET_BEACON
:
1467 ret
= ieee80211_ioctl_set_beacon(dev
, param
, p
->length
, 0);
1469 case PRISM2_HOSTAPD_GET_HW_FEATURES
:
1470 ret
= ieee80211_ioctl_get_hw_features(dev
, param
, p
->length
);
1472 case PRISM2_HOSTAPD_SCAN
:
1473 ret
= ieee80211_ioctl_scan(dev
, param
);
1475 #ifdef CONFIG_HOSTAPD_WPA_TESTING
1476 case PRISM2_HOSTAPD_WPA_TRIGGER
:
1477 ret
= ieee80211_ioctl_wpa_trigger(dev
, param
);
1479 #endif /* CONFIG_HOSTAPD_WPA_TESTING */
1480 case PRISM2_HOSTAPD_SET_RATE_SETS
:
1481 ret
= ieee80211_ioctl_set_rate_sets(dev
, param
, p
->length
);
1483 case PRISM2_HOSTAPD_ADD_IF
:
1484 ret
= ieee80211_ioctl_add_if(dev
, param
, p
->length
);
1486 case PRISM2_HOSTAPD_REMOVE_IF
:
1487 ret
= ieee80211_ioctl_remove_if(dev
, param
);
1489 case PRISM2_HOSTAPD_GET_DOT11COUNTERSTABLE
:
1490 ret
= ieee80211_ioctl_get_dot11counterstable(dev
, param
);
1492 case PRISM2_HOSTAPD_GET_LOAD_STATS
:
1493 ret
= ieee80211_ioctl_get_load_stats(dev
, param
);
1495 case PRISM2_HOSTAPD_SET_STA_VLAN
:
1496 ret
= ieee80211_ioctl_set_sta_vlan(dev
, param
);
1498 case PRISM2_HOSTAPD_SET_GENERIC_INFO_ELEM
:
1499 ret
= ieee80211_ioctl_set_generic_info_elem(dev
, param
,
1502 case PRISM2_HOSTAPD_SET_CHANNEL_FLAG
:
1503 ret
= ieee80211_ioctl_set_channel_flag(dev
, param
);
1505 case PRISM2_HOSTAPD_SET_REGULATORY_DOMAIN
:
1506 ret
= ieee80211_ioctl_set_regulatory_domain(dev
, param
);
1508 case PRISM2_HOSTAPD_SET_TX_QUEUE_PARAMS
:
1509 ret
= ieee80211_ioctl_set_tx_queue_params(dev
, param
);
1511 case PRISM2_HOSTAPD_GET_TX_STATS
:
1512 ret
= ieee80211_ioctl_get_tx_stats(dev
, param
);
1514 case PRISM2_HOSTAPD_UPDATE_IF
:
1515 ret
= ieee80211_ioctl_update_if(dev
, param
, p
->length
);
1517 case PRISM2_HOSTAPD_SCAN_REQ
:
1518 ret
= ieee80211_ioctl_scan_req(dev
, param
, p
->length
);
1520 case PRISM2_STA_GET_STATE
:
1521 ret
= ieee80211_ioctl_sta_get_state(dev
, param
);
1523 case PRISM2_HOSTAPD_MLME
:
1524 ret
= ieee80211_ioctl_mlme(dev
, param
);
1526 case PRISM2_HOSTAPD_FLUSH_IFS
:
1527 ret
= ieee80211_ioctl_flush_ifs(dev
, param
);
1529 case PRISM2_HOSTAPD_SET_RADAR_PARAMS
:
1530 ret
= ieee80211_ioctl_set_radar_params(dev
, param
);
1532 case PRISM2_HOSTAPD_SET_QUIET_PARAMS
:
1533 ret
= ieee80211_ioctl_set_quiet_params(dev
, param
);
1540 if (copy_to_user(p
->pointer
, param
, p
->length
))
1550 static int ieee80211_ioctl_giwname(struct net_device
*dev
,
1551 struct iw_request_info
*info
,
1552 char *name
, char *extra
)
1554 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1556 switch (local
->hw
.conf
.phymode
) {
1557 case MODE_IEEE80211A
:
1558 strcpy(name
, "IEEE 802.11a");
1560 case MODE_IEEE80211B
:
1561 strcpy(name
, "IEEE 802.11b");
1563 case MODE_IEEE80211G
:
1564 strcpy(name
, "IEEE 802.11g");
1566 case MODE_ATHEROS_TURBO
:
1567 strcpy(name
, "5GHz Turbo");
1570 strcpy(name
, "IEEE 802.11");
1578 static int ieee80211_ioctl_giwrange(struct net_device
*dev
,
1579 struct iw_request_info
*info
,
1580 struct iw_point
*data
, char *extra
)
1582 struct iw_range
*range
= (struct iw_range
*) extra
;
1584 data
->length
= sizeof(struct iw_range
);
1585 memset(range
, 0, sizeof(struct iw_range
));
1587 range
->we_version_compiled
= WIRELESS_EXT
;
1588 range
->we_version_source
= 14;
1589 range
->retry_capa
= IW_RETRY_LIMIT
;
1590 range
->retry_flags
= IW_RETRY_LIMIT
;
1591 range
->min_retry
= 0;
1592 range
->max_retry
= 255;
1594 range
->max_rts
= 2347;
1595 range
->min_frag
= 256;
1596 range
->max_frag
= 2346;
1598 range
->max_qual
.qual
= 100;
1599 range
->max_qual
.level
= 146; /* set floor at -110 dBm (146 - 256) */
1600 range
->max_qual
.noise
= 146;
1601 range
->max_qual
.updated
= IW_QUAL_ALL_UPDATED
;
1603 range
->avg_qual
.qual
= 50;
1604 range
->avg_qual
.level
= 0;
1605 range
->avg_qual
.noise
= 0;
1606 range
->avg_qual
.updated
= IW_QUAL_ALL_UPDATED
;
1612 struct ieee80211_channel_range
{
1615 unsigned char power_level
;
1616 unsigned char antenna_max
;
1619 static const struct ieee80211_channel_range ieee80211_fcc_channels
[] = {
1620 { 2412, 2462, 27, 6 } /* IEEE 802.11b/g, channels 1..11 */,
1621 { 5180, 5240, 17, 6 } /* IEEE 802.11a, channels 36..48 */,
1622 { 5260, 5320, 23, 6 } /* IEEE 802.11a, channels 52..64 */,
1623 { 5745, 5825, 30, 6 } /* IEEE 802.11a, channels 149..165, outdoor */,
1627 static const struct ieee80211_channel_range ieee80211_mkk_channels
[] = {
1628 { 2412, 2472, 20, 6 } /* IEEE 802.11b/g, channels 1..13 */,
1629 { 5170, 5240, 20, 6 } /* IEEE 802.11a, channels 34..48 */,
1630 { 5260, 5320, 20, 6 } /* IEEE 802.11a, channels 52..64 */,
1635 static const struct ieee80211_channel_range
*channel_range
=
1636 ieee80211_fcc_channels
;
1639 static void ieee80211_unmask_channel(struct net_device
*dev
, int mode
,
1640 struct ieee80211_channel
*chan
)
1646 if (ieee80211_regdom
== 64 &&
1647 (mode
== MODE_ATHEROS_TURBO
|| mode
== MODE_ATHEROS_TURBOG
)) {
1648 /* Do not allow Turbo modes in Japan. */
1652 for (i
= 0; channel_range
[i
].start_freq
; i
++) {
1653 const struct ieee80211_channel_range
*r
= &channel_range
[i
];
1654 if (r
->start_freq
<= chan
->freq
&& r
->end_freq
>= chan
->freq
) {
1655 if (ieee80211_regdom
== 64 && !ieee80211_japan_5ghz
&&
1656 chan
->freq
>= 5260 && chan
->freq
<= 5320) {
1658 * Skip new channels in Japan since the
1659 * firmware was not marked having been upgraded
1665 if (ieee80211_regdom
== 0x10 &&
1666 (chan
->freq
== 5190 || chan
->freq
== 5210 ||
1667 chan
->freq
== 5230)) {
1668 /* Skip MKK channels when in FCC domain. */
1672 chan
->flag
|= IEEE80211_CHAN_W_SCAN
|
1673 IEEE80211_CHAN_W_ACTIVE_SCAN
|
1674 IEEE80211_CHAN_W_IBSS
;
1675 chan
->power_level
= r
->power_level
;
1676 chan
->antenna_max
= r
->antenna_max
;
1678 if (ieee80211_regdom
== 64 &&
1679 (chan
->freq
== 5170 || chan
->freq
== 5190 ||
1680 chan
->freq
== 5210 || chan
->freq
== 5230)) {
1682 * New regulatory rules in Japan have backwards
1683 * compatibility with old channels in 5.15-5.25
1684 * GHz band, but the station is not allowed to
1685 * use active scan on these old channels.
1687 chan
->flag
&= ~IEEE80211_CHAN_W_ACTIVE_SCAN
;
1690 if (ieee80211_regdom
== 64 &&
1691 (chan
->freq
== 5260 || chan
->freq
== 5280 ||
1692 chan
->freq
== 5300 || chan
->freq
== 5320)) {
1694 * IBSS is not allowed on 5.25-5.35 GHz band
1695 * due to radar detection requirements.
1697 chan
->flag
&= ~IEEE80211_CHAN_W_IBSS
;
1706 static int ieee80211_unmask_channels(struct net_device
*dev
)
1708 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1711 for (m
= 0; m
< local
->hw
.num_modes
; m
++) {
1712 struct ieee80211_hw_modes
*mode
= &local
->hw
.modes
[m
];
1713 for (c
= 0; c
< mode
->num_channels
; c
++) {
1714 ieee80211_unmask_channel(dev
, mode
->mode
,
1715 &mode
->channels
[c
]);
1722 int ieee80211_init_client(struct net_device
*dev
)
1724 if (ieee80211_regdom
== 0x40)
1725 channel_range
= ieee80211_mkk_channels
;
1726 ieee80211_unmask_channels(dev
);
1731 static int ieee80211_ioctl_siwmode(struct net_device
*dev
,
1732 struct iw_request_info
*info
,
1733 __u32
*mode
, char *extra
)
1735 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1738 if (sdata
->type
== IEEE80211_IF_TYPE_VLAN
)
1740 if (netif_running(dev
))
1744 case IW_MODE_MASTER
:
1745 type
= IEEE80211_IF_TYPE_AP
;
1748 type
= IEEE80211_IF_TYPE_STA
;
1751 type
= IEEE80211_IF_TYPE_IBSS
;
1753 case IW_MODE_MONITOR
:
1754 type
= IEEE80211_IF_TYPE_MNTR
;
1756 case IW_MODE_REPEAT
:
1757 type
= IEEE80211_IF_TYPE_WDS
;
1763 if (type
!= sdata
->type
) {
1764 ieee80211_if_reinit(dev
);
1765 ieee80211_if_set_type(dev
, type
);
1771 static int ieee80211_ioctl_giwmode(struct net_device
*dev
,
1772 struct iw_request_info
*info
,
1773 __u32
*mode
, char *extra
)
1775 struct ieee80211_sub_if_data
*sdata
;
1777 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1778 switch (sdata
->type
) {
1779 case IEEE80211_IF_TYPE_AP
:
1780 *mode
= IW_MODE_MASTER
;
1782 case IEEE80211_IF_TYPE_STA
:
1783 *mode
= IW_MODE_INFRA
;
1785 case IEEE80211_IF_TYPE_IBSS
:
1786 *mode
= IW_MODE_ADHOC
;
1788 case IEEE80211_IF_TYPE_MNTR
:
1789 *mode
= IW_MODE_MONITOR
;
1791 case IEEE80211_IF_TYPE_WDS
:
1792 *mode
= IW_MODE_REPEAT
;
1794 case IEEE80211_IF_TYPE_VLAN
:
1795 *mode
= IW_MODE_SECOND
; /* FIXME */
1798 *mode
= IW_MODE_AUTO
;
1805 int ieee80211_ioctl_siwfreq(struct net_device
*dev
,
1806 struct iw_request_info
*info
,
1807 struct iw_freq
*freq
, char *extra
)
1809 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1810 int m
, c
, nfreq
, set
= 0;
1812 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
1816 int i
, div
= 1000000;
1817 for (i
= 0; i
< freq
->e
; i
++)
1820 nfreq
= freq
->m
/ div
;
1825 for (m
= 0; m
< local
->hw
.num_modes
; m
++) {
1826 struct ieee80211_hw_modes
*mode
= &local
->hw
.modes
[m
];
1827 for (c
= 0; c
< mode
->num_channels
; c
++) {
1828 struct ieee80211_channel
*chan
= &mode
->channels
[c
];
1829 if (chan
->flag
& IEEE80211_CHAN_W_SCAN
&&
1830 ((freq
->e
== 0 && chan
->chan
== freq
->m
) ||
1831 (freq
->e
> 0 && nfreq
== chan
->freq
)) &&
1832 (local
->enabled_modes
& (1 << mode
->mode
))) {
1833 /* Use next_mode as the mode preference to
1834 * resolve non-unique channel numbers. */
1835 if (set
&& mode
->mode
!= local
->next_mode
)
1838 local
->hw
.conf
.channel
= chan
->chan
;
1839 local
->hw
.conf
.channel_val
= chan
->val
;
1840 local
->hw
.conf
.power_level
= chan
->power_level
;
1841 local
->hw
.conf
.freq
= chan
->freq
;
1842 local
->hw
.conf
.phymode
= mode
->mode
;
1843 local
->hw
.conf
.antenna_max
= chan
->antenna_max
;
1850 local
->sta_scanning
= 0; /* Abort possible scan */
1851 return ieee80211_hw_config(local
);
1858 static int ieee80211_ioctl_giwfreq(struct net_device
*dev
,
1859 struct iw_request_info
*info
,
1860 struct iw_freq
*freq
, char *extra
)
1862 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1864 /* TODO: in station mode (Managed/Ad-hoc) might need to poll low-level
1865 * driver for the current channel with firmware-based management */
1867 freq
->m
= local
->hw
.conf
.freq
;
1874 static int ieee80211_ioctl_siwessid(struct net_device
*dev
,
1875 struct iw_request_info
*info
,
1876 struct iw_point
*data
, char *ssid
)
1878 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1879 struct ieee80211_sub_if_data
*sdata
;
1880 size_t len
= data
->length
;
1882 /* iwconfig uses nul termination in SSID.. */
1883 if (len
> 0 && ssid
[len
- 1] == '\0')
1886 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1887 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
1888 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
1889 if (local
->user_space_mlme
) {
1890 if (len
> IEEE80211_MAX_SSID_LEN
)
1892 memcpy(sdata
->u
.sta
.ssid
, ssid
, len
);
1893 sdata
->u
.sta
.ssid_len
= len
;
1896 return ieee80211_sta_set_ssid(dev
, ssid
, len
);
1899 if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
1900 memcpy(sdata
->u
.ap
.ssid
, ssid
, len
);
1901 memset(sdata
->u
.ap
.ssid
+ len
, 0,
1902 IEEE80211_MAX_SSID_LEN
- len
);
1903 sdata
->u
.ap
.ssid_len
= len
;
1904 return ieee80211_if_config(dev
);
1910 static int ieee80211_ioctl_giwessid(struct net_device
*dev
,
1911 struct iw_request_info
*info
,
1912 struct iw_point
*data
, char *ssid
)
1916 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
) {
1920 int res
= ieee80211_sta_get_ssid(dev
, ssid
, &len
);
1929 if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
1930 len
= sdata
->u
.ap
.ssid_len
;
1931 if (len
> IW_ESSID_MAX_SIZE
)
1932 len
= IW_ESSID_MAX_SIZE
;
1933 memcpy(ssid
, sdata
->u
.ap
.ssid
, len
);
1942 static int ieee80211_ioctl_siwap(struct net_device
*dev
,
1943 struct iw_request_info
*info
,
1944 struct sockaddr
*ap_addr
, char *extra
)
1946 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1947 struct ieee80211_sub_if_data
*sdata
;
1949 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1950 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
1951 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
1952 if (local
->user_space_mlme
) {
1953 memcpy(sdata
->u
.sta
.bssid
, (u8
*) &ap_addr
->sa_data
,
1957 return ieee80211_sta_set_bssid(dev
, (u8
*) &ap_addr
->sa_data
);
1958 } else if (sdata
->type
== IEEE80211_IF_TYPE_WDS
) {
1959 if (memcmp(sdata
->u
.wds
.remote_addr
, (u8
*) &ap_addr
->sa_data
,
1962 return ieee80211_if_update_wds(dev
, (u8
*) &ap_addr
->sa_data
);
1969 static int ieee80211_ioctl_giwap(struct net_device
*dev
,
1970 struct iw_request_info
*info
,
1971 struct sockaddr
*ap_addr
, char *extra
)
1973 struct ieee80211_sub_if_data
*sdata
;
1975 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1976 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
1977 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
1978 ap_addr
->sa_family
= ARPHRD_ETHER
;
1979 memcpy(&ap_addr
->sa_data
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
1981 } else if (sdata
->type
== IEEE80211_IF_TYPE_WDS
) {
1982 ap_addr
->sa_family
= ARPHRD_ETHER
;
1983 memcpy(&ap_addr
->sa_data
, sdata
->u
.wds
.remote_addr
, ETH_ALEN
);
1991 static int ieee80211_ioctl_siwscan(struct net_device
*dev
,
1992 struct iw_request_info
*info
,
1993 struct iw_point
*data
, char *extra
)
1995 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
1996 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1998 size_t ssid_len
= 0;
2000 if (!netif_running(dev
))
2003 if (local
->scan_flags
& IEEE80211_SCAN_MATCH_SSID
) {
2004 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
2005 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
2006 ssid
= sdata
->u
.sta
.ssid
;
2007 ssid_len
= sdata
->u
.sta
.ssid_len
;
2008 } else if (sdata
== IEEE80211_IF_TYPE_AP
) {
2009 ssid
= sdata
->u
.ap
.ssid
;
2010 ssid_len
= sdata
->u
.ap
.ssid_len
;
2014 return ieee80211_sta_req_scan(dev
, ssid
, ssid_len
);
2018 static int ieee80211_ioctl_giwscan(struct net_device
*dev
,
2019 struct iw_request_info
*info
,
2020 struct iw_point
*data
, char *extra
)
2023 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2024 if (local
->sta_scanning
)
2026 res
= ieee80211_sta_scan_results(dev
, extra
, data
->length
);
2036 static int ieee80211_ioctl_siwrts(struct net_device
*dev
,
2037 struct iw_request_info
*info
,
2038 struct iw_param
*rts
, char *extra
)
2040 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2043 local
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
2044 else if (rts
->value
< 0 || rts
->value
> IEEE80211_MAX_RTS_THRESHOLD
)
2047 local
->rts_threshold
= rts
->value
;
2049 /* If the wlan card performs RTS/CTS in hardware/firmware,
2050 * configure it here */
2052 if (local
->ops
->set_rts_threshold
)
2053 local
->ops
->set_rts_threshold(local_to_hw(local
),
2054 local
->rts_threshold
);
2059 static int ieee80211_ioctl_giwrts(struct net_device
*dev
,
2060 struct iw_request_info
*info
,
2061 struct iw_param
*rts
, char *extra
)
2063 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2065 rts
->value
= local
->rts_threshold
;
2066 rts
->disabled
= (rts
->value
>= IEEE80211_MAX_RTS_THRESHOLD
);
2073 static int ieee80211_ioctl_siwfrag(struct net_device
*dev
,
2074 struct iw_request_info
*info
,
2075 struct iw_param
*frag
, char *extra
)
2077 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2080 local
->fragmentation_threshold
= IEEE80211_MAX_FRAG_THRESHOLD
;
2081 else if (frag
->value
< 256 ||
2082 frag
->value
> IEEE80211_MAX_FRAG_THRESHOLD
)
2085 /* Fragment length must be even, so strip LSB. */
2086 local
->fragmentation_threshold
= frag
->value
& ~0x1;
2089 /* If the wlan card performs fragmentation in hardware/firmware,
2090 * configure it here */
2092 if (local
->ops
->set_frag_threshold
)
2093 local
->ops
->set_frag_threshold(
2095 local
->fragmentation_threshold
);
2100 static int ieee80211_ioctl_giwfrag(struct net_device
*dev
,
2101 struct iw_request_info
*info
,
2102 struct iw_param
*frag
, char *extra
)
2104 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2106 frag
->value
= local
->fragmentation_threshold
;
2107 frag
->disabled
= (frag
->value
>= IEEE80211_MAX_RTS_THRESHOLD
);
2114 static int ieee80211_ioctl_siwretry(struct net_device
*dev
,
2115 struct iw_request_info
*info
,
2116 struct iw_param
*retry
, char *extra
)
2118 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2120 if (retry
->disabled
||
2121 (retry
->flags
& IW_RETRY_TYPE
) != IW_RETRY_LIMIT
)
2124 if (retry
->flags
& IW_RETRY_MAX
)
2125 local
->long_retry_limit
= retry
->value
;
2126 else if (retry
->flags
& IW_RETRY_MIN
)
2127 local
->short_retry_limit
= retry
->value
;
2129 local
->long_retry_limit
= retry
->value
;
2130 local
->short_retry_limit
= retry
->value
;
2133 if (local
->ops
->set_retry_limit
) {
2134 return local
->ops
->set_retry_limit(
2136 local
->short_retry_limit
,
2137 local
->long_retry_limit
);
2144 static int ieee80211_ioctl_giwretry(struct net_device
*dev
,
2145 struct iw_request_info
*info
,
2146 struct iw_param
*retry
, char *extra
)
2148 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2150 retry
->disabled
= 0;
2151 if ((retry
->flags
& IW_RETRY_TYPE
) != IW_RETRY_LIMIT
)
2153 if (retry
->flags
& IW_RETRY_MAX
) {
2154 retry
->flags
= IW_RETRY_LIMIT
| IW_RETRY_MAX
;
2155 retry
->value
= local
->long_retry_limit
;
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
;
2167 static void ieee80211_ioctl_unmask_channels(struct ieee80211_local
*local
)
2171 for (m
= 0; m
< local
->hw
.num_modes
; m
++) {
2172 struct ieee80211_hw_modes
*mode
= &local
->hw
.modes
[m
];
2173 for (c
= 0; c
< mode
->num_channels
; c
++) {
2174 struct ieee80211_channel
*chan
= &mode
->channels
[c
];
2175 chan
->flag
|= IEEE80211_CHAN_W_SCAN
;
2181 static int ieee80211_ioctl_test_mode(struct net_device
*dev
, int mode
)
2183 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2184 int ret
= -EOPNOTSUPP
;
2186 if (mode
== IEEE80211_TEST_UNMASK_CHANNELS
) {
2187 ieee80211_ioctl_unmask_channels(local
);
2191 if (local
->ops
->test_mode
)
2192 ret
= local
->ops
->test_mode(local_to_hw(local
), mode
);
2198 static int ieee80211_ioctl_clear_keys(struct net_device
*dev
)
2200 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2201 struct ieee80211_key_conf key
;
2204 struct ieee80211_key_conf
*keyconf
;
2205 struct ieee80211_sub_if_data
*sdata
;
2206 struct sta_info
*sta
;
2208 memset(addr
, 0xff, ETH_ALEN
);
2209 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
2210 for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
2212 if (sdata
->keys
[i
] &&
2213 !sdata
->keys
[i
]->force_sw_encrypt
&&
2214 local
->ops
->set_key
&&
2215 (keyconf
= ieee80211_key_data2conf(local
,
2217 local
->ops
->set_key(local_to_hw(local
),
2221 ieee80211_key_free(sdata
->keys
[i
]);
2222 sdata
->keys
[i
] = NULL
;
2224 sdata
->default_key
= NULL
;
2227 spin_lock_bh(&local
->sta_lock
);
2228 list_for_each_entry(sta
, &local
->sta_list
, list
) {
2230 if (sta
->key
&& !sta
->key
->force_sw_encrypt
&&
2231 local
->ops
->set_key
&&
2232 (keyconf
= ieee80211_key_data2conf(local
, sta
->key
)))
2233 local
->ops
->set_key(local_to_hw(local
), DISABLE_KEY
,
2234 sta
->addr
, keyconf
, sta
->aid
);
2236 ieee80211_key_free(sta
->key
);
2239 spin_unlock_bh(&local
->sta_lock
);
2241 memset(&key
, 0, sizeof(key
));
2242 if (local
->ops
->set_key
&&
2243 local
->ops
->set_key(local_to_hw(local
), REMOVE_ALL_KEYS
,
2245 printk(KERN_DEBUG
"%s: failed to remove hwaccel keys\n",
2253 ieee80211_ioctl_force_unicast_rate(struct net_device
*dev
,
2254 struct ieee80211_sub_if_data
*sdata
,
2257 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2260 if (sdata
->type
!= IEEE80211_IF_TYPE_AP
)
2264 sdata
->u
.ap
.force_unicast_rateidx
= -1;
2268 for (i
= 0; i
< local
->num_curr_rates
; i
++) {
2269 if (local
->curr_rates
[i
].rate
== rate
) {
2270 sdata
->u
.ap
.force_unicast_rateidx
= i
;
2279 ieee80211_ioctl_max_ratectrl_rate(struct net_device
*dev
,
2280 struct ieee80211_sub_if_data
*sdata
,
2283 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2286 if (sdata
->type
!= IEEE80211_IF_TYPE_AP
)
2290 sdata
->u
.ap
.max_ratectrl_rateidx
= -1;
2294 for (i
= 0; i
< local
->num_curr_rates
; i
++) {
2295 if (local
->curr_rates
[i
].rate
== rate
) {
2296 sdata
->u
.ap
.max_ratectrl_rateidx
= i
;
2304 static void ieee80211_key_enable_hwaccel(struct ieee80211_local
*local
,
2305 struct ieee80211_key
*key
)
2307 struct ieee80211_key_conf
*keyconf
;
2310 if (!key
|| key
->alg
!= ALG_WEP
|| !key
->force_sw_encrypt
||
2311 (local
->hw
.flags
& IEEE80211_HW_DEVICE_HIDES_WEP
))
2314 memset(addr
, 0xff, ETH_ALEN
);
2315 keyconf
= ieee80211_key_data2conf(local
, key
);
2316 if (keyconf
&& local
->ops
->set_key
&&
2317 local
->ops
->set_key(local_to_hw(local
),
2318 SET_KEY
, addr
, keyconf
, 0) == 0) {
2319 key
->force_sw_encrypt
=
2320 !!(keyconf
->flags
& IEEE80211_KEY_FORCE_SW_ENCRYPT
);
2321 key
->hw_key_idx
= keyconf
->hw_key_idx
;
2327 static void ieee80211_key_disable_hwaccel(struct ieee80211_local
*local
,
2328 struct ieee80211_key
*key
)
2330 struct ieee80211_key_conf
*keyconf
;
2333 if (!key
|| key
->alg
!= ALG_WEP
|| key
->force_sw_encrypt
||
2334 (local
->hw
.flags
& IEEE80211_HW_DEVICE_HIDES_WEP
))
2337 memset(addr
, 0xff, ETH_ALEN
);
2338 keyconf
= ieee80211_key_data2conf(local
, key
);
2339 if (keyconf
&& local
->ops
->set_key
)
2340 local
->ops
->set_key(local_to_hw(local
), DISABLE_KEY
,
2343 key
->force_sw_encrypt
= 1;
2347 static int ieee80211_ioctl_default_wep_only(struct ieee80211_local
*local
,
2351 struct ieee80211_sub_if_data
*sdata
;
2353 local
->default_wep_only
= value
;
2354 list_for_each_entry(sdata
, &local
->sub_if_list
, list
)
2355 for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++)
2357 ieee80211_key_enable_hwaccel(local
,
2360 ieee80211_key_disable_hwaccel(local
,
2367 static int ieee80211_ioctl_prism2_param(struct net_device
*dev
,
2368 struct iw_request_info
*info
,
2369 void *wrqu
, char *extra
)
2371 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2372 struct ieee80211_sub_if_data
*sdata
;
2373 int *i
= (int *) extra
;
2375 int value
= *(i
+ 1);
2378 if (!capable(CAP_NET_ADMIN
))
2381 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2384 case PRISM2_PARAM_HOST_ENCRYPT
:
2385 case PRISM2_PARAM_HOST_DECRYPT
:
2386 /* TODO: implement these; return success now to prevent
2387 * hostapd from aborting */
2390 case PRISM2_PARAM_BEACON_INT
:
2391 local
->hw
.conf
.beacon_int
= value
;
2392 if (ieee80211_hw_config(local
))
2396 case PRISM2_PARAM_AP_BRIDGE_PACKETS
:
2397 local
->bridge_packets
= value
;
2400 case PRISM2_PARAM_AP_AUTH_ALGS
:
2401 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
2402 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
2403 sdata
->u
.sta
.auth_algs
= value
;
2408 case PRISM2_PARAM_DTIM_PERIOD
:
2411 else if (sdata
->type
!= IEEE80211_IF_TYPE_AP
)
2414 sdata
->u
.ap
.dtim_period
= value
;
2417 case PRISM2_PARAM_IEEE_802_1X
:
2418 sdata
->ieee802_1x
= value
;
2419 if (local
->ops
->set_ieee8021x
&&
2420 local
->ops
->set_ieee8021x(local_to_hw(local
), value
))
2421 printk(KERN_DEBUG
"%s: failed to set IEEE 802.1X (%d) "
2422 "for low-level driver\n", dev
->name
, value
);
2425 case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES
:
2426 local
->cts_protect_erp_frames
= value
;
2429 case PRISM2_PARAM_DROP_UNENCRYPTED
:
2430 sdata
->drop_unencrypted
= value
;
2433 case PRISM2_PARAM_PREAMBLE
:
2434 local
->short_preamble
= value
;
2437 case PRISM2_PARAM_STAT_TIME
:
2438 if (!local
->stat_time
&& value
) {
2439 local
->stat_timer
.expires
= jiffies
+ HZ
* value
/ 100;
2440 add_timer(&local
->stat_timer
);
2441 } else if (local
->stat_time
&& !value
) {
2442 del_timer_sync(&local
->stat_timer
);
2444 local
->stat_time
= value
;
2446 case PRISM2_PARAM_SHORT_SLOT_TIME
:
2448 local
->hw
.conf
.flags
|= IEEE80211_CONF_SHORT_SLOT_TIME
;
2450 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_SHORT_SLOT_TIME
;
2451 if (ieee80211_hw_config(local
))
2455 case PRISM2_PARAM_PRIVACY_INVOKED
:
2456 if (local
->ops
->set_privacy_invoked
)
2457 ret
= local
->ops
->set_privacy_invoked(
2458 local_to_hw(local
), value
);
2461 case PRISM2_PARAM_TEST_MODE
:
2462 ret
= ieee80211_ioctl_test_mode(dev
, value
);
2465 case PRISM2_PARAM_NEXT_MODE
:
2466 local
->next_mode
= value
;
2469 case PRISM2_PARAM_CLEAR_KEYS
:
2470 ret
= ieee80211_ioctl_clear_keys(dev
);
2473 case PRISM2_PARAM_RADIO_ENABLED
:
2474 ret
= ieee80211_ioctl_set_radio_enabled(dev
, value
);
2477 case PRISM2_PARAM_ANTENNA_SEL
:
2478 local
->hw
.conf
.antenna_sel
= value
;
2479 if (ieee80211_hw_config(local
))
2483 case PRISM2_PARAM_ANTENNA_MODE
:
2484 local
->hw
.conf
.antenna_mode
= value
;
2485 if (ieee80211_hw_config(local
))
2489 case PRISM2_PARAM_BROADCAST_SSID
:
2490 if ((value
< 0) || (value
> 1))
2493 local
->hw
.conf
.flags
|= IEEE80211_CONF_SSID_HIDDEN
;
2495 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_SSID_HIDDEN
;
2498 case PRISM2_PARAM_STA_ANTENNA_SEL
:
2499 local
->sta_antenna_sel
= value
;
2502 case PRISM2_PARAM_FORCE_UNICAST_RATE
:
2503 ret
= ieee80211_ioctl_force_unicast_rate(dev
, sdata
, value
);
2506 case PRISM2_PARAM_MAX_RATECTRL_RATE
:
2507 ret
= ieee80211_ioctl_max_ratectrl_rate(dev
, sdata
, value
);
2510 case PRISM2_PARAM_RATE_CTRL_NUM_UP
:
2511 local
->rate_ctrl_num_up
= value
;
2514 case PRISM2_PARAM_RATE_CTRL_NUM_DOWN
:
2515 local
->rate_ctrl_num_down
= value
;
2518 case PRISM2_PARAM_TX_POWER_REDUCTION
:
2522 local
->hw
.conf
.tx_power_reduction
= value
;
2525 case PRISM2_PARAM_EAPOL
:
2526 sdata
->eapol
= value
;
2529 case PRISM2_PARAM_KEY_TX_RX_THRESHOLD
:
2530 local
->key_tx_rx_threshold
= value
;
2533 case PRISM2_PARAM_KEY_INDEX
:
2534 if (value
< 0 || value
>= NUM_DEFAULT_KEYS
)
2536 else if (!sdata
->keys
[value
])
2539 sdata
->default_key
= sdata
->keys
[value
];
2542 case PRISM2_PARAM_DEFAULT_WEP_ONLY
:
2543 ret
= ieee80211_ioctl_default_wep_only(local
, value
);
2546 case PRISM2_PARAM_WIFI_WME_NOACK_TEST
:
2547 local
->wifi_wme_noack_test
= value
;
2550 case PRISM2_PARAM_ALLOW_BROADCAST_ALWAYS
:
2551 local
->allow_broadcast_always
= value
;
2554 case PRISM2_PARAM_SCAN_FLAGS
:
2555 local
->scan_flags
= value
;
2558 case PRISM2_PARAM_MIXED_CELL
:
2559 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
2560 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
2563 sdata
->u
.sta
.mixed_cell
= !!value
;
2566 case PRISM2_PARAM_KEY_MGMT
:
2567 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
2570 sdata
->u
.sta
.key_mgmt
= value
;
2573 case PRISM2_PARAM_HW_MODES
:
2574 local
->enabled_modes
= value
;
2577 case PRISM2_PARAM_CREATE_IBSS
:
2578 if (sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
2581 sdata
->u
.sta
.create_ibss
= !!value
;
2583 case PRISM2_PARAM_WMM_ENABLED
:
2584 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
2585 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
2588 sdata
->u
.sta
.wmm_enabled
= !!value
;
2590 case PRISM2_PARAM_RADAR_DETECT
:
2591 local
->hw
.conf
.radar_detect
= value
;
2593 case PRISM2_PARAM_SPECTRUM_MGMT
:
2594 local
->hw
.conf
.spect_mgmt
= value
;
2596 case PRISM2_PARAM_MGMT_IF
:
2599 ret
= ieee80211_if_add_mgmt(local
);
2600 } else if (value
== 0) {
2602 ieee80211_if_del_mgmt(local
);
2606 case PRISM2_PARAM_USER_SPACE_MLME
:
2607 local
->user_space_mlme
= value
;
2618 static int ieee80211_ioctl_get_prism2_param(struct net_device
*dev
,
2619 struct iw_request_info
*info
,
2620 void *wrqu
, char *extra
)
2622 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2623 struct ieee80211_sub_if_data
*sdata
;
2624 int *param
= (int *) extra
;
2627 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2630 case PRISM2_PARAM_BEACON_INT
:
2631 *param
= local
->hw
.conf
.beacon_int
;
2634 case PRISM2_PARAM_AP_BRIDGE_PACKETS
:
2635 *param
= local
->bridge_packets
;
2638 case PRISM2_PARAM_AP_AUTH_ALGS
:
2639 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
2640 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
2641 *param
= sdata
->u
.sta
.auth_algs
;
2646 case PRISM2_PARAM_DTIM_PERIOD
:
2647 if (sdata
->type
!= IEEE80211_IF_TYPE_AP
)
2650 *param
= sdata
->u
.ap
.dtim_period
;
2653 case PRISM2_PARAM_IEEE_802_1X
:
2654 *param
= sdata
->ieee802_1x
;
2657 case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES
:
2658 *param
= local
->cts_protect_erp_frames
;
2661 case PRISM2_PARAM_DROP_UNENCRYPTED
:
2662 *param
= sdata
->drop_unencrypted
;
2665 case PRISM2_PARAM_PREAMBLE
:
2666 *param
= local
->short_preamble
;
2669 case PRISM2_PARAM_STAT_TIME
:
2670 *param
= local
->stat_time
;
2672 case PRISM2_PARAM_SHORT_SLOT_TIME
:
2673 *param
= !!(local
->hw
.conf
.flags
& IEEE80211_CONF_SHORT_SLOT_TIME
);
2676 case PRISM2_PARAM_NEXT_MODE
:
2677 *param
= local
->next_mode
;
2680 case PRISM2_PARAM_ANTENNA_SEL
:
2681 *param
= local
->hw
.conf
.antenna_sel
;
2684 case PRISM2_PARAM_ANTENNA_MODE
:
2685 *param
= local
->hw
.conf
.antenna_mode
;
2688 case PRISM2_PARAM_BROADCAST_SSID
:
2689 *param
= !!(local
->hw
.conf
.flags
& IEEE80211_CONF_SSID_HIDDEN
);
2692 case PRISM2_PARAM_STA_ANTENNA_SEL
:
2693 *param
= local
->sta_antenna_sel
;
2696 case PRISM2_PARAM_RATE_CTRL_NUM_UP
:
2697 *param
= local
->rate_ctrl_num_up
;
2700 case PRISM2_PARAM_RATE_CTRL_NUM_DOWN
:
2701 *param
= local
->rate_ctrl_num_down
;
2704 case PRISM2_PARAM_TX_POWER_REDUCTION
:
2705 *param
= local
->hw
.conf
.tx_power_reduction
;
2708 case PRISM2_PARAM_EAPOL
:
2709 *param
= sdata
->eapol
;
2712 case PRISM2_PARAM_KEY_TX_RX_THRESHOLD
:
2713 *param
= local
->key_tx_rx_threshold
;
2716 case PRISM2_PARAM_KEY_INDEX
:
2717 if (!sdata
->default_key
)
2719 else if (sdata
->default_key
== sdata
->keys
[0])
2721 else if (sdata
->default_key
== sdata
->keys
[1])
2723 else if (sdata
->default_key
== sdata
->keys
[2])
2725 else if (sdata
->default_key
== sdata
->keys
[3])
2731 case PRISM2_PARAM_DEFAULT_WEP_ONLY
:
2732 *param
= local
->default_wep_only
;
2735 case PRISM2_PARAM_WIFI_WME_NOACK_TEST
:
2736 *param
= local
->wifi_wme_noack_test
;
2739 case PRISM2_PARAM_ALLOW_BROADCAST_ALWAYS
:
2740 *param
= local
->allow_broadcast_always
;
2743 case PRISM2_PARAM_SCAN_FLAGS
:
2744 *param
= local
->scan_flags
;
2747 case PRISM2_PARAM_HW_MODES
:
2748 *param
= local
->enabled_modes
;
2751 case PRISM2_PARAM_CREATE_IBSS
:
2752 if (sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
2755 *param
= !!sdata
->u
.sta
.create_ibss
;
2758 case PRISM2_PARAM_MIXED_CELL
:
2759 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
2760 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
2763 *param
= !!sdata
->u
.sta
.mixed_cell
;
2766 case PRISM2_PARAM_KEY_MGMT
:
2767 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
2770 *param
= sdata
->u
.sta
.key_mgmt
;
2772 case PRISM2_PARAM_WMM_ENABLED
:
2773 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
2774 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
2777 *param
= !!sdata
->u
.sta
.wmm_enabled
;
2779 case PRISM2_PARAM_MGMT_IF
:
2781 *param
= local
->apdev
->ifindex
;
2785 case PRISM2_PARAM_USER_SPACE_MLME
:
2786 *param
= local
->user_space_mlme
;
2798 static int ieee80211_ioctl_test_param(struct net_device
*dev
,
2799 struct iw_request_info
*info
,
2800 void *wrqu
, char *extra
)
2802 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2803 int *i
= (int *) extra
;
2805 int value
= *(i
+ 1);
2807 if (!capable(CAP_NET_ADMIN
))
2810 if (local
->ops
->test_param
)
2811 return local
->ops
->test_param(local_to_hw(local
),
2818 static int ieee80211_ioctl_siwmlme(struct net_device
*dev
,
2819 struct iw_request_info
*info
,
2820 struct iw_point
*data
, char *extra
)
2822 struct ieee80211_sub_if_data
*sdata
;
2823 struct iw_mlme
*mlme
= (struct iw_mlme
*) extra
;
2825 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2826 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
&&
2827 sdata
->type
!= IEEE80211_IF_TYPE_IBSS
)
2830 switch (mlme
->cmd
) {
2831 case IW_MLME_DEAUTH
:
2832 /* TODO: mlme->addr.sa_data */
2833 return ieee80211_sta_deauthenticate(dev
, mlme
->reason_code
);
2834 case IW_MLME_DISASSOC
:
2835 /* TODO: mlme->addr.sa_data */
2836 return ieee80211_sta_disassociate(dev
, mlme
->reason_code
);
2843 static int ieee80211_ioctl_siwencode(struct net_device
*dev
,
2844 struct iw_request_info
*info
,
2845 struct iw_point
*erq
, char *keybuf
)
2847 struct ieee80211_sub_if_data
*sdata
;
2848 int idx
, i
, alg
= ALG_WEP
;
2849 u8 bcaddr
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2851 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2853 idx
= erq
->flags
& IW_ENCODE_INDEX
;
2854 if (idx
< 1 || idx
> 4) {
2856 if (!sdata
->default_key
)
2858 else for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
2859 if (sdata
->default_key
== sdata
->keys
[i
]) {
2869 if (erq
->flags
& IW_ENCODE_DISABLED
)
2871 else if (erq
->length
== 0) {
2872 /* No key data - just set the default TX key index */
2873 if (sdata
->default_key
!= sdata
->keys
[idx
]) {
2874 if (sdata
->default_key
)
2875 ieee80211_key_sysfs_remove_default(sdata
);
2876 sdata
->default_key
= sdata
->keys
[idx
];
2877 if (sdata
->default_key
)
2878 ieee80211_key_sysfs_add_default(sdata
);
2883 return ieee80211_set_encryption(
2886 !sdata
->default_key
,
2887 NULL
, keybuf
, erq
->length
);
2891 static int ieee80211_ioctl_giwencode(struct net_device
*dev
,
2892 struct iw_request_info
*info
,
2893 struct iw_point
*erq
, char *key
)
2895 struct ieee80211_sub_if_data
*sdata
;
2898 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2900 idx
= erq
->flags
& IW_ENCODE_INDEX
;
2901 if (idx
< 1 || idx
> 4) {
2903 if (!sdata
->default_key
)
2905 else for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
2906 if (sdata
->default_key
== sdata
->keys
[i
]) {
2916 erq
->flags
= idx
+ 1;
2918 if (!sdata
->keys
[idx
]) {
2920 erq
->flags
|= IW_ENCODE_DISABLED
;
2924 memcpy(key
, sdata
->keys
[idx
]->key
,
2925 min((int)erq
->length
, sdata
->keys
[idx
]->keylen
));
2926 erq
->length
= sdata
->keys
[idx
]->keylen
;
2927 erq
->flags
|= IW_ENCODE_ENABLED
;
2933 static int ieee80211_ioctl_siwgenie(struct net_device
*dev
,
2934 struct iw_request_info
*info
,
2935 struct iw_point
*data
, char *extra
)
2937 return ieee80211_set_gen_ie(dev
, extra
, data
->length
);
2941 static int ieee80211_ioctl_siwauth(struct net_device
*dev
,
2942 struct iw_request_info
*info
,
2943 struct iw_param
*data
, char *extra
)
2945 struct ieee80211_local
*local
= dev
->ieee80211_ptr
;
2946 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2949 switch (data
->flags
& IW_AUTH_INDEX
) {
2950 case IW_AUTH_WPA_VERSION
:
2951 case IW_AUTH_CIPHER_PAIRWISE
:
2952 case IW_AUTH_CIPHER_GROUP
:
2953 case IW_AUTH_WPA_ENABLED
:
2954 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
2956 case IW_AUTH_KEY_MGMT
:
2957 if (sdata
->type
!= IEEE80211_IF_TYPE_STA
)
2961 * TODO: sdata->u.sta.key_mgmt does not match with WE18
2962 * value completely; could consider modifying this to
2963 * be closer to WE18. For now, this value is not really
2964 * used for anything else than Privacy matching, so the
2965 * current code here should be more or less OK.
2967 if (data
->value
& IW_AUTH_KEY_MGMT_802_1X
) {
2968 sdata
->u
.sta
.key_mgmt
=
2969 IEEE80211_KEY_MGMT_WPA_EAP
;
2970 } else if (data
->value
& IW_AUTH_KEY_MGMT_PSK
) {
2971 sdata
->u
.sta
.key_mgmt
=
2972 IEEE80211_KEY_MGMT_WPA_PSK
;
2974 sdata
->u
.sta
.key_mgmt
=
2975 IEEE80211_KEY_MGMT_NONE
;
2979 case IW_AUTH_80211_AUTH_ALG
:
2980 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
2981 sdata
->type
== IEEE80211_IF_TYPE_IBSS
)
2982 sdata
->u
.sta
.auth_algs
= data
->value
;
2986 case IW_AUTH_PRIVACY_INVOKED
:
2987 if (local
->ops
->set_privacy_invoked
)
2988 ret
= local
->ops
->set_privacy_invoked(
2989 local_to_hw(local
), data
->value
);
2998 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
2999 static struct iw_statistics
*ieee80211_get_wireless_stats(struct net_device
*net_dev
)
3001 struct ieee80211_local
*local
= net_dev
->ieee80211_ptr
;
3002 struct iw_statistics
* wstats
= &local
->wstats
;
3003 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(net_dev
);
3004 struct sta_info
*sta
;
3005 static int tmp_level
= 0;
3006 static int tmp_qual
= 0;
3008 sta
= sta_info_get(local
, sdata
->u
.sta
.bssid
);
3010 wstats
->discard
.fragment
= 0;
3011 wstats
->discard
.misc
= 0;
3012 wstats
->qual
.qual
= 0;
3013 wstats
->qual
.level
= 0;
3014 wstats
->qual
.noise
= 0;
3015 wstats
->qual
.updated
= IW_QUAL_ALL_INVALID
;
3017 if (!tmp_level
) { /* get initial values */
3018 tmp_level
= sta
->last_signal
;
3019 tmp_qual
= sta
->last_rssi
;
3020 } else { /* smooth results */
3021 tmp_level
= (15 * tmp_level
+ sta
->last_signal
)/16;
3022 tmp_qual
= (15 * tmp_qual
+ sta
->last_rssi
)/16;
3024 wstats
->qual
.level
= tmp_level
;
3025 wstats
->qual
.qual
= 100*tmp_qual
/local
->hw
.maxssi
;
3026 wstats
->qual
.noise
= sta
->last_noise
;
3027 wstats
->qual
.updated
= IW_QUAL_ALL_UPDATED
| IW_QUAL_DBM
;
3032 static int ieee80211_ioctl_giwauth(struct net_device
*dev
,
3033 struct iw_request_info
*info
,
3034 struct iw_param
*data
, char *extra
)
3036 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3039 switch (data
->flags
& IW_AUTH_INDEX
) {
3040 case IW_AUTH_80211_AUTH_ALG
:
3041 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
3042 sdata
->type
== IEEE80211_IF_TYPE_IBSS
)
3043 data
->value
= sdata
->u
.sta
.auth_algs
;
3055 static int ieee80211_ioctl_siwencodeext(struct net_device
*dev
,
3056 struct iw_request_info
*info
,
3057 struct iw_point
*erq
, char *extra
)
3059 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3060 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*) extra
;
3064 case IW_ENCODE_ALG_NONE
:
3067 case IW_ENCODE_ALG_WEP
:
3070 case IW_ENCODE_ALG_TKIP
:
3073 case IW_ENCODE_ALG_CCMP
:
3080 if (erq
->flags
& IW_ENCODE_DISABLED
)
3083 idx
= erq
->flags
& IW_ENCODE_INDEX
;
3084 if (idx
< 1 || idx
> 4) {
3086 if (!sdata
->default_key
)
3088 else for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
3089 if (sdata
->default_key
== sdata
->keys
[i
]) {
3099 return ieee80211_set_encryption(dev
, ext
->addr
.sa_data
, idx
, alg
,
3101 IW_ENCODE_EXT_SET_TX_KEY
,
3102 NULL
, ext
->key
, ext
->key_len
);
3106 static const struct iw_priv_args ieee80211_ioctl_priv
[] = {
3107 { PRISM2_IOCTL_PRISM2_PARAM
,
3108 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 2, 0, "param" },
3109 { PRISM2_IOCTL_GET_PRISM2_PARAM
,
3110 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
3111 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1, "get_param" },
3112 { PRISM2_IOCTL_TEST_PARAM
,
3113 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 2, 0, "test_param" },
3117 int ieee80211_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
3119 struct iwreq
*wrq
= (struct iwreq
*) rq
;
3123 /* Private ioctls (iwpriv) that have not yet been converted
3124 * into new wireless extensions API */
3125 case PRISM2_IOCTL_TEST_PARAM
:
3126 ret
= ieee80211_ioctl_test_param(dev
, NULL
, &wrq
->u
,
3129 case PRISM2_IOCTL_HOSTAPD
:
3130 if (!capable(CAP_NET_ADMIN
)) ret
= -EPERM
;
3131 else ret
= ieee80211_ioctl_priv_hostapd(dev
, &wrq
->u
.data
);
3142 /* Structures to export the Wireless Handlers */
3144 static const iw_handler ieee80211_handler
[] =
3146 (iw_handler
) NULL
, /* SIOCSIWCOMMIT */
3147 (iw_handler
) ieee80211_ioctl_giwname
, /* SIOCGIWNAME */
3148 (iw_handler
) NULL
, /* SIOCSIWNWID */
3149 (iw_handler
) NULL
, /* SIOCGIWNWID */
3150 (iw_handler
) ieee80211_ioctl_siwfreq
, /* SIOCSIWFREQ */
3151 (iw_handler
) ieee80211_ioctl_giwfreq
, /* SIOCGIWFREQ */
3152 (iw_handler
) ieee80211_ioctl_siwmode
, /* SIOCSIWMODE */
3153 (iw_handler
) ieee80211_ioctl_giwmode
, /* SIOCGIWMODE */
3154 (iw_handler
) NULL
, /* SIOCSIWSENS */
3155 (iw_handler
) NULL
, /* SIOCGIWSENS */
3156 (iw_handler
) NULL
/* not used */, /* SIOCSIWRANGE */
3157 (iw_handler
) ieee80211_ioctl_giwrange
, /* SIOCGIWRANGE */
3158 (iw_handler
) NULL
/* not used */, /* SIOCSIWPRIV */
3159 (iw_handler
) NULL
/* kernel code */, /* SIOCGIWPRIV */
3160 (iw_handler
) NULL
/* not used */, /* SIOCSIWSTATS */
3161 (iw_handler
) NULL
/* kernel code */, /* SIOCGIWSTATS */
3162 iw_handler_set_spy
, /* SIOCSIWSPY */
3163 iw_handler_get_spy
, /* SIOCGIWSPY */
3164 iw_handler_set_thrspy
, /* SIOCSIWTHRSPY */
3165 iw_handler_get_thrspy
, /* SIOCGIWTHRSPY */
3166 (iw_handler
) ieee80211_ioctl_siwap
, /* SIOCSIWAP */
3167 (iw_handler
) ieee80211_ioctl_giwap
, /* SIOCGIWAP */
3168 (iw_handler
) ieee80211_ioctl_siwmlme
, /* SIOCSIWMLME */
3169 (iw_handler
) NULL
, /* SIOCGIWAPLIST */
3170 (iw_handler
) ieee80211_ioctl_siwscan
, /* SIOCSIWSCAN */
3171 (iw_handler
) ieee80211_ioctl_giwscan
, /* SIOCGIWSCAN */
3172 (iw_handler
) ieee80211_ioctl_siwessid
, /* SIOCSIWESSID */
3173 (iw_handler
) ieee80211_ioctl_giwessid
, /* SIOCGIWESSID */
3174 (iw_handler
) NULL
, /* SIOCSIWNICKN */
3175 (iw_handler
) NULL
, /* SIOCGIWNICKN */
3176 (iw_handler
) NULL
, /* -- hole -- */
3177 (iw_handler
) NULL
, /* -- hole -- */
3178 (iw_handler
) NULL
, /* SIOCSIWRATE */
3179 (iw_handler
) NULL
, /* SIOCGIWRATE */
3180 (iw_handler
) ieee80211_ioctl_siwrts
, /* SIOCSIWRTS */
3181 (iw_handler
) ieee80211_ioctl_giwrts
, /* SIOCGIWRTS */
3182 (iw_handler
) ieee80211_ioctl_siwfrag
, /* SIOCSIWFRAG */
3183 (iw_handler
) ieee80211_ioctl_giwfrag
, /* SIOCGIWFRAG */
3184 (iw_handler
) NULL
, /* SIOCSIWTXPOW */
3185 (iw_handler
) NULL
, /* SIOCGIWTXPOW */
3186 (iw_handler
) ieee80211_ioctl_siwretry
, /* SIOCSIWRETRY */
3187 (iw_handler
) ieee80211_ioctl_giwretry
, /* SIOCGIWRETRY */
3188 (iw_handler
) ieee80211_ioctl_siwencode
, /* SIOCSIWENCODE */
3189 (iw_handler
) ieee80211_ioctl_giwencode
, /* SIOCGIWENCODE */
3190 (iw_handler
) NULL
, /* SIOCSIWPOWER */
3191 (iw_handler
) NULL
, /* SIOCGIWPOWER */
3192 (iw_handler
) NULL
, /* -- hole -- */
3193 (iw_handler
) NULL
, /* -- hole -- */
3194 (iw_handler
) ieee80211_ioctl_siwgenie
, /* SIOCSIWGENIE */
3195 (iw_handler
) NULL
, /* SIOCGIWGENIE */
3196 (iw_handler
) ieee80211_ioctl_siwauth
, /* SIOCSIWAUTH */
3197 (iw_handler
) ieee80211_ioctl_giwauth
, /* SIOCGIWAUTH */
3198 (iw_handler
) ieee80211_ioctl_siwencodeext
, /* SIOCSIWENCODEEXT */
3199 (iw_handler
) NULL
, /* SIOCGIWENCODEEXT */
3200 (iw_handler
) NULL
, /* SIOCSIWPMKSA */
3201 (iw_handler
) NULL
, /* -- hole -- */
3204 static const iw_handler ieee80211_private_handler
[] =
3205 { /* SIOCIWFIRSTPRIV + */
3206 (iw_handler
) ieee80211_ioctl_prism2_param
, /* 0 */
3207 (iw_handler
) ieee80211_ioctl_get_prism2_param
, /* 1 */
3210 const struct iw_handler_def ieee80211_iw_handler_def
=
3212 .num_standard
= sizeof(ieee80211_handler
) / sizeof(iw_handler
),
3213 .num_private
= sizeof(ieee80211_private_handler
) /
3215 .num_private_args
= sizeof(ieee80211_ioctl_priv
) /
3216 sizeof(struct iw_priv_args
),
3217 .standard
= (iw_handler
*) ieee80211_handler
,
3218 .private = (iw_handler
*) ieee80211_private_handler
,
3219 .private_args
= (struct iw_priv_args
*) ieee80211_ioctl_priv
,
3220 .get_wireless_stats
= ieee80211_get_wireless_stats
,
3223 /* Wireless handlers for master interface */
3225 static const iw_handler ieee80211_master_handler
[] =
3227 [SIOCGIWNAME
- SIOCIWFIRST
] = (iw_handler
) ieee80211_ioctl_giwname
,
3228 [SIOCSIWFREQ
- SIOCIWFIRST
] = (iw_handler
) ieee80211_ioctl_siwfreq
,
3229 [SIOCGIWFREQ
- SIOCIWFIRST
] = (iw_handler
) ieee80211_ioctl_giwfreq
,
3230 [SIOCGIWRANGE
- SIOCIWFIRST
] = (iw_handler
) ieee80211_ioctl_giwrange
,
3231 [SIOCSIWRTS
- SIOCIWFIRST
] = (iw_handler
) ieee80211_ioctl_siwrts
,
3232 [SIOCGIWRTS
- SIOCIWFIRST
] = (iw_handler
) ieee80211_ioctl_giwrts
,
3233 [SIOCSIWFRAG
- SIOCIWFIRST
] = (iw_handler
) ieee80211_ioctl_siwfrag
,
3234 [SIOCGIWFRAG
- SIOCIWFIRST
] = (iw_handler
) ieee80211_ioctl_giwfrag
,
3235 [SIOCSIWRETRY
- SIOCIWFIRST
] = (iw_handler
) ieee80211_ioctl_siwretry
,
3236 [SIOCGIWRETRY
- SIOCIWFIRST
] = (iw_handler
) ieee80211_ioctl_giwretry
,
3239 const struct iw_handler_def ieee80211_iw_master_handler_def
=
3241 .num_standard
= sizeof(ieee80211_master_handler
) / sizeof(iw_handler
),
3242 .standard
= ieee80211_master_handler
,