This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / drivers / net / wireless / prism54 / isl_ioctl.c
1 /*
2  *  
3  *  Copyright (C) 2002 Intersil Americas Inc.
4  *            (C) 2003,2004 Aurelien Alleaume <slts@free.fr>
5  *            (C) 2003 Herbert Valerio Riedel <hvr@gnu.org>
6  *            (C) 2003 Luis R. Rodriguez <mcgrof@ruslug.rutgers.edu>
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22
23 #include <linux/version.h>
24 #include <linux/module.h>
25 #include <linux/kernel.h>
26 #include <linux/if_arp.h>
27 #include <linux/pci.h>
28
29 #include <asm/uaccess.h>
30
31 #include "prismcompat.h"
32 #include "isl_ioctl.h"
33 #include "islpci_mgt.h"
34 #include "isl_oid.h"            /* additional types and defs for isl38xx fw */
35 #include "oid_mgt.h"
36
37 #include <net/iw_handler.h>     /* New driver API */
38
39 static int init_mode = CARD_DEFAULT_IW_MODE;
40 static int init_channel = CARD_DEFAULT_CHANNEL;
41 static int init_wep = CARD_DEFAULT_WEP;
42 static int init_filter = CARD_DEFAULT_FILTER;
43 static int init_authen = CARD_DEFAULT_AUTHEN;
44 static int init_dot1x = CARD_DEFAULT_DOT1X;
45 static int init_conformance = CARD_DEFAULT_CONFORMANCE;
46 static int init_mlme = CARD_DEFAULT_MLME_MODE;
47
48 module_param(init_mode, int, 0);
49 MODULE_PARM_DESC(init_mode,
50                  "Set card mode:\n0: Auto\n1: Ad-Hoc\n2: Managed Client (Default)\n3: Master / Access Point\n4: Repeater (Not supported yet)\n5: Secondary (Not supported yet)\n6: Monitor");
51
52 module_param(init_channel, int, 0);
53 MODULE_PARM_DESC(init_channel,
54                  "Check `iwpriv ethx channel` for available channels");
55
56 module_param(init_wep, int, 0);
57 module_param(init_filter, int, 0);
58
59 module_param(init_authen, int, 0);
60 MODULE_PARM_DESC(init_authen,
61                  "Authentication method. Can be of seven types:\n0 0x0000: None\n1 0x0001: DOT11_AUTH_OS (Default)\n2 0x0002: DOT11_AUTH_SK\n3 0x0003: DOT11_AUTH_BOTH");
62
63 module_param(init_dot1x, int, 0);
64 MODULE_PARM_DESC(init_dot1x,
65                  "\n0: None/not set     (Default)\n1: DOT11_DOT1X_AUTHENABLED\n2: DOT11_DOT1X_KEYTXENABLED");
66
67 module_param(init_mlme, int, 0);
68 MODULE_PARM_DESC(init_mlme,
69                  "Sets the MAC layer management entity (MLME) mode of operation,\n0: DOT11_MLME_AUTO (Default)\n1: DOT11_MLME_INTERMEDIATE\n2: DOT11_MLME_EXTENDED");
70
71 /**
72  * prism54_mib_mode_helper - MIB change mode helper function
73  * @mib: the &struct islpci_mib object to modify
74  * @iw_mode: new mode (%IW_MODE_*)
75  * 
76  *  This is a helper function, hence it does not lock. Make sure
77  *  caller deals with locking *if* necessary. This function sets the 
78  *  mode-dependent mib values and does the mapping of the Linux 
79  *  Wireless API modes to Device firmware modes. It also checks for 
80  *  correct valid Linux wireless modes. 
81  */
82 int
83 prism54_mib_mode_helper(islpci_private *priv, u32 iw_mode)
84 {
85         u32 config = INL_CONFIG_MANUALRUN;
86         u32 mode, bsstype;
87
88         /* For now, just catch early the Repeater and Secondary modes here */
89         if (iw_mode == IW_MODE_REPEAT || iw_mode == IW_MODE_SECOND) {
90                 printk(KERN_DEBUG
91                        "%s(): Sorry, Repeater mode and Secondary mode "
92                        "are not yet supported by this driver.\n", __FUNCTION__);
93                 return -EINVAL;
94         }
95
96         priv->iw_mode = iw_mode;
97
98         switch (iw_mode) {
99         case IW_MODE_AUTO:
100                 mode = INL_MODE_CLIENT;
101                 bsstype = DOT11_BSSTYPE_ANY;
102                 break;
103         case IW_MODE_ADHOC:
104                 mode = INL_MODE_CLIENT;
105                 bsstype = DOT11_BSSTYPE_IBSS;
106                 break;
107         case IW_MODE_INFRA:
108                 mode = INL_MODE_CLIENT;
109                 bsstype = DOT11_BSSTYPE_INFRA;
110                 break;
111         case IW_MODE_MASTER:
112                 mode = INL_MODE_AP;
113                 bsstype = DOT11_BSSTYPE_INFRA;
114                 break;
115         case IW_MODE_MONITOR:
116                 mode = INL_MODE_PROMISCUOUS;
117                 bsstype = DOT11_BSSTYPE_ANY;
118                 config |= INL_CONFIG_RXANNEX;
119                 break;
120         default:
121                 return -EINVAL;
122         }
123
124         if (init_wds)
125                 config |= INL_CONFIG_WDS;
126         mgt_set(priv, DOT11_OID_BSSTYPE, &bsstype);
127         mgt_set(priv, OID_INL_CONFIG, &config);
128         mgt_set(priv, OID_INL_MODE, &mode);
129
130         return 0;
131 }
132
133 /**
134  * prism54_mib_init - fill MIB cache with defaults
135  *
136  *  this function initializes the struct given as @mib with defaults,
137  *  of which many are retrieved from the global module parameter
138  *  variables.  
139  */
140
141 void
142 prism54_mib_init(islpci_private *priv)
143 {
144         u32 t;
145         struct obj_buffer psm_buffer = {
146                 .size = PSM_BUFFER_SIZE,
147                 .addr = priv->device_psm_buffer
148         };
149
150         mgt_set(priv, DOT11_OID_CHANNEL, &init_channel);
151         mgt_set(priv, DOT11_OID_AUTHENABLE, &init_authen);
152         mgt_set(priv, DOT11_OID_PRIVACYINVOKED, &init_wep);
153
154         mgt_set(priv, DOT11_OID_PSMBUFFER, &psm_buffer);
155         mgt_set(priv, DOT11_OID_EXUNENCRYPTED, &init_filter);
156         mgt_set(priv, DOT11_OID_DOT1XENABLE, &init_dot1x);
157         mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &init_mlme);
158         mgt_set(priv, OID_INL_DOT11D_CONFORMANCE, &init_conformance);
159
160         t = 127;
161         mgt_set(priv, OID_INL_OUTPUTPOWER, &t);
162
163         /* Important: we are setting a default wireless mode and we are 
164          * forcing a valid one, so prism54_mib_mode_helper should just set
165          * mib values depending on what the wireless mode given is. No need
166          * for it save old values */
167         if (init_mode > IW_MODE_MONITOR || init_mode < IW_MODE_AUTO) {
168                 printk(KERN_DEBUG "%s(): You passed a non-valid init_mode. "
169                        "Using default mode\n", __FUNCTION__);
170                 init_mode = CARD_DEFAULT_IW_MODE;
171         }
172         /* This sets all of the mode-dependent values */
173         prism54_mib_mode_helper(priv, init_mode);
174 }
175
176 /* this will be executed outside of atomic context thanks to
177  * schedule_work(), thus we can as well use sleeping semaphore
178  * locking */
179 void
180 prism54_update_stats(islpci_private *priv)
181 {
182         char *data;
183         int j;
184         struct obj_bss bss, *bss2;
185         union oid_res_t r;
186
187         if (down_interruptible(&priv->stats_sem))
188                 return;
189
190 /* Noise floor.
191  * I'm not sure if the unit is dBm.
192  * Note : If we are not connected, this value seems to be irrelevant. */
193
194         mgt_get_request(priv, DOT11_OID_NOISEFLOOR, 0, NULL, &r);
195         priv->local_iwstatistics.qual.noise = r.u;
196
197 /* Get the rssi of the link. To do this we need to retrieve a bss. */
198
199         /* First get the MAC address of the AP we are associated with. */
200         mgt_get_request(priv, DOT11_OID_BSSID, 0, NULL, &r);
201         data = r.ptr;
202
203         /* copy this MAC to the bss */
204         memcpy(bss.address, data, 6);
205         kfree(data);
206
207         /* now ask for the corresponding bss */
208         j = mgt_get_request(priv, DOT11_OID_BSSFIND, 0, (void *) &bss, &r);
209         bss2 = r.ptr;
210         /* report the rssi and use it to calculate
211          *  link quality through a signal-noise
212          *  ratio */
213         priv->local_iwstatistics.qual.level = bss2->rssi;
214         priv->local_iwstatistics.qual.qual =
215             bss2->rssi - priv->iwstatistics.qual.noise;
216
217         kfree(bss2);
218
219         /* report that the stats are new */
220         priv->local_iwstatistics.qual.updated = 0x7;
221
222 /* Rx : unable to decrypt the MPDU */
223         mgt_get_request(priv, DOT11_OID_PRIVRXFAILED, 0, NULL, &r);
224         priv->local_iwstatistics.discard.code = r.u;
225
226 /* Tx : Max MAC retries num reached */
227         mgt_get_request(priv, DOT11_OID_MPDUTXFAILED, 0, NULL, &r);
228         priv->local_iwstatistics.discard.retries = r.u;
229
230         up(&priv->stats_sem);
231
232         return;
233 }
234
235 struct iw_statistics *
236 prism54_get_wireless_stats(struct net_device *ndev)
237 {
238         islpci_private *priv = netdev_priv(ndev);
239
240         /* If the stats are being updated return old data */
241         if (down_trylock(&priv->stats_sem) == 0) {
242                 memcpy(&priv->iwstatistics, &priv->local_iwstatistics,
243                        sizeof (struct iw_statistics));
244                 /* They won't be marked updated for the next time */
245                 priv->local_iwstatistics.qual.updated = 0;
246                 up(&priv->stats_sem);
247         } else
248                 priv->iwstatistics.qual.updated = 0;
249
250         /* Update our wireless stats, but do not schedule to often 
251          * (max 1 HZ) */
252         if ((priv->stats_timestamp == 0) ||
253             time_after(jiffies, priv->stats_timestamp + 1 * HZ)) {
254                 schedule_work(&priv->stats_work);
255                 priv->stats_timestamp = jiffies;
256         }
257
258         return &priv->iwstatistics;
259 }
260
261 static int
262 prism54_commit(struct net_device *ndev, struct iw_request_info *info,
263                char *cwrq, char *extra)
264 {
265         islpci_private *priv = netdev_priv(ndev);
266
267         /* simply re-set the last set SSID, this should commit most stuff */
268
269         /* Commit in Monitor mode is not necessary, also setting essid
270          * in Monitor mode does not make sense and isn't allowed for this
271          * device's firmware */
272         if (priv->iw_mode != IW_MODE_MONITOR)
273                 return mgt_set_request(priv, DOT11_OID_SSID, 0, NULL);
274         return 0;
275 }
276
277 static int
278 prism54_get_name(struct net_device *ndev, struct iw_request_info *info,
279                  char *cwrq, char *extra)
280 {
281         islpci_private *priv = netdev_priv(ndev);
282         char *capabilities;
283         union oid_res_t r;
284         int rvalue;
285
286         if (islpci_get_state(priv) < PRV_STATE_INIT) {
287                 strncpy(cwrq, "NOT READY!", IFNAMSIZ);
288                 return 0;
289         }
290         rvalue = mgt_get_request(priv, OID_INL_PHYCAPABILITIES, 0, NULL, &r);
291
292         switch (r.u) {
293         case INL_PHYCAP_5000MHZ:
294                 capabilities = "IEEE 802.11a/b/g";
295                 break;
296         case INL_PHYCAP_FAA:
297                 capabilities = "IEEE 802.11b/g - FAA Support";
298                 break;
299         case INL_PHYCAP_2400MHZ:
300         default:
301                 capabilities = "IEEE 802.11b/g";        /* Default */
302                 break;
303         }
304         strncpy(cwrq, capabilities, IFNAMSIZ);
305         return rvalue;
306 }
307
308 static int
309 prism54_set_freq(struct net_device *ndev, struct iw_request_info *info,
310                  struct iw_freq *fwrq, char *extra)
311 {
312         islpci_private *priv = netdev_priv(ndev);
313         int rvalue;
314         u32 c;
315
316         if (fwrq->m < 1000)
317                 /* we have a channel number */
318                 c = fwrq->m;
319         else
320                 c = (fwrq->e == 1) ? channel_of_freq(fwrq->m / 100000) : 0;
321
322         rvalue = c ? mgt_set_request(priv, DOT11_OID_CHANNEL, 0, &c) : -EINVAL;
323
324         /* Call commit handler */
325         return (rvalue ? rvalue : -EINPROGRESS);
326 }
327
328 static int
329 prism54_get_freq(struct net_device *ndev, struct iw_request_info *info,
330                  struct iw_freq *fwrq, char *extra)
331 {
332         islpci_private *priv = netdev_priv(ndev);
333         union oid_res_t r;
334         int rvalue;
335
336         rvalue = mgt_get_request(priv, DOT11_OID_CHANNEL, 0, NULL, &r);
337
338         fwrq->m = r.u;
339         fwrq->e = 0;
340
341         return rvalue;
342 }
343
344 static int
345 prism54_set_mode(struct net_device *ndev, struct iw_request_info *info,
346                  __u32 * uwrq, char *extra)
347 {
348         islpci_private *priv = netdev_priv(ndev);
349         u32 mlmeautolevel = CARD_DEFAULT_MLME_MODE;
350
351         /* Let's see if the user passed a valid Linux Wireless mode */
352         if (*uwrq > IW_MODE_MONITOR || *uwrq < IW_MODE_AUTO) {
353                 printk(KERN_DEBUG
354                        "%s: %s() You passed a non-valid init_mode.\n",
355                        priv->ndev->name, __FUNCTION__);
356                 return -EINVAL;
357         }
358
359         down_write(&priv->mib_sem);
360
361         if (prism54_mib_mode_helper(priv, *uwrq)) {
362                 up_write(&priv->mib_sem);
363                 return -EOPNOTSUPP;
364         }
365
366         /* the ACL code needs an intermediate mlmeautolevel. The wpa stuff an
367          * extended one.
368          */
369         if ((*uwrq == IW_MODE_MASTER) && (priv->acl.policy != MAC_POLICY_OPEN))
370                 mlmeautolevel = DOT11_MLME_INTERMEDIATE;
371         if (priv->wpa)
372                 mlmeautolevel = DOT11_MLME_EXTENDED;
373
374         mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &mlmeautolevel);
375
376         mgt_commit(priv);
377         priv->ndev->type = (priv->iw_mode == IW_MODE_MONITOR)
378             ? priv->monitor_type : ARPHRD_ETHER;
379         up_write(&priv->mib_sem);
380
381         return 0;
382 }
383
384 /* Use mib cache */
385 static int
386 prism54_get_mode(struct net_device *ndev, struct iw_request_info *info,
387                  __u32 * uwrq, char *extra)
388 {
389         islpci_private *priv = netdev_priv(ndev);
390
391         BUG_ON((priv->iw_mode < IW_MODE_AUTO) || (priv->iw_mode >
392                                                   IW_MODE_MONITOR));
393         *uwrq = priv->iw_mode;
394
395         return 0;
396 }
397
398 /* we use DOT11_OID_EDTHRESHOLD. From what I guess the card will not try to
399  * emit data if (sensitivity > rssi - noise) (in dBm).
400  * prism54_set_sens does not seem to work.
401  */
402
403 static int
404 prism54_set_sens(struct net_device *ndev, struct iw_request_info *info,
405                  struct iw_param *vwrq, char *extra)
406 {
407         islpci_private *priv = netdev_priv(ndev);
408         u32 sens;
409
410         /* by default  the card sets this to 20. */
411         sens = vwrq->disabled ? 20 : vwrq->value;
412
413         return mgt_set_request(priv, DOT11_OID_EDTHRESHOLD, 0, &sens);
414 }
415
416 static int
417 prism54_get_sens(struct net_device *ndev, struct iw_request_info *info,
418                  struct iw_param *vwrq, char *extra)
419 {
420         islpci_private *priv = netdev_priv(ndev);
421         union oid_res_t r;
422         int rvalue;
423
424         rvalue = mgt_get_request(priv, DOT11_OID_EDTHRESHOLD, 0, NULL, &r);
425
426         vwrq->value = r.u;
427         vwrq->disabled = (vwrq->value == 0);
428         vwrq->fixed = 1;
429
430         return rvalue;
431 }
432
433 static int
434 prism54_get_range(struct net_device *ndev, struct iw_request_info *info,
435                   struct iw_point *dwrq, char *extra)
436 {
437         struct iw_range *range = (struct iw_range *) extra;
438         islpci_private *priv = netdev_priv(ndev);
439         char *data;
440         int i, m, rvalue;
441         struct obj_frequencies *freq;
442         union oid_res_t r;
443
444         memset(range, 0, sizeof (struct iw_range));
445         dwrq->length = sizeof (struct iw_range);
446
447         /* set the wireless extension version number */
448         range->we_version_source = SUPPORTED_WIRELESS_EXT;
449         range->we_version_compiled = WIRELESS_EXT;
450
451         /* Now the encoding capabilities */
452         range->num_encoding_sizes = 3;
453         /* 64(40) bits WEP */
454         range->encoding_size[0] = 5;
455         /* 128(104) bits WEP */
456         range->encoding_size[1] = 13;
457         /* 256 bits for WPA-PSK */
458         range->encoding_size[2] = 32;
459         /* 4 keys are allowed */
460         range->max_encoding_tokens = 4;
461
462         /* we don't know the quality range... */
463         range->max_qual.level = 0;
464         range->max_qual.noise = 0;
465         range->max_qual.qual = 0;
466         /* these value describe an average quality. Needs more tweaking... */
467         range->avg_qual.level = -80;    /* -80 dBm */
468         range->avg_qual.noise = 0;      /* don't know what to put here */
469         range->avg_qual.qual = 0;
470
471         range->sensitivity = 200;
472
473         /* retry limit capabilities */
474         range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
475         range->retry_flags = IW_RETRY_LIMIT;
476         range->r_time_flags = IW_RETRY_LIFETIME;
477
478         /* I don't know the range. Put stupid things here */
479         range->min_retry = 1;
480         range->max_retry = 65535;
481         range->min_r_time = 1024;
482         range->max_r_time = 65535 * 1024;
483
484         /* txpower is supported in dBm's */
485         range->txpower_capa = IW_TXPOW_DBM;
486
487         if (islpci_get_state(priv) < PRV_STATE_INIT)
488                 return 0;
489
490         /* Request the device for the supported frequencies
491          * not really relevant since some devices will report the 5 GHz band
492          * frequencies even if they don't support them.
493          */
494         rvalue =
495             mgt_get_request(priv, DOT11_OID_SUPPORTEDFREQUENCIES, 0, NULL, &r);
496         freq = r.ptr;
497
498         range->num_channels = freq->nr;
499         range->num_frequency = freq->nr;
500
501         m = min(IW_MAX_FREQUENCIES, (int) freq->nr);
502         for (i = 0; i < m; i++) {
503                 range->freq[i].m = freq->mhz[i];
504                 range->freq[i].e = 6;
505                 range->freq[i].i = channel_of_freq(freq->mhz[i]);
506         }
507         kfree(freq);
508
509         rvalue |= mgt_get_request(priv, DOT11_OID_SUPPORTEDRATES, 0, NULL, &r);
510         data = r.ptr;
511
512         /* We got an array of char. It is NULL terminated. */
513         i = 0;
514         while ((i < IW_MAX_BITRATES) && (*data != 0)) {
515                 /*       the result must be in bps. The card gives us 500Kbps */
516                 range->bitrate[i] = (__s32) (*data >> 1);
517                 range->bitrate[i] *= 1000000;
518                 i++;
519                 data++;
520         }
521         range->num_bitrates = i;
522         kfree(r.ptr);
523
524         return rvalue;
525 }
526
527 /* Set AP address*/
528
529 static int
530 prism54_set_wap(struct net_device *ndev, struct iw_request_info *info,
531                 struct sockaddr *awrq, char *extra)
532 {
533         islpci_private *priv = netdev_priv(ndev);
534         char bssid[6];
535         int rvalue;
536
537         if (awrq->sa_family != ARPHRD_ETHER)
538                 return -EINVAL;
539
540         /* prepare the structure for the set object */
541         memcpy(&bssid[0], awrq->sa_data, 6);
542
543         /* set the bssid -- does this make sense when in AP mode? */
544         rvalue = mgt_set_request(priv, DOT11_OID_BSSID, 0, &bssid);
545
546         return (rvalue ? rvalue : -EINPROGRESS);        /* Call commit handler */
547 }
548
549 /* get AP address*/
550
551 static int
552 prism54_get_wap(struct net_device *ndev, struct iw_request_info *info,
553                 struct sockaddr *awrq, char *extra)
554 {
555         islpci_private *priv = netdev_priv(ndev);
556         union oid_res_t r;
557         int rvalue;
558
559         rvalue = mgt_get_request(priv, DOT11_OID_BSSID, 0, NULL, &r);
560         memcpy(awrq->sa_data, r.ptr, 6);
561         awrq->sa_family = ARPHRD_ETHER;
562         kfree(r.ptr);
563
564         return rvalue;
565 }
566
567 static int
568 prism54_set_scan(struct net_device *dev, struct iw_request_info *info,
569                  struct iw_param *vwrq, char *extra)
570 {
571         /* hehe the device does this automagicaly */
572         return 0;
573 }
574
575 /* a little helper that will translate our data into a card independent
576  * format that the Wireless Tools will understand. This was inspired by
577  * the "Aironet driver for 4500 and 4800 series cards" (GPL)
578  */
579
580 inline char *
581 prism54_translate_bss(struct net_device *ndev, char *current_ev,
582                       char *end_buf, struct obj_bss *bss, char noise)
583 {
584         struct iw_event iwe;    /* Temporary buffer */
585         short cap;
586         islpci_private *priv = netdev_priv(ndev);
587
588         /* The first entry must be the MAC address */
589         memcpy(iwe.u.ap_addr.sa_data, bss->address, 6);
590         iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
591         iwe.cmd = SIOCGIWAP;
592         current_ev =
593             iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
594
595         /* The following entries will be displayed in the same order we give them */
596
597         /* The ESSID. */
598         iwe.u.data.length = bss->ssid.length;
599         iwe.u.data.flags = 1;
600         iwe.cmd = SIOCGIWESSID;
601         current_ev = iwe_stream_add_point(current_ev, end_buf,
602                                           &iwe, bss->ssid.octets);
603
604         /* Capabilities */
605 #define CAP_ESS 0x01
606 #define CAP_IBSS 0x02
607 #define CAP_CRYPT 0x10
608
609         /* Mode */
610         cap = bss->capinfo;
611         iwe.u.mode = 0;
612         if (cap & CAP_ESS)
613                 iwe.u.mode = IW_MODE_MASTER;
614         else if (cap & CAP_IBSS)
615                 iwe.u.mode = IW_MODE_ADHOC;
616         iwe.cmd = SIOCGIWMODE;
617         if (iwe.u.mode)
618                 current_ev =
619                     iwe_stream_add_event(current_ev, end_buf, &iwe,
620                                          IW_EV_UINT_LEN);
621
622         /* Encryption capability */
623         if (cap & CAP_CRYPT)
624                 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
625         else
626                 iwe.u.data.flags = IW_ENCODE_DISABLED;
627         iwe.u.data.length = 0;
628         iwe.cmd = SIOCGIWENCODE;
629         current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, NULL);
630
631         /* Add frequency. (short) bss->channel is the frequency in MHz */
632         iwe.u.freq.m = channel_of_freq(bss->channel);
633         iwe.u.freq.e = 0;
634         iwe.cmd = SIOCGIWFREQ;
635         current_ev =
636             iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
637
638         /* Add quality statistics */
639         iwe.u.qual.level = bss->rssi;
640         iwe.u.qual.noise = noise;
641         /* do a simple SNR for quality */
642         iwe.u.qual.qual = bss->rssi - noise;
643         iwe.cmd = IWEVQUAL;
644         current_ev =
645             iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
646
647         if (priv->wpa) {
648                 u8 wpa_ie[MAX_WPA_IE_LEN];
649                 char *buf, *p;
650                 size_t wpa_ie_len;
651                 int i;
652
653                 wpa_ie_len = prism54_wpa_ie_get(priv, bss->address, wpa_ie);
654                 if (wpa_ie_len > 0 &&
655                     (buf = kmalloc(wpa_ie_len * 2 + 10, GFP_ATOMIC))) {
656                         p = buf;
657                         p += sprintf(p, "wpa_ie=");
658                         for (i = 0; i < wpa_ie_len; i++) {
659                                 p += sprintf(p, "%02x", wpa_ie[i]);
660                         }
661                         memset(&iwe, 0, sizeof (iwe));
662                         iwe.cmd = IWEVCUSTOM;
663                         iwe.u.data.length = strlen(buf);
664                         current_ev = iwe_stream_add_point(current_ev, end_buf,
665                                                           &iwe, buf);
666                         kfree(buf);
667                 }
668         }
669         return current_ev;
670 }
671
672 int
673 prism54_get_scan(struct net_device *ndev, struct iw_request_info *info,
674                  struct iw_point *dwrq, char *extra)
675 {
676         islpci_private *priv = netdev_priv(ndev);
677         int i, rvalue;
678         struct obj_bsslist *bsslist;
679         u32 noise = 0;
680         char *current_ev = extra;
681         union oid_res_t r;
682
683         if (islpci_get_state(priv) < PRV_STATE_INIT) {
684                 /* device is not ready, fail gently */
685                 dwrq->length = 0;
686                 return 0;
687         }
688
689         /* first get the noise value. We will use it to report the link quality */
690         rvalue = mgt_get_request(priv, DOT11_OID_NOISEFLOOR, 0, NULL, &r);
691         noise = r.u;
692
693         /* Ask the device for a list of known bss. We can report at most
694          * IW_MAX_AP=64 to the range struct. But the device won't repport anything
695          * if you change the value of IWMAX_BSS=24.
696          */
697         rvalue |= mgt_get_request(priv, DOT11_OID_BSSLIST, 0, NULL, &r);
698         bsslist = r.ptr;
699
700         /* ok now, scan the list and translate its info */
701         for (i = 0; i < min(IW_MAX_AP, (int) bsslist->nr); i++)
702                 current_ev = prism54_translate_bss(ndev, current_ev,
703                                                    extra + IW_SCAN_MAX_DATA,
704                                                    &(bsslist->bsslist[i]),
705                                                    noise);
706         kfree(bsslist);
707         dwrq->length = (current_ev - extra);
708         dwrq->flags = 0;        /* todo */
709
710         return rvalue;
711 }
712
713 static int
714 prism54_set_essid(struct net_device *ndev, struct iw_request_info *info,
715                   struct iw_point *dwrq, char *extra)
716 {
717         islpci_private *priv = netdev_priv(ndev);
718         struct obj_ssid essid;
719
720         memset(essid.octets, 0, 33);
721
722         /* Check if we were asked for `any' */
723         if (dwrq->flags && dwrq->length) {
724                 if (dwrq->length > min(33, IW_ESSID_MAX_SIZE + 1))
725                         return -E2BIG;
726                 essid.length = dwrq->length - 1;
727                 memcpy(essid.octets, extra, dwrq->length);
728         } else
729                 essid.length = 0;
730
731         if (priv->iw_mode != IW_MODE_MONITOR)
732                 return mgt_set_request(priv, DOT11_OID_SSID, 0, &essid);
733
734         /* If in monitor mode, just save to mib */
735         mgt_set(priv, DOT11_OID_SSID, &essid);
736         return 0;
737
738 }
739
740 static int
741 prism54_get_essid(struct net_device *ndev, struct iw_request_info *info,
742                   struct iw_point *dwrq, char *extra)
743 {
744         islpci_private *priv = netdev_priv(ndev);
745         struct obj_ssid *essid;
746         union oid_res_t r;
747         int rvalue;
748
749         rvalue = mgt_get_request(priv, DOT11_OID_SSID, 0, NULL, &r);
750         essid = r.ptr;
751
752         if (essid->length) {
753                 dwrq->flags = 1;        /* set ESSID to ON for Wireless Extensions */
754                 /* if it is to big, trunk it */
755                 dwrq->length = min(IW_ESSID_MAX_SIZE, essid->length + 1);
756         } else {
757                 dwrq->flags = 0;
758                 dwrq->length = 0;
759         }
760         essid->octets[essid->length] = '\0';
761         memcpy(extra, essid->octets, dwrq->length);
762         kfree(essid);
763
764         return rvalue;
765 }
766
767 /* Provides no functionality, just completes the ioctl. In essence this is a 
768  * just a cosmetic ioctl.
769  */
770 static int
771 prism54_set_nick(struct net_device *ndev, struct iw_request_info *info,
772                  struct iw_point *dwrq, char *extra)
773 {
774         islpci_private *priv = netdev_priv(ndev);
775
776         if (dwrq->length > IW_ESSID_MAX_SIZE)
777                 return -E2BIG;
778
779         down_write(&priv->mib_sem);
780         memset(priv->nickname, 0, sizeof (priv->nickname));
781         memcpy(priv->nickname, extra, dwrq->length);
782         up_write(&priv->mib_sem);
783
784         return 0;
785 }
786
787 static int
788 prism54_get_nick(struct net_device *ndev, struct iw_request_info *info,
789                  struct iw_point *dwrq, char *extra)
790 {
791         islpci_private *priv = netdev_priv(ndev);
792
793         dwrq->length = 0;
794
795         down_read(&priv->mib_sem);
796         dwrq->length = strlen(priv->nickname) + 1;
797         memcpy(extra, priv->nickname, dwrq->length);
798         up_read(&priv->mib_sem);
799
800         return 0;
801 }
802
803 /* Set the allowed Bitrates */
804
805 static int
806 prism54_set_rate(struct net_device *ndev,
807                  struct iw_request_info *info,
808                  struct iw_param *vwrq, char *extra)
809 {
810
811         islpci_private *priv = netdev_priv(ndev);
812         u32 rate, profile;
813         char *data;
814         int ret, i;
815         union oid_res_t r;
816
817         if (vwrq->value == -1) {
818                 /* auto mode. No limit. */
819                 profile = 1;
820                 return mgt_set_request(priv, DOT11_OID_PROFILES, 0, &profile);
821         }
822
823         if ((ret =
824              mgt_get_request(priv, DOT11_OID_SUPPORTEDRATES, 0, NULL, &r)))
825                 return ret;
826
827         rate = (u32) (vwrq->value / 500000);
828         data = r.ptr;
829         i = 0;
830
831         while (data[i]) {
832                 if (rate && (data[i] == rate)) {
833                         break;
834                 }
835                 if (vwrq->value == i) {
836                         break;
837                 }
838                 data[i] |= 0x80;
839                 i++;
840         }
841
842         if (!data[i]) {
843                 return -EINVAL;
844         }
845
846         data[i] |= 0x80;
847         data[i + 1] = 0;
848
849         /* Now, check if we want a fixed or auto value */
850         if (vwrq->fixed) {
851                 data[0] = data[i];
852                 data[1] = 0;
853         }
854
855 /*
856         i = 0;
857         printk("prism54 rate: ");
858         while(data[i]) {
859                 printk("%u ", data[i]);
860                 i++;
861         }
862         printk("0\n");
863 */
864         profile = -1;
865         ret = mgt_set_request(priv, DOT11_OID_PROFILES, 0, &profile);
866         ret |= mgt_set_request(priv, DOT11_OID_EXTENDEDRATES, 0, data);
867         ret |= mgt_set_request(priv, DOT11_OID_RATES, 0, data);
868
869         kfree(r.ptr);
870
871         return ret;
872 }
873
874 /* Get the current bit rate */
875 static int
876 prism54_get_rate(struct net_device *ndev,
877                  struct iw_request_info *info,
878                  struct iw_param *vwrq, char *extra)
879 {
880         islpci_private *priv = netdev_priv(ndev);
881         int rvalue;
882         char *data;
883         union oid_res_t r;
884
885         /* Get the current bit rate */
886         if ((rvalue = mgt_get_request(priv, GEN_OID_LINKSTATE, 0, NULL, &r)))
887                 return rvalue;
888         vwrq->value = r.u * 500000;
889
890         /* request the device for the enabled rates */
891         if ((rvalue = mgt_get_request(priv, DOT11_OID_RATES, 0, NULL, &r)))
892                 return rvalue;
893         data = r.ptr;
894         vwrq->fixed = (data[0] != 0) && (data[1] == 0);
895         kfree(r.ptr);
896
897         return 0;
898 }
899
900 static int
901 prism54_set_rts(struct net_device *ndev, struct iw_request_info *info,
902                 struct iw_param *vwrq, char *extra)
903 {
904         islpci_private *priv = netdev_priv(ndev);
905
906         return mgt_set_request(priv, DOT11_OID_RTSTHRESH, 0, &vwrq->value);
907 }
908
909 static int
910 prism54_get_rts(struct net_device *ndev, struct iw_request_info *info,
911                 struct iw_param *vwrq, char *extra)
912 {
913         islpci_private *priv = netdev_priv(ndev);
914         union oid_res_t r;
915         int rvalue;
916
917         /* get the rts threshold */
918         rvalue = mgt_get_request(priv, DOT11_OID_RTSTHRESH, 0, NULL, &r);
919         vwrq->value = r.u;
920
921         return rvalue;
922 }
923
924 static int
925 prism54_set_frag(struct net_device *ndev, struct iw_request_info *info,
926                  struct iw_param *vwrq, char *extra)
927 {
928         islpci_private *priv = netdev_priv(ndev);
929
930         return mgt_set_request(priv, DOT11_OID_FRAGTHRESH, 0, &vwrq->value);
931 }
932
933 static int
934 prism54_get_frag(struct net_device *ndev, struct iw_request_info *info,
935                  struct iw_param *vwrq, char *extra)
936 {
937         islpci_private *priv = netdev_priv(ndev);
938         union oid_res_t r;
939         int rvalue;
940
941         rvalue = mgt_get_request(priv, DOT11_OID_FRAGTHRESH, 0, NULL, &r);
942         vwrq->value = r.u;
943
944         return rvalue;
945 }
946
947 /* Here we have (min,max) = max retries for (small frames, big frames). Where
948  * big frame <=>  bigger than the rts threshold
949  * small frame <=>  smaller than the rts threshold
950  * This is not really the behavior expected by the wireless tool but it seems
951  * to be a common behavior in other drivers.
952  */
953
954 static int
955 prism54_set_retry(struct net_device *ndev, struct iw_request_info *info,
956                   struct iw_param *vwrq, char *extra)
957 {
958         islpci_private *priv = netdev_priv(ndev);
959         u32 slimit = 0, llimit = 0;     /* short and long limit */
960         u32 lifetime = 0;
961         int rvalue = 0;
962
963         if (vwrq->disabled)
964                 /* we cannot disable this feature */
965                 return -EINVAL;
966
967         if (vwrq->flags & IW_RETRY_LIMIT) {
968                 if (vwrq->flags & IW_RETRY_MIN)
969                         slimit = vwrq->value;
970                 else if (vwrq->flags & IW_RETRY_MAX)
971                         llimit = vwrq->value;
972                 else {
973                         /* we are asked to set both */
974                         slimit = vwrq->value;
975                         llimit = vwrq->value;
976                 }
977         }
978         if (vwrq->flags & IW_RETRY_LIFETIME)
979                 /* Wireless tools use us unit while the device uses 1024 us unit */
980                 lifetime = vwrq->value / 1024;
981
982         /* now set what is requested */
983         if (slimit)
984                 rvalue =
985                     mgt_set_request(priv, DOT11_OID_SHORTRETRIES, 0, &slimit);
986         if (llimit)
987                 rvalue |=
988                     mgt_set_request(priv, DOT11_OID_LONGRETRIES, 0, &llimit);
989         if (lifetime)
990                 rvalue |=
991                     mgt_set_request(priv, DOT11_OID_MAXTXLIFETIME, 0,
992                                     &lifetime);
993         return rvalue;
994 }
995
996 static int
997 prism54_get_retry(struct net_device *ndev, struct iw_request_info *info,
998                   struct iw_param *vwrq, char *extra)
999 {
1000         islpci_private *priv = netdev_priv(ndev);
1001         union oid_res_t r;
1002         int rvalue = 0;
1003         vwrq->disabled = 0;     /* It cannot be disabled */
1004
1005         if ((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1006                 /* we are asked for the life time */
1007                 rvalue =
1008                     mgt_get_request(priv, DOT11_OID_MAXTXLIFETIME, 0, NULL, &r);
1009                 vwrq->value = r.u * 1024;
1010                 vwrq->flags = IW_RETRY_LIFETIME;
1011         } else if ((vwrq->flags & IW_RETRY_MAX)) {
1012                 /* we are asked for the long retry limit */
1013                 rvalue |=
1014                     mgt_get_request(priv, DOT11_OID_LONGRETRIES, 0, NULL, &r);
1015                 vwrq->value = r.u;
1016                 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
1017         } else {
1018                 /* default. get the  short retry limit */
1019                 rvalue |=
1020                     mgt_get_request(priv, DOT11_OID_SHORTRETRIES, 0, NULL, &r);
1021                 vwrq->value = r.u;
1022                 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
1023         }
1024
1025         return rvalue;
1026 }
1027
1028 static int
1029 prism54_set_encode(struct net_device *ndev, struct iw_request_info *info,
1030                    struct iw_point *dwrq, char *extra)
1031 {
1032         islpci_private *priv = netdev_priv(ndev);
1033         int rvalue = 0, force = 0;
1034         int authen = DOT11_AUTH_OS, invoke = 0, exunencrypt = 0;
1035         union oid_res_t r;
1036
1037         /* with the new API, it's impossible to get a NULL pointer.
1038          * New version of iwconfig set the IW_ENCODE_NOKEY flag
1039          * when no key is given, but older versions don't. */
1040
1041         if (dwrq->length > 0) {
1042                 /* we have a key to set */
1043                 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1044                 int current_index;
1045                 struct obj_key key = { DOT11_PRIV_WEP, 0, "" };
1046
1047                 /* get the current key index */
1048                 rvalue = mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r);
1049                 current_index = r.u;
1050                 /* Verify that the key is not marked as invalid */
1051                 if (!(dwrq->flags & IW_ENCODE_NOKEY)) {
1052                         key.length = dwrq->length > sizeof (key.key) ?
1053                             sizeof (key.key) : dwrq->length;
1054                         memcpy(key.key, extra, key.length);
1055                         if (key.length == 32)
1056                                 /* we want WPA-PSK */
1057                                 key.type = DOT11_PRIV_TKIP;
1058                         if ((index < 0) || (index > 3))
1059                                 /* no index provided use the current one */
1060                                 index = current_index;
1061
1062                         /* now send the key to the card  */
1063                         rvalue |=
1064                             mgt_set_request(priv, DOT11_OID_DEFKEYX, index,
1065                                             &key);
1066                 }
1067                 /*
1068                  * If a valid key is set, encryption should be enabled 
1069                  * (user may turn it off later).
1070                  * This is also how "iwconfig ethX key on" works
1071                  */
1072                 if ((index == current_index) && (key.length > 0))
1073                         force = 1;
1074         } else {
1075                 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1076                 if ((index >= 0) && (index <= 3)) {
1077                         /* we want to set the key index */
1078                         rvalue |=
1079                             mgt_set_request(priv, DOT11_OID_DEFKEYID, 0,
1080                                             &index);
1081                 } else {
1082                         if (!dwrq->flags & IW_ENCODE_MODE) {
1083                                 /* we cannot do anything. Complain. */
1084                                 return -EINVAL;
1085                         }
1086                 }
1087         }
1088         /* now read the flags */
1089         if (dwrq->flags & IW_ENCODE_DISABLED) {
1090                 /* Encoding disabled, 
1091                  * authen = DOT11_AUTH_OS;
1092                  * invoke = 0;
1093                  * exunencrypt = 0; */
1094         }
1095         if (dwrq->flags & IW_ENCODE_OPEN)
1096                 /* Encode but accept non-encoded packets. No auth */
1097                 invoke = 1;
1098         if ((dwrq->flags & IW_ENCODE_RESTRICTED) || force) {
1099                 /* Refuse non-encoded packets. Auth */
1100                 authen = DOT11_AUTH_BOTH;
1101                 invoke = 1;
1102                 exunencrypt = 1;
1103         }
1104         /* do the change if requested  */
1105         if ((dwrq->flags & IW_ENCODE_MODE) || force) {
1106                 rvalue |=
1107                     mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0, &authen);
1108                 rvalue |=
1109                     mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0, &invoke);
1110                 rvalue |=
1111                     mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0,
1112                                     &exunencrypt);
1113         }
1114         return rvalue;
1115 }
1116
1117 static int
1118 prism54_get_encode(struct net_device *ndev, struct iw_request_info *info,
1119                    struct iw_point *dwrq, char *extra)
1120 {
1121         islpci_private *priv = netdev_priv(ndev);
1122         struct obj_key *key;
1123         u32 devindex, index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1124         u32 authen = 0, invoke = 0, exunencrypt = 0;
1125         int rvalue;
1126         union oid_res_t r;
1127
1128         /* first get the flags */
1129         rvalue = mgt_get_request(priv, DOT11_OID_AUTHENABLE, 0, NULL, &r);
1130         authen = r.u;
1131         rvalue |= mgt_get_request(priv, DOT11_OID_PRIVACYINVOKED, 0, NULL, &r);
1132         invoke = r.u;
1133         rvalue |= mgt_get_request(priv, DOT11_OID_EXUNENCRYPTED, 0, NULL, &r);
1134         exunencrypt = r.u;
1135
1136         if (invoke && (authen == DOT11_AUTH_BOTH) && exunencrypt)
1137                 dwrq->flags = IW_ENCODE_RESTRICTED;
1138         else if ((authen == DOT11_AUTH_OS) && !exunencrypt) {
1139                 if (invoke)
1140                         dwrq->flags = IW_ENCODE_OPEN;
1141                 else
1142                         dwrq->flags = IW_ENCODE_DISABLED;
1143         } else
1144                 /* The card should not work in this state */
1145                 dwrq->flags = 0;
1146
1147         /* get the current device key index */
1148         rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r);
1149         devindex = r.u;
1150         /* Now get the key, return it */
1151         if ((index < 0) || (index > 3))
1152                 /* no index provided, use the current one */
1153                 index = devindex;
1154         rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYX, index, NULL, &r);
1155         key = r.ptr;
1156         dwrq->length = key->length;
1157         memcpy(extra, key->key, dwrq->length);
1158         kfree(key);
1159         /* return the used key index */
1160         dwrq->flags |= devindex + 1;
1161
1162         return rvalue;
1163 }
1164
1165 static int
1166 prism54_get_txpower(struct net_device *ndev, struct iw_request_info *info,
1167                     struct iw_param *vwrq, char *extra)
1168 {
1169         islpci_private *priv = netdev_priv(ndev);
1170         union oid_res_t r;
1171         int rvalue;
1172
1173         rvalue = mgt_get_request(priv, OID_INL_OUTPUTPOWER, 0, NULL, &r);
1174         /* intersil firmware operates in 0.25 dBm (1/4 dBm) */
1175         vwrq->value = (s32) r.u / 4;
1176         vwrq->fixed = 1;
1177         /* radio is not turned of
1178          * btw: how is possible to turn off only the radio 
1179          */
1180         vwrq->disabled = 0;
1181
1182         return rvalue;
1183 }
1184
1185 static int
1186 prism54_set_txpower(struct net_device *ndev, struct iw_request_info *info,
1187                     struct iw_param *vwrq, char *extra)
1188 {
1189         islpci_private *priv = netdev_priv(ndev);
1190         s32 u = vwrq->value;
1191
1192         /* intersil firmware operates in 0.25 dBm (1/4) */
1193         u *= 4;
1194         if (vwrq->disabled) {
1195                 /* don't know how to disable radio */
1196                 printk(KERN_DEBUG
1197                        "%s: %s() disabling radio is not yet supported.\n",
1198                        priv->ndev->name, __FUNCTION__);
1199                 return -ENOTSUPP;
1200         } else if (vwrq->fixed)
1201                 /* currently only fixed value is supported */
1202                 return mgt_set_request(priv, OID_INL_OUTPUTPOWER, 0, &u);
1203         else {
1204                 printk(KERN_DEBUG
1205                        "%s: %s() auto power will be implemented later.\n",
1206                        priv->ndev->name, __FUNCTION__);
1207                 return -ENOTSUPP;
1208         }
1209 }
1210
1211 static int
1212 prism54_reset(struct net_device *ndev, struct iw_request_info *info,
1213               __u32 * uwrq, char *extra)
1214 {
1215         islpci_reset(netdev_priv(ndev), 0);
1216
1217         return 0;
1218 }
1219
1220 static int
1221 prism54_get_oid(struct net_device *ndev, struct iw_request_info *info,
1222                 struct iw_point *dwrq, char *extra)
1223 {
1224         union oid_res_t r;
1225         int rvalue;
1226         enum oid_num_t n = dwrq->flags;
1227
1228         rvalue = mgt_get_request((islpci_private *) ndev->priv, n, 0, NULL, &r);
1229         dwrq->length = mgt_response_to_str(n, &r, extra);
1230         if ((isl_oid[n].flags & OID_FLAG_TYPE) != OID_TYPE_U32)
1231                 kfree(r.ptr);
1232         return rvalue;
1233 }
1234
1235 static int
1236 prism54_set_u32(struct net_device *ndev, struct iw_request_info *info,
1237                 __u32 * uwrq, char *extra)
1238 {
1239         u32 oid = uwrq[0], u = uwrq[1];
1240
1241         return mgt_set_request((islpci_private *) ndev->priv, oid, 0, &u);
1242 }
1243
1244 static int
1245 prism54_set_raw(struct net_device *ndev, struct iw_request_info *info,
1246                 struct iw_point *dwrq, char *extra)
1247 {
1248         u32 oid = dwrq->flags;
1249
1250         return mgt_set_request((islpci_private *) ndev->priv, oid, 0, extra);
1251 }
1252
1253 void
1254 prism54_acl_init(struct islpci_acl *acl)
1255 {
1256         sema_init(&acl->sem, 1);
1257         INIT_LIST_HEAD(&acl->mac_list);
1258         acl->size = 0;
1259         acl->policy = MAC_POLICY_OPEN;
1260 }
1261
1262 static void
1263 prism54_clear_mac(struct islpci_acl *acl)
1264 {
1265         struct list_head *ptr, *next;
1266         struct mac_entry *entry;
1267
1268         if (down_interruptible(&acl->sem))
1269                 return;
1270
1271         if (acl->size == 0) {
1272                 up(&acl->sem);
1273                 return;
1274         }
1275
1276         for (ptr = acl->mac_list.next, next = ptr->next;
1277              ptr != &acl->mac_list; ptr = next, next = ptr->next) {
1278                 entry = list_entry(ptr, struct mac_entry, _list);
1279                 list_del(ptr);
1280                 kfree(entry);
1281         }
1282         acl->size = 0;
1283         up(&acl->sem);
1284 }
1285
1286 void
1287 prism54_acl_clean(struct islpci_acl *acl)
1288 {
1289         prism54_clear_mac(acl);
1290 }
1291
1292 static int
1293 prism54_add_mac(struct net_device *ndev, struct iw_request_info *info,
1294                 struct sockaddr *awrq, char *extra)
1295 {
1296         islpci_private *priv = netdev_priv(ndev);
1297         struct islpci_acl *acl = &priv->acl;
1298         struct mac_entry *entry;
1299         struct sockaddr *addr = (struct sockaddr *) extra;
1300
1301         if (addr->sa_family != ARPHRD_ETHER)
1302                 return -EOPNOTSUPP;
1303
1304         entry = kmalloc(sizeof (struct mac_entry), GFP_KERNEL);
1305         if (entry == NULL)
1306                 return -ENOMEM;
1307
1308         memcpy(entry->addr, addr->sa_data, ETH_ALEN);
1309
1310         if (down_interruptible(&acl->sem)) {
1311                 kfree(entry);
1312                 return -ERESTARTSYS;
1313         }
1314         list_add_tail(&entry->_list, &acl->mac_list);
1315         acl->size++;
1316         up(&acl->sem);
1317
1318         return 0;
1319 }
1320
1321 static int
1322 prism54_del_mac(struct net_device *ndev, struct iw_request_info *info,
1323                 struct sockaddr *awrq, char *extra)
1324 {
1325         islpci_private *priv = netdev_priv(ndev);
1326         struct islpci_acl *acl = &priv->acl;
1327         struct mac_entry *entry;
1328         struct list_head *ptr;
1329         struct sockaddr *addr = (struct sockaddr *) extra;
1330
1331         if (addr->sa_family != ARPHRD_ETHER)
1332                 return -EOPNOTSUPP;
1333
1334         if (down_interruptible(&acl->sem))
1335                 return -ERESTARTSYS;
1336         for (ptr = acl->mac_list.next; ptr != &acl->mac_list; ptr = ptr->next) {
1337                 entry = list_entry(ptr, struct mac_entry, _list);
1338
1339                 if (memcmp(entry->addr, addr->sa_data, ETH_ALEN) == 0) {
1340                         list_del(ptr);
1341                         acl->size--;
1342                         kfree(entry);
1343                         up(&acl->sem);
1344                         return 0;
1345                 }
1346         }
1347         up(&acl->sem);
1348         return -EINVAL;
1349 }
1350
1351 static int
1352 prism54_get_mac(struct net_device *ndev, struct iw_request_info *info,
1353                 struct iw_point *dwrq, char *extra)
1354 {
1355         islpci_private *priv = netdev_priv(ndev);
1356         struct islpci_acl *acl = &priv->acl;
1357         struct mac_entry *entry;
1358         struct list_head *ptr;
1359         struct sockaddr *dst = (struct sockaddr *) extra;
1360
1361         dwrq->length = 0;
1362
1363         if (down_interruptible(&acl->sem))
1364                 return -ERESTARTSYS;
1365
1366         for (ptr = acl->mac_list.next; ptr != &acl->mac_list; ptr = ptr->next) {
1367                 entry = list_entry(ptr, struct mac_entry, _list);
1368
1369                 memcpy(dst->sa_data, entry->addr, ETH_ALEN);
1370                 dst->sa_family = ARPHRD_ETHER;
1371                 dwrq->length++;
1372                 dst++;
1373         }
1374         up(&acl->sem);
1375         return 0;
1376 }
1377
1378 /* Setting policy also clears the MAC acl, even if we don't change the defaut
1379  * policy
1380  */
1381
1382 static int
1383 prism54_set_policy(struct net_device *ndev, struct iw_request_info *info,
1384                    __u32 * uwrq, char *extra)
1385 {
1386         islpci_private *priv = netdev_priv(ndev);
1387         struct islpci_acl *acl = &priv->acl;
1388         u32 mlmeautolevel;
1389
1390         prism54_clear_mac(acl);
1391
1392         if ((*uwrq < MAC_POLICY_OPEN) || (*uwrq > MAC_POLICY_REJECT))
1393                 return -EINVAL;
1394
1395         down_write(&priv->mib_sem);
1396
1397         acl->policy = *uwrq;
1398
1399         /* the ACL code needs an intermediate mlmeautolevel */
1400         if ((priv->iw_mode == IW_MODE_MASTER) &&
1401             (acl->policy != MAC_POLICY_OPEN))
1402                 mlmeautolevel = DOT11_MLME_INTERMEDIATE;
1403         else
1404                 mlmeautolevel = CARD_DEFAULT_MLME_MODE;
1405         if (priv->wpa)
1406                 mlmeautolevel = DOT11_MLME_EXTENDED;
1407         mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &mlmeautolevel);
1408         /* restart the card with our new policy */
1409         mgt_commit(priv);
1410         up_write(&priv->mib_sem);
1411
1412         return 0;
1413 }
1414
1415 static int
1416 prism54_get_policy(struct net_device *ndev, struct iw_request_info *info,
1417                    __u32 * uwrq, char *extra)
1418 {
1419         islpci_private *priv = netdev_priv(ndev);
1420         struct islpci_acl *acl = &priv->acl;
1421
1422         *uwrq = acl->policy;
1423
1424         return 0;
1425 }
1426
1427 /* Return 1 only if client should be accepted. */
1428
1429 static int
1430 prism54_mac_accept(struct islpci_acl *acl, char *mac)
1431 {
1432         struct list_head *ptr;
1433         struct mac_entry *entry;
1434         int res = 0;
1435
1436         if (down_interruptible(&acl->sem))
1437                 return -ERESTARTSYS;
1438
1439         if (acl->policy == MAC_POLICY_OPEN) {
1440                 up(&acl->sem);
1441                 return 1;
1442         }
1443
1444         for (ptr = acl->mac_list.next; ptr != &acl->mac_list; ptr = ptr->next) {
1445                 entry = list_entry(ptr, struct mac_entry, _list);
1446                 if (memcmp(entry->addr, mac, ETH_ALEN) == 0) {
1447                         res = 1;
1448                         break;
1449                 }
1450         }
1451         res = (acl->policy == MAC_POLICY_ACCEPT) ? !res : res;
1452         up(&acl->sem);
1453
1454         return res;
1455 }
1456
1457 static int
1458 prism54_kick_all(struct net_device *ndev, struct iw_request_info *info,
1459                  struct iw_point *dwrq, char *extra)
1460 {
1461         struct obj_mlme *mlme;
1462         int rvalue;
1463
1464         mlme = kmalloc(sizeof (struct obj_mlme), GFP_KERNEL);
1465         if (mlme == NULL)
1466                 return -ENOMEM;
1467
1468         /* Tell the card to kick every client */
1469         mlme->id = 0;
1470         rvalue =
1471             mgt_set_request(netdev_priv(ndev), DOT11_OID_DISASSOCIATE, 0, mlme);
1472         kfree(mlme);
1473
1474         return rvalue;
1475 }
1476
1477 static int
1478 prism54_kick_mac(struct net_device *ndev, struct iw_request_info *info,
1479                  struct sockaddr *awrq, char *extra)
1480 {
1481         struct obj_mlme *mlme;
1482         struct sockaddr *addr = (struct sockaddr *) extra;
1483         int rvalue;
1484
1485         if (addr->sa_family != ARPHRD_ETHER)
1486                 return -EOPNOTSUPP;
1487
1488         mlme = kmalloc(sizeof (struct obj_mlme), GFP_KERNEL);
1489         if (mlme == NULL)
1490                 return -ENOMEM;
1491
1492         /* Tell the card to only kick the corresponding bastard */
1493         memcpy(mlme->address, addr->sa_data, ETH_ALEN);
1494         mlme->id = -1;
1495         rvalue =
1496             mgt_set_request(netdev_priv(ndev), DOT11_OID_DISASSOCIATE, 0, mlme);
1497
1498         kfree(mlme);
1499
1500         return rvalue;
1501 }
1502
1503 /* Translate a TRAP oid into a wireless event. Called in islpci_mgt_receive. */
1504
1505 static inline void
1506 format_event(islpci_private *priv, char *dest, const char *str,
1507              const struct obj_mlme *mlme, u16 *length, int error)
1508 {
1509         const u8 *a = mlme->address;
1510         int n = snprintf(dest, IW_CUSTOM_MAX,
1511                          "%s %s %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X %s (%2.2X)",
1512                          str,
1513                          ((priv->iw_mode == IW_MODE_MASTER) ? "from" : "to"),
1514                          a[0], a[1], a[2], a[3], a[4], a[5],
1515                          (error ? (mlme->code ? " : REJECTED " : " : ACCEPTED ")
1516                           : ""), mlme->code);
1517         BUG_ON(n > IW_CUSTOM_MAX);
1518         *length = n;
1519 }
1520
1521 static void
1522 send_formatted_event(islpci_private *priv, const char *str,
1523                      const struct obj_mlme *mlme, int error)
1524 {
1525         union iwreq_data wrqu;
1526
1527         wrqu.data.pointer = kmalloc(IW_CUSTOM_MAX, GFP_KERNEL);
1528         if (!wrqu.data.pointer)
1529                 return;
1530         wrqu.data.length = 0;
1531         format_event(priv, wrqu.data.pointer, str, mlme, &wrqu.data.length,
1532                      error);
1533         wireless_send_event(priv->ndev, IWEVCUSTOM, &wrqu, wrqu.data.pointer);
1534         kfree(wrqu.data.pointer);
1535 }
1536
1537 static void
1538 send_simple_event(islpci_private *priv, const char *str)
1539 {
1540         union iwreq_data wrqu;
1541         int n = strlen(str);
1542
1543         wrqu.data.pointer = kmalloc(IW_CUSTOM_MAX, GFP_KERNEL);
1544         if (!wrqu.data.pointer)
1545                 return;
1546         BUG_ON(n > IW_CUSTOM_MAX);
1547         wrqu.data.length = n;
1548         strcpy(wrqu.data.pointer, str);
1549         wireless_send_event(priv->ndev, IWEVCUSTOM, &wrqu, wrqu.data.pointer);
1550         kfree(wrqu.data.pointer);
1551 }
1552
1553 static void
1554 link_changed(struct net_device *ndev, u32 bitrate)
1555 {
1556         islpci_private *priv = netdev_priv(ndev);
1557
1558         if (bitrate) {
1559                 if (priv->iw_mode == IW_MODE_INFRA) {
1560                         union iwreq_data uwrq;
1561                         prism54_get_wap(ndev, NULL, (struct sockaddr *) &uwrq,
1562                                         NULL);
1563                         wireless_send_event(ndev, SIOCGIWAP, &uwrq, NULL);
1564                 } else
1565                         send_simple_event(netdev_priv(ndev),
1566                                           "Link established");
1567         } else
1568                 send_simple_event(netdev_priv(ndev), "Link lost");
1569 }
1570
1571 /* Beacon/ProbeResp payload header */
1572 struct ieee80211_beacon_phdr {
1573         u8 timestamp[8];
1574         u16 beacon_int;
1575         u16 capab_info;
1576 } __attribute__ ((packed));
1577
1578 #define WLAN_EID_GENERIC 0xdd
1579 static u8 wpa_oid[4] = { 0x00, 0x50, 0xf2, 1 };
1580
1581 #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
1582 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
1583
1584 void
1585 prism54_wpa_ie_add(islpci_private *priv, u8 *bssid,
1586                    u8 *wpa_ie, size_t wpa_ie_len)
1587 {
1588         struct list_head *ptr;
1589         struct islpci_bss_wpa_ie *bss = NULL;
1590
1591         if (wpa_ie_len > MAX_WPA_IE_LEN)
1592                 wpa_ie_len = MAX_WPA_IE_LEN;
1593
1594         if (down_interruptible(&priv->wpa_sem))
1595                 return;
1596
1597         /* try to use existing entry */
1598         list_for_each(ptr, &priv->bss_wpa_list) {
1599                 bss = list_entry(ptr, struct islpci_bss_wpa_ie, list);
1600                 if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0) {
1601                         list_move(&bss->list, &priv->bss_wpa_list);
1602                         break;
1603                 }
1604                 bss = NULL;
1605         }
1606
1607         if (bss == NULL) {
1608                 /* add a new BSS entry; if max number of entries is already
1609                  * reached, replace the least recently updated */
1610                 if (priv->num_bss_wpa >= MAX_BSS_WPA_IE_COUNT) {
1611                         bss = list_entry(priv->bss_wpa_list.prev,
1612                                          struct islpci_bss_wpa_ie, list);
1613                         list_del(&bss->list);
1614                 } else {
1615                         bss = kmalloc(sizeof (*bss), GFP_ATOMIC);
1616                         if (bss != NULL) {
1617                                 priv->num_bss_wpa++;
1618                                 memset(bss, 0, sizeof (*bss));
1619                         }
1620                 }
1621                 if (bss != NULL) {
1622                         memcpy(bss->bssid, bssid, ETH_ALEN);
1623                         list_add(&bss->list, &priv->bss_wpa_list);
1624                 }
1625         }
1626
1627         if (bss != NULL) {
1628                 memcpy(bss->wpa_ie, wpa_ie, wpa_ie_len);
1629                 bss->wpa_ie_len = wpa_ie_len;
1630                 bss->last_update = jiffies;
1631         } else {
1632                 printk(KERN_DEBUG "Failed to add BSS WPA entry for " MACSTR
1633                        "\n", MAC2STR(bssid));
1634         }
1635
1636         /* expire old entries from WPA list */
1637         while (priv->num_bss_wpa > 0) {
1638                 bss = list_entry(priv->bss_wpa_list.prev,
1639                                  struct islpci_bss_wpa_ie, list);
1640                 if (!time_after(jiffies, bss->last_update + 60 * HZ))
1641                         break;
1642
1643                 list_del(&bss->list);
1644                 priv->num_bss_wpa--;
1645                 kfree(bss);
1646         }
1647
1648         up(&priv->wpa_sem);
1649 }
1650
1651 size_t
1652 prism54_wpa_ie_get(islpci_private *priv, u8 *bssid, u8 *wpa_ie)
1653 {
1654         struct list_head *ptr;
1655         struct islpci_bss_wpa_ie *bss = NULL;
1656         size_t len = 0;
1657
1658         if (down_interruptible(&priv->wpa_sem))
1659                 return 0;
1660
1661         list_for_each(ptr, &priv->bss_wpa_list) {
1662                 bss = list_entry(ptr, struct islpci_bss_wpa_ie, list);
1663                 if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0)
1664                         break;
1665                 bss = NULL;
1666         }
1667         if (bss) {
1668                 len = bss->wpa_ie_len;
1669                 memcpy(wpa_ie, bss->wpa_ie, len);
1670         }
1671         up(&priv->wpa_sem);
1672
1673         return len;
1674 }
1675
1676 void
1677 prism54_wpa_ie_init(islpci_private *priv)
1678 {
1679         INIT_LIST_HEAD(&priv->bss_wpa_list);
1680         sema_init(&priv->wpa_sem, 1);
1681 }
1682
1683 void
1684 prism54_wpa_ie_clean(islpci_private *priv)
1685 {
1686         struct list_head *ptr, *n;
1687
1688         list_for_each_safe(ptr, n, &priv->bss_wpa_list) {
1689                 struct islpci_bss_wpa_ie *bss;
1690                 bss = list_entry(ptr, struct islpci_bss_wpa_ie, list);
1691                 kfree(bss);
1692         }
1693 }
1694
1695 static void
1696 prism54_process_bss_data(islpci_private *priv, u32 oid, u8 *addr,
1697                          u8 *payload, size_t len)
1698 {
1699         struct ieee80211_beacon_phdr *hdr;
1700         u8 *pos, *end;
1701
1702         if (!priv->wpa)
1703                 return;
1704
1705         hdr = (struct ieee80211_beacon_phdr *) payload;
1706         pos = (u8 *) (hdr + 1);
1707         end = payload + len;
1708         while (pos < end) {
1709                 if (pos + 2 + pos[1] > end) {
1710                         printk(KERN_DEBUG "Parsing Beacon/ProbeResp failed "
1711                                "for " MACSTR "\n", MAC2STR(addr));
1712                         return;
1713                 }
1714                 if (pos[0] == WLAN_EID_GENERIC && pos[1] >= 4 &&
1715                     memcmp(pos + 2, wpa_oid, 4) == 0) {
1716                         prism54_wpa_ie_add(priv, addr, pos, pos[1] + 2);
1717                         return;
1718                 }
1719                 pos += 2 + pos[1];
1720         }
1721 }
1722
1723 static void
1724 handle_request(islpci_private *priv, struct obj_mlme *mlme, enum oid_num_t oid)
1725 {
1726         if (((mlme->state == DOT11_STATE_AUTHING) ||
1727              (mlme->state == DOT11_STATE_ASSOCING))
1728             && mgt_mlme_answer(priv)) {
1729                 /* Someone is requesting auth and we must respond. Just send back
1730                  * the trap with error code set accordingly.
1731                  */
1732                 mlme->code = prism54_mac_accept(&priv->acl,
1733                                                 mlme->address) ? 0 : 1;
1734                 mgt_set_request(priv, oid, 0, mlme);
1735         }
1736 }
1737
1738 int
1739 prism54_process_trap_helper(islpci_private *priv, enum oid_num_t oid,
1740                             char *data)
1741 {
1742         struct obj_mlme *mlme = (struct obj_mlme *) data;
1743         size_t len;
1744         u8 *payload, *pos = (u8 *) (mlme + 1);
1745
1746         len = pos[0] | (pos[1] << 8);   /* little endian data length */
1747         payload = pos + 2;
1748
1749         /* I think all trapable objects are listed here.
1750          * Some oids have a EX version. The difference is that they are emitted
1751          * in DOT11_MLME_EXTENDED mode (set with DOT11_OID_MLMEAUTOLEVEL)
1752          * with more info.
1753          * The few events already defined by the wireless tools are not really
1754          * suited. We use the more flexible custom event facility.
1755          */
1756
1757         /* I fear prism54_process_bss_data won't work with big endian data */
1758         if ((oid == DOT11_OID_BEACON) || (oid == DOT11_OID_PROBE))
1759                 prism54_process_bss_data(priv, oid, mlme->address,
1760                                          payload, len);
1761
1762         mgt_le_to_cpu(isl_oid[oid].flags & OID_FLAG_TYPE, (void *) mlme);
1763
1764         switch (oid) {
1765
1766         case GEN_OID_LINKSTATE:
1767                 link_changed(priv->ndev, (u32) *data);
1768                 break;
1769
1770         case DOT11_OID_MICFAILURE:
1771                 send_simple_event(priv, "Mic failure");
1772                 break;
1773
1774         case DOT11_OID_DEAUTHENTICATE:
1775                 send_formatted_event(priv, "DeAuthenticate request", mlme, 0);
1776                 break;
1777
1778         case DOT11_OID_AUTHENTICATE:
1779                 handle_request(priv, mlme, oid);
1780                 send_formatted_event(priv, "Authenticate request", mlme, 1);
1781                 break;
1782
1783         case DOT11_OID_DISASSOCIATE:
1784                 send_formatted_event(priv, "Disassociate request", mlme, 0);
1785                 break;
1786
1787         case DOT11_OID_ASSOCIATE:
1788                 handle_request(priv, mlme, oid);
1789                 send_formatted_event(priv, "Associate request", mlme, 1);
1790                 break;
1791
1792         case DOT11_OID_REASSOCIATE:
1793                 handle_request(priv, mlme, oid);
1794                 send_formatted_event(priv, "ReAssociate request", mlme, 1);
1795                 break;
1796
1797         case DOT11_OID_BEACON:
1798                 send_formatted_event(priv,
1799                                      "Received a beacon from an unkown AP",
1800                                      mlme, 0);
1801                 break;
1802
1803         case DOT11_OID_PROBE:
1804                 /* we received a probe from a client. */
1805                 send_formatted_event(priv, "Received a probe from client", mlme,
1806                                      0);
1807                 break;
1808
1809                 /* Note : "mlme" is actually a "struct obj_mlmeex *" here, but this
1810                  * is backward compatible layout-wise with "struct obj_mlme".
1811                  */
1812
1813         case DOT11_OID_DEAUTHENTICATEEX:
1814                 send_formatted_event(priv, "DeAuthenticate request", mlme, 0);
1815                 break;
1816
1817         case DOT11_OID_AUTHENTICATEEX:
1818                 handle_request(priv, mlme, oid);
1819                 send_formatted_event(priv, "Authenticate request", mlme, 1);
1820                 break;
1821
1822         case DOT11_OID_DISASSOCIATEEX:
1823                 send_formatted_event(priv, "Disassociate request", mlme, 0);
1824                 break;
1825
1826         case DOT11_OID_ASSOCIATEEX:
1827                 handle_request(priv, mlme, oid);
1828                 send_formatted_event(priv, "Associate request", mlme, 1);
1829                 break;
1830
1831         case DOT11_OID_REASSOCIATEEX:
1832                 handle_request(priv, mlme, oid);
1833                 send_formatted_event(priv, "Reassociate request", mlme, 1);
1834                 break;
1835
1836         default:
1837                 return -EINVAL;
1838         }
1839
1840         return 0;
1841 }
1842
1843 /*
1844  * Process a device trap.  This is called via schedule_work(), outside of
1845  * interrupt context, no locks held.
1846  */
1847 void
1848 prism54_process_trap(void *data)
1849 {
1850         struct islpci_mgmtframe *frame = data;
1851         struct net_device *ndev = frame->ndev;
1852         enum oid_num_t n = mgt_oidtonum(frame->header->oid);
1853
1854         if (n != OID_NUM_LAST)
1855                 prism54_process_trap_helper(netdev_priv(ndev), n, frame->data);
1856         islpci_mgt_release(frame);
1857 }
1858
1859 int
1860 prism54_set_mac_address(struct net_device *ndev, void *addr)
1861 {
1862         islpci_private *priv = netdev_priv(ndev);
1863         int ret;
1864
1865         if (ndev->addr_len != 6)
1866                 return -EINVAL;
1867         ret = mgt_set_request(priv, GEN_OID_MACADDRESS, 0,
1868                               &((struct sockaddr *) addr)->sa_data);
1869         if (!ret)
1870                 memcpy(priv->ndev->dev_addr,
1871                        &((struct sockaddr *) addr)->sa_data, 6);
1872
1873         return ret;
1874 }
1875
1876 int
1877 prism54_set_wpa(struct net_device *ndev, struct iw_request_info *info,
1878                 __u32 * uwrq, char *extra)
1879 {
1880         islpci_private *priv = netdev_priv(ndev);
1881
1882         down_write(&priv->mib_sem);
1883
1884         priv->wpa = *uwrq;
1885         if (priv->wpa) {
1886                 u32 l = DOT11_MLME_EXTENDED;
1887                 mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &l);
1888         }
1889         /* restart the card with new level. Needed ? */
1890         mgt_commit(priv);
1891         up_write(&priv->mib_sem);
1892
1893         return 0;
1894 }
1895
1896 int
1897 prism54_get_wpa(struct net_device *ndev, struct iw_request_info *info,
1898                 __u32 * uwrq, char *extra)
1899 {
1900         islpci_private *priv = netdev_priv(ndev);
1901         *uwrq = priv->wpa;
1902         return 0;
1903 }
1904
1905 int
1906 prism54_set_prismhdr(struct net_device *ndev, struct iw_request_info *info,
1907                      __u32 * uwrq, char *extra)
1908 {
1909         islpci_private *priv = netdev_priv(ndev);
1910         priv->monitor_type =
1911             (*uwrq ? ARPHRD_IEEE80211_PRISM : ARPHRD_IEEE80211);
1912         if (priv->iw_mode == IW_MODE_MONITOR)
1913                 priv->ndev->type = priv->monitor_type;
1914
1915         return 0;
1916 }
1917
1918 int
1919 prism54_get_prismhdr(struct net_device *ndev, struct iw_request_info *info,
1920                      __u32 * uwrq, char *extra)
1921 {
1922         islpci_private *priv = netdev_priv(ndev);
1923         *uwrq = (priv->monitor_type == ARPHRD_IEEE80211_PRISM);
1924         return 0;
1925 }
1926
1927 int
1928 prism54_debug_oid(struct net_device *ndev, struct iw_request_info *info,
1929                   __u32 * uwrq, char *extra)
1930 {
1931         islpci_private *priv = netdev_priv(ndev);
1932
1933         priv->priv_oid = *uwrq;
1934         printk("%s: oid 0x%08X\n", ndev->name, *uwrq);
1935
1936         return 0;
1937 }
1938
1939 int
1940 prism54_debug_get_oid(struct net_device *ndev, struct iw_request_info *info,
1941                       struct iw_point *data, char *extra)
1942 {
1943         islpci_private *priv = netdev_priv(ndev);
1944         struct islpci_mgmtframe *response = NULL;
1945         int ret = -EIO, response_op = PIMFOR_OP_ERROR;
1946
1947         printk("%s: get_oid 0x%08X\n", ndev->name, priv->priv_oid);
1948         data->length = 0;
1949
1950         if (islpci_get_state(priv) >= PRV_STATE_INIT) {
1951                 ret =
1952                     islpci_mgt_transaction(priv->ndev, PIMFOR_OP_GET,
1953                                            priv->priv_oid, extra, 256,
1954                                            &response);
1955                 response_op = response->header->operation;
1956                 printk("%s: ret: %i\n", ndev->name, ret);
1957                 printk("%s: response_op: %i\n", ndev->name, response_op);
1958                 if (ret || !response
1959                     || response->header->operation == PIMFOR_OP_ERROR) {
1960                         if (response) {
1961                                 islpci_mgt_release(response);
1962                         }
1963                         printk("%s: EIO\n", ndev->name);
1964                         ret = -EIO;
1965                 }
1966                 if (!ret) {
1967                         data->length = response->header->length;
1968                         memcpy(extra, response->data, data->length);
1969                         islpci_mgt_release(response);
1970                         printk("%s: len: %i\n", ndev->name, data->length);
1971                 }
1972         }
1973
1974         return ret;
1975 }
1976
1977 int
1978 prism54_debug_set_oid(struct net_device *ndev, struct iw_request_info *info,
1979                       struct iw_point *data, char *extra)
1980 {
1981         islpci_private *priv = netdev_priv(ndev);
1982         struct islpci_mgmtframe *response = NULL;
1983         int ret = 0, response_op = PIMFOR_OP_ERROR;
1984
1985         printk("%s: set_oid 0x%08X\tlen: %d\n", ndev->name, priv->priv_oid,
1986                data->length);
1987
1988         if (islpci_get_state(priv) >= PRV_STATE_INIT) {
1989                 ret =
1990                     islpci_mgt_transaction(priv->ndev, PIMFOR_OP_SET,
1991                                            priv->priv_oid, extra, data->length,
1992                                            &response);
1993                 printk("%s: ret: %i\n", ndev->name, ret);
1994                 if (!ret) {
1995                         response_op = response->header->operation;
1996                         printk("%s: response_op: %i\n", ndev->name,
1997                                response_op);
1998                         islpci_mgt_release(response);
1999                 }
2000                 if (ret || response_op == PIMFOR_OP_ERROR) {
2001                         printk("%s: EIO\n", ndev->name);
2002                         ret = -EIO;
2003                 }
2004         }
2005
2006         return (ret ? ret : -EINPROGRESS);
2007 }
2008
2009 static int
2010 prism54_set_spy(struct net_device *ndev,
2011                 struct iw_request_info *info,
2012                 union iwreq_data *uwrq, char *extra)
2013 {
2014         islpci_private *priv = netdev_priv(ndev);
2015         u32 u, oid = OID_INL_CONFIG;
2016
2017         down_write(&priv->mib_sem);
2018         mgt_get(priv, OID_INL_CONFIG, &u);
2019
2020         if ((uwrq->data.length == 0) && (priv->spy_data.spy_number > 0))
2021                 /* disable spy */
2022                 u &= ~INL_CONFIG_RXANNEX;
2023         else if ((uwrq->data.length > 0) && (priv->spy_data.spy_number == 0))
2024                 /* enable spy */
2025                 u |= INL_CONFIG_RXANNEX;
2026
2027         mgt_set(priv, OID_INL_CONFIG, &u);
2028         mgt_commit_list(priv, &oid, 1);
2029         up_write(&priv->mib_sem);
2030
2031         return iw_handler_set_spy(ndev, info, uwrq, extra);
2032 }
2033
2034 static const iw_handler prism54_handler[] = {
2035         (iw_handler) prism54_commit,    /* SIOCSIWCOMMIT */
2036         (iw_handler) prism54_get_name,  /* SIOCGIWNAME */
2037         (iw_handler) NULL,      /* SIOCSIWNWID */
2038         (iw_handler) NULL,      /* SIOCGIWNWID */
2039         (iw_handler) prism54_set_freq,  /* SIOCSIWFREQ */
2040         (iw_handler) prism54_get_freq,  /* SIOCGIWFREQ */
2041         (iw_handler) prism54_set_mode,  /* SIOCSIWMODE */
2042         (iw_handler) prism54_get_mode,  /* SIOCGIWMODE */
2043         (iw_handler) prism54_set_sens,  /* SIOCSIWSENS */
2044         (iw_handler) prism54_get_sens,  /* SIOCGIWSENS */
2045         (iw_handler) NULL,      /* SIOCSIWRANGE */
2046         (iw_handler) prism54_get_range, /* SIOCGIWRANGE */
2047         (iw_handler) NULL,      /* SIOCSIWPRIV */
2048         (iw_handler) NULL,      /* SIOCGIWPRIV */
2049         (iw_handler) NULL,      /* SIOCSIWSTATS */
2050         (iw_handler) NULL,      /* SIOCGIWSTATS */
2051         prism54_set_spy,        /* SIOCSIWSPY */
2052         iw_handler_get_spy,     /* SIOCGIWSPY */
2053         iw_handler_set_thrspy,  /* SIOCSIWTHRSPY */
2054         iw_handler_get_thrspy,  /* SIOCGIWTHRSPY */
2055         (iw_handler) prism54_set_wap,   /* SIOCSIWAP */
2056         (iw_handler) prism54_get_wap,   /* SIOCGIWAP */
2057         (iw_handler) NULL,      /* -- hole -- */
2058         (iw_handler) NULL,      /* SIOCGIWAPLIST depreciated */
2059         (iw_handler) prism54_set_scan,  /* SIOCSIWSCAN */
2060         (iw_handler) prism54_get_scan,  /* SIOCGIWSCAN */
2061         (iw_handler) prism54_set_essid, /* SIOCSIWESSID */
2062         (iw_handler) prism54_get_essid, /* SIOCGIWESSID */
2063         (iw_handler) prism54_set_nick,  /* SIOCSIWNICKN */
2064         (iw_handler) prism54_get_nick,  /* SIOCGIWNICKN */
2065         (iw_handler) NULL,      /* -- hole -- */
2066         (iw_handler) NULL,      /* -- hole -- */
2067         (iw_handler) prism54_set_rate,  /* SIOCSIWRATE */
2068         (iw_handler) prism54_get_rate,  /* SIOCGIWRATE */
2069         (iw_handler) prism54_set_rts,   /* SIOCSIWRTS */
2070         (iw_handler) prism54_get_rts,   /* SIOCGIWRTS */
2071         (iw_handler) prism54_set_frag,  /* SIOCSIWFRAG */
2072         (iw_handler) prism54_get_frag,  /* SIOCGIWFRAG */
2073         (iw_handler) prism54_set_txpower,       /* SIOCSIWTXPOW */
2074         (iw_handler) prism54_get_txpower,       /* SIOCGIWTXPOW */
2075         (iw_handler) prism54_set_retry, /* SIOCSIWRETRY */
2076         (iw_handler) prism54_get_retry, /* SIOCGIWRETRY */
2077         (iw_handler) prism54_set_encode,        /* SIOCSIWENCODE */
2078         (iw_handler) prism54_get_encode,        /* SIOCGIWENCODE */
2079         (iw_handler) NULL,      /* SIOCSIWPOWER */
2080         (iw_handler) NULL,      /* SIOCGIWPOWER */
2081 };
2082
2083 /* The low order bit identify a SET (0) or a GET (1) ioctl.  */
2084
2085 #define PRISM54_RESET           SIOCIWFIRSTPRIV
2086 #define PRISM54_GET_POLICY      SIOCIWFIRSTPRIV+1
2087 #define PRISM54_SET_POLICY      SIOCIWFIRSTPRIV+2
2088 #define PRISM54_GET_MAC         SIOCIWFIRSTPRIV+3
2089 #define PRISM54_ADD_MAC         SIOCIWFIRSTPRIV+4
2090
2091 #define PRISM54_DEL_MAC         SIOCIWFIRSTPRIV+6
2092
2093 #define PRISM54_KICK_MAC        SIOCIWFIRSTPRIV+8
2094
2095 #define PRISM54_KICK_ALL        SIOCIWFIRSTPRIV+10
2096
2097 #define PRISM54_GET_WPA         SIOCIWFIRSTPRIV+11
2098 #define PRISM54_SET_WPA         SIOCIWFIRSTPRIV+12
2099
2100 #define PRISM54_DBG_OID         SIOCIWFIRSTPRIV+14
2101 #define PRISM54_DBG_GET_OID     SIOCIWFIRSTPRIV+15
2102 #define PRISM54_DBG_SET_OID     SIOCIWFIRSTPRIV+16
2103
2104 #define PRISM54_GET_OID         SIOCIWFIRSTPRIV+17
2105 #define PRISM54_SET_OID_U32     SIOCIWFIRSTPRIV+18
2106 #define PRISM54_SET_OID_STR     SIOCIWFIRSTPRIV+20
2107 #define PRISM54_SET_OID_ADDR    SIOCIWFIRSTPRIV+22
2108
2109 #define PRISM54_GET_PRISMHDR    SIOCIWFIRSTPRIV+23
2110 #define PRISM54_SET_PRISMHDR    SIOCIWFIRSTPRIV+24
2111
2112 #define IWPRIV_SET_U32(n,x)     { n, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "s_"x }
2113 #define IWPRIV_SET_SSID(n,x)    { n, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 1, 0, "s_"x }
2114 #define IWPRIV_SET_ADDR(n,x)    { n, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "s_"x }
2115 #define IWPRIV_GET(n,x) { n, 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | PRIV_STR_SIZE, "g_"x }
2116
2117 #define IWPRIV_U32(n,x)         IWPRIV_SET_U32(n,x), IWPRIV_GET(n,x)
2118 #define IWPRIV_SSID(n,x)        IWPRIV_SET_SSID(n,x), IWPRIV_GET(n,x)
2119 #define IWPRIV_ADDR(n,x)        IWPRIV_SET_ADDR(n,x), IWPRIV_GET(n,x)
2120
2121 /* Note : limited to 128 private ioctls (wireless tools 26) */
2122
2123 static const struct iw_priv_args prism54_private_args[] = {
2124 /*{ cmd, set_args, get_args, name } */
2125         {PRISM54_RESET, 0, 0, "reset"},
2126         {PRISM54_GET_PRISMHDR, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2127          "get_prismhdr"},
2128         {PRISM54_SET_PRISMHDR, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0,
2129          "set_prismhdr"},
2130         {PRISM54_GET_POLICY, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2131          "getPolicy"},
2132         {PRISM54_SET_POLICY, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0,
2133          "setPolicy"},
2134         {PRISM54_GET_MAC, 0, IW_PRIV_TYPE_ADDR | 64, "getMac"},
2135         {PRISM54_ADD_MAC, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0,
2136          "addMac"},
2137         {PRISM54_DEL_MAC, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0,
2138          "delMac"},
2139         {PRISM54_KICK_MAC, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0,
2140          "kickMac"},
2141         {PRISM54_KICK_ALL, 0, 0, "kickAll"},
2142         {PRISM54_GET_WPA, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2143          "get_wpa"},
2144         {PRISM54_SET_WPA, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0,
2145          "set_wpa"},
2146         {PRISM54_DBG_OID, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0,
2147          "dbg_oid"},
2148         {PRISM54_DBG_GET_OID, 0, IW_PRIV_TYPE_BYTE | 256, "dbg_get_oid"},
2149         {PRISM54_DBG_SET_OID, IW_PRIV_TYPE_BYTE | 256, 0, "dbg_set_oid"},
2150         /* --- sub-ioctls handlers --- */
2151         {PRISM54_GET_OID,
2152          0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | PRIV_STR_SIZE, ""},
2153         {PRISM54_SET_OID_U32,
2154          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, ""},
2155         {PRISM54_SET_OID_STR,
2156          IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 1, 0, ""},
2157         {PRISM54_SET_OID_ADDR,
2158          IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, ""},
2159         /* --- sub-ioctls definitions --- */
2160         IWPRIV_ADDR(GEN_OID_MACADDRESS, "addr"),
2161         IWPRIV_GET(GEN_OID_LINKSTATE, "linkstate"),
2162         IWPRIV_U32(DOT11_OID_BSSTYPE, "bsstype"),
2163         IWPRIV_ADDR(DOT11_OID_BSSID, "bssid"),
2164         IWPRIV_U32(DOT11_OID_STATE, "state"),
2165         IWPRIV_U32(DOT11_OID_AID, "aid"),
2166
2167         IWPRIV_SSID(DOT11_OID_SSIDOVERRIDE, "ssidoverride"),
2168
2169         IWPRIV_U32(DOT11_OID_MEDIUMLIMIT, "medlimit"),
2170         IWPRIV_U32(DOT11_OID_BEACONPERIOD, "beacon"),
2171         IWPRIV_U32(DOT11_OID_DTIMPERIOD, "dtimperiod"),
2172
2173         IWPRIV_U32(DOT11_OID_AUTHENABLE, "authenable"),
2174         IWPRIV_U32(DOT11_OID_PRIVACYINVOKED, "privinvok"),
2175         IWPRIV_U32(DOT11_OID_EXUNENCRYPTED, "exunencrypt"),
2176
2177         IWPRIV_U32(DOT11_OID_REKEYTHRESHOLD, "rekeythresh"),
2178
2179         IWPRIV_U32(DOT11_OID_MAXTXLIFETIME, "maxtxlife"),
2180         IWPRIV_U32(DOT11_OID_MAXRXLIFETIME, "maxrxlife"),
2181         IWPRIV_U32(DOT11_OID_ALOFT_FIXEDRATE, "fixedrate"),
2182         IWPRIV_U32(DOT11_OID_MAXFRAMEBURST, "frameburst"),
2183         IWPRIV_U32(DOT11_OID_PSM, "psm"),
2184
2185         IWPRIV_U32(DOT11_OID_BRIDGELOCAL, "bridge"),
2186         IWPRIV_U32(DOT11_OID_CLIENTS, "clients"),
2187         IWPRIV_U32(DOT11_OID_CLIENTSASSOCIATED, "clientassoc"),
2188         IWPRIV_U32(DOT11_OID_DOT1XENABLE, "dot1xenable"),
2189         IWPRIV_U32(DOT11_OID_ANTENNARX, "rxant"),
2190         IWPRIV_U32(DOT11_OID_ANTENNATX, "txant"),
2191         IWPRIV_U32(DOT11_OID_ANTENNADIVERSITY, "antdivers"),
2192         IWPRIV_U32(DOT11_OID_EDTHRESHOLD, "edthresh"),
2193         IWPRIV_U32(DOT11_OID_PREAMBLESETTINGS, "preamble"),
2194         IWPRIV_GET(DOT11_OID_RATES, "rates"),
2195         IWPRIV_U32(DOT11_OID_OUTPUTPOWER, ".11outpower"),
2196         IWPRIV_GET(DOT11_OID_SUPPORTEDRATES, "supprates"),
2197         IWPRIV_GET(DOT11_OID_SUPPORTEDFREQUENCIES, "suppfreq"),
2198
2199         IWPRIV_U32(DOT11_OID_NOISEFLOOR, "noisefloor"),
2200         IWPRIV_GET(DOT11_OID_FREQUENCYACTIVITY, "freqactivity"),
2201         IWPRIV_U32(DOT11_OID_NONERPPROTECTION, "nonerpprotec"),
2202         IWPRIV_U32(DOT11_OID_PROFILES, "profile"),
2203         IWPRIV_GET(DOT11_OID_EXTENDEDRATES, "extrates"),
2204         IWPRIV_U32(DOT11_OID_MLMEAUTOLEVEL, "mlmelevel"),
2205
2206         IWPRIV_GET(DOT11_OID_BSSS, "bsss"),
2207         IWPRIV_GET(DOT11_OID_BSSLIST, "bsslist"),
2208         IWPRIV_U32(OID_INL_MODE, "mode"),
2209         IWPRIV_U32(OID_INL_CONFIG, "config"),
2210         IWPRIV_U32(OID_INL_DOT11D_CONFORMANCE, ".11dconform"),
2211         IWPRIV_GET(OID_INL_PHYCAPABILITIES, "phycapa"),
2212         IWPRIV_U32(OID_INL_OUTPUTPOWER, "outpower"),
2213 };
2214
2215 static const iw_handler prism54_private_handler[] = {
2216         (iw_handler) prism54_reset,
2217         (iw_handler) prism54_get_policy,
2218         (iw_handler) prism54_set_policy,
2219         (iw_handler) prism54_get_mac,
2220         (iw_handler) prism54_add_mac,
2221         (iw_handler) NULL,
2222         (iw_handler) prism54_del_mac,
2223         (iw_handler) NULL,
2224         (iw_handler) prism54_kick_mac,
2225         (iw_handler) NULL,
2226         (iw_handler) prism54_kick_all,
2227         (iw_handler) prism54_get_wpa,
2228         (iw_handler) prism54_set_wpa,
2229         (iw_handler) NULL,
2230         (iw_handler) prism54_debug_oid,
2231         (iw_handler) prism54_debug_get_oid,
2232         (iw_handler) prism54_debug_set_oid,
2233         (iw_handler) prism54_get_oid,
2234         (iw_handler) prism54_set_u32,
2235         (iw_handler) NULL,
2236         (iw_handler) prism54_set_raw,
2237         (iw_handler) NULL,
2238         (iw_handler) prism54_set_raw,
2239         (iw_handler) prism54_get_prismhdr,
2240         (iw_handler) prism54_set_prismhdr,
2241 };
2242
2243 const struct iw_handler_def prism54_handler_def = {
2244         .num_standard = sizeof (prism54_handler) / sizeof (iw_handler),
2245         .num_private = sizeof (prism54_private_handler) / sizeof (iw_handler),
2246         .num_private_args =
2247             sizeof (prism54_private_args) / sizeof (struct iw_priv_args),
2248         .standard = (iw_handler *) prism54_handler,
2249         .private = (iw_handler *) prism54_private_handler,
2250         .private_args = (struct iw_priv_args *) prism54_private_args,
2251         .spy_offset = offsetof(islpci_private, spy_data),
2252 };
2253
2254 /* For ioctls that don't work with the new API */
2255
2256 int
2257 prism54_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
2258 {
2259
2260         return -EOPNOTSUPP;
2261 }