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_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 -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 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 static int ks_wlan_get_name(struct net_device *dev,
177 struct iw_request_info *info, char *cwrq,
180 struct ks_wlan_private *priv = netdev_priv(dev);
182 if (priv->sleep_mode == SLP_SLEEP)
186 if (priv->dev_state < DEVICE_STATE_READY)
187 strcpy(cwrq, "NOT READY!");
188 else if (priv->reg.phy_type == D_11B_ONLY_MODE)
189 strcpy(cwrq, "IEEE 802.11b");
190 else if (priv->reg.phy_type == D_11G_ONLY_MODE)
191 strcpy(cwrq, "IEEE 802.11g");
193 strcpy(cwrq, "IEEE 802.11b/g");
198 static int ks_wlan_set_freq(struct net_device *dev,
199 struct iw_request_info *info, struct iw_freq *fwrq,
202 struct ks_wlan_private *priv = netdev_priv(dev);
205 if (priv->sleep_mode == SLP_SLEEP)
209 /* If setting by frequency, convert to a channel */
210 if ((fwrq->e == 1) &&
211 (fwrq->m >= (int)2.412e8) && (fwrq->m <= (int)2.487e8)) {
212 int f = fwrq->m / 100000;
215 while ((c < 14) && (f != frequency_list[c]))
217 /* Hack to fall through... */
221 /* Setting by channel number */
222 if ((fwrq->m > 1000) || (fwrq->e > 0))
226 /* We should do a better check than that,
227 * based on the card capability !!!
229 if ((channel < 1) || (channel > 14)) {
230 netdev_dbg(dev, "%s: New channel value of %d is invalid!\n",
235 /* Yes ! We can set it !!! */
236 priv->reg.channel = (u8)(channel);
237 priv->need_commit |= SME_MODE_SET;
239 return -EINPROGRESS; /* Call commit handler */
242 static int ks_wlan_get_freq(struct net_device *dev,
243 struct iw_request_info *info, struct iw_freq *fwrq,
246 struct ks_wlan_private *priv = netdev_priv(dev);
249 if (priv->sleep_mode == SLP_SLEEP)
253 if (is_connect_status(priv->connect_status))
254 f = (int)priv->current_ap.channel;
256 f = (int)priv->reg.channel;
258 fwrq->m = frequency_list[f - 1] * 100000;
264 static int ks_wlan_set_essid(struct net_device *dev,
265 struct iw_request_info *info,
266 struct iw_point *dwrq, char *extra)
268 struct ks_wlan_private *priv = netdev_priv(dev);
271 DPRINTK(2, " %d\n", dwrq->flags);
273 if (priv->sleep_mode == SLP_SLEEP)
277 /* Check if we asked for `any' */
279 /* Just send an empty SSID list */
280 memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
281 priv->reg.ssid.size = 0;
285 /* iwconfig uses nul termination in SSID.. */
286 if (len > 0 && extra[len - 1] == '\0')
289 /* Check the size of the string */
290 if (len > IW_ESSID_MAX_SIZE)
294 /* Check the size of the string */
295 if (dwrq->length > IW_ESSID_MAX_SIZE + 1)
301 memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
304 memcpy(priv->reg.ssid.body, extra, len);
305 priv->reg.ssid.size = len;
307 memcpy(priv->reg.ssid.body, extra, dwrq->length);
308 priv->reg.ssid.size = dwrq->length;
311 /* Write it to the card */
312 priv->need_commit |= SME_MODE_SET;
314 // return -EINPROGRESS; /* Call commit handler */
315 ks_wlan_setup_parameter(priv, priv->need_commit);
316 priv->need_commit = 0;
320 static int ks_wlan_get_essid(struct net_device *dev,
321 struct iw_request_info *info,
322 struct iw_point *dwrq, char *extra)
324 struct ks_wlan_private *priv = netdev_priv(dev);
326 if (priv->sleep_mode == SLP_SLEEP)
330 /* Note : if dwrq->flags != 0, we should
331 * get the relevant SSID from the SSID list...
333 if (priv->reg.ssid.size != 0) {
334 /* Get the current SSID */
335 memcpy(extra, priv->reg.ssid.body, priv->reg.ssid.size);
337 /* If none, we may want to get the one that was set */
340 dwrq->length = priv->reg.ssid.size;
341 dwrq->flags = 1; /* active */
344 dwrq->flags = 0; /* ANY */
350 static int ks_wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
351 struct sockaddr *ap_addr, char *extra)
353 struct ks_wlan_private *priv = netdev_priv(dev);
357 if (priv->sleep_mode == SLP_SLEEP)
361 if (priv->reg.operation_mode == MODE_ADHOC ||
362 priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
363 memcpy(priv->reg.bssid, &ap_addr->sa_data, ETH_ALEN);
365 if (is_valid_ether_addr((u8 *)priv->reg.bssid))
366 priv->need_commit |= SME_MODE_SET;
369 eth_zero_addr(priv->reg.bssid);
373 DPRINTK(2, "bssid = %pM\n", priv->reg.bssid);
375 /* Write it to the card */
376 if (priv->need_commit) {
377 priv->need_commit |= SME_MODE_SET;
378 return -EINPROGRESS; /* Call commit handler */
383 static int ks_wlan_get_wap(struct net_device *dev, struct iw_request_info *info,
384 struct sockaddr *awrq, char *extra)
386 struct ks_wlan_private *priv = netdev_priv(dev);
388 if (priv->sleep_mode == SLP_SLEEP)
392 if (is_connect_status(priv->connect_status))
393 memcpy(awrq->sa_data, priv->current_ap.bssid, ETH_ALEN);
395 eth_zero_addr(awrq->sa_data);
397 awrq->sa_family = ARPHRD_ETHER;
402 static int ks_wlan_set_nick(struct net_device *dev,
403 struct iw_request_info *info, struct iw_point *dwrq,
406 struct ks_wlan_private *priv = netdev_priv(dev);
408 if (priv->sleep_mode == SLP_SLEEP)
412 /* Check the size of the string */
413 if (dwrq->length > 16 + 1)
416 memset(priv->nick, 0, sizeof(priv->nick));
417 memcpy(priv->nick, extra, dwrq->length);
419 return -EINPROGRESS; /* Call commit handler */
422 static int ks_wlan_get_nick(struct net_device *dev,
423 struct iw_request_info *info, struct iw_point *dwrq,
426 struct ks_wlan_private *priv = netdev_priv(dev);
428 if (priv->sleep_mode == SLP_SLEEP)
432 strncpy(extra, priv->nick, 16);
434 dwrq->length = strlen(extra) + 1;
439 static int ks_wlan_set_rate(struct net_device *dev,
440 struct iw_request_info *info, struct iw_param *vwrq,
443 struct ks_wlan_private *priv = netdev_priv(dev);
446 if (priv->sleep_mode == SLP_SLEEP)
450 if (priv->reg.phy_type == D_11B_ONLY_MODE) {
451 if (vwrq->fixed == 1) {
452 switch (vwrq->value) {
455 priv->reg.rate_set.body[0] =
456 (uint8_t)(vwrq->value / 500000);
460 priv->reg.rate_set.body[0] =
461 ((uint8_t)(vwrq->value / 500000)) |
467 priv->reg.tx_rate = TX_RATE_FIXED;
468 priv->reg.rate_set.size = 1;
469 } else { /* vwrq->fixed == 0 */
470 if (vwrq->value > 0) {
471 switch (vwrq->value) {
473 priv->reg.rate_set.body[3] =
477 priv->reg.rate_set.body[2] = TX_RATE_5M;
480 priv->reg.rate_set.body[1] =
481 TX_RATE_2M | BASIC_RATE;
484 priv->reg.rate_set.body[0] =
485 TX_RATE_1M | BASIC_RATE;
491 priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
492 priv->reg.rate_set.size = i;
494 priv->reg.rate_set.body[3] = TX_RATE_11M;
495 priv->reg.rate_set.body[2] = TX_RATE_5M;
496 priv->reg.rate_set.body[1] =
497 TX_RATE_2M | BASIC_RATE;
498 priv->reg.rate_set.body[0] =
499 TX_RATE_1M | BASIC_RATE;
500 priv->reg.tx_rate = TX_RATE_FULL_AUTO;
501 priv->reg.rate_set.size = 4;
504 } else { /* D_11B_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
505 if (vwrq->fixed == 1) {
506 switch (vwrq->value) {
512 priv->reg.rate_set.body[0] =
513 (uint8_t)(vwrq->value / 500000);
522 priv->reg.rate_set.body[0] =
523 ((uint8_t)(vwrq->value / 500000)) |
529 priv->reg.tx_rate = TX_RATE_FIXED;
530 priv->reg.rate_set.size = 1;
531 } else { /* vwrq->fixed == 0 */
532 if (vwrq->value > 0) {
533 switch (vwrq->value) {
535 priv->reg.rate_set.body[11] =
539 priv->reg.rate_set.body[10] =
543 priv->reg.rate_set.body[9] =
552 if (vwrq->value == 24000000) {
553 priv->reg.rate_set.body[8] =
556 priv->reg.rate_set.body[7] =
559 priv->reg.rate_set.body[6] =
560 TX_RATE_24M | BASIC_RATE;
562 priv->reg.rate_set.body[5] =
563 TX_RATE_12M | BASIC_RATE;
565 priv->reg.rate_set.body[4] =
566 TX_RATE_6M | BASIC_RATE;
568 priv->reg.rate_set.body[3] =
569 TX_RATE_11M | BASIC_RATE;
571 } else if (vwrq->value == 18000000) {
572 priv->reg.rate_set.body[7] =
575 priv->reg.rate_set.body[6] =
578 priv->reg.rate_set.body[5] =
579 TX_RATE_12M | BASIC_RATE;
581 priv->reg.rate_set.body[4] =
582 TX_RATE_6M | BASIC_RATE;
584 priv->reg.rate_set.body[3] =
585 TX_RATE_11M | BASIC_RATE;
587 } else if (vwrq->value == 12000000) {
588 priv->reg.rate_set.body[6] =
591 priv->reg.rate_set.body[5] =
592 TX_RATE_12M | BASIC_RATE;
594 priv->reg.rate_set.body[4] =
595 TX_RATE_6M | BASIC_RATE;
597 priv->reg.rate_set.body[3] =
598 TX_RATE_11M | BASIC_RATE;
600 } else if (vwrq->value == 11000000) {
601 priv->reg.rate_set.body[5] =
604 priv->reg.rate_set.body[4] =
605 TX_RATE_6M | BASIC_RATE;
607 priv->reg.rate_set.body[3] =
608 TX_RATE_11M | BASIC_RATE;
610 } else if (vwrq->value == 9000000) {
611 priv->reg.rate_set.body[4] =
614 priv->reg.rate_set.body[3] =
615 TX_RATE_6M | BASIC_RATE;
617 } else { /* vwrq->value == 6000000 */
618 priv->reg.rate_set.body[3] =
619 TX_RATE_6M | BASIC_RATE;
623 priv->reg.rate_set.body[2] =
624 TX_RATE_5M | BASIC_RATE;
627 priv->reg.rate_set.body[1] =
628 TX_RATE_2M | BASIC_RATE;
631 priv->reg.rate_set.body[0] =
632 TX_RATE_1M | BASIC_RATE;
638 priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
639 priv->reg.rate_set.size = i;
641 priv->reg.rate_set.body[11] = TX_RATE_54M;
642 priv->reg.rate_set.body[10] = TX_RATE_48M;
643 priv->reg.rate_set.body[9] = TX_RATE_36M;
644 priv->reg.rate_set.body[8] = TX_RATE_18M;
645 priv->reg.rate_set.body[7] = TX_RATE_9M;
646 priv->reg.rate_set.body[6] =
647 TX_RATE_24M | BASIC_RATE;
648 priv->reg.rate_set.body[5] =
649 TX_RATE_12M | BASIC_RATE;
650 priv->reg.rate_set.body[4] =
651 TX_RATE_6M | BASIC_RATE;
652 priv->reg.rate_set.body[3] =
653 TX_RATE_11M | BASIC_RATE;
654 priv->reg.rate_set.body[2] =
655 TX_RATE_5M | BASIC_RATE;
656 priv->reg.rate_set.body[1] =
657 TX_RATE_2M | BASIC_RATE;
658 priv->reg.rate_set.body[0] =
659 TX_RATE_1M | BASIC_RATE;
660 priv->reg.tx_rate = TX_RATE_FULL_AUTO;
661 priv->reg.rate_set.size = 12;
666 priv->need_commit |= SME_MODE_SET;
668 return -EINPROGRESS; /* Call commit handler */
671 static int ks_wlan_get_rate(struct net_device *dev,
672 struct iw_request_info *info, struct iw_param *vwrq,
675 struct ks_wlan_private *priv = netdev_priv(dev);
677 DPRINTK(2, "in_interrupt = %ld update_phyinfo = %d\n",
678 in_interrupt(), atomic_read(&update_phyinfo));
680 if (priv->sleep_mode == SLP_SLEEP)
684 if (!atomic_read(&update_phyinfo))
685 ks_wlan_update_phy_information(priv);
687 vwrq->value = ((priv->current_rate) & RATE_MASK) * 500000;
688 if (priv->reg.tx_rate == TX_RATE_FIXED)
696 static int ks_wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
697 struct iw_param *vwrq, char *extra)
699 struct ks_wlan_private *priv = netdev_priv(dev);
700 int rthr = vwrq->value;
702 if (priv->sleep_mode == SLP_SLEEP)
708 if ((rthr < 0) || (rthr > 2347))
711 priv->reg.rts = rthr;
712 priv->need_commit |= SME_RTS;
714 return -EINPROGRESS; /* Call commit handler */
717 static int ks_wlan_get_rts(struct net_device *dev, struct iw_request_info *info,
718 struct iw_param *vwrq, char *extra)
720 struct ks_wlan_private *priv = netdev_priv(dev);
722 if (priv->sleep_mode == SLP_SLEEP)
726 vwrq->value = priv->reg.rts;
727 vwrq->disabled = (vwrq->value >= 2347);
733 static int ks_wlan_set_frag(struct net_device *dev,
734 struct iw_request_info *info, struct iw_param *vwrq,
737 struct ks_wlan_private *priv = netdev_priv(dev);
738 int fthr = vwrq->value;
740 if (priv->sleep_mode == SLP_SLEEP)
746 if ((fthr < 256) || (fthr > 2346))
749 fthr &= ~0x1; /* Get an even value - is it really needed ??? */
750 priv->reg.fragment = fthr;
751 priv->need_commit |= SME_FRAG;
753 return -EINPROGRESS; /* Call commit handler */
756 static int ks_wlan_get_frag(struct net_device *dev,
757 struct iw_request_info *info, struct iw_param *vwrq,
760 struct ks_wlan_private *priv = netdev_priv(dev);
762 if (priv->sleep_mode == SLP_SLEEP)
766 vwrq->value = priv->reg.fragment;
767 vwrq->disabled = (vwrq->value >= 2346);
773 static int ks_wlan_set_mode(struct net_device *dev,
774 struct iw_request_info *info, __u32 *uwrq,
777 struct ks_wlan_private *priv = netdev_priv(dev);
779 DPRINTK(2, "mode=%d\n", *uwrq);
781 if (priv->sleep_mode == SLP_SLEEP)
787 priv->reg.operation_mode = MODE_ADHOC;
788 priv->need_commit |= SME_MODE_SET;
791 priv->reg.operation_mode = MODE_INFRASTRUCTURE;
792 priv->need_commit |= SME_MODE_SET;
798 case IW_MODE_MONITOR:
803 return -EINPROGRESS; /* Call commit handler */
806 static int ks_wlan_get_mode(struct net_device *dev,
807 struct iw_request_info *info, __u32 *uwrq,
810 struct ks_wlan_private *priv = netdev_priv(dev);
812 if (priv->sleep_mode == SLP_SLEEP)
816 /* If not managed, assume it's ad-hoc */
817 switch (priv->reg.operation_mode) {
818 case MODE_INFRASTRUCTURE:
819 *uwrq = IW_MODE_INFRA;
822 *uwrq = IW_MODE_ADHOC;
825 *uwrq = IW_MODE_ADHOC;
831 static int ks_wlan_set_encode(struct net_device *dev,
832 struct iw_request_info *info,
833 struct iw_point *dwrq, char *extra)
835 struct ks_wlan_private *priv = netdev_priv(dev);
838 int index = (dwrq->flags & IW_ENCODE_INDEX);
839 int current_index = priv->reg.wep_index;
842 DPRINTK(2, "flags=%04X\n", dwrq->flags);
844 if (priv->sleep_mode == SLP_SLEEP)
849 if ((index < 0) || (index > 4))
852 index = current_index;
856 /* Is WEP supported ? */
857 /* Basic checking: do we have a key to set ? */
858 if (dwrq->length > 0) {
859 if (dwrq->length > MAX_KEY_SIZE) { /* Check the size of the key */
862 if (dwrq->length > MIN_KEY_SIZE) { /* Set the length */
863 key.len = MAX_KEY_SIZE;
864 priv->reg.privacy_invoked = 0x01;
865 priv->need_commit |= SME_WEP_FLAG;
866 wep_on_off = WEP_ON_128BIT;
868 if (dwrq->length > 0) {
869 key.len = MIN_KEY_SIZE;
870 priv->reg.privacy_invoked = 0x01;
871 priv->need_commit |= SME_WEP_FLAG;
872 wep_on_off = WEP_ON_64BIT;
873 } else { /* Disable the key */
877 /* Check if the key is not marked as invalid */
878 if (!(dwrq->flags & IW_ENCODE_NOKEY)) {
880 memset(key.key, 0, MAX_KEY_SIZE);
881 /* Copy the key in the driver */
883 (key.key, dwrq->pointer, dwrq->length)) {
887 /* Send the key to the card */
888 priv->reg.wep_key[index].size = key.len;
889 for (i = 0; i < (priv->reg.wep_key[index].size); i++)
890 priv->reg.wep_key[index].val[i] = key.key[i];
892 priv->need_commit |= (SME_WEP_VAL1 << index);
893 priv->reg.wep_index = index;
894 priv->need_commit |= SME_WEP_INDEX;
897 if (dwrq->flags & IW_ENCODE_DISABLED) {
898 priv->reg.wep_key[0].size = 0;
899 priv->reg.wep_key[1].size = 0;
900 priv->reg.wep_key[2].size = 0;
901 priv->reg.wep_key[3].size = 0;
902 priv->reg.privacy_invoked = 0x00;
903 if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY)
904 priv->need_commit |= SME_MODE_SET;
906 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
907 wep_on_off = WEP_OFF;
908 priv->need_commit |= SME_WEP_FLAG;
910 /* Do we want to just set the transmit key index ? */
911 if ((index >= 0) && (index < 4)) {
912 /* set_wep_key(priv, index, 0, 0, 1); xxx */
913 if (priv->reg.wep_key[index].size != 0) {
914 priv->reg.wep_index = index;
915 priv->need_commit |= SME_WEP_INDEX;
923 /* Commit the changes if needed */
924 if (dwrq->flags & IW_ENCODE_MODE)
925 priv->need_commit |= SME_WEP_FLAG;
927 if (dwrq->flags & IW_ENCODE_OPEN) {
928 if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY)
929 priv->need_commit |= SME_MODE_SET;
931 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
932 } else if (dwrq->flags & IW_ENCODE_RESTRICTED) {
933 if (priv->reg.authenticate_type == AUTH_TYPE_OPEN_SYSTEM)
934 priv->need_commit |= SME_MODE_SET;
936 priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
938 // return -EINPROGRESS; /* Call commit handler */
939 if (priv->need_commit) {
940 ks_wlan_setup_parameter(priv, priv->need_commit);
941 priv->need_commit = 0;
946 static int ks_wlan_get_encode(struct net_device *dev,
947 struct iw_request_info *info,
948 struct iw_point *dwrq, char *extra)
950 struct ks_wlan_private *priv = netdev_priv(dev);
952 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
954 if (priv->sleep_mode == SLP_SLEEP)
958 dwrq->flags = IW_ENCODE_DISABLED;
960 /* Check encryption mode */
961 switch (priv->reg.authenticate_type) {
962 case AUTH_TYPE_OPEN_SYSTEM:
963 dwrq->flags = IW_ENCODE_OPEN;
965 case AUTH_TYPE_SHARED_KEY:
966 dwrq->flags = IW_ENCODE_RESTRICTED;
970 memset(zeros, 0, sizeof(zeros));
972 /* Which key do we want ? -1 -> tx index */
973 if ((index < 0) || (index >= 4))
974 index = priv->reg.wep_index;
975 if (priv->reg.privacy_invoked) {
976 dwrq->flags &= ~IW_ENCODE_DISABLED;
977 /* dwrq->flags |= IW_ENCODE_NOKEY; */
979 dwrq->flags |= index + 1;
980 DPRINTK(2, "encoding flag = 0x%04X\n", dwrq->flags);
981 /* Copy the key to the user buffer */
982 if ((index >= 0) && (index < 4))
983 dwrq->length = priv->reg.wep_key[index].size;
984 if (dwrq->length > 16)
986 #if 1 /* IW_ENCODE_NOKEY; */
988 if ((index >= 0) && (index < 4))
989 memcpy(extra, priv->reg.wep_key[index].val,
992 memcpy(extra, zeros, dwrq->length);
998 #ifndef KSC_OPNOTSUPP
999 static int ks_wlan_set_txpow(struct net_device *dev,
1000 struct iw_request_info *info,
1001 struct iw_param *vwrq, char *extra)
1003 return -EOPNOTSUPP; /* Not Support */
1006 static int ks_wlan_get_txpow(struct net_device *dev,
1007 struct iw_request_info *info,
1008 struct iw_param *vwrq, char *extra)
1010 if (priv->sleep_mode == SLP_SLEEP)
1013 /* for SLEEP MODE */
1016 vwrq->disabled = (vwrq->value == 0);
1021 static int ks_wlan_set_retry(struct net_device *dev,
1022 struct iw_request_info *info,
1023 struct iw_param *vwrq, char *extra)
1025 return -EOPNOTSUPP; /* Not Support */
1028 static int ks_wlan_get_retry(struct net_device *dev,
1029 struct iw_request_info *info,
1030 struct iw_param *vwrq, char *extra)
1032 if (priv->sleep_mode == SLP_SLEEP)
1035 /* for SLEEP MODE */
1038 vwrq->disabled = (vwrq->value == 0);
1042 #endif /* KSC_OPNOTSUPP */
1044 static int ks_wlan_get_range(struct net_device *dev,
1045 struct iw_request_info *info,
1046 struct iw_point *dwrq, char *extra)
1048 struct ks_wlan_private *priv = netdev_priv(dev);
1049 struct iw_range *range = (struct iw_range *)extra;
1054 if (priv->sleep_mode == SLP_SLEEP)
1057 /* for SLEEP MODE */
1058 dwrq->length = sizeof(struct iw_range);
1059 memset(range, 0, sizeof(*range));
1060 range->min_nwid = 0x0000;
1061 range->max_nwid = 0x0000;
1062 range->num_channels = 14;
1063 /* Should be based on cap_rid.country to give only
1064 * what the current card support
1067 for (i = 0; i < 13; i++) { /* channel 1 -- 13 */
1068 range->freq[k].i = i + 1; /* List index */
1069 range->freq[k].m = frequency_list[i] * 100000;
1070 range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
1072 range->num_frequency = k;
1073 if (priv->reg.phy_type == D_11B_ONLY_MODE || priv->reg.phy_type == D_11BG_COMPATIBLE_MODE) { /* channel 14 */
1074 range->freq[13].i = 14; /* List index */
1075 range->freq[13].m = frequency_list[13] * 100000;
1076 range->freq[13].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
1077 range->num_frequency = 14;
1080 /* Hum... Should put the right values there */
1081 range->max_qual.qual = 100;
1082 range->max_qual.level = 256 - 128; /* 0 dBm? */
1083 range->max_qual.noise = 256 - 128;
1084 range->sensitivity = 1;
1086 if (priv->reg.phy_type == D_11B_ONLY_MODE) {
1087 range->bitrate[0] = 1e6;
1088 range->bitrate[1] = 2e6;
1089 range->bitrate[2] = 5.5e6;
1090 range->bitrate[3] = 11e6;
1091 range->num_bitrates = 4;
1092 } else { /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
1093 range->bitrate[0] = 1e6;
1094 range->bitrate[1] = 2e6;
1095 range->bitrate[2] = 5.5e6;
1096 range->bitrate[3] = 11e6;
1098 range->bitrate[4] = 6e6;
1099 range->bitrate[5] = 9e6;
1100 range->bitrate[6] = 12e6;
1101 if (IW_MAX_BITRATES < 9) {
1102 range->bitrate[7] = 54e6;
1103 range->num_bitrates = 8;
1105 range->bitrate[7] = 18e6;
1106 range->bitrate[8] = 24e6;
1107 range->bitrate[9] = 36e6;
1108 range->bitrate[10] = 48e6;
1109 range->bitrate[11] = 54e6;
1111 range->num_bitrates = 12;
1115 /* Set an indication of the max TCP throughput
1116 * in bit/s that we can expect using this interface.
1117 * May be use for QoS stuff... Jean II
1120 range->throughput = 5000 * 1000;
1122 range->throughput = 1500 * 1000;
1125 range->max_rts = 2347;
1126 range->min_frag = 256;
1127 range->max_frag = 2346;
1129 range->encoding_size[0] = 5; /* WEP: RC4 40 bits */
1130 range->encoding_size[1] = 13; /* WEP: RC4 ~128 bits */
1131 range->num_encoding_sizes = 2;
1132 range->max_encoding_tokens = 4;
1134 /* power management not support */
1135 range->pmp_flags = IW_POWER_ON;
1136 range->pmt_flags = IW_POWER_ON;
1139 /* Transmit Power - values are in dBm( or mW) */
1140 range->txpower[0] = -256;
1141 range->num_txpower = 1;
1142 range->txpower_capa = IW_TXPOW_DBM;
1143 /* range->txpower_capa = IW_TXPOW_MWATT; */
1145 range->we_version_source = 21;
1146 range->we_version_compiled = WIRELESS_EXT;
1148 range->retry_capa = IW_RETRY_ON;
1149 range->retry_flags = IW_RETRY_ON;
1150 range->r_time_flags = IW_RETRY_ON;
1152 /* Experimental measurements - boundary 11/5.5 Mb/s
1154 * Note : with or without the (local->rssi), results
1155 * are somewhat different. - Jean II
1157 range->avg_qual.qual = 50;
1158 range->avg_qual.level = 186; /* -70 dBm */
1159 range->avg_qual.noise = 0;
1161 /* Event capability (kernel + driver) */
1162 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
1163 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
1164 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
1165 range->event_capa[1] = IW_EVENT_CAPA_K_1;
1166 range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVCUSTOM) |
1167 IW_EVENT_CAPA_MASK(IWEVMICHAELMICFAILURE));
1169 /* encode extension (WPA) capability */
1170 range->enc_capa = (IW_ENC_CAPA_WPA |
1172 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP);
1176 static int ks_wlan_set_power(struct net_device *dev,
1177 struct iw_request_info *info,
1178 struct iw_param *vwrq, char *extra)
1180 struct ks_wlan_private *priv = netdev_priv(dev);
1182 if (priv->sleep_mode == SLP_SLEEP)
1185 if (vwrq->disabled) {
1186 priv->reg.power_mgmt = POWER_MGMT_ACTIVE;
1188 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
1189 priv->reg.power_mgmt = POWER_MGMT_SAVE1;
1194 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
1199 static int ks_wlan_get_power(struct net_device *dev,
1200 struct iw_request_info *info,
1201 struct iw_param *vwrq, char *extra)
1203 struct ks_wlan_private *priv = netdev_priv(dev);
1205 if (priv->sleep_mode == SLP_SLEEP)
1207 /* for SLEEP MODE */
1208 if (priv->reg.power_mgmt > 0)
1216 static int ks_wlan_get_iwstats(struct net_device *dev,
1217 struct iw_request_info *info,
1218 struct iw_quality *vwrq, char *extra)
1220 struct ks_wlan_private *priv = netdev_priv(dev);
1222 if (priv->sleep_mode == SLP_SLEEP)
1224 /* for SLEEP MODE */
1225 vwrq->qual = 0; /* not supported */
1226 vwrq->level = priv->wstats.qual.level;
1227 vwrq->noise = 0; /* not supported */
1233 #ifndef KSC_OPNOTSUPP
1235 static int ks_wlan_set_sens(struct net_device *dev,
1236 struct iw_request_info *info, struct iw_param *vwrq,
1239 return -EOPNOTSUPP; /* Not Support */
1242 static int ks_wlan_get_sens(struct net_device *dev,
1243 struct iw_request_info *info, struct iw_param *vwrq,
1248 vwrq->disabled = (vwrq->value == 0);
1252 #endif /* KSC_OPNOTSUPP */
1254 /* Note : this is deprecated in favor of IWSCAN */
1255 static int ks_wlan_get_aplist(struct net_device *dev,
1256 struct iw_request_info *info,
1257 struct iw_point *dwrq, char *extra)
1259 struct ks_wlan_private *priv = netdev_priv(dev);
1260 struct sockaddr *address = (struct sockaddr *)extra;
1261 struct iw_quality qual[LOCAL_APLIST_MAX];
1265 if (priv->sleep_mode == SLP_SLEEP)
1267 /* for SLEEP MODE */
1268 for (i = 0; i < priv->aplist.size; i++) {
1269 memcpy(address[i].sa_data, &(priv->aplist.ap[i].bssid[0]),
1271 address[i].sa_family = ARPHRD_ETHER;
1272 qual[i].level = 256 - priv->aplist.ap[i].rssi;
1273 qual[i].qual = priv->aplist.ap[i].sq;
1274 qual[i].noise = 0; /* invalid noise value */
1275 qual[i].updated = 7;
1278 dwrq->flags = 1; /* Should be define'd */
1279 memcpy(extra + sizeof(struct sockaddr) * i,
1280 &qual, sizeof(struct iw_quality) * i);
1287 static int ks_wlan_set_scan(struct net_device *dev,
1288 struct iw_request_info *info,
1289 union iwreq_data *wrqu, char *extra)
1291 struct ks_wlan_private *priv = netdev_priv(dev);
1292 struct iw_scan_req *req = NULL;
1297 if (priv->sleep_mode == SLP_SLEEP)
1300 /* for SLEEP MODE */
1301 /* specified SSID SCAN */
1302 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
1303 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1304 req = (struct iw_scan_req *)extra;
1305 len = min_t(int, req->essid_len, IW_ESSID_MAX_SIZE);
1306 priv->scan_ssid_len = len;
1307 memcpy(priv->scan_ssid, req->essid, len);
1309 priv->scan_ssid_len = 0;
1312 priv->sme_i.sme_flag |= SME_AP_SCAN;
1313 hostif_sme_enqueue(priv, SME_BSS_SCAN_REQUEST);
1315 /* At this point, just return to the user. */
1321 * Translate scan data returned from the card to a card independent
1322 * format that the Wireless Tools will understand - Jean II
1324 static inline char *ks_wlan_translate_scan(struct net_device *dev,
1325 struct iw_request_info *info,
1326 char *current_ev, char *end_buf,
1327 struct local_ap_t *ap)
1329 /* struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; */
1330 struct iw_event iwe; /* Temporary buffer */
1332 char *current_val; /* For rates */
1334 static const char rsn_leader[] = "rsn_ie=";
1335 static const char wpa_leader[] = "wpa_ie=";
1336 char buf0[RSN_IE_BODY_MAX * 2 + 30];
1337 char buf1[RSN_IE_BODY_MAX * 2 + 30];
1339 /* First entry *MUST* be the AP MAC address */
1340 iwe.cmd = SIOCGIWAP;
1341 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1342 memcpy(iwe.u.ap_addr.sa_data, ap->bssid, ETH_ALEN);
1344 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1347 /* Other entries will be displayed in the order we give them */
1350 iwe.u.data.length = ap->ssid.size;
1351 if (iwe.u.data.length > 32)
1352 iwe.u.data.length = 32;
1353 iwe.cmd = SIOCGIWESSID;
1354 iwe.u.data.flags = 1;
1356 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1360 iwe.cmd = SIOCGIWMODE;
1361 capabilities = ap->capability;
1362 if (capabilities & (BSS_CAP_ESS | BSS_CAP_IBSS)) {
1363 if (capabilities & BSS_CAP_ESS)
1364 iwe.u.mode = IW_MODE_INFRA;
1366 iwe.u.mode = IW_MODE_ADHOC;
1368 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1373 iwe.cmd = SIOCGIWFREQ;
1374 iwe.u.freq.m = ap->channel;
1375 iwe.u.freq.m = frequency_list[iwe.u.freq.m - 1] * 100000;
1378 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1381 /* Add quality statistics */
1383 iwe.u.qual.level = 256 - ap->rssi;
1384 iwe.u.qual.qual = ap->sq;
1385 iwe.u.qual.noise = 0; /* invalid noise value */
1387 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1390 /* Add encryption capability */
1391 iwe.cmd = SIOCGIWENCODE;
1392 if (capabilities & BSS_CAP_PRIVACY)
1393 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1395 iwe.u.data.flags = IW_ENCODE_DISABLED;
1396 iwe.u.data.length = 0;
1398 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1401 /* Rate : stuffing multiple values in a single event require a bit
1402 * more of magic - Jean II
1404 current_val = current_ev + IW_EV_LCP_LEN;
1406 iwe.cmd = SIOCGIWRATE;
1408 /* These two flags are ignored... */
1409 iwe.u.bitrate.fixed = 0;
1410 iwe.u.bitrate.disabled = 0;
1413 for (i = 0; i < 16; i++) {
1414 /* NULL terminated */
1415 if (i >= ap->rate_set.size)
1417 /* Bit rate given in 500 kb/s units (+ 0x80) */
1418 iwe.u.bitrate.value = ((ap->rate_set.body[i] & 0x7f) * 500000);
1419 /* Add new value to event */
1421 iwe_stream_add_value(info, current_ev, current_val, end_buf,
1422 &iwe, IW_EV_PARAM_LEN);
1424 /* Check if we added any event */
1425 if ((current_val - current_ev) > IW_EV_LCP_LEN)
1426 current_ev = current_val;
1428 #define GENERIC_INFO_ELEM_ID 0xdd
1429 #define RSN_INFO_ELEM_ID 0x30
1430 if (ap->rsn_ie.id == RSN_INFO_ELEM_ID && ap->rsn_ie.size != 0) {
1432 memset(&iwe, 0, sizeof(iwe));
1433 iwe.cmd = IWEVCUSTOM;
1434 memcpy(buf0, rsn_leader, sizeof(rsn_leader) - 1);
1435 iwe.u.data.length += sizeof(rsn_leader) - 1;
1436 pbuf += sizeof(rsn_leader) - 1;
1438 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.id);
1439 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.size);
1440 iwe.u.data.length += 4;
1442 for (i = 0; i < ap->rsn_ie.size; i++)
1443 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.body[i]);
1444 iwe.u.data.length += (ap->rsn_ie.size) * 2;
1446 DPRINTK(4, "ap->rsn.size=%d\n", ap->rsn_ie.size);
1449 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1452 if (ap->wpa_ie.id == GENERIC_INFO_ELEM_ID && ap->wpa_ie.size != 0) {
1454 memset(&iwe, 0, sizeof(iwe));
1455 iwe.cmd = IWEVCUSTOM;
1456 memcpy(buf1, wpa_leader, sizeof(wpa_leader) - 1);
1457 iwe.u.data.length += sizeof(wpa_leader) - 1;
1458 pbuf += sizeof(wpa_leader) - 1;
1460 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.id);
1461 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.size);
1462 iwe.u.data.length += 4;
1464 for (i = 0; i < ap->wpa_ie.size; i++)
1465 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.body[i]);
1466 iwe.u.data.length += (ap->wpa_ie.size) * 2;
1468 DPRINTK(4, "ap->rsn.size=%d\n", ap->wpa_ie.size);
1469 DPRINTK(4, "iwe.u.data.length=%d\n", iwe.u.data.length);
1472 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1476 /* The other data in the scan result are not really
1477 * interesting, so for now drop it - Jean II
1482 static int ks_wlan_get_scan(struct net_device *dev,
1483 struct iw_request_info *info, struct iw_point *dwrq,
1486 struct ks_wlan_private *priv = netdev_priv(dev);
1488 char *current_ev = extra;
1492 if (priv->sleep_mode == SLP_SLEEP)
1494 /* for SLEEP MODE */
1495 if (priv->sme_i.sme_flag & SME_AP_SCAN) {
1496 DPRINTK(2, "flag AP_SCAN\n");
1500 if (priv->aplist.size == 0) {
1501 /* Client error, no scan results...
1502 * The caller need to restart the scan.
1504 DPRINTK(2, "aplist 0\n");
1508 /* Read and parse all entries */
1509 for (i = 0; i < priv->aplist.size; i++) {
1510 if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) {
1514 /* Translate to WE format this entry */
1515 current_ev = ks_wlan_translate_scan(dev, info, current_ev,
1516 extra + dwrq->length,
1517 &priv->aplist.ap[i]);
1519 /* Length of data */
1520 dwrq->length = (current_ev - extra);
1526 /* called after a bunch of SET operations */
1527 static int ks_wlan_config_commit(struct net_device *dev,
1528 struct iw_request_info *info, void *zwrq,
1531 struct ks_wlan_private *priv = netdev_priv(dev);
1533 if (!priv->need_commit)
1536 ks_wlan_setup_parameter(priv, priv->need_commit);
1537 priv->need_commit = 0;
1541 /* set association ie params */
1542 static int ks_wlan_set_genie(struct net_device *dev,
1543 struct iw_request_info *info,
1544 struct iw_point *dwrq, char *extra)
1546 struct ks_wlan_private *priv = netdev_priv(dev);
1550 if (priv->sleep_mode == SLP_SLEEP)
1552 /* for SLEEP MODE */
1554 // return -EOPNOTSUPP;
1557 static int ks_wlan_set_auth_mode(struct net_device *dev,
1558 struct iw_request_info *info,
1559 struct iw_param *vwrq, char *extra)
1561 struct ks_wlan_private *priv = netdev_priv(dev);
1562 int index = (vwrq->flags & IW_AUTH_INDEX);
1563 int value = vwrq->value;
1565 DPRINTK(2, "index=%d:value=%08X\n", index, value);
1567 if (priv->sleep_mode == SLP_SLEEP)
1569 /* for SLEEP MODE */
1571 case IW_AUTH_WPA_VERSION: /* 0 */
1573 case IW_AUTH_WPA_VERSION_DISABLED:
1574 priv->wpa.version = value;
1575 if (priv->wpa.rsn_enabled)
1576 priv->wpa.rsn_enabled = 0;
1577 priv->need_commit |= SME_RSN;
1579 case IW_AUTH_WPA_VERSION_WPA:
1580 case IW_AUTH_WPA_VERSION_WPA2:
1581 priv->wpa.version = value;
1582 if (!(priv->wpa.rsn_enabled))
1583 priv->wpa.rsn_enabled = 1;
1584 priv->need_commit |= SME_RSN;
1590 case IW_AUTH_CIPHER_PAIRWISE: /* 1 */
1592 case IW_AUTH_CIPHER_NONE:
1593 if (priv->reg.privacy_invoked) {
1594 priv->reg.privacy_invoked = 0x00;
1595 priv->need_commit |= SME_WEP_FLAG;
1598 case IW_AUTH_CIPHER_WEP40:
1599 case IW_AUTH_CIPHER_TKIP:
1600 case IW_AUTH_CIPHER_CCMP:
1601 case IW_AUTH_CIPHER_WEP104:
1602 if (!priv->reg.privacy_invoked) {
1603 priv->reg.privacy_invoked = 0x01;
1604 priv->need_commit |= SME_WEP_FLAG;
1606 priv->wpa.pairwise_suite = value;
1607 priv->need_commit |= SME_RSN_UNICAST;
1613 case IW_AUTH_CIPHER_GROUP: /* 2 */
1615 case IW_AUTH_CIPHER_NONE:
1616 if (priv->reg.privacy_invoked) {
1617 priv->reg.privacy_invoked = 0x00;
1618 priv->need_commit |= SME_WEP_FLAG;
1621 case IW_AUTH_CIPHER_WEP40:
1622 case IW_AUTH_CIPHER_TKIP:
1623 case IW_AUTH_CIPHER_CCMP:
1624 case IW_AUTH_CIPHER_WEP104:
1625 if (!priv->reg.privacy_invoked) {
1626 priv->reg.privacy_invoked = 0x01;
1627 priv->need_commit |= SME_WEP_FLAG;
1629 priv->wpa.group_suite = value;
1630 priv->need_commit |= SME_RSN_MULTICAST;
1636 case IW_AUTH_KEY_MGMT: /* 3 */
1638 case IW_AUTH_KEY_MGMT_802_1X:
1639 case IW_AUTH_KEY_MGMT_PSK:
1640 case 0: /* NONE or 802_1X_NO_WPA */
1641 case 4: /* WPA_NONE */
1642 priv->wpa.key_mgmt_suite = value;
1643 priv->need_commit |= SME_RSN_AUTH;
1649 case IW_AUTH_80211_AUTH_ALG: /* 6 */
1651 case IW_AUTH_ALG_OPEN_SYSTEM:
1652 priv->wpa.auth_alg = value;
1653 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
1655 case IW_AUTH_ALG_SHARED_KEY:
1656 priv->wpa.auth_alg = value;
1657 priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
1659 case IW_AUTH_ALG_LEAP:
1663 priv->need_commit |= SME_MODE_SET;
1665 case IW_AUTH_WPA_ENABLED: /* 7 */
1666 priv->wpa.wpa_enabled = value;
1668 case IW_AUTH_PRIVACY_INVOKED: /* 10 */
1669 if ((value && !priv->reg.privacy_invoked) ||
1670 (!value && priv->reg.privacy_invoked)) {
1671 priv->reg.privacy_invoked = value ? 0x01 : 0x00;
1672 priv->need_commit |= SME_WEP_FLAG;
1675 case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* 4 */
1676 case IW_AUTH_TKIP_COUNTERMEASURES: /* 5 */
1677 case IW_AUTH_DROP_UNENCRYPTED: /* 8 */
1678 case IW_AUTH_ROAMING_CONTROL: /* 9 */
1683 /* return -EINPROGRESS; */
1684 if (priv->need_commit) {
1685 ks_wlan_setup_parameter(priv, priv->need_commit);
1686 priv->need_commit = 0;
1691 static int ks_wlan_get_auth_mode(struct net_device *dev,
1692 struct iw_request_info *info,
1693 struct iw_param *vwrq, char *extra)
1695 struct ks_wlan_private *priv = netdev_priv(dev);
1696 int index = (vwrq->flags & IW_AUTH_INDEX);
1698 DPRINTK(2, "index=%d\n", index);
1700 if (priv->sleep_mode == SLP_SLEEP)
1703 /* for SLEEP MODE */
1704 /* WPA (not used ?? wpa_supplicant) */
1706 case IW_AUTH_WPA_VERSION:
1707 vwrq->value = priv->wpa.version;
1709 case IW_AUTH_CIPHER_PAIRWISE:
1710 vwrq->value = priv->wpa.pairwise_suite;
1712 case IW_AUTH_CIPHER_GROUP:
1713 vwrq->value = priv->wpa.group_suite;
1715 case IW_AUTH_KEY_MGMT:
1716 vwrq->value = priv->wpa.key_mgmt_suite;
1718 case IW_AUTH_80211_AUTH_ALG:
1719 vwrq->value = priv->wpa.auth_alg;
1721 case IW_AUTH_WPA_ENABLED:
1722 vwrq->value = priv->wpa.rsn_enabled;
1724 case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* OK??? */
1725 case IW_AUTH_TKIP_COUNTERMEASURES:
1726 case IW_AUTH_DROP_UNENCRYPTED:
1728 /* return -EOPNOTSUPP; */
1734 /* set encoding token & mode (WPA)*/
1735 static int ks_wlan_set_encode_ext(struct net_device *dev,
1736 struct iw_request_info *info,
1737 struct iw_point *dwrq, char *extra)
1739 struct ks_wlan_private *priv = netdev_priv(dev);
1740 struct iw_encode_ext *enc;
1741 int index = dwrq->flags & IW_ENCODE_INDEX;
1742 unsigned int commit = 0;
1743 struct wpa_key_t *key;
1745 enc = (struct iw_encode_ext *)extra;
1749 DPRINTK(2, "flags=%04X:: ext_flags=%08X\n", dwrq->flags,
1752 if (priv->sleep_mode == SLP_SLEEP)
1755 /* for SLEEP MODE */
1756 if (index < 1 || index > 4)
1759 key = &priv->wpa.key[index];
1761 if (dwrq->flags & IW_ENCODE_DISABLED)
1764 key->ext_flags = enc->ext_flags;
1765 if (enc->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
1766 priv->wpa.txkey = index;
1767 commit |= SME_WEP_INDEX;
1768 } else if (enc->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
1769 memcpy(&key->rx_seq[0], &enc->rx_seq[0], IW_ENCODE_SEQ_MAX_SIZE);
1772 memcpy(&key->addr.sa_data[0], &enc->addr.sa_data[0], ETH_ALEN);
1775 case IW_ENCODE_ALG_NONE:
1776 if (priv->reg.privacy_invoked) {
1777 priv->reg.privacy_invoked = 0x00;
1778 commit |= SME_WEP_FLAG;
1783 case IW_ENCODE_ALG_WEP:
1784 case IW_ENCODE_ALG_CCMP:
1785 if (!priv->reg.privacy_invoked) {
1786 priv->reg.privacy_invoked = 0x01;
1787 commit |= SME_WEP_FLAG;
1790 memcpy(&key->key_val[0], &enc->key[0], enc->key_len);
1791 key->key_len = enc->key_len;
1792 commit |= (SME_WEP_VAL1 << index);
1795 case IW_ENCODE_ALG_TKIP:
1796 if (!priv->reg.privacy_invoked) {
1797 priv->reg.privacy_invoked = 0x01;
1798 commit |= SME_WEP_FLAG;
1800 if (enc->key_len == 32) {
1801 memcpy(&key->key_val[0], &enc->key[0], enc->key_len - 16);
1802 key->key_len = enc->key_len - 16;
1803 if (priv->wpa.key_mgmt_suite == 4) { /* WPA_NONE */
1804 memcpy(&key->tx_mic_key[0], &enc->key[16], 8);
1805 memcpy(&key->rx_mic_key[0], &enc->key[16], 8);
1807 memcpy(&key->tx_mic_key[0], &enc->key[16], 8);
1808 memcpy(&key->rx_mic_key[0], &enc->key[24], 8);
1810 commit |= (SME_WEP_VAL1 << index);
1816 key->alg = enc->alg;
1819 if (commit & SME_WEP_INDEX)
1820 hostif_sme_enqueue(priv, SME_SET_TXKEY);
1821 if (commit & SME_WEP_VAL_MASK)
1822 hostif_sme_enqueue(priv, SME_SET_KEY1 + index);
1823 if (commit & SME_WEP_FLAG)
1824 hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
1830 /* get encoding token & mode (WPA)*/
1831 static int ks_wlan_get_encode_ext(struct net_device *dev,
1832 struct iw_request_info *info,
1833 struct iw_point *dwrq, char *extra)
1835 struct ks_wlan_private *priv = netdev_priv(dev);
1837 if (priv->sleep_mode == SLP_SLEEP)
1840 /* for SLEEP MODE */
1841 /* WPA (not used ?? wpa_supplicant)
1842 * struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
1843 * struct iw_encode_ext *enc;
1844 * enc = (struct iw_encode_ext *)extra;
1845 * int index = dwrq->flags & IW_ENCODE_INDEX;
1846 * WPA (not used ?? wpa_supplicant)
1851 static int ks_wlan_set_pmksa(struct net_device *dev,
1852 struct iw_request_info *info,
1853 struct iw_point *dwrq, char *extra)
1855 struct ks_wlan_private *priv = netdev_priv(dev);
1856 struct iw_pmksa *pmksa;
1859 struct list_head *ptr;
1863 if (priv->sleep_mode == SLP_SLEEP)
1866 /* for SLEEP MODE */
1870 pmksa = (struct iw_pmksa *)extra;
1871 DPRINTK(2, "cmd=%d\n", pmksa->cmd);
1873 switch (pmksa->cmd) {
1875 if (list_empty(&priv->pmklist.head)) { /* new list */
1876 for (i = 0; i < PMK_LIST_MAX; i++) {
1877 pmk = &priv->pmklist.pmk[i];
1878 if (memcmp("\x00\x00\x00\x00\x00\x00",
1879 pmk->bssid, ETH_ALEN) == 0)
1882 memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
1883 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1884 list_add(&pmk->list, &priv->pmklist.head);
1885 priv->pmklist.size++;
1888 /* search cache data */
1889 list_for_each(ptr, &priv->pmklist.head) {
1890 pmk = list_entry(ptr, struct pmk_t, list);
1891 if (memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN) == 0) {
1892 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1893 list_move(&pmk->list, &priv->pmklist.head);
1894 break; /* list_for_each */
1897 if (ptr != &priv->pmklist.head) /* not find address. */
1900 if (priv->pmklist.size < PMK_LIST_MAX) { /* new cache data */
1901 for (i = 0; i < PMK_LIST_MAX; i++) {
1902 pmk = &priv->pmklist.pmk[i];
1903 if (memcmp("\x00\x00\x00\x00\x00\x00",
1904 pmk->bssid, ETH_ALEN) == 0)
1907 memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
1908 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1909 list_add(&pmk->list, &priv->pmklist.head);
1910 priv->pmklist.size++;
1911 } else { /* overwrite old cache data */
1912 pmk = list_entry(priv->pmklist.head.prev, struct pmk_t,
1914 memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
1915 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1916 list_move(&pmk->list, &priv->pmklist.head);
1919 case IW_PMKSA_REMOVE:
1920 if (list_empty(&priv->pmklist.head)) { /* list empty */
1923 /* search cache data */
1924 list_for_each(ptr, &priv->pmklist.head) {
1925 pmk = list_entry(ptr, struct pmk_t, list);
1926 if (memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN) == 0) {
1927 eth_zero_addr(pmk->bssid);
1928 memset(pmk->pmkid, 0, IW_PMKID_LEN);
1929 list_del_init(&pmk->list);
1933 if (ptr == &priv->pmklist.head) { /* not find address. */
1938 case IW_PMKSA_FLUSH:
1939 memset(&priv->pmklist, 0, sizeof(priv->pmklist));
1940 INIT_LIST_HEAD(&priv->pmklist.head);
1941 for (i = 0; i < PMK_LIST_MAX; i++)
1942 INIT_LIST_HEAD(&priv->pmklist.pmk[i].list);
1948 hostif_sme_enqueue(priv, SME_SET_PMKSA);
1952 static struct iw_statistics *ks_get_wireless_stats(struct net_device *dev)
1954 struct ks_wlan_private *priv = netdev_priv(dev);
1955 struct iw_statistics *wstats = &priv->wstats;
1957 if (!atomic_read(&update_phyinfo)) {
1958 if (priv->dev_state < DEVICE_STATE_READY)
1959 return NULL; /* not finished initialize */
1964 /* Packets discarded in the wireless adapter due to wireless
1967 wstats->discard.nwid = 0; /* Rx invalid nwid */
1968 wstats->discard.code = 0; /* Rx invalid crypt */
1969 wstats->discard.fragment = 0; /* Rx invalid frag */
1970 wstats->discard.retries = 0; /* Tx excessive retries */
1971 wstats->discard.misc = 0; /* Invalid misc */
1972 wstats->miss.beacon = 0; /* Missed beacon */
1977 static int ks_wlan_set_stop_request(struct net_device *dev,
1978 struct iw_request_info *info, __u32 *uwrq,
1981 struct ks_wlan_private *priv = netdev_priv(dev);
1985 if (priv->sleep_mode == SLP_SLEEP)
1988 /* for SLEEP MODE */
1992 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
1996 #include <linux/ieee80211.h>
1997 static int ks_wlan_set_mlme(struct net_device *dev,
1998 struct iw_request_info *info, struct iw_point *dwrq,
2001 struct ks_wlan_private *priv = netdev_priv(dev);
2002 struct iw_mlme *mlme = (struct iw_mlme *)extra;
2005 DPRINTK(2, ":%d :%d\n", mlme->cmd, mlme->reason_code);
2007 if (priv->sleep_mode == SLP_SLEEP)
2010 /* for SLEEP MODE */
2011 switch (mlme->cmd) {
2012 case IW_MLME_DEAUTH:
2013 if (mlme->reason_code == WLAN_REASON_MIC_FAILURE)
2015 case IW_MLME_DISASSOC:
2017 return ks_wlan_set_stop_request(dev, NULL, &mode, NULL);
2019 return -EOPNOTSUPP; /* Not Support */
2023 static int ks_wlan_get_firmware_version(struct net_device *dev,
2024 struct iw_request_info *info,
2025 struct iw_point *dwrq, char *extra)
2027 struct ks_wlan_private *priv = netdev_priv(dev);
2029 strcpy(extra, priv->firmware_version);
2030 dwrq->length = priv->version_size + 1;
2034 static int ks_wlan_set_preamble(struct net_device *dev,
2035 struct iw_request_info *info, __u32 *uwrq,
2038 struct ks_wlan_private *priv = netdev_priv(dev);
2040 if (priv->sleep_mode == SLP_SLEEP)
2043 /* for SLEEP MODE */
2044 if (*uwrq == LONG_PREAMBLE) { /* 0 */
2045 priv->reg.preamble = LONG_PREAMBLE;
2046 } else if (*uwrq == SHORT_PREAMBLE) { /* 1 */
2047 priv->reg.preamble = SHORT_PREAMBLE;
2052 priv->need_commit |= SME_MODE_SET;
2053 return -EINPROGRESS; /* Call commit handler */
2056 static int ks_wlan_get_preamble(struct net_device *dev,
2057 struct iw_request_info *info, __u32 *uwrq,
2060 struct ks_wlan_private *priv = netdev_priv(dev);
2062 if (priv->sleep_mode == SLP_SLEEP)
2065 /* for SLEEP MODE */
2066 *uwrq = priv->reg.preamble;
2070 static int ks_wlan_set_power_mgmt(struct net_device *dev,
2071 struct iw_request_info *info, __u32 *uwrq,
2074 struct ks_wlan_private *priv = netdev_priv(dev);
2076 if (priv->sleep_mode == SLP_SLEEP)
2079 /* for SLEEP MODE */
2080 if (*uwrq == POWER_MGMT_ACTIVE) { /* 0 */
2081 priv->reg.power_mgmt = POWER_MGMT_ACTIVE;
2082 } else if (*uwrq == POWER_MGMT_SAVE1) { /* 1 */
2083 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2084 priv->reg.power_mgmt = POWER_MGMT_SAVE1;
2087 } else if (*uwrq == POWER_MGMT_SAVE2) { /* 2 */
2088 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2089 priv->reg.power_mgmt = POWER_MGMT_SAVE2;
2096 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
2101 static int ks_wlan_get_power_mgmt(struct net_device *dev,
2102 struct iw_request_info *info, __u32 *uwrq,
2105 struct ks_wlan_private *priv = netdev_priv(dev);
2107 if (priv->sleep_mode == SLP_SLEEP)
2110 /* for SLEEP MODE */
2111 *uwrq = priv->reg.power_mgmt;
2115 static int ks_wlan_set_scan_type(struct net_device *dev,
2116 struct iw_request_info *info, __u32 *uwrq,
2119 struct ks_wlan_private *priv = netdev_priv(dev);
2121 if (priv->sleep_mode == SLP_SLEEP)
2123 /* for SLEEP MODE */
2124 if (*uwrq == ACTIVE_SCAN) { /* 0 */
2125 priv->reg.scan_type = ACTIVE_SCAN;
2126 } else if (*uwrq == PASSIVE_SCAN) { /* 1 */
2127 priv->reg.scan_type = PASSIVE_SCAN;
2135 static int ks_wlan_get_scan_type(struct net_device *dev,
2136 struct iw_request_info *info, __u32 *uwrq,
2139 struct ks_wlan_private *priv = netdev_priv(dev);
2141 if (priv->sleep_mode == SLP_SLEEP)
2143 /* for SLEEP MODE */
2144 *uwrq = priv->reg.scan_type;
2148 static int ks_wlan_set_beacon_lost(struct net_device *dev,
2149 struct iw_request_info *info, __u32 *uwrq,
2152 struct ks_wlan_private *priv = netdev_priv(dev);
2154 if (priv->sleep_mode == SLP_SLEEP)
2156 /* for SLEEP MODE */
2157 if (*uwrq >= BEACON_LOST_COUNT_MIN && *uwrq <= BEACON_LOST_COUNT_MAX)
2158 priv->reg.beacon_lost_count = *uwrq;
2162 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
2163 priv->need_commit |= SME_MODE_SET;
2164 return -EINPROGRESS; /* Call commit handler */
2170 static int ks_wlan_get_beacon_lost(struct net_device *dev,
2171 struct iw_request_info *info, __u32 *uwrq,
2174 struct ks_wlan_private *priv = netdev_priv(dev);
2176 if (priv->sleep_mode == SLP_SLEEP)
2178 /* for SLEEP MODE */
2179 *uwrq = priv->reg.beacon_lost_count;
2183 static int ks_wlan_set_phy_type(struct net_device *dev,
2184 struct iw_request_info *info, __u32 *uwrq,
2187 struct ks_wlan_private *priv = netdev_priv(dev);
2189 if (priv->sleep_mode == SLP_SLEEP)
2191 /* for SLEEP MODE */
2192 if (*uwrq == D_11B_ONLY_MODE) { /* 0 */
2193 priv->reg.phy_type = D_11B_ONLY_MODE;
2194 } else if (*uwrq == D_11G_ONLY_MODE) { /* 1 */
2195 priv->reg.phy_type = D_11G_ONLY_MODE;
2196 } else if (*uwrq == D_11BG_COMPATIBLE_MODE) { /* 2 */
2197 priv->reg.phy_type = D_11BG_COMPATIBLE_MODE;
2202 priv->need_commit |= SME_MODE_SET;
2203 return -EINPROGRESS; /* Call commit handler */
2206 static int ks_wlan_get_phy_type(struct net_device *dev,
2207 struct iw_request_info *info, __u32 *uwrq,
2210 struct ks_wlan_private *priv = netdev_priv(dev);
2212 if (priv->sleep_mode == SLP_SLEEP)
2214 /* for SLEEP MODE */
2215 *uwrq = priv->reg.phy_type;
2219 static int ks_wlan_set_cts_mode(struct net_device *dev,
2220 struct iw_request_info *info, __u32 *uwrq,
2223 struct ks_wlan_private *priv = netdev_priv(dev);
2225 if (priv->sleep_mode == SLP_SLEEP)
2227 /* for SLEEP MODE */
2228 if (*uwrq == CTS_MODE_FALSE) { /* 0 */
2229 priv->reg.cts_mode = CTS_MODE_FALSE;
2230 } else if (*uwrq == CTS_MODE_TRUE) { /* 1 */
2231 if (priv->reg.phy_type == D_11G_ONLY_MODE ||
2232 priv->reg.phy_type == D_11BG_COMPATIBLE_MODE) {
2233 priv->reg.cts_mode = CTS_MODE_TRUE;
2235 priv->reg.cts_mode = CTS_MODE_FALSE;
2241 priv->need_commit |= SME_MODE_SET;
2242 return -EINPROGRESS; /* Call commit handler */
2245 static int ks_wlan_get_cts_mode(struct net_device *dev,
2246 struct iw_request_info *info, __u32 *uwrq,
2249 struct ks_wlan_private *priv = netdev_priv(dev);
2251 if (priv->sleep_mode == SLP_SLEEP)
2253 /* for SLEEP MODE */
2254 *uwrq = priv->reg.cts_mode;
2258 static int ks_wlan_set_sleep_mode(struct net_device *dev,
2259 struct iw_request_info *info,
2260 __u32 *uwrq, char *extra)
2262 struct ks_wlan_private *priv = netdev_priv(dev);
2266 if (*uwrq == SLP_SLEEP) {
2267 priv->sleep_mode = *uwrq;
2268 netdev_info(dev, "SET_SLEEP_MODE %d\n", priv->sleep_mode);
2270 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2271 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2273 } else if (*uwrq == SLP_ACTIVE) {
2274 priv->sleep_mode = *uwrq;
2275 netdev_info(dev, "SET_SLEEP_MODE %d\n", priv->sleep_mode);
2276 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2278 netdev_err(dev, "SET_SLEEP_MODE %d error\n", *uwrq);
2285 static int ks_wlan_get_sleep_mode(struct net_device *dev,
2286 struct iw_request_info *info,
2287 __u32 *uwrq, char *extra)
2289 struct ks_wlan_private *priv = netdev_priv(dev);
2291 DPRINTK(2, "GET_SLEEP_MODE %d\n", priv->sleep_mode);
2292 *uwrq = priv->sleep_mode;
2299 static int ks_wlan_set_wps_enable(struct net_device *dev,
2300 struct iw_request_info *info, __u32 *uwrq,
2303 struct ks_wlan_private *priv = netdev_priv(dev);
2307 if (priv->sleep_mode == SLP_SLEEP)
2309 /* for SLEEP MODE */
2310 if (*uwrq == 0 || *uwrq == 1)
2311 priv->wps.wps_enabled = *uwrq;
2315 hostif_sme_enqueue(priv, SME_WPS_ENABLE_REQUEST);
2320 static int ks_wlan_get_wps_enable(struct net_device *dev,
2321 struct iw_request_info *info, __u32 *uwrq,
2324 struct ks_wlan_private *priv = netdev_priv(dev);
2328 if (priv->sleep_mode == SLP_SLEEP)
2330 /* for SLEEP MODE */
2331 *uwrq = priv->wps.wps_enabled;
2332 netdev_info(dev, "return=%d\n", *uwrq);
2337 static int ks_wlan_set_wps_probe_req(struct net_device *dev,
2338 struct iw_request_info *info,
2339 struct iw_point *dwrq, char *extra)
2343 struct ks_wlan_private *priv = netdev_priv(dev);
2347 if (priv->sleep_mode == SLP_SLEEP)
2349 /* for SLEEP MODE */
2350 DPRINTK(2, "dwrq->length=%d\n", dwrq->length);
2353 if (p[1] + 2 != dwrq->length || dwrq->length > 256)
2356 priv->wps.ielen = p[1] + 2 + 1; /* IE header + IE + sizeof(len) */
2357 len = p[1] + 2; /* IE header + IE */
2359 memcpy(priv->wps.ie, &len, sizeof(len));
2360 p = memcpy(priv->wps.ie + 1, p, len);
2362 DPRINTK(2, "%d(%#x): %02X %02X %02X %02X ... %02X %02X %02X\n",
2363 priv->wps.ielen, priv->wps.ielen, p[0], p[1], p[2], p[3],
2364 p[priv->wps.ielen - 3], p[priv->wps.ielen - 2],
2365 p[priv->wps.ielen - 1]);
2367 hostif_sme_enqueue(priv, SME_WPS_PROBE_REQUEST);
2373 static int ks_wlan_set_tx_gain(struct net_device *dev,
2374 struct iw_request_info *info, __u32 *uwrq,
2377 struct ks_wlan_private *priv = netdev_priv(dev);
2379 if (priv->sleep_mode == SLP_SLEEP)
2381 /* for SLEEP MODE */
2382 if (*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2383 priv->gain.tx_gain = (uint8_t)*uwrq;
2387 if (priv->gain.tx_gain < 0xFF)
2388 priv->gain.tx_mode = 1;
2390 priv->gain.tx_mode = 0;
2392 hostif_sme_enqueue(priv, SME_SET_GAIN);
2396 static int ks_wlan_get_tx_gain(struct net_device *dev,
2397 struct iw_request_info *info, __u32 *uwrq,
2400 struct ks_wlan_private *priv = netdev_priv(dev);
2402 if (priv->sleep_mode == SLP_SLEEP)
2404 /* for SLEEP MODE */
2405 *uwrq = priv->gain.tx_gain;
2406 hostif_sme_enqueue(priv, SME_GET_GAIN);
2410 static int ks_wlan_set_rx_gain(struct net_device *dev,
2411 struct iw_request_info *info, __u32 *uwrq,
2414 struct ks_wlan_private *priv = netdev_priv(dev);
2416 if (priv->sleep_mode == SLP_SLEEP)
2418 /* for SLEEP MODE */
2419 if (*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2420 priv->gain.rx_gain = (uint8_t)*uwrq;
2424 if (priv->gain.rx_gain < 0xFF)
2425 priv->gain.rx_mode = 1;
2427 priv->gain.rx_mode = 0;
2429 hostif_sme_enqueue(priv, SME_SET_GAIN);
2433 static int ks_wlan_get_rx_gain(struct net_device *dev,
2434 struct iw_request_info *info, __u32 *uwrq,
2437 struct ks_wlan_private *priv = netdev_priv(dev);
2439 if (priv->sleep_mode == SLP_SLEEP)
2441 /* for SLEEP MODE */
2442 *uwrq = priv->gain.rx_gain;
2443 hostif_sme_enqueue(priv, SME_GET_GAIN);
2447 static int ks_wlan_get_eeprom_cksum(struct net_device *dev,
2448 struct iw_request_info *info, __u32 *uwrq,
2451 struct ks_wlan_private *priv = netdev_priv(dev);
2453 *uwrq = priv->eeprom_checksum;
2457 static void print_hif_event(struct net_device *dev, int event)
2461 netdev_info(dev, "HIF_DATA_REQ\n");
2464 netdev_info(dev, "HIF_DATA_IND\n");
2466 case HIF_MIB_GET_REQ:
2467 netdev_info(dev, "HIF_MIB_GET_REQ\n");
2469 case HIF_MIB_GET_CONF:
2470 netdev_info(dev, "HIF_MIB_GET_CONF\n");
2472 case HIF_MIB_SET_REQ:
2473 netdev_info(dev, "HIF_MIB_SET_REQ\n");
2475 case HIF_MIB_SET_CONF:
2476 netdev_info(dev, "HIF_MIB_SET_CONF\n");
2478 case HIF_POWER_MGMT_REQ:
2479 netdev_info(dev, "HIF_POWER_MGMT_REQ\n");
2481 case HIF_POWER_MGMT_CONF:
2482 netdev_info(dev, "HIF_POWER_MGMT_CONF\n");
2485 netdev_info(dev, "HIF_START_REQ\n");
2487 case HIF_START_CONF:
2488 netdev_info(dev, "HIF_START_CONF\n");
2490 case HIF_CONNECT_IND:
2491 netdev_info(dev, "HIF_CONNECT_IND\n");
2494 netdev_info(dev, "HIF_STOP_REQ\n");
2497 netdev_info(dev, "HIF_STOP_CONF\n");
2499 case HIF_PS_ADH_SET_REQ:
2500 netdev_info(dev, "HIF_PS_ADH_SET_REQ\n");
2502 case HIF_PS_ADH_SET_CONF:
2503 netdev_info(dev, "HIF_PS_ADH_SET_CONF\n");
2505 case HIF_INFRA_SET_REQ:
2506 netdev_info(dev, "HIF_INFRA_SET_REQ\n");
2508 case HIF_INFRA_SET_CONF:
2509 netdev_info(dev, "HIF_INFRA_SET_CONF\n");
2511 case HIF_ADH_SET_REQ:
2512 netdev_info(dev, "HIF_ADH_SET_REQ\n");
2514 case HIF_ADH_SET_CONF:
2515 netdev_info(dev, "HIF_ADH_SET_CONF\n");
2517 case HIF_AP_SET_REQ:
2518 netdev_info(dev, "HIF_AP_SET_REQ\n");
2520 case HIF_AP_SET_CONF:
2521 netdev_info(dev, "HIF_AP_SET_CONF\n");
2523 case HIF_ASSOC_INFO_IND:
2524 netdev_info(dev, "HIF_ASSOC_INFO_IND\n");
2526 case HIF_MIC_FAILURE_REQ:
2527 netdev_info(dev, "HIF_MIC_FAILURE_REQ\n");
2529 case HIF_MIC_FAILURE_CONF:
2530 netdev_info(dev, "HIF_MIC_FAILURE_CONF\n");
2533 netdev_info(dev, "HIF_SCAN_REQ\n");
2536 netdev_info(dev, "HIF_SCAN_CONF\n");
2538 case HIF_PHY_INFO_REQ:
2539 netdev_info(dev, "HIF_PHY_INFO_REQ\n");
2541 case HIF_PHY_INFO_CONF:
2542 netdev_info(dev, "HIF_PHY_INFO_CONF\n");
2545 netdev_info(dev, "HIF_SLEEP_REQ\n");
2547 case HIF_SLEEP_CONF:
2548 netdev_info(dev, "HIF_SLEEP_CONF\n");
2550 case HIF_PHY_INFO_IND:
2551 netdev_info(dev, "HIF_PHY_INFO_IND\n");
2554 netdev_info(dev, "HIF_SCAN_IND\n");
2556 case HIF_INFRA_SET2_REQ:
2557 netdev_info(dev, "HIF_INFRA_SET2_REQ\n");
2559 case HIF_INFRA_SET2_CONF:
2560 netdev_info(dev, "HIF_INFRA_SET2_CONF\n");
2562 case HIF_ADH_SET2_REQ:
2563 netdev_info(dev, "HIF_ADH_SET2_REQ\n");
2565 case HIF_ADH_SET2_CONF:
2566 netdev_info(dev, "HIF_ADH_SET2_CONF\n");
2570 /* get host command history */
2571 static int ks_wlan_hostt(struct net_device *dev, struct iw_request_info *info,
2572 __u32 *uwrq, char *extra)
2575 struct ks_wlan_private *priv = netdev_priv(dev);
2577 for (i = 63; i >= 0; i--) {
2579 priv->hostt.buff[(priv->hostt.qtail - 1 - i) %
2580 SME_EVENT_BUFF_SIZE];
2581 print_hif_event(dev, event);
2586 /* Structures to export the Wireless Handlers */
2588 static const struct iw_priv_args ks_wlan_private_args[] = {
2589 /*{ cmd, set_args, get_args, name[16] } */
2590 {KS_WLAN_GET_FIRM_VERSION, IW_PRIV_TYPE_NONE,
2591 IW_PRIV_TYPE_CHAR | (128 + 1), "GetFirmwareVer"},
2593 {KS_WLAN_SET_WPS_ENABLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2594 IW_PRIV_TYPE_NONE, "SetWPSEnable"},
2595 {KS_WLAN_GET_WPS_ENABLE, IW_PRIV_TYPE_NONE,
2596 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetW"},
2597 {KS_WLAN_SET_WPS_PROBE_REQ, IW_PRIV_TYPE_BYTE | 2047, IW_PRIV_TYPE_NONE,
2600 {KS_WLAN_SET_PREAMBLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2601 IW_PRIV_TYPE_NONE, "SetPreamble"},
2602 {KS_WLAN_GET_PREAMBLE, IW_PRIV_TYPE_NONE,
2603 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPreamble"},
2604 {KS_WLAN_SET_POWER_SAVE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2605 IW_PRIV_TYPE_NONE, "SetPowerSave"},
2606 {KS_WLAN_GET_POWER_SAVE, IW_PRIV_TYPE_NONE,
2607 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPowerSave"},
2608 {KS_WLAN_SET_SCAN_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2609 IW_PRIV_TYPE_NONE, "SetScanType"},
2610 {KS_WLAN_GET_SCAN_TYPE, IW_PRIV_TYPE_NONE,
2611 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetScanType"},
2612 {KS_WLAN_SET_RX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2613 IW_PRIV_TYPE_NONE, "SetRxGain"},
2614 {KS_WLAN_GET_RX_GAIN, IW_PRIV_TYPE_NONE,
2615 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetRxGain"},
2616 {KS_WLAN_HOSTT, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | (128 + 1),
2618 {KS_WLAN_SET_BEACON_LOST, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2619 IW_PRIV_TYPE_NONE, "SetBeaconLost"},
2620 {KS_WLAN_GET_BEACON_LOST, IW_PRIV_TYPE_NONE,
2621 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetBeaconLost"},
2622 {KS_WLAN_SET_SLEEP_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2623 IW_PRIV_TYPE_NONE, "SetSleepMode"},
2624 {KS_WLAN_GET_SLEEP_MODE, IW_PRIV_TYPE_NONE,
2625 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetSleepMode"},
2626 {KS_WLAN_SET_TX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2627 IW_PRIV_TYPE_NONE, "SetTxGain"},
2628 {KS_WLAN_GET_TX_GAIN, IW_PRIV_TYPE_NONE,
2629 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetTxGain"},
2630 {KS_WLAN_SET_PHY_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2631 IW_PRIV_TYPE_NONE, "SetPhyType"},
2632 {KS_WLAN_GET_PHY_TYPE, IW_PRIV_TYPE_NONE,
2633 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPhyType"},
2634 {KS_WLAN_SET_CTS_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2635 IW_PRIV_TYPE_NONE, "SetCtsMode"},
2636 {KS_WLAN_GET_CTS_MODE, IW_PRIV_TYPE_NONE,
2637 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetCtsMode"},
2638 {KS_WLAN_GET_EEPROM_CKSUM, IW_PRIV_TYPE_NONE,
2639 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetChecksum"},
2642 static const iw_handler ks_wlan_handler[] = {
2643 (iw_handler)ks_wlan_config_commit, /* SIOCSIWCOMMIT */
2644 (iw_handler)ks_wlan_get_name, /* SIOCGIWNAME */
2645 (iw_handler)NULL, /* SIOCSIWNWID */
2646 (iw_handler)NULL, /* SIOCGIWNWID */
2647 (iw_handler)ks_wlan_set_freq, /* SIOCSIWFREQ */
2648 (iw_handler)ks_wlan_get_freq, /* SIOCGIWFREQ */
2649 (iw_handler)ks_wlan_set_mode, /* SIOCSIWMODE */
2650 (iw_handler)ks_wlan_get_mode, /* SIOCGIWMODE */
2651 #ifndef KSC_OPNOTSUPP
2652 (iw_handler)ks_wlan_set_sens, /* SIOCSIWSENS */
2653 (iw_handler)ks_wlan_get_sens, /* SIOCGIWSENS */
2654 #else /* KSC_OPNOTSUPP */
2655 (iw_handler)NULL, /* SIOCSIWSENS */
2656 (iw_handler)NULL, /* SIOCGIWSENS */
2657 #endif /* KSC_OPNOTSUPP */
2658 (iw_handler)NULL, /* SIOCSIWRANGE */
2659 (iw_handler)ks_wlan_get_range, /* SIOCGIWRANGE */
2660 (iw_handler)NULL, /* SIOCSIWPRIV */
2661 (iw_handler)NULL, /* SIOCGIWPRIV */
2662 (iw_handler)NULL, /* SIOCSIWSTATS */
2663 (iw_handler)ks_wlan_get_iwstats, /* SIOCGIWSTATS */
2664 (iw_handler)NULL, /* SIOCSIWSPY */
2665 (iw_handler)NULL, /* SIOCGIWSPY */
2666 (iw_handler)NULL, /* SIOCSIWTHRSPY */
2667 (iw_handler)NULL, /* SIOCGIWTHRSPY */
2668 (iw_handler)ks_wlan_set_wap, /* SIOCSIWAP */
2669 (iw_handler)ks_wlan_get_wap, /* SIOCGIWAP */
2670 // (iw_handler)NULL, /* SIOCSIWMLME */
2671 (iw_handler)ks_wlan_set_mlme, /* SIOCSIWMLME */
2672 (iw_handler)ks_wlan_get_aplist, /* SIOCGIWAPLIST */
2673 (iw_handler)ks_wlan_set_scan, /* SIOCSIWSCAN */
2674 (iw_handler)ks_wlan_get_scan, /* SIOCGIWSCAN */
2675 (iw_handler)ks_wlan_set_essid, /* SIOCSIWESSID */
2676 (iw_handler)ks_wlan_get_essid, /* SIOCGIWESSID */
2677 (iw_handler)ks_wlan_set_nick, /* SIOCSIWNICKN */
2678 (iw_handler)ks_wlan_get_nick, /* SIOCGIWNICKN */
2679 (iw_handler)NULL, /* -- hole -- */
2680 (iw_handler)NULL, /* -- hole -- */
2681 (iw_handler)ks_wlan_set_rate, /* SIOCSIWRATE */
2682 (iw_handler)ks_wlan_get_rate, /* SIOCGIWRATE */
2683 (iw_handler)ks_wlan_set_rts, /* SIOCSIWRTS */
2684 (iw_handler)ks_wlan_get_rts, /* SIOCGIWRTS */
2685 (iw_handler)ks_wlan_set_frag, /* SIOCSIWFRAG */
2686 (iw_handler)ks_wlan_get_frag, /* SIOCGIWFRAG */
2687 #ifndef KSC_OPNOTSUPP
2688 (iw_handler)ks_wlan_set_txpow, /* SIOCSIWTXPOW */
2689 (iw_handler)ks_wlan_get_txpow, /* SIOCGIWTXPOW */
2690 (iw_handler)ks_wlan_set_retry, /* SIOCSIWRETRY */
2691 (iw_handler)ks_wlan_get_retry, /* SIOCGIWRETRY */
2692 #else /* KSC_OPNOTSUPP */
2693 (iw_handler)NULL, /* SIOCSIWTXPOW */
2694 (iw_handler)NULL, /* SIOCGIWTXPOW */
2695 (iw_handler)NULL, /* SIOCSIWRETRY */
2696 (iw_handler)NULL, /* SIOCGIWRETRY */
2697 #endif /* KSC_OPNOTSUPP */
2698 (iw_handler)ks_wlan_set_encode, /* SIOCSIWENCODE */
2699 (iw_handler)ks_wlan_get_encode, /* SIOCGIWENCODE */
2700 (iw_handler)ks_wlan_set_power, /* SIOCSIWPOWER */
2701 (iw_handler)ks_wlan_get_power, /* SIOCGIWPOWER */
2702 (iw_handler)NULL, /* -- hole -- */
2703 (iw_handler)NULL, /* -- hole -- */
2704 // (iw_handler)NULL, /* SIOCSIWGENIE */
2705 (iw_handler)ks_wlan_set_genie, /* SIOCSIWGENIE */
2706 (iw_handler)NULL, /* SIOCGIWGENIE */
2707 (iw_handler)ks_wlan_set_auth_mode, /* SIOCSIWAUTH */
2708 (iw_handler)ks_wlan_get_auth_mode, /* SIOCGIWAUTH */
2709 (iw_handler)ks_wlan_set_encode_ext, /* SIOCSIWENCODEEXT */
2710 (iw_handler)ks_wlan_get_encode_ext, /* SIOCGIWENCODEEXT */
2711 (iw_handler)ks_wlan_set_pmksa, /* SIOCSIWPMKSA */
2712 (iw_handler)NULL, /* -- hole -- */
2715 /* private_handler */
2716 static const iw_handler ks_wlan_private_handler[] = {
2717 (iw_handler)NULL, /* 0 */
2718 (iw_handler)NULL, /* 1, used to be: KS_WLAN_GET_DRIVER_VERSION */
2719 (iw_handler)NULL, /* 2 */
2720 (iw_handler)ks_wlan_get_firmware_version, /* 3 KS_WLAN_GET_FIRM_VERSION */
2722 (iw_handler)ks_wlan_set_wps_enable, /* 4 KS_WLAN_SET_WPS_ENABLE */
2723 (iw_handler)ks_wlan_get_wps_enable, /* 5 KS_WLAN_GET_WPS_ENABLE */
2724 (iw_handler)ks_wlan_set_wps_probe_req, /* 6 KS_WLAN_SET_WPS_PROBE_REQ */
2726 (iw_handler)NULL, /* 4 */
2727 (iw_handler)NULL, /* 5 */
2728 (iw_handler)NULL, /* 6 */
2731 (iw_handler)ks_wlan_get_eeprom_cksum, /* 7 KS_WLAN_GET_CONNECT */
2732 (iw_handler)ks_wlan_set_preamble, /* 8 KS_WLAN_SET_PREAMBLE */
2733 (iw_handler)ks_wlan_get_preamble, /* 9 KS_WLAN_GET_PREAMBLE */
2734 (iw_handler)ks_wlan_set_power_mgmt, /* 10 KS_WLAN_SET_POWER_SAVE */
2735 (iw_handler)ks_wlan_get_power_mgmt, /* 11 KS_WLAN_GET_POWER_SAVE */
2736 (iw_handler)ks_wlan_set_scan_type, /* 12 KS_WLAN_SET_SCAN_TYPE */
2737 (iw_handler)ks_wlan_get_scan_type, /* 13 KS_WLAN_GET_SCAN_TYPE */
2738 (iw_handler)ks_wlan_set_rx_gain, /* 14 KS_WLAN_SET_RX_GAIN */
2739 (iw_handler)ks_wlan_get_rx_gain, /* 15 KS_WLAN_GET_RX_GAIN */
2740 (iw_handler)ks_wlan_hostt, /* 16 KS_WLAN_HOSTT */
2741 (iw_handler)NULL, /* 17 */
2742 (iw_handler)ks_wlan_set_beacon_lost, /* 18 KS_WLAN_SET_BECAN_LOST */
2743 (iw_handler)ks_wlan_get_beacon_lost, /* 19 KS_WLAN_GET_BECAN_LOST */
2744 (iw_handler)ks_wlan_set_tx_gain, /* 20 KS_WLAN_SET_TX_GAIN */
2745 (iw_handler)ks_wlan_get_tx_gain, /* 21 KS_WLAN_GET_TX_GAIN */
2746 (iw_handler)ks_wlan_set_phy_type, /* 22 KS_WLAN_SET_PHY_TYPE */
2747 (iw_handler)ks_wlan_get_phy_type, /* 23 KS_WLAN_GET_PHY_TYPE */
2748 (iw_handler)ks_wlan_set_cts_mode, /* 24 KS_WLAN_SET_CTS_MODE */
2749 (iw_handler)ks_wlan_get_cts_mode, /* 25 KS_WLAN_GET_CTS_MODE */
2750 (iw_handler)NULL, /* 26 */
2751 (iw_handler)NULL, /* 27 */
2752 (iw_handler)ks_wlan_set_sleep_mode, /* 28 KS_WLAN_SET_SLEEP_MODE */
2753 (iw_handler)ks_wlan_get_sleep_mode, /* 29 KS_WLAN_GET_SLEEP_MODE */
2754 (iw_handler)NULL, /* 30 */
2755 (iw_handler)NULL, /* 31 */
2758 static const struct iw_handler_def ks_wlan_handler_def = {
2759 .num_standard = sizeof(ks_wlan_handler) / sizeof(iw_handler),
2760 .num_private = sizeof(ks_wlan_private_handler) / sizeof(iw_handler),
2762 sizeof(ks_wlan_private_args) / sizeof(struct iw_priv_args),
2763 .standard = (iw_handler *)ks_wlan_handler,
2764 .private = (iw_handler *)ks_wlan_private_handler,
2765 .private_args = (struct iw_priv_args *)ks_wlan_private_args,
2766 .get_wireless_stats = ks_get_wireless_stats,
2769 static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq,
2773 struct iwreq *wrq = (struct iwreq *)rq;
2776 case SIOCIWFIRSTPRIV + 20: /* KS_WLAN_SET_STOP_REQ */
2777 ret = ks_wlan_set_stop_request(dev, NULL, &wrq->u.mode, NULL);
2779 // All other calls are currently unsupported
2784 DPRINTK(5, "return=%d\n", ret);
2789 struct net_device_stats *ks_wlan_get_stats(struct net_device *dev)
2791 struct ks_wlan_private *priv = netdev_priv(dev);
2793 if (priv->dev_state < DEVICE_STATE_READY)
2794 return NULL; /* not finished initialize */
2796 return &priv->nstats;
2800 int ks_wlan_set_mac_address(struct net_device *dev, void *addr)
2802 struct ks_wlan_private *priv = netdev_priv(dev);
2803 struct sockaddr *mac_addr = (struct sockaddr *)addr;
2805 if (netif_running(dev))
2807 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
2808 memcpy(priv->eth_addr, mac_addr->sa_data, ETH_ALEN);
2810 priv->mac_address_valid = 0;
2811 hostif_sme_enqueue(priv, SME_MACADDRESS_SET_REQUEST);
2812 netdev_info(dev, "ks_wlan: MAC ADDRESS = %pM\n", priv->eth_addr);
2817 void ks_wlan_tx_timeout(struct net_device *dev)
2819 struct ks_wlan_private *priv = netdev_priv(dev);
2821 DPRINTK(1, "head(%d) tail(%d)!!\n", priv->tx_dev.qhead,
2822 priv->tx_dev.qtail);
2823 if (!netif_queue_stopped(dev))
2824 netif_stop_queue(dev);
2825 priv->nstats.tx_errors++;
2826 netif_wake_queue(dev);
2830 int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev)
2832 struct ks_wlan_private *priv = netdev_priv(dev);
2835 DPRINTK(3, "in_interrupt()=%ld\n", in_interrupt());
2838 netdev_err(dev, "ks_wlan: skb == NULL!!!\n");
2841 if (priv->dev_state < DEVICE_STATE_READY) {
2843 return 0; /* not finished initialize */
2846 if (netif_running(dev))
2847 netif_stop_queue(dev);
2849 ret = hostif_data_request(priv, skb);
2850 netif_trans_update(dev);
2853 DPRINTK(4, "hostif_data_request error: =%d\n", ret);
2858 void send_packet_complete(struct ks_wlan_private *priv, struct sk_buff *skb)
2862 priv->nstats.tx_packets++;
2864 if (netif_queue_stopped(priv->net_dev))
2865 netif_wake_queue(priv->net_dev);
2868 priv->nstats.tx_bytes += skb->len;
2874 * Set or clear the multicast filter for this adaptor.
2875 * This routine is not state sensitive and need not be SMP locked.
2878 void ks_wlan_set_multicast_list(struct net_device *dev)
2880 struct ks_wlan_private *priv = netdev_priv(dev);
2883 if (priv->dev_state < DEVICE_STATE_READY)
2884 return; /* not finished initialize */
2885 hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST);
2889 int ks_wlan_open(struct net_device *dev)
2891 struct ks_wlan_private *priv = netdev_priv(dev);
2895 if (!priv->mac_address_valid) {
2896 netdev_err(dev, "ks_wlan : %s Not READY !!\n", dev->name);
2899 netif_start_queue(dev);
2905 int ks_wlan_close(struct net_device *dev)
2907 netif_stop_queue(dev);
2909 DPRINTK(4, "%s: Shutting down ethercard, status was 0x%4.4x.\n",
2915 /* Operational parameters that usually are not changed. */
2916 /* Time in jiffies before concluding the transmitter is hung. */
2917 #define TX_TIMEOUT (3 * HZ)
2918 static const unsigned char dummy_addr[] = {
2919 0x00, 0x0b, 0xe3, 0x00, 0x00, 0x00
2922 static const struct net_device_ops ks_wlan_netdev_ops = {
2923 .ndo_start_xmit = ks_wlan_start_xmit,
2924 .ndo_open = ks_wlan_open,
2925 .ndo_stop = ks_wlan_close,
2926 .ndo_do_ioctl = ks_wlan_netdev_ioctl,
2927 .ndo_set_mac_address = ks_wlan_set_mac_address,
2928 .ndo_get_stats = ks_wlan_get_stats,
2929 .ndo_tx_timeout = ks_wlan_tx_timeout,
2930 .ndo_set_rx_mode = ks_wlan_set_multicast_list,
2933 int ks_wlan_net_start(struct net_device *dev)
2935 struct ks_wlan_private *priv;
2938 priv = netdev_priv(dev);
2939 priv->mac_address_valid = 0;
2940 priv->need_commit = 0;
2942 priv->device_open_status = 1;
2944 /* phy information update timer */
2945 atomic_set(&update_phyinfo, 0);
2946 setup_timer(&update_phyinfo_timer, ks_wlan_update_phyinfo_timeout,
2947 (unsigned long)priv);
2949 /* dummy address set */
2950 memcpy(priv->eth_addr, dummy_addr, ETH_ALEN);
2951 dev->dev_addr[0] = priv->eth_addr[0];
2952 dev->dev_addr[1] = priv->eth_addr[1];
2953 dev->dev_addr[2] = priv->eth_addr[2];
2954 dev->dev_addr[3] = priv->eth_addr[3];
2955 dev->dev_addr[4] = priv->eth_addr[4];
2956 dev->dev_addr[5] = priv->eth_addr[5];
2957 dev->dev_addr[6] = 0x00;
2958 dev->dev_addr[7] = 0x00;
2960 /* The ks_wlan-specific entries in the device structure. */
2961 dev->netdev_ops = &ks_wlan_netdev_ops;
2962 dev->wireless_handlers = (struct iw_handler_def *)&ks_wlan_handler_def;
2963 dev->watchdog_timeo = TX_TIMEOUT;
2965 netif_carrier_off(dev);
2970 int ks_wlan_net_stop(struct net_device *dev)
2972 struct ks_wlan_private *priv = netdev_priv(dev);
2974 priv->device_open_status = 0;
2975 del_timer_sync(&update_phyinfo_timer);
2977 if (netif_running(dev))
2978 netif_stop_queue(dev);
2984 * is_connect_status() - return true if status is 'connected'
2985 * @status: high bit is used as FORCE_DISCONNECT, low bits used for
2988 bool is_connect_status(u32 status)
2990 return (status & CONNECT_STATUS_MASK) == CONNECT_STATUS;
2994 * is_disconnect_status() - return true if status is 'disconnected'
2995 * @status: high bit is used as FORCE_DISCONNECT, low bits used for
2996 * disconnect status.
2998 bool is_disconnect_status(u32 status)
3000 return (status & CONNECT_STATUS_MASK) == DISCONNECT_STATUS;