Linux-2.6.12-rc2
[linux-2.6/next.git] / drivers / net / wireless / prism54 / isl_ioctl.c
blob0f29a9c7bc2cd6ded382198d06254f767f4e6e58
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>
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
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.
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
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>
29 #include <asm/uaccess.h>
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"
37 #include <net/iw_handler.h> /* New driver API */
40 static void prism54_wpa_ie_add(islpci_private *priv, u8 *bssid,
41 u8 *wpa_ie, size_t wpa_ie_len);
42 static size_t prism54_wpa_ie_get(islpci_private *priv, u8 *bssid, u8 *wpa_ie);
43 static int prism54_set_wpa(struct net_device *, struct iw_request_info *,
44 __u32 *, char *);
47 /**
48 * prism54_mib_mode_helper - MIB change mode helper function
49 * @mib: the &struct islpci_mib object to modify
50 * @iw_mode: new mode (%IW_MODE_*)
52 * This is a helper function, hence it does not lock. Make sure
53 * caller deals with locking *if* necessary. This function sets the
54 * mode-dependent mib values and does the mapping of the Linux
55 * Wireless API modes to Device firmware modes. It also checks for
56 * correct valid Linux wireless modes.
58 static int
59 prism54_mib_mode_helper(islpci_private *priv, u32 iw_mode)
61 u32 config = INL_CONFIG_MANUALRUN;
62 u32 mode, bsstype;
64 /* For now, just catch early the Repeater and Secondary modes here */
65 if (iw_mode == IW_MODE_REPEAT || iw_mode == IW_MODE_SECOND) {
66 printk(KERN_DEBUG
67 "%s(): Sorry, Repeater mode and Secondary mode "
68 "are not yet supported by this driver.\n", __FUNCTION__);
69 return -EINVAL;
72 priv->iw_mode = iw_mode;
74 switch (iw_mode) {
75 case IW_MODE_AUTO:
76 mode = INL_MODE_CLIENT;
77 bsstype = DOT11_BSSTYPE_ANY;
78 break;
79 case IW_MODE_ADHOC:
80 mode = INL_MODE_CLIENT;
81 bsstype = DOT11_BSSTYPE_IBSS;
82 break;
83 case IW_MODE_INFRA:
84 mode = INL_MODE_CLIENT;
85 bsstype = DOT11_BSSTYPE_INFRA;
86 break;
87 case IW_MODE_MASTER:
88 mode = INL_MODE_AP;
89 bsstype = DOT11_BSSTYPE_INFRA;
90 break;
91 case IW_MODE_MONITOR:
92 mode = INL_MODE_PROMISCUOUS;
93 bsstype = DOT11_BSSTYPE_ANY;
94 config |= INL_CONFIG_RXANNEX;
95 break;
96 default:
97 return -EINVAL;
100 if (init_wds)
101 config |= INL_CONFIG_WDS;
102 mgt_set(priv, DOT11_OID_BSSTYPE, &bsstype);
103 mgt_set(priv, OID_INL_CONFIG, &config);
104 mgt_set(priv, OID_INL_MODE, &mode);
106 return 0;
110 * prism54_mib_init - fill MIB cache with defaults
112 * this function initializes the struct given as @mib with defaults,
113 * of which many are retrieved from the global module parameter
114 * variables.
117 void
118 prism54_mib_init(islpci_private *priv)
120 u32 channel, authen, wep, filter, dot1x, mlme, conformance, power, mode;
121 struct obj_buffer psm_buffer = {
122 .size = PSM_BUFFER_SIZE,
123 .addr = priv->device_psm_buffer
126 channel = CARD_DEFAULT_CHANNEL;
127 authen = CARD_DEFAULT_AUTHEN;
128 wep = CARD_DEFAULT_WEP;
129 filter = CARD_DEFAULT_FILTER; /* (0) Do not filter un-encrypted data */
130 dot1x = CARD_DEFAULT_DOT1X;
131 mlme = CARD_DEFAULT_MLME_MODE;
132 conformance = CARD_DEFAULT_CONFORMANCE;
133 power = 127;
134 mode = CARD_DEFAULT_IW_MODE;
136 mgt_set(priv, DOT11_OID_CHANNEL, &channel);
137 mgt_set(priv, DOT11_OID_AUTHENABLE, &authen);
138 mgt_set(priv, DOT11_OID_PRIVACYINVOKED, &wep);
139 mgt_set(priv, DOT11_OID_PSMBUFFER, &psm_buffer);
140 mgt_set(priv, DOT11_OID_EXUNENCRYPTED, &filter);
141 mgt_set(priv, DOT11_OID_DOT1XENABLE, &dot1x);
142 mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &mlme);
143 mgt_set(priv, OID_INL_DOT11D_CONFORMANCE, &conformance);
144 mgt_set(priv, OID_INL_OUTPUTPOWER, &power);
146 /* This sets all of the mode-dependent values */
147 prism54_mib_mode_helper(priv, mode);
150 /* this will be executed outside of atomic context thanks to
151 * schedule_work(), thus we can as well use sleeping semaphore
152 * locking */
153 void
154 prism54_update_stats(islpci_private *priv)
156 char *data;
157 int j;
158 struct obj_bss bss, *bss2;
159 union oid_res_t r;
161 if (down_interruptible(&priv->stats_sem))
162 return;
164 /* Noise floor.
165 * I'm not sure if the unit is dBm.
166 * Note : If we are not connected, this value seems to be irrelevant. */
168 mgt_get_request(priv, DOT11_OID_NOISEFLOOR, 0, NULL, &r);
169 priv->local_iwstatistics.qual.noise = r.u;
171 /* Get the rssi of the link. To do this we need to retrieve a bss. */
173 /* First get the MAC address of the AP we are associated with. */
174 mgt_get_request(priv, DOT11_OID_BSSID, 0, NULL, &r);
175 data = r.ptr;
177 /* copy this MAC to the bss */
178 memcpy(bss.address, data, 6);
179 kfree(data);
181 /* now ask for the corresponding bss */
182 j = mgt_get_request(priv, DOT11_OID_BSSFIND, 0, (void *) &bss, &r);
183 bss2 = r.ptr;
184 /* report the rssi and use it to calculate
185 * link quality through a signal-noise
186 * ratio */
187 priv->local_iwstatistics.qual.level = bss2->rssi;
188 priv->local_iwstatistics.qual.qual =
189 bss2->rssi - priv->iwstatistics.qual.noise;
191 kfree(bss2);
193 /* report that the stats are new */
194 priv->local_iwstatistics.qual.updated = 0x7;
196 /* Rx : unable to decrypt the MPDU */
197 mgt_get_request(priv, DOT11_OID_PRIVRXFAILED, 0, NULL, &r);
198 priv->local_iwstatistics.discard.code = r.u;
200 /* Tx : Max MAC retries num reached */
201 mgt_get_request(priv, DOT11_OID_MPDUTXFAILED, 0, NULL, &r);
202 priv->local_iwstatistics.discard.retries = r.u;
204 up(&priv->stats_sem);
206 return;
209 struct iw_statistics *
210 prism54_get_wireless_stats(struct net_device *ndev)
212 islpci_private *priv = netdev_priv(ndev);
214 /* If the stats are being updated return old data */
215 if (down_trylock(&priv->stats_sem) == 0) {
216 memcpy(&priv->iwstatistics, &priv->local_iwstatistics,
217 sizeof (struct iw_statistics));
218 /* They won't be marked updated for the next time */
219 priv->local_iwstatistics.qual.updated = 0;
220 up(&priv->stats_sem);
221 } else
222 priv->iwstatistics.qual.updated = 0;
224 /* Update our wireless stats, but do not schedule to often
225 * (max 1 HZ) */
226 if ((priv->stats_timestamp == 0) ||
227 time_after(jiffies, priv->stats_timestamp + 1 * HZ)) {
228 schedule_work(&priv->stats_work);
229 priv->stats_timestamp = jiffies;
232 return &priv->iwstatistics;
235 static int
236 prism54_commit(struct net_device *ndev, struct iw_request_info *info,
237 char *cwrq, char *extra)
239 islpci_private *priv = netdev_priv(ndev);
241 /* simply re-set the last set SSID, this should commit most stuff */
243 /* Commit in Monitor mode is not necessary, also setting essid
244 * in Monitor mode does not make sense and isn't allowed for this
245 * device's firmware */
246 if (priv->iw_mode != IW_MODE_MONITOR)
247 return mgt_set_request(priv, DOT11_OID_SSID, 0, NULL);
248 return 0;
251 static int
252 prism54_get_name(struct net_device *ndev, struct iw_request_info *info,
253 char *cwrq, char *extra)
255 islpci_private *priv = netdev_priv(ndev);
256 char *capabilities;
257 union oid_res_t r;
258 int rvalue;
260 if (islpci_get_state(priv) < PRV_STATE_INIT) {
261 strncpy(cwrq, "NOT READY!", IFNAMSIZ);
262 return 0;
264 rvalue = mgt_get_request(priv, OID_INL_PHYCAPABILITIES, 0, NULL, &r);
266 switch (r.u) {
267 case INL_PHYCAP_5000MHZ:
268 capabilities = "IEEE 802.11a/b/g";
269 break;
270 case INL_PHYCAP_FAA:
271 capabilities = "IEEE 802.11b/g - FAA Support";
272 break;
273 case INL_PHYCAP_2400MHZ:
274 default:
275 capabilities = "IEEE 802.11b/g"; /* Default */
276 break;
278 strncpy(cwrq, capabilities, IFNAMSIZ);
279 return rvalue;
282 static int
283 prism54_set_freq(struct net_device *ndev, struct iw_request_info *info,
284 struct iw_freq *fwrq, char *extra)
286 islpci_private *priv = netdev_priv(ndev);
287 int rvalue;
288 u32 c;
290 if (fwrq->m < 1000)
291 /* we have a channel number */
292 c = fwrq->m;
293 else
294 c = (fwrq->e == 1) ? channel_of_freq(fwrq->m / 100000) : 0;
296 rvalue = c ? mgt_set_request(priv, DOT11_OID_CHANNEL, 0, &c) : -EINVAL;
298 /* Call commit handler */
299 return (rvalue ? rvalue : -EINPROGRESS);
302 static int
303 prism54_get_freq(struct net_device *ndev, struct iw_request_info *info,
304 struct iw_freq *fwrq, char *extra)
306 islpci_private *priv = netdev_priv(ndev);
307 union oid_res_t r;
308 int rvalue;
310 rvalue = mgt_get_request(priv, DOT11_OID_CHANNEL, 0, NULL, &r);
311 fwrq->i = r.u;
312 rvalue |= mgt_get_request(priv, DOT11_OID_FREQUENCY, 0, NULL, &r);
313 fwrq->m = r.u;
314 fwrq->e = 3;
316 return rvalue;
319 static int
320 prism54_set_mode(struct net_device *ndev, struct iw_request_info *info,
321 __u32 * uwrq, char *extra)
323 islpci_private *priv = netdev_priv(ndev);
324 u32 mlmeautolevel = CARD_DEFAULT_MLME_MODE;
326 /* Let's see if the user passed a valid Linux Wireless mode */
327 if (*uwrq > IW_MODE_MONITOR || *uwrq < IW_MODE_AUTO) {
328 printk(KERN_DEBUG
329 "%s: %s() You passed a non-valid init_mode.\n",
330 priv->ndev->name, __FUNCTION__);
331 return -EINVAL;
334 down_write(&priv->mib_sem);
336 if (prism54_mib_mode_helper(priv, *uwrq)) {
337 up_write(&priv->mib_sem);
338 return -EOPNOTSUPP;
341 /* the ACL code needs an intermediate mlmeautolevel. The wpa stuff an
342 * extended one.
344 if ((*uwrq == IW_MODE_MASTER) && (priv->acl.policy != MAC_POLICY_OPEN))
345 mlmeautolevel = DOT11_MLME_INTERMEDIATE;
346 if (priv->wpa)
347 mlmeautolevel = DOT11_MLME_EXTENDED;
349 mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &mlmeautolevel);
351 if (mgt_commit(priv)) {
352 up_write(&priv->mib_sem);
353 return -EIO;
355 priv->ndev->type = (priv->iw_mode == IW_MODE_MONITOR)
356 ? priv->monitor_type : ARPHRD_ETHER;
357 up_write(&priv->mib_sem);
359 return 0;
362 /* Use mib cache */
363 static int
364 prism54_get_mode(struct net_device *ndev, struct iw_request_info *info,
365 __u32 * uwrq, char *extra)
367 islpci_private *priv = netdev_priv(ndev);
369 BUG_ON((priv->iw_mode < IW_MODE_AUTO) || (priv->iw_mode >
370 IW_MODE_MONITOR));
371 *uwrq = priv->iw_mode;
373 return 0;
376 /* we use DOT11_OID_EDTHRESHOLD. From what I guess the card will not try to
377 * emit data if (sensitivity > rssi - noise) (in dBm).
378 * prism54_set_sens does not seem to work.
381 static int
382 prism54_set_sens(struct net_device *ndev, struct iw_request_info *info,
383 struct iw_param *vwrq, char *extra)
385 islpci_private *priv = netdev_priv(ndev);
386 u32 sens;
388 /* by default the card sets this to 20. */
389 sens = vwrq->disabled ? 20 : vwrq->value;
391 return mgt_set_request(priv, DOT11_OID_EDTHRESHOLD, 0, &sens);
394 static int
395 prism54_get_sens(struct net_device *ndev, struct iw_request_info *info,
396 struct iw_param *vwrq, char *extra)
398 islpci_private *priv = netdev_priv(ndev);
399 union oid_res_t r;
400 int rvalue;
402 rvalue = mgt_get_request(priv, DOT11_OID_EDTHRESHOLD, 0, NULL, &r);
404 vwrq->value = r.u;
405 vwrq->disabled = (vwrq->value == 0);
406 vwrq->fixed = 1;
408 return rvalue;
411 static int
412 prism54_get_range(struct net_device *ndev, struct iw_request_info *info,
413 struct iw_point *dwrq, char *extra)
415 struct iw_range *range = (struct iw_range *) extra;
416 islpci_private *priv = netdev_priv(ndev);
417 u8 *data;
418 int i, m, rvalue;
419 struct obj_frequencies *freq;
420 union oid_res_t r;
422 memset(range, 0, sizeof (struct iw_range));
423 dwrq->length = sizeof (struct iw_range);
425 /* set the wireless extension version number */
426 range->we_version_source = SUPPORTED_WIRELESS_EXT;
427 range->we_version_compiled = WIRELESS_EXT;
429 /* Now the encoding capabilities */
430 range->num_encoding_sizes = 3;
431 /* 64(40) bits WEP */
432 range->encoding_size[0] = 5;
433 /* 128(104) bits WEP */
434 range->encoding_size[1] = 13;
435 /* 256 bits for WPA-PSK */
436 range->encoding_size[2] = 32;
437 /* 4 keys are allowed */
438 range->max_encoding_tokens = 4;
440 /* we don't know the quality range... */
441 range->max_qual.level = 0;
442 range->max_qual.noise = 0;
443 range->max_qual.qual = 0;
444 /* these value describe an average quality. Needs more tweaking... */
445 range->avg_qual.level = -80; /* -80 dBm */
446 range->avg_qual.noise = 0; /* don't know what to put here */
447 range->avg_qual.qual = 0;
449 range->sensitivity = 200;
451 /* retry limit capabilities */
452 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
453 range->retry_flags = IW_RETRY_LIMIT;
454 range->r_time_flags = IW_RETRY_LIFETIME;
456 /* I don't know the range. Put stupid things here */
457 range->min_retry = 1;
458 range->max_retry = 65535;
459 range->min_r_time = 1024;
460 range->max_r_time = 65535 * 1024;
462 /* txpower is supported in dBm's */
463 range->txpower_capa = IW_TXPOW_DBM;
465 #if WIRELESS_EXT > 16
466 /* Event capability (kernel + driver) */
467 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
468 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
469 IW_EVENT_CAPA_MASK(SIOCGIWAP));
470 range->event_capa[1] = IW_EVENT_CAPA_K_1;
471 range->event_capa[4] = IW_EVENT_CAPA_MASK(IWEVCUSTOM);
472 #endif /* WIRELESS_EXT > 16 */
474 if (islpci_get_state(priv) < PRV_STATE_INIT)
475 return 0;
477 /* Request the device for the supported frequencies
478 * not really relevant since some devices will report the 5 GHz band
479 * frequencies even if they don't support them.
481 rvalue =
482 mgt_get_request(priv, DOT11_OID_SUPPORTEDFREQUENCIES, 0, NULL, &r);
483 freq = r.ptr;
485 range->num_channels = freq->nr;
486 range->num_frequency = freq->nr;
488 m = min(IW_MAX_FREQUENCIES, (int) freq->nr);
489 for (i = 0; i < m; i++) {
490 range->freq[i].m = freq->mhz[i];
491 range->freq[i].e = 6;
492 range->freq[i].i = channel_of_freq(freq->mhz[i]);
494 kfree(freq);
496 rvalue |= mgt_get_request(priv, DOT11_OID_SUPPORTEDRATES, 0, NULL, &r);
497 data = r.ptr;
499 /* We got an array of char. It is NULL terminated. */
500 i = 0;
501 while ((i < IW_MAX_BITRATES) && (*data != 0)) {
502 /* the result must be in bps. The card gives us 500Kbps */
503 range->bitrate[i] = *data * 500000;
504 i++;
505 data++;
507 range->num_bitrates = i;
508 kfree(r.ptr);
510 return rvalue;
513 /* Set AP address*/
515 static int
516 prism54_set_wap(struct net_device *ndev, struct iw_request_info *info,
517 struct sockaddr *awrq, char *extra)
519 islpci_private *priv = netdev_priv(ndev);
520 char bssid[6];
521 int rvalue;
523 if (awrq->sa_family != ARPHRD_ETHER)
524 return -EINVAL;
526 /* prepare the structure for the set object */
527 memcpy(&bssid[0], awrq->sa_data, 6);
529 /* set the bssid -- does this make sense when in AP mode? */
530 rvalue = mgt_set_request(priv, DOT11_OID_BSSID, 0, &bssid);
532 return (rvalue ? rvalue : -EINPROGRESS); /* Call commit handler */
535 /* get AP address*/
537 static int
538 prism54_get_wap(struct net_device *ndev, struct iw_request_info *info,
539 struct sockaddr *awrq, char *extra)
541 islpci_private *priv = netdev_priv(ndev);
542 union oid_res_t r;
543 int rvalue;
545 rvalue = mgt_get_request(priv, DOT11_OID_BSSID, 0, NULL, &r);
546 memcpy(awrq->sa_data, r.ptr, 6);
547 awrq->sa_family = ARPHRD_ETHER;
548 kfree(r.ptr);
550 return rvalue;
553 static int
554 prism54_set_scan(struct net_device *dev, struct iw_request_info *info,
555 struct iw_param *vwrq, char *extra)
557 /* hehe the device does this automagicaly */
558 return 0;
561 /* a little helper that will translate our data into a card independent
562 * format that the Wireless Tools will understand. This was inspired by
563 * the "Aironet driver for 4500 and 4800 series cards" (GPL)
566 static char *
567 prism54_translate_bss(struct net_device *ndev, char *current_ev,
568 char *end_buf, struct obj_bss *bss, char noise)
570 struct iw_event iwe; /* Temporary buffer */
571 short cap;
572 islpci_private *priv = netdev_priv(ndev);
574 /* The first entry must be the MAC address */
575 memcpy(iwe.u.ap_addr.sa_data, bss->address, 6);
576 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
577 iwe.cmd = SIOCGIWAP;
578 current_ev =
579 iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
581 /* The following entries will be displayed in the same order we give them */
583 /* The ESSID. */
584 iwe.u.data.length = bss->ssid.length;
585 iwe.u.data.flags = 1;
586 iwe.cmd = SIOCGIWESSID;
587 current_ev = iwe_stream_add_point(current_ev, end_buf,
588 &iwe, bss->ssid.octets);
590 /* Capabilities */
591 #define CAP_ESS 0x01
592 #define CAP_IBSS 0x02
593 #define CAP_CRYPT 0x10
595 /* Mode */
596 cap = bss->capinfo;
597 iwe.u.mode = 0;
598 if (cap & CAP_ESS)
599 iwe.u.mode = IW_MODE_MASTER;
600 else if (cap & CAP_IBSS)
601 iwe.u.mode = IW_MODE_ADHOC;
602 iwe.cmd = SIOCGIWMODE;
603 if (iwe.u.mode)
604 current_ev =
605 iwe_stream_add_event(current_ev, end_buf, &iwe,
606 IW_EV_UINT_LEN);
608 /* Encryption capability */
609 if (cap & CAP_CRYPT)
610 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
611 else
612 iwe.u.data.flags = IW_ENCODE_DISABLED;
613 iwe.u.data.length = 0;
614 iwe.cmd = SIOCGIWENCODE;
615 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, NULL);
617 /* Add frequency. (short) bss->channel is the frequency in MHz */
618 iwe.u.freq.m = bss->channel;
619 iwe.u.freq.e = 6;
620 iwe.cmd = SIOCGIWFREQ;
621 current_ev =
622 iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
624 /* Add quality statistics */
625 iwe.u.qual.level = bss->rssi;
626 iwe.u.qual.noise = noise;
627 /* do a simple SNR for quality */
628 iwe.u.qual.qual = bss->rssi - noise;
629 iwe.cmd = IWEVQUAL;
630 current_ev =
631 iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
633 if (priv->wpa) {
634 u8 wpa_ie[MAX_WPA_IE_LEN];
635 char *buf, *p;
636 size_t wpa_ie_len;
637 int i;
639 wpa_ie_len = prism54_wpa_ie_get(priv, bss->address, wpa_ie);
640 if (wpa_ie_len > 0 &&
641 (buf = kmalloc(wpa_ie_len * 2 + 10, GFP_ATOMIC))) {
642 p = buf;
643 p += sprintf(p, "wpa_ie=");
644 for (i = 0; i < wpa_ie_len; i++) {
645 p += sprintf(p, "%02x", wpa_ie[i]);
647 memset(&iwe, 0, sizeof (iwe));
648 iwe.cmd = IWEVCUSTOM;
649 iwe.u.data.length = strlen(buf);
650 current_ev = iwe_stream_add_point(current_ev, end_buf,
651 &iwe, buf);
652 kfree(buf);
655 return current_ev;
658 static int
659 prism54_get_scan(struct net_device *ndev, struct iw_request_info *info,
660 struct iw_point *dwrq, char *extra)
662 islpci_private *priv = netdev_priv(ndev);
663 int i, rvalue;
664 struct obj_bsslist *bsslist;
665 u32 noise = 0;
666 char *current_ev = extra;
667 union oid_res_t r;
669 if (islpci_get_state(priv) < PRV_STATE_INIT) {
670 /* device is not ready, fail gently */
671 dwrq->length = 0;
672 return 0;
675 /* first get the noise value. We will use it to report the link quality */
676 rvalue = mgt_get_request(priv, DOT11_OID_NOISEFLOOR, 0, NULL, &r);
677 noise = r.u;
679 /* Ask the device for a list of known bss.
680 * The old API, using SIOCGIWAPLIST, had a hard limit of IW_MAX_AP=64.
681 * The new API, using SIOCGIWSCAN, is only limited by the buffer size.
682 * WE-14->WE-16, the buffer is limited to IW_SCAN_MAX_DATA bytes.
683 * Starting with WE-17, the buffer can be as big as needed.
684 * But the device won't repport anything if you change the value
685 * of IWMAX_BSS=24. */
687 rvalue |= mgt_get_request(priv, DOT11_OID_BSSLIST, 0, NULL, &r);
688 bsslist = r.ptr;
690 /* ok now, scan the list and translate its info */
691 for (i = 0; i < (int) bsslist->nr; i++) {
692 current_ev = prism54_translate_bss(ndev, current_ev,
693 extra + dwrq->length,
694 &(bsslist->bsslist[i]),
695 noise);
696 #if WIRELESS_EXT > 16
697 /* Check if there is space for one more entry */
698 if((extra + dwrq->length - current_ev) <= IW_EV_ADDR_LEN) {
699 /* Ask user space to try again with a bigger buffer */
700 rvalue = -E2BIG;
701 break;
703 #endif /* WIRELESS_EXT > 16 */
706 kfree(bsslist);
707 dwrq->length = (current_ev - extra);
708 dwrq->flags = 0; /* todo */
710 return rvalue;
713 static int
714 prism54_set_essid(struct net_device *ndev, struct iw_request_info *info,
715 struct iw_point *dwrq, char *extra)
717 islpci_private *priv = netdev_priv(ndev);
718 struct obj_ssid essid;
720 memset(essid.octets, 0, 33);
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;
731 if (priv->iw_mode != IW_MODE_MONITOR)
732 return mgt_set_request(priv, DOT11_OID_SSID, 0, &essid);
734 /* If in monitor mode, just save to mib */
735 mgt_set(priv, DOT11_OID_SSID, &essid);
736 return 0;
740 static int
741 prism54_get_essid(struct net_device *ndev, struct iw_request_info *info,
742 struct iw_point *dwrq, char *extra)
744 islpci_private *priv = netdev_priv(ndev);
745 struct obj_ssid *essid;
746 union oid_res_t r;
747 int rvalue;
749 rvalue = mgt_get_request(priv, DOT11_OID_SSID, 0, NULL, &r);
750 essid = r.ptr;
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;
760 essid->octets[essid->length] = '\0';
761 memcpy(extra, essid->octets, dwrq->length);
762 kfree(essid);
764 return rvalue;
767 /* Provides no functionality, just completes the ioctl. In essence this is a
768 * just a cosmetic ioctl.
770 static int
771 prism54_set_nick(struct net_device *ndev, struct iw_request_info *info,
772 struct iw_point *dwrq, char *extra)
774 islpci_private *priv = netdev_priv(ndev);
776 if (dwrq->length > IW_ESSID_MAX_SIZE)
777 return -E2BIG;
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);
784 return 0;
787 static int
788 prism54_get_nick(struct net_device *ndev, struct iw_request_info *info,
789 struct iw_point *dwrq, char *extra)
791 islpci_private *priv = netdev_priv(ndev);
793 dwrq->length = 0;
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);
800 return 0;
803 /* Set the allowed Bitrates */
805 static int
806 prism54_set_rate(struct net_device *ndev,
807 struct iw_request_info *info,
808 struct iw_param *vwrq, char *extra)
811 islpci_private *priv = netdev_priv(ndev);
812 u32 rate, profile;
813 char *data;
814 int ret, i;
815 union oid_res_t r;
817 if (vwrq->value == -1) {
818 /* auto mode. No limit. */
819 profile = 1;
820 return mgt_set_request(priv, DOT11_OID_PROFILES, 0, &profile);
823 ret = mgt_get_request(priv, DOT11_OID_SUPPORTEDRATES, 0, NULL, &r);
824 if (ret) {
825 kfree(r.ptr);
826 return ret;
829 rate = (u32) (vwrq->value / 500000);
830 data = r.ptr;
831 i = 0;
833 while (data[i]) {
834 if (rate && (data[i] == rate)) {
835 break;
837 if (vwrq->value == i) {
838 break;
840 data[i] |= 0x80;
841 i++;
844 if (!data[i]) {
845 kfree(r.ptr);
846 return -EINVAL;
849 data[i] |= 0x80;
850 data[i + 1] = 0;
852 /* Now, check if we want a fixed or auto value */
853 if (vwrq->fixed) {
854 data[0] = data[i];
855 data[1] = 0;
859 i = 0;
860 printk("prism54 rate: ");
861 while(data[i]) {
862 printk("%u ", data[i]);
863 i++;
865 printk("0\n");
867 profile = -1;
868 ret = mgt_set_request(priv, DOT11_OID_PROFILES, 0, &profile);
869 ret |= mgt_set_request(priv, DOT11_OID_EXTENDEDRATES, 0, data);
870 ret |= mgt_set_request(priv, DOT11_OID_RATES, 0, data);
872 kfree(r.ptr);
874 return ret;
877 /* Get the current bit rate */
878 static int
879 prism54_get_rate(struct net_device *ndev,
880 struct iw_request_info *info,
881 struct iw_param *vwrq, char *extra)
883 islpci_private *priv = netdev_priv(ndev);
884 int rvalue;
885 char *data;
886 union oid_res_t r;
888 /* Get the current bit rate */
889 if ((rvalue = mgt_get_request(priv, GEN_OID_LINKSTATE, 0, NULL, &r)))
890 return rvalue;
891 vwrq->value = r.u * 500000;
893 /* request the device for the enabled rates */
894 rvalue = mgt_get_request(priv, DOT11_OID_RATES, 0, NULL, &r);
895 if (rvalue) {
896 kfree(r.ptr);
897 return rvalue;
899 data = r.ptr;
900 vwrq->fixed = (data[0] != 0) && (data[1] == 0);
901 kfree(r.ptr);
903 return 0;
906 static int
907 prism54_set_rts(struct net_device *ndev, struct iw_request_info *info,
908 struct iw_param *vwrq, char *extra)
910 islpci_private *priv = netdev_priv(ndev);
912 return mgt_set_request(priv, DOT11_OID_RTSTHRESH, 0, &vwrq->value);
915 static int
916 prism54_get_rts(struct net_device *ndev, struct iw_request_info *info,
917 struct iw_param *vwrq, char *extra)
919 islpci_private *priv = netdev_priv(ndev);
920 union oid_res_t r;
921 int rvalue;
923 /* get the rts threshold */
924 rvalue = mgt_get_request(priv, DOT11_OID_RTSTHRESH, 0, NULL, &r);
925 vwrq->value = r.u;
927 return rvalue;
930 static int
931 prism54_set_frag(struct net_device *ndev, struct iw_request_info *info,
932 struct iw_param *vwrq, char *extra)
934 islpci_private *priv = netdev_priv(ndev);
936 return mgt_set_request(priv, DOT11_OID_FRAGTHRESH, 0, &vwrq->value);
939 static int
940 prism54_get_frag(struct net_device *ndev, struct iw_request_info *info,
941 struct iw_param *vwrq, char *extra)
943 islpci_private *priv = netdev_priv(ndev);
944 union oid_res_t r;
945 int rvalue;
947 rvalue = mgt_get_request(priv, DOT11_OID_FRAGTHRESH, 0, NULL, &r);
948 vwrq->value = r.u;
950 return rvalue;
953 /* Here we have (min,max) = max retries for (small frames, big frames). Where
954 * big frame <=> bigger than the rts threshold
955 * small frame <=> smaller than the rts threshold
956 * This is not really the behavior expected by the wireless tool but it seems
957 * to be a common behavior in other drivers.
960 static int
961 prism54_set_retry(struct net_device *ndev, struct iw_request_info *info,
962 struct iw_param *vwrq, char *extra)
964 islpci_private *priv = netdev_priv(ndev);
965 u32 slimit = 0, llimit = 0; /* short and long limit */
966 u32 lifetime = 0;
967 int rvalue = 0;
969 if (vwrq->disabled)
970 /* we cannot disable this feature */
971 return -EINVAL;
973 if (vwrq->flags & IW_RETRY_LIMIT) {
974 if (vwrq->flags & IW_RETRY_MIN)
975 slimit = vwrq->value;
976 else if (vwrq->flags & IW_RETRY_MAX)
977 llimit = vwrq->value;
978 else {
979 /* we are asked to set both */
980 slimit = vwrq->value;
981 llimit = vwrq->value;
984 if (vwrq->flags & IW_RETRY_LIFETIME)
985 /* Wireless tools use us unit while the device uses 1024 us unit */
986 lifetime = vwrq->value / 1024;
988 /* now set what is requested */
989 if (slimit)
990 rvalue =
991 mgt_set_request(priv, DOT11_OID_SHORTRETRIES, 0, &slimit);
992 if (llimit)
993 rvalue |=
994 mgt_set_request(priv, DOT11_OID_LONGRETRIES, 0, &llimit);
995 if (lifetime)
996 rvalue |=
997 mgt_set_request(priv, DOT11_OID_MAXTXLIFETIME, 0,
998 &lifetime);
999 return rvalue;
1002 static int
1003 prism54_get_retry(struct net_device *ndev, struct iw_request_info *info,
1004 struct iw_param *vwrq, char *extra)
1006 islpci_private *priv = netdev_priv(ndev);
1007 union oid_res_t r;
1008 int rvalue = 0;
1009 vwrq->disabled = 0; /* It cannot be disabled */
1011 if ((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1012 /* we are asked for the life time */
1013 rvalue =
1014 mgt_get_request(priv, DOT11_OID_MAXTXLIFETIME, 0, NULL, &r);
1015 vwrq->value = r.u * 1024;
1016 vwrq->flags = IW_RETRY_LIFETIME;
1017 } else if ((vwrq->flags & IW_RETRY_MAX)) {
1018 /* we are asked for the long retry limit */
1019 rvalue |=
1020 mgt_get_request(priv, DOT11_OID_LONGRETRIES, 0, NULL, &r);
1021 vwrq->value = r.u;
1022 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
1023 } else {
1024 /* default. get the short retry limit */
1025 rvalue |=
1026 mgt_get_request(priv, DOT11_OID_SHORTRETRIES, 0, NULL, &r);
1027 vwrq->value = r.u;
1028 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
1031 return rvalue;
1034 static int
1035 prism54_set_encode(struct net_device *ndev, struct iw_request_info *info,
1036 struct iw_point *dwrq, char *extra)
1038 islpci_private *priv = netdev_priv(ndev);
1039 int rvalue = 0, force = 0;
1040 int authen = DOT11_AUTH_OS, invoke = 0, exunencrypt = 0;
1041 union oid_res_t r;
1043 /* with the new API, it's impossible to get a NULL pointer.
1044 * New version of iwconfig set the IW_ENCODE_NOKEY flag
1045 * when no key is given, but older versions don't. */
1047 if (dwrq->length > 0) {
1048 /* we have a key to set */
1049 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1050 int current_index;
1051 struct obj_key key = { DOT11_PRIV_WEP, 0, "" };
1053 /* get the current key index */
1054 rvalue = mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r);
1055 current_index = r.u;
1056 /* Verify that the key is not marked as invalid */
1057 if (!(dwrq->flags & IW_ENCODE_NOKEY)) {
1058 key.length = dwrq->length > sizeof (key.key) ?
1059 sizeof (key.key) : dwrq->length;
1060 memcpy(key.key, extra, key.length);
1061 if (key.length == 32)
1062 /* we want WPA-PSK */
1063 key.type = DOT11_PRIV_TKIP;
1064 if ((index < 0) || (index > 3))
1065 /* no index provided use the current one */
1066 index = current_index;
1068 /* now send the key to the card */
1069 rvalue |=
1070 mgt_set_request(priv, DOT11_OID_DEFKEYX, index,
1071 &key);
1074 * If a valid key is set, encryption should be enabled
1075 * (user may turn it off later).
1076 * This is also how "iwconfig ethX key on" works
1078 if ((index == current_index) && (key.length > 0))
1079 force = 1;
1080 } else {
1081 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1082 if ((index >= 0) && (index <= 3)) {
1083 /* we want to set the key index */
1084 rvalue |=
1085 mgt_set_request(priv, DOT11_OID_DEFKEYID, 0,
1086 &index);
1087 } else {
1088 if (!dwrq->flags & IW_ENCODE_MODE) {
1089 /* we cannot do anything. Complain. */
1090 return -EINVAL;
1094 /* now read the flags */
1095 if (dwrq->flags & IW_ENCODE_DISABLED) {
1096 /* Encoding disabled,
1097 * authen = DOT11_AUTH_OS;
1098 * invoke = 0;
1099 * exunencrypt = 0; */
1101 if (dwrq->flags & IW_ENCODE_OPEN)
1102 /* Encode but accept non-encoded packets. No auth */
1103 invoke = 1;
1104 if ((dwrq->flags & IW_ENCODE_RESTRICTED) || force) {
1105 /* Refuse non-encoded packets. Auth */
1106 authen = DOT11_AUTH_BOTH;
1107 invoke = 1;
1108 exunencrypt = 1;
1110 /* do the change if requested */
1111 if ((dwrq->flags & IW_ENCODE_MODE) || force) {
1112 rvalue |=
1113 mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0, &authen);
1114 rvalue |=
1115 mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0, &invoke);
1116 rvalue |=
1117 mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0,
1118 &exunencrypt);
1120 return rvalue;
1123 static int
1124 prism54_get_encode(struct net_device *ndev, struct iw_request_info *info,
1125 struct iw_point *dwrq, char *extra)
1127 islpci_private *priv = netdev_priv(ndev);
1128 struct obj_key *key;
1129 u32 devindex, index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1130 u32 authen = 0, invoke = 0, exunencrypt = 0;
1131 int rvalue;
1132 union oid_res_t r;
1134 /* first get the flags */
1135 rvalue = mgt_get_request(priv, DOT11_OID_AUTHENABLE, 0, NULL, &r);
1136 authen = r.u;
1137 rvalue |= mgt_get_request(priv, DOT11_OID_PRIVACYINVOKED, 0, NULL, &r);
1138 invoke = r.u;
1139 rvalue |= mgt_get_request(priv, DOT11_OID_EXUNENCRYPTED, 0, NULL, &r);
1140 exunencrypt = r.u;
1142 if (invoke && (authen == DOT11_AUTH_BOTH) && exunencrypt)
1143 dwrq->flags = IW_ENCODE_RESTRICTED;
1144 else if ((authen == DOT11_AUTH_OS) && !exunencrypt) {
1145 if (invoke)
1146 dwrq->flags = IW_ENCODE_OPEN;
1147 else
1148 dwrq->flags = IW_ENCODE_DISABLED;
1149 } else
1150 /* The card should not work in this state */
1151 dwrq->flags = 0;
1153 /* get the current device key index */
1154 rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r);
1155 devindex = r.u;
1156 /* Now get the key, return it */
1157 if ((index < 0) || (index > 3))
1158 /* no index provided, use the current one */
1159 index = devindex;
1160 rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYX, index, NULL, &r);
1161 key = r.ptr;
1162 dwrq->length = key->length;
1163 memcpy(extra, key->key, dwrq->length);
1164 kfree(key);
1165 /* return the used key index */
1166 dwrq->flags |= devindex + 1;
1168 return rvalue;
1171 static int
1172 prism54_get_txpower(struct net_device *ndev, struct iw_request_info *info,
1173 struct iw_param *vwrq, char *extra)
1175 islpci_private *priv = netdev_priv(ndev);
1176 union oid_res_t r;
1177 int rvalue;
1179 rvalue = mgt_get_request(priv, OID_INL_OUTPUTPOWER, 0, NULL, &r);
1180 /* intersil firmware operates in 0.25 dBm (1/4 dBm) */
1181 vwrq->value = (s32) r.u / 4;
1182 vwrq->fixed = 1;
1183 /* radio is not turned of
1184 * btw: how is possible to turn off only the radio
1186 vwrq->disabled = 0;
1188 return rvalue;
1191 static int
1192 prism54_set_txpower(struct net_device *ndev, struct iw_request_info *info,
1193 struct iw_param *vwrq, char *extra)
1195 islpci_private *priv = netdev_priv(ndev);
1196 s32 u = vwrq->value;
1198 /* intersil firmware operates in 0.25 dBm (1/4) */
1199 u *= 4;
1200 if (vwrq->disabled) {
1201 /* don't know how to disable radio */
1202 printk(KERN_DEBUG
1203 "%s: %s() disabling radio is not yet supported.\n",
1204 priv->ndev->name, __FUNCTION__);
1205 return -ENOTSUPP;
1206 } else if (vwrq->fixed)
1207 /* currently only fixed value is supported */
1208 return mgt_set_request(priv, OID_INL_OUTPUTPOWER, 0, &u);
1209 else {
1210 printk(KERN_DEBUG
1211 "%s: %s() auto power will be implemented later.\n",
1212 priv->ndev->name, __FUNCTION__);
1213 return -ENOTSUPP;
1217 static int
1218 prism54_reset(struct net_device *ndev, struct iw_request_info *info,
1219 __u32 * uwrq, char *extra)
1221 islpci_reset(netdev_priv(ndev), 0);
1223 return 0;
1226 static int
1227 prism54_get_oid(struct net_device *ndev, struct iw_request_info *info,
1228 struct iw_point *dwrq, char *extra)
1230 union oid_res_t r;
1231 int rvalue;
1232 enum oid_num_t n = dwrq->flags;
1234 rvalue = mgt_get_request((islpci_private *) ndev->priv, n, 0, NULL, &r);
1235 dwrq->length = mgt_response_to_str(n, &r, extra);
1236 if ((isl_oid[n].flags & OID_FLAG_TYPE) != OID_TYPE_U32)
1237 kfree(r.ptr);
1238 return rvalue;
1241 static int
1242 prism54_set_u32(struct net_device *ndev, struct iw_request_info *info,
1243 __u32 * uwrq, char *extra)
1245 u32 oid = uwrq[0], u = uwrq[1];
1247 return mgt_set_request((islpci_private *) ndev->priv, oid, 0, &u);
1250 static int
1251 prism54_set_raw(struct net_device *ndev, struct iw_request_info *info,
1252 struct iw_point *dwrq, char *extra)
1254 u32 oid = dwrq->flags;
1256 return mgt_set_request((islpci_private *) ndev->priv, oid, 0, extra);
1259 void
1260 prism54_acl_init(struct islpci_acl *acl)
1262 sema_init(&acl->sem, 1);
1263 INIT_LIST_HEAD(&acl->mac_list);
1264 acl->size = 0;
1265 acl->policy = MAC_POLICY_OPEN;
1268 static void
1269 prism54_clear_mac(struct islpci_acl *acl)
1271 struct list_head *ptr, *next;
1272 struct mac_entry *entry;
1274 if (down_interruptible(&acl->sem))
1275 return;
1277 if (acl->size == 0) {
1278 up(&acl->sem);
1279 return;
1282 for (ptr = acl->mac_list.next, next = ptr->next;
1283 ptr != &acl->mac_list; ptr = next, next = ptr->next) {
1284 entry = list_entry(ptr, struct mac_entry, _list);
1285 list_del(ptr);
1286 kfree(entry);
1288 acl->size = 0;
1289 up(&acl->sem);
1292 void
1293 prism54_acl_clean(struct islpci_acl *acl)
1295 prism54_clear_mac(acl);
1298 static int
1299 prism54_add_mac(struct net_device *ndev, struct iw_request_info *info,
1300 struct sockaddr *awrq, char *extra)
1302 islpci_private *priv = netdev_priv(ndev);
1303 struct islpci_acl *acl = &priv->acl;
1304 struct mac_entry *entry;
1305 struct sockaddr *addr = (struct sockaddr *) extra;
1307 if (addr->sa_family != ARPHRD_ETHER)
1308 return -EOPNOTSUPP;
1310 entry = kmalloc(sizeof (struct mac_entry), GFP_KERNEL);
1311 if (entry == NULL)
1312 return -ENOMEM;
1314 memcpy(entry->addr, addr->sa_data, ETH_ALEN);
1316 if (down_interruptible(&acl->sem)) {
1317 kfree(entry);
1318 return -ERESTARTSYS;
1320 list_add_tail(&entry->_list, &acl->mac_list);
1321 acl->size++;
1322 up(&acl->sem);
1324 return 0;
1327 static int
1328 prism54_del_mac(struct net_device *ndev, struct iw_request_info *info,
1329 struct sockaddr *awrq, char *extra)
1331 islpci_private *priv = netdev_priv(ndev);
1332 struct islpci_acl *acl = &priv->acl;
1333 struct mac_entry *entry;
1334 struct list_head *ptr;
1335 struct sockaddr *addr = (struct sockaddr *) extra;
1337 if (addr->sa_family != ARPHRD_ETHER)
1338 return -EOPNOTSUPP;
1340 if (down_interruptible(&acl->sem))
1341 return -ERESTARTSYS;
1342 for (ptr = acl->mac_list.next; ptr != &acl->mac_list; ptr = ptr->next) {
1343 entry = list_entry(ptr, struct mac_entry, _list);
1345 if (memcmp(entry->addr, addr->sa_data, ETH_ALEN) == 0) {
1346 list_del(ptr);
1347 acl->size--;
1348 kfree(entry);
1349 up(&acl->sem);
1350 return 0;
1353 up(&acl->sem);
1354 return -EINVAL;
1357 static int
1358 prism54_get_mac(struct net_device *ndev, struct iw_request_info *info,
1359 struct iw_point *dwrq, char *extra)
1361 islpci_private *priv = netdev_priv(ndev);
1362 struct islpci_acl *acl = &priv->acl;
1363 struct mac_entry *entry;
1364 struct list_head *ptr;
1365 struct sockaddr *dst = (struct sockaddr *) extra;
1367 dwrq->length = 0;
1369 if (down_interruptible(&acl->sem))
1370 return -ERESTARTSYS;
1372 for (ptr = acl->mac_list.next; ptr != &acl->mac_list; ptr = ptr->next) {
1373 entry = list_entry(ptr, struct mac_entry, _list);
1375 memcpy(dst->sa_data, entry->addr, ETH_ALEN);
1376 dst->sa_family = ARPHRD_ETHER;
1377 dwrq->length++;
1378 dst++;
1380 up(&acl->sem);
1381 return 0;
1384 /* Setting policy also clears the MAC acl, even if we don't change the defaut
1385 * policy
1388 static int
1389 prism54_set_policy(struct net_device *ndev, struct iw_request_info *info,
1390 __u32 * uwrq, char *extra)
1392 islpci_private *priv = netdev_priv(ndev);
1393 struct islpci_acl *acl = &priv->acl;
1394 u32 mlmeautolevel;
1396 prism54_clear_mac(acl);
1398 if ((*uwrq < MAC_POLICY_OPEN) || (*uwrq > MAC_POLICY_REJECT))
1399 return -EINVAL;
1401 down_write(&priv->mib_sem);
1403 acl->policy = *uwrq;
1405 /* the ACL code needs an intermediate mlmeautolevel */
1406 if ((priv->iw_mode == IW_MODE_MASTER) &&
1407 (acl->policy != MAC_POLICY_OPEN))
1408 mlmeautolevel = DOT11_MLME_INTERMEDIATE;
1409 else
1410 mlmeautolevel = CARD_DEFAULT_MLME_MODE;
1411 if (priv->wpa)
1412 mlmeautolevel = DOT11_MLME_EXTENDED;
1413 mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &mlmeautolevel);
1414 /* restart the card with our new policy */
1415 if (mgt_commit(priv)) {
1416 up_write(&priv->mib_sem);
1417 return -EIO;
1419 up_write(&priv->mib_sem);
1421 return 0;
1424 static int
1425 prism54_get_policy(struct net_device *ndev, struct iw_request_info *info,
1426 __u32 * uwrq, char *extra)
1428 islpci_private *priv = netdev_priv(ndev);
1429 struct islpci_acl *acl = &priv->acl;
1431 *uwrq = acl->policy;
1433 return 0;
1436 /* Return 1 only if client should be accepted. */
1438 static int
1439 prism54_mac_accept(struct islpci_acl *acl, char *mac)
1441 struct list_head *ptr;
1442 struct mac_entry *entry;
1443 int res = 0;
1445 if (down_interruptible(&acl->sem))
1446 return -ERESTARTSYS;
1448 if (acl->policy == MAC_POLICY_OPEN) {
1449 up(&acl->sem);
1450 return 1;
1453 for (ptr = acl->mac_list.next; ptr != &acl->mac_list; ptr = ptr->next) {
1454 entry = list_entry(ptr, struct mac_entry, _list);
1455 if (memcmp(entry->addr, mac, ETH_ALEN) == 0) {
1456 res = 1;
1457 break;
1460 res = (acl->policy == MAC_POLICY_ACCEPT) ? !res : res;
1461 up(&acl->sem);
1463 return res;
1466 static int
1467 prism54_kick_all(struct net_device *ndev, struct iw_request_info *info,
1468 struct iw_point *dwrq, char *extra)
1470 struct obj_mlme *mlme;
1471 int rvalue;
1473 mlme = kmalloc(sizeof (struct obj_mlme), GFP_KERNEL);
1474 if (mlme == NULL)
1475 return -ENOMEM;
1477 /* Tell the card to kick every client */
1478 mlme->id = 0;
1479 rvalue =
1480 mgt_set_request(netdev_priv(ndev), DOT11_OID_DISASSOCIATE, 0, mlme);
1481 kfree(mlme);
1483 return rvalue;
1486 static int
1487 prism54_kick_mac(struct net_device *ndev, struct iw_request_info *info,
1488 struct sockaddr *awrq, char *extra)
1490 struct obj_mlme *mlme;
1491 struct sockaddr *addr = (struct sockaddr *) extra;
1492 int rvalue;
1494 if (addr->sa_family != ARPHRD_ETHER)
1495 return -EOPNOTSUPP;
1497 mlme = kmalloc(sizeof (struct obj_mlme), GFP_KERNEL);
1498 if (mlme == NULL)
1499 return -ENOMEM;
1501 /* Tell the card to only kick the corresponding bastard */
1502 memcpy(mlme->address, addr->sa_data, ETH_ALEN);
1503 mlme->id = -1;
1504 rvalue =
1505 mgt_set_request(netdev_priv(ndev), DOT11_OID_DISASSOCIATE, 0, mlme);
1507 kfree(mlme);
1509 return rvalue;
1512 /* Translate a TRAP oid into a wireless event. Called in islpci_mgt_receive. */
1514 static void
1515 format_event(islpci_private *priv, char *dest, const char *str,
1516 const struct obj_mlme *mlme, u16 *length, int error)
1518 const u8 *a = mlme->address;
1519 int n = snprintf(dest, IW_CUSTOM_MAX,
1520 "%s %s %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X %s (%2.2X)",
1521 str,
1522 ((priv->iw_mode == IW_MODE_MASTER) ? "from" : "to"),
1523 a[0], a[1], a[2], a[3], a[4], a[5],
1524 (error ? (mlme->code ? " : REJECTED " : " : ACCEPTED ")
1525 : ""), mlme->code);
1526 BUG_ON(n > IW_CUSTOM_MAX);
1527 *length = n;
1530 static void
1531 send_formatted_event(islpci_private *priv, const char *str,
1532 const struct obj_mlme *mlme, int error)
1534 union iwreq_data wrqu;
1535 char *memptr;
1537 memptr = kmalloc(IW_CUSTOM_MAX, GFP_KERNEL);
1538 if (!memptr)
1539 return;
1540 wrqu.data.pointer = memptr;
1541 wrqu.data.length = 0;
1542 format_event(priv, memptr, str, mlme, &wrqu.data.length,
1543 error);
1544 wireless_send_event(priv->ndev, IWEVCUSTOM, &wrqu, memptr);
1545 kfree(memptr);
1548 static void
1549 send_simple_event(islpci_private *priv, const char *str)
1551 union iwreq_data wrqu;
1552 char *memptr;
1553 int n = strlen(str);
1555 memptr = kmalloc(IW_CUSTOM_MAX, GFP_KERNEL);
1556 if (!memptr)
1557 return;
1558 BUG_ON(n > IW_CUSTOM_MAX);
1559 wrqu.data.pointer = memptr;
1560 wrqu.data.length = n;
1561 strcpy(memptr, str);
1562 wireless_send_event(priv->ndev, IWEVCUSTOM, &wrqu, memptr);
1563 kfree(memptr);
1566 static void
1567 link_changed(struct net_device *ndev, u32 bitrate)
1569 islpci_private *priv = netdev_priv(ndev);
1571 if (bitrate) {
1572 if (priv->iw_mode == IW_MODE_INFRA) {
1573 union iwreq_data uwrq;
1574 prism54_get_wap(ndev, NULL, (struct sockaddr *) &uwrq,
1575 NULL);
1576 wireless_send_event(ndev, SIOCGIWAP, &uwrq, NULL);
1577 } else
1578 send_simple_event(netdev_priv(ndev),
1579 "Link established");
1580 } else
1581 send_simple_event(netdev_priv(ndev), "Link lost");
1584 /* Beacon/ProbeResp payload header */
1585 struct ieee80211_beacon_phdr {
1586 u8 timestamp[8];
1587 u16 beacon_int;
1588 u16 capab_info;
1589 } __attribute__ ((packed));
1591 #define WLAN_EID_GENERIC 0xdd
1592 static u8 wpa_oid[4] = { 0x00, 0x50, 0xf2, 1 };
1594 #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
1595 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
1597 static void
1598 prism54_wpa_ie_add(islpci_private *priv, u8 *bssid,
1599 u8 *wpa_ie, size_t wpa_ie_len)
1601 struct list_head *ptr;
1602 struct islpci_bss_wpa_ie *bss = NULL;
1604 if (wpa_ie_len > MAX_WPA_IE_LEN)
1605 wpa_ie_len = MAX_WPA_IE_LEN;
1607 if (down_interruptible(&priv->wpa_sem))
1608 return;
1610 /* try to use existing entry */
1611 list_for_each(ptr, &priv->bss_wpa_list) {
1612 bss = list_entry(ptr, struct islpci_bss_wpa_ie, list);
1613 if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0) {
1614 list_move(&bss->list, &priv->bss_wpa_list);
1615 break;
1617 bss = NULL;
1620 if (bss == NULL) {
1621 /* add a new BSS entry; if max number of entries is already
1622 * reached, replace the least recently updated */
1623 if (priv->num_bss_wpa >= MAX_BSS_WPA_IE_COUNT) {
1624 bss = list_entry(priv->bss_wpa_list.prev,
1625 struct islpci_bss_wpa_ie, list);
1626 list_del(&bss->list);
1627 } else {
1628 bss = kmalloc(sizeof (*bss), GFP_ATOMIC);
1629 if (bss != NULL) {
1630 priv->num_bss_wpa++;
1631 memset(bss, 0, sizeof (*bss));
1634 if (bss != NULL) {
1635 memcpy(bss->bssid, bssid, ETH_ALEN);
1636 list_add(&bss->list, &priv->bss_wpa_list);
1640 if (bss != NULL) {
1641 memcpy(bss->wpa_ie, wpa_ie, wpa_ie_len);
1642 bss->wpa_ie_len = wpa_ie_len;
1643 bss->last_update = jiffies;
1644 } else {
1645 printk(KERN_DEBUG "Failed to add BSS WPA entry for " MACSTR
1646 "\n", MAC2STR(bssid));
1649 /* expire old entries from WPA list */
1650 while (priv->num_bss_wpa > 0) {
1651 bss = list_entry(priv->bss_wpa_list.prev,
1652 struct islpci_bss_wpa_ie, list);
1653 if (!time_after(jiffies, bss->last_update + 60 * HZ))
1654 break;
1656 list_del(&bss->list);
1657 priv->num_bss_wpa--;
1658 kfree(bss);
1661 up(&priv->wpa_sem);
1664 static size_t
1665 prism54_wpa_ie_get(islpci_private *priv, u8 *bssid, u8 *wpa_ie)
1667 struct list_head *ptr;
1668 struct islpci_bss_wpa_ie *bss = NULL;
1669 size_t len = 0;
1671 if (down_interruptible(&priv->wpa_sem))
1672 return 0;
1674 list_for_each(ptr, &priv->bss_wpa_list) {
1675 bss = list_entry(ptr, struct islpci_bss_wpa_ie, list);
1676 if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0)
1677 break;
1678 bss = NULL;
1680 if (bss) {
1681 len = bss->wpa_ie_len;
1682 memcpy(wpa_ie, bss->wpa_ie, len);
1684 up(&priv->wpa_sem);
1686 return len;
1689 void
1690 prism54_wpa_ie_init(islpci_private *priv)
1692 INIT_LIST_HEAD(&priv->bss_wpa_list);
1693 sema_init(&priv->wpa_sem, 1);
1696 void
1697 prism54_wpa_ie_clean(islpci_private *priv)
1699 struct list_head *ptr, *n;
1701 list_for_each_safe(ptr, n, &priv->bss_wpa_list) {
1702 struct islpci_bss_wpa_ie *bss;
1703 bss = list_entry(ptr, struct islpci_bss_wpa_ie, list);
1704 kfree(bss);
1708 static void
1709 prism54_process_bss_data(islpci_private *priv, u32 oid, u8 *addr,
1710 u8 *payload, size_t len)
1712 struct ieee80211_beacon_phdr *hdr;
1713 u8 *pos, *end;
1715 if (!priv->wpa)
1716 return;
1718 hdr = (struct ieee80211_beacon_phdr *) payload;
1719 pos = (u8 *) (hdr + 1);
1720 end = payload + len;
1721 while (pos < end) {
1722 if (pos + 2 + pos[1] > end) {
1723 printk(KERN_DEBUG "Parsing Beacon/ProbeResp failed "
1724 "for " MACSTR "\n", MAC2STR(addr));
1725 return;
1727 if (pos[0] == WLAN_EID_GENERIC && pos[1] >= 4 &&
1728 memcmp(pos + 2, wpa_oid, 4) == 0) {
1729 prism54_wpa_ie_add(priv, addr, pos, pos[1] + 2);
1730 return;
1732 pos += 2 + pos[1];
1736 static void
1737 handle_request(islpci_private *priv, struct obj_mlme *mlme, enum oid_num_t oid)
1739 if (((mlme->state == DOT11_STATE_AUTHING) ||
1740 (mlme->state == DOT11_STATE_ASSOCING))
1741 && mgt_mlme_answer(priv)) {
1742 /* Someone is requesting auth and we must respond. Just send back
1743 * the trap with error code set accordingly.
1745 mlme->code = prism54_mac_accept(&priv->acl,
1746 mlme->address) ? 0 : 1;
1747 mgt_set_request(priv, oid, 0, mlme);
1751 static int
1752 prism54_process_trap_helper(islpci_private *priv, enum oid_num_t oid,
1753 char *data)
1755 struct obj_mlme *mlme = (struct obj_mlme *) data;
1756 struct obj_mlmeex *mlmeex = (struct obj_mlmeex *) data;
1757 struct obj_mlmeex *confirm;
1758 u8 wpa_ie[MAX_WPA_IE_LEN];
1759 int wpa_ie_len;
1760 size_t len = 0; /* u16, better? */
1761 u8 *payload = NULL, *pos = NULL;
1762 int ret;
1764 /* I think all trapable objects are listed here.
1765 * Some oids have a EX version. The difference is that they are emitted
1766 * in DOT11_MLME_EXTENDED mode (set with DOT11_OID_MLMEAUTOLEVEL)
1767 * with more info.
1768 * The few events already defined by the wireless tools are not really
1769 * suited. We use the more flexible custom event facility.
1772 if (oid >= DOT11_OID_BEACON) {
1773 len = mlmeex->size;
1774 payload = pos = mlmeex->data;
1777 /* I fear prism54_process_bss_data won't work with big endian data */
1778 if ((oid == DOT11_OID_BEACON) || (oid == DOT11_OID_PROBE))
1779 prism54_process_bss_data(priv, oid, mlmeex->address,
1780 payload, len);
1782 mgt_le_to_cpu(isl_oid[oid].flags & OID_FLAG_TYPE, (void *) mlme);
1784 switch (oid) {
1786 case GEN_OID_LINKSTATE:
1787 link_changed(priv->ndev, (u32) *data);
1788 break;
1790 case DOT11_OID_MICFAILURE:
1791 send_simple_event(priv, "Mic failure");
1792 break;
1794 case DOT11_OID_DEAUTHENTICATE:
1795 send_formatted_event(priv, "DeAuthenticate request", mlme, 0);
1796 break;
1798 case DOT11_OID_AUTHENTICATE:
1799 handle_request(priv, mlme, oid);
1800 send_formatted_event(priv, "Authenticate request", mlme, 1);
1801 break;
1803 case DOT11_OID_DISASSOCIATE:
1804 send_formatted_event(priv, "Disassociate request", mlme, 0);
1805 break;
1807 case DOT11_OID_ASSOCIATE:
1808 handle_request(priv, mlme, oid);
1809 send_formatted_event(priv, "Associate request", mlme, 1);
1810 break;
1812 case DOT11_OID_REASSOCIATE:
1813 handle_request(priv, mlme, oid);
1814 send_formatted_event(priv, "ReAssociate request", mlme, 1);
1815 break;
1817 case DOT11_OID_BEACON:
1818 send_formatted_event(priv,
1819 "Received a beacon from an unkown AP",
1820 mlme, 0);
1821 break;
1823 case DOT11_OID_PROBE:
1824 /* we received a probe from a client. */
1825 send_formatted_event(priv, "Received a probe from client", mlme,
1827 break;
1829 /* Note : "mlme" is actually a "struct obj_mlmeex *" here, but this
1830 * is backward compatible layout-wise with "struct obj_mlme".
1833 case DOT11_OID_DEAUTHENTICATEEX:
1834 send_formatted_event(priv, "DeAuthenticate request", mlme, 0);
1835 break;
1837 case DOT11_OID_AUTHENTICATEEX:
1838 handle_request(priv, mlme, oid);
1839 send_formatted_event(priv, "Authenticate request (ex)", mlme, 1);
1841 if (priv->iw_mode != IW_MODE_MASTER
1842 && mlmeex->state != DOT11_STATE_AUTHING)
1843 break;
1845 confirm = kmalloc(sizeof(struct obj_mlmeex) + 6, GFP_ATOMIC);
1847 if (!confirm)
1848 break;
1850 memcpy(&confirm->address, mlmeex->address, ETH_ALEN);
1851 printk(KERN_DEBUG "Authenticate from: address:\t%02x:%02x:%02x:%02x:%02x:%02x\n",
1852 mlmeex->address[0],
1853 mlmeex->address[1],
1854 mlmeex->address[2],
1855 mlmeex->address[3],
1856 mlmeex->address[4],
1857 mlmeex->address[5]
1859 confirm->id = -1; /* or mlmeex->id ? */
1860 confirm->state = 0; /* not used */
1861 confirm->code = 0;
1862 confirm->size = 6;
1863 confirm->data[0] = 0x00;
1864 confirm->data[1] = 0x00;
1865 confirm->data[2] = 0x02;
1866 confirm->data[3] = 0x00;
1867 confirm->data[4] = 0x00;
1868 confirm->data[5] = 0x00;
1870 ret = mgt_set_varlen(priv, DOT11_OID_ASSOCIATEEX, confirm, 6);
1872 kfree(confirm);
1873 if (ret)
1874 return ret;
1875 break;
1877 case DOT11_OID_DISASSOCIATEEX:
1878 send_formatted_event(priv, "Disassociate request (ex)", mlme, 0);
1879 break;
1881 case DOT11_OID_ASSOCIATEEX:
1882 handle_request(priv, mlme, oid);
1883 send_formatted_event(priv, "Associate request (ex)", mlme, 1);
1885 if (priv->iw_mode != IW_MODE_MASTER
1886 && mlmeex->state != DOT11_STATE_AUTHING)
1887 break;
1889 confirm = kmalloc(sizeof(struct obj_mlmeex), GFP_ATOMIC);
1891 if (!confirm)
1892 break;
1894 memcpy(&confirm->address, mlmeex->address, ETH_ALEN);
1896 confirm->id = ((struct obj_mlmeex *)mlme)->id;
1897 confirm->state = 0; /* not used */
1898 confirm->code = 0;
1900 wpa_ie_len = prism54_wpa_ie_get(priv, mlmeex->address, wpa_ie);
1902 if (!wpa_ie_len) {
1903 printk(KERN_DEBUG "No WPA IE found from "
1904 "address:\t%02x:%02x:%02x:%02x:%02x:%02x\n",
1905 mlmeex->address[0],
1906 mlmeex->address[1],
1907 mlmeex->address[2],
1908 mlmeex->address[3],
1909 mlmeex->address[4],
1910 mlmeex->address[5]
1912 kfree(confirm);
1913 break;
1916 confirm->size = wpa_ie_len;
1917 memcpy(&confirm->data, wpa_ie, wpa_ie_len);
1919 mgt_set_varlen(priv, oid, confirm, wpa_ie_len);
1921 kfree(confirm);
1923 break;
1925 case DOT11_OID_REASSOCIATEEX:
1926 handle_request(priv, mlme, oid);
1927 send_formatted_event(priv, "Reassociate request (ex)", mlme, 1);
1929 if (priv->iw_mode != IW_MODE_MASTER
1930 && mlmeex->state != DOT11_STATE_ASSOCING)
1931 break;
1933 confirm = kmalloc(sizeof(struct obj_mlmeex), GFP_ATOMIC);
1935 if (!confirm)
1936 break;
1938 memcpy(&confirm->address, mlmeex->address, ETH_ALEN);
1940 confirm->id = mlmeex->id;
1941 confirm->state = 0; /* not used */
1942 confirm->code = 0;
1944 wpa_ie_len = prism54_wpa_ie_get(priv, mlmeex->address, wpa_ie);
1946 if (!wpa_ie_len) {
1947 printk(KERN_DEBUG "No WPA IE found from "
1948 "address:\t%02x:%02x:%02x:%02x:%02x:%02x\n",
1949 mlmeex->address[0],
1950 mlmeex->address[1],
1951 mlmeex->address[2],
1952 mlmeex->address[3],
1953 mlmeex->address[4],
1954 mlmeex->address[5]
1956 kfree(confirm);
1957 break;
1960 confirm->size = wpa_ie_len;
1961 memcpy(&confirm->data, wpa_ie, wpa_ie_len);
1963 mgt_set_varlen(priv, oid, confirm, wpa_ie_len);
1965 kfree(confirm);
1967 break;
1969 default:
1970 return -EINVAL;
1973 return 0;
1977 * Process a device trap. This is called via schedule_work(), outside of
1978 * interrupt context, no locks held.
1980 void
1981 prism54_process_trap(void *data)
1983 struct islpci_mgmtframe *frame = data;
1984 struct net_device *ndev = frame->ndev;
1985 enum oid_num_t n = mgt_oidtonum(frame->header->oid);
1987 if (n != OID_NUM_LAST)
1988 prism54_process_trap_helper(netdev_priv(ndev), n, frame->data);
1989 islpci_mgt_release(frame);
1993 prism54_set_mac_address(struct net_device *ndev, void *addr)
1995 islpci_private *priv = netdev_priv(ndev);
1996 int ret;
1998 if (ndev->addr_len != 6)
1999 return -EINVAL;
2000 ret = mgt_set_request(priv, GEN_OID_MACADDRESS, 0,
2001 &((struct sockaddr *) addr)->sa_data);
2002 if (!ret)
2003 memcpy(priv->ndev->dev_addr,
2004 &((struct sockaddr *) addr)->sa_data, 6);
2006 return ret;
2009 /* Note: currently, use hostapd ioctl from the Host AP driver for WPA
2010 * support. This is to be replaced with Linux wireless extensions once they
2011 * get WPA support. */
2013 /* Note II: please leave all this together as it will be easier to remove later,
2014 * once wireless extensions add WPA support -mcgrof */
2016 /* PRISM54_HOSTAPD ioctl() cmd: */
2017 enum {
2018 PRISM2_SET_ENCRYPTION = 6,
2019 PRISM2_HOSTAPD_SET_GENERIC_ELEMENT = 12,
2020 PRISM2_HOSTAPD_MLME = 13,
2021 PRISM2_HOSTAPD_SCAN_REQ = 14,
2024 #define PRISM54_SET_WPA SIOCIWFIRSTPRIV+12
2025 #define PRISM54_HOSTAPD SIOCIWFIRSTPRIV+25
2026 #define PRISM54_DROP_UNENCRYPTED SIOCIWFIRSTPRIV+26
2028 #define PRISM2_HOSTAPD_MAX_BUF_SIZE 1024
2029 #define PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN \
2030 ((int) (&((struct prism2_hostapd_param *) 0)->u.generic_elem.data))
2032 /* Maximum length for algorithm names (-1 for nul termination)
2033 * used in ioctl() */
2034 #define HOSTAP_CRYPT_ALG_NAME_LEN 16
2036 struct prism2_hostapd_param {
2037 u32 cmd;
2038 u8 sta_addr[ETH_ALEN];
2039 union {
2040 struct {
2041 u8 alg[HOSTAP_CRYPT_ALG_NAME_LEN];
2042 u32 flags;
2043 u32 err;
2044 u8 idx;
2045 u8 seq[8]; /* sequence counter (set: RX, get: TX) */
2046 u16 key_len;
2047 u8 key[0];
2048 } crypt;
2049 struct {
2050 u8 len;
2051 u8 data[0];
2052 } generic_elem;
2053 struct {
2054 #define MLME_STA_DEAUTH 0
2055 #define MLME_STA_DISASSOC 1
2056 u16 cmd;
2057 u16 reason_code;
2058 } mlme;
2059 struct {
2060 u8 ssid_len;
2061 u8 ssid[32];
2062 } scan_req;
2063 } u;
2067 static int
2068 prism2_ioctl_set_encryption(struct net_device *dev,
2069 struct prism2_hostapd_param *param,
2070 int param_len)
2072 islpci_private *priv = netdev_priv(dev);
2073 int rvalue = 0, force = 0;
2074 int authen = DOT11_AUTH_OS, invoke = 0, exunencrypt = 0;
2075 union oid_res_t r;
2077 /* with the new API, it's impossible to get a NULL pointer.
2078 * New version of iwconfig set the IW_ENCODE_NOKEY flag
2079 * when no key is given, but older versions don't. */
2081 if (param->u.crypt.key_len > 0) {
2082 /* we have a key to set */
2083 int index = param->u.crypt.idx;
2084 int current_index;
2085 struct obj_key key = { DOT11_PRIV_TKIP, 0, "" };
2087 /* get the current key index */
2088 rvalue = mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r);
2089 current_index = r.u;
2090 /* Verify that the key is not marked as invalid */
2091 if (!(param->u.crypt.flags & IW_ENCODE_NOKEY)) {
2092 key.length = param->u.crypt.key_len > sizeof (param->u.crypt.key) ?
2093 sizeof (param->u.crypt.key) : param->u.crypt.key_len;
2094 memcpy(key.key, param->u.crypt.key, key.length);
2095 if (key.length == 32)
2096 /* we want WPA-PSK */
2097 key.type = DOT11_PRIV_TKIP;
2098 if ((index < 0) || (index > 3))
2099 /* no index provided use the current one */
2100 index = current_index;
2102 /* now send the key to the card */
2103 rvalue |=
2104 mgt_set_request(priv, DOT11_OID_DEFKEYX, index,
2105 &key);
2108 * If a valid key is set, encryption should be enabled
2109 * (user may turn it off later).
2110 * This is also how "iwconfig ethX key on" works
2112 if ((index == current_index) && (key.length > 0))
2113 force = 1;
2114 } else {
2115 int index = (param->u.crypt.flags & IW_ENCODE_INDEX) - 1;
2116 if ((index >= 0) && (index <= 3)) {
2117 /* we want to set the key index */
2118 rvalue |=
2119 mgt_set_request(priv, DOT11_OID_DEFKEYID, 0,
2120 &index);
2121 } else {
2122 if (!param->u.crypt.flags & IW_ENCODE_MODE) {
2123 /* we cannot do anything. Complain. */
2124 return -EINVAL;
2128 /* now read the flags */
2129 if (param->u.crypt.flags & IW_ENCODE_DISABLED) {
2130 /* Encoding disabled,
2131 * authen = DOT11_AUTH_OS;
2132 * invoke = 0;
2133 * exunencrypt = 0; */
2135 if (param->u.crypt.flags & IW_ENCODE_OPEN)
2136 /* Encode but accept non-encoded packets. No auth */
2137 invoke = 1;
2138 if ((param->u.crypt.flags & IW_ENCODE_RESTRICTED) || force) {
2139 /* Refuse non-encoded packets. Auth */
2140 authen = DOT11_AUTH_BOTH;
2141 invoke = 1;
2142 exunencrypt = 1;
2144 /* do the change if requested */
2145 if ((param->u.crypt.flags & IW_ENCODE_MODE) || force) {
2146 rvalue |=
2147 mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0, &authen);
2148 rvalue |=
2149 mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0, &invoke);
2150 rvalue |=
2151 mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0,
2152 &exunencrypt);
2154 return rvalue;
2157 static int
2158 prism2_ioctl_set_generic_element(struct net_device *ndev,
2159 struct prism2_hostapd_param *param,
2160 int param_len)
2162 islpci_private *priv = netdev_priv(ndev);
2163 int max_len, len, alen, ret=0;
2164 struct obj_attachment *attach;
2166 len = param->u.generic_elem.len;
2167 max_len = param_len - PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN;
2168 if (max_len < 0 || max_len < len)
2169 return -EINVAL;
2171 alen = sizeof(*attach) + len;
2172 attach = kmalloc(alen, GFP_KERNEL);
2173 if (attach == NULL)
2174 return -ENOMEM;
2176 memset(attach, 0, alen);
2177 #define WLAN_FC_TYPE_MGMT 0
2178 #define WLAN_FC_STYPE_ASSOC_REQ 0
2179 #define WLAN_FC_STYPE_REASSOC_REQ 2
2181 /* Note: endianness is covered by mgt_set_varlen */
2183 attach->type = (WLAN_FC_TYPE_MGMT << 2) |
2184 (WLAN_FC_STYPE_ASSOC_REQ << 4);
2185 attach->id = -1;
2186 attach->size = len;
2187 memcpy(attach->data, param->u.generic_elem.data, len);
2189 ret = mgt_set_varlen(priv, DOT11_OID_ATTACHMENT, attach, len);
2191 if (ret == 0) {
2192 attach->type = (WLAN_FC_TYPE_MGMT << 2) |
2193 (WLAN_FC_STYPE_REASSOC_REQ << 4);
2195 ret = mgt_set_varlen(priv, DOT11_OID_ATTACHMENT, attach, len);
2197 if (ret == 0)
2198 printk(KERN_DEBUG "%s: WPA IE Attachment was set\n",
2199 ndev->name);
2202 kfree(attach);
2203 return ret;
2207 static int
2208 prism2_ioctl_mlme(struct net_device *dev, struct prism2_hostapd_param *param)
2210 return -EOPNOTSUPP;
2213 static int
2214 prism2_ioctl_scan_req(struct net_device *ndev,
2215 struct prism2_hostapd_param *param)
2217 islpci_private *priv = netdev_priv(ndev);
2218 int i, rvalue;
2219 struct obj_bsslist *bsslist;
2220 u32 noise = 0;
2221 char *extra = "";
2222 char *current_ev = "foo";
2223 union oid_res_t r;
2225 if (islpci_get_state(priv) < PRV_STATE_INIT) {
2226 /* device is not ready, fail gently */
2227 return 0;
2230 /* first get the noise value. We will use it to report the link quality */
2231 rvalue = mgt_get_request(priv, DOT11_OID_NOISEFLOOR, 0, NULL, &r);
2232 noise = r.u;
2234 /* Ask the device for a list of known bss. We can report at most
2235 * IW_MAX_AP=64 to the range struct. But the device won't repport anything
2236 * if you change the value of IWMAX_BSS=24.
2238 rvalue |= mgt_get_request(priv, DOT11_OID_BSSLIST, 0, NULL, &r);
2239 bsslist = r.ptr;
2241 /* ok now, scan the list and translate its info */
2242 for (i = 0; i < min(IW_MAX_AP, (int) bsslist->nr); i++)
2243 current_ev = prism54_translate_bss(ndev, current_ev,
2244 extra + IW_SCAN_MAX_DATA,
2245 &(bsslist->bsslist[i]),
2246 noise);
2247 kfree(bsslist);
2249 return rvalue;
2252 static int
2253 prism54_hostapd(struct net_device *ndev, struct iw_point *p)
2255 struct prism2_hostapd_param *param;
2256 int ret = 0;
2257 u32 uwrq;
2259 printk(KERN_DEBUG "prism54_hostapd - len=%d\n", p->length);
2260 if (p->length < sizeof(struct prism2_hostapd_param) ||
2261 p->length > PRISM2_HOSTAPD_MAX_BUF_SIZE || !p->pointer)
2262 return -EINVAL;
2264 param = (struct prism2_hostapd_param *) kmalloc(p->length, GFP_KERNEL);
2265 if (param == NULL)
2266 return -ENOMEM;
2268 if (copy_from_user(param, p->pointer, p->length)) {
2269 kfree(param);
2270 return -EFAULT;
2273 switch (param->cmd) {
2274 case PRISM2_SET_ENCRYPTION:
2275 printk(KERN_DEBUG "%s: Caught WPA supplicant set encryption request\n",
2276 ndev->name);
2277 ret = prism2_ioctl_set_encryption(ndev, param, p->length);
2278 break;
2279 case PRISM2_HOSTAPD_SET_GENERIC_ELEMENT:
2280 printk(KERN_DEBUG "%s: Caught WPA supplicant set WPA IE request\n",
2281 ndev->name);
2282 ret = prism2_ioctl_set_generic_element(ndev, param,
2283 p->length);
2284 break;
2285 case PRISM2_HOSTAPD_MLME:
2286 printk(KERN_DEBUG "%s: Caught WPA supplicant MLME request\n",
2287 ndev->name);
2288 ret = prism2_ioctl_mlme(ndev, param);
2289 break;
2290 case PRISM2_HOSTAPD_SCAN_REQ:
2291 printk(KERN_DEBUG "%s: Caught WPA supplicant scan request\n",
2292 ndev->name);
2293 ret = prism2_ioctl_scan_req(ndev, param);
2294 break;
2295 case PRISM54_SET_WPA:
2296 printk(KERN_DEBUG "%s: Caught WPA supplicant wpa init request\n",
2297 ndev->name);
2298 uwrq = 1;
2299 ret = prism54_set_wpa(ndev, NULL, &uwrq, NULL);
2300 break;
2301 case PRISM54_DROP_UNENCRYPTED:
2302 printk(KERN_DEBUG "%s: Caught WPA drop unencrypted request\n",
2303 ndev->name);
2304 #if 0
2305 uwrq = 0x01;
2306 mgt_set(priv, DOT11_OID_EXUNENCRYPTED, &uwrq);
2307 down_write(&priv->mib_sem);
2308 mgt_commit(priv);
2309 up_write(&priv->mib_sem);
2310 #endif
2311 /* Not necessary, as set_wpa does it, should we just do it here though? */
2312 ret = 0;
2313 break;
2314 default:
2315 printk(KERN_DEBUG "%s: Caught a WPA supplicant request that is not supported\n",
2316 ndev->name);
2317 ret = -EOPNOTSUPP;
2318 break;
2321 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
2322 ret = -EFAULT;
2324 kfree(param);
2326 return ret;
2329 static int
2330 prism54_set_wpa(struct net_device *ndev, struct iw_request_info *info,
2331 __u32 * uwrq, char *extra)
2333 islpci_private *priv = netdev_priv(ndev);
2334 u32 mlme, authen, dot1x, filter, wep;
2336 if (islpci_get_state(priv) < PRV_STATE_INIT)
2337 return 0;
2339 wep = 1; /* For privacy invoked */
2340 filter = 1; /* Filter out all unencrypted frames */
2341 dot1x = 0x01; /* To enable eap filter */
2342 mlme = DOT11_MLME_EXTENDED;
2343 authen = DOT11_AUTH_OS; /* Only WEP uses _SK and _BOTH */
2345 down_write(&priv->mib_sem);
2346 priv->wpa = *uwrq;
2348 switch (priv->wpa) {
2349 default:
2350 case 0: /* Clears/disables WPA and friends */
2351 wep = 0;
2352 filter = 0; /* Do not filter un-encrypted data */
2353 dot1x = 0;
2354 mlme = DOT11_MLME_AUTO;
2355 printk("%s: Disabling WPA\n", ndev->name);
2356 break;
2357 case 2:
2358 case 1: /* WPA */
2359 printk("%s: Enabling WPA\n", ndev->name);
2360 break;
2362 up_write(&priv->mib_sem);
2364 mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0, &authen);
2365 mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0, &wep);
2366 mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0, &filter);
2367 mgt_set_request(priv, DOT11_OID_DOT1XENABLE, 0, &dot1x);
2368 mgt_set_request(priv, DOT11_OID_MLMEAUTOLEVEL, 0, &mlme);
2370 return 0;
2373 static int
2374 prism54_get_wpa(struct net_device *ndev, struct iw_request_info *info,
2375 __u32 * uwrq, char *extra)
2377 islpci_private *priv = netdev_priv(ndev);
2378 *uwrq = priv->wpa;
2379 return 0;
2382 static int
2383 prism54_set_prismhdr(struct net_device *ndev, struct iw_request_info *info,
2384 __u32 * uwrq, char *extra)
2386 islpci_private *priv = netdev_priv(ndev);
2387 priv->monitor_type =
2388 (*uwrq ? ARPHRD_IEEE80211_PRISM : ARPHRD_IEEE80211);
2389 if (priv->iw_mode == IW_MODE_MONITOR)
2390 priv->ndev->type = priv->monitor_type;
2392 return 0;
2395 static int
2396 prism54_get_prismhdr(struct net_device *ndev, struct iw_request_info *info,
2397 __u32 * uwrq, char *extra)
2399 islpci_private *priv = netdev_priv(ndev);
2400 *uwrq = (priv->monitor_type == ARPHRD_IEEE80211_PRISM);
2401 return 0;
2404 static int
2405 prism54_debug_oid(struct net_device *ndev, struct iw_request_info *info,
2406 __u32 * uwrq, char *extra)
2408 islpci_private *priv = netdev_priv(ndev);
2410 priv->priv_oid = *uwrq;
2411 printk("%s: oid 0x%08X\n", ndev->name, *uwrq);
2413 return 0;
2416 static int
2417 prism54_debug_get_oid(struct net_device *ndev, struct iw_request_info *info,
2418 struct iw_point *data, char *extra)
2420 islpci_private *priv = netdev_priv(ndev);
2421 struct islpci_mgmtframe *response;
2422 int ret = -EIO;
2424 printk("%s: get_oid 0x%08X\n", ndev->name, priv->priv_oid);
2425 data->length = 0;
2427 if (islpci_get_state(priv) >= PRV_STATE_INIT) {
2428 ret =
2429 islpci_mgt_transaction(priv->ndev, PIMFOR_OP_GET,
2430 priv->priv_oid, extra, 256,
2431 &response);
2432 printk("%s: ret: %i\n", ndev->name, ret);
2433 if (ret || !response
2434 || response->header->operation == PIMFOR_OP_ERROR) {
2435 if (response) {
2436 islpci_mgt_release(response);
2438 printk("%s: EIO\n", ndev->name);
2439 ret = -EIO;
2441 if (!ret) {
2442 data->length = response->header->length;
2443 memcpy(extra, response->data, data->length);
2444 islpci_mgt_release(response);
2445 printk("%s: len: %i\n", ndev->name, data->length);
2449 return ret;
2452 static int
2453 prism54_debug_set_oid(struct net_device *ndev, struct iw_request_info *info,
2454 struct iw_point *data, char *extra)
2456 islpci_private *priv = netdev_priv(ndev);
2457 struct islpci_mgmtframe *response;
2458 int ret = 0, response_op = PIMFOR_OP_ERROR;
2460 printk("%s: set_oid 0x%08X\tlen: %d\n", ndev->name, priv->priv_oid,
2461 data->length);
2463 if (islpci_get_state(priv) >= PRV_STATE_INIT) {
2464 ret =
2465 islpci_mgt_transaction(priv->ndev, PIMFOR_OP_SET,
2466 priv->priv_oid, extra, data->length,
2467 &response);
2468 printk("%s: ret: %i\n", ndev->name, ret);
2469 if (ret || !response
2470 || response->header->operation == PIMFOR_OP_ERROR) {
2471 if (response) {
2472 islpci_mgt_release(response);
2474 printk("%s: EIO\n", ndev->name);
2475 ret = -EIO;
2477 if (!ret) {
2478 response_op = response->header->operation;
2479 printk("%s: response_op: %i\n", ndev->name,
2480 response_op);
2481 islpci_mgt_release(response);
2485 return (ret ? ret : -EINPROGRESS);
2488 static int
2489 prism54_set_spy(struct net_device *ndev,
2490 struct iw_request_info *info,
2491 union iwreq_data *uwrq, char *extra)
2493 islpci_private *priv = netdev_priv(ndev);
2494 u32 u, oid = OID_INL_CONFIG;
2496 down_write(&priv->mib_sem);
2497 mgt_get(priv, OID_INL_CONFIG, &u);
2499 if ((uwrq->data.length == 0) && (priv->spy_data.spy_number > 0))
2500 /* disable spy */
2501 u &= ~INL_CONFIG_RXANNEX;
2502 else if ((uwrq->data.length > 0) && (priv->spy_data.spy_number == 0))
2503 /* enable spy */
2504 u |= INL_CONFIG_RXANNEX;
2506 mgt_set(priv, OID_INL_CONFIG, &u);
2507 mgt_commit_list(priv, &oid, 1);
2508 up_write(&priv->mib_sem);
2510 return iw_handler_set_spy(ndev, info, uwrq, extra);
2513 static const iw_handler prism54_handler[] = {
2514 (iw_handler) prism54_commit, /* SIOCSIWCOMMIT */
2515 (iw_handler) prism54_get_name, /* SIOCGIWNAME */
2516 (iw_handler) NULL, /* SIOCSIWNWID */
2517 (iw_handler) NULL, /* SIOCGIWNWID */
2518 (iw_handler) prism54_set_freq, /* SIOCSIWFREQ */
2519 (iw_handler) prism54_get_freq, /* SIOCGIWFREQ */
2520 (iw_handler) prism54_set_mode, /* SIOCSIWMODE */
2521 (iw_handler) prism54_get_mode, /* SIOCGIWMODE */
2522 (iw_handler) prism54_set_sens, /* SIOCSIWSENS */
2523 (iw_handler) prism54_get_sens, /* SIOCGIWSENS */
2524 (iw_handler) NULL, /* SIOCSIWRANGE */
2525 (iw_handler) prism54_get_range, /* SIOCGIWRANGE */
2526 (iw_handler) NULL, /* SIOCSIWPRIV */
2527 (iw_handler) NULL, /* SIOCGIWPRIV */
2528 (iw_handler) NULL, /* SIOCSIWSTATS */
2529 (iw_handler) NULL, /* SIOCGIWSTATS */
2530 prism54_set_spy, /* SIOCSIWSPY */
2531 iw_handler_get_spy, /* SIOCGIWSPY */
2532 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2533 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2534 (iw_handler) prism54_set_wap, /* SIOCSIWAP */
2535 (iw_handler) prism54_get_wap, /* SIOCGIWAP */
2536 (iw_handler) NULL, /* -- hole -- */
2537 (iw_handler) NULL, /* SIOCGIWAPLIST depreciated */
2538 (iw_handler) prism54_set_scan, /* SIOCSIWSCAN */
2539 (iw_handler) prism54_get_scan, /* SIOCGIWSCAN */
2540 (iw_handler) prism54_set_essid, /* SIOCSIWESSID */
2541 (iw_handler) prism54_get_essid, /* SIOCGIWESSID */
2542 (iw_handler) prism54_set_nick, /* SIOCSIWNICKN */
2543 (iw_handler) prism54_get_nick, /* SIOCGIWNICKN */
2544 (iw_handler) NULL, /* -- hole -- */
2545 (iw_handler) NULL, /* -- hole -- */
2546 (iw_handler) prism54_set_rate, /* SIOCSIWRATE */
2547 (iw_handler) prism54_get_rate, /* SIOCGIWRATE */
2548 (iw_handler) prism54_set_rts, /* SIOCSIWRTS */
2549 (iw_handler) prism54_get_rts, /* SIOCGIWRTS */
2550 (iw_handler) prism54_set_frag, /* SIOCSIWFRAG */
2551 (iw_handler) prism54_get_frag, /* SIOCGIWFRAG */
2552 (iw_handler) prism54_set_txpower, /* SIOCSIWTXPOW */
2553 (iw_handler) prism54_get_txpower, /* SIOCGIWTXPOW */
2554 (iw_handler) prism54_set_retry, /* SIOCSIWRETRY */
2555 (iw_handler) prism54_get_retry, /* SIOCGIWRETRY */
2556 (iw_handler) prism54_set_encode, /* SIOCSIWENCODE */
2557 (iw_handler) prism54_get_encode, /* SIOCGIWENCODE */
2558 (iw_handler) NULL, /* SIOCSIWPOWER */
2559 (iw_handler) NULL, /* SIOCGIWPOWER */
2562 /* The low order bit identify a SET (0) or a GET (1) ioctl. */
2564 #define PRISM54_RESET SIOCIWFIRSTPRIV
2565 #define PRISM54_GET_POLICY SIOCIWFIRSTPRIV+1
2566 #define PRISM54_SET_POLICY SIOCIWFIRSTPRIV+2
2567 #define PRISM54_GET_MAC SIOCIWFIRSTPRIV+3
2568 #define PRISM54_ADD_MAC SIOCIWFIRSTPRIV+4
2570 #define PRISM54_DEL_MAC SIOCIWFIRSTPRIV+6
2572 #define PRISM54_KICK_MAC SIOCIWFIRSTPRIV+8
2574 #define PRISM54_KICK_ALL SIOCIWFIRSTPRIV+10
2576 #define PRISM54_GET_WPA SIOCIWFIRSTPRIV+11
2577 #define PRISM54_SET_WPA SIOCIWFIRSTPRIV+12
2579 #define PRISM54_DBG_OID SIOCIWFIRSTPRIV+14
2580 #define PRISM54_DBG_GET_OID SIOCIWFIRSTPRIV+15
2581 #define PRISM54_DBG_SET_OID SIOCIWFIRSTPRIV+16
2583 #define PRISM54_GET_OID SIOCIWFIRSTPRIV+17
2584 #define PRISM54_SET_OID_U32 SIOCIWFIRSTPRIV+18
2585 #define PRISM54_SET_OID_STR SIOCIWFIRSTPRIV+20
2586 #define PRISM54_SET_OID_ADDR SIOCIWFIRSTPRIV+22
2588 #define PRISM54_GET_PRISMHDR SIOCIWFIRSTPRIV+23
2589 #define PRISM54_SET_PRISMHDR SIOCIWFIRSTPRIV+24
2591 #define IWPRIV_SET_U32(n,x) { n, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "s_"x }
2592 #define IWPRIV_SET_SSID(n,x) { n, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 1, 0, "s_"x }
2593 #define IWPRIV_SET_ADDR(n,x) { n, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "s_"x }
2594 #define IWPRIV_GET(n,x) { n, 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | PRIV_STR_SIZE, "g_"x }
2596 #define IWPRIV_U32(n,x) IWPRIV_SET_U32(n,x), IWPRIV_GET(n,x)
2597 #define IWPRIV_SSID(n,x) IWPRIV_SET_SSID(n,x), IWPRIV_GET(n,x)
2598 #define IWPRIV_ADDR(n,x) IWPRIV_SET_ADDR(n,x), IWPRIV_GET(n,x)
2600 /* Note : limited to 128 private ioctls (wireless tools 26) */
2602 static const struct iw_priv_args prism54_private_args[] = {
2603 /*{ cmd, set_args, get_args, name } */
2604 {PRISM54_RESET, 0, 0, "reset"},
2605 {PRISM54_GET_PRISMHDR, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2606 "get_prismhdr"},
2607 {PRISM54_SET_PRISMHDR, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0,
2608 "set_prismhdr"},
2609 {PRISM54_GET_POLICY, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2610 "getPolicy"},
2611 {PRISM54_SET_POLICY, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0,
2612 "setPolicy"},
2613 {PRISM54_GET_MAC, 0, IW_PRIV_TYPE_ADDR | 64, "getMac"},
2614 {PRISM54_ADD_MAC, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0,
2615 "addMac"},
2616 {PRISM54_DEL_MAC, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0,
2617 "delMac"},
2618 {PRISM54_KICK_MAC, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0,
2619 "kickMac"},
2620 {PRISM54_KICK_ALL, 0, 0, "kickAll"},
2621 {PRISM54_GET_WPA, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2622 "get_wpa"},
2623 {PRISM54_SET_WPA, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0,
2624 "set_wpa"},
2625 {PRISM54_DBG_OID, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0,
2626 "dbg_oid"},
2627 {PRISM54_DBG_GET_OID, 0, IW_PRIV_TYPE_BYTE | 256, "dbg_get_oid"},
2628 {PRISM54_DBG_SET_OID, IW_PRIV_TYPE_BYTE | 256, 0, "dbg_set_oid"},
2629 /* --- sub-ioctls handlers --- */
2630 {PRISM54_GET_OID,
2631 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | PRIV_STR_SIZE, ""},
2632 {PRISM54_SET_OID_U32,
2633 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, ""},
2634 {PRISM54_SET_OID_STR,
2635 IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 1, 0, ""},
2636 {PRISM54_SET_OID_ADDR,
2637 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, ""},
2638 /* --- sub-ioctls definitions --- */
2639 IWPRIV_ADDR(GEN_OID_MACADDRESS, "addr"),
2640 IWPRIV_GET(GEN_OID_LINKSTATE, "linkstate"),
2641 IWPRIV_U32(DOT11_OID_BSSTYPE, "bsstype"),
2642 IWPRIV_ADDR(DOT11_OID_BSSID, "bssid"),
2643 IWPRIV_U32(DOT11_OID_STATE, "state"),
2644 IWPRIV_U32(DOT11_OID_AID, "aid"),
2646 IWPRIV_SSID(DOT11_OID_SSIDOVERRIDE, "ssidoverride"),
2648 IWPRIV_U32(DOT11_OID_MEDIUMLIMIT, "medlimit"),
2649 IWPRIV_U32(DOT11_OID_BEACONPERIOD, "beacon"),
2650 IWPRIV_U32(DOT11_OID_DTIMPERIOD, "dtimperiod"),
2652 IWPRIV_U32(DOT11_OID_AUTHENABLE, "authenable"),
2653 IWPRIV_U32(DOT11_OID_PRIVACYINVOKED, "privinvok"),
2654 IWPRIV_U32(DOT11_OID_EXUNENCRYPTED, "exunencrypt"),
2656 IWPRIV_U32(DOT11_OID_REKEYTHRESHOLD, "rekeythresh"),
2658 IWPRIV_U32(DOT11_OID_MAXTXLIFETIME, "maxtxlife"),
2659 IWPRIV_U32(DOT11_OID_MAXRXLIFETIME, "maxrxlife"),
2660 IWPRIV_U32(DOT11_OID_ALOFT_FIXEDRATE, "fixedrate"),
2661 IWPRIV_U32(DOT11_OID_MAXFRAMEBURST, "frameburst"),
2662 IWPRIV_U32(DOT11_OID_PSM, "psm"),
2664 IWPRIV_U32(DOT11_OID_BRIDGELOCAL, "bridge"),
2665 IWPRIV_U32(DOT11_OID_CLIENTS, "clients"),
2666 IWPRIV_U32(DOT11_OID_CLIENTSASSOCIATED, "clientassoc"),
2667 IWPRIV_U32(DOT11_OID_DOT1XENABLE, "dot1xenable"),
2668 IWPRIV_U32(DOT11_OID_ANTENNARX, "rxant"),
2669 IWPRIV_U32(DOT11_OID_ANTENNATX, "txant"),
2670 IWPRIV_U32(DOT11_OID_ANTENNADIVERSITY, "antdivers"),
2671 IWPRIV_U32(DOT11_OID_EDTHRESHOLD, "edthresh"),
2672 IWPRIV_U32(DOT11_OID_PREAMBLESETTINGS, "preamble"),
2673 IWPRIV_GET(DOT11_OID_RATES, "rates"),
2674 IWPRIV_U32(DOT11_OID_OUTPUTPOWER, ".11outpower"),
2675 IWPRIV_GET(DOT11_OID_SUPPORTEDRATES, "supprates"),
2676 IWPRIV_GET(DOT11_OID_SUPPORTEDFREQUENCIES, "suppfreq"),
2678 IWPRIV_U32(DOT11_OID_NOISEFLOOR, "noisefloor"),
2679 IWPRIV_GET(DOT11_OID_FREQUENCYACTIVITY, "freqactivity"),
2680 IWPRIV_U32(DOT11_OID_NONERPPROTECTION, "nonerpprotec"),
2681 IWPRIV_U32(DOT11_OID_PROFILES, "profile"),
2682 IWPRIV_GET(DOT11_OID_EXTENDEDRATES, "extrates"),
2683 IWPRIV_U32(DOT11_OID_MLMEAUTOLEVEL, "mlmelevel"),
2685 IWPRIV_GET(DOT11_OID_BSSS, "bsss"),
2686 IWPRIV_GET(DOT11_OID_BSSLIST, "bsslist"),
2687 IWPRIV_U32(OID_INL_MODE, "mode"),
2688 IWPRIV_U32(OID_INL_CONFIG, "config"),
2689 IWPRIV_U32(OID_INL_DOT11D_CONFORMANCE, ".11dconform"),
2690 IWPRIV_GET(OID_INL_PHYCAPABILITIES, "phycapa"),
2691 IWPRIV_U32(OID_INL_OUTPUTPOWER, "outpower"),
2694 static const iw_handler prism54_private_handler[] = {
2695 (iw_handler) prism54_reset,
2696 (iw_handler) prism54_get_policy,
2697 (iw_handler) prism54_set_policy,
2698 (iw_handler) prism54_get_mac,
2699 (iw_handler) prism54_add_mac,
2700 (iw_handler) NULL,
2701 (iw_handler) prism54_del_mac,
2702 (iw_handler) NULL,
2703 (iw_handler) prism54_kick_mac,
2704 (iw_handler) NULL,
2705 (iw_handler) prism54_kick_all,
2706 (iw_handler) prism54_get_wpa,
2707 (iw_handler) prism54_set_wpa,
2708 (iw_handler) NULL,
2709 (iw_handler) prism54_debug_oid,
2710 (iw_handler) prism54_debug_get_oid,
2711 (iw_handler) prism54_debug_set_oid,
2712 (iw_handler) prism54_get_oid,
2713 (iw_handler) prism54_set_u32,
2714 (iw_handler) NULL,
2715 (iw_handler) prism54_set_raw,
2716 (iw_handler) NULL,
2717 (iw_handler) prism54_set_raw,
2718 (iw_handler) prism54_get_prismhdr,
2719 (iw_handler) prism54_set_prismhdr,
2722 const struct iw_handler_def prism54_handler_def = {
2723 .num_standard = sizeof (prism54_handler) / sizeof (iw_handler),
2724 .num_private = sizeof (prism54_private_handler) / sizeof (iw_handler),
2725 .num_private_args =
2726 sizeof (prism54_private_args) / sizeof (struct iw_priv_args),
2727 .standard = (iw_handler *) prism54_handler,
2728 .private = (iw_handler *) prism54_private_handler,
2729 .private_args = (struct iw_priv_args *) prism54_private_args,
2730 #if WIRELESS_EXT == 16
2731 .spy_offset = offsetof(islpci_private, spy_data),
2732 #endif /* WIRELESS_EXT == 16 */
2735 /* For wpa_supplicant */
2738 prism54_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
2740 struct iwreq *wrq = (struct iwreq *) rq;
2741 int ret = -1;
2742 switch (cmd) {
2743 case PRISM54_HOSTAPD:
2744 if (!capable(CAP_NET_ADMIN))
2745 return -EPERM;
2746 ret = prism54_hostapd(ndev, &wrq->u.data);
2747 return ret;
2749 return -EOPNOTSUPP;