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