2 * Driver for KeyStream 11b/g wireless LAN
4 * Copyright (C) 2005-2008 KeyStream Corp.
5 * Copyright (C) 2009 Renesas Technology Corp.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/compiler.h>
15 #include <linux/init.h>
16 #include <linux/ioport.h>
17 #include <linux/netdevice.h>
18 #include <linux/etherdevice.h>
19 #include <linux/if_arp.h>
20 #include <linux/rtnetlink.h>
21 #include <linux/delay.h>
22 #include <linux/completion.h>
23 #include <linux/mii.h>
24 #include <linux/pci.h>
25 #include <linux/ctype.h>
26 #include <linux/timer.h>
27 #include <asm/atomic.h>
29 #include <asm/uaccess.h>
31 static int wep_on_off;
33 #define WEP_ON_64BIT 1
34 #define WEP_ON_128BIT 2
37 #include "ks_hostif.h"
38 #include "ks_wlan_ioctl.h"
40 /* Include Wireless Extension definition and check version */
41 #include <linux/wireless.h>
42 #define WIRELESS_SPY /* enable iwspy support */
43 #include <net/iw_handler.h> /* New driver API */
45 /* Frequency list (map channels to frequencies) */
46 static const long frequency_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
47 2447, 2452, 2457, 2462, 2467, 2472, 2484
50 /* A few details needed for WEP (Wireless Equivalent Privacy) */
51 #define MAX_KEY_SIZE 13 /* 128 (?) bits */
52 #define MIN_KEY_SIZE 5 /* 40 bits RC4 - WEP */
53 typedef struct wep_key_t {
55 u8 key[16]; /* 40-bit and 104-bit keys */
58 /* Backward compatibility */
59 #ifndef IW_ENCODE_NOKEY
60 #define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not present */
61 #define IW_ENCODE_MODE (IW_ENCODE_DISABLED | IW_ENCODE_RESTRICTED | IW_ENCODE_OPEN)
62 #endif /* IW_ENCODE_NOKEY */
64 /* List of Wireless Handlers (new API) */
65 static const struct iw_handler_def ks_wlan_handler_def;
67 #define KSC_OPNOTSUPP /* Operation Not Support */
72 static int ks_wlan_open(struct net_device *dev);
73 static void ks_wlan_tx_timeout(struct net_device *dev);
74 static int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev);
75 static int ks_wlan_close(struct net_device *dev);
76 static void ks_wlan_set_multicast_list(struct net_device *dev);
77 static struct net_device_stats *ks_wlan_get_stats(struct net_device *dev);
78 static int ks_wlan_set_mac_address(struct net_device *dev, void *addr);
79 static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq,
82 static atomic_t update_phyinfo;
83 static struct timer_list update_phyinfo_timer;
85 int ks_wlan_update_phy_information(struct ks_wlan_private *priv)
87 struct iw_statistics *wstats = &priv->wstats;
89 DPRINTK(4, "in_interrupt = %ld\n", in_interrupt());
91 if (priv->dev_state < DEVICE_STATE_READY) {
92 return -1; /* not finished initialize */
94 if (atomic_read(&update_phyinfo))
98 wstats->status = priv->reg.operation_mode; /* Operation mode */
100 /* Signal quality and co. But where is the noise level ??? */
101 hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST);
103 /* interruptible_sleep_on_timeout(&priv->confirm_wait, HZ/2); */
104 if (!wait_for_completion_interruptible_timeout
105 (&priv->confirm_wait, HZ / 2)) {
106 DPRINTK(1, "wait time out!!\n");
109 atomic_inc(&update_phyinfo);
110 update_phyinfo_timer.expires = jiffies + HZ; /* 1sec */
111 add_timer(&update_phyinfo_timer);
117 void ks_wlan_update_phyinfo_timeout(unsigned long ptr)
119 DPRINTK(4, "in_interrupt = %ld\n", in_interrupt());
120 atomic_set(&update_phyinfo, 0);
123 int ks_wlan_setup_parameter(struct ks_wlan_private *priv,
124 unsigned int commit_flag)
128 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
130 if (commit_flag & SME_RTS)
131 hostif_sme_enqueue(priv, SME_RTS_THRESHOLD_REQUEST);
132 if (commit_flag & SME_FRAG)
133 hostif_sme_enqueue(priv, SME_FRAGMENTATION_THRESHOLD_REQUEST);
135 if (commit_flag & SME_WEP_INDEX)
136 hostif_sme_enqueue(priv, SME_WEP_INDEX_REQUEST);
137 if (commit_flag & SME_WEP_VAL1)
138 hostif_sme_enqueue(priv, SME_WEP_KEY1_REQUEST);
139 if (commit_flag & SME_WEP_VAL2)
140 hostif_sme_enqueue(priv, SME_WEP_KEY2_REQUEST);
141 if (commit_flag & SME_WEP_VAL3)
142 hostif_sme_enqueue(priv, SME_WEP_KEY3_REQUEST);
143 if (commit_flag & SME_WEP_VAL4)
144 hostif_sme_enqueue(priv, SME_WEP_KEY4_REQUEST);
145 if (commit_flag & SME_WEP_FLAG)
146 hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
148 if (commit_flag & SME_RSN) {
149 hostif_sme_enqueue(priv, SME_RSN_ENABLED_REQUEST);
150 hostif_sme_enqueue(priv, SME_RSN_MODE_REQUEST);
152 if (commit_flag & SME_RSN_MULTICAST)
153 hostif_sme_enqueue(priv, SME_RSN_MCAST_REQUEST);
154 if (commit_flag & SME_RSN_UNICAST)
155 hostif_sme_enqueue(priv, SME_RSN_UCAST_REQUEST);
156 if (commit_flag & SME_RSN_AUTH)
157 hostif_sme_enqueue(priv, SME_RSN_AUTH_REQUEST);
159 hostif_sme_enqueue(priv, SME_MODE_SET_REQUEST);
161 hostif_sme_enqueue(priv, SME_START_REQUEST);
167 * Initial Wireless Extension code for Ks_Wlannet driver by :
168 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00
169 * Conversion to new driver API by :
170 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 26 March 02
171 * Javier also did a good amount of work here, adding some new extensions
172 * and fixing my code. Let's just say that without him this code just
173 * would not work at all... - Jean II
176 /*------------------------------------------------------------------*/
177 /* Wireless Handler : get protocol name */
178 static int ks_wlan_get_name(struct net_device *dev,
179 struct iw_request_info *info, char *cwrq,
182 struct ks_wlan_private *priv =
183 (struct ks_wlan_private *)netdev_priv(dev);
185 if (priv->sleep_mode == SLP_SLEEP) {
189 if (priv->dev_state < DEVICE_STATE_READY) {
190 strcpy(cwrq, "NOT READY!");
191 } else if (priv->reg.phy_type == D_11B_ONLY_MODE) {
192 strcpy(cwrq, "IEEE 802.11b");
193 } else if (priv->reg.phy_type == D_11G_ONLY_MODE) {
194 strcpy(cwrq, "IEEE 802.11g");
196 strcpy(cwrq, "IEEE 802.11b/g");
202 /*------------------------------------------------------------------*/
203 /* Wireless Handler : set frequency */
204 static int ks_wlan_set_freq(struct net_device *dev,
205 struct iw_request_info *info, struct iw_freq *fwrq,
208 struct ks_wlan_private *priv =
209 (struct ks_wlan_private *)netdev_priv(dev);
210 int rc = -EINPROGRESS; /* Call commit handler */
212 if (priv->sleep_mode == SLP_SLEEP) {
217 /* If setting by frequency, convert to a channel */
218 if ((fwrq->e == 1) &&
219 (fwrq->m >= (int)2.412e8) && (fwrq->m <= (int)2.487e8)) {
220 int f = fwrq->m / 100000;
222 while ((c < 14) && (f != frequency_list[c]))
224 /* Hack to fall through... */
228 /* Setting by channel number */
229 if ((fwrq->m > 1000) || (fwrq->e > 0))
232 int channel = fwrq->m;
233 /* We should do a better check than that,
234 * based on the card capability !!! */
235 if ((channel < 1) || (channel > 14)) {
237 "%s: New channel value of %d is invalid!\n",
241 /* Yes ! We can set it !!! */
242 priv->reg.channel = (u8) (channel);
243 priv->need_commit |= SME_MODE_SET;
250 /*------------------------------------------------------------------*/
251 /* Wireless Handler : get frequency */
252 static int ks_wlan_get_freq(struct net_device *dev,
253 struct iw_request_info *info, struct iw_freq *fwrq,
256 struct ks_wlan_private *priv =
257 (struct ks_wlan_private *)netdev_priv(dev);
260 if (priv->sleep_mode == SLP_SLEEP) {
264 if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
265 f = (int)priv->current_ap.channel;
267 f = (int)priv->reg.channel;
268 fwrq->m = frequency_list[f - 1] * 100000;
274 /*------------------------------------------------------------------*/
275 /* Wireless Handler : set ESSID */
276 static int ks_wlan_set_essid(struct net_device *dev,
277 struct iw_request_info *info,
278 struct iw_point *dwrq, char *extra)
280 struct ks_wlan_private *priv =
281 (struct ks_wlan_private *)netdev_priv(dev);
284 DPRINTK(2, " %d\n", dwrq->flags);
286 if (priv->sleep_mode == SLP_SLEEP) {
291 /* Check if we asked for `any' */
292 if (dwrq->flags == 0) {
293 /* Just send an empty SSID list */
294 memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
295 priv->reg.ssid.size = 0;
299 /* iwconfig uses nul termination in SSID.. */
300 if (len > 0 && extra[len - 1] == '\0')
303 /* Check the size of the string */
304 if (len > IW_ESSID_MAX_SIZE) {
308 /* Check the size of the string */
309 if (dwrq->length > IW_ESSID_MAX_SIZE + 1) {
315 memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
318 memcpy(priv->reg.ssid.body, extra, len);
319 priv->reg.ssid.size = len;
321 memcpy(priv->reg.ssid.body, extra, dwrq->length);
322 priv->reg.ssid.size = dwrq->length;
325 /* Write it to the card */
326 priv->need_commit |= SME_MODE_SET;
328 // return -EINPROGRESS; /* Call commit handler */
329 ks_wlan_setup_parameter(priv, priv->need_commit);
330 priv->need_commit = 0;
334 /*------------------------------------------------------------------*/
335 /* Wireless Handler : get ESSID */
336 static int ks_wlan_get_essid(struct net_device *dev,
337 struct iw_request_info *info,
338 struct iw_point *dwrq, char *extra)
340 struct ks_wlan_private *priv =
341 (struct ks_wlan_private *)netdev_priv(dev);
343 if (priv->sleep_mode == SLP_SLEEP) {
348 /* Note : if dwrq->flags != 0, we should
349 * get the relevant SSID from the SSID list... */
350 if (priv->reg.ssid.size) {
351 /* Get the current SSID */
352 memcpy(extra, priv->reg.ssid.body, priv->reg.ssid.size);
354 extra[priv->reg.ssid.size] = '\0';
356 /* If none, we may want to get the one that was set */
360 dwrq->length = priv->reg.ssid.size;
362 dwrq->length = priv->reg.ssid.size + 1;
364 dwrq->flags = 1; /* active */
372 dwrq->flags = 0; /* ANY */
378 /*------------------------------------------------------------------*/
379 /* Wireless Handler : set AP address */
380 static int ks_wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
381 struct sockaddr *ap_addr, char *extra)
383 struct ks_wlan_private *priv =
384 (struct ks_wlan_private *)netdev_priv(dev);
388 if (priv->sleep_mode == SLP_SLEEP) {
392 if (priv->reg.operation_mode == MODE_ADHOC ||
393 priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
394 memcpy(priv->reg.bssid, (u8 *) & ap_addr->sa_data, ETH_ALEN);
396 if (is_valid_ether_addr((u8 *) priv->reg.bssid)) {
397 priv->need_commit |= SME_MODE_SET;
400 eth_zero_addr(priv->reg.bssid);
404 DPRINTK(2, "bssid = %02x:%02x:%02x:%02x:%02x:%02x\n",
405 priv->reg.bssid[0], priv->reg.bssid[1], priv->reg.bssid[2],
406 priv->reg.bssid[3], priv->reg.bssid[4], priv->reg.bssid[5]);
408 /* Write it to the card */
409 if (priv->need_commit) {
410 priv->need_commit |= SME_MODE_SET;
411 return -EINPROGRESS; /* Call commit handler */
416 /*------------------------------------------------------------------*/
417 /* Wireless Handler : get AP address */
418 static int ks_wlan_get_wap(struct net_device *dev, struct iw_request_info *info,
419 struct sockaddr *awrq, char *extra)
421 struct ks_wlan_private *priv =
422 (struct ks_wlan_private *)netdev_priv(dev);
424 if (priv->sleep_mode == SLP_SLEEP) {
428 if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
429 memcpy(awrq->sa_data, &(priv->current_ap.bssid[0]), ETH_ALEN);
431 eth_zero_addr(awrq->sa_data);
434 awrq->sa_family = ARPHRD_ETHER;
439 /*------------------------------------------------------------------*/
440 /* Wireless Handler : set Nickname */
441 static int ks_wlan_set_nick(struct net_device *dev,
442 struct iw_request_info *info, struct iw_point *dwrq,
445 struct ks_wlan_private *priv =
446 (struct ks_wlan_private *)netdev_priv(dev);
448 if (priv->sleep_mode == SLP_SLEEP) {
453 /* Check the size of the string */
454 if (dwrq->length > 16 + 1) {
457 memset(priv->nick, 0, sizeof(priv->nick));
458 memcpy(priv->nick, extra, dwrq->length);
460 return -EINPROGRESS; /* Call commit handler */
463 /*------------------------------------------------------------------*/
464 /* Wireless Handler : get Nickname */
465 static int ks_wlan_get_nick(struct net_device *dev,
466 struct iw_request_info *info, struct iw_point *dwrq,
469 struct ks_wlan_private *priv =
470 (struct ks_wlan_private *)netdev_priv(dev);
472 if (priv->sleep_mode == SLP_SLEEP) {
476 strncpy(extra, priv->nick, 16);
478 dwrq->length = strlen(extra) + 1;
483 /*------------------------------------------------------------------*/
484 /* Wireless Handler : set Bit-Rate */
485 static int ks_wlan_set_rate(struct net_device *dev,
486 struct iw_request_info *info, struct iw_param *vwrq,
489 struct ks_wlan_private *priv =
490 (struct ks_wlan_private *)netdev_priv(dev);
493 if (priv->sleep_mode == SLP_SLEEP) {
497 if (priv->reg.phy_type == D_11B_ONLY_MODE) {
498 if (vwrq->fixed == 1) {
499 switch (vwrq->value) {
502 priv->reg.rate_set.body[0] =
503 (uint8_t) (vwrq->value / 500000);
507 priv->reg.rate_set.body[0] =
508 ((uint8_t) (vwrq->value / 500000)) |
514 priv->reg.tx_rate = TX_RATE_FIXED;
515 priv->reg.rate_set.size = 1;
516 } else { /* vwrq->fixed == 0 */
517 if (vwrq->value > 0) {
518 switch (vwrq->value) {
520 priv->reg.rate_set.body[3] =
524 priv->reg.rate_set.body[2] = TX_RATE_5M;
527 priv->reg.rate_set.body[1] =
528 TX_RATE_2M | BASIC_RATE;
531 priv->reg.rate_set.body[0] =
532 TX_RATE_1M | BASIC_RATE;
538 priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
539 priv->reg.rate_set.size = i;
541 priv->reg.rate_set.body[3] = TX_RATE_11M;
542 priv->reg.rate_set.body[2] = TX_RATE_5M;
543 priv->reg.rate_set.body[1] =
544 TX_RATE_2M | BASIC_RATE;
545 priv->reg.rate_set.body[0] =
546 TX_RATE_1M | BASIC_RATE;
547 priv->reg.tx_rate = TX_RATE_FULL_AUTO;
548 priv->reg.rate_set.size = 4;
551 } else { /* D_11B_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
552 if (vwrq->fixed == 1) {
553 switch (vwrq->value) {
559 priv->reg.rate_set.body[0] =
560 (uint8_t) (vwrq->value / 500000);
569 priv->reg.rate_set.body[0] =
570 ((uint8_t) (vwrq->value / 500000)) |
576 priv->reg.tx_rate = TX_RATE_FIXED;
577 priv->reg.rate_set.size = 1;
578 } else { /* vwrq->fixed == 0 */
579 if (vwrq->value > 0) {
580 switch (vwrq->value) {
582 priv->reg.rate_set.body[11] =
586 priv->reg.rate_set.body[10] =
590 priv->reg.rate_set.body[9] =
599 if (vwrq->value == 24000000) {
600 priv->reg.rate_set.body[8] =
603 priv->reg.rate_set.body[7] =
606 priv->reg.rate_set.body[6] =
607 TX_RATE_24M | BASIC_RATE;
609 priv->reg.rate_set.body[5] =
610 TX_RATE_12M | BASIC_RATE;
612 priv->reg.rate_set.body[4] =
613 TX_RATE_6M | BASIC_RATE;
615 priv->reg.rate_set.body[3] =
616 TX_RATE_11M | BASIC_RATE;
618 } else if (vwrq->value == 18000000) {
619 priv->reg.rate_set.body[7] =
622 priv->reg.rate_set.body[6] =
625 priv->reg.rate_set.body[5] =
626 TX_RATE_12M | BASIC_RATE;
628 priv->reg.rate_set.body[4] =
629 TX_RATE_6M | BASIC_RATE;
631 priv->reg.rate_set.body[3] =
632 TX_RATE_11M | BASIC_RATE;
634 } else if (vwrq->value == 12000000) {
635 priv->reg.rate_set.body[6] =
638 priv->reg.rate_set.body[5] =
639 TX_RATE_12M | BASIC_RATE;
641 priv->reg.rate_set.body[4] =
642 TX_RATE_6M | BASIC_RATE;
644 priv->reg.rate_set.body[3] =
645 TX_RATE_11M | BASIC_RATE;
647 } else if (vwrq->value == 11000000) {
648 priv->reg.rate_set.body[5] =
651 priv->reg.rate_set.body[4] =
652 TX_RATE_6M | BASIC_RATE;
654 priv->reg.rate_set.body[3] =
655 TX_RATE_11M | BASIC_RATE;
657 } else if (vwrq->value == 9000000) {
658 priv->reg.rate_set.body[4] =
661 priv->reg.rate_set.body[3] =
662 TX_RATE_6M | BASIC_RATE;
664 } else { /* vwrq->value == 6000000 */
665 priv->reg.rate_set.body[3] =
666 TX_RATE_6M | BASIC_RATE;
670 priv->reg.rate_set.body[2] =
671 TX_RATE_5M | BASIC_RATE;
674 priv->reg.rate_set.body[1] =
675 TX_RATE_2M | BASIC_RATE;
678 priv->reg.rate_set.body[0] =
679 TX_RATE_1M | BASIC_RATE;
685 priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
686 priv->reg.rate_set.size = i;
688 priv->reg.rate_set.body[11] = TX_RATE_54M;
689 priv->reg.rate_set.body[10] = TX_RATE_48M;
690 priv->reg.rate_set.body[9] = TX_RATE_36M;
691 priv->reg.rate_set.body[8] = TX_RATE_18M;
692 priv->reg.rate_set.body[7] = TX_RATE_9M;
693 priv->reg.rate_set.body[6] =
694 TX_RATE_24M | BASIC_RATE;
695 priv->reg.rate_set.body[5] =
696 TX_RATE_12M | BASIC_RATE;
697 priv->reg.rate_set.body[4] =
698 TX_RATE_6M | BASIC_RATE;
699 priv->reg.rate_set.body[3] =
700 TX_RATE_11M | BASIC_RATE;
701 priv->reg.rate_set.body[2] =
702 TX_RATE_5M | BASIC_RATE;
703 priv->reg.rate_set.body[1] =
704 TX_RATE_2M | BASIC_RATE;
705 priv->reg.rate_set.body[0] =
706 TX_RATE_1M | BASIC_RATE;
707 priv->reg.tx_rate = TX_RATE_FULL_AUTO;
708 priv->reg.rate_set.size = 12;
713 priv->need_commit |= SME_MODE_SET;
715 return -EINPROGRESS; /* Call commit handler */
718 /*------------------------------------------------------------------*/
719 /* Wireless Handler : get Bit-Rate */
720 static int ks_wlan_get_rate(struct net_device *dev,
721 struct iw_request_info *info, struct iw_param *vwrq,
724 struct ks_wlan_private *priv =
725 (struct ks_wlan_private *)netdev_priv(dev);
727 DPRINTK(2, "in_interrupt = %ld update_phyinfo = %d\n",
728 in_interrupt(), atomic_read(&update_phyinfo));
730 if (priv->sleep_mode == SLP_SLEEP) {
734 if (!atomic_read(&update_phyinfo)) {
735 ks_wlan_update_phy_information(priv);
737 vwrq->value = ((priv->current_rate) & RATE_MASK) * 500000;
738 if (priv->reg.tx_rate == TX_RATE_FIXED)
746 /*------------------------------------------------------------------*/
747 /* Wireless Handler : set RTS threshold */
748 static int ks_wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
749 struct iw_param *vwrq, char *extra)
751 struct ks_wlan_private *priv =
752 (struct ks_wlan_private *)netdev_priv(dev);
753 int rthr = vwrq->value;
755 if (priv->sleep_mode == SLP_SLEEP) {
761 if ((rthr < 0) || (rthr > 2347)) {
764 priv->reg.rts = rthr;
765 priv->need_commit |= SME_RTS;
767 return -EINPROGRESS; /* Call commit handler */
770 /*------------------------------------------------------------------*/
771 /* Wireless Handler : get RTS threshold */
772 static int ks_wlan_get_rts(struct net_device *dev, struct iw_request_info *info,
773 struct iw_param *vwrq, char *extra)
775 struct ks_wlan_private *priv =
776 (struct ks_wlan_private *)netdev_priv(dev);
778 if (priv->sleep_mode == SLP_SLEEP) {
782 vwrq->value = priv->reg.rts;
783 vwrq->disabled = (vwrq->value >= 2347);
789 /*------------------------------------------------------------------*/
790 /* Wireless Handler : set Fragmentation threshold */
791 static int ks_wlan_set_frag(struct net_device *dev,
792 struct iw_request_info *info, struct iw_param *vwrq,
795 struct ks_wlan_private *priv =
796 (struct ks_wlan_private *)netdev_priv(dev);
797 int fthr = vwrq->value;
799 if (priv->sleep_mode == SLP_SLEEP) {
805 if ((fthr < 256) || (fthr > 2346)) {
808 fthr &= ~0x1; /* Get an even value - is it really needed ??? */
809 priv->reg.fragment = fthr;
810 priv->need_commit |= SME_FRAG;
812 return -EINPROGRESS; /* Call commit handler */
815 /*------------------------------------------------------------------*/
816 /* Wireless Handler : get Fragmentation threshold */
817 static int ks_wlan_get_frag(struct net_device *dev,
818 struct iw_request_info *info, struct iw_param *vwrq,
821 struct ks_wlan_private *priv =
822 (struct ks_wlan_private *)netdev_priv(dev);
824 if (priv->sleep_mode == SLP_SLEEP) {
828 vwrq->value = priv->reg.fragment;
829 vwrq->disabled = (vwrq->value >= 2346);
835 /*------------------------------------------------------------------*/
836 /* Wireless Handler : set Mode of Operation */
837 static int ks_wlan_set_mode(struct net_device *dev,
838 struct iw_request_info *info, __u32 * uwrq,
841 struct ks_wlan_private *priv =
842 (struct ks_wlan_private *)netdev_priv(dev);
844 DPRINTK(2, "mode=%d\n", *uwrq);
846 if (priv->sleep_mode == SLP_SLEEP) {
852 priv->reg.operation_mode = MODE_ADHOC;
853 priv->need_commit |= SME_MODE_SET;
856 priv->reg.operation_mode = MODE_INFRASTRUCTURE;
857 priv->need_commit |= SME_MODE_SET;
863 case IW_MODE_MONITOR:
868 return -EINPROGRESS; /* Call commit handler */
871 /*------------------------------------------------------------------*/
872 /* Wireless Handler : get Mode of Operation */
873 static int ks_wlan_get_mode(struct net_device *dev,
874 struct iw_request_info *info, __u32 * uwrq,
877 struct ks_wlan_private *priv =
878 (struct ks_wlan_private *)netdev_priv(dev);
880 if (priv->sleep_mode == SLP_SLEEP) {
885 /* If not managed, assume it's ad-hoc */
886 switch (priv->reg.operation_mode) {
887 case MODE_INFRASTRUCTURE:
888 *uwrq = IW_MODE_INFRA;
891 *uwrq = IW_MODE_ADHOC;
894 *uwrq = IW_MODE_ADHOC;
900 /*------------------------------------------------------------------*/
901 /* Wireless Handler : set Encryption Key */
902 static int ks_wlan_set_encode(struct net_device *dev,
903 struct iw_request_info *info,
904 struct iw_point *dwrq, char *extra)
906 struct ks_wlan_private *priv =
907 (struct ks_wlan_private *)netdev_priv(dev);
910 int index = (dwrq->flags & IW_ENCODE_INDEX);
911 int current_index = priv->reg.wep_index;
914 DPRINTK(2, "flags=%04X\n", dwrq->flags);
916 if (priv->sleep_mode == SLP_SLEEP) {
922 if ((index < 0) || (index > 4))
925 index = current_index;
929 /* Is WEP supported ? */
930 /* Basic checking: do we have a key to set ? */
931 if (dwrq->length > 0) {
932 if (dwrq->length > MAX_KEY_SIZE) { /* Check the size of the key */
935 if (dwrq->length > MIN_KEY_SIZE) { /* Set the length */
936 key.len = MAX_KEY_SIZE;
937 priv->reg.privacy_invoked = 0x01;
938 priv->need_commit |= SME_WEP_FLAG;
939 wep_on_off = WEP_ON_128BIT;
941 if (dwrq->length > 0) {
942 key.len = MIN_KEY_SIZE;
943 priv->reg.privacy_invoked = 0x01;
944 priv->need_commit |= SME_WEP_FLAG;
945 wep_on_off = WEP_ON_64BIT;
946 } else { /* Disable the key */
950 /* Check if the key is not marked as invalid */
951 if (!(dwrq->flags & IW_ENCODE_NOKEY)) {
953 memset(key.key, 0, MAX_KEY_SIZE);
954 /* Copy the key in the driver */
956 (key.key, dwrq->pointer, dwrq->length)) {
960 /* Send the key to the card */
961 priv->reg.wep_key[index].size = key.len;
962 for (i = 0; i < (priv->reg.wep_key[index].size); i++) {
963 priv->reg.wep_key[index].val[i] = key.key[i];
965 priv->need_commit |= (SME_WEP_VAL1 << index);
966 priv->reg.wep_index = index;
967 priv->need_commit |= SME_WEP_INDEX;
970 if (dwrq->flags & IW_ENCODE_DISABLED) {
971 priv->reg.wep_key[0].size = 0;
972 priv->reg.wep_key[1].size = 0;
973 priv->reg.wep_key[2].size = 0;
974 priv->reg.wep_key[3].size = 0;
975 priv->reg.privacy_invoked = 0x00;
976 if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY) {
977 priv->need_commit |= SME_MODE_SET;
979 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
980 wep_on_off = WEP_OFF;
981 priv->need_commit |= SME_WEP_FLAG;
983 /* Do we want to just set the transmit key index ? */
984 if ((index >= 0) && (index < 4)) {
985 /* set_wep_key(priv, index, 0, 0, 1); xxx */
986 if (priv->reg.wep_key[index].size) {
987 priv->reg.wep_index = index;
988 priv->need_commit |= SME_WEP_INDEX;
995 /* Commit the changes if needed */
996 if (dwrq->flags & IW_ENCODE_MODE)
997 priv->need_commit |= SME_WEP_FLAG;
999 if (dwrq->flags & IW_ENCODE_OPEN) {
1000 if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY) {
1001 priv->need_commit |= SME_MODE_SET;
1003 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
1004 } else if (dwrq->flags & IW_ENCODE_RESTRICTED) {
1005 if (priv->reg.authenticate_type == AUTH_TYPE_OPEN_SYSTEM) {
1006 priv->need_commit |= SME_MODE_SET;
1008 priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
1010 // return -EINPROGRESS; /* Call commit handler */
1011 if (priv->need_commit) {
1012 ks_wlan_setup_parameter(priv, priv->need_commit);
1013 priv->need_commit = 0;
1018 /*------------------------------------------------------------------*/
1019 /* Wireless Handler : get Encryption Key */
1020 static int ks_wlan_get_encode(struct net_device *dev,
1021 struct iw_request_info *info,
1022 struct iw_point *dwrq, char *extra)
1024 struct ks_wlan_private *priv =
1025 (struct ks_wlan_private *)netdev_priv(dev);
1027 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1029 if (priv->sleep_mode == SLP_SLEEP) {
1032 /* for SLEEP MODE */
1033 dwrq->flags = IW_ENCODE_DISABLED;
1035 /* Check encryption mode */
1036 switch (priv->reg.authenticate_type) {
1037 case AUTH_TYPE_OPEN_SYSTEM:
1038 dwrq->flags = IW_ENCODE_OPEN;
1040 case AUTH_TYPE_SHARED_KEY:
1041 dwrq->flags = IW_ENCODE_RESTRICTED;
1045 memset(zeros, 0, sizeof(zeros));
1047 /* Which key do we want ? -1 -> tx index */
1048 if ((index < 0) || (index >= 4))
1049 index = priv->reg.wep_index;
1050 if (priv->reg.privacy_invoked) {
1051 dwrq->flags &= ~IW_ENCODE_DISABLED;
1052 /* dwrq->flags |= IW_ENCODE_NOKEY; */
1054 dwrq->flags |= index + 1;
1055 DPRINTK(2, "encoding flag = 0x%04X\n", dwrq->flags);
1056 /* Copy the key to the user buffer */
1057 if ((index >= 0) && (index < 4))
1058 dwrq->length = priv->reg.wep_key[index].size;
1059 if (dwrq->length > 16) {
1062 #if 1 /* IW_ENCODE_NOKEY; */
1064 if ((index >= 0) && (index < 4))
1065 memcpy(extra, priv->reg.wep_key[index].val,
1068 memcpy(extra, zeros, dwrq->length);
1073 #ifndef KSC_OPNOTSUPP
1074 /*------------------------------------------------------------------*/
1075 /* Wireless Handler : set Tx-Power */
1076 static int ks_wlan_set_txpow(struct net_device *dev,
1077 struct iw_request_info *info,
1078 struct iw_param *vwrq, char *extra)
1080 return -EOPNOTSUPP; /* Not Support */
1083 /*------------------------------------------------------------------*/
1084 /* Wireless Handler : get Tx-Power */
1085 static int ks_wlan_get_txpow(struct net_device *dev,
1086 struct iw_request_info *info,
1087 struct iw_param *vwrq, char *extra)
1089 if (priv->sleep_mode == SLP_SLEEP) {
1093 /* for SLEEP MODE */
1096 vwrq->disabled = (vwrq->value == 0);
1101 /*------------------------------------------------------------------*/
1102 /* Wireless Handler : set Retry limits */
1103 static int ks_wlan_set_retry(struct net_device *dev,
1104 struct iw_request_info *info,
1105 struct iw_param *vwrq, char *extra)
1107 return -EOPNOTSUPP; /* Not Support */
1110 /*------------------------------------------------------------------*/
1111 /* Wireless Handler : get Retry limits */
1112 static int ks_wlan_get_retry(struct net_device *dev,
1113 struct iw_request_info *info,
1114 struct iw_param *vwrq, char *extra)
1116 if (priv->sleep_mode == SLP_SLEEP) {
1120 /* for SLEEP MODE */
1123 vwrq->disabled = (vwrq->value == 0);
1127 #endif /* KSC_OPNOTSUPP */
1129 /*------------------------------------------------------------------*/
1130 /* Wireless Handler : get range info */
1131 static int ks_wlan_get_range(struct net_device *dev,
1132 struct iw_request_info *info,
1133 struct iw_point *dwrq, char *extra)
1135 struct ks_wlan_private *priv =
1136 (struct ks_wlan_private *)netdev_priv(dev);
1137 struct iw_range *range = (struct iw_range *)extra;
1142 if (priv->sleep_mode == SLP_SLEEP) {
1145 /* for SLEEP MODE */
1146 dwrq->length = sizeof(struct iw_range);
1147 memset(range, 0, sizeof(*range));
1148 range->min_nwid = 0x0000;
1149 range->max_nwid = 0x0000;
1150 range->num_channels = 14;
1151 /* Should be based on cap_rid.country to give only
1152 * what the current card support */
1154 for (i = 0; i < 13; i++) { /* channel 1 -- 13 */
1155 range->freq[k].i = i + 1; /* List index */
1156 range->freq[k].m = frequency_list[i] * 100000;
1157 range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
1159 range->num_frequency = k;
1160 if (priv->reg.phy_type == D_11B_ONLY_MODE || priv->reg.phy_type == D_11BG_COMPATIBLE_MODE) { /* channel 14 */
1161 range->freq[13].i = 14; /* List index */
1162 range->freq[13].m = frequency_list[13] * 100000;
1163 range->freq[13].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
1164 range->num_frequency = 14;
1167 /* Hum... Should put the right values there */
1168 range->max_qual.qual = 100;
1169 range->max_qual.level = 256 - 128; /* 0 dBm? */
1170 range->max_qual.noise = 256 - 128;
1171 range->sensitivity = 1;
1173 if (priv->reg.phy_type == D_11B_ONLY_MODE) {
1174 range->bitrate[0] = 1e6;
1175 range->bitrate[1] = 2e6;
1176 range->bitrate[2] = 5.5e6;
1177 range->bitrate[3] = 11e6;
1178 range->num_bitrates = 4;
1179 } else { /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
1180 range->bitrate[0] = 1e6;
1181 range->bitrate[1] = 2e6;
1182 range->bitrate[2] = 5.5e6;
1183 range->bitrate[3] = 11e6;
1185 range->bitrate[4] = 6e6;
1186 range->bitrate[5] = 9e6;
1187 range->bitrate[6] = 12e6;
1188 if (IW_MAX_BITRATES < 9) {
1189 range->bitrate[7] = 54e6;
1190 range->num_bitrates = 8;
1192 range->bitrate[7] = 18e6;
1193 range->bitrate[8] = 24e6;
1194 range->bitrate[9] = 36e6;
1195 range->bitrate[10] = 48e6;
1196 range->bitrate[11] = 54e6;
1198 range->num_bitrates = 12;
1202 /* Set an indication of the max TCP throughput
1203 * in bit/s that we can expect using this interface.
1204 * May be use for QoS stuff... Jean II */
1206 range->throughput = 5000 * 1000;
1208 range->throughput = 1500 * 1000;
1211 range->max_rts = 2347;
1212 range->min_frag = 256;
1213 range->max_frag = 2346;
1215 range->encoding_size[0] = 5; /* WEP: RC4 40 bits */
1216 range->encoding_size[1] = 13; /* WEP: RC4 ~128 bits */
1217 range->num_encoding_sizes = 2;
1218 range->max_encoding_tokens = 4;
1220 /* power management not support */
1221 range->pmp_flags = IW_POWER_ON;
1222 range->pmt_flags = IW_POWER_ON;
1225 /* Transmit Power - values are in dBm( or mW) */
1226 range->txpower[0] = -256;
1227 range->num_txpower = 1;
1228 range->txpower_capa = IW_TXPOW_DBM;
1229 /* range->txpower_capa = IW_TXPOW_MWATT; */
1231 range->we_version_source = 21;
1232 range->we_version_compiled = WIRELESS_EXT;
1234 range->retry_capa = IW_RETRY_ON;
1235 range->retry_flags = IW_RETRY_ON;
1236 range->r_time_flags = IW_RETRY_ON;
1238 /* Experimental measurements - boundary 11/5.5 Mb/s */
1239 /* Note : with or without the (local->rssi), results
1240 * are somewhat different. - Jean II */
1241 range->avg_qual.qual = 50;
1242 range->avg_qual.level = 186; /* -70 dBm */
1243 range->avg_qual.noise = 0;
1245 /* Event capability (kernel + driver) */
1246 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
1247 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
1248 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
1249 range->event_capa[1] = IW_EVENT_CAPA_K_1;
1250 range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVCUSTOM) |
1251 IW_EVENT_CAPA_MASK(IWEVMICHAELMICFAILURE));
1253 /* encode extension (WPA) capability */
1254 range->enc_capa = (IW_ENC_CAPA_WPA |
1256 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP);
1260 /*------------------------------------------------------------------*/
1261 /* Wireless Handler : set Power Management */
1262 static int ks_wlan_set_power(struct net_device *dev,
1263 struct iw_request_info *info,
1264 struct iw_param *vwrq, char *extra)
1266 struct ks_wlan_private *priv =
1267 (struct ks_wlan_private *)netdev_priv(dev);
1270 if (priv->sleep_mode == SLP_SLEEP) {
1273 /* for SLEEP MODE */
1274 enabled = vwrq->disabled ? 0 : 1;
1275 if (enabled == 0) { /* 0 */
1276 priv->reg.powermgt = POWMGT_ACTIVE_MODE;
1277 } else if (enabled) { /* 1 */
1278 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
1279 priv->reg.powermgt = POWMGT_SAVE1_MODE;
1282 } else if (enabled) { /* 2 */
1283 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
1284 priv->reg.powermgt = POWMGT_SAVE2_MODE;
1290 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
1295 /*------------------------------------------------------------------*/
1296 /* Wireless Handler : get Power Management */
1297 static int ks_wlan_get_power(struct net_device *dev,
1298 struct iw_request_info *info,
1299 struct iw_param *vwrq, char *extra)
1301 struct ks_wlan_private *priv =
1302 (struct ks_wlan_private *)netdev_priv(dev);
1304 if (priv->sleep_mode == SLP_SLEEP) {
1307 /* for SLEEP MODE */
1308 if (priv->reg.powermgt > 0)
1316 /*------------------------------------------------------------------*/
1317 /* Wireless Handler : get wirless statistics */
1318 static int ks_wlan_get_iwstats(struct net_device *dev,
1319 struct iw_request_info *info,
1320 struct iw_quality *vwrq, char *extra)
1322 struct ks_wlan_private *priv =
1323 (struct ks_wlan_private *)netdev_priv(dev);
1325 if (priv->sleep_mode == SLP_SLEEP) {
1328 /* for SLEEP MODE */
1329 vwrq->qual = 0; /* not supported */
1330 vwrq->level = priv->wstats.qual.level;
1331 vwrq->noise = 0; /* not supported */
1337 #ifndef KSC_OPNOTSUPP
1338 /*------------------------------------------------------------------*/
1339 /* Wireless Handler : set Sensitivity */
1340 static int ks_wlan_set_sens(struct net_device *dev,
1341 struct iw_request_info *info, struct iw_param *vwrq,
1344 return -EOPNOTSUPP; /* Not Support */
1347 /*------------------------------------------------------------------*/
1348 /* Wireless Handler : get Sensitivity */
1349 static int ks_wlan_get_sens(struct net_device *dev,
1350 struct iw_request_info *info, struct iw_param *vwrq,
1355 vwrq->disabled = (vwrq->value == 0);
1359 #endif /* KSC_OPNOTSUPP */
1361 /*------------------------------------------------------------------*/
1362 /* Wireless Handler : get AP List */
1363 /* Note : this is deprecated in favor of IWSCAN */
1364 static int ks_wlan_get_aplist(struct net_device *dev,
1365 struct iw_request_info *info,
1366 struct iw_point *dwrq, char *extra)
1368 struct ks_wlan_private *priv =
1369 (struct ks_wlan_private *)netdev_priv(dev);
1370 struct sockaddr *address = (struct sockaddr *)extra;
1371 struct iw_quality qual[LOCAL_APLIST_MAX];
1375 if (priv->sleep_mode == SLP_SLEEP) {
1378 /* for SLEEP MODE */
1379 for (i = 0; i < priv->aplist.size; i++) {
1380 memcpy(address[i].sa_data, &(priv->aplist.ap[i].bssid[0]),
1382 address[i].sa_family = ARPHRD_ETHER;
1383 qual[i].level = 256 - priv->aplist.ap[i].rssi;
1384 qual[i].qual = priv->aplist.ap[i].sq;
1385 qual[i].noise = 0; /* invalid noise value */
1386 qual[i].updated = 7;
1389 dwrq->flags = 1; /* Should be define'd */
1390 memcpy(extra + sizeof(struct sockaddr) * i,
1391 &qual, sizeof(struct iw_quality) * i);
1398 /*------------------------------------------------------------------*/
1399 /* Wireless Handler : Initiate Scan */
1400 static int ks_wlan_set_scan(struct net_device *dev,
1401 struct iw_request_info *info,
1402 union iwreq_data *wrqu, char *extra)
1404 struct ks_wlan_private *priv =
1405 (struct ks_wlan_private *)netdev_priv(dev);
1406 struct iw_scan_req *req = NULL;
1410 if (priv->sleep_mode == SLP_SLEEP) {
1414 /* for SLEEP MODE */
1415 /* specified SSID SCAN */
1416 if (wrqu->data.length == sizeof(struct iw_scan_req)
1417 && wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1418 req = (struct iw_scan_req *)extra;
1419 len = min_t(int, req->essid_len, IW_ESSID_MAX_SIZE);
1420 priv->scan_ssid_len = len;
1421 memcpy(priv->scan_ssid, req->essid, len);
1423 priv->scan_ssid_len = 0;
1426 priv->sme_i.sme_flag |= SME_AP_SCAN;
1427 hostif_sme_enqueue(priv, SME_BSS_SCAN_REQUEST);
1429 /* At this point, just return to the user. */
1434 /*------------------------------------------------------------------*/
1436 * Translate scan data returned from the card to a card independent
1437 * format that the Wireless Tools will understand - Jean II
1439 static inline char *ks_wlan_translate_scan(struct net_device *dev,
1440 struct iw_request_info *info,
1441 char *current_ev, char *end_buf,
1442 struct local_ap_t *ap)
1444 /* struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; */
1445 struct iw_event iwe; /* Temporary buffer */
1447 char *current_val; /* For rates */
1449 static const char rsn_leader[] = "rsn_ie=";
1450 static const char wpa_leader[] = "wpa_ie=";
1451 char buf0[RSN_IE_BODY_MAX * 2 + 30];
1452 char buf1[RSN_IE_BODY_MAX * 2 + 30];
1454 /* First entry *MUST* be the AP MAC address */
1455 iwe.cmd = SIOCGIWAP;
1456 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1457 memcpy(iwe.u.ap_addr.sa_data, ap->bssid, ETH_ALEN);
1459 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1462 /* Other entries will be displayed in the order we give them */
1465 iwe.u.data.length = ap->ssid.size;
1466 if (iwe.u.data.length > 32)
1467 iwe.u.data.length = 32;
1468 iwe.cmd = SIOCGIWESSID;
1469 iwe.u.data.flags = 1;
1471 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1472 &(ap->ssid.body[0]));
1475 iwe.cmd = SIOCGIWMODE;
1476 capabilities = le16_to_cpu(ap->capability);
1477 if (capabilities & (BSS_CAP_ESS | BSS_CAP_IBSS)) {
1478 if (capabilities & BSS_CAP_ESS)
1479 iwe.u.mode = IW_MODE_INFRA;
1481 iwe.u.mode = IW_MODE_ADHOC;
1483 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1488 iwe.cmd = SIOCGIWFREQ;
1489 iwe.u.freq.m = ap->channel;
1490 iwe.u.freq.m = frequency_list[iwe.u.freq.m - 1] * 100000;
1493 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1496 /* Add quality statistics */
1498 iwe.u.qual.level = 256 - ap->rssi;
1499 iwe.u.qual.qual = ap->sq;
1500 iwe.u.qual.noise = 0; /* invalid noise value */
1502 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1505 /* Add encryption capability */
1506 iwe.cmd = SIOCGIWENCODE;
1507 if (capabilities & BSS_CAP_PRIVACY)
1508 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1510 iwe.u.data.flags = IW_ENCODE_DISABLED;
1511 iwe.u.data.length = 0;
1513 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1514 &(ap->ssid.body[0]));
1516 /* Rate : stuffing multiple values in a single event require a bit
1517 * more of magic - Jean II */
1518 current_val = current_ev + IW_EV_LCP_LEN;
1520 iwe.cmd = SIOCGIWRATE;
1521 /* Those two flags are ignored... */
1522 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
1525 for (i = 0; i < 16; i++) {
1526 /* NULL terminated */
1527 if (i >= ap->rate_set.size)
1529 /* Bit rate given in 500 kb/s units (+ 0x80) */
1530 iwe.u.bitrate.value = ((ap->rate_set.body[i] & 0x7f) * 500000);
1531 /* Add new value to event */
1533 iwe_stream_add_value(info, current_ev, current_val, end_buf,
1534 &iwe, IW_EV_PARAM_LEN);
1536 /* Check if we added any event */
1537 if ((current_val - current_ev) > IW_EV_LCP_LEN)
1538 current_ev = current_val;
1540 #define GENERIC_INFO_ELEM_ID 0xdd
1541 #define RSN_INFO_ELEM_ID 0x30
1542 if (ap->rsn_ie.id == RSN_INFO_ELEM_ID && ap->rsn_ie.size != 0) {
1544 memset(&iwe, 0, sizeof(iwe));
1545 iwe.cmd = IWEVCUSTOM;
1546 memcpy(buf0, rsn_leader, sizeof(rsn_leader) - 1);
1547 iwe.u.data.length += sizeof(rsn_leader) - 1;
1548 pbuf += sizeof(rsn_leader) - 1;
1550 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.id);
1551 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.size);
1552 iwe.u.data.length += 4;
1554 for (i = 0; i < ap->rsn_ie.size; i++)
1555 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.body[i]);
1556 iwe.u.data.length += (ap->rsn_ie.size) * 2;
1558 DPRINTK(4, "ap->rsn.size=%d\n", ap->rsn_ie.size);
1561 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1564 if (ap->wpa_ie.id == GENERIC_INFO_ELEM_ID && ap->wpa_ie.size != 0) {
1566 memset(&iwe, 0, sizeof(iwe));
1567 iwe.cmd = IWEVCUSTOM;
1568 memcpy(buf1, wpa_leader, sizeof(wpa_leader) - 1);
1569 iwe.u.data.length += sizeof(wpa_leader) - 1;
1570 pbuf += sizeof(wpa_leader) - 1;
1572 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.id);
1573 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.size);
1574 iwe.u.data.length += 4;
1576 for (i = 0; i < ap->wpa_ie.size; i++)
1577 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.body[i]);
1578 iwe.u.data.length += (ap->wpa_ie.size) * 2;
1580 DPRINTK(4, "ap->rsn.size=%d\n", ap->wpa_ie.size);
1581 DPRINTK(4, "iwe.u.data.length=%d\n", iwe.u.data.length);
1584 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1588 /* The other data in the scan result are not really
1589 * interesting, so for now drop it - Jean II */
1593 /*------------------------------------------------------------------*/
1594 /* Wireless Handler : Read Scan Results */
1595 static int ks_wlan_get_scan(struct net_device *dev,
1596 struct iw_request_info *info, struct iw_point *dwrq,
1599 struct ks_wlan_private *priv =
1600 (struct ks_wlan_private *)netdev_priv(dev);
1602 char *current_ev = extra;
1605 if (priv->sleep_mode == SLP_SLEEP) {
1608 /* for SLEEP MODE */
1609 if (priv->sme_i.sme_flag & SME_AP_SCAN) {
1610 DPRINTK(2, "flag AP_SCAN\n");
1614 if (priv->aplist.size == 0) {
1615 /* Client error, no scan results...
1616 * The caller need to restart the scan. */
1617 DPRINTK(2, "aplist 0\n");
1621 /* current connect ap */
1622 if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
1623 if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) {
1627 current_ev = ks_wlan_translate_scan(dev, current_ev,
1628 // extra + IW_SCAN_MAX_DATA,
1629 extra + dwrq->length,
1630 &(priv->current_ap));
1633 /* Read and parse all entries */
1634 for (i = 0; i < priv->aplist.size; i++) {
1635 if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) {
1639 /* Translate to WE format this entry */
1640 current_ev = ks_wlan_translate_scan(dev, info, current_ev,
1641 // extra + IW_SCAN_MAX_DATA,
1642 extra + dwrq->length,
1643 &(priv->aplist.ap[i]));
1645 /* Length of data */
1646 dwrq->length = (current_ev - extra);
1652 /*------------------------------------------------------------------*/
1653 /* Commit handler : called after a bunch of SET operations */
1654 static int ks_wlan_config_commit(struct net_device *dev,
1655 struct iw_request_info *info, void *zwrq,
1658 struct ks_wlan_private *priv =
1659 (struct ks_wlan_private *)netdev_priv(dev);
1661 if (!priv->need_commit)
1664 ks_wlan_setup_parameter(priv, priv->need_commit);
1665 priv->need_commit = 0;
1669 /*------------------------------------------------------------------*/
1670 /* Wireless handler : set association ie params */
1671 static int ks_wlan_set_genie(struct net_device *dev,
1672 struct iw_request_info *info,
1673 struct iw_point *dwrq, char *extra)
1675 struct ks_wlan_private *priv =
1676 (struct ks_wlan_private *)netdev_priv(dev);
1680 if (priv->sleep_mode == SLP_SLEEP) {
1683 /* for SLEEP MODE */
1685 // return -EOPNOTSUPP;
1688 /*------------------------------------------------------------------*/
1689 /* Wireless handler : set authentication mode params */
1690 static int ks_wlan_set_auth_mode(struct net_device *dev,
1691 struct iw_request_info *info,
1692 struct iw_param *vwrq, char *extra)
1694 struct ks_wlan_private *priv =
1695 (struct ks_wlan_private *)netdev_priv(dev);
1696 int index = (vwrq->flags & IW_AUTH_INDEX);
1697 int value = vwrq->value;
1699 DPRINTK(2, "index=%d:value=%08X\n", index, value);
1701 if (priv->sleep_mode == SLP_SLEEP) {
1704 /* for SLEEP MODE */
1706 case IW_AUTH_WPA_VERSION: /* 0 */
1708 case IW_AUTH_WPA_VERSION_DISABLED:
1709 priv->wpa.version = value;
1710 if (priv->wpa.rsn_enabled) {
1711 priv->wpa.rsn_enabled = 0;
1713 priv->need_commit |= SME_RSN;
1715 case IW_AUTH_WPA_VERSION_WPA:
1716 case IW_AUTH_WPA_VERSION_WPA2:
1717 priv->wpa.version = value;
1718 if (!(priv->wpa.rsn_enabled)) {
1719 priv->wpa.rsn_enabled = 1;
1721 priv->need_commit |= SME_RSN;
1727 case IW_AUTH_CIPHER_PAIRWISE: /* 1 */
1729 case IW_AUTH_CIPHER_NONE:
1730 if (priv->reg.privacy_invoked) {
1731 priv->reg.privacy_invoked = 0x00;
1732 priv->need_commit |= SME_WEP_FLAG;
1735 case IW_AUTH_CIPHER_WEP40:
1736 case IW_AUTH_CIPHER_TKIP:
1737 case IW_AUTH_CIPHER_CCMP:
1738 case IW_AUTH_CIPHER_WEP104:
1739 if (!priv->reg.privacy_invoked) {
1740 priv->reg.privacy_invoked = 0x01;
1741 priv->need_commit |= SME_WEP_FLAG;
1743 priv->wpa.pairwise_suite = value;
1744 priv->need_commit |= SME_RSN_UNICAST;
1750 case IW_AUTH_CIPHER_GROUP: /* 2 */
1752 case IW_AUTH_CIPHER_NONE:
1753 if (priv->reg.privacy_invoked) {
1754 priv->reg.privacy_invoked = 0x00;
1755 priv->need_commit |= SME_WEP_FLAG;
1758 case IW_AUTH_CIPHER_WEP40:
1759 case IW_AUTH_CIPHER_TKIP:
1760 case IW_AUTH_CIPHER_CCMP:
1761 case IW_AUTH_CIPHER_WEP104:
1762 if (!priv->reg.privacy_invoked) {
1763 priv->reg.privacy_invoked = 0x01;
1764 priv->need_commit |= SME_WEP_FLAG;
1766 priv->wpa.group_suite = value;
1767 priv->need_commit |= SME_RSN_MULTICAST;
1773 case IW_AUTH_KEY_MGMT: /* 3 */
1775 case IW_AUTH_KEY_MGMT_802_1X:
1776 case IW_AUTH_KEY_MGMT_PSK:
1777 case 0: /* NONE or 802_1X_NO_WPA */
1778 case 4: /* WPA_NONE */
1779 priv->wpa.key_mgmt_suite = value;
1780 priv->need_commit |= SME_RSN_AUTH;
1786 case IW_AUTH_80211_AUTH_ALG: /* 6 */
1788 case IW_AUTH_ALG_OPEN_SYSTEM:
1789 priv->wpa.auth_alg = value;
1790 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
1792 case IW_AUTH_ALG_SHARED_KEY:
1793 priv->wpa.auth_alg = value;
1794 priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
1796 case IW_AUTH_ALG_LEAP:
1800 priv->need_commit |= SME_MODE_SET;
1802 case IW_AUTH_WPA_ENABLED: /* 7 */
1803 priv->wpa.wpa_enabled = value;
1805 case IW_AUTH_PRIVACY_INVOKED: /* 10 */
1806 if ((value && !priv->reg.privacy_invoked) ||
1807 (!value && priv->reg.privacy_invoked)) {
1808 priv->reg.privacy_invoked = value ? 0x01 : 0x00;
1809 priv->need_commit |= SME_WEP_FLAG;
1812 case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* 4 */
1813 case IW_AUTH_TKIP_COUNTERMEASURES: /* 5 */
1814 case IW_AUTH_DROP_UNENCRYPTED: /* 8 */
1815 case IW_AUTH_ROAMING_CONTROL: /* 9 */
1820 /* return -EINPROGRESS; */
1821 if (priv->need_commit) {
1822 ks_wlan_setup_parameter(priv, priv->need_commit);
1823 priv->need_commit = 0;
1828 /*------------------------------------------------------------------*/
1829 /* Wireless handler : get authentication mode params */
1830 static int ks_wlan_get_auth_mode(struct net_device *dev,
1831 struct iw_request_info *info,
1832 struct iw_param *vwrq, char *extra)
1834 struct ks_wlan_private *priv =
1835 (struct ks_wlan_private *)netdev_priv(dev);
1836 int index = (vwrq->flags & IW_AUTH_INDEX);
1837 DPRINTK(2, "index=%d\n", index);
1839 if (priv->sleep_mode == SLP_SLEEP) {
1843 /* for SLEEP MODE */
1844 /* WPA (not used ?? wpa_supplicant) */
1846 case IW_AUTH_WPA_VERSION:
1847 vwrq->value = priv->wpa.version;
1849 case IW_AUTH_CIPHER_PAIRWISE:
1850 vwrq->value = priv->wpa.pairwise_suite;
1852 case IW_AUTH_CIPHER_GROUP:
1853 vwrq->value = priv->wpa.group_suite;
1855 case IW_AUTH_KEY_MGMT:
1856 vwrq->value = priv->wpa.key_mgmt_suite;
1858 case IW_AUTH_80211_AUTH_ALG:
1859 vwrq->value = priv->wpa.auth_alg;
1861 case IW_AUTH_WPA_ENABLED:
1862 vwrq->value = priv->wpa.rsn_enabled;
1864 case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* OK??? */
1865 case IW_AUTH_TKIP_COUNTERMEASURES:
1866 case IW_AUTH_DROP_UNENCRYPTED:
1868 /* return -EOPNOTSUPP; */
1874 /*------------------------------------------------------------------*/
1875 /* Wireless Handler : set encoding token & mode (WPA)*/
1876 static int ks_wlan_set_encode_ext(struct net_device *dev,
1877 struct iw_request_info *info,
1878 struct iw_point *dwrq, char *extra)
1880 struct ks_wlan_private *priv =
1881 (struct ks_wlan_private *)netdev_priv(dev);
1882 struct iw_encode_ext *enc;
1883 int index = dwrq->flags & IW_ENCODE_INDEX;
1884 unsigned int commit = 0;
1886 enc = (struct iw_encode_ext *)extra;
1888 DPRINTK(2, "flags=%04X:: ext_flags=%08X\n", dwrq->flags,
1891 if (priv->sleep_mode == SLP_SLEEP) {
1894 /* for SLEEP MODE */
1895 if (index < 1 || index > 4)
1900 if (dwrq->flags & IW_ENCODE_DISABLED) {
1901 priv->wpa.key[index].key_len = 0;
1905 priv->wpa.key[index].ext_flags = enc->ext_flags;
1906 if (enc->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
1907 priv->wpa.txkey = index;
1908 commit |= SME_WEP_INDEX;
1909 } else if (enc->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
1910 memcpy(&priv->wpa.key[index].rx_seq[0],
1911 enc->rx_seq, IW_ENCODE_SEQ_MAX_SIZE);
1914 memcpy(&priv->wpa.key[index].addr.sa_data[0],
1915 &enc->addr.sa_data[0], ETH_ALEN);
1918 case IW_ENCODE_ALG_NONE:
1919 if (priv->reg.privacy_invoked) {
1920 priv->reg.privacy_invoked = 0x00;
1921 commit |= SME_WEP_FLAG;
1923 priv->wpa.key[index].key_len = 0;
1926 case IW_ENCODE_ALG_WEP:
1927 case IW_ENCODE_ALG_CCMP:
1928 if (!priv->reg.privacy_invoked) {
1929 priv->reg.privacy_invoked = 0x01;
1930 commit |= SME_WEP_FLAG;
1933 memcpy(&priv->wpa.key[index].key_val[0],
1934 &enc->key[0], enc->key_len);
1935 priv->wpa.key[index].key_len = enc->key_len;
1936 commit |= (SME_WEP_VAL1 << index);
1939 case IW_ENCODE_ALG_TKIP:
1940 if (!priv->reg.privacy_invoked) {
1941 priv->reg.privacy_invoked = 0x01;
1942 commit |= SME_WEP_FLAG;
1944 if (enc->key_len == 32) {
1945 memcpy(&priv->wpa.key[index].key_val[0],
1946 &enc->key[0], enc->key_len - 16);
1947 priv->wpa.key[index].key_len =
1949 if (priv->wpa.key_mgmt_suite == 4) { /* WPA_NONE */
1950 memcpy(&priv->wpa.key[index].
1951 tx_mic_key[0], &enc->key[16], 8);
1952 memcpy(&priv->wpa.key[index].
1953 rx_mic_key[0], &enc->key[16], 8);
1955 memcpy(&priv->wpa.key[index].
1956 tx_mic_key[0], &enc->key[16], 8);
1957 memcpy(&priv->wpa.key[index].
1958 rx_mic_key[0], &enc->key[24], 8);
1960 commit |= (SME_WEP_VAL1 << index);
1966 priv->wpa.key[index].alg = enc->alg;
1971 if (commit & SME_WEP_INDEX)
1972 hostif_sme_enqueue(priv, SME_SET_TXKEY);
1973 if (commit & SME_WEP_VAL_MASK)
1974 hostif_sme_enqueue(priv, SME_SET_KEY1 + index);
1975 if (commit & SME_WEP_FLAG)
1976 hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
1982 /*------------------------------------------------------------------*/
1983 /* Wireless Handler : get encoding token & mode (WPA)*/
1984 static int ks_wlan_get_encode_ext(struct net_device *dev,
1985 struct iw_request_info *info,
1986 struct iw_point *dwrq, char *extra)
1988 struct ks_wlan_private *priv =
1989 (struct ks_wlan_private *)netdev_priv(dev);
1991 if (priv->sleep_mode == SLP_SLEEP) {
1995 /* for SLEEP MODE */
1996 /* WPA (not used ?? wpa_supplicant)
1997 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
1998 struct iw_encode_ext *enc;
1999 enc = (struct iw_encode_ext *)extra;
2000 int index = dwrq->flags & IW_ENCODE_INDEX;
2001 WPA (not used ?? wpa_supplicant) */
2005 /*------------------------------------------------------------------*/
2006 /* Wireless Handler : PMKSA cache operation (WPA2) */
2007 static int ks_wlan_set_pmksa(struct net_device *dev,
2008 struct iw_request_info *info,
2009 struct iw_point *dwrq, char *extra)
2011 struct ks_wlan_private *priv =
2012 (struct ks_wlan_private *)netdev_priv(dev);
2013 struct iw_pmksa *pmksa;
2016 struct list_head *ptr;
2020 if (priv->sleep_mode == SLP_SLEEP) {
2023 /* for SLEEP MODE */
2027 pmksa = (struct iw_pmksa *)extra;
2028 DPRINTK(2, "cmd=%d\n", pmksa->cmd);
2030 switch (pmksa->cmd) {
2032 if (list_empty(&priv->pmklist.head)) { /* new list */
2033 for (i = 0; i < PMK_LIST_MAX; i++) {
2034 pmk = &priv->pmklist.pmk[i];
2036 ("\x00\x00\x00\x00\x00\x00", pmk->bssid,
2040 memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
2041 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
2042 list_add(&pmk->list, &priv->pmklist.head);
2043 priv->pmklist.size++;
2044 } else { /* search cache data */
2045 list_for_each(ptr, &priv->pmklist.head) {
2046 pmk = list_entry(ptr, struct pmk_t, list);
2047 if (!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)) { /* match address! list move to head. */
2048 memcpy(pmk->pmkid, pmksa->pmkid,
2050 list_move(&pmk->list,
2051 &priv->pmklist.head);
2055 if (ptr == &priv->pmklist.head) { /* not find address. */
2056 if (PMK_LIST_MAX > priv->pmklist.size) { /* new cache data */
2057 for (i = 0; i < PMK_LIST_MAX; i++) {
2058 pmk = &priv->pmklist.pmk[i];
2060 ("\x00\x00\x00\x00\x00\x00",
2061 pmk->bssid, ETH_ALEN))
2064 memcpy(pmk->bssid, pmksa->bssid.sa_data,
2066 memcpy(pmk->pmkid, pmksa->pmkid,
2068 list_add(&pmk->list,
2069 &priv->pmklist.head);
2070 priv->pmklist.size++;
2071 } else { /* overwrite old cache data */
2073 list_entry(priv->pmklist.head.prev,
2074 struct pmk_t, list);
2075 memcpy(pmk->bssid, pmksa->bssid.sa_data,
2077 memcpy(pmk->pmkid, pmksa->pmkid,
2079 list_move(&pmk->list,
2080 &priv->pmklist.head);
2085 case IW_PMKSA_REMOVE:
2086 if (list_empty(&priv->pmklist.head)) { /* list empty */
2088 } else { /* search cache data */
2089 list_for_each(ptr, &priv->pmklist.head) {
2090 pmk = list_entry(ptr, struct pmk_t, list);
2091 if (!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)) { /* match address! list del. */
2092 eth_zero_addr(pmk->bssid);
2093 memset(pmk->pmkid, 0, IW_PMKID_LEN);
2094 list_del_init(&pmk->list);
2098 if (ptr == &priv->pmklist.head) { /* not find address. */
2103 case IW_PMKSA_FLUSH:
2104 memset(&(priv->pmklist), 0, sizeof(priv->pmklist));
2105 INIT_LIST_HEAD(&priv->pmklist.head);
2106 for (i = 0; i < PMK_LIST_MAX; i++)
2107 INIT_LIST_HEAD(&priv->pmklist.pmk[i].list);
2113 hostif_sme_enqueue(priv, SME_SET_PMKSA);
2117 static struct iw_statistics *ks_get_wireless_stats(struct net_device *dev)
2120 struct ks_wlan_private *priv =
2121 (struct ks_wlan_private *)netdev_priv(dev);
2122 struct iw_statistics *wstats = &priv->wstats;
2124 if (!atomic_read(&update_phyinfo)) {
2125 if (priv->dev_state < DEVICE_STATE_READY)
2126 return NULL; /* not finished initialize */
2131 /* Packets discarded in the wireless adapter due to wireless
2132 * specific problems */
2133 wstats->discard.nwid = 0; /* Rx invalid nwid */
2134 wstats->discard.code = 0; /* Rx invalid crypt */
2135 wstats->discard.fragment = 0; /* Rx invalid frag */
2136 wstats->discard.retries = 0; /* Tx excessive retries */
2137 wstats->discard.misc = 0; /* Invalid misc */
2138 wstats->miss.beacon = 0; /* Missed beacon */
2143 /*------------------------------------------------------------------*/
2144 /* Private handler : set stop request */
2145 static int ks_wlan_set_stop_request(struct net_device *dev,
2146 struct iw_request_info *info, __u32 * uwrq,
2149 struct ks_wlan_private *priv =
2150 (struct ks_wlan_private *)netdev_priv(dev);
2153 if (priv->sleep_mode == SLP_SLEEP) {
2156 /* for SLEEP MODE */
2160 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2164 /*------------------------------------------------------------------*/
2165 /* Wireless Handler : set MLME */
2166 #include <linux/ieee80211.h>
2167 static int ks_wlan_set_mlme(struct net_device *dev,
2168 struct iw_request_info *info, struct iw_point *dwrq,
2171 struct ks_wlan_private *priv =
2172 (struct ks_wlan_private *)netdev_priv(dev);
2173 struct iw_mlme *mlme = (struct iw_mlme *)extra;
2176 DPRINTK(2, ":%d :%d\n", mlme->cmd, mlme->reason_code);
2178 if (priv->sleep_mode == SLP_SLEEP) {
2181 /* for SLEEP MODE */
2182 switch (mlme->cmd) {
2183 case IW_MLME_DEAUTH:
2184 if (mlme->reason_code == WLAN_REASON_MIC_FAILURE) {
2187 case IW_MLME_DISASSOC:
2189 return ks_wlan_set_stop_request(dev, NULL, &mode, NULL);
2191 return -EOPNOTSUPP; /* Not Support */
2195 /*------------------------------------------------------------------*/
2196 /* Private handler : get firemware version */
2197 static int ks_wlan_get_firmware_version(struct net_device *dev,
2198 struct iw_request_info *info,
2199 struct iw_point *dwrq, char *extra)
2201 struct ks_wlan_private *priv =
2202 (struct ks_wlan_private *)netdev_priv(dev);
2203 strcpy(extra, &(priv->firmware_version[0]));
2204 dwrq->length = priv->version_size + 1;
2209 /*------------------------------------------------------------------*/
2210 /* Private handler : set force disconnect status */
2211 static int ks_wlan_set_detach(struct net_device *dev,
2212 struct iw_request_info *info, __u32 * uwrq,
2215 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2217 if (priv->sleep_mode == SLP_SLEEP) {
2220 /* for SLEEP MODE */
2221 if (*uwrq == CONNECT_STATUS) { /* 0 */
2222 priv->connect_status &= ~FORCE_DISCONNECT;
2223 if ((priv->connect_status & CONNECT_STATUS_MASK) ==
2225 netif_carrier_on(dev);
2226 } else if (*uwrq == DISCONNECT_STATUS) { /* 1 */
2227 priv->connect_status |= FORCE_DISCONNECT;
2228 netif_carrier_off(dev);
2234 /*------------------------------------------------------------------*/
2235 /* Private handler : get force disconnect status */
2236 static int ks_wlan_get_detach(struct net_device *dev,
2237 struct iw_request_info *info, __u32 * uwrq,
2240 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2242 if (priv->sleep_mode == SLP_SLEEP) {
2245 /* for SLEEP MODE */
2246 *uwrq = ((priv->connect_status & FORCE_DISCONNECT) ? 1 : 0);
2250 /*------------------------------------------------------------------*/
2251 /* Private handler : get connect status */
2252 static int ks_wlan_get_connect(struct net_device *dev,
2253 struct iw_request_info *info, __u32 * uwrq,
2256 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2258 if (priv->sleep_mode == SLP_SLEEP) {
2261 /* for SLEEP MODE */
2262 *uwrq = (priv->connect_status & CONNECT_STATUS_MASK);
2267 /*------------------------------------------------------------------*/
2268 /* Private handler : set preamble */
2269 static int ks_wlan_set_preamble(struct net_device *dev,
2270 struct iw_request_info *info, __u32 * uwrq,
2273 struct ks_wlan_private *priv =
2274 (struct ks_wlan_private *)netdev_priv(dev);
2276 if (priv->sleep_mode == SLP_SLEEP) {
2279 /* for SLEEP MODE */
2280 if (*uwrq == LONG_PREAMBLE) { /* 0 */
2281 priv->reg.preamble = LONG_PREAMBLE;
2282 } else if (*uwrq == SHORT_PREAMBLE) { /* 1 */
2283 priv->reg.preamble = SHORT_PREAMBLE;
2287 priv->need_commit |= SME_MODE_SET;
2288 return -EINPROGRESS; /* Call commit handler */
2292 /*------------------------------------------------------------------*/
2293 /* Private handler : get preamble */
2294 static int ks_wlan_get_preamble(struct net_device *dev,
2295 struct iw_request_info *info, __u32 * uwrq,
2298 struct ks_wlan_private *priv =
2299 (struct ks_wlan_private *)netdev_priv(dev);
2301 if (priv->sleep_mode == SLP_SLEEP) {
2304 /* for SLEEP MODE */
2305 *uwrq = priv->reg.preamble;
2309 /*------------------------------------------------------------------*/
2310 /* Private handler : set power save mode */
2311 static int ks_wlan_set_powermgt(struct net_device *dev,
2312 struct iw_request_info *info, __u32 * uwrq,
2315 struct ks_wlan_private *priv =
2316 (struct ks_wlan_private *)netdev_priv(dev);
2318 if (priv->sleep_mode == SLP_SLEEP) {
2321 /* for SLEEP MODE */
2322 if (*uwrq == POWMGT_ACTIVE_MODE) { /* 0 */
2323 priv->reg.powermgt = POWMGT_ACTIVE_MODE;
2324 } else if (*uwrq == POWMGT_SAVE1_MODE) { /* 1 */
2325 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2326 priv->reg.powermgt = POWMGT_SAVE1_MODE;
2329 } else if (*uwrq == POWMGT_SAVE2_MODE) { /* 2 */
2330 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2331 priv->reg.powermgt = POWMGT_SAVE2_MODE;
2337 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
2342 /*------------------------------------------------------------------*/
2343 /* Private handler : get power save made */
2344 static int ks_wlan_get_powermgt(struct net_device *dev,
2345 struct iw_request_info *info, __u32 * uwrq,
2348 struct ks_wlan_private *priv =
2349 (struct ks_wlan_private *)netdev_priv(dev);
2351 if (priv->sleep_mode == SLP_SLEEP) {
2354 /* for SLEEP MODE */
2355 *uwrq = priv->reg.powermgt;
2359 /*------------------------------------------------------------------*/
2360 /* Private handler : set scan type */
2361 static int ks_wlan_set_scan_type(struct net_device *dev,
2362 struct iw_request_info *info, __u32 * uwrq,
2365 struct ks_wlan_private *priv =
2366 (struct ks_wlan_private *)netdev_priv(dev);
2368 if (priv->sleep_mode == SLP_SLEEP) {
2371 /* for SLEEP MODE */
2372 if (*uwrq == ACTIVE_SCAN) { /* 0 */
2373 priv->reg.scan_type = ACTIVE_SCAN;
2374 } else if (*uwrq == PASSIVE_SCAN) { /* 1 */
2375 priv->reg.scan_type = PASSIVE_SCAN;
2382 /*------------------------------------------------------------------*/
2383 /* Private handler : get scan type */
2384 static int ks_wlan_get_scan_type(struct net_device *dev,
2385 struct iw_request_info *info, __u32 * uwrq,
2388 struct ks_wlan_private *priv =
2389 (struct ks_wlan_private *)netdev_priv(dev);
2391 if (priv->sleep_mode == SLP_SLEEP) {
2394 /* for SLEEP MODE */
2395 *uwrq = priv->reg.scan_type;
2400 /*------------------------------------------------------------------*/
2401 /* Private handler : write raw data to device */
2402 static int ks_wlan_data_write(struct net_device *dev,
2403 struct iw_request_info *info,
2404 struct iw_point *dwrq, char *extra)
2406 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2407 unsigned char *wbuff = NULL;
2409 if (priv->sleep_mode == SLP_SLEEP) {
2412 /* for SLEEP MODE */
2413 wbuff = (unsigned char *)kmalloc(dwrq->length, GFP_ATOMIC);
2416 memcpy(wbuff, extra, dwrq->length);
2418 /* write to device */
2419 ks_wlan_hw_tx(priv, wbuff, dwrq->length, NULL, NULL, NULL);
2424 /*------------------------------------------------------------------*/
2425 /* Private handler : read raw data form device */
2426 static int ks_wlan_data_read(struct net_device *dev,
2427 struct iw_request_info *info,
2428 struct iw_point *dwrq, char *extra)
2430 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2431 unsigned short read_length;
2433 if (priv->sleep_mode == SLP_SLEEP) {
2436 /* for SLEEP MODE */
2437 if (!atomic_read(&priv->event_count)) {
2438 if (priv->dev_state < DEVICE_STATE_BOOT) { /* Remove device */
2440 memset(extra, 0xff, read_length);
2441 dwrq->length = read_length;
2445 memset(extra, 0, 1);
2450 if (atomic_read(&priv->event_count) > 0)
2451 atomic_dec(&priv->event_count);
2453 spin_lock(&priv->dev_read_lock); /* request spin lock */
2455 /* Copy length max size 0x07ff */
2456 if (priv->dev_size[priv->dev_count] > 2047)
2459 read_length = priv->dev_size[priv->dev_count];
2462 memcpy(extra, &(priv->dev_data[priv->dev_count][0]), read_length);
2464 spin_unlock(&priv->dev_read_lock); /* release spin lock */
2467 priv->dev_data[priv->dev_count] = 0;
2468 priv->dev_size[priv->dev_count] = 0;
2471 if (priv->dev_count == DEVICE_STOCK_COUNT)
2472 priv->dev_count = 0;
2475 dwrq->length = read_length;
2482 /*------------------------------------------------------------------*/
2483 /* Private handler : get wep string */
2484 #define WEP_ASCII_BUFF_SIZE (17+64*4+1)
2485 static int ks_wlan_get_wep_ascii(struct net_device *dev,
2486 struct iw_request_info *info,
2487 struct iw_point *dwrq, char *extra)
2489 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2491 char tmp[WEP_ASCII_BUFF_SIZE];
2493 if (priv->sleep_mode == SLP_SLEEP) {
2496 /* for SLEEP MODE */
2497 strcpy(tmp, " WEP keys ASCII \n");
2498 len += strlen(" WEP keys ASCII \n");
2500 for (i = 0; i < 4; i++) {
2501 strcpy(tmp + len, "\t[");
2502 len += strlen("\t[");
2505 strcpy(tmp + len, "] ");
2506 len += strlen("] ");
2507 if (priv->reg.wep_key[i].size) {
2509 (priv->reg.wep_key[i].size <
2510 6 ? "(40bits) [" : "(104bits) ["));
2512 strlen((priv->reg.wep_key[i].size <
2513 6 ? "(40bits) [" : "(104bits) ["));
2514 for (j = 0; j < priv->reg.wep_key[i].size; j++, len++)
2516 (isprint(priv->reg.wep_key[i].val[j]) ?
2517 priv->reg.wep_key[i].val[j] : ' ');
2519 strcpy(tmp + len, "]\n");
2520 len += strlen("]\n");
2522 strcpy(tmp + len, "off\n");
2523 len += strlen("off\n");
2527 memcpy(extra, tmp, len);
2528 dwrq->length = len + 1;
2533 /*------------------------------------------------------------------*/
2534 /* Private handler : set beacon lost count */
2535 static int ks_wlan_set_beacon_lost(struct net_device *dev,
2536 struct iw_request_info *info, __u32 * uwrq,
2539 struct ks_wlan_private *priv =
2540 (struct ks_wlan_private *)netdev_priv(dev);
2542 if (priv->sleep_mode == SLP_SLEEP) {
2545 /* for SLEEP MODE */
2546 if (*uwrq >= BEACON_LOST_COUNT_MIN && *uwrq <= BEACON_LOST_COUNT_MAX) {
2547 priv->reg.beacon_lost_count = *uwrq;
2551 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
2552 priv->need_commit |= SME_MODE_SET;
2553 return -EINPROGRESS; /* Call commit handler */
2558 /*------------------------------------------------------------------*/
2559 /* Private handler : get beacon lost count */
2560 static int ks_wlan_get_beacon_lost(struct net_device *dev,
2561 struct iw_request_info *info, __u32 * uwrq,
2564 struct ks_wlan_private *priv =
2565 (struct ks_wlan_private *)netdev_priv(dev);
2567 if (priv->sleep_mode == SLP_SLEEP) {
2570 /* for SLEEP MODE */
2571 *uwrq = priv->reg.beacon_lost_count;
2575 /*------------------------------------------------------------------*/
2576 /* Private handler : set phy type */
2577 static int ks_wlan_set_phy_type(struct net_device *dev,
2578 struct iw_request_info *info, __u32 * uwrq,
2581 struct ks_wlan_private *priv =
2582 (struct ks_wlan_private *)netdev_priv(dev);
2584 if (priv->sleep_mode == SLP_SLEEP) {
2587 /* for SLEEP MODE */
2588 if (*uwrq == D_11B_ONLY_MODE) { /* 0 */
2589 priv->reg.phy_type = D_11B_ONLY_MODE;
2590 } else if (*uwrq == D_11G_ONLY_MODE) { /* 1 */
2591 priv->reg.phy_type = D_11G_ONLY_MODE;
2592 } else if (*uwrq == D_11BG_COMPATIBLE_MODE) { /* 2 */
2593 priv->reg.phy_type = D_11BG_COMPATIBLE_MODE;
2597 priv->need_commit |= SME_MODE_SET;
2598 return -EINPROGRESS; /* Call commit handler */
2601 /*------------------------------------------------------------------*/
2602 /* Private handler : get phy type */
2603 static int ks_wlan_get_phy_type(struct net_device *dev,
2604 struct iw_request_info *info, __u32 * uwrq,
2607 struct ks_wlan_private *priv =
2608 (struct ks_wlan_private *)netdev_priv(dev);
2610 if (priv->sleep_mode == SLP_SLEEP) {
2613 /* for SLEEP MODE */
2614 *uwrq = priv->reg.phy_type;
2618 /*------------------------------------------------------------------*/
2619 /* Private handler : set cts mode */
2620 static int ks_wlan_set_cts_mode(struct net_device *dev,
2621 struct iw_request_info *info, __u32 * uwrq,
2624 struct ks_wlan_private *priv =
2625 (struct ks_wlan_private *)netdev_priv(dev);
2627 if (priv->sleep_mode == SLP_SLEEP) {
2630 /* for SLEEP MODE */
2631 if (*uwrq == CTS_MODE_FALSE) { /* 0 */
2632 priv->reg.cts_mode = CTS_MODE_FALSE;
2633 } else if (*uwrq == CTS_MODE_TRUE) { /* 1 */
2634 if (priv->reg.phy_type == D_11G_ONLY_MODE ||
2635 priv->reg.phy_type == D_11BG_COMPATIBLE_MODE)
2636 priv->reg.cts_mode = CTS_MODE_TRUE;
2638 priv->reg.cts_mode = CTS_MODE_FALSE;
2642 priv->need_commit |= SME_MODE_SET;
2643 return -EINPROGRESS; /* Call commit handler */
2646 /*------------------------------------------------------------------*/
2647 /* Private handler : get cts mode */
2648 static int ks_wlan_get_cts_mode(struct net_device *dev,
2649 struct iw_request_info *info, __u32 * uwrq,
2652 struct ks_wlan_private *priv =
2653 (struct ks_wlan_private *)netdev_priv(dev);
2655 if (priv->sleep_mode == SLP_SLEEP) {
2658 /* for SLEEP MODE */
2659 *uwrq = priv->reg.cts_mode;
2663 /*------------------------------------------------------------------*/
2664 /* Private handler : set sleep mode */
2665 static int ks_wlan_set_sleep_mode(struct net_device *dev,
2666 struct iw_request_info *info,
2667 __u32 * uwrq, char *extra)
2669 struct ks_wlan_private *priv =
2670 (struct ks_wlan_private *)netdev_priv(dev);
2674 if (*uwrq == SLP_SLEEP) {
2675 priv->sleep_mode = *uwrq;
2676 netdev_info(dev, "SET_SLEEP_MODE %d\n", priv->sleep_mode);
2678 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2679 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2681 } else if (*uwrq == SLP_ACTIVE) {
2682 priv->sleep_mode = *uwrq;
2683 netdev_info(dev, "SET_SLEEP_MODE %d\n", priv->sleep_mode);
2684 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2686 netdev_err(dev, "SET_SLEEP_MODE %d errror\n", *uwrq);
2693 /*------------------------------------------------------------------*/
2694 /* Private handler : get sleep mode */
2695 static int ks_wlan_get_sleep_mode(struct net_device *dev,
2696 struct iw_request_info *info,
2697 __u32 * uwrq, char *extra)
2699 struct ks_wlan_private *priv =
2700 (struct ks_wlan_private *)netdev_priv(dev);
2702 DPRINTK(2, "GET_SLEEP_MODE %d\n", priv->sleep_mode);
2703 *uwrq = priv->sleep_mode;
2709 /*------------------------------------------------------------------*/
2710 /* Private handler : set phy information timer */
2711 static int ks_wlan_set_phy_information_timer(struct net_device *dev,
2712 struct iw_request_info *info,
2713 __u32 * uwrq, char *extra)
2715 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2717 if (priv->sleep_mode == SLP_SLEEP) {
2720 /* for SLEEP MODE */
2721 if (*uwrq >= 0 && *uwrq <= 0xFFFF) /* 0-65535 */
2722 priv->reg.phy_info_timer = (uint16_t) * uwrq;
2726 hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST);
2731 /*------------------------------------------------------------------*/
2732 /* Private handler : get phy information timer */
2733 static int ks_wlan_get_phy_information_timer(struct net_device *dev,
2734 struct iw_request_info *info,
2735 __u32 * uwrq, char *extra)
2737 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2739 if (priv->sleep_mode == SLP_SLEEP) {
2742 /* for SLEEP MODE */
2743 *uwrq = priv->reg.phy_info_timer;
2749 /*------------------------------------------------------------------*/
2750 /* Private handler : set WPS enable */
2751 static int ks_wlan_set_wps_enable(struct net_device *dev,
2752 struct iw_request_info *info, __u32 * uwrq,
2755 struct ks_wlan_private *priv =
2756 (struct ks_wlan_private *)netdev_priv(dev);
2759 if (priv->sleep_mode == SLP_SLEEP) {
2762 /* for SLEEP MODE */
2763 if (*uwrq == 0 || *uwrq == 1)
2764 priv->wps.wps_enabled = *uwrq;
2768 hostif_sme_enqueue(priv, SME_WPS_ENABLE_REQUEST);
2773 /*------------------------------------------------------------------*/
2774 /* Private handler : get WPS enable */
2775 static int ks_wlan_get_wps_enable(struct net_device *dev,
2776 struct iw_request_info *info, __u32 * uwrq,
2779 struct ks_wlan_private *priv =
2780 (struct ks_wlan_private *)netdev_priv(dev);
2783 if (priv->sleep_mode == SLP_SLEEP) {
2786 /* for SLEEP MODE */
2787 *uwrq = priv->wps.wps_enabled;
2788 netdev_info(dev, "return=%d\n", *uwrq);
2793 /*------------------------------------------------------------------*/
2794 /* Private handler : set WPS probe req */
2795 static int ks_wlan_set_wps_probe_req(struct net_device *dev,
2796 struct iw_request_info *info,
2797 struct iw_point *dwrq, char *extra)
2801 struct ks_wlan_private *priv =
2802 (struct ks_wlan_private *)netdev_priv(dev);
2806 if (priv->sleep_mode == SLP_SLEEP) {
2809 /* for SLEEP MODE */
2810 DPRINTK(2, "dwrq->length=%d\n", dwrq->length);
2813 if (p[1] + 2 != dwrq->length || dwrq->length > 256) {
2817 priv->wps.ielen = p[1] + 2 + 1; /* IE header + IE + sizeof(len) */
2818 len = p[1] + 2; /* IE header + IE */
2820 memcpy(priv->wps.ie, &len, sizeof(len));
2821 p = memcpy(priv->wps.ie + 1, p, len);
2823 DPRINTK(2, "%d(%#x): %02X %02X %02X %02X ... %02X %02X %02X\n",
2824 priv->wps.ielen, priv->wps.ielen, p[0], p[1], p[2], p[3],
2825 p[priv->wps.ielen - 3], p[priv->wps.ielen - 2],
2826 p[priv->wps.ielen - 1]);
2828 hostif_sme_enqueue(priv, SME_WPS_PROBE_REQUEST);
2834 /*------------------------------------------------------------------*/
2835 /* Private handler : get WPS probe req */
2836 static int ks_wlan_get_wps_probe_req(struct net_device *dev,
2837 struct iw_request_info *info,
2838 __u32 * uwrq, char *extra)
2840 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2843 if (priv->sleep_mode == SLP_SLEEP) {
2846 /* for SLEEP MODE */
2852 /*------------------------------------------------------------------*/
2853 /* Private handler : set tx gain control value */
2854 static int ks_wlan_set_tx_gain(struct net_device *dev,
2855 struct iw_request_info *info, __u32 * uwrq,
2858 struct ks_wlan_private *priv =
2859 (struct ks_wlan_private *)netdev_priv(dev);
2861 if (priv->sleep_mode == SLP_SLEEP) {
2864 /* for SLEEP MODE */
2865 if (*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2866 priv->gain.TxGain = (uint8_t) * uwrq;
2870 if (priv->gain.TxGain < 0xFF)
2871 priv->gain.TxMode = 1;
2873 priv->gain.TxMode = 0;
2875 hostif_sme_enqueue(priv, SME_SET_GAIN);
2879 /*------------------------------------------------------------------*/
2880 /* Private handler : get tx gain control value */
2881 static int ks_wlan_get_tx_gain(struct net_device *dev,
2882 struct iw_request_info *info, __u32 * uwrq,
2885 struct ks_wlan_private *priv =
2886 (struct ks_wlan_private *)netdev_priv(dev);
2888 if (priv->sleep_mode == SLP_SLEEP) {
2891 /* for SLEEP MODE */
2892 *uwrq = priv->gain.TxGain;
2893 hostif_sme_enqueue(priv, SME_GET_GAIN);
2897 /*------------------------------------------------------------------*/
2898 /* Private handler : set rx gain control value */
2899 static int ks_wlan_set_rx_gain(struct net_device *dev,
2900 struct iw_request_info *info, __u32 * uwrq,
2903 struct ks_wlan_private *priv =
2904 (struct ks_wlan_private *)netdev_priv(dev);
2906 if (priv->sleep_mode == SLP_SLEEP) {
2909 /* for SLEEP MODE */
2910 if (*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2911 priv->gain.RxGain = (uint8_t) * uwrq;
2915 if (priv->gain.RxGain < 0xFF)
2916 priv->gain.RxMode = 1;
2918 priv->gain.RxMode = 0;
2920 hostif_sme_enqueue(priv, SME_SET_GAIN);
2924 /*------------------------------------------------------------------*/
2925 /* Private handler : get rx gain control value */
2926 static int ks_wlan_get_rx_gain(struct net_device *dev,
2927 struct iw_request_info *info, __u32 * uwrq,
2930 struct ks_wlan_private *priv =
2931 (struct ks_wlan_private *)netdev_priv(dev);
2933 if (priv->sleep_mode == SLP_SLEEP) {
2936 /* for SLEEP MODE */
2937 *uwrq = priv->gain.RxGain;
2938 hostif_sme_enqueue(priv, SME_GET_GAIN);
2943 /*------------------------------------------------------------------*/
2944 /* Private handler : set region value */
2945 static int ks_wlan_set_region(struct net_device *dev,
2946 struct iw_request_info *info, __u32 * uwrq,
2949 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2951 if (priv->sleep_mode == SLP_SLEEP) {
2954 /* for SLEEP MODE */
2955 if (*uwrq >= 0x9 && *uwrq <= 0xF) /* 0x9-0xf */
2956 priv->region = (uint8_t) * uwrq;
2960 hostif_sme_enqueue(priv, SME_SET_REGION);
2965 /*------------------------------------------------------------------*/
2966 /* Private handler : get eeprom checksum result */
2967 static int ks_wlan_get_eeprom_cksum(struct net_device *dev,
2968 struct iw_request_info *info, __u32 * uwrq,
2971 struct ks_wlan_private *priv =
2972 (struct ks_wlan_private *)netdev_priv(dev);
2974 *uwrq = priv->eeprom_checksum;
2978 static void print_hif_event(struct net_device *dev, int event)
2983 netdev_info(dev, "HIF_DATA_REQ\n");
2986 netdev_info(dev, "HIF_DATA_IND\n");
2988 case HIF_MIB_GET_REQ:
2989 netdev_info(dev, "HIF_MIB_GET_REQ\n");
2991 case HIF_MIB_GET_CONF:
2992 netdev_info(dev, "HIF_MIB_GET_CONF\n");
2994 case HIF_MIB_SET_REQ:
2995 netdev_info(dev, "HIF_MIB_SET_REQ\n");
2997 case HIF_MIB_SET_CONF:
2998 netdev_info(dev, "HIF_MIB_SET_CONF\n");
3000 case HIF_POWERMGT_REQ:
3001 netdev_info(dev, "HIF_POWERMGT_REQ\n");
3003 case HIF_POWERMGT_CONF:
3004 netdev_info(dev, "HIF_POWERMGT_CONF\n");
3007 netdev_info(dev, "HIF_START_REQ\n");
3009 case HIF_START_CONF:
3010 netdev_info(dev, "HIF_START_CONF\n");
3012 case HIF_CONNECT_IND:
3013 netdev_info(dev, "HIF_CONNECT_IND\n");
3016 netdev_info(dev, "HIF_STOP_REQ\n");
3019 netdev_info(dev, "HIF_STOP_CONF\n");
3021 case HIF_PS_ADH_SET_REQ:
3022 netdev_info(dev, "HIF_PS_ADH_SET_REQ\n");
3024 case HIF_PS_ADH_SET_CONF:
3025 netdev_info(dev, "HIF_PS_ADH_SET_CONF\n");
3027 case HIF_INFRA_SET_REQ:
3028 netdev_info(dev, "HIF_INFRA_SET_REQ\n");
3030 case HIF_INFRA_SET_CONF:
3031 netdev_info(dev, "HIF_INFRA_SET_CONF\n");
3033 case HIF_ADH_SET_REQ:
3034 netdev_info(dev, "HIF_ADH_SET_REQ\n");
3036 case HIF_ADH_SET_CONF:
3037 netdev_info(dev, "HIF_ADH_SET_CONF\n");
3039 case HIF_AP_SET_REQ:
3040 netdev_info(dev, "HIF_AP_SET_REQ\n");
3042 case HIF_AP_SET_CONF:
3043 netdev_info(dev, "HIF_AP_SET_CONF\n");
3045 case HIF_ASSOC_INFO_IND:
3046 netdev_info(dev, "HIF_ASSOC_INFO_IND\n");
3048 case HIF_MIC_FAILURE_REQ:
3049 netdev_info(dev, "HIF_MIC_FAILURE_REQ\n");
3051 case HIF_MIC_FAILURE_CONF:
3052 netdev_info(dev, "HIF_MIC_FAILURE_CONF\n");
3055 netdev_info(dev, "HIF_SCAN_REQ\n");
3058 netdev_info(dev, "HIF_SCAN_CONF\n");
3060 case HIF_PHY_INFO_REQ:
3061 netdev_info(dev, "HIF_PHY_INFO_REQ\n");
3063 case HIF_PHY_INFO_CONF:
3064 netdev_info(dev, "HIF_PHY_INFO_CONF\n");
3067 netdev_info(dev, "HIF_SLEEP_REQ\n");
3069 case HIF_SLEEP_CONF:
3070 netdev_info(dev, "HIF_SLEEP_CONF\n");
3072 case HIF_PHY_INFO_IND:
3073 netdev_info(dev, "HIF_PHY_INFO_IND\n");
3076 netdev_info(dev, "HIF_SCAN_IND\n");
3078 case HIF_INFRA_SET2_REQ:
3079 netdev_info(dev, "HIF_INFRA_SET2_REQ\n");
3081 case HIF_INFRA_SET2_CONF:
3082 netdev_info(dev, "HIF_INFRA_SET2_CONF\n");
3084 case HIF_ADH_SET2_REQ:
3085 netdev_info(dev, "HIF_ADH_SET2_REQ\n");
3087 case HIF_ADH_SET2_CONF:
3088 netdev_info(dev, "HIF_ADH_SET2_CONF\n");
3092 /*------------------------------------------------------------------*/
3093 /* Private handler : get host command history */
3094 static int ks_wlan_hostt(struct net_device *dev, struct iw_request_info *info,
3095 __u32 * uwrq, char *extra)
3098 struct ks_wlan_private *priv =
3099 (struct ks_wlan_private *)netdev_priv(dev);
3101 for (i = 63; i >= 0; i--) {
3103 priv->hostt.buff[(priv->hostt.qtail - 1 - i) %
3104 SME_EVENT_BUFF_SIZE];
3105 print_hif_event(dev, event);
3110 /* Structures to export the Wireless Handlers */
3112 static const struct iw_priv_args ks_wlan_private_args[] = {
3113 /*{ cmd, set_args, get_args, name[16] } */
3114 {KS_WLAN_GET_FIRM_VERSION, IW_PRIV_TYPE_NONE,
3115 IW_PRIV_TYPE_CHAR | (128 + 1), "GetFirmwareVer"},
3117 {KS_WLAN_SET_WPS_ENABLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3118 IW_PRIV_TYPE_NONE, "SetWPSEnable"},
3119 {KS_WLAN_GET_WPS_ENABLE, IW_PRIV_TYPE_NONE,
3120 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetW"},
3121 {KS_WLAN_SET_WPS_PROBE_REQ, IW_PRIV_TYPE_BYTE | 2047, IW_PRIV_TYPE_NONE,
3124 {KS_WLAN_SET_PREAMBLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3125 IW_PRIV_TYPE_NONE, "SetPreamble"},
3126 {KS_WLAN_GET_PREAMBLE, IW_PRIV_TYPE_NONE,
3127 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPreamble"},
3128 {KS_WLAN_SET_POWER_SAVE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3129 IW_PRIV_TYPE_NONE, "SetPowerSave"},
3130 {KS_WLAN_GET_POWER_SAVE, IW_PRIV_TYPE_NONE,
3131 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPowerSave"},
3132 {KS_WLAN_SET_SCAN_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3133 IW_PRIV_TYPE_NONE, "SetScanType"},
3134 {KS_WLAN_GET_SCAN_TYPE, IW_PRIV_TYPE_NONE,
3135 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetScanType"},
3136 {KS_WLAN_SET_RX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3137 IW_PRIV_TYPE_NONE, "SetRxGain"},
3138 {KS_WLAN_GET_RX_GAIN, IW_PRIV_TYPE_NONE,
3139 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetRxGain"},
3140 {KS_WLAN_HOSTT, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | (128 + 1),
3142 {KS_WLAN_SET_BEACON_LOST, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3143 IW_PRIV_TYPE_NONE, "SetBeaconLost"},
3144 {KS_WLAN_GET_BEACON_LOST, IW_PRIV_TYPE_NONE,
3145 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetBeaconLost"},
3146 {KS_WLAN_SET_SLEEP_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3147 IW_PRIV_TYPE_NONE, "SetSleepMode"},
3148 {KS_WLAN_GET_SLEEP_MODE, IW_PRIV_TYPE_NONE,
3149 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetSleepMode"},
3150 {KS_WLAN_SET_TX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3151 IW_PRIV_TYPE_NONE, "SetTxGain"},
3152 {KS_WLAN_GET_TX_GAIN, IW_PRIV_TYPE_NONE,
3153 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetTxGain"},
3154 {KS_WLAN_SET_PHY_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3155 IW_PRIV_TYPE_NONE, "SetPhyType"},
3156 {KS_WLAN_GET_PHY_TYPE, IW_PRIV_TYPE_NONE,
3157 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPhyType"},
3158 {KS_WLAN_SET_CTS_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3159 IW_PRIV_TYPE_NONE, "SetCtsMode"},
3160 {KS_WLAN_GET_CTS_MODE, IW_PRIV_TYPE_NONE,
3161 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetCtsMode"},
3162 {KS_WLAN_GET_EEPROM_CKSUM, IW_PRIV_TYPE_NONE,
3163 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetChecksum"},
3166 static const iw_handler ks_wlan_handler[] = {
3167 (iw_handler) ks_wlan_config_commit, /* SIOCSIWCOMMIT */
3168 (iw_handler) ks_wlan_get_name, /* SIOCGIWNAME */
3169 (iw_handler) NULL, /* SIOCSIWNWID */
3170 (iw_handler) NULL, /* SIOCGIWNWID */
3171 (iw_handler) ks_wlan_set_freq, /* SIOCSIWFREQ */
3172 (iw_handler) ks_wlan_get_freq, /* SIOCGIWFREQ */
3173 (iw_handler) ks_wlan_set_mode, /* SIOCSIWMODE */
3174 (iw_handler) ks_wlan_get_mode, /* SIOCGIWMODE */
3175 #ifndef KSC_OPNOTSUPP
3176 (iw_handler) ks_wlan_set_sens, /* SIOCSIWSENS */
3177 (iw_handler) ks_wlan_get_sens, /* SIOCGIWSENS */
3178 #else /* KSC_OPNOTSUPP */
3179 (iw_handler) NULL, /* SIOCSIWSENS */
3180 (iw_handler) NULL, /* SIOCGIWSENS */
3181 #endif /* KSC_OPNOTSUPP */
3182 (iw_handler) NULL, /* SIOCSIWRANGE */
3183 (iw_handler) ks_wlan_get_range, /* SIOCGIWRANGE */
3184 (iw_handler) NULL, /* SIOCSIWPRIV */
3185 (iw_handler) NULL, /* SIOCGIWPRIV */
3186 (iw_handler) NULL, /* SIOCSIWSTATS */
3187 (iw_handler) ks_wlan_get_iwstats, /* SIOCGIWSTATS */
3188 (iw_handler) NULL, /* SIOCSIWSPY */
3189 (iw_handler) NULL, /* SIOCGIWSPY */
3190 (iw_handler) NULL, /* SIOCSIWTHRSPY */
3191 (iw_handler) NULL, /* SIOCGIWTHRSPY */
3192 (iw_handler) ks_wlan_set_wap, /* SIOCSIWAP */
3193 (iw_handler) ks_wlan_get_wap, /* SIOCGIWAP */
3194 // (iw_handler) NULL, /* SIOCSIWMLME */
3195 (iw_handler) ks_wlan_set_mlme, /* SIOCSIWMLME */
3196 (iw_handler) ks_wlan_get_aplist, /* SIOCGIWAPLIST */
3197 (iw_handler) ks_wlan_set_scan, /* SIOCSIWSCAN */
3198 (iw_handler) ks_wlan_get_scan, /* SIOCGIWSCAN */
3199 (iw_handler) ks_wlan_set_essid, /* SIOCSIWESSID */
3200 (iw_handler) ks_wlan_get_essid, /* SIOCGIWESSID */
3201 (iw_handler) ks_wlan_set_nick, /* SIOCSIWNICKN */
3202 (iw_handler) ks_wlan_get_nick, /* SIOCGIWNICKN */
3203 (iw_handler) NULL, /* -- hole -- */
3204 (iw_handler) NULL, /* -- hole -- */
3205 (iw_handler) ks_wlan_set_rate, /* SIOCSIWRATE */
3206 (iw_handler) ks_wlan_get_rate, /* SIOCGIWRATE */
3207 (iw_handler) ks_wlan_set_rts, /* SIOCSIWRTS */
3208 (iw_handler) ks_wlan_get_rts, /* SIOCGIWRTS */
3209 (iw_handler) ks_wlan_set_frag, /* SIOCSIWFRAG */
3210 (iw_handler) ks_wlan_get_frag, /* SIOCGIWFRAG */
3211 #ifndef KSC_OPNOTSUPP
3212 (iw_handler) ks_wlan_set_txpow, /* SIOCSIWTXPOW */
3213 (iw_handler) ks_wlan_get_txpow, /* SIOCGIWTXPOW */
3214 (iw_handler) ks_wlan_set_retry, /* SIOCSIWRETRY */
3215 (iw_handler) ks_wlan_get_retry, /* SIOCGIWRETRY */
3216 #else /* KSC_OPNOTSUPP */
3217 (iw_handler) NULL, /* SIOCSIWTXPOW */
3218 (iw_handler) NULL, /* SIOCGIWTXPOW */
3219 (iw_handler) NULL, /* SIOCSIWRETRY */
3220 (iw_handler) NULL, /* SIOCGIWRETRY */
3221 #endif /* KSC_OPNOTSUPP */
3222 (iw_handler) ks_wlan_set_encode, /* SIOCSIWENCODE */
3223 (iw_handler) ks_wlan_get_encode, /* SIOCGIWENCODE */
3224 (iw_handler) ks_wlan_set_power, /* SIOCSIWPOWER */
3225 (iw_handler) ks_wlan_get_power, /* SIOCGIWPOWER */
3226 (iw_handler) NULL, /* -- hole -- */
3227 (iw_handler) NULL, /* -- hole -- */
3228 // (iw_handler) NULL, /* SIOCSIWGENIE */
3229 (iw_handler) ks_wlan_set_genie, /* SIOCSIWGENIE */
3230 (iw_handler) NULL, /* SIOCGIWGENIE */
3231 (iw_handler) ks_wlan_set_auth_mode, /* SIOCSIWAUTH */
3232 (iw_handler) ks_wlan_get_auth_mode, /* SIOCGIWAUTH */
3233 (iw_handler) ks_wlan_set_encode_ext, /* SIOCSIWENCODEEXT */
3234 (iw_handler) ks_wlan_get_encode_ext, /* SIOCGIWENCODEEXT */
3235 (iw_handler) ks_wlan_set_pmksa, /* SIOCSIWPMKSA */
3236 (iw_handler) NULL, /* -- hole -- */
3239 /* private_handler */
3240 static const iw_handler ks_wlan_private_handler[] = {
3241 (iw_handler) NULL, /* 0 */
3242 (iw_handler) NULL, /* 1, used to be: KS_WLAN_GET_DRIVER_VERSION */
3243 (iw_handler) NULL, /* 2 */
3244 (iw_handler) ks_wlan_get_firmware_version, /* 3 KS_WLAN_GET_FIRM_VERSION */
3246 (iw_handler) ks_wlan_set_wps_enable, /* 4 KS_WLAN_SET_WPS_ENABLE */
3247 (iw_handler) ks_wlan_get_wps_enable, /* 5 KS_WLAN_GET_WPS_ENABLE */
3248 (iw_handler) ks_wlan_set_wps_probe_req, /* 6 KS_WLAN_SET_WPS_PROBE_REQ */
3250 (iw_handler) NULL, /* 4 */
3251 (iw_handler) NULL, /* 5 */
3252 (iw_handler) NULL, /* 6 */
3255 (iw_handler) ks_wlan_get_eeprom_cksum, /* 7 KS_WLAN_GET_CONNECT */
3256 (iw_handler) ks_wlan_set_preamble, /* 8 KS_WLAN_SET_PREAMBLE */
3257 (iw_handler) ks_wlan_get_preamble, /* 9 KS_WLAN_GET_PREAMBLE */
3258 (iw_handler) ks_wlan_set_powermgt, /* 10 KS_WLAN_SET_POWER_SAVE */
3259 (iw_handler) ks_wlan_get_powermgt, /* 11 KS_WLAN_GET_POWER_SAVE */
3260 (iw_handler) ks_wlan_set_scan_type, /* 12 KS_WLAN_SET_SCAN_TYPE */
3261 (iw_handler) ks_wlan_get_scan_type, /* 13 KS_WLAN_GET_SCAN_TYPE */
3262 (iw_handler) ks_wlan_set_rx_gain, /* 14 KS_WLAN_SET_RX_GAIN */
3263 (iw_handler) ks_wlan_get_rx_gain, /* 15 KS_WLAN_GET_RX_GAIN */
3264 (iw_handler) ks_wlan_hostt, /* 16 KS_WLAN_HOSTT */
3265 (iw_handler) NULL, /* 17 */
3266 (iw_handler) ks_wlan_set_beacon_lost, /* 18 KS_WLAN_SET_BECAN_LOST */
3267 (iw_handler) ks_wlan_get_beacon_lost, /* 19 KS_WLAN_GET_BECAN_LOST */
3268 (iw_handler) ks_wlan_set_tx_gain, /* 20 KS_WLAN_SET_TX_GAIN */
3269 (iw_handler) ks_wlan_get_tx_gain, /* 21 KS_WLAN_GET_TX_GAIN */
3270 (iw_handler) ks_wlan_set_phy_type, /* 22 KS_WLAN_SET_PHY_TYPE */
3271 (iw_handler) ks_wlan_get_phy_type, /* 23 KS_WLAN_GET_PHY_TYPE */
3272 (iw_handler) ks_wlan_set_cts_mode, /* 24 KS_WLAN_SET_CTS_MODE */
3273 (iw_handler) ks_wlan_get_cts_mode, /* 25 KS_WLAN_GET_CTS_MODE */
3274 (iw_handler) NULL, /* 26 */
3275 (iw_handler) NULL, /* 27 */
3276 (iw_handler) ks_wlan_set_sleep_mode, /* 28 KS_WLAN_SET_SLEEP_MODE */
3277 (iw_handler) ks_wlan_get_sleep_mode, /* 29 KS_WLAN_GET_SLEEP_MODE */
3278 (iw_handler) NULL, /* 30 */
3279 (iw_handler) NULL, /* 31 */
3282 static const struct iw_handler_def ks_wlan_handler_def = {
3283 .num_standard = sizeof(ks_wlan_handler) / sizeof(iw_handler),
3284 .num_private = sizeof(ks_wlan_private_handler) / sizeof(iw_handler),
3286 sizeof(ks_wlan_private_args) / sizeof(struct iw_priv_args),
3287 .standard = (iw_handler *) ks_wlan_handler,
3288 .private = (iw_handler *) ks_wlan_private_handler,
3289 .private_args = (struct iw_priv_args *)ks_wlan_private_args,
3290 .get_wireless_stats = ks_get_wireless_stats,
3293 static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq,
3297 struct iwreq *wrq = (struct iwreq *)rq;
3299 case SIOCIWFIRSTPRIV + 20: /* KS_WLAN_SET_STOP_REQ */
3300 rc = ks_wlan_set_stop_request(dev, NULL, &(wrq->u.mode), NULL);
3302 // All other calls are currently unsupported
3307 DPRINTK(5, "return=%d\n", rc);
3312 struct net_device_stats *ks_wlan_get_stats(struct net_device *dev)
3314 struct ks_wlan_private *priv = netdev_priv(dev);
3316 if (priv->dev_state < DEVICE_STATE_READY) {
3317 return NULL; /* not finished initialize */
3320 return &priv->nstats;
3324 int ks_wlan_set_mac_address(struct net_device *dev, void *addr)
3326 struct ks_wlan_private *priv = netdev_priv(dev);
3327 struct sockaddr *mac_addr = (struct sockaddr *)addr;
3328 if (netif_running(dev))
3330 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
3331 memcpy(priv->eth_addr, mac_addr->sa_data, ETH_ALEN);
3333 priv->mac_address_valid = 0;
3334 hostif_sme_enqueue(priv, SME_MACADDRESS_SET_REQUEST);
3336 "ks_wlan: MAC ADDRESS = %02x:%02x:%02x:%02x:%02x:%02x\n",
3337 priv->eth_addr[0], priv->eth_addr[1], priv->eth_addr[2],
3338 priv->eth_addr[3], priv->eth_addr[4], priv->eth_addr[5]);
3343 void ks_wlan_tx_timeout(struct net_device *dev)
3345 struct ks_wlan_private *priv = netdev_priv(dev);
3347 DPRINTK(1, "head(%d) tail(%d)!!\n", priv->tx_dev.qhead,
3348 priv->tx_dev.qtail);
3349 if (!netif_queue_stopped(dev)) {
3350 netif_stop_queue(dev);
3352 priv->nstats.tx_errors++;
3353 netif_wake_queue(dev);
3357 int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev)
3359 struct ks_wlan_private *priv = netdev_priv(dev);
3362 DPRINTK(3, "in_interrupt()=%ld\n", in_interrupt());
3365 netdev_err(dev, "ks_wlan: skb == NULL!!!\n");
3368 if (priv->dev_state < DEVICE_STATE_READY) {
3370 return 0; /* not finished initialize */
3373 if (netif_running(dev))
3374 netif_stop_queue(dev);
3376 rc = hostif_data_request(priv, skb);
3377 netif_trans_update(dev);
3379 DPRINTK(4, "rc=%d\n", rc);
3387 void send_packet_complete(void *arg1, void *arg2)
3389 struct ks_wlan_private *priv = (struct ks_wlan_private *)arg1;
3390 struct sk_buff *packet = (struct sk_buff *)arg2;
3394 priv->nstats.tx_packets++;
3396 if (netif_queue_stopped(priv->net_dev))
3397 netif_wake_queue(priv->net_dev);
3400 priv->nstats.tx_bytes += packet->len;
3401 dev_kfree_skb(packet);
3407 /* Set or clear the multicast filter for this adaptor.
3408 This routine is not state sensitive and need not be SMP locked. */
3410 void ks_wlan_set_multicast_list(struct net_device *dev)
3412 struct ks_wlan_private *priv = netdev_priv(dev);
3415 if (priv->dev_state < DEVICE_STATE_READY) {
3416 return; /* not finished initialize */
3418 hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST);
3422 int ks_wlan_open(struct net_device *dev)
3424 struct ks_wlan_private *priv = netdev_priv(dev);
3428 if (!priv->mac_address_valid) {
3429 netdev_err(dev, "ks_wlan : %s Not READY !!\n", dev->name);
3432 netif_start_queue(dev);
3438 int ks_wlan_close(struct net_device *dev)
3441 netif_stop_queue(dev);
3443 DPRINTK(4, "%s: Shutting down ethercard, status was 0x%4.4x.\n",
3449 /* Operational parameters that usually are not changed. */
3450 /* Time in jiffies before concluding the transmitter is hung. */
3451 #define TX_TIMEOUT (3*HZ)
3452 static const unsigned char dummy_addr[] =
3453 { 0x00, 0x0b, 0xe3, 0x00, 0x00, 0x00 };
3455 static const struct net_device_ops ks_wlan_netdev_ops = {
3456 .ndo_start_xmit = ks_wlan_start_xmit,
3457 .ndo_open = ks_wlan_open,
3458 .ndo_stop = ks_wlan_close,
3459 .ndo_do_ioctl = ks_wlan_netdev_ioctl,
3460 .ndo_set_mac_address = ks_wlan_set_mac_address,
3461 .ndo_get_stats = ks_wlan_get_stats,
3462 .ndo_tx_timeout = ks_wlan_tx_timeout,
3463 .ndo_set_rx_mode = ks_wlan_set_multicast_list,
3466 int ks_wlan_net_start(struct net_device *dev)
3468 struct ks_wlan_private *priv;
3471 priv = netdev_priv(dev);
3472 priv->mac_address_valid = 0;
3473 priv->need_commit = 0;
3475 priv->device_open_status = 1;
3477 /* phy information update timer */
3478 atomic_set(&update_phyinfo, 0);
3479 init_timer(&update_phyinfo_timer);
3480 update_phyinfo_timer.function = ks_wlan_update_phyinfo_timeout;
3481 update_phyinfo_timer.data = (unsigned long)priv;
3483 /* dummy address set */
3484 memcpy(priv->eth_addr, dummy_addr, ETH_ALEN);
3485 dev->dev_addr[0] = priv->eth_addr[0];
3486 dev->dev_addr[1] = priv->eth_addr[1];
3487 dev->dev_addr[2] = priv->eth_addr[2];
3488 dev->dev_addr[3] = priv->eth_addr[3];
3489 dev->dev_addr[4] = priv->eth_addr[4];
3490 dev->dev_addr[5] = priv->eth_addr[5];
3491 dev->dev_addr[6] = 0x00;
3492 dev->dev_addr[7] = 0x00;
3494 /* The ks_wlan-specific entries in the device structure. */
3495 dev->netdev_ops = &ks_wlan_netdev_ops;
3496 dev->wireless_handlers = (struct iw_handler_def *)&ks_wlan_handler_def;
3497 dev->watchdog_timeo = TX_TIMEOUT;
3499 netif_carrier_off(dev);
3504 int ks_wlan_net_stop(struct net_device *dev)
3506 struct ks_wlan_private *priv = netdev_priv(dev);
3508 priv->device_open_status = 0;
3509 del_timer_sync(&update_phyinfo_timer);
3511 if (netif_running(dev))
3512 netif_stop_queue(dev);