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/version.h>
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/compiler.h>
16 #include <linux/init.h>
17 #include <linux/ioport.h>
18 #include <linux/netdevice.h>
19 #include <linux/etherdevice.h>
20 #include <linux/if_arp.h>
21 #include <linux/rtnetlink.h>
22 #include <linux/delay.h>
23 #include <linux/completion.h>
24 #include <linux/mii.h>
25 #include <linux/pci.h>
26 #include <linux/ctype.h>
27 #include <linux/timer.h>
28 #include <asm/atomic.h>
30 #include <asm/uaccess.h>
32 static int wep_on_off;
34 #define WEP_ON_64BIT 1
35 #define WEP_ON_128BIT 2
38 #include "ks_hostif.h"
39 #include "ks_wlan_ioctl.h"
41 /* Include Wireless Extension definition and check version */
42 #include <linux/wireless.h>
43 #define WIRELESS_SPY /* enable iwspy support */
44 #include <net/iw_handler.h> /* New driver API */
46 /* Frequency list (map channels to frequencies) */
47 static const long frequency_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
48 2447, 2452, 2457, 2462, 2467, 2472, 2484
51 /* A few details needed for WEP (Wireless Equivalent Privacy) */
52 #define MAX_KEY_SIZE 13 /* 128 (?) bits */
53 #define MIN_KEY_SIZE 5 /* 40 bits RC4 - WEP */
54 typedef struct wep_key_t {
56 u8 key[16]; /* 40-bit and 104-bit keys */
59 /* Backward compatibility */
60 #ifndef IW_ENCODE_NOKEY
61 #define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not present */
62 #define IW_ENCODE_MODE (IW_ENCODE_DISABLED | IW_ENCODE_RESTRICTED | IW_ENCODE_OPEN)
63 #endif /* IW_ENCODE_NOKEY */
65 /* List of Wireless Handlers (new API) */
66 static const struct iw_handler_def ks_wlan_handler_def;
68 #define KSC_OPNOTSUPP /* Operation Not Support */
73 extern int ks_wlan_hw_tx(struct ks_wlan_private *priv, void *p,
75 void (*complete_handler) (void *arg1, void *arg2),
76 void *arg1, void *arg2);
77 static int ks_wlan_open(struct net_device *dev);
78 static void ks_wlan_tx_timeout(struct net_device *dev);
79 static int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev);
80 static int ks_wlan_close(struct net_device *dev);
81 static void ks_wlan_set_multicast_list(struct net_device *dev);
82 static struct net_device_stats *ks_wlan_get_stats(struct net_device *dev);
83 static int ks_wlan_set_mac_address(struct net_device *dev, void *addr);
84 static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq,
87 static atomic_t update_phyinfo;
88 static struct timer_list update_phyinfo_timer;
90 int ks_wlan_update_phy_information(struct ks_wlan_private *priv)
92 struct iw_statistics *wstats = &priv->wstats;
94 DPRINTK(4, "in_interrupt = %ld\n", in_interrupt());
96 if (priv->dev_state < DEVICE_STATE_READY) {
97 return -1; /* not finished initialize */
99 if (atomic_read(&update_phyinfo))
103 wstats->status = priv->reg.operation_mode; /* Operation mode */
105 /* Signal quality and co. But where is the noise level ??? */
106 hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST);
108 /* interruptible_sleep_on_timeout(&priv->confirm_wait, HZ/2); */
109 if (!wait_for_completion_interruptible_timeout
110 (&priv->confirm_wait, HZ / 2)) {
111 DPRINTK(1, "wait time out!!\n");
114 atomic_inc(&update_phyinfo);
115 update_phyinfo_timer.expires = jiffies + HZ; /* 1sec */
116 add_timer(&update_phyinfo_timer);
122 void ks_wlan_update_phyinfo_timeout(unsigned long ptr)
124 DPRINTK(4, "in_interrupt = %ld\n", in_interrupt());
125 atomic_set(&update_phyinfo, 0);
128 int ks_wlan_setup_parameter(struct ks_wlan_private *priv,
129 unsigned int commit_flag)
133 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
135 if (commit_flag & SME_RTS)
136 hostif_sme_enqueue(priv, SME_RTS_THRESHOLD_REQUEST);
137 if (commit_flag & SME_FRAG)
138 hostif_sme_enqueue(priv, SME_FRAGMENTATION_THRESHOLD_REQUEST);
140 if (commit_flag & SME_WEP_INDEX)
141 hostif_sme_enqueue(priv, SME_WEP_INDEX_REQUEST);
142 if (commit_flag & SME_WEP_VAL1)
143 hostif_sme_enqueue(priv, SME_WEP_KEY1_REQUEST);
144 if (commit_flag & SME_WEP_VAL2)
145 hostif_sme_enqueue(priv, SME_WEP_KEY2_REQUEST);
146 if (commit_flag & SME_WEP_VAL3)
147 hostif_sme_enqueue(priv, SME_WEP_KEY3_REQUEST);
148 if (commit_flag & SME_WEP_VAL4)
149 hostif_sme_enqueue(priv, SME_WEP_KEY4_REQUEST);
150 if (commit_flag & SME_WEP_FLAG)
151 hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
153 if (commit_flag & SME_RSN) {
154 hostif_sme_enqueue(priv, SME_RSN_ENABLED_REQUEST);
155 hostif_sme_enqueue(priv, SME_RSN_MODE_REQUEST);
157 if (commit_flag & SME_RSN_MULTICAST)
158 hostif_sme_enqueue(priv, SME_RSN_MCAST_REQUEST);
159 if (commit_flag & SME_RSN_UNICAST)
160 hostif_sme_enqueue(priv, SME_RSN_UCAST_REQUEST);
161 if (commit_flag & SME_RSN_AUTH)
162 hostif_sme_enqueue(priv, SME_RSN_AUTH_REQUEST);
164 hostif_sme_enqueue(priv, SME_MODE_SET_REQUEST);
166 hostif_sme_enqueue(priv, SME_START_REQUEST);
172 * Initial Wireless Extension code for Ks_Wlannet driver by :
173 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00
174 * Conversion to new driver API by :
175 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 26 March 02
176 * Javier also did a good amount of work here, adding some new extensions
177 * and fixing my code. Let's just say that without him this code just
178 * would not work at all... - Jean II
181 /*------------------------------------------------------------------*/
182 /* Wireless Handler : get protocol name */
183 static int ks_wlan_get_name(struct net_device *dev,
184 struct iw_request_info *info, char *cwrq,
187 struct ks_wlan_private *priv =
188 (struct ks_wlan_private *)netdev_priv(dev);
190 if (priv->sleep_mode == SLP_SLEEP) {
194 if (priv->dev_state < DEVICE_STATE_READY) {
195 strcpy(cwrq, "NOT READY!");
196 } else if (priv->reg.phy_type == D_11B_ONLY_MODE) {
197 strcpy(cwrq, "IEEE 802.11b");
198 } else if (priv->reg.phy_type == D_11G_ONLY_MODE) {
199 strcpy(cwrq, "IEEE 802.11g");
201 strcpy(cwrq, "IEEE 802.11b/g");
207 /*------------------------------------------------------------------*/
208 /* Wireless Handler : set frequency */
209 static int ks_wlan_set_freq(struct net_device *dev,
210 struct iw_request_info *info, struct iw_freq *fwrq,
213 struct ks_wlan_private *priv =
214 (struct ks_wlan_private *)netdev_priv(dev);
215 int rc = -EINPROGRESS; /* Call commit handler */
217 if (priv->sleep_mode == SLP_SLEEP) {
222 /* If setting by frequency, convert to a channel */
223 if ((fwrq->e == 1) &&
224 (fwrq->m >= (int)2.412e8) && (fwrq->m <= (int)2.487e8)) {
225 int f = fwrq->m / 100000;
227 while ((c < 14) && (f != frequency_list[c]))
229 /* Hack to fall through... */
233 /* Setting by channel number */
234 if ((fwrq->m > 1000) || (fwrq->e > 0))
237 int channel = fwrq->m;
238 /* We should do a better check than that,
239 * based on the card capability !!! */
240 if ((channel < 1) || (channel > 14)) {
242 "%s: New channel value of %d is invalid!\n",
246 /* Yes ! We can set it !!! */
247 priv->reg.channel = (u8) (channel);
248 priv->need_commit |= SME_MODE_SET;
255 /*------------------------------------------------------------------*/
256 /* Wireless Handler : get frequency */
257 static int ks_wlan_get_freq(struct net_device *dev,
258 struct iw_request_info *info, struct iw_freq *fwrq,
261 struct ks_wlan_private *priv =
262 (struct ks_wlan_private *)netdev_priv(dev);
265 if (priv->sleep_mode == SLP_SLEEP) {
269 if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
270 f = (int)priv->current_ap.channel;
272 f = (int)priv->reg.channel;
273 fwrq->m = frequency_list[f - 1] * 100000;
279 /*------------------------------------------------------------------*/
280 /* Wireless Handler : set ESSID */
281 static int ks_wlan_set_essid(struct net_device *dev,
282 struct iw_request_info *info,
283 struct iw_point *dwrq, char *extra)
285 struct ks_wlan_private *priv =
286 (struct ks_wlan_private *)netdev_priv(dev);
289 DPRINTK(2, " %d\n", dwrq->flags);
291 if (priv->sleep_mode == SLP_SLEEP) {
296 /* Check if we asked for `any' */
297 if (dwrq->flags == 0) {
298 /* Just send an empty SSID list */
299 memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
300 priv->reg.ssid.size = 0;
304 /* iwconfig uses nul termination in SSID.. */
305 if (len > 0 && extra[len - 1] == '\0')
308 /* Check the size of the string */
309 if (len > IW_ESSID_MAX_SIZE) {
313 /* Check the size of the string */
314 if (dwrq->length > IW_ESSID_MAX_SIZE + 1) {
320 memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
323 memcpy(priv->reg.ssid.body, extra, len);
324 priv->reg.ssid.size = len;
326 memcpy(priv->reg.ssid.body, extra, dwrq->length);
327 priv->reg.ssid.size = dwrq->length;
330 /* Write it to the card */
331 priv->need_commit |= SME_MODE_SET;
333 // return -EINPROGRESS; /* Call commit handler */
334 ks_wlan_setup_parameter(priv, priv->need_commit);
335 priv->need_commit = 0;
339 /*------------------------------------------------------------------*/
340 /* Wireless Handler : get ESSID */
341 static int ks_wlan_get_essid(struct net_device *dev,
342 struct iw_request_info *info,
343 struct iw_point *dwrq, char *extra)
345 struct ks_wlan_private *priv =
346 (struct ks_wlan_private *)netdev_priv(dev);
348 if (priv->sleep_mode == SLP_SLEEP) {
353 /* Note : if dwrq->flags != 0, we should
354 * get the relevant SSID from the SSID list... */
355 if (priv->reg.ssid.size) {
356 /* Get the current SSID */
357 memcpy(extra, priv->reg.ssid.body, priv->reg.ssid.size);
359 extra[priv->reg.ssid.size] = '\0';
361 /* If none, we may want to get the one that was set */
365 dwrq->length = priv->reg.ssid.size;
367 dwrq->length = priv->reg.ssid.size + 1;
369 dwrq->flags = 1; /* active */
377 dwrq->flags = 0; /* ANY */
383 /*------------------------------------------------------------------*/
384 /* Wireless Handler : set AP address */
385 static int ks_wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
386 struct sockaddr *ap_addr, char *extra)
388 struct ks_wlan_private *priv =
389 (struct ks_wlan_private *)netdev_priv(dev);
393 if (priv->sleep_mode == SLP_SLEEP) {
397 if (priv->reg.operation_mode == MODE_ADHOC ||
398 priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
399 memcpy(priv->reg.bssid, (u8 *) & ap_addr->sa_data, ETH_ALEN);
401 if (is_valid_ether_addr((u8 *) priv->reg.bssid)) {
402 priv->need_commit |= SME_MODE_SET;
405 memset(priv->reg.bssid, 0x0, ETH_ALEN);
409 DPRINTK(2, "bssid = %02x:%02x:%02x:%02x:%02x:%02x\n",
410 priv->reg.bssid[0], priv->reg.bssid[1], priv->reg.bssid[2],
411 priv->reg.bssid[3], priv->reg.bssid[4], priv->reg.bssid[5]);
413 /* Write it to the card */
414 if (priv->need_commit) {
415 priv->need_commit |= SME_MODE_SET;
416 return -EINPROGRESS; /* Call commit handler */
421 /*------------------------------------------------------------------*/
422 /* Wireless Handler : get AP address */
423 static int ks_wlan_get_wap(struct net_device *dev, struct iw_request_info *info,
424 struct sockaddr *awrq, char *extra)
426 struct ks_wlan_private *priv =
427 (struct ks_wlan_private *)netdev_priv(dev);
429 if (priv->sleep_mode == SLP_SLEEP) {
433 if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
434 memcpy(awrq->sa_data, &(priv->current_ap.bssid[0]), ETH_ALEN);
436 memset(awrq->sa_data, 0, ETH_ALEN);
439 awrq->sa_family = ARPHRD_ETHER;
444 /*------------------------------------------------------------------*/
445 /* Wireless Handler : set Nickname */
446 static int ks_wlan_set_nick(struct net_device *dev,
447 struct iw_request_info *info, struct iw_point *dwrq,
450 struct ks_wlan_private *priv =
451 (struct ks_wlan_private *)netdev_priv(dev);
453 if (priv->sleep_mode == SLP_SLEEP) {
458 /* Check the size of the string */
459 if (dwrq->length > 16 + 1) {
462 memset(priv->nick, 0, sizeof(priv->nick));
463 memcpy(priv->nick, extra, dwrq->length);
465 return -EINPROGRESS; /* Call commit handler */
468 /*------------------------------------------------------------------*/
469 /* Wireless Handler : get Nickname */
470 static int ks_wlan_get_nick(struct net_device *dev,
471 struct iw_request_info *info, struct iw_point *dwrq,
474 struct ks_wlan_private *priv =
475 (struct ks_wlan_private *)netdev_priv(dev);
477 if (priv->sleep_mode == SLP_SLEEP) {
481 strncpy(extra, priv->nick, 16);
483 dwrq->length = strlen(extra) + 1;
488 /*------------------------------------------------------------------*/
489 /* Wireless Handler : set Bit-Rate */
490 static int ks_wlan_set_rate(struct net_device *dev,
491 struct iw_request_info *info, struct iw_param *vwrq,
494 struct ks_wlan_private *priv =
495 (struct ks_wlan_private *)netdev_priv(dev);
498 if (priv->sleep_mode == SLP_SLEEP) {
502 if (priv->reg.phy_type == D_11B_ONLY_MODE) {
503 if (vwrq->fixed == 1) {
504 switch (vwrq->value) {
507 priv->reg.rate_set.body[0] =
508 (uint8_t) (vwrq->value / 500000);
512 priv->reg.rate_set.body[0] =
513 ((uint8_t) (vwrq->value / 500000)) |
519 priv->reg.tx_rate = TX_RATE_FIXED;
520 priv->reg.rate_set.size = 1;
521 } else { /* vwrq->fixed == 0 */
522 if (vwrq->value > 0) {
523 switch (vwrq->value) {
525 priv->reg.rate_set.body[3] =
529 priv->reg.rate_set.body[2] = TX_RATE_5M;
532 priv->reg.rate_set.body[1] =
533 TX_RATE_2M | BASIC_RATE;
536 priv->reg.rate_set.body[0] =
537 TX_RATE_1M | BASIC_RATE;
543 priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
544 priv->reg.rate_set.size = i;
546 priv->reg.rate_set.body[3] = TX_RATE_11M;
547 priv->reg.rate_set.body[2] = TX_RATE_5M;
548 priv->reg.rate_set.body[1] =
549 TX_RATE_2M | BASIC_RATE;
550 priv->reg.rate_set.body[0] =
551 TX_RATE_1M | BASIC_RATE;
552 priv->reg.tx_rate = TX_RATE_FULL_AUTO;
553 priv->reg.rate_set.size = 4;
556 } else { /* D_11B_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
557 if (vwrq->fixed == 1) {
558 switch (vwrq->value) {
564 priv->reg.rate_set.body[0] =
565 (uint8_t) (vwrq->value / 500000);
574 priv->reg.rate_set.body[0] =
575 ((uint8_t) (vwrq->value / 500000)) |
581 priv->reg.tx_rate = TX_RATE_FIXED;
582 priv->reg.rate_set.size = 1;
583 } else { /* vwrq->fixed == 0 */
584 if (vwrq->value > 0) {
585 switch (vwrq->value) {
587 priv->reg.rate_set.body[11] =
591 priv->reg.rate_set.body[10] =
595 priv->reg.rate_set.body[9] =
604 if (vwrq->value == 24000000) {
605 priv->reg.rate_set.body[8] =
608 priv->reg.rate_set.body[7] =
611 priv->reg.rate_set.body[6] =
612 TX_RATE_24M | BASIC_RATE;
614 priv->reg.rate_set.body[5] =
615 TX_RATE_12M | BASIC_RATE;
617 priv->reg.rate_set.body[4] =
618 TX_RATE_6M | BASIC_RATE;
620 priv->reg.rate_set.body[3] =
621 TX_RATE_11M | BASIC_RATE;
623 } else if (vwrq->value == 18000000) {
624 priv->reg.rate_set.body[7] =
627 priv->reg.rate_set.body[6] =
630 priv->reg.rate_set.body[5] =
631 TX_RATE_12M | BASIC_RATE;
633 priv->reg.rate_set.body[4] =
634 TX_RATE_6M | BASIC_RATE;
636 priv->reg.rate_set.body[3] =
637 TX_RATE_11M | BASIC_RATE;
639 } else if (vwrq->value == 12000000) {
640 priv->reg.rate_set.body[6] =
643 priv->reg.rate_set.body[5] =
644 TX_RATE_12M | BASIC_RATE;
646 priv->reg.rate_set.body[4] =
647 TX_RATE_6M | BASIC_RATE;
649 priv->reg.rate_set.body[3] =
650 TX_RATE_11M | BASIC_RATE;
652 } else if (vwrq->value == 11000000) {
653 priv->reg.rate_set.body[5] =
656 priv->reg.rate_set.body[4] =
657 TX_RATE_6M | BASIC_RATE;
659 priv->reg.rate_set.body[3] =
660 TX_RATE_11M | BASIC_RATE;
662 } else if (vwrq->value == 9000000) {
663 priv->reg.rate_set.body[4] =
666 priv->reg.rate_set.body[3] =
667 TX_RATE_6M | BASIC_RATE;
669 } else { /* vwrq->value == 6000000 */
670 priv->reg.rate_set.body[3] =
671 TX_RATE_6M | BASIC_RATE;
675 priv->reg.rate_set.body[2] =
676 TX_RATE_5M | BASIC_RATE;
679 priv->reg.rate_set.body[1] =
680 TX_RATE_2M | BASIC_RATE;
683 priv->reg.rate_set.body[0] =
684 TX_RATE_1M | BASIC_RATE;
690 priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
691 priv->reg.rate_set.size = i;
693 priv->reg.rate_set.body[11] = TX_RATE_54M;
694 priv->reg.rate_set.body[10] = TX_RATE_48M;
695 priv->reg.rate_set.body[9] = TX_RATE_36M;
696 priv->reg.rate_set.body[8] = TX_RATE_18M;
697 priv->reg.rate_set.body[7] = TX_RATE_9M;
698 priv->reg.rate_set.body[6] =
699 TX_RATE_24M | BASIC_RATE;
700 priv->reg.rate_set.body[5] =
701 TX_RATE_12M | BASIC_RATE;
702 priv->reg.rate_set.body[4] =
703 TX_RATE_6M | BASIC_RATE;
704 priv->reg.rate_set.body[3] =
705 TX_RATE_11M | BASIC_RATE;
706 priv->reg.rate_set.body[2] =
707 TX_RATE_5M | BASIC_RATE;
708 priv->reg.rate_set.body[1] =
709 TX_RATE_2M | BASIC_RATE;
710 priv->reg.rate_set.body[0] =
711 TX_RATE_1M | BASIC_RATE;
712 priv->reg.tx_rate = TX_RATE_FULL_AUTO;
713 priv->reg.rate_set.size = 12;
718 priv->need_commit |= SME_MODE_SET;
720 return -EINPROGRESS; /* Call commit handler */
723 /*------------------------------------------------------------------*/
724 /* Wireless Handler : get Bit-Rate */
725 static int ks_wlan_get_rate(struct net_device *dev,
726 struct iw_request_info *info, struct iw_param *vwrq,
729 struct ks_wlan_private *priv =
730 (struct ks_wlan_private *)netdev_priv(dev);
732 DPRINTK(2, "in_interrupt = %ld update_phyinfo = %d\n",
733 in_interrupt(), atomic_read(&update_phyinfo));
735 if (priv->sleep_mode == SLP_SLEEP) {
739 if (!atomic_read(&update_phyinfo)) {
740 ks_wlan_update_phy_information(priv);
742 vwrq->value = ((priv->current_rate) & RATE_MASK) * 500000;
743 if (priv->reg.tx_rate == TX_RATE_FIXED)
751 /*------------------------------------------------------------------*/
752 /* Wireless Handler : set RTS threshold */
753 static int ks_wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
754 struct iw_param *vwrq, char *extra)
756 struct ks_wlan_private *priv =
757 (struct ks_wlan_private *)netdev_priv(dev);
758 int rthr = vwrq->value;
760 if (priv->sleep_mode == SLP_SLEEP) {
766 if ((rthr < 0) || (rthr > 2347)) {
769 priv->reg.rts = rthr;
770 priv->need_commit |= SME_RTS;
772 return -EINPROGRESS; /* Call commit handler */
775 /*------------------------------------------------------------------*/
776 /* Wireless Handler : get RTS threshold */
777 static int ks_wlan_get_rts(struct net_device *dev, struct iw_request_info *info,
778 struct iw_param *vwrq, char *extra)
780 struct ks_wlan_private *priv =
781 (struct ks_wlan_private *)netdev_priv(dev);
783 if (priv->sleep_mode == SLP_SLEEP) {
787 vwrq->value = priv->reg.rts;
788 vwrq->disabled = (vwrq->value >= 2347);
794 /*------------------------------------------------------------------*/
795 /* Wireless Handler : set Fragmentation threshold */
796 static int ks_wlan_set_frag(struct net_device *dev,
797 struct iw_request_info *info, struct iw_param *vwrq,
800 struct ks_wlan_private *priv =
801 (struct ks_wlan_private *)netdev_priv(dev);
802 int fthr = vwrq->value;
804 if (priv->sleep_mode == SLP_SLEEP) {
810 if ((fthr < 256) || (fthr > 2346)) {
813 fthr &= ~0x1; /* Get an even value - is it really needed ??? */
814 priv->reg.fragment = fthr;
815 priv->need_commit |= SME_FRAG;
817 return -EINPROGRESS; /* Call commit handler */
820 /*------------------------------------------------------------------*/
821 /* Wireless Handler : get Fragmentation threshold */
822 static int ks_wlan_get_frag(struct net_device *dev,
823 struct iw_request_info *info, struct iw_param *vwrq,
826 struct ks_wlan_private *priv =
827 (struct ks_wlan_private *)netdev_priv(dev);
829 if (priv->sleep_mode == SLP_SLEEP) {
833 vwrq->value = priv->reg.fragment;
834 vwrq->disabled = (vwrq->value >= 2346);
840 /*------------------------------------------------------------------*/
841 /* Wireless Handler : set Mode of Operation */
842 static int ks_wlan_set_mode(struct net_device *dev,
843 struct iw_request_info *info, __u32 * uwrq,
846 struct ks_wlan_private *priv =
847 (struct ks_wlan_private *)netdev_priv(dev);
849 DPRINTK(2, "mode=%d\n", *uwrq);
851 if (priv->sleep_mode == SLP_SLEEP) {
857 priv->reg.operation_mode = MODE_ADHOC;
858 priv->need_commit |= SME_MODE_SET;
861 priv->reg.operation_mode = MODE_INFRASTRUCTURE;
862 priv->need_commit |= SME_MODE_SET;
868 case IW_MODE_MONITOR:
873 return -EINPROGRESS; /* Call commit handler */
876 /*------------------------------------------------------------------*/
877 /* Wireless Handler : get Mode of Operation */
878 static int ks_wlan_get_mode(struct net_device *dev,
879 struct iw_request_info *info, __u32 * uwrq,
882 struct ks_wlan_private *priv =
883 (struct ks_wlan_private *)netdev_priv(dev);
885 if (priv->sleep_mode == SLP_SLEEP) {
890 /* If not managed, assume it's ad-hoc */
891 switch (priv->reg.operation_mode) {
892 case MODE_INFRASTRUCTURE:
893 *uwrq = IW_MODE_INFRA;
896 *uwrq = IW_MODE_ADHOC;
899 *uwrq = IW_MODE_ADHOC;
905 /*------------------------------------------------------------------*/
906 /* Wireless Handler : set Encryption Key */
907 static int ks_wlan_set_encode(struct net_device *dev,
908 struct iw_request_info *info,
909 struct iw_point *dwrq, char *extra)
911 struct ks_wlan_private *priv =
912 (struct ks_wlan_private *)netdev_priv(dev);
915 int index = (dwrq->flags & IW_ENCODE_INDEX);
916 int current_index = priv->reg.wep_index;
919 DPRINTK(2, "flags=%04X\n", dwrq->flags);
921 if (priv->sleep_mode == SLP_SLEEP) {
927 if ((index < 0) || (index > 4))
930 index = current_index;
934 /* Is WEP supported ? */
935 /* Basic checking: do we have a key to set ? */
936 if (dwrq->length > 0) {
937 if (dwrq->length > MAX_KEY_SIZE) { /* Check the size of the key */
940 if (dwrq->length > MIN_KEY_SIZE) { /* Set the length */
941 key.len = MAX_KEY_SIZE;
942 priv->reg.privacy_invoked = 0x01;
943 priv->need_commit |= SME_WEP_FLAG;
944 wep_on_off = WEP_ON_128BIT;
946 if (dwrq->length > 0) {
947 key.len = MIN_KEY_SIZE;
948 priv->reg.privacy_invoked = 0x01;
949 priv->need_commit |= SME_WEP_FLAG;
950 wep_on_off = WEP_ON_64BIT;
951 } else { /* Disable the key */
955 /* Check if the key is not marked as invalid */
956 if (!(dwrq->flags & IW_ENCODE_NOKEY)) {
958 memset(key.key, 0, MAX_KEY_SIZE);
959 /* Copy the key in the driver */
961 (key.key, dwrq->pointer, dwrq->length)) {
965 /* Send the key to the card */
966 priv->reg.wep_key[index].size = key.len;
967 for (i = 0; i < (priv->reg.wep_key[index].size); i++) {
968 priv->reg.wep_key[index].val[i] = key.key[i];
970 priv->need_commit |= (SME_WEP_VAL1 << index);
971 priv->reg.wep_index = index;
972 priv->need_commit |= SME_WEP_INDEX;
975 if (dwrq->flags & IW_ENCODE_DISABLED) {
976 priv->reg.wep_key[0].size = 0;
977 priv->reg.wep_key[1].size = 0;
978 priv->reg.wep_key[2].size = 0;
979 priv->reg.wep_key[3].size = 0;
980 priv->reg.privacy_invoked = 0x00;
981 if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY) {
982 priv->need_commit |= SME_MODE_SET;
984 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
985 wep_on_off = WEP_OFF;
986 priv->need_commit |= SME_WEP_FLAG;
988 /* Do we want to just set the transmit key index ? */
989 if ((index >= 0) && (index < 4)) {
990 /* set_wep_key(priv, index, 0, 0, 1); xxx */
991 if (priv->reg.wep_key[index].size) {
992 priv->reg.wep_index = index;
993 priv->need_commit |= SME_WEP_INDEX;
1000 /* Commit the changes if needed */
1001 if (dwrq->flags & IW_ENCODE_MODE)
1002 priv->need_commit |= SME_WEP_FLAG;
1004 if (dwrq->flags & IW_ENCODE_OPEN) {
1005 if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY) {
1006 priv->need_commit |= SME_MODE_SET;
1008 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
1009 } else if (dwrq->flags & IW_ENCODE_RESTRICTED) {
1010 if (priv->reg.authenticate_type == AUTH_TYPE_OPEN_SYSTEM) {
1011 priv->need_commit |= SME_MODE_SET;
1013 priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
1015 // return -EINPROGRESS; /* Call commit handler */
1016 if (priv->need_commit) {
1017 ks_wlan_setup_parameter(priv, priv->need_commit);
1018 priv->need_commit = 0;
1023 /*------------------------------------------------------------------*/
1024 /* Wireless Handler : get Encryption Key */
1025 static int ks_wlan_get_encode(struct net_device *dev,
1026 struct iw_request_info *info,
1027 struct iw_point *dwrq, char *extra)
1029 struct ks_wlan_private *priv =
1030 (struct ks_wlan_private *)netdev_priv(dev);
1032 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1034 if (priv->sleep_mode == SLP_SLEEP) {
1037 /* for SLEEP MODE */
1038 dwrq->flags = IW_ENCODE_DISABLED;
1040 /* Check encryption mode */
1041 switch (priv->reg.authenticate_type) {
1042 case AUTH_TYPE_OPEN_SYSTEM:
1043 dwrq->flags = IW_ENCODE_OPEN;
1045 case AUTH_TYPE_SHARED_KEY:
1046 dwrq->flags = IW_ENCODE_RESTRICTED;
1050 memset(zeros, 0, sizeof(zeros));
1052 /* Which key do we want ? -1 -> tx index */
1053 if ((index < 0) || (index >= 4))
1054 index = priv->reg.wep_index;
1055 if (priv->reg.privacy_invoked) {
1056 dwrq->flags &= ~IW_ENCODE_DISABLED;
1057 /* dwrq->flags |= IW_ENCODE_NOKEY; */
1059 dwrq->flags |= index + 1;
1060 DPRINTK(2, "encoding flag = 0x%04X\n", dwrq->flags);
1061 /* Copy the key to the user buffer */
1062 if ((index >= 0) && (index < 4))
1063 dwrq->length = priv->reg.wep_key[index].size;
1064 if (dwrq->length > 16) {
1067 #if 1 /* IW_ENCODE_NOKEY; */
1069 if ((index >= 0) && (index < 4))
1070 memcpy(extra, priv->reg.wep_key[index].val,
1073 memcpy(extra, zeros, dwrq->length);
1078 #ifndef KSC_OPNOTSUPP
1079 /*------------------------------------------------------------------*/
1080 /* Wireless Handler : set Tx-Power */
1081 static int ks_wlan_set_txpow(struct net_device *dev,
1082 struct iw_request_info *info,
1083 struct iw_param *vwrq, char *extra)
1085 return -EOPNOTSUPP; /* Not Support */
1088 /*------------------------------------------------------------------*/
1089 /* Wireless Handler : get Tx-Power */
1090 static int ks_wlan_get_txpow(struct net_device *dev,
1091 struct iw_request_info *info,
1092 struct iw_param *vwrq, char *extra)
1094 if (priv->sleep_mode == SLP_SLEEP) {
1098 /* for SLEEP MODE */
1101 vwrq->disabled = (vwrq->value == 0);
1106 /*------------------------------------------------------------------*/
1107 /* Wireless Handler : set Retry limits */
1108 static int ks_wlan_set_retry(struct net_device *dev,
1109 struct iw_request_info *info,
1110 struct iw_param *vwrq, char *extra)
1112 return -EOPNOTSUPP; /* Not Support */
1115 /*------------------------------------------------------------------*/
1116 /* Wireless Handler : get Retry limits */
1117 static int ks_wlan_get_retry(struct net_device *dev,
1118 struct iw_request_info *info,
1119 struct iw_param *vwrq, char *extra)
1121 if (priv->sleep_mode == SLP_SLEEP) {
1125 /* for SLEEP MODE */
1128 vwrq->disabled = (vwrq->value == 0);
1132 #endif /* KSC_OPNOTSUPP */
1134 /*------------------------------------------------------------------*/
1135 /* Wireless Handler : get range info */
1136 static int ks_wlan_get_range(struct net_device *dev,
1137 struct iw_request_info *info,
1138 struct iw_point *dwrq, char *extra)
1140 struct ks_wlan_private *priv =
1141 (struct ks_wlan_private *)netdev_priv(dev);
1142 struct iw_range *range = (struct iw_range *)extra;
1147 if (priv->sleep_mode == SLP_SLEEP) {
1150 /* for SLEEP MODE */
1151 dwrq->length = sizeof(struct iw_range);
1152 memset(range, 0, sizeof(*range));
1153 range->min_nwid = 0x0000;
1154 range->max_nwid = 0x0000;
1155 range->num_channels = 14;
1156 /* Should be based on cap_rid.country to give only
1157 * what the current card support */
1159 for (i = 0; i < 13; i++) { /* channel 1 -- 13 */
1160 range->freq[k].i = i + 1; /* List index */
1161 range->freq[k].m = frequency_list[i] * 100000;
1162 range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
1164 range->num_frequency = k;
1165 if (priv->reg.phy_type == D_11B_ONLY_MODE || priv->reg.phy_type == D_11BG_COMPATIBLE_MODE) { /* channel 14 */
1166 range->freq[13].i = 14; /* List index */
1167 range->freq[13].m = frequency_list[13] * 100000;
1168 range->freq[13].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
1169 range->num_frequency = 14;
1172 /* Hum... Should put the right values there */
1173 range->max_qual.qual = 100;
1174 range->max_qual.level = 256 - 128; /* 0 dBm? */
1175 range->max_qual.noise = 256 - 128;
1176 range->sensitivity = 1;
1178 if (priv->reg.phy_type == D_11B_ONLY_MODE) {
1179 range->bitrate[0] = 1e6;
1180 range->bitrate[1] = 2e6;
1181 range->bitrate[2] = 5.5e6;
1182 range->bitrate[3] = 11e6;
1183 range->num_bitrates = 4;
1184 } else { /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
1185 range->bitrate[0] = 1e6;
1186 range->bitrate[1] = 2e6;
1187 range->bitrate[2] = 5.5e6;
1188 range->bitrate[3] = 11e6;
1190 range->bitrate[4] = 6e6;
1191 range->bitrate[5] = 9e6;
1192 range->bitrate[6] = 12e6;
1193 if (IW_MAX_BITRATES < 9) {
1194 range->bitrate[7] = 54e6;
1195 range->num_bitrates = 8;
1197 range->bitrate[7] = 18e6;
1198 range->bitrate[8] = 24e6;
1199 range->bitrate[9] = 36e6;
1200 range->bitrate[10] = 48e6;
1201 range->bitrate[11] = 54e6;
1203 range->num_bitrates = 12;
1207 /* Set an indication of the max TCP throughput
1208 * in bit/s that we can expect using this interface.
1209 * May be use for QoS stuff... Jean II */
1211 range->throughput = 5000 * 1000;
1213 range->throughput = 1500 * 1000;
1216 range->max_rts = 2347;
1217 range->min_frag = 256;
1218 range->max_frag = 2346;
1220 range->encoding_size[0] = 5; /* WEP: RC4 40 bits */
1221 range->encoding_size[1] = 13; /* WEP: RC4 ~128 bits */
1222 range->num_encoding_sizes = 2;
1223 range->max_encoding_tokens = 4;
1225 /* power management not support */
1226 range->pmp_flags = IW_POWER_ON;
1227 range->pmt_flags = IW_POWER_ON;
1230 /* Transmit Power - values are in dBm( or mW) */
1231 range->txpower[0] = -256;
1232 range->num_txpower = 1;
1233 range->txpower_capa = IW_TXPOW_DBM;
1234 /* range->txpower_capa = IW_TXPOW_MWATT; */
1236 range->we_version_source = 21;
1237 range->we_version_compiled = WIRELESS_EXT;
1239 range->retry_capa = IW_RETRY_ON;
1240 range->retry_flags = IW_RETRY_ON;
1241 range->r_time_flags = IW_RETRY_ON;
1243 /* Experimental measurements - boundary 11/5.5 Mb/s */
1244 /* Note : with or without the (local->rssi), results
1245 * are somewhat different. - Jean II */
1246 range->avg_qual.qual = 50;
1247 range->avg_qual.level = 186; /* -70 dBm */
1248 range->avg_qual.noise = 0;
1250 /* Event capability (kernel + driver) */
1251 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
1252 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
1253 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
1254 range->event_capa[1] = IW_EVENT_CAPA_K_1;
1255 range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVCUSTOM) |
1256 IW_EVENT_CAPA_MASK(IWEVMICHAELMICFAILURE));
1258 /* encode extension (WPA) capability */
1259 range->enc_capa = (IW_ENC_CAPA_WPA |
1261 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP);
1265 /*------------------------------------------------------------------*/
1266 /* Wireless Handler : set Power Management */
1267 static int ks_wlan_set_power(struct net_device *dev,
1268 struct iw_request_info *info,
1269 struct iw_param *vwrq, char *extra)
1271 struct ks_wlan_private *priv =
1272 (struct ks_wlan_private *)netdev_priv(dev);
1275 if (priv->sleep_mode == SLP_SLEEP) {
1278 /* for SLEEP MODE */
1279 enabled = vwrq->disabled ? 0 : 1;
1280 if (enabled == 0) { /* 0 */
1281 priv->reg.powermgt = POWMGT_ACTIVE_MODE;
1282 } else if (enabled) { /* 1 */
1283 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
1284 priv->reg.powermgt = POWMGT_SAVE1_MODE;
1287 } else if (enabled) { /* 2 */
1288 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
1289 priv->reg.powermgt = POWMGT_SAVE2_MODE;
1295 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
1300 /*------------------------------------------------------------------*/
1301 /* Wireless Handler : get Power Management */
1302 static int ks_wlan_get_power(struct net_device *dev,
1303 struct iw_request_info *info,
1304 struct iw_param *vwrq, char *extra)
1306 struct ks_wlan_private *priv =
1307 (struct ks_wlan_private *)netdev_priv(dev);
1309 if (priv->sleep_mode == SLP_SLEEP) {
1312 /* for SLEEP MODE */
1313 if (priv->reg.powermgt > 0)
1321 /*------------------------------------------------------------------*/
1322 /* Wireless Handler : get wirless statistics */
1323 static int ks_wlan_get_iwstats(struct net_device *dev,
1324 struct iw_request_info *info,
1325 struct iw_quality *vwrq, char *extra)
1327 struct ks_wlan_private *priv =
1328 (struct ks_wlan_private *)netdev_priv(dev);
1330 if (priv->sleep_mode == SLP_SLEEP) {
1333 /* for SLEEP MODE */
1334 vwrq->qual = 0; /* not supported */
1335 vwrq->level = priv->wstats.qual.level;
1336 vwrq->noise = 0; /* not supported */
1342 #ifndef KSC_OPNOTSUPP
1343 /*------------------------------------------------------------------*/
1344 /* Wireless Handler : set Sensitivity */
1345 static int ks_wlan_set_sens(struct net_device *dev,
1346 struct iw_request_info *info, struct iw_param *vwrq,
1349 return -EOPNOTSUPP; /* Not Support */
1352 /*------------------------------------------------------------------*/
1353 /* Wireless Handler : get Sensitivity */
1354 static int ks_wlan_get_sens(struct net_device *dev,
1355 struct iw_request_info *info, struct iw_param *vwrq,
1360 vwrq->disabled = (vwrq->value == 0);
1364 #endif /* KSC_OPNOTSUPP */
1366 /*------------------------------------------------------------------*/
1367 /* Wireless Handler : get AP List */
1368 /* Note : this is deprecated in favor of IWSCAN */
1369 static int ks_wlan_get_aplist(struct net_device *dev,
1370 struct iw_request_info *info,
1371 struct iw_point *dwrq, char *extra)
1373 struct ks_wlan_private *priv =
1374 (struct ks_wlan_private *)netdev_priv(dev);
1375 struct sockaddr *address = (struct sockaddr *)extra;
1376 struct iw_quality qual[LOCAL_APLIST_MAX];
1380 if (priv->sleep_mode == SLP_SLEEP) {
1383 /* for SLEEP MODE */
1384 for (i = 0; i < priv->aplist.size; i++) {
1385 memcpy(address[i].sa_data, &(priv->aplist.ap[i].bssid[0]),
1387 address[i].sa_family = ARPHRD_ETHER;
1388 qual[i].level = 256 - priv->aplist.ap[i].rssi;
1389 qual[i].qual = priv->aplist.ap[i].sq;
1390 qual[i].noise = 0; /* invalid noise value */
1391 qual[i].updated = 7;
1394 dwrq->flags = 1; /* Should be define'd */
1395 memcpy(extra + sizeof(struct sockaddr) * i,
1396 &qual, sizeof(struct iw_quality) * i);
1403 /*------------------------------------------------------------------*/
1404 /* Wireless Handler : Initiate Scan */
1405 static int ks_wlan_set_scan(struct net_device *dev,
1406 struct iw_request_info *info,
1407 union iwreq_data *wrqu, char *extra)
1409 struct ks_wlan_private *priv =
1410 (struct ks_wlan_private *)netdev_priv(dev);
1411 struct iw_scan_req *req = NULL;
1414 if (priv->sleep_mode == SLP_SLEEP) {
1418 /* for SLEEP MODE */
1419 /* specified SSID SCAN */
1420 if (wrqu->data.length == sizeof(struct iw_scan_req)
1421 && wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1422 req = (struct iw_scan_req *)extra;
1423 priv->scan_ssid_len = req->essid_len;
1424 memcpy(priv->scan_ssid, req->essid, priv->scan_ssid_len);
1426 priv->scan_ssid_len = 0;
1429 priv->sme_i.sme_flag |= SME_AP_SCAN;
1430 hostif_sme_enqueue(priv, SME_BSS_SCAN_REQUEST);
1432 /* At this point, just return to the user. */
1437 /*------------------------------------------------------------------*/
1439 * Translate scan data returned from the card to a card independent
1440 * format that the Wireless Tools will understand - Jean II
1442 static inline char *ks_wlan_translate_scan(struct net_device *dev,
1443 struct iw_request_info *info,
1444 char *current_ev, char *end_buf,
1445 struct local_ap_t *ap)
1447 /* struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; */
1448 struct iw_event iwe; /* Temporary buffer */
1450 char *current_val; /* For rates */
1452 static const char rsn_leader[] = "rsn_ie=";
1453 static const char wpa_leader[] = "wpa_ie=";
1454 char buf0[RSN_IE_BODY_MAX * 2 + 30];
1455 char buf1[RSN_IE_BODY_MAX * 2 + 30];
1457 /* First entry *MUST* be the AP MAC address */
1458 iwe.cmd = SIOCGIWAP;
1459 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1460 memcpy(iwe.u.ap_addr.sa_data, ap->bssid, ETH_ALEN);
1462 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1465 /* Other entries will be displayed in the order we give them */
1468 iwe.u.data.length = ap->ssid.size;
1469 if (iwe.u.data.length > 32)
1470 iwe.u.data.length = 32;
1471 iwe.cmd = SIOCGIWESSID;
1472 iwe.u.data.flags = 1;
1474 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1475 &(ap->ssid.body[0]));
1478 iwe.cmd = SIOCGIWMODE;
1479 capabilities = le16_to_cpu(ap->capability);
1480 if (capabilities & (BSS_CAP_ESS | BSS_CAP_IBSS)) {
1481 if (capabilities & BSS_CAP_ESS)
1482 iwe.u.mode = IW_MODE_INFRA;
1484 iwe.u.mode = IW_MODE_ADHOC;
1486 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1491 iwe.cmd = SIOCGIWFREQ;
1492 iwe.u.freq.m = ap->channel;
1493 iwe.u.freq.m = frequency_list[iwe.u.freq.m - 1] * 100000;
1496 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1499 /* Add quality statistics */
1501 iwe.u.qual.level = 256 - ap->rssi;
1502 iwe.u.qual.qual = ap->sq;
1503 iwe.u.qual.noise = 0; /* invalid noise value */
1505 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1508 /* Add encryption capability */
1509 iwe.cmd = SIOCGIWENCODE;
1510 if (capabilities & BSS_CAP_PRIVACY)
1511 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1513 iwe.u.data.flags = IW_ENCODE_DISABLED;
1514 iwe.u.data.length = 0;
1516 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1517 &(ap->ssid.body[0]));
1519 /* Rate : stuffing multiple values in a single event require a bit
1520 * more of magic - Jean II */
1521 current_val = current_ev + IW_EV_LCP_LEN;
1523 iwe.cmd = SIOCGIWRATE;
1524 /* Those two flags are ignored... */
1525 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
1528 for (i = 0; i < 16; i++) {
1529 /* NULL terminated */
1530 if (i >= ap->rate_set.size)
1532 /* Bit rate given in 500 kb/s units (+ 0x80) */
1533 iwe.u.bitrate.value = ((ap->rate_set.body[i] & 0x7f) * 500000);
1534 /* Add new value to event */
1536 iwe_stream_add_value(info, current_ev, current_val, end_buf,
1537 &iwe, IW_EV_PARAM_LEN);
1539 /* Check if we added any event */
1540 if ((current_val - current_ev) > IW_EV_LCP_LEN)
1541 current_ev = current_val;
1543 #define GENERIC_INFO_ELEM_ID 0xdd
1544 #define RSN_INFO_ELEM_ID 0x30
1545 if (ap->rsn_ie.id == RSN_INFO_ELEM_ID && ap->rsn_ie.size != 0) {
1547 memset(&iwe, 0, sizeof(iwe));
1548 iwe.cmd = IWEVCUSTOM;
1549 memcpy(buf0, rsn_leader, sizeof(rsn_leader) - 1);
1550 iwe.u.data.length += sizeof(rsn_leader) - 1;
1551 pbuf += sizeof(rsn_leader) - 1;
1553 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.id);
1554 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.size);
1555 iwe.u.data.length += 4;
1557 for (i = 0; i < ap->rsn_ie.size; i++)
1558 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.body[i]);
1559 iwe.u.data.length += (ap->rsn_ie.size) * 2;
1561 DPRINTK(4, "ap->rsn.size=%d\n", ap->rsn_ie.size);
1564 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1567 if (ap->wpa_ie.id == GENERIC_INFO_ELEM_ID && ap->wpa_ie.size != 0) {
1569 memset(&iwe, 0, sizeof(iwe));
1570 iwe.cmd = IWEVCUSTOM;
1571 memcpy(buf1, wpa_leader, sizeof(wpa_leader) - 1);
1572 iwe.u.data.length += sizeof(wpa_leader) - 1;
1573 pbuf += sizeof(wpa_leader) - 1;
1575 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.id);
1576 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.size);
1577 iwe.u.data.length += 4;
1579 for (i = 0; i < ap->wpa_ie.size; i++)
1580 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.body[i]);
1581 iwe.u.data.length += (ap->wpa_ie.size) * 2;
1583 DPRINTK(4, "ap->rsn.size=%d\n", ap->wpa_ie.size);
1584 DPRINTK(4, "iwe.u.data.length=%d\n", iwe.u.data.length);
1587 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1591 /* The other data in the scan result are not really
1592 * interesting, so for now drop it - Jean II */
1596 /*------------------------------------------------------------------*/
1597 /* Wireless Handler : Read Scan Results */
1598 static int ks_wlan_get_scan(struct net_device *dev,
1599 struct iw_request_info *info, struct iw_point *dwrq,
1602 struct ks_wlan_private *priv =
1603 (struct ks_wlan_private *)netdev_priv(dev);
1605 char *current_ev = extra;
1608 if (priv->sleep_mode == SLP_SLEEP) {
1611 /* for SLEEP MODE */
1612 if (priv->sme_i.sme_flag & SME_AP_SCAN) {
1613 DPRINTK(2, "flag AP_SCAN\n");
1617 if (priv->aplist.size == 0) {
1618 /* Client error, no scan results...
1619 * The caller need to restart the scan. */
1620 DPRINTK(2, "aplist 0\n");
1624 /* current connect ap */
1625 if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
1626 if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) {
1630 current_ev = ks_wlan_translate_scan(dev, current_ev,
1631 // extra + IW_SCAN_MAX_DATA,
1632 extra + dwrq->length,
1633 &(priv->current_ap));
1636 /* Read and parse all entries */
1637 for (i = 0; i < priv->aplist.size; i++) {
1638 if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) {
1642 /* Translate to WE format this entry */
1643 current_ev = ks_wlan_translate_scan(dev, info, current_ev,
1644 // extra + IW_SCAN_MAX_DATA,
1645 extra + dwrq->length,
1646 &(priv->aplist.ap[i]));
1648 /* Length of data */
1649 dwrq->length = (current_ev - extra);
1655 /*------------------------------------------------------------------*/
1656 /* Commit handler : called after a bunch of SET operations */
1657 static int ks_wlan_config_commit(struct net_device *dev,
1658 struct iw_request_info *info, void *zwrq,
1661 struct ks_wlan_private *priv =
1662 (struct ks_wlan_private *)netdev_priv(dev);
1664 if (!priv->need_commit)
1667 ks_wlan_setup_parameter(priv, priv->need_commit);
1668 priv->need_commit = 0;
1672 /*------------------------------------------------------------------*/
1673 /* Wireless handler : set association ie params */
1674 static int ks_wlan_set_genie(struct net_device *dev,
1675 struct iw_request_info *info,
1676 struct iw_point *dwrq, char *extra)
1678 struct ks_wlan_private *priv =
1679 (struct ks_wlan_private *)netdev_priv(dev);
1683 if (priv->sleep_mode == SLP_SLEEP) {
1686 /* for SLEEP MODE */
1688 // return -EOPNOTSUPP;
1691 /*------------------------------------------------------------------*/
1692 /* Wireless handler : set authentication mode params */
1693 static int ks_wlan_set_auth_mode(struct net_device *dev,
1694 struct iw_request_info *info,
1695 struct iw_param *vwrq, char *extra)
1697 struct ks_wlan_private *priv =
1698 (struct ks_wlan_private *)netdev_priv(dev);
1699 int index = (vwrq->flags & IW_AUTH_INDEX);
1700 int value = vwrq->value;
1702 DPRINTK(2, "index=%d:value=%08X\n", index, value);
1704 if (priv->sleep_mode == SLP_SLEEP) {
1707 /* for SLEEP MODE */
1709 case IW_AUTH_WPA_VERSION: /* 0 */
1711 case IW_AUTH_WPA_VERSION_DISABLED:
1712 priv->wpa.version = value;
1713 if (priv->wpa.rsn_enabled) {
1714 priv->wpa.rsn_enabled = 0;
1716 priv->need_commit |= SME_RSN;
1718 case IW_AUTH_WPA_VERSION_WPA:
1719 case IW_AUTH_WPA_VERSION_WPA2:
1720 priv->wpa.version = value;
1721 if (!(priv->wpa.rsn_enabled)) {
1722 priv->wpa.rsn_enabled = 1;
1724 priv->need_commit |= SME_RSN;
1730 case IW_AUTH_CIPHER_PAIRWISE: /* 1 */
1732 case IW_AUTH_CIPHER_NONE:
1733 if (priv->reg.privacy_invoked) {
1734 priv->reg.privacy_invoked = 0x00;
1735 priv->need_commit |= SME_WEP_FLAG;
1738 case IW_AUTH_CIPHER_WEP40:
1739 case IW_AUTH_CIPHER_TKIP:
1740 case IW_AUTH_CIPHER_CCMP:
1741 case IW_AUTH_CIPHER_WEP104:
1742 if (!priv->reg.privacy_invoked) {
1743 priv->reg.privacy_invoked = 0x01;
1744 priv->need_commit |= SME_WEP_FLAG;
1746 priv->wpa.pairwise_suite = value;
1747 priv->need_commit |= SME_RSN_UNICAST;
1753 case IW_AUTH_CIPHER_GROUP: /* 2 */
1755 case IW_AUTH_CIPHER_NONE:
1756 if (priv->reg.privacy_invoked) {
1757 priv->reg.privacy_invoked = 0x00;
1758 priv->need_commit |= SME_WEP_FLAG;
1761 case IW_AUTH_CIPHER_WEP40:
1762 case IW_AUTH_CIPHER_TKIP:
1763 case IW_AUTH_CIPHER_CCMP:
1764 case IW_AUTH_CIPHER_WEP104:
1765 if (!priv->reg.privacy_invoked) {
1766 priv->reg.privacy_invoked = 0x01;
1767 priv->need_commit |= SME_WEP_FLAG;
1769 priv->wpa.group_suite = value;
1770 priv->need_commit |= SME_RSN_MULTICAST;
1776 case IW_AUTH_KEY_MGMT: /* 3 */
1778 case IW_AUTH_KEY_MGMT_802_1X:
1779 case IW_AUTH_KEY_MGMT_PSK:
1780 case 0: /* NONE or 802_1X_NO_WPA */
1781 case 4: /* WPA_NONE */
1782 priv->wpa.key_mgmt_suite = value;
1783 priv->need_commit |= SME_RSN_AUTH;
1789 case IW_AUTH_80211_AUTH_ALG: /* 6 */
1791 case IW_AUTH_ALG_OPEN_SYSTEM:
1792 priv->wpa.auth_alg = value;
1793 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
1795 case IW_AUTH_ALG_SHARED_KEY:
1796 priv->wpa.auth_alg = value;
1797 priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
1799 case IW_AUTH_ALG_LEAP:
1803 priv->need_commit |= SME_MODE_SET;
1805 case IW_AUTH_WPA_ENABLED: /* 7 */
1806 priv->wpa.wpa_enabled = value;
1808 case IW_AUTH_PRIVACY_INVOKED: /* 10 */
1809 if ((value && !priv->reg.privacy_invoked) ||
1810 (!value && priv->reg.privacy_invoked)) {
1811 priv->reg.privacy_invoked = value ? 0x01 : 0x00;
1812 priv->need_commit |= SME_WEP_FLAG;
1815 case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* 4 */
1816 case IW_AUTH_TKIP_COUNTERMEASURES: /* 5 */
1817 case IW_AUTH_DROP_UNENCRYPTED: /* 8 */
1818 case IW_AUTH_ROAMING_CONTROL: /* 9 */
1823 /* return -EINPROGRESS; */
1824 if (priv->need_commit) {
1825 ks_wlan_setup_parameter(priv, priv->need_commit);
1826 priv->need_commit = 0;
1831 /*------------------------------------------------------------------*/
1832 /* Wireless handler : get authentication mode params */
1833 static int ks_wlan_get_auth_mode(struct net_device *dev,
1834 struct iw_request_info *info,
1835 struct iw_param *vwrq, char *extra)
1837 struct ks_wlan_private *priv =
1838 (struct ks_wlan_private *)netdev_priv(dev);
1839 int index = (vwrq->flags & IW_AUTH_INDEX);
1840 DPRINTK(2, "index=%d\n", index);
1842 if (priv->sleep_mode == SLP_SLEEP) {
1846 /* for SLEEP MODE */
1847 /* WPA (not used ?? wpa_supplicant) */
1849 case IW_AUTH_WPA_VERSION:
1850 vwrq->value = priv->wpa.version;
1852 case IW_AUTH_CIPHER_PAIRWISE:
1853 vwrq->value = priv->wpa.pairwise_suite;
1855 case IW_AUTH_CIPHER_GROUP:
1856 vwrq->value = priv->wpa.group_suite;
1858 case IW_AUTH_KEY_MGMT:
1859 vwrq->value = priv->wpa.key_mgmt_suite;
1861 case IW_AUTH_80211_AUTH_ALG:
1862 vwrq->value = priv->wpa.auth_alg;
1864 case IW_AUTH_WPA_ENABLED:
1865 vwrq->value = priv->wpa.rsn_enabled;
1867 case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* OK??? */
1868 case IW_AUTH_TKIP_COUNTERMEASURES:
1869 case IW_AUTH_DROP_UNENCRYPTED:
1871 /* return -EOPNOTSUPP; */
1877 /*------------------------------------------------------------------*/
1878 /* Wireless Handler : set encoding token & mode (WPA)*/
1879 static int ks_wlan_set_encode_ext(struct net_device *dev,
1880 struct iw_request_info *info,
1881 struct iw_point *dwrq, char *extra)
1883 struct ks_wlan_private *priv =
1884 (struct ks_wlan_private *)netdev_priv(dev);
1885 struct iw_encode_ext *enc;
1886 int index = dwrq->flags & IW_ENCODE_INDEX;
1887 unsigned int commit = 0;
1889 enc = (struct iw_encode_ext *)extra;
1891 DPRINTK(2, "flags=%04X:: ext_flags=%08X\n", dwrq->flags,
1894 if (priv->sleep_mode == SLP_SLEEP) {
1897 /* for SLEEP MODE */
1898 if (index < 1 || index > 4)
1903 if (dwrq->flags & IW_ENCODE_DISABLED) {
1904 priv->wpa.key[index].key_len = 0;
1908 priv->wpa.key[index].ext_flags = enc->ext_flags;
1909 if (enc->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
1910 priv->wpa.txkey = index;
1911 commit |= SME_WEP_INDEX;
1912 } else if (enc->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
1913 memcpy(&priv->wpa.key[index].rx_seq[0],
1914 enc->rx_seq, IW_ENCODE_SEQ_MAX_SIZE);
1917 memcpy(&priv->wpa.key[index].addr.sa_data[0],
1918 &enc->addr.sa_data[0], ETH_ALEN);
1921 case IW_ENCODE_ALG_NONE:
1922 if (priv->reg.privacy_invoked) {
1923 priv->reg.privacy_invoked = 0x00;
1924 commit |= SME_WEP_FLAG;
1926 priv->wpa.key[index].key_len = 0;
1929 case IW_ENCODE_ALG_WEP:
1930 case IW_ENCODE_ALG_CCMP:
1931 if (!priv->reg.privacy_invoked) {
1932 priv->reg.privacy_invoked = 0x01;
1933 commit |= SME_WEP_FLAG;
1936 memcpy(&priv->wpa.key[index].key_val[0],
1937 &enc->key[0], enc->key_len);
1938 priv->wpa.key[index].key_len = enc->key_len;
1939 commit |= (SME_WEP_VAL1 << index);
1942 case IW_ENCODE_ALG_TKIP:
1943 if (!priv->reg.privacy_invoked) {
1944 priv->reg.privacy_invoked = 0x01;
1945 commit |= SME_WEP_FLAG;
1947 if (enc->key_len == 32) {
1948 memcpy(&priv->wpa.key[index].key_val[0],
1949 &enc->key[0], enc->key_len - 16);
1950 priv->wpa.key[index].key_len =
1952 if (priv->wpa.key_mgmt_suite == 4) { /* WPA_NONE */
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[16], 8);
1958 memcpy(&priv->wpa.key[index].
1959 tx_mic_key[0], &enc->key[16], 8);
1960 memcpy(&priv->wpa.key[index].
1961 rx_mic_key[0], &enc->key[24], 8);
1963 commit |= (SME_WEP_VAL1 << index);
1969 priv->wpa.key[index].alg = enc->alg;
1974 if (commit & SME_WEP_INDEX)
1975 hostif_sme_enqueue(priv, SME_SET_TXKEY);
1976 if (commit & SME_WEP_VAL_MASK)
1977 hostif_sme_enqueue(priv, SME_SET_KEY1 + index);
1978 if (commit & SME_WEP_FLAG)
1979 hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
1985 /*------------------------------------------------------------------*/
1986 /* Wireless Handler : get encoding token & mode (WPA)*/
1987 static int ks_wlan_get_encode_ext(struct net_device *dev,
1988 struct iw_request_info *info,
1989 struct iw_point *dwrq, char *extra)
1991 struct ks_wlan_private *priv =
1992 (struct ks_wlan_private *)netdev_priv(dev);
1994 if (priv->sleep_mode == SLP_SLEEP) {
1998 /* for SLEEP MODE */
1999 /* WPA (not used ?? wpa_supplicant)
2000 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2001 struct iw_encode_ext *enc;
2002 enc = (struct iw_encode_ext *)extra;
2003 int index = dwrq->flags & IW_ENCODE_INDEX;
2004 WPA (not used ?? wpa_supplicant) */
2008 /*------------------------------------------------------------------*/
2009 /* Wireless Handler : PMKSA cache operation (WPA2) */
2010 static int ks_wlan_set_pmksa(struct net_device *dev,
2011 struct iw_request_info *info,
2012 struct iw_point *dwrq, char *extra)
2014 struct ks_wlan_private *priv =
2015 (struct ks_wlan_private *)netdev_priv(dev);
2016 struct iw_pmksa *pmksa;
2019 struct list_head *ptr;
2023 if (priv->sleep_mode == SLP_SLEEP) {
2026 /* for SLEEP MODE */
2030 pmksa = (struct iw_pmksa *)extra;
2031 DPRINTK(2, "cmd=%d\n", pmksa->cmd);
2033 switch (pmksa->cmd) {
2035 if (list_empty(&priv->pmklist.head)) { /* new list */
2036 for (i = 0; i < PMK_LIST_MAX; i++) {
2037 pmk = &priv->pmklist.pmk[i];
2039 ("\x00\x00\x00\x00\x00\x00", pmk->bssid,
2043 memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
2044 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
2045 list_add(&pmk->list, &priv->pmklist.head);
2046 priv->pmklist.size++;
2047 } else { /* search cache data */
2048 list_for_each(ptr, &priv->pmklist.head) {
2049 pmk = list_entry(ptr, struct pmk_t, list);
2050 if (!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)) { /* match address! list move to head. */
2051 memcpy(pmk->pmkid, pmksa->pmkid,
2053 list_move(&pmk->list,
2054 &priv->pmklist.head);
2058 if (ptr == &priv->pmklist.head) { /* not find address. */
2059 if (PMK_LIST_MAX > priv->pmklist.size) { /* new cache data */
2060 for (i = 0; i < PMK_LIST_MAX; i++) {
2061 pmk = &priv->pmklist.pmk[i];
2063 ("\x00\x00\x00\x00\x00\x00",
2064 pmk->bssid, ETH_ALEN))
2067 memcpy(pmk->bssid, pmksa->bssid.sa_data,
2069 memcpy(pmk->pmkid, pmksa->pmkid,
2071 list_add(&pmk->list,
2072 &priv->pmklist.head);
2073 priv->pmklist.size++;
2074 } else { /* overwrite old cache data */
2076 list_entry(priv->pmklist.head.prev,
2077 struct pmk_t, list);
2078 memcpy(pmk->bssid, pmksa->bssid.sa_data,
2080 memcpy(pmk->pmkid, pmksa->pmkid,
2082 list_move(&pmk->list,
2083 &priv->pmklist.head);
2088 case IW_PMKSA_REMOVE:
2089 if (list_empty(&priv->pmklist.head)) { /* list empty */
2091 } else { /* search cache data */
2092 list_for_each(ptr, &priv->pmklist.head) {
2093 pmk = list_entry(ptr, struct pmk_t, list);
2094 if (!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)) { /* match address! list del. */
2095 memset(pmk->bssid, 0, ETH_ALEN);
2096 memset(pmk->pmkid, 0, IW_PMKID_LEN);
2097 list_del_init(&pmk->list);
2101 if (ptr == &priv->pmklist.head) { /* not find address. */
2106 case IW_PMKSA_FLUSH:
2107 memset(&(priv->pmklist), 0, sizeof(priv->pmklist));
2108 INIT_LIST_HEAD(&priv->pmklist.head);
2109 for (i = 0; i < PMK_LIST_MAX; i++)
2110 INIT_LIST_HEAD(&priv->pmklist.pmk[i].list);
2116 hostif_sme_enqueue(priv, SME_SET_PMKSA);
2120 static struct iw_statistics *ks_get_wireless_stats(struct net_device *dev)
2123 struct ks_wlan_private *priv =
2124 (struct ks_wlan_private *)netdev_priv(dev);
2125 struct iw_statistics *wstats = &priv->wstats;
2127 if (!atomic_read(&update_phyinfo)) {
2128 if (priv->dev_state < DEVICE_STATE_READY)
2129 return NULL; /* not finished initialize */
2134 /* Packets discarded in the wireless adapter due to wireless
2135 * specific problems */
2136 wstats->discard.nwid = 0; /* Rx invalid nwid */
2137 wstats->discard.code = 0; /* Rx invalid crypt */
2138 wstats->discard.fragment = 0; /* Rx invalid frag */
2139 wstats->discard.retries = 0; /* Tx excessive retries */
2140 wstats->discard.misc = 0; /* Invalid misc */
2141 wstats->miss.beacon = 0; /* Missed beacon */
2146 /*------------------------------------------------------------------*/
2147 /* Private handler : set stop request */
2148 static int ks_wlan_set_stop_request(struct net_device *dev,
2149 struct iw_request_info *info, __u32 * uwrq,
2152 struct ks_wlan_private *priv =
2153 (struct ks_wlan_private *)netdev_priv(dev);
2156 if (priv->sleep_mode == SLP_SLEEP) {
2159 /* for SLEEP MODE */
2163 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2167 /*------------------------------------------------------------------*/
2168 /* Wireless Handler : set MLME */
2169 #include <linux/ieee80211.h>
2170 static int ks_wlan_set_mlme(struct net_device *dev,
2171 struct iw_request_info *info, struct iw_point *dwrq,
2174 struct ks_wlan_private *priv =
2175 (struct ks_wlan_private *)netdev_priv(dev);
2176 struct iw_mlme *mlme = (struct iw_mlme *)extra;
2179 DPRINTK(2, ":%d :%d\n", mlme->cmd, mlme->reason_code);
2181 if (priv->sleep_mode == SLP_SLEEP) {
2184 /* for SLEEP MODE */
2185 switch (mlme->cmd) {
2186 case IW_MLME_DEAUTH:
2187 if (mlme->reason_code == WLAN_REASON_MIC_FAILURE) {
2190 case IW_MLME_DISASSOC:
2192 return ks_wlan_set_stop_request(dev, NULL, &mode, NULL);
2194 return -EOPNOTSUPP; /* Not Support */
2198 /*------------------------------------------------------------------*/
2199 /* Private handler : get firemware version */
2200 static int ks_wlan_get_firmware_version(struct net_device *dev,
2201 struct iw_request_info *info,
2202 struct iw_point *dwrq, char *extra)
2204 struct ks_wlan_private *priv =
2205 (struct ks_wlan_private *)netdev_priv(dev);
2206 strcpy(extra, &(priv->firmware_version[0]));
2207 dwrq->length = priv->version_size + 1;
2212 /*------------------------------------------------------------------*/
2213 /* Private handler : set force disconnect status */
2214 static int ks_wlan_set_detach(struct net_device *dev,
2215 struct iw_request_info *info, __u32 * uwrq,
2218 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2220 if (priv->sleep_mode == SLP_SLEEP) {
2223 /* for SLEEP MODE */
2224 if (*uwrq == CONNECT_STATUS) { /* 0 */
2225 priv->connect_status &= ~FORCE_DISCONNECT;
2226 if ((priv->connect_status & CONNECT_STATUS_MASK) ==
2228 netif_carrier_on(dev);
2229 } else if (*uwrq == DISCONNECT_STATUS) { /* 1 */
2230 priv->connect_status |= FORCE_DISCONNECT;
2231 netif_carrier_off(dev);
2237 /*------------------------------------------------------------------*/
2238 /* Private handler : get force disconnect status */
2239 static int ks_wlan_get_detach(struct net_device *dev,
2240 struct iw_request_info *info, __u32 * uwrq,
2243 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2245 if (priv->sleep_mode == SLP_SLEEP) {
2248 /* for SLEEP MODE */
2249 *uwrq = ((priv->connect_status & FORCE_DISCONNECT) ? 1 : 0);
2253 /*------------------------------------------------------------------*/
2254 /* Private handler : get connect status */
2255 static int ks_wlan_get_connect(struct net_device *dev,
2256 struct iw_request_info *info, __u32 * uwrq,
2259 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2261 if (priv->sleep_mode == SLP_SLEEP) {
2264 /* for SLEEP MODE */
2265 *uwrq = (priv->connect_status & CONNECT_STATUS_MASK);
2270 /*------------------------------------------------------------------*/
2271 /* Private handler : set preamble */
2272 static int ks_wlan_set_preamble(struct net_device *dev,
2273 struct iw_request_info *info, __u32 * uwrq,
2276 struct ks_wlan_private *priv =
2277 (struct ks_wlan_private *)netdev_priv(dev);
2279 if (priv->sleep_mode == SLP_SLEEP) {
2282 /* for SLEEP MODE */
2283 if (*uwrq == LONG_PREAMBLE) { /* 0 */
2284 priv->reg.preamble = LONG_PREAMBLE;
2285 } else if (*uwrq == SHORT_PREAMBLE) { /* 1 */
2286 priv->reg.preamble = SHORT_PREAMBLE;
2290 priv->need_commit |= SME_MODE_SET;
2291 return -EINPROGRESS; /* Call commit handler */
2295 /*------------------------------------------------------------------*/
2296 /* Private handler : get preamble */
2297 static int ks_wlan_get_preamble(struct net_device *dev,
2298 struct iw_request_info *info, __u32 * uwrq,
2301 struct ks_wlan_private *priv =
2302 (struct ks_wlan_private *)netdev_priv(dev);
2304 if (priv->sleep_mode == SLP_SLEEP) {
2307 /* for SLEEP MODE */
2308 *uwrq = priv->reg.preamble;
2312 /*------------------------------------------------------------------*/
2313 /* Private handler : set power save mode */
2314 static int ks_wlan_set_powermgt(struct net_device *dev,
2315 struct iw_request_info *info, __u32 * uwrq,
2318 struct ks_wlan_private *priv =
2319 (struct ks_wlan_private *)netdev_priv(dev);
2321 if (priv->sleep_mode == SLP_SLEEP) {
2324 /* for SLEEP MODE */
2325 if (*uwrq == POWMGT_ACTIVE_MODE) { /* 0 */
2326 priv->reg.powermgt = POWMGT_ACTIVE_MODE;
2327 } else if (*uwrq == POWMGT_SAVE1_MODE) { /* 1 */
2328 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2329 priv->reg.powermgt = POWMGT_SAVE1_MODE;
2332 } else if (*uwrq == POWMGT_SAVE2_MODE) { /* 2 */
2333 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2334 priv->reg.powermgt = POWMGT_SAVE2_MODE;
2340 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
2345 /*------------------------------------------------------------------*/
2346 /* Private handler : get power save made */
2347 static int ks_wlan_get_powermgt(struct net_device *dev,
2348 struct iw_request_info *info, __u32 * uwrq,
2351 struct ks_wlan_private *priv =
2352 (struct ks_wlan_private *)netdev_priv(dev);
2354 if (priv->sleep_mode == SLP_SLEEP) {
2357 /* for SLEEP MODE */
2358 *uwrq = priv->reg.powermgt;
2362 /*------------------------------------------------------------------*/
2363 /* Private handler : set scan type */
2364 static int ks_wlan_set_scan_type(struct net_device *dev,
2365 struct iw_request_info *info, __u32 * uwrq,
2368 struct ks_wlan_private *priv =
2369 (struct ks_wlan_private *)netdev_priv(dev);
2371 if (priv->sleep_mode == SLP_SLEEP) {
2374 /* for SLEEP MODE */
2375 if (*uwrq == ACTIVE_SCAN) { /* 0 */
2376 priv->reg.scan_type = ACTIVE_SCAN;
2377 } else if (*uwrq == PASSIVE_SCAN) { /* 1 */
2378 priv->reg.scan_type = PASSIVE_SCAN;
2385 /*------------------------------------------------------------------*/
2386 /* Private handler : get scan type */
2387 static int ks_wlan_get_scan_type(struct net_device *dev,
2388 struct iw_request_info *info, __u32 * uwrq,
2391 struct ks_wlan_private *priv =
2392 (struct ks_wlan_private *)netdev_priv(dev);
2394 if (priv->sleep_mode == SLP_SLEEP) {
2397 /* for SLEEP MODE */
2398 *uwrq = priv->reg.scan_type;
2403 /*------------------------------------------------------------------*/
2404 /* Private handler : write raw data to device */
2405 static int ks_wlan_data_write(struct net_device *dev,
2406 struct iw_request_info *info,
2407 struct iw_point *dwrq, char *extra)
2409 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2410 unsigned char *wbuff = NULL;
2412 if (priv->sleep_mode == SLP_SLEEP) {
2415 /* for SLEEP MODE */
2416 wbuff = (unsigned char *)kmalloc(dwrq->length, GFP_ATOMIC);
2419 memcpy(wbuff, extra, dwrq->length);
2421 /* write to device */
2422 ks_wlan_hw_tx(priv, wbuff, dwrq->length, NULL, NULL, NULL);
2427 /*------------------------------------------------------------------*/
2428 /* Private handler : read raw data form device */
2429 static int ks_wlan_data_read(struct net_device *dev,
2430 struct iw_request_info *info,
2431 struct iw_point *dwrq, char *extra)
2433 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2434 unsigned short read_length;
2436 if (priv->sleep_mode == SLP_SLEEP) {
2439 /* for SLEEP MODE */
2440 if (!atomic_read(&priv->event_count)) {
2441 if (priv->dev_state < DEVICE_STATE_BOOT) { /* Remove device */
2443 memset(extra, 0xff, read_length);
2444 dwrq->length = read_length;
2448 memset(extra, 0, 1);
2453 if (atomic_read(&priv->event_count) > 0)
2454 atomic_dec(&priv->event_count);
2456 spin_lock(&priv->dev_read_lock); /* request spin lock */
2458 /* Copy length max size 0x07ff */
2459 if (priv->dev_size[priv->dev_count] > 2047)
2462 read_length = priv->dev_size[priv->dev_count];
2465 memcpy(extra, &(priv->dev_data[priv->dev_count][0]), read_length);
2467 spin_unlock(&priv->dev_read_lock); /* release spin lock */
2470 priv->dev_data[priv->dev_count] = 0;
2471 priv->dev_size[priv->dev_count] = 0;
2474 if (priv->dev_count == DEVICE_STOCK_COUNT)
2475 priv->dev_count = 0;
2478 dwrq->length = read_length;
2485 /*------------------------------------------------------------------*/
2486 /* Private handler : get wep string */
2487 #define WEP_ASCII_BUFF_SIZE (17+64*4+1)
2488 static int ks_wlan_get_wep_ascii(struct net_device *dev,
2489 struct iw_request_info *info,
2490 struct iw_point *dwrq, char *extra)
2492 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2494 char tmp[WEP_ASCII_BUFF_SIZE];
2496 if (priv->sleep_mode == SLP_SLEEP) {
2499 /* for SLEEP MODE */
2500 strcpy(tmp, " WEP keys ASCII \n");
2501 len += strlen(" WEP keys ASCII \n");
2503 for (i = 0; i < 4; i++) {
2504 strcpy(tmp + len, "\t[");
2505 len += strlen("\t[");
2508 strcpy(tmp + len, "] ");
2509 len += strlen("] ");
2510 if (priv->reg.wep_key[i].size) {
2512 (priv->reg.wep_key[i].size <
2513 6 ? "(40bits) [" : "(104bits) ["));
2515 strlen((priv->reg.wep_key[i].size <
2516 6 ? "(40bits) [" : "(104bits) ["));
2517 for (j = 0; j < priv->reg.wep_key[i].size; j++, len++)
2519 (isprint(priv->reg.wep_key[i].val[j]) ?
2520 priv->reg.wep_key[i].val[j] : ' ');
2522 strcpy(tmp + len, "]\n");
2523 len += strlen("]\n");
2525 strcpy(tmp + len, "off\n");
2526 len += strlen("off\n");
2530 memcpy(extra, tmp, len);
2531 dwrq->length = len + 1;
2536 /*------------------------------------------------------------------*/
2537 /* Private handler : set beacon lost count */
2538 static int ks_wlan_set_beacon_lost(struct net_device *dev,
2539 struct iw_request_info *info, __u32 * uwrq,
2542 struct ks_wlan_private *priv =
2543 (struct ks_wlan_private *)netdev_priv(dev);
2545 if (priv->sleep_mode == SLP_SLEEP) {
2548 /* for SLEEP MODE */
2549 if (*uwrq >= BEACON_LOST_COUNT_MIN && *uwrq <= BEACON_LOST_COUNT_MAX) {
2550 priv->reg.beacon_lost_count = *uwrq;
2554 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
2555 priv->need_commit |= SME_MODE_SET;
2556 return -EINPROGRESS; /* Call commit handler */
2561 /*------------------------------------------------------------------*/
2562 /* Private handler : get beacon lost count */
2563 static int ks_wlan_get_beacon_lost(struct net_device *dev,
2564 struct iw_request_info *info, __u32 * uwrq,
2567 struct ks_wlan_private *priv =
2568 (struct ks_wlan_private *)netdev_priv(dev);
2570 if (priv->sleep_mode == SLP_SLEEP) {
2573 /* for SLEEP MODE */
2574 *uwrq = priv->reg.beacon_lost_count;
2578 /*------------------------------------------------------------------*/
2579 /* Private handler : set phy type */
2580 static int ks_wlan_set_phy_type(struct net_device *dev,
2581 struct iw_request_info *info, __u32 * uwrq,
2584 struct ks_wlan_private *priv =
2585 (struct ks_wlan_private *)netdev_priv(dev);
2587 if (priv->sleep_mode == SLP_SLEEP) {
2590 /* for SLEEP MODE */
2591 if (*uwrq == D_11B_ONLY_MODE) { /* 0 */
2592 priv->reg.phy_type = D_11B_ONLY_MODE;
2593 } else if (*uwrq == D_11G_ONLY_MODE) { /* 1 */
2594 priv->reg.phy_type = D_11G_ONLY_MODE;
2595 } else if (*uwrq == D_11BG_COMPATIBLE_MODE) { /* 2 */
2596 priv->reg.phy_type = D_11BG_COMPATIBLE_MODE;
2600 priv->need_commit |= SME_MODE_SET;
2601 return -EINPROGRESS; /* Call commit handler */
2604 /*------------------------------------------------------------------*/
2605 /* Private handler : get phy type */
2606 static int ks_wlan_get_phy_type(struct net_device *dev,
2607 struct iw_request_info *info, __u32 * uwrq,
2610 struct ks_wlan_private *priv =
2611 (struct ks_wlan_private *)netdev_priv(dev);
2613 if (priv->sleep_mode == SLP_SLEEP) {
2616 /* for SLEEP MODE */
2617 *uwrq = priv->reg.phy_type;
2621 /*------------------------------------------------------------------*/
2622 /* Private handler : set cts mode */
2623 static int ks_wlan_set_cts_mode(struct net_device *dev,
2624 struct iw_request_info *info, __u32 * uwrq,
2627 struct ks_wlan_private *priv =
2628 (struct ks_wlan_private *)netdev_priv(dev);
2630 if (priv->sleep_mode == SLP_SLEEP) {
2633 /* for SLEEP MODE */
2634 if (*uwrq == CTS_MODE_FALSE) { /* 0 */
2635 priv->reg.cts_mode = CTS_MODE_FALSE;
2636 } else if (*uwrq == CTS_MODE_TRUE) { /* 1 */
2637 if (priv->reg.phy_type == D_11G_ONLY_MODE ||
2638 priv->reg.phy_type == D_11BG_COMPATIBLE_MODE)
2639 priv->reg.cts_mode = CTS_MODE_TRUE;
2641 priv->reg.cts_mode = CTS_MODE_FALSE;
2645 priv->need_commit |= SME_MODE_SET;
2646 return -EINPROGRESS; /* Call commit handler */
2649 /*------------------------------------------------------------------*/
2650 /* Private handler : get cts mode */
2651 static int ks_wlan_get_cts_mode(struct net_device *dev,
2652 struct iw_request_info *info, __u32 * uwrq,
2655 struct ks_wlan_private *priv =
2656 (struct ks_wlan_private *)netdev_priv(dev);
2658 if (priv->sleep_mode == SLP_SLEEP) {
2661 /* for SLEEP MODE */
2662 *uwrq = priv->reg.cts_mode;
2666 /*------------------------------------------------------------------*/
2667 /* Private handler : set sleep mode */
2668 static int ks_wlan_set_sleep_mode(struct net_device *dev,
2669 struct iw_request_info *info,
2670 __u32 * uwrq, char *extra)
2672 struct ks_wlan_private *priv =
2673 (struct ks_wlan_private *)netdev_priv(dev);
2677 if (*uwrq == SLP_SLEEP) {
2678 priv->sleep_mode = *uwrq;
2679 printk("SET_SLEEP_MODE %d\n", priv->sleep_mode);
2681 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2682 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2684 } else if (*uwrq == SLP_ACTIVE) {
2685 priv->sleep_mode = *uwrq;
2686 printk("SET_SLEEP_MODE %d\n", priv->sleep_mode);
2687 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2689 printk("SET_SLEEP_MODE %d errror\n", *uwrq);
2696 /*------------------------------------------------------------------*/
2697 /* Private handler : get sleep mode */
2698 static int ks_wlan_get_sleep_mode(struct net_device *dev,
2699 struct iw_request_info *info,
2700 __u32 * uwrq, char *extra)
2702 struct ks_wlan_private *priv =
2703 (struct ks_wlan_private *)netdev_priv(dev);
2705 DPRINTK(2, "GET_SLEEP_MODE %d\n", priv->sleep_mode);
2706 *uwrq = priv->sleep_mode;
2712 /*------------------------------------------------------------------*/
2713 /* Private handler : set phy information timer */
2714 static int ks_wlan_set_phy_information_timer(struct net_device *dev,
2715 struct iw_request_info *info,
2716 __u32 * uwrq, char *extra)
2718 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2720 if (priv->sleep_mode == SLP_SLEEP) {
2723 /* for SLEEP MODE */
2724 if (*uwrq >= 0 && *uwrq <= 0xFFFF) /* 0-65535 */
2725 priv->reg.phy_info_timer = (uint16_t) * uwrq;
2729 hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST);
2734 /*------------------------------------------------------------------*/
2735 /* Private handler : get phy information timer */
2736 static int ks_wlan_get_phy_information_timer(struct net_device *dev,
2737 struct iw_request_info *info,
2738 __u32 * uwrq, char *extra)
2740 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2742 if (priv->sleep_mode == SLP_SLEEP) {
2745 /* for SLEEP MODE */
2746 *uwrq = priv->reg.phy_info_timer;
2752 /*------------------------------------------------------------------*/
2753 /* Private handler : set WPS enable */
2754 static int ks_wlan_set_wps_enable(struct net_device *dev,
2755 struct iw_request_info *info, __u32 * uwrq,
2758 struct ks_wlan_private *priv =
2759 (struct ks_wlan_private *)netdev_priv(dev);
2762 if (priv->sleep_mode == SLP_SLEEP) {
2765 /* for SLEEP MODE */
2766 if (*uwrq == 0 || *uwrq == 1)
2767 priv->wps.wps_enabled = *uwrq;
2771 hostif_sme_enqueue(priv, SME_WPS_ENABLE_REQUEST);
2776 /*------------------------------------------------------------------*/
2777 /* Private handler : get WPS enable */
2778 static int ks_wlan_get_wps_enable(struct net_device *dev,
2779 struct iw_request_info *info, __u32 * uwrq,
2782 struct ks_wlan_private *priv =
2783 (struct ks_wlan_private *)netdev_priv(dev);
2786 if (priv->sleep_mode == SLP_SLEEP) {
2789 /* for SLEEP MODE */
2790 *uwrq = priv->wps.wps_enabled;
2791 printk("return=%d\n", *uwrq);
2796 /*------------------------------------------------------------------*/
2797 /* Private handler : set WPS probe req */
2798 static int ks_wlan_set_wps_probe_req(struct net_device *dev,
2799 struct iw_request_info *info,
2800 struct iw_point *dwrq, char *extra)
2804 struct ks_wlan_private *priv =
2805 (struct ks_wlan_private *)netdev_priv(dev);
2809 if (priv->sleep_mode == SLP_SLEEP) {
2812 /* for SLEEP MODE */
2813 DPRINTK(2, "dwrq->length=%d\n", dwrq->length);
2816 if (p[1] + 2 != dwrq->length || dwrq->length > 256) {
2820 priv->wps.ielen = p[1] + 2 + 1; /* IE header + IE + sizeof(len) */
2821 len = p[1] + 2; /* IE header + IE */
2823 memcpy(priv->wps.ie, &len, sizeof(len));
2824 p = memcpy(priv->wps.ie + 1, p, len);
2826 DPRINTK(2, "%d(%#x): %02X %02X %02X %02X ... %02X %02X %02X\n",
2827 priv->wps.ielen, priv->wps.ielen, p[0], p[1], p[2], p[3],
2828 p[priv->wps.ielen - 3], p[priv->wps.ielen - 2],
2829 p[priv->wps.ielen - 1]);
2831 hostif_sme_enqueue(priv, SME_WPS_PROBE_REQUEST);
2837 /*------------------------------------------------------------------*/
2838 /* Private handler : get WPS probe req */
2839 static int ks_wlan_get_wps_probe_req(struct net_device *dev,
2840 struct iw_request_info *info,
2841 __u32 * uwrq, char *extra)
2843 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2846 if (priv->sleep_mode == SLP_SLEEP) {
2849 /* for SLEEP MODE */
2855 /*------------------------------------------------------------------*/
2856 /* Private handler : set tx gain control value */
2857 static int ks_wlan_set_tx_gain(struct net_device *dev,
2858 struct iw_request_info *info, __u32 * uwrq,
2861 struct ks_wlan_private *priv =
2862 (struct ks_wlan_private *)netdev_priv(dev);
2864 if (priv->sleep_mode == SLP_SLEEP) {
2867 /* for SLEEP MODE */
2868 if (*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2869 priv->gain.TxGain = (uint8_t) * uwrq;
2873 if (priv->gain.TxGain < 0xFF)
2874 priv->gain.TxMode = 1;
2876 priv->gain.TxMode = 0;
2878 hostif_sme_enqueue(priv, SME_SET_GAIN);
2882 /*------------------------------------------------------------------*/
2883 /* Private handler : get tx gain control value */
2884 static int ks_wlan_get_tx_gain(struct net_device *dev,
2885 struct iw_request_info *info, __u32 * uwrq,
2888 struct ks_wlan_private *priv =
2889 (struct ks_wlan_private *)netdev_priv(dev);
2891 if (priv->sleep_mode == SLP_SLEEP) {
2894 /* for SLEEP MODE */
2895 *uwrq = priv->gain.TxGain;
2896 hostif_sme_enqueue(priv, SME_GET_GAIN);
2900 /*------------------------------------------------------------------*/
2901 /* Private handler : set rx gain control value */
2902 static int ks_wlan_set_rx_gain(struct net_device *dev,
2903 struct iw_request_info *info, __u32 * uwrq,
2906 struct ks_wlan_private *priv =
2907 (struct ks_wlan_private *)netdev_priv(dev);
2909 if (priv->sleep_mode == SLP_SLEEP) {
2912 /* for SLEEP MODE */
2913 if (*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2914 priv->gain.RxGain = (uint8_t) * uwrq;
2918 if (priv->gain.RxGain < 0xFF)
2919 priv->gain.RxMode = 1;
2921 priv->gain.RxMode = 0;
2923 hostif_sme_enqueue(priv, SME_SET_GAIN);
2927 /*------------------------------------------------------------------*/
2928 /* Private handler : get rx gain control value */
2929 static int ks_wlan_get_rx_gain(struct net_device *dev,
2930 struct iw_request_info *info, __u32 * uwrq,
2933 struct ks_wlan_private *priv =
2934 (struct ks_wlan_private *)netdev_priv(dev);
2936 if (priv->sleep_mode == SLP_SLEEP) {
2939 /* for SLEEP MODE */
2940 *uwrq = priv->gain.RxGain;
2941 hostif_sme_enqueue(priv, SME_GET_GAIN);
2946 /*------------------------------------------------------------------*/
2947 /* Private handler : set region value */
2948 static int ks_wlan_set_region(struct net_device *dev,
2949 struct iw_request_info *info, __u32 * uwrq,
2952 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2954 if (priv->sleep_mode == SLP_SLEEP) {
2957 /* for SLEEP MODE */
2958 if (*uwrq >= 0x9 && *uwrq <= 0xF) /* 0x9-0xf */
2959 priv->region = (uint8_t) * uwrq;
2963 hostif_sme_enqueue(priv, SME_SET_REGION);
2968 /*------------------------------------------------------------------*/
2969 /* Private handler : get eeprom checksum result */
2970 static int ks_wlan_get_eeprom_cksum(struct net_device *dev,
2971 struct iw_request_info *info, __u32 * uwrq,
2974 struct ks_wlan_private *priv =
2975 (struct ks_wlan_private *)netdev_priv(dev);
2977 *uwrq = priv->eeprom_checksum;
2981 static void print_hif_event(int event)
2986 printk("HIF_DATA_REQ\n");
2989 printk("HIF_DATA_IND\n");
2991 case HIF_MIB_GET_REQ:
2992 printk("HIF_MIB_GET_REQ\n");
2994 case HIF_MIB_GET_CONF:
2995 printk("HIF_MIB_GET_CONF\n");
2997 case HIF_MIB_SET_REQ:
2998 printk("HIF_MIB_SET_REQ\n");
3000 case HIF_MIB_SET_CONF:
3001 printk("HIF_MIB_SET_CONF\n");
3003 case HIF_POWERMGT_REQ:
3004 printk("HIF_POWERMGT_REQ\n");
3006 case HIF_POWERMGT_CONF:
3007 printk("HIF_POWERMGT_CONF\n");
3010 printk("HIF_START_REQ\n");
3012 case HIF_START_CONF:
3013 printk("HIF_START_CONF\n");
3015 case HIF_CONNECT_IND:
3016 printk("HIF_CONNECT_IND\n");
3019 printk("HIF_STOP_REQ\n");
3022 printk("HIF_STOP_CONF\n");
3024 case HIF_PS_ADH_SET_REQ:
3025 printk("HIF_PS_ADH_SET_REQ\n");
3027 case HIF_PS_ADH_SET_CONF:
3028 printk("HIF_PS_ADH_SET_CONF\n");
3030 case HIF_INFRA_SET_REQ:
3031 printk("HIF_INFRA_SET_REQ\n");
3033 case HIF_INFRA_SET_CONF:
3034 printk("HIF_INFRA_SET_CONF\n");
3036 case HIF_ADH_SET_REQ:
3037 printk("HIF_ADH_SET_REQ\n");
3039 case HIF_ADH_SET_CONF:
3040 printk("HIF_ADH_SET_CONF\n");
3042 case HIF_AP_SET_REQ:
3043 printk("HIF_AP_SET_REQ\n");
3045 case HIF_AP_SET_CONF:
3046 printk("HIF_AP_SET_CONF\n");
3048 case HIF_ASSOC_INFO_IND:
3049 printk("HIF_ASSOC_INFO_IND\n");
3051 case HIF_MIC_FAILURE_REQ:
3052 printk("HIF_MIC_FAILURE_REQ\n");
3054 case HIF_MIC_FAILURE_CONF:
3055 printk("HIF_MIC_FAILURE_CONF\n");
3058 printk("HIF_SCAN_REQ\n");
3061 printk("HIF_SCAN_CONF\n");
3063 case HIF_PHY_INFO_REQ:
3064 printk("HIF_PHY_INFO_REQ\n");
3066 case HIF_PHY_INFO_CONF:
3067 printk("HIF_PHY_INFO_CONF\n");
3070 printk("HIF_SLEEP_REQ\n");
3072 case HIF_SLEEP_CONF:
3073 printk("HIF_SLEEP_CONF\n");
3075 case HIF_PHY_INFO_IND:
3076 printk("HIF_PHY_INFO_IND\n");
3079 printk("HIF_SCAN_IND\n");
3081 case HIF_INFRA_SET2_REQ:
3082 printk("HIF_INFRA_SET2_REQ\n");
3084 case HIF_INFRA_SET2_CONF:
3085 printk("HIF_INFRA_SET2_CONF\n");
3087 case HIF_ADH_SET2_REQ:
3088 printk("HIF_ADH_SET2_REQ\n");
3090 case HIF_ADH_SET2_CONF:
3091 printk("HIF_ADH_SET2_CONF\n");
3095 /*------------------------------------------------------------------*/
3096 /* Private handler : get host command history */
3097 static int ks_wlan_hostt(struct net_device *dev, struct iw_request_info *info,
3098 __u32 * uwrq, char *extra)
3101 struct ks_wlan_private *priv =
3102 (struct ks_wlan_private *)netdev_priv(dev);
3104 for (i = 63; i >= 0; i--) {
3106 priv->hostt.buff[(priv->hostt.qtail - 1 - i) %
3107 SME_EVENT_BUFF_SIZE];
3108 print_hif_event(event);
3113 /* Structures to export the Wireless Handlers */
3115 static const struct iw_priv_args ks_wlan_private_args[] = {
3116 /*{ cmd, set_args, get_args, name[16] } */
3117 {KS_WLAN_GET_FIRM_VERSION, IW_PRIV_TYPE_NONE,
3118 IW_PRIV_TYPE_CHAR | (128 + 1), "GetFirmwareVer"},
3120 {KS_WLAN_SET_WPS_ENABLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3121 IW_PRIV_TYPE_NONE, "SetWPSEnable"},
3122 {KS_WLAN_GET_WPS_ENABLE, IW_PRIV_TYPE_NONE,
3123 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetW"},
3124 {KS_WLAN_SET_WPS_PROBE_REQ, IW_PRIV_TYPE_BYTE | 2047, IW_PRIV_TYPE_NONE,
3127 {KS_WLAN_SET_PREAMBLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3128 IW_PRIV_TYPE_NONE, "SetPreamble"},
3129 {KS_WLAN_GET_PREAMBLE, IW_PRIV_TYPE_NONE,
3130 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPreamble"},
3131 {KS_WLAN_SET_POWER_SAVE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3132 IW_PRIV_TYPE_NONE, "SetPowerSave"},
3133 {KS_WLAN_GET_POWER_SAVE, IW_PRIV_TYPE_NONE,
3134 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPowerSave"},
3135 {KS_WLAN_SET_SCAN_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3136 IW_PRIV_TYPE_NONE, "SetScanType"},
3137 {KS_WLAN_GET_SCAN_TYPE, IW_PRIV_TYPE_NONE,
3138 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetScanType"},
3139 {KS_WLAN_SET_RX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3140 IW_PRIV_TYPE_NONE, "SetRxGain"},
3141 {KS_WLAN_GET_RX_GAIN, IW_PRIV_TYPE_NONE,
3142 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetRxGain"},
3143 {KS_WLAN_HOSTT, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | (128 + 1),
3145 {KS_WLAN_SET_BEACON_LOST, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3146 IW_PRIV_TYPE_NONE, "SetBeaconLost"},
3147 {KS_WLAN_GET_BEACON_LOST, IW_PRIV_TYPE_NONE,
3148 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetBeaconLost"},
3149 {KS_WLAN_SET_SLEEP_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3150 IW_PRIV_TYPE_NONE, "SetSleepMode"},
3151 {KS_WLAN_GET_SLEEP_MODE, IW_PRIV_TYPE_NONE,
3152 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetSleepMode"},
3153 {KS_WLAN_SET_TX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3154 IW_PRIV_TYPE_NONE, "SetTxGain"},
3155 {KS_WLAN_GET_TX_GAIN, IW_PRIV_TYPE_NONE,
3156 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetTxGain"},
3157 {KS_WLAN_SET_PHY_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3158 IW_PRIV_TYPE_NONE, "SetPhyType"},
3159 {KS_WLAN_GET_PHY_TYPE, IW_PRIV_TYPE_NONE,
3160 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPhyType"},
3161 {KS_WLAN_SET_CTS_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3162 IW_PRIV_TYPE_NONE, "SetCtsMode"},
3163 {KS_WLAN_GET_CTS_MODE, IW_PRIV_TYPE_NONE,
3164 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetCtsMode"},
3165 {KS_WLAN_GET_EEPROM_CKSUM, IW_PRIV_TYPE_NONE,
3166 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetChecksum"},
3169 static const iw_handler ks_wlan_handler[] = {
3170 (iw_handler) ks_wlan_config_commit, /* SIOCSIWCOMMIT */
3171 (iw_handler) ks_wlan_get_name, /* SIOCGIWNAME */
3172 (iw_handler) NULL, /* SIOCSIWNWID */
3173 (iw_handler) NULL, /* SIOCGIWNWID */
3174 (iw_handler) ks_wlan_set_freq, /* SIOCSIWFREQ */
3175 (iw_handler) ks_wlan_get_freq, /* SIOCGIWFREQ */
3176 (iw_handler) ks_wlan_set_mode, /* SIOCSIWMODE */
3177 (iw_handler) ks_wlan_get_mode, /* SIOCGIWMODE */
3178 #ifndef KSC_OPNOTSUPP
3179 (iw_handler) ks_wlan_set_sens, /* SIOCSIWSENS */
3180 (iw_handler) ks_wlan_get_sens, /* SIOCGIWSENS */
3181 #else /* KSC_OPNOTSUPP */
3182 (iw_handler) NULL, /* SIOCSIWSENS */
3183 (iw_handler) NULL, /* SIOCGIWSENS */
3184 #endif /* KSC_OPNOTSUPP */
3185 (iw_handler) NULL, /* SIOCSIWRANGE */
3186 (iw_handler) ks_wlan_get_range, /* SIOCGIWRANGE */
3187 (iw_handler) NULL, /* SIOCSIWPRIV */
3188 (iw_handler) NULL, /* SIOCGIWPRIV */
3189 (iw_handler) NULL, /* SIOCSIWSTATS */
3190 (iw_handler) ks_wlan_get_iwstats, /* SIOCGIWSTATS */
3191 (iw_handler) NULL, /* SIOCSIWSPY */
3192 (iw_handler) NULL, /* SIOCGIWSPY */
3193 (iw_handler) NULL, /* SIOCSIWTHRSPY */
3194 (iw_handler) NULL, /* SIOCGIWTHRSPY */
3195 (iw_handler) ks_wlan_set_wap, /* SIOCSIWAP */
3196 (iw_handler) ks_wlan_get_wap, /* SIOCGIWAP */
3197 // (iw_handler) NULL, /* SIOCSIWMLME */
3198 (iw_handler) ks_wlan_set_mlme, /* SIOCSIWMLME */
3199 (iw_handler) ks_wlan_get_aplist, /* SIOCGIWAPLIST */
3200 (iw_handler) ks_wlan_set_scan, /* SIOCSIWSCAN */
3201 (iw_handler) ks_wlan_get_scan, /* SIOCGIWSCAN */
3202 (iw_handler) ks_wlan_set_essid, /* SIOCSIWESSID */
3203 (iw_handler) ks_wlan_get_essid, /* SIOCGIWESSID */
3204 (iw_handler) ks_wlan_set_nick, /* SIOCSIWNICKN */
3205 (iw_handler) ks_wlan_get_nick, /* SIOCGIWNICKN */
3206 (iw_handler) NULL, /* -- hole -- */
3207 (iw_handler) NULL, /* -- hole -- */
3208 (iw_handler) ks_wlan_set_rate, /* SIOCSIWRATE */
3209 (iw_handler) ks_wlan_get_rate, /* SIOCGIWRATE */
3210 (iw_handler) ks_wlan_set_rts, /* SIOCSIWRTS */
3211 (iw_handler) ks_wlan_get_rts, /* SIOCGIWRTS */
3212 (iw_handler) ks_wlan_set_frag, /* SIOCSIWFRAG */
3213 (iw_handler) ks_wlan_get_frag, /* SIOCGIWFRAG */
3214 #ifndef KSC_OPNOTSUPP
3215 (iw_handler) ks_wlan_set_txpow, /* SIOCSIWTXPOW */
3216 (iw_handler) ks_wlan_get_txpow, /* SIOCGIWTXPOW */
3217 (iw_handler) ks_wlan_set_retry, /* SIOCSIWRETRY */
3218 (iw_handler) ks_wlan_get_retry, /* SIOCGIWRETRY */
3219 #else /* KSC_OPNOTSUPP */
3220 (iw_handler) NULL, /* SIOCSIWTXPOW */
3221 (iw_handler) NULL, /* SIOCGIWTXPOW */
3222 (iw_handler) NULL, /* SIOCSIWRETRY */
3223 (iw_handler) NULL, /* SIOCGIWRETRY */
3224 #endif /* KSC_OPNOTSUPP */
3225 (iw_handler) ks_wlan_set_encode, /* SIOCSIWENCODE */
3226 (iw_handler) ks_wlan_get_encode, /* SIOCGIWENCODE */
3227 (iw_handler) ks_wlan_set_power, /* SIOCSIWPOWER */
3228 (iw_handler) ks_wlan_get_power, /* SIOCGIWPOWER */
3229 (iw_handler) NULL, /* -- hole -- */
3230 (iw_handler) NULL, /* -- hole -- */
3231 // (iw_handler) NULL, /* SIOCSIWGENIE */
3232 (iw_handler) ks_wlan_set_genie, /* SIOCSIWGENIE */
3233 (iw_handler) NULL, /* SIOCGIWGENIE */
3234 (iw_handler) ks_wlan_set_auth_mode, /* SIOCSIWAUTH */
3235 (iw_handler) ks_wlan_get_auth_mode, /* SIOCGIWAUTH */
3236 (iw_handler) ks_wlan_set_encode_ext, /* SIOCSIWENCODEEXT */
3237 (iw_handler) ks_wlan_get_encode_ext, /* SIOCGIWENCODEEXT */
3238 (iw_handler) ks_wlan_set_pmksa, /* SIOCSIWPMKSA */
3239 (iw_handler) NULL, /* -- hole -- */
3242 /* private_handler */
3243 static const iw_handler ks_wlan_private_handler[] = {
3244 (iw_handler) NULL, /* 0 */
3245 (iw_handler) NULL, /* 1, used to be: KS_WLAN_GET_DRIVER_VERSION */
3246 (iw_handler) NULL, /* 2 */
3247 (iw_handler) ks_wlan_get_firmware_version, /* 3 KS_WLAN_GET_FIRM_VERSION */
3249 (iw_handler) ks_wlan_set_wps_enable, /* 4 KS_WLAN_SET_WPS_ENABLE */
3250 (iw_handler) ks_wlan_get_wps_enable, /* 5 KS_WLAN_GET_WPS_ENABLE */
3251 (iw_handler) ks_wlan_set_wps_probe_req, /* 6 KS_WLAN_SET_WPS_PROBE_REQ */
3253 (iw_handler) NULL, /* 4 */
3254 (iw_handler) NULL, /* 5 */
3255 (iw_handler) NULL, /* 6 */
3258 (iw_handler) ks_wlan_get_eeprom_cksum, /* 7 KS_WLAN_GET_CONNECT */
3259 (iw_handler) ks_wlan_set_preamble, /* 8 KS_WLAN_SET_PREAMBLE */
3260 (iw_handler) ks_wlan_get_preamble, /* 9 KS_WLAN_GET_PREAMBLE */
3261 (iw_handler) ks_wlan_set_powermgt, /* 10 KS_WLAN_SET_POWER_SAVE */
3262 (iw_handler) ks_wlan_get_powermgt, /* 11 KS_WLAN_GET_POWER_SAVE */
3263 (iw_handler) ks_wlan_set_scan_type, /* 12 KS_WLAN_SET_SCAN_TYPE */
3264 (iw_handler) ks_wlan_get_scan_type, /* 13 KS_WLAN_GET_SCAN_TYPE */
3265 (iw_handler) ks_wlan_set_rx_gain, /* 14 KS_WLAN_SET_RX_GAIN */
3266 (iw_handler) ks_wlan_get_rx_gain, /* 15 KS_WLAN_GET_RX_GAIN */
3267 (iw_handler) ks_wlan_hostt, /* 16 KS_WLAN_HOSTT */
3268 (iw_handler) NULL, /* 17 */
3269 (iw_handler) ks_wlan_set_beacon_lost, /* 18 KS_WLAN_SET_BECAN_LOST */
3270 (iw_handler) ks_wlan_get_beacon_lost, /* 19 KS_WLAN_GET_BECAN_LOST */
3271 (iw_handler) ks_wlan_set_tx_gain, /* 20 KS_WLAN_SET_TX_GAIN */
3272 (iw_handler) ks_wlan_get_tx_gain, /* 21 KS_WLAN_GET_TX_GAIN */
3273 (iw_handler) ks_wlan_set_phy_type, /* 22 KS_WLAN_SET_PHY_TYPE */
3274 (iw_handler) ks_wlan_get_phy_type, /* 23 KS_WLAN_GET_PHY_TYPE */
3275 (iw_handler) ks_wlan_set_cts_mode, /* 24 KS_WLAN_SET_CTS_MODE */
3276 (iw_handler) ks_wlan_get_cts_mode, /* 25 KS_WLAN_GET_CTS_MODE */
3277 (iw_handler) NULL, /* 26 */
3278 (iw_handler) NULL, /* 27 */
3279 (iw_handler) ks_wlan_set_sleep_mode, /* 28 KS_WLAN_SET_SLEEP_MODE */
3280 (iw_handler) ks_wlan_get_sleep_mode, /* 29 KS_WLAN_GET_SLEEP_MODE */
3281 (iw_handler) NULL, /* 30 */
3282 (iw_handler) NULL, /* 31 */
3285 static const struct iw_handler_def ks_wlan_handler_def = {
3286 .num_standard = sizeof(ks_wlan_handler) / sizeof(iw_handler),
3287 .num_private = sizeof(ks_wlan_private_handler) / sizeof(iw_handler),
3289 sizeof(ks_wlan_private_args) / sizeof(struct iw_priv_args),
3290 .standard = (iw_handler *) ks_wlan_handler,
3291 .private = (iw_handler *) ks_wlan_private_handler,
3292 .private_args = (struct iw_priv_args *)ks_wlan_private_args,
3293 .get_wireless_stats = ks_get_wireless_stats,
3296 static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq,
3300 struct iwreq *wrq = (struct iwreq *)rq;
3302 case SIOCIWFIRSTPRIV + 20: /* KS_WLAN_SET_STOP_REQ */
3303 rc = ks_wlan_set_stop_request(dev, NULL, &(wrq->u.mode), NULL);
3305 // All other calls are currently unsupported
3310 DPRINTK(5, "return=%d\n", rc);
3315 struct net_device_stats *ks_wlan_get_stats(struct net_device *dev)
3317 struct ks_wlan_private *priv = netdev_priv(dev);
3319 if (priv->dev_state < DEVICE_STATE_READY) {
3320 return NULL; /* not finished initialize */
3323 return &priv->nstats;
3327 int ks_wlan_set_mac_address(struct net_device *dev, void *addr)
3329 struct ks_wlan_private *priv = netdev_priv(dev);
3330 struct sockaddr *mac_addr = (struct sockaddr *)addr;
3331 if (netif_running(dev))
3333 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
3334 memcpy(priv->eth_addr, mac_addr->sa_data, ETH_ALEN);
3336 priv->mac_address_valid = 0;
3337 hostif_sme_enqueue(priv, SME_MACADDRESS_SET_REQUEST);
3339 "ks_wlan: MAC ADDRESS = %02x:%02x:%02x:%02x:%02x:%02x\n",
3340 priv->eth_addr[0], priv->eth_addr[1], priv->eth_addr[2],
3341 priv->eth_addr[3], priv->eth_addr[4], priv->eth_addr[5]);
3346 void ks_wlan_tx_timeout(struct net_device *dev)
3348 struct ks_wlan_private *priv = netdev_priv(dev);
3350 DPRINTK(1, "head(%d) tail(%d)!!\n", priv->tx_dev.qhead,
3351 priv->tx_dev.qtail);
3352 if (!netif_queue_stopped(dev)) {
3353 netif_stop_queue(dev);
3355 priv->nstats.tx_errors++;
3356 netif_wake_queue(dev);
3362 int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev)
3364 struct ks_wlan_private *priv = netdev_priv(dev);
3367 DPRINTK(3, "in_interrupt()=%ld\n", in_interrupt());
3370 printk(KERN_ERR "ks_wlan: skb == NULL!!!\n");
3373 if (priv->dev_state < DEVICE_STATE_READY) {
3375 return 0; /* not finished initialize */
3378 if (netif_running(dev))
3379 netif_stop_queue(dev);
3381 rc = hostif_data_request(priv, skb);
3382 netif_trans_update(dev);
3384 DPRINTK(4, "rc=%d\n", rc);
3392 void send_packet_complete(void *arg1, void *arg2)
3394 struct ks_wlan_private *priv = (struct ks_wlan_private *)arg1;
3395 struct sk_buff *packet = (struct sk_buff *)arg2;
3399 priv->nstats.tx_bytes += packet->len;
3400 priv->nstats.tx_packets++;
3402 if (netif_queue_stopped(priv->net_dev))
3403 netif_wake_queue(priv->net_dev);
3406 dev_kfree_skb(packet);
3412 /* Set or clear the multicast filter for this adaptor.
3413 This routine is not state sensitive and need not be SMP locked. */
3415 void ks_wlan_set_multicast_list(struct net_device *dev)
3417 struct ks_wlan_private *priv = netdev_priv(dev);
3420 if (priv->dev_state < DEVICE_STATE_READY) {
3421 return; /* not finished initialize */
3423 hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST);
3429 int ks_wlan_open(struct net_device *dev)
3431 struct ks_wlan_private *priv = netdev_priv(dev);
3435 if (!priv->mac_address_valid) {
3436 printk(KERN_ERR "ks_wlan : %s Not READY !!\n", dev->name);
3439 netif_start_queue(dev);
3445 int ks_wlan_close(struct net_device *dev)
3448 netif_stop_queue(dev);
3450 DPRINTK(4, "%s: Shutting down ethercard, status was 0x%4.4x.\n",
3456 /* Operational parameters that usually are not changed. */
3457 /* Time in jiffies before concluding the transmitter is hung. */
3458 #define TX_TIMEOUT (3*HZ)
3459 static const unsigned char dummy_addr[] =
3460 { 0x00, 0x0b, 0xe3, 0x00, 0x00, 0x00 };
3462 static const struct net_device_ops ks_wlan_netdev_ops = {
3463 .ndo_start_xmit = ks_wlan_start_xmit,
3464 .ndo_open = ks_wlan_open,
3465 .ndo_stop = ks_wlan_close,
3466 .ndo_do_ioctl = ks_wlan_netdev_ioctl,
3467 .ndo_set_mac_address = ks_wlan_set_mac_address,
3468 .ndo_get_stats = ks_wlan_get_stats,
3469 .ndo_tx_timeout = ks_wlan_tx_timeout,
3470 .ndo_set_rx_mode = ks_wlan_set_multicast_list,
3473 int ks_wlan_net_start(struct net_device *dev)
3475 struct ks_wlan_private *priv;
3478 priv = netdev_priv(dev);
3479 priv->mac_address_valid = 0;
3480 priv->need_commit = 0;
3482 priv->device_open_status = 1;
3484 /* phy information update timer */
3485 atomic_set(&update_phyinfo, 0);
3486 init_timer(&update_phyinfo_timer);
3487 update_phyinfo_timer.function = ks_wlan_update_phyinfo_timeout;
3488 update_phyinfo_timer.data = (unsigned long)priv;
3490 /* dummy address set */
3491 memcpy(priv->eth_addr, dummy_addr, ETH_ALEN);
3492 dev->dev_addr[0] = priv->eth_addr[0];
3493 dev->dev_addr[1] = priv->eth_addr[1];
3494 dev->dev_addr[2] = priv->eth_addr[2];
3495 dev->dev_addr[3] = priv->eth_addr[3];
3496 dev->dev_addr[4] = priv->eth_addr[4];
3497 dev->dev_addr[5] = priv->eth_addr[5];
3498 dev->dev_addr[6] = 0x00;
3499 dev->dev_addr[7] = 0x00;
3501 /* The ks_wlan-specific entries in the device structure. */
3502 dev->netdev_ops = &ks_wlan_netdev_ops;
3503 dev->wireless_handlers = (struct iw_handler_def *)&ks_wlan_handler_def;
3504 dev->watchdog_timeo = TX_TIMEOUT;
3506 netif_carrier_off(dev);
3511 int ks_wlan_net_stop(struct net_device *dev)
3513 struct ks_wlan_private *priv = netdev_priv(dev);
3516 priv->device_open_status = 0;
3517 del_timer_sync(&update_phyinfo_timer);
3519 if (netif_running(dev))
3520 netif_stop_queue(dev);
3525 int ks_wlan_reset(struct net_device *dev)