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