• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
usbdrv_freq2chan(u32_t freq)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 
usbdrv_chan2freq(int chan)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 
usbdrv_ioctl_setessid(struct net_device * dev,struct iw_point * erq)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->ml_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 
usbdrv_ioctl_getessid(struct net_device * dev,struct iw_point * erq)225 int usbdrv_ioctl_getessid(struct net_device *dev, struct iw_point *erq)
226 {
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;
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 
usbdrv_ioctl_setrts(struct net_device * dev,struct iw_param * rrq)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  */
encode_ie(void * buf,u32 bufsize,const u8 * ie,u32 ielen,const u8 * leader,u32 leader_len)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  */
usbdrv_translate_scan(struct net_device * dev,struct iw_request_info * info,char * current_ev,char * end_buf,struct zsBssInfo * list)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 	info,
313 	current_ev,
314 	end_buf, &iwe, IW_EV_ADDR_LEN);
315 
316     /* Ran out of buffer */
317     if (last_ev == current_ev)
318     {
319         return end_buf;
320     }
321 
322     last_ev = current_ev;
323 
324 /* Other entries will be displayed in the order we give them */
325 
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]);
335 
336     /* Ran out of buffer */
337     if (last_ev == current_ev)
338     {
339         return end_buf;
340     }
341 
342     last_ev = current_ev;
343 
344 /* Add mode */
345     iwe.cmd = SIOCGIWMODE;
346     capabilities = (list->capability[1] << 8) + list->capability[0];
347     if(capabilities & (0x01 | 0x02))
348     {
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);
356     }
357 
358     /* Ran out of buffer */
359     if (last_ev == current_ev)
360     {
361         return end_buf;
362     }
363 
364     last_ev = current_ev;
365 
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)
371     {
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;
376     }
377     else
378     {
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;
383     }
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);
388 
389     /* Ran out of buffer */
390     if (last_ev == current_ev)
391     {
392         return end_buf;
393     }
394 
395     last_ev = current_ev;
396 
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);
409 
410     /* Ran out of buffer */
411     if (last_ev == current_ev)
412     {
413         return end_buf;
414     }
415 
416     last_ev = current_ev;
417 
418 /* Add encryption capability */
419 
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;
425 
426     iwe.u.data.length = 0;
427     current_ev = iwe_stream_add_point(
428 	info,
429 	current_ev, end_buf, &iwe, list->ssid);
430 
431     /* Ran out of buffer */
432     if (last_ev == current_ev)
433     {
434         return end_buf;
435     }
436 
437     last_ev = current_ev;
438 
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;
442 
443     iwe.cmd = SIOCGIWRATE;
444 /* Those two flags are ignored... */
445     iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
446 
447     for(i = 0 ; i < list->supportedRates[1] ; i++)
448     {
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);
455 
456         /* Ran out of buffer */
457         if (last_ev == current_val)
458         {
459             return end_buf;
460         }
461 
462         last_ev = current_val;
463     }
464 
465     for (i = 0 ; i < list->extSupportedRates[1] ; i++)
466     {
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);
473 
474         /* Ran out of buffer */
475         if (last_ev == current_val)
476         {
477             return end_buf;
478         }
479 
480         last_ev = current_ev;
481     }
482 
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);
495 
496     /* Ran out of buffer */
497     if (last_ev == current_ev)
498     {
499         return end_buf;
500     }
501 
502     last_ev = current_ev;
503 
504     if (list->wpaIe[1] != 0)
505     {
506         static const char rsn_leader[] = "rsn_ie=";
507         static const char wpa_leader[] = "wpa_ie=";
508 
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);
519 
520         if (iwe.u.data.length != 0)
521             current_ev = iwe_stream_add_point(
522 		info,
523 		current_ev, end_buf, &iwe, buf);
524 
525         /* Ran out of buffer */
526         if (last_ev == current_ev)
527         {
528             return end_buf;
529         }
530 
531         last_ev = current_ev;
532     }
533     if (list->rsnIe[1] != 0)
534     {
535         static const char rsn_leader[] = "rsn_ie=";
536         memset(&iwe, 0, sizeof(iwe));
537         iwe.cmd = IWEVCUSTOM;
538 
539         if (list->rsnIe[0] == IEEE80211_ELEMID_RSN)
540         {
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);
548 
549             /* Ran out of buffer */
550             if (last_ev == current_ev)
551             {
552                 return end_buf;
553             }
554 
555             last_ev = current_ev;
556         }
557     }
558 #endif
559 /* The other data in the scan result are not really
560  * interesting, so for now drop it */
561     return current_ev;
562 }
563 
usbdrvwext_giwname(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrq,char * extra)564 int usbdrvwext_giwname(struct net_device *dev,
565             struct iw_request_info *info,
566             union iwreq_data *wrq, char *extra)
567 {
568     //struct usbdrv_private *macp = dev->ml_priv;
569 
570     strcpy(wrq->name, "IEEE 802.11-MIMO");
571 
572     return 0;
573 }
574 
usbdrvwext_siwfreq(struct net_device * dev,struct iw_request_info * info,struct iw_freq * freq,char * extra)575 int usbdrvwext_siwfreq(struct net_device *dev,
576             struct iw_request_info *info,
577             struct iw_freq *freq, char *extra)
578 {
579     u32_t FreqKHz;
580     struct usbdrv_private *macp = dev->ml_priv;
581 
582     if(!netif_running(dev))
583         return -EINVAL;
584 
585     if (freq->e > 1)
586         return -EINVAL;
587 
588     if (freq->e == 1)
589     {
590         FreqKHz = (freq->m / 100000);
591 
592         if (FreqKHz > 4000000)
593         {
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;
602         }
603         else
604         {
605             if (FreqKHz > 2484000)
606                 FreqKHz = 2484000;
607             else if (FreqKHz < 2412000)
608                 FreqKHz = 2412000;
609             else
610                 FreqKHz = (((FreqKHz - 2412000) / 5000) * 5000) + 2412000;
611         }
612 
613     }
614     else
615     {
616         FreqKHz = usbdrv_chan2freq(freq->m);
617 
618         if (FreqKHz != -1)
619             FreqKHz *= 1000;
620         else
621             FreqKHz = 2412000;
622     }
623 
624     //printk("freq->m: %d, freq->e: %d\n", freq->m, freq->e);
625     //printk("FreqKHz: %d\n", FreqKHz);
626 
627     if (macp->DeviceOpened == 1)
628     {
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);
636     }
637 
638     return 0;
639 }
640 
usbdrvwext_giwfreq(struct net_device * dev,struct iw_request_info * info,struct iw_freq * freq,char * extra)641 int usbdrvwext_giwfreq(struct net_device *dev,
642             struct iw_request_info *info,
643             struct iw_freq *freq, char *extra)
644 {
645     struct usbdrv_private *macp = dev->ml_priv;
646 
647     if (macp->DeviceOpened != 1)
648         return 0;
649 
650     freq->m = zfiWlanQueryFrequency(dev);
651     freq->e = 3;
652 
653     return 0;
654 }
655 
usbdrvwext_siwmode(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrq,char * extra)656 int usbdrvwext_siwmode(struct net_device *dev,
657             struct iw_request_info *info,
658             union iwreq_data *wrq, char *extra)
659 {
660     struct usbdrv_private *macp = dev->ml_priv;
661     u8_t WlanMode;
662 
663     if(!netif_running(dev))
664         return -EINVAL;
665 
666     if (macp->DeviceOpened != 1)
667         return 0;
668 
669     switch(wrq->mode)
670     {
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;
683     }
684 
685     zfiWlanSetWlanMode(dev,WlanMode);
686     zfiWlanDisable(dev, 1);
687     zfiWlanEnable(dev);
688 
689     return 0;
690 }
691 
usbdrvwext_giwmode(struct net_device * dev,struct iw_request_info * info,__u32 * mode,char * extra)692 int usbdrvwext_giwmode(struct net_device *dev,
693             struct iw_request_info *info,
694             __u32 *mode, char *extra)
695 {
696     unsigned long irqFlag;
697     struct usbdrv_private *macp = dev->ml_priv;
698 
699     if(!netif_running(dev))
700         return -EINVAL;
701 
702     if (macp->DeviceOpened != 1)
703         return 0;
704 
705     spin_lock_irqsave(&macp->cs_lock, irqFlag);
706 
707     switch(zfiWlanQueryWlanMode(dev))
708     {
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;
721     }
722 
723     spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
724 
725     return 0;
726 }
727 
usbdrvwext_siwsens(struct net_device * dev,struct iw_request_info * info,struct iw_param * sens,char * extra)728 int usbdrvwext_siwsens(struct net_device *dev,
729 			struct iw_request_info *info,
730 			struct iw_param *sens, char *extra)
731 {
732 	return 0;
733 }
734 
usbdrvwext_giwsens(struct net_device * dev,struct iw_request_info * info,struct iw_param * sens,char * extra)735 int usbdrvwext_giwsens(struct net_device *dev,
736 			struct iw_request_info *info,
737 			struct iw_param *sens, char *extra)
738 {
739 	sens->value = 0;
740 	sens->fixed = 1;
741 
742 	return 0;
743 }
744 
usbdrvwext_giwrange(struct net_device * dev,struct iw_request_info * info,struct iw_point * data,char * extra)745 int usbdrvwext_giwrange(struct net_device *dev,
746             struct iw_request_info *info,
747             struct iw_point *data, char *extra)
748 {
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;
754 
755     if(!netif_running(dev))
756         return -EINVAL;
757 
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
762 
763 #if WIRELESS_EXT > 10
764     range->we_version_compiled = WIRELESS_EXT;
765     range->we_version_source = 13;
766 
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 */
772 
773     channel_num = zfiWlanQueryAllowChannels(dev, channels);
774 
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;
778 
779     val = 0;
780 
781     for (i = 0; i < channel_num; i++)
782     {
783         range->freq[val].i = usbdrv_freq2chan(channels[i]);
784         range->freq[val].m = channels[i];
785         range->freq[val].e = 6;
786         val++;
787     }
788 
789     range->num_channels = channel_num;
790     range->num_frequency = channel_num;
791 
792 #if 0
793     range->num_channels = 14; // Only 2.4G
794 
795 /* XXX need to filter against the regulatory domain &| active set */
796     val = 0;
797     for (i = 1; i <= 14; i++) // B,G Bands
798     {
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++;
806     }
807 
808     num_band_a = (IW_MAX_FREQUENCIES - val);
809 
810     for (i = 0; i < num_band_a; i++) // A Bands
811     {
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++;
816     }
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
821 
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; //??
827 
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; //??
835 
836     range->encoding_size[0] = 5; //??               //WEP Key Encoding Size
837     range->encoding_size[1] = 13;//??
838 
839 // XXX what about num_bitrates/throughput?
840     range->num_bitrates = 0; //??
841 
842 /* estimated max throughput */
843 // XXX need to cap it if we're running at ~2Mbps..
844 
845     range->throughput = 300000000;
846 
847     return 0;
848 }
849 
usbdrvwext_siwap(struct net_device * dev,struct iw_request_info * info,struct sockaddr * MacAddr,char * extra)850 int usbdrvwext_siwap(struct net_device *dev, struct iw_request_info *info,
851         struct sockaddr *MacAddr, char *extra)
852 {
853     struct usbdrv_private *macp = dev->ml_priv;
854 
855     if(!netif_running(dev))
856         return -EINVAL;
857 
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]);
862 
863     if (macp->DeviceOpened == 1)
864     {
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);
871     }
872 
873     return 0;
874 }
875 
usbdrvwext_giwap(struct net_device * dev,struct iw_request_info * info,struct sockaddr * MacAddr,char * extra)876 int usbdrvwext_giwap(struct net_device *dev,
877             struct iw_request_info *info,
878             struct sockaddr *MacAddr, char *extra)
879 {
880     struct usbdrv_private *macp = dev->ml_priv;
881 
882     if (macp->DeviceOpened != 1)
883         return 0;
884 
885     if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) // AP Mode
886         zfiWlanQueryMacAddress(dev, &MacAddr->sa_data[0]);
887     else                                 //STA Mode
888     {
889         if (macp->adapterState == ZM_STATUS_MEDIA_CONNECT)
890         {
891             zfiWlanQueryBssid(dev, &MacAddr->sa_data[0]);
892         }
893         else
894         {
895             u8_t zero_addr[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
896             memcpy(&MacAddr->sa_data[0], zero_addr, sizeof(zero_addr));
897         }
898     }
899 
900     return 0;
901 }
902 
usbdrvwext_iwaplist(struct net_device * dev,struct iw_request_info * info,struct iw_point * data,char * extra)903 int usbdrvwext_iwaplist(struct net_device *dev,
904 			struct iw_request_info *info,
905 			struct iw_point *data, char *extra)
906 {
907     //Don't know how to do yet--CWYang(+)
908     return 0;
909 
910 }
911 
usbdrvwext_siwscan(struct net_device * dev,struct iw_request_info * info,struct iw_point * data,char * extra)912 int usbdrvwext_siwscan(struct net_device *dev, struct iw_request_info *info,
913         struct iw_point *data, char *extra)
914 {
915     struct usbdrv_private *macp = dev->ml_priv;
916 
917     if (macp->DeviceOpened != 1)
918         return 0;
919 
920     printk("CWY - usbdrvwext_siwscan\n");
921 
922     zfiWlanScan(dev);
923 
924     return 0;
925 }
926 
usbdrvwext_giwscan(struct net_device * dev,struct iw_request_info * info,struct iw_point * data,char * extra)927 int usbdrvwext_giwscan(struct net_device *dev,
928             struct iw_request_info *info,
929             struct iw_point *data, char *extra)
930 {
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);
940 
941     if (macp->DeviceOpened != 1)
942         return 0;
943 
944     if (data->length == 0)
945     {
946        end_buf = extra + IW_SCAN_MAX_DATA;
947     }
948     else
949     {
950         end_buf = extra + data->length;
951     }
952 
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);
959 
960 /* Read and parse all entries */
961     printk("giwscan - pBssList->bssCount : %d\n", pBssList->bssCount);
962     //printk("giwscan - BssList.bssCount : %d\n", BssList.bssCount);
963 
964     for (i = 0; i < pBssList->bssCount; i++)
965     {
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]);
971 
972 #if WIRELESS_EXT > 16
973         if (current_ev == end_buf)
974         {
975             kfree(pBssList);
976             data->length = current_ev - extra;
977             return -E2BIG;
978         }
979 #endif
980     }
981 
982 /* Length of data */
983     data->length = (current_ev - extra);
984     data->flags = 0;                              /* todo */
985 
986     kfree(pBssList);
987 
988     return 0;
989 }
990 
usbdrvwext_siwessid(struct net_device * dev,struct iw_request_info * info,struct iw_point * essid,char * extra)991 int usbdrvwext_siwessid(struct net_device *dev,
992             struct iw_request_info *info,
993             struct iw_point *essid, char *extra)
994 {
995     char EssidBuf[IW_ESSID_MAX_SIZE+1];
996     struct usbdrv_private *macp = dev->ml_priv;
997 
998     if(!netif_running(dev))
999         return -EINVAL;
1000 
1001     if (essid->flags == 1)
1002     {
1003         if (essid->length > (IW_ESSID_MAX_SIZE+1))
1004             return -E2BIG;
1005 
1006         if (copy_from_user(&EssidBuf, essid->pointer, essid->length))
1007             return -EFAULT;
1008 
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)
1014         {
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);
1024         }
1025     }
1026 
1027     return 0;
1028 }
1029 
usbdrvwext_giwessid(struct net_device * dev,struct iw_request_info * info,struct iw_point * essid,char * extra)1030 int usbdrvwext_giwessid(struct net_device *dev,
1031             struct iw_request_info *info,
1032             struct iw_point *essid, char *extra)
1033 {
1034     struct usbdrv_private *macp = dev->ml_priv;
1035     u8_t EssidLen;
1036     char EssidBuf[IW_ESSID_MAX_SIZE+1];
1037     int ssid_len;
1038 
1039     if(!netif_running(dev))
1040         return -EINVAL;
1041 
1042     if (macp->DeviceOpened != 1)
1043         return 0;
1044 
1045     zfiWlanQuerySSID(dev, &EssidBuf[0], &EssidLen);
1046 
1047     /* Convert type from unsigned char to char */
1048     ssid_len = (int)EssidLen;
1049 
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;
1053 
1054     EssidBuf[ssid_len] = '\0';
1055 
1056     essid->flags = 1;
1057     essid->length = strlen(EssidBuf);
1058 
1059     memcpy(extra, EssidBuf, essid->length);
1060     // wireless.c in Kernel would handle copy_to_user -- line 679
1061     /*if (essid->pointer)
1062     {
1063         if ( copy_to_user(essid->pointer, EssidBuf, essid->length) )
1064         {
1065             printk("giwessid - copy_to_user Fail\n");
1066             return -EFAULT;
1067         }
1068     }*/
1069 
1070     return 0;
1071 }
1072 
usbdrvwext_siwnickn(struct net_device * dev,struct iw_request_info * info,struct iw_point * data,char * nickname)1073 int usbdrvwext_siwnickn(struct net_device *dev,
1074 			struct iw_request_info *info,
1075 			struct iw_point *data, char *nickname)
1076 {
1077     //Exist but junk--CWYang(+)
1078 	return 0;
1079 }
1080 
usbdrvwext_giwnickn(struct net_device * dev,struct iw_request_info * info,struct iw_point * data,char * nickname)1081 int usbdrvwext_giwnickn(struct net_device *dev,
1082 			struct iw_request_info *info,
1083 			struct iw_point *data, char *nickname)
1084 {
1085     struct usbdrv_private *macp = dev->ml_priv;
1086     u8_t EssidLen;
1087     char EssidBuf[IW_ESSID_MAX_SIZE+1];
1088 
1089     if (macp->DeviceOpened != 1)
1090         return 0;
1091 
1092     zfiWlanQuerySSID(dev, &EssidBuf[0], &EssidLen);
1093     EssidBuf[EssidLen] = 0;
1094 
1095     data->flags = 1;
1096     data->length = strlen(EssidBuf);
1097 
1098     memcpy(nickname, EssidBuf, data->length);
1099 
1100 	return 0;
1101 }
1102 
usbdrvwext_siwrate(struct net_device * dev,struct iw_request_info * info,struct iw_param * frq,char * extra)1103 int usbdrvwext_siwrate(struct net_device *dev,
1104             struct iw_request_info *info,
1105             struct iw_param *frq, char *extra)
1106 {
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;
1115 
1116     //printk("frq->disabled : 0x%x\n",frq->disabled);
1117     //printk("frq->value : 0x%x\n",frq->value);
1118 
1119     RateKbps = frq->value / 1000;
1120     //printk("RateKbps : %d\n", RateKbps);
1121     for (i = 0; i < 16; i++)
1122     {
1123         if (RateKbps == zcIndextoRateBG[i])
1124             RateIndex = i;
1125     }
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)
1134     {
1135         RateIndex = 20;
1136         printk("RateIndex : %d\n", RateIndex);
1137     }
1138     if (macp->DeviceOpened == 1)
1139     {
1140         zfiWlanSetTxRate(dev, i);
1141         //zfiWlanDisable(dev);
1142         //zfiWlanEnable(dev);
1143     }
1144 
1145     return 0;
1146 }
1147 
usbdrvwext_giwrate(struct net_device * dev,struct iw_request_info * info,struct iw_param * frq,char * extra)1148 int usbdrvwext_giwrate(struct net_device *dev,
1149             struct iw_request_info *info,
1150             struct iw_param *frq, char *extra)
1151 {
1152     struct usbdrv_private *macp = dev->ml_priv;
1153 
1154     if(!netif_running(dev))
1155         return -EINVAL;
1156 
1157     if (macp->DeviceOpened != 1)
1158         return 0;
1159 
1160     frq->fixed = 0;
1161     frq->disabled = 0;
1162     frq->value = zfiWlanQueryRxRate(dev) * 1000;
1163 
1164     return 0;
1165 }
1166 
usbdrvwext_siwrts(struct net_device * dev,struct iw_request_info * info,struct iw_param * rts,char * extra)1167 int usbdrvwext_siwrts(struct net_device *dev,
1168             struct iw_request_info *info,
1169             struct iw_param *rts, char *extra)
1170 {
1171     struct usbdrv_private *macp = dev->ml_priv;
1172     int val = rts->value;
1173 
1174     if (macp->DeviceOpened != 1)
1175         return 0;
1176 
1177     if (rts->disabled)
1178         val = 2347;
1179 
1180     if ((val < 0) || (val > 2347))
1181         return -EINVAL;
1182 
1183     zfiWlanSetRtsThreshold(dev,val);
1184 
1185     return 0;
1186 }
1187 
usbdrvwext_giwrts(struct net_device * dev,struct iw_request_info * info,struct iw_param * rts,char * extra)1188 int usbdrvwext_giwrts(struct net_device *dev,
1189             struct iw_request_info *info,
1190             struct iw_param *rts, char *extra)
1191 {
1192     struct usbdrv_private *macp = dev->ml_priv;
1193 
1194     if(!netif_running(dev))
1195         return -EINVAL;
1196 
1197     if (macp->DeviceOpened != 1)
1198         return 0;
1199 
1200     rts->value = zfiWlanQueryRtsThreshold(dev);
1201     rts->disabled = (rts->value >= 2347);
1202     rts->fixed = 1;
1203 
1204     return 0;
1205 
1206 }
1207 
usbdrvwext_siwfrag(struct net_device * dev,struct iw_request_info * info,struct iw_param * frag,char * extra)1208 int usbdrvwext_siwfrag(struct net_device *dev,
1209             struct iw_request_info *info,
1210             struct iw_param *frag, char *extra)
1211 {
1212     struct usbdrv_private *macp = dev->ml_priv;
1213     u16_t fragThreshold;
1214 
1215     if (macp->DeviceOpened != 1)
1216         return 0;
1217 
1218     if (frag->disabled)
1219         fragThreshold = 0;
1220     else
1221         fragThreshold = frag->value;
1222 
1223     zfiWlanSetFragThreshold(dev,fragThreshold);
1224 
1225     return 0;
1226 }
1227 
usbdrvwext_giwfrag(struct net_device * dev,struct iw_request_info * info,struct iw_param * frag,char * extra)1228 int usbdrvwext_giwfrag(struct net_device *dev,
1229             struct iw_request_info *info,
1230             struct iw_param *frag, char *extra)
1231 {
1232     struct usbdrv_private *macp = dev->ml_priv;
1233     u16 val;
1234     unsigned long irqFlag;
1235 
1236     if(!netif_running(dev))
1237         return -EINVAL;
1238 
1239     if (macp->DeviceOpened != 1)
1240         return 0;
1241 
1242     spin_lock_irqsave(&macp->cs_lock, irqFlag);
1243 
1244     val = zfiWlanQueryFragThreshold(dev);
1245 
1246     frag->value = val;
1247 
1248     frag->disabled = (val >= 2346);
1249     frag->fixed = 1;
1250 
1251     spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
1252 
1253     return 0;
1254 }
1255 
usbdrvwext_siwtxpow(struct net_device * dev,struct iw_request_info * info,struct iw_param * rrq,char * extra)1256 int usbdrvwext_siwtxpow(struct net_device *dev,
1257 			struct iw_request_info *info,
1258 			struct iw_param *rrq, char *extra)
1259 {
1260     //Not support yet--CWYng(+)
1261 	return 0;
1262 }
1263 
usbdrvwext_giwtxpow(struct net_device * dev,struct iw_request_info * info,struct iw_param * rrq,char * extra)1264 int usbdrvwext_giwtxpow(struct net_device *dev,
1265 			struct iw_request_info *info,
1266 			struct iw_param *rrq, char *extra)
1267 {
1268     //Not support yet--CWYng(+)
1269 	return 0;
1270 }
1271 
usbdrvwext_siwretry(struct net_device * dev,struct iw_request_info * info,struct iw_param * rrq,char * extra)1272 int usbdrvwext_siwretry(struct net_device *dev,
1273 			struct iw_request_info *info,
1274 			struct iw_param *rrq, char *extra)
1275 {
1276     //Do nothing--CWYang(+)
1277 	return 0;
1278 }
1279 
usbdrvwext_giwretry(struct net_device * dev,struct iw_request_info * info,struct iw_param * rrq,char * extra)1280 int usbdrvwext_giwretry(struct net_device *dev,
1281 			struct iw_request_info *info,
1282 			struct iw_param *rrq, char *extra)
1283 {
1284     //Do nothing--CWYang(+)
1285 	return 0;
1286 }
1287 
usbdrvwext_siwencode(struct net_device * dev,struct iw_request_info * info,struct iw_point * erq,char * key)1288 int usbdrvwext_siwencode(struct net_device *dev,
1289             struct iw_request_info *info,
1290             struct iw_point *erq, char *key)
1291 {
1292     struct zsKeyInfo keyInfo;
1293     int i, WepState = ZM_ENCRYPTION_WEP_DISABLED;
1294     struct usbdrv_private *macp = dev->ml_priv;
1295 
1296     if(!netif_running(dev))
1297         return -EINVAL;
1298 
1299     if ((erq->flags & IW_ENCODE_DISABLED) == 0)
1300     {
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;
1307 
1308         zfiWlanSetKey(dev, keyInfo);
1309         WepState = ZM_ENCRYPTION_WEP_ENABLED;
1310     }
1311     else
1312     {
1313         for (i = 1; i < 4; i++)
1314             zfiWlanRemoveKey(dev, 0, i);
1315         WepState = ZM_ENCRYPTION_WEP_DISABLED;
1316         //zfiWlanSetEncryMode(dev, ZM_NO_WEP);
1317     }
1318 
1319     if (macp->DeviceOpened == 1)
1320     {
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);
1330     }
1331 
1332     return 0;
1333 }
1334 
usbdrvwext_giwencode(struct net_device * dev,struct iw_request_info * info,struct iw_point * erq,char * key)1335 int usbdrvwext_giwencode(struct net_device *dev,
1336             struct iw_request_info *info,
1337             struct iw_point *erq, char *key)
1338 {
1339     struct usbdrv_private *macp = dev->ml_priv;
1340     u8_t EncryptionMode;
1341     u8_t keyLen = 0;
1342 
1343     if (macp->DeviceOpened != 1)
1344         return 0;
1345 
1346     EncryptionMode = zfiWlanQueryEncryMode(dev);
1347 
1348     if (EncryptionMode)
1349     {
1350         erq->flags = IW_ENCODE_ENABLED;
1351     }
1352     else
1353     {
1354         erq->flags = IW_ENCODE_DISABLED;
1355     }
1356 
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);
1360 
1361 /* Copy the key to the user buffer */
1362     switch(EncryptionMode)
1363     {
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;
1391 
1392     }
1393     erq->length = keyLen;
1394 
1395     return 0;
1396 }
1397 
usbdrvwext_siwpower(struct net_device * dev,struct iw_request_info * info,struct iw_param * frq,char * extra)1398 int usbdrvwext_siwpower(struct net_device *dev,
1399             struct iw_request_info *info,
1400             struct iw_param *frq, char *extra)
1401 {
1402     struct usbdrv_private *macp = dev->ml_priv;
1403     u8_t PSMode;
1404 
1405     if (macp->DeviceOpened != 1)
1406         return 0;
1407 
1408     if (frq->disabled)
1409         PSMode = ZM_STA_PS_NONE;
1410     else
1411         PSMode = ZM_STA_PS_MAX;
1412 
1413     zfiWlanSetPowerSaveMode(dev,PSMode);
1414 
1415     return 0;
1416 }
1417 
usbdrvwext_giwpower(struct net_device * dev,struct iw_request_info * info,struct iw_param * frq,char * extra)1418 int usbdrvwext_giwpower(struct net_device *dev,
1419             struct iw_request_info *info,
1420             struct iw_param *frq, char *extra)
1421 {
1422     unsigned long irqFlag;
1423     struct usbdrv_private *macp = dev->ml_priv;
1424 
1425     if (macp->DeviceOpened != 1)
1426         return 0;
1427 
1428     spin_lock_irqsave(&macp->cs_lock, irqFlag);
1429 
1430     if (zfiWlanQueryPowerSaveMode(dev) == ZM_STA_PS_NONE)
1431         frq->disabled = 1;
1432     else
1433         frq->disabled = 0;
1434 
1435     spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
1436 
1437     return 0;
1438 }
1439 
1440 //int usbdrvwext_setparam(struct net_device *dev, struct iw_request_info *info,
1441 //		   	 void *w, char *extra)
1442 //{
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;
1453 //
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;
1939 //}
1940 
usbdrvwext_setmode(struct net_device * dev,struct iw_request_info * info,void * w,char * extra)1941 int usbdrvwext_setmode(struct net_device *dev, struct iw_request_info *info,
1942 		   	 void *w, char *extra)
1943 {
1944 	return 0;
1945 }
1946 
usbdrvwext_getmode(struct net_device * dev,struct iw_request_info * info,void * w,char * extra)1947 int usbdrvwext_getmode(struct net_device *dev, struct iw_request_info *info,
1948 			void *w, char *extra)
1949 {
1950 	//struct usbdrv_private *macp = dev->ml_priv;
1951 	struct iw_point *wri = (struct iw_point *)extra;
1952 	char mode[8];
1953 
1954     strcpy(mode,"11g");
1955 	return (copy_to_user(wri->pointer, mode, 6) ? -EFAULT : 0);
1956 }
1957 
zfLnxPrivateIoctl(struct net_device * dev,struct zdap_ioctl * zdreq)1958 int zfLnxPrivateIoctl(struct net_device *dev, struct zdap_ioctl* zdreq)
1959 {
1960 	//void* regp = macp->regp;
1961 	u16_t cmd;
1962 	//u32_t temp;
1963 	u32_t* p;
1964 	u32_t i;
1965 
1966 	cmd = zdreq->cmd;
1967 	switch(cmd)
1968 	{
1969 	case ZM_IOCTL_REG_READ:
1970 		zfiDbgReadReg(dev, zdreq->addr);
1971 		break;
1972 
1973 	case ZM_IOCTL_REG_WRITE:
1974 		zfiDbgWriteReg(dev, zdreq->addr, zdreq->value);
1975 		break;
1976 
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;
1981 
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;
1987 
1988 	case ZM_IOCTL_TALLY :
1989 		zfiWlanShowTally(dev);
1990 		if (zdreq->addr)
1991 			zfiWlanResetTally(dev);
1992 		break;
1993 
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++)
2002             {
2003                 if ((i&0x7) == 0)
2004                 {
2005                     printk("\n");
2006                 }
2007                 printk("%02X ", (unsigned char)zdreq->data[i]);
2008             }
2009             printk("\n");
2010             #endif
2011 
2012 
2013             #if 0 //For Test?? 1 to 0 by CWYang(-)
2014             {
2015             struct sk_buff* s;
2016 
2017             /* Allocate a skb */
2018             s = alloc_skb(2000, GFP_ATOMIC);
2019 
2020             /* Copy data to skb */
2021             for (i=0; i<zdreq->addr; i++)
2022             {
2023                 s->data[i] = zdreq->data[i];
2024             }
2025             s->len = zdreq->addr;
2026 
2027             /* Call zfIdlRecv() */
2028             zfiRecv80211(dev, s, NULL);
2029             }
2030             #endif
2031 
2032             break;
2033 
2034 
2035 /****************************** ZDCONFIG ******************************/
2036         case ZM_IOCTL_FRAG :
2037             zfiWlanSetFragThreshold(dev, zdreq->addr);
2038             break;
2039 
2040         case ZM_IOCTL_RTS :
2041             zfiWlanSetRtsThreshold(dev, zdreq->addr);
2042             break;
2043 
2044         case ZM_IOCTL_SCAN :
2045             zfiWlanScan(dev);
2046             break;
2047 
2048         case ZM_IOCTL_KEY :
2049             {
2050                 u8_t key[29];
2051                 struct zsKeyInfo keyInfo;
2052                 u32_t i;
2053 
2054                 for (i=0; i<29; i++)
2055                 {
2056                     key[i] = 0;
2057                 }
2058 
2059                 for (i=0; i<zdreq->addr; i++)
2060                 {
2061                     key[i] = zdreq->data[i];
2062                 }
2063 
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]);
2066 
2067                 keyInfo.keyLength = zdreq->addr;
2068                 keyInfo.keyIndex = 0;
2069                 keyInfo.flag = 0;
2070                 keyInfo.key = key;
2071                 zfiWlanSetKey(dev, keyInfo);
2072             }
2073             break;
2074 
2075         case ZM_IOCTL_RATE :
2076             zfiWlanSetTxRate(dev, zdreq->addr);
2077             break;
2078 
2079         case ZM_IOCTL_ENCRYPTION_MODE :
2080             zfiWlanSetEncryMode(dev, zdreq->addr);
2081 
2082             zfiWlanDisable(dev, 0);
2083             zfiWlanEnable(dev);
2084             break;
2085         //CWYang(+)
2086         case ZM_IOCTL_SIGNAL_STRENGTH :
2087             {
2088                 u8_t buffer[2];
2089                 zfiWlanQuerySignalInfo(dev, &buffer[0]);
2090                 printk("Current Signal Strength : %02d\n", buffer[0]);
2091             }
2092             break;
2093         //CWYang(+)
2094         case ZM_IOCTL_SIGNAL_QUALITY :
2095             {
2096                 u8_t buffer[2];
2097                 zfiWlanQuerySignalInfo(dev, &buffer[0]);
2098                 printk("Current Signal Quality : %02d\n", buffer[1]);
2099             }
2100             break;
2101 
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);
2107 
2108 		zfiWlanDisable(dev, 0);
2109 		zfiWlanEnable(dev);
2110 
2111 		break;
2112 /****************************** ZDCONFIG ******************************/
2113 
2114 	default :
2115 		printk(KERN_ERR "usbdrv: error command = %x\n", cmd);
2116 		break;
2117 	}
2118 
2119 	return 0;
2120 }
2121 
usbdrv_wpa_ioctl(struct net_device * dev,struct athr_wlan_param * zdparm)2122 int usbdrv_wpa_ioctl(struct net_device *dev, struct athr_wlan_param *zdparm)
2123 {
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;
2130 
2131     //zmw_get_wlan_dev(dev);
2132 
2133     switch(zdparm->cmd)
2134     {
2135         case ZD_CMD_SET_ENCRYPT_KEY:
2136 
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;
2147 
2148             /* Identify the MAC address information */
2149             if (memcmp(zdparm->sta_addr, bc_addr, sizeof(bc_addr)) == 0)
2150             {
2151                 keyInfo.flag |= ZM_KEY_FLAG_GK;
2152             }
2153             else
2154             {
2155                 keyInfo.flag |= ZM_KEY_FLAG_PK;
2156             }
2157 
2158             if (!strcmp(zdparm->u.crypt.alg, "NONE"))
2159             {
2160                 //u8_t zero_mac[]={0,0,0,0,0,0};
2161 
2162                 /* Set key length to zero */
2163                 keyInfo.keyLength = 0;
2164 
2165                 if (zdparm->sta_addr[0] & 1)//del group key
2166                 {
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;
2174                     //}
2175                     //mWpaBcKeyLen = mGkInstalled = 0;
2176                 }
2177                 else
2178                 {
2179                     //if (memcmp(zero_mac,zdparm->sta_addr, 6)==0)
2180                     //{
2181                     //    mDynKeyMode=0;
2182                     //    mKeyFormat[0]=0;
2183                     //    pSetting->DynKeyMode=0;
2184                     //    pSetting->EncryMode[0]=0;
2185                     //    mDynKeyMode=0;
2186                     //}
2187                 }
2188 
2189                 printk(KERN_ERR "Set Encryption Type NONE\n");
2190                 return ret;
2191             }
2192             else if (!strcmp(zdparm->u.crypt.alg, "TKIP"))
2193             {
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++)
2203                 //{
2204                 //    temp = keyInfo.key[16 + k];
2205                 //    keyInfo.key[16 + k] = keyInfo.key[24 + k];
2206                 //    keyInfo.key[24 + k] = temp;
2207                 //}
2208                 //CamEncryType = ZM_TKIP;
2209                 ////if (idx == 0)
2210                 //{// Pairwise key
2211                 //    mKeyFormat[0] = CamEncryType;
2212                 //    mDynKeyMode = pSetting->DynKeyMode = DYN_KEY_TKIP;
2213                 //}
2214             }
2215             else if (!strcmp(zdparm->u.crypt.alg, "CCMP"))
2216             {
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;
2223                 //}
2224             }
2225             else if (!strcmp(zdparm->u.crypt.alg, "WEP"))
2226             {
2227                 if (keyInfo.keyLength == 5)
2228                 { // WEP 64
2229                     zfiWlanSetEncryMode(dev, ZM_WEP64);
2230                 //    CamEncryType = ZM_WEP64;
2231                 //    tmpDynKeyMode=DYN_KEY_WEP64;
2232                 }
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;
2238                 }
2239                 else
2240                 {
2241                     zfiWlanSetEncryMode(dev, ZM_WEP256);
2242                 }
2243 
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)
2251                 //{
2252                 //    mKeyFormat[0] = CamEncryType;
2253                 //    mDynKeyMode = pSetting->DynKeyMode = tmpDynKeyMode;
2254                 //    mPrivacyInvoked[0]=TRUE;
2255                 //    mCap[0] |= CAP_PRIVACY;
2256                 //    macp->cardSetting.EncryOnOff[0]=1;
2257                 //}
2258             }
2259 
2260             /* DUMP key context */
2261 //#ifdef WPA_DEBUG
2262             if (keyInfo.keyLength > 0)
2263             {
2264                 int ii;
2265                 printk("Otus: Key Context:\n");
2266                 for(ii = 0; ii < keyInfo.keyLength;)
2267                 {
2268                     printk("0x%02x ", keyInfo.key[ii]);
2269                     if((++ii % 16) == 0)
2270                         printk("\n");
2271                 }
2272                 printk("\n");
2273             }
2274 //#endif
2275 
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];
2286 
2287             zfiWlanSetKey(dev, keyInfo);
2288 
2289             //zfiWlanDisable(dev);
2290             //zfiWlanEnable(dev);
2291             break;
2292 
2293         case ZD_CMD_SET_MLME:
2294             printk(KERN_ERR "usbdrv_wpa_ioctl: ZD_CMD_SET_MLME\n");
2295 
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]);
2299 
2300             switch(zdparm->u.mlme.cmd)
2301             {
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;
2309 
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;
2317 
2318                 default:
2319                     printk(KERN_ERR "MLME command: 0x%04x not support\n", zdparm->u.mlme.cmd);
2320                     break;
2321             }
2322 
2323             break;
2324 
2325         case ZD_CMD_SCAN_REQ:
2326             printk(KERN_ERR "usbdrv_wpa_ioctl: ZD_CMD_SCAN_REQ\n");
2327             break;
2328 
2329         case ZD_CMD_SET_GENERIC_ELEMENT:
2330             printk(KERN_ERR "usbdrv_wpa_ioctl: ZD_CMD_SET_GENERIC_ELEMENT\n");
2331 
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
2336             {
2337                 zfiWlanSetWpaIe(dev, zdparm->u.generic_elem.data, zdparm->u.generic_elem.len);
2338             }
2339             else
2340             {
2341                 macp->supLen = zdparm->u.generic_elem.len;
2342                 memcpy(macp->supIe, zdparm->u.generic_elem.data, zdparm->u.generic_elem.len);
2343             }
2344             zfiWlanSetWpaSupport(dev, 1);
2345             //zfiWlanSetWpaIe(dev, zdparm->u.generic_elem.data, zdparm->u.generic_elem.len);
2346             {
2347                 int ii;
2348                 u8_t len = zdparm->u.generic_elem.len;
2349                 u8_t *wpaie = (u8_t *)zdparm->u.generic_elem.data;
2350 
2351                 printk(KERN_ERR "wd->ap.wpaLen: %d\n", len);
2352 
2353                 /* DUMP WPA IE */
2354                 for(ii = 0; ii < len;)
2355                 {
2356                     printk(KERN_ERR "0x%02x ", wpaie[ii]);
2357 
2358                     if((++ii % 16) == 0)
2359                         printk(KERN_ERR "\n");
2360                 }
2361                 printk(KERN_ERR "\n");
2362             }
2363 
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");
2369             //}
2370 //            #endif
2371             break;
2372 
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
2378 
2379         default:
2380             printk(KERN_ERR "usbdrv_wpa_ioctl default: 0x%04x\n", zdparm->cmd);
2381             ret = -EINVAL;
2382             break;
2383     }
2384 
2385     return ret;
2386 }
2387 
2388 #ifdef ZM_ENABLE_CENC
usbdrv_cenc_ioctl(struct net_device * dev,struct zydas_cenc_param * zdparm)2389 int usbdrv_cenc_ioctl(struct net_device *dev, struct zydas_cenc_param *zdparm)
2390 {
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;
2397 
2398     /* Get the AP Id */
2399     apId = zfLnxGetVapId(dev);
2400 
2401     if (apId == 0xffff)
2402     {
2403         apId = 0;
2404     }
2405     else
2406     {
2407         apId = apId+1;
2408     }
2409 
2410     switch (zdparm->cmd)
2411     {
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");
2420 
2421             printk(KERN_ERR "MAC address= ");
2422             for(ii = 0; ii < 6; ii++)
2423             {
2424                 printk(KERN_ERR "0x%02x ", zdparm->u.crypt.sta_addr[ii]);
2425             }
2426             printk(KERN_ERR "\n");
2427 
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++)
2431             {
2432                 printk(KERN_ERR "0x%02x ", zdparm->u.crypt.key[ii]);
2433             }
2434             printk(KERN_ERR "\n");
2435 
2436             printk(KERN_ERR "MIC key= ");
2437             for(ii = 16; ii < ZM_CENC_KEY_SIZE; ii++)
2438             {
2439                 printk(KERN_ERR "0x%02x ", zdparm->u.crypt.key[ii]);
2440             }
2441             printk(KERN_ERR "\n");
2442 
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;
2449 
2450             /* Identify the MAC address information */
2451             if (memcmp(zdparm->u.crypt.sta_addr, bc_addr, sizeof(bc_addr)) == 0)
2452             {
2453                 keyInfo.flag |= ZM_KEY_FLAG_GK;
2454                 keyInfo.vapId = apId;
2455                 memcpy(keyInfo.vapAddr, dev->dev_addr, ETH_ALEN);
2456             }
2457             else
2458             {
2459                 keyInfo.flag |= ZM_KEY_FLAG_PK;
2460             }
2461 
2462             zfiWlanSetKey(dev, keyInfo);
2463 
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;
2472 
2473     }
2474 
2475     //if (retv == ENETRESET)
2476     //    retv = IS_UP_AUTO(vap) ? ieee80211_open(vap->iv_dev) : 0;
2477 
2478     return ret;
2479 }
2480 #endif //ZM_ENABLE_CENC
2481 /////////////////////////////////////////
usbdrv_ioctl(struct net_device * dev,struct ifreq * ifr,int cmd)2482 int usbdrv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2483 {
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;
2490 
2491     int err = 0;
2492     int changed = 0;
2493 
2494 //    regp = macp->regp;
2495 
2496     if(!netif_running(dev))
2497         return -EINVAL;
2498 
2499     switch (cmd)
2500     {
2501             case SIOCGIWNAME:
2502             strcpy(wrq->u.name, "IEEE 802.11-DS");
2503             break;
2504 
2505         case SIOCGIWAP:
2506             err = usbdrvwext_giwap(dev, NULL, &wrq->u.ap_addr, NULL);
2507             break;
2508 
2509 
2510         case SIOCSIWAP:
2511             err = usbdrvwext_siwap(dev, NULL, &wrq->u.ap_addr, NULL);
2512             break;
2513 
2514 
2515         case SIOCGIWMODE:
2516             err = usbdrvwext_giwmode(dev, NULL, &wrq->u.mode, NULL);
2517             break;
2518 
2519 
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);
2524 
2525             if (! err)
2526                 changed = 1;
2527             break;
2528 
2529 
2530         case SIOCGIWESSID:
2531             err = usbdrvwext_giwessid(dev, NULL, &wrq->u.essid, NULL);
2532             break;
2533 
2534 
2535         case SIOCSIWRTS:
2536 
2537             err = usbdrv_ioctl_setrts(dev, &wrq->u.rts);
2538             if (! err)
2539                 changed = 1;
2540             break;
2541 
2542 
2543 		case SIOCIWFIRSTPRIV + 0x2: /* set_auth */
2544 		{
2545 			//printk("CWY - SIOCIWFIRSTPRIV + 0x2 (set_auth)\n");
2546 			if (! capable(CAP_NET_ADMIN))
2547 			{
2548 				err = -EPERM;
2549 				break;
2550 			}
2551 			{
2552 				int val = *( (int *) wrq->u.name );
2553 				if ((val < 0) || (val > 2))
2554 				{
2555 					err = -EINVAL;
2556 					break;
2557 				}
2558 				else
2559 				{
2560 					zfiWlanSetAuthenticationMode(dev, val);
2561 
2562                     if (macp->DeviceOpened == 1)
2563                     {
2564                         zfiWlanDisable(dev, 0);
2565                         zfiWlanEnable(dev);
2566                     }
2567 
2568 					err = 0;
2569 					changed = 1;
2570 				}
2571 			}
2572 		}
2573 			break;
2574 
2575 		case SIOCIWFIRSTPRIV + 0x3: /* get_auth */
2576 		{
2577 		    int AuthMode = ZM_AUTH_MODE_OPEN;
2578 
2579 			//printk("CWY - SIOCIWFIRSTPRIV + 0x3 (get_auth)\n");
2580 
2581 			if (wrq->u.data.pointer)
2582 			{
2583 				wrq->u.data.flags = 1;
2584 
2585 				AuthMode = zfiWlanQueryAuthenticationMode(dev, 0);
2586 				if (AuthMode == ZM_AUTH_MODE_OPEN)
2587 				{
2588 					wrq->u.data.length = 12;
2589 
2590 					if (copy_to_user(wrq->u.data.pointer, "open system", 12))
2591 					{
2592 						return -EFAULT;
2593 					}
2594 				}
2595 				else if (AuthMode == ZM_AUTH_MODE_SHARED_KEY)
2596 				{
2597 					wrq->u.data.length = 11;
2598 
2599 					if (copy_to_user(wrq->u.data.pointer, "shared key", 11))
2600 					{
2601 						return -EFAULT;
2602 					}
2603 				}
2604 				else if (AuthMode == ZM_AUTH_MODE_AUTO)
2605 				{
2606 					wrq->u.data.length = 10;
2607 
2608 					if (copy_to_user(wrq->u.data.pointer, "auto mode", 10))
2609 					{
2610 						return -EFAULT;
2611 					}
2612 				}
2613 				else
2614 				{
2615 					return -EFAULT;
2616 				}
2617 			}
2618 		}
2619 			break;
2620 
2621 
2622         case ZDAPIOCTL:    //debug command
2623             if (copy_from_user(&zdreq, ifr->ifr_data, sizeof (zdreq)))
2624             {
2625                 printk(KERN_ERR "usbdrv: copy_from_user error\n");
2626                 return -EFAULT;
2627             }
2628 
2629             //printk(KERN_DEBUG "usbdrv: cmd=%2x, reg=0x%04lx, value=0x%08lx\n",
2630             //        zdreq.cmd, zdreq.addr, zdreq.value);
2631 
2632 			zfLnxPrivateIoctl(dev, &zdreq);
2633 
2634             err = 0;
2635             break;
2636 
2637         case ZD_IOCTL_WPA:
2638             if (copy_from_user(&zdparm, ifr->ifr_data, sizeof(struct athr_wlan_param)))
2639             {
2640                 printk(KERN_ERR "usbdrv: copy_from_user error\n");
2641                 return -EFAULT;
2642             }
2643 
2644             usbdrv_wpa_ioctl(dev, &zdparm);
2645             err = 0;
2646             break;
2647 
2648         case ZD_IOCTL_PARAM:
2649         {
2650             int *p;
2651             int op;
2652             int arg;
2653 
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;
2659 
2660             if(op == ZD_PARAM_ROAMING)
2661             {
2662                 printk(KERN_ERR "************* ZD_PARAM_ROAMING: %d\n", arg);
2663                 //macp->cardSetting.ap_scan=(U8)arg;
2664             }
2665             if(op == ZD_PARAM_PRIVACY)
2666             {
2667                 printk(KERN_ERR "ZD_IOCTL_PRIVACY: ");
2668 
2669                 /* Turn on the privacy invoke flag */
2670                 if(arg)
2671                 {
2672                 //    mCap[0] |= CAP_PRIVACY;
2673                 //    macp->cardSetting.EncryOnOff[0] = 1;
2674                     printk(KERN_ERR "enable\n");
2675 
2676                 }
2677                 else
2678                 {
2679                 //    mCap[0] &= ~CAP_PRIVACY;
2680                 //    macp->cardSetting.EncryOnOff[0] = 0;
2681                     printk(KERN_ERR "disable\n");
2682                 }
2683                                 //changed=1;
2684             }
2685             if(op == ZD_PARAM_WPA)
2686             {
2687                 printk(KERN_ERR "ZD_PARAM_WPA: ");
2688 
2689                 if(arg)
2690                 {
2691                     printk(KERN_ERR "enable\n");
2692 
2693                     if (zfiWlanQueryWlanMode(dev) != ZM_MODE_AP)
2694                     {
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))
2702                         {
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);
2707                         }
2708                         else if ((macp->supIe[21] == 0x50) &&
2709                                  (macp->supIe[22] == 0xf2) &&
2710                                  (macp->supIe[23] == 0x1))
2711                         {
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);
2716                         }
2717                         else if ((macp->supIe[17] == 0xf) &&
2718                                  (macp->supIe[18] == 0xac) &&
2719                                  (macp->supIe[19] == 0x2))
2720                         {
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);
2725                         }
2726                         else if ((macp->supIe[17] == 0xf) &&
2727                                  (macp->supIe[18] == 0xac) &&
2728                                  (macp->supIe[19] == 0x1))
2729                         {
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);
2734                         }
2735                         if ((macp->supIe[21] == 0x50) || (macp->supIe[22] == 0xf2))//WPA or WPAPSK
2736                         {
2737                             if (macp->supIe[11] == 0x2)
2738                             {
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);
2743                             }
2744                             else
2745                             {
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);
2750                             }
2751                         }
2752                         if ((macp->supIe[17] == 0xf) || (macp->supIe[18] == 0xac)) //WPA2 or WPA2PSK
2753                         {
2754                             if (macp->supIe[13] == 0x2)
2755                             {
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);
2760                             }
2761                             else
2762                             {
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);
2767                             }
2768                         }
2769                     }
2770                     zfiWlanSetWpaSupport(dev, 1);
2771                 }
2772                 else
2773                 {
2774                     /* Reset the WPA related variables */
2775                     printk(KERN_ERR "disable\n");
2776 
2777                     zfiWlanSetWpaSupport(dev, 0);
2778                     zfiWlanSetAuthenticationMode(dev, ZM_AUTH_MODE_OPEN);
2779                     zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_WEP_DISABLED);
2780 
2781                     /* Now we only set the length in the WPA IE
2782                      * field to zero.                         */
2783                     //macp->cardSetting.WPAIe[1] = 0;
2784                 }
2785             }
2786             if(op == ZD_PARAM_COUNTERMEASURES)
2787             {
2788                 printk(KERN_ERR "================ZD_PARAM_COUNTERMEASURES: ");
2789 
2790                 if(arg)
2791                 {
2792                 //    mCounterMeasureState=1;
2793                     printk(KERN_ERR "enable\n");
2794                 }
2795                 else
2796                 {
2797                 //    mCounterMeasureState=0;
2798                     printk(KERN_ERR "disable\n");
2799                 }
2800             }
2801             if(op == ZD_PARAM_DROPUNENCRYPTED)
2802             {
2803                 printk(KERN_ERR "ZD_PARAM_DROPUNENCRYPTED: ");
2804 
2805                 if(arg)
2806                 {
2807                     printk(KERN_ERR "enable\n");
2808                 }
2809                 else
2810                 {
2811                     printk(KERN_ERR "disable\n");
2812                 }
2813             }
2814             if(op == ZD_PARAM_AUTH_ALGS)
2815             {
2816                 printk(KERN_ERR "ZD_PARAM_AUTH_ALGS: ");
2817 
2818                 if(arg == 0)
2819                 {
2820                     printk(KERN_ERR "OPEN_SYSTEM\n");
2821                 }
2822                 else
2823                 {
2824                     printk(KERN_ERR "SHARED_KEY\n");
2825                 }
2826             }
2827             if(op == ZD_PARAM_WPS_FILTER)
2828             {
2829                 printk(KERN_ERR "ZD_PARAM_WPS_FILTER: ");
2830 
2831                 if(arg)
2832                 {
2833                 //    mCounterMeasureState=1;
2834                     macp->forwardMgmt = 1;
2835                     printk(KERN_ERR "enable\n");
2836                 }
2837                 else
2838                 {
2839                 //    mCounterMeasureState=0;
2840                     macp->forwardMgmt = 0;
2841                     printk(KERN_ERR "disable\n");
2842                 }
2843             }
2844         }
2845             err = 0;
2846             break;
2847 
2848         case ZD_IOCTL_GETWPAIE:
2849         {
2850             struct ieee80211req_wpaie req_wpaie;
2851             u16_t apId, i, j;
2852 
2853             /* Get the AP Id */
2854             apId = zfLnxGetVapId(dev);
2855 
2856             if (apId == 0xffff)
2857             {
2858                 apId = 0;
2859             }
2860             else
2861             {
2862                 apId = apId+1;
2863             }
2864 
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;
2868             }
2869 
2870             for(i = 0; i < ZM_OAL_MAX_STA_SUPPORT; i++)
2871             {
2872                 for(j = 0; j < IEEE80211_ADDR_LEN; j++)
2873                 {
2874                     if (macp->stawpaie[i].wpa_macaddr[j] != req_wpaie.wpa_macaddr[j])
2875                         break;
2876                 }
2877                 if (j == 6)
2878                     break;
2879             }
2880             if (i < ZM_OAL_MAX_STA_SUPPORT)
2881             {
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);
2884             }
2885 
2886             if (copy_to_user(wrq->u.data.pointer, &req_wpaie, sizeof(struct ieee80211req_wpaie)))
2887             {
2888                     return -EFAULT;
2889             }
2890         }
2891 
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)))
2897             {
2898                 printk(KERN_ERR "usbdrv: copy_from_user error\n");
2899                 return -EFAULT;
2900             }
2901 
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;
2909     }
2910 
2911 
2912     return err;
2913 }
2914