Merge branch 'fix/oss-header-fix' into for-linus
[linux-2.6/mini2440.git] / drivers / staging / otus / ioctl.c
blob7a5c1e876b01c9e923d695541f1763f712e76ec6
1 /*
2 * Copyright (c) 2007-2008 Atheros Communications Inc.
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.
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.
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>
30 #include "usbdrv.h"
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
46 #ifdef ZM_ENABLE_CENC
47 #define P80211_PACKET_CENCFLAG 0x0001
48 #endif //ZM_ENABLE_CENC
49 #define P80211_PACKET_SETKEY 0x0003
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
57 #define ZD_CRYPT_ALG_NAME_LEN 16
58 #define ZD_MAX_KEY_SIZE 32
59 #define ZD_MAX_GENERIC_SIZE 64
61 #if WIRELESS_EXT > 12
62 #include <net/iw_handler.h>
63 #endif
65 extern u16_t zfLnxGetVapId(zdev_t* dev);
67 static const u32_t channel_frequency_11A[] =
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,
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,
102 149,5745,
103 153,5765,
104 157,5785,
105 161,5805,
106 165,5825
110 int usbdrv_freq2chan(u32_t freq)
112 /* 2.4G Hz */
113 if (freq > 2400 && freq < 3000)
115 return ((freq-2412)/5) + 1;
117 else
119 u16_t ii;
120 u16_t num_chan = sizeof(channel_frequency_11A)/sizeof(u32_t);
122 for(ii = 1; ii < num_chan; ii += 2)
124 if (channel_frequency_11A[ii] == freq)
125 return channel_frequency_11A[ii-1];
129 return 0;
132 int usbdrv_chan2freq(int chan)
134 int freq;
136 /* If channel number is out of range */
137 if (chan > 165 || chan <= 0)
138 return -1;
140 /* 2.4G band */
141 if (chan >= 1 && chan <= 13)
143 freq = (2412 + (chan - 1) * 5);
144 return freq;
146 else if (chan >= 36 && chan <= 165)
148 u16_t ii;
149 u16_t num_chan = sizeof(channel_frequency_11A)/sizeof(u32_t);
151 for(ii = 0; ii < num_chan; ii += 2)
153 if (channel_frequency_11A[ii] == chan)
154 return channel_frequency_11A[ii+1];
157 /* Can't find desired frequency */
158 if (ii == num_chan)
159 return -1;
162 /* Can't find deisred frequency */
163 return -1;
166 int usbdrv_ioctl_setessid(struct net_device *dev, struct iw_point *erq)
168 #ifdef ZM_HOSTAPD_SUPPORT
169 //struct usbdrv_private *macp = dev->ml_priv;
170 char essidbuf[IW_ESSID_MAX_SIZE+1];
171 int i;
173 if(!netif_running(dev))
174 return -EINVAL;
176 memset(essidbuf, 0, sizeof(essidbuf));
178 printk(KERN_ERR "usbdrv_ioctl_setessid\n");
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;
185 if (copy_from_user(essidbuf, erq->pointer, erq->length))
186 return -EFAULT;
189 //zd_DisasocAll(2);
190 //wait_ms(100);
192 printk(KERN_ERR "essidbuf: ");
194 for(i = 0; i < erq->length; i++)
196 printk(KERN_ERR "%02x ", essidbuf[i]);
199 printk(KERN_ERR "\n");
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
206 zfiWlanSetSSID(dev, essidbuf, erq->length);
207 #if 0
208 printk(KERN_ERR "macp->wd.ws.ssid: ");
210 for(i = 0; i < macp->wd.ws.ssidLen; i++)
212 printk(KERN_ERR "%02x ", macp->wd.ws.ssid[i]);
215 printk(KERN_ERR "\n");
216 #endif
217 zfiWlanDisable(dev, 0);
218 zfiWlanEnable(dev);
220 #endif
222 return 0;
225 int usbdrv_ioctl_getessid(struct net_device *dev, struct iw_point *erq)
227 //struct usbdrv_private *macp = dev->ml_priv;
228 u8_t essidbuf[IW_ESSID_MAX_SIZE+1];
229 u8_t len;
230 u8_t i;
233 //len = macp->wd.ws.ssidLen;
234 //memcpy(essidbuf, macp->wd.ws.ssid, macp->wd.ws.ssidLen);
235 zfiWlanQuerySSID(dev, essidbuf, &len);
237 essidbuf[len] = 0;
239 printk(KERN_ERR "ESSID: ");
241 for(i = 0; i < len; i++)
243 printk(KERN_ERR "%c", essidbuf[i]);
246 printk(KERN_ERR "\n");
248 erq->flags= 1;
249 erq->length = strlen(essidbuf) + 1;
251 if (erq->pointer)
252 if (copy_to_user(erq->pointer, essidbuf, erq->length))
253 return -EFAULT;
255 return 0;
259 int usbdrv_ioctl_setrts(struct net_device *dev, struct iw_param *rrq)
262 return 0;
265 #if WIRELESS_EXT > 14
267 * Encode a WPA or RSN information element as a custom
268 * element using the hostap format.
270 u32 encode_ie(void *buf, u32 bufsize, const u8 *ie, u32 ielen, const u8 *leader, u32 leader_len)
272 u8 *p;
273 u32 i;
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);
285 #endif /* WIRELESS_EXT > 14 */
287 /*------------------------------------------------------------------*/
289 * Translate scan data returned from the card to a card independent
290 * format that the Wireless Tools will understand
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)
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
305 last_ev = current_ev;
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 info,
313 current_ev,
314 end_buf, &iwe, IW_EV_ADDR_LEN);
316 /* Ran out of buffer */
317 if (last_ev == current_ev)
319 return end_buf;
322 last_ev = current_ev;
324 /* Other entries will be displayed in the order we give them */
326 /* Add the ESSID */
327 iwe.u.data.length = list->ssid[1];
328 if(iwe.u.data.length > 32)
329 iwe.u.data.length = 32;
330 iwe.cmd = SIOCGIWESSID;
331 iwe.u.data.flags = 1;
332 current_ev = iwe_stream_add_point(
333 info,
334 current_ev, end_buf, &iwe, &list->ssid[2]);
336 /* Ran out of buffer */
337 if (last_ev == current_ev)
339 return end_buf;
342 last_ev = current_ev;
344 /* Add mode */
345 iwe.cmd = SIOCGIWMODE;
346 capabilities = (list->capability[1] << 8) + list->capability[0];
347 if(capabilities & (0x01 | 0x02))
349 if(capabilities & 0x01)
350 iwe.u.mode = IW_MODE_MASTER;
351 else
352 iwe.u.mode = IW_MODE_ADHOC;
353 current_ev = iwe_stream_add_event(
354 info,
355 current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
358 /* Ran out of buffer */
359 if (last_ev == current_ev)
361 return end_buf;
364 last_ev = current_ev;
366 /* Add frequency */
367 iwe.cmd = SIOCGIWFREQ;
368 iwe.u.freq.m = list->channel;
369 /* Channel frequency in KHz */
370 if (iwe.u.freq.m > 14)
372 if ((184 <= iwe.u.freq.m) && (iwe.u.freq.m<=196))
373 iwe.u.freq.m = 4000 + iwe.u.freq.m * 5;
374 else
375 iwe.u.freq.m = 5000 + iwe.u.freq.m * 5;
377 else
379 if (iwe.u.freq.m == 14)
380 iwe.u.freq.m = 2484;
381 else
382 iwe.u.freq.m = 2412 + (iwe.u.freq.m - 1) * 5;
384 iwe.u.freq.e = 6;
385 current_ev = iwe_stream_add_event(
386 info,
387 current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
389 /* Ran out of buffer */
390 if (last_ev == current_ev)
392 return end_buf;
395 last_ev = current_ev;
397 /* Add quality statistics */
398 iwe.cmd = IWEVQUAL;
399 #if WIRELESS_EXT > 18
400 iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED
401 |IW_QUAL_NOISE_UPDATED;
402 #endif
403 iwe.u.qual.level = list->signalStrength;
404 iwe.u.qual.noise = 0;
405 iwe.u.qual.qual = list->signalQuality;
406 current_ev = iwe_stream_add_event(
407 info,
408 current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
410 /* Ran out of buffer */
411 if (last_ev == current_ev)
413 return end_buf;
416 last_ev = current_ev;
418 /* Add encryption capability */
420 iwe.cmd = SIOCGIWENCODE;
421 if(capabilities & 0x10)
422 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
423 else
424 iwe.u.data.flags = IW_ENCODE_DISABLED;
426 iwe.u.data.length = 0;
427 current_ev = iwe_stream_add_point(
428 info,
429 current_ev, end_buf, &iwe, list->ssid);
431 /* Ran out of buffer */
432 if (last_ev == current_ev)
434 return end_buf;
437 last_ev = current_ev;
439 /* Rate : stuffing multiple values in a single event require a bit
440 * more of magic */
441 current_val = current_ev + IW_EV_LCP_LEN;
443 iwe.cmd = SIOCGIWRATE;
444 /* Those two flags are ignored... */
445 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
447 for(i = 0 ; i < list->supportedRates[1] ; i++)
449 /* Bit rate given in 500 kb/s units (+ 0x80) */
450 iwe.u.bitrate.value = ((list->supportedRates[i+2] & 0x7f) * 500000);
451 /* Add new value to event */
452 current_val = iwe_stream_add_value(
453 info,
454 current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
456 /* Ran out of buffer */
457 if (last_ev == current_val)
459 return end_buf;
462 last_ev = current_val;
465 for (i = 0 ; i < list->extSupportedRates[1] ; i++)
467 /* Bit rate given in 500 kb/s units (+ 0x80) */
468 iwe.u.bitrate.value = ((list->extSupportedRates[i+2] & 0x7f) * 500000);
469 /* Add new value to event */
470 current_val = iwe_stream_add_value(
471 info,
472 current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
474 /* Ran out of buffer */
475 if (last_ev == current_val)
477 return end_buf;
480 last_ev = current_ev;
483 /* Check if we added any event */
484 if((current_val - current_ev) > IW_EV_LCP_LEN)
485 current_ev = current_val;
486 #if WIRELESS_EXT > 14
487 #define IEEE80211_ELEMID_RSN 0x30
488 memset(&iwe, 0, sizeof(iwe));
489 iwe.cmd = IWEVCUSTOM;
490 snprintf(buf, sizeof(buf), "bcn_int=%d", (list->beaconInterval[1] << 8) + list->beaconInterval[0]);
491 iwe.u.data.length = strlen(buf);
492 current_ev = iwe_stream_add_point(
493 info,
494 current_ev, end_buf, &iwe, buf);
496 /* Ran out of buffer */
497 if (last_ev == current_ev)
499 return end_buf;
502 last_ev = current_ev;
504 if (list->wpaIe[1] != 0)
506 static const char rsn_leader[] = "rsn_ie=";
507 static const char wpa_leader[] = "wpa_ie=";
509 memset(&iwe, 0, sizeof(iwe));
510 iwe.cmd = IWEVCUSTOM;
511 if (list->wpaIe[0] == IEEE80211_ELEMID_RSN)
512 iwe.u.data.length = encode_ie(buf, sizeof(buf),
513 list->wpaIe, list->wpaIe[1]+2,
514 rsn_leader, sizeof(rsn_leader)-1);
515 else
516 iwe.u.data.length = encode_ie(buf, sizeof(buf),
517 list->wpaIe, list->wpaIe[1]+2,
518 wpa_leader, sizeof(wpa_leader)-1);
520 if (iwe.u.data.length != 0)
521 current_ev = iwe_stream_add_point(
522 info,
523 current_ev, end_buf, &iwe, buf);
525 /* Ran out of buffer */
526 if (last_ev == current_ev)
528 return end_buf;
531 last_ev = current_ev;
533 if (list->rsnIe[1] != 0)
535 static const char rsn_leader[] = "rsn_ie=";
536 memset(&iwe, 0, sizeof(iwe));
537 iwe.cmd = IWEVCUSTOM;
539 if (list->rsnIe[0] == IEEE80211_ELEMID_RSN)
541 iwe.u.data.length = encode_ie(buf, sizeof(buf),
542 list->rsnIe, list->rsnIe[1]+2,
543 rsn_leader, sizeof(rsn_leader)-1);
544 if (iwe.u.data.length != 0)
545 current_ev = iwe_stream_add_point(
546 info,
547 current_ev, end_buf, &iwe, buf);
549 /* Ran out of buffer */
550 if (last_ev == current_ev)
552 return end_buf;
555 last_ev = current_ev;
558 #endif
559 /* The other data in the scan result are not really
560 * interesting, so for now drop it */
561 return current_ev;
564 int usbdrvwext_giwname(struct net_device *dev,
565 struct iw_request_info *info,
566 union iwreq_data *wrq, char *extra)
568 //struct usbdrv_private *macp = dev->ml_priv;
570 strcpy(wrq->name, "IEEE 802.11-MIMO");
572 return 0;
575 int usbdrvwext_siwfreq(struct net_device *dev,
576 struct iw_request_info *info,
577 struct iw_freq *freq, char *extra)
579 u32_t FreqKHz;
580 struct usbdrv_private *macp = dev->ml_priv;
582 if(!netif_running(dev))
583 return -EINVAL;
585 if (freq->e > 1)
586 return -EINVAL;
588 if (freq->e == 1)
590 FreqKHz = (freq->m / 100000);
592 if (FreqKHz > 4000000)
594 if (FreqKHz > 5825000)
595 FreqKHz = 5825000;
596 else if (FreqKHz < 4920000)
597 FreqKHz = 4920000;
598 else if (FreqKHz < 5000000)
599 FreqKHz = (((FreqKHz - 4000000) / 5000) * 5000) + 4000000;
600 else
601 FreqKHz = (((FreqKHz - 5000000) / 5000) * 5000) + 5000000;
603 else
605 if (FreqKHz > 2484000)
606 FreqKHz = 2484000;
607 else if (FreqKHz < 2412000)
608 FreqKHz = 2412000;
609 else
610 FreqKHz = (((FreqKHz - 2412000) / 5000) * 5000) + 2412000;
614 else
616 FreqKHz = usbdrv_chan2freq(freq->m);
618 if (FreqKHz != -1)
619 FreqKHz *= 1000;
620 else
621 FreqKHz = 2412000;
624 //printk("freq->m: %d, freq->e: %d\n", freq->m, freq->e);
625 //printk("FreqKHz: %d\n", FreqKHz);
627 if (macp->DeviceOpened == 1)
629 zfiWlanSetFrequency(dev, FreqKHz, 0); // Immediate
630 //u8_t wpaieLen,wpaie[50];
631 //zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen);
632 zfiWlanDisable(dev, 0);
633 zfiWlanEnable(dev);
634 //if (wpaieLen > 2)
635 // zfiWlanSetWpaIe(dev, wpaie, wpaieLen);
638 return 0;
641 int usbdrvwext_giwfreq(struct net_device *dev,
642 struct iw_request_info *info,
643 struct iw_freq *freq, char *extra)
645 struct usbdrv_private *macp = dev->ml_priv;
647 if (macp->DeviceOpened != 1)
648 return 0;
650 freq->m = zfiWlanQueryFrequency(dev);
651 freq->e = 3;
653 return 0;
656 int usbdrvwext_siwmode(struct net_device *dev,
657 struct iw_request_info *info,
658 union iwreq_data *wrq, char *extra)
660 struct usbdrv_private *macp = dev->ml_priv;
661 u8_t WlanMode;
663 if(!netif_running(dev))
664 return -EINVAL;
666 if (macp->DeviceOpened != 1)
667 return 0;
669 switch(wrq->mode)
671 case IW_MODE_MASTER:
672 WlanMode = ZM_MODE_AP;
673 break;
674 case IW_MODE_INFRA:
675 WlanMode = ZM_MODE_INFRASTRUCTURE;
676 break;
677 case IW_MODE_ADHOC:
678 WlanMode = ZM_MODE_IBSS;
679 break;
680 default:
681 WlanMode = ZM_MODE_IBSS;
682 break;
685 zfiWlanSetWlanMode(dev,WlanMode);
686 zfiWlanDisable(dev, 1);
687 zfiWlanEnable(dev);
689 return 0;
692 int usbdrvwext_giwmode(struct net_device *dev,
693 struct iw_request_info *info,
694 __u32 *mode, char *extra)
696 unsigned long irqFlag;
697 struct usbdrv_private *macp = dev->ml_priv;
699 if(!netif_running(dev))
700 return -EINVAL;
702 if (macp->DeviceOpened != 1)
703 return 0;
705 spin_lock_irqsave(&macp->cs_lock, irqFlag);
707 switch(zfiWlanQueryWlanMode(dev))
709 case ZM_MODE_AP:
710 *mode = IW_MODE_MASTER;
711 break;
712 case ZM_MODE_INFRASTRUCTURE:
713 *mode = IW_MODE_INFRA;
714 break;
715 case ZM_MODE_IBSS:
716 *mode = IW_MODE_ADHOC;
717 break;
718 default:
719 *mode = IW_MODE_ADHOC;
720 break;
723 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
725 return 0;
728 int usbdrvwext_siwsens(struct net_device *dev,
729 struct iw_request_info *info,
730 struct iw_param *sens, char *extra)
732 return 0;
735 int usbdrvwext_giwsens(struct net_device *dev,
736 struct iw_request_info *info,
737 struct iw_param *sens, char *extra)
739 sens->value = 0;
740 sens->fixed = 1;
742 return 0;
745 int usbdrvwext_giwrange(struct net_device *dev,
746 struct iw_request_info *info,
747 struct iw_point *data, char *extra)
749 struct iw_range *range = (struct iw_range *) extra;
750 int i, val;
751 //int num_band_a;
752 u16_t channels[60];
753 u16_t channel_num;
755 if(!netif_running(dev))
756 return -EINVAL;
758 #if WIRELESS_EXT > 9
759 range->txpower_capa = IW_TXPOW_DBM;
760 // XXX what about min/max_pmp, min/max_pmt, etc.
761 #endif
763 #if WIRELESS_EXT > 10
764 range->we_version_compiled = WIRELESS_EXT;
765 range->we_version_source = 13;
767 range->retry_capa = IW_RETRY_LIMIT;
768 range->retry_flags = IW_RETRY_LIMIT;
769 range->min_retry = 0;
770 range->max_retry = 255;
771 #endif /* WIRELESS_EXT > 10 */
773 channel_num = zfiWlanQueryAllowChannels(dev, channels);
775 /* Gurantee reported channel numbers is less or equal to IW_MAX_FREQUENCIES */
776 if (channel_num > IW_MAX_FREQUENCIES)
777 channel_num = IW_MAX_FREQUENCIES;
779 val = 0;
781 for (i = 0; i < channel_num; i++)
783 range->freq[val].i = usbdrv_freq2chan(channels[i]);
784 range->freq[val].m = channels[i];
785 range->freq[val].e = 6;
786 val++;
789 range->num_channels = channel_num;
790 range->num_frequency = channel_num;
792 #if 0
793 range->num_channels = 14; // Only 2.4G
795 /* XXX need to filter against the regulatory domain &| active set */
796 val = 0;
797 for (i = 1; i <= 14; i++) // B,G Bands
799 range->freq[val].i = i;
800 if (i == 14)
801 range->freq[val].m = 2484000;
802 else
803 range->freq[val].m = (2412+(i-1)*5)*1000;
804 range->freq[val].e = 3;
805 val++;
808 num_band_a = (IW_MAX_FREQUENCIES - val);
810 for (i = 0; i < num_band_a; i++) // A Bands
812 range->freq[val].i = channel_frequency_11A[2 * i];
813 range->freq[val].m = channel_frequency_11A[2 * i + 1] * 1000;
814 range->freq[val].e = 3;
815 val++;
817 // MIMO Rate Not Defined Now
818 //For 802.11a, there are too more frequency. We can't return them all
819 range->num_frequency = val;
820 #endif
822 /* Max of /proc/net/wireless */
823 range->max_qual.qual = 100; //?? //92;
824 range->max_qual.level = 154; //??
825 range->max_qual.noise = 154; //??
826 range->sensitivity = 3; //??
828 // XXX these need to be nsd-specific!
829 range->min_rts = 0;
830 range->max_rts = 2347;
831 range->min_frag = 256;
832 range->max_frag = 2346;
833 range->max_encoding_tokens = 4/*NUM_WEPKEYS*/; //??
834 range->num_encoding_sizes = 2; //??
836 range->encoding_size[0] = 5; //?? //WEP Key Encoding Size
837 range->encoding_size[1] = 13;//??
839 // XXX what about num_bitrates/throughput?
840 range->num_bitrates = 0; //??
842 /* estimated max throughput */
843 // XXX need to cap it if we're running at ~2Mbps..
845 range->throughput = 300000000;
847 return 0;
850 int usbdrvwext_siwap(struct net_device *dev, struct iw_request_info *info,
851 struct sockaddr *MacAddr, char *extra)
853 struct usbdrv_private *macp = dev->ml_priv;
855 if(!netif_running(dev))
856 return -EINVAL;
858 if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) // AP Mode
859 zfiWlanSetMacAddress(dev,(u16_t *)&MacAddr->sa_data[0]);
860 else //STA Mode
861 zfiWlanSetBssid(dev,&MacAddr->sa_data[0]);
863 if (macp->DeviceOpened == 1)
865 //u8_t wpaieLen,wpaie[80];
866 //zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen);
867 zfiWlanDisable(dev, 0);
868 zfiWlanEnable(dev);
869 //if (wpaieLen > 2)
870 // zfiWlanSetWpaIe(dev, wpaie, wpaieLen);
873 return 0;
876 int usbdrvwext_giwap(struct net_device *dev,
877 struct iw_request_info *info,
878 struct sockaddr *MacAddr, char *extra)
880 struct usbdrv_private *macp = dev->ml_priv;
882 if (macp->DeviceOpened != 1)
883 return 0;
885 if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) // AP Mode
886 zfiWlanQueryMacAddress(dev, &MacAddr->sa_data[0]);
887 else //STA Mode
889 if (macp->adapterState == ZM_STATUS_MEDIA_CONNECT)
891 zfiWlanQueryBssid(dev, &MacAddr->sa_data[0]);
893 else
895 u8_t zero_addr[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
896 memcpy(&MacAddr->sa_data[0], zero_addr, sizeof(zero_addr));
900 return 0;
903 int usbdrvwext_iwaplist(struct net_device *dev,
904 struct iw_request_info *info,
905 struct iw_point *data, char *extra)
907 //Don't know how to do yet--CWYang(+)
908 return 0;
912 int usbdrvwext_siwscan(struct net_device *dev, struct iw_request_info *info,
913 struct iw_point *data, char *extra)
915 struct usbdrv_private *macp = dev->ml_priv;
917 if (macp->DeviceOpened != 1)
918 return 0;
920 printk("CWY - usbdrvwext_siwscan\n");
922 zfiWlanScan(dev);
924 return 0;
927 int usbdrvwext_giwscan(struct net_device *dev,
928 struct iw_request_info *info,
929 struct iw_point *data, char *extra)
931 struct usbdrv_private *macp = dev->ml_priv;
932 //struct zsWlanDev* wd = (struct zsWlanDev*) zmw_wlan_dev(dev);
933 char *current_ev = extra;
934 char *end_buf;
935 int i;
936 //struct zsBssList BssList;
937 struct zsBssListV1 *pBssList = kmalloc(sizeof(struct zsBssListV1), GFP_KERNEL);
938 //BssList = wd->sta.pBssList;
939 //zmw_get_wlan_dev(dev);
941 if (macp->DeviceOpened != 1)
942 return 0;
944 if (data->length == 0)
946 end_buf = extra + IW_SCAN_MAX_DATA;
948 else
950 end_buf = extra + data->length;
953 printk("giwscan - Report Scan Results\n");
954 //printk("giwscan - BssList Sreucture Len : %d\n", sizeof(BssList));
955 //printk("giwscan - BssList Count : %d\n", wd->sta.pBssList->bssCount);
956 //printk("giwscan - UpdateBssList Count : %d\n", wd->sta.pUpdateBssList->bssCount);
957 zfiWlanQueryBssListV1(dev, pBssList);
958 //zfiWlanQueryBssList(dev, &BssList);
960 /* Read and parse all entries */
961 printk("giwscan - pBssList->bssCount : %d\n", pBssList->bssCount);
962 //printk("giwscan - BssList.bssCount : %d\n", BssList.bssCount);
964 for (i = 0; i < pBssList->bssCount; i++)
966 /* Translate to WE format this entry */
967 //current_ev = usbdrv_translate_scan(dev, info, current_ev,
968 // extra + IW_SCAN_MAX_DATA, &pBssList->bssInfo[i]);
969 current_ev = usbdrv_translate_scan(dev, info, current_ev,
970 end_buf, &pBssList->bssInfo[i]);
972 #if WIRELESS_EXT > 16
973 if (current_ev == end_buf)
975 kfree(pBssList);
976 data->length = current_ev - extra;
977 return -E2BIG;
979 #endif
982 /* Length of data */
983 data->length = (current_ev - extra);
984 data->flags = 0; /* todo */
986 kfree(pBssList);
988 return 0;
991 int usbdrvwext_siwessid(struct net_device *dev,
992 struct iw_request_info *info,
993 struct iw_point *essid, char *extra)
995 char EssidBuf[IW_ESSID_MAX_SIZE+1];
996 struct usbdrv_private *macp = dev->ml_priv;
998 if(!netif_running(dev))
999 return -EINVAL;
1001 if (essid->flags == 1)
1003 if (essid->length > (IW_ESSID_MAX_SIZE+1))
1004 return -E2BIG;
1006 if (copy_from_user(&EssidBuf, essid->pointer, essid->length))
1007 return -EFAULT;
1009 EssidBuf[essid->length] = '\0';
1010 //printk("siwessid - Set Essid : %s\n",EssidBuf);
1011 //printk("siwessid - Essid Len : %d\n",essid->length);
1012 //printk("siwessid - Essid Flag : %x\n",essid->flags);
1013 if (macp->DeviceOpened == 1)
1015 zfiWlanSetSSID(dev, EssidBuf, strlen(EssidBuf));
1016 zfiWlanSetFrequency(dev, zfiWlanQueryFrequency(dev), FALSE);
1017 zfiWlanSetEncryMode(dev, zfiWlanQueryEncryMode(dev));
1018 //u8_t wpaieLen,wpaie[50];
1019 //zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen);
1020 zfiWlanDisable(dev, 0);
1021 zfiWlanEnable(dev);
1022 //if (wpaieLen > 2)
1023 // zfiWlanSetWpaIe(dev, wpaie, wpaieLen);
1027 return 0;
1030 int usbdrvwext_giwessid(struct net_device *dev,
1031 struct iw_request_info *info,
1032 struct iw_point *essid, char *extra)
1034 struct usbdrv_private *macp = dev->ml_priv;
1035 u8_t EssidLen;
1036 char EssidBuf[IW_ESSID_MAX_SIZE+1];
1037 int ssid_len;
1039 if(!netif_running(dev))
1040 return -EINVAL;
1042 if (macp->DeviceOpened != 1)
1043 return 0;
1045 zfiWlanQuerySSID(dev, &EssidBuf[0], &EssidLen);
1047 /* Convert type from unsigned char to char */
1048 ssid_len = (int)EssidLen;
1050 /* Make sure the essid length is not greater than IW_ESSID_MAX_SIZE */
1051 if (ssid_len > IW_ESSID_MAX_SIZE)
1052 ssid_len = IW_ESSID_MAX_SIZE;
1054 EssidBuf[ssid_len] = '\0';
1056 essid->flags = 1;
1057 essid->length = strlen(EssidBuf);
1059 memcpy(extra, EssidBuf, essid->length);
1060 // wireless.c in Kernel would handle copy_to_user -- line 679
1061 /*if (essid->pointer)
1063 if ( copy_to_user(essid->pointer, EssidBuf, essid->length) )
1065 printk("giwessid - copy_to_user Fail\n");
1066 return -EFAULT;
1070 return 0;
1073 int usbdrvwext_siwnickn(struct net_device *dev,
1074 struct iw_request_info *info,
1075 struct iw_point *data, char *nickname)
1077 //Exist but junk--CWYang(+)
1078 return 0;
1081 int usbdrvwext_giwnickn(struct net_device *dev,
1082 struct iw_request_info *info,
1083 struct iw_point *data, char *nickname)
1085 struct usbdrv_private *macp = dev->ml_priv;
1086 u8_t EssidLen;
1087 char EssidBuf[IW_ESSID_MAX_SIZE+1];
1089 if (macp->DeviceOpened != 1)
1090 return 0;
1092 zfiWlanQuerySSID(dev, &EssidBuf[0], &EssidLen);
1093 EssidBuf[EssidLen] = 0;
1095 data->flags = 1;
1096 data->length = strlen(EssidBuf);
1098 memcpy(nickname, EssidBuf, data->length);
1100 return 0;
1103 int usbdrvwext_siwrate(struct net_device *dev,
1104 struct iw_request_info *info,
1105 struct iw_param *frq, char *extra)
1107 struct usbdrv_private *macp = dev->ml_priv;
1108 //Array to Define Rate Number that Send to Driver
1109 u16_t zcIndextoRateBG[16] = {1000, 2000, 5500, 11000, 0, 0, 0, 0, 48000,
1110 24000, 12000, 6000, 54000, 36000, 18000, 9000};
1111 u16_t zcRateToMCS[] = {0xff, 0, 1, 2, 3, 0xb, 0xf, 0xa, 0xe, 0x9, 0xd,
1112 0x8, 0xc};
1113 u8_t i,RateIndex = 4;
1114 u16_t RateKbps;
1116 //printk("frq->disabled : 0x%x\n",frq->disabled);
1117 //printk("frq->value : 0x%x\n",frq->value);
1119 RateKbps = frq->value / 1000;
1120 //printk("RateKbps : %d\n", RateKbps);
1121 for (i = 0; i < 16; i++)
1123 if (RateKbps == zcIndextoRateBG[i])
1124 RateIndex = i;
1126 if (zcIndextoRateBG[RateIndex] == 0)
1127 RateIndex = 0xff;
1128 //printk("RateIndex : %x\n", RateIndex);
1129 for (i = 0; i < 13; i++)
1130 if (RateIndex == zcRateToMCS[i])
1131 break;
1132 //printk("Index : %x\n", i);
1133 if (RateKbps == 65000)
1135 RateIndex = 20;
1136 printk("RateIndex : %d\n", RateIndex);
1138 if (macp->DeviceOpened == 1)
1140 zfiWlanSetTxRate(dev, i);
1141 //zfiWlanDisable(dev);
1142 //zfiWlanEnable(dev);
1145 return 0;
1148 int usbdrvwext_giwrate(struct net_device *dev,
1149 struct iw_request_info *info,
1150 struct iw_param *frq, char *extra)
1152 struct usbdrv_private *macp = dev->ml_priv;
1154 if(!netif_running(dev))
1155 return -EINVAL;
1157 if (macp->DeviceOpened != 1)
1158 return 0;
1160 frq->fixed = 0;
1161 frq->disabled = 0;
1162 frq->value = zfiWlanQueryRxRate(dev) * 1000;
1164 return 0;
1167 int usbdrvwext_siwrts(struct net_device *dev,
1168 struct iw_request_info *info,
1169 struct iw_param *rts, char *extra)
1171 struct usbdrv_private *macp = dev->ml_priv;
1172 int val = rts->value;
1174 if (macp->DeviceOpened != 1)
1175 return 0;
1177 if (rts->disabled)
1178 val = 2347;
1180 if ((val < 0) || (val > 2347))
1181 return -EINVAL;
1183 zfiWlanSetRtsThreshold(dev,val);
1185 return 0;
1188 int usbdrvwext_giwrts(struct net_device *dev,
1189 struct iw_request_info *info,
1190 struct iw_param *rts, char *extra)
1192 struct usbdrv_private *macp = dev->ml_priv;
1194 if(!netif_running(dev))
1195 return -EINVAL;
1197 if (macp->DeviceOpened != 1)
1198 return 0;
1200 rts->value = zfiWlanQueryRtsThreshold(dev);
1201 rts->disabled = (rts->value >= 2347);
1202 rts->fixed = 1;
1204 return 0;
1208 int usbdrvwext_siwfrag(struct net_device *dev,
1209 struct iw_request_info *info,
1210 struct iw_param *frag, char *extra)
1212 struct usbdrv_private *macp = dev->ml_priv;
1213 u16_t fragThreshold;
1215 if (macp->DeviceOpened != 1)
1216 return 0;
1218 if (frag->disabled)
1219 fragThreshold = 0;
1220 else
1221 fragThreshold = frag->value;
1223 zfiWlanSetFragThreshold(dev,fragThreshold);
1225 return 0;
1228 int usbdrvwext_giwfrag(struct net_device *dev,
1229 struct iw_request_info *info,
1230 struct iw_param *frag, char *extra)
1232 struct usbdrv_private *macp = dev->ml_priv;
1233 u16 val;
1234 unsigned long irqFlag;
1236 if(!netif_running(dev))
1237 return -EINVAL;
1239 if (macp->DeviceOpened != 1)
1240 return 0;
1242 spin_lock_irqsave(&macp->cs_lock, irqFlag);
1244 val = zfiWlanQueryFragThreshold(dev);
1246 frag->value = val;
1248 frag->disabled = (val >= 2346);
1249 frag->fixed = 1;
1251 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
1253 return 0;
1256 int usbdrvwext_siwtxpow(struct net_device *dev,
1257 struct iw_request_info *info,
1258 struct iw_param *rrq, char *extra)
1260 //Not support yet--CWYng(+)
1261 return 0;
1264 int usbdrvwext_giwtxpow(struct net_device *dev,
1265 struct iw_request_info *info,
1266 struct iw_param *rrq, char *extra)
1268 //Not support yet--CWYng(+)
1269 return 0;
1272 int usbdrvwext_siwretry(struct net_device *dev,
1273 struct iw_request_info *info,
1274 struct iw_param *rrq, char *extra)
1276 //Do nothing--CWYang(+)
1277 return 0;
1280 int usbdrvwext_giwretry(struct net_device *dev,
1281 struct iw_request_info *info,
1282 struct iw_param *rrq, char *extra)
1284 //Do nothing--CWYang(+)
1285 return 0;
1288 int usbdrvwext_siwencode(struct net_device *dev,
1289 struct iw_request_info *info,
1290 struct iw_point *erq, char *key)
1292 struct zsKeyInfo keyInfo;
1293 int i, WepState = ZM_ENCRYPTION_WEP_DISABLED;
1294 struct usbdrv_private *macp = dev->ml_priv;
1296 if(!netif_running(dev))
1297 return -EINVAL;
1299 if ((erq->flags & IW_ENCODE_DISABLED) == 0)
1301 keyInfo.key = key;
1302 keyInfo.keyLength = erq->length;
1303 keyInfo.keyIndex = (erq->flags & IW_ENCODE_INDEX) - 1;
1304 if (keyInfo.keyIndex >= 4)
1305 keyInfo.keyIndex = 0;
1306 keyInfo.flag = ZM_KEY_FLAG_DEFAULT_KEY;
1308 zfiWlanSetKey(dev, keyInfo);
1309 WepState = ZM_ENCRYPTION_WEP_ENABLED;
1311 else
1313 for (i = 1; i < 4; i++)
1314 zfiWlanRemoveKey(dev, 0, i);
1315 WepState = ZM_ENCRYPTION_WEP_DISABLED;
1316 //zfiWlanSetEncryMode(dev, ZM_NO_WEP);
1319 if (macp->DeviceOpened == 1)
1321 zfiWlanSetWepStatus(dev, WepState);
1322 zfiWlanSetFrequency(dev, zfiWlanQueryFrequency(dev), FALSE);
1323 //zfiWlanSetEncryMode(dev, zfiWlanQueryEncryMode(dev));
1324 //u8_t wpaieLen,wpaie[50];
1325 //zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen);
1326 zfiWlanDisable(dev, 0);
1327 zfiWlanEnable(dev);
1328 //if (wpaieLen > 2)
1329 // zfiWlanSetWpaIe(dev, wpaie, wpaieLen);
1332 return 0;
1335 int usbdrvwext_giwencode(struct net_device *dev,
1336 struct iw_request_info *info,
1337 struct iw_point *erq, char *key)
1339 struct usbdrv_private *macp = dev->ml_priv;
1340 u8_t EncryptionMode;
1341 u8_t keyLen = 0;
1343 if (macp->DeviceOpened != 1)
1344 return 0;
1346 EncryptionMode = zfiWlanQueryEncryMode(dev);
1348 if (EncryptionMode)
1350 erq->flags = IW_ENCODE_ENABLED;
1352 else
1354 erq->flags = IW_ENCODE_DISABLED;
1357 /* We can't return the key, so set the proper flag and return zero */
1358 erq->flags |= IW_ENCODE_NOKEY;
1359 memset(key, 0, 16);
1361 /* Copy the key to the user buffer */
1362 switch(EncryptionMode)
1364 case ZM_WEP64:
1365 keyLen = 5;
1366 break;
1367 case ZM_WEP128:
1368 keyLen = 13;
1369 break;
1370 case ZM_WEP256:
1371 keyLen = 29;
1372 break;
1373 case ZM_AES:
1374 keyLen = 16;
1375 break;
1376 case ZM_TKIP:
1377 keyLen = 32;
1378 break;
1379 #ifdef ZM_ENABLE_CENC
1380 case ZM_CENC:
1381 keyLen = 32;
1382 break;
1383 #endif //ZM_ENABLE_CENC
1384 case ZM_NO_WEP:
1385 keyLen = 0;
1386 break;
1387 default :
1388 keyLen = 0;
1389 printk("Unknown EncryMode\n");
1390 break;
1393 erq->length = keyLen;
1395 return 0;
1398 int usbdrvwext_siwpower(struct net_device *dev,
1399 struct iw_request_info *info,
1400 struct iw_param *frq, char *extra)
1402 struct usbdrv_private *macp = dev->ml_priv;
1403 u8_t PSMode;
1405 if (macp->DeviceOpened != 1)
1406 return 0;
1408 if (frq->disabled)
1409 PSMode = ZM_STA_PS_NONE;
1410 else
1411 PSMode = ZM_STA_PS_MAX;
1413 zfiWlanSetPowerSaveMode(dev,PSMode);
1415 return 0;
1418 int usbdrvwext_giwpower(struct net_device *dev,
1419 struct iw_request_info *info,
1420 struct iw_param *frq, char *extra)
1422 unsigned long irqFlag;
1423 struct usbdrv_private *macp = dev->ml_priv;
1425 if (macp->DeviceOpened != 1)
1426 return 0;
1428 spin_lock_irqsave(&macp->cs_lock, irqFlag);
1430 if (zfiWlanQueryPowerSaveMode(dev) == ZM_STA_PS_NONE)
1431 frq->disabled = 1;
1432 else
1433 frq->disabled = 0;
1435 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
1437 return 0;
1440 //int usbdrvwext_setparam(struct net_device *dev, struct iw_request_info *info,
1441 // void *w, char *extra)
1443 // struct ieee80211vap *vap = dev->ml_priv;
1444 // struct ieee80211com *ic = vap->iv_ic;
1445 // struct ieee80211_rsnparms *rsn = &vap->iv_bss->ni_rsn;
1446 // int *i = (int *) extra;
1447 // int param = i[0]; /* parameter id is 1st */
1448 // int value = i[1]; /* NB: most values are TYPE_INT */
1449 // int retv = 0;
1450 // int j, caps;
1451 // const struct ieee80211_authenticator *auth;
1452 // const struct ieee80211_aclator *acl;
1454 // switch (param) {
1455 // case IEEE80211_PARAM_AUTHMODE:
1456 // switch (value) {
1457 // case IEEE80211_AUTH_WPA: /* WPA */
1458 // case IEEE80211_AUTH_8021X: /* 802.1x */
1459 // case IEEE80211_AUTH_OPEN: /* open */
1460 // case IEEE80211_AUTH_SHARED: /* shared-key */
1461 // case IEEE80211_AUTH_AUTO: /* auto */
1462 // auth = ieee80211_authenticator_get(value);
1463 // if (auth == NULL)
1464 // return -EINVAL;
1465 // break;
1466 // default:
1467 // return -EINVAL;
1468 // }
1469 // switch (value) {
1470 // case IEEE80211_AUTH_WPA: /* WPA w/ 802.1x */
1471 // vap->iv_flags |= IEEE80211_F_PRIVACY;
1472 // value = IEEE80211_AUTH_8021X;
1473 // break;
1474 // case IEEE80211_AUTH_OPEN: /* open */
1475 // vap->iv_flags &= ~(IEEE80211_F_WPA|IEEE80211_F_PRIVACY);
1476 // break;
1477 // case IEEE80211_AUTH_SHARED: /* shared-key */
1478 // case IEEE80211_AUTH_AUTO: /* auto */
1479 // case IEEE80211_AUTH_8021X: /* 802.1x */
1480 // vap->iv_flags &= ~IEEE80211_F_WPA;
1481 // /* both require a key so mark the PRIVACY capability */
1482 // vap->iv_flags |= IEEE80211_F_PRIVACY;
1483 // break;
1484 // }
1485 // /* NB: authenticator attach/detach happens on state change */
1486 // vap->iv_bss->ni_authmode = value;
1487 // /* XXX mixed/mode/usage? */
1488 // vap->iv_auth = auth;
1489 // retv = ENETRESET;
1490 // break;
1491 // case IEEE80211_PARAM_PROTMODE:
1492 // if (value > IEEE80211_PROT_RTSCTS)
1493 // return -EINVAL;
1494 // ic->ic_protmode = value;
1495 // /* NB: if not operating in 11g this can wait */
1496 // if (ic->ic_bsschan != IEEE80211_CHAN_ANYC &&
1497 // IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan))
1498 // retv = ENETRESET;
1499 // break;
1500 // case IEEE80211_PARAM_MCASTCIPHER:
1501 // if ((vap->iv_caps & cipher2cap(value)) == 0 &&
1502 // !ieee80211_crypto_available(value))
1503 // return -EINVAL;
1504 // rsn->rsn_mcastcipher = value;
1505 // if (vap->iv_flags & IEEE80211_F_WPA)
1506 // retv = ENETRESET;
1507 // break;
1508 // case IEEE80211_PARAM_MCASTKEYLEN:
1509 // if (!(0 < value && value < IEEE80211_KEYBUF_SIZE))
1510 // return -EINVAL;
1511 // /* XXX no way to verify driver capability */
1512 // rsn->rsn_mcastkeylen = value;
1513 // if (vap->iv_flags & IEEE80211_F_WPA)
1514 // retv = ENETRESET;
1515 // break;
1516 // case IEEE80211_PARAM_UCASTCIPHERS:
1517 // /*
1518 // * Convert cipher set to equivalent capabilities.
1519 // * NB: this logic intentionally ignores unknown and
1520 // * unsupported ciphers so folks can specify 0xff or
1521 // * similar and get all available ciphers.
1522 // */
1523 // caps = 0;
1524 // for (j = 1; j < 32; j++) /* NB: skip WEP */
1525 // if ((value & (1<<j)) &&
1526 // ((vap->iv_caps & cipher2cap(j)) ||
1527 // ieee80211_crypto_available(j)))
1528 // caps |= 1<<j;
1529 // if (caps == 0) /* nothing available */
1530 // return -EINVAL;
1531 // /* XXX verify ciphers ok for unicast use? */
1532 // /* XXX disallow if running as it'll have no effect */
1533 // rsn->rsn_ucastcipherset = caps;
1534 // if (vap->iv_flags & IEEE80211_F_WPA)
1535 // retv = ENETRESET;
1536 // break;
1537 // case IEEE80211_PARAM_UCASTCIPHER:
1538 // if ((rsn->rsn_ucastcipherset & cipher2cap(value)) == 0)
1539 // return -EINVAL;
1540 // rsn->rsn_ucastcipher = value;
1541 // break;
1542 // case IEEE80211_PARAM_UCASTKEYLEN:
1543 // if (!(0 < value && value < IEEE80211_KEYBUF_SIZE))
1544 // return -EINVAL;
1545 // /* XXX no way to verify driver capability */
1546 // rsn->rsn_ucastkeylen = value;
1547 // break;
1548 // case IEEE80211_PARAM_KEYMGTALGS:
1549 // /* XXX check */
1550 // rsn->rsn_keymgmtset = value;
1551 // if (vap->iv_flags & IEEE80211_F_WPA)
1552 // retv = ENETRESET;
1553 // break;
1554 // case IEEE80211_PARAM_RSNCAPS:
1555 // /* XXX check */
1556 // rsn->rsn_caps = value;
1557 // if (vap->iv_flags & IEEE80211_F_WPA)
1558 // retv = ENETRESET;
1559 // break;
1560 // case IEEE80211_PARAM_WPA:
1561 // if (value > 3)
1562 // return -EINVAL;
1563 // /* XXX verify ciphers available */
1564 // vap->iv_flags &= ~IEEE80211_F_WPA;
1565 // switch (value) {
1566 // case 1:
1567 // vap->iv_flags |= IEEE80211_F_WPA1;
1568 // break;
1569 // case 2:
1570 // vap->iv_flags |= IEEE80211_F_WPA2;
1571 // break;
1572 // case 3:
1573 // vap->iv_flags |= IEEE80211_F_WPA1 | IEEE80211_F_WPA2;
1574 // break;
1575 // }
1576 // retv = ENETRESET; /* XXX? */
1577 // break;
1578 // case IEEE80211_PARAM_ROAMING:
1579 // if (!(IEEE80211_ROAMING_DEVICE <= value &&
1580 // value <= IEEE80211_ROAMING_MANUAL))
1581 // return -EINVAL;
1582 // ic->ic_roaming = value;
1583 // break;
1584 // case IEEE80211_PARAM_PRIVACY:
1585 // if (value) {
1586 // /* XXX check for key state? */
1587 // vap->iv_flags |= IEEE80211_F_PRIVACY;
1588 // } else
1589 // vap->iv_flags &= ~IEEE80211_F_PRIVACY;
1590 // break;
1591 // case IEEE80211_PARAM_DROPUNENCRYPTED:
1592 // if (value)
1593 // vap->iv_flags |= IEEE80211_F_DROPUNENC;
1594 // else
1595 // vap->iv_flags &= ~IEEE80211_F_DROPUNENC;
1596 // break;
1597 // case IEEE80211_PARAM_COUNTERMEASURES:
1598 // if (value) {
1599 // if ((vap->iv_flags & IEEE80211_F_WPA) == 0)
1600 // return -EINVAL;
1601 // vap->iv_flags |= IEEE80211_F_COUNTERM;
1602 // } else
1603 // vap->iv_flags &= ~IEEE80211_F_COUNTERM;
1604 // break;
1605 // case IEEE80211_PARAM_DRIVER_CAPS:
1606 // vap->iv_caps = value; /* NB: for testing */
1607 // break;
1608 // case IEEE80211_PARAM_MACCMD:
1609 // acl = vap->iv_acl;
1610 // switch (value) {
1611 // case IEEE80211_MACCMD_POLICY_OPEN:
1612 // case IEEE80211_MACCMD_POLICY_ALLOW:
1613 // case IEEE80211_MACCMD_POLICY_DENY:
1614 // if (acl == NULL) {
1615 // acl = ieee80211_aclator_get("mac");
1616 // if (acl == NULL || !acl->iac_attach(vap))
1617 // return -EINVAL;
1618 // vap->iv_acl = acl;
1619 // }
1620 // acl->iac_setpolicy(vap, value);
1621 // break;
1622 // case IEEE80211_MACCMD_FLUSH:
1623 // if (acl != NULL)
1624 // acl->iac_flush(vap);
1625 // /* NB: silently ignore when not in use */
1626 // break;
1627 // case IEEE80211_MACCMD_DETACH:
1628 // if (acl != NULL) {
1629 // vap->iv_acl = NULL;
1630 // acl->iac_detach(vap);
1631 // }
1632 // break;
1633 // }
1634 // break;
1635 // case IEEE80211_PARAM_WMM:
1636 // if (ic->ic_caps & IEEE80211_C_WME){
1637 // if (value) {
1638 // vap->iv_flags |= IEEE80211_F_WME;
1639 // vap->iv_ic->ic_flags |= IEEE80211_F_WME; /* XXX needed by ic_reset */
1640 // }
1641 // else {
1642 // vap->iv_flags &= ~IEEE80211_F_WME;
1643 // vap->iv_ic->ic_flags &= ~IEEE80211_F_WME; /* XXX needed by ic_reset */
1644 // }
1645 // retv = ENETRESET; /* Renegotiate for capabilities */
1646 // }
1647 // break;
1648 // case IEEE80211_PARAM_HIDESSID:
1649 // if (value)
1650 // vap->iv_flags |= IEEE80211_F_HIDESSID;
1651 // else
1652 // vap->iv_flags &= ~IEEE80211_F_HIDESSID;
1653 // retv = ENETRESET;
1654 // break;
1655 // case IEEE80211_PARAM_APBRIDGE:
1656 // if (value == 0)
1657 // vap->iv_flags |= IEEE80211_F_NOBRIDGE;
1658 // else
1659 // vap->iv_flags &= ~IEEE80211_F_NOBRIDGE;
1660 // break;
1661 // case IEEE80211_PARAM_INACT:
1662 // vap->iv_inact_run = value / IEEE80211_INACT_WAIT;
1663 // break;
1664 // case IEEE80211_PARAM_INACT_AUTH:
1665 // vap->iv_inact_auth = value / IEEE80211_INACT_WAIT;
1666 // break;
1667 // case IEEE80211_PARAM_INACT_INIT:
1668 // vap->iv_inact_init = value / IEEE80211_INACT_WAIT;
1669 // break;
1670 // case IEEE80211_PARAM_ABOLT:
1671 // caps = 0;
1672 // /*
1673 // * Map abolt settings to capability bits;
1674 // * this also strips unknown/unwanted bits.
1675 // */
1676 // if (value & IEEE80211_ABOLT_TURBO_PRIME)
1677 // caps |= IEEE80211_ATHC_TURBOP;
1678 // if (value & IEEE80211_ABOLT_COMPRESSION)
1679 // caps |= IEEE80211_ATHC_COMP;
1680 // if (value & IEEE80211_ABOLT_FAST_FRAME)
1681 // caps |= IEEE80211_ATHC_FF;
1682 // if (value & IEEE80211_ABOLT_XR)
1683 // caps |= IEEE80211_ATHC_XR;
1684 // if (value & IEEE80211_ABOLT_AR)
1685 // caps |= IEEE80211_ATHC_AR;
1686 // if (value & IEEE80211_ABOLT_BURST)
1687 // caps |= IEEE80211_ATHC_BURST;
1688 // if (value & IEEE80211_ABOLT_WME_ELE)
1689 // caps |= IEEE80211_ATHC_WME;
1690 // /* verify requested capabilities are supported */
1691 // if ((caps & ic->ic_ath_cap) != caps)
1692 // return -EINVAL;
1693 // if (vap->iv_ath_cap != caps) {
1694 // if ((vap->iv_ath_cap ^ caps) & IEEE80211_ATHC_TURBOP) {
1695 // if (ieee80211_set_turbo(dev, caps & IEEE80211_ATHC_TURBOP))
1696 // return -EINVAL;
1697 // ieee80211_scan_flush(ic);
1698 // }
1699 // vap->iv_ath_cap = caps;
1700 // ic->ic_athcapsetup(vap->iv_ic, vap->iv_ath_cap);
1701 // retv = ENETRESET;
1702 // }
1703 // break;
1704 // case IEEE80211_PARAM_DTIM_PERIOD:
1705 // if (vap->iv_opmode != IEEE80211_M_HOSTAP &&
1706 // vap->iv_opmode != IEEE80211_M_IBSS)
1707 // return -EINVAL;
1708 // if (IEEE80211_DTIM_MIN <= value &&
1709 // value <= IEEE80211_DTIM_MAX) {
1710 // vap->iv_dtim_period = value;
1711 // retv = ENETRESET; /* requires restart */
1712 // } else
1713 // retv = EINVAL;
1714 // break;
1715 // case IEEE80211_PARAM_BEACON_INTERVAL:
1716 // if (vap->iv_opmode != IEEE80211_M_HOSTAP &&
1717 // vap->iv_opmode != IEEE80211_M_IBSS)
1718 // return -EINVAL;
1719 // if (IEEE80211_BINTVAL_MIN <= value &&
1720 // value <= IEEE80211_BINTVAL_MAX) {
1721 // ic->ic_lintval = value; /* XXX multi-bss */
1722 // retv = ENETRESET; /* requires restart */
1723 // } else
1724 // retv = EINVAL;
1725 // break;
1726 // case IEEE80211_PARAM_DOTH:
1727 // if (value) {
1728 // ic->ic_flags |= IEEE80211_F_DOTH;
1729 // }
1730 // else
1731 // ic->ic_flags &= ~IEEE80211_F_DOTH;
1732 // retv = ENETRESET; /* XXX: need something this drastic? */
1733 // break;
1734 // case IEEE80211_PARAM_PWRTARGET:
1735 // ic->ic_curchanmaxpwr = value;
1736 // break;
1737 // case IEEE80211_PARAM_GENREASSOC:
1738 // IEEE80211_SEND_MGMT(vap->iv_bss, IEEE80211_FC0_SUBTYPE_REASSOC_REQ, 0);
1739 // break;
1740 // case IEEE80211_PARAM_COMPRESSION:
1741 // retv = ieee80211_setathcap(vap, IEEE80211_ATHC_COMP, value);
1742 // break;
1743 // case IEEE80211_PARAM_WMM_AGGRMODE:
1744 // retv = ieee80211_setathcap(vap, IEEE80211_ATHC_WME, value);
1745 // break;
1746 // case IEEE80211_PARAM_FF:
1747 // retv = ieee80211_setathcap(vap, IEEE80211_ATHC_FF, value);
1748 // break;
1749 // case IEEE80211_PARAM_TURBO:
1750 // retv = ieee80211_setathcap(vap, IEEE80211_ATHC_TURBOP, value);
1751 // if (retv == ENETRESET) {
1752 // if(ieee80211_set_turbo(dev,value))
1753 // return -EINVAL;
1754 // ieee80211_scan_flush(ic);
1755 // }
1756 // break;
1757 // case IEEE80211_PARAM_XR:
1758 // retv = ieee80211_setathcap(vap, IEEE80211_ATHC_XR, value);
1759 // break;
1760 // case IEEE80211_PARAM_BURST:
1761 // retv = ieee80211_setathcap(vap, IEEE80211_ATHC_BURST, value);
1762 // break;
1763 // case IEEE80211_PARAM_AR:
1764 // retv = ieee80211_setathcap(vap, IEEE80211_ATHC_AR, value);
1765 // break;
1766 // case IEEE80211_PARAM_PUREG:
1767 // if (value)
1768 // vap->iv_flags |= IEEE80211_F_PUREG;
1769 // else
1770 // vap->iv_flags &= ~IEEE80211_F_PUREG;
1771 // /* NB: reset only if we're operating on an 11g channel */
1772 // if (ic->ic_bsschan != IEEE80211_CHAN_ANYC &&
1773 // IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan))
1774 // retv = ENETRESET;
1775 // break;
1776 // case IEEE80211_PARAM_WDS:
1777 // if (value)
1778 // vap->iv_flags_ext |= IEEE80211_FEXT_WDS;
1779 // else
1780 // vap->iv_flags_ext &= ~IEEE80211_FEXT_WDS;
1781 // break;
1782 // case IEEE80211_PARAM_BGSCAN:
1783 // if (value) {
1784 // if ((vap->iv_caps & IEEE80211_C_BGSCAN) == 0)
1785 // return -EINVAL;
1786 // vap->iv_flags |= IEEE80211_F_BGSCAN;
1787 // } else {
1788 // /* XXX racey? */
1789 // vap->iv_flags &= ~IEEE80211_F_BGSCAN;
1790 // ieee80211_cancel_scan(vap); /* anything current */
1791 // }
1792 // break;
1793 // case IEEE80211_PARAM_BGSCAN_IDLE:
1794 // if (value >= IEEE80211_BGSCAN_IDLE_MIN)
1795 // vap->iv_bgscanidle = value*HZ/1000;
1796 // else
1797 // retv = EINVAL;
1798 // break;
1799 // case IEEE80211_PARAM_BGSCAN_INTERVAL:
1800 // if (value >= IEEE80211_BGSCAN_INTVAL_MIN)
1801 // vap->iv_bgscanintvl = value*HZ;
1802 // else
1803 // retv = EINVAL;
1804 // break;
1805 // case IEEE80211_PARAM_MCAST_RATE:
1806 // /* units are in KILObits per second */
1807 // if (value >= 256 && value <= 54000)
1808 // vap->iv_mcast_rate = value;
1809 // else
1810 // retv = EINVAL;
1811 // break;
1812 // case IEEE80211_PARAM_COVERAGE_CLASS:
1813 // if (value >= 0 && value <= IEEE80211_COVERAGE_CLASS_MAX) {
1814 // ic->ic_coverageclass = value;
1815 // if (IS_UP_AUTO(vap))
1816 // ieee80211_new_state(vap, IEEE80211_S_SCAN, 0);
1817 // retv = 0;
1818 // }
1819 // else
1820 // retv = EINVAL;
1821 // break;
1822 // case IEEE80211_PARAM_COUNTRY_IE:
1823 // if (value)
1824 // ic->ic_flags_ext |= IEEE80211_FEXT_COUNTRYIE;
1825 // else
1826 // ic->ic_flags_ext &= ~IEEE80211_FEXT_COUNTRYIE;
1827 // retv = ENETRESET;
1828 // break;
1829 // case IEEE80211_PARAM_REGCLASS:
1830 // if (value)
1831 // ic->ic_flags_ext |= IEEE80211_FEXT_REGCLASS;
1832 // else
1833 // ic->ic_flags_ext &= ~IEEE80211_FEXT_REGCLASS;
1834 // retv = ENETRESET;
1835 // break;
1836 // case IEEE80211_PARAM_SCANVALID:
1837 // vap->iv_scanvalid = value*HZ;
1838 // break;
1839 // case IEEE80211_PARAM_ROAM_RSSI_11A:
1840 // vap->iv_roam.rssi11a = value;
1841 // break;
1842 // case IEEE80211_PARAM_ROAM_RSSI_11B:
1843 // vap->iv_roam.rssi11bOnly = value;
1844 // break;
1845 // case IEEE80211_PARAM_ROAM_RSSI_11G:
1846 // vap->iv_roam.rssi11b = value;
1847 // break;
1848 // case IEEE80211_PARAM_ROAM_RATE_11A:
1849 // vap->iv_roam.rate11a = value;
1850 // break;
1851 // case IEEE80211_PARAM_ROAM_RATE_11B:
1852 // vap->iv_roam.rate11bOnly = value;
1853 // break;
1854 // case IEEE80211_PARAM_ROAM_RATE_11G:
1855 // vap->iv_roam.rate11b = value;
1856 // break;
1857 // case IEEE80211_PARAM_UAPSDINFO:
1858 // if (vap->iv_opmode == IEEE80211_M_HOSTAP) {
1859 // if (ic->ic_caps & IEEE80211_C_UAPSD) {
1860 // if (value)
1861 // IEEE80211_VAP_UAPSD_ENABLE(vap);
1862 // else
1863 // IEEE80211_VAP_UAPSD_DISABLE(vap);
1864 // retv = ENETRESET;
1865 // }
1866 // }
1867 // else if (vap->iv_opmode == IEEE80211_M_STA) {
1868 // vap->iv_uapsdinfo = value;
1869 // IEEE80211_VAP_UAPSD_ENABLE(vap);
1870 // retv = ENETRESET;
1871 // }
1872 // break;
1873 // case IEEE80211_PARAM_SLEEP:
1874 // /* XXX: Forced sleep for testing. Does not actually place the
1875 // * HW in sleep mode yet. this only makes sense for STAs.
1876 // */
1877 // if (value) {
1878 // /* goto sleep */
1879 // IEEE80211_VAP_GOTOSLEEP(vap);
1880 // }
1881 // else {
1882 // /* wakeup */
1883 // IEEE80211_VAP_WAKEUP(vap);
1884 // }
1885 // ieee80211_send_nulldata(ieee80211_ref_node(vap->iv_bss));
1886 // break;
1887 // case IEEE80211_PARAM_QOSNULL:
1888 // /* Force a QoS Null for testing. */
1889 // ieee80211_send_qosnulldata(vap->iv_bss, value);
1890 // break;
1891 // case IEEE80211_PARAM_PSPOLL:
1892 // /* Force a PS-POLL for testing. */
1893 // ieee80211_send_pspoll(vap->iv_bss);
1894 // break;
1895 // case IEEE80211_PARAM_EOSPDROP:
1896 // if (vap->iv_opmode == IEEE80211_M_HOSTAP) {
1897 // if (value) IEEE80211_VAP_EOSPDROP_ENABLE(vap);
1898 // else IEEE80211_VAP_EOSPDROP_DISABLE(vap);
1899 // }
1900 // break;
1901 // case IEEE80211_PARAM_MARKDFS:
1902 // if (value)
1903 // ic->ic_flags_ext |= IEEE80211_FEXT_MARKDFS;
1904 // else
1905 // ic->ic_flags_ext &= ~IEEE80211_FEXT_MARKDFS;
1906 // break;
1907 // case IEEE80211_PARAM_CHANBW:
1908 // switch (value) {
1909 // case 0:
1910 // ic->ic_chanbwflag = 0;
1911 // break;
1912 // case 1:
1913 // ic->ic_chanbwflag = IEEE80211_CHAN_HALF;
1914 // break;
1915 // case 2:
1916 // ic->ic_chanbwflag = IEEE80211_CHAN_QUARTER;
1917 // break;
1918 // default:
1919 // retv = EINVAL;
1920 // break;
1921 // }
1922 // break;
1923 // case IEEE80211_PARAM_SHORTPREAMBLE:
1924 // if (value) {
1925 // ic->ic_caps |= IEEE80211_C_SHPREAMBLE;
1926 // } else {
1927 // ic->ic_caps &= ~IEEE80211_C_SHPREAMBLE;
1928 // }
1929 // retv = ENETRESET;
1930 // break;
1931 // default:
1932 // retv = EOPNOTSUPP;
1933 // break;
1934 // }
1935 // /* XXX should any of these cause a rescan? */
1936 // if (retv == ENETRESET)
1937 // retv = IS_UP_AUTO(vap) ? ieee80211_open(vap->iv_dev) : 0;
1938 // return -retv;
1941 int usbdrvwext_setmode(struct net_device *dev, struct iw_request_info *info,
1942 void *w, char *extra)
1944 return 0;
1947 int usbdrvwext_getmode(struct net_device *dev, struct iw_request_info *info,
1948 void *w, char *extra)
1950 //struct usbdrv_private *macp = dev->ml_priv;
1951 struct iw_point *wri = (struct iw_point *)extra;
1952 char mode[8];
1954 strcpy(mode,"11g");
1955 return (copy_to_user(wri->pointer, mode, 6) ? -EFAULT : 0);
1958 int zfLnxPrivateIoctl(struct net_device *dev, struct zdap_ioctl* zdreq)
1960 //void* regp = macp->regp;
1961 u16_t cmd;
1962 //u32_t temp;
1963 u32_t* p;
1964 u32_t i;
1966 cmd = zdreq->cmd;
1967 switch(cmd)
1969 case ZM_IOCTL_REG_READ:
1970 zfiDbgReadReg(dev, zdreq->addr);
1971 break;
1973 case ZM_IOCTL_REG_WRITE:
1974 zfiDbgWriteReg(dev, zdreq->addr, zdreq->value);
1975 break;
1977 case ZM_IOCTL_MEM_READ:
1978 p = (u32_t *) bus_to_virt(zdreq->addr);
1979 printk(KERN_DEBUG "usbdrv: read memory addr: 0x%08x value: 0x%08x\n", zdreq->addr, *p);
1980 break;
1982 case ZM_IOCTL_MEM_WRITE:
1983 p = (u32_t *) bus_to_virt(zdreq->addr);
1984 *p = zdreq->value;
1985 printk(KERN_DEBUG "usbdrv: write value: 0x%08x to memory addr: 0x%08x\n", zdreq->value, zdreq->addr);
1986 break;
1988 case ZM_IOCTL_TALLY :
1989 zfiWlanShowTally(dev);
1990 if (zdreq->addr)
1991 zfiWlanResetTally(dev);
1992 break;
1994 case ZM_IOCTL_TEST :
1995 printk(KERN_DEBUG "ZM_IOCTL_TEST:len=%d\n", zdreq->addr);
1996 //zfiWlanReadReg(dev, 0x10f400);
1997 //zfiWlanReadReg(dev, 0x10f404);
1998 printk("IOCTL TEST\n");
1999 #if 1
2000 //print packet
2001 for (i=0; i<zdreq->addr; i++)
2003 if ((i&0x7) == 0)
2005 printk("\n");
2007 printk("%02X ", (unsigned char)zdreq->data[i]);
2009 printk("\n");
2010 #endif
2013 #if 0 //For Test?? 1 to 0 by CWYang(-)
2015 struct sk_buff* s;
2017 /* Allocate a skb */
2018 s = alloc_skb(2000, GFP_ATOMIC);
2020 /* Copy data to skb */
2021 for (i=0; i<zdreq->addr; i++)
2023 s->data[i] = zdreq->data[i];
2025 s->len = zdreq->addr;
2027 /* Call zfIdlRecv() */
2028 zfiRecv80211(dev, s, NULL);
2030 #endif
2032 break;
2035 /****************************** ZDCONFIG ******************************/
2036 case ZM_IOCTL_FRAG :
2037 zfiWlanSetFragThreshold(dev, zdreq->addr);
2038 break;
2040 case ZM_IOCTL_RTS :
2041 zfiWlanSetRtsThreshold(dev, zdreq->addr);
2042 break;
2044 case ZM_IOCTL_SCAN :
2045 zfiWlanScan(dev);
2046 break;
2048 case ZM_IOCTL_KEY :
2050 u8_t key[29];
2051 struct zsKeyInfo keyInfo;
2052 u32_t i;
2054 for (i=0; i<29; i++)
2056 key[i] = 0;
2059 for (i=0; i<zdreq->addr; i++)
2061 key[i] = zdreq->data[i];
2064 printk("key len=%d, key=%02x%02x%02x%02x%02x...\n",
2065 zdreq->addr, key[0], key[1], key[2], key[3], key[4]);
2067 keyInfo.keyLength = zdreq->addr;
2068 keyInfo.keyIndex = 0;
2069 keyInfo.flag = 0;
2070 keyInfo.key = key;
2071 zfiWlanSetKey(dev, keyInfo);
2073 break;
2075 case ZM_IOCTL_RATE :
2076 zfiWlanSetTxRate(dev, zdreq->addr);
2077 break;
2079 case ZM_IOCTL_ENCRYPTION_MODE :
2080 zfiWlanSetEncryMode(dev, zdreq->addr);
2082 zfiWlanDisable(dev, 0);
2083 zfiWlanEnable(dev);
2084 break;
2085 //CWYang(+)
2086 case ZM_IOCTL_SIGNAL_STRENGTH :
2088 u8_t buffer[2];
2089 zfiWlanQuerySignalInfo(dev, &buffer[0]);
2090 printk("Current Signal Strength : %02d\n", buffer[0]);
2092 break;
2093 //CWYang(+)
2094 case ZM_IOCTL_SIGNAL_QUALITY :
2096 u8_t buffer[2];
2097 zfiWlanQuerySignalInfo(dev, &buffer[0]);
2098 printk("Current Signal Quality : %02d\n", buffer[1]);
2100 break;
2102 case ZM_IOCTL_SET_PIBSS_MODE:
2103 if (zdreq->addr == 1)
2104 zfiWlanSetWlanMode(dev, ZM_MODE_PSEUDO);
2105 else
2106 zfiWlanSetWlanMode(dev, ZM_MODE_INFRASTRUCTURE);
2108 zfiWlanDisable(dev, 0);
2109 zfiWlanEnable(dev);
2111 break;
2112 /****************************** ZDCONFIG ******************************/
2114 default :
2115 printk(KERN_ERR "usbdrv: error command = %x\n", cmd);
2116 break;
2119 return 0;
2122 int usbdrv_wpa_ioctl(struct net_device *dev, struct athr_wlan_param *zdparm)
2124 int ret = 0;
2125 u8_t bc_addr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2126 u8_t mac_addr[80];
2127 struct zsKeyInfo keyInfo;
2128 struct usbdrv_private *macp = dev->ml_priv;
2129 u16_t vapId = 0;
2131 //zmw_get_wlan_dev(dev);
2133 switch(zdparm->cmd)
2135 case ZD_CMD_SET_ENCRYPT_KEY:
2137 /* Set up key information */
2138 keyInfo.keyLength = zdparm->u.crypt.key_len;
2139 keyInfo.keyIndex = zdparm->u.crypt.idx;
2140 if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) // AP Mode
2141 keyInfo.flag = ZM_KEY_FLAG_AUTHENTICATOR;
2142 else
2143 keyInfo.flag = 0;
2144 keyInfo.key = zdparm->u.crypt.key;
2145 keyInfo.initIv = zdparm->u.crypt.seq;
2146 keyInfo.macAddr = (u16_t *)zdparm->sta_addr;
2148 /* Identify the MAC address information */
2149 if (memcmp(zdparm->sta_addr, bc_addr, sizeof(bc_addr)) == 0)
2151 keyInfo.flag |= ZM_KEY_FLAG_GK;
2153 else
2155 keyInfo.flag |= ZM_KEY_FLAG_PK;
2158 if (!strcmp(zdparm->u.crypt.alg, "NONE"))
2160 //u8_t zero_mac[]={0,0,0,0,0,0};
2162 /* Set key length to zero */
2163 keyInfo.keyLength = 0;
2165 if (zdparm->sta_addr[0] & 1)//del group key
2167 //if (macp->cardSetting.WPAIeLen==0)
2168 //{//802.1x dynamic WEP
2169 // mDynKeyMode = 0;
2170 // mKeyFormat[0] = 0;
2171 // mPrivacyInvoked[0]=FALSE;
2172 // mCap[0] &= ~CAP_PRIVACY;
2173 // macp->cardSetting.EncryOnOff[0]=0;
2175 //mWpaBcKeyLen = mGkInstalled = 0;
2177 else
2179 //if (memcmp(zero_mac,zdparm->sta_addr, 6)==0)
2181 // mDynKeyMode=0;
2182 // mKeyFormat[0]=0;
2183 // pSetting->DynKeyMode=0;
2184 // pSetting->EncryMode[0]=0;
2185 // mDynKeyMode=0;
2189 printk(KERN_ERR "Set Encryption Type NONE\n");
2190 return ret;
2192 else if (!strcmp(zdparm->u.crypt.alg, "TKIP"))
2194 zfiWlanSetEncryMode(dev, ZM_TKIP);
2195 //Linux Supplicant will inverse Tx/Rx key
2196 //So we inverse it back //CWYang(+)
2197 //zfMemoryCopy(&temp[0], &keyInfo.key[16], 8);
2198 //zfMemoryCopy(&keyInfo.key[16], keyInfo.key[24], 8);
2199 //zfMemoryCopy(&keyInfo.key[24], &temp[0], 8);
2200 //u8_t temp;
2201 //int k;
2202 //for (k = 0; k < 8; k++)
2204 // temp = keyInfo.key[16 + k];
2205 // keyInfo.key[16 + k] = keyInfo.key[24 + k];
2206 // keyInfo.key[24 + k] = temp;
2208 //CamEncryType = ZM_TKIP;
2209 ////if (idx == 0)
2210 //{// Pairwise key
2211 // mKeyFormat[0] = CamEncryType;
2212 // mDynKeyMode = pSetting->DynKeyMode = DYN_KEY_TKIP;
2215 else if (!strcmp(zdparm->u.crypt.alg, "CCMP"))
2217 zfiWlanSetEncryMode(dev, ZM_AES);
2218 //CamEncryType = ZM_AES;
2219 ////if (idx == 0)
2220 //{// Pairwise key
2221 // mKeyFormat[0] = CamEncryType;
2222 // mDynKeyMode = pSetting->DynKeyMode = DYN_KEY_AES;
2225 else if (!strcmp(zdparm->u.crypt.alg, "WEP"))
2227 if (keyInfo.keyLength == 5)
2228 { // WEP 64
2229 zfiWlanSetEncryMode(dev, ZM_WEP64);
2230 // CamEncryType = ZM_WEP64;
2231 // tmpDynKeyMode=DYN_KEY_WEP64;
2233 else if (keyInfo.keyLength == 13)
2234 {//keylen=13, WEP 128
2235 zfiWlanSetEncryMode(dev, ZM_WEP128);
2236 // CamEncryType = ZM_WEP128;
2237 // tmpDynKeyMode=DYN_KEY_WEP128;
2239 else
2241 zfiWlanSetEncryMode(dev, ZM_WEP256);
2244 // For Dynamic WEP key (Non-WPA Radius), the key ID range: 0-3
2245 // In WPA/RSN mode, the key ID range: 1-3, usually, a broadcast key.
2246 // For WEP key setting: we set mDynKeyMode and mKeyFormat in following case:
2247 // 1. For 802.1x dynamically generated WEP key method.
2248 // 2. For WPA/RSN mode, but key id == 0. (But this is an impossible case)
2249 // So, only check case 1.
2250 //if (macp->cardSetting.WPAIeLen==0)
2252 // mKeyFormat[0] = CamEncryType;
2253 // mDynKeyMode = pSetting->DynKeyMode = tmpDynKeyMode;
2254 // mPrivacyInvoked[0]=TRUE;
2255 // mCap[0] |= CAP_PRIVACY;
2256 // macp->cardSetting.EncryOnOff[0]=1;
2260 /* DUMP key context */
2261 //#ifdef WPA_DEBUG
2262 if (keyInfo.keyLength > 0)
2264 int ii;
2265 printk("Otus: Key Context:\n");
2266 for(ii = 0; ii < keyInfo.keyLength;)
2268 printk("0x%02x ", keyInfo.key[ii]);
2269 if((++ii % 16) == 0)
2270 printk("\n");
2272 printk("\n");
2274 //#endif
2276 /* Set encrypt mode */
2277 //zfiWlanSetEncryMode(dev, CamEncryType);
2278 vapId = zfLnxGetVapId(dev);
2279 if (vapId == 0xffff)
2280 keyInfo.vapId = 0;
2281 else
2282 keyInfo.vapId = vapId + 1;
2283 keyInfo.vapAddr[0] = keyInfo.macAddr[0];
2284 keyInfo.vapAddr[1] = keyInfo.macAddr[1];
2285 keyInfo.vapAddr[2] = keyInfo.macAddr[2];
2287 zfiWlanSetKey(dev, keyInfo);
2289 //zfiWlanDisable(dev);
2290 //zfiWlanEnable(dev);
2291 break;
2293 case ZD_CMD_SET_MLME:
2294 printk(KERN_ERR "usbdrv_wpa_ioctl: ZD_CMD_SET_MLME\n");
2296 /* Translate STA's address */
2297 sprintf(mac_addr, "%02x:%02x:%02x:%02x:%02x:%02x", zdparm->sta_addr[0], zdparm->sta_addr[1],
2298 zdparm->sta_addr[2], zdparm->sta_addr[3], zdparm->sta_addr[4], zdparm->sta_addr[5]);
2300 switch(zdparm->u.mlme.cmd)
2302 case MLME_STA_DEAUTH:
2303 printk(" -------Call zfiWlanDeauth, reason:%d\n",zdparm->u.mlme.reason_code);
2304 if(zfiWlanDeauth(dev, (u16_t*) zdparm->sta_addr, zdparm->u.mlme.reason_code) != 0)
2305 printk(KERN_ERR "Can't deauthencate STA: %s\n", mac_addr);
2306 else
2307 printk(KERN_ERR "Deauthenticate STA: %s with reason code: %d\n", mac_addr, zdparm->u.mlme.reason_code);
2308 break;
2310 case MLME_STA_DISASSOC:
2311 printk(" -------Call zfiWlanDeauth, reason:%d\n",zdparm->u.mlme.reason_code);
2312 if(zfiWlanDeauth(dev, (u16_t*) zdparm->sta_addr, zdparm->u.mlme.reason_code) != 0)
2313 printk(KERN_ERR "Can't disassociate STA: %s\n", mac_addr);
2314 else
2315 printk(KERN_ERR "Disassociate STA: %s with reason code: %d\n", mac_addr, zdparm->u.mlme.reason_code);
2316 break;
2318 default:
2319 printk(KERN_ERR "MLME command: 0x%04x not support\n", zdparm->u.mlme.cmd);
2320 break;
2323 break;
2325 case ZD_CMD_SCAN_REQ:
2326 printk(KERN_ERR "usbdrv_wpa_ioctl: ZD_CMD_SCAN_REQ\n");
2327 break;
2329 case ZD_CMD_SET_GENERIC_ELEMENT:
2330 printk(KERN_ERR "usbdrv_wpa_ioctl: ZD_CMD_SET_GENERIC_ELEMENT\n");
2332 /* Copy the WPA IE */
2333 //zm_msg1_mm(ZM_LV_0, "CWY - wpaie Length : ", zdparm->u.generic_elem.len);
2334 printk(KERN_ERR "wpaie Length : %d\n", zdparm->u.generic_elem.len);
2335 if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) // AP Mode
2337 zfiWlanSetWpaIe(dev, zdparm->u.generic_elem.data, zdparm->u.generic_elem.len);
2339 else
2341 macp->supLen = zdparm->u.generic_elem.len;
2342 memcpy(macp->supIe, zdparm->u.generic_elem.data, zdparm->u.generic_elem.len);
2344 zfiWlanSetWpaSupport(dev, 1);
2345 //zfiWlanSetWpaIe(dev, zdparm->u.generic_elem.data, zdparm->u.generic_elem.len);
2347 int ii;
2348 u8_t len = zdparm->u.generic_elem.len;
2349 u8_t *wpaie = (u8_t *)zdparm->u.generic_elem.data;
2351 printk(KERN_ERR "wd->ap.wpaLen: %d\n", len);
2353 /* DUMP WPA IE */
2354 for(ii = 0; ii < len;)
2356 printk(KERN_ERR "0x%02x ", wpaie[ii]);
2358 if((++ii % 16) == 0)
2359 printk(KERN_ERR "\n");
2361 printk(KERN_ERR "\n");
2364 // #ifdef ZM_HOSTAPD_SUPPORT
2365 //if (wd->wlanMode == ZM_MODE_AP)
2366 //{// Update Beacon FIFO in the next TBTT.
2367 // memcpy(&mWPAIe, pSetting->WPAIe, pSetting->WPAIeLen);
2368 // printk(KERN_ERR "Copy WPA IE into mWPAIe\n");
2370 // #endif
2371 break;
2373 // #ifdef ZM_HOSTAPD_SUPPORT
2374 case ZD_CMD_GET_TSC:
2375 printk(KERN_ERR "usbdrv_wpa_ioctl: ZD_CMD_GET_TSC\n");
2376 break;
2377 // #endif
2379 default:
2380 printk(KERN_ERR "usbdrv_wpa_ioctl default: 0x%04x\n", zdparm->cmd);
2381 ret = -EINVAL;
2382 break;
2385 return ret;
2388 #ifdef ZM_ENABLE_CENC
2389 int usbdrv_cenc_ioctl(struct net_device *dev, struct zydas_cenc_param *zdparm)
2391 //struct usbdrv_private *macp = dev->ml_priv;
2392 struct zsKeyInfo keyInfo;
2393 u16_t apId;
2394 u8_t bc_addr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2395 int ret = 0;
2396 int ii;
2398 /* Get the AP Id */
2399 apId = zfLnxGetVapId(dev);
2401 if (apId == 0xffff)
2403 apId = 0;
2405 else
2407 apId = apId+1;
2410 switch (zdparm->cmd)
2412 case ZM_CMD_CENC_SETCENC:
2413 printk(KERN_ERR "ZM_CMD_CENC_SETCENC\n");
2414 printk(KERN_ERR "length: %d\n", zdparm->len);
2415 printk(KERN_ERR "policy: %d\n", zdparm->u.info.cenc_policy);
2416 break;
2417 case ZM_CMD_CENC_SETKEY:
2418 //ret = wai_ioctl_setkey(vap, ioctl_msg);
2419 printk(KERN_ERR "ZM_CMD_CENC_SETKEY\n");
2421 printk(KERN_ERR "MAC address= ");
2422 for(ii = 0; ii < 6; ii++)
2424 printk(KERN_ERR "0x%02x ", zdparm->u.crypt.sta_addr[ii]);
2426 printk(KERN_ERR "\n");
2428 printk(KERN_ERR "Key Index: %d\n", zdparm->u.crypt.keyid);
2429 printk(KERN_ERR "Encryption key= ");
2430 for(ii = 0; ii < 16; ii++)
2432 printk(KERN_ERR "0x%02x ", zdparm->u.crypt.key[ii]);
2434 printk(KERN_ERR "\n");
2436 printk(KERN_ERR "MIC key= ");
2437 for(ii = 16; ii < ZM_CENC_KEY_SIZE; ii++)
2439 printk(KERN_ERR "0x%02x ", zdparm->u.crypt.key[ii]);
2441 printk(KERN_ERR "\n");
2443 /* Set up key information */
2444 keyInfo.keyLength = ZM_CENC_KEY_SIZE;
2445 keyInfo.keyIndex = zdparm->u.crypt.keyid;
2446 keyInfo.flag = ZM_KEY_FLAG_AUTHENTICATOR | ZM_KEY_FLAG_CENC;
2447 keyInfo.key = zdparm->u.crypt.key;
2448 keyInfo.macAddr = (u16_t *)zdparm->u.crypt.sta_addr;
2450 /* Identify the MAC address information */
2451 if (memcmp(zdparm->u.crypt.sta_addr, bc_addr, sizeof(bc_addr)) == 0)
2453 keyInfo.flag |= ZM_KEY_FLAG_GK;
2454 keyInfo.vapId = apId;
2455 memcpy(keyInfo.vapAddr, dev->dev_addr, ETH_ALEN);
2457 else
2459 keyInfo.flag |= ZM_KEY_FLAG_PK;
2462 zfiWlanSetKey(dev, keyInfo);
2464 break;
2465 case ZM_CMD_CENC_REKEY:
2466 //ret = wai_ioctl_rekey(vap, ioctl_msg);
2467 printk(KERN_ERR "ZM_CMD_CENC_REKEY\n");
2468 break;
2469 default:
2470 ret = -EOPNOTSUPP;
2471 break;
2475 //if (retv == ENETRESET)
2476 // retv = IS_UP_AUTO(vap) ? ieee80211_open(vap->iv_dev) : 0;
2478 return ret;
2480 #endif //ZM_ENABLE_CENC
2481 /////////////////////////////////////////
2482 int usbdrv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2484 // struct usbdrv_private *macp;
2485 // void *regp;
2486 struct zdap_ioctl zdreq;
2487 struct iwreq *wrq = (struct iwreq *)ifr;
2488 struct athr_wlan_param zdparm;
2489 struct usbdrv_private *macp = dev->ml_priv;
2491 int err = 0;
2492 int changed = 0;
2494 // regp = macp->regp;
2496 if(!netif_running(dev))
2497 return -EINVAL;
2499 switch (cmd)
2501 case SIOCGIWNAME:
2502 strcpy(wrq->u.name, "IEEE 802.11-DS");
2503 break;
2505 case SIOCGIWAP:
2506 err = usbdrvwext_giwap(dev, NULL, &wrq->u.ap_addr, NULL);
2507 break;
2510 case SIOCSIWAP:
2511 err = usbdrvwext_siwap(dev, NULL, &wrq->u.ap_addr, NULL);
2512 break;
2515 case SIOCGIWMODE:
2516 err = usbdrvwext_giwmode(dev, NULL, &wrq->u.mode, NULL);
2517 break;
2520 case SIOCSIWESSID:
2521 printk(KERN_ERR "CWY - usbdrvwext_siwessid\n");
2522 //err = usbdrv_ioctl_setessid(dev, &wrq->u.essid);
2523 err = usbdrvwext_siwessid(dev, NULL, &wrq->u.essid, NULL);
2525 if (! err)
2526 changed = 1;
2527 break;
2530 case SIOCGIWESSID:
2531 err = usbdrvwext_giwessid(dev, NULL, &wrq->u.essid, NULL);
2532 break;
2535 case SIOCSIWRTS:
2537 err = usbdrv_ioctl_setrts(dev, &wrq->u.rts);
2538 if (! err)
2539 changed = 1;
2540 break;
2543 case SIOCIWFIRSTPRIV + 0x2: /* set_auth */
2545 //printk("CWY - SIOCIWFIRSTPRIV + 0x2 (set_auth)\n");
2546 if (! capable(CAP_NET_ADMIN))
2548 err = -EPERM;
2549 break;
2552 int val = *( (int *) wrq->u.name );
2553 if ((val < 0) || (val > 2))
2555 err = -EINVAL;
2556 break;
2558 else
2560 zfiWlanSetAuthenticationMode(dev, val);
2562 if (macp->DeviceOpened == 1)
2564 zfiWlanDisable(dev, 0);
2565 zfiWlanEnable(dev);
2568 err = 0;
2569 changed = 1;
2573 break;
2575 case SIOCIWFIRSTPRIV + 0x3: /* get_auth */
2577 int AuthMode = ZM_AUTH_MODE_OPEN;
2579 //printk("CWY - SIOCIWFIRSTPRIV + 0x3 (get_auth)\n");
2581 if (wrq->u.data.pointer)
2583 wrq->u.data.flags = 1;
2585 AuthMode = zfiWlanQueryAuthenticationMode(dev, 0);
2586 if (AuthMode == ZM_AUTH_MODE_OPEN)
2588 wrq->u.data.length = 12;
2590 if (copy_to_user(wrq->u.data.pointer, "open system", 12))
2592 return -EFAULT;
2595 else if (AuthMode == ZM_AUTH_MODE_SHARED_KEY)
2597 wrq->u.data.length = 11;
2599 if (copy_to_user(wrq->u.data.pointer, "shared key", 11))
2601 return -EFAULT;
2604 else if (AuthMode == ZM_AUTH_MODE_AUTO)
2606 wrq->u.data.length = 10;
2608 if (copy_to_user(wrq->u.data.pointer, "auto mode", 10))
2610 return -EFAULT;
2613 else
2615 return -EFAULT;
2619 break;
2622 case ZDAPIOCTL: //debug command
2623 if (copy_from_user(&zdreq, ifr->ifr_data, sizeof (zdreq)))
2625 printk(KERN_ERR "usbdrv: copy_from_user error\n");
2626 return -EFAULT;
2629 //printk(KERN_DEBUG "usbdrv: cmd=%2x, reg=0x%04lx, value=0x%08lx\n",
2630 // zdreq.cmd, zdreq.addr, zdreq.value);
2632 zfLnxPrivateIoctl(dev, &zdreq);
2634 err = 0;
2635 break;
2637 case ZD_IOCTL_WPA:
2638 if (copy_from_user(&zdparm, ifr->ifr_data, sizeof(struct athr_wlan_param)))
2640 printk(KERN_ERR "usbdrv: copy_from_user error\n");
2641 return -EFAULT;
2644 usbdrv_wpa_ioctl(dev, &zdparm);
2645 err = 0;
2646 break;
2648 case ZD_IOCTL_PARAM:
2650 int *p;
2651 int op;
2652 int arg;
2654 /* Point to the name field and retrieve the
2655 * op and arg elements. */
2656 p = (int *)wrq->u.name;
2657 op = *p++;
2658 arg = *p;
2660 if(op == ZD_PARAM_ROAMING)
2662 printk(KERN_ERR "************* ZD_PARAM_ROAMING: %d\n", arg);
2663 //macp->cardSetting.ap_scan=(U8)arg;
2665 if(op == ZD_PARAM_PRIVACY)
2667 printk(KERN_ERR "ZD_IOCTL_PRIVACY: ");
2669 /* Turn on the privacy invoke flag */
2670 if(arg)
2672 // mCap[0] |= CAP_PRIVACY;
2673 // macp->cardSetting.EncryOnOff[0] = 1;
2674 printk(KERN_ERR "enable\n");
2677 else
2679 // mCap[0] &= ~CAP_PRIVACY;
2680 // macp->cardSetting.EncryOnOff[0] = 0;
2681 printk(KERN_ERR "disable\n");
2683 //changed=1;
2685 if(op == ZD_PARAM_WPA)
2687 printk(KERN_ERR "ZD_PARAM_WPA: ");
2689 if(arg)
2691 printk(KERN_ERR "enable\n");
2693 if (zfiWlanQueryWlanMode(dev) != ZM_MODE_AP)
2695 printk(KERN_ERR "Station Mode\n");
2696 //zfiWlanQueryWpaIe(dev, (u8_t *)&wpaIe, &wpalen);
2697 //printk("wpaIe : %2x,%2x,%2x\n", wpaIe[21], wpaIe[22], wpaIe[23]);
2698 //printk("rsnIe : %2x,%2x,%2x\n", wpaIe[17], wpaIe[18], wpaIe[19]);
2699 if ((macp->supIe[21] == 0x50) &&
2700 (macp->supIe[22] == 0xf2) &&
2701 (macp->supIe[23] == 0x2))
2703 printk(KERN_ERR "wd->sta.authMode = ZM_AUTH_MODE_WPAPSK\n");
2704 //wd->sta.authMode = ZM_AUTH_MODE_WPAPSK;
2705 //wd->ws.authMode = ZM_AUTH_MODE_WPAPSK;
2706 zfiWlanSetAuthenticationMode(dev, ZM_AUTH_MODE_WPAPSK);
2708 else if ((macp->supIe[21] == 0x50) &&
2709 (macp->supIe[22] == 0xf2) &&
2710 (macp->supIe[23] == 0x1))
2712 printk(KERN_ERR "wd->sta.authMode = ZM_AUTH_MODE_WPA\n");
2713 //wd->sta.authMode = ZM_AUTH_MODE_WPA;
2714 //wd->ws.authMode = ZM_AUTH_MODE_WPA;
2715 zfiWlanSetAuthenticationMode(dev, ZM_AUTH_MODE_WPA);
2717 else if ((macp->supIe[17] == 0xf) &&
2718 (macp->supIe[18] == 0xac) &&
2719 (macp->supIe[19] == 0x2))
2721 printk(KERN_ERR "wd->sta.authMode = ZM_AUTH_MODE_WPA2PSK\n");
2722 //wd->sta.authMode = ZM_AUTH_MODE_WPA2PSK;
2723 //wd->ws.authMode = ZM_AUTH_MODE_WPA2PSK;
2724 zfiWlanSetAuthenticationMode(dev, ZM_AUTH_MODE_WPA2PSK);
2726 else if ((macp->supIe[17] == 0xf) &&
2727 (macp->supIe[18] == 0xac) &&
2728 (macp->supIe[19] == 0x1))
2730 printk(KERN_ERR "wd->sta.authMode = ZM_AUTH_MODE_WPA2\n");
2731 //wd->sta.authMode = ZM_AUTH_MODE_WPA2;
2732 //wd->ws.authMode = ZM_AUTH_MODE_WPA2;
2733 zfiWlanSetAuthenticationMode(dev, ZM_AUTH_MODE_WPA2);
2735 if ((macp->supIe[21] == 0x50) || (macp->supIe[22] == 0xf2))//WPA or WPAPSK
2737 if (macp->supIe[11] == 0x2)
2739 printk(KERN_ERR "wd->sta.wepStatus = ZM_ENCRYPTION_TKIP\n");
2740 //wd->sta.wepStatus = ZM_ENCRYPTION_TKIP;
2741 //wd->ws.wepStatus = ZM_ENCRYPTION_TKIP;
2742 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_TKIP);
2744 else
2746 printk(KERN_ERR "wd->sta.wepStatus = ZM_ENCRYPTION_AES\n");
2747 //wd->sta.wepStatus = ZM_ENCRYPTION_AES;
2748 //wd->ws.wepStatus = ZM_ENCRYPTION_AES;
2749 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_AES);
2752 if ((macp->supIe[17] == 0xf) || (macp->supIe[18] == 0xac)) //WPA2 or WPA2PSK
2754 if (macp->supIe[13] == 0x2)
2756 printk(KERN_ERR "wd->sta.wepStatus = ZM_ENCRYPTION_TKIP\n");
2757 //wd->sta.wepStatus = ZM_ENCRYPTION_TKIP;
2758 //wd->ws.wepStatus = ZM_ENCRYPTION_TKIP;
2759 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_TKIP);
2761 else
2763 printk(KERN_ERR "wd->sta.wepStatus = ZM_ENCRYPTION_AES\n");
2764 //wd->sta.wepStatus = ZM_ENCRYPTION_AES;
2765 //wd->ws.wepStatus = ZM_ENCRYPTION_AES;
2766 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_AES);
2770 zfiWlanSetWpaSupport(dev, 1);
2772 else
2774 /* Reset the WPA related variables */
2775 printk(KERN_ERR "disable\n");
2777 zfiWlanSetWpaSupport(dev, 0);
2778 zfiWlanSetAuthenticationMode(dev, ZM_AUTH_MODE_OPEN);
2779 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_WEP_DISABLED);
2781 /* Now we only set the length in the WPA IE
2782 * field to zero. */
2783 //macp->cardSetting.WPAIe[1] = 0;
2786 if(op == ZD_PARAM_COUNTERMEASURES)
2788 printk(KERN_ERR "================ZD_PARAM_COUNTERMEASURES: ");
2790 if(arg)
2792 // mCounterMeasureState=1;
2793 printk(KERN_ERR "enable\n");
2795 else
2797 // mCounterMeasureState=0;
2798 printk(KERN_ERR "disable\n");
2801 if(op == ZD_PARAM_DROPUNENCRYPTED)
2803 printk(KERN_ERR "ZD_PARAM_DROPUNENCRYPTED: ");
2805 if(arg)
2807 printk(KERN_ERR "enable\n");
2809 else
2811 printk(KERN_ERR "disable\n");
2814 if(op == ZD_PARAM_AUTH_ALGS)
2816 printk(KERN_ERR "ZD_PARAM_AUTH_ALGS: ");
2818 if(arg == 0)
2820 printk(KERN_ERR "OPEN_SYSTEM\n");
2822 else
2824 printk(KERN_ERR "SHARED_KEY\n");
2827 if(op == ZD_PARAM_WPS_FILTER)
2829 printk(KERN_ERR "ZD_PARAM_WPS_FILTER: ");
2831 if(arg)
2833 // mCounterMeasureState=1;
2834 macp->forwardMgmt = 1;
2835 printk(KERN_ERR "enable\n");
2837 else
2839 // mCounterMeasureState=0;
2840 macp->forwardMgmt = 0;
2841 printk(KERN_ERR "disable\n");
2845 err = 0;
2846 break;
2848 case ZD_IOCTL_GETWPAIE:
2850 struct ieee80211req_wpaie req_wpaie;
2851 u16_t apId, i, j;
2853 /* Get the AP Id */
2854 apId = zfLnxGetVapId(dev);
2856 if (apId == 0xffff)
2858 apId = 0;
2860 else
2862 apId = apId+1;
2865 if (copy_from_user(&req_wpaie, ifr->ifr_data, sizeof(struct ieee80211req_wpaie))){
2866 printk(KERN_ERR "usbdrv: copy_from_user error\n");
2867 return -EFAULT;
2870 for(i = 0; i < ZM_OAL_MAX_STA_SUPPORT; i++)
2872 for(j = 0; j < IEEE80211_ADDR_LEN; j++)
2874 if (macp->stawpaie[i].wpa_macaddr[j] != req_wpaie.wpa_macaddr[j])
2875 break;
2877 if (j == 6)
2878 break;
2880 if (i < ZM_OAL_MAX_STA_SUPPORT)
2882 //printk("ZD_IOCTL_GETWPAIE - sta index = %d\n", i);
2883 memcpy(req_wpaie.wpa_ie, macp->stawpaie[i].wpa_ie, IEEE80211_MAX_IE_SIZE);
2886 if (copy_to_user(wrq->u.data.pointer, &req_wpaie, sizeof(struct ieee80211req_wpaie)))
2888 return -EFAULT;
2892 err = 0;
2893 break;
2894 #ifdef ZM_ENABLE_CENC
2895 case ZM_IOCTL_CENC:
2896 if (copy_from_user(&macp->zd_wpa_req, ifr->ifr_data, sizeof(struct athr_wlan_param)))
2898 printk(KERN_ERR "usbdrv: copy_from_user error\n");
2899 return -EFAULT;
2902 usbdrv_cenc_ioctl(dev, (struct zydas_cenc_param *)&macp->zd_wpa_req);
2903 err = 0;
2904 break;
2905 #endif //ZM_ENABLE_CENC
2906 default:
2907 err = -EOPNOTSUPP;
2908 break;
2912 return err;