2 * Driver for KeyStream 11b/g wireless LAN
4 * Copyright (C) 2005-2008 KeyStream Corp.
5 * Copyright (C) 2009 Renesas Technology Corp.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/compiler.h>
15 #include <linux/init.h>
16 #include <linux/ioport.h>
17 #include <linux/netdevice.h>
18 #include <linux/etherdevice.h>
19 #include <linux/if_arp.h>
20 #include <linux/rtnetlink.h>
21 #include <linux/delay.h>
22 #include <linux/completion.h>
23 #include <linux/mii.h>
24 #include <linux/pci.h>
25 #include <linux/ctype.h>
26 #include <linux/timer.h>
27 #include <linux/atomic.h>
29 #include <linux/uaccess.h>
31 static int wep_on_off;
33 #define WEP_ON_64BIT 1
34 #define WEP_ON_128BIT 2
37 #include "ks_hostif.h"
38 #include "ks_wlan_ioctl.h"
40 /* Include Wireless Extension definition and check version */
41 #include <linux/wireless.h>
42 #define WIRELESS_SPY /* enable iwspy support */
43 #include <net/iw_handler.h> /* New driver API */
45 /* Frequency list (map channels to frequencies) */
46 static const long frequency_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
47 2447, 2452, 2457, 2462, 2467, 2472, 2484
50 /* A few details needed for WEP (Wireless Equivalent Privacy) */
51 #define MAX_KEY_SIZE 13 /* 128 (?) bits */
52 #define MIN_KEY_SIZE 5 /* 40 bits RC4 - WEP */
55 u8 key[16]; /* 40-bit and 104-bit keys */
58 /* Backward compatibility */
59 #ifndef IW_ENCODE_NOKEY
60 #define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not present */
61 #define IW_ENCODE_MODE (IW_ENCODE_DISABLED | IW_ENCODE_RESTRICTED | IW_ENCODE_OPEN)
62 #endif /* IW_ENCODE_NOKEY */
64 /* List of Wireless Handlers (new API) */
65 static const struct iw_handler_def ks_wlan_handler_def;
67 #define KSC_OPNOTSUPP /* Operation Not Support */
72 static int ks_wlan_open(struct net_device *dev);
73 static void ks_wlan_tx_timeout(struct net_device *dev);
74 static int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev);
75 static int ks_wlan_close(struct net_device *dev);
76 static void ks_wlan_set_multicast_list(struct net_device *dev);
77 static struct net_device_stats *ks_wlan_get_stats(struct net_device *dev);
78 static int ks_wlan_set_mac_address(struct net_device *dev, void *addr);
79 static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq,
82 static atomic_t update_phyinfo;
83 static struct timer_list update_phyinfo_timer;
85 int ks_wlan_update_phy_information(struct ks_wlan_private *priv)
87 struct iw_statistics *wstats = &priv->wstats;
89 DPRINTK(4, "in_interrupt = %ld\n", in_interrupt());
91 if (priv->dev_state < DEVICE_STATE_READY)
92 return -1; /* not finished initialize */
94 if (atomic_read(&update_phyinfo))
98 wstats->status = priv->reg.operation_mode; /* Operation mode */
100 /* Signal quality and co. But where is the noise level ??? */
101 hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST);
103 /* interruptible_sleep_on_timeout(&priv->confirm_wait, HZ/2); */
104 if (!wait_for_completion_interruptible_timeout
105 (&priv->confirm_wait, HZ / 2)) {
106 DPRINTK(1, "wait time out!!\n");
109 atomic_inc(&update_phyinfo);
110 update_phyinfo_timer.expires = jiffies + HZ; /* 1sec */
111 add_timer(&update_phyinfo_timer);
117 void ks_wlan_update_phyinfo_timeout(unsigned long ptr)
119 DPRINTK(4, "in_interrupt = %ld\n", in_interrupt());
120 atomic_set(&update_phyinfo, 0);
123 int ks_wlan_setup_parameter(struct ks_wlan_private *priv,
124 unsigned int commit_flag)
128 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
130 if (commit_flag & SME_RTS)
131 hostif_sme_enqueue(priv, SME_RTS_THRESHOLD_REQUEST);
132 if (commit_flag & SME_FRAG)
133 hostif_sme_enqueue(priv, SME_FRAGMENTATION_THRESHOLD_REQUEST);
135 if (commit_flag & SME_WEP_INDEX)
136 hostif_sme_enqueue(priv, SME_WEP_INDEX_REQUEST);
137 if (commit_flag & SME_WEP_VAL1)
138 hostif_sme_enqueue(priv, SME_WEP_KEY1_REQUEST);
139 if (commit_flag & SME_WEP_VAL2)
140 hostif_sme_enqueue(priv, SME_WEP_KEY2_REQUEST);
141 if (commit_flag & SME_WEP_VAL3)
142 hostif_sme_enqueue(priv, SME_WEP_KEY3_REQUEST);
143 if (commit_flag & SME_WEP_VAL4)
144 hostif_sme_enqueue(priv, SME_WEP_KEY4_REQUEST);
145 if (commit_flag & SME_WEP_FLAG)
146 hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
148 if (commit_flag & SME_RSN) {
149 hostif_sme_enqueue(priv, SME_RSN_ENABLED_REQUEST);
150 hostif_sme_enqueue(priv, SME_RSN_MODE_REQUEST);
152 if (commit_flag & SME_RSN_MULTICAST)
153 hostif_sme_enqueue(priv, SME_RSN_MCAST_REQUEST);
154 if (commit_flag & SME_RSN_UNICAST)
155 hostif_sme_enqueue(priv, SME_RSN_UCAST_REQUEST);
156 if (commit_flag & SME_RSN_AUTH)
157 hostif_sme_enqueue(priv, SME_RSN_AUTH_REQUEST);
159 hostif_sme_enqueue(priv, SME_MODE_SET_REQUEST);
161 hostif_sme_enqueue(priv, SME_START_REQUEST);
167 * Initial Wireless Extension code for Ks_Wlannet driver by :
168 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00
169 * Conversion to new driver API by :
170 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 26 March 02
171 * Javier also did a good amount of work here, adding some new extensions
172 * and fixing my code. Let's just say that without him this code just
173 * would not work at all... - Jean II
176 /*------------------------------------------------------------------*/
177 /* Wireless Handler : get protocol name */
178 static int ks_wlan_get_name(struct net_device *dev,
179 struct iw_request_info *info, char *cwrq,
182 struct ks_wlan_private *priv =
183 (struct ks_wlan_private *)netdev_priv(dev);
185 if (priv->sleep_mode == SLP_SLEEP)
189 if (priv->dev_state < DEVICE_STATE_READY)
190 strcpy(cwrq, "NOT READY!");
191 else if (priv->reg.phy_type == D_11B_ONLY_MODE)
192 strcpy(cwrq, "IEEE 802.11b");
193 else if (priv->reg.phy_type == D_11G_ONLY_MODE)
194 strcpy(cwrq, "IEEE 802.11g");
196 strcpy(cwrq, "IEEE 802.11b/g");
201 /*------------------------------------------------------------------*/
202 /* Wireless Handler : set frequency */
203 static int ks_wlan_set_freq(struct net_device *dev,
204 struct iw_request_info *info, struct iw_freq *fwrq,
207 struct ks_wlan_private *priv =
208 (struct ks_wlan_private *)netdev_priv(dev);
209 int rc = -EINPROGRESS; /* Call commit handler */
211 if (priv->sleep_mode == SLP_SLEEP)
215 /* If setting by frequency, convert to a channel */
216 if ((fwrq->e == 1) &&
217 (fwrq->m >= (int)2.412e8) && (fwrq->m <= (int)2.487e8)) {
218 int f = fwrq->m / 100000;
221 while ((c < 14) && (f != frequency_list[c]))
223 /* Hack to fall through... */
227 /* Setting by channel number */
228 if ((fwrq->m > 1000) || (fwrq->e > 0))
231 int channel = fwrq->m;
232 /* We should do a better check than that,
233 * based on the card capability !!! */
234 if ((channel < 1) || (channel > 14)) {
236 "%s: New channel value of %d is invalid!\n",
240 /* Yes ! We can set it !!! */
241 priv->reg.channel = (u8) (channel);
242 priv->need_commit |= SME_MODE_SET;
249 /*------------------------------------------------------------------*/
250 /* Wireless Handler : get frequency */
251 static int ks_wlan_get_freq(struct net_device *dev,
252 struct iw_request_info *info, struct iw_freq *fwrq,
255 struct ks_wlan_private *priv =
256 (struct ks_wlan_private *)netdev_priv(dev);
259 if (priv->sleep_mode == SLP_SLEEP)
263 if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS)
264 f = (int)priv->current_ap.channel;
266 f = (int)priv->reg.channel;
267 fwrq->m = frequency_list[f - 1] * 100000;
273 /*------------------------------------------------------------------*/
274 /* Wireless Handler : set ESSID */
275 static int ks_wlan_set_essid(struct net_device *dev,
276 struct iw_request_info *info,
277 struct iw_point *dwrq, char *extra)
279 struct ks_wlan_private *priv =
280 (struct ks_wlan_private *)netdev_priv(dev);
283 DPRINTK(2, " %d\n", dwrq->flags);
285 if (priv->sleep_mode == SLP_SLEEP)
289 /* Check if we asked for `any' */
290 if (dwrq->flags == 0) {
291 /* Just send an empty SSID list */
292 memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
293 priv->reg.ssid.size = 0;
297 /* iwconfig uses nul termination in SSID.. */
298 if (len > 0 && extra[len - 1] == '\0')
301 /* Check the size of the string */
302 if (len > IW_ESSID_MAX_SIZE)
306 /* Check the size of the string */
307 if (dwrq->length > IW_ESSID_MAX_SIZE + 1)
313 memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
316 memcpy(priv->reg.ssid.body, extra, len);
317 priv->reg.ssid.size = len;
319 memcpy(priv->reg.ssid.body, extra, dwrq->length);
320 priv->reg.ssid.size = dwrq->length;
323 /* Write it to the card */
324 priv->need_commit |= SME_MODE_SET;
326 // return -EINPROGRESS; /* Call commit handler */
327 ks_wlan_setup_parameter(priv, priv->need_commit);
328 priv->need_commit = 0;
332 /*------------------------------------------------------------------*/
333 /* Wireless Handler : get ESSID */
334 static int ks_wlan_get_essid(struct net_device *dev,
335 struct iw_request_info *info,
336 struct iw_point *dwrq, char *extra)
338 struct ks_wlan_private *priv =
339 (struct ks_wlan_private *)netdev_priv(dev);
341 if (priv->sleep_mode == SLP_SLEEP)
345 /* Note : if dwrq->flags != 0, we should
346 * get the relevant SSID from the SSID list... */
347 if (priv->reg.ssid.size) {
348 /* Get the current SSID */
349 memcpy(extra, priv->reg.ssid.body, priv->reg.ssid.size);
351 extra[priv->reg.ssid.size] = '\0';
353 /* If none, we may want to get the one that was set */
357 dwrq->length = priv->reg.ssid.size;
359 dwrq->length = priv->reg.ssid.size + 1;
361 dwrq->flags = 1; /* active */
369 dwrq->flags = 0; /* ANY */
375 /*------------------------------------------------------------------*/
376 /* Wireless Handler : set AP address */
377 static int ks_wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
378 struct sockaddr *ap_addr, char *extra)
380 struct ks_wlan_private *priv =
381 (struct ks_wlan_private *)netdev_priv(dev);
385 if (priv->sleep_mode == SLP_SLEEP)
389 if (priv->reg.operation_mode == MODE_ADHOC ||
390 priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
391 memcpy(priv->reg.bssid, &ap_addr->sa_data, ETH_ALEN);
393 if (is_valid_ether_addr((u8 *)priv->reg.bssid))
394 priv->need_commit |= SME_MODE_SET;
397 eth_zero_addr(priv->reg.bssid);
401 DPRINTK(2, "bssid = %pM\n", priv->reg.bssid);
403 /* Write it to the card */
404 if (priv->need_commit) {
405 priv->need_commit |= SME_MODE_SET;
406 return -EINPROGRESS; /* Call commit handler */
411 /*------------------------------------------------------------------*/
412 /* Wireless Handler : get AP address */
413 static int ks_wlan_get_wap(struct net_device *dev, struct iw_request_info *info,
414 struct sockaddr *awrq, char *extra)
416 struct ks_wlan_private *priv =
417 (struct ks_wlan_private *)netdev_priv(dev);
419 if (priv->sleep_mode == SLP_SLEEP)
423 if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS)
424 memcpy(awrq->sa_data, &(priv->current_ap.bssid[0]), ETH_ALEN);
426 eth_zero_addr(awrq->sa_data);
428 awrq->sa_family = ARPHRD_ETHER;
433 /*------------------------------------------------------------------*/
434 /* Wireless Handler : set Nickname */
435 static int ks_wlan_set_nick(struct net_device *dev,
436 struct iw_request_info *info, struct iw_point *dwrq,
439 struct ks_wlan_private *priv =
440 (struct ks_wlan_private *)netdev_priv(dev);
442 if (priv->sleep_mode == SLP_SLEEP)
446 /* Check the size of the string */
447 if (dwrq->length > 16 + 1)
450 memset(priv->nick, 0, sizeof(priv->nick));
451 memcpy(priv->nick, extra, dwrq->length);
453 return -EINPROGRESS; /* Call commit handler */
456 /*------------------------------------------------------------------*/
457 /* Wireless Handler : get Nickname */
458 static int ks_wlan_get_nick(struct net_device *dev,
459 struct iw_request_info *info, struct iw_point *dwrq,
462 struct ks_wlan_private *priv =
463 (struct ks_wlan_private *)netdev_priv(dev);
465 if (priv->sleep_mode == SLP_SLEEP)
469 strncpy(extra, priv->nick, 16);
471 dwrq->length = strlen(extra) + 1;
476 /*------------------------------------------------------------------*/
477 /* Wireless Handler : set Bit-Rate */
478 static int ks_wlan_set_rate(struct net_device *dev,
479 struct iw_request_info *info, struct iw_param *vwrq,
482 struct ks_wlan_private *priv =
483 (struct ks_wlan_private *)netdev_priv(dev);
486 if (priv->sleep_mode == SLP_SLEEP)
490 if (priv->reg.phy_type == D_11B_ONLY_MODE) {
491 if (vwrq->fixed == 1) {
492 switch (vwrq->value) {
495 priv->reg.rate_set.body[0] =
496 (uint8_t) (vwrq->value / 500000);
500 priv->reg.rate_set.body[0] =
501 ((uint8_t) (vwrq->value / 500000)) |
507 priv->reg.tx_rate = TX_RATE_FIXED;
508 priv->reg.rate_set.size = 1;
509 } else { /* vwrq->fixed == 0 */
510 if (vwrq->value > 0) {
511 switch (vwrq->value) {
513 priv->reg.rate_set.body[3] =
517 priv->reg.rate_set.body[2] = TX_RATE_5M;
520 priv->reg.rate_set.body[1] =
521 TX_RATE_2M | BASIC_RATE;
524 priv->reg.rate_set.body[0] =
525 TX_RATE_1M | BASIC_RATE;
531 priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
532 priv->reg.rate_set.size = i;
534 priv->reg.rate_set.body[3] = TX_RATE_11M;
535 priv->reg.rate_set.body[2] = TX_RATE_5M;
536 priv->reg.rate_set.body[1] =
537 TX_RATE_2M | BASIC_RATE;
538 priv->reg.rate_set.body[0] =
539 TX_RATE_1M | BASIC_RATE;
540 priv->reg.tx_rate = TX_RATE_FULL_AUTO;
541 priv->reg.rate_set.size = 4;
544 } else { /* D_11B_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
545 if (vwrq->fixed == 1) {
546 switch (vwrq->value) {
552 priv->reg.rate_set.body[0] =
553 (uint8_t) (vwrq->value / 500000);
562 priv->reg.rate_set.body[0] =
563 ((uint8_t) (vwrq->value / 500000)) |
569 priv->reg.tx_rate = TX_RATE_FIXED;
570 priv->reg.rate_set.size = 1;
571 } else { /* vwrq->fixed == 0 */
572 if (vwrq->value > 0) {
573 switch (vwrq->value) {
575 priv->reg.rate_set.body[11] =
579 priv->reg.rate_set.body[10] =
583 priv->reg.rate_set.body[9] =
592 if (vwrq->value == 24000000) {
593 priv->reg.rate_set.body[8] =
596 priv->reg.rate_set.body[7] =
599 priv->reg.rate_set.body[6] =
600 TX_RATE_24M | BASIC_RATE;
602 priv->reg.rate_set.body[5] =
603 TX_RATE_12M | BASIC_RATE;
605 priv->reg.rate_set.body[4] =
606 TX_RATE_6M | BASIC_RATE;
608 priv->reg.rate_set.body[3] =
609 TX_RATE_11M | BASIC_RATE;
611 } else if (vwrq->value == 18000000) {
612 priv->reg.rate_set.body[7] =
615 priv->reg.rate_set.body[6] =
618 priv->reg.rate_set.body[5] =
619 TX_RATE_12M | BASIC_RATE;
621 priv->reg.rate_set.body[4] =
622 TX_RATE_6M | BASIC_RATE;
624 priv->reg.rate_set.body[3] =
625 TX_RATE_11M | BASIC_RATE;
627 } else if (vwrq->value == 12000000) {
628 priv->reg.rate_set.body[6] =
631 priv->reg.rate_set.body[5] =
632 TX_RATE_12M | BASIC_RATE;
634 priv->reg.rate_set.body[4] =
635 TX_RATE_6M | BASIC_RATE;
637 priv->reg.rate_set.body[3] =
638 TX_RATE_11M | BASIC_RATE;
640 } else if (vwrq->value == 11000000) {
641 priv->reg.rate_set.body[5] =
644 priv->reg.rate_set.body[4] =
645 TX_RATE_6M | BASIC_RATE;
647 priv->reg.rate_set.body[3] =
648 TX_RATE_11M | BASIC_RATE;
650 } else if (vwrq->value == 9000000) {
651 priv->reg.rate_set.body[4] =
654 priv->reg.rate_set.body[3] =
655 TX_RATE_6M | BASIC_RATE;
657 } else { /* vwrq->value == 6000000 */
658 priv->reg.rate_set.body[3] =
659 TX_RATE_6M | BASIC_RATE;
663 priv->reg.rate_set.body[2] =
664 TX_RATE_5M | BASIC_RATE;
667 priv->reg.rate_set.body[1] =
668 TX_RATE_2M | BASIC_RATE;
671 priv->reg.rate_set.body[0] =
672 TX_RATE_1M | BASIC_RATE;
678 priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
679 priv->reg.rate_set.size = i;
681 priv->reg.rate_set.body[11] = TX_RATE_54M;
682 priv->reg.rate_set.body[10] = TX_RATE_48M;
683 priv->reg.rate_set.body[9] = TX_RATE_36M;
684 priv->reg.rate_set.body[8] = TX_RATE_18M;
685 priv->reg.rate_set.body[7] = TX_RATE_9M;
686 priv->reg.rate_set.body[6] =
687 TX_RATE_24M | BASIC_RATE;
688 priv->reg.rate_set.body[5] =
689 TX_RATE_12M | BASIC_RATE;
690 priv->reg.rate_set.body[4] =
691 TX_RATE_6M | BASIC_RATE;
692 priv->reg.rate_set.body[3] =
693 TX_RATE_11M | BASIC_RATE;
694 priv->reg.rate_set.body[2] =
695 TX_RATE_5M | BASIC_RATE;
696 priv->reg.rate_set.body[1] =
697 TX_RATE_2M | BASIC_RATE;
698 priv->reg.rate_set.body[0] =
699 TX_RATE_1M | BASIC_RATE;
700 priv->reg.tx_rate = TX_RATE_FULL_AUTO;
701 priv->reg.rate_set.size = 12;
706 priv->need_commit |= SME_MODE_SET;
708 return -EINPROGRESS; /* Call commit handler */
711 /*------------------------------------------------------------------*/
712 /* Wireless Handler : get Bit-Rate */
713 static int ks_wlan_get_rate(struct net_device *dev,
714 struct iw_request_info *info, struct iw_param *vwrq,
717 struct ks_wlan_private *priv =
718 (struct ks_wlan_private *)netdev_priv(dev);
720 DPRINTK(2, "in_interrupt = %ld update_phyinfo = %d\n",
721 in_interrupt(), atomic_read(&update_phyinfo));
723 if (priv->sleep_mode == SLP_SLEEP)
727 if (!atomic_read(&update_phyinfo))
728 ks_wlan_update_phy_information(priv);
730 vwrq->value = ((priv->current_rate) & RATE_MASK) * 500000;
731 if (priv->reg.tx_rate == TX_RATE_FIXED)
739 /*------------------------------------------------------------------*/
740 /* Wireless Handler : set RTS threshold */
741 static int ks_wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
742 struct iw_param *vwrq, char *extra)
744 struct ks_wlan_private *priv =
745 (struct ks_wlan_private *)netdev_priv(dev);
746 int rthr = vwrq->value;
748 if (priv->sleep_mode == SLP_SLEEP)
754 if ((rthr < 0) || (rthr > 2347))
757 priv->reg.rts = rthr;
758 priv->need_commit |= SME_RTS;
760 return -EINPROGRESS; /* Call commit handler */
763 /*------------------------------------------------------------------*/
764 /* Wireless Handler : get RTS threshold */
765 static int ks_wlan_get_rts(struct net_device *dev, struct iw_request_info *info,
766 struct iw_param *vwrq, char *extra)
768 struct ks_wlan_private *priv =
769 (struct ks_wlan_private *)netdev_priv(dev);
771 if (priv->sleep_mode == SLP_SLEEP)
775 vwrq->value = priv->reg.rts;
776 vwrq->disabled = (vwrq->value >= 2347);
782 /*------------------------------------------------------------------*/
783 /* Wireless Handler : set Fragmentation threshold */
784 static int ks_wlan_set_frag(struct net_device *dev,
785 struct iw_request_info *info, struct iw_param *vwrq,
788 struct ks_wlan_private *priv =
789 (struct ks_wlan_private *)netdev_priv(dev);
790 int fthr = vwrq->value;
792 if (priv->sleep_mode == SLP_SLEEP)
798 if ((fthr < 256) || (fthr > 2346))
801 fthr &= ~0x1; /* Get an even value - is it really needed ??? */
802 priv->reg.fragment = fthr;
803 priv->need_commit |= SME_FRAG;
805 return -EINPROGRESS; /* Call commit handler */
808 /*------------------------------------------------------------------*/
809 /* Wireless Handler : get Fragmentation threshold */
810 static int ks_wlan_get_frag(struct net_device *dev,
811 struct iw_request_info *info, struct iw_param *vwrq,
814 struct ks_wlan_private *priv =
815 (struct ks_wlan_private *)netdev_priv(dev);
817 if (priv->sleep_mode == SLP_SLEEP)
821 vwrq->value = priv->reg.fragment;
822 vwrq->disabled = (vwrq->value >= 2346);
828 /*------------------------------------------------------------------*/
829 /* Wireless Handler : set Mode of Operation */
830 static int ks_wlan_set_mode(struct net_device *dev,
831 struct iw_request_info *info, __u32 *uwrq,
834 struct ks_wlan_private *priv =
835 (struct ks_wlan_private *)netdev_priv(dev);
837 DPRINTK(2, "mode=%d\n", *uwrq);
839 if (priv->sleep_mode == SLP_SLEEP)
845 priv->reg.operation_mode = MODE_ADHOC;
846 priv->need_commit |= SME_MODE_SET;
849 priv->reg.operation_mode = MODE_INFRASTRUCTURE;
850 priv->need_commit |= SME_MODE_SET;
856 case IW_MODE_MONITOR:
861 return -EINPROGRESS; /* Call commit handler */
864 /*------------------------------------------------------------------*/
865 /* Wireless Handler : get Mode of Operation */
866 static int ks_wlan_get_mode(struct net_device *dev,
867 struct iw_request_info *info, __u32 *uwrq,
870 struct ks_wlan_private *priv =
871 (struct ks_wlan_private *)netdev_priv(dev);
873 if (priv->sleep_mode == SLP_SLEEP)
877 /* If not managed, assume it's ad-hoc */
878 switch (priv->reg.operation_mode) {
879 case MODE_INFRASTRUCTURE:
880 *uwrq = IW_MODE_INFRA;
883 *uwrq = IW_MODE_ADHOC;
886 *uwrq = IW_MODE_ADHOC;
892 /*------------------------------------------------------------------*/
893 /* Wireless Handler : set Encryption Key */
894 static int ks_wlan_set_encode(struct net_device *dev,
895 struct iw_request_info *info,
896 struct iw_point *dwrq, char *extra)
898 struct ks_wlan_private *priv =
899 (struct ks_wlan_private *)netdev_priv(dev);
902 int index = (dwrq->flags & IW_ENCODE_INDEX);
903 int current_index = priv->reg.wep_index;
906 DPRINTK(2, "flags=%04X\n", dwrq->flags);
908 if (priv->sleep_mode == SLP_SLEEP)
913 if ((index < 0) || (index > 4))
916 index = current_index;
920 /* Is WEP supported ? */
921 /* Basic checking: do we have a key to set ? */
922 if (dwrq->length > 0) {
923 if (dwrq->length > MAX_KEY_SIZE) { /* Check the size of the key */
926 if (dwrq->length > MIN_KEY_SIZE) { /* Set the length */
927 key.len = MAX_KEY_SIZE;
928 priv->reg.privacy_invoked = 0x01;
929 priv->need_commit |= SME_WEP_FLAG;
930 wep_on_off = WEP_ON_128BIT;
932 if (dwrq->length > 0) {
933 key.len = MIN_KEY_SIZE;
934 priv->reg.privacy_invoked = 0x01;
935 priv->need_commit |= SME_WEP_FLAG;
936 wep_on_off = WEP_ON_64BIT;
937 } else { /* Disable the key */
941 /* Check if the key is not marked as invalid */
942 if (!(dwrq->flags & IW_ENCODE_NOKEY)) {
944 memset(key.key, 0, MAX_KEY_SIZE);
945 /* Copy the key in the driver */
947 (key.key, dwrq->pointer, dwrq->length)) {
951 /* Send the key to the card */
952 priv->reg.wep_key[index].size = key.len;
953 for (i = 0; i < (priv->reg.wep_key[index].size); i++)
954 priv->reg.wep_key[index].val[i] = key.key[i];
956 priv->need_commit |= (SME_WEP_VAL1 << index);
957 priv->reg.wep_index = index;
958 priv->need_commit |= SME_WEP_INDEX;
961 if (dwrq->flags & IW_ENCODE_DISABLED) {
962 priv->reg.wep_key[0].size = 0;
963 priv->reg.wep_key[1].size = 0;
964 priv->reg.wep_key[2].size = 0;
965 priv->reg.wep_key[3].size = 0;
966 priv->reg.privacy_invoked = 0x00;
967 if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY)
968 priv->need_commit |= SME_MODE_SET;
970 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
971 wep_on_off = WEP_OFF;
972 priv->need_commit |= SME_WEP_FLAG;
974 /* Do we want to just set the transmit key index ? */
975 if ((index >= 0) && (index < 4)) {
976 /* set_wep_key(priv, index, 0, 0, 1); xxx */
977 if (priv->reg.wep_key[index].size) {
978 priv->reg.wep_index = index;
979 priv->need_commit |= SME_WEP_INDEX;
986 /* Commit the changes if needed */
987 if (dwrq->flags & IW_ENCODE_MODE)
988 priv->need_commit |= SME_WEP_FLAG;
990 if (dwrq->flags & IW_ENCODE_OPEN) {
991 if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY)
992 priv->need_commit |= SME_MODE_SET;
994 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
995 } else if (dwrq->flags & IW_ENCODE_RESTRICTED) {
996 if (priv->reg.authenticate_type == AUTH_TYPE_OPEN_SYSTEM)
997 priv->need_commit |= SME_MODE_SET;
999 priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
1001 // return -EINPROGRESS; /* Call commit handler */
1002 if (priv->need_commit) {
1003 ks_wlan_setup_parameter(priv, priv->need_commit);
1004 priv->need_commit = 0;
1009 /*------------------------------------------------------------------*/
1010 /* Wireless Handler : get Encryption Key */
1011 static int ks_wlan_get_encode(struct net_device *dev,
1012 struct iw_request_info *info,
1013 struct iw_point *dwrq, char *extra)
1015 struct ks_wlan_private *priv =
1016 (struct ks_wlan_private *)netdev_priv(dev);
1018 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1020 if (priv->sleep_mode == SLP_SLEEP)
1023 /* for SLEEP MODE */
1024 dwrq->flags = IW_ENCODE_DISABLED;
1026 /* Check encryption mode */
1027 switch (priv->reg.authenticate_type) {
1028 case AUTH_TYPE_OPEN_SYSTEM:
1029 dwrq->flags = IW_ENCODE_OPEN;
1031 case AUTH_TYPE_SHARED_KEY:
1032 dwrq->flags = IW_ENCODE_RESTRICTED;
1036 memset(zeros, 0, sizeof(zeros));
1038 /* Which key do we want ? -1 -> tx index */
1039 if ((index < 0) || (index >= 4))
1040 index = priv->reg.wep_index;
1041 if (priv->reg.privacy_invoked) {
1042 dwrq->flags &= ~IW_ENCODE_DISABLED;
1043 /* dwrq->flags |= IW_ENCODE_NOKEY; */
1045 dwrq->flags |= index + 1;
1046 DPRINTK(2, "encoding flag = 0x%04X\n", dwrq->flags);
1047 /* Copy the key to the user buffer */
1048 if ((index >= 0) && (index < 4))
1049 dwrq->length = priv->reg.wep_key[index].size;
1050 if (dwrq->length > 16)
1052 #if 1 /* IW_ENCODE_NOKEY; */
1054 if ((index >= 0) && (index < 4))
1055 memcpy(extra, priv->reg.wep_key[index].val,
1058 memcpy(extra, zeros, dwrq->length);
1063 #ifndef KSC_OPNOTSUPP
1064 /*------------------------------------------------------------------*/
1065 /* Wireless Handler : set Tx-Power */
1066 static int ks_wlan_set_txpow(struct net_device *dev,
1067 struct iw_request_info *info,
1068 struct iw_param *vwrq, char *extra)
1070 return -EOPNOTSUPP; /* Not Support */
1073 /*------------------------------------------------------------------*/
1074 /* Wireless Handler : get Tx-Power */
1075 static int ks_wlan_get_txpow(struct net_device *dev,
1076 struct iw_request_info *info,
1077 struct iw_param *vwrq, char *extra)
1079 if (priv->sleep_mode == SLP_SLEEP)
1082 /* for SLEEP MODE */
1085 vwrq->disabled = (vwrq->value == 0);
1090 /*------------------------------------------------------------------*/
1091 /* Wireless Handler : set Retry limits */
1092 static int ks_wlan_set_retry(struct net_device *dev,
1093 struct iw_request_info *info,
1094 struct iw_param *vwrq, char *extra)
1096 return -EOPNOTSUPP; /* Not Support */
1099 /*------------------------------------------------------------------*/
1100 /* Wireless Handler : get Retry limits */
1101 static int ks_wlan_get_retry(struct net_device *dev,
1102 struct iw_request_info *info,
1103 struct iw_param *vwrq, char *extra)
1105 if (priv->sleep_mode == SLP_SLEEP)
1108 /* for SLEEP MODE */
1111 vwrq->disabled = (vwrq->value == 0);
1115 #endif /* KSC_OPNOTSUPP */
1117 /*------------------------------------------------------------------*/
1118 /* Wireless Handler : get range info */
1119 static int ks_wlan_get_range(struct net_device *dev,
1120 struct iw_request_info *info,
1121 struct iw_point *dwrq, char *extra)
1123 struct ks_wlan_private *priv =
1124 (struct ks_wlan_private *)netdev_priv(dev);
1125 struct iw_range *range = (struct iw_range *)extra;
1130 if (priv->sleep_mode == SLP_SLEEP)
1133 /* for SLEEP MODE */
1134 dwrq->length = sizeof(struct iw_range);
1135 memset(range, 0, sizeof(*range));
1136 range->min_nwid = 0x0000;
1137 range->max_nwid = 0x0000;
1138 range->num_channels = 14;
1139 /* Should be based on cap_rid.country to give only
1140 * what the current card support */
1142 for (i = 0; i < 13; i++) { /* channel 1 -- 13 */
1143 range->freq[k].i = i + 1; /* List index */
1144 range->freq[k].m = frequency_list[i] * 100000;
1145 range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
1147 range->num_frequency = k;
1148 if (priv->reg.phy_type == D_11B_ONLY_MODE || priv->reg.phy_type == D_11BG_COMPATIBLE_MODE) { /* channel 14 */
1149 range->freq[13].i = 14; /* List index */
1150 range->freq[13].m = frequency_list[13] * 100000;
1151 range->freq[13].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
1152 range->num_frequency = 14;
1155 /* Hum... Should put the right values there */
1156 range->max_qual.qual = 100;
1157 range->max_qual.level = 256 - 128; /* 0 dBm? */
1158 range->max_qual.noise = 256 - 128;
1159 range->sensitivity = 1;
1161 if (priv->reg.phy_type == D_11B_ONLY_MODE) {
1162 range->bitrate[0] = 1e6;
1163 range->bitrate[1] = 2e6;
1164 range->bitrate[2] = 5.5e6;
1165 range->bitrate[3] = 11e6;
1166 range->num_bitrates = 4;
1167 } else { /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
1168 range->bitrate[0] = 1e6;
1169 range->bitrate[1] = 2e6;
1170 range->bitrate[2] = 5.5e6;
1171 range->bitrate[3] = 11e6;
1173 range->bitrate[4] = 6e6;
1174 range->bitrate[5] = 9e6;
1175 range->bitrate[6] = 12e6;
1176 if (IW_MAX_BITRATES < 9) {
1177 range->bitrate[7] = 54e6;
1178 range->num_bitrates = 8;
1180 range->bitrate[7] = 18e6;
1181 range->bitrate[8] = 24e6;
1182 range->bitrate[9] = 36e6;
1183 range->bitrate[10] = 48e6;
1184 range->bitrate[11] = 54e6;
1186 range->num_bitrates = 12;
1190 /* Set an indication of the max TCP throughput
1191 * in bit/s that we can expect using this interface.
1192 * May be use for QoS stuff... Jean II */
1194 range->throughput = 5000 * 1000;
1196 range->throughput = 1500 * 1000;
1199 range->max_rts = 2347;
1200 range->min_frag = 256;
1201 range->max_frag = 2346;
1203 range->encoding_size[0] = 5; /* WEP: RC4 40 bits */
1204 range->encoding_size[1] = 13; /* WEP: RC4 ~128 bits */
1205 range->num_encoding_sizes = 2;
1206 range->max_encoding_tokens = 4;
1208 /* power management not support */
1209 range->pmp_flags = IW_POWER_ON;
1210 range->pmt_flags = IW_POWER_ON;
1213 /* Transmit Power - values are in dBm( or mW) */
1214 range->txpower[0] = -256;
1215 range->num_txpower = 1;
1216 range->txpower_capa = IW_TXPOW_DBM;
1217 /* range->txpower_capa = IW_TXPOW_MWATT; */
1219 range->we_version_source = 21;
1220 range->we_version_compiled = WIRELESS_EXT;
1222 range->retry_capa = IW_RETRY_ON;
1223 range->retry_flags = IW_RETRY_ON;
1224 range->r_time_flags = IW_RETRY_ON;
1226 /* Experimental measurements - boundary 11/5.5 Mb/s */
1227 /* Note : with or without the (local->rssi), results
1228 * are somewhat different. - Jean II */
1229 range->avg_qual.qual = 50;
1230 range->avg_qual.level = 186; /* -70 dBm */
1231 range->avg_qual.noise = 0;
1233 /* Event capability (kernel + driver) */
1234 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
1235 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
1236 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
1237 range->event_capa[1] = IW_EVENT_CAPA_K_1;
1238 range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVCUSTOM) |
1239 IW_EVENT_CAPA_MASK(IWEVMICHAELMICFAILURE));
1241 /* encode extension (WPA) capability */
1242 range->enc_capa = (IW_ENC_CAPA_WPA |
1244 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP);
1248 /*------------------------------------------------------------------*/
1249 /* Wireless Handler : set Power Management */
1250 static int ks_wlan_set_power(struct net_device *dev,
1251 struct iw_request_info *info,
1252 struct iw_param *vwrq, char *extra)
1254 struct ks_wlan_private *priv =
1255 (struct ks_wlan_private *)netdev_priv(dev);
1258 if (priv->sleep_mode == SLP_SLEEP)
1261 /* for SLEEP MODE */
1262 enabled = vwrq->disabled ? 0 : 1;
1263 if (enabled == 0) { /* 0 */
1264 priv->reg.powermgt = POWMGT_ACTIVE_MODE;
1265 } else if (enabled) { /* 1 */
1266 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
1267 priv->reg.powermgt = POWMGT_SAVE1_MODE;
1270 } else if (enabled) { /* 2 */
1271 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
1272 priv->reg.powermgt = POWMGT_SAVE2_MODE;
1278 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
1283 /*------------------------------------------------------------------*/
1284 /* Wireless Handler : get Power Management */
1285 static int ks_wlan_get_power(struct net_device *dev,
1286 struct iw_request_info *info,
1287 struct iw_param *vwrq, char *extra)
1289 struct ks_wlan_private *priv =
1290 (struct ks_wlan_private *)netdev_priv(dev);
1292 if (priv->sleep_mode == SLP_SLEEP)
1294 /* for SLEEP MODE */
1295 if (priv->reg.powermgt > 0)
1303 /*------------------------------------------------------------------*/
1304 /* Wireless Handler : get wirless statistics */
1305 static int ks_wlan_get_iwstats(struct net_device *dev,
1306 struct iw_request_info *info,
1307 struct iw_quality *vwrq, char *extra)
1309 struct ks_wlan_private *priv =
1310 (struct ks_wlan_private *)netdev_priv(dev);
1312 if (priv->sleep_mode == SLP_SLEEP)
1314 /* for SLEEP MODE */
1315 vwrq->qual = 0; /* not supported */
1316 vwrq->level = priv->wstats.qual.level;
1317 vwrq->noise = 0; /* not supported */
1323 #ifndef KSC_OPNOTSUPP
1324 /*------------------------------------------------------------------*/
1325 /* Wireless Handler : set Sensitivity */
1326 static int ks_wlan_set_sens(struct net_device *dev,
1327 struct iw_request_info *info, struct iw_param *vwrq,
1330 return -EOPNOTSUPP; /* Not Support */
1333 /*------------------------------------------------------------------*/
1334 /* Wireless Handler : get Sensitivity */
1335 static int ks_wlan_get_sens(struct net_device *dev,
1336 struct iw_request_info *info, struct iw_param *vwrq,
1341 vwrq->disabled = (vwrq->value == 0);
1345 #endif /* KSC_OPNOTSUPP */
1347 /*------------------------------------------------------------------*/
1348 /* Wireless Handler : get AP List */
1349 /* Note : this is deprecated in favor of IWSCAN */
1350 static int ks_wlan_get_aplist(struct net_device *dev,
1351 struct iw_request_info *info,
1352 struct iw_point *dwrq, char *extra)
1354 struct ks_wlan_private *priv =
1355 (struct ks_wlan_private *)netdev_priv(dev);
1356 struct sockaddr *address = (struct sockaddr *)extra;
1357 struct iw_quality qual[LOCAL_APLIST_MAX];
1361 if (priv->sleep_mode == SLP_SLEEP)
1363 /* for SLEEP MODE */
1364 for (i = 0; i < priv->aplist.size; i++) {
1365 memcpy(address[i].sa_data, &(priv->aplist.ap[i].bssid[0]),
1367 address[i].sa_family = ARPHRD_ETHER;
1368 qual[i].level = 256 - priv->aplist.ap[i].rssi;
1369 qual[i].qual = priv->aplist.ap[i].sq;
1370 qual[i].noise = 0; /* invalid noise value */
1371 qual[i].updated = 7;
1374 dwrq->flags = 1; /* Should be define'd */
1375 memcpy(extra + sizeof(struct sockaddr) * i,
1376 &qual, sizeof(struct iw_quality) * i);
1383 /*------------------------------------------------------------------*/
1384 /* Wireless Handler : Initiate Scan */
1385 static int ks_wlan_set_scan(struct net_device *dev,
1386 struct iw_request_info *info,
1387 union iwreq_data *wrqu, char *extra)
1389 struct ks_wlan_private *priv =
1390 (struct ks_wlan_private *)netdev_priv(dev);
1391 struct iw_scan_req *req = NULL;
1395 if (priv->sleep_mode == SLP_SLEEP)
1398 /* for SLEEP MODE */
1399 /* specified SSID SCAN */
1400 if (wrqu->data.length == sizeof(struct iw_scan_req)
1401 && wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1402 req = (struct iw_scan_req *)extra;
1403 priv->scan_ssid_len = req->essid_len;
1404 memcpy(priv->scan_ssid, req->essid, priv->scan_ssid_len);
1406 priv->scan_ssid_len = 0;
1409 priv->sme_i.sme_flag |= SME_AP_SCAN;
1410 hostif_sme_enqueue(priv, SME_BSS_SCAN_REQUEST);
1412 /* At this point, just return to the user. */
1417 /*------------------------------------------------------------------*/
1419 * Translate scan data returned from the card to a card independent
1420 * format that the Wireless Tools will understand - Jean II
1422 static inline char *ks_wlan_translate_scan(struct net_device *dev,
1423 struct iw_request_info *info,
1424 char *current_ev, char *end_buf,
1425 struct local_ap_t *ap)
1427 /* struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; */
1428 struct iw_event iwe; /* Temporary buffer */
1430 char *current_val; /* For rates */
1432 static const char rsn_leader[] = "rsn_ie=";
1433 static const char wpa_leader[] = "wpa_ie=";
1434 char buf0[RSN_IE_BODY_MAX * 2 + 30];
1435 char buf1[RSN_IE_BODY_MAX * 2 + 30];
1437 /* First entry *MUST* be the AP MAC address */
1438 iwe.cmd = SIOCGIWAP;
1439 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1440 memcpy(iwe.u.ap_addr.sa_data, ap->bssid, ETH_ALEN);
1442 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1445 /* Other entries will be displayed in the order we give them */
1448 iwe.u.data.length = ap->ssid.size;
1449 if (iwe.u.data.length > 32)
1450 iwe.u.data.length = 32;
1451 iwe.cmd = SIOCGIWESSID;
1452 iwe.u.data.flags = 1;
1454 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1455 &(ap->ssid.body[0]));
1458 iwe.cmd = SIOCGIWMODE;
1459 capabilities = le16_to_cpu(ap->capability);
1460 if (capabilities & (BSS_CAP_ESS | BSS_CAP_IBSS)) {
1461 if (capabilities & BSS_CAP_ESS)
1462 iwe.u.mode = IW_MODE_INFRA;
1464 iwe.u.mode = IW_MODE_ADHOC;
1466 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1471 iwe.cmd = SIOCGIWFREQ;
1472 iwe.u.freq.m = ap->channel;
1473 iwe.u.freq.m = frequency_list[iwe.u.freq.m - 1] * 100000;
1476 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1479 /* Add quality statistics */
1481 iwe.u.qual.level = 256 - ap->rssi;
1482 iwe.u.qual.qual = ap->sq;
1483 iwe.u.qual.noise = 0; /* invalid noise value */
1485 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1488 /* Add encryption capability */
1489 iwe.cmd = SIOCGIWENCODE;
1490 if (capabilities & BSS_CAP_PRIVACY)
1491 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1493 iwe.u.data.flags = IW_ENCODE_DISABLED;
1494 iwe.u.data.length = 0;
1496 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1497 &(ap->ssid.body[0]));
1499 /* Rate : stuffing multiple values in a single event require a bit
1500 * more of magic - Jean II */
1501 current_val = current_ev + IW_EV_LCP_LEN;
1503 iwe.cmd = SIOCGIWRATE;
1504 /* Those two flags are ignored... */
1505 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
1508 for (i = 0; i < 16; i++) {
1509 /* NULL terminated */
1510 if (i >= ap->rate_set.size)
1512 /* Bit rate given in 500 kb/s units (+ 0x80) */
1513 iwe.u.bitrate.value = ((ap->rate_set.body[i] & 0x7f) * 500000);
1514 /* Add new value to event */
1516 iwe_stream_add_value(info, current_ev, current_val, end_buf,
1517 &iwe, IW_EV_PARAM_LEN);
1519 /* Check if we added any event */
1520 if ((current_val - current_ev) > IW_EV_LCP_LEN)
1521 current_ev = current_val;
1523 #define GENERIC_INFO_ELEM_ID 0xdd
1524 #define RSN_INFO_ELEM_ID 0x30
1525 if (ap->rsn_ie.id == RSN_INFO_ELEM_ID && ap->rsn_ie.size != 0) {
1527 memset(&iwe, 0, sizeof(iwe));
1528 iwe.cmd = IWEVCUSTOM;
1529 memcpy(buf0, rsn_leader, sizeof(rsn_leader) - 1);
1530 iwe.u.data.length += sizeof(rsn_leader) - 1;
1531 pbuf += sizeof(rsn_leader) - 1;
1533 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.id);
1534 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.size);
1535 iwe.u.data.length += 4;
1537 for (i = 0; i < ap->rsn_ie.size; i++)
1538 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.body[i]);
1539 iwe.u.data.length += (ap->rsn_ie.size) * 2;
1541 DPRINTK(4, "ap->rsn.size=%d\n", ap->rsn_ie.size);
1544 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1547 if (ap->wpa_ie.id == GENERIC_INFO_ELEM_ID && ap->wpa_ie.size != 0) {
1549 memset(&iwe, 0, sizeof(iwe));
1550 iwe.cmd = IWEVCUSTOM;
1551 memcpy(buf1, wpa_leader, sizeof(wpa_leader) - 1);
1552 iwe.u.data.length += sizeof(wpa_leader) - 1;
1553 pbuf += sizeof(wpa_leader) - 1;
1555 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.id);
1556 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.size);
1557 iwe.u.data.length += 4;
1559 for (i = 0; i < ap->wpa_ie.size; i++)
1560 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.body[i]);
1561 iwe.u.data.length += (ap->wpa_ie.size) * 2;
1563 DPRINTK(4, "ap->rsn.size=%d\n", ap->wpa_ie.size);
1564 DPRINTK(4, "iwe.u.data.length=%d\n", iwe.u.data.length);
1567 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1571 /* The other data in the scan result are not really
1572 * interesting, so for now drop it - Jean II */
1576 /*------------------------------------------------------------------*/
1577 /* Wireless Handler : Read Scan Results */
1578 static int ks_wlan_get_scan(struct net_device *dev,
1579 struct iw_request_info *info, struct iw_point *dwrq,
1582 struct ks_wlan_private *priv =
1583 (struct ks_wlan_private *)netdev_priv(dev);
1585 char *current_ev = extra;
1589 if (priv->sleep_mode == SLP_SLEEP)
1591 /* for SLEEP MODE */
1592 if (priv->sme_i.sme_flag & SME_AP_SCAN) {
1593 DPRINTK(2, "flag AP_SCAN\n");
1597 if (priv->aplist.size == 0) {
1598 /* Client error, no scan results...
1599 * The caller need to restart the scan. */
1600 DPRINTK(2, "aplist 0\n");
1604 /* current connect ap */
1605 if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
1606 if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) {
1610 current_ev = ks_wlan_translate_scan(dev, current_ev,
1611 // extra + IW_SCAN_MAX_DATA,
1612 extra + dwrq->length,
1613 &(priv->current_ap));
1616 /* Read and parse all entries */
1617 for (i = 0; i < priv->aplist.size; i++) {
1618 if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) {
1622 /* Translate to WE format this entry */
1623 current_ev = ks_wlan_translate_scan(dev, info, current_ev,
1624 // extra + IW_SCAN_MAX_DATA,
1625 extra + dwrq->length,
1626 &(priv->aplist.ap[i]));
1628 /* Length of data */
1629 dwrq->length = (current_ev - extra);
1635 /*------------------------------------------------------------------*/
1636 /* Commit handler : called after a bunch of SET operations */
1637 static int ks_wlan_config_commit(struct net_device *dev,
1638 struct iw_request_info *info, void *zwrq,
1641 struct ks_wlan_private *priv =
1642 (struct ks_wlan_private *)netdev_priv(dev);
1644 if (!priv->need_commit)
1647 ks_wlan_setup_parameter(priv, priv->need_commit);
1648 priv->need_commit = 0;
1652 /*------------------------------------------------------------------*/
1653 /* Wireless handler : set association ie params */
1654 static int ks_wlan_set_genie(struct net_device *dev,
1655 struct iw_request_info *info,
1656 struct iw_point *dwrq, char *extra)
1658 struct ks_wlan_private *priv =
1659 (struct ks_wlan_private *)netdev_priv(dev);
1663 if (priv->sleep_mode == SLP_SLEEP)
1665 /* for SLEEP MODE */
1667 // return -EOPNOTSUPP;
1670 /*------------------------------------------------------------------*/
1671 /* Wireless handler : set authentication mode params */
1672 static int ks_wlan_set_auth_mode(struct net_device *dev,
1673 struct iw_request_info *info,
1674 struct iw_param *vwrq, char *extra)
1676 struct ks_wlan_private *priv =
1677 (struct ks_wlan_private *)netdev_priv(dev);
1678 int index = (vwrq->flags & IW_AUTH_INDEX);
1679 int value = vwrq->value;
1681 DPRINTK(2, "index=%d:value=%08X\n", index, value);
1683 if (priv->sleep_mode == SLP_SLEEP)
1685 /* for SLEEP MODE */
1687 case IW_AUTH_WPA_VERSION: /* 0 */
1689 case IW_AUTH_WPA_VERSION_DISABLED:
1690 priv->wpa.version = value;
1691 if (priv->wpa.rsn_enabled)
1692 priv->wpa.rsn_enabled = 0;
1693 priv->need_commit |= SME_RSN;
1695 case IW_AUTH_WPA_VERSION_WPA:
1696 case IW_AUTH_WPA_VERSION_WPA2:
1697 priv->wpa.version = value;
1698 if (!(priv->wpa.rsn_enabled))
1699 priv->wpa.rsn_enabled = 1;
1700 priv->need_commit |= SME_RSN;
1706 case IW_AUTH_CIPHER_PAIRWISE: /* 1 */
1708 case IW_AUTH_CIPHER_NONE:
1709 if (priv->reg.privacy_invoked) {
1710 priv->reg.privacy_invoked = 0x00;
1711 priv->need_commit |= SME_WEP_FLAG;
1714 case IW_AUTH_CIPHER_WEP40:
1715 case IW_AUTH_CIPHER_TKIP:
1716 case IW_AUTH_CIPHER_CCMP:
1717 case IW_AUTH_CIPHER_WEP104:
1718 if (!priv->reg.privacy_invoked) {
1719 priv->reg.privacy_invoked = 0x01;
1720 priv->need_commit |= SME_WEP_FLAG;
1722 priv->wpa.pairwise_suite = value;
1723 priv->need_commit |= SME_RSN_UNICAST;
1729 case IW_AUTH_CIPHER_GROUP: /* 2 */
1731 case IW_AUTH_CIPHER_NONE:
1732 if (priv->reg.privacy_invoked) {
1733 priv->reg.privacy_invoked = 0x00;
1734 priv->need_commit |= SME_WEP_FLAG;
1737 case IW_AUTH_CIPHER_WEP40:
1738 case IW_AUTH_CIPHER_TKIP:
1739 case IW_AUTH_CIPHER_CCMP:
1740 case IW_AUTH_CIPHER_WEP104:
1741 if (!priv->reg.privacy_invoked) {
1742 priv->reg.privacy_invoked = 0x01;
1743 priv->need_commit |= SME_WEP_FLAG;
1745 priv->wpa.group_suite = value;
1746 priv->need_commit |= SME_RSN_MULTICAST;
1752 case IW_AUTH_KEY_MGMT: /* 3 */
1754 case IW_AUTH_KEY_MGMT_802_1X:
1755 case IW_AUTH_KEY_MGMT_PSK:
1756 case 0: /* NONE or 802_1X_NO_WPA */
1757 case 4: /* WPA_NONE */
1758 priv->wpa.key_mgmt_suite = value;
1759 priv->need_commit |= SME_RSN_AUTH;
1765 case IW_AUTH_80211_AUTH_ALG: /* 6 */
1767 case IW_AUTH_ALG_OPEN_SYSTEM:
1768 priv->wpa.auth_alg = value;
1769 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
1771 case IW_AUTH_ALG_SHARED_KEY:
1772 priv->wpa.auth_alg = value;
1773 priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
1775 case IW_AUTH_ALG_LEAP:
1779 priv->need_commit |= SME_MODE_SET;
1781 case IW_AUTH_WPA_ENABLED: /* 7 */
1782 priv->wpa.wpa_enabled = value;
1784 case IW_AUTH_PRIVACY_INVOKED: /* 10 */
1785 if ((value && !priv->reg.privacy_invoked) ||
1786 (!value && priv->reg.privacy_invoked)) {
1787 priv->reg.privacy_invoked = value ? 0x01 : 0x00;
1788 priv->need_commit |= SME_WEP_FLAG;
1791 case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* 4 */
1792 case IW_AUTH_TKIP_COUNTERMEASURES: /* 5 */
1793 case IW_AUTH_DROP_UNENCRYPTED: /* 8 */
1794 case IW_AUTH_ROAMING_CONTROL: /* 9 */
1799 /* return -EINPROGRESS; */
1800 if (priv->need_commit) {
1801 ks_wlan_setup_parameter(priv, priv->need_commit);
1802 priv->need_commit = 0;
1807 /*------------------------------------------------------------------*/
1808 /* Wireless handler : get authentication mode params */
1809 static int ks_wlan_get_auth_mode(struct net_device *dev,
1810 struct iw_request_info *info,
1811 struct iw_param *vwrq, char *extra)
1813 struct ks_wlan_private *priv =
1814 (struct ks_wlan_private *)netdev_priv(dev);
1815 int index = (vwrq->flags & IW_AUTH_INDEX);
1817 DPRINTK(2, "index=%d\n", index);
1819 if (priv->sleep_mode == SLP_SLEEP)
1822 /* for SLEEP MODE */
1823 /* WPA (not used ?? wpa_supplicant) */
1825 case IW_AUTH_WPA_VERSION:
1826 vwrq->value = priv->wpa.version;
1828 case IW_AUTH_CIPHER_PAIRWISE:
1829 vwrq->value = priv->wpa.pairwise_suite;
1831 case IW_AUTH_CIPHER_GROUP:
1832 vwrq->value = priv->wpa.group_suite;
1834 case IW_AUTH_KEY_MGMT:
1835 vwrq->value = priv->wpa.key_mgmt_suite;
1837 case IW_AUTH_80211_AUTH_ALG:
1838 vwrq->value = priv->wpa.auth_alg;
1840 case IW_AUTH_WPA_ENABLED:
1841 vwrq->value = priv->wpa.rsn_enabled;
1843 case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* OK??? */
1844 case IW_AUTH_TKIP_COUNTERMEASURES:
1845 case IW_AUTH_DROP_UNENCRYPTED:
1847 /* return -EOPNOTSUPP; */
1853 /*------------------------------------------------------------------*/
1854 /* Wireless Handler : set encoding token & mode (WPA)*/
1855 static int ks_wlan_set_encode_ext(struct net_device *dev,
1856 struct iw_request_info *info,
1857 struct iw_point *dwrq, char *extra)
1859 struct ks_wlan_private *priv =
1860 (struct ks_wlan_private *)netdev_priv(dev);
1861 struct iw_encode_ext *enc;
1862 int index = dwrq->flags & IW_ENCODE_INDEX;
1863 unsigned int commit = 0;
1865 enc = (struct iw_encode_ext *)extra;
1867 DPRINTK(2, "flags=%04X:: ext_flags=%08X\n", dwrq->flags,
1870 if (priv->sleep_mode == SLP_SLEEP)
1873 /* for SLEEP MODE */
1874 if (index < 1 || index > 4)
1879 if (dwrq->flags & IW_ENCODE_DISABLED)
1880 priv->wpa.key[index].key_len = 0;
1883 priv->wpa.key[index].ext_flags = enc->ext_flags;
1884 if (enc->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
1885 priv->wpa.txkey = index;
1886 commit |= SME_WEP_INDEX;
1887 } else if (enc->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
1888 memcpy(&priv->wpa.key[index].rx_seq[0],
1889 enc->rx_seq, IW_ENCODE_SEQ_MAX_SIZE);
1892 memcpy(&priv->wpa.key[index].addr.sa_data[0],
1893 &enc->addr.sa_data[0], ETH_ALEN);
1896 case IW_ENCODE_ALG_NONE:
1897 if (priv->reg.privacy_invoked) {
1898 priv->reg.privacy_invoked = 0x00;
1899 commit |= SME_WEP_FLAG;
1901 priv->wpa.key[index].key_len = 0;
1904 case IW_ENCODE_ALG_WEP:
1905 case IW_ENCODE_ALG_CCMP:
1906 if (!priv->reg.privacy_invoked) {
1907 priv->reg.privacy_invoked = 0x01;
1908 commit |= SME_WEP_FLAG;
1911 memcpy(&priv->wpa.key[index].key_val[0],
1912 &enc->key[0], enc->key_len);
1913 priv->wpa.key[index].key_len = enc->key_len;
1914 commit |= (SME_WEP_VAL1 << index);
1917 case IW_ENCODE_ALG_TKIP:
1918 if (!priv->reg.privacy_invoked) {
1919 priv->reg.privacy_invoked = 0x01;
1920 commit |= SME_WEP_FLAG;
1922 if (enc->key_len == 32) {
1923 memcpy(&priv->wpa.key[index].key_val[0],
1924 &enc->key[0], enc->key_len - 16);
1925 priv->wpa.key[index].key_len =
1927 if (priv->wpa.key_mgmt_suite == 4) { /* WPA_NONE */
1928 memcpy(&priv->wpa.key[index].
1929 tx_mic_key[0], &enc->key[16], 8);
1930 memcpy(&priv->wpa.key[index].
1931 rx_mic_key[0], &enc->key[16], 8);
1933 memcpy(&priv->wpa.key[index].
1934 tx_mic_key[0], &enc->key[16], 8);
1935 memcpy(&priv->wpa.key[index].
1936 rx_mic_key[0], &enc->key[24], 8);
1938 commit |= (SME_WEP_VAL1 << index);
1944 priv->wpa.key[index].alg = enc->alg;
1949 if (commit & SME_WEP_INDEX)
1950 hostif_sme_enqueue(priv, SME_SET_TXKEY);
1951 if (commit & SME_WEP_VAL_MASK)
1952 hostif_sme_enqueue(priv, SME_SET_KEY1 + index);
1953 if (commit & SME_WEP_FLAG)
1954 hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
1960 /*------------------------------------------------------------------*/
1961 /* Wireless Handler : get encoding token & mode (WPA)*/
1962 static int ks_wlan_get_encode_ext(struct net_device *dev,
1963 struct iw_request_info *info,
1964 struct iw_point *dwrq, char *extra)
1966 struct ks_wlan_private *priv =
1967 (struct ks_wlan_private *)netdev_priv(dev);
1969 if (priv->sleep_mode == SLP_SLEEP)
1972 /* for SLEEP MODE */
1973 /* WPA (not used ?? wpa_supplicant)
1974 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
1975 struct iw_encode_ext *enc;
1976 enc = (struct iw_encode_ext *)extra;
1977 int index = dwrq->flags & IW_ENCODE_INDEX;
1978 WPA (not used ?? wpa_supplicant) */
1982 /*------------------------------------------------------------------*/
1983 /* Wireless Handler : PMKSA cache operation (WPA2) */
1984 static int ks_wlan_set_pmksa(struct net_device *dev,
1985 struct iw_request_info *info,
1986 struct iw_point *dwrq, char *extra)
1988 struct ks_wlan_private *priv =
1989 (struct ks_wlan_private *)netdev_priv(dev);
1990 struct iw_pmksa *pmksa;
1993 struct list_head *ptr;
1997 if (priv->sleep_mode == SLP_SLEEP)
2000 /* for SLEEP MODE */
2004 pmksa = (struct iw_pmksa *)extra;
2005 DPRINTK(2, "cmd=%d\n", pmksa->cmd);
2007 switch (pmksa->cmd) {
2009 if (list_empty(&priv->pmklist.head)) { /* new list */
2010 for (i = 0; i < PMK_LIST_MAX; i++) {
2011 pmk = &priv->pmklist.pmk[i];
2013 ("\x00\x00\x00\x00\x00\x00", pmk->bssid,
2017 memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
2018 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
2019 list_add(&pmk->list, &priv->pmklist.head);
2020 priv->pmklist.size++;
2021 } else { /* search cache data */
2022 list_for_each(ptr, &priv->pmklist.head) {
2023 pmk = list_entry(ptr, struct pmk_t, list);
2024 if (!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)) { /* match address! list move to head. */
2025 memcpy(pmk->pmkid, pmksa->pmkid,
2027 list_move(&pmk->list,
2028 &priv->pmklist.head);
2032 if (ptr == &priv->pmklist.head) { /* not find address. */
2033 if (PMK_LIST_MAX > priv->pmklist.size) { /* new cache data */
2034 for (i = 0; i < PMK_LIST_MAX; i++) {
2035 pmk = &priv->pmklist.pmk[i];
2037 ("\x00\x00\x00\x00\x00\x00",
2038 pmk->bssid, ETH_ALEN))
2041 memcpy(pmk->bssid, pmksa->bssid.sa_data,
2043 memcpy(pmk->pmkid, pmksa->pmkid,
2045 list_add(&pmk->list,
2046 &priv->pmklist.head);
2047 priv->pmklist.size++;
2048 } else { /* overwrite old cache data */
2050 list_entry(priv->pmklist.head.prev,
2051 struct pmk_t, list);
2052 memcpy(pmk->bssid, pmksa->bssid.sa_data,
2054 memcpy(pmk->pmkid, pmksa->pmkid,
2056 list_move(&pmk->list,
2057 &priv->pmklist.head);
2062 case IW_PMKSA_REMOVE:
2063 if (list_empty(&priv->pmklist.head)) { /* list empty */
2065 } else { /* search cache data */
2066 list_for_each(ptr, &priv->pmklist.head) {
2067 pmk = list_entry(ptr, struct pmk_t, list);
2068 if (!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)) { /* match address! list del. */
2069 eth_zero_addr(pmk->bssid);
2070 memset(pmk->pmkid, 0, IW_PMKID_LEN);
2071 list_del_init(&pmk->list);
2075 if (ptr == &priv->pmklist.head) { /* not find address. */
2080 case IW_PMKSA_FLUSH:
2081 memset(&(priv->pmklist), 0, sizeof(priv->pmklist));
2082 INIT_LIST_HEAD(&priv->pmklist.head);
2083 for (i = 0; i < PMK_LIST_MAX; i++)
2084 INIT_LIST_HEAD(&priv->pmklist.pmk[i].list);
2090 hostif_sme_enqueue(priv, SME_SET_PMKSA);
2094 static struct iw_statistics *ks_get_wireless_stats(struct net_device *dev)
2096 struct ks_wlan_private *priv =
2097 (struct ks_wlan_private *)netdev_priv(dev);
2098 struct iw_statistics *wstats = &priv->wstats;
2100 if (!atomic_read(&update_phyinfo)) {
2101 if (priv->dev_state < DEVICE_STATE_READY)
2102 return NULL; /* not finished initialize */
2107 /* Packets discarded in the wireless adapter due to wireless
2108 * specific problems */
2109 wstats->discard.nwid = 0; /* Rx invalid nwid */
2110 wstats->discard.code = 0; /* Rx invalid crypt */
2111 wstats->discard.fragment = 0; /* Rx invalid frag */
2112 wstats->discard.retries = 0; /* Tx excessive retries */
2113 wstats->discard.misc = 0; /* Invalid misc */
2114 wstats->miss.beacon = 0; /* Missed beacon */
2119 /*------------------------------------------------------------------*/
2120 /* Private handler : set stop request */
2121 static int ks_wlan_set_stop_request(struct net_device *dev,
2122 struct iw_request_info *info, __u32 *uwrq,
2125 struct ks_wlan_private *priv =
2126 (struct ks_wlan_private *)netdev_priv(dev);
2129 if (priv->sleep_mode == SLP_SLEEP)
2132 /* for SLEEP MODE */
2136 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2140 /*------------------------------------------------------------------*/
2141 /* Wireless Handler : set MLME */
2142 #include <linux/ieee80211.h>
2143 static int ks_wlan_set_mlme(struct net_device *dev,
2144 struct iw_request_info *info, struct iw_point *dwrq,
2147 struct ks_wlan_private *priv =
2148 (struct ks_wlan_private *)netdev_priv(dev);
2149 struct iw_mlme *mlme = (struct iw_mlme *)extra;
2152 DPRINTK(2, ":%d :%d\n", mlme->cmd, mlme->reason_code);
2154 if (priv->sleep_mode == SLP_SLEEP)
2157 /* for SLEEP MODE */
2158 switch (mlme->cmd) {
2159 case IW_MLME_DEAUTH:
2160 if (mlme->reason_code == WLAN_REASON_MIC_FAILURE)
2162 case IW_MLME_DISASSOC:
2164 return ks_wlan_set_stop_request(dev, NULL, &mode, NULL);
2166 return -EOPNOTSUPP; /* Not Support */
2170 /*------------------------------------------------------------------*/
2171 /* Private handler : get firemware version */
2172 static int ks_wlan_get_firmware_version(struct net_device *dev,
2173 struct iw_request_info *info,
2174 struct iw_point *dwrq, char *extra)
2176 struct ks_wlan_private *priv =
2177 (struct ks_wlan_private *)netdev_priv(dev);
2178 strcpy(extra, &(priv->firmware_version[0]));
2179 dwrq->length = priv->version_size + 1;
2184 /*------------------------------------------------------------------*/
2185 /* Private handler : set force disconnect status */
2186 static int ks_wlan_set_detach(struct net_device *dev,
2187 struct iw_request_info *info, __u32 *uwrq,
2190 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2192 if (priv->sleep_mode == SLP_SLEEP)
2195 /* for SLEEP MODE */
2196 if (*uwrq == CONNECT_STATUS) { /* 0 */
2197 priv->connect_status &= ~FORCE_DISCONNECT;
2198 if ((priv->connect_status & CONNECT_STATUS_MASK) ==
2200 netif_carrier_on(dev);
2201 } else if (*uwrq == DISCONNECT_STATUS) { /* 1 */
2202 priv->connect_status |= FORCE_DISCONNECT;
2203 netif_carrier_off(dev);
2209 /*------------------------------------------------------------------*/
2210 /* Private handler : get force disconnect status */
2211 static int ks_wlan_get_detach(struct net_device *dev,
2212 struct iw_request_info *info, __u32 *uwrq,
2215 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2217 if (priv->sleep_mode == SLP_SLEEP)
2220 /* for SLEEP MODE */
2221 *uwrq = ((priv->connect_status & FORCE_DISCONNECT) ? 1 : 0);
2225 /*------------------------------------------------------------------*/
2226 /* Private handler : get connect status */
2227 static int ks_wlan_get_connect(struct net_device *dev,
2228 struct iw_request_info *info, __u32 *uwrq,
2231 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2233 if (priv->sleep_mode == SLP_SLEEP)
2236 /* for SLEEP MODE */
2237 *uwrq = (priv->connect_status & CONNECT_STATUS_MASK);
2242 /*------------------------------------------------------------------*/
2243 /* Private handler : set preamble */
2244 static int ks_wlan_set_preamble(struct net_device *dev,
2245 struct iw_request_info *info, __u32 *uwrq,
2248 struct ks_wlan_private *priv =
2249 (struct ks_wlan_private *)netdev_priv(dev);
2251 if (priv->sleep_mode == SLP_SLEEP)
2254 /* for SLEEP MODE */
2255 if (*uwrq == LONG_PREAMBLE) { /* 0 */
2256 priv->reg.preamble = LONG_PREAMBLE;
2257 } else if (*uwrq == SHORT_PREAMBLE) { /* 1 */
2258 priv->reg.preamble = SHORT_PREAMBLE;
2262 priv->need_commit |= SME_MODE_SET;
2263 return -EINPROGRESS; /* Call commit handler */
2266 /*------------------------------------------------------------------*/
2267 /* Private handler : get preamble */
2268 static int ks_wlan_get_preamble(struct net_device *dev,
2269 struct iw_request_info *info, __u32 *uwrq,
2272 struct ks_wlan_private *priv =
2273 (struct ks_wlan_private *)netdev_priv(dev);
2275 if (priv->sleep_mode == SLP_SLEEP)
2278 /* for SLEEP MODE */
2279 *uwrq = priv->reg.preamble;
2283 /*------------------------------------------------------------------*/
2284 /* Private handler : set power save mode */
2285 static int ks_wlan_set_powermgt(struct net_device *dev,
2286 struct iw_request_info *info, __u32 *uwrq,
2289 struct ks_wlan_private *priv =
2290 (struct ks_wlan_private *)netdev_priv(dev);
2292 if (priv->sleep_mode == SLP_SLEEP)
2295 /* for SLEEP MODE */
2296 if (*uwrq == POWMGT_ACTIVE_MODE) { /* 0 */
2297 priv->reg.powermgt = POWMGT_ACTIVE_MODE;
2298 } else if (*uwrq == POWMGT_SAVE1_MODE) { /* 1 */
2299 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2300 priv->reg.powermgt = POWMGT_SAVE1_MODE;
2303 } else if (*uwrq == POWMGT_SAVE2_MODE) { /* 2 */
2304 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2305 priv->reg.powermgt = POWMGT_SAVE2_MODE;
2311 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
2316 /*------------------------------------------------------------------*/
2317 /* Private handler : get power save made */
2318 static int ks_wlan_get_powermgt(struct net_device *dev,
2319 struct iw_request_info *info, __u32 *uwrq,
2322 struct ks_wlan_private *priv =
2323 (struct ks_wlan_private *)netdev_priv(dev);
2325 if (priv->sleep_mode == SLP_SLEEP)
2328 /* for SLEEP MODE */
2329 *uwrq = priv->reg.powermgt;
2333 /*------------------------------------------------------------------*/
2334 /* Private handler : set scan type */
2335 static int ks_wlan_set_scan_type(struct net_device *dev,
2336 struct iw_request_info *info, __u32 *uwrq,
2339 struct ks_wlan_private *priv =
2340 (struct ks_wlan_private *)netdev_priv(dev);
2342 if (priv->sleep_mode == SLP_SLEEP)
2344 /* for SLEEP MODE */
2345 if (*uwrq == ACTIVE_SCAN) { /* 0 */
2346 priv->reg.scan_type = ACTIVE_SCAN;
2347 } else if (*uwrq == PASSIVE_SCAN) { /* 1 */
2348 priv->reg.scan_type = PASSIVE_SCAN;
2355 /*------------------------------------------------------------------*/
2356 /* Private handler : get scan type */
2357 static int ks_wlan_get_scan_type(struct net_device *dev,
2358 struct iw_request_info *info, __u32 *uwrq,
2361 struct ks_wlan_private *priv =
2362 (struct ks_wlan_private *)netdev_priv(dev);
2364 if (priv->sleep_mode == SLP_SLEEP)
2366 /* for SLEEP MODE */
2367 *uwrq = priv->reg.scan_type;
2372 /*------------------------------------------------------------------*/
2373 /* Private handler : write raw data to device */
2374 static int ks_wlan_data_write(struct net_device *dev,
2375 struct iw_request_info *info,
2376 struct iw_point *dwrq, char *extra)
2378 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2379 unsigned char *wbuff = NULL;
2381 if (priv->sleep_mode == SLP_SLEEP)
2383 /* for SLEEP MODE */
2384 wbuff = (unsigned char *)kmalloc(dwrq->length, GFP_ATOMIC);
2387 memcpy(wbuff, extra, dwrq->length);
2389 /* write to device */
2390 ks_wlan_hw_tx(priv, wbuff, dwrq->length, NULL, NULL, NULL);
2395 /*------------------------------------------------------------------*/
2396 /* Private handler : read raw data form device */
2397 static int ks_wlan_data_read(struct net_device *dev,
2398 struct iw_request_info *info,
2399 struct iw_point *dwrq, char *extra)
2401 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2402 unsigned short read_length;
2404 if (priv->sleep_mode == SLP_SLEEP)
2406 /* for SLEEP MODE */
2407 if (!atomic_read(&priv->event_count)) {
2408 if (priv->dev_state < DEVICE_STATE_BOOT) { /* Remove device */
2410 memset(extra, 0xff, read_length);
2411 dwrq->length = read_length;
2415 memset(extra, 0, 1);
2420 if (atomic_read(&priv->event_count) > 0)
2421 atomic_dec(&priv->event_count);
2423 spin_lock(&priv->dev_read_lock); /* request spin lock */
2425 /* Copy length max size 0x07ff */
2426 if (priv->dev_size[priv->dev_count] > 2047)
2429 read_length = priv->dev_size[priv->dev_count];
2432 memcpy(extra, &(priv->dev_data[priv->dev_count][0]), read_length);
2434 spin_unlock(&priv->dev_read_lock); /* release spin lock */
2437 priv->dev_data[priv->dev_count] = 0;
2438 priv->dev_size[priv->dev_count] = 0;
2441 if (priv->dev_count == DEVICE_STOCK_COUNT)
2442 priv->dev_count = 0;
2445 dwrq->length = read_length;
2452 /*------------------------------------------------------------------*/
2453 /* Private handler : get wep string */
2454 #define WEP_ASCII_BUFF_SIZE (17 + 64 * 4 + 1)
2455 static int ks_wlan_get_wep_ascii(struct net_device *dev,
2456 struct iw_request_info *info,
2457 struct iw_point *dwrq, char *extra)
2459 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2461 char tmp[WEP_ASCII_BUFF_SIZE];
2463 if (priv->sleep_mode == SLP_SLEEP)
2465 /* for SLEEP MODE */
2466 strcpy(tmp, " WEP keys ASCII \n");
2467 len += strlen(" WEP keys ASCII \n");
2469 for (i = 0; i < 4; i++) {
2470 strcpy(tmp + len, "\t[");
2471 len += strlen("\t[");
2474 strcpy(tmp + len, "] ");
2475 len += strlen("] ");
2476 if (priv->reg.wep_key[i].size) {
2478 (priv->reg.wep_key[i].size <
2479 6 ? "(40bits) [" : "(104bits) ["));
2481 strlen((priv->reg.wep_key[i].size <
2482 6 ? "(40bits) [" : "(104bits) ["));
2483 for (j = 0; j < priv->reg.wep_key[i].size; j++, len++)
2485 (isprint(priv->reg.wep_key[i].val[j]) ?
2486 priv->reg.wep_key[i].val[j] : ' ');
2488 strcpy(tmp + len, "]\n");
2489 len += strlen("]\n");
2491 strcpy(tmp + len, "off\n");
2492 len += strlen("off\n");
2496 memcpy(extra, tmp, len);
2497 dwrq->length = len + 1;
2502 /*------------------------------------------------------------------*/
2503 /* Private handler : set beacon lost count */
2504 static int ks_wlan_set_beacon_lost(struct net_device *dev,
2505 struct iw_request_info *info, __u32 *uwrq,
2508 struct ks_wlan_private *priv =
2509 (struct ks_wlan_private *)netdev_priv(dev);
2511 if (priv->sleep_mode == SLP_SLEEP)
2513 /* for SLEEP MODE */
2514 if (*uwrq >= BEACON_LOST_COUNT_MIN && *uwrq <= BEACON_LOST_COUNT_MAX)
2515 priv->reg.beacon_lost_count = *uwrq;
2519 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
2520 priv->need_commit |= SME_MODE_SET;
2521 return -EINPROGRESS; /* Call commit handler */
2526 /*------------------------------------------------------------------*/
2527 /* Private handler : get beacon lost count */
2528 static int ks_wlan_get_beacon_lost(struct net_device *dev,
2529 struct iw_request_info *info, __u32 *uwrq,
2532 struct ks_wlan_private *priv =
2533 (struct ks_wlan_private *)netdev_priv(dev);
2535 if (priv->sleep_mode == SLP_SLEEP)
2537 /* for SLEEP MODE */
2538 *uwrq = priv->reg.beacon_lost_count;
2542 /*------------------------------------------------------------------*/
2543 /* Private handler : set phy type */
2544 static int ks_wlan_set_phy_type(struct net_device *dev,
2545 struct iw_request_info *info, __u32 *uwrq,
2548 struct ks_wlan_private *priv =
2549 (struct ks_wlan_private *)netdev_priv(dev);
2551 if (priv->sleep_mode == SLP_SLEEP)
2553 /* for SLEEP MODE */
2554 if (*uwrq == D_11B_ONLY_MODE) { /* 0 */
2555 priv->reg.phy_type = D_11B_ONLY_MODE;
2556 } else if (*uwrq == D_11G_ONLY_MODE) { /* 1 */
2557 priv->reg.phy_type = D_11G_ONLY_MODE;
2558 } else if (*uwrq == D_11BG_COMPATIBLE_MODE) { /* 2 */
2559 priv->reg.phy_type = D_11BG_COMPATIBLE_MODE;
2563 priv->need_commit |= SME_MODE_SET;
2564 return -EINPROGRESS; /* Call commit handler */
2567 /*------------------------------------------------------------------*/
2568 /* Private handler : get phy type */
2569 static int ks_wlan_get_phy_type(struct net_device *dev,
2570 struct iw_request_info *info, __u32 *uwrq,
2573 struct ks_wlan_private *priv =
2574 (struct ks_wlan_private *)netdev_priv(dev);
2576 if (priv->sleep_mode == SLP_SLEEP)
2578 /* for SLEEP MODE */
2579 *uwrq = priv->reg.phy_type;
2583 /*------------------------------------------------------------------*/
2584 /* Private handler : set cts mode */
2585 static int ks_wlan_set_cts_mode(struct net_device *dev,
2586 struct iw_request_info *info, __u32 *uwrq,
2589 struct ks_wlan_private *priv =
2590 (struct ks_wlan_private *)netdev_priv(dev);
2592 if (priv->sleep_mode == SLP_SLEEP)
2594 /* for SLEEP MODE */
2595 if (*uwrq == CTS_MODE_FALSE) { /* 0 */
2596 priv->reg.cts_mode = CTS_MODE_FALSE;
2597 } else if (*uwrq == CTS_MODE_TRUE) { /* 1 */
2598 if (priv->reg.phy_type == D_11G_ONLY_MODE ||
2599 priv->reg.phy_type == D_11BG_COMPATIBLE_MODE)
2600 priv->reg.cts_mode = CTS_MODE_TRUE;
2602 priv->reg.cts_mode = CTS_MODE_FALSE;
2606 priv->need_commit |= SME_MODE_SET;
2607 return -EINPROGRESS; /* Call commit handler */
2610 /*------------------------------------------------------------------*/
2611 /* Private handler : get cts mode */
2612 static int ks_wlan_get_cts_mode(struct net_device *dev,
2613 struct iw_request_info *info, __u32 *uwrq,
2616 struct ks_wlan_private *priv =
2617 (struct ks_wlan_private *)netdev_priv(dev);
2619 if (priv->sleep_mode == SLP_SLEEP)
2621 /* for SLEEP MODE */
2622 *uwrq = priv->reg.cts_mode;
2626 /*------------------------------------------------------------------*/
2627 /* Private handler : set sleep mode */
2628 static int ks_wlan_set_sleep_mode(struct net_device *dev,
2629 struct iw_request_info *info,
2630 __u32 *uwrq, char *extra)
2632 struct ks_wlan_private *priv =
2633 (struct ks_wlan_private *)netdev_priv(dev);
2637 if (*uwrq == SLP_SLEEP) {
2638 priv->sleep_mode = *uwrq;
2639 netdev_info(dev, "SET_SLEEP_MODE %d\n", priv->sleep_mode);
2641 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2642 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2644 } else if (*uwrq == SLP_ACTIVE) {
2645 priv->sleep_mode = *uwrq;
2646 netdev_info(dev, "SET_SLEEP_MODE %d\n", priv->sleep_mode);
2647 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2649 netdev_err(dev, "SET_SLEEP_MODE %d errror\n", *uwrq);
2656 /*------------------------------------------------------------------*/
2657 /* Private handler : get sleep mode */
2658 static int ks_wlan_get_sleep_mode(struct net_device *dev,
2659 struct iw_request_info *info,
2660 __u32 *uwrq, char *extra)
2662 struct ks_wlan_private *priv =
2663 (struct ks_wlan_private *)netdev_priv(dev);
2665 DPRINTK(2, "GET_SLEEP_MODE %d\n", priv->sleep_mode);
2666 *uwrq = priv->sleep_mode;
2672 /*------------------------------------------------------------------*/
2673 /* Private handler : set phy information timer */
2674 static int ks_wlan_set_phy_information_timer(struct net_device *dev,
2675 struct iw_request_info *info,
2676 __u32 *uwrq, char *extra)
2678 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2680 if (priv->sleep_mode == SLP_SLEEP)
2682 /* for SLEEP MODE */
2683 if (*uwrq >= 0 && *uwrq <= 0xFFFF) /* 0-65535 */
2684 priv->reg.phy_info_timer = (uint16_t)*uwrq;
2688 hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST);
2693 /*------------------------------------------------------------------*/
2694 /* Private handler : get phy information timer */
2695 static int ks_wlan_get_phy_information_timer(struct net_device *dev,
2696 struct iw_request_info *info,
2697 __u32 *uwrq, char *extra)
2699 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2701 if (priv->sleep_mode == SLP_SLEEP)
2703 /* for SLEEP MODE */
2704 *uwrq = priv->reg.phy_info_timer;
2710 /*------------------------------------------------------------------*/
2711 /* Private handler : set WPS enable */
2712 static int ks_wlan_set_wps_enable(struct net_device *dev,
2713 struct iw_request_info *info, __u32 *uwrq,
2716 struct ks_wlan_private *priv =
2717 (struct ks_wlan_private *)netdev_priv(dev);
2720 if (priv->sleep_mode == SLP_SLEEP)
2722 /* for SLEEP MODE */
2723 if (*uwrq == 0 || *uwrq == 1)
2724 priv->wps.wps_enabled = *uwrq;
2728 hostif_sme_enqueue(priv, SME_WPS_ENABLE_REQUEST);
2733 /*------------------------------------------------------------------*/
2734 /* Private handler : get WPS enable */
2735 static int ks_wlan_get_wps_enable(struct net_device *dev,
2736 struct iw_request_info *info, __u32 *uwrq,
2739 struct ks_wlan_private *priv =
2740 (struct ks_wlan_private *)netdev_priv(dev);
2743 if (priv->sleep_mode == SLP_SLEEP)
2745 /* for SLEEP MODE */
2746 *uwrq = priv->wps.wps_enabled;
2747 netdev_info(dev, "return=%d\n", *uwrq);
2752 /*------------------------------------------------------------------*/
2753 /* Private handler : set WPS probe req */
2754 static int ks_wlan_set_wps_probe_req(struct net_device *dev,
2755 struct iw_request_info *info,
2756 struct iw_point *dwrq, char *extra)
2760 struct ks_wlan_private *priv =
2761 (struct ks_wlan_private *)netdev_priv(dev);
2765 if (priv->sleep_mode == SLP_SLEEP)
2767 /* for SLEEP MODE */
2768 DPRINTK(2, "dwrq->length=%d\n", dwrq->length);
2771 if (p[1] + 2 != dwrq->length || dwrq->length > 256)
2774 priv->wps.ielen = p[1] + 2 + 1; /* IE header + IE + sizeof(len) */
2775 len = p[1] + 2; /* IE header + IE */
2777 memcpy(priv->wps.ie, &len, sizeof(len));
2778 p = memcpy(priv->wps.ie + 1, p, len);
2780 DPRINTK(2, "%d(%#x): %02X %02X %02X %02X ... %02X %02X %02X\n",
2781 priv->wps.ielen, priv->wps.ielen, p[0], p[1], p[2], p[3],
2782 p[priv->wps.ielen - 3], p[priv->wps.ielen - 2],
2783 p[priv->wps.ielen - 1]);
2785 hostif_sme_enqueue(priv, SME_WPS_PROBE_REQUEST);
2791 /*------------------------------------------------------------------*/
2792 /* Private handler : get WPS probe req */
2793 static int ks_wlan_get_wps_probe_req(struct net_device *dev,
2794 struct iw_request_info *info,
2795 __u32 *uwrq, char *extra)
2797 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2801 if (priv->sleep_mode == SLP_SLEEP)
2803 /* for SLEEP MODE */
2809 /*------------------------------------------------------------------*/
2810 /* Private handler : set tx gain control value */
2811 static int ks_wlan_set_tx_gain(struct net_device *dev,
2812 struct iw_request_info *info, __u32 *uwrq,
2815 struct ks_wlan_private *priv =
2816 (struct ks_wlan_private *)netdev_priv(dev);
2818 if (priv->sleep_mode == SLP_SLEEP)
2820 /* for SLEEP MODE */
2821 if (*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2822 priv->gain.TxGain = (uint8_t)*uwrq;
2826 if (priv->gain.TxGain < 0xFF)
2827 priv->gain.TxMode = 1;
2829 priv->gain.TxMode = 0;
2831 hostif_sme_enqueue(priv, SME_SET_GAIN);
2835 /*------------------------------------------------------------------*/
2836 /* Private handler : get tx gain control value */
2837 static int ks_wlan_get_tx_gain(struct net_device *dev,
2838 struct iw_request_info *info, __u32 *uwrq,
2841 struct ks_wlan_private *priv =
2842 (struct ks_wlan_private *)netdev_priv(dev);
2844 if (priv->sleep_mode == SLP_SLEEP)
2846 /* for SLEEP MODE */
2847 *uwrq = priv->gain.TxGain;
2848 hostif_sme_enqueue(priv, SME_GET_GAIN);
2852 /*------------------------------------------------------------------*/
2853 /* Private handler : set rx gain control value */
2854 static int ks_wlan_set_rx_gain(struct net_device *dev,
2855 struct iw_request_info *info, __u32 *uwrq,
2858 struct ks_wlan_private *priv =
2859 (struct ks_wlan_private *)netdev_priv(dev);
2861 if (priv->sleep_mode == SLP_SLEEP)
2863 /* for SLEEP MODE */
2864 if (*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2865 priv->gain.RxGain = (uint8_t)*uwrq;
2869 if (priv->gain.RxGain < 0xFF)
2870 priv->gain.RxMode = 1;
2872 priv->gain.RxMode = 0;
2874 hostif_sme_enqueue(priv, SME_SET_GAIN);
2878 /*------------------------------------------------------------------*/
2879 /* Private handler : get rx gain control value */
2880 static int ks_wlan_get_rx_gain(struct net_device *dev,
2881 struct iw_request_info *info, __u32 *uwrq,
2884 struct ks_wlan_private *priv =
2885 (struct ks_wlan_private *)netdev_priv(dev);
2887 if (priv->sleep_mode == SLP_SLEEP)
2889 /* for SLEEP MODE */
2890 *uwrq = priv->gain.RxGain;
2891 hostif_sme_enqueue(priv, SME_GET_GAIN);
2896 /*------------------------------------------------------------------*/
2897 /* Private handler : set region value */
2898 static int ks_wlan_set_region(struct net_device *dev,
2899 struct iw_request_info *info, __u32 *uwrq,
2902 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2904 if (priv->sleep_mode == SLP_SLEEP)
2906 /* for SLEEP MODE */
2907 if (*uwrq >= 0x9 && *uwrq <= 0xF) /* 0x9-0xf */
2908 priv->region = (uint8_t)*uwrq;
2912 hostif_sme_enqueue(priv, SME_SET_REGION);
2917 /*------------------------------------------------------------------*/
2918 /* Private handler : get eeprom checksum result */
2919 static int ks_wlan_get_eeprom_cksum(struct net_device *dev,
2920 struct iw_request_info *info, __u32 *uwrq,
2923 struct ks_wlan_private *priv =
2924 (struct ks_wlan_private *)netdev_priv(dev);
2926 *uwrq = priv->eeprom_checksum;
2930 static void print_hif_event(struct net_device *dev, int event)
2934 netdev_info(dev, "HIF_DATA_REQ\n");
2937 netdev_info(dev, "HIF_DATA_IND\n");
2939 case HIF_MIB_GET_REQ:
2940 netdev_info(dev, "HIF_MIB_GET_REQ\n");
2942 case HIF_MIB_GET_CONF:
2943 netdev_info(dev, "HIF_MIB_GET_CONF\n");
2945 case HIF_MIB_SET_REQ:
2946 netdev_info(dev, "HIF_MIB_SET_REQ\n");
2948 case HIF_MIB_SET_CONF:
2949 netdev_info(dev, "HIF_MIB_SET_CONF\n");
2951 case HIF_POWERMGT_REQ:
2952 netdev_info(dev, "HIF_POWERMGT_REQ\n");
2954 case HIF_POWERMGT_CONF:
2955 netdev_info(dev, "HIF_POWERMGT_CONF\n");
2958 netdev_info(dev, "HIF_START_REQ\n");
2960 case HIF_START_CONF:
2961 netdev_info(dev, "HIF_START_CONF\n");
2963 case HIF_CONNECT_IND:
2964 netdev_info(dev, "HIF_CONNECT_IND\n");
2967 netdev_info(dev, "HIF_STOP_REQ\n");
2970 netdev_info(dev, "HIF_STOP_CONF\n");
2972 case HIF_PS_ADH_SET_REQ:
2973 netdev_info(dev, "HIF_PS_ADH_SET_REQ\n");
2975 case HIF_PS_ADH_SET_CONF:
2976 netdev_info(dev, "HIF_PS_ADH_SET_CONF\n");
2978 case HIF_INFRA_SET_REQ:
2979 netdev_info(dev, "HIF_INFRA_SET_REQ\n");
2981 case HIF_INFRA_SET_CONF:
2982 netdev_info(dev, "HIF_INFRA_SET_CONF\n");
2984 case HIF_ADH_SET_REQ:
2985 netdev_info(dev, "HIF_ADH_SET_REQ\n");
2987 case HIF_ADH_SET_CONF:
2988 netdev_info(dev, "HIF_ADH_SET_CONF\n");
2990 case HIF_AP_SET_REQ:
2991 netdev_info(dev, "HIF_AP_SET_REQ\n");
2993 case HIF_AP_SET_CONF:
2994 netdev_info(dev, "HIF_AP_SET_CONF\n");
2996 case HIF_ASSOC_INFO_IND:
2997 netdev_info(dev, "HIF_ASSOC_INFO_IND\n");
2999 case HIF_MIC_FAILURE_REQ:
3000 netdev_info(dev, "HIF_MIC_FAILURE_REQ\n");
3002 case HIF_MIC_FAILURE_CONF:
3003 netdev_info(dev, "HIF_MIC_FAILURE_CONF\n");
3006 netdev_info(dev, "HIF_SCAN_REQ\n");
3009 netdev_info(dev, "HIF_SCAN_CONF\n");
3011 case HIF_PHY_INFO_REQ:
3012 netdev_info(dev, "HIF_PHY_INFO_REQ\n");
3014 case HIF_PHY_INFO_CONF:
3015 netdev_info(dev, "HIF_PHY_INFO_CONF\n");
3018 netdev_info(dev, "HIF_SLEEP_REQ\n");
3020 case HIF_SLEEP_CONF:
3021 netdev_info(dev, "HIF_SLEEP_CONF\n");
3023 case HIF_PHY_INFO_IND:
3024 netdev_info(dev, "HIF_PHY_INFO_IND\n");
3027 netdev_info(dev, "HIF_SCAN_IND\n");
3029 case HIF_INFRA_SET2_REQ:
3030 netdev_info(dev, "HIF_INFRA_SET2_REQ\n");
3032 case HIF_INFRA_SET2_CONF:
3033 netdev_info(dev, "HIF_INFRA_SET2_CONF\n");
3035 case HIF_ADH_SET2_REQ:
3036 netdev_info(dev, "HIF_ADH_SET2_REQ\n");
3038 case HIF_ADH_SET2_CONF:
3039 netdev_info(dev, "HIF_ADH_SET2_CONF\n");
3043 /*------------------------------------------------------------------*/
3044 /* Private handler : get host command history */
3045 static int ks_wlan_hostt(struct net_device *dev, struct iw_request_info *info,
3046 __u32 *uwrq, char *extra)
3049 struct ks_wlan_private *priv =
3050 (struct ks_wlan_private *)netdev_priv(dev);
3052 for (i = 63; i >= 0; i--) {
3054 priv->hostt.buff[(priv->hostt.qtail - 1 - i) %
3055 SME_EVENT_BUFF_SIZE];
3056 print_hif_event(dev, event);
3061 /* Structures to export the Wireless Handlers */
3063 static const struct iw_priv_args ks_wlan_private_args[] = {
3064 /*{ cmd, set_args, get_args, name[16] } */
3065 {KS_WLAN_GET_FIRM_VERSION, IW_PRIV_TYPE_NONE,
3066 IW_PRIV_TYPE_CHAR | (128 + 1), "GetFirmwareVer"},
3068 {KS_WLAN_SET_WPS_ENABLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3069 IW_PRIV_TYPE_NONE, "SetWPSEnable"},
3070 {KS_WLAN_GET_WPS_ENABLE, IW_PRIV_TYPE_NONE,
3071 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetW"},
3072 {KS_WLAN_SET_WPS_PROBE_REQ, IW_PRIV_TYPE_BYTE | 2047, IW_PRIV_TYPE_NONE,
3075 {KS_WLAN_SET_PREAMBLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3076 IW_PRIV_TYPE_NONE, "SetPreamble"},
3077 {KS_WLAN_GET_PREAMBLE, IW_PRIV_TYPE_NONE,
3078 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPreamble"},
3079 {KS_WLAN_SET_POWER_SAVE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3080 IW_PRIV_TYPE_NONE, "SetPowerSave"},
3081 {KS_WLAN_GET_POWER_SAVE, IW_PRIV_TYPE_NONE,
3082 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPowerSave"},
3083 {KS_WLAN_SET_SCAN_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3084 IW_PRIV_TYPE_NONE, "SetScanType"},
3085 {KS_WLAN_GET_SCAN_TYPE, IW_PRIV_TYPE_NONE,
3086 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetScanType"},
3087 {KS_WLAN_SET_RX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3088 IW_PRIV_TYPE_NONE, "SetRxGain"},
3089 {KS_WLAN_GET_RX_GAIN, IW_PRIV_TYPE_NONE,
3090 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetRxGain"},
3091 {KS_WLAN_HOSTT, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | (128 + 1),
3093 {KS_WLAN_SET_BEACON_LOST, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3094 IW_PRIV_TYPE_NONE, "SetBeaconLost"},
3095 {KS_WLAN_GET_BEACON_LOST, IW_PRIV_TYPE_NONE,
3096 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetBeaconLost"},
3097 {KS_WLAN_SET_SLEEP_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3098 IW_PRIV_TYPE_NONE, "SetSleepMode"},
3099 {KS_WLAN_GET_SLEEP_MODE, IW_PRIV_TYPE_NONE,
3100 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetSleepMode"},
3101 {KS_WLAN_SET_TX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3102 IW_PRIV_TYPE_NONE, "SetTxGain"},
3103 {KS_WLAN_GET_TX_GAIN, IW_PRIV_TYPE_NONE,
3104 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetTxGain"},
3105 {KS_WLAN_SET_PHY_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3106 IW_PRIV_TYPE_NONE, "SetPhyType"},
3107 {KS_WLAN_GET_PHY_TYPE, IW_PRIV_TYPE_NONE,
3108 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPhyType"},
3109 {KS_WLAN_SET_CTS_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3110 IW_PRIV_TYPE_NONE, "SetCtsMode"},
3111 {KS_WLAN_GET_CTS_MODE, IW_PRIV_TYPE_NONE,
3112 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetCtsMode"},
3113 {KS_WLAN_GET_EEPROM_CKSUM, IW_PRIV_TYPE_NONE,
3114 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetChecksum"},
3117 static const iw_handler ks_wlan_handler[] = {
3118 (iw_handler) ks_wlan_config_commit, /* SIOCSIWCOMMIT */
3119 (iw_handler) ks_wlan_get_name, /* SIOCGIWNAME */
3120 (iw_handler) NULL, /* SIOCSIWNWID */
3121 (iw_handler) NULL, /* SIOCGIWNWID */
3122 (iw_handler) ks_wlan_set_freq, /* SIOCSIWFREQ */
3123 (iw_handler) ks_wlan_get_freq, /* SIOCGIWFREQ */
3124 (iw_handler) ks_wlan_set_mode, /* SIOCSIWMODE */
3125 (iw_handler) ks_wlan_get_mode, /* SIOCGIWMODE */
3126 #ifndef KSC_OPNOTSUPP
3127 (iw_handler) ks_wlan_set_sens, /* SIOCSIWSENS */
3128 (iw_handler) ks_wlan_get_sens, /* SIOCGIWSENS */
3129 #else /* KSC_OPNOTSUPP */
3130 (iw_handler) NULL, /* SIOCSIWSENS */
3131 (iw_handler) NULL, /* SIOCGIWSENS */
3132 #endif /* KSC_OPNOTSUPP */
3133 (iw_handler) NULL, /* SIOCSIWRANGE */
3134 (iw_handler) ks_wlan_get_range, /* SIOCGIWRANGE */
3135 (iw_handler) NULL, /* SIOCSIWPRIV */
3136 (iw_handler) NULL, /* SIOCGIWPRIV */
3137 (iw_handler) NULL, /* SIOCSIWSTATS */
3138 (iw_handler) ks_wlan_get_iwstats, /* SIOCGIWSTATS */
3139 (iw_handler) NULL, /* SIOCSIWSPY */
3140 (iw_handler) NULL, /* SIOCGIWSPY */
3141 (iw_handler) NULL, /* SIOCSIWTHRSPY */
3142 (iw_handler) NULL, /* SIOCGIWTHRSPY */
3143 (iw_handler) ks_wlan_set_wap, /* SIOCSIWAP */
3144 (iw_handler) ks_wlan_get_wap, /* SIOCGIWAP */
3145 // (iw_handler) NULL, /* SIOCSIWMLME */
3146 (iw_handler) ks_wlan_set_mlme, /* SIOCSIWMLME */
3147 (iw_handler) ks_wlan_get_aplist, /* SIOCGIWAPLIST */
3148 (iw_handler) ks_wlan_set_scan, /* SIOCSIWSCAN */
3149 (iw_handler) ks_wlan_get_scan, /* SIOCGIWSCAN */
3150 (iw_handler) ks_wlan_set_essid, /* SIOCSIWESSID */
3151 (iw_handler) ks_wlan_get_essid, /* SIOCGIWESSID */
3152 (iw_handler) ks_wlan_set_nick, /* SIOCSIWNICKN */
3153 (iw_handler) ks_wlan_get_nick, /* SIOCGIWNICKN */
3154 (iw_handler) NULL, /* -- hole -- */
3155 (iw_handler) NULL, /* -- hole -- */
3156 (iw_handler) ks_wlan_set_rate, /* SIOCSIWRATE */
3157 (iw_handler) ks_wlan_get_rate, /* SIOCGIWRATE */
3158 (iw_handler) ks_wlan_set_rts, /* SIOCSIWRTS */
3159 (iw_handler) ks_wlan_get_rts, /* SIOCGIWRTS */
3160 (iw_handler) ks_wlan_set_frag, /* SIOCSIWFRAG */
3161 (iw_handler) ks_wlan_get_frag, /* SIOCGIWFRAG */
3162 #ifndef KSC_OPNOTSUPP
3163 (iw_handler) ks_wlan_set_txpow, /* SIOCSIWTXPOW */
3164 (iw_handler) ks_wlan_get_txpow, /* SIOCGIWTXPOW */
3165 (iw_handler) ks_wlan_set_retry, /* SIOCSIWRETRY */
3166 (iw_handler) ks_wlan_get_retry, /* SIOCGIWRETRY */
3167 #else /* KSC_OPNOTSUPP */
3168 (iw_handler) NULL, /* SIOCSIWTXPOW */
3169 (iw_handler) NULL, /* SIOCGIWTXPOW */
3170 (iw_handler) NULL, /* SIOCSIWRETRY */
3171 (iw_handler) NULL, /* SIOCGIWRETRY */
3172 #endif /* KSC_OPNOTSUPP */
3173 (iw_handler) ks_wlan_set_encode, /* SIOCSIWENCODE */
3174 (iw_handler) ks_wlan_get_encode, /* SIOCGIWENCODE */
3175 (iw_handler) ks_wlan_set_power, /* SIOCSIWPOWER */
3176 (iw_handler) ks_wlan_get_power, /* SIOCGIWPOWER */
3177 (iw_handler) NULL, /* -- hole -- */
3178 (iw_handler) NULL, /* -- hole -- */
3179 // (iw_handler) NULL, /* SIOCSIWGENIE */
3180 (iw_handler) ks_wlan_set_genie, /* SIOCSIWGENIE */
3181 (iw_handler) NULL, /* SIOCGIWGENIE */
3182 (iw_handler) ks_wlan_set_auth_mode, /* SIOCSIWAUTH */
3183 (iw_handler) ks_wlan_get_auth_mode, /* SIOCGIWAUTH */
3184 (iw_handler) ks_wlan_set_encode_ext, /* SIOCSIWENCODEEXT */
3185 (iw_handler) ks_wlan_get_encode_ext, /* SIOCGIWENCODEEXT */
3186 (iw_handler) ks_wlan_set_pmksa, /* SIOCSIWPMKSA */
3187 (iw_handler) NULL, /* -- hole -- */
3190 /* private_handler */
3191 static const iw_handler ks_wlan_private_handler[] = {
3192 (iw_handler) NULL, /* 0 */
3193 (iw_handler) NULL, /* 1, used to be: KS_WLAN_GET_DRIVER_VERSION */
3194 (iw_handler) NULL, /* 2 */
3195 (iw_handler) ks_wlan_get_firmware_version, /* 3 KS_WLAN_GET_FIRM_VERSION */
3197 (iw_handler) ks_wlan_set_wps_enable, /* 4 KS_WLAN_SET_WPS_ENABLE */
3198 (iw_handler) ks_wlan_get_wps_enable, /* 5 KS_WLAN_GET_WPS_ENABLE */
3199 (iw_handler) ks_wlan_set_wps_probe_req, /* 6 KS_WLAN_SET_WPS_PROBE_REQ */
3201 (iw_handler) NULL, /* 4 */
3202 (iw_handler) NULL, /* 5 */
3203 (iw_handler) NULL, /* 6 */
3206 (iw_handler) ks_wlan_get_eeprom_cksum, /* 7 KS_WLAN_GET_CONNECT */
3207 (iw_handler) ks_wlan_set_preamble, /* 8 KS_WLAN_SET_PREAMBLE */
3208 (iw_handler) ks_wlan_get_preamble, /* 9 KS_WLAN_GET_PREAMBLE */
3209 (iw_handler) ks_wlan_set_powermgt, /* 10 KS_WLAN_SET_POWER_SAVE */
3210 (iw_handler) ks_wlan_get_powermgt, /* 11 KS_WLAN_GET_POWER_SAVE */
3211 (iw_handler) ks_wlan_set_scan_type, /* 12 KS_WLAN_SET_SCAN_TYPE */
3212 (iw_handler) ks_wlan_get_scan_type, /* 13 KS_WLAN_GET_SCAN_TYPE */
3213 (iw_handler) ks_wlan_set_rx_gain, /* 14 KS_WLAN_SET_RX_GAIN */
3214 (iw_handler) ks_wlan_get_rx_gain, /* 15 KS_WLAN_GET_RX_GAIN */
3215 (iw_handler) ks_wlan_hostt, /* 16 KS_WLAN_HOSTT */
3216 (iw_handler) NULL, /* 17 */
3217 (iw_handler) ks_wlan_set_beacon_lost, /* 18 KS_WLAN_SET_BECAN_LOST */
3218 (iw_handler) ks_wlan_get_beacon_lost, /* 19 KS_WLAN_GET_BECAN_LOST */
3219 (iw_handler) ks_wlan_set_tx_gain, /* 20 KS_WLAN_SET_TX_GAIN */
3220 (iw_handler) ks_wlan_get_tx_gain, /* 21 KS_WLAN_GET_TX_GAIN */
3221 (iw_handler) ks_wlan_set_phy_type, /* 22 KS_WLAN_SET_PHY_TYPE */
3222 (iw_handler) ks_wlan_get_phy_type, /* 23 KS_WLAN_GET_PHY_TYPE */
3223 (iw_handler) ks_wlan_set_cts_mode, /* 24 KS_WLAN_SET_CTS_MODE */
3224 (iw_handler) ks_wlan_get_cts_mode, /* 25 KS_WLAN_GET_CTS_MODE */
3225 (iw_handler) NULL, /* 26 */
3226 (iw_handler) NULL, /* 27 */
3227 (iw_handler) ks_wlan_set_sleep_mode, /* 28 KS_WLAN_SET_SLEEP_MODE */
3228 (iw_handler) ks_wlan_get_sleep_mode, /* 29 KS_WLAN_GET_SLEEP_MODE */
3229 (iw_handler) NULL, /* 30 */
3230 (iw_handler) NULL, /* 31 */
3233 static const struct iw_handler_def ks_wlan_handler_def = {
3234 .num_standard = sizeof(ks_wlan_handler) / sizeof(iw_handler),
3235 .num_private = sizeof(ks_wlan_private_handler) / sizeof(iw_handler),
3237 sizeof(ks_wlan_private_args) / sizeof(struct iw_priv_args),
3238 .standard = (iw_handler *) ks_wlan_handler,
3239 .private = (iw_handler *) ks_wlan_private_handler,
3240 .private_args = (struct iw_priv_args *)ks_wlan_private_args,
3241 .get_wireless_stats = ks_get_wireless_stats,
3244 static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq,
3248 struct iwreq *wrq = (struct iwreq *)rq;
3251 case SIOCIWFIRSTPRIV + 20: /* KS_WLAN_SET_STOP_REQ */
3252 rc = ks_wlan_set_stop_request(dev, NULL, &(wrq->u.mode), NULL);
3254 // All other calls are currently unsupported
3259 DPRINTK(5, "return=%d\n", rc);
3264 struct net_device_stats *ks_wlan_get_stats(struct net_device *dev)
3266 struct ks_wlan_private *priv = netdev_priv(dev);
3268 if (priv->dev_state < DEVICE_STATE_READY)
3269 return NULL; /* not finished initialize */
3271 return &priv->nstats;
3275 int ks_wlan_set_mac_address(struct net_device *dev, void *addr)
3277 struct ks_wlan_private *priv = netdev_priv(dev);
3278 struct sockaddr *mac_addr = (struct sockaddr *)addr;
3280 if (netif_running(dev))
3282 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
3283 memcpy(priv->eth_addr, mac_addr->sa_data, ETH_ALEN);
3285 priv->mac_address_valid = 0;
3286 hostif_sme_enqueue(priv, SME_MACADDRESS_SET_REQUEST);
3287 netdev_info(dev, "ks_wlan: MAC ADDRESS = %pM\n", priv->eth_addr);
3292 void ks_wlan_tx_timeout(struct net_device *dev)
3294 struct ks_wlan_private *priv = netdev_priv(dev);
3296 DPRINTK(1, "head(%d) tail(%d)!!\n", priv->tx_dev.qhead,
3297 priv->tx_dev.qtail);
3298 if (!netif_queue_stopped(dev))
3299 netif_stop_queue(dev);
3300 priv->nstats.tx_errors++;
3301 netif_wake_queue(dev);
3305 int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev)
3307 struct ks_wlan_private *priv = netdev_priv(dev);
3310 DPRINTK(3, "in_interrupt()=%ld\n", in_interrupt());
3313 netdev_err(dev, "ks_wlan: skb == NULL!!!\n");
3316 if (priv->dev_state < DEVICE_STATE_READY) {
3318 return 0; /* not finished initialize */
3321 if (netif_running(dev))
3322 netif_stop_queue(dev);
3324 rc = hostif_data_request(priv, skb);
3325 netif_trans_update(dev);
3327 DPRINTK(4, "rc=%d\n", rc);
3334 void send_packet_complete(void *arg1, void *arg2)
3336 struct ks_wlan_private *priv = (struct ks_wlan_private *)arg1;
3337 struct sk_buff *packet = (struct sk_buff *)arg2;
3341 priv->nstats.tx_packets++;
3343 if (netif_queue_stopped(priv->net_dev))
3344 netif_wake_queue(priv->net_dev);
3347 priv->nstats.tx_bytes += packet->len;
3348 dev_kfree_skb(packet);
3353 /* Set or clear the multicast filter for this adaptor.
3354 This routine is not state sensitive and need not be SMP locked. */
3356 void ks_wlan_set_multicast_list(struct net_device *dev)
3358 struct ks_wlan_private *priv = netdev_priv(dev);
3361 if (priv->dev_state < DEVICE_STATE_READY)
3362 return; /* not finished initialize */
3363 hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST);
3367 int ks_wlan_open(struct net_device *dev)
3369 struct ks_wlan_private *priv = netdev_priv(dev);
3373 if (!priv->mac_address_valid) {
3374 netdev_err(dev, "ks_wlan : %s Not READY !!\n", dev->name);
3377 netif_start_queue(dev);
3383 int ks_wlan_close(struct net_device *dev)
3385 netif_stop_queue(dev);
3387 DPRINTK(4, "%s: Shutting down ethercard, status was 0x%4.4x.\n",
3393 /* Operational parameters that usually are not changed. */
3394 /* Time in jiffies before concluding the transmitter is hung. */
3395 #define TX_TIMEOUT (3 * HZ)
3396 static const unsigned char dummy_addr[] = {
3397 0x00, 0x0b, 0xe3, 0x00, 0x00, 0x00
3400 static const struct net_device_ops ks_wlan_netdev_ops = {
3401 .ndo_start_xmit = ks_wlan_start_xmit,
3402 .ndo_open = ks_wlan_open,
3403 .ndo_stop = ks_wlan_close,
3404 .ndo_do_ioctl = ks_wlan_netdev_ioctl,
3405 .ndo_set_mac_address = ks_wlan_set_mac_address,
3406 .ndo_get_stats = ks_wlan_get_stats,
3407 .ndo_tx_timeout = ks_wlan_tx_timeout,
3408 .ndo_set_rx_mode = ks_wlan_set_multicast_list,
3411 int ks_wlan_net_start(struct net_device *dev)
3413 struct ks_wlan_private *priv;
3416 priv = netdev_priv(dev);
3417 priv->mac_address_valid = 0;
3418 priv->need_commit = 0;
3420 priv->device_open_status = 1;
3422 /* phy information update timer */
3423 atomic_set(&update_phyinfo, 0);
3424 setup_timer(&update_phyinfo_timer, ks_wlan_update_phyinfo_timeout,
3425 (unsigned long)priv);
3427 /* dummy address set */
3428 memcpy(priv->eth_addr, dummy_addr, ETH_ALEN);
3429 dev->dev_addr[0] = priv->eth_addr[0];
3430 dev->dev_addr[1] = priv->eth_addr[1];
3431 dev->dev_addr[2] = priv->eth_addr[2];
3432 dev->dev_addr[3] = priv->eth_addr[3];
3433 dev->dev_addr[4] = priv->eth_addr[4];
3434 dev->dev_addr[5] = priv->eth_addr[5];
3435 dev->dev_addr[6] = 0x00;
3436 dev->dev_addr[7] = 0x00;
3438 /* The ks_wlan-specific entries in the device structure. */
3439 dev->netdev_ops = &ks_wlan_netdev_ops;
3440 dev->wireless_handlers = (struct iw_handler_def *)&ks_wlan_handler_def;
3441 dev->watchdog_timeo = TX_TIMEOUT;
3443 netif_carrier_off(dev);
3448 int ks_wlan_net_stop(struct net_device *dev)
3450 struct ks_wlan_private *priv = netdev_priv(dev);
3452 priv->device_open_status = 0;
3453 del_timer_sync(&update_phyinfo_timer);
3455 if (netif_running(dev))
3456 netif_stop_queue(dev);