Merge tag 'renesas-dt5-for-v3.15' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / drivers / net / wireless / prism54 / isl_ioctl.c
CommitLineData
1da177e4 1/*
1da177e4
LT
2 * Copyright (C) 2002 Intersil Americas Inc.
3 * (C) 2003,2004 Aurelien Alleaume <slts@free.fr>
4 * (C) 2003 Herbert Valerio Riedel <hvr@gnu.org>
5 * (C) 2003 Luis R. Rodriguez <mcgrof@ruslug.rutgers.edu>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
4280db9d 17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
1da177e4
LT
18 *
19 */
20
d43c36dc 21#include <linux/capability.h>
1da177e4
LT
22#include <linux/module.h>
23#include <linux/kernel.h>
24#include <linux/if_arp.h>
5a0e3ad6 25#include <linux/slab.h>
1da177e4 26#include <linux/pci.h>
692e5167 27#include <linux/etherdevice.h>
1da177e4
LT
28
29#include <asm/uaccess.h>
30
31#include "prismcompat.h"
32#include "isl_ioctl.h"
33#include "islpci_mgt.h"
34#include "isl_oid.h" /* additional types and defs for isl38xx fw */
35#include "oid_mgt.h"
36
37#include <net/iw_handler.h> /* New driver API */
38
eab411f1
DW
39#define KEY_SIZE_WEP104 13 /* 104/128-bit WEP keys */
40#define KEY_SIZE_WEP40 5 /* 40/64-bit WEP keys */
41/* KEY_SIZE_TKIP should match isl_oid.h, struct obj_key.key[] size */
42#define KEY_SIZE_TKIP 32 /* TKIP keys */
1da177e4 43
eab411f1 44static void prism54_wpa_bss_ie_add(islpci_private *priv, u8 *bssid,
1da177e4 45 u8 *wpa_ie, size_t wpa_ie_len);
eab411f1 46static size_t prism54_wpa_bss_ie_get(islpci_private *priv, u8 *bssid, u8 *wpa_ie);
1da177e4
LT
47static int prism54_set_wpa(struct net_device *, struct iw_request_info *,
48 __u32 *, char *);
49
bd6dd756
JT
50/* In 500 kbps */
51static const unsigned char scan_rate_list[] = { 2, 4, 11, 22,
52 12, 18, 24, 36,
53 48, 72, 96, 108 };
1da177e4
LT
54
55/**
56 * prism54_mib_mode_helper - MIB change mode helper function
57 * @mib: the &struct islpci_mib object to modify
58 * @iw_mode: new mode (%IW_MODE_*)
93b2dd12 59 *
1da177e4 60 * This is a helper function, hence it does not lock. Make sure
93b2dd12
DT
61 * caller deals with locking *if* necessary. This function sets the
62 * mode-dependent mib values and does the mapping of the Linux
63 * Wireless API modes to Device firmware modes. It also checks for
64 * correct valid Linux wireless modes.
1da177e4
LT
65 */
66static int
67prism54_mib_mode_helper(islpci_private *priv, u32 iw_mode)
68{
69 u32 config = INL_CONFIG_MANUALRUN;
70 u32 mode, bsstype;
71
72 /* For now, just catch early the Repeater and Secondary modes here */
73 if (iw_mode == IW_MODE_REPEAT || iw_mode == IW_MODE_SECOND) {
74 printk(KERN_DEBUG
75 "%s(): Sorry, Repeater mode and Secondary mode "
c94c93da 76 "are not yet supported by this driver.\n", __func__);
1da177e4
LT
77 return -EINVAL;
78 }
79
80 priv->iw_mode = iw_mode;
81
82 switch (iw_mode) {
83 case IW_MODE_AUTO:
84 mode = INL_MODE_CLIENT;
85 bsstype = DOT11_BSSTYPE_ANY;
86 break;
87 case IW_MODE_ADHOC:
88 mode = INL_MODE_CLIENT;
89 bsstype = DOT11_BSSTYPE_IBSS;
90 break;
91 case IW_MODE_INFRA:
92 mode = INL_MODE_CLIENT;
93 bsstype = DOT11_BSSTYPE_INFRA;
94 break;
95 case IW_MODE_MASTER:
96 mode = INL_MODE_AP;
97 bsstype = DOT11_BSSTYPE_INFRA;
98 break;
99 case IW_MODE_MONITOR:
100 mode = INL_MODE_PROMISCUOUS;
101 bsstype = DOT11_BSSTYPE_ANY;
102 config |= INL_CONFIG_RXANNEX;
103 break;
104 default:
105 return -EINVAL;
106 }
107
108 if (init_wds)
109 config |= INL_CONFIG_WDS;
110 mgt_set(priv, DOT11_OID_BSSTYPE, &bsstype);
111 mgt_set(priv, OID_INL_CONFIG, &config);
112 mgt_set(priv, OID_INL_MODE, &mode);
113
114 return 0;
115}
116
117/**
118 * prism54_mib_init - fill MIB cache with defaults
119 *
120 * this function initializes the struct given as @mib with defaults,
121 * of which many are retrieved from the global module parameter
93b2dd12 122 * variables.
1da177e4
LT
123 */
124
125void
126prism54_mib_init(islpci_private *priv)
127{
128 u32 channel, authen, wep, filter, dot1x, mlme, conformance, power, mode;
129 struct obj_buffer psm_buffer = {
130 .size = PSM_BUFFER_SIZE,
131 .addr = priv->device_psm_buffer
132 };
133
134 channel = CARD_DEFAULT_CHANNEL;
135 authen = CARD_DEFAULT_AUTHEN;
136 wep = CARD_DEFAULT_WEP;
137 filter = CARD_DEFAULT_FILTER; /* (0) Do not filter un-encrypted data */
93b2dd12 138 dot1x = CARD_DEFAULT_DOT1X;
1da177e4
LT
139 mlme = CARD_DEFAULT_MLME_MODE;
140 conformance = CARD_DEFAULT_CONFORMANCE;
141 power = 127;
142 mode = CARD_DEFAULT_IW_MODE;
143
144 mgt_set(priv, DOT11_OID_CHANNEL, &channel);
145 mgt_set(priv, DOT11_OID_AUTHENABLE, &authen);
146 mgt_set(priv, DOT11_OID_PRIVACYINVOKED, &wep);
147 mgt_set(priv, DOT11_OID_PSMBUFFER, &psm_buffer);
148 mgt_set(priv, DOT11_OID_EXUNENCRYPTED, &filter);
149 mgt_set(priv, DOT11_OID_DOT1XENABLE, &dot1x);
150 mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &mlme);
151 mgt_set(priv, OID_INL_DOT11D_CONFORMANCE, &conformance);
152 mgt_set(priv, OID_INL_OUTPUTPOWER, &power);
153
154 /* This sets all of the mode-dependent values */
155 prism54_mib_mode_helper(priv, mode);
156}
157
158/* this will be executed outside of atomic context thanks to
159 * schedule_work(), thus we can as well use sleeping semaphore
160 * locking */
161void
c4028958 162prism54_update_stats(struct work_struct *work)
1da177e4 163{
c4028958 164 islpci_private *priv = container_of(work, islpci_private, stats_work);
1da177e4
LT
165 char *data;
166 int j;
167 struct obj_bss bss, *bss2;
168 union oid_res_t r;
169
f8139218 170 mutex_lock(&priv->stats_lock);
1da177e4
LT
171
172/* Noise floor.
173 * I'm not sure if the unit is dBm.
174 * Note : If we are not connected, this value seems to be irrelevant. */
175
176 mgt_get_request(priv, DOT11_OID_NOISEFLOOR, 0, NULL, &r);
177 priv->local_iwstatistics.qual.noise = r.u;
178
179/* Get the rssi of the link. To do this we need to retrieve a bss. */
180
181 /* First get the MAC address of the AP we are associated with. */
182 mgt_get_request(priv, DOT11_OID_BSSID, 0, NULL, &r);
183 data = r.ptr;
184
185 /* copy this MAC to the bss */
d458cdf7 186 memcpy(bss.address, data, ETH_ALEN);
1da177e4
LT
187 kfree(data);
188
189 /* now ask for the corresponding bss */
190 j = mgt_get_request(priv, DOT11_OID_BSSFIND, 0, (void *) &bss, &r);
191 bss2 = r.ptr;
192 /* report the rssi and use it to calculate
193 * link quality through a signal-noise
194 * ratio */
195 priv->local_iwstatistics.qual.level = bss2->rssi;
196 priv->local_iwstatistics.qual.qual =
197 bss2->rssi - priv->iwstatistics.qual.noise;
198
199 kfree(bss2);
200
201 /* report that the stats are new */
202 priv->local_iwstatistics.qual.updated = 0x7;
203
204/* Rx : unable to decrypt the MPDU */
205 mgt_get_request(priv, DOT11_OID_PRIVRXFAILED, 0, NULL, &r);
206 priv->local_iwstatistics.discard.code = r.u;
207
208/* Tx : Max MAC retries num reached */
209 mgt_get_request(priv, DOT11_OID_MPDUTXFAILED, 0, NULL, &r);
210 priv->local_iwstatistics.discard.retries = r.u;
211
f8139218 212 mutex_unlock(&priv->stats_lock);
1da177e4
LT
213}
214
215struct iw_statistics *
216prism54_get_wireless_stats(struct net_device *ndev)
217{
218 islpci_private *priv = netdev_priv(ndev);
219
220 /* If the stats are being updated return old data */
8dd62822 221 if (mutex_trylock(&priv->stats_lock)) {
1da177e4
LT
222 memcpy(&priv->iwstatistics, &priv->local_iwstatistics,
223 sizeof (struct iw_statistics));
224 /* They won't be marked updated for the next time */
225 priv->local_iwstatistics.qual.updated = 0;
f8139218 226 mutex_unlock(&priv->stats_lock);
1da177e4
LT
227 } else
228 priv->iwstatistics.qual.updated = 0;
229
93b2dd12 230 /* Update our wireless stats, but do not schedule to often
1da177e4
LT
231 * (max 1 HZ) */
232 if ((priv->stats_timestamp == 0) ||
233 time_after(jiffies, priv->stats_timestamp + 1 * HZ)) {
234 schedule_work(&priv->stats_work);
235 priv->stats_timestamp = jiffies;
236 }
237
238 return &priv->iwstatistics;
239}
240
241static int
242prism54_commit(struct net_device *ndev, struct iw_request_info *info,
243 char *cwrq, char *extra)
244{
245 islpci_private *priv = netdev_priv(ndev);
246
247 /* simply re-set the last set SSID, this should commit most stuff */
248
249 /* Commit in Monitor mode is not necessary, also setting essid
250 * in Monitor mode does not make sense and isn't allowed for this
251 * device's firmware */
252 if (priv->iw_mode != IW_MODE_MONITOR)
253 return mgt_set_request(priv, DOT11_OID_SSID, 0, NULL);
254 return 0;
255}
256
257static int
258prism54_get_name(struct net_device *ndev, struct iw_request_info *info,
259 char *cwrq, char *extra)
260{
261 islpci_private *priv = netdev_priv(ndev);
262 char *capabilities;
263 union oid_res_t r;
264 int rvalue;
265
266 if (islpci_get_state(priv) < PRV_STATE_INIT) {
267 strncpy(cwrq, "NOT READY!", IFNAMSIZ);
268 return 0;
269 }
270 rvalue = mgt_get_request(priv, OID_INL_PHYCAPABILITIES, 0, NULL, &r);
271
272 switch (r.u) {
273 case INL_PHYCAP_5000MHZ:
274 capabilities = "IEEE 802.11a/b/g";
275 break;
276 case INL_PHYCAP_FAA:
277 capabilities = "IEEE 802.11b/g - FAA Support";
278 break;
279 case INL_PHYCAP_2400MHZ:
280 default:
281 capabilities = "IEEE 802.11b/g"; /* Default */
282 break;
283 }
284 strncpy(cwrq, capabilities, IFNAMSIZ);
285 return rvalue;
286}
287
288static int
289prism54_set_freq(struct net_device *ndev, struct iw_request_info *info,
290 struct iw_freq *fwrq, char *extra)
291{
292 islpci_private *priv = netdev_priv(ndev);
293 int rvalue;
294 u32 c;
295
296 if (fwrq->m < 1000)
297 /* we have a channel number */
298 c = fwrq->m;
299 else
300 c = (fwrq->e == 1) ? channel_of_freq(fwrq->m / 100000) : 0;
301
302 rvalue = c ? mgt_set_request(priv, DOT11_OID_CHANNEL, 0, &c) : -EINVAL;
303
304 /* Call commit handler */
305 return (rvalue ? rvalue : -EINPROGRESS);
306}
307
308static int
309prism54_get_freq(struct net_device *ndev, struct iw_request_info *info,
310 struct iw_freq *fwrq, char *extra)
311{
312 islpci_private *priv = netdev_priv(ndev);
313 union oid_res_t r;
314 int rvalue;
315
316 rvalue = mgt_get_request(priv, DOT11_OID_CHANNEL, 0, NULL, &r);
317 fwrq->i = r.u;
318 rvalue |= mgt_get_request(priv, DOT11_OID_FREQUENCY, 0, NULL, &r);
319 fwrq->m = r.u;
320 fwrq->e = 3;
321
322 return rvalue;
323}
324
325static int
326prism54_set_mode(struct net_device *ndev, struct iw_request_info *info,
327 __u32 * uwrq, char *extra)
328{
329 islpci_private *priv = netdev_priv(ndev);
330 u32 mlmeautolevel = CARD_DEFAULT_MLME_MODE;
331
332 /* Let's see if the user passed a valid Linux Wireless mode */
333 if (*uwrq > IW_MODE_MONITOR || *uwrq < IW_MODE_AUTO) {
334 printk(KERN_DEBUG
335 "%s: %s() You passed a non-valid init_mode.\n",
c94c93da 336 priv->ndev->name, __func__);
1da177e4
LT
337 return -EINVAL;
338 }
339
340 down_write(&priv->mib_sem);
341
342 if (prism54_mib_mode_helper(priv, *uwrq)) {
343 up_write(&priv->mib_sem);
344 return -EOPNOTSUPP;
345 }
346
347 /* the ACL code needs an intermediate mlmeautolevel. The wpa stuff an
348 * extended one.
349 */
350 if ((*uwrq == IW_MODE_MASTER) && (priv->acl.policy != MAC_POLICY_OPEN))
351 mlmeautolevel = DOT11_MLME_INTERMEDIATE;
352 if (priv->wpa)
353 mlmeautolevel = DOT11_MLME_EXTENDED;
354
355 mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &mlmeautolevel);
356
357 if (mgt_commit(priv)) {
358 up_write(&priv->mib_sem);
359 return -EIO;
360 }
361 priv->ndev->type = (priv->iw_mode == IW_MODE_MONITOR)
362 ? priv->monitor_type : ARPHRD_ETHER;
363 up_write(&priv->mib_sem);
364
365 return 0;
366}
367
368/* Use mib cache */
369static int
370prism54_get_mode(struct net_device *ndev, struct iw_request_info *info,
371 __u32 * uwrq, char *extra)
372{
373 islpci_private *priv = netdev_priv(ndev);
374
375 BUG_ON((priv->iw_mode < IW_MODE_AUTO) || (priv->iw_mode >
376 IW_MODE_MONITOR));
377 *uwrq = priv->iw_mode;
378
379 return 0;
380}
381
382/* we use DOT11_OID_EDTHRESHOLD. From what I guess the card will not try to
383 * emit data if (sensitivity > rssi - noise) (in dBm).
384 * prism54_set_sens does not seem to work.
385 */
386
387static int
388prism54_set_sens(struct net_device *ndev, struct iw_request_info *info,
389 struct iw_param *vwrq, char *extra)
390{
391 islpci_private *priv = netdev_priv(ndev);
392 u32 sens;
393
394 /* by default the card sets this to 20. */
395 sens = vwrq->disabled ? 20 : vwrq->value;
396
397 return mgt_set_request(priv, DOT11_OID_EDTHRESHOLD, 0, &sens);
398}
399
400static int
401prism54_get_sens(struct net_device *ndev, struct iw_request_info *info,
402 struct iw_param *vwrq, char *extra)
403{
404 islpci_private *priv = netdev_priv(ndev);
405 union oid_res_t r;
406 int rvalue;
407
408 rvalue = mgt_get_request(priv, DOT11_OID_EDTHRESHOLD, 0, NULL, &r);
409
410 vwrq->value = r.u;
411 vwrq->disabled = (vwrq->value == 0);
412 vwrq->fixed = 1;
413
414 return rvalue;
415}
416
417static int
418prism54_get_range(struct net_device *ndev, struct iw_request_info *info,
419 struct iw_point *dwrq, char *extra)
420{
421 struct iw_range *range = (struct iw_range *) extra;
422 islpci_private *priv = netdev_priv(ndev);
423 u8 *data;
424 int i, m, rvalue;
425 struct obj_frequencies *freq;
426 union oid_res_t r;
427
428 memset(range, 0, sizeof (struct iw_range));
429 dwrq->length = sizeof (struct iw_range);
430
431 /* set the wireless extension version number */
432 range->we_version_source = SUPPORTED_WIRELESS_EXT;
433 range->we_version_compiled = WIRELESS_EXT;
434
435 /* Now the encoding capabilities */
436 range->num_encoding_sizes = 3;
437 /* 64(40) bits WEP */
438 range->encoding_size[0] = 5;
439 /* 128(104) bits WEP */
440 range->encoding_size[1] = 13;
441 /* 256 bits for WPA-PSK */
442 range->encoding_size[2] = 32;
443 /* 4 keys are allowed */
444 range->max_encoding_tokens = 4;
445
446 /* we don't know the quality range... */
447 range->max_qual.level = 0;
448 range->max_qual.noise = 0;
449 range->max_qual.qual = 0;
450 /* these value describe an average quality. Needs more tweaking... */
451 range->avg_qual.level = -80; /* -80 dBm */
452 range->avg_qual.noise = 0; /* don't know what to put here */
453 range->avg_qual.qual = 0;
454
455 range->sensitivity = 200;
456
457 /* retry limit capabilities */
458 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
459 range->retry_flags = IW_RETRY_LIMIT;
460 range->r_time_flags = IW_RETRY_LIFETIME;
461
462 /* I don't know the range. Put stupid things here */
463 range->min_retry = 1;
464 range->max_retry = 65535;
465 range->min_r_time = 1024;
466 range->max_r_time = 65535 * 1024;
467
468 /* txpower is supported in dBm's */
469 range->txpower_capa = IW_TXPOW_DBM;
470
1da177e4
LT
471 /* Event capability (kernel + driver) */
472 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
473 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
474 IW_EVENT_CAPA_MASK(SIOCGIWAP));
475 range->event_capa[1] = IW_EVENT_CAPA_K_1;
476 range->event_capa[4] = IW_EVENT_CAPA_MASK(IWEVCUSTOM);
1da177e4 477
eab411f1
DW
478 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
479 IW_ENC_CAPA_CIPHER_TKIP;
480
1da177e4
LT
481 if (islpci_get_state(priv) < PRV_STATE_INIT)
482 return 0;
483
484 /* Request the device for the supported frequencies
485 * not really relevant since some devices will report the 5 GHz band
486 * frequencies even if they don't support them.
487 */
488 rvalue =
489 mgt_get_request(priv, DOT11_OID_SUPPORTEDFREQUENCIES, 0, NULL, &r);
490 freq = r.ptr;
491
492 range->num_channels = freq->nr;
493 range->num_frequency = freq->nr;
494
495 m = min(IW_MAX_FREQUENCIES, (int) freq->nr);
496 for (i = 0; i < m; i++) {
497 range->freq[i].m = freq->mhz[i];
498 range->freq[i].e = 6;
499 range->freq[i].i = channel_of_freq(freq->mhz[i]);
500 }
501 kfree(freq);
502
503 rvalue |= mgt_get_request(priv, DOT11_OID_SUPPORTEDRATES, 0, NULL, &r);
504 data = r.ptr;
505
506 /* We got an array of char. It is NULL terminated. */
507 i = 0;
508 while ((i < IW_MAX_BITRATES) && (*data != 0)) {
509 /* the result must be in bps. The card gives us 500Kbps */
510 range->bitrate[i] = *data * 500000;
511 i++;
512 data++;
513 }
514 range->num_bitrates = i;
515 kfree(r.ptr);
516
517 return rvalue;
518}
519
520/* Set AP address*/
521
522static int
523prism54_set_wap(struct net_device *ndev, struct iw_request_info *info,
524 struct sockaddr *awrq, char *extra)
525{
526 islpci_private *priv = netdev_priv(ndev);
527 char bssid[6];
528 int rvalue;
529
530 if (awrq->sa_family != ARPHRD_ETHER)
531 return -EINVAL;
532
533 /* prepare the structure for the set object */
d458cdf7 534 memcpy(&bssid[0], awrq->sa_data, ETH_ALEN);
1da177e4
LT
535
536 /* set the bssid -- does this make sense when in AP mode? */
537 rvalue = mgt_set_request(priv, DOT11_OID_BSSID, 0, &bssid);
538
539 return (rvalue ? rvalue : -EINPROGRESS); /* Call commit handler */
540}
541
542/* get AP address*/
543
544static int
545prism54_get_wap(struct net_device *ndev, struct iw_request_info *info,
546 struct sockaddr *awrq, char *extra)
547{
548 islpci_private *priv = netdev_priv(ndev);
549 union oid_res_t r;
550 int rvalue;
551
552 rvalue = mgt_get_request(priv, DOT11_OID_BSSID, 0, NULL, &r);
d458cdf7 553 memcpy(awrq->sa_data, r.ptr, ETH_ALEN);
1da177e4
LT
554 awrq->sa_family = ARPHRD_ETHER;
555 kfree(r.ptr);
556
557 return rvalue;
558}
559
560static int
561prism54_set_scan(struct net_device *dev, struct iw_request_info *info,
562 struct iw_param *vwrq, char *extra)
563{
564 /* hehe the device does this automagicaly */
565 return 0;
566}
567
568/* a little helper that will translate our data into a card independent
569 * format that the Wireless Tools will understand. This was inspired by
570 * the "Aironet driver for 4500 and 4800 series cards" (GPL)
571 */
572
573static char *
ccc58057
DM
574prism54_translate_bss(struct net_device *ndev, struct iw_request_info *info,
575 char *current_ev, char *end_buf, struct obj_bss *bss,
576 char noise)
1da177e4
LT
577{
578 struct iw_event iwe; /* Temporary buffer */
579 short cap;
580 islpci_private *priv = netdev_priv(ndev);
eab411f1
DW
581 u8 wpa_ie[MAX_WPA_IE_LEN];
582 size_t wpa_ie_len;
1da177e4
LT
583
584 /* The first entry must be the MAC address */
d458cdf7 585 memcpy(iwe.u.ap_addr.sa_data, bss->address, ETH_ALEN);
1da177e4
LT
586 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
587 iwe.cmd = SIOCGIWAP;
ccc58057
DM
588 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
589 &iwe, IW_EV_ADDR_LEN);
1da177e4
LT
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;
ccc58057 597 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1da177e4
LT
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)
ccc58057
DM
614 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
615 &iwe, IW_EV_UINT_LEN);
1da177e4
LT
616
617 /* Encryption capability */
618 if (cap & CAP_CRYPT)
619 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
620 else
621 iwe.u.data.flags = IW_ENCODE_DISABLED;
622 iwe.u.data.length = 0;
623 iwe.cmd = SIOCGIWENCODE;
ccc58057
DM
624 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
625 &iwe, NULL);
1da177e4
LT
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;
ccc58057
DM
631 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
632 &iwe, IW_EV_FREQ_LEN);
1da177e4
LT
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;
ccc58057
DM
640 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
641 &iwe, IW_EV_QUAL_LEN);
1da177e4 642
eab411f1
DW
643 /* 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;
c8e49556 647 iwe.u.data.length = min_t(size_t, wpa_ie_len, MAX_WPA_IE_LEN);
ccc58057
DM
648 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
649 &iwe, wpa_ie);
1da177e4 650 }
bd6dd756
JT
651 /* Do the bitrates */
652 {
ccc58057 653 char *current_val = current_ev + iwe_stream_lcp_len(info);
bd6dd756
JT
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);
ccc58057
DM
666 current_val = iwe_stream_add_value(
667 info, current_ev, current_val,
668 end_buf, &iwe, IW_EV_PARAM_LEN);
bd6dd756
JT
669 }
670 mask <<= 1;
671 }
672 /* Check if we added any event */
ccc58057 673 if ((current_val - current_ev) > iwe_stream_lcp_len(info))
bd6dd756
JT
674 current_ev = current_val;
675 }
676
1da177e4
LT
677 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. */
93b2dd12 708
1da177e4
LT
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++) {
ccc58057 714 current_ev = prism54_translate_bss(ndev, info, current_ev,
1da177e4
LT
715 extra + dwrq->length,
716 &(bsslist->bsslist[i]),
717 noise);
e2e96507 718
1da177e4
LT
719 /* 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 }
1da177e4
LT
725 }
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) {
bad04f2c 745 if (dwrq->length > 32)
1da177e4 746 return -E2BIG;
bad04f2c 747 essid.length = dwrq->length;
1da177e4
LT
748 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 */
7f927fcc 775 /* if it is too big, trunk it */
bf82a449 776 dwrq->length = min((u8)IW_ESSID_MAX_SIZE, essid->length);
1da177e4
LT
777 } else {
778 dwrq->flags = 0;
779 dwrq->length = 0;
780 }
40f9cd29 781 essid->octets[dwrq->length] = '\0';
1da177e4
LT
782 memcpy(extra, essid->octets, dwrq->length);
783 kfree(essid);
784
785 return rvalue;
786}
787
93b2dd12 788/* Provides no functionality, just completes the ioctl. In essence this is a
1da177e4
LT
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);
bad04f2c 817 dwrq->length = strlen(priv->nickname);
1da177e4
LT
818 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) {
bad04f2c 995 if (vwrq->flags & IW_RETRY_SHORT)
1da177e4 996 slimit = vwrq->value;
bad04f2c 997 else if (vwrq->flags & IW_RETRY_LONG)
1da177e4
LT
998 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;
bad04f2c 1038 } else if ((vwrq->flags & IW_RETRY_LONG)) {
1da177e4
LT
1039 /* 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;
bad04f2c 1043 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
1da177e4
LT
1044 } 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;
bad04f2c 1049 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
1da177e4
LT
1050 }
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)) {
eab411f1
DW
1079 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 */
1da177e4 1085 key.type = DOT11_PRIV_TKIP;
eab411f1
DW
1086 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
1da177e4
LT
1097 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 /*
93b2dd12 1107 * If a valid key is set, encryption should be enabled
1da177e4
LT
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 {
f59d9782 1121 if (!(dwrq->flags & IW_ENCODE_MODE)) {
1da177e4
LT
1122 /* we cannot do anything. Complain. */
1123 return -EINVAL;
1124 }
1125 }
1126 }
1127 /* now read the flags */
1128 if (dwrq->flags & IW_ENCODE_DISABLED) {
93b2dd12 1129 /* Encoding disabled,
1da177e4
LT
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 */
8ba82e96 1190 if (index == -1 || index > 3)
1da177e4
LT
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
93b2dd12 1217 * btw: how is possible to turn off only the radio
1da177e4
LT
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",
c94c93da 1237 priv->ndev->name, __func__);
1da177e4
LT
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",
c94c93da 1245 priv->ndev->name, __func__);
1da177e4
LT
1246 return -ENOTSUPP;
1247 }
1248}
1249
eab411f1
DW
1250static 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:
b5c41651
DW
1398 /* dot1x should be the opposite of RX_UNENCRYPTED_EAPOL;
1399 * turn off dot1x when allowing receipt of unencrypted EAPOL
1400 * frames, turn on dot1x when receipt should be disallowed
1401 */
1402 dot1x = param->value ? 0 : 0x01;
eab411f1
DW
1403 break;
1404
1405 case IW_AUTH_PRIVACY_INVOKED:
1406 privinvoked = param->value ? 1 : 0;
b5c41651 1407 break;
eab411f1
DW
1408
1409 case IW_AUTH_DROP_UNENCRYPTED:
1410 exunencrypt = param->value ? 1 : 0;
1411 break;
1412
1413 case IW_AUTH_80211_AUTH_ALG:
1414 if (param->value & IW_AUTH_ALG_SHARED_KEY) {
1415 /* Only WEP uses _SK and _BOTH */
1416 if (wpa > 0) {
1417 ret = -EINVAL;
1418 goto out;
1419 }
1420 authen = DOT11_AUTH_SK;
1421 } else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM) {
1422 authen = DOT11_AUTH_OS;
1423 } else {
1424 ret = -EINVAL;
1425 goto out;
1426 }
1427 break;
1428
1429 default:
1430 return -EOPNOTSUPP;
1431 }
1432
1433 /* Set all the values */
1434 down_write(&priv->mib_sem);
1435 priv->wpa = wpa;
1436 up_write(&priv->mib_sem);
1437 mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0, &authen);
1438 mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0, &privinvoked);
1439 mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0, &exunencrypt);
1440 mgt_set_request(priv, DOT11_OID_DOT1XENABLE, 0, &dot1x);
1441 mgt_set_request(priv, DOT11_OID_MLMEAUTOLEVEL, 0, &mlmelevel);
1442
1443out:
1444 return ret;
1445}
1446
1447static int prism54_get_auth(struct net_device *ndev,
1448 struct iw_request_info *info,
1449 union iwreq_data *wrqu, char *extra)
1450{
1451 islpci_private *priv = netdev_priv(ndev);
1452 struct iw_param *param = &wrqu->param;
1453 u32 wpa = 0;
1454 int ret = 0;
1455 union oid_res_t r;
1456
1457 if (islpci_get_state(priv) < PRV_STATE_INIT)
1458 return 0;
1459
1460 /* first get the flags */
1461 down_write(&priv->mib_sem);
1462 wpa = priv->wpa;
1463 up_write(&priv->mib_sem);
1464
1465 switch (param->flags & IW_AUTH_INDEX) {
1466 case IW_AUTH_CIPHER_PAIRWISE:
1467 case IW_AUTH_CIPHER_GROUP:
1468 case IW_AUTH_KEY_MGMT:
1469 /*
1470 * wpa_supplicant will control these internally
1471 */
1472 ret = -EOPNOTSUPP;
1473 break;
1474
1475 case IW_AUTH_WPA_VERSION:
1476 switch (wpa) {
1477 case 1:
1478 param->value = IW_AUTH_WPA_VERSION_WPA;
1479 break;
1480 case 2:
1481 param->value = IW_AUTH_WPA_VERSION_WPA2;
1482 break;
1483 case 0:
1484 default:
1485 param->value = IW_AUTH_WPA_VERSION_DISABLED;
1486 break;
1487 }
1488 break;
1489
1490 case IW_AUTH_DROP_UNENCRYPTED:
1491 ret = mgt_get_request(priv, DOT11_OID_EXUNENCRYPTED, 0, NULL, &r);
1492 if (ret >= 0)
1493 param->value = r.u > 0 ? 1 : 0;
1494 break;
1495
1496 case IW_AUTH_80211_AUTH_ALG:
1497 ret = mgt_get_request(priv, DOT11_OID_AUTHENABLE, 0, NULL, &r);
1498 if (ret >= 0) {
1499 switch (r.u) {
1500 case DOT11_AUTH_OS:
1501 param->value = IW_AUTH_ALG_OPEN_SYSTEM;
1502 break;
1503 case DOT11_AUTH_BOTH:
1504 case DOT11_AUTH_SK:
1505 param->value = IW_AUTH_ALG_SHARED_KEY;
f49aabf8 1506 break;
eab411f1
DW
1507 case DOT11_AUTH_NONE:
1508 default:
1509 param->value = 0;
1510 break;
1511 }
1512 }
1513 break;
1514
1515 case IW_AUTH_WPA_ENABLED:
1516 param->value = wpa > 0 ? 1 : 0;
1517 break;
1518
1519 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1520 ret = mgt_get_request(priv, DOT11_OID_DOT1XENABLE, 0, NULL, &r);
1521 if (ret >= 0)
1522 param->value = r.u > 0 ? 1 : 0;
1523 break;
1524
1525 case IW_AUTH_PRIVACY_INVOKED:
1526 ret = mgt_get_request(priv, DOT11_OID_PRIVACYINVOKED, 0, NULL, &r);
1527 if (ret >= 0)
1528 param->value = r.u > 0 ? 1 : 0;
1529 break;
1530
1531 default:
1532 return -EOPNOTSUPP;
1533 }
1534 return ret;
1535}
1536
1537static int prism54_set_encodeext(struct net_device *ndev,
1538 struct iw_request_info *info,
1539 union iwreq_data *wrqu,
1540 char *extra)
1541{
1542 islpci_private *priv = netdev_priv(ndev);
1543 struct iw_point *encoding = &wrqu->encoding;
1544 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1545 int idx, alg = ext->alg, set_key = 1;
1546 union oid_res_t r;
1547 int authen = DOT11_AUTH_OS, invoke = 0, exunencrypt = 0;
1548 int ret = 0;
1549
1550 if (islpci_get_state(priv) < PRV_STATE_INIT)
1551 return 0;
1552
1553 /* Determine and validate the key index */
1554 idx = (encoding->flags & IW_ENCODE_INDEX) - 1;
1555 if (idx) {
1556 if (idx < 0 || idx > 3)
1557 return -EINVAL;
1558 } else {
1559 ret = mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r);
1560 if (ret < 0)
1561 goto out;
1562 idx = r.u;
1563 }
1564
1565 if (encoding->flags & IW_ENCODE_DISABLED)
1566 alg = IW_ENCODE_ALG_NONE;
1567
1568 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
1569 /* Only set transmit key index here, actual
1570 * key is set below if needed.
1571 */
1572 ret = mgt_set_request(priv, DOT11_OID_DEFKEYID, 0, &idx);
1573 set_key = ext->key_len > 0 ? 1 : 0;
1574 }
1575
1576 if (set_key) {
1577 struct obj_key key = { DOT11_PRIV_WEP, 0, "" };
1578 switch (alg) {
1579 case IW_ENCODE_ALG_NONE:
1580 break;
1581 case IW_ENCODE_ALG_WEP:
1582 if (ext->key_len > KEY_SIZE_WEP104) {
1583 ret = -EINVAL;
1584 goto out;
1585 }
1586 if (ext->key_len > KEY_SIZE_WEP40)
1587 key.length = KEY_SIZE_WEP104;
1588 else
1589 key.length = KEY_SIZE_WEP40;
1590 break;
1591 case IW_ENCODE_ALG_TKIP:
1592 if (ext->key_len > KEY_SIZE_TKIP) {
1593 ret = -EINVAL;
1594 goto out;
1595 }
1596 key.type = DOT11_PRIV_TKIP;
1597 key.length = KEY_SIZE_TKIP;
b5c41651 1598 break;
eab411f1
DW
1599 default:
1600 return -EINVAL;
1601 }
1602
1603 if (key.length) {
1604 memset(key.key, 0, sizeof(key.key));
1605 memcpy(key.key, ext->key, ext->key_len);
1606 ret = mgt_set_request(priv, DOT11_OID_DEFKEYX, idx,
1607 &key);
1608 if (ret < 0)
1609 goto out;
1610 }
1611 }
1612
1613 /* Read the flags */
1614 if (encoding->flags & IW_ENCODE_DISABLED) {
1615 /* Encoding disabled,
1616 * authen = DOT11_AUTH_OS;
1617 * invoke = 0;
1618 * exunencrypt = 0; */
1619 }
1620 if (encoding->flags & IW_ENCODE_OPEN) {
1621 /* Encode but accept non-encoded packets. No auth */
1622 invoke = 1;
1623 }
1624 if (encoding->flags & IW_ENCODE_RESTRICTED) {
1625 /* Refuse non-encoded packets. Auth */
1626 authen = DOT11_AUTH_BOTH;
1627 invoke = 1;
1628 exunencrypt = 1;
1629 }
1630
1631 /* do the change if requested */
1632 if (encoding->flags & IW_ENCODE_MODE) {
1633 ret = mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0,
1634 &authen);
1635 ret = mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0,
1636 &invoke);
1637 ret = mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0,
1638 &exunencrypt);
1639 }
1640
1641out:
1642 return ret;
1643}
1644
1645
1646static int prism54_get_encodeext(struct net_device *ndev,
1647 struct iw_request_info *info,
1648 union iwreq_data *wrqu,
1649 char *extra)
1650{
1651 islpci_private *priv = netdev_priv(ndev);
1652 struct iw_point *encoding = &wrqu->encoding;
1653 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1654 int idx, max_key_len;
1655 union oid_res_t r;
1656 int authen = DOT11_AUTH_OS, invoke = 0, exunencrypt = 0, wpa = 0;
1657 int ret = 0;
1658
1659 if (islpci_get_state(priv) < PRV_STATE_INIT)
1660 return 0;
1661
1662 /* first get the flags */
1663 ret = mgt_get_request(priv, DOT11_OID_AUTHENABLE, 0, NULL, &r);
1664 authen = r.u;
1665 ret = mgt_get_request(priv, DOT11_OID_PRIVACYINVOKED, 0, NULL, &r);
1666 invoke = r.u;
1667 ret = mgt_get_request(priv, DOT11_OID_EXUNENCRYPTED, 0, NULL, &r);
1668 exunencrypt = r.u;
1669 if (ret < 0)
1670 goto out;
1671
1672 max_key_len = encoding->length - sizeof(*ext);
1673 if (max_key_len < 0)
1674 return -EINVAL;
1675
1676 idx = (encoding->flags & IW_ENCODE_INDEX) - 1;
1677 if (idx) {
1678 if (idx < 0 || idx > 3)
1679 return -EINVAL;
1680 } else {
1681 ret = mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r);
1682 if (ret < 0)
1683 goto out;
1684 idx = r.u;
1685 }
1686
1687 encoding->flags = idx + 1;
1688 memset(ext, 0, sizeof(*ext));
1689
1690 switch (authen) {
1691 case DOT11_AUTH_BOTH:
1692 case DOT11_AUTH_SK:
1693 wrqu->encoding.flags |= IW_ENCODE_RESTRICTED;
1694 case DOT11_AUTH_OS:
1695 default:
1696 wrqu->encoding.flags |= IW_ENCODE_OPEN;
1697 break;
1698 }
1699
1700 down_write(&priv->mib_sem);
1701 wpa = priv->wpa;
1702 up_write(&priv->mib_sem);
1703
1704 if (authen == DOT11_AUTH_OS && !exunencrypt && !invoke && !wpa) {
1705 /* No encryption */
1706 ext->alg = IW_ENCODE_ALG_NONE;
1707 ext->key_len = 0;
1708 wrqu->encoding.flags |= IW_ENCODE_DISABLED;
1709 } else {
1710 struct obj_key *key;
1711
1712 ret = mgt_get_request(priv, DOT11_OID_DEFKEYX, idx, NULL, &r);
1713 if (ret < 0)
1714 goto out;
1715 key = r.ptr;
1716 if (max_key_len < key->length) {
1717 ret = -E2BIG;
1718 goto out;
1719 }
1720 memcpy(ext->key, key->key, key->length);
1721 ext->key_len = key->length;
1722
1723 switch (key->type) {
1724 case DOT11_PRIV_TKIP:
1725 ext->alg = IW_ENCODE_ALG_TKIP;
1726 break;
1727 default:
1728 case DOT11_PRIV_WEP:
1729 ext->alg = IW_ENCODE_ALG_WEP;
1730 break;
1731 }
1732 wrqu->encoding.flags |= IW_ENCODE_ENABLED;
1733 }
1734
1735out:
1736 return ret;
1737}
1738
1739
1da177e4
LT
1740static int
1741prism54_reset(struct net_device *ndev, struct iw_request_info *info,
1742 __u32 * uwrq, char *extra)
1743{
1744 islpci_reset(netdev_priv(ndev), 0);
1745
1746 return 0;
1747}
1748
1749static int
1750prism54_get_oid(struct net_device *ndev, struct iw_request_info *info,
1751 struct iw_point *dwrq, char *extra)
1752{
1753 union oid_res_t r;
1754 int rvalue;
1755 enum oid_num_t n = dwrq->flags;
1756
6dbc9c89 1757 rvalue = mgt_get_request(netdev_priv(ndev), n, 0, NULL, &r);
1da177e4
LT
1758 dwrq->length = mgt_response_to_str(n, &r, extra);
1759 if ((isl_oid[n].flags & OID_FLAG_TYPE) != OID_TYPE_U32)
1760 kfree(r.ptr);
1761 return rvalue;
1762}
1763
1764static int
1765prism54_set_u32(struct net_device *ndev, struct iw_request_info *info,
1766 __u32 * uwrq, char *extra)
1767{
1768 u32 oid = uwrq[0], u = uwrq[1];
1769
6dbc9c89 1770 return mgt_set_request(netdev_priv(ndev), oid, 0, &u);
1da177e4
LT
1771}
1772
1773static int
1774prism54_set_raw(struct net_device *ndev, struct iw_request_info *info,
1775 struct iw_point *dwrq, char *extra)
1776{
1777 u32 oid = dwrq->flags;
1778
6dbc9c89 1779 return mgt_set_request(netdev_priv(ndev), oid, 0, extra);
1da177e4
LT
1780}
1781
1782void
1783prism54_acl_init(struct islpci_acl *acl)
1784{
6f865c0a 1785 mutex_init(&acl->lock);
1da177e4
LT
1786 INIT_LIST_HEAD(&acl->mac_list);
1787 acl->size = 0;
1788 acl->policy = MAC_POLICY_OPEN;
1789}
1790
1791static void
1792prism54_clear_mac(struct islpci_acl *acl)
1793{
1794 struct list_head *ptr, *next;
1795 struct mac_entry *entry;
1796
6f865c0a 1797 mutex_lock(&acl->lock);
1da177e4
LT
1798
1799 if (acl->size == 0) {
6f865c0a 1800 mutex_unlock(&acl->lock);
1da177e4
LT
1801 return;
1802 }
1803
1804 for (ptr = acl->mac_list.next, next = ptr->next;
1805 ptr != &acl->mac_list; ptr = next, next = ptr->next) {
1806 entry = list_entry(ptr, struct mac_entry, _list);
1807 list_del(ptr);
1808 kfree(entry);
1809 }
1810 acl->size = 0;
6f865c0a 1811 mutex_unlock(&acl->lock);
1da177e4
LT
1812}
1813
1814void
1815prism54_acl_clean(struct islpci_acl *acl)
1816{
1817 prism54_clear_mac(acl);
1818}
1819
1820static int
1821prism54_add_mac(struct net_device *ndev, struct iw_request_info *info,
1822 struct sockaddr *awrq, char *extra)
1823{
1824 islpci_private *priv = netdev_priv(ndev);
1825 struct islpci_acl *acl = &priv->acl;
1826 struct mac_entry *entry;
1827 struct sockaddr *addr = (struct sockaddr *) extra;
1828
1829 if (addr->sa_family != ARPHRD_ETHER)
1830 return -EOPNOTSUPP;
1831
1832 entry = kmalloc(sizeof (struct mac_entry), GFP_KERNEL);
1833 if (entry == NULL)
1834 return -ENOMEM;
1835
1836 memcpy(entry->addr, addr->sa_data, ETH_ALEN);
1837
6f865c0a 1838 if (mutex_lock_interruptible(&acl->lock)) {
1da177e4
LT
1839 kfree(entry);
1840 return -ERESTARTSYS;
1841 }
1842 list_add_tail(&entry->_list, &acl->mac_list);
1843 acl->size++;
6f865c0a 1844 mutex_unlock(&acl->lock);
1da177e4
LT
1845
1846 return 0;
1847}
1848
1849static int
1850prism54_del_mac(struct net_device *ndev, struct iw_request_info *info,
1851 struct sockaddr *awrq, char *extra)
1852{
1853 islpci_private *priv = netdev_priv(ndev);
1854 struct islpci_acl *acl = &priv->acl;
1855 struct mac_entry *entry;
1da177e4
LT
1856 struct sockaddr *addr = (struct sockaddr *) extra;
1857
1858 if (addr->sa_family != ARPHRD_ETHER)
1859 return -EOPNOTSUPP;
1860
6f865c0a 1861 if (mutex_lock_interruptible(&acl->lock))
1da177e4 1862 return -ERESTARTSYS;
426921bd 1863 list_for_each_entry(entry, &acl->mac_list, _list) {
692e5167 1864 if (ether_addr_equal(entry->addr, addr->sa_data)) {
426921bd 1865 list_del(&entry->_list);
1da177e4
LT
1866 acl->size--;
1867 kfree(entry);
6f865c0a 1868 mutex_unlock(&acl->lock);
1da177e4
LT
1869 return 0;
1870 }
1871 }
6f865c0a 1872 mutex_unlock(&acl->lock);
1da177e4
LT
1873 return -EINVAL;
1874}
1875
1876static int
1877prism54_get_mac(struct net_device *ndev, struct iw_request_info *info,
1878 struct iw_point *dwrq, char *extra)
1879{
1880 islpci_private *priv = netdev_priv(ndev);
1881 struct islpci_acl *acl = &priv->acl;
1882 struct mac_entry *entry;
1da177e4
LT
1883 struct sockaddr *dst = (struct sockaddr *) extra;
1884
1885 dwrq->length = 0;
1886
6f865c0a 1887 if (mutex_lock_interruptible(&acl->lock))
1da177e4
LT
1888 return -ERESTARTSYS;
1889
426921bd 1890 list_for_each_entry(entry, &acl->mac_list, _list) {
1da177e4
LT
1891 memcpy(dst->sa_data, entry->addr, ETH_ALEN);
1892 dst->sa_family = ARPHRD_ETHER;
1893 dwrq->length++;
1894 dst++;
1895 }
6f865c0a 1896 mutex_unlock(&acl->lock);
1da177e4
LT
1897 return 0;
1898}
1899
af901ca1 1900/* Setting policy also clears the MAC acl, even if we don't change the default
1da177e4
LT
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{
1da177e4
LT
1957 struct mac_entry *entry;
1958 int res = 0;
1959
6f865c0a 1960 if (mutex_lock_interruptible(&acl->lock))
1da177e4
LT
1961 return -ERESTARTSYS;
1962
1963 if (acl->policy == MAC_POLICY_OPEN) {
6f865c0a 1964 mutex_unlock(&acl->lock);
1da177e4
LT
1965 return 1;
1966 }
1967
426921bd 1968 list_for_each_entry(entry, &acl->mac_list, _list) {
1da177e4
LT
1969 if (memcmp(entry->addr, mac, ETH_ALEN) == 0) {
1970 res = 1;
1971 break;
1972 }
1973 }
1974 res = (acl->policy == MAC_POLICY_ACCEPT) ? !res : res;
6f865c0a 1975 mutex_unlock(&acl->lock);
1da177e4
LT
1976
1977 return res;
1978}
1979
1980static int
1981prism54_kick_all(struct net_device *ndev, struct iw_request_info *info,
1982 struct iw_point *dwrq, char *extra)
1983{
1984 struct obj_mlme *mlme;
1985 int rvalue;
1986
1987 mlme = kmalloc(sizeof (struct obj_mlme), GFP_KERNEL);
1988 if (mlme == NULL)
1989 return -ENOMEM;
1990
1991 /* Tell the card to kick every client */
1992 mlme->id = 0;
1993 rvalue =
1994 mgt_set_request(netdev_priv(ndev), DOT11_OID_DISASSOCIATE, 0, mlme);
1995 kfree(mlme);
1996
1997 return rvalue;
1998}
1999
2000static int
2001prism54_kick_mac(struct net_device *ndev, struct iw_request_info *info,
2002 struct sockaddr *awrq, char *extra)
2003{
2004 struct obj_mlme *mlme;
2005 struct sockaddr *addr = (struct sockaddr *) extra;
2006 int rvalue;
2007
2008 if (addr->sa_family != ARPHRD_ETHER)
2009 return -EOPNOTSUPP;
2010
2011 mlme = kmalloc(sizeof (struct obj_mlme), GFP_KERNEL);
2012 if (mlme == NULL)
2013 return -ENOMEM;
2014
2015 /* Tell the card to only kick the corresponding bastard */
2016 memcpy(mlme->address, addr->sa_data, ETH_ALEN);
2017 mlme->id = -1;
2018 rvalue =
2019 mgt_set_request(netdev_priv(ndev), DOT11_OID_DISASSOCIATE, 0, mlme);
2020
2021 kfree(mlme);
2022
2023 return rvalue;
2024}
2025
2026/* Translate a TRAP oid into a wireless event. Called in islpci_mgt_receive. */
2027
2028static void
2029format_event(islpci_private *priv, char *dest, const char *str,
2030 const struct obj_mlme *mlme, u16 *length, int error)
2031{
1da177e4 2032 int n = snprintf(dest, IW_CUSTOM_MAX,
e174961c 2033 "%s %s %pM %s (%2.2X)",
1da177e4
LT
2034 str,
2035 ((priv->iw_mode == IW_MODE_MASTER) ? "from" : "to"),
e174961c 2036 mlme->address,
1da177e4
LT
2037 (error ? (mlme->code ? " : REJECTED " : " : ACCEPTED ")
2038 : ""), mlme->code);
2039 BUG_ON(n > IW_CUSTOM_MAX);
2040 *length = n;
2041}
2042
2043static void
2044send_formatted_event(islpci_private *priv, const char *str,
2045 const struct obj_mlme *mlme, int error)
2046{
2047 union iwreq_data wrqu;
2048 char *memptr;
2049
2050 memptr = kmalloc(IW_CUSTOM_MAX, GFP_KERNEL);
2051 if (!memptr)
2052 return;
2053 wrqu.data.pointer = memptr;
2054 wrqu.data.length = 0;
2055 format_event(priv, memptr, str, mlme, &wrqu.data.length,
2056 error);
2057 wireless_send_event(priv->ndev, IWEVCUSTOM, &wrqu, memptr);
2058 kfree(memptr);
2059}
2060
2061static void
2062send_simple_event(islpci_private *priv, const char *str)
2063{
2064 union iwreq_data wrqu;
2065 char *memptr;
2066 int n = strlen(str);
2067
2068 memptr = kmalloc(IW_CUSTOM_MAX, GFP_KERNEL);
2069 if (!memptr)
2070 return;
4c92831d 2071 BUG_ON(n >= IW_CUSTOM_MAX);
1da177e4
LT
2072 wrqu.data.pointer = memptr;
2073 wrqu.data.length = n;
2074 strcpy(memptr, str);
2075 wireless_send_event(priv->ndev, IWEVCUSTOM, &wrqu, memptr);
2076 kfree(memptr);
2077}
2078
2079static void
2080link_changed(struct net_device *ndev, u32 bitrate)
2081{
2082 islpci_private *priv = netdev_priv(ndev);
2083
2084 if (bitrate) {
7b463ced 2085 netif_carrier_on(ndev);
1da177e4
LT
2086 if (priv->iw_mode == IW_MODE_INFRA) {
2087 union iwreq_data uwrq;
2088 prism54_get_wap(ndev, NULL, (struct sockaddr *) &uwrq,
2089 NULL);
2090 wireless_send_event(ndev, SIOCGIWAP, &uwrq, NULL);
2091 } else
2092 send_simple_event(netdev_priv(ndev),
2093 "Link established");
7b463ced
LR
2094 } else {
2095 netif_carrier_off(ndev);
1da177e4 2096 send_simple_event(netdev_priv(ndev), "Link lost");
7b463ced 2097 }
1da177e4
LT
2098}
2099
2100/* Beacon/ProbeResp payload header */
2101struct ieee80211_beacon_phdr {
2102 u8 timestamp[8];
2103 u16 beacon_int;
2104 u16 capab_info;
ba2d3587 2105} __packed;
1da177e4
LT
2106
2107#define WLAN_EID_GENERIC 0xdd
2108static u8 wpa_oid[4] = { 0x00, 0x50, 0xf2, 1 };
2109
1da177e4 2110static void
eab411f1
DW
2111prism54_wpa_bss_ie_add(islpci_private *priv, u8 *bssid,
2112 u8 *wpa_ie, size_t wpa_ie_len)
1da177e4
LT
2113{
2114 struct list_head *ptr;
2115 struct islpci_bss_wpa_ie *bss = NULL;
2116
2117 if (wpa_ie_len > MAX_WPA_IE_LEN)
2118 wpa_ie_len = MAX_WPA_IE_LEN;
2119
f948db5d 2120 mutex_lock(&priv->wpa_lock);
1da177e4
LT
2121
2122 /* try to use existing entry */
2123 list_for_each(ptr, &priv->bss_wpa_list) {
2124 bss = list_entry(ptr, struct islpci_bss_wpa_ie, list);
2125 if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0) {
2126 list_move(&bss->list, &priv->bss_wpa_list);
2127 break;
2128 }
2129 bss = NULL;
2130 }
2131
2132 if (bss == NULL) {
2133 /* add a new BSS entry; if max number of entries is already
2134 * reached, replace the least recently updated */
2135 if (priv->num_bss_wpa >= MAX_BSS_WPA_IE_COUNT) {
2136 bss = list_entry(priv->bss_wpa_list.prev,
2137 struct islpci_bss_wpa_ie, list);
2138 list_del(&bss->list);
2139 } else {
b950e83b
YB
2140 bss = kzalloc(sizeof (*bss), GFP_ATOMIC);
2141 if (bss != NULL)
1da177e4 2142 priv->num_bss_wpa++;
1da177e4
LT
2143 }
2144 if (bss != NULL) {
2145 memcpy(bss->bssid, bssid, ETH_ALEN);
2146 list_add(&bss->list, &priv->bss_wpa_list);
2147 }
2148 }
2149
2150 if (bss != NULL) {
2151 memcpy(bss->wpa_ie, wpa_ie, wpa_ie_len);
2152 bss->wpa_ie_len = wpa_ie_len;
2153 bss->last_update = jiffies;
2154 } else {
0795af57 2155 printk(KERN_DEBUG "Failed to add BSS WPA entry for "
e174961c 2156 "%pM\n", bssid);
1da177e4
LT
2157 }
2158
2159 /* expire old entries from WPA list */
2160 while (priv->num_bss_wpa > 0) {
2161 bss = list_entry(priv->bss_wpa_list.prev,
2162 struct islpci_bss_wpa_ie, list);
2163 if (!time_after(jiffies, bss->last_update + 60 * HZ))
2164 break;
2165
2166 list_del(&bss->list);
2167 priv->num_bss_wpa--;
2168 kfree(bss);
2169 }
2170
f948db5d 2171 mutex_unlock(&priv->wpa_lock);
1da177e4
LT
2172}
2173
2174static size_t
eab411f1 2175prism54_wpa_bss_ie_get(islpci_private *priv, u8 *bssid, u8 *wpa_ie)
1da177e4
LT
2176{
2177 struct list_head *ptr;
2178 struct islpci_bss_wpa_ie *bss = NULL;
2179 size_t len = 0;
2180
f948db5d 2181 mutex_lock(&priv->wpa_lock);
1da177e4
LT
2182
2183 list_for_each(ptr, &priv->bss_wpa_list) {
2184 bss = list_entry(ptr, struct islpci_bss_wpa_ie, list);
2185 if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0)
2186 break;
2187 bss = NULL;
2188 }
2189 if (bss) {
2190 len = bss->wpa_ie_len;
2191 memcpy(wpa_ie, bss->wpa_ie, len);
2192 }
f948db5d 2193 mutex_unlock(&priv->wpa_lock);
1da177e4
LT
2194
2195 return len;
2196}
2197
2198void
eab411f1 2199prism54_wpa_bss_ie_init(islpci_private *priv)
1da177e4
LT
2200{
2201 INIT_LIST_HEAD(&priv->bss_wpa_list);
f948db5d 2202 mutex_init(&priv->wpa_lock);
1da177e4
LT
2203}
2204
2205void
eab411f1 2206prism54_wpa_bss_ie_clean(islpci_private *priv)
1da177e4 2207{
426921bd 2208 struct islpci_bss_wpa_ie *bss, *n;
1da177e4 2209
426921bd 2210 list_for_each_entry_safe(bss, n, &priv->bss_wpa_list, list) {
1da177e4
LT
2211 kfree(bss);
2212 }
2213}
2214
2215static void
2216prism54_process_bss_data(islpci_private *priv, u32 oid, u8 *addr,
2217 u8 *payload, size_t len)
2218{
2219 struct ieee80211_beacon_phdr *hdr;
2220 u8 *pos, *end;
2221
2222 if (!priv->wpa)
2223 return;
2224
2225 hdr = (struct ieee80211_beacon_phdr *) payload;
2226 pos = (u8 *) (hdr + 1);
2227 end = payload + len;
2228 while (pos < end) {
2229 if (pos + 2 + pos[1] > end) {
2230 printk(KERN_DEBUG "Parsing Beacon/ProbeResp failed "
e174961c 2231 "for %pM\n", addr);
1da177e4
LT
2232 return;
2233 }
2234 if (pos[0] == WLAN_EID_GENERIC && pos[1] >= 4 &&
2235 memcmp(pos + 2, wpa_oid, 4) == 0) {
eab411f1 2236 prism54_wpa_bss_ie_add(priv, addr, pos, pos[1] + 2);
1da177e4
LT
2237 return;
2238 }
2239 pos += 2 + pos[1];
2240 }
2241}
2242
2243static void
2244handle_request(islpci_private *priv, struct obj_mlme *mlme, enum oid_num_t oid)
2245{
2246 if (((mlme->state == DOT11_STATE_AUTHING) ||
2247 (mlme->state == DOT11_STATE_ASSOCING))
2248 && mgt_mlme_answer(priv)) {
2249 /* Someone is requesting auth and we must respond. Just send back
2250 * the trap with error code set accordingly.
2251 */
2252 mlme->code = prism54_mac_accept(&priv->acl,
2253 mlme->address) ? 0 : 1;
2254 mgt_set_request(priv, oid, 0, mlme);
2255 }
2256}
2257
2258static int
2259prism54_process_trap_helper(islpci_private *priv, enum oid_num_t oid,
2260 char *data)
2261{
2262 struct obj_mlme *mlme = (struct obj_mlme *) data;
2263 struct obj_mlmeex *mlmeex = (struct obj_mlmeex *) data;
2264 struct obj_mlmeex *confirm;
2265 u8 wpa_ie[MAX_WPA_IE_LEN];
2266 int wpa_ie_len;
2267 size_t len = 0; /* u16, better? */
2268 u8 *payload = NULL, *pos = NULL;
2269 int ret;
2270
2271 /* I think all trapable objects are listed here.
2272 * Some oids have a EX version. The difference is that they are emitted
2273 * in DOT11_MLME_EXTENDED mode (set with DOT11_OID_MLMEAUTOLEVEL)
2274 * with more info.
2275 * The few events already defined by the wireless tools are not really
2276 * suited. We use the more flexible custom event facility.
2277 */
2278
2279 if (oid >= DOT11_OID_BEACON) {
2280 len = mlmeex->size;
2281 payload = pos = mlmeex->data;
2282 }
2283
2284 /* I fear prism54_process_bss_data won't work with big endian data */
2285 if ((oid == DOT11_OID_BEACON) || (oid == DOT11_OID_PROBE))
2286 prism54_process_bss_data(priv, oid, mlmeex->address,
2287 payload, len);
2288
2289 mgt_le_to_cpu(isl_oid[oid].flags & OID_FLAG_TYPE, (void *) mlme);
2290
2291 switch (oid) {
2292
2293 case GEN_OID_LINKSTATE:
2294 link_changed(priv->ndev, (u32) *data);
2295 break;
2296
2297 case DOT11_OID_MICFAILURE:
2298 send_simple_event(priv, "Mic failure");
2299 break;
2300
2301 case DOT11_OID_DEAUTHENTICATE:
2302 send_formatted_event(priv, "DeAuthenticate request", mlme, 0);
2303 break;
2304
2305 case DOT11_OID_AUTHENTICATE:
2306 handle_request(priv, mlme, oid);
2307 send_formatted_event(priv, "Authenticate request", mlme, 1);
2308 break;
2309
2310 case DOT11_OID_DISASSOCIATE:
2311 send_formatted_event(priv, "Disassociate request", mlme, 0);
2312 break;
2313
2314 case DOT11_OID_ASSOCIATE:
2315 handle_request(priv, mlme, oid);
2316 send_formatted_event(priv, "Associate request", mlme, 1);
2317 break;
2318
2319 case DOT11_OID_REASSOCIATE:
2320 handle_request(priv, mlme, oid);
2321 send_formatted_event(priv, "ReAssociate request", mlme, 1);
2322 break;
2323
2324 case DOT11_OID_BEACON:
2325 send_formatted_event(priv,
af901ca1 2326 "Received a beacon from an unknown AP",
1da177e4
LT
2327 mlme, 0);
2328 break;
2329
2330 case DOT11_OID_PROBE:
2331 /* we received a probe from a client. */
2332 send_formatted_event(priv, "Received a probe from client", mlme,
2333 0);
2334 break;
2335
2336 /* Note : "mlme" is actually a "struct obj_mlmeex *" here, but this
2337 * is backward compatible layout-wise with "struct obj_mlme".
2338 */
2339
2340 case DOT11_OID_DEAUTHENTICATEEX:
2341 send_formatted_event(priv, "DeAuthenticate request", mlme, 0);
2342 break;
2343
2344 case DOT11_OID_AUTHENTICATEEX:
2345 handle_request(priv, mlme, oid);
2346 send_formatted_event(priv, "Authenticate request (ex)", mlme, 1);
2347
93b2dd12 2348 if (priv->iw_mode != IW_MODE_MASTER
1da177e4
LT
2349 && mlmeex->state != DOT11_STATE_AUTHING)
2350 break;
2351
2352 confirm = kmalloc(sizeof(struct obj_mlmeex) + 6, GFP_ATOMIC);
2353
93b2dd12 2354 if (!confirm)
1da177e4
LT
2355 break;
2356
2357 memcpy(&confirm->address, mlmeex->address, ETH_ALEN);
e174961c
JB
2358 printk(KERN_DEBUG "Authenticate from: address:\t%pM\n",
2359 mlmeex->address);
1da177e4
LT
2360 confirm->id = -1; /* or mlmeex->id ? */
2361 confirm->state = 0; /* not used */
2362 confirm->code = 0;
2363 confirm->size = 6;
2364 confirm->data[0] = 0x00;
2365 confirm->data[1] = 0x00;
2366 confirm->data[2] = 0x02;
2367 confirm->data[3] = 0x00;
2368 confirm->data[4] = 0x00;
2369 confirm->data[5] = 0x00;
2370
2371 ret = mgt_set_varlen(priv, DOT11_OID_ASSOCIATEEX, confirm, 6);
2372
2373 kfree(confirm);
2374 if (ret)
2375 return ret;
2376 break;
2377
2378 case DOT11_OID_DISASSOCIATEEX:
2379 send_formatted_event(priv, "Disassociate request (ex)", mlme, 0);
2380 break;
2381
2382 case DOT11_OID_ASSOCIATEEX:
2383 handle_request(priv, mlme, oid);
2384 send_formatted_event(priv, "Associate request (ex)", mlme, 1);
2385
93b2dd12 2386 if (priv->iw_mode != IW_MODE_MASTER
eab411f1 2387 && mlmeex->state != DOT11_STATE_ASSOCING)
1da177e4 2388 break;
93b2dd12 2389
1da177e4
LT
2390 confirm = kmalloc(sizeof(struct obj_mlmeex), GFP_ATOMIC);
2391
2392 if (!confirm)
2393 break;
2394
2395 memcpy(&confirm->address, mlmeex->address, ETH_ALEN);
2396
2397 confirm->id = ((struct obj_mlmeex *)mlme)->id;
2398 confirm->state = 0; /* not used */
2399 confirm->code = 0;
2400
eab411f1 2401 wpa_ie_len = prism54_wpa_bss_ie_get(priv, mlmeex->address, wpa_ie);
1da177e4
LT
2402
2403 if (!wpa_ie_len) {
e174961c
JB
2404 printk(KERN_DEBUG "No WPA IE found from address:\t%pM\n",
2405 mlmeex->address);
1da177e4
LT
2406 kfree(confirm);
2407 break;
2408 }
2409
2410 confirm->size = wpa_ie_len;
2411 memcpy(&confirm->data, wpa_ie, wpa_ie_len);
2412
2413 mgt_set_varlen(priv, oid, confirm, wpa_ie_len);
2414
2415 kfree(confirm);
93b2dd12 2416
1da177e4
LT
2417 break;
2418
2419 case DOT11_OID_REASSOCIATEEX:
2420 handle_request(priv, mlme, oid);
2421 send_formatted_event(priv, "Reassociate request (ex)", mlme, 1);
2422
93b2dd12 2423 if (priv->iw_mode != IW_MODE_MASTER
1da177e4
LT
2424 && mlmeex->state != DOT11_STATE_ASSOCING)
2425 break;
2426
2427 confirm = kmalloc(sizeof(struct obj_mlmeex), GFP_ATOMIC);
2428
2429 if (!confirm)
2430 break;
2431
2432 memcpy(&confirm->address, mlmeex->address, ETH_ALEN);
2433
2434 confirm->id = mlmeex->id;
2435 confirm->state = 0; /* not used */
2436 confirm->code = 0;
2437
eab411f1 2438 wpa_ie_len = prism54_wpa_bss_ie_get(priv, mlmeex->address, wpa_ie);
1da177e4
LT
2439
2440 if (!wpa_ie_len) {
e174961c
JB
2441 printk(KERN_DEBUG "No WPA IE found from address:\t%pM\n",
2442 mlmeex->address);
1da177e4
LT
2443 kfree(confirm);
2444 break;
2445 }
2446
93b2dd12 2447 confirm->size = wpa_ie_len;
1da177e4
LT
2448 memcpy(&confirm->data, wpa_ie, wpa_ie_len);
2449
2450 mgt_set_varlen(priv, oid, confirm, wpa_ie_len);
2451
2452 kfree(confirm);
93b2dd12 2453
1da177e4
LT
2454 break;
2455
2456 default:
2457 return -EINVAL;
2458 }
2459
2460 return 0;
2461}
2462
2463/*
2464 * Process a device trap. This is called via schedule_work(), outside of
2465 * interrupt context, no locks held.
2466 */
2467void
c4028958 2468prism54_process_trap(struct work_struct *work)
1da177e4 2469{
c4028958
DH
2470 struct islpci_mgmtframe *frame =
2471 container_of(work, struct islpci_mgmtframe, ws);
1da177e4
LT
2472 struct net_device *ndev = frame->ndev;
2473 enum oid_num_t n = mgt_oidtonum(frame->header->oid);
2474
2475 if (n != OID_NUM_LAST)
2476 prism54_process_trap_helper(netdev_priv(ndev), n, frame->data);
2477 islpci_mgt_release(frame);
2478}
2479
2480int
2481prism54_set_mac_address(struct net_device *ndev, void *addr)
2482{
2483 islpci_private *priv = netdev_priv(ndev);
2484 int ret;
2485
2486 if (ndev->addr_len != 6)
2487 return -EINVAL;
2488 ret = mgt_set_request(priv, GEN_OID_MACADDRESS, 0,
2489 &((struct sockaddr *) addr)->sa_data);
2490 if (!ret)
2491 memcpy(priv->ndev->dev_addr,
d458cdf7 2492 &((struct sockaddr *) addr)->sa_data, ETH_ALEN);
1da177e4
LT
2493
2494 return ret;
2495}
2496
1da177e4 2497#define PRISM54_SET_WPA SIOCIWFIRSTPRIV+12
1da177e4
LT
2498
2499static int
2500prism54_set_wpa(struct net_device *ndev, struct iw_request_info *info,
2501 __u32 * uwrq, char *extra)
2502{
2503 islpci_private *priv = netdev_priv(ndev);
2504 u32 mlme, authen, dot1x, filter, wep;
2505
2506 if (islpci_get_state(priv) < PRV_STATE_INIT)
2507 return 0;
2508
2509 wep = 1; /* For privacy invoked */
2510 filter = 1; /* Filter out all unencrypted frames */
2511 dot1x = 0x01; /* To enable eap filter */
2512 mlme = DOT11_MLME_EXTENDED;
2513 authen = DOT11_AUTH_OS; /* Only WEP uses _SK and _BOTH */
2514
2515 down_write(&priv->mib_sem);
2516 priv->wpa = *uwrq;
2517
2518 switch (priv->wpa) {
2519 default:
2520 case 0: /* Clears/disables WPA and friends */
2521 wep = 0;
2522 filter = 0; /* Do not filter un-encrypted data */
2523 dot1x = 0;
2524 mlme = DOT11_MLME_AUTO;
2525 printk("%s: Disabling WPA\n", ndev->name);
2526 break;
93b2dd12 2527 case 2:
1da177e4
LT
2528 case 1: /* WPA */
2529 printk("%s: Enabling WPA\n", ndev->name);
2530 break;
2531 }
2532 up_write(&priv->mib_sem);
2533
2534 mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0, &authen);
2535 mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0, &wep);
2536 mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0, &filter);
2537 mgt_set_request(priv, DOT11_OID_DOT1XENABLE, 0, &dot1x);
2538 mgt_set_request(priv, DOT11_OID_MLMEAUTOLEVEL, 0, &mlme);
2539
2540 return 0;
2541}
2542
2543static int
2544prism54_get_wpa(struct net_device *ndev, struct iw_request_info *info,
2545 __u32 * uwrq, char *extra)
2546{
2547 islpci_private *priv = netdev_priv(ndev);
2548 *uwrq = priv->wpa;
2549 return 0;
2550}
2551
2552static int
2553prism54_set_prismhdr(struct net_device *ndev, struct iw_request_info *info,
2554 __u32 * uwrq, char *extra)
2555{
2556 islpci_private *priv = netdev_priv(ndev);
2557 priv->monitor_type =
2558 (*uwrq ? ARPHRD_IEEE80211_PRISM : ARPHRD_IEEE80211);
2559 if (priv->iw_mode == IW_MODE_MONITOR)
2560 priv->ndev->type = priv->monitor_type;
2561
2562 return 0;
2563}
2564
2565static int
2566prism54_get_prismhdr(struct net_device *ndev, struct iw_request_info *info,
2567 __u32 * uwrq, char *extra)
2568{
2569 islpci_private *priv = netdev_priv(ndev);
2570 *uwrq = (priv->monitor_type == ARPHRD_IEEE80211_PRISM);
2571 return 0;
2572}
2573
2574static int
2575prism54_debug_oid(struct net_device *ndev, struct iw_request_info *info,
2576 __u32 * uwrq, char *extra)
2577{
2578 islpci_private *priv = netdev_priv(ndev);
2579
2580 priv->priv_oid = *uwrq;
2581 printk("%s: oid 0x%08X\n", ndev->name, *uwrq);
2582
2583 return 0;
2584}
2585
2586static int
2587prism54_debug_get_oid(struct net_device *ndev, struct iw_request_info *info,
2588 struct iw_point *data, char *extra)
2589{
2590 islpci_private *priv = netdev_priv(ndev);
2591 struct islpci_mgmtframe *response;
2592 int ret = -EIO;
2593
2594 printk("%s: get_oid 0x%08X\n", ndev->name, priv->priv_oid);
2595 data->length = 0;
2596
2597 if (islpci_get_state(priv) >= PRV_STATE_INIT) {
2598 ret =
2599 islpci_mgt_transaction(priv->ndev, PIMFOR_OP_GET,
2600 priv->priv_oid, extra, 256,
2601 &response);
2602 printk("%s: ret: %i\n", ndev->name, ret);
2603 if (ret || !response
2604 || response->header->operation == PIMFOR_OP_ERROR) {
2605 if (response) {
2606 islpci_mgt_release(response);
2607 }
2608 printk("%s: EIO\n", ndev->name);
2609 ret = -EIO;
2610 }
2611 if (!ret) {
2612 data->length = response->header->length;
2613 memcpy(extra, response->data, data->length);
2614 islpci_mgt_release(response);
2615 printk("%s: len: %i\n", ndev->name, data->length);
2616 }
2617 }
2618
2619 return ret;
2620}
2621
2622static int
2623prism54_debug_set_oid(struct net_device *ndev, struct iw_request_info *info,
2624 struct iw_point *data, char *extra)
2625{
2626 islpci_private *priv = netdev_priv(ndev);
2627 struct islpci_mgmtframe *response;
2628 int ret = 0, response_op = PIMFOR_OP_ERROR;
2629
2630 printk("%s: set_oid 0x%08X\tlen: %d\n", ndev->name, priv->priv_oid,
2631 data->length);
2632
2633 if (islpci_get_state(priv) >= PRV_STATE_INIT) {
2634 ret =
2635 islpci_mgt_transaction(priv->ndev, PIMFOR_OP_SET,
2636 priv->priv_oid, extra, data->length,
2637 &response);
2638 printk("%s: ret: %i\n", ndev->name, ret);
2639 if (ret || !response
2640 || response->header->operation == PIMFOR_OP_ERROR) {
2641 if (response) {
2642 islpci_mgt_release(response);
2643 }
2644 printk("%s: EIO\n", ndev->name);
2645 ret = -EIO;
2646 }
2647 if (!ret) {
2648 response_op = response->header->operation;
2649 printk("%s: response_op: %i\n", ndev->name,
2650 response_op);
2651 islpci_mgt_release(response);
2652 }
2653 }
2654
2655 return (ret ? ret : -EINPROGRESS);
2656}
2657
2658static int
2659prism54_set_spy(struct net_device *ndev,
2660 struct iw_request_info *info,
2661 union iwreq_data *uwrq, char *extra)
2662{
2663 islpci_private *priv = netdev_priv(ndev);
7f50ca07
HE
2664 u32 u;
2665 enum oid_num_t oid = OID_INL_CONFIG;
1da177e4
LT
2666
2667 down_write(&priv->mib_sem);
2668 mgt_get(priv, OID_INL_CONFIG, &u);
2669
2670 if ((uwrq->data.length == 0) && (priv->spy_data.spy_number > 0))
2671 /* disable spy */
2672 u &= ~INL_CONFIG_RXANNEX;
2673 else if ((uwrq->data.length > 0) && (priv->spy_data.spy_number == 0))
2674 /* enable spy */
2675 u |= INL_CONFIG_RXANNEX;
2676
2677 mgt_set(priv, OID_INL_CONFIG, &u);
2678 mgt_commit_list(priv, &oid, 1);
2679 up_write(&priv->mib_sem);
2680
2681 return iw_handler_set_spy(ndev, info, uwrq, extra);
2682}
2683
2684static const iw_handler prism54_handler[] = {
2685 (iw_handler) prism54_commit, /* SIOCSIWCOMMIT */
2686 (iw_handler) prism54_get_name, /* SIOCGIWNAME */
2687 (iw_handler) NULL, /* SIOCSIWNWID */
2688 (iw_handler) NULL, /* SIOCGIWNWID */
2689 (iw_handler) prism54_set_freq, /* SIOCSIWFREQ */
2690 (iw_handler) prism54_get_freq, /* SIOCGIWFREQ */
2691 (iw_handler) prism54_set_mode, /* SIOCSIWMODE */
2692 (iw_handler) prism54_get_mode, /* SIOCGIWMODE */
2693 (iw_handler) prism54_set_sens, /* SIOCSIWSENS */
2694 (iw_handler) prism54_get_sens, /* SIOCGIWSENS */
2695 (iw_handler) NULL, /* SIOCSIWRANGE */
2696 (iw_handler) prism54_get_range, /* SIOCGIWRANGE */
2697 (iw_handler) NULL, /* SIOCSIWPRIV */
2698 (iw_handler) NULL, /* SIOCGIWPRIV */
2699 (iw_handler) NULL, /* SIOCSIWSTATS */
2700 (iw_handler) NULL, /* SIOCGIWSTATS */
2701 prism54_set_spy, /* SIOCSIWSPY */
2702 iw_handler_get_spy, /* SIOCGIWSPY */
2703 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2704 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2705 (iw_handler) prism54_set_wap, /* SIOCSIWAP */
2706 (iw_handler) prism54_get_wap, /* SIOCGIWAP */
2707 (iw_handler) NULL, /* -- hole -- */
1591275c 2708 (iw_handler) NULL, /* SIOCGIWAPLIST deprecated */
1da177e4
LT
2709 (iw_handler) prism54_set_scan, /* SIOCSIWSCAN */
2710 (iw_handler) prism54_get_scan, /* SIOCGIWSCAN */
2711 (iw_handler) prism54_set_essid, /* SIOCSIWESSID */
2712 (iw_handler) prism54_get_essid, /* SIOCGIWESSID */
2713 (iw_handler) prism54_set_nick, /* SIOCSIWNICKN */
2714 (iw_handler) prism54_get_nick, /* SIOCGIWNICKN */
2715 (iw_handler) NULL, /* -- hole -- */
2716 (iw_handler) NULL, /* -- hole -- */
2717 (iw_handler) prism54_set_rate, /* SIOCSIWRATE */
2718 (iw_handler) prism54_get_rate, /* SIOCGIWRATE */
2719 (iw_handler) prism54_set_rts, /* SIOCSIWRTS */
2720 (iw_handler) prism54_get_rts, /* SIOCGIWRTS */
2721 (iw_handler) prism54_set_frag, /* SIOCSIWFRAG */
2722 (iw_handler) prism54_get_frag, /* SIOCGIWFRAG */
2723 (iw_handler) prism54_set_txpower, /* SIOCSIWTXPOW */
2724 (iw_handler) prism54_get_txpower, /* SIOCGIWTXPOW */
2725 (iw_handler) prism54_set_retry, /* SIOCSIWRETRY */
2726 (iw_handler) prism54_get_retry, /* SIOCGIWRETRY */
2727 (iw_handler) prism54_set_encode, /* SIOCSIWENCODE */
2728 (iw_handler) prism54_get_encode, /* SIOCGIWENCODE */
2729 (iw_handler) NULL, /* SIOCSIWPOWER */
2730 (iw_handler) NULL, /* SIOCGIWPOWER */
eab411f1
DW
2731 NULL, /* -- hole -- */
2732 NULL, /* -- hole -- */
2733 (iw_handler) prism54_set_genie, /* SIOCSIWGENIE */
2734 (iw_handler) prism54_get_genie, /* SIOCGIWGENIE */
2735 (iw_handler) prism54_set_auth, /* SIOCSIWAUTH */
2736 (iw_handler) prism54_get_auth, /* SIOCGIWAUTH */
2737 (iw_handler) prism54_set_encodeext, /* SIOCSIWENCODEEXT */
2738 (iw_handler) prism54_get_encodeext, /* SIOCGIWENCODEEXT */
2739 NULL, /* SIOCSIWPMKSA */
1da177e4
LT
2740};
2741
2742/* The low order bit identify a SET (0) or a GET (1) ioctl. */
2743
2744#define PRISM54_RESET SIOCIWFIRSTPRIV
2745#define PRISM54_GET_POLICY SIOCIWFIRSTPRIV+1
2746#define PRISM54_SET_POLICY SIOCIWFIRSTPRIV+2
2747#define PRISM54_GET_MAC SIOCIWFIRSTPRIV+3
2748#define PRISM54_ADD_MAC SIOCIWFIRSTPRIV+4
2749
2750#define PRISM54_DEL_MAC SIOCIWFIRSTPRIV+6
2751
2752#define PRISM54_KICK_MAC SIOCIWFIRSTPRIV+8
2753
2754#define PRISM54_KICK_ALL SIOCIWFIRSTPRIV+10
2755
2756#define PRISM54_GET_WPA SIOCIWFIRSTPRIV+11
2757#define PRISM54_SET_WPA SIOCIWFIRSTPRIV+12
2758
2759#define PRISM54_DBG_OID SIOCIWFIRSTPRIV+14
2760#define PRISM54_DBG_GET_OID SIOCIWFIRSTPRIV+15
2761#define PRISM54_DBG_SET_OID SIOCIWFIRSTPRIV+16
2762
2763#define PRISM54_GET_OID SIOCIWFIRSTPRIV+17
2764#define PRISM54_SET_OID_U32 SIOCIWFIRSTPRIV+18
2765#define PRISM54_SET_OID_STR SIOCIWFIRSTPRIV+20
2766#define PRISM54_SET_OID_ADDR SIOCIWFIRSTPRIV+22
2767
2768#define PRISM54_GET_PRISMHDR SIOCIWFIRSTPRIV+23
2769#define PRISM54_SET_PRISMHDR SIOCIWFIRSTPRIV+24
2770
2771#define IWPRIV_SET_U32(n,x) { n, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "s_"x }
2772#define IWPRIV_SET_SSID(n,x) { n, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 1, 0, "s_"x }
2773#define IWPRIV_SET_ADDR(n,x) { n, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "s_"x }
2774#define IWPRIV_GET(n,x) { n, 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | PRIV_STR_SIZE, "g_"x }
2775
2776#define IWPRIV_U32(n,x) IWPRIV_SET_U32(n,x), IWPRIV_GET(n,x)
2777#define IWPRIV_SSID(n,x) IWPRIV_SET_SSID(n,x), IWPRIV_GET(n,x)
2778#define IWPRIV_ADDR(n,x) IWPRIV_SET_ADDR(n,x), IWPRIV_GET(n,x)
2779
2780/* Note : limited to 128 private ioctls (wireless tools 26) */
2781
2782static const struct iw_priv_args prism54_private_args[] = {
2783/*{ cmd, set_args, get_args, name } */
2784 {PRISM54_RESET, 0, 0, "reset"},
2785 {PRISM54_GET_PRISMHDR, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2786 "get_prismhdr"},
2787 {PRISM54_SET_PRISMHDR, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0,
2788 "set_prismhdr"},
2789 {PRISM54_GET_POLICY, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2790 "getPolicy"},
2791 {PRISM54_SET_POLICY, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0,
2792 "setPolicy"},
2793 {PRISM54_GET_MAC, 0, IW_PRIV_TYPE_ADDR | 64, "getMac"},
2794 {PRISM54_ADD_MAC, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0,
2795 "addMac"},
2796 {PRISM54_DEL_MAC, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0,
2797 "delMac"},
2798 {PRISM54_KICK_MAC, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0,
2799 "kickMac"},
2800 {PRISM54_KICK_ALL, 0, 0, "kickAll"},
2801 {PRISM54_GET_WPA, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2802 "get_wpa"},
2803 {PRISM54_SET_WPA, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0,
2804 "set_wpa"},
2805 {PRISM54_DBG_OID, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0,
2806 "dbg_oid"},
2807 {PRISM54_DBG_GET_OID, 0, IW_PRIV_TYPE_BYTE | 256, "dbg_get_oid"},
2808 {PRISM54_DBG_SET_OID, IW_PRIV_TYPE_BYTE | 256, 0, "dbg_set_oid"},
2809 /* --- sub-ioctls handlers --- */
2810 {PRISM54_GET_OID,
2811 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | PRIV_STR_SIZE, ""},
2812 {PRISM54_SET_OID_U32,
2813 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, ""},
2814 {PRISM54_SET_OID_STR,
2815 IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 1, 0, ""},
2816 {PRISM54_SET_OID_ADDR,
2817 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, ""},
2818 /* --- sub-ioctls definitions --- */
2819 IWPRIV_ADDR(GEN_OID_MACADDRESS, "addr"),
2820 IWPRIV_GET(GEN_OID_LINKSTATE, "linkstate"),
2821 IWPRIV_U32(DOT11_OID_BSSTYPE, "bsstype"),
2822 IWPRIV_ADDR(DOT11_OID_BSSID, "bssid"),
2823 IWPRIV_U32(DOT11_OID_STATE, "state"),
2824 IWPRIV_U32(DOT11_OID_AID, "aid"),
2825
2826 IWPRIV_SSID(DOT11_OID_SSIDOVERRIDE, "ssidoverride"),
2827
2828 IWPRIV_U32(DOT11_OID_MEDIUMLIMIT, "medlimit"),
2829 IWPRIV_U32(DOT11_OID_BEACONPERIOD, "beacon"),
2830 IWPRIV_U32(DOT11_OID_DTIMPERIOD, "dtimperiod"),
2831
2832 IWPRIV_U32(DOT11_OID_AUTHENABLE, "authenable"),
2833 IWPRIV_U32(DOT11_OID_PRIVACYINVOKED, "privinvok"),
2834 IWPRIV_U32(DOT11_OID_EXUNENCRYPTED, "exunencrypt"),
2835
2836 IWPRIV_U32(DOT11_OID_REKEYTHRESHOLD, "rekeythresh"),
2837
2838 IWPRIV_U32(DOT11_OID_MAXTXLIFETIME, "maxtxlife"),
2839 IWPRIV_U32(DOT11_OID_MAXRXLIFETIME, "maxrxlife"),
2840 IWPRIV_U32(DOT11_OID_ALOFT_FIXEDRATE, "fixedrate"),
2841 IWPRIV_U32(DOT11_OID_MAXFRAMEBURST, "frameburst"),
2842 IWPRIV_U32(DOT11_OID_PSM, "psm"),
2843
2844 IWPRIV_U32(DOT11_OID_BRIDGELOCAL, "bridge"),
2845 IWPRIV_U32(DOT11_OID_CLIENTS, "clients"),
2846 IWPRIV_U32(DOT11_OID_CLIENTSASSOCIATED, "clientassoc"),
2847 IWPRIV_U32(DOT11_OID_DOT1XENABLE, "dot1xenable"),
2848 IWPRIV_U32(DOT11_OID_ANTENNARX, "rxant"),
2849 IWPRIV_U32(DOT11_OID_ANTENNATX, "txant"),
2850 IWPRIV_U32(DOT11_OID_ANTENNADIVERSITY, "antdivers"),
2851 IWPRIV_U32(DOT11_OID_EDTHRESHOLD, "edthresh"),
2852 IWPRIV_U32(DOT11_OID_PREAMBLESETTINGS, "preamble"),
2853 IWPRIV_GET(DOT11_OID_RATES, "rates"),
2854 IWPRIV_U32(DOT11_OID_OUTPUTPOWER, ".11outpower"),
2855 IWPRIV_GET(DOT11_OID_SUPPORTEDRATES, "supprates"),
2856 IWPRIV_GET(DOT11_OID_SUPPORTEDFREQUENCIES, "suppfreq"),
2857
2858 IWPRIV_U32(DOT11_OID_NOISEFLOOR, "noisefloor"),
2859 IWPRIV_GET(DOT11_OID_FREQUENCYACTIVITY, "freqactivity"),
2860 IWPRIV_U32(DOT11_OID_NONERPPROTECTION, "nonerpprotec"),
2861 IWPRIV_U32(DOT11_OID_PROFILES, "profile"),
2862 IWPRIV_GET(DOT11_OID_EXTENDEDRATES, "extrates"),
2863 IWPRIV_U32(DOT11_OID_MLMEAUTOLEVEL, "mlmelevel"),
2864
2865 IWPRIV_GET(DOT11_OID_BSSS, "bsss"),
2866 IWPRIV_GET(DOT11_OID_BSSLIST, "bsslist"),
2867 IWPRIV_U32(OID_INL_MODE, "mode"),
2868 IWPRIV_U32(OID_INL_CONFIG, "config"),
2869 IWPRIV_U32(OID_INL_DOT11D_CONFORMANCE, ".11dconform"),
2870 IWPRIV_GET(OID_INL_PHYCAPABILITIES, "phycapa"),
2871 IWPRIV_U32(OID_INL_OUTPUTPOWER, "outpower"),
2872};
2873
2874static const iw_handler prism54_private_handler[] = {
2875 (iw_handler) prism54_reset,
2876 (iw_handler) prism54_get_policy,
2877 (iw_handler) prism54_set_policy,
2878 (iw_handler) prism54_get_mac,
2879 (iw_handler) prism54_add_mac,
2880 (iw_handler) NULL,
2881 (iw_handler) prism54_del_mac,
2882 (iw_handler) NULL,
2883 (iw_handler) prism54_kick_mac,
2884 (iw_handler) NULL,
2885 (iw_handler) prism54_kick_all,
2886 (iw_handler) prism54_get_wpa,
2887 (iw_handler) prism54_set_wpa,
2888 (iw_handler) NULL,
2889 (iw_handler) prism54_debug_oid,
2890 (iw_handler) prism54_debug_get_oid,
2891 (iw_handler) prism54_debug_set_oid,
2892 (iw_handler) prism54_get_oid,
2893 (iw_handler) prism54_set_u32,
2894 (iw_handler) NULL,
2895 (iw_handler) prism54_set_raw,
2896 (iw_handler) NULL,
2897 (iw_handler) prism54_set_raw,
2898 (iw_handler) prism54_get_prismhdr,
2899 (iw_handler) prism54_set_prismhdr,
2900};
2901
2902const struct iw_handler_def prism54_handler_def = {
ff8ac609
DC
2903 .num_standard = ARRAY_SIZE(prism54_handler),
2904 .num_private = ARRAY_SIZE(prism54_private_handler),
2905 .num_private_args = ARRAY_SIZE(prism54_private_args),
1da177e4
LT
2906 .standard = (iw_handler *) prism54_handler,
2907 .private = (iw_handler *) prism54_private_handler,
2908 .private_args = (struct iw_priv_args *) prism54_private_args,
61bd4963 2909 .get_wireless_stats = prism54_get_wireless_stats,
1da177e4 2910};