USB: Fix documentation for avoid_reset_quirk
[linux-2.6/libata-dev.git] / drivers / staging / otus / ioctl.c
blob8c47b1a686271f041fc4701ba83ced08ba7098e6
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 #include <net/iw_handler.h>
63 extern u16_t zfLnxGetVapId(zdev_t *dev);
65 static const u32_t channel_frequency_11A[] =
67 /* Even element for Channel Number, Odd for Frequency */
68 36, 5180,
69 40, 5200,
70 44, 5220,
71 48, 5240,
72 52, 5260,
73 56, 5280,
74 60, 5300,
75 64, 5320,
76 100, 5500,
77 104, 5520,
78 108, 5540,
79 112, 5560,
80 116, 5580,
81 120, 5600,
82 124, 5620,
83 128, 5640,
84 132, 5660,
85 136, 5680,
86 140, 5700,
87 /**/
88 184, 4920,
89 188, 4940,
90 192, 4960,
91 196, 4980,
92 8, 5040,
93 12, 5060,
94 16, 5080,
95 34, 5170,
96 38, 5190,
97 42, 5210,
98 46, 5230,
99 /**/
100 149, 5745,
101 153, 5765,
102 157, 5785,
103 161, 5805,
104 165, 5825
105 /**/
108 int usbdrv_freq2chan(u32_t freq)
110 /* 2.4G Hz */
111 if (freq > 2400 && freq < 3000) {
112 return ((freq-2412)/5) + 1;
113 } else {
114 u16_t ii;
115 u16_t num_chan = sizeof(channel_frequency_11A)/sizeof(u32_t);
117 for (ii = 1; ii < num_chan; ii += 2) {
118 if (channel_frequency_11A[ii] == freq)
119 return channel_frequency_11A[ii-1];
123 return 0;
126 int usbdrv_chan2freq(int chan)
128 int freq;
130 /* If channel number is out of range */
131 if (chan > 165 || chan <= 0)
132 return -1;
134 /* 2.4G band */
135 if (chan >= 1 && chan <= 13) {
136 freq = (2412 + (chan - 1) * 5);
137 return freq;
138 } else if (chan >= 36 && chan <= 165) {
139 u16_t ii;
140 u16_t num_chan = sizeof(channel_frequency_11A)/sizeof(u32_t);
142 for (ii = 0; ii < num_chan; ii += 2) {
143 if (channel_frequency_11A[ii] == chan)
144 return channel_frequency_11A[ii+1];
147 /* Can't find desired frequency */
148 if (ii == num_chan)
149 return -1;
152 /* Can't find deisred frequency */
153 return -1;
156 int usbdrv_ioctl_setessid(struct net_device *dev, struct iw_point *erq)
158 #ifdef ZM_HOSTAPD_SUPPORT
159 /* struct usbdrv_private *macp = dev->ml_priv; */
160 char essidbuf[IW_ESSID_MAX_SIZE+1];
161 int i;
163 if (!netif_running(dev))
164 return -EINVAL;
166 memset(essidbuf, 0, sizeof(essidbuf));
168 printk(KERN_ERR "usbdrv_ioctl_setessid\n");
170 /* printk("ssidlen=%d\n", erq->length); //for any, it is 1. */
171 if (erq->flags) {
172 if (erq->length > (IW_ESSID_MAX_SIZE+1))
173 return -E2BIG;
175 if (copy_from_user(essidbuf, erq->pointer, erq->length))
176 return -EFAULT;
179 /* zd_DisasocAll(2); */
180 /* wait_ms(100); */
182 printk(KERN_ERR "essidbuf: ");
184 for (i = 0; i < erq->length; i++)
185 printk(KERN_ERR "%02x ", essidbuf[i]);
187 printk(KERN_ERR "\n");
189 essidbuf[erq->length] = '\0';
190 /* memcpy(macp->wd.ws.ssid, essidbuf, erq->length); */
191 /* macp->wd.ws.ssidLen = strlen(essidbuf)+2; */
192 /* macp->wd.ws.ssid[1] = strlen(essidbuf); Update ssid length */
194 zfiWlanSetSSID(dev, essidbuf, erq->length);
195 #if 0
196 printk(KERN_ERR "macp->wd.ws.ssid: ");
198 for (i = 0; i < macp->wd.ws.ssidLen; i++)
199 printk(KERN_ERR "%02x ", macp->wd.ws.ssid[i]);
201 printk(KERN_ERR "\n");
202 #endif
204 zfiWlanDisable(dev, 0);
205 zfiWlanEnable(dev);
207 #endif
209 return 0;
212 int usbdrv_ioctl_getessid(struct net_device *dev, struct iw_point *erq)
214 /* struct usbdrv_private *macp = dev->ml_priv; */
215 u8_t essidbuf[IW_ESSID_MAX_SIZE+1];
216 u8_t len;
217 u8_t i;
220 /* len = macp->wd.ws.ssidLen; */
221 /* memcpy(essidbuf, macp->wd.ws.ssid, macp->wd.ws.ssidLen); */
222 zfiWlanQuerySSID(dev, essidbuf, &len);
224 essidbuf[len] = 0;
226 printk(KERN_ERR "ESSID: ");
228 for (i = 0; i < len; i++)
229 printk(KERN_ERR "%c", essidbuf[i]);
231 printk(KERN_ERR "\n");
233 erq->flags = 1;
234 erq->length = strlen(essidbuf) + 1;
236 if (erq->pointer) {
237 if (copy_to_user(erq->pointer, essidbuf, erq->length))
238 return -EFAULT;
241 return 0;
244 int usbdrv_ioctl_setrts(struct net_device *dev, struct iw_param *rrq)
246 return 0;
250 * Encode a WPA or RSN information element as a custom
251 * element using the hostap format.
253 u32 encode_ie(void *buf, u32 bufsize, const u8 *ie, u32 ielen,
254 const u8 *leader, u32 leader_len)
256 u8 *p;
257 u32 i;
259 if (bufsize < leader_len)
260 return 0;
261 p = buf;
262 memcpy(p, leader, leader_len);
263 bufsize -= leader_len;
264 p += leader_len;
265 for (i = 0; i < ielen && bufsize > 2; i++)
266 p += sprintf(p, "%02x", ie[i]);
267 return (i == ielen ? p - (u8 *)buf:0);
271 * Translate scan data returned from the card to a card independent
272 * format that the Wireless Tools will understand
274 char *usbdrv_translate_scan(struct net_device *dev,
275 struct iw_request_info *info, char *current_ev,
276 char *end_buf, struct zsBssInfo *list)
278 struct iw_event iwe; /* Temporary buffer */
279 u16_t capabilities;
280 char *current_val; /* For rates */
281 char *last_ev;
282 int i;
283 char buf[64*2 + 30];
285 last_ev = current_ev;
287 /* First entry *MUST* be the AP MAC address */
288 iwe.cmd = SIOCGIWAP;
289 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
290 memcpy(iwe.u.ap_addr.sa_data, list->bssid, ETH_ALEN);
291 current_ev = iwe_stream_add_event(info, current_ev,
292 end_buf, &iwe, IW_EV_ADDR_LEN);
294 /* Ran out of buffer */
295 if (last_ev == current_ev)
296 return end_buf;
298 last_ev = current_ev;
300 /* Other entries will be displayed in the order we give them */
302 /* Add the ESSID */
303 iwe.u.data.length = list->ssid[1];
304 if (iwe.u.data.length > 32)
305 iwe.u.data.length = 32;
306 iwe.cmd = SIOCGIWESSID;
307 iwe.u.data.flags = 1;
308 current_ev = iwe_stream_add_point(info, current_ev,
309 end_buf, &iwe, &list->ssid[2]);
311 /* Ran out of buffer */
312 if (last_ev == current_ev)
313 return end_buf;
315 last_ev = current_ev;
317 /* Add mode */
318 iwe.cmd = SIOCGIWMODE;
319 capabilities = (list->capability[1] << 8) + list->capability[0];
320 if (capabilities & (0x01 | 0x02)) {
321 if (capabilities & 0x01)
322 iwe.u.mode = IW_MODE_MASTER;
323 else
324 iwe.u.mode = IW_MODE_ADHOC;
325 current_ev = iwe_stream_add_event(info, current_ev,
326 end_buf, &iwe, IW_EV_UINT_LEN);
329 /* Ran out of buffer */
330 if (last_ev == current_ev)
331 return end_buf;
333 last_ev = current_ev;
335 /* Add frequency */
336 iwe.cmd = SIOCGIWFREQ;
337 iwe.u.freq.m = list->channel;
338 /* Channel frequency in KHz */
339 if (iwe.u.freq.m > 14) {
340 if ((184 <= iwe.u.freq.m) && (iwe.u.freq.m <= 196))
341 iwe.u.freq.m = 4000 + iwe.u.freq.m * 5;
342 else
343 iwe.u.freq.m = 5000 + iwe.u.freq.m * 5;
344 } else {
345 if (iwe.u.freq.m == 14)
346 iwe.u.freq.m = 2484;
347 else
348 iwe.u.freq.m = 2412 + (iwe.u.freq.m - 1) * 5;
350 iwe.u.freq.e = 6;
351 current_ev = iwe_stream_add_event(info, current_ev,
352 end_buf, &iwe, IW_EV_FREQ_LEN);
354 /* Ran out of buffer */
355 if (last_ev == current_ev)
356 return end_buf;
358 last_ev = current_ev;
360 /* Add quality statistics */
361 iwe.cmd = IWEVQUAL;
362 iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED
363 | IW_QUAL_NOISE_UPDATED;
364 iwe.u.qual.level = list->signalStrength;
365 iwe.u.qual.noise = 0;
366 iwe.u.qual.qual = list->signalQuality;
367 current_ev = iwe_stream_add_event(info, current_ev,
368 end_buf, &iwe, IW_EV_QUAL_LEN);
370 /* Ran out of buffer */
371 if (last_ev == current_ev)
372 return end_buf;
374 last_ev = current_ev;
376 /* Add encryption capability */
378 iwe.cmd = SIOCGIWENCODE;
379 if (capabilities & 0x10)
380 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
381 else
382 iwe.u.data.flags = IW_ENCODE_DISABLED;
384 iwe.u.data.length = 0;
385 current_ev = iwe_stream_add_point(info, current_ev,
386 end_buf, &iwe, list->ssid);
388 /* Ran out of buffer */
389 if (last_ev == current_ev)
390 return end_buf;
392 last_ev = current_ev;
394 /* Rate : stuffing multiple values in a single event require a bit
395 * more of magic
397 current_val = current_ev + IW_EV_LCP_LEN;
399 iwe.cmd = SIOCGIWRATE;
400 /* Those two flags are ignored... */
401 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
403 for (i = 0 ; i < list->supportedRates[1] ; i++) {
404 /* Bit rate given in 500 kb/s units (+ 0x80) */
405 iwe.u.bitrate.value = ((list->supportedRates[i+2] & 0x7f)
406 * 500000);
407 /* Add new value to event */
408 current_val = iwe_stream_add_value(info, current_ev,
409 current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
411 /* Ran out of buffer */
412 if (last_ev == current_val)
413 return end_buf;
415 last_ev = current_val;
418 for (i = 0 ; i < list->extSupportedRates[1] ; i++) {
419 /* Bit rate given in 500 kb/s units (+ 0x80) */
420 iwe.u.bitrate.value = ((list->extSupportedRates[i+2] & 0x7f)
421 * 500000);
422 /* Add new value to event */
423 current_val = iwe_stream_add_value(info, current_ev,
424 current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
426 /* Ran out of buffer */
427 if (last_ev == current_val)
428 return end_buf;
430 last_ev = current_ev;
433 /* Check if we added any event */
434 if ((current_val - current_ev) > IW_EV_LCP_LEN)
435 current_ev = current_val;
436 #define IEEE80211_ELEMID_RSN 0x30
437 memset(&iwe, 0, sizeof(iwe));
438 iwe.cmd = IWEVCUSTOM;
439 snprintf(buf, sizeof(buf), "bcn_int=%d", (list->beaconInterval[1] << 8)
440 + list->beaconInterval[0]);
441 iwe.u.data.length = strlen(buf);
442 current_ev = iwe_stream_add_point(info, current_ev,
443 end_buf, &iwe, buf);
445 /* Ran out of buffer */
446 if (last_ev == current_ev)
447 return end_buf;
449 last_ev = current_ev;
451 if (list->wpaIe[1] != 0) {
452 static const char rsn_leader[] = "rsn_ie=";
453 static const char wpa_leader[] = "wpa_ie=";
455 memset(&iwe, 0, sizeof(iwe));
456 iwe.cmd = IWEVCUSTOM;
457 if (list->wpaIe[0] == IEEE80211_ELEMID_RSN)
458 iwe.u.data.length = encode_ie(buf, sizeof(buf),
459 list->wpaIe, list->wpaIe[1]+2,
460 rsn_leader, sizeof(rsn_leader)-1);
461 else
462 iwe.u.data.length = encode_ie(buf, sizeof(buf),
463 list->wpaIe, list->wpaIe[1]+2,
464 wpa_leader, sizeof(wpa_leader)-1);
466 if (iwe.u.data.length != 0)
467 current_ev = iwe_stream_add_point(info, current_ev,
468 end_buf, &iwe, buf);
470 /* Ran out of buffer */
471 if (last_ev == current_ev)
472 return end_buf;
474 last_ev = current_ev;
477 if (list->rsnIe[1] != 0) {
478 static const char rsn_leader[] = "rsn_ie=";
479 memset(&iwe, 0, sizeof(iwe));
480 iwe.cmd = IWEVCUSTOM;
482 if (list->rsnIe[0] == IEEE80211_ELEMID_RSN) {
483 iwe.u.data.length = encode_ie(buf, sizeof(buf),
484 list->rsnIe, list->rsnIe[1]+2,
485 rsn_leader, sizeof(rsn_leader)-1);
486 if (iwe.u.data.length != 0)
487 current_ev = iwe_stream_add_point(info,
488 current_ev, end_buf, &iwe, buf);
490 /* Ran out of buffer */
491 if (last_ev == current_ev)
492 return end_buf;
494 last_ev = current_ev;
497 /* The other data in the scan result are not really
498 * interesting, so for now drop it
500 return current_ev;
503 int usbdrvwext_giwname(struct net_device *dev,
504 struct iw_request_info *info,
505 union iwreq_data *wrq, char *extra)
507 /* struct usbdrv_private *macp = dev->ml_priv; */
509 strcpy(wrq->name, "IEEE 802.11-MIMO");
511 return 0;
514 int usbdrvwext_siwfreq(struct net_device *dev,
515 struct iw_request_info *info,
516 struct iw_freq *freq, char *extra)
518 u32_t FreqKHz;
519 struct usbdrv_private *macp = dev->ml_priv;
521 if (!netif_running(dev))
522 return -EINVAL;
524 if (freq->e > 1)
525 return -EINVAL;
527 if (freq->e == 1) {
528 FreqKHz = (freq->m / 100000);
530 if (FreqKHz > 4000000) {
531 if (FreqKHz > 5825000)
532 FreqKHz = 5825000;
533 else if (FreqKHz < 4920000)
534 FreqKHz = 4920000;
535 else if (FreqKHz < 5000000)
536 FreqKHz = (((FreqKHz - 4000000) / 5000) * 5000)
537 + 4000000;
538 else
539 FreqKHz = (((FreqKHz - 5000000) / 5000) * 5000)
540 + 5000000;
541 } else {
542 if (FreqKHz > 2484000)
543 FreqKHz = 2484000;
544 else if (FreqKHz < 2412000)
545 FreqKHz = 2412000;
546 else
547 FreqKHz = (((FreqKHz - 2412000) / 5000) * 5000)
548 + 2412000;
550 } else {
551 FreqKHz = usbdrv_chan2freq(freq->m);
553 if (FreqKHz != -1)
554 FreqKHz *= 1000;
555 else
556 FreqKHz = 2412000;
559 /* printk("freq->m: %d, freq->e: %d\n", freq->m, freq->e); */
560 /* printk("FreqKHz: %d\n", FreqKHz); */
562 if (macp->DeviceOpened == 1) {
563 zfiWlanSetFrequency(dev, FreqKHz, 0); /* Immediate */
564 /* u8_t wpaieLen,wpaie[50]; */
565 /* zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen); */
566 zfiWlanDisable(dev, 0);
567 zfiWlanEnable(dev);
568 /* if (wpaieLen > 2) */
569 /* zfiWlanSetWpaIe(dev, wpaie, wpaieLen); */
572 return 0;
575 int usbdrvwext_giwfreq(struct net_device *dev,
576 struct iw_request_info *info,
577 struct iw_freq *freq, char *extra)
579 struct usbdrv_private *macp = dev->ml_priv;
581 if (macp->DeviceOpened != 1)
582 return 0;
584 freq->m = zfiWlanQueryFrequency(dev);
585 freq->e = 3;
587 return 0;
590 int usbdrvwext_siwmode(struct net_device *dev,
591 struct iw_request_info *info,
592 union iwreq_data *wrq, char *extra)
594 struct usbdrv_private *macp = dev->ml_priv;
595 u8_t WlanMode;
597 if (!netif_running(dev))
598 return -EINVAL;
600 if (macp->DeviceOpened != 1)
601 return 0;
603 switch (wrq->mode) {
604 case IW_MODE_MASTER:
605 WlanMode = ZM_MODE_AP;
606 break;
607 case IW_MODE_INFRA:
608 WlanMode = ZM_MODE_INFRASTRUCTURE;
609 break;
610 case IW_MODE_ADHOC:
611 WlanMode = ZM_MODE_IBSS;
612 break;
613 default:
614 WlanMode = ZM_MODE_IBSS;
615 break;
618 zfiWlanSetWlanMode(dev, WlanMode);
619 zfiWlanDisable(dev, 1);
620 zfiWlanEnable(dev);
622 return 0;
625 int usbdrvwext_giwmode(struct net_device *dev,
626 struct iw_request_info *info,
627 __u32 *mode, char *extra)
629 unsigned long irqFlag;
630 struct usbdrv_private *macp = dev->ml_priv;
632 if (!netif_running(dev))
633 return -EINVAL;
635 if (macp->DeviceOpened != 1)
636 return 0;
638 spin_lock_irqsave(&macp->cs_lock, irqFlag);
640 switch (zfiWlanQueryWlanMode(dev)) {
641 case ZM_MODE_AP:
642 *mode = IW_MODE_MASTER;
643 break;
644 case ZM_MODE_INFRASTRUCTURE:
645 *mode = IW_MODE_INFRA;
646 break;
647 case ZM_MODE_IBSS:
648 *mode = IW_MODE_ADHOC;
649 break;
650 default:
651 *mode = IW_MODE_ADHOC;
652 break;
655 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
657 return 0;
660 int usbdrvwext_siwsens(struct net_device *dev,
661 struct iw_request_info *info,
662 struct iw_param *sens, char *extra)
664 return 0;
667 int usbdrvwext_giwsens(struct net_device *dev,
668 struct iw_request_info *info,
669 struct iw_param *sens, char *extra)
671 sens->value = 0;
672 sens->fixed = 1;
674 return 0;
677 int usbdrvwext_giwrange(struct net_device *dev,
678 struct iw_request_info *info,
679 struct iw_point *data, char *extra)
681 struct iw_range *range = (struct iw_range *) extra;
682 int i, val;
683 /* int num_band_a; */
684 u16_t channels[60];
685 u16_t channel_num;
687 if (!netif_running(dev))
688 return -EINVAL;
690 range->txpower_capa = IW_TXPOW_DBM;
691 /* XXX what about min/max_pmp, min/max_pmt, etc. */
693 range->we_version_compiled = WIRELESS_EXT;
694 range->we_version_source = 13;
696 range->retry_capa = IW_RETRY_LIMIT;
697 range->retry_flags = IW_RETRY_LIMIT;
698 range->min_retry = 0;
699 range->max_retry = 255;
701 channel_num = zfiWlanQueryAllowChannels(dev, channels);
703 /* Gurantee reported channel numbers is less
704 * or equal to IW_MAX_FREQUENCIES
706 if (channel_num > IW_MAX_FREQUENCIES)
707 channel_num = IW_MAX_FREQUENCIES;
709 val = 0;
711 for (i = 0; i < channel_num; i++) {
712 range->freq[val].i = usbdrv_freq2chan(channels[i]);
713 range->freq[val].m = channels[i];
714 range->freq[val].e = 6;
715 val++;
718 range->num_channels = channel_num;
719 range->num_frequency = channel_num;
721 #if 0
722 range->num_channels = 14; /* Only 2.4G */
724 /* XXX need to filter against the regulatory domain &| active set */
725 val = 0;
726 /* B,G Bands */
727 for (i = 1; i <= 14; i++) {
728 range->freq[val].i = i;
729 if (i == 14)
730 range->freq[val].m = 2484000;
731 else
732 range->freq[val].m = (2412+(i-1)*5)*1000;
733 range->freq[val].e = 3;
734 val++;
737 num_band_a = (IW_MAX_FREQUENCIES - val);
738 /* A Bands */
739 for (i = 0; i < num_band_a; i++) {
740 range->freq[val].i = channel_frequency_11A[2 * i];
741 range->freq[val].m = channel_frequency_11A[2 * i + 1] * 1000;
742 range->freq[val].e = 3;
743 val++;
745 /* MIMO Rate Not Defined Now
746 * For 802.11a, there are too more frequency.
747 * We can't return them all.
749 range->num_frequency = val;
750 #endif
752 /* Max of /proc/net/wireless */
753 range->max_qual.qual = 100; /* ?? 92; */
754 range->max_qual.level = 154; /* ?? */
755 range->max_qual.noise = 154; /* ?? */
756 range->sensitivity = 3; /* ?? */
758 /* XXX these need to be nsd-specific! */
759 range->min_rts = 0;
760 range->max_rts = 2347;
761 range->min_frag = 256;
762 range->max_frag = 2346;
763 range->max_encoding_tokens = 4 /* NUM_WEPKEYS ?? */;
764 range->num_encoding_sizes = 2; /* ?? */
766 range->encoding_size[0] = 5; /* ?? WEP Key Encoding Size */
767 range->encoding_size[1] = 13; /* ?? */
769 /* XXX what about num_bitrates/throughput? */
770 range->num_bitrates = 0; /* ?? */
772 /* estimated max throughput
773 * XXX need to cap it if we're running at ~2Mbps..
776 range->throughput = 300000000;
778 return 0;
781 int usbdrvwext_siwap(struct net_device *dev, struct iw_request_info *info,
782 struct sockaddr *MacAddr, char *extra)
784 struct usbdrv_private *macp = dev->ml_priv;
786 if (!netif_running(dev))
787 return -EINVAL;
789 if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) {
790 /* AP Mode */
791 zfiWlanSetMacAddress(dev, (u16_t *)&MacAddr->sa_data[0]);
792 } else {
793 /* STA Mode */
794 zfiWlanSetBssid(dev, &MacAddr->sa_data[0]);
797 if (macp->DeviceOpened == 1) {
798 /* u8_t wpaieLen,wpaie[80]; */
799 /* zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen); */
800 zfiWlanDisable(dev, 0);
801 zfiWlanEnable(dev);
802 /* if (wpaieLen > 2) */
803 /* zfiWlanSetWpaIe(dev, wpaie, wpaieLen); */
806 return 0;
809 int usbdrvwext_giwap(struct net_device *dev,
810 struct iw_request_info *info,
811 struct sockaddr *MacAddr, char *extra)
813 struct usbdrv_private *macp = dev->ml_priv;
815 if (macp->DeviceOpened != 1)
816 return 0;
818 if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) {
819 /* AP Mode */
820 zfiWlanQueryMacAddress(dev, &MacAddr->sa_data[0]);
821 } else {
822 /* STA Mode */
823 if (macp->adapterState == ZM_STATUS_MEDIA_CONNECT) {
824 zfiWlanQueryBssid(dev, &MacAddr->sa_data[0]);
825 } else {
826 u8_t zero_addr[6] = { 0x00, 0x00, 0x00, 0x00,
827 0x00, 0x00 };
828 memcpy(&MacAddr->sa_data[0], zero_addr,
829 sizeof(zero_addr));
833 return 0;
836 int usbdrvwext_iwaplist(struct net_device *dev,
837 struct iw_request_info *info,
838 struct iw_point *data, char *extra)
840 /* Don't know how to do yet--CWYang(+) */
841 return 0;
845 int usbdrvwext_siwscan(struct net_device *dev, struct iw_request_info *info,
846 struct iw_point *data, char *extra)
848 struct usbdrv_private *macp = dev->ml_priv;
850 if (macp->DeviceOpened != 1)
851 return 0;
853 printk(KERN_WARNING "CWY - usbdrvwext_siwscan\n");
855 zfiWlanScan(dev);
857 return 0;
860 int usbdrvwext_giwscan(struct net_device *dev,
861 struct iw_request_info *info,
862 struct iw_point *data, char *extra)
864 struct usbdrv_private *macp = dev->ml_priv;
865 /* struct zsWlanDev* wd = (struct zsWlanDev*) zmw_wlan_dev(dev); */
866 char *current_ev = extra;
867 char *end_buf;
868 int i;
869 /* BssList = wd->sta.pBssList; */
870 /* zmw_get_wlan_dev(dev); */
872 if (macp->DeviceOpened != 1)
873 return 0;
875 /* struct zsBssList BssList; */
876 struct zsBssListV1 *pBssList = kmalloc(sizeof(struct zsBssListV1),
877 GFP_KERNEL);
878 if (data->length == 0)
879 end_buf = extra + IW_SCAN_MAX_DATA;
880 else
881 end_buf = extra + data->length;
883 printk(KERN_WARNING "giwscan - Report Scan Results\n");
884 /* printk("giwscan - BssList Sreucture Len : %d\n", sizeof(BssList));
885 * printk("giwscan - BssList Count : %d\n",
886 * wd->sta.pBssList->bssCount);
887 * printk("giwscan - UpdateBssList Count : %d\n",
888 * wd->sta.pUpdateBssList->bssCount);
890 zfiWlanQueryBssListV1(dev, pBssList);
891 /* zfiWlanQueryBssList(dev, &BssList); */
893 /* Read and parse all entries */
894 printk(KERN_WARNING "giwscan - pBssList->bssCount : %d\n",
895 pBssList->bssCount);
896 /* printk("giwscan - BssList.bssCount : %d\n", BssList.bssCount); */
898 for (i = 0; i < pBssList->bssCount; i++) {
899 /* Translate to WE format this entry
900 * current_ev = usbdrv_translate_scan(dev, info, current_ev,
901 * extra + IW_SCAN_MAX_DATA, &pBssList->bssInfo[i]);
903 current_ev = usbdrv_translate_scan(dev, info, current_ev,
904 end_buf, &pBssList->bssInfo[i]);
906 if (current_ev == end_buf) {
907 kfree(pBssList);
908 data->length = current_ev - extra;
909 return -E2BIG;
913 /* Length of data */
914 data->length = (current_ev - extra);
915 data->flags = 0; /* todo */
917 kfree(pBssList);
919 return 0;
922 int usbdrvwext_siwessid(struct net_device *dev,
923 struct iw_request_info *info,
924 struct iw_point *essid, char *extra)
926 char EssidBuf[IW_ESSID_MAX_SIZE + 1];
927 struct usbdrv_private *macp = dev->ml_priv;
929 if (!netif_running(dev))
930 return -EINVAL;
932 if (essid->flags == 1) {
933 if (essid->length > IW_ESSID_MAX_SIZE)
934 return -E2BIG;
936 if (copy_from_user(&EssidBuf, essid->pointer, essid->length))
937 return -EFAULT;
939 EssidBuf[essid->length] = '\0';
940 /* printk("siwessid - Set Essid : %s\n",EssidBuf); */
941 /* printk("siwessid - Essid Len : %d\n",essid->length); */
942 /* printk("siwessid - Essid Flag : %x\n",essid->flags); */
943 if (macp->DeviceOpened == 1) {
944 zfiWlanSetSSID(dev, EssidBuf, strlen(EssidBuf));
945 zfiWlanSetFrequency(dev, zfiWlanQueryFrequency(dev),
946 FALSE);
947 zfiWlanSetEncryMode(dev, zfiWlanQueryEncryMode(dev));
948 /* u8_t wpaieLen,wpaie[50]; */
949 /* zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen); */
950 zfiWlanDisable(dev, 0);
951 zfiWlanEnable(dev);
952 /* if (wpaieLen > 2) */
953 /* zfiWlanSetWpaIe(dev, wpaie, wpaieLen); */
957 return 0;
960 int usbdrvwext_giwessid(struct net_device *dev,
961 struct iw_request_info *info,
962 struct iw_point *essid, char *extra)
964 struct usbdrv_private *macp = dev->ml_priv;
965 u8_t EssidLen;
966 char EssidBuf[IW_ESSID_MAX_SIZE + 1];
967 int ssid_len;
969 if (!netif_running(dev))
970 return -EINVAL;
972 if (macp->DeviceOpened != 1)
973 return 0;
975 zfiWlanQuerySSID(dev, &EssidBuf[0], &EssidLen);
977 /* Convert type from unsigned char to char */
978 ssid_len = (int)EssidLen;
980 /* Make sure the essid length is not greater than IW_ESSID_MAX_SIZE */
981 if (ssid_len > IW_ESSID_MAX_SIZE)
982 ssid_len = IW_ESSID_MAX_SIZE;
984 EssidBuf[ssid_len] = '\0';
986 essid->flags = 1;
987 essid->length = strlen(EssidBuf);
989 memcpy(extra, EssidBuf, essid->length);
990 /* wireless.c in Kernel would handle copy_to_user -- line 679 */
991 /* if (essid->pointer) {
992 * if (copy_to_user(essid->pointer, EssidBuf, essid->length)) {
993 * printk("giwessid - copy_to_user Fail\n");
994 * return -EFAULT;
999 return 0;
1002 int usbdrvwext_siwnickn(struct net_device *dev,
1003 struct iw_request_info *info,
1004 struct iw_point *data, char *nickname)
1006 /* Exist but junk--CWYang(+) */
1007 return 0;
1010 int usbdrvwext_giwnickn(struct net_device *dev,
1011 struct iw_request_info *info,
1012 struct iw_point *data, char *nickname)
1014 struct usbdrv_private *macp = dev->ml_priv;
1015 u8_t EssidLen;
1016 char EssidBuf[IW_ESSID_MAX_SIZE + 1];
1018 if (macp->DeviceOpened != 1)
1019 return 0;
1021 zfiWlanQuerySSID(dev, &EssidBuf[0], &EssidLen);
1022 EssidBuf[EssidLen] = 0;
1024 data->flags = 1;
1025 data->length = strlen(EssidBuf);
1027 memcpy(nickname, EssidBuf, data->length);
1029 return 0;
1032 int usbdrvwext_siwrate(struct net_device *dev,
1033 struct iw_request_info *info,
1034 struct iw_param *frq, char *extra)
1036 struct usbdrv_private *macp = dev->ml_priv;
1037 /* Array to Define Rate Number that Send to Driver */
1038 u16_t zcIndextoRateBG[16] = {1000, 2000, 5500, 11000, 0, 0, 0, 0,
1039 48000, 24000, 12000, 6000, 54000, 36000, 18000, 9000};
1040 u16_t zcRateToMCS[] = {0xff, 0, 1, 2, 3, 0xb, 0xf, 0xa, 0xe, 0x9, 0xd,
1041 0x8, 0xc};
1042 u8_t i, RateIndex = 4;
1043 u16_t RateKbps;
1045 /* printk("frq->disabled : 0x%x\n",frq->disabled); */
1046 /* printk("frq->value : 0x%x\n",frq->value); */
1048 RateKbps = frq->value / 1000;
1049 /* printk("RateKbps : %d\n", RateKbps); */
1050 for (i = 0; i < 16; i++) {
1051 if (RateKbps == zcIndextoRateBG[i])
1052 RateIndex = i;
1055 if (zcIndextoRateBG[RateIndex] == 0)
1056 RateIndex = 0xff;
1057 /* printk("RateIndex : %x\n", RateIndex); */
1058 for (i = 0; i < 13; i++)
1059 if (RateIndex == zcRateToMCS[i])
1060 break;
1061 /* printk("Index : %x\n", i); */
1062 if (RateKbps == 65000) {
1063 RateIndex = 20;
1064 printk(KERN_WARNING "RateIndex : %d\n", RateIndex);
1067 if (macp->DeviceOpened == 1) {
1068 zfiWlanSetTxRate(dev, i);
1069 /* zfiWlanDisable(dev); */
1070 /* zfiWlanEnable(dev); */
1073 return 0;
1076 int usbdrvwext_giwrate(struct net_device *dev,
1077 struct iw_request_info *info,
1078 struct iw_param *frq, char *extra)
1080 struct usbdrv_private *macp = dev->ml_priv;
1082 if (!netif_running(dev))
1083 return -EINVAL;
1085 if (macp->DeviceOpened != 1)
1086 return 0;
1088 frq->fixed = 0;
1089 frq->disabled = 0;
1090 frq->value = zfiWlanQueryRxRate(dev) * 1000;
1092 return 0;
1095 int usbdrvwext_siwrts(struct net_device *dev,
1096 struct iw_request_info *info,
1097 struct iw_param *rts, char *extra)
1099 struct usbdrv_private *macp = dev->ml_priv;
1100 int val = rts->value;
1102 if (macp->DeviceOpened != 1)
1103 return 0;
1105 if (rts->disabled)
1106 val = 2347;
1108 if ((val < 0) || (val > 2347))
1109 return -EINVAL;
1111 zfiWlanSetRtsThreshold(dev, val);
1113 return 0;
1116 int usbdrvwext_giwrts(struct net_device *dev,
1117 struct iw_request_info *info,
1118 struct iw_param *rts, char *extra)
1120 struct usbdrv_private *macp = dev->ml_priv;
1122 if (!netif_running(dev))
1123 return -EINVAL;
1125 if (macp->DeviceOpened != 1)
1126 return 0;
1128 rts->value = zfiWlanQueryRtsThreshold(dev);
1129 rts->disabled = (rts->value >= 2347);
1130 rts->fixed = 1;
1132 return 0;
1135 int usbdrvwext_siwfrag(struct net_device *dev,
1136 struct iw_request_info *info,
1137 struct iw_param *frag, char *extra)
1139 struct usbdrv_private *macp = dev->ml_priv;
1140 u16_t fragThreshold;
1142 if (macp->DeviceOpened != 1)
1143 return 0;
1145 if (frag->disabled)
1146 fragThreshold = 0;
1147 else
1148 fragThreshold = frag->value;
1150 zfiWlanSetFragThreshold(dev, fragThreshold);
1152 return 0;
1155 int usbdrvwext_giwfrag(struct net_device *dev,
1156 struct iw_request_info *info,
1157 struct iw_param *frag, char *extra)
1159 struct usbdrv_private *macp = dev->ml_priv;
1160 u16 val;
1161 unsigned long irqFlag;
1163 if (!netif_running(dev))
1164 return -EINVAL;
1166 if (macp->DeviceOpened != 1)
1167 return 0;
1169 spin_lock_irqsave(&macp->cs_lock, irqFlag);
1171 val = zfiWlanQueryFragThreshold(dev);
1173 frag->value = val;
1175 frag->disabled = (val >= 2346);
1176 frag->fixed = 1;
1178 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
1180 return 0;
1183 int usbdrvwext_siwtxpow(struct net_device *dev,
1184 struct iw_request_info *info,
1185 struct iw_param *rrq, char *extra)
1187 /* Not support yet--CWYng(+) */
1188 return 0;
1191 int usbdrvwext_giwtxpow(struct net_device *dev,
1192 struct iw_request_info *info,
1193 struct iw_param *rrq, char *extra)
1195 /* Not support yet--CWYng(+) */
1196 return 0;
1199 int usbdrvwext_siwretry(struct net_device *dev,
1200 struct iw_request_info *info,
1201 struct iw_param *rrq, char *extra)
1203 /* Do nothing--CWYang(+) */
1204 return 0;
1207 int usbdrvwext_giwretry(struct net_device *dev,
1208 struct iw_request_info *info,
1209 struct iw_param *rrq, char *extra)
1211 /* Do nothing--CWYang(+) */
1212 return 0;
1215 int usbdrvwext_siwencode(struct net_device *dev,
1216 struct iw_request_info *info,
1217 struct iw_point *erq, char *key)
1219 struct zsKeyInfo keyInfo;
1220 int i;
1221 int WepState = ZM_ENCRYPTION_WEP_DISABLED;
1222 struct usbdrv_private *macp = dev->ml_priv;
1224 if (!netif_running(dev))
1225 return -EINVAL;
1227 if ((erq->flags & IW_ENCODE_DISABLED) == 0) {
1228 keyInfo.key = key;
1229 keyInfo.keyLength = erq->length;
1230 keyInfo.keyIndex = (erq->flags & IW_ENCODE_INDEX) - 1;
1231 if (keyInfo.keyIndex >= 4)
1232 keyInfo.keyIndex = 0;
1233 keyInfo.flag = ZM_KEY_FLAG_DEFAULT_KEY;
1235 zfiWlanSetKey(dev, keyInfo);
1236 WepState = ZM_ENCRYPTION_WEP_ENABLED;
1237 } else {
1238 for (i = 1; i < 4; i++)
1239 zfiWlanRemoveKey(dev, 0, i);
1240 WepState = ZM_ENCRYPTION_WEP_DISABLED;
1241 /* zfiWlanSetEncryMode(dev, ZM_NO_WEP); */
1244 if (macp->DeviceOpened == 1) {
1245 zfiWlanSetWepStatus(dev, WepState);
1246 zfiWlanSetFrequency(dev, zfiWlanQueryFrequency(dev), FALSE);
1247 /* zfiWlanSetEncryMode(dev, zfiWlanQueryEncryMode(dev)); */
1248 /* u8_t wpaieLen,wpaie[50]; */
1249 /* zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen); */
1250 zfiWlanDisable(dev, 0);
1251 zfiWlanEnable(dev);
1252 /* if (wpaieLen > 2) */
1253 /* zfiWlanSetWpaIe(dev, wpaie, wpaieLen); */
1256 return 0;
1259 int usbdrvwext_giwencode(struct net_device *dev,
1260 struct iw_request_info *info,
1261 struct iw_point *erq, char *key)
1263 struct usbdrv_private *macp = dev->ml_priv;
1264 u8_t EncryptionMode;
1265 u8_t keyLen = 0;
1267 if (macp->DeviceOpened != 1)
1268 return 0;
1270 EncryptionMode = zfiWlanQueryEncryMode(dev);
1272 if (EncryptionMode)
1273 erq->flags = IW_ENCODE_ENABLED;
1274 else
1275 erq->flags = IW_ENCODE_DISABLED;
1277 /* We can't return the key, so set the proper flag and return zero */
1278 erq->flags |= IW_ENCODE_NOKEY;
1279 memset(key, 0, 16);
1281 /* Copy the key to the user buffer */
1282 switch (EncryptionMode) {
1283 case ZM_WEP64:
1284 keyLen = 5;
1285 break;
1286 case ZM_WEP128:
1287 keyLen = 13;
1288 break;
1289 case ZM_WEP256:
1290 keyLen = 29;
1291 break;
1292 case ZM_AES:
1293 keyLen = 16;
1294 break;
1295 case ZM_TKIP:
1296 keyLen = 32;
1297 break;
1298 #ifdef ZM_ENABLE_CENC
1299 case ZM_CENC:
1300 /* ZM_ENABLE_CENC */
1301 keyLen = 32;
1302 break;
1303 #endif
1304 case ZM_NO_WEP:
1305 keyLen = 0;
1306 break;
1307 default:
1308 keyLen = 0;
1309 printk(KERN_ERR "Unknown EncryMode\n");
1310 break;
1312 erq->length = keyLen;
1314 return 0;
1317 int usbdrvwext_siwpower(struct net_device *dev,
1318 struct iw_request_info *info,
1319 struct iw_param *frq, char *extra)
1321 struct usbdrv_private *macp = dev->ml_priv;
1322 u8_t PSMode;
1324 if (macp->DeviceOpened != 1)
1325 return 0;
1327 if (frq->disabled)
1328 PSMode = ZM_STA_PS_NONE;
1329 else
1330 PSMode = ZM_STA_PS_MAX;
1332 zfiWlanSetPowerSaveMode(dev, PSMode);
1334 return 0;
1337 int usbdrvwext_giwpower(struct net_device *dev,
1338 struct iw_request_info *info,
1339 struct iw_param *frq, char *extra)
1341 unsigned long irqFlag;
1342 struct usbdrv_private *macp = dev->ml_priv;
1344 if (macp->DeviceOpened != 1)
1345 return 0;
1347 spin_lock_irqsave(&macp->cs_lock, irqFlag);
1349 if (zfiWlanQueryPowerSaveMode(dev) == ZM_STA_PS_NONE)
1350 frq->disabled = 1;
1351 else
1352 frq->disabled = 0;
1354 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
1356 return 0;
1359 /*int usbdrvwext_setparam(struct net_device *dev, struct iw_request_info *info,
1360 * void *w, char *extra)
1362 * struct ieee80211vap *vap = dev->ml_priv;
1363 * struct ieee80211com *ic = vap->iv_ic;
1364 * struct ieee80211_rsnparms *rsn = &vap->iv_bss->ni_rsn;
1365 * int *i = (int *) extra;
1366 * int param = i[0]; // parameter id is 1st
1367 * int value = i[1]; // NB: most values are TYPE_INT
1368 * int retv = 0;
1369 * int j, caps;
1370 * const struct ieee80211_authenticator *auth;
1371 * const struct ieee80211_aclator *acl;
1373 * switch (param) {
1374 * case IEEE80211_PARAM_AUTHMODE:
1375 * switch (value) {
1376 * case IEEE80211_AUTH_WPA: // WPA
1377 * case IEEE80211_AUTH_8021X: // 802.1x
1378 * case IEEE80211_AUTH_OPEN: // open
1379 * case IEEE80211_AUTH_SHARED: // shared-key
1380 * case IEEE80211_AUTH_AUTO: // auto
1381 * auth = ieee80211_authenticator_get(value);
1382 * if (auth == NULL)
1383 * return -EINVAL;
1384 * break;
1385 * default:
1386 * return -EINVAL;
1388 * switch (value) {
1389 * case IEEE80211_AUTH_WPA: // WPA w/ 802.1x
1390 * vap->iv_flags |= IEEE80211_F_PRIVACY;
1391 * value = IEEE80211_AUTH_8021X;
1392 * break;
1393 * case IEEE80211_AUTH_OPEN: // open
1394 * vap->iv_flags &= ~(IEEE80211_F_WPA | IEEE80211_F_PRIVACY);
1395 * break;
1396 * case IEEE80211_AUTH_SHARED: // shared-key
1397 * case IEEE80211_AUTH_AUTO: // auto
1398 * case IEEE80211_AUTH_8021X: // 802.1x
1399 * vap->iv_flags &= ~IEEE80211_F_WPA;
1400 * // both require a key so mark the PRIVACY capability
1401 * vap->iv_flags |= IEEE80211_F_PRIVACY;
1402 * break;
1404 * // NB: authenticator attach/detach happens on state change
1405 * vap->iv_bss->ni_authmode = value;
1406 * // XXX mixed/mode/usage?
1407 * vap->iv_auth = auth;
1408 * retv = ENETRESET;
1409 * break;
1410 * case IEEE80211_PARAM_PROTMODE:
1411 * if (value > IEEE80211_PROT_RTSCTS)
1412 * return -EINVAL;
1413 * ic->ic_protmode = value;
1414 * // NB: if not operating in 11g this can wait
1415 * if (ic->ic_bsschan != IEEE80211_CHAN_ANYC &&
1416 * IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan))
1417 * retv = ENETRESET;
1418 * break;
1419 * case IEEE80211_PARAM_MCASTCIPHER:
1420 * if ((vap->iv_caps & cipher2cap(value)) == 0 &&
1421 * !ieee80211_crypto_available(value))
1422 * return -EINVAL;
1423 * rsn->rsn_mcastcipher = value;
1424 * if (vap->iv_flags & IEEE80211_F_WPA)
1425 * retv = ENETRESET;
1426 * break;
1427 * case IEEE80211_PARAM_MCASTKEYLEN:
1428 * if (!(0 < value && value < IEEE80211_KEYBUF_SIZE))
1429 * return -EINVAL;
1430 * // XXX no way to verify driver capability
1431 * rsn->rsn_mcastkeylen = value;
1432 * if (vap->iv_flags & IEEE80211_F_WPA)
1433 * retv = ENETRESET;
1434 * break;
1435 * case IEEE80211_PARAM_UCASTCIPHERS:
1437 * // Convert cipher set to equivalent capabilities.
1438 * // NB: this logic intentionally ignores unknown and
1439 * // unsupported ciphers so folks can specify 0xff or
1440 * // similar and get all available ciphers.
1442 * caps = 0;
1443 * for (j = 1; j < 32; j++) // NB: skip WEP
1444 * if ((value & (1<<j)) &&
1445 * ((vap->iv_caps & cipher2cap(j)) ||
1446 * ieee80211_crypto_available(j)))
1447 * caps |= 1<<j;
1448 * if (caps == 0) // nothing available
1449 * return -EINVAL;
1450 * // XXX verify ciphers ok for unicast use?
1451 * // XXX disallow if running as it'll have no effect
1452 * rsn->rsn_ucastcipherset = caps;
1453 * if (vap->iv_flags & IEEE80211_F_WPA)
1454 * retv = ENETRESET;
1455 * break;
1456 * case IEEE80211_PARAM_UCASTCIPHER:
1457 * if ((rsn->rsn_ucastcipherset & cipher2cap(value)) == 0)
1458 * return -EINVAL;
1459 * rsn->rsn_ucastcipher = value;
1460 * break;
1461 * case IEEE80211_PARAM_UCASTKEYLEN:
1462 * if (!(0 < value && value < IEEE80211_KEYBUF_SIZE))
1463 * return -EINVAL;
1464 * // XXX no way to verify driver capability
1465 * rsn->rsn_ucastkeylen = value;
1466 * break;
1467 * case IEEE80211_PARAM_KEYMGTALGS:
1468 * // XXX check
1469 * rsn->rsn_keymgmtset = value;
1470 * if (vap->iv_flags & IEEE80211_F_WPA)
1471 * retv = ENETRESET;
1472 * break;
1473 * case IEEE80211_PARAM_RSNCAPS:
1474 * // XXX check
1475 * rsn->rsn_caps = value;
1476 * if (vap->iv_flags & IEEE80211_F_WPA)
1477 * retv = ENETRESET;
1478 * break;
1479 * case IEEE80211_PARAM_WPA:
1480 * if (value > 3)
1481 * return -EINVAL;
1482 * // XXX verify ciphers available
1483 * vap->iv_flags &= ~IEEE80211_F_WPA;
1484 * switch (value) {
1485 * case 1:
1486 * vap->iv_flags |= IEEE80211_F_WPA1;
1487 * break;
1488 * case 2:
1489 * vap->iv_flags |= IEEE80211_F_WPA2;
1490 * break;
1491 * case 3:
1492 * vap->iv_flags |= IEEE80211_F_WPA1 | IEEE80211_F_WPA2;
1493 * break;
1495 * retv = ENETRESET; // XXX?
1496 * break;
1497 * case IEEE80211_PARAM_ROAMING:
1498 * if (!(IEEE80211_ROAMING_DEVICE <= value &&
1499 * value <= IEEE80211_ROAMING_MANUAL))
1500 * return -EINVAL;
1501 * ic->ic_roaming = value;
1502 * break;
1503 * case IEEE80211_PARAM_PRIVACY:
1504 * if (value) {
1505 * // XXX check for key state?
1506 * vap->iv_flags |= IEEE80211_F_PRIVACY;
1507 * } else
1508 * vap->iv_flags &= ~IEEE80211_F_PRIVACY;
1509 * break;
1510 * case IEEE80211_PARAM_DROPUNENCRYPTED:
1511 * if (value)
1512 * vap->iv_flags |= IEEE80211_F_DROPUNENC;
1513 * else
1514 * vap->iv_flags &= ~IEEE80211_F_DROPUNENC;
1515 * break;
1516 * case IEEE80211_PARAM_COUNTERMEASURES:
1517 * if (value) {
1518 * if ((vap->iv_flags & IEEE80211_F_WPA) == 0)
1519 * return -EINVAL;
1520 * vap->iv_flags |= IEEE80211_F_COUNTERM;
1521 * } else
1522 * vap->iv_flags &= ~IEEE80211_F_COUNTERM;
1523 * break;
1524 * case IEEE80211_PARAM_DRIVER_CAPS:
1525 * vap->iv_caps = value; // NB: for testing
1526 * break;
1527 * case IEEE80211_PARAM_MACCMD:
1528 * acl = vap->iv_acl;
1529 * switch (value) {
1530 * case IEEE80211_MACCMD_POLICY_OPEN:
1531 * case IEEE80211_MACCMD_POLICY_ALLOW:
1532 * case IEEE80211_MACCMD_POLICY_DENY:
1533 * if (acl == NULL) {
1534 * acl = ieee80211_aclator_get("mac");
1535 * if (acl == NULL || !acl->iac_attach(vap))
1536 * return -EINVAL;
1537 * vap->iv_acl = acl;
1539 * acl->iac_setpolicy(vap, value);
1540 * break;
1541 * case IEEE80211_MACCMD_FLUSH:
1542 * if (acl != NULL)
1543 * acl->iac_flush(vap);
1544 * // NB: silently ignore when not in use
1545 * break;
1546 * case IEEE80211_MACCMD_DETACH:
1547 * if (acl != NULL) {
1548 * vap->iv_acl = NULL;
1549 * acl->iac_detach(vap);
1551 * break;
1553 * break;
1554 * case IEEE80211_PARAM_WMM:
1555 * if (ic->ic_caps & IEEE80211_C_WME){
1556 * if (value) {
1557 * vap->iv_flags |= IEEE80211_F_WME;
1558 * *//* XXX needed by ic_reset *//*
1559 * vap->iv_ic->ic_flags |= IEEE80211_F_WME;
1561 * else {
1562 * *//* XXX needed by ic_reset *//*
1563 * vap->iv_flags &= ~IEEE80211_F_WME;
1564 * vap->iv_ic->ic_flags &= ~IEEE80211_F_WME;
1566 * retv = ENETRESET; // Renegotiate for capabilities
1568 * break;
1569 * case IEEE80211_PARAM_HIDESSID:
1570 * if (value)
1571 * vap->iv_flags |= IEEE80211_F_HIDESSID;
1572 * else
1573 * vap->iv_flags &= ~IEEE80211_F_HIDESSID;
1574 * retv = ENETRESET;
1575 * break;
1576 * case IEEE80211_PARAM_APBRIDGE:
1577 * if (value == 0)
1578 * vap->iv_flags |= IEEE80211_F_NOBRIDGE;
1579 * else
1580 * vap->iv_flags &= ~IEEE80211_F_NOBRIDGE;
1581 * break;
1582 * case IEEE80211_PARAM_INACT:
1583 * vap->iv_inact_run = value / IEEE80211_INACT_WAIT;
1584 * break;
1585 * case IEEE80211_PARAM_INACT_AUTH:
1586 * vap->iv_inact_auth = value / IEEE80211_INACT_WAIT;
1587 * break;
1588 * case IEEE80211_PARAM_INACT_INIT:
1589 * vap->iv_inact_init = value / IEEE80211_INACT_WAIT;
1590 * break;
1591 * case IEEE80211_PARAM_ABOLT:
1592 * caps = 0;
1594 * // Map abolt settings to capability bits;
1595 * // this also strips unknown/unwanted bits.
1597 * if (value & IEEE80211_ABOLT_TURBO_PRIME)
1598 * caps |= IEEE80211_ATHC_TURBOP;
1599 * if (value & IEEE80211_ABOLT_COMPRESSION)
1600 * caps |= IEEE80211_ATHC_COMP;
1601 * if (value & IEEE80211_ABOLT_FAST_FRAME)
1602 * caps |= IEEE80211_ATHC_FF;
1603 * if (value & IEEE80211_ABOLT_XR)
1604 * caps |= IEEE80211_ATHC_XR;
1605 * if (value & IEEE80211_ABOLT_AR)
1606 * caps |= IEEE80211_ATHC_AR;
1607 * if (value & IEEE80211_ABOLT_BURST)
1608 * caps |= IEEE80211_ATHC_BURST;
1609 * if (value & IEEE80211_ABOLT_WME_ELE)
1610 * caps |= IEEE80211_ATHC_WME;
1611 * // verify requested capabilities are supported
1612 * if ((caps & ic->ic_ath_cap) != caps)
1613 * return -EINVAL;
1614 * if (vap->iv_ath_cap != caps) {
1615 * if ((vap->iv_ath_cap ^ caps) & IEEE80211_ATHC_TURBOP) {
1616 * if (ieee80211_set_turbo(dev,
1617 * caps & IEEE80211_ATHC_TURBOP))
1618 * return -EINVAL;
1619 * ieee80211_scan_flush(ic);
1621 * vap->iv_ath_cap = caps;
1622 * ic->ic_athcapsetup(vap->iv_ic, vap->iv_ath_cap);
1623 * retv = ENETRESET;
1625 * break;
1626 * case IEEE80211_PARAM_DTIM_PERIOD:
1627 * if (vap->iv_opmode != IEEE80211_M_HOSTAP &&
1628 * vap->iv_opmode != IEEE80211_M_IBSS)
1629 * return -EINVAL;
1630 * if (IEEE80211_DTIM_MIN <= value &&
1631 * value <= IEEE80211_DTIM_MAX) {
1632 * vap->iv_dtim_period = value;
1633 * retv = ENETRESET; // requires restart
1634 * } else
1635 * retv = EINVAL;
1636 * break;
1637 * case IEEE80211_PARAM_BEACON_INTERVAL:
1638 * if (vap->iv_opmode != IEEE80211_M_HOSTAP &&
1639 * vap->iv_opmode != IEEE80211_M_IBSS)
1640 * return -EINVAL;
1641 * if (IEEE80211_BINTVAL_MIN <= value &&
1642 * value <= IEEE80211_BINTVAL_MAX) {
1643 * ic->ic_lintval = value; // XXX multi-bss
1644 * retv = ENETRESET; // requires restart
1645 * } else
1646 * retv = EINVAL;
1647 * break;
1648 * case IEEE80211_PARAM_DOTH:
1649 * if (value) {
1650 * ic->ic_flags |= IEEE80211_F_DOTH;
1652 * else
1653 * ic->ic_flags &= ~IEEE80211_F_DOTH;
1654 * retv = ENETRESET; // XXX: need something this drastic?
1655 * break;
1656 * case IEEE80211_PARAM_PWRTARGET:
1657 * ic->ic_curchanmaxpwr = value;
1658 * break;
1659 * case IEEE80211_PARAM_GENREASSOC:
1660 * IEEE80211_SEND_MGMT(vap->iv_bss,
1661 * IEEE80211_FC0_SUBTYPE_REASSOC_REQ, 0);
1662 * break;
1663 * case IEEE80211_PARAM_COMPRESSION:
1664 * retv = ieee80211_setathcap(vap, IEEE80211_ATHC_COMP, value);
1665 * break;
1666 * case IEEE80211_PARAM_WMM_AGGRMODE:
1667 * retv = ieee80211_setathcap(vap, IEEE80211_ATHC_WME, value);
1668 * break;
1669 * case IEEE80211_PARAM_FF:
1670 * retv = ieee80211_setathcap(vap, IEEE80211_ATHC_FF, value);
1671 * break;
1672 * case IEEE80211_PARAM_TURBO:
1673 * retv = ieee80211_setathcap(vap, IEEE80211_ATHC_TURBOP, value);
1674 * if (retv == ENETRESET) {
1675 * if(ieee80211_set_turbo(dev,value))
1676 * return -EINVAL;
1677 * ieee80211_scan_flush(ic);
1679 * break;
1680 * case IEEE80211_PARAM_XR:
1681 * retv = ieee80211_setathcap(vap, IEEE80211_ATHC_XR, value);
1682 * break;
1683 * case IEEE80211_PARAM_BURST:
1684 * retv = ieee80211_setathcap(vap, IEEE80211_ATHC_BURST, value);
1685 * break;
1686 * case IEEE80211_PARAM_AR:
1687 * retv = ieee80211_setathcap(vap, IEEE80211_ATHC_AR, value);
1688 * break;
1689 * case IEEE80211_PARAM_PUREG:
1690 * if (value)
1691 * vap->iv_flags |= IEEE80211_F_PUREG;
1692 * else
1693 * vap->iv_flags &= ~IEEE80211_F_PUREG;
1694 * // NB: reset only if we're operating on an 11g channel
1695 * if (ic->ic_bsschan != IEEE80211_CHAN_ANYC &&
1696 * IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan))
1697 * retv = ENETRESET;
1698 * break;
1699 * case IEEE80211_PARAM_WDS:
1700 * if (value)
1701 * vap->iv_flags_ext |= IEEE80211_FEXT_WDS;
1702 * else
1703 * vap->iv_flags_ext &= ~IEEE80211_FEXT_WDS;
1704 * break;
1705 * case IEEE80211_PARAM_BGSCAN:
1706 * if (value) {
1707 * if ((vap->iv_caps & IEEE80211_C_BGSCAN) == 0)
1708 * return -EINVAL;
1709 * vap->iv_flags |= IEEE80211_F_BGSCAN;
1710 * } else {
1711 * // XXX racey?
1712 * vap->iv_flags &= ~IEEE80211_F_BGSCAN;
1713 * ieee80211_cancel_scan(vap); // anything current
1715 * break;
1716 * case IEEE80211_PARAM_BGSCAN_IDLE:
1717 * if (value >= IEEE80211_BGSCAN_IDLE_MIN)
1718 * vap->iv_bgscanidle = value*HZ/1000;
1719 * else
1720 * retv = EINVAL;
1721 * break;
1722 * case IEEE80211_PARAM_BGSCAN_INTERVAL:
1723 * if (value >= IEEE80211_BGSCAN_INTVAL_MIN)
1724 * vap->iv_bgscanintvl = value*HZ;
1725 * else
1726 * retv = EINVAL;
1727 * break;
1728 * case IEEE80211_PARAM_MCAST_RATE:
1729 * // units are in KILObits per second
1730 * if (value >= 256 && value <= 54000)
1731 * vap->iv_mcast_rate = value;
1732 * else
1733 * retv = EINVAL;
1734 * break;
1735 * case IEEE80211_PARAM_COVERAGE_CLASS:
1736 * if (value >= 0 && value <= IEEE80211_COVERAGE_CLASS_MAX) {
1737 * ic->ic_coverageclass = value;
1738 * if (IS_UP_AUTO(vap))
1739 * ieee80211_new_state(vap, IEEE80211_S_SCAN, 0);
1740 * retv = 0;
1742 * else
1743 * retv = EINVAL;
1744 * break;
1745 * case IEEE80211_PARAM_COUNTRY_IE:
1746 * if (value)
1747 * ic->ic_flags_ext |= IEEE80211_FEXT_COUNTRYIE;
1748 * else
1749 * ic->ic_flags_ext &= ~IEEE80211_FEXT_COUNTRYIE;
1750 * retv = ENETRESET;
1751 * break;
1752 * case IEEE80211_PARAM_REGCLASS:
1753 * if (value)
1754 * ic->ic_flags_ext |= IEEE80211_FEXT_REGCLASS;
1755 * else
1756 * ic->ic_flags_ext &= ~IEEE80211_FEXT_REGCLASS;
1757 * retv = ENETRESET;
1758 * break;
1759 * case IEEE80211_PARAM_SCANVALID:
1760 * vap->iv_scanvalid = value*HZ;
1761 * break;
1762 * case IEEE80211_PARAM_ROAM_RSSI_11A:
1763 * vap->iv_roam.rssi11a = value;
1764 * break;
1765 * case IEEE80211_PARAM_ROAM_RSSI_11B:
1766 * vap->iv_roam.rssi11bOnly = value;
1767 * break;
1768 * case IEEE80211_PARAM_ROAM_RSSI_11G:
1769 * vap->iv_roam.rssi11b = value;
1770 * break;
1771 * case IEEE80211_PARAM_ROAM_RATE_11A:
1772 * vap->iv_roam.rate11a = value;
1773 * break;
1774 * case IEEE80211_PARAM_ROAM_RATE_11B:
1775 * vap->iv_roam.rate11bOnly = value;
1776 * break;
1777 * case IEEE80211_PARAM_ROAM_RATE_11G:
1778 * vap->iv_roam.rate11b = value;
1779 * break;
1780 * case IEEE80211_PARAM_UAPSDINFO:
1781 * if (vap->iv_opmode == IEEE80211_M_HOSTAP) {
1782 * if (ic->ic_caps & IEEE80211_C_UAPSD) {
1783 * if (value)
1784 * IEEE80211_VAP_UAPSD_ENABLE(vap);
1785 * else
1786 * IEEE80211_VAP_UAPSD_DISABLE(vap);
1787 * retv = ENETRESET;
1790 * else if (vap->iv_opmode == IEEE80211_M_STA) {
1791 * vap->iv_uapsdinfo = value;
1792 * IEEE80211_VAP_UAPSD_ENABLE(vap);
1793 * retv = ENETRESET;
1795 * break;
1796 * case IEEE80211_PARAM_SLEEP:
1797 * // XXX: Forced sleep for testing. Does not actually place the
1798 * // HW in sleep mode yet. this only makes sense for STAs.
1800 * if (value) {
1801 * // goto sleep
1802 * IEEE80211_VAP_GOTOSLEEP(vap);
1804 * else {
1805 * // wakeup
1806 * IEEE80211_VAP_WAKEUP(vap);
1808 * ieee80211_send_nulldata(ieee80211_ref_node(vap->iv_bss));
1809 * break;
1810 * case IEEE80211_PARAM_QOSNULL:
1811 * // Force a QoS Null for testing.
1812 * ieee80211_send_qosnulldata(vap->iv_bss, value);
1813 * break;
1814 * case IEEE80211_PARAM_PSPOLL:
1815 * // Force a PS-POLL for testing.
1816 * ieee80211_send_pspoll(vap->iv_bss);
1817 * break;
1818 * case IEEE80211_PARAM_EOSPDROP:
1819 * if (vap->iv_opmode == IEEE80211_M_HOSTAP) {
1820 * if (value) IEEE80211_VAP_EOSPDROP_ENABLE(vap);
1821 * else IEEE80211_VAP_EOSPDROP_DISABLE(vap);
1823 * break;
1824 * case IEEE80211_PARAM_MARKDFS:
1825 * if (value)
1826 * ic->ic_flags_ext |= IEEE80211_FEXT_MARKDFS;
1827 * else
1828 * ic->ic_flags_ext &= ~IEEE80211_FEXT_MARKDFS;
1829 * break;
1830 * case IEEE80211_PARAM_CHANBW:
1831 * switch (value) {
1832 * case 0:
1833 * ic->ic_chanbwflag = 0;
1834 * break;
1835 * case 1:
1836 * ic->ic_chanbwflag = IEEE80211_CHAN_HALF;
1837 * break;
1838 * case 2:
1839 * ic->ic_chanbwflag = IEEE80211_CHAN_QUARTER;
1840 * break;
1841 * default:
1842 * retv = EINVAL;
1843 * break;
1845 * break;
1846 * case IEEE80211_PARAM_SHORTPREAMBLE:
1847 * if (value) {
1848 * ic->ic_caps |= IEEE80211_C_SHPREAMBLE;
1849 * } else {
1850 * ic->ic_caps &= ~IEEE80211_C_SHPREAMBLE;
1852 * retv = ENETRESET;
1853 * break;
1854 * default:
1855 * retv = EOPNOTSUPP;
1856 * break;
1858 * // XXX should any of these cause a rescan?
1859 * if (retv == ENETRESET)
1860 * retv = IS_UP_AUTO(vap) ? ieee80211_open(vap->iv_dev) : 0;
1861 * return -retv;
1865 int usbdrvwext_setmode(struct net_device *dev, struct iw_request_info *info,
1866 void *w, char *extra)
1868 return 0;
1871 int usbdrvwext_getmode(struct net_device *dev, struct iw_request_info *info,
1872 void *w, char *extra)
1874 /* struct usbdrv_private *macp = dev->ml_priv; */
1875 struct iw_point *wri = (struct iw_point *)extra;
1876 char mode[8];
1878 strcpy(mode, "11g");
1879 return copy_to_user(wri->pointer, mode, 6) ? -EFAULT : 0;
1882 int zfLnxPrivateIoctl(struct net_device *dev, struct zdap_ioctl* zdreq)
1884 /* void* regp = macp->regp; */
1885 u16_t cmd;
1886 /* u32_t temp; */
1887 u32_t *p;
1888 u32_t i;
1890 cmd = zdreq->cmd;
1891 switch (cmd) {
1892 case ZM_IOCTL_REG_READ:
1893 zfiDbgReadReg(dev, zdreq->addr);
1894 break;
1895 case ZM_IOCTL_REG_WRITE:
1896 zfiDbgWriteReg(dev, zdreq->addr, zdreq->value);
1897 break;
1898 case ZM_IOCTL_MEM_READ:
1899 p = (u32_t *) bus_to_virt(zdreq->addr);
1900 printk(KERN_WARNING
1901 "usbdrv: read memory addr: 0x%08x value:"
1902 " 0x%08x\n", zdreq->addr, *p);
1903 break;
1904 case ZM_IOCTL_MEM_WRITE:
1905 p = (u32_t *) bus_to_virt(zdreq->addr);
1906 *p = zdreq->value;
1907 printk(KERN_WARNING
1908 "usbdrv : write value : 0x%08x to memory addr :"
1909 " 0x%08x\n", zdreq->value, zdreq->addr);
1910 break;
1911 case ZM_IOCTL_TALLY:
1912 zfiWlanShowTally(dev);
1913 if (zdreq->addr)
1914 zfiWlanResetTally(dev);
1915 break;
1916 case ZM_IOCTL_TEST:
1917 printk(KERN_WARNING
1918 "ZM_IOCTL_TEST:len=%d\n", zdreq->addr);
1919 /* zfiWlanReadReg(dev, 0x10f400); */
1920 /* zfiWlanReadReg(dev, 0x10f404); */
1921 printk(KERN_WARNING "IOCTL TEST\n");
1922 #if 1
1923 /* print packet */
1924 for (i = 0; i < zdreq->addr; i++) {
1925 if ((i&0x7) == 0)
1926 printk(KERN_WARNING "\n");
1927 printk(KERN_WARNING "%02X ",
1928 (unsigned char)zdreq->data[i]);
1930 printk(KERN_WARNING "\n");
1931 #endif
1933 /* For Test?? 1 to 0 by CWYang(-) */
1934 #if 0
1935 struct sk_buff *s;
1937 /* Allocate a skb */
1938 s = alloc_skb(2000, GFP_ATOMIC);
1940 /* Copy data to skb */
1941 for (i = 0; i < zdreq->addr; i++)
1942 s->data[i] = zdreq->data[i];
1943 s->len = zdreq->addr;
1945 /* Call zfIdlRecv() */
1946 zfiRecv80211(dev, s, NULL);
1947 #endif
1948 break;
1949 /************************* ZDCONFIG ***************************/
1950 case ZM_IOCTL_FRAG:
1951 zfiWlanSetFragThreshold(dev, zdreq->addr);
1952 break;
1953 case ZM_IOCTL_RTS:
1954 zfiWlanSetRtsThreshold(dev, zdreq->addr);
1955 break;
1956 case ZM_IOCTL_SCAN:
1957 zfiWlanScan(dev);
1958 break;
1959 case ZM_IOCTL_KEY: {
1960 u8_t key[29];
1961 struct zsKeyInfo keyInfo;
1962 u32_t i;
1964 for (i = 0; i < 29; i++)
1965 key[i] = 0;
1967 for (i = 0; i < zdreq->addr; i++)
1968 key[i] = zdreq->data[i];
1970 printk(KERN_WARNING
1971 "key len=%d, key=%02x%02x%02x%02x%02x...\n",
1972 zdreq->addr, key[0], key[1], key[2], key[3], key[4]);
1974 keyInfo.keyLength = zdreq->addr;
1975 keyInfo.keyIndex = 0;
1976 keyInfo.flag = 0;
1977 keyInfo.key = key;
1978 zfiWlanSetKey(dev, keyInfo);
1980 break;
1981 case ZM_IOCTL_RATE:
1982 zfiWlanSetTxRate(dev, zdreq->addr);
1983 break;
1984 case ZM_IOCTL_ENCRYPTION_MODE:
1985 zfiWlanSetEncryMode(dev, zdreq->addr);
1987 zfiWlanDisable(dev, 0);
1988 zfiWlanEnable(dev);
1989 break;
1990 /* CWYang(+) */
1991 case ZM_IOCTL_SIGNAL_STRENGTH: {
1992 u8_t buffer[2];
1993 zfiWlanQuerySignalInfo(dev, &buffer[0]);
1994 printk(KERN_WARNING
1995 "Current Signal Strength : %02d\n", buffer[0]);
1997 break;
1998 /* CWYang(+) */
1999 case ZM_IOCTL_SIGNAL_QUALITY: {
2000 u8_t buffer[2];
2001 zfiWlanQuerySignalInfo(dev, &buffer[0]);
2002 printk(KERN_WARNING
2003 "Current Signal Quality : %02d\n", buffer[1]);
2005 break;
2006 case ZM_IOCTL_SET_PIBSS_MODE:
2007 if (zdreq->addr == 1)
2008 zfiWlanSetWlanMode(dev, ZM_MODE_PSEUDO);
2009 else
2010 zfiWlanSetWlanMode(dev, ZM_MODE_INFRASTRUCTURE);
2012 zfiWlanDisable(dev, 0);
2013 zfiWlanEnable(dev);
2014 break;
2015 /********************* ZDCONFIG ***********************/
2016 default:
2017 printk(KERN_ERR "usbdrv: error command = %x\n", cmd);
2018 break;
2021 return 0;
2024 int usbdrv_wpa_ioctl(struct net_device *dev, struct athr_wlan_param *zdparm)
2026 int ret = 0;
2027 u8_t bc_addr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2028 u8_t mac_addr[80];
2029 struct zsKeyInfo keyInfo;
2030 struct usbdrv_private *macp = dev->ml_priv;
2031 u16_t vapId = 0;
2032 int ii;
2034 /* zmw_get_wlan_dev(dev); */
2036 switch (zdparm->cmd) {
2037 case ZD_CMD_SET_ENCRYPT_KEY:
2038 /* Set up key information */
2039 keyInfo.keyLength = zdparm->u.crypt.key_len;
2040 keyInfo.keyIndex = zdparm->u.crypt.idx;
2041 if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) {
2042 /* AP Mode */
2043 keyInfo.flag = ZM_KEY_FLAG_AUTHENTICATOR;
2044 } else
2045 keyInfo.flag = 0;
2046 keyInfo.key = zdparm->u.crypt.key;
2047 keyInfo.initIv = zdparm->u.crypt.seq;
2048 keyInfo.macAddr = (u16_t *)zdparm->sta_addr;
2050 /* Identify the MAC address information */
2051 if (memcmp(zdparm->sta_addr, bc_addr, sizeof(bc_addr)) == 0)
2052 keyInfo.flag |= ZM_KEY_FLAG_GK;
2053 else
2054 keyInfo.flag |= ZM_KEY_FLAG_PK;
2056 if (!strcmp(zdparm->u.crypt.alg, "NONE")) {
2057 /* u8_t zero_mac[]={0,0,0,0,0,0}; */
2059 /* Set key length to zero */
2060 keyInfo.keyLength = 0;
2062 /* del group key */
2063 if (zdparm->sta_addr[0] & 1) {
2064 /* if (macp->cardSetting.WPAIeLen==0)
2065 * { 802.1x dynamic WEP
2066 * mDynKeyMode = 0;
2067 * mKeyFormat[0] = 0;
2068 * mPrivacyInvoked[0]=FALSE;
2069 * mCap[0] &= ~CAP_PRIVACY;
2070 * macp->cardSetting.EncryOnOff[0]=0;
2072 * mWpaBcKeyLen = mGkInstalled = 0;
2074 } else {
2075 /* if (memcmp(zero_mac,zdparm->sta_addr, 6)==0)
2077 * mDynKeyMode=0;
2078 * mKeyFormat[0]=0;
2079 * pSetting->DynKeyMode=0;
2080 * pSetting->EncryMode[0]=0;
2081 * mDynKeyMode=0;
2086 printk(KERN_ERR "Set Encryption Type NONE\n");
2087 return ret;
2088 } else if (!strcmp(zdparm->u.crypt.alg, "TKIP")) {
2089 zfiWlanSetEncryMode(dev, ZM_TKIP);
2090 /* //Linux Supplicant will inverse Tx/Rx key
2091 * //So we inverse it back, CWYang(+)
2092 * zfMemoryCopy(&temp[0], &keyInfo.key[16], 8);
2093 * zfMemoryCopy(&keyInfo.key[16], keyInfo.key[24], 8);
2094 * zfMemoryCopy(&keyInfo.key[24], &temp[0], 8);
2095 * u8_t temp;
2096 * int k;
2097 * for (k = 0; k < 8; k++)
2099 * temp = keyInfo.key[16 + k];
2100 * keyInfo.key[16 + k] = keyInfo.key[24 + k];
2101 * keyInfo.key[24 + k] = temp;
2103 * CamEncryType = ZM_TKIP;
2104 * if (idx == 0)
2105 * { // Pairwise key
2106 * mKeyFormat[0] = CamEncryType;
2107 * mDynKeyMode = pSetting->DynKeyMode = DYN_KEY_TKIP;
2110 } else if (!strcmp(zdparm->u.crypt.alg, "CCMP")) {
2111 zfiWlanSetEncryMode(dev, ZM_AES);
2112 /* CamEncryType = ZM_AES;
2113 * if (idx == 0)
2114 * { // Pairwise key
2115 * mKeyFormat[0] = CamEncryType;
2116 * mDynKeyMode = pSetting->DynKeyMode = DYN_KEY_AES;
2119 } else if (!strcmp(zdparm->u.crypt.alg, "WEP")) {
2120 if (keyInfo.keyLength == 5) {
2121 /* WEP 64 */
2122 zfiWlanSetEncryMode(dev, ZM_WEP64);
2123 /* CamEncryType = ZM_WEP64; */
2124 /* tmpDynKeyMode=DYN_KEY_WEP64; */
2125 } else if (keyInfo.keyLength == 13) {
2126 /* keylen=13, WEP 128 */
2127 zfiWlanSetEncryMode(dev, ZM_WEP128);
2128 /* CamEncryType = ZM_WEP128; */
2129 /* tmpDynKeyMode=DYN_KEY_WEP128; */
2130 } else {
2131 zfiWlanSetEncryMode(dev, ZM_WEP256);
2134 /* For Dynamic WEP key (Non-WPA Radius), the key ID range: 0-3
2135 * In WPA/RSN mode, the key ID range: 1-3, usually, a broadcast key.
2136 * For WEP key setting: we set mDynKeyMode and mKeyFormat in following
2137 * case:
2138 * 1. For 802.1x dynamically generated WEP key method.
2139 * 2. For WPA/RSN mode, but key id == 0.
2140 * (But this is an impossible case)
2141 * So, only check case 1.
2142 * if (macp->cardSetting.WPAIeLen==0)
2144 * mKeyFormat[0] = CamEncryType;
2145 * mDynKeyMode = pSetting->DynKeyMode = tmpDynKeyMode;
2146 * mPrivacyInvoked[0]=TRUE;
2147 * mCap[0] |= CAP_PRIVACY;
2148 * macp->cardSetting.EncryOnOff[0]=1;
2153 /* DUMP key context */
2154 /* #ifdef WPA_DEBUG */
2155 if (keyInfo.keyLength > 0) {
2156 printk(KERN_WARNING
2157 "Otus: Key Context:\n");
2158 for (ii = 0; ii < keyInfo.keyLength; ) {
2159 printk(KERN_WARNING
2160 "0x%02x ", keyInfo.key[ii]);
2161 if ((++ii % 16) == 0)
2162 printk(KERN_WARNING "\n");
2164 printk(KERN_WARNING "\n");
2166 /* #endif */
2168 /* Set encrypt mode */
2169 /* zfiWlanSetEncryMode(dev, CamEncryType); */
2170 vapId = zfLnxGetVapId(dev);
2171 if (vapId == 0xffff)
2172 keyInfo.vapId = 0;
2173 else
2174 keyInfo.vapId = vapId + 1;
2175 keyInfo.vapAddr[0] = keyInfo.macAddr[0];
2176 keyInfo.vapAddr[1] = keyInfo.macAddr[1];
2177 keyInfo.vapAddr[2] = keyInfo.macAddr[2];
2179 zfiWlanSetKey(dev, keyInfo);
2181 /* zfiWlanDisable(dev); */
2182 /* zfiWlanEnable(dev); */
2183 break;
2184 case ZD_CMD_SET_MLME:
2185 printk(KERN_ERR "usbdrv_wpa_ioctl: ZD_CMD_SET_MLME\n");
2187 /* Translate STA's address */
2188 sprintf(mac_addr, "%02x:%02x:%02x:%02x:%02x:%02x",
2189 zdparm->sta_addr[0], zdparm->sta_addr[1],
2190 zdparm->sta_addr[2], zdparm->sta_addr[3],
2191 zdparm->sta_addr[4], zdparm->sta_addr[5]);
2193 switch (zdparm->u.mlme.cmd) {
2194 case MLME_STA_DEAUTH:
2195 printk(KERN_WARNING
2196 " -------Call zfiWlanDeauth, reason:%d\n",
2197 zdparm->u.mlme.reason_code);
2198 if (zfiWlanDeauth(dev, (u16_t *) zdparm->sta_addr,
2199 zdparm->u.mlme.reason_code) != 0)
2200 printk(KERN_ERR "Can't deauthencate STA: %s\n",
2201 mac_addr);
2202 else
2203 printk(KERN_ERR "Deauthenticate STA: %s"
2204 "with reason code: %d\n",
2205 mac_addr, zdparm->u.mlme.reason_code);
2206 break;
2207 case MLME_STA_DISASSOC:
2208 printk(KERN_WARNING
2209 " -------Call zfiWlanDeauth, reason:%d\n",
2210 zdparm->u.mlme.reason_code);
2211 if (zfiWlanDeauth(dev, (u16_t *) zdparm->sta_addr,
2212 zdparm->u.mlme.reason_code) != 0)
2213 printk(KERN_ERR "Can't disassociate STA: %s\n",
2214 mac_addr);
2215 else
2216 printk(KERN_ERR "Disassociate STA: %s"
2217 "with reason code: %d\n",
2218 mac_addr, zdparm->u.mlme.reason_code);
2219 break;
2220 default:
2221 printk(KERN_ERR "MLME command: 0x%04x not support\n",
2222 zdparm->u.mlme.cmd);
2223 break;
2226 break;
2227 case ZD_CMD_SCAN_REQ:
2228 printk(KERN_ERR "usbdrv_wpa_ioctl: ZD_CMD_SCAN_REQ\n");
2229 break;
2230 case ZD_CMD_SET_GENERIC_ELEMENT: {
2231 u8_t len, *wpaie;
2232 printk(KERN_ERR "usbdrv_wpa_ioctl:"
2233 " ZD_CMD_SET_GENERIC_ELEMENT\n");
2235 /* Copy the WPA IE
2236 * zm_msg1_mm(ZM_LV_0, "CWY - wpaie Length : ",
2237 * zdparm->u.generic_elem.len);
2239 printk(KERN_ERR "wpaie Length : % d\n",
2240 zdparm->u.generic_elem.len);
2241 if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) {
2242 /* AP Mode */
2243 zfiWlanSetWpaIe(dev, zdparm->u.generic_elem.data,
2244 zdparm->u.generic_elem.len);
2245 } else {
2246 macp->supLen = zdparm->u.generic_elem.len;
2247 memcpy(macp->supIe, zdparm->u.generic_elem.data,
2248 zdparm->u.generic_elem.len);
2250 zfiWlanSetWpaSupport(dev, 1);
2251 /* zfiWlanSetWpaIe(dev, zdparm->u.generic_elem.data,
2252 * zdparm->u.generic_elem.len);
2254 len = zdparm->u.generic_elem.len;
2255 wpaie = zdparm->u.generic_elem.data;
2257 printk(KERN_ERR "wd->ap.wpaLen : % d\n", len);
2259 /* DUMP WPA IE */
2260 for(ii = 0; ii < len;) {
2261 printk(KERN_ERR "0x%02x ", wpaie[ii]);
2263 if((++ii % 16) == 0)
2264 printk(KERN_ERR "\n");
2266 printk(KERN_ERR "\n");
2268 /* #ifdef ZM_HOSTAPD_SUPPORT
2269 * if (wd->wlanMode == ZM_MODE_AP)
2270 * {// Update Beacon FIFO in the next TBTT.
2271 * memcpy(&mWPAIe, pSetting->WPAIe, pSetting->WPAIeLen);
2272 * printk(KERN_ERR "Copy WPA IE into mWPAIe\n");
2274 * #endif
2276 break;
2279 /* #ifdef ZM_HOSTAPD_SUPPORT */
2280 case ZD_CMD_GET_TSC:
2281 printk(KERN_ERR "usbdrv_wpa_ioctl : ZD_CMD_GET_TSC\n");
2282 break;
2283 /* #endif */
2285 default:
2286 printk(KERN_ERR "usbdrv_wpa_ioctl default : 0x%04x\n",
2287 zdparm->cmd);
2288 ret = -EINVAL;
2289 break;
2292 return ret;
2295 #ifdef ZM_ENABLE_CENC
2296 int usbdrv_cenc_ioctl(struct net_device *dev, struct zydas_cenc_param *zdparm)
2298 /* struct usbdrv_private *macp = dev->ml_priv; */
2299 struct zsKeyInfo keyInfo;
2300 u16_t apId;
2301 u8_t bc_addr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2302 int ret = 0;
2303 int ii;
2305 /* Get the AP Id */
2306 apId = zfLnxGetVapId(dev);
2308 if (apId == 0xffff) {
2309 apId = 0;
2310 } else {
2311 apId = apId + 1;
2314 switch (zdparm->cmd) {
2315 case ZM_CMD_CENC_SETCENC:
2316 printk(KERN_ERR "ZM_CMD_CENC_SETCENC\n");
2317 printk(KERN_ERR "length : % d\n", zdparm->len);
2318 printk(KERN_ERR "policy : % d\n", zdparm->u.info.cenc_policy);
2319 break;
2320 case ZM_CMD_CENC_SETKEY:
2321 /* ret = wai_ioctl_setkey(vap, ioctl_msg); */
2322 printk(KERN_ERR "ZM_CMD_CENC_SETKEY\n");
2324 printk(KERN_ERR "MAC address = ");
2325 for (ii = 0; ii < 6; ii++) {
2326 printk(KERN_ERR "0x%02x ",
2327 zdparm->u.crypt.sta_addr[ii]);
2329 printk(KERN_ERR "\n");
2331 printk(KERN_ERR "Key Index : % d\n", zdparm->u.crypt.keyid);
2332 printk(KERN_ERR "Encryption key = ");
2333 for (ii = 0; ii < 16; ii++) {
2334 printk(KERN_ERR "0x%02x ", zdparm->u.crypt.key[ii]);
2336 printk(KERN_ERR "\n");
2338 printk(KERN_ERR "MIC key = ");
2339 for(ii = 16; ii < ZM_CENC_KEY_SIZE; ii++) {
2340 printk(KERN_ERR "0x%02x ", zdparm->u.crypt.key[ii]);
2342 printk(KERN_ERR "\n");
2344 /* Set up key information */
2345 keyInfo.keyLength = ZM_CENC_KEY_SIZE;
2346 keyInfo.keyIndex = zdparm->u.crypt.keyid;
2347 keyInfo.flag = ZM_KEY_FLAG_AUTHENTICATOR | ZM_KEY_FLAG_CENC;
2348 keyInfo.key = zdparm->u.crypt.key;
2349 keyInfo.macAddr = (u16_t *)zdparm->u.crypt.sta_addr;
2351 /* Identify the MAC address information */
2352 if (memcmp(zdparm->u.crypt.sta_addr, bc_addr,
2353 sizeof(bc_addr)) == 0) {
2354 keyInfo.flag |= ZM_KEY_FLAG_GK;
2355 keyInfo.vapId = apId;
2356 memcpy(keyInfo.vapAddr, dev->dev_addr, ETH_ALEN);
2357 } else {
2358 keyInfo.flag |= ZM_KEY_FLAG_PK;
2361 zfiWlanSetKey(dev, keyInfo);
2363 break;
2364 case ZM_CMD_CENC_REKEY:
2365 /* ret = wai_ioctl_rekey(vap, ioctl_msg); */
2366 printk(KERN_ERR "ZM_CMD_CENC_REKEY\n");
2367 break;
2368 default:
2369 ret = -EOPNOTSUPP;
2370 break;
2373 /* if (retv == ENETRESET) */
2374 /* retv = IS_UP_AUTO(vap) ? ieee80211_open(vap->iv_dev) : 0; */
2376 return ret;
2378 #endif /* ZM_ENABLE_CENC */
2380 int usbdrv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2382 /* struct usbdrv_private *macp; */
2383 /* void *regp; */
2384 struct zdap_ioctl zdreq;
2385 struct iwreq *wrq = (struct iwreq *)ifr;
2386 struct athr_wlan_param zdparm;
2387 struct usbdrv_private *macp = dev->ml_priv;
2389 int err = 0, val = 0;
2390 int changed = 0;
2392 /* regp = macp->regp; */
2394 if (!netif_running(dev))
2395 return -EINVAL;
2397 switch (cmd) {
2398 case SIOCGIWNAME:
2399 strcpy(wrq->u.name, "IEEE 802.11-DS");
2400 break;
2401 case SIOCGIWAP:
2402 err = usbdrvwext_giwap(dev, NULL, &wrq->u.ap_addr, NULL);
2403 break;
2404 case SIOCSIWAP:
2405 err = usbdrvwext_siwap(dev, NULL, &wrq->u.ap_addr, NULL);
2406 break;
2407 case SIOCGIWMODE:
2408 err = usbdrvwext_giwmode(dev, NULL, &wrq->u.mode, NULL);
2409 break;
2410 case SIOCSIWESSID:
2411 printk(KERN_ERR "CWY - usbdrvwext_siwessid\n");
2412 /* err = usbdrv_ioctl_setessid(dev, &wrq->u.essid); */
2413 err = usbdrvwext_siwessid(dev, NULL, &wrq->u.essid, NULL);
2415 if (!err)
2416 changed = 1;
2417 break;
2418 case SIOCGIWESSID:
2419 err = usbdrvwext_giwessid(dev, NULL, &wrq->u.essid, NULL);
2420 break;
2421 case SIOCSIWRTS:
2422 err = usbdrv_ioctl_setrts(dev, &wrq->u.rts);
2423 if (! err)
2424 changed = 1;
2425 break;
2426 /* set_auth */
2427 case SIOCIWFIRSTPRIV + 0x2: {
2428 /* printk("CWY - SIOCIWFIRSTPRIV + 0x2(set_auth)\n"); */
2429 if (!capable(CAP_NET_ADMIN)) {
2430 err = -EPERM;
2431 break;
2433 val = *((int *) wrq->u.name);
2434 if ((val < 0) || (val > 2)) {
2435 err = -EINVAL;
2436 break;
2437 } else {
2438 zfiWlanSetAuthenticationMode(dev, val);
2440 if (macp->DeviceOpened == 1) {
2441 zfiWlanDisable(dev, 0);
2442 zfiWlanEnable(dev);
2445 err = 0;
2446 changed = 1;
2449 break;
2450 /* get_auth */
2451 case SIOCIWFIRSTPRIV + 0x3: {
2452 int AuthMode = ZM_AUTH_MODE_OPEN;
2454 /* printk("CWY - SIOCIWFIRSTPRIV + 0x3(get_auth)\n"); */
2456 if (wrq->u.data.pointer) {
2457 wrq->u.data.flags = 1;
2459 AuthMode = zfiWlanQueryAuthenticationMode(dev, 0);
2460 if (AuthMode == ZM_AUTH_MODE_OPEN) {
2461 wrq->u.data.length = 12;
2463 if (copy_to_user(wrq->u.data.pointer,
2464 "open system", 12)) {
2465 return -EFAULT;
2467 } else if (AuthMode == ZM_AUTH_MODE_SHARED_KEY) {
2468 wrq->u.data.length = 11;
2470 if (copy_to_user(wrq->u.data.pointer,
2471 "shared key", 11)) {
2472 return -EFAULT;
2474 } else if (AuthMode == ZM_AUTH_MODE_AUTO) {
2475 wrq->u.data.length = 10;
2477 if (copy_to_user(wrq->u.data.pointer,
2478 "auto mode", 10)) {
2479 return -EFAULT;
2481 } else {
2482 return -EFAULT;
2486 break;
2487 /* debug command */
2488 case ZDAPIOCTL:
2489 if (copy_from_user(&zdreq, ifr->ifr_data, sizeof(zdreq))) {
2490 printk(KERN_ERR "usbdrv : copy_from_user error\n");
2491 return -EFAULT;
2494 /* printk(KERN_WARNING
2495 * "usbdrv : cmd = % 2x, reg = 0x%04lx,
2496 *value = 0x%08lx\n",
2497 * zdreq.cmd, zdreq.addr, zdreq.value);
2499 zfLnxPrivateIoctl(dev, &zdreq);
2501 err = 0;
2502 break;
2503 case ZD_IOCTL_WPA:
2504 if (copy_from_user(&zdparm, ifr->ifr_data,
2505 sizeof(struct athr_wlan_param))) {
2506 printk(KERN_ERR "usbdrv : copy_from_user error\n");
2507 return -EFAULT;
2510 usbdrv_wpa_ioctl(dev, &zdparm);
2511 err = 0;
2512 break;
2513 case ZD_IOCTL_PARAM: {
2514 int *p;
2515 int op;
2516 int arg;
2518 /* Point to the name field and retrieve the
2519 * op and arg elements.
2521 p = (int *)wrq->u.name;
2522 op = *p++;
2523 arg = *p;
2525 if (op == ZD_PARAM_ROAMING) {
2526 printk(KERN_ERR
2527 "*************ZD_PARAM_ROAMING : % d\n", arg);
2528 /* macp->cardSetting.ap_scan=(U8)arg; */
2530 if (op == ZD_PARAM_PRIVACY) {
2531 printk(KERN_ERR "ZD_IOCTL_PRIVACY : ");
2533 /* Turn on the privacy invoke flag */
2534 if (arg) {
2535 /* mCap[0] |= CAP_PRIVACY; */
2536 /* macp->cardSetting.EncryOnOff[0] = 1; */
2537 printk(KERN_ERR "enable\n");
2539 } else {
2540 /* mCap[0] &= ~CAP_PRIVACY; */
2541 /* macp->cardSetting.EncryOnOff[0] = 0; */
2542 printk(KERN_ERR "disable\n");
2544 /* changed=1; */
2546 if (op == ZD_PARAM_WPA) {
2548 printk(KERN_ERR "ZD_PARAM_WPA : ");
2550 if (arg) {
2551 printk(KERN_ERR "enable\n");
2553 if (zfiWlanQueryWlanMode(dev) != ZM_MODE_AP) {
2554 printk(KERN_ERR "Station Mode\n");
2555 /* zfiWlanQueryWpaIe(dev, (u8_t *)
2556 &wpaIe, &wpalen); */
2557 /* printk("wpaIe : % 2x, % 2x, % 2x\n",
2558 wpaIe[21], wpaIe[22], wpaIe[23]); */
2559 /* printk("rsnIe : % 2x, % 2x, % 2x\n",
2560 wpaIe[17], wpaIe[18], wpaIe[19]); */
2561 if ((macp->supIe[21] == 0x50) &&
2562 (macp->supIe[22] == 0xf2) &&
2563 (macp->supIe[23] == 0x2)) {
2564 printk(KERN_ERR
2565 "wd->sta.authMode = ZM_AUTH_MODE_WPAPSK\n");
2566 /* wd->sta.authMode = ZM_AUTH_MODE_WPAPSK; */
2567 /* wd->ws.authMode = ZM_AUTH_MODE_WPAPSK; */
2568 zfiWlanSetAuthenticationMode(dev,
2569 ZM_AUTH_MODE_WPAPSK);
2570 } else if ((macp->supIe[21] == 0x50) &&
2571 (macp->supIe[22] == 0xf2) &&
2572 (macp->supIe[23] == 0x1)) {
2573 printk(KERN_ERR
2574 "wd->sta.authMode = ZM_AUTH_MODE_WPA\n");
2575 /* wd->sta.authMode = ZM_AUTH_MODE_WPA; */
2576 /* wd->ws.authMode = ZM_AUTH_MODE_WPA; */
2577 zfiWlanSetAuthenticationMode(dev,
2578 ZM_AUTH_MODE_WPA);
2579 } else if ((macp->supIe[17] == 0xf) &&
2580 (macp->supIe[18] == 0xac) &&
2581 (macp->supIe[19] == 0x2))
2583 printk(KERN_ERR
2584 "wd->sta.authMode = ZM_AUTH_MODE_WPA2PSK\n");
2585 /* wd->sta.authMode = ZM_AUTH_MODE_WPA2PSK; */
2586 /* wd->ws.authMode = ZM_AUTH_MODE_WPA2PSK; */
2587 zfiWlanSetAuthenticationMode(dev,
2588 ZM_AUTH_MODE_WPA2PSK);
2589 } else if ((macp->supIe[17] == 0xf) &&
2590 (macp->supIe[18] == 0xac) &&
2591 (macp->supIe[19] == 0x1))
2593 printk(KERN_ERR
2594 "wd->sta.authMode = ZM_AUTH_MODE_WPA2\n");
2595 /* wd->sta.authMode = ZM_AUTH_MODE_WPA2; */
2596 /* wd->ws.authMode = ZM_AUTH_MODE_WPA2; */
2597 zfiWlanSetAuthenticationMode(dev,
2598 ZM_AUTH_MODE_WPA2);
2600 /* WPA or WPAPSK */
2601 if ((macp->supIe[21] == 0x50) ||
2602 (macp->supIe[22] == 0xf2)) {
2603 if (macp->supIe[11] == 0x2) {
2604 printk(KERN_ERR
2605 "wd->sta.wepStatus = ZM_ENCRYPTION_TKIP\n");
2606 /* wd->sta.wepStatus = ZM_ENCRYPTION_TKIP; */
2607 /* wd->ws.wepStatus = ZM_ENCRYPTION_TKIP; */
2608 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_TKIP);
2609 } else {
2610 printk(KERN_ERR
2611 "wd->sta.wepStatus = ZM_ENCRYPTION_AES\n");
2612 /* wd->sta.wepStatus = ZM_ENCRYPTION_AES; */
2613 /* wd->ws.wepStatus = ZM_ENCRYPTION_AES; */
2614 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_AES);
2617 //WPA2 or WPA2PSK
2618 if ((macp->supIe[17] == 0xf) ||
2619 (macp->supIe[18] == 0xac)) {
2620 if (macp->supIe[13] == 0x2) {
2621 printk(KERN_ERR
2622 "wd->sta.wepStatus = ZM_ENCRYPTION_TKIP\n");
2623 /* wd->sta.wepStatus = ZM_ENCRYPTION_TKIP; */
2624 /* wd->ws.wepStatus = ZM_ENCRYPTION_TKIP; */
2625 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_TKIP);
2626 } else {
2627 printk(KERN_ERR
2628 "wd->sta.wepStatus = ZM_ENCRYPTION_AES\n");
2629 /* wd->sta.wepStatus = ZM_ENCRYPTION_AES; */
2630 /* wd->ws.wepStatus = ZM_ENCRYPTION_AES; */
2631 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_AES);
2635 zfiWlanSetWpaSupport(dev, 1);
2636 } else {
2637 /* Reset the WPA related variables */
2638 printk(KERN_ERR "disable\n");
2640 zfiWlanSetWpaSupport(dev, 0);
2641 zfiWlanSetAuthenticationMode(dev, ZM_AUTH_MODE_OPEN);
2642 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_WEP_DISABLED);
2644 /* Now we only set the length in the WPA IE
2645 * field to zero.
2646 *macp->cardSetting.WPAIe[1] = 0;
2651 if (op == ZD_PARAM_COUNTERMEASURES) {
2652 printk(KERN_ERR
2653 "****************ZD_PARAM_COUNTERMEASURES : ");
2655 if(arg) {
2656 /* mCounterMeasureState=1; */
2657 printk(KERN_ERR "enable\n");
2658 } else {
2659 /* mCounterMeasureState=0; */
2660 printk(KERN_ERR "disable\n");
2663 if (op == ZD_PARAM_DROPUNENCRYPTED) {
2664 printk(KERN_ERR "ZD_PARAM_DROPUNENCRYPTED : ");
2666 if(arg) {
2667 printk(KERN_ERR "enable\n");
2668 } else {
2669 printk(KERN_ERR "disable\n");
2672 if (op == ZD_PARAM_AUTH_ALGS) {
2673 printk(KERN_ERR "ZD_PARAM_AUTH_ALGS : ");
2675 if (arg == 0) {
2676 printk(KERN_ERR "OPEN_SYSTEM\n");
2677 } else {
2678 printk(KERN_ERR "SHARED_KEY\n");
2681 if (op == ZD_PARAM_WPS_FILTER) {
2682 printk(KERN_ERR "ZD_PARAM_WPS_FILTER : ");
2684 if (arg) {
2685 /* mCounterMeasureState=1; */
2686 macp->forwardMgmt = 1;
2687 printk(KERN_ERR "enable\n");
2688 } else {
2689 /* mCounterMeasureState=0; */
2690 macp->forwardMgmt = 0;
2691 printk(KERN_ERR "disable\n");
2695 err = 0;
2696 break;
2697 case ZD_IOCTL_GETWPAIE: {
2698 struct ieee80211req_wpaie req_wpaie;
2699 u16_t apId, i, j;
2701 /* Get the AP Id */
2702 apId = zfLnxGetVapId(dev);
2704 if (apId == 0xffff) {
2705 apId = 0;
2706 } else {
2707 apId = apId + 1;
2710 if (copy_from_user(&req_wpaie, ifr->ifr_data,
2711 sizeof(struct ieee80211req_wpaie))) {
2712 printk(KERN_ERR "usbdrv : copy_from_user error\n");
2713 return -EFAULT;
2716 for (i = 0; i < ZM_OAL_MAX_STA_SUPPORT; i++) {
2717 for (j = 0; j < IEEE80211_ADDR_LEN; j++) {
2718 if (macp->stawpaie[i].wpa_macaddr[j] !=
2719 req_wpaie.wpa_macaddr[j])
2720 break;
2722 if (j == 6)
2723 break;
2726 if (i < ZM_OAL_MAX_STA_SUPPORT) {
2727 /* printk("ZD_IOCTL_GETWPAIE - sta index = % d\n", i); */
2728 memcpy(req_wpaie.wpa_ie, macp->stawpaie[i].wpa_ie,
2729 IEEE80211_MAX_IE_SIZE);
2732 if (copy_to_user(wrq->u.data.pointer, &req_wpaie,
2733 sizeof(struct ieee80211req_wpaie))) {
2734 return -EFAULT;
2738 err = 0;
2739 break;
2740 #ifdef ZM_ENABLE_CENC
2741 case ZM_IOCTL_CENC:
2742 if (copy_from_user(&macp->zd_wpa_req, ifr->ifr_data,
2743 sizeof(struct athr_wlan_param))) {
2744 printk(KERN_ERR "usbdrv : copy_from_user error\n");
2745 return -EFAULT;
2748 usbdrv_cenc_ioctl(dev,
2749 (struct zydas_cenc_param *)&macp->zd_wpa_req);
2750 err = 0;
2751 break;
2752 #endif /* ZM_ENABLE_CENC */
2753 default:
2754 err = -EOPNOTSUPP;
2755 break;
2758 return err;