2 * Driver for KeyStream 11b/g wireless LAN
4 * Copyright (C) 2005-2008 KeyStream Corp.
5 * Copyright (C) 2009 Renesas Technology Corp.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/compiler.h>
15 #include <linux/init.h>
16 #include <linux/ioport.h>
17 #include <linux/netdevice.h>
18 #include <linux/etherdevice.h>
19 #include <linux/if_arp.h>
20 #include <linux/rtnetlink.h>
21 #include <linux/delay.h>
22 #include <linux/completion.h>
23 #include <linux/mii.h>
24 #include <linux/pci.h>
25 #include <linux/ctype.h>
26 #include <linux/timer.h>
27 #include <asm/atomic.h>
29 #include <asm/uaccess.h>
31 static int wep_on_off;
33 #define WEP_ON_64BIT 1
34 #define WEP_ON_128BIT 2
37 #include "ks_hostif.h"
38 #include "ks_wlan_ioctl.h"
40 /* Include Wireless Extension definition and check version */
41 #include <linux/wireless.h>
42 #define WIRELESS_SPY /* enable iwspy support */
43 #include <net/iw_handler.h> /* New driver API */
45 /* Frequency list (map channels to frequencies) */
46 static const long frequency_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
47 2447, 2452, 2457, 2462, 2467, 2472, 2484
50 /* A few details needed for WEP (Wireless Equivalent Privacy) */
51 #define MAX_KEY_SIZE 13 /* 128 (?) bits */
52 #define MIN_KEY_SIZE 5 /* 40 bits RC4 - WEP */
53 typedef struct wep_key_t {
55 u8 key[16]; /* 40-bit and 104-bit keys */
58 /* Backward compatibility */
59 #ifndef IW_ENCODE_NOKEY
60 #define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not present */
61 #define IW_ENCODE_MODE (IW_ENCODE_DISABLED | IW_ENCODE_RESTRICTED | IW_ENCODE_OPEN)
62 #endif /* IW_ENCODE_NOKEY */
64 /* List of Wireless Handlers (new API) */
65 static const struct iw_handler_def ks_wlan_handler_def;
67 #define KSC_OPNOTSUPP /* Operation Not Support */
72 static int ks_wlan_open(struct net_device *dev);
73 static void ks_wlan_tx_timeout(struct net_device *dev);
74 static int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev);
75 static int ks_wlan_close(struct net_device *dev);
76 static void ks_wlan_set_multicast_list(struct net_device *dev);
77 static struct net_device_stats *ks_wlan_get_stats(struct net_device *dev);
78 static int ks_wlan_set_mac_address(struct net_device *dev, void *addr);
79 static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq,
82 static atomic_t update_phyinfo;
83 static struct timer_list update_phyinfo_timer;
85 int ks_wlan_update_phy_information(struct ks_wlan_private *priv)
87 struct iw_statistics *wstats = &priv->wstats;
89 DPRINTK(4, "in_interrupt = %ld\n", in_interrupt());
91 if (priv->dev_state < DEVICE_STATE_READY) {
92 return -1; /* not finished initialize */
94 if (atomic_read(&update_phyinfo))
98 wstats->status = priv->reg.operation_mode; /* Operation mode */
100 /* Signal quality and co. But where is the noise level ??? */
101 hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST);
103 /* interruptible_sleep_on_timeout(&priv->confirm_wait, HZ/2); */
104 if (!wait_for_completion_interruptible_timeout
105 (&priv->confirm_wait, HZ / 2)) {
106 DPRINTK(1, "wait time out!!\n");
109 atomic_inc(&update_phyinfo);
110 update_phyinfo_timer.expires = jiffies + HZ; /* 1sec */
111 add_timer(&update_phyinfo_timer);
117 void ks_wlan_update_phyinfo_timeout(unsigned long ptr)
119 DPRINTK(4, "in_interrupt = %ld\n", in_interrupt());
120 atomic_set(&update_phyinfo, 0);
123 int ks_wlan_setup_parameter(struct ks_wlan_private *priv,
124 unsigned int commit_flag)
128 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
130 if (commit_flag & SME_RTS)
131 hostif_sme_enqueue(priv, SME_RTS_THRESHOLD_REQUEST);
132 if (commit_flag & SME_FRAG)
133 hostif_sme_enqueue(priv, SME_FRAGMENTATION_THRESHOLD_REQUEST);
135 if (commit_flag & SME_WEP_INDEX)
136 hostif_sme_enqueue(priv, SME_WEP_INDEX_REQUEST);
137 if (commit_flag & SME_WEP_VAL1)
138 hostif_sme_enqueue(priv, SME_WEP_KEY1_REQUEST);
139 if (commit_flag & SME_WEP_VAL2)
140 hostif_sme_enqueue(priv, SME_WEP_KEY2_REQUEST);
141 if (commit_flag & SME_WEP_VAL3)
142 hostif_sme_enqueue(priv, SME_WEP_KEY3_REQUEST);
143 if (commit_flag & SME_WEP_VAL4)
144 hostif_sme_enqueue(priv, SME_WEP_KEY4_REQUEST);
145 if (commit_flag & SME_WEP_FLAG)
146 hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
148 if (commit_flag & SME_RSN) {
149 hostif_sme_enqueue(priv, SME_RSN_ENABLED_REQUEST);
150 hostif_sme_enqueue(priv, SME_RSN_MODE_REQUEST);
152 if (commit_flag & SME_RSN_MULTICAST)
153 hostif_sme_enqueue(priv, SME_RSN_MCAST_REQUEST);
154 if (commit_flag & SME_RSN_UNICAST)
155 hostif_sme_enqueue(priv, SME_RSN_UCAST_REQUEST);
156 if (commit_flag & SME_RSN_AUTH)
157 hostif_sme_enqueue(priv, SME_RSN_AUTH_REQUEST);
159 hostif_sme_enqueue(priv, SME_MODE_SET_REQUEST);
161 hostif_sme_enqueue(priv, SME_START_REQUEST);
167 * Initial Wireless Extension code for Ks_Wlannet driver by :
168 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00
169 * Conversion to new driver API by :
170 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 26 March 02
171 * Javier also did a good amount of work here, adding some new extensions
172 * and fixing my code. Let's just say that without him this code just
173 * would not work at all... - Jean II
176 /*------------------------------------------------------------------*/
177 /* Wireless Handler : get protocol name */
178 static int ks_wlan_get_name(struct net_device *dev,
179 struct iw_request_info *info, char *cwrq,
182 struct ks_wlan_private *priv =
183 (struct ks_wlan_private *)netdev_priv(dev);
185 if (priv->sleep_mode == SLP_SLEEP) {
189 if (priv->dev_state < DEVICE_STATE_READY) {
190 strcpy(cwrq, "NOT READY!");
191 } else if (priv->reg.phy_type == D_11B_ONLY_MODE) {
192 strcpy(cwrq, "IEEE 802.11b");
193 } else if (priv->reg.phy_type == D_11G_ONLY_MODE) {
194 strcpy(cwrq, "IEEE 802.11g");
196 strcpy(cwrq, "IEEE 802.11b/g");
202 /*------------------------------------------------------------------*/
203 /* Wireless Handler : set frequency */
204 static int ks_wlan_set_freq(struct net_device *dev,
205 struct iw_request_info *info, struct iw_freq *fwrq,
208 struct ks_wlan_private *priv =
209 (struct ks_wlan_private *)netdev_priv(dev);
210 int rc = -EINPROGRESS; /* Call commit handler */
212 if (priv->sleep_mode == SLP_SLEEP) {
217 /* If setting by frequency, convert to a channel */
218 if ((fwrq->e == 1) &&
219 (fwrq->m >= (int)2.412e8) && (fwrq->m <= (int)2.487e8)) {
220 int f = fwrq->m / 100000;
222 while ((c < 14) && (f != frequency_list[c]))
224 /* Hack to fall through... */
228 /* Setting by channel number */
229 if ((fwrq->m > 1000) || (fwrq->e > 0))
232 int channel = fwrq->m;
233 /* We should do a better check than that,
234 * based on the card capability !!! */
235 if ((channel < 1) || (channel > 14)) {
237 "%s: New channel value of %d is invalid!\n",
241 /* Yes ! We can set it !!! */
242 priv->reg.channel = (u8) (channel);
243 priv->need_commit |= SME_MODE_SET;
250 /*------------------------------------------------------------------*/
251 /* Wireless Handler : get frequency */
252 static int ks_wlan_get_freq(struct net_device *dev,
253 struct iw_request_info *info, struct iw_freq *fwrq,
256 struct ks_wlan_private *priv =
257 (struct ks_wlan_private *)netdev_priv(dev);
260 if (priv->sleep_mode == SLP_SLEEP) {
264 if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
265 f = (int)priv->current_ap.channel;
267 f = (int)priv->reg.channel;
268 fwrq->m = frequency_list[f - 1] * 100000;
274 /*------------------------------------------------------------------*/
275 /* Wireless Handler : set ESSID */
276 static int ks_wlan_set_essid(struct net_device *dev,
277 struct iw_request_info *info,
278 struct iw_point *dwrq, char *extra)
280 struct ks_wlan_private *priv =
281 (struct ks_wlan_private *)netdev_priv(dev);
284 DPRINTK(2, " %d\n", dwrq->flags);
286 if (priv->sleep_mode == SLP_SLEEP) {
291 /* Check if we asked for `any' */
292 if (dwrq->flags == 0) {
293 /* Just send an empty SSID list */
294 memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
295 priv->reg.ssid.size = 0;
299 /* iwconfig uses nul termination in SSID.. */
300 if (len > 0 && extra[len - 1] == '\0')
303 /* Check the size of the string */
304 if (len > IW_ESSID_MAX_SIZE) {
308 /* Check the size of the string */
309 if (dwrq->length > IW_ESSID_MAX_SIZE + 1) {
315 memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
318 memcpy(priv->reg.ssid.body, extra, len);
319 priv->reg.ssid.size = len;
321 memcpy(priv->reg.ssid.body, extra, dwrq->length);
322 priv->reg.ssid.size = dwrq->length;
325 /* Write it to the card */
326 priv->need_commit |= SME_MODE_SET;
328 // return -EINPROGRESS; /* Call commit handler */
329 ks_wlan_setup_parameter(priv, priv->need_commit);
330 priv->need_commit = 0;
334 /*------------------------------------------------------------------*/
335 /* Wireless Handler : get ESSID */
336 static int ks_wlan_get_essid(struct net_device *dev,
337 struct iw_request_info *info,
338 struct iw_point *dwrq, char *extra)
340 struct ks_wlan_private *priv =
341 (struct ks_wlan_private *)netdev_priv(dev);
343 if (priv->sleep_mode == SLP_SLEEP) {
348 /* Note : if dwrq->flags != 0, we should
349 * get the relevant SSID from the SSID list... */
350 if (priv->reg.ssid.size) {
351 /* Get the current SSID */
352 memcpy(extra, priv->reg.ssid.body, priv->reg.ssid.size);
354 extra[priv->reg.ssid.size] = '\0';
356 /* If none, we may want to get the one that was set */
360 dwrq->length = priv->reg.ssid.size;
362 dwrq->length = priv->reg.ssid.size + 1;
364 dwrq->flags = 1; /* active */
372 dwrq->flags = 0; /* ANY */
378 /*------------------------------------------------------------------*/
379 /* Wireless Handler : set AP address */
380 static int ks_wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
381 struct sockaddr *ap_addr, char *extra)
383 struct ks_wlan_private *priv =
384 (struct ks_wlan_private *)netdev_priv(dev);
388 if (priv->sleep_mode == SLP_SLEEP) {
392 if (priv->reg.operation_mode == MODE_ADHOC ||
393 priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
394 memcpy(priv->reg.bssid, (u8 *) & ap_addr->sa_data, ETH_ALEN);
396 if (is_valid_ether_addr((u8 *) priv->reg.bssid)) {
397 priv->need_commit |= SME_MODE_SET;
400 eth_zero_addr(priv->reg.bssid);
404 DPRINTK(2, "bssid = %02x:%02x:%02x:%02x:%02x:%02x\n",
405 priv->reg.bssid[0], priv->reg.bssid[1], priv->reg.bssid[2],
406 priv->reg.bssid[3], priv->reg.bssid[4], priv->reg.bssid[5]);
408 /* Write it to the card */
409 if (priv->need_commit) {
410 priv->need_commit |= SME_MODE_SET;
411 return -EINPROGRESS; /* Call commit handler */
416 /*------------------------------------------------------------------*/
417 /* Wireless Handler : get AP address */
418 static int ks_wlan_get_wap(struct net_device *dev, struct iw_request_info *info,
419 struct sockaddr *awrq, char *extra)
421 struct ks_wlan_private *priv =
422 (struct ks_wlan_private *)netdev_priv(dev);
424 if (priv->sleep_mode == SLP_SLEEP) {
428 if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
429 memcpy(awrq->sa_data, &(priv->current_ap.bssid[0]), ETH_ALEN);
431 eth_zero_addr(awrq->sa_data);
434 awrq->sa_family = ARPHRD_ETHER;
439 /*------------------------------------------------------------------*/
440 /* Wireless Handler : set Nickname */
441 static int ks_wlan_set_nick(struct net_device *dev,
442 struct iw_request_info *info, struct iw_point *dwrq,
445 struct ks_wlan_private *priv =
446 (struct ks_wlan_private *)netdev_priv(dev);
448 if (priv->sleep_mode == SLP_SLEEP) {
453 /* Check the size of the string */
454 if (dwrq->length > 16 + 1) {
457 memset(priv->nick, 0, sizeof(priv->nick));
458 memcpy(priv->nick, extra, dwrq->length);
460 return -EINPROGRESS; /* Call commit handler */
463 /*------------------------------------------------------------------*/
464 /* Wireless Handler : get Nickname */
465 static int ks_wlan_get_nick(struct net_device *dev,
466 struct iw_request_info *info, struct iw_point *dwrq,
469 struct ks_wlan_private *priv =
470 (struct ks_wlan_private *)netdev_priv(dev);
472 if (priv->sleep_mode == SLP_SLEEP) {
476 strncpy(extra, priv->nick, 16);
478 dwrq->length = strlen(extra) + 1;
483 /*------------------------------------------------------------------*/
484 /* Wireless Handler : set Bit-Rate */
485 static int ks_wlan_set_rate(struct net_device *dev,
486 struct iw_request_info *info, struct iw_param *vwrq,
489 struct ks_wlan_private *priv =
490 (struct ks_wlan_private *)netdev_priv(dev);
493 if (priv->sleep_mode == SLP_SLEEP) {
497 if (priv->reg.phy_type == D_11B_ONLY_MODE) {
498 if (vwrq->fixed == 1) {
499 switch (vwrq->value) {
502 priv->reg.rate_set.body[0] =
503 (uint8_t) (vwrq->value / 500000);
507 priv->reg.rate_set.body[0] =
508 ((uint8_t) (vwrq->value / 500000)) |
514 priv->reg.tx_rate = TX_RATE_FIXED;
515 priv->reg.rate_set.size = 1;
516 } else { /* vwrq->fixed == 0 */
517 if (vwrq->value > 0) {
518 switch (vwrq->value) {
520 priv->reg.rate_set.body[3] =
524 priv->reg.rate_set.body[2] = TX_RATE_5M;
527 priv->reg.rate_set.body[1] =
528 TX_RATE_2M | BASIC_RATE;
531 priv->reg.rate_set.body[0] =
532 TX_RATE_1M | BASIC_RATE;
538 priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
539 priv->reg.rate_set.size = i;
541 priv->reg.rate_set.body[3] = TX_RATE_11M;
542 priv->reg.rate_set.body[2] = TX_RATE_5M;
543 priv->reg.rate_set.body[1] =
544 TX_RATE_2M | BASIC_RATE;
545 priv->reg.rate_set.body[0] =
546 TX_RATE_1M | BASIC_RATE;
547 priv->reg.tx_rate = TX_RATE_FULL_AUTO;
548 priv->reg.rate_set.size = 4;
551 } else { /* D_11B_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
552 if (vwrq->fixed == 1) {
553 switch (vwrq->value) {
559 priv->reg.rate_set.body[0] =
560 (uint8_t) (vwrq->value / 500000);
569 priv->reg.rate_set.body[0] =
570 ((uint8_t) (vwrq->value / 500000)) |
576 priv->reg.tx_rate = TX_RATE_FIXED;
577 priv->reg.rate_set.size = 1;
578 } else { /* vwrq->fixed == 0 */
579 if (vwrq->value > 0) {
580 switch (vwrq->value) {
582 priv->reg.rate_set.body[11] =
586 priv->reg.rate_set.body[10] =
590 priv->reg.rate_set.body[9] =
599 if (vwrq->value == 24000000) {
600 priv->reg.rate_set.body[8] =
603 priv->reg.rate_set.body[7] =
606 priv->reg.rate_set.body[6] =
607 TX_RATE_24M | BASIC_RATE;
609 priv->reg.rate_set.body[5] =
610 TX_RATE_12M | BASIC_RATE;
612 priv->reg.rate_set.body[4] =
613 TX_RATE_6M | BASIC_RATE;
615 priv->reg.rate_set.body[3] =
616 TX_RATE_11M | BASIC_RATE;
618 } else if (vwrq->value == 18000000) {
619 priv->reg.rate_set.body[7] =
622 priv->reg.rate_set.body[6] =
625 priv->reg.rate_set.body[5] =
626 TX_RATE_12M | BASIC_RATE;
628 priv->reg.rate_set.body[4] =
629 TX_RATE_6M | BASIC_RATE;
631 priv->reg.rate_set.body[3] =
632 TX_RATE_11M | BASIC_RATE;
634 } else if (vwrq->value == 12000000) {
635 priv->reg.rate_set.body[6] =
638 priv->reg.rate_set.body[5] =
639 TX_RATE_12M | BASIC_RATE;
641 priv->reg.rate_set.body[4] =
642 TX_RATE_6M | BASIC_RATE;
644 priv->reg.rate_set.body[3] =
645 TX_RATE_11M | BASIC_RATE;
647 } else if (vwrq->value == 11000000) {
648 priv->reg.rate_set.body[5] =
651 priv->reg.rate_set.body[4] =
652 TX_RATE_6M | BASIC_RATE;
654 priv->reg.rate_set.body[3] =
655 TX_RATE_11M | BASIC_RATE;
657 } else if (vwrq->value == 9000000) {
658 priv->reg.rate_set.body[4] =
661 priv->reg.rate_set.body[3] =
662 TX_RATE_6M | BASIC_RATE;
664 } else { /* vwrq->value == 6000000 */
665 priv->reg.rate_set.body[3] =
666 TX_RATE_6M | BASIC_RATE;
670 priv->reg.rate_set.body[2] =
671 TX_RATE_5M | BASIC_RATE;
674 priv->reg.rate_set.body[1] =
675 TX_RATE_2M | BASIC_RATE;
678 priv->reg.rate_set.body[0] =
679 TX_RATE_1M | BASIC_RATE;
685 priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
686 priv->reg.rate_set.size = i;
688 priv->reg.rate_set.body[11] = TX_RATE_54M;
689 priv->reg.rate_set.body[10] = TX_RATE_48M;
690 priv->reg.rate_set.body[9] = TX_RATE_36M;
691 priv->reg.rate_set.body[8] = TX_RATE_18M;
692 priv->reg.rate_set.body[7] = TX_RATE_9M;
693 priv->reg.rate_set.body[6] =
694 TX_RATE_24M | BASIC_RATE;
695 priv->reg.rate_set.body[5] =
696 TX_RATE_12M | BASIC_RATE;
697 priv->reg.rate_set.body[4] =
698 TX_RATE_6M | BASIC_RATE;
699 priv->reg.rate_set.body[3] =
700 TX_RATE_11M | BASIC_RATE;
701 priv->reg.rate_set.body[2] =
702 TX_RATE_5M | BASIC_RATE;
703 priv->reg.rate_set.body[1] =
704 TX_RATE_2M | BASIC_RATE;
705 priv->reg.rate_set.body[0] =
706 TX_RATE_1M | BASIC_RATE;
707 priv->reg.tx_rate = TX_RATE_FULL_AUTO;
708 priv->reg.rate_set.size = 12;
713 priv->need_commit |= SME_MODE_SET;
715 return -EINPROGRESS; /* Call commit handler */
718 /*------------------------------------------------------------------*/
719 /* Wireless Handler : get Bit-Rate */
720 static int ks_wlan_get_rate(struct net_device *dev,
721 struct iw_request_info *info, struct iw_param *vwrq,
724 struct ks_wlan_private *priv =
725 (struct ks_wlan_private *)netdev_priv(dev);
727 DPRINTK(2, "in_interrupt = %ld update_phyinfo = %d\n",
728 in_interrupt(), atomic_read(&update_phyinfo));
730 if (priv->sleep_mode == SLP_SLEEP) {
734 if (!atomic_read(&update_phyinfo)) {
735 ks_wlan_update_phy_information(priv);
737 vwrq->value = ((priv->current_rate) & RATE_MASK) * 500000;
738 if (priv->reg.tx_rate == TX_RATE_FIXED)
746 /*------------------------------------------------------------------*/
747 /* Wireless Handler : set RTS threshold */
748 static int ks_wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
749 struct iw_param *vwrq, char *extra)
751 struct ks_wlan_private *priv =
752 (struct ks_wlan_private *)netdev_priv(dev);
753 int rthr = vwrq->value;
755 if (priv->sleep_mode == SLP_SLEEP) {
761 if ((rthr < 0) || (rthr > 2347)) {
764 priv->reg.rts = rthr;
765 priv->need_commit |= SME_RTS;
767 return -EINPROGRESS; /* Call commit handler */
770 /*------------------------------------------------------------------*/
771 /* Wireless Handler : get RTS threshold */
772 static int ks_wlan_get_rts(struct net_device *dev, struct iw_request_info *info,
773 struct iw_param *vwrq, char *extra)
775 struct ks_wlan_private *priv =
776 (struct ks_wlan_private *)netdev_priv(dev);
778 if (priv->sleep_mode == SLP_SLEEP) {
782 vwrq->value = priv->reg.rts;
783 vwrq->disabled = (vwrq->value >= 2347);
789 /*------------------------------------------------------------------*/
790 /* Wireless Handler : set Fragmentation threshold */
791 static int ks_wlan_set_frag(struct net_device *dev,
792 struct iw_request_info *info, struct iw_param *vwrq,
795 struct ks_wlan_private *priv =
796 (struct ks_wlan_private *)netdev_priv(dev);
797 int fthr = vwrq->value;
799 if (priv->sleep_mode == SLP_SLEEP) {
805 if ((fthr < 256) || (fthr > 2346)) {
808 fthr &= ~0x1; /* Get an even value - is it really needed ??? */
809 priv->reg.fragment = fthr;
810 priv->need_commit |= SME_FRAG;
812 return -EINPROGRESS; /* Call commit handler */
815 /*------------------------------------------------------------------*/
816 /* Wireless Handler : get Fragmentation threshold */
817 static int ks_wlan_get_frag(struct net_device *dev,
818 struct iw_request_info *info, struct iw_param *vwrq,
821 struct ks_wlan_private *priv =
822 (struct ks_wlan_private *)netdev_priv(dev);
824 if (priv->sleep_mode == SLP_SLEEP) {
828 vwrq->value = priv->reg.fragment;
829 vwrq->disabled = (vwrq->value >= 2346);
835 /*------------------------------------------------------------------*/
836 /* Wireless Handler : set Mode of Operation */
837 static int ks_wlan_set_mode(struct net_device *dev,
838 struct iw_request_info *info, __u32 * uwrq,
841 struct ks_wlan_private *priv =
842 (struct ks_wlan_private *)netdev_priv(dev);
844 DPRINTK(2, "mode=%d\n", *uwrq);
846 if (priv->sleep_mode == SLP_SLEEP) {
852 priv->reg.operation_mode = MODE_ADHOC;
853 priv->need_commit |= SME_MODE_SET;
856 priv->reg.operation_mode = MODE_INFRASTRUCTURE;
857 priv->need_commit |= SME_MODE_SET;
863 case IW_MODE_MONITOR:
868 return -EINPROGRESS; /* Call commit handler */
871 /*------------------------------------------------------------------*/
872 /* Wireless Handler : get Mode of Operation */
873 static int ks_wlan_get_mode(struct net_device *dev,
874 struct iw_request_info *info, __u32 * uwrq,
877 struct ks_wlan_private *priv =
878 (struct ks_wlan_private *)netdev_priv(dev);
880 if (priv->sleep_mode == SLP_SLEEP) {
885 /* If not managed, assume it's ad-hoc */
886 switch (priv->reg.operation_mode) {
887 case MODE_INFRASTRUCTURE:
888 *uwrq = IW_MODE_INFRA;
891 *uwrq = IW_MODE_ADHOC;
894 *uwrq = IW_MODE_ADHOC;
900 /*------------------------------------------------------------------*/
901 /* Wireless Handler : set Encryption Key */
902 static int ks_wlan_set_encode(struct net_device *dev,
903 struct iw_request_info *info,
904 struct iw_point *dwrq, char *extra)
906 struct ks_wlan_private *priv =
907 (struct ks_wlan_private *)netdev_priv(dev);
910 int index = (dwrq->flags & IW_ENCODE_INDEX);
911 int current_index = priv->reg.wep_index;
914 DPRINTK(2, "flags=%04X\n", dwrq->flags);
916 if (priv->sleep_mode == SLP_SLEEP) {
922 if ((index < 0) || (index > 4))
925 index = current_index;
929 /* Is WEP supported ? */
930 /* Basic checking: do we have a key to set ? */
931 if (dwrq->length > 0) {
932 if (dwrq->length > MAX_KEY_SIZE) { /* Check the size of the key */
935 if (dwrq->length > MIN_KEY_SIZE) { /* Set the length */
936 key.len = MAX_KEY_SIZE;
937 priv->reg.privacy_invoked = 0x01;
938 priv->need_commit |= SME_WEP_FLAG;
939 wep_on_off = WEP_ON_128BIT;
941 if (dwrq->length > 0) {
942 key.len = MIN_KEY_SIZE;
943 priv->reg.privacy_invoked = 0x01;
944 priv->need_commit |= SME_WEP_FLAG;
945 wep_on_off = WEP_ON_64BIT;
946 } else { /* Disable the key */
950 /* Check if the key is not marked as invalid */
951 if (!(dwrq->flags & IW_ENCODE_NOKEY)) {
953 memset(key.key, 0, MAX_KEY_SIZE);
954 /* Copy the key in the driver */
956 (key.key, dwrq->pointer, dwrq->length)) {
960 /* Send the key to the card */
961 priv->reg.wep_key[index].size = key.len;
962 for (i = 0; i < (priv->reg.wep_key[index].size); i++) {
963 priv->reg.wep_key[index].val[i] = key.key[i];
965 priv->need_commit |= (SME_WEP_VAL1 << index);
966 priv->reg.wep_index = index;
967 priv->need_commit |= SME_WEP_INDEX;
970 if (dwrq->flags & IW_ENCODE_DISABLED) {
971 priv->reg.wep_key[0].size = 0;
972 priv->reg.wep_key[1].size = 0;
973 priv->reg.wep_key[2].size = 0;
974 priv->reg.wep_key[3].size = 0;
975 priv->reg.privacy_invoked = 0x00;
976 if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY) {
977 priv->need_commit |= SME_MODE_SET;
979 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
980 wep_on_off = WEP_OFF;
981 priv->need_commit |= SME_WEP_FLAG;
983 /* Do we want to just set the transmit key index ? */
984 if ((index >= 0) && (index < 4)) {
985 /* set_wep_key(priv, index, 0, 0, 1); xxx */
986 if (priv->reg.wep_key[index].size) {
987 priv->reg.wep_index = index;
988 priv->need_commit |= SME_WEP_INDEX;
995 /* Commit the changes if needed */
996 if (dwrq->flags & IW_ENCODE_MODE)
997 priv->need_commit |= SME_WEP_FLAG;
999 if (dwrq->flags & IW_ENCODE_OPEN) {
1000 if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY) {
1001 priv->need_commit |= SME_MODE_SET;
1003 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
1004 } else if (dwrq->flags & IW_ENCODE_RESTRICTED) {
1005 if (priv->reg.authenticate_type == AUTH_TYPE_OPEN_SYSTEM) {
1006 priv->need_commit |= SME_MODE_SET;
1008 priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
1010 // return -EINPROGRESS; /* Call commit handler */
1011 if (priv->need_commit) {
1012 ks_wlan_setup_parameter(priv, priv->need_commit);
1013 priv->need_commit = 0;
1018 /*------------------------------------------------------------------*/
1019 /* Wireless Handler : get Encryption Key */
1020 static int ks_wlan_get_encode(struct net_device *dev,
1021 struct iw_request_info *info,
1022 struct iw_point *dwrq, char *extra)
1024 struct ks_wlan_private *priv =
1025 (struct ks_wlan_private *)netdev_priv(dev);
1027 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1029 if (priv->sleep_mode == SLP_SLEEP) {
1032 /* for SLEEP MODE */
1033 dwrq->flags = IW_ENCODE_DISABLED;
1035 /* Check encryption mode */
1036 switch (priv->reg.authenticate_type) {
1037 case AUTH_TYPE_OPEN_SYSTEM:
1038 dwrq->flags = IW_ENCODE_OPEN;
1040 case AUTH_TYPE_SHARED_KEY:
1041 dwrq->flags = IW_ENCODE_RESTRICTED;
1045 memset(zeros, 0, sizeof(zeros));
1047 /* Which key do we want ? -1 -> tx index */
1048 if ((index < 0) || (index >= 4))
1049 index = priv->reg.wep_index;
1050 if (priv->reg.privacy_invoked) {
1051 dwrq->flags &= ~IW_ENCODE_DISABLED;
1052 /* dwrq->flags |= IW_ENCODE_NOKEY; */
1054 dwrq->flags |= index + 1;
1055 DPRINTK(2, "encoding flag = 0x%04X\n", dwrq->flags);
1056 /* Copy the key to the user buffer */
1057 if ((index >= 0) && (index < 4))
1058 dwrq->length = priv->reg.wep_key[index].size;
1059 if (dwrq->length > 16) {
1062 #if 1 /* IW_ENCODE_NOKEY; */
1064 if ((index >= 0) && (index < 4))
1065 memcpy(extra, priv->reg.wep_key[index].val,
1068 memcpy(extra, zeros, dwrq->length);
1073 #ifndef KSC_OPNOTSUPP
1074 /*------------------------------------------------------------------*/
1075 /* Wireless Handler : set Tx-Power */
1076 static int ks_wlan_set_txpow(struct net_device *dev,
1077 struct iw_request_info *info,
1078 struct iw_param *vwrq, char *extra)
1080 return -EOPNOTSUPP; /* Not Support */
1083 /*------------------------------------------------------------------*/
1084 /* Wireless Handler : get Tx-Power */
1085 static int ks_wlan_get_txpow(struct net_device *dev,
1086 struct iw_request_info *info,
1087 struct iw_param *vwrq, char *extra)
1089 if (priv->sleep_mode == SLP_SLEEP) {
1093 /* for SLEEP MODE */
1096 vwrq->disabled = (vwrq->value == 0);
1101 /*------------------------------------------------------------------*/
1102 /* Wireless Handler : set Retry limits */
1103 static int ks_wlan_set_retry(struct net_device *dev,
1104 struct iw_request_info *info,
1105 struct iw_param *vwrq, char *extra)
1107 return -EOPNOTSUPP; /* Not Support */
1110 /*------------------------------------------------------------------*/
1111 /* Wireless Handler : get Retry limits */
1112 static int ks_wlan_get_retry(struct net_device *dev,
1113 struct iw_request_info *info,
1114 struct iw_param *vwrq, char *extra)
1116 if (priv->sleep_mode == SLP_SLEEP) {
1120 /* for SLEEP MODE */
1123 vwrq->disabled = (vwrq->value == 0);
1127 #endif /* KSC_OPNOTSUPP */
1129 /*------------------------------------------------------------------*/
1130 /* Wireless Handler : get range info */
1131 static int ks_wlan_get_range(struct net_device *dev,
1132 struct iw_request_info *info,
1133 struct iw_point *dwrq, char *extra)
1135 struct ks_wlan_private *priv =
1136 (struct ks_wlan_private *)netdev_priv(dev);
1137 struct iw_range *range = (struct iw_range *)extra;
1142 if (priv->sleep_mode == SLP_SLEEP) {
1145 /* for SLEEP MODE */
1146 dwrq->length = sizeof(struct iw_range);
1147 memset(range, 0, sizeof(*range));
1148 range->min_nwid = 0x0000;
1149 range->max_nwid = 0x0000;
1150 range->num_channels = 14;
1151 /* Should be based on cap_rid.country to give only
1152 * what the current card support */
1154 for (i = 0; i < 13; i++) { /* channel 1 -- 13 */
1155 range->freq[k].i = i + 1; /* List index */
1156 range->freq[k].m = frequency_list[i] * 100000;
1157 range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
1159 range->num_frequency = k;
1160 if (priv->reg.phy_type == D_11B_ONLY_MODE || priv->reg.phy_type == D_11BG_COMPATIBLE_MODE) { /* channel 14 */
1161 range->freq[13].i = 14; /* List index */
1162 range->freq[13].m = frequency_list[13] * 100000;
1163 range->freq[13].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
1164 range->num_frequency = 14;
1167 /* Hum... Should put the right values there */
1168 range->max_qual.qual = 100;
1169 range->max_qual.level = 256 - 128; /* 0 dBm? */
1170 range->max_qual.noise = 256 - 128;
1171 range->sensitivity = 1;
1173 if (priv->reg.phy_type == D_11B_ONLY_MODE) {
1174 range->bitrate[0] = 1e6;
1175 range->bitrate[1] = 2e6;
1176 range->bitrate[2] = 5.5e6;
1177 range->bitrate[3] = 11e6;
1178 range->num_bitrates = 4;
1179 } else { /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
1180 range->bitrate[0] = 1e6;
1181 range->bitrate[1] = 2e6;
1182 range->bitrate[2] = 5.5e6;
1183 range->bitrate[3] = 11e6;
1185 range->bitrate[4] = 6e6;
1186 range->bitrate[5] = 9e6;
1187 range->bitrate[6] = 12e6;
1188 if (IW_MAX_BITRATES < 9) {
1189 range->bitrate[7] = 54e6;
1190 range->num_bitrates = 8;
1192 range->bitrate[7] = 18e6;
1193 range->bitrate[8] = 24e6;
1194 range->bitrate[9] = 36e6;
1195 range->bitrate[10] = 48e6;
1196 range->bitrate[11] = 54e6;
1198 range->num_bitrates = 12;
1202 /* Set an indication of the max TCP throughput
1203 * in bit/s that we can expect using this interface.
1204 * May be use for QoS stuff... Jean II */
1206 range->throughput = 5000 * 1000;
1208 range->throughput = 1500 * 1000;
1211 range->max_rts = 2347;
1212 range->min_frag = 256;
1213 range->max_frag = 2346;
1215 range->encoding_size[0] = 5; /* WEP: RC4 40 bits */
1216 range->encoding_size[1] = 13; /* WEP: RC4 ~128 bits */
1217 range->num_encoding_sizes = 2;
1218 range->max_encoding_tokens = 4;
1220 /* power management not support */
1221 range->pmp_flags = IW_POWER_ON;
1222 range->pmt_flags = IW_POWER_ON;
1225 /* Transmit Power - values are in dBm( or mW) */
1226 range->txpower[0] = -256;
1227 range->num_txpower = 1;
1228 range->txpower_capa = IW_TXPOW_DBM;
1229 /* range->txpower_capa = IW_TXPOW_MWATT; */
1231 range->we_version_source = 21;
1232 range->we_version_compiled = WIRELESS_EXT;
1234 range->retry_capa = IW_RETRY_ON;
1235 range->retry_flags = IW_RETRY_ON;
1236 range->r_time_flags = IW_RETRY_ON;
1238 /* Experimental measurements - boundary 11/5.5 Mb/s */
1239 /* Note : with or without the (local->rssi), results
1240 * are somewhat different. - Jean II */
1241 range->avg_qual.qual = 50;
1242 range->avg_qual.level = 186; /* -70 dBm */
1243 range->avg_qual.noise = 0;
1245 /* Event capability (kernel + driver) */
1246 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
1247 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
1248 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
1249 range->event_capa[1] = IW_EVENT_CAPA_K_1;
1250 range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVCUSTOM) |
1251 IW_EVENT_CAPA_MASK(IWEVMICHAELMICFAILURE));
1253 /* encode extension (WPA) capability */
1254 range->enc_capa = (IW_ENC_CAPA_WPA |
1256 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP);
1260 /*------------------------------------------------------------------*/
1261 /* Wireless Handler : set Power Management */
1262 static int ks_wlan_set_power(struct net_device *dev,
1263 struct iw_request_info *info,
1264 struct iw_param *vwrq, char *extra)
1266 struct ks_wlan_private *priv =
1267 (struct ks_wlan_private *)netdev_priv(dev);
1270 if (priv->sleep_mode == SLP_SLEEP) {
1273 /* for SLEEP MODE */
1274 enabled = vwrq->disabled ? 0 : 1;
1275 if (enabled == 0) { /* 0 */
1276 priv->reg.powermgt = POWMGT_ACTIVE_MODE;
1277 } else if (enabled) { /* 1 */
1278 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
1279 priv->reg.powermgt = POWMGT_SAVE1_MODE;
1282 } else if (enabled) { /* 2 */
1283 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
1284 priv->reg.powermgt = POWMGT_SAVE2_MODE;
1290 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
1295 /*------------------------------------------------------------------*/
1296 /* Wireless Handler : get Power Management */
1297 static int ks_wlan_get_power(struct net_device *dev,
1298 struct iw_request_info *info,
1299 struct iw_param *vwrq, char *extra)
1301 struct ks_wlan_private *priv =
1302 (struct ks_wlan_private *)netdev_priv(dev);
1304 if (priv->sleep_mode == SLP_SLEEP) {
1307 /* for SLEEP MODE */
1308 if (priv->reg.powermgt > 0)
1316 /*------------------------------------------------------------------*/
1317 /* Wireless Handler : get wirless statistics */
1318 static int ks_wlan_get_iwstats(struct net_device *dev,
1319 struct iw_request_info *info,
1320 struct iw_quality *vwrq, char *extra)
1322 struct ks_wlan_private *priv =
1323 (struct ks_wlan_private *)netdev_priv(dev);
1325 if (priv->sleep_mode == SLP_SLEEP) {
1328 /* for SLEEP MODE */
1329 vwrq->qual = 0; /* not supported */
1330 vwrq->level = priv->wstats.qual.level;
1331 vwrq->noise = 0; /* not supported */
1337 #ifndef KSC_OPNOTSUPP
1338 /*------------------------------------------------------------------*/
1339 /* Wireless Handler : set Sensitivity */
1340 static int ks_wlan_set_sens(struct net_device *dev,
1341 struct iw_request_info *info, struct iw_param *vwrq,
1344 return -EOPNOTSUPP; /* Not Support */
1347 /*------------------------------------------------------------------*/
1348 /* Wireless Handler : get Sensitivity */
1349 static int ks_wlan_get_sens(struct net_device *dev,
1350 struct iw_request_info *info, struct iw_param *vwrq,
1355 vwrq->disabled = (vwrq->value == 0);
1359 #endif /* KSC_OPNOTSUPP */
1361 /*------------------------------------------------------------------*/
1362 /* Wireless Handler : get AP List */
1363 /* Note : this is deprecated in favor of IWSCAN */
1364 static int ks_wlan_get_aplist(struct net_device *dev,
1365 struct iw_request_info *info,
1366 struct iw_point *dwrq, char *extra)
1368 struct ks_wlan_private *priv =
1369 (struct ks_wlan_private *)netdev_priv(dev);
1370 struct sockaddr *address = (struct sockaddr *)extra;
1371 struct iw_quality qual[LOCAL_APLIST_MAX];
1375 if (priv->sleep_mode == SLP_SLEEP) {
1378 /* for SLEEP MODE */
1379 for (i = 0; i < priv->aplist.size; i++) {
1380 memcpy(address[i].sa_data, &(priv->aplist.ap[i].bssid[0]),
1382 address[i].sa_family = ARPHRD_ETHER;
1383 qual[i].level = 256 - priv->aplist.ap[i].rssi;
1384 qual[i].qual = priv->aplist.ap[i].sq;
1385 qual[i].noise = 0; /* invalid noise value */
1386 qual[i].updated = 7;
1389 dwrq->flags = 1; /* Should be define'd */
1390 memcpy(extra + sizeof(struct sockaddr) * i,
1391 &qual, sizeof(struct iw_quality) * i);
1398 /*------------------------------------------------------------------*/
1399 /* Wireless Handler : Initiate Scan */
1400 static int ks_wlan_set_scan(struct net_device *dev,
1401 struct iw_request_info *info,
1402 union iwreq_data *wrqu, char *extra)
1404 struct ks_wlan_private *priv =
1405 (struct ks_wlan_private *)netdev_priv(dev);
1406 struct iw_scan_req *req = NULL;
1409 if (priv->sleep_mode == SLP_SLEEP) {
1413 /* for SLEEP MODE */
1414 /* specified SSID SCAN */
1415 if (wrqu->data.length == sizeof(struct iw_scan_req)
1416 && wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1417 req = (struct iw_scan_req *)extra;
1418 priv->scan_ssid_len = req->essid_len;
1419 memcpy(priv->scan_ssid, req->essid, priv->scan_ssid_len);
1421 priv->scan_ssid_len = 0;
1424 priv->sme_i.sme_flag |= SME_AP_SCAN;
1425 hostif_sme_enqueue(priv, SME_BSS_SCAN_REQUEST);
1427 /* At this point, just return to the user. */
1432 /*------------------------------------------------------------------*/
1434 * Translate scan data returned from the card to a card independent
1435 * format that the Wireless Tools will understand - Jean II
1437 static inline char *ks_wlan_translate_scan(struct net_device *dev,
1438 struct iw_request_info *info,
1439 char *current_ev, char *end_buf,
1440 struct local_ap_t *ap)
1442 /* struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; */
1443 struct iw_event iwe; /* Temporary buffer */
1445 char *current_val; /* For rates */
1447 static const char rsn_leader[] = "rsn_ie=";
1448 static const char wpa_leader[] = "wpa_ie=";
1449 char buf0[RSN_IE_BODY_MAX * 2 + 30];
1450 char buf1[RSN_IE_BODY_MAX * 2 + 30];
1452 /* First entry *MUST* be the AP MAC address */
1453 iwe.cmd = SIOCGIWAP;
1454 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1455 memcpy(iwe.u.ap_addr.sa_data, ap->bssid, ETH_ALEN);
1457 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1460 /* Other entries will be displayed in the order we give them */
1463 iwe.u.data.length = ap->ssid.size;
1464 if (iwe.u.data.length > 32)
1465 iwe.u.data.length = 32;
1466 iwe.cmd = SIOCGIWESSID;
1467 iwe.u.data.flags = 1;
1469 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1470 &(ap->ssid.body[0]));
1473 iwe.cmd = SIOCGIWMODE;
1474 capabilities = le16_to_cpu(ap->capability);
1475 if (capabilities & (BSS_CAP_ESS | BSS_CAP_IBSS)) {
1476 if (capabilities & BSS_CAP_ESS)
1477 iwe.u.mode = IW_MODE_INFRA;
1479 iwe.u.mode = IW_MODE_ADHOC;
1481 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1486 iwe.cmd = SIOCGIWFREQ;
1487 iwe.u.freq.m = ap->channel;
1488 iwe.u.freq.m = frequency_list[iwe.u.freq.m - 1] * 100000;
1491 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1494 /* Add quality statistics */
1496 iwe.u.qual.level = 256 - ap->rssi;
1497 iwe.u.qual.qual = ap->sq;
1498 iwe.u.qual.noise = 0; /* invalid noise value */
1500 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1503 /* Add encryption capability */
1504 iwe.cmd = SIOCGIWENCODE;
1505 if (capabilities & BSS_CAP_PRIVACY)
1506 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1508 iwe.u.data.flags = IW_ENCODE_DISABLED;
1509 iwe.u.data.length = 0;
1511 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1512 &(ap->ssid.body[0]));
1514 /* Rate : stuffing multiple values in a single event require a bit
1515 * more of magic - Jean II */
1516 current_val = current_ev + IW_EV_LCP_LEN;
1518 iwe.cmd = SIOCGIWRATE;
1519 /* Those two flags are ignored... */
1520 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
1523 for (i = 0; i < 16; i++) {
1524 /* NULL terminated */
1525 if (i >= ap->rate_set.size)
1527 /* Bit rate given in 500 kb/s units (+ 0x80) */
1528 iwe.u.bitrate.value = ((ap->rate_set.body[i] & 0x7f) * 500000);
1529 /* Add new value to event */
1531 iwe_stream_add_value(info, current_ev, current_val, end_buf,
1532 &iwe, IW_EV_PARAM_LEN);
1534 /* Check if we added any event */
1535 if ((current_val - current_ev) > IW_EV_LCP_LEN)
1536 current_ev = current_val;
1538 #define GENERIC_INFO_ELEM_ID 0xdd
1539 #define RSN_INFO_ELEM_ID 0x30
1540 if (ap->rsn_ie.id == RSN_INFO_ELEM_ID && ap->rsn_ie.size != 0) {
1542 memset(&iwe, 0, sizeof(iwe));
1543 iwe.cmd = IWEVCUSTOM;
1544 memcpy(buf0, rsn_leader, sizeof(rsn_leader) - 1);
1545 iwe.u.data.length += sizeof(rsn_leader) - 1;
1546 pbuf += sizeof(rsn_leader) - 1;
1548 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.id);
1549 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.size);
1550 iwe.u.data.length += 4;
1552 for (i = 0; i < ap->rsn_ie.size; i++)
1553 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.body[i]);
1554 iwe.u.data.length += (ap->rsn_ie.size) * 2;
1556 DPRINTK(4, "ap->rsn.size=%d\n", ap->rsn_ie.size);
1559 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1562 if (ap->wpa_ie.id == GENERIC_INFO_ELEM_ID && ap->wpa_ie.size != 0) {
1564 memset(&iwe, 0, sizeof(iwe));
1565 iwe.cmd = IWEVCUSTOM;
1566 memcpy(buf1, wpa_leader, sizeof(wpa_leader) - 1);
1567 iwe.u.data.length += sizeof(wpa_leader) - 1;
1568 pbuf += sizeof(wpa_leader) - 1;
1570 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.id);
1571 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.size);
1572 iwe.u.data.length += 4;
1574 for (i = 0; i < ap->wpa_ie.size; i++)
1575 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.body[i]);
1576 iwe.u.data.length += (ap->wpa_ie.size) * 2;
1578 DPRINTK(4, "ap->rsn.size=%d\n", ap->wpa_ie.size);
1579 DPRINTK(4, "iwe.u.data.length=%d\n", iwe.u.data.length);
1582 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1586 /* The other data in the scan result are not really
1587 * interesting, so for now drop it - Jean II */
1591 /*------------------------------------------------------------------*/
1592 /* Wireless Handler : Read Scan Results */
1593 static int ks_wlan_get_scan(struct net_device *dev,
1594 struct iw_request_info *info, struct iw_point *dwrq,
1597 struct ks_wlan_private *priv =
1598 (struct ks_wlan_private *)netdev_priv(dev);
1600 char *current_ev = extra;
1603 if (priv->sleep_mode == SLP_SLEEP) {
1606 /* for SLEEP MODE */
1607 if (priv->sme_i.sme_flag & SME_AP_SCAN) {
1608 DPRINTK(2, "flag AP_SCAN\n");
1612 if (priv->aplist.size == 0) {
1613 /* Client error, no scan results...
1614 * The caller need to restart the scan. */
1615 DPRINTK(2, "aplist 0\n");
1619 /* current connect ap */
1620 if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
1621 if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) {
1625 current_ev = ks_wlan_translate_scan(dev, current_ev,
1626 // extra + IW_SCAN_MAX_DATA,
1627 extra + dwrq->length,
1628 &(priv->current_ap));
1631 /* Read and parse all entries */
1632 for (i = 0; i < priv->aplist.size; i++) {
1633 if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) {
1637 /* Translate to WE format this entry */
1638 current_ev = ks_wlan_translate_scan(dev, info, current_ev,
1639 // extra + IW_SCAN_MAX_DATA,
1640 extra + dwrq->length,
1641 &(priv->aplist.ap[i]));
1643 /* Length of data */
1644 dwrq->length = (current_ev - extra);
1650 /*------------------------------------------------------------------*/
1651 /* Commit handler : called after a bunch of SET operations */
1652 static int ks_wlan_config_commit(struct net_device *dev,
1653 struct iw_request_info *info, void *zwrq,
1656 struct ks_wlan_private *priv =
1657 (struct ks_wlan_private *)netdev_priv(dev);
1659 if (!priv->need_commit)
1662 ks_wlan_setup_parameter(priv, priv->need_commit);
1663 priv->need_commit = 0;
1667 /*------------------------------------------------------------------*/
1668 /* Wireless handler : set association ie params */
1669 static int ks_wlan_set_genie(struct net_device *dev,
1670 struct iw_request_info *info,
1671 struct iw_point *dwrq, char *extra)
1673 struct ks_wlan_private *priv =
1674 (struct ks_wlan_private *)netdev_priv(dev);
1678 if (priv->sleep_mode == SLP_SLEEP) {
1681 /* for SLEEP MODE */
1683 // return -EOPNOTSUPP;
1686 /*------------------------------------------------------------------*/
1687 /* Wireless handler : set authentication mode params */
1688 static int ks_wlan_set_auth_mode(struct net_device *dev,
1689 struct iw_request_info *info,
1690 struct iw_param *vwrq, char *extra)
1692 struct ks_wlan_private *priv =
1693 (struct ks_wlan_private *)netdev_priv(dev);
1694 int index = (vwrq->flags & IW_AUTH_INDEX);
1695 int value = vwrq->value;
1697 DPRINTK(2, "index=%d:value=%08X\n", index, value);
1699 if (priv->sleep_mode == SLP_SLEEP) {
1702 /* for SLEEP MODE */
1704 case IW_AUTH_WPA_VERSION: /* 0 */
1706 case IW_AUTH_WPA_VERSION_DISABLED:
1707 priv->wpa.version = value;
1708 if (priv->wpa.rsn_enabled) {
1709 priv->wpa.rsn_enabled = 0;
1711 priv->need_commit |= SME_RSN;
1713 case IW_AUTH_WPA_VERSION_WPA:
1714 case IW_AUTH_WPA_VERSION_WPA2:
1715 priv->wpa.version = value;
1716 if (!(priv->wpa.rsn_enabled)) {
1717 priv->wpa.rsn_enabled = 1;
1719 priv->need_commit |= SME_RSN;
1725 case IW_AUTH_CIPHER_PAIRWISE: /* 1 */
1727 case IW_AUTH_CIPHER_NONE:
1728 if (priv->reg.privacy_invoked) {
1729 priv->reg.privacy_invoked = 0x00;
1730 priv->need_commit |= SME_WEP_FLAG;
1733 case IW_AUTH_CIPHER_WEP40:
1734 case IW_AUTH_CIPHER_TKIP:
1735 case IW_AUTH_CIPHER_CCMP:
1736 case IW_AUTH_CIPHER_WEP104:
1737 if (!priv->reg.privacy_invoked) {
1738 priv->reg.privacy_invoked = 0x01;
1739 priv->need_commit |= SME_WEP_FLAG;
1741 priv->wpa.pairwise_suite = value;
1742 priv->need_commit |= SME_RSN_UNICAST;
1748 case IW_AUTH_CIPHER_GROUP: /* 2 */
1750 case IW_AUTH_CIPHER_NONE:
1751 if (priv->reg.privacy_invoked) {
1752 priv->reg.privacy_invoked = 0x00;
1753 priv->need_commit |= SME_WEP_FLAG;
1756 case IW_AUTH_CIPHER_WEP40:
1757 case IW_AUTH_CIPHER_TKIP:
1758 case IW_AUTH_CIPHER_CCMP:
1759 case IW_AUTH_CIPHER_WEP104:
1760 if (!priv->reg.privacy_invoked) {
1761 priv->reg.privacy_invoked = 0x01;
1762 priv->need_commit |= SME_WEP_FLAG;
1764 priv->wpa.group_suite = value;
1765 priv->need_commit |= SME_RSN_MULTICAST;
1771 case IW_AUTH_KEY_MGMT: /* 3 */
1773 case IW_AUTH_KEY_MGMT_802_1X:
1774 case IW_AUTH_KEY_MGMT_PSK:
1775 case 0: /* NONE or 802_1X_NO_WPA */
1776 case 4: /* WPA_NONE */
1777 priv->wpa.key_mgmt_suite = value;
1778 priv->need_commit |= SME_RSN_AUTH;
1784 case IW_AUTH_80211_AUTH_ALG: /* 6 */
1786 case IW_AUTH_ALG_OPEN_SYSTEM:
1787 priv->wpa.auth_alg = value;
1788 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
1790 case IW_AUTH_ALG_SHARED_KEY:
1791 priv->wpa.auth_alg = value;
1792 priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
1794 case IW_AUTH_ALG_LEAP:
1798 priv->need_commit |= SME_MODE_SET;
1800 case IW_AUTH_WPA_ENABLED: /* 7 */
1801 priv->wpa.wpa_enabled = value;
1803 case IW_AUTH_PRIVACY_INVOKED: /* 10 */
1804 if ((value && !priv->reg.privacy_invoked) ||
1805 (!value && priv->reg.privacy_invoked)) {
1806 priv->reg.privacy_invoked = value ? 0x01 : 0x00;
1807 priv->need_commit |= SME_WEP_FLAG;
1810 case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* 4 */
1811 case IW_AUTH_TKIP_COUNTERMEASURES: /* 5 */
1812 case IW_AUTH_DROP_UNENCRYPTED: /* 8 */
1813 case IW_AUTH_ROAMING_CONTROL: /* 9 */
1818 /* return -EINPROGRESS; */
1819 if (priv->need_commit) {
1820 ks_wlan_setup_parameter(priv, priv->need_commit);
1821 priv->need_commit = 0;
1826 /*------------------------------------------------------------------*/
1827 /* Wireless handler : get authentication mode params */
1828 static int ks_wlan_get_auth_mode(struct net_device *dev,
1829 struct iw_request_info *info,
1830 struct iw_param *vwrq, char *extra)
1832 struct ks_wlan_private *priv =
1833 (struct ks_wlan_private *)netdev_priv(dev);
1834 int index = (vwrq->flags & IW_AUTH_INDEX);
1835 DPRINTK(2, "index=%d\n", index);
1837 if (priv->sleep_mode == SLP_SLEEP) {
1841 /* for SLEEP MODE */
1842 /* WPA (not used ?? wpa_supplicant) */
1844 case IW_AUTH_WPA_VERSION:
1845 vwrq->value = priv->wpa.version;
1847 case IW_AUTH_CIPHER_PAIRWISE:
1848 vwrq->value = priv->wpa.pairwise_suite;
1850 case IW_AUTH_CIPHER_GROUP:
1851 vwrq->value = priv->wpa.group_suite;
1853 case IW_AUTH_KEY_MGMT:
1854 vwrq->value = priv->wpa.key_mgmt_suite;
1856 case IW_AUTH_80211_AUTH_ALG:
1857 vwrq->value = priv->wpa.auth_alg;
1859 case IW_AUTH_WPA_ENABLED:
1860 vwrq->value = priv->wpa.rsn_enabled;
1862 case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* OK??? */
1863 case IW_AUTH_TKIP_COUNTERMEASURES:
1864 case IW_AUTH_DROP_UNENCRYPTED:
1866 /* return -EOPNOTSUPP; */
1872 /*------------------------------------------------------------------*/
1873 /* Wireless Handler : set encoding token & mode (WPA)*/
1874 static int ks_wlan_set_encode_ext(struct net_device *dev,
1875 struct iw_request_info *info,
1876 struct iw_point *dwrq, char *extra)
1878 struct ks_wlan_private *priv =
1879 (struct ks_wlan_private *)netdev_priv(dev);
1880 struct iw_encode_ext *enc;
1881 int index = dwrq->flags & IW_ENCODE_INDEX;
1882 unsigned int commit = 0;
1884 enc = (struct iw_encode_ext *)extra;
1886 DPRINTK(2, "flags=%04X:: ext_flags=%08X\n", dwrq->flags,
1889 if (priv->sleep_mode == SLP_SLEEP) {
1892 /* for SLEEP MODE */
1893 if (index < 1 || index > 4)
1898 if (dwrq->flags & IW_ENCODE_DISABLED) {
1899 priv->wpa.key[index].key_len = 0;
1903 priv->wpa.key[index].ext_flags = enc->ext_flags;
1904 if (enc->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
1905 priv->wpa.txkey = index;
1906 commit |= SME_WEP_INDEX;
1907 } else if (enc->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
1908 memcpy(&priv->wpa.key[index].rx_seq[0],
1909 enc->rx_seq, IW_ENCODE_SEQ_MAX_SIZE);
1912 memcpy(&priv->wpa.key[index].addr.sa_data[0],
1913 &enc->addr.sa_data[0], ETH_ALEN);
1916 case IW_ENCODE_ALG_NONE:
1917 if (priv->reg.privacy_invoked) {
1918 priv->reg.privacy_invoked = 0x00;
1919 commit |= SME_WEP_FLAG;
1921 priv->wpa.key[index].key_len = 0;
1924 case IW_ENCODE_ALG_WEP:
1925 case IW_ENCODE_ALG_CCMP:
1926 if (!priv->reg.privacy_invoked) {
1927 priv->reg.privacy_invoked = 0x01;
1928 commit |= SME_WEP_FLAG;
1931 memcpy(&priv->wpa.key[index].key_val[0],
1932 &enc->key[0], enc->key_len);
1933 priv->wpa.key[index].key_len = enc->key_len;
1934 commit |= (SME_WEP_VAL1 << index);
1937 case IW_ENCODE_ALG_TKIP:
1938 if (!priv->reg.privacy_invoked) {
1939 priv->reg.privacy_invoked = 0x01;
1940 commit |= SME_WEP_FLAG;
1942 if (enc->key_len == 32) {
1943 memcpy(&priv->wpa.key[index].key_val[0],
1944 &enc->key[0], enc->key_len - 16);
1945 priv->wpa.key[index].key_len =
1947 if (priv->wpa.key_mgmt_suite == 4) { /* WPA_NONE */
1948 memcpy(&priv->wpa.key[index].
1949 tx_mic_key[0], &enc->key[16], 8);
1950 memcpy(&priv->wpa.key[index].
1951 rx_mic_key[0], &enc->key[16], 8);
1953 memcpy(&priv->wpa.key[index].
1954 tx_mic_key[0], &enc->key[16], 8);
1955 memcpy(&priv->wpa.key[index].
1956 rx_mic_key[0], &enc->key[24], 8);
1958 commit |= (SME_WEP_VAL1 << index);
1964 priv->wpa.key[index].alg = enc->alg;
1969 if (commit & SME_WEP_INDEX)
1970 hostif_sme_enqueue(priv, SME_SET_TXKEY);
1971 if (commit & SME_WEP_VAL_MASK)
1972 hostif_sme_enqueue(priv, SME_SET_KEY1 + index);
1973 if (commit & SME_WEP_FLAG)
1974 hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
1980 /*------------------------------------------------------------------*/
1981 /* Wireless Handler : get encoding token & mode (WPA)*/
1982 static int ks_wlan_get_encode_ext(struct net_device *dev,
1983 struct iw_request_info *info,
1984 struct iw_point *dwrq, char *extra)
1986 struct ks_wlan_private *priv =
1987 (struct ks_wlan_private *)netdev_priv(dev);
1989 if (priv->sleep_mode == SLP_SLEEP) {
1993 /* for SLEEP MODE */
1994 /* WPA (not used ?? wpa_supplicant)
1995 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
1996 struct iw_encode_ext *enc;
1997 enc = (struct iw_encode_ext *)extra;
1998 int index = dwrq->flags & IW_ENCODE_INDEX;
1999 WPA (not used ?? wpa_supplicant) */
2003 /*------------------------------------------------------------------*/
2004 /* Wireless Handler : PMKSA cache operation (WPA2) */
2005 static int ks_wlan_set_pmksa(struct net_device *dev,
2006 struct iw_request_info *info,
2007 struct iw_point *dwrq, char *extra)
2009 struct ks_wlan_private *priv =
2010 (struct ks_wlan_private *)netdev_priv(dev);
2011 struct iw_pmksa *pmksa;
2014 struct list_head *ptr;
2018 if (priv->sleep_mode == SLP_SLEEP) {
2021 /* for SLEEP MODE */
2025 pmksa = (struct iw_pmksa *)extra;
2026 DPRINTK(2, "cmd=%d\n", pmksa->cmd);
2028 switch (pmksa->cmd) {
2030 if (list_empty(&priv->pmklist.head)) { /* new list */
2031 for (i = 0; i < PMK_LIST_MAX; i++) {
2032 pmk = &priv->pmklist.pmk[i];
2034 ("\x00\x00\x00\x00\x00\x00", pmk->bssid,
2038 memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
2039 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
2040 list_add(&pmk->list, &priv->pmklist.head);
2041 priv->pmklist.size++;
2042 } else { /* search cache data */
2043 list_for_each(ptr, &priv->pmklist.head) {
2044 pmk = list_entry(ptr, struct pmk_t, list);
2045 if (!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)) { /* match address! list move to head. */
2046 memcpy(pmk->pmkid, pmksa->pmkid,
2048 list_move(&pmk->list,
2049 &priv->pmklist.head);
2053 if (ptr == &priv->pmklist.head) { /* not find address. */
2054 if (PMK_LIST_MAX > priv->pmklist.size) { /* new cache data */
2055 for (i = 0; i < PMK_LIST_MAX; i++) {
2056 pmk = &priv->pmklist.pmk[i];
2058 ("\x00\x00\x00\x00\x00\x00",
2059 pmk->bssid, ETH_ALEN))
2062 memcpy(pmk->bssid, pmksa->bssid.sa_data,
2064 memcpy(pmk->pmkid, pmksa->pmkid,
2066 list_add(&pmk->list,
2067 &priv->pmklist.head);
2068 priv->pmklist.size++;
2069 } else { /* overwrite old cache data */
2071 list_entry(priv->pmklist.head.prev,
2072 struct pmk_t, list);
2073 memcpy(pmk->bssid, pmksa->bssid.sa_data,
2075 memcpy(pmk->pmkid, pmksa->pmkid,
2077 list_move(&pmk->list,
2078 &priv->pmklist.head);
2083 case IW_PMKSA_REMOVE:
2084 if (list_empty(&priv->pmklist.head)) { /* list empty */
2086 } else { /* search cache data */
2087 list_for_each(ptr, &priv->pmklist.head) {
2088 pmk = list_entry(ptr, struct pmk_t, list);
2089 if (!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)) { /* match address! list del. */
2090 eth_zero_addr(pmk->bssid);
2091 memset(pmk->pmkid, 0, IW_PMKID_LEN);
2092 list_del_init(&pmk->list);
2096 if (ptr == &priv->pmklist.head) { /* not find address. */
2101 case IW_PMKSA_FLUSH:
2102 memset(&(priv->pmklist), 0, sizeof(priv->pmklist));
2103 INIT_LIST_HEAD(&priv->pmklist.head);
2104 for (i = 0; i < PMK_LIST_MAX; i++)
2105 INIT_LIST_HEAD(&priv->pmklist.pmk[i].list);
2111 hostif_sme_enqueue(priv, SME_SET_PMKSA);
2115 static struct iw_statistics *ks_get_wireless_stats(struct net_device *dev)
2118 struct ks_wlan_private *priv =
2119 (struct ks_wlan_private *)netdev_priv(dev);
2120 struct iw_statistics *wstats = &priv->wstats;
2122 if (!atomic_read(&update_phyinfo)) {
2123 if (priv->dev_state < DEVICE_STATE_READY)
2124 return NULL; /* not finished initialize */
2129 /* Packets discarded in the wireless adapter due to wireless
2130 * specific problems */
2131 wstats->discard.nwid = 0; /* Rx invalid nwid */
2132 wstats->discard.code = 0; /* Rx invalid crypt */
2133 wstats->discard.fragment = 0; /* Rx invalid frag */
2134 wstats->discard.retries = 0; /* Tx excessive retries */
2135 wstats->discard.misc = 0; /* Invalid misc */
2136 wstats->miss.beacon = 0; /* Missed beacon */
2141 /*------------------------------------------------------------------*/
2142 /* Private handler : set stop request */
2143 static int ks_wlan_set_stop_request(struct net_device *dev,
2144 struct iw_request_info *info, __u32 * uwrq,
2147 struct ks_wlan_private *priv =
2148 (struct ks_wlan_private *)netdev_priv(dev);
2151 if (priv->sleep_mode == SLP_SLEEP) {
2154 /* for SLEEP MODE */
2158 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2162 /*------------------------------------------------------------------*/
2163 /* Wireless Handler : set MLME */
2164 #include <linux/ieee80211.h>
2165 static int ks_wlan_set_mlme(struct net_device *dev,
2166 struct iw_request_info *info, struct iw_point *dwrq,
2169 struct ks_wlan_private *priv =
2170 (struct ks_wlan_private *)netdev_priv(dev);
2171 struct iw_mlme *mlme = (struct iw_mlme *)extra;
2174 DPRINTK(2, ":%d :%d\n", mlme->cmd, mlme->reason_code);
2176 if (priv->sleep_mode == SLP_SLEEP) {
2179 /* for SLEEP MODE */
2180 switch (mlme->cmd) {
2181 case IW_MLME_DEAUTH:
2182 if (mlme->reason_code == WLAN_REASON_MIC_FAILURE) {
2185 case IW_MLME_DISASSOC:
2187 return ks_wlan_set_stop_request(dev, NULL, &mode, NULL);
2189 return -EOPNOTSUPP; /* Not Support */
2193 /*------------------------------------------------------------------*/
2194 /* Private handler : get firemware version */
2195 static int ks_wlan_get_firmware_version(struct net_device *dev,
2196 struct iw_request_info *info,
2197 struct iw_point *dwrq, char *extra)
2199 struct ks_wlan_private *priv =
2200 (struct ks_wlan_private *)netdev_priv(dev);
2201 strcpy(extra, &(priv->firmware_version[0]));
2202 dwrq->length = priv->version_size + 1;
2207 /*------------------------------------------------------------------*/
2208 /* Private handler : set force disconnect status */
2209 static int ks_wlan_set_detach(struct net_device *dev,
2210 struct iw_request_info *info, __u32 * uwrq,
2213 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2215 if (priv->sleep_mode == SLP_SLEEP) {
2218 /* for SLEEP MODE */
2219 if (*uwrq == CONNECT_STATUS) { /* 0 */
2220 priv->connect_status &= ~FORCE_DISCONNECT;
2221 if ((priv->connect_status & CONNECT_STATUS_MASK) ==
2223 netif_carrier_on(dev);
2224 } else if (*uwrq == DISCONNECT_STATUS) { /* 1 */
2225 priv->connect_status |= FORCE_DISCONNECT;
2226 netif_carrier_off(dev);
2232 /*------------------------------------------------------------------*/
2233 /* Private handler : get force disconnect status */
2234 static int ks_wlan_get_detach(struct net_device *dev,
2235 struct iw_request_info *info, __u32 * uwrq,
2238 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2240 if (priv->sleep_mode == SLP_SLEEP) {
2243 /* for SLEEP MODE */
2244 *uwrq = ((priv->connect_status & FORCE_DISCONNECT) ? 1 : 0);
2248 /*------------------------------------------------------------------*/
2249 /* Private handler : get connect status */
2250 static int ks_wlan_get_connect(struct net_device *dev,
2251 struct iw_request_info *info, __u32 * uwrq,
2254 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2256 if (priv->sleep_mode == SLP_SLEEP) {
2259 /* for SLEEP MODE */
2260 *uwrq = (priv->connect_status & CONNECT_STATUS_MASK);
2265 /*------------------------------------------------------------------*/
2266 /* Private handler : set preamble */
2267 static int ks_wlan_set_preamble(struct net_device *dev,
2268 struct iw_request_info *info, __u32 * uwrq,
2271 struct ks_wlan_private *priv =
2272 (struct ks_wlan_private *)netdev_priv(dev);
2274 if (priv->sleep_mode == SLP_SLEEP) {
2277 /* for SLEEP MODE */
2278 if (*uwrq == LONG_PREAMBLE) { /* 0 */
2279 priv->reg.preamble = LONG_PREAMBLE;
2280 } else if (*uwrq == SHORT_PREAMBLE) { /* 1 */
2281 priv->reg.preamble = SHORT_PREAMBLE;
2285 priv->need_commit |= SME_MODE_SET;
2286 return -EINPROGRESS; /* Call commit handler */
2290 /*------------------------------------------------------------------*/
2291 /* Private handler : get preamble */
2292 static int ks_wlan_get_preamble(struct net_device *dev,
2293 struct iw_request_info *info, __u32 * uwrq,
2296 struct ks_wlan_private *priv =
2297 (struct ks_wlan_private *)netdev_priv(dev);
2299 if (priv->sleep_mode == SLP_SLEEP) {
2302 /* for SLEEP MODE */
2303 *uwrq = priv->reg.preamble;
2307 /*------------------------------------------------------------------*/
2308 /* Private handler : set power save mode */
2309 static int ks_wlan_set_powermgt(struct net_device *dev,
2310 struct iw_request_info *info, __u32 * uwrq,
2313 struct ks_wlan_private *priv =
2314 (struct ks_wlan_private *)netdev_priv(dev);
2316 if (priv->sleep_mode == SLP_SLEEP) {
2319 /* for SLEEP MODE */
2320 if (*uwrq == POWMGT_ACTIVE_MODE) { /* 0 */
2321 priv->reg.powermgt = POWMGT_ACTIVE_MODE;
2322 } else if (*uwrq == POWMGT_SAVE1_MODE) { /* 1 */
2323 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2324 priv->reg.powermgt = POWMGT_SAVE1_MODE;
2327 } else if (*uwrq == POWMGT_SAVE2_MODE) { /* 2 */
2328 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2329 priv->reg.powermgt = POWMGT_SAVE2_MODE;
2335 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
2340 /*------------------------------------------------------------------*/
2341 /* Private handler : get power save made */
2342 static int ks_wlan_get_powermgt(struct net_device *dev,
2343 struct iw_request_info *info, __u32 * uwrq,
2346 struct ks_wlan_private *priv =
2347 (struct ks_wlan_private *)netdev_priv(dev);
2349 if (priv->sleep_mode == SLP_SLEEP) {
2352 /* for SLEEP MODE */
2353 *uwrq = priv->reg.powermgt;
2357 /*------------------------------------------------------------------*/
2358 /* Private handler : set scan type */
2359 static int ks_wlan_set_scan_type(struct net_device *dev,
2360 struct iw_request_info *info, __u32 * uwrq,
2363 struct ks_wlan_private *priv =
2364 (struct ks_wlan_private *)netdev_priv(dev);
2366 if (priv->sleep_mode == SLP_SLEEP) {
2369 /* for SLEEP MODE */
2370 if (*uwrq == ACTIVE_SCAN) { /* 0 */
2371 priv->reg.scan_type = ACTIVE_SCAN;
2372 } else if (*uwrq == PASSIVE_SCAN) { /* 1 */
2373 priv->reg.scan_type = PASSIVE_SCAN;
2380 /*------------------------------------------------------------------*/
2381 /* Private handler : get scan type */
2382 static int ks_wlan_get_scan_type(struct net_device *dev,
2383 struct iw_request_info *info, __u32 * uwrq,
2386 struct ks_wlan_private *priv =
2387 (struct ks_wlan_private *)netdev_priv(dev);
2389 if (priv->sleep_mode == SLP_SLEEP) {
2392 /* for SLEEP MODE */
2393 *uwrq = priv->reg.scan_type;
2398 /*------------------------------------------------------------------*/
2399 /* Private handler : write raw data to device */
2400 static int ks_wlan_data_write(struct net_device *dev,
2401 struct iw_request_info *info,
2402 struct iw_point *dwrq, char *extra)
2404 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2405 unsigned char *wbuff = NULL;
2407 if (priv->sleep_mode == SLP_SLEEP) {
2410 /* for SLEEP MODE */
2411 wbuff = (unsigned char *)kmalloc(dwrq->length, GFP_ATOMIC);
2414 memcpy(wbuff, extra, dwrq->length);
2416 /* write to device */
2417 ks_wlan_hw_tx(priv, wbuff, dwrq->length, NULL, NULL, NULL);
2422 /*------------------------------------------------------------------*/
2423 /* Private handler : read raw data form device */
2424 static int ks_wlan_data_read(struct net_device *dev,
2425 struct iw_request_info *info,
2426 struct iw_point *dwrq, char *extra)
2428 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2429 unsigned short read_length;
2431 if (priv->sleep_mode == SLP_SLEEP) {
2434 /* for SLEEP MODE */
2435 if (!atomic_read(&priv->event_count)) {
2436 if (priv->dev_state < DEVICE_STATE_BOOT) { /* Remove device */
2438 memset(extra, 0xff, read_length);
2439 dwrq->length = read_length;
2443 memset(extra, 0, 1);
2448 if (atomic_read(&priv->event_count) > 0)
2449 atomic_dec(&priv->event_count);
2451 spin_lock(&priv->dev_read_lock); /* request spin lock */
2453 /* Copy length max size 0x07ff */
2454 if (priv->dev_size[priv->dev_count] > 2047)
2457 read_length = priv->dev_size[priv->dev_count];
2460 memcpy(extra, &(priv->dev_data[priv->dev_count][0]), read_length);
2462 spin_unlock(&priv->dev_read_lock); /* release spin lock */
2465 priv->dev_data[priv->dev_count] = 0;
2466 priv->dev_size[priv->dev_count] = 0;
2469 if (priv->dev_count == DEVICE_STOCK_COUNT)
2470 priv->dev_count = 0;
2473 dwrq->length = read_length;
2480 /*------------------------------------------------------------------*/
2481 /* Private handler : get wep string */
2482 #define WEP_ASCII_BUFF_SIZE (17+64*4+1)
2483 static int ks_wlan_get_wep_ascii(struct net_device *dev,
2484 struct iw_request_info *info,
2485 struct iw_point *dwrq, char *extra)
2487 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2489 char tmp[WEP_ASCII_BUFF_SIZE];
2491 if (priv->sleep_mode == SLP_SLEEP) {
2494 /* for SLEEP MODE */
2495 strcpy(tmp, " WEP keys ASCII \n");
2496 len += strlen(" WEP keys ASCII \n");
2498 for (i = 0; i < 4; i++) {
2499 strcpy(tmp + len, "\t[");
2500 len += strlen("\t[");
2503 strcpy(tmp + len, "] ");
2504 len += strlen("] ");
2505 if (priv->reg.wep_key[i].size) {
2507 (priv->reg.wep_key[i].size <
2508 6 ? "(40bits) [" : "(104bits) ["));
2510 strlen((priv->reg.wep_key[i].size <
2511 6 ? "(40bits) [" : "(104bits) ["));
2512 for (j = 0; j < priv->reg.wep_key[i].size; j++, len++)
2514 (isprint(priv->reg.wep_key[i].val[j]) ?
2515 priv->reg.wep_key[i].val[j] : ' ');
2517 strcpy(tmp + len, "]\n");
2518 len += strlen("]\n");
2520 strcpy(tmp + len, "off\n");
2521 len += strlen("off\n");
2525 memcpy(extra, tmp, len);
2526 dwrq->length = len + 1;
2531 /*------------------------------------------------------------------*/
2532 /* Private handler : set beacon lost count */
2533 static int ks_wlan_set_beacon_lost(struct net_device *dev,
2534 struct iw_request_info *info, __u32 * uwrq,
2537 struct ks_wlan_private *priv =
2538 (struct ks_wlan_private *)netdev_priv(dev);
2540 if (priv->sleep_mode == SLP_SLEEP) {
2543 /* for SLEEP MODE */
2544 if (*uwrq >= BEACON_LOST_COUNT_MIN && *uwrq <= BEACON_LOST_COUNT_MAX) {
2545 priv->reg.beacon_lost_count = *uwrq;
2549 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
2550 priv->need_commit |= SME_MODE_SET;
2551 return -EINPROGRESS; /* Call commit handler */
2556 /*------------------------------------------------------------------*/
2557 /* Private handler : get beacon lost count */
2558 static int ks_wlan_get_beacon_lost(struct net_device *dev,
2559 struct iw_request_info *info, __u32 * uwrq,
2562 struct ks_wlan_private *priv =
2563 (struct ks_wlan_private *)netdev_priv(dev);
2565 if (priv->sleep_mode == SLP_SLEEP) {
2568 /* for SLEEP MODE */
2569 *uwrq = priv->reg.beacon_lost_count;
2573 /*------------------------------------------------------------------*/
2574 /* Private handler : set phy type */
2575 static int ks_wlan_set_phy_type(struct net_device *dev,
2576 struct iw_request_info *info, __u32 * uwrq,
2579 struct ks_wlan_private *priv =
2580 (struct ks_wlan_private *)netdev_priv(dev);
2582 if (priv->sleep_mode == SLP_SLEEP) {
2585 /* for SLEEP MODE */
2586 if (*uwrq == D_11B_ONLY_MODE) { /* 0 */
2587 priv->reg.phy_type = D_11B_ONLY_MODE;
2588 } else if (*uwrq == D_11G_ONLY_MODE) { /* 1 */
2589 priv->reg.phy_type = D_11G_ONLY_MODE;
2590 } else if (*uwrq == D_11BG_COMPATIBLE_MODE) { /* 2 */
2591 priv->reg.phy_type = D_11BG_COMPATIBLE_MODE;
2595 priv->need_commit |= SME_MODE_SET;
2596 return -EINPROGRESS; /* Call commit handler */
2599 /*------------------------------------------------------------------*/
2600 /* Private handler : get phy type */
2601 static int ks_wlan_get_phy_type(struct net_device *dev,
2602 struct iw_request_info *info, __u32 * uwrq,
2605 struct ks_wlan_private *priv =
2606 (struct ks_wlan_private *)netdev_priv(dev);
2608 if (priv->sleep_mode == SLP_SLEEP) {
2611 /* for SLEEP MODE */
2612 *uwrq = priv->reg.phy_type;
2616 /*------------------------------------------------------------------*/
2617 /* Private handler : set cts mode */
2618 static int ks_wlan_set_cts_mode(struct net_device *dev,
2619 struct iw_request_info *info, __u32 * uwrq,
2622 struct ks_wlan_private *priv =
2623 (struct ks_wlan_private *)netdev_priv(dev);
2625 if (priv->sleep_mode == SLP_SLEEP) {
2628 /* for SLEEP MODE */
2629 if (*uwrq == CTS_MODE_FALSE) { /* 0 */
2630 priv->reg.cts_mode = CTS_MODE_FALSE;
2631 } else if (*uwrq == CTS_MODE_TRUE) { /* 1 */
2632 if (priv->reg.phy_type == D_11G_ONLY_MODE ||
2633 priv->reg.phy_type == D_11BG_COMPATIBLE_MODE)
2634 priv->reg.cts_mode = CTS_MODE_TRUE;
2636 priv->reg.cts_mode = CTS_MODE_FALSE;
2640 priv->need_commit |= SME_MODE_SET;
2641 return -EINPROGRESS; /* Call commit handler */
2644 /*------------------------------------------------------------------*/
2645 /* Private handler : get cts mode */
2646 static int ks_wlan_get_cts_mode(struct net_device *dev,
2647 struct iw_request_info *info, __u32 * uwrq,
2650 struct ks_wlan_private *priv =
2651 (struct ks_wlan_private *)netdev_priv(dev);
2653 if (priv->sleep_mode == SLP_SLEEP) {
2656 /* for SLEEP MODE */
2657 *uwrq = priv->reg.cts_mode;
2661 /*------------------------------------------------------------------*/
2662 /* Private handler : set sleep mode */
2663 static int ks_wlan_set_sleep_mode(struct net_device *dev,
2664 struct iw_request_info *info,
2665 __u32 * uwrq, char *extra)
2667 struct ks_wlan_private *priv =
2668 (struct ks_wlan_private *)netdev_priv(dev);
2672 if (*uwrq == SLP_SLEEP) {
2673 priv->sleep_mode = *uwrq;
2674 netdev_info(dev, "SET_SLEEP_MODE %d\n", priv->sleep_mode);
2676 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2677 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2679 } else if (*uwrq == SLP_ACTIVE) {
2680 priv->sleep_mode = *uwrq;
2681 netdev_info(dev, "SET_SLEEP_MODE %d\n", priv->sleep_mode);
2682 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2684 netdev_err(dev, "SET_SLEEP_MODE %d errror\n", *uwrq);
2691 /*------------------------------------------------------------------*/
2692 /* Private handler : get sleep mode */
2693 static int ks_wlan_get_sleep_mode(struct net_device *dev,
2694 struct iw_request_info *info,
2695 __u32 * uwrq, char *extra)
2697 struct ks_wlan_private *priv =
2698 (struct ks_wlan_private *)netdev_priv(dev);
2700 DPRINTK(2, "GET_SLEEP_MODE %d\n", priv->sleep_mode);
2701 *uwrq = priv->sleep_mode;
2707 /*------------------------------------------------------------------*/
2708 /* Private handler : set phy information timer */
2709 static int ks_wlan_set_phy_information_timer(struct net_device *dev,
2710 struct iw_request_info *info,
2711 __u32 * uwrq, char *extra)
2713 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2715 if (priv->sleep_mode == SLP_SLEEP) {
2718 /* for SLEEP MODE */
2719 if (*uwrq >= 0 && *uwrq <= 0xFFFF) /* 0-65535 */
2720 priv->reg.phy_info_timer = (uint16_t) * uwrq;
2724 hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST);
2729 /*------------------------------------------------------------------*/
2730 /* Private handler : get phy information timer */
2731 static int ks_wlan_get_phy_information_timer(struct net_device *dev,
2732 struct iw_request_info *info,
2733 __u32 * uwrq, char *extra)
2735 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2737 if (priv->sleep_mode == SLP_SLEEP) {
2740 /* for SLEEP MODE */
2741 *uwrq = priv->reg.phy_info_timer;
2747 /*------------------------------------------------------------------*/
2748 /* Private handler : set WPS enable */
2749 static int ks_wlan_set_wps_enable(struct net_device *dev,
2750 struct iw_request_info *info, __u32 * uwrq,
2753 struct ks_wlan_private *priv =
2754 (struct ks_wlan_private *)netdev_priv(dev);
2757 if (priv->sleep_mode == SLP_SLEEP) {
2760 /* for SLEEP MODE */
2761 if (*uwrq == 0 || *uwrq == 1)
2762 priv->wps.wps_enabled = *uwrq;
2766 hostif_sme_enqueue(priv, SME_WPS_ENABLE_REQUEST);
2771 /*------------------------------------------------------------------*/
2772 /* Private handler : get WPS enable */
2773 static int ks_wlan_get_wps_enable(struct net_device *dev,
2774 struct iw_request_info *info, __u32 * uwrq,
2777 struct ks_wlan_private *priv =
2778 (struct ks_wlan_private *)netdev_priv(dev);
2781 if (priv->sleep_mode == SLP_SLEEP) {
2784 /* for SLEEP MODE */
2785 *uwrq = priv->wps.wps_enabled;
2786 netdev_info(dev, "return=%d\n", *uwrq);
2791 /*------------------------------------------------------------------*/
2792 /* Private handler : set WPS probe req */
2793 static int ks_wlan_set_wps_probe_req(struct net_device *dev,
2794 struct iw_request_info *info,
2795 struct iw_point *dwrq, char *extra)
2799 struct ks_wlan_private *priv =
2800 (struct ks_wlan_private *)netdev_priv(dev);
2804 if (priv->sleep_mode == SLP_SLEEP) {
2807 /* for SLEEP MODE */
2808 DPRINTK(2, "dwrq->length=%d\n", dwrq->length);
2811 if (p[1] + 2 != dwrq->length || dwrq->length > 256) {
2815 priv->wps.ielen = p[1] + 2 + 1; /* IE header + IE + sizeof(len) */
2816 len = p[1] + 2; /* IE header + IE */
2818 memcpy(priv->wps.ie, &len, sizeof(len));
2819 p = memcpy(priv->wps.ie + 1, p, len);
2821 DPRINTK(2, "%d(%#x): %02X %02X %02X %02X ... %02X %02X %02X\n",
2822 priv->wps.ielen, priv->wps.ielen, p[0], p[1], p[2], p[3],
2823 p[priv->wps.ielen - 3], p[priv->wps.ielen - 2],
2824 p[priv->wps.ielen - 1]);
2826 hostif_sme_enqueue(priv, SME_WPS_PROBE_REQUEST);
2832 /*------------------------------------------------------------------*/
2833 /* Private handler : get WPS probe req */
2834 static int ks_wlan_get_wps_probe_req(struct net_device *dev,
2835 struct iw_request_info *info,
2836 __u32 * uwrq, char *extra)
2838 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2841 if (priv->sleep_mode == SLP_SLEEP) {
2844 /* for SLEEP MODE */
2850 /*------------------------------------------------------------------*/
2851 /* Private handler : set tx gain control value */
2852 static int ks_wlan_set_tx_gain(struct net_device *dev,
2853 struct iw_request_info *info, __u32 * uwrq,
2856 struct ks_wlan_private *priv =
2857 (struct ks_wlan_private *)netdev_priv(dev);
2859 if (priv->sleep_mode == SLP_SLEEP) {
2862 /* for SLEEP MODE */
2863 if (*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2864 priv->gain.TxGain = (uint8_t) * uwrq;
2868 if (priv->gain.TxGain < 0xFF)
2869 priv->gain.TxMode = 1;
2871 priv->gain.TxMode = 0;
2873 hostif_sme_enqueue(priv, SME_SET_GAIN);
2877 /*------------------------------------------------------------------*/
2878 /* Private handler : get tx gain control value */
2879 static int ks_wlan_get_tx_gain(struct net_device *dev,
2880 struct iw_request_info *info, __u32 * uwrq,
2883 struct ks_wlan_private *priv =
2884 (struct ks_wlan_private *)netdev_priv(dev);
2886 if (priv->sleep_mode == SLP_SLEEP) {
2889 /* for SLEEP MODE */
2890 *uwrq = priv->gain.TxGain;
2891 hostif_sme_enqueue(priv, SME_GET_GAIN);
2895 /*------------------------------------------------------------------*/
2896 /* Private handler : set rx gain control value */
2897 static int ks_wlan_set_rx_gain(struct net_device *dev,
2898 struct iw_request_info *info, __u32 * uwrq,
2901 struct ks_wlan_private *priv =
2902 (struct ks_wlan_private *)netdev_priv(dev);
2904 if (priv->sleep_mode == SLP_SLEEP) {
2907 /* for SLEEP MODE */
2908 if (*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2909 priv->gain.RxGain = (uint8_t) * uwrq;
2913 if (priv->gain.RxGain < 0xFF)
2914 priv->gain.RxMode = 1;
2916 priv->gain.RxMode = 0;
2918 hostif_sme_enqueue(priv, SME_SET_GAIN);
2922 /*------------------------------------------------------------------*/
2923 /* Private handler : get rx gain control value */
2924 static int ks_wlan_get_rx_gain(struct net_device *dev,
2925 struct iw_request_info *info, __u32 * uwrq,
2928 struct ks_wlan_private *priv =
2929 (struct ks_wlan_private *)netdev_priv(dev);
2931 if (priv->sleep_mode == SLP_SLEEP) {
2934 /* for SLEEP MODE */
2935 *uwrq = priv->gain.RxGain;
2936 hostif_sme_enqueue(priv, SME_GET_GAIN);
2941 /*------------------------------------------------------------------*/
2942 /* Private handler : set region value */
2943 static int ks_wlan_set_region(struct net_device *dev,
2944 struct iw_request_info *info, __u32 * uwrq,
2947 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2949 if (priv->sleep_mode == SLP_SLEEP) {
2952 /* for SLEEP MODE */
2953 if (*uwrq >= 0x9 && *uwrq <= 0xF) /* 0x9-0xf */
2954 priv->region = (uint8_t) * uwrq;
2958 hostif_sme_enqueue(priv, SME_SET_REGION);
2963 /*------------------------------------------------------------------*/
2964 /* Private handler : get eeprom checksum result */
2965 static int ks_wlan_get_eeprom_cksum(struct net_device *dev,
2966 struct iw_request_info *info, __u32 * uwrq,
2969 struct ks_wlan_private *priv =
2970 (struct ks_wlan_private *)netdev_priv(dev);
2972 *uwrq = priv->eeprom_checksum;
2976 static void print_hif_event(struct net_device *dev, int event)
2981 netdev_info(dev, "HIF_DATA_REQ\n");
2984 netdev_info(dev, "HIF_DATA_IND\n");
2986 case HIF_MIB_GET_REQ:
2987 netdev_info(dev, "HIF_MIB_GET_REQ\n");
2989 case HIF_MIB_GET_CONF:
2990 netdev_info(dev, "HIF_MIB_GET_CONF\n");
2992 case HIF_MIB_SET_REQ:
2993 netdev_info(dev, "HIF_MIB_SET_REQ\n");
2995 case HIF_MIB_SET_CONF:
2996 netdev_info(dev, "HIF_MIB_SET_CONF\n");
2998 case HIF_POWERMGT_REQ:
2999 netdev_info(dev, "HIF_POWERMGT_REQ\n");
3001 case HIF_POWERMGT_CONF:
3002 netdev_info(dev, "HIF_POWERMGT_CONF\n");
3005 netdev_info(dev, "HIF_START_REQ\n");
3007 case HIF_START_CONF:
3008 netdev_info(dev, "HIF_START_CONF\n");
3010 case HIF_CONNECT_IND:
3011 netdev_info(dev, "HIF_CONNECT_IND\n");
3014 netdev_info(dev, "HIF_STOP_REQ\n");
3017 netdev_info(dev, "HIF_STOP_CONF\n");
3019 case HIF_PS_ADH_SET_REQ:
3020 netdev_info(dev, "HIF_PS_ADH_SET_REQ\n");
3022 case HIF_PS_ADH_SET_CONF:
3023 netdev_info(dev, "HIF_PS_ADH_SET_CONF\n");
3025 case HIF_INFRA_SET_REQ:
3026 netdev_info(dev, "HIF_INFRA_SET_REQ\n");
3028 case HIF_INFRA_SET_CONF:
3029 netdev_info(dev, "HIF_INFRA_SET_CONF\n");
3031 case HIF_ADH_SET_REQ:
3032 netdev_info(dev, "HIF_ADH_SET_REQ\n");
3034 case HIF_ADH_SET_CONF:
3035 netdev_info(dev, "HIF_ADH_SET_CONF\n");
3037 case HIF_AP_SET_REQ:
3038 netdev_info(dev, "HIF_AP_SET_REQ\n");
3040 case HIF_AP_SET_CONF:
3041 netdev_info(dev, "HIF_AP_SET_CONF\n");
3043 case HIF_ASSOC_INFO_IND:
3044 netdev_info(dev, "HIF_ASSOC_INFO_IND\n");
3046 case HIF_MIC_FAILURE_REQ:
3047 netdev_info(dev, "HIF_MIC_FAILURE_REQ\n");
3049 case HIF_MIC_FAILURE_CONF:
3050 netdev_info(dev, "HIF_MIC_FAILURE_CONF\n");
3053 netdev_info(dev, "HIF_SCAN_REQ\n");
3056 netdev_info(dev, "HIF_SCAN_CONF\n");
3058 case HIF_PHY_INFO_REQ:
3059 netdev_info(dev, "HIF_PHY_INFO_REQ\n");
3061 case HIF_PHY_INFO_CONF:
3062 netdev_info(dev, "HIF_PHY_INFO_CONF\n");
3065 netdev_info(dev, "HIF_SLEEP_REQ\n");
3067 case HIF_SLEEP_CONF:
3068 netdev_info(dev, "HIF_SLEEP_CONF\n");
3070 case HIF_PHY_INFO_IND:
3071 netdev_info(dev, "HIF_PHY_INFO_IND\n");
3074 netdev_info(dev, "HIF_SCAN_IND\n");
3076 case HIF_INFRA_SET2_REQ:
3077 netdev_info(dev, "HIF_INFRA_SET2_REQ\n");
3079 case HIF_INFRA_SET2_CONF:
3080 netdev_info(dev, "HIF_INFRA_SET2_CONF\n");
3082 case HIF_ADH_SET2_REQ:
3083 netdev_info(dev, "HIF_ADH_SET2_REQ\n");
3085 case HIF_ADH_SET2_CONF:
3086 netdev_info(dev, "HIF_ADH_SET2_CONF\n");
3090 /*------------------------------------------------------------------*/
3091 /* Private handler : get host command history */
3092 static int ks_wlan_hostt(struct net_device *dev, struct iw_request_info *info,
3093 __u32 * uwrq, char *extra)
3096 struct ks_wlan_private *priv =
3097 (struct ks_wlan_private *)netdev_priv(dev);
3099 for (i = 63; i >= 0; i--) {
3101 priv->hostt.buff[(priv->hostt.qtail - 1 - i) %
3102 SME_EVENT_BUFF_SIZE];
3103 print_hif_event(dev, event);
3108 /* Structures to export the Wireless Handlers */
3110 static const struct iw_priv_args ks_wlan_private_args[] = {
3111 /*{ cmd, set_args, get_args, name[16] } */
3112 {KS_WLAN_GET_FIRM_VERSION, IW_PRIV_TYPE_NONE,
3113 IW_PRIV_TYPE_CHAR | (128 + 1), "GetFirmwareVer"},
3115 {KS_WLAN_SET_WPS_ENABLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3116 IW_PRIV_TYPE_NONE, "SetWPSEnable"},
3117 {KS_WLAN_GET_WPS_ENABLE, IW_PRIV_TYPE_NONE,
3118 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetW"},
3119 {KS_WLAN_SET_WPS_PROBE_REQ, IW_PRIV_TYPE_BYTE | 2047, IW_PRIV_TYPE_NONE,
3122 {KS_WLAN_SET_PREAMBLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3123 IW_PRIV_TYPE_NONE, "SetPreamble"},
3124 {KS_WLAN_GET_PREAMBLE, IW_PRIV_TYPE_NONE,
3125 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPreamble"},
3126 {KS_WLAN_SET_POWER_SAVE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3127 IW_PRIV_TYPE_NONE, "SetPowerSave"},
3128 {KS_WLAN_GET_POWER_SAVE, IW_PRIV_TYPE_NONE,
3129 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPowerSave"},
3130 {KS_WLAN_SET_SCAN_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3131 IW_PRIV_TYPE_NONE, "SetScanType"},
3132 {KS_WLAN_GET_SCAN_TYPE, IW_PRIV_TYPE_NONE,
3133 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetScanType"},
3134 {KS_WLAN_SET_RX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3135 IW_PRIV_TYPE_NONE, "SetRxGain"},
3136 {KS_WLAN_GET_RX_GAIN, IW_PRIV_TYPE_NONE,
3137 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetRxGain"},
3138 {KS_WLAN_HOSTT, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | (128 + 1),
3140 {KS_WLAN_SET_BEACON_LOST, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3141 IW_PRIV_TYPE_NONE, "SetBeaconLost"},
3142 {KS_WLAN_GET_BEACON_LOST, IW_PRIV_TYPE_NONE,
3143 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetBeaconLost"},
3144 {KS_WLAN_SET_SLEEP_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3145 IW_PRIV_TYPE_NONE, "SetSleepMode"},
3146 {KS_WLAN_GET_SLEEP_MODE, IW_PRIV_TYPE_NONE,
3147 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetSleepMode"},
3148 {KS_WLAN_SET_TX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3149 IW_PRIV_TYPE_NONE, "SetTxGain"},
3150 {KS_WLAN_GET_TX_GAIN, IW_PRIV_TYPE_NONE,
3151 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetTxGain"},
3152 {KS_WLAN_SET_PHY_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3153 IW_PRIV_TYPE_NONE, "SetPhyType"},
3154 {KS_WLAN_GET_PHY_TYPE, IW_PRIV_TYPE_NONE,
3155 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPhyType"},
3156 {KS_WLAN_SET_CTS_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3157 IW_PRIV_TYPE_NONE, "SetCtsMode"},
3158 {KS_WLAN_GET_CTS_MODE, IW_PRIV_TYPE_NONE,
3159 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetCtsMode"},
3160 {KS_WLAN_GET_EEPROM_CKSUM, IW_PRIV_TYPE_NONE,
3161 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetChecksum"},
3164 static const iw_handler ks_wlan_handler[] = {
3165 (iw_handler) ks_wlan_config_commit, /* SIOCSIWCOMMIT */
3166 (iw_handler) ks_wlan_get_name, /* SIOCGIWNAME */
3167 (iw_handler) NULL, /* SIOCSIWNWID */
3168 (iw_handler) NULL, /* SIOCGIWNWID */
3169 (iw_handler) ks_wlan_set_freq, /* SIOCSIWFREQ */
3170 (iw_handler) ks_wlan_get_freq, /* SIOCGIWFREQ */
3171 (iw_handler) ks_wlan_set_mode, /* SIOCSIWMODE */
3172 (iw_handler) ks_wlan_get_mode, /* SIOCGIWMODE */
3173 #ifndef KSC_OPNOTSUPP
3174 (iw_handler) ks_wlan_set_sens, /* SIOCSIWSENS */
3175 (iw_handler) ks_wlan_get_sens, /* SIOCGIWSENS */
3176 #else /* KSC_OPNOTSUPP */
3177 (iw_handler) NULL, /* SIOCSIWSENS */
3178 (iw_handler) NULL, /* SIOCGIWSENS */
3179 #endif /* KSC_OPNOTSUPP */
3180 (iw_handler) NULL, /* SIOCSIWRANGE */
3181 (iw_handler) ks_wlan_get_range, /* SIOCGIWRANGE */
3182 (iw_handler) NULL, /* SIOCSIWPRIV */
3183 (iw_handler) NULL, /* SIOCGIWPRIV */
3184 (iw_handler) NULL, /* SIOCSIWSTATS */
3185 (iw_handler) ks_wlan_get_iwstats, /* SIOCGIWSTATS */
3186 (iw_handler) NULL, /* SIOCSIWSPY */
3187 (iw_handler) NULL, /* SIOCGIWSPY */
3188 (iw_handler) NULL, /* SIOCSIWTHRSPY */
3189 (iw_handler) NULL, /* SIOCGIWTHRSPY */
3190 (iw_handler) ks_wlan_set_wap, /* SIOCSIWAP */
3191 (iw_handler) ks_wlan_get_wap, /* SIOCGIWAP */
3192 // (iw_handler) NULL, /* SIOCSIWMLME */
3193 (iw_handler) ks_wlan_set_mlme, /* SIOCSIWMLME */
3194 (iw_handler) ks_wlan_get_aplist, /* SIOCGIWAPLIST */
3195 (iw_handler) ks_wlan_set_scan, /* SIOCSIWSCAN */
3196 (iw_handler) ks_wlan_get_scan, /* SIOCGIWSCAN */
3197 (iw_handler) ks_wlan_set_essid, /* SIOCSIWESSID */
3198 (iw_handler) ks_wlan_get_essid, /* SIOCGIWESSID */
3199 (iw_handler) ks_wlan_set_nick, /* SIOCSIWNICKN */
3200 (iw_handler) ks_wlan_get_nick, /* SIOCGIWNICKN */
3201 (iw_handler) NULL, /* -- hole -- */
3202 (iw_handler) NULL, /* -- hole -- */
3203 (iw_handler) ks_wlan_set_rate, /* SIOCSIWRATE */
3204 (iw_handler) ks_wlan_get_rate, /* SIOCGIWRATE */
3205 (iw_handler) ks_wlan_set_rts, /* SIOCSIWRTS */
3206 (iw_handler) ks_wlan_get_rts, /* SIOCGIWRTS */
3207 (iw_handler) ks_wlan_set_frag, /* SIOCSIWFRAG */
3208 (iw_handler) ks_wlan_get_frag, /* SIOCGIWFRAG */
3209 #ifndef KSC_OPNOTSUPP
3210 (iw_handler) ks_wlan_set_txpow, /* SIOCSIWTXPOW */
3211 (iw_handler) ks_wlan_get_txpow, /* SIOCGIWTXPOW */
3212 (iw_handler) ks_wlan_set_retry, /* SIOCSIWRETRY */
3213 (iw_handler) ks_wlan_get_retry, /* SIOCGIWRETRY */
3214 #else /* KSC_OPNOTSUPP */
3215 (iw_handler) NULL, /* SIOCSIWTXPOW */
3216 (iw_handler) NULL, /* SIOCGIWTXPOW */
3217 (iw_handler) NULL, /* SIOCSIWRETRY */
3218 (iw_handler) NULL, /* SIOCGIWRETRY */
3219 #endif /* KSC_OPNOTSUPP */
3220 (iw_handler) ks_wlan_set_encode, /* SIOCSIWENCODE */
3221 (iw_handler) ks_wlan_get_encode, /* SIOCGIWENCODE */
3222 (iw_handler) ks_wlan_set_power, /* SIOCSIWPOWER */
3223 (iw_handler) ks_wlan_get_power, /* SIOCGIWPOWER */
3224 (iw_handler) NULL, /* -- hole -- */
3225 (iw_handler) NULL, /* -- hole -- */
3226 // (iw_handler) NULL, /* SIOCSIWGENIE */
3227 (iw_handler) ks_wlan_set_genie, /* SIOCSIWGENIE */
3228 (iw_handler) NULL, /* SIOCGIWGENIE */
3229 (iw_handler) ks_wlan_set_auth_mode, /* SIOCSIWAUTH */
3230 (iw_handler) ks_wlan_get_auth_mode, /* SIOCGIWAUTH */
3231 (iw_handler) ks_wlan_set_encode_ext, /* SIOCSIWENCODEEXT */
3232 (iw_handler) ks_wlan_get_encode_ext, /* SIOCGIWENCODEEXT */
3233 (iw_handler) ks_wlan_set_pmksa, /* SIOCSIWPMKSA */
3234 (iw_handler) NULL, /* -- hole -- */
3237 /* private_handler */
3238 static const iw_handler ks_wlan_private_handler[] = {
3239 (iw_handler) NULL, /* 0 */
3240 (iw_handler) NULL, /* 1, used to be: KS_WLAN_GET_DRIVER_VERSION */
3241 (iw_handler) NULL, /* 2 */
3242 (iw_handler) ks_wlan_get_firmware_version, /* 3 KS_WLAN_GET_FIRM_VERSION */
3244 (iw_handler) ks_wlan_set_wps_enable, /* 4 KS_WLAN_SET_WPS_ENABLE */
3245 (iw_handler) ks_wlan_get_wps_enable, /* 5 KS_WLAN_GET_WPS_ENABLE */
3246 (iw_handler) ks_wlan_set_wps_probe_req, /* 6 KS_WLAN_SET_WPS_PROBE_REQ */
3248 (iw_handler) NULL, /* 4 */
3249 (iw_handler) NULL, /* 5 */
3250 (iw_handler) NULL, /* 6 */
3253 (iw_handler) ks_wlan_get_eeprom_cksum, /* 7 KS_WLAN_GET_CONNECT */
3254 (iw_handler) ks_wlan_set_preamble, /* 8 KS_WLAN_SET_PREAMBLE */
3255 (iw_handler) ks_wlan_get_preamble, /* 9 KS_WLAN_GET_PREAMBLE */
3256 (iw_handler) ks_wlan_set_powermgt, /* 10 KS_WLAN_SET_POWER_SAVE */
3257 (iw_handler) ks_wlan_get_powermgt, /* 11 KS_WLAN_GET_POWER_SAVE */
3258 (iw_handler) ks_wlan_set_scan_type, /* 12 KS_WLAN_SET_SCAN_TYPE */
3259 (iw_handler) ks_wlan_get_scan_type, /* 13 KS_WLAN_GET_SCAN_TYPE */
3260 (iw_handler) ks_wlan_set_rx_gain, /* 14 KS_WLAN_SET_RX_GAIN */
3261 (iw_handler) ks_wlan_get_rx_gain, /* 15 KS_WLAN_GET_RX_GAIN */
3262 (iw_handler) ks_wlan_hostt, /* 16 KS_WLAN_HOSTT */
3263 (iw_handler) NULL, /* 17 */
3264 (iw_handler) ks_wlan_set_beacon_lost, /* 18 KS_WLAN_SET_BECAN_LOST */
3265 (iw_handler) ks_wlan_get_beacon_lost, /* 19 KS_WLAN_GET_BECAN_LOST */
3266 (iw_handler) ks_wlan_set_tx_gain, /* 20 KS_WLAN_SET_TX_GAIN */
3267 (iw_handler) ks_wlan_get_tx_gain, /* 21 KS_WLAN_GET_TX_GAIN */
3268 (iw_handler) ks_wlan_set_phy_type, /* 22 KS_WLAN_SET_PHY_TYPE */
3269 (iw_handler) ks_wlan_get_phy_type, /* 23 KS_WLAN_GET_PHY_TYPE */
3270 (iw_handler) ks_wlan_set_cts_mode, /* 24 KS_WLAN_SET_CTS_MODE */
3271 (iw_handler) ks_wlan_get_cts_mode, /* 25 KS_WLAN_GET_CTS_MODE */
3272 (iw_handler) NULL, /* 26 */
3273 (iw_handler) NULL, /* 27 */
3274 (iw_handler) ks_wlan_set_sleep_mode, /* 28 KS_WLAN_SET_SLEEP_MODE */
3275 (iw_handler) ks_wlan_get_sleep_mode, /* 29 KS_WLAN_GET_SLEEP_MODE */
3276 (iw_handler) NULL, /* 30 */
3277 (iw_handler) NULL, /* 31 */
3280 static const struct iw_handler_def ks_wlan_handler_def = {
3281 .num_standard = sizeof(ks_wlan_handler) / sizeof(iw_handler),
3282 .num_private = sizeof(ks_wlan_private_handler) / sizeof(iw_handler),
3284 sizeof(ks_wlan_private_args) / sizeof(struct iw_priv_args),
3285 .standard = (iw_handler *) ks_wlan_handler,
3286 .private = (iw_handler *) ks_wlan_private_handler,
3287 .private_args = (struct iw_priv_args *)ks_wlan_private_args,
3288 .get_wireless_stats = ks_get_wireless_stats,
3291 static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq,
3295 struct iwreq *wrq = (struct iwreq *)rq;
3297 case SIOCIWFIRSTPRIV + 20: /* KS_WLAN_SET_STOP_REQ */
3298 rc = ks_wlan_set_stop_request(dev, NULL, &(wrq->u.mode), NULL);
3300 // All other calls are currently unsupported
3305 DPRINTK(5, "return=%d\n", rc);
3310 struct net_device_stats *ks_wlan_get_stats(struct net_device *dev)
3312 struct ks_wlan_private *priv = netdev_priv(dev);
3314 if (priv->dev_state < DEVICE_STATE_READY) {
3315 return NULL; /* not finished initialize */
3318 return &priv->nstats;
3322 int ks_wlan_set_mac_address(struct net_device *dev, void *addr)
3324 struct ks_wlan_private *priv = netdev_priv(dev);
3325 struct sockaddr *mac_addr = (struct sockaddr *)addr;
3326 if (netif_running(dev))
3328 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
3329 memcpy(priv->eth_addr, mac_addr->sa_data, ETH_ALEN);
3331 priv->mac_address_valid = 0;
3332 hostif_sme_enqueue(priv, SME_MACADDRESS_SET_REQUEST);
3334 "ks_wlan: MAC ADDRESS = %02x:%02x:%02x:%02x:%02x:%02x\n",
3335 priv->eth_addr[0], priv->eth_addr[1], priv->eth_addr[2],
3336 priv->eth_addr[3], priv->eth_addr[4], priv->eth_addr[5]);
3341 void ks_wlan_tx_timeout(struct net_device *dev)
3343 struct ks_wlan_private *priv = netdev_priv(dev);
3345 DPRINTK(1, "head(%d) tail(%d)!!\n", priv->tx_dev.qhead,
3346 priv->tx_dev.qtail);
3347 if (!netif_queue_stopped(dev)) {
3348 netif_stop_queue(dev);
3350 priv->nstats.tx_errors++;
3351 netif_wake_queue(dev);
3355 int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev)
3357 struct ks_wlan_private *priv = netdev_priv(dev);
3360 DPRINTK(3, "in_interrupt()=%ld\n", in_interrupt());
3363 netdev_err(dev, "ks_wlan: skb == NULL!!!\n");
3366 if (priv->dev_state < DEVICE_STATE_READY) {
3368 return 0; /* not finished initialize */
3371 if (netif_running(dev))
3372 netif_stop_queue(dev);
3374 rc = hostif_data_request(priv, skb);
3375 netif_trans_update(dev);
3377 DPRINTK(4, "rc=%d\n", rc);
3385 void send_packet_complete(void *arg1, void *arg2)
3387 struct ks_wlan_private *priv = (struct ks_wlan_private *)arg1;
3388 struct sk_buff *packet = (struct sk_buff *)arg2;
3392 priv->nstats.tx_packets++;
3394 if (netif_queue_stopped(priv->net_dev))
3395 netif_wake_queue(priv->net_dev);
3398 priv->nstats.tx_bytes += packet->len;
3399 dev_kfree_skb(packet);
3405 /* Set or clear the multicast filter for this adaptor.
3406 This routine is not state sensitive and need not be SMP locked. */
3408 void ks_wlan_set_multicast_list(struct net_device *dev)
3410 struct ks_wlan_private *priv = netdev_priv(dev);
3413 if (priv->dev_state < DEVICE_STATE_READY) {
3414 return; /* not finished initialize */
3416 hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST);
3420 int ks_wlan_open(struct net_device *dev)
3422 struct ks_wlan_private *priv = netdev_priv(dev);
3426 if (!priv->mac_address_valid) {
3427 netdev_err(dev, "ks_wlan : %s Not READY !!\n", dev->name);
3430 netif_start_queue(dev);
3436 int ks_wlan_close(struct net_device *dev)
3439 netif_stop_queue(dev);
3441 DPRINTK(4, "%s: Shutting down ethercard, status was 0x%4.4x.\n",
3447 /* Operational parameters that usually are not changed. */
3448 /* Time in jiffies before concluding the transmitter is hung. */
3449 #define TX_TIMEOUT (3*HZ)
3450 static const unsigned char dummy_addr[] =
3451 { 0x00, 0x0b, 0xe3, 0x00, 0x00, 0x00 };
3453 static const struct net_device_ops ks_wlan_netdev_ops = {
3454 .ndo_start_xmit = ks_wlan_start_xmit,
3455 .ndo_open = ks_wlan_open,
3456 .ndo_stop = ks_wlan_close,
3457 .ndo_do_ioctl = ks_wlan_netdev_ioctl,
3458 .ndo_set_mac_address = ks_wlan_set_mac_address,
3459 .ndo_get_stats = ks_wlan_get_stats,
3460 .ndo_tx_timeout = ks_wlan_tx_timeout,
3461 .ndo_set_rx_mode = ks_wlan_set_multicast_list,
3464 int ks_wlan_net_start(struct net_device *dev)
3466 struct ks_wlan_private *priv;
3469 priv = netdev_priv(dev);
3470 priv->mac_address_valid = 0;
3471 priv->need_commit = 0;
3473 priv->device_open_status = 1;
3475 /* phy information update timer */
3476 atomic_set(&update_phyinfo, 0);
3477 init_timer(&update_phyinfo_timer);
3478 update_phyinfo_timer.function = ks_wlan_update_phyinfo_timeout;
3479 update_phyinfo_timer.data = (unsigned long)priv;
3481 /* dummy address set */
3482 memcpy(priv->eth_addr, dummy_addr, ETH_ALEN);
3483 dev->dev_addr[0] = priv->eth_addr[0];
3484 dev->dev_addr[1] = priv->eth_addr[1];
3485 dev->dev_addr[2] = priv->eth_addr[2];
3486 dev->dev_addr[3] = priv->eth_addr[3];
3487 dev->dev_addr[4] = priv->eth_addr[4];
3488 dev->dev_addr[5] = priv->eth_addr[5];
3489 dev->dev_addr[6] = 0x00;
3490 dev->dev_addr[7] = 0x00;
3492 /* The ks_wlan-specific entries in the device structure. */
3493 dev->netdev_ops = &ks_wlan_netdev_ops;
3494 dev->wireless_handlers = (struct iw_handler_def *)&ks_wlan_handler_def;
3495 dev->watchdog_timeo = TX_TIMEOUT;
3497 netif_carrier_off(dev);
3502 int ks_wlan_net_stop(struct net_device *dev)
3504 struct ks_wlan_private *priv = netdev_priv(dev);
3506 priv->device_open_status = 0;
3507 del_timer_sync(&update_phyinfo_timer);
3509 if (netif_running(dev))
3510 netif_stop_queue(dev);