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) {
1914 memcpy(&priv->wpa.key[index].rx_seq[0],
1915 enc->rx_seq, IW_ENCODE_SEQ_MAX_SIZE);
1920 memcpy(&priv->wpa.key[index].addr.sa_data[0],
1921 &enc->addr.sa_data[0], ETH_ALEN);
1924 case IW_ENCODE_ALG_NONE:
1925 if (priv->reg.privacy_invoked) {
1926 priv->reg.privacy_invoked = 0x00;
1927 commit |= SME_WEP_FLAG;
1929 priv->wpa.key[index].key_len = 0;
1932 case IW_ENCODE_ALG_WEP:
1933 case IW_ENCODE_ALG_CCMP:
1934 if (!priv->reg.privacy_invoked) {
1935 priv->reg.privacy_invoked = 0x01;
1936 commit |= SME_WEP_FLAG;
1938 if (enc->key && enc->key_len) {
1939 memcpy(&priv->wpa.key[index].key_val[0],
1940 &enc->key[0], enc->key_len);
1941 priv->wpa.key[index].key_len = enc->key_len;
1942 commit |= (SME_WEP_VAL1 << index);
1945 case IW_ENCODE_ALG_TKIP:
1946 if (!priv->reg.privacy_invoked) {
1947 priv->reg.privacy_invoked = 0x01;
1948 commit |= SME_WEP_FLAG;
1950 if (enc->key && enc->key_len == 32) {
1951 memcpy(&priv->wpa.key[index].key_val[0],
1952 &enc->key[0], enc->key_len - 16);
1953 priv->wpa.key[index].key_len =
1955 if (priv->wpa.key_mgmt_suite == 4) { /* WPA_NONE */
1956 memcpy(&priv->wpa.key[index].
1957 tx_mic_key[0], &enc->key[16], 8);
1958 memcpy(&priv->wpa.key[index].
1959 rx_mic_key[0], &enc->key[16], 8);
1961 memcpy(&priv->wpa.key[index].
1962 tx_mic_key[0], &enc->key[16], 8);
1963 memcpy(&priv->wpa.key[index].
1964 rx_mic_key[0], &enc->key[24], 8);
1966 commit |= (SME_WEP_VAL1 << index);
1972 priv->wpa.key[index].alg = enc->alg;
1977 if (commit & SME_WEP_INDEX)
1978 hostif_sme_enqueue(priv, SME_SET_TXKEY);
1979 if (commit & SME_WEP_VAL_MASK)
1980 hostif_sme_enqueue(priv, SME_SET_KEY1 + index);
1981 if (commit & SME_WEP_FLAG)
1982 hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
1988 /*------------------------------------------------------------------*/
1989 /* Wireless Handler : get encoding token & mode (WPA)*/
1990 static int ks_wlan_get_encode_ext(struct net_device *dev,
1991 struct iw_request_info *info,
1992 struct iw_point *dwrq, char *extra)
1994 struct ks_wlan_private *priv =
1995 (struct ks_wlan_private *)netdev_priv(dev);
1997 if (priv->sleep_mode == SLP_SLEEP) {
2001 /* for SLEEP MODE */
2002 /* WPA (not used ?? wpa_supplicant)
2003 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2004 struct iw_encode_ext *enc;
2005 enc = (struct iw_encode_ext *)extra;
2006 int index = dwrq->flags & IW_ENCODE_INDEX;
2007 WPA (not used ?? wpa_supplicant) */
2011 /*------------------------------------------------------------------*/
2012 /* Wireless Handler : PMKSA cache operation (WPA2) */
2013 static int ks_wlan_set_pmksa(struct net_device *dev,
2014 struct iw_request_info *info,
2015 struct iw_point *dwrq, char *extra)
2017 struct ks_wlan_private *priv =
2018 (struct ks_wlan_private *)netdev_priv(dev);
2019 struct iw_pmksa *pmksa;
2022 struct list_head *ptr;
2026 if (priv->sleep_mode == SLP_SLEEP) {
2029 /* for SLEEP MODE */
2033 pmksa = (struct iw_pmksa *)extra;
2034 DPRINTK(2, "cmd=%d\n", pmksa->cmd);
2036 switch (pmksa->cmd) {
2038 if (list_empty(&priv->pmklist.head)) { /* new list */
2039 for (i = 0; i < PMK_LIST_MAX; i++) {
2040 pmk = &priv->pmklist.pmk[i];
2042 ("\x00\x00\x00\x00\x00\x00", pmk->bssid,
2046 memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
2047 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
2048 list_add(&pmk->list, &priv->pmklist.head);
2049 priv->pmklist.size++;
2050 } else { /* search cache data */
2051 list_for_each(ptr, &priv->pmklist.head) {
2052 pmk = list_entry(ptr, struct pmk_t, list);
2053 if (!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)) { /* match address! list move to head. */
2054 memcpy(pmk->pmkid, pmksa->pmkid,
2056 list_move(&pmk->list,
2057 &priv->pmklist.head);
2061 if (ptr == &priv->pmklist.head) { /* not find address. */
2062 if (PMK_LIST_MAX > priv->pmklist.size) { /* new cache data */
2063 for (i = 0; i < PMK_LIST_MAX; i++) {
2064 pmk = &priv->pmklist.pmk[i];
2066 ("\x00\x00\x00\x00\x00\x00",
2067 pmk->bssid, ETH_ALEN))
2070 memcpy(pmk->bssid, pmksa->bssid.sa_data,
2072 memcpy(pmk->pmkid, pmksa->pmkid,
2074 list_add(&pmk->list,
2075 &priv->pmklist.head);
2076 priv->pmklist.size++;
2077 } else { /* overwrite old cache data */
2079 list_entry(priv->pmklist.head.prev,
2080 struct pmk_t, list);
2081 memcpy(pmk->bssid, pmksa->bssid.sa_data,
2083 memcpy(pmk->pmkid, pmksa->pmkid,
2085 list_move(&pmk->list,
2086 &priv->pmklist.head);
2091 case IW_PMKSA_REMOVE:
2092 if (list_empty(&priv->pmklist.head)) { /* list empty */
2094 } else { /* search cache data */
2095 list_for_each(ptr, &priv->pmklist.head) {
2096 pmk = list_entry(ptr, struct pmk_t, list);
2097 if (!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)) { /* match address! list del. */
2098 memset(pmk->bssid, 0, ETH_ALEN);
2099 memset(pmk->pmkid, 0, IW_PMKID_LEN);
2100 list_del_init(&pmk->list);
2104 if (ptr == &priv->pmklist.head) { /* not find address. */
2109 case IW_PMKSA_FLUSH:
2110 memset(&(priv->pmklist), 0, sizeof(priv->pmklist));
2111 INIT_LIST_HEAD(&priv->pmklist.head);
2112 for (i = 0; i < PMK_LIST_MAX; i++)
2113 INIT_LIST_HEAD(&priv->pmklist.pmk[i].list);
2119 hostif_sme_enqueue(priv, SME_SET_PMKSA);
2123 static struct iw_statistics *ks_get_wireless_stats(struct net_device *dev)
2126 struct ks_wlan_private *priv =
2127 (struct ks_wlan_private *)netdev_priv(dev);
2128 struct iw_statistics *wstats = &priv->wstats;
2130 if (!atomic_read(&update_phyinfo)) {
2131 if (priv->dev_state < DEVICE_STATE_READY)
2132 return NULL; /* not finished initialize */
2137 /* Packets discarded in the wireless adapter due to wireless
2138 * specific problems */
2139 wstats->discard.nwid = 0; /* Rx invalid nwid */
2140 wstats->discard.code = 0; /* Rx invalid crypt */
2141 wstats->discard.fragment = 0; /* Rx invalid frag */
2142 wstats->discard.retries = 0; /* Tx excessive retries */
2143 wstats->discard.misc = 0; /* Invalid misc */
2144 wstats->miss.beacon = 0; /* Missed beacon */
2149 /*------------------------------------------------------------------*/
2150 /* Private handler : set stop request */
2151 static int ks_wlan_set_stop_request(struct net_device *dev,
2152 struct iw_request_info *info, __u32 * uwrq,
2155 struct ks_wlan_private *priv =
2156 (struct ks_wlan_private *)netdev_priv(dev);
2159 if (priv->sleep_mode == SLP_SLEEP) {
2162 /* for SLEEP MODE */
2166 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2170 /*------------------------------------------------------------------*/
2171 /* Wireless Handler : set MLME */
2172 #include <linux/ieee80211.h>
2173 static int ks_wlan_set_mlme(struct net_device *dev,
2174 struct iw_request_info *info, struct iw_point *dwrq,
2177 struct ks_wlan_private *priv =
2178 (struct ks_wlan_private *)netdev_priv(dev);
2179 struct iw_mlme *mlme = (struct iw_mlme *)extra;
2182 DPRINTK(2, ":%d :%d\n", mlme->cmd, mlme->reason_code);
2184 if (priv->sleep_mode == SLP_SLEEP) {
2187 /* for SLEEP MODE */
2188 switch (mlme->cmd) {
2189 case IW_MLME_DEAUTH:
2190 if (mlme->reason_code == WLAN_REASON_MIC_FAILURE) {
2193 case IW_MLME_DISASSOC:
2195 return ks_wlan_set_stop_request(dev, NULL, &mode, NULL);
2197 return -EOPNOTSUPP; /* Not Support */
2201 /*------------------------------------------------------------------*/
2202 /* Private handler : get firemware version */
2203 static int ks_wlan_get_firmware_version(struct net_device *dev,
2204 struct iw_request_info *info,
2205 struct iw_point *dwrq, char *extra)
2207 struct ks_wlan_private *priv =
2208 (struct ks_wlan_private *)netdev_priv(dev);
2209 strcpy(extra, &(priv->firmware_version[0]));
2210 dwrq->length = priv->version_size + 1;
2215 /*------------------------------------------------------------------*/
2216 /* Private handler : set force disconnect status */
2217 static int ks_wlan_set_detach(struct net_device *dev,
2218 struct iw_request_info *info, __u32 * uwrq,
2221 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2223 if (priv->sleep_mode == SLP_SLEEP) {
2226 /* for SLEEP MODE */
2227 if (*uwrq == CONNECT_STATUS) { /* 0 */
2228 priv->connect_status &= ~FORCE_DISCONNECT;
2229 if ((priv->connect_status & CONNECT_STATUS_MASK) ==
2231 netif_carrier_on(dev);
2232 } else if (*uwrq == DISCONNECT_STATUS) { /* 1 */
2233 priv->connect_status |= FORCE_DISCONNECT;
2234 netif_carrier_off(dev);
2240 /*------------------------------------------------------------------*/
2241 /* Private handler : get force disconnect status */
2242 static int ks_wlan_get_detach(struct net_device *dev,
2243 struct iw_request_info *info, __u32 * uwrq,
2246 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2248 if (priv->sleep_mode == SLP_SLEEP) {
2251 /* for SLEEP MODE */
2252 *uwrq = ((priv->connect_status & FORCE_DISCONNECT) ? 1 : 0);
2256 /*------------------------------------------------------------------*/
2257 /* Private handler : get connect status */
2258 static int ks_wlan_get_connect(struct net_device *dev,
2259 struct iw_request_info *info, __u32 * uwrq,
2262 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2264 if (priv->sleep_mode == SLP_SLEEP) {
2267 /* for SLEEP MODE */
2268 *uwrq = (priv->connect_status & CONNECT_STATUS_MASK);
2273 /*------------------------------------------------------------------*/
2274 /* Private handler : set preamble */
2275 static int ks_wlan_set_preamble(struct net_device *dev,
2276 struct iw_request_info *info, __u32 * uwrq,
2279 struct ks_wlan_private *priv =
2280 (struct ks_wlan_private *)netdev_priv(dev);
2282 if (priv->sleep_mode == SLP_SLEEP) {
2285 /* for SLEEP MODE */
2286 if (*uwrq == LONG_PREAMBLE) { /* 0 */
2287 priv->reg.preamble = LONG_PREAMBLE;
2288 } else if (*uwrq == SHORT_PREAMBLE) { /* 1 */
2289 priv->reg.preamble = SHORT_PREAMBLE;
2293 priv->need_commit |= SME_MODE_SET;
2294 return -EINPROGRESS; /* Call commit handler */
2298 /*------------------------------------------------------------------*/
2299 /* Private handler : get preamble */
2300 static int ks_wlan_get_preamble(struct net_device *dev,
2301 struct iw_request_info *info, __u32 * uwrq,
2304 struct ks_wlan_private *priv =
2305 (struct ks_wlan_private *)netdev_priv(dev);
2307 if (priv->sleep_mode == SLP_SLEEP) {
2310 /* for SLEEP MODE */
2311 *uwrq = priv->reg.preamble;
2315 /*------------------------------------------------------------------*/
2316 /* Private handler : set power save mode */
2317 static int ks_wlan_set_powermgt(struct net_device *dev,
2318 struct iw_request_info *info, __u32 * uwrq,
2321 struct ks_wlan_private *priv =
2322 (struct ks_wlan_private *)netdev_priv(dev);
2324 if (priv->sleep_mode == SLP_SLEEP) {
2327 /* for SLEEP MODE */
2328 if (*uwrq == POWMGT_ACTIVE_MODE) { /* 0 */
2329 priv->reg.powermgt = POWMGT_ACTIVE_MODE;
2330 } else if (*uwrq == POWMGT_SAVE1_MODE) { /* 1 */
2331 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2332 priv->reg.powermgt = POWMGT_SAVE1_MODE;
2335 } else if (*uwrq == POWMGT_SAVE2_MODE) { /* 2 */
2336 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2337 priv->reg.powermgt = POWMGT_SAVE2_MODE;
2343 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
2348 /*------------------------------------------------------------------*/
2349 /* Private handler : get power save made */
2350 static int ks_wlan_get_powermgt(struct net_device *dev,
2351 struct iw_request_info *info, __u32 * uwrq,
2354 struct ks_wlan_private *priv =
2355 (struct ks_wlan_private *)netdev_priv(dev);
2357 if (priv->sleep_mode == SLP_SLEEP) {
2360 /* for SLEEP MODE */
2361 *uwrq = priv->reg.powermgt;
2365 /*------------------------------------------------------------------*/
2366 /* Private handler : set scan type */
2367 static int ks_wlan_set_scan_type(struct net_device *dev,
2368 struct iw_request_info *info, __u32 * uwrq,
2371 struct ks_wlan_private *priv =
2372 (struct ks_wlan_private *)netdev_priv(dev);
2374 if (priv->sleep_mode == SLP_SLEEP) {
2377 /* for SLEEP MODE */
2378 if (*uwrq == ACTIVE_SCAN) { /* 0 */
2379 priv->reg.scan_type = ACTIVE_SCAN;
2380 } else if (*uwrq == PASSIVE_SCAN) { /* 1 */
2381 priv->reg.scan_type = PASSIVE_SCAN;
2388 /*------------------------------------------------------------------*/
2389 /* Private handler : get scan type */
2390 static int ks_wlan_get_scan_type(struct net_device *dev,
2391 struct iw_request_info *info, __u32 * uwrq,
2394 struct ks_wlan_private *priv =
2395 (struct ks_wlan_private *)netdev_priv(dev);
2397 if (priv->sleep_mode == SLP_SLEEP) {
2400 /* for SLEEP MODE */
2401 *uwrq = priv->reg.scan_type;
2406 /*------------------------------------------------------------------*/
2407 /* Private handler : write raw data to device */
2408 static int ks_wlan_data_write(struct net_device *dev,
2409 struct iw_request_info *info,
2410 struct iw_point *dwrq, char *extra)
2412 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2413 unsigned char *wbuff = NULL;
2415 if (priv->sleep_mode == SLP_SLEEP) {
2418 /* for SLEEP MODE */
2419 wbuff = (unsigned char *)kmalloc(dwrq->length, GFP_ATOMIC);
2422 memcpy(wbuff, extra, dwrq->length);
2424 /* write to device */
2425 ks_wlan_hw_tx(priv, wbuff, dwrq->length, NULL, NULL, NULL);
2430 /*------------------------------------------------------------------*/
2431 /* Private handler : read raw data form device */
2432 static int ks_wlan_data_read(struct net_device *dev,
2433 struct iw_request_info *info,
2434 struct iw_point *dwrq, char *extra)
2436 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2437 unsigned short read_length;
2439 if (priv->sleep_mode == SLP_SLEEP) {
2442 /* for SLEEP MODE */
2443 if (!atomic_read(&priv->event_count)) {
2444 if (priv->dev_state < DEVICE_STATE_BOOT) { /* Remove device */
2446 memset(extra, 0xff, read_length);
2447 dwrq->length = read_length;
2451 memset(extra, 0, 1);
2456 if (atomic_read(&priv->event_count) > 0)
2457 atomic_dec(&priv->event_count);
2459 spin_lock(&priv->dev_read_lock); /* request spin lock */
2461 /* Copy length max size 0x07ff */
2462 if (priv->dev_size[priv->dev_count] > 2047)
2465 read_length = priv->dev_size[priv->dev_count];
2468 memcpy(extra, &(priv->dev_data[priv->dev_count][0]), read_length);
2470 spin_unlock(&priv->dev_read_lock); /* release spin lock */
2473 priv->dev_data[priv->dev_count] = 0;
2474 priv->dev_size[priv->dev_count] = 0;
2477 if (priv->dev_count == DEVICE_STOCK_COUNT)
2478 priv->dev_count = 0;
2481 dwrq->length = read_length;
2488 /*------------------------------------------------------------------*/
2489 /* Private handler : get wep string */
2490 #define WEP_ASCII_BUFF_SIZE (17+64*4+1)
2491 static int ks_wlan_get_wep_ascii(struct net_device *dev,
2492 struct iw_request_info *info,
2493 struct iw_point *dwrq, char *extra)
2495 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2497 char tmp[WEP_ASCII_BUFF_SIZE];
2499 if (priv->sleep_mode == SLP_SLEEP) {
2502 /* for SLEEP MODE */
2503 strcpy(tmp, " WEP keys ASCII \n");
2504 len += strlen(" WEP keys ASCII \n");
2506 for (i = 0; i < 4; i++) {
2507 strcpy(tmp + len, "\t[");
2508 len += strlen("\t[");
2511 strcpy(tmp + len, "] ");
2512 len += strlen("] ");
2513 if (priv->reg.wep_key[i].size) {
2515 (priv->reg.wep_key[i].size <
2516 6 ? "(40bits) [" : "(104bits) ["));
2518 strlen((priv->reg.wep_key[i].size <
2519 6 ? "(40bits) [" : "(104bits) ["));
2520 for (j = 0; j < priv->reg.wep_key[i].size; j++, len++)
2522 (isprint(priv->reg.wep_key[i].val[j]) ?
2523 priv->reg.wep_key[i].val[j] : ' ');
2525 strcpy(tmp + len, "]\n");
2526 len += strlen("]\n");
2528 strcpy(tmp + len, "off\n");
2529 len += strlen("off\n");
2533 memcpy(extra, tmp, len);
2534 dwrq->length = len + 1;
2539 /*------------------------------------------------------------------*/
2540 /* Private handler : set beacon lost count */
2541 static int ks_wlan_set_beacon_lost(struct net_device *dev,
2542 struct iw_request_info *info, __u32 * uwrq,
2545 struct ks_wlan_private *priv =
2546 (struct ks_wlan_private *)netdev_priv(dev);
2548 if (priv->sleep_mode == SLP_SLEEP) {
2551 /* for SLEEP MODE */
2552 if (*uwrq >= BEACON_LOST_COUNT_MIN && *uwrq <= BEACON_LOST_COUNT_MAX) {
2553 priv->reg.beacon_lost_count = *uwrq;
2557 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
2558 priv->need_commit |= SME_MODE_SET;
2559 return -EINPROGRESS; /* Call commit handler */
2564 /*------------------------------------------------------------------*/
2565 /* Private handler : get beacon lost count */
2566 static int ks_wlan_get_beacon_lost(struct net_device *dev,
2567 struct iw_request_info *info, __u32 * uwrq,
2570 struct ks_wlan_private *priv =
2571 (struct ks_wlan_private *)netdev_priv(dev);
2573 if (priv->sleep_mode == SLP_SLEEP) {
2576 /* for SLEEP MODE */
2577 *uwrq = priv->reg.beacon_lost_count;
2581 /*------------------------------------------------------------------*/
2582 /* Private handler : set phy type */
2583 static int ks_wlan_set_phy_type(struct net_device *dev,
2584 struct iw_request_info *info, __u32 * uwrq,
2587 struct ks_wlan_private *priv =
2588 (struct ks_wlan_private *)netdev_priv(dev);
2590 if (priv->sleep_mode == SLP_SLEEP) {
2593 /* for SLEEP MODE */
2594 if (*uwrq == D_11B_ONLY_MODE) { /* 0 */
2595 priv->reg.phy_type = D_11B_ONLY_MODE;
2596 } else if (*uwrq == D_11G_ONLY_MODE) { /* 1 */
2597 priv->reg.phy_type = D_11G_ONLY_MODE;
2598 } else if (*uwrq == D_11BG_COMPATIBLE_MODE) { /* 2 */
2599 priv->reg.phy_type = D_11BG_COMPATIBLE_MODE;
2603 priv->need_commit |= SME_MODE_SET;
2604 return -EINPROGRESS; /* Call commit handler */
2607 /*------------------------------------------------------------------*/
2608 /* Private handler : get phy type */
2609 static int ks_wlan_get_phy_type(struct net_device *dev,
2610 struct iw_request_info *info, __u32 * uwrq,
2613 struct ks_wlan_private *priv =
2614 (struct ks_wlan_private *)netdev_priv(dev);
2616 if (priv->sleep_mode == SLP_SLEEP) {
2619 /* for SLEEP MODE */
2620 *uwrq = priv->reg.phy_type;
2624 /*------------------------------------------------------------------*/
2625 /* Private handler : set cts mode */
2626 static int ks_wlan_set_cts_mode(struct net_device *dev,
2627 struct iw_request_info *info, __u32 * uwrq,
2630 struct ks_wlan_private *priv =
2631 (struct ks_wlan_private *)netdev_priv(dev);
2633 if (priv->sleep_mode == SLP_SLEEP) {
2636 /* for SLEEP MODE */
2637 if (*uwrq == CTS_MODE_FALSE) { /* 0 */
2638 priv->reg.cts_mode = CTS_MODE_FALSE;
2639 } else if (*uwrq == CTS_MODE_TRUE) { /* 1 */
2640 if (priv->reg.phy_type == D_11G_ONLY_MODE ||
2641 priv->reg.phy_type == D_11BG_COMPATIBLE_MODE)
2642 priv->reg.cts_mode = CTS_MODE_TRUE;
2644 priv->reg.cts_mode = CTS_MODE_FALSE;
2648 priv->need_commit |= SME_MODE_SET;
2649 return -EINPROGRESS; /* Call commit handler */
2652 /*------------------------------------------------------------------*/
2653 /* Private handler : get cts mode */
2654 static int ks_wlan_get_cts_mode(struct net_device *dev,
2655 struct iw_request_info *info, __u32 * uwrq,
2658 struct ks_wlan_private *priv =
2659 (struct ks_wlan_private *)netdev_priv(dev);
2661 if (priv->sleep_mode == SLP_SLEEP) {
2664 /* for SLEEP MODE */
2665 *uwrq = priv->reg.cts_mode;
2669 /*------------------------------------------------------------------*/
2670 /* Private handler : set sleep mode */
2671 static int ks_wlan_set_sleep_mode(struct net_device *dev,
2672 struct iw_request_info *info,
2673 __u32 * uwrq, char *extra)
2675 struct ks_wlan_private *priv =
2676 (struct ks_wlan_private *)netdev_priv(dev);
2680 if (*uwrq == SLP_SLEEP) {
2681 priv->sleep_mode = *uwrq;
2682 printk("SET_SLEEP_MODE %d\n", priv->sleep_mode);
2684 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2685 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2687 } else if (*uwrq == SLP_ACTIVE) {
2688 priv->sleep_mode = *uwrq;
2689 printk("SET_SLEEP_MODE %d\n", priv->sleep_mode);
2690 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2692 printk("SET_SLEEP_MODE %d errror\n", *uwrq);
2699 /*------------------------------------------------------------------*/
2700 /* Private handler : get sleep mode */
2701 static int ks_wlan_get_sleep_mode(struct net_device *dev,
2702 struct iw_request_info *info,
2703 __u32 * uwrq, char *extra)
2705 struct ks_wlan_private *priv =
2706 (struct ks_wlan_private *)netdev_priv(dev);
2708 DPRINTK(2, "GET_SLEEP_MODE %d\n", priv->sleep_mode);
2709 *uwrq = priv->sleep_mode;
2715 /*------------------------------------------------------------------*/
2716 /* Private handler : set phy information timer */
2717 static int ks_wlan_set_phy_information_timer(struct net_device *dev,
2718 struct iw_request_info *info,
2719 __u32 * uwrq, char *extra)
2721 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2723 if (priv->sleep_mode == SLP_SLEEP) {
2726 /* for SLEEP MODE */
2727 if (*uwrq >= 0 && *uwrq <= 0xFFFF) /* 0-65535 */
2728 priv->reg.phy_info_timer = (uint16_t) * uwrq;
2732 hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST);
2737 /*------------------------------------------------------------------*/
2738 /* Private handler : get phy information timer */
2739 static int ks_wlan_get_phy_information_timer(struct net_device *dev,
2740 struct iw_request_info *info,
2741 __u32 * uwrq, char *extra)
2743 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2745 if (priv->sleep_mode == SLP_SLEEP) {
2748 /* for SLEEP MODE */
2749 *uwrq = priv->reg.phy_info_timer;
2755 /*------------------------------------------------------------------*/
2756 /* Private handler : set WPS enable */
2757 static int ks_wlan_set_wps_enable(struct net_device *dev,
2758 struct iw_request_info *info, __u32 * uwrq,
2761 struct ks_wlan_private *priv =
2762 (struct ks_wlan_private *)netdev_priv(dev);
2765 if (priv->sleep_mode == SLP_SLEEP) {
2768 /* for SLEEP MODE */
2769 if (*uwrq == 0 || *uwrq == 1)
2770 priv->wps.wps_enabled = *uwrq;
2774 hostif_sme_enqueue(priv, SME_WPS_ENABLE_REQUEST);
2779 /*------------------------------------------------------------------*/
2780 /* Private handler : get WPS enable */
2781 static int ks_wlan_get_wps_enable(struct net_device *dev,
2782 struct iw_request_info *info, __u32 * uwrq,
2785 struct ks_wlan_private *priv =
2786 (struct ks_wlan_private *)netdev_priv(dev);
2789 if (priv->sleep_mode == SLP_SLEEP) {
2792 /* for SLEEP MODE */
2793 *uwrq = priv->wps.wps_enabled;
2794 printk("return=%d\n", *uwrq);
2799 /*------------------------------------------------------------------*/
2800 /* Private handler : set WPS probe req */
2801 static int ks_wlan_set_wps_probe_req(struct net_device *dev,
2802 struct iw_request_info *info,
2803 struct iw_point *dwrq, char *extra)
2807 struct ks_wlan_private *priv =
2808 (struct ks_wlan_private *)netdev_priv(dev);
2812 if (priv->sleep_mode == SLP_SLEEP) {
2815 /* for SLEEP MODE */
2816 DPRINTK(2, "dwrq->length=%d\n", dwrq->length);
2819 if (p[1] + 2 != dwrq->length || dwrq->length > 256) {
2823 priv->wps.ielen = p[1] + 2 + 1; /* IE header + IE + sizeof(len) */
2824 len = p[1] + 2; /* IE header + IE */
2826 memcpy(priv->wps.ie, &len, sizeof(len));
2827 p = memcpy(priv->wps.ie + 1, p, len);
2829 DPRINTK(2, "%d(%#x): %02X %02X %02X %02X ... %02X %02X %02X\n",
2830 priv->wps.ielen, priv->wps.ielen, p[0], p[1], p[2], p[3],
2831 p[priv->wps.ielen - 3], p[priv->wps.ielen - 2],
2832 p[priv->wps.ielen - 1]);
2834 hostif_sme_enqueue(priv, SME_WPS_PROBE_REQUEST);
2840 /*------------------------------------------------------------------*/
2841 /* Private handler : get WPS probe req */
2842 static int ks_wlan_get_wps_probe_req(struct net_device *dev,
2843 struct iw_request_info *info,
2844 __u32 * uwrq, char *extra)
2846 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2849 if (priv->sleep_mode == SLP_SLEEP) {
2852 /* for SLEEP MODE */
2858 /*------------------------------------------------------------------*/
2859 /* Private handler : set tx gain control value */
2860 static int ks_wlan_set_tx_gain(struct net_device *dev,
2861 struct iw_request_info *info, __u32 * uwrq,
2864 struct ks_wlan_private *priv =
2865 (struct ks_wlan_private *)netdev_priv(dev);
2867 if (priv->sleep_mode == SLP_SLEEP) {
2870 /* for SLEEP MODE */
2871 if (*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2872 priv->gain.TxGain = (uint8_t) * uwrq;
2876 if (priv->gain.TxGain < 0xFF)
2877 priv->gain.TxMode = 1;
2879 priv->gain.TxMode = 0;
2881 hostif_sme_enqueue(priv, SME_SET_GAIN);
2885 /*------------------------------------------------------------------*/
2886 /* Private handler : get tx gain control value */
2887 static int ks_wlan_get_tx_gain(struct net_device *dev,
2888 struct iw_request_info *info, __u32 * uwrq,
2891 struct ks_wlan_private *priv =
2892 (struct ks_wlan_private *)netdev_priv(dev);
2894 if (priv->sleep_mode == SLP_SLEEP) {
2897 /* for SLEEP MODE */
2898 *uwrq = priv->gain.TxGain;
2899 hostif_sme_enqueue(priv, SME_GET_GAIN);
2903 /*------------------------------------------------------------------*/
2904 /* Private handler : set rx gain control value */
2905 static int ks_wlan_set_rx_gain(struct net_device *dev,
2906 struct iw_request_info *info, __u32 * uwrq,
2909 struct ks_wlan_private *priv =
2910 (struct ks_wlan_private *)netdev_priv(dev);
2912 if (priv->sleep_mode == SLP_SLEEP) {
2915 /* for SLEEP MODE */
2916 if (*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2917 priv->gain.RxGain = (uint8_t) * uwrq;
2921 if (priv->gain.RxGain < 0xFF)
2922 priv->gain.RxMode = 1;
2924 priv->gain.RxMode = 0;
2926 hostif_sme_enqueue(priv, SME_SET_GAIN);
2930 /*------------------------------------------------------------------*/
2931 /* Private handler : get rx gain control value */
2932 static int ks_wlan_get_rx_gain(struct net_device *dev,
2933 struct iw_request_info *info, __u32 * uwrq,
2936 struct ks_wlan_private *priv =
2937 (struct ks_wlan_private *)netdev_priv(dev);
2939 if (priv->sleep_mode == SLP_SLEEP) {
2942 /* for SLEEP MODE */
2943 *uwrq = priv->gain.RxGain;
2944 hostif_sme_enqueue(priv, SME_GET_GAIN);
2949 /*------------------------------------------------------------------*/
2950 /* Private handler : set region value */
2951 static int ks_wlan_set_region(struct net_device *dev,
2952 struct iw_request_info *info, __u32 * uwrq,
2955 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2957 if (priv->sleep_mode == SLP_SLEEP) {
2960 /* for SLEEP MODE */
2961 if (*uwrq >= 0x9 && *uwrq <= 0xF) /* 0x9-0xf */
2962 priv->region = (uint8_t) * uwrq;
2966 hostif_sme_enqueue(priv, SME_SET_REGION);
2971 /*------------------------------------------------------------------*/
2972 /* Private handler : get eeprom checksum result */
2973 static int ks_wlan_get_eeprom_cksum(struct net_device *dev,
2974 struct iw_request_info *info, __u32 * uwrq,
2977 struct ks_wlan_private *priv =
2978 (struct ks_wlan_private *)netdev_priv(dev);
2980 *uwrq = priv->eeprom_checksum;
2984 static void print_hif_event(int event)
2989 printk("HIF_DATA_REQ\n");
2992 printk("HIF_DATA_IND\n");
2994 case HIF_MIB_GET_REQ:
2995 printk("HIF_MIB_GET_REQ\n");
2997 case HIF_MIB_GET_CONF:
2998 printk("HIF_MIB_GET_CONF\n");
3000 case HIF_MIB_SET_REQ:
3001 printk("HIF_MIB_SET_REQ\n");
3003 case HIF_MIB_SET_CONF:
3004 printk("HIF_MIB_SET_CONF\n");
3006 case HIF_POWERMGT_REQ:
3007 printk("HIF_POWERMGT_REQ\n");
3009 case HIF_POWERMGT_CONF:
3010 printk("HIF_POWERMGT_CONF\n");
3013 printk("HIF_START_REQ\n");
3015 case HIF_START_CONF:
3016 printk("HIF_START_CONF\n");
3018 case HIF_CONNECT_IND:
3019 printk("HIF_CONNECT_IND\n");
3022 printk("HIF_STOP_REQ\n");
3025 printk("HIF_STOP_CONF\n");
3027 case HIF_PS_ADH_SET_REQ:
3028 printk("HIF_PS_ADH_SET_REQ\n");
3030 case HIF_PS_ADH_SET_CONF:
3031 printk("HIF_PS_ADH_SET_CONF\n");
3033 case HIF_INFRA_SET_REQ:
3034 printk("HIF_INFRA_SET_REQ\n");
3036 case HIF_INFRA_SET_CONF:
3037 printk("HIF_INFRA_SET_CONF\n");
3039 case HIF_ADH_SET_REQ:
3040 printk("HIF_ADH_SET_REQ\n");
3042 case HIF_ADH_SET_CONF:
3043 printk("HIF_ADH_SET_CONF\n");
3045 case HIF_AP_SET_REQ:
3046 printk("HIF_AP_SET_REQ\n");
3048 case HIF_AP_SET_CONF:
3049 printk("HIF_AP_SET_CONF\n");
3051 case HIF_ASSOC_INFO_IND:
3052 printk("HIF_ASSOC_INFO_IND\n");
3054 case HIF_MIC_FAILURE_REQ:
3055 printk("HIF_MIC_FAILURE_REQ\n");
3057 case HIF_MIC_FAILURE_CONF:
3058 printk("HIF_MIC_FAILURE_CONF\n");
3061 printk("HIF_SCAN_REQ\n");
3064 printk("HIF_SCAN_CONF\n");
3066 case HIF_PHY_INFO_REQ:
3067 printk("HIF_PHY_INFO_REQ\n");
3069 case HIF_PHY_INFO_CONF:
3070 printk("HIF_PHY_INFO_CONF\n");
3073 printk("HIF_SLEEP_REQ\n");
3075 case HIF_SLEEP_CONF:
3076 printk("HIF_SLEEP_CONF\n");
3078 case HIF_PHY_INFO_IND:
3079 printk("HIF_PHY_INFO_IND\n");
3082 printk("HIF_SCAN_IND\n");
3084 case HIF_INFRA_SET2_REQ:
3085 printk("HIF_INFRA_SET2_REQ\n");
3087 case HIF_INFRA_SET2_CONF:
3088 printk("HIF_INFRA_SET2_CONF\n");
3090 case HIF_ADH_SET2_REQ:
3091 printk("HIF_ADH_SET2_REQ\n");
3093 case HIF_ADH_SET2_CONF:
3094 printk("HIF_ADH_SET2_CONF\n");
3098 /*------------------------------------------------------------------*/
3099 /* Private handler : get host command history */
3100 static int ks_wlan_hostt(struct net_device *dev, struct iw_request_info *info,
3101 __u32 * uwrq, char *extra)
3104 struct ks_wlan_private *priv =
3105 (struct ks_wlan_private *)netdev_priv(dev);
3107 for (i = 63; i >= 0; i--) {
3109 priv->hostt.buff[(priv->hostt.qtail - 1 - i) %
3110 SME_EVENT_BUFF_SIZE];
3111 print_hif_event(event);
3116 /* Structures to export the Wireless Handlers */
3118 static const struct iw_priv_args ks_wlan_private_args[] = {
3119 /*{ cmd, set_args, get_args, name[16] } */
3120 {KS_WLAN_GET_FIRM_VERSION, IW_PRIV_TYPE_NONE,
3121 IW_PRIV_TYPE_CHAR | (128 + 1), "GetFirmwareVer"},
3123 {KS_WLAN_SET_WPS_ENABLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3124 IW_PRIV_TYPE_NONE, "SetWPSEnable"},
3125 {KS_WLAN_GET_WPS_ENABLE, IW_PRIV_TYPE_NONE,
3126 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetW"},
3127 {KS_WLAN_SET_WPS_PROBE_REQ, IW_PRIV_TYPE_BYTE | 2047, IW_PRIV_TYPE_NONE,
3130 {KS_WLAN_SET_PREAMBLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3131 IW_PRIV_TYPE_NONE, "SetPreamble"},
3132 {KS_WLAN_GET_PREAMBLE, IW_PRIV_TYPE_NONE,
3133 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPreamble"},
3134 {KS_WLAN_SET_POWER_SAVE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3135 IW_PRIV_TYPE_NONE, "SetPowerSave"},
3136 {KS_WLAN_GET_POWER_SAVE, IW_PRIV_TYPE_NONE,
3137 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPowerSave"},
3138 {KS_WLAN_SET_SCAN_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3139 IW_PRIV_TYPE_NONE, "SetScanType"},
3140 {KS_WLAN_GET_SCAN_TYPE, IW_PRIV_TYPE_NONE,
3141 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetScanType"},
3142 {KS_WLAN_SET_RX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3143 IW_PRIV_TYPE_NONE, "SetRxGain"},
3144 {KS_WLAN_GET_RX_GAIN, IW_PRIV_TYPE_NONE,
3145 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetRxGain"},
3146 {KS_WLAN_HOSTT, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | (128 + 1),
3148 {KS_WLAN_SET_BEACON_LOST, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3149 IW_PRIV_TYPE_NONE, "SetBeaconLost"},
3150 {KS_WLAN_GET_BEACON_LOST, IW_PRIV_TYPE_NONE,
3151 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetBeaconLost"},
3152 {KS_WLAN_SET_SLEEP_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3153 IW_PRIV_TYPE_NONE, "SetSleepMode"},
3154 {KS_WLAN_GET_SLEEP_MODE, IW_PRIV_TYPE_NONE,
3155 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetSleepMode"},
3156 {KS_WLAN_SET_TX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3157 IW_PRIV_TYPE_NONE, "SetTxGain"},
3158 {KS_WLAN_GET_TX_GAIN, IW_PRIV_TYPE_NONE,
3159 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetTxGain"},
3160 {KS_WLAN_SET_PHY_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3161 IW_PRIV_TYPE_NONE, "SetPhyType"},
3162 {KS_WLAN_GET_PHY_TYPE, IW_PRIV_TYPE_NONE,
3163 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPhyType"},
3164 {KS_WLAN_SET_CTS_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3165 IW_PRIV_TYPE_NONE, "SetCtsMode"},
3166 {KS_WLAN_GET_CTS_MODE, IW_PRIV_TYPE_NONE,
3167 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetCtsMode"},
3168 {KS_WLAN_GET_EEPROM_CKSUM, IW_PRIV_TYPE_NONE,
3169 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetChecksum"},
3172 static const iw_handler ks_wlan_handler[] = {
3173 (iw_handler) ks_wlan_config_commit, /* SIOCSIWCOMMIT */
3174 (iw_handler) ks_wlan_get_name, /* SIOCGIWNAME */
3175 (iw_handler) NULL, /* SIOCSIWNWID */
3176 (iw_handler) NULL, /* SIOCGIWNWID */
3177 (iw_handler) ks_wlan_set_freq, /* SIOCSIWFREQ */
3178 (iw_handler) ks_wlan_get_freq, /* SIOCGIWFREQ */
3179 (iw_handler) ks_wlan_set_mode, /* SIOCSIWMODE */
3180 (iw_handler) ks_wlan_get_mode, /* SIOCGIWMODE */
3181 #ifndef KSC_OPNOTSUPP
3182 (iw_handler) ks_wlan_set_sens, /* SIOCSIWSENS */
3183 (iw_handler) ks_wlan_get_sens, /* SIOCGIWSENS */
3184 #else /* KSC_OPNOTSUPP */
3185 (iw_handler) NULL, /* SIOCSIWSENS */
3186 (iw_handler) NULL, /* SIOCGIWSENS */
3187 #endif /* KSC_OPNOTSUPP */
3188 (iw_handler) NULL, /* SIOCSIWRANGE */
3189 (iw_handler) ks_wlan_get_range, /* SIOCGIWRANGE */
3190 (iw_handler) NULL, /* SIOCSIWPRIV */
3191 (iw_handler) NULL, /* SIOCGIWPRIV */
3192 (iw_handler) NULL, /* SIOCSIWSTATS */
3193 (iw_handler) ks_wlan_get_iwstats, /* SIOCGIWSTATS */
3194 (iw_handler) NULL, /* SIOCSIWSPY */
3195 (iw_handler) NULL, /* SIOCGIWSPY */
3196 (iw_handler) NULL, /* SIOCSIWTHRSPY */
3197 (iw_handler) NULL, /* SIOCGIWTHRSPY */
3198 (iw_handler) ks_wlan_set_wap, /* SIOCSIWAP */
3199 (iw_handler) ks_wlan_get_wap, /* SIOCGIWAP */
3200 // (iw_handler) NULL, /* SIOCSIWMLME */
3201 (iw_handler) ks_wlan_set_mlme, /* SIOCSIWMLME */
3202 (iw_handler) ks_wlan_get_aplist, /* SIOCGIWAPLIST */
3203 (iw_handler) ks_wlan_set_scan, /* SIOCSIWSCAN */
3204 (iw_handler) ks_wlan_get_scan, /* SIOCGIWSCAN */
3205 (iw_handler) ks_wlan_set_essid, /* SIOCSIWESSID */
3206 (iw_handler) ks_wlan_get_essid, /* SIOCGIWESSID */
3207 (iw_handler) ks_wlan_set_nick, /* SIOCSIWNICKN */
3208 (iw_handler) ks_wlan_get_nick, /* SIOCGIWNICKN */
3209 (iw_handler) NULL, /* -- hole -- */
3210 (iw_handler) NULL, /* -- hole -- */
3211 (iw_handler) ks_wlan_set_rate, /* SIOCSIWRATE */
3212 (iw_handler) ks_wlan_get_rate, /* SIOCGIWRATE */
3213 (iw_handler) ks_wlan_set_rts, /* SIOCSIWRTS */
3214 (iw_handler) ks_wlan_get_rts, /* SIOCGIWRTS */
3215 (iw_handler) ks_wlan_set_frag, /* SIOCSIWFRAG */
3216 (iw_handler) ks_wlan_get_frag, /* SIOCGIWFRAG */
3217 #ifndef KSC_OPNOTSUPP
3218 (iw_handler) ks_wlan_set_txpow, /* SIOCSIWTXPOW */
3219 (iw_handler) ks_wlan_get_txpow, /* SIOCGIWTXPOW */
3220 (iw_handler) ks_wlan_set_retry, /* SIOCSIWRETRY */
3221 (iw_handler) ks_wlan_get_retry, /* SIOCGIWRETRY */
3222 #else /* KSC_OPNOTSUPP */
3223 (iw_handler) NULL, /* SIOCSIWTXPOW */
3224 (iw_handler) NULL, /* SIOCGIWTXPOW */
3225 (iw_handler) NULL, /* SIOCSIWRETRY */
3226 (iw_handler) NULL, /* SIOCGIWRETRY */
3227 #endif /* KSC_OPNOTSUPP */
3228 (iw_handler) ks_wlan_set_encode, /* SIOCSIWENCODE */
3229 (iw_handler) ks_wlan_get_encode, /* SIOCGIWENCODE */
3230 (iw_handler) ks_wlan_set_power, /* SIOCSIWPOWER */
3231 (iw_handler) ks_wlan_get_power, /* SIOCGIWPOWER */
3232 (iw_handler) NULL, /* -- hole -- */
3233 (iw_handler) NULL, /* -- hole -- */
3234 // (iw_handler) NULL, /* SIOCSIWGENIE */
3235 (iw_handler) ks_wlan_set_genie, /* SIOCSIWGENIE */
3236 (iw_handler) NULL, /* SIOCGIWGENIE */
3237 (iw_handler) ks_wlan_set_auth_mode, /* SIOCSIWAUTH */
3238 (iw_handler) ks_wlan_get_auth_mode, /* SIOCGIWAUTH */
3239 (iw_handler) ks_wlan_set_encode_ext, /* SIOCSIWENCODEEXT */
3240 (iw_handler) ks_wlan_get_encode_ext, /* SIOCGIWENCODEEXT */
3241 (iw_handler) ks_wlan_set_pmksa, /* SIOCSIWPMKSA */
3242 (iw_handler) NULL, /* -- hole -- */
3245 /* private_handler */
3246 static const iw_handler ks_wlan_private_handler[] = {
3247 (iw_handler) NULL, /* 0 */
3248 (iw_handler) NULL, /* 1, used to be: KS_WLAN_GET_DRIVER_VERSION */
3249 (iw_handler) NULL, /* 2 */
3250 (iw_handler) ks_wlan_get_firmware_version, /* 3 KS_WLAN_GET_FIRM_VERSION */
3252 (iw_handler) ks_wlan_set_wps_enable, /* 4 KS_WLAN_SET_WPS_ENABLE */
3253 (iw_handler) ks_wlan_get_wps_enable, /* 5 KS_WLAN_GET_WPS_ENABLE */
3254 (iw_handler) ks_wlan_set_wps_probe_req, /* 6 KS_WLAN_SET_WPS_PROBE_REQ */
3256 (iw_handler) NULL, /* 4 */
3257 (iw_handler) NULL, /* 5 */
3258 (iw_handler) NULL, /* 6 */
3261 (iw_handler) ks_wlan_get_eeprom_cksum, /* 7 KS_WLAN_GET_CONNECT */
3262 (iw_handler) ks_wlan_set_preamble, /* 8 KS_WLAN_SET_PREAMBLE */
3263 (iw_handler) ks_wlan_get_preamble, /* 9 KS_WLAN_GET_PREAMBLE */
3264 (iw_handler) ks_wlan_set_powermgt, /* 10 KS_WLAN_SET_POWER_SAVE */
3265 (iw_handler) ks_wlan_get_powermgt, /* 11 KS_WLAN_GET_POWER_SAVE */
3266 (iw_handler) ks_wlan_set_scan_type, /* 12 KS_WLAN_SET_SCAN_TYPE */
3267 (iw_handler) ks_wlan_get_scan_type, /* 13 KS_WLAN_GET_SCAN_TYPE */
3268 (iw_handler) ks_wlan_set_rx_gain, /* 14 KS_WLAN_SET_RX_GAIN */
3269 (iw_handler) ks_wlan_get_rx_gain, /* 15 KS_WLAN_GET_RX_GAIN */
3270 (iw_handler) ks_wlan_hostt, /* 16 KS_WLAN_HOSTT */
3271 (iw_handler) NULL, /* 17 */
3272 (iw_handler) ks_wlan_set_beacon_lost, /* 18 KS_WLAN_SET_BECAN_LOST */
3273 (iw_handler) ks_wlan_get_beacon_lost, /* 19 KS_WLAN_GET_BECAN_LOST */
3274 (iw_handler) ks_wlan_set_tx_gain, /* 20 KS_WLAN_SET_TX_GAIN */
3275 (iw_handler) ks_wlan_get_tx_gain, /* 21 KS_WLAN_GET_TX_GAIN */
3276 (iw_handler) ks_wlan_set_phy_type, /* 22 KS_WLAN_SET_PHY_TYPE */
3277 (iw_handler) ks_wlan_get_phy_type, /* 23 KS_WLAN_GET_PHY_TYPE */
3278 (iw_handler) ks_wlan_set_cts_mode, /* 24 KS_WLAN_SET_CTS_MODE */
3279 (iw_handler) ks_wlan_get_cts_mode, /* 25 KS_WLAN_GET_CTS_MODE */
3280 (iw_handler) NULL, /* 26 */
3281 (iw_handler) NULL, /* 27 */
3282 (iw_handler) ks_wlan_set_sleep_mode, /* 28 KS_WLAN_SET_SLEEP_MODE */
3283 (iw_handler) ks_wlan_get_sleep_mode, /* 29 KS_WLAN_GET_SLEEP_MODE */
3284 (iw_handler) NULL, /* 30 */
3285 (iw_handler) NULL, /* 31 */
3288 static const struct iw_handler_def ks_wlan_handler_def = {
3289 .num_standard = sizeof(ks_wlan_handler) / sizeof(iw_handler),
3290 .num_private = sizeof(ks_wlan_private_handler) / sizeof(iw_handler),
3292 sizeof(ks_wlan_private_args) / sizeof(struct iw_priv_args),
3293 .standard = (iw_handler *) ks_wlan_handler,
3294 .private = (iw_handler *) ks_wlan_private_handler,
3295 .private_args = (struct iw_priv_args *)ks_wlan_private_args,
3296 .get_wireless_stats = ks_get_wireless_stats,
3299 static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq,
3303 struct iwreq *wrq = (struct iwreq *)rq;
3305 case SIOCIWFIRSTPRIV + 20: /* KS_WLAN_SET_STOP_REQ */
3306 rc = ks_wlan_set_stop_request(dev, NULL, &(wrq->u.mode), NULL);
3308 // All other calls are currently unsupported
3313 DPRINTK(5, "return=%d\n", rc);
3318 struct net_device_stats *ks_wlan_get_stats(struct net_device *dev)
3320 struct ks_wlan_private *priv = netdev_priv(dev);
3322 if (priv->dev_state < DEVICE_STATE_READY) {
3323 return NULL; /* not finished initialize */
3326 return &priv->nstats;
3330 int ks_wlan_set_mac_address(struct net_device *dev, void *addr)
3332 struct ks_wlan_private *priv = netdev_priv(dev);
3333 struct sockaddr *mac_addr = (struct sockaddr *)addr;
3334 if (netif_running(dev))
3336 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
3337 memcpy(priv->eth_addr, mac_addr->sa_data, ETH_ALEN);
3339 priv->mac_address_valid = 0;
3340 hostif_sme_enqueue(priv, SME_MACADDRESS_SET_REQUEST);
3342 "ks_wlan: MAC ADDRESS = %02x:%02x:%02x:%02x:%02x:%02x\n",
3343 priv->eth_addr[0], priv->eth_addr[1], priv->eth_addr[2],
3344 priv->eth_addr[3], priv->eth_addr[4], priv->eth_addr[5]);
3349 void ks_wlan_tx_timeout(struct net_device *dev)
3351 struct ks_wlan_private *priv = netdev_priv(dev);
3353 DPRINTK(1, "head(%d) tail(%d)!!\n", priv->tx_dev.qhead,
3354 priv->tx_dev.qtail);
3355 if (!netif_queue_stopped(dev)) {
3356 netif_stop_queue(dev);
3358 priv->nstats.tx_errors++;
3359 netif_wake_queue(dev);
3365 int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev)
3367 struct ks_wlan_private *priv = netdev_priv(dev);
3370 DPRINTK(3, "in_interrupt()=%ld\n", in_interrupt());
3373 printk(KERN_ERR "ks_wlan: skb == NULL!!!\n");
3376 if (priv->dev_state < DEVICE_STATE_READY) {
3378 return 0; /* not finished initialize */
3381 if (netif_running(dev))
3382 netif_stop_queue(dev);
3384 rc = hostif_data_request(priv, skb);
3385 netif_trans_update(dev);
3387 DPRINTK(4, "rc=%d\n", rc);
3395 void send_packet_complete(void *arg1, void *arg2)
3397 struct ks_wlan_private *priv = (struct ks_wlan_private *)arg1;
3398 struct sk_buff *packet = (struct sk_buff *)arg2;
3402 priv->nstats.tx_bytes += packet->len;
3403 priv->nstats.tx_packets++;
3405 if (netif_queue_stopped(priv->net_dev))
3406 netif_wake_queue(priv->net_dev);
3409 dev_kfree_skb(packet);
3415 /* Set or clear the multicast filter for this adaptor.
3416 This routine is not state sensitive and need not be SMP locked. */
3418 void ks_wlan_set_multicast_list(struct net_device *dev)
3420 struct ks_wlan_private *priv = netdev_priv(dev);
3423 if (priv->dev_state < DEVICE_STATE_READY) {
3424 return; /* not finished initialize */
3426 hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST);
3432 int ks_wlan_open(struct net_device *dev)
3434 struct ks_wlan_private *priv = netdev_priv(dev);
3438 if (!priv->mac_address_valid) {
3439 printk(KERN_ERR "ks_wlan : %s Not READY !!\n", dev->name);
3442 netif_start_queue(dev);
3448 int ks_wlan_close(struct net_device *dev)
3451 netif_stop_queue(dev);
3453 DPRINTK(4, "%s: Shutting down ethercard, status was 0x%4.4x.\n",
3459 /* Operational parameters that usually are not changed. */
3460 /* Time in jiffies before concluding the transmitter is hung. */
3461 #define TX_TIMEOUT (3*HZ)
3462 static const unsigned char dummy_addr[] =
3463 { 0x00, 0x0b, 0xe3, 0x00, 0x00, 0x00 };
3465 static const struct net_device_ops ks_wlan_netdev_ops = {
3466 .ndo_start_xmit = ks_wlan_start_xmit,
3467 .ndo_open = ks_wlan_open,
3468 .ndo_stop = ks_wlan_close,
3469 .ndo_do_ioctl = ks_wlan_netdev_ioctl,
3470 .ndo_set_mac_address = ks_wlan_set_mac_address,
3471 .ndo_get_stats = ks_wlan_get_stats,
3472 .ndo_tx_timeout = ks_wlan_tx_timeout,
3473 .ndo_set_rx_mode = ks_wlan_set_multicast_list,
3476 int ks_wlan_net_start(struct net_device *dev)
3478 struct ks_wlan_private *priv;
3481 priv = netdev_priv(dev);
3482 priv->mac_address_valid = 0;
3483 priv->need_commit = 0;
3485 priv->device_open_status = 1;
3487 /* phy information update timer */
3488 atomic_set(&update_phyinfo, 0);
3489 init_timer(&update_phyinfo_timer);
3490 update_phyinfo_timer.function = ks_wlan_update_phyinfo_timeout;
3491 update_phyinfo_timer.data = (unsigned long)priv;
3493 /* dummy address set */
3494 memcpy(priv->eth_addr, dummy_addr, ETH_ALEN);
3495 dev->dev_addr[0] = priv->eth_addr[0];
3496 dev->dev_addr[1] = priv->eth_addr[1];
3497 dev->dev_addr[2] = priv->eth_addr[2];
3498 dev->dev_addr[3] = priv->eth_addr[3];
3499 dev->dev_addr[4] = priv->eth_addr[4];
3500 dev->dev_addr[5] = priv->eth_addr[5];
3501 dev->dev_addr[6] = 0x00;
3502 dev->dev_addr[7] = 0x00;
3504 /* The ks_wlan-specific entries in the device structure. */
3505 dev->netdev_ops = &ks_wlan_netdev_ops;
3506 dev->wireless_handlers = (struct iw_handler_def *)&ks_wlan_handler_def;
3507 dev->watchdog_timeo = TX_TIMEOUT;
3509 netif_carrier_off(dev);
3514 int ks_wlan_net_stop(struct net_device *dev)
3516 struct ks_wlan_private *priv = netdev_priv(dev);
3519 priv->device_open_status = 0;
3520 del_timer_sync(&update_phyinfo_timer);
3522 if (netif_running(dev))
3523 netif_stop_queue(dev);
3528 int ks_wlan_reset(struct net_device *dev)