Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux...
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / staging / otus / ioctl.c
CommitLineData
4bd43f50
LR
1/*
2 * Copyright (c) 2007-2008 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16/* */
17/* Module Name : ioctl.c */
18/* */
19/* Abstract */
20/* This module contains Linux wireless extension related functons. */
21/* */
22/* NOTES */
23/* Platform dependent. */
24/* */
25/************************************************************************/
5a0e3ad6 26#include <linux/slab.h>
4bd43f50
LR
27#include <linux/module.h>
28#include <linux/if_arp.h>
aef911a5 29#include <linux/uaccess.h>
4bd43f50
LR
30
31#include "usbdrv.h"
32
cd20decf
SH
33#define ZD_IOCTL_WPA (SIOCDEVPRIVATE + 1)
34#define ZD_IOCTL_PARAM (SIOCDEVPRIVATE + 2)
35#define ZD_IOCTL_GETWPAIE (SIOCDEVPRIVATE + 3)
4bd43f50 36#ifdef ZM_ENABLE_CENC
cd20decf 37#define ZM_IOCTL_CENC (SIOCDEVPRIVATE + 4)
aef911a5 38#endif /* ZM_ENABLE_CENC */
cd20decf
SH
39#define ZD_PARAM_ROAMING 0x0001
40#define ZD_PARAM_PRIVACY 0x0002
41#define ZD_PARAM_WPA 0x0003
4bd43f50
LR
42#define ZD_PARAM_COUNTERMEASURES 0x0004
43#define ZD_PARAM_DROPUNENCRYPTED 0x0005
cd20decf
SH
44#define ZD_PARAM_AUTH_ALGS 0x0006
45#define ZD_PARAM_WPS_FILTER 0x0007
4bd43f50
LR
46
47#ifdef ZM_ENABLE_CENC
48#define P80211_PACKET_CENCFLAG 0x0001
aef911a5 49#endif /* ZM_ENABLE_CENC */
cd20decf 50#define P80211_PACKET_SETKEY 0x0003
4bd43f50
LR
51
52#define ZD_CMD_SET_ENCRYPT_KEY 0x0001
cd20decf
SH
53#define ZD_CMD_SET_MLME 0x0002
54#define ZD_CMD_SCAN_REQ 0x0003
4bd43f50 55#define ZD_CMD_SET_GENERIC_ELEMENT 0x0004
cd20decf 56#define ZD_CMD_GET_TSC 0x0005
4bd43f50
LR
57
58#define ZD_CRYPT_ALG_NAME_LEN 16
cd20decf
SH
59#define ZD_MAX_KEY_SIZE 32
60#define ZD_MAX_GENERIC_SIZE 64
4bd43f50 61
4bd43f50 62#include <net/iw_handler.h>
4bd43f50 63
aef911a5 64extern u16_t zfLnxGetVapId(zdev_t *dev);
4bd43f50 65
25b37eca 66static const u32_t channel_frequency_11A[] = {
aef911a5
DZ
67 /* Even element for Channel Number, Odd for Frequency */
68 36, 5180,
69 40, 5200,
70 44, 5220,
71 48, 5240,
72 52, 5260,
73 56, 5280,
74 60, 5300,
75 64, 5320,
76 100, 5500,
77 104, 5520,
78 108, 5540,
79 112, 5560,
80 116, 5580,
81 120, 5600,
82 124, 5620,
83 128, 5640,
84 132, 5660,
85 136, 5680,
86 140, 5700,
87 /**/
88 184, 4920,
89 188, 4940,
90 192, 4960,
91 196, 4980,
92 8, 5040,
93 12, 5060,
94 16, 5080,
95 34, 5170,
96 38, 5190,
97 42, 5210,
98 46, 5230,
99 /**/
100 149, 5745,
101 153, 5765,
102 157, 5785,
103 161, 5805,
104 165, 5825
105 /**/
4bd43f50
LR
106};
107
108int usbdrv_freq2chan(u32_t freq)
109{
aef911a5
DZ
110 /* 2.4G Hz */
111 if (freq > 2400 && freq < 3000) {
112 return ((freq-2412)/5) + 1;
113 } else {
114 u16_t ii;
115 u16_t num_chan = sizeof(channel_frequency_11A)/sizeof(u32_t);
116
117 for (ii = 1; ii < num_chan; ii += 2) {
118 if (channel_frequency_11A[ii] == freq)
119 return channel_frequency_11A[ii-1];
120 }
121 }
122
123 return 0;
4bd43f50
LR
124}
125
126int usbdrv_chan2freq(int chan)
127{
aef911a5
DZ
128 int freq;
129
130 /* If channel number is out of range */
131 if (chan > 165 || chan <= 0)
132 return -1;
133
134 /* 2.4G band */
135 if (chan >= 1 && chan <= 13) {
136 freq = (2412 + (chan - 1) * 5);
137 return freq;
138 } else if (chan >= 36 && chan <= 165) {
139 u16_t ii;
140 u16_t num_chan = sizeof(channel_frequency_11A)/sizeof(u32_t);
141
142 for (ii = 0; ii < num_chan; ii += 2) {
143 if (channel_frequency_11A[ii] == chan)
144 return channel_frequency_11A[ii+1];
145 }
146
147 /* Can't find desired frequency */
148 if (ii == num_chan)
149 return -1;
150 }
151
152 /* Can't find deisred frequency */
153 return -1;
4bd43f50
LR
154}
155
156int usbdrv_ioctl_setessid(struct net_device *dev, struct iw_point *erq)
157{
aef911a5
DZ
158 #ifdef ZM_HOSTAPD_SUPPORT
159 /* struct usbdrv_private *macp = dev->ml_priv; */
160 char essidbuf[IW_ESSID_MAX_SIZE+1];
161 int i;
4bd43f50 162
aef911a5
DZ
163 if (!netif_running(dev))
164 return -EINVAL;
4bd43f50 165
aef911a5 166 memset(essidbuf, 0, sizeof(essidbuf));
4bd43f50 167
aef911a5 168 printk(KERN_ERR "usbdrv_ioctl_setessid\n");
4bd43f50 169
aef911a5
DZ
170 /* printk("ssidlen=%d\n", erq->length); //for any, it is 1. */
171 if (erq->flags) {
172 if (erq->length > (IW_ESSID_MAX_SIZE+1))
173 return -E2BIG;
4bd43f50 174
aef911a5
DZ
175 if (copy_from_user(essidbuf, erq->pointer, erq->length))
176 return -EFAULT;
177 }
4bd43f50 178
aef911a5
DZ
179 /* zd_DisasocAll(2); */
180 /* wait_ms(100); */
4bd43f50 181
aef911a5 182 printk(KERN_ERR "essidbuf: ");
4bd43f50 183
aef911a5
DZ
184 for (i = 0; i < erq->length; i++)
185 printk(KERN_ERR "%02x ", essidbuf[i]);
4bd43f50 186
aef911a5 187 printk(KERN_ERR "\n");
4bd43f50 188
aef911a5
DZ
189 essidbuf[erq->length] = '\0';
190 /* memcpy(macp->wd.ws.ssid, essidbuf, erq->length); */
191 /* macp->wd.ws.ssidLen = strlen(essidbuf)+2; */
192 /* macp->wd.ws.ssid[1] = strlen(essidbuf); Update ssid length */
4bd43f50 193
aef911a5
DZ
194 zfiWlanSetSSID(dev, essidbuf, erq->length);
195 #if 0
196 printk(KERN_ERR "macp->wd.ws.ssid: ");
4bd43f50 197
aef911a5
DZ
198 for (i = 0; i < macp->wd.ws.ssidLen; i++)
199 printk(KERN_ERR "%02x ", macp->wd.ws.ssid[i]);
4bd43f50 200
aef911a5
DZ
201 printk(KERN_ERR "\n");
202 #endif
4bd43f50 203
aef911a5
DZ
204 zfiWlanDisable(dev, 0);
205 zfiWlanEnable(dev);
4bd43f50 206
aef911a5
DZ
207 #endif
208
209 return 0;
4bd43f50
LR
210}
211
212int usbdrv_ioctl_getessid(struct net_device *dev, struct iw_point *erq)
213{
aef911a5
DZ
214 /* struct usbdrv_private *macp = dev->ml_priv; */
215 u8_t essidbuf[IW_ESSID_MAX_SIZE+1];
216 u8_t len;
217 u8_t i;
4bd43f50
LR
218
219
aef911a5
DZ
220 /* len = macp->wd.ws.ssidLen; */
221 /* memcpy(essidbuf, macp->wd.ws.ssid, macp->wd.ws.ssidLen); */
222 zfiWlanQuerySSID(dev, essidbuf, &len);
4bd43f50 223
aef911a5 224 essidbuf[len] = 0;
4bd43f50 225
aef911a5 226 printk(KERN_ERR "ESSID: ");
4bd43f50 227
aef911a5
DZ
228 for (i = 0; i < len; i++)
229 printk(KERN_ERR "%c", essidbuf[i]);
4bd43f50 230
aef911a5 231 printk(KERN_ERR "\n");
4bd43f50 232
aef911a5
DZ
233 erq->flags = 1;
234 erq->length = strlen(essidbuf) + 1;
4bd43f50 235
aef911a5
DZ
236 if (erq->pointer) {
237 if (copy_to_user(erq->pointer, essidbuf, erq->length))
238 return -EFAULT;
239 }
4bd43f50 240
aef911a5 241 return 0;
4bd43f50
LR
242}
243
4bd43f50
LR
244int usbdrv_ioctl_setrts(struct net_device *dev, struct iw_param *rrq)
245{
aef911a5 246 return 0;
4bd43f50
LR
247}
248
4bd43f50
LR
249/*
250 * Encode a WPA or RSN information element as a custom
251 * element using the hostap format.
252 */
aef911a5
DZ
253u32 encode_ie(void *buf, u32 bufsize, const u8 *ie, u32 ielen,
254 const u8 *leader, u32 leader_len)
4bd43f50 255{
aef911a5
DZ
256 u8 *p;
257 u32 i;
258
259 if (bufsize < leader_len)
260 return 0;
261 p = buf;
262 memcpy(p, leader, leader_len);
263 bufsize -= leader_len;
264 p += leader_len;
265 for (i = 0; i < ielen && bufsize > 2; i++)
266 p += sprintf(p, "%02x", ie[i]);
267 return (i == ielen ? p - (u8 *)buf:0);
4bd43f50 268}
4bd43f50 269
4bd43f50
LR
270/*
271 * Translate scan data returned from the card to a card independent
272 * format that the Wireless Tools will understand
273 */
274char *usbdrv_translate_scan(struct net_device *dev,
275 struct iw_request_info *info, char *current_ev,
aef911a5 276 char *end_buf, struct zsBssInfo *list)
4bd43f50 277{
aef911a5
DZ
278 struct iw_event iwe; /* Temporary buffer */
279 u16_t capabilities;
280 char *current_val; /* For rates */
281 char *last_ev;
282 int i;
92e6765f 283 char buf[64*2 + 30];
aef911a5
DZ
284
285 last_ev = current_ev;
286
287 /* First entry *MUST* be the AP MAC address */
288 iwe.cmd = SIOCGIWAP;
289 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
290 memcpy(iwe.u.ap_addr.sa_data, list->bssid, ETH_ALEN);
291 current_ev = iwe_stream_add_event(info, current_ev,
292 end_buf, &iwe, IW_EV_ADDR_LEN);
293
294 /* Ran out of buffer */
295 if (last_ev == current_ev)
296 return end_buf;
297
298 last_ev = current_ev;
299
300 /* Other entries will be displayed in the order we give them */
301
302 /* Add the ESSID */
303 iwe.u.data.length = list->ssid[1];
304 if (iwe.u.data.length > 32)
305 iwe.u.data.length = 32;
306 iwe.cmd = SIOCGIWESSID;
307 iwe.u.data.flags = 1;
308 current_ev = iwe_stream_add_point(info, current_ev,
309 end_buf, &iwe, &list->ssid[2]);
310
311 /* Ran out of buffer */
312 if (last_ev == current_ev)
313 return end_buf;
314
315 last_ev = current_ev;
316
317 /* Add mode */
318 iwe.cmd = SIOCGIWMODE;
319 capabilities = (list->capability[1] << 8) + list->capability[0];
320 if (capabilities & (0x01 | 0x02)) {
321 if (capabilities & 0x01)
322 iwe.u.mode = IW_MODE_MASTER;
323 else
324 iwe.u.mode = IW_MODE_ADHOC;
325 current_ev = iwe_stream_add_event(info, current_ev,
326 end_buf, &iwe, IW_EV_UINT_LEN);
327 }
4bd43f50 328
aef911a5
DZ
329 /* Ran out of buffer */
330 if (last_ev == current_ev)
331 return end_buf;
332
333 last_ev = current_ev;
334
335 /* Add frequency */
336 iwe.cmd = SIOCGIWFREQ;
337 iwe.u.freq.m = list->channel;
338 /* Channel frequency in KHz */
339 if (iwe.u.freq.m > 14) {
340 if ((184 <= iwe.u.freq.m) && (iwe.u.freq.m <= 196))
341 iwe.u.freq.m = 4000 + iwe.u.freq.m * 5;
342 else
343 iwe.u.freq.m = 5000 + iwe.u.freq.m * 5;
344 } else {
345 if (iwe.u.freq.m == 14)
346 iwe.u.freq.m = 2484;
347 else
348 iwe.u.freq.m = 2412 + (iwe.u.freq.m - 1) * 5;
349 }
350 iwe.u.freq.e = 6;
351 current_ev = iwe_stream_add_event(info, current_ev,
352 end_buf, &iwe, IW_EV_FREQ_LEN);
353
354 /* Ran out of buffer */
355 if (last_ev == current_ev)
356 return end_buf;
357
358 last_ev = current_ev;
359
360 /* Add quality statistics */
361 iwe.cmd = IWEVQUAL;
aef911a5
DZ
362 iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED
363 | IW_QUAL_NOISE_UPDATED;
aef911a5
DZ
364 iwe.u.qual.level = list->signalStrength;
365 iwe.u.qual.noise = 0;
366 iwe.u.qual.qual = list->signalQuality;
367 current_ev = iwe_stream_add_event(info, current_ev,
368 end_buf, &iwe, IW_EV_QUAL_LEN);
369
370 /* Ran out of buffer */
371 if (last_ev == current_ev)
372 return end_buf;
373
374 last_ev = current_ev;
375
376 /* Add encryption capability */
377
378 iwe.cmd = SIOCGIWENCODE;
379 if (capabilities & 0x10)
380 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
381 else
382 iwe.u.data.flags = IW_ENCODE_DISABLED;
383
384 iwe.u.data.length = 0;
385 current_ev = iwe_stream_add_point(info, current_ev,
386 end_buf, &iwe, list->ssid);
387
388 /* Ran out of buffer */
389 if (last_ev == current_ev)
390 return end_buf;
391
392 last_ev = current_ev;
393
394 /* Rate : stuffing multiple values in a single event require a bit
395 * more of magic
396 */
397 current_val = current_ev + IW_EV_LCP_LEN;
398
399 iwe.cmd = SIOCGIWRATE;
400 /* Those two flags are ignored... */
401 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
402
403 for (i = 0 ; i < list->supportedRates[1] ; i++) {
404 /* Bit rate given in 500 kb/s units (+ 0x80) */
405 iwe.u.bitrate.value = ((list->supportedRates[i+2] & 0x7f)
406 * 500000);
407 /* Add new value to event */
408 current_val = iwe_stream_add_value(info, current_ev,
409 current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
410
411 /* Ran out of buffer */
412 if (last_ev == current_val)
413 return end_buf;
414
415 last_ev = current_val;
416 }
417
418 for (i = 0 ; i < list->extSupportedRates[1] ; i++) {
419 /* Bit rate given in 500 kb/s units (+ 0x80) */
420 iwe.u.bitrate.value = ((list->extSupportedRates[i+2] & 0x7f)
421 * 500000);
422 /* Add new value to event */
423 current_val = iwe_stream_add_value(info, current_ev,
424 current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
425
426 /* Ran out of buffer */
427 if (last_ev == current_val)
428 return end_buf;
429
430 last_ev = current_ev;
431 }
432
433 /* Check if we added any event */
434 if ((current_val - current_ev) > IW_EV_LCP_LEN)
435 current_ev = current_val;
aef911a5
DZ
436 #define IEEE80211_ELEMID_RSN 0x30
437 memset(&iwe, 0, sizeof(iwe));
438 iwe.cmd = IWEVCUSTOM;
439 snprintf(buf, sizeof(buf), "bcn_int=%d", (list->beaconInterval[1] << 8)
440 + list->beaconInterval[0]);
441 iwe.u.data.length = strlen(buf);
442 current_ev = iwe_stream_add_point(info, current_ev,
443 end_buf, &iwe, buf);
444
445 /* Ran out of buffer */
446 if (last_ev == current_ev)
447 return end_buf;
448
449 last_ev = current_ev;
450
451 if (list->wpaIe[1] != 0) {
452 static const char rsn_leader[] = "rsn_ie=";
453 static const char wpa_leader[] = "wpa_ie=";
454
455 memset(&iwe, 0, sizeof(iwe));
456 iwe.cmd = IWEVCUSTOM;
457 if (list->wpaIe[0] == IEEE80211_ELEMID_RSN)
458 iwe.u.data.length = encode_ie(buf, sizeof(buf),
459 list->wpaIe, list->wpaIe[1]+2,
460 rsn_leader, sizeof(rsn_leader)-1);
461 else
462 iwe.u.data.length = encode_ie(buf, sizeof(buf),
463 list->wpaIe, list->wpaIe[1]+2,
464 wpa_leader, sizeof(wpa_leader)-1);
465
466 if (iwe.u.data.length != 0)
467 current_ev = iwe_stream_add_point(info, current_ev,
468 end_buf, &iwe, buf);
469
470 /* Ran out of buffer */
471 if (last_ev == current_ev)
472 return end_buf;
473
474 last_ev = current_ev;
475 }
476
477 if (list->rsnIe[1] != 0) {
478 static const char rsn_leader[] = "rsn_ie=";
479 memset(&iwe, 0, sizeof(iwe));
480 iwe.cmd = IWEVCUSTOM;
481
482 if (list->rsnIe[0] == IEEE80211_ELEMID_RSN) {
483 iwe.u.data.length = encode_ie(buf, sizeof(buf),
484 list->rsnIe, list->rsnIe[1]+2,
485 rsn_leader, sizeof(rsn_leader)-1);
486 if (iwe.u.data.length != 0)
487 current_ev = iwe_stream_add_point(info,
488 current_ev, end_buf, &iwe, buf);
489
490 /* Ran out of buffer */
491 if (last_ev == current_ev)
492 return end_buf;
493
494 last_ev = current_ev;
495 }
496 }
aef911a5
DZ
497 /* The other data in the scan result are not really
498 * interesting, so for now drop it
499 */
500 return current_ev;
4bd43f50
LR
501}
502
503int usbdrvwext_giwname(struct net_device *dev,
aef911a5
DZ
504 struct iw_request_info *info,
505 union iwreq_data *wrq, char *extra)
4bd43f50 506{
aef911a5 507 /* struct usbdrv_private *macp = dev->ml_priv; */
4bd43f50 508
cc7e7d38 509 strcpy(wrq->name, "IEEE 802.11abgn");
4bd43f50 510
aef911a5 511 return 0;
4bd43f50
LR
512}
513
514int usbdrvwext_siwfreq(struct net_device *dev,
aef911a5
DZ
515 struct iw_request_info *info,
516 struct iw_freq *freq, char *extra)
4bd43f50 517{
aef911a5
DZ
518 u32_t FreqKHz;
519 struct usbdrv_private *macp = dev->ml_priv;
520
521 if (!netif_running(dev))
522 return -EINVAL;
523
524 if (freq->e > 1)
525 return -EINVAL;
526
527 if (freq->e == 1) {
528 FreqKHz = (freq->m / 100000);
529
530 if (FreqKHz > 4000000) {
531 if (FreqKHz > 5825000)
532 FreqKHz = 5825000;
533 else if (FreqKHz < 4920000)
534 FreqKHz = 4920000;
535 else if (FreqKHz < 5000000)
536 FreqKHz = (((FreqKHz - 4000000) / 5000) * 5000)
537 + 4000000;
538 else
539 FreqKHz = (((FreqKHz - 5000000) / 5000) * 5000)
540 + 5000000;
541 } else {
542 if (FreqKHz > 2484000)
543 FreqKHz = 2484000;
544 else if (FreqKHz < 2412000)
545 FreqKHz = 2412000;
546 else
547 FreqKHz = (((FreqKHz - 2412000) / 5000) * 5000)
548 + 2412000;
549 }
550 } else {
551 FreqKHz = usbdrv_chan2freq(freq->m);
552
553 if (FreqKHz != -1)
554 FreqKHz *= 1000;
555 else
556 FreqKHz = 2412000;
557 }
558
559 /* printk("freq->m: %d, freq->e: %d\n", freq->m, freq->e); */
560 /* printk("FreqKHz: %d\n", FreqKHz); */
561
562 if (macp->DeviceOpened == 1) {
563 zfiWlanSetFrequency(dev, FreqKHz, 0); /* Immediate */
564 /* u8_t wpaieLen,wpaie[50]; */
565 /* zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen); */
566 zfiWlanDisable(dev, 0);
567 zfiWlanEnable(dev);
568 /* if (wpaieLen > 2) */
569 /* zfiWlanSetWpaIe(dev, wpaie, wpaieLen); */
570 }
571
572 return 0;
4bd43f50
LR
573}
574
575int usbdrvwext_giwfreq(struct net_device *dev,
aef911a5
DZ
576 struct iw_request_info *info,
577 struct iw_freq *freq, char *extra)
4bd43f50 578{
aef911a5 579 struct usbdrv_private *macp = dev->ml_priv;
4bd43f50 580
aef911a5
DZ
581 if (macp->DeviceOpened != 1)
582 return 0;
4bd43f50 583
aef911a5
DZ
584 freq->m = zfiWlanQueryFrequency(dev);
585 freq->e = 3;
4bd43f50 586
aef911a5 587 return 0;
4bd43f50
LR
588}
589
590int usbdrvwext_siwmode(struct net_device *dev,
aef911a5
DZ
591 struct iw_request_info *info,
592 union iwreq_data *wrq, char *extra)
4bd43f50 593{
aef911a5
DZ
594 struct usbdrv_private *macp = dev->ml_priv;
595 u8_t WlanMode;
596
597 if (!netif_running(dev))
598 return -EINVAL;
599
600 if (macp->DeviceOpened != 1)
601 return 0;
602
603 switch (wrq->mode) {
604 case IW_MODE_MASTER:
605 WlanMode = ZM_MODE_AP;
606 break;
607 case IW_MODE_INFRA:
608 WlanMode = ZM_MODE_INFRASTRUCTURE;
609 break;
610 case IW_MODE_ADHOC:
611 WlanMode = ZM_MODE_IBSS;
612 break;
613 default:
614 WlanMode = ZM_MODE_IBSS;
615 break;
616 }
617
618 zfiWlanSetWlanMode(dev, WlanMode);
619 zfiWlanDisable(dev, 1);
620 zfiWlanEnable(dev);
621
622 return 0;
4bd43f50
LR
623}
624
625int usbdrvwext_giwmode(struct net_device *dev,
aef911a5
DZ
626 struct iw_request_info *info,
627 __u32 *mode, char *extra)
4bd43f50 628{
aef911a5
DZ
629 unsigned long irqFlag;
630 struct usbdrv_private *macp = dev->ml_priv;
631
632 if (!netif_running(dev))
633 return -EINVAL;
634
635 if (macp->DeviceOpened != 1)
636 return 0;
637
638 spin_lock_irqsave(&macp->cs_lock, irqFlag);
639
640 switch (zfiWlanQueryWlanMode(dev)) {
641 case ZM_MODE_AP:
642 *mode = IW_MODE_MASTER;
643 break;
644 case ZM_MODE_INFRASTRUCTURE:
645 *mode = IW_MODE_INFRA;
646 break;
647 case ZM_MODE_IBSS:
648 *mode = IW_MODE_ADHOC;
649 break;
650 default:
651 *mode = IW_MODE_ADHOC;
652 break;
653 }
654
655 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
656
657 return 0;
4bd43f50
LR
658}
659
660int usbdrvwext_siwsens(struct net_device *dev,
661 struct iw_request_info *info,
662 struct iw_param *sens, char *extra)
663{
664 return 0;
665}
666
667int usbdrvwext_giwsens(struct net_device *dev,
668 struct iw_request_info *info,
669 struct iw_param *sens, char *extra)
670{
671 sens->value = 0;
672 sens->fixed = 1;
673
674 return 0;
675}
676
677int usbdrvwext_giwrange(struct net_device *dev,
aef911a5
DZ
678 struct iw_request_info *info,
679 struct iw_point *data, char *extra)
4bd43f50 680{
aef911a5
DZ
681 struct iw_range *range = (struct iw_range *) extra;
682 int i, val;
683 /* int num_band_a; */
684 u16_t channels[60];
685 u16_t channel_num;
686
687 if (!netif_running(dev))
688 return -EINVAL;
689
aef911a5
DZ
690 range->txpower_capa = IW_TXPOW_DBM;
691 /* XXX what about min/max_pmp, min/max_pmt, etc. */
aef911a5 692
aef911a5
DZ
693 range->we_version_compiled = WIRELESS_EXT;
694 range->we_version_source = 13;
695
696 range->retry_capa = IW_RETRY_LIMIT;
697 range->retry_flags = IW_RETRY_LIMIT;
698 range->min_retry = 0;
699 range->max_retry = 255;
aef911a5
DZ
700
701 channel_num = zfiWlanQueryAllowChannels(dev, channels);
702
703 /* Gurantee reported channel numbers is less
704 * or equal to IW_MAX_FREQUENCIES
705 */
706 if (channel_num > IW_MAX_FREQUENCIES)
707 channel_num = IW_MAX_FREQUENCIES;
708
709 val = 0;
710
711 for (i = 0; i < channel_num; i++) {
712 range->freq[val].i = usbdrv_freq2chan(channels[i]);
713 range->freq[val].m = channels[i];
714 range->freq[val].e = 6;
715 val++;
716 }
4bd43f50 717
aef911a5
DZ
718 range->num_channels = channel_num;
719 range->num_frequency = channel_num;
4bd43f50 720
aef911a5
DZ
721 #if 0
722 range->num_channels = 14; /* Only 2.4G */
4bd43f50 723
aef911a5
DZ
724 /* XXX need to filter against the regulatory domain &| active set */
725 val = 0;
726 /* B,G Bands */
727 for (i = 1; i <= 14; i++) {
728 range->freq[val].i = i;
729 if (i == 14)
730 range->freq[val].m = 2484000;
731 else
732 range->freq[val].m = (2412+(i-1)*5)*1000;
733 range->freq[val].e = 3;
734 val++;
735 }
4bd43f50 736
aef911a5
DZ
737 num_band_a = (IW_MAX_FREQUENCIES - val);
738 /* A Bands */
739 for (i = 0; i < num_band_a; i++) {
740 range->freq[val].i = channel_frequency_11A[2 * i];
741 range->freq[val].m = channel_frequency_11A[2 * i + 1] * 1000;
742 range->freq[val].e = 3;
743 val++;
744 }
745 /* MIMO Rate Not Defined Now
746 * For 802.11a, there are too more frequency.
747 * We can't return them all.
748 */
749 range->num_frequency = val;
750 #endif
751
752 /* Max of /proc/net/wireless */
753 range->max_qual.qual = 100; /* ?? 92; */
754 range->max_qual.level = 154; /* ?? */
755 range->max_qual.noise = 154; /* ?? */
756 range->sensitivity = 3; /* ?? */
757
758 /* XXX these need to be nsd-specific! */
759 range->min_rts = 0;
760 range->max_rts = 2347;
761 range->min_frag = 256;
762 range->max_frag = 2346;
763 range->max_encoding_tokens = 4 /* NUM_WEPKEYS ?? */;
764 range->num_encoding_sizes = 2; /* ?? */
765
766 range->encoding_size[0] = 5; /* ?? WEP Key Encoding Size */
767 range->encoding_size[1] = 13; /* ?? */
768
769 /* XXX what about num_bitrates/throughput? */
770 range->num_bitrates = 0; /* ?? */
771
772 /* estimated max throughput
773 * XXX need to cap it if we're running at ~2Mbps..
774 */
775
776 range->throughput = 300000000;
4bd43f50 777
aef911a5 778 return 0;
4bd43f50
LR
779}
780
781int usbdrvwext_siwap(struct net_device *dev, struct iw_request_info *info,
aef911a5 782 struct sockaddr *MacAddr, char *extra)
4bd43f50 783{
aef911a5
DZ
784 struct usbdrv_private *macp = dev->ml_priv;
785
786 if (!netif_running(dev))
787 return -EINVAL;
788
789 if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) {
790 /* AP Mode */
791 zfiWlanSetMacAddress(dev, (u16_t *)&MacAddr->sa_data[0]);
792 } else {
793 /* STA Mode */
794 zfiWlanSetBssid(dev, &MacAddr->sa_data[0]);
795 }
796
797 if (macp->DeviceOpened == 1) {
798 /* u8_t wpaieLen,wpaie[80]; */
799 /* zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen); */
800 zfiWlanDisable(dev, 0);
801 zfiWlanEnable(dev);
802 /* if (wpaieLen > 2) */
803 /* zfiWlanSetWpaIe(dev, wpaie, wpaieLen); */
804 }
805
806 return 0;
4bd43f50
LR
807}
808
809int usbdrvwext_giwap(struct net_device *dev,
aef911a5
DZ
810 struct iw_request_info *info,
811 struct sockaddr *MacAddr, char *extra)
4bd43f50 812{
aef911a5
DZ
813 struct usbdrv_private *macp = dev->ml_priv;
814
815 if (macp->DeviceOpened != 1)
816 return 0;
817
818 if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) {
819 /* AP Mode */
820 zfiWlanQueryMacAddress(dev, &MacAddr->sa_data[0]);
821 } else {
822 /* STA Mode */
823 if (macp->adapterState == ZM_STATUS_MEDIA_CONNECT) {
824 zfiWlanQueryBssid(dev, &MacAddr->sa_data[0]);
825 } else {
826 u8_t zero_addr[6] = { 0x00, 0x00, 0x00, 0x00,
827 0x00, 0x00 };
828 memcpy(&MacAddr->sa_data[0], zero_addr,
829 sizeof(zero_addr));
830 }
831 }
832
833 return 0;
4bd43f50
LR
834}
835
836int usbdrvwext_iwaplist(struct net_device *dev,
837 struct iw_request_info *info,
838 struct iw_point *data, char *extra)
839{
aef911a5
DZ
840 /* Don't know how to do yet--CWYang(+) */
841 return 0;
4bd43f50
LR
842
843}
844
845int usbdrvwext_siwscan(struct net_device *dev, struct iw_request_info *info,
aef911a5 846 struct iw_point *data, char *extra)
4bd43f50 847{
aef911a5 848 struct usbdrv_private *macp = dev->ml_priv;
4bd43f50 849
aef911a5
DZ
850 if (macp->DeviceOpened != 1)
851 return 0;
4bd43f50 852
aef911a5 853 printk(KERN_WARNING "CWY - usbdrvwext_siwscan\n");
4bd43f50 854
aef911a5 855 zfiWlanScan(dev);
4bd43f50 856
aef911a5 857 return 0;
4bd43f50
LR
858}
859
860int usbdrvwext_giwscan(struct net_device *dev,
aef911a5
DZ
861 struct iw_request_info *info,
862 struct iw_point *data, char *extra)
4bd43f50 863{
aef911a5
DZ
864 struct usbdrv_private *macp = dev->ml_priv;
865 /* struct zsWlanDev* wd = (struct zsWlanDev*) zmw_wlan_dev(dev); */
866 char *current_ev = extra;
867 char *end_buf;
868 int i;
f4d52b07 869 struct zsBssListV1 *pBssList;
aef911a5
DZ
870 /* BssList = wd->sta.pBssList; */
871 /* zmw_get_wlan_dev(dev); */
872
873 if (macp->DeviceOpened != 1)
874 return 0;
875
e501b36b 876 /* struct zsBssList BssList; */
f4d52b07
PH
877 pBssList = kmalloc(sizeof(struct zsBssListV1), GFP_KERNEL);
878 if (pBssList == NULL)
879 return -ENOMEM;
880
aef911a5
DZ
881 if (data->length == 0)
882 end_buf = extra + IW_SCAN_MAX_DATA;
883 else
884 end_buf = extra + data->length;
885
886 printk(KERN_WARNING "giwscan - Report Scan Results\n");
887 /* printk("giwscan - BssList Sreucture Len : %d\n", sizeof(BssList));
888 * printk("giwscan - BssList Count : %d\n",
889 * wd->sta.pBssList->bssCount);
890 * printk("giwscan - UpdateBssList Count : %d\n",
891 * wd->sta.pUpdateBssList->bssCount);
892 */
893 zfiWlanQueryBssListV1(dev, pBssList);
894 /* zfiWlanQueryBssList(dev, &BssList); */
895
896 /* Read and parse all entries */
897 printk(KERN_WARNING "giwscan - pBssList->bssCount : %d\n",
898 pBssList->bssCount);
899 /* printk("giwscan - BssList.bssCount : %d\n", BssList.bssCount); */
900
901 for (i = 0; i < pBssList->bssCount; i++) {
902 /* Translate to WE format this entry
903 * current_ev = usbdrv_translate_scan(dev, info, current_ev,
904 * extra + IW_SCAN_MAX_DATA, &pBssList->bssInfo[i]);
905 */
906 current_ev = usbdrv_translate_scan(dev, info, current_ev,
907 end_buf, &pBssList->bssInfo[i]);
908
aef911a5
DZ
909 if (current_ev == end_buf) {
910 kfree(pBssList);
911 data->length = current_ev - extra;
912 return -E2BIG;
913 }
aef911a5 914 }
4bd43f50 915
aef911a5
DZ
916 /* Length of data */
917 data->length = (current_ev - extra);
918 data->flags = 0; /* todo */
4bd43f50 919
aef911a5 920 kfree(pBssList);
4bd43f50 921
aef911a5 922 return 0;
4bd43f50
LR
923}
924
925int usbdrvwext_siwessid(struct net_device *dev,
aef911a5
DZ
926 struct iw_request_info *info,
927 struct iw_point *essid, char *extra)
4bd43f50 928{
aef911a5
DZ
929 char EssidBuf[IW_ESSID_MAX_SIZE + 1];
930 struct usbdrv_private *macp = dev->ml_priv;
931
932 if (!netif_running(dev))
933 return -EINVAL;
934
935 if (essid->flags == 1) {
1c7e4a7c 936 if (essid->length > IW_ESSID_MAX_SIZE)
aef911a5
DZ
937 return -E2BIG;
938
939 if (copy_from_user(&EssidBuf, essid->pointer, essid->length))
940 return -EFAULT;
941
942 EssidBuf[essid->length] = '\0';
943 /* printk("siwessid - Set Essid : %s\n",EssidBuf); */
944 /* printk("siwessid - Essid Len : %d\n",essid->length); */
945 /* printk("siwessid - Essid Flag : %x\n",essid->flags); */
946 if (macp->DeviceOpened == 1) {
947 zfiWlanSetSSID(dev, EssidBuf, strlen(EssidBuf));
948 zfiWlanSetFrequency(dev, zfiWlanQueryFrequency(dev),
949 FALSE);
950 zfiWlanSetEncryMode(dev, zfiWlanQueryEncryMode(dev));
951 /* u8_t wpaieLen,wpaie[50]; */
952 /* zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen); */
953 zfiWlanDisable(dev, 0);
954 zfiWlanEnable(dev);
955 /* if (wpaieLen > 2) */
956 /* zfiWlanSetWpaIe(dev, wpaie, wpaieLen); */
957 }
958 }
959
960 return 0;
4bd43f50
LR
961}
962
963int usbdrvwext_giwessid(struct net_device *dev,
aef911a5
DZ
964 struct iw_request_info *info,
965 struct iw_point *essid, char *extra)
4bd43f50 966{
aef911a5
DZ
967 struct usbdrv_private *macp = dev->ml_priv;
968 u8_t EssidLen;
969 char EssidBuf[IW_ESSID_MAX_SIZE + 1];
970 int ssid_len;
4bd43f50 971
aef911a5
DZ
972 if (!netif_running(dev))
973 return -EINVAL;
4bd43f50 974
aef911a5
DZ
975 if (macp->DeviceOpened != 1)
976 return 0;
4bd43f50 977
aef911a5 978 zfiWlanQuerySSID(dev, &EssidBuf[0], &EssidLen);
4bd43f50 979
aef911a5
DZ
980 /* Convert type from unsigned char to char */
981 ssid_len = (int)EssidLen;
4bd43f50 982
aef911a5
DZ
983 /* Make sure the essid length is not greater than IW_ESSID_MAX_SIZE */
984 if (ssid_len > IW_ESSID_MAX_SIZE)
985 ssid_len = IW_ESSID_MAX_SIZE;
4bd43f50 986
aef911a5 987 EssidBuf[ssid_len] = '\0';
4bd43f50 988
aef911a5
DZ
989 essid->flags = 1;
990 essid->length = strlen(EssidBuf);
4bd43f50 991
aef911a5
DZ
992 memcpy(extra, EssidBuf, essid->length);
993 /* wireless.c in Kernel would handle copy_to_user -- line 679 */
994 /* if (essid->pointer) {
995 * if (copy_to_user(essid->pointer, EssidBuf, essid->length)) {
996 * printk("giwessid - copy_to_user Fail\n");
997 * return -EFAULT;
998 * }
999 * }
1000 */
4bd43f50 1001
aef911a5 1002 return 0;
4bd43f50
LR
1003}
1004
1005int usbdrvwext_siwnickn(struct net_device *dev,
1006 struct iw_request_info *info,
1007 struct iw_point *data, char *nickname)
1008{
aef911a5 1009 /* Exist but junk--CWYang(+) */
4bd43f50
LR
1010 return 0;
1011}
1012
1013int usbdrvwext_giwnickn(struct net_device *dev,
1014 struct iw_request_info *info,
1015 struct iw_point *data, char *nickname)
1016{
aef911a5
DZ
1017 struct usbdrv_private *macp = dev->ml_priv;
1018 u8_t EssidLen;
1019 char EssidBuf[IW_ESSID_MAX_SIZE + 1];
4bd43f50 1020
aef911a5
DZ
1021 if (macp->DeviceOpened != 1)
1022 return 0;
4bd43f50 1023
aef911a5
DZ
1024 zfiWlanQuerySSID(dev, &EssidBuf[0], &EssidLen);
1025 EssidBuf[EssidLen] = 0;
4bd43f50 1026
aef911a5
DZ
1027 data->flags = 1;
1028 data->length = strlen(EssidBuf);
4bd43f50 1029
aef911a5 1030 memcpy(nickname, EssidBuf, data->length);
4bd43f50
LR
1031
1032 return 0;
1033}
1034
1035int usbdrvwext_siwrate(struct net_device *dev,
aef911a5
DZ
1036 struct iw_request_info *info,
1037 struct iw_param *frq, char *extra)
4bd43f50 1038{
da3e8908 1039 struct usbdrv_private *macp = dev->ml_priv;
aef911a5
DZ
1040 /* Array to Define Rate Number that Send to Driver */
1041 u16_t zcIndextoRateBG[16] = {1000, 2000, 5500, 11000, 0, 0, 0, 0,
1042 48000, 24000, 12000, 6000, 54000, 36000, 18000, 9000};
1043 u16_t zcRateToMCS[] = {0xff, 0, 1, 2, 3, 0xb, 0xf, 0xa, 0xe, 0x9, 0xd,
1044 0x8, 0xc};
1045 u8_t i, RateIndex = 4;
1046 u16_t RateKbps;
1047
1048 /* printk("frq->disabled : 0x%x\n",frq->disabled); */
1049 /* printk("frq->value : 0x%x\n",frq->value); */
1050
1051 RateKbps = frq->value / 1000;
1052 /* printk("RateKbps : %d\n", RateKbps); */
1053 for (i = 0; i < 16; i++) {
1054 if (RateKbps == zcIndextoRateBG[i])
1055 RateIndex = i;
1056 }
1057
1058 if (zcIndextoRateBG[RateIndex] == 0)
1059 RateIndex = 0xff;
1060 /* printk("RateIndex : %x\n", RateIndex); */
1061 for (i = 0; i < 13; i++)
1062 if (RateIndex == zcRateToMCS[i])
1063 break;
1064 /* printk("Index : %x\n", i); */
1065 if (RateKbps == 65000) {
1066 RateIndex = 20;
1067 printk(KERN_WARNING "RateIndex : %d\n", RateIndex);
1068 }
1069
1070 if (macp->DeviceOpened == 1) {
1071 zfiWlanSetTxRate(dev, i);
1072 /* zfiWlanDisable(dev); */
1073 /* zfiWlanEnable(dev); */
1074 }
1075
1076 return 0;
4bd43f50
LR
1077}
1078
1079int usbdrvwext_giwrate(struct net_device *dev,
aef911a5
DZ
1080 struct iw_request_info *info,
1081 struct iw_param *frq, char *extra)
4bd43f50 1082{
aef911a5 1083 struct usbdrv_private *macp = dev->ml_priv;
4bd43f50 1084
aef911a5
DZ
1085 if (!netif_running(dev))
1086 return -EINVAL;
4bd43f50 1087
aef911a5
DZ
1088 if (macp->DeviceOpened != 1)
1089 return 0;
4bd43f50 1090
aef911a5
DZ
1091 frq->fixed = 0;
1092 frq->disabled = 0;
1093 frq->value = zfiWlanQueryRxRate(dev) * 1000;
4bd43f50 1094
aef911a5 1095 return 0;
4bd43f50
LR
1096}
1097
1098int usbdrvwext_siwrts(struct net_device *dev,
aef911a5
DZ
1099 struct iw_request_info *info,
1100 struct iw_param *rts, char *extra)
4bd43f50 1101{
aef911a5
DZ
1102 struct usbdrv_private *macp = dev->ml_priv;
1103 int val = rts->value;
4bd43f50 1104
aef911a5
DZ
1105 if (macp->DeviceOpened != 1)
1106 return 0;
4bd43f50 1107
aef911a5
DZ
1108 if (rts->disabled)
1109 val = 2347;
4bd43f50 1110
aef911a5
DZ
1111 if ((val < 0) || (val > 2347))
1112 return -EINVAL;
4bd43f50 1113
aef911a5 1114 zfiWlanSetRtsThreshold(dev, val);
4bd43f50 1115
aef911a5 1116 return 0;
4bd43f50
LR
1117}
1118
1119int usbdrvwext_giwrts(struct net_device *dev,
aef911a5
DZ
1120 struct iw_request_info *info,
1121 struct iw_param *rts, char *extra)
4bd43f50 1122{
aef911a5 1123 struct usbdrv_private *macp = dev->ml_priv;
4bd43f50 1124
aef911a5
DZ
1125 if (!netif_running(dev))
1126 return -EINVAL;
4bd43f50 1127
aef911a5
DZ
1128 if (macp->DeviceOpened != 1)
1129 return 0;
4bd43f50 1130
aef911a5
DZ
1131 rts->value = zfiWlanQueryRtsThreshold(dev);
1132 rts->disabled = (rts->value >= 2347);
1133 rts->fixed = 1;
4bd43f50 1134
aef911a5 1135 return 0;
4bd43f50
LR
1136}
1137
1138int usbdrvwext_siwfrag(struct net_device *dev,
aef911a5
DZ
1139 struct iw_request_info *info,
1140 struct iw_param *frag, char *extra)
4bd43f50 1141{
aef911a5
DZ
1142 struct usbdrv_private *macp = dev->ml_priv;
1143 u16_t fragThreshold;
4bd43f50 1144
aef911a5
DZ
1145 if (macp->DeviceOpened != 1)
1146 return 0;
4bd43f50 1147
aef911a5
DZ
1148 if (frag->disabled)
1149 fragThreshold = 0;
1150 else
1151 fragThreshold = frag->value;
4bd43f50 1152
aef911a5 1153 zfiWlanSetFragThreshold(dev, fragThreshold);
4bd43f50 1154
aef911a5 1155 return 0;
4bd43f50
LR
1156}
1157
1158int usbdrvwext_giwfrag(struct net_device *dev,
aef911a5
DZ
1159 struct iw_request_info *info,
1160 struct iw_param *frag, char *extra)
4bd43f50 1161{
aef911a5
DZ
1162 struct usbdrv_private *macp = dev->ml_priv;
1163 u16 val;
1164 unsigned long irqFlag;
4bd43f50 1165
aef911a5
DZ
1166 if (!netif_running(dev))
1167 return -EINVAL;
4bd43f50 1168
aef911a5
DZ
1169 if (macp->DeviceOpened != 1)
1170 return 0;
4bd43f50 1171
aef911a5 1172 spin_lock_irqsave(&macp->cs_lock, irqFlag);
4bd43f50 1173
aef911a5 1174 val = zfiWlanQueryFragThreshold(dev);
4bd43f50 1175
aef911a5 1176 frag->value = val;
4bd43f50 1177
aef911a5
DZ
1178 frag->disabled = (val >= 2346);
1179 frag->fixed = 1;
4bd43f50 1180
aef911a5 1181 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
4bd43f50 1182
aef911a5 1183 return 0;
4bd43f50
LR
1184}
1185
1186int usbdrvwext_siwtxpow(struct net_device *dev,
1187 struct iw_request_info *info,
1188 struct iw_param *rrq, char *extra)
1189{
aef911a5 1190 /* Not support yet--CWYng(+) */
4bd43f50
LR
1191 return 0;
1192}
1193
1194int usbdrvwext_giwtxpow(struct net_device *dev,
1195 struct iw_request_info *info,
1196 struct iw_param *rrq, char *extra)
1197{
aef911a5 1198 /* Not support yet--CWYng(+) */
4bd43f50
LR
1199 return 0;
1200}
1201
1202int usbdrvwext_siwretry(struct net_device *dev,
1203 struct iw_request_info *info,
1204 struct iw_param *rrq, char *extra)
1205{
aef911a5 1206 /* Do nothing--CWYang(+) */
4bd43f50
LR
1207 return 0;
1208}
1209
1210int usbdrvwext_giwretry(struct net_device *dev,
1211 struct iw_request_info *info,
1212 struct iw_param *rrq, char *extra)
1213{
aef911a5 1214 /* Do nothing--CWYang(+) */
4bd43f50
LR
1215 return 0;
1216}
1217
1218int usbdrvwext_siwencode(struct net_device *dev,
aef911a5
DZ
1219 struct iw_request_info *info,
1220 struct iw_point *erq, char *key)
4bd43f50 1221{
aef911a5
DZ
1222 struct zsKeyInfo keyInfo;
1223 int i;
1224 int WepState = ZM_ENCRYPTION_WEP_DISABLED;
1225 struct usbdrv_private *macp = dev->ml_priv;
1226
1227 if (!netif_running(dev))
1228 return -EINVAL;
1229
1230 if ((erq->flags & IW_ENCODE_DISABLED) == 0) {
1231 keyInfo.key = key;
1232 keyInfo.keyLength = erq->length;
1233 keyInfo.keyIndex = (erq->flags & IW_ENCODE_INDEX) - 1;
1234 if (keyInfo.keyIndex >= 4)
1235 keyInfo.keyIndex = 0;
1236 keyInfo.flag = ZM_KEY_FLAG_DEFAULT_KEY;
1237
1238 zfiWlanSetKey(dev, keyInfo);
1239 WepState = ZM_ENCRYPTION_WEP_ENABLED;
1240 } else {
1241 for (i = 1; i < 4; i++)
1242 zfiWlanRemoveKey(dev, 0, i);
1243 WepState = ZM_ENCRYPTION_WEP_DISABLED;
1244 /* zfiWlanSetEncryMode(dev, ZM_NO_WEP); */
1245 }
1246
1247 if (macp->DeviceOpened == 1) {
1248 zfiWlanSetWepStatus(dev, WepState);
1249 zfiWlanSetFrequency(dev, zfiWlanQueryFrequency(dev), FALSE);
1250 /* zfiWlanSetEncryMode(dev, zfiWlanQueryEncryMode(dev)); */
1251 /* u8_t wpaieLen,wpaie[50]; */
1252 /* zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen); */
1253 zfiWlanDisable(dev, 0);
1254 zfiWlanEnable(dev);
1255 /* if (wpaieLen > 2) */
1256 /* zfiWlanSetWpaIe(dev, wpaie, wpaieLen); */
1257 }
1258
1259 return 0;
4bd43f50
LR
1260}
1261
1262int usbdrvwext_giwencode(struct net_device *dev,
aef911a5
DZ
1263 struct iw_request_info *info,
1264 struct iw_point *erq, char *key)
4bd43f50 1265{
aef911a5
DZ
1266 struct usbdrv_private *macp = dev->ml_priv;
1267 u8_t EncryptionMode;
1268 u8_t keyLen = 0;
1269
1270 if (macp->DeviceOpened != 1)
1271 return 0;
1272
1273 EncryptionMode = zfiWlanQueryEncryMode(dev);
1274
1275 if (EncryptionMode)
1276 erq->flags = IW_ENCODE_ENABLED;
1277 else
1278 erq->flags = IW_ENCODE_DISABLED;
1279
1280 /* We can't return the key, so set the proper flag and return zero */
1281 erq->flags |= IW_ENCODE_NOKEY;
1282 memset(key, 0, 16);
1283
1284 /* Copy the key to the user buffer */
1285 switch (EncryptionMode) {
1286 case ZM_WEP64:
1287 keyLen = 5;
1288 break;
1289 case ZM_WEP128:
1290 keyLen = 13;
1291 break;
1292 case ZM_WEP256:
1293 keyLen = 29;
1294 break;
1295 case ZM_AES:
1296 keyLen = 16;
1297 break;
1298 case ZM_TKIP:
1299 keyLen = 32;
1300 break;
1301 #ifdef ZM_ENABLE_CENC
1302 case ZM_CENC:
1303 /* ZM_ENABLE_CENC */
1304 keyLen = 32;
1305 break;
1306 #endif
1307 case ZM_NO_WEP:
1308 keyLen = 0;
1309 break;
1310 default:
1311 keyLen = 0;
1312 printk(KERN_ERR "Unknown EncryMode\n");
1313 break;
1314 }
1315 erq->length = keyLen;
1316
1317 return 0;
4bd43f50
LR
1318}
1319
1320int usbdrvwext_siwpower(struct net_device *dev,
aef911a5
DZ
1321 struct iw_request_info *info,
1322 struct iw_param *frq, char *extra)
4bd43f50 1323{
aef911a5
DZ
1324 struct usbdrv_private *macp = dev->ml_priv;
1325 u8_t PSMode;
4bd43f50 1326
aef911a5
DZ
1327 if (macp->DeviceOpened != 1)
1328 return 0;
4bd43f50 1329
aef911a5
DZ
1330 if (frq->disabled)
1331 PSMode = ZM_STA_PS_NONE;
1332 else
1333 PSMode = ZM_STA_PS_MAX;
4bd43f50 1334
aef911a5 1335 zfiWlanSetPowerSaveMode(dev, PSMode);
4bd43f50 1336
aef911a5 1337 return 0;
4bd43f50
LR
1338}
1339
1340int usbdrvwext_giwpower(struct net_device *dev,
aef911a5
DZ
1341 struct iw_request_info *info,
1342 struct iw_param *frq, char *extra)
4bd43f50 1343{
aef911a5
DZ
1344 unsigned long irqFlag;
1345 struct usbdrv_private *macp = dev->ml_priv;
4bd43f50 1346
aef911a5
DZ
1347 if (macp->DeviceOpened != 1)
1348 return 0;
4bd43f50 1349
aef911a5 1350 spin_lock_irqsave(&macp->cs_lock, irqFlag);
4bd43f50 1351
aef911a5
DZ
1352 if (zfiWlanQueryPowerSaveMode(dev) == ZM_STA_PS_NONE)
1353 frq->disabled = 1;
1354 else
1355 frq->disabled = 0;
4bd43f50 1356
aef911a5 1357 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
4bd43f50 1358
aef911a5 1359 return 0;
4bd43f50
LR
1360}
1361
aef911a5 1362/*int usbdrvwext_setparam(struct net_device *dev, struct iw_request_info *info,
25b37eca 1363* void *w, char *extra)
aef911a5
DZ
1364*{
1365* struct ieee80211vap *vap = dev->ml_priv;
1366* struct ieee80211com *ic = vap->iv_ic;
1367* struct ieee80211_rsnparms *rsn = &vap->iv_bss->ni_rsn;
1368* int *i = (int *) extra;
1369* int param = i[0]; // parameter id is 1st
1370* int value = i[1]; // NB: most values are TYPE_INT
1371* int retv = 0;
1372* int j, caps;
1373* const struct ieee80211_authenticator *auth;
1374* const struct ieee80211_aclator *acl;
1375*
1376* switch (param) {
1377* case IEEE80211_PARAM_AUTHMODE:
1378* switch (value) {
1379* case IEEE80211_AUTH_WPA: // WPA
1380* case IEEE80211_AUTH_8021X: // 802.1x
1381* case IEEE80211_AUTH_OPEN: // open
1382* case IEEE80211_AUTH_SHARED: // shared-key
1383* case IEEE80211_AUTH_AUTO: // auto
1384* auth = ieee80211_authenticator_get(value);
1385* if (auth == NULL)
1386* return -EINVAL;
1387* break;
1388* default:
1389* return -EINVAL;
1390* }
1391* switch (value) {
1392* case IEEE80211_AUTH_WPA: // WPA w/ 802.1x
1393* vap->iv_flags |= IEEE80211_F_PRIVACY;
1394* value = IEEE80211_AUTH_8021X;
1395* break;
1396* case IEEE80211_AUTH_OPEN: // open
1397* vap->iv_flags &= ~(IEEE80211_F_WPA | IEEE80211_F_PRIVACY);
1398* break;
1399* case IEEE80211_AUTH_SHARED: // shared-key
1400* case IEEE80211_AUTH_AUTO: // auto
1401* case IEEE80211_AUTH_8021X: // 802.1x
1402* vap->iv_flags &= ~IEEE80211_F_WPA;
1403* // both require a key so mark the PRIVACY capability
1404* vap->iv_flags |= IEEE80211_F_PRIVACY;
1405* break;
1406* }
1407* // NB: authenticator attach/detach happens on state change
1408* vap->iv_bss->ni_authmode = value;
1409* // XXX mixed/mode/usage?
1410* vap->iv_auth = auth;
1411* retv = ENETRESET;
1412* break;
1413* case IEEE80211_PARAM_PROTMODE:
1414* if (value > IEEE80211_PROT_RTSCTS)
1415* return -EINVAL;
1416* ic->ic_protmode = value;
1417* // NB: if not operating in 11g this can wait
1418* if (ic->ic_bsschan != IEEE80211_CHAN_ANYC &&
1419* IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan))
1420* retv = ENETRESET;
1421* break;
1422* case IEEE80211_PARAM_MCASTCIPHER:
1423* if ((vap->iv_caps & cipher2cap(value)) == 0 &&
1424* !ieee80211_crypto_available(value))
1425* return -EINVAL;
1426* rsn->rsn_mcastcipher = value;
1427* if (vap->iv_flags & IEEE80211_F_WPA)
1428* retv = ENETRESET;
1429* break;
1430* case IEEE80211_PARAM_MCASTKEYLEN:
1431* if (!(0 < value && value < IEEE80211_KEYBUF_SIZE))
1432* return -EINVAL;
1433* // XXX no way to verify driver capability
1434* rsn->rsn_mcastkeylen = value;
1435* if (vap->iv_flags & IEEE80211_F_WPA)
1436* retv = ENETRESET;
1437* break;
1438* case IEEE80211_PARAM_UCASTCIPHERS:
1439*
1440* // Convert cipher set to equivalent capabilities.
1441* // NB: this logic intentionally ignores unknown and
1442* // unsupported ciphers so folks can specify 0xff or
1443* // similar and get all available ciphers.
1444*
1445* caps = 0;
1446* for (j = 1; j < 32; j++) // NB: skip WEP
1447* if ((value & (1<<j)) &&
1448* ((vap->iv_caps & cipher2cap(j)) ||
1449* ieee80211_crypto_available(j)))
1450* caps |= 1<<j;
1451* if (caps == 0) // nothing available
1452* return -EINVAL;
1453* // XXX verify ciphers ok for unicast use?
1454* // XXX disallow if running as it'll have no effect
1455* rsn->rsn_ucastcipherset = caps;
1456* if (vap->iv_flags & IEEE80211_F_WPA)
1457* retv = ENETRESET;
1458* break;
1459* case IEEE80211_PARAM_UCASTCIPHER:
1460* if ((rsn->rsn_ucastcipherset & cipher2cap(value)) == 0)
1461* return -EINVAL;
1462* rsn->rsn_ucastcipher = value;
1463* break;
1464* case IEEE80211_PARAM_UCASTKEYLEN:
1465* if (!(0 < value && value < IEEE80211_KEYBUF_SIZE))
1466* return -EINVAL;
1467* // XXX no way to verify driver capability
1468* rsn->rsn_ucastkeylen = value;
1469* break;
1470* case IEEE80211_PARAM_KEYMGTALGS:
1471* // XXX check
1472* rsn->rsn_keymgmtset = value;
1473* if (vap->iv_flags & IEEE80211_F_WPA)
1474* retv = ENETRESET;
1475* break;
1476* case IEEE80211_PARAM_RSNCAPS:
1477* // XXX check
1478* rsn->rsn_caps = value;
1479* if (vap->iv_flags & IEEE80211_F_WPA)
1480* retv = ENETRESET;
1481* break;
1482* case IEEE80211_PARAM_WPA:
1483* if (value > 3)
1484* return -EINVAL;
1485* // XXX verify ciphers available
1486* vap->iv_flags &= ~IEEE80211_F_WPA;
1487* switch (value) {
1488* case 1:
1489* vap->iv_flags |= IEEE80211_F_WPA1;
1490* break;
1491* case 2:
1492* vap->iv_flags |= IEEE80211_F_WPA2;
1493* break;
1494* case 3:
1495* vap->iv_flags |= IEEE80211_F_WPA1 | IEEE80211_F_WPA2;
1496* break;
1497* }
1498* retv = ENETRESET; // XXX?
1499* break;
1500* case IEEE80211_PARAM_ROAMING:
1501* if (!(IEEE80211_ROAMING_DEVICE <= value &&
1502* value <= IEEE80211_ROAMING_MANUAL))
1503* return -EINVAL;
1504* ic->ic_roaming = value;
1505* break;
1506* case IEEE80211_PARAM_PRIVACY:
1507* if (value) {
1508* // XXX check for key state?
1509* vap->iv_flags |= IEEE80211_F_PRIVACY;
1510* } else
1511* vap->iv_flags &= ~IEEE80211_F_PRIVACY;
1512* break;
1513* case IEEE80211_PARAM_DROPUNENCRYPTED:
1514* if (value)
1515* vap->iv_flags |= IEEE80211_F_DROPUNENC;
1516* else
1517* vap->iv_flags &= ~IEEE80211_F_DROPUNENC;
1518* break;
1519* case IEEE80211_PARAM_COUNTERMEASURES:
1520* if (value) {
1521* if ((vap->iv_flags & IEEE80211_F_WPA) == 0)
1522* return -EINVAL;
1523* vap->iv_flags |= IEEE80211_F_COUNTERM;
1524* } else
1525* vap->iv_flags &= ~IEEE80211_F_COUNTERM;
1526* break;
1527* case IEEE80211_PARAM_DRIVER_CAPS:
1528* vap->iv_caps = value; // NB: for testing
1529* break;
1530* case IEEE80211_PARAM_MACCMD:
1531* acl = vap->iv_acl;
1532* switch (value) {
1533* case IEEE80211_MACCMD_POLICY_OPEN:
1534* case IEEE80211_MACCMD_POLICY_ALLOW:
1535* case IEEE80211_MACCMD_POLICY_DENY:
1536* if (acl == NULL) {
1537* acl = ieee80211_aclator_get("mac");
1538* if (acl == NULL || !acl->iac_attach(vap))
1539* return -EINVAL;
1540* vap->iv_acl = acl;
1541* }
1542* acl->iac_setpolicy(vap, value);
1543* break;
1544* case IEEE80211_MACCMD_FLUSH:
1545* if (acl != NULL)
1546* acl->iac_flush(vap);
1547* // NB: silently ignore when not in use
1548* break;
1549* case IEEE80211_MACCMD_DETACH:
1550* if (acl != NULL) {
1551* vap->iv_acl = NULL;
1552* acl->iac_detach(vap);
1553* }
1554* break;
1555* }
1556* break;
1557* case IEEE80211_PARAM_WMM:
1558* if (ic->ic_caps & IEEE80211_C_WME){
1559* if (value) {
1560* vap->iv_flags |= IEEE80211_F_WME;
1561* *//* XXX needed by ic_reset *//*
1562* vap->iv_ic->ic_flags |= IEEE80211_F_WME;
1563* }
1564* else {
1565* *//* XXX needed by ic_reset *//*
1566* vap->iv_flags &= ~IEEE80211_F_WME;
1567* vap->iv_ic->ic_flags &= ~IEEE80211_F_WME;
1568* }
1569* retv = ENETRESET; // Renegotiate for capabilities
1570* }
1571* break;
1572* case IEEE80211_PARAM_HIDESSID:
1573* if (value)
1574* vap->iv_flags |= IEEE80211_F_HIDESSID;
1575* else
1576* vap->iv_flags &= ~IEEE80211_F_HIDESSID;
1577* retv = ENETRESET;
1578* break;
1579* case IEEE80211_PARAM_APBRIDGE:
1580* if (value == 0)
1581* vap->iv_flags |= IEEE80211_F_NOBRIDGE;
1582* else
1583* vap->iv_flags &= ~IEEE80211_F_NOBRIDGE;
1584* break;
1585* case IEEE80211_PARAM_INACT:
1586* vap->iv_inact_run = value / IEEE80211_INACT_WAIT;
1587* break;
1588* case IEEE80211_PARAM_INACT_AUTH:
1589* vap->iv_inact_auth = value / IEEE80211_INACT_WAIT;
1590* break;
1591* case IEEE80211_PARAM_INACT_INIT:
1592* vap->iv_inact_init = value / IEEE80211_INACT_WAIT;
1593* break;
1594* case IEEE80211_PARAM_ABOLT:
1595* caps = 0;
1596*
1597* // Map abolt settings to capability bits;
1598* // this also strips unknown/unwanted bits.
1599*
1600* if (value & IEEE80211_ABOLT_TURBO_PRIME)
1601* caps |= IEEE80211_ATHC_TURBOP;
1602* if (value & IEEE80211_ABOLT_COMPRESSION)
1603* caps |= IEEE80211_ATHC_COMP;
1604* if (value & IEEE80211_ABOLT_FAST_FRAME)
1605* caps |= IEEE80211_ATHC_FF;
1606* if (value & IEEE80211_ABOLT_XR)
1607* caps |= IEEE80211_ATHC_XR;
1608* if (value & IEEE80211_ABOLT_AR)
1609* caps |= IEEE80211_ATHC_AR;
1610* if (value & IEEE80211_ABOLT_BURST)
1611* caps |= IEEE80211_ATHC_BURST;
1612* if (value & IEEE80211_ABOLT_WME_ELE)
1613* caps |= IEEE80211_ATHC_WME;
1614* // verify requested capabilities are supported
1615* if ((caps & ic->ic_ath_cap) != caps)
1616* return -EINVAL;
1617* if (vap->iv_ath_cap != caps) {
1618* if ((vap->iv_ath_cap ^ caps) & IEEE80211_ATHC_TURBOP) {
1619* if (ieee80211_set_turbo(dev,
1620* caps & IEEE80211_ATHC_TURBOP))
1621* return -EINVAL;
1622* ieee80211_scan_flush(ic);
1623* }
1624* vap->iv_ath_cap = caps;
1625* ic->ic_athcapsetup(vap->iv_ic, vap->iv_ath_cap);
1626* retv = ENETRESET;
1627* }
1628* break;
1629* case IEEE80211_PARAM_DTIM_PERIOD:
1630* if (vap->iv_opmode != IEEE80211_M_HOSTAP &&
1631* vap->iv_opmode != IEEE80211_M_IBSS)
1632* return -EINVAL;
1633* if (IEEE80211_DTIM_MIN <= value &&
1634* value <= IEEE80211_DTIM_MAX) {
1635* vap->iv_dtim_period = value;
1636* retv = ENETRESET; // requires restart
1637* } else
1638* retv = EINVAL;
1639* break;
1640* case IEEE80211_PARAM_BEACON_INTERVAL:
1641* if (vap->iv_opmode != IEEE80211_M_HOSTAP &&
1642* vap->iv_opmode != IEEE80211_M_IBSS)
1643* return -EINVAL;
1644* if (IEEE80211_BINTVAL_MIN <= value &&
1645* value <= IEEE80211_BINTVAL_MAX) {
1646* ic->ic_lintval = value; // XXX multi-bss
1647* retv = ENETRESET; // requires restart
1648* } else
1649* retv = EINVAL;
1650* break;
1651* case IEEE80211_PARAM_DOTH:
1652* if (value) {
1653* ic->ic_flags |= IEEE80211_F_DOTH;
1654* }
1655* else
1656* ic->ic_flags &= ~IEEE80211_F_DOTH;
1657* retv = ENETRESET; // XXX: need something this drastic?
1658* break;
1659* case IEEE80211_PARAM_PWRTARGET:
1660* ic->ic_curchanmaxpwr = value;
1661* break;
1662* case IEEE80211_PARAM_GENREASSOC:
1663* IEEE80211_SEND_MGMT(vap->iv_bss,
1664* IEEE80211_FC0_SUBTYPE_REASSOC_REQ, 0);
1665* break;
1666* case IEEE80211_PARAM_COMPRESSION:
1667* retv = ieee80211_setathcap(vap, IEEE80211_ATHC_COMP, value);
1668* break;
1669* case IEEE80211_PARAM_WMM_AGGRMODE:
1670* retv = ieee80211_setathcap(vap, IEEE80211_ATHC_WME, value);
1671* break;
1672* case IEEE80211_PARAM_FF:
1673* retv = ieee80211_setathcap(vap, IEEE80211_ATHC_FF, value);
1674* break;
1675* case IEEE80211_PARAM_TURBO:
1676* retv = ieee80211_setathcap(vap, IEEE80211_ATHC_TURBOP, value);
1677* if (retv == ENETRESET) {
1678* if(ieee80211_set_turbo(dev,value))
1679* return -EINVAL;
1680* ieee80211_scan_flush(ic);
1681* }
1682* break;
1683* case IEEE80211_PARAM_XR:
1684* retv = ieee80211_setathcap(vap, IEEE80211_ATHC_XR, value);
1685* break;
1686* case IEEE80211_PARAM_BURST:
1687* retv = ieee80211_setathcap(vap, IEEE80211_ATHC_BURST, value);
1688* break;
1689* case IEEE80211_PARAM_AR:
1690* retv = ieee80211_setathcap(vap, IEEE80211_ATHC_AR, value);
1691* break;
1692* case IEEE80211_PARAM_PUREG:
1693* if (value)
1694* vap->iv_flags |= IEEE80211_F_PUREG;
1695* else
1696* vap->iv_flags &= ~IEEE80211_F_PUREG;
1697* // NB: reset only if we're operating on an 11g channel
1698* if (ic->ic_bsschan != IEEE80211_CHAN_ANYC &&
1699* IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan))
1700* retv = ENETRESET;
1701* break;
1702* case IEEE80211_PARAM_WDS:
1703* if (value)
1704* vap->iv_flags_ext |= IEEE80211_FEXT_WDS;
1705* else
1706* vap->iv_flags_ext &= ~IEEE80211_FEXT_WDS;
1707* break;
1708* case IEEE80211_PARAM_BGSCAN:
1709* if (value) {
1710* if ((vap->iv_caps & IEEE80211_C_BGSCAN) == 0)
1711* return -EINVAL;
1712* vap->iv_flags |= IEEE80211_F_BGSCAN;
1713* } else {
1714* // XXX racey?
1715* vap->iv_flags &= ~IEEE80211_F_BGSCAN;
1716* ieee80211_cancel_scan(vap); // anything current
1717* }
1718* break;
1719* case IEEE80211_PARAM_BGSCAN_IDLE:
1720* if (value >= IEEE80211_BGSCAN_IDLE_MIN)
1721* vap->iv_bgscanidle = value*HZ/1000;
1722* else
1723* retv = EINVAL;
1724* break;
1725* case IEEE80211_PARAM_BGSCAN_INTERVAL:
1726* if (value >= IEEE80211_BGSCAN_INTVAL_MIN)
1727* vap->iv_bgscanintvl = value*HZ;
1728* else
1729* retv = EINVAL;
1730* break;
1731* case IEEE80211_PARAM_MCAST_RATE:
1732* // units are in KILObits per second
1733* if (value >= 256 && value <= 54000)
1734* vap->iv_mcast_rate = value;
1735* else
1736* retv = EINVAL;
1737* break;
1738* case IEEE80211_PARAM_COVERAGE_CLASS:
1739* if (value >= 0 && value <= IEEE80211_COVERAGE_CLASS_MAX) {
1740* ic->ic_coverageclass = value;
1741* if (IS_UP_AUTO(vap))
1742* ieee80211_new_state(vap, IEEE80211_S_SCAN, 0);
1743* retv = 0;
1744* }
1745* else
1746* retv = EINVAL;
1747* break;
1748* case IEEE80211_PARAM_COUNTRY_IE:
1749* if (value)
1750* ic->ic_flags_ext |= IEEE80211_FEXT_COUNTRYIE;
1751* else
1752* ic->ic_flags_ext &= ~IEEE80211_FEXT_COUNTRYIE;
1753* retv = ENETRESET;
1754* break;
1755* case IEEE80211_PARAM_REGCLASS:
1756* if (value)
1757* ic->ic_flags_ext |= IEEE80211_FEXT_REGCLASS;
1758* else
1759* ic->ic_flags_ext &= ~IEEE80211_FEXT_REGCLASS;
1760* retv = ENETRESET;
1761* break;
1762* case IEEE80211_PARAM_SCANVALID:
1763* vap->iv_scanvalid = value*HZ;
1764* break;
1765* case IEEE80211_PARAM_ROAM_RSSI_11A:
1766* vap->iv_roam.rssi11a = value;
1767* break;
1768* case IEEE80211_PARAM_ROAM_RSSI_11B:
1769* vap->iv_roam.rssi11bOnly = value;
1770* break;
1771* case IEEE80211_PARAM_ROAM_RSSI_11G:
1772* vap->iv_roam.rssi11b = value;
1773* break;
1774* case IEEE80211_PARAM_ROAM_RATE_11A:
1775* vap->iv_roam.rate11a = value;
1776* break;
1777* case IEEE80211_PARAM_ROAM_RATE_11B:
1778* vap->iv_roam.rate11bOnly = value;
1779* break;
1780* case IEEE80211_PARAM_ROAM_RATE_11G:
1781* vap->iv_roam.rate11b = value;
1782* break;
1783* case IEEE80211_PARAM_UAPSDINFO:
1784* if (vap->iv_opmode == IEEE80211_M_HOSTAP) {
1785* if (ic->ic_caps & IEEE80211_C_UAPSD) {
1786* if (value)
1787* IEEE80211_VAP_UAPSD_ENABLE(vap);
1788* else
1789* IEEE80211_VAP_UAPSD_DISABLE(vap);
1790* retv = ENETRESET;
1791* }
1792* }
1793* else if (vap->iv_opmode == IEEE80211_M_STA) {
1794* vap->iv_uapsdinfo = value;
1795* IEEE80211_VAP_UAPSD_ENABLE(vap);
1796* retv = ENETRESET;
1797* }
1798* break;
1799* case IEEE80211_PARAM_SLEEP:
1800* // XXX: Forced sleep for testing. Does not actually place the
1801* // HW in sleep mode yet. this only makes sense for STAs.
1802*
1803* if (value) {
1804* // goto sleep
1805* IEEE80211_VAP_GOTOSLEEP(vap);
1806* }
1807* else {
1808* // wakeup
1809* IEEE80211_VAP_WAKEUP(vap);
1810* }
1811* ieee80211_send_nulldata(ieee80211_ref_node(vap->iv_bss));
1812* break;
1813* case IEEE80211_PARAM_QOSNULL:
1814* // Force a QoS Null for testing.
1815* ieee80211_send_qosnulldata(vap->iv_bss, value);
1816* break;
1817* case IEEE80211_PARAM_PSPOLL:
1818* // Force a PS-POLL for testing.
1819* ieee80211_send_pspoll(vap->iv_bss);
1820* break;
1821* case IEEE80211_PARAM_EOSPDROP:
1822* if (vap->iv_opmode == IEEE80211_M_HOSTAP) {
1823* if (value) IEEE80211_VAP_EOSPDROP_ENABLE(vap);
1824* else IEEE80211_VAP_EOSPDROP_DISABLE(vap);
1825* }
1826* break;
1827* case IEEE80211_PARAM_MARKDFS:
1828* if (value)
1829* ic->ic_flags_ext |= IEEE80211_FEXT_MARKDFS;
1830* else
1831* ic->ic_flags_ext &= ~IEEE80211_FEXT_MARKDFS;
1832* break;
1833* case IEEE80211_PARAM_CHANBW:
1834* switch (value) {
1835* case 0:
1836* ic->ic_chanbwflag = 0;
1837* break;
1838* case 1:
1839* ic->ic_chanbwflag = IEEE80211_CHAN_HALF;
1840* break;
1841* case 2:
1842* ic->ic_chanbwflag = IEEE80211_CHAN_QUARTER;
1843* break;
1844* default:
1845* retv = EINVAL;
1846* break;
1847* }
1848* break;
1849* case IEEE80211_PARAM_SHORTPREAMBLE:
1850* if (value) {
1851* ic->ic_caps |= IEEE80211_C_SHPREAMBLE;
1852* } else {
1853* ic->ic_caps &= ~IEEE80211_C_SHPREAMBLE;
1854* }
1855* retv = ENETRESET;
1856* break;
1857* default:
1858* retv = EOPNOTSUPP;
1859* break;
1860* }
1861* // XXX should any of these cause a rescan?
1862* if (retv == ENETRESET)
1863* retv = IS_UP_AUTO(vap) ? ieee80211_open(vap->iv_dev) : 0;
1864* return -retv;
1865*}
1866*/
4bd43f50
LR
1867
1868int usbdrvwext_setmode(struct net_device *dev, struct iw_request_info *info,
aef911a5 1869 void *w, char *extra)
4bd43f50
LR
1870{
1871 return 0;
1872}
1873
1874int usbdrvwext_getmode(struct net_device *dev, struct iw_request_info *info,
1875 void *w, char *extra)
1876{
aef911a5 1877 /* struct usbdrv_private *macp = dev->ml_priv; */
4bd43f50
LR
1878 struct iw_point *wri = (struct iw_point *)extra;
1879 char mode[8];
1880
aef911a5
DZ
1881 strcpy(mode, "11g");
1882 return copy_to_user(wri->pointer, mode, 6) ? -EFAULT : 0;
4bd43f50
LR
1883}
1884
1885int zfLnxPrivateIoctl(struct net_device *dev, struct zdap_ioctl* zdreq)
1886{
aef911a5 1887 /* void* regp = macp->regp; */
4bd43f50 1888 u16_t cmd;
aef911a5
DZ
1889 /* u32_t temp; */
1890 u32_t *p;
4bd43f50
LR
1891 u32_t i;
1892
1893 cmd = zdreq->cmd;
aef911a5 1894 switch (cmd) {
4bd43f50
LR
1895 case ZM_IOCTL_REG_READ:
1896 zfiDbgReadReg(dev, zdreq->addr);
1897 break;
4bd43f50
LR
1898 case ZM_IOCTL_REG_WRITE:
1899 zfiDbgWriteReg(dev, zdreq->addr, zdreq->value);
1900 break;
4bd43f50
LR
1901 case ZM_IOCTL_MEM_READ:
1902 p = (u32_t *) bus_to_virt(zdreq->addr);
aef911a5
DZ
1903 printk(KERN_WARNING
1904 "usbdrv: read memory addr: 0x%08x value:"
1905 " 0x%08x\n", zdreq->addr, *p);
4bd43f50 1906 break;
4bd43f50
LR
1907 case ZM_IOCTL_MEM_WRITE:
1908 p = (u32_t *) bus_to_virt(zdreq->addr);
1909 *p = zdreq->value;
aef911a5
DZ
1910 printk(KERN_WARNING
1911 "usbdrv : write value : 0x%08x to memory addr :"
1912 " 0x%08x\n", zdreq->value, zdreq->addr);
4bd43f50 1913 break;
aef911a5 1914 case ZM_IOCTL_TALLY:
4bd43f50
LR
1915 zfiWlanShowTally(dev);
1916 if (zdreq->addr)
1917 zfiWlanResetTally(dev);
1918 break;
aef911a5
DZ
1919 case ZM_IOCTL_TEST:
1920 printk(KERN_WARNING
1921 "ZM_IOCTL_TEST:len=%d\n", zdreq->addr);
1922 /* zfiWlanReadReg(dev, 0x10f400); */
1923 /* zfiWlanReadReg(dev, 0x10f404); */
1924 printk(KERN_WARNING "IOCTL TEST\n");
1925 #if 1
1926 /* print packet */
1927 for (i = 0; i < zdreq->addr; i++) {
1928 if ((i&0x7) == 0)
1929 printk(KERN_WARNING "\n");
1930 printk(KERN_WARNING "%02X ",
1931 (unsigned char)zdreq->data[i]);
1932 }
1933 printk(KERN_WARNING "\n");
1934 #endif
1935
1936 /* For Test?? 1 to 0 by CWYang(-) */
1937 #if 0
1938 struct sk_buff *s;
1939
1940 /* Allocate a skb */
1941 s = alloc_skb(2000, GFP_ATOMIC);
4bd43f50 1942
aef911a5
DZ
1943 /* Copy data to skb */
1944 for (i = 0; i < zdreq->addr; i++)
1945 s->data[i] = zdreq->data[i];
1946 s->len = zdreq->addr;
4bd43f50 1947
aef911a5
DZ
1948 /* Call zfIdlRecv() */
1949 zfiRecv80211(dev, s, NULL);
1950 #endif
1951 break;
1952 /************************* ZDCONFIG ***************************/
1953 case ZM_IOCTL_FRAG:
1954 zfiWlanSetFragThreshold(dev, zdreq->addr);
1955 break;
1956 case ZM_IOCTL_RTS:
1957 zfiWlanSetRtsThreshold(dev, zdreq->addr);
1958 break;
1959 case ZM_IOCTL_SCAN:
1960 zfiWlanScan(dev);
1961 break;
1962 case ZM_IOCTL_KEY: {
1963 u8_t key[29];
1964 struct zsKeyInfo keyInfo;
1965 u32_t i;
1966
1967 for (i = 0; i < 29; i++)
1968 key[i] = 0;
1969
1970 for (i = 0; i < zdreq->addr; i++)
1971 key[i] = zdreq->data[i];
1972
1973 printk(KERN_WARNING
1974 "key len=%d, key=%02x%02x%02x%02x%02x...\n",
1975 zdreq->addr, key[0], key[1], key[2], key[3], key[4]);
1976
1977 keyInfo.keyLength = zdreq->addr;
1978 keyInfo.keyIndex = 0;
1979 keyInfo.flag = 0;
1980 keyInfo.key = key;
1981 zfiWlanSetKey(dev, keyInfo);
1982 }
1983 break;
1984 case ZM_IOCTL_RATE:
1985 zfiWlanSetTxRate(dev, zdreq->addr);
1986 break;
1987 case ZM_IOCTL_ENCRYPTION_MODE:
1988 zfiWlanSetEncryMode(dev, zdreq->addr);
1989
1990 zfiWlanDisable(dev, 0);
1991 zfiWlanEnable(dev);
1992 break;
1993 /* CWYang(+) */
1994 case ZM_IOCTL_SIGNAL_STRENGTH: {
1995 u8_t buffer[2];
1996 zfiWlanQuerySignalInfo(dev, &buffer[0]);
1997 printk(KERN_WARNING
1998 "Current Signal Strength : %02d\n", buffer[0]);
1999 }
2000 break;
2001 /* CWYang(+) */
2002 case ZM_IOCTL_SIGNAL_QUALITY: {
2003 u8_t buffer[2];
2004 zfiWlanQuerySignalInfo(dev, &buffer[0]);
2005 printk(KERN_WARNING
2006 "Current Signal Quality : %02d\n", buffer[1]);
2007 }
2008 break;
4bd43f50
LR
2009 case ZM_IOCTL_SET_PIBSS_MODE:
2010 if (zdreq->addr == 1)
2011 zfiWlanSetWlanMode(dev, ZM_MODE_PSEUDO);
2012 else
2013 zfiWlanSetWlanMode(dev, ZM_MODE_INFRASTRUCTURE);
2014
2015 zfiWlanDisable(dev, 0);
2016 zfiWlanEnable(dev);
4bd43f50 2017 break;
aef911a5
DZ
2018 /********************* ZDCONFIG ***********************/
2019 default:
4bd43f50
LR
2020 printk(KERN_ERR "usbdrv: error command = %x\n", cmd);
2021 break;
2022 }
2023
2024 return 0;
2025}
2026
2027int usbdrv_wpa_ioctl(struct net_device *dev, struct athr_wlan_param *zdparm)
2028{
aef911a5
DZ
2029 int ret = 0;
2030 u8_t bc_addr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2031 u8_t mac_addr[80];
2032 struct zsKeyInfo keyInfo;
2033 struct usbdrv_private *macp = dev->ml_priv;
2034 u16_t vapId = 0;
4a5629b9 2035 int ii;
aef911a5
DZ
2036
2037 /* zmw_get_wlan_dev(dev); */
2038
2039 switch (zdparm->cmd) {
2040 case ZD_CMD_SET_ENCRYPT_KEY:
2041 /* Set up key information */
2042 keyInfo.keyLength = zdparm->u.crypt.key_len;
2043 keyInfo.keyIndex = zdparm->u.crypt.idx;
2044 if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) {
2045 /* AP Mode */
2046 keyInfo.flag = ZM_KEY_FLAG_AUTHENTICATOR;
2047 } else
2048 keyInfo.flag = 0;
2049 keyInfo.key = zdparm->u.crypt.key;
2050 keyInfo.initIv = zdparm->u.crypt.seq;
2051 keyInfo.macAddr = (u16_t *)zdparm->sta_addr;
2052
2053 /* Identify the MAC address information */
2054 if (memcmp(zdparm->sta_addr, bc_addr, sizeof(bc_addr)) == 0)
2055 keyInfo.flag |= ZM_KEY_FLAG_GK;
2056 else
2057 keyInfo.flag |= ZM_KEY_FLAG_PK;
2058
2059 if (!strcmp(zdparm->u.crypt.alg, "NONE")) {
2060 /* u8_t zero_mac[]={0,0,0,0,0,0}; */
2061
2062 /* Set key length to zero */
2063 keyInfo.keyLength = 0;
2064
2065 /* del group key */
2066 if (zdparm->sta_addr[0] & 1) {
2067 /* if (macp->cardSetting.WPAIeLen==0)
2068 * { 802.1x dynamic WEP
2069 * mDynKeyMode = 0;
2070 * mKeyFormat[0] = 0;
2071 * mPrivacyInvoked[0]=FALSE;
2072 * mCap[0] &= ~CAP_PRIVACY;
2073 * macp->cardSetting.EncryOnOff[0]=0;
2074 * }
2075 * mWpaBcKeyLen = mGkInstalled = 0;
2076 */
2077 } else {
2078 /* if (memcmp(zero_mac,zdparm->sta_addr, 6)==0)
2079 * {
2080 * mDynKeyMode=0;
2081 * mKeyFormat[0]=0;
2082 * pSetting->DynKeyMode=0;
2083 * pSetting->EncryMode[0]=0;
2084 * mDynKeyMode=0;
2085 * }
2086 */
2087 }
2088
2089 printk(KERN_ERR "Set Encryption Type NONE\n");
2090 return ret;
2091 } else if (!strcmp(zdparm->u.crypt.alg, "TKIP")) {
2092 zfiWlanSetEncryMode(dev, ZM_TKIP);
2093 /* //Linux Supplicant will inverse Tx/Rx key
2094 * //So we inverse it back, CWYang(+)
2095 * zfMemoryCopy(&temp[0], &keyInfo.key[16], 8);
2096 * zfMemoryCopy(&keyInfo.key[16], keyInfo.key[24], 8);
2097 * zfMemoryCopy(&keyInfo.key[24], &temp[0], 8);
2098 * u8_t temp;
2099 * int k;
2100 * for (k = 0; k < 8; k++)
2101 * {
2102 * temp = keyInfo.key[16 + k];
2103 * keyInfo.key[16 + k] = keyInfo.key[24 + k];
2104 * keyInfo.key[24 + k] = temp;
2105 * }
2106 * CamEncryType = ZM_TKIP;
2107 * if (idx == 0)
2108 * { // Pairwise key
2109 * mKeyFormat[0] = CamEncryType;
2110 * mDynKeyMode = pSetting->DynKeyMode = DYN_KEY_TKIP;
2111 * }
2112 */
2113 } else if (!strcmp(zdparm->u.crypt.alg, "CCMP")) {
2114 zfiWlanSetEncryMode(dev, ZM_AES);
2115 /* CamEncryType = ZM_AES;
2116 * if (idx == 0)
2117 * { // Pairwise key
2118 * mKeyFormat[0] = CamEncryType;
2119 * mDynKeyMode = pSetting->DynKeyMode = DYN_KEY_AES;
2120 * }
2121 */
2122 } else if (!strcmp(zdparm->u.crypt.alg, "WEP")) {
2123 if (keyInfo.keyLength == 5) {
2124 /* WEP 64 */
2125 zfiWlanSetEncryMode(dev, ZM_WEP64);
2126 /* CamEncryType = ZM_WEP64; */
2127 /* tmpDynKeyMode=DYN_KEY_WEP64; */
2128 } else if (keyInfo.keyLength == 13) {
2129 /* keylen=13, WEP 128 */
2130 zfiWlanSetEncryMode(dev, ZM_WEP128);
2131 /* CamEncryType = ZM_WEP128; */
2132 /* tmpDynKeyMode=DYN_KEY_WEP128; */
2133 } else {
2134 zfiWlanSetEncryMode(dev, ZM_WEP256);
2135 }
2136
2137 /* For Dynamic WEP key (Non-WPA Radius), the key ID range: 0-3
2138 * In WPA/RSN mode, the key ID range: 1-3, usually, a broadcast key.
2139 * For WEP key setting: we set mDynKeyMode and mKeyFormat in following
2140 * case:
2141 * 1. For 802.1x dynamically generated WEP key method.
2142 * 2. For WPA/RSN mode, but key id == 0.
2143 * (But this is an impossible case)
2144 * So, only check case 1.
2145 * if (macp->cardSetting.WPAIeLen==0)
2146 * {
2147 * mKeyFormat[0] = CamEncryType;
2148 * mDynKeyMode = pSetting->DynKeyMode = tmpDynKeyMode;
2149 * mPrivacyInvoked[0]=TRUE;
2150 * mCap[0] |= CAP_PRIVACY;
2151 * macp->cardSetting.EncryOnOff[0]=1;
2152 * }
2153 */
2154 }
2155
2156 /* DUMP key context */
2157 /* #ifdef WPA_DEBUG */
2158 if (keyInfo.keyLength > 0) {
aef911a5
DZ
2159 printk(KERN_WARNING
2160 "Otus: Key Context:\n");
2161 for (ii = 0; ii < keyInfo.keyLength; ) {
2162 printk(KERN_WARNING
2163 "0x%02x ", keyInfo.key[ii]);
2164 if ((++ii % 16) == 0)
2165 printk(KERN_WARNING "\n");
2166 }
2167 printk(KERN_WARNING "\n");
2168 }
2169 /* #endif */
2170
2171 /* Set encrypt mode */
2172 /* zfiWlanSetEncryMode(dev, CamEncryType); */
2173 vapId = zfLnxGetVapId(dev);
2174 if (vapId == 0xffff)
2175 keyInfo.vapId = 0;
2176 else
2177 keyInfo.vapId = vapId + 1;
2178 keyInfo.vapAddr[0] = keyInfo.macAddr[0];
2179 keyInfo.vapAddr[1] = keyInfo.macAddr[1];
2180 keyInfo.vapAddr[2] = keyInfo.macAddr[2];
2181
2182 zfiWlanSetKey(dev, keyInfo);
2183
2184 /* zfiWlanDisable(dev); */
2185 /* zfiWlanEnable(dev); */
2186 break;
2187 case ZD_CMD_SET_MLME:
2188 printk(KERN_ERR "usbdrv_wpa_ioctl: ZD_CMD_SET_MLME\n");
2189
2190 /* Translate STA's address */
2191 sprintf(mac_addr, "%02x:%02x:%02x:%02x:%02x:%02x",
2192 zdparm->sta_addr[0], zdparm->sta_addr[1],
2193 zdparm->sta_addr[2], zdparm->sta_addr[3],
2194 zdparm->sta_addr[4], zdparm->sta_addr[5]);
2195
2196 switch (zdparm->u.mlme.cmd) {
2197 case MLME_STA_DEAUTH:
2198 printk(KERN_WARNING
2199 " -------Call zfiWlanDeauth, reason:%d\n",
2200 zdparm->u.mlme.reason_code);
2201 if (zfiWlanDeauth(dev, (u16_t *) zdparm->sta_addr,
2202 zdparm->u.mlme.reason_code) != 0)
2203 printk(KERN_ERR "Can't deauthencate STA: %s\n",
2204 mac_addr);
2205 else
2206 printk(KERN_ERR "Deauthenticate STA: %s"
2207 "with reason code: %d\n",
2208 mac_addr, zdparm->u.mlme.reason_code);
2209 break;
2210 case MLME_STA_DISASSOC:
2211 printk(KERN_WARNING
2212 " -------Call zfiWlanDeauth, reason:%d\n",
2213 zdparm->u.mlme.reason_code);
2214 if (zfiWlanDeauth(dev, (u16_t *) zdparm->sta_addr,
2215 zdparm->u.mlme.reason_code) != 0)
2216 printk(KERN_ERR "Can't disassociate STA: %s\n",
2217 mac_addr);
2218 else
2219 printk(KERN_ERR "Disassociate STA: %s"
2220 "with reason code: %d\n",
2221 mac_addr, zdparm->u.mlme.reason_code);
2222 break;
2223 default:
2224 printk(KERN_ERR "MLME command: 0x%04x not support\n",
2225 zdparm->u.mlme.cmd);
2226 break;
2227 }
2228
2229 break;
2230 case ZD_CMD_SCAN_REQ:
2231 printk(KERN_ERR "usbdrv_wpa_ioctl: ZD_CMD_SCAN_REQ\n");
2232 break;
d0279369 2233 case ZD_CMD_SET_GENERIC_ELEMENT: {
2234 u8_t len, *wpaie;
aef911a5
DZ
2235 printk(KERN_ERR "usbdrv_wpa_ioctl:"
2236 " ZD_CMD_SET_GENERIC_ELEMENT\n");
2237
2238 /* Copy the WPA IE
2239 * zm_msg1_mm(ZM_LV_0, "CWY - wpaie Length : ",
2240 * zdparm->u.generic_elem.len);
2241 */
2242 printk(KERN_ERR "wpaie Length : % d\n",
2243 zdparm->u.generic_elem.len);
2244 if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) {
2245 /* AP Mode */
2246 zfiWlanSetWpaIe(dev, zdparm->u.generic_elem.data,
2247 zdparm->u.generic_elem.len);
2248 } else {
2249 macp->supLen = zdparm->u.generic_elem.len;
2250 memcpy(macp->supIe, zdparm->u.generic_elem.data,
2251 zdparm->u.generic_elem.len);
2252 }
2253 zfiWlanSetWpaSupport(dev, 1);
2254 /* zfiWlanSetWpaIe(dev, zdparm->u.generic_elem.data,
2255 * zdparm->u.generic_elem.len);
2256 */
d0279369 2257 len = zdparm->u.generic_elem.len;
2258 wpaie = zdparm->u.generic_elem.data;
aef911a5
DZ
2259
2260 printk(KERN_ERR "wd->ap.wpaLen : % d\n", len);
2261
2262 /* DUMP WPA IE */
25b37eca 2263 for (ii = 0; ii < len;) {
aef911a5
DZ
2264 printk(KERN_ERR "0x%02x ", wpaie[ii]);
2265
25b37eca 2266 if ((++ii % 16) == 0)
aef911a5
DZ
2267 printk(KERN_ERR "\n");
2268 }
2269 printk(KERN_ERR "\n");
2270
2271 /* #ifdef ZM_HOSTAPD_SUPPORT
2272 * if (wd->wlanMode == ZM_MODE_AP)
2273 * {// Update Beacon FIFO in the next TBTT.
2274 * memcpy(&mWPAIe, pSetting->WPAIe, pSetting->WPAIeLen);
2275 * printk(KERN_ERR "Copy WPA IE into mWPAIe\n");
2276 * }
2277 * #endif
2278 */
2279 break;
d0279369 2280 }
aef911a5
DZ
2281
2282 /* #ifdef ZM_HOSTAPD_SUPPORT */
2283 case ZD_CMD_GET_TSC:
2284 printk(KERN_ERR "usbdrv_wpa_ioctl : ZD_CMD_GET_TSC\n");
2285 break;
2286 /* #endif */
2287
2288 default:
2289 printk(KERN_ERR "usbdrv_wpa_ioctl default : 0x%04x\n",
2290 zdparm->cmd);
2291 ret = -EINVAL;
2292 break;
2293 }
2294
2295 return ret;
4bd43f50
LR
2296}
2297
2298#ifdef ZM_ENABLE_CENC
2299int usbdrv_cenc_ioctl(struct net_device *dev, struct zydas_cenc_param *zdparm)
2300{
aef911a5
DZ
2301 /* struct usbdrv_private *macp = dev->ml_priv; */
2302 struct zsKeyInfo keyInfo;
2303 u16_t apId;
2304 u8_t bc_addr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2305 int ret = 0;
2306 int ii;
2307
2308 /* Get the AP Id */
2309 apId = zfLnxGetVapId(dev);
2310
25b37eca 2311 if (apId == 0xffff)
aef911a5 2312 apId = 0;
25b37eca 2313 else
aef911a5 2314 apId = apId + 1;
4bd43f50 2315
aef911a5
DZ
2316 switch (zdparm->cmd) {
2317 case ZM_CMD_CENC_SETCENC:
2318 printk(KERN_ERR "ZM_CMD_CENC_SETCENC\n");
2319 printk(KERN_ERR "length : % d\n", zdparm->len);
2320 printk(KERN_ERR "policy : % d\n", zdparm->u.info.cenc_policy);
2321 break;
2322 case ZM_CMD_CENC_SETKEY:
2323 /* ret = wai_ioctl_setkey(vap, ioctl_msg); */
2324 printk(KERN_ERR "ZM_CMD_CENC_SETKEY\n");
2325
2326 printk(KERN_ERR "MAC address = ");
2327 for (ii = 0; ii < 6; ii++) {
2328 printk(KERN_ERR "0x%02x ",
2329 zdparm->u.crypt.sta_addr[ii]);
2330 }
2331 printk(KERN_ERR "\n");
4bd43f50 2332
aef911a5
DZ
2333 printk(KERN_ERR "Key Index : % d\n", zdparm->u.crypt.keyid);
2334 printk(KERN_ERR "Encryption key = ");
25b37eca 2335 for (ii = 0; ii < 16; ii++)
aef911a5 2336 printk(KERN_ERR "0x%02x ", zdparm->u.crypt.key[ii]);
25b37eca 2337
aef911a5 2338 printk(KERN_ERR "\n");
4bd43f50 2339
aef911a5 2340 printk(KERN_ERR "MIC key = ");
25b37eca 2341 for (ii = 16; ii < ZM_CENC_KEY_SIZE; ii++)
aef911a5 2342 printk(KERN_ERR "0x%02x ", zdparm->u.crypt.key[ii]);
25b37eca 2343
aef911a5
DZ
2344 printk(KERN_ERR "\n");
2345
2346 /* Set up key information */
2347 keyInfo.keyLength = ZM_CENC_KEY_SIZE;
2348 keyInfo.keyIndex = zdparm->u.crypt.keyid;
2349 keyInfo.flag = ZM_KEY_FLAG_AUTHENTICATOR | ZM_KEY_FLAG_CENC;
2350 keyInfo.key = zdparm->u.crypt.key;
2351 keyInfo.macAddr = (u16_t *)zdparm->u.crypt.sta_addr;
2352
2353 /* Identify the MAC address information */
2354 if (memcmp(zdparm->u.crypt.sta_addr, bc_addr,
2355 sizeof(bc_addr)) == 0) {
2356 keyInfo.flag |= ZM_KEY_FLAG_GK;
2357 keyInfo.vapId = apId;
2358 memcpy(keyInfo.vapAddr, dev->dev_addr, ETH_ALEN);
2359 } else {
2360 keyInfo.flag |= ZM_KEY_FLAG_PK;
2361 }
4bd43f50 2362
aef911a5 2363 zfiWlanSetKey(dev, keyInfo);
4bd43f50 2364
aef911a5
DZ
2365 break;
2366 case ZM_CMD_CENC_REKEY:
2367 /* ret = wai_ioctl_rekey(vap, ioctl_msg); */
2368 printk(KERN_ERR "ZM_CMD_CENC_REKEY\n");
2369 break;
2370 default:
2371 ret = -EOPNOTSUPP;
2372 break;
2373 }
4bd43f50 2374
aef911a5
DZ
2375 /* if (retv == ENETRESET) */
2376 /* retv = IS_UP_AUTO(vap) ? ieee80211_open(vap->iv_dev) : 0; */
4bd43f50 2377
aef911a5
DZ
2378 return ret;
2379}
2380#endif /* ZM_ENABLE_CENC */
4bd43f50 2381
aef911a5
DZ
2382int usbdrv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2383{
2384 /* struct usbdrv_private *macp; */
2385 /* void *regp; */
2386 struct zdap_ioctl zdreq;
2387 struct iwreq *wrq = (struct iwreq *)ifr;
2388 struct athr_wlan_param zdparm;
2389 struct usbdrv_private *macp = dev->ml_priv;
4bd43f50 2390
4a5629b9 2391 int err = 0, val = 0;
aef911a5 2392 int changed = 0;
4bd43f50 2393
aef911a5 2394 /* regp = macp->regp; */
4bd43f50 2395
aef911a5
DZ
2396 if (!netif_running(dev))
2397 return -EINVAL;
4bd43f50 2398
aef911a5
DZ
2399 switch (cmd) {
2400 case SIOCGIWNAME:
2401 strcpy(wrq->u.name, "IEEE 802.11-DS");
2402 break;
2403 case SIOCGIWAP:
2404 err = usbdrvwext_giwap(dev, NULL, &wrq->u.ap_addr, NULL);
2405 break;
2406 case SIOCSIWAP:
2407 err = usbdrvwext_siwap(dev, NULL, &wrq->u.ap_addr, NULL);
2408 break;
2409 case SIOCGIWMODE:
2410 err = usbdrvwext_giwmode(dev, NULL, &wrq->u.mode, NULL);
2411 break;
2412 case SIOCSIWESSID:
2413 printk(KERN_ERR "CWY - usbdrvwext_siwessid\n");
2414 /* err = usbdrv_ioctl_setessid(dev, &wrq->u.essid); */
2415 err = usbdrvwext_siwessid(dev, NULL, &wrq->u.essid, NULL);
4bd43f50 2416
aef911a5
DZ
2417 if (!err)
2418 changed = 1;
2419 break;
2420 case SIOCGIWESSID:
2421 err = usbdrvwext_giwessid(dev, NULL, &wrq->u.essid, NULL);
2422 break;
2423 case SIOCSIWRTS:
2424 err = usbdrv_ioctl_setrts(dev, &wrq->u.rts);
25b37eca 2425 if (!err)
aef911a5
DZ
2426 changed = 1;
2427 break;
2428 /* set_auth */
2429 case SIOCIWFIRSTPRIV + 0x2: {
2430 /* printk("CWY - SIOCIWFIRSTPRIV + 0x2(set_auth)\n"); */
2431 if (!capable(CAP_NET_ADMIN)) {
2432 err = -EPERM;
2433 break;
2434 }
4a5629b9 2435 val = *((int *) wrq->u.name);
aef911a5
DZ
2436 if ((val < 0) || (val > 2)) {
2437 err = -EINVAL;
2438 break;
2439 } else {
2440 zfiWlanSetAuthenticationMode(dev, val);
4bd43f50 2441
aef911a5
DZ
2442 if (macp->DeviceOpened == 1) {
2443 zfiWlanDisable(dev, 0);
2444 zfiWlanEnable(dev);
2445 }
4bd43f50 2446
aef911a5
DZ
2447 err = 0;
2448 changed = 1;
2449 }
2450 }
2451 break;
2452 /* get_auth */
2453 case SIOCIWFIRSTPRIV + 0x3: {
2454 int AuthMode = ZM_AUTH_MODE_OPEN;
4bd43f50 2455
aef911a5 2456 /* printk("CWY - SIOCIWFIRSTPRIV + 0x3(get_auth)\n"); */
4bd43f50 2457
aef911a5
DZ
2458 if (wrq->u.data.pointer) {
2459 wrq->u.data.flags = 1;
4bd43f50 2460
aef911a5
DZ
2461 AuthMode = zfiWlanQueryAuthenticationMode(dev, 0);
2462 if (AuthMode == ZM_AUTH_MODE_OPEN) {
2463 wrq->u.data.length = 12;
4bd43f50 2464
aef911a5
DZ
2465 if (copy_to_user(wrq->u.data.pointer,
2466 "open system", 12)) {
2467 return -EFAULT;
4bd43f50 2468 }
aef911a5
DZ
2469 } else if (AuthMode == ZM_AUTH_MODE_SHARED_KEY) {
2470 wrq->u.data.length = 11;
4bd43f50 2471
aef911a5
DZ
2472 if (copy_to_user(wrq->u.data.pointer,
2473 "shared key", 11)) {
2474 return -EFAULT;
2475 }
2476 } else if (AuthMode == ZM_AUTH_MODE_AUTO) {
2477 wrq->u.data.length = 10;
4bd43f50 2478
aef911a5
DZ
2479 if (copy_to_user(wrq->u.data.pointer,
2480 "auto mode", 10)) {
2481 return -EFAULT;
4bd43f50 2482 }
aef911a5
DZ
2483 } else {
2484 return -EFAULT;
4bd43f50
LR
2485 }
2486 }
aef911a5
DZ
2487 }
2488 break;
2489 /* debug command */
2490 case ZDAPIOCTL:
2491 if (copy_from_user(&zdreq, ifr->ifr_data, sizeof(zdreq))) {
2492 printk(KERN_ERR "usbdrv : copy_from_user error\n");
2493 return -EFAULT;
2494 }
4bd43f50 2495
aef911a5
DZ
2496 /* printk(KERN_WARNING
2497 * "usbdrv : cmd = % 2x, reg = 0x%04lx,
2498 *value = 0x%08lx\n",
2499 * zdreq.cmd, zdreq.addr, zdreq.value);
2500 */
2501 zfLnxPrivateIoctl(dev, &zdreq);
4bd43f50 2502
aef911a5
DZ
2503 err = 0;
2504 break;
2505 case ZD_IOCTL_WPA:
2506 if (copy_from_user(&zdparm, ifr->ifr_data,
2507 sizeof(struct athr_wlan_param))) {
2508 printk(KERN_ERR "usbdrv : copy_from_user error\n");
2509 return -EFAULT;
2510 }
4bd43f50 2511
aef911a5
DZ
2512 usbdrv_wpa_ioctl(dev, &zdparm);
2513 err = 0;
2514 break;
2515 case ZD_IOCTL_PARAM: {
2516 int *p;
2517 int op;
2518 int arg;
2519
2520 /* Point to the name field and retrieve the
2521 * op and arg elements.
2522 */
2523 p = (int *)wrq->u.name;
2524 op = *p++;
2525 arg = *p;
2526
2527 if (op == ZD_PARAM_ROAMING) {
2528 printk(KERN_ERR
2529 "*************ZD_PARAM_ROAMING : % d\n", arg);
2530 /* macp->cardSetting.ap_scan=(U8)arg; */
2531 }
2532 if (op == ZD_PARAM_PRIVACY) {
2533 printk(KERN_ERR "ZD_IOCTL_PRIVACY : ");
2534
2535 /* Turn on the privacy invoke flag */
2536 if (arg) {
2537 /* mCap[0] |= CAP_PRIVACY; */
2538 /* macp->cardSetting.EncryOnOff[0] = 1; */
2539 printk(KERN_ERR "enable\n");
2540
2541 } else {
2542 /* mCap[0] &= ~CAP_PRIVACY; */
2543 /* macp->cardSetting.EncryOnOff[0] = 0; */
2544 printk(KERN_ERR "disable\n");
2545 }
2546 /* changed=1; */
2547 }
2548 if (op == ZD_PARAM_WPA) {
2549
2550 printk(KERN_ERR "ZD_PARAM_WPA : ");
2551
2552 if (arg) {
2553 printk(KERN_ERR "enable\n");
2554
2555 if (zfiWlanQueryWlanMode(dev) != ZM_MODE_AP) {
2556 printk(KERN_ERR "Station Mode\n");
2557 /* zfiWlanQueryWpaIe(dev, (u8_t *)
2558 &wpaIe, &wpalen); */
2559 /* printk("wpaIe : % 2x, % 2x, % 2x\n",
2560 wpaIe[21], wpaIe[22], wpaIe[23]); */
2561 /* printk("rsnIe : % 2x, % 2x, % 2x\n",
2562 wpaIe[17], wpaIe[18], wpaIe[19]); */
2563 if ((macp->supIe[21] == 0x50) &&
2564 (macp->supIe[22] == 0xf2) &&
2565 (macp->supIe[23] == 0x2)) {
2566 printk(KERN_ERR
2567 "wd->sta.authMode = ZM_AUTH_MODE_WPAPSK\n");
2568 /* wd->sta.authMode = ZM_AUTH_MODE_WPAPSK; */
2569 /* wd->ws.authMode = ZM_AUTH_MODE_WPAPSK; */
2570 zfiWlanSetAuthenticationMode(dev,
2571 ZM_AUTH_MODE_WPAPSK);
2572 } else if ((macp->supIe[21] == 0x50) &&
2573 (macp->supIe[22] == 0xf2) &&
2574 (macp->supIe[23] == 0x1)) {
2575 printk(KERN_ERR
2576 "wd->sta.authMode = ZM_AUTH_MODE_WPA\n");
2577 /* wd->sta.authMode = ZM_AUTH_MODE_WPA; */
2578 /* wd->ws.authMode = ZM_AUTH_MODE_WPA; */
2579 zfiWlanSetAuthenticationMode(dev,
2580 ZM_AUTH_MODE_WPA);
2581 } else if ((macp->supIe[17] == 0xf) &&
2582 (macp->supIe[18] == 0xac) &&
25b37eca 2583 (macp->supIe[19] == 0x2)) {
aef911a5
DZ
2584 printk(KERN_ERR
2585 "wd->sta.authMode = ZM_AUTH_MODE_WPA2PSK\n");
2586 /* wd->sta.authMode = ZM_AUTH_MODE_WPA2PSK; */
2587 /* wd->ws.authMode = ZM_AUTH_MODE_WPA2PSK; */
2588 zfiWlanSetAuthenticationMode(dev,
2589 ZM_AUTH_MODE_WPA2PSK);
2590 } else if ((macp->supIe[17] == 0xf) &&
2591 (macp->supIe[18] == 0xac) &&
25b37eca 2592 (macp->supIe[19] == 0x1)) {
aef911a5
DZ
2593 printk(KERN_ERR
2594 "wd->sta.authMode = ZM_AUTH_MODE_WPA2\n");
2595 /* wd->sta.authMode = ZM_AUTH_MODE_WPA2; */
2596 /* wd->ws.authMode = ZM_AUTH_MODE_WPA2; */
2597 zfiWlanSetAuthenticationMode(dev,
2598 ZM_AUTH_MODE_WPA2);
2599 }
2600 /* WPA or WPAPSK */
2601 if ((macp->supIe[21] == 0x50) ||
2602 (macp->supIe[22] == 0xf2)) {
2603 if (macp->supIe[11] == 0x2) {
2604 printk(KERN_ERR
2605 "wd->sta.wepStatus = ZM_ENCRYPTION_TKIP\n");
2606 /* wd->sta.wepStatus = ZM_ENCRYPTION_TKIP; */
2607 /* wd->ws.wepStatus = ZM_ENCRYPTION_TKIP; */
2608 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_TKIP);
2609 } else {
2610 printk(KERN_ERR
2611 "wd->sta.wepStatus = ZM_ENCRYPTION_AES\n");
2612 /* wd->sta.wepStatus = ZM_ENCRYPTION_AES; */
2613 /* wd->ws.wepStatus = ZM_ENCRYPTION_AES; */
2614 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_AES);
4bd43f50 2615 }
aef911a5 2616 }
25b37eca 2617 /*WPA2 or WPA2PSK*/
aef911a5
DZ
2618 if ((macp->supIe[17] == 0xf) ||
2619 (macp->supIe[18] == 0xac)) {
2620 if (macp->supIe[13] == 0x2) {
2621 printk(KERN_ERR
2622 "wd->sta.wepStatus = ZM_ENCRYPTION_TKIP\n");
2623 /* wd->sta.wepStatus = ZM_ENCRYPTION_TKIP; */
2624 /* wd->ws.wepStatus = ZM_ENCRYPTION_TKIP; */
2625 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_TKIP);
2626 } else {
2627 printk(KERN_ERR
2628 "wd->sta.wepStatus = ZM_ENCRYPTION_AES\n");
2629 /* wd->sta.wepStatus = ZM_ENCRYPTION_AES; */
2630 /* wd->ws.wepStatus = ZM_ENCRYPTION_AES; */
2631 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_AES);
4bd43f50
LR
2632 }
2633 }
4bd43f50 2634 }
aef911a5
DZ
2635 zfiWlanSetWpaSupport(dev, 1);
2636 } else {
2637 /* Reset the WPA related variables */
2638 printk(KERN_ERR "disable\n");
2639
2640 zfiWlanSetWpaSupport(dev, 0);
2641 zfiWlanSetAuthenticationMode(dev, ZM_AUTH_MODE_OPEN);
2642 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_WEP_DISABLED);
2643
2644 /* Now we only set the length in the WPA IE
2645 * field to zero.
2646 *macp->cardSetting.WPAIe[1] = 0;
2647 */
2648 }
2649 }
2650
2651 if (op == ZD_PARAM_COUNTERMEASURES) {
2652 printk(KERN_ERR
2653 "****************ZD_PARAM_COUNTERMEASURES : ");
2654
25b37eca 2655 if (arg) {
aef911a5
DZ
2656 /* mCounterMeasureState=1; */
2657 printk(KERN_ERR "enable\n");
2658 } else {
2659 /* mCounterMeasureState=0; */
2660 printk(KERN_ERR "disable\n");
2661 }
2662 }
2663 if (op == ZD_PARAM_DROPUNENCRYPTED) {
2664 printk(KERN_ERR "ZD_PARAM_DROPUNENCRYPTED : ");
2665
25b37eca 2666 if (arg)
aef911a5 2667 printk(KERN_ERR "enable\n");
25b37eca 2668 else
aef911a5 2669 printk(KERN_ERR "disable\n");
aef911a5
DZ
2670 }
2671 if (op == ZD_PARAM_AUTH_ALGS) {
2672 printk(KERN_ERR "ZD_PARAM_AUTH_ALGS : ");
2673
25b37eca 2674 if (arg == 0)
aef911a5 2675 printk(KERN_ERR "OPEN_SYSTEM\n");
25b37eca 2676 else
aef911a5 2677 printk(KERN_ERR "SHARED_KEY\n");
aef911a5
DZ
2678 }
2679 if (op == ZD_PARAM_WPS_FILTER) {
2680 printk(KERN_ERR "ZD_PARAM_WPS_FILTER : ");
2681
2682 if (arg) {
2683 /* mCounterMeasureState=1; */
2684 macp->forwardMgmt = 1;
2685 printk(KERN_ERR "enable\n");
2686 } else {
2687 /* mCounterMeasureState=0; */
2688 macp->forwardMgmt = 0;
2689 printk(KERN_ERR "disable\n");
2690 }
2691 }
2692 }
2693 err = 0;
2694 break;
2695 case ZD_IOCTL_GETWPAIE: {
2696 struct ieee80211req_wpaie req_wpaie;
2697 u16_t apId, i, j;
2698
2699 /* Get the AP Id */
2700 apId = zfLnxGetVapId(dev);
2701
25b37eca 2702 if (apId == 0xffff)
aef911a5 2703 apId = 0;
25b37eca 2704 else
aef911a5 2705 apId = apId + 1;
aef911a5
DZ
2706
2707 if (copy_from_user(&req_wpaie, ifr->ifr_data,
2708 sizeof(struct ieee80211req_wpaie))) {
2709 printk(KERN_ERR "usbdrv : copy_from_user error\n");
2710 return -EFAULT;
2711 }
2712
2713 for (i = 0; i < ZM_OAL_MAX_STA_SUPPORT; i++) {
2714 for (j = 0; j < IEEE80211_ADDR_LEN; j++) {
2715 if (macp->stawpaie[i].wpa_macaddr[j] !=
2716 req_wpaie.wpa_macaddr[j])
25b37eca 2717 break;
aef911a5
DZ
2718 }
2719 if (j == 6)
25b37eca 2720 break;
aef911a5 2721 }
4bd43f50 2722
aef911a5
DZ
2723 if (i < ZM_OAL_MAX_STA_SUPPORT) {
2724 /* printk("ZD_IOCTL_GETWPAIE - sta index = % d\n", i); */
2725 memcpy(req_wpaie.wpa_ie, macp->stawpaie[i].wpa_ie,
2726 IEEE80211_MAX_IE_SIZE);
2727 }
4bd43f50 2728
aef911a5
DZ
2729 if (copy_to_user(wrq->u.data.pointer, &req_wpaie,
2730 sizeof(struct ieee80211req_wpaie))) {
2731 return -EFAULT;
2732 }
2733 }
2734
2735 err = 0;
2736 break;
2737 #ifdef ZM_ENABLE_CENC
2738 case ZM_IOCTL_CENC:
2739 if (copy_from_user(&macp->zd_wpa_req, ifr->ifr_data,
2740 sizeof(struct athr_wlan_param))) {
2741 printk(KERN_ERR "usbdrv : copy_from_user error\n");
2742 return -EFAULT;
2743 }
2744
2745 usbdrv_cenc_ioctl(dev,
2746 (struct zydas_cenc_param *)&macp->zd_wpa_req);
2747 err = 0;
2748 break;
2749 #endif /* ZM_ENABLE_CENC */
2750 default:
2751 err = -EOPNOTSUPP;
2752 break;
2753 }
2754
2755 return err;
4bd43f50 2756}