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 <linux/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) {
114 return ((freq-2412)/5) + 1;
117 u16_t num_chan = sizeof(channel_frequency_11A)/sizeof(u32_t);
119 for (ii = 1; ii < num_chan; ii += 2) {
120 if (channel_frequency_11A[ii] == freq)
121 return channel_frequency_11A[ii-1];
128 int usbdrv_chan2freq(int chan)
132 /* If channel number is out of range */
133 if (chan > 165 || chan <= 0)
137 if (chan >= 1 && chan <= 13) {
138 freq = (2412 + (chan - 1) * 5);
140 } else if (chan >= 36 && chan <= 165) {
142 u16_t num_chan = sizeof(channel_frequency_11A)/sizeof(u32_t);
144 for (ii = 0; ii < num_chan; ii += 2) {
145 if (channel_frequency_11A[ii] == chan)
146 return channel_frequency_11A[ii+1];
149 /* Can't find desired frequency */
154 /* Can't find deisred frequency */
158 int usbdrv_ioctl_setessid(struct net_device *dev, struct iw_point *erq)
160 #ifdef ZM_HOSTAPD_SUPPORT
161 /* struct usbdrv_private *macp = dev->ml_priv; */
162 char essidbuf[IW_ESSID_MAX_SIZE+1];
165 if (!netif_running(dev))
168 memset(essidbuf, 0, sizeof(essidbuf));
170 printk(KERN_ERR "usbdrv_ioctl_setessid\n");
172 /* printk("ssidlen=%d\n", erq->length); //for any, it is 1. */
174 if (erq->length > (IW_ESSID_MAX_SIZE+1))
177 if (copy_from_user(essidbuf, erq->pointer, erq->length))
181 /* zd_DisasocAll(2); */
184 printk(KERN_ERR "essidbuf: ");
186 for (i = 0; i < erq->length; i++)
187 printk(KERN_ERR "%02x ", essidbuf[i]);
189 printk(KERN_ERR "\n");
191 essidbuf[erq->length] = '\0';
192 /* memcpy(macp->wd.ws.ssid, essidbuf, erq->length); */
193 /* macp->wd.ws.ssidLen = strlen(essidbuf)+2; */
194 /* macp->wd.ws.ssid[1] = strlen(essidbuf); Update ssid length */
196 zfiWlanSetSSID(dev, essidbuf, erq->length);
198 printk(KERN_ERR "macp->wd.ws.ssid: ");
200 for (i = 0; i < macp->wd.ws.ssidLen; i++)
201 printk(KERN_ERR "%02x ", macp->wd.ws.ssid[i]);
203 printk(KERN_ERR "\n");
206 zfiWlanDisable(dev, 0);
214 int usbdrv_ioctl_getessid(struct net_device *dev, struct iw_point *erq)
216 /* struct usbdrv_private *macp = dev->ml_priv; */
217 u8_t essidbuf[IW_ESSID_MAX_SIZE+1];
222 /* len = macp->wd.ws.ssidLen; */
223 /* memcpy(essidbuf, macp->wd.ws.ssid, macp->wd.ws.ssidLen); */
224 zfiWlanQuerySSID(dev, essidbuf, &len);
228 printk(KERN_ERR "ESSID: ");
230 for (i = 0; i < len; i++)
231 printk(KERN_ERR "%c", essidbuf[i]);
233 printk(KERN_ERR "\n");
236 erq->length = strlen(essidbuf) + 1;
239 if (copy_to_user(erq->pointer, essidbuf, erq->length))
246 int usbdrv_ioctl_setrts(struct net_device *dev, struct iw_param *rrq)
251 #if WIRELESS_EXT > 14
253 * Encode a WPA or RSN information element as a custom
254 * element using the hostap format.
256 u32 encode_ie(void *buf, u32 bufsize, const u8 *ie, u32 ielen,
257 const u8 *leader, u32 leader_len)
262 if (bufsize < leader_len)
265 memcpy(p, leader, leader_len);
266 bufsize -= leader_len;
268 for (i = 0; i < ielen && bufsize > 2; i++)
269 p += sprintf(p, "%02x", ie[i]);
270 return (i == ielen ? p - (u8 *)buf:0);
272 #endif /* WIRELESS_EXT > 14 */
275 * Translate scan data returned from the card to a card independent
276 * format that the Wireless Tools will understand
278 char *usbdrv_translate_scan(struct net_device *dev,
279 struct iw_request_info *info, char *current_ev,
280 char *end_buf, struct zsBssInfo *list)
282 struct iw_event iwe; /* Temporary buffer */
284 char *current_val; /* For rates */
287 #if WIRELESS_EXT > 14
291 last_ev = current_ev;
293 /* First entry *MUST* be the AP MAC address */
295 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
296 memcpy(iwe.u.ap_addr.sa_data, list->bssid, ETH_ALEN);
297 current_ev = iwe_stream_add_event(info, current_ev,
298 end_buf, &iwe, IW_EV_ADDR_LEN);
300 /* Ran out of buffer */
301 if (last_ev == current_ev)
304 last_ev = current_ev;
306 /* Other entries will be displayed in the order we give them */
309 iwe.u.data.length = list->ssid[1];
310 if (iwe.u.data.length > 32)
311 iwe.u.data.length = 32;
312 iwe.cmd = SIOCGIWESSID;
313 iwe.u.data.flags = 1;
314 current_ev = iwe_stream_add_point(info, current_ev,
315 end_buf, &iwe, &list->ssid[2]);
317 /* Ran out of buffer */
318 if (last_ev == current_ev)
321 last_ev = current_ev;
324 iwe.cmd = SIOCGIWMODE;
325 capabilities = (list->capability[1] << 8) + list->capability[0];
326 if (capabilities & (0x01 | 0x02)) {
327 if (capabilities & 0x01)
328 iwe.u.mode = IW_MODE_MASTER;
330 iwe.u.mode = IW_MODE_ADHOC;
331 current_ev = iwe_stream_add_event(info, current_ev,
332 end_buf, &iwe, IW_EV_UINT_LEN);
335 /* Ran out of buffer */
336 if (last_ev == current_ev)
339 last_ev = current_ev;
342 iwe.cmd = SIOCGIWFREQ;
343 iwe.u.freq.m = list->channel;
344 /* Channel frequency in KHz */
345 if (iwe.u.freq.m > 14) {
346 if ((184 <= iwe.u.freq.m) && (iwe.u.freq.m <= 196))
347 iwe.u.freq.m = 4000 + iwe.u.freq.m * 5;
349 iwe.u.freq.m = 5000 + iwe.u.freq.m * 5;
351 if (iwe.u.freq.m == 14)
354 iwe.u.freq.m = 2412 + (iwe.u.freq.m - 1) * 5;
357 current_ev = iwe_stream_add_event(info, current_ev,
358 end_buf, &iwe, IW_EV_FREQ_LEN);
360 /* Ran out of buffer */
361 if (last_ev == current_ev)
364 last_ev = current_ev;
366 /* Add quality statistics */
368 #if WIRELESS_EXT > 18
369 iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED
370 | IW_QUAL_NOISE_UPDATED;
372 iwe.u.qual.level = list->signalStrength;
373 iwe.u.qual.noise = 0;
374 iwe.u.qual.qual = list->signalQuality;
375 current_ev = iwe_stream_add_event(info, current_ev,
376 end_buf, &iwe, IW_EV_QUAL_LEN);
378 /* Ran out of buffer */
379 if (last_ev == current_ev)
382 last_ev = current_ev;
384 /* Add encryption capability */
386 iwe.cmd = SIOCGIWENCODE;
387 if (capabilities & 0x10)
388 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
390 iwe.u.data.flags = IW_ENCODE_DISABLED;
392 iwe.u.data.length = 0;
393 current_ev = iwe_stream_add_point(info, current_ev,
394 end_buf, &iwe, list->ssid);
396 /* Ran out of buffer */
397 if (last_ev == current_ev)
400 last_ev = current_ev;
402 /* Rate : stuffing multiple values in a single event require a bit
405 current_val = current_ev + IW_EV_LCP_LEN;
407 iwe.cmd = SIOCGIWRATE;
408 /* Those two flags are ignored... */
409 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
411 for (i = 0 ; i < list->supportedRates[1] ; i++) {
412 /* Bit rate given in 500 kb/s units (+ 0x80) */
413 iwe.u.bitrate.value = ((list->supportedRates[i+2] & 0x7f)
415 /* Add new value to event */
416 current_val = iwe_stream_add_value(info, current_ev,
417 current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
419 /* Ran out of buffer */
420 if (last_ev == current_val)
423 last_ev = current_val;
426 for (i = 0 ; i < list->extSupportedRates[1] ; i++) {
427 /* Bit rate given in 500 kb/s units (+ 0x80) */
428 iwe.u.bitrate.value = ((list->extSupportedRates[i+2] & 0x7f)
430 /* Add new value to event */
431 current_val = iwe_stream_add_value(info, current_ev,
432 current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
434 /* Ran out of buffer */
435 if (last_ev == current_val)
438 last_ev = current_ev;
441 /* Check if we added any event */
442 if ((current_val - current_ev) > IW_EV_LCP_LEN)
443 current_ev = current_val;
444 #if WIRELESS_EXT > 14
445 #define IEEE80211_ELEMID_RSN 0x30
446 memset(&iwe, 0, sizeof(iwe));
447 iwe.cmd = IWEVCUSTOM;
448 snprintf(buf, sizeof(buf), "bcn_int=%d", (list->beaconInterval[1] << 8)
449 + list->beaconInterval[0]);
450 iwe.u.data.length = strlen(buf);
451 current_ev = iwe_stream_add_point(info, current_ev,
454 /* Ran out of buffer */
455 if (last_ev == current_ev)
458 last_ev = current_ev;
460 if (list->wpaIe[1] != 0) {
461 static const char rsn_leader[] = "rsn_ie=";
462 static const char wpa_leader[] = "wpa_ie=";
464 memset(&iwe, 0, sizeof(iwe));
465 iwe.cmd = IWEVCUSTOM;
466 if (list->wpaIe[0] == IEEE80211_ELEMID_RSN)
467 iwe.u.data.length = encode_ie(buf, sizeof(buf),
468 list->wpaIe, list->wpaIe[1]+2,
469 rsn_leader, sizeof(rsn_leader)-1);
471 iwe.u.data.length = encode_ie(buf, sizeof(buf),
472 list->wpaIe, list->wpaIe[1]+2,
473 wpa_leader, sizeof(wpa_leader)-1);
475 if (iwe.u.data.length != 0)
476 current_ev = iwe_stream_add_point(info, current_ev,
479 /* Ran out of buffer */
480 if (last_ev == current_ev)
483 last_ev = current_ev;
486 if (list->rsnIe[1] != 0) {
487 static const char rsn_leader[] = "rsn_ie=";
488 memset(&iwe, 0, sizeof(iwe));
489 iwe.cmd = IWEVCUSTOM;
491 if (list->rsnIe[0] == IEEE80211_ELEMID_RSN) {
492 iwe.u.data.length = encode_ie(buf, sizeof(buf),
493 list->rsnIe, list->rsnIe[1]+2,
494 rsn_leader, sizeof(rsn_leader)-1);
495 if (iwe.u.data.length != 0)
496 current_ev = iwe_stream_add_point(info,
497 current_ev, end_buf, &iwe, buf);
499 /* Ran out of buffer */
500 if (last_ev == current_ev)
503 last_ev = current_ev;
507 /* The other data in the scan result are not really
508 * interesting, so for now drop it
513 int usbdrvwext_giwname(struct net_device *dev,
514 struct iw_request_info *info,
515 union iwreq_data *wrq, char *extra)
517 /* struct usbdrv_private *macp = dev->ml_priv; */
519 strcpy(wrq->name, "IEEE 802.11-MIMO");
524 int usbdrvwext_siwfreq(struct net_device *dev,
525 struct iw_request_info *info,
526 struct iw_freq *freq, char *extra)
529 struct usbdrv_private *macp = dev->ml_priv;
531 if (!netif_running(dev))
538 FreqKHz = (freq->m / 100000);
540 if (FreqKHz > 4000000) {
541 if (FreqKHz > 5825000)
543 else if (FreqKHz < 4920000)
545 else if (FreqKHz < 5000000)
546 FreqKHz = (((FreqKHz - 4000000) / 5000) * 5000)
549 FreqKHz = (((FreqKHz - 5000000) / 5000) * 5000)
552 if (FreqKHz > 2484000)
554 else if (FreqKHz < 2412000)
557 FreqKHz = (((FreqKHz - 2412000) / 5000) * 5000)
561 FreqKHz = usbdrv_chan2freq(freq->m);
569 /* printk("freq->m: %d, freq->e: %d\n", freq->m, freq->e); */
570 /* printk("FreqKHz: %d\n", FreqKHz); */
572 if (macp->DeviceOpened == 1) {
573 zfiWlanSetFrequency(dev, FreqKHz, 0); /* Immediate */
574 /* u8_t wpaieLen,wpaie[50]; */
575 /* zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen); */
576 zfiWlanDisable(dev, 0);
578 /* if (wpaieLen > 2) */
579 /* zfiWlanSetWpaIe(dev, wpaie, wpaieLen); */
585 int usbdrvwext_giwfreq(struct net_device *dev,
586 struct iw_request_info *info,
587 struct iw_freq *freq, char *extra)
589 struct usbdrv_private *macp = dev->ml_priv;
591 if (macp->DeviceOpened != 1)
594 freq->m = zfiWlanQueryFrequency(dev);
600 int usbdrvwext_siwmode(struct net_device *dev,
601 struct iw_request_info *info,
602 union iwreq_data *wrq, char *extra)
604 struct usbdrv_private *macp = dev->ml_priv;
607 if (!netif_running(dev))
610 if (macp->DeviceOpened != 1)
615 WlanMode = ZM_MODE_AP;
618 WlanMode = ZM_MODE_INFRASTRUCTURE;
621 WlanMode = ZM_MODE_IBSS;
624 WlanMode = ZM_MODE_IBSS;
628 zfiWlanSetWlanMode(dev, WlanMode);
629 zfiWlanDisable(dev, 1);
635 int usbdrvwext_giwmode(struct net_device *dev,
636 struct iw_request_info *info,
637 __u32 *mode, char *extra)
639 unsigned long irqFlag;
640 struct usbdrv_private *macp = dev->ml_priv;
642 if (!netif_running(dev))
645 if (macp->DeviceOpened != 1)
648 spin_lock_irqsave(&macp->cs_lock, irqFlag);
650 switch (zfiWlanQueryWlanMode(dev)) {
652 *mode = IW_MODE_MASTER;
654 case ZM_MODE_INFRASTRUCTURE:
655 *mode = IW_MODE_INFRA;
658 *mode = IW_MODE_ADHOC;
661 *mode = IW_MODE_ADHOC;
665 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
670 int usbdrvwext_siwsens(struct net_device *dev,
671 struct iw_request_info *info,
672 struct iw_param *sens, char *extra)
677 int usbdrvwext_giwsens(struct net_device *dev,
678 struct iw_request_info *info,
679 struct iw_param *sens, char *extra)
687 int usbdrvwext_giwrange(struct net_device *dev,
688 struct iw_request_info *info,
689 struct iw_point *data, char *extra)
691 struct iw_range *range = (struct iw_range *) extra;
693 /* int num_band_a; */
697 if (!netif_running(dev))
701 range->txpower_capa = IW_TXPOW_DBM;
702 /* XXX what about min/max_pmp, min/max_pmt, etc. */
705 #if WIRELESS_EXT > 10
706 range->we_version_compiled = WIRELESS_EXT;
707 range->we_version_source = 13;
709 range->retry_capa = IW_RETRY_LIMIT;
710 range->retry_flags = IW_RETRY_LIMIT;
711 range->min_retry = 0;
712 range->max_retry = 255;
713 #endif /* WIRELESS_EXT > 10 */
715 channel_num = zfiWlanQueryAllowChannels(dev, channels);
717 /* Gurantee reported channel numbers is less
718 * or equal to IW_MAX_FREQUENCIES
720 if (channel_num > IW_MAX_FREQUENCIES)
721 channel_num = IW_MAX_FREQUENCIES;
725 for (i = 0; i < channel_num; i++) {
726 range->freq[val].i = usbdrv_freq2chan(channels[i]);
727 range->freq[val].m = channels[i];
728 range->freq[val].e = 6;
732 range->num_channels = channel_num;
733 range->num_frequency = channel_num;
736 range->num_channels = 14; /* Only 2.4G */
738 /* XXX need to filter against the regulatory domain &| active set */
741 for (i = 1; i <= 14; i++) {
742 range->freq[val].i = i;
744 range->freq[val].m = 2484000;
746 range->freq[val].m = (2412+(i-1)*5)*1000;
747 range->freq[val].e = 3;
751 num_band_a = (IW_MAX_FREQUENCIES - val);
753 for (i = 0; i < num_band_a; i++) {
754 range->freq[val].i = channel_frequency_11A[2 * i];
755 range->freq[val].m = channel_frequency_11A[2 * i + 1] * 1000;
756 range->freq[val].e = 3;
759 /* MIMO Rate Not Defined Now
760 * For 802.11a, there are too more frequency.
761 * We can't return them all.
763 range->num_frequency = val;
766 /* Max of /proc/net/wireless */
767 range->max_qual.qual = 100; /* ?? 92; */
768 range->max_qual.level = 154; /* ?? */
769 range->max_qual.noise = 154; /* ?? */
770 range->sensitivity = 3; /* ?? */
772 /* XXX these need to be nsd-specific! */
774 range->max_rts = 2347;
775 range->min_frag = 256;
776 range->max_frag = 2346;
777 range->max_encoding_tokens = 4 /* NUM_WEPKEYS ?? */;
778 range->num_encoding_sizes = 2; /* ?? */
780 range->encoding_size[0] = 5; /* ?? WEP Key Encoding Size */
781 range->encoding_size[1] = 13; /* ?? */
783 /* XXX what about num_bitrates/throughput? */
784 range->num_bitrates = 0; /* ?? */
786 /* estimated max throughput
787 * XXX need to cap it if we're running at ~2Mbps..
790 range->throughput = 300000000;
795 int usbdrvwext_siwap(struct net_device *dev, struct iw_request_info *info,
796 struct sockaddr *MacAddr, char *extra)
798 struct usbdrv_private *macp = dev->ml_priv;
800 if (!netif_running(dev))
803 if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) {
805 zfiWlanSetMacAddress(dev, (u16_t *)&MacAddr->sa_data[0]);
808 zfiWlanSetBssid(dev, &MacAddr->sa_data[0]);
811 if (macp->DeviceOpened == 1) {
812 /* u8_t wpaieLen,wpaie[80]; */
813 /* zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen); */
814 zfiWlanDisable(dev, 0);
816 /* if (wpaieLen > 2) */
817 /* zfiWlanSetWpaIe(dev, wpaie, wpaieLen); */
823 int usbdrvwext_giwap(struct net_device *dev,
824 struct iw_request_info *info,
825 struct sockaddr *MacAddr, char *extra)
827 struct usbdrv_private *macp = dev->ml_priv;
829 if (macp->DeviceOpened != 1)
832 if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) {
834 zfiWlanQueryMacAddress(dev, &MacAddr->sa_data[0]);
837 if (macp->adapterState == ZM_STATUS_MEDIA_CONNECT) {
838 zfiWlanQueryBssid(dev, &MacAddr->sa_data[0]);
840 u8_t zero_addr[6] = { 0x00, 0x00, 0x00, 0x00,
842 memcpy(&MacAddr->sa_data[0], zero_addr,
850 int usbdrvwext_iwaplist(struct net_device *dev,
851 struct iw_request_info *info,
852 struct iw_point *data, char *extra)
854 /* Don't know how to do yet--CWYang(+) */
859 int usbdrvwext_siwscan(struct net_device *dev, struct iw_request_info *info,
860 struct iw_point *data, char *extra)
862 struct usbdrv_private *macp = dev->ml_priv;
864 if (macp->DeviceOpened != 1)
867 printk(KERN_WARNING "CWY - usbdrvwext_siwscan\n");
874 int usbdrvwext_giwscan(struct net_device *dev,
875 struct iw_request_info *info,
876 struct iw_point *data, char *extra)
878 struct usbdrv_private *macp = dev->ml_priv;
879 /* struct zsWlanDev* wd = (struct zsWlanDev*) zmw_wlan_dev(dev); */
880 char *current_ev = extra;
883 /* struct zsBssList BssList; */
884 struct zsBssListV1 *pBssList = kmalloc(sizeof(struct zsBssListV1),
886 /* BssList = wd->sta.pBssList; */
887 /* zmw_get_wlan_dev(dev); */
889 if (macp->DeviceOpened != 1)
892 if (data->length == 0)
893 end_buf = extra + IW_SCAN_MAX_DATA;
895 end_buf = extra + data->length;
897 printk(KERN_WARNING "giwscan - Report Scan Results\n");
898 /* printk("giwscan - BssList Sreucture Len : %d\n", sizeof(BssList));
899 * printk("giwscan - BssList Count : %d\n",
900 * wd->sta.pBssList->bssCount);
901 * printk("giwscan - UpdateBssList Count : %d\n",
902 * wd->sta.pUpdateBssList->bssCount);
904 zfiWlanQueryBssListV1(dev, pBssList);
905 /* zfiWlanQueryBssList(dev, &BssList); */
907 /* Read and parse all entries */
908 printk(KERN_WARNING "giwscan - pBssList->bssCount : %d\n",
910 /* printk("giwscan - BssList.bssCount : %d\n", BssList.bssCount); */
912 for (i = 0; i < pBssList->bssCount; i++) {
913 /* Translate to WE format this entry
914 * current_ev = usbdrv_translate_scan(dev, info, current_ev,
915 * extra + IW_SCAN_MAX_DATA, &pBssList->bssInfo[i]);
917 current_ev = usbdrv_translate_scan(dev, info, current_ev,
918 end_buf, &pBssList->bssInfo[i]);
920 #if WIRELESS_EXT > 16
921 if (current_ev == end_buf) {
923 data->length = current_ev - extra;
930 data->length = (current_ev - extra);
931 data->flags = 0; /* todo */
938 int usbdrvwext_siwessid(struct net_device *dev,
939 struct iw_request_info *info,
940 struct iw_point *essid, char *extra)
942 char EssidBuf[IW_ESSID_MAX_SIZE + 1];
943 struct usbdrv_private *macp = dev->ml_priv;
945 if (!netif_running(dev))
948 if (essid->flags == 1) {
949 if (essid->length > (IW_ESSID_MAX_SIZE + 1))
952 if (copy_from_user(&EssidBuf, essid->pointer, essid->length))
955 EssidBuf[essid->length] = '\0';
956 /* printk("siwessid - Set Essid : %s\n",EssidBuf); */
957 /* printk("siwessid - Essid Len : %d\n",essid->length); */
958 /* printk("siwessid - Essid Flag : %x\n",essid->flags); */
959 if (macp->DeviceOpened == 1) {
960 zfiWlanSetSSID(dev, EssidBuf, strlen(EssidBuf));
961 zfiWlanSetFrequency(dev, zfiWlanQueryFrequency(dev),
963 zfiWlanSetEncryMode(dev, zfiWlanQueryEncryMode(dev));
964 /* u8_t wpaieLen,wpaie[50]; */
965 /* zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen); */
966 zfiWlanDisable(dev, 0);
968 /* if (wpaieLen > 2) */
969 /* zfiWlanSetWpaIe(dev, wpaie, wpaieLen); */
976 int usbdrvwext_giwessid(struct net_device *dev,
977 struct iw_request_info *info,
978 struct iw_point *essid, char *extra)
980 struct usbdrv_private *macp = dev->ml_priv;
982 char EssidBuf[IW_ESSID_MAX_SIZE + 1];
985 if (!netif_running(dev))
988 if (macp->DeviceOpened != 1)
991 zfiWlanQuerySSID(dev, &EssidBuf[0], &EssidLen);
993 /* Convert type from unsigned char to char */
994 ssid_len = (int)EssidLen;
996 /* Make sure the essid length is not greater than IW_ESSID_MAX_SIZE */
997 if (ssid_len > IW_ESSID_MAX_SIZE)
998 ssid_len = IW_ESSID_MAX_SIZE;
1000 EssidBuf[ssid_len] = '\0';
1003 essid->length = strlen(EssidBuf);
1005 memcpy(extra, EssidBuf, essid->length);
1006 /* wireless.c in Kernel would handle copy_to_user -- line 679 */
1007 /* if (essid->pointer) {
1008 * if (copy_to_user(essid->pointer, EssidBuf, essid->length)) {
1009 * printk("giwessid - copy_to_user Fail\n");
1018 int usbdrvwext_siwnickn(struct net_device *dev,
1019 struct iw_request_info *info,
1020 struct iw_point *data, char *nickname)
1022 /* Exist but junk--CWYang(+) */
1026 int usbdrvwext_giwnickn(struct net_device *dev,
1027 struct iw_request_info *info,
1028 struct iw_point *data, char *nickname)
1030 struct usbdrv_private *macp = dev->ml_priv;
1032 char EssidBuf[IW_ESSID_MAX_SIZE + 1];
1034 if (macp->DeviceOpened != 1)
1037 zfiWlanQuerySSID(dev, &EssidBuf[0], &EssidLen);
1038 EssidBuf[EssidLen] = 0;
1041 data->length = strlen(EssidBuf);
1043 memcpy(nickname, EssidBuf, data->length);
1048 int usbdrvwext_siwrate(struct net_device *dev,
1049 struct iw_request_info *info,
1050 struct iw_param *frq, char *extra)
1052 struct usbdrv_private *macp = dev->ml_priv;
1053 /* Array to Define Rate Number that Send to Driver */
1054 u16_t zcIndextoRateBG[16] = {1000, 2000, 5500, 11000, 0, 0, 0, 0,
1055 48000, 24000, 12000, 6000, 54000, 36000, 18000, 9000};
1056 u16_t zcRateToMCS[] = {0xff, 0, 1, 2, 3, 0xb, 0xf, 0xa, 0xe, 0x9, 0xd,
1058 u8_t i, RateIndex = 4;
1061 /* printk("frq->disabled : 0x%x\n",frq->disabled); */
1062 /* printk("frq->value : 0x%x\n",frq->value); */
1064 RateKbps = frq->value / 1000;
1065 /* printk("RateKbps : %d\n", RateKbps); */
1066 for (i = 0; i < 16; i++) {
1067 if (RateKbps == zcIndextoRateBG[i])
1071 if (zcIndextoRateBG[RateIndex] == 0)
1073 /* printk("RateIndex : %x\n", RateIndex); */
1074 for (i = 0; i < 13; i++)
1075 if (RateIndex == zcRateToMCS[i])
1077 /* printk("Index : %x\n", i); */
1078 if (RateKbps == 65000) {
1080 printk(KERN_WARNING "RateIndex : %d\n", RateIndex);
1083 if (macp->DeviceOpened == 1) {
1084 zfiWlanSetTxRate(dev, i);
1085 /* zfiWlanDisable(dev); */
1086 /* zfiWlanEnable(dev); */
1092 int usbdrvwext_giwrate(struct net_device *dev,
1093 struct iw_request_info *info,
1094 struct iw_param *frq, char *extra)
1096 struct usbdrv_private *macp = dev->ml_priv;
1098 if (!netif_running(dev))
1101 if (macp->DeviceOpened != 1)
1106 frq->value = zfiWlanQueryRxRate(dev) * 1000;
1111 int usbdrvwext_siwrts(struct net_device *dev,
1112 struct iw_request_info *info,
1113 struct iw_param *rts, char *extra)
1115 struct usbdrv_private *macp = dev->ml_priv;
1116 int val = rts->value;
1118 if (macp->DeviceOpened != 1)
1124 if ((val < 0) || (val > 2347))
1127 zfiWlanSetRtsThreshold(dev, val);
1132 int usbdrvwext_giwrts(struct net_device *dev,
1133 struct iw_request_info *info,
1134 struct iw_param *rts, char *extra)
1136 struct usbdrv_private *macp = dev->ml_priv;
1138 if (!netif_running(dev))
1141 if (macp->DeviceOpened != 1)
1144 rts->value = zfiWlanQueryRtsThreshold(dev);
1145 rts->disabled = (rts->value >= 2347);
1151 int usbdrvwext_siwfrag(struct net_device *dev,
1152 struct iw_request_info *info,
1153 struct iw_param *frag, char *extra)
1155 struct usbdrv_private *macp = dev->ml_priv;
1156 u16_t fragThreshold;
1158 if (macp->DeviceOpened != 1)
1164 fragThreshold = frag->value;
1166 zfiWlanSetFragThreshold(dev, fragThreshold);
1171 int usbdrvwext_giwfrag(struct net_device *dev,
1172 struct iw_request_info *info,
1173 struct iw_param *frag, char *extra)
1175 struct usbdrv_private *macp = dev->ml_priv;
1177 unsigned long irqFlag;
1179 if (!netif_running(dev))
1182 if (macp->DeviceOpened != 1)
1185 spin_lock_irqsave(&macp->cs_lock, irqFlag);
1187 val = zfiWlanQueryFragThreshold(dev);
1191 frag->disabled = (val >= 2346);
1194 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
1199 int usbdrvwext_siwtxpow(struct net_device *dev,
1200 struct iw_request_info *info,
1201 struct iw_param *rrq, char *extra)
1203 /* Not support yet--CWYng(+) */
1207 int usbdrvwext_giwtxpow(struct net_device *dev,
1208 struct iw_request_info *info,
1209 struct iw_param *rrq, char *extra)
1211 /* Not support yet--CWYng(+) */
1215 int usbdrvwext_siwretry(struct net_device *dev,
1216 struct iw_request_info *info,
1217 struct iw_param *rrq, char *extra)
1219 /* Do nothing--CWYang(+) */
1223 int usbdrvwext_giwretry(struct net_device *dev,
1224 struct iw_request_info *info,
1225 struct iw_param *rrq, char *extra)
1227 /* Do nothing--CWYang(+) */
1231 int usbdrvwext_siwencode(struct net_device *dev,
1232 struct iw_request_info *info,
1233 struct iw_point *erq, char *key)
1235 struct zsKeyInfo keyInfo;
1237 int WepState = ZM_ENCRYPTION_WEP_DISABLED;
1238 struct usbdrv_private *macp = dev->ml_priv;
1240 if (!netif_running(dev))
1243 if ((erq->flags & IW_ENCODE_DISABLED) == 0) {
1245 keyInfo.keyLength = erq->length;
1246 keyInfo.keyIndex = (erq->flags & IW_ENCODE_INDEX) - 1;
1247 if (keyInfo.keyIndex >= 4)
1248 keyInfo.keyIndex = 0;
1249 keyInfo.flag = ZM_KEY_FLAG_DEFAULT_KEY;
1251 zfiWlanSetKey(dev, keyInfo);
1252 WepState = ZM_ENCRYPTION_WEP_ENABLED;
1254 for (i = 1; i < 4; i++)
1255 zfiWlanRemoveKey(dev, 0, i);
1256 WepState = ZM_ENCRYPTION_WEP_DISABLED;
1257 /* zfiWlanSetEncryMode(dev, ZM_NO_WEP); */
1260 if (macp->DeviceOpened == 1) {
1261 zfiWlanSetWepStatus(dev, WepState);
1262 zfiWlanSetFrequency(dev, zfiWlanQueryFrequency(dev), FALSE);
1263 /* zfiWlanSetEncryMode(dev, zfiWlanQueryEncryMode(dev)); */
1264 /* u8_t wpaieLen,wpaie[50]; */
1265 /* zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen); */
1266 zfiWlanDisable(dev, 0);
1268 /* if (wpaieLen > 2) */
1269 /* zfiWlanSetWpaIe(dev, wpaie, wpaieLen); */
1275 int usbdrvwext_giwencode(struct net_device *dev,
1276 struct iw_request_info *info,
1277 struct iw_point *erq, char *key)
1279 struct usbdrv_private *macp = dev->ml_priv;
1280 u8_t EncryptionMode;
1283 if (macp->DeviceOpened != 1)
1286 EncryptionMode = zfiWlanQueryEncryMode(dev);
1289 erq->flags = IW_ENCODE_ENABLED;
1291 erq->flags = IW_ENCODE_DISABLED;
1293 /* We can't return the key, so set the proper flag and return zero */
1294 erq->flags |= IW_ENCODE_NOKEY;
1297 /* Copy the key to the user buffer */
1298 switch (EncryptionMode) {
1314 #ifdef ZM_ENABLE_CENC
1316 /* ZM_ENABLE_CENC */
1325 printk(KERN_ERR "Unknown EncryMode\n");
1328 erq->length = keyLen;
1333 int usbdrvwext_siwpower(struct net_device *dev,
1334 struct iw_request_info *info,
1335 struct iw_param *frq, char *extra)
1337 struct usbdrv_private *macp = dev->ml_priv;
1340 if (macp->DeviceOpened != 1)
1344 PSMode = ZM_STA_PS_NONE;
1346 PSMode = ZM_STA_PS_MAX;
1348 zfiWlanSetPowerSaveMode(dev, PSMode);
1353 int usbdrvwext_giwpower(struct net_device *dev,
1354 struct iw_request_info *info,
1355 struct iw_param *frq, char *extra)
1357 unsigned long irqFlag;
1358 struct usbdrv_private *macp = dev->ml_priv;
1360 if (macp->DeviceOpened != 1)
1363 spin_lock_irqsave(&macp->cs_lock, irqFlag);
1365 if (zfiWlanQueryPowerSaveMode(dev) == ZM_STA_PS_NONE)
1370 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
1375 /*int usbdrvwext_setparam(struct net_device *dev, struct iw_request_info *info,
1376 * void *w, char *extra)
1378 * struct ieee80211vap *vap = dev->ml_priv;
1379 * struct ieee80211com *ic = vap->iv_ic;
1380 * struct ieee80211_rsnparms *rsn = &vap->iv_bss->ni_rsn;
1381 * int *i = (int *) extra;
1382 * int param = i[0]; // parameter id is 1st
1383 * int value = i[1]; // NB: most values are TYPE_INT
1386 * const struct ieee80211_authenticator *auth;
1387 * const struct ieee80211_aclator *acl;
1390 * case IEEE80211_PARAM_AUTHMODE:
1392 * case IEEE80211_AUTH_WPA: // WPA
1393 * case IEEE80211_AUTH_8021X: // 802.1x
1394 * case IEEE80211_AUTH_OPEN: // open
1395 * case IEEE80211_AUTH_SHARED: // shared-key
1396 * case IEEE80211_AUTH_AUTO: // auto
1397 * auth = ieee80211_authenticator_get(value);
1405 * case IEEE80211_AUTH_WPA: // WPA w/ 802.1x
1406 * vap->iv_flags |= IEEE80211_F_PRIVACY;
1407 * value = IEEE80211_AUTH_8021X;
1409 * case IEEE80211_AUTH_OPEN: // open
1410 * vap->iv_flags &= ~(IEEE80211_F_WPA | IEEE80211_F_PRIVACY);
1412 * case IEEE80211_AUTH_SHARED: // shared-key
1413 * case IEEE80211_AUTH_AUTO: // auto
1414 * case IEEE80211_AUTH_8021X: // 802.1x
1415 * vap->iv_flags &= ~IEEE80211_F_WPA;
1416 * // both require a key so mark the PRIVACY capability
1417 * vap->iv_flags |= IEEE80211_F_PRIVACY;
1420 * // NB: authenticator attach/detach happens on state change
1421 * vap->iv_bss->ni_authmode = value;
1422 * // XXX mixed/mode/usage?
1423 * vap->iv_auth = auth;
1426 * case IEEE80211_PARAM_PROTMODE:
1427 * if (value > IEEE80211_PROT_RTSCTS)
1429 * ic->ic_protmode = value;
1430 * // NB: if not operating in 11g this can wait
1431 * if (ic->ic_bsschan != IEEE80211_CHAN_ANYC &&
1432 * IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan))
1435 * case IEEE80211_PARAM_MCASTCIPHER:
1436 * if ((vap->iv_caps & cipher2cap(value)) == 0 &&
1437 * !ieee80211_crypto_available(value))
1439 * rsn->rsn_mcastcipher = value;
1440 * if (vap->iv_flags & IEEE80211_F_WPA)
1443 * case IEEE80211_PARAM_MCASTKEYLEN:
1444 * if (!(0 < value && value < IEEE80211_KEYBUF_SIZE))
1446 * // XXX no way to verify driver capability
1447 * rsn->rsn_mcastkeylen = value;
1448 * if (vap->iv_flags & IEEE80211_F_WPA)
1451 * case IEEE80211_PARAM_UCASTCIPHERS:
1453 * // Convert cipher set to equivalent capabilities.
1454 * // NB: this logic intentionally ignores unknown and
1455 * // unsupported ciphers so folks can specify 0xff or
1456 * // similar and get all available ciphers.
1459 * for (j = 1; j < 32; j++) // NB: skip WEP
1460 * if ((value & (1<<j)) &&
1461 * ((vap->iv_caps & cipher2cap(j)) ||
1462 * ieee80211_crypto_available(j)))
1464 * if (caps == 0) // nothing available
1466 * // XXX verify ciphers ok for unicast use?
1467 * // XXX disallow if running as it'll have no effect
1468 * rsn->rsn_ucastcipherset = caps;
1469 * if (vap->iv_flags & IEEE80211_F_WPA)
1472 * case IEEE80211_PARAM_UCASTCIPHER:
1473 * if ((rsn->rsn_ucastcipherset & cipher2cap(value)) == 0)
1475 * rsn->rsn_ucastcipher = value;
1477 * case IEEE80211_PARAM_UCASTKEYLEN:
1478 * if (!(0 < value && value < IEEE80211_KEYBUF_SIZE))
1480 * // XXX no way to verify driver capability
1481 * rsn->rsn_ucastkeylen = value;
1483 * case IEEE80211_PARAM_KEYMGTALGS:
1485 * rsn->rsn_keymgmtset = value;
1486 * if (vap->iv_flags & IEEE80211_F_WPA)
1489 * case IEEE80211_PARAM_RSNCAPS:
1491 * rsn->rsn_caps = value;
1492 * if (vap->iv_flags & IEEE80211_F_WPA)
1495 * case IEEE80211_PARAM_WPA:
1498 * // XXX verify ciphers available
1499 * vap->iv_flags &= ~IEEE80211_F_WPA;
1502 * vap->iv_flags |= IEEE80211_F_WPA1;
1505 * vap->iv_flags |= IEEE80211_F_WPA2;
1508 * vap->iv_flags |= IEEE80211_F_WPA1 | IEEE80211_F_WPA2;
1511 * retv = ENETRESET; // XXX?
1513 * case IEEE80211_PARAM_ROAMING:
1514 * if (!(IEEE80211_ROAMING_DEVICE <= value &&
1515 * value <= IEEE80211_ROAMING_MANUAL))
1517 * ic->ic_roaming = value;
1519 * case IEEE80211_PARAM_PRIVACY:
1521 * // XXX check for key state?
1522 * vap->iv_flags |= IEEE80211_F_PRIVACY;
1524 * vap->iv_flags &= ~IEEE80211_F_PRIVACY;
1526 * case IEEE80211_PARAM_DROPUNENCRYPTED:
1528 * vap->iv_flags |= IEEE80211_F_DROPUNENC;
1530 * vap->iv_flags &= ~IEEE80211_F_DROPUNENC;
1532 * case IEEE80211_PARAM_COUNTERMEASURES:
1534 * if ((vap->iv_flags & IEEE80211_F_WPA) == 0)
1536 * vap->iv_flags |= IEEE80211_F_COUNTERM;
1538 * vap->iv_flags &= ~IEEE80211_F_COUNTERM;
1540 * case IEEE80211_PARAM_DRIVER_CAPS:
1541 * vap->iv_caps = value; // NB: for testing
1543 * case IEEE80211_PARAM_MACCMD:
1544 * acl = vap->iv_acl;
1546 * case IEEE80211_MACCMD_POLICY_OPEN:
1547 * case IEEE80211_MACCMD_POLICY_ALLOW:
1548 * case IEEE80211_MACCMD_POLICY_DENY:
1549 * if (acl == NULL) {
1550 * acl = ieee80211_aclator_get("mac");
1551 * if (acl == NULL || !acl->iac_attach(vap))
1553 * vap->iv_acl = acl;
1555 * acl->iac_setpolicy(vap, value);
1557 * case IEEE80211_MACCMD_FLUSH:
1559 * acl->iac_flush(vap);
1560 * // NB: silently ignore when not in use
1562 * case IEEE80211_MACCMD_DETACH:
1563 * if (acl != NULL) {
1564 * vap->iv_acl = NULL;
1565 * acl->iac_detach(vap);
1570 * case IEEE80211_PARAM_WMM:
1571 * if (ic->ic_caps & IEEE80211_C_WME){
1573 * vap->iv_flags |= IEEE80211_F_WME;
1574 * *//* XXX needed by ic_reset *//*
1575 * vap->iv_ic->ic_flags |= IEEE80211_F_WME;
1578 * *//* XXX needed by ic_reset *//*
1579 * vap->iv_flags &= ~IEEE80211_F_WME;
1580 * vap->iv_ic->ic_flags &= ~IEEE80211_F_WME;
1582 * retv = ENETRESET; // Renegotiate for capabilities
1585 * case IEEE80211_PARAM_HIDESSID:
1587 * vap->iv_flags |= IEEE80211_F_HIDESSID;
1589 * vap->iv_flags &= ~IEEE80211_F_HIDESSID;
1592 * case IEEE80211_PARAM_APBRIDGE:
1594 * vap->iv_flags |= IEEE80211_F_NOBRIDGE;
1596 * vap->iv_flags &= ~IEEE80211_F_NOBRIDGE;
1598 * case IEEE80211_PARAM_INACT:
1599 * vap->iv_inact_run = value / IEEE80211_INACT_WAIT;
1601 * case IEEE80211_PARAM_INACT_AUTH:
1602 * vap->iv_inact_auth = value / IEEE80211_INACT_WAIT;
1604 * case IEEE80211_PARAM_INACT_INIT:
1605 * vap->iv_inact_init = value / IEEE80211_INACT_WAIT;
1607 * case IEEE80211_PARAM_ABOLT:
1610 * // Map abolt settings to capability bits;
1611 * // this also strips unknown/unwanted bits.
1613 * if (value & IEEE80211_ABOLT_TURBO_PRIME)
1614 * caps |= IEEE80211_ATHC_TURBOP;
1615 * if (value & IEEE80211_ABOLT_COMPRESSION)
1616 * caps |= IEEE80211_ATHC_COMP;
1617 * if (value & IEEE80211_ABOLT_FAST_FRAME)
1618 * caps |= IEEE80211_ATHC_FF;
1619 * if (value & IEEE80211_ABOLT_XR)
1620 * caps |= IEEE80211_ATHC_XR;
1621 * if (value & IEEE80211_ABOLT_AR)
1622 * caps |= IEEE80211_ATHC_AR;
1623 * if (value & IEEE80211_ABOLT_BURST)
1624 * caps |= IEEE80211_ATHC_BURST;
1625 * if (value & IEEE80211_ABOLT_WME_ELE)
1626 * caps |= IEEE80211_ATHC_WME;
1627 * // verify requested capabilities are supported
1628 * if ((caps & ic->ic_ath_cap) != caps)
1630 * if (vap->iv_ath_cap != caps) {
1631 * if ((vap->iv_ath_cap ^ caps) & IEEE80211_ATHC_TURBOP) {
1632 * if (ieee80211_set_turbo(dev,
1633 * caps & IEEE80211_ATHC_TURBOP))
1635 * ieee80211_scan_flush(ic);
1637 * vap->iv_ath_cap = caps;
1638 * ic->ic_athcapsetup(vap->iv_ic, vap->iv_ath_cap);
1642 * case IEEE80211_PARAM_DTIM_PERIOD:
1643 * if (vap->iv_opmode != IEEE80211_M_HOSTAP &&
1644 * vap->iv_opmode != IEEE80211_M_IBSS)
1646 * if (IEEE80211_DTIM_MIN <= value &&
1647 * value <= IEEE80211_DTIM_MAX) {
1648 * vap->iv_dtim_period = value;
1649 * retv = ENETRESET; // requires restart
1653 * case IEEE80211_PARAM_BEACON_INTERVAL:
1654 * if (vap->iv_opmode != IEEE80211_M_HOSTAP &&
1655 * vap->iv_opmode != IEEE80211_M_IBSS)
1657 * if (IEEE80211_BINTVAL_MIN <= value &&
1658 * value <= IEEE80211_BINTVAL_MAX) {
1659 * ic->ic_lintval = value; // XXX multi-bss
1660 * retv = ENETRESET; // requires restart
1664 * case IEEE80211_PARAM_DOTH:
1666 * ic->ic_flags |= IEEE80211_F_DOTH;
1669 * ic->ic_flags &= ~IEEE80211_F_DOTH;
1670 * retv = ENETRESET; // XXX: need something this drastic?
1672 * case IEEE80211_PARAM_PWRTARGET:
1673 * ic->ic_curchanmaxpwr = value;
1675 * case IEEE80211_PARAM_GENREASSOC:
1676 * IEEE80211_SEND_MGMT(vap->iv_bss,
1677 * IEEE80211_FC0_SUBTYPE_REASSOC_REQ, 0);
1679 * case IEEE80211_PARAM_COMPRESSION:
1680 * retv = ieee80211_setathcap(vap, IEEE80211_ATHC_COMP, value);
1682 * case IEEE80211_PARAM_WMM_AGGRMODE:
1683 * retv = ieee80211_setathcap(vap, IEEE80211_ATHC_WME, value);
1685 * case IEEE80211_PARAM_FF:
1686 * retv = ieee80211_setathcap(vap, IEEE80211_ATHC_FF, value);
1688 * case IEEE80211_PARAM_TURBO:
1689 * retv = ieee80211_setathcap(vap, IEEE80211_ATHC_TURBOP, value);
1690 * if (retv == ENETRESET) {
1691 * if(ieee80211_set_turbo(dev,value))
1693 * ieee80211_scan_flush(ic);
1696 * case IEEE80211_PARAM_XR:
1697 * retv = ieee80211_setathcap(vap, IEEE80211_ATHC_XR, value);
1699 * case IEEE80211_PARAM_BURST:
1700 * retv = ieee80211_setathcap(vap, IEEE80211_ATHC_BURST, value);
1702 * case IEEE80211_PARAM_AR:
1703 * retv = ieee80211_setathcap(vap, IEEE80211_ATHC_AR, value);
1705 * case IEEE80211_PARAM_PUREG:
1707 * vap->iv_flags |= IEEE80211_F_PUREG;
1709 * vap->iv_flags &= ~IEEE80211_F_PUREG;
1710 * // NB: reset only if we're operating on an 11g channel
1711 * if (ic->ic_bsschan != IEEE80211_CHAN_ANYC &&
1712 * IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan))
1715 * case IEEE80211_PARAM_WDS:
1717 * vap->iv_flags_ext |= IEEE80211_FEXT_WDS;
1719 * vap->iv_flags_ext &= ~IEEE80211_FEXT_WDS;
1721 * case IEEE80211_PARAM_BGSCAN:
1723 * if ((vap->iv_caps & IEEE80211_C_BGSCAN) == 0)
1725 * vap->iv_flags |= IEEE80211_F_BGSCAN;
1728 * vap->iv_flags &= ~IEEE80211_F_BGSCAN;
1729 * ieee80211_cancel_scan(vap); // anything current
1732 * case IEEE80211_PARAM_BGSCAN_IDLE:
1733 * if (value >= IEEE80211_BGSCAN_IDLE_MIN)
1734 * vap->iv_bgscanidle = value*HZ/1000;
1738 * case IEEE80211_PARAM_BGSCAN_INTERVAL:
1739 * if (value >= IEEE80211_BGSCAN_INTVAL_MIN)
1740 * vap->iv_bgscanintvl = value*HZ;
1744 * case IEEE80211_PARAM_MCAST_RATE:
1745 * // units are in KILObits per second
1746 * if (value >= 256 && value <= 54000)
1747 * vap->iv_mcast_rate = value;
1751 * case IEEE80211_PARAM_COVERAGE_CLASS:
1752 * if (value >= 0 && value <= IEEE80211_COVERAGE_CLASS_MAX) {
1753 * ic->ic_coverageclass = value;
1754 * if (IS_UP_AUTO(vap))
1755 * ieee80211_new_state(vap, IEEE80211_S_SCAN, 0);
1761 * case IEEE80211_PARAM_COUNTRY_IE:
1763 * ic->ic_flags_ext |= IEEE80211_FEXT_COUNTRYIE;
1765 * ic->ic_flags_ext &= ~IEEE80211_FEXT_COUNTRYIE;
1768 * case IEEE80211_PARAM_REGCLASS:
1770 * ic->ic_flags_ext |= IEEE80211_FEXT_REGCLASS;
1772 * ic->ic_flags_ext &= ~IEEE80211_FEXT_REGCLASS;
1775 * case IEEE80211_PARAM_SCANVALID:
1776 * vap->iv_scanvalid = value*HZ;
1778 * case IEEE80211_PARAM_ROAM_RSSI_11A:
1779 * vap->iv_roam.rssi11a = value;
1781 * case IEEE80211_PARAM_ROAM_RSSI_11B:
1782 * vap->iv_roam.rssi11bOnly = value;
1784 * case IEEE80211_PARAM_ROAM_RSSI_11G:
1785 * vap->iv_roam.rssi11b = value;
1787 * case IEEE80211_PARAM_ROAM_RATE_11A:
1788 * vap->iv_roam.rate11a = value;
1790 * case IEEE80211_PARAM_ROAM_RATE_11B:
1791 * vap->iv_roam.rate11bOnly = value;
1793 * case IEEE80211_PARAM_ROAM_RATE_11G:
1794 * vap->iv_roam.rate11b = value;
1796 * case IEEE80211_PARAM_UAPSDINFO:
1797 * if (vap->iv_opmode == IEEE80211_M_HOSTAP) {
1798 * if (ic->ic_caps & IEEE80211_C_UAPSD) {
1800 * IEEE80211_VAP_UAPSD_ENABLE(vap);
1802 * IEEE80211_VAP_UAPSD_DISABLE(vap);
1806 * else if (vap->iv_opmode == IEEE80211_M_STA) {
1807 * vap->iv_uapsdinfo = value;
1808 * IEEE80211_VAP_UAPSD_ENABLE(vap);
1812 * case IEEE80211_PARAM_SLEEP:
1813 * // XXX: Forced sleep for testing. Does not actually place the
1814 * // HW in sleep mode yet. this only makes sense for STAs.
1818 * IEEE80211_VAP_GOTOSLEEP(vap);
1822 * IEEE80211_VAP_WAKEUP(vap);
1824 * ieee80211_send_nulldata(ieee80211_ref_node(vap->iv_bss));
1826 * case IEEE80211_PARAM_QOSNULL:
1827 * // Force a QoS Null for testing.
1828 * ieee80211_send_qosnulldata(vap->iv_bss, value);
1830 * case IEEE80211_PARAM_PSPOLL:
1831 * // Force a PS-POLL for testing.
1832 * ieee80211_send_pspoll(vap->iv_bss);
1834 * case IEEE80211_PARAM_EOSPDROP:
1835 * if (vap->iv_opmode == IEEE80211_M_HOSTAP) {
1836 * if (value) IEEE80211_VAP_EOSPDROP_ENABLE(vap);
1837 * else IEEE80211_VAP_EOSPDROP_DISABLE(vap);
1840 * case IEEE80211_PARAM_MARKDFS:
1842 * ic->ic_flags_ext |= IEEE80211_FEXT_MARKDFS;
1844 * ic->ic_flags_ext &= ~IEEE80211_FEXT_MARKDFS;
1846 * case IEEE80211_PARAM_CHANBW:
1849 * ic->ic_chanbwflag = 0;
1852 * ic->ic_chanbwflag = IEEE80211_CHAN_HALF;
1855 * ic->ic_chanbwflag = IEEE80211_CHAN_QUARTER;
1862 * case IEEE80211_PARAM_SHORTPREAMBLE:
1864 * ic->ic_caps |= IEEE80211_C_SHPREAMBLE;
1866 * ic->ic_caps &= ~IEEE80211_C_SHPREAMBLE;
1871 * retv = EOPNOTSUPP;
1874 * // XXX should any of these cause a rescan?
1875 * if (retv == ENETRESET)
1876 * retv = IS_UP_AUTO(vap) ? ieee80211_open(vap->iv_dev) : 0;
1881 int usbdrvwext_setmode(struct net_device *dev, struct iw_request_info *info,
1882 void *w, char *extra)
1887 int usbdrvwext_getmode(struct net_device *dev, struct iw_request_info *info,
1888 void *w, char *extra)
1890 /* struct usbdrv_private *macp = dev->ml_priv; */
1891 struct iw_point *wri = (struct iw_point *)extra;
1894 strcpy(mode, "11g");
1895 return copy_to_user(wri->pointer, mode, 6) ? -EFAULT : 0;
1898 int zfLnxPrivateIoctl(struct net_device *dev, struct zdap_ioctl* zdreq)
1900 /* void* regp = macp->regp; */
1908 case ZM_IOCTL_REG_READ:
1909 zfiDbgReadReg(dev, zdreq->addr);
1911 case ZM_IOCTL_REG_WRITE:
1912 zfiDbgWriteReg(dev, zdreq->addr, zdreq->value);
1914 case ZM_IOCTL_MEM_READ:
1915 p = (u32_t *) bus_to_virt(zdreq->addr);
1917 "usbdrv: read memory addr: 0x%08x value:"
1918 " 0x%08x\n", zdreq->addr, *p);
1920 case ZM_IOCTL_MEM_WRITE:
1921 p = (u32_t *) bus_to_virt(zdreq->addr);
1924 "usbdrv : write value : 0x%08x to memory addr :"
1925 " 0x%08x\n", zdreq->value, zdreq->addr);
1927 case ZM_IOCTL_TALLY:
1928 zfiWlanShowTally(dev);
1930 zfiWlanResetTally(dev);
1934 "ZM_IOCTL_TEST:len=%d\n", zdreq->addr);
1935 /* zfiWlanReadReg(dev, 0x10f400); */
1936 /* zfiWlanReadReg(dev, 0x10f404); */
1937 printk(KERN_WARNING "IOCTL TEST\n");
1940 for (i = 0; i < zdreq->addr; i++) {
1942 printk(KERN_WARNING "\n");
1943 printk(KERN_WARNING "%02X ",
1944 (unsigned char)zdreq->data[i]);
1946 printk(KERN_WARNING "\n");
1949 /* For Test?? 1 to 0 by CWYang(-) */
1953 /* Allocate a skb */
1954 s = alloc_skb(2000, GFP_ATOMIC);
1956 /* Copy data to skb */
1957 for (i = 0; i < zdreq->addr; i++)
1958 s->data[i] = zdreq->data[i];
1959 s->len = zdreq->addr;
1961 /* Call zfIdlRecv() */
1962 zfiRecv80211(dev, s, NULL);
1965 /************************* ZDCONFIG ***************************/
1967 zfiWlanSetFragThreshold(dev, zdreq->addr);
1970 zfiWlanSetRtsThreshold(dev, zdreq->addr);
1975 case ZM_IOCTL_KEY: {
1977 struct zsKeyInfo keyInfo;
1980 for (i = 0; i < 29; i++)
1983 for (i = 0; i < zdreq->addr; i++)
1984 key[i] = zdreq->data[i];
1987 "key len=%d, key=%02x%02x%02x%02x%02x...\n",
1988 zdreq->addr, key[0], key[1], key[2], key[3], key[4]);
1990 keyInfo.keyLength = zdreq->addr;
1991 keyInfo.keyIndex = 0;
1994 zfiWlanSetKey(dev, keyInfo);
1998 zfiWlanSetTxRate(dev, zdreq->addr);
2000 case ZM_IOCTL_ENCRYPTION_MODE:
2001 zfiWlanSetEncryMode(dev, zdreq->addr);
2003 zfiWlanDisable(dev, 0);
2007 case ZM_IOCTL_SIGNAL_STRENGTH: {
2009 zfiWlanQuerySignalInfo(dev, &buffer[0]);
2011 "Current Signal Strength : %02d\n", buffer[0]);
2015 case ZM_IOCTL_SIGNAL_QUALITY: {
2017 zfiWlanQuerySignalInfo(dev, &buffer[0]);
2019 "Current Signal Quality : %02d\n", buffer[1]);
2022 case ZM_IOCTL_SET_PIBSS_MODE:
2023 if (zdreq->addr == 1)
2024 zfiWlanSetWlanMode(dev, ZM_MODE_PSEUDO);
2026 zfiWlanSetWlanMode(dev, ZM_MODE_INFRASTRUCTURE);
2028 zfiWlanDisable(dev, 0);
2031 /********************* ZDCONFIG ***********************/
2033 printk(KERN_ERR "usbdrv: error command = %x\n", cmd);
2040 int usbdrv_wpa_ioctl(struct net_device *dev, struct athr_wlan_param *zdparm)
2043 u8_t bc_addr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2045 struct zsKeyInfo keyInfo;
2046 struct usbdrv_private *macp = dev->ml_priv;
2049 /* zmw_get_wlan_dev(dev); */
2051 switch (zdparm->cmd) {
2052 case ZD_CMD_SET_ENCRYPT_KEY:
2053 /* Set up key information */
2054 keyInfo.keyLength = zdparm->u.crypt.key_len;
2055 keyInfo.keyIndex = zdparm->u.crypt.idx;
2056 if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) {
2058 keyInfo.flag = ZM_KEY_FLAG_AUTHENTICATOR;
2061 keyInfo.key = zdparm->u.crypt.key;
2062 keyInfo.initIv = zdparm->u.crypt.seq;
2063 keyInfo.macAddr = (u16_t *)zdparm->sta_addr;
2065 /* Identify the MAC address information */
2066 if (memcmp(zdparm->sta_addr, bc_addr, sizeof(bc_addr)) == 0)
2067 keyInfo.flag |= ZM_KEY_FLAG_GK;
2069 keyInfo.flag |= ZM_KEY_FLAG_PK;
2071 if (!strcmp(zdparm->u.crypt.alg, "NONE")) {
2072 /* u8_t zero_mac[]={0,0,0,0,0,0}; */
2074 /* Set key length to zero */
2075 keyInfo.keyLength = 0;
2078 if (zdparm->sta_addr[0] & 1) {
2079 /* if (macp->cardSetting.WPAIeLen==0)
2080 * { 802.1x dynamic WEP
2082 * mKeyFormat[0] = 0;
2083 * mPrivacyInvoked[0]=FALSE;
2084 * mCap[0] &= ~CAP_PRIVACY;
2085 * macp->cardSetting.EncryOnOff[0]=0;
2087 * mWpaBcKeyLen = mGkInstalled = 0;
2090 /* if (memcmp(zero_mac,zdparm->sta_addr, 6)==0)
2094 * pSetting->DynKeyMode=0;
2095 * pSetting->EncryMode[0]=0;
2101 printk(KERN_ERR "Set Encryption Type NONE\n");
2103 } else if (!strcmp(zdparm->u.crypt.alg, "TKIP")) {
2104 zfiWlanSetEncryMode(dev, ZM_TKIP);
2105 /* //Linux Supplicant will inverse Tx/Rx key
2106 * //So we inverse it back, CWYang(+)
2107 * zfMemoryCopy(&temp[0], &keyInfo.key[16], 8);
2108 * zfMemoryCopy(&keyInfo.key[16], keyInfo.key[24], 8);
2109 * zfMemoryCopy(&keyInfo.key[24], &temp[0], 8);
2112 * for (k = 0; k < 8; k++)
2114 * temp = keyInfo.key[16 + k];
2115 * keyInfo.key[16 + k] = keyInfo.key[24 + k];
2116 * keyInfo.key[24 + k] = temp;
2118 * CamEncryType = ZM_TKIP;
2121 * mKeyFormat[0] = CamEncryType;
2122 * mDynKeyMode = pSetting->DynKeyMode = DYN_KEY_TKIP;
2125 } else if (!strcmp(zdparm->u.crypt.alg, "CCMP")) {
2126 zfiWlanSetEncryMode(dev, ZM_AES);
2127 /* CamEncryType = ZM_AES;
2130 * mKeyFormat[0] = CamEncryType;
2131 * mDynKeyMode = pSetting->DynKeyMode = DYN_KEY_AES;
2134 } else if (!strcmp(zdparm->u.crypt.alg, "WEP")) {
2135 if (keyInfo.keyLength == 5) {
2137 zfiWlanSetEncryMode(dev, ZM_WEP64);
2138 /* CamEncryType = ZM_WEP64; */
2139 /* tmpDynKeyMode=DYN_KEY_WEP64; */
2140 } else if (keyInfo.keyLength == 13) {
2141 /* keylen=13, WEP 128 */
2142 zfiWlanSetEncryMode(dev, ZM_WEP128);
2143 /* CamEncryType = ZM_WEP128; */
2144 /* tmpDynKeyMode=DYN_KEY_WEP128; */
2146 zfiWlanSetEncryMode(dev, ZM_WEP256);
2149 /* For Dynamic WEP key (Non-WPA Radius), the key ID range: 0-3
2150 * In WPA/RSN mode, the key ID range: 1-3, usually, a broadcast key.
2151 * For WEP key setting: we set mDynKeyMode and mKeyFormat in following
2153 * 1. For 802.1x dynamically generated WEP key method.
2154 * 2. For WPA/RSN mode, but key id == 0.
2155 * (But this is an impossible case)
2156 * So, only check case 1.
2157 * if (macp->cardSetting.WPAIeLen==0)
2159 * mKeyFormat[0] = CamEncryType;
2160 * mDynKeyMode = pSetting->DynKeyMode = tmpDynKeyMode;
2161 * mPrivacyInvoked[0]=TRUE;
2162 * mCap[0] |= CAP_PRIVACY;
2163 * macp->cardSetting.EncryOnOff[0]=1;
2168 /* DUMP key context */
2169 /* #ifdef WPA_DEBUG */
2170 if (keyInfo.keyLength > 0) {
2173 "Otus: Key Context:\n");
2174 for (ii = 0; ii < keyInfo.keyLength; ) {
2176 "0x%02x ", keyInfo.key[ii]);
2177 if ((++ii % 16) == 0)
2178 printk(KERN_WARNING "\n");
2180 printk(KERN_WARNING "\n");
2184 /* Set encrypt mode */
2185 /* zfiWlanSetEncryMode(dev, CamEncryType); */
2186 vapId = zfLnxGetVapId(dev);
2187 if (vapId == 0xffff)
2190 keyInfo.vapId = vapId + 1;
2191 keyInfo.vapAddr[0] = keyInfo.macAddr[0];
2192 keyInfo.vapAddr[1] = keyInfo.macAddr[1];
2193 keyInfo.vapAddr[2] = keyInfo.macAddr[2];
2195 zfiWlanSetKey(dev, keyInfo);
2197 /* zfiWlanDisable(dev); */
2198 /* zfiWlanEnable(dev); */
2200 case ZD_CMD_SET_MLME:
2201 printk(KERN_ERR "usbdrv_wpa_ioctl: ZD_CMD_SET_MLME\n");
2203 /* Translate STA's address */
2204 sprintf(mac_addr, "%02x:%02x:%02x:%02x:%02x:%02x",
2205 zdparm->sta_addr[0], zdparm->sta_addr[1],
2206 zdparm->sta_addr[2], zdparm->sta_addr[3],
2207 zdparm->sta_addr[4], zdparm->sta_addr[5]);
2209 switch (zdparm->u.mlme.cmd) {
2210 case MLME_STA_DEAUTH:
2212 " -------Call zfiWlanDeauth, reason:%d\n",
2213 zdparm->u.mlme.reason_code);
2214 if (zfiWlanDeauth(dev, (u16_t *) zdparm->sta_addr,
2215 zdparm->u.mlme.reason_code) != 0)
2216 printk(KERN_ERR "Can't deauthencate STA: %s\n",
2219 printk(KERN_ERR "Deauthenticate STA: %s"
2220 "with reason code: %d\n",
2221 mac_addr, zdparm->u.mlme.reason_code);
2223 case MLME_STA_DISASSOC:
2225 " -------Call zfiWlanDeauth, reason:%d\n",
2226 zdparm->u.mlme.reason_code);
2227 if (zfiWlanDeauth(dev, (u16_t *) zdparm->sta_addr,
2228 zdparm->u.mlme.reason_code) != 0)
2229 printk(KERN_ERR "Can't disassociate STA: %s\n",
2232 printk(KERN_ERR "Disassociate STA: %s"
2233 "with reason code: %d\n",
2234 mac_addr, zdparm->u.mlme.reason_code);
2237 printk(KERN_ERR "MLME command: 0x%04x not support\n",
2238 zdparm->u.mlme.cmd);
2243 case ZD_CMD_SCAN_REQ:
2244 printk(KERN_ERR "usbdrv_wpa_ioctl: ZD_CMD_SCAN_REQ\n");
2246 case ZD_CMD_SET_GENERIC_ELEMENT:
2247 printk(KERN_ERR "usbdrv_wpa_ioctl:"
2248 " ZD_CMD_SET_GENERIC_ELEMENT\n");
2251 * zm_msg1_mm(ZM_LV_0, "CWY - wpaie Length : ",
2252 * zdparm->u.generic_elem.len);
2254 printk(KERN_ERR "wpaie Length : % d\n",
2255 zdparm->u.generic_elem.len);
2256 if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) {
2258 zfiWlanSetWpaIe(dev, zdparm->u.generic_elem.data,
2259 zdparm->u.generic_elem.len);
2261 macp->supLen = zdparm->u.generic_elem.len;
2262 memcpy(macp->supIe, zdparm->u.generic_elem.data,
2263 zdparm->u.generic_elem.len);
2265 zfiWlanSetWpaSupport(dev, 1);
2266 /* zfiWlanSetWpaIe(dev, zdparm->u.generic_elem.data,
2267 * zdparm->u.generic_elem.len);
2270 u8_t len = zdparm->u.generic_elem.len;
2271 u8_t *wpaie = (u8_t *)zdparm->u.generic_elem.data;
2273 printk(KERN_ERR "wd->ap.wpaLen : % d\n", len);
2276 for(ii = 0; ii < len;) {
2277 printk(KERN_ERR "0x%02x ", wpaie[ii]);
2279 if((++ii % 16) == 0)
2280 printk(KERN_ERR "\n");
2282 printk(KERN_ERR "\n");
2284 /* #ifdef ZM_HOSTAPD_SUPPORT
2285 * if (wd->wlanMode == ZM_MODE_AP)
2286 * {// Update Beacon FIFO in the next TBTT.
2287 * memcpy(&mWPAIe, pSetting->WPAIe, pSetting->WPAIeLen);
2288 * printk(KERN_ERR "Copy WPA IE into mWPAIe\n");
2294 /* #ifdef ZM_HOSTAPD_SUPPORT */
2295 case ZD_CMD_GET_TSC:
2296 printk(KERN_ERR "usbdrv_wpa_ioctl : ZD_CMD_GET_TSC\n");
2301 printk(KERN_ERR "usbdrv_wpa_ioctl default : 0x%04x\n",
2310 #ifdef ZM_ENABLE_CENC
2311 int usbdrv_cenc_ioctl(struct net_device *dev, struct zydas_cenc_param *zdparm)
2313 /* struct usbdrv_private *macp = dev->ml_priv; */
2314 struct zsKeyInfo keyInfo;
2316 u8_t bc_addr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2321 apId = zfLnxGetVapId(dev);
2323 if (apId == 0xffff) {
2329 switch (zdparm->cmd) {
2330 case ZM_CMD_CENC_SETCENC:
2331 printk(KERN_ERR "ZM_CMD_CENC_SETCENC\n");
2332 printk(KERN_ERR "length : % d\n", zdparm->len);
2333 printk(KERN_ERR "policy : % d\n", zdparm->u.info.cenc_policy);
2335 case ZM_CMD_CENC_SETKEY:
2336 /* ret = wai_ioctl_setkey(vap, ioctl_msg); */
2337 printk(KERN_ERR "ZM_CMD_CENC_SETKEY\n");
2339 printk(KERN_ERR "MAC address = ");
2340 for (ii = 0; ii < 6; ii++) {
2341 printk(KERN_ERR "0x%02x ",
2342 zdparm->u.crypt.sta_addr[ii]);
2344 printk(KERN_ERR "\n");
2346 printk(KERN_ERR "Key Index : % d\n", zdparm->u.crypt.keyid);
2347 printk(KERN_ERR "Encryption key = ");
2348 for (ii = 0; ii < 16; ii++) {
2349 printk(KERN_ERR "0x%02x ", zdparm->u.crypt.key[ii]);
2351 printk(KERN_ERR "\n");
2353 printk(KERN_ERR "MIC key = ");
2354 for(ii = 16; ii < ZM_CENC_KEY_SIZE; ii++) {
2355 printk(KERN_ERR "0x%02x ", zdparm->u.crypt.key[ii]);
2357 printk(KERN_ERR "\n");
2359 /* Set up key information */
2360 keyInfo.keyLength = ZM_CENC_KEY_SIZE;
2361 keyInfo.keyIndex = zdparm->u.crypt.keyid;
2362 keyInfo.flag = ZM_KEY_FLAG_AUTHENTICATOR | ZM_KEY_FLAG_CENC;
2363 keyInfo.key = zdparm->u.crypt.key;
2364 keyInfo.macAddr = (u16_t *)zdparm->u.crypt.sta_addr;
2366 /* Identify the MAC address information */
2367 if (memcmp(zdparm->u.crypt.sta_addr, bc_addr,
2368 sizeof(bc_addr)) == 0) {
2369 keyInfo.flag |= ZM_KEY_FLAG_GK;
2370 keyInfo.vapId = apId;
2371 memcpy(keyInfo.vapAddr, dev->dev_addr, ETH_ALEN);
2373 keyInfo.flag |= ZM_KEY_FLAG_PK;
2376 zfiWlanSetKey(dev, keyInfo);
2379 case ZM_CMD_CENC_REKEY:
2380 /* ret = wai_ioctl_rekey(vap, ioctl_msg); */
2381 printk(KERN_ERR "ZM_CMD_CENC_REKEY\n");
2388 /* if (retv == ENETRESET) */
2389 /* retv = IS_UP_AUTO(vap) ? ieee80211_open(vap->iv_dev) : 0; */
2393 #endif /* ZM_ENABLE_CENC */
2395 int usbdrv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2397 /* struct usbdrv_private *macp; */
2399 struct zdap_ioctl zdreq;
2400 struct iwreq *wrq = (struct iwreq *)ifr;
2401 struct athr_wlan_param zdparm;
2402 struct usbdrv_private *macp = dev->ml_priv;
2407 /* regp = macp->regp; */
2409 if (!netif_running(dev))
2414 strcpy(wrq->u.name, "IEEE 802.11-DS");
2417 err = usbdrvwext_giwap(dev, NULL, &wrq->u.ap_addr, NULL);
2420 err = usbdrvwext_siwap(dev, NULL, &wrq->u.ap_addr, NULL);
2423 err = usbdrvwext_giwmode(dev, NULL, &wrq->u.mode, NULL);
2426 printk(KERN_ERR "CWY - usbdrvwext_siwessid\n");
2427 /* err = usbdrv_ioctl_setessid(dev, &wrq->u.essid); */
2428 err = usbdrvwext_siwessid(dev, NULL, &wrq->u.essid, NULL);
2434 err = usbdrvwext_giwessid(dev, NULL, &wrq->u.essid, NULL);
2437 err = usbdrv_ioctl_setrts(dev, &wrq->u.rts);
2442 case SIOCIWFIRSTPRIV + 0x2: {
2443 /* printk("CWY - SIOCIWFIRSTPRIV + 0x2(set_auth)\n"); */
2444 if (!capable(CAP_NET_ADMIN)) {
2448 int val = *((int *) wrq->u.name);
2449 if ((val < 0) || (val > 2)) {
2453 zfiWlanSetAuthenticationMode(dev, val);
2455 if (macp->DeviceOpened == 1) {
2456 zfiWlanDisable(dev, 0);
2466 case SIOCIWFIRSTPRIV + 0x3: {
2467 int AuthMode = ZM_AUTH_MODE_OPEN;
2469 /* printk("CWY - SIOCIWFIRSTPRIV + 0x3(get_auth)\n"); */
2471 if (wrq->u.data.pointer) {
2472 wrq->u.data.flags = 1;
2474 AuthMode = zfiWlanQueryAuthenticationMode(dev, 0);
2475 if (AuthMode == ZM_AUTH_MODE_OPEN) {
2476 wrq->u.data.length = 12;
2478 if (copy_to_user(wrq->u.data.pointer,
2479 "open system", 12)) {
2482 } else if (AuthMode == ZM_AUTH_MODE_SHARED_KEY) {
2483 wrq->u.data.length = 11;
2485 if (copy_to_user(wrq->u.data.pointer,
2486 "shared key", 11)) {
2489 } else if (AuthMode == ZM_AUTH_MODE_AUTO) {
2490 wrq->u.data.length = 10;
2492 if (copy_to_user(wrq->u.data.pointer,
2504 if (copy_from_user(&zdreq, ifr->ifr_data, sizeof(zdreq))) {
2505 printk(KERN_ERR "usbdrv : copy_from_user error\n");
2509 /* printk(KERN_WARNING
2510 * "usbdrv : cmd = % 2x, reg = 0x%04lx,
2511 *value = 0x%08lx\n",
2512 * zdreq.cmd, zdreq.addr, zdreq.value);
2514 zfLnxPrivateIoctl(dev, &zdreq);
2519 if (copy_from_user(&zdparm, ifr->ifr_data,
2520 sizeof(struct athr_wlan_param))) {
2521 printk(KERN_ERR "usbdrv : copy_from_user error\n");
2525 usbdrv_wpa_ioctl(dev, &zdparm);
2528 case ZD_IOCTL_PARAM: {
2533 /* Point to the name field and retrieve the
2534 * op and arg elements.
2536 p = (int *)wrq->u.name;
2540 if (op == ZD_PARAM_ROAMING) {
2542 "*************ZD_PARAM_ROAMING : % d\n", arg);
2543 /* macp->cardSetting.ap_scan=(U8)arg; */
2545 if (op == ZD_PARAM_PRIVACY) {
2546 printk(KERN_ERR "ZD_IOCTL_PRIVACY : ");
2548 /* Turn on the privacy invoke flag */
2550 /* mCap[0] |= CAP_PRIVACY; */
2551 /* macp->cardSetting.EncryOnOff[0] = 1; */
2552 printk(KERN_ERR "enable\n");
2555 /* mCap[0] &= ~CAP_PRIVACY; */
2556 /* macp->cardSetting.EncryOnOff[0] = 0; */
2557 printk(KERN_ERR "disable\n");
2561 if (op == ZD_PARAM_WPA) {
2563 printk(KERN_ERR "ZD_PARAM_WPA : ");
2566 printk(KERN_ERR "enable\n");
2568 if (zfiWlanQueryWlanMode(dev) != ZM_MODE_AP) {
2569 printk(KERN_ERR "Station Mode\n");
2570 /* zfiWlanQueryWpaIe(dev, (u8_t *)
2571 &wpaIe, &wpalen); */
2572 /* printk("wpaIe : % 2x, % 2x, % 2x\n",
2573 wpaIe[21], wpaIe[22], wpaIe[23]); */
2574 /* printk("rsnIe : % 2x, % 2x, % 2x\n",
2575 wpaIe[17], wpaIe[18], wpaIe[19]); */
2576 if ((macp->supIe[21] == 0x50) &&
2577 (macp->supIe[22] == 0xf2) &&
2578 (macp->supIe[23] == 0x2)) {
2580 "wd->sta.authMode = ZM_AUTH_MODE_WPAPSK\n");
2581 /* wd->sta.authMode = ZM_AUTH_MODE_WPAPSK; */
2582 /* wd->ws.authMode = ZM_AUTH_MODE_WPAPSK; */
2583 zfiWlanSetAuthenticationMode(dev,
2584 ZM_AUTH_MODE_WPAPSK);
2585 } else if ((macp->supIe[21] == 0x50) &&
2586 (macp->supIe[22] == 0xf2) &&
2587 (macp->supIe[23] == 0x1)) {
2589 "wd->sta.authMode = ZM_AUTH_MODE_WPA\n");
2590 /* wd->sta.authMode = ZM_AUTH_MODE_WPA; */
2591 /* wd->ws.authMode = ZM_AUTH_MODE_WPA; */
2592 zfiWlanSetAuthenticationMode(dev,
2594 } else if ((macp->supIe[17] == 0xf) &&
2595 (macp->supIe[18] == 0xac) &&
2596 (macp->supIe[19] == 0x2))
2599 "wd->sta.authMode = ZM_AUTH_MODE_WPA2PSK\n");
2600 /* wd->sta.authMode = ZM_AUTH_MODE_WPA2PSK; */
2601 /* wd->ws.authMode = ZM_AUTH_MODE_WPA2PSK; */
2602 zfiWlanSetAuthenticationMode(dev,
2603 ZM_AUTH_MODE_WPA2PSK);
2604 } else if ((macp->supIe[17] == 0xf) &&
2605 (macp->supIe[18] == 0xac) &&
2606 (macp->supIe[19] == 0x1))
2609 "wd->sta.authMode = ZM_AUTH_MODE_WPA2\n");
2610 /* wd->sta.authMode = ZM_AUTH_MODE_WPA2; */
2611 /* wd->ws.authMode = ZM_AUTH_MODE_WPA2; */
2612 zfiWlanSetAuthenticationMode(dev,
2616 if ((macp->supIe[21] == 0x50) ||
2617 (macp->supIe[22] == 0xf2)) {
2618 if (macp->supIe[11] == 0x2) {
2620 "wd->sta.wepStatus = ZM_ENCRYPTION_TKIP\n");
2621 /* wd->sta.wepStatus = ZM_ENCRYPTION_TKIP; */
2622 /* wd->ws.wepStatus = ZM_ENCRYPTION_TKIP; */
2623 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_TKIP);
2626 "wd->sta.wepStatus = ZM_ENCRYPTION_AES\n");
2627 /* wd->sta.wepStatus = ZM_ENCRYPTION_AES; */
2628 /* wd->ws.wepStatus = ZM_ENCRYPTION_AES; */
2629 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_AES);
2633 if ((macp->supIe[17] == 0xf) ||
2634 (macp->supIe[18] == 0xac)) {
2635 if (macp->supIe[13] == 0x2) {
2637 "wd->sta.wepStatus = ZM_ENCRYPTION_TKIP\n");
2638 /* wd->sta.wepStatus = ZM_ENCRYPTION_TKIP; */
2639 /* wd->ws.wepStatus = ZM_ENCRYPTION_TKIP; */
2640 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_TKIP);
2643 "wd->sta.wepStatus = ZM_ENCRYPTION_AES\n");
2644 /* wd->sta.wepStatus = ZM_ENCRYPTION_AES; */
2645 /* wd->ws.wepStatus = ZM_ENCRYPTION_AES; */
2646 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_AES);
2650 zfiWlanSetWpaSupport(dev, 1);
2652 /* Reset the WPA related variables */
2653 printk(KERN_ERR "disable\n");
2655 zfiWlanSetWpaSupport(dev, 0);
2656 zfiWlanSetAuthenticationMode(dev, ZM_AUTH_MODE_OPEN);
2657 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_WEP_DISABLED);
2659 /* Now we only set the length in the WPA IE
2661 *macp->cardSetting.WPAIe[1] = 0;
2666 if (op == ZD_PARAM_COUNTERMEASURES) {
2668 "****************ZD_PARAM_COUNTERMEASURES : ");
2671 /* mCounterMeasureState=1; */
2672 printk(KERN_ERR "enable\n");
2674 /* mCounterMeasureState=0; */
2675 printk(KERN_ERR "disable\n");
2678 if (op == ZD_PARAM_DROPUNENCRYPTED) {
2679 printk(KERN_ERR "ZD_PARAM_DROPUNENCRYPTED : ");
2682 printk(KERN_ERR "enable\n");
2684 printk(KERN_ERR "disable\n");
2687 if (op == ZD_PARAM_AUTH_ALGS) {
2688 printk(KERN_ERR "ZD_PARAM_AUTH_ALGS : ");
2691 printk(KERN_ERR "OPEN_SYSTEM\n");
2693 printk(KERN_ERR "SHARED_KEY\n");
2696 if (op == ZD_PARAM_WPS_FILTER) {
2697 printk(KERN_ERR "ZD_PARAM_WPS_FILTER : ");
2700 /* mCounterMeasureState=1; */
2701 macp->forwardMgmt = 1;
2702 printk(KERN_ERR "enable\n");
2704 /* mCounterMeasureState=0; */
2705 macp->forwardMgmt = 0;
2706 printk(KERN_ERR "disable\n");
2712 case ZD_IOCTL_GETWPAIE: {
2713 struct ieee80211req_wpaie req_wpaie;
2717 apId = zfLnxGetVapId(dev);
2719 if (apId == 0xffff) {
2725 if (copy_from_user(&req_wpaie, ifr->ifr_data,
2726 sizeof(struct ieee80211req_wpaie))) {
2727 printk(KERN_ERR "usbdrv : copy_from_user error\n");
2731 for (i = 0; i < ZM_OAL_MAX_STA_SUPPORT; i++) {
2732 for (j = 0; j < IEEE80211_ADDR_LEN; j++) {
2733 if (macp->stawpaie[i].wpa_macaddr[j] !=
2734 req_wpaie.wpa_macaddr[j])
2741 if (i < ZM_OAL_MAX_STA_SUPPORT) {
2742 /* printk("ZD_IOCTL_GETWPAIE - sta index = % d\n", i); */
2743 memcpy(req_wpaie.wpa_ie, macp->stawpaie[i].wpa_ie,
2744 IEEE80211_MAX_IE_SIZE);
2747 if (copy_to_user(wrq->u.data.pointer, &req_wpaie,
2748 sizeof(struct ieee80211req_wpaie))) {
2755 #ifdef ZM_ENABLE_CENC
2757 if (copy_from_user(&macp->zd_wpa_req, ifr->ifr_data,
2758 sizeof(struct athr_wlan_param))) {
2759 printk(KERN_ERR "usbdrv : copy_from_user error\n");
2763 usbdrv_cenc_ioctl(dev,
2764 (struct zydas_cenc_param *)&macp->zd_wpa_req);
2767 #endif /* ZM_ENABLE_CENC */