2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005, 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/config.h>
11 #include <linux/version.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/netdevice.h>
15 #include <linux/types.h>
16 #include <linux/slab.h>
17 #include <linux/skbuff.h>
18 #include <linux/if_arp.h>
19 #include <linux/wireless.h>
20 #include <net/iw_handler.h>
21 #include <asm/uaccess.h>
23 #include <net/ieee80211.h>
24 #include <net/ieee80211_mgmt.h>
25 #include "ieee80211_i.h"
26 #include "hostapd_ioctl.h"
27 #include "rate_control.h"
32 static int ieee80211_regdom
= 0x10; /* FCC */
33 MODULE_PARM(ieee80211_regdom
, "i");
34 MODULE_PARM_DESC(ieee80211_regdom
, "IEEE 802.11 regulatory domain; 64=MKK");
37 * If firmware is upgraded by the vendor, additional channels can be used based
38 * on the new Japanese regulatory rules. This is indicated by setting
39 * ieee80211_japan_5ghz module parameter to one when loading the 80211 kernel
42 static int ieee80211_japan_5ghz
/* = 0 */;
43 MODULE_PARM(ieee80211_japan_5ghz
, "i");
44 MODULE_PARM_DESC(ieee80211_japan_5ghz
, "Vendor-updated firmware for 5 GHz");
47 static int ieee80211_ioctl_set_beacon(struct net_device
*dev
,
48 struct prism2_hostapd_param
*param
,
52 struct ieee80211_sub_if_data
*sdata
;
53 struct ieee80211_if_norm
*norm
;
54 u8
**b_head
, **b_tail
;
55 int *b_head_len
, *b_tail_len
;
58 len
= ((char *) param
->u
.beacon
.data
- (char *) param
) +
59 param
->u
.beacon
.head_len
+ param
->u
.beacon
.tail_len
;
63 else if (param_len
!= len
)
66 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
67 if (sdata
->type
!= IEEE80211_SUB_IF_TYPE_NORM
)
69 norm
= &sdata
->u
.norm
;
73 b_head
= &norm
->beacon_head
;
74 b_tail
= &norm
->beacon_tail
;
75 b_head_len
= &norm
->beacon_head_len
;
76 b_tail_len
= &norm
->beacon_tail_len
;
79 printk(KERN_DEBUG
"%s: unknown beacon flag %d\n",
89 *b_head_len
= param
->u
.beacon
.head_len
;
90 *b_tail_len
= param
->u
.beacon
.tail_len
;
92 *b_head
= kmalloc(*b_head_len
, GFP_KERNEL
);
94 memcpy(*b_head
, param
->u
.beacon
.data
, *b_head_len
);
96 printk(KERN_DEBUG
"%s: failed to allocate beacon_head\n",
101 if (*b_tail_len
> 0) {
102 *b_tail
= kmalloc(*b_tail_len
, GFP_KERNEL
);
104 memcpy(*b_tail
, param
->u
.beacon
.data
+ (*b_head_len
),
107 printk(KERN_DEBUG
"%s: failed to allocate "
108 "beacon_tail\n", dev
->name
);
117 static int ieee80211_ioctl_get_hw_features(struct net_device
*dev
,
118 struct prism2_hostapd_param
*param
,
121 struct ieee80211_local
*local
= dev
->priv
;
122 u8
*pos
= param
->u
.hw_features
.data
;
123 int left
= param_len
- (pos
- (u8
*) param
);
125 struct hostapd_ioctl_hw_modes_hdr
*hdr
;
126 struct ieee80211_rate_data
*rate
;
127 struct ieee80211_channel_data
*chan
;
129 param
->u
.hw_features
.flags
= 0;
130 if (local
->hw
->data_nullfunc_ack
)
131 param
->u
.hw_features
.flags
|= HOSTAP_HW_FLAG_NULLFUNC_OK
;
133 param
->u
.hw_features
.num_modes
= local
->hw
->num_modes
;
134 for (mode
= 0; mode
< local
->hw
->num_modes
; mode
++) {
136 struct ieee80211_hw_modes
*m
= &local
->hw
->modes
[mode
];
137 clen
= m
->num_channels
* sizeof(struct ieee80211_channel_data
);
138 rlen
= m
->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
;
145 hdr
->num_channels
= m
->num_channels
;
146 hdr
->num_rates
= m
->num_rates
;
148 pos
= (u8
*) (hdr
+ 1);
149 chan
= (struct ieee80211_channel_data
*) pos
;
150 for (i
= 0; i
< m
->num_channels
; i
++) {
151 chan
[i
].chan
= m
->channels
[i
].chan
;
152 chan
[i
].freq
= m
->channels
[i
].freq
;
153 chan
[i
].flag
= m
->channels
[i
].flag
;
157 rate
= (struct ieee80211_rate_data
*) pos
;
158 for (i
= 0; i
< m
->num_rates
; i
++) {
159 rate
[i
].rate
= m
->rates
[i
].rate
;
160 rate
[i
].flags
= m
->rates
[i
].flags
;
169 static int ieee80211_ioctl_scan(struct net_device
*dev
,
170 struct prism2_hostapd_param
*param
)
172 struct ieee80211_local
*local
= dev
->priv
;
174 if (local
->hw
->passive_scan
== NULL
)
177 if ((param
->u
.scan
.now
== 1) && (local
->scan
.in_scan
== 1))
180 if (param
->u
.scan
.our_mode_only
>= 0)
181 local
->scan
.our_mode_only
= param
->u
.scan
.our_mode_only
;
182 if (param
->u
.scan
.interval
>= 0)
183 local
->scan
.interval
= param
->u
.scan
.interval
;
184 if (param
->u
.scan
.listen
>= 0)
185 local
->scan
.time
= param
->u
.scan
.listen
;
186 if (param
->u
.scan
.channel
> 0)
187 local
->scan
.channel
= param
->u
.scan
.channel
;
188 if (param
->u
.scan
.now
== 1) {
189 local
->scan
.in_scan
= 0;
190 mod_timer(&local
->scan
.timer
, jiffies
);
193 param
->u
.scan
.our_mode_only
= local
->scan
.our_mode_only
;
194 param
->u
.scan
.interval
= local
->scan
.interval
;
195 param
->u
.scan
.listen
= local
->scan
.time
;
196 if (local
->scan
.in_scan
== 1)
197 param
->u
.scan
.last_rx
= -1;
199 param
->u
.scan
.last_rx
= local
->scan
.rx_packets
;
200 local
->scan
.rx_packets
= -1;
202 param
->u
.scan
.channel
= local
->hw
->modes
[local
->scan
.mode_idx
].
203 channels
[local
->scan
.chan_idx
].chan
;
209 static int ieee80211_ioctl_flush(struct net_device
*dev
,
210 struct prism2_hostapd_param
*param
)
212 struct ieee80211_local
*local
= dev
->priv
;
213 sta_info_flush(local
, NULL
);
220 static int ieee80211_ioctl_add_sta(struct net_device
*dev
,
221 struct prism2_hostapd_param
*param
)
223 struct ieee80211_local
*local
= dev
->priv
;
224 struct sta_info
*sta
;
227 struct ieee80211_sub_if_data
*sdata
;
228 int add_key_entry
= 1;
230 sta
= sta_info_get(local
, param
->sta_addr
);
233 sta
= sta_info_add(local
, dev
, param
->sta_addr
);
238 if (sta
->dev
!= dev
) {
239 /* Binding STA to a new interface, so remove all references to
241 sta_info_remove_aid_ptr(sta
);
245 * We "steal" the device in case someone owns it
246 * This will hurt WDS links and such when we have a
247 * WDS link and a client associating from the same station
250 sdata
= IEEE80211_DEV_TO_SUB_IF(sta
->dev
);
252 sta
->flags
|= WLAN_STA_AUTH
| WLAN_STA_ASSOC
;
253 sta
->aid
= param
->u
.add_sta
.aid
;
254 if (sta
->aid
> MAX_AID_TABLE_SIZE
)
256 if (sta
->aid
> 0 && sdata
->bss
)
257 sdata
->bss
->sta_aid
[sta
->aid
- 1] = sta
;
258 if (sdata
->bss
&& sta
->aid
> sdata
->bss
->max_aid
)
259 sdata
->bss
->max_aid
= sta
->aid
;
262 for (i
= 0; i
< sizeof(param
->u
.add_sta
.supp_rates
); i
++) {
263 int rate
= (param
->u
.add_sta
.supp_rates
[i
] & 0x7f) * 5;
264 if (local
->conf
.phymode
== MODE_ATHEROS_TURBO
||
265 local
->conf
.phymode
== MODE_ATHEROS_TURBOG
)
267 for (j
= 0; j
< local
->num_curr_rates
; j
++) {
268 if (local
->curr_rates
[j
].rate
== rate
)
273 sta
->supp_rates
= rates
;
275 rate_control_rate_init(local
, sta
);
279 if (param
->u
.add_sta
.wds_flags
& 0x01)
280 sta
->flags
|= WLAN_STA_WDS
;
282 sta
->flags
&= ~WLAN_STA_WDS
;
284 if (add_key_entry
&& sta
->key
== NULL
&& sdata
->default_key
== NULL
&&
285 local
->hw
->set_key
) {
286 struct ieee80211_key_conf conf
;
287 /* Add key cache entry with NULL key type because this may used
288 * for TX filtering. */
289 memset(&conf
, 0, sizeof(conf
));
290 conf
.hw_key_idx
= HW_KEY_IDX_INVALID
;
292 conf
.force_sw_encrypt
= 1;
293 if (local
->hw
->set_key(dev
, SET_KEY
, sta
->addr
, &conf
,
295 sta
->key_idx_compression
= HW_KEY_IDX_INVALID
;
297 sta
->key_idx_compression
= conf
.hw_key_idx
;
301 sta_info_release(local
, sta
);
307 static int ieee80211_ioctl_remove_sta(struct net_device
*dev
,
308 struct prism2_hostapd_param
*param
)
310 struct ieee80211_local
*local
= dev
->priv
;
311 struct sta_info
*sta
;
313 sta
= sta_info_get(local
, param
->sta_addr
);
315 sta_info_release(local
, sta
);
316 sta_info_free(local
, sta
, 1);
319 return sta
? 0 : -ENOENT
;
323 static int ieee80211_ioctl_get_dot11counterstable(struct net_device
*dev
,
324 struct prism2_hostapd_param
*param
)
326 struct ieee80211_local
*local
= dev
->priv
;
327 struct ieee80211_low_level_stats stats
;
329 memset(&stats
, 0, sizeof(stats
));
330 if (local
->hw
->get_stats
)
331 local
->hw
->get_stats(dev
, &stats
);
332 param
->u
.dot11CountersTable
.dot11TransmittedFragmentCount
=
333 local
->dot11TransmittedFragmentCount
;
334 param
->u
.dot11CountersTable
.dot11MulticastTransmittedFrameCount
=
335 local
->dot11MulticastTransmittedFrameCount
;
336 param
->u
.dot11CountersTable
.dot11ReceivedFragmentCount
=
337 local
->dot11ReceivedFragmentCount
;
338 param
->u
.dot11CountersTable
.dot11MulticastReceivedFrameCount
=
339 local
->dot11MulticastReceivedFrameCount
;
340 param
->u
.dot11CountersTable
.dot11TransmittedFrameCount
=
341 local
->dot11TransmittedFrameCount
;
342 param
->u
.dot11CountersTable
.dot11FCSErrorCount
=
343 stats
.dot11FCSErrorCount
;
344 param
->u
.dot11CountersTable
.dot11ACKFailureCount
=
345 stats
.dot11ACKFailureCount
;
346 param
->u
.dot11CountersTable
.dot11RTSFailureCount
=
347 stats
.dot11RTSFailureCount
;
348 param
->u
.dot11CountersTable
.dot11RTSSuccessCount
=
349 stats
.dot11RTSSuccessCount
;
354 static int ieee80211_ioctl_get_info_sta(struct net_device
*dev
,
355 struct prism2_hostapd_param
*param
)
357 struct ieee80211_local
*local
= dev
->priv
;
358 struct sta_info
*sta
;
360 if (param
->sta_addr
[0] == 0xff && param
->sta_addr
[1] == 0xff &&
361 param
->sta_addr
[2] == 0xff && param
->sta_addr
[3] == 0xff &&
362 param
->sta_addr
[4] == 0xff && param
->sta_addr
[5] == 0xff) {
363 struct ieee80211_sub_if_data
*sdata
;
364 struct net_device_stats
*stats
;
366 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
367 stats
= ieee80211_dev_stats(sdata
->master
);
368 param
->u
.get_info_sta
.rx_bytes
= stats
->rx_bytes
;
369 param
->u
.get_info_sta
.tx_bytes
= stats
->tx_bytes
;
370 /* go through all STAs and get STA with lowest max. rate */
371 param
->u
.get_info_sta
.current_tx_rate
=
372 local
->curr_rates
[sta_info_min_txrate_get(local
)].rate
;
376 sta
= sta_info_get(local
, param
->sta_addr
);
381 param
->u
.get_info_sta
.inactive_msec
=
382 jiffies_to_msecs(jiffies
- sta
->last_rx
);
383 param
->u
.get_info_sta
.rx_packets
= sta
->rx_packets
;
384 param
->u
.get_info_sta
.tx_packets
= sta
->tx_packets
;
385 param
->u
.get_info_sta
.rx_bytes
= sta
->rx_bytes
;
386 param
->u
.get_info_sta
.tx_bytes
= sta
->tx_bytes
;
387 param
->u
.get_info_sta
.channel_use
= sta
->channel_use
;
388 param
->u
.get_info_sta
.flags
= sta
->flags
;
389 if (sta
->txrate
>= 0 && sta
->txrate
< local
->num_curr_rates
)
390 param
->u
.get_info_sta
.current_tx_rate
=
391 local
->curr_rates
[sta
->txrate
].rate
;
392 param
->u
.get_info_sta
.num_ps_buf_frames
=
393 skb_queue_len(&sta
->ps_tx_buf
);
394 param
->u
.get_info_sta
.tx_retry_failed
= sta
->tx_retry_failed
;
395 param
->u
.get_info_sta
.tx_retry_count
= sta
->tx_retry_count
;
396 param
->u
.get_info_sta
.last_rssi
= sta
->last_rssi
;
397 param
->u
.get_info_sta
.last_ack_rssi
= sta
->last_ack_rssi
[2];
399 sta_info_release(local
, sta
);
405 static int ieee80211_ioctl_set_flags_sta(struct net_device
*dev
,
406 struct prism2_hostapd_param
*param
)
408 struct ieee80211_local
*local
= dev
->priv
;
409 struct sta_info
*sta
;
411 sta
= sta_info_get(local
, param
->sta_addr
);
413 sta
->flags
|= param
->u
.set_flags_sta
.flags_or
;
414 sta
->flags
&= param
->u
.set_flags_sta
.flags_and
;
415 if (local
->hw
->set_port_auth
&&
416 (param
->u
.set_flags_sta
.flags_or
& WLAN_STA_AUTHORIZED
) &&
417 local
->hw
->set_port_auth(local
->mdev
, sta
->addr
, 1))
418 printk(KERN_DEBUG
"%s: failed to set low-level driver "
419 "PAE state (authorized) for " MACSTR
"\n",
420 dev
->name
, MAC2STR(sta
->addr
));
421 if (local
->hw
->set_port_auth
&&
422 !(param
->u
.set_flags_sta
.flags_and
& WLAN_STA_AUTHORIZED
)
423 && local
->hw
->set_port_auth(local
->mdev
, sta
->addr
, 0))
424 printk(KERN_DEBUG
"%s: failed to set low-level driver "
425 "PAE state (unauthorized) for " MACSTR
"\n",
426 dev
->name
, MAC2STR(sta
->addr
));
427 sta_info_release(local
, sta
);
430 return sta
? 0 : -ENOENT
;
434 int ieee80211_set_hw_encryption(struct net_device
*dev
,
435 struct sta_info
*sta
, u8 addr
[ETH_ALEN
],
436 struct ieee80211_key
*key
)
438 struct ieee80211_key_conf
*keyconf
= NULL
;
439 struct ieee80211_local
*local
= dev
->priv
;
442 /* default to sw encryption; this will be cleared by low-level
443 * driver if the hw supports requested encryption */
445 key
->force_sw_encrypt
= 1;
447 if (key
&& local
->hw
->set_key
&&
448 (!local
->conf
.sw_encrypt
|| !local
->conf
.sw_decrypt
) &&
449 (keyconf
= ieee80211_key_data2conf(local
, key
)) != NULL
) {
450 if (local
->hw
->set_key(dev
, SET_KEY
, addr
,
451 keyconf
, sta
? sta
->aid
: 0)) {
452 rc
= HOSTAP_CRYPT_ERR_KEY_SET_FAILED
;
453 key
->force_sw_encrypt
= 1;
454 key
->hw_key_idx
= HW_KEY_IDX_INVALID
;
456 key
->force_sw_encrypt
=
457 keyconf
->force_sw_encrypt
;
469 static int ieee80211_ioctl_set_encryption(struct net_device
*dev
,
470 struct prism2_hostapd_param
*param
,
473 struct ieee80211_local
*local
= dev
->priv
;
475 struct sta_info
*sta
;
476 struct ieee80211_key
**key
;
477 int set_tx_key
= 0, try_hwaccel
= 1;
478 struct ieee80211_key_conf
*keyconf
;
479 struct ieee80211_sub_if_data
*sdata
;
481 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
483 param
->u
.crypt
.err
= 0;
484 param
->u
.crypt
.alg
[HOSTAP_CRYPT_ALG_NAME_LEN
- 1] = '\0';
487 (int) ((char *) param
->u
.crypt
.key
- (char *) param
) +
488 param
->u
.crypt
.key_len
) {
489 printk(KERN_DEBUG
"%s: set_encrypt - invalid param_lem\n",
494 if (param
->sta_addr
[0] == 0xff && param
->sta_addr
[1] == 0xff &&
495 param
->sta_addr
[2] == 0xff && param
->sta_addr
[3] == 0xff &&
496 param
->sta_addr
[4] == 0xff && param
->sta_addr
[5] == 0xff) {
498 if (param
->u
.crypt
.idx
>= NUM_DEFAULT_KEYS
) {
499 printk(KERN_DEBUG
"%s: set_encrypt - invalid idx=%d\n",
500 dev
->name
, param
->u
.crypt
.idx
);
503 key
= &sdata
->keys
[param
->u
.crypt
.idx
];
504 if (param
->u
.crypt
.flags
& HOSTAP_CRYPT_FLAG_SET_TX_KEY
)
507 /* Disable hwaccel for default keys when the interface is not
509 * TODO: consider adding hwaccel support for these; at least
510 * Atheros key cache should be able to handle this since AP is
511 * only transmitting frames with default keys. */
512 /* FIX: hw key cache can be used when only one virtual
513 * STA is associated with each AP. If more than one STA
514 * is associated to the same AP, software encryption
515 * must be used. This should be done automatically
516 * based on configured station devices. For the time
517 * being, this can be only set at compile time. */
518 if (sdata
->type
== IEEE80211_SUB_IF_TYPE_STA
) {
519 if (0 /* FIX: more than one STA per AP */)
522 if (sdata
->type
!= IEEE80211_SUB_IF_TYPE_NORM
||
526 if (param
->u
.crypt
.idx
!= 0) {
527 printk(KERN_DEBUG
"%s: set_encrypt - non-zero idx for "
528 "individual key\n", dev
->name
);
532 sta
= sta_info_get(local
, param
->sta_addr
);
534 param
->u
.crypt
.err
= HOSTAP_CRYPT_ERR_UNKNOWN_ADDR
;
535 #ifdef CONFIG_IEEE80211_VERBOSE_DEBUG
536 printk(KERN_DEBUG
"%s: set_encrypt - unknown addr "
538 dev
->name
, MAC2STR(param
->sta_addr
));
539 #endif /* CONFIG_IEEE80211_VERBOSE_DEBUG */
547 if (strcmp(param
->u
.crypt
.alg
, "none") == 0) {
549 } else if (strcmp(param
->u
.crypt
.alg
, "WEP") == 0) {
551 } else if (strcmp(param
->u
.crypt
.alg
, "TKIP") == 0) {
552 if (param
->u
.crypt
.key_len
!= ALG_TKIP_KEY_LEN
) {
553 printk(KERN_DEBUG
"%s: set_encrypt - invalid TKIP key "
554 "length %d\n", dev
->name
,
555 param
->u
.crypt
.key_len
);
560 } else if (strcmp(param
->u
.crypt
.alg
, "CCMP") == 0) {
561 if (param
->u
.crypt
.key_len
!= ALG_CCMP_KEY_LEN
) {
562 printk(KERN_DEBUG
"%s: set_encrypt - invalid CCMP key "
563 "length %d\n", dev
->name
,
564 param
->u
.crypt
.key_len
);
570 param
->u
.crypt
.err
= HOSTAP_CRYPT_ERR_UNKNOWN_ALG
;
571 printk(KERN_DEBUG
"%s: set_encrypt - unknown alg\n",
578 * Cannot configure default hwaccel keys with WEP algorithm, if
579 * any of the virtual interfaces is using static WEP
580 * configuration because hwaccel would otherwise try to decrypt
583 * For now, just disable WEP hwaccel for broadcast when there is
584 * possibility of conflict with default keys. This can maybe later be
585 * optimized by using non-default keys (at least with Atheros ar521x).
587 if (!sta
&& alg
== ALG_WEP
&& !local
->default_wep_only
&&
588 local
->conf
.mode
!= IW_MODE_ADHOC
&&
589 local
->conf
.mode
!= IW_MODE_INFRA
) {
593 if (local
->hw
->device_hides_wep
) {
594 /* Software encryption cannot be used with devices that hide
595 * encryption from the host system, so always try to use
596 * hardware acceleration with such devices. */
600 if (local
->hw
->no_tkip_wmm_hwaccel
&& alg
== ALG_TKIP
) {
601 if (sta
&& (sta
->flags
& WLAN_STA_WME
)) {
602 /* Hardware does not support hwaccel with TKIP when using WMM.
606 else if (sdata
->type
== IEEE80211_SUB_IF_TYPE_STA
) {
607 sta
= sta_info_get(local
, sdata
->u
.sta
.bssid
);
609 if (sta
->flags
& WLAN_STA_WME
) {
612 sta_info_release(local
, sta
);
619 if (alg
== ALG_NONE
) {
621 if (try_hwaccel
&& *key
&& local
->hw
->set_key
&&
622 (keyconf
= ieee80211_key_data2conf(local
, *key
)) != NULL
&&
623 local
->hw
->set_key(dev
, DISABLE_KEY
, param
->sta_addr
,
624 keyconf
, sta
? sta
->aid
: 0)) {
625 param
->u
.crypt
.err
= HOSTAP_CRYPT_ERR_KEY_SET_FAILED
;
626 printk(KERN_DEBUG
"%s: set_encrypt - low-level disable"
627 " failed\n", dev
->name
);
632 if (sdata
->default_key
== *key
)
633 sdata
->default_key
= NULL
;
637 if (*key
== NULL
|| (*key
)->keylen
< param
->u
.crypt
.key_len
) {
639 *key
= kmalloc(sizeof(struct ieee80211_key
) +
640 param
->u
.crypt
.key_len
, GFP_ATOMIC
);
646 memset(*key
, 0, sizeof(struct ieee80211_key
) +
647 param
->u
.crypt
.key_len
);
648 /* default to sw encryption; low-level driver sets these if the
649 * requested encryption is supported */
650 (*key
)->hw_key_idx
= HW_KEY_IDX_INVALID
;
651 (*key
)->force_sw_encrypt
= 1;
654 (*key
)->keyidx
= param
->u
.crypt
.idx
;
655 (*key
)->keylen
= param
->u
.crypt
.key_len
;
656 memcpy((*key
)->key
, param
->u
.crypt
.key
,
657 param
->u
.crypt
.key_len
);
659 (*key
)->default_tx_key
= 1;
661 if (alg
== ALG_CCMP
) {
662 /* Initialize AES key state here as an optimization
663 * so that it does not need to be initialized for every
665 ieee80211_aes_key_setup_encrypt(
666 (*key
)->u
.ccmp
.aes_state
, (*key
)->key
);
670 (alg
== ALG_WEP
|| alg
== ALG_TKIP
|| alg
== ALG_CCMP
))
671 param
->u
.crypt
.err
= ieee80211_set_hw_encryption(
672 dev
, sta
, param
->sta_addr
, *key
);
675 if (set_tx_key
|| (sta
== NULL
&& sdata
->default_key
== NULL
)) {
676 sdata
->default_key
= *key
;
677 if (local
->hw
->set_key_idx
&&
678 local
->hw
->set_key_idx(dev
, param
->u
.crypt
.idx
))
679 printk(KERN_DEBUG
"%s: failed to set TX key idx for "
680 "low-level driver\n", dev
->name
);
685 sta_info_release(local
, sta
);
690 static int ieee80211_ioctl_get_encryption(struct net_device
*dev
,
691 struct prism2_hostapd_param
*param
,
694 struct ieee80211_local
*local
= dev
->priv
;
696 struct sta_info
*sta
;
697 struct ieee80211_key
**key
;
699 struct ieee80211_sub_if_data
*sdata
;
702 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
704 param
->u
.crypt
.err
= 0;
706 max_key_len
= param_len
-
707 (int) ((char *) param
->u
.crypt
.key
- (char *) param
);
711 if (param
->sta_addr
[0] == 0xff && param
->sta_addr
[1] == 0xff &&
712 param
->sta_addr
[2] == 0xff && param
->sta_addr
[3] == 0xff &&
713 param
->sta_addr
[4] == 0xff && param
->sta_addr
[5] == 0xff) {
715 if (param
->u
.crypt
.idx
> NUM_DEFAULT_KEYS
) {
716 param
->u
.crypt
.idx
= sdata
->default_key
?
717 sdata
->default_key
->keyidx
: 0;
720 key
= &sdata
->keys
[param
->u
.crypt
.idx
];
722 sta
= sta_info_get(local
, param
->sta_addr
);
724 param
->u
.crypt
.err
= HOSTAP_CRYPT_ERR_UNKNOWN_ADDR
;
732 memset(param
->u
.crypt
.seq_counter
, 0, HOSTAP_SEQ_COUNTER_SIZE
);
734 memcpy(param
->u
.crypt
.alg
, "none", 5);
735 param
->u
.crypt
.key_len
= 0;
736 param
->u
.crypt
.idx
= 0xff;
738 switch ((*key
)->alg
) {
740 memcpy(param
->u
.crypt
.alg
, "WEP", 4);
747 memcpy(param
->u
.crypt
.alg
, "TKIP", 5);
748 if (local
->hw
->get_sequence_counter
) {
749 /* Get transmit counter from low level driver */
750 if (local
->hw
->get_sequence_counter(dev
,
753 IEEE80211_SEQ_COUNTER_TX
,
756 /* Error getting value from device */
760 /* Get it from our own local data */
761 iv32
= (*key
)->u
.tkip
.iv32
;
762 iv16
= (*key
)->u
.tkip
.iv16
;
764 pos
= param
->u
.crypt
.seq_counter
;
765 *pos
++ = iv16
& 0xff;
766 *pos
++ = (iv16
>> 8) & 0xff;
767 *pos
++ = iv32
& 0xff;
768 *pos
++ = (iv32
>> 8) & 0xff;
769 *pos
++ = (iv32
>> 16) & 0xff;
770 *pos
++ = (iv32
>> 24) & 0xff;
776 memcpy(param
->u
.crypt
.alg
, "CCMP", 5);
777 pos
= param
->u
.crypt
.seq_counter
;
778 pn
= (*key
)->u
.ccmp
.tx_pn
;
788 memcpy(param
->u
.crypt
.alg
, "unknown", 8);
792 if (max_key_len
< (*key
)->keylen
)
795 param
->u
.crypt
.key_len
= (*key
)->keylen
;
796 memcpy(param
->u
.crypt
.key
, (*key
)->key
,
802 sta_info_release(local
, sta
);
808 #ifdef CONFIG_HOSTAPD_WPA_TESTING
809 static int ieee80211_ioctl_wpa_trigger(struct net_device
*dev
,
810 struct prism2_hostapd_param
*param
)
812 struct ieee80211_local
*local
= dev
->priv
;
813 struct sta_info
*sta
;
815 if (param
->sta_addr
[0] == 0xff && param
->sta_addr
[1] == 0xff &&
816 param
->sta_addr
[2] == 0xff && param
->sta_addr
[3] == 0xff &&
817 param
->sta_addr
[4] == 0xff && param
->sta_addr
[5] == 0xff) {
818 local
->wpa_trigger
= param
->u
.wpa_trigger
.trigger
;
822 sta
= sta_info_get(local
, param
->sta_addr
);
824 printk(KERN_DEBUG
"%s: wpa_trigger - unknown addr\n",
829 sta
->wpa_trigger
= param
->u
.wpa_trigger
.trigger
;
831 sta_info_release(local
, sta
);
834 #endif /* CONFIG_HOSTAPD_WPA_TESTING */
837 static int ieee80211_ioctl_set_rate_sets(struct net_device
*dev
,
838 struct prism2_hostapd_param
*param
,
841 struct ieee80211_local
*local
= dev
->priv
;
842 u16
*pos
= (u16
*) param
->u
.set_rate_sets
.data
;
843 int left
= param_len
- ((u8
*) pos
- (u8
*) param
);
844 int i
, mode
, num_supp
, num_basic
, *supp
, *basic
, *prev
;
846 mode
= param
->u
.set_rate_sets
.mode
;
847 num_supp
= param
->u
.set_rate_sets
.num_supported_rates
;
848 num_basic
= param
->u
.set_rate_sets
.num_basic_rates
;
850 if (left
< (num_supp
+ num_basic
) * 2) {
851 printk(KERN_WARNING
"%s: invalid length in hostapd set rate "
852 "sets ioctl (%d != %d)\n", dev
->name
, left
,
853 (num_supp
+ num_basic
) * 2);
857 supp
= (int *) kmalloc((num_supp
+ 1) * sizeof(int), GFP_KERNEL
);
858 basic
= (int *) kmalloc((num_basic
+ 1) * sizeof(int), GFP_KERNEL
);
860 if (!supp
|| !basic
) {
866 for (i
= 0; i
< num_supp
; i
++)
870 for (i
= 0; i
< num_basic
; i
++)
879 if (num_basic
== 0) {
884 prev
= local
->supp_rates
[mode
];
885 local
->supp_rates
[mode
] = supp
;
888 prev
= local
->basic_rates
[mode
];
889 local
->basic_rates
[mode
] = basic
;
892 if (mode
== local
->conf
.phymode
) {
893 /* TODO: should update STA TX rates and remove STAs if they
894 * do not have any remaining supported rates after the change
896 ieee80211_prepare_rates(dev
);
903 static int ieee80211_ioctl_add_if(struct net_device
*dev
,
904 struct prism2_hostapd_param
*param
,
907 u8
*pos
= param
->u
.if_info
.data
;
908 int left
= param_len
- ((u8
*) pos
- (u8
*) param
);
910 if (param
->u
.if_info
.type
== HOSTAP_IF_WDS
) {
911 struct ieee80211_if_wds iwds
;
912 struct hostapd_if_wds
*wds
=
913 (struct hostapd_if_wds
*) param
->u
.if_info
.data
;
915 if (left
< sizeof(struct ieee80211_if_wds
))
918 memcpy(iwds
.remote_addr
, wds
->remote_addr
, ETH_ALEN
);
920 return ieee80211_if_add_wds(dev
, param
->u
.if_info
.name
,
922 } else if (param
->u
.if_info
.type
== HOSTAP_IF_VLAN
) {
923 struct hostapd_if_vlan
*vlan
= (struct hostapd_if_vlan
*) pos
;
924 struct ieee80211_if_vlan ivlan
;
926 if (left
< sizeof(struct hostapd_if_vlan
))
931 return ieee80211_if_add_vlan(dev
, param
->u
.if_info
.name
,
933 } else if (param
->u
.if_info
.type
== HOSTAP_IF_BSS
) {
934 struct hostapd_if_bss
*bss
=
935 (struct hostapd_if_bss
*) param
->u
.if_info
.data
;
937 if (left
< sizeof(struct hostapd_if_bss
))
940 return ieee80211_if_add_norm(dev
, param
->u
.if_info
.name
,
942 } else if (param
->u
.if_info
.type
== HOSTAP_IF_STA
) {
944 struct hostapd_if_sta
*sta
=
945 (struct hostapd_if_sta
*) param
->u
.if_info
.data
;
948 if (left
< sizeof(struct hostapd_if_sta
))
951 return ieee80211_if_add_sta(dev
, param
->u
.if_info
.name
, 1);
959 static int ieee80211_ioctl_remove_if(struct net_device
*dev
,
960 struct prism2_hostapd_param
*param
)
962 if (param
->u
.if_info
.type
== HOSTAP_IF_WDS
) {
963 return ieee80211_if_remove_wds(dev
, param
->u
.if_info
.name
, 1);
964 } else if (param
->u
.if_info
.type
== HOSTAP_IF_VLAN
) {
965 return ieee80211_if_remove_vlan(dev
, param
->u
.if_info
.name
, 1);
966 } else if (param
->u
.if_info
.type
== HOSTAP_IF_BSS
) {
967 return ieee80211_if_remove_norm(dev
, param
->u
.if_info
.name
, 1);
968 } else if (param
->u
.if_info
.type
== HOSTAP_IF_STA
) {
969 return ieee80211_if_remove_sta(dev
, param
->u
.if_info
.name
, 1);
976 static int ieee80211_ioctl_update_if(struct net_device
*dev
,
977 struct prism2_hostapd_param
*param
,
980 u8
*pos
= param
->u
.if_info
.data
;
981 int left
= param_len
- ((u8
*) pos
- (u8
*) param
);
983 if (param
->u
.if_info
.type
== HOSTAP_IF_WDS
) {
984 struct ieee80211_if_wds iwds
;
985 struct hostapd_if_wds
*wds
=
986 (struct hostapd_if_wds
*) param
->u
.if_info
.data
;
988 if (left
< sizeof(struct ieee80211_if_wds
))
991 memcpy(iwds
.remote_addr
, wds
->remote_addr
, ETH_ALEN
);
993 return ieee80211_if_update_wds(dev
, param
->u
.if_info
.name
,
1001 static int ieee80211_ioctl_flush_ifs(struct net_device
*dev
,
1002 struct prism2_hostapd_param
*param
)
1004 return ieee80211_if_flush(dev
, 1);
1008 static int ieee80211_ioctl_scan_req(struct net_device
*dev
,
1009 struct prism2_hostapd_param
*param
,
1012 u8
*pos
= param
->u
.scan_req
.ssid
;
1013 int left
= param_len
- ((u8
*) pos
- (u8
*) param
);
1014 int len
= param
->u
.scan_req
.ssid_len
;
1016 if (left
< len
|| len
> IEEE80211_MAX_SSID_LEN
)
1019 return ieee80211_sta_req_scan(dev
, pos
, len
);
1023 static int ieee80211_ioctl_sta_get_state(struct net_device
*dev
,
1024 struct prism2_hostapd_param
*param
)
1026 struct ieee80211_sub_if_data
*sdata
;
1028 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1029 if (sdata
->type
!= IEEE80211_SUB_IF_TYPE_STA
)
1031 param
->u
.sta_get_state
.state
= sdata
->u
.sta
.state
;
1036 static int ieee80211_ioctl_mlme(struct net_device
*dev
,
1037 struct prism2_hostapd_param
*param
)
1039 struct ieee80211_sub_if_data
*sdata
;
1041 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1042 if (sdata
->type
!= IEEE80211_SUB_IF_TYPE_STA
)
1044 switch (param
->u
.mlme
.cmd
) {
1045 case MLME_STA_DEAUTH
:
1046 ieee80211_sta_deauthenticate(dev
, param
->u
.mlme
.reason_code
);
1048 case MLME_STA_DISASSOC
:
1049 ieee80211_sta_disassociate(dev
, param
->u
.mlme
.reason_code
);
1056 static int ieee80211_ioctl_get_load_stats(struct net_device
*dev
,
1057 struct prism2_hostapd_param
*param
)
1059 struct ieee80211_local
*local
= dev
->priv
;
1061 param
->u
.get_load_stats
.channel_use
= local
->channel_use
;
1062 /* if (param->u.get_load_stats.flags & LOAD_STATS_CLEAR)
1063 local->channel_use = 0; */ /* now it's not raw counter */
1069 static int ieee80211_ioctl_set_sta_vlan(struct net_device
*dev
,
1070 struct prism2_hostapd_param
*param
)
1072 struct ieee80211_local
*local
= dev
->priv
;
1073 struct sta_info
*sta
;
1075 sta
= sta_info_get(local
, param
->sta_addr
);
1077 struct net_device
*new_vlan_dev
;
1079 dev_get_by_name(param
->u
.set_sta_vlan
.vlan_name
);
1082 printk("%s: Station " MACSTR
" moved to vlan: %s\n",
1083 dev
->name
, MAC2STR(param
->sta_addr
),
1084 new_vlan_dev
->name
);
1086 sta
->dev
= new_vlan_dev
;
1087 sta
->vlan_id
= param
->u
.set_sta_vlan
.vlan_id
;
1088 dev_put(new_vlan_dev
);
1090 sta_info_release(local
, sta
);
1093 return sta
? 0 : -ENOENT
;
1098 ieee80211_ioctl_set_generic_info_elem(struct net_device
*dev
,
1099 struct prism2_hostapd_param
*param
,
1102 struct ieee80211_local
*local
= dev
->priv
;
1103 u8
*pos
= param
->u
.set_generic_info_elem
.data
;
1104 int left
= param_len
- ((u8
*) pos
- (u8
*) param
);
1105 int len
= param
->u
.set_generic_info_elem
.len
;
1111 struct ieee80211_sub_if_data
*sdata
;
1112 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1113 if (sdata
->type
== IEEE80211_SUB_IF_TYPE_STA
)
1114 return ieee80211_sta_set_extra_ie(dev
, pos
, len
);
1116 kfree(local
->conf
.generic_elem
);
1117 local
->conf
.generic_elem
= kmalloc(len
, GFP_KERNEL
);
1118 if (local
->conf
.generic_elem
== NULL
)
1120 memcpy(local
->conf
.generic_elem
, pos
, len
);
1121 local
->conf
.generic_elem_len
= len
;
1123 return ieee80211_hw_config(dev
);
1127 static int ieee80211_ioctl_set_regulatory_domain(struct net_device
*dev
,
1128 struct prism2_hostapd_param
*param
)
1130 struct ieee80211_conf
*conf
= ieee80211_get_hw_conf(dev
);
1131 conf
->regulatory_domain
= param
->u
.set_regulatory_domain
.rd
;
1136 static int ieee80211_ioctl_set_adm_status(struct net_device
*dev
,
1139 struct ieee80211_conf
*conf
= ieee80211_get_hw_conf(dev
);
1140 conf
->adm_status
= val
;
1141 return ieee80211_hw_config(dev
);
1145 ieee80211_ioctl_set_tx_queue_params(struct net_device
*dev
,
1146 struct prism2_hostapd_param
*param
)
1148 struct ieee80211_local
*local
= dev
->priv
;
1149 struct ieee80211_tx_queue_params qparam
;
1151 if (!local
->hw
->conf_tx
) {
1152 printk(KERN_DEBUG
"%s: low-level driver does not support TX "
1153 "queue configuration\n", dev
->name
);
1157 memset(&qparam
, 0, sizeof(qparam
));
1158 qparam
.aifs
= param
->u
.tx_queue_params
.aifs
;
1159 qparam
.cw_min
= param
->u
.tx_queue_params
.cw_min
;
1160 qparam
.cw_max
= param
->u
.tx_queue_params
.cw_max
;
1161 qparam
.burst_time
= param
->u
.tx_queue_params
.burst_time
;
1163 return local
->hw
->conf_tx(dev
, param
->u
.tx_queue_params
.queue
,
1168 static int ieee80211_ioctl_get_tx_stats(struct net_device
*dev
,
1169 struct prism2_hostapd_param
*param
)
1171 struct ieee80211_local
*local
= dev
->priv
;
1172 struct ieee80211_tx_queue_stats stats
;
1175 if (!local
->hw
->get_tx_stats
)
1178 memset(&stats
, 0, sizeof(stats
));
1179 ret
= local
->hw
->get_tx_stats(dev
, &stats
);
1183 for (i
= 0; i
< 4; i
++) {
1184 param
->u
.get_tx_stats
.data
[i
].len
= stats
.data
[i
].len
;
1185 param
->u
.get_tx_stats
.data
[i
].limit
= stats
.data
[i
].limit
;
1186 param
->u
.get_tx_stats
.data
[i
].count
= stats
.data
[i
].count
;
1193 static int ieee80211_ioctl_set_bss(struct net_device
*dev
,
1194 struct prism2_hostapd_param
*param
)
1196 struct ieee80211_local
*local
= dev
->priv
;
1197 struct ieee80211_conf
*conf
= ieee80211_get_hw_conf(dev
);
1199 int new_count
= param
->u
.set_bss
.bss_count
;
1200 struct net_device
**bss_devs
, **prev
;
1201 struct net_device
**sta_devs
, **prev_sta_devs
;
1204 for (i
= 0; i
< conf
->bss_count
; i
++) {
1205 if (local
->bss_devs
[i
])
1209 if (new_count
< bss_count
) {
1210 printk(KERN_DEBUG
"%s: invalid BSS count %d (in use: %d)\n",
1211 dev
->name
, new_count
, bss_count
);
1215 bss_devs
= kmalloc(new_count
* sizeof(struct net_device
*),
1217 if (bss_devs
== NULL
)
1219 sta_devs
= kmalloc(new_count
* sizeof(struct net_device
*),
1221 if (sta_devs
== NULL
) {
1226 spin_lock_bh(&local
->sub_if_lock
);
1227 memcpy(bss_devs
, local
->bss_devs
,
1228 bss_count
* sizeof(struct net_device
*));
1229 memset(&bss_devs
[bss_count
], 0,
1230 (new_count
- bss_count
) * sizeof(struct net_device
*));
1232 memcpy(conf
->bssid_mask
, param
->u
.set_bss
.bssid_mask
, ETH_ALEN
);
1234 prev
= local
->bss_devs
;
1235 local
->bss_devs
= bss_devs
;
1236 conf
->bss_count
= new_count
;
1238 memcpy(sta_devs
, local
->sta_devs
,
1239 bss_count
* sizeof(struct net_device
*));
1240 memset(&sta_devs
[bss_count
], 0,
1241 (new_count
- bss_count
) * sizeof(struct net_device
*));
1242 prev_sta_devs
= local
->sta_devs
;
1243 local
->sta_devs
= sta_devs
;
1245 spin_unlock_bh(&local
->sub_if_lock
);
1247 kfree(prev_sta_devs
);
1249 return ieee80211_hw_config(dev
);
1253 static int ieee80211_ioctl_set_channel_flag(struct net_device
*dev
,
1254 struct prism2_hostapd_param
*param
)
1256 struct ieee80211_local
*local
= dev
->priv
;
1257 struct ieee80211_hw_modes
*mode
= NULL
;
1258 struct ieee80211_channel
*chan
= NULL
;
1261 for (i
= 0; i
< local
->hw
->num_modes
; i
++) {
1262 mode
= &local
->hw
->modes
[i
];
1263 if (mode
->mode
== param
->u
.set_channel_flag
.mode
)
1271 for (i
= 0; i
< mode
->num_channels
; i
++) {
1272 chan
= &mode
->channels
[i
];
1273 if (chan
->chan
== param
->u
.set_channel_flag
.chan
)
1281 chan
->flag
= param
->u
.set_channel_flag
.flag
;
1282 chan
->power_level
= param
->u
.set_channel_flag
.power_level
;
1283 chan
->antenna_max
= param
->u
.set_channel_flag
.antenna_max
;
1289 static int ieee80211_ioctl_set_quiet_params(struct net_device
*dev
,
1290 struct prism2_hostapd_param
*param
)
1292 struct ieee80211_conf
*conf
= ieee80211_get_hw_conf(dev
);
1293 conf
->quiet_duration
= param
->u
.quiet
.duration
;
1294 conf
->quiet_offset
= param
->u
.quiet
.offset
;
1295 conf
->quiet_period
= param
->u
.quiet
.period
;
1300 static int ieee80211_ioctl_set_radar_params(struct net_device
*dev
,
1301 struct prism2_hostapd_param
*param
)
1303 /* struct ieee80211_conf *conf = ieee80211_get_hw_conf(dev); */
1308 static int ieee80211_ioctl_priv_hostapd(struct net_device
*dev
,
1311 struct prism2_hostapd_param
*param
;
1314 if (p
->length
< sizeof(struct prism2_hostapd_param
) ||
1315 p
->length
> PRISM2_HOSTAPD_MAX_BUF_SIZE
|| !p
->pointer
) {
1316 printk(KERN_DEBUG
"%s: hostapd ioctl: ptr=%p len=%d min=%d "
1317 "max=%d\n", dev
->name
, p
->pointer
, p
->length
,
1318 (int)sizeof(struct prism2_hostapd_param
),
1319 PRISM2_HOSTAPD_MAX_BUF_SIZE
);
1323 param
= (struct prism2_hostapd_param
*) kmalloc(p
->length
, GFP_KERNEL
);
1327 if (copy_from_user(param
, p
->pointer
, p
->length
)) {
1332 switch (param
->cmd
) {
1333 case PRISM2_HOSTAPD_FLUSH
:
1334 ret
= ieee80211_ioctl_flush(dev
, param
);
1336 case PRISM2_HOSTAPD_ADD_STA
:
1337 ret
= ieee80211_ioctl_add_sta(dev
, param
);
1339 case PRISM2_HOSTAPD_REMOVE_STA
:
1340 ret
= ieee80211_ioctl_remove_sta(dev
, param
);
1342 case PRISM2_HOSTAPD_GET_INFO_STA
:
1343 ret
= ieee80211_ioctl_get_info_sta(dev
, param
);
1345 case PRISM2_SET_ENCRYPTION
:
1346 ret
= ieee80211_ioctl_set_encryption(dev
, param
, p
->length
);
1348 case PRISM2_GET_ENCRYPTION
:
1349 ret
= ieee80211_ioctl_get_encryption(dev
, param
, p
->length
);
1351 case PRISM2_HOSTAPD_SET_FLAGS_STA
:
1352 ret
= ieee80211_ioctl_set_flags_sta(dev
, param
);
1354 case PRISM2_HOSTAPD_SET_BEACON
:
1355 ret
= ieee80211_ioctl_set_beacon(dev
, param
, p
->length
, 0);
1357 case PRISM2_HOSTAPD_GET_HW_FEATURES
:
1358 ret
= ieee80211_ioctl_get_hw_features(dev
, param
, p
->length
);
1360 case PRISM2_HOSTAPD_SCAN
:
1361 ret
= ieee80211_ioctl_scan(dev
, param
);
1363 #ifdef CONFIG_HOSTAPD_WPA_TESTING
1364 case PRISM2_HOSTAPD_WPA_TRIGGER
:
1365 ret
= ieee80211_ioctl_wpa_trigger(dev
, param
);
1367 #endif /* CONFIG_HOSTAPD_WPA_TESTING */
1368 case PRISM2_HOSTAPD_SET_RATE_SETS
:
1369 ret
= ieee80211_ioctl_set_rate_sets(dev
, param
, p
->length
);
1371 case PRISM2_HOSTAPD_ADD_IF
:
1372 ret
= ieee80211_ioctl_add_if(dev
, param
, p
->length
);
1374 case PRISM2_HOSTAPD_REMOVE_IF
:
1375 ret
= ieee80211_ioctl_remove_if(dev
, param
);
1377 case PRISM2_HOSTAPD_GET_DOT11COUNTERSTABLE
:
1378 ret
= ieee80211_ioctl_get_dot11counterstable(dev
, param
);
1380 case PRISM2_HOSTAPD_GET_LOAD_STATS
:
1381 ret
= ieee80211_ioctl_get_load_stats(dev
, param
);
1383 case PRISM2_HOSTAPD_SET_STA_VLAN
:
1384 ret
= ieee80211_ioctl_set_sta_vlan(dev
, param
);
1386 case PRISM2_HOSTAPD_SET_GENERIC_INFO_ELEM
:
1387 ret
= ieee80211_ioctl_set_generic_info_elem(dev
, param
,
1390 case PRISM2_HOSTAPD_SET_CHANNEL_FLAG
:
1391 ret
= ieee80211_ioctl_set_channel_flag(dev
, param
);
1393 case PRISM2_HOSTAPD_SET_REGULATORY_DOMAIN
:
1394 ret
= ieee80211_ioctl_set_regulatory_domain(dev
, param
);
1396 case PRISM2_HOSTAPD_SET_TX_QUEUE_PARAMS
:
1397 ret
= ieee80211_ioctl_set_tx_queue_params(dev
, param
);
1399 case PRISM2_HOSTAPD_SET_BSS
:
1400 ret
= ieee80211_ioctl_set_bss(dev
, param
);
1402 case PRISM2_HOSTAPD_GET_TX_STATS
:
1403 ret
= ieee80211_ioctl_get_tx_stats(dev
, param
);
1405 case PRISM2_HOSTAPD_UPDATE_IF
:
1406 ret
= ieee80211_ioctl_update_if(dev
, param
, p
->length
);
1408 case PRISM2_HOSTAPD_SCAN_REQ
:
1409 ret
= ieee80211_ioctl_scan_req(dev
, param
, p
->length
);
1411 case PRISM2_STA_GET_STATE
:
1412 ret
= ieee80211_ioctl_sta_get_state(dev
, param
);
1414 case PRISM2_HOSTAPD_MLME
:
1415 ret
= ieee80211_ioctl_mlme(dev
, param
);
1417 case PRISM2_HOSTAPD_FLUSH_IFS
:
1418 ret
= ieee80211_ioctl_flush_ifs(dev
, param
);
1420 case PRISM2_HOSTAPD_SET_RADAR_PARAMS
:
1421 ret
= ieee80211_ioctl_set_radar_params(dev
, param
);
1423 case PRISM2_HOSTAPD_SET_QUIET_PARAMS
:
1424 ret
= ieee80211_ioctl_set_quiet_params(dev
, param
);
1431 if (copy_to_user(p
->pointer
, param
, p
->length
))
1441 static int ieee80211_ioctl_giwname(struct net_device
*dev
,
1442 struct iw_request_info
*info
,
1443 char *name
, char *extra
)
1445 struct ieee80211_local
*local
= dev
->priv
;
1447 switch (local
->conf
.phymode
) {
1448 case MODE_IEEE80211A
:
1449 strcpy(name
, "IEEE 802.11a");
1451 case MODE_IEEE80211B
:
1452 strcpy(name
, "IEEE 802.11b");
1454 case MODE_IEEE80211G
:
1455 strcpy(name
, "IEEE 802.11g");
1457 case MODE_ATHEROS_TURBO
:
1458 strcpy(name
, "5GHz Turbo");
1461 strcpy(name
, "IEEE 802.11");
1469 static int ieee80211_ioctl_giwrange(struct net_device
*dev
,
1470 struct iw_request_info
*info
,
1471 struct iw_point
*data
, char *extra
)
1473 struct iw_range
*range
= (struct iw_range
*) extra
;
1475 data
->length
= sizeof(struct iw_range
);
1476 memset(range
, 0, sizeof(struct iw_range
));
1478 range
->we_version_compiled
= WIRELESS_EXT
;
1479 range
->we_version_source
= 14;
1480 range
->retry_capa
= IW_RETRY_LIMIT
;
1481 range
->retry_flags
= IW_RETRY_LIMIT
;
1482 range
->min_retry
= 0;
1483 range
->max_retry
= 255;
1485 range
->max_rts
= 2347;
1486 range
->min_frag
= 256;
1487 range
->max_frag
= 2346;
1493 struct ieee80211_channel_range
{
1496 unsigned char power_level
;
1497 unsigned char antenna_max
;
1500 static const struct ieee80211_channel_range ieee80211_fcc_channels
[] = {
1501 { 2412, 2462, 27, 6 } /* IEEE 802.11b/g, channels 1..11 */,
1502 { 5180, 5240, 17, 6 } /* IEEE 802.11a, channels 36..48 */,
1503 { 5260, 5320, 23, 6 } /* IEEE 802.11a, channels 52..64 */,
1504 { 5745, 5825, 30, 6 } /* IEEE 802.11a, channels 149..165, outdoor */,
1508 static const struct ieee80211_channel_range ieee80211_mkk_channels
[] = {
1509 { 2412, 2472, 20, 6 } /* IEEE 802.11b/g, channels 1..13 */,
1510 { 5170, 5240, 20, 6 } /* IEEE 802.11a, channels 34..48 */,
1511 { 5260, 5320, 20, 6 } /* IEEE 802.11a, channels 52..64 */,
1516 static const struct ieee80211_channel_range
*channel_range
=
1517 ieee80211_fcc_channels
;
1520 static void ieee80211_unmask_channel(struct net_device
*dev
, int mode
,
1521 struct ieee80211_channel
*chan
)
1527 if (ieee80211_regdom
== 64 &&
1528 (mode
== MODE_ATHEROS_TURBO
|| mode
== MODE_ATHEROS_TURBOG
)) {
1529 /* Do not allow Turbo modes in Japan. */
1533 for (i
= 0; channel_range
[i
].start_freq
; i
++) {
1534 const struct ieee80211_channel_range
*r
= &channel_range
[i
];
1535 if (r
->start_freq
<= chan
->freq
&& r
->end_freq
>= chan
->freq
) {
1536 if (ieee80211_regdom
== 64 && !ieee80211_japan_5ghz
&&
1537 chan
->freq
>= 5260 && chan
->freq
<= 5320) {
1539 * Skip new channels in Japan since the
1540 * firmware was not marked having been upgraded
1546 if (ieee80211_regdom
== 0x10 &&
1547 (chan
->freq
== 5190 || chan
->freq
== 5210 ||
1548 chan
->freq
== 5230)) {
1549 /* Skip MKK channels when in FCC domain. */
1553 chan
->flag
|= IEEE80211_CHAN_W_SCAN
|
1554 IEEE80211_CHAN_W_ACTIVE_SCAN
|
1555 IEEE80211_CHAN_W_IBSS
;
1556 chan
->power_level
= r
->power_level
;
1557 chan
->antenna_max
= r
->antenna_max
;
1559 if (ieee80211_regdom
== 64 &&
1560 (chan
->freq
== 5170 || chan
->freq
== 5190 ||
1561 chan
->freq
== 5210 || chan
->freq
== 5230)) {
1563 * New regulatory rules in Japan have backwards
1564 * compatibility with old channels in 5.15-5.25
1565 * GHz band, but the station is not allowed to
1566 * use active scan on these old channels.
1568 chan
->flag
&= ~IEEE80211_CHAN_W_ACTIVE_SCAN
;
1571 if (ieee80211_regdom
== 64 &&
1572 (chan
->freq
== 5260 || chan
->freq
== 5280 ||
1573 chan
->freq
== 5300 || chan
->freq
== 5320)) {
1575 * IBSS is not allowed on 5.25-5.35 GHz band
1576 * due to radar detection requirements.
1578 chan
->flag
&= ~IEEE80211_CHAN_W_IBSS
;
1587 static int ieee80211_unmask_channels(struct net_device
*dev
)
1589 struct ieee80211_local
*local
= dev
->priv
;
1592 for (m
= 0; m
< local
->hw
->num_modes
; m
++) {
1593 struct ieee80211_hw_modes
*mode
= &local
->hw
->modes
[m
];
1594 for (c
= 0; c
< mode
->num_channels
; c
++) {
1595 ieee80211_unmask_channel(dev
, mode
->mode
,
1596 &mode
->channels
[c
]);
1603 static int ieee80211_init_client(struct net_device
*dev
)
1605 if (ieee80211_regdom
== 0x40)
1606 channel_range
= ieee80211_mkk_channels
;
1607 ieee80211_unmask_channels(dev
);
1608 ieee80211_ioctl_set_adm_status(dev
, 1);
1613 static int ieee80211_is_client_mode(int iw_mode
)
1615 return (iw_mode
== IW_MODE_INFRA
|| iw_mode
== IW_MODE_ADHOC
);
1619 static int ieee80211_ioctl_siwmode(struct net_device
*dev
,
1620 struct iw_request_info
*info
,
1621 __u32
*mode
, char *extra
)
1623 struct ieee80211_local
*local
= dev
->priv
;
1625 if (!ieee80211_is_client_mode(local
->conf
.mode
) &&
1626 ieee80211_is_client_mode(*mode
)) {
1627 ieee80211_init_client(dev
);
1629 if (local
->conf
.mode
!= *mode
) {
1630 struct ieee80211_sub_if_data
*sdata
=
1631 IEEE80211_DEV_TO_SUB_IF(dev
);
1632 sta_info_flush(local
, NULL
);
1633 if (local
->conf
.mode
== IW_MODE_ADHOC
&&
1634 sdata
->type
== IEEE80211_SUB_IF_TYPE_STA
) {
1635 /* Clear drop_unencrypted when leaving adhoc mode since
1636 * only adhoc mode is using automatic setting for this
1638 sdata
->drop_unencrypted
= 0;
1640 if (*mode
== IW_MODE_MASTER
) {
1641 /* AP mode does not currently use ACM bits to limit
1642 * TX, so clear the bitfield here. */
1646 local
->conf
.mode
= *mode
;
1647 return ieee80211_hw_config(dev
);
1651 static int ieee80211_ioctl_giwmode(struct net_device
*dev
,
1652 struct iw_request_info
*info
,
1653 __u32
*mode
, char *extra
)
1655 struct ieee80211_local
*local
= dev
->priv
;
1656 struct ieee80211_sub_if_data
*sdata
;
1658 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1659 if (sdata
->type
== IEEE80211_SUB_IF_TYPE_STA
) {
1660 if (local
->conf
.mode
== IW_MODE_ADHOC
)
1661 *mode
= IW_MODE_ADHOC
;
1663 *mode
= IW_MODE_INFRA
;
1665 *mode
= local
->conf
.mode
;
1670 int ieee80211_ioctl_siwfreq(struct net_device
*dev
,
1671 struct iw_request_info
*info
,
1672 struct iw_freq
*freq
, char *extra
)
1674 struct ieee80211_local
*local
= dev
->priv
;
1675 int m
, c
, nfreq
, set
= 0;
1677 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
1681 int i
, div
= 1000000;
1682 for (i
= 0; i
< freq
->e
; i
++)
1685 nfreq
= freq
->m
/ div
;
1690 for (m
= 0; m
< local
->hw
->num_modes
; m
++) {
1691 struct ieee80211_hw_modes
*mode
= &local
->hw
->modes
[m
];
1692 for (c
= 0; c
< mode
->num_channels
; c
++) {
1693 struct ieee80211_channel
*chan
= &mode
->channels
[c
];
1694 if (chan
->flag
& IEEE80211_CHAN_W_SCAN
&&
1695 ((freq
->e
== 0 && chan
->chan
== freq
->m
) ||
1696 (freq
->e
> 0 && nfreq
== chan
->freq
)) &&
1697 (local
->hw_modes
& (1 << mode
->mode
))) {
1698 /* Use next_mode as the mode preference to
1699 * resolve non-unique channel numbers. */
1700 if (set
&& mode
->mode
!= local
->next_mode
)
1703 local
->conf
.channel
= chan
->chan
;
1704 local
->conf
.channel_val
= chan
->val
;
1705 local
->conf
.power_level
= chan
->power_level
;
1706 local
->conf
.freq
= chan
->freq
;
1707 local
->conf
.phymode
= mode
->mode
;
1708 local
->conf
.antenna_max
= chan
->antenna_max
;
1715 local
->sta_scanning
= 0; /* Abort possible scan */
1716 return ieee80211_hw_config(dev
);
1723 static int ieee80211_ioctl_giwfreq(struct net_device
*dev
,
1724 struct iw_request_info
*info
,
1725 struct iw_freq
*freq
, char *extra
)
1727 struct ieee80211_local
*local
= dev
->priv
;
1729 /* TODO: in station mode (Managed/Ad-hoc) might need to poll low-level
1730 * driver for the current channel with firmware-based management */
1732 freq
->m
= local
->conf
.freq
;
1739 static int ieee80211_ioctl_siwessid(struct net_device
*dev
,
1740 struct iw_request_info
*info
,
1741 struct iw_point
*data
, char *ssid
)
1743 struct ieee80211_local
*local
= dev
->priv
;
1744 struct ieee80211_sub_if_data
*sdata
;
1745 size_t len
= data
->length
;
1747 /* iwconfig uses nul termination in SSID.. */
1748 if (len
> 0 && ssid
[len
- 1] == '\0')
1751 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1752 if (sdata
->type
== IEEE80211_SUB_IF_TYPE_STA
)
1753 return ieee80211_sta_set_ssid(dev
, ssid
, len
);
1755 kfree(local
->conf
.ssid
);
1756 local
->conf
.ssid
= kmalloc(len
+ 1, GFP_KERNEL
);
1757 if (local
->conf
.ssid
== NULL
)
1759 memcpy(local
->conf
.ssid
, ssid
, len
);
1760 local
->conf
.ssid
[len
] = '\0';
1761 local
->conf
.ssid_len
= len
;
1762 return ieee80211_hw_config(dev
);
1766 static int ieee80211_ioctl_giwessid(struct net_device
*dev
,
1767 struct iw_request_info
*info
,
1768 struct iw_point
*data
, char *ssid
)
1770 struct ieee80211_local
*local
= dev
->priv
;
1773 struct ieee80211_sub_if_data
*sdata
;
1774 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1775 if (sdata
->type
== IEEE80211_SUB_IF_TYPE_STA
) {
1776 int res
= ieee80211_sta_get_ssid(dev
, ssid
, &len
);
1782 len
= local
->conf
.ssid_len
;
1783 if (len
> IW_ESSID_MAX_SIZE
)
1784 len
= IW_ESSID_MAX_SIZE
;
1785 memcpy(ssid
, local
->conf
.ssid
, len
);
1791 static int ieee80211_ioctl_siwap(struct net_device
*dev
,
1792 struct iw_request_info
*info
,
1793 struct sockaddr
*ap_addr
, char *extra
)
1795 struct ieee80211_local
*local
= dev
->priv
;
1796 struct ieee80211_sub_if_data
*sdata
;
1798 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1799 if (sdata
->type
== IEEE80211_SUB_IF_TYPE_STA
) {
1800 int changed_bssid
= 0;
1801 if (memcmp(local
->conf
.client_bssid
, (u8
*) &ap_addr
->sa_data
,
1804 memcpy(local
->conf
.client_bssid
, (u8
*) &ap_addr
->sa_data
,
1806 if (changed_bssid
&& ieee80211_hw_config(dev
)) {
1807 printk(KERN_DEBUG
"%s: Failed to config new BSSID to "
1808 "the low-level driver\n", dev
->name
);
1810 return ieee80211_sta_set_bssid(dev
, (u8
*) &ap_addr
->sa_data
);
1817 static int ieee80211_ioctl_giwap(struct net_device
*dev
,
1818 struct iw_request_info
*info
,
1819 struct sockaddr
*ap_addr
, char *extra
)
1821 struct ieee80211_sub_if_data
*sdata
;
1823 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1824 if (sdata
->type
== IEEE80211_SUB_IF_TYPE_STA
) {
1825 ap_addr
->sa_family
= ARPHRD_ETHER
;
1826 memcpy(&ap_addr
->sa_data
, sdata
->u
.sta
.bssid
, ETH_ALEN
);
1834 static int ieee80211_ioctl_siwscan(struct net_device
*dev
,
1835 struct iw_request_info
*info
,
1836 struct iw_point
*data
, char *extra
)
1838 struct ieee80211_local
*local
= dev
->priv
;
1840 size_t ssid_len
= 0;
1842 if (local
->scan_flags
& IEEE80211_SCAN_MATCH_SSID
) {
1843 ssid
= local
->conf
.ssid
;
1844 ssid_len
= local
->conf
.ssid_len
;
1846 return ieee80211_sta_req_scan(dev
, ssid
, ssid_len
);
1850 static int ieee80211_ioctl_giwscan(struct net_device
*dev
,
1851 struct iw_request_info
*info
,
1852 struct iw_point
*data
, char *extra
)
1855 struct ieee80211_local
*local
= dev
->priv
;
1856 if (local
->sta_scanning
)
1858 res
= ieee80211_sta_scan_results(dev
, extra
, IW_SCAN_MAX_DATA
);
1868 static int ieee80211_ioctl_siwrts(struct net_device
*dev
,
1869 struct iw_request_info
*info
,
1870 struct iw_param
*rts
, char *extra
)
1872 struct ieee80211_local
*local
= dev
->priv
;
1875 local
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
1876 else if (rts
->value
< 0 || rts
->value
> IEEE80211_MAX_RTS_THRESHOLD
)
1879 local
->rts_threshold
= rts
->value
;
1881 /* If the wlan card performs RTS/CTS in hardware/firmware,
1882 * configure it here */
1884 if (local
->hw
->set_rts_threshold
) {
1885 local
->hw
->set_rts_threshold(dev
, local
->rts_threshold
);
1891 static int ieee80211_ioctl_giwrts(struct net_device
*dev
,
1892 struct iw_request_info
*info
,
1893 struct iw_param
*rts
, char *extra
)
1895 struct ieee80211_local
*local
= dev
->priv
;
1897 rts
->value
= local
->rts_threshold
;
1898 rts
->disabled
= (rts
->value
>= IEEE80211_MAX_RTS_THRESHOLD
);
1905 static int ieee80211_ioctl_siwfrag(struct net_device
*dev
,
1906 struct iw_request_info
*info
,
1907 struct iw_param
*frag
, char *extra
)
1909 struct ieee80211_local
*local
= dev
->priv
;
1912 local
->fragmentation_threshold
= IEEE80211_MAX_FRAG_THRESHOLD
;
1913 else if (frag
->value
< 256 ||
1914 frag
->value
> IEEE80211_MAX_FRAG_THRESHOLD
)
1917 /* Fragment length must be even, so strip LSB. */
1918 local
->fragmentation_threshold
= frag
->value
& ~0x1;
1921 /* If the wlan card performs fragmentation in hardware/firmware,
1922 * configure it here */
1924 if (local
->hw
->set_frag_threshold
) {
1925 local
->hw
->set_frag_threshold(
1926 dev
, local
->fragmentation_threshold
);
1932 static int ieee80211_ioctl_giwfrag(struct net_device
*dev
,
1933 struct iw_request_info
*info
,
1934 struct iw_param
*frag
, char *extra
)
1936 struct ieee80211_local
*local
= dev
->priv
;
1938 frag
->value
= local
->fragmentation_threshold
;
1939 frag
->disabled
= (frag
->value
>= IEEE80211_MAX_RTS_THRESHOLD
);
1946 static int ieee80211_ioctl_siwretry(struct net_device
*dev
,
1947 struct iw_request_info
*info
,
1948 struct iw_param
*retry
, char *extra
)
1950 struct ieee80211_local
*local
= dev
->priv
;
1952 if (retry
->disabled
||
1953 (retry
->flags
& IW_RETRY_TYPE
) != IW_RETRY_LIMIT
)
1956 if (retry
->flags
& IW_RETRY_MAX
)
1957 local
->long_retry_limit
= retry
->value
;
1958 else if (retry
->flags
& IW_RETRY_MIN
)
1959 local
->short_retry_limit
= retry
->value
;
1961 local
->long_retry_limit
= retry
->value
;
1962 local
->short_retry_limit
= retry
->value
;
1965 if (local
->hw
->set_retry_limit
) {
1966 return local
->hw
->set_retry_limit(
1967 dev
, local
->short_retry_limit
,
1968 local
->long_retry_limit
);
1975 static int ieee80211_ioctl_giwretry(struct net_device
*dev
,
1976 struct iw_request_info
*info
,
1977 struct iw_param
*retry
, char *extra
)
1979 struct ieee80211_local
*local
= dev
->priv
;
1981 retry
->disabled
= 0;
1982 if ((retry
->flags
& IW_RETRY_TYPE
) != IW_RETRY_LIMIT
)
1984 if (retry
->flags
& IW_RETRY_MAX
) {
1985 retry
->flags
= IW_RETRY_LIMIT
| IW_RETRY_MAX
;
1986 retry
->value
= local
->long_retry_limit
;
1988 retry
->flags
= IW_RETRY_LIMIT
;
1989 retry
->value
= local
->short_retry_limit
;
1990 if (local
->long_retry_limit
!= local
->short_retry_limit
)
1991 retry
->flags
|= IW_RETRY_MIN
;
1998 static void ieee80211_ioctl_unmask_channels(struct ieee80211_local
*local
)
2002 for (m
= 0; m
< local
->hw
->num_modes
; m
++) {
2003 struct ieee80211_hw_modes
*mode
= &local
->hw
->modes
[m
];
2004 for (c
= 0; c
< mode
->num_channels
; c
++) {
2005 struct ieee80211_channel
*chan
= &mode
->channels
[c
];
2006 chan
->flag
|= IEEE80211_CHAN_W_SCAN
;
2012 static int ieee80211_ioctl_test_mode(struct net_device
*dev
, int mode
)
2014 struct ieee80211_local
*local
= dev
->priv
;
2015 int ret
= -EOPNOTSUPP
;
2017 if (mode
== IEEE80211_TEST_UNMASK_CHANNELS
) {
2018 ieee80211_ioctl_unmask_channels(local
);
2022 if (local
->hw
->test_mode
)
2023 ret
= local
->hw
->test_mode(dev
, mode
);
2029 static int ieee80211_ioctl_clear_keys(struct net_device
*dev
)
2031 struct ieee80211_local
*local
= dev
->priv
;
2032 struct ieee80211_key_conf key
;
2033 struct list_head
*ptr
;
2036 struct ieee80211_key_conf
*keyconf
;
2038 memset(addr
, 0xff, ETH_ALEN
);
2039 list_for_each(ptr
, &local
->sub_if_list
) {
2040 struct ieee80211_sub_if_data
*sdata
=
2041 list_entry(ptr
, struct ieee80211_sub_if_data
, list
);
2042 for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
2044 if (sdata
->keys
[i
] &&
2045 !sdata
->keys
[i
]->force_sw_encrypt
&&
2046 local
->hw
->set_key
&&
2047 (keyconf
= ieee80211_key_data2conf(local
,
2050 local
->hw
->set_key(dev
, DISABLE_KEY
, addr
,
2053 kfree(sdata
->keys
[i
]);
2054 sdata
->keys
[i
] = NULL
;
2056 sdata
->default_key
= NULL
;
2059 spin_lock_bh(&local
->sta_lock
);
2060 list_for_each(ptr
, &local
->sta_list
) {
2061 struct sta_info
*sta
=
2062 list_entry(ptr
, struct sta_info
, list
);
2064 if (sta
->key
&& !sta
->key
->force_sw_encrypt
&&
2065 local
->hw
->set_key
&&
2066 (keyconf
= ieee80211_key_data2conf(local
, sta
->key
))
2068 local
->hw
->set_key(dev
, DISABLE_KEY
, sta
->addr
,
2074 spin_unlock_bh(&local
->sta_lock
);
2077 memset(&key
, 0, sizeof(key
));
2078 if (local
->hw
->set_key
&&
2079 local
->hw
->set_key(dev
, REMOVE_ALL_KEYS
, NULL
,
2081 printk(KERN_DEBUG
"%s: failed to remove hwaccel keys\n",
2089 ieee80211_ioctl_force_unicast_rate(struct net_device
*dev
,
2090 struct ieee80211_sub_if_data
*sdata
,
2093 struct ieee80211_local
*local
= dev
->priv
;
2096 if (sdata
->type
!= IEEE80211_SUB_IF_TYPE_NORM
)
2100 sdata
->u
.norm
.force_unicast_rateidx
= -1;
2104 for (i
= 0; i
< local
->num_curr_rates
; i
++) {
2105 if (local
->curr_rates
[i
].rate
== rate
) {
2106 sdata
->u
.norm
.force_unicast_rateidx
= i
;
2115 ieee80211_ioctl_max_ratectrl_rate(struct net_device
*dev
,
2116 struct ieee80211_sub_if_data
*sdata
,
2119 struct ieee80211_local
*local
= dev
->priv
;
2122 if (sdata
->type
!= IEEE80211_SUB_IF_TYPE_NORM
)
2126 sdata
->u
.norm
.max_ratectrl_rateidx
= -1;
2130 for (i
= 0; i
< local
->num_curr_rates
; i
++) {
2131 if (local
->curr_rates
[i
].rate
== rate
) {
2132 sdata
->u
.norm
.max_ratectrl_rateidx
= i
;
2140 static void ieee80211_key_enable_hwaccel(struct ieee80211_local
*local
,
2141 struct ieee80211_key
*key
)
2143 struct ieee80211_key_conf
*keyconf
;
2146 if (key
== NULL
|| key
->alg
!= ALG_WEP
|| !key
->force_sw_encrypt
||
2147 local
->hw
->device_hides_wep
)
2150 memset(addr
, 0xff, ETH_ALEN
);
2151 keyconf
= ieee80211_key_data2conf(local
, key
);
2152 if (keyconf
&& local
->hw
->set_key
&&
2153 local
->hw
->set_key(local
->mdev
, SET_KEY
, addr
, keyconf
, 0) == 0) {
2154 key
->force_sw_encrypt
= keyconf
->force_sw_encrypt
;
2155 key
->hw_key_idx
= keyconf
->hw_key_idx
;
2161 static void ieee80211_key_disable_hwaccel(struct ieee80211_local
*local
,
2162 struct ieee80211_key
*key
)
2164 struct ieee80211_key_conf
*keyconf
;
2167 if (key
== NULL
|| key
->alg
!= ALG_WEP
|| key
->force_sw_encrypt
||
2168 local
->hw
->device_hides_wep
)
2171 memset(addr
, 0xff, ETH_ALEN
);
2172 keyconf
= ieee80211_key_data2conf(local
, key
);
2173 if (keyconf
&& local
->hw
->set_key
)
2174 local
->hw
->set_key(local
->mdev
, DISABLE_KEY
, addr
, keyconf
, 0);
2176 key
->force_sw_encrypt
= 1;
2180 static int ieee80211_ioctl_default_wep_only(struct ieee80211_local
*local
,
2184 struct list_head
*ptr
;
2186 local
->default_wep_only
= value
;
2187 list_for_each(ptr
, &local
->sub_if_list
) {
2188 struct ieee80211_sub_if_data
*sdata
=
2189 list_entry(ptr
, struct ieee80211_sub_if_data
, list
);
2190 for (i
= 0; i
< NUM_DEFAULT_KEYS
; i
++) {
2192 ieee80211_key_enable_hwaccel(local
,
2195 ieee80211_key_disable_hwaccel(local
,
2205 static int ieee80211_ioctl_prism2_param(struct net_device
*dev
,
2206 struct iw_request_info
*info
,
2207 void *wrqu
, char *extra
)
2209 struct ieee80211_local
*local
= dev
->priv
;
2210 struct ieee80211_sub_if_data
*sdata
;
2211 int *i
= (int *) extra
;
2213 int value
= *(i
+ 1);
2216 if (!capable(CAP_NET_ADMIN
))
2219 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2222 case PRISM2_PARAM_HOST_ENCRYPT
:
2223 case PRISM2_PARAM_HOST_DECRYPT
:
2224 /* TODO: implement these; return success now to prevent
2225 * hostapd from aborting */
2228 case PRISM2_PARAM_BEACON_INT
:
2229 local
->conf
.beacon_int
= value
;
2230 if (ieee80211_hw_config(dev
))
2234 case PRISM2_PARAM_AP_BRIDGE_PACKETS
:
2235 local
->bridge_packets
= value
;
2238 case PRISM2_PARAM_AP_AUTH_ALGS
:
2239 if (sdata
->type
== IEEE80211_SUB_IF_TYPE_STA
) {
2240 sdata
->u
.sta
.auth_algs
= value
;
2245 case PRISM2_PARAM_DTIM_PERIOD
:
2248 else if (sdata
->type
!= IEEE80211_SUB_IF_TYPE_NORM
)
2251 sdata
->u
.norm
.dtim_period
= value
;
2254 case PRISM2_PARAM_IEEE_802_1X
:
2255 sdata
->ieee802_1x
= value
;
2256 if (local
->hw
->set_ieee8021x
&&
2257 local
->hw
->set_ieee8021x(dev
, value
))
2258 printk(KERN_DEBUG
"%s: failed to set IEEE 802.1X (%d) "
2259 "for low-level driver\n", dev
->name
, value
);
2262 case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES
:
2263 local
->cts_protect_erp_frames
= value
;
2266 case PRISM2_PARAM_DROP_UNENCRYPTED
:
2267 sdata
->drop_unencrypted
= value
;
2270 case PRISM2_PARAM_PREAMBLE
:
2271 local
->short_preamble
= value
;
2274 case PRISM2_PARAM_RATE_LIMIT_BURST
:
2275 local
->rate_limit_burst
= value
;
2276 local
->rate_limit_bucket
= value
;
2279 case PRISM2_PARAM_RATE_LIMIT
:
2280 /* number of packets (tokens) allowed per second */
2281 if (!local
->rate_limit
&& value
) {
2282 if (!local
->rate_limit_burst
) local
->rate_limit_burst
=
2284 local
->rate_limit_bucket
= local
->rate_limit_burst
;
2285 local
->rate_limit_timer
.expires
= jiffies
+ HZ
;
2286 add_timer(&local
->rate_limit_timer
);
2287 } else if (local
->rate_limit
&& !value
) {
2288 del_timer_sync(&local
->rate_limit_timer
);
2290 local
->rate_limit
= value
;
2293 case PRISM2_PARAM_STAT_TIME
:
2294 if (!local
->stat_time
&& value
) {
2295 local
->stat_timer
.expires
= jiffies
+ HZ
* value
/ 100;
2296 add_timer(&local
->stat_timer
);
2297 } else if (local
->stat_time
&& !value
) {
2298 del_timer_sync(&local
->stat_timer
);
2300 local
->stat_time
= value
;
2302 case PRISM2_PARAM_SHORT_SLOT_TIME
:
2303 local
->conf
.short_slot_time
= value
;
2304 if (ieee80211_hw_config(dev
))
2308 case PRISM2_PARAM_PRIVACY_INVOKED
:
2309 if (local
->hw
->set_privacy_invoked
)
2310 ret
= local
->hw
->set_privacy_invoked(dev
, value
);
2313 case PRISM2_PARAM_TEST_MODE
:
2314 ret
= ieee80211_ioctl_test_mode(dev
, value
);
2317 case PRISM2_PARAM_NEXT_MODE
:
2318 local
->next_mode
= value
;
2321 case PRISM2_PARAM_CLEAR_KEYS
:
2322 ret
= ieee80211_ioctl_clear_keys(dev
);
2325 case PRISM2_PARAM_ADM_STATUS
:
2326 ret
= ieee80211_ioctl_set_adm_status(dev
, value
);
2329 case PRISM2_PARAM_ANTENNA_SEL
:
2330 local
->conf
.antenna_sel
= value
;
2331 if (ieee80211_hw_config(dev
))
2335 case PRISM2_PARAM_CALIB_INT
:
2336 local
->conf
.calib_int
= value
;
2337 if (ieee80211_hw_config(dev
))
2341 case PRISM2_PARAM_ANTENNA_MODE
:
2342 local
->conf
.antenna_mode
= value
;
2343 if (ieee80211_hw_config(dev
))
2347 case PRISM2_PARAM_BROADCAST_SSID
:
2348 if ((value
< 0) || (value
> 1))
2351 local
->conf
.ssid_hidden
= value
;
2354 case PRISM2_PARAM_STA_ANTENNA_SEL
:
2355 local
->sta_antenna_sel
= value
;
2358 case PRISM2_PARAM_FORCE_UNICAST_RATE
:
2359 ret
= ieee80211_ioctl_force_unicast_rate(dev
, sdata
, value
);
2362 case PRISM2_PARAM_MAX_RATECTRL_RATE
:
2363 ret
= ieee80211_ioctl_max_ratectrl_rate(dev
, sdata
, value
);
2366 case PRISM2_PARAM_RATE_CTRL_NUM_UP
:
2367 local
->rate_ctrl_num_up
= value
;
2370 case PRISM2_PARAM_RATE_CTRL_NUM_DOWN
:
2371 local
->rate_ctrl_num_down
= value
;
2374 case PRISM2_PARAM_TX_POWER_REDUCTION
:
2378 local
->conf
.tx_power_reduction
= value
;
2381 case PRISM2_PARAM_EAPOL
:
2382 sdata
->eapol
= value
;
2385 case PRISM2_PARAM_KEY_TX_RX_THRESHOLD
:
2386 local
->key_tx_rx_threshold
= value
;
2389 case PRISM2_PARAM_KEY_INDEX
:
2390 if (value
< 0 || value
>= NUM_DEFAULT_KEYS
)
2392 else if (sdata
->keys
[value
] == NULL
)
2395 sdata
->default_key
= sdata
->keys
[value
];
2398 case PRISM2_PARAM_DEFAULT_WEP_ONLY
:
2399 ret
= ieee80211_ioctl_default_wep_only(local
, value
);
2402 case PRISM2_PARAM_WIFI_WME_NOACK_TEST
:
2403 local
->wifi_wme_noack_test
= value
;
2408 case PRISM2_PARAM_ALLOW_BROADCAST_ALWAYS
:
2409 local
->allow_broadcast_always
= value
;
2412 case PRISM2_PARAM_SCAN_FLAGS
:
2413 local
->scan_flags
= value
;
2416 case PRISM2_PARAM_MIXED_CELL
:
2417 if (sdata
->type
!= IEEE80211_SUB_IF_TYPE_STA
)
2420 sdata
->u
.sta
.mixed_cell
= !!value
;
2423 case PRISM2_PARAM_KEY_MGMT
:
2424 if (sdata
->type
!= IEEE80211_SUB_IF_TYPE_STA
)
2427 sdata
->u
.sta
.key_mgmt
= value
;
2430 case PRISM2_PARAM_HW_MODES
:
2431 local
->hw_modes
= value
;
2434 case PRISM2_PARAM_CREATE_IBSS
:
2435 if (sdata
->type
!= IEEE80211_SUB_IF_TYPE_STA
)
2438 sdata
->u
.sta
.create_ibss
= !!value
;
2440 case PRISM2_PARAM_WMM_ENABLED
:
2441 if (sdata
->type
!= IEEE80211_SUB_IF_TYPE_STA
)
2444 sdata
->u
.sta
.wmm_enabled
= !!value
;
2446 case PRISM2_PARAM_RADAR_DETECT
:
2447 local
->conf
.radar_detect
= value
;
2449 case PRISM2_PARAM_SPECTRUM_MGMT
:
2450 local
->conf
.spect_mgmt
= value
;
2461 static int ieee80211_ioctl_get_prism2_param(struct net_device
*dev
,
2462 struct iw_request_info
*info
,
2463 void *wrqu
, char *extra
)
2465 struct ieee80211_local
*local
= dev
->priv
;
2466 struct ieee80211_sub_if_data
*sdata
;
2467 int *param
= (int *) extra
;
2470 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2473 case PRISM2_PARAM_BEACON_INT
:
2474 *param
= local
->conf
.beacon_int
;
2477 case PRISM2_PARAM_AP_BRIDGE_PACKETS
:
2478 *param
= local
->bridge_packets
;
2481 case PRISM2_PARAM_AP_AUTH_ALGS
:
2482 if (sdata
->type
== IEEE80211_SUB_IF_TYPE_STA
) {
2483 *param
= sdata
->u
.sta
.auth_algs
;
2488 case PRISM2_PARAM_DTIM_PERIOD
:
2489 if (sdata
->type
!= IEEE80211_SUB_IF_TYPE_NORM
)
2492 *param
= sdata
->u
.norm
.dtim_period
;
2495 case PRISM2_PARAM_IEEE_802_1X
:
2496 *param
= sdata
->ieee802_1x
;
2499 case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES
:
2500 *param
= local
->cts_protect_erp_frames
;
2503 case PRISM2_PARAM_DROP_UNENCRYPTED
:
2504 *param
= sdata
->drop_unencrypted
;
2507 case PRISM2_PARAM_PREAMBLE
:
2508 *param
= local
->short_preamble
;
2511 case PRISM2_PARAM_RATE_LIMIT_BURST
:
2512 *param
= local
->rate_limit_burst
;
2515 case PRISM2_PARAM_RATE_LIMIT
:
2516 *param
= local
->rate_limit
;
2519 case PRISM2_PARAM_STAT_TIME
:
2520 *param
= local
->stat_time
;
2522 case PRISM2_PARAM_SHORT_SLOT_TIME
:
2523 *param
= local
->conf
.short_slot_time
;
2526 case PRISM2_PARAM_NEXT_MODE
:
2527 *param
= local
->next_mode
;
2530 case PRISM2_PARAM_ANTENNA_SEL
:
2531 *param
= local
->conf
.antenna_sel
;
2534 case PRISM2_PARAM_CALIB_INT
:
2535 *param
= local
->conf
.calib_int
;
2538 case PRISM2_PARAM_ANTENNA_MODE
:
2539 *param
= local
->conf
.antenna_mode
;
2542 case PRISM2_PARAM_BROADCAST_SSID
:
2543 *param
= local
->conf
.ssid_hidden
;
2546 case PRISM2_PARAM_STA_ANTENNA_SEL
:
2547 *param
= local
->sta_antenna_sel
;
2550 case PRISM2_PARAM_RATE_CTRL_NUM_UP
:
2551 *param
= local
->rate_ctrl_num_up
;
2554 case PRISM2_PARAM_RATE_CTRL_NUM_DOWN
:
2555 *param
= local
->rate_ctrl_num_down
;
2558 case PRISM2_PARAM_TX_POWER_REDUCTION
:
2559 *param
= local
->conf
.tx_power_reduction
;
2562 case PRISM2_PARAM_EAPOL
:
2563 *param
= sdata
->eapol
;
2566 case PRISM2_PARAM_KEY_TX_RX_THRESHOLD
:
2567 *param
= local
->key_tx_rx_threshold
;
2570 case PRISM2_PARAM_KEY_INDEX
:
2571 if (sdata
->default_key
== NULL
)
2573 else if (sdata
->default_key
== sdata
->keys
[0])
2575 else if (sdata
->default_key
== sdata
->keys
[1])
2577 else if (sdata
->default_key
== sdata
->keys
[2])
2579 else if (sdata
->default_key
== sdata
->keys
[3])
2585 case PRISM2_PARAM_DEFAULT_WEP_ONLY
:
2586 *param
= local
->default_wep_only
;
2589 case PRISM2_PARAM_WIFI_WME_NOACK_TEST
:
2590 *param
= local
->wifi_wme_noack_test
;
2595 case PRISM2_PARAM_ALLOW_BROADCAST_ALWAYS
:
2596 *param
= local
->allow_broadcast_always
;
2599 case PRISM2_PARAM_SCAN_FLAGS
:
2600 *param
= local
->scan_flags
;
2603 case PRISM2_PARAM_HW_MODES
:
2604 *param
= local
->hw_modes
;
2607 case PRISM2_PARAM_CREATE_IBSS
:
2608 if (sdata
->type
!= IEEE80211_SUB_IF_TYPE_STA
)
2611 *param
= !!sdata
->u
.sta
.create_ibss
;
2614 case PRISM2_PARAM_MIXED_CELL
:
2615 if (sdata
->type
!= IEEE80211_SUB_IF_TYPE_STA
)
2618 *param
= !!sdata
->u
.sta
.mixed_cell
;
2621 case PRISM2_PARAM_KEY_MGMT
:
2622 if (sdata
->type
!= IEEE80211_SUB_IF_TYPE_STA
)
2625 *param
= sdata
->u
.sta
.key_mgmt
;
2627 case PRISM2_PARAM_WMM_ENABLED
:
2628 if (sdata
->type
!= IEEE80211_SUB_IF_TYPE_STA
)
2631 *param
= !!sdata
->u
.sta
.wmm_enabled
;
2643 static int ieee80211_ioctl_test_param(struct net_device
*dev
,
2644 struct iw_request_info
*info
,
2645 void *wrqu
, char *extra
)
2647 struct ieee80211_local
*local
= dev
->priv
;
2648 int *i
= (int *) extra
;
2650 int value
= *(i
+ 1);
2652 if (!capable(CAP_NET_ADMIN
))
2655 if (local
->hw
->test_param
)
2656 return local
->hw
->test_param(local
->mdev
, param
, value
);
2662 static const struct iw_priv_args ieee80211_ioctl_priv
[] = {
2663 { PRISM2_IOCTL_PRISM2_PARAM
,
2664 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 2, 0, "param" },
2665 { PRISM2_IOCTL_GET_PRISM2_PARAM
,
2666 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
2667 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1, "get_param" },
2668 { PRISM2_IOCTL_TEST_PARAM
,
2669 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 2, 0, "test_param" },
2673 static int ieee80211_ioctl_giwpriv(struct net_device
*dev
,
2674 struct iw_point
*data
)
2677 if (!data
->pointer
||
2678 !access_ok(VERIFY_WRITE
, data
->pointer
,
2679 sizeof(ieee80211_ioctl_priv
)))
2682 data
->length
= sizeof(ieee80211_ioctl_priv
) /
2683 sizeof(ieee80211_ioctl_priv
[0]);
2684 if (copy_to_user(data
->pointer
, ieee80211_ioctl_priv
,
2685 sizeof(ieee80211_ioctl_priv
)))
2691 int ieee80211_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
2693 struct iwreq
*wrq
= (struct iwreq
*) rq
;
2695 char ssid
[IW_ESSID_MAX_SIZE
+ 1];
2699 ret
= ieee80211_ioctl_giwname(dev
, NULL
, (char *) &wrq
->u
,
2703 if (!wrq
->u
.essid
.pointer
)
2705 else if (wrq
->u
.essid
.length
> IW_ESSID_MAX_SIZE
)
2708 if (copy_from_user(ssid
, wrq
->u
.essid
.pointer
,
2709 wrq
->u
.essid
.length
)) {
2713 ret
= ieee80211_ioctl_siwessid(dev
, NULL
,
2714 &wrq
->u
.essid
, ssid
);
2718 if (!wrq
->u
.essid
.pointer
) {
2721 memset(ssid
, 0, IW_ESSID_MAX_SIZE
+ 1);
2722 ret
= ieee80211_ioctl_giwessid(dev
, NULL
,
2723 &wrq
->u
.essid
, ssid
);
2724 if (copy_to_user(wrq
->u
.essid
.pointer
, ssid
,
2725 wrq
->u
.essid
.length
)) {
2734 struct iw_range range
;
2735 if (!access_ok(VERIFY_WRITE
, wrq
->u
.data
.pointer
,
2740 ret
= ieee80211_ioctl_giwrange(dev
, NULL
, &wrq
->u
.data
,
2744 if (copy_to_user(wrq
->u
.data
.pointer
, &range
, sizeof(range
)))
2750 ret
= ieee80211_ioctl_siwap(dev
, NULL
, &wrq
->u
.ap_addr
, NULL
);
2753 ret
= ieee80211_ioctl_giwap(dev
, NULL
, &wrq
->u
.ap_addr
, NULL
);
2756 ret
= ieee80211_ioctl_siwscan(dev
, NULL
, &wrq
->u
.data
, NULL
);
2760 char *buf
= kmalloc(IW_SCAN_MAX_DATA
, GFP_KERNEL
);
2765 ret
= ieee80211_ioctl_giwscan(dev
, NULL
, &wrq
->u
.data
, buf
);
2767 copy_to_user(wrq
->u
.data
.pointer
, buf
, wrq
->u
.data
.length
))
2774 ret
= ieee80211_ioctl_siwfreq(dev
, NULL
, &wrq
->u
.freq
, NULL
);
2777 ret
= ieee80211_ioctl_giwfreq(dev
, NULL
, &wrq
->u
.freq
, NULL
);
2780 ret
= ieee80211_ioctl_siwmode(dev
, NULL
, &wrq
->u
.mode
, NULL
);
2783 ret
= ieee80211_ioctl_giwmode(dev
, NULL
, &wrq
->u
.mode
, NULL
);
2787 ret
= ieee80211_ioctl_siwrts(dev
, NULL
, &wrq
->u
.rts
, NULL
);
2790 ret
= ieee80211_ioctl_giwrts(dev
, NULL
, &wrq
->u
.rts
, NULL
);
2794 ret
= ieee80211_ioctl_siwfrag(dev
, NULL
, &wrq
->u
.frag
, NULL
);
2797 ret
= ieee80211_ioctl_giwfrag(dev
, NULL
, &wrq
->u
.frag
, NULL
);
2801 ret
= ieee80211_ioctl_siwretry(dev
, NULL
, &wrq
->u
.retry
, NULL
);
2804 ret
= ieee80211_ioctl_giwretry(dev
, NULL
, &wrq
->u
.retry
, NULL
);
2807 case PRISM2_IOCTL_PRISM2_PARAM
:
2808 ret
= ieee80211_ioctl_prism2_param(dev
, NULL
, &wrq
->u
,
2811 case PRISM2_IOCTL_GET_PRISM2_PARAM
:
2812 ret
= ieee80211_ioctl_get_prism2_param(dev
, NULL
, &wrq
->u
,
2815 case PRISM2_IOCTL_TEST_PARAM
:
2816 ret
= ieee80211_ioctl_test_param(dev
, NULL
, &wrq
->u
,
2819 case PRISM2_IOCTL_HOSTAPD
:
2820 if (!capable(CAP_NET_ADMIN
)) ret
= -EPERM
;
2821 else ret
= ieee80211_ioctl_priv_hostapd(dev
, &wrq
->u
.data
);
2824 ret
= ieee80211_ioctl_giwpriv(dev
, &wrq
->u
.data
);