2 * Copyright (c) 2007-2008 Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 /* Module Name : ioctl.c */
20 /* This module contains Linux wireless extension related functons. */
23 /* Platform dependent. */
25 /************************************************************************/
26 #include <linux/module.h>
27 #include <linux/if_arp.h>
28 #include <asm/uaccess.h>
32 #define ZD_IOCTL_WPA (SIOCDEVPRIVATE + 1)
33 #define ZD_IOCTL_PARAM (SIOCDEVPRIVATE + 2)
34 #define ZD_IOCTL_GETWPAIE (SIOCDEVPRIVATE + 3)
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
47 #define P80211_PACKET_CENCFLAG 0x0001
48 #endif //ZM_ENABLE_CENC
49 #define P80211_PACKET_SETKEY 0x0003
51 #define ZD_CMD_SET_ENCRYPT_KEY 0x0001
52 #define ZD_CMD_SET_MLME 0x0002
53 #define ZD_CMD_SCAN_REQ 0x0003
54 #define ZD_CMD_SET_GENERIC_ELEMENT 0x0004
55 #define ZD_CMD_GET_TSC 0x0005
57 #define ZD_CRYPT_ALG_NAME_LEN 16
58 #define ZD_MAX_KEY_SIZE 32
59 #define ZD_MAX_GENERIC_SIZE 64
62 #include <net/iw_handler.h>
65 extern u16_t zfLnxGetVapId(zdev_t* dev);
67 static const u32_t channel_frequency_11A[] =
69 //Even element for Channel Number, Odd for Frequency
110 int usbdrv_freq2chan(u32_t freq)
113 if (freq > 2400 && freq < 3000)
115 return ((freq-2412)/5) + 1;
120 u16_t num_chan = sizeof(channel_frequency_11A)/sizeof(u32_t);
122 for(ii = 1; ii < num_chan; ii += 2)
124 if (channel_frequency_11A[ii] == freq)
125 return channel_frequency_11A[ii-1];
132 int usbdrv_chan2freq(int chan)
136 /* If channel number is out of range */
137 if (chan > 165 || chan <= 0)
141 if (chan >= 1 && chan <= 13)
143 freq = (2412 + (chan - 1) * 5);
146 else if (chan >= 36 && chan <= 165)
149 u16_t num_chan = sizeof(channel_frequency_11A)/sizeof(u32_t);
151 for(ii = 0; ii < num_chan; ii += 2)
153 if (channel_frequency_11A[ii] == chan)
154 return channel_frequency_11A[ii+1];
157 /* Can't find desired frequency */
162 /* Can't find deisred frequency */
166 int usbdrv_ioctl_setessid(struct net_device *dev, struct iw_point *erq)
168 #ifdef ZM_HOSTAPD_SUPPORT
169 //struct usbdrv_private *macp = dev->ml_priv;
170 char essidbuf[IW_ESSID_MAX_SIZE+1];
173 if(!netif_running(dev))
176 memset(essidbuf, 0, sizeof(essidbuf));
178 printk(KERN_ERR "usbdrv_ioctl_setessid\n");
180 //printk("ssidlen=%d\n", erq->length); //for any, it is 1.
182 if (erq->length > (IW_ESSID_MAX_SIZE+1))
185 if (copy_from_user(essidbuf, erq->pointer, erq->length))
192 printk(KERN_ERR "essidbuf: ");
194 for(i = 0; i < erq->length; i++)
196 printk(KERN_ERR "%02x ", essidbuf[i]);
199 printk(KERN_ERR "\n");
201 essidbuf[erq->length] = '\0';
202 //memcpy(macp->wd.ws.ssid, essidbuf, erq->length);
203 //macp->wd.ws.ssidLen = strlen(essidbuf)+2;
204 //macp->wd.ws.ssid[1] = strlen(essidbuf); // Update ssid length
206 zfiWlanSetSSID(dev, essidbuf, erq->length);
208 printk(KERN_ERR "macp->wd.ws.ssid: ");
210 for(i = 0; i < macp->wd.ws.ssidLen; i++)
212 printk(KERN_ERR "%02x ", macp->wd.ws.ssid[i]);
215 printk(KERN_ERR "\n");
217 zfiWlanDisable(dev, 0);
225 int usbdrv_ioctl_getessid(struct net_device *dev, struct iw_point *erq)
227 //struct usbdrv_private *macp = dev->ml_priv;
228 u8_t essidbuf[IW_ESSID_MAX_SIZE+1];
233 //len = macp->wd.ws.ssidLen;
234 //memcpy(essidbuf, macp->wd.ws.ssid, macp->wd.ws.ssidLen);
235 zfiWlanQuerySSID(dev, essidbuf, &len);
239 printk(KERN_ERR "ESSID: ");
241 for(i = 0; i < len; i++)
243 printk(KERN_ERR "%c", essidbuf[i]);
246 printk(KERN_ERR "\n");
249 erq->length = strlen(essidbuf) + 1;
252 if (copy_to_user(erq->pointer, essidbuf, erq->length))
259 int usbdrv_ioctl_setrts(struct net_device *dev, struct iw_param *rrq)
265 #if WIRELESS_EXT > 14
267 * Encode a WPA or RSN information element as a custom
268 * element using the hostap format.
270 u32 encode_ie(void *buf, u32 bufsize, const u8 *ie, u32 ielen, const u8 *leader, u32 leader_len)
275 if (bufsize < leader_len)
278 memcpy(p, leader, leader_len);
279 bufsize -= leader_len;
281 for (i = 0; i < ielen && bufsize > 2; i++)
282 p += sprintf(p, "%02x", ie[i]);
283 return (i == ielen ? p - (u8 *)buf : 0);
285 #endif /* WIRELESS_EXT > 14 */
287 /*------------------------------------------------------------------*/
289 * Translate scan data returned from the card to a card independent
290 * format that the Wireless Tools will understand
292 char *usbdrv_translate_scan(struct net_device *dev,
293 struct iw_request_info *info, char *current_ev,
294 char *end_buf, struct zsBssInfo *list)
296 struct iw_event iwe; /* Temporary buffer */
298 char *current_val; /* For rates */
301 #if WIRELESS_EXT > 14
305 last_ev = current_ev;
307 /* First entry *MUST* be the AP MAC address */
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(
314 end_buf, &iwe, IW_EV_ADDR_LEN);
316 /* Ran out of buffer */
317 if (last_ev == current_ev)
322 last_ev = current_ev;
324 /* Other entries will be displayed in the order we give them */
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(
334 current_ev, end_buf, &iwe, &list->ssid[2]);
336 /* Ran out of buffer */
337 if (last_ev == current_ev)
342 last_ev = current_ev;
345 iwe.cmd = SIOCGIWMODE;
346 capabilities = (list->capability[1] << 8) + list->capability[0];
347 if(capabilities & (0x01 | 0x02))
349 if(capabilities & 0x01)
350 iwe.u.mode = IW_MODE_MASTER;
352 iwe.u.mode = IW_MODE_ADHOC;
353 current_ev = iwe_stream_add_event(
355 current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
358 /* Ran out of buffer */
359 if (last_ev == current_ev)
364 last_ev = current_ev;
367 iwe.cmd = SIOCGIWFREQ;
368 iwe.u.freq.m = list->channel;
369 /* Channel frequency in KHz */
370 if (iwe.u.freq.m > 14)
372 if ((184 <= iwe.u.freq.m) && (iwe.u.freq.m<=196))
373 iwe.u.freq.m = 4000 + iwe.u.freq.m * 5;
375 iwe.u.freq.m = 5000 + iwe.u.freq.m * 5;
379 if (iwe.u.freq.m == 14)
382 iwe.u.freq.m = 2412 + (iwe.u.freq.m - 1) * 5;
385 current_ev = iwe_stream_add_event(
387 current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
389 /* Ran out of buffer */
390 if (last_ev == current_ev)
395 last_ev = current_ev;
397 /* Add quality statistics */
399 #if WIRELESS_EXT > 18
400 iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED
401 |IW_QUAL_NOISE_UPDATED;
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(
408 current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
410 /* Ran out of buffer */
411 if (last_ev == current_ev)
416 last_ev = current_ev;
418 /* Add encryption capability */
420 iwe.cmd = SIOCGIWENCODE;
421 if(capabilities & 0x10)
422 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
424 iwe.u.data.flags = IW_ENCODE_DISABLED;
426 iwe.u.data.length = 0;
427 current_ev = iwe_stream_add_point(
429 current_ev, end_buf, &iwe, list->ssid);
431 /* Ran out of buffer */
432 if (last_ev == current_ev)
437 last_ev = current_ev;
439 /* Rate : stuffing multiple values in a single event require a bit
441 current_val = current_ev + IW_EV_LCP_LEN;
443 iwe.cmd = SIOCGIWRATE;
444 /* Those two flags are ignored... */
445 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
447 for(i = 0 ; i < list->supportedRates[1] ; i++)
449 /* Bit rate given in 500 kb/s units (+ 0x80) */
450 iwe.u.bitrate.value = ((list->supportedRates[i+2] & 0x7f) * 500000);
451 /* Add new value to event */
452 current_val = iwe_stream_add_value(
454 current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
456 /* Ran out of buffer */
457 if (last_ev == current_val)
462 last_ev = current_val;
465 for (i = 0 ; i < list->extSupportedRates[1] ; i++)
467 /* Bit rate given in 500 kb/s units (+ 0x80) */
468 iwe.u.bitrate.value = ((list->extSupportedRates[i+2] & 0x7f) * 500000);
469 /* Add new value to event */
470 current_val = iwe_stream_add_value(
472 current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
474 /* Ran out of buffer */
475 if (last_ev == current_val)
480 last_ev = current_ev;
483 /* Check if we added any event */
484 if((current_val - current_ev) > IW_EV_LCP_LEN)
485 current_ev = current_val;
486 #if WIRELESS_EXT > 14
487 #define IEEE80211_ELEMID_RSN 0x30
488 memset(&iwe, 0, sizeof(iwe));
489 iwe.cmd = IWEVCUSTOM;
490 snprintf(buf, sizeof(buf), "bcn_int=%d", (list->beaconInterval[1] << 8) + list->beaconInterval[0]);
491 iwe.u.data.length = strlen(buf);
492 current_ev = iwe_stream_add_point(
494 current_ev, end_buf, &iwe, buf);
496 /* Ran out of buffer */
497 if (last_ev == current_ev)
502 last_ev = current_ev;
504 if (list->wpaIe[1] != 0)
506 static const char rsn_leader[] = "rsn_ie=";
507 static const char wpa_leader[] = "wpa_ie=";
509 memset(&iwe, 0, sizeof(iwe));
510 iwe.cmd = IWEVCUSTOM;
511 if (list->wpaIe[0] == IEEE80211_ELEMID_RSN)
512 iwe.u.data.length = encode_ie(buf, sizeof(buf),
513 list->wpaIe, list->wpaIe[1]+2,
514 rsn_leader, sizeof(rsn_leader)-1);
516 iwe.u.data.length = encode_ie(buf, sizeof(buf),
517 list->wpaIe, list->wpaIe[1]+2,
518 wpa_leader, sizeof(wpa_leader)-1);
520 if (iwe.u.data.length != 0)
521 current_ev = iwe_stream_add_point(
523 current_ev, end_buf, &iwe, buf);
525 /* Ran out of buffer */
526 if (last_ev == current_ev)
531 last_ev = current_ev;
533 if (list->rsnIe[1] != 0)
535 static const char rsn_leader[] = "rsn_ie=";
536 memset(&iwe, 0, sizeof(iwe));
537 iwe.cmd = IWEVCUSTOM;
539 if (list->rsnIe[0] == IEEE80211_ELEMID_RSN)
541 iwe.u.data.length = encode_ie(buf, sizeof(buf),
542 list->rsnIe, list->rsnIe[1]+2,
543 rsn_leader, sizeof(rsn_leader)-1);
544 if (iwe.u.data.length != 0)
545 current_ev = iwe_stream_add_point(
547 current_ev, end_buf, &iwe, buf);
549 /* Ran out of buffer */
550 if (last_ev == current_ev)
555 last_ev = current_ev;
559 /* The other data in the scan result are not really
560 * interesting, so for now drop it */
564 int usbdrvwext_giwname(struct net_device *dev,
565 struct iw_request_info *info,
566 union iwreq_data *wrq, char *extra)
568 //struct usbdrv_private *macp = dev->ml_priv;
570 strcpy(wrq->name, "IEEE 802.11-MIMO");
575 int usbdrvwext_siwfreq(struct net_device *dev,
576 struct iw_request_info *info,
577 struct iw_freq *freq, char *extra)
580 struct usbdrv_private *macp = dev->ml_priv;
582 if(!netif_running(dev))
590 FreqKHz = (freq->m / 100000);
592 if (FreqKHz > 4000000)
594 if (FreqKHz > 5825000)
596 else if (FreqKHz < 4920000)
598 else if (FreqKHz < 5000000)
599 FreqKHz = (((FreqKHz - 4000000) / 5000) * 5000) + 4000000;
601 FreqKHz = (((FreqKHz - 5000000) / 5000) * 5000) + 5000000;
605 if (FreqKHz > 2484000)
607 else if (FreqKHz < 2412000)
610 FreqKHz = (((FreqKHz - 2412000) / 5000) * 5000) + 2412000;
616 FreqKHz = usbdrv_chan2freq(freq->m);
624 //printk("freq->m: %d, freq->e: %d\n", freq->m, freq->e);
625 //printk("FreqKHz: %d\n", FreqKHz);
627 if (macp->DeviceOpened == 1)
629 zfiWlanSetFrequency(dev, FreqKHz, 0); // Immediate
630 //u8_t wpaieLen,wpaie[50];
631 //zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen);
632 zfiWlanDisable(dev, 0);
635 // zfiWlanSetWpaIe(dev, wpaie, wpaieLen);
641 int usbdrvwext_giwfreq(struct net_device *dev,
642 struct iw_request_info *info,
643 struct iw_freq *freq, char *extra)
645 struct usbdrv_private *macp = dev->ml_priv;
647 if (macp->DeviceOpened != 1)
650 freq->m = zfiWlanQueryFrequency(dev);
656 int usbdrvwext_siwmode(struct net_device *dev,
657 struct iw_request_info *info,
658 union iwreq_data *wrq, char *extra)
660 struct usbdrv_private *macp = dev->ml_priv;
663 if(!netif_running(dev))
666 if (macp->DeviceOpened != 1)
672 WlanMode = ZM_MODE_AP;
675 WlanMode = ZM_MODE_INFRASTRUCTURE;
678 WlanMode = ZM_MODE_IBSS;
681 WlanMode = ZM_MODE_IBSS;
685 zfiWlanSetWlanMode(dev,WlanMode);
686 zfiWlanDisable(dev, 1);
692 int usbdrvwext_giwmode(struct net_device *dev,
693 struct iw_request_info *info,
694 __u32 *mode, char *extra)
696 unsigned long irqFlag;
697 struct usbdrv_private *macp = dev->ml_priv;
699 if(!netif_running(dev))
702 if (macp->DeviceOpened != 1)
705 spin_lock_irqsave(&macp->cs_lock, irqFlag);
707 switch(zfiWlanQueryWlanMode(dev))
710 *mode = IW_MODE_MASTER;
712 case ZM_MODE_INFRASTRUCTURE:
713 *mode = IW_MODE_INFRA;
716 *mode = IW_MODE_ADHOC;
719 *mode = IW_MODE_ADHOC;
723 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
728 int usbdrvwext_siwsens(struct net_device *dev,
729 struct iw_request_info *info,
730 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)
745 int usbdrvwext_giwrange(struct net_device *dev,
746 struct iw_request_info *info,
747 struct iw_point *data, char *extra)
749 struct iw_range *range = (struct iw_range *) extra;
755 if(!netif_running(dev))
759 range->txpower_capa = IW_TXPOW_DBM;
760 // XXX what about min/max_pmp, min/max_pmt, etc.
763 #if WIRELESS_EXT > 10
764 range->we_version_compiled = WIRELESS_EXT;
765 range->we_version_source = 13;
767 range->retry_capa = IW_RETRY_LIMIT;
768 range->retry_flags = IW_RETRY_LIMIT;
769 range->min_retry = 0;
770 range->max_retry = 255;
771 #endif /* WIRELESS_EXT > 10 */
773 channel_num = zfiWlanQueryAllowChannels(dev, channels);
775 /* Gurantee reported channel numbers is less or equal to IW_MAX_FREQUENCIES */
776 if (channel_num > IW_MAX_FREQUENCIES)
777 channel_num = IW_MAX_FREQUENCIES;
781 for (i = 0; i < channel_num; i++)
783 range->freq[val].i = usbdrv_freq2chan(channels[i]);
784 range->freq[val].m = channels[i];
785 range->freq[val].e = 6;
789 range->num_channels = channel_num;
790 range->num_frequency = channel_num;
793 range->num_channels = 14; // Only 2.4G
795 /* XXX need to filter against the regulatory domain &| active set */
797 for (i = 1; i <= 14; i++) // B,G Bands
799 range->freq[val].i = i;
801 range->freq[val].m = 2484000;
803 range->freq[val].m = (2412+(i-1)*5)*1000;
804 range->freq[val].e = 3;
808 num_band_a = (IW_MAX_FREQUENCIES - val);
810 for (i = 0; i < num_band_a; i++) // A Bands
812 range->freq[val].i = channel_frequency_11A[2 * i];
813 range->freq[val].m = channel_frequency_11A[2 * i + 1] * 1000;
814 range->freq[val].e = 3;
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;
822 /* Max of /proc/net/wireless */
823 range->max_qual.qual = 100; //?? //92;
824 range->max_qual.level = 154; //??
825 range->max_qual.noise = 154; //??
826 range->sensitivity = 3; //??
828 // XXX these need to be nsd-specific!
830 range->max_rts = 2347;
831 range->min_frag = 256;
832 range->max_frag = 2346;
833 range->max_encoding_tokens = 4/*NUM_WEPKEYS*/; //??
834 range->num_encoding_sizes = 2; //??
836 range->encoding_size[0] = 5; //?? //WEP Key Encoding Size
837 range->encoding_size[1] = 13;//??
839 // XXX what about num_bitrates/throughput?
840 range->num_bitrates = 0; //??
842 /* estimated max throughput */
843 // XXX need to cap it if we're running at ~2Mbps..
845 range->throughput = 300000000;
850 int usbdrvwext_siwap(struct net_device *dev, struct iw_request_info *info,
851 struct sockaddr *MacAddr, char *extra)
853 struct usbdrv_private *macp = dev->ml_priv;
855 if(!netif_running(dev))
858 if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) // AP Mode
859 zfiWlanSetMacAddress(dev,(u16_t *)&MacAddr->sa_data[0]);
861 zfiWlanSetBssid(dev,&MacAddr->sa_data[0]);
863 if (macp->DeviceOpened == 1)
865 //u8_t wpaieLen,wpaie[80];
866 //zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen);
867 zfiWlanDisable(dev, 0);
870 // zfiWlanSetWpaIe(dev, wpaie, wpaieLen);
876 int usbdrvwext_giwap(struct net_device *dev,
877 struct iw_request_info *info,
878 struct sockaddr *MacAddr, char *extra)
880 struct usbdrv_private *macp = dev->ml_priv;
882 if (macp->DeviceOpened != 1)
885 if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) // AP Mode
886 zfiWlanQueryMacAddress(dev, &MacAddr->sa_data[0]);
889 if (macp->adapterState == ZM_STATUS_MEDIA_CONNECT)
891 zfiWlanQueryBssid(dev, &MacAddr->sa_data[0]);
895 u8_t zero_addr[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
896 memcpy(&MacAddr->sa_data[0], zero_addr, sizeof(zero_addr));
903 int usbdrvwext_iwaplist(struct net_device *dev,
904 struct iw_request_info *info,
905 struct iw_point *data, char *extra)
907 //Don't know how to do yet--CWYang(+)
912 int usbdrvwext_siwscan(struct net_device *dev, struct iw_request_info *info,
913 struct iw_point *data, char *extra)
915 struct usbdrv_private *macp = dev->ml_priv;
917 if (macp->DeviceOpened != 1)
920 printk("CWY - usbdrvwext_siwscan\n");
927 int usbdrvwext_giwscan(struct net_device *dev,
928 struct iw_request_info *info,
929 struct iw_point *data, char *extra)
931 struct usbdrv_private *macp = dev->ml_priv;
932 //struct zsWlanDev* wd = (struct zsWlanDev*) zmw_wlan_dev(dev);
933 char *current_ev = extra;
936 //struct zsBssList BssList;
937 struct zsBssListV1 *pBssList = kmalloc(sizeof(struct zsBssListV1), GFP_KERNEL);
938 //BssList = wd->sta.pBssList;
939 //zmw_get_wlan_dev(dev);
941 if (macp->DeviceOpened != 1)
944 if (data->length == 0)
946 end_buf = extra + IW_SCAN_MAX_DATA;
950 end_buf = extra + data->length;
953 printk("giwscan - Report Scan Results\n");
954 //printk("giwscan - BssList Sreucture Len : %d\n", sizeof(BssList));
955 //printk("giwscan - BssList Count : %d\n", wd->sta.pBssList->bssCount);
956 //printk("giwscan - UpdateBssList Count : %d\n", wd->sta.pUpdateBssList->bssCount);
957 zfiWlanQueryBssListV1(dev, pBssList);
958 //zfiWlanQueryBssList(dev, &BssList);
960 /* Read and parse all entries */
961 printk("giwscan - pBssList->bssCount : %d\n", pBssList->bssCount);
962 //printk("giwscan - BssList.bssCount : %d\n", BssList.bssCount);
964 for (i = 0; i < pBssList->bssCount; i++)
966 /* Translate to WE format this entry */
967 //current_ev = usbdrv_translate_scan(dev, info, current_ev,
968 // extra + IW_SCAN_MAX_DATA, &pBssList->bssInfo[i]);
969 current_ev = usbdrv_translate_scan(dev, info, current_ev,
970 end_buf, &pBssList->bssInfo[i]);
972 #if WIRELESS_EXT > 16
973 if (current_ev == end_buf)
976 data->length = current_ev - extra;
983 data->length = (current_ev - extra);
984 data->flags = 0; /* todo */
991 int usbdrvwext_siwessid(struct net_device *dev,
992 struct iw_request_info *info,
993 struct iw_point *essid, char *extra)
995 char EssidBuf[IW_ESSID_MAX_SIZE+1];
996 struct usbdrv_private *macp = dev->ml_priv;
998 if(!netif_running(dev))
1001 if (essid->flags == 1)
1003 if (essid->length > (IW_ESSID_MAX_SIZE+1))
1006 if (copy_from_user(&EssidBuf, essid->pointer, essid->length))
1009 EssidBuf[essid->length] = '\0';
1010 //printk("siwessid - Set Essid : %s\n",EssidBuf);
1011 //printk("siwessid - Essid Len : %d\n",essid->length);
1012 //printk("siwessid - Essid Flag : %x\n",essid->flags);
1013 if (macp->DeviceOpened == 1)
1015 zfiWlanSetSSID(dev, EssidBuf, strlen(EssidBuf));
1016 zfiWlanSetFrequency(dev, zfiWlanQueryFrequency(dev), FALSE);
1017 zfiWlanSetEncryMode(dev, zfiWlanQueryEncryMode(dev));
1018 //u8_t wpaieLen,wpaie[50];
1019 //zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen);
1020 zfiWlanDisable(dev, 0);
1023 // zfiWlanSetWpaIe(dev, wpaie, wpaieLen);
1030 int usbdrvwext_giwessid(struct net_device *dev,
1031 struct iw_request_info *info,
1032 struct iw_point *essid, char *extra)
1034 struct usbdrv_private *macp = dev->ml_priv;
1036 char EssidBuf[IW_ESSID_MAX_SIZE+1];
1039 if(!netif_running(dev))
1042 if (macp->DeviceOpened != 1)
1045 zfiWlanQuerySSID(dev, &EssidBuf[0], &EssidLen);
1047 /* Convert type from unsigned char to char */
1048 ssid_len = (int)EssidLen;
1050 /* Make sure the essid length is not greater than IW_ESSID_MAX_SIZE */
1051 if (ssid_len > IW_ESSID_MAX_SIZE)
1052 ssid_len = IW_ESSID_MAX_SIZE;
1054 EssidBuf[ssid_len] = '\0';
1057 essid->length = strlen(EssidBuf);
1059 memcpy(extra, EssidBuf, essid->length);
1060 // wireless.c in Kernel would handle copy_to_user -- line 679
1061 /*if (essid->pointer)
1063 if ( copy_to_user(essid->pointer, EssidBuf, essid->length) )
1065 printk("giwessid - copy_to_user Fail\n");
1073 int usbdrvwext_siwnickn(struct net_device *dev,
1074 struct iw_request_info *info,
1075 struct iw_point *data, char *nickname)
1077 //Exist but junk--CWYang(+)
1081 int usbdrvwext_giwnickn(struct net_device *dev,
1082 struct iw_request_info *info,
1083 struct iw_point *data, char *nickname)
1085 struct usbdrv_private *macp = dev->ml_priv;
1087 char EssidBuf[IW_ESSID_MAX_SIZE+1];
1089 if (macp->DeviceOpened != 1)
1092 zfiWlanQuerySSID(dev, &EssidBuf[0], &EssidLen);
1093 EssidBuf[EssidLen] = 0;
1096 data->length = strlen(EssidBuf);
1098 memcpy(nickname, EssidBuf, data->length);
1103 int usbdrvwext_siwrate(struct net_device *dev,
1104 struct iw_request_info *info,
1105 struct iw_param *frq, char *extra)
1107 struct usbdrv_private *macp = dev->ml_priv;
1108 //Array to Define Rate Number that Send to Driver
1109 u16_t zcIndextoRateBG[16] = {1000, 2000, 5500, 11000, 0, 0, 0, 0, 48000,
1110 24000, 12000, 6000, 54000, 36000, 18000, 9000};
1111 u16_t zcRateToMCS[] = {0xff, 0, 1, 2, 3, 0xb, 0xf, 0xa, 0xe, 0x9, 0xd,
1113 u8_t i,RateIndex = 4;
1116 //printk("frq->disabled : 0x%x\n",frq->disabled);
1117 //printk("frq->value : 0x%x\n",frq->value);
1119 RateKbps = frq->value / 1000;
1120 //printk("RateKbps : %d\n", RateKbps);
1121 for (i = 0; i < 16; i++)
1123 if (RateKbps == zcIndextoRateBG[i])
1126 if (zcIndextoRateBG[RateIndex] == 0)
1128 //printk("RateIndex : %x\n", RateIndex);
1129 for (i = 0; i < 13; i++)
1130 if (RateIndex == zcRateToMCS[i])
1132 //printk("Index : %x\n", i);
1133 if (RateKbps == 65000)
1136 printk("RateIndex : %d\n", RateIndex);
1138 if (macp->DeviceOpened == 1)
1140 zfiWlanSetTxRate(dev, i);
1141 //zfiWlanDisable(dev);
1142 //zfiWlanEnable(dev);
1148 int usbdrvwext_giwrate(struct net_device *dev,
1149 struct iw_request_info *info,
1150 struct iw_param *frq, char *extra)
1152 struct usbdrv_private *macp = dev->ml_priv;
1154 if(!netif_running(dev))
1157 if (macp->DeviceOpened != 1)
1162 frq->value = zfiWlanQueryRxRate(dev) * 1000;
1167 int usbdrvwext_siwrts(struct net_device *dev,
1168 struct iw_request_info *info,
1169 struct iw_param *rts, char *extra)
1171 struct usbdrv_private *macp = dev->ml_priv;
1172 int val = rts->value;
1174 if (macp->DeviceOpened != 1)
1180 if ((val < 0) || (val > 2347))
1183 zfiWlanSetRtsThreshold(dev,val);
1188 int usbdrvwext_giwrts(struct net_device *dev,
1189 struct iw_request_info *info,
1190 struct iw_param *rts, char *extra)
1192 struct usbdrv_private *macp = dev->ml_priv;
1194 if(!netif_running(dev))
1197 if (macp->DeviceOpened != 1)
1200 rts->value = zfiWlanQueryRtsThreshold(dev);
1201 rts->disabled = (rts->value >= 2347);
1208 int usbdrvwext_siwfrag(struct net_device *dev,
1209 struct iw_request_info *info,
1210 struct iw_param *frag, char *extra)
1212 struct usbdrv_private *macp = dev->ml_priv;
1213 u16_t fragThreshold;
1215 if (macp->DeviceOpened != 1)
1221 fragThreshold = frag->value;
1223 zfiWlanSetFragThreshold(dev,fragThreshold);
1228 int usbdrvwext_giwfrag(struct net_device *dev,
1229 struct iw_request_info *info,
1230 struct iw_param *frag, char *extra)
1232 struct usbdrv_private *macp = dev->ml_priv;
1234 unsigned long irqFlag;
1236 if(!netif_running(dev))
1239 if (macp->DeviceOpened != 1)
1242 spin_lock_irqsave(&macp->cs_lock, irqFlag);
1244 val = zfiWlanQueryFragThreshold(dev);
1248 frag->disabled = (val >= 2346);
1251 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
1256 int usbdrvwext_siwtxpow(struct net_device *dev,
1257 struct iw_request_info *info,
1258 struct iw_param *rrq, char *extra)
1260 //Not support yet--CWYng(+)
1264 int usbdrvwext_giwtxpow(struct net_device *dev,
1265 struct iw_request_info *info,
1266 struct iw_param *rrq, char *extra)
1268 //Not support yet--CWYng(+)
1272 int usbdrvwext_siwretry(struct net_device *dev,
1273 struct iw_request_info *info,
1274 struct iw_param *rrq, char *extra)
1276 //Do nothing--CWYang(+)
1280 int usbdrvwext_giwretry(struct net_device *dev,
1281 struct iw_request_info *info,
1282 struct iw_param *rrq, char *extra)
1284 //Do nothing--CWYang(+)
1288 int usbdrvwext_siwencode(struct net_device *dev,
1289 struct iw_request_info *info,
1290 struct iw_point *erq, char *key)
1292 struct zsKeyInfo keyInfo;
1293 int i, WepState = ZM_ENCRYPTION_WEP_DISABLED;
1294 struct usbdrv_private *macp = dev->ml_priv;
1296 if(!netif_running(dev))
1299 if ((erq->flags & IW_ENCODE_DISABLED) == 0)
1302 keyInfo.keyLength = erq->length;
1303 keyInfo.keyIndex = (erq->flags & IW_ENCODE_INDEX) - 1;
1304 if (keyInfo.keyIndex >= 4)
1305 keyInfo.keyIndex = 0;
1306 keyInfo.flag = ZM_KEY_FLAG_DEFAULT_KEY;
1308 zfiWlanSetKey(dev, keyInfo);
1309 WepState = ZM_ENCRYPTION_WEP_ENABLED;
1313 for (i = 1; i < 4; i++)
1314 zfiWlanRemoveKey(dev, 0, i);
1315 WepState = ZM_ENCRYPTION_WEP_DISABLED;
1316 //zfiWlanSetEncryMode(dev, ZM_NO_WEP);
1319 if (macp->DeviceOpened == 1)
1321 zfiWlanSetWepStatus(dev, WepState);
1322 zfiWlanSetFrequency(dev, zfiWlanQueryFrequency(dev), FALSE);
1323 //zfiWlanSetEncryMode(dev, zfiWlanQueryEncryMode(dev));
1324 //u8_t wpaieLen,wpaie[50];
1325 //zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen);
1326 zfiWlanDisable(dev, 0);
1329 // zfiWlanSetWpaIe(dev, wpaie, wpaieLen);
1335 int usbdrvwext_giwencode(struct net_device *dev,
1336 struct iw_request_info *info,
1337 struct iw_point *erq, char *key)
1339 struct usbdrv_private *macp = dev->ml_priv;
1340 u8_t EncryptionMode;
1343 if (macp->DeviceOpened != 1)
1346 EncryptionMode = zfiWlanQueryEncryMode(dev);
1350 erq->flags = IW_ENCODE_ENABLED;
1354 erq->flags = IW_ENCODE_DISABLED;
1357 /* We can't return the key, so set the proper flag and return zero */
1358 erq->flags |= IW_ENCODE_NOKEY;
1361 /* Copy the key to the user buffer */
1362 switch(EncryptionMode)
1379 #ifdef ZM_ENABLE_CENC
1383 #endif //ZM_ENABLE_CENC
1389 printk("Unknown EncryMode\n");
1393 erq->length = keyLen;
1398 int usbdrvwext_siwpower(struct net_device *dev,
1399 struct iw_request_info *info,
1400 struct iw_param *frq, char *extra)
1402 struct usbdrv_private *macp = dev->ml_priv;
1405 if (macp->DeviceOpened != 1)
1409 PSMode = ZM_STA_PS_NONE;
1411 PSMode = ZM_STA_PS_MAX;
1413 zfiWlanSetPowerSaveMode(dev,PSMode);
1418 int usbdrvwext_giwpower(struct net_device *dev,
1419 struct iw_request_info *info,
1420 struct iw_param *frq, char *extra)
1422 unsigned long irqFlag;
1423 struct usbdrv_private *macp = dev->ml_priv;
1425 if (macp->DeviceOpened != 1)
1428 spin_lock_irqsave(&macp->cs_lock, irqFlag);
1430 if (zfiWlanQueryPowerSaveMode(dev) == ZM_STA_PS_NONE)
1435 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
1440 //int usbdrvwext_setparam(struct net_device *dev, struct iw_request_info *info,
1441 // void *w, char *extra)
1443 // struct ieee80211vap *vap = dev->ml_priv;
1444 // struct ieee80211com *ic = vap->iv_ic;
1445 // struct ieee80211_rsnparms *rsn = &vap->iv_bss->ni_rsn;
1446 // int *i = (int *) extra;
1447 // int param = i[0]; /* parameter id is 1st */
1448 // int value = i[1]; /* NB: most values are TYPE_INT */
1451 // const struct ieee80211_authenticator *auth;
1452 // const struct ieee80211_aclator *acl;
1455 // case IEEE80211_PARAM_AUTHMODE:
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)
1470 // case IEEE80211_AUTH_WPA: /* WPA w/ 802.1x */
1471 // vap->iv_flags |= IEEE80211_F_PRIVACY;
1472 // value = IEEE80211_AUTH_8021X;
1474 // case IEEE80211_AUTH_OPEN: /* open */
1475 // vap->iv_flags &= ~(IEEE80211_F_WPA|IEEE80211_F_PRIVACY);
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;
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;
1491 // case IEEE80211_PARAM_PROTMODE:
1492 // if (value > IEEE80211_PROT_RTSCTS)
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;
1500 // case IEEE80211_PARAM_MCASTCIPHER:
1501 // if ((vap->iv_caps & cipher2cap(value)) == 0 &&
1502 // !ieee80211_crypto_available(value))
1504 // rsn->rsn_mcastcipher = value;
1505 // if (vap->iv_flags & IEEE80211_F_WPA)
1506 // retv = ENETRESET;
1508 // case IEEE80211_PARAM_MCASTKEYLEN:
1509 // if (!(0 < value && value < IEEE80211_KEYBUF_SIZE))
1511 // /* XXX no way to verify driver capability */
1512 // rsn->rsn_mcastkeylen = value;
1513 // if (vap->iv_flags & IEEE80211_F_WPA)
1514 // retv = ENETRESET;
1516 // case IEEE80211_PARAM_UCASTCIPHERS:
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.
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)))
1529 // if (caps == 0) /* nothing available */
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;
1537 // case IEEE80211_PARAM_UCASTCIPHER:
1538 // if ((rsn->rsn_ucastcipherset & cipher2cap(value)) == 0)
1540 // rsn->rsn_ucastcipher = value;
1542 // case IEEE80211_PARAM_UCASTKEYLEN:
1543 // if (!(0 < value && value < IEEE80211_KEYBUF_SIZE))
1545 // /* XXX no way to verify driver capability */
1546 // rsn->rsn_ucastkeylen = value;
1548 // case IEEE80211_PARAM_KEYMGTALGS:
1550 // rsn->rsn_keymgmtset = value;
1551 // if (vap->iv_flags & IEEE80211_F_WPA)
1552 // retv = ENETRESET;
1554 // case IEEE80211_PARAM_RSNCAPS:
1556 // rsn->rsn_caps = value;
1557 // if (vap->iv_flags & IEEE80211_F_WPA)
1558 // retv = ENETRESET;
1560 // case IEEE80211_PARAM_WPA:
1563 // /* XXX verify ciphers available */
1564 // vap->iv_flags &= ~IEEE80211_F_WPA;
1567 // vap->iv_flags |= IEEE80211_F_WPA1;
1570 // vap->iv_flags |= IEEE80211_F_WPA2;
1573 // vap->iv_flags |= IEEE80211_F_WPA1 | IEEE80211_F_WPA2;
1576 // retv = ENETRESET; /* XXX? */
1578 // case IEEE80211_PARAM_ROAMING:
1579 // if (!(IEEE80211_ROAMING_DEVICE <= value &&
1580 // value <= IEEE80211_ROAMING_MANUAL))
1582 // ic->ic_roaming = value;
1584 // case IEEE80211_PARAM_PRIVACY:
1586 // /* XXX check for key state? */
1587 // vap->iv_flags |= IEEE80211_F_PRIVACY;
1589 // vap->iv_flags &= ~IEEE80211_F_PRIVACY;
1591 // case IEEE80211_PARAM_DROPUNENCRYPTED:
1593 // vap->iv_flags |= IEEE80211_F_DROPUNENC;
1595 // vap->iv_flags &= ~IEEE80211_F_DROPUNENC;
1597 // case IEEE80211_PARAM_COUNTERMEASURES:
1599 // if ((vap->iv_flags & IEEE80211_F_WPA) == 0)
1601 // vap->iv_flags |= IEEE80211_F_COUNTERM;
1603 // vap->iv_flags &= ~IEEE80211_F_COUNTERM;
1605 // case IEEE80211_PARAM_DRIVER_CAPS:
1606 // vap->iv_caps = value; /* NB: for testing */
1608 // case IEEE80211_PARAM_MACCMD:
1609 // acl = vap->iv_acl;
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))
1618 // vap->iv_acl = acl;
1620 // acl->iac_setpolicy(vap, value);
1622 // case IEEE80211_MACCMD_FLUSH:
1624 // acl->iac_flush(vap);
1625 // /* NB: silently ignore when not in use */
1627 // case IEEE80211_MACCMD_DETACH:
1628 // if (acl != NULL) {
1629 // vap->iv_acl = NULL;
1630 // acl->iac_detach(vap);
1635 // case IEEE80211_PARAM_WMM:
1636 // if (ic->ic_caps & IEEE80211_C_WME){
1638 // vap->iv_flags |= IEEE80211_F_WME;
1639 // vap->iv_ic->ic_flags |= IEEE80211_F_WME; /* XXX needed by ic_reset */
1642 // vap->iv_flags &= ~IEEE80211_F_WME;
1643 // vap->iv_ic->ic_flags &= ~IEEE80211_F_WME; /* XXX needed by ic_reset */
1645 // retv = ENETRESET; /* Renegotiate for capabilities */
1648 // case IEEE80211_PARAM_HIDESSID:
1650 // vap->iv_flags |= IEEE80211_F_HIDESSID;
1652 // vap->iv_flags &= ~IEEE80211_F_HIDESSID;
1653 // retv = ENETRESET;
1655 // case IEEE80211_PARAM_APBRIDGE:
1657 // vap->iv_flags |= IEEE80211_F_NOBRIDGE;
1659 // vap->iv_flags &= ~IEEE80211_F_NOBRIDGE;
1661 // case IEEE80211_PARAM_INACT:
1662 // vap->iv_inact_run = value / IEEE80211_INACT_WAIT;
1664 // case IEEE80211_PARAM_INACT_AUTH:
1665 // vap->iv_inact_auth = value / IEEE80211_INACT_WAIT;
1667 // case IEEE80211_PARAM_INACT_INIT:
1668 // vap->iv_inact_init = value / IEEE80211_INACT_WAIT;
1670 // case IEEE80211_PARAM_ABOLT:
1673 // * Map abolt settings to capability bits;
1674 // * this also strips unknown/unwanted bits.
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)
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))
1697 // ieee80211_scan_flush(ic);
1699 // vap->iv_ath_cap = caps;
1700 // ic->ic_athcapsetup(vap->iv_ic, vap->iv_ath_cap);
1701 // retv = ENETRESET;
1704 // case IEEE80211_PARAM_DTIM_PERIOD:
1705 // if (vap->iv_opmode != IEEE80211_M_HOSTAP &&
1706 // vap->iv_opmode != IEEE80211_M_IBSS)
1708 // if (IEEE80211_DTIM_MIN <= value &&
1709 // value <= IEEE80211_DTIM_MAX) {
1710 // vap->iv_dtim_period = value;
1711 // retv = ENETRESET; /* requires restart */
1715 // case IEEE80211_PARAM_BEACON_INTERVAL:
1716 // if (vap->iv_opmode != IEEE80211_M_HOSTAP &&
1717 // vap->iv_opmode != IEEE80211_M_IBSS)
1719 // if (IEEE80211_BINTVAL_MIN <= value &&
1720 // value <= IEEE80211_BINTVAL_MAX) {
1721 // ic->ic_lintval = value; /* XXX multi-bss */
1722 // retv = ENETRESET; /* requires restart */
1726 // case IEEE80211_PARAM_DOTH:
1728 // ic->ic_flags |= IEEE80211_F_DOTH;
1731 // ic->ic_flags &= ~IEEE80211_F_DOTH;
1732 // retv = ENETRESET; /* XXX: need something this drastic? */
1734 // case IEEE80211_PARAM_PWRTARGET:
1735 // ic->ic_curchanmaxpwr = value;
1737 // case IEEE80211_PARAM_GENREASSOC:
1738 // IEEE80211_SEND_MGMT(vap->iv_bss, IEEE80211_FC0_SUBTYPE_REASSOC_REQ, 0);
1740 // case IEEE80211_PARAM_COMPRESSION:
1741 // retv = ieee80211_setathcap(vap, IEEE80211_ATHC_COMP, value);
1743 // case IEEE80211_PARAM_WMM_AGGRMODE:
1744 // retv = ieee80211_setathcap(vap, IEEE80211_ATHC_WME, value);
1746 // case IEEE80211_PARAM_FF:
1747 // retv = ieee80211_setathcap(vap, IEEE80211_ATHC_FF, value);
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))
1754 // ieee80211_scan_flush(ic);
1757 // case IEEE80211_PARAM_XR:
1758 // retv = ieee80211_setathcap(vap, IEEE80211_ATHC_XR, value);
1760 // case IEEE80211_PARAM_BURST:
1761 // retv = ieee80211_setathcap(vap, IEEE80211_ATHC_BURST, value);
1763 // case IEEE80211_PARAM_AR:
1764 // retv = ieee80211_setathcap(vap, IEEE80211_ATHC_AR, value);
1766 // case IEEE80211_PARAM_PUREG:
1768 // vap->iv_flags |= IEEE80211_F_PUREG;
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;
1776 // case IEEE80211_PARAM_WDS:
1778 // vap->iv_flags_ext |= IEEE80211_FEXT_WDS;
1780 // vap->iv_flags_ext &= ~IEEE80211_FEXT_WDS;
1782 // case IEEE80211_PARAM_BGSCAN:
1784 // if ((vap->iv_caps & IEEE80211_C_BGSCAN) == 0)
1786 // vap->iv_flags |= IEEE80211_F_BGSCAN;
1789 // vap->iv_flags &= ~IEEE80211_F_BGSCAN;
1790 // ieee80211_cancel_scan(vap); /* anything current */
1793 // case IEEE80211_PARAM_BGSCAN_IDLE:
1794 // if (value >= IEEE80211_BGSCAN_IDLE_MIN)
1795 // vap->iv_bgscanidle = value*HZ/1000;
1799 // case IEEE80211_PARAM_BGSCAN_INTERVAL:
1800 // if (value >= IEEE80211_BGSCAN_INTVAL_MIN)
1801 // vap->iv_bgscanintvl = value*HZ;
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;
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);
1822 // case IEEE80211_PARAM_COUNTRY_IE:
1824 // ic->ic_flags_ext |= IEEE80211_FEXT_COUNTRYIE;
1826 // ic->ic_flags_ext &= ~IEEE80211_FEXT_COUNTRYIE;
1827 // retv = ENETRESET;
1829 // case IEEE80211_PARAM_REGCLASS:
1831 // ic->ic_flags_ext |= IEEE80211_FEXT_REGCLASS;
1833 // ic->ic_flags_ext &= ~IEEE80211_FEXT_REGCLASS;
1834 // retv = ENETRESET;
1836 // case IEEE80211_PARAM_SCANVALID:
1837 // vap->iv_scanvalid = value*HZ;
1839 // case IEEE80211_PARAM_ROAM_RSSI_11A:
1840 // vap->iv_roam.rssi11a = value;
1842 // case IEEE80211_PARAM_ROAM_RSSI_11B:
1843 // vap->iv_roam.rssi11bOnly = value;
1845 // case IEEE80211_PARAM_ROAM_RSSI_11G:
1846 // vap->iv_roam.rssi11b = value;
1848 // case IEEE80211_PARAM_ROAM_RATE_11A:
1849 // vap->iv_roam.rate11a = value;
1851 // case IEEE80211_PARAM_ROAM_RATE_11B:
1852 // vap->iv_roam.rate11bOnly = value;
1854 // case IEEE80211_PARAM_ROAM_RATE_11G:
1855 // vap->iv_roam.rate11b = value;
1857 // case IEEE80211_PARAM_UAPSDINFO:
1858 // if (vap->iv_opmode == IEEE80211_M_HOSTAP) {
1859 // if (ic->ic_caps & IEEE80211_C_UAPSD) {
1861 // IEEE80211_VAP_UAPSD_ENABLE(vap);
1863 // IEEE80211_VAP_UAPSD_DISABLE(vap);
1864 // retv = ENETRESET;
1867 // else if (vap->iv_opmode == IEEE80211_M_STA) {
1868 // vap->iv_uapsdinfo = value;
1869 // IEEE80211_VAP_UAPSD_ENABLE(vap);
1870 // retv = ENETRESET;
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.
1879 // IEEE80211_VAP_GOTOSLEEP(vap);
1883 // IEEE80211_VAP_WAKEUP(vap);
1885 // ieee80211_send_nulldata(ieee80211_ref_node(vap->iv_bss));
1887 // case IEEE80211_PARAM_QOSNULL:
1888 // /* Force a QoS Null for testing. */
1889 // ieee80211_send_qosnulldata(vap->iv_bss, value);
1891 // case IEEE80211_PARAM_PSPOLL:
1892 // /* Force a PS-POLL for testing. */
1893 // ieee80211_send_pspoll(vap->iv_bss);
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);
1901 // case IEEE80211_PARAM_MARKDFS:
1903 // ic->ic_flags_ext |= IEEE80211_FEXT_MARKDFS;
1905 // ic->ic_flags_ext &= ~IEEE80211_FEXT_MARKDFS;
1907 // case IEEE80211_PARAM_CHANBW:
1910 // ic->ic_chanbwflag = 0;
1913 // ic->ic_chanbwflag = IEEE80211_CHAN_HALF;
1916 // ic->ic_chanbwflag = IEEE80211_CHAN_QUARTER;
1923 // case IEEE80211_PARAM_SHORTPREAMBLE:
1925 // ic->ic_caps |= IEEE80211_C_SHPREAMBLE;
1927 // ic->ic_caps &= ~IEEE80211_C_SHPREAMBLE;
1929 // retv = ENETRESET;
1932 // retv = EOPNOTSUPP;
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;
1941 int usbdrvwext_setmode(struct net_device *dev, struct iw_request_info *info,
1942 void *w, char *extra)
1947 int usbdrvwext_getmode(struct net_device *dev, struct iw_request_info *info,
1948 void *w, char *extra)
1950 //struct usbdrv_private *macp = dev->ml_priv;
1951 struct iw_point *wri = (struct iw_point *)extra;
1955 return (copy_to_user(wri->pointer, mode, 6) ? -EFAULT : 0);
1958 int zfLnxPrivateIoctl(struct net_device *dev, struct zdap_ioctl* zdreq)
1960 //void* regp = macp->regp;
1969 case ZM_IOCTL_REG_READ:
1970 zfiDbgReadReg(dev, zdreq->addr);
1973 case ZM_IOCTL_REG_WRITE:
1974 zfiDbgWriteReg(dev, zdreq->addr, zdreq->value);
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);
1982 case ZM_IOCTL_MEM_WRITE:
1983 p = (u32_t *) bus_to_virt(zdreq->addr);
1985 printk(KERN_DEBUG "usbdrv: write value: 0x%08x to memory addr: 0x%08x\n", zdreq->value, zdreq->addr);
1988 case ZM_IOCTL_TALLY :
1989 zfiWlanShowTally(dev);
1991 zfiWlanResetTally(dev);
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");
2001 for (i=0; i<zdreq->addr; i++)
2007 printk("%02X ", (unsigned char)zdreq->data[i]);
2013 #if 0 //For Test?? 1 to 0 by CWYang(-)
2017 /* Allocate a skb */
2018 s = alloc_skb(2000, GFP_ATOMIC);
2020 /* Copy data to skb */
2021 for (i=0; i<zdreq->addr; i++)
2023 s->data[i] = zdreq->data[i];
2025 s->len = zdreq->addr;
2027 /* Call zfIdlRecv() */
2028 zfiRecv80211(dev, s, NULL);
2035 /****************************** ZDCONFIG ******************************/
2036 case ZM_IOCTL_FRAG :
2037 zfiWlanSetFragThreshold(dev, zdreq->addr);
2041 zfiWlanSetRtsThreshold(dev, zdreq->addr);
2044 case ZM_IOCTL_SCAN :
2051 struct zsKeyInfo keyInfo;
2054 for (i=0; i<29; i++)
2059 for (i=0; i<zdreq->addr; i++)
2061 key[i] = zdreq->data[i];
2064 printk("key len=%d, key=%02x%02x%02x%02x%02x...\n",
2065 zdreq->addr, key[0], key[1], key[2], key[3], key[4]);
2067 keyInfo.keyLength = zdreq->addr;
2068 keyInfo.keyIndex = 0;
2071 zfiWlanSetKey(dev, keyInfo);
2075 case ZM_IOCTL_RATE :
2076 zfiWlanSetTxRate(dev, zdreq->addr);
2079 case ZM_IOCTL_ENCRYPTION_MODE :
2080 zfiWlanSetEncryMode(dev, zdreq->addr);
2082 zfiWlanDisable(dev, 0);
2086 case ZM_IOCTL_SIGNAL_STRENGTH :
2089 zfiWlanQuerySignalInfo(dev, &buffer[0]);
2090 printk("Current Signal Strength : %02d\n", buffer[0]);
2094 case ZM_IOCTL_SIGNAL_QUALITY :
2097 zfiWlanQuerySignalInfo(dev, &buffer[0]);
2098 printk("Current Signal Quality : %02d\n", buffer[1]);
2102 case ZM_IOCTL_SET_PIBSS_MODE:
2103 if (zdreq->addr == 1)
2104 zfiWlanSetWlanMode(dev, ZM_MODE_PSEUDO);
2106 zfiWlanSetWlanMode(dev, ZM_MODE_INFRASTRUCTURE);
2108 zfiWlanDisable(dev, 0);
2112 /****************************** ZDCONFIG ******************************/
2115 printk(KERN_ERR "usbdrv: error command = %x\n", cmd);
2122 int usbdrv_wpa_ioctl(struct net_device *dev, struct athr_wlan_param *zdparm)
2125 u8_t bc_addr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2127 struct zsKeyInfo keyInfo;
2128 struct usbdrv_private *macp = dev->ml_priv;
2131 //zmw_get_wlan_dev(dev);
2135 case ZD_CMD_SET_ENCRYPT_KEY:
2137 /* Set up key information */
2138 keyInfo.keyLength = zdparm->u.crypt.key_len;
2139 keyInfo.keyIndex = zdparm->u.crypt.idx;
2140 if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) // AP Mode
2141 keyInfo.flag = ZM_KEY_FLAG_AUTHENTICATOR;
2144 keyInfo.key = zdparm->u.crypt.key;
2145 keyInfo.initIv = zdparm->u.crypt.seq;
2146 keyInfo.macAddr = (u16_t *)zdparm->sta_addr;
2148 /* Identify the MAC address information */
2149 if (memcmp(zdparm->sta_addr, bc_addr, sizeof(bc_addr)) == 0)
2151 keyInfo.flag |= ZM_KEY_FLAG_GK;
2155 keyInfo.flag |= ZM_KEY_FLAG_PK;
2158 if (!strcmp(zdparm->u.crypt.alg, "NONE"))
2160 //u8_t zero_mac[]={0,0,0,0,0,0};
2162 /* Set key length to zero */
2163 keyInfo.keyLength = 0;
2165 if (zdparm->sta_addr[0] & 1)//del group key
2167 //if (macp->cardSetting.WPAIeLen==0)
2168 //{//802.1x dynamic WEP
2170 // mKeyFormat[0] = 0;
2171 // mPrivacyInvoked[0]=FALSE;
2172 // mCap[0] &= ~CAP_PRIVACY;
2173 // macp->cardSetting.EncryOnOff[0]=0;
2175 //mWpaBcKeyLen = mGkInstalled = 0;
2179 //if (memcmp(zero_mac,zdparm->sta_addr, 6)==0)
2183 // pSetting->DynKeyMode=0;
2184 // pSetting->EncryMode[0]=0;
2189 printk(KERN_ERR "Set Encryption Type NONE\n");
2192 else if (!strcmp(zdparm->u.crypt.alg, "TKIP"))
2194 zfiWlanSetEncryMode(dev, ZM_TKIP);
2195 //Linux Supplicant will inverse Tx/Rx key
2196 //So we inverse it back //CWYang(+)
2197 //zfMemoryCopy(&temp[0], &keyInfo.key[16], 8);
2198 //zfMemoryCopy(&keyInfo.key[16], keyInfo.key[24], 8);
2199 //zfMemoryCopy(&keyInfo.key[24], &temp[0], 8);
2202 //for (k = 0; k < 8; k++)
2204 // temp = keyInfo.key[16 + k];
2205 // keyInfo.key[16 + k] = keyInfo.key[24 + k];
2206 // keyInfo.key[24 + k] = temp;
2208 //CamEncryType = ZM_TKIP;
2211 // mKeyFormat[0] = CamEncryType;
2212 // mDynKeyMode = pSetting->DynKeyMode = DYN_KEY_TKIP;
2215 else if (!strcmp(zdparm->u.crypt.alg, "CCMP"))
2217 zfiWlanSetEncryMode(dev, ZM_AES);
2218 //CamEncryType = ZM_AES;
2221 // mKeyFormat[0] = CamEncryType;
2222 // mDynKeyMode = pSetting->DynKeyMode = DYN_KEY_AES;
2225 else if (!strcmp(zdparm->u.crypt.alg, "WEP"))
2227 if (keyInfo.keyLength == 5)
2229 zfiWlanSetEncryMode(dev, ZM_WEP64);
2230 // CamEncryType = ZM_WEP64;
2231 // tmpDynKeyMode=DYN_KEY_WEP64;
2233 else if (keyInfo.keyLength == 13)
2234 {//keylen=13, WEP 128
2235 zfiWlanSetEncryMode(dev, ZM_WEP128);
2236 // CamEncryType = ZM_WEP128;
2237 // tmpDynKeyMode=DYN_KEY_WEP128;
2241 zfiWlanSetEncryMode(dev, ZM_WEP256);
2244 // For Dynamic WEP key (Non-WPA Radius), the key ID range: 0-3
2245 // In WPA/RSN mode, the key ID range: 1-3, usually, a broadcast key.
2246 // For WEP key setting: we set mDynKeyMode and mKeyFormat in following case:
2247 // 1. For 802.1x dynamically generated WEP key method.
2248 // 2. For WPA/RSN mode, but key id == 0. (But this is an impossible case)
2249 // So, only check case 1.
2250 //if (macp->cardSetting.WPAIeLen==0)
2252 // mKeyFormat[0] = CamEncryType;
2253 // mDynKeyMode = pSetting->DynKeyMode = tmpDynKeyMode;
2254 // mPrivacyInvoked[0]=TRUE;
2255 // mCap[0] |= CAP_PRIVACY;
2256 // macp->cardSetting.EncryOnOff[0]=1;
2260 /* DUMP key context */
2262 if (keyInfo.keyLength > 0)
2265 printk("Otus: Key Context:\n");
2266 for(ii = 0; ii < keyInfo.keyLength;)
2268 printk("0x%02x ", keyInfo.key[ii]);
2269 if((++ii % 16) == 0)
2276 /* Set encrypt mode */
2277 //zfiWlanSetEncryMode(dev, CamEncryType);
2278 vapId = zfLnxGetVapId(dev);
2279 if (vapId == 0xffff)
2282 keyInfo.vapId = vapId + 1;
2283 keyInfo.vapAddr[0] = keyInfo.macAddr[0];
2284 keyInfo.vapAddr[1] = keyInfo.macAddr[1];
2285 keyInfo.vapAddr[2] = keyInfo.macAddr[2];
2287 zfiWlanSetKey(dev, keyInfo);
2289 //zfiWlanDisable(dev);
2290 //zfiWlanEnable(dev);
2293 case ZD_CMD_SET_MLME:
2294 printk(KERN_ERR "usbdrv_wpa_ioctl: ZD_CMD_SET_MLME\n");
2296 /* Translate STA's address */
2297 sprintf(mac_addr, "%02x:%02x:%02x:%02x:%02x:%02x", zdparm->sta_addr[0], zdparm->sta_addr[1],
2298 zdparm->sta_addr[2], zdparm->sta_addr[3], zdparm->sta_addr[4], zdparm->sta_addr[5]);
2300 switch(zdparm->u.mlme.cmd)
2302 case MLME_STA_DEAUTH:
2303 printk(" -------Call zfiWlanDeauth, reason:%d\n",zdparm->u.mlme.reason_code);
2304 if(zfiWlanDeauth(dev, (u16_t*) zdparm->sta_addr, zdparm->u.mlme.reason_code) != 0)
2305 printk(KERN_ERR "Can't deauthencate STA: %s\n", mac_addr);
2307 printk(KERN_ERR "Deauthenticate STA: %s with reason code: %d\n", mac_addr, zdparm->u.mlme.reason_code);
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);
2315 printk(KERN_ERR "Disassociate STA: %s with reason code: %d\n", mac_addr, zdparm->u.mlme.reason_code);
2319 printk(KERN_ERR "MLME command: 0x%04x not support\n", zdparm->u.mlme.cmd);
2325 case ZD_CMD_SCAN_REQ:
2326 printk(KERN_ERR "usbdrv_wpa_ioctl: ZD_CMD_SCAN_REQ\n");
2329 case ZD_CMD_SET_GENERIC_ELEMENT:
2330 printk(KERN_ERR "usbdrv_wpa_ioctl: ZD_CMD_SET_GENERIC_ELEMENT\n");
2332 /* Copy the WPA IE */
2333 //zm_msg1_mm(ZM_LV_0, "CWY - wpaie Length : ", zdparm->u.generic_elem.len);
2334 printk(KERN_ERR "wpaie Length : %d\n", zdparm->u.generic_elem.len);
2335 if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) // AP Mode
2337 zfiWlanSetWpaIe(dev, zdparm->u.generic_elem.data, zdparm->u.generic_elem.len);
2341 macp->supLen = zdparm->u.generic_elem.len;
2342 memcpy(macp->supIe, zdparm->u.generic_elem.data, zdparm->u.generic_elem.len);
2344 zfiWlanSetWpaSupport(dev, 1);
2345 //zfiWlanSetWpaIe(dev, zdparm->u.generic_elem.data, zdparm->u.generic_elem.len);
2348 u8_t len = zdparm->u.generic_elem.len;
2349 u8_t *wpaie = (u8_t *)zdparm->u.generic_elem.data;
2351 printk(KERN_ERR "wd->ap.wpaLen: %d\n", len);
2354 for(ii = 0; ii < len;)
2356 printk(KERN_ERR "0x%02x ", wpaie[ii]);
2358 if((++ii % 16) == 0)
2359 printk(KERN_ERR "\n");
2361 printk(KERN_ERR "\n");
2364 // #ifdef ZM_HOSTAPD_SUPPORT
2365 //if (wd->wlanMode == ZM_MODE_AP)
2366 //{// Update Beacon FIFO in the next TBTT.
2367 // memcpy(&mWPAIe, pSetting->WPAIe, pSetting->WPAIeLen);
2368 // printk(KERN_ERR "Copy WPA IE into mWPAIe\n");
2373 // #ifdef ZM_HOSTAPD_SUPPORT
2374 case ZD_CMD_GET_TSC:
2375 printk(KERN_ERR "usbdrv_wpa_ioctl: ZD_CMD_GET_TSC\n");
2380 printk(KERN_ERR "usbdrv_wpa_ioctl default: 0x%04x\n", zdparm->cmd);
2388 #ifdef ZM_ENABLE_CENC
2389 int usbdrv_cenc_ioctl(struct net_device *dev, struct zydas_cenc_param *zdparm)
2391 //struct usbdrv_private *macp = dev->ml_priv;
2392 struct zsKeyInfo keyInfo;
2394 u8_t bc_addr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2399 apId = zfLnxGetVapId(dev);
2410 switch (zdparm->cmd)
2412 case ZM_CMD_CENC_SETCENC:
2413 printk(KERN_ERR "ZM_CMD_CENC_SETCENC\n");
2414 printk(KERN_ERR "length: %d\n", zdparm->len);
2415 printk(KERN_ERR "policy: %d\n", zdparm->u.info.cenc_policy);
2417 case ZM_CMD_CENC_SETKEY:
2418 //ret = wai_ioctl_setkey(vap, ioctl_msg);
2419 printk(KERN_ERR "ZM_CMD_CENC_SETKEY\n");
2421 printk(KERN_ERR "MAC address= ");
2422 for(ii = 0; ii < 6; ii++)
2424 printk(KERN_ERR "0x%02x ", zdparm->u.crypt.sta_addr[ii]);
2426 printk(KERN_ERR "\n");
2428 printk(KERN_ERR "Key Index: %d\n", zdparm->u.crypt.keyid);
2429 printk(KERN_ERR "Encryption key= ");
2430 for(ii = 0; ii < 16; ii++)
2432 printk(KERN_ERR "0x%02x ", zdparm->u.crypt.key[ii]);
2434 printk(KERN_ERR "\n");
2436 printk(KERN_ERR "MIC key= ");
2437 for(ii = 16; ii < ZM_CENC_KEY_SIZE; ii++)
2439 printk(KERN_ERR "0x%02x ", zdparm->u.crypt.key[ii]);
2441 printk(KERN_ERR "\n");
2443 /* Set up key information */
2444 keyInfo.keyLength = ZM_CENC_KEY_SIZE;
2445 keyInfo.keyIndex = zdparm->u.crypt.keyid;
2446 keyInfo.flag = ZM_KEY_FLAG_AUTHENTICATOR | ZM_KEY_FLAG_CENC;
2447 keyInfo.key = zdparm->u.crypt.key;
2448 keyInfo.macAddr = (u16_t *)zdparm->u.crypt.sta_addr;
2450 /* Identify the MAC address information */
2451 if (memcmp(zdparm->u.crypt.sta_addr, bc_addr, sizeof(bc_addr)) == 0)
2453 keyInfo.flag |= ZM_KEY_FLAG_GK;
2454 keyInfo.vapId = apId;
2455 memcpy(keyInfo.vapAddr, dev->dev_addr, ETH_ALEN);
2459 keyInfo.flag |= ZM_KEY_FLAG_PK;
2462 zfiWlanSetKey(dev, keyInfo);
2465 case ZM_CMD_CENC_REKEY:
2466 //ret = wai_ioctl_rekey(vap, ioctl_msg);
2467 printk(KERN_ERR "ZM_CMD_CENC_REKEY\n");
2475 //if (retv == ENETRESET)
2476 // retv = IS_UP_AUTO(vap) ? ieee80211_open(vap->iv_dev) : 0;
2480 #endif //ZM_ENABLE_CENC
2481 /////////////////////////////////////////
2482 int usbdrv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2484 // struct usbdrv_private *macp;
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;
2494 // regp = macp->regp;
2496 if(!netif_running(dev))
2502 strcpy(wrq->u.name, "IEEE 802.11-DS");
2506 err = usbdrvwext_giwap(dev, NULL, &wrq->u.ap_addr, NULL);
2511 err = usbdrvwext_siwap(dev, NULL, &wrq->u.ap_addr, NULL);
2516 err = usbdrvwext_giwmode(dev, NULL, &wrq->u.mode, NULL);
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);
2531 err = usbdrvwext_giwessid(dev, NULL, &wrq->u.essid, NULL);
2537 err = usbdrv_ioctl_setrts(dev, &wrq->u.rts);
2543 case SIOCIWFIRSTPRIV + 0x2: /* set_auth */
2545 //printk("CWY - SIOCIWFIRSTPRIV + 0x2 (set_auth)\n");
2546 if (! capable(CAP_NET_ADMIN))
2552 int val = *( (int *) wrq->u.name );
2553 if ((val < 0) || (val > 2))
2560 zfiWlanSetAuthenticationMode(dev, val);
2562 if (macp->DeviceOpened == 1)
2564 zfiWlanDisable(dev, 0);
2575 case SIOCIWFIRSTPRIV + 0x3: /* get_auth */
2577 int AuthMode = ZM_AUTH_MODE_OPEN;
2579 //printk("CWY - SIOCIWFIRSTPRIV + 0x3 (get_auth)\n");
2581 if (wrq->u.data.pointer)
2583 wrq->u.data.flags = 1;
2585 AuthMode = zfiWlanQueryAuthenticationMode(dev, 0);
2586 if (AuthMode == ZM_AUTH_MODE_OPEN)
2588 wrq->u.data.length = 12;
2590 if (copy_to_user(wrq->u.data.pointer, "open system", 12))
2595 else if (AuthMode == ZM_AUTH_MODE_SHARED_KEY)
2597 wrq->u.data.length = 11;
2599 if (copy_to_user(wrq->u.data.pointer, "shared key", 11))
2604 else if (AuthMode == ZM_AUTH_MODE_AUTO)
2606 wrq->u.data.length = 10;
2608 if (copy_to_user(wrq->u.data.pointer, "auto mode", 10))
2622 case ZDAPIOCTL: //debug command
2623 if (copy_from_user(&zdreq, ifr->ifr_data, sizeof (zdreq)))
2625 printk(KERN_ERR "usbdrv: copy_from_user error\n");
2629 //printk(KERN_DEBUG "usbdrv: cmd=%2x, reg=0x%04lx, value=0x%08lx\n",
2630 // zdreq.cmd, zdreq.addr, zdreq.value);
2632 zfLnxPrivateIoctl(dev, &zdreq);
2638 if (copy_from_user(&zdparm, ifr->ifr_data, sizeof(struct athr_wlan_param)))
2640 printk(KERN_ERR "usbdrv: copy_from_user error\n");
2644 usbdrv_wpa_ioctl(dev, &zdparm);
2648 case ZD_IOCTL_PARAM:
2654 /* Point to the name field and retrieve the
2655 * op and arg elements. */
2656 p = (int *)wrq->u.name;
2660 if(op == ZD_PARAM_ROAMING)
2662 printk(KERN_ERR "************* ZD_PARAM_ROAMING: %d\n", arg);
2663 //macp->cardSetting.ap_scan=(U8)arg;
2665 if(op == ZD_PARAM_PRIVACY)
2667 printk(KERN_ERR "ZD_IOCTL_PRIVACY: ");
2669 /* Turn on the privacy invoke flag */
2672 // mCap[0] |= CAP_PRIVACY;
2673 // macp->cardSetting.EncryOnOff[0] = 1;
2674 printk(KERN_ERR "enable\n");
2679 // mCap[0] &= ~CAP_PRIVACY;
2680 // macp->cardSetting.EncryOnOff[0] = 0;
2681 printk(KERN_ERR "disable\n");
2685 if(op == ZD_PARAM_WPA)
2687 printk(KERN_ERR "ZD_PARAM_WPA: ");
2691 printk(KERN_ERR "enable\n");
2693 if (zfiWlanQueryWlanMode(dev) != ZM_MODE_AP)
2695 printk(KERN_ERR "Station Mode\n");
2696 //zfiWlanQueryWpaIe(dev, (u8_t *)&wpaIe, &wpalen);
2697 //printk("wpaIe : %2x,%2x,%2x\n", wpaIe[21], wpaIe[22], wpaIe[23]);
2698 //printk("rsnIe : %2x,%2x,%2x\n", wpaIe[17], wpaIe[18], wpaIe[19]);
2699 if ((macp->supIe[21] == 0x50) &&
2700 (macp->supIe[22] == 0xf2) &&
2701 (macp->supIe[23] == 0x2))
2703 printk(KERN_ERR "wd->sta.authMode = ZM_AUTH_MODE_WPAPSK\n");
2704 //wd->sta.authMode = ZM_AUTH_MODE_WPAPSK;
2705 //wd->ws.authMode = ZM_AUTH_MODE_WPAPSK;
2706 zfiWlanSetAuthenticationMode(dev, ZM_AUTH_MODE_WPAPSK);
2708 else if ((macp->supIe[21] == 0x50) &&
2709 (macp->supIe[22] == 0xf2) &&
2710 (macp->supIe[23] == 0x1))
2712 printk(KERN_ERR "wd->sta.authMode = ZM_AUTH_MODE_WPA\n");
2713 //wd->sta.authMode = ZM_AUTH_MODE_WPA;
2714 //wd->ws.authMode = ZM_AUTH_MODE_WPA;
2715 zfiWlanSetAuthenticationMode(dev, ZM_AUTH_MODE_WPA);
2717 else if ((macp->supIe[17] == 0xf) &&
2718 (macp->supIe[18] == 0xac) &&
2719 (macp->supIe[19] == 0x2))
2721 printk(KERN_ERR "wd->sta.authMode = ZM_AUTH_MODE_WPA2PSK\n");
2722 //wd->sta.authMode = ZM_AUTH_MODE_WPA2PSK;
2723 //wd->ws.authMode = ZM_AUTH_MODE_WPA2PSK;
2724 zfiWlanSetAuthenticationMode(dev, ZM_AUTH_MODE_WPA2PSK);
2726 else if ((macp->supIe[17] == 0xf) &&
2727 (macp->supIe[18] == 0xac) &&
2728 (macp->supIe[19] == 0x1))
2730 printk(KERN_ERR "wd->sta.authMode = ZM_AUTH_MODE_WPA2\n");
2731 //wd->sta.authMode = ZM_AUTH_MODE_WPA2;
2732 //wd->ws.authMode = ZM_AUTH_MODE_WPA2;
2733 zfiWlanSetAuthenticationMode(dev, ZM_AUTH_MODE_WPA2);
2735 if ((macp->supIe[21] == 0x50) || (macp->supIe[22] == 0xf2))//WPA or WPAPSK
2737 if (macp->supIe[11] == 0x2)
2739 printk(KERN_ERR "wd->sta.wepStatus = ZM_ENCRYPTION_TKIP\n");
2740 //wd->sta.wepStatus = ZM_ENCRYPTION_TKIP;
2741 //wd->ws.wepStatus = ZM_ENCRYPTION_TKIP;
2742 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_TKIP);
2746 printk(KERN_ERR "wd->sta.wepStatus = ZM_ENCRYPTION_AES\n");
2747 //wd->sta.wepStatus = ZM_ENCRYPTION_AES;
2748 //wd->ws.wepStatus = ZM_ENCRYPTION_AES;
2749 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_AES);
2752 if ((macp->supIe[17] == 0xf) || (macp->supIe[18] == 0xac)) //WPA2 or WPA2PSK
2754 if (macp->supIe[13] == 0x2)
2756 printk(KERN_ERR "wd->sta.wepStatus = ZM_ENCRYPTION_TKIP\n");
2757 //wd->sta.wepStatus = ZM_ENCRYPTION_TKIP;
2758 //wd->ws.wepStatus = ZM_ENCRYPTION_TKIP;
2759 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_TKIP);
2763 printk(KERN_ERR "wd->sta.wepStatus = ZM_ENCRYPTION_AES\n");
2764 //wd->sta.wepStatus = ZM_ENCRYPTION_AES;
2765 //wd->ws.wepStatus = ZM_ENCRYPTION_AES;
2766 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_AES);
2770 zfiWlanSetWpaSupport(dev, 1);
2774 /* Reset the WPA related variables */
2775 printk(KERN_ERR "disable\n");
2777 zfiWlanSetWpaSupport(dev, 0);
2778 zfiWlanSetAuthenticationMode(dev, ZM_AUTH_MODE_OPEN);
2779 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_WEP_DISABLED);
2781 /* Now we only set the length in the WPA IE
2783 //macp->cardSetting.WPAIe[1] = 0;
2786 if(op == ZD_PARAM_COUNTERMEASURES)
2788 printk(KERN_ERR "================ZD_PARAM_COUNTERMEASURES: ");
2792 // mCounterMeasureState=1;
2793 printk(KERN_ERR "enable\n");
2797 // mCounterMeasureState=0;
2798 printk(KERN_ERR "disable\n");
2801 if(op == ZD_PARAM_DROPUNENCRYPTED)
2803 printk(KERN_ERR "ZD_PARAM_DROPUNENCRYPTED: ");
2807 printk(KERN_ERR "enable\n");
2811 printk(KERN_ERR "disable\n");
2814 if(op == ZD_PARAM_AUTH_ALGS)
2816 printk(KERN_ERR "ZD_PARAM_AUTH_ALGS: ");
2820 printk(KERN_ERR "OPEN_SYSTEM\n");
2824 printk(KERN_ERR "SHARED_KEY\n");
2827 if(op == ZD_PARAM_WPS_FILTER)
2829 printk(KERN_ERR "ZD_PARAM_WPS_FILTER: ");
2833 // mCounterMeasureState=1;
2834 macp->forwardMgmt = 1;
2835 printk(KERN_ERR "enable\n");
2839 // mCounterMeasureState=0;
2840 macp->forwardMgmt = 0;
2841 printk(KERN_ERR "disable\n");
2848 case ZD_IOCTL_GETWPAIE:
2850 struct ieee80211req_wpaie req_wpaie;
2854 apId = zfLnxGetVapId(dev);
2865 if (copy_from_user(&req_wpaie, ifr->ifr_data, sizeof(struct ieee80211req_wpaie))){
2866 printk(KERN_ERR "usbdrv: copy_from_user error\n");
2870 for(i = 0; i < ZM_OAL_MAX_STA_SUPPORT; i++)
2872 for(j = 0; j < IEEE80211_ADDR_LEN; j++)
2874 if (macp->stawpaie[i].wpa_macaddr[j] != req_wpaie.wpa_macaddr[j])
2880 if (i < ZM_OAL_MAX_STA_SUPPORT)
2882 //printk("ZD_IOCTL_GETWPAIE - sta index = %d\n", i);
2883 memcpy(req_wpaie.wpa_ie, macp->stawpaie[i].wpa_ie, IEEE80211_MAX_IE_SIZE);
2886 if (copy_to_user(wrq->u.data.pointer, &req_wpaie, sizeof(struct ieee80211req_wpaie)))
2894 #ifdef ZM_ENABLE_CENC
2896 if (copy_from_user(&macp->zd_wpa_req, ifr->ifr_data, sizeof(struct athr_wlan_param)))
2898 printk(KERN_ERR "usbdrv: copy_from_user error\n");
2902 usbdrv_cenc_ioctl(dev, (struct zydas_cenc_param *)&macp->zd_wpa_req);
2905 #endif //ZM_ENABLE_CENC