1 /* $Header: /var/lib/cvs/prism54-ng/ksrc/isl_ioctl.c,v 1.140 2004/02/28 03:06:07 mcgrof Exp $
3 * Copyright (C) 2002 Intersil Americas Inc.
4 * (C) 2003 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>
28 #include <linux/moduleparam.h>
30 #include <asm/uaccess.h>
32 #include "isl_ioctl.h"
33 #include "islpci_mgt.h"
34 #include "isl_oid.h" /* additional types and defs for isl38xx fw */
37 #include <net/iw_handler.h> /* New driver API */
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;
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");
52 module_param(init_channel, int, 0);
53 MODULE_PARM_DESC(init_channel,
54 "Check `iwpriv ethx channel` for available channels");
56 module_param(init_wep, int, 0);
57 module_param(init_filter, int, 0);
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");
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");
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");
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_*)
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.
83 prism54_mib_mode_helper(islpci_private *priv, u32 iw_mode)
85 u32 config = INL_CONFIG_MANUALRUN;
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 "%s(): Sorry, Repeater mode and Secondary mode "
91 "are not yet supported by this driver.\n",
96 priv->iw_mode = iw_mode;
100 mode = INL_MODE_CLIENT;
101 bsstype = DOT11_BSSTYPE_ANY;
104 mode = INL_MODE_CLIENT;
105 bsstype = DOT11_BSSTYPE_IBSS;
108 mode = INL_MODE_CLIENT;
109 bsstype = DOT11_BSSTYPE_INFRA;
113 bsstype = DOT11_BSSTYPE_INFRA;
115 case IW_MODE_MONITOR:
116 mode = INL_MODE_PROMISCUOUS;
117 bsstype = DOT11_BSSTYPE_ANY;
118 config |= INL_CONFIG_RXANNEX;
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);
134 * prism54_mib_init - fill MIB cache with defaults
136 * this function initializes the struct given as @mib with defaults,
137 * of which many are retrieved from the global module parameter
142 prism54_mib_init(islpci_private *priv)
145 struct obj_buffer psm_buffer = {
146 .size = cpu_to_le32(PSM_BUFFER_SIZE),
147 .addr = cpu_to_le32(priv->device_psm_buffer)
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);
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);
161 mgt_set(priv, OID_INL_OUTPUTPOWER, &t);
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;
172 /* This sets all of the mode-dependent values */
173 prism54_mib_mode_helper(priv, init_mode);
177 prism54_mib_init_work(islpci_private *priv)
179 down_write(&priv->mib_sem);
181 up_write(&priv->mib_sem);
184 /* this will be executed outside of atomic context thanks to
185 * schedule_work(), thus we can as well use sleeping semaphore
188 prism54_update_stats(islpci_private *priv)
192 struct obj_bss bss, *bss2;
195 if (down_interruptible(&priv->stats_sem))
198 /* missing stats are :
199 * iwstatistics.qual.updated
200 * iwstatistics.discard.nwid
201 * iwstatistics.discard.fragment
202 * iwstatistics.discard.misc
203 * iwstatistics.miss.beacon */
206 * I'm not sure if the unit is dBm.
207 * Note : If we are not connected, this value seems to be irrevelant. */
209 mgt_get_request(priv, DOT11_OID_NOISEFLOOR, 0, NULL, &r);
210 priv->local_iwstatistics.qual.noise = r.u;
212 /* Get the rssi of the link. To do this we need to retrieve a bss. */
214 /* First get the MAC address of the AP we are associated with. */
215 mgt_get_request(priv, DOT11_OID_BSSID, 0, NULL, &r);
218 /* copy this MAC to the bss */
219 for (j = 0; j < 6; j++)
220 bss.address[j] = data[j];
223 /* now ask for the corresponding bss */
224 j = mgt_get_request(priv, DOT11_OID_BSSFIND, 0, (void *) &bss, &r);
226 /* report the rssi and use it to calculate
227 * link quality through a signal-noise
229 priv->local_iwstatistics.qual.level = bss2->rssi;
230 priv->local_iwstatistics.qual.qual =
231 bss2->rssi - priv->iwstatistics.qual.noise;
235 /* report that the stats are new */
236 priv->local_iwstatistics.qual.updated = 0x7;
238 /* Rx : unable to decrypt the MPDU */
239 mgt_get_request(priv, DOT11_OID_PRIVRXFAILED, 0, NULL, &r);
240 priv->local_iwstatistics.discard.code = r.u;
242 /* Tx : Max MAC retries num reached */
243 mgt_get_request(priv, DOT11_OID_MPDUTXFAILED, 0, NULL, &r);
244 priv->local_iwstatistics.discard.retries = r.u;
246 up(&priv->stats_sem);
251 struct iw_statistics *
252 prism54_get_wireless_stats(struct net_device *ndev)
254 islpci_private *priv = netdev_priv(ndev);
256 /* If the stats are being updated return old data */
257 if (down_trylock(&priv->stats_sem) == 0) {
258 memcpy(&priv->iwstatistics, &priv->local_iwstatistics,
259 sizeof (struct iw_statistics));
260 /* They won't be marked updated for the next time */
261 priv->local_iwstatistics.qual.updated = 0;
262 up(&priv->stats_sem);
264 priv->iwstatistics.qual.updated = 0;
266 /* Update our wireless stats, but do not schedule to often
268 if ((priv->stats_timestamp == 0) ||
269 time_after(jiffies, priv->stats_timestamp + 1 * HZ)) {
270 schedule_work(&priv->stats_work);
271 priv->stats_timestamp = jiffies;
274 return &priv->iwstatistics;
278 prism54_commit(struct net_device *ndev, struct iw_request_info *info,
279 char *cwrq, char *extra)
281 islpci_private *priv = netdev_priv(ndev);
283 /* simply re-set the last set SSID, this should commit most stuff */
285 /* Commit in Monitor mode is not necessary, also setting essid
286 * in Monitor mode does not make sense and isn't allowed for this
287 * device's firmware */
288 if(priv->iw_mode != IW_MODE_MONITOR)
289 return mgt_set_request(priv, DOT11_OID_SSID, 0, NULL);
294 prism54_get_name(struct net_device *ndev, struct iw_request_info *info,
295 char *cwrq, char *extra)
297 islpci_private *priv = netdev_priv(ndev);
302 if (islpci_get_state(priv) < PRV_STATE_INIT) {
303 strncpy(cwrq, "NOT READY!", IFNAMSIZ);
306 rvalue = mgt_get_request(priv, OID_INL_PHYCAPABILITIES, 0, NULL, &r);
309 case INL_PHYCAP_5000MHZ:
310 capabilities = "IEEE 802.11a/b/g";
313 capabilities = "IEEE 802.11b/g - FAA Support";
315 case INL_PHYCAP_2400MHZ:
317 capabilities = "IEEE 802.11b/g"; /* Default */
320 strncpy(cwrq, capabilities, IFNAMSIZ);
325 prism54_set_freq(struct net_device *ndev, struct iw_request_info *info,
326 struct iw_freq *fwrq, char *extra)
328 islpci_private *priv = netdev_priv(ndev);
332 /* prepare the structure for the set object */
334 /* structure value contains a channel indication */
337 /* structure contains a frequency indication and fwrq->e = 1 */
338 int f = fwrq->m / 100000;
342 if ((f >= 2412) && (f <= 2484)) {
343 while ((c < 14) && (f != frequency_list_bg[c]))
347 } else if ((f >= (int) 5170) && (f <= (int) 5320)) {
348 while ((c < 12) && (f != frequency_list_a[c]))
357 rvalue = mgt_set_request(priv, DOT11_OID_CHANNEL, 0, &c);
359 /* Call commit handler */
360 return (rvalue ? rvalue : -EINPROGRESS);
364 prism54_get_freq(struct net_device *ndev, struct iw_request_info *info,
365 struct iw_freq *fwrq, char *extra)
367 islpci_private *priv = netdev_priv(ndev);
371 rvalue = mgt_get_request(priv, DOT11_OID_CHANNEL, 0, NULL, &r);
380 prism54_set_mode(struct net_device *ndev, struct iw_request_info *info,
381 __u32 * uwrq, char *extra)
383 islpci_private *priv = netdev_priv(ndev);
384 u32 mlmeautolevel = CARD_DEFAULT_MLME_MODE;
386 /* Let's see if the user passed a valid Linux Wireless mode */
387 if (*uwrq > IW_MODE_MONITOR || *uwrq < IW_MODE_AUTO) {
389 "%s: %s() You passed a non-valid init_mode.\n",
390 priv->ndev->name, __FUNCTION__);
394 down_write(&priv->mib_sem);
396 if (prism54_mib_mode_helper(priv, *uwrq)) {
397 up_write(&priv->mib_sem);
401 /* the ACL code needs an intermediate mlmeautolevel. The wpa stuff an
404 if ((*uwrq == IW_MODE_MASTER) && (priv->acl.policy != MAC_POLICY_OPEN))
405 mlmeautolevel = DOT11_MLME_INTERMEDIATE;
407 mlmeautolevel = DOT11_MLME_EXTENDED;
409 mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &mlmeautolevel);
412 priv->ndev->type = (priv->iw_mode == IW_MODE_MONITOR)
413 ? ARPHRD_IEEE80211 : ARPHRD_ETHER;
414 up_write(&priv->mib_sem);
421 prism54_get_mode(struct net_device *ndev, struct iw_request_info *info,
422 __u32 * uwrq, char *extra)
424 islpci_private *priv = netdev_priv(ndev);
426 BUG_ON((priv->iw_mode < IW_MODE_AUTO) || (priv->iw_mode >
428 *uwrq = priv->iw_mode;
433 /* we use DOT11_OID_EDTHRESHOLD. From what I guess the card will not try to
434 * emit data if (sensitivity > rssi - noise) (in dBm).
435 * prism54_set_sens does not seem to work.
439 prism54_set_sens(struct net_device *ndev, struct iw_request_info *info,
440 struct iw_param *vwrq, char *extra)
442 islpci_private *priv = netdev_priv(ndev);
445 /* by default the card sets this to 20. */
446 sens = vwrq->disabled ? 20 : vwrq->value;
448 /* set the ed threshold. */
449 return mgt_set_request(priv, DOT11_OID_EDTHRESHOLD, 0, &sens);
453 prism54_get_sens(struct net_device *ndev, struct iw_request_info *info,
454 struct iw_param *vwrq, char *extra)
456 islpci_private *priv = netdev_priv(ndev);
460 rvalue = mgt_get_request(priv, DOT11_OID_EDTHRESHOLD, 0, NULL, &r);
463 vwrq->disabled = (vwrq->value == 0);
470 prism54_get_range(struct net_device *ndev, struct iw_request_info *info,
471 struct iw_point *dwrq, char *extra)
473 struct iw_range *range = (struct iw_range *) extra;
474 islpci_private *priv = netdev_priv(ndev);
477 struct obj_frequencies *freq;
480 memset(range, 0, sizeof (struct iw_range));
481 dwrq->length = sizeof (struct iw_range);
483 /* set the wireless extension version number */
484 range->we_version_source = SUPPORTED_WIRELESS_EXT;
485 range->we_version_compiled = WIRELESS_EXT;
487 /* Now the encoding capabilities */
488 range->num_encoding_sizes = 3;
489 /* 64(40) bits WEP */
490 range->encoding_size[0] = 5;
491 /* 128(104) bits WEP */
492 range->encoding_size[1] = 13;
493 /* 256 bits for WPA-PSK */
494 range->encoding_size[2] = 32;
495 /* 4 keys are allowed */
496 range->max_encoding_tokens = 4;
498 /* we don't know the quality range... */
499 range->max_qual.level = 0;
500 range->max_qual.noise = 0;
501 range->max_qual.qual = 0;
502 /* these value describe an average quality. Needs more tweaking... */
503 range->avg_qual.level = -80; /* -80 dBm */
504 range->avg_qual.noise = 0; /* don't know what to put here */
505 range->avg_qual.qual = 0;
507 range->sensitivity = 200;
509 /* retry limit capabilities */
510 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
511 range->retry_flags = IW_RETRY_LIMIT;
512 range->r_time_flags = IW_RETRY_LIFETIME;
514 /* I don't know the range. Put stupid things here */
515 range->min_retry = 1;
516 range->max_retry = 65535;
517 range->min_r_time = 1024;
518 range->max_r_time = 65535 * 1024;
520 /* txpower is supported in dBm's */
521 range->txpower_capa = IW_TXPOW_DBM;
523 if (islpci_get_state(priv) < PRV_STATE_INIT)
526 /* Request the device for the supported frequencies
527 * not really revelant since some devices will report the 5 GHz band
528 * frequencies even if they don't support them.
531 mgt_get_request(priv, DOT11_OID_SUPPORTEDFREQUENCIES, 0, NULL, &r);
534 range->num_channels = le16_to_cpu(freq->nr);
535 range->num_frequency = le16_to_cpu(freq->nr);
537 /* Frequencies are not listed in the right order. The reordering is probably
538 * firmware dependant and thus should work for everyone.
540 m = min(IW_MAX_FREQUENCIES, (int) le16_to_cpu(freq->nr));
541 for (i = 0; i < m - 12; i++) {
542 range->freq[i].m = le16_to_cpu(freq->mhz[12 + i]);
543 range->freq[i].e = 6;
544 range->freq[i].i = i + 1;
546 for (i = m - 12; i < m; i++) {
547 range->freq[i].m = le16_to_cpu(freq->mhz[i - m + 12]);
548 range->freq[i].e = 6;
549 range->freq[i].i = i + 23;
554 rvalue |= mgt_get_request(priv, DOT11_OID_SUPPORTEDRATES, 0, NULL, &r);
557 /* We got an array of char. It is NULL terminated. */
559 while ((i < IW_MAX_BITRATES) && (*data != 0)) {
560 /* the result must be in bps. The card gives us 500Kbps */
561 range->bitrate[i] = (__s32) (*data >> 1);
562 range->bitrate[i] *= 1000000;
567 range->num_bitrates = i;
577 prism54_set_wap(struct net_device *ndev, struct iw_request_info *info,
578 struct sockaddr *awrq, char *extra)
580 islpci_private *priv = netdev_priv(ndev);
584 if (awrq->sa_family != ARPHRD_ETHER)
587 /* prepare the structure for the set object */
588 memcpy(&bssid[0], awrq->sa_data, 6);
590 /* set the bssid -- does this make sense when in AP mode? */
591 rvalue = mgt_set_request(priv, DOT11_OID_BSSID, 0, &bssid);
593 return (rvalue ? rvalue : -EINPROGRESS); /* Call commit handler */
599 prism54_get_wap(struct net_device *ndev, struct iw_request_info *info,
600 struct sockaddr *awrq, char *extra)
602 islpci_private *priv = netdev_priv(ndev);
606 rvalue = mgt_get_request(priv, DOT11_OID_BSSID, 0, NULL, &r);
608 memcpy(awrq->sa_data, r.ptr, 6);
609 awrq->sa_family = ARPHRD_ETHER;
616 prism54_set_scan(struct net_device *dev, struct iw_request_info *info,
617 struct iw_param *vwrq, char *extra)
619 /* hehe the device does this automagicaly */
623 /* a little helper that will translate our data into a card independent
624 * format that the Wireless Tools will understand. This was inspired by
625 * the "Aironet driver for 4500 and 4800 series cards" (GPL)
629 prism54_translate_bss(struct net_device *ndev, char *current_ev,
630 char *end_buf, struct obj_bss *bss, char noise)
632 struct iw_event iwe; /* Temporary buffer */
634 islpci_private *priv = netdev_priv(ndev);
636 /* The first entry must be the MAC address */
637 memcpy(iwe.u.ap_addr.sa_data, bss->address, 6);
638 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
641 iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
643 /* The following entries will be displayed in the same order we give them */
646 iwe.u.data.length = bss->ssid.length;
647 iwe.u.data.flags = 1;
648 iwe.cmd = SIOCGIWESSID;
649 current_ev = iwe_stream_add_point(current_ev, end_buf,
650 &iwe, bss->ssid.octets);
654 #define CAP_IBSS 0x02
655 #define CAP_CRYPT 0x10
658 cap = le16_to_cpu(bss->capinfo);
661 iwe.u.mode = IW_MODE_MASTER;
662 else if (cap & CAP_IBSS)
663 iwe.u.mode = IW_MODE_ADHOC;
664 iwe.cmd = SIOCGIWMODE;
667 iwe_stream_add_event(current_ev, end_buf, &iwe,
670 /* Encryption capability */
672 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
674 iwe.u.data.flags = IW_ENCODE_DISABLED;
675 iwe.u.data.length = 0;
676 iwe.cmd = SIOCGIWENCODE;
677 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, NULL);
679 /* Add frequency. (short) bss->channel is the frequency in MHz */
680 iwe.u.freq.m = bss->channel;
682 iwe.cmd = SIOCGIWFREQ;
684 iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
686 /* Add quality statistics */
687 iwe.u.qual.level = bss->rssi;
688 iwe.u.qual.noise = noise;
689 /* do a simple SNR for quality */
690 iwe.u.qual.qual = bss->rssi - noise;
693 iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
696 u8 wpa_ie[MAX_WPA_IE_LEN];
701 wpa_ie_len = prism54_wpa_ie_get(priv, bss->address, wpa_ie);
702 if (wpa_ie_len > 0 &&
703 (buf = kmalloc(wpa_ie_len * 2 + 10, GFP_ATOMIC))) {
705 p += sprintf(p, "wpa_ie=");
706 for (i = 0; i < wpa_ie_len; i++) {
707 p += sprintf(p, "%02x", wpa_ie[i]);
709 memset(&iwe, 0, sizeof (iwe));
710 iwe.cmd = IWEVCUSTOM;
711 iwe.u.data.length = strlen(buf);
712 current_ev = iwe_stream_add_point(current_ev, end_buf,
722 prism54_get_scan(struct net_device *ndev, struct iw_request_info *info,
723 struct iw_point *dwrq, char *extra)
725 islpci_private *priv = netdev_priv(ndev);
727 struct obj_bsslist *bsslist;
729 char *current_ev = extra;
732 if (islpci_get_state(priv) < PRV_STATE_INIT) {
733 /* device is not ready, fail gently */
738 /* first get the noise value. We will use it to report the link quality */
739 rvalue = mgt_get_request(priv, DOT11_OID_NOISEFLOOR, 0, NULL, &r);
742 /* Ask the device for a list of known bss. We can report at most
743 * IW_MAX_AP=64 to the range struct. But the device won't repport anything
744 * if you change the value of MAXBSS=24. Anyway 24 AP It is probably enough.
746 rvalue |= mgt_get_request(priv, DOT11_OID_BSSLIST, 0, NULL, &r);
749 /* ok now, scan the list and translate its info */
750 for (i = 0; i < min(IW_MAX_AP, (int) le32_to_cpu(bsslist->nr)); i++)
751 current_ev = prism54_translate_bss(ndev, current_ev,
752 extra + IW_SCAN_MAX_DATA,
753 &(bsslist->bsslist[i]),
756 dwrq->length = (current_ev - extra);
757 dwrq->flags = 0; /* todo */
763 prism54_set_essid(struct net_device *ndev, struct iw_request_info *info,
764 struct iw_point *dwrq, char *extra)
766 islpci_private *priv = netdev_priv(ndev);
767 struct obj_ssid essid;
769 memset(essid.octets, 0, 33);
771 /* Check if we were asked for `any' */
772 if (dwrq->flags && dwrq->length) {
773 if (dwrq->length > min(33, IW_ESSID_MAX_SIZE + 1))
775 essid.length = dwrq->length - 1;
776 memcpy(essid.octets, extra, dwrq->length);
780 if (priv->iw_mode != IW_MODE_MONITOR)
781 return mgt_set_request(priv, DOT11_OID_SSID, 0, &essid);
783 /* If in monitor mode, just save to mib */
784 mgt_set(priv, DOT11_OID_SSID, &essid);
790 prism54_get_essid(struct net_device *ndev, struct iw_request_info *info,
791 struct iw_point *dwrq, char *extra)
793 islpci_private *priv = netdev_priv(ndev);
794 struct obj_ssid *essid;
798 rvalue = mgt_get_request(priv, DOT11_OID_SSID, 0, NULL, &r);
802 dwrq->flags = 1; /* set ESSID to ON for Wireless Extensions */
803 /* if it is to big, trunk it */
804 dwrq->length = min(IW_ESSID_MAX_SIZE, essid->length + 1);
809 essid->octets[essid->length] = '\0';
810 memcpy(extra, essid->octets, dwrq->length);
816 /* Provides no functionality, just completes the ioctl. In essence this is a
817 * just a cosmetic ioctl.
820 prism54_set_nick(struct net_device *ndev, struct iw_request_info *info,
821 struct iw_point *dwrq, char *extra)
823 islpci_private *priv = netdev_priv(ndev);
825 if (dwrq->length > IW_ESSID_MAX_SIZE)
828 down_write(&priv->mib_sem);
829 memset(priv->nickname, 0, sizeof (priv->nickname));
830 memcpy(priv->nickname, extra, dwrq->length);
831 up_write(&priv->mib_sem);
837 prism54_get_nick(struct net_device *ndev, struct iw_request_info *info,
838 struct iw_point *dwrq, char *extra)
840 islpci_private *priv = netdev_priv(ndev);
844 down_read(&priv->mib_sem);
845 dwrq->length = strlen(priv->nickname) + 1;
846 memcpy(extra, priv->nickname, dwrq->length);
847 up_read(&priv->mib_sem);
852 /* Set the allowed Bitrates */
855 prism54_set_rate(struct net_device *ndev,
856 struct iw_request_info *info,
857 struct iw_param *vwrq, char *extra)
860 islpci_private *priv = netdev_priv(ndev);
866 if (vwrq->value == -1) {
867 /* auto mode. No limit. */
869 return mgt_set_request(priv, DOT11_OID_PROFILES, 0, &profile);
872 if((ret = mgt_get_request(priv, DOT11_OID_SUPPORTEDRATES, 0, NULL, &r)))
875 rate = (u32) (vwrq->value / 500000);
880 if(rate && (data[i] == rate)) {
883 if(vwrq->value == i) {
897 /* Now, check if we want a fixed or auto value */
905 printk("prism54 rate: ");
907 printk("%u ", data[i]);
913 ret = mgt_set_request(priv, DOT11_OID_PROFILES, 0, &profile);
914 ret |= mgt_set_request(priv, DOT11_OID_EXTENDEDRATES, 0, data);
915 ret |= mgt_set_request(priv, DOT11_OID_RATES, 0, data);
922 /* Get the current bit rate */
924 prism54_get_rate(struct net_device *ndev,
925 struct iw_request_info *info,
926 struct iw_param *vwrq, char *extra)
928 islpci_private *priv = netdev_priv(ndev);
933 /* Get the current bit rate */
934 if((rvalue = mgt_get_request(priv, GEN_OID_LINKSTATE, 0, NULL, &r)))
936 vwrq->value = r.u * 500000;
938 /* request the device for the enabled rates */
939 if((rvalue = mgt_get_request(priv, DOT11_OID_RATES, 0, NULL, &r)))
942 vwrq->fixed = (data[0] != 0) && (data[1] == 0);
949 prism54_set_rts(struct net_device *ndev, struct iw_request_info *info,
950 struct iw_param *vwrq, char *extra)
952 islpci_private *priv = netdev_priv(ndev);
954 return mgt_set_request(priv, DOT11_OID_RTSTHRESH, 0, &vwrq->value);
958 prism54_get_rts(struct net_device *ndev, struct iw_request_info *info,
959 struct iw_param *vwrq, char *extra)
961 islpci_private *priv = netdev_priv(ndev);
965 /* get the rts threshold */
966 rvalue = mgt_get_request(priv, DOT11_OID_RTSTHRESH, 0, NULL, &r);
973 prism54_set_frag(struct net_device *ndev, struct iw_request_info *info,
974 struct iw_param *vwrq, char *extra)
976 islpci_private *priv = netdev_priv(ndev);
978 return mgt_set_request(priv, DOT11_OID_FRAGTHRESH, 0, &vwrq->value);
982 prism54_get_frag(struct net_device *ndev, struct iw_request_info *info,
983 struct iw_param *vwrq, char *extra)
985 islpci_private *priv = netdev_priv(ndev);
989 rvalue = mgt_get_request(priv, DOT11_OID_FRAGTHRESH, 0, NULL, &r);
995 /* Here we have (min,max) = max retries for (small frames, big frames). Where
996 * big frame <=> bigger than the rts threshold
997 * small frame <=> smaller than the rts threshold
998 * This is not really the behavior expected by the wireless tool but it seems
999 * to be a common behavior in other drivers.
1001 * It seems that playing with this tends to hang the card -> DISABLED
1005 prism54_set_retry(struct net_device *ndev, struct iw_request_info *info,
1006 struct iw_param *vwrq, char *extra)
1008 islpci_private *priv = netdev_priv(ndev);
1009 u32 slimit = 0, llimit = 0; /* short and long limit */
1014 /* we cannot disable this feature */
1017 if (vwrq->flags & IW_RETRY_LIMIT) {
1018 if (vwrq->flags & IW_RETRY_MIN)
1019 slimit = vwrq->value;
1020 else if (vwrq->flags & IW_RETRY_MAX)
1021 llimit = vwrq->value;
1023 /* we are asked to set both */
1024 slimit = vwrq->value;
1025 llimit = vwrq->value;
1028 if (vwrq->flags & IW_RETRY_LIFETIME)
1029 /* Wireless tools use us unit while the device uses 1024 us unit */
1030 lifetime = vwrq->value / 1024;
1032 /* now set what is requested */
1036 mgt_set_request(priv, DOT11_OID_SHORTRETRIES, 0, &slimit);
1039 mgt_set_request(priv, DOT11_OID_LONGRETRIES, 0, &llimit);
1042 mgt_set_request(priv, DOT11_OID_MAXTXLIFETIME, 0,
1049 prism54_get_retry(struct net_device *ndev, struct iw_request_info *info,
1050 struct iw_param *vwrq, char *extra)
1052 islpci_private *priv = netdev_priv(ndev);
1055 vwrq->disabled = 0; /* It cannot be disabled */
1057 if ((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1058 /* we are asked for the life time */
1060 mgt_get_request(priv, DOT11_OID_MAXTXLIFETIME, 0, NULL, &r);
1061 vwrq->value = r.u * 1024;
1062 vwrq->flags = IW_RETRY_LIFETIME;
1063 } else if ((vwrq->flags & IW_RETRY_MAX)) {
1064 /* we are asked for the long retry limit */
1066 mgt_get_request(priv, DOT11_OID_LONGRETRIES, 0, NULL, &r);
1068 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
1070 /* default. get the short retry limit */
1072 mgt_get_request(priv, DOT11_OID_SHORTRETRIES, 0, NULL, &r);
1074 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
1081 prism54_set_encode(struct net_device *ndev, struct iw_request_info *info,
1082 struct iw_point *dwrq, char *extra)
1084 islpci_private *priv = netdev_priv(ndev);
1085 int rvalue = 0, force = 0;
1086 int authen = DOT11_AUTH_OS, invoke = 0, exunencrypt = 0;
1089 /* with the new API, it's impossible to get a NULL pointer.
1090 * New version of iwconfig set the IW_ENCODE_NOKEY flag
1091 * when no key is given, but older versions don't. */
1093 if (dwrq->length > 0) {
1094 /* we have a key to set */
1095 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1097 struct obj_key key = { DOT11_PRIV_WEP, 0, "" };
1099 /* get the current key index */
1100 rvalue = mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r);
1101 current_index = r.u;
1102 /* Verify that the key is not marked as invalid */
1103 if (!(dwrq->flags & IW_ENCODE_NOKEY)) {
1104 key.length = dwrq->length > sizeof (key.key) ?
1105 sizeof (key.key) : dwrq->length;
1106 memcpy(key.key, extra, key.length);
1107 if (key.length == 32)
1108 /* we want WPA-PSK */
1109 key.type = DOT11_PRIV_TKIP;
1110 if ((index < 0) || (index > 3))
1111 /* no index provided use the current one */
1112 index = current_index;
1114 /* now send the key to the card */
1116 mgt_set_request(priv, DOT11_OID_DEFKEYX, index,
1120 * If a valid key is set, encryption should be enabled
1121 * (user may turn it off later).
1122 * This is also how "iwconfig ethX key on" works
1124 if ((index == current_index) && (key.length > 0))
1127 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1128 if ((index >= 0) && (index <= 3)) {
1129 /* we want to set the key index */
1131 mgt_set_request(priv, DOT11_OID_DEFKEYID, 0,
1134 if (!dwrq->flags & IW_ENCODE_MODE) {
1135 /* we cannot do anything. Complain. */
1141 /* now read the flags */
1142 if (dwrq->flags & IW_ENCODE_DISABLED) {
1143 /* Encoding disabled,
1144 * authen = DOT11_AUTH_OS;
1146 * exunencrypt = 0; */
1148 if (dwrq->flags & IW_ENCODE_OPEN)
1149 /* Encode but accept non-encoded packets. No auth */
1151 if ((dwrq->flags & IW_ENCODE_RESTRICTED) || force) {
1152 /* Refuse non-encoded packets. Auth */
1153 authen = DOT11_AUTH_BOTH;
1157 /* do the change if requested */
1158 if ((dwrq->flags & IW_ENCODE_MODE) || force) {
1160 mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0, &authen);
1162 mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0, &invoke);
1164 mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0,
1171 prism54_get_encode(struct net_device *ndev, struct iw_request_info *info,
1172 struct iw_point *dwrq, char *extra)
1174 islpci_private *priv = netdev_priv(ndev);
1175 struct obj_key *key;
1176 u32 devindex, index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1177 u32 authen = 0, invoke = 0, exunencrypt = 0;
1181 /* first get the flags */
1182 rvalue = mgt_get_request(priv, DOT11_OID_AUTHENABLE, 0, NULL, &r);
1184 rvalue |= mgt_get_request(priv, DOT11_OID_PRIVACYINVOKED, 0, NULL, &r);
1186 rvalue |= mgt_get_request(priv, DOT11_OID_EXUNENCRYPTED, 0, NULL, &r);
1189 if (invoke && (authen == DOT11_AUTH_BOTH) && exunencrypt)
1190 dwrq->flags = IW_ENCODE_RESTRICTED;
1191 else if ((authen == DOT11_AUTH_OS) && !exunencrypt) {
1193 dwrq->flags = IW_ENCODE_OPEN;
1195 dwrq->flags = IW_ENCODE_DISABLED;
1197 /* The card should not work in this state */
1200 /* get the current device key index */
1201 rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r);
1203 /* Now get the key, return it */
1204 if ((index < 0) || (index > 3))
1205 /* no index provided, use the current one */
1207 rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYX, index, NULL, &r);
1209 dwrq->length = key->length;
1210 memcpy(extra, key->key, dwrq->length);
1212 /* return the used key index */
1213 dwrq->flags |= devindex + 1;
1219 prism54_get_txpower(struct net_device *ndev, struct iw_request_info *info,
1220 struct iw_param *vwrq, char *extra)
1222 islpci_private *priv = netdev_priv(ndev);
1226 rvalue = mgt_get_request(priv, OID_INL_OUTPUTPOWER, 0, NULL, &r);
1227 /* intersil firmware operates in 0.25 dBm (1/4 dBm) */
1228 vwrq->value = (s32)r.u / 4;
1230 /* radio is not turned of
1231 * btw: how is possible to turn off only the radio
1239 prism54_set_txpower(struct net_device *ndev, struct iw_request_info *info,
1240 struct iw_param *vwrq, char *extra)
1242 islpci_private *priv = netdev_priv(ndev);
1243 s32 u = vwrq->value;
1245 /* intersil firmware operates in 0.25 dBm (1/4) */
1247 if (vwrq->disabled) {
1248 /* don't know how to disable radio */
1250 "%s: %s() disabling radio is not yet supported.\n",
1251 priv->ndev->name, __FUNCTION__);
1253 } else if (vwrq->fixed)
1254 /* currently only fixed value is supported */
1255 return mgt_set_request(priv, OID_INL_OUTPUTPOWER, 0, &u);
1258 "%s: %s() auto power will be implemented later.\n",
1259 priv->ndev->name, __FUNCTION__);
1265 prism54_reset(struct net_device *ndev, struct iw_request_info *info,
1266 __u32 * uwrq, char *extra)
1268 islpci_reset(netdev_priv(ndev), 0);
1274 prism54_set_beacon(struct net_device *ndev, struct iw_request_info *info,
1275 __u32 * uwrq, char *extra)
1277 int rvalue = mgt_set_request((islpci_private *) netdev_priv(ndev),
1278 DOT11_OID_BEACONPERIOD, 0, uwrq);
1280 return (rvalue ? rvalue : -EINPROGRESS);
1284 prism54_get_beacon(struct net_device *ndev, struct iw_request_info *info,
1285 __u32 * uwrq, char *extra)
1291 mgt_get_request((islpci_private *) netdev_priv(ndev),
1292 DOT11_OID_BEACONPERIOD, 0, NULL, &r);
1299 prism54_acl_init(struct islpci_acl *acl)
1301 sema_init(&acl->sem, 1);
1302 INIT_LIST_HEAD(&acl->mac_list);
1304 acl->policy = MAC_POLICY_OPEN;
1308 prism54_clear_mac(struct islpci_acl *acl)
1310 struct list_head *ptr, *next;
1311 struct mac_entry *entry;
1313 if (down_interruptible(&acl->sem))
1316 if (acl->size == 0) {
1321 for (ptr = acl->mac_list.next, next = ptr->next;
1322 ptr != &acl->mac_list; ptr = next, next = ptr->next) {
1323 entry = list_entry(ptr, struct mac_entry, _list);
1332 prism54_acl_clean(struct islpci_acl *acl)
1334 prism54_clear_mac(acl);
1338 prism54_add_mac(struct net_device *ndev, struct iw_request_info *info,
1339 struct sockaddr *awrq, char *extra)
1341 islpci_private *priv = netdev_priv(ndev);
1342 struct islpci_acl *acl = &priv->acl;
1343 struct mac_entry *entry;
1344 struct sockaddr *addr = (struct sockaddr *) extra;
1346 if (addr->sa_family != ARPHRD_ETHER)
1349 entry = kmalloc(sizeof (struct mac_entry), GFP_KERNEL);
1353 memcpy(entry->addr, addr->sa_data, ETH_ALEN);
1355 if (down_interruptible(&acl->sem)) {
1357 return -ERESTARTSYS;
1359 list_add_tail(&entry->_list, &acl->mac_list);
1367 prism54_del_mac(struct net_device *ndev, struct iw_request_info *info,
1368 struct sockaddr *awrq, char *extra)
1370 islpci_private *priv = netdev_priv(ndev);
1371 struct islpci_acl *acl = &priv->acl;
1372 struct mac_entry *entry;
1373 struct list_head *ptr;
1374 struct sockaddr *addr = (struct sockaddr *) extra;
1376 if (addr->sa_family != ARPHRD_ETHER)
1379 if (down_interruptible(&acl->sem))
1380 return -ERESTARTSYS;
1381 for (ptr = acl->mac_list.next; ptr != &acl->mac_list; ptr = ptr->next) {
1382 entry = list_entry(ptr, struct mac_entry, _list);
1384 if (memcmp(entry->addr, addr->sa_data, ETH_ALEN) == 0) {
1397 prism54_get_mac(struct net_device *ndev, struct iw_request_info *info,
1398 struct iw_point *dwrq, char *extra)
1400 islpci_private *priv = netdev_priv(ndev);
1401 struct islpci_acl *acl = &priv->acl;
1402 struct mac_entry *entry;
1403 struct list_head *ptr;
1404 struct sockaddr *dst = (struct sockaddr *) extra;
1408 if (down_interruptible(&acl->sem))
1409 return -ERESTARTSYS;
1411 for (ptr = acl->mac_list.next; ptr != &acl->mac_list; ptr = ptr->next) {
1412 entry = list_entry(ptr, struct mac_entry, _list);
1414 memcpy(dst->sa_data, entry->addr, ETH_ALEN);
1415 dst->sa_family = ARPHRD_ETHER;
1423 /* Setting policy also clears the MAC acl, even if we don't change the defaut
1428 prism54_set_policy(struct net_device *ndev, struct iw_request_info *info,
1429 __u32 * uwrq, char *extra)
1431 islpci_private *priv = netdev_priv(ndev);
1432 struct islpci_acl *acl = &priv->acl;
1435 prism54_clear_mac(acl);
1437 if ((*uwrq < MAC_POLICY_OPEN) || (*uwrq > MAC_POLICY_REJECT))
1440 down_write(&priv->mib_sem);
1442 acl->policy = *uwrq;
1444 /* the ACL code needs an intermediate mlmeautolevel */
1445 if ((priv->iw_mode == IW_MODE_MASTER) &&
1446 (acl->policy != MAC_POLICY_OPEN))
1447 mlmeautolevel = DOT11_MLME_INTERMEDIATE;
1449 mlmeautolevel = CARD_DEFAULT_MLME_MODE;
1451 mlmeautolevel = DOT11_MLME_EXTENDED;
1452 mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &mlmeautolevel);
1453 /* restart the card with our new policy */
1455 up_write(&priv->mib_sem);
1461 prism54_get_policy(struct net_device *ndev, struct iw_request_info *info,
1462 __u32 * uwrq, char *extra)
1464 islpci_private *priv = netdev_priv(ndev);
1465 struct islpci_acl *acl = &priv->acl;
1467 *uwrq = acl->policy;
1472 /* Return 1 only if client should be accepted. */
1475 prism54_mac_accept(struct islpci_acl *acl, char *mac)
1477 struct list_head *ptr;
1478 struct mac_entry *entry;
1481 if (down_interruptible(&acl->sem))
1482 return -ERESTARTSYS;
1484 if (acl->policy == MAC_POLICY_OPEN) {
1489 for (ptr = acl->mac_list.next; ptr != &acl->mac_list; ptr = ptr->next) {
1490 entry = list_entry(ptr, struct mac_entry, _list);
1491 if (memcmp(entry->addr, mac, ETH_ALEN) == 0) {
1496 res = (acl->policy == MAC_POLICY_ACCEPT) ? !res : res;
1503 prism54_kick_all(struct net_device *ndev, struct iw_request_info *info,
1504 struct iw_point *dwrq, char *extra)
1506 struct obj_mlme *mlme;
1509 mlme = kmalloc(sizeof (struct obj_mlme), GFP_KERNEL);
1513 /* Tell the card to kick every client */
1514 mlme->id = cpu_to_le16(0);
1515 rvalue = mgt_set_request(netdev_priv(ndev), DOT11_OID_DISASSOCIATE, 0, mlme);
1522 prism54_kick_mac(struct net_device *ndev, struct iw_request_info *info,
1523 struct sockaddr *awrq, char *extra)
1525 struct obj_mlme *mlme;
1526 struct sockaddr *addr = (struct sockaddr *) extra;
1529 if (addr->sa_family != ARPHRD_ETHER)
1532 mlme = kmalloc(sizeof (struct obj_mlme), GFP_KERNEL);
1536 /* Tell the card to only kick the corresponding bastard */
1537 memcpy(mlme->address, addr->sa_data, ETH_ALEN);
1538 mlme->id = cpu_to_le16(-1);
1539 rvalue = mgt_set_request(netdev_priv(ndev), DOT11_OID_DISASSOCIATE, 0, mlme);
1546 /* Translate a TRAP oid into a wireless event. Called in islpci_mgt_receive. */
1549 format_event(islpci_private *priv, char *dest, const char *str,
1550 const struct obj_mlme *mlme, u16 *length, int error)
1552 const u8 *a = mlme->address;
1553 int n = snprintf(dest, IW_CUSTOM_MAX,
1554 "%s %s %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X %s",
1556 ((priv->iw_mode == IW_MODE_MASTER) ? "to" : "from"),
1557 a[0], a[1], a[2], a[3], a[4], a[5],
1558 (error ? (mlme->code ? " : REJECTED " : " : ACCEPTED ")
1560 BUG_ON(n > IW_CUSTOM_MAX);
1565 send_formatted_event(islpci_private *priv, const char *str,
1566 const struct obj_mlme *mlme, int error)
1568 union iwreq_data wrqu;
1570 wrqu.data.pointer = kmalloc(IW_CUSTOM_MAX, GFP_KERNEL);
1571 if (!wrqu.data.pointer)
1573 wrqu.data.length = 0;
1574 format_event(priv, wrqu.data.pointer, str, mlme, &wrqu.data.length,
1576 wireless_send_event(priv->ndev, IWEVCUSTOM, &wrqu, wrqu.data.pointer);
1577 kfree(wrqu.data.pointer);
1581 send_simple_event(islpci_private *priv, const char *str)
1583 union iwreq_data wrqu;
1584 int n = strlen(str);
1586 wrqu.data.pointer = kmalloc(IW_CUSTOM_MAX, GFP_KERNEL);
1587 if (!wrqu.data.pointer)
1589 BUG_ON(n > IW_CUSTOM_MAX);
1590 wrqu.data.length = n;
1591 strcpy(wrqu.data.pointer, str);
1592 wireless_send_event(priv->ndev, IWEVCUSTOM, &wrqu, wrqu.data.pointer);
1593 kfree(wrqu.data.pointer);
1597 link_changed(struct net_device *ndev, u32 bitrate)
1599 islpci_private *priv = netdev_priv(ndev);
1601 if (le32_to_cpu(bitrate)) {
1602 if (priv->iw_mode == IW_MODE_INFRA) {
1603 union iwreq_data uwrq;
1604 prism54_get_wap(ndev, NULL, (struct sockaddr *) &uwrq,
1606 wireless_send_event(ndev, SIOCGIWAP, &uwrq, NULL);
1608 send_simple_event(netdev_priv(ndev), "Link established");
1610 send_simple_event(netdev_priv(ndev), "Link lost");
1613 /* Beacon/ProbeResp payload header */
1614 struct ieee80211_beacon_phdr {
1618 } __attribute__ ((packed));
1620 #define WLAN_EID_GENERIC 0xdd
1621 static u8 wpa_oid[4] = { 0x00, 0x50, 0xf2, 1 };
1623 #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
1624 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
1627 prism54_wpa_ie_add(islpci_private *priv, u8 *bssid,
1628 u8 *wpa_ie, size_t wpa_ie_len)
1630 struct list_head *ptr;
1631 struct islpci_bss_wpa_ie *bss = NULL;
1633 if (wpa_ie_len > MAX_WPA_IE_LEN)
1634 wpa_ie_len = MAX_WPA_IE_LEN;
1636 if (down_interruptible(&priv->wpa_sem))
1639 /* try to use existing entry */
1640 list_for_each(ptr, &priv->bss_wpa_list) {
1641 bss = list_entry(ptr, struct islpci_bss_wpa_ie, list);
1642 if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0) {
1643 list_move(&bss->list, &priv->bss_wpa_list);
1650 /* add a new BSS entry; if max number of entries is already
1651 * reached, replace the least recently updated */
1652 if (priv->num_bss_wpa >= MAX_BSS_WPA_IE_COUNT) {
1653 bss = list_entry(priv->bss_wpa_list.prev,
1654 struct islpci_bss_wpa_ie, list);
1655 list_del(&bss->list);
1657 bss = kmalloc(sizeof (*bss), GFP_ATOMIC);
1659 priv->num_bss_wpa++;
1660 memset(bss, 0, sizeof (*bss));
1664 memcpy(bss->bssid, bssid, ETH_ALEN);
1665 list_add(&bss->list, &priv->bss_wpa_list);
1670 memcpy(bss->wpa_ie, wpa_ie, wpa_ie_len);
1671 bss->wpa_ie_len = wpa_ie_len;
1672 bss->last_update = jiffies;
1674 printk(KERN_DEBUG "Failed to add BSS WPA entry for " MACSTR
1675 "\n", MAC2STR(bssid));
1678 /* expire old entries from WPA list */
1679 while (priv->num_bss_wpa > 0) {
1680 bss = list_entry(priv->bss_wpa_list.prev,
1681 struct islpci_bss_wpa_ie, list);
1682 if (!time_after(jiffies, bss->last_update + 60 * HZ))
1685 list_del(&bss->list);
1686 priv->num_bss_wpa--;
1694 prism54_wpa_ie_get(islpci_private *priv, u8 *bssid, u8 *wpa_ie)
1696 struct list_head *ptr;
1697 struct islpci_bss_wpa_ie *bss = NULL;
1700 if (down_interruptible(&priv->wpa_sem))
1703 list_for_each(ptr, &priv->bss_wpa_list) {
1704 bss = list_entry(ptr, struct islpci_bss_wpa_ie, list);
1705 if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0)
1710 len = bss->wpa_ie_len;
1711 memcpy(wpa_ie, bss->wpa_ie, len);
1719 prism54_wpa_ie_init(islpci_private *priv)
1721 INIT_LIST_HEAD(&priv->bss_wpa_list);
1722 sema_init(&priv->wpa_sem, 1);
1726 prism54_wpa_ie_clean(islpci_private *priv)
1728 struct list_head *ptr, *n;
1730 list_for_each_safe(ptr, n, &priv->bss_wpa_list) {
1731 struct islpci_bss_wpa_ie *bss;
1732 bss = list_entry(ptr, struct islpci_bss_wpa_ie, list);
1738 prism54_process_bss_data(islpci_private *priv, u32 oid, u8 *addr,
1739 u8 *payload, size_t len)
1741 struct ieee80211_beacon_phdr *hdr;
1747 hdr = (struct ieee80211_beacon_phdr *) payload;
1748 pos = (u8 *) (hdr + 1);
1749 end = payload + len;
1751 if (pos + 2 + pos[1] > end) {
1752 printk(KERN_DEBUG "Parsing Beacon/ProbeResp failed "
1753 "for " MACSTR "\n", MAC2STR(addr));
1756 if (pos[0] == WLAN_EID_GENERIC && pos[1] >= 4 &&
1757 memcmp(pos + 2, wpa_oid, 4) == 0) {
1758 prism54_wpa_ie_add(priv, addr, pos, pos[1] + 2);
1766 handle_request(islpci_private *priv, struct obj_mlme *mlme, enum oid_num_t oid)
1768 if (((le16_to_cpu(mlme->state) == DOT11_STATE_AUTHING) ||
1769 (le16_to_cpu(mlme->state) == DOT11_STATE_ASSOCING))
1770 && mgt_mlme_answer(priv)) {
1771 /* Someone is requesting auth and we must respond. Just send back
1772 * the trap with error code set accordingly.
1774 mlme->code = cpu_to_le16(prism54_mac_accept(&priv->acl,
1777 mgt_set_request(priv, oid, 0, mlme);
1782 prism54_process_trap_helper(islpci_private *priv, enum oid_num_t oid,
1785 struct obj_mlme *mlme = (struct obj_mlme *) data;
1787 u8 *payload, *pos = (u8 *) (mlme + 1);
1789 len = pos[0] | (pos[1] << 8); /* little endian data length */
1792 /* I think all trapable objects are listed here.
1793 * Some oids have a EX version. The difference is that they are emitted
1794 * in DOT11_MLME_EXTENDED mode (set with DOT11_OID_MLMEAUTOLEVEL)
1796 * The few events already defined by the wireless tools are not really
1797 * suited. We use the more flexible custom event facility.
1802 case GEN_OID_LINKSTATE:
1803 link_changed(priv->ndev, (u32) *data);
1806 case DOT11_OID_MICFAILURE:
1807 send_simple_event(priv, "Mic failure");
1810 case DOT11_OID_DEAUTHENTICATE:
1811 send_formatted_event(priv, "DeAuthenticate request", mlme, 0);
1814 case DOT11_OID_AUTHENTICATE:
1815 handle_request(priv, mlme, oid);
1816 send_formatted_event(priv, "Authenticate request", mlme, 1);
1819 case DOT11_OID_DISASSOCIATE:
1820 send_formatted_event(priv, "Disassociate request", mlme, 0);
1823 case DOT11_OID_ASSOCIATE:
1824 handle_request(priv, mlme, oid);
1825 send_formatted_event(priv, "Associate request", mlme, 1);
1828 case DOT11_OID_REASSOCIATE:
1829 handle_request(priv, mlme, oid);
1830 send_formatted_event(priv, "ReAssociate request", mlme, 1);
1833 case DOT11_OID_BEACON:
1834 prism54_process_bss_data(priv, oid, mlme->address,
1836 send_formatted_event(priv,
1837 "Received a beacon from an unkown AP",
1841 case DOT11_OID_PROBE:
1842 /* we received a probe from a client. */
1843 prism54_process_bss_data(priv, oid, mlme->address,
1845 send_formatted_event(priv, "Received a probe from client", mlme,
1849 /* Note : the following should never happen since we don't run the card in
1851 * Note : "mlme" is actually a "struct obj_mlmeex *" here, but this
1852 * is backward compatible layout-wise with "struct obj_mlme".
1855 case DOT11_OID_DEAUTHENTICATEEX:
1856 send_formatted_event(priv, "DeAuthenticate request", mlme, 0);
1859 case DOT11_OID_AUTHENTICATEEX:
1860 handle_request(priv, mlme, oid);
1861 send_formatted_event(priv, "Authenticate request", mlme, 1);
1864 case DOT11_OID_DISASSOCIATEEX:
1865 send_formatted_event(priv, "Disassociate request", mlme, 0);
1868 case DOT11_OID_ASSOCIATEEX:
1869 handle_request(priv, mlme, oid);
1870 send_formatted_event(priv, "Associate request", mlme, 1);
1873 case DOT11_OID_REASSOCIATEEX:
1874 handle_request(priv, mlme, oid);
1875 send_formatted_event(priv, "Reassociate request", mlme, 1);
1886 * Process a device trap. This is called via schedule_work(), outside of
1887 * interrupt context, no locks held.
1890 prism54_process_trap(void *data)
1892 struct islpci_mgmtframe *frame = data;
1893 struct net_device *ndev = frame->ndev;
1894 enum oid_num_t n = mgt_oidtonum(frame->header->oid);
1896 prism54_process_trap_helper(netdev_priv(ndev), n, frame->data);
1897 islpci_mgt_release(frame);
1901 prism54_set_mac_address(struct net_device *ndev, void *addr)
1903 islpci_private *priv = netdev_priv(ndev);
1906 if (ndev->addr_len != 6)
1908 ret = mgt_set_request(priv, GEN_OID_MACADDRESS, 0,
1909 &((struct sockaddr *) addr)->sa_data);
1911 memcpy(priv->ndev->dev_addr,
1912 &((struct sockaddr *) addr)->sa_data, 6);
1918 prism54_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
1920 /* should we really support this old stuff ? */
1925 prism54_set_wpa(struct net_device *ndev, struct iw_request_info *info,
1926 __u32 * uwrq, char *extra)
1928 islpci_private *priv = netdev_priv(ndev);
1930 down_write(&priv->mib_sem);
1934 u32 l = DOT11_MLME_EXTENDED;
1935 mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &l);
1937 /* restart the card with new level. Needed ? */
1939 up_write(&priv->mib_sem);
1945 prism54_get_wpa(struct net_device *ndev, struct iw_request_info *info,
1946 __u32 * uwrq, char *extra)
1948 islpci_private *priv = netdev_priv(ndev);
1954 prism54_set_maxframeburst(struct net_device *ndev, struct iw_request_info *info,
1955 __u32 *uwrq, char *extra)
1957 islpci_private *priv = netdev_priv(ndev);
1960 max_burst = (*uwrq) ? *uwrq : CARD_DEFAULT_MAXFRAMEBURST;
1961 mgt_set_request(priv, DOT11_OID_MAXFRAMEBURST, 0, &max_burst);
1963 return -EINPROGRESS; /* Call commit handler */
1967 prism54_get_maxframeburst(struct net_device *ndev, struct iw_request_info *info,
1968 __u32 *uwrq, char *extra)
1970 islpci_private *priv = netdev_priv(ndev);
1974 rvalue = mgt_get_request(priv, DOT11_OID_MAXFRAMEBURST, 0, NULL, &r);
1981 prism54_set_profile(struct net_device *ndev, struct iw_request_info *info,
1982 __u32 *uwrq, char *extra)
1984 islpci_private *priv = netdev_priv(ndev);
1987 profile = (*uwrq) ? *uwrq : CARD_DEFAULT_PROFILE;
1988 mgt_set_request(priv, DOT11_OID_PROFILES, 0, &profile);
1990 return -EINPROGRESS; /* Call commit handler */
1994 prism54_get_profile(struct net_device *ndev, struct iw_request_info *info,
1995 __u32 *uwrq, char *extra)
1997 islpci_private *priv = netdev_priv(ndev);
2001 rvalue = mgt_get_request(priv, DOT11_OID_PROFILES, 0, NULL, &r);
2008 prism54_oid(struct net_device *ndev, struct iw_request_info *info,
2009 __u32 *uwrq, char *extra)
2011 islpci_private *priv = netdev_priv(ndev);
2013 priv->priv_oid = *uwrq;
2014 printk("%s: oid 0x%08X\n", ndev->name, *uwrq);
2020 prism54_get_oid(struct net_device *ndev, struct iw_request_info *info,
2021 struct iw_point *data, char *extra)
2023 islpci_private *priv = netdev_priv(ndev);
2024 struct islpci_mgmtframe *response = NULL;
2025 int ret = -EIO, response_op = PIMFOR_OP_ERROR;
2027 printk("%s: get_oid 0x%08X\n", ndev->name, priv->priv_oid);
2030 if (islpci_get_state(priv) >= PRV_STATE_INIT) {
2031 ret = islpci_mgt_transaction(priv->ndev, PIMFOR_OP_GET, priv->priv_oid, extra, 256, &response);
2032 response_op = response->header->operation;
2033 printk("%s: ret: %i\n", ndev->name, ret);
2034 printk("%s: response_op: %i\n", ndev->name, response_op);
2035 if (ret || !response || response->header->operation == PIMFOR_OP_ERROR) {
2037 islpci_mgt_release(response);
2039 printk("%s: EIO\n", ndev->name);
2043 data->length = response->header->length;
2044 memcpy(extra, response->data, data->length);
2045 islpci_mgt_release(response);
2046 printk("%s: len: %i\n", ndev->name, data->length);
2054 prism54_set_oid(struct net_device *ndev, struct iw_request_info *info,
2055 struct iw_point *data, char *extra)
2057 islpci_private *priv = netdev_priv(ndev);
2058 struct islpci_mgmtframe *response = NULL;
2059 int ret = 0, response_op = PIMFOR_OP_ERROR;
2061 printk("%s: set_oid 0x%08X\tlen: %d\n", ndev->name, priv->priv_oid, data->length);
2063 if (islpci_get_state(priv) >= PRV_STATE_INIT) {
2064 ret = islpci_mgt_transaction(priv->ndev, PIMFOR_OP_SET, priv->priv_oid, extra, data->length, &response);
2065 printk("%s: ret: %i\n", ndev->name, ret);
2067 response_op = response->header->operation;
2068 printk("%s: response_op: %i\n", ndev->name, response_op);
2069 islpci_mgt_release(response);
2071 if (ret || response_op == PIMFOR_OP_ERROR) {
2072 printk("%s: EIO\n", ndev->name);
2080 static const iw_handler prism54_handler[] = {
2081 (iw_handler) prism54_commit, /* SIOCSIWCOMMIT */
2082 (iw_handler) prism54_get_name, /* SIOCGIWNAME */
2083 (iw_handler) NULL, /* SIOCSIWNWID */
2084 (iw_handler) NULL, /* SIOCGIWNWID */
2085 (iw_handler) prism54_set_freq, /* SIOCSIWFREQ */
2086 (iw_handler) prism54_get_freq, /* SIOCGIWFREQ */
2087 (iw_handler) prism54_set_mode, /* SIOCSIWMODE */
2088 (iw_handler) prism54_get_mode, /* SIOCGIWMODE */
2089 (iw_handler) prism54_set_sens, /* SIOCSIWSENS */
2090 (iw_handler) prism54_get_sens, /* SIOCGIWSENS */
2091 (iw_handler) NULL, /* SIOCSIWRANGE */
2092 (iw_handler) prism54_get_range, /* SIOCGIWRANGE */
2093 (iw_handler) NULL, /* SIOCSIWPRIV */
2094 (iw_handler) NULL, /* SIOCGIWPRIV */
2095 (iw_handler) NULL, /* SIOCSIWSTATS */
2096 (iw_handler) NULL, /* SIOCGIWSTATS */
2097 iw_handler_set_spy, /* SIOCSIWSPY */
2098 iw_handler_get_spy, /* SIOCGIWSPY */
2099 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2100 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2101 (iw_handler) prism54_set_wap, /* SIOCSIWAP */
2102 (iw_handler) prism54_get_wap, /* SIOCGIWAP */
2103 (iw_handler) NULL, /* -- hole -- */
2104 (iw_handler) NULL, /* SIOCGIWAPLIST depreciated */
2105 (iw_handler) prism54_set_scan, /* SIOCSIWSCAN */
2106 (iw_handler) prism54_get_scan, /* SIOCGIWSCAN */
2107 (iw_handler) prism54_set_essid, /* SIOCSIWESSID */
2108 (iw_handler) prism54_get_essid, /* SIOCGIWESSID */
2109 (iw_handler) prism54_set_nick, /* SIOCSIWNICKN */
2110 (iw_handler) prism54_get_nick, /* SIOCGIWNICKN */
2111 (iw_handler) NULL, /* -- hole -- */
2112 (iw_handler) NULL, /* -- hole -- */
2113 (iw_handler) prism54_set_rate, /* SIOCSIWRATE */
2114 (iw_handler) prism54_get_rate, /* SIOCGIWRATE */
2115 (iw_handler) prism54_set_rts, /* SIOCSIWRTS */
2116 (iw_handler) prism54_get_rts, /* SIOCGIWRTS */
2117 (iw_handler) prism54_set_frag, /* SIOCSIWFRAG */
2118 (iw_handler) prism54_get_frag, /* SIOCGIWFRAG */
2119 (iw_handler) prism54_set_txpower, /* SIOCSIWTXPOW */
2120 (iw_handler) prism54_get_txpower, /* SIOCGIWTXPOW */
2121 (iw_handler) prism54_set_retry, /* SIOCSIWRETRY */
2122 (iw_handler) prism54_get_retry, /* SIOCGIWRETRY */
2123 (iw_handler) prism54_set_encode, /* SIOCSIWENCODE */
2124 (iw_handler) prism54_get_encode, /* SIOCGIWENCODE */
2125 (iw_handler) NULL, /* SIOCSIWPOWER */
2126 (iw_handler) NULL, /* SIOCGIWPOWER */
2129 /* The low order bit identify a SET (0) or a GET (1) ioctl. */
2131 #define PRISM54_RESET SIOCIWFIRSTPRIV
2132 #define PRISM54_GET_BEACON SIOCIWFIRSTPRIV+1
2133 #define PRISM54_SET_BEACON SIOCIWFIRSTPRIV+2
2134 #define PRISM54_GET_POLICY SIOCIWFIRSTPRIV+3
2135 #define PRISM54_SET_POLICY SIOCIWFIRSTPRIV+4
2136 #define PRISM54_GET_MAC SIOCIWFIRSTPRIV+5
2137 #define PRISM54_ADD_MAC SIOCIWFIRSTPRIV+6
2139 #define PRISM54_DEL_MAC SIOCIWFIRSTPRIV+8
2141 #define PRISM54_KICK_MAC SIOCIWFIRSTPRIV+10
2143 #define PRISM54_KICK_ALL SIOCIWFIRSTPRIV+12
2145 #define PRISM54_GET_WPA SIOCIWFIRSTPRIV+13
2146 #define PRISM54_SET_WPA SIOCIWFIRSTPRIV+14
2148 #define PRISM54_OID SIOCIWFIRSTPRIV+16
2149 #define PRISM54_GET_OID SIOCIWFIRSTPRIV+17
2150 #define PRISM54_SET_OID SIOCIWFIRSTPRIV+18
2152 static const struct iw_priv_args prism54_private_args[] = {
2153 /*{ cmd, set_args, get_args, name } */
2154 {PRISM54_RESET, 0, 0, "reset"},
2155 {PRISM54_GET_BEACON, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2157 {PRISM54_SET_BEACON, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0,
2159 {PRISM54_GET_POLICY, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2161 {PRISM54_SET_POLICY, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0,
2163 {PRISM54_GET_MAC, 0, IW_PRIV_TYPE_ADDR | 64, "getMac"},
2164 {PRISM54_ADD_MAC, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0,
2166 {PRISM54_DEL_MAC, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0,
2168 {PRISM54_KICK_MAC, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0,
2170 {PRISM54_KICK_ALL, 0, 0, "kickAll"},
2171 {PRISM54_GET_WPA, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2173 {PRISM54_SET_WPA, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0,
2175 {PRISM54_OID, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "oid"},
2176 {PRISM54_GET_OID, 0, IW_PRIV_TYPE_BYTE | 256, "get_oid"},
2177 {PRISM54_SET_OID, IW_PRIV_TYPE_BYTE | 256, 0, "set_oid"},
2180 static const iw_handler prism54_private_handler[] = {
2181 (iw_handler) prism54_reset,
2182 (iw_handler) prism54_get_beacon,
2183 (iw_handler) prism54_set_beacon,
2184 (iw_handler) prism54_get_policy,
2185 (iw_handler) prism54_set_policy,
2186 (iw_handler) prism54_get_mac,
2187 (iw_handler) prism54_add_mac,
2189 (iw_handler) prism54_del_mac,
2191 (iw_handler) prism54_kick_mac,
2193 (iw_handler) prism54_kick_all,
2194 (iw_handler) prism54_get_wpa,
2195 (iw_handler) prism54_set_wpa,
2197 (iw_handler) prism54_oid,
2198 (iw_handler) prism54_get_oid,
2199 (iw_handler) prism54_set_oid,
2202 const struct iw_handler_def prism54_handler_def = {
2203 .num_standard = sizeof (prism54_handler) / sizeof (iw_handler),
2204 .num_private = sizeof (prism54_private_handler) / sizeof (iw_handler),
2206 sizeof (prism54_private_args) / sizeof (struct iw_priv_args),
2207 .standard = (iw_handler *) prism54_handler,
2208 .private = (iw_handler *) prism54_private_handler,
2209 .private_args = (struct iw_priv_args *) prism54_private_args,