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] =
478 priv->reg.rate_set.body[2] = TX_RATE_5M;
482 priv->reg.rate_set.body[1] =
483 TX_RATE_2M | BASIC_RATE;
487 priv->reg.rate_set.body[0] =
488 TX_RATE_1M | BASIC_RATE;
494 priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
495 priv->reg.rate_set.size = i;
497 priv->reg.rate_set.body[3] = TX_RATE_11M;
498 priv->reg.rate_set.body[2] = TX_RATE_5M;
499 priv->reg.rate_set.body[1] =
500 TX_RATE_2M | BASIC_RATE;
501 priv->reg.rate_set.body[0] =
502 TX_RATE_1M | BASIC_RATE;
503 priv->reg.tx_rate = TX_RATE_FULL_AUTO;
504 priv->reg.rate_set.size = 4;
507 } else { /* D_11B_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
508 if (vwrq->fixed == 1) {
509 switch (vwrq->value) {
515 priv->reg.rate_set.body[0] =
516 (uint8_t)(vwrq->value / 500000);
525 priv->reg.rate_set.body[0] =
526 ((uint8_t)(vwrq->value / 500000)) |
532 priv->reg.tx_rate = TX_RATE_FIXED;
533 priv->reg.rate_set.size = 1;
534 } else { /* vwrq->fixed == 0 */
535 if (vwrq->value > 0) {
536 switch (vwrq->value) {
538 priv->reg.rate_set.body[11] =
543 priv->reg.rate_set.body[10] =
548 priv->reg.rate_set.body[9] =
558 if (vwrq->value == 24000000) {
559 priv->reg.rate_set.body[8] =
562 priv->reg.rate_set.body[7] =
565 priv->reg.rate_set.body[6] =
566 TX_RATE_24M | BASIC_RATE;
568 priv->reg.rate_set.body[5] =
569 TX_RATE_12M | BASIC_RATE;
571 priv->reg.rate_set.body[4] =
572 TX_RATE_6M | BASIC_RATE;
574 priv->reg.rate_set.body[3] =
575 TX_RATE_11M | BASIC_RATE;
577 } else if (vwrq->value == 18000000) {
578 priv->reg.rate_set.body[7] =
581 priv->reg.rate_set.body[6] =
584 priv->reg.rate_set.body[5] =
585 TX_RATE_12M | BASIC_RATE;
587 priv->reg.rate_set.body[4] =
588 TX_RATE_6M | BASIC_RATE;
590 priv->reg.rate_set.body[3] =
591 TX_RATE_11M | BASIC_RATE;
593 } else if (vwrq->value == 12000000) {
594 priv->reg.rate_set.body[6] =
597 priv->reg.rate_set.body[5] =
598 TX_RATE_12M | BASIC_RATE;
600 priv->reg.rate_set.body[4] =
601 TX_RATE_6M | BASIC_RATE;
603 priv->reg.rate_set.body[3] =
604 TX_RATE_11M | BASIC_RATE;
606 } else if (vwrq->value == 11000000) {
607 priv->reg.rate_set.body[5] =
610 priv->reg.rate_set.body[4] =
611 TX_RATE_6M | BASIC_RATE;
613 priv->reg.rate_set.body[3] =
614 TX_RATE_11M | BASIC_RATE;
616 } else if (vwrq->value == 9000000) {
617 priv->reg.rate_set.body[4] =
620 priv->reg.rate_set.body[3] =
621 TX_RATE_6M | BASIC_RATE;
623 } else { /* vwrq->value == 6000000 */
624 priv->reg.rate_set.body[3] =
625 TX_RATE_6M | BASIC_RATE;
630 priv->reg.rate_set.body[2] =
631 TX_RATE_5M | BASIC_RATE;
635 priv->reg.rate_set.body[1] =
636 TX_RATE_2M | BASIC_RATE;
640 priv->reg.rate_set.body[0] =
641 TX_RATE_1M | BASIC_RATE;
647 priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
648 priv->reg.rate_set.size = i;
650 priv->reg.rate_set.body[11] = TX_RATE_54M;
651 priv->reg.rate_set.body[10] = TX_RATE_48M;
652 priv->reg.rate_set.body[9] = TX_RATE_36M;
653 priv->reg.rate_set.body[8] = TX_RATE_18M;
654 priv->reg.rate_set.body[7] = TX_RATE_9M;
655 priv->reg.rate_set.body[6] =
656 TX_RATE_24M | BASIC_RATE;
657 priv->reg.rate_set.body[5] =
658 TX_RATE_12M | BASIC_RATE;
659 priv->reg.rate_set.body[4] =
660 TX_RATE_6M | BASIC_RATE;
661 priv->reg.rate_set.body[3] =
662 TX_RATE_11M | BASIC_RATE;
663 priv->reg.rate_set.body[2] =
664 TX_RATE_5M | BASIC_RATE;
665 priv->reg.rate_set.body[1] =
666 TX_RATE_2M | BASIC_RATE;
667 priv->reg.rate_set.body[0] =
668 TX_RATE_1M | BASIC_RATE;
669 priv->reg.tx_rate = TX_RATE_FULL_AUTO;
670 priv->reg.rate_set.size = 12;
675 priv->need_commit |= SME_MODE_SET;
677 return -EINPROGRESS; /* Call commit handler */
680 static int ks_wlan_get_rate(struct net_device *dev,
681 struct iw_request_info *info, struct iw_param *vwrq,
684 struct ks_wlan_private *priv = netdev_priv(dev);
686 DPRINTK(2, "in_interrupt = %ld update_phyinfo = %d\n",
687 in_interrupt(), atomic_read(&update_phyinfo));
689 if (priv->sleep_mode == SLP_SLEEP)
693 if (!atomic_read(&update_phyinfo))
694 ks_wlan_update_phy_information(priv);
696 vwrq->value = ((priv->current_rate) & RATE_MASK) * 500000;
697 if (priv->reg.tx_rate == TX_RATE_FIXED)
705 static int ks_wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
706 struct iw_param *vwrq, char *extra)
708 struct ks_wlan_private *priv = netdev_priv(dev);
709 int rthr = vwrq->value;
711 if (priv->sleep_mode == SLP_SLEEP)
717 if ((rthr < 0) || (rthr > 2347))
720 priv->reg.rts = rthr;
721 priv->need_commit |= SME_RTS;
723 return -EINPROGRESS; /* Call commit handler */
726 static int ks_wlan_get_rts(struct net_device *dev, struct iw_request_info *info,
727 struct iw_param *vwrq, char *extra)
729 struct ks_wlan_private *priv = netdev_priv(dev);
731 if (priv->sleep_mode == SLP_SLEEP)
735 vwrq->value = priv->reg.rts;
736 vwrq->disabled = (vwrq->value >= 2347);
742 static int ks_wlan_set_frag(struct net_device *dev,
743 struct iw_request_info *info, struct iw_param *vwrq,
746 struct ks_wlan_private *priv = netdev_priv(dev);
747 int fthr = vwrq->value;
749 if (priv->sleep_mode == SLP_SLEEP)
755 if ((fthr < 256) || (fthr > 2346))
758 fthr &= ~0x1; /* Get an even value - is it really needed ??? */
759 priv->reg.fragment = fthr;
760 priv->need_commit |= SME_FRAG;
762 return -EINPROGRESS; /* Call commit handler */
765 static int ks_wlan_get_frag(struct net_device *dev,
766 struct iw_request_info *info, struct iw_param *vwrq,
769 struct ks_wlan_private *priv = netdev_priv(dev);
771 if (priv->sleep_mode == SLP_SLEEP)
775 vwrq->value = priv->reg.fragment;
776 vwrq->disabled = (vwrq->value >= 2346);
782 static int ks_wlan_set_mode(struct net_device *dev,
783 struct iw_request_info *info, __u32 *uwrq,
786 struct ks_wlan_private *priv = netdev_priv(dev);
788 DPRINTK(2, "mode=%d\n", *uwrq);
790 if (priv->sleep_mode == SLP_SLEEP)
796 priv->reg.operation_mode = MODE_ADHOC;
797 priv->need_commit |= SME_MODE_SET;
800 priv->reg.operation_mode = MODE_INFRASTRUCTURE;
801 priv->need_commit |= SME_MODE_SET;
807 case IW_MODE_MONITOR:
812 return -EINPROGRESS; /* Call commit handler */
815 static int ks_wlan_get_mode(struct net_device *dev,
816 struct iw_request_info *info, __u32 *uwrq,
819 struct ks_wlan_private *priv = netdev_priv(dev);
821 if (priv->sleep_mode == SLP_SLEEP)
825 /* If not managed, assume it's ad-hoc */
826 switch (priv->reg.operation_mode) {
827 case MODE_INFRASTRUCTURE:
828 *uwrq = IW_MODE_INFRA;
831 *uwrq = IW_MODE_ADHOC;
834 *uwrq = IW_MODE_ADHOC;
840 static int ks_wlan_set_encode(struct net_device *dev,
841 struct iw_request_info *info,
842 struct iw_point *dwrq, char *extra)
844 struct ks_wlan_private *priv = netdev_priv(dev);
847 int index = (dwrq->flags & IW_ENCODE_INDEX);
848 int current_index = priv->reg.wep_index;
851 DPRINTK(2, "flags=%04X\n", dwrq->flags);
853 if (priv->sleep_mode == SLP_SLEEP)
858 if ((index < 0) || (index > 4))
861 index = current_index;
865 /* Is WEP supported ? */
866 /* Basic checking: do we have a key to set ? */
867 if (dwrq->length > 0) {
868 if (dwrq->length > MAX_KEY_SIZE) { /* Check the size of the key */
871 if (dwrq->length > MIN_KEY_SIZE) { /* Set the length */
872 key.len = MAX_KEY_SIZE;
873 priv->reg.privacy_invoked = 0x01;
874 priv->need_commit |= SME_WEP_FLAG;
875 wep_on_off = WEP_ON_128BIT;
877 if (dwrq->length > 0) {
878 key.len = MIN_KEY_SIZE;
879 priv->reg.privacy_invoked = 0x01;
880 priv->need_commit |= SME_WEP_FLAG;
881 wep_on_off = WEP_ON_64BIT;
882 } else { /* Disable the key */
886 /* Check if the key is not marked as invalid */
887 if (!(dwrq->flags & IW_ENCODE_NOKEY)) {
889 memset(key.key, 0, MAX_KEY_SIZE);
890 /* Copy the key in the driver */
892 (key.key, dwrq->pointer, dwrq->length)) {
896 /* Send the key to the card */
897 priv->reg.wep_key[index].size = key.len;
898 for (i = 0; i < (priv->reg.wep_key[index].size); i++)
899 priv->reg.wep_key[index].val[i] = key.key[i];
901 priv->need_commit |= (SME_WEP_VAL1 << index);
902 priv->reg.wep_index = index;
903 priv->need_commit |= SME_WEP_INDEX;
906 if (dwrq->flags & IW_ENCODE_DISABLED) {
907 priv->reg.wep_key[0].size = 0;
908 priv->reg.wep_key[1].size = 0;
909 priv->reg.wep_key[2].size = 0;
910 priv->reg.wep_key[3].size = 0;
911 priv->reg.privacy_invoked = 0x00;
912 if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY)
913 priv->need_commit |= SME_MODE_SET;
915 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
916 wep_on_off = WEP_OFF;
917 priv->need_commit |= SME_WEP_FLAG;
919 /* Do we want to just set the transmit key index ? */
920 if ((index >= 0) && (index < 4)) {
921 /* set_wep_key(priv, index, 0, 0, 1); xxx */
922 if (priv->reg.wep_key[index].size != 0) {
923 priv->reg.wep_index = index;
924 priv->need_commit |= SME_WEP_INDEX;
932 /* Commit the changes if needed */
933 if (dwrq->flags & IW_ENCODE_MODE)
934 priv->need_commit |= SME_WEP_FLAG;
936 if (dwrq->flags & IW_ENCODE_OPEN) {
937 if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY)
938 priv->need_commit |= SME_MODE_SET;
940 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
941 } else if (dwrq->flags & IW_ENCODE_RESTRICTED) {
942 if (priv->reg.authenticate_type == AUTH_TYPE_OPEN_SYSTEM)
943 priv->need_commit |= SME_MODE_SET;
945 priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
947 // return -EINPROGRESS; /* Call commit handler */
948 if (priv->need_commit) {
949 ks_wlan_setup_parameter(priv, priv->need_commit);
950 priv->need_commit = 0;
955 static int ks_wlan_get_encode(struct net_device *dev,
956 struct iw_request_info *info,
957 struct iw_point *dwrq, char *extra)
959 struct ks_wlan_private *priv = netdev_priv(dev);
961 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
963 if (priv->sleep_mode == SLP_SLEEP)
967 dwrq->flags = IW_ENCODE_DISABLED;
969 /* Check encryption mode */
970 switch (priv->reg.authenticate_type) {
971 case AUTH_TYPE_OPEN_SYSTEM:
972 dwrq->flags = IW_ENCODE_OPEN;
974 case AUTH_TYPE_SHARED_KEY:
975 dwrq->flags = IW_ENCODE_RESTRICTED;
979 memset(zeros, 0, sizeof(zeros));
981 /* Which key do we want ? -1 -> tx index */
982 if ((index < 0) || (index >= 4))
983 index = priv->reg.wep_index;
984 if (priv->reg.privacy_invoked) {
985 dwrq->flags &= ~IW_ENCODE_DISABLED;
986 /* dwrq->flags |= IW_ENCODE_NOKEY; */
988 dwrq->flags |= index + 1;
989 DPRINTK(2, "encoding flag = 0x%04X\n", dwrq->flags);
990 /* Copy the key to the user buffer */
991 if ((index >= 0) && (index < 4))
992 dwrq->length = priv->reg.wep_key[index].size;
993 if (dwrq->length > 16)
995 #if 1 /* IW_ENCODE_NOKEY; */
997 if ((index >= 0) && (index < 4))
998 memcpy(extra, priv->reg.wep_key[index].val,
1001 memcpy(extra, zeros, dwrq->length);
1007 #ifndef KSC_OPNOTSUPP
1008 static int ks_wlan_set_txpow(struct net_device *dev,
1009 struct iw_request_info *info,
1010 struct iw_param *vwrq, char *extra)
1012 return -EOPNOTSUPP; /* Not Support */
1015 static int ks_wlan_get_txpow(struct net_device *dev,
1016 struct iw_request_info *info,
1017 struct iw_param *vwrq, char *extra)
1019 if (priv->sleep_mode == SLP_SLEEP)
1022 /* for SLEEP MODE */
1025 vwrq->disabled = (vwrq->value == 0);
1030 static int ks_wlan_set_retry(struct net_device *dev,
1031 struct iw_request_info *info,
1032 struct iw_param *vwrq, char *extra)
1034 return -EOPNOTSUPP; /* Not Support */
1037 static int ks_wlan_get_retry(struct net_device *dev,
1038 struct iw_request_info *info,
1039 struct iw_param *vwrq, char *extra)
1041 if (priv->sleep_mode == SLP_SLEEP)
1044 /* for SLEEP MODE */
1047 vwrq->disabled = (vwrq->value == 0);
1051 #endif /* KSC_OPNOTSUPP */
1053 static int ks_wlan_get_range(struct net_device *dev,
1054 struct iw_request_info *info,
1055 struct iw_point *dwrq, char *extra)
1057 struct ks_wlan_private *priv = netdev_priv(dev);
1058 struct iw_range *range = (struct iw_range *)extra;
1063 if (priv->sleep_mode == SLP_SLEEP)
1066 /* for SLEEP MODE */
1067 dwrq->length = sizeof(struct iw_range);
1068 memset(range, 0, sizeof(*range));
1069 range->min_nwid = 0x0000;
1070 range->max_nwid = 0x0000;
1071 range->num_channels = 14;
1072 /* Should be based on cap_rid.country to give only
1073 * what the current card support
1076 for (i = 0; i < 13; i++) { /* channel 1 -- 13 */
1077 range->freq[k].i = i + 1; /* List index */
1078 range->freq[k].m = frequency_list[i] * 100000;
1079 range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
1081 range->num_frequency = k;
1082 if (priv->reg.phy_type == D_11B_ONLY_MODE || priv->reg.phy_type == D_11BG_COMPATIBLE_MODE) { /* channel 14 */
1083 range->freq[13].i = 14; /* List index */
1084 range->freq[13].m = frequency_list[13] * 100000;
1085 range->freq[13].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
1086 range->num_frequency = 14;
1089 /* Hum... Should put the right values there */
1090 range->max_qual.qual = 100;
1091 range->max_qual.level = 256 - 128; /* 0 dBm? */
1092 range->max_qual.noise = 256 - 128;
1093 range->sensitivity = 1;
1095 if (priv->reg.phy_type == D_11B_ONLY_MODE) {
1096 range->bitrate[0] = 1e6;
1097 range->bitrate[1] = 2e6;
1098 range->bitrate[2] = 5.5e6;
1099 range->bitrate[3] = 11e6;
1100 range->num_bitrates = 4;
1101 } else { /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
1102 range->bitrate[0] = 1e6;
1103 range->bitrate[1] = 2e6;
1104 range->bitrate[2] = 5.5e6;
1105 range->bitrate[3] = 11e6;
1107 range->bitrate[4] = 6e6;
1108 range->bitrate[5] = 9e6;
1109 range->bitrate[6] = 12e6;
1110 if (IW_MAX_BITRATES < 9) {
1111 range->bitrate[7] = 54e6;
1112 range->num_bitrates = 8;
1114 range->bitrate[7] = 18e6;
1115 range->bitrate[8] = 24e6;
1116 range->bitrate[9] = 36e6;
1117 range->bitrate[10] = 48e6;
1118 range->bitrate[11] = 54e6;
1120 range->num_bitrates = 12;
1124 /* Set an indication of the max TCP throughput
1125 * in bit/s that we can expect using this interface.
1126 * May be use for QoS stuff... Jean II
1129 range->throughput = 5000 * 1000;
1131 range->throughput = 1500 * 1000;
1134 range->max_rts = 2347;
1135 range->min_frag = 256;
1136 range->max_frag = 2346;
1138 range->encoding_size[0] = 5; /* WEP: RC4 40 bits */
1139 range->encoding_size[1] = 13; /* WEP: RC4 ~128 bits */
1140 range->num_encoding_sizes = 2;
1141 range->max_encoding_tokens = 4;
1143 /* power management not support */
1144 range->pmp_flags = IW_POWER_ON;
1145 range->pmt_flags = IW_POWER_ON;
1148 /* Transmit Power - values are in dBm( or mW) */
1149 range->txpower[0] = -256;
1150 range->num_txpower = 1;
1151 range->txpower_capa = IW_TXPOW_DBM;
1152 /* range->txpower_capa = IW_TXPOW_MWATT; */
1154 range->we_version_source = 21;
1155 range->we_version_compiled = WIRELESS_EXT;
1157 range->retry_capa = IW_RETRY_ON;
1158 range->retry_flags = IW_RETRY_ON;
1159 range->r_time_flags = IW_RETRY_ON;
1161 /* Experimental measurements - boundary 11/5.5 Mb/s
1163 * Note : with or without the (local->rssi), results
1164 * are somewhat different. - Jean II
1166 range->avg_qual.qual = 50;
1167 range->avg_qual.level = 186; /* -70 dBm */
1168 range->avg_qual.noise = 0;
1170 /* Event capability (kernel + driver) */
1171 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
1172 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
1173 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
1174 range->event_capa[1] = IW_EVENT_CAPA_K_1;
1175 range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVCUSTOM) |
1176 IW_EVENT_CAPA_MASK(IWEVMICHAELMICFAILURE));
1178 /* encode extension (WPA) capability */
1179 range->enc_capa = (IW_ENC_CAPA_WPA |
1181 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP);
1185 static int ks_wlan_set_power(struct net_device *dev,
1186 struct iw_request_info *info,
1187 struct iw_param *vwrq, char *extra)
1189 struct ks_wlan_private *priv = netdev_priv(dev);
1191 if (priv->sleep_mode == SLP_SLEEP)
1194 if (vwrq->disabled) {
1195 priv->reg.power_mgmt = POWER_MGMT_ACTIVE;
1197 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
1198 priv->reg.power_mgmt = POWER_MGMT_SAVE1;
1203 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
1208 static int ks_wlan_get_power(struct net_device *dev,
1209 struct iw_request_info *info,
1210 struct iw_param *vwrq, char *extra)
1212 struct ks_wlan_private *priv = netdev_priv(dev);
1214 if (priv->sleep_mode == SLP_SLEEP)
1216 /* for SLEEP MODE */
1217 if (priv->reg.power_mgmt > 0)
1225 static int ks_wlan_get_iwstats(struct net_device *dev,
1226 struct iw_request_info *info,
1227 struct iw_quality *vwrq, char *extra)
1229 struct ks_wlan_private *priv = netdev_priv(dev);
1231 if (priv->sleep_mode == SLP_SLEEP)
1233 /* for SLEEP MODE */
1234 vwrq->qual = 0; /* not supported */
1235 vwrq->level = priv->wstats.qual.level;
1236 vwrq->noise = 0; /* not supported */
1242 #ifndef KSC_OPNOTSUPP
1244 static int ks_wlan_set_sens(struct net_device *dev,
1245 struct iw_request_info *info, struct iw_param *vwrq,
1248 return -EOPNOTSUPP; /* Not Support */
1251 static int ks_wlan_get_sens(struct net_device *dev,
1252 struct iw_request_info *info, struct iw_param *vwrq,
1257 vwrq->disabled = (vwrq->value == 0);
1261 #endif /* KSC_OPNOTSUPP */
1263 /* Note : this is deprecated in favor of IWSCAN */
1264 static int ks_wlan_get_aplist(struct net_device *dev,
1265 struct iw_request_info *info,
1266 struct iw_point *dwrq, char *extra)
1268 struct ks_wlan_private *priv = netdev_priv(dev);
1269 struct sockaddr *address = (struct sockaddr *)extra;
1270 struct iw_quality qual[LOCAL_APLIST_MAX];
1274 if (priv->sleep_mode == SLP_SLEEP)
1276 /* for SLEEP MODE */
1277 for (i = 0; i < priv->aplist.size; i++) {
1278 memcpy(address[i].sa_data, &(priv->aplist.ap[i].bssid[0]),
1280 address[i].sa_family = ARPHRD_ETHER;
1281 qual[i].level = 256 - priv->aplist.ap[i].rssi;
1282 qual[i].qual = priv->aplist.ap[i].sq;
1283 qual[i].noise = 0; /* invalid noise value */
1284 qual[i].updated = 7;
1287 dwrq->flags = 1; /* Should be define'd */
1288 memcpy(extra + sizeof(struct sockaddr) * i,
1289 &qual, sizeof(struct iw_quality) * i);
1296 static int ks_wlan_set_scan(struct net_device *dev,
1297 struct iw_request_info *info,
1298 union iwreq_data *wrqu, char *extra)
1300 struct ks_wlan_private *priv = netdev_priv(dev);
1301 struct iw_scan_req *req = NULL;
1305 if (priv->sleep_mode == SLP_SLEEP)
1308 /* for SLEEP MODE */
1309 /* specified SSID SCAN */
1310 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
1311 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1312 req = (struct iw_scan_req *)extra;
1313 priv->scan_ssid_len = req->essid_len;
1314 memcpy(priv->scan_ssid, req->essid, priv->scan_ssid_len);
1316 priv->scan_ssid_len = 0;
1319 priv->sme_i.sme_flag |= SME_AP_SCAN;
1320 hostif_sme_enqueue(priv, SME_BSS_SCAN_REQUEST);
1322 /* At this point, just return to the user. */
1328 * Translate scan data returned from the card to a card independent
1329 * format that the Wireless Tools will understand - Jean II
1331 static inline char *ks_wlan_translate_scan(struct net_device *dev,
1332 struct iw_request_info *info,
1333 char *current_ev, char *end_buf,
1334 struct local_ap_t *ap)
1336 /* struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; */
1337 struct iw_event iwe; /* Temporary buffer */
1339 char *current_val; /* For rates */
1341 static const char rsn_leader[] = "rsn_ie=";
1342 static const char wpa_leader[] = "wpa_ie=";
1343 char buf0[RSN_IE_BODY_MAX * 2 + 30];
1344 char buf1[RSN_IE_BODY_MAX * 2 + 30];
1346 /* First entry *MUST* be the AP MAC address */
1347 iwe.cmd = SIOCGIWAP;
1348 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1349 memcpy(iwe.u.ap_addr.sa_data, ap->bssid, ETH_ALEN);
1351 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1354 /* Other entries will be displayed in the order we give them */
1357 iwe.u.data.length = ap->ssid.size;
1358 if (iwe.u.data.length > 32)
1359 iwe.u.data.length = 32;
1360 iwe.cmd = SIOCGIWESSID;
1361 iwe.u.data.flags = 1;
1363 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1367 iwe.cmd = SIOCGIWMODE;
1368 capabilities = ap->capability;
1369 if (capabilities & (BSS_CAP_ESS | BSS_CAP_IBSS)) {
1370 if (capabilities & BSS_CAP_ESS)
1371 iwe.u.mode = IW_MODE_INFRA;
1373 iwe.u.mode = IW_MODE_ADHOC;
1375 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1380 iwe.cmd = SIOCGIWFREQ;
1381 iwe.u.freq.m = ap->channel;
1382 iwe.u.freq.m = frequency_list[iwe.u.freq.m - 1] * 100000;
1385 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1388 /* Add quality statistics */
1390 iwe.u.qual.level = 256 - ap->rssi;
1391 iwe.u.qual.qual = ap->sq;
1392 iwe.u.qual.noise = 0; /* invalid noise value */
1394 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1397 /* Add encryption capability */
1398 iwe.cmd = SIOCGIWENCODE;
1399 if (capabilities & BSS_CAP_PRIVACY)
1400 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1402 iwe.u.data.flags = IW_ENCODE_DISABLED;
1403 iwe.u.data.length = 0;
1405 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1408 /* Rate : stuffing multiple values in a single event require a bit
1409 * more of magic - Jean II
1411 current_val = current_ev + IW_EV_LCP_LEN;
1413 iwe.cmd = SIOCGIWRATE;
1415 /* These two flags are ignored... */
1416 iwe.u.bitrate.fixed = 0;
1417 iwe.u.bitrate.disabled = 0;
1420 for (i = 0; i < 16; i++) {
1421 /* NULL terminated */
1422 if (i >= ap->rate_set.size)
1424 /* Bit rate given in 500 kb/s units (+ 0x80) */
1425 iwe.u.bitrate.value = ((ap->rate_set.body[i] & 0x7f) * 500000);
1426 /* Add new value to event */
1428 iwe_stream_add_value(info, current_ev, current_val, end_buf,
1429 &iwe, IW_EV_PARAM_LEN);
1431 /* Check if we added any event */
1432 if ((current_val - current_ev) > IW_EV_LCP_LEN)
1433 current_ev = current_val;
1435 #define GENERIC_INFO_ELEM_ID 0xdd
1436 #define RSN_INFO_ELEM_ID 0x30
1437 if (ap->rsn_ie.id == RSN_INFO_ELEM_ID && ap->rsn_ie.size != 0) {
1439 memset(&iwe, 0, sizeof(iwe));
1440 iwe.cmd = IWEVCUSTOM;
1441 memcpy(buf0, rsn_leader, sizeof(rsn_leader) - 1);
1442 iwe.u.data.length += sizeof(rsn_leader) - 1;
1443 pbuf += sizeof(rsn_leader) - 1;
1445 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.id);
1446 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.size);
1447 iwe.u.data.length += 4;
1449 for (i = 0; i < ap->rsn_ie.size; i++)
1450 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.body[i]);
1451 iwe.u.data.length += (ap->rsn_ie.size) * 2;
1453 DPRINTK(4, "ap->rsn.size=%d\n", ap->rsn_ie.size);
1456 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1459 if (ap->wpa_ie.id == GENERIC_INFO_ELEM_ID && ap->wpa_ie.size != 0) {
1461 memset(&iwe, 0, sizeof(iwe));
1462 iwe.cmd = IWEVCUSTOM;
1463 memcpy(buf1, wpa_leader, sizeof(wpa_leader) - 1);
1464 iwe.u.data.length += sizeof(wpa_leader) - 1;
1465 pbuf += sizeof(wpa_leader) - 1;
1467 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.id);
1468 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.size);
1469 iwe.u.data.length += 4;
1471 for (i = 0; i < ap->wpa_ie.size; i++)
1472 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.body[i]);
1473 iwe.u.data.length += (ap->wpa_ie.size) * 2;
1475 DPRINTK(4, "ap->rsn.size=%d\n", ap->wpa_ie.size);
1476 DPRINTK(4, "iwe.u.data.length=%d\n", iwe.u.data.length);
1479 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1483 /* The other data in the scan result are not really
1484 * interesting, so for now drop it - Jean II
1489 static int ks_wlan_get_scan(struct net_device *dev,
1490 struct iw_request_info *info, struct iw_point *dwrq,
1493 struct ks_wlan_private *priv = netdev_priv(dev);
1495 char *current_ev = extra;
1499 if (priv->sleep_mode == SLP_SLEEP)
1501 /* for SLEEP MODE */
1502 if (priv->sme_i.sme_flag & SME_AP_SCAN) {
1503 DPRINTK(2, "flag AP_SCAN\n");
1507 if (priv->aplist.size == 0) {
1508 /* Client error, no scan results...
1509 * The caller need to restart the scan.
1511 DPRINTK(2, "aplist 0\n");
1515 /* Read and parse all entries */
1516 for (i = 0; i < priv->aplist.size; i++) {
1517 if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) {
1521 /* Translate to WE format this entry */
1522 current_ev = ks_wlan_translate_scan(dev, info, current_ev,
1523 extra + dwrq->length,
1524 &priv->aplist.ap[i]);
1526 /* Length of data */
1527 dwrq->length = (current_ev - extra);
1533 /* called after a bunch of SET operations */
1534 static int ks_wlan_config_commit(struct net_device *dev,
1535 struct iw_request_info *info, void *zwrq,
1538 struct ks_wlan_private *priv = netdev_priv(dev);
1540 if (!priv->need_commit)
1543 ks_wlan_setup_parameter(priv, priv->need_commit);
1544 priv->need_commit = 0;
1548 /* set association ie params */
1549 static int ks_wlan_set_genie(struct net_device *dev,
1550 struct iw_request_info *info,
1551 struct iw_point *dwrq, char *extra)
1553 struct ks_wlan_private *priv = netdev_priv(dev);
1557 if (priv->sleep_mode == SLP_SLEEP)
1559 /* for SLEEP MODE */
1561 // return -EOPNOTSUPP;
1564 static int ks_wlan_set_auth_mode(struct net_device *dev,
1565 struct iw_request_info *info,
1566 struct iw_param *vwrq, char *extra)
1568 struct ks_wlan_private *priv = netdev_priv(dev);
1569 int index = (vwrq->flags & IW_AUTH_INDEX);
1570 int value = vwrq->value;
1572 DPRINTK(2, "index=%d:value=%08X\n", index, value);
1574 if (priv->sleep_mode == SLP_SLEEP)
1576 /* for SLEEP MODE */
1578 case IW_AUTH_WPA_VERSION: /* 0 */
1580 case IW_AUTH_WPA_VERSION_DISABLED:
1581 priv->wpa.version = value;
1582 if (priv->wpa.rsn_enabled)
1583 priv->wpa.rsn_enabled = 0;
1584 priv->need_commit |= SME_RSN;
1586 case IW_AUTH_WPA_VERSION_WPA:
1587 case IW_AUTH_WPA_VERSION_WPA2:
1588 priv->wpa.version = value;
1589 if (!(priv->wpa.rsn_enabled))
1590 priv->wpa.rsn_enabled = 1;
1591 priv->need_commit |= SME_RSN;
1597 case IW_AUTH_CIPHER_PAIRWISE: /* 1 */
1599 case IW_AUTH_CIPHER_NONE:
1600 if (priv->reg.privacy_invoked) {
1601 priv->reg.privacy_invoked = 0x00;
1602 priv->need_commit |= SME_WEP_FLAG;
1605 case IW_AUTH_CIPHER_WEP40:
1606 case IW_AUTH_CIPHER_TKIP:
1607 case IW_AUTH_CIPHER_CCMP:
1608 case IW_AUTH_CIPHER_WEP104:
1609 if (!priv->reg.privacy_invoked) {
1610 priv->reg.privacy_invoked = 0x01;
1611 priv->need_commit |= SME_WEP_FLAG;
1613 priv->wpa.pairwise_suite = value;
1614 priv->need_commit |= SME_RSN_UNICAST;
1620 case IW_AUTH_CIPHER_GROUP: /* 2 */
1622 case IW_AUTH_CIPHER_NONE:
1623 if (priv->reg.privacy_invoked) {
1624 priv->reg.privacy_invoked = 0x00;
1625 priv->need_commit |= SME_WEP_FLAG;
1628 case IW_AUTH_CIPHER_WEP40:
1629 case IW_AUTH_CIPHER_TKIP:
1630 case IW_AUTH_CIPHER_CCMP:
1631 case IW_AUTH_CIPHER_WEP104:
1632 if (!priv->reg.privacy_invoked) {
1633 priv->reg.privacy_invoked = 0x01;
1634 priv->need_commit |= SME_WEP_FLAG;
1636 priv->wpa.group_suite = value;
1637 priv->need_commit |= SME_RSN_MULTICAST;
1643 case IW_AUTH_KEY_MGMT: /* 3 */
1645 case IW_AUTH_KEY_MGMT_802_1X:
1646 case IW_AUTH_KEY_MGMT_PSK:
1647 case 0: /* NONE or 802_1X_NO_WPA */
1648 case 4: /* WPA_NONE */
1649 priv->wpa.key_mgmt_suite = value;
1650 priv->need_commit |= SME_RSN_AUTH;
1656 case IW_AUTH_80211_AUTH_ALG: /* 6 */
1658 case IW_AUTH_ALG_OPEN_SYSTEM:
1659 priv->wpa.auth_alg = value;
1660 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
1662 case IW_AUTH_ALG_SHARED_KEY:
1663 priv->wpa.auth_alg = value;
1664 priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
1666 case IW_AUTH_ALG_LEAP:
1670 priv->need_commit |= SME_MODE_SET;
1672 case IW_AUTH_WPA_ENABLED: /* 7 */
1673 priv->wpa.wpa_enabled = value;
1675 case IW_AUTH_PRIVACY_INVOKED: /* 10 */
1676 if ((value && !priv->reg.privacy_invoked) ||
1677 (!value && priv->reg.privacy_invoked)) {
1678 priv->reg.privacy_invoked = value ? 0x01 : 0x00;
1679 priv->need_commit |= SME_WEP_FLAG;
1682 case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* 4 */
1683 case IW_AUTH_TKIP_COUNTERMEASURES: /* 5 */
1684 case IW_AUTH_DROP_UNENCRYPTED: /* 8 */
1685 case IW_AUTH_ROAMING_CONTROL: /* 9 */
1690 /* return -EINPROGRESS; */
1691 if (priv->need_commit) {
1692 ks_wlan_setup_parameter(priv, priv->need_commit);
1693 priv->need_commit = 0;
1698 static int ks_wlan_get_auth_mode(struct net_device *dev,
1699 struct iw_request_info *info,
1700 struct iw_param *vwrq, char *extra)
1702 struct ks_wlan_private *priv = netdev_priv(dev);
1703 int index = (vwrq->flags & IW_AUTH_INDEX);
1705 DPRINTK(2, "index=%d\n", index);
1707 if (priv->sleep_mode == SLP_SLEEP)
1710 /* for SLEEP MODE */
1711 /* WPA (not used ?? wpa_supplicant) */
1713 case IW_AUTH_WPA_VERSION:
1714 vwrq->value = priv->wpa.version;
1716 case IW_AUTH_CIPHER_PAIRWISE:
1717 vwrq->value = priv->wpa.pairwise_suite;
1719 case IW_AUTH_CIPHER_GROUP:
1720 vwrq->value = priv->wpa.group_suite;
1722 case IW_AUTH_KEY_MGMT:
1723 vwrq->value = priv->wpa.key_mgmt_suite;
1725 case IW_AUTH_80211_AUTH_ALG:
1726 vwrq->value = priv->wpa.auth_alg;
1728 case IW_AUTH_WPA_ENABLED:
1729 vwrq->value = priv->wpa.rsn_enabled;
1731 case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* OK??? */
1732 case IW_AUTH_TKIP_COUNTERMEASURES:
1733 case IW_AUTH_DROP_UNENCRYPTED:
1735 /* return -EOPNOTSUPP; */
1741 /* set encoding token & mode (WPA)*/
1742 static int ks_wlan_set_encode_ext(struct net_device *dev,
1743 struct iw_request_info *info,
1744 struct iw_point *dwrq, char *extra)
1746 struct ks_wlan_private *priv = netdev_priv(dev);
1747 struct iw_encode_ext *enc;
1748 int index = dwrq->flags & IW_ENCODE_INDEX;
1749 unsigned int commit = 0;
1750 struct wpa_key_t *key;
1752 enc = (struct iw_encode_ext *)extra;
1756 DPRINTK(2, "flags=%04X:: ext_flags=%08X\n", dwrq->flags,
1759 if (priv->sleep_mode == SLP_SLEEP)
1762 /* for SLEEP MODE */
1763 if (index < 1 || index > 4)
1766 key = &priv->wpa.key[index];
1768 if (dwrq->flags & IW_ENCODE_DISABLED)
1771 key->ext_flags = enc->ext_flags;
1772 if (enc->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
1773 priv->wpa.txkey = index;
1774 commit |= SME_WEP_INDEX;
1775 } else if (enc->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
1776 memcpy(&key->rx_seq[0], &enc->rx_seq[0], IW_ENCODE_SEQ_MAX_SIZE);
1779 memcpy(&key->addr.sa_data[0], &enc->addr.sa_data[0], ETH_ALEN);
1782 case IW_ENCODE_ALG_NONE:
1783 if (priv->reg.privacy_invoked) {
1784 priv->reg.privacy_invoked = 0x00;
1785 commit |= SME_WEP_FLAG;
1790 case IW_ENCODE_ALG_WEP:
1791 case IW_ENCODE_ALG_CCMP:
1792 if (!priv->reg.privacy_invoked) {
1793 priv->reg.privacy_invoked = 0x01;
1794 commit |= SME_WEP_FLAG;
1797 memcpy(&key->key_val[0], &enc->key[0], enc->key_len);
1798 key->key_len = enc->key_len;
1799 commit |= (SME_WEP_VAL1 << index);
1802 case IW_ENCODE_ALG_TKIP:
1803 if (!priv->reg.privacy_invoked) {
1804 priv->reg.privacy_invoked = 0x01;
1805 commit |= SME_WEP_FLAG;
1807 if (enc->key_len == 32) {
1808 memcpy(&key->key_val[0], &enc->key[0], enc->key_len - 16);
1809 key->key_len = enc->key_len - 16;
1810 if (priv->wpa.key_mgmt_suite == 4) { /* WPA_NONE */
1811 memcpy(&key->tx_mic_key[0], &enc->key[16], 8);
1812 memcpy(&key->rx_mic_key[0], &enc->key[16], 8);
1814 memcpy(&key->tx_mic_key[0], &enc->key[16], 8);
1815 memcpy(&key->rx_mic_key[0], &enc->key[24], 8);
1817 commit |= (SME_WEP_VAL1 << index);
1823 key->alg = enc->alg;
1826 if (commit & SME_WEP_INDEX)
1827 hostif_sme_enqueue(priv, SME_SET_TXKEY);
1828 if (commit & SME_WEP_VAL_MASK)
1829 hostif_sme_enqueue(priv, SME_SET_KEY1 + index);
1830 if (commit & SME_WEP_FLAG)
1831 hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
1837 /* get encoding token & mode (WPA)*/
1838 static int ks_wlan_get_encode_ext(struct net_device *dev,
1839 struct iw_request_info *info,
1840 struct iw_point *dwrq, char *extra)
1842 struct ks_wlan_private *priv = netdev_priv(dev);
1844 if (priv->sleep_mode == SLP_SLEEP)
1847 /* for SLEEP MODE */
1848 /* WPA (not used ?? wpa_supplicant)
1849 * struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
1850 * struct iw_encode_ext *enc;
1851 * enc = (struct iw_encode_ext *)extra;
1852 * int index = dwrq->flags & IW_ENCODE_INDEX;
1853 * WPA (not used ?? wpa_supplicant)
1858 static int ks_wlan_set_pmksa(struct net_device *dev,
1859 struct iw_request_info *info,
1860 struct iw_point *dwrq, char *extra)
1862 struct ks_wlan_private *priv = netdev_priv(dev);
1863 struct iw_pmksa *pmksa;
1866 struct list_head *ptr;
1870 if (priv->sleep_mode == SLP_SLEEP)
1873 /* for SLEEP MODE */
1877 pmksa = (struct iw_pmksa *)extra;
1878 DPRINTK(2, "cmd=%d\n", pmksa->cmd);
1880 switch (pmksa->cmd) {
1882 if (list_empty(&priv->pmklist.head)) { /* new list */
1883 for (i = 0; i < PMK_LIST_MAX; i++) {
1884 pmk = &priv->pmklist.pmk[i];
1885 if (memcmp("\x00\x00\x00\x00\x00\x00",
1886 pmk->bssid, ETH_ALEN) == 0)
1889 memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
1890 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1891 list_add(&pmk->list, &priv->pmklist.head);
1892 priv->pmklist.size++;
1895 /* search cache data */
1896 list_for_each(ptr, &priv->pmklist.head) {
1897 pmk = list_entry(ptr, struct pmk_t, list);
1898 if (memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN) == 0) {
1899 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1900 list_move(&pmk->list, &priv->pmklist.head);
1901 break; /* list_for_each */
1904 if (ptr != &priv->pmklist.head) /* not find address. */
1907 if (priv->pmklist.size < PMK_LIST_MAX) { /* new cache data */
1908 for (i = 0; i < PMK_LIST_MAX; i++) {
1909 pmk = &priv->pmklist.pmk[i];
1910 if (memcmp("\x00\x00\x00\x00\x00\x00",
1911 pmk->bssid, ETH_ALEN) == 0)
1914 memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
1915 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1916 list_add(&pmk->list, &priv->pmklist.head);
1917 priv->pmklist.size++;
1918 } else { /* overwrite old cache data */
1919 pmk = list_entry(priv->pmklist.head.prev, struct pmk_t,
1921 memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
1922 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1923 list_move(&pmk->list, &priv->pmklist.head);
1926 case IW_PMKSA_REMOVE:
1927 if (list_empty(&priv->pmklist.head)) { /* list empty */
1930 /* search cache data */
1931 list_for_each(ptr, &priv->pmklist.head) {
1932 pmk = list_entry(ptr, struct pmk_t, list);
1933 if (memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN) == 0) {
1934 eth_zero_addr(pmk->bssid);
1935 memset(pmk->pmkid, 0, IW_PMKID_LEN);
1936 list_del_init(&pmk->list);
1940 if (ptr == &priv->pmklist.head) { /* not find address. */
1945 case IW_PMKSA_FLUSH:
1946 memset(&priv->pmklist, 0, sizeof(priv->pmklist));
1947 INIT_LIST_HEAD(&priv->pmklist.head);
1948 for (i = 0; i < PMK_LIST_MAX; i++)
1949 INIT_LIST_HEAD(&priv->pmklist.pmk[i].list);
1955 hostif_sme_enqueue(priv, SME_SET_PMKSA);
1959 static struct iw_statistics *ks_get_wireless_stats(struct net_device *dev)
1961 struct ks_wlan_private *priv = netdev_priv(dev);
1962 struct iw_statistics *wstats = &priv->wstats;
1964 if (!atomic_read(&update_phyinfo)) {
1965 if (priv->dev_state < DEVICE_STATE_READY)
1966 return NULL; /* not finished initialize */
1971 /* Packets discarded in the wireless adapter due to wireless
1974 wstats->discard.nwid = 0; /* Rx invalid nwid */
1975 wstats->discard.code = 0; /* Rx invalid crypt */
1976 wstats->discard.fragment = 0; /* Rx invalid frag */
1977 wstats->discard.retries = 0; /* Tx excessive retries */
1978 wstats->discard.misc = 0; /* Invalid misc */
1979 wstats->miss.beacon = 0; /* Missed beacon */
1984 static int ks_wlan_set_stop_request(struct net_device *dev,
1985 struct iw_request_info *info, __u32 *uwrq,
1988 struct ks_wlan_private *priv = netdev_priv(dev);
1992 if (priv->sleep_mode == SLP_SLEEP)
1995 /* for SLEEP MODE */
1999 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2003 #include <linux/ieee80211.h>
2004 static int ks_wlan_set_mlme(struct net_device *dev,
2005 struct iw_request_info *info, struct iw_point *dwrq,
2008 struct ks_wlan_private *priv = netdev_priv(dev);
2009 struct iw_mlme *mlme = (struct iw_mlme *)extra;
2012 DPRINTK(2, ":%d :%d\n", mlme->cmd, mlme->reason_code);
2014 if (priv->sleep_mode == SLP_SLEEP)
2017 /* for SLEEP MODE */
2018 switch (mlme->cmd) {
2019 case IW_MLME_DEAUTH:
2020 if (mlme->reason_code == WLAN_REASON_MIC_FAILURE)
2023 case IW_MLME_DISASSOC:
2025 return ks_wlan_set_stop_request(dev, NULL, &mode, NULL);
2027 return -EOPNOTSUPP; /* Not Support */
2031 static int ks_wlan_get_firmware_version(struct net_device *dev,
2032 struct iw_request_info *info,
2033 struct iw_point *dwrq, char *extra)
2035 struct ks_wlan_private *priv = netdev_priv(dev);
2037 strcpy(extra, priv->firmware_version);
2038 dwrq->length = priv->version_size + 1;
2042 static int ks_wlan_set_preamble(struct net_device *dev,
2043 struct iw_request_info *info, __u32 *uwrq,
2046 struct ks_wlan_private *priv = netdev_priv(dev);
2048 if (priv->sleep_mode == SLP_SLEEP)
2051 /* for SLEEP MODE */
2052 if (*uwrq == LONG_PREAMBLE) { /* 0 */
2053 priv->reg.preamble = LONG_PREAMBLE;
2054 } else if (*uwrq == SHORT_PREAMBLE) { /* 1 */
2055 priv->reg.preamble = SHORT_PREAMBLE;
2060 priv->need_commit |= SME_MODE_SET;
2061 return -EINPROGRESS; /* Call commit handler */
2064 static int ks_wlan_get_preamble(struct net_device *dev,
2065 struct iw_request_info *info, __u32 *uwrq,
2068 struct ks_wlan_private *priv = netdev_priv(dev);
2070 if (priv->sleep_mode == SLP_SLEEP)
2073 /* for SLEEP MODE */
2074 *uwrq = priv->reg.preamble;
2078 static int ks_wlan_set_power_mgmt(struct net_device *dev,
2079 struct iw_request_info *info, __u32 *uwrq,
2082 struct ks_wlan_private *priv = netdev_priv(dev);
2084 if (priv->sleep_mode == SLP_SLEEP)
2087 /* for SLEEP MODE */
2088 if (*uwrq == POWER_MGMT_ACTIVE) { /* 0 */
2089 priv->reg.power_mgmt = POWER_MGMT_ACTIVE;
2090 } else if (*uwrq == POWER_MGMT_SAVE1) { /* 1 */
2091 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2092 priv->reg.power_mgmt = POWER_MGMT_SAVE1;
2095 } else if (*uwrq == POWER_MGMT_SAVE2) { /* 2 */
2096 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2097 priv->reg.power_mgmt = POWER_MGMT_SAVE2;
2104 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
2109 static int ks_wlan_get_power_mgmt(struct net_device *dev,
2110 struct iw_request_info *info, __u32 *uwrq,
2113 struct ks_wlan_private *priv = netdev_priv(dev);
2115 if (priv->sleep_mode == SLP_SLEEP)
2118 /* for SLEEP MODE */
2119 *uwrq = priv->reg.power_mgmt;
2123 static int ks_wlan_set_scan_type(struct net_device *dev,
2124 struct iw_request_info *info, __u32 *uwrq,
2127 struct ks_wlan_private *priv = netdev_priv(dev);
2129 if (priv->sleep_mode == SLP_SLEEP)
2131 /* for SLEEP MODE */
2132 if (*uwrq == ACTIVE_SCAN) { /* 0 */
2133 priv->reg.scan_type = ACTIVE_SCAN;
2134 } else if (*uwrq == PASSIVE_SCAN) { /* 1 */
2135 priv->reg.scan_type = PASSIVE_SCAN;
2143 static int ks_wlan_get_scan_type(struct net_device *dev,
2144 struct iw_request_info *info, __u32 *uwrq,
2147 struct ks_wlan_private *priv = netdev_priv(dev);
2149 if (priv->sleep_mode == SLP_SLEEP)
2151 /* for SLEEP MODE */
2152 *uwrq = priv->reg.scan_type;
2156 static int ks_wlan_set_beacon_lost(struct net_device *dev,
2157 struct iw_request_info *info, __u32 *uwrq,
2160 struct ks_wlan_private *priv = netdev_priv(dev);
2162 if (priv->sleep_mode == SLP_SLEEP)
2164 /* for SLEEP MODE */
2165 if (*uwrq >= BEACON_LOST_COUNT_MIN && *uwrq <= BEACON_LOST_COUNT_MAX)
2166 priv->reg.beacon_lost_count = *uwrq;
2170 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
2171 priv->need_commit |= SME_MODE_SET;
2172 return -EINPROGRESS; /* Call commit handler */
2178 static int ks_wlan_get_beacon_lost(struct net_device *dev,
2179 struct iw_request_info *info, __u32 *uwrq,
2182 struct ks_wlan_private *priv = netdev_priv(dev);
2184 if (priv->sleep_mode == SLP_SLEEP)
2186 /* for SLEEP MODE */
2187 *uwrq = priv->reg.beacon_lost_count;
2191 static int ks_wlan_set_phy_type(struct net_device *dev,
2192 struct iw_request_info *info, __u32 *uwrq,
2195 struct ks_wlan_private *priv = netdev_priv(dev);
2197 if (priv->sleep_mode == SLP_SLEEP)
2199 /* for SLEEP MODE */
2200 if (*uwrq == D_11B_ONLY_MODE) { /* 0 */
2201 priv->reg.phy_type = D_11B_ONLY_MODE;
2202 } else if (*uwrq == D_11G_ONLY_MODE) { /* 1 */
2203 priv->reg.phy_type = D_11G_ONLY_MODE;
2204 } else if (*uwrq == D_11BG_COMPATIBLE_MODE) { /* 2 */
2205 priv->reg.phy_type = D_11BG_COMPATIBLE_MODE;
2210 priv->need_commit |= SME_MODE_SET;
2211 return -EINPROGRESS; /* Call commit handler */
2214 static int ks_wlan_get_phy_type(struct net_device *dev,
2215 struct iw_request_info *info, __u32 *uwrq,
2218 struct ks_wlan_private *priv = netdev_priv(dev);
2220 if (priv->sleep_mode == SLP_SLEEP)
2222 /* for SLEEP MODE */
2223 *uwrq = priv->reg.phy_type;
2227 static int ks_wlan_set_cts_mode(struct net_device *dev,
2228 struct iw_request_info *info, __u32 *uwrq,
2231 struct ks_wlan_private *priv = netdev_priv(dev);
2233 if (priv->sleep_mode == SLP_SLEEP)
2235 /* for SLEEP MODE */
2236 if (*uwrq == CTS_MODE_FALSE) { /* 0 */
2237 priv->reg.cts_mode = CTS_MODE_FALSE;
2238 } else if (*uwrq == CTS_MODE_TRUE) { /* 1 */
2239 if (priv->reg.phy_type == D_11G_ONLY_MODE ||
2240 priv->reg.phy_type == D_11BG_COMPATIBLE_MODE) {
2241 priv->reg.cts_mode = CTS_MODE_TRUE;
2243 priv->reg.cts_mode = CTS_MODE_FALSE;
2249 priv->need_commit |= SME_MODE_SET;
2250 return -EINPROGRESS; /* Call commit handler */
2253 static int ks_wlan_get_cts_mode(struct net_device *dev,
2254 struct iw_request_info *info, __u32 *uwrq,
2257 struct ks_wlan_private *priv = netdev_priv(dev);
2259 if (priv->sleep_mode == SLP_SLEEP)
2261 /* for SLEEP MODE */
2262 *uwrq = priv->reg.cts_mode;
2266 static int ks_wlan_set_sleep_mode(struct net_device *dev,
2267 struct iw_request_info *info,
2268 __u32 *uwrq, char *extra)
2270 struct ks_wlan_private *priv = netdev_priv(dev);
2274 if (*uwrq == SLP_SLEEP) {
2275 priv->sleep_mode = *uwrq;
2276 netdev_info(dev, "SET_SLEEP_MODE %d\n", priv->sleep_mode);
2278 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2279 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2281 } else if (*uwrq == SLP_ACTIVE) {
2282 priv->sleep_mode = *uwrq;
2283 netdev_info(dev, "SET_SLEEP_MODE %d\n", priv->sleep_mode);
2284 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2286 netdev_err(dev, "SET_SLEEP_MODE %d error\n", *uwrq);
2293 static int ks_wlan_get_sleep_mode(struct net_device *dev,
2294 struct iw_request_info *info,
2295 __u32 *uwrq, char *extra)
2297 struct ks_wlan_private *priv = netdev_priv(dev);
2299 DPRINTK(2, "GET_SLEEP_MODE %d\n", priv->sleep_mode);
2300 *uwrq = priv->sleep_mode;
2307 static int ks_wlan_set_wps_enable(struct net_device *dev,
2308 struct iw_request_info *info, __u32 *uwrq,
2311 struct ks_wlan_private *priv = netdev_priv(dev);
2315 if (priv->sleep_mode == SLP_SLEEP)
2317 /* for SLEEP MODE */
2318 if (*uwrq == 0 || *uwrq == 1)
2319 priv->wps.wps_enabled = *uwrq;
2323 hostif_sme_enqueue(priv, SME_WPS_ENABLE_REQUEST);
2328 static int ks_wlan_get_wps_enable(struct net_device *dev,
2329 struct iw_request_info *info, __u32 *uwrq,
2332 struct ks_wlan_private *priv = netdev_priv(dev);
2336 if (priv->sleep_mode == SLP_SLEEP)
2338 /* for SLEEP MODE */
2339 *uwrq = priv->wps.wps_enabled;
2340 netdev_info(dev, "return=%d\n", *uwrq);
2345 static int ks_wlan_set_wps_probe_req(struct net_device *dev,
2346 struct iw_request_info *info,
2347 struct iw_point *dwrq, char *extra)
2351 struct ks_wlan_private *priv = netdev_priv(dev);
2355 if (priv->sleep_mode == SLP_SLEEP)
2357 /* for SLEEP MODE */
2358 DPRINTK(2, "dwrq->length=%d\n", dwrq->length);
2361 if (p[1] + 2 != dwrq->length || dwrq->length > 256)
2364 priv->wps.ielen = p[1] + 2 + 1; /* IE header + IE + sizeof(len) */
2365 len = p[1] + 2; /* IE header + IE */
2367 memcpy(priv->wps.ie, &len, sizeof(len));
2368 p = memcpy(priv->wps.ie + 1, p, len);
2370 DPRINTK(2, "%d(%#x): %02X %02X %02X %02X ... %02X %02X %02X\n",
2371 priv->wps.ielen, priv->wps.ielen, p[0], p[1], p[2], p[3],
2372 p[priv->wps.ielen - 3], p[priv->wps.ielen - 2],
2373 p[priv->wps.ielen - 1]);
2375 hostif_sme_enqueue(priv, SME_WPS_PROBE_REQUEST);
2381 static int ks_wlan_set_tx_gain(struct net_device *dev,
2382 struct iw_request_info *info, __u32 *uwrq,
2385 struct ks_wlan_private *priv = netdev_priv(dev);
2387 if (priv->sleep_mode == SLP_SLEEP)
2389 /* for SLEEP MODE */
2390 if (*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2391 priv->gain.tx_gain = (uint8_t)*uwrq;
2395 if (priv->gain.tx_gain < 0xFF)
2396 priv->gain.tx_mode = 1;
2398 priv->gain.tx_mode = 0;
2400 hostif_sme_enqueue(priv, SME_SET_GAIN);
2404 static int ks_wlan_get_tx_gain(struct net_device *dev,
2405 struct iw_request_info *info, __u32 *uwrq,
2408 struct ks_wlan_private *priv = netdev_priv(dev);
2410 if (priv->sleep_mode == SLP_SLEEP)
2412 /* for SLEEP MODE */
2413 *uwrq = priv->gain.tx_gain;
2414 hostif_sme_enqueue(priv, SME_GET_GAIN);
2418 static int ks_wlan_set_rx_gain(struct net_device *dev,
2419 struct iw_request_info *info, __u32 *uwrq,
2422 struct ks_wlan_private *priv = netdev_priv(dev);
2424 if (priv->sleep_mode == SLP_SLEEP)
2426 /* for SLEEP MODE */
2427 if (*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2428 priv->gain.rx_gain = (uint8_t)*uwrq;
2432 if (priv->gain.rx_gain < 0xFF)
2433 priv->gain.rx_mode = 1;
2435 priv->gain.rx_mode = 0;
2437 hostif_sme_enqueue(priv, SME_SET_GAIN);
2441 static int ks_wlan_get_rx_gain(struct net_device *dev,
2442 struct iw_request_info *info, __u32 *uwrq,
2445 struct ks_wlan_private *priv = netdev_priv(dev);
2447 if (priv->sleep_mode == SLP_SLEEP)
2449 /* for SLEEP MODE */
2450 *uwrq = priv->gain.rx_gain;
2451 hostif_sme_enqueue(priv, SME_GET_GAIN);
2455 static int ks_wlan_get_eeprom_cksum(struct net_device *dev,
2456 struct iw_request_info *info, __u32 *uwrq,
2459 struct ks_wlan_private *priv = netdev_priv(dev);
2461 *uwrq = priv->eeprom_checksum;
2465 static void print_hif_event(struct net_device *dev, int event)
2469 netdev_info(dev, "HIF_DATA_REQ\n");
2472 netdev_info(dev, "HIF_DATA_IND\n");
2474 case HIF_MIB_GET_REQ:
2475 netdev_info(dev, "HIF_MIB_GET_REQ\n");
2477 case HIF_MIB_GET_CONF:
2478 netdev_info(dev, "HIF_MIB_GET_CONF\n");
2480 case HIF_MIB_SET_REQ:
2481 netdev_info(dev, "HIF_MIB_SET_REQ\n");
2483 case HIF_MIB_SET_CONF:
2484 netdev_info(dev, "HIF_MIB_SET_CONF\n");
2486 case HIF_POWER_MGMT_REQ:
2487 netdev_info(dev, "HIF_POWER_MGMT_REQ\n");
2489 case HIF_POWER_MGMT_CONF:
2490 netdev_info(dev, "HIF_POWER_MGMT_CONF\n");
2493 netdev_info(dev, "HIF_START_REQ\n");
2495 case HIF_START_CONF:
2496 netdev_info(dev, "HIF_START_CONF\n");
2498 case HIF_CONNECT_IND:
2499 netdev_info(dev, "HIF_CONNECT_IND\n");
2502 netdev_info(dev, "HIF_STOP_REQ\n");
2505 netdev_info(dev, "HIF_STOP_CONF\n");
2507 case HIF_PS_ADH_SET_REQ:
2508 netdev_info(dev, "HIF_PS_ADH_SET_REQ\n");
2510 case HIF_PS_ADH_SET_CONF:
2511 netdev_info(dev, "HIF_PS_ADH_SET_CONF\n");
2513 case HIF_INFRA_SET_REQ:
2514 netdev_info(dev, "HIF_INFRA_SET_REQ\n");
2516 case HIF_INFRA_SET_CONF:
2517 netdev_info(dev, "HIF_INFRA_SET_CONF\n");
2519 case HIF_ADH_SET_REQ:
2520 netdev_info(dev, "HIF_ADH_SET_REQ\n");
2522 case HIF_ADH_SET_CONF:
2523 netdev_info(dev, "HIF_ADH_SET_CONF\n");
2525 case HIF_AP_SET_REQ:
2526 netdev_info(dev, "HIF_AP_SET_REQ\n");
2528 case HIF_AP_SET_CONF:
2529 netdev_info(dev, "HIF_AP_SET_CONF\n");
2531 case HIF_ASSOC_INFO_IND:
2532 netdev_info(dev, "HIF_ASSOC_INFO_IND\n");
2534 case HIF_MIC_FAILURE_REQ:
2535 netdev_info(dev, "HIF_MIC_FAILURE_REQ\n");
2537 case HIF_MIC_FAILURE_CONF:
2538 netdev_info(dev, "HIF_MIC_FAILURE_CONF\n");
2541 netdev_info(dev, "HIF_SCAN_REQ\n");
2544 netdev_info(dev, "HIF_SCAN_CONF\n");
2546 case HIF_PHY_INFO_REQ:
2547 netdev_info(dev, "HIF_PHY_INFO_REQ\n");
2549 case HIF_PHY_INFO_CONF:
2550 netdev_info(dev, "HIF_PHY_INFO_CONF\n");
2553 netdev_info(dev, "HIF_SLEEP_REQ\n");
2555 case HIF_SLEEP_CONF:
2556 netdev_info(dev, "HIF_SLEEP_CONF\n");
2558 case HIF_PHY_INFO_IND:
2559 netdev_info(dev, "HIF_PHY_INFO_IND\n");
2562 netdev_info(dev, "HIF_SCAN_IND\n");
2564 case HIF_INFRA_SET2_REQ:
2565 netdev_info(dev, "HIF_INFRA_SET2_REQ\n");
2567 case HIF_INFRA_SET2_CONF:
2568 netdev_info(dev, "HIF_INFRA_SET2_CONF\n");
2570 case HIF_ADH_SET2_REQ:
2571 netdev_info(dev, "HIF_ADH_SET2_REQ\n");
2573 case HIF_ADH_SET2_CONF:
2574 netdev_info(dev, "HIF_ADH_SET2_CONF\n");
2578 /* get host command history */
2579 static int ks_wlan_hostt(struct net_device *dev, struct iw_request_info *info,
2580 __u32 *uwrq, char *extra)
2583 struct ks_wlan_private *priv = netdev_priv(dev);
2585 for (i = 63; i >= 0; i--) {
2587 priv->hostt.buff[(priv->hostt.qtail - 1 - i) %
2588 SME_EVENT_BUFF_SIZE];
2589 print_hif_event(dev, event);
2594 /* Structures to export the Wireless Handlers */
2596 static const struct iw_priv_args ks_wlan_private_args[] = {
2597 /*{ cmd, set_args, get_args, name[16] } */
2598 {KS_WLAN_GET_FIRM_VERSION, IW_PRIV_TYPE_NONE,
2599 IW_PRIV_TYPE_CHAR | (128 + 1), "GetFirmwareVer"},
2601 {KS_WLAN_SET_WPS_ENABLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2602 IW_PRIV_TYPE_NONE, "SetWPSEnable"},
2603 {KS_WLAN_GET_WPS_ENABLE, IW_PRIV_TYPE_NONE,
2604 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetW"},
2605 {KS_WLAN_SET_WPS_PROBE_REQ, IW_PRIV_TYPE_BYTE | 2047, IW_PRIV_TYPE_NONE,
2608 {KS_WLAN_SET_PREAMBLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2609 IW_PRIV_TYPE_NONE, "SetPreamble"},
2610 {KS_WLAN_GET_PREAMBLE, IW_PRIV_TYPE_NONE,
2611 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPreamble"},
2612 {KS_WLAN_SET_POWER_SAVE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2613 IW_PRIV_TYPE_NONE, "SetPowerSave"},
2614 {KS_WLAN_GET_POWER_SAVE, IW_PRIV_TYPE_NONE,
2615 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPowerSave"},
2616 {KS_WLAN_SET_SCAN_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2617 IW_PRIV_TYPE_NONE, "SetScanType"},
2618 {KS_WLAN_GET_SCAN_TYPE, IW_PRIV_TYPE_NONE,
2619 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetScanType"},
2620 {KS_WLAN_SET_RX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2621 IW_PRIV_TYPE_NONE, "SetRxGain"},
2622 {KS_WLAN_GET_RX_GAIN, IW_PRIV_TYPE_NONE,
2623 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetRxGain"},
2624 {KS_WLAN_HOSTT, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | (128 + 1),
2626 {KS_WLAN_SET_BEACON_LOST, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2627 IW_PRIV_TYPE_NONE, "SetBeaconLost"},
2628 {KS_WLAN_GET_BEACON_LOST, IW_PRIV_TYPE_NONE,
2629 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetBeaconLost"},
2630 {KS_WLAN_SET_SLEEP_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2631 IW_PRIV_TYPE_NONE, "SetSleepMode"},
2632 {KS_WLAN_GET_SLEEP_MODE, IW_PRIV_TYPE_NONE,
2633 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetSleepMode"},
2634 {KS_WLAN_SET_TX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2635 IW_PRIV_TYPE_NONE, "SetTxGain"},
2636 {KS_WLAN_GET_TX_GAIN, IW_PRIV_TYPE_NONE,
2637 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetTxGain"},
2638 {KS_WLAN_SET_PHY_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2639 IW_PRIV_TYPE_NONE, "SetPhyType"},
2640 {KS_WLAN_GET_PHY_TYPE, IW_PRIV_TYPE_NONE,
2641 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPhyType"},
2642 {KS_WLAN_SET_CTS_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2643 IW_PRIV_TYPE_NONE, "SetCtsMode"},
2644 {KS_WLAN_GET_CTS_MODE, IW_PRIV_TYPE_NONE,
2645 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetCtsMode"},
2646 {KS_WLAN_GET_EEPROM_CKSUM, IW_PRIV_TYPE_NONE,
2647 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetChecksum"},
2650 static const iw_handler ks_wlan_handler[] = {
2651 (iw_handler)ks_wlan_config_commit, /* SIOCSIWCOMMIT */
2652 (iw_handler)ks_wlan_get_name, /* SIOCGIWNAME */
2653 (iw_handler)NULL, /* SIOCSIWNWID */
2654 (iw_handler)NULL, /* SIOCGIWNWID */
2655 (iw_handler)ks_wlan_set_freq, /* SIOCSIWFREQ */
2656 (iw_handler)ks_wlan_get_freq, /* SIOCGIWFREQ */
2657 (iw_handler)ks_wlan_set_mode, /* SIOCSIWMODE */
2658 (iw_handler)ks_wlan_get_mode, /* SIOCGIWMODE */
2659 #ifndef KSC_OPNOTSUPP
2660 (iw_handler)ks_wlan_set_sens, /* SIOCSIWSENS */
2661 (iw_handler)ks_wlan_get_sens, /* SIOCGIWSENS */
2662 #else /* KSC_OPNOTSUPP */
2663 (iw_handler)NULL, /* SIOCSIWSENS */
2664 (iw_handler)NULL, /* SIOCGIWSENS */
2665 #endif /* KSC_OPNOTSUPP */
2666 (iw_handler)NULL, /* SIOCSIWRANGE */
2667 (iw_handler)ks_wlan_get_range, /* SIOCGIWRANGE */
2668 (iw_handler)NULL, /* SIOCSIWPRIV */
2669 (iw_handler)NULL, /* SIOCGIWPRIV */
2670 (iw_handler)NULL, /* SIOCSIWSTATS */
2671 (iw_handler)ks_wlan_get_iwstats, /* SIOCGIWSTATS */
2672 (iw_handler)NULL, /* SIOCSIWSPY */
2673 (iw_handler)NULL, /* SIOCGIWSPY */
2674 (iw_handler)NULL, /* SIOCSIWTHRSPY */
2675 (iw_handler)NULL, /* SIOCGIWTHRSPY */
2676 (iw_handler)ks_wlan_set_wap, /* SIOCSIWAP */
2677 (iw_handler)ks_wlan_get_wap, /* SIOCGIWAP */
2678 // (iw_handler)NULL, /* SIOCSIWMLME */
2679 (iw_handler)ks_wlan_set_mlme, /* SIOCSIWMLME */
2680 (iw_handler)ks_wlan_get_aplist, /* SIOCGIWAPLIST */
2681 (iw_handler)ks_wlan_set_scan, /* SIOCSIWSCAN */
2682 (iw_handler)ks_wlan_get_scan, /* SIOCGIWSCAN */
2683 (iw_handler)ks_wlan_set_essid, /* SIOCSIWESSID */
2684 (iw_handler)ks_wlan_get_essid, /* SIOCGIWESSID */
2685 (iw_handler)ks_wlan_set_nick, /* SIOCSIWNICKN */
2686 (iw_handler)ks_wlan_get_nick, /* SIOCGIWNICKN */
2687 (iw_handler)NULL, /* -- hole -- */
2688 (iw_handler)NULL, /* -- hole -- */
2689 (iw_handler)ks_wlan_set_rate, /* SIOCSIWRATE */
2690 (iw_handler)ks_wlan_get_rate, /* SIOCGIWRATE */
2691 (iw_handler)ks_wlan_set_rts, /* SIOCSIWRTS */
2692 (iw_handler)ks_wlan_get_rts, /* SIOCGIWRTS */
2693 (iw_handler)ks_wlan_set_frag, /* SIOCSIWFRAG */
2694 (iw_handler)ks_wlan_get_frag, /* SIOCGIWFRAG */
2695 #ifndef KSC_OPNOTSUPP
2696 (iw_handler)ks_wlan_set_txpow, /* SIOCSIWTXPOW */
2697 (iw_handler)ks_wlan_get_txpow, /* SIOCGIWTXPOW */
2698 (iw_handler)ks_wlan_set_retry, /* SIOCSIWRETRY */
2699 (iw_handler)ks_wlan_get_retry, /* SIOCGIWRETRY */
2700 #else /* KSC_OPNOTSUPP */
2701 (iw_handler)NULL, /* SIOCSIWTXPOW */
2702 (iw_handler)NULL, /* SIOCGIWTXPOW */
2703 (iw_handler)NULL, /* SIOCSIWRETRY */
2704 (iw_handler)NULL, /* SIOCGIWRETRY */
2705 #endif /* KSC_OPNOTSUPP */
2706 (iw_handler)ks_wlan_set_encode, /* SIOCSIWENCODE */
2707 (iw_handler)ks_wlan_get_encode, /* SIOCGIWENCODE */
2708 (iw_handler)ks_wlan_set_power, /* SIOCSIWPOWER */
2709 (iw_handler)ks_wlan_get_power, /* SIOCGIWPOWER */
2710 (iw_handler)NULL, /* -- hole -- */
2711 (iw_handler)NULL, /* -- hole -- */
2712 // (iw_handler)NULL, /* SIOCSIWGENIE */
2713 (iw_handler)ks_wlan_set_genie, /* SIOCSIWGENIE */
2714 (iw_handler)NULL, /* SIOCGIWGENIE */
2715 (iw_handler)ks_wlan_set_auth_mode, /* SIOCSIWAUTH */
2716 (iw_handler)ks_wlan_get_auth_mode, /* SIOCGIWAUTH */
2717 (iw_handler)ks_wlan_set_encode_ext, /* SIOCSIWENCODEEXT */
2718 (iw_handler)ks_wlan_get_encode_ext, /* SIOCGIWENCODEEXT */
2719 (iw_handler)ks_wlan_set_pmksa, /* SIOCSIWPMKSA */
2720 (iw_handler)NULL, /* -- hole -- */
2723 /* private_handler */
2724 static const iw_handler ks_wlan_private_handler[] = {
2725 (iw_handler)NULL, /* 0 */
2726 (iw_handler)NULL, /* 1, used to be: KS_WLAN_GET_DRIVER_VERSION */
2727 (iw_handler)NULL, /* 2 */
2728 (iw_handler)ks_wlan_get_firmware_version, /* 3 KS_WLAN_GET_FIRM_VERSION */
2730 (iw_handler)ks_wlan_set_wps_enable, /* 4 KS_WLAN_SET_WPS_ENABLE */
2731 (iw_handler)ks_wlan_get_wps_enable, /* 5 KS_WLAN_GET_WPS_ENABLE */
2732 (iw_handler)ks_wlan_set_wps_probe_req, /* 6 KS_WLAN_SET_WPS_PROBE_REQ */
2734 (iw_handler)NULL, /* 4 */
2735 (iw_handler)NULL, /* 5 */
2736 (iw_handler)NULL, /* 6 */
2739 (iw_handler)ks_wlan_get_eeprom_cksum, /* 7 KS_WLAN_GET_CONNECT */
2740 (iw_handler)ks_wlan_set_preamble, /* 8 KS_WLAN_SET_PREAMBLE */
2741 (iw_handler)ks_wlan_get_preamble, /* 9 KS_WLAN_GET_PREAMBLE */
2742 (iw_handler)ks_wlan_set_power_mgmt, /* 10 KS_WLAN_SET_POWER_SAVE */
2743 (iw_handler)ks_wlan_get_power_mgmt, /* 11 KS_WLAN_GET_POWER_SAVE */
2744 (iw_handler)ks_wlan_set_scan_type, /* 12 KS_WLAN_SET_SCAN_TYPE */
2745 (iw_handler)ks_wlan_get_scan_type, /* 13 KS_WLAN_GET_SCAN_TYPE */
2746 (iw_handler)ks_wlan_set_rx_gain, /* 14 KS_WLAN_SET_RX_GAIN */
2747 (iw_handler)ks_wlan_get_rx_gain, /* 15 KS_WLAN_GET_RX_GAIN */
2748 (iw_handler)ks_wlan_hostt, /* 16 KS_WLAN_HOSTT */
2749 (iw_handler)NULL, /* 17 */
2750 (iw_handler)ks_wlan_set_beacon_lost, /* 18 KS_WLAN_SET_BECAN_LOST */
2751 (iw_handler)ks_wlan_get_beacon_lost, /* 19 KS_WLAN_GET_BECAN_LOST */
2752 (iw_handler)ks_wlan_set_tx_gain, /* 20 KS_WLAN_SET_TX_GAIN */
2753 (iw_handler)ks_wlan_get_tx_gain, /* 21 KS_WLAN_GET_TX_GAIN */
2754 (iw_handler)ks_wlan_set_phy_type, /* 22 KS_WLAN_SET_PHY_TYPE */
2755 (iw_handler)ks_wlan_get_phy_type, /* 23 KS_WLAN_GET_PHY_TYPE */
2756 (iw_handler)ks_wlan_set_cts_mode, /* 24 KS_WLAN_SET_CTS_MODE */
2757 (iw_handler)ks_wlan_get_cts_mode, /* 25 KS_WLAN_GET_CTS_MODE */
2758 (iw_handler)NULL, /* 26 */
2759 (iw_handler)NULL, /* 27 */
2760 (iw_handler)ks_wlan_set_sleep_mode, /* 28 KS_WLAN_SET_SLEEP_MODE */
2761 (iw_handler)ks_wlan_get_sleep_mode, /* 29 KS_WLAN_GET_SLEEP_MODE */
2762 (iw_handler)NULL, /* 30 */
2763 (iw_handler)NULL, /* 31 */
2766 static const struct iw_handler_def ks_wlan_handler_def = {
2767 .num_standard = sizeof(ks_wlan_handler) / sizeof(iw_handler),
2768 .num_private = sizeof(ks_wlan_private_handler) / sizeof(iw_handler),
2770 sizeof(ks_wlan_private_args) / sizeof(struct iw_priv_args),
2771 .standard = (iw_handler *)ks_wlan_handler,
2772 .private = (iw_handler *)ks_wlan_private_handler,
2773 .private_args = (struct iw_priv_args *)ks_wlan_private_args,
2774 .get_wireless_stats = ks_get_wireless_stats,
2777 static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq,
2781 struct iwreq *wrq = (struct iwreq *)rq;
2784 case SIOCIWFIRSTPRIV + 20: /* KS_WLAN_SET_STOP_REQ */
2785 ret = ks_wlan_set_stop_request(dev, NULL, &wrq->u.mode, NULL);
2787 // All other calls are currently unsupported
2792 DPRINTK(5, "return=%d\n", ret);
2797 struct net_device_stats *ks_wlan_get_stats(struct net_device *dev)
2799 struct ks_wlan_private *priv = netdev_priv(dev);
2801 if (priv->dev_state < DEVICE_STATE_READY)
2802 return NULL; /* not finished initialize */
2804 return &priv->nstats;
2808 int ks_wlan_set_mac_address(struct net_device *dev, void *addr)
2810 struct ks_wlan_private *priv = netdev_priv(dev);
2811 struct sockaddr *mac_addr = (struct sockaddr *)addr;
2813 if (netif_running(dev))
2815 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
2816 memcpy(priv->eth_addr, mac_addr->sa_data, ETH_ALEN);
2818 priv->mac_address_valid = 0;
2819 hostif_sme_enqueue(priv, SME_MACADDRESS_SET_REQUEST);
2820 netdev_info(dev, "ks_wlan: MAC ADDRESS = %pM\n", priv->eth_addr);
2825 void ks_wlan_tx_timeout(struct net_device *dev)
2827 struct ks_wlan_private *priv = netdev_priv(dev);
2829 DPRINTK(1, "head(%d) tail(%d)!!\n", priv->tx_dev.qhead,
2830 priv->tx_dev.qtail);
2831 if (!netif_queue_stopped(dev))
2832 netif_stop_queue(dev);
2833 priv->nstats.tx_errors++;
2834 netif_wake_queue(dev);
2838 int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev)
2840 struct ks_wlan_private *priv = netdev_priv(dev);
2843 DPRINTK(3, "in_interrupt()=%ld\n", in_interrupt());
2846 netdev_err(dev, "ks_wlan: skb == NULL!!!\n");
2849 if (priv->dev_state < DEVICE_STATE_READY) {
2851 return 0; /* not finished initialize */
2854 if (netif_running(dev))
2855 netif_stop_queue(dev);
2857 ret = hostif_data_request(priv, skb);
2858 netif_trans_update(dev);
2861 DPRINTK(4, "hostif_data_request error: =%d\n", ret);
2866 void send_packet_complete(struct ks_wlan_private *priv, struct sk_buff *skb)
2870 priv->nstats.tx_packets++;
2872 if (netif_queue_stopped(priv->net_dev))
2873 netif_wake_queue(priv->net_dev);
2876 priv->nstats.tx_bytes += skb->len;
2882 * Set or clear the multicast filter for this adaptor.
2883 * This routine is not state sensitive and need not be SMP locked.
2886 void ks_wlan_set_multicast_list(struct net_device *dev)
2888 struct ks_wlan_private *priv = netdev_priv(dev);
2891 if (priv->dev_state < DEVICE_STATE_READY)
2892 return; /* not finished initialize */
2893 hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST);
2897 int ks_wlan_open(struct net_device *dev)
2899 struct ks_wlan_private *priv = netdev_priv(dev);
2903 if (!priv->mac_address_valid) {
2904 netdev_err(dev, "ks_wlan : %s Not READY !!\n", dev->name);
2907 netif_start_queue(dev);
2913 int ks_wlan_close(struct net_device *dev)
2915 netif_stop_queue(dev);
2917 DPRINTK(4, "%s: Shutting down ethercard, status was 0x%4.4x.\n",
2923 /* Operational parameters that usually are not changed. */
2924 /* Time in jiffies before concluding the transmitter is hung. */
2925 #define TX_TIMEOUT (3 * HZ)
2926 static const unsigned char dummy_addr[] = {
2927 0x00, 0x0b, 0xe3, 0x00, 0x00, 0x00
2930 static const struct net_device_ops ks_wlan_netdev_ops = {
2931 .ndo_start_xmit = ks_wlan_start_xmit,
2932 .ndo_open = ks_wlan_open,
2933 .ndo_stop = ks_wlan_close,
2934 .ndo_do_ioctl = ks_wlan_netdev_ioctl,
2935 .ndo_set_mac_address = ks_wlan_set_mac_address,
2936 .ndo_get_stats = ks_wlan_get_stats,
2937 .ndo_tx_timeout = ks_wlan_tx_timeout,
2938 .ndo_set_rx_mode = ks_wlan_set_multicast_list,
2941 int ks_wlan_net_start(struct net_device *dev)
2943 struct ks_wlan_private *priv;
2946 priv = netdev_priv(dev);
2947 priv->mac_address_valid = 0;
2948 priv->need_commit = 0;
2950 priv->device_open_status = 1;
2952 /* phy information update timer */
2953 atomic_set(&update_phyinfo, 0);
2954 setup_timer(&update_phyinfo_timer, ks_wlan_update_phyinfo_timeout,
2955 (unsigned long)priv);
2957 /* dummy address set */
2958 memcpy(priv->eth_addr, dummy_addr, ETH_ALEN);
2959 dev->dev_addr[0] = priv->eth_addr[0];
2960 dev->dev_addr[1] = priv->eth_addr[1];
2961 dev->dev_addr[2] = priv->eth_addr[2];
2962 dev->dev_addr[3] = priv->eth_addr[3];
2963 dev->dev_addr[4] = priv->eth_addr[4];
2964 dev->dev_addr[5] = priv->eth_addr[5];
2965 dev->dev_addr[6] = 0x00;
2966 dev->dev_addr[7] = 0x00;
2968 /* The ks_wlan-specific entries in the device structure. */
2969 dev->netdev_ops = &ks_wlan_netdev_ops;
2970 dev->wireless_handlers = (struct iw_handler_def *)&ks_wlan_handler_def;
2971 dev->watchdog_timeo = TX_TIMEOUT;
2973 netif_carrier_off(dev);
2978 int ks_wlan_net_stop(struct net_device *dev)
2980 struct ks_wlan_private *priv = netdev_priv(dev);
2982 priv->device_open_status = 0;
2983 del_timer_sync(&update_phyinfo_timer);
2985 if (netif_running(dev))
2986 netif_stop_queue(dev);
2992 * is_connect_status() - return true if status is 'connected'
2993 * @status: high bit is used as FORCE_DISCONNECT, low bits used for
2996 bool is_connect_status(u32 status)
2998 return (status & CONNECT_STATUS_MASK) == CONNECT_STATUS;
3002 * is_disconnect_status() - return true if status is 'disconnected'
3003 * @status: high bit is used as FORCE_DISCONNECT, low bits used for
3004 * disconnect status.
3006 bool is_disconnect_status(u32 status)
3008 return (status & CONNECT_STATUS_MASK) == DISCONNECT_STATUS;