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 <linux/atomic.h>
29 #include <linux/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 */
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_rx_mode(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 netdev_dbg(priv->net_dev, "in_interrupt = %ld\n", in_interrupt());
91 if (priv->dev_state < DEVICE_STATE_READY)
92 return -EBUSY; /* 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 netdev_dbg(priv->net_dev, "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(struct timer_list *unused)
119 pr_debug("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)
126 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
128 if (commit_flag & SME_RTS)
129 hostif_sme_enqueue(priv, SME_RTS_THRESHOLD_REQUEST);
130 if (commit_flag & SME_FRAG)
131 hostif_sme_enqueue(priv, SME_FRAGMENTATION_THRESHOLD_REQUEST);
133 if (commit_flag & SME_WEP_INDEX)
134 hostif_sme_enqueue(priv, SME_WEP_INDEX_REQUEST);
135 if (commit_flag & SME_WEP_VAL1)
136 hostif_sme_enqueue(priv, SME_WEP_KEY1_REQUEST);
137 if (commit_flag & SME_WEP_VAL2)
138 hostif_sme_enqueue(priv, SME_WEP_KEY2_REQUEST);
139 if (commit_flag & SME_WEP_VAL3)
140 hostif_sme_enqueue(priv, SME_WEP_KEY3_REQUEST);
141 if (commit_flag & SME_WEP_VAL4)
142 hostif_sme_enqueue(priv, SME_WEP_KEY4_REQUEST);
143 if (commit_flag & SME_WEP_FLAG)
144 hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
146 if (commit_flag & SME_RSN) {
147 hostif_sme_enqueue(priv, SME_RSN_ENABLED_REQUEST);
148 hostif_sme_enqueue(priv, SME_RSN_MODE_REQUEST);
150 if (commit_flag & SME_RSN_MULTICAST)
151 hostif_sme_enqueue(priv, SME_RSN_MCAST_REQUEST);
152 if (commit_flag & SME_RSN_UNICAST)
153 hostif_sme_enqueue(priv, SME_RSN_UCAST_REQUEST);
154 if (commit_flag & SME_RSN_AUTH)
155 hostif_sme_enqueue(priv, SME_RSN_AUTH_REQUEST);
157 hostif_sme_enqueue(priv, SME_MODE_SET_REQUEST);
159 hostif_sme_enqueue(priv, SME_START_REQUEST);
165 * Initial Wireless Extension code for Ks_Wlannet driver by :
166 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00
167 * Conversion to new driver API by :
168 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 26 March 02
169 * Javier also did a good amount of work here, adding some new extensions
170 * and fixing my code. Let's just say that without him this code just
171 * would not work at all... - Jean II
174 static int ks_wlan_get_name(struct net_device *dev,
175 struct iw_request_info *info, char *cwrq,
178 struct ks_wlan_private *priv = netdev_priv(dev);
180 if (priv->sleep_mode == SLP_SLEEP)
184 if (priv->dev_state < DEVICE_STATE_READY)
185 strcpy(cwrq, "NOT READY!");
186 else if (priv->reg.phy_type == D_11B_ONLY_MODE)
187 strcpy(cwrq, "IEEE 802.11b");
188 else if (priv->reg.phy_type == D_11G_ONLY_MODE)
189 strcpy(cwrq, "IEEE 802.11g");
191 strcpy(cwrq, "IEEE 802.11b/g");
196 static int ks_wlan_set_freq(struct net_device *dev,
197 struct iw_request_info *info, struct iw_freq *fwrq,
200 struct ks_wlan_private *priv = netdev_priv(dev);
203 if (priv->sleep_mode == SLP_SLEEP)
207 /* If setting by frequency, convert to a channel */
208 if ((fwrq->e == 1) &&
209 (fwrq->m >= (int)2.412e8) && (fwrq->m <= (int)2.487e8)) {
210 int f = fwrq->m / 100000;
213 while ((c < 14) && (f != frequency_list[c]))
215 /* Hack to fall through... */
219 /* Setting by channel number */
220 if ((fwrq->m > 1000) || (fwrq->e > 0))
224 /* We should do a better check than that,
225 * based on the card capability !!!
227 if ((channel < 1) || (channel > 14)) {
228 netdev_dbg(dev, "%s: New channel value of %d is invalid!\n",
233 /* Yes ! We can set it !!! */
234 priv->reg.channel = (u8)(channel);
235 priv->need_commit |= SME_MODE_SET;
237 return -EINPROGRESS; /* Call commit handler */
240 static int ks_wlan_get_freq(struct net_device *dev,
241 struct iw_request_info *info, struct iw_freq *fwrq,
244 struct ks_wlan_private *priv = netdev_priv(dev);
247 if (priv->sleep_mode == SLP_SLEEP)
251 if (is_connect_status(priv->connect_status))
252 f = (int)priv->current_ap.channel;
254 f = (int)priv->reg.channel;
256 fwrq->m = frequency_list[f - 1] * 100000;
262 static int ks_wlan_set_essid(struct net_device *dev,
263 struct iw_request_info *info,
264 struct iw_point *dwrq, char *extra)
266 struct ks_wlan_private *priv = netdev_priv(dev);
269 if (priv->sleep_mode == SLP_SLEEP)
273 /* Check if we asked for `any' */
275 /* Just send an empty SSID list */
276 memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
277 priv->reg.ssid.size = 0;
280 /* iwconfig uses nul termination in SSID.. */
281 if (len > 0 && extra[len - 1] == '\0')
284 /* Check the size of the string */
285 if (len > IW_ESSID_MAX_SIZE)
289 memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
290 memcpy(priv->reg.ssid.body, extra, len);
291 priv->reg.ssid.size = len;
293 /* Write it to the card */
294 priv->need_commit |= SME_MODE_SET;
296 ks_wlan_setup_parameter(priv, priv->need_commit);
297 priv->need_commit = 0;
301 static int ks_wlan_get_essid(struct net_device *dev,
302 struct iw_request_info *info,
303 struct iw_point *dwrq, char *extra)
305 struct ks_wlan_private *priv = netdev_priv(dev);
307 if (priv->sleep_mode == SLP_SLEEP)
311 /* Note : if dwrq->flags != 0, we should
312 * get the relevant SSID from the SSID list...
314 if (priv->reg.ssid.size != 0) {
315 /* Get the current SSID */
316 memcpy(extra, priv->reg.ssid.body, priv->reg.ssid.size);
318 /* If none, we may want to get the one that was set */
321 dwrq->length = priv->reg.ssid.size;
322 dwrq->flags = 1; /* active */
325 dwrq->flags = 0; /* ANY */
331 static int ks_wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
332 struct sockaddr *ap_addr, char *extra)
334 struct ks_wlan_private *priv = netdev_priv(dev);
336 if (priv->sleep_mode == SLP_SLEEP)
340 if (priv->reg.operation_mode == MODE_ADHOC ||
341 priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
342 memcpy(priv->reg.bssid, &ap_addr->sa_data, ETH_ALEN);
344 if (is_valid_ether_addr((u8 *)priv->reg.bssid))
345 priv->need_commit |= SME_MODE_SET;
348 eth_zero_addr(priv->reg.bssid);
352 netdev_dbg(dev, "bssid = %pM\n", priv->reg.bssid);
354 /* Write it to the card */
355 if (priv->need_commit) {
356 priv->need_commit |= SME_MODE_SET;
357 return -EINPROGRESS; /* Call commit handler */
362 static int ks_wlan_get_wap(struct net_device *dev, struct iw_request_info *info,
363 struct sockaddr *awrq, char *extra)
365 struct ks_wlan_private *priv = netdev_priv(dev);
367 if (priv->sleep_mode == SLP_SLEEP)
371 if (is_connect_status(priv->connect_status))
372 memcpy(awrq->sa_data, priv->current_ap.bssid, ETH_ALEN);
374 eth_zero_addr(awrq->sa_data);
376 awrq->sa_family = ARPHRD_ETHER;
381 static int ks_wlan_set_nick(struct net_device *dev,
382 struct iw_request_info *info, struct iw_point *dwrq,
385 struct ks_wlan_private *priv = netdev_priv(dev);
387 if (priv->sleep_mode == SLP_SLEEP)
391 /* Check the size of the string */
392 if (dwrq->length > 16 + 1)
395 memset(priv->nick, 0, sizeof(priv->nick));
396 memcpy(priv->nick, extra, dwrq->length);
398 return -EINPROGRESS; /* Call commit handler */
401 static int ks_wlan_get_nick(struct net_device *dev,
402 struct iw_request_info *info, struct iw_point *dwrq,
405 struct ks_wlan_private *priv = netdev_priv(dev);
407 if (priv->sleep_mode == SLP_SLEEP)
411 strncpy(extra, priv->nick, 16);
413 dwrq->length = strlen(extra) + 1;
418 static int ks_wlan_set_rate(struct net_device *dev,
419 struct iw_request_info *info, struct iw_param *vwrq,
422 struct ks_wlan_private *priv = netdev_priv(dev);
425 if (priv->sleep_mode == SLP_SLEEP)
429 if (priv->reg.phy_type == D_11B_ONLY_MODE) {
430 if (vwrq->fixed == 1) {
431 switch (vwrq->value) {
434 priv->reg.rate_set.body[0] =
435 (uint8_t)(vwrq->value / 500000);
439 priv->reg.rate_set.body[0] =
440 ((uint8_t)(vwrq->value / 500000)) |
446 priv->reg.tx_rate = TX_RATE_FIXED;
447 priv->reg.rate_set.size = 1;
448 } else { /* vwrq->fixed == 0 */
449 if (vwrq->value > 0) {
450 switch (vwrq->value) {
452 priv->reg.rate_set.body[3] =
457 priv->reg.rate_set.body[2] = TX_RATE_5M;
461 priv->reg.rate_set.body[1] =
462 TX_RATE_2M | BASIC_RATE;
466 priv->reg.rate_set.body[0] =
467 TX_RATE_1M | BASIC_RATE;
473 priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
474 priv->reg.rate_set.size = i;
476 priv->reg.rate_set.body[3] = TX_RATE_11M;
477 priv->reg.rate_set.body[2] = TX_RATE_5M;
478 priv->reg.rate_set.body[1] =
479 TX_RATE_2M | BASIC_RATE;
480 priv->reg.rate_set.body[0] =
481 TX_RATE_1M | BASIC_RATE;
482 priv->reg.tx_rate = TX_RATE_FULL_AUTO;
483 priv->reg.rate_set.size = 4;
486 } else { /* D_11B_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
487 if (vwrq->fixed == 1) {
488 switch (vwrq->value) {
494 priv->reg.rate_set.body[0] =
495 (uint8_t)(vwrq->value / 500000);
504 priv->reg.rate_set.body[0] =
505 ((uint8_t)(vwrq->value / 500000)) |
511 priv->reg.tx_rate = TX_RATE_FIXED;
512 priv->reg.rate_set.size = 1;
513 } else { /* vwrq->fixed == 0 */
514 if (vwrq->value > 0) {
515 switch (vwrq->value) {
517 priv->reg.rate_set.body[11] =
522 priv->reg.rate_set.body[10] =
527 priv->reg.rate_set.body[9] =
537 if (vwrq->value == 24000000) {
538 priv->reg.rate_set.body[8] =
541 priv->reg.rate_set.body[7] =
544 priv->reg.rate_set.body[6] =
545 TX_RATE_24M | BASIC_RATE;
547 priv->reg.rate_set.body[5] =
548 TX_RATE_12M | BASIC_RATE;
550 priv->reg.rate_set.body[4] =
551 TX_RATE_6M | BASIC_RATE;
553 priv->reg.rate_set.body[3] =
554 TX_RATE_11M | BASIC_RATE;
556 } else if (vwrq->value == 18000000) {
557 priv->reg.rate_set.body[7] =
560 priv->reg.rate_set.body[6] =
563 priv->reg.rate_set.body[5] =
564 TX_RATE_12M | BASIC_RATE;
566 priv->reg.rate_set.body[4] =
567 TX_RATE_6M | BASIC_RATE;
569 priv->reg.rate_set.body[3] =
570 TX_RATE_11M | BASIC_RATE;
572 } else if (vwrq->value == 12000000) {
573 priv->reg.rate_set.body[6] =
576 priv->reg.rate_set.body[5] =
577 TX_RATE_12M | BASIC_RATE;
579 priv->reg.rate_set.body[4] =
580 TX_RATE_6M | BASIC_RATE;
582 priv->reg.rate_set.body[3] =
583 TX_RATE_11M | BASIC_RATE;
585 } else if (vwrq->value == 11000000) {
586 priv->reg.rate_set.body[5] =
589 priv->reg.rate_set.body[4] =
590 TX_RATE_6M | BASIC_RATE;
592 priv->reg.rate_set.body[3] =
593 TX_RATE_11M | BASIC_RATE;
595 } else if (vwrq->value == 9000000) {
596 priv->reg.rate_set.body[4] =
599 priv->reg.rate_set.body[3] =
600 TX_RATE_6M | BASIC_RATE;
602 } else { /* vwrq->value == 6000000 */
603 priv->reg.rate_set.body[3] =
604 TX_RATE_6M | BASIC_RATE;
609 priv->reg.rate_set.body[2] =
610 TX_RATE_5M | BASIC_RATE;
614 priv->reg.rate_set.body[1] =
615 TX_RATE_2M | BASIC_RATE;
619 priv->reg.rate_set.body[0] =
620 TX_RATE_1M | BASIC_RATE;
626 priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
627 priv->reg.rate_set.size = i;
629 priv->reg.rate_set.body[11] = TX_RATE_54M;
630 priv->reg.rate_set.body[10] = TX_RATE_48M;
631 priv->reg.rate_set.body[9] = TX_RATE_36M;
632 priv->reg.rate_set.body[8] = TX_RATE_18M;
633 priv->reg.rate_set.body[7] = TX_RATE_9M;
634 priv->reg.rate_set.body[6] =
635 TX_RATE_24M | BASIC_RATE;
636 priv->reg.rate_set.body[5] =
637 TX_RATE_12M | BASIC_RATE;
638 priv->reg.rate_set.body[4] =
639 TX_RATE_6M | BASIC_RATE;
640 priv->reg.rate_set.body[3] =
641 TX_RATE_11M | BASIC_RATE;
642 priv->reg.rate_set.body[2] =
643 TX_RATE_5M | BASIC_RATE;
644 priv->reg.rate_set.body[1] =
645 TX_RATE_2M | BASIC_RATE;
646 priv->reg.rate_set.body[0] =
647 TX_RATE_1M | BASIC_RATE;
648 priv->reg.tx_rate = TX_RATE_FULL_AUTO;
649 priv->reg.rate_set.size = 12;
654 priv->need_commit |= SME_MODE_SET;
656 return -EINPROGRESS; /* Call commit handler */
659 static int ks_wlan_get_rate(struct net_device *dev,
660 struct iw_request_info *info, struct iw_param *vwrq,
663 struct ks_wlan_private *priv = netdev_priv(dev);
665 netdev_dbg(dev, "in_interrupt = %ld update_phyinfo = %d\n",
666 in_interrupt(), atomic_read(&update_phyinfo));
668 if (priv->sleep_mode == SLP_SLEEP)
672 if (!atomic_read(&update_phyinfo))
673 ks_wlan_update_phy_information(priv);
675 vwrq->value = ((priv->current_rate) & RATE_MASK) * 500000;
676 if (priv->reg.tx_rate == TX_RATE_FIXED)
684 static int ks_wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
685 struct iw_param *vwrq, char *extra)
687 struct ks_wlan_private *priv = netdev_priv(dev);
688 int rthr = vwrq->value;
690 if (priv->sleep_mode == SLP_SLEEP)
696 if ((rthr < 0) || (rthr > 2347))
699 priv->reg.rts = rthr;
700 priv->need_commit |= SME_RTS;
702 return -EINPROGRESS; /* Call commit handler */
705 static int ks_wlan_get_rts(struct net_device *dev, struct iw_request_info *info,
706 struct iw_param *vwrq, char *extra)
708 struct ks_wlan_private *priv = netdev_priv(dev);
710 if (priv->sleep_mode == SLP_SLEEP)
714 vwrq->value = priv->reg.rts;
715 vwrq->disabled = (vwrq->value >= 2347);
721 static int ks_wlan_set_frag(struct net_device *dev,
722 struct iw_request_info *info, struct iw_param *vwrq,
725 struct ks_wlan_private *priv = netdev_priv(dev);
726 int fthr = vwrq->value;
728 if (priv->sleep_mode == SLP_SLEEP)
734 if ((fthr < 256) || (fthr > 2346))
737 fthr &= ~0x1; /* Get an even value - is it really needed ??? */
738 priv->reg.fragment = fthr;
739 priv->need_commit |= SME_FRAG;
741 return -EINPROGRESS; /* Call commit handler */
744 static int ks_wlan_get_frag(struct net_device *dev,
745 struct iw_request_info *info, struct iw_param *vwrq,
748 struct ks_wlan_private *priv = netdev_priv(dev);
750 if (priv->sleep_mode == SLP_SLEEP)
754 vwrq->value = priv->reg.fragment;
755 vwrq->disabled = (vwrq->value >= 2346);
761 static int ks_wlan_set_mode(struct net_device *dev,
762 struct iw_request_info *info, __u32 *uwrq,
765 struct ks_wlan_private *priv = netdev_priv(dev);
767 if (priv->sleep_mode == SLP_SLEEP)
773 priv->reg.operation_mode = MODE_ADHOC;
774 priv->need_commit |= SME_MODE_SET;
777 priv->reg.operation_mode = MODE_INFRASTRUCTURE;
778 priv->need_commit |= SME_MODE_SET;
784 case IW_MODE_MONITOR:
789 return -EINPROGRESS; /* Call commit handler */
792 static int ks_wlan_get_mode(struct net_device *dev,
793 struct iw_request_info *info, __u32 *uwrq,
796 struct ks_wlan_private *priv = netdev_priv(dev);
798 if (priv->sleep_mode == SLP_SLEEP)
802 /* If not managed, assume it's ad-hoc */
803 switch (priv->reg.operation_mode) {
804 case MODE_INFRASTRUCTURE:
805 *uwrq = IW_MODE_INFRA;
808 *uwrq = IW_MODE_ADHOC;
811 *uwrq = IW_MODE_ADHOC;
817 static int ks_wlan_set_encode(struct net_device *dev,
818 struct iw_request_info *info,
819 struct iw_point *dwrq, char *extra)
821 struct ks_wlan_private *priv = netdev_priv(dev);
824 int index = (dwrq->flags & IW_ENCODE_INDEX);
825 int current_index = priv->reg.wep_index;
828 if (priv->sleep_mode == SLP_SLEEP)
833 if ((index < 0) || (index > 4))
836 index = current_index;
840 /* Is WEP supported ? */
841 /* Basic checking: do we have a key to set ? */
842 if (dwrq->length > 0) {
843 if (dwrq->length > MAX_KEY_SIZE) { /* Check the size of the key */
846 if (dwrq->length > MIN_KEY_SIZE) { /* Set the length */
847 key.len = MAX_KEY_SIZE;
848 priv->reg.privacy_invoked = 0x01;
849 priv->need_commit |= SME_WEP_FLAG;
850 wep_on_off = WEP_ON_128BIT;
852 if (dwrq->length > 0) {
853 key.len = MIN_KEY_SIZE;
854 priv->reg.privacy_invoked = 0x01;
855 priv->need_commit |= SME_WEP_FLAG;
856 wep_on_off = WEP_ON_64BIT;
857 } else { /* Disable the key */
861 /* Check if the key is not marked as invalid */
862 if (!(dwrq->flags & IW_ENCODE_NOKEY)) {
864 memset(key.key, 0, MAX_KEY_SIZE);
865 /* Copy the key in the driver */
867 (key.key, dwrq->pointer, dwrq->length)) {
871 /* Send the key to the card */
872 priv->reg.wep_key[index].size = key.len;
873 for (i = 0; i < (priv->reg.wep_key[index].size); i++)
874 priv->reg.wep_key[index].val[i] = key.key[i];
876 priv->need_commit |= (SME_WEP_VAL1 << index);
877 priv->reg.wep_index = index;
878 priv->need_commit |= SME_WEP_INDEX;
881 if (dwrq->flags & IW_ENCODE_DISABLED) {
882 priv->reg.wep_key[0].size = 0;
883 priv->reg.wep_key[1].size = 0;
884 priv->reg.wep_key[2].size = 0;
885 priv->reg.wep_key[3].size = 0;
886 priv->reg.privacy_invoked = 0x00;
887 if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY)
888 priv->need_commit |= SME_MODE_SET;
890 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
891 wep_on_off = WEP_OFF;
892 priv->need_commit |= SME_WEP_FLAG;
894 /* Do we want to just set the transmit key index ? */
895 if ((index >= 0) && (index < 4)) {
896 /* set_wep_key(priv, index, 0, 0, 1); xxx */
897 if (priv->reg.wep_key[index].size != 0) {
898 priv->reg.wep_index = index;
899 priv->need_commit |= SME_WEP_INDEX;
907 /* Commit the changes if needed */
908 if (dwrq->flags & IW_ENCODE_MODE)
909 priv->need_commit |= SME_WEP_FLAG;
911 if (dwrq->flags & IW_ENCODE_OPEN) {
912 if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY)
913 priv->need_commit |= SME_MODE_SET;
915 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
916 } else if (dwrq->flags & IW_ENCODE_RESTRICTED) {
917 if (priv->reg.authenticate_type == AUTH_TYPE_OPEN_SYSTEM)
918 priv->need_commit |= SME_MODE_SET;
920 priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
922 // return -EINPROGRESS; /* Call commit handler */
923 if (priv->need_commit) {
924 ks_wlan_setup_parameter(priv, priv->need_commit);
925 priv->need_commit = 0;
930 static int ks_wlan_get_encode(struct net_device *dev,
931 struct iw_request_info *info,
932 struct iw_point *dwrq, char *extra)
934 struct ks_wlan_private *priv = netdev_priv(dev);
936 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
938 if (priv->sleep_mode == SLP_SLEEP)
942 dwrq->flags = IW_ENCODE_DISABLED;
944 /* Check encryption mode */
945 switch (priv->reg.authenticate_type) {
946 case AUTH_TYPE_OPEN_SYSTEM:
947 dwrq->flags = IW_ENCODE_OPEN;
949 case AUTH_TYPE_SHARED_KEY:
950 dwrq->flags = IW_ENCODE_RESTRICTED;
954 memset(zeros, 0, sizeof(zeros));
956 /* Which key do we want ? -1 -> tx index */
957 if ((index < 0) || (index >= 4))
958 index = priv->reg.wep_index;
959 if (priv->reg.privacy_invoked) {
960 dwrq->flags &= ~IW_ENCODE_DISABLED;
961 /* dwrq->flags |= IW_ENCODE_NOKEY; */
963 dwrq->flags |= index + 1;
964 /* Copy the key to the user buffer */
965 if ((index >= 0) && (index < 4))
966 dwrq->length = priv->reg.wep_key[index].size;
967 if (dwrq->length > 16)
969 #if 1 /* IW_ENCODE_NOKEY; */
971 if ((index >= 0) && (index < 4))
972 memcpy(extra, priv->reg.wep_key[index].val,
975 memcpy(extra, zeros, dwrq->length);
981 #ifndef KSC_OPNOTSUPP
982 static int ks_wlan_set_txpow(struct net_device *dev,
983 struct iw_request_info *info,
984 struct iw_param *vwrq, char *extra)
986 return -EOPNOTSUPP; /* Not Support */
989 static int ks_wlan_get_txpow(struct net_device *dev,
990 struct iw_request_info *info,
991 struct iw_param *vwrq, char *extra)
993 if (priv->sleep_mode == SLP_SLEEP)
999 vwrq->disabled = (vwrq->value == 0);
1004 static int ks_wlan_set_retry(struct net_device *dev,
1005 struct iw_request_info *info,
1006 struct iw_param *vwrq, char *extra)
1008 return -EOPNOTSUPP; /* Not Support */
1011 static int ks_wlan_get_retry(struct net_device *dev,
1012 struct iw_request_info *info,
1013 struct iw_param *vwrq, char *extra)
1015 if (priv->sleep_mode == SLP_SLEEP)
1018 /* for SLEEP MODE */
1021 vwrq->disabled = (vwrq->value == 0);
1025 #endif /* KSC_OPNOTSUPP */
1027 static int ks_wlan_get_range(struct net_device *dev,
1028 struct iw_request_info *info,
1029 struct iw_point *dwrq, char *extra)
1031 struct ks_wlan_private *priv = netdev_priv(dev);
1032 struct iw_range *range = (struct iw_range *)extra;
1035 if (priv->sleep_mode == SLP_SLEEP)
1038 /* for SLEEP MODE */
1039 dwrq->length = sizeof(struct iw_range);
1040 memset(range, 0, sizeof(*range));
1041 range->min_nwid = 0x0000;
1042 range->max_nwid = 0x0000;
1043 range->num_channels = 14;
1044 /* Should be based on cap_rid.country to give only
1045 * what the current card support
1048 for (i = 0; i < 13; i++) { /* channel 1 -- 13 */
1049 range->freq[k].i = i + 1; /* List index */
1050 range->freq[k].m = frequency_list[i] * 100000;
1051 range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
1053 range->num_frequency = k;
1054 if (priv->reg.phy_type == D_11B_ONLY_MODE || priv->reg.phy_type == D_11BG_COMPATIBLE_MODE) { /* channel 14 */
1055 range->freq[13].i = 14; /* List index */
1056 range->freq[13].m = frequency_list[13] * 100000;
1057 range->freq[13].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
1058 range->num_frequency = 14;
1061 /* Hum... Should put the right values there */
1062 range->max_qual.qual = 100;
1063 range->max_qual.level = 256 - 128; /* 0 dBm? */
1064 range->max_qual.noise = 256 - 128;
1065 range->sensitivity = 1;
1067 if (priv->reg.phy_type == D_11B_ONLY_MODE) {
1068 range->bitrate[0] = 1e6;
1069 range->bitrate[1] = 2e6;
1070 range->bitrate[2] = 5.5e6;
1071 range->bitrate[3] = 11e6;
1072 range->num_bitrates = 4;
1073 } else { /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
1074 range->bitrate[0] = 1e6;
1075 range->bitrate[1] = 2e6;
1076 range->bitrate[2] = 5.5e6;
1077 range->bitrate[3] = 11e6;
1079 range->bitrate[4] = 6e6;
1080 range->bitrate[5] = 9e6;
1081 range->bitrate[6] = 12e6;
1082 if (IW_MAX_BITRATES < 9) {
1083 range->bitrate[7] = 54e6;
1084 range->num_bitrates = 8;
1086 range->bitrate[7] = 18e6;
1087 range->bitrate[8] = 24e6;
1088 range->bitrate[9] = 36e6;
1089 range->bitrate[10] = 48e6;
1090 range->bitrate[11] = 54e6;
1092 range->num_bitrates = 12;
1096 /* Set an indication of the max TCP throughput
1097 * in bit/s that we can expect using this interface.
1098 * May be use for QoS stuff... Jean II
1101 range->throughput = 5000 * 1000;
1103 range->throughput = 1500 * 1000;
1106 range->max_rts = 2347;
1107 range->min_frag = 256;
1108 range->max_frag = 2346;
1110 range->encoding_size[0] = 5; /* WEP: RC4 40 bits */
1111 range->encoding_size[1] = 13; /* WEP: RC4 ~128 bits */
1112 range->num_encoding_sizes = 2;
1113 range->max_encoding_tokens = 4;
1115 /* power management not support */
1116 range->pmp_flags = IW_POWER_ON;
1117 range->pmt_flags = IW_POWER_ON;
1120 /* Transmit Power - values are in dBm( or mW) */
1121 range->txpower[0] = -256;
1122 range->num_txpower = 1;
1123 range->txpower_capa = IW_TXPOW_DBM;
1124 /* range->txpower_capa = IW_TXPOW_MWATT; */
1126 range->we_version_source = 21;
1127 range->we_version_compiled = WIRELESS_EXT;
1129 range->retry_capa = IW_RETRY_ON;
1130 range->retry_flags = IW_RETRY_ON;
1131 range->r_time_flags = IW_RETRY_ON;
1133 /* Experimental measurements - boundary 11/5.5 Mb/s
1135 * Note : with or without the (local->rssi), results
1136 * are somewhat different. - Jean II
1138 range->avg_qual.qual = 50;
1139 range->avg_qual.level = 186; /* -70 dBm */
1140 range->avg_qual.noise = 0;
1142 /* Event capability (kernel + driver) */
1143 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
1144 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
1145 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
1146 range->event_capa[1] = IW_EVENT_CAPA_K_1;
1147 range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVCUSTOM) |
1148 IW_EVENT_CAPA_MASK(IWEVMICHAELMICFAILURE));
1150 /* encode extension (WPA) capability */
1151 range->enc_capa = (IW_ENC_CAPA_WPA |
1153 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP);
1157 static int ks_wlan_set_power(struct net_device *dev,
1158 struct iw_request_info *info,
1159 struct iw_param *vwrq, char *extra)
1161 struct ks_wlan_private *priv = netdev_priv(dev);
1163 if (priv->sleep_mode == SLP_SLEEP)
1166 if (vwrq->disabled) {
1167 priv->reg.power_mgmt = POWER_MGMT_ACTIVE;
1169 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
1170 priv->reg.power_mgmt = POWER_MGMT_SAVE1;
1175 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
1180 static int ks_wlan_get_power(struct net_device *dev,
1181 struct iw_request_info *info,
1182 struct iw_param *vwrq, char *extra)
1184 struct ks_wlan_private *priv = netdev_priv(dev);
1186 if (priv->sleep_mode == SLP_SLEEP)
1188 /* for SLEEP MODE */
1189 if (priv->reg.power_mgmt > 0)
1197 static int ks_wlan_get_iwstats(struct net_device *dev,
1198 struct iw_request_info *info,
1199 struct iw_quality *vwrq, char *extra)
1201 struct ks_wlan_private *priv = netdev_priv(dev);
1203 if (priv->sleep_mode == SLP_SLEEP)
1205 /* for SLEEP MODE */
1206 vwrq->qual = 0; /* not supported */
1207 vwrq->level = priv->wstats.qual.level;
1208 vwrq->noise = 0; /* not supported */
1214 #ifndef KSC_OPNOTSUPP
1216 static int ks_wlan_set_sens(struct net_device *dev,
1217 struct iw_request_info *info, struct iw_param *vwrq,
1220 return -EOPNOTSUPP; /* Not Support */
1223 static int ks_wlan_get_sens(struct net_device *dev,
1224 struct iw_request_info *info, struct iw_param *vwrq,
1229 vwrq->disabled = (vwrq->value == 0);
1233 #endif /* KSC_OPNOTSUPP */
1235 /* Note : this is deprecated in favor of IWSCAN */
1236 static int ks_wlan_get_aplist(struct net_device *dev,
1237 struct iw_request_info *info,
1238 struct iw_point *dwrq, char *extra)
1240 struct ks_wlan_private *priv = netdev_priv(dev);
1241 struct sockaddr *address = (struct sockaddr *)extra;
1242 struct iw_quality qual[LOCAL_APLIST_MAX];
1246 if (priv->sleep_mode == SLP_SLEEP)
1248 /* for SLEEP MODE */
1249 for (i = 0; i < priv->aplist.size; i++) {
1250 memcpy(address[i].sa_data, &(priv->aplist.ap[i].bssid[0]),
1252 address[i].sa_family = ARPHRD_ETHER;
1253 qual[i].level = 256 - priv->aplist.ap[i].rssi;
1254 qual[i].qual = priv->aplist.ap[i].sq;
1255 qual[i].noise = 0; /* invalid noise value */
1256 qual[i].updated = 7;
1259 dwrq->flags = 1; /* Should be define'd */
1260 memcpy(extra + sizeof(struct sockaddr) * i,
1261 &qual, sizeof(struct iw_quality) * i);
1268 static int ks_wlan_set_scan(struct net_device *dev,
1269 struct iw_request_info *info,
1270 union iwreq_data *wrqu, char *extra)
1272 struct ks_wlan_private *priv = netdev_priv(dev);
1273 struct iw_scan_req *req = NULL;
1275 if (priv->sleep_mode == SLP_SLEEP)
1278 /* for SLEEP MODE */
1279 /* specified SSID SCAN */
1280 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
1281 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1282 req = (struct iw_scan_req *)extra;
1283 priv->scan_ssid_len = req->essid_len;
1284 memcpy(priv->scan_ssid, req->essid, priv->scan_ssid_len);
1286 priv->scan_ssid_len = 0;
1289 priv->sme_i.sme_flag |= SME_AP_SCAN;
1290 hostif_sme_enqueue(priv, SME_BSS_SCAN_REQUEST);
1292 /* At this point, just return to the user. */
1298 * Translate scan data returned from the card to a card independent
1299 * format that the Wireless Tools will understand - Jean II
1301 static inline char *ks_wlan_translate_scan(struct net_device *dev,
1302 struct iw_request_info *info,
1303 char *current_ev, char *end_buf,
1304 struct local_ap *ap)
1306 /* struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; */
1307 struct iw_event iwe; /* Temporary buffer */
1309 char *current_val; /* For rates */
1311 static const char rsn_leader[] = "rsn_ie=";
1312 static const char wpa_leader[] = "wpa_ie=";
1313 char buf0[RSN_IE_BODY_MAX * 2 + 30];
1314 char buf1[RSN_IE_BODY_MAX * 2 + 30];
1316 /* First entry *MUST* be the AP MAC address */
1317 iwe.cmd = SIOCGIWAP;
1318 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1319 memcpy(iwe.u.ap_addr.sa_data, ap->bssid, ETH_ALEN);
1321 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1324 /* Other entries will be displayed in the order we give them */
1327 iwe.u.data.length = ap->ssid.size;
1328 if (iwe.u.data.length > 32)
1329 iwe.u.data.length = 32;
1330 iwe.cmd = SIOCGIWESSID;
1331 iwe.u.data.flags = 1;
1333 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1337 iwe.cmd = SIOCGIWMODE;
1338 capabilities = ap->capability;
1339 if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
1340 if (capabilities & WLAN_CAPABILITY_ESS)
1341 iwe.u.mode = IW_MODE_INFRA;
1343 iwe.u.mode = IW_MODE_ADHOC;
1345 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1350 iwe.cmd = SIOCGIWFREQ;
1351 iwe.u.freq.m = ap->channel;
1352 iwe.u.freq.m = frequency_list[iwe.u.freq.m - 1] * 100000;
1355 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1358 /* Add quality statistics */
1360 iwe.u.qual.level = 256 - ap->rssi;
1361 iwe.u.qual.qual = ap->sq;
1362 iwe.u.qual.noise = 0; /* invalid noise value */
1364 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1367 /* Add encryption capability */
1368 iwe.cmd = SIOCGIWENCODE;
1369 if (capabilities & WLAN_CAPABILITY_PRIVACY)
1370 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1372 iwe.u.data.flags = IW_ENCODE_DISABLED;
1373 iwe.u.data.length = 0;
1375 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1378 /* Rate : stuffing multiple values in a single event require a bit
1379 * more of magic - Jean II
1381 current_val = current_ev + IW_EV_LCP_LEN;
1383 iwe.cmd = SIOCGIWRATE;
1385 /* These two flags are ignored... */
1386 iwe.u.bitrate.fixed = 0;
1387 iwe.u.bitrate.disabled = 0;
1390 for (i = 0; i < 16; i++) {
1391 /* NULL terminated */
1392 if (i >= ap->rate_set.size)
1394 /* Bit rate given in 500 kb/s units (+ 0x80) */
1395 iwe.u.bitrate.value = ((ap->rate_set.body[i] & 0x7f) * 500000);
1396 /* Add new value to event */
1398 iwe_stream_add_value(info, current_ev, current_val, end_buf,
1399 &iwe, IW_EV_PARAM_LEN);
1401 /* Check if we added any event */
1402 if ((current_val - current_ev) > IW_EV_LCP_LEN)
1403 current_ev = current_val;
1405 #define GENERIC_INFO_ELEM_ID 0xdd
1406 #define RSN_INFO_ELEM_ID 0x30
1407 if (ap->rsn_ie.id == RSN_INFO_ELEM_ID && ap->rsn_ie.size != 0) {
1409 memset(&iwe, 0, sizeof(iwe));
1410 iwe.cmd = IWEVCUSTOM;
1411 memcpy(buf0, rsn_leader, sizeof(rsn_leader) - 1);
1412 iwe.u.data.length += sizeof(rsn_leader) - 1;
1413 pbuf += sizeof(rsn_leader) - 1;
1415 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.id);
1416 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.size);
1417 iwe.u.data.length += 4;
1419 for (i = 0; i < ap->rsn_ie.size; i++)
1420 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.body[i]);
1421 iwe.u.data.length += (ap->rsn_ie.size) * 2;
1423 netdev_dbg(dev, "ap->rsn.size=%d\n", ap->rsn_ie.size);
1426 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1429 if (ap->wpa_ie.id == GENERIC_INFO_ELEM_ID && ap->wpa_ie.size != 0) {
1431 memset(&iwe, 0, sizeof(iwe));
1432 iwe.cmd = IWEVCUSTOM;
1433 memcpy(buf1, wpa_leader, sizeof(wpa_leader) - 1);
1434 iwe.u.data.length += sizeof(wpa_leader) - 1;
1435 pbuf += sizeof(wpa_leader) - 1;
1437 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.id);
1438 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.size);
1439 iwe.u.data.length += 4;
1441 for (i = 0; i < ap->wpa_ie.size; i++)
1442 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.body[i]);
1443 iwe.u.data.length += (ap->wpa_ie.size) * 2;
1445 netdev_dbg(dev, "ap->rsn.size=%d\n", ap->wpa_ie.size);
1446 netdev_dbg(dev, "iwe.u.data.length=%d\n", iwe.u.data.length);
1449 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1453 /* The other data in the scan result are not really
1454 * interesting, so for now drop it - Jean II
1459 static int ks_wlan_get_scan(struct net_device *dev,
1460 struct iw_request_info *info, struct iw_point *dwrq,
1463 struct ks_wlan_private *priv = netdev_priv(dev);
1465 char *current_ev = extra;
1467 if (priv->sleep_mode == SLP_SLEEP)
1469 /* for SLEEP MODE */
1470 if (priv->sme_i.sme_flag & SME_AP_SCAN)
1473 if (priv->aplist.size == 0) {
1474 /* Client error, no scan results...
1475 * The caller need to restart the scan.
1480 /* Read and parse all entries */
1481 for (i = 0; i < priv->aplist.size; i++) {
1482 if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) {
1486 /* Translate to WE format this entry */
1487 current_ev = ks_wlan_translate_scan(dev, info, current_ev,
1488 extra + dwrq->length,
1489 &priv->aplist.ap[i]);
1491 /* Length of data */
1492 dwrq->length = (current_ev - extra);
1498 /* called after a bunch of SET operations */
1499 static int ks_wlan_config_commit(struct net_device *dev,
1500 struct iw_request_info *info, void *zwrq,
1503 struct ks_wlan_private *priv = netdev_priv(dev);
1505 if (!priv->need_commit)
1508 ks_wlan_setup_parameter(priv, priv->need_commit);
1509 priv->need_commit = 0;
1513 /* set association ie params */
1514 static int ks_wlan_set_genie(struct net_device *dev,
1515 struct iw_request_info *info,
1516 struct iw_point *dwrq, char *extra)
1518 struct ks_wlan_private *priv = netdev_priv(dev);
1520 if (priv->sleep_mode == SLP_SLEEP)
1522 /* for SLEEP MODE */
1524 // return -EOPNOTSUPP;
1527 static int ks_wlan_set_auth_mode(struct net_device *dev,
1528 struct iw_request_info *info,
1529 struct iw_param *vwrq, char *extra)
1531 struct ks_wlan_private *priv = netdev_priv(dev);
1532 int index = (vwrq->flags & IW_AUTH_INDEX);
1533 int value = vwrq->value;
1535 if (priv->sleep_mode == SLP_SLEEP)
1537 /* for SLEEP MODE */
1539 case IW_AUTH_WPA_VERSION: /* 0 */
1541 case IW_AUTH_WPA_VERSION_DISABLED:
1542 priv->wpa.version = value;
1543 if (priv->wpa.rsn_enabled)
1544 priv->wpa.rsn_enabled = 0;
1545 priv->need_commit |= SME_RSN;
1547 case IW_AUTH_WPA_VERSION_WPA:
1548 case IW_AUTH_WPA_VERSION_WPA2:
1549 priv->wpa.version = value;
1550 if (!(priv->wpa.rsn_enabled))
1551 priv->wpa.rsn_enabled = 1;
1552 priv->need_commit |= SME_RSN;
1558 case IW_AUTH_CIPHER_PAIRWISE: /* 1 */
1560 case IW_AUTH_CIPHER_NONE:
1561 if (priv->reg.privacy_invoked) {
1562 priv->reg.privacy_invoked = 0x00;
1563 priv->need_commit |= SME_WEP_FLAG;
1566 case IW_AUTH_CIPHER_WEP40:
1567 case IW_AUTH_CIPHER_TKIP:
1568 case IW_AUTH_CIPHER_CCMP:
1569 case IW_AUTH_CIPHER_WEP104:
1570 if (!priv->reg.privacy_invoked) {
1571 priv->reg.privacy_invoked = 0x01;
1572 priv->need_commit |= SME_WEP_FLAG;
1574 priv->wpa.pairwise_suite = value;
1575 priv->need_commit |= SME_RSN_UNICAST;
1581 case IW_AUTH_CIPHER_GROUP: /* 2 */
1583 case IW_AUTH_CIPHER_NONE:
1584 if (priv->reg.privacy_invoked) {
1585 priv->reg.privacy_invoked = 0x00;
1586 priv->need_commit |= SME_WEP_FLAG;
1589 case IW_AUTH_CIPHER_WEP40:
1590 case IW_AUTH_CIPHER_TKIP:
1591 case IW_AUTH_CIPHER_CCMP:
1592 case IW_AUTH_CIPHER_WEP104:
1593 if (!priv->reg.privacy_invoked) {
1594 priv->reg.privacy_invoked = 0x01;
1595 priv->need_commit |= SME_WEP_FLAG;
1597 priv->wpa.group_suite = value;
1598 priv->need_commit |= SME_RSN_MULTICAST;
1604 case IW_AUTH_KEY_MGMT: /* 3 */
1606 case IW_AUTH_KEY_MGMT_802_1X:
1607 case IW_AUTH_KEY_MGMT_PSK:
1608 case 0: /* NONE or 802_1X_NO_WPA */
1609 case 4: /* WPA_NONE */
1610 priv->wpa.key_mgmt_suite = value;
1611 priv->need_commit |= SME_RSN_AUTH;
1617 case IW_AUTH_80211_AUTH_ALG: /* 6 */
1619 case IW_AUTH_ALG_OPEN_SYSTEM:
1620 priv->wpa.auth_alg = value;
1621 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
1623 case IW_AUTH_ALG_SHARED_KEY:
1624 priv->wpa.auth_alg = value;
1625 priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
1627 case IW_AUTH_ALG_LEAP:
1631 priv->need_commit |= SME_MODE_SET;
1633 case IW_AUTH_WPA_ENABLED: /* 7 */
1634 priv->wpa.wpa_enabled = value;
1636 case IW_AUTH_PRIVACY_INVOKED: /* 10 */
1637 if ((value && !priv->reg.privacy_invoked) ||
1638 (!value && priv->reg.privacy_invoked)) {
1639 priv->reg.privacy_invoked = value ? 0x01 : 0x00;
1640 priv->need_commit |= SME_WEP_FLAG;
1643 case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* 4 */
1644 case IW_AUTH_TKIP_COUNTERMEASURES: /* 5 */
1645 case IW_AUTH_DROP_UNENCRYPTED: /* 8 */
1646 case IW_AUTH_ROAMING_CONTROL: /* 9 */
1651 /* return -EINPROGRESS; */
1652 if (priv->need_commit) {
1653 ks_wlan_setup_parameter(priv, priv->need_commit);
1654 priv->need_commit = 0;
1659 static int ks_wlan_get_auth_mode(struct net_device *dev,
1660 struct iw_request_info *info,
1661 struct iw_param *vwrq, char *extra)
1663 struct ks_wlan_private *priv = netdev_priv(dev);
1664 int index = (vwrq->flags & IW_AUTH_INDEX);
1666 if (priv->sleep_mode == SLP_SLEEP)
1669 /* for SLEEP MODE */
1670 /* WPA (not used ?? wpa_supplicant) */
1672 case IW_AUTH_WPA_VERSION:
1673 vwrq->value = priv->wpa.version;
1675 case IW_AUTH_CIPHER_PAIRWISE:
1676 vwrq->value = priv->wpa.pairwise_suite;
1678 case IW_AUTH_CIPHER_GROUP:
1679 vwrq->value = priv->wpa.group_suite;
1681 case IW_AUTH_KEY_MGMT:
1682 vwrq->value = priv->wpa.key_mgmt_suite;
1684 case IW_AUTH_80211_AUTH_ALG:
1685 vwrq->value = priv->wpa.auth_alg;
1687 case IW_AUTH_WPA_ENABLED:
1688 vwrq->value = priv->wpa.rsn_enabled;
1690 case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* OK??? */
1691 case IW_AUTH_TKIP_COUNTERMEASURES:
1692 case IW_AUTH_DROP_UNENCRYPTED:
1694 /* return -EOPNOTSUPP; */
1700 /* set encoding token & mode (WPA)*/
1701 static int ks_wlan_set_encode_ext(struct net_device *dev,
1702 struct iw_request_info *info,
1703 struct iw_point *dwrq, char *extra)
1705 struct ks_wlan_private *priv = netdev_priv(dev);
1706 struct iw_encode_ext *enc;
1707 int index = dwrq->flags & IW_ENCODE_INDEX;
1708 unsigned int commit = 0;
1709 struct wpa_key *key;
1711 enc = (struct iw_encode_ext *)extra;
1715 if (priv->sleep_mode == SLP_SLEEP)
1718 /* for SLEEP MODE */
1719 if (index < 1 || index > 4)
1722 key = &priv->wpa.key[index];
1724 if (dwrq->flags & IW_ENCODE_DISABLED)
1727 key->ext_flags = enc->ext_flags;
1728 if (enc->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
1729 priv->wpa.txkey = index;
1730 commit |= SME_WEP_INDEX;
1731 } else if (enc->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
1732 memcpy(&key->rx_seq[0], &enc->rx_seq[0], IW_ENCODE_SEQ_MAX_SIZE);
1735 memcpy(&key->addr.sa_data[0], &enc->addr.sa_data[0], ETH_ALEN);
1738 case IW_ENCODE_ALG_NONE:
1739 if (priv->reg.privacy_invoked) {
1740 priv->reg.privacy_invoked = 0x00;
1741 commit |= SME_WEP_FLAG;
1746 case IW_ENCODE_ALG_WEP:
1747 case IW_ENCODE_ALG_CCMP:
1748 if (!priv->reg.privacy_invoked) {
1749 priv->reg.privacy_invoked = 0x01;
1750 commit |= SME_WEP_FLAG;
1753 memcpy(&key->key_val[0], &enc->key[0], enc->key_len);
1754 key->key_len = enc->key_len;
1755 commit |= (SME_WEP_VAL1 << index);
1758 case IW_ENCODE_ALG_TKIP:
1759 if (!priv->reg.privacy_invoked) {
1760 priv->reg.privacy_invoked = 0x01;
1761 commit |= SME_WEP_FLAG;
1763 if (enc->key_len == 32) {
1764 memcpy(&key->key_val[0], &enc->key[0], enc->key_len - 16);
1765 key->key_len = enc->key_len - 16;
1766 if (priv->wpa.key_mgmt_suite == 4) { /* WPA_NONE */
1767 memcpy(&key->tx_mic_key[0], &enc->key[16], 8);
1768 memcpy(&key->rx_mic_key[0], &enc->key[16], 8);
1770 memcpy(&key->tx_mic_key[0], &enc->key[16], 8);
1771 memcpy(&key->rx_mic_key[0], &enc->key[24], 8);
1773 commit |= (SME_WEP_VAL1 << index);
1779 key->alg = enc->alg;
1782 if (commit & SME_WEP_INDEX)
1783 hostif_sme_enqueue(priv, SME_SET_TXKEY);
1784 if (commit & SME_WEP_VAL_MASK)
1785 hostif_sme_enqueue(priv, SME_SET_KEY1 + index);
1786 if (commit & SME_WEP_FLAG)
1787 hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
1793 /* get encoding token & mode (WPA)*/
1794 static int ks_wlan_get_encode_ext(struct net_device *dev,
1795 struct iw_request_info *info,
1796 struct iw_point *dwrq, char *extra)
1798 struct ks_wlan_private *priv = netdev_priv(dev);
1800 if (priv->sleep_mode == SLP_SLEEP)
1803 /* for SLEEP MODE */
1804 /* WPA (not used ?? wpa_supplicant)
1805 * struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
1806 * struct iw_encode_ext *enc;
1807 * enc = (struct iw_encode_ext *)extra;
1808 * int index = dwrq->flags & IW_ENCODE_INDEX;
1809 * WPA (not used ?? wpa_supplicant)
1814 static int ks_wlan_set_pmksa(struct net_device *dev,
1815 struct iw_request_info *info,
1816 struct iw_point *dwrq, char *extra)
1818 struct ks_wlan_private *priv = netdev_priv(dev);
1819 struct iw_pmksa *pmksa;
1822 struct list_head *ptr;
1824 if (priv->sleep_mode == SLP_SLEEP)
1827 /* for SLEEP MODE */
1831 pmksa = (struct iw_pmksa *)extra;
1833 switch (pmksa->cmd) {
1835 if (list_empty(&priv->pmklist.head)) { /* new list */
1836 for (i = 0; i < PMK_LIST_MAX; i++) {
1837 pmk = &priv->pmklist.pmk[i];
1838 if (memcmp("\x00\x00\x00\x00\x00\x00",
1839 pmk->bssid, ETH_ALEN) == 0)
1842 memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
1843 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1844 list_add(&pmk->list, &priv->pmklist.head);
1845 priv->pmklist.size++;
1848 /* search cache data */
1849 list_for_each(ptr, &priv->pmklist.head) {
1850 pmk = list_entry(ptr, struct pmk, list);
1851 if (memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN) == 0) {
1852 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1853 list_move(&pmk->list, &priv->pmklist.head);
1854 break; /* list_for_each */
1857 if (ptr != &priv->pmklist.head) /* not find address. */
1860 if (priv->pmklist.size < PMK_LIST_MAX) { /* new cache data */
1861 for (i = 0; i < PMK_LIST_MAX; i++) {
1862 pmk = &priv->pmklist.pmk[i];
1863 if (memcmp("\x00\x00\x00\x00\x00\x00",
1864 pmk->bssid, ETH_ALEN) == 0)
1867 memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
1868 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1869 list_add(&pmk->list, &priv->pmklist.head);
1870 priv->pmklist.size++;
1871 } else { /* overwrite old cache data */
1872 pmk = list_entry(priv->pmklist.head.prev, struct pmk,
1874 memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
1875 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1876 list_move(&pmk->list, &priv->pmklist.head);
1879 case IW_PMKSA_REMOVE:
1880 if (list_empty(&priv->pmklist.head)) { /* list empty */
1883 /* search cache data */
1884 list_for_each(ptr, &priv->pmklist.head) {
1885 pmk = list_entry(ptr, struct pmk, list);
1886 if (memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN) == 0) {
1887 eth_zero_addr(pmk->bssid);
1888 memset(pmk->pmkid, 0, IW_PMKID_LEN);
1889 list_del_init(&pmk->list);
1893 if (ptr == &priv->pmklist.head) { /* not find address. */
1898 case IW_PMKSA_FLUSH:
1899 memset(&priv->pmklist, 0, sizeof(priv->pmklist));
1900 INIT_LIST_HEAD(&priv->pmklist.head);
1901 for (i = 0; i < PMK_LIST_MAX; i++)
1902 INIT_LIST_HEAD(&priv->pmklist.pmk[i].list);
1908 hostif_sme_enqueue(priv, SME_SET_PMKSA);
1912 static struct iw_statistics *ks_get_wireless_stats(struct net_device *dev)
1914 struct ks_wlan_private *priv = netdev_priv(dev);
1915 struct iw_statistics *wstats = &priv->wstats;
1917 if (!atomic_read(&update_phyinfo)) {
1918 if (priv->dev_state < DEVICE_STATE_READY)
1919 return NULL; /* not finished initialize */
1924 /* Packets discarded in the wireless adapter due to wireless
1927 wstats->discard.nwid = 0; /* Rx invalid nwid */
1928 wstats->discard.code = 0; /* Rx invalid crypt */
1929 wstats->discard.fragment = 0; /* Rx invalid frag */
1930 wstats->discard.retries = 0; /* Tx excessive retries */
1931 wstats->discard.misc = 0; /* Invalid misc */
1932 wstats->miss.beacon = 0; /* Missed beacon */
1937 static int ks_wlan_set_stop_request(struct net_device *dev,
1938 struct iw_request_info *info, __u32 *uwrq,
1941 struct ks_wlan_private *priv = netdev_priv(dev);
1943 if (priv->sleep_mode == SLP_SLEEP)
1946 /* for SLEEP MODE */
1950 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
1954 #include <linux/ieee80211.h>
1955 static int ks_wlan_set_mlme(struct net_device *dev,
1956 struct iw_request_info *info, struct iw_point *dwrq,
1959 struct ks_wlan_private *priv = netdev_priv(dev);
1960 struct iw_mlme *mlme = (struct iw_mlme *)extra;
1963 if (priv->sleep_mode == SLP_SLEEP)
1966 /* for SLEEP MODE */
1967 switch (mlme->cmd) {
1968 case IW_MLME_DEAUTH:
1969 if (mlme->reason_code == WLAN_REASON_MIC_FAILURE)
1972 case IW_MLME_DISASSOC:
1974 return ks_wlan_set_stop_request(dev, NULL, &mode, NULL);
1976 return -EOPNOTSUPP; /* Not Support */
1980 static int ks_wlan_get_firmware_version(struct net_device *dev,
1981 struct iw_request_info *info,
1982 struct iw_point *dwrq, char *extra)
1984 struct ks_wlan_private *priv = netdev_priv(dev);
1986 strcpy(extra, priv->firmware_version);
1987 dwrq->length = priv->version_size + 1;
1991 static int ks_wlan_set_preamble(struct net_device *dev,
1992 struct iw_request_info *info, __u32 *uwrq,
1995 struct ks_wlan_private *priv = netdev_priv(dev);
1997 if (priv->sleep_mode == SLP_SLEEP)
2000 /* for SLEEP MODE */
2001 if (*uwrq == LONG_PREAMBLE) { /* 0 */
2002 priv->reg.preamble = LONG_PREAMBLE;
2003 } else if (*uwrq == SHORT_PREAMBLE) { /* 1 */
2004 priv->reg.preamble = SHORT_PREAMBLE;
2009 priv->need_commit |= SME_MODE_SET;
2010 return -EINPROGRESS; /* Call commit handler */
2013 static int ks_wlan_get_preamble(struct net_device *dev,
2014 struct iw_request_info *info, __u32 *uwrq,
2017 struct ks_wlan_private *priv = netdev_priv(dev);
2019 if (priv->sleep_mode == SLP_SLEEP)
2022 /* for SLEEP MODE */
2023 *uwrq = priv->reg.preamble;
2027 static int ks_wlan_set_power_mgmt(struct net_device *dev,
2028 struct iw_request_info *info, __u32 *uwrq,
2031 struct ks_wlan_private *priv = netdev_priv(dev);
2033 if (priv->sleep_mode == SLP_SLEEP)
2036 /* for SLEEP MODE */
2037 if (*uwrq == POWER_MGMT_ACTIVE) { /* 0 */
2038 priv->reg.power_mgmt = POWER_MGMT_ACTIVE;
2039 } else if (*uwrq == POWER_MGMT_SAVE1) { /* 1 */
2040 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2041 priv->reg.power_mgmt = POWER_MGMT_SAVE1;
2044 } else if (*uwrq == POWER_MGMT_SAVE2) { /* 2 */
2045 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2046 priv->reg.power_mgmt = POWER_MGMT_SAVE2;
2053 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
2058 static int ks_wlan_get_power_mgmt(struct net_device *dev,
2059 struct iw_request_info *info, __u32 *uwrq,
2062 struct ks_wlan_private *priv = netdev_priv(dev);
2064 if (priv->sleep_mode == SLP_SLEEP)
2067 /* for SLEEP MODE */
2068 *uwrq = priv->reg.power_mgmt;
2072 static int ks_wlan_set_scan_type(struct net_device *dev,
2073 struct iw_request_info *info, __u32 *uwrq,
2076 struct ks_wlan_private *priv = netdev_priv(dev);
2078 if (priv->sleep_mode == SLP_SLEEP)
2080 /* for SLEEP MODE */
2081 if (*uwrq == ACTIVE_SCAN) { /* 0 */
2082 priv->reg.scan_type = ACTIVE_SCAN;
2083 } else if (*uwrq == PASSIVE_SCAN) { /* 1 */
2084 priv->reg.scan_type = PASSIVE_SCAN;
2092 static int ks_wlan_get_scan_type(struct net_device *dev,
2093 struct iw_request_info *info, __u32 *uwrq,
2096 struct ks_wlan_private *priv = netdev_priv(dev);
2098 if (priv->sleep_mode == SLP_SLEEP)
2100 /* for SLEEP MODE */
2101 *uwrq = priv->reg.scan_type;
2105 static int ks_wlan_set_beacon_lost(struct net_device *dev,
2106 struct iw_request_info *info, __u32 *uwrq,
2109 struct ks_wlan_private *priv = netdev_priv(dev);
2111 if (priv->sleep_mode == SLP_SLEEP)
2113 /* for SLEEP MODE */
2114 if (*uwrq >= BEACON_LOST_COUNT_MIN && *uwrq <= BEACON_LOST_COUNT_MAX)
2115 priv->reg.beacon_lost_count = *uwrq;
2119 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
2120 priv->need_commit |= SME_MODE_SET;
2121 return -EINPROGRESS; /* Call commit handler */
2127 static int ks_wlan_get_beacon_lost(struct net_device *dev,
2128 struct iw_request_info *info, __u32 *uwrq,
2131 struct ks_wlan_private *priv = netdev_priv(dev);
2133 if (priv->sleep_mode == SLP_SLEEP)
2135 /* for SLEEP MODE */
2136 *uwrq = priv->reg.beacon_lost_count;
2140 static int ks_wlan_set_phy_type(struct net_device *dev,
2141 struct iw_request_info *info, __u32 *uwrq,
2144 struct ks_wlan_private *priv = netdev_priv(dev);
2146 if (priv->sleep_mode == SLP_SLEEP)
2148 /* for SLEEP MODE */
2149 if (*uwrq == D_11B_ONLY_MODE) { /* 0 */
2150 priv->reg.phy_type = D_11B_ONLY_MODE;
2151 } else if (*uwrq == D_11G_ONLY_MODE) { /* 1 */
2152 priv->reg.phy_type = D_11G_ONLY_MODE;
2153 } else if (*uwrq == D_11BG_COMPATIBLE_MODE) { /* 2 */
2154 priv->reg.phy_type = D_11BG_COMPATIBLE_MODE;
2159 priv->need_commit |= SME_MODE_SET;
2160 return -EINPROGRESS; /* Call commit handler */
2163 static int ks_wlan_get_phy_type(struct net_device *dev,
2164 struct iw_request_info *info, __u32 *uwrq,
2167 struct ks_wlan_private *priv = netdev_priv(dev);
2169 if (priv->sleep_mode == SLP_SLEEP)
2171 /* for SLEEP MODE */
2172 *uwrq = priv->reg.phy_type;
2176 static int ks_wlan_set_cts_mode(struct net_device *dev,
2177 struct iw_request_info *info, __u32 *uwrq,
2180 struct ks_wlan_private *priv = netdev_priv(dev);
2182 if (priv->sleep_mode == SLP_SLEEP)
2184 /* for SLEEP MODE */
2185 if (*uwrq == CTS_MODE_FALSE) { /* 0 */
2186 priv->reg.cts_mode = CTS_MODE_FALSE;
2187 } else if (*uwrq == CTS_MODE_TRUE) { /* 1 */
2188 if (priv->reg.phy_type == D_11G_ONLY_MODE ||
2189 priv->reg.phy_type == D_11BG_COMPATIBLE_MODE) {
2190 priv->reg.cts_mode = CTS_MODE_TRUE;
2192 priv->reg.cts_mode = CTS_MODE_FALSE;
2198 priv->need_commit |= SME_MODE_SET;
2199 return -EINPROGRESS; /* Call commit handler */
2202 static int ks_wlan_get_cts_mode(struct net_device *dev,
2203 struct iw_request_info *info, __u32 *uwrq,
2206 struct ks_wlan_private *priv = netdev_priv(dev);
2208 if (priv->sleep_mode == SLP_SLEEP)
2210 /* for SLEEP MODE */
2211 *uwrq = priv->reg.cts_mode;
2215 static int ks_wlan_set_sleep_mode(struct net_device *dev,
2216 struct iw_request_info *info,
2217 __u32 *uwrq, char *extra)
2219 struct ks_wlan_private *priv = netdev_priv(dev);
2221 if (*uwrq == SLP_SLEEP) {
2222 priv->sleep_mode = *uwrq;
2223 netdev_info(dev, "SET_SLEEP_MODE %d\n", priv->sleep_mode);
2225 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2226 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2228 } else if (*uwrq == SLP_ACTIVE) {
2229 priv->sleep_mode = *uwrq;
2230 netdev_info(dev, "SET_SLEEP_MODE %d\n", priv->sleep_mode);
2231 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2233 netdev_err(dev, "SET_SLEEP_MODE %d error\n", *uwrq);
2240 static int ks_wlan_get_sleep_mode(struct net_device *dev,
2241 struct iw_request_info *info,
2242 __u32 *uwrq, char *extra)
2244 struct ks_wlan_private *priv = netdev_priv(dev);
2246 *uwrq = priv->sleep_mode;
2253 static int ks_wlan_set_wps_enable(struct net_device *dev,
2254 struct iw_request_info *info, __u32 *uwrq,
2257 struct ks_wlan_private *priv = netdev_priv(dev);
2259 if (priv->sleep_mode == SLP_SLEEP)
2261 /* for SLEEP MODE */
2262 if (*uwrq == 0 || *uwrq == 1)
2263 priv->wps.wps_enabled = *uwrq;
2267 hostif_sme_enqueue(priv, SME_WPS_ENABLE_REQUEST);
2272 static int ks_wlan_get_wps_enable(struct net_device *dev,
2273 struct iw_request_info *info, __u32 *uwrq,
2276 struct ks_wlan_private *priv = netdev_priv(dev);
2278 if (priv->sleep_mode == SLP_SLEEP)
2280 /* for SLEEP MODE */
2281 *uwrq = priv->wps.wps_enabled;
2282 netdev_info(dev, "return=%d\n", *uwrq);
2287 static int ks_wlan_set_wps_probe_req(struct net_device *dev,
2288 struct iw_request_info *info,
2289 struct iw_point *dwrq, char *extra)
2293 struct ks_wlan_private *priv = netdev_priv(dev);
2295 if (priv->sleep_mode == SLP_SLEEP)
2299 if (p[1] + 2 != dwrq->length || dwrq->length > 256)
2302 priv->wps.ielen = p[1] + 2 + 1; /* IE header + IE + sizeof(len) */
2303 len = p[1] + 2; /* IE header + IE */
2305 memcpy(priv->wps.ie, &len, sizeof(len));
2306 p = memcpy(priv->wps.ie + 1, p, len);
2308 netdev_dbg(dev, "%d(%#x): %02X %02X %02X %02X ... %02X %02X %02X\n",
2309 priv->wps.ielen, priv->wps.ielen, p[0], p[1], p[2], p[3],
2310 p[priv->wps.ielen - 3], p[priv->wps.ielen - 2],
2311 p[priv->wps.ielen - 1]);
2313 hostif_sme_enqueue(priv, SME_WPS_PROBE_REQUEST);
2319 static int ks_wlan_set_tx_gain(struct net_device *dev,
2320 struct iw_request_info *info, __u32 *uwrq,
2323 struct ks_wlan_private *priv = netdev_priv(dev);
2325 if (priv->sleep_mode == SLP_SLEEP)
2327 /* for SLEEP MODE */
2328 if (*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2329 priv->gain.tx_gain = (uint8_t)*uwrq;
2333 if (priv->gain.tx_gain < 0xFF)
2334 priv->gain.tx_mode = 1;
2336 priv->gain.tx_mode = 0;
2338 hostif_sme_enqueue(priv, SME_SET_GAIN);
2342 static int ks_wlan_get_tx_gain(struct net_device *dev,
2343 struct iw_request_info *info, __u32 *uwrq,
2346 struct ks_wlan_private *priv = netdev_priv(dev);
2348 if (priv->sleep_mode == SLP_SLEEP)
2350 /* for SLEEP MODE */
2351 *uwrq = priv->gain.tx_gain;
2352 hostif_sme_enqueue(priv, SME_GET_GAIN);
2356 static int ks_wlan_set_rx_gain(struct net_device *dev,
2357 struct iw_request_info *info, __u32 *uwrq,
2360 struct ks_wlan_private *priv = netdev_priv(dev);
2362 if (priv->sleep_mode == SLP_SLEEP)
2364 /* for SLEEP MODE */
2365 if (*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2366 priv->gain.rx_gain = (uint8_t)*uwrq;
2370 if (priv->gain.rx_gain < 0xFF)
2371 priv->gain.rx_mode = 1;
2373 priv->gain.rx_mode = 0;
2375 hostif_sme_enqueue(priv, SME_SET_GAIN);
2379 static int ks_wlan_get_rx_gain(struct net_device *dev,
2380 struct iw_request_info *info, __u32 *uwrq,
2383 struct ks_wlan_private *priv = netdev_priv(dev);
2385 if (priv->sleep_mode == SLP_SLEEP)
2387 /* for SLEEP MODE */
2388 *uwrq = priv->gain.rx_gain;
2389 hostif_sme_enqueue(priv, SME_GET_GAIN);
2393 static int ks_wlan_get_eeprom_cksum(struct net_device *dev,
2394 struct iw_request_info *info, __u32 *uwrq,
2397 struct ks_wlan_private *priv = netdev_priv(dev);
2399 *uwrq = priv->eeprom_checksum;
2403 static void print_hif_event(struct net_device *dev, int event)
2407 netdev_info(dev, "HIF_DATA_REQ\n");
2410 netdev_info(dev, "HIF_DATA_IND\n");
2412 case HIF_MIB_GET_REQ:
2413 netdev_info(dev, "HIF_MIB_GET_REQ\n");
2415 case HIF_MIB_GET_CONF:
2416 netdev_info(dev, "HIF_MIB_GET_CONF\n");
2418 case HIF_MIB_SET_REQ:
2419 netdev_info(dev, "HIF_MIB_SET_REQ\n");
2421 case HIF_MIB_SET_CONF:
2422 netdev_info(dev, "HIF_MIB_SET_CONF\n");
2424 case HIF_POWER_MGMT_REQ:
2425 netdev_info(dev, "HIF_POWER_MGMT_REQ\n");
2427 case HIF_POWER_MGMT_CONF:
2428 netdev_info(dev, "HIF_POWER_MGMT_CONF\n");
2431 netdev_info(dev, "HIF_START_REQ\n");
2433 case HIF_START_CONF:
2434 netdev_info(dev, "HIF_START_CONF\n");
2436 case HIF_CONNECT_IND:
2437 netdev_info(dev, "HIF_CONNECT_IND\n");
2440 netdev_info(dev, "HIF_STOP_REQ\n");
2443 netdev_info(dev, "HIF_STOP_CONF\n");
2445 case HIF_PS_ADH_SET_REQ:
2446 netdev_info(dev, "HIF_PS_ADH_SET_REQ\n");
2448 case HIF_PS_ADH_SET_CONF:
2449 netdev_info(dev, "HIF_PS_ADH_SET_CONF\n");
2451 case HIF_INFRA_SET_REQ:
2452 netdev_info(dev, "HIF_INFRA_SET_REQ\n");
2454 case HIF_INFRA_SET_CONF:
2455 netdev_info(dev, "HIF_INFRA_SET_CONF\n");
2457 case HIF_ADH_SET_REQ:
2458 netdev_info(dev, "HIF_ADH_SET_REQ\n");
2460 case HIF_ADH_SET_CONF:
2461 netdev_info(dev, "HIF_ADH_SET_CONF\n");
2463 case HIF_AP_SET_REQ:
2464 netdev_info(dev, "HIF_AP_SET_REQ\n");
2466 case HIF_AP_SET_CONF:
2467 netdev_info(dev, "HIF_AP_SET_CONF\n");
2469 case HIF_ASSOC_INFO_IND:
2470 netdev_info(dev, "HIF_ASSOC_INFO_IND\n");
2472 case HIF_MIC_FAILURE_REQ:
2473 netdev_info(dev, "HIF_MIC_FAILURE_REQ\n");
2475 case HIF_MIC_FAILURE_CONF:
2476 netdev_info(dev, "HIF_MIC_FAILURE_CONF\n");
2479 netdev_info(dev, "HIF_SCAN_REQ\n");
2482 netdev_info(dev, "HIF_SCAN_CONF\n");
2484 case HIF_PHY_INFO_REQ:
2485 netdev_info(dev, "HIF_PHY_INFO_REQ\n");
2487 case HIF_PHY_INFO_CONF:
2488 netdev_info(dev, "HIF_PHY_INFO_CONF\n");
2491 netdev_info(dev, "HIF_SLEEP_REQ\n");
2493 case HIF_SLEEP_CONF:
2494 netdev_info(dev, "HIF_SLEEP_CONF\n");
2496 case HIF_PHY_INFO_IND:
2497 netdev_info(dev, "HIF_PHY_INFO_IND\n");
2500 netdev_info(dev, "HIF_SCAN_IND\n");
2502 case HIF_INFRA_SET2_REQ:
2503 netdev_info(dev, "HIF_INFRA_SET2_REQ\n");
2505 case HIF_INFRA_SET2_CONF:
2506 netdev_info(dev, "HIF_INFRA_SET2_CONF\n");
2508 case HIF_ADH_SET2_REQ:
2509 netdev_info(dev, "HIF_ADH_SET2_REQ\n");
2511 case HIF_ADH_SET2_CONF:
2512 netdev_info(dev, "HIF_ADH_SET2_CONF\n");
2516 /* get host command history */
2517 static int ks_wlan_hostt(struct net_device *dev, struct iw_request_info *info,
2518 __u32 *uwrq, char *extra)
2521 struct ks_wlan_private *priv = netdev_priv(dev);
2523 for (i = 63; i >= 0; i--) {
2525 priv->hostt.buff[(priv->hostt.qtail - 1 - i) %
2526 SME_EVENT_BUFF_SIZE];
2527 print_hif_event(dev, event);
2532 /* Structures to export the Wireless Handlers */
2534 static const struct iw_priv_args ks_wlan_private_args[] = {
2535 /*{ cmd, set_args, get_args, name[16] } */
2536 {KS_WLAN_GET_FIRM_VERSION, IW_PRIV_TYPE_NONE,
2537 IW_PRIV_TYPE_CHAR | (128 + 1), "GetFirmwareVer"},
2539 {KS_WLAN_SET_WPS_ENABLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2540 IW_PRIV_TYPE_NONE, "SetWPSEnable"},
2541 {KS_WLAN_GET_WPS_ENABLE, IW_PRIV_TYPE_NONE,
2542 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetW"},
2543 {KS_WLAN_SET_WPS_PROBE_REQ, IW_PRIV_TYPE_BYTE | 2047, IW_PRIV_TYPE_NONE,
2546 {KS_WLAN_SET_PREAMBLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2547 IW_PRIV_TYPE_NONE, "SetPreamble"},
2548 {KS_WLAN_GET_PREAMBLE, IW_PRIV_TYPE_NONE,
2549 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPreamble"},
2550 {KS_WLAN_SET_POWER_SAVE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2551 IW_PRIV_TYPE_NONE, "SetPowerSave"},
2552 {KS_WLAN_GET_POWER_SAVE, IW_PRIV_TYPE_NONE,
2553 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPowerSave"},
2554 {KS_WLAN_SET_SCAN_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2555 IW_PRIV_TYPE_NONE, "SetScanType"},
2556 {KS_WLAN_GET_SCAN_TYPE, IW_PRIV_TYPE_NONE,
2557 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetScanType"},
2558 {KS_WLAN_SET_RX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2559 IW_PRIV_TYPE_NONE, "SetRxGain"},
2560 {KS_WLAN_GET_RX_GAIN, IW_PRIV_TYPE_NONE,
2561 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetRxGain"},
2562 {KS_WLAN_HOSTT, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | (128 + 1),
2564 {KS_WLAN_SET_BEACON_LOST, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2565 IW_PRIV_TYPE_NONE, "SetBeaconLost"},
2566 {KS_WLAN_GET_BEACON_LOST, IW_PRIV_TYPE_NONE,
2567 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetBeaconLost"},
2568 {KS_WLAN_SET_SLEEP_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2569 IW_PRIV_TYPE_NONE, "SetSleepMode"},
2570 {KS_WLAN_GET_SLEEP_MODE, IW_PRIV_TYPE_NONE,
2571 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetSleepMode"},
2572 {KS_WLAN_SET_TX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2573 IW_PRIV_TYPE_NONE, "SetTxGain"},
2574 {KS_WLAN_GET_TX_GAIN, IW_PRIV_TYPE_NONE,
2575 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetTxGain"},
2576 {KS_WLAN_SET_PHY_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2577 IW_PRIV_TYPE_NONE, "SetPhyType"},
2578 {KS_WLAN_GET_PHY_TYPE, IW_PRIV_TYPE_NONE,
2579 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPhyType"},
2580 {KS_WLAN_SET_CTS_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2581 IW_PRIV_TYPE_NONE, "SetCtsMode"},
2582 {KS_WLAN_GET_CTS_MODE, IW_PRIV_TYPE_NONE,
2583 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetCtsMode"},
2584 {KS_WLAN_GET_EEPROM_CKSUM, IW_PRIV_TYPE_NONE,
2585 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetChecksum"},
2588 static const iw_handler ks_wlan_handler[] = {
2589 (iw_handler)ks_wlan_config_commit, /* SIOCSIWCOMMIT */
2590 (iw_handler)ks_wlan_get_name, /* SIOCGIWNAME */
2591 (iw_handler)NULL, /* SIOCSIWNWID */
2592 (iw_handler)NULL, /* SIOCGIWNWID */
2593 (iw_handler)ks_wlan_set_freq, /* SIOCSIWFREQ */
2594 (iw_handler)ks_wlan_get_freq, /* SIOCGIWFREQ */
2595 (iw_handler)ks_wlan_set_mode, /* SIOCSIWMODE */
2596 (iw_handler)ks_wlan_get_mode, /* SIOCGIWMODE */
2597 #ifndef KSC_OPNOTSUPP
2598 (iw_handler)ks_wlan_set_sens, /* SIOCSIWSENS */
2599 (iw_handler)ks_wlan_get_sens, /* SIOCGIWSENS */
2600 #else /* KSC_OPNOTSUPP */
2601 (iw_handler)NULL, /* SIOCSIWSENS */
2602 (iw_handler)NULL, /* SIOCGIWSENS */
2603 #endif /* KSC_OPNOTSUPP */
2604 (iw_handler)NULL, /* SIOCSIWRANGE */
2605 (iw_handler)ks_wlan_get_range, /* SIOCGIWRANGE */
2606 (iw_handler)NULL, /* SIOCSIWPRIV */
2607 (iw_handler)NULL, /* SIOCGIWPRIV */
2608 (iw_handler)NULL, /* SIOCSIWSTATS */
2609 (iw_handler)ks_wlan_get_iwstats, /* SIOCGIWSTATS */
2610 (iw_handler)NULL, /* SIOCSIWSPY */
2611 (iw_handler)NULL, /* SIOCGIWSPY */
2612 (iw_handler)NULL, /* SIOCSIWTHRSPY */
2613 (iw_handler)NULL, /* SIOCGIWTHRSPY */
2614 (iw_handler)ks_wlan_set_wap, /* SIOCSIWAP */
2615 (iw_handler)ks_wlan_get_wap, /* SIOCGIWAP */
2616 // (iw_handler)NULL, /* SIOCSIWMLME */
2617 (iw_handler)ks_wlan_set_mlme, /* SIOCSIWMLME */
2618 (iw_handler)ks_wlan_get_aplist, /* SIOCGIWAPLIST */
2619 (iw_handler)ks_wlan_set_scan, /* SIOCSIWSCAN */
2620 (iw_handler)ks_wlan_get_scan, /* SIOCGIWSCAN */
2621 (iw_handler)ks_wlan_set_essid, /* SIOCSIWESSID */
2622 (iw_handler)ks_wlan_get_essid, /* SIOCGIWESSID */
2623 (iw_handler)ks_wlan_set_nick, /* SIOCSIWNICKN */
2624 (iw_handler)ks_wlan_get_nick, /* SIOCGIWNICKN */
2625 (iw_handler)NULL, /* -- hole -- */
2626 (iw_handler)NULL, /* -- hole -- */
2627 (iw_handler)ks_wlan_set_rate, /* SIOCSIWRATE */
2628 (iw_handler)ks_wlan_get_rate, /* SIOCGIWRATE */
2629 (iw_handler)ks_wlan_set_rts, /* SIOCSIWRTS */
2630 (iw_handler)ks_wlan_get_rts, /* SIOCGIWRTS */
2631 (iw_handler)ks_wlan_set_frag, /* SIOCSIWFRAG */
2632 (iw_handler)ks_wlan_get_frag, /* SIOCGIWFRAG */
2633 #ifndef KSC_OPNOTSUPP
2634 (iw_handler)ks_wlan_set_txpow, /* SIOCSIWTXPOW */
2635 (iw_handler)ks_wlan_get_txpow, /* SIOCGIWTXPOW */
2636 (iw_handler)ks_wlan_set_retry, /* SIOCSIWRETRY */
2637 (iw_handler)ks_wlan_get_retry, /* SIOCGIWRETRY */
2638 #else /* KSC_OPNOTSUPP */
2639 (iw_handler)NULL, /* SIOCSIWTXPOW */
2640 (iw_handler)NULL, /* SIOCGIWTXPOW */
2641 (iw_handler)NULL, /* SIOCSIWRETRY */
2642 (iw_handler)NULL, /* SIOCGIWRETRY */
2643 #endif /* KSC_OPNOTSUPP */
2644 (iw_handler)ks_wlan_set_encode, /* SIOCSIWENCODE */
2645 (iw_handler)ks_wlan_get_encode, /* SIOCGIWENCODE */
2646 (iw_handler)ks_wlan_set_power, /* SIOCSIWPOWER */
2647 (iw_handler)ks_wlan_get_power, /* SIOCGIWPOWER */
2648 (iw_handler)NULL, /* -- hole -- */
2649 (iw_handler)NULL, /* -- hole -- */
2650 // (iw_handler)NULL, /* SIOCSIWGENIE */
2651 (iw_handler)ks_wlan_set_genie, /* SIOCSIWGENIE */
2652 (iw_handler)NULL, /* SIOCGIWGENIE */
2653 (iw_handler)ks_wlan_set_auth_mode, /* SIOCSIWAUTH */
2654 (iw_handler)ks_wlan_get_auth_mode, /* SIOCGIWAUTH */
2655 (iw_handler)ks_wlan_set_encode_ext, /* SIOCSIWENCODEEXT */
2656 (iw_handler)ks_wlan_get_encode_ext, /* SIOCGIWENCODEEXT */
2657 (iw_handler)ks_wlan_set_pmksa, /* SIOCSIWPMKSA */
2658 (iw_handler)NULL, /* -- hole -- */
2661 /* private_handler */
2662 static const iw_handler ks_wlan_private_handler[] = {
2663 (iw_handler)NULL, /* 0 */
2664 (iw_handler)NULL, /* 1, used to be: KS_WLAN_GET_DRIVER_VERSION */
2665 (iw_handler)NULL, /* 2 */
2666 (iw_handler)ks_wlan_get_firmware_version, /* 3 KS_WLAN_GET_FIRM_VERSION */
2668 (iw_handler)ks_wlan_set_wps_enable, /* 4 KS_WLAN_SET_WPS_ENABLE */
2669 (iw_handler)ks_wlan_get_wps_enable, /* 5 KS_WLAN_GET_WPS_ENABLE */
2670 (iw_handler)ks_wlan_set_wps_probe_req, /* 6 KS_WLAN_SET_WPS_PROBE_REQ */
2672 (iw_handler)NULL, /* 4 */
2673 (iw_handler)NULL, /* 5 */
2674 (iw_handler)NULL, /* 6 */
2677 (iw_handler)ks_wlan_get_eeprom_cksum, /* 7 KS_WLAN_GET_CONNECT */
2678 (iw_handler)ks_wlan_set_preamble, /* 8 KS_WLAN_SET_PREAMBLE */
2679 (iw_handler)ks_wlan_get_preamble, /* 9 KS_WLAN_GET_PREAMBLE */
2680 (iw_handler)ks_wlan_set_power_mgmt, /* 10 KS_WLAN_SET_POWER_SAVE */
2681 (iw_handler)ks_wlan_get_power_mgmt, /* 11 KS_WLAN_GET_POWER_SAVE */
2682 (iw_handler)ks_wlan_set_scan_type, /* 12 KS_WLAN_SET_SCAN_TYPE */
2683 (iw_handler)ks_wlan_get_scan_type, /* 13 KS_WLAN_GET_SCAN_TYPE */
2684 (iw_handler)ks_wlan_set_rx_gain, /* 14 KS_WLAN_SET_RX_GAIN */
2685 (iw_handler)ks_wlan_get_rx_gain, /* 15 KS_WLAN_GET_RX_GAIN */
2686 (iw_handler)ks_wlan_hostt, /* 16 KS_WLAN_HOSTT */
2687 (iw_handler)NULL, /* 17 */
2688 (iw_handler)ks_wlan_set_beacon_lost, /* 18 KS_WLAN_SET_BECAN_LOST */
2689 (iw_handler)ks_wlan_get_beacon_lost, /* 19 KS_WLAN_GET_BECAN_LOST */
2690 (iw_handler)ks_wlan_set_tx_gain, /* 20 KS_WLAN_SET_TX_GAIN */
2691 (iw_handler)ks_wlan_get_tx_gain, /* 21 KS_WLAN_GET_TX_GAIN */
2692 (iw_handler)ks_wlan_set_phy_type, /* 22 KS_WLAN_SET_PHY_TYPE */
2693 (iw_handler)ks_wlan_get_phy_type, /* 23 KS_WLAN_GET_PHY_TYPE */
2694 (iw_handler)ks_wlan_set_cts_mode, /* 24 KS_WLAN_SET_CTS_MODE */
2695 (iw_handler)ks_wlan_get_cts_mode, /* 25 KS_WLAN_GET_CTS_MODE */
2696 (iw_handler)NULL, /* 26 */
2697 (iw_handler)NULL, /* 27 */
2698 (iw_handler)ks_wlan_set_sleep_mode, /* 28 KS_WLAN_SET_SLEEP_MODE */
2699 (iw_handler)ks_wlan_get_sleep_mode, /* 29 KS_WLAN_GET_SLEEP_MODE */
2700 (iw_handler)NULL, /* 30 */
2701 (iw_handler)NULL, /* 31 */
2704 static const struct iw_handler_def ks_wlan_handler_def = {
2705 .num_standard = ARRAY_SIZE(ks_wlan_handler),
2706 .num_private = ARRAY_SIZE(ks_wlan_private_handler),
2707 .num_private_args = ARRAY_SIZE(ks_wlan_private_args),
2708 .standard = (iw_handler *)ks_wlan_handler,
2709 .private = (iw_handler *)ks_wlan_private_handler,
2710 .private_args = (struct iw_priv_args *)ks_wlan_private_args,
2711 .get_wireless_stats = ks_get_wireless_stats,
2714 static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq,
2718 struct iwreq *wrq = (struct iwreq *)rq;
2721 case SIOCIWFIRSTPRIV + 20: /* KS_WLAN_SET_STOP_REQ */
2722 ret = ks_wlan_set_stop_request(dev, NULL, &wrq->u.mode, NULL);
2724 // All other calls are currently unsupported
2733 struct net_device_stats *ks_wlan_get_stats(struct net_device *dev)
2735 struct ks_wlan_private *priv = netdev_priv(dev);
2737 if (priv->dev_state < DEVICE_STATE_READY)
2738 return NULL; /* not finished initialize */
2740 return &priv->nstats;
2744 int ks_wlan_set_mac_address(struct net_device *dev, void *addr)
2746 struct ks_wlan_private *priv = netdev_priv(dev);
2747 struct sockaddr *mac_addr = (struct sockaddr *)addr;
2749 if (netif_running(dev))
2751 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
2752 memcpy(priv->eth_addr, mac_addr->sa_data, ETH_ALEN);
2754 priv->mac_address_valid = false;
2755 hostif_sme_enqueue(priv, SME_MACADDRESS_SET_REQUEST);
2756 netdev_info(dev, "ks_wlan: MAC ADDRESS = %pM\n", priv->eth_addr);
2761 void ks_wlan_tx_timeout(struct net_device *dev)
2763 struct ks_wlan_private *priv = netdev_priv(dev);
2765 netdev_dbg(dev, "head(%d) tail(%d)!!\n", priv->tx_dev.qhead,
2766 priv->tx_dev.qtail);
2767 if (!netif_queue_stopped(dev))
2768 netif_stop_queue(dev);
2769 priv->nstats.tx_errors++;
2770 netif_wake_queue(dev);
2774 int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev)
2776 struct ks_wlan_private *priv = netdev_priv(dev);
2779 netdev_dbg(dev, "in_interrupt()=%ld\n", in_interrupt());
2782 netdev_err(dev, "ks_wlan: skb == NULL!!!\n");
2785 if (priv->dev_state < DEVICE_STATE_READY) {
2787 return 0; /* not finished initialize */
2790 if (netif_running(dev))
2791 netif_stop_queue(dev);
2793 ret = hostif_data_request(priv, skb);
2794 netif_trans_update(dev);
2797 netdev_err(dev, "hostif_data_request error: =%d\n", ret);
2802 void send_packet_complete(struct ks_wlan_private *priv, struct sk_buff *skb)
2804 priv->nstats.tx_packets++;
2806 if (netif_queue_stopped(priv->net_dev))
2807 netif_wake_queue(priv->net_dev);
2810 priv->nstats.tx_bytes += skb->len;
2816 * Set or clear the multicast filter for this adaptor.
2817 * This routine is not state sensitive and need not be SMP locked.
2820 void ks_wlan_set_rx_mode(struct net_device *dev)
2822 struct ks_wlan_private *priv = netdev_priv(dev);
2824 if (priv->dev_state < DEVICE_STATE_READY)
2825 return; /* not finished initialize */
2826 hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST);
2830 int ks_wlan_open(struct net_device *dev)
2832 struct ks_wlan_private *priv = netdev_priv(dev);
2836 if (!priv->mac_address_valid) {
2837 netdev_err(dev, "ks_wlan : %s Not READY !!\n", dev->name);
2840 netif_start_queue(dev);
2846 int ks_wlan_close(struct net_device *dev)
2848 netif_stop_queue(dev);
2853 /* Operational parameters that usually are not changed. */
2854 /* Time in jiffies before concluding the transmitter is hung. */
2855 #define TX_TIMEOUT (3 * HZ)
2856 static const unsigned char dummy_addr[] = {
2857 0x00, 0x0b, 0xe3, 0x00, 0x00, 0x00
2860 static const struct net_device_ops ks_wlan_netdev_ops = {
2861 .ndo_start_xmit = ks_wlan_start_xmit,
2862 .ndo_open = ks_wlan_open,
2863 .ndo_stop = ks_wlan_close,
2864 .ndo_do_ioctl = ks_wlan_netdev_ioctl,
2865 .ndo_set_mac_address = ks_wlan_set_mac_address,
2866 .ndo_get_stats = ks_wlan_get_stats,
2867 .ndo_tx_timeout = ks_wlan_tx_timeout,
2868 .ndo_set_rx_mode = ks_wlan_set_rx_mode,
2871 int ks_wlan_net_start(struct net_device *dev)
2873 struct ks_wlan_private *priv;
2876 priv = netdev_priv(dev);
2877 priv->mac_address_valid = false;
2878 priv->need_commit = 0;
2880 priv->device_open_status = 1;
2882 /* phy information update timer */
2883 atomic_set(&update_phyinfo, 0);
2884 timer_setup(&update_phyinfo_timer, ks_wlan_update_phyinfo_timeout, 0);
2886 /* dummy address set */
2887 memcpy(priv->eth_addr, dummy_addr, ETH_ALEN);
2888 dev->dev_addr[0] = priv->eth_addr[0];
2889 dev->dev_addr[1] = priv->eth_addr[1];
2890 dev->dev_addr[2] = priv->eth_addr[2];
2891 dev->dev_addr[3] = priv->eth_addr[3];
2892 dev->dev_addr[4] = priv->eth_addr[4];
2893 dev->dev_addr[5] = priv->eth_addr[5];
2894 dev->dev_addr[6] = 0x00;
2895 dev->dev_addr[7] = 0x00;
2897 /* The ks_wlan-specific entries in the device structure. */
2898 dev->netdev_ops = &ks_wlan_netdev_ops;
2899 dev->wireless_handlers = &ks_wlan_handler_def;
2900 dev->watchdog_timeo = TX_TIMEOUT;
2902 netif_carrier_off(dev);
2907 int ks_wlan_net_stop(struct net_device *dev)
2909 struct ks_wlan_private *priv = netdev_priv(dev);
2911 priv->device_open_status = 0;
2912 del_timer_sync(&update_phyinfo_timer);
2914 if (netif_running(dev))
2915 netif_stop_queue(dev);
2921 * is_connect_status() - return true if status is 'connected'
2922 * @status: high bit is used as FORCE_DISCONNECT, low bits used for
2925 bool is_connect_status(u32 status)
2927 return (status & CONNECT_STATUS_MASK) == CONNECT_STATUS;
2931 * is_disconnect_status() - return true if status is 'disconnected'
2932 * @status: high bit is used as FORCE_DISCONNECT, low bits used for
2933 * disconnect status.
2935 bool is_disconnect_status(u32 status)
2937 return (status & CONNECT_STATUS_MASK) == DISCONNECT_STATUS;