d261423ecf620979fa8bc172460504277a7be785
[safe/jmp/linux-2.6] / drivers / net / wireless / orinoco / wext.c
1 /* Wireless extensions support.
2  *
3  * See copyright notice in main.c
4  */
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>
11
12 #include "hermes.h"
13 #include "hermes_rid.h"
14 #include "orinoco.h"
15
16 #include "hw.h"
17 #include "mic.h"
18 #include "scan.h"
19 #include "main.h"
20
21 #include "wext.h"
22
23 #define MAX_RID_LEN 1024
24
25 /* Helper routine to record keys
26  * It is called under orinoco_lock so it may not sleep */
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)
30 {
31         kzfree(priv->keys[index].key);
32         kzfree(priv->keys[index].seq);
33
34         if (key_len) {
35                 priv->keys[index].key = kzalloc(key_len, GFP_ATOMIC);
36                 if (!priv->keys[index].key)
37                         goto nomem;
38         } else
39                 priv->keys[index].key = NULL;
40
41         if (seq_len) {
42                 priv->keys[index].seq = kzalloc(seq_len, GFP_ATOMIC);
43                 if (!priv->keys[index].seq)
44                         goto free_key;
45         } else
46                 priv->keys[index].seq = NULL;
47
48         priv->keys[index].key_len = key_len;
49         priv->keys[index].seq_len = seq_len;
50
51         if (key_len)
52                 memcpy(priv->keys[index].key, key, key_len);
53         if (seq_len)
54                 memcpy(priv->keys[index].seq, seq, seq_len);
55
56         switch (alg) {
57         case ORINOCO_ALG_TKIP:
58                 priv->keys[index].cipher = WLAN_CIPHER_SUITE_TKIP;
59                 break;
60
61         case ORINOCO_ALG_WEP:
62                 priv->keys[index].cipher = (key_len > SMALL_KEY_SIZE) ?
63                         WLAN_CIPHER_SUITE_WEP104 : WLAN_CIPHER_SUITE_WEP40;
64                 break;
65
66         case ORINOCO_ALG_NONE:
67         default:
68                 priv->keys[index].cipher = 0;
69                 break;
70         }
71
72         return 0;
73
74 free_key:
75         kfree(priv->keys[index].key);
76         priv->keys[index].key = NULL;
77
78 nomem:
79         priv->keys[index].key_len = 0;
80         priv->keys[index].seq_len = 0;
81         priv->keys[index].cipher = 0;
82
83         return -ENOMEM;
84 }
85
86 static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
87 {
88         struct orinoco_private *priv = ndev_priv(dev);
89         hermes_t *hw = &priv->hw;
90         struct iw_statistics *wstats = &priv->wstats;
91         int err;
92         unsigned long flags;
93
94         if (!netif_device_present(dev)) {
95                 printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
96                        dev->name);
97                 return NULL; /* FIXME: Can we do better than this? */
98         }
99
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)
103                 return wstats;
104
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);
115
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;
126                 }
127         } else {
128                 struct {
129                         __le16 qual, signal, noise, unused;
130                 } __attribute__ ((packed)) cq;
131
132                 err = HERMES_READ_RECORD(hw, USER_BAP,
133                                          HERMES_RID_COMMSQUALITY, &cq);
134
135                 if (!err) {
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;
141                 }
142         }
143
144         orinoco_unlock(priv, &flags);
145         return wstats;
146 }
147
148 /********************************************************************/
149 /* Wireless extensions                                              */
150 /********************************************************************/
151
152 static int orinoco_ioctl_setwap(struct net_device *dev,
153                                 struct iw_request_info *info,
154                                 struct sockaddr *ap_addr,
155                                 char *extra)
156 {
157         struct orinoco_private *priv = ndev_priv(dev);
158         int err = -EINPROGRESS;         /* Call commit handler */
159         unsigned long flags;
160         static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
161         static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
162
163         if (orinoco_lock(priv, &flags) != 0)
164                 return -EBUSY;
165
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);
171
172                 /* "off" means keep existing connection */
173                 if (ap_addr->sa_data[0] == 0) {
174                         __orinoco_hw_set_wap(priv);
175                         err = 0;
176                 }
177                 goto out;
178         }
179
180         if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
181                 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
182                        "support manual roaming\n",
183                        dev->name);
184                 err = -EOPNOTSUPP;
185                 goto out;
186         }
187
188         if (priv->iw_mode != NL80211_IFTYPE_STATION) {
189                 printk(KERN_WARNING "%s: Manual roaming supported only in "
190                        "managed mode\n", dev->name);
191                 err = -EOPNOTSUPP;
192                 goto out;
193         }
194
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);
200                 err = -EOPNOTSUPP;
201                 goto out;
202         }
203
204         /* Finally, enable manual roaming */
205         priv->bssid_fixed = 1;
206         memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
207
208  out:
209         orinoco_unlock(priv, &flags);
210         return err;
211 }
212
213 static int orinoco_ioctl_getwap(struct net_device *dev,
214                                 struct iw_request_info *info,
215                                 struct sockaddr *ap_addr,
216                                 char *extra)
217 {
218         struct orinoco_private *priv = ndev_priv(dev);
219
220         int err = 0;
221         unsigned long flags;
222
223         if (orinoco_lock(priv, &flags) != 0)
224                 return -EBUSY;
225
226         ap_addr->sa_family = ARPHRD_ETHER;
227         err = orinoco_hw_get_current_bssid(priv, ap_addr->sa_data);
228
229         orinoco_unlock(priv, &flags);
230
231         return err;
232 }
233
234 static int orinoco_ioctl_setiwencode(struct net_device *dev,
235                                      struct iw_request_info *info,
236                                      struct iw_point *erq,
237                                      char *keybuf)
238 {
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 */
245         unsigned long flags;
246
247         if (!priv->has_wep)
248                 return -EOPNOTSUPP;
249
250         if (erq->pointer) {
251                 /* We actually have a key to set - check its length */
252                 if (erq->length > LARGE_KEY_SIZE)
253                         return -E2BIG;
254
255                 if ((erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep)
256                         return -E2BIG;
257         }
258
259         if (orinoco_lock(priv, &flags) != 0)
260                 return -EBUSY;
261
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);
265
266         if (erq->length > 0) {
267                 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
268                         index = priv->tx_key;
269
270                 /* Switch on WEP if off */
271                 if (encode_alg != ORINOCO_ALG_WEP) {
272                         setindex = index;
273                         encode_alg = ORINOCO_ALG_WEP;
274                 }
275         } else {
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)) {
281                                 err = -EINVAL;
282                                 goto out;
283                         }
284                 } else {
285                         /* Set the index : Check that the key is valid */
286                         if (priv->keys[index].key_len == 0) {
287                                 err = -EINVAL;
288                                 goto out;
289                         }
290                         setindex = index;
291                 }
292         }
293
294         if (erq->flags & IW_ENCODE_DISABLED)
295                 encode_alg = ORINOCO_ALG_NONE;
296         if (erq->flags & IW_ENCODE_OPEN)
297                 restricted = 0;
298         if (erq->flags & IW_ENCODE_RESTRICTED)
299                 restricted = 1;
300
301         if (erq->pointer && erq->length > 0) {
302                 err = orinoco_set_key(priv, index, ORINOCO_ALG_WEP, keybuf,
303                                       erq->length, NULL, 0);
304         }
305         priv->tx_key = setindex;
306
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 */
313                 goto out;
314         }
315
316         priv->encode_alg = encode_alg;
317         priv->wep_restrict = restricted;
318
319  out:
320         orinoco_unlock(priv, &flags);
321
322         return err;
323 }
324
325 static int orinoco_ioctl_getiwencode(struct net_device *dev,
326                                      struct iw_request_info *info,
327                                      struct iw_point *erq,
328                                      char *keybuf)
329 {
330         struct orinoco_private *priv = ndev_priv(dev);
331         int index = (erq->flags & IW_ENCODE_INDEX) - 1;
332         unsigned long flags;
333
334         if (!priv->has_wep)
335                 return -EOPNOTSUPP;
336
337         if (orinoco_lock(priv, &flags) != 0)
338                 return -EBUSY;
339
340         if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
341                 index = priv->tx_key;
342
343         erq->flags = 0;
344         if (!priv->encode_alg)
345                 erq->flags |= IW_ENCODE_DISABLED;
346         erq->flags |= index + 1;
347
348         if (priv->wep_restrict)
349                 erq->flags |= IW_ENCODE_RESTRICTED;
350         else
351                 erq->flags |= IW_ENCODE_OPEN;
352
353         erq->length = priv->keys[index].key_len;
354
355         memcpy(keybuf, priv->keys[index].key, erq->length);
356
357         orinoco_unlock(priv, &flags);
358         return 0;
359 }
360
361 static int orinoco_ioctl_setessid(struct net_device *dev,
362                                   struct iw_request_info *info,
363                                   struct iw_point *erq,
364                                   char *essidbuf)
365 {
366         struct orinoco_private *priv = ndev_priv(dev);
367         unsigned long flags;
368
369         /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
370          * anyway... - Jean II */
371
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)
375                 return -E2BIG;
376
377         if (orinoco_lock(priv, &flags) != 0)
378                 return -EBUSY;
379
380         /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
381         memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
382
383         /* If not ANY, get the new ESSID */
384         if (erq->flags)
385                 memcpy(priv->desired_essid, essidbuf, erq->length);
386
387         orinoco_unlock(priv, &flags);
388
389         return -EINPROGRESS;            /* Call commit handler */
390 }
391
392 static int orinoco_ioctl_getessid(struct net_device *dev,
393                                   struct iw_request_info *info,
394                                   struct iw_point *erq,
395                                   char *essidbuf)
396 {
397         struct orinoco_private *priv = ndev_priv(dev);
398         int active;
399         int err = 0;
400         unsigned long flags;
401
402         if (netif_running(dev)) {
403                 err = orinoco_hw_get_essid(priv, &active, essidbuf);
404                 if (err < 0)
405                         return err;
406                 erq->length = err;
407         } else {
408                 if (orinoco_lock(priv, &flags) != 0)
409                         return -EBUSY;
410                 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE);
411                 erq->length = strlen(priv->desired_essid);
412                 orinoco_unlock(priv, &flags);
413         }
414
415         erq->flags = 1;
416
417         return 0;
418 }
419
420 static int orinoco_ioctl_setfreq(struct net_device *dev,
421                                  struct iw_request_info *info,
422                                  struct iw_freq *frq,
423                                  char *extra)
424 {
425         struct orinoco_private *priv = ndev_priv(dev);
426         int chan = -1;
427         unsigned long flags;
428         int err = -EINPROGRESS;         /* Call commit handler */
429
430         /* In infrastructure mode the AP sets the channel */
431         if (priv->iw_mode == NL80211_IFTYPE_STATION)
432                 return -EBUSY;
433
434         if ((frq->e == 0) && (frq->m <= 1000)) {
435                 /* Setting by channel number */
436                 chan = frq->m;
437         } else {
438                 /* Setting by frequency */
439                 int denom = 1;
440                 int i;
441
442                 /* Calculate denominator to rescale to MHz */
443                 for (i = 0; i < (6 - frq->e); i++)
444                         denom *= 10;
445
446                 chan = ieee80211_freq_to_dsss_chan(frq->m / denom);
447         }
448
449         if ((chan < 1) || (chan > NUM_CHANNELS) ||
450              !(priv->channel_mask & (1 << (chan-1))))
451                 return -EINVAL;
452
453         if (orinoco_lock(priv, &flags) != 0)
454                 return -EBUSY;
455
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,
462                                         chan, NULL);
463         }
464         orinoco_unlock(priv, &flags);
465
466         return err;
467 }
468
469 static int orinoco_ioctl_getfreq(struct net_device *dev,
470                                  struct iw_request_info *info,
471                                  struct iw_freq *frq,
472                                  char *extra)
473 {
474         struct orinoco_private *priv = ndev_priv(dev);
475         int tmp;
476
477         /* Locking done in there */
478         tmp = orinoco_hw_get_freq(priv);
479         if (tmp < 0)
480                 return tmp;
481
482         frq->m = tmp * 100000;
483         frq->e = 1;
484
485         return 0;
486 }
487
488 static int orinoco_ioctl_getsens(struct net_device *dev,
489                                  struct iw_request_info *info,
490                                  struct iw_param *srq,
491                                  char *extra)
492 {
493         struct orinoco_private *priv = ndev_priv(dev);
494         hermes_t *hw = &priv->hw;
495         u16 val;
496         int err;
497         unsigned long flags;
498
499         if (!priv->has_sensitivity)
500                 return -EOPNOTSUPP;
501
502         if (orinoco_lock(priv, &flags) != 0)
503                 return -EBUSY;
504         err = hermes_read_wordrec(hw, USER_BAP,
505                                   HERMES_RID_CNFSYSTEMSCALE, &val);
506         orinoco_unlock(priv, &flags);
507
508         if (err)
509                 return err;
510
511         srq->value = val;
512         srq->fixed = 0; /* auto */
513
514         return 0;
515 }
516
517 static int orinoco_ioctl_setsens(struct net_device *dev,
518                                  struct iw_request_info *info,
519                                  struct iw_param *srq,
520                                  char *extra)
521 {
522         struct orinoco_private *priv = ndev_priv(dev);
523         int val = srq->value;
524         unsigned long flags;
525
526         if (!priv->has_sensitivity)
527                 return -EOPNOTSUPP;
528
529         if ((val < 1) || (val > 3))
530                 return -EINVAL;
531
532         if (orinoco_lock(priv, &flags) != 0)
533                 return -EBUSY;
534         priv->ap_density = val;
535         orinoco_unlock(priv, &flags);
536
537         return -EINPROGRESS;            /* Call commit handler */
538 }
539
540 static int orinoco_ioctl_setrate(struct net_device *dev,
541                                  struct iw_request_info *info,
542                                  struct iw_param *rrq,
543                                  char *extra)
544 {
545         struct orinoco_private *priv = ndev_priv(dev);
546         int ratemode;
547         int bitrate; /* 100s of kilobits */
548         unsigned long flags;
549
550         /* As the user space doesn't know our highest rate, it uses -1
551          * to ask us to set the highest rate.  Test it using "iwconfig
552          * ethX rate auto" - Jean II */
553         if (rrq->value == -1)
554                 bitrate = 110;
555         else {
556                 if (rrq->value % 100000)
557                         return -EINVAL;
558                 bitrate = rrq->value / 100000;
559         }
560
561         ratemode = orinoco_get_bitratemode(bitrate, !rrq->fixed);
562
563         if (ratemode == -1)
564                 return -EINVAL;
565
566         if (orinoco_lock(priv, &flags) != 0)
567                 return -EBUSY;
568         priv->bitratemode = ratemode;
569         orinoco_unlock(priv, &flags);
570
571         return -EINPROGRESS;
572 }
573
574 static int orinoco_ioctl_getrate(struct net_device *dev,
575                                  struct iw_request_info *info,
576                                  struct iw_param *rrq,
577                                  char *extra)
578 {
579         struct orinoco_private *priv = ndev_priv(dev);
580         int err = 0;
581         int bitrate, automatic;
582         unsigned long flags;
583
584         if (orinoco_lock(priv, &flags) != 0)
585                 return -EBUSY;
586
587         orinoco_get_ratemode_cfg(priv->bitratemode, &bitrate, &automatic);
588
589         /* If the interface is running we try to find more about the
590            current mode */
591         if (netif_running(dev))
592                 err = orinoco_hw_get_act_bitrate(priv, &bitrate);
593
594         orinoco_unlock(priv, &flags);
595
596         rrq->value = bitrate;
597         rrq->fixed = !automatic;
598         rrq->disabled = 0;
599
600         return err;
601 }
602
603 static int orinoco_ioctl_setpower(struct net_device *dev,
604                                   struct iw_request_info *info,
605                                   struct iw_param *prq,
606                                   char *extra)
607 {
608         struct orinoco_private *priv = ndev_priv(dev);
609         int err = -EINPROGRESS;         /* Call commit handler */
610         unsigned long flags;
611
612         if (orinoco_lock(priv, &flags) != 0)
613                 return -EBUSY;
614
615         if (prq->disabled) {
616                 priv->pm_on = 0;
617         } else {
618                 switch (prq->flags & IW_POWER_MODE) {
619                 case IW_POWER_UNICAST_R:
620                         priv->pm_mcast = 0;
621                         priv->pm_on = 1;
622                         break;
623                 case IW_POWER_ALL_R:
624                         priv->pm_mcast = 1;
625                         priv->pm_on = 1;
626                         break;
627                 case IW_POWER_ON:
628                         /* No flags : but we may have a value - Jean II */
629                         break;
630                 default:
631                         err = -EINVAL;
632                         goto out;
633                 }
634
635                 if (prq->flags & IW_POWER_TIMEOUT) {
636                         priv->pm_on = 1;
637                         priv->pm_timeout = prq->value / 1000;
638                 }
639                 if (prq->flags & IW_POWER_PERIOD) {
640                         priv->pm_on = 1;
641                         priv->pm_period = prq->value / 1000;
642                 }
643                 /* It's valid to not have a value if we are just toggling
644                  * the flags... Jean II */
645                 if (!priv->pm_on) {
646                         err = -EINVAL;
647                         goto out;
648                 }
649         }
650
651  out:
652         orinoco_unlock(priv, &flags);
653
654         return err;
655 }
656
657 static int orinoco_ioctl_getpower(struct net_device *dev,
658                                   struct iw_request_info *info,
659                                   struct iw_param *prq,
660                                   char *extra)
661 {
662         struct orinoco_private *priv = ndev_priv(dev);
663         hermes_t *hw = &priv->hw;
664         int err = 0;
665         u16 enable, period, timeout, mcast;
666         unsigned long flags;
667
668         if (orinoco_lock(priv, &flags) != 0)
669                 return -EBUSY;
670
671         err = hermes_read_wordrec(hw, USER_BAP,
672                                   HERMES_RID_CNFPMENABLED, &enable);
673         if (err)
674                 goto out;
675
676         err = hermes_read_wordrec(hw, USER_BAP,
677                                   HERMES_RID_CNFMAXSLEEPDURATION, &period);
678         if (err)
679                 goto out;
680
681         err = hermes_read_wordrec(hw, USER_BAP,
682                                   HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
683         if (err)
684                 goto out;
685
686         err = hermes_read_wordrec(hw, USER_BAP,
687                                   HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
688         if (err)
689                 goto out;
690
691         prq->disabled = !enable;
692         /* Note : by default, display the period */
693         if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
694                 prq->flags = IW_POWER_TIMEOUT;
695                 prq->value = timeout * 1000;
696         } else {
697                 prq->flags = IW_POWER_PERIOD;
698                 prq->value = period * 1000;
699         }
700         if (mcast)
701                 prq->flags |= IW_POWER_ALL_R;
702         else
703                 prq->flags |= IW_POWER_UNICAST_R;
704
705  out:
706         orinoco_unlock(priv, &flags);
707
708         return err;
709 }
710
711 static int orinoco_ioctl_set_encodeext(struct net_device *dev,
712                                        struct iw_request_info *info,
713                                        union iwreq_data *wrqu,
714                                        char *extra)
715 {
716         struct orinoco_private *priv = ndev_priv(dev);
717         struct iw_point *encoding = &wrqu->encoding;
718         struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
719         int idx, alg = ext->alg, set_key = 1;
720         unsigned long flags;
721         int err = -EINVAL;
722
723         if (orinoco_lock(priv, &flags) != 0)
724                 return -EBUSY;
725
726         /* Determine and validate the key index */
727         idx = encoding->flags & IW_ENCODE_INDEX;
728         if (idx) {
729                 if ((idx < 1) || (idx > 4))
730                         goto out;
731                 idx--;
732         } else
733                 idx = priv->tx_key;
734
735         if (encoding->flags & IW_ENCODE_DISABLED)
736                 alg = IW_ENCODE_ALG_NONE;
737
738         if (priv->has_wpa && (alg != IW_ENCODE_ALG_TKIP)) {
739                 /* Clear any TKIP TX key we had */
740                 (void) orinoco_clear_tkip_key(priv, priv->tx_key);
741         }
742
743         if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
744                 priv->tx_key = idx;
745                 set_key = ((alg == IW_ENCODE_ALG_TKIP) ||
746                            (ext->key_len > 0)) ? 1 : 0;
747         }
748
749         if (set_key) {
750                 /* Set the requested key first */
751                 switch (alg) {
752                 case IW_ENCODE_ALG_NONE:
753                         priv->encode_alg = ORINOCO_ALG_NONE;
754                         err = orinoco_set_key(priv, idx, ORINOCO_ALG_NONE,
755                                               NULL, 0, NULL, 0);
756                         break;
757
758                 case IW_ENCODE_ALG_WEP:
759                         if (ext->key_len <= 0)
760                                 goto out;
761
762                         priv->encode_alg = ORINOCO_ALG_WEP;
763                         err = orinoco_set_key(priv, idx, ORINOCO_ALG_WEP,
764                                               ext->key, ext->key_len, NULL, 0);
765                         break;
766
767                 case IW_ENCODE_ALG_TKIP:
768                 {
769                         u8 *tkip_iv = NULL;
770
771                         if (!priv->has_wpa ||
772                             (ext->key_len > sizeof(struct orinoco_tkip_key)))
773                                 goto out;
774
775                         priv->encode_alg = ORINOCO_ALG_TKIP;
776
777                         if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
778                                 tkip_iv = &ext->rx_seq[0];
779
780                         err = orinoco_set_key(priv, idx, ORINOCO_ALG_TKIP,
781                                               ext->key, ext->key_len, tkip_iv,
782                                               ORINOCO_SEQ_LEN);
783
784                         err = __orinoco_hw_set_tkip_key(priv, idx,
785                                  ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
786                                  priv->keys[idx].key,
787                                  tkip_iv, ORINOCO_SEQ_LEN, NULL, 0);
788                         if (err)
789                                 printk(KERN_ERR "%s: Error %d setting TKIP key"
790                                        "\n", dev->name, err);
791
792                         goto out;
793                 }
794                 default:
795                         goto out;
796                 }
797         }
798         err = -EINPROGRESS;
799  out:
800         orinoco_unlock(priv, &flags);
801
802         return err;
803 }
804
805 static int orinoco_ioctl_get_encodeext(struct net_device *dev,
806                                        struct iw_request_info *info,
807                                        union iwreq_data *wrqu,
808                                        char *extra)
809 {
810         struct orinoco_private *priv = ndev_priv(dev);
811         struct iw_point *encoding = &wrqu->encoding;
812         struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
813         int idx, max_key_len;
814         unsigned long flags;
815         int err;
816
817         if (orinoco_lock(priv, &flags) != 0)
818                 return -EBUSY;
819
820         err = -EINVAL;
821         max_key_len = encoding->length - sizeof(*ext);
822         if (max_key_len < 0)
823                 goto out;
824
825         idx = encoding->flags & IW_ENCODE_INDEX;
826         if (idx) {
827                 if ((idx < 1) || (idx > 4))
828                         goto out;
829                 idx--;
830         } else
831                 idx = priv->tx_key;
832
833         encoding->flags = idx + 1;
834         memset(ext, 0, sizeof(*ext));
835
836         switch (priv->encode_alg) {
837         case ORINOCO_ALG_NONE:
838                 ext->alg = IW_ENCODE_ALG_NONE;
839                 ext->key_len = 0;
840                 encoding->flags |= IW_ENCODE_DISABLED;
841                 break;
842         case ORINOCO_ALG_WEP:
843                 ext->alg = IW_ENCODE_ALG_WEP;
844                 ext->key_len = min(priv->keys[idx].key_len, max_key_len);
845                 memcpy(ext->key, priv->keys[idx].key, ext->key_len);
846                 encoding->flags |= IW_ENCODE_ENABLED;
847                 break;
848         case ORINOCO_ALG_TKIP:
849                 ext->alg = IW_ENCODE_ALG_TKIP;
850                 ext->key_len = min(priv->keys[idx].key_len, max_key_len);
851                 memcpy(ext->key, priv->keys[idx].key, ext->key_len);
852                 encoding->flags |= IW_ENCODE_ENABLED;
853                 break;
854         }
855
856         err = 0;
857  out:
858         orinoco_unlock(priv, &flags);
859
860         return err;
861 }
862
863 static int orinoco_ioctl_set_auth(struct net_device *dev,
864                                   struct iw_request_info *info,
865                                   union iwreq_data *wrqu, char *extra)
866 {
867         struct orinoco_private *priv = ndev_priv(dev);
868         hermes_t *hw = &priv->hw;
869         struct iw_param *param = &wrqu->param;
870         unsigned long flags;
871         int ret = -EINPROGRESS;
872
873         if (orinoco_lock(priv, &flags) != 0)
874                 return -EBUSY;
875
876         switch (param->flags & IW_AUTH_INDEX) {
877         case IW_AUTH_WPA_VERSION:
878         case IW_AUTH_CIPHER_PAIRWISE:
879         case IW_AUTH_CIPHER_GROUP:
880         case IW_AUTH_RX_UNENCRYPTED_EAPOL:
881         case IW_AUTH_PRIVACY_INVOKED:
882         case IW_AUTH_DROP_UNENCRYPTED:
883                 /*
884                  * orinoco does not use these parameters
885                  */
886                 break;
887
888         case IW_AUTH_KEY_MGMT:
889                 /* wl_lkm implies value 2 == PSK for Hermes I
890                  * which ties in with WEXT
891                  * no other hints tho :(
892                  */
893                 priv->key_mgmt = param->value;
894                 break;
895
896         case IW_AUTH_TKIP_COUNTERMEASURES:
897                 /* When countermeasures are enabled, shut down the
898                  * card; when disabled, re-enable the card. This must
899                  * take effect immediately.
900                  *
901                  * TODO: Make sure that the EAPOL message is getting
902                  *       out before card disabled
903                  */
904                 if (param->value) {
905                         priv->tkip_cm_active = 1;
906                         ret = hermes_enable_port(hw, 0);
907                 } else {
908                         priv->tkip_cm_active = 0;
909                         ret = hermes_disable_port(hw, 0);
910                 }
911                 break;
912
913         case IW_AUTH_80211_AUTH_ALG:
914                 if (param->value & IW_AUTH_ALG_SHARED_KEY)
915                         priv->wep_restrict = 1;
916                 else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
917                         priv->wep_restrict = 0;
918                 else
919                         ret = -EINVAL;
920                 break;
921
922         case IW_AUTH_WPA_ENABLED:
923                 if (priv->has_wpa) {
924                         priv->wpa_enabled = param->value ? 1 : 0;
925                 } else {
926                         if (param->value)
927                                 ret = -EOPNOTSUPP;
928                         /* else silently accept disable of WPA */
929                         priv->wpa_enabled = 0;
930                 }
931                 break;
932
933         default:
934                 ret = -EOPNOTSUPP;
935         }
936
937         orinoco_unlock(priv, &flags);
938         return ret;
939 }
940
941 static int orinoco_ioctl_get_auth(struct net_device *dev,
942                                   struct iw_request_info *info,
943                                   union iwreq_data *wrqu, char *extra)
944 {
945         struct orinoco_private *priv = ndev_priv(dev);
946         struct iw_param *param = &wrqu->param;
947         unsigned long flags;
948         int ret = 0;
949
950         if (orinoco_lock(priv, &flags) != 0)
951                 return -EBUSY;
952
953         switch (param->flags & IW_AUTH_INDEX) {
954         case IW_AUTH_KEY_MGMT:
955                 param->value = priv->key_mgmt;
956                 break;
957
958         case IW_AUTH_TKIP_COUNTERMEASURES:
959                 param->value = priv->tkip_cm_active;
960                 break;
961
962         case IW_AUTH_80211_AUTH_ALG:
963                 if (priv->wep_restrict)
964                         param->value = IW_AUTH_ALG_SHARED_KEY;
965                 else
966                         param->value = IW_AUTH_ALG_OPEN_SYSTEM;
967                 break;
968
969         case IW_AUTH_WPA_ENABLED:
970                 param->value = priv->wpa_enabled;
971                 break;
972
973         default:
974                 ret = -EOPNOTSUPP;
975         }
976
977         orinoco_unlock(priv, &flags);
978         return ret;
979 }
980
981 static int orinoco_ioctl_set_genie(struct net_device *dev,
982                                    struct iw_request_info *info,
983                                    union iwreq_data *wrqu, char *extra)
984 {
985         struct orinoco_private *priv = ndev_priv(dev);
986         u8 *buf;
987         unsigned long flags;
988
989         /* cut off at IEEE80211_MAX_DATA_LEN */
990         if ((wrqu->data.length > IEEE80211_MAX_DATA_LEN) ||
991             (wrqu->data.length && (extra == NULL)))
992                 return -EINVAL;
993
994         if (wrqu->data.length) {
995                 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
996                 if (buf == NULL)
997                         return -ENOMEM;
998
999                 memcpy(buf, extra, wrqu->data.length);
1000         } else
1001                 buf = NULL;
1002
1003         if (orinoco_lock(priv, &flags) != 0) {
1004                 kfree(buf);
1005                 return -EBUSY;
1006         }
1007
1008         kfree(priv->wpa_ie);
1009         priv->wpa_ie = buf;
1010         priv->wpa_ie_len = wrqu->data.length;
1011
1012         if (priv->wpa_ie) {
1013                 /* Looks like wl_lkm wants to check the auth alg, and
1014                  * somehow pass it to the firmware.
1015                  * Instead it just calls the key mgmt rid
1016                  *   - we do this in set auth.
1017                  */
1018         }
1019
1020         orinoco_unlock(priv, &flags);
1021         return 0;
1022 }
1023
1024 static int orinoco_ioctl_get_genie(struct net_device *dev,
1025                                    struct iw_request_info *info,
1026                                    union iwreq_data *wrqu, char *extra)
1027 {
1028         struct orinoco_private *priv = ndev_priv(dev);
1029         unsigned long flags;
1030         int err = 0;
1031
1032         if (orinoco_lock(priv, &flags) != 0)
1033                 return -EBUSY;
1034
1035         if ((priv->wpa_ie_len == 0) || (priv->wpa_ie == NULL)) {
1036                 wrqu->data.length = 0;
1037                 goto out;
1038         }
1039
1040         if (wrqu->data.length < priv->wpa_ie_len) {
1041                 err = -E2BIG;
1042                 goto out;
1043         }
1044
1045         wrqu->data.length = priv->wpa_ie_len;
1046         memcpy(extra, priv->wpa_ie, priv->wpa_ie_len);
1047
1048 out:
1049         orinoco_unlock(priv, &flags);
1050         return err;
1051 }
1052
1053 static int orinoco_ioctl_set_mlme(struct net_device *dev,
1054                                   struct iw_request_info *info,
1055                                   union iwreq_data *wrqu, char *extra)
1056 {
1057         struct orinoco_private *priv = ndev_priv(dev);
1058         struct iw_mlme *mlme = (struct iw_mlme *)extra;
1059         unsigned long flags;
1060         int ret = 0;
1061
1062         if (orinoco_lock(priv, &flags) != 0)
1063                 return -EBUSY;
1064
1065         switch (mlme->cmd) {
1066         case IW_MLME_DEAUTH:
1067                 /* silently ignore */
1068                 break;
1069
1070         case IW_MLME_DISASSOC:
1071
1072                 ret = orinoco_hw_disassociate(priv, mlme->addr.sa_data,
1073                                               mlme->reason_code);
1074                 break;
1075
1076         default:
1077                 ret = -EOPNOTSUPP;
1078         }
1079
1080         orinoco_unlock(priv, &flags);
1081         return ret;
1082 }
1083
1084 static int orinoco_ioctl_reset(struct net_device *dev,
1085                                struct iw_request_info *info,
1086                                void *wrqu,
1087                                char *extra)
1088 {
1089         struct orinoco_private *priv = ndev_priv(dev);
1090
1091         if (!capable(CAP_NET_ADMIN))
1092                 return -EPERM;
1093
1094         if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
1095                 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
1096
1097                 /* Firmware reset */
1098                 orinoco_reset(&priv->reset_work);
1099         } else {
1100                 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
1101
1102                 schedule_work(&priv->reset_work);
1103         }
1104
1105         return 0;
1106 }
1107
1108 static int orinoco_ioctl_setibssport(struct net_device *dev,
1109                                      struct iw_request_info *info,
1110                                      void *wrqu,
1111                                      char *extra)
1112
1113 {
1114         struct orinoco_private *priv = ndev_priv(dev);
1115         int val = *((int *) extra);
1116         unsigned long flags;
1117
1118         if (orinoco_lock(priv, &flags) != 0)
1119                 return -EBUSY;
1120
1121         priv->ibss_port = val;
1122
1123         /* Actually update the mode we are using */
1124         set_port_type(priv);
1125
1126         orinoco_unlock(priv, &flags);
1127         return -EINPROGRESS;            /* Call commit handler */
1128 }
1129
1130 static int orinoco_ioctl_getibssport(struct net_device *dev,
1131                                      struct iw_request_info *info,
1132                                      void *wrqu,
1133                                      char *extra)
1134 {
1135         struct orinoco_private *priv = ndev_priv(dev);
1136         int *val = (int *) extra;
1137
1138         *val = priv->ibss_port;
1139         return 0;
1140 }
1141
1142 static int orinoco_ioctl_setport3(struct net_device *dev,
1143                                   struct iw_request_info *info,
1144                                   void *wrqu,
1145                                   char *extra)
1146 {
1147         struct orinoco_private *priv = ndev_priv(dev);
1148         int val = *((int *) extra);
1149         int err = 0;
1150         unsigned long flags;
1151
1152         if (orinoco_lock(priv, &flags) != 0)
1153                 return -EBUSY;
1154
1155         switch (val) {
1156         case 0: /* Try to do IEEE ad-hoc mode */
1157                 if (!priv->has_ibss) {
1158                         err = -EINVAL;
1159                         break;
1160                 }
1161                 priv->prefer_port3 = 0;
1162
1163                 break;
1164
1165         case 1: /* Try to do Lucent proprietary ad-hoc mode */
1166                 if (!priv->has_port3) {
1167                         err = -EINVAL;
1168                         break;
1169                 }
1170                 priv->prefer_port3 = 1;
1171                 break;
1172
1173         default:
1174                 err = -EINVAL;
1175         }
1176
1177         if (!err) {
1178                 /* Actually update the mode we are using */
1179                 set_port_type(priv);
1180                 err = -EINPROGRESS;
1181         }
1182
1183         orinoco_unlock(priv, &flags);
1184
1185         return err;
1186 }
1187
1188 static int orinoco_ioctl_getport3(struct net_device *dev,
1189                                   struct iw_request_info *info,
1190                                   void *wrqu,
1191                                   char *extra)
1192 {
1193         struct orinoco_private *priv = ndev_priv(dev);
1194         int *val = (int *) extra;
1195
1196         *val = priv->prefer_port3;
1197         return 0;
1198 }
1199
1200 static int orinoco_ioctl_setpreamble(struct net_device *dev,
1201                                      struct iw_request_info *info,
1202                                      void *wrqu,
1203                                      char *extra)
1204 {
1205         struct orinoco_private *priv = ndev_priv(dev);
1206         unsigned long flags;
1207         int val;
1208
1209         if (!priv->has_preamble)
1210                 return -EOPNOTSUPP;
1211
1212         /* 802.11b has recently defined some short preamble.
1213          * Basically, the Phy header has been reduced in size.
1214          * This increase performance, especially at high rates
1215          * (the preamble is transmitted at 1Mb/s), unfortunately
1216          * this give compatibility troubles... - Jean II */
1217         val = *((int *) extra);
1218
1219         if (orinoco_lock(priv, &flags) != 0)
1220                 return -EBUSY;
1221
1222         if (val)
1223                 priv->preamble = 1;
1224         else
1225                 priv->preamble = 0;
1226
1227         orinoco_unlock(priv, &flags);
1228
1229         return -EINPROGRESS;            /* Call commit handler */
1230 }
1231
1232 static int orinoco_ioctl_getpreamble(struct net_device *dev,
1233                                      struct iw_request_info *info,
1234                                      void *wrqu,
1235                                      char *extra)
1236 {
1237         struct orinoco_private *priv = ndev_priv(dev);
1238         int *val = (int *) extra;
1239
1240         if (!priv->has_preamble)
1241                 return -EOPNOTSUPP;
1242
1243         *val = priv->preamble;
1244         return 0;
1245 }
1246
1247 /* ioctl interface to hermes_read_ltv()
1248  * To use with iwpriv, pass the RID as the token argument, e.g.
1249  * iwpriv get_rid [0xfc00]
1250  * At least Wireless Tools 25 is required to use iwpriv.
1251  * For Wireless Tools 25 and 26 append "dummy" are the end. */
1252 static int orinoco_ioctl_getrid(struct net_device *dev,
1253                                 struct iw_request_info *info,
1254                                 struct iw_point *data,
1255                                 char *extra)
1256 {
1257         struct orinoco_private *priv = ndev_priv(dev);
1258         hermes_t *hw = &priv->hw;
1259         int rid = data->flags;
1260         u16 length;
1261         int err;
1262         unsigned long flags;
1263
1264         /* It's a "get" function, but we don't want users to access the
1265          * WEP key and other raw firmware data */
1266         if (!capable(CAP_NET_ADMIN))
1267                 return -EPERM;
1268
1269         if (rid < 0xfc00 || rid > 0xffff)
1270                 return -EINVAL;
1271
1272         if (orinoco_lock(priv, &flags) != 0)
1273                 return -EBUSY;
1274
1275         err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
1276                               extra);
1277         if (err)
1278                 goto out;
1279
1280         data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
1281                              MAX_RID_LEN);
1282
1283  out:
1284         orinoco_unlock(priv, &flags);
1285         return err;
1286 }
1287
1288
1289 /* Commit handler, called after set operations */
1290 static int orinoco_ioctl_commit(struct net_device *dev,
1291                                 struct iw_request_info *info,
1292                                 void *wrqu,
1293                                 char *extra)
1294 {
1295         struct orinoco_private *priv = ndev_priv(dev);
1296         unsigned long flags;
1297         int err = 0;
1298
1299         if (!priv->open)
1300                 return 0;
1301
1302         if (orinoco_lock(priv, &flags) != 0)
1303                 return err;
1304
1305         err = orinoco_commit(priv);
1306
1307         orinoco_unlock(priv, &flags);
1308         return err;
1309 }
1310
1311 static const struct iw_priv_args orinoco_privtab[] = {
1312         { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
1313         { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
1314         { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1315           0, "set_port3" },
1316         { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1317           "get_port3" },
1318         { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1319           0, "set_preamble" },
1320         { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1321           "get_preamble" },
1322         { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1323           0, "set_ibssport" },
1324         { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1325           "get_ibssport" },
1326         { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
1327           "get_rid" },
1328 };
1329
1330
1331 /*
1332  * Structures to export the Wireless Handlers
1333  */
1334
1335 static const iw_handler orinoco_handler[] = {
1336         IW_HANDLER(SIOCSIWCOMMIT,       (iw_handler)orinoco_ioctl_commit),
1337         IW_HANDLER(SIOCGIWNAME,         (iw_handler)cfg80211_wext_giwname),
1338         IW_HANDLER(SIOCSIWFREQ,         (iw_handler)orinoco_ioctl_setfreq),
1339         IW_HANDLER(SIOCGIWFREQ,         (iw_handler)orinoco_ioctl_getfreq),
1340         IW_HANDLER(SIOCSIWMODE,         (iw_handler)cfg80211_wext_siwmode),
1341         IW_HANDLER(SIOCGIWMODE,         (iw_handler)cfg80211_wext_giwmode),
1342         IW_HANDLER(SIOCSIWSENS,         (iw_handler)orinoco_ioctl_setsens),
1343         IW_HANDLER(SIOCGIWSENS,         (iw_handler)orinoco_ioctl_getsens),
1344         IW_HANDLER(SIOCGIWRANGE,        (iw_handler)cfg80211_wext_giwrange),
1345         IW_HANDLER(SIOCSIWSPY,          iw_handler_set_spy),
1346         IW_HANDLER(SIOCGIWSPY,          iw_handler_get_spy),
1347         IW_HANDLER(SIOCSIWTHRSPY,       iw_handler_set_thrspy),
1348         IW_HANDLER(SIOCGIWTHRSPY,       iw_handler_get_thrspy),
1349         IW_HANDLER(SIOCSIWAP,           (iw_handler)orinoco_ioctl_setwap),
1350         IW_HANDLER(SIOCGIWAP,           (iw_handler)orinoco_ioctl_getwap),
1351         IW_HANDLER(SIOCSIWSCAN,         (iw_handler)cfg80211_wext_siwscan),
1352         IW_HANDLER(SIOCGIWSCAN,         (iw_handler)cfg80211_wext_giwscan),
1353         IW_HANDLER(SIOCSIWESSID,        (iw_handler)orinoco_ioctl_setessid),
1354         IW_HANDLER(SIOCGIWESSID,        (iw_handler)orinoco_ioctl_getessid),
1355         IW_HANDLER(SIOCSIWRATE,         (iw_handler)orinoco_ioctl_setrate),
1356         IW_HANDLER(SIOCGIWRATE,         (iw_handler)orinoco_ioctl_getrate),
1357         IW_HANDLER(SIOCSIWRTS,          (iw_handler)cfg80211_wext_siwrts),
1358         IW_HANDLER(SIOCGIWRTS,          (iw_handler)cfg80211_wext_giwrts),
1359         IW_HANDLER(SIOCSIWFRAG,         (iw_handler)cfg80211_wext_siwfrag),
1360         IW_HANDLER(SIOCGIWFRAG,         (iw_handler)cfg80211_wext_giwfrag),
1361         IW_HANDLER(SIOCGIWRETRY,        (iw_handler)cfg80211_wext_giwretry),
1362         IW_HANDLER(SIOCSIWENCODE,       (iw_handler)orinoco_ioctl_setiwencode),
1363         IW_HANDLER(SIOCGIWENCODE,       (iw_handler)orinoco_ioctl_getiwencode),
1364         IW_HANDLER(SIOCSIWPOWER,        (iw_handler)orinoco_ioctl_setpower),
1365         IW_HANDLER(SIOCGIWPOWER,        (iw_handler)orinoco_ioctl_getpower),
1366         IW_HANDLER(SIOCSIWGENIE,        orinoco_ioctl_set_genie),
1367         IW_HANDLER(SIOCGIWGENIE,        orinoco_ioctl_get_genie),
1368         IW_HANDLER(SIOCSIWMLME,         orinoco_ioctl_set_mlme),
1369         IW_HANDLER(SIOCSIWAUTH,         orinoco_ioctl_set_auth),
1370         IW_HANDLER(SIOCGIWAUTH,         orinoco_ioctl_get_auth),
1371         IW_HANDLER(SIOCSIWENCODEEXT,    orinoco_ioctl_set_encodeext),
1372         IW_HANDLER(SIOCGIWENCODEEXT,    orinoco_ioctl_get_encodeext),
1373 };
1374
1375
1376 /*
1377   Added typecasting since we no longer use iwreq_data -- Moustafa
1378  */
1379 static const iw_handler orinoco_private_handler[] = {
1380         [0] = (iw_handler)orinoco_ioctl_reset,
1381         [1] = (iw_handler)orinoco_ioctl_reset,
1382         [2] = (iw_handler)orinoco_ioctl_setport3,
1383         [3] = (iw_handler)orinoco_ioctl_getport3,
1384         [4] = (iw_handler)orinoco_ioctl_setpreamble,
1385         [5] = (iw_handler)orinoco_ioctl_getpreamble,
1386         [6] = (iw_handler)orinoco_ioctl_setibssport,
1387         [7] = (iw_handler)orinoco_ioctl_getibssport,
1388         [9] = (iw_handler)orinoco_ioctl_getrid,
1389 };
1390
1391 const struct iw_handler_def orinoco_handler_def = {
1392         .num_standard = ARRAY_SIZE(orinoco_handler),
1393         .num_private = ARRAY_SIZE(orinoco_private_handler),
1394         .num_private_args = ARRAY_SIZE(orinoco_privtab),
1395         .standard = orinoco_handler,
1396         .private = orinoco_private_handler,
1397         .private_args = orinoco_privtab,
1398         .get_wireless_stats = orinoco_get_wireless_stats,
1399 };