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 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24))
17 #include <linux/config.h>
19 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include <linux/compiler.h>
22 #include <linux/init.h>
23 #include <linux/ioport.h>
24 #include <linux/netdevice.h>
25 #include <linux/etherdevice.h>
26 #include <linux/if_arp.h>
27 #include <linux/rtnetlink.h>
28 #include <linux/delay.h>
29 #include <linux/completion.h>
30 #include <linux/mii.h>
31 #include <linux/pci.h>
32 #include <linux/ctype.h>
33 #include <linux/timer.h>
34 #include <asm/atomic.h>
36 #include <asm/uaccess.h>
38 static int wep_on_off;
40 #define WEP_ON_64BIT 1
41 #define WEP_ON_128BIT 2
44 #include "ks_hostif.h"
45 #include "ks_wlan_ioctl.h"
48 /* Include Wireless Extension definition and check version */
49 #include <linux/wireless.h>
50 #define WIRELESS_SPY /* enable iwspy support */
51 #include <net/iw_handler.h> /* New driver API */
53 /* Frequency list (map channels to frequencies) */
54 static const long frequency_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
55 2447, 2452, 2457, 2462, 2467, 2472, 2484 };
57 /* A few details needed for WEP (Wireless Equivalent Privacy) */
58 #define MAX_KEY_SIZE 13 /* 128 (?) bits */
59 #define MIN_KEY_SIZE 5 /* 40 bits RC4 - WEP */
60 typedef struct wep_key_t {
62 u8 key[16]; /* 40-bit and 104-bit keys */
65 /* Backward compatibility */
66 #ifndef IW_ENCODE_NOKEY
67 #define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not present */
68 #define IW_ENCODE_MODE (IW_ENCODE_DISABLED | IW_ENCODE_RESTRICTED | IW_ENCODE_OPEN)
69 #endif /* IW_ENCODE_NOKEY */
71 /* List of Wireless Handlers (new API) */
72 static const struct iw_handler_def ks_wlan_handler_def;
74 #define KSC_OPNOTSUPP /* Operation Not Support*/
80 extern int ks_wlan_hw_tx(ks_wlan_private *priv, void *p, unsigned long size,
81 void (*complete_handler)(void *arg1, void *arg2),
84 static int ks_wlan_open (struct net_device *dev);
85 static void ks_wlan_tx_timeout (struct net_device *dev);
86 static int ks_wlan_start_xmit (struct sk_buff *skb, struct net_device *dev);
87 static int ks_wlan_close (struct net_device *dev);
88 static void ks_wlan_set_multicast_list (struct net_device *dev);
89 static struct net_device_stats *ks_wlan_get_stats (struct net_device *dev);
90 static int ks_wlan_set_mac_address(struct net_device *dev, void *addr);
91 static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
93 static atomic_t update_phyinfo;
94 static struct timer_list update_phyinfo_timer;
96 int ks_wlan_update_phy_information(ks_wlan_private *priv)
98 struct iw_statistics *wstats = &priv->wstats;
100 DPRINTK(4, "in_interrupt = %ld\n", in_interrupt());
102 if (priv->dev_state < DEVICE_STATE_READY) {
103 return -1; /* not finished initialize */
105 if(atomic_read(&update_phyinfo))
109 wstats->status = priv->reg.operation_mode; /* Operation mode */
111 /* Signal quality and co. But where is the noise level ??? */
112 hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST);
114 /* interruptible_sleep_on_timeout(&priv->confirm_wait, HZ/2); */
115 if(!wait_for_completion_interruptible_timeout(&priv->confirm_wait,HZ/2)){
116 DPRINTK(1,"wait time out!!\n");
119 atomic_inc(&update_phyinfo);
120 update_phyinfo_timer.expires = jiffies + HZ; /* 1sec */
121 add_timer(&update_phyinfo_timer);
127 void ks_wlan_update_phyinfo_timeout(unsigned long ptr)
129 DPRINTK(4, "in_interrupt = %ld\n", in_interrupt());
130 atomic_set(&update_phyinfo,0);
133 int ks_wlan_setup_parameter(ks_wlan_private *priv, unsigned int commit_flag)
137 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
139 if(commit_flag & SME_RTS)
140 hostif_sme_enqueue(priv, SME_RTS_THRESHOLD_REQUEST);
141 if(commit_flag & SME_FRAG)
142 hostif_sme_enqueue(priv, SME_FRAGMENTATION_THRESHOLD_REQUEST);
144 if(commit_flag & SME_WEP_INDEX)
145 hostif_sme_enqueue(priv, SME_WEP_INDEX_REQUEST);
146 if(commit_flag & SME_WEP_VAL1)
147 hostif_sme_enqueue(priv, SME_WEP_KEY1_REQUEST);
148 if(commit_flag & SME_WEP_VAL2)
149 hostif_sme_enqueue(priv, SME_WEP_KEY2_REQUEST);
150 if(commit_flag & SME_WEP_VAL3)
151 hostif_sme_enqueue(priv, SME_WEP_KEY3_REQUEST);
152 if(commit_flag & SME_WEP_VAL4)
153 hostif_sme_enqueue(priv, SME_WEP_KEY4_REQUEST);
154 if(commit_flag & SME_WEP_FLAG)
155 hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
157 if(commit_flag & SME_RSN){
158 hostif_sme_enqueue(priv, SME_RSN_ENABLED_REQUEST);
159 hostif_sme_enqueue(priv, SME_RSN_MODE_REQUEST);
161 if(commit_flag & SME_RSN_MULTICAST)
162 hostif_sme_enqueue(priv, SME_RSN_MCAST_REQUEST);
163 if(commit_flag & SME_RSN_UNICAST)
164 hostif_sme_enqueue(priv, SME_RSN_UCAST_REQUEST);
165 if(commit_flag & SME_RSN_AUTH)
166 hostif_sme_enqueue(priv, SME_RSN_AUTH_REQUEST);
168 hostif_sme_enqueue(priv, SME_MODE_SET_REQUEST);
170 hostif_sme_enqueue(priv, SME_START_REQUEST);
176 * Initial Wireless Extension code for Ks_Wlannet driver by :
177 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00
178 * Conversion to new driver API by :
179 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 26 March 02
180 * Javier also did a good amount of work here, adding some new extensions
181 * and fixing my code. Let's just say that without him this code just
182 * would not work at all... - Jean II
185 /*------------------------------------------------------------------*/
186 /* Wireless Handler : get protocol name */
187 static int ks_wlan_get_name(struct net_device *dev, struct iw_request_info *info,
188 char *cwrq, char *extra)
190 ks_wlan_private *priv = (ks_wlan_private *) netdev_priv(dev);
192 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
194 if (priv->dev_state < DEVICE_STATE_READY) {
195 strcpy(cwrq, "NOT READY!");
197 else if(priv->reg.phy_type == D_11B_ONLY_MODE){
198 strcpy(cwrq, "IEEE 802.11b");
200 else if(priv->reg.phy_type == D_11G_ONLY_MODE){
201 strcpy(cwrq, "IEEE 802.11g");
204 strcpy(cwrq, "IEEE 802.11b/g");
210 /*------------------------------------------------------------------*/
211 /* Wireless Handler : set frequency */
212 static int ks_wlan_set_freq(struct net_device *dev, struct iw_request_info *info,
213 struct iw_freq *fwrq, char *extra)
215 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
216 int rc = -EINPROGRESS; /* Call commit handler */
218 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
220 /* If setting by frequency, convert to a channel */
222 (fwrq->m >= (int) 2.412e8) &&
223 (fwrq->m <= (int) 2.487e8)) {
224 int f = fwrq->m / 100000;
226 while((c < 14) && (f != frequency_list[c]))
228 /* Hack to fall through... */
232 /* Setting by channel number */
233 if((fwrq->m > 1000) || (fwrq->e > 0))
236 int channel = fwrq->m;
237 /* We should do a better check than that,
238 * based on the card capability !!! */
239 if((channel < 1) || (channel > 14)) {
240 printk(KERN_DEBUG "%s: New channel value of %d is invalid!\n", dev->name, fwrq->m);
243 /* Yes ! We can set it !!! */
244 priv->reg.channel = (u8)(channel);
245 priv->need_commit |= SME_MODE_SET;
252 /*------------------------------------------------------------------*/
253 /* Wireless Handler : get frequency */
254 static int ks_wlan_get_freq(struct net_device *dev, struct iw_request_info *info,
255 struct iw_freq *fwrq, char *extra)
257 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
260 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
262 if((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS){
263 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, struct iw_request_info *info,
276 struct iw_point *dwrq, char *extra)
278 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
281 DPRINTK(2," %d\n", dwrq->flags);
283 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
285 /* Check if we asked for `any' */
286 if(dwrq->flags == 0) {
287 /* Just send an empty SSID list */
288 memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
289 priv->reg.ssid.size = 0;
293 /* iwconfig uses nul termination in SSID.. */
294 if (len > 0 && extra[len - 1] == '\0')
297 /* Check the size of the string */
298 if(len > IW_ESSID_MAX_SIZE) {
302 /* Check the size of the string */
303 if(dwrq->length > IW_ESSID_MAX_SIZE+1) {
309 memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
312 memcpy(priv->reg.ssid.body, extra, len);
313 priv->reg.ssid.size = len;
315 memcpy(priv->reg.ssid.body, extra, dwrq->length);
316 priv->reg.ssid.size = dwrq->length;
319 /* Write it to the card */
320 priv->need_commit |= SME_MODE_SET;
322 // return -EINPROGRESS; /* Call commit handler */
323 ks_wlan_setup_parameter(priv, priv->need_commit);
328 /*------------------------------------------------------------------*/
329 /* Wireless Handler : get ESSID */
330 static int ks_wlan_get_essid(struct net_device *dev, struct iw_request_info *info,
331 struct iw_point *dwrq, char *extra)
333 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
335 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
337 /* Note : if dwrq->flags != 0, we should
338 * get the relevant SSID from the SSID list... */
340 if(priv->reg.ssid.size){
341 /* Get the current SSID */
342 memcpy(extra, priv->reg.ssid.body, priv->reg.ssid.size);
344 extra[priv->reg.ssid.size] = '\0';
346 /* If none, we may want to get the one that was set */
350 dwrq->length = priv->reg.ssid.size;
352 dwrq->length = priv->reg.ssid.size+1;
354 dwrq->flags = 1; /* active */
362 dwrq->flags = 0; /* ANY */
368 /*------------------------------------------------------------------*/
369 /* Wireless Handler : set AP address */
370 static int ks_wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
371 struct sockaddr *ap_addr, char *extra)
373 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
377 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
379 if (priv->reg.operation_mode == MODE_ADHOC ||
380 priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
381 memcpy(priv->reg.bssid, (u8 *)&ap_addr->sa_data, ETH_ALEN);
383 if (is_valid_ether_addr((u8 *)priv->reg.bssid)) {
384 priv->need_commit |= SME_MODE_SET;
388 memset(priv->reg.bssid, 0x0, ETH_ALEN);
392 DPRINTK(2, "bssid = %02x:%02x:%02x:%02x:%02x:%02x\n",
393 priv->reg.bssid[0],priv->reg.bssid[1],priv->reg.bssid[2],
394 priv->reg.bssid[3],priv->reg.bssid[4],priv->reg.bssid[5]);
396 /* Write it to the card */
397 if (priv->need_commit) {
398 priv->need_commit |= SME_MODE_SET;
399 return -EINPROGRESS; /* Call commit handler */
404 /*------------------------------------------------------------------*/
405 /* Wireless Handler : get AP address */
406 static int ks_wlan_get_wap(struct net_device *dev, struct iw_request_info *info,
407 struct sockaddr *awrq, char *extra)
409 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
411 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
413 if((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS){
414 memcpy(awrq->sa_data, &(priv->current_ap.bssid[0]), ETH_ALEN);
417 memset(awrq->sa_data, 0, ETH_ALEN);
420 awrq->sa_family = ARPHRD_ETHER;
425 /*------------------------------------------------------------------*/
426 /* Wireless Handler : set Nickname */
427 static int ks_wlan_set_nick(struct net_device *dev, struct iw_request_info *info,
428 struct iw_point *dwrq, char *extra)
430 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
432 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
434 /* Check the size of the string */
435 if(dwrq->length > 16 + 1) {
438 memset(priv->nick, 0, sizeof(priv->nick));
439 memcpy(priv->nick, extra, dwrq->length);
441 return -EINPROGRESS; /* Call commit handler */
444 /*------------------------------------------------------------------*/
445 /* Wireless Handler : get Nickname */
446 static int ks_wlan_get_nick(struct net_device *dev, struct iw_request_info *info,
447 struct iw_point *dwrq, char *extra)
449 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
451 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
453 strncpy(extra, priv->nick, 16);
455 dwrq->length = strlen(extra) + 1;
460 /*------------------------------------------------------------------*/
461 /* Wireless Handler : set Bit-Rate */
462 static int ks_wlan_set_rate(struct net_device *dev, struct iw_request_info *info,
463 struct iw_param *vwrq, char *extra)
465 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
468 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
470 if(priv->reg.phy_type == D_11B_ONLY_MODE){
471 if(vwrq->fixed == 1) {
475 priv->reg.rate_set.body[0] = (uint8_t)(vwrq->value/500000);
479 priv->reg.rate_set.body[0] = ((uint8_t)(vwrq->value/500000))|BASIC_RATE;
484 priv->reg.tx_rate = TX_RATE_FIXED;
485 priv->reg.rate_set.size = 1;
486 }else{ /* vwrq->fixed == 0 */
490 priv->reg.rate_set.body[3] = TX_RATE_11M; i++;
492 priv->reg.rate_set.body[2] = TX_RATE_5M; i++;
494 priv->reg.rate_set.body[1] = TX_RATE_2M|BASIC_RATE; i++;
496 priv->reg.rate_set.body[0] = TX_RATE_1M|BASIC_RATE; i++;
501 priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
502 priv->reg.rate_set.size = i;
504 priv->reg.rate_set.body[3] = TX_RATE_11M;
505 priv->reg.rate_set.body[2] = TX_RATE_5M;
506 priv->reg.rate_set.body[1] = TX_RATE_2M|BASIC_RATE;
507 priv->reg.rate_set.body[0] = TX_RATE_1M|BASIC_RATE;
508 priv->reg.tx_rate = TX_RATE_FULL_AUTO;
509 priv->reg.rate_set.size = 4;
512 }else{ /* D_11B_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
513 if(vwrq->fixed == 1) {
520 priv->reg.rate_set.body[0] = (uint8_t)(vwrq->value/500000);
529 priv->reg.rate_set.body[0] = ((uint8_t)(vwrq->value/500000))|BASIC_RATE;
534 priv->reg.tx_rate = TX_RATE_FIXED;
535 priv->reg.rate_set.size = 1;
536 }else{ /* vwrq->fixed == 0 */
540 priv->reg.rate_set.body[11] = TX_RATE_54M; i++;
542 priv->reg.rate_set.body[10] = TX_RATE_48M; i++;
544 priv->reg.rate_set.body[9] = TX_RATE_36M; i++;
545 case 24000000: case 18000000: case 12000000:
546 case 11000000: case 9000000: case 6000000:
547 if(vwrq->value == 24000000){
548 priv->reg.rate_set.body[8] = TX_RATE_18M; i++;
549 priv->reg.rate_set.body[7] = TX_RATE_9M; i++;
550 priv->reg.rate_set.body[6] = TX_RATE_24M|BASIC_RATE; i++;
551 priv->reg.rate_set.body[5] = TX_RATE_12M|BASIC_RATE; i++;
552 priv->reg.rate_set.body[4] = TX_RATE_6M|BASIC_RATE; i++;
553 priv->reg.rate_set.body[3] = TX_RATE_11M|BASIC_RATE; i++;
554 }else if(vwrq->value == 18000000){
555 priv->reg.rate_set.body[7] = TX_RATE_18M; i++;
556 priv->reg.rate_set.body[6] = TX_RATE_9M; i++;
557 priv->reg.rate_set.body[5] = TX_RATE_12M|BASIC_RATE; i++;
558 priv->reg.rate_set.body[4] = TX_RATE_6M|BASIC_RATE; i++;
559 priv->reg.rate_set.body[3] = TX_RATE_11M|BASIC_RATE; i++;
560 }else if(vwrq->value == 12000000){
561 priv->reg.rate_set.body[6] = TX_RATE_9M; i++;
562 priv->reg.rate_set.body[5] = TX_RATE_12M|BASIC_RATE; i++;
563 priv->reg.rate_set.body[4] = TX_RATE_6M|BASIC_RATE; i++;
564 priv->reg.rate_set.body[3] = TX_RATE_11M|BASIC_RATE; i++;
565 }else if(vwrq->value == 11000000){
566 priv->reg.rate_set.body[5] = TX_RATE_9M; i++;
567 priv->reg.rate_set.body[4] = TX_RATE_6M|BASIC_RATE; i++;
568 priv->reg.rate_set.body[3] = TX_RATE_11M|BASIC_RATE; i++;
569 }else if(vwrq->value == 9000000){
570 priv->reg.rate_set.body[4] = TX_RATE_9M; i++;
571 priv->reg.rate_set.body[3] = TX_RATE_6M|BASIC_RATE; i++;
572 }else{ /* vwrq->value == 6000000 */
573 priv->reg.rate_set.body[3] = TX_RATE_6M|BASIC_RATE; i++;
576 priv->reg.rate_set.body[2] = TX_RATE_5M|BASIC_RATE; i++;
578 priv->reg.rate_set.body[1] = TX_RATE_2M|BASIC_RATE; i++;
580 priv->reg.rate_set.body[0] = TX_RATE_1M|BASIC_RATE; i++;
585 priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
586 priv->reg.rate_set.size = i;
588 priv->reg.rate_set.body[11] = TX_RATE_54M;
589 priv->reg.rate_set.body[10] = TX_RATE_48M;
590 priv->reg.rate_set.body[9] = TX_RATE_36M;
591 priv->reg.rate_set.body[8] = TX_RATE_18M;
592 priv->reg.rate_set.body[7] = TX_RATE_9M;
593 priv->reg.rate_set.body[6] = TX_RATE_24M|BASIC_RATE;
594 priv->reg.rate_set.body[5] = TX_RATE_12M|BASIC_RATE;
595 priv->reg.rate_set.body[4] = TX_RATE_6M|BASIC_RATE;
596 priv->reg.rate_set.body[3] = TX_RATE_11M|BASIC_RATE;
597 priv->reg.rate_set.body[2] = TX_RATE_5M|BASIC_RATE;
598 priv->reg.rate_set.body[1] = TX_RATE_2M|BASIC_RATE;
599 priv->reg.rate_set.body[0] = TX_RATE_1M|BASIC_RATE;
600 priv->reg.tx_rate = TX_RATE_FULL_AUTO;
601 priv->reg.rate_set.size = 12;
606 priv->need_commit |= SME_MODE_SET;
608 return -EINPROGRESS; /* Call commit handler */
611 /*------------------------------------------------------------------*/
612 /* Wireless Handler : get Bit-Rate */
613 static int ks_wlan_get_rate(struct net_device *dev, struct iw_request_info *info,
614 struct iw_param *vwrq, char *extra)
616 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
618 DPRINTK(2, "in_interrupt = %ld update_phyinfo = %d\n",
619 in_interrupt(),atomic_read(&update_phyinfo));
621 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
623 if(!atomic_read(&update_phyinfo)){
624 ks_wlan_update_phy_information(priv);
626 vwrq->value = ((priv->current_rate) & RATE_MASK) * 500000;
627 if(priv->reg.tx_rate == TX_RATE_FIXED)
635 /*------------------------------------------------------------------*/
636 /* Wireless Handler : set RTS threshold */
637 static int ks_wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
638 struct iw_param *vwrq, char *extra)
640 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
641 int rthr = vwrq->value;
643 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
647 if((rthr < 0) || (rthr > 2347)) {
650 priv->reg.rts = rthr;
651 priv->need_commit |= SME_RTS;
653 return -EINPROGRESS; /* Call commit handler */
656 /*------------------------------------------------------------------*/
657 /* Wireless Handler : get RTS threshold */
658 static int ks_wlan_get_rts(struct net_device *dev, struct iw_request_info *info,
659 struct iw_param *vwrq, char *extra)
661 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
663 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
665 vwrq->value = priv->reg.rts;
666 vwrq->disabled = (vwrq->value >= 2347);
672 /*------------------------------------------------------------------*/
673 /* Wireless Handler : set Fragmentation threshold */
674 static int ks_wlan_set_frag(struct net_device *dev, struct iw_request_info *info,
675 struct iw_param *vwrq, char *extra)
677 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
678 int fthr = vwrq->value;
680 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
684 if((fthr < 256) || (fthr > 2346)) {
687 fthr &= ~0x1; /* Get an even value - is it really needed ??? */
688 priv->reg.fragment = fthr;
689 priv->need_commit |= SME_FRAG;
691 return -EINPROGRESS; /* Call commit handler */
694 /*------------------------------------------------------------------*/
695 /* Wireless Handler : get Fragmentation threshold */
696 static int ks_wlan_get_frag(struct net_device *dev, struct iw_request_info *info,
697 struct iw_param *vwrq, char *extra)
699 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
701 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
703 vwrq->value = priv->reg.fragment;
704 vwrq->disabled = (vwrq->value >= 2346);
710 /*------------------------------------------------------------------*/
711 /* Wireless Handler : set Mode of Operation */
712 static int ks_wlan_set_mode(struct net_device *dev, struct iw_request_info *info,
713 __u32 *uwrq, char *extra)
715 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
717 DPRINTK(2,"mode=%d\n",*uwrq);
719 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
723 priv->reg.operation_mode = MODE_ADHOC;
724 priv->need_commit |= SME_MODE_SET;
727 priv->reg.operation_mode = MODE_INFRASTRUCTURE;
728 priv->need_commit |= SME_MODE_SET;
734 case IW_MODE_MONITOR:
739 return -EINPROGRESS; /* Call commit handler */
742 /*------------------------------------------------------------------*/
743 /* Wireless Handler : get Mode of Operation */
744 static int ks_wlan_get_mode(struct net_device *dev, struct iw_request_info *info,
745 __u32 *uwrq, char *extra)
747 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
749 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
751 /* If not managed, assume it's ad-hoc */
752 switch (priv->reg.operation_mode) {
753 case MODE_INFRASTRUCTURE:
754 *uwrq = IW_MODE_INFRA;
757 *uwrq = IW_MODE_ADHOC;
760 *uwrq = IW_MODE_ADHOC;
766 /*------------------------------------------------------------------*/
767 /* Wireless Handler : set Encryption Key */
768 static int ks_wlan_set_encode(struct net_device *dev, struct iw_request_info *info,
769 struct iw_point *dwrq, char *extra)
771 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
774 int index = (dwrq->flags & IW_ENCODE_INDEX);
775 int current_index = priv->reg.wep_index;
778 DPRINTK(2,"flags=%04X\n",dwrq->flags);
780 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
783 if((index<0) || (index>4))
786 index = current_index;
790 /* Is WEP supported ? */
791 /* Basic checking: do we have a key to set ? */
792 if (dwrq->length > 0) {
793 if (dwrq->length > MAX_KEY_SIZE) { /* Check the size of the key */
796 if (dwrq->length > MIN_KEY_SIZE) { /* Set the length */
797 key.len = MAX_KEY_SIZE;
798 priv->reg.privacy_invoked = 0x01;
799 priv->need_commit |= SME_WEP_FLAG;
800 wep_on_off = WEP_ON_128BIT;
802 if (dwrq->length > 0) {
803 key.len = MIN_KEY_SIZE;
804 priv->reg.privacy_invoked = 0x01;
805 priv->need_commit |= SME_WEP_FLAG;
806 wep_on_off = WEP_ON_64BIT;
807 } else { /* Disable the key */
811 /* Check if the key is not marked as invalid */
812 if(!(dwrq->flags & IW_ENCODE_NOKEY)) {
814 memset(key.key, 0, MAX_KEY_SIZE);
815 /* Copy the key in the driver */
816 if(copy_from_user(key.key,dwrq->pointer,dwrq->length)) {
820 /* Send the key to the card */
821 priv->reg.wep_key[index].size = key.len;
822 for (i=0; i<(priv->reg.wep_key[index].size); i++) {
823 priv->reg.wep_key[index].val[i] = key.key[i];
825 priv->need_commit |= (SME_WEP_VAL1<<index);
826 priv->reg.wep_index = index;
827 priv->need_commit |= SME_WEP_INDEX;
830 if(dwrq->flags & IW_ENCODE_DISABLED){
831 priv->reg.wep_key[0].size = 0;
832 priv->reg.wep_key[1].size = 0;
833 priv->reg.wep_key[2].size = 0;
834 priv->reg.wep_key[3].size = 0;
835 priv->reg.privacy_invoked = 0x00;
836 if(priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY){
837 priv->need_commit |= SME_MODE_SET;
839 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
840 wep_on_off = WEP_OFF;
841 priv->need_commit |= SME_WEP_FLAG;
843 /* Do we want to just set the transmit key index ? */
844 if ((index>=0) && (index<4)) {
845 /* set_wep_key(priv, index, 0, 0, 1); xxx */
846 if(priv->reg.wep_key[index].size){
847 priv->reg.wep_index = index;
848 priv->need_commit |= SME_WEP_INDEX;
856 /* Commit the changes if needed */
857 if(dwrq->flags & IW_ENCODE_MODE)
858 priv->need_commit |= SME_WEP_FLAG;
860 if(dwrq->flags & IW_ENCODE_OPEN) {
861 if(priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY){
862 priv->need_commit |= SME_MODE_SET;
864 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
865 } else if(dwrq->flags & IW_ENCODE_RESTRICTED) {
866 if(priv->reg.authenticate_type == AUTH_TYPE_OPEN_SYSTEM){
867 priv->need_commit |= SME_MODE_SET;
869 priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
872 // return -EINPROGRESS; /* Call commit handler */
873 if(priv->need_commit){
874 ks_wlan_setup_parameter(priv, priv->need_commit);
880 /*------------------------------------------------------------------*/
881 /* Wireless Handler : get Encryption Key */
882 static int ks_wlan_get_encode(struct net_device *dev, struct iw_request_info *info,
883 struct iw_point *dwrq, char *extra)
885 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
887 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
889 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
891 dwrq->flags = IW_ENCODE_DISABLED;
893 /* Check encryption mode */
894 switch(priv->reg.authenticate_type) {
895 case AUTH_TYPE_OPEN_SYSTEM:
896 dwrq->flags = IW_ENCODE_OPEN;
898 case AUTH_TYPE_SHARED_KEY:
899 dwrq->flags = IW_ENCODE_RESTRICTED;
903 memset(zeros,0, sizeof(zeros));
905 /* Which key do we want ? -1 -> tx index */
906 if((index < 0) || (index >= 4))
907 index = priv->reg.wep_index;
908 if (priv->reg.privacy_invoked){
909 dwrq->flags &= ~IW_ENCODE_DISABLED;
910 /* dwrq->flags |= IW_ENCODE_NOKEY; */
912 dwrq->flags |= index + 1;
913 DPRINTK(2,"encoding flag = 0x%04X\n",dwrq->flags);
914 /* Copy the key to the user buffer */
915 if((index >= 0) && (index < 4))
916 dwrq->length = priv->reg.wep_key[index].size;
917 if (dwrq->length > 16) {
920 #if 1 /* IW_ENCODE_NOKEY; */
922 if((index >= 0) && (index < 4))
923 memcpy(extra,priv->reg.wep_key[index].val,dwrq->length);
925 memcpy(extra,zeros,dwrq->length);
930 #ifndef KSC_OPNOTSUPP
931 /*------------------------------------------------------------------*/
932 /* Wireless Handler : set Tx-Power */
933 static int ks_wlan_set_txpow(struct net_device *dev, struct iw_request_info *info,
934 struct iw_param *vwrq, char *extra)
936 return -EOPNOTSUPP; /* Not Support */
939 /*------------------------------------------------------------------*/
940 /* Wireless Handler : get Tx-Power */
941 static int ks_wlan_get_txpow(struct net_device *dev, struct iw_request_info *info,
942 struct iw_param *vwrq, char *extra)
944 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
948 vwrq->disabled = (vwrq->value == 0);
953 /*------------------------------------------------------------------*/
954 /* Wireless Handler : set Retry limits */
955 static int ks_wlan_set_retry(struct net_device *dev, struct iw_request_info *info,
956 struct iw_param *vwrq, char *extra)
958 return -EOPNOTSUPP; /* Not Support */
961 /*------------------------------------------------------------------*/
962 /* Wireless Handler : get Retry limits */
963 static int ks_wlan_get_retry(struct net_device *dev, struct iw_request_info *info,
964 struct iw_param *vwrq, char *extra)
966 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
970 vwrq->disabled = (vwrq->value == 0);
974 #endif /* KSC_OPNOTSUPP */
976 /*------------------------------------------------------------------*/
977 /* Wireless Handler : get range info */
978 static int ks_wlan_get_range(struct net_device *dev, struct iw_request_info *info,
979 struct iw_point *dwrq, char *extra)
981 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
982 struct iw_range *range = (struct iw_range *) extra;
987 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
989 dwrq->length = sizeof(struct iw_range);
990 memset(range, 0, sizeof(*range));
991 range->min_nwid = 0x0000;
992 range->max_nwid = 0x0000;
993 range->num_channels = 14;
994 /* Should be based on cap_rid.country to give only
995 * what the current card support */
997 for(i = 0; i < 13; i++) { /* channel 1 -- 13*/
998 range->freq[k].i = i + 1; /* List index */
999 range->freq[k].m = frequency_list[i] * 100000;
1000 range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
1002 range->num_frequency = k;
1003 if(priv->reg.phy_type == D_11B_ONLY_MODE ||
1004 priv->reg.phy_type == D_11BG_COMPATIBLE_MODE){ /* channel 14 */
1005 range->freq[13].i = 14; /* List index */
1006 range->freq[13].m = frequency_list[13] * 100000;
1007 range->freq[13].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
1008 range->num_frequency = 14;
1011 /* Hum... Should put the right values there */
1012 range->max_qual.qual = 100;
1013 range->max_qual.level = 256 - 128; /* 0 dBm? */
1014 range->max_qual.noise = 256 - 128;
1015 range->sensitivity = 1;
1017 if(priv->reg.phy_type == D_11B_ONLY_MODE){
1018 range->bitrate[0] = 1e6;
1019 range->bitrate[1] = 2e6;
1020 range->bitrate[2] = 5.5e6;
1021 range->bitrate[3] = 11e6;
1022 range->num_bitrates = 4;
1024 else{ /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
1025 range->bitrate[0] = 1e6;
1026 range->bitrate[1] = 2e6;
1027 range->bitrate[2] = 5.5e6;
1028 range->bitrate[3] = 11e6;
1030 range->bitrate[4] = 6e6;
1031 range->bitrate[5] = 9e6;
1032 range->bitrate[6] = 12e6;
1033 if(IW_MAX_BITRATES < 9){
1034 range->bitrate[7] = 54e6;
1035 range->num_bitrates = 8;
1037 range->bitrate[7] = 18e6;
1038 range->bitrate[8] = 24e6;
1039 range->bitrate[9] = 36e6;
1040 range->bitrate[10] = 48e6;
1041 range->bitrate[11] = 54e6;
1043 range->num_bitrates = 12;
1047 /* Set an indication of the max TCP throughput
1048 * in bit/s that we can expect using this interface.
1049 * May be use for QoS stuff... Jean II */
1051 range->throughput = 5000 * 1000;
1053 range->throughput = 1500 * 1000;
1056 range->max_rts = 2347;
1057 range->min_frag = 256;
1058 range->max_frag = 2346;
1060 range->encoding_size[0] = 5; /* WEP: RC4 40 bits */
1061 range->encoding_size[1] = 13; /* WEP: RC4 ~128 bits */
1062 range->num_encoding_sizes = 2;
1063 range->max_encoding_tokens = 4;
1065 /* power management not support */
1066 range->pmp_flags = IW_POWER_ON;
1067 range->pmt_flags = IW_POWER_ON;
1070 /* Transmit Power - values are in dBm( or mW) */
1071 range->txpower[0]=-256;
1072 range->num_txpower = 1;
1073 range->txpower_capa = IW_TXPOW_DBM;
1074 /* range->txpower_capa = IW_TXPOW_MWATT; */
1076 range->we_version_source = 21;
1077 range->we_version_compiled = WIRELESS_EXT;
1079 range->retry_capa = IW_RETRY_ON;
1080 range->retry_flags = IW_RETRY_ON;
1081 range->r_time_flags = IW_RETRY_ON;
1083 /* Experimental measurements - boundary 11/5.5 Mb/s */
1084 /* Note : with or without the (local->rssi), results
1085 * are somewhat different. - Jean II */
1086 range->avg_qual.qual = 50;
1087 range->avg_qual.level = 186; /* -70 dBm */
1088 range->avg_qual.noise = 0;
1090 /* Event capability (kernel + driver) */
1091 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
1092 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
1093 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
1094 range->event_capa[1] = IW_EVENT_CAPA_K_1;
1095 range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVCUSTOM) |
1096 IW_EVENT_CAPA_MASK(IWEVMICHAELMICFAILURE));
1098 /* encode extension (WPA) capability */
1099 range->enc_capa = (IW_ENC_CAPA_WPA |
1101 IW_ENC_CAPA_CIPHER_TKIP |
1102 IW_ENC_CAPA_CIPHER_CCMP);
1107 /*------------------------------------------------------------------*/
1108 /* Wireless Handler : set Power Management */
1109 static int ks_wlan_set_power(struct net_device *dev, struct iw_request_info *info,
1110 struct iw_param *vwrq, char *extra)
1112 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1115 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1117 enabled = vwrq->disabled ? 0 : 1;
1118 if(enabled == 0 ){ /* 0 */
1119 priv->reg.powermgt = POWMGT_ACTIVE_MODE;
1120 }else if(enabled){ /* 1 */
1121 if(priv->reg.operation_mode == MODE_INFRASTRUCTURE)
1122 priv->reg.powermgt = POWMGT_SAVE1_MODE;
1125 }else if(enabled){ /* 2 */
1126 if(priv->reg.operation_mode == MODE_INFRASTRUCTURE)
1127 priv->reg.powermgt = POWMGT_SAVE2_MODE;
1133 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
1138 /*------------------------------------------------------------------*/
1139 /* Wireless Handler : get Power Management */
1140 static int ks_wlan_get_power(struct net_device *dev, struct iw_request_info *info,
1141 struct iw_param *vwrq, char *extra)
1143 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1145 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1147 if(priv->reg.powermgt > 0)
1155 /*------------------------------------------------------------------*/
1156 /* Wireless Handler : get wirless statistics */
1157 static int ks_wlan_get_iwstats(struct net_device *dev, struct iw_request_info *info,
1158 struct iw_quality *vwrq, char *extra)
1160 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1162 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1164 vwrq->qual = 0; /* not supported */
1165 vwrq->level = priv->wstats.qual.level;
1166 vwrq->noise = 0; /* not supported */
1172 #ifndef KSC_OPNOTSUPP
1173 /*------------------------------------------------------------------*/
1174 /* Wireless Handler : set Sensitivity */
1175 static int ks_wlan_set_sens(struct net_device *dev, struct iw_request_info *info,
1176 struct iw_param *vwrq, char *extra)
1178 return -EOPNOTSUPP; /* Not Support */
1181 /*------------------------------------------------------------------*/
1182 /* Wireless Handler : get Sensitivity */
1183 static int ks_wlan_get_sens(struct net_device *dev, struct iw_request_info *info,
1184 struct iw_param *vwrq, char *extra)
1188 vwrq->disabled = (vwrq->value == 0);
1192 #endif /* KSC_OPNOTSUPP */
1195 /*------------------------------------------------------------------*/
1196 /* Wireless Handler : get AP List */
1197 /* Note : this is deprecated in favor of IWSCAN */
1198 static int ks_wlan_get_aplist(struct net_device *dev, struct iw_request_info *info,
1199 struct iw_point *dwrq, char *extra)
1201 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1202 struct sockaddr *address = (struct sockaddr *) extra;
1203 struct iw_quality qual[LOCAL_APLIST_MAX];
1207 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1209 for (i = 0; i < priv->aplist.size; i++) {
1210 memcpy(address[i].sa_data, &(priv->aplist.ap[i].bssid[0]), ETH_ALEN);
1211 address[i].sa_family = ARPHRD_ETHER;
1212 qual[i].level = 256 - priv->aplist.ap[i].rssi;
1213 qual[i].qual = priv->aplist.ap[i].sq;
1214 qual[i].noise = 0; /* invalid noise value */
1215 qual[i].updated = 7;
1218 dwrq->flags = 1; /* Should be define'd */
1219 memcpy(extra + sizeof(struct sockaddr)*i,
1220 &qual, sizeof(struct iw_quality)*i);
1227 /*------------------------------------------------------------------*/
1228 /* Wireless Handler : Initiate Scan */
1229 static int ks_wlan_set_scan(struct net_device *dev, struct iw_request_info *info,
1230 union iwreq_data *wrqu, char *extra)
1232 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1233 struct iw_scan_req *req = NULL;
1236 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1238 /* specified SSID SCAN */
1239 if(wrqu->data.length == sizeof(struct iw_scan_req) && wrqu->data.flags & IW_SCAN_THIS_ESSID){
1240 req = (struct iw_scan_req *) extra;
1241 priv->scan_ssid_len = req->essid_len;
1242 memcpy(priv->scan_ssid, req->essid, priv->scan_ssid_len);
1244 priv->scan_ssid_len = 0;
1248 priv->sme_i.sme_flag |= SME_AP_SCAN;
1249 hostif_sme_enqueue(priv, SME_BSS_SCAN_REQUEST);
1251 /* At this point, just return to the user. */
1256 /*------------------------------------------------------------------*/
1258 * Translate scan data returned from the card to a card independent
1259 * format that the Wireless Tools will understand - Jean II
1261 static inline char *ks_wlan_translate_scan(struct net_device *dev, struct iw_request_info *info, char *current_ev,
1262 char *end_buf, struct local_ap_t *ap)
1264 /* ks_wlan_private *priv = (ks_wlan_private *)dev->priv; */
1265 struct iw_event iwe; /* Temporary buffer */
1267 char *current_val; /* For rates */
1269 static const char rsn_leader[] = "rsn_ie=";
1270 static const char wpa_leader[] = "wpa_ie=";
1271 char buf0[RSN_IE_BODY_MAX*2 + 30];
1272 char buf1[RSN_IE_BODY_MAX*2 + 30];
1274 /* First entry *MUST* be the AP MAC address */
1275 iwe.cmd = SIOCGIWAP;
1276 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1277 memcpy(iwe.u.ap_addr.sa_data, ap->bssid, ETH_ALEN);
1278 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
1280 /* Other entries will be displayed in the order we give them */
1283 iwe.u.data.length = ap->ssid.size;
1284 if(iwe.u.data.length > 32)
1285 iwe.u.data.length = 32;
1286 iwe.cmd = SIOCGIWESSID;
1287 iwe.u.data.flags = 1;
1288 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, &(ap->ssid.body[0]));
1291 iwe.cmd = SIOCGIWMODE;
1292 capabilities = le16_to_cpu(ap->capability);
1293 if(capabilities & (BSS_CAP_ESS | BSS_CAP_IBSS)) {
1294 if(capabilities & BSS_CAP_ESS)
1295 iwe.u.mode = IW_MODE_INFRA;
1297 iwe.u.mode = IW_MODE_ADHOC;
1298 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
1302 iwe.cmd = SIOCGIWFREQ;
1303 iwe.u.freq.m = ap->channel;
1304 iwe.u.freq.m = frequency_list[iwe.u.freq.m-1] * 100000;
1306 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
1308 /* Add quality statistics */
1310 iwe.u.qual.level = 256 - ap->rssi;
1311 iwe.u.qual.qual = ap->sq;
1312 iwe.u.qual.noise = 0; /* invalid noise value */
1313 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
1315 /* Add encryption capability */
1316 iwe.cmd = SIOCGIWENCODE;
1317 if(capabilities & BSS_CAP_PRIVACY)
1318 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1320 iwe.u.data.flags = IW_ENCODE_DISABLED;
1321 iwe.u.data.length = 0;
1322 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, &(ap->ssid.body[0]));
1324 /* Rate : stuffing multiple values in a single event require a bit
1325 * more of magic - Jean II */
1326 current_val = current_ev + IW_EV_LCP_LEN;
1328 iwe.cmd = SIOCGIWRATE;
1329 /* Those two flags are ignored... */
1330 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
1333 for(i = 0 ; i < 16 ; i++) {
1334 /* NULL terminated */
1335 if(i >= ap->rate_set.size)
1337 /* Bit rate given in 500 kb/s units (+ 0x80) */
1338 iwe.u.bitrate.value = ((ap->rate_set.body[i] & 0x7f) * 500000);
1339 /* Add new value to event */
1340 current_val = iwe_stream_add_value(info, current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
1342 /* Check if we added any event */
1343 if((current_val - current_ev) > IW_EV_LCP_LEN)
1344 current_ev = current_val;
1346 #define GENERIC_INFO_ELEM_ID 0xdd
1347 #define RSN_INFO_ELEM_ID 0x30
1348 if (ap->rsn_ie.id == RSN_INFO_ELEM_ID && ap->rsn_ie.size != 0) {
1350 memset(&iwe, 0, sizeof(iwe));
1351 iwe.cmd = IWEVCUSTOM;
1352 memcpy(buf0,rsn_leader,sizeof(rsn_leader)-1);
1353 iwe.u.data.length += sizeof(rsn_leader)-1;
1354 pbuf += sizeof(rsn_leader)-1;
1356 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.id);
1357 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.size);
1358 iwe.u.data.length += 4;
1360 for (i = 0; i < ap->rsn_ie.size; i++)
1361 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.body[i]);
1362 iwe.u.data.length += (ap->rsn_ie.size)*2;
1364 DPRINTK(4,"ap->rsn.size=%d\n",ap->rsn_ie.size);
1366 current_ev = iwe_stream_add_point(info, current_ev, end_buf,&iwe, &buf0[0]);
1368 if (ap->wpa_ie.id == GENERIC_INFO_ELEM_ID && ap->wpa_ie.size != 0) {
1370 memset(&iwe, 0, sizeof(iwe));
1371 iwe.cmd = IWEVCUSTOM;
1372 memcpy(buf1,wpa_leader,sizeof(wpa_leader)-1);
1373 iwe.u.data.length += sizeof(wpa_leader)-1;
1374 pbuf += sizeof(wpa_leader)-1;
1376 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.id);
1377 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.size);
1378 iwe.u.data.length += 4;
1380 for (i = 0; i < ap->wpa_ie.size; i++)
1381 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.body[i]);
1382 iwe.u.data.length += (ap->wpa_ie.size)*2;
1384 DPRINTK(4,"ap->rsn.size=%d\n",ap->wpa_ie.size);
1385 DPRINTK(4,"iwe.u.data.length=%d\n",iwe.u.data.length);
1387 current_ev = iwe_stream_add_point(info, current_ev, end_buf,&iwe, &buf1[0]);
1390 /* The other data in the scan result are not really
1391 * interesting, so for now drop it - Jean II */
1395 /*------------------------------------------------------------------*/
1396 /* Wireless Handler : Read Scan Results */
1397 static int ks_wlan_get_scan(struct net_device *dev, struct iw_request_info *info,
1398 struct iw_point *dwrq, char *extra)
1400 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1402 char *current_ev = extra;
1405 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1407 if(priv->sme_i.sme_flag & SME_AP_SCAN) {
1408 DPRINTK(2,"flag AP_SCAN\n");
1412 if(priv->aplist.size == 0) {
1413 /* Client error, no scan results...
1414 * The caller need to restart the scan. */
1415 DPRINTK(2,"aplist 0\n");
1419 /* current connect ap */
1420 if((priv->connect_status & CONNECT_STATUS_MASK)== CONNECT_STATUS){
1421 if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) {
1425 current_ev = ks_wlan_translate_scan(dev, current_ev,
1426 // extra + IW_SCAN_MAX_DATA,
1427 extra + dwrq->length,
1428 &(priv->current_ap));
1431 /* Read and parse all entries */
1432 for(i=0; i < priv->aplist.size; i++) {
1433 if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) {
1437 /* Translate to WE format this entry */
1438 current_ev = ks_wlan_translate_scan(dev, info, current_ev,
1439 // extra + IW_SCAN_MAX_DATA,
1440 extra + dwrq->length,
1441 &(priv->aplist.ap[i]));
1443 /* Length of data */
1444 dwrq->length = (current_ev - extra);
1450 /*------------------------------------------------------------------*/
1451 /* Commit handler : called after a bunch of SET operations */
1452 static int ks_wlan_config_commit(struct net_device *dev, struct iw_request_info *info,
1453 void *zwrq, char *extra)
1455 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1457 if (!priv->need_commit)
1460 ks_wlan_setup_parameter(priv, priv->need_commit);
1461 priv->need_commit=0;
1465 /*------------------------------------------------------------------*/
1466 /* Wireless handler : set association ie params */
1467 static int ks_wlan_set_genie(struct net_device *dev, struct iw_request_info *info,
1468 struct iw_point *dwrq, char *extra)
1470 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1474 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1477 // return -EOPNOTSUPP;
1480 /*------------------------------------------------------------------*/
1481 /* Wireless handler : set authentication mode params */
1482 static int ks_wlan_set_auth_mode(struct net_device *dev, struct iw_request_info *info,
1483 struct iw_param *vwrq, char *extra)
1485 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1486 int index = (vwrq->flags & IW_AUTH_INDEX);
1487 int value = vwrq->value;
1489 DPRINTK(2,"index=%d:value=%08X\n",index,value);
1491 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1494 case IW_AUTH_WPA_VERSION: /* 0 */
1496 case IW_AUTH_WPA_VERSION_DISABLED:
1497 priv->wpa.version = value;
1498 if(priv->wpa.rsn_enabled){
1499 priv->wpa.rsn_enabled = 0;
1501 priv->need_commit |= SME_RSN;
1503 case IW_AUTH_WPA_VERSION_WPA:
1504 case IW_AUTH_WPA_VERSION_WPA2:
1505 priv->wpa.version = value;
1506 if(!(priv->wpa.rsn_enabled)){
1507 priv->wpa.rsn_enabled = 1;
1509 priv->need_commit |= SME_RSN;
1515 case IW_AUTH_CIPHER_PAIRWISE: /* 1 */
1517 case IW_AUTH_CIPHER_NONE:
1518 if(priv->reg.privacy_invoked){
1519 priv->reg.privacy_invoked = 0x00;
1520 priv->need_commit |= SME_WEP_FLAG;
1523 case IW_AUTH_CIPHER_WEP40:
1524 case IW_AUTH_CIPHER_TKIP:
1525 case IW_AUTH_CIPHER_CCMP:
1526 case IW_AUTH_CIPHER_WEP104:
1527 if(!priv->reg.privacy_invoked){
1528 priv->reg.privacy_invoked = 0x01;
1529 priv->need_commit |= SME_WEP_FLAG;
1531 priv->wpa.pairwise_suite = value;
1532 priv->need_commit |= SME_RSN_UNICAST;
1538 case IW_AUTH_CIPHER_GROUP: /* 2 */
1540 case IW_AUTH_CIPHER_NONE:
1541 if(priv->reg.privacy_invoked){
1542 priv->reg.privacy_invoked = 0x00;
1543 priv->need_commit |= SME_WEP_FLAG;
1546 case IW_AUTH_CIPHER_WEP40:
1547 case IW_AUTH_CIPHER_TKIP:
1548 case IW_AUTH_CIPHER_CCMP:
1549 case IW_AUTH_CIPHER_WEP104:
1550 if(!priv->reg.privacy_invoked){
1551 priv->reg.privacy_invoked = 0x01;
1552 priv->need_commit |= SME_WEP_FLAG;
1554 priv->wpa.group_suite = value;
1555 priv->need_commit |= SME_RSN_MULTICAST;
1561 case IW_AUTH_KEY_MGMT: /* 3 */
1563 case IW_AUTH_KEY_MGMT_802_1X:
1564 case IW_AUTH_KEY_MGMT_PSK:
1565 case 0: /* NONE or 802_1X_NO_WPA */
1566 case 4: /* WPA_NONE */
1567 priv->wpa.key_mgmt_suite = value;
1568 priv->need_commit |= SME_RSN_AUTH;
1574 case IW_AUTH_80211_AUTH_ALG: /* 6 */
1576 case IW_AUTH_ALG_OPEN_SYSTEM:
1577 priv->wpa.auth_alg = value;
1578 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
1580 case IW_AUTH_ALG_SHARED_KEY:
1581 priv->wpa.auth_alg = value;
1582 priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
1584 case IW_AUTH_ALG_LEAP:
1588 priv->need_commit |= SME_MODE_SET;
1590 case IW_AUTH_WPA_ENABLED: /* 7 */
1591 priv->wpa.wpa_enabled = value;
1593 case IW_AUTH_PRIVACY_INVOKED: /* 10 */
1594 if((value && !priv->reg.privacy_invoked)||
1595 (!value && priv->reg.privacy_invoked)){
1596 priv->reg.privacy_invoked = value?0x01:0x00;
1597 priv->need_commit |= SME_WEP_FLAG;
1600 case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* 4 */
1601 case IW_AUTH_TKIP_COUNTERMEASURES: /* 5 */
1602 case IW_AUTH_DROP_UNENCRYPTED: /* 8 */
1603 case IW_AUTH_ROAMING_CONTROL: /* 9 */
1608 /* return -EINPROGRESS; */
1609 if(priv->need_commit){
1610 ks_wlan_setup_parameter(priv, priv->need_commit);
1611 priv->need_commit=0;
1616 /*------------------------------------------------------------------*/
1617 /* Wireless handler : get authentication mode params */
1618 static int ks_wlan_get_auth_mode(struct net_device *dev, struct iw_request_info *info,
1619 struct iw_param *vwrq, char *extra)
1621 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1622 int index = (vwrq->flags & IW_AUTH_INDEX);
1623 DPRINTK(2,"index=%d\n",index);
1625 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1627 /* WPA (not used ?? wpa_supplicant) */
1629 case IW_AUTH_WPA_VERSION:
1630 vwrq->value = priv->wpa.version;
1632 case IW_AUTH_CIPHER_PAIRWISE:
1633 vwrq->value = priv->wpa.pairwise_suite;
1635 case IW_AUTH_CIPHER_GROUP:
1636 vwrq->value = priv->wpa.group_suite;
1638 case IW_AUTH_KEY_MGMT:
1639 vwrq->value = priv->wpa.key_mgmt_suite;
1641 case IW_AUTH_80211_AUTH_ALG:
1642 vwrq->value = priv->wpa.auth_alg;
1644 case IW_AUTH_WPA_ENABLED:
1645 vwrq->value = priv->wpa.rsn_enabled;
1647 case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* OK??? */
1648 case IW_AUTH_TKIP_COUNTERMEASURES:
1649 case IW_AUTH_DROP_UNENCRYPTED:
1651 /* return -EOPNOTSUPP; */
1657 /*------------------------------------------------------------------*/
1658 /* Wireless Handler : set encoding token & mode (WPA)*/
1659 static int ks_wlan_set_encode_ext(struct net_device *dev, struct iw_request_info *info,
1660 struct iw_point *dwrq, char *extra)
1662 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1663 struct iw_encode_ext *enc;
1664 int index = dwrq->flags & IW_ENCODE_INDEX;
1665 unsigned int commit=0;
1667 enc = (struct iw_encode_ext *)extra;
1669 DPRINTK(2,"flags=%04X:: ext_flags=%08X\n",dwrq->flags, enc->ext_flags);
1671 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1673 if(index<1||index>4)
1678 if(dwrq->flags & IW_ENCODE_DISABLED){
1679 priv->wpa.key[index].key_len=0;
1683 priv->wpa.key[index].ext_flags=enc->ext_flags;
1684 if(enc->ext_flags&IW_ENCODE_EXT_SET_TX_KEY){
1685 priv->wpa.txkey=index;
1686 commit |= SME_WEP_INDEX;
1687 }else if(enc->ext_flags&IW_ENCODE_EXT_RX_SEQ_VALID){
1689 memcpy(&priv->wpa.key[index].rx_seq[0],
1690 enc->rx_seq, IW_ENCODE_SEQ_MAX_SIZE);
1695 memcpy(&priv->wpa.key[index].addr.sa_data[0],
1696 &enc->addr.sa_data[0], ETH_ALEN);
1699 case IW_ENCODE_ALG_NONE:
1700 if(priv->reg.privacy_invoked){
1701 priv->reg.privacy_invoked = 0x00;
1702 commit |= SME_WEP_FLAG;
1704 priv->wpa.key[index].key_len = 0;
1707 case IW_ENCODE_ALG_WEP:
1708 case IW_ENCODE_ALG_CCMP:
1709 if(!priv->reg.privacy_invoked){
1710 priv->reg.privacy_invoked = 0x01;
1711 commit |= SME_WEP_FLAG;
1713 if(enc->key && enc->key_len){
1714 memcpy(&priv->wpa.key[index].key_val[0],
1715 &enc->key[0], enc->key_len);
1716 priv->wpa.key[index].key_len = enc->key_len;
1717 commit |= (SME_WEP_VAL1 << index);
1720 case IW_ENCODE_ALG_TKIP:
1721 if(!priv->reg.privacy_invoked){
1722 priv->reg.privacy_invoked = 0x01;
1723 commit |= SME_WEP_FLAG;
1725 if(enc->key && enc->key_len == 32){
1726 memcpy(&priv->wpa.key[index].key_val[0],
1727 &enc->key[0], enc->key_len-16);
1728 priv->wpa.key[index].key_len = enc->key_len-16;
1729 if(priv->wpa.key_mgmt_suite==4){ /* WPA_NONE */
1730 memcpy(&priv->wpa.key[index].tx_mic_key[0],
1732 memcpy(&priv->wpa.key[index].rx_mic_key[0],
1735 memcpy(&priv->wpa.key[index].tx_mic_key[0],
1737 memcpy(&priv->wpa.key[index].rx_mic_key[0],
1740 commit |= (SME_WEP_VAL1 << index);
1746 priv->wpa.key[index].alg=enc->alg;
1752 if(commit&SME_WEP_INDEX)
1753 hostif_sme_enqueue(priv, SME_SET_TXKEY);
1754 if(commit&SME_WEP_VAL_MASK)
1755 hostif_sme_enqueue(priv, SME_SET_KEY1+index);
1756 if(commit&SME_WEP_FLAG)
1757 hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
1763 /*------------------------------------------------------------------*/
1764 /* Wireless Handler : get encoding token & mode (WPA)*/
1765 static int ks_wlan_get_encode_ext(struct net_device *dev, struct iw_request_info *info,
1766 struct iw_point *dwrq, char *extra)
1768 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1770 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1772 /* WPA (not used ?? wpa_supplicant)
1773 ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
1774 struct iw_encode_ext *enc;
1775 enc = (struct iw_encode_ext *)extra;
1776 int index = dwrq->flags & IW_ENCODE_INDEX;
1777 WPA (not used ?? wpa_supplicant) */
1781 /*------------------------------------------------------------------*/
1782 /* Wireless Handler : PMKSA cache operation (WPA2) */
1783 static int ks_wlan_set_pmksa(struct net_device *dev, struct iw_request_info *info,
1784 struct iw_point *dwrq, char *extra)
1786 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1787 struct iw_pmksa *pmksa ;
1790 struct list_head *ptr;
1794 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1799 pmksa = (struct iw_pmksa *)extra;
1800 DPRINTK(2,"cmd=%d\n",pmksa->cmd);
1804 if(list_empty(&priv->pmklist.head)){ /* new list */
1805 for(i=0;i<PMK_LIST_MAX;i++){
1806 pmk = &priv->pmklist.pmk[i];
1807 if(!memcmp("\x00\x00\x00\x00\x00\x00",pmk->bssid,ETH_ALEN))
1810 memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
1811 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1812 list_add(&pmk->list,&priv->pmklist.head);
1813 priv->pmklist.size++;
1815 else { /* search cache data */
1816 list_for_each(ptr, &priv->pmklist.head){
1817 pmk = list_entry(ptr, struct pmk_t, list);
1818 if(!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)){ /* match address! list move to head. */
1819 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1820 list_move(&pmk->list, &priv->pmklist.head);
1824 if(ptr == &priv->pmklist.head){ /* not find address. */
1825 if(PMK_LIST_MAX > priv->pmklist.size){ /* new cache data */
1826 for(i=0;i<PMK_LIST_MAX;i++){
1827 pmk = &priv->pmklist.pmk[i];
1828 if(!memcmp("\x00\x00\x00\x00\x00\x00",pmk->bssid,ETH_ALEN))
1831 memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
1832 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1833 list_add(&pmk->list,&priv->pmklist.head);
1834 priv->pmklist.size++;
1836 else{ /* overwrite old cache data */
1837 pmk = list_entry(priv->pmklist.head.prev, struct pmk_t, list);
1838 memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
1839 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1840 list_move(&pmk->list,&priv->pmklist.head);
1845 case IW_PMKSA_REMOVE:
1846 if(list_empty(&priv->pmklist.head)){ /* list empty */
1849 else{ /* search cache data */
1850 list_for_each(ptr, &priv->pmklist.head){
1851 pmk = list_entry(ptr, struct pmk_t, list);
1852 if(!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)){ /* match address! list del. */
1853 memset(pmk->bssid, 0, ETH_ALEN);
1854 memset(pmk->pmkid, 0, IW_PMKID_LEN);
1855 list_del_init(&pmk->list);
1859 if(ptr == &priv->pmklist.head){ /* not find address. */
1864 case IW_PMKSA_FLUSH:
1865 memset(&(priv->pmklist), 0, sizeof(priv->pmklist));
1866 INIT_LIST_HEAD(&priv->pmklist.head);
1867 for(i=0;i<PMK_LIST_MAX;i++)
1868 INIT_LIST_HEAD(&priv->pmklist.pmk[i].list);
1874 hostif_sme_enqueue(priv, SME_SET_PMKSA);
1878 static struct iw_statistics *ks_get_wireless_stats(struct net_device *dev)
1881 ks_wlan_private *priv = (ks_wlan_private *) netdev_priv(dev);
1882 struct iw_statistics *wstats = &priv->wstats;
1884 if(!atomic_read(&update_phyinfo)){
1885 if (priv->dev_state < DEVICE_STATE_READY)
1886 return NULL; /* not finished initialize */
1891 /* Packets discarded in the wireless adapter due to wireless
1892 * specific problems */
1893 wstats->discard.nwid = 0; /* Rx invalid nwid */
1894 wstats->discard.code = 0; /* Rx invalid crypt */
1895 wstats->discard.fragment = 0; /* Rx invalid frag */
1896 wstats->discard.retries = 0; /* Tx excessive retries */
1897 wstats->discard.misc = 0; /* Invalid misc */
1898 wstats->miss.beacon = 0; /* Missed beacon */
1903 /*------------------------------------------------------------------*/
1904 /* Private handler : set stop request */
1905 static int ks_wlan_set_stop_request(struct net_device *dev, struct iw_request_info *info,
1906 __u32 *uwrq, char *extra)
1908 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1911 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1916 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
1920 /*------------------------------------------------------------------*/
1921 /* Wireless Handler : set MLME */
1922 #include <linux/ieee80211.h>
1923 static int ks_wlan_set_mlme(struct net_device *dev, struct iw_request_info *info,
1924 struct iw_point *dwrq, char *extra)
1926 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1927 struct iw_mlme *mlme = (struct iw_mlme *)extra;
1930 DPRINTK(2, ":%d :%d\n", mlme->cmd, mlme->reason_code);
1932 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1934 switch (mlme->cmd) {
1935 case IW_MLME_DEAUTH:
1936 if (mlme->reason_code == WLAN_REASON_MIC_FAILURE) {
1939 case IW_MLME_DISASSOC:
1941 return ks_wlan_set_stop_request(dev, NULL, &mode, NULL);
1943 return -EOPNOTSUPP; /* Not Support */
1947 /*------------------------------------------------------------------*/
1948 /* Private handler : get driver version */
1949 static int ks_wlan_get_driver_version(struct net_device *dev, struct iw_request_info *info,
1950 struct iw_point *dwrq, char *extra)
1952 strcpy(extra, KS_WLAN_DRIVER_VERSION_INFO);
1953 dwrq->length = strlen(KS_WLAN_DRIVER_VERSION_INFO)+1;
1957 /*------------------------------------------------------------------*/
1958 /* Private handler : get firemware version */
1959 static int ks_wlan_get_firmware_version(struct net_device *dev, struct iw_request_info *info,
1960 struct iw_point *dwrq, char *extra)
1962 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1963 strcpy(extra, &(priv->firmware_version[0]));
1964 dwrq->length = priv->version_size+1;
1969 /*------------------------------------------------------------------*/
1970 /* Private handler : set force disconnect status */
1971 static int ks_wlan_set_detach(struct net_device *dev, struct iw_request_info *info,
1972 __u32 *uwrq, char *extra)
1974 ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
1976 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1978 if(*uwrq == CONNECT_STATUS){ /* 0 */
1979 priv->connect_status &= ~FORCE_DISCONNECT;
1980 if((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS)
1981 netif_carrier_on(dev);
1982 }else if(*uwrq == DISCONNECT_STATUS){ /* 1 */
1983 priv->connect_status |= FORCE_DISCONNECT;
1984 netif_carrier_off(dev);
1990 /*------------------------------------------------------------------*/
1991 /* Private handler : get force disconnect status */
1992 static int ks_wlan_get_detach(struct net_device *dev, struct iw_request_info *info,
1993 __u32 *uwrq, char *extra)
1995 ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
1997 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
1999 *uwrq = ((priv->connect_status & FORCE_DISCONNECT) ? 1 : 0 );
2003 /*------------------------------------------------------------------*/
2004 /* Private handler : get connect status */
2005 static int ks_wlan_get_connect(struct net_device *dev, struct iw_request_info *info,
2006 __u32 *uwrq, char *extra)
2008 ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2010 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2012 *uwrq = (priv->connect_status & CONNECT_STATUS_MASK);
2017 /*------------------------------------------------------------------*/
2018 /* Private handler : set preamble */
2019 static int ks_wlan_set_preamble(struct net_device *dev, struct iw_request_info *info,
2020 __u32 *uwrq, char *extra)
2022 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2024 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2026 if(*uwrq == LONG_PREAMBLE){ /* 0 */
2027 priv->reg.preamble = LONG_PREAMBLE;
2028 }else if(*uwrq == SHORT_PREAMBLE){ /* 1 */
2029 priv->reg.preamble = SHORT_PREAMBLE;
2033 priv->need_commit |= SME_MODE_SET;
2034 return -EINPROGRESS; /* Call commit handler */
2038 /*------------------------------------------------------------------*/
2039 /* Private handler : get preamble */
2040 static int ks_wlan_get_preamble(struct net_device *dev, struct iw_request_info *info,
2041 __u32 *uwrq, char *extra)
2043 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2045 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2047 *uwrq = priv->reg.preamble;
2051 /*------------------------------------------------------------------*/
2052 /* Private handler : set power save mode */
2053 static int ks_wlan_set_powermgt(struct net_device *dev, struct iw_request_info *info,
2054 __u32 *uwrq, char *extra)
2056 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2058 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2060 if(*uwrq == POWMGT_ACTIVE_MODE){ /* 0 */
2061 priv->reg.powermgt = POWMGT_ACTIVE_MODE;
2062 }else if(*uwrq == POWMGT_SAVE1_MODE){ /* 1 */
2063 if(priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2064 priv->reg.powermgt = POWMGT_SAVE1_MODE;
2067 }else if(*uwrq == POWMGT_SAVE2_MODE){ /* 2 */
2068 if(priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2069 priv->reg.powermgt = POWMGT_SAVE2_MODE;
2075 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
2080 /*------------------------------------------------------------------*/
2081 /* Private handler : get power save made */
2082 static int ks_wlan_get_powermgt(struct net_device *dev, struct iw_request_info *info,
2083 __u32 *uwrq, char *extra)
2085 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2087 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2089 *uwrq = priv->reg.powermgt;
2093 /*------------------------------------------------------------------*/
2094 /* Private handler : set scan type */
2095 static int ks_wlan_set_scan_type(struct net_device *dev, struct iw_request_info *info,
2096 __u32 *uwrq, char *extra)
2098 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2100 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2102 if(*uwrq == ACTIVE_SCAN){ /* 0 */
2103 priv->reg.scan_type = ACTIVE_SCAN;
2104 }else if(*uwrq == PASSIVE_SCAN){ /* 1 */
2105 priv->reg.scan_type = PASSIVE_SCAN;
2112 /*------------------------------------------------------------------*/
2113 /* Private handler : get scan type */
2114 static int ks_wlan_get_scan_type(struct net_device *dev, struct iw_request_info *info,
2115 __u32 *uwrq, char *extra)
2117 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2119 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2121 *uwrq = priv->reg.scan_type;
2125 /*------------------------------------------------------------------*/
2126 /* Private handler : write raw data to device */
2127 static int ks_wlan_data_write(struct net_device *dev, struct iw_request_info *info,
2128 struct iw_point *dwrq, char *extra)
2130 ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2131 unsigned char *wbuff = NULL;
2133 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2135 wbuff = (unsigned char *)kmalloc(dwrq->length, GFP_ATOMIC);
2138 memcpy(wbuff, extra, dwrq->length);
2140 /* write to device */
2141 ks_wlan_hw_tx( priv, wbuff, dwrq->length, NULL, NULL, NULL);
2146 /*------------------------------------------------------------------*/
2147 /* Private handler : read raw data form device */
2148 static int ks_wlan_data_read(struct net_device *dev, struct iw_request_info *info,
2149 struct iw_point *dwrq, char *extra)
2151 ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2152 unsigned short read_length;
2154 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2156 if(!atomic_read(&priv->event_count)){
2157 if (priv->dev_state < DEVICE_STATE_BOOT) { /* Remove device */
2159 memset(extra,0xff,read_length);
2160 dwrq->length = read_length;
2169 if(atomic_read(&priv->event_count)>0)
2170 atomic_dec(&priv->event_count);
2172 spin_lock(&priv->dev_read_lock); /* request spin lock */
2174 /* Copy length max size 0x07ff */
2175 if(priv->dev_size[priv->dev_count] > 2047)
2178 read_length = priv->dev_size[priv->dev_count];
2181 memcpy(extra, &(priv->dev_data[priv->dev_count][0]), read_length);
2183 spin_unlock(&priv->dev_read_lock); /* release spin lock */
2186 priv->dev_data[priv->dev_count] = 0;
2187 priv->dev_size[priv->dev_count] = 0;
2190 if(priv->dev_count == DEVICE_STOCK_COUNT)
2194 dwrq->length = read_length;
2201 /*------------------------------------------------------------------*/
2202 /* Private handler : get wep string */
2203 #define WEP_ASCII_BUFF_SIZE (17+64*4+1)
2204 static int ks_wlan_get_wep_ascii(struct net_device *dev, struct iw_request_info *info,
2205 struct iw_point *dwrq, char *extra)
2207 ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2209 char tmp[WEP_ASCII_BUFF_SIZE];
2211 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2213 strcpy(tmp," WEP keys ASCII \n");
2214 len+=strlen(" WEP keys ASCII \n");
2217 strcpy(tmp+len,"\t[");
2221 strcpy(tmp+len,"] ");
2223 if(priv->reg.wep_key[i].size){
2224 strcpy(tmp+len,(priv->reg.wep_key[i].size < 6 ? "(40bits) [" : "(104bits) ["));
2225 len+=strlen((priv->reg.wep_key[i].size < 6 ? "(40bits) [" : "(104bits) ["));
2226 for(j=0;j<priv->reg.wep_key[i].size;j++,len++)
2227 tmp[len]=(isprint(priv->reg.wep_key[i].val[j]) ? priv->reg.wep_key[i].val[j] : ' ');
2229 strcpy(tmp+len,"]\n");
2233 strcpy(tmp+len,"off\n");
2234 len+=strlen("off\n");
2238 memcpy(extra, tmp, len);
2239 dwrq->length = len+1;
2244 /*------------------------------------------------------------------*/
2245 /* Private handler : set beacon lost count */
2246 static int ks_wlan_set_beacon_lost(struct net_device *dev, struct iw_request_info *info,
2247 __u32 *uwrq, char *extra)
2249 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2251 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2253 if(*uwrq >= BEACON_LOST_COUNT_MIN &&
2254 *uwrq <= BEACON_LOST_COUNT_MAX){
2255 priv->reg.beacon_lost_count = *uwrq;
2259 if(priv->reg.operation_mode == MODE_INFRASTRUCTURE){
2260 priv->need_commit |= SME_MODE_SET;
2261 return -EINPROGRESS; /* Call commit handler */
2267 /*------------------------------------------------------------------*/
2268 /* Private handler : get beacon lost count */
2269 static int ks_wlan_get_beacon_lost(struct net_device *dev, struct iw_request_info *info,
2270 __u32 *uwrq, char *extra)
2272 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2274 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2276 *uwrq = priv->reg.beacon_lost_count;
2280 /*------------------------------------------------------------------*/
2281 /* Private handler : set phy type */
2282 static int ks_wlan_set_phy_type(struct net_device *dev, struct iw_request_info *info,
2283 __u32 *uwrq, char *extra)
2285 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2287 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2289 if(*uwrq == D_11B_ONLY_MODE){ /* 0 */
2290 priv->reg.phy_type = D_11B_ONLY_MODE;
2291 }else if(*uwrq == D_11G_ONLY_MODE){ /* 1 */
2292 priv->reg.phy_type = D_11G_ONLY_MODE;
2293 }else if(*uwrq == D_11BG_COMPATIBLE_MODE){ /* 2 */
2294 priv->reg.phy_type = D_11BG_COMPATIBLE_MODE;
2298 priv->need_commit |= SME_MODE_SET;
2299 return -EINPROGRESS; /* Call commit handler */
2302 /*------------------------------------------------------------------*/
2303 /* Private handler : get phy type */
2304 static int ks_wlan_get_phy_type(struct net_device *dev, struct iw_request_info *info,
2305 __u32 *uwrq, char *extra)
2307 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2309 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2311 *uwrq = priv->reg.phy_type;
2315 /*------------------------------------------------------------------*/
2316 /* Private handler : set cts mode */
2317 static int ks_wlan_set_cts_mode(struct net_device *dev, struct iw_request_info *info,
2318 __u32 *uwrq, char *extra)
2320 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2322 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2324 if(*uwrq == CTS_MODE_FALSE){ /* 0 */
2325 priv->reg.cts_mode = CTS_MODE_FALSE;
2326 }else if(*uwrq == CTS_MODE_TRUE){ /* 1 */
2327 if(priv->reg.phy_type == D_11G_ONLY_MODE ||
2328 priv->reg.phy_type == D_11BG_COMPATIBLE_MODE)
2329 priv->reg.cts_mode = CTS_MODE_TRUE;
2331 priv->reg.cts_mode = CTS_MODE_FALSE;
2335 priv->need_commit |= SME_MODE_SET;
2336 return -EINPROGRESS; /* Call commit handler */
2339 /*------------------------------------------------------------------*/
2340 /* Private handler : get cts mode */
2341 static int ks_wlan_get_cts_mode(struct net_device *dev, struct iw_request_info *info,
2342 __u32 *uwrq, char *extra)
2344 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2346 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2348 *uwrq = priv->reg.cts_mode;
2352 /*------------------------------------------------------------------*/
2353 /* Private handler : set sleep mode */
2354 static int ks_wlan_set_sleep_mode(struct net_device *dev,
2355 struct iw_request_info *info,
2356 __u32 *uwrq, char *extra)
2358 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2362 if(*uwrq == SLP_SLEEP){
2363 priv->sleep_mode = *uwrq;
2364 printk("SET_SLEEP_MODE %d\n", priv->sleep_mode);
2366 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2367 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2369 }else if(*uwrq == SLP_ACTIVE) {
2370 priv->sleep_mode = *uwrq;
2371 printk("SET_SLEEP_MODE %d\n", priv->sleep_mode);
2372 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2374 printk("SET_SLEEP_MODE %d errror\n", *uwrq);
2380 /*------------------------------------------------------------------*/
2381 /* Private handler : get sleep mode */
2382 static int ks_wlan_get_sleep_mode(struct net_device *dev,
2383 struct iw_request_info *info,
2384 __u32 *uwrq, char *extra)
2386 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2388 DPRINTK(2, "GET_SLEEP_MODE %d\n", priv->sleep_mode);
2389 *uwrq = priv->sleep_mode;
2395 /*------------------------------------------------------------------*/
2396 /* Private handler : set phy information timer */
2397 static int ks_wlan_set_phy_information_timer(struct net_device *dev, struct iw_request_info *info,
2398 __u32 *uwrq, char *extra)
2400 ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2402 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2404 if(*uwrq >= 0 && *uwrq <= 0xFFFF) /* 0-65535 */
2405 priv->reg.phy_info_timer = (uint16_t)*uwrq;
2409 hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST);
2414 /*------------------------------------------------------------------*/
2415 /* Private handler : get phy information timer */
2416 static int ks_wlan_get_phy_information_timer(struct net_device *dev, struct iw_request_info *info,
2417 __u32 *uwrq, char *extra)
2419 ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2421 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2423 *uwrq = priv->reg.phy_info_timer;
2429 /*------------------------------------------------------------------*/
2430 /* Private handler : set WPS enable */
2431 static int ks_wlan_set_wps_enable(struct net_device *dev, struct iw_request_info *info,
2432 __u32 *uwrq, char *extra)
2434 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2437 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2439 if(*uwrq == 0 || *uwrq == 1)
2440 priv->wps.wps_enabled = *uwrq;
2444 hostif_sme_enqueue(priv, SME_WPS_ENABLE_REQUEST);
2448 /*------------------------------------------------------------------*/
2449 /* Private handler : get WPS enable */
2450 static int ks_wlan_get_wps_enable(struct net_device *dev, struct iw_request_info *info,
2451 __u32 *uwrq, char *extra)
2453 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2456 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2458 *uwrq = priv->wps.wps_enabled;
2459 printk("return=%d\n", *uwrq);
2463 /*------------------------------------------------------------------*/
2464 /* Private handler : set WPS probe req */
2465 static int ks_wlan_set_wps_probe_req(struct net_device *dev,
2466 struct iw_request_info *info,
2467 struct iw_point *dwrq, char *extra)
2471 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2475 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2477 DPRINTK(2,"dwrq->length=%d\n", dwrq->length);
2480 if(p[1] + 2 != dwrq->length || dwrq->length > 256 ){
2484 priv->wps.ielen = p[1] + 2 + 1; /* IE header + IE + sizeof(len) */
2485 len = p[1] + 2; /* IE header + IE */
2487 memcpy(priv->wps.ie, &len, sizeof(len));
2488 p = memcpy(priv->wps.ie+1, p, len);
2490 DPRINTK(2,"%d(%#x): %02X %02X %02X %02X ... %02X %02X %02X\n",
2491 priv->wps.ielen, priv->wps.ielen, p[0], p[1], p[2], p[3],
2492 p[priv->wps.ielen-3], p[priv->wps.ielen-2], p[priv->wps.ielen-1]);
2494 hostif_sme_enqueue(priv, SME_WPS_PROBE_REQUEST);
2499 /*------------------------------------------------------------------*/
2500 /* Private handler : get WPS probe req */
2501 static int ks_wlan_get_wps_probe_req(struct net_device *dev,
2502 struct iw_request_info *info,
2503 __u32 *uwrq, char *extra)
2505 ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2508 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2515 /*------------------------------------------------------------------*/
2516 /* Private handler : set tx gain control value */
2517 static int ks_wlan_set_tx_gain(struct net_device *dev, struct iw_request_info *info,
2518 __u32 *uwrq, char *extra)
2520 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2522 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2524 if(*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2525 priv->gain.TxGain = (uint8_t)*uwrq;
2529 if(priv->gain.TxGain < 0xFF)
2530 priv->gain.TxMode = 1;
2532 priv->gain.TxMode = 0;
2535 hostif_sme_enqueue(priv, SME_SET_GAIN);
2539 /*------------------------------------------------------------------*/
2540 /* Private handler : get tx gain control value */
2541 static int ks_wlan_get_tx_gain(struct net_device *dev, struct iw_request_info *info,
2542 __u32 *uwrq, char *extra)
2544 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2546 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2548 *uwrq = priv->gain.TxGain;
2549 hostif_sme_enqueue(priv, SME_GET_GAIN);
2553 /*------------------------------------------------------------------*/
2554 /* Private handler : set rx gain control value */
2555 static int ks_wlan_set_rx_gain(struct net_device *dev, struct iw_request_info *info,
2556 __u32 *uwrq, char *extra)
2558 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2560 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2562 if(*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2563 priv->gain.RxGain = (uint8_t)*uwrq;
2567 if(priv->gain.RxGain < 0xFF)
2568 priv->gain.RxMode = 1;
2570 priv->gain.RxMode = 0;
2572 hostif_sme_enqueue(priv, SME_SET_GAIN);
2576 /*------------------------------------------------------------------*/
2577 /* Private handler : get rx gain control value */
2578 static int ks_wlan_get_rx_gain(struct net_device *dev, struct iw_request_info *info,
2579 __u32 *uwrq, char *extra)
2581 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2583 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2585 *uwrq = priv->gain.RxGain;
2586 hostif_sme_enqueue(priv, SME_GET_GAIN);
2590 /*------------------------------------------------------------------*/
2591 /* Private handler : set region value */
2592 static int ks_wlan_set_region(struct net_device *dev, struct iw_request_info *info,
2593 __u32 *uwrq, char *extra)
2595 ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2597 if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
2599 if(*uwrq >= 0x9 && *uwrq <= 0xF) /* 0x9-0xf */
2600 priv->region = (uint8_t)*uwrq;
2604 hostif_sme_enqueue(priv, SME_SET_REGION);
2609 /*------------------------------------------------------------------*/
2610 /* Private handler : get eeprom checksum result */
2611 static int ks_wlan_get_eeprom_cksum(struct net_device *dev, struct iw_request_info *info,
2612 __u32 *uwrq, char *extra)
2614 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2616 *uwrq = priv->eeprom_checksum;
2620 static void print_hif_event(int event){
2624 printk("HIF_DATA_REQ\n");
2627 printk("HIF_DATA_IND\n");
2629 case HIF_MIB_GET_REQ :
2630 printk("HIF_MIB_GET_REQ\n");
2632 case HIF_MIB_GET_CONF :
2633 printk("HIF_MIB_GET_CONF\n");
2635 case HIF_MIB_SET_REQ :
2636 printk("HIF_MIB_SET_REQ\n");
2638 case HIF_MIB_SET_CONF :
2639 printk("HIF_MIB_SET_CONF\n");
2641 case HIF_POWERMGT_REQ :
2642 printk("HIF_POWERMGT_REQ\n");
2644 case HIF_POWERMGT_CONF :
2645 printk("HIF_POWERMGT_CONF\n");
2647 case HIF_START_REQ :
2648 printk("HIF_START_REQ\n");
2650 case HIF_START_CONF :
2651 printk("HIF_START_CONF\n");
2653 case HIF_CONNECT_IND :
2654 printk("HIF_CONNECT_IND\n");
2657 printk("HIF_STOP_REQ\n");
2659 case HIF_STOP_CONF :
2660 printk("HIF_STOP_CONF\n");
2662 case HIF_PS_ADH_SET_REQ :
2663 printk("HIF_PS_ADH_SET_REQ\n");
2665 case HIF_PS_ADH_SET_CONF:
2666 printk("HIF_PS_ADH_SET_CONF\n");
2668 case HIF_INFRA_SET_REQ :
2669 printk("HIF_INFRA_SET_REQ\n");
2671 case HIF_INFRA_SET_CONF :
2672 printk("HIF_INFRA_SET_CONF\n");
2674 case HIF_ADH_SET_REQ :
2675 printk("HIF_ADH_SET_REQ\n");
2677 case HIF_ADH_SET_CONF :
2678 printk("HIF_ADH_SET_CONF\n");
2680 case HIF_AP_SET_REQ :
2681 printk("HIF_AP_SET_REQ\n");
2683 case HIF_AP_SET_CONF :
2684 printk("HIF_AP_SET_CONF\n");
2686 case HIF_ASSOC_INFO_IND :
2687 printk("HIF_ASSOC_INFO_IND\n");
2689 case HIF_MIC_FAILURE_REQ:
2690 printk("HIF_MIC_FAILURE_REQ\n");
2692 case HIF_MIC_FAILURE_CONF :
2693 printk("HIF_MIC_FAILURE_CONF\n");
2696 printk("HIF_SCAN_REQ\n");
2698 case HIF_SCAN_CONF :
2699 printk("HIF_SCAN_CONF\n");
2701 case HIF_PHY_INFO_REQ :
2702 printk("HIF_PHY_INFO_REQ\n");
2704 case HIF_PHY_INFO_CONF :
2705 printk("HIF_PHY_INFO_CONF\n");
2707 case HIF_SLEEP_REQ :
2708 printk("HIF_SLEEP_REQ\n");
2710 case HIF_SLEEP_CONF :
2711 printk("HIF_SLEEP_CONF\n");
2713 case HIF_PHY_INFO_IND :
2714 printk("HIF_PHY_INFO_IND\n");
2717 printk("HIF_SCAN_IND\n");
2719 case HIF_INFRA_SET2_REQ :
2720 printk("HIF_INFRA_SET2_REQ\n");
2722 case HIF_INFRA_SET2_CONF:
2723 printk("HIF_INFRA_SET2_CONF\n");
2725 case HIF_ADH_SET2_REQ :
2726 printk("HIF_ADH_SET2_REQ\n");
2728 case HIF_ADH_SET2_CONF :
2729 printk("HIF_ADH_SET2_CONF\n");
2733 /*------------------------------------------------------------------*/
2734 /* Private handler : get host command history */
2735 static int ks_wlan_hostt(struct net_device *dev, struct iw_request_info *info,
2736 __u32 *uwrq, char *extra)
2739 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2741 for(i = 63; i >= 0; i--){
2742 event = priv->hostt.buff[(priv->hostt.qtail -1 -i)%SME_EVENT_BUFF_SIZE] ;
2743 print_hif_event(event);
2748 /* Structures to export the Wireless Handlers */
2750 static const struct iw_priv_args ks_wlan_private_args[] = {
2751 /*{ cmd, set_args, get_args, name[16] } */
2752 { KS_WLAN_GET_DRIVER_VERSION, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | (128+1), "GetDriverVer" },
2753 { KS_WLAN_GET_FIRM_VERSION, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | (128+1), "GetFirmwareVer" },
2755 { KS_WLAN_SET_WPS_ENABLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetWPSEnable" },
2756 { KS_WLAN_GET_WPS_ENABLE, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetW" },
2757 { KS_WLAN_SET_WPS_PROBE_REQ, IW_PRIV_TYPE_BYTE | 2047, IW_PRIV_TYPE_NONE, "SetWPSProbeReq" },
2759 { KS_WLAN_SET_PREAMBLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetPreamble" },
2760 { KS_WLAN_GET_PREAMBLE, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPreamble" },
2761 { KS_WLAN_SET_POWER_SAVE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetPowerSave" },
2762 { KS_WLAN_GET_POWER_SAVE, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPowerSave" },
2763 { KS_WLAN_SET_SCAN_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetScanType" },
2764 { KS_WLAN_GET_SCAN_TYPE, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetScanType" },
2765 { KS_WLAN_SET_RX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetRxGain" },
2766 { KS_WLAN_GET_RX_GAIN, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetRxGain" },
2767 { KS_WLAN_HOSTT, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | (128+1), "hostt" },
2768 { KS_WLAN_SET_BEACON_LOST, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetBeaconLost" },
2769 { KS_WLAN_GET_BEACON_LOST, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetBeaconLost" },
2770 { KS_WLAN_SET_SLEEP_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetSleepMode" },
2771 { KS_WLAN_GET_SLEEP_MODE, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetSleepMode" },
2772 { KS_WLAN_SET_TX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetTxGain" },
2773 { KS_WLAN_GET_TX_GAIN, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetTxGain" },
2774 { KS_WLAN_SET_PHY_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetPhyType" },
2775 { KS_WLAN_GET_PHY_TYPE, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPhyType" },
2776 { KS_WLAN_SET_CTS_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, IW_PRIV_TYPE_NONE, "SetCtsMode" },
2777 { KS_WLAN_GET_CTS_MODE, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetCtsMode" },
2778 { KS_WLAN_GET_EEPROM_CKSUM, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetChecksum" },
2780 static const iw_handler ks_wlan_handler[] =
2782 (iw_handler) ks_wlan_config_commit, /* SIOCSIWCOMMIT */
2783 (iw_handler) ks_wlan_get_name, /* SIOCGIWNAME */
2784 (iw_handler) NULL, /* SIOCSIWNWID */
2785 (iw_handler) NULL, /* SIOCGIWNWID */
2786 (iw_handler) ks_wlan_set_freq, /* SIOCSIWFREQ */
2787 (iw_handler) ks_wlan_get_freq, /* SIOCGIWFREQ */
2788 (iw_handler) ks_wlan_set_mode, /* SIOCSIWMODE */
2789 (iw_handler) ks_wlan_get_mode, /* SIOCGIWMODE */
2790 #ifndef KSC_OPNOTSUPP
2791 (iw_handler) ks_wlan_set_sens, /* SIOCSIWSENS */
2792 (iw_handler) ks_wlan_get_sens, /* SIOCGIWSENS */
2793 #else /* KSC_OPNOTSUPP */
2794 (iw_handler) NULL, /* SIOCSIWSENS */
2795 (iw_handler) NULL, /* SIOCGIWSENS */
2796 #endif /* KSC_OPNOTSUPP */
2797 (iw_handler) NULL, /* SIOCSIWRANGE */
2798 (iw_handler) ks_wlan_get_range, /* SIOCGIWRANGE */
2799 (iw_handler) NULL, /* SIOCSIWPRIV */
2800 (iw_handler) NULL, /* SIOCGIWPRIV */
2801 (iw_handler) NULL, /* SIOCSIWSTATS */
2802 (iw_handler) ks_wlan_get_iwstats, /* SIOCGIWSTATS */
2803 (iw_handler) NULL, /* SIOCSIWSPY */
2804 (iw_handler) NULL, /* SIOCGIWSPY */
2805 (iw_handler) NULL, /* SIOCSIWTHRSPY */
2806 (iw_handler) NULL, /* SIOCGIWTHRSPY */
2807 (iw_handler) ks_wlan_set_wap, /* SIOCSIWAP */
2808 (iw_handler) ks_wlan_get_wap, /* SIOCGIWAP */
2809 // (iw_handler) NULL, /* SIOCSIWMLME */
2810 (iw_handler) ks_wlan_set_mlme, /* SIOCSIWMLME */
2811 (iw_handler) ks_wlan_get_aplist, /* SIOCGIWAPLIST */
2812 (iw_handler) ks_wlan_set_scan, /* SIOCSIWSCAN */
2813 (iw_handler) ks_wlan_get_scan, /* SIOCGIWSCAN */
2814 (iw_handler) ks_wlan_set_essid, /* SIOCSIWESSID */
2815 (iw_handler) ks_wlan_get_essid, /* SIOCGIWESSID */
2816 (iw_handler) ks_wlan_set_nick, /* SIOCSIWNICKN */
2817 (iw_handler) ks_wlan_get_nick, /* SIOCGIWNICKN */
2818 (iw_handler) NULL, /* -- hole -- */
2819 (iw_handler) NULL, /* -- hole -- */
2820 (iw_handler) ks_wlan_set_rate, /* SIOCSIWRATE */
2821 (iw_handler) ks_wlan_get_rate, /* SIOCGIWRATE */
2822 (iw_handler) ks_wlan_set_rts, /* SIOCSIWRTS */
2823 (iw_handler) ks_wlan_get_rts, /* SIOCGIWRTS */
2824 (iw_handler) ks_wlan_set_frag, /* SIOCSIWFRAG */
2825 (iw_handler) ks_wlan_get_frag, /* SIOCGIWFRAG */
2826 #ifndef KSC_OPNOTSUPP
2827 (iw_handler) ks_wlan_set_txpow, /* SIOCSIWTXPOW */
2828 (iw_handler) ks_wlan_get_txpow, /* SIOCGIWTXPOW */
2829 (iw_handler) ks_wlan_set_retry, /* SIOCSIWRETRY */
2830 (iw_handler) ks_wlan_get_retry, /* SIOCGIWRETRY */
2831 #else /* KSC_OPNOTSUPP */
2832 (iw_handler) NULL, /* SIOCSIWTXPOW */
2833 (iw_handler) NULL, /* SIOCGIWTXPOW */
2834 (iw_handler) NULL, /* SIOCSIWRETRY */
2835 (iw_handler) NULL, /* SIOCGIWRETRY */
2836 #endif /* KSC_OPNOTSUPP */
2837 (iw_handler) ks_wlan_set_encode, /* SIOCSIWENCODE */
2838 (iw_handler) ks_wlan_get_encode, /* SIOCGIWENCODE */
2839 (iw_handler) ks_wlan_set_power, /* SIOCSIWPOWER */
2840 (iw_handler) ks_wlan_get_power, /* SIOCGIWPOWER */
2841 (iw_handler) NULL, /* -- hole -- */
2842 (iw_handler) NULL, /* -- hole -- */
2843 // (iw_handler) NULL, /* SIOCSIWGENIE */
2844 (iw_handler) ks_wlan_set_genie, /* SIOCSIWGENIE */
2845 (iw_handler) NULL, /* SIOCGIWGENIE */
2846 (iw_handler) ks_wlan_set_auth_mode, /* SIOCSIWAUTH */
2847 (iw_handler) ks_wlan_get_auth_mode, /* SIOCGIWAUTH */
2848 (iw_handler) ks_wlan_set_encode_ext, /* SIOCSIWENCODEEXT */
2849 (iw_handler) ks_wlan_get_encode_ext, /* SIOCGIWENCODEEXT */
2850 (iw_handler) ks_wlan_set_pmksa, /* SIOCSIWPMKSA */
2851 (iw_handler) NULL, /* -- hole -- */
2854 /* private_handler */
2855 static const iw_handler ks_wlan_private_handler[] =
2857 (iw_handler) NULL, /* 0 */
2858 (iw_handler) ks_wlan_get_driver_version, /* 1 KS_WLAN_GET_DRIVER_VERSION */
2859 (iw_handler) NULL, /* 2 */
2860 (iw_handler) ks_wlan_get_firmware_version, /* 3 KS_WLAN_GET_FIRM_VERSION */
2862 (iw_handler) ks_wlan_set_wps_enable, /* 4 KS_WLAN_SET_WPS_ENABLE */
2863 (iw_handler) ks_wlan_get_wps_enable, /* 5 KS_WLAN_GET_WPS_ENABLE */
2864 (iw_handler) ks_wlan_set_wps_probe_req, /* 6 KS_WLAN_SET_WPS_PROBE_REQ */
2866 (iw_handler) NULL, /* 4 */
2867 (iw_handler) NULL, /* 5 */
2868 (iw_handler) NULL, /* 6 */
2871 (iw_handler) ks_wlan_get_eeprom_cksum, /* 7 KS_WLAN_GET_CONNECT */
2872 (iw_handler) ks_wlan_set_preamble, /* 8 KS_WLAN_SET_PREAMBLE */
2873 (iw_handler) ks_wlan_get_preamble, /* 9 KS_WLAN_GET_PREAMBLE */
2874 (iw_handler) ks_wlan_set_powermgt, /* 10 KS_WLAN_SET_POWER_SAVE */
2875 (iw_handler) ks_wlan_get_powermgt, /* 11 KS_WLAN_GET_POWER_SAVE */
2876 (iw_handler) ks_wlan_set_scan_type, /* 12 KS_WLAN_SET_SCAN_TYPE */
2877 (iw_handler) ks_wlan_get_scan_type, /* 13 KS_WLAN_GET_SCAN_TYPE */
2878 (iw_handler) ks_wlan_set_rx_gain, /* 14 KS_WLAN_SET_RX_GAIN */
2879 (iw_handler) ks_wlan_get_rx_gain, /* 15 KS_WLAN_GET_RX_GAIN */
2880 (iw_handler) ks_wlan_hostt, /* 16 KS_WLAN_HOSTT */
2881 (iw_handler) NULL, /* 17 */
2882 (iw_handler) ks_wlan_set_beacon_lost, /* 18 KS_WLAN_SET_BECAN_LOST */
2883 (iw_handler) ks_wlan_get_beacon_lost, /* 19 KS_WLAN_GET_BECAN_LOST */
2884 (iw_handler) ks_wlan_set_tx_gain, /* 20 KS_WLAN_SET_TX_GAIN */
2885 (iw_handler) ks_wlan_get_tx_gain, /* 21 KS_WLAN_GET_TX_GAIN */
2886 (iw_handler) ks_wlan_set_phy_type, /* 22 KS_WLAN_SET_PHY_TYPE */
2887 (iw_handler) ks_wlan_get_phy_type, /* 23 KS_WLAN_GET_PHY_TYPE */
2888 (iw_handler) ks_wlan_set_cts_mode, /* 24 KS_WLAN_SET_CTS_MODE */
2889 (iw_handler) ks_wlan_get_cts_mode, /* 25 KS_WLAN_GET_CTS_MODE */
2890 (iw_handler) NULL, /* 26 */
2891 (iw_handler) NULL, /* 27 */
2892 (iw_handler) ks_wlan_set_sleep_mode, /* 28 KS_WLAN_SET_SLEEP_MODE */
2893 (iw_handler) ks_wlan_get_sleep_mode, /* 29 KS_WLAN_GET_SLEEP_MODE */
2894 (iw_handler) NULL, /* 30 */
2895 (iw_handler) NULL, /* 31 */
2898 static const struct iw_handler_def ks_wlan_handler_def =
2900 .num_standard = sizeof(ks_wlan_handler)/sizeof(iw_handler),
2901 .num_private = sizeof(ks_wlan_private_handler)/sizeof(iw_handler),
2902 .num_private_args = sizeof(ks_wlan_private_args)/sizeof(struct iw_priv_args),
2903 .standard = (iw_handler *) ks_wlan_handler,
2904 .private = (iw_handler *) ks_wlan_private_handler,
2905 .private_args = (struct iw_priv_args *) ks_wlan_private_args,
2906 .get_wireless_stats = ks_get_wireless_stats,
2910 static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2913 struct iwreq *wrq = (struct iwreq *) rq;
2915 case SIOCIWFIRSTPRIV+20: /* KS_WLAN_SET_STOP_REQ */
2916 rc = ks_wlan_set_stop_request(dev, NULL, &(wrq->u.mode), NULL);
2918 // All other calls are currently unsupported
2923 DPRINTK(5,"return=%d\n",rc);
2929 struct net_device_stats *ks_wlan_get_stats(struct net_device *dev)
2931 ks_wlan_private *priv = netdev_priv(dev);
2933 if (priv->dev_state < DEVICE_STATE_READY) {
2934 return NULL; /* not finished initialize */
2937 return &priv->nstats;
2941 int ks_wlan_set_mac_address(struct net_device *dev, void *addr)
2943 ks_wlan_private *priv = netdev_priv(dev);
2944 struct sockaddr *mac_addr=(struct sockaddr *)addr;
2945 if (netif_running(dev))
2947 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
2948 memcpy(priv->eth_addr, mac_addr->sa_data, ETH_ALEN);
2950 priv->mac_address_valid = 0;
2951 hostif_sme_enqueue(priv, SME_MACADDRESS_SET_REQUEST);
2952 printk(KERN_INFO "ks_wlan: MAC ADDRESS = %02x:%02x:%02x:%02x:%02x:%02x\n",
2953 priv->eth_addr[0],priv->eth_addr[1],priv->eth_addr[2],
2954 priv->eth_addr[3],priv->eth_addr[4],priv->eth_addr[5]);
2960 void ks_wlan_tx_timeout(struct net_device *dev)
2962 ks_wlan_private *priv = netdev_priv(dev);
2964 DPRINTK(1,"head(%d) tail(%d)!!\n",priv->tx_dev.qhead, priv->tx_dev.qtail);
2965 if(!netif_queue_stopped(dev)){
2966 netif_stop_queue(dev);
2968 priv->nstats.tx_errors++;
2969 netif_wake_queue(dev);
2975 int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev)
2977 ks_wlan_private *priv = netdev_priv(dev);
2980 DPRINTK(3,"in_interrupt()=%ld\n",in_interrupt());
2982 if ( skb == NULL ) {
2983 printk( KERN_ERR "ks_wlan: skb == NULL!!!\n" );
2986 if (priv->dev_state < DEVICE_STATE_READY) {
2988 return 0; /* not finished initialize */
2991 if(netif_running(dev))
2992 netif_stop_queue(dev);
2994 rc = hostif_data_request(priv, skb);
2995 dev->trans_start = jiffies;
2997 DPRINTK(4,"rc=%d\n",rc);
3005 void send_packet_complete(void *arg1, void *arg2)
3007 ks_wlan_private *priv = (ks_wlan_private *)arg1;
3008 struct sk_buff *packet = (struct sk_buff *)arg2;
3012 priv->nstats.tx_bytes += packet->len;
3013 priv->nstats.tx_packets++;
3015 if(netif_queue_stopped(priv->net_dev))
3016 netif_wake_queue(priv->net_dev);
3019 dev_kfree_skb(packet);
3025 /* Set or clear the multicast filter for this adaptor.
3026 This routine is not state sensitive and need not be SMP locked. */
3028 void ks_wlan_set_multicast_list(struct net_device *dev)
3030 ks_wlan_private *priv = netdev_priv(dev);
3033 if (priv->dev_state < DEVICE_STATE_READY) {
3034 return ; /* not finished initialize */
3036 hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST);
3042 int ks_wlan_open(struct net_device *dev)
3044 ks_wlan_private *priv = netdev_priv(dev);
3048 if(!priv->mac_address_valid){
3049 printk(KERN_ERR "ks_wlan : %s Not READY !!\n", dev->name);
3053 netif_start_queue (dev);
3059 int ks_wlan_close(struct net_device *dev)
3062 netif_stop_queue (dev);
3064 DPRINTK(4, "%s: Shutting down ethercard, status was 0x%4.4x.\n",
3071 /* Operational parameters that usually are not changed. */
3072 /* Time in jiffies before concluding the transmitter is hung. */
3073 #define TX_TIMEOUT (3*HZ)
3074 static const unsigned char dummy_addr[] = {0x00,0x0b,0xe3,0x00,0x00,0x00};
3076 static const struct net_device_ops ks_wlan_netdev_ops = {
3077 .ndo_start_xmit = ks_wlan_start_xmit,
3078 .ndo_open = ks_wlan_open,
3079 .ndo_stop = ks_wlan_close,
3080 .ndo_do_ioctl = ks_wlan_netdev_ioctl,
3081 .ndo_set_mac_address = ks_wlan_set_mac_address,
3082 .ndo_get_stats = ks_wlan_get_stats,
3083 .ndo_tx_timeout = ks_wlan_tx_timeout,
3084 .ndo_set_rx_mode = ks_wlan_set_multicast_list,
3087 int ks_wlan_net_start(struct net_device *dev)
3089 ks_wlan_private *priv;
3092 priv = netdev_priv(dev);
3093 priv->mac_address_valid = 0;
3094 priv->need_commit = 0;
3096 priv->device_open_status = 1;
3098 /* phy information update timer */
3099 atomic_set(&update_phyinfo,0);
3100 init_timer(&update_phyinfo_timer);
3101 update_phyinfo_timer.function=ks_wlan_update_phyinfo_timeout;
3102 update_phyinfo_timer.data = (unsigned long)priv;
3104 /* dummy address set */
3105 memcpy(priv->eth_addr, dummy_addr, ETH_ALEN);
3106 dev->dev_addr[0] = priv->eth_addr[0];
3107 dev->dev_addr[1] = priv->eth_addr[1];
3108 dev->dev_addr[2] = priv->eth_addr[2];
3109 dev->dev_addr[3] = priv->eth_addr[3];
3110 dev->dev_addr[4] = priv->eth_addr[4];
3111 dev->dev_addr[5] = priv->eth_addr[5];
3112 dev->dev_addr[6] = 0x00;
3113 dev->dev_addr[7] = 0x00;
3115 /* The ks_wlan-specific entries in the device structure. */
3116 dev->netdev_ops = &ks_wlan_netdev_ops;
3117 dev->wireless_handlers = (struct iw_handler_def *)&ks_wlan_handler_def;
3118 dev->watchdog_timeo = TX_TIMEOUT;
3120 netif_carrier_off(dev);
3126 int ks_wlan_net_stop(struct net_device *dev)
3128 ks_wlan_private *priv = netdev_priv(dev);
3131 priv->device_open_status = 0;
3132 del_timer_sync(&update_phyinfo_timer);
3134 if(netif_running(dev))
3135 netif_stop_queue(dev);
3140 int ks_wlan_reset(struct net_device *dev)