1 /* Wireless extensions support.
3 * See copyright notice in main.c
5 #include <linux/kernel.h>
6 #include <linux/if_arp.h>
7 #include <linux/wireless.h>
8 #include <linux/ieee80211.h>
9 #include <net/iw_handler.h>
10 #include <net/cfg80211.h>
13 #include "hermes_rid.h"
23 #define MAX_RID_LEN 1024
25 /* Helper routine to record keys
26 * Do not call from interrupt context */
27 static int orinoco_set_key(struct orinoco_private
*priv
, int index
,
28 enum orinoco_alg alg
, const u8
*key
, int key_len
,
29 const u8
*seq
, int seq_len
)
31 kzfree(priv
->keys
[index
].key
);
32 kzfree(priv
->keys
[index
].seq
);
35 priv
->keys
[index
].key
= kzalloc(key_len
, GFP_KERNEL
);
36 if (!priv
->keys
[index
].key
)
39 priv
->keys
[index
].key
= NULL
;
42 priv
->keys
[index
].seq
= kzalloc(seq_len
, GFP_KERNEL
);
43 if (!priv
->keys
[index
].seq
)
46 priv
->keys
[index
].seq
= NULL
;
48 priv
->keys
[index
].key_len
= key_len
;
49 priv
->keys
[index
].seq_len
= seq_len
;
52 memcpy(priv
->keys
[index
].key
, key
, key_len
);
54 memcpy(priv
->keys
[index
].seq
, seq
, seq_len
);
57 case ORINOCO_ALG_TKIP
:
58 priv
->keys
[index
].cipher
= WLAN_CIPHER_SUITE_TKIP
;
62 priv
->keys
[index
].cipher
= (key_len
> SMALL_KEY_SIZE
) ?
63 WLAN_CIPHER_SUITE_WEP104
: WLAN_CIPHER_SUITE_WEP40
;
66 case ORINOCO_ALG_NONE
:
68 priv
->keys
[index
].cipher
= 0;
75 kfree(priv
->keys
[index
].key
);
76 priv
->keys
[index
].key
= NULL
;
79 priv
->keys
[index
].key_len
= 0;
80 priv
->keys
[index
].seq_len
= 0;
81 priv
->keys
[index
].cipher
= 0;
86 static struct iw_statistics
*orinoco_get_wireless_stats(struct net_device
*dev
)
88 struct orinoco_private
*priv
= ndev_priv(dev
);
89 hermes_t
*hw
= &priv
->hw
;
90 struct iw_statistics
*wstats
= &priv
->wstats
;
94 if (!netif_device_present(dev
)) {
95 printk(KERN_WARNING
"%s: get_wireless_stats() called while device not present\n",
97 return NULL
; /* FIXME: Can we do better than this? */
100 /* If busy, return the old stats. Returning NULL may cause
101 * the interface to disappear from /proc/net/wireless */
102 if (orinoco_lock(priv
, &flags
) != 0)
105 /* We can't really wait for the tallies inquiry command to
106 * complete, so we just use the previous results and trigger
107 * a new tallies inquiry command for next time - Jean II */
108 /* FIXME: Really we should wait for the inquiry to come back -
109 * as it is the stats we give don't make a whole lot of sense.
110 * Unfortunately, it's not clear how to do that within the
111 * wireless extensions framework: I think we're in user
112 * context, but a lock seems to be held by the time we get in
113 * here so we're not safe to sleep here. */
114 hermes_inquire(hw
, HERMES_INQ_TALLIES
);
116 if (priv
->iw_mode
== NL80211_IFTYPE_ADHOC
) {
117 memset(&wstats
->qual
, 0, sizeof(wstats
->qual
));
118 /* If a spy address is defined, we report stats of the
119 * first spy address - Jean II */
120 if (SPY_NUMBER(priv
)) {
121 wstats
->qual
.qual
= priv
->spy_data
.spy_stat
[0].qual
;
122 wstats
->qual
.level
= priv
->spy_data
.spy_stat
[0].level
;
123 wstats
->qual
.noise
= priv
->spy_data
.spy_stat
[0].noise
;
124 wstats
->qual
.updated
=
125 priv
->spy_data
.spy_stat
[0].updated
;
129 __le16 qual
, signal
, noise
, unused
;
130 } __attribute__ ((packed
)) cq
;
132 err
= HERMES_READ_RECORD(hw
, USER_BAP
,
133 HERMES_RID_COMMSQUALITY
, &cq
);
136 wstats
->qual
.qual
= (int)le16_to_cpu(cq
.qual
);
137 wstats
->qual
.level
= (int)le16_to_cpu(cq
.signal
) - 0x95;
138 wstats
->qual
.noise
= (int)le16_to_cpu(cq
.noise
) - 0x95;
139 wstats
->qual
.updated
=
140 IW_QUAL_ALL_UPDATED
| IW_QUAL_DBM
;
144 orinoco_unlock(priv
, &flags
);
148 /********************************************************************/
149 /* Wireless extensions */
150 /********************************************************************/
152 static int orinoco_ioctl_setwap(struct net_device
*dev
,
153 struct iw_request_info
*info
,
154 struct sockaddr
*ap_addr
,
157 struct orinoco_private
*priv
= ndev_priv(dev
);
158 int err
= -EINPROGRESS
; /* Call commit handler */
160 static const u8 off_addr
[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
161 static const u8 any_addr
[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
163 if (orinoco_lock(priv
, &flags
) != 0)
166 /* Enable automatic roaming - no sanity checks are needed */
167 if (memcmp(&ap_addr
->sa_data
, off_addr
, ETH_ALEN
) == 0 ||
168 memcmp(&ap_addr
->sa_data
, any_addr
, ETH_ALEN
) == 0) {
169 priv
->bssid_fixed
= 0;
170 memset(priv
->desired_bssid
, 0, ETH_ALEN
);
172 /* "off" means keep existing connection */
173 if (ap_addr
->sa_data
[0] == 0) {
174 __orinoco_hw_set_wap(priv
);
180 if (priv
->firmware_type
== FIRMWARE_TYPE_AGERE
) {
181 printk(KERN_WARNING
"%s: Lucent/Agere firmware doesn't "
182 "support manual roaming\n",
188 if (priv
->iw_mode
!= NL80211_IFTYPE_STATION
) {
189 printk(KERN_WARNING
"%s: Manual roaming supported only in "
190 "managed mode\n", dev
->name
);
195 /* Intersil firmware hangs without Desired ESSID */
196 if (priv
->firmware_type
== FIRMWARE_TYPE_INTERSIL
&&
197 strlen(priv
->desired_essid
) == 0) {
198 printk(KERN_WARNING
"%s: Desired ESSID must be set for "
199 "manual roaming\n", dev
->name
);
204 /* Finally, enable manual roaming */
205 priv
->bssid_fixed
= 1;
206 memcpy(priv
->desired_bssid
, &ap_addr
->sa_data
, ETH_ALEN
);
209 orinoco_unlock(priv
, &flags
);
213 static int orinoco_ioctl_getwap(struct net_device
*dev
,
214 struct iw_request_info
*info
,
215 struct sockaddr
*ap_addr
,
218 struct orinoco_private
*priv
= ndev_priv(dev
);
223 if (orinoco_lock(priv
, &flags
) != 0)
226 ap_addr
->sa_family
= ARPHRD_ETHER
;
227 err
= orinoco_hw_get_current_bssid(priv
, ap_addr
->sa_data
);
229 orinoco_unlock(priv
, &flags
);
234 static int orinoco_ioctl_setiwencode(struct net_device
*dev
,
235 struct iw_request_info
*info
,
236 struct iw_point
*erq
,
239 struct orinoco_private
*priv
= ndev_priv(dev
);
240 int index
= (erq
->flags
& IW_ENCODE_INDEX
) - 1;
241 int setindex
= priv
->tx_key
;
242 enum orinoco_alg encode_alg
= priv
->encode_alg
;
243 int restricted
= priv
->wep_restrict
;
244 int err
= -EINPROGRESS
; /* Call commit handler */
251 /* We actually have a key to set - check its length */
252 if (erq
->length
> LARGE_KEY_SIZE
)
255 if ((erq
->length
> SMALL_KEY_SIZE
) && !priv
->has_big_wep
)
259 if (orinoco_lock(priv
, &flags
) != 0)
262 /* Clear any TKIP key we have */
263 if ((priv
->has_wpa
) && (priv
->encode_alg
== ORINOCO_ALG_TKIP
))
264 (void) orinoco_clear_tkip_key(priv
, setindex
);
266 if (erq
->length
> 0) {
267 if ((index
< 0) || (index
>= ORINOCO_MAX_KEYS
))
268 index
= priv
->tx_key
;
270 /* Switch on WEP if off */
271 if (encode_alg
!= ORINOCO_ALG_WEP
) {
273 encode_alg
= ORINOCO_ALG_WEP
;
276 /* Important note : if the user do "iwconfig eth0 enc off",
277 * we will arrive there with an index of -1. This is valid
278 * but need to be taken care off... Jean II */
279 if ((index
< 0) || (index
>= ORINOCO_MAX_KEYS
)) {
280 if ((index
!= -1) || (erq
->flags
== 0)) {
285 /* Set the index : Check that the key is valid */
286 if (priv
->keys
[index
].key_len
== 0) {
294 if (erq
->flags
& IW_ENCODE_DISABLED
)
295 encode_alg
= ORINOCO_ALG_NONE
;
296 if (erq
->flags
& IW_ENCODE_OPEN
)
298 if (erq
->flags
& IW_ENCODE_RESTRICTED
)
301 if (erq
->pointer
&& erq
->length
> 0) {
302 err
= orinoco_set_key(priv
, index
, ORINOCO_ALG_WEP
, keybuf
,
303 erq
->length
, NULL
, 0);
305 priv
->tx_key
= setindex
;
307 /* Try fast key change if connected and only keys are changed */
308 if ((priv
->encode_alg
== encode_alg
) &&
309 (priv
->wep_restrict
== restricted
) &&
310 netif_carrier_ok(dev
)) {
311 err
= __orinoco_hw_setup_wepkeys(priv
);
312 /* No need to commit if successful */
316 priv
->encode_alg
= encode_alg
;
317 priv
->wep_restrict
= restricted
;
320 orinoco_unlock(priv
, &flags
);
325 static int orinoco_ioctl_getiwencode(struct net_device
*dev
,
326 struct iw_request_info
*info
,
327 struct iw_point
*erq
,
330 struct orinoco_private
*priv
= ndev_priv(dev
);
331 int index
= (erq
->flags
& IW_ENCODE_INDEX
) - 1;
337 if (orinoco_lock(priv
, &flags
) != 0)
340 if ((index
< 0) || (index
>= ORINOCO_MAX_KEYS
))
341 index
= priv
->tx_key
;
344 if (!priv
->encode_alg
)
345 erq
->flags
|= IW_ENCODE_DISABLED
;
346 erq
->flags
|= index
+ 1;
348 if (priv
->wep_restrict
)
349 erq
->flags
|= IW_ENCODE_RESTRICTED
;
351 erq
->flags
|= IW_ENCODE_OPEN
;
353 erq
->length
= priv
->keys
[index
].key_len
;
355 memcpy(keybuf
, priv
->keys
[index
].key
, erq
->length
);
357 orinoco_unlock(priv
, &flags
);
361 static int orinoco_ioctl_setessid(struct net_device
*dev
,
362 struct iw_request_info
*info
,
363 struct iw_point
*erq
,
366 struct orinoco_private
*priv
= ndev_priv(dev
);
369 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
370 * anyway... - Jean II */
372 /* Hum... Should not use Wireless Extension constant (may change),
373 * should use our own... - Jean II */
374 if (erq
->length
> IW_ESSID_MAX_SIZE
)
377 if (orinoco_lock(priv
, &flags
) != 0)
380 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
381 memset(priv
->desired_essid
, 0, sizeof(priv
->desired_essid
));
383 /* If not ANY, get the new ESSID */
385 memcpy(priv
->desired_essid
, essidbuf
, erq
->length
);
387 orinoco_unlock(priv
, &flags
);
389 return -EINPROGRESS
; /* Call commit handler */
392 static int orinoco_ioctl_getessid(struct net_device
*dev
,
393 struct iw_request_info
*info
,
394 struct iw_point
*erq
,
397 struct orinoco_private
*priv
= ndev_priv(dev
);
402 if (netif_running(dev
)) {
403 err
= orinoco_hw_get_essid(priv
, &active
, essidbuf
);
408 if (orinoco_lock(priv
, &flags
) != 0)
410 memcpy(essidbuf
, priv
->desired_essid
, IW_ESSID_MAX_SIZE
);
411 erq
->length
= strlen(priv
->desired_essid
);
412 orinoco_unlock(priv
, &flags
);
420 static int orinoco_ioctl_setfreq(struct net_device
*dev
,
421 struct iw_request_info
*info
,
425 struct orinoco_private
*priv
= ndev_priv(dev
);
428 int err
= -EINPROGRESS
; /* Call commit handler */
430 /* In infrastructure mode the AP sets the channel */
431 if (priv
->iw_mode
== NL80211_IFTYPE_STATION
)
434 if ((frq
->e
== 0) && (frq
->m
<= 1000)) {
435 /* Setting by channel number */
438 /* Setting by frequency */
442 /* Calculate denominator to rescale to MHz */
443 for (i
= 0; i
< (6 - frq
->e
); i
++)
446 chan
= ieee80211_freq_to_dsss_chan(frq
->m
/ denom
);
449 if ((chan
< 1) || (chan
> NUM_CHANNELS
) ||
450 !(priv
->channel_mask
& (1 << (chan
-1))))
453 if (orinoco_lock(priv
, &flags
) != 0)
456 priv
->channel
= chan
;
457 if (priv
->iw_mode
== NL80211_IFTYPE_MONITOR
) {
458 /* Fast channel change - no commit if successful */
459 hermes_t
*hw
= &priv
->hw
;
460 err
= hermes_docmd_wait(hw
, HERMES_CMD_TEST
|
461 HERMES_TEST_SET_CHANNEL
,
464 orinoco_unlock(priv
, &flags
);
469 static int orinoco_ioctl_getfreq(struct net_device
*dev
,
470 struct iw_request_info
*info
,
474 struct orinoco_private
*priv
= ndev_priv(dev
);
477 /* Locking done in there */
478 tmp
= orinoco_hw_get_freq(priv
);
482 frq
->m
= tmp
* 100000;
488 static int orinoco_ioctl_getsens(struct net_device
*dev
,
489 struct iw_request_info
*info
,
490 struct iw_param
*srq
,
493 struct orinoco_private
*priv
= ndev_priv(dev
);
494 hermes_t
*hw
= &priv
->hw
;
499 if (!priv
->has_sensitivity
)
502 if (orinoco_lock(priv
, &flags
) != 0)
504 err
= hermes_read_wordrec(hw
, USER_BAP
,
505 HERMES_RID_CNFSYSTEMSCALE
, &val
);
506 orinoco_unlock(priv
, &flags
);
512 srq
->fixed
= 0; /* auto */
517 static int orinoco_ioctl_setsens(struct net_device
*dev
,
518 struct iw_request_info
*info
,
519 struct iw_param
*srq
,
522 struct orinoco_private
*priv
= ndev_priv(dev
);
523 int val
= srq
->value
;
526 if (!priv
->has_sensitivity
)
529 if ((val
< 1) || (val
> 3))
532 if (orinoco_lock(priv
, &flags
) != 0)
534 priv
->ap_density
= val
;
535 orinoco_unlock(priv
, &flags
);
537 return -EINPROGRESS
; /* Call commit handler */
540 static int orinoco_ioctl_setrts(struct net_device
*dev
,
541 struct iw_request_info
*info
,
542 struct iw_param
*rrq
,
545 struct orinoco_private
*priv
= ndev_priv(dev
);
546 int val
= rrq
->value
;
552 if ((val
< 0) || (val
> 2347))
555 if (orinoco_lock(priv
, &flags
) != 0)
558 priv
->rts_thresh
= val
;
559 orinoco_unlock(priv
, &flags
);
561 return -EINPROGRESS
; /* Call commit handler */
564 static int orinoco_ioctl_getrts(struct net_device
*dev
,
565 struct iw_request_info
*info
,
566 struct iw_param
*rrq
,
569 struct orinoco_private
*priv
= ndev_priv(dev
);
571 rrq
->value
= priv
->rts_thresh
;
572 rrq
->disabled
= (rrq
->value
== 2347);
578 static int orinoco_ioctl_setfrag(struct net_device
*dev
,
579 struct iw_request_info
*info
,
580 struct iw_param
*frq
,
583 struct orinoco_private
*priv
= ndev_priv(dev
);
584 int err
= -EINPROGRESS
; /* Call commit handler */
587 if (orinoco_lock(priv
, &flags
) != 0)
592 priv
->mwo_robust
= 0;
595 printk(KERN_WARNING
"%s: Fixed fragmentation "
596 "is not supported on this firmware. "
597 "Using MWO robust instead.\n",
599 priv
->mwo_robust
= 1;
603 priv
->frag_thresh
= 2346;
605 if ((frq
->value
< 256) || (frq
->value
> 2346))
609 priv
->frag_thresh
= frq
->value
& ~0x1;
613 orinoco_unlock(priv
, &flags
);
618 static int orinoco_ioctl_getfrag(struct net_device
*dev
,
619 struct iw_request_info
*info
,
620 struct iw_param
*frq
,
623 struct orinoco_private
*priv
= ndev_priv(dev
);
624 hermes_t
*hw
= &priv
->hw
;
629 if (orinoco_lock(priv
, &flags
) != 0)
633 err
= hermes_read_wordrec(hw
, USER_BAP
,
634 HERMES_RID_CNFMWOROBUST_AGERE
,
639 frq
->value
= val
? 2347 : 0;
640 frq
->disabled
= !val
;
643 err
= hermes_read_wordrec(hw
, USER_BAP
,
644 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD
,
650 frq
->disabled
= (val
>= 2346);
654 orinoco_unlock(priv
, &flags
);
659 static int orinoco_ioctl_setrate(struct net_device
*dev
,
660 struct iw_request_info
*info
,
661 struct iw_param
*rrq
,
664 struct orinoco_private
*priv
= ndev_priv(dev
);
666 int bitrate
; /* 100s of kilobits */
669 /* As the user space doesn't know our highest rate, it uses -1
670 * to ask us to set the highest rate. Test it using "iwconfig
671 * ethX rate auto" - Jean II */
672 if (rrq
->value
== -1)
675 if (rrq
->value
% 100000)
677 bitrate
= rrq
->value
/ 100000;
680 ratemode
= orinoco_get_bitratemode(bitrate
, !rrq
->fixed
);
685 if (orinoco_lock(priv
, &flags
) != 0)
687 priv
->bitratemode
= ratemode
;
688 orinoco_unlock(priv
, &flags
);
693 static int orinoco_ioctl_getrate(struct net_device
*dev
,
694 struct iw_request_info
*info
,
695 struct iw_param
*rrq
,
698 struct orinoco_private
*priv
= ndev_priv(dev
);
700 int bitrate
, automatic
;
703 if (orinoco_lock(priv
, &flags
) != 0)
706 orinoco_get_ratemode_cfg(priv
->bitratemode
, &bitrate
, &automatic
);
708 /* If the interface is running we try to find more about the
710 if (netif_running(dev
))
711 err
= orinoco_hw_get_act_bitrate(priv
, &bitrate
);
713 orinoco_unlock(priv
, &flags
);
715 rrq
->value
= bitrate
;
716 rrq
->fixed
= !automatic
;
722 static int orinoco_ioctl_setpower(struct net_device
*dev
,
723 struct iw_request_info
*info
,
724 struct iw_param
*prq
,
727 struct orinoco_private
*priv
= ndev_priv(dev
);
728 int err
= -EINPROGRESS
; /* Call commit handler */
731 if (orinoco_lock(priv
, &flags
) != 0)
737 switch (prq
->flags
& IW_POWER_MODE
) {
738 case IW_POWER_UNICAST_R
:
747 /* No flags : but we may have a value - Jean II */
754 if (prq
->flags
& IW_POWER_TIMEOUT
) {
756 priv
->pm_timeout
= prq
->value
/ 1000;
758 if (prq
->flags
& IW_POWER_PERIOD
) {
760 priv
->pm_period
= prq
->value
/ 1000;
762 /* It's valid to not have a value if we are just toggling
763 * the flags... Jean II */
771 orinoco_unlock(priv
, &flags
);
776 static int orinoco_ioctl_getpower(struct net_device
*dev
,
777 struct iw_request_info
*info
,
778 struct iw_param
*prq
,
781 struct orinoco_private
*priv
= ndev_priv(dev
);
782 hermes_t
*hw
= &priv
->hw
;
784 u16 enable
, period
, timeout
, mcast
;
787 if (orinoco_lock(priv
, &flags
) != 0)
790 err
= hermes_read_wordrec(hw
, USER_BAP
,
791 HERMES_RID_CNFPMENABLED
, &enable
);
795 err
= hermes_read_wordrec(hw
, USER_BAP
,
796 HERMES_RID_CNFMAXSLEEPDURATION
, &period
);
800 err
= hermes_read_wordrec(hw
, USER_BAP
,
801 HERMES_RID_CNFPMHOLDOVERDURATION
, &timeout
);
805 err
= hermes_read_wordrec(hw
, USER_BAP
,
806 HERMES_RID_CNFMULTICASTRECEIVE
, &mcast
);
810 prq
->disabled
= !enable
;
811 /* Note : by default, display the period */
812 if ((prq
->flags
& IW_POWER_TYPE
) == IW_POWER_TIMEOUT
) {
813 prq
->flags
= IW_POWER_TIMEOUT
;
814 prq
->value
= timeout
* 1000;
816 prq
->flags
= IW_POWER_PERIOD
;
817 prq
->value
= period
* 1000;
820 prq
->flags
|= IW_POWER_ALL_R
;
822 prq
->flags
|= IW_POWER_UNICAST_R
;
825 orinoco_unlock(priv
, &flags
);
830 static int orinoco_ioctl_set_encodeext(struct net_device
*dev
,
831 struct iw_request_info
*info
,
832 union iwreq_data
*wrqu
,
835 struct orinoco_private
*priv
= ndev_priv(dev
);
836 struct iw_point
*encoding
= &wrqu
->encoding
;
837 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*)extra
;
838 int idx
, alg
= ext
->alg
, set_key
= 1;
842 if (orinoco_lock(priv
, &flags
) != 0)
845 /* Determine and validate the key index */
846 idx
= encoding
->flags
& IW_ENCODE_INDEX
;
848 if ((idx
< 1) || (idx
> 4))
854 if (encoding
->flags
& IW_ENCODE_DISABLED
)
855 alg
= IW_ENCODE_ALG_NONE
;
857 if (priv
->has_wpa
&& (alg
!= IW_ENCODE_ALG_TKIP
)) {
858 /* Clear any TKIP TX key we had */
859 (void) orinoco_clear_tkip_key(priv
, priv
->tx_key
);
862 if (ext
->ext_flags
& IW_ENCODE_EXT_SET_TX_KEY
) {
864 set_key
= ((alg
== IW_ENCODE_ALG_TKIP
) ||
865 (ext
->key_len
> 0)) ? 1 : 0;
869 /* Set the requested key first */
871 case IW_ENCODE_ALG_NONE
:
872 priv
->encode_alg
= ORINOCO_ALG_NONE
;
873 err
= orinoco_set_key(priv
, idx
, ORINOCO_ALG_NONE
,
877 case IW_ENCODE_ALG_WEP
:
878 if (ext
->key_len
<= 0)
881 priv
->encode_alg
= ORINOCO_ALG_WEP
;
882 err
= orinoco_set_key(priv
, idx
, ORINOCO_ALG_WEP
,
883 ext
->key
, ext
->key_len
, NULL
, 0);
886 case IW_ENCODE_ALG_TKIP
:
890 if (!priv
->has_wpa
||
891 (ext
->key_len
> sizeof(struct orinoco_tkip_key
)))
894 priv
->encode_alg
= ORINOCO_ALG_TKIP
;
896 if (ext
->ext_flags
& IW_ENCODE_EXT_RX_SEQ_VALID
)
897 tkip_iv
= &ext
->rx_seq
[0];
899 err
= orinoco_set_key(priv
, idx
, ORINOCO_ALG_TKIP
,
900 ext
->key
, ext
->key_len
, tkip_iv
,
903 err
= __orinoco_hw_set_tkip_key(priv
, idx
,
904 ext
->ext_flags
& IW_ENCODE_EXT_SET_TX_KEY
,
906 tkip_iv
, ORINOCO_SEQ_LEN
, NULL
, 0);
908 printk(KERN_ERR
"%s: Error %d setting TKIP key"
909 "\n", dev
->name
, err
);
919 orinoco_unlock(priv
, &flags
);
924 static int orinoco_ioctl_get_encodeext(struct net_device
*dev
,
925 struct iw_request_info
*info
,
926 union iwreq_data
*wrqu
,
929 struct orinoco_private
*priv
= ndev_priv(dev
);
930 struct iw_point
*encoding
= &wrqu
->encoding
;
931 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*)extra
;
932 int idx
, max_key_len
;
936 if (orinoco_lock(priv
, &flags
) != 0)
940 max_key_len
= encoding
->length
- sizeof(*ext
);
944 idx
= encoding
->flags
& IW_ENCODE_INDEX
;
946 if ((idx
< 1) || (idx
> 4))
952 encoding
->flags
= idx
+ 1;
953 memset(ext
, 0, sizeof(*ext
));
955 switch (priv
->encode_alg
) {
956 case ORINOCO_ALG_NONE
:
957 ext
->alg
= IW_ENCODE_ALG_NONE
;
959 encoding
->flags
|= IW_ENCODE_DISABLED
;
961 case ORINOCO_ALG_WEP
:
962 ext
->alg
= IW_ENCODE_ALG_WEP
;
963 ext
->key_len
= min(priv
->keys
[idx
].key_len
, max_key_len
);
964 memcpy(ext
->key
, priv
->keys
[idx
].key
, ext
->key_len
);
965 encoding
->flags
|= IW_ENCODE_ENABLED
;
967 case ORINOCO_ALG_TKIP
:
968 ext
->alg
= IW_ENCODE_ALG_TKIP
;
969 ext
->key_len
= min(priv
->keys
[idx
].key_len
, max_key_len
);
970 memcpy(ext
->key
, priv
->keys
[idx
].key
, ext
->key_len
);
971 encoding
->flags
|= IW_ENCODE_ENABLED
;
977 orinoco_unlock(priv
, &flags
);
982 static int orinoco_ioctl_set_auth(struct net_device
*dev
,
983 struct iw_request_info
*info
,
984 union iwreq_data
*wrqu
, char *extra
)
986 struct orinoco_private
*priv
= ndev_priv(dev
);
987 hermes_t
*hw
= &priv
->hw
;
988 struct iw_param
*param
= &wrqu
->param
;
990 int ret
= -EINPROGRESS
;
992 if (orinoco_lock(priv
, &flags
) != 0)
995 switch (param
->flags
& IW_AUTH_INDEX
) {
996 case IW_AUTH_WPA_VERSION
:
997 case IW_AUTH_CIPHER_PAIRWISE
:
998 case IW_AUTH_CIPHER_GROUP
:
999 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
1000 case IW_AUTH_PRIVACY_INVOKED
:
1001 case IW_AUTH_DROP_UNENCRYPTED
:
1003 * orinoco does not use these parameters
1007 case IW_AUTH_KEY_MGMT
:
1008 /* wl_lkm implies value 2 == PSK for Hermes I
1009 * which ties in with WEXT
1010 * no other hints tho :(
1012 priv
->key_mgmt
= param
->value
;
1015 case IW_AUTH_TKIP_COUNTERMEASURES
:
1016 /* When countermeasures are enabled, shut down the
1017 * card; when disabled, re-enable the card. This must
1018 * take effect immediately.
1020 * TODO: Make sure that the EAPOL message is getting
1021 * out before card disabled
1024 priv
->tkip_cm_active
= 1;
1025 ret
= hermes_enable_port(hw
, 0);
1027 priv
->tkip_cm_active
= 0;
1028 ret
= hermes_disable_port(hw
, 0);
1032 case IW_AUTH_80211_AUTH_ALG
:
1033 if (param
->value
& IW_AUTH_ALG_SHARED_KEY
)
1034 priv
->wep_restrict
= 1;
1035 else if (param
->value
& IW_AUTH_ALG_OPEN_SYSTEM
)
1036 priv
->wep_restrict
= 0;
1041 case IW_AUTH_WPA_ENABLED
:
1042 if (priv
->has_wpa
) {
1043 priv
->wpa_enabled
= param
->value
? 1 : 0;
1047 /* else silently accept disable of WPA */
1048 priv
->wpa_enabled
= 0;
1056 orinoco_unlock(priv
, &flags
);
1060 static int orinoco_ioctl_get_auth(struct net_device
*dev
,
1061 struct iw_request_info
*info
,
1062 union iwreq_data
*wrqu
, char *extra
)
1064 struct orinoco_private
*priv
= ndev_priv(dev
);
1065 struct iw_param
*param
= &wrqu
->param
;
1066 unsigned long flags
;
1069 if (orinoco_lock(priv
, &flags
) != 0)
1072 switch (param
->flags
& IW_AUTH_INDEX
) {
1073 case IW_AUTH_KEY_MGMT
:
1074 param
->value
= priv
->key_mgmt
;
1077 case IW_AUTH_TKIP_COUNTERMEASURES
:
1078 param
->value
= priv
->tkip_cm_active
;
1081 case IW_AUTH_80211_AUTH_ALG
:
1082 if (priv
->wep_restrict
)
1083 param
->value
= IW_AUTH_ALG_SHARED_KEY
;
1085 param
->value
= IW_AUTH_ALG_OPEN_SYSTEM
;
1088 case IW_AUTH_WPA_ENABLED
:
1089 param
->value
= priv
->wpa_enabled
;
1096 orinoco_unlock(priv
, &flags
);
1100 static int orinoco_ioctl_set_genie(struct net_device
*dev
,
1101 struct iw_request_info
*info
,
1102 union iwreq_data
*wrqu
, char *extra
)
1104 struct orinoco_private
*priv
= ndev_priv(dev
);
1106 unsigned long flags
;
1108 /* cut off at IEEE80211_MAX_DATA_LEN */
1109 if ((wrqu
->data
.length
> IEEE80211_MAX_DATA_LEN
) ||
1110 (wrqu
->data
.length
&& (extra
== NULL
)))
1113 if (wrqu
->data
.length
) {
1114 buf
= kmalloc(wrqu
->data
.length
, GFP_KERNEL
);
1118 memcpy(buf
, extra
, wrqu
->data
.length
);
1122 if (orinoco_lock(priv
, &flags
) != 0) {
1127 kfree(priv
->wpa_ie
);
1129 priv
->wpa_ie_len
= wrqu
->data
.length
;
1132 /* Looks like wl_lkm wants to check the auth alg, and
1133 * somehow pass it to the firmware.
1134 * Instead it just calls the key mgmt rid
1135 * - we do this in set auth.
1139 orinoco_unlock(priv
, &flags
);
1143 static int orinoco_ioctl_get_genie(struct net_device
*dev
,
1144 struct iw_request_info
*info
,
1145 union iwreq_data
*wrqu
, char *extra
)
1147 struct orinoco_private
*priv
= ndev_priv(dev
);
1148 unsigned long flags
;
1151 if (orinoco_lock(priv
, &flags
) != 0)
1154 if ((priv
->wpa_ie_len
== 0) || (priv
->wpa_ie
== NULL
)) {
1155 wrqu
->data
.length
= 0;
1159 if (wrqu
->data
.length
< priv
->wpa_ie_len
) {
1164 wrqu
->data
.length
= priv
->wpa_ie_len
;
1165 memcpy(extra
, priv
->wpa_ie
, priv
->wpa_ie_len
);
1168 orinoco_unlock(priv
, &flags
);
1172 static int orinoco_ioctl_set_mlme(struct net_device
*dev
,
1173 struct iw_request_info
*info
,
1174 union iwreq_data
*wrqu
, char *extra
)
1176 struct orinoco_private
*priv
= ndev_priv(dev
);
1177 struct iw_mlme
*mlme
= (struct iw_mlme
*)extra
;
1178 unsigned long flags
;
1181 if (orinoco_lock(priv
, &flags
) != 0)
1184 switch (mlme
->cmd
) {
1185 case IW_MLME_DEAUTH
:
1186 /* silently ignore */
1189 case IW_MLME_DISASSOC
:
1191 ret
= orinoco_hw_disassociate(priv
, mlme
->addr
.sa_data
,
1199 orinoco_unlock(priv
, &flags
);
1203 static int orinoco_ioctl_getretry(struct net_device
*dev
,
1204 struct iw_request_info
*info
,
1205 struct iw_param
*rrq
,
1208 struct orinoco_private
*priv
= ndev_priv(dev
);
1209 hermes_t
*hw
= &priv
->hw
;
1211 u16 short_limit
, long_limit
, lifetime
;
1212 unsigned long flags
;
1214 if (orinoco_lock(priv
, &flags
) != 0)
1217 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_SHORTRETRYLIMIT
,
1222 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_LONGRETRYLIMIT
,
1227 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_MAXTRANSMITLIFETIME
,
1232 rrq
->disabled
= 0; /* Can't be disabled */
1234 /* Note : by default, display the retry number */
1235 if ((rrq
->flags
& IW_RETRY_TYPE
) == IW_RETRY_LIFETIME
) {
1236 rrq
->flags
= IW_RETRY_LIFETIME
;
1237 rrq
->value
= lifetime
* 1000; /* ??? */
1239 /* By default, display the min number */
1240 if ((rrq
->flags
& IW_RETRY_LONG
)) {
1241 rrq
->flags
= IW_RETRY_LIMIT
| IW_RETRY_LONG
;
1242 rrq
->value
= long_limit
;
1244 rrq
->flags
= IW_RETRY_LIMIT
;
1245 rrq
->value
= short_limit
;
1246 if (short_limit
!= long_limit
)
1247 rrq
->flags
|= IW_RETRY_SHORT
;
1252 orinoco_unlock(priv
, &flags
);
1257 static int orinoco_ioctl_reset(struct net_device
*dev
,
1258 struct iw_request_info
*info
,
1262 struct orinoco_private
*priv
= ndev_priv(dev
);
1264 if (!capable(CAP_NET_ADMIN
))
1267 if (info
->cmd
== (SIOCIWFIRSTPRIV
+ 0x1)) {
1268 printk(KERN_DEBUG
"%s: Forcing reset!\n", dev
->name
);
1270 /* Firmware reset */
1271 orinoco_reset(&priv
->reset_work
);
1273 printk(KERN_DEBUG
"%s: Force scheduling reset!\n", dev
->name
);
1275 schedule_work(&priv
->reset_work
);
1281 static int orinoco_ioctl_setibssport(struct net_device
*dev
,
1282 struct iw_request_info
*info
,
1287 struct orinoco_private
*priv
= ndev_priv(dev
);
1288 int val
= *((int *) extra
);
1289 unsigned long flags
;
1291 if (orinoco_lock(priv
, &flags
) != 0)
1294 priv
->ibss_port
= val
;
1296 /* Actually update the mode we are using */
1297 set_port_type(priv
);
1299 orinoco_unlock(priv
, &flags
);
1300 return -EINPROGRESS
; /* Call commit handler */
1303 static int orinoco_ioctl_getibssport(struct net_device
*dev
,
1304 struct iw_request_info
*info
,
1308 struct orinoco_private
*priv
= ndev_priv(dev
);
1309 int *val
= (int *) extra
;
1311 *val
= priv
->ibss_port
;
1315 static int orinoco_ioctl_setport3(struct net_device
*dev
,
1316 struct iw_request_info
*info
,
1320 struct orinoco_private
*priv
= ndev_priv(dev
);
1321 int val
= *((int *) extra
);
1323 unsigned long flags
;
1325 if (orinoco_lock(priv
, &flags
) != 0)
1329 case 0: /* Try to do IEEE ad-hoc mode */
1330 if (!priv
->has_ibss
) {
1334 priv
->prefer_port3
= 0;
1338 case 1: /* Try to do Lucent proprietary ad-hoc mode */
1339 if (!priv
->has_port3
) {
1343 priv
->prefer_port3
= 1;
1351 /* Actually update the mode we are using */
1352 set_port_type(priv
);
1356 orinoco_unlock(priv
, &flags
);
1361 static int orinoco_ioctl_getport3(struct net_device
*dev
,
1362 struct iw_request_info
*info
,
1366 struct orinoco_private
*priv
= ndev_priv(dev
);
1367 int *val
= (int *) extra
;
1369 *val
= priv
->prefer_port3
;
1373 static int orinoco_ioctl_setpreamble(struct net_device
*dev
,
1374 struct iw_request_info
*info
,
1378 struct orinoco_private
*priv
= ndev_priv(dev
);
1379 unsigned long flags
;
1382 if (!priv
->has_preamble
)
1385 /* 802.11b has recently defined some short preamble.
1386 * Basically, the Phy header has been reduced in size.
1387 * This increase performance, especially at high rates
1388 * (the preamble is transmitted at 1Mb/s), unfortunately
1389 * this give compatibility troubles... - Jean II */
1390 val
= *((int *) extra
);
1392 if (orinoco_lock(priv
, &flags
) != 0)
1400 orinoco_unlock(priv
, &flags
);
1402 return -EINPROGRESS
; /* Call commit handler */
1405 static int orinoco_ioctl_getpreamble(struct net_device
*dev
,
1406 struct iw_request_info
*info
,
1410 struct orinoco_private
*priv
= ndev_priv(dev
);
1411 int *val
= (int *) extra
;
1413 if (!priv
->has_preamble
)
1416 *val
= priv
->preamble
;
1420 /* ioctl interface to hermes_read_ltv()
1421 * To use with iwpriv, pass the RID as the token argument, e.g.
1422 * iwpriv get_rid [0xfc00]
1423 * At least Wireless Tools 25 is required to use iwpriv.
1424 * For Wireless Tools 25 and 26 append "dummy" are the end. */
1425 static int orinoco_ioctl_getrid(struct net_device
*dev
,
1426 struct iw_request_info
*info
,
1427 struct iw_point
*data
,
1430 struct orinoco_private
*priv
= ndev_priv(dev
);
1431 hermes_t
*hw
= &priv
->hw
;
1432 int rid
= data
->flags
;
1435 unsigned long flags
;
1437 /* It's a "get" function, but we don't want users to access the
1438 * WEP key and other raw firmware data */
1439 if (!capable(CAP_NET_ADMIN
))
1442 if (rid
< 0xfc00 || rid
> 0xffff)
1445 if (orinoco_lock(priv
, &flags
) != 0)
1448 err
= hermes_read_ltv(hw
, USER_BAP
, rid
, MAX_RID_LEN
, &length
,
1453 data
->length
= min_t(u16
, HERMES_RECLEN_TO_BYTES(length
),
1457 orinoco_unlock(priv
, &flags
);
1462 /* Commit handler, called after set operations */
1463 static int orinoco_ioctl_commit(struct net_device
*dev
,
1464 struct iw_request_info
*info
,
1468 struct orinoco_private
*priv
= ndev_priv(dev
);
1469 unsigned long flags
;
1475 if (orinoco_lock(priv
, &flags
) != 0)
1478 err
= orinoco_commit(priv
);
1480 orinoco_unlock(priv
, &flags
);
1484 static const struct iw_priv_args orinoco_privtab
[] = {
1485 { SIOCIWFIRSTPRIV
+ 0x0, 0, 0, "force_reset" },
1486 { SIOCIWFIRSTPRIV
+ 0x1, 0, 0, "card_reset" },
1487 { SIOCIWFIRSTPRIV
+ 0x2, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
1489 { SIOCIWFIRSTPRIV
+ 0x3, 0, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
1491 { SIOCIWFIRSTPRIV
+ 0x4, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
1492 0, "set_preamble" },
1493 { SIOCIWFIRSTPRIV
+ 0x5, 0, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
1495 { SIOCIWFIRSTPRIV
+ 0x6, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
1496 0, "set_ibssport" },
1497 { SIOCIWFIRSTPRIV
+ 0x7, 0, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
1499 { SIOCIWFIRSTPRIV
+ 0x9, 0, IW_PRIV_TYPE_BYTE
| MAX_RID_LEN
,
1505 * Structures to export the Wireless Handlers
1508 #define STD_IW_HANDLER(id, func) \
1509 [IW_IOCTL_IDX(id)] = (iw_handler) func
1510 static const iw_handler orinoco_handler
[] = {
1511 STD_IW_HANDLER(SIOCSIWCOMMIT
, orinoco_ioctl_commit
),
1512 STD_IW_HANDLER(SIOCGIWNAME
, cfg80211_wext_giwname
),
1513 STD_IW_HANDLER(SIOCSIWFREQ
, orinoco_ioctl_setfreq
),
1514 STD_IW_HANDLER(SIOCGIWFREQ
, orinoco_ioctl_getfreq
),
1515 STD_IW_HANDLER(SIOCSIWMODE
, cfg80211_wext_siwmode
),
1516 STD_IW_HANDLER(SIOCGIWMODE
, cfg80211_wext_giwmode
),
1517 STD_IW_HANDLER(SIOCSIWSENS
, orinoco_ioctl_setsens
),
1518 STD_IW_HANDLER(SIOCGIWSENS
, orinoco_ioctl_getsens
),
1519 STD_IW_HANDLER(SIOCGIWRANGE
, cfg80211_wext_giwrange
),
1520 STD_IW_HANDLER(SIOCSIWSPY
, iw_handler_set_spy
),
1521 STD_IW_HANDLER(SIOCGIWSPY
, iw_handler_get_spy
),
1522 STD_IW_HANDLER(SIOCSIWTHRSPY
, iw_handler_set_thrspy
),
1523 STD_IW_HANDLER(SIOCGIWTHRSPY
, iw_handler_get_thrspy
),
1524 STD_IW_HANDLER(SIOCSIWAP
, orinoco_ioctl_setwap
),
1525 STD_IW_HANDLER(SIOCGIWAP
, orinoco_ioctl_getwap
),
1526 STD_IW_HANDLER(SIOCSIWSCAN
, cfg80211_wext_siwscan
),
1527 STD_IW_HANDLER(SIOCGIWSCAN
, cfg80211_wext_giwscan
),
1528 STD_IW_HANDLER(SIOCSIWESSID
, orinoco_ioctl_setessid
),
1529 STD_IW_HANDLER(SIOCGIWESSID
, orinoco_ioctl_getessid
),
1530 STD_IW_HANDLER(SIOCSIWRATE
, orinoco_ioctl_setrate
),
1531 STD_IW_HANDLER(SIOCGIWRATE
, orinoco_ioctl_getrate
),
1532 STD_IW_HANDLER(SIOCSIWRTS
, orinoco_ioctl_setrts
),
1533 STD_IW_HANDLER(SIOCGIWRTS
, orinoco_ioctl_getrts
),
1534 STD_IW_HANDLER(SIOCSIWFRAG
, orinoco_ioctl_setfrag
),
1535 STD_IW_HANDLER(SIOCGIWFRAG
, orinoco_ioctl_getfrag
),
1536 STD_IW_HANDLER(SIOCGIWRETRY
, orinoco_ioctl_getretry
),
1537 STD_IW_HANDLER(SIOCSIWENCODE
, orinoco_ioctl_setiwencode
),
1538 STD_IW_HANDLER(SIOCGIWENCODE
, orinoco_ioctl_getiwencode
),
1539 STD_IW_HANDLER(SIOCSIWPOWER
, orinoco_ioctl_setpower
),
1540 STD_IW_HANDLER(SIOCGIWPOWER
, orinoco_ioctl_getpower
),
1541 STD_IW_HANDLER(SIOCSIWGENIE
, orinoco_ioctl_set_genie
),
1542 STD_IW_HANDLER(SIOCGIWGENIE
, orinoco_ioctl_get_genie
),
1543 STD_IW_HANDLER(SIOCSIWMLME
, orinoco_ioctl_set_mlme
),
1544 STD_IW_HANDLER(SIOCSIWAUTH
, orinoco_ioctl_set_auth
),
1545 STD_IW_HANDLER(SIOCGIWAUTH
, orinoco_ioctl_get_auth
),
1546 STD_IW_HANDLER(SIOCSIWENCODEEXT
, orinoco_ioctl_set_encodeext
),
1547 STD_IW_HANDLER(SIOCGIWENCODEEXT
, orinoco_ioctl_get_encodeext
),
1552 Added typecasting since we no longer use iwreq_data -- Moustafa
1554 static const iw_handler orinoco_private_handler
[] = {
1555 [0] = (iw_handler
) orinoco_ioctl_reset
,
1556 [1] = (iw_handler
) orinoco_ioctl_reset
,
1557 [2] = (iw_handler
) orinoco_ioctl_setport3
,
1558 [3] = (iw_handler
) orinoco_ioctl_getport3
,
1559 [4] = (iw_handler
) orinoco_ioctl_setpreamble
,
1560 [5] = (iw_handler
) orinoco_ioctl_getpreamble
,
1561 [6] = (iw_handler
) orinoco_ioctl_setibssport
,
1562 [7] = (iw_handler
) orinoco_ioctl_getibssport
,
1563 [9] = (iw_handler
) orinoco_ioctl_getrid
,
1566 const struct iw_handler_def orinoco_handler_def
= {
1567 .num_standard
= ARRAY_SIZE(orinoco_handler
),
1568 .num_private
= ARRAY_SIZE(orinoco_private_handler
),
1569 .num_private_args
= ARRAY_SIZE(orinoco_privtab
),
1570 .standard
= orinoco_handler
,
1571 .private = orinoco_private_handler
,
1572 .private_args
= orinoco_privtab
,
1573 .get_wireless_stats
= orinoco_get_wireless_stats
,