1 /* Wireless extensions support.
3 * See copyright notice in main.c
5 #include <linux/slab.h>
6 #include <linux/kernel.h>
7 #include <linux/if_arp.h>
8 #include <linux/wireless.h>
9 #include <linux/ieee80211.h>
10 #include <net/iw_handler.h>
11 #include <net/cfg80211.h>
14 #include "hermes_rid.h"
24 #define MAX_RID_LEN 1024
26 /* Helper routine to record keys
27 * It is called under orinoco_lock so it may not sleep */
28 static int orinoco_set_key(struct orinoco_private
*priv
, int index
,
29 enum orinoco_alg alg
, const u8
*key
, int key_len
,
30 const u8
*seq
, int seq_len
)
32 kzfree(priv
->keys
[index
].key
);
33 kzfree(priv
->keys
[index
].seq
);
36 priv
->keys
[index
].key
= kzalloc(key_len
, GFP_ATOMIC
);
37 if (!priv
->keys
[index
].key
)
40 priv
->keys
[index
].key
= NULL
;
43 priv
->keys
[index
].seq
= kzalloc(seq_len
, GFP_ATOMIC
);
44 if (!priv
->keys
[index
].seq
)
47 priv
->keys
[index
].seq
= NULL
;
49 priv
->keys
[index
].key_len
= key_len
;
50 priv
->keys
[index
].seq_len
= seq_len
;
53 memcpy(priv
->keys
[index
].key
, key
, key_len
);
55 memcpy(priv
->keys
[index
].seq
, seq
, seq_len
);
58 case ORINOCO_ALG_TKIP
:
59 priv
->keys
[index
].cipher
= WLAN_CIPHER_SUITE_TKIP
;
63 priv
->keys
[index
].cipher
= (key_len
> SMALL_KEY_SIZE
) ?
64 WLAN_CIPHER_SUITE_WEP104
: WLAN_CIPHER_SUITE_WEP40
;
67 case ORINOCO_ALG_NONE
:
69 priv
->keys
[index
].cipher
= 0;
76 kfree(priv
->keys
[index
].key
);
77 priv
->keys
[index
].key
= NULL
;
80 priv
->keys
[index
].key_len
= 0;
81 priv
->keys
[index
].seq_len
= 0;
82 priv
->keys
[index
].cipher
= 0;
87 static struct iw_statistics
*orinoco_get_wireless_stats(struct net_device
*dev
)
89 struct orinoco_private
*priv
= ndev_priv(dev
);
90 hermes_t
*hw
= &priv
->hw
;
91 struct iw_statistics
*wstats
= &priv
->wstats
;
95 if (!netif_device_present(dev
)) {
96 printk(KERN_WARNING
"%s: get_wireless_stats() called while device not present\n",
98 return NULL
; /* FIXME: Can we do better than this? */
101 /* If busy, return the old stats. Returning NULL may cause
102 * the interface to disappear from /proc/net/wireless */
103 if (orinoco_lock(priv
, &flags
) != 0)
106 /* We can't really wait for the tallies inquiry command to
107 * complete, so we just use the previous results and trigger
108 * a new tallies inquiry command for next time - Jean II */
109 /* FIXME: Really we should wait for the inquiry to come back -
110 * as it is the stats we give don't make a whole lot of sense.
111 * Unfortunately, it's not clear how to do that within the
112 * wireless extensions framework: I think we're in user
113 * context, but a lock seems to be held by the time we get in
114 * here so we're not safe to sleep here. */
115 hermes_inquire(hw
, HERMES_INQ_TALLIES
);
117 if (priv
->iw_mode
== NL80211_IFTYPE_ADHOC
) {
118 memset(&wstats
->qual
, 0, sizeof(wstats
->qual
));
119 /* If a spy address is defined, we report stats of the
120 * first spy address - Jean II */
121 if (SPY_NUMBER(priv
)) {
122 wstats
->qual
.qual
= priv
->spy_data
.spy_stat
[0].qual
;
123 wstats
->qual
.level
= priv
->spy_data
.spy_stat
[0].level
;
124 wstats
->qual
.noise
= priv
->spy_data
.spy_stat
[0].noise
;
125 wstats
->qual
.updated
=
126 priv
->spy_data
.spy_stat
[0].updated
;
130 __le16 qual
, signal
, noise
, unused
;
131 } __attribute__ ((packed
)) cq
;
133 err
= HERMES_READ_RECORD(hw
, USER_BAP
,
134 HERMES_RID_COMMSQUALITY
, &cq
);
137 wstats
->qual
.qual
= (int)le16_to_cpu(cq
.qual
);
138 wstats
->qual
.level
= (int)le16_to_cpu(cq
.signal
) - 0x95;
139 wstats
->qual
.noise
= (int)le16_to_cpu(cq
.noise
) - 0x95;
140 wstats
->qual
.updated
=
141 IW_QUAL_ALL_UPDATED
| IW_QUAL_DBM
;
145 orinoco_unlock(priv
, &flags
);
149 /********************************************************************/
150 /* Wireless extensions */
151 /********************************************************************/
153 static int orinoco_ioctl_setwap(struct net_device
*dev
,
154 struct iw_request_info
*info
,
155 struct sockaddr
*ap_addr
,
158 struct orinoco_private
*priv
= ndev_priv(dev
);
159 int err
= -EINPROGRESS
; /* Call commit handler */
161 static const u8 off_addr
[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
162 static const u8 any_addr
[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
164 if (orinoco_lock(priv
, &flags
) != 0)
167 /* Enable automatic roaming - no sanity checks are needed */
168 if (memcmp(&ap_addr
->sa_data
, off_addr
, ETH_ALEN
) == 0 ||
169 memcmp(&ap_addr
->sa_data
, any_addr
, ETH_ALEN
) == 0) {
170 priv
->bssid_fixed
= 0;
171 memset(priv
->desired_bssid
, 0, ETH_ALEN
);
173 /* "off" means keep existing connection */
174 if (ap_addr
->sa_data
[0] == 0) {
175 __orinoco_hw_set_wap(priv
);
181 if (priv
->firmware_type
== FIRMWARE_TYPE_AGERE
) {
182 printk(KERN_WARNING
"%s: Lucent/Agere firmware doesn't "
183 "support manual roaming\n",
189 if (priv
->iw_mode
!= NL80211_IFTYPE_STATION
) {
190 printk(KERN_WARNING
"%s: Manual roaming supported only in "
191 "managed mode\n", dev
->name
);
196 /* Intersil firmware hangs without Desired ESSID */
197 if (priv
->firmware_type
== FIRMWARE_TYPE_INTERSIL
&&
198 strlen(priv
->desired_essid
) == 0) {
199 printk(KERN_WARNING
"%s: Desired ESSID must be set for "
200 "manual roaming\n", dev
->name
);
205 /* Finally, enable manual roaming */
206 priv
->bssid_fixed
= 1;
207 memcpy(priv
->desired_bssid
, &ap_addr
->sa_data
, ETH_ALEN
);
210 orinoco_unlock(priv
, &flags
);
214 static int orinoco_ioctl_getwap(struct net_device
*dev
,
215 struct iw_request_info
*info
,
216 struct sockaddr
*ap_addr
,
219 struct orinoco_private
*priv
= ndev_priv(dev
);
224 if (orinoco_lock(priv
, &flags
) != 0)
227 ap_addr
->sa_family
= ARPHRD_ETHER
;
228 err
= orinoco_hw_get_current_bssid(priv
, ap_addr
->sa_data
);
230 orinoco_unlock(priv
, &flags
);
235 static int orinoco_ioctl_setiwencode(struct net_device
*dev
,
236 struct iw_request_info
*info
,
237 struct iw_point
*erq
,
240 struct orinoco_private
*priv
= ndev_priv(dev
);
241 int index
= (erq
->flags
& IW_ENCODE_INDEX
) - 1;
242 int setindex
= priv
->tx_key
;
243 enum orinoco_alg encode_alg
= priv
->encode_alg
;
244 int restricted
= priv
->wep_restrict
;
245 int err
= -EINPROGRESS
; /* Call commit handler */
252 /* We actually have a key to set - check its length */
253 if (erq
->length
> LARGE_KEY_SIZE
)
256 if ((erq
->length
> SMALL_KEY_SIZE
) && !priv
->has_big_wep
)
260 if (orinoco_lock(priv
, &flags
) != 0)
263 /* Clear any TKIP key we have */
264 if ((priv
->has_wpa
) && (priv
->encode_alg
== ORINOCO_ALG_TKIP
))
265 (void) orinoco_clear_tkip_key(priv
, setindex
);
267 if (erq
->length
> 0) {
268 if ((index
< 0) || (index
>= ORINOCO_MAX_KEYS
))
269 index
= priv
->tx_key
;
271 /* Switch on WEP if off */
272 if (encode_alg
!= ORINOCO_ALG_WEP
) {
274 encode_alg
= ORINOCO_ALG_WEP
;
277 /* Important note : if the user do "iwconfig eth0 enc off",
278 * we will arrive there with an index of -1. This is valid
279 * but need to be taken care off... Jean II */
280 if ((index
< 0) || (index
>= ORINOCO_MAX_KEYS
)) {
281 if ((index
!= -1) || (erq
->flags
== 0)) {
286 /* Set the index : Check that the key is valid */
287 if (priv
->keys
[index
].key_len
== 0) {
295 if (erq
->flags
& IW_ENCODE_DISABLED
)
296 encode_alg
= ORINOCO_ALG_NONE
;
297 if (erq
->flags
& IW_ENCODE_OPEN
)
299 if (erq
->flags
& IW_ENCODE_RESTRICTED
)
302 if (erq
->pointer
&& erq
->length
> 0) {
303 err
= orinoco_set_key(priv
, index
, ORINOCO_ALG_WEP
, keybuf
,
304 erq
->length
, NULL
, 0);
306 priv
->tx_key
= setindex
;
308 /* Try fast key change if connected and only keys are changed */
309 if ((priv
->encode_alg
== encode_alg
) &&
310 (priv
->wep_restrict
== restricted
) &&
311 netif_carrier_ok(dev
)) {
312 err
= __orinoco_hw_setup_wepkeys(priv
);
313 /* No need to commit if successful */
317 priv
->encode_alg
= encode_alg
;
318 priv
->wep_restrict
= restricted
;
321 orinoco_unlock(priv
, &flags
);
326 static int orinoco_ioctl_getiwencode(struct net_device
*dev
,
327 struct iw_request_info
*info
,
328 struct iw_point
*erq
,
331 struct orinoco_private
*priv
= ndev_priv(dev
);
332 int index
= (erq
->flags
& IW_ENCODE_INDEX
) - 1;
338 if (orinoco_lock(priv
, &flags
) != 0)
341 if ((index
< 0) || (index
>= ORINOCO_MAX_KEYS
))
342 index
= priv
->tx_key
;
345 if (!priv
->encode_alg
)
346 erq
->flags
|= IW_ENCODE_DISABLED
;
347 erq
->flags
|= index
+ 1;
349 if (priv
->wep_restrict
)
350 erq
->flags
|= IW_ENCODE_RESTRICTED
;
352 erq
->flags
|= IW_ENCODE_OPEN
;
354 erq
->length
= priv
->keys
[index
].key_len
;
356 memcpy(keybuf
, priv
->keys
[index
].key
, erq
->length
);
358 orinoco_unlock(priv
, &flags
);
362 static int orinoco_ioctl_setessid(struct net_device
*dev
,
363 struct iw_request_info
*info
,
364 struct iw_point
*erq
,
367 struct orinoco_private
*priv
= ndev_priv(dev
);
370 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
371 * anyway... - Jean II */
373 /* Hum... Should not use Wireless Extension constant (may change),
374 * should use our own... - Jean II */
375 if (erq
->length
> IW_ESSID_MAX_SIZE
)
378 if (orinoco_lock(priv
, &flags
) != 0)
381 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
382 memset(priv
->desired_essid
, 0, sizeof(priv
->desired_essid
));
384 /* If not ANY, get the new ESSID */
386 memcpy(priv
->desired_essid
, essidbuf
, erq
->length
);
388 orinoco_unlock(priv
, &flags
);
390 return -EINPROGRESS
; /* Call commit handler */
393 static int orinoco_ioctl_getessid(struct net_device
*dev
,
394 struct iw_request_info
*info
,
395 struct iw_point
*erq
,
398 struct orinoco_private
*priv
= ndev_priv(dev
);
403 if (netif_running(dev
)) {
404 err
= orinoco_hw_get_essid(priv
, &active
, essidbuf
);
409 if (orinoco_lock(priv
, &flags
) != 0)
411 memcpy(essidbuf
, priv
->desired_essid
, IW_ESSID_MAX_SIZE
);
412 erq
->length
= strlen(priv
->desired_essid
);
413 orinoco_unlock(priv
, &flags
);
421 static int orinoco_ioctl_setfreq(struct net_device
*dev
,
422 struct iw_request_info
*info
,
426 struct orinoco_private
*priv
= ndev_priv(dev
);
429 int err
= -EINPROGRESS
; /* Call commit handler */
431 /* In infrastructure mode the AP sets the channel */
432 if (priv
->iw_mode
== NL80211_IFTYPE_STATION
)
435 if ((frq
->e
== 0) && (frq
->m
<= 1000)) {
436 /* Setting by channel number */
439 /* Setting by frequency */
443 /* Calculate denominator to rescale to MHz */
444 for (i
= 0; i
< (6 - frq
->e
); i
++)
447 chan
= ieee80211_freq_to_dsss_chan(frq
->m
/ denom
);
450 if ((chan
< 1) || (chan
> NUM_CHANNELS
) ||
451 !(priv
->channel_mask
& (1 << (chan
-1))))
454 if (orinoco_lock(priv
, &flags
) != 0)
457 priv
->channel
= chan
;
458 if (priv
->iw_mode
== NL80211_IFTYPE_MONITOR
) {
459 /* Fast channel change - no commit if successful */
460 hermes_t
*hw
= &priv
->hw
;
461 err
= hermes_docmd_wait(hw
, HERMES_CMD_TEST
|
462 HERMES_TEST_SET_CHANNEL
,
465 orinoco_unlock(priv
, &flags
);
470 static int orinoco_ioctl_getfreq(struct net_device
*dev
,
471 struct iw_request_info
*info
,
475 struct orinoco_private
*priv
= ndev_priv(dev
);
478 /* Locking done in there */
479 tmp
= orinoco_hw_get_freq(priv
);
483 frq
->m
= tmp
* 100000;
489 static int orinoco_ioctl_getsens(struct net_device
*dev
,
490 struct iw_request_info
*info
,
491 struct iw_param
*srq
,
494 struct orinoco_private
*priv
= ndev_priv(dev
);
495 hermes_t
*hw
= &priv
->hw
;
500 if (!priv
->has_sensitivity
)
503 if (orinoco_lock(priv
, &flags
) != 0)
505 err
= hermes_read_wordrec(hw
, USER_BAP
,
506 HERMES_RID_CNFSYSTEMSCALE
, &val
);
507 orinoco_unlock(priv
, &flags
);
513 srq
->fixed
= 0; /* auto */
518 static int orinoco_ioctl_setsens(struct net_device
*dev
,
519 struct iw_request_info
*info
,
520 struct iw_param
*srq
,
523 struct orinoco_private
*priv
= ndev_priv(dev
);
524 int val
= srq
->value
;
527 if (!priv
->has_sensitivity
)
530 if ((val
< 1) || (val
> 3))
533 if (orinoco_lock(priv
, &flags
) != 0)
535 priv
->ap_density
= val
;
536 orinoco_unlock(priv
, &flags
);
538 return -EINPROGRESS
; /* Call commit handler */
541 static int orinoco_ioctl_setrts(struct net_device
*dev
,
542 struct iw_request_info
*info
,
543 struct iw_param
*rrq
,
546 struct orinoco_private
*priv
= ndev_priv(dev
);
547 int val
= rrq
->value
;
553 if ((val
< 0) || (val
> 2347))
556 if (orinoco_lock(priv
, &flags
) != 0)
559 priv
->rts_thresh
= val
;
560 orinoco_unlock(priv
, &flags
);
562 return -EINPROGRESS
; /* Call commit handler */
565 static int orinoco_ioctl_getrts(struct net_device
*dev
,
566 struct iw_request_info
*info
,
567 struct iw_param
*rrq
,
570 struct orinoco_private
*priv
= ndev_priv(dev
);
572 rrq
->value
= priv
->rts_thresh
;
573 rrq
->disabled
= (rrq
->value
== 2347);
579 static int orinoco_ioctl_setfrag(struct net_device
*dev
,
580 struct iw_request_info
*info
,
581 struct iw_param
*frq
,
584 struct orinoco_private
*priv
= ndev_priv(dev
);
585 int err
= -EINPROGRESS
; /* Call commit handler */
588 if (orinoco_lock(priv
, &flags
) != 0)
593 priv
->mwo_robust
= 0;
596 printk(KERN_WARNING
"%s: Fixed fragmentation "
597 "is not supported on this firmware. "
598 "Using MWO robust instead.\n",
600 priv
->mwo_robust
= 1;
604 priv
->frag_thresh
= 2346;
606 if ((frq
->value
< 256) || (frq
->value
> 2346))
610 priv
->frag_thresh
= frq
->value
& ~0x1;
614 orinoco_unlock(priv
, &flags
);
619 static int orinoco_ioctl_getfrag(struct net_device
*dev
,
620 struct iw_request_info
*info
,
621 struct iw_param
*frq
,
624 struct orinoco_private
*priv
= ndev_priv(dev
);
625 hermes_t
*hw
= &priv
->hw
;
630 if (orinoco_lock(priv
, &flags
) != 0)
634 err
= hermes_read_wordrec(hw
, USER_BAP
,
635 HERMES_RID_CNFMWOROBUST_AGERE
,
640 frq
->value
= val
? 2347 : 0;
641 frq
->disabled
= !val
;
644 err
= hermes_read_wordrec(hw
, USER_BAP
,
645 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD
,
651 frq
->disabled
= (val
>= 2346);
655 orinoco_unlock(priv
, &flags
);
660 static int orinoco_ioctl_setrate(struct net_device
*dev
,
661 struct iw_request_info
*info
,
662 struct iw_param
*rrq
,
665 struct orinoco_private
*priv
= ndev_priv(dev
);
667 int bitrate
; /* 100s of kilobits */
670 /* As the user space doesn't know our highest rate, it uses -1
671 * to ask us to set the highest rate. Test it using "iwconfig
672 * ethX rate auto" - Jean II */
673 if (rrq
->value
== -1)
676 if (rrq
->value
% 100000)
678 bitrate
= rrq
->value
/ 100000;
681 ratemode
= orinoco_get_bitratemode(bitrate
, !rrq
->fixed
);
686 if (orinoco_lock(priv
, &flags
) != 0)
688 priv
->bitratemode
= ratemode
;
689 orinoco_unlock(priv
, &flags
);
694 static int orinoco_ioctl_getrate(struct net_device
*dev
,
695 struct iw_request_info
*info
,
696 struct iw_param
*rrq
,
699 struct orinoco_private
*priv
= ndev_priv(dev
);
701 int bitrate
, automatic
;
704 if (orinoco_lock(priv
, &flags
) != 0)
707 orinoco_get_ratemode_cfg(priv
->bitratemode
, &bitrate
, &automatic
);
709 /* If the interface is running we try to find more about the
711 if (netif_running(dev
))
712 err
= orinoco_hw_get_act_bitrate(priv
, &bitrate
);
714 orinoco_unlock(priv
, &flags
);
716 rrq
->value
= bitrate
;
717 rrq
->fixed
= !automatic
;
723 static int orinoco_ioctl_setpower(struct net_device
*dev
,
724 struct iw_request_info
*info
,
725 struct iw_param
*prq
,
728 struct orinoco_private
*priv
= ndev_priv(dev
);
729 int err
= -EINPROGRESS
; /* Call commit handler */
732 if (orinoco_lock(priv
, &flags
) != 0)
738 switch (prq
->flags
& IW_POWER_MODE
) {
739 case IW_POWER_UNICAST_R
:
748 /* No flags : but we may have a value - Jean II */
755 if (prq
->flags
& IW_POWER_TIMEOUT
) {
757 priv
->pm_timeout
= prq
->value
/ 1000;
759 if (prq
->flags
& IW_POWER_PERIOD
) {
761 priv
->pm_period
= prq
->value
/ 1000;
763 /* It's valid to not have a value if we are just toggling
764 * the flags... Jean II */
772 orinoco_unlock(priv
, &flags
);
777 static int orinoco_ioctl_getpower(struct net_device
*dev
,
778 struct iw_request_info
*info
,
779 struct iw_param
*prq
,
782 struct orinoco_private
*priv
= ndev_priv(dev
);
783 hermes_t
*hw
= &priv
->hw
;
785 u16 enable
, period
, timeout
, mcast
;
788 if (orinoco_lock(priv
, &flags
) != 0)
791 err
= hermes_read_wordrec(hw
, USER_BAP
,
792 HERMES_RID_CNFPMENABLED
, &enable
);
796 err
= hermes_read_wordrec(hw
, USER_BAP
,
797 HERMES_RID_CNFMAXSLEEPDURATION
, &period
);
801 err
= hermes_read_wordrec(hw
, USER_BAP
,
802 HERMES_RID_CNFPMHOLDOVERDURATION
, &timeout
);
806 err
= hermes_read_wordrec(hw
, USER_BAP
,
807 HERMES_RID_CNFMULTICASTRECEIVE
, &mcast
);
811 prq
->disabled
= !enable
;
812 /* Note : by default, display the period */
813 if ((prq
->flags
& IW_POWER_TYPE
) == IW_POWER_TIMEOUT
) {
814 prq
->flags
= IW_POWER_TIMEOUT
;
815 prq
->value
= timeout
* 1000;
817 prq
->flags
= IW_POWER_PERIOD
;
818 prq
->value
= period
* 1000;
821 prq
->flags
|= IW_POWER_ALL_R
;
823 prq
->flags
|= IW_POWER_UNICAST_R
;
826 orinoco_unlock(priv
, &flags
);
831 static int orinoco_ioctl_set_encodeext(struct net_device
*dev
,
832 struct iw_request_info
*info
,
833 union iwreq_data
*wrqu
,
836 struct orinoco_private
*priv
= ndev_priv(dev
);
837 struct iw_point
*encoding
= &wrqu
->encoding
;
838 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*)extra
;
839 int idx
, alg
= ext
->alg
, set_key
= 1;
843 if (orinoco_lock(priv
, &flags
) != 0)
846 /* Determine and validate the key index */
847 idx
= encoding
->flags
& IW_ENCODE_INDEX
;
849 if ((idx
< 1) || (idx
> 4))
855 if (encoding
->flags
& IW_ENCODE_DISABLED
)
856 alg
= IW_ENCODE_ALG_NONE
;
858 if (priv
->has_wpa
&& (alg
!= IW_ENCODE_ALG_TKIP
)) {
859 /* Clear any TKIP TX key we had */
860 (void) orinoco_clear_tkip_key(priv
, priv
->tx_key
);
863 if (ext
->ext_flags
& IW_ENCODE_EXT_SET_TX_KEY
) {
865 set_key
= ((alg
== IW_ENCODE_ALG_TKIP
) ||
866 (ext
->key_len
> 0)) ? 1 : 0;
870 /* Set the requested key first */
872 case IW_ENCODE_ALG_NONE
:
873 priv
->encode_alg
= ORINOCO_ALG_NONE
;
874 err
= orinoco_set_key(priv
, idx
, ORINOCO_ALG_NONE
,
878 case IW_ENCODE_ALG_WEP
:
879 if (ext
->key_len
<= 0)
882 priv
->encode_alg
= ORINOCO_ALG_WEP
;
883 err
= orinoco_set_key(priv
, idx
, ORINOCO_ALG_WEP
,
884 ext
->key
, ext
->key_len
, NULL
, 0);
887 case IW_ENCODE_ALG_TKIP
:
891 if (!priv
->has_wpa
||
892 (ext
->key_len
> sizeof(struct orinoco_tkip_key
)))
895 priv
->encode_alg
= ORINOCO_ALG_TKIP
;
897 if (ext
->ext_flags
& IW_ENCODE_EXT_RX_SEQ_VALID
)
898 tkip_iv
= &ext
->rx_seq
[0];
900 err
= orinoco_set_key(priv
, idx
, ORINOCO_ALG_TKIP
,
901 ext
->key
, ext
->key_len
, tkip_iv
,
904 err
= __orinoco_hw_set_tkip_key(priv
, idx
,
905 ext
->ext_flags
& IW_ENCODE_EXT_SET_TX_KEY
,
907 tkip_iv
, ORINOCO_SEQ_LEN
, NULL
, 0);
909 printk(KERN_ERR
"%s: Error %d setting TKIP key"
910 "\n", dev
->name
, err
);
920 orinoco_unlock(priv
, &flags
);
925 static int orinoco_ioctl_get_encodeext(struct net_device
*dev
,
926 struct iw_request_info
*info
,
927 union iwreq_data
*wrqu
,
930 struct orinoco_private
*priv
= ndev_priv(dev
);
931 struct iw_point
*encoding
= &wrqu
->encoding
;
932 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*)extra
;
933 int idx
, max_key_len
;
937 if (orinoco_lock(priv
, &flags
) != 0)
941 max_key_len
= encoding
->length
- sizeof(*ext
);
945 idx
= encoding
->flags
& IW_ENCODE_INDEX
;
947 if ((idx
< 1) || (idx
> 4))
953 encoding
->flags
= idx
+ 1;
954 memset(ext
, 0, sizeof(*ext
));
956 switch (priv
->encode_alg
) {
957 case ORINOCO_ALG_NONE
:
958 ext
->alg
= IW_ENCODE_ALG_NONE
;
960 encoding
->flags
|= IW_ENCODE_DISABLED
;
962 case ORINOCO_ALG_WEP
:
963 ext
->alg
= IW_ENCODE_ALG_WEP
;
964 ext
->key_len
= min(priv
->keys
[idx
].key_len
, max_key_len
);
965 memcpy(ext
->key
, priv
->keys
[idx
].key
, ext
->key_len
);
966 encoding
->flags
|= IW_ENCODE_ENABLED
;
968 case ORINOCO_ALG_TKIP
:
969 ext
->alg
= IW_ENCODE_ALG_TKIP
;
970 ext
->key_len
= min(priv
->keys
[idx
].key_len
, max_key_len
);
971 memcpy(ext
->key
, priv
->keys
[idx
].key
, ext
->key_len
);
972 encoding
->flags
|= IW_ENCODE_ENABLED
;
978 orinoco_unlock(priv
, &flags
);
983 static int orinoco_ioctl_set_auth(struct net_device
*dev
,
984 struct iw_request_info
*info
,
985 union iwreq_data
*wrqu
, char *extra
)
987 struct orinoco_private
*priv
= ndev_priv(dev
);
988 hermes_t
*hw
= &priv
->hw
;
989 struct iw_param
*param
= &wrqu
->param
;
991 int ret
= -EINPROGRESS
;
993 if (orinoco_lock(priv
, &flags
) != 0)
996 switch (param
->flags
& IW_AUTH_INDEX
) {
997 case IW_AUTH_WPA_VERSION
:
998 case IW_AUTH_CIPHER_PAIRWISE
:
999 case IW_AUTH_CIPHER_GROUP
:
1000 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
1001 case IW_AUTH_PRIVACY_INVOKED
:
1002 case IW_AUTH_DROP_UNENCRYPTED
:
1004 * orinoco does not use these parameters
1008 case IW_AUTH_KEY_MGMT
:
1009 /* wl_lkm implies value 2 == PSK for Hermes I
1010 * which ties in with WEXT
1011 * no other hints tho :(
1013 priv
->key_mgmt
= param
->value
;
1016 case IW_AUTH_TKIP_COUNTERMEASURES
:
1017 /* When countermeasures are enabled, shut down the
1018 * card; when disabled, re-enable the card. This must
1019 * take effect immediately.
1021 * TODO: Make sure that the EAPOL message is getting
1022 * out before card disabled
1025 priv
->tkip_cm_active
= 1;
1026 ret
= hermes_enable_port(hw
, 0);
1028 priv
->tkip_cm_active
= 0;
1029 ret
= hermes_disable_port(hw
, 0);
1033 case IW_AUTH_80211_AUTH_ALG
:
1034 if (param
->value
& IW_AUTH_ALG_SHARED_KEY
)
1035 priv
->wep_restrict
= 1;
1036 else if (param
->value
& IW_AUTH_ALG_OPEN_SYSTEM
)
1037 priv
->wep_restrict
= 0;
1042 case IW_AUTH_WPA_ENABLED
:
1043 if (priv
->has_wpa
) {
1044 priv
->wpa_enabled
= param
->value
? 1 : 0;
1048 /* else silently accept disable of WPA */
1049 priv
->wpa_enabled
= 0;
1057 orinoco_unlock(priv
, &flags
);
1061 static int orinoco_ioctl_get_auth(struct net_device
*dev
,
1062 struct iw_request_info
*info
,
1063 union iwreq_data
*wrqu
, char *extra
)
1065 struct orinoco_private
*priv
= ndev_priv(dev
);
1066 struct iw_param
*param
= &wrqu
->param
;
1067 unsigned long flags
;
1070 if (orinoco_lock(priv
, &flags
) != 0)
1073 switch (param
->flags
& IW_AUTH_INDEX
) {
1074 case IW_AUTH_KEY_MGMT
:
1075 param
->value
= priv
->key_mgmt
;
1078 case IW_AUTH_TKIP_COUNTERMEASURES
:
1079 param
->value
= priv
->tkip_cm_active
;
1082 case IW_AUTH_80211_AUTH_ALG
:
1083 if (priv
->wep_restrict
)
1084 param
->value
= IW_AUTH_ALG_SHARED_KEY
;
1086 param
->value
= IW_AUTH_ALG_OPEN_SYSTEM
;
1089 case IW_AUTH_WPA_ENABLED
:
1090 param
->value
= priv
->wpa_enabled
;
1097 orinoco_unlock(priv
, &flags
);
1101 static int orinoco_ioctl_set_genie(struct net_device
*dev
,
1102 struct iw_request_info
*info
,
1103 union iwreq_data
*wrqu
, char *extra
)
1105 struct orinoco_private
*priv
= ndev_priv(dev
);
1107 unsigned long flags
;
1109 /* cut off at IEEE80211_MAX_DATA_LEN */
1110 if ((wrqu
->data
.length
> IEEE80211_MAX_DATA_LEN
) ||
1111 (wrqu
->data
.length
&& (extra
== NULL
)))
1114 if (wrqu
->data
.length
) {
1115 buf
= kmalloc(wrqu
->data
.length
, GFP_KERNEL
);
1119 memcpy(buf
, extra
, wrqu
->data
.length
);
1123 if (orinoco_lock(priv
, &flags
) != 0) {
1128 kfree(priv
->wpa_ie
);
1130 priv
->wpa_ie_len
= wrqu
->data
.length
;
1133 /* Looks like wl_lkm wants to check the auth alg, and
1134 * somehow pass it to the firmware.
1135 * Instead it just calls the key mgmt rid
1136 * - we do this in set auth.
1140 orinoco_unlock(priv
, &flags
);
1144 static int orinoco_ioctl_get_genie(struct net_device
*dev
,
1145 struct iw_request_info
*info
,
1146 union iwreq_data
*wrqu
, char *extra
)
1148 struct orinoco_private
*priv
= ndev_priv(dev
);
1149 unsigned long flags
;
1152 if (orinoco_lock(priv
, &flags
) != 0)
1155 if ((priv
->wpa_ie_len
== 0) || (priv
->wpa_ie
== NULL
)) {
1156 wrqu
->data
.length
= 0;
1160 if (wrqu
->data
.length
< priv
->wpa_ie_len
) {
1165 wrqu
->data
.length
= priv
->wpa_ie_len
;
1166 memcpy(extra
, priv
->wpa_ie
, priv
->wpa_ie_len
);
1169 orinoco_unlock(priv
, &flags
);
1173 static int orinoco_ioctl_set_mlme(struct net_device
*dev
,
1174 struct iw_request_info
*info
,
1175 union iwreq_data
*wrqu
, char *extra
)
1177 struct orinoco_private
*priv
= ndev_priv(dev
);
1178 struct iw_mlme
*mlme
= (struct iw_mlme
*)extra
;
1179 unsigned long flags
;
1182 if (orinoco_lock(priv
, &flags
) != 0)
1185 switch (mlme
->cmd
) {
1186 case IW_MLME_DEAUTH
:
1187 /* silently ignore */
1190 case IW_MLME_DISASSOC
:
1192 ret
= orinoco_hw_disassociate(priv
, mlme
->addr
.sa_data
,
1200 orinoco_unlock(priv
, &flags
);
1204 static int orinoco_ioctl_getretry(struct net_device
*dev
,
1205 struct iw_request_info
*info
,
1206 struct iw_param
*rrq
,
1209 struct orinoco_private
*priv
= ndev_priv(dev
);
1210 hermes_t
*hw
= &priv
->hw
;
1212 u16 short_limit
, long_limit
, lifetime
;
1213 unsigned long flags
;
1215 if (orinoco_lock(priv
, &flags
) != 0)
1218 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_SHORTRETRYLIMIT
,
1223 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_LONGRETRYLIMIT
,
1228 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_MAXTRANSMITLIFETIME
,
1233 rrq
->disabled
= 0; /* Can't be disabled */
1235 /* Note : by default, display the retry number */
1236 if ((rrq
->flags
& IW_RETRY_TYPE
) == IW_RETRY_LIFETIME
) {
1237 rrq
->flags
= IW_RETRY_LIFETIME
;
1238 rrq
->value
= lifetime
* 1000; /* ??? */
1240 /* By default, display the min number */
1241 if ((rrq
->flags
& IW_RETRY_LONG
)) {
1242 rrq
->flags
= IW_RETRY_LIMIT
| IW_RETRY_LONG
;
1243 rrq
->value
= long_limit
;
1245 rrq
->flags
= IW_RETRY_LIMIT
;
1246 rrq
->value
= short_limit
;
1247 if (short_limit
!= long_limit
)
1248 rrq
->flags
|= IW_RETRY_SHORT
;
1253 orinoco_unlock(priv
, &flags
);
1258 static int orinoco_ioctl_reset(struct net_device
*dev
,
1259 struct iw_request_info
*info
,
1263 struct orinoco_private
*priv
= ndev_priv(dev
);
1265 if (!capable(CAP_NET_ADMIN
))
1268 if (info
->cmd
== (SIOCIWFIRSTPRIV
+ 0x1)) {
1269 printk(KERN_DEBUG
"%s: Forcing reset!\n", dev
->name
);
1271 /* Firmware reset */
1272 orinoco_reset(&priv
->reset_work
);
1274 printk(KERN_DEBUG
"%s: Force scheduling reset!\n", dev
->name
);
1276 schedule_work(&priv
->reset_work
);
1282 static int orinoco_ioctl_setibssport(struct net_device
*dev
,
1283 struct iw_request_info
*info
,
1288 struct orinoco_private
*priv
= ndev_priv(dev
);
1289 int val
= *((int *) extra
);
1290 unsigned long flags
;
1292 if (orinoco_lock(priv
, &flags
) != 0)
1295 priv
->ibss_port
= val
;
1297 /* Actually update the mode we are using */
1298 set_port_type(priv
);
1300 orinoco_unlock(priv
, &flags
);
1301 return -EINPROGRESS
; /* Call commit handler */
1304 static int orinoco_ioctl_getibssport(struct net_device
*dev
,
1305 struct iw_request_info
*info
,
1309 struct orinoco_private
*priv
= ndev_priv(dev
);
1310 int *val
= (int *) extra
;
1312 *val
= priv
->ibss_port
;
1316 static int orinoco_ioctl_setport3(struct net_device
*dev
,
1317 struct iw_request_info
*info
,
1321 struct orinoco_private
*priv
= ndev_priv(dev
);
1322 int val
= *((int *) extra
);
1324 unsigned long flags
;
1326 if (orinoco_lock(priv
, &flags
) != 0)
1330 case 0: /* Try to do IEEE ad-hoc mode */
1331 if (!priv
->has_ibss
) {
1335 priv
->prefer_port3
= 0;
1339 case 1: /* Try to do Lucent proprietary ad-hoc mode */
1340 if (!priv
->has_port3
) {
1344 priv
->prefer_port3
= 1;
1352 /* Actually update the mode we are using */
1353 set_port_type(priv
);
1357 orinoco_unlock(priv
, &flags
);
1362 static int orinoco_ioctl_getport3(struct net_device
*dev
,
1363 struct iw_request_info
*info
,
1367 struct orinoco_private
*priv
= ndev_priv(dev
);
1368 int *val
= (int *) extra
;
1370 *val
= priv
->prefer_port3
;
1374 static int orinoco_ioctl_setpreamble(struct net_device
*dev
,
1375 struct iw_request_info
*info
,
1379 struct orinoco_private
*priv
= ndev_priv(dev
);
1380 unsigned long flags
;
1383 if (!priv
->has_preamble
)
1386 /* 802.11b has recently defined some short preamble.
1387 * Basically, the Phy header has been reduced in size.
1388 * This increase performance, especially at high rates
1389 * (the preamble is transmitted at 1Mb/s), unfortunately
1390 * this give compatibility troubles... - Jean II */
1391 val
= *((int *) extra
);
1393 if (orinoco_lock(priv
, &flags
) != 0)
1401 orinoco_unlock(priv
, &flags
);
1403 return -EINPROGRESS
; /* Call commit handler */
1406 static int orinoco_ioctl_getpreamble(struct net_device
*dev
,
1407 struct iw_request_info
*info
,
1411 struct orinoco_private
*priv
= ndev_priv(dev
);
1412 int *val
= (int *) extra
;
1414 if (!priv
->has_preamble
)
1417 *val
= priv
->preamble
;
1421 /* ioctl interface to hermes_read_ltv()
1422 * To use with iwpriv, pass the RID as the token argument, e.g.
1423 * iwpriv get_rid [0xfc00]
1424 * At least Wireless Tools 25 is required to use iwpriv.
1425 * For Wireless Tools 25 and 26 append "dummy" are the end. */
1426 static int orinoco_ioctl_getrid(struct net_device
*dev
,
1427 struct iw_request_info
*info
,
1428 struct iw_point
*data
,
1431 struct orinoco_private
*priv
= ndev_priv(dev
);
1432 hermes_t
*hw
= &priv
->hw
;
1433 int rid
= data
->flags
;
1436 unsigned long flags
;
1438 /* It's a "get" function, but we don't want users to access the
1439 * WEP key and other raw firmware data */
1440 if (!capable(CAP_NET_ADMIN
))
1443 if (rid
< 0xfc00 || rid
> 0xffff)
1446 if (orinoco_lock(priv
, &flags
) != 0)
1449 err
= hermes_read_ltv(hw
, USER_BAP
, rid
, MAX_RID_LEN
, &length
,
1454 data
->length
= min_t(u16
, HERMES_RECLEN_TO_BYTES(length
),
1458 orinoco_unlock(priv
, &flags
);
1463 /* Commit handler, called after set operations */
1464 static int orinoco_ioctl_commit(struct net_device
*dev
,
1465 struct iw_request_info
*info
,
1469 struct orinoco_private
*priv
= ndev_priv(dev
);
1470 unsigned long flags
;
1476 if (orinoco_lock(priv
, &flags
) != 0)
1479 err
= orinoco_commit(priv
);
1481 orinoco_unlock(priv
, &flags
);
1485 static const struct iw_priv_args orinoco_privtab
[] = {
1486 { SIOCIWFIRSTPRIV
+ 0x0, 0, 0, "force_reset" },
1487 { SIOCIWFIRSTPRIV
+ 0x1, 0, 0, "card_reset" },
1488 { SIOCIWFIRSTPRIV
+ 0x2, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
1490 { SIOCIWFIRSTPRIV
+ 0x3, 0, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
1492 { SIOCIWFIRSTPRIV
+ 0x4, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
1493 0, "set_preamble" },
1494 { SIOCIWFIRSTPRIV
+ 0x5, 0, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
1496 { SIOCIWFIRSTPRIV
+ 0x6, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
1497 0, "set_ibssport" },
1498 { SIOCIWFIRSTPRIV
+ 0x7, 0, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
1500 { SIOCIWFIRSTPRIV
+ 0x9, 0, IW_PRIV_TYPE_BYTE
| MAX_RID_LEN
,
1506 * Structures to export the Wireless Handlers
1509 #define STD_IW_HANDLER(id, func) \
1510 [IW_IOCTL_IDX(id)] = (iw_handler) func
1511 static const iw_handler orinoco_handler
[] = {
1512 STD_IW_HANDLER(SIOCSIWCOMMIT
, orinoco_ioctl_commit
),
1513 STD_IW_HANDLER(SIOCGIWNAME
, cfg80211_wext_giwname
),
1514 STD_IW_HANDLER(SIOCSIWFREQ
, orinoco_ioctl_setfreq
),
1515 STD_IW_HANDLER(SIOCGIWFREQ
, orinoco_ioctl_getfreq
),
1516 STD_IW_HANDLER(SIOCSIWMODE
, cfg80211_wext_siwmode
),
1517 STD_IW_HANDLER(SIOCGIWMODE
, cfg80211_wext_giwmode
),
1518 STD_IW_HANDLER(SIOCSIWSENS
, orinoco_ioctl_setsens
),
1519 STD_IW_HANDLER(SIOCGIWSENS
, orinoco_ioctl_getsens
),
1520 STD_IW_HANDLER(SIOCGIWRANGE
, cfg80211_wext_giwrange
),
1521 STD_IW_HANDLER(SIOCSIWSPY
, iw_handler_set_spy
),
1522 STD_IW_HANDLER(SIOCGIWSPY
, iw_handler_get_spy
),
1523 STD_IW_HANDLER(SIOCSIWTHRSPY
, iw_handler_set_thrspy
),
1524 STD_IW_HANDLER(SIOCGIWTHRSPY
, iw_handler_get_thrspy
),
1525 STD_IW_HANDLER(SIOCSIWAP
, orinoco_ioctl_setwap
),
1526 STD_IW_HANDLER(SIOCGIWAP
, orinoco_ioctl_getwap
),
1527 STD_IW_HANDLER(SIOCSIWSCAN
, cfg80211_wext_siwscan
),
1528 STD_IW_HANDLER(SIOCGIWSCAN
, cfg80211_wext_giwscan
),
1529 STD_IW_HANDLER(SIOCSIWESSID
, orinoco_ioctl_setessid
),
1530 STD_IW_HANDLER(SIOCGIWESSID
, orinoco_ioctl_getessid
),
1531 STD_IW_HANDLER(SIOCSIWRATE
, orinoco_ioctl_setrate
),
1532 STD_IW_HANDLER(SIOCGIWRATE
, orinoco_ioctl_getrate
),
1533 STD_IW_HANDLER(SIOCSIWRTS
, orinoco_ioctl_setrts
),
1534 STD_IW_HANDLER(SIOCGIWRTS
, orinoco_ioctl_getrts
),
1535 STD_IW_HANDLER(SIOCSIWFRAG
, orinoco_ioctl_setfrag
),
1536 STD_IW_HANDLER(SIOCGIWFRAG
, orinoco_ioctl_getfrag
),
1537 STD_IW_HANDLER(SIOCGIWRETRY
, orinoco_ioctl_getretry
),
1538 STD_IW_HANDLER(SIOCSIWENCODE
, orinoco_ioctl_setiwencode
),
1539 STD_IW_HANDLER(SIOCGIWENCODE
, orinoco_ioctl_getiwencode
),
1540 STD_IW_HANDLER(SIOCSIWPOWER
, orinoco_ioctl_setpower
),
1541 STD_IW_HANDLER(SIOCGIWPOWER
, orinoco_ioctl_getpower
),
1542 STD_IW_HANDLER(SIOCSIWGENIE
, orinoco_ioctl_set_genie
),
1543 STD_IW_HANDLER(SIOCGIWGENIE
, orinoco_ioctl_get_genie
),
1544 STD_IW_HANDLER(SIOCSIWMLME
, orinoco_ioctl_set_mlme
),
1545 STD_IW_HANDLER(SIOCSIWAUTH
, orinoco_ioctl_set_auth
),
1546 STD_IW_HANDLER(SIOCGIWAUTH
, orinoco_ioctl_get_auth
),
1547 STD_IW_HANDLER(SIOCSIWENCODEEXT
, orinoco_ioctl_set_encodeext
),
1548 STD_IW_HANDLER(SIOCGIWENCODEEXT
, orinoco_ioctl_get_encodeext
),
1553 Added typecasting since we no longer use iwreq_data -- Moustafa
1555 static const iw_handler orinoco_private_handler
[] = {
1556 [0] = (iw_handler
) orinoco_ioctl_reset
,
1557 [1] = (iw_handler
) orinoco_ioctl_reset
,
1558 [2] = (iw_handler
) orinoco_ioctl_setport3
,
1559 [3] = (iw_handler
) orinoco_ioctl_getport3
,
1560 [4] = (iw_handler
) orinoco_ioctl_setpreamble
,
1561 [5] = (iw_handler
) orinoco_ioctl_getpreamble
,
1562 [6] = (iw_handler
) orinoco_ioctl_setibssport
,
1563 [7] = (iw_handler
) orinoco_ioctl_getibssport
,
1564 [9] = (iw_handler
) orinoco_ioctl_getrid
,
1567 const struct iw_handler_def orinoco_handler_def
= {
1568 .num_standard
= ARRAY_SIZE(orinoco_handler
),
1569 .num_private
= ARRAY_SIZE(orinoco_private_handler
),
1570 .num_private_args
= ARRAY_SIZE(orinoco_privtab
),
1571 .standard
= orinoco_handler
,
1572 .private = orinoco_private_handler
,
1573 .private_args
= orinoco_privtab
,
1574 .get_wireless_stats
= orinoco_get_wireless_stats
,