ASoC: Remove duplicate ADC/DAC widgets from wm_hubs.c
[linux/fpc-iii.git] / drivers / staging / otus / ioctl.c
blobce04218253dd63cf37b81c449d628ddaf99c17d1
1 /*
2 * Copyright (c) 2007-2008 Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 /* */
17 /* Module Name : ioctl.c */
18 /* */
19 /* Abstract */
20 /* This module contains Linux wireless extension related functons. */
21 /* */
22 /* NOTES */
23 /* Platform dependent. */
24 /* */
25 /************************************************************************/
26 #include <linux/module.h>
27 #include <linux/if_arp.h>
28 #include <linux/uaccess.h>
30 #include "usbdrv.h"
32 #define ZD_IOCTL_WPA (SIOCDEVPRIVATE + 1)
33 #define ZD_IOCTL_PARAM (SIOCDEVPRIVATE + 2)
34 #define ZD_IOCTL_GETWPAIE (SIOCDEVPRIVATE + 3)
35 #ifdef ZM_ENABLE_CENC
36 #define ZM_IOCTL_CENC (SIOCDEVPRIVATE + 4)
37 #endif /* ZM_ENABLE_CENC */
38 #define ZD_PARAM_ROAMING 0x0001
39 #define ZD_PARAM_PRIVACY 0x0002
40 #define ZD_PARAM_WPA 0x0003
41 #define ZD_PARAM_COUNTERMEASURES 0x0004
42 #define ZD_PARAM_DROPUNENCRYPTED 0x0005
43 #define ZD_PARAM_AUTH_ALGS 0x0006
44 #define ZD_PARAM_WPS_FILTER 0x0007
46 #ifdef ZM_ENABLE_CENC
47 #define P80211_PACKET_CENCFLAG 0x0001
48 #endif /* ZM_ENABLE_CENC */
49 #define P80211_PACKET_SETKEY 0x0003
51 #define ZD_CMD_SET_ENCRYPT_KEY 0x0001
52 #define ZD_CMD_SET_MLME 0x0002
53 #define ZD_CMD_SCAN_REQ 0x0003
54 #define ZD_CMD_SET_GENERIC_ELEMENT 0x0004
55 #define ZD_CMD_GET_TSC 0x0005
57 #define ZD_CRYPT_ALG_NAME_LEN 16
58 #define ZD_MAX_KEY_SIZE 32
59 #define ZD_MAX_GENERIC_SIZE 64
61 #if WIRELESS_EXT > 12
62 #include <net/iw_handler.h>
63 #endif
65 extern u16_t zfLnxGetVapId(zdev_t *dev);
67 static const u32_t channel_frequency_11A[] =
69 /* Even element for Channel Number, Odd for Frequency */
70 36, 5180,
71 40, 5200,
72 44, 5220,
73 48, 5240,
74 52, 5260,
75 56, 5280,
76 60, 5300,
77 64, 5320,
78 100, 5500,
79 104, 5520,
80 108, 5540,
81 112, 5560,
82 116, 5580,
83 120, 5600,
84 124, 5620,
85 128, 5640,
86 132, 5660,
87 136, 5680,
88 140, 5700,
89 /**/
90 184, 4920,
91 188, 4940,
92 192, 4960,
93 196, 4980,
94 8, 5040,
95 12, 5060,
96 16, 5080,
97 34, 5170,
98 38, 5190,
99 42, 5210,
100 46, 5230,
101 /**/
102 149, 5745,
103 153, 5765,
104 157, 5785,
105 161, 5805,
106 165, 5825
107 /**/
110 int usbdrv_freq2chan(u32_t freq)
112 /* 2.4G Hz */
113 if (freq > 2400 && freq < 3000) {
114 return ((freq-2412)/5) + 1;
115 } else {
116 u16_t ii;
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];
125 return 0;
128 int usbdrv_chan2freq(int chan)
130 int freq;
132 /* If channel number is out of range */
133 if (chan > 165 || chan <= 0)
134 return -1;
136 /* 2.4G band */
137 if (chan >= 1 && chan <= 13) {
138 freq = (2412 + (chan - 1) * 5);
139 return freq;
140 } else if (chan >= 36 && chan <= 165) {
141 u16_t ii;
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 */
150 if (ii == num_chan)
151 return -1;
154 /* Can't find deisred frequency */
155 return -1;
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];
163 int i;
165 if (!netif_running(dev))
166 return -EINVAL;
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. */
173 if (erq->flags) {
174 if (erq->length > (IW_ESSID_MAX_SIZE+1))
175 return -E2BIG;
177 if (copy_from_user(essidbuf, erq->pointer, erq->length))
178 return -EFAULT;
181 /* zd_DisasocAll(2); */
182 /* wait_ms(100); */
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);
197 #if 0
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");
204 #endif
206 zfiWlanDisable(dev, 0);
207 zfiWlanEnable(dev);
209 #endif
211 return 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];
218 u8_t len;
219 u8_t i;
222 /* len = macp->wd.ws.ssidLen; */
223 /* memcpy(essidbuf, macp->wd.ws.ssid, macp->wd.ws.ssidLen); */
224 zfiWlanQuerySSID(dev, essidbuf, &len);
226 essidbuf[len] = 0;
228 printk(KERN_ERR "ESSID: ");
230 for (i = 0; i < len; i++)
231 printk(KERN_ERR "%c", essidbuf[i]);
233 printk(KERN_ERR "\n");
235 erq->flags = 1;
236 erq->length = strlen(essidbuf) + 1;
238 if (erq->pointer) {
239 if (copy_to_user(erq->pointer, essidbuf, erq->length))
240 return -EFAULT;
243 return 0;
246 int usbdrv_ioctl_setrts(struct net_device *dev, struct iw_param *rrq)
248 return 0;
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)
259 u8 *p;
260 u32 i;
262 if (bufsize < leader_len)
263 return 0;
264 p = buf;
265 memcpy(p, leader, leader_len);
266 bufsize -= leader_len;
267 p += 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 */
283 u16_t capabilities;
284 char *current_val; /* For rates */
285 char *last_ev;
286 int i;
287 #if WIRELESS_EXT > 14
288 char buf[64*2 + 30];
289 #endif
291 last_ev = current_ev;
293 /* First entry *MUST* be the AP MAC address */
294 iwe.cmd = SIOCGIWAP;
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)
302 return end_buf;
304 last_ev = current_ev;
306 /* Other entries will be displayed in the order we give them */
308 /* Add the ESSID */
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)
319 return end_buf;
321 last_ev = current_ev;
323 /* Add mode */
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;
329 else
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)
337 return end_buf;
339 last_ev = current_ev;
341 /* Add frequency */
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;
348 else
349 iwe.u.freq.m = 5000 + iwe.u.freq.m * 5;
350 } else {
351 if (iwe.u.freq.m == 14)
352 iwe.u.freq.m = 2484;
353 else
354 iwe.u.freq.m = 2412 + (iwe.u.freq.m - 1) * 5;
356 iwe.u.freq.e = 6;
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)
362 return end_buf;
364 last_ev = current_ev;
366 /* Add quality statistics */
367 iwe.cmd = IWEVQUAL;
368 #if WIRELESS_EXT > 18
369 iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED
370 | IW_QUAL_NOISE_UPDATED;
371 #endif
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)
380 return end_buf;
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;
389 else
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)
398 return end_buf;
400 last_ev = current_ev;
402 /* Rate : stuffing multiple values in a single event require a bit
403 * more of magic
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)
414 * 500000);
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)
421 return end_buf;
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)
429 * 500000);
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)
436 return end_buf;
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,
452 end_buf, &iwe, buf);
454 /* Ran out of buffer */
455 if (last_ev == current_ev)
456 return end_buf;
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);
470 else
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,
477 end_buf, &iwe, buf);
479 /* Ran out of buffer */
480 if (last_ev == current_ev)
481 return end_buf;
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)
501 return end_buf;
503 last_ev = current_ev;
506 #endif
507 /* The other data in the scan result are not really
508 * interesting, so for now drop it
510 return current_ev;
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");
521 return 0;
524 int usbdrvwext_siwfreq(struct net_device *dev,
525 struct iw_request_info *info,
526 struct iw_freq *freq, char *extra)
528 u32_t FreqKHz;
529 struct usbdrv_private *macp = dev->ml_priv;
531 if (!netif_running(dev))
532 return -EINVAL;
534 if (freq->e > 1)
535 return -EINVAL;
537 if (freq->e == 1) {
538 FreqKHz = (freq->m / 100000);
540 if (FreqKHz > 4000000) {
541 if (FreqKHz > 5825000)
542 FreqKHz = 5825000;
543 else if (FreqKHz < 4920000)
544 FreqKHz = 4920000;
545 else if (FreqKHz < 5000000)
546 FreqKHz = (((FreqKHz - 4000000) / 5000) * 5000)
547 + 4000000;
548 else
549 FreqKHz = (((FreqKHz - 5000000) / 5000) * 5000)
550 + 5000000;
551 } else {
552 if (FreqKHz > 2484000)
553 FreqKHz = 2484000;
554 else if (FreqKHz < 2412000)
555 FreqKHz = 2412000;
556 else
557 FreqKHz = (((FreqKHz - 2412000) / 5000) * 5000)
558 + 2412000;
560 } else {
561 FreqKHz = usbdrv_chan2freq(freq->m);
563 if (FreqKHz != -1)
564 FreqKHz *= 1000;
565 else
566 FreqKHz = 2412000;
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);
577 zfiWlanEnable(dev);
578 /* if (wpaieLen > 2) */
579 /* zfiWlanSetWpaIe(dev, wpaie, wpaieLen); */
582 return 0;
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)
592 return 0;
594 freq->m = zfiWlanQueryFrequency(dev);
595 freq->e = 3;
597 return 0;
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;
605 u8_t WlanMode;
607 if (!netif_running(dev))
608 return -EINVAL;
610 if (macp->DeviceOpened != 1)
611 return 0;
613 switch (wrq->mode) {
614 case IW_MODE_MASTER:
615 WlanMode = ZM_MODE_AP;
616 break;
617 case IW_MODE_INFRA:
618 WlanMode = ZM_MODE_INFRASTRUCTURE;
619 break;
620 case IW_MODE_ADHOC:
621 WlanMode = ZM_MODE_IBSS;
622 break;
623 default:
624 WlanMode = ZM_MODE_IBSS;
625 break;
628 zfiWlanSetWlanMode(dev, WlanMode);
629 zfiWlanDisable(dev, 1);
630 zfiWlanEnable(dev);
632 return 0;
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))
643 return -EINVAL;
645 if (macp->DeviceOpened != 1)
646 return 0;
648 spin_lock_irqsave(&macp->cs_lock, irqFlag);
650 switch (zfiWlanQueryWlanMode(dev)) {
651 case ZM_MODE_AP:
652 *mode = IW_MODE_MASTER;
653 break;
654 case ZM_MODE_INFRASTRUCTURE:
655 *mode = IW_MODE_INFRA;
656 break;
657 case ZM_MODE_IBSS:
658 *mode = IW_MODE_ADHOC;
659 break;
660 default:
661 *mode = IW_MODE_ADHOC;
662 break;
665 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
667 return 0;
670 int usbdrvwext_siwsens(struct net_device *dev,
671 struct iw_request_info *info,
672 struct iw_param *sens, char *extra)
674 return 0;
677 int usbdrvwext_giwsens(struct net_device *dev,
678 struct iw_request_info *info,
679 struct iw_param *sens, char *extra)
681 sens->value = 0;
682 sens->fixed = 1;
684 return 0;
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;
692 int i, val;
693 /* int num_band_a; */
694 u16_t channels[60];
695 u16_t channel_num;
697 if (!netif_running(dev))
698 return -EINVAL;
700 #if WIRELESS_EXT > 9
701 range->txpower_capa = IW_TXPOW_DBM;
702 /* XXX what about min/max_pmp, min/max_pmt, etc. */
703 #endif
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;
723 val = 0;
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;
729 val++;
732 range->num_channels = channel_num;
733 range->num_frequency = channel_num;
735 #if 0
736 range->num_channels = 14; /* Only 2.4G */
738 /* XXX need to filter against the regulatory domain &| active set */
739 val = 0;
740 /* B,G Bands */
741 for (i = 1; i <= 14; i++) {
742 range->freq[val].i = i;
743 if (i == 14)
744 range->freq[val].m = 2484000;
745 else
746 range->freq[val].m = (2412+(i-1)*5)*1000;
747 range->freq[val].e = 3;
748 val++;
751 num_band_a = (IW_MAX_FREQUENCIES - val);
752 /* A Bands */
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;
757 val++;
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;
764 #endif
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! */
773 range->min_rts = 0;
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;
792 return 0;
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))
801 return -EINVAL;
803 if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) {
804 /* AP Mode */
805 zfiWlanSetMacAddress(dev, (u16_t *)&MacAddr->sa_data[0]);
806 } else {
807 /* STA Mode */
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);
815 zfiWlanEnable(dev);
816 /* if (wpaieLen > 2) */
817 /* zfiWlanSetWpaIe(dev, wpaie, wpaieLen); */
820 return 0;
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)
830 return 0;
832 if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) {
833 /* AP Mode */
834 zfiWlanQueryMacAddress(dev, &MacAddr->sa_data[0]);
835 } else {
836 /* STA Mode */
837 if (macp->adapterState == ZM_STATUS_MEDIA_CONNECT) {
838 zfiWlanQueryBssid(dev, &MacAddr->sa_data[0]);
839 } else {
840 u8_t zero_addr[6] = { 0x00, 0x00, 0x00, 0x00,
841 0x00, 0x00 };
842 memcpy(&MacAddr->sa_data[0], zero_addr,
843 sizeof(zero_addr));
847 return 0;
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(+) */
855 return 0;
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)
865 return 0;
867 printk(KERN_WARNING "CWY - usbdrvwext_siwscan\n");
869 zfiWlanScan(dev);
871 return 0;
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;
881 char *end_buf;
882 int i;
883 /* struct zsBssList BssList; */
884 struct zsBssListV1 *pBssList = kmalloc(sizeof(struct zsBssListV1),
885 GFP_KERNEL);
886 /* BssList = wd->sta.pBssList; */
887 /* zmw_get_wlan_dev(dev); */
889 if (macp->DeviceOpened != 1)
890 return 0;
892 if (data->length == 0)
893 end_buf = extra + IW_SCAN_MAX_DATA;
894 else
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",
909 pBssList->bssCount);
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) {
922 kfree(pBssList);
923 data->length = current_ev - extra;
924 return -E2BIG;
926 #endif
929 /* Length of data */
930 data->length = (current_ev - extra);
931 data->flags = 0; /* todo */
933 kfree(pBssList);
935 return 0;
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))
946 return -EINVAL;
948 if (essid->flags == 1) {
949 if (essid->length > (IW_ESSID_MAX_SIZE + 1))
950 return -E2BIG;
952 if (copy_from_user(&EssidBuf, essid->pointer, essid->length))
953 return -EFAULT;
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),
962 FALSE);
963 zfiWlanSetEncryMode(dev, zfiWlanQueryEncryMode(dev));
964 /* u8_t wpaieLen,wpaie[50]; */
965 /* zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen); */
966 zfiWlanDisable(dev, 0);
967 zfiWlanEnable(dev);
968 /* if (wpaieLen > 2) */
969 /* zfiWlanSetWpaIe(dev, wpaie, wpaieLen); */
973 return 0;
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;
981 u8_t EssidLen;
982 char EssidBuf[IW_ESSID_MAX_SIZE + 1];
983 int ssid_len;
985 if (!netif_running(dev))
986 return -EINVAL;
988 if (macp->DeviceOpened != 1)
989 return 0;
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';
1002 essid->flags = 1;
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");
1010 * return -EFAULT;
1015 return 0;
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(+) */
1023 return 0;
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;
1031 u8_t EssidLen;
1032 char EssidBuf[IW_ESSID_MAX_SIZE + 1];
1034 if (macp->DeviceOpened != 1)
1035 return 0;
1037 zfiWlanQuerySSID(dev, &EssidBuf[0], &EssidLen);
1038 EssidBuf[EssidLen] = 0;
1040 data->flags = 1;
1041 data->length = strlen(EssidBuf);
1043 memcpy(nickname, EssidBuf, data->length);
1045 return 0;
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,
1057 0x8, 0xc};
1058 u8_t i, RateIndex = 4;
1059 u16_t RateKbps;
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])
1068 RateIndex = i;
1071 if (zcIndextoRateBG[RateIndex] == 0)
1072 RateIndex = 0xff;
1073 /* printk("RateIndex : %x\n", RateIndex); */
1074 for (i = 0; i < 13; i++)
1075 if (RateIndex == zcRateToMCS[i])
1076 break;
1077 /* printk("Index : %x\n", i); */
1078 if (RateKbps == 65000) {
1079 RateIndex = 20;
1080 printk(KERN_WARNING "RateIndex : %d\n", RateIndex);
1083 if (macp->DeviceOpened == 1) {
1084 zfiWlanSetTxRate(dev, i);
1085 /* zfiWlanDisable(dev); */
1086 /* zfiWlanEnable(dev); */
1089 return 0;
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))
1099 return -EINVAL;
1101 if (macp->DeviceOpened != 1)
1102 return 0;
1104 frq->fixed = 0;
1105 frq->disabled = 0;
1106 frq->value = zfiWlanQueryRxRate(dev) * 1000;
1108 return 0;
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)
1119 return 0;
1121 if (rts->disabled)
1122 val = 2347;
1124 if ((val < 0) || (val > 2347))
1125 return -EINVAL;
1127 zfiWlanSetRtsThreshold(dev, val);
1129 return 0;
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))
1139 return -EINVAL;
1141 if (macp->DeviceOpened != 1)
1142 return 0;
1144 rts->value = zfiWlanQueryRtsThreshold(dev);
1145 rts->disabled = (rts->value >= 2347);
1146 rts->fixed = 1;
1148 return 0;
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)
1159 return 0;
1161 if (frag->disabled)
1162 fragThreshold = 0;
1163 else
1164 fragThreshold = frag->value;
1166 zfiWlanSetFragThreshold(dev, fragThreshold);
1168 return 0;
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;
1176 u16 val;
1177 unsigned long irqFlag;
1179 if (!netif_running(dev))
1180 return -EINVAL;
1182 if (macp->DeviceOpened != 1)
1183 return 0;
1185 spin_lock_irqsave(&macp->cs_lock, irqFlag);
1187 val = zfiWlanQueryFragThreshold(dev);
1189 frag->value = val;
1191 frag->disabled = (val >= 2346);
1192 frag->fixed = 1;
1194 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
1196 return 0;
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(+) */
1204 return 0;
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(+) */
1212 return 0;
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(+) */
1220 return 0;
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(+) */
1228 return 0;
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;
1236 int i;
1237 int WepState = ZM_ENCRYPTION_WEP_DISABLED;
1238 struct usbdrv_private *macp = dev->ml_priv;
1240 if (!netif_running(dev))
1241 return -EINVAL;
1243 if ((erq->flags & IW_ENCODE_DISABLED) == 0) {
1244 keyInfo.key = key;
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;
1253 } else {
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);
1267 zfiWlanEnable(dev);
1268 /* if (wpaieLen > 2) */
1269 /* zfiWlanSetWpaIe(dev, wpaie, wpaieLen); */
1272 return 0;
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;
1281 u8_t keyLen = 0;
1283 if (macp->DeviceOpened != 1)
1284 return 0;
1286 EncryptionMode = zfiWlanQueryEncryMode(dev);
1288 if (EncryptionMode)
1289 erq->flags = IW_ENCODE_ENABLED;
1290 else
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;
1295 memset(key, 0, 16);
1297 /* Copy the key to the user buffer */
1298 switch (EncryptionMode) {
1299 case ZM_WEP64:
1300 keyLen = 5;
1301 break;
1302 case ZM_WEP128:
1303 keyLen = 13;
1304 break;
1305 case ZM_WEP256:
1306 keyLen = 29;
1307 break;
1308 case ZM_AES:
1309 keyLen = 16;
1310 break;
1311 case ZM_TKIP:
1312 keyLen = 32;
1313 break;
1314 #ifdef ZM_ENABLE_CENC
1315 case ZM_CENC:
1316 /* ZM_ENABLE_CENC */
1317 keyLen = 32;
1318 break;
1319 #endif
1320 case ZM_NO_WEP:
1321 keyLen = 0;
1322 break;
1323 default:
1324 keyLen = 0;
1325 printk(KERN_ERR "Unknown EncryMode\n");
1326 break;
1328 erq->length = keyLen;
1330 return 0;
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;
1338 u8_t PSMode;
1340 if (macp->DeviceOpened != 1)
1341 return 0;
1343 if (frq->disabled)
1344 PSMode = ZM_STA_PS_NONE;
1345 else
1346 PSMode = ZM_STA_PS_MAX;
1348 zfiWlanSetPowerSaveMode(dev, PSMode);
1350 return 0;
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)
1361 return 0;
1363 spin_lock_irqsave(&macp->cs_lock, irqFlag);
1365 if (zfiWlanQueryPowerSaveMode(dev) == ZM_STA_PS_NONE)
1366 frq->disabled = 1;
1367 else
1368 frq->disabled = 0;
1370 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
1372 return 0;
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
1384 * int retv = 0;
1385 * int j, caps;
1386 * const struct ieee80211_authenticator *auth;
1387 * const struct ieee80211_aclator *acl;
1389 * switch (param) {
1390 * case IEEE80211_PARAM_AUTHMODE:
1391 * switch (value) {
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);
1398 * if (auth == NULL)
1399 * return -EINVAL;
1400 * break;
1401 * default:
1402 * return -EINVAL;
1404 * switch (value) {
1405 * case IEEE80211_AUTH_WPA: // WPA w/ 802.1x
1406 * vap->iv_flags |= IEEE80211_F_PRIVACY;
1407 * value = IEEE80211_AUTH_8021X;
1408 * break;
1409 * case IEEE80211_AUTH_OPEN: // open
1410 * vap->iv_flags &= ~(IEEE80211_F_WPA | IEEE80211_F_PRIVACY);
1411 * break;
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;
1418 * break;
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;
1424 * retv = ENETRESET;
1425 * break;
1426 * case IEEE80211_PARAM_PROTMODE:
1427 * if (value > IEEE80211_PROT_RTSCTS)
1428 * return -EINVAL;
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))
1433 * retv = ENETRESET;
1434 * break;
1435 * case IEEE80211_PARAM_MCASTCIPHER:
1436 * if ((vap->iv_caps & cipher2cap(value)) == 0 &&
1437 * !ieee80211_crypto_available(value))
1438 * return -EINVAL;
1439 * rsn->rsn_mcastcipher = value;
1440 * if (vap->iv_flags & IEEE80211_F_WPA)
1441 * retv = ENETRESET;
1442 * break;
1443 * case IEEE80211_PARAM_MCASTKEYLEN:
1444 * if (!(0 < value && value < IEEE80211_KEYBUF_SIZE))
1445 * return -EINVAL;
1446 * // XXX no way to verify driver capability
1447 * rsn->rsn_mcastkeylen = value;
1448 * if (vap->iv_flags & IEEE80211_F_WPA)
1449 * retv = ENETRESET;
1450 * break;
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.
1458 * caps = 0;
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)))
1463 * caps |= 1<<j;
1464 * if (caps == 0) // nothing available
1465 * return -EINVAL;
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)
1470 * retv = ENETRESET;
1471 * break;
1472 * case IEEE80211_PARAM_UCASTCIPHER:
1473 * if ((rsn->rsn_ucastcipherset & cipher2cap(value)) == 0)
1474 * return -EINVAL;
1475 * rsn->rsn_ucastcipher = value;
1476 * break;
1477 * case IEEE80211_PARAM_UCASTKEYLEN:
1478 * if (!(0 < value && value < IEEE80211_KEYBUF_SIZE))
1479 * return -EINVAL;
1480 * // XXX no way to verify driver capability
1481 * rsn->rsn_ucastkeylen = value;
1482 * break;
1483 * case IEEE80211_PARAM_KEYMGTALGS:
1484 * // XXX check
1485 * rsn->rsn_keymgmtset = value;
1486 * if (vap->iv_flags & IEEE80211_F_WPA)
1487 * retv = ENETRESET;
1488 * break;
1489 * case IEEE80211_PARAM_RSNCAPS:
1490 * // XXX check
1491 * rsn->rsn_caps = value;
1492 * if (vap->iv_flags & IEEE80211_F_WPA)
1493 * retv = ENETRESET;
1494 * break;
1495 * case IEEE80211_PARAM_WPA:
1496 * if (value > 3)
1497 * return -EINVAL;
1498 * // XXX verify ciphers available
1499 * vap->iv_flags &= ~IEEE80211_F_WPA;
1500 * switch (value) {
1501 * case 1:
1502 * vap->iv_flags |= IEEE80211_F_WPA1;
1503 * break;
1504 * case 2:
1505 * vap->iv_flags |= IEEE80211_F_WPA2;
1506 * break;
1507 * case 3:
1508 * vap->iv_flags |= IEEE80211_F_WPA1 | IEEE80211_F_WPA2;
1509 * break;
1511 * retv = ENETRESET; // XXX?
1512 * break;
1513 * case IEEE80211_PARAM_ROAMING:
1514 * if (!(IEEE80211_ROAMING_DEVICE <= value &&
1515 * value <= IEEE80211_ROAMING_MANUAL))
1516 * return -EINVAL;
1517 * ic->ic_roaming = value;
1518 * break;
1519 * case IEEE80211_PARAM_PRIVACY:
1520 * if (value) {
1521 * // XXX check for key state?
1522 * vap->iv_flags |= IEEE80211_F_PRIVACY;
1523 * } else
1524 * vap->iv_flags &= ~IEEE80211_F_PRIVACY;
1525 * break;
1526 * case IEEE80211_PARAM_DROPUNENCRYPTED:
1527 * if (value)
1528 * vap->iv_flags |= IEEE80211_F_DROPUNENC;
1529 * else
1530 * vap->iv_flags &= ~IEEE80211_F_DROPUNENC;
1531 * break;
1532 * case IEEE80211_PARAM_COUNTERMEASURES:
1533 * if (value) {
1534 * if ((vap->iv_flags & IEEE80211_F_WPA) == 0)
1535 * return -EINVAL;
1536 * vap->iv_flags |= IEEE80211_F_COUNTERM;
1537 * } else
1538 * vap->iv_flags &= ~IEEE80211_F_COUNTERM;
1539 * break;
1540 * case IEEE80211_PARAM_DRIVER_CAPS:
1541 * vap->iv_caps = value; // NB: for testing
1542 * break;
1543 * case IEEE80211_PARAM_MACCMD:
1544 * acl = vap->iv_acl;
1545 * switch (value) {
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))
1552 * return -EINVAL;
1553 * vap->iv_acl = acl;
1555 * acl->iac_setpolicy(vap, value);
1556 * break;
1557 * case IEEE80211_MACCMD_FLUSH:
1558 * if (acl != NULL)
1559 * acl->iac_flush(vap);
1560 * // NB: silently ignore when not in use
1561 * break;
1562 * case IEEE80211_MACCMD_DETACH:
1563 * if (acl != NULL) {
1564 * vap->iv_acl = NULL;
1565 * acl->iac_detach(vap);
1567 * break;
1569 * break;
1570 * case IEEE80211_PARAM_WMM:
1571 * if (ic->ic_caps & IEEE80211_C_WME){
1572 * if (value) {
1573 * vap->iv_flags |= IEEE80211_F_WME;
1574 * *//* XXX needed by ic_reset *//*
1575 * vap->iv_ic->ic_flags |= IEEE80211_F_WME;
1577 * else {
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
1584 * break;
1585 * case IEEE80211_PARAM_HIDESSID:
1586 * if (value)
1587 * vap->iv_flags |= IEEE80211_F_HIDESSID;
1588 * else
1589 * vap->iv_flags &= ~IEEE80211_F_HIDESSID;
1590 * retv = ENETRESET;
1591 * break;
1592 * case IEEE80211_PARAM_APBRIDGE:
1593 * if (value == 0)
1594 * vap->iv_flags |= IEEE80211_F_NOBRIDGE;
1595 * else
1596 * vap->iv_flags &= ~IEEE80211_F_NOBRIDGE;
1597 * break;
1598 * case IEEE80211_PARAM_INACT:
1599 * vap->iv_inact_run = value / IEEE80211_INACT_WAIT;
1600 * break;
1601 * case IEEE80211_PARAM_INACT_AUTH:
1602 * vap->iv_inact_auth = value / IEEE80211_INACT_WAIT;
1603 * break;
1604 * case IEEE80211_PARAM_INACT_INIT:
1605 * vap->iv_inact_init = value / IEEE80211_INACT_WAIT;
1606 * break;
1607 * case IEEE80211_PARAM_ABOLT:
1608 * caps = 0;
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)
1629 * return -EINVAL;
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))
1634 * return -EINVAL;
1635 * ieee80211_scan_flush(ic);
1637 * vap->iv_ath_cap = caps;
1638 * ic->ic_athcapsetup(vap->iv_ic, vap->iv_ath_cap);
1639 * retv = ENETRESET;
1641 * break;
1642 * case IEEE80211_PARAM_DTIM_PERIOD:
1643 * if (vap->iv_opmode != IEEE80211_M_HOSTAP &&
1644 * vap->iv_opmode != IEEE80211_M_IBSS)
1645 * return -EINVAL;
1646 * if (IEEE80211_DTIM_MIN <= value &&
1647 * value <= IEEE80211_DTIM_MAX) {
1648 * vap->iv_dtim_period = value;
1649 * retv = ENETRESET; // requires restart
1650 * } else
1651 * retv = EINVAL;
1652 * break;
1653 * case IEEE80211_PARAM_BEACON_INTERVAL:
1654 * if (vap->iv_opmode != IEEE80211_M_HOSTAP &&
1655 * vap->iv_opmode != IEEE80211_M_IBSS)
1656 * return -EINVAL;
1657 * if (IEEE80211_BINTVAL_MIN <= value &&
1658 * value <= IEEE80211_BINTVAL_MAX) {
1659 * ic->ic_lintval = value; // XXX multi-bss
1660 * retv = ENETRESET; // requires restart
1661 * } else
1662 * retv = EINVAL;
1663 * break;
1664 * case IEEE80211_PARAM_DOTH:
1665 * if (value) {
1666 * ic->ic_flags |= IEEE80211_F_DOTH;
1668 * else
1669 * ic->ic_flags &= ~IEEE80211_F_DOTH;
1670 * retv = ENETRESET; // XXX: need something this drastic?
1671 * break;
1672 * case IEEE80211_PARAM_PWRTARGET:
1673 * ic->ic_curchanmaxpwr = value;
1674 * break;
1675 * case IEEE80211_PARAM_GENREASSOC:
1676 * IEEE80211_SEND_MGMT(vap->iv_bss,
1677 * IEEE80211_FC0_SUBTYPE_REASSOC_REQ, 0);
1678 * break;
1679 * case IEEE80211_PARAM_COMPRESSION:
1680 * retv = ieee80211_setathcap(vap, IEEE80211_ATHC_COMP, value);
1681 * break;
1682 * case IEEE80211_PARAM_WMM_AGGRMODE:
1683 * retv = ieee80211_setathcap(vap, IEEE80211_ATHC_WME, value);
1684 * break;
1685 * case IEEE80211_PARAM_FF:
1686 * retv = ieee80211_setathcap(vap, IEEE80211_ATHC_FF, value);
1687 * break;
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))
1692 * return -EINVAL;
1693 * ieee80211_scan_flush(ic);
1695 * break;
1696 * case IEEE80211_PARAM_XR:
1697 * retv = ieee80211_setathcap(vap, IEEE80211_ATHC_XR, value);
1698 * break;
1699 * case IEEE80211_PARAM_BURST:
1700 * retv = ieee80211_setathcap(vap, IEEE80211_ATHC_BURST, value);
1701 * break;
1702 * case IEEE80211_PARAM_AR:
1703 * retv = ieee80211_setathcap(vap, IEEE80211_ATHC_AR, value);
1704 * break;
1705 * case IEEE80211_PARAM_PUREG:
1706 * if (value)
1707 * vap->iv_flags |= IEEE80211_F_PUREG;
1708 * else
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))
1713 * retv = ENETRESET;
1714 * break;
1715 * case IEEE80211_PARAM_WDS:
1716 * if (value)
1717 * vap->iv_flags_ext |= IEEE80211_FEXT_WDS;
1718 * else
1719 * vap->iv_flags_ext &= ~IEEE80211_FEXT_WDS;
1720 * break;
1721 * case IEEE80211_PARAM_BGSCAN:
1722 * if (value) {
1723 * if ((vap->iv_caps & IEEE80211_C_BGSCAN) == 0)
1724 * return -EINVAL;
1725 * vap->iv_flags |= IEEE80211_F_BGSCAN;
1726 * } else {
1727 * // XXX racey?
1728 * vap->iv_flags &= ~IEEE80211_F_BGSCAN;
1729 * ieee80211_cancel_scan(vap); // anything current
1731 * break;
1732 * case IEEE80211_PARAM_BGSCAN_IDLE:
1733 * if (value >= IEEE80211_BGSCAN_IDLE_MIN)
1734 * vap->iv_bgscanidle = value*HZ/1000;
1735 * else
1736 * retv = EINVAL;
1737 * break;
1738 * case IEEE80211_PARAM_BGSCAN_INTERVAL:
1739 * if (value >= IEEE80211_BGSCAN_INTVAL_MIN)
1740 * vap->iv_bgscanintvl = value*HZ;
1741 * else
1742 * retv = EINVAL;
1743 * break;
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;
1748 * else
1749 * retv = EINVAL;
1750 * break;
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);
1756 * retv = 0;
1758 * else
1759 * retv = EINVAL;
1760 * break;
1761 * case IEEE80211_PARAM_COUNTRY_IE:
1762 * if (value)
1763 * ic->ic_flags_ext |= IEEE80211_FEXT_COUNTRYIE;
1764 * else
1765 * ic->ic_flags_ext &= ~IEEE80211_FEXT_COUNTRYIE;
1766 * retv = ENETRESET;
1767 * break;
1768 * case IEEE80211_PARAM_REGCLASS:
1769 * if (value)
1770 * ic->ic_flags_ext |= IEEE80211_FEXT_REGCLASS;
1771 * else
1772 * ic->ic_flags_ext &= ~IEEE80211_FEXT_REGCLASS;
1773 * retv = ENETRESET;
1774 * break;
1775 * case IEEE80211_PARAM_SCANVALID:
1776 * vap->iv_scanvalid = value*HZ;
1777 * break;
1778 * case IEEE80211_PARAM_ROAM_RSSI_11A:
1779 * vap->iv_roam.rssi11a = value;
1780 * break;
1781 * case IEEE80211_PARAM_ROAM_RSSI_11B:
1782 * vap->iv_roam.rssi11bOnly = value;
1783 * break;
1784 * case IEEE80211_PARAM_ROAM_RSSI_11G:
1785 * vap->iv_roam.rssi11b = value;
1786 * break;
1787 * case IEEE80211_PARAM_ROAM_RATE_11A:
1788 * vap->iv_roam.rate11a = value;
1789 * break;
1790 * case IEEE80211_PARAM_ROAM_RATE_11B:
1791 * vap->iv_roam.rate11bOnly = value;
1792 * break;
1793 * case IEEE80211_PARAM_ROAM_RATE_11G:
1794 * vap->iv_roam.rate11b = value;
1795 * break;
1796 * case IEEE80211_PARAM_UAPSDINFO:
1797 * if (vap->iv_opmode == IEEE80211_M_HOSTAP) {
1798 * if (ic->ic_caps & IEEE80211_C_UAPSD) {
1799 * if (value)
1800 * IEEE80211_VAP_UAPSD_ENABLE(vap);
1801 * else
1802 * IEEE80211_VAP_UAPSD_DISABLE(vap);
1803 * retv = ENETRESET;
1806 * else if (vap->iv_opmode == IEEE80211_M_STA) {
1807 * vap->iv_uapsdinfo = value;
1808 * IEEE80211_VAP_UAPSD_ENABLE(vap);
1809 * retv = ENETRESET;
1811 * break;
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.
1816 * if (value) {
1817 * // goto sleep
1818 * IEEE80211_VAP_GOTOSLEEP(vap);
1820 * else {
1821 * // wakeup
1822 * IEEE80211_VAP_WAKEUP(vap);
1824 * ieee80211_send_nulldata(ieee80211_ref_node(vap->iv_bss));
1825 * break;
1826 * case IEEE80211_PARAM_QOSNULL:
1827 * // Force a QoS Null for testing.
1828 * ieee80211_send_qosnulldata(vap->iv_bss, value);
1829 * break;
1830 * case IEEE80211_PARAM_PSPOLL:
1831 * // Force a PS-POLL for testing.
1832 * ieee80211_send_pspoll(vap->iv_bss);
1833 * break;
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);
1839 * break;
1840 * case IEEE80211_PARAM_MARKDFS:
1841 * if (value)
1842 * ic->ic_flags_ext |= IEEE80211_FEXT_MARKDFS;
1843 * else
1844 * ic->ic_flags_ext &= ~IEEE80211_FEXT_MARKDFS;
1845 * break;
1846 * case IEEE80211_PARAM_CHANBW:
1847 * switch (value) {
1848 * case 0:
1849 * ic->ic_chanbwflag = 0;
1850 * break;
1851 * case 1:
1852 * ic->ic_chanbwflag = IEEE80211_CHAN_HALF;
1853 * break;
1854 * case 2:
1855 * ic->ic_chanbwflag = IEEE80211_CHAN_QUARTER;
1856 * break;
1857 * default:
1858 * retv = EINVAL;
1859 * break;
1861 * break;
1862 * case IEEE80211_PARAM_SHORTPREAMBLE:
1863 * if (value) {
1864 * ic->ic_caps |= IEEE80211_C_SHPREAMBLE;
1865 * } else {
1866 * ic->ic_caps &= ~IEEE80211_C_SHPREAMBLE;
1868 * retv = ENETRESET;
1869 * break;
1870 * default:
1871 * retv = EOPNOTSUPP;
1872 * break;
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;
1877 * return -retv;
1881 int usbdrvwext_setmode(struct net_device *dev, struct iw_request_info *info,
1882 void *w, char *extra)
1884 return 0;
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;
1892 char mode[8];
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; */
1901 u16_t cmd;
1902 /* u32_t temp; */
1903 u32_t *p;
1904 u32_t i;
1906 cmd = zdreq->cmd;
1907 switch (cmd) {
1908 case ZM_IOCTL_REG_READ:
1909 zfiDbgReadReg(dev, zdreq->addr);
1910 break;
1911 case ZM_IOCTL_REG_WRITE:
1912 zfiDbgWriteReg(dev, zdreq->addr, zdreq->value);
1913 break;
1914 case ZM_IOCTL_MEM_READ:
1915 p = (u32_t *) bus_to_virt(zdreq->addr);
1916 printk(KERN_WARNING
1917 "usbdrv: read memory addr: 0x%08x value:"
1918 " 0x%08x\n", zdreq->addr, *p);
1919 break;
1920 case ZM_IOCTL_MEM_WRITE:
1921 p = (u32_t *) bus_to_virt(zdreq->addr);
1922 *p = zdreq->value;
1923 printk(KERN_WARNING
1924 "usbdrv : write value : 0x%08x to memory addr :"
1925 " 0x%08x\n", zdreq->value, zdreq->addr);
1926 break;
1927 case ZM_IOCTL_TALLY:
1928 zfiWlanShowTally(dev);
1929 if (zdreq->addr)
1930 zfiWlanResetTally(dev);
1931 break;
1932 case ZM_IOCTL_TEST:
1933 printk(KERN_WARNING
1934 "ZM_IOCTL_TEST:len=%d\n", zdreq->addr);
1935 /* zfiWlanReadReg(dev, 0x10f400); */
1936 /* zfiWlanReadReg(dev, 0x10f404); */
1937 printk(KERN_WARNING "IOCTL TEST\n");
1938 #if 1
1939 /* print packet */
1940 for (i = 0; i < zdreq->addr; i++) {
1941 if ((i&0x7) == 0)
1942 printk(KERN_WARNING "\n");
1943 printk(KERN_WARNING "%02X ",
1944 (unsigned char)zdreq->data[i]);
1946 printk(KERN_WARNING "\n");
1947 #endif
1949 /* For Test?? 1 to 0 by CWYang(-) */
1950 #if 0
1951 struct sk_buff *s;
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);
1963 #endif
1964 break;
1965 /************************* ZDCONFIG ***************************/
1966 case ZM_IOCTL_FRAG:
1967 zfiWlanSetFragThreshold(dev, zdreq->addr);
1968 break;
1969 case ZM_IOCTL_RTS:
1970 zfiWlanSetRtsThreshold(dev, zdreq->addr);
1971 break;
1972 case ZM_IOCTL_SCAN:
1973 zfiWlanScan(dev);
1974 break;
1975 case ZM_IOCTL_KEY: {
1976 u8_t key[29];
1977 struct zsKeyInfo keyInfo;
1978 u32_t i;
1980 for (i = 0; i < 29; i++)
1981 key[i] = 0;
1983 for (i = 0; i < zdreq->addr; i++)
1984 key[i] = zdreq->data[i];
1986 printk(KERN_WARNING
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;
1992 keyInfo.flag = 0;
1993 keyInfo.key = key;
1994 zfiWlanSetKey(dev, keyInfo);
1996 break;
1997 case ZM_IOCTL_RATE:
1998 zfiWlanSetTxRate(dev, zdreq->addr);
1999 break;
2000 case ZM_IOCTL_ENCRYPTION_MODE:
2001 zfiWlanSetEncryMode(dev, zdreq->addr);
2003 zfiWlanDisable(dev, 0);
2004 zfiWlanEnable(dev);
2005 break;
2006 /* CWYang(+) */
2007 case ZM_IOCTL_SIGNAL_STRENGTH: {
2008 u8_t buffer[2];
2009 zfiWlanQuerySignalInfo(dev, &buffer[0]);
2010 printk(KERN_WARNING
2011 "Current Signal Strength : %02d\n", buffer[0]);
2013 break;
2014 /* CWYang(+) */
2015 case ZM_IOCTL_SIGNAL_QUALITY: {
2016 u8_t buffer[2];
2017 zfiWlanQuerySignalInfo(dev, &buffer[0]);
2018 printk(KERN_WARNING
2019 "Current Signal Quality : %02d\n", buffer[1]);
2021 break;
2022 case ZM_IOCTL_SET_PIBSS_MODE:
2023 if (zdreq->addr == 1)
2024 zfiWlanSetWlanMode(dev, ZM_MODE_PSEUDO);
2025 else
2026 zfiWlanSetWlanMode(dev, ZM_MODE_INFRASTRUCTURE);
2028 zfiWlanDisable(dev, 0);
2029 zfiWlanEnable(dev);
2030 break;
2031 /********************* ZDCONFIG ***********************/
2032 default:
2033 printk(KERN_ERR "usbdrv: error command = %x\n", cmd);
2034 break;
2037 return 0;
2040 int usbdrv_wpa_ioctl(struct net_device *dev, struct athr_wlan_param *zdparm)
2042 int ret = 0;
2043 u8_t bc_addr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2044 u8_t mac_addr[80];
2045 struct zsKeyInfo keyInfo;
2046 struct usbdrv_private *macp = dev->ml_priv;
2047 u16_t vapId = 0;
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) {
2057 /* AP Mode */
2058 keyInfo.flag = ZM_KEY_FLAG_AUTHENTICATOR;
2059 } else
2060 keyInfo.flag = 0;
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;
2068 else
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;
2077 /* del group key */
2078 if (zdparm->sta_addr[0] & 1) {
2079 /* if (macp->cardSetting.WPAIeLen==0)
2080 * { 802.1x dynamic WEP
2081 * mDynKeyMode = 0;
2082 * mKeyFormat[0] = 0;
2083 * mPrivacyInvoked[0]=FALSE;
2084 * mCap[0] &= ~CAP_PRIVACY;
2085 * macp->cardSetting.EncryOnOff[0]=0;
2087 * mWpaBcKeyLen = mGkInstalled = 0;
2089 } else {
2090 /* if (memcmp(zero_mac,zdparm->sta_addr, 6)==0)
2092 * mDynKeyMode=0;
2093 * mKeyFormat[0]=0;
2094 * pSetting->DynKeyMode=0;
2095 * pSetting->EncryMode[0]=0;
2096 * mDynKeyMode=0;
2101 printk(KERN_ERR "Set Encryption Type NONE\n");
2102 return ret;
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);
2110 * u8_t temp;
2111 * int k;
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;
2119 * if (idx == 0)
2120 * { // Pairwise key
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;
2128 * if (idx == 0)
2129 * { // Pairwise key
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) {
2136 /* WEP 64 */
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; */
2145 } else {
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
2152 * case:
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) {
2171 int ii;
2172 printk(KERN_WARNING
2173 "Otus: Key Context:\n");
2174 for (ii = 0; ii < keyInfo.keyLength; ) {
2175 printk(KERN_WARNING
2176 "0x%02x ", keyInfo.key[ii]);
2177 if ((++ii % 16) == 0)
2178 printk(KERN_WARNING "\n");
2180 printk(KERN_WARNING "\n");
2182 /* #endif */
2184 /* Set encrypt mode */
2185 /* zfiWlanSetEncryMode(dev, CamEncryType); */
2186 vapId = zfLnxGetVapId(dev);
2187 if (vapId == 0xffff)
2188 keyInfo.vapId = 0;
2189 else
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); */
2199 break;
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:
2211 printk(KERN_WARNING
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",
2217 mac_addr);
2218 else
2219 printk(KERN_ERR "Deauthenticate STA: %s"
2220 "with reason code: %d\n",
2221 mac_addr, zdparm->u.mlme.reason_code);
2222 break;
2223 case MLME_STA_DISASSOC:
2224 printk(KERN_WARNING
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",
2230 mac_addr);
2231 else
2232 printk(KERN_ERR "Disassociate STA: %s"
2233 "with reason code: %d\n",
2234 mac_addr, zdparm->u.mlme.reason_code);
2235 break;
2236 default:
2237 printk(KERN_ERR "MLME command: 0x%04x not support\n",
2238 zdparm->u.mlme.cmd);
2239 break;
2242 break;
2243 case ZD_CMD_SCAN_REQ:
2244 printk(KERN_ERR "usbdrv_wpa_ioctl: ZD_CMD_SCAN_REQ\n");
2245 break;
2246 case ZD_CMD_SET_GENERIC_ELEMENT:
2247 printk(KERN_ERR "usbdrv_wpa_ioctl:"
2248 " ZD_CMD_SET_GENERIC_ELEMENT\n");
2250 /* Copy the WPA IE
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) {
2257 /* AP Mode */
2258 zfiWlanSetWpaIe(dev, zdparm->u.generic_elem.data,
2259 zdparm->u.generic_elem.len);
2260 } else {
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);
2269 int ii;
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);
2275 /* DUMP WPA IE */
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");
2290 * #endif
2292 break;
2294 /* #ifdef ZM_HOSTAPD_SUPPORT */
2295 case ZD_CMD_GET_TSC:
2296 printk(KERN_ERR "usbdrv_wpa_ioctl : ZD_CMD_GET_TSC\n");
2297 break;
2298 /* #endif */
2300 default:
2301 printk(KERN_ERR "usbdrv_wpa_ioctl default : 0x%04x\n",
2302 zdparm->cmd);
2303 ret = -EINVAL;
2304 break;
2307 return ret;
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;
2315 u16_t apId;
2316 u8_t bc_addr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2317 int ret = 0;
2318 int ii;
2320 /* Get the AP Id */
2321 apId = zfLnxGetVapId(dev);
2323 if (apId == 0xffff) {
2324 apId = 0;
2325 } else {
2326 apId = apId + 1;
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);
2334 break;
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);
2372 } else {
2373 keyInfo.flag |= ZM_KEY_FLAG_PK;
2376 zfiWlanSetKey(dev, keyInfo);
2378 break;
2379 case ZM_CMD_CENC_REKEY:
2380 /* ret = wai_ioctl_rekey(vap, ioctl_msg); */
2381 printk(KERN_ERR "ZM_CMD_CENC_REKEY\n");
2382 break;
2383 default:
2384 ret = -EOPNOTSUPP;
2385 break;
2388 /* if (retv == ENETRESET) */
2389 /* retv = IS_UP_AUTO(vap) ? ieee80211_open(vap->iv_dev) : 0; */
2391 return ret;
2393 #endif /* ZM_ENABLE_CENC */
2395 int usbdrv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2397 /* struct usbdrv_private *macp; */
2398 /* void *regp; */
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;
2404 int err = 0;
2405 int changed = 0;
2407 /* regp = macp->regp; */
2409 if (!netif_running(dev))
2410 return -EINVAL;
2412 switch (cmd) {
2413 case SIOCGIWNAME:
2414 strcpy(wrq->u.name, "IEEE 802.11-DS");
2415 break;
2416 case SIOCGIWAP:
2417 err = usbdrvwext_giwap(dev, NULL, &wrq->u.ap_addr, NULL);
2418 break;
2419 case SIOCSIWAP:
2420 err = usbdrvwext_siwap(dev, NULL, &wrq->u.ap_addr, NULL);
2421 break;
2422 case SIOCGIWMODE:
2423 err = usbdrvwext_giwmode(dev, NULL, &wrq->u.mode, NULL);
2424 break;
2425 case SIOCSIWESSID:
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);
2430 if (!err)
2431 changed = 1;
2432 break;
2433 case SIOCGIWESSID:
2434 err = usbdrvwext_giwessid(dev, NULL, &wrq->u.essid, NULL);
2435 break;
2436 case SIOCSIWRTS:
2437 err = usbdrv_ioctl_setrts(dev, &wrq->u.rts);
2438 if (! err)
2439 changed = 1;
2440 break;
2441 /* set_auth */
2442 case SIOCIWFIRSTPRIV + 0x2: {
2443 /* printk("CWY - SIOCIWFIRSTPRIV + 0x2(set_auth)\n"); */
2444 if (!capable(CAP_NET_ADMIN)) {
2445 err = -EPERM;
2446 break;
2448 int val = *((int *) wrq->u.name);
2449 if ((val < 0) || (val > 2)) {
2450 err = -EINVAL;
2451 break;
2452 } else {
2453 zfiWlanSetAuthenticationMode(dev, val);
2455 if (macp->DeviceOpened == 1) {
2456 zfiWlanDisable(dev, 0);
2457 zfiWlanEnable(dev);
2460 err = 0;
2461 changed = 1;
2464 break;
2465 /* get_auth */
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)) {
2480 return -EFAULT;
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)) {
2487 return -EFAULT;
2489 } else if (AuthMode == ZM_AUTH_MODE_AUTO) {
2490 wrq->u.data.length = 10;
2492 if (copy_to_user(wrq->u.data.pointer,
2493 "auto mode", 10)) {
2494 return -EFAULT;
2496 } else {
2497 return -EFAULT;
2501 break;
2502 /* debug command */
2503 case ZDAPIOCTL:
2504 if (copy_from_user(&zdreq, ifr->ifr_data, sizeof(zdreq))) {
2505 printk(KERN_ERR "usbdrv : copy_from_user error\n");
2506 return -EFAULT;
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);
2516 err = 0;
2517 break;
2518 case ZD_IOCTL_WPA:
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");
2522 return -EFAULT;
2525 usbdrv_wpa_ioctl(dev, &zdparm);
2526 err = 0;
2527 break;
2528 case ZD_IOCTL_PARAM: {
2529 int *p;
2530 int op;
2531 int arg;
2533 /* Point to the name field and retrieve the
2534 * op and arg elements.
2536 p = (int *)wrq->u.name;
2537 op = *p++;
2538 arg = *p;
2540 if (op == ZD_PARAM_ROAMING) {
2541 printk(KERN_ERR
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 */
2549 if (arg) {
2550 /* mCap[0] |= CAP_PRIVACY; */
2551 /* macp->cardSetting.EncryOnOff[0] = 1; */
2552 printk(KERN_ERR "enable\n");
2554 } else {
2555 /* mCap[0] &= ~CAP_PRIVACY; */
2556 /* macp->cardSetting.EncryOnOff[0] = 0; */
2557 printk(KERN_ERR "disable\n");
2559 /* changed=1; */
2561 if (op == ZD_PARAM_WPA) {
2563 printk(KERN_ERR "ZD_PARAM_WPA : ");
2565 if (arg) {
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)) {
2579 printk(KERN_ERR
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)) {
2588 printk(KERN_ERR
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,
2593 ZM_AUTH_MODE_WPA);
2594 } else if ((macp->supIe[17] == 0xf) &&
2595 (macp->supIe[18] == 0xac) &&
2596 (macp->supIe[19] == 0x2))
2598 printk(KERN_ERR
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))
2608 printk(KERN_ERR
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,
2613 ZM_AUTH_MODE_WPA2);
2615 /* WPA or WPAPSK */
2616 if ((macp->supIe[21] == 0x50) ||
2617 (macp->supIe[22] == 0xf2)) {
2618 if (macp->supIe[11] == 0x2) {
2619 printk(KERN_ERR
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);
2624 } else {
2625 printk(KERN_ERR
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);
2632 //WPA2 or WPA2PSK
2633 if ((macp->supIe[17] == 0xf) ||
2634 (macp->supIe[18] == 0xac)) {
2635 if (macp->supIe[13] == 0x2) {
2636 printk(KERN_ERR
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);
2641 } else {
2642 printk(KERN_ERR
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);
2651 } else {
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
2660 * field to zero.
2661 *macp->cardSetting.WPAIe[1] = 0;
2666 if (op == ZD_PARAM_COUNTERMEASURES) {
2667 printk(KERN_ERR
2668 "****************ZD_PARAM_COUNTERMEASURES : ");
2670 if(arg) {
2671 /* mCounterMeasureState=1; */
2672 printk(KERN_ERR "enable\n");
2673 } else {
2674 /* mCounterMeasureState=0; */
2675 printk(KERN_ERR "disable\n");
2678 if (op == ZD_PARAM_DROPUNENCRYPTED) {
2679 printk(KERN_ERR "ZD_PARAM_DROPUNENCRYPTED : ");
2681 if(arg) {
2682 printk(KERN_ERR "enable\n");
2683 } else {
2684 printk(KERN_ERR "disable\n");
2687 if (op == ZD_PARAM_AUTH_ALGS) {
2688 printk(KERN_ERR "ZD_PARAM_AUTH_ALGS : ");
2690 if (arg == 0) {
2691 printk(KERN_ERR "OPEN_SYSTEM\n");
2692 } else {
2693 printk(KERN_ERR "SHARED_KEY\n");
2696 if (op == ZD_PARAM_WPS_FILTER) {
2697 printk(KERN_ERR "ZD_PARAM_WPS_FILTER : ");
2699 if (arg) {
2700 /* mCounterMeasureState=1; */
2701 macp->forwardMgmt = 1;
2702 printk(KERN_ERR "enable\n");
2703 } else {
2704 /* mCounterMeasureState=0; */
2705 macp->forwardMgmt = 0;
2706 printk(KERN_ERR "disable\n");
2710 err = 0;
2711 break;
2712 case ZD_IOCTL_GETWPAIE: {
2713 struct ieee80211req_wpaie req_wpaie;
2714 u16_t apId, i, j;
2716 /* Get the AP Id */
2717 apId = zfLnxGetVapId(dev);
2719 if (apId == 0xffff) {
2720 apId = 0;
2721 } else {
2722 apId = apId + 1;
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");
2728 return -EFAULT;
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])
2735 break;
2737 if (j == 6)
2738 break;
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))) {
2749 return -EFAULT;
2753 err = 0;
2754 break;
2755 #ifdef ZM_ENABLE_CENC
2756 case ZM_IOCTL_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");
2760 return -EFAULT;
2763 usbdrv_cenc_ioctl(dev,
2764 (struct zydas_cenc_param *)&macp->zd_wpa_req);
2765 err = 0;
2766 break;
2767 #endif /* ZM_ENABLE_CENC */
2768 default:
2769 err = -EOPNOTSUPP;
2770 break;
2773 return err;