blob: 286325ca3293d491f3005aa1f726ca0775645f78 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 *
3 * Copyright (C) 2002 Intersil Americas Inc.
4 * (C) 2003,2004 Aurelien Alleaume <slts@free.fr>
5 * (C) 2003 Herbert Valerio Riedel <hvr@gnu.org>
6 * (C) 2003 Luis R. Rodriguez <mcgrof@ruslug.rutgers.edu>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/module.h>
24#include <linux/kernel.h>
25#include <linux/if_arp.h>
26#include <linux/pci.h>
27
28#include <asm/uaccess.h>
29
30#include "prismcompat.h"
31#include "isl_ioctl.h"
32#include "islpci_mgt.h"
33#include "isl_oid.h" /* additional types and defs for isl38xx fw */
34#include "oid_mgt.h"
35
36#include <net/iw_handler.h> /* New driver API */
37
Dan Williamseab411f2006-07-17 21:21:47 -040038#define KEY_SIZE_WEP104 13 /* 104/128-bit WEP keys */
39#define KEY_SIZE_WEP40 5 /* 40/64-bit WEP keys */
40/* KEY_SIZE_TKIP should match isl_oid.h, struct obj_key.key[] size */
41#define KEY_SIZE_TKIP 32 /* TKIP keys */
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Dan Williamseab411f2006-07-17 21:21:47 -040043static void prism54_wpa_bss_ie_add(islpci_private *priv, u8 *bssid,
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 u8 *wpa_ie, size_t wpa_ie_len);
Dan Williamseab411f2006-07-17 21:21:47 -040045static size_t prism54_wpa_bss_ie_get(islpci_private *priv, u8 *bssid, u8 *wpa_ie);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046static int prism54_set_wpa(struct net_device *, struct iw_request_info *,
47 __u32 *, char *);
48
Jean Tourrilhesbd6dd752006-08-29 18:19:23 -070049/* In 500 kbps */
50static const unsigned char scan_rate_list[] = { 2, 4, 11, 22,
51 12, 18, 24, 36,
52 48, 72, 96, 108 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54/**
55 * prism54_mib_mode_helper - MIB change mode helper function
56 * @mib: the &struct islpci_mib object to modify
57 * @iw_mode: new mode (%IW_MODE_*)
58 *
59 * This is a helper function, hence it does not lock. Make sure
60 * caller deals with locking *if* necessary. This function sets the
61 * mode-dependent mib values and does the mapping of the Linux
62 * Wireless API modes to Device firmware modes. It also checks for
63 * correct valid Linux wireless modes.
64 */
65static int
66prism54_mib_mode_helper(islpci_private *priv, u32 iw_mode)
67{
68 u32 config = INL_CONFIG_MANUALRUN;
69 u32 mode, bsstype;
70
71 /* For now, just catch early the Repeater and Secondary modes here */
72 if (iw_mode == IW_MODE_REPEAT || iw_mode == IW_MODE_SECOND) {
73 printk(KERN_DEBUG
74 "%s(): Sorry, Repeater mode and Secondary mode "
75 "are not yet supported by this driver.\n", __FUNCTION__);
76 return -EINVAL;
77 }
78
79 priv->iw_mode = iw_mode;
80
81 switch (iw_mode) {
82 case IW_MODE_AUTO:
83 mode = INL_MODE_CLIENT;
84 bsstype = DOT11_BSSTYPE_ANY;
85 break;
86 case IW_MODE_ADHOC:
87 mode = INL_MODE_CLIENT;
88 bsstype = DOT11_BSSTYPE_IBSS;
89 break;
90 case IW_MODE_INFRA:
91 mode = INL_MODE_CLIENT;
92 bsstype = DOT11_BSSTYPE_INFRA;
93 break;
94 case IW_MODE_MASTER:
95 mode = INL_MODE_AP;
96 bsstype = DOT11_BSSTYPE_INFRA;
97 break;
98 case IW_MODE_MONITOR:
99 mode = INL_MODE_PROMISCUOUS;
100 bsstype = DOT11_BSSTYPE_ANY;
101 config |= INL_CONFIG_RXANNEX;
102 break;
103 default:
104 return -EINVAL;
105 }
106
107 if (init_wds)
108 config |= INL_CONFIG_WDS;
109 mgt_set(priv, DOT11_OID_BSSTYPE, &bsstype);
110 mgt_set(priv, OID_INL_CONFIG, &config);
111 mgt_set(priv, OID_INL_MODE, &mode);
112
113 return 0;
114}
115
116/**
117 * prism54_mib_init - fill MIB cache with defaults
118 *
119 * this function initializes the struct given as @mib with defaults,
120 * of which many are retrieved from the global module parameter
121 * variables.
122 */
123
124void
125prism54_mib_init(islpci_private *priv)
126{
127 u32 channel, authen, wep, filter, dot1x, mlme, conformance, power, mode;
128 struct obj_buffer psm_buffer = {
129 .size = PSM_BUFFER_SIZE,
130 .addr = priv->device_psm_buffer
131 };
132
133 channel = CARD_DEFAULT_CHANNEL;
134 authen = CARD_DEFAULT_AUTHEN;
135 wep = CARD_DEFAULT_WEP;
136 filter = CARD_DEFAULT_FILTER; /* (0) Do not filter un-encrypted data */
137 dot1x = CARD_DEFAULT_DOT1X;
138 mlme = CARD_DEFAULT_MLME_MODE;
139 conformance = CARD_DEFAULT_CONFORMANCE;
140 power = 127;
141 mode = CARD_DEFAULT_IW_MODE;
142
143 mgt_set(priv, DOT11_OID_CHANNEL, &channel);
144 mgt_set(priv, DOT11_OID_AUTHENABLE, &authen);
145 mgt_set(priv, DOT11_OID_PRIVACYINVOKED, &wep);
146 mgt_set(priv, DOT11_OID_PSMBUFFER, &psm_buffer);
147 mgt_set(priv, DOT11_OID_EXUNENCRYPTED, &filter);
148 mgt_set(priv, DOT11_OID_DOT1XENABLE, &dot1x);
149 mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &mlme);
150 mgt_set(priv, OID_INL_DOT11D_CONFORMANCE, &conformance);
151 mgt_set(priv, OID_INL_OUTPUTPOWER, &power);
152
153 /* This sets all of the mode-dependent values */
154 prism54_mib_mode_helper(priv, mode);
155}
156
157/* this will be executed outside of atomic context thanks to
158 * schedule_work(), thus we can as well use sleeping semaphore
159 * locking */
160void
161prism54_update_stats(islpci_private *priv)
162{
163 char *data;
164 int j;
165 struct obj_bss bss, *bss2;
166 union oid_res_t r;
167
168 if (down_interruptible(&priv->stats_sem))
169 return;
170
171/* Noise floor.
172 * I'm not sure if the unit is dBm.
173 * Note : If we are not connected, this value seems to be irrelevant. */
174
175 mgt_get_request(priv, DOT11_OID_NOISEFLOOR, 0, NULL, &r);
176 priv->local_iwstatistics.qual.noise = r.u;
177
178/* Get the rssi of the link. To do this we need to retrieve a bss. */
179
180 /* First get the MAC address of the AP we are associated with. */
181 mgt_get_request(priv, DOT11_OID_BSSID, 0, NULL, &r);
182 data = r.ptr;
183
184 /* copy this MAC to the bss */
185 memcpy(bss.address, data, 6);
186 kfree(data);
187
188 /* now ask for the corresponding bss */
189 j = mgt_get_request(priv, DOT11_OID_BSSFIND, 0, (void *) &bss, &r);
190 bss2 = r.ptr;
191 /* report the rssi and use it to calculate
192 * link quality through a signal-noise
193 * ratio */
194 priv->local_iwstatistics.qual.level = bss2->rssi;
195 priv->local_iwstatistics.qual.qual =
196 bss2->rssi - priv->iwstatistics.qual.noise;
197
198 kfree(bss2);
199
200 /* report that the stats are new */
201 priv->local_iwstatistics.qual.updated = 0x7;
202
203/* Rx : unable to decrypt the MPDU */
204 mgt_get_request(priv, DOT11_OID_PRIVRXFAILED, 0, NULL, &r);
205 priv->local_iwstatistics.discard.code = r.u;
206
207/* Tx : Max MAC retries num reached */
208 mgt_get_request(priv, DOT11_OID_MPDUTXFAILED, 0, NULL, &r);
209 priv->local_iwstatistics.discard.retries = r.u;
210
211 up(&priv->stats_sem);
212
213 return;
214}
215
216struct iw_statistics *
217prism54_get_wireless_stats(struct net_device *ndev)
218{
219 islpci_private *priv = netdev_priv(ndev);
220
221 /* If the stats are being updated return old data */
222 if (down_trylock(&priv->stats_sem) == 0) {
223 memcpy(&priv->iwstatistics, &priv->local_iwstatistics,
224 sizeof (struct iw_statistics));
225 /* They won't be marked updated for the next time */
226 priv->local_iwstatistics.qual.updated = 0;
227 up(&priv->stats_sem);
228 } else
229 priv->iwstatistics.qual.updated = 0;
230
231 /* Update our wireless stats, but do not schedule to often
232 * (max 1 HZ) */
233 if ((priv->stats_timestamp == 0) ||
234 time_after(jiffies, priv->stats_timestamp + 1 * HZ)) {
235 schedule_work(&priv->stats_work);
236 priv->stats_timestamp = jiffies;
237 }
238
239 return &priv->iwstatistics;
240}
241
242static int
243prism54_commit(struct net_device *ndev, struct iw_request_info *info,
244 char *cwrq, char *extra)
245{
246 islpci_private *priv = netdev_priv(ndev);
247
248 /* simply re-set the last set SSID, this should commit most stuff */
249
250 /* Commit in Monitor mode is not necessary, also setting essid
251 * in Monitor mode does not make sense and isn't allowed for this
252 * device's firmware */
253 if (priv->iw_mode != IW_MODE_MONITOR)
254 return mgt_set_request(priv, DOT11_OID_SSID, 0, NULL);
255 return 0;
256}
257
258static int
259prism54_get_name(struct net_device *ndev, struct iw_request_info *info,
260 char *cwrq, char *extra)
261{
262 islpci_private *priv = netdev_priv(ndev);
263 char *capabilities;
264 union oid_res_t r;
265 int rvalue;
266
267 if (islpci_get_state(priv) < PRV_STATE_INIT) {
268 strncpy(cwrq, "NOT READY!", IFNAMSIZ);
269 return 0;
270 }
271 rvalue = mgt_get_request(priv, OID_INL_PHYCAPABILITIES, 0, NULL, &r);
272
273 switch (r.u) {
274 case INL_PHYCAP_5000MHZ:
275 capabilities = "IEEE 802.11a/b/g";
276 break;
277 case INL_PHYCAP_FAA:
278 capabilities = "IEEE 802.11b/g - FAA Support";
279 break;
280 case INL_PHYCAP_2400MHZ:
281 default:
282 capabilities = "IEEE 802.11b/g"; /* Default */
283 break;
284 }
285 strncpy(cwrq, capabilities, IFNAMSIZ);
286 return rvalue;
287}
288
289static int
290prism54_set_freq(struct net_device *ndev, struct iw_request_info *info,
291 struct iw_freq *fwrq, char *extra)
292{
293 islpci_private *priv = netdev_priv(ndev);
294 int rvalue;
295 u32 c;
296
297 if (fwrq->m < 1000)
298 /* we have a channel number */
299 c = fwrq->m;
300 else
301 c = (fwrq->e == 1) ? channel_of_freq(fwrq->m / 100000) : 0;
302
303 rvalue = c ? mgt_set_request(priv, DOT11_OID_CHANNEL, 0, &c) : -EINVAL;
304
305 /* Call commit handler */
306 return (rvalue ? rvalue : -EINPROGRESS);
307}
308
309static int
310prism54_get_freq(struct net_device *ndev, struct iw_request_info *info,
311 struct iw_freq *fwrq, char *extra)
312{
313 islpci_private *priv = netdev_priv(ndev);
314 union oid_res_t r;
315 int rvalue;
316
317 rvalue = mgt_get_request(priv, DOT11_OID_CHANNEL, 0, NULL, &r);
318 fwrq->i = r.u;
319 rvalue |= mgt_get_request(priv, DOT11_OID_FREQUENCY, 0, NULL, &r);
320 fwrq->m = r.u;
321 fwrq->e = 3;
322
323 return rvalue;
324}
325
326static int
327prism54_set_mode(struct net_device *ndev, struct iw_request_info *info,
328 __u32 * uwrq, char *extra)
329{
330 islpci_private *priv = netdev_priv(ndev);
331 u32 mlmeautolevel = CARD_DEFAULT_MLME_MODE;
332
333 /* Let's see if the user passed a valid Linux Wireless mode */
334 if (*uwrq > IW_MODE_MONITOR || *uwrq < IW_MODE_AUTO) {
335 printk(KERN_DEBUG
336 "%s: %s() You passed a non-valid init_mode.\n",
337 priv->ndev->name, __FUNCTION__);
338 return -EINVAL;
339 }
340
341 down_write(&priv->mib_sem);
342
343 if (prism54_mib_mode_helper(priv, *uwrq)) {
344 up_write(&priv->mib_sem);
345 return -EOPNOTSUPP;
346 }
347
348 /* the ACL code needs an intermediate mlmeautolevel. The wpa stuff an
349 * extended one.
350 */
351 if ((*uwrq == IW_MODE_MASTER) && (priv->acl.policy != MAC_POLICY_OPEN))
352 mlmeautolevel = DOT11_MLME_INTERMEDIATE;
353 if (priv->wpa)
354 mlmeautolevel = DOT11_MLME_EXTENDED;
355
356 mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &mlmeautolevel);
357
358 if (mgt_commit(priv)) {
359 up_write(&priv->mib_sem);
360 return -EIO;
361 }
362 priv->ndev->type = (priv->iw_mode == IW_MODE_MONITOR)
363 ? priv->monitor_type : ARPHRD_ETHER;
364 up_write(&priv->mib_sem);
365
366 return 0;
367}
368
369/* Use mib cache */
370static int
371prism54_get_mode(struct net_device *ndev, struct iw_request_info *info,
372 __u32 * uwrq, char *extra)
373{
374 islpci_private *priv = netdev_priv(ndev);
375
376 BUG_ON((priv->iw_mode < IW_MODE_AUTO) || (priv->iw_mode >
377 IW_MODE_MONITOR));
378 *uwrq = priv->iw_mode;
379
380 return 0;
381}
382
383/* we use DOT11_OID_EDTHRESHOLD. From what I guess the card will not try to
384 * emit data if (sensitivity > rssi - noise) (in dBm).
385 * prism54_set_sens does not seem to work.
386 */
387
388static int
389prism54_set_sens(struct net_device *ndev, struct iw_request_info *info,
390 struct iw_param *vwrq, char *extra)
391{
392 islpci_private *priv = netdev_priv(ndev);
393 u32 sens;
394
395 /* by default the card sets this to 20. */
396 sens = vwrq->disabled ? 20 : vwrq->value;
397
398 return mgt_set_request(priv, DOT11_OID_EDTHRESHOLD, 0, &sens);
399}
400
401static int
402prism54_get_sens(struct net_device *ndev, struct iw_request_info *info,
403 struct iw_param *vwrq, char *extra)
404{
405 islpci_private *priv = netdev_priv(ndev);
406 union oid_res_t r;
407 int rvalue;
408
409 rvalue = mgt_get_request(priv, DOT11_OID_EDTHRESHOLD, 0, NULL, &r);
410
411 vwrq->value = r.u;
412 vwrq->disabled = (vwrq->value == 0);
413 vwrq->fixed = 1;
414
415 return rvalue;
416}
417
418static int
419prism54_get_range(struct net_device *ndev, struct iw_request_info *info,
420 struct iw_point *dwrq, char *extra)
421{
422 struct iw_range *range = (struct iw_range *) extra;
423 islpci_private *priv = netdev_priv(ndev);
424 u8 *data;
425 int i, m, rvalue;
426 struct obj_frequencies *freq;
427 union oid_res_t r;
428
429 memset(range, 0, sizeof (struct iw_range));
430 dwrq->length = sizeof (struct iw_range);
431
432 /* set the wireless extension version number */
433 range->we_version_source = SUPPORTED_WIRELESS_EXT;
434 range->we_version_compiled = WIRELESS_EXT;
435
436 /* Now the encoding capabilities */
437 range->num_encoding_sizes = 3;
438 /* 64(40) bits WEP */
439 range->encoding_size[0] = 5;
440 /* 128(104) bits WEP */
441 range->encoding_size[1] = 13;
442 /* 256 bits for WPA-PSK */
443 range->encoding_size[2] = 32;
444 /* 4 keys are allowed */
445 range->max_encoding_tokens = 4;
446
447 /* we don't know the quality range... */
448 range->max_qual.level = 0;
449 range->max_qual.noise = 0;
450 range->max_qual.qual = 0;
451 /* these value describe an average quality. Needs more tweaking... */
452 range->avg_qual.level = -80; /* -80 dBm */
453 range->avg_qual.noise = 0; /* don't know what to put here */
454 range->avg_qual.qual = 0;
455
456 range->sensitivity = 200;
457
458 /* retry limit capabilities */
459 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
460 range->retry_flags = IW_RETRY_LIMIT;
461 range->r_time_flags = IW_RETRY_LIFETIME;
462
463 /* I don't know the range. Put stupid things here */
464 range->min_retry = 1;
465 range->max_retry = 65535;
466 range->min_r_time = 1024;
467 range->max_r_time = 65535 * 1024;
468
469 /* txpower is supported in dBm's */
470 range->txpower_capa = IW_TXPOW_DBM;
471
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 /* Event capability (kernel + driver) */
473 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
474 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
475 IW_EVENT_CAPA_MASK(SIOCGIWAP));
476 range->event_capa[1] = IW_EVENT_CAPA_K_1;
477 range->event_capa[4] = IW_EVENT_CAPA_MASK(IWEVCUSTOM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
Dan Williamseab411f2006-07-17 21:21:47 -0400479 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
480 IW_ENC_CAPA_CIPHER_TKIP;
481
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 if (islpci_get_state(priv) < PRV_STATE_INIT)
483 return 0;
484
485 /* Request the device for the supported frequencies
486 * not really relevant since some devices will report the 5 GHz band
487 * frequencies even if they don't support them.
488 */
489 rvalue =
490 mgt_get_request(priv, DOT11_OID_SUPPORTEDFREQUENCIES, 0, NULL, &r);
491 freq = r.ptr;
492
493 range->num_channels = freq->nr;
494 range->num_frequency = freq->nr;
495
496 m = min(IW_MAX_FREQUENCIES, (int) freq->nr);
497 for (i = 0; i < m; i++) {
498 range->freq[i].m = freq->mhz[i];
499 range->freq[i].e = 6;
500 range->freq[i].i = channel_of_freq(freq->mhz[i]);
501 }
502 kfree(freq);
503
504 rvalue |= mgt_get_request(priv, DOT11_OID_SUPPORTEDRATES, 0, NULL, &r);
505 data = r.ptr;
506
507 /* We got an array of char. It is NULL terminated. */
508 i = 0;
509 while ((i < IW_MAX_BITRATES) && (*data != 0)) {
510 /* the result must be in bps. The card gives us 500Kbps */
511 range->bitrate[i] = *data * 500000;
512 i++;
513 data++;
514 }
515 range->num_bitrates = i;
516 kfree(r.ptr);
517
518 return rvalue;
519}
520
521/* Set AP address*/
522
523static int
524prism54_set_wap(struct net_device *ndev, struct iw_request_info *info,
525 struct sockaddr *awrq, char *extra)
526{
527 islpci_private *priv = netdev_priv(ndev);
528 char bssid[6];
529 int rvalue;
530
531 if (awrq->sa_family != ARPHRD_ETHER)
532 return -EINVAL;
533
534 /* prepare the structure for the set object */
535 memcpy(&bssid[0], awrq->sa_data, 6);
536
537 /* set the bssid -- does this make sense when in AP mode? */
538 rvalue = mgt_set_request(priv, DOT11_OID_BSSID, 0, &bssid);
539
540 return (rvalue ? rvalue : -EINPROGRESS); /* Call commit handler */
541}
542
543/* get AP address*/
544
545static int
546prism54_get_wap(struct net_device *ndev, struct iw_request_info *info,
547 struct sockaddr *awrq, char *extra)
548{
549 islpci_private *priv = netdev_priv(ndev);
550 union oid_res_t r;
551 int rvalue;
552
553 rvalue = mgt_get_request(priv, DOT11_OID_BSSID, 0, NULL, &r);
554 memcpy(awrq->sa_data, r.ptr, 6);
555 awrq->sa_family = ARPHRD_ETHER;
556 kfree(r.ptr);
557
558 return rvalue;
559}
560
561static int
562prism54_set_scan(struct net_device *dev, struct iw_request_info *info,
563 struct iw_param *vwrq, char *extra)
564{
565 /* hehe the device does this automagicaly */
566 return 0;
567}
568
569/* a little helper that will translate our data into a card independent
570 * format that the Wireless Tools will understand. This was inspired by
571 * the "Aironet driver for 4500 and 4800 series cards" (GPL)
572 */
573
574static char *
575prism54_translate_bss(struct net_device *ndev, char *current_ev,
576 char *end_buf, struct obj_bss *bss, char noise)
577{
578 struct iw_event iwe; /* Temporary buffer */
579 short cap;
580 islpci_private *priv = netdev_priv(ndev);
Dan Williamseab411f2006-07-17 21:21:47 -0400581 u8 wpa_ie[MAX_WPA_IE_LEN];
582 size_t wpa_ie_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
584 /* The first entry must be the MAC address */
585 memcpy(iwe.u.ap_addr.sa_data, bss->address, 6);
586 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
587 iwe.cmd = SIOCGIWAP;
588 current_ev =
589 iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
590
591 /* The following entries will be displayed in the same order we give them */
592
593 /* The ESSID. */
594 iwe.u.data.length = bss->ssid.length;
595 iwe.u.data.flags = 1;
596 iwe.cmd = SIOCGIWESSID;
597 current_ev = iwe_stream_add_point(current_ev, end_buf,
598 &iwe, bss->ssid.octets);
599
600 /* Capabilities */
601#define CAP_ESS 0x01
602#define CAP_IBSS 0x02
603#define CAP_CRYPT 0x10
604
605 /* Mode */
606 cap = bss->capinfo;
607 iwe.u.mode = 0;
608 if (cap & CAP_ESS)
609 iwe.u.mode = IW_MODE_MASTER;
610 else if (cap & CAP_IBSS)
611 iwe.u.mode = IW_MODE_ADHOC;
612 iwe.cmd = SIOCGIWMODE;
613 if (iwe.u.mode)
614 current_ev =
615 iwe_stream_add_event(current_ev, end_buf, &iwe,
616 IW_EV_UINT_LEN);
617
618 /* Encryption capability */
619 if (cap & CAP_CRYPT)
620 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
621 else
622 iwe.u.data.flags = IW_ENCODE_DISABLED;
623 iwe.u.data.length = 0;
624 iwe.cmd = SIOCGIWENCODE;
625 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, NULL);
626
627 /* Add frequency. (short) bss->channel is the frequency in MHz */
628 iwe.u.freq.m = bss->channel;
629 iwe.u.freq.e = 6;
630 iwe.cmd = SIOCGIWFREQ;
631 current_ev =
632 iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
633
634 /* Add quality statistics */
635 iwe.u.qual.level = bss->rssi;
636 iwe.u.qual.noise = noise;
637 /* do a simple SNR for quality */
638 iwe.u.qual.qual = bss->rssi - noise;
639 iwe.cmd = IWEVQUAL;
640 current_ev =
641 iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
642
Dan Williamseab411f2006-07-17 21:21:47 -0400643 /* Add WPA/RSN Information Element, if any */
644 wpa_ie_len = prism54_wpa_bss_ie_get(priv, bss->address, wpa_ie);
645 if (wpa_ie_len > 0) {
646 iwe.cmd = IWEVGENIE;
647 iwe.u.data.length = min(wpa_ie_len, (size_t)MAX_WPA_IE_LEN);
648 current_ev = iwe_stream_add_point(current_ev, end_buf,
649 &iwe, wpa_ie);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 }
Jean Tourrilhesbd6dd752006-08-29 18:19:23 -0700651 /* Do the bitrates */
652 {
653 char * current_val = current_ev + IW_EV_LCP_LEN;
654 int i;
655 int mask;
656
657 iwe.cmd = SIOCGIWRATE;
658 /* Those two flags are ignored... */
659 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
660
661 /* Parse the bitmask */
662 mask = 0x1;
663 for(i = 0; i < sizeof(scan_rate_list); i++) {
664 if(bss->rates & mask) {
665 iwe.u.bitrate.value = (scan_rate_list[i] * 500000);
666 current_val = iwe_stream_add_value(current_ev, current_val,
667 end_buf, &iwe,
668 IW_EV_PARAM_LEN);
669 }
670 mask <<= 1;
671 }
672 /* Check if we added any event */
673 if ((current_val - current_ev) > IW_EV_LCP_LEN)
674 current_ev = current_val;
675 }
676
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 return current_ev;
678}
679
680static int
681prism54_get_scan(struct net_device *ndev, struct iw_request_info *info,
682 struct iw_point *dwrq, char *extra)
683{
684 islpci_private *priv = netdev_priv(ndev);
685 int i, rvalue;
686 struct obj_bsslist *bsslist;
687 u32 noise = 0;
688 char *current_ev = extra;
689 union oid_res_t r;
690
691 if (islpci_get_state(priv) < PRV_STATE_INIT) {
692 /* device is not ready, fail gently */
693 dwrq->length = 0;
694 return 0;
695 }
696
697 /* first get the noise value. We will use it to report the link quality */
698 rvalue = mgt_get_request(priv, DOT11_OID_NOISEFLOOR, 0, NULL, &r);
699 noise = r.u;
700
701 /* Ask the device for a list of known bss.
702 * The old API, using SIOCGIWAPLIST, had a hard limit of IW_MAX_AP=64.
703 * The new API, using SIOCGIWSCAN, is only limited by the buffer size.
704 * WE-14->WE-16, the buffer is limited to IW_SCAN_MAX_DATA bytes.
705 * Starting with WE-17, the buffer can be as big as needed.
706 * But the device won't repport anything if you change the value
707 * of IWMAX_BSS=24. */
708
709 rvalue |= mgt_get_request(priv, DOT11_OID_BSSLIST, 0, NULL, &r);
710 bsslist = r.ptr;
711
712 /* ok now, scan the list and translate its info */
713 for (i = 0; i < (int) bsslist->nr; i++) {
714 current_ev = prism54_translate_bss(ndev, current_ev,
715 extra + dwrq->length,
716 &(bsslist->bsslist[i]),
717 noise);
Jeff Garzike2e96502005-09-24 04:05:52 -0400718
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 /* Check if there is space for one more entry */
720 if((extra + dwrq->length - current_ev) <= IW_EV_ADDR_LEN) {
721 /* Ask user space to try again with a bigger buffer */
722 rvalue = -E2BIG;
723 break;
724 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 }
726
727 kfree(bsslist);
728 dwrq->length = (current_ev - extra);
729 dwrq->flags = 0; /* todo */
730
731 return rvalue;
732}
733
734static int
735prism54_set_essid(struct net_device *ndev, struct iw_request_info *info,
736 struct iw_point *dwrq, char *extra)
737{
738 islpci_private *priv = netdev_priv(ndev);
739 struct obj_ssid essid;
740
741 memset(essid.octets, 0, 33);
742
743 /* Check if we were asked for `any' */
744 if (dwrq->flags && dwrq->length) {
Jean Tourrilhesbad04f22006-08-29 18:03:23 -0700745 if (dwrq->length > 32)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 return -E2BIG;
Jean Tourrilhesbad04f22006-08-29 18:03:23 -0700747 essid.length = dwrq->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 memcpy(essid.octets, extra, dwrq->length);
749 } else
750 essid.length = 0;
751
752 if (priv->iw_mode != IW_MODE_MONITOR)
753 return mgt_set_request(priv, DOT11_OID_SSID, 0, &essid);
754
755 /* If in monitor mode, just save to mib */
756 mgt_set(priv, DOT11_OID_SSID, &essid);
757 return 0;
758
759}
760
761static int
762prism54_get_essid(struct net_device *ndev, struct iw_request_info *info,
763 struct iw_point *dwrq, char *extra)
764{
765 islpci_private *priv = netdev_priv(ndev);
766 struct obj_ssid *essid;
767 union oid_res_t r;
768 int rvalue;
769
770 rvalue = mgt_get_request(priv, DOT11_OID_SSID, 0, NULL, &r);
771 essid = r.ptr;
772
773 if (essid->length) {
774 dwrq->flags = 1; /* set ESSID to ON for Wireless Extensions */
Alexey Dobriyan7f927fc2006-03-28 01:56:53 -0800775 /* if it is too big, trunk it */
Al Virobf82a442006-02-01 06:42:28 -0500776 dwrq->length = min((u8)IW_ESSID_MAX_SIZE, essid->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 } else {
778 dwrq->flags = 0;
779 dwrq->length = 0;
780 }
781 essid->octets[essid->length] = '\0';
782 memcpy(extra, essid->octets, dwrq->length);
783 kfree(essid);
784
785 return rvalue;
786}
787
788/* Provides no functionality, just completes the ioctl. In essence this is a
789 * just a cosmetic ioctl.
790 */
791static int
792prism54_set_nick(struct net_device *ndev, struct iw_request_info *info,
793 struct iw_point *dwrq, char *extra)
794{
795 islpci_private *priv = netdev_priv(ndev);
796
797 if (dwrq->length > IW_ESSID_MAX_SIZE)
798 return -E2BIG;
799
800 down_write(&priv->mib_sem);
801 memset(priv->nickname, 0, sizeof (priv->nickname));
802 memcpy(priv->nickname, extra, dwrq->length);
803 up_write(&priv->mib_sem);
804
805 return 0;
806}
807
808static int
809prism54_get_nick(struct net_device *ndev, struct iw_request_info *info,
810 struct iw_point *dwrq, char *extra)
811{
812 islpci_private *priv = netdev_priv(ndev);
813
814 dwrq->length = 0;
815
816 down_read(&priv->mib_sem);
Jean Tourrilhesbad04f22006-08-29 18:03:23 -0700817 dwrq->length = strlen(priv->nickname);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 memcpy(extra, priv->nickname, dwrq->length);
819 up_read(&priv->mib_sem);
820
821 return 0;
822}
823
824/* Set the allowed Bitrates */
825
826static int
827prism54_set_rate(struct net_device *ndev,
828 struct iw_request_info *info,
829 struct iw_param *vwrq, char *extra)
830{
831
832 islpci_private *priv = netdev_priv(ndev);
833 u32 rate, profile;
834 char *data;
835 int ret, i;
836 union oid_res_t r;
837
838 if (vwrq->value == -1) {
839 /* auto mode. No limit. */
840 profile = 1;
841 return mgt_set_request(priv, DOT11_OID_PROFILES, 0, &profile);
842 }
843
844 ret = mgt_get_request(priv, DOT11_OID_SUPPORTEDRATES, 0, NULL, &r);
845 if (ret) {
846 kfree(r.ptr);
847 return ret;
848 }
849
850 rate = (u32) (vwrq->value / 500000);
851 data = r.ptr;
852 i = 0;
853
854 while (data[i]) {
855 if (rate && (data[i] == rate)) {
856 break;
857 }
858 if (vwrq->value == i) {
859 break;
860 }
861 data[i] |= 0x80;
862 i++;
863 }
864
865 if (!data[i]) {
866 kfree(r.ptr);
867 return -EINVAL;
868 }
869
870 data[i] |= 0x80;
871 data[i + 1] = 0;
872
873 /* Now, check if we want a fixed or auto value */
874 if (vwrq->fixed) {
875 data[0] = data[i];
876 data[1] = 0;
877 }
878
879/*
880 i = 0;
881 printk("prism54 rate: ");
882 while(data[i]) {
883 printk("%u ", data[i]);
884 i++;
885 }
886 printk("0\n");
887*/
888 profile = -1;
889 ret = mgt_set_request(priv, DOT11_OID_PROFILES, 0, &profile);
890 ret |= mgt_set_request(priv, DOT11_OID_EXTENDEDRATES, 0, data);
891 ret |= mgt_set_request(priv, DOT11_OID_RATES, 0, data);
892
893 kfree(r.ptr);
894
895 return ret;
896}
897
898/* Get the current bit rate */
899static int
900prism54_get_rate(struct net_device *ndev,
901 struct iw_request_info *info,
902 struct iw_param *vwrq, char *extra)
903{
904 islpci_private *priv = netdev_priv(ndev);
905 int rvalue;
906 char *data;
907 union oid_res_t r;
908
909 /* Get the current bit rate */
910 if ((rvalue = mgt_get_request(priv, GEN_OID_LINKSTATE, 0, NULL, &r)))
911 return rvalue;
912 vwrq->value = r.u * 500000;
913
914 /* request the device for the enabled rates */
915 rvalue = mgt_get_request(priv, DOT11_OID_RATES, 0, NULL, &r);
916 if (rvalue) {
917 kfree(r.ptr);
918 return rvalue;
919 }
920 data = r.ptr;
921 vwrq->fixed = (data[0] != 0) && (data[1] == 0);
922 kfree(r.ptr);
923
924 return 0;
925}
926
927static int
928prism54_set_rts(struct net_device *ndev, struct iw_request_info *info,
929 struct iw_param *vwrq, char *extra)
930{
931 islpci_private *priv = netdev_priv(ndev);
932
933 return mgt_set_request(priv, DOT11_OID_RTSTHRESH, 0, &vwrq->value);
934}
935
936static int
937prism54_get_rts(struct net_device *ndev, struct iw_request_info *info,
938 struct iw_param *vwrq, char *extra)
939{
940 islpci_private *priv = netdev_priv(ndev);
941 union oid_res_t r;
942 int rvalue;
943
944 /* get the rts threshold */
945 rvalue = mgt_get_request(priv, DOT11_OID_RTSTHRESH, 0, NULL, &r);
946 vwrq->value = r.u;
947
948 return rvalue;
949}
950
951static int
952prism54_set_frag(struct net_device *ndev, struct iw_request_info *info,
953 struct iw_param *vwrq, char *extra)
954{
955 islpci_private *priv = netdev_priv(ndev);
956
957 return mgt_set_request(priv, DOT11_OID_FRAGTHRESH, 0, &vwrq->value);
958}
959
960static int
961prism54_get_frag(struct net_device *ndev, struct iw_request_info *info,
962 struct iw_param *vwrq, char *extra)
963{
964 islpci_private *priv = netdev_priv(ndev);
965 union oid_res_t r;
966 int rvalue;
967
968 rvalue = mgt_get_request(priv, DOT11_OID_FRAGTHRESH, 0, NULL, &r);
969 vwrq->value = r.u;
970
971 return rvalue;
972}
973
974/* Here we have (min,max) = max retries for (small frames, big frames). Where
975 * big frame <=> bigger than the rts threshold
976 * small frame <=> smaller than the rts threshold
977 * This is not really the behavior expected by the wireless tool but it seems
978 * to be a common behavior in other drivers.
979 */
980
981static int
982prism54_set_retry(struct net_device *ndev, struct iw_request_info *info,
983 struct iw_param *vwrq, char *extra)
984{
985 islpci_private *priv = netdev_priv(ndev);
986 u32 slimit = 0, llimit = 0; /* short and long limit */
987 u32 lifetime = 0;
988 int rvalue = 0;
989
990 if (vwrq->disabled)
991 /* we cannot disable this feature */
992 return -EINVAL;
993
994 if (vwrq->flags & IW_RETRY_LIMIT) {
Jean Tourrilhesbad04f22006-08-29 18:03:23 -0700995 if (vwrq->flags & IW_RETRY_SHORT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 slimit = vwrq->value;
Jean Tourrilhesbad04f22006-08-29 18:03:23 -0700997 else if (vwrq->flags & IW_RETRY_LONG)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 llimit = vwrq->value;
999 else {
1000 /* we are asked to set both */
1001 slimit = vwrq->value;
1002 llimit = vwrq->value;
1003 }
1004 }
1005 if (vwrq->flags & IW_RETRY_LIFETIME)
1006 /* Wireless tools use us unit while the device uses 1024 us unit */
1007 lifetime = vwrq->value / 1024;
1008
1009 /* now set what is requested */
1010 if (slimit)
1011 rvalue =
1012 mgt_set_request(priv, DOT11_OID_SHORTRETRIES, 0, &slimit);
1013 if (llimit)
1014 rvalue |=
1015 mgt_set_request(priv, DOT11_OID_LONGRETRIES, 0, &llimit);
1016 if (lifetime)
1017 rvalue |=
1018 mgt_set_request(priv, DOT11_OID_MAXTXLIFETIME, 0,
1019 &lifetime);
1020 return rvalue;
1021}
1022
1023static int
1024prism54_get_retry(struct net_device *ndev, struct iw_request_info *info,
1025 struct iw_param *vwrq, char *extra)
1026{
1027 islpci_private *priv = netdev_priv(ndev);
1028 union oid_res_t r;
1029 int rvalue = 0;
1030 vwrq->disabled = 0; /* It cannot be disabled */
1031
1032 if ((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1033 /* we are asked for the life time */
1034 rvalue =
1035 mgt_get_request(priv, DOT11_OID_MAXTXLIFETIME, 0, NULL, &r);
1036 vwrq->value = r.u * 1024;
1037 vwrq->flags = IW_RETRY_LIFETIME;
Jean Tourrilhesbad04f22006-08-29 18:03:23 -07001038 } else if ((vwrq->flags & IW_RETRY_LONG)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 /* we are asked for the long retry limit */
1040 rvalue |=
1041 mgt_get_request(priv, DOT11_OID_LONGRETRIES, 0, NULL, &r);
1042 vwrq->value = r.u;
Jean Tourrilhesbad04f22006-08-29 18:03:23 -07001043 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 } else {
1045 /* default. get the short retry limit */
1046 rvalue |=
1047 mgt_get_request(priv, DOT11_OID_SHORTRETRIES, 0, NULL, &r);
1048 vwrq->value = r.u;
Jean Tourrilhesbad04f22006-08-29 18:03:23 -07001049 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 }
1051
1052 return rvalue;
1053}
1054
1055static int
1056prism54_set_encode(struct net_device *ndev, struct iw_request_info *info,
1057 struct iw_point *dwrq, char *extra)
1058{
1059 islpci_private *priv = netdev_priv(ndev);
1060 int rvalue = 0, force = 0;
1061 int authen = DOT11_AUTH_OS, invoke = 0, exunencrypt = 0;
1062 union oid_res_t r;
1063
1064 /* with the new API, it's impossible to get a NULL pointer.
1065 * New version of iwconfig set the IW_ENCODE_NOKEY flag
1066 * when no key is given, but older versions don't. */
1067
1068 if (dwrq->length > 0) {
1069 /* we have a key to set */
1070 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1071 int current_index;
1072 struct obj_key key = { DOT11_PRIV_WEP, 0, "" };
1073
1074 /* get the current key index */
1075 rvalue = mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r);
1076 current_index = r.u;
1077 /* Verify that the key is not marked as invalid */
1078 if (!(dwrq->flags & IW_ENCODE_NOKEY)) {
Dan Williamseab411f2006-07-17 21:21:47 -04001079 if (dwrq->length > KEY_SIZE_TKIP) {
1080 /* User-provided key data too big */
1081 return -EINVAL;
1082 }
1083 if (dwrq->length > KEY_SIZE_WEP104) {
1084 /* WPA-PSK TKIP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 key.type = DOT11_PRIV_TKIP;
Dan Williamseab411f2006-07-17 21:21:47 -04001086 key.length = KEY_SIZE_TKIP;
1087 } else if (dwrq->length > KEY_SIZE_WEP40) {
1088 /* WEP 104/128 */
1089 key.length = KEY_SIZE_WEP104;
1090 } else {
1091 /* WEP 40/64 */
1092 key.length = KEY_SIZE_WEP40;
1093 }
1094 memset(key.key, 0, sizeof (key.key));
1095 memcpy(key.key, extra, dwrq->length);
1096
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 if ((index < 0) || (index > 3))
1098 /* no index provided use the current one */
1099 index = current_index;
1100
1101 /* now send the key to the card */
1102 rvalue |=
1103 mgt_set_request(priv, DOT11_OID_DEFKEYX, index,
1104 &key);
1105 }
1106 /*
1107 * If a valid key is set, encryption should be enabled
1108 * (user may turn it off later).
1109 * This is also how "iwconfig ethX key on" works
1110 */
1111 if ((index == current_index) && (key.length > 0))
1112 force = 1;
1113 } else {
1114 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1115 if ((index >= 0) && (index <= 3)) {
1116 /* we want to set the key index */
1117 rvalue |=
1118 mgt_set_request(priv, DOT11_OID_DEFKEYID, 0,
1119 &index);
1120 } else {
1121 if (!dwrq->flags & IW_ENCODE_MODE) {
1122 /* we cannot do anything. Complain. */
1123 return -EINVAL;
1124 }
1125 }
1126 }
1127 /* now read the flags */
1128 if (dwrq->flags & IW_ENCODE_DISABLED) {
1129 /* Encoding disabled,
1130 * authen = DOT11_AUTH_OS;
1131 * invoke = 0;
1132 * exunencrypt = 0; */
1133 }
1134 if (dwrq->flags & IW_ENCODE_OPEN)
1135 /* Encode but accept non-encoded packets. No auth */
1136 invoke = 1;
1137 if ((dwrq->flags & IW_ENCODE_RESTRICTED) || force) {
1138 /* Refuse non-encoded packets. Auth */
1139 authen = DOT11_AUTH_BOTH;
1140 invoke = 1;
1141 exunencrypt = 1;
1142 }
1143 /* do the change if requested */
1144 if ((dwrq->flags & IW_ENCODE_MODE) || force) {
1145 rvalue |=
1146 mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0, &authen);
1147 rvalue |=
1148 mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0, &invoke);
1149 rvalue |=
1150 mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0,
1151 &exunencrypt);
1152 }
1153 return rvalue;
1154}
1155
1156static int
1157prism54_get_encode(struct net_device *ndev, struct iw_request_info *info,
1158 struct iw_point *dwrq, char *extra)
1159{
1160 islpci_private *priv = netdev_priv(ndev);
1161 struct obj_key *key;
1162 u32 devindex, index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1163 u32 authen = 0, invoke = 0, exunencrypt = 0;
1164 int rvalue;
1165 union oid_res_t r;
1166
1167 /* first get the flags */
1168 rvalue = mgt_get_request(priv, DOT11_OID_AUTHENABLE, 0, NULL, &r);
1169 authen = r.u;
1170 rvalue |= mgt_get_request(priv, DOT11_OID_PRIVACYINVOKED, 0, NULL, &r);
1171 invoke = r.u;
1172 rvalue |= mgt_get_request(priv, DOT11_OID_EXUNENCRYPTED, 0, NULL, &r);
1173 exunencrypt = r.u;
1174
1175 if (invoke && (authen == DOT11_AUTH_BOTH) && exunencrypt)
1176 dwrq->flags = IW_ENCODE_RESTRICTED;
1177 else if ((authen == DOT11_AUTH_OS) && !exunencrypt) {
1178 if (invoke)
1179 dwrq->flags = IW_ENCODE_OPEN;
1180 else
1181 dwrq->flags = IW_ENCODE_DISABLED;
1182 } else
1183 /* The card should not work in this state */
1184 dwrq->flags = 0;
1185
1186 /* get the current device key index */
1187 rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r);
1188 devindex = r.u;
1189 /* Now get the key, return it */
1190 if ((index < 0) || (index > 3))
1191 /* no index provided, use the current one */
1192 index = devindex;
1193 rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYX, index, NULL, &r);
1194 key = r.ptr;
1195 dwrq->length = key->length;
1196 memcpy(extra, key->key, dwrq->length);
1197 kfree(key);
1198 /* return the used key index */
1199 dwrq->flags |= devindex + 1;
1200
1201 return rvalue;
1202}
1203
1204static int
1205prism54_get_txpower(struct net_device *ndev, struct iw_request_info *info,
1206 struct iw_param *vwrq, char *extra)
1207{
1208 islpci_private *priv = netdev_priv(ndev);
1209 union oid_res_t r;
1210 int rvalue;
1211
1212 rvalue = mgt_get_request(priv, OID_INL_OUTPUTPOWER, 0, NULL, &r);
1213 /* intersil firmware operates in 0.25 dBm (1/4 dBm) */
1214 vwrq->value = (s32) r.u / 4;
1215 vwrq->fixed = 1;
1216 /* radio is not turned of
1217 * btw: how is possible to turn off only the radio
1218 */
1219 vwrq->disabled = 0;
1220
1221 return rvalue;
1222}
1223
1224static int
1225prism54_set_txpower(struct net_device *ndev, struct iw_request_info *info,
1226 struct iw_param *vwrq, char *extra)
1227{
1228 islpci_private *priv = netdev_priv(ndev);
1229 s32 u = vwrq->value;
1230
1231 /* intersil firmware operates in 0.25 dBm (1/4) */
1232 u *= 4;
1233 if (vwrq->disabled) {
1234 /* don't know how to disable radio */
1235 printk(KERN_DEBUG
1236 "%s: %s() disabling radio is not yet supported.\n",
1237 priv->ndev->name, __FUNCTION__);
1238 return -ENOTSUPP;
1239 } else if (vwrq->fixed)
1240 /* currently only fixed value is supported */
1241 return mgt_set_request(priv, OID_INL_OUTPUTPOWER, 0, &u);
1242 else {
1243 printk(KERN_DEBUG
1244 "%s: %s() auto power will be implemented later.\n",
1245 priv->ndev->name, __FUNCTION__);
1246 return -ENOTSUPP;
1247 }
1248}
1249
Dan Williamseab411f2006-07-17 21:21:47 -04001250static int prism54_set_genie(struct net_device *ndev,
1251 struct iw_request_info *info,
1252 struct iw_point *data, char *extra)
1253{
1254 islpci_private *priv = netdev_priv(ndev);
1255 int alen, ret = 0;
1256 struct obj_attachment *attach;
1257
1258 if (data->length > MAX_WPA_IE_LEN ||
1259 (data->length && extra == NULL))
1260 return -EINVAL;
1261
1262 memcpy(priv->wpa_ie, extra, data->length);
1263 priv->wpa_ie_len = data->length;
1264
1265 alen = sizeof(*attach) + priv->wpa_ie_len;
1266 attach = kzalloc(alen, GFP_KERNEL);
1267 if (attach == NULL)
1268 return -ENOMEM;
1269
1270#define WLAN_FC_TYPE_MGMT 0
1271#define WLAN_FC_STYPE_ASSOC_REQ 0
1272#define WLAN_FC_STYPE_REASSOC_REQ 2
1273
1274 /* Note: endianness is covered by mgt_set_varlen */
1275 attach->type = (WLAN_FC_TYPE_MGMT << 2) |
1276 (WLAN_FC_STYPE_ASSOC_REQ << 4);
1277 attach->id = -1;
1278 attach->size = priv->wpa_ie_len;
1279 memcpy(attach->data, extra, priv->wpa_ie_len);
1280
1281 ret = mgt_set_varlen(priv, DOT11_OID_ATTACHMENT, attach,
1282 priv->wpa_ie_len);
1283 if (ret == 0) {
1284 attach->type = (WLAN_FC_TYPE_MGMT << 2) |
1285 (WLAN_FC_STYPE_REASSOC_REQ << 4);
1286
1287 ret = mgt_set_varlen(priv, DOT11_OID_ATTACHMENT, attach,
1288 priv->wpa_ie_len);
1289 if (ret == 0)
1290 printk(KERN_DEBUG "%s: WPA IE Attachment was set\n",
1291 ndev->name);
1292 }
1293
1294 kfree(attach);
1295 return ret;
1296}
1297
1298
1299static int prism54_get_genie(struct net_device *ndev,
1300 struct iw_request_info *info,
1301 struct iw_point *data, char *extra)
1302{
1303 islpci_private *priv = netdev_priv(ndev);
1304 int len = priv->wpa_ie_len;
1305
1306 if (len <= 0) {
1307 data->length = 0;
1308 return 0;
1309 }
1310
1311 if (data->length < len)
1312 return -E2BIG;
1313
1314 data->length = len;
1315 memcpy(extra, priv->wpa_ie, len);
1316
1317 return 0;
1318}
1319
1320static int prism54_set_auth(struct net_device *ndev,
1321 struct iw_request_info *info,
1322 union iwreq_data *wrqu, char *extra)
1323{
1324 islpci_private *priv = netdev_priv(ndev);
1325 struct iw_param *param = &wrqu->param;
1326 u32 mlmelevel = 0, authen = 0, dot1x = 0;
1327 u32 exunencrypt = 0, privinvoked = 0, wpa = 0;
1328 u32 old_wpa;
1329 int ret = 0;
1330 union oid_res_t r;
1331
1332 if (islpci_get_state(priv) < PRV_STATE_INIT)
1333 return 0;
1334
1335 /* first get the flags */
1336 down_write(&priv->mib_sem);
1337 wpa = old_wpa = priv->wpa;
1338 up_write(&priv->mib_sem);
1339 ret = mgt_get_request(priv, DOT11_OID_AUTHENABLE, 0, NULL, &r);
1340 authen = r.u;
1341 ret = mgt_get_request(priv, DOT11_OID_PRIVACYINVOKED, 0, NULL, &r);
1342 privinvoked = r.u;
1343 ret = mgt_get_request(priv, DOT11_OID_EXUNENCRYPTED, 0, NULL, &r);
1344 exunencrypt = r.u;
1345 ret = mgt_get_request(priv, DOT11_OID_DOT1XENABLE, 0, NULL, &r);
1346 dot1x = r.u;
1347 ret = mgt_get_request(priv, DOT11_OID_MLMEAUTOLEVEL, 0, NULL, &r);
1348 mlmelevel = r.u;
1349
1350 if (ret < 0)
1351 goto out;
1352
1353 switch (param->flags & IW_AUTH_INDEX) {
1354 case IW_AUTH_CIPHER_PAIRWISE:
1355 case IW_AUTH_CIPHER_GROUP:
1356 case IW_AUTH_KEY_MGMT:
1357 break;
1358
1359 case IW_AUTH_WPA_ENABLED:
1360 /* Do the same thing as IW_AUTH_WPA_VERSION */
1361 if (param->value) {
1362 wpa = 1;
1363 privinvoked = 1; /* For privacy invoked */
1364 exunencrypt = 1; /* Filter out all unencrypted frames */
1365 dot1x = 0x01; /* To enable eap filter */
1366 mlmelevel = DOT11_MLME_EXTENDED;
1367 authen = DOT11_AUTH_OS; /* Only WEP uses _SK and _BOTH */
1368 } else {
1369 wpa = 0;
1370 privinvoked = 0;
1371 exunencrypt = 0; /* Do not filter un-encrypted data */
1372 dot1x = 0;
1373 mlmelevel = DOT11_MLME_AUTO;
1374 }
1375 break;
1376
1377 case IW_AUTH_WPA_VERSION:
1378 if (param->value & IW_AUTH_WPA_VERSION_DISABLED) {
1379 wpa = 0;
1380 privinvoked = 0;
1381 exunencrypt = 0; /* Do not filter un-encrypted data */
1382 dot1x = 0;
1383 mlmelevel = DOT11_MLME_AUTO;
1384 } else {
1385 if (param->value & IW_AUTH_WPA_VERSION_WPA)
1386 wpa = 1;
1387 else if (param->value & IW_AUTH_WPA_VERSION_WPA2)
1388 wpa = 2;
1389 privinvoked = 1; /* For privacy invoked */
1390 exunencrypt = 1; /* Filter out all unencrypted frames */
1391 dot1x = 0x01; /* To enable eap filter */
1392 mlmelevel = DOT11_MLME_EXTENDED;
1393 authen = DOT11_AUTH_OS; /* Only WEP uses _SK and _BOTH */
1394 }
1395 break;
1396
1397 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1398 dot1x = param->value ? 1 : 0;
1399 break;
1400
1401 case IW_AUTH_PRIVACY_INVOKED:
1402 privinvoked = param->value ? 1 : 0;
1403
1404 case IW_AUTH_DROP_UNENCRYPTED:
1405 exunencrypt = param->value ? 1 : 0;
1406 break;
1407
1408 case IW_AUTH_80211_AUTH_ALG:
1409 if (param->value & IW_AUTH_ALG_SHARED_KEY) {
1410 /* Only WEP uses _SK and _BOTH */
1411 if (wpa > 0) {
1412 ret = -EINVAL;
1413 goto out;
1414 }
1415 authen = DOT11_AUTH_SK;
1416 } else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM) {
1417 authen = DOT11_AUTH_OS;
1418 } else {
1419 ret = -EINVAL;
1420 goto out;
1421 }
1422 break;
1423
1424 default:
1425 return -EOPNOTSUPP;
1426 }
1427
1428 /* Set all the values */
1429 down_write(&priv->mib_sem);
1430 priv->wpa = wpa;
1431 up_write(&priv->mib_sem);
1432 mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0, &authen);
1433 mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0, &privinvoked);
1434 mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0, &exunencrypt);
1435 mgt_set_request(priv, DOT11_OID_DOT1XENABLE, 0, &dot1x);
1436 mgt_set_request(priv, DOT11_OID_MLMEAUTOLEVEL, 0, &mlmelevel);
1437
1438out:
1439 return ret;
1440}
1441
1442static int prism54_get_auth(struct net_device *ndev,
1443 struct iw_request_info *info,
1444 union iwreq_data *wrqu, char *extra)
1445{
1446 islpci_private *priv = netdev_priv(ndev);
1447 struct iw_param *param = &wrqu->param;
1448 u32 wpa = 0;
1449 int ret = 0;
1450 union oid_res_t r;
1451
1452 if (islpci_get_state(priv) < PRV_STATE_INIT)
1453 return 0;
1454
1455 /* first get the flags */
1456 down_write(&priv->mib_sem);
1457 wpa = priv->wpa;
1458 up_write(&priv->mib_sem);
1459
1460 switch (param->flags & IW_AUTH_INDEX) {
1461 case IW_AUTH_CIPHER_PAIRWISE:
1462 case IW_AUTH_CIPHER_GROUP:
1463 case IW_AUTH_KEY_MGMT:
1464 /*
1465 * wpa_supplicant will control these internally
1466 */
1467 ret = -EOPNOTSUPP;
1468 break;
1469
1470 case IW_AUTH_WPA_VERSION:
1471 switch (wpa) {
1472 case 1:
1473 param->value = IW_AUTH_WPA_VERSION_WPA;
1474 break;
1475 case 2:
1476 param->value = IW_AUTH_WPA_VERSION_WPA2;
1477 break;
1478 case 0:
1479 default:
1480 param->value = IW_AUTH_WPA_VERSION_DISABLED;
1481 break;
1482 }
1483 break;
1484
1485 case IW_AUTH_DROP_UNENCRYPTED:
1486 ret = mgt_get_request(priv, DOT11_OID_EXUNENCRYPTED, 0, NULL, &r);
1487 if (ret >= 0)
1488 param->value = r.u > 0 ? 1 : 0;
1489 break;
1490
1491 case IW_AUTH_80211_AUTH_ALG:
1492 ret = mgt_get_request(priv, DOT11_OID_AUTHENABLE, 0, NULL, &r);
1493 if (ret >= 0) {
1494 switch (r.u) {
1495 case DOT11_AUTH_OS:
1496 param->value = IW_AUTH_ALG_OPEN_SYSTEM;
1497 break;
1498 case DOT11_AUTH_BOTH:
1499 case DOT11_AUTH_SK:
1500 param->value = IW_AUTH_ALG_SHARED_KEY;
1501 case DOT11_AUTH_NONE:
1502 default:
1503 param->value = 0;
1504 break;
1505 }
1506 }
1507 break;
1508
1509 case IW_AUTH_WPA_ENABLED:
1510 param->value = wpa > 0 ? 1 : 0;
1511 break;
1512
1513 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1514 ret = mgt_get_request(priv, DOT11_OID_DOT1XENABLE, 0, NULL, &r);
1515 if (ret >= 0)
1516 param->value = r.u > 0 ? 1 : 0;
1517 break;
1518
1519 case IW_AUTH_PRIVACY_INVOKED:
1520 ret = mgt_get_request(priv, DOT11_OID_PRIVACYINVOKED, 0, NULL, &r);
1521 if (ret >= 0)
1522 param->value = r.u > 0 ? 1 : 0;
1523 break;
1524
1525 default:
1526 return -EOPNOTSUPP;
1527 }
1528 return ret;
1529}
1530
1531static int prism54_set_encodeext(struct net_device *ndev,
1532 struct iw_request_info *info,
1533 union iwreq_data *wrqu,
1534 char *extra)
1535{
1536 islpci_private *priv = netdev_priv(ndev);
1537 struct iw_point *encoding = &wrqu->encoding;
1538 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1539 int idx, alg = ext->alg, set_key = 1;
1540 union oid_res_t r;
1541 int authen = DOT11_AUTH_OS, invoke = 0, exunencrypt = 0;
1542 int ret = 0;
1543
1544 if (islpci_get_state(priv) < PRV_STATE_INIT)
1545 return 0;
1546
1547 /* Determine and validate the key index */
1548 idx = (encoding->flags & IW_ENCODE_INDEX) - 1;
1549 if (idx) {
1550 if (idx < 0 || idx > 3)
1551 return -EINVAL;
1552 } else {
1553 ret = mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r);
1554 if (ret < 0)
1555 goto out;
1556 idx = r.u;
1557 }
1558
1559 if (encoding->flags & IW_ENCODE_DISABLED)
1560 alg = IW_ENCODE_ALG_NONE;
1561
1562 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
1563 /* Only set transmit key index here, actual
1564 * key is set below if needed.
1565 */
1566 ret = mgt_set_request(priv, DOT11_OID_DEFKEYID, 0, &idx);
1567 set_key = ext->key_len > 0 ? 1 : 0;
1568 }
1569
1570 if (set_key) {
1571 struct obj_key key = { DOT11_PRIV_WEP, 0, "" };
1572 switch (alg) {
1573 case IW_ENCODE_ALG_NONE:
1574 break;
1575 case IW_ENCODE_ALG_WEP:
1576 if (ext->key_len > KEY_SIZE_WEP104) {
1577 ret = -EINVAL;
1578 goto out;
1579 }
1580 if (ext->key_len > KEY_SIZE_WEP40)
1581 key.length = KEY_SIZE_WEP104;
1582 else
1583 key.length = KEY_SIZE_WEP40;
1584 break;
1585 case IW_ENCODE_ALG_TKIP:
1586 if (ext->key_len > KEY_SIZE_TKIP) {
1587 ret = -EINVAL;
1588 goto out;
1589 }
1590 key.type = DOT11_PRIV_TKIP;
1591 key.length = KEY_SIZE_TKIP;
1592 default:
1593 return -EINVAL;
1594 }
1595
1596 if (key.length) {
1597 memset(key.key, 0, sizeof(key.key));
1598 memcpy(key.key, ext->key, ext->key_len);
1599 ret = mgt_set_request(priv, DOT11_OID_DEFKEYX, idx,
1600 &key);
1601 if (ret < 0)
1602 goto out;
1603 }
1604 }
1605
1606 /* Read the flags */
1607 if (encoding->flags & IW_ENCODE_DISABLED) {
1608 /* Encoding disabled,
1609 * authen = DOT11_AUTH_OS;
1610 * invoke = 0;
1611 * exunencrypt = 0; */
1612 }
1613 if (encoding->flags & IW_ENCODE_OPEN) {
1614 /* Encode but accept non-encoded packets. No auth */
1615 invoke = 1;
1616 }
1617 if (encoding->flags & IW_ENCODE_RESTRICTED) {
1618 /* Refuse non-encoded packets. Auth */
1619 authen = DOT11_AUTH_BOTH;
1620 invoke = 1;
1621 exunencrypt = 1;
1622 }
1623
1624 /* do the change if requested */
1625 if (encoding->flags & IW_ENCODE_MODE) {
1626 ret = mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0,
1627 &authen);
1628 ret = mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0,
1629 &invoke);
1630 ret = mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0,
1631 &exunencrypt);
1632 }
1633
1634out:
1635 return ret;
1636}
1637
1638
1639static int prism54_get_encodeext(struct net_device *ndev,
1640 struct iw_request_info *info,
1641 union iwreq_data *wrqu,
1642 char *extra)
1643{
1644 islpci_private *priv = netdev_priv(ndev);
1645 struct iw_point *encoding = &wrqu->encoding;
1646 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1647 int idx, max_key_len;
1648 union oid_res_t r;
1649 int authen = DOT11_AUTH_OS, invoke = 0, exunencrypt = 0, wpa = 0;
1650 int ret = 0;
1651
1652 if (islpci_get_state(priv) < PRV_STATE_INIT)
1653 return 0;
1654
1655 /* first get the flags */
1656 ret = mgt_get_request(priv, DOT11_OID_AUTHENABLE, 0, NULL, &r);
1657 authen = r.u;
1658 ret = mgt_get_request(priv, DOT11_OID_PRIVACYINVOKED, 0, NULL, &r);
1659 invoke = r.u;
1660 ret = mgt_get_request(priv, DOT11_OID_EXUNENCRYPTED, 0, NULL, &r);
1661 exunencrypt = r.u;
1662 if (ret < 0)
1663 goto out;
1664
1665 max_key_len = encoding->length - sizeof(*ext);
1666 if (max_key_len < 0)
1667 return -EINVAL;
1668
1669 idx = (encoding->flags & IW_ENCODE_INDEX) - 1;
1670 if (idx) {
1671 if (idx < 0 || idx > 3)
1672 return -EINVAL;
1673 } else {
1674 ret = mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r);
1675 if (ret < 0)
1676 goto out;
1677 idx = r.u;
1678 }
1679
1680 encoding->flags = idx + 1;
1681 memset(ext, 0, sizeof(*ext));
1682
1683 switch (authen) {
1684 case DOT11_AUTH_BOTH:
1685 case DOT11_AUTH_SK:
1686 wrqu->encoding.flags |= IW_ENCODE_RESTRICTED;
1687 case DOT11_AUTH_OS:
1688 default:
1689 wrqu->encoding.flags |= IW_ENCODE_OPEN;
1690 break;
1691 }
1692
1693 down_write(&priv->mib_sem);
1694 wpa = priv->wpa;
1695 up_write(&priv->mib_sem);
1696
1697 if (authen == DOT11_AUTH_OS && !exunencrypt && !invoke && !wpa) {
1698 /* No encryption */
1699 ext->alg = IW_ENCODE_ALG_NONE;
1700 ext->key_len = 0;
1701 wrqu->encoding.flags |= IW_ENCODE_DISABLED;
1702 } else {
1703 struct obj_key *key;
1704
1705 ret = mgt_get_request(priv, DOT11_OID_DEFKEYX, idx, NULL, &r);
1706 if (ret < 0)
1707 goto out;
1708 key = r.ptr;
1709 if (max_key_len < key->length) {
1710 ret = -E2BIG;
1711 goto out;
1712 }
1713 memcpy(ext->key, key->key, key->length);
1714 ext->key_len = key->length;
1715
1716 switch (key->type) {
1717 case DOT11_PRIV_TKIP:
1718 ext->alg = IW_ENCODE_ALG_TKIP;
1719 break;
1720 default:
1721 case DOT11_PRIV_WEP:
1722 ext->alg = IW_ENCODE_ALG_WEP;
1723 break;
1724 }
1725 wrqu->encoding.flags |= IW_ENCODE_ENABLED;
1726 }
1727
1728out:
1729 return ret;
1730}
1731
1732
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733static int
1734prism54_reset(struct net_device *ndev, struct iw_request_info *info,
1735 __u32 * uwrq, char *extra)
1736{
1737 islpci_reset(netdev_priv(ndev), 0);
1738
1739 return 0;
1740}
1741
1742static int
1743prism54_get_oid(struct net_device *ndev, struct iw_request_info *info,
1744 struct iw_point *dwrq, char *extra)
1745{
1746 union oid_res_t r;
1747 int rvalue;
1748 enum oid_num_t n = dwrq->flags;
1749
1750 rvalue = mgt_get_request((islpci_private *) ndev->priv, n, 0, NULL, &r);
1751 dwrq->length = mgt_response_to_str(n, &r, extra);
1752 if ((isl_oid[n].flags & OID_FLAG_TYPE) != OID_TYPE_U32)
1753 kfree(r.ptr);
1754 return rvalue;
1755}
1756
1757static int
1758prism54_set_u32(struct net_device *ndev, struct iw_request_info *info,
1759 __u32 * uwrq, char *extra)
1760{
1761 u32 oid = uwrq[0], u = uwrq[1];
1762
1763 return mgt_set_request((islpci_private *) ndev->priv, oid, 0, &u);
1764}
1765
1766static int
1767prism54_set_raw(struct net_device *ndev, struct iw_request_info *info,
1768 struct iw_point *dwrq, char *extra)
1769{
1770 u32 oid = dwrq->flags;
1771
1772 return mgt_set_request((islpci_private *) ndev->priv, oid, 0, extra);
1773}
1774
1775void
1776prism54_acl_init(struct islpci_acl *acl)
1777{
1778 sema_init(&acl->sem, 1);
1779 INIT_LIST_HEAD(&acl->mac_list);
1780 acl->size = 0;
1781 acl->policy = MAC_POLICY_OPEN;
1782}
1783
1784static void
1785prism54_clear_mac(struct islpci_acl *acl)
1786{
1787 struct list_head *ptr, *next;
1788 struct mac_entry *entry;
1789
1790 if (down_interruptible(&acl->sem))
1791 return;
1792
1793 if (acl->size == 0) {
1794 up(&acl->sem);
1795 return;
1796 }
1797
1798 for (ptr = acl->mac_list.next, next = ptr->next;
1799 ptr != &acl->mac_list; ptr = next, next = ptr->next) {
1800 entry = list_entry(ptr, struct mac_entry, _list);
1801 list_del(ptr);
1802 kfree(entry);
1803 }
1804 acl->size = 0;
1805 up(&acl->sem);
1806}
1807
1808void
1809prism54_acl_clean(struct islpci_acl *acl)
1810{
1811 prism54_clear_mac(acl);
1812}
1813
1814static int
1815prism54_add_mac(struct net_device *ndev, struct iw_request_info *info,
1816 struct sockaddr *awrq, char *extra)
1817{
1818 islpci_private *priv = netdev_priv(ndev);
1819 struct islpci_acl *acl = &priv->acl;
1820 struct mac_entry *entry;
1821 struct sockaddr *addr = (struct sockaddr *) extra;
1822
1823 if (addr->sa_family != ARPHRD_ETHER)
1824 return -EOPNOTSUPP;
1825
1826 entry = kmalloc(sizeof (struct mac_entry), GFP_KERNEL);
1827 if (entry == NULL)
1828 return -ENOMEM;
1829
1830 memcpy(entry->addr, addr->sa_data, ETH_ALEN);
1831
1832 if (down_interruptible(&acl->sem)) {
1833 kfree(entry);
1834 return -ERESTARTSYS;
1835 }
1836 list_add_tail(&entry->_list, &acl->mac_list);
1837 acl->size++;
1838 up(&acl->sem);
1839
1840 return 0;
1841}
1842
1843static int
1844prism54_del_mac(struct net_device *ndev, struct iw_request_info *info,
1845 struct sockaddr *awrq, char *extra)
1846{
1847 islpci_private *priv = netdev_priv(ndev);
1848 struct islpci_acl *acl = &priv->acl;
1849 struct mac_entry *entry;
1850 struct list_head *ptr;
1851 struct sockaddr *addr = (struct sockaddr *) extra;
1852
1853 if (addr->sa_family != ARPHRD_ETHER)
1854 return -EOPNOTSUPP;
1855
1856 if (down_interruptible(&acl->sem))
1857 return -ERESTARTSYS;
1858 for (ptr = acl->mac_list.next; ptr != &acl->mac_list; ptr = ptr->next) {
1859 entry = list_entry(ptr, struct mac_entry, _list);
1860
1861 if (memcmp(entry->addr, addr->sa_data, ETH_ALEN) == 0) {
1862 list_del(ptr);
1863 acl->size--;
1864 kfree(entry);
1865 up(&acl->sem);
1866 return 0;
1867 }
1868 }
1869 up(&acl->sem);
1870 return -EINVAL;
1871}
1872
1873static int
1874prism54_get_mac(struct net_device *ndev, struct iw_request_info *info,
1875 struct iw_point *dwrq, char *extra)
1876{
1877 islpci_private *priv = netdev_priv(ndev);
1878 struct islpci_acl *acl = &priv->acl;
1879 struct mac_entry *entry;
1880 struct list_head *ptr;
1881 struct sockaddr *dst = (struct sockaddr *) extra;
1882
1883 dwrq->length = 0;
1884
1885 if (down_interruptible(&acl->sem))
1886 return -ERESTARTSYS;
1887
1888 for (ptr = acl->mac_list.next; ptr != &acl->mac_list; ptr = ptr->next) {
1889 entry = list_entry(ptr, struct mac_entry, _list);
1890
1891 memcpy(dst->sa_data, entry->addr, ETH_ALEN);
1892 dst->sa_family = ARPHRD_ETHER;
1893 dwrq->length++;
1894 dst++;
1895 }
1896 up(&acl->sem);
1897 return 0;
1898}
1899
1900/* Setting policy also clears the MAC acl, even if we don't change the defaut
1901 * policy
1902 */
1903
1904static int
1905prism54_set_policy(struct net_device *ndev, struct iw_request_info *info,
1906 __u32 * uwrq, char *extra)
1907{
1908 islpci_private *priv = netdev_priv(ndev);
1909 struct islpci_acl *acl = &priv->acl;
1910 u32 mlmeautolevel;
1911
1912 prism54_clear_mac(acl);
1913
1914 if ((*uwrq < MAC_POLICY_OPEN) || (*uwrq > MAC_POLICY_REJECT))
1915 return -EINVAL;
1916
1917 down_write(&priv->mib_sem);
1918
1919 acl->policy = *uwrq;
1920
1921 /* the ACL code needs an intermediate mlmeautolevel */
1922 if ((priv->iw_mode == IW_MODE_MASTER) &&
1923 (acl->policy != MAC_POLICY_OPEN))
1924 mlmeautolevel = DOT11_MLME_INTERMEDIATE;
1925 else
1926 mlmeautolevel = CARD_DEFAULT_MLME_MODE;
1927 if (priv->wpa)
1928 mlmeautolevel = DOT11_MLME_EXTENDED;
1929 mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &mlmeautolevel);
1930 /* restart the card with our new policy */
1931 if (mgt_commit(priv)) {
1932 up_write(&priv->mib_sem);
1933 return -EIO;
1934 }
1935 up_write(&priv->mib_sem);
1936
1937 return 0;
1938}
1939
1940static int
1941prism54_get_policy(struct net_device *ndev, struct iw_request_info *info,
1942 __u32 * uwrq, char *extra)
1943{
1944 islpci_private *priv = netdev_priv(ndev);
1945 struct islpci_acl *acl = &priv->acl;
1946
1947 *uwrq = acl->policy;
1948
1949 return 0;
1950}
1951
1952/* Return 1 only if client should be accepted. */
1953
1954static int
1955prism54_mac_accept(struct islpci_acl *acl, char *mac)
1956{
1957 struct list_head *ptr;
1958 struct mac_entry *entry;
1959 int res = 0;
1960
1961 if (down_interruptible(&acl->sem))
1962 return -ERESTARTSYS;
1963
1964 if (acl->policy == MAC_POLICY_OPEN) {
1965 up(&acl->sem);
1966 return 1;
1967 }
1968
1969 for (ptr = acl->mac_list.next; ptr != &acl->mac_list; ptr = ptr->next) {
1970 entry = list_entry(ptr, struct mac_entry, _list);
1971 if (memcmp(entry->addr, mac, ETH_ALEN) == 0) {
1972 res = 1;
1973 break;
1974 }
1975 }
1976 res = (acl->policy == MAC_POLICY_ACCEPT) ? !res : res;
1977 up(&acl->sem);
1978
1979 return res;
1980}
1981
1982static int
1983prism54_kick_all(struct net_device *ndev, struct iw_request_info *info,
1984 struct iw_point *dwrq, char *extra)
1985{
1986 struct obj_mlme *mlme;
1987 int rvalue;
1988
1989 mlme = kmalloc(sizeof (struct obj_mlme), GFP_KERNEL);
1990 if (mlme == NULL)
1991 return -ENOMEM;
1992
1993 /* Tell the card to kick every client */
1994 mlme->id = 0;
1995 rvalue =
1996 mgt_set_request(netdev_priv(ndev), DOT11_OID_DISASSOCIATE, 0, mlme);
1997 kfree(mlme);
1998
1999 return rvalue;
2000}
2001
2002static int
2003prism54_kick_mac(struct net_device *ndev, struct iw_request_info *info,
2004 struct sockaddr *awrq, char *extra)
2005{
2006 struct obj_mlme *mlme;
2007 struct sockaddr *addr = (struct sockaddr *) extra;
2008 int rvalue;
2009
2010 if (addr->sa_family != ARPHRD_ETHER)
2011 return -EOPNOTSUPP;
2012
2013 mlme = kmalloc(sizeof (struct obj_mlme), GFP_KERNEL);
2014 if (mlme == NULL)
2015 return -ENOMEM;
2016
2017 /* Tell the card to only kick the corresponding bastard */
2018 memcpy(mlme->address, addr->sa_data, ETH_ALEN);
2019 mlme->id = -1;
2020 rvalue =
2021 mgt_set_request(netdev_priv(ndev), DOT11_OID_DISASSOCIATE, 0, mlme);
2022
2023 kfree(mlme);
2024
2025 return rvalue;
2026}
2027
2028/* Translate a TRAP oid into a wireless event. Called in islpci_mgt_receive. */
2029
2030static void
2031format_event(islpci_private *priv, char *dest, const char *str,
2032 const struct obj_mlme *mlme, u16 *length, int error)
2033{
2034 const u8 *a = mlme->address;
2035 int n = snprintf(dest, IW_CUSTOM_MAX,
2036 "%s %s %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X %s (%2.2X)",
2037 str,
2038 ((priv->iw_mode == IW_MODE_MASTER) ? "from" : "to"),
2039 a[0], a[1], a[2], a[3], a[4], a[5],
2040 (error ? (mlme->code ? " : REJECTED " : " : ACCEPTED ")
2041 : ""), mlme->code);
2042 BUG_ON(n > IW_CUSTOM_MAX);
2043 *length = n;
2044}
2045
2046static void
2047send_formatted_event(islpci_private *priv, const char *str,
2048 const struct obj_mlme *mlme, int error)
2049{
2050 union iwreq_data wrqu;
2051 char *memptr;
2052
2053 memptr = kmalloc(IW_CUSTOM_MAX, GFP_KERNEL);
2054 if (!memptr)
2055 return;
2056 wrqu.data.pointer = memptr;
2057 wrqu.data.length = 0;
2058 format_event(priv, memptr, str, mlme, &wrqu.data.length,
2059 error);
2060 wireless_send_event(priv->ndev, IWEVCUSTOM, &wrqu, memptr);
2061 kfree(memptr);
2062}
2063
2064static void
2065send_simple_event(islpci_private *priv, const char *str)
2066{
2067 union iwreq_data wrqu;
2068 char *memptr;
2069 int n = strlen(str);
2070
2071 memptr = kmalloc(IW_CUSTOM_MAX, GFP_KERNEL);
2072 if (!memptr)
2073 return;
2074 BUG_ON(n > IW_CUSTOM_MAX);
2075 wrqu.data.pointer = memptr;
2076 wrqu.data.length = n;
2077 strcpy(memptr, str);
2078 wireless_send_event(priv->ndev, IWEVCUSTOM, &wrqu, memptr);
2079 kfree(memptr);
2080}
2081
2082static void
2083link_changed(struct net_device *ndev, u32 bitrate)
2084{
2085 islpci_private *priv = netdev_priv(ndev);
2086
2087 if (bitrate) {
2088 if (priv->iw_mode == IW_MODE_INFRA) {
2089 union iwreq_data uwrq;
2090 prism54_get_wap(ndev, NULL, (struct sockaddr *) &uwrq,
2091 NULL);
2092 wireless_send_event(ndev, SIOCGIWAP, &uwrq, NULL);
2093 } else
2094 send_simple_event(netdev_priv(ndev),
2095 "Link established");
2096 } else
2097 send_simple_event(netdev_priv(ndev), "Link lost");
2098}
2099
2100/* Beacon/ProbeResp payload header */
2101struct ieee80211_beacon_phdr {
2102 u8 timestamp[8];
2103 u16 beacon_int;
2104 u16 capab_info;
2105} __attribute__ ((packed));
2106
2107#define WLAN_EID_GENERIC 0xdd
2108static u8 wpa_oid[4] = { 0x00, 0x50, 0xf2, 1 };
2109
2110#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
2111#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
2112
2113static void
Dan Williamseab411f2006-07-17 21:21:47 -04002114prism54_wpa_bss_ie_add(islpci_private *priv, u8 *bssid,
2115 u8 *wpa_ie, size_t wpa_ie_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116{
2117 struct list_head *ptr;
2118 struct islpci_bss_wpa_ie *bss = NULL;
2119
2120 if (wpa_ie_len > MAX_WPA_IE_LEN)
2121 wpa_ie_len = MAX_WPA_IE_LEN;
2122
2123 if (down_interruptible(&priv->wpa_sem))
2124 return;
2125
2126 /* try to use existing entry */
2127 list_for_each(ptr, &priv->bss_wpa_list) {
2128 bss = list_entry(ptr, struct islpci_bss_wpa_ie, list);
2129 if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0) {
2130 list_move(&bss->list, &priv->bss_wpa_list);
2131 break;
2132 }
2133 bss = NULL;
2134 }
2135
2136 if (bss == NULL) {
2137 /* add a new BSS entry; if max number of entries is already
2138 * reached, replace the least recently updated */
2139 if (priv->num_bss_wpa >= MAX_BSS_WPA_IE_COUNT) {
2140 bss = list_entry(priv->bss_wpa_list.prev,
2141 struct islpci_bss_wpa_ie, list);
2142 list_del(&bss->list);
2143 } else {
2144 bss = kmalloc(sizeof (*bss), GFP_ATOMIC);
2145 if (bss != NULL) {
2146 priv->num_bss_wpa++;
2147 memset(bss, 0, sizeof (*bss));
2148 }
2149 }
2150 if (bss != NULL) {
2151 memcpy(bss->bssid, bssid, ETH_ALEN);
2152 list_add(&bss->list, &priv->bss_wpa_list);
2153 }
2154 }
2155
2156 if (bss != NULL) {
2157 memcpy(bss->wpa_ie, wpa_ie, wpa_ie_len);
2158 bss->wpa_ie_len = wpa_ie_len;
2159 bss->last_update = jiffies;
2160 } else {
2161 printk(KERN_DEBUG "Failed to add BSS WPA entry for " MACSTR
2162 "\n", MAC2STR(bssid));
2163 }
2164
2165 /* expire old entries from WPA list */
2166 while (priv->num_bss_wpa > 0) {
2167 bss = list_entry(priv->bss_wpa_list.prev,
2168 struct islpci_bss_wpa_ie, list);
2169 if (!time_after(jiffies, bss->last_update + 60 * HZ))
2170 break;
2171
2172 list_del(&bss->list);
2173 priv->num_bss_wpa--;
2174 kfree(bss);
2175 }
2176
2177 up(&priv->wpa_sem);
2178}
2179
2180static size_t
Dan Williamseab411f2006-07-17 21:21:47 -04002181prism54_wpa_bss_ie_get(islpci_private *priv, u8 *bssid, u8 *wpa_ie)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182{
2183 struct list_head *ptr;
2184 struct islpci_bss_wpa_ie *bss = NULL;
2185 size_t len = 0;
2186
2187 if (down_interruptible(&priv->wpa_sem))
2188 return 0;
2189
2190 list_for_each(ptr, &priv->bss_wpa_list) {
2191 bss = list_entry(ptr, struct islpci_bss_wpa_ie, list);
2192 if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0)
2193 break;
2194 bss = NULL;
2195 }
2196 if (bss) {
2197 len = bss->wpa_ie_len;
2198 memcpy(wpa_ie, bss->wpa_ie, len);
2199 }
2200 up(&priv->wpa_sem);
2201
2202 return len;
2203}
2204
2205void
Dan Williamseab411f2006-07-17 21:21:47 -04002206prism54_wpa_bss_ie_init(islpci_private *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207{
2208 INIT_LIST_HEAD(&priv->bss_wpa_list);
2209 sema_init(&priv->wpa_sem, 1);
2210}
2211
2212void
Dan Williamseab411f2006-07-17 21:21:47 -04002213prism54_wpa_bss_ie_clean(islpci_private *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214{
2215 struct list_head *ptr, *n;
2216
2217 list_for_each_safe(ptr, n, &priv->bss_wpa_list) {
2218 struct islpci_bss_wpa_ie *bss;
2219 bss = list_entry(ptr, struct islpci_bss_wpa_ie, list);
2220 kfree(bss);
2221 }
2222}
2223
2224static void
2225prism54_process_bss_data(islpci_private *priv, u32 oid, u8 *addr,
2226 u8 *payload, size_t len)
2227{
2228 struct ieee80211_beacon_phdr *hdr;
2229 u8 *pos, *end;
2230
2231 if (!priv->wpa)
2232 return;
2233
2234 hdr = (struct ieee80211_beacon_phdr *) payload;
2235 pos = (u8 *) (hdr + 1);
2236 end = payload + len;
2237 while (pos < end) {
2238 if (pos + 2 + pos[1] > end) {
2239 printk(KERN_DEBUG "Parsing Beacon/ProbeResp failed "
2240 "for " MACSTR "\n", MAC2STR(addr));
2241 return;
2242 }
2243 if (pos[0] == WLAN_EID_GENERIC && pos[1] >= 4 &&
2244 memcmp(pos + 2, wpa_oid, 4) == 0) {
Dan Williamseab411f2006-07-17 21:21:47 -04002245 prism54_wpa_bss_ie_add(priv, addr, pos, pos[1] + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 return;
2247 }
2248 pos += 2 + pos[1];
2249 }
2250}
2251
2252static void
2253handle_request(islpci_private *priv, struct obj_mlme *mlme, enum oid_num_t oid)
2254{
2255 if (((mlme->state == DOT11_STATE_AUTHING) ||
2256 (mlme->state == DOT11_STATE_ASSOCING))
2257 && mgt_mlme_answer(priv)) {
2258 /* Someone is requesting auth and we must respond. Just send back
2259 * the trap with error code set accordingly.
2260 */
2261 mlme->code = prism54_mac_accept(&priv->acl,
2262 mlme->address) ? 0 : 1;
2263 mgt_set_request(priv, oid, 0, mlme);
2264 }
2265}
2266
2267static int
2268prism54_process_trap_helper(islpci_private *priv, enum oid_num_t oid,
2269 char *data)
2270{
2271 struct obj_mlme *mlme = (struct obj_mlme *) data;
2272 struct obj_mlmeex *mlmeex = (struct obj_mlmeex *) data;
2273 struct obj_mlmeex *confirm;
2274 u8 wpa_ie[MAX_WPA_IE_LEN];
2275 int wpa_ie_len;
2276 size_t len = 0; /* u16, better? */
2277 u8 *payload = NULL, *pos = NULL;
2278 int ret;
2279
2280 /* I think all trapable objects are listed here.
2281 * Some oids have a EX version. The difference is that they are emitted
2282 * in DOT11_MLME_EXTENDED mode (set with DOT11_OID_MLMEAUTOLEVEL)
2283 * with more info.
2284 * The few events already defined by the wireless tools are not really
2285 * suited. We use the more flexible custom event facility.
2286 */
2287
2288 if (oid >= DOT11_OID_BEACON) {
2289 len = mlmeex->size;
2290 payload = pos = mlmeex->data;
2291 }
2292
2293 /* I fear prism54_process_bss_data won't work with big endian data */
2294 if ((oid == DOT11_OID_BEACON) || (oid == DOT11_OID_PROBE))
2295 prism54_process_bss_data(priv, oid, mlmeex->address,
2296 payload, len);
2297
2298 mgt_le_to_cpu(isl_oid[oid].flags & OID_FLAG_TYPE, (void *) mlme);
2299
2300 switch (oid) {
2301
2302 case GEN_OID_LINKSTATE:
2303 link_changed(priv->ndev, (u32) *data);
2304 break;
2305
2306 case DOT11_OID_MICFAILURE:
2307 send_simple_event(priv, "Mic failure");
2308 break;
2309
2310 case DOT11_OID_DEAUTHENTICATE:
2311 send_formatted_event(priv, "DeAuthenticate request", mlme, 0);
2312 break;
2313
2314 case DOT11_OID_AUTHENTICATE:
2315 handle_request(priv, mlme, oid);
2316 send_formatted_event(priv, "Authenticate request", mlme, 1);
2317 break;
2318
2319 case DOT11_OID_DISASSOCIATE:
2320 send_formatted_event(priv, "Disassociate request", mlme, 0);
2321 break;
2322
2323 case DOT11_OID_ASSOCIATE:
2324 handle_request(priv, mlme, oid);
2325 send_formatted_event(priv, "Associate request", mlme, 1);
2326 break;
2327
2328 case DOT11_OID_REASSOCIATE:
2329 handle_request(priv, mlme, oid);
2330 send_formatted_event(priv, "ReAssociate request", mlme, 1);
2331 break;
2332
2333 case DOT11_OID_BEACON:
2334 send_formatted_event(priv,
2335 "Received a beacon from an unkown AP",
2336 mlme, 0);
2337 break;
2338
2339 case DOT11_OID_PROBE:
2340 /* we received a probe from a client. */
2341 send_formatted_event(priv, "Received a probe from client", mlme,
2342 0);
2343 break;
2344
2345 /* Note : "mlme" is actually a "struct obj_mlmeex *" here, but this
2346 * is backward compatible layout-wise with "struct obj_mlme".
2347 */
2348
2349 case DOT11_OID_DEAUTHENTICATEEX:
2350 send_formatted_event(priv, "DeAuthenticate request", mlme, 0);
2351 break;
2352
2353 case DOT11_OID_AUTHENTICATEEX:
2354 handle_request(priv, mlme, oid);
2355 send_formatted_event(priv, "Authenticate request (ex)", mlme, 1);
2356
2357 if (priv->iw_mode != IW_MODE_MASTER
2358 && mlmeex->state != DOT11_STATE_AUTHING)
2359 break;
2360
2361 confirm = kmalloc(sizeof(struct obj_mlmeex) + 6, GFP_ATOMIC);
2362
2363 if (!confirm)
2364 break;
2365
2366 memcpy(&confirm->address, mlmeex->address, ETH_ALEN);
2367 printk(KERN_DEBUG "Authenticate from: address:\t%02x:%02x:%02x:%02x:%02x:%02x\n",
2368 mlmeex->address[0],
2369 mlmeex->address[1],
2370 mlmeex->address[2],
2371 mlmeex->address[3],
2372 mlmeex->address[4],
2373 mlmeex->address[5]
2374 );
2375 confirm->id = -1; /* or mlmeex->id ? */
2376 confirm->state = 0; /* not used */
2377 confirm->code = 0;
2378 confirm->size = 6;
2379 confirm->data[0] = 0x00;
2380 confirm->data[1] = 0x00;
2381 confirm->data[2] = 0x02;
2382 confirm->data[3] = 0x00;
2383 confirm->data[4] = 0x00;
2384 confirm->data[5] = 0x00;
2385
2386 ret = mgt_set_varlen(priv, DOT11_OID_ASSOCIATEEX, confirm, 6);
2387
2388 kfree(confirm);
2389 if (ret)
2390 return ret;
2391 break;
2392
2393 case DOT11_OID_DISASSOCIATEEX:
2394 send_formatted_event(priv, "Disassociate request (ex)", mlme, 0);
2395 break;
2396
2397 case DOT11_OID_ASSOCIATEEX:
2398 handle_request(priv, mlme, oid);
2399 send_formatted_event(priv, "Associate request (ex)", mlme, 1);
2400
2401 if (priv->iw_mode != IW_MODE_MASTER
Dan Williamseab411f2006-07-17 21:21:47 -04002402 && mlmeex->state != DOT11_STATE_ASSOCING)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 break;
2404
2405 confirm = kmalloc(sizeof(struct obj_mlmeex), GFP_ATOMIC);
2406
2407 if (!confirm)
2408 break;
2409
2410 memcpy(&confirm->address, mlmeex->address, ETH_ALEN);
2411
2412 confirm->id = ((struct obj_mlmeex *)mlme)->id;
2413 confirm->state = 0; /* not used */
2414 confirm->code = 0;
2415
Dan Williamseab411f2006-07-17 21:21:47 -04002416 wpa_ie_len = prism54_wpa_bss_ie_get(priv, mlmeex->address, wpa_ie);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417
2418 if (!wpa_ie_len) {
2419 printk(KERN_DEBUG "No WPA IE found from "
2420 "address:\t%02x:%02x:%02x:%02x:%02x:%02x\n",
2421 mlmeex->address[0],
2422 mlmeex->address[1],
2423 mlmeex->address[2],
2424 mlmeex->address[3],
2425 mlmeex->address[4],
2426 mlmeex->address[5]
2427 );
2428 kfree(confirm);
2429 break;
2430 }
2431
2432 confirm->size = wpa_ie_len;
2433 memcpy(&confirm->data, wpa_ie, wpa_ie_len);
2434
2435 mgt_set_varlen(priv, oid, confirm, wpa_ie_len);
2436
2437 kfree(confirm);
2438
2439 break;
2440
2441 case DOT11_OID_REASSOCIATEEX:
2442 handle_request(priv, mlme, oid);
2443 send_formatted_event(priv, "Reassociate request (ex)", mlme, 1);
2444
2445 if (priv->iw_mode != IW_MODE_MASTER
2446 && mlmeex->state != DOT11_STATE_ASSOCING)
2447 break;
2448
2449 confirm = kmalloc(sizeof(struct obj_mlmeex), GFP_ATOMIC);
2450
2451 if (!confirm)
2452 break;
2453
2454 memcpy(&confirm->address, mlmeex->address, ETH_ALEN);
2455
2456 confirm->id = mlmeex->id;
2457 confirm->state = 0; /* not used */
2458 confirm->code = 0;
2459
Dan Williamseab411f2006-07-17 21:21:47 -04002460 wpa_ie_len = prism54_wpa_bss_ie_get(priv, mlmeex->address, wpa_ie);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461
2462 if (!wpa_ie_len) {
2463 printk(KERN_DEBUG "No WPA IE found from "
2464 "address:\t%02x:%02x:%02x:%02x:%02x:%02x\n",
2465 mlmeex->address[0],
2466 mlmeex->address[1],
2467 mlmeex->address[2],
2468 mlmeex->address[3],
2469 mlmeex->address[4],
2470 mlmeex->address[5]
2471 );
2472 kfree(confirm);
2473 break;
2474 }
2475
2476 confirm->size = wpa_ie_len;
2477 memcpy(&confirm->data, wpa_ie, wpa_ie_len);
2478
2479 mgt_set_varlen(priv, oid, confirm, wpa_ie_len);
2480
2481 kfree(confirm);
2482
2483 break;
2484
2485 default:
2486 return -EINVAL;
2487 }
2488
2489 return 0;
2490}
2491
2492/*
2493 * Process a device trap. This is called via schedule_work(), outside of
2494 * interrupt context, no locks held.
2495 */
2496void
2497prism54_process_trap(void *data)
2498{
2499 struct islpci_mgmtframe *frame = data;
2500 struct net_device *ndev = frame->ndev;
2501 enum oid_num_t n = mgt_oidtonum(frame->header->oid);
2502
2503 if (n != OID_NUM_LAST)
2504 prism54_process_trap_helper(netdev_priv(ndev), n, frame->data);
2505 islpci_mgt_release(frame);
2506}
2507
2508int
2509prism54_set_mac_address(struct net_device *ndev, void *addr)
2510{
2511 islpci_private *priv = netdev_priv(ndev);
2512 int ret;
2513
2514 if (ndev->addr_len != 6)
2515 return -EINVAL;
2516 ret = mgt_set_request(priv, GEN_OID_MACADDRESS, 0,
2517 &((struct sockaddr *) addr)->sa_data);
2518 if (!ret)
2519 memcpy(priv->ndev->dev_addr,
2520 &((struct sockaddr *) addr)->sa_data, 6);
2521
2522 return ret;
2523}
2524
2525/* Note: currently, use hostapd ioctl from the Host AP driver for WPA
2526 * support. This is to be replaced with Linux wireless extensions once they
2527 * get WPA support. */
2528
2529/* Note II: please leave all this together as it will be easier to remove later,
2530 * once wireless extensions add WPA support -mcgrof */
2531
2532/* PRISM54_HOSTAPD ioctl() cmd: */
2533enum {
2534 PRISM2_SET_ENCRYPTION = 6,
2535 PRISM2_HOSTAPD_SET_GENERIC_ELEMENT = 12,
2536 PRISM2_HOSTAPD_MLME = 13,
2537 PRISM2_HOSTAPD_SCAN_REQ = 14,
2538};
2539
2540#define PRISM54_SET_WPA SIOCIWFIRSTPRIV+12
2541#define PRISM54_HOSTAPD SIOCIWFIRSTPRIV+25
2542#define PRISM54_DROP_UNENCRYPTED SIOCIWFIRSTPRIV+26
2543
2544#define PRISM2_HOSTAPD_MAX_BUF_SIZE 1024
2545#define PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN \
2546((int) (&((struct prism2_hostapd_param *) 0)->u.generic_elem.data))
2547
2548/* Maximum length for algorithm names (-1 for nul termination)
2549 * used in ioctl() */
2550#define HOSTAP_CRYPT_ALG_NAME_LEN 16
2551
2552struct prism2_hostapd_param {
2553 u32 cmd;
2554 u8 sta_addr[ETH_ALEN];
2555 union {
2556 struct {
2557 u8 alg[HOSTAP_CRYPT_ALG_NAME_LEN];
2558 u32 flags;
2559 u32 err;
2560 u8 idx;
2561 u8 seq[8]; /* sequence counter (set: RX, get: TX) */
2562 u16 key_len;
2563 u8 key[0];
2564 } crypt;
2565 struct {
2566 u8 len;
2567 u8 data[0];
2568 } generic_elem;
2569 struct {
2570#define MLME_STA_DEAUTH 0
2571#define MLME_STA_DISASSOC 1
2572 u16 cmd;
2573 u16 reason_code;
2574 } mlme;
2575 struct {
2576 u8 ssid_len;
2577 u8 ssid[32];
2578 } scan_req;
2579 } u;
2580};
2581
2582
2583static int
2584prism2_ioctl_set_encryption(struct net_device *dev,
2585 struct prism2_hostapd_param *param,
2586 int param_len)
2587{
2588 islpci_private *priv = netdev_priv(dev);
2589 int rvalue = 0, force = 0;
2590 int authen = DOT11_AUTH_OS, invoke = 0, exunencrypt = 0;
2591 union oid_res_t r;
2592
2593 /* with the new API, it's impossible to get a NULL pointer.
2594 * New version of iwconfig set the IW_ENCODE_NOKEY flag
2595 * when no key is given, but older versions don't. */
2596
2597 if (param->u.crypt.key_len > 0) {
2598 /* we have a key to set */
2599 int index = param->u.crypt.idx;
2600 int current_index;
2601 struct obj_key key = { DOT11_PRIV_TKIP, 0, "" };
2602
2603 /* get the current key index */
2604 rvalue = mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r);
2605 current_index = r.u;
2606 /* Verify that the key is not marked as invalid */
2607 if (!(param->u.crypt.flags & IW_ENCODE_NOKEY)) {
2608 key.length = param->u.crypt.key_len > sizeof (param->u.crypt.key) ?
2609 sizeof (param->u.crypt.key) : param->u.crypt.key_len;
2610 memcpy(key.key, param->u.crypt.key, key.length);
2611 if (key.length == 32)
2612 /* we want WPA-PSK */
2613 key.type = DOT11_PRIV_TKIP;
2614 if ((index < 0) || (index > 3))
2615 /* no index provided use the current one */
2616 index = current_index;
2617
2618 /* now send the key to the card */
2619 rvalue |=
2620 mgt_set_request(priv, DOT11_OID_DEFKEYX, index,
2621 &key);
2622 }
2623 /*
2624 * If a valid key is set, encryption should be enabled
2625 * (user may turn it off later).
2626 * This is also how "iwconfig ethX key on" works
2627 */
2628 if ((index == current_index) && (key.length > 0))
2629 force = 1;
2630 } else {
2631 int index = (param->u.crypt.flags & IW_ENCODE_INDEX) - 1;
2632 if ((index >= 0) && (index <= 3)) {
2633 /* we want to set the key index */
2634 rvalue |=
2635 mgt_set_request(priv, DOT11_OID_DEFKEYID, 0,
2636 &index);
2637 } else {
2638 if (!param->u.crypt.flags & IW_ENCODE_MODE) {
2639 /* we cannot do anything. Complain. */
2640 return -EINVAL;
2641 }
2642 }
2643 }
2644 /* now read the flags */
2645 if (param->u.crypt.flags & IW_ENCODE_DISABLED) {
2646 /* Encoding disabled,
2647 * authen = DOT11_AUTH_OS;
2648 * invoke = 0;
2649 * exunencrypt = 0; */
2650 }
2651 if (param->u.crypt.flags & IW_ENCODE_OPEN)
2652 /* Encode but accept non-encoded packets. No auth */
2653 invoke = 1;
2654 if ((param->u.crypt.flags & IW_ENCODE_RESTRICTED) || force) {
2655 /* Refuse non-encoded packets. Auth */
2656 authen = DOT11_AUTH_BOTH;
2657 invoke = 1;
2658 exunencrypt = 1;
2659 }
2660 /* do the change if requested */
2661 if ((param->u.crypt.flags & IW_ENCODE_MODE) || force) {
2662 rvalue |=
2663 mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0, &authen);
2664 rvalue |=
2665 mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0, &invoke);
2666 rvalue |=
2667 mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0,
2668 &exunencrypt);
2669 }
2670 return rvalue;
2671}
2672
2673static int
2674prism2_ioctl_set_generic_element(struct net_device *ndev,
2675 struct prism2_hostapd_param *param,
2676 int param_len)
2677{
2678 islpci_private *priv = netdev_priv(ndev);
2679 int max_len, len, alen, ret=0;
2680 struct obj_attachment *attach;
2681
2682 len = param->u.generic_elem.len;
2683 max_len = param_len - PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN;
2684 if (max_len < 0 || max_len < len)
2685 return -EINVAL;
2686
2687 alen = sizeof(*attach) + len;
2688 attach = kmalloc(alen, GFP_KERNEL);
2689 if (attach == NULL)
2690 return -ENOMEM;
2691
2692 memset(attach, 0, alen);
2693#define WLAN_FC_TYPE_MGMT 0
2694#define WLAN_FC_STYPE_ASSOC_REQ 0
2695#define WLAN_FC_STYPE_REASSOC_REQ 2
2696
2697 /* Note: endianness is covered by mgt_set_varlen */
2698
2699 attach->type = (WLAN_FC_TYPE_MGMT << 2) |
2700 (WLAN_FC_STYPE_ASSOC_REQ << 4);
2701 attach->id = -1;
2702 attach->size = len;
2703 memcpy(attach->data, param->u.generic_elem.data, len);
2704
2705 ret = mgt_set_varlen(priv, DOT11_OID_ATTACHMENT, attach, len);
2706
2707 if (ret == 0) {
2708 attach->type = (WLAN_FC_TYPE_MGMT << 2) |
2709 (WLAN_FC_STYPE_REASSOC_REQ << 4);
2710
2711 ret = mgt_set_varlen(priv, DOT11_OID_ATTACHMENT, attach, len);
2712
2713 if (ret == 0)
2714 printk(KERN_DEBUG "%s: WPA IE Attachment was set\n",
2715 ndev->name);
2716 }
2717
2718 kfree(attach);
2719 return ret;
2720
2721}
2722
2723static int
2724prism2_ioctl_mlme(struct net_device *dev, struct prism2_hostapd_param *param)
2725{
2726 return -EOPNOTSUPP;
2727}
2728
2729static int
2730prism2_ioctl_scan_req(struct net_device *ndev,
2731 struct prism2_hostapd_param *param)
2732{
2733 islpci_private *priv = netdev_priv(ndev);
2734 int i, rvalue;
2735 struct obj_bsslist *bsslist;
2736 u32 noise = 0;
2737 char *extra = "";
2738 char *current_ev = "foo";
2739 union oid_res_t r;
2740
2741 if (islpci_get_state(priv) < PRV_STATE_INIT) {
2742 /* device is not ready, fail gently */
2743 return 0;
2744 }
2745
2746 /* first get the noise value. We will use it to report the link quality */
2747 rvalue = mgt_get_request(priv, DOT11_OID_NOISEFLOOR, 0, NULL, &r);
2748 noise = r.u;
2749
2750 /* Ask the device for a list of known bss. We can report at most
2751 * IW_MAX_AP=64 to the range struct. But the device won't repport anything
2752 * if you change the value of IWMAX_BSS=24.
2753 */
2754 rvalue |= mgt_get_request(priv, DOT11_OID_BSSLIST, 0, NULL, &r);
2755 bsslist = r.ptr;
2756
2757 /* ok now, scan the list and translate its info */
2758 for (i = 0; i < min(IW_MAX_AP, (int) bsslist->nr); i++)
2759 current_ev = prism54_translate_bss(ndev, current_ev,
2760 extra + IW_SCAN_MAX_DATA,
2761 &(bsslist->bsslist[i]),
2762 noise);
2763 kfree(bsslist);
2764
2765 return rvalue;
2766}
2767
2768static int
2769prism54_hostapd(struct net_device *ndev, struct iw_point *p)
2770{
2771 struct prism2_hostapd_param *param;
2772 int ret = 0;
2773 u32 uwrq;
2774
2775 printk(KERN_DEBUG "prism54_hostapd - len=%d\n", p->length);
2776 if (p->length < sizeof(struct prism2_hostapd_param) ||
2777 p->length > PRISM2_HOSTAPD_MAX_BUF_SIZE || !p->pointer)
2778 return -EINVAL;
2779
2780 param = (struct prism2_hostapd_param *) kmalloc(p->length, GFP_KERNEL);
2781 if (param == NULL)
2782 return -ENOMEM;
2783
2784 if (copy_from_user(param, p->pointer, p->length)) {
2785 kfree(param);
2786 return -EFAULT;
2787 }
2788
2789 switch (param->cmd) {
2790 case PRISM2_SET_ENCRYPTION:
2791 printk(KERN_DEBUG "%s: Caught WPA supplicant set encryption request\n",
2792 ndev->name);
2793 ret = prism2_ioctl_set_encryption(ndev, param, p->length);
2794 break;
2795 case PRISM2_HOSTAPD_SET_GENERIC_ELEMENT:
2796 printk(KERN_DEBUG "%s: Caught WPA supplicant set WPA IE request\n",
2797 ndev->name);
2798 ret = prism2_ioctl_set_generic_element(ndev, param,
2799 p->length);
2800 break;
2801 case PRISM2_HOSTAPD_MLME:
2802 printk(KERN_DEBUG "%s: Caught WPA supplicant MLME request\n",
2803 ndev->name);
2804 ret = prism2_ioctl_mlme(ndev, param);
2805 break;
2806 case PRISM2_HOSTAPD_SCAN_REQ:
2807 printk(KERN_DEBUG "%s: Caught WPA supplicant scan request\n",
2808 ndev->name);
2809 ret = prism2_ioctl_scan_req(ndev, param);
2810 break;
2811 case PRISM54_SET_WPA:
2812 printk(KERN_DEBUG "%s: Caught WPA supplicant wpa init request\n",
2813 ndev->name);
2814 uwrq = 1;
2815 ret = prism54_set_wpa(ndev, NULL, &uwrq, NULL);
2816 break;
2817 case PRISM54_DROP_UNENCRYPTED:
2818 printk(KERN_DEBUG "%s: Caught WPA drop unencrypted request\n",
2819 ndev->name);
2820#if 0
2821 uwrq = 0x01;
2822 mgt_set(priv, DOT11_OID_EXUNENCRYPTED, &uwrq);
2823 down_write(&priv->mib_sem);
2824 mgt_commit(priv);
2825 up_write(&priv->mib_sem);
2826#endif
2827 /* Not necessary, as set_wpa does it, should we just do it here though? */
2828 ret = 0;
2829 break;
2830 default:
2831 printk(KERN_DEBUG "%s: Caught a WPA supplicant request that is not supported\n",
2832 ndev->name);
2833 ret = -EOPNOTSUPP;
2834 break;
2835 }
2836
2837 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
2838 ret = -EFAULT;
2839
2840 kfree(param);
2841
2842 return ret;
2843}
2844
2845static int
2846prism54_set_wpa(struct net_device *ndev, struct iw_request_info *info,
2847 __u32 * uwrq, char *extra)
2848{
2849 islpci_private *priv = netdev_priv(ndev);
2850 u32 mlme, authen, dot1x, filter, wep;
2851
2852 if (islpci_get_state(priv) < PRV_STATE_INIT)
2853 return 0;
2854
2855 wep = 1; /* For privacy invoked */
2856 filter = 1; /* Filter out all unencrypted frames */
2857 dot1x = 0x01; /* To enable eap filter */
2858 mlme = DOT11_MLME_EXTENDED;
2859 authen = DOT11_AUTH_OS; /* Only WEP uses _SK and _BOTH */
2860
2861 down_write(&priv->mib_sem);
2862 priv->wpa = *uwrq;
2863
2864 switch (priv->wpa) {
2865 default:
2866 case 0: /* Clears/disables WPA and friends */
2867 wep = 0;
2868 filter = 0; /* Do not filter un-encrypted data */
2869 dot1x = 0;
2870 mlme = DOT11_MLME_AUTO;
2871 printk("%s: Disabling WPA\n", ndev->name);
2872 break;
2873 case 2:
2874 case 1: /* WPA */
2875 printk("%s: Enabling WPA\n", ndev->name);
2876 break;
2877 }
2878 up_write(&priv->mib_sem);
2879
2880 mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0, &authen);
2881 mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0, &wep);
2882 mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0, &filter);
2883 mgt_set_request(priv, DOT11_OID_DOT1XENABLE, 0, &dot1x);
2884 mgt_set_request(priv, DOT11_OID_MLMEAUTOLEVEL, 0, &mlme);
2885
2886 return 0;
2887}
2888
2889static int
2890prism54_get_wpa(struct net_device *ndev, struct iw_request_info *info,
2891 __u32 * uwrq, char *extra)
2892{
2893 islpci_private *priv = netdev_priv(ndev);
2894 *uwrq = priv->wpa;
2895 return 0;
2896}
2897
2898static int
2899prism54_set_prismhdr(struct net_device *ndev, struct iw_request_info *info,
2900 __u32 * uwrq, char *extra)
2901{
2902 islpci_private *priv = netdev_priv(ndev);
2903 priv->monitor_type =
2904 (*uwrq ? ARPHRD_IEEE80211_PRISM : ARPHRD_IEEE80211);
2905 if (priv->iw_mode == IW_MODE_MONITOR)
2906 priv->ndev->type = priv->monitor_type;
2907
2908 return 0;
2909}
2910
2911static int
2912prism54_get_prismhdr(struct net_device *ndev, struct iw_request_info *info,
2913 __u32 * uwrq, char *extra)
2914{
2915 islpci_private *priv = netdev_priv(ndev);
2916 *uwrq = (priv->monitor_type == ARPHRD_IEEE80211_PRISM);
2917 return 0;
2918}
2919
2920static int
2921prism54_debug_oid(struct net_device *ndev, struct iw_request_info *info,
2922 __u32 * uwrq, char *extra)
2923{
2924 islpci_private *priv = netdev_priv(ndev);
2925
2926 priv->priv_oid = *uwrq;
2927 printk("%s: oid 0x%08X\n", ndev->name, *uwrq);
2928
2929 return 0;
2930}
2931
2932static int
2933prism54_debug_get_oid(struct net_device *ndev, struct iw_request_info *info,
2934 struct iw_point *data, char *extra)
2935{
2936 islpci_private *priv = netdev_priv(ndev);
2937 struct islpci_mgmtframe *response;
2938 int ret = -EIO;
2939
2940 printk("%s: get_oid 0x%08X\n", ndev->name, priv->priv_oid);
2941 data->length = 0;
2942
2943 if (islpci_get_state(priv) >= PRV_STATE_INIT) {
2944 ret =
2945 islpci_mgt_transaction(priv->ndev, PIMFOR_OP_GET,
2946 priv->priv_oid, extra, 256,
2947 &response);
2948 printk("%s: ret: %i\n", ndev->name, ret);
2949 if (ret || !response
2950 || response->header->operation == PIMFOR_OP_ERROR) {
2951 if (response) {
2952 islpci_mgt_release(response);
2953 }
2954 printk("%s: EIO\n", ndev->name);
2955 ret = -EIO;
2956 }
2957 if (!ret) {
2958 data->length = response->header->length;
2959 memcpy(extra, response->data, data->length);
2960 islpci_mgt_release(response);
2961 printk("%s: len: %i\n", ndev->name, data->length);
2962 }
2963 }
2964
2965 return ret;
2966}
2967
2968static int
2969prism54_debug_set_oid(struct net_device *ndev, struct iw_request_info *info,
2970 struct iw_point *data, char *extra)
2971{
2972 islpci_private *priv = netdev_priv(ndev);
2973 struct islpci_mgmtframe *response;
2974 int ret = 0, response_op = PIMFOR_OP_ERROR;
2975
2976 printk("%s: set_oid 0x%08X\tlen: %d\n", ndev->name, priv->priv_oid,
2977 data->length);
2978
2979 if (islpci_get_state(priv) >= PRV_STATE_INIT) {
2980 ret =
2981 islpci_mgt_transaction(priv->ndev, PIMFOR_OP_SET,
2982 priv->priv_oid, extra, data->length,
2983 &response);
2984 printk("%s: ret: %i\n", ndev->name, ret);
2985 if (ret || !response
2986 || response->header->operation == PIMFOR_OP_ERROR) {
2987 if (response) {
2988 islpci_mgt_release(response);
2989 }
2990 printk("%s: EIO\n", ndev->name);
2991 ret = -EIO;
2992 }
2993 if (!ret) {
2994 response_op = response->header->operation;
2995 printk("%s: response_op: %i\n", ndev->name,
2996 response_op);
2997 islpci_mgt_release(response);
2998 }
2999 }
3000
3001 return (ret ? ret : -EINPROGRESS);
3002}
3003
3004static int
3005prism54_set_spy(struct net_device *ndev,
3006 struct iw_request_info *info,
3007 union iwreq_data *uwrq, char *extra)
3008{
3009 islpci_private *priv = netdev_priv(ndev);
3010 u32 u, oid = OID_INL_CONFIG;
3011
3012 down_write(&priv->mib_sem);
3013 mgt_get(priv, OID_INL_CONFIG, &u);
3014
3015 if ((uwrq->data.length == 0) && (priv->spy_data.spy_number > 0))
3016 /* disable spy */
3017 u &= ~INL_CONFIG_RXANNEX;
3018 else if ((uwrq->data.length > 0) && (priv->spy_data.spy_number == 0))
3019 /* enable spy */
3020 u |= INL_CONFIG_RXANNEX;
3021
3022 mgt_set(priv, OID_INL_CONFIG, &u);
3023 mgt_commit_list(priv, &oid, 1);
3024 up_write(&priv->mib_sem);
3025
3026 return iw_handler_set_spy(ndev, info, uwrq, extra);
3027}
3028
3029static const iw_handler prism54_handler[] = {
3030 (iw_handler) prism54_commit, /* SIOCSIWCOMMIT */
3031 (iw_handler) prism54_get_name, /* SIOCGIWNAME */
3032 (iw_handler) NULL, /* SIOCSIWNWID */
3033 (iw_handler) NULL, /* SIOCGIWNWID */
3034 (iw_handler) prism54_set_freq, /* SIOCSIWFREQ */
3035 (iw_handler) prism54_get_freq, /* SIOCGIWFREQ */
3036 (iw_handler) prism54_set_mode, /* SIOCSIWMODE */
3037 (iw_handler) prism54_get_mode, /* SIOCGIWMODE */
3038 (iw_handler) prism54_set_sens, /* SIOCSIWSENS */
3039 (iw_handler) prism54_get_sens, /* SIOCGIWSENS */
3040 (iw_handler) NULL, /* SIOCSIWRANGE */
3041 (iw_handler) prism54_get_range, /* SIOCGIWRANGE */
3042 (iw_handler) NULL, /* SIOCSIWPRIV */
3043 (iw_handler) NULL, /* SIOCGIWPRIV */
3044 (iw_handler) NULL, /* SIOCSIWSTATS */
3045 (iw_handler) NULL, /* SIOCGIWSTATS */
3046 prism54_set_spy, /* SIOCSIWSPY */
3047 iw_handler_get_spy, /* SIOCGIWSPY */
3048 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
3049 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
3050 (iw_handler) prism54_set_wap, /* SIOCSIWAP */
3051 (iw_handler) prism54_get_wap, /* SIOCGIWAP */
3052 (iw_handler) NULL, /* -- hole -- */
3053 (iw_handler) NULL, /* SIOCGIWAPLIST depreciated */
3054 (iw_handler) prism54_set_scan, /* SIOCSIWSCAN */
3055 (iw_handler) prism54_get_scan, /* SIOCGIWSCAN */
3056 (iw_handler) prism54_set_essid, /* SIOCSIWESSID */
3057 (iw_handler) prism54_get_essid, /* SIOCGIWESSID */
3058 (iw_handler) prism54_set_nick, /* SIOCSIWNICKN */
3059 (iw_handler) prism54_get_nick, /* SIOCGIWNICKN */
3060 (iw_handler) NULL, /* -- hole -- */
3061 (iw_handler) NULL, /* -- hole -- */
3062 (iw_handler) prism54_set_rate, /* SIOCSIWRATE */
3063 (iw_handler) prism54_get_rate, /* SIOCGIWRATE */
3064 (iw_handler) prism54_set_rts, /* SIOCSIWRTS */
3065 (iw_handler) prism54_get_rts, /* SIOCGIWRTS */
3066 (iw_handler) prism54_set_frag, /* SIOCSIWFRAG */
3067 (iw_handler) prism54_get_frag, /* SIOCGIWFRAG */
3068 (iw_handler) prism54_set_txpower, /* SIOCSIWTXPOW */
3069 (iw_handler) prism54_get_txpower, /* SIOCGIWTXPOW */
3070 (iw_handler) prism54_set_retry, /* SIOCSIWRETRY */
3071 (iw_handler) prism54_get_retry, /* SIOCGIWRETRY */
3072 (iw_handler) prism54_set_encode, /* SIOCSIWENCODE */
3073 (iw_handler) prism54_get_encode, /* SIOCGIWENCODE */
3074 (iw_handler) NULL, /* SIOCSIWPOWER */
3075 (iw_handler) NULL, /* SIOCGIWPOWER */
Dan Williamseab411f2006-07-17 21:21:47 -04003076 NULL, /* -- hole -- */
3077 NULL, /* -- hole -- */
3078 (iw_handler) prism54_set_genie, /* SIOCSIWGENIE */
3079 (iw_handler) prism54_get_genie, /* SIOCGIWGENIE */
3080 (iw_handler) prism54_set_auth, /* SIOCSIWAUTH */
3081 (iw_handler) prism54_get_auth, /* SIOCGIWAUTH */
3082 (iw_handler) prism54_set_encodeext, /* SIOCSIWENCODEEXT */
3083 (iw_handler) prism54_get_encodeext, /* SIOCGIWENCODEEXT */
3084 NULL, /* SIOCSIWPMKSA */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085};
3086
3087/* The low order bit identify a SET (0) or a GET (1) ioctl. */
3088
3089#define PRISM54_RESET SIOCIWFIRSTPRIV
3090#define PRISM54_GET_POLICY SIOCIWFIRSTPRIV+1
3091#define PRISM54_SET_POLICY SIOCIWFIRSTPRIV+2
3092#define PRISM54_GET_MAC SIOCIWFIRSTPRIV+3
3093#define PRISM54_ADD_MAC SIOCIWFIRSTPRIV+4
3094
3095#define PRISM54_DEL_MAC SIOCIWFIRSTPRIV+6
3096
3097#define PRISM54_KICK_MAC SIOCIWFIRSTPRIV+8
3098
3099#define PRISM54_KICK_ALL SIOCIWFIRSTPRIV+10
3100
3101#define PRISM54_GET_WPA SIOCIWFIRSTPRIV+11
3102#define PRISM54_SET_WPA SIOCIWFIRSTPRIV+12
3103
3104#define PRISM54_DBG_OID SIOCIWFIRSTPRIV+14
3105#define PRISM54_DBG_GET_OID SIOCIWFIRSTPRIV+15
3106#define PRISM54_DBG_SET_OID SIOCIWFIRSTPRIV+16
3107
3108#define PRISM54_GET_OID SIOCIWFIRSTPRIV+17
3109#define PRISM54_SET_OID_U32 SIOCIWFIRSTPRIV+18
3110#define PRISM54_SET_OID_STR SIOCIWFIRSTPRIV+20
3111#define PRISM54_SET_OID_ADDR SIOCIWFIRSTPRIV+22
3112
3113#define PRISM54_GET_PRISMHDR SIOCIWFIRSTPRIV+23
3114#define PRISM54_SET_PRISMHDR SIOCIWFIRSTPRIV+24
3115
3116#define IWPRIV_SET_U32(n,x) { n, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "s_"x }
3117#define IWPRIV_SET_SSID(n,x) { n, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 1, 0, "s_"x }
3118#define IWPRIV_SET_ADDR(n,x) { n, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "s_"x }
3119#define IWPRIV_GET(n,x) { n, 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | PRIV_STR_SIZE, "g_"x }
3120
3121#define IWPRIV_U32(n,x) IWPRIV_SET_U32(n,x), IWPRIV_GET(n,x)
3122#define IWPRIV_SSID(n,x) IWPRIV_SET_SSID(n,x), IWPRIV_GET(n,x)
3123#define IWPRIV_ADDR(n,x) IWPRIV_SET_ADDR(n,x), IWPRIV_GET(n,x)
3124
3125/* Note : limited to 128 private ioctls (wireless tools 26) */
3126
3127static const struct iw_priv_args prism54_private_args[] = {
3128/*{ cmd, set_args, get_args, name } */
3129 {PRISM54_RESET, 0, 0, "reset"},
3130 {PRISM54_GET_PRISMHDR, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3131 "get_prismhdr"},
3132 {PRISM54_SET_PRISMHDR, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0,
3133 "set_prismhdr"},
3134 {PRISM54_GET_POLICY, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3135 "getPolicy"},
3136 {PRISM54_SET_POLICY, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0,
3137 "setPolicy"},
3138 {PRISM54_GET_MAC, 0, IW_PRIV_TYPE_ADDR | 64, "getMac"},
3139 {PRISM54_ADD_MAC, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0,
3140 "addMac"},
3141 {PRISM54_DEL_MAC, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0,
3142 "delMac"},
3143 {PRISM54_KICK_MAC, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0,
3144 "kickMac"},
3145 {PRISM54_KICK_ALL, 0, 0, "kickAll"},
3146 {PRISM54_GET_WPA, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3147 "get_wpa"},
3148 {PRISM54_SET_WPA, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0,
3149 "set_wpa"},
3150 {PRISM54_DBG_OID, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0,
3151 "dbg_oid"},
3152 {PRISM54_DBG_GET_OID, 0, IW_PRIV_TYPE_BYTE | 256, "dbg_get_oid"},
3153 {PRISM54_DBG_SET_OID, IW_PRIV_TYPE_BYTE | 256, 0, "dbg_set_oid"},
3154 /* --- sub-ioctls handlers --- */
3155 {PRISM54_GET_OID,
3156 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | PRIV_STR_SIZE, ""},
3157 {PRISM54_SET_OID_U32,
3158 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, ""},
3159 {PRISM54_SET_OID_STR,
3160 IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 1, 0, ""},
3161 {PRISM54_SET_OID_ADDR,
3162 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, ""},
3163 /* --- sub-ioctls definitions --- */
3164 IWPRIV_ADDR(GEN_OID_MACADDRESS, "addr"),
3165 IWPRIV_GET(GEN_OID_LINKSTATE, "linkstate"),
3166 IWPRIV_U32(DOT11_OID_BSSTYPE, "bsstype"),
3167 IWPRIV_ADDR(DOT11_OID_BSSID, "bssid"),
3168 IWPRIV_U32(DOT11_OID_STATE, "state"),
3169 IWPRIV_U32(DOT11_OID_AID, "aid"),
3170
3171 IWPRIV_SSID(DOT11_OID_SSIDOVERRIDE, "ssidoverride"),
3172
3173 IWPRIV_U32(DOT11_OID_MEDIUMLIMIT, "medlimit"),
3174 IWPRIV_U32(DOT11_OID_BEACONPERIOD, "beacon"),
3175 IWPRIV_U32(DOT11_OID_DTIMPERIOD, "dtimperiod"),
3176
3177 IWPRIV_U32(DOT11_OID_AUTHENABLE, "authenable"),
3178 IWPRIV_U32(DOT11_OID_PRIVACYINVOKED, "privinvok"),
3179 IWPRIV_U32(DOT11_OID_EXUNENCRYPTED, "exunencrypt"),
3180
3181 IWPRIV_U32(DOT11_OID_REKEYTHRESHOLD, "rekeythresh"),
3182
3183 IWPRIV_U32(DOT11_OID_MAXTXLIFETIME, "maxtxlife"),
3184 IWPRIV_U32(DOT11_OID_MAXRXLIFETIME, "maxrxlife"),
3185 IWPRIV_U32(DOT11_OID_ALOFT_FIXEDRATE, "fixedrate"),
3186 IWPRIV_U32(DOT11_OID_MAXFRAMEBURST, "frameburst"),
3187 IWPRIV_U32(DOT11_OID_PSM, "psm"),
3188
3189 IWPRIV_U32(DOT11_OID_BRIDGELOCAL, "bridge"),
3190 IWPRIV_U32(DOT11_OID_CLIENTS, "clients"),
3191 IWPRIV_U32(DOT11_OID_CLIENTSASSOCIATED, "clientassoc"),
3192 IWPRIV_U32(DOT11_OID_DOT1XENABLE, "dot1xenable"),
3193 IWPRIV_U32(DOT11_OID_ANTENNARX, "rxant"),
3194 IWPRIV_U32(DOT11_OID_ANTENNATX, "txant"),
3195 IWPRIV_U32(DOT11_OID_ANTENNADIVERSITY, "antdivers"),
3196 IWPRIV_U32(DOT11_OID_EDTHRESHOLD, "edthresh"),
3197 IWPRIV_U32(DOT11_OID_PREAMBLESETTINGS, "preamble"),
3198 IWPRIV_GET(DOT11_OID_RATES, "rates"),
3199 IWPRIV_U32(DOT11_OID_OUTPUTPOWER, ".11outpower"),
3200 IWPRIV_GET(DOT11_OID_SUPPORTEDRATES, "supprates"),
3201 IWPRIV_GET(DOT11_OID_SUPPORTEDFREQUENCIES, "suppfreq"),
3202
3203 IWPRIV_U32(DOT11_OID_NOISEFLOOR, "noisefloor"),
3204 IWPRIV_GET(DOT11_OID_FREQUENCYACTIVITY, "freqactivity"),
3205 IWPRIV_U32(DOT11_OID_NONERPPROTECTION, "nonerpprotec"),
3206 IWPRIV_U32(DOT11_OID_PROFILES, "profile"),
3207 IWPRIV_GET(DOT11_OID_EXTENDEDRATES, "extrates"),
3208 IWPRIV_U32(DOT11_OID_MLMEAUTOLEVEL, "mlmelevel"),
3209
3210 IWPRIV_GET(DOT11_OID_BSSS, "bsss"),
3211 IWPRIV_GET(DOT11_OID_BSSLIST, "bsslist"),
3212 IWPRIV_U32(OID_INL_MODE, "mode"),
3213 IWPRIV_U32(OID_INL_CONFIG, "config"),
3214 IWPRIV_U32(OID_INL_DOT11D_CONFORMANCE, ".11dconform"),
3215 IWPRIV_GET(OID_INL_PHYCAPABILITIES, "phycapa"),
3216 IWPRIV_U32(OID_INL_OUTPUTPOWER, "outpower"),
3217};
3218
3219static const iw_handler prism54_private_handler[] = {
3220 (iw_handler) prism54_reset,
3221 (iw_handler) prism54_get_policy,
3222 (iw_handler) prism54_set_policy,
3223 (iw_handler) prism54_get_mac,
3224 (iw_handler) prism54_add_mac,
3225 (iw_handler) NULL,
3226 (iw_handler) prism54_del_mac,
3227 (iw_handler) NULL,
3228 (iw_handler) prism54_kick_mac,
3229 (iw_handler) NULL,
3230 (iw_handler) prism54_kick_all,
3231 (iw_handler) prism54_get_wpa,
3232 (iw_handler) prism54_set_wpa,
3233 (iw_handler) NULL,
3234 (iw_handler) prism54_debug_oid,
3235 (iw_handler) prism54_debug_get_oid,
3236 (iw_handler) prism54_debug_set_oid,
3237 (iw_handler) prism54_get_oid,
3238 (iw_handler) prism54_set_u32,
3239 (iw_handler) NULL,
3240 (iw_handler) prism54_set_raw,
3241 (iw_handler) NULL,
3242 (iw_handler) prism54_set_raw,
3243 (iw_handler) prism54_get_prismhdr,
3244 (iw_handler) prism54_set_prismhdr,
3245};
3246
3247const struct iw_handler_def prism54_handler_def = {
3248 .num_standard = sizeof (prism54_handler) / sizeof (iw_handler),
3249 .num_private = sizeof (prism54_private_handler) / sizeof (iw_handler),
3250 .num_private_args =
3251 sizeof (prism54_private_args) / sizeof (struct iw_priv_args),
3252 .standard = (iw_handler *) prism54_handler,
3253 .private = (iw_handler *) prism54_private_handler,
3254 .private_args = (struct iw_priv_args *) prism54_private_args,
Jean Tourrilhes61bd4962005-09-02 11:42:56 -07003255 .get_wireless_stats = prism54_get_wireless_stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256};
3257
3258/* For wpa_supplicant */
3259
3260int
3261prism54_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
3262{
3263 struct iwreq *wrq = (struct iwreq *) rq;
3264 int ret = -1;
3265 switch (cmd) {
3266 case PRISM54_HOSTAPD:
3267 if (!capable(CAP_NET_ADMIN))
3268 return -EPERM;
3269 ret = prism54_hostapd(ndev, &wrq->u.data);
3270 return ret;
3271 }
3272 return -EOPNOTSUPP;
3273}