2 * Driver for KeyStream 11b/g wireless LAN
5 * $Id: ks_wlan_net.c 1020 2009-09-28 05:48:31Z sekine $
7 * Copyright (C) 2005-2008 KeyStream Corp.
8 * Copyright (C) 2009 Renesas Technology Corp.
10 * This program is free software; you can redistribute it and/or modify
11 * it undr the terms of the GNU General Public License version 2 as
12 * published by the Free Sotware Foundation.
15 #include <linux/version.h>
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/compiler.h>
19 #include <linux/init.h>
20 #include <linux/ioport.h>
21 #include <linux/netdevice.h>
22 #include <linux/etherdevice.h>
23 #include <linux/if_arp.h>
24 #include <linux/rtnetlink.h>
25 #include <linux/delay.h>
26 #include <linux/completion.h>
27 #include <linux/mii.h>
28 #include <linux/pci.h>
29 #include <linux/ctype.h>
30 #include <linux/timer.h>
31 #include <asm/atomic.h>
33 #include <asm/uaccess.h>
35 static int wep_on_off;
37 #define WEP_ON_64BIT 1
38 #define WEP_ON_128BIT 2
41 #include "ks_hostif.h"
42 #include "ks_wlan_ioctl.h"
45 /* Include Wireless Extension definition and check version */
46 #include <linux/wireless.h>
47 #define WIRELESS_SPY /* enable iwspy support */
48 #include <net/iw_handler.h> /* New driver API */
50 /* Frequency list (map channels to frequencies) */
51 static const long frequency_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
52 2447, 2452, 2457, 2462, 2467, 2472, 2484 };
54 /* A few details needed for WEP (Wireless Equivalent Privacy) */
55 #define MAX_KEY_SIZE 13 /* 128 (?) bits */
56 #define MIN_KEY_SIZE 5 /* 40 bits RC4 - WEP */
57 typedef struct wep_key_t {
59 u8 key[16]; /* 40-bit and 104-bit keys */
62 /* Backward compatibility */
63 #ifndef IW_ENCODE_NOKEY
64 #define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not present */
65 #define IW_ENCODE_MODE (IW_ENCODE_DISABLED | IW_ENCODE_RESTRICTED | IW_ENCODE_OPEN)
66 #endif /* IW_ENCODE_NOKEY */
68 /* List of Wireless Handlers (new API) */
69 static const struct iw_handler_def ks_wlan_handler_def;
71 #define KSC_OPNOTSUPP /* Operation Not Support*/
77 extern int ks_wlan_hw_tx(ks_wlan_private *priv, void *p, unsigned long size,
78 void (*complete_handler)(void *arg1, void *arg2),
81 static int ks_wlan_open (struct net_device *dev);
82 static void ks_wlan_tx_timeout (struct net_device *dev);
83 static int ks_wlan_start_xmit (struct sk_buff *skb, struct net_device *dev);
84 static int ks_wlan_close (struct net_device *dev);
85 static void ks_wlan_set_multicast_list (struct net_device *dev);
86 static struct net_device_stats *ks_wlan_get_stats (struct net_device *dev);
87 static int ks_wlan_set_mac_address(struct net_device *dev, void *addr);
88 static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
90 static atomic_t update_phyinfo;
91 static struct timer_list update_phyinfo_timer;
93 int ks_wlan_update_phy_information(ks_wlan_private *priv)
95 struct iw_statistics *wstats = &priv->wstats;
97 DPRINTK(4, "in_interrupt = %ld\n", in_interrupt());
99 if (priv->dev_state < DEVICE_STATE_READY) {
100 return -1; /* not finished initialize */
102 if(atomic_read(&update_phyinfo))
106 wstats->status = priv->reg.operation_mode; /* Operation mode */
108 /* Signal quality and co. But where is the noise level ??? */
109 hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST);
111 /* interruptible_sleep_on_timeout(&priv->confirm_wait, HZ/2); */
112 if(!wait_for_completion_interruptible_timeout(&priv->confirm_wait,HZ/2)){
113 DPRINTK(1,"wait time out!!\n");
116 atomic_inc(&update_phyinfo);
117 update_phyinfo_timer.expires = jiffies + HZ; /* 1sec */
118 add_timer(&update_phyinfo_timer);
124 void ks_wlan_update_phyinfo_timeout(unsigned long ptr)
126 DPRINTK(4, "in_interrupt = %ld\n", in_interrupt());
127 atomic_set(&update_phyinfo,0);
130 int ks_wlan_setup_parameter(ks_wlan_private *priv, unsigned int commit_flag)
134 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
136 if(commit_flag & SME_RTS)
137 hostif_sme_enqueue(priv, SME_RTS_THRESHOLD_REQUEST);
138 if(commit_flag & SME_FRAG)
139 hostif_sme_enqueue(priv, SME_FRAGMENTATION_THRESHOLD_REQUEST);
141 if(commit_flag & SME_WEP_INDEX)
142 hostif_sme_enqueue(priv, SME_WEP_INDEX_REQUEST);
143 if(commit_flag & SME_WEP_VAL1)
144 hostif_sme_enqueue(priv, SME_WEP_KEY1_REQUEST);
145 if(commit_flag & SME_WEP_VAL2)
146 hostif_sme_enqueue(priv, SME_WEP_KEY2_REQUEST);
147 if(commit_flag & SME_WEP_VAL3)
148 hostif_sme_enqueue(priv, SME_WEP_KEY3_REQUEST);
149 if(commit_flag & SME_WEP_VAL4)
150 hostif_sme_enqueue(priv, SME_WEP_KEY4_REQUEST);
151 if(commit_flag & SME_WEP_FLAG)
152 hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
154 if(commit_flag & SME_RSN){
155 hostif_sme_enqueue(priv, SME_RSN_ENABLED_REQUEST);
156 hostif_sme_enqueue(priv, SME_RSN_MODE_REQUEST);
158 if(commit_flag & SME_RSN_MULTICAST)
159 hostif_sme_enqueue(priv, SME_RSN_MCAST_REQUEST);
160 if(commit_flag & SME_RSN_UNICAST)
161 hostif_sme_enqueue(priv, SME_RSN_UCAST_REQUEST);
162 if(commit_flag & SME_RSN_AUTH)
163 hostif_sme_enqueue(priv, SME_RSN_AUTH_REQUEST);
165 hostif_sme_enqueue(priv, SME_MODE_SET_REQUEST);
167 hostif_sme_enqueue(priv, SME_START_REQUEST);
173 * Initial Wireless Extension code for Ks_Wlannet driver by :
174 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00
175 * Conversion to new driver API by :
176 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 26 March 02
177 * Javier also did a good amount of work here, adding some new extensions
178 * and fixing my code. Let's just say that without him this code just
179 * would not work at all... - Jean II
182 /*------------------------------------------------------------------*/
183 /* Wireless Handler : get protocol name */
184 static int ks_wlan_get_name(struct net_device *dev, struct iw_request_info *info,
185 char *cwrq, char *extra)
187 ks_wlan_private *priv = (ks_wlan_private *) netdev_priv(dev);
189 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
191 if (priv->dev_state < DEVICE_STATE_READY) {
192 strcpy(cwrq, "NOT READY!");
194 else if(priv->reg.phy_type == D_11B_ONLY_MODE){
195 strcpy(cwrq, "IEEE 802.11b");
197 else if(priv->reg.phy_type == D_11G_ONLY_MODE){
198 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, struct iw_request_info *info,
210 struct iw_freq *fwrq, char *extra)
212 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
213 int rc = -EINPROGRESS; /* Call commit handler */
215 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
217 /* If setting by frequency, convert to a channel */
219 (fwrq->m >= (int) 2.412e8) &&
220 (fwrq->m <= (int) 2.487e8)) {
221 int f = fwrq->m / 100000;
223 while((c < 14) && (f != frequency_list[c]))
225 /* Hack to fall through... */
229 /* Setting by channel number */
230 if((fwrq->m > 1000) || (fwrq->e > 0))
233 int channel = fwrq->m;
234 /* We should do a better check than that,
235 * based on the card capability !!! */
236 if((channel < 1) || (channel > 14)) {
237 printk(KERN_DEBUG "%s: New channel value of %d is invalid!\n", dev->name, fwrq->m);
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, struct iw_request_info *info,
252 struct iw_freq *fwrq, char *extra)
254 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
257 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
259 if((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS){
260 f = (int)priv->current_ap.channel;
263 f = (int)priv->reg.channel;
264 fwrq->m = frequency_list[f-1] * 100000;
270 /*------------------------------------------------------------------*/
271 /* Wireless Handler : set ESSID */
272 static int ks_wlan_set_essid(struct net_device *dev, struct iw_request_info *info,
273 struct iw_point *dwrq, char *extra)
275 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
278 DPRINTK(2," %d\n", dwrq->flags);
280 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
282 /* Check if we asked for `any' */
283 if(dwrq->flags == 0) {
284 /* Just send an empty SSID list */
285 memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
286 priv->reg.ssid.size = 0;
290 /* iwconfig uses nul termination in SSID.. */
291 if (len > 0 && extra[len - 1] == '\0')
294 /* Check the size of the string */
295 if(len > IW_ESSID_MAX_SIZE) {
299 /* Check the size of the string */
300 if(dwrq->length > IW_ESSID_MAX_SIZE+1) {
306 memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
309 memcpy(priv->reg.ssid.body, extra, len);
310 priv->reg.ssid.size = len;
312 memcpy(priv->reg.ssid.body, extra, dwrq->length);
313 priv->reg.ssid.size = dwrq->length;
316 /* Write it to the card */
317 priv->need_commit |= SME_MODE_SET;
319 // return -EINPROGRESS; /* Call commit handler */
320 ks_wlan_setup_parameter(priv, priv->need_commit);
325 /*------------------------------------------------------------------*/
326 /* Wireless Handler : get ESSID */
327 static int ks_wlan_get_essid(struct net_device *dev, struct iw_request_info *info,
328 struct iw_point *dwrq, char *extra)
330 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
332 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
334 /* Note : if dwrq->flags != 0, we should
335 * get the relevant SSID from the SSID list... */
337 if(priv->reg.ssid.size){
338 /* Get the current SSID */
339 memcpy(extra, priv->reg.ssid.body, priv->reg.ssid.size);
341 extra[priv->reg.ssid.size] = '\0';
343 /* If none, we may want to get the one that was set */
347 dwrq->length = priv->reg.ssid.size;
349 dwrq->length = priv->reg.ssid.size+1;
351 dwrq->flags = 1; /* active */
359 dwrq->flags = 0; /* ANY */
365 /*------------------------------------------------------------------*/
366 /* Wireless Handler : set AP address */
367 static int ks_wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
368 struct sockaddr *ap_addr, char *extra)
370 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
374 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
376 if (priv->reg.operation_mode == MODE_ADHOC ||
377 priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
378 memcpy(priv->reg.bssid, (u8 *)&ap_addr->sa_data, ETH_ALEN);
380 if (is_valid_ether_addr((u8 *)priv->reg.bssid)) {
381 priv->need_commit |= SME_MODE_SET;
385 memset(priv->reg.bssid, 0x0, ETH_ALEN);
389 DPRINTK(2, "bssid = %02x:%02x:%02x:%02x:%02x:%02x\n",
390 priv->reg.bssid[0],priv->reg.bssid[1],priv->reg.bssid[2],
391 priv->reg.bssid[3],priv->reg.bssid[4],priv->reg.bssid[5]);
393 /* Write it to the card */
394 if (priv->need_commit) {
395 priv->need_commit |= SME_MODE_SET;
396 return -EINPROGRESS; /* Call commit handler */
401 /*------------------------------------------------------------------*/
402 /* Wireless Handler : get AP address */
403 static int ks_wlan_get_wap(struct net_device *dev, struct iw_request_info *info,
404 struct sockaddr *awrq, char *extra)
406 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
408 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
410 if((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS){
411 memcpy(awrq->sa_data, &(priv->current_ap.bssid[0]), ETH_ALEN);
414 memset(awrq->sa_data, 0, ETH_ALEN);
417 awrq->sa_family = ARPHRD_ETHER;
422 /*------------------------------------------------------------------*/
423 /* Wireless Handler : set Nickname */
424 static int ks_wlan_set_nick(struct net_device *dev, struct iw_request_info *info,
425 struct iw_point *dwrq, char *extra)
427 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
429 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
431 /* Check the size of the string */
432 if(dwrq->length > 16 + 1) {
435 memset(priv->nick, 0, sizeof(priv->nick));
436 memcpy(priv->nick, extra, dwrq->length);
438 return -EINPROGRESS; /* Call commit handler */
441 /*------------------------------------------------------------------*/
442 /* Wireless Handler : get Nickname */
443 static int ks_wlan_get_nick(struct net_device *dev, struct iw_request_info *info,
444 struct iw_point *dwrq, char *extra)
446 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
448 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
450 strncpy(extra, priv->nick, 16);
452 dwrq->length = strlen(extra) + 1;
457 /*------------------------------------------------------------------*/
458 /* Wireless Handler : set Bit-Rate */
459 static int ks_wlan_set_rate(struct net_device *dev, struct iw_request_info *info,
460 struct iw_param *vwrq, char *extra)
462 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
465 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
467 if(priv->reg.phy_type == D_11B_ONLY_MODE){
468 if(vwrq->fixed == 1) {
472 priv->reg.rate_set.body[0] = (uint8_t)(vwrq->value/500000);
476 priv->reg.rate_set.body[0] = ((uint8_t)(vwrq->value/500000))|BASIC_RATE;
481 priv->reg.tx_rate = TX_RATE_FIXED;
482 priv->reg.rate_set.size = 1;
483 }else{ /* vwrq->fixed == 0 */
487 priv->reg.rate_set.body[3] = TX_RATE_11M; i++;
489 priv->reg.rate_set.body[2] = TX_RATE_5M; i++;
491 priv->reg.rate_set.body[1] = TX_RATE_2M|BASIC_RATE; i++;
493 priv->reg.rate_set.body[0] = TX_RATE_1M|BASIC_RATE; i++;
498 priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
499 priv->reg.rate_set.size = i;
501 priv->reg.rate_set.body[3] = TX_RATE_11M;
502 priv->reg.rate_set.body[2] = TX_RATE_5M;
503 priv->reg.rate_set.body[1] = TX_RATE_2M|BASIC_RATE;
504 priv->reg.rate_set.body[0] = TX_RATE_1M|BASIC_RATE;
505 priv->reg.tx_rate = TX_RATE_FULL_AUTO;
506 priv->reg.rate_set.size = 4;
509 }else{ /* D_11B_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
510 if(vwrq->fixed == 1) {
517 priv->reg.rate_set.body[0] = (uint8_t)(vwrq->value/500000);
526 priv->reg.rate_set.body[0] = ((uint8_t)(vwrq->value/500000))|BASIC_RATE;
531 priv->reg.tx_rate = TX_RATE_FIXED;
532 priv->reg.rate_set.size = 1;
533 }else{ /* vwrq->fixed == 0 */
537 priv->reg.rate_set.body[11] = TX_RATE_54M; i++;
539 priv->reg.rate_set.body[10] = TX_RATE_48M; i++;
541 priv->reg.rate_set.body[9] = TX_RATE_36M; i++;
542 case 24000000: case 18000000: case 12000000:
543 case 11000000: case 9000000: case 6000000:
544 if(vwrq->value == 24000000){
545 priv->reg.rate_set.body[8] = TX_RATE_18M; i++;
546 priv->reg.rate_set.body[7] = TX_RATE_9M; i++;
547 priv->reg.rate_set.body[6] = TX_RATE_24M|BASIC_RATE; i++;
548 priv->reg.rate_set.body[5] = TX_RATE_12M|BASIC_RATE; i++;
549 priv->reg.rate_set.body[4] = TX_RATE_6M|BASIC_RATE; i++;
550 priv->reg.rate_set.body[3] = TX_RATE_11M|BASIC_RATE; i++;
551 }else if(vwrq->value == 18000000){
552 priv->reg.rate_set.body[7] = TX_RATE_18M; i++;
553 priv->reg.rate_set.body[6] = TX_RATE_9M; i++;
554 priv->reg.rate_set.body[5] = TX_RATE_12M|BASIC_RATE; i++;
555 priv->reg.rate_set.body[4] = TX_RATE_6M|BASIC_RATE; i++;
556 priv->reg.rate_set.body[3] = TX_RATE_11M|BASIC_RATE; i++;
557 }else if(vwrq->value == 12000000){
558 priv->reg.rate_set.body[6] = TX_RATE_9M; i++;
559 priv->reg.rate_set.body[5] = TX_RATE_12M|BASIC_RATE; i++;
560 priv->reg.rate_set.body[4] = TX_RATE_6M|BASIC_RATE; i++;
561 priv->reg.rate_set.body[3] = TX_RATE_11M|BASIC_RATE; i++;
562 }else if(vwrq->value == 11000000){
563 priv->reg.rate_set.body[5] = TX_RATE_9M; i++;
564 priv->reg.rate_set.body[4] = TX_RATE_6M|BASIC_RATE; i++;
565 priv->reg.rate_set.body[3] = TX_RATE_11M|BASIC_RATE; i++;
566 }else if(vwrq->value == 9000000){
567 priv->reg.rate_set.body[4] = TX_RATE_9M; i++;
568 priv->reg.rate_set.body[3] = TX_RATE_6M|BASIC_RATE; i++;
569 }else{ /* vwrq->value == 6000000 */
570 priv->reg.rate_set.body[3] = TX_RATE_6M|BASIC_RATE; i++;
573 priv->reg.rate_set.body[2] = TX_RATE_5M|BASIC_RATE; i++;
575 priv->reg.rate_set.body[1] = TX_RATE_2M|BASIC_RATE; i++;
577 priv->reg.rate_set.body[0] = TX_RATE_1M|BASIC_RATE; i++;
582 priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
583 priv->reg.rate_set.size = i;
585 priv->reg.rate_set.body[11] = TX_RATE_54M;
586 priv->reg.rate_set.body[10] = TX_RATE_48M;
587 priv->reg.rate_set.body[9] = TX_RATE_36M;
588 priv->reg.rate_set.body[8] = TX_RATE_18M;
589 priv->reg.rate_set.body[7] = TX_RATE_9M;
590 priv->reg.rate_set.body[6] = TX_RATE_24M|BASIC_RATE;
591 priv->reg.rate_set.body[5] = TX_RATE_12M|BASIC_RATE;
592 priv->reg.rate_set.body[4] = TX_RATE_6M|BASIC_RATE;
593 priv->reg.rate_set.body[3] = TX_RATE_11M|BASIC_RATE;
594 priv->reg.rate_set.body[2] = TX_RATE_5M|BASIC_RATE;
595 priv->reg.rate_set.body[1] = TX_RATE_2M|BASIC_RATE;
596 priv->reg.rate_set.body[0] = TX_RATE_1M|BASIC_RATE;
597 priv->reg.tx_rate = TX_RATE_FULL_AUTO;
598 priv->reg.rate_set.size = 12;
603 priv->need_commit |= SME_MODE_SET;
605 return -EINPROGRESS; /* Call commit handler */
608 /*------------------------------------------------------------------*/
609 /* Wireless Handler : get Bit-Rate */
610 static int ks_wlan_get_rate(struct net_device *dev, struct iw_request_info *info,
611 struct iw_param *vwrq, char *extra)
613 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
615 DPRINTK(2, "in_interrupt = %ld update_phyinfo = %d\n",
616 in_interrupt(),atomic_read(&update_phyinfo));
618 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
620 if(!atomic_read(&update_phyinfo)){
621 ks_wlan_update_phy_information(priv);
623 vwrq->value = ((priv->current_rate) & RATE_MASK) * 500000;
624 if(priv->reg.tx_rate == TX_RATE_FIXED)
632 /*------------------------------------------------------------------*/
633 /* Wireless Handler : set RTS threshold */
634 static int ks_wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
635 struct iw_param *vwrq, char *extra)
637 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
638 int rthr = vwrq->value;
640 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
644 if((rthr < 0) || (rthr > 2347)) {
647 priv->reg.rts = rthr;
648 priv->need_commit |= SME_RTS;
650 return -EINPROGRESS; /* Call commit handler */
653 /*------------------------------------------------------------------*/
654 /* Wireless Handler : get RTS threshold */
655 static int ks_wlan_get_rts(struct net_device *dev, struct iw_request_info *info,
656 struct iw_param *vwrq, char *extra)
658 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
660 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
662 vwrq->value = priv->reg.rts;
663 vwrq->disabled = (vwrq->value >= 2347);
669 /*------------------------------------------------------------------*/
670 /* Wireless Handler : set Fragmentation threshold */
671 static int ks_wlan_set_frag(struct net_device *dev, struct iw_request_info *info,
672 struct iw_param *vwrq, char *extra)
674 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
675 int fthr = vwrq->value;
677 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
681 if((fthr < 256) || (fthr > 2346)) {
684 fthr &= ~0x1; /* Get an even value - is it really needed ??? */
685 priv->reg.fragment = fthr;
686 priv->need_commit |= SME_FRAG;
688 return -EINPROGRESS; /* Call commit handler */
691 /*------------------------------------------------------------------*/
692 /* Wireless Handler : get Fragmentation threshold */
693 static int ks_wlan_get_frag(struct net_device *dev, struct iw_request_info *info,
694 struct iw_param *vwrq, char *extra)
696 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
698 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
700 vwrq->value = priv->reg.fragment;
701 vwrq->disabled = (vwrq->value >= 2346);
707 /*------------------------------------------------------------------*/
708 /* Wireless Handler : set Mode of Operation */
709 static int ks_wlan_set_mode(struct net_device *dev, struct iw_request_info *info,
710 __u32 *uwrq, char *extra)
712 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
714 DPRINTK(2,"mode=%d\n",*uwrq);
716 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
720 priv->reg.operation_mode = MODE_ADHOC;
721 priv->need_commit |= SME_MODE_SET;
724 priv->reg.operation_mode = MODE_INFRASTRUCTURE;
725 priv->need_commit |= SME_MODE_SET;
731 case IW_MODE_MONITOR:
736 return -EINPROGRESS; /* Call commit handler */
739 /*------------------------------------------------------------------*/
740 /* Wireless Handler : get Mode of Operation */
741 static int ks_wlan_get_mode(struct net_device *dev, struct iw_request_info *info,
742 __u32 *uwrq, char *extra)
744 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
746 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
748 /* If not managed, assume it's ad-hoc */
749 switch (priv->reg.operation_mode) {
750 case MODE_INFRASTRUCTURE:
751 *uwrq = IW_MODE_INFRA;
754 *uwrq = IW_MODE_ADHOC;
757 *uwrq = IW_MODE_ADHOC;
763 /*------------------------------------------------------------------*/
764 /* Wireless Handler : set Encryption Key */
765 static int ks_wlan_set_encode(struct net_device *dev, struct iw_request_info *info,
766 struct iw_point *dwrq, char *extra)
768 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
771 int index = (dwrq->flags & IW_ENCODE_INDEX);
772 int current_index = priv->reg.wep_index;
775 DPRINTK(2,"flags=%04X\n",dwrq->flags);
777 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
780 if((index<0) || (index>4))
783 index = current_index;
787 /* Is WEP supported ? */
788 /* Basic checking: do we have a key to set ? */
789 if (dwrq->length > 0) {
790 if (dwrq->length > MAX_KEY_SIZE) { /* Check the size of the key */
793 if (dwrq->length > MIN_KEY_SIZE) { /* Set the length */
794 key.len = MAX_KEY_SIZE;
795 priv->reg.privacy_invoked = 0x01;
796 priv->need_commit |= SME_WEP_FLAG;
797 wep_on_off = WEP_ON_128BIT;
799 if (dwrq->length > 0) {
800 key.len = MIN_KEY_SIZE;
801 priv->reg.privacy_invoked = 0x01;
802 priv->need_commit |= SME_WEP_FLAG;
803 wep_on_off = WEP_ON_64BIT;
804 } else { /* Disable the key */
808 /* Check if the key is not marked as invalid */
809 if(!(dwrq->flags & IW_ENCODE_NOKEY)) {
811 memset(key.key, 0, MAX_KEY_SIZE);
812 /* Copy the key in the driver */
813 if(copy_from_user(key.key,dwrq->pointer,dwrq->length)) {
817 /* Send the key to the card */
818 priv->reg.wep_key[index].size = key.len;
819 for (i=0; i<(priv->reg.wep_key[index].size); i++) {
820 priv->reg.wep_key[index].val[i] = key.key[i];
822 priv->need_commit |= (SME_WEP_VAL1<<index);
823 priv->reg.wep_index = index;
824 priv->need_commit |= SME_WEP_INDEX;
827 if(dwrq->flags & IW_ENCODE_DISABLED){
828 priv->reg.wep_key[0].size = 0;
829 priv->reg.wep_key[1].size = 0;
830 priv->reg.wep_key[2].size = 0;
831 priv->reg.wep_key[3].size = 0;
832 priv->reg.privacy_invoked = 0x00;
833 if(priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY){
834 priv->need_commit |= SME_MODE_SET;
836 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
837 wep_on_off = WEP_OFF;
838 priv->need_commit |= SME_WEP_FLAG;
840 /* Do we want to just set the transmit key index ? */
841 if ((index>=0) && (index<4)) {
842 /* set_wep_key(priv, index, 0, 0, 1); xxx */
843 if(priv->reg.wep_key[index].size){
844 priv->reg.wep_index = index;
845 priv->need_commit |= SME_WEP_INDEX;
853 /* Commit the changes if needed */
854 if(dwrq->flags & IW_ENCODE_MODE)
855 priv->need_commit |= SME_WEP_FLAG;
857 if(dwrq->flags & IW_ENCODE_OPEN) {
858 if(priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY){
859 priv->need_commit |= SME_MODE_SET;
861 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
862 } else if(dwrq->flags & IW_ENCODE_RESTRICTED) {
863 if(priv->reg.authenticate_type == AUTH_TYPE_OPEN_SYSTEM){
864 priv->need_commit |= SME_MODE_SET;
866 priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
869 // return -EINPROGRESS; /* Call commit handler */
870 if(priv->need_commit){
871 ks_wlan_setup_parameter(priv, priv->need_commit);
877 /*------------------------------------------------------------------*/
878 /* Wireless Handler : get Encryption Key */
879 static int ks_wlan_get_encode(struct net_device *dev, struct iw_request_info *info,
880 struct iw_point *dwrq, char *extra)
882 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
884 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
886 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
888 dwrq->flags = IW_ENCODE_DISABLED;
890 /* Check encryption mode */
891 switch(priv->reg.authenticate_type) {
892 case AUTH_TYPE_OPEN_SYSTEM:
893 dwrq->flags = IW_ENCODE_OPEN;
895 case AUTH_TYPE_SHARED_KEY:
896 dwrq->flags = IW_ENCODE_RESTRICTED;
900 memset(zeros,0, sizeof(zeros));
902 /* Which key do we want ? -1 -> tx index */
903 if((index < 0) || (index >= 4))
904 index = priv->reg.wep_index;
905 if (priv->reg.privacy_invoked){
906 dwrq->flags &= ~IW_ENCODE_DISABLED;
907 /* dwrq->flags |= IW_ENCODE_NOKEY; */
909 dwrq->flags |= index + 1;
910 DPRINTK(2,"encoding flag = 0x%04X\n",dwrq->flags);
911 /* Copy the key to the user buffer */
912 if((index >= 0) && (index < 4))
913 dwrq->length = priv->reg.wep_key[index].size;
914 if (dwrq->length > 16) {
917 #if 1 /* IW_ENCODE_NOKEY; */
919 if((index >= 0) && (index < 4))
920 memcpy(extra,priv->reg.wep_key[index].val,dwrq->length);
922 memcpy(extra,zeros,dwrq->length);
927 #ifndef KSC_OPNOTSUPP
928 /*------------------------------------------------------------------*/
929 /* Wireless Handler : set Tx-Power */
930 static int ks_wlan_set_txpow(struct net_device *dev, struct iw_request_info *info,
931 struct iw_param *vwrq, char *extra)
933 return -EOPNOTSUPP; /* Not Support */
936 /*------------------------------------------------------------------*/
937 /* Wireless Handler : get Tx-Power */
938 static int ks_wlan_get_txpow(struct net_device *dev, struct iw_request_info *info,
939 struct iw_param *vwrq, char *extra)
941 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
945 vwrq->disabled = (vwrq->value == 0);
950 /*------------------------------------------------------------------*/
951 /* Wireless Handler : set Retry limits */
952 static int ks_wlan_set_retry(struct net_device *dev, struct iw_request_info *info,
953 struct iw_param *vwrq, char *extra)
955 return -EOPNOTSUPP; /* Not Support */
958 /*------------------------------------------------------------------*/
959 /* Wireless Handler : get Retry limits */
960 static int ks_wlan_get_retry(struct net_device *dev, struct iw_request_info *info,
961 struct iw_param *vwrq, char *extra)
963 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
967 vwrq->disabled = (vwrq->value == 0);
971 #endif /* KSC_OPNOTSUPP */
973 /*------------------------------------------------------------------*/
974 /* Wireless Handler : get range info */
975 static int ks_wlan_get_range(struct net_device *dev, struct iw_request_info *info,
976 struct iw_point *dwrq, char *extra)
978 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
979 struct iw_range *range = (struct iw_range *) extra;
984 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
986 dwrq->length = sizeof(struct iw_range);
987 memset(range, 0, sizeof(*range));
988 range->min_nwid = 0x0000;
989 range->max_nwid = 0x0000;
990 range->num_channels = 14;
991 /* Should be based on cap_rid.country to give only
992 * what the current card support */
994 for(i = 0; i < 13; i++) { /* channel 1 -- 13*/
995 range->freq[k].i = i + 1; /* List index */
996 range->freq[k].m = frequency_list[i] * 100000;
997 range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
999 range->num_frequency = k;
1000 if(priv->reg.phy_type == D_11B_ONLY_MODE ||
1001 priv->reg.phy_type == D_11BG_COMPATIBLE_MODE){ /* channel 14 */
1002 range->freq[13].i = 14; /* List index */
1003 range->freq[13].m = frequency_list[13] * 100000;
1004 range->freq[13].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
1005 range->num_frequency = 14;
1008 /* Hum... Should put the right values there */
1009 range->max_qual.qual = 100;
1010 range->max_qual.level = 256 - 128; /* 0 dBm? */
1011 range->max_qual.noise = 256 - 128;
1012 range->sensitivity = 1;
1014 if(priv->reg.phy_type == D_11B_ONLY_MODE){
1015 range->bitrate[0] = 1e6;
1016 range->bitrate[1] = 2e6;
1017 range->bitrate[2] = 5.5e6;
1018 range->bitrate[3] = 11e6;
1019 range->num_bitrates = 4;
1021 else{ /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
1022 range->bitrate[0] = 1e6;
1023 range->bitrate[1] = 2e6;
1024 range->bitrate[2] = 5.5e6;
1025 range->bitrate[3] = 11e6;
1027 range->bitrate[4] = 6e6;
1028 range->bitrate[5] = 9e6;
1029 range->bitrate[6] = 12e6;
1030 if(IW_MAX_BITRATES < 9){
1031 range->bitrate[7] = 54e6;
1032 range->num_bitrates = 8;
1034 range->bitrate[7] = 18e6;
1035 range->bitrate[8] = 24e6;
1036 range->bitrate[9] = 36e6;
1037 range->bitrate[10] = 48e6;
1038 range->bitrate[11] = 54e6;
1040 range->num_bitrates = 12;
1044 /* Set an indication of the max TCP throughput
1045 * in bit/s that we can expect using this interface.
1046 * May be use for QoS stuff... Jean II */
1048 range->throughput = 5000 * 1000;
1050 range->throughput = 1500 * 1000;
1053 range->max_rts = 2347;
1054 range->min_frag = 256;
1055 range->max_frag = 2346;
1057 range->encoding_size[0] = 5; /* WEP: RC4 40 bits */
1058 range->encoding_size[1] = 13; /* WEP: RC4 ~128 bits */
1059 range->num_encoding_sizes = 2;
1060 range->max_encoding_tokens = 4;
1062 /* power management not support */
1063 range->pmp_flags = IW_POWER_ON;
1064 range->pmt_flags = IW_POWER_ON;
1067 /* Transmit Power - values are in dBm( or mW) */
1068 range->txpower[0]=-256;
1069 range->num_txpower = 1;
1070 range->txpower_capa = IW_TXPOW_DBM;
1071 /* range->txpower_capa = IW_TXPOW_MWATT; */
1073 range->we_version_source = 21;
1074 range->we_version_compiled = WIRELESS_EXT;
1076 range->retry_capa = IW_RETRY_ON;
1077 range->retry_flags = IW_RETRY_ON;
1078 range->r_time_flags = IW_RETRY_ON;
1080 /* Experimental measurements - boundary 11/5.5 Mb/s */
1081 /* Note : with or without the (local->rssi), results
1082 * are somewhat different. - Jean II */
1083 range->avg_qual.qual = 50;
1084 range->avg_qual.level = 186; /* -70 dBm */
1085 range->avg_qual.noise = 0;
1087 /* Event capability (kernel + driver) */
1088 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
1089 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
1090 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
1091 range->event_capa[1] = IW_EVENT_CAPA_K_1;
1092 range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVCUSTOM) |
1093 IW_EVENT_CAPA_MASK(IWEVMICHAELMICFAILURE));
1095 /* encode extension (WPA) capability */
1096 range->enc_capa = (IW_ENC_CAPA_WPA |
1098 IW_ENC_CAPA_CIPHER_TKIP |
1099 IW_ENC_CAPA_CIPHER_CCMP);
1104 /*------------------------------------------------------------------*/
1105 /* Wireless Handler : set Power Management */
1106 static int ks_wlan_set_power(struct net_device *dev, struct iw_request_info *info,
1107 struct iw_param *vwrq, char *extra)
1109 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1112 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1114 enabled = vwrq->disabled ? 0 : 1;
1115 if(enabled == 0 ){ /* 0 */
1116 priv->reg.powermgt = POWMGT_ACTIVE_MODE;
1117 }else if(enabled){ /* 1 */
1118 if(priv->reg.operation_mode == MODE_INFRASTRUCTURE)
1119 priv->reg.powermgt = POWMGT_SAVE1_MODE;
1122 }else if(enabled){ /* 2 */
1123 if(priv->reg.operation_mode == MODE_INFRASTRUCTURE)
1124 priv->reg.powermgt = POWMGT_SAVE2_MODE;
1130 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
1135 /*------------------------------------------------------------------*/
1136 /* Wireless Handler : get Power Management */
1137 static int ks_wlan_get_power(struct net_device *dev, struct iw_request_info *info,
1138 struct iw_param *vwrq, char *extra)
1140 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1142 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1144 if(priv->reg.powermgt > 0)
1152 /*------------------------------------------------------------------*/
1153 /* Wireless Handler : get wirless statistics */
1154 static int ks_wlan_get_iwstats(struct net_device *dev, struct iw_request_info *info,
1155 struct iw_quality *vwrq, char *extra)
1157 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1159 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1161 vwrq->qual = 0; /* not supported */
1162 vwrq->level = priv->wstats.qual.level;
1163 vwrq->noise = 0; /* not supported */
1169 #ifndef KSC_OPNOTSUPP
1170 /*------------------------------------------------------------------*/
1171 /* Wireless Handler : set Sensitivity */
1172 static int ks_wlan_set_sens(struct net_device *dev, struct iw_request_info *info,
1173 struct iw_param *vwrq, char *extra)
1175 return -EOPNOTSUPP; /* Not Support */
1178 /*------------------------------------------------------------------*/
1179 /* Wireless Handler : get Sensitivity */
1180 static int ks_wlan_get_sens(struct net_device *dev, struct iw_request_info *info,
1181 struct iw_param *vwrq, char *extra)
1185 vwrq->disabled = (vwrq->value == 0);
1189 #endif /* KSC_OPNOTSUPP */
1192 /*------------------------------------------------------------------*/
1193 /* Wireless Handler : get AP List */
1194 /* Note : this is deprecated in favor of IWSCAN */
1195 static int ks_wlan_get_aplist(struct net_device *dev, struct iw_request_info *info,
1196 struct iw_point *dwrq, char *extra)
1198 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1199 struct sockaddr *address = (struct sockaddr *) extra;
1200 struct iw_quality qual[LOCAL_APLIST_MAX];
1204 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1206 for (i = 0; i < priv->aplist.size; i++) {
1207 memcpy(address[i].sa_data, &(priv->aplist.ap[i].bssid[0]), ETH_ALEN);
1208 address[i].sa_family = ARPHRD_ETHER;
1209 qual[i].level = 256 - priv->aplist.ap[i].rssi;
1210 qual[i].qual = priv->aplist.ap[i].sq;
1211 qual[i].noise = 0; /* invalid noise value */
1212 qual[i].updated = 7;
1215 dwrq->flags = 1; /* Should be define'd */
1216 memcpy(extra + sizeof(struct sockaddr)*i,
1217 &qual, sizeof(struct iw_quality)*i);
1224 /*------------------------------------------------------------------*/
1225 /* Wireless Handler : Initiate Scan */
1226 static int ks_wlan_set_scan(struct net_device *dev, struct iw_request_info *info,
1227 union iwreq_data *wrqu, char *extra)
1229 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1230 struct iw_scan_req *req = NULL;
1233 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1235 /* specified SSID SCAN */
1236 if(wrqu->data.length == sizeof(struct iw_scan_req) && wrqu->data.flags & IW_SCAN_THIS_ESSID){
1237 req = (struct iw_scan_req *) extra;
1238 priv->scan_ssid_len = req->essid_len;
1239 memcpy(priv->scan_ssid, req->essid, priv->scan_ssid_len);
1241 priv->scan_ssid_len = 0;
1245 priv->sme_i.sme_flag |= SME_AP_SCAN;
1246 hostif_sme_enqueue(priv, SME_BSS_SCAN_REQUEST);
1248 /* At this point, just return to the user. */
1253 /*------------------------------------------------------------------*/
1255 * Translate scan data returned from the card to a card independent
1256 * format that the Wireless Tools will understand - Jean II
1258 static inline char *ks_wlan_translate_scan(struct net_device *dev, struct iw_request_info *info, char *current_ev,
1259 char *end_buf, struct local_ap_t *ap)
1261 /* ks_wlan_private *priv = (ks_wlan_private *)dev->priv; */
1262 struct iw_event iwe; /* Temporary buffer */
1264 char *current_val; /* For rates */
1266 static const char rsn_leader[] = "rsn_ie=";
1267 static const char wpa_leader[] = "wpa_ie=";
1268 char buf0[RSN_IE_BODY_MAX*2 + 30];
1269 char buf1[RSN_IE_BODY_MAX*2 + 30];
1271 /* First entry *MUST* be the AP MAC address */
1272 iwe.cmd = SIOCGIWAP;
1273 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1274 memcpy(iwe.u.ap_addr.sa_data, ap->bssid, ETH_ALEN);
1275 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
1277 /* Other entries will be displayed in the order we give them */
1280 iwe.u.data.length = ap->ssid.size;
1281 if(iwe.u.data.length > 32)
1282 iwe.u.data.length = 32;
1283 iwe.cmd = SIOCGIWESSID;
1284 iwe.u.data.flags = 1;
1285 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, &(ap->ssid.body[0]));
1288 iwe.cmd = SIOCGIWMODE;
1289 capabilities = le16_to_cpu(ap->capability);
1290 if(capabilities & (BSS_CAP_ESS | BSS_CAP_IBSS)) {
1291 if(capabilities & BSS_CAP_ESS)
1292 iwe.u.mode = IW_MODE_INFRA;
1294 iwe.u.mode = IW_MODE_ADHOC;
1295 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
1299 iwe.cmd = SIOCGIWFREQ;
1300 iwe.u.freq.m = ap->channel;
1301 iwe.u.freq.m = frequency_list[iwe.u.freq.m-1] * 100000;
1303 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
1305 /* Add quality statistics */
1307 iwe.u.qual.level = 256 - ap->rssi;
1308 iwe.u.qual.qual = ap->sq;
1309 iwe.u.qual.noise = 0; /* invalid noise value */
1310 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
1312 /* Add encryption capability */
1313 iwe.cmd = SIOCGIWENCODE;
1314 if(capabilities & BSS_CAP_PRIVACY)
1315 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1317 iwe.u.data.flags = IW_ENCODE_DISABLED;
1318 iwe.u.data.length = 0;
1319 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, &(ap->ssid.body[0]));
1321 /* Rate : stuffing multiple values in a single event require a bit
1322 * more of magic - Jean II */
1323 current_val = current_ev + IW_EV_LCP_LEN;
1325 iwe.cmd = SIOCGIWRATE;
1326 /* Those two flags are ignored... */
1327 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
1330 for(i = 0 ; i < 16 ; i++) {
1331 /* NULL terminated */
1332 if(i >= ap->rate_set.size)
1334 /* Bit rate given in 500 kb/s units (+ 0x80) */
1335 iwe.u.bitrate.value = ((ap->rate_set.body[i] & 0x7f) * 500000);
1336 /* Add new value to event */
1337 current_val = iwe_stream_add_value(info, current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
1339 /* Check if we added any event */
1340 if((current_val - current_ev) > IW_EV_LCP_LEN)
1341 current_ev = current_val;
1343 #define GENERIC_INFO_ELEM_ID 0xdd
1344 #define RSN_INFO_ELEM_ID 0x30
1345 if (ap->rsn_ie.id == RSN_INFO_ELEM_ID && ap->rsn_ie.size != 0) {
1347 memset(&iwe, 0, sizeof(iwe));
1348 iwe.cmd = IWEVCUSTOM;
1349 memcpy(buf0,rsn_leader,sizeof(rsn_leader)-1);
1350 iwe.u.data.length += sizeof(rsn_leader)-1;
1351 pbuf += sizeof(rsn_leader)-1;
1353 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.id);
1354 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.size);
1355 iwe.u.data.length += 4;
1357 for (i = 0; i < ap->rsn_ie.size; i++)
1358 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.body[i]);
1359 iwe.u.data.length += (ap->rsn_ie.size)*2;
1361 DPRINTK(4,"ap->rsn.size=%d\n",ap->rsn_ie.size);
1363 current_ev = iwe_stream_add_point(info, current_ev, end_buf,&iwe, &buf0[0]);
1365 if (ap->wpa_ie.id == GENERIC_INFO_ELEM_ID && ap->wpa_ie.size != 0) {
1367 memset(&iwe, 0, sizeof(iwe));
1368 iwe.cmd = IWEVCUSTOM;
1369 memcpy(buf1,wpa_leader,sizeof(wpa_leader)-1);
1370 iwe.u.data.length += sizeof(wpa_leader)-1;
1371 pbuf += sizeof(wpa_leader)-1;
1373 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.id);
1374 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.size);
1375 iwe.u.data.length += 4;
1377 for (i = 0; i < ap->wpa_ie.size; i++)
1378 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.body[i]);
1379 iwe.u.data.length += (ap->wpa_ie.size)*2;
1381 DPRINTK(4,"ap->rsn.size=%d\n",ap->wpa_ie.size);
1382 DPRINTK(4,"iwe.u.data.length=%d\n",iwe.u.data.length);
1384 current_ev = iwe_stream_add_point(info, current_ev, end_buf,&iwe, &buf1[0]);
1387 /* The other data in the scan result are not really
1388 * interesting, so for now drop it - Jean II */
1392 /*------------------------------------------------------------------*/
1393 /* Wireless Handler : Read Scan Results */
1394 static int ks_wlan_get_scan(struct net_device *dev, struct iw_request_info *info,
1395 struct iw_point *dwrq, char *extra)
1397 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1399 char *current_ev = extra;
1402 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1404 if(priv->sme_i.sme_flag & SME_AP_SCAN) {
1405 DPRINTK(2,"flag AP_SCAN\n");
1409 if(priv->aplist.size == 0) {
1410 /* Client error, no scan results...
1411 * The caller need to restart the scan. */
1412 DPRINTK(2,"aplist 0\n");
1416 /* current connect ap */
1417 if((priv->connect_status & CONNECT_STATUS_MASK)== CONNECT_STATUS){
1418 if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) {
1422 current_ev = ks_wlan_translate_scan(dev, current_ev,
1423 // extra + IW_SCAN_MAX_DATA,
1424 extra + dwrq->length,
1425 &(priv->current_ap));
1428 /* Read and parse all entries */
1429 for(i=0; i < priv->aplist.size; i++) {
1430 if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) {
1434 /* Translate to WE format this entry */
1435 current_ev = ks_wlan_translate_scan(dev, info, current_ev,
1436 // extra + IW_SCAN_MAX_DATA,
1437 extra + dwrq->length,
1438 &(priv->aplist.ap[i]));
1440 /* Length of data */
1441 dwrq->length = (current_ev - extra);
1447 /*------------------------------------------------------------------*/
1448 /* Commit handler : called after a bunch of SET operations */
1449 static int ks_wlan_config_commit(struct net_device *dev, struct iw_request_info *info,
1450 void *zwrq, char *extra)
1452 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1454 if (!priv->need_commit)
1457 ks_wlan_setup_parameter(priv, priv->need_commit);
1458 priv->need_commit=0;
1462 /*------------------------------------------------------------------*/
1463 /* Wireless handler : set association ie params */
1464 static int ks_wlan_set_genie(struct net_device *dev, struct iw_request_info *info,
1465 struct iw_point *dwrq, char *extra)
1467 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1471 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1474 // return -EOPNOTSUPP;
1477 /*------------------------------------------------------------------*/
1478 /* Wireless handler : set authentication mode params */
1479 static int ks_wlan_set_auth_mode(struct net_device *dev, struct iw_request_info *info,
1480 struct iw_param *vwrq, char *extra)
1482 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1483 int index = (vwrq->flags & IW_AUTH_INDEX);
1484 int value = vwrq->value;
1486 DPRINTK(2,"index=%d:value=%08X\n",index,value);
1488 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1491 case IW_AUTH_WPA_VERSION: /* 0 */
1493 case IW_AUTH_WPA_VERSION_DISABLED:
1494 priv->wpa.version = value;
1495 if(priv->wpa.rsn_enabled){
1496 priv->wpa.rsn_enabled = 0;
1498 priv->need_commit |= SME_RSN;
1500 case IW_AUTH_WPA_VERSION_WPA:
1501 case IW_AUTH_WPA_VERSION_WPA2:
1502 priv->wpa.version = value;
1503 if(!(priv->wpa.rsn_enabled)){
1504 priv->wpa.rsn_enabled = 1;
1506 priv->need_commit |= SME_RSN;
1512 case IW_AUTH_CIPHER_PAIRWISE: /* 1 */
1514 case IW_AUTH_CIPHER_NONE:
1515 if(priv->reg.privacy_invoked){
1516 priv->reg.privacy_invoked = 0x00;
1517 priv->need_commit |= SME_WEP_FLAG;
1520 case IW_AUTH_CIPHER_WEP40:
1521 case IW_AUTH_CIPHER_TKIP:
1522 case IW_AUTH_CIPHER_CCMP:
1523 case IW_AUTH_CIPHER_WEP104:
1524 if(!priv->reg.privacy_invoked){
1525 priv->reg.privacy_invoked = 0x01;
1526 priv->need_commit |= SME_WEP_FLAG;
1528 priv->wpa.pairwise_suite = value;
1529 priv->need_commit |= SME_RSN_UNICAST;
1535 case IW_AUTH_CIPHER_GROUP: /* 2 */
1537 case IW_AUTH_CIPHER_NONE:
1538 if(priv->reg.privacy_invoked){
1539 priv->reg.privacy_invoked = 0x00;
1540 priv->need_commit |= SME_WEP_FLAG;
1543 case IW_AUTH_CIPHER_WEP40:
1544 case IW_AUTH_CIPHER_TKIP:
1545 case IW_AUTH_CIPHER_CCMP:
1546 case IW_AUTH_CIPHER_WEP104:
1547 if(!priv->reg.privacy_invoked){
1548 priv->reg.privacy_invoked = 0x01;
1549 priv->need_commit |= SME_WEP_FLAG;
1551 priv->wpa.group_suite = value;
1552 priv->need_commit |= SME_RSN_MULTICAST;
1558 case IW_AUTH_KEY_MGMT: /* 3 */
1560 case IW_AUTH_KEY_MGMT_802_1X:
1561 case IW_AUTH_KEY_MGMT_PSK:
1562 case 0: /* NONE or 802_1X_NO_WPA */
1563 case 4: /* WPA_NONE */
1564 priv->wpa.key_mgmt_suite = value;
1565 priv->need_commit |= SME_RSN_AUTH;
1571 case IW_AUTH_80211_AUTH_ALG: /* 6 */
1573 case IW_AUTH_ALG_OPEN_SYSTEM:
1574 priv->wpa.auth_alg = value;
1575 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
1577 case IW_AUTH_ALG_SHARED_KEY:
1578 priv->wpa.auth_alg = value;
1579 priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
1581 case IW_AUTH_ALG_LEAP:
1585 priv->need_commit |= SME_MODE_SET;
1587 case IW_AUTH_WPA_ENABLED: /* 7 */
1588 priv->wpa.wpa_enabled = value;
1590 case IW_AUTH_PRIVACY_INVOKED: /* 10 */
1591 if((value && !priv->reg.privacy_invoked)||
1592 (!value && priv->reg.privacy_invoked)){
1593 priv->reg.privacy_invoked = value?0x01:0x00;
1594 priv->need_commit |= SME_WEP_FLAG;
1597 case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* 4 */
1598 case IW_AUTH_TKIP_COUNTERMEASURES: /* 5 */
1599 case IW_AUTH_DROP_UNENCRYPTED: /* 8 */
1600 case IW_AUTH_ROAMING_CONTROL: /* 9 */
1605 /* return -EINPROGRESS; */
1606 if(priv->need_commit){
1607 ks_wlan_setup_parameter(priv, priv->need_commit);
1608 priv->need_commit=0;
1613 /*------------------------------------------------------------------*/
1614 /* Wireless handler : get authentication mode params */
1615 static int ks_wlan_get_auth_mode(struct net_device *dev, struct iw_request_info *info,
1616 struct iw_param *vwrq, char *extra)
1618 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1619 int index = (vwrq->flags & IW_AUTH_INDEX);
1620 DPRINTK(2,"index=%d\n",index);
1622 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1624 /* WPA (not used ?? wpa_supplicant) */
1626 case IW_AUTH_WPA_VERSION:
1627 vwrq->value = priv->wpa.version;
1629 case IW_AUTH_CIPHER_PAIRWISE:
1630 vwrq->value = priv->wpa.pairwise_suite;
1632 case IW_AUTH_CIPHER_GROUP:
1633 vwrq->value = priv->wpa.group_suite;
1635 case IW_AUTH_KEY_MGMT:
1636 vwrq->value = priv->wpa.key_mgmt_suite;
1638 case IW_AUTH_80211_AUTH_ALG:
1639 vwrq->value = priv->wpa.auth_alg;
1641 case IW_AUTH_WPA_ENABLED:
1642 vwrq->value = priv->wpa.rsn_enabled;
1644 case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* OK??? */
1645 case IW_AUTH_TKIP_COUNTERMEASURES:
1646 case IW_AUTH_DROP_UNENCRYPTED:
1648 /* return -EOPNOTSUPP; */
1654 /*------------------------------------------------------------------*/
1655 /* Wireless Handler : set encoding token & mode (WPA)*/
1656 static int ks_wlan_set_encode_ext(struct net_device *dev, struct iw_request_info *info,
1657 struct iw_point *dwrq, char *extra)
1659 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1660 struct iw_encode_ext *enc;
1661 int index = dwrq->flags & IW_ENCODE_INDEX;
1662 unsigned int commit=0;
1664 enc = (struct iw_encode_ext *)extra;
1666 DPRINTK(2,"flags=%04X:: ext_flags=%08X\n",dwrq->flags, enc->ext_flags);
1668 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1670 if(index<1||index>4)
1675 if(dwrq->flags & IW_ENCODE_DISABLED){
1676 priv->wpa.key[index].key_len=0;
1680 priv->wpa.key[index].ext_flags=enc->ext_flags;
1681 if(enc->ext_flags&IW_ENCODE_EXT_SET_TX_KEY){
1682 priv->wpa.txkey=index;
1683 commit |= SME_WEP_INDEX;
1684 }else if(enc->ext_flags&IW_ENCODE_EXT_RX_SEQ_VALID){
1686 memcpy(&priv->wpa.key[index].rx_seq[0],
1687 enc->rx_seq, IW_ENCODE_SEQ_MAX_SIZE);
1692 memcpy(&priv->wpa.key[index].addr.sa_data[0],
1693 &enc->addr.sa_data[0], ETH_ALEN);
1696 case IW_ENCODE_ALG_NONE:
1697 if(priv->reg.privacy_invoked){
1698 priv->reg.privacy_invoked = 0x00;
1699 commit |= SME_WEP_FLAG;
1701 priv->wpa.key[index].key_len = 0;
1704 case IW_ENCODE_ALG_WEP:
1705 case IW_ENCODE_ALG_CCMP:
1706 if(!priv->reg.privacy_invoked){
1707 priv->reg.privacy_invoked = 0x01;
1708 commit |= SME_WEP_FLAG;
1710 if(enc->key && enc->key_len){
1711 memcpy(&priv->wpa.key[index].key_val[0],
1712 &enc->key[0], enc->key_len);
1713 priv->wpa.key[index].key_len = enc->key_len;
1714 commit |= (SME_WEP_VAL1 << index);
1717 case IW_ENCODE_ALG_TKIP:
1718 if(!priv->reg.privacy_invoked){
1719 priv->reg.privacy_invoked = 0x01;
1720 commit |= SME_WEP_FLAG;
1722 if(enc->key && enc->key_len == 32){
1723 memcpy(&priv->wpa.key[index].key_val[0],
1724 &enc->key[0], enc->key_len-16);
1725 priv->wpa.key[index].key_len = enc->key_len-16;
1726 if(priv->wpa.key_mgmt_suite==4){ /* WPA_NONE */
1727 memcpy(&priv->wpa.key[index].tx_mic_key[0],
1729 memcpy(&priv->wpa.key[index].rx_mic_key[0],
1732 memcpy(&priv->wpa.key[index].tx_mic_key[0],
1734 memcpy(&priv->wpa.key[index].rx_mic_key[0],
1737 commit |= (SME_WEP_VAL1 << index);
1743 priv->wpa.key[index].alg=enc->alg;
1749 if(commit&SME_WEP_INDEX)
1750 hostif_sme_enqueue(priv, SME_SET_TXKEY);
1751 if(commit&SME_WEP_VAL_MASK)
1752 hostif_sme_enqueue(priv, SME_SET_KEY1+index);
1753 if(commit&SME_WEP_FLAG)
1754 hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
1760 /*------------------------------------------------------------------*/
1761 /* Wireless Handler : get encoding token & mode (WPA)*/
1762 static int ks_wlan_get_encode_ext(struct net_device *dev, struct iw_request_info *info,
1763 struct iw_point *dwrq, char *extra)
1765 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1767 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1769 /* WPA (not used ?? wpa_supplicant)
1770 ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
1771 struct iw_encode_ext *enc;
1772 enc = (struct iw_encode_ext *)extra;
1773 int index = dwrq->flags & IW_ENCODE_INDEX;
1774 WPA (not used ?? wpa_supplicant) */
1778 /*------------------------------------------------------------------*/
1779 /* Wireless Handler : PMKSA cache operation (WPA2) */
1780 static int ks_wlan_set_pmksa(struct net_device *dev, struct iw_request_info *info,
1781 struct iw_point *dwrq, char *extra)
1783 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1784 struct iw_pmksa *pmksa ;
1787 struct list_head *ptr;
1791 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1796 pmksa = (struct iw_pmksa *)extra;
1797 DPRINTK(2,"cmd=%d\n",pmksa->cmd);
1801 if(list_empty(&priv->pmklist.head)){ /* new list */
1802 for(i=0;i<PMK_LIST_MAX;i++){
1803 pmk = &priv->pmklist.pmk[i];
1804 if(!memcmp("\x00\x00\x00\x00\x00\x00",pmk->bssid,ETH_ALEN))
1807 memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
1808 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1809 list_add(&pmk->list,&priv->pmklist.head);
1810 priv->pmklist.size++;
1812 else { /* search cache data */
1813 list_for_each(ptr, &priv->pmklist.head){
1814 pmk = list_entry(ptr, struct pmk_t, list);
1815 if(!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)){ /* match address! list move to head. */
1816 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1817 list_move(&pmk->list, &priv->pmklist.head);
1821 if(ptr == &priv->pmklist.head){ /* not find address. */
1822 if(PMK_LIST_MAX > priv->pmklist.size){ /* new cache data */
1823 for(i=0;i<PMK_LIST_MAX;i++){
1824 pmk = &priv->pmklist.pmk[i];
1825 if(!memcmp("\x00\x00\x00\x00\x00\x00",pmk->bssid,ETH_ALEN))
1828 memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
1829 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1830 list_add(&pmk->list,&priv->pmklist.head);
1831 priv->pmklist.size++;
1833 else{ /* overwrite old cache data */
1834 pmk = list_entry(priv->pmklist.head.prev, struct pmk_t, list);
1835 memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
1836 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1837 list_move(&pmk->list,&priv->pmklist.head);
1842 case IW_PMKSA_REMOVE:
1843 if(list_empty(&priv->pmklist.head)){ /* list empty */
1846 else{ /* search cache data */
1847 list_for_each(ptr, &priv->pmklist.head){
1848 pmk = list_entry(ptr, struct pmk_t, list);
1849 if(!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)){ /* match address! list del. */
1850 memset(pmk->bssid, 0, ETH_ALEN);
1851 memset(pmk->pmkid, 0, IW_PMKID_LEN);
1852 list_del_init(&pmk->list);
1856 if(ptr == &priv->pmklist.head){ /* not find address. */
1861 case IW_PMKSA_FLUSH:
1862 memset(&(priv->pmklist), 0, sizeof(priv->pmklist));
1863 INIT_LIST_HEAD(&priv->pmklist.head);
1864 for(i=0;i<PMK_LIST_MAX;i++)
1865 INIT_LIST_HEAD(&priv->pmklist.pmk[i].list);
1871 hostif_sme_enqueue(priv, SME_SET_PMKSA);
1875 static struct iw_statistics *ks_get_wireless_stats(struct net_device *dev)
1878 ks_wlan_private *priv = (ks_wlan_private *) netdev_priv(dev);
1879 struct iw_statistics *wstats = &priv->wstats;
1881 if(!atomic_read(&update_phyinfo)){
1882 if (priv->dev_state < DEVICE_STATE_READY)
1883 return NULL; /* not finished initialize */
1888 /* Packets discarded in the wireless adapter due to wireless
1889 * specific problems */
1890 wstats->discard.nwid = 0; /* Rx invalid nwid */
1891 wstats->discard.code = 0; /* Rx invalid crypt */
1892 wstats->discard.fragment = 0; /* Rx invalid frag */
1893 wstats->discard.retries = 0; /* Tx excessive retries */
1894 wstats->discard.misc = 0; /* Invalid misc */
1895 wstats->miss.beacon = 0; /* Missed beacon */
1900 /*------------------------------------------------------------------*/
1901 /* Private handler : set stop request */
1902 static int ks_wlan_set_stop_request(struct net_device *dev, struct iw_request_info *info,
1903 __u32 *uwrq, char *extra)
1905 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1908 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1913 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
1917 /*------------------------------------------------------------------*/
1918 /* Wireless Handler : set MLME */
1919 #include <linux/ieee80211.h>
1920 static int ks_wlan_set_mlme(struct net_device *dev, struct iw_request_info *info,
1921 struct iw_point *dwrq, char *extra)
1923 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1924 struct iw_mlme *mlme = (struct iw_mlme *)extra;
1927 DPRINTK(2, ":%d :%d\n", mlme->cmd, mlme->reason_code);
1929 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1931 switch (mlme->cmd) {
1932 case IW_MLME_DEAUTH:
1933 if (mlme->reason_code == WLAN_REASON_MIC_FAILURE) {
1936 case IW_MLME_DISASSOC:
1938 return ks_wlan_set_stop_request(dev, NULL, &mode, NULL);
1940 return -EOPNOTSUPP; /* Not Support */
1944 /*------------------------------------------------------------------*/
1945 /* Private handler : get driver version */
1946 static int ks_wlan_get_driver_version(struct net_device *dev, struct iw_request_info *info,
1947 struct iw_point *dwrq, char *extra)
1949 strcpy(extra, KS_WLAN_DRIVER_VERSION_INFO);
1950 dwrq->length = strlen(KS_WLAN_DRIVER_VERSION_INFO)+1;
1954 /*------------------------------------------------------------------*/
1955 /* Private handler : get firemware version */
1956 static int ks_wlan_get_firmware_version(struct net_device *dev, struct iw_request_info *info,
1957 struct iw_point *dwrq, char *extra)
1959 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1960 strcpy(extra, &(priv->firmware_version[0]));
1961 dwrq->length = priv->version_size+1;
1966 /*------------------------------------------------------------------*/
1967 /* Private handler : set force disconnect status */
1968 static int ks_wlan_set_detach(struct net_device *dev, struct iw_request_info *info,
1969 __u32 *uwrq, char *extra)
1971 ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
1973 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1975 if(*uwrq == CONNECT_STATUS){ /* 0 */
1976 priv->connect_status &= ~FORCE_DISCONNECT;
1977 if((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS)
1978 netif_carrier_on(dev);
1979 }else if(*uwrq == DISCONNECT_STATUS){ /* 1 */
1980 priv->connect_status |= FORCE_DISCONNECT;
1981 netif_carrier_off(dev);
1987 /*------------------------------------------------------------------*/
1988 /* Private handler : get force disconnect status */
1989 static int ks_wlan_get_detach(struct net_device *dev, struct iw_request_info *info,
1990 __u32 *uwrq, char *extra)
1992 ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
1994 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1996 *uwrq = ((priv->connect_status & FORCE_DISCONNECT) ? 1 : 0 );
2000 /*------------------------------------------------------------------*/
2001 /* Private handler : get connect status */
2002 static int ks_wlan_get_connect(struct net_device *dev, struct iw_request_info *info,
2003 __u32 *uwrq, char *extra)
2005 ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2007 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2009 *uwrq = (priv->connect_status & CONNECT_STATUS_MASK);
2014 /*------------------------------------------------------------------*/
2015 /* Private handler : set preamble */
2016 static int ks_wlan_set_preamble(struct net_device *dev, struct iw_request_info *info,
2017 __u32 *uwrq, char *extra)
2019 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2021 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2023 if(*uwrq == LONG_PREAMBLE){ /* 0 */
2024 priv->reg.preamble = LONG_PREAMBLE;
2025 }else if(*uwrq == SHORT_PREAMBLE){ /* 1 */
2026 priv->reg.preamble = SHORT_PREAMBLE;
2030 priv->need_commit |= SME_MODE_SET;
2031 return -EINPROGRESS; /* Call commit handler */
2035 /*------------------------------------------------------------------*/
2036 /* Private handler : get preamble */
2037 static int ks_wlan_get_preamble(struct net_device *dev, struct iw_request_info *info,
2038 __u32 *uwrq, char *extra)
2040 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2042 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2044 *uwrq = priv->reg.preamble;
2048 /*------------------------------------------------------------------*/
2049 /* Private handler : set power save mode */
2050 static int ks_wlan_set_powermgt(struct net_device *dev, struct iw_request_info *info,
2051 __u32 *uwrq, char *extra)
2053 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2055 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2057 if(*uwrq == POWMGT_ACTIVE_MODE){ /* 0 */
2058 priv->reg.powermgt = POWMGT_ACTIVE_MODE;
2059 }else if(*uwrq == POWMGT_SAVE1_MODE){ /* 1 */
2060 if(priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2061 priv->reg.powermgt = POWMGT_SAVE1_MODE;
2064 }else if(*uwrq == POWMGT_SAVE2_MODE){ /* 2 */
2065 if(priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2066 priv->reg.powermgt = POWMGT_SAVE2_MODE;
2072 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
2077 /*------------------------------------------------------------------*/
2078 /* Private handler : get power save made */
2079 static int ks_wlan_get_powermgt(struct net_device *dev, struct iw_request_info *info,
2080 __u32 *uwrq, char *extra)
2082 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2084 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2086 *uwrq = priv->reg.powermgt;
2090 /*------------------------------------------------------------------*/
2091 /* Private handler : set scan type */
2092 static int ks_wlan_set_scan_type(struct net_device *dev, struct iw_request_info *info,
2093 __u32 *uwrq, char *extra)
2095 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2097 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2099 if(*uwrq == ACTIVE_SCAN){ /* 0 */
2100 priv->reg.scan_type = ACTIVE_SCAN;
2101 }else if(*uwrq == PASSIVE_SCAN){ /* 1 */
2102 priv->reg.scan_type = PASSIVE_SCAN;
2109 /*------------------------------------------------------------------*/
2110 /* Private handler : get scan type */
2111 static int ks_wlan_get_scan_type(struct net_device *dev, struct iw_request_info *info,
2112 __u32 *uwrq, char *extra)
2114 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2116 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2118 *uwrq = priv->reg.scan_type;
2122 /*------------------------------------------------------------------*/
2123 /* Private handler : write raw data to device */
2124 static int ks_wlan_data_write(struct net_device *dev, struct iw_request_info *info,
2125 struct iw_point *dwrq, char *extra)
2127 ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2128 unsigned char *wbuff = NULL;
2130 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2132 wbuff = (unsigned char *)kmalloc(dwrq->length, GFP_ATOMIC);
2135 memcpy(wbuff, extra, dwrq->length);
2137 /* write to device */
2138 ks_wlan_hw_tx( priv, wbuff, dwrq->length, NULL, NULL, NULL);
2143 /*------------------------------------------------------------------*/
2144 /* Private handler : read raw data form device */
2145 static int ks_wlan_data_read(struct net_device *dev, struct iw_request_info *info,
2146 struct iw_point *dwrq, char *extra)
2148 ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2149 unsigned short read_length;
2151 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2153 if(!atomic_read(&priv->event_count)){
2154 if (priv->dev_state < DEVICE_STATE_BOOT) { /* Remove device */
2156 memset(extra,0xff,read_length);
2157 dwrq->length = read_length;
2166 if(atomic_read(&priv->event_count)>0)
2167 atomic_dec(&priv->event_count);
2169 spin_lock(&priv->dev_read_lock); /* request spin lock */
2171 /* Copy length max size 0x07ff */
2172 if(priv->dev_size[priv->dev_count] > 2047)
2175 read_length = priv->dev_size[priv->dev_count];
2178 memcpy(extra, &(priv->dev_data[priv->dev_count][0]), read_length);
2180 spin_unlock(&priv->dev_read_lock); /* release spin lock */
2183 priv->dev_data[priv->dev_count] = 0;
2184 priv->dev_size[priv->dev_count] = 0;
2187 if(priv->dev_count == DEVICE_STOCK_COUNT)
2191 dwrq->length = read_length;
2198 /*------------------------------------------------------------------*/
2199 /* Private handler : get wep string */
2200 #define WEP_ASCII_BUFF_SIZE (17+64*4+1)
2201 static int ks_wlan_get_wep_ascii(struct net_device *dev, struct iw_request_info *info,
2202 struct iw_point *dwrq, char *extra)
2204 ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2206 char tmp[WEP_ASCII_BUFF_SIZE];
2208 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2210 strcpy(tmp," WEP keys ASCII \n");
2211 len+=strlen(" WEP keys ASCII \n");
2214 strcpy(tmp+len,"\t[");
2218 strcpy(tmp+len,"] ");
2220 if(priv->reg.wep_key[i].size){
2221 strcpy(tmp+len,(priv->reg.wep_key[i].size < 6 ? "(40bits) [" : "(104bits) ["));
2222 len+=strlen((priv->reg.wep_key[i].size < 6 ? "(40bits) [" : "(104bits) ["));
2223 for(j=0;j<priv->reg.wep_key[i].size;j++,len++)
2224 tmp[len]=(isprint(priv->reg.wep_key[i].val[j]) ? priv->reg.wep_key[i].val[j] : ' ');
2226 strcpy(tmp+len,"]\n");
2230 strcpy(tmp+len,"off\n");
2231 len+=strlen("off\n");
2235 memcpy(extra, tmp, len);
2236 dwrq->length = len+1;
2241 /*------------------------------------------------------------------*/
2242 /* Private handler : set beacon lost count */
2243 static int ks_wlan_set_beacon_lost(struct net_device *dev, struct iw_request_info *info,
2244 __u32 *uwrq, char *extra)
2246 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2248 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2250 if(*uwrq >= BEACON_LOST_COUNT_MIN &&
2251 *uwrq <= BEACON_LOST_COUNT_MAX){
2252 priv->reg.beacon_lost_count = *uwrq;
2256 if(priv->reg.operation_mode == MODE_INFRASTRUCTURE){
2257 priv->need_commit |= SME_MODE_SET;
2258 return -EINPROGRESS; /* Call commit handler */
2264 /*------------------------------------------------------------------*/
2265 /* Private handler : get beacon lost count */
2266 static int ks_wlan_get_beacon_lost(struct net_device *dev, struct iw_request_info *info,
2267 __u32 *uwrq, char *extra)
2269 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2271 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2273 *uwrq = priv->reg.beacon_lost_count;
2277 /*------------------------------------------------------------------*/
2278 /* Private handler : set phy type */
2279 static int ks_wlan_set_phy_type(struct net_device *dev, struct iw_request_info *info,
2280 __u32 *uwrq, char *extra)
2282 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2284 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2286 if(*uwrq == D_11B_ONLY_MODE){ /* 0 */
2287 priv->reg.phy_type = D_11B_ONLY_MODE;
2288 }else if(*uwrq == D_11G_ONLY_MODE){ /* 1 */
2289 priv->reg.phy_type = D_11G_ONLY_MODE;
2290 }else if(*uwrq == D_11BG_COMPATIBLE_MODE){ /* 2 */
2291 priv->reg.phy_type = D_11BG_COMPATIBLE_MODE;
2295 priv->need_commit |= SME_MODE_SET;
2296 return -EINPROGRESS; /* Call commit handler */
2299 /*------------------------------------------------------------------*/
2300 /* Private handler : get phy type */
2301 static int ks_wlan_get_phy_type(struct net_device *dev, struct iw_request_info *info,
2302 __u32 *uwrq, char *extra)
2304 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2306 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2308 *uwrq = priv->reg.phy_type;
2312 /*------------------------------------------------------------------*/
2313 /* Private handler : set cts mode */
2314 static int ks_wlan_set_cts_mode(struct net_device *dev, struct iw_request_info *info,
2315 __u32 *uwrq, char *extra)
2317 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2319 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2321 if(*uwrq == CTS_MODE_FALSE){ /* 0 */
2322 priv->reg.cts_mode = CTS_MODE_FALSE;
2323 }else if(*uwrq == CTS_MODE_TRUE){ /* 1 */
2324 if(priv->reg.phy_type == D_11G_ONLY_MODE ||
2325 priv->reg.phy_type == D_11BG_COMPATIBLE_MODE)
2326 priv->reg.cts_mode = CTS_MODE_TRUE;
2328 priv->reg.cts_mode = CTS_MODE_FALSE;
2332 priv->need_commit |= SME_MODE_SET;
2333 return -EINPROGRESS; /* Call commit handler */
2336 /*------------------------------------------------------------------*/
2337 /* Private handler : get cts mode */
2338 static int ks_wlan_get_cts_mode(struct net_device *dev, struct iw_request_info *info,
2339 __u32 *uwrq, char *extra)
2341 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2343 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2345 *uwrq = priv->reg.cts_mode;
2349 /*------------------------------------------------------------------*/
2350 /* Private handler : set sleep mode */
2351 static int ks_wlan_set_sleep_mode(struct net_device *dev,
2352 struct iw_request_info *info,
2353 __u32 *uwrq, char *extra)
2355 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2359 if(*uwrq == SLP_SLEEP){
2360 priv->sleep_mode = *uwrq;
2361 printk("SET_SLEEP_MODE %d\n", priv->sleep_mode);
2363 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2364 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2366 }else if(*uwrq == SLP_ACTIVE) {
2367 priv->sleep_mode = *uwrq;
2368 printk("SET_SLEEP_MODE %d\n", priv->sleep_mode);
2369 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2371 printk("SET_SLEEP_MODE %d errror\n", *uwrq);
2377 /*------------------------------------------------------------------*/
2378 /* Private handler : get sleep mode */
2379 static int ks_wlan_get_sleep_mode(struct net_device *dev,
2380 struct iw_request_info *info,
2381 __u32 *uwrq, char *extra)
2383 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2385 DPRINTK(2, "GET_SLEEP_MODE %d\n", priv->sleep_mode);
2386 *uwrq = priv->sleep_mode;
2392 /*------------------------------------------------------------------*/
2393 /* Private handler : set phy information timer */
2394 static int ks_wlan_set_phy_information_timer(struct net_device *dev, struct iw_request_info *info,
2395 __u32 *uwrq, char *extra)
2397 ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2399 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2401 if(*uwrq >= 0 && *uwrq <= 0xFFFF) /* 0-65535 */
2402 priv->reg.phy_info_timer = (uint16_t)*uwrq;
2406 hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST);
2411 /*------------------------------------------------------------------*/
2412 /* Private handler : get phy information timer */
2413 static int ks_wlan_get_phy_information_timer(struct net_device *dev, struct iw_request_info *info,
2414 __u32 *uwrq, char *extra)
2416 ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2418 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2420 *uwrq = priv->reg.phy_info_timer;
2426 /*------------------------------------------------------------------*/
2427 /* Private handler : set WPS enable */
2428 static int ks_wlan_set_wps_enable(struct net_device *dev, struct iw_request_info *info,
2429 __u32 *uwrq, char *extra)
2431 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2434 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2436 if(*uwrq == 0 || *uwrq == 1)
2437 priv->wps.wps_enabled = *uwrq;
2441 hostif_sme_enqueue(priv, SME_WPS_ENABLE_REQUEST);
2445 /*------------------------------------------------------------------*/
2446 /* Private handler : get WPS enable */
2447 static int ks_wlan_get_wps_enable(struct net_device *dev, struct iw_request_info *info,
2448 __u32 *uwrq, char *extra)
2450 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2453 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2455 *uwrq = priv->wps.wps_enabled;
2456 printk("return=%d\n", *uwrq);
2460 /*------------------------------------------------------------------*/
2461 /* Private handler : set WPS probe req */
2462 static int ks_wlan_set_wps_probe_req(struct net_device *dev,
2463 struct iw_request_info *info,
2464 struct iw_point *dwrq, char *extra)
2468 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2472 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2474 DPRINTK(2,"dwrq->length=%d\n", dwrq->length);
2477 if(p[1] + 2 != dwrq->length || dwrq->length > 256 ){
2481 priv->wps.ielen = p[1] + 2 + 1; /* IE header + IE + sizeof(len) */
2482 len = p[1] + 2; /* IE header + IE */
2484 memcpy(priv->wps.ie, &len, sizeof(len));
2485 p = memcpy(priv->wps.ie+1, p, len);
2487 DPRINTK(2,"%d(%#x): %02X %02X %02X %02X ... %02X %02X %02X\n",
2488 priv->wps.ielen, priv->wps.ielen, p[0], p[1], p[2], p[3],
2489 p[priv->wps.ielen-3], p[priv->wps.ielen-2], p[priv->wps.ielen-1]);
2491 hostif_sme_enqueue(priv, SME_WPS_PROBE_REQUEST);
2496 /*------------------------------------------------------------------*/
2497 /* Private handler : get WPS probe req */
2498 static int ks_wlan_get_wps_probe_req(struct net_device *dev,
2499 struct iw_request_info *info,
2500 __u32 *uwrq, char *extra)
2502 ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2505 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2512 /*------------------------------------------------------------------*/
2513 /* Private handler : set tx gain control value */
2514 static int ks_wlan_set_tx_gain(struct net_device *dev, struct iw_request_info *info,
2515 __u32 *uwrq, char *extra)
2517 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2519 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2521 if(*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2522 priv->gain.TxGain = (uint8_t)*uwrq;
2526 if(priv->gain.TxGain < 0xFF)
2527 priv->gain.TxMode = 1;
2529 priv->gain.TxMode = 0;
2532 hostif_sme_enqueue(priv, SME_SET_GAIN);
2536 /*------------------------------------------------------------------*/
2537 /* Private handler : get tx gain control value */
2538 static int ks_wlan_get_tx_gain(struct net_device *dev, struct iw_request_info *info,
2539 __u32 *uwrq, char *extra)
2541 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2543 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2545 *uwrq = priv->gain.TxGain;
2546 hostif_sme_enqueue(priv, SME_GET_GAIN);
2550 /*------------------------------------------------------------------*/
2551 /* Private handler : set rx gain control value */
2552 static int ks_wlan_set_rx_gain(struct net_device *dev, struct iw_request_info *info,
2553 __u32 *uwrq, char *extra)
2555 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2557 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2559 if(*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2560 priv->gain.RxGain = (uint8_t)*uwrq;
2564 if(priv->gain.RxGain < 0xFF)
2565 priv->gain.RxMode = 1;
2567 priv->gain.RxMode = 0;
2569 hostif_sme_enqueue(priv, SME_SET_GAIN);
2573 /*------------------------------------------------------------------*/
2574 /* Private handler : get rx gain control value */
2575 static int ks_wlan_get_rx_gain(struct net_device *dev, struct iw_request_info *info,
2576 __u32 *uwrq, char *extra)
2578 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2580 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2582 *uwrq = priv->gain.RxGain;
2583 hostif_sme_enqueue(priv, SME_GET_GAIN);
2587 /*------------------------------------------------------------------*/
2588 /* Private handler : set region value */
2589 static int ks_wlan_set_region(struct net_device *dev, struct iw_request_info *info,
2590 __u32 *uwrq, char *extra)
2592 ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2594 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2596 if(*uwrq >= 0x9 && *uwrq <= 0xF) /* 0x9-0xf */
2597 priv->region = (uint8_t)*uwrq;
2601 hostif_sme_enqueue(priv, SME_SET_REGION);
2606 /*------------------------------------------------------------------*/
2607 /* Private handler : get eeprom checksum result */
2608 static int ks_wlan_get_eeprom_cksum(struct net_device *dev, struct iw_request_info *info,
2609 __u32 *uwrq, char *extra)
2611 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2613 *uwrq = priv->eeprom_checksum;
2617 static void print_hif_event(int event){
2621 printk("HIF_DATA_REQ\n");
2624 printk("HIF_DATA_IND\n");
2626 case HIF_MIB_GET_REQ :
2627 printk("HIF_MIB_GET_REQ\n");
2629 case HIF_MIB_GET_CONF :
2630 printk("HIF_MIB_GET_CONF\n");
2632 case HIF_MIB_SET_REQ :
2633 printk("HIF_MIB_SET_REQ\n");
2635 case HIF_MIB_SET_CONF :
2636 printk("HIF_MIB_SET_CONF\n");
2638 case HIF_POWERMGT_REQ :
2639 printk("HIF_POWERMGT_REQ\n");
2641 case HIF_POWERMGT_CONF :
2642 printk("HIF_POWERMGT_CONF\n");
2644 case HIF_START_REQ :
2645 printk("HIF_START_REQ\n");
2647 case HIF_START_CONF :
2648 printk("HIF_START_CONF\n");
2650 case HIF_CONNECT_IND :
2651 printk("HIF_CONNECT_IND\n");
2654 printk("HIF_STOP_REQ\n");
2656 case HIF_STOP_CONF :
2657 printk("HIF_STOP_CONF\n");
2659 case HIF_PS_ADH_SET_REQ :
2660 printk("HIF_PS_ADH_SET_REQ\n");
2662 case HIF_PS_ADH_SET_CONF:
2663 printk("HIF_PS_ADH_SET_CONF\n");
2665 case HIF_INFRA_SET_REQ :
2666 printk("HIF_INFRA_SET_REQ\n");
2668 case HIF_INFRA_SET_CONF :
2669 printk("HIF_INFRA_SET_CONF\n");
2671 case HIF_ADH_SET_REQ :
2672 printk("HIF_ADH_SET_REQ\n");
2674 case HIF_ADH_SET_CONF :
2675 printk("HIF_ADH_SET_CONF\n");
2677 case HIF_AP_SET_REQ :
2678 printk("HIF_AP_SET_REQ\n");
2680 case HIF_AP_SET_CONF :
2681 printk("HIF_AP_SET_CONF\n");
2683 case HIF_ASSOC_INFO_IND :
2684 printk("HIF_ASSOC_INFO_IND\n");
2686 case HIF_MIC_FAILURE_REQ:
2687 printk("HIF_MIC_FAILURE_REQ\n");
2689 case HIF_MIC_FAILURE_CONF :
2690 printk("HIF_MIC_FAILURE_CONF\n");
2693 printk("HIF_SCAN_REQ\n");
2695 case HIF_SCAN_CONF :
2696 printk("HIF_SCAN_CONF\n");
2698 case HIF_PHY_INFO_REQ :
2699 printk("HIF_PHY_INFO_REQ\n");
2701 case HIF_PHY_INFO_CONF :
2702 printk("HIF_PHY_INFO_CONF\n");
2704 case HIF_SLEEP_REQ :
2705 printk("HIF_SLEEP_REQ\n");
2707 case HIF_SLEEP_CONF :
2708 printk("HIF_SLEEP_CONF\n");
2710 case HIF_PHY_INFO_IND :
2711 printk("HIF_PHY_INFO_IND\n");
2714 printk("HIF_SCAN_IND\n");
2716 case HIF_INFRA_SET2_REQ :
2717 printk("HIF_INFRA_SET2_REQ\n");
2719 case HIF_INFRA_SET2_CONF:
2720 printk("HIF_INFRA_SET2_CONF\n");
2722 case HIF_ADH_SET2_REQ :
2723 printk("HIF_ADH_SET2_REQ\n");
2725 case HIF_ADH_SET2_CONF :
2726 printk("HIF_ADH_SET2_CONF\n");
2730 /*------------------------------------------------------------------*/
2731 /* Private handler : get host command history */
2732 static int ks_wlan_hostt(struct net_device *dev, struct iw_request_info *info,
2733 __u32 *uwrq, char *extra)
2736 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2738 for(i = 63; i >= 0; i--){
2739 event = priv->hostt.buff[(priv->hostt.qtail -1 -i)%SME_EVENT_BUFF_SIZE] ;
2740 print_hif_event(event);
2745 /* Structures to export the Wireless Handlers */
2747 static const struct iw_priv_args ks_wlan_private_args[] = {
2748 /*{ cmd, set_args, get_args, name[16] } */
2749 { KS_WLAN_GET_DRIVER_VERSION, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | (128+1), "GetDriverVer" },
2750 { KS_WLAN_GET_FIRM_VERSION, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | (128+1), "GetFirmwareVer" },
2752 { KS_WLAN_SET_WPS_ENABLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetWPSEnable" },
2753 { KS_WLAN_GET_WPS_ENABLE, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetW" },
2754 { KS_WLAN_SET_WPS_PROBE_REQ, IW_PRIV_TYPE_BYTE | 2047, IW_PRIV_TYPE_NONE, "SetWPSProbeReq" },
2756 { KS_WLAN_SET_PREAMBLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetPreamble" },
2757 { KS_WLAN_GET_PREAMBLE, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPreamble" },
2758 { KS_WLAN_SET_POWER_SAVE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetPowerSave" },
2759 { KS_WLAN_GET_POWER_SAVE, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPowerSave" },
2760 { KS_WLAN_SET_SCAN_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetScanType" },
2761 { KS_WLAN_GET_SCAN_TYPE, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetScanType" },
2762 { KS_WLAN_SET_RX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetRxGain" },
2763 { KS_WLAN_GET_RX_GAIN, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetRxGain" },
2764 { KS_WLAN_HOSTT, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | (128+1), "hostt" },
2765 { KS_WLAN_SET_BEACON_LOST, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetBeaconLost" },
2766 { KS_WLAN_GET_BEACON_LOST, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetBeaconLost" },
2767 { KS_WLAN_SET_SLEEP_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetSleepMode" },
2768 { KS_WLAN_GET_SLEEP_MODE, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetSleepMode" },
2769 { KS_WLAN_SET_TX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetTxGain" },
2770 { KS_WLAN_GET_TX_GAIN, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetTxGain" },
2771 { KS_WLAN_SET_PHY_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetPhyType" },
2772 { KS_WLAN_GET_PHY_TYPE, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPhyType" },
2773 { KS_WLAN_SET_CTS_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetCtsMode" },
2774 { KS_WLAN_GET_CTS_MODE, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetCtsMode" },
2775 { KS_WLAN_GET_EEPROM_CKSUM, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetChecksum" },
2777 static const iw_handler ks_wlan_handler[] =
2779 (iw_handler) ks_wlan_config_commit, /* SIOCSIWCOMMIT */
2780 (iw_handler) ks_wlan_get_name, /* SIOCGIWNAME */
2781 (iw_handler) NULL, /* SIOCSIWNWID */
2782 (iw_handler) NULL, /* SIOCGIWNWID */
2783 (iw_handler) ks_wlan_set_freq, /* SIOCSIWFREQ */
2784 (iw_handler) ks_wlan_get_freq, /* SIOCGIWFREQ */
2785 (iw_handler) ks_wlan_set_mode, /* SIOCSIWMODE */
2786 (iw_handler) ks_wlan_get_mode, /* SIOCGIWMODE */
2787 #ifndef KSC_OPNOTSUPP
2788 (iw_handler) ks_wlan_set_sens, /* SIOCSIWSENS */
2789 (iw_handler) ks_wlan_get_sens, /* SIOCGIWSENS */
2790 #else /* KSC_OPNOTSUPP */
2791 (iw_handler) NULL, /* SIOCSIWSENS */
2792 (iw_handler) NULL, /* SIOCGIWSENS */
2793 #endif /* KSC_OPNOTSUPP */
2794 (iw_handler) NULL, /* SIOCSIWRANGE */
2795 (iw_handler) ks_wlan_get_range, /* SIOCGIWRANGE */
2796 (iw_handler) NULL, /* SIOCSIWPRIV */
2797 (iw_handler) NULL, /* SIOCGIWPRIV */
2798 (iw_handler) NULL, /* SIOCSIWSTATS */
2799 (iw_handler) ks_wlan_get_iwstats, /* SIOCGIWSTATS */
2800 (iw_handler) NULL, /* SIOCSIWSPY */
2801 (iw_handler) NULL, /* SIOCGIWSPY */
2802 (iw_handler) NULL, /* SIOCSIWTHRSPY */
2803 (iw_handler) NULL, /* SIOCGIWTHRSPY */
2804 (iw_handler) ks_wlan_set_wap, /* SIOCSIWAP */
2805 (iw_handler) ks_wlan_get_wap, /* SIOCGIWAP */
2806 // (iw_handler) NULL, /* SIOCSIWMLME */
2807 (iw_handler) ks_wlan_set_mlme, /* SIOCSIWMLME */
2808 (iw_handler) ks_wlan_get_aplist, /* SIOCGIWAPLIST */
2809 (iw_handler) ks_wlan_set_scan, /* SIOCSIWSCAN */
2810 (iw_handler) ks_wlan_get_scan, /* SIOCGIWSCAN */
2811 (iw_handler) ks_wlan_set_essid, /* SIOCSIWESSID */
2812 (iw_handler) ks_wlan_get_essid, /* SIOCGIWESSID */
2813 (iw_handler) ks_wlan_set_nick, /* SIOCSIWNICKN */
2814 (iw_handler) ks_wlan_get_nick, /* SIOCGIWNICKN */
2815 (iw_handler) NULL, /* -- hole -- */
2816 (iw_handler) NULL, /* -- hole -- */
2817 (iw_handler) ks_wlan_set_rate, /* SIOCSIWRATE */
2818 (iw_handler) ks_wlan_get_rate, /* SIOCGIWRATE */
2819 (iw_handler) ks_wlan_set_rts, /* SIOCSIWRTS */
2820 (iw_handler) ks_wlan_get_rts, /* SIOCGIWRTS */
2821 (iw_handler) ks_wlan_set_frag, /* SIOCSIWFRAG */
2822 (iw_handler) ks_wlan_get_frag, /* SIOCGIWFRAG */
2823 #ifndef KSC_OPNOTSUPP
2824 (iw_handler) ks_wlan_set_txpow, /* SIOCSIWTXPOW */
2825 (iw_handler) ks_wlan_get_txpow, /* SIOCGIWTXPOW */
2826 (iw_handler) ks_wlan_set_retry, /* SIOCSIWRETRY */
2827 (iw_handler) ks_wlan_get_retry, /* SIOCGIWRETRY */
2828 #else /* KSC_OPNOTSUPP */
2829 (iw_handler) NULL, /* SIOCSIWTXPOW */
2830 (iw_handler) NULL, /* SIOCGIWTXPOW */
2831 (iw_handler) NULL, /* SIOCSIWRETRY */
2832 (iw_handler) NULL, /* SIOCGIWRETRY */
2833 #endif /* KSC_OPNOTSUPP */
2834 (iw_handler) ks_wlan_set_encode, /* SIOCSIWENCODE */
2835 (iw_handler) ks_wlan_get_encode, /* SIOCGIWENCODE */
2836 (iw_handler) ks_wlan_set_power, /* SIOCSIWPOWER */
2837 (iw_handler) ks_wlan_get_power, /* SIOCGIWPOWER */
2838 (iw_handler) NULL, /* -- hole -- */
2839 (iw_handler) NULL, /* -- hole -- */
2840 // (iw_handler) NULL, /* SIOCSIWGENIE */
2841 (iw_handler) ks_wlan_set_genie, /* SIOCSIWGENIE */
2842 (iw_handler) NULL, /* SIOCGIWGENIE */
2843 (iw_handler) ks_wlan_set_auth_mode, /* SIOCSIWAUTH */
2844 (iw_handler) ks_wlan_get_auth_mode, /* SIOCGIWAUTH */
2845 (iw_handler) ks_wlan_set_encode_ext, /* SIOCSIWENCODEEXT */
2846 (iw_handler) ks_wlan_get_encode_ext, /* SIOCGIWENCODEEXT */
2847 (iw_handler) ks_wlan_set_pmksa, /* SIOCSIWPMKSA */
2848 (iw_handler) NULL, /* -- hole -- */
2851 /* private_handler */
2852 static const iw_handler ks_wlan_private_handler[] =
2854 (iw_handler) NULL, /* 0 */
2855 (iw_handler) ks_wlan_get_driver_version, /* 1 KS_WLAN_GET_DRIVER_VERSION */
2856 (iw_handler) NULL, /* 2 */
2857 (iw_handler) ks_wlan_get_firmware_version, /* 3 KS_WLAN_GET_FIRM_VERSION */
2859 (iw_handler) ks_wlan_set_wps_enable, /* 4 KS_WLAN_SET_WPS_ENABLE */
2860 (iw_handler) ks_wlan_get_wps_enable, /* 5 KS_WLAN_GET_WPS_ENABLE */
2861 (iw_handler) ks_wlan_set_wps_probe_req, /* 6 KS_WLAN_SET_WPS_PROBE_REQ */
2863 (iw_handler) NULL, /* 4 */
2864 (iw_handler) NULL, /* 5 */
2865 (iw_handler) NULL, /* 6 */
2868 (iw_handler) ks_wlan_get_eeprom_cksum, /* 7 KS_WLAN_GET_CONNECT */
2869 (iw_handler) ks_wlan_set_preamble, /* 8 KS_WLAN_SET_PREAMBLE */
2870 (iw_handler) ks_wlan_get_preamble, /* 9 KS_WLAN_GET_PREAMBLE */
2871 (iw_handler) ks_wlan_set_powermgt, /* 10 KS_WLAN_SET_POWER_SAVE */
2872 (iw_handler) ks_wlan_get_powermgt, /* 11 KS_WLAN_GET_POWER_SAVE */
2873 (iw_handler) ks_wlan_set_scan_type, /* 12 KS_WLAN_SET_SCAN_TYPE */
2874 (iw_handler) ks_wlan_get_scan_type, /* 13 KS_WLAN_GET_SCAN_TYPE */
2875 (iw_handler) ks_wlan_set_rx_gain, /* 14 KS_WLAN_SET_RX_GAIN */
2876 (iw_handler) ks_wlan_get_rx_gain, /* 15 KS_WLAN_GET_RX_GAIN */
2877 (iw_handler) ks_wlan_hostt, /* 16 KS_WLAN_HOSTT */
2878 (iw_handler) NULL, /* 17 */
2879 (iw_handler) ks_wlan_set_beacon_lost, /* 18 KS_WLAN_SET_BECAN_LOST */
2880 (iw_handler) ks_wlan_get_beacon_lost, /* 19 KS_WLAN_GET_BECAN_LOST */
2881 (iw_handler) ks_wlan_set_tx_gain, /* 20 KS_WLAN_SET_TX_GAIN */
2882 (iw_handler) ks_wlan_get_tx_gain, /* 21 KS_WLAN_GET_TX_GAIN */
2883 (iw_handler) ks_wlan_set_phy_type, /* 22 KS_WLAN_SET_PHY_TYPE */
2884 (iw_handler) ks_wlan_get_phy_type, /* 23 KS_WLAN_GET_PHY_TYPE */
2885 (iw_handler) ks_wlan_set_cts_mode, /* 24 KS_WLAN_SET_CTS_MODE */
2886 (iw_handler) ks_wlan_get_cts_mode, /* 25 KS_WLAN_GET_CTS_MODE */
2887 (iw_handler) NULL, /* 26 */
2888 (iw_handler) NULL, /* 27 */
2889 (iw_handler) ks_wlan_set_sleep_mode, /* 28 KS_WLAN_SET_SLEEP_MODE */
2890 (iw_handler) ks_wlan_get_sleep_mode, /* 29 KS_WLAN_GET_SLEEP_MODE */
2891 (iw_handler) NULL, /* 30 */
2892 (iw_handler) NULL, /* 31 */
2895 static const struct iw_handler_def ks_wlan_handler_def =
2897 .num_standard = sizeof(ks_wlan_handler)/sizeof(iw_handler),
2898 .num_private = sizeof(ks_wlan_private_handler)/sizeof(iw_handler),
2899 .num_private_args = sizeof(ks_wlan_private_args)/sizeof(struct iw_priv_args),
2900 .standard = (iw_handler *) ks_wlan_handler,
2901 .private = (iw_handler *) ks_wlan_private_handler,
2902 .private_args = (struct iw_priv_args *) ks_wlan_private_args,
2903 .get_wireless_stats = ks_get_wireless_stats,
2907 static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2910 struct iwreq *wrq = (struct iwreq *) rq;
2912 case SIOCIWFIRSTPRIV+20: /* KS_WLAN_SET_STOP_REQ */
2913 rc = ks_wlan_set_stop_request(dev, NULL, &(wrq->u.mode), NULL);
2915 // All other calls are currently unsupported
2920 DPRINTK(5,"return=%d\n",rc);
2926 struct net_device_stats *ks_wlan_get_stats(struct net_device *dev)
2928 ks_wlan_private *priv = netdev_priv(dev);
2930 if (priv->dev_state < DEVICE_STATE_READY) {
2931 return NULL; /* not finished initialize */
2934 return &priv->nstats;
2938 int ks_wlan_set_mac_address(struct net_device *dev, void *addr)
2940 ks_wlan_private *priv = netdev_priv(dev);
2941 struct sockaddr *mac_addr=(struct sockaddr *)addr;
2942 if (netif_running(dev))
2944 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
2945 memcpy(priv->eth_addr, mac_addr->sa_data, ETH_ALEN);
2947 priv->mac_address_valid = 0;
2948 hostif_sme_enqueue(priv, SME_MACADDRESS_SET_REQUEST);
2949 printk(KERN_INFO "ks_wlan: MAC ADDRESS = %02x:%02x:%02x:%02x:%02x:%02x\n",
2950 priv->eth_addr[0],priv->eth_addr[1],priv->eth_addr[2],
2951 priv->eth_addr[3],priv->eth_addr[4],priv->eth_addr[5]);
2957 void ks_wlan_tx_timeout(struct net_device *dev)
2959 ks_wlan_private *priv = netdev_priv(dev);
2961 DPRINTK(1,"head(%d) tail(%d)!!\n",priv->tx_dev.qhead, priv->tx_dev.qtail);
2962 if(!netif_queue_stopped(dev)){
2963 netif_stop_queue(dev);
2965 priv->nstats.tx_errors++;
2966 netif_wake_queue(dev);
2972 int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev)
2974 ks_wlan_private *priv = netdev_priv(dev);
2977 DPRINTK(3,"in_interrupt()=%ld\n",in_interrupt());
2979 if ( skb == NULL ) {
2980 printk( KERN_ERR "ks_wlan: skb == NULL!!!\n" );
2983 if (priv->dev_state < DEVICE_STATE_READY) {
2985 return 0; /* not finished initialize */
2988 if(netif_running(dev))
2989 netif_stop_queue(dev);
2991 rc = hostif_data_request(priv, skb);
2992 dev->trans_start = jiffies;
2994 DPRINTK(4,"rc=%d\n",rc);
3002 void send_packet_complete(void *arg1, void *arg2)
3004 ks_wlan_private *priv = (ks_wlan_private *)arg1;
3005 struct sk_buff *packet = (struct sk_buff *)arg2;
3009 priv->nstats.tx_bytes += packet->len;
3010 priv->nstats.tx_packets++;
3012 if(netif_queue_stopped(priv->net_dev))
3013 netif_wake_queue(priv->net_dev);
3016 dev_kfree_skb(packet);
3022 /* Set or clear the multicast filter for this adaptor.
3023 This routine is not state sensitive and need not be SMP locked. */
3025 void ks_wlan_set_multicast_list(struct net_device *dev)
3027 ks_wlan_private *priv = netdev_priv(dev);
3030 if (priv->dev_state < DEVICE_STATE_READY) {
3031 return ; /* not finished initialize */
3033 hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST);
3039 int ks_wlan_open(struct net_device *dev)
3041 ks_wlan_private *priv = netdev_priv(dev);
3045 if(!priv->mac_address_valid){
3046 printk(KERN_ERR "ks_wlan : %s Not READY !!\n", dev->name);
3050 netif_start_queue (dev);
3056 int ks_wlan_close(struct net_device *dev)
3059 netif_stop_queue (dev);
3061 DPRINTK(4, "%s: Shutting down ethercard, status was 0x%4.4x.\n",
3068 /* Operational parameters that usually are not changed. */
3069 /* Time in jiffies before concluding the transmitter is hung. */
3070 #define TX_TIMEOUT (3*HZ)
3071 static const unsigned char dummy_addr[] = {0x00,0x0b,0xe3,0x00,0x00,0x00};
3073 static const struct net_device_ops ks_wlan_netdev_ops = {
3074 .ndo_start_xmit = ks_wlan_start_xmit,
3075 .ndo_open = ks_wlan_open,
3076 .ndo_stop = ks_wlan_close,
3077 .ndo_do_ioctl = ks_wlan_netdev_ioctl,
3078 .ndo_set_mac_address = ks_wlan_set_mac_address,
3079 .ndo_get_stats = ks_wlan_get_stats,
3080 .ndo_tx_timeout = ks_wlan_tx_timeout,
3081 .ndo_set_rx_mode = ks_wlan_set_multicast_list,
3084 int ks_wlan_net_start(struct net_device *dev)
3086 ks_wlan_private *priv;
3089 priv = netdev_priv(dev);
3090 priv->mac_address_valid = 0;
3091 priv->need_commit = 0;
3093 priv->device_open_status = 1;
3095 /* phy information update timer */
3096 atomic_set(&update_phyinfo,0);
3097 init_timer(&update_phyinfo_timer);
3098 update_phyinfo_timer.function=ks_wlan_update_phyinfo_timeout;
3099 update_phyinfo_timer.data = (unsigned long)priv;
3101 /* dummy address set */
3102 memcpy(priv->eth_addr, dummy_addr, ETH_ALEN);
3103 dev->dev_addr[0] = priv->eth_addr[0];
3104 dev->dev_addr[1] = priv->eth_addr[1];
3105 dev->dev_addr[2] = priv->eth_addr[2];
3106 dev->dev_addr[3] = priv->eth_addr[3];
3107 dev->dev_addr[4] = priv->eth_addr[4];
3108 dev->dev_addr[5] = priv->eth_addr[5];
3109 dev->dev_addr[6] = 0x00;
3110 dev->dev_addr[7] = 0x00;
3112 /* The ks_wlan-specific entries in the device structure. */
3113 dev->netdev_ops = &ks_wlan_netdev_ops;
3114 dev->wireless_handlers = (struct iw_handler_def *)&ks_wlan_handler_def;
3115 dev->watchdog_timeo = TX_TIMEOUT;
3117 netif_carrier_off(dev);
3123 int ks_wlan_net_stop(struct net_device *dev)
3125 ks_wlan_private *priv = netdev_priv(dev);
3128 priv->device_open_status = 0;
3129 del_timer_sync(&update_phyinfo_timer);
3131 if(netif_running(dev))
3132 netif_stop_queue(dev);
3137 int ks_wlan_reset(struct net_device *dev)