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