staging: ks7010: remove code for old kernel versions
[cascardo/linux.git] / drivers / staging / ks7010 / ks_wlan_net.c
1 /*
2  *   Driver for KeyStream 11b/g wireless LAN
3  *
4  *   ks_wlan_net.c
5  *   $Id: ks_wlan_net.c 1020 2009-09-28 05:48:31Z sekine $
6  *
7  *   Copyright (C) 2005-2008 KeyStream Corp.
8  *   Copyright (C) 2009 Renesas Technology Corp.
9  *
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.
13  */
14
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>
32 #include <linux/io.h>
33 #include <asm/uaccess.h>
34
35 static int wep_on_off;
36 #define WEP_OFF         0
37 #define WEP_ON_64BIT    1
38 #define WEP_ON_128BIT   2
39
40 #include "ks_wlan.h"
41 #include "ks_hostif.h"
42 #include "ks_wlan_ioctl.h"
43 #include "ks_debug.h"
44
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 */
49
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 };
53
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 {
58         u16     len;
59         u8      key[16]; /* 40-bit and 104-bit keys */
60 } wep_key_t;
61
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 */
67
68 /* List of Wireless Handlers (new API) */
69 static const struct iw_handler_def      ks_wlan_handler_def;
70
71 #define KSC_OPNOTSUPP /* Operation Not Support*/
72
73
74 /*
75  *      function prototypes
76  */
77 extern int ks_wlan_hw_tx(ks_wlan_private *priv, void *p, unsigned long size,
78                         void (*complete_handler)(void *arg1, void *arg2),
79                         void *arg1,
80                         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);
89
90 static atomic_t update_phyinfo;
91 static struct timer_list update_phyinfo_timer;
92 static
93 int ks_wlan_update_phy_information(ks_wlan_private *priv)
94 {
95                 struct iw_statistics *wstats = &priv->wstats;
96
97         DPRINTK(4, "in_interrupt = %ld\n", in_interrupt());
98
99         if (priv->dev_state < DEVICE_STATE_READY) {
100                                 return -1; /* not finished initialize */
101                 }
102         if(atomic_read(&update_phyinfo))
103                 return 1;
104
105         /* The status */
106         wstats->status = priv->reg.operation_mode;      /* Operation mode */
107
108         /* Signal quality and co. But where is the noise level ??? */
109         hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST);
110
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");
114         }
115
116         atomic_inc(&update_phyinfo);
117         update_phyinfo_timer.expires = jiffies + HZ; /* 1sec */
118         add_timer(&update_phyinfo_timer);
119
120         return 0;
121 }
122
123 static
124 void ks_wlan_update_phyinfo_timeout(unsigned long ptr)
125 {
126         DPRINTK(4, "in_interrupt = %ld\n", in_interrupt());
127         atomic_set(&update_phyinfo,0);
128 }
129
130 int ks_wlan_setup_parameter(ks_wlan_private *priv, unsigned int commit_flag)
131 {
132         DPRINTK(2,"\n");
133
134         hostif_sme_enqueue(priv, SME_STOP_REQUEST);
135
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);
140
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);
153
154         if(commit_flag & SME_RSN){
155                 hostif_sme_enqueue(priv, SME_RSN_ENABLED_REQUEST);
156                 hostif_sme_enqueue(priv, SME_RSN_MODE_REQUEST);
157         }
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);
164
165         hostif_sme_enqueue(priv, SME_MODE_SET_REQUEST);
166
167         hostif_sme_enqueue(priv, SME_START_REQUEST);
168
169         return 0;
170 }
171
172 /*
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
180  */
181
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)
186 {
187         ks_wlan_private *priv = (ks_wlan_private *) netdev_priv(dev);
188
189         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
190
191         if (priv->dev_state < DEVICE_STATE_READY) {
192                 strcpy(cwrq, "NOT READY!");
193                 }
194         else if(priv->reg.phy_type == D_11B_ONLY_MODE){
195                 strcpy(cwrq, "IEEE 802.11b");
196         }
197         else if(priv->reg.phy_type == D_11G_ONLY_MODE){
198                 strcpy(cwrq, "IEEE 802.11g");
199         }
200         else {
201                 strcpy(cwrq, "IEEE 802.11b/g");
202         }
203
204         return 0;
205 }
206
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)
211 {
212         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
213         int rc = -EINPROGRESS;          /* Call commit handler */
214
215         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
216
217         /* If setting by frequency, convert to a channel */
218         if((fwrq->e == 1) &&
219            (fwrq->m >= (int) 2.412e8) &&
220            (fwrq->m <= (int) 2.487e8)) {
221                 int f = fwrq->m / 100000;
222                 int c = 0;
223                 while((c < 14) && (f != frequency_list[c]))
224                         c++;
225                 /* Hack to fall through... */
226                 fwrq->e = 0;
227                 fwrq->m = c + 1;
228         }
229         /* Setting by channel number */
230         if((fwrq->m > 1000) || (fwrq->e > 0))
231                 rc = -EOPNOTSUPP;
232         else {
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);
238                         rc = -EINVAL;
239                 } else {
240                         /* Yes ! We can set it !!! */
241                         priv->reg.channel = (u8)(channel);
242                         priv->need_commit |= SME_MODE_SET;
243                 }
244         }
245
246         return rc;
247 }
248
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)
253 {
254         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
255         int f;
256
257         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
258
259         if((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS){
260                 f = (int)priv->current_ap.channel;
261         }
262         else
263                 f = (int)priv->reg.channel;
264         fwrq->m = frequency_list[f-1] * 100000;
265         fwrq->e = 1;
266
267         return 0;
268 }
269
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)
274 {
275         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
276         size_t len;
277
278         DPRINTK(2," %d\n", dwrq->flags);
279
280         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
281
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;
287         } else {
288 #if 1
289                 len = dwrq->length;
290                 /* iwconfig uses nul termination in SSID.. */
291                 if (len > 0 && extra[len - 1] == '\0')
292                         len--;
293
294                 /* Check the size of the string */
295                 if(len > IW_ESSID_MAX_SIZE) {
296                         return -EINVAL;
297                 }
298 #else
299                 /* Check the size of the string */
300                 if(dwrq->length > IW_ESSID_MAX_SIZE+1) {
301                         return -E2BIG ;
302                 }
303 #endif
304
305                 /* Set the SSID */
306                 memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
307
308 #if 1
309                 memcpy(priv->reg.ssid.body, extra, len);
310                 priv->reg.ssid.size = len;
311 #else
312                 memcpy(priv->reg.ssid.body, extra, dwrq->length);
313                 priv->reg.ssid.size = dwrq->length;
314 #endif
315         }
316         /* Write it to the card */
317         priv->need_commit |= SME_MODE_SET;
318
319 //      return  -EINPROGRESS;   /* Call commit handler */
320         ks_wlan_setup_parameter(priv, priv->need_commit);
321         priv->need_commit=0;
322         return  0;
323 }
324
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)
329 {
330         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
331
332         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
333
334         /* Note : if dwrq->flags != 0, we should
335          * get the relevant SSID from the SSID list... */
336
337         if(priv->reg.ssid.size){
338                 /* Get the current SSID */
339                 memcpy(extra, priv->reg.ssid.body, priv->reg.ssid.size);
340 #if 0
341                 extra[priv->reg.ssid.size] = '\0';
342 #endif
343                 /* If none, we may want to get the one that was set */
344
345                 /* Push it out ! */
346 #if 1
347                 dwrq->length = priv->reg.ssid.size;
348 #else
349                 dwrq->length = priv->reg.ssid.size+1;
350 #endif
351                 dwrq->flags = 1; /* active */
352         }else{
353 #if 1
354                 dwrq->length = 0;
355 #else
356                 extra[0] = '\0';
357                 dwrq->length = 1;
358 #endif
359                 dwrq->flags = 0; /* ANY */
360         }
361
362         return 0;
363 }
364
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)
369 {
370         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
371
372         DPRINTK(2,"\n");
373
374         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
375
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);
379
380                 if (is_valid_ether_addr((u8 *)priv->reg.bssid)) {
381                         priv->need_commit |= SME_MODE_SET;
382                 }
383         }
384         else {
385                 memset(priv->reg.bssid, 0x0, ETH_ALEN);
386                 return -EOPNOTSUPP;
387         }
388
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]);
392
393         /* Write it to the card */
394         if (priv->need_commit) {
395                 priv->need_commit |= SME_MODE_SET;
396                 return  -EINPROGRESS;   /* Call commit handler */
397         }
398         return 0;
399 }
400
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)
405 {
406                 ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
407
408         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
409
410         if((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS){
411                 memcpy(awrq->sa_data, &(priv->current_ap.bssid[0]), ETH_ALEN);
412         }
413         else{
414                 memset(awrq->sa_data, 0, ETH_ALEN);
415         }
416
417         awrq->sa_family = ARPHRD_ETHER;
418
419         return 0;
420 }
421
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)
426 {
427         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
428
429         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
430
431         /* Check the size of the string */
432         if(dwrq->length > 16 + 1) {
433                 return -E2BIG;
434         }
435         memset(priv->nick, 0, sizeof(priv->nick));
436         memcpy(priv->nick, extra, dwrq->length);
437
438         return -EINPROGRESS;    /* Call commit handler */
439 }
440
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)
445 {
446         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
447
448         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
449
450         strncpy(extra, priv->nick, 16);
451         extra[16] = '\0';
452         dwrq->length = strlen(extra) + 1;
453
454         return 0;
455 }
456
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)
461 {
462         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
463         int i = 0;
464
465         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
466
467         if(priv->reg.phy_type == D_11B_ONLY_MODE){
468                 if(vwrq->fixed == 1) {
469                         switch(vwrq->value){
470                         case 11000000:
471                         case  5500000:
472                                 priv->reg.rate_set.body[0] = (uint8_t)(vwrq->value/500000);
473                                 break;
474                         case  2000000:
475                         case  1000000:
476                                 priv->reg.rate_set.body[0] = ((uint8_t)(vwrq->value/500000))|BASIC_RATE;
477                                 break;
478                         default:
479                                 return -EINVAL;
480                         }
481                         priv->reg.tx_rate = TX_RATE_FIXED;
482                         priv->reg.rate_set.size = 1;
483                 }else{  /* vwrq->fixed == 0 */
484                         if(vwrq->value > 0){
485                                 switch(vwrq->value){
486                                 case 11000000:
487                                         priv->reg.rate_set.body[3] = TX_RATE_11M; i++;
488                                 case  5500000:
489                                         priv->reg.rate_set.body[2] = TX_RATE_5M; i++;
490                                 case  2000000:
491                                         priv->reg.rate_set.body[1] = TX_RATE_2M|BASIC_RATE; i++;
492                                 case  1000000:
493                                         priv->reg.rate_set.body[0] = TX_RATE_1M|BASIC_RATE; i++;
494                                         break;
495                                 default:
496                                         return -EINVAL;
497                                 }
498                                 priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
499                                 priv->reg.rate_set.size = i;
500                         }else{
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;
507                         }
508                 }
509         }else{ /* D_11B_ONLY_MODE or  D_11BG_COMPATIBLE_MODE */
510                 if(vwrq->fixed == 1) {
511                         switch(vwrq->value){
512                         case 54000000:
513                         case 48000000:
514                         case 36000000:
515                         case 18000000:
516                         case  9000000:
517                                 priv->reg.rate_set.body[0] = (uint8_t)(vwrq->value/500000);
518                                 break;
519                         case 24000000:
520                         case 12000000:
521                         case 11000000:
522                         case  6000000:
523                         case  5500000:
524                         case  2000000:
525                         case  1000000:
526                                 priv->reg.rate_set.body[0] = ((uint8_t)(vwrq->value/500000))|BASIC_RATE;
527                                 break;
528                         default:
529                                 return -EINVAL;
530                         }
531                         priv->reg.tx_rate = TX_RATE_FIXED;
532                         priv->reg.rate_set.size = 1;
533                 }else{  /* vwrq->fixed == 0 */
534                         if(vwrq->value > 0){
535                                 switch(vwrq->value){
536                                 case 54000000:
537                                         priv->reg.rate_set.body[11] = TX_RATE_54M; i++;
538                                 case 48000000:
539                                         priv->reg.rate_set.body[10] = TX_RATE_48M; i++;
540                                 case 36000000:
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++;
571                                         }
572                                 case  5500000:
573                                         priv->reg.rate_set.body[2] = TX_RATE_5M|BASIC_RATE; i++;
574                                 case  2000000:
575                                         priv->reg.rate_set.body[1] = TX_RATE_2M|BASIC_RATE; i++;
576                                 case  1000000:
577                                         priv->reg.rate_set.body[0] = TX_RATE_1M|BASIC_RATE; i++;
578                                         break;
579                                 default:
580                                         return -EINVAL;
581                                 }
582                                 priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
583                                 priv->reg.rate_set.size = i;
584                         }else{
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;
599                         }
600                 }
601         }
602
603         priv->need_commit |= SME_MODE_SET;
604
605         return -EINPROGRESS;    /* Call commit handler */
606 }
607
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)
612 {
613         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
614
615         DPRINTK(2, "in_interrupt = %ld update_phyinfo = %d\n",
616                 in_interrupt(),atomic_read(&update_phyinfo));
617
618         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
619
620         if(!atomic_read(&update_phyinfo)){
621                 ks_wlan_update_phy_information(priv);
622         }
623         vwrq->value = ((priv->current_rate) & RATE_MASK) * 500000;
624         if(priv->reg.tx_rate == TX_RATE_FIXED)
625                 vwrq->fixed = 1;
626         else
627                 vwrq->fixed = 0;
628
629         return 0;
630 }
631
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)
636 {
637         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
638         int rthr = vwrq->value;
639
640         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
641
642         if(vwrq->disabled)
643                 rthr = 2347;
644         if((rthr < 0) || (rthr > 2347)) {
645                 return -EINVAL;
646         }
647         priv->reg.rts = rthr;
648         priv->need_commit |= SME_RTS;
649
650         return -EINPROGRESS;    /* Call commit handler */
651 }
652
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)
657 {
658         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
659
660         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
661
662         vwrq->value = priv->reg.rts;
663         vwrq->disabled = (vwrq->value >= 2347);
664         vwrq->fixed = 1;
665
666         return 0;
667 }
668
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)
673 {
674         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
675         int fthr = vwrq->value;
676
677         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
678
679         if(vwrq->disabled)
680                 fthr = 2346;
681         if((fthr < 256) || (fthr > 2346)) {
682                 return -EINVAL;
683         }
684         fthr &= ~0x1;   /* Get an even value - is it really needed ??? */
685         priv->reg.fragment = fthr;
686         priv->need_commit |= SME_FRAG;
687
688         return -EINPROGRESS;    /* Call commit handler */
689 }
690
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)
695 {
696         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
697
698         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
699
700         vwrq->value = priv->reg.fragment;
701         vwrq->disabled = (vwrq->value >= 2346);
702         vwrq->fixed = 1;
703
704         return 0;
705 }
706
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)
711 {
712         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
713
714         DPRINTK(2,"mode=%d\n",*uwrq);
715
716         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
717
718         switch(*uwrq) {
719         case IW_MODE_ADHOC:
720                 priv->reg.operation_mode = MODE_ADHOC;
721                 priv->need_commit |= SME_MODE_SET;
722                 break;
723         case IW_MODE_INFRA:
724                 priv->reg.operation_mode = MODE_INFRASTRUCTURE;
725                 priv->need_commit |= SME_MODE_SET;
726                 break;
727         case IW_MODE_AUTO:
728         case IW_MODE_MASTER:
729         case IW_MODE_REPEAT:
730         case IW_MODE_SECOND:
731         case IW_MODE_MONITOR:
732         default:
733                 return -EINVAL;
734         }
735
736         return -EINPROGRESS;            /* Call commit handler */
737 }
738
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)
743 {
744         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
745
746         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
747
748         /* If not managed, assume it's ad-hoc */
749         switch (priv->reg.operation_mode) {
750                 case MODE_INFRASTRUCTURE:
751                         *uwrq = IW_MODE_INFRA;
752                         break;
753                 case MODE_ADHOC:
754                         *uwrq = IW_MODE_ADHOC;
755                         break;
756                 default:
757                         *uwrq = IW_MODE_ADHOC;
758         }
759
760         return 0;
761 }
762
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)
767 {
768         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
769
770         wep_key_t key;
771         int index = (dwrq->flags & IW_ENCODE_INDEX);
772         int current_index = priv->reg.wep_index;
773         int i;
774
775         DPRINTK(2,"flags=%04X\n",dwrq->flags);
776
777         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
778
779         /* index check */
780         if((index<0) || (index>4))
781                 return -EINVAL;
782         else if (index==0)
783                 index = current_index;
784         else
785                 index--;
786
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 */
791                         return -EINVAL;
792                 }
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;
798                 } else {
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 */
805                                 key.len = 0;
806                         }
807                 }
808                 /* Check if the key is not marked as invalid */
809                 if(!(dwrq->flags & IW_ENCODE_NOKEY)) {
810                         /* Cleanup */
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)) {
814                                 key.len = 0;
815                                 return -EFAULT;
816                         }
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];
821                         }
822                         priv->need_commit |= (SME_WEP_VAL1<<index);
823                         priv->reg.wep_index = index;
824                         priv->need_commit |= SME_WEP_INDEX;
825                 }
826         } else {
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;
835                         }
836                         priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
837                         wep_on_off = WEP_OFF;
838                         priv->need_commit |= SME_WEP_FLAG;
839                 }else{
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;
846                                 }
847                                 else
848                                         return -EINVAL;
849                         }
850                 }
851         }
852
853         /* Commit the changes if needed */
854         if(dwrq->flags & IW_ENCODE_MODE)
855                 priv->need_commit |= SME_WEP_FLAG;
856
857         if(dwrq->flags & IW_ENCODE_OPEN) {
858                 if(priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY){
859                         priv->need_commit |= SME_MODE_SET;
860                 }
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;
865                 }
866                 priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
867         }
868
869 //      return -EINPROGRESS;            /* Call commit handler */
870         if(priv->need_commit){
871                 ks_wlan_setup_parameter(priv, priv->need_commit);
872                 priv->need_commit=0;
873         }
874         return 0;
875 }
876
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)
881 {
882         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
883         char zeros[16];
884         int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
885
886         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
887
888         dwrq->flags = IW_ENCODE_DISABLED;
889
890         /* Check encryption mode */
891         switch(priv->reg.authenticate_type) {
892         case AUTH_TYPE_OPEN_SYSTEM:
893                 dwrq->flags = IW_ENCODE_OPEN;
894                 break;
895         case AUTH_TYPE_SHARED_KEY:
896                 dwrq->flags = IW_ENCODE_RESTRICTED;
897                 break;
898         }
899
900         memset(zeros,0, sizeof(zeros));
901
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; */
908         }
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) {
915                 dwrq->length=0;
916         }
917 #if 1 /* IW_ENCODE_NOKEY; */
918         if (dwrq->length) {
919                 if((index >= 0) && (index < 4))
920                         memcpy(extra,priv->reg.wep_key[index].val,dwrq->length);
921         } else
922                 memcpy(extra,zeros,dwrq->length);
923 #endif
924         return 0;
925 }
926
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)
932 {
933         return -EOPNOTSUPP; /* Not Support */
934 }
935
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)
940 {
941         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
942
943         /* Not Support */
944         vwrq->value = 0;
945         vwrq->disabled = (vwrq->value == 0);
946         vwrq->fixed = 1;
947         return 0;
948 }
949
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)
954 {
955         return -EOPNOTSUPP; /* Not Support */
956 }
957
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)
962 {
963         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
964
965         /* Not Support */
966         vwrq->value = 0;
967         vwrq->disabled = (vwrq->value == 0);
968         vwrq->fixed = 1;
969         return 0;
970 }
971 #endif /* KSC_OPNOTSUPP */
972
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)
977 {
978         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
979         struct iw_range *range = (struct iw_range *) extra;
980         int i,k;
981
982         DPRINTK(2,"\n");
983
984         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
985
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 */
993         k = 0;
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 */
998         }
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;
1006         }
1007
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;
1013
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;
1020         }
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;
1026
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;
1033                 }else{
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;
1039
1040                         range->num_bitrates = 12;
1041                 }
1042         }
1043
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 */
1047         if(i > 2)
1048                 range->throughput = 5000 * 1000;
1049         else
1050                 range->throughput = 1500 * 1000;
1051
1052         range->min_rts = 0;
1053         range->max_rts = 2347;
1054         range->min_frag = 256;
1055         range->max_frag = 2346;
1056
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;
1061
1062         /* power management not support */
1063         range->pmp_flags = IW_POWER_ON;
1064         range->pmt_flags = IW_POWER_ON;
1065         range->pm_capa = 0;
1066
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; */
1072
1073         range->we_version_source = 21;
1074         range->we_version_compiled = WIRELESS_EXT;
1075
1076         range->retry_capa = IW_RETRY_ON;
1077                 range->retry_flags = IW_RETRY_ON;
1078                 range->r_time_flags = IW_RETRY_ON;
1079
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;
1086
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));
1094
1095         /* encode extension (WPA) capability */
1096         range->enc_capa = (IW_ENC_CAPA_WPA  |
1097                            IW_ENC_CAPA_WPA2 |
1098                            IW_ENC_CAPA_CIPHER_TKIP |
1099                            IW_ENC_CAPA_CIPHER_CCMP);
1100         return 0;
1101 }
1102
1103
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)
1108 {
1109         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1110         short enabled;
1111
1112         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
1113
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;
1120                  else
1121                          return  -EINVAL;
1122         }else if(enabled){  /* 2 */
1123                 if(priv->reg.operation_mode == MODE_INFRASTRUCTURE)
1124                         priv->reg.powermgt = POWMGT_SAVE2_MODE;
1125                 else
1126                         return -EINVAL;
1127         }else
1128                 return  -EINVAL;
1129
1130         hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
1131
1132         return 0;
1133 }
1134
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)
1139 {
1140         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1141
1142         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
1143
1144         if(priv->reg.powermgt > 0)
1145                 vwrq->disabled =  0;
1146         else
1147                 vwrq->disabled =  1;
1148
1149         return 0;
1150 }
1151
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)
1156 {
1157         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1158
1159         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
1160
1161         vwrq->qual    = 0;      /* not supported */
1162         vwrq->level   = priv->wstats.qual.level;
1163         vwrq->noise   = 0;      /* not supported */
1164         vwrq->updated = 0;
1165
1166         return 0;
1167 }
1168
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)
1174 {
1175         return -EOPNOTSUPP;  /* Not Support */
1176 }
1177
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)
1182 {
1183         /* Not Support */
1184         vwrq->value = 0;
1185         vwrq->disabled = (vwrq->value == 0);
1186         vwrq->fixed = 1;
1187         return 0;
1188 }
1189 #endif /* KSC_OPNOTSUPP */
1190
1191
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)
1197 {
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];
1201
1202         int i;
1203
1204         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
1205
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;
1213         }
1214         if (i){
1215                 dwrq->flags = 1; /* Should be define'd */
1216                 memcpy(extra + sizeof(struct sockaddr)*i,
1217                            &qual,  sizeof(struct iw_quality)*i);
1218         }
1219         dwrq->length = i;
1220
1221         return 0;
1222 }
1223
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)
1228 {
1229         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1230         struct iw_scan_req *req = NULL;
1231         DPRINTK(2,"\n");
1232
1233         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
1234
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);
1240         }else{
1241                 priv->scan_ssid_len = 0;
1242         }
1243
1244
1245         priv->sme_i.sme_flag |= SME_AP_SCAN;
1246         hostif_sme_enqueue(priv, SME_BSS_SCAN_REQUEST);
1247
1248         /* At this point, just return to the user. */
1249
1250         return 0;
1251 }
1252
1253 /*------------------------------------------------------------------*/
1254 /*
1255  * Translate scan data returned from the card to a card independent
1256  * format that the Wireless Tools will understand - Jean II
1257  */
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)
1260 {
1261         /* ks_wlan_private *priv = (ks_wlan_private *)dev->priv; */
1262         struct iw_event iwe;            /* Temporary buffer */
1263         u16 capabilities;
1264         char *current_val;      /* For rates */
1265         int i;
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];
1270         char *pbuf;
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);
1276
1277         /* Other entries will be displayed in the order we give them */
1278
1279         /* Add the ESSID */
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]));
1286
1287         /* Add mode */
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;
1293                 else
1294                         iwe.u.mode = IW_MODE_ADHOC;
1295                 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
1296         }
1297
1298         /* Add frequency */
1299         iwe.cmd = SIOCGIWFREQ;
1300         iwe.u.freq.m = ap->channel;
1301         iwe.u.freq.m = frequency_list[iwe.u.freq.m-1] * 100000;
1302         iwe.u.freq.e = 1;
1303         current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
1304
1305         /* Add quality statistics */
1306         iwe.cmd = IWEVQUAL;
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);
1311
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;
1316         else
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]));
1320
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;
1324
1325         iwe.cmd = SIOCGIWRATE;
1326         /* Those two flags are ignored... */
1327         iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
1328
1329         /* Max 16 values */
1330         for(i = 0 ; i < 16 ; i++) {
1331                 /* NULL terminated */
1332                 if(i >= ap->rate_set.size)
1333                         break;
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);
1338         }
1339         /* Check if we added any event */
1340         if((current_val - current_ev) > IW_EV_LCP_LEN)
1341                 current_ev = current_val;
1342
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) {
1346                         pbuf = &buf0[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;
1352
1353                         pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.id);
1354                         pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.size);
1355                         iwe.u.data.length += 4;
1356
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;
1360
1361                         DPRINTK(4,"ap->rsn.size=%d\n",ap->rsn_ie.size);
1362
1363                         current_ev = iwe_stream_add_point(info, current_ev, end_buf,&iwe, &buf0[0]);
1364                 }
1365                 if (ap->wpa_ie.id == GENERIC_INFO_ELEM_ID && ap->wpa_ie.size != 0) {
1366                         pbuf = &buf1[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;
1372
1373                         pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.id);
1374                         pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.size);
1375                         iwe.u.data.length += 4;
1376
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;
1380
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);
1383
1384                         current_ev = iwe_stream_add_point(info, current_ev, end_buf,&iwe, &buf1[0]);
1385                 }
1386
1387         /* The other data in the scan result are not really
1388          * interesting, so for now drop it - Jean II */
1389         return current_ev;
1390 }
1391
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)
1396 {
1397         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1398         int i;
1399         char *current_ev = extra;
1400         DPRINTK(2,"\n");
1401
1402         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
1403
1404         if(priv->sme_i.sme_flag & SME_AP_SCAN) {
1405 DPRINTK(2,"flag AP_SCAN\n");
1406                 return -EAGAIN;
1407         }
1408
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");
1413                 return -ENODATA;
1414         }
1415 #if 0
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) {
1419                         dwrq->length = 0;
1420                         return -E2BIG;
1421                 }
1422                 current_ev = ks_wlan_translate_scan(dev, current_ev,
1423 //                                                  extra + IW_SCAN_MAX_DATA,
1424                                                     extra + dwrq->length,
1425                                                     &(priv->current_ap));
1426         }
1427 #endif
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) {
1431                         dwrq->length = 0;
1432                         return -E2BIG;
1433                 }
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]));
1439         }
1440         /* Length of data */
1441         dwrq->length = (current_ev - extra);
1442         dwrq->flags = 0;
1443
1444         return 0;
1445 }
1446
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)
1451 {
1452         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1453
1454         if (!priv->need_commit)
1455                 return 0;
1456
1457         ks_wlan_setup_parameter(priv, priv->need_commit);
1458         priv->need_commit=0;
1459         return 0;
1460 }
1461
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)
1466 {
1467         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1468
1469         DPRINTK(2, "\n");
1470
1471         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
1472
1473         return 0;
1474 //      return -EOPNOTSUPP;
1475 }
1476
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)
1481 {
1482         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1483         int index = (vwrq->flags & IW_AUTH_INDEX);
1484         int value = vwrq->value;
1485
1486         DPRINTK(2,"index=%d:value=%08X\n",index,value);
1487
1488         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
1489
1490         switch(index){
1491         case IW_AUTH_WPA_VERSION: /* 0 */
1492                 switch(value){
1493                 case IW_AUTH_WPA_VERSION_DISABLED:
1494                         priv->wpa.version = value;
1495                         if(priv->wpa.rsn_enabled){
1496                                 priv->wpa.rsn_enabled = 0;
1497                         }
1498                         priv->need_commit |= SME_RSN;
1499                         break;
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;
1505                         }
1506                         priv->need_commit |= SME_RSN;
1507                         break;
1508                 default:
1509                         return -EOPNOTSUPP;
1510                 }
1511                 break;
1512         case IW_AUTH_CIPHER_PAIRWISE: /* 1 */
1513                 switch(value){
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;
1518                         }
1519                         break;
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;
1527                         }
1528                         priv->wpa.pairwise_suite = value;
1529                         priv->need_commit |= SME_RSN_UNICAST;
1530                         break;
1531                 default:
1532                         return -EOPNOTSUPP;
1533                 }
1534                 break;
1535         case IW_AUTH_CIPHER_GROUP: /* 2 */
1536                 switch(value){
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;
1541                         }
1542                         break;
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;
1550                         }
1551                         priv->wpa.group_suite = value;
1552                         priv->need_commit |= SME_RSN_MULTICAST;
1553                         break;
1554                 default:
1555                         return -EOPNOTSUPP;
1556                 }
1557                 break;
1558         case IW_AUTH_KEY_MGMT: /* 3 */
1559                 switch(value){
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;
1566                         break;
1567                 default:
1568                         return -EOPNOTSUPP;
1569                 }
1570                 break;
1571         case IW_AUTH_80211_AUTH_ALG: /* 6 */
1572                 switch(value){
1573                 case IW_AUTH_ALG_OPEN_SYSTEM:
1574                         priv->wpa.auth_alg = value;
1575                         priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
1576                         break;
1577                 case IW_AUTH_ALG_SHARED_KEY:
1578                         priv->wpa.auth_alg = value;
1579                         priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
1580                         break;
1581                 case IW_AUTH_ALG_LEAP:
1582                 default:
1583                         return -EOPNOTSUPP;
1584                 }
1585                 priv->need_commit |= SME_MODE_SET;
1586                 break;
1587         case IW_AUTH_WPA_ENABLED: /* 7 */
1588                 priv->wpa.wpa_enabled = value;
1589                 break;
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;
1595                 }
1596                 break;
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 */
1601         default:
1602                 break;
1603         }
1604
1605         /* return -EINPROGRESS; */
1606         if(priv->need_commit){
1607                 ks_wlan_setup_parameter(priv, priv->need_commit);
1608                 priv->need_commit=0;
1609         }
1610         return 0;
1611 }
1612
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)
1617 {
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);
1621
1622         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
1623
1624         /*  WPA (not used ?? wpa_supplicant) */
1625         switch(index){
1626         case IW_AUTH_WPA_VERSION:
1627                 vwrq->value = priv->wpa.version;
1628                 break;
1629         case IW_AUTH_CIPHER_PAIRWISE:
1630                 vwrq->value = priv->wpa.pairwise_suite;
1631                 break;
1632         case IW_AUTH_CIPHER_GROUP:
1633                 vwrq->value = priv->wpa.group_suite;
1634                 break;
1635         case IW_AUTH_KEY_MGMT:
1636                 vwrq->value = priv->wpa.key_mgmt_suite;
1637                 break;
1638         case IW_AUTH_80211_AUTH_ALG:
1639                 vwrq->value = priv->wpa.auth_alg;
1640                 break;
1641         case IW_AUTH_WPA_ENABLED:
1642                 vwrq->value = priv->wpa.rsn_enabled;
1643                 break;
1644         case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* OK??? */
1645         case IW_AUTH_TKIP_COUNTERMEASURES:
1646         case IW_AUTH_DROP_UNENCRYPTED:
1647         default:
1648                 /* return -EOPNOTSUPP; */
1649                 break;
1650         }
1651         return 0;
1652 }
1653
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)
1658 {
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;
1663
1664         enc = (struct iw_encode_ext *)extra;
1665
1666         DPRINTK(2,"flags=%04X:: ext_flags=%08X\n",dwrq->flags, enc->ext_flags);
1667
1668         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
1669
1670         if(index<1||index>4)
1671                 return -EINVAL;
1672         else
1673                 index--;
1674
1675         if(dwrq->flags & IW_ENCODE_DISABLED){
1676                 priv->wpa.key[index].key_len=0;
1677         }
1678
1679         if(enc){
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){
1685                         if(enc->rx_seq)
1686                                 memcpy(&priv->wpa.key[index].rx_seq[0],
1687                                        enc->rx_seq, IW_ENCODE_SEQ_MAX_SIZE);
1688                         else
1689                                 return -EINVAL;
1690                 }
1691
1692                 memcpy(&priv->wpa.key[index].addr.sa_data[0],
1693                            &enc->addr.sa_data[0], ETH_ALEN);
1694
1695                 switch (enc->alg) {
1696                 case IW_ENCODE_ALG_NONE:
1697                         if(priv->reg.privacy_invoked){
1698                                 priv->reg.privacy_invoked = 0x00;
1699                                 commit |= SME_WEP_FLAG;
1700                         }
1701                         priv->wpa.key[index].key_len = 0;
1702
1703                         break;
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;
1709                         }
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);
1715                         }
1716                         break;
1717                 case IW_ENCODE_ALG_TKIP:
1718                         if(!priv->reg.privacy_invoked){
1719                                 priv->reg.privacy_invoked = 0x01;
1720                                 commit |= SME_WEP_FLAG;
1721                         }
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],
1728                                                &enc->key[16],8);
1729                                         memcpy(&priv->wpa.key[index].rx_mic_key[0],
1730                                                &enc->key[16],8);
1731                                 }else{
1732                                         memcpy(&priv->wpa.key[index].tx_mic_key[0],
1733                                                &enc->key[16],8);
1734                                         memcpy(&priv->wpa.key[index].rx_mic_key[0],
1735                                                &enc->key[24],8);
1736                                 }
1737                                 commit |= (SME_WEP_VAL1 << index);
1738                         }
1739                         break;
1740                 default:
1741                         return -EINVAL;
1742                 }
1743                 priv->wpa.key[index].alg=enc->alg;
1744         }
1745         else
1746                 return -EINVAL;
1747
1748         if(commit){
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);
1755         }
1756
1757         return 0;
1758 }
1759
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)
1764 {
1765         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1766
1767         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
1768
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) */
1775         return 0;
1776 }
1777
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)
1782 {
1783         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1784         struct iw_pmksa *pmksa ;
1785         int i;
1786         struct pmk_t *pmk;
1787         struct list_head *ptr;
1788
1789         DPRINTK(2,"\n");
1790
1791         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
1792
1793         if(!extra){
1794                 return -EINVAL;
1795         }
1796         pmksa = (struct iw_pmksa *)extra;
1797         DPRINTK(2,"cmd=%d\n",pmksa->cmd);
1798
1799         switch(pmksa->cmd){
1800         case IW_PMKSA_ADD:
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))
1805                                         break;
1806                         }
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++;
1811                 }
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);
1818                                         break;
1819                                 }
1820                         }
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))
1826                                                         break;
1827                                         }
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++;
1832                                 }
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);
1838                                 }
1839                         }
1840                 }
1841                 break;
1842         case IW_PMKSA_REMOVE:
1843                 if(list_empty(&priv->pmklist.head)){ /* list empty */
1844                         return -EINVAL;
1845                 }
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);
1853                                         break;
1854                                 }
1855                         }
1856                         if(ptr == &priv->pmklist.head){ /* not find address. */
1857                                 return 0;
1858                         }
1859                 }
1860                 break;
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);
1866                 break;
1867         default:
1868                 return -EINVAL;
1869         }
1870
1871         hostif_sme_enqueue(priv, SME_SET_PMKSA);
1872         return 0;
1873 }
1874
1875 static struct iw_statistics *ks_get_wireless_stats(struct net_device *dev)
1876 {
1877
1878         ks_wlan_private *priv = (ks_wlan_private *) netdev_priv(dev);
1879                 struct iw_statistics *wstats = &priv->wstats;
1880
1881         if(!atomic_read(&update_phyinfo)){
1882                 if (priv->dev_state < DEVICE_STATE_READY)
1883                         return NULL; /* not finished initialize */
1884                 else
1885                         return wstats;
1886         }
1887
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        */
1896
1897                 return wstats;
1898 }
1899
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)
1904 {
1905         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1906         DPRINTK(2,"\n");
1907
1908         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
1909
1910         if(!(*uwrq))
1911                 return  -EINVAL;
1912
1913         hostif_sme_enqueue(priv, SME_STOP_REQUEST);
1914         return 0;
1915 }
1916
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)
1922 {
1923         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
1924         struct iw_mlme *mlme = (struct iw_mlme *)extra;
1925         __u32 mode;
1926
1927         DPRINTK(2, ":%d :%d\n", mlme->cmd, mlme->reason_code);
1928
1929         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
1930
1931         switch (mlme->cmd) {
1932         case IW_MLME_DEAUTH:
1933                 if (mlme->reason_code == WLAN_REASON_MIC_FAILURE) {
1934                         return 0;
1935                 }
1936         case IW_MLME_DISASSOC:
1937                 mode = 1;
1938                 return ks_wlan_set_stop_request(dev, NULL, &mode, NULL);
1939         default:
1940                 return -EOPNOTSUPP;  /* Not Support */
1941         }
1942 }
1943
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)
1948 {
1949         strcpy(extra, KS_WLAN_DRIVER_VERSION_INFO);
1950         dwrq->length = strlen(KS_WLAN_DRIVER_VERSION_INFO)+1;
1951         return 0;
1952 }
1953
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)
1958 {
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;
1962         return 0;
1963 }
1964
1965 #if 0
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)
1970 {
1971         ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
1972
1973         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
1974
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);
1982         }else
1983                 return  -EINVAL;
1984         return 0;
1985 }
1986
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)
1991 {
1992         ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
1993
1994         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
1995
1996         *uwrq = ((priv->connect_status & FORCE_DISCONNECT) ? 1 : 0 );
1997         return 0;
1998 }
1999
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)
2004 {
2005         ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2006
2007         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
2008
2009         *uwrq = (priv->connect_status & CONNECT_STATUS_MASK);
2010         return 0;
2011 }
2012 #endif
2013
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)
2018 {
2019         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2020
2021         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
2022
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;
2027         }else
2028                 return  -EINVAL;
2029
2030         priv->need_commit |= SME_MODE_SET;
2031         return -EINPROGRESS;            /* Call commit handler */
2032
2033 }
2034
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)
2039 {
2040         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2041
2042         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
2043
2044         *uwrq = priv->reg.preamble;
2045         return 0;
2046 }
2047
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)
2052 {
2053         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2054
2055         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
2056
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;
2062                  else
2063                          return  -EINVAL;
2064         }else if(*uwrq == POWMGT_SAVE2_MODE){  /* 2 */
2065                 if(priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2066                         priv->reg.powermgt = POWMGT_SAVE2_MODE;
2067                 else
2068                         return -EINVAL;
2069         }else
2070                 return  -EINVAL;
2071
2072         hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
2073
2074         return 0;
2075 }
2076
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)
2081 {
2082         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2083
2084         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
2085
2086         *uwrq = priv->reg.powermgt;
2087         return 0;
2088 }
2089
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)
2094 {
2095         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2096
2097         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
2098
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;
2103         }else
2104                 return  -EINVAL;
2105
2106         return 0;
2107 }
2108
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)
2113 {
2114         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2115
2116         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
2117
2118         *uwrq = priv->reg.scan_type;
2119         return 0;
2120 }
2121 #if 0
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)
2126 {
2127         ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2128         unsigned char *wbuff = NULL;
2129
2130         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
2131
2132         wbuff = (unsigned char *)kmalloc(dwrq->length, GFP_ATOMIC);
2133         if(!wbuff)
2134                         return  -EFAULT;
2135         memcpy(wbuff, extra, dwrq->length);
2136
2137         /* write to device */
2138         ks_wlan_hw_tx( priv, wbuff, dwrq->length, NULL, NULL, NULL);
2139
2140         return 0;
2141 }
2142
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)
2147 {
2148         ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2149         unsigned short read_length;
2150
2151         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
2152
2153         if(!atomic_read(&priv->event_count)){
2154                 if (priv->dev_state < DEVICE_STATE_BOOT) { /* Remove device */
2155                                 read_length = 4;
2156                         memset(extra,0xff,read_length);
2157                         dwrq->length = read_length;
2158                         return 0;
2159                 }
2160                 read_length = 0;
2161                 memset(extra,0,1);
2162                 dwrq->length = 0;
2163                 return 0;
2164         }
2165
2166         if(atomic_read(&priv->event_count)>0)
2167                         atomic_dec(&priv->event_count);
2168
2169         spin_lock(&priv->dev_read_lock);        /* request spin lock */
2170
2171                 /* Copy length max size 0x07ff */
2172         if(priv->dev_size[priv->dev_count] > 2047)
2173                 read_length = 2047;
2174         else
2175                 read_length = priv->dev_size[priv->dev_count];
2176
2177         /* Copy data */
2178         memcpy(extra, &(priv->dev_data[priv->dev_count][0]), read_length);
2179
2180         spin_unlock(&priv->dev_read_lock); /* release spin lock */
2181
2182         /* Initialize */
2183         priv->dev_data[priv->dev_count] = 0;
2184         priv->dev_size[priv->dev_count] = 0;
2185
2186         priv->dev_count++;
2187         if(priv->dev_count == DEVICE_STOCK_COUNT)
2188                          priv->dev_count=0;
2189
2190         /* Set read size */
2191         dwrq->length = read_length;
2192
2193         return 0;
2194 }
2195 #endif
2196
2197 #if 0
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)
2203 {
2204         ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2205         int i,j,len=0;
2206         char tmp[WEP_ASCII_BUFF_SIZE];
2207
2208         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
2209
2210         strcpy(tmp," WEP keys ASCII \n");
2211         len+=strlen(" WEP keys ASCII \n");
2212
2213         for(i=0;i<4;i++){
2214                 strcpy(tmp+len,"\t[");
2215                 len+=strlen("\t[");
2216                 tmp[len] = '1'+i;
2217                 len++;
2218                 strcpy(tmp+len,"] ");
2219                 len+=strlen("] ");
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] : ' ');
2225
2226                         strcpy(tmp+len,"]\n");
2227                         len+=strlen("]\n");
2228                 }
2229                 else{
2230                         strcpy(tmp+len,"off\n");
2231                         len+=strlen("off\n");
2232                 }
2233         }
2234
2235         memcpy(extra, tmp, len);
2236         dwrq->length = len+1;
2237         return 0;
2238 }
2239 #endif
2240
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)
2245 {
2246         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2247
2248         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
2249
2250         if(*uwrq >= BEACON_LOST_COUNT_MIN &&
2251            *uwrq <= BEACON_LOST_COUNT_MAX){
2252                 priv->reg.beacon_lost_count = *uwrq;
2253         }else
2254                 return  -EINVAL;
2255
2256         if(priv->reg.operation_mode == MODE_INFRASTRUCTURE){
2257                 priv->need_commit |= SME_MODE_SET;
2258                 return -EINPROGRESS;            /* Call commit handler */
2259         }
2260         else
2261                 return 0;
2262 }
2263
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)
2268 {
2269         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2270
2271         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
2272
2273         *uwrq = priv->reg.beacon_lost_count;
2274         return 0;
2275 }
2276
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)
2281 {
2282         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2283
2284         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
2285
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;
2292         }else
2293                 return  -EINVAL;
2294
2295         priv->need_commit |= SME_MODE_SET;
2296         return -EINPROGRESS;            /* Call commit handler */
2297 }
2298
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)
2303 {
2304         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2305
2306         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
2307
2308         *uwrq = priv->reg.phy_type;
2309         return 0;
2310 }
2311
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)
2316 {
2317         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2318
2319         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
2320
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;
2327                 else
2328                         priv->reg.cts_mode = CTS_MODE_FALSE;
2329         }else
2330                 return  -EINVAL;
2331
2332         priv->need_commit |= SME_MODE_SET;
2333         return -EINPROGRESS;            /* Call commit handler */
2334 }
2335
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)
2340 {
2341         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2342
2343         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
2344
2345         *uwrq = priv->reg.cts_mode;
2346         return 0;
2347 }
2348
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)
2354 {
2355         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2356
2357         DPRINTK(2,"\n");
2358
2359         if(*uwrq == SLP_SLEEP){
2360                 priv->sleep_mode = *uwrq;
2361                 printk("SET_SLEEP_MODE %d\n", priv->sleep_mode);
2362
2363                 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2364                 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2365
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);
2370         }else{
2371                 printk("SET_SLEEP_MODE %d errror\n", *uwrq);
2372                 return  -EINVAL;
2373         }
2374
2375         return 0;
2376 }
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)
2382 {
2383         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2384
2385         DPRINTK(2, "GET_SLEEP_MODE %d\n", priv->sleep_mode);
2386         *uwrq = priv->sleep_mode;
2387
2388         return 0;
2389 }
2390
2391 #if 0
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)
2396 {
2397         ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2398
2399         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
2400
2401         if(*uwrq >= 0 && *uwrq <= 0xFFFF) /* 0-65535 */
2402                 priv->reg.phy_info_timer = (uint16_t)*uwrq;
2403         else
2404                 return  -EINVAL;
2405
2406         hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST);
2407
2408         return 0;
2409 }
2410
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)
2415 {
2416         ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2417
2418         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
2419
2420         *uwrq = priv->reg.phy_info_timer;
2421         return 0;
2422 }
2423 #endif
2424
2425 #ifdef WPS
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)
2430 {
2431         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2432         DPRINTK(2,"\n");
2433
2434         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
2435
2436         if(*uwrq == 0 || *uwrq == 1)
2437                 priv->wps.wps_enabled = *uwrq;
2438         else
2439                 return  -EINVAL;
2440
2441         hostif_sme_enqueue(priv, SME_WPS_ENABLE_REQUEST);
2442
2443         return 0;
2444 }
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)
2449 {
2450         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2451         DPRINTK(2,"\n");
2452
2453         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
2454
2455         *uwrq = priv->wps.wps_enabled;
2456         printk("return=%d\n", *uwrq);
2457
2458         return 0;
2459 }
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)
2465 {
2466         uint8_t *p = extra;
2467         unsigned char len;
2468         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2469
2470         DPRINTK(2,"\n");
2471
2472         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
2473
2474         DPRINTK(2,"dwrq->length=%d\n", dwrq->length);
2475
2476         /* length check */
2477         if(p[1] + 2  != dwrq->length  || dwrq->length > 256  ){
2478                 return -EINVAL;
2479         }
2480
2481         priv->wps.ielen = p[1] + 2 + 1;  /* IE header + IE + sizeof(len) */
2482         len = p[1] + 2;              /* IE header + IE */
2483
2484         memcpy(priv->wps.ie, &len, sizeof(len));
2485         p = memcpy(priv->wps.ie+1, p, len);
2486
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]);
2490
2491         hostif_sme_enqueue(priv, SME_WPS_PROBE_REQUEST);
2492
2493         return 0;
2494 }
2495 #if 0
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)
2501 {
2502         ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2503         DPRINTK(2,"\n");
2504
2505         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
2506
2507         return 0;
2508 }
2509 #endif
2510 #endif /* WPS */
2511
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)
2516 {
2517         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2518
2519         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
2520
2521         if(*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2522                 priv->gain.TxGain = (uint8_t)*uwrq;
2523         else
2524                 return  -EINVAL;
2525
2526         if(priv->gain.TxGain < 0xFF)
2527                 priv->gain.TxMode = 1;
2528         else
2529                 priv->gain.TxMode = 0;
2530
2531
2532         hostif_sme_enqueue(priv, SME_SET_GAIN);
2533         return  0;
2534 }
2535
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)
2540 {
2541         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2542
2543         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
2544
2545         *uwrq = priv->gain.TxGain;
2546         hostif_sme_enqueue(priv, SME_GET_GAIN);
2547         return 0;
2548 }
2549
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)
2554 {
2555         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2556
2557         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
2558
2559         if(*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2560                 priv->gain.RxGain = (uint8_t)*uwrq;
2561         else
2562                 return  -EINVAL;
2563
2564         if(priv->gain.RxGain < 0xFF)
2565                 priv->gain.RxMode = 1;
2566         else
2567                 priv->gain.RxMode = 0;
2568
2569         hostif_sme_enqueue(priv, SME_SET_GAIN);
2570         return  0;
2571 }
2572
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)
2577 {
2578         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2579
2580         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
2581
2582         *uwrq = priv->gain.RxGain;
2583         hostif_sme_enqueue(priv, SME_GET_GAIN);
2584         return 0;
2585 }
2586 #if 0
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)
2591 {
2592         ks_wlan_private *priv = (ks_wlan_private *)dev->priv;
2593
2594         if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; }  /* for SLEEP MODE */
2595
2596         if(*uwrq >= 0x9 && *uwrq <= 0xF) /* 0x9-0xf */
2597                 priv->region = (uint8_t)*uwrq;
2598         else
2599                 return  -EINVAL;
2600
2601         hostif_sme_enqueue(priv, SME_SET_REGION);
2602         return  0;
2603 }
2604 #endif
2605
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)
2610 {
2611         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2612
2613         *uwrq = priv->eeprom_checksum;
2614         return 0;
2615 }
2616
2617 static void print_hif_event(int event){
2618
2619         switch(event){
2620         case HIF_DATA_REQ       :
2621                 printk("HIF_DATA_REQ\n");
2622                 break;
2623         case HIF_DATA_IND       :
2624                 printk("HIF_DATA_IND\n");
2625                 break;
2626         case HIF_MIB_GET_REQ    :
2627                 printk("HIF_MIB_GET_REQ\n");
2628                 break;
2629         case HIF_MIB_GET_CONF   :
2630                 printk("HIF_MIB_GET_CONF\n");
2631                 break;
2632         case HIF_MIB_SET_REQ    :
2633                 printk("HIF_MIB_SET_REQ\n");
2634                 break;
2635         case HIF_MIB_SET_CONF   :
2636                 printk("HIF_MIB_SET_CONF\n");
2637                 break;
2638         case HIF_POWERMGT_REQ   :
2639                 printk("HIF_POWERMGT_REQ\n");
2640                 break;
2641         case HIF_POWERMGT_CONF  :
2642                 printk("HIF_POWERMGT_CONF\n");
2643                 break;
2644         case HIF_START_REQ      :
2645                 printk("HIF_START_REQ\n");
2646                 break;
2647         case HIF_START_CONF     :
2648                 printk("HIF_START_CONF\n");
2649                 break;
2650         case HIF_CONNECT_IND    :
2651                 printk("HIF_CONNECT_IND\n");
2652                 break;
2653         case HIF_STOP_REQ       :
2654                 printk("HIF_STOP_REQ\n");
2655                 break;
2656         case HIF_STOP_CONF      :
2657                 printk("HIF_STOP_CONF\n");
2658                 break;
2659         case HIF_PS_ADH_SET_REQ :
2660                 printk("HIF_PS_ADH_SET_REQ\n");
2661                 break;
2662         case HIF_PS_ADH_SET_CONF:
2663                 printk("HIF_PS_ADH_SET_CONF\n");
2664                 break;
2665         case HIF_INFRA_SET_REQ  :
2666                 printk("HIF_INFRA_SET_REQ\n");
2667                 break;
2668         case HIF_INFRA_SET_CONF :
2669                 printk("HIF_INFRA_SET_CONF\n");
2670                 break;
2671         case HIF_ADH_SET_REQ    :
2672                 printk("HIF_ADH_SET_REQ\n");
2673                 break;
2674         case HIF_ADH_SET_CONF   :
2675                 printk("HIF_ADH_SET_CONF\n");
2676                 break;
2677         case HIF_AP_SET_REQ     :
2678                 printk("HIF_AP_SET_REQ\n");
2679                 break;
2680         case HIF_AP_SET_CONF    :
2681                 printk("HIF_AP_SET_CONF\n");
2682                 break;
2683         case HIF_ASSOC_INFO_IND :
2684                 printk("HIF_ASSOC_INFO_IND\n");
2685                 break;
2686         case HIF_MIC_FAILURE_REQ:
2687                 printk("HIF_MIC_FAILURE_REQ\n");
2688                 break;
2689         case HIF_MIC_FAILURE_CONF       :
2690                 printk("HIF_MIC_FAILURE_CONF\n");
2691                 break;
2692         case HIF_SCAN_REQ       :
2693                 printk("HIF_SCAN_REQ\n");
2694                 break;
2695         case HIF_SCAN_CONF      :
2696                 printk("HIF_SCAN_CONF\n");
2697                 break;
2698         case HIF_PHY_INFO_REQ   :
2699                 printk("HIF_PHY_INFO_REQ\n");
2700                 break;
2701         case HIF_PHY_INFO_CONF  :
2702                 printk("HIF_PHY_INFO_CONF\n");
2703                 break;
2704         case HIF_SLEEP_REQ      :
2705                 printk("HIF_SLEEP_REQ\n");
2706                 break;
2707         case HIF_SLEEP_CONF     :
2708                 printk("HIF_SLEEP_CONF\n");
2709                 break;
2710         case HIF_PHY_INFO_IND   :
2711                 printk("HIF_PHY_INFO_IND\n");
2712                 break;
2713         case HIF_SCAN_IND       :
2714                 printk("HIF_SCAN_IND\n");
2715                 break;
2716         case HIF_INFRA_SET2_REQ :
2717                 printk("HIF_INFRA_SET2_REQ\n");
2718                 break;
2719         case HIF_INFRA_SET2_CONF:
2720                 printk("HIF_INFRA_SET2_CONF\n");
2721                 break;
2722         case HIF_ADH_SET2_REQ   :
2723                 printk("HIF_ADH_SET2_REQ\n");
2724                 break;
2725         case HIF_ADH_SET2_CONF  :
2726                 printk("HIF_ADH_SET2_CONF\n");
2727         }
2728 }
2729
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)
2734 {
2735         int i,event;
2736         ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
2737
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);
2741         }
2742         return 0;
2743 }
2744
2745 /* Structures to export the Wireless Handlers */
2746
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" },
2751 #ifdef WPS
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" },
2755 #endif /* WPS */
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" },
2776 };
2777 static const iw_handler         ks_wlan_handler[] =
2778 {
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 -- */
2849 };
2850
2851 /* private_handler */
2852 static const iw_handler         ks_wlan_private_handler[] =
2853 {
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 */
2858 #ifdef WPS
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 */
2862 #else
2863         (iw_handler) NULL,                              /*  4 */
2864         (iw_handler) NULL,                              /*  5 */
2865         (iw_handler) NULL,                              /*  6 */
2866 #endif /* WPS */
2867
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 */
2893 };
2894
2895 static const struct iw_handler_def      ks_wlan_handler_def =
2896 {
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,
2904 };
2905
2906
2907 static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2908 {
2909         int rc = 0;
2910         struct iwreq *wrq = (struct iwreq *) rq;
2911         switch (cmd) {
2912         case SIOCIWFIRSTPRIV+20: /* KS_WLAN_SET_STOP_REQ */
2913                 rc = ks_wlan_set_stop_request(dev, NULL, &(wrq->u.mode), NULL);
2914                 break;
2915         // All other calls are currently unsupported
2916         default:
2917                 rc = -EOPNOTSUPP;
2918         }
2919
2920         DPRINTK(5,"return=%d\n",rc);
2921         return rc;
2922 }
2923
2924
2925 static
2926 struct net_device_stats *ks_wlan_get_stats(struct net_device *dev)
2927 {
2928         ks_wlan_private *priv = netdev_priv(dev);
2929
2930         if (priv->dev_state < DEVICE_STATE_READY) {
2931                                 return NULL; /* not finished initialize */
2932                 }
2933
2934         return &priv->nstats;
2935 }
2936
2937 static
2938 int ks_wlan_set_mac_address(struct net_device *dev, void *addr)
2939 {
2940         ks_wlan_private *priv = netdev_priv(dev);
2941         struct sockaddr *mac_addr=(struct sockaddr *)addr;
2942         if (netif_running(dev))
2943                 return -EBUSY;
2944         memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
2945         memcpy(priv->eth_addr, mac_addr->sa_data, ETH_ALEN);
2946
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]);
2952         return 0;
2953 }
2954
2955
2956 static
2957 void ks_wlan_tx_timeout(struct net_device *dev)
2958 {
2959                 ks_wlan_private *priv = netdev_priv(dev);
2960
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);
2964         }
2965         priv->nstats.tx_errors++;
2966         netif_wake_queue(dev);
2967
2968         return;
2969 }
2970
2971 static
2972 int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev)
2973 {
2974         ks_wlan_private *priv = netdev_priv(dev);
2975         int rc = 0;
2976
2977         DPRINTK(3,"in_interrupt()=%ld\n",in_interrupt());
2978
2979         if ( skb == NULL ) {
2980                 printk( KERN_ERR "ks_wlan:  skb == NULL!!!\n" );
2981                 return 0;
2982         }
2983         if (priv->dev_state < DEVICE_STATE_READY) {
2984                 dev_kfree_skb(skb);
2985                 return 0; /* not finished initialize */
2986                 }
2987
2988         if(netif_running(dev))
2989                 netif_stop_queue(dev);
2990
2991         rc = hostif_data_request(priv, skb);
2992         dev->trans_start = jiffies;
2993
2994         DPRINTK(4,"rc=%d\n",rc);
2995         if (rc){
2996                 rc=0;
2997         }
2998
2999         return rc;
3000 }
3001
3002 void send_packet_complete(void *arg1, void *arg2)
3003 {
3004         ks_wlan_private *priv = (ks_wlan_private *)arg1;
3005         struct sk_buff *packet = (struct sk_buff *)arg2;
3006
3007                 DPRINTK(3,"\n");
3008
3009                 priv->nstats.tx_bytes += packet->len;
3010         priv->nstats.tx_packets++;
3011
3012         if(netif_queue_stopped(priv->net_dev))
3013                         netif_wake_queue(priv->net_dev);
3014
3015         if(packet){
3016                 dev_kfree_skb(packet);
3017                 packet=NULL;
3018         }
3019
3020 }
3021
3022 /* Set or clear the multicast filter for this adaptor.
3023    This routine is not state sensitive and need not be SMP locked. */
3024 static
3025 void ks_wlan_set_multicast_list(struct net_device *dev)
3026 {
3027         ks_wlan_private *priv = netdev_priv(dev);
3028
3029         DPRINTK(4,"\n");
3030         if (priv->dev_state < DEVICE_STATE_READY) {
3031                                 return ; /* not finished initialize */
3032         }
3033         hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST);
3034
3035         return;
3036 }
3037
3038 static
3039 int ks_wlan_open(struct net_device *dev)
3040 {
3041         ks_wlan_private *priv = netdev_priv(dev);
3042
3043         priv->cur_rx = 0;
3044
3045         if(!priv->mac_address_valid){
3046                 printk(KERN_ERR "ks_wlan : %s Not READY !!\n", dev->name);
3047                 return -EBUSY;
3048         }
3049         else
3050                 netif_start_queue (dev);
3051
3052         return 0;
3053 }
3054
3055 static
3056 int ks_wlan_close(struct net_device *dev)
3057 {
3058
3059         netif_stop_queue (dev);
3060
3061         DPRINTK(4, "%s: Shutting down ethercard, status was 0x%4.4x.\n",
3062                 dev->name, 0x00);
3063
3064         return 0;
3065 }
3066
3067
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};
3072
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,
3082 };
3083
3084 int ks_wlan_net_start(struct net_device *dev)
3085 {
3086         ks_wlan_private *priv;
3087         /* int rc; */
3088
3089         priv = netdev_priv(dev);
3090         priv->mac_address_valid = 0;
3091         priv->need_commit = 0;
3092
3093         priv->device_open_status = 1;
3094
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;
3100
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;
3111
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;
3116
3117         netif_carrier_off(dev);
3118
3119         return 0;
3120 }
3121
3122
3123 int ks_wlan_net_stop(struct net_device *dev)
3124 {
3125         ks_wlan_private *priv = netdev_priv(dev);
3126
3127         int ret = 0;
3128         priv->device_open_status = 0;
3129         del_timer_sync(&update_phyinfo_timer);
3130
3131         if(netif_running(dev))
3132                 netif_stop_queue(dev);
3133
3134         return ret;
3135 }
3136
3137 int ks_wlan_reset(struct net_device *dev)
3138 {
3139         return 0;
3140 }