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 int key_len = clamp_val(enc->key_len, 0, IW_ENCODING_TOKEN_MAX);
1792 memcpy(&key->key_val[0], &enc->key[0], key_len);
1793 key->key_len = key_len;
1794 commit |= (SME_WEP_VAL1 << index);
1797 case IW_ENCODE_ALG_TKIP:
1798 if (!priv->reg.privacy_invoked) {
1799 priv->reg.privacy_invoked = 0x01;
1800 commit |= SME_WEP_FLAG;
1802 if (enc->key_len == 32) {
1803 memcpy(&key->key_val[0], &enc->key[0], enc->key_len - 16);
1804 key->key_len = enc->key_len - 16;
1805 if (priv->wpa.key_mgmt_suite == 4) { /* WPA_NONE */
1806 memcpy(&key->tx_mic_key[0], &enc->key[16], 8);
1807 memcpy(&key->rx_mic_key[0], &enc->key[16], 8);
1809 memcpy(&key->tx_mic_key[0], &enc->key[16], 8);
1810 memcpy(&key->rx_mic_key[0], &enc->key[24], 8);
1812 commit |= (SME_WEP_VAL1 << index);
1818 key->alg = enc->alg;
1821 if (commit & SME_WEP_INDEX)
1822 hostif_sme_enqueue(priv, SME_SET_TXKEY);
1823 if (commit & SME_WEP_VAL_MASK)
1824 hostif_sme_enqueue(priv, SME_SET_KEY1 + index);
1825 if (commit & SME_WEP_FLAG)
1826 hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
1832 /* get encoding token & mode (WPA)*/
1833 static int ks_wlan_get_encode_ext(struct net_device *dev,
1834 struct iw_request_info *info,
1835 struct iw_point *dwrq, char *extra)
1837 struct ks_wlan_private *priv = netdev_priv(dev);
1839 if (priv->sleep_mode == SLP_SLEEP)
1842 /* for SLEEP MODE */
1843 /* WPA (not used ?? wpa_supplicant)
1844 * struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
1845 * struct iw_encode_ext *enc;
1846 * enc = (struct iw_encode_ext *)extra;
1847 * int index = dwrq->flags & IW_ENCODE_INDEX;
1848 * WPA (not used ?? wpa_supplicant)
1853 static int ks_wlan_set_pmksa(struct net_device *dev,
1854 struct iw_request_info *info,
1855 struct iw_point *dwrq, char *extra)
1857 struct ks_wlan_private *priv = netdev_priv(dev);
1858 struct iw_pmksa *pmksa;
1861 struct list_head *ptr;
1865 if (priv->sleep_mode == SLP_SLEEP)
1868 /* for SLEEP MODE */
1872 pmksa = (struct iw_pmksa *)extra;
1873 DPRINTK(2, "cmd=%d\n", pmksa->cmd);
1875 switch (pmksa->cmd) {
1877 if (list_empty(&priv->pmklist.head)) { /* new list */
1878 for (i = 0; i < PMK_LIST_MAX; i++) {
1879 pmk = &priv->pmklist.pmk[i];
1880 if (memcmp("\x00\x00\x00\x00\x00\x00",
1881 pmk->bssid, ETH_ALEN) == 0)
1884 memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
1885 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1886 list_add(&pmk->list, &priv->pmklist.head);
1887 priv->pmklist.size++;
1890 /* search cache data */
1891 list_for_each(ptr, &priv->pmklist.head) {
1892 pmk = list_entry(ptr, struct pmk_t, list);
1893 if (memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN) == 0) {
1894 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1895 list_move(&pmk->list, &priv->pmklist.head);
1896 break; /* list_for_each */
1899 if (ptr != &priv->pmklist.head) /* not find address. */
1902 if (priv->pmklist.size < PMK_LIST_MAX) { /* new cache data */
1903 for (i = 0; i < PMK_LIST_MAX; i++) {
1904 pmk = &priv->pmklist.pmk[i];
1905 if (memcmp("\x00\x00\x00\x00\x00\x00",
1906 pmk->bssid, ETH_ALEN) == 0)
1909 memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
1910 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1911 list_add(&pmk->list, &priv->pmklist.head);
1912 priv->pmklist.size++;
1913 } else { /* overwrite old cache data */
1914 pmk = list_entry(priv->pmklist.head.prev, struct pmk_t,
1916 memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
1917 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1918 list_move(&pmk->list, &priv->pmklist.head);
1921 case IW_PMKSA_REMOVE:
1922 if (list_empty(&priv->pmklist.head)) { /* list empty */
1925 /* search cache data */
1926 list_for_each(ptr, &priv->pmklist.head) {
1927 pmk = list_entry(ptr, struct pmk_t, list);
1928 if (memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN) == 0) {
1929 eth_zero_addr(pmk->bssid);
1930 memset(pmk->pmkid, 0, IW_PMKID_LEN);
1931 list_del_init(&pmk->list);
1935 if (ptr == &priv->pmklist.head) { /* not find address. */
1940 case IW_PMKSA_FLUSH:
1941 memset(&priv->pmklist, 0, sizeof(priv->pmklist));
1942 INIT_LIST_HEAD(&priv->pmklist.head);
1943 for (i = 0; i < PMK_LIST_MAX; i++)
1944 INIT_LIST_HEAD(&priv->pmklist.pmk[i].list);
1950 hostif_sme_enqueue(priv, SME_SET_PMKSA);
1954 static struct iw_statistics *ks_get_wireless_stats(struct net_device *dev)
1956 struct ks_wlan_private *priv = netdev_priv(dev);
1957 struct iw_statistics *wstats = &priv->wstats;
1959 if (!atomic_read(&update_phyinfo)) {
1960 if (priv->dev_state < DEVICE_STATE_READY)
1961 return NULL; /* not finished initialize */
1966 /* Packets discarded in the wireless adapter due to wireless
1969 wstats->discard.nwid = 0; /* Rx invalid nwid */
1970 wstats->discard.code = 0; /* Rx invalid crypt */
1971 wstats->discard.fragment = 0; /* Rx invalid frag */
1972 wstats->discard.retries = 0; /* Tx excessive retries */
1973 wstats->discard.misc = 0; /* Invalid misc */
1974 wstats->miss.beacon = 0; /* Missed beacon */
1979 static int ks_wlan_set_stop_request(struct net_device *dev,
1980 struct iw_request_info *info, __u32 *uwrq,
1983 struct ks_wlan_private *priv = netdev_priv(dev);
1987 if (priv->sleep_mode == SLP_SLEEP)
1990 /* for SLEEP MODE */
1994 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
1998 #include <linux/ieee80211.h>
1999 static int ks_wlan_set_mlme(struct net_device *dev,
2000 struct iw_request_info *info, struct iw_point *dwrq,
2003 struct ks_wlan_private *priv = netdev_priv(dev);
2004 struct iw_mlme *mlme = (struct iw_mlme *)extra;
2007 DPRINTK(2, ":%d :%d\n", mlme->cmd, mlme->reason_code);
2009 if (priv->sleep_mode == SLP_SLEEP)
2012 /* for SLEEP MODE */
2013 switch (mlme->cmd) {
2014 case IW_MLME_DEAUTH:
2015 if (mlme->reason_code == WLAN_REASON_MIC_FAILURE)
2017 case IW_MLME_DISASSOC:
2019 return ks_wlan_set_stop_request(dev, NULL, &mode, NULL);
2021 return -EOPNOTSUPP; /* Not Support */
2025 static int ks_wlan_get_firmware_version(struct net_device *dev,
2026 struct iw_request_info *info,
2027 struct iw_point *dwrq, char *extra)
2029 struct ks_wlan_private *priv = netdev_priv(dev);
2031 strcpy(extra, priv->firmware_version);
2032 dwrq->length = priv->version_size + 1;
2036 static int ks_wlan_set_preamble(struct net_device *dev,
2037 struct iw_request_info *info, __u32 *uwrq,
2040 struct ks_wlan_private *priv = netdev_priv(dev);
2042 if (priv->sleep_mode == SLP_SLEEP)
2045 /* for SLEEP MODE */
2046 if (*uwrq == LONG_PREAMBLE) { /* 0 */
2047 priv->reg.preamble = LONG_PREAMBLE;
2048 } else if (*uwrq == SHORT_PREAMBLE) { /* 1 */
2049 priv->reg.preamble = SHORT_PREAMBLE;
2054 priv->need_commit |= SME_MODE_SET;
2055 return -EINPROGRESS; /* Call commit handler */
2058 static int ks_wlan_get_preamble(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.preamble;
2072 static int ks_wlan_set_power_mgmt(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)
2081 /* for SLEEP MODE */
2082 if (*uwrq == POWER_MGMT_ACTIVE) { /* 0 */
2083 priv->reg.power_mgmt = POWER_MGMT_ACTIVE;
2084 } else if (*uwrq == POWER_MGMT_SAVE1) { /* 1 */
2085 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2086 priv->reg.power_mgmt = POWER_MGMT_SAVE1;
2089 } else if (*uwrq == POWER_MGMT_SAVE2) { /* 2 */
2090 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2091 priv->reg.power_mgmt = POWER_MGMT_SAVE2;
2098 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
2103 static int ks_wlan_get_power_mgmt(struct net_device *dev,
2104 struct iw_request_info *info, __u32 *uwrq,
2107 struct ks_wlan_private *priv = netdev_priv(dev);
2109 if (priv->sleep_mode == SLP_SLEEP)
2112 /* for SLEEP MODE */
2113 *uwrq = priv->reg.power_mgmt;
2117 static int ks_wlan_set_scan_type(struct net_device *dev,
2118 struct iw_request_info *info, __u32 *uwrq,
2121 struct ks_wlan_private *priv = netdev_priv(dev);
2123 if (priv->sleep_mode == SLP_SLEEP)
2125 /* for SLEEP MODE */
2126 if (*uwrq == ACTIVE_SCAN) { /* 0 */
2127 priv->reg.scan_type = ACTIVE_SCAN;
2128 } else if (*uwrq == PASSIVE_SCAN) { /* 1 */
2129 priv->reg.scan_type = PASSIVE_SCAN;
2137 static int ks_wlan_get_scan_type(struct net_device *dev,
2138 struct iw_request_info *info, __u32 *uwrq,
2141 struct ks_wlan_private *priv = netdev_priv(dev);
2143 if (priv->sleep_mode == SLP_SLEEP)
2145 /* for SLEEP MODE */
2146 *uwrq = priv->reg.scan_type;
2150 static int ks_wlan_set_beacon_lost(struct net_device *dev,
2151 struct iw_request_info *info, __u32 *uwrq,
2154 struct ks_wlan_private *priv = netdev_priv(dev);
2156 if (priv->sleep_mode == SLP_SLEEP)
2158 /* for SLEEP MODE */
2159 if (*uwrq >= BEACON_LOST_COUNT_MIN && *uwrq <= BEACON_LOST_COUNT_MAX)
2160 priv->reg.beacon_lost_count = *uwrq;
2164 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
2165 priv->need_commit |= SME_MODE_SET;
2166 return -EINPROGRESS; /* Call commit handler */
2172 static int ks_wlan_get_beacon_lost(struct net_device *dev,
2173 struct iw_request_info *info, __u32 *uwrq,
2176 struct ks_wlan_private *priv = netdev_priv(dev);
2178 if (priv->sleep_mode == SLP_SLEEP)
2180 /* for SLEEP MODE */
2181 *uwrq = priv->reg.beacon_lost_count;
2185 static int ks_wlan_set_phy_type(struct net_device *dev,
2186 struct iw_request_info *info, __u32 *uwrq,
2189 struct ks_wlan_private *priv = netdev_priv(dev);
2191 if (priv->sleep_mode == SLP_SLEEP)
2193 /* for SLEEP MODE */
2194 if (*uwrq == D_11B_ONLY_MODE) { /* 0 */
2195 priv->reg.phy_type = D_11B_ONLY_MODE;
2196 } else if (*uwrq == D_11G_ONLY_MODE) { /* 1 */
2197 priv->reg.phy_type = D_11G_ONLY_MODE;
2198 } else if (*uwrq == D_11BG_COMPATIBLE_MODE) { /* 2 */
2199 priv->reg.phy_type = D_11BG_COMPATIBLE_MODE;
2204 priv->need_commit |= SME_MODE_SET;
2205 return -EINPROGRESS; /* Call commit handler */
2208 static int ks_wlan_get_phy_type(struct net_device *dev,
2209 struct iw_request_info *info, __u32 *uwrq,
2212 struct ks_wlan_private *priv = netdev_priv(dev);
2214 if (priv->sleep_mode == SLP_SLEEP)
2216 /* for SLEEP MODE */
2217 *uwrq = priv->reg.phy_type;
2221 static int ks_wlan_set_cts_mode(struct net_device *dev,
2222 struct iw_request_info *info, __u32 *uwrq,
2225 struct ks_wlan_private *priv = netdev_priv(dev);
2227 if (priv->sleep_mode == SLP_SLEEP)
2229 /* for SLEEP MODE */
2230 if (*uwrq == CTS_MODE_FALSE) { /* 0 */
2231 priv->reg.cts_mode = CTS_MODE_FALSE;
2232 } else if (*uwrq == CTS_MODE_TRUE) { /* 1 */
2233 if (priv->reg.phy_type == D_11G_ONLY_MODE ||
2234 priv->reg.phy_type == D_11BG_COMPATIBLE_MODE) {
2235 priv->reg.cts_mode = CTS_MODE_TRUE;
2237 priv->reg.cts_mode = CTS_MODE_FALSE;
2243 priv->need_commit |= SME_MODE_SET;
2244 return -EINPROGRESS; /* Call commit handler */
2247 static int ks_wlan_get_cts_mode(struct net_device *dev,
2248 struct iw_request_info *info, __u32 *uwrq,
2251 struct ks_wlan_private *priv = netdev_priv(dev);
2253 if (priv->sleep_mode == SLP_SLEEP)
2255 /* for SLEEP MODE */
2256 *uwrq = priv->reg.cts_mode;
2260 static int ks_wlan_set_sleep_mode(struct net_device *dev,
2261 struct iw_request_info *info,
2262 __u32 *uwrq, char *extra)
2264 struct ks_wlan_private *priv = netdev_priv(dev);
2268 if (*uwrq == SLP_SLEEP) {
2269 priv->sleep_mode = *uwrq;
2270 netdev_info(dev, "SET_SLEEP_MODE %d\n", priv->sleep_mode);
2272 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2273 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2275 } else if (*uwrq == SLP_ACTIVE) {
2276 priv->sleep_mode = *uwrq;
2277 netdev_info(dev, "SET_SLEEP_MODE %d\n", priv->sleep_mode);
2278 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2280 netdev_err(dev, "SET_SLEEP_MODE %d error\n", *uwrq);
2287 static int ks_wlan_get_sleep_mode(struct net_device *dev,
2288 struct iw_request_info *info,
2289 __u32 *uwrq, char *extra)
2291 struct ks_wlan_private *priv = netdev_priv(dev);
2293 DPRINTK(2, "GET_SLEEP_MODE %d\n", priv->sleep_mode);
2294 *uwrq = priv->sleep_mode;
2301 static int ks_wlan_set_wps_enable(struct net_device *dev,
2302 struct iw_request_info *info, __u32 *uwrq,
2305 struct ks_wlan_private *priv = netdev_priv(dev);
2309 if (priv->sleep_mode == SLP_SLEEP)
2311 /* for SLEEP MODE */
2312 if (*uwrq == 0 || *uwrq == 1)
2313 priv->wps.wps_enabled = *uwrq;
2317 hostif_sme_enqueue(priv, SME_WPS_ENABLE_REQUEST);
2322 static int ks_wlan_get_wps_enable(struct net_device *dev,
2323 struct iw_request_info *info, __u32 *uwrq,
2326 struct ks_wlan_private *priv = netdev_priv(dev);
2330 if (priv->sleep_mode == SLP_SLEEP)
2332 /* for SLEEP MODE */
2333 *uwrq = priv->wps.wps_enabled;
2334 netdev_info(dev, "return=%d\n", *uwrq);
2339 static int ks_wlan_set_wps_probe_req(struct net_device *dev,
2340 struct iw_request_info *info,
2341 struct iw_point *dwrq, char *extra)
2345 struct ks_wlan_private *priv = netdev_priv(dev);
2349 if (priv->sleep_mode == SLP_SLEEP)
2351 /* for SLEEP MODE */
2352 DPRINTK(2, "dwrq->length=%d\n", dwrq->length);
2355 if (p[1] + 2 != dwrq->length || dwrq->length > 256)
2358 priv->wps.ielen = p[1] + 2 + 1; /* IE header + IE + sizeof(len) */
2359 len = p[1] + 2; /* IE header + IE */
2361 memcpy(priv->wps.ie, &len, sizeof(len));
2362 p = memcpy(priv->wps.ie + 1, p, len);
2364 DPRINTK(2, "%d(%#x): %02X %02X %02X %02X ... %02X %02X %02X\n",
2365 priv->wps.ielen, priv->wps.ielen, p[0], p[1], p[2], p[3],
2366 p[priv->wps.ielen - 3], p[priv->wps.ielen - 2],
2367 p[priv->wps.ielen - 1]);
2369 hostif_sme_enqueue(priv, SME_WPS_PROBE_REQUEST);
2375 static int ks_wlan_set_tx_gain(struct net_device *dev,
2376 struct iw_request_info *info, __u32 *uwrq,
2379 struct ks_wlan_private *priv = netdev_priv(dev);
2381 if (priv->sleep_mode == SLP_SLEEP)
2383 /* for SLEEP MODE */
2384 if (*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2385 priv->gain.tx_gain = (uint8_t)*uwrq;
2389 if (priv->gain.tx_gain < 0xFF)
2390 priv->gain.tx_mode = 1;
2392 priv->gain.tx_mode = 0;
2394 hostif_sme_enqueue(priv, SME_SET_GAIN);
2398 static int ks_wlan_get_tx_gain(struct net_device *dev,
2399 struct iw_request_info *info, __u32 *uwrq,
2402 struct ks_wlan_private *priv = netdev_priv(dev);
2404 if (priv->sleep_mode == SLP_SLEEP)
2406 /* for SLEEP MODE */
2407 *uwrq = priv->gain.tx_gain;
2408 hostif_sme_enqueue(priv, SME_GET_GAIN);
2412 static int ks_wlan_set_rx_gain(struct net_device *dev,
2413 struct iw_request_info *info, __u32 *uwrq,
2416 struct ks_wlan_private *priv = netdev_priv(dev);
2418 if (priv->sleep_mode == SLP_SLEEP)
2420 /* for SLEEP MODE */
2421 if (*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2422 priv->gain.rx_gain = (uint8_t)*uwrq;
2426 if (priv->gain.rx_gain < 0xFF)
2427 priv->gain.rx_mode = 1;
2429 priv->gain.rx_mode = 0;
2431 hostif_sme_enqueue(priv, SME_SET_GAIN);
2435 static int ks_wlan_get_rx_gain(struct net_device *dev,
2436 struct iw_request_info *info, __u32 *uwrq,
2439 struct ks_wlan_private *priv = netdev_priv(dev);
2441 if (priv->sleep_mode == SLP_SLEEP)
2443 /* for SLEEP MODE */
2444 *uwrq = priv->gain.rx_gain;
2445 hostif_sme_enqueue(priv, SME_GET_GAIN);
2449 static int ks_wlan_get_eeprom_cksum(struct net_device *dev,
2450 struct iw_request_info *info, __u32 *uwrq,
2453 struct ks_wlan_private *priv = netdev_priv(dev);
2455 *uwrq = priv->eeprom_checksum;
2459 static void print_hif_event(struct net_device *dev, int event)
2463 netdev_info(dev, "HIF_DATA_REQ\n");
2466 netdev_info(dev, "HIF_DATA_IND\n");
2468 case HIF_MIB_GET_REQ:
2469 netdev_info(dev, "HIF_MIB_GET_REQ\n");
2471 case HIF_MIB_GET_CONF:
2472 netdev_info(dev, "HIF_MIB_GET_CONF\n");
2474 case HIF_MIB_SET_REQ:
2475 netdev_info(dev, "HIF_MIB_SET_REQ\n");
2477 case HIF_MIB_SET_CONF:
2478 netdev_info(dev, "HIF_MIB_SET_CONF\n");
2480 case HIF_POWER_MGMT_REQ:
2481 netdev_info(dev, "HIF_POWER_MGMT_REQ\n");
2483 case HIF_POWER_MGMT_CONF:
2484 netdev_info(dev, "HIF_POWER_MGMT_CONF\n");
2487 netdev_info(dev, "HIF_START_REQ\n");
2489 case HIF_START_CONF:
2490 netdev_info(dev, "HIF_START_CONF\n");
2492 case HIF_CONNECT_IND:
2493 netdev_info(dev, "HIF_CONNECT_IND\n");
2496 netdev_info(dev, "HIF_STOP_REQ\n");
2499 netdev_info(dev, "HIF_STOP_CONF\n");
2501 case HIF_PS_ADH_SET_REQ:
2502 netdev_info(dev, "HIF_PS_ADH_SET_REQ\n");
2504 case HIF_PS_ADH_SET_CONF:
2505 netdev_info(dev, "HIF_PS_ADH_SET_CONF\n");
2507 case HIF_INFRA_SET_REQ:
2508 netdev_info(dev, "HIF_INFRA_SET_REQ\n");
2510 case HIF_INFRA_SET_CONF:
2511 netdev_info(dev, "HIF_INFRA_SET_CONF\n");
2513 case HIF_ADH_SET_REQ:
2514 netdev_info(dev, "HIF_ADH_SET_REQ\n");
2516 case HIF_ADH_SET_CONF:
2517 netdev_info(dev, "HIF_ADH_SET_CONF\n");
2519 case HIF_AP_SET_REQ:
2520 netdev_info(dev, "HIF_AP_SET_REQ\n");
2522 case HIF_AP_SET_CONF:
2523 netdev_info(dev, "HIF_AP_SET_CONF\n");
2525 case HIF_ASSOC_INFO_IND:
2526 netdev_info(dev, "HIF_ASSOC_INFO_IND\n");
2528 case HIF_MIC_FAILURE_REQ:
2529 netdev_info(dev, "HIF_MIC_FAILURE_REQ\n");
2531 case HIF_MIC_FAILURE_CONF:
2532 netdev_info(dev, "HIF_MIC_FAILURE_CONF\n");
2535 netdev_info(dev, "HIF_SCAN_REQ\n");
2538 netdev_info(dev, "HIF_SCAN_CONF\n");
2540 case HIF_PHY_INFO_REQ:
2541 netdev_info(dev, "HIF_PHY_INFO_REQ\n");
2543 case HIF_PHY_INFO_CONF:
2544 netdev_info(dev, "HIF_PHY_INFO_CONF\n");
2547 netdev_info(dev, "HIF_SLEEP_REQ\n");
2549 case HIF_SLEEP_CONF:
2550 netdev_info(dev, "HIF_SLEEP_CONF\n");
2552 case HIF_PHY_INFO_IND:
2553 netdev_info(dev, "HIF_PHY_INFO_IND\n");
2556 netdev_info(dev, "HIF_SCAN_IND\n");
2558 case HIF_INFRA_SET2_REQ:
2559 netdev_info(dev, "HIF_INFRA_SET2_REQ\n");
2561 case HIF_INFRA_SET2_CONF:
2562 netdev_info(dev, "HIF_INFRA_SET2_CONF\n");
2564 case HIF_ADH_SET2_REQ:
2565 netdev_info(dev, "HIF_ADH_SET2_REQ\n");
2567 case HIF_ADH_SET2_CONF:
2568 netdev_info(dev, "HIF_ADH_SET2_CONF\n");
2572 /* get host command history */
2573 static int ks_wlan_hostt(struct net_device *dev, struct iw_request_info *info,
2574 __u32 *uwrq, char *extra)
2577 struct ks_wlan_private *priv = netdev_priv(dev);
2579 for (i = 63; i >= 0; i--) {
2581 priv->hostt.buff[(priv->hostt.qtail - 1 - i) %
2582 SME_EVENT_BUFF_SIZE];
2583 print_hif_event(dev, event);
2588 /* Structures to export the Wireless Handlers */
2590 static const struct iw_priv_args ks_wlan_private_args[] = {
2591 /*{ cmd, set_args, get_args, name[16] } */
2592 {KS_WLAN_GET_FIRM_VERSION, IW_PRIV_TYPE_NONE,
2593 IW_PRIV_TYPE_CHAR | (128 + 1), "GetFirmwareVer"},
2595 {KS_WLAN_SET_WPS_ENABLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2596 IW_PRIV_TYPE_NONE, "SetWPSEnable"},
2597 {KS_WLAN_GET_WPS_ENABLE, IW_PRIV_TYPE_NONE,
2598 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetW"},
2599 {KS_WLAN_SET_WPS_PROBE_REQ, IW_PRIV_TYPE_BYTE | 2047, IW_PRIV_TYPE_NONE,
2602 {KS_WLAN_SET_PREAMBLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2603 IW_PRIV_TYPE_NONE, "SetPreamble"},
2604 {KS_WLAN_GET_PREAMBLE, IW_PRIV_TYPE_NONE,
2605 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPreamble"},
2606 {KS_WLAN_SET_POWER_SAVE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2607 IW_PRIV_TYPE_NONE, "SetPowerSave"},
2608 {KS_WLAN_GET_POWER_SAVE, IW_PRIV_TYPE_NONE,
2609 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPowerSave"},
2610 {KS_WLAN_SET_SCAN_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2611 IW_PRIV_TYPE_NONE, "SetScanType"},
2612 {KS_WLAN_GET_SCAN_TYPE, IW_PRIV_TYPE_NONE,
2613 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetScanType"},
2614 {KS_WLAN_SET_RX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2615 IW_PRIV_TYPE_NONE, "SetRxGain"},
2616 {KS_WLAN_GET_RX_GAIN, IW_PRIV_TYPE_NONE,
2617 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetRxGain"},
2618 {KS_WLAN_HOSTT, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | (128 + 1),
2620 {KS_WLAN_SET_BEACON_LOST, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2621 IW_PRIV_TYPE_NONE, "SetBeaconLost"},
2622 {KS_WLAN_GET_BEACON_LOST, IW_PRIV_TYPE_NONE,
2623 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetBeaconLost"},
2624 {KS_WLAN_SET_SLEEP_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2625 IW_PRIV_TYPE_NONE, "SetSleepMode"},
2626 {KS_WLAN_GET_SLEEP_MODE, IW_PRIV_TYPE_NONE,
2627 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetSleepMode"},
2628 {KS_WLAN_SET_TX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2629 IW_PRIV_TYPE_NONE, "SetTxGain"},
2630 {KS_WLAN_GET_TX_GAIN, IW_PRIV_TYPE_NONE,
2631 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetTxGain"},
2632 {KS_WLAN_SET_PHY_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2633 IW_PRIV_TYPE_NONE, "SetPhyType"},
2634 {KS_WLAN_GET_PHY_TYPE, IW_PRIV_TYPE_NONE,
2635 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPhyType"},
2636 {KS_WLAN_SET_CTS_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2637 IW_PRIV_TYPE_NONE, "SetCtsMode"},
2638 {KS_WLAN_GET_CTS_MODE, IW_PRIV_TYPE_NONE,
2639 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetCtsMode"},
2640 {KS_WLAN_GET_EEPROM_CKSUM, IW_PRIV_TYPE_NONE,
2641 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetChecksum"},
2644 static const iw_handler ks_wlan_handler[] = {
2645 (iw_handler)ks_wlan_config_commit, /* SIOCSIWCOMMIT */
2646 (iw_handler)ks_wlan_get_name, /* SIOCGIWNAME */
2647 (iw_handler)NULL, /* SIOCSIWNWID */
2648 (iw_handler)NULL, /* SIOCGIWNWID */
2649 (iw_handler)ks_wlan_set_freq, /* SIOCSIWFREQ */
2650 (iw_handler)ks_wlan_get_freq, /* SIOCGIWFREQ */
2651 (iw_handler)ks_wlan_set_mode, /* SIOCSIWMODE */
2652 (iw_handler)ks_wlan_get_mode, /* SIOCGIWMODE */
2653 #ifndef KSC_OPNOTSUPP
2654 (iw_handler)ks_wlan_set_sens, /* SIOCSIWSENS */
2655 (iw_handler)ks_wlan_get_sens, /* SIOCGIWSENS */
2656 #else /* KSC_OPNOTSUPP */
2657 (iw_handler)NULL, /* SIOCSIWSENS */
2658 (iw_handler)NULL, /* SIOCGIWSENS */
2659 #endif /* KSC_OPNOTSUPP */
2660 (iw_handler)NULL, /* SIOCSIWRANGE */
2661 (iw_handler)ks_wlan_get_range, /* SIOCGIWRANGE */
2662 (iw_handler)NULL, /* SIOCSIWPRIV */
2663 (iw_handler)NULL, /* SIOCGIWPRIV */
2664 (iw_handler)NULL, /* SIOCSIWSTATS */
2665 (iw_handler)ks_wlan_get_iwstats, /* SIOCGIWSTATS */
2666 (iw_handler)NULL, /* SIOCSIWSPY */
2667 (iw_handler)NULL, /* SIOCGIWSPY */
2668 (iw_handler)NULL, /* SIOCSIWTHRSPY */
2669 (iw_handler)NULL, /* SIOCGIWTHRSPY */
2670 (iw_handler)ks_wlan_set_wap, /* SIOCSIWAP */
2671 (iw_handler)ks_wlan_get_wap, /* SIOCGIWAP */
2672 // (iw_handler)NULL, /* SIOCSIWMLME */
2673 (iw_handler)ks_wlan_set_mlme, /* SIOCSIWMLME */
2674 (iw_handler)ks_wlan_get_aplist, /* SIOCGIWAPLIST */
2675 (iw_handler)ks_wlan_set_scan, /* SIOCSIWSCAN */
2676 (iw_handler)ks_wlan_get_scan, /* SIOCGIWSCAN */
2677 (iw_handler)ks_wlan_set_essid, /* SIOCSIWESSID */
2678 (iw_handler)ks_wlan_get_essid, /* SIOCGIWESSID */
2679 (iw_handler)ks_wlan_set_nick, /* SIOCSIWNICKN */
2680 (iw_handler)ks_wlan_get_nick, /* SIOCGIWNICKN */
2681 (iw_handler)NULL, /* -- hole -- */
2682 (iw_handler)NULL, /* -- hole -- */
2683 (iw_handler)ks_wlan_set_rate, /* SIOCSIWRATE */
2684 (iw_handler)ks_wlan_get_rate, /* SIOCGIWRATE */
2685 (iw_handler)ks_wlan_set_rts, /* SIOCSIWRTS */
2686 (iw_handler)ks_wlan_get_rts, /* SIOCGIWRTS */
2687 (iw_handler)ks_wlan_set_frag, /* SIOCSIWFRAG */
2688 (iw_handler)ks_wlan_get_frag, /* SIOCGIWFRAG */
2689 #ifndef KSC_OPNOTSUPP
2690 (iw_handler)ks_wlan_set_txpow, /* SIOCSIWTXPOW */
2691 (iw_handler)ks_wlan_get_txpow, /* SIOCGIWTXPOW */
2692 (iw_handler)ks_wlan_set_retry, /* SIOCSIWRETRY */
2693 (iw_handler)ks_wlan_get_retry, /* SIOCGIWRETRY */
2694 #else /* KSC_OPNOTSUPP */
2695 (iw_handler)NULL, /* SIOCSIWTXPOW */
2696 (iw_handler)NULL, /* SIOCGIWTXPOW */
2697 (iw_handler)NULL, /* SIOCSIWRETRY */
2698 (iw_handler)NULL, /* SIOCGIWRETRY */
2699 #endif /* KSC_OPNOTSUPP */
2700 (iw_handler)ks_wlan_set_encode, /* SIOCSIWENCODE */
2701 (iw_handler)ks_wlan_get_encode, /* SIOCGIWENCODE */
2702 (iw_handler)ks_wlan_set_power, /* SIOCSIWPOWER */
2703 (iw_handler)ks_wlan_get_power, /* SIOCGIWPOWER */
2704 (iw_handler)NULL, /* -- hole -- */
2705 (iw_handler)NULL, /* -- hole -- */
2706 // (iw_handler)NULL, /* SIOCSIWGENIE */
2707 (iw_handler)ks_wlan_set_genie, /* SIOCSIWGENIE */
2708 (iw_handler)NULL, /* SIOCGIWGENIE */
2709 (iw_handler)ks_wlan_set_auth_mode, /* SIOCSIWAUTH */
2710 (iw_handler)ks_wlan_get_auth_mode, /* SIOCGIWAUTH */
2711 (iw_handler)ks_wlan_set_encode_ext, /* SIOCSIWENCODEEXT */
2712 (iw_handler)ks_wlan_get_encode_ext, /* SIOCGIWENCODEEXT */
2713 (iw_handler)ks_wlan_set_pmksa, /* SIOCSIWPMKSA */
2714 (iw_handler)NULL, /* -- hole -- */
2717 /* private_handler */
2718 static const iw_handler ks_wlan_private_handler[] = {
2719 (iw_handler)NULL, /* 0 */
2720 (iw_handler)NULL, /* 1, used to be: KS_WLAN_GET_DRIVER_VERSION */
2721 (iw_handler)NULL, /* 2 */
2722 (iw_handler)ks_wlan_get_firmware_version, /* 3 KS_WLAN_GET_FIRM_VERSION */
2724 (iw_handler)ks_wlan_set_wps_enable, /* 4 KS_WLAN_SET_WPS_ENABLE */
2725 (iw_handler)ks_wlan_get_wps_enable, /* 5 KS_WLAN_GET_WPS_ENABLE */
2726 (iw_handler)ks_wlan_set_wps_probe_req, /* 6 KS_WLAN_SET_WPS_PROBE_REQ */
2728 (iw_handler)NULL, /* 4 */
2729 (iw_handler)NULL, /* 5 */
2730 (iw_handler)NULL, /* 6 */
2733 (iw_handler)ks_wlan_get_eeprom_cksum, /* 7 KS_WLAN_GET_CONNECT */
2734 (iw_handler)ks_wlan_set_preamble, /* 8 KS_WLAN_SET_PREAMBLE */
2735 (iw_handler)ks_wlan_get_preamble, /* 9 KS_WLAN_GET_PREAMBLE */
2736 (iw_handler)ks_wlan_set_power_mgmt, /* 10 KS_WLAN_SET_POWER_SAVE */
2737 (iw_handler)ks_wlan_get_power_mgmt, /* 11 KS_WLAN_GET_POWER_SAVE */
2738 (iw_handler)ks_wlan_set_scan_type, /* 12 KS_WLAN_SET_SCAN_TYPE */
2739 (iw_handler)ks_wlan_get_scan_type, /* 13 KS_WLAN_GET_SCAN_TYPE */
2740 (iw_handler)ks_wlan_set_rx_gain, /* 14 KS_WLAN_SET_RX_GAIN */
2741 (iw_handler)ks_wlan_get_rx_gain, /* 15 KS_WLAN_GET_RX_GAIN */
2742 (iw_handler)ks_wlan_hostt, /* 16 KS_WLAN_HOSTT */
2743 (iw_handler)NULL, /* 17 */
2744 (iw_handler)ks_wlan_set_beacon_lost, /* 18 KS_WLAN_SET_BECAN_LOST */
2745 (iw_handler)ks_wlan_get_beacon_lost, /* 19 KS_WLAN_GET_BECAN_LOST */
2746 (iw_handler)ks_wlan_set_tx_gain, /* 20 KS_WLAN_SET_TX_GAIN */
2747 (iw_handler)ks_wlan_get_tx_gain, /* 21 KS_WLAN_GET_TX_GAIN */
2748 (iw_handler)ks_wlan_set_phy_type, /* 22 KS_WLAN_SET_PHY_TYPE */
2749 (iw_handler)ks_wlan_get_phy_type, /* 23 KS_WLAN_GET_PHY_TYPE */
2750 (iw_handler)ks_wlan_set_cts_mode, /* 24 KS_WLAN_SET_CTS_MODE */
2751 (iw_handler)ks_wlan_get_cts_mode, /* 25 KS_WLAN_GET_CTS_MODE */
2752 (iw_handler)NULL, /* 26 */
2753 (iw_handler)NULL, /* 27 */
2754 (iw_handler)ks_wlan_set_sleep_mode, /* 28 KS_WLAN_SET_SLEEP_MODE */
2755 (iw_handler)ks_wlan_get_sleep_mode, /* 29 KS_WLAN_GET_SLEEP_MODE */
2756 (iw_handler)NULL, /* 30 */
2757 (iw_handler)NULL, /* 31 */
2760 static const struct iw_handler_def ks_wlan_handler_def = {
2761 .num_standard = sizeof(ks_wlan_handler) / sizeof(iw_handler),
2762 .num_private = sizeof(ks_wlan_private_handler) / sizeof(iw_handler),
2764 sizeof(ks_wlan_private_args) / sizeof(struct iw_priv_args),
2765 .standard = (iw_handler *)ks_wlan_handler,
2766 .private = (iw_handler *)ks_wlan_private_handler,
2767 .private_args = (struct iw_priv_args *)ks_wlan_private_args,
2768 .get_wireless_stats = ks_get_wireless_stats,
2771 static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq,
2775 struct iwreq *wrq = (struct iwreq *)rq;
2778 case SIOCIWFIRSTPRIV + 20: /* KS_WLAN_SET_STOP_REQ */
2779 ret = ks_wlan_set_stop_request(dev, NULL, &wrq->u.mode, NULL);
2781 // All other calls are currently unsupported
2786 DPRINTK(5, "return=%d\n", ret);
2791 struct net_device_stats *ks_wlan_get_stats(struct net_device *dev)
2793 struct ks_wlan_private *priv = netdev_priv(dev);
2795 if (priv->dev_state < DEVICE_STATE_READY)
2796 return NULL; /* not finished initialize */
2798 return &priv->nstats;
2802 int ks_wlan_set_mac_address(struct net_device *dev, void *addr)
2804 struct ks_wlan_private *priv = netdev_priv(dev);
2805 struct sockaddr *mac_addr = (struct sockaddr *)addr;
2807 if (netif_running(dev))
2809 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
2810 memcpy(priv->eth_addr, mac_addr->sa_data, ETH_ALEN);
2812 priv->mac_address_valid = 0;
2813 hostif_sme_enqueue(priv, SME_MACADDRESS_SET_REQUEST);
2814 netdev_info(dev, "ks_wlan: MAC ADDRESS = %pM\n", priv->eth_addr);
2819 void ks_wlan_tx_timeout(struct net_device *dev)
2821 struct ks_wlan_private *priv = netdev_priv(dev);
2823 DPRINTK(1, "head(%d) tail(%d)!!\n", priv->tx_dev.qhead,
2824 priv->tx_dev.qtail);
2825 if (!netif_queue_stopped(dev))
2826 netif_stop_queue(dev);
2827 priv->nstats.tx_errors++;
2828 netif_wake_queue(dev);
2832 int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev)
2834 struct ks_wlan_private *priv = netdev_priv(dev);
2837 DPRINTK(3, "in_interrupt()=%ld\n", in_interrupt());
2840 netdev_err(dev, "ks_wlan: skb == NULL!!!\n");
2843 if (priv->dev_state < DEVICE_STATE_READY) {
2845 return 0; /* not finished initialize */
2848 if (netif_running(dev))
2849 netif_stop_queue(dev);
2851 ret = hostif_data_request(priv, skb);
2852 netif_trans_update(dev);
2855 DPRINTK(4, "hostif_data_request error: =%d\n", ret);
2860 void send_packet_complete(struct ks_wlan_private *priv, struct sk_buff *skb)
2864 priv->nstats.tx_packets++;
2866 if (netif_queue_stopped(priv->net_dev))
2867 netif_wake_queue(priv->net_dev);
2870 priv->nstats.tx_bytes += skb->len;
2876 * Set or clear the multicast filter for this adaptor.
2877 * This routine is not state sensitive and need not be SMP locked.
2880 void ks_wlan_set_multicast_list(struct net_device *dev)
2882 struct ks_wlan_private *priv = netdev_priv(dev);
2885 if (priv->dev_state < DEVICE_STATE_READY)
2886 return; /* not finished initialize */
2887 hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST);
2891 int ks_wlan_open(struct net_device *dev)
2893 struct ks_wlan_private *priv = netdev_priv(dev);
2897 if (!priv->mac_address_valid) {
2898 netdev_err(dev, "ks_wlan : %s Not READY !!\n", dev->name);
2901 netif_start_queue(dev);
2907 int ks_wlan_close(struct net_device *dev)
2909 netif_stop_queue(dev);
2911 DPRINTK(4, "%s: Shutting down ethercard, status was 0x%4.4x.\n",
2917 /* Operational parameters that usually are not changed. */
2918 /* Time in jiffies before concluding the transmitter is hung. */
2919 #define TX_TIMEOUT (3 * HZ)
2920 static const unsigned char dummy_addr[] = {
2921 0x00, 0x0b, 0xe3, 0x00, 0x00, 0x00
2924 static const struct net_device_ops ks_wlan_netdev_ops = {
2925 .ndo_start_xmit = ks_wlan_start_xmit,
2926 .ndo_open = ks_wlan_open,
2927 .ndo_stop = ks_wlan_close,
2928 .ndo_do_ioctl = ks_wlan_netdev_ioctl,
2929 .ndo_set_mac_address = ks_wlan_set_mac_address,
2930 .ndo_get_stats = ks_wlan_get_stats,
2931 .ndo_tx_timeout = ks_wlan_tx_timeout,
2932 .ndo_set_rx_mode = ks_wlan_set_multicast_list,
2935 int ks_wlan_net_start(struct net_device *dev)
2937 struct ks_wlan_private *priv;
2940 priv = netdev_priv(dev);
2941 priv->mac_address_valid = 0;
2942 priv->need_commit = 0;
2944 priv->device_open_status = 1;
2946 /* phy information update timer */
2947 atomic_set(&update_phyinfo, 0);
2948 setup_timer(&update_phyinfo_timer, ks_wlan_update_phyinfo_timeout,
2949 (unsigned long)priv);
2951 /* dummy address set */
2952 memcpy(priv->eth_addr, dummy_addr, ETH_ALEN);
2953 dev->dev_addr[0] = priv->eth_addr[0];
2954 dev->dev_addr[1] = priv->eth_addr[1];
2955 dev->dev_addr[2] = priv->eth_addr[2];
2956 dev->dev_addr[3] = priv->eth_addr[3];
2957 dev->dev_addr[4] = priv->eth_addr[4];
2958 dev->dev_addr[5] = priv->eth_addr[5];
2959 dev->dev_addr[6] = 0x00;
2960 dev->dev_addr[7] = 0x00;
2962 /* The ks_wlan-specific entries in the device structure. */
2963 dev->netdev_ops = &ks_wlan_netdev_ops;
2964 dev->wireless_handlers = (struct iw_handler_def *)&ks_wlan_handler_def;
2965 dev->watchdog_timeo = TX_TIMEOUT;
2967 netif_carrier_off(dev);
2972 int ks_wlan_net_stop(struct net_device *dev)
2974 struct ks_wlan_private *priv = netdev_priv(dev);
2976 priv->device_open_status = 0;
2977 del_timer_sync(&update_phyinfo_timer);
2979 if (netif_running(dev))
2980 netif_stop_queue(dev);
2986 * is_connect_status() - return true if status is 'connected'
2987 * @status: high bit is used as FORCE_DISCONNECT, low bits used for
2990 bool is_connect_status(u32 status)
2992 return (status & CONNECT_STATUS_MASK) == CONNECT_STATUS;
2996 * is_disconnect_status() - return true if status is 'disconnected'
2997 * @status: high bit is used as FORCE_DISCONNECT, low bits used for
2998 * disconnect status.
3000 bool is_disconnect_status(u32 status)
3002 return (status & CONNECT_STATUS_MASK) == DISCONNECT_STATUS;