staging: ks7010: drop private handler for driver version
[cascardo/linux.git] / drivers / staging / ks7010 / ks_wlan_net.c
1 /*
2  *   Driver for KeyStream 11b/g wireless LAN
3  *
4  *   Copyright (C) 2005-2008 KeyStream Corp.
5  *   Copyright (C) 2009 Renesas Technology Corp.
6  *
7  *   This program is free software; you can redistribute it and/or modify
8  *   it under the terms of the GNU General Public License version 2 as
9  *   published by the Free Software Foundation.
10  */
11
12 #include <linux/version.h>
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/compiler.h>
16 #include <linux/init.h>
17 #include <linux/ioport.h>
18 #include <linux/netdevice.h>
19 #include <linux/etherdevice.h>
20 #include <linux/if_arp.h>
21 #include <linux/rtnetlink.h>
22 #include <linux/delay.h>
23 #include <linux/completion.h>
24 #include <linux/mii.h>
25 #include <linux/pci.h>
26 #include <linux/ctype.h>
27 #include <linux/timer.h>
28 #include <asm/atomic.h>
29 #include <linux/io.h>
30 #include <asm/uaccess.h>
31
32 static int wep_on_off;
33 #define WEP_OFF         0
34 #define WEP_ON_64BIT    1
35 #define WEP_ON_128BIT   2
36
37 #include "ks_wlan.h"
38 #include "ks_hostif.h"
39 #include "ks_wlan_ioctl.h"
40
41 /* Include Wireless Extension definition and check version */
42 #include <linux/wireless.h>
43 #define WIRELESS_SPY    /* enable iwspy support */
44 #include <net/iw_handler.h>     /* New driver API */
45
46 /* Frequency list (map channels to frequencies) */
47 static const long frequency_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
48         2447, 2452, 2457, 2462, 2467, 2472, 2484
49 };
50
51 /* A few details needed for WEP (Wireless Equivalent Privacy) */
52 #define MAX_KEY_SIZE 13 /* 128 (?) bits */
53 #define MIN_KEY_SIZE  5 /* 40 bits RC4 - WEP */
54 typedef struct wep_key_t {
55         u16 len;
56         u8 key[16];     /* 40-bit and 104-bit keys */
57 } wep_key_t;
58
59 /* Backward compatibility */
60 #ifndef IW_ENCODE_NOKEY
61 #define IW_ENCODE_NOKEY 0x0800  /* Key is write only, so not present */
62 #define IW_ENCODE_MODE  (IW_ENCODE_DISABLED | IW_ENCODE_RESTRICTED | IW_ENCODE_OPEN)
63 #endif /* IW_ENCODE_NOKEY */
64
65 /* List of Wireless Handlers (new API) */
66 static const struct iw_handler_def ks_wlan_handler_def;
67
68 #define KSC_OPNOTSUPP   /* Operation Not Support */
69
70 /*
71  *      function prototypes
72  */
73 extern int ks_wlan_hw_tx(struct ks_wlan_private *priv, void *p,
74                          unsigned long size,
75                          void (*complete_handler) (void *arg1, void *arg2),
76                          void *arg1, void *arg2);
77 static int ks_wlan_open(struct net_device *dev);
78 static void ks_wlan_tx_timeout(struct net_device *dev);
79 static int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev);
80 static int ks_wlan_close(struct net_device *dev);
81 static void ks_wlan_set_multicast_list(struct net_device *dev);
82 static struct net_device_stats *ks_wlan_get_stats(struct net_device *dev);
83 static int ks_wlan_set_mac_address(struct net_device *dev, void *addr);
84 static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq,
85                                 int cmd);
86
87 static atomic_t update_phyinfo;
88 static struct timer_list update_phyinfo_timer;
89 static
90 int ks_wlan_update_phy_information(struct ks_wlan_private *priv)
91 {
92         struct iw_statistics *wstats = &priv->wstats;
93
94         DPRINTK(4, "in_interrupt = %ld\n", in_interrupt());
95
96         if (priv->dev_state < DEVICE_STATE_READY) {
97                 return -1;      /* not finished initialize */
98         }
99         if (atomic_read(&update_phyinfo))
100                 return 1;
101
102         /* The status */
103         wstats->status = priv->reg.operation_mode;      /* Operation mode */
104
105         /* Signal quality and co. But where is the noise level ??? */
106         hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST);
107
108         /* interruptible_sleep_on_timeout(&priv->confirm_wait, HZ/2); */
109         if (!wait_for_completion_interruptible_timeout
110             (&priv->confirm_wait, HZ / 2)) {
111                 DPRINTK(1, "wait time out!!\n");
112         }
113
114         atomic_inc(&update_phyinfo);
115         update_phyinfo_timer.expires = jiffies + HZ;    /* 1sec */
116         add_timer(&update_phyinfo_timer);
117
118         return 0;
119 }
120
121 static
122 void ks_wlan_update_phyinfo_timeout(unsigned long ptr)
123 {
124         DPRINTK(4, "in_interrupt = %ld\n", in_interrupt());
125         atomic_set(&update_phyinfo, 0);
126 }
127
128 int ks_wlan_setup_parameter(struct ks_wlan_private *priv,
129                             unsigned int commit_flag)
130 {
131         DPRINTK(2, "\n");
132
133         hostif_sme_enqueue(priv, SME_STOP_REQUEST);
134
135         if (commit_flag & SME_RTS)
136                 hostif_sme_enqueue(priv, SME_RTS_THRESHOLD_REQUEST);
137         if (commit_flag & SME_FRAG)
138                 hostif_sme_enqueue(priv, SME_FRAGMENTATION_THRESHOLD_REQUEST);
139
140         if (commit_flag & SME_WEP_INDEX)
141                 hostif_sme_enqueue(priv, SME_WEP_INDEX_REQUEST);
142         if (commit_flag & SME_WEP_VAL1)
143                 hostif_sme_enqueue(priv, SME_WEP_KEY1_REQUEST);
144         if (commit_flag & SME_WEP_VAL2)
145                 hostif_sme_enqueue(priv, SME_WEP_KEY2_REQUEST);
146         if (commit_flag & SME_WEP_VAL3)
147                 hostif_sme_enqueue(priv, SME_WEP_KEY3_REQUEST);
148         if (commit_flag & SME_WEP_VAL4)
149                 hostif_sme_enqueue(priv, SME_WEP_KEY4_REQUEST);
150         if (commit_flag & SME_WEP_FLAG)
151                 hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
152
153         if (commit_flag & SME_RSN) {
154                 hostif_sme_enqueue(priv, SME_RSN_ENABLED_REQUEST);
155                 hostif_sme_enqueue(priv, SME_RSN_MODE_REQUEST);
156         }
157         if (commit_flag & SME_RSN_MULTICAST)
158                 hostif_sme_enqueue(priv, SME_RSN_MCAST_REQUEST);
159         if (commit_flag & SME_RSN_UNICAST)
160                 hostif_sme_enqueue(priv, SME_RSN_UCAST_REQUEST);
161         if (commit_flag & SME_RSN_AUTH)
162                 hostif_sme_enqueue(priv, SME_RSN_AUTH_REQUEST);
163
164         hostif_sme_enqueue(priv, SME_MODE_SET_REQUEST);
165
166         hostif_sme_enqueue(priv, SME_START_REQUEST);
167
168         return 0;
169 }
170
171 /*
172  * Initial Wireless Extension code for Ks_Wlannet driver by :
173  *      Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00
174  * Conversion to new driver API by :
175  *      Jean Tourrilhes <jt@hpl.hp.com> - HPL - 26 March 02
176  * Javier also did a good amount of work here, adding some new extensions
177  * and fixing my code. Let's just say that without him this code just
178  * would not work at all... - Jean II
179  */
180
181 /*------------------------------------------------------------------*/
182 /* Wireless Handler : get protocol name */
183 static int ks_wlan_get_name(struct net_device *dev,
184                             struct iw_request_info *info, char *cwrq,
185                             char *extra)
186 {
187         struct ks_wlan_private *priv =
188             (struct ks_wlan_private *)netdev_priv(dev);
189
190         if (priv->sleep_mode == SLP_SLEEP) {
191                 return -EPERM;
192         }
193         /* for SLEEP MODE */
194         if (priv->dev_state < DEVICE_STATE_READY) {
195                 strcpy(cwrq, "NOT READY!");
196         } else if (priv->reg.phy_type == D_11B_ONLY_MODE) {
197                 strcpy(cwrq, "IEEE 802.11b");
198         } else if (priv->reg.phy_type == D_11G_ONLY_MODE) {
199                 strcpy(cwrq, "IEEE 802.11g");
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,
210                             struct iw_request_info *info, struct iw_freq *fwrq,
211                             char *extra)
212 {
213         struct ks_wlan_private *priv =
214             (struct ks_wlan_private *)netdev_priv(dev);
215         int rc = -EINPROGRESS;  /* Call commit handler */
216
217         if (priv->sleep_mode == SLP_SLEEP) {
218                 return -EPERM;
219         }
220
221         /* for SLEEP MODE */
222         /* If setting by frequency, convert to a channel */
223         if ((fwrq->e == 1) &&
224             (fwrq->m >= (int)2.412e8) && (fwrq->m <= (int)2.487e8)) {
225                 int f = fwrq->m / 100000;
226                 int c = 0;
227                 while ((c < 14) && (f != frequency_list[c]))
228                         c++;
229                 /* Hack to fall through... */
230                 fwrq->e = 0;
231                 fwrq->m = c + 1;
232         }
233         /* Setting by channel number */
234         if ((fwrq->m > 1000) || (fwrq->e > 0))
235                 rc = -EOPNOTSUPP;
236         else {
237                 int channel = fwrq->m;
238                 /* We should do a better check than that,
239                  * based on the card capability !!! */
240                 if ((channel < 1) || (channel > 14)) {
241                         printk(KERN_DEBUG
242                                "%s: New channel value of %d is invalid!\n",
243                                dev->name, fwrq->m);
244                         rc = -EINVAL;
245                 } else {
246                         /* Yes ! We can set it !!! */
247                         priv->reg.channel = (u8) (channel);
248                         priv->need_commit |= SME_MODE_SET;
249                 }
250         }
251
252         return rc;
253 }
254
255 /*------------------------------------------------------------------*/
256 /* Wireless Handler : get frequency */
257 static int ks_wlan_get_freq(struct net_device *dev,
258                             struct iw_request_info *info, struct iw_freq *fwrq,
259                             char *extra)
260 {
261         struct ks_wlan_private *priv =
262             (struct ks_wlan_private *)netdev_priv(dev);
263         int f;
264
265         if (priv->sleep_mode == SLP_SLEEP) {
266                 return -EPERM;
267         }
268         /* for SLEEP MODE */
269         if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
270                 f = (int)priv->current_ap.channel;
271         } else
272                 f = (int)priv->reg.channel;
273         fwrq->m = frequency_list[f - 1] * 100000;
274         fwrq->e = 1;
275
276         return 0;
277 }
278
279 /*------------------------------------------------------------------*/
280 /* Wireless Handler : set ESSID */
281 static int ks_wlan_set_essid(struct net_device *dev,
282                              struct iw_request_info *info,
283                              struct iw_point *dwrq, char *extra)
284 {
285         struct ks_wlan_private *priv =
286             (struct ks_wlan_private *)netdev_priv(dev);
287         size_t len;
288
289         DPRINTK(2, " %d\n", dwrq->flags);
290
291         if (priv->sleep_mode == SLP_SLEEP) {
292                 return -EPERM;
293         }
294
295         /* for SLEEP MODE */
296         /* Check if we asked for `any' */
297         if (dwrq->flags == 0) {
298                 /* Just send an empty SSID list */
299                 memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
300                 priv->reg.ssid.size = 0;
301         } else {
302 #if 1
303                 len = dwrq->length;
304                 /* iwconfig uses nul termination in SSID.. */
305                 if (len > 0 && extra[len - 1] == '\0')
306                         len--;
307
308                 /* Check the size of the string */
309                 if (len > IW_ESSID_MAX_SIZE) {
310                         return -EINVAL;
311                 }
312 #else
313                 /* Check the size of the string */
314                 if (dwrq->length > IW_ESSID_MAX_SIZE + 1) {
315                         return -E2BIG;
316                 }
317 #endif
318
319                 /* Set the SSID */
320                 memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
321
322 #if 1
323                 memcpy(priv->reg.ssid.body, extra, len);
324                 priv->reg.ssid.size = len;
325 #else
326                 memcpy(priv->reg.ssid.body, extra, dwrq->length);
327                 priv->reg.ssid.size = dwrq->length;
328 #endif
329         }
330         /* Write it to the card */
331         priv->need_commit |= SME_MODE_SET;
332
333 //      return  -EINPROGRESS;   /* Call commit handler */
334         ks_wlan_setup_parameter(priv, priv->need_commit);
335         priv->need_commit = 0;
336         return 0;
337 }
338
339 /*------------------------------------------------------------------*/
340 /* Wireless Handler : get ESSID */
341 static int ks_wlan_get_essid(struct net_device *dev,
342                              struct iw_request_info *info,
343                              struct iw_point *dwrq, char *extra)
344 {
345         struct ks_wlan_private *priv =
346             (struct ks_wlan_private *)netdev_priv(dev);
347
348         if (priv->sleep_mode == SLP_SLEEP) {
349                 return -EPERM;
350         }
351
352         /* for SLEEP MODE */
353         /* Note : if dwrq->flags != 0, we should
354          * get the relevant SSID from the SSID list... */
355         if (priv->reg.ssid.size) {
356                 /* Get the current SSID */
357                 memcpy(extra, priv->reg.ssid.body, priv->reg.ssid.size);
358 #if 0
359                 extra[priv->reg.ssid.size] = '\0';
360 #endif
361                 /* If none, we may want to get the one that was set */
362
363                 /* Push it out ! */
364 #if 1
365                 dwrq->length = priv->reg.ssid.size;
366 #else
367                 dwrq->length = priv->reg.ssid.size + 1;
368 #endif
369                 dwrq->flags = 1;        /* active */
370         } else {
371 #if 1
372                 dwrq->length = 0;
373 #else
374                 extra[0] = '\0';
375                 dwrq->length = 1;
376 #endif
377                 dwrq->flags = 0;        /* ANY */
378         }
379
380         return 0;
381 }
382
383 /*------------------------------------------------------------------*/
384 /* Wireless Handler : set AP address */
385 static int ks_wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
386                            struct sockaddr *ap_addr, char *extra)
387 {
388         struct ks_wlan_private *priv =
389             (struct ks_wlan_private *)netdev_priv(dev);
390
391         DPRINTK(2, "\n");
392
393         if (priv->sleep_mode == SLP_SLEEP) {
394                 return -EPERM;
395         }
396         /* for SLEEP MODE */
397         if (priv->reg.operation_mode == MODE_ADHOC ||
398             priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
399                 memcpy(priv->reg.bssid, (u8 *) & ap_addr->sa_data, ETH_ALEN);
400
401                 if (is_valid_ether_addr((u8 *) priv->reg.bssid)) {
402                         priv->need_commit |= SME_MODE_SET;
403                 }
404         } else {
405                 memset(priv->reg.bssid, 0x0, ETH_ALEN);
406                 return -EOPNOTSUPP;
407         }
408
409         DPRINTK(2, "bssid = %02x:%02x:%02x:%02x:%02x:%02x\n",
410                 priv->reg.bssid[0], priv->reg.bssid[1], priv->reg.bssid[2],
411                 priv->reg.bssid[3], priv->reg.bssid[4], priv->reg.bssid[5]);
412
413         /* Write it to the card */
414         if (priv->need_commit) {
415                 priv->need_commit |= SME_MODE_SET;
416                 return -EINPROGRESS;    /* Call commit handler */
417         }
418         return 0;
419 }
420
421 /*------------------------------------------------------------------*/
422 /* Wireless Handler : get AP address */
423 static int ks_wlan_get_wap(struct net_device *dev, struct iw_request_info *info,
424                            struct sockaddr *awrq, char *extra)
425 {
426         struct ks_wlan_private *priv =
427             (struct ks_wlan_private *)netdev_priv(dev);
428
429         if (priv->sleep_mode == SLP_SLEEP) {
430                 return -EPERM;
431         }
432         /* for SLEEP MODE */
433         if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
434                 memcpy(awrq->sa_data, &(priv->current_ap.bssid[0]), ETH_ALEN);
435         } else {
436                 memset(awrq->sa_data, 0, ETH_ALEN);
437         }
438
439         awrq->sa_family = ARPHRD_ETHER;
440
441         return 0;
442 }
443
444 /*------------------------------------------------------------------*/
445 /* Wireless Handler : set Nickname */
446 static int ks_wlan_set_nick(struct net_device *dev,
447                             struct iw_request_info *info, struct iw_point *dwrq,
448                             char *extra)
449 {
450         struct ks_wlan_private *priv =
451             (struct ks_wlan_private *)netdev_priv(dev);
452
453         if (priv->sleep_mode == SLP_SLEEP) {
454                 return -EPERM;
455         }
456
457         /* for SLEEP MODE */
458         /* Check the size of the string */
459         if (dwrq->length > 16 + 1) {
460                 return -E2BIG;
461         }
462         memset(priv->nick, 0, sizeof(priv->nick));
463         memcpy(priv->nick, extra, dwrq->length);
464
465         return -EINPROGRESS;    /* Call commit handler */
466 }
467
468 /*------------------------------------------------------------------*/
469 /* Wireless Handler : get Nickname */
470 static int ks_wlan_get_nick(struct net_device *dev,
471                             struct iw_request_info *info, struct iw_point *dwrq,
472                             char *extra)
473 {
474         struct ks_wlan_private *priv =
475             (struct ks_wlan_private *)netdev_priv(dev);
476
477         if (priv->sleep_mode == SLP_SLEEP) {
478                 return -EPERM;
479         }
480         /* for SLEEP MODE */
481         strncpy(extra, priv->nick, 16);
482         extra[16] = '\0';
483         dwrq->length = strlen(extra) + 1;
484
485         return 0;
486 }
487
488 /*------------------------------------------------------------------*/
489 /* Wireless Handler : set Bit-Rate */
490 static int ks_wlan_set_rate(struct net_device *dev,
491                             struct iw_request_info *info, struct iw_param *vwrq,
492                             char *extra)
493 {
494         struct ks_wlan_private *priv =
495             (struct ks_wlan_private *)netdev_priv(dev);
496         int i = 0;
497
498         if (priv->sleep_mode == SLP_SLEEP) {
499                 return -EPERM;
500         }
501         /* for SLEEP MODE */
502         if (priv->reg.phy_type == D_11B_ONLY_MODE) {
503                 if (vwrq->fixed == 1) {
504                         switch (vwrq->value) {
505                         case 11000000:
506                         case 5500000:
507                                 priv->reg.rate_set.body[0] =
508                                     (uint8_t) (vwrq->value / 500000);
509                                 break;
510                         case 2000000:
511                         case 1000000:
512                                 priv->reg.rate_set.body[0] =
513                                     ((uint8_t) (vwrq->value / 500000)) |
514                                     BASIC_RATE;
515                                 break;
516                         default:
517                                 return -EINVAL;
518                         }
519                         priv->reg.tx_rate = TX_RATE_FIXED;
520                         priv->reg.rate_set.size = 1;
521                 } else {        /* vwrq->fixed == 0 */
522                         if (vwrq->value > 0) {
523                                 switch (vwrq->value) {
524                                 case 11000000:
525                                         priv->reg.rate_set.body[3] =
526                                             TX_RATE_11M;
527                                         i++;
528                                 case 5500000:
529                                         priv->reg.rate_set.body[2] = TX_RATE_5M;
530                                         i++;
531                                 case 2000000:
532                                         priv->reg.rate_set.body[1] =
533                                             TX_RATE_2M | BASIC_RATE;
534                                         i++;
535                                 case 1000000:
536                                         priv->reg.rate_set.body[0] =
537                                             TX_RATE_1M | BASIC_RATE;
538                                         i++;
539                                         break;
540                                 default:
541                                         return -EINVAL;
542                                 }
543                                 priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
544                                 priv->reg.rate_set.size = i;
545                         } else {
546                                 priv->reg.rate_set.body[3] = TX_RATE_11M;
547                                 priv->reg.rate_set.body[2] = TX_RATE_5M;
548                                 priv->reg.rate_set.body[1] =
549                                     TX_RATE_2M | BASIC_RATE;
550                                 priv->reg.rate_set.body[0] =
551                                     TX_RATE_1M | BASIC_RATE;
552                                 priv->reg.tx_rate = TX_RATE_FULL_AUTO;
553                                 priv->reg.rate_set.size = 4;
554                         }
555                 }
556         } else {        /* D_11B_ONLY_MODE or  D_11BG_COMPATIBLE_MODE */
557                 if (vwrq->fixed == 1) {
558                         switch (vwrq->value) {
559                         case 54000000:
560                         case 48000000:
561                         case 36000000:
562                         case 18000000:
563                         case 9000000:
564                                 priv->reg.rate_set.body[0] =
565                                     (uint8_t) (vwrq->value / 500000);
566                                 break;
567                         case 24000000:
568                         case 12000000:
569                         case 11000000:
570                         case 6000000:
571                         case 5500000:
572                         case 2000000:
573                         case 1000000:
574                                 priv->reg.rate_set.body[0] =
575                                     ((uint8_t) (vwrq->value / 500000)) |
576                                     BASIC_RATE;
577                                 break;
578                         default:
579                                 return -EINVAL;
580                         }
581                         priv->reg.tx_rate = TX_RATE_FIXED;
582                         priv->reg.rate_set.size = 1;
583                 } else {        /* vwrq->fixed == 0 */
584                         if (vwrq->value > 0) {
585                                 switch (vwrq->value) {
586                                 case 54000000:
587                                         priv->reg.rate_set.body[11] =
588                                             TX_RATE_54M;
589                                         i++;
590                                 case 48000000:
591                                         priv->reg.rate_set.body[10] =
592                                             TX_RATE_48M;
593                                         i++;
594                                 case 36000000:
595                                         priv->reg.rate_set.body[9] =
596                                             TX_RATE_36M;
597                                         i++;
598                                 case 24000000:
599                                 case 18000000:
600                                 case 12000000:
601                                 case 11000000:
602                                 case 9000000:
603                                 case 6000000:
604                                         if (vwrq->value == 24000000) {
605                                                 priv->reg.rate_set.body[8] =
606                                                     TX_RATE_18M;
607                                                 i++;
608                                                 priv->reg.rate_set.body[7] =
609                                                     TX_RATE_9M;
610                                                 i++;
611                                                 priv->reg.rate_set.body[6] =
612                                                     TX_RATE_24M | BASIC_RATE;
613                                                 i++;
614                                                 priv->reg.rate_set.body[5] =
615                                                     TX_RATE_12M | BASIC_RATE;
616                                                 i++;
617                                                 priv->reg.rate_set.body[4] =
618                                                     TX_RATE_6M | BASIC_RATE;
619                                                 i++;
620                                                 priv->reg.rate_set.body[3] =
621                                                     TX_RATE_11M | BASIC_RATE;
622                                                 i++;
623                                         } else if (vwrq->value == 18000000) {
624                                                 priv->reg.rate_set.body[7] =
625                                                     TX_RATE_18M;
626                                                 i++;
627                                                 priv->reg.rate_set.body[6] =
628                                                     TX_RATE_9M;
629                                                 i++;
630                                                 priv->reg.rate_set.body[5] =
631                                                     TX_RATE_12M | BASIC_RATE;
632                                                 i++;
633                                                 priv->reg.rate_set.body[4] =
634                                                     TX_RATE_6M | BASIC_RATE;
635                                                 i++;
636                                                 priv->reg.rate_set.body[3] =
637                                                     TX_RATE_11M | BASIC_RATE;
638                                                 i++;
639                                         } else if (vwrq->value == 12000000) {
640                                                 priv->reg.rate_set.body[6] =
641                                                     TX_RATE_9M;
642                                                 i++;
643                                                 priv->reg.rate_set.body[5] =
644                                                     TX_RATE_12M | BASIC_RATE;
645                                                 i++;
646                                                 priv->reg.rate_set.body[4] =
647                                                     TX_RATE_6M | BASIC_RATE;
648                                                 i++;
649                                                 priv->reg.rate_set.body[3] =
650                                                     TX_RATE_11M | BASIC_RATE;
651                                                 i++;
652                                         } else if (vwrq->value == 11000000) {
653                                                 priv->reg.rate_set.body[5] =
654                                                     TX_RATE_9M;
655                                                 i++;
656                                                 priv->reg.rate_set.body[4] =
657                                                     TX_RATE_6M | BASIC_RATE;
658                                                 i++;
659                                                 priv->reg.rate_set.body[3] =
660                                                     TX_RATE_11M | BASIC_RATE;
661                                                 i++;
662                                         } else if (vwrq->value == 9000000) {
663                                                 priv->reg.rate_set.body[4] =
664                                                     TX_RATE_9M;
665                                                 i++;
666                                                 priv->reg.rate_set.body[3] =
667                                                     TX_RATE_6M | BASIC_RATE;
668                                                 i++;
669                                         } else {        /* vwrq->value == 6000000 */
670                                                 priv->reg.rate_set.body[3] =
671                                                     TX_RATE_6M | BASIC_RATE;
672                                                 i++;
673                                         }
674                                 case 5500000:
675                                         priv->reg.rate_set.body[2] =
676                                             TX_RATE_5M | BASIC_RATE;
677                                         i++;
678                                 case 2000000:
679                                         priv->reg.rate_set.body[1] =
680                                             TX_RATE_2M | BASIC_RATE;
681                                         i++;
682                                 case 1000000:
683                                         priv->reg.rate_set.body[0] =
684                                             TX_RATE_1M | BASIC_RATE;
685                                         i++;
686                                         break;
687                                 default:
688                                         return -EINVAL;
689                                 }
690                                 priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
691                                 priv->reg.rate_set.size = i;
692                         } else {
693                                 priv->reg.rate_set.body[11] = TX_RATE_54M;
694                                 priv->reg.rate_set.body[10] = TX_RATE_48M;
695                                 priv->reg.rate_set.body[9] = TX_RATE_36M;
696                                 priv->reg.rate_set.body[8] = TX_RATE_18M;
697                                 priv->reg.rate_set.body[7] = TX_RATE_9M;
698                                 priv->reg.rate_set.body[6] =
699                                     TX_RATE_24M | BASIC_RATE;
700                                 priv->reg.rate_set.body[5] =
701                                     TX_RATE_12M | BASIC_RATE;
702                                 priv->reg.rate_set.body[4] =
703                                     TX_RATE_6M | BASIC_RATE;
704                                 priv->reg.rate_set.body[3] =
705                                     TX_RATE_11M | BASIC_RATE;
706                                 priv->reg.rate_set.body[2] =
707                                     TX_RATE_5M | BASIC_RATE;
708                                 priv->reg.rate_set.body[1] =
709                                     TX_RATE_2M | BASIC_RATE;
710                                 priv->reg.rate_set.body[0] =
711                                     TX_RATE_1M | BASIC_RATE;
712                                 priv->reg.tx_rate = TX_RATE_FULL_AUTO;
713                                 priv->reg.rate_set.size = 12;
714                         }
715                 }
716         }
717
718         priv->need_commit |= SME_MODE_SET;
719
720         return -EINPROGRESS;    /* Call commit handler */
721 }
722
723 /*------------------------------------------------------------------*/
724 /* Wireless Handler : get Bit-Rate */
725 static int ks_wlan_get_rate(struct net_device *dev,
726                             struct iw_request_info *info, struct iw_param *vwrq,
727                             char *extra)
728 {
729         struct ks_wlan_private *priv =
730             (struct ks_wlan_private *)netdev_priv(dev);
731
732         DPRINTK(2, "in_interrupt = %ld update_phyinfo = %d\n",
733                 in_interrupt(), atomic_read(&update_phyinfo));
734
735         if (priv->sleep_mode == SLP_SLEEP) {
736                 return -EPERM;
737         }
738         /* for SLEEP MODE */
739         if (!atomic_read(&update_phyinfo)) {
740                 ks_wlan_update_phy_information(priv);
741         }
742         vwrq->value = ((priv->current_rate) & RATE_MASK) * 500000;
743         if (priv->reg.tx_rate == TX_RATE_FIXED)
744                 vwrq->fixed = 1;
745         else
746                 vwrq->fixed = 0;
747
748         return 0;
749 }
750
751 /*------------------------------------------------------------------*/
752 /* Wireless Handler : set RTS threshold */
753 static int ks_wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
754                            struct iw_param *vwrq, char *extra)
755 {
756         struct ks_wlan_private *priv =
757             (struct ks_wlan_private *)netdev_priv(dev);
758         int rthr = vwrq->value;
759
760         if (priv->sleep_mode == SLP_SLEEP) {
761                 return -EPERM;
762         }
763         /* for SLEEP MODE */
764         if (vwrq->disabled)
765                 rthr = 2347;
766         if ((rthr < 0) || (rthr > 2347)) {
767                 return -EINVAL;
768         }
769         priv->reg.rts = rthr;
770         priv->need_commit |= SME_RTS;
771
772         return -EINPROGRESS;    /* Call commit handler */
773 }
774
775 /*------------------------------------------------------------------*/
776 /* Wireless Handler : get RTS threshold */
777 static int ks_wlan_get_rts(struct net_device *dev, struct iw_request_info *info,
778                            struct iw_param *vwrq, char *extra)
779 {
780         struct ks_wlan_private *priv =
781             (struct ks_wlan_private *)netdev_priv(dev);
782
783         if (priv->sleep_mode == SLP_SLEEP) {
784                 return -EPERM;
785         }
786         /* for SLEEP MODE */
787         vwrq->value = priv->reg.rts;
788         vwrq->disabled = (vwrq->value >= 2347);
789         vwrq->fixed = 1;
790
791         return 0;
792 }
793
794 /*------------------------------------------------------------------*/
795 /* Wireless Handler : set Fragmentation threshold */
796 static int ks_wlan_set_frag(struct net_device *dev,
797                             struct iw_request_info *info, struct iw_param *vwrq,
798                             char *extra)
799 {
800         struct ks_wlan_private *priv =
801             (struct ks_wlan_private *)netdev_priv(dev);
802         int fthr = vwrq->value;
803
804         if (priv->sleep_mode == SLP_SLEEP) {
805                 return -EPERM;
806         }
807         /* for SLEEP MODE */
808         if (vwrq->disabled)
809                 fthr = 2346;
810         if ((fthr < 256) || (fthr > 2346)) {
811                 return -EINVAL;
812         }
813         fthr &= ~0x1;   /* Get an even value - is it really needed ??? */
814         priv->reg.fragment = fthr;
815         priv->need_commit |= SME_FRAG;
816
817         return -EINPROGRESS;    /* Call commit handler */
818 }
819
820 /*------------------------------------------------------------------*/
821 /* Wireless Handler : get Fragmentation threshold */
822 static int ks_wlan_get_frag(struct net_device *dev,
823                             struct iw_request_info *info, struct iw_param *vwrq,
824                             char *extra)
825 {
826         struct ks_wlan_private *priv =
827             (struct ks_wlan_private *)netdev_priv(dev);
828
829         if (priv->sleep_mode == SLP_SLEEP) {
830                 return -EPERM;
831         }
832         /* for SLEEP MODE */
833         vwrq->value = priv->reg.fragment;
834         vwrq->disabled = (vwrq->value >= 2346);
835         vwrq->fixed = 1;
836
837         return 0;
838 }
839
840 /*------------------------------------------------------------------*/
841 /* Wireless Handler : set Mode of Operation */
842 static int ks_wlan_set_mode(struct net_device *dev,
843                             struct iw_request_info *info, __u32 * uwrq,
844                             char *extra)
845 {
846         struct ks_wlan_private *priv =
847             (struct ks_wlan_private *)netdev_priv(dev);
848
849         DPRINTK(2, "mode=%d\n", *uwrq);
850
851         if (priv->sleep_mode == SLP_SLEEP) {
852                 return -EPERM;
853         }
854         /* for SLEEP MODE */
855         switch (*uwrq) {
856         case IW_MODE_ADHOC:
857                 priv->reg.operation_mode = MODE_ADHOC;
858                 priv->need_commit |= SME_MODE_SET;
859                 break;
860         case IW_MODE_INFRA:
861                 priv->reg.operation_mode = MODE_INFRASTRUCTURE;
862                 priv->need_commit |= SME_MODE_SET;
863                 break;
864         case IW_MODE_AUTO:
865         case IW_MODE_MASTER:
866         case IW_MODE_REPEAT:
867         case IW_MODE_SECOND:
868         case IW_MODE_MONITOR:
869         default:
870                 return -EINVAL;
871         }
872
873         return -EINPROGRESS;    /* Call commit handler */
874 }
875
876 /*------------------------------------------------------------------*/
877 /* Wireless Handler : get Mode of Operation */
878 static int ks_wlan_get_mode(struct net_device *dev,
879                             struct iw_request_info *info, __u32 * uwrq,
880                             char *extra)
881 {
882         struct ks_wlan_private *priv =
883             (struct ks_wlan_private *)netdev_priv(dev);
884
885         if (priv->sleep_mode == SLP_SLEEP) {
886                 return -EPERM;
887         }
888
889         /* for SLEEP MODE */
890         /* If not managed, assume it's ad-hoc */
891         switch (priv->reg.operation_mode) {
892         case MODE_INFRASTRUCTURE:
893                 *uwrq = IW_MODE_INFRA;
894                 break;
895         case MODE_ADHOC:
896                 *uwrq = IW_MODE_ADHOC;
897                 break;
898         default:
899                 *uwrq = IW_MODE_ADHOC;
900         }
901
902         return 0;
903 }
904
905 /*------------------------------------------------------------------*/
906 /* Wireless Handler : set Encryption Key */
907 static int ks_wlan_set_encode(struct net_device *dev,
908                               struct iw_request_info *info,
909                               struct iw_point *dwrq, char *extra)
910 {
911         struct ks_wlan_private *priv =
912             (struct ks_wlan_private *)netdev_priv(dev);
913
914         wep_key_t key;
915         int index = (dwrq->flags & IW_ENCODE_INDEX);
916         int current_index = priv->reg.wep_index;
917         int i;
918
919         DPRINTK(2, "flags=%04X\n", dwrq->flags);
920
921         if (priv->sleep_mode == SLP_SLEEP) {
922                 return -EPERM;
923         }
924
925         /* for SLEEP MODE */
926         /* index check */
927         if ((index < 0) || (index > 4))
928                 return -EINVAL;
929         else if (index == 0)
930                 index = current_index;
931         else
932                 index--;
933
934         /* Is WEP supported ? */
935         /* Basic checking: do we have a key to set ? */
936         if (dwrq->length > 0) {
937                 if (dwrq->length > MAX_KEY_SIZE) {      /* Check the size of the key */
938                         return -EINVAL;
939                 }
940                 if (dwrq->length > MIN_KEY_SIZE) {      /* Set the length */
941                         key.len = MAX_KEY_SIZE;
942                         priv->reg.privacy_invoked = 0x01;
943                         priv->need_commit |= SME_WEP_FLAG;
944                         wep_on_off = WEP_ON_128BIT;
945                 } else {
946                         if (dwrq->length > 0) {
947                                 key.len = MIN_KEY_SIZE;
948                                 priv->reg.privacy_invoked = 0x01;
949                                 priv->need_commit |= SME_WEP_FLAG;
950                                 wep_on_off = WEP_ON_64BIT;
951                         } else {        /* Disable the key */
952                                 key.len = 0;
953                         }
954                 }
955                 /* Check if the key is not marked as invalid */
956                 if (!(dwrq->flags & IW_ENCODE_NOKEY)) {
957                         /* Cleanup */
958                         memset(key.key, 0, MAX_KEY_SIZE);
959                         /* Copy the key in the driver */
960                         if (copy_from_user
961                             (key.key, dwrq->pointer, dwrq->length)) {
962                                 key.len = 0;
963                                 return -EFAULT;
964                         }
965                         /* Send the key to the card */
966                         priv->reg.wep_key[index].size = key.len;
967                         for (i = 0; i < (priv->reg.wep_key[index].size); i++) {
968                                 priv->reg.wep_key[index].val[i] = key.key[i];
969                         }
970                         priv->need_commit |= (SME_WEP_VAL1 << index);
971                         priv->reg.wep_index = index;
972                         priv->need_commit |= SME_WEP_INDEX;
973                 }
974         } else {
975                 if (dwrq->flags & IW_ENCODE_DISABLED) {
976                         priv->reg.wep_key[0].size = 0;
977                         priv->reg.wep_key[1].size = 0;
978                         priv->reg.wep_key[2].size = 0;
979                         priv->reg.wep_key[3].size = 0;
980                         priv->reg.privacy_invoked = 0x00;
981                         if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY) {
982                                 priv->need_commit |= SME_MODE_SET;
983                         }
984                         priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
985                         wep_on_off = WEP_OFF;
986                         priv->need_commit |= SME_WEP_FLAG;
987                 } else {
988                         /* Do we want to just set the transmit key index ? */
989                         if ((index >= 0) && (index < 4)) {
990                                 /* set_wep_key(priv, index, 0, 0, 1);   xxx */
991                                 if (priv->reg.wep_key[index].size) {
992                                         priv->reg.wep_index = index;
993                                         priv->need_commit |= SME_WEP_INDEX;
994                                 } else
995                                         return -EINVAL;
996                         }
997                 }
998         }
999
1000         /* Commit the changes if needed */
1001         if (dwrq->flags & IW_ENCODE_MODE)
1002                 priv->need_commit |= SME_WEP_FLAG;
1003
1004         if (dwrq->flags & IW_ENCODE_OPEN) {
1005                 if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY) {
1006                         priv->need_commit |= SME_MODE_SET;
1007                 }
1008                 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
1009         } else if (dwrq->flags & IW_ENCODE_RESTRICTED) {
1010                 if (priv->reg.authenticate_type == AUTH_TYPE_OPEN_SYSTEM) {
1011                         priv->need_commit |= SME_MODE_SET;
1012                 }
1013                 priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
1014         }
1015 //      return -EINPROGRESS;            /* Call commit handler */
1016         if (priv->need_commit) {
1017                 ks_wlan_setup_parameter(priv, priv->need_commit);
1018                 priv->need_commit = 0;
1019         }
1020         return 0;
1021 }
1022
1023 /*------------------------------------------------------------------*/
1024 /* Wireless Handler : get Encryption Key */
1025 static int ks_wlan_get_encode(struct net_device *dev,
1026                               struct iw_request_info *info,
1027                               struct iw_point *dwrq, char *extra)
1028 {
1029         struct ks_wlan_private *priv =
1030             (struct ks_wlan_private *)netdev_priv(dev);
1031         char zeros[16];
1032         int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1033
1034         if (priv->sleep_mode == SLP_SLEEP) {
1035                 return -EPERM;
1036         }
1037         /* for SLEEP MODE */
1038         dwrq->flags = IW_ENCODE_DISABLED;
1039
1040         /* Check encryption mode */
1041         switch (priv->reg.authenticate_type) {
1042         case AUTH_TYPE_OPEN_SYSTEM:
1043                 dwrq->flags = IW_ENCODE_OPEN;
1044                 break;
1045         case AUTH_TYPE_SHARED_KEY:
1046                 dwrq->flags = IW_ENCODE_RESTRICTED;
1047                 break;
1048         }
1049
1050         memset(zeros, 0, sizeof(zeros));
1051
1052         /* Which key do we want ? -1 -> tx index */
1053         if ((index < 0) || (index >= 4))
1054                 index = priv->reg.wep_index;
1055         if (priv->reg.privacy_invoked) {
1056                 dwrq->flags &= ~IW_ENCODE_DISABLED;
1057                 /* dwrq->flags |= IW_ENCODE_NOKEY; */
1058         }
1059         dwrq->flags |= index + 1;
1060         DPRINTK(2, "encoding flag = 0x%04X\n", dwrq->flags);
1061         /* Copy the key to the user buffer */
1062         if ((index >= 0) && (index < 4))
1063                 dwrq->length = priv->reg.wep_key[index].size;
1064         if (dwrq->length > 16) {
1065                 dwrq->length = 0;
1066         }
1067 #if 1   /* IW_ENCODE_NOKEY; */
1068         if (dwrq->length) {
1069                 if ((index >= 0) && (index < 4))
1070                         memcpy(extra, priv->reg.wep_key[index].val,
1071                                dwrq->length);
1072         } else
1073                 memcpy(extra, zeros, dwrq->length);
1074 #endif
1075         return 0;
1076 }
1077
1078 #ifndef KSC_OPNOTSUPP
1079 /*------------------------------------------------------------------*/
1080 /* Wireless Handler : set Tx-Power */
1081 static int ks_wlan_set_txpow(struct net_device *dev,
1082                              struct iw_request_info *info,
1083                              struct iw_param *vwrq, char *extra)
1084 {
1085         return -EOPNOTSUPP;     /* Not Support */
1086 }
1087
1088 /*------------------------------------------------------------------*/
1089 /* Wireless Handler : get Tx-Power */
1090 static int ks_wlan_get_txpow(struct net_device *dev,
1091                              struct iw_request_info *info,
1092                              struct iw_param *vwrq, char *extra)
1093 {
1094         if (priv->sleep_mode == SLP_SLEEP) {
1095                 return -EPERM;
1096         }
1097
1098         /* for SLEEP MODE */
1099         /* Not Support */
1100         vwrq->value = 0;
1101         vwrq->disabled = (vwrq->value == 0);
1102         vwrq->fixed = 1;
1103         return 0;
1104 }
1105
1106 /*------------------------------------------------------------------*/
1107 /* Wireless Handler : set Retry limits */
1108 static int ks_wlan_set_retry(struct net_device *dev,
1109                              struct iw_request_info *info,
1110                              struct iw_param *vwrq, char *extra)
1111 {
1112         return -EOPNOTSUPP;     /* Not Support */
1113 }
1114
1115 /*------------------------------------------------------------------*/
1116 /* Wireless Handler : get Retry limits */
1117 static int ks_wlan_get_retry(struct net_device *dev,
1118                              struct iw_request_info *info,
1119                              struct iw_param *vwrq, char *extra)
1120 {
1121         if (priv->sleep_mode == SLP_SLEEP) {
1122                 return -EPERM;
1123         }
1124
1125         /* for SLEEP MODE */
1126         /* Not Support */
1127         vwrq->value = 0;
1128         vwrq->disabled = (vwrq->value == 0);
1129         vwrq->fixed = 1;
1130         return 0;
1131 }
1132 #endif /* KSC_OPNOTSUPP */
1133
1134 /*------------------------------------------------------------------*/
1135 /* Wireless Handler : get range info */
1136 static int ks_wlan_get_range(struct net_device *dev,
1137                              struct iw_request_info *info,
1138                              struct iw_point *dwrq, char *extra)
1139 {
1140         struct ks_wlan_private *priv =
1141             (struct ks_wlan_private *)netdev_priv(dev);
1142         struct iw_range *range = (struct iw_range *)extra;
1143         int i, k;
1144
1145         DPRINTK(2, "\n");
1146
1147         if (priv->sleep_mode == SLP_SLEEP) {
1148                 return -EPERM;
1149         }
1150         /* for SLEEP MODE */
1151         dwrq->length = sizeof(struct iw_range);
1152         memset(range, 0, sizeof(*range));
1153         range->min_nwid = 0x0000;
1154         range->max_nwid = 0x0000;
1155         range->num_channels = 14;
1156         /* Should be based on cap_rid.country to give only
1157          * what the current card support */
1158         k = 0;
1159         for (i = 0; i < 13; i++) {      /* channel 1 -- 13 */
1160                 range->freq[k].i = i + 1;       /* List index */
1161                 range->freq[k].m = frequency_list[i] * 100000;
1162                 range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
1163         }
1164         range->num_frequency = k;
1165         if (priv->reg.phy_type == D_11B_ONLY_MODE || priv->reg.phy_type == D_11BG_COMPATIBLE_MODE) {    /* channel 14 */
1166                 range->freq[13].i = 14; /* List index */
1167                 range->freq[13].m = frequency_list[13] * 100000;
1168                 range->freq[13].e = 1;  /* Values in table in MHz -> * 10^5 * 10 */
1169                 range->num_frequency = 14;
1170         }
1171
1172         /* Hum... Should put the right values there */
1173         range->max_qual.qual = 100;
1174         range->max_qual.level = 256 - 128;      /* 0 dBm? */
1175         range->max_qual.noise = 256 - 128;
1176         range->sensitivity = 1;
1177
1178         if (priv->reg.phy_type == D_11B_ONLY_MODE) {
1179                 range->bitrate[0] = 1e6;
1180                 range->bitrate[1] = 2e6;
1181                 range->bitrate[2] = 5.5e6;
1182                 range->bitrate[3] = 11e6;
1183                 range->num_bitrates = 4;
1184         } else {        /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
1185                 range->bitrate[0] = 1e6;
1186                 range->bitrate[1] = 2e6;
1187                 range->bitrate[2] = 5.5e6;
1188                 range->bitrate[3] = 11e6;
1189
1190                 range->bitrate[4] = 6e6;
1191                 range->bitrate[5] = 9e6;
1192                 range->bitrate[6] = 12e6;
1193                 if (IW_MAX_BITRATES < 9) {
1194                         range->bitrate[7] = 54e6;
1195                         range->num_bitrates = 8;
1196                 } else {
1197                         range->bitrate[7] = 18e6;
1198                         range->bitrate[8] = 24e6;
1199                         range->bitrate[9] = 36e6;
1200                         range->bitrate[10] = 48e6;
1201                         range->bitrate[11] = 54e6;
1202
1203                         range->num_bitrates = 12;
1204                 }
1205         }
1206
1207         /* Set an indication of the max TCP throughput
1208          * in bit/s that we can expect using this interface.
1209          * May be use for QoS stuff... Jean II */
1210         if (i > 2)
1211                 range->throughput = 5000 * 1000;
1212         else
1213                 range->throughput = 1500 * 1000;
1214
1215         range->min_rts = 0;
1216         range->max_rts = 2347;
1217         range->min_frag = 256;
1218         range->max_frag = 2346;
1219
1220         range->encoding_size[0] = 5;    /* WEP: RC4 40 bits */
1221         range->encoding_size[1] = 13;   /* WEP: RC4 ~128 bits */
1222         range->num_encoding_sizes = 2;
1223         range->max_encoding_tokens = 4;
1224
1225         /* power management not support */
1226         range->pmp_flags = IW_POWER_ON;
1227         range->pmt_flags = IW_POWER_ON;
1228         range->pm_capa = 0;
1229
1230         /* Transmit Power - values are in dBm( or mW) */
1231         range->txpower[0] = -256;
1232         range->num_txpower = 1;
1233         range->txpower_capa = IW_TXPOW_DBM;
1234         /* range->txpower_capa = IW_TXPOW_MWATT; */
1235
1236         range->we_version_source = 21;
1237         range->we_version_compiled = WIRELESS_EXT;
1238
1239         range->retry_capa = IW_RETRY_ON;
1240         range->retry_flags = IW_RETRY_ON;
1241         range->r_time_flags = IW_RETRY_ON;
1242
1243         /* Experimental measurements - boundary 11/5.5 Mb/s */
1244         /* Note : with or without the (local->rssi), results
1245          * are somewhat different. - Jean II */
1246         range->avg_qual.qual = 50;
1247         range->avg_qual.level = 186;    /* -70 dBm */
1248         range->avg_qual.noise = 0;
1249
1250         /* Event capability (kernel + driver) */
1251         range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
1252                                 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
1253                                 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
1254         range->event_capa[1] = IW_EVENT_CAPA_K_1;
1255         range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVCUSTOM) |
1256                                 IW_EVENT_CAPA_MASK(IWEVMICHAELMICFAILURE));
1257
1258         /* encode extension (WPA) capability */
1259         range->enc_capa = (IW_ENC_CAPA_WPA |
1260                            IW_ENC_CAPA_WPA2 |
1261                            IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP);
1262         return 0;
1263 }
1264
1265 /*------------------------------------------------------------------*/
1266 /* Wireless Handler : set Power Management */
1267 static int ks_wlan_set_power(struct net_device *dev,
1268                              struct iw_request_info *info,
1269                              struct iw_param *vwrq, char *extra)
1270 {
1271         struct ks_wlan_private *priv =
1272             (struct ks_wlan_private *)netdev_priv(dev);
1273         short enabled;
1274
1275         if (priv->sleep_mode == SLP_SLEEP) {
1276                 return -EPERM;
1277         }
1278         /* for SLEEP MODE */
1279         enabled = vwrq->disabled ? 0 : 1;
1280         if (enabled == 0) {     /* 0 */
1281                 priv->reg.powermgt = POWMGT_ACTIVE_MODE;
1282         } else if (enabled) {   /* 1 */
1283                 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
1284                         priv->reg.powermgt = POWMGT_SAVE1_MODE;
1285                 else
1286                         return -EINVAL;
1287         } else if (enabled) {   /* 2 */
1288                 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
1289                         priv->reg.powermgt = POWMGT_SAVE2_MODE;
1290                 else
1291                         return -EINVAL;
1292         } else
1293                 return -EINVAL;
1294
1295         hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
1296
1297         return 0;
1298 }
1299
1300 /*------------------------------------------------------------------*/
1301 /* Wireless Handler : get Power Management */
1302 static int ks_wlan_get_power(struct net_device *dev,
1303                              struct iw_request_info *info,
1304                              struct iw_param *vwrq, char *extra)
1305 {
1306         struct ks_wlan_private *priv =
1307             (struct ks_wlan_private *)netdev_priv(dev);
1308
1309         if (priv->sleep_mode == SLP_SLEEP) {
1310                 return -EPERM;
1311         }
1312         /* for SLEEP MODE */
1313         if (priv->reg.powermgt > 0)
1314                 vwrq->disabled = 0;
1315         else
1316                 vwrq->disabled = 1;
1317
1318         return 0;
1319 }
1320
1321 /*------------------------------------------------------------------*/
1322 /* Wireless Handler : get wirless statistics */
1323 static int ks_wlan_get_iwstats(struct net_device *dev,
1324                                struct iw_request_info *info,
1325                                struct iw_quality *vwrq, char *extra)
1326 {
1327         struct ks_wlan_private *priv =
1328             (struct ks_wlan_private *)netdev_priv(dev);
1329
1330         if (priv->sleep_mode == SLP_SLEEP) {
1331                 return -EPERM;
1332         }
1333         /* for SLEEP MODE */
1334         vwrq->qual = 0; /* not supported */
1335         vwrq->level = priv->wstats.qual.level;
1336         vwrq->noise = 0;        /* not supported */
1337         vwrq->updated = 0;
1338
1339         return 0;
1340 }
1341
1342 #ifndef KSC_OPNOTSUPP
1343 /*------------------------------------------------------------------*/
1344 /* Wireless Handler : set Sensitivity */
1345 static int ks_wlan_set_sens(struct net_device *dev,
1346                             struct iw_request_info *info, struct iw_param *vwrq,
1347                             char *extra)
1348 {
1349         return -EOPNOTSUPP;     /* Not Support */
1350 }
1351
1352 /*------------------------------------------------------------------*/
1353 /* Wireless Handler : get Sensitivity */
1354 static int ks_wlan_get_sens(struct net_device *dev,
1355                             struct iw_request_info *info, struct iw_param *vwrq,
1356                             char *extra)
1357 {
1358         /* Not Support */
1359         vwrq->value = 0;
1360         vwrq->disabled = (vwrq->value == 0);
1361         vwrq->fixed = 1;
1362         return 0;
1363 }
1364 #endif /* KSC_OPNOTSUPP */
1365
1366 /*------------------------------------------------------------------*/
1367 /* Wireless Handler : get AP List */
1368 /* Note : this is deprecated in favor of IWSCAN */
1369 static int ks_wlan_get_aplist(struct net_device *dev,
1370                               struct iw_request_info *info,
1371                               struct iw_point *dwrq, char *extra)
1372 {
1373         struct ks_wlan_private *priv =
1374             (struct ks_wlan_private *)netdev_priv(dev);
1375         struct sockaddr *address = (struct sockaddr *)extra;
1376         struct iw_quality qual[LOCAL_APLIST_MAX];
1377
1378         int i;
1379
1380         if (priv->sleep_mode == SLP_SLEEP) {
1381                 return -EPERM;
1382         }
1383         /* for SLEEP MODE */
1384         for (i = 0; i < priv->aplist.size; i++) {
1385                 memcpy(address[i].sa_data, &(priv->aplist.ap[i].bssid[0]),
1386                        ETH_ALEN);
1387                 address[i].sa_family = ARPHRD_ETHER;
1388                 qual[i].level = 256 - priv->aplist.ap[i].rssi;
1389                 qual[i].qual = priv->aplist.ap[i].sq;
1390                 qual[i].noise = 0;      /* invalid noise value */
1391                 qual[i].updated = 7;
1392         }
1393         if (i) {
1394                 dwrq->flags = 1;        /* Should be define'd */
1395                 memcpy(extra + sizeof(struct sockaddr) * i,
1396                        &qual, sizeof(struct iw_quality) * i);
1397         }
1398         dwrq->length = i;
1399
1400         return 0;
1401 }
1402
1403 /*------------------------------------------------------------------*/
1404 /* Wireless Handler : Initiate Scan */
1405 static int ks_wlan_set_scan(struct net_device *dev,
1406                             struct iw_request_info *info,
1407                             union iwreq_data *wrqu, char *extra)
1408 {
1409         struct ks_wlan_private *priv =
1410             (struct ks_wlan_private *)netdev_priv(dev);
1411         struct iw_scan_req *req = NULL;
1412         DPRINTK(2, "\n");
1413
1414         if (priv->sleep_mode == SLP_SLEEP) {
1415                 return -EPERM;
1416         }
1417
1418         /* for SLEEP MODE */
1419         /* specified SSID SCAN */
1420         if (wrqu->data.length == sizeof(struct iw_scan_req)
1421             && wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1422                 req = (struct iw_scan_req *)extra;
1423                 priv->scan_ssid_len = req->essid_len;
1424                 memcpy(priv->scan_ssid, req->essid, priv->scan_ssid_len);
1425         } else {
1426                 priv->scan_ssid_len = 0;
1427         }
1428
1429         priv->sme_i.sme_flag |= SME_AP_SCAN;
1430         hostif_sme_enqueue(priv, SME_BSS_SCAN_REQUEST);
1431
1432         /* At this point, just return to the user. */
1433
1434         return 0;
1435 }
1436
1437 /*------------------------------------------------------------------*/
1438 /*
1439  * Translate scan data returned from the card to a card independent
1440  * format that the Wireless Tools will understand - Jean II
1441  */
1442 static inline char *ks_wlan_translate_scan(struct net_device *dev,
1443                                            struct iw_request_info *info,
1444                                            char *current_ev, char *end_buf,
1445                                            struct local_ap_t *ap)
1446 {
1447         /* struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; */
1448         struct iw_event iwe;    /* Temporary buffer */
1449         u16 capabilities;
1450         char *current_val;      /* For rates */
1451         int i;
1452         static const char rsn_leader[] = "rsn_ie=";
1453         static const char wpa_leader[] = "wpa_ie=";
1454         char buf0[RSN_IE_BODY_MAX * 2 + 30];
1455         char buf1[RSN_IE_BODY_MAX * 2 + 30];
1456         char *pbuf;
1457         /* First entry *MUST* be the AP MAC address */
1458         iwe.cmd = SIOCGIWAP;
1459         iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1460         memcpy(iwe.u.ap_addr.sa_data, ap->bssid, ETH_ALEN);
1461         current_ev =
1462             iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1463                                  IW_EV_ADDR_LEN);
1464
1465         /* Other entries will be displayed in the order we give them */
1466
1467         /* Add the ESSID */
1468         iwe.u.data.length = ap->ssid.size;
1469         if (iwe.u.data.length > 32)
1470                 iwe.u.data.length = 32;
1471         iwe.cmd = SIOCGIWESSID;
1472         iwe.u.data.flags = 1;
1473         current_ev =
1474             iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1475                                  &(ap->ssid.body[0]));
1476
1477         /* Add mode */
1478         iwe.cmd = SIOCGIWMODE;
1479         capabilities = le16_to_cpu(ap->capability);
1480         if (capabilities & (BSS_CAP_ESS | BSS_CAP_IBSS)) {
1481                 if (capabilities & BSS_CAP_ESS)
1482                         iwe.u.mode = IW_MODE_INFRA;
1483                 else
1484                         iwe.u.mode = IW_MODE_ADHOC;
1485                 current_ev =
1486                     iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1487                                          IW_EV_UINT_LEN);
1488         }
1489
1490         /* Add frequency */
1491         iwe.cmd = SIOCGIWFREQ;
1492         iwe.u.freq.m = ap->channel;
1493         iwe.u.freq.m = frequency_list[iwe.u.freq.m - 1] * 100000;
1494         iwe.u.freq.e = 1;
1495         current_ev =
1496             iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1497                                  IW_EV_FREQ_LEN);
1498
1499         /* Add quality statistics */
1500         iwe.cmd = IWEVQUAL;
1501         iwe.u.qual.level = 256 - ap->rssi;
1502         iwe.u.qual.qual = ap->sq;
1503         iwe.u.qual.noise = 0;   /* invalid noise value */
1504         current_ev =
1505             iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1506                                  IW_EV_QUAL_LEN);
1507
1508         /* Add encryption capability */
1509         iwe.cmd = SIOCGIWENCODE;
1510         if (capabilities & BSS_CAP_PRIVACY)
1511                 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1512         else
1513                 iwe.u.data.flags = IW_ENCODE_DISABLED;
1514         iwe.u.data.length = 0;
1515         current_ev =
1516             iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1517                                  &(ap->ssid.body[0]));
1518
1519         /* Rate : stuffing multiple values in a single event require a bit
1520          * more of magic - Jean II */
1521         current_val = current_ev + IW_EV_LCP_LEN;
1522
1523         iwe.cmd = SIOCGIWRATE;
1524         /* Those two flags are ignored... */
1525         iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
1526
1527         /* Max 16 values */
1528         for (i = 0; i < 16; i++) {
1529                 /* NULL terminated */
1530                 if (i >= ap->rate_set.size)
1531                         break;
1532                 /* Bit rate given in 500 kb/s units (+ 0x80) */
1533                 iwe.u.bitrate.value = ((ap->rate_set.body[i] & 0x7f) * 500000);
1534                 /* Add new value to event */
1535                 current_val =
1536                     iwe_stream_add_value(info, current_ev, current_val, end_buf,
1537                                          &iwe, IW_EV_PARAM_LEN);
1538         }
1539         /* Check if we added any event */
1540         if ((current_val - current_ev) > IW_EV_LCP_LEN)
1541                 current_ev = current_val;
1542
1543 #define GENERIC_INFO_ELEM_ID 0xdd
1544 #define RSN_INFO_ELEM_ID 0x30
1545         if (ap->rsn_ie.id == RSN_INFO_ELEM_ID && ap->rsn_ie.size != 0) {
1546                 pbuf = &buf0[0];
1547                 memset(&iwe, 0, sizeof(iwe));
1548                 iwe.cmd = IWEVCUSTOM;
1549                 memcpy(buf0, rsn_leader, sizeof(rsn_leader) - 1);
1550                 iwe.u.data.length += sizeof(rsn_leader) - 1;
1551                 pbuf += sizeof(rsn_leader) - 1;
1552
1553                 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.id);
1554                 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.size);
1555                 iwe.u.data.length += 4;
1556
1557                 for (i = 0; i < ap->rsn_ie.size; i++)
1558                         pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.body[i]);
1559                 iwe.u.data.length += (ap->rsn_ie.size) * 2;
1560
1561                 DPRINTK(4, "ap->rsn.size=%d\n", ap->rsn_ie.size);
1562
1563                 current_ev =
1564                     iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1565                                          &buf0[0]);
1566         }
1567         if (ap->wpa_ie.id == GENERIC_INFO_ELEM_ID && ap->wpa_ie.size != 0) {
1568                 pbuf = &buf1[0];
1569                 memset(&iwe, 0, sizeof(iwe));
1570                 iwe.cmd = IWEVCUSTOM;
1571                 memcpy(buf1, wpa_leader, sizeof(wpa_leader) - 1);
1572                 iwe.u.data.length += sizeof(wpa_leader) - 1;
1573                 pbuf += sizeof(wpa_leader) - 1;
1574
1575                 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.id);
1576                 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.size);
1577                 iwe.u.data.length += 4;
1578
1579                 for (i = 0; i < ap->wpa_ie.size; i++)
1580                         pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.body[i]);
1581                 iwe.u.data.length += (ap->wpa_ie.size) * 2;
1582
1583                 DPRINTK(4, "ap->rsn.size=%d\n", ap->wpa_ie.size);
1584                 DPRINTK(4, "iwe.u.data.length=%d\n", iwe.u.data.length);
1585
1586                 current_ev =
1587                     iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1588                                          &buf1[0]);
1589         }
1590
1591         /* The other data in the scan result are not really
1592          * interesting, so for now drop it - Jean II */
1593         return current_ev;
1594 }
1595
1596 /*------------------------------------------------------------------*/
1597 /* Wireless Handler : Read Scan Results */
1598 static int ks_wlan_get_scan(struct net_device *dev,
1599                             struct iw_request_info *info, struct iw_point *dwrq,
1600                             char *extra)
1601 {
1602         struct ks_wlan_private *priv =
1603             (struct ks_wlan_private *)netdev_priv(dev);
1604         int i;
1605         char *current_ev = extra;
1606         DPRINTK(2, "\n");
1607
1608         if (priv->sleep_mode == SLP_SLEEP) {
1609                 return -EPERM;
1610         }
1611         /* for SLEEP MODE */
1612         if (priv->sme_i.sme_flag & SME_AP_SCAN) {
1613                 DPRINTK(2, "flag AP_SCAN\n");
1614                 return -EAGAIN;
1615         }
1616
1617         if (priv->aplist.size == 0) {
1618                 /* Client error, no scan results...
1619                  * The caller need to restart the scan. */
1620                 DPRINTK(2, "aplist 0\n");
1621                 return -ENODATA;
1622         }
1623 #if 0
1624         /* current connect ap */
1625         if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
1626                 if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) {
1627                         dwrq->length = 0;
1628                         return -E2BIG;
1629                 }
1630                 current_ev = ks_wlan_translate_scan(dev, current_ev,
1631 //                                                  extra + IW_SCAN_MAX_DATA,
1632                                                     extra + dwrq->length,
1633                                                     &(priv->current_ap));
1634         }
1635 #endif
1636         /* Read and parse all entries */
1637         for (i = 0; i < priv->aplist.size; i++) {
1638                 if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) {
1639                         dwrq->length = 0;
1640                         return -E2BIG;
1641                 }
1642                 /* Translate to WE format this entry */
1643                 current_ev = ks_wlan_translate_scan(dev, info, current_ev,
1644 //                                                  extra + IW_SCAN_MAX_DATA,
1645                                                     extra + dwrq->length,
1646                                                     &(priv->aplist.ap[i]));
1647         }
1648         /* Length of data */
1649         dwrq->length = (current_ev - extra);
1650         dwrq->flags = 0;
1651
1652         return 0;
1653 }
1654
1655 /*------------------------------------------------------------------*/
1656 /* Commit handler : called after a bunch of SET operations */
1657 static int ks_wlan_config_commit(struct net_device *dev,
1658                                  struct iw_request_info *info, void *zwrq,
1659                                  char *extra)
1660 {
1661         struct ks_wlan_private *priv =
1662             (struct ks_wlan_private *)netdev_priv(dev);
1663
1664         if (!priv->need_commit)
1665                 return 0;
1666
1667         ks_wlan_setup_parameter(priv, priv->need_commit);
1668         priv->need_commit = 0;
1669         return 0;
1670 }
1671
1672 /*------------------------------------------------------------------*/
1673 /* Wireless handler : set association ie params */
1674 static int ks_wlan_set_genie(struct net_device *dev,
1675                              struct iw_request_info *info,
1676                              struct iw_point *dwrq, char *extra)
1677 {
1678         struct ks_wlan_private *priv =
1679             (struct ks_wlan_private *)netdev_priv(dev);
1680
1681         DPRINTK(2, "\n");
1682
1683         if (priv->sleep_mode == SLP_SLEEP) {
1684                 return -EPERM;
1685         }
1686         /* for SLEEP MODE */
1687         return 0;
1688 //      return -EOPNOTSUPP;
1689 }
1690
1691 /*------------------------------------------------------------------*/
1692 /* Wireless handler : set authentication mode params */
1693 static int ks_wlan_set_auth_mode(struct net_device *dev,
1694                                  struct iw_request_info *info,
1695                                  struct iw_param *vwrq, char *extra)
1696 {
1697         struct ks_wlan_private *priv =
1698             (struct ks_wlan_private *)netdev_priv(dev);
1699         int index = (vwrq->flags & IW_AUTH_INDEX);
1700         int value = vwrq->value;
1701
1702         DPRINTK(2, "index=%d:value=%08X\n", index, value);
1703
1704         if (priv->sleep_mode == SLP_SLEEP) {
1705                 return -EPERM;
1706         }
1707         /* for SLEEP MODE */
1708         switch (index) {
1709         case IW_AUTH_WPA_VERSION:       /* 0 */
1710                 switch (value) {
1711                 case IW_AUTH_WPA_VERSION_DISABLED:
1712                         priv->wpa.version = value;
1713                         if (priv->wpa.rsn_enabled) {
1714                                 priv->wpa.rsn_enabled = 0;
1715                         }
1716                         priv->need_commit |= SME_RSN;
1717                         break;
1718                 case IW_AUTH_WPA_VERSION_WPA:
1719                 case IW_AUTH_WPA_VERSION_WPA2:
1720                         priv->wpa.version = value;
1721                         if (!(priv->wpa.rsn_enabled)) {
1722                                 priv->wpa.rsn_enabled = 1;
1723                         }
1724                         priv->need_commit |= SME_RSN;
1725                         break;
1726                 default:
1727                         return -EOPNOTSUPP;
1728                 }
1729                 break;
1730         case IW_AUTH_CIPHER_PAIRWISE:   /* 1 */
1731                 switch (value) {
1732                 case IW_AUTH_CIPHER_NONE:
1733                         if (priv->reg.privacy_invoked) {
1734                                 priv->reg.privacy_invoked = 0x00;
1735                                 priv->need_commit |= SME_WEP_FLAG;
1736                         }
1737                         break;
1738                 case IW_AUTH_CIPHER_WEP40:
1739                 case IW_AUTH_CIPHER_TKIP:
1740                 case IW_AUTH_CIPHER_CCMP:
1741                 case IW_AUTH_CIPHER_WEP104:
1742                         if (!priv->reg.privacy_invoked) {
1743                                 priv->reg.privacy_invoked = 0x01;
1744                                 priv->need_commit |= SME_WEP_FLAG;
1745                         }
1746                         priv->wpa.pairwise_suite = value;
1747                         priv->need_commit |= SME_RSN_UNICAST;
1748                         break;
1749                 default:
1750                         return -EOPNOTSUPP;
1751                 }
1752                 break;
1753         case IW_AUTH_CIPHER_GROUP:      /* 2 */
1754                 switch (value) {
1755                 case IW_AUTH_CIPHER_NONE:
1756                         if (priv->reg.privacy_invoked) {
1757                                 priv->reg.privacy_invoked = 0x00;
1758                                 priv->need_commit |= SME_WEP_FLAG;
1759                         }
1760                         break;
1761                 case IW_AUTH_CIPHER_WEP40:
1762                 case IW_AUTH_CIPHER_TKIP:
1763                 case IW_AUTH_CIPHER_CCMP:
1764                 case IW_AUTH_CIPHER_WEP104:
1765                         if (!priv->reg.privacy_invoked) {
1766                                 priv->reg.privacy_invoked = 0x01;
1767                                 priv->need_commit |= SME_WEP_FLAG;
1768                         }
1769                         priv->wpa.group_suite = value;
1770                         priv->need_commit |= SME_RSN_MULTICAST;
1771                         break;
1772                 default:
1773                         return -EOPNOTSUPP;
1774                 }
1775                 break;
1776         case IW_AUTH_KEY_MGMT:  /* 3 */
1777                 switch (value) {
1778                 case IW_AUTH_KEY_MGMT_802_1X:
1779                 case IW_AUTH_KEY_MGMT_PSK:
1780                 case 0: /* NONE or 802_1X_NO_WPA */
1781                 case 4: /* WPA_NONE */
1782                         priv->wpa.key_mgmt_suite = value;
1783                         priv->need_commit |= SME_RSN_AUTH;
1784                         break;
1785                 default:
1786                         return -EOPNOTSUPP;
1787                 }
1788                 break;
1789         case IW_AUTH_80211_AUTH_ALG:    /* 6 */
1790                 switch (value) {
1791                 case IW_AUTH_ALG_OPEN_SYSTEM:
1792                         priv->wpa.auth_alg = value;
1793                         priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
1794                         break;
1795                 case IW_AUTH_ALG_SHARED_KEY:
1796                         priv->wpa.auth_alg = value;
1797                         priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
1798                         break;
1799                 case IW_AUTH_ALG_LEAP:
1800                 default:
1801                         return -EOPNOTSUPP;
1802                 }
1803                 priv->need_commit |= SME_MODE_SET;
1804                 break;
1805         case IW_AUTH_WPA_ENABLED:       /* 7 */
1806                 priv->wpa.wpa_enabled = value;
1807                 break;
1808         case IW_AUTH_PRIVACY_INVOKED:   /* 10 */
1809                 if ((value && !priv->reg.privacy_invoked) ||
1810                     (!value && priv->reg.privacy_invoked)) {
1811                         priv->reg.privacy_invoked = value ? 0x01 : 0x00;
1812                         priv->need_commit |= SME_WEP_FLAG;
1813                 }
1814                 break;
1815         case IW_AUTH_RX_UNENCRYPTED_EAPOL:      /* 4 */
1816         case IW_AUTH_TKIP_COUNTERMEASURES:      /* 5 */
1817         case IW_AUTH_DROP_UNENCRYPTED:  /* 8 */
1818         case IW_AUTH_ROAMING_CONTROL:   /* 9 */
1819         default:
1820                 break;
1821         }
1822
1823         /* return -EINPROGRESS; */
1824         if (priv->need_commit) {
1825                 ks_wlan_setup_parameter(priv, priv->need_commit);
1826                 priv->need_commit = 0;
1827         }
1828         return 0;
1829 }
1830
1831 /*------------------------------------------------------------------*/
1832 /* Wireless handler : get authentication mode params */
1833 static int ks_wlan_get_auth_mode(struct net_device *dev,
1834                                  struct iw_request_info *info,
1835                                  struct iw_param *vwrq, char *extra)
1836 {
1837         struct ks_wlan_private *priv =
1838             (struct ks_wlan_private *)netdev_priv(dev);
1839         int index = (vwrq->flags & IW_AUTH_INDEX);
1840         DPRINTK(2, "index=%d\n", index);
1841
1842         if (priv->sleep_mode == SLP_SLEEP) {
1843                 return -EPERM;
1844         }
1845
1846         /* for SLEEP MODE */
1847         /*  WPA (not used ?? wpa_supplicant) */
1848         switch (index) {
1849         case IW_AUTH_WPA_VERSION:
1850                 vwrq->value = priv->wpa.version;
1851                 break;
1852         case IW_AUTH_CIPHER_PAIRWISE:
1853                 vwrq->value = priv->wpa.pairwise_suite;
1854                 break;
1855         case IW_AUTH_CIPHER_GROUP:
1856                 vwrq->value = priv->wpa.group_suite;
1857                 break;
1858         case IW_AUTH_KEY_MGMT:
1859                 vwrq->value = priv->wpa.key_mgmt_suite;
1860                 break;
1861         case IW_AUTH_80211_AUTH_ALG:
1862                 vwrq->value = priv->wpa.auth_alg;
1863                 break;
1864         case IW_AUTH_WPA_ENABLED:
1865                 vwrq->value = priv->wpa.rsn_enabled;
1866                 break;
1867         case IW_AUTH_RX_UNENCRYPTED_EAPOL:      /* OK??? */
1868         case IW_AUTH_TKIP_COUNTERMEASURES:
1869         case IW_AUTH_DROP_UNENCRYPTED:
1870         default:
1871                 /* return -EOPNOTSUPP; */
1872                 break;
1873         }
1874         return 0;
1875 }
1876
1877 /*------------------------------------------------------------------*/
1878 /* Wireless Handler : set encoding token & mode (WPA)*/
1879 static int ks_wlan_set_encode_ext(struct net_device *dev,
1880                                   struct iw_request_info *info,
1881                                   struct iw_point *dwrq, char *extra)
1882 {
1883         struct ks_wlan_private *priv =
1884             (struct ks_wlan_private *)netdev_priv(dev);
1885         struct iw_encode_ext *enc;
1886         int index = dwrq->flags & IW_ENCODE_INDEX;
1887         unsigned int commit = 0;
1888
1889         enc = (struct iw_encode_ext *)extra;
1890
1891         DPRINTK(2, "flags=%04X:: ext_flags=%08X\n", dwrq->flags,
1892                 enc->ext_flags);
1893
1894         if (priv->sleep_mode == SLP_SLEEP) {
1895                 return -EPERM;
1896         }
1897         /* for SLEEP MODE */
1898         if (index < 1 || index > 4)
1899                 return -EINVAL;
1900         else
1901                 index--;
1902
1903         if (dwrq->flags & IW_ENCODE_DISABLED) {
1904                 priv->wpa.key[index].key_len = 0;
1905         }
1906
1907         if (enc) {
1908                 priv->wpa.key[index].ext_flags = enc->ext_flags;
1909                 if (enc->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
1910                         priv->wpa.txkey = index;
1911                         commit |= SME_WEP_INDEX;
1912                 } else if (enc->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
1913                         if (enc->rx_seq)
1914                                 memcpy(&priv->wpa.key[index].rx_seq[0],
1915                                        enc->rx_seq, IW_ENCODE_SEQ_MAX_SIZE);
1916                         else
1917                                 return -EINVAL;
1918                 }
1919
1920                 memcpy(&priv->wpa.key[index].addr.sa_data[0],
1921                        &enc->addr.sa_data[0], ETH_ALEN);
1922
1923                 switch (enc->alg) {
1924                 case IW_ENCODE_ALG_NONE:
1925                         if (priv->reg.privacy_invoked) {
1926                                 priv->reg.privacy_invoked = 0x00;
1927                                 commit |= SME_WEP_FLAG;
1928                         }
1929                         priv->wpa.key[index].key_len = 0;
1930
1931                         break;
1932                 case IW_ENCODE_ALG_WEP:
1933                 case IW_ENCODE_ALG_CCMP:
1934                         if (!priv->reg.privacy_invoked) {
1935                                 priv->reg.privacy_invoked = 0x01;
1936                                 commit |= SME_WEP_FLAG;
1937                         }
1938                         if (enc->key && enc->key_len) {
1939                                 memcpy(&priv->wpa.key[index].key_val[0],
1940                                        &enc->key[0], enc->key_len);
1941                                 priv->wpa.key[index].key_len = enc->key_len;
1942                                 commit |= (SME_WEP_VAL1 << index);
1943                         }
1944                         break;
1945                 case IW_ENCODE_ALG_TKIP:
1946                         if (!priv->reg.privacy_invoked) {
1947                                 priv->reg.privacy_invoked = 0x01;
1948                                 commit |= SME_WEP_FLAG;
1949                         }
1950                         if (enc->key && enc->key_len == 32) {
1951                                 memcpy(&priv->wpa.key[index].key_val[0],
1952                                        &enc->key[0], enc->key_len - 16);
1953                                 priv->wpa.key[index].key_len =
1954                                     enc->key_len - 16;
1955                                 if (priv->wpa.key_mgmt_suite == 4) {    /* WPA_NONE */
1956                                         memcpy(&priv->wpa.key[index].
1957                                                tx_mic_key[0], &enc->key[16], 8);
1958                                         memcpy(&priv->wpa.key[index].
1959                                                rx_mic_key[0], &enc->key[16], 8);
1960                                 } else {
1961                                         memcpy(&priv->wpa.key[index].
1962                                                tx_mic_key[0], &enc->key[16], 8);
1963                                         memcpy(&priv->wpa.key[index].
1964                                                rx_mic_key[0], &enc->key[24], 8);
1965                                 }
1966                                 commit |= (SME_WEP_VAL1 << index);
1967                         }
1968                         break;
1969                 default:
1970                         return -EINVAL;
1971                 }
1972                 priv->wpa.key[index].alg = enc->alg;
1973         } else
1974                 return -EINVAL;
1975
1976         if (commit) {
1977                 if (commit & SME_WEP_INDEX)
1978                         hostif_sme_enqueue(priv, SME_SET_TXKEY);
1979                 if (commit & SME_WEP_VAL_MASK)
1980                         hostif_sme_enqueue(priv, SME_SET_KEY1 + index);
1981                 if (commit & SME_WEP_FLAG)
1982                         hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
1983         }
1984
1985         return 0;
1986 }
1987
1988 /*------------------------------------------------------------------*/
1989 /* Wireless Handler : get encoding token & mode (WPA)*/
1990 static int ks_wlan_get_encode_ext(struct net_device *dev,
1991                                   struct iw_request_info *info,
1992                                   struct iw_point *dwrq, char *extra)
1993 {
1994         struct ks_wlan_private *priv =
1995             (struct ks_wlan_private *)netdev_priv(dev);
1996
1997         if (priv->sleep_mode == SLP_SLEEP) {
1998                 return -EPERM;
1999         }
2000
2001         /* for SLEEP MODE */
2002         /*  WPA (not used ?? wpa_supplicant)
2003            struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2004            struct iw_encode_ext *enc;
2005            enc = (struct iw_encode_ext *)extra;
2006            int index = dwrq->flags & IW_ENCODE_INDEX;
2007            WPA (not used ?? wpa_supplicant) */
2008         return 0;
2009 }
2010
2011 /*------------------------------------------------------------------*/
2012 /* Wireless Handler : PMKSA cache operation (WPA2) */
2013 static int ks_wlan_set_pmksa(struct net_device *dev,
2014                              struct iw_request_info *info,
2015                              struct iw_point *dwrq, char *extra)
2016 {
2017         struct ks_wlan_private *priv =
2018             (struct ks_wlan_private *)netdev_priv(dev);
2019         struct iw_pmksa *pmksa;
2020         int i;
2021         struct pmk_t *pmk;
2022         struct list_head *ptr;
2023
2024         DPRINTK(2, "\n");
2025
2026         if (priv->sleep_mode == SLP_SLEEP) {
2027                 return -EPERM;
2028         }
2029         /* for SLEEP MODE */
2030         if (!extra) {
2031                 return -EINVAL;
2032         }
2033         pmksa = (struct iw_pmksa *)extra;
2034         DPRINTK(2, "cmd=%d\n", pmksa->cmd);
2035
2036         switch (pmksa->cmd) {
2037         case IW_PMKSA_ADD:
2038                 if (list_empty(&priv->pmklist.head)) {  /* new list */
2039                         for (i = 0; i < PMK_LIST_MAX; i++) {
2040                                 pmk = &priv->pmklist.pmk[i];
2041                                 if (!memcmp
2042                                     ("\x00\x00\x00\x00\x00\x00", pmk->bssid,
2043                                      ETH_ALEN))
2044                                         break;
2045                         }
2046                         memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
2047                         memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
2048                         list_add(&pmk->list, &priv->pmklist.head);
2049                         priv->pmklist.size++;
2050                 } else {        /* search cache data */
2051                         list_for_each(ptr, &priv->pmklist.head) {
2052                                 pmk = list_entry(ptr, struct pmk_t, list);
2053                                 if (!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)) {      /* match address! list move to head. */
2054                                         memcpy(pmk->pmkid, pmksa->pmkid,
2055                                                IW_PMKID_LEN);
2056                                         list_move(&pmk->list,
2057                                                   &priv->pmklist.head);
2058                                         break;
2059                                 }
2060                         }
2061                         if (ptr == &priv->pmklist.head) {       /* not find address. */
2062                                 if (PMK_LIST_MAX > priv->pmklist.size) {        /* new cache data */
2063                                         for (i = 0; i < PMK_LIST_MAX; i++) {
2064                                                 pmk = &priv->pmklist.pmk[i];
2065                                                 if (!memcmp
2066                                                     ("\x00\x00\x00\x00\x00\x00",
2067                                                      pmk->bssid, ETH_ALEN))
2068                                                         break;
2069                                         }
2070                                         memcpy(pmk->bssid, pmksa->bssid.sa_data,
2071                                                ETH_ALEN);
2072                                         memcpy(pmk->pmkid, pmksa->pmkid,
2073                                                IW_PMKID_LEN);
2074                                         list_add(&pmk->list,
2075                                                  &priv->pmklist.head);
2076                                         priv->pmklist.size++;
2077                                 } else {        /* overwrite old cache data */
2078                                         pmk =
2079                                             list_entry(priv->pmklist.head.prev,
2080                                                        struct pmk_t, list);
2081                                         memcpy(pmk->bssid, pmksa->bssid.sa_data,
2082                                                ETH_ALEN);
2083                                         memcpy(pmk->pmkid, pmksa->pmkid,
2084                                                IW_PMKID_LEN);
2085                                         list_move(&pmk->list,
2086                                                   &priv->pmklist.head);
2087                                 }
2088                         }
2089                 }
2090                 break;
2091         case IW_PMKSA_REMOVE:
2092                 if (list_empty(&priv->pmklist.head)) {  /* list empty */
2093                         return -EINVAL;
2094                 } else {        /* search cache data */
2095                         list_for_each(ptr, &priv->pmklist.head) {
2096                                 pmk = list_entry(ptr, struct pmk_t, list);
2097                                 if (!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)) {      /* match address! list del. */
2098                                         memset(pmk->bssid, 0, ETH_ALEN);
2099                                         memset(pmk->pmkid, 0, IW_PMKID_LEN);
2100                                         list_del_init(&pmk->list);
2101                                         break;
2102                                 }
2103                         }
2104                         if (ptr == &priv->pmklist.head) {       /* not find address. */
2105                                 return 0;
2106                         }
2107                 }
2108                 break;
2109         case IW_PMKSA_FLUSH:
2110                 memset(&(priv->pmklist), 0, sizeof(priv->pmklist));
2111                 INIT_LIST_HEAD(&priv->pmklist.head);
2112                 for (i = 0; i < PMK_LIST_MAX; i++)
2113                         INIT_LIST_HEAD(&priv->pmklist.pmk[i].list);
2114                 break;
2115         default:
2116                 return -EINVAL;
2117         }
2118
2119         hostif_sme_enqueue(priv, SME_SET_PMKSA);
2120         return 0;
2121 }
2122
2123 static struct iw_statistics *ks_get_wireless_stats(struct net_device *dev)
2124 {
2125
2126         struct ks_wlan_private *priv =
2127             (struct ks_wlan_private *)netdev_priv(dev);
2128         struct iw_statistics *wstats = &priv->wstats;
2129
2130         if (!atomic_read(&update_phyinfo)) {
2131                 if (priv->dev_state < DEVICE_STATE_READY)
2132                         return NULL;    /* not finished initialize */
2133                 else
2134                         return wstats;
2135         }
2136
2137         /* Packets discarded in the wireless adapter due to wireless
2138          * specific problems */
2139         wstats->discard.nwid = 0;       /* Rx invalid nwid      */
2140         wstats->discard.code = 0;       /* Rx invalid crypt     */
2141         wstats->discard.fragment = 0;   /* Rx invalid frag      */
2142         wstats->discard.retries = 0;    /* Tx excessive retries */
2143         wstats->discard.misc = 0;       /* Invalid misc         */
2144         wstats->miss.beacon = 0;        /* Missed beacon        */
2145
2146         return wstats;
2147 }
2148
2149 /*------------------------------------------------------------------*/
2150 /* Private handler : set stop request */
2151 static int ks_wlan_set_stop_request(struct net_device *dev,
2152                                     struct iw_request_info *info, __u32 * uwrq,
2153                                     char *extra)
2154 {
2155         struct ks_wlan_private *priv =
2156             (struct ks_wlan_private *)netdev_priv(dev);
2157         DPRINTK(2, "\n");
2158
2159         if (priv->sleep_mode == SLP_SLEEP) {
2160                 return -EPERM;
2161         }
2162         /* for SLEEP MODE */
2163         if (!(*uwrq))
2164                 return -EINVAL;
2165
2166         hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2167         return 0;
2168 }
2169
2170 /*------------------------------------------------------------------*/
2171 /* Wireless Handler : set MLME */
2172 #include <linux/ieee80211.h>
2173 static int ks_wlan_set_mlme(struct net_device *dev,
2174                             struct iw_request_info *info, struct iw_point *dwrq,
2175                             char *extra)
2176 {
2177         struct ks_wlan_private *priv =
2178             (struct ks_wlan_private *)netdev_priv(dev);
2179         struct iw_mlme *mlme = (struct iw_mlme *)extra;
2180         __u32 mode;
2181
2182         DPRINTK(2, ":%d :%d\n", mlme->cmd, mlme->reason_code);
2183
2184         if (priv->sleep_mode == SLP_SLEEP) {
2185                 return -EPERM;
2186         }
2187         /* for SLEEP MODE */
2188         switch (mlme->cmd) {
2189         case IW_MLME_DEAUTH:
2190                 if (mlme->reason_code == WLAN_REASON_MIC_FAILURE) {
2191                         return 0;
2192                 }
2193         case IW_MLME_DISASSOC:
2194                 mode = 1;
2195                 return ks_wlan_set_stop_request(dev, NULL, &mode, NULL);
2196         default:
2197                 return -EOPNOTSUPP;     /* Not Support */
2198         }
2199 }
2200
2201 /*------------------------------------------------------------------*/
2202 /* Private handler : get firemware version */
2203 static int ks_wlan_get_firmware_version(struct net_device *dev,
2204                                         struct iw_request_info *info,
2205                                         struct iw_point *dwrq, char *extra)
2206 {
2207         struct ks_wlan_private *priv =
2208             (struct ks_wlan_private *)netdev_priv(dev);
2209         strcpy(extra, &(priv->firmware_version[0]));
2210         dwrq->length = priv->version_size + 1;
2211         return 0;
2212 }
2213
2214 #if 0
2215 /*------------------------------------------------------------------*/
2216 /* Private handler : set force disconnect status */
2217 static int ks_wlan_set_detach(struct net_device *dev,
2218                               struct iw_request_info *info, __u32 * uwrq,
2219                               char *extra)
2220 {
2221         struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2222
2223         if (priv->sleep_mode == SLP_SLEEP) {
2224                 return -EPERM;
2225         }
2226         /* for SLEEP MODE */
2227         if (*uwrq == CONNECT_STATUS) {  /* 0 */
2228                 priv->connect_status &= ~FORCE_DISCONNECT;
2229                 if ((priv->connect_status & CONNECT_STATUS_MASK) ==
2230                     CONNECT_STATUS)
2231                         netif_carrier_on(dev);
2232         } else if (*uwrq == DISCONNECT_STATUS) {        /* 1 */
2233                 priv->connect_status |= FORCE_DISCONNECT;
2234                 netif_carrier_off(dev);
2235         } else
2236                 return -EINVAL;
2237         return 0;
2238 }
2239
2240 /*------------------------------------------------------------------*/
2241 /* Private handler : get force disconnect status */
2242 static int ks_wlan_get_detach(struct net_device *dev,
2243                               struct iw_request_info *info, __u32 * uwrq,
2244                               char *extra)
2245 {
2246         struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2247
2248         if (priv->sleep_mode == SLP_SLEEP) {
2249                 return -EPERM;
2250         }
2251         /* for SLEEP MODE */
2252         *uwrq = ((priv->connect_status & FORCE_DISCONNECT) ? 1 : 0);
2253         return 0;
2254 }
2255
2256 /*------------------------------------------------------------------*/
2257 /* Private handler : get connect status */
2258 static int ks_wlan_get_connect(struct net_device *dev,
2259                                struct iw_request_info *info, __u32 * uwrq,
2260                                char *extra)
2261 {
2262         struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2263
2264         if (priv->sleep_mode == SLP_SLEEP) {
2265                 return -EPERM;
2266         }
2267         /* for SLEEP MODE */
2268         *uwrq = (priv->connect_status & CONNECT_STATUS_MASK);
2269         return 0;
2270 }
2271 #endif
2272
2273 /*------------------------------------------------------------------*/
2274 /* Private handler : set preamble */
2275 static int ks_wlan_set_preamble(struct net_device *dev,
2276                                 struct iw_request_info *info, __u32 * uwrq,
2277                                 char *extra)
2278 {
2279         struct ks_wlan_private *priv =
2280             (struct ks_wlan_private *)netdev_priv(dev);
2281
2282         if (priv->sleep_mode == SLP_SLEEP) {
2283                 return -EPERM;
2284         }
2285         /* for SLEEP MODE */
2286         if (*uwrq == LONG_PREAMBLE) {   /* 0 */
2287                 priv->reg.preamble = LONG_PREAMBLE;
2288         } else if (*uwrq == SHORT_PREAMBLE) {   /* 1 */
2289                 priv->reg.preamble = SHORT_PREAMBLE;
2290         } else
2291                 return -EINVAL;
2292
2293         priv->need_commit |= SME_MODE_SET;
2294         return -EINPROGRESS;    /* Call commit handler */
2295
2296 }
2297
2298 /*------------------------------------------------------------------*/
2299 /* Private handler : get preamble */
2300 static int ks_wlan_get_preamble(struct net_device *dev,
2301                                 struct iw_request_info *info, __u32 * uwrq,
2302                                 char *extra)
2303 {
2304         struct ks_wlan_private *priv =
2305             (struct ks_wlan_private *)netdev_priv(dev);
2306
2307         if (priv->sleep_mode == SLP_SLEEP) {
2308                 return -EPERM;
2309         }
2310         /* for SLEEP MODE */
2311         *uwrq = priv->reg.preamble;
2312         return 0;
2313 }
2314
2315 /*------------------------------------------------------------------*/
2316 /* Private handler : set power save mode */
2317 static int ks_wlan_set_powermgt(struct net_device *dev,
2318                                 struct iw_request_info *info, __u32 * uwrq,
2319                                 char *extra)
2320 {
2321         struct ks_wlan_private *priv =
2322             (struct ks_wlan_private *)netdev_priv(dev);
2323
2324         if (priv->sleep_mode == SLP_SLEEP) {
2325                 return -EPERM;
2326         }
2327         /* for SLEEP MODE */
2328         if (*uwrq == POWMGT_ACTIVE_MODE) {      /* 0 */
2329                 priv->reg.powermgt = POWMGT_ACTIVE_MODE;
2330         } else if (*uwrq == POWMGT_SAVE1_MODE) {        /* 1 */
2331                 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2332                         priv->reg.powermgt = POWMGT_SAVE1_MODE;
2333                 else
2334                         return -EINVAL;
2335         } else if (*uwrq == POWMGT_SAVE2_MODE) {        /* 2 */
2336                 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2337                         priv->reg.powermgt = POWMGT_SAVE2_MODE;
2338                 else
2339                         return -EINVAL;
2340         } else
2341                 return -EINVAL;
2342
2343         hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
2344
2345         return 0;
2346 }
2347
2348 /*------------------------------------------------------------------*/
2349 /* Private handler : get power save made */
2350 static int ks_wlan_get_powermgt(struct net_device *dev,
2351                                 struct iw_request_info *info, __u32 * uwrq,
2352                                 char *extra)
2353 {
2354         struct ks_wlan_private *priv =
2355             (struct ks_wlan_private *)netdev_priv(dev);
2356
2357         if (priv->sleep_mode == SLP_SLEEP) {
2358                 return -EPERM;
2359         }
2360         /* for SLEEP MODE */
2361         *uwrq = priv->reg.powermgt;
2362         return 0;
2363 }
2364
2365 /*------------------------------------------------------------------*/
2366 /* Private handler : set scan type */
2367 static int ks_wlan_set_scan_type(struct net_device *dev,
2368                                  struct iw_request_info *info, __u32 * uwrq,
2369                                  char *extra)
2370 {
2371         struct ks_wlan_private *priv =
2372             (struct ks_wlan_private *)netdev_priv(dev);
2373
2374         if (priv->sleep_mode == SLP_SLEEP) {
2375                 return -EPERM;
2376         }
2377         /* for SLEEP MODE */
2378         if (*uwrq == ACTIVE_SCAN) {     /* 0 */
2379                 priv->reg.scan_type = ACTIVE_SCAN;
2380         } else if (*uwrq == PASSIVE_SCAN) {     /* 1 */
2381                 priv->reg.scan_type = PASSIVE_SCAN;
2382         } else
2383                 return -EINVAL;
2384
2385         return 0;
2386 }
2387
2388 /*------------------------------------------------------------------*/
2389 /* Private handler : get scan type */
2390 static int ks_wlan_get_scan_type(struct net_device *dev,
2391                                  struct iw_request_info *info, __u32 * uwrq,
2392                                  char *extra)
2393 {
2394         struct ks_wlan_private *priv =
2395             (struct ks_wlan_private *)netdev_priv(dev);
2396
2397         if (priv->sleep_mode == SLP_SLEEP) {
2398                 return -EPERM;
2399         }
2400         /* for SLEEP MODE */
2401         *uwrq = priv->reg.scan_type;
2402         return 0;
2403 }
2404
2405 #if 0
2406 /*------------------------------------------------------------------*/
2407 /* Private handler : write raw data to device */
2408 static int ks_wlan_data_write(struct net_device *dev,
2409                               struct iw_request_info *info,
2410                               struct iw_point *dwrq, char *extra)
2411 {
2412         struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2413         unsigned char *wbuff = NULL;
2414
2415         if (priv->sleep_mode == SLP_SLEEP) {
2416                 return -EPERM;
2417         }
2418         /* for SLEEP MODE */
2419         wbuff = (unsigned char *)kmalloc(dwrq->length, GFP_ATOMIC);
2420         if (!wbuff)
2421                 return -EFAULT;
2422         memcpy(wbuff, extra, dwrq->length);
2423
2424         /* write to device */
2425         ks_wlan_hw_tx(priv, wbuff, dwrq->length, NULL, NULL, NULL);
2426
2427         return 0;
2428 }
2429
2430 /*------------------------------------------------------------------*/
2431 /* Private handler : read raw data form device */
2432 static int ks_wlan_data_read(struct net_device *dev,
2433                              struct iw_request_info *info,
2434                              struct iw_point *dwrq, char *extra)
2435 {
2436         struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2437         unsigned short read_length;
2438
2439         if (priv->sleep_mode == SLP_SLEEP) {
2440                 return -EPERM;
2441         }
2442         /* for SLEEP MODE */
2443         if (!atomic_read(&priv->event_count)) {
2444                 if (priv->dev_state < DEVICE_STATE_BOOT) {      /* Remove device */
2445                         read_length = 4;
2446                         memset(extra, 0xff, read_length);
2447                         dwrq->length = read_length;
2448                         return 0;
2449                 }
2450                 read_length = 0;
2451                 memset(extra, 0, 1);
2452                 dwrq->length = 0;
2453                 return 0;
2454         }
2455
2456         if (atomic_read(&priv->event_count) > 0)
2457                 atomic_dec(&priv->event_count);
2458
2459         spin_lock(&priv->dev_read_lock);        /* request spin lock */
2460
2461         /* Copy length max size 0x07ff */
2462         if (priv->dev_size[priv->dev_count] > 2047)
2463                 read_length = 2047;
2464         else
2465                 read_length = priv->dev_size[priv->dev_count];
2466
2467         /* Copy data */
2468         memcpy(extra, &(priv->dev_data[priv->dev_count][0]), read_length);
2469
2470         spin_unlock(&priv->dev_read_lock);      /* release spin lock */
2471
2472         /* Initialize */
2473         priv->dev_data[priv->dev_count] = 0;
2474         priv->dev_size[priv->dev_count] = 0;
2475
2476         priv->dev_count++;
2477         if (priv->dev_count == DEVICE_STOCK_COUNT)
2478                 priv->dev_count = 0;
2479
2480         /* Set read size */
2481         dwrq->length = read_length;
2482
2483         return 0;
2484 }
2485 #endif
2486
2487 #if 0
2488 /*------------------------------------------------------------------*/
2489 /* Private handler : get wep string */
2490 #define WEP_ASCII_BUFF_SIZE (17+64*4+1)
2491 static int ks_wlan_get_wep_ascii(struct net_device *dev,
2492                                  struct iw_request_info *info,
2493                                  struct iw_point *dwrq, char *extra)
2494 {
2495         struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2496         int i, j, len = 0;
2497         char tmp[WEP_ASCII_BUFF_SIZE];
2498
2499         if (priv->sleep_mode == SLP_SLEEP) {
2500                 return -EPERM;
2501         }
2502         /* for SLEEP MODE */
2503         strcpy(tmp, " WEP keys ASCII \n");
2504         len += strlen(" WEP keys ASCII \n");
2505
2506         for (i = 0; i < 4; i++) {
2507                 strcpy(tmp + len, "\t[");
2508                 len += strlen("\t[");
2509                 tmp[len] = '1' + i;
2510                 len++;
2511                 strcpy(tmp + len, "] ");
2512                 len += strlen("] ");
2513                 if (priv->reg.wep_key[i].size) {
2514                         strcpy(tmp + len,
2515                                (priv->reg.wep_key[i].size <
2516                                 6 ? "(40bits) [" : "(104bits) ["));
2517                         len +=
2518                             strlen((priv->reg.wep_key[i].size <
2519                                     6 ? "(40bits) [" : "(104bits) ["));
2520                         for (j = 0; j < priv->reg.wep_key[i].size; j++, len++)
2521                                 tmp[len] =
2522                                     (isprint(priv->reg.wep_key[i].val[j]) ?
2523                                      priv->reg.wep_key[i].val[j] : ' ');
2524
2525                         strcpy(tmp + len, "]\n");
2526                         len += strlen("]\n");
2527                 } else {
2528                         strcpy(tmp + len, "off\n");
2529                         len += strlen("off\n");
2530                 }
2531         }
2532
2533         memcpy(extra, tmp, len);
2534         dwrq->length = len + 1;
2535         return 0;
2536 }
2537 #endif
2538
2539 /*------------------------------------------------------------------*/
2540 /* Private handler : set beacon lost count */
2541 static int ks_wlan_set_beacon_lost(struct net_device *dev,
2542                                    struct iw_request_info *info, __u32 * uwrq,
2543                                    char *extra)
2544 {
2545         struct ks_wlan_private *priv =
2546             (struct ks_wlan_private *)netdev_priv(dev);
2547
2548         if (priv->sleep_mode == SLP_SLEEP) {
2549                 return -EPERM;
2550         }
2551         /* for SLEEP MODE */
2552         if (*uwrq >= BEACON_LOST_COUNT_MIN && *uwrq <= BEACON_LOST_COUNT_MAX) {
2553                 priv->reg.beacon_lost_count = *uwrq;
2554         } else
2555                 return -EINVAL;
2556
2557         if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
2558                 priv->need_commit |= SME_MODE_SET;
2559                 return -EINPROGRESS;    /* Call commit handler */
2560         } else
2561                 return 0;
2562 }
2563
2564 /*------------------------------------------------------------------*/
2565 /* Private handler : get beacon lost count */
2566 static int ks_wlan_get_beacon_lost(struct net_device *dev,
2567                                    struct iw_request_info *info, __u32 * uwrq,
2568                                    char *extra)
2569 {
2570         struct ks_wlan_private *priv =
2571             (struct ks_wlan_private *)netdev_priv(dev);
2572
2573         if (priv->sleep_mode == SLP_SLEEP) {
2574                 return -EPERM;
2575         }
2576         /* for SLEEP MODE */
2577         *uwrq = priv->reg.beacon_lost_count;
2578         return 0;
2579 }
2580
2581 /*------------------------------------------------------------------*/
2582 /* Private handler : set phy type */
2583 static int ks_wlan_set_phy_type(struct net_device *dev,
2584                                 struct iw_request_info *info, __u32 * uwrq,
2585                                 char *extra)
2586 {
2587         struct ks_wlan_private *priv =
2588             (struct ks_wlan_private *)netdev_priv(dev);
2589
2590         if (priv->sleep_mode == SLP_SLEEP) {
2591                 return -EPERM;
2592         }
2593         /* for SLEEP MODE */
2594         if (*uwrq == D_11B_ONLY_MODE) { /* 0 */
2595                 priv->reg.phy_type = D_11B_ONLY_MODE;
2596         } else if (*uwrq == D_11G_ONLY_MODE) {  /* 1 */
2597                 priv->reg.phy_type = D_11G_ONLY_MODE;
2598         } else if (*uwrq == D_11BG_COMPATIBLE_MODE) {   /* 2 */
2599                 priv->reg.phy_type = D_11BG_COMPATIBLE_MODE;
2600         } else
2601                 return -EINVAL;
2602
2603         priv->need_commit |= SME_MODE_SET;
2604         return -EINPROGRESS;    /* Call commit handler */
2605 }
2606
2607 /*------------------------------------------------------------------*/
2608 /* Private handler : get phy type */
2609 static int ks_wlan_get_phy_type(struct net_device *dev,
2610                                 struct iw_request_info *info, __u32 * uwrq,
2611                                 char *extra)
2612 {
2613         struct ks_wlan_private *priv =
2614             (struct ks_wlan_private *)netdev_priv(dev);
2615
2616         if (priv->sleep_mode == SLP_SLEEP) {
2617                 return -EPERM;
2618         }
2619         /* for SLEEP MODE */
2620         *uwrq = priv->reg.phy_type;
2621         return 0;
2622 }
2623
2624 /*------------------------------------------------------------------*/
2625 /* Private handler : set cts mode */
2626 static int ks_wlan_set_cts_mode(struct net_device *dev,
2627                                 struct iw_request_info *info, __u32 * uwrq,
2628                                 char *extra)
2629 {
2630         struct ks_wlan_private *priv =
2631             (struct ks_wlan_private *)netdev_priv(dev);
2632
2633         if (priv->sleep_mode == SLP_SLEEP) {
2634                 return -EPERM;
2635         }
2636         /* for SLEEP MODE */
2637         if (*uwrq == CTS_MODE_FALSE) {  /* 0 */
2638                 priv->reg.cts_mode = CTS_MODE_FALSE;
2639         } else if (*uwrq == CTS_MODE_TRUE) {    /* 1 */
2640                 if (priv->reg.phy_type == D_11G_ONLY_MODE ||
2641                     priv->reg.phy_type == D_11BG_COMPATIBLE_MODE)
2642                         priv->reg.cts_mode = CTS_MODE_TRUE;
2643                 else
2644                         priv->reg.cts_mode = CTS_MODE_FALSE;
2645         } else
2646                 return -EINVAL;
2647
2648         priv->need_commit |= SME_MODE_SET;
2649         return -EINPROGRESS;    /* Call commit handler */
2650 }
2651
2652 /*------------------------------------------------------------------*/
2653 /* Private handler : get cts mode */
2654 static int ks_wlan_get_cts_mode(struct net_device *dev,
2655                                 struct iw_request_info *info, __u32 * uwrq,
2656                                 char *extra)
2657 {
2658         struct ks_wlan_private *priv =
2659             (struct ks_wlan_private *)netdev_priv(dev);
2660
2661         if (priv->sleep_mode == SLP_SLEEP) {
2662                 return -EPERM;
2663         }
2664         /* for SLEEP MODE */
2665         *uwrq = priv->reg.cts_mode;
2666         return 0;
2667 }
2668
2669 /*------------------------------------------------------------------*/
2670 /* Private handler : set sleep mode */
2671 static int ks_wlan_set_sleep_mode(struct net_device *dev,
2672                                   struct iw_request_info *info,
2673                                   __u32 * uwrq, char *extra)
2674 {
2675         struct ks_wlan_private *priv =
2676             (struct ks_wlan_private *)netdev_priv(dev);
2677
2678         DPRINTK(2, "\n");
2679
2680         if (*uwrq == SLP_SLEEP) {
2681                 priv->sleep_mode = *uwrq;
2682                 printk("SET_SLEEP_MODE %d\n", priv->sleep_mode);
2683
2684                 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2685                 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2686
2687         } else if (*uwrq == SLP_ACTIVE) {
2688                 priv->sleep_mode = *uwrq;
2689                 printk("SET_SLEEP_MODE %d\n", priv->sleep_mode);
2690                 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2691         } else {
2692                 printk("SET_SLEEP_MODE %d errror\n", *uwrq);
2693                 return -EINVAL;
2694         }
2695
2696         return 0;
2697 }
2698
2699 /*------------------------------------------------------------------*/
2700 /* Private handler : get sleep mode */
2701 static int ks_wlan_get_sleep_mode(struct net_device *dev,
2702                                   struct iw_request_info *info,
2703                                   __u32 * uwrq, char *extra)
2704 {
2705         struct ks_wlan_private *priv =
2706             (struct ks_wlan_private *)netdev_priv(dev);
2707
2708         DPRINTK(2, "GET_SLEEP_MODE %d\n", priv->sleep_mode);
2709         *uwrq = priv->sleep_mode;
2710
2711         return 0;
2712 }
2713
2714 #if 0
2715 /*------------------------------------------------------------------*/
2716 /* Private handler : set phy information timer */
2717 static int ks_wlan_set_phy_information_timer(struct net_device *dev,
2718                                              struct iw_request_info *info,
2719                                              __u32 * uwrq, char *extra)
2720 {
2721         struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2722
2723         if (priv->sleep_mode == SLP_SLEEP) {
2724                 return -EPERM;
2725         }
2726         /* for SLEEP MODE */
2727         if (*uwrq >= 0 && *uwrq <= 0xFFFF)      /* 0-65535 */
2728                 priv->reg.phy_info_timer = (uint16_t) * uwrq;
2729         else
2730                 return -EINVAL;
2731
2732         hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST);
2733
2734         return 0;
2735 }
2736
2737 /*------------------------------------------------------------------*/
2738 /* Private handler : get phy information timer */
2739 static int ks_wlan_get_phy_information_timer(struct net_device *dev,
2740                                              struct iw_request_info *info,
2741                                              __u32 * uwrq, char *extra)
2742 {
2743         struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2744
2745         if (priv->sleep_mode == SLP_SLEEP) {
2746                 return -EPERM;
2747         }
2748         /* for SLEEP MODE */
2749         *uwrq = priv->reg.phy_info_timer;
2750         return 0;
2751 }
2752 #endif
2753
2754 #ifdef WPS
2755 /*------------------------------------------------------------------*/
2756 /* Private handler : set WPS enable */
2757 static int ks_wlan_set_wps_enable(struct net_device *dev,
2758                                   struct iw_request_info *info, __u32 * uwrq,
2759                                   char *extra)
2760 {
2761         struct ks_wlan_private *priv =
2762             (struct ks_wlan_private *)netdev_priv(dev);
2763         DPRINTK(2, "\n");
2764
2765         if (priv->sleep_mode == SLP_SLEEP) {
2766                 return -EPERM;
2767         }
2768         /* for SLEEP MODE */
2769         if (*uwrq == 0 || *uwrq == 1)
2770                 priv->wps.wps_enabled = *uwrq;
2771         else
2772                 return -EINVAL;
2773
2774         hostif_sme_enqueue(priv, SME_WPS_ENABLE_REQUEST);
2775
2776         return 0;
2777 }
2778
2779 /*------------------------------------------------------------------*/
2780 /* Private handler : get WPS enable */
2781 static int ks_wlan_get_wps_enable(struct net_device *dev,
2782                                   struct iw_request_info *info, __u32 * uwrq,
2783                                   char *extra)
2784 {
2785         struct ks_wlan_private *priv =
2786             (struct ks_wlan_private *)netdev_priv(dev);
2787         DPRINTK(2, "\n");
2788
2789         if (priv->sleep_mode == SLP_SLEEP) {
2790                 return -EPERM;
2791         }
2792         /* for SLEEP MODE */
2793         *uwrq = priv->wps.wps_enabled;
2794         printk("return=%d\n", *uwrq);
2795
2796         return 0;
2797 }
2798
2799 /*------------------------------------------------------------------*/
2800 /* Private handler : set WPS probe req */
2801 static int ks_wlan_set_wps_probe_req(struct net_device *dev,
2802                                      struct iw_request_info *info,
2803                                      struct iw_point *dwrq, char *extra)
2804 {
2805         uint8_t *p = extra;
2806         unsigned char len;
2807         struct ks_wlan_private *priv =
2808             (struct ks_wlan_private *)netdev_priv(dev);
2809
2810         DPRINTK(2, "\n");
2811
2812         if (priv->sleep_mode == SLP_SLEEP) {
2813                 return -EPERM;
2814         }
2815         /* for SLEEP MODE */
2816         DPRINTK(2, "dwrq->length=%d\n", dwrq->length);
2817
2818         /* length check */
2819         if (p[1] + 2 != dwrq->length || dwrq->length > 256) {
2820                 return -EINVAL;
2821         }
2822
2823         priv->wps.ielen = p[1] + 2 + 1; /* IE header + IE + sizeof(len) */
2824         len = p[1] + 2; /* IE header + IE */
2825
2826         memcpy(priv->wps.ie, &len, sizeof(len));
2827         p = memcpy(priv->wps.ie + 1, p, len);
2828
2829         DPRINTK(2, "%d(%#x): %02X %02X %02X %02X ... %02X %02X %02X\n",
2830                 priv->wps.ielen, priv->wps.ielen, p[0], p[1], p[2], p[3],
2831                 p[priv->wps.ielen - 3], p[priv->wps.ielen - 2],
2832                 p[priv->wps.ielen - 1]);
2833
2834         hostif_sme_enqueue(priv, SME_WPS_PROBE_REQUEST);
2835
2836         return 0;
2837 }
2838
2839 #if 0
2840 /*------------------------------------------------------------------*/
2841 /* Private handler : get WPS probe req */
2842 static int ks_wlan_get_wps_probe_req(struct net_device *dev,
2843                                      struct iw_request_info *info,
2844                                      __u32 * uwrq, char *extra)
2845 {
2846         struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2847         DPRINTK(2, "\n");
2848
2849         if (priv->sleep_mode == SLP_SLEEP) {
2850                 return -EPERM;
2851         }
2852         /* for SLEEP MODE */
2853         return 0;
2854 }
2855 #endif
2856 #endif /* WPS */
2857
2858 /*------------------------------------------------------------------*/
2859 /* Private handler : set tx gain control value */
2860 static int ks_wlan_set_tx_gain(struct net_device *dev,
2861                                struct iw_request_info *info, __u32 * uwrq,
2862                                char *extra)
2863 {
2864         struct ks_wlan_private *priv =
2865             (struct ks_wlan_private *)netdev_priv(dev);
2866
2867         if (priv->sleep_mode == SLP_SLEEP) {
2868                 return -EPERM;
2869         }
2870         /* for SLEEP MODE */
2871         if (*uwrq >= 0 && *uwrq <= 0xFF)        /* 0-255 */
2872                 priv->gain.TxGain = (uint8_t) * uwrq;
2873         else
2874                 return -EINVAL;
2875
2876         if (priv->gain.TxGain < 0xFF)
2877                 priv->gain.TxMode = 1;
2878         else
2879                 priv->gain.TxMode = 0;
2880
2881         hostif_sme_enqueue(priv, SME_SET_GAIN);
2882         return 0;
2883 }
2884
2885 /*------------------------------------------------------------------*/
2886 /* Private handler : get tx gain control value */
2887 static int ks_wlan_get_tx_gain(struct net_device *dev,
2888                                struct iw_request_info *info, __u32 * uwrq,
2889                                char *extra)
2890 {
2891         struct ks_wlan_private *priv =
2892             (struct ks_wlan_private *)netdev_priv(dev);
2893
2894         if (priv->sleep_mode == SLP_SLEEP) {
2895                 return -EPERM;
2896         }
2897         /* for SLEEP MODE */
2898         *uwrq = priv->gain.TxGain;
2899         hostif_sme_enqueue(priv, SME_GET_GAIN);
2900         return 0;
2901 }
2902
2903 /*------------------------------------------------------------------*/
2904 /* Private handler : set rx gain control value */
2905 static int ks_wlan_set_rx_gain(struct net_device *dev,
2906                                struct iw_request_info *info, __u32 * uwrq,
2907                                char *extra)
2908 {
2909         struct ks_wlan_private *priv =
2910             (struct ks_wlan_private *)netdev_priv(dev);
2911
2912         if (priv->sleep_mode == SLP_SLEEP) {
2913                 return -EPERM;
2914         }
2915         /* for SLEEP MODE */
2916         if (*uwrq >= 0 && *uwrq <= 0xFF)        /* 0-255 */
2917                 priv->gain.RxGain = (uint8_t) * uwrq;
2918         else
2919                 return -EINVAL;
2920
2921         if (priv->gain.RxGain < 0xFF)
2922                 priv->gain.RxMode = 1;
2923         else
2924                 priv->gain.RxMode = 0;
2925
2926         hostif_sme_enqueue(priv, SME_SET_GAIN);
2927         return 0;
2928 }
2929
2930 /*------------------------------------------------------------------*/
2931 /* Private handler : get rx gain control value */
2932 static int ks_wlan_get_rx_gain(struct net_device *dev,
2933                                struct iw_request_info *info, __u32 * uwrq,
2934                                char *extra)
2935 {
2936         struct ks_wlan_private *priv =
2937             (struct ks_wlan_private *)netdev_priv(dev);
2938
2939         if (priv->sleep_mode == SLP_SLEEP) {
2940                 return -EPERM;
2941         }
2942         /* for SLEEP MODE */
2943         *uwrq = priv->gain.RxGain;
2944         hostif_sme_enqueue(priv, SME_GET_GAIN);
2945         return 0;
2946 }
2947
2948 #if 0
2949 /*------------------------------------------------------------------*/
2950 /* Private handler : set region value */
2951 static int ks_wlan_set_region(struct net_device *dev,
2952                               struct iw_request_info *info, __u32 * uwrq,
2953                               char *extra)
2954 {
2955         struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2956
2957         if (priv->sleep_mode == SLP_SLEEP) {
2958                 return -EPERM;
2959         }
2960         /* for SLEEP MODE */
2961         if (*uwrq >= 0x9 && *uwrq <= 0xF)       /* 0x9-0xf */
2962                 priv->region = (uint8_t) * uwrq;
2963         else
2964                 return -EINVAL;
2965
2966         hostif_sme_enqueue(priv, SME_SET_REGION);
2967         return 0;
2968 }
2969 #endif
2970
2971 /*------------------------------------------------------------------*/
2972 /* Private handler : get eeprom checksum result */
2973 static int ks_wlan_get_eeprom_cksum(struct net_device *dev,
2974                                     struct iw_request_info *info, __u32 * uwrq,
2975                                     char *extra)
2976 {
2977         struct ks_wlan_private *priv =
2978             (struct ks_wlan_private *)netdev_priv(dev);
2979
2980         *uwrq = priv->eeprom_checksum;
2981         return 0;
2982 }
2983
2984 static void print_hif_event(int event)
2985 {
2986
2987         switch (event) {
2988         case HIF_DATA_REQ:
2989                 printk("HIF_DATA_REQ\n");
2990                 break;
2991         case HIF_DATA_IND:
2992                 printk("HIF_DATA_IND\n");
2993                 break;
2994         case HIF_MIB_GET_REQ:
2995                 printk("HIF_MIB_GET_REQ\n");
2996                 break;
2997         case HIF_MIB_GET_CONF:
2998                 printk("HIF_MIB_GET_CONF\n");
2999                 break;
3000         case HIF_MIB_SET_REQ:
3001                 printk("HIF_MIB_SET_REQ\n");
3002                 break;
3003         case HIF_MIB_SET_CONF:
3004                 printk("HIF_MIB_SET_CONF\n");
3005                 break;
3006         case HIF_POWERMGT_REQ:
3007                 printk("HIF_POWERMGT_REQ\n");
3008                 break;
3009         case HIF_POWERMGT_CONF:
3010                 printk("HIF_POWERMGT_CONF\n");
3011                 break;
3012         case HIF_START_REQ:
3013                 printk("HIF_START_REQ\n");
3014                 break;
3015         case HIF_START_CONF:
3016                 printk("HIF_START_CONF\n");
3017                 break;
3018         case HIF_CONNECT_IND:
3019                 printk("HIF_CONNECT_IND\n");
3020                 break;
3021         case HIF_STOP_REQ:
3022                 printk("HIF_STOP_REQ\n");
3023                 break;
3024         case HIF_STOP_CONF:
3025                 printk("HIF_STOP_CONF\n");
3026                 break;
3027         case HIF_PS_ADH_SET_REQ:
3028                 printk("HIF_PS_ADH_SET_REQ\n");
3029                 break;
3030         case HIF_PS_ADH_SET_CONF:
3031                 printk("HIF_PS_ADH_SET_CONF\n");
3032                 break;
3033         case HIF_INFRA_SET_REQ:
3034                 printk("HIF_INFRA_SET_REQ\n");
3035                 break;
3036         case HIF_INFRA_SET_CONF:
3037                 printk("HIF_INFRA_SET_CONF\n");
3038                 break;
3039         case HIF_ADH_SET_REQ:
3040                 printk("HIF_ADH_SET_REQ\n");
3041                 break;
3042         case HIF_ADH_SET_CONF:
3043                 printk("HIF_ADH_SET_CONF\n");
3044                 break;
3045         case HIF_AP_SET_REQ:
3046                 printk("HIF_AP_SET_REQ\n");
3047                 break;
3048         case HIF_AP_SET_CONF:
3049                 printk("HIF_AP_SET_CONF\n");
3050                 break;
3051         case HIF_ASSOC_INFO_IND:
3052                 printk("HIF_ASSOC_INFO_IND\n");
3053                 break;
3054         case HIF_MIC_FAILURE_REQ:
3055                 printk("HIF_MIC_FAILURE_REQ\n");
3056                 break;
3057         case HIF_MIC_FAILURE_CONF:
3058                 printk("HIF_MIC_FAILURE_CONF\n");
3059                 break;
3060         case HIF_SCAN_REQ:
3061                 printk("HIF_SCAN_REQ\n");
3062                 break;
3063         case HIF_SCAN_CONF:
3064                 printk("HIF_SCAN_CONF\n");
3065                 break;
3066         case HIF_PHY_INFO_REQ:
3067                 printk("HIF_PHY_INFO_REQ\n");
3068                 break;
3069         case HIF_PHY_INFO_CONF:
3070                 printk("HIF_PHY_INFO_CONF\n");
3071                 break;
3072         case HIF_SLEEP_REQ:
3073                 printk("HIF_SLEEP_REQ\n");
3074                 break;
3075         case HIF_SLEEP_CONF:
3076                 printk("HIF_SLEEP_CONF\n");
3077                 break;
3078         case HIF_PHY_INFO_IND:
3079                 printk("HIF_PHY_INFO_IND\n");
3080                 break;
3081         case HIF_SCAN_IND:
3082                 printk("HIF_SCAN_IND\n");
3083                 break;
3084         case HIF_INFRA_SET2_REQ:
3085                 printk("HIF_INFRA_SET2_REQ\n");
3086                 break;
3087         case HIF_INFRA_SET2_CONF:
3088                 printk("HIF_INFRA_SET2_CONF\n");
3089                 break;
3090         case HIF_ADH_SET2_REQ:
3091                 printk("HIF_ADH_SET2_REQ\n");
3092                 break;
3093         case HIF_ADH_SET2_CONF:
3094                 printk("HIF_ADH_SET2_CONF\n");
3095         }
3096 }
3097
3098 /*------------------------------------------------------------------*/
3099 /* Private handler : get host command history */
3100 static int ks_wlan_hostt(struct net_device *dev, struct iw_request_info *info,
3101                          __u32 * uwrq, char *extra)
3102 {
3103         int i, event;
3104         struct ks_wlan_private *priv =
3105             (struct ks_wlan_private *)netdev_priv(dev);
3106
3107         for (i = 63; i >= 0; i--) {
3108                 event =
3109                     priv->hostt.buff[(priv->hostt.qtail - 1 - i) %
3110                                      SME_EVENT_BUFF_SIZE];
3111                 print_hif_event(event);
3112         }
3113         return 0;
3114 }
3115
3116 /* Structures to export the Wireless Handlers */
3117
3118 static const struct iw_priv_args ks_wlan_private_args[] = {
3119 /*{ cmd, set_args, get_args, name[16] } */
3120         {KS_WLAN_GET_FIRM_VERSION, IW_PRIV_TYPE_NONE,
3121          IW_PRIV_TYPE_CHAR | (128 + 1), "GetFirmwareVer"},
3122 #ifdef WPS
3123         {KS_WLAN_SET_WPS_ENABLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3124          IW_PRIV_TYPE_NONE, "SetWPSEnable"},
3125         {KS_WLAN_GET_WPS_ENABLE, IW_PRIV_TYPE_NONE,
3126          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetW"},
3127         {KS_WLAN_SET_WPS_PROBE_REQ, IW_PRIV_TYPE_BYTE | 2047, IW_PRIV_TYPE_NONE,
3128          "SetWPSProbeReq"},
3129 #endif /* WPS */
3130         {KS_WLAN_SET_PREAMBLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3131          IW_PRIV_TYPE_NONE, "SetPreamble"},
3132         {KS_WLAN_GET_PREAMBLE, IW_PRIV_TYPE_NONE,
3133          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPreamble"},
3134         {KS_WLAN_SET_POWER_SAVE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3135          IW_PRIV_TYPE_NONE, "SetPowerSave"},
3136         {KS_WLAN_GET_POWER_SAVE, IW_PRIV_TYPE_NONE,
3137          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPowerSave"},
3138         {KS_WLAN_SET_SCAN_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3139          IW_PRIV_TYPE_NONE, "SetScanType"},
3140         {KS_WLAN_GET_SCAN_TYPE, IW_PRIV_TYPE_NONE,
3141          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetScanType"},
3142         {KS_WLAN_SET_RX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3143          IW_PRIV_TYPE_NONE, "SetRxGain"},
3144         {KS_WLAN_GET_RX_GAIN, IW_PRIV_TYPE_NONE,
3145          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetRxGain"},
3146         {KS_WLAN_HOSTT, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | (128 + 1),
3147          "hostt"},
3148         {KS_WLAN_SET_BEACON_LOST, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3149          IW_PRIV_TYPE_NONE, "SetBeaconLost"},
3150         {KS_WLAN_GET_BEACON_LOST, IW_PRIV_TYPE_NONE,
3151          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetBeaconLost"},
3152         {KS_WLAN_SET_SLEEP_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3153          IW_PRIV_TYPE_NONE, "SetSleepMode"},
3154         {KS_WLAN_GET_SLEEP_MODE, IW_PRIV_TYPE_NONE,
3155          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetSleepMode"},
3156         {KS_WLAN_SET_TX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3157          IW_PRIV_TYPE_NONE, "SetTxGain"},
3158         {KS_WLAN_GET_TX_GAIN, IW_PRIV_TYPE_NONE,
3159          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetTxGain"},
3160         {KS_WLAN_SET_PHY_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3161          IW_PRIV_TYPE_NONE, "SetPhyType"},
3162         {KS_WLAN_GET_PHY_TYPE, IW_PRIV_TYPE_NONE,
3163          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPhyType"},
3164         {KS_WLAN_SET_CTS_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3165          IW_PRIV_TYPE_NONE, "SetCtsMode"},
3166         {KS_WLAN_GET_CTS_MODE, IW_PRIV_TYPE_NONE,
3167          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetCtsMode"},
3168         {KS_WLAN_GET_EEPROM_CKSUM, IW_PRIV_TYPE_NONE,
3169          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetChecksum"},
3170 };
3171
3172 static const iw_handler ks_wlan_handler[] = {
3173         (iw_handler) ks_wlan_config_commit,     /* SIOCSIWCOMMIT */
3174         (iw_handler) ks_wlan_get_name,  /* SIOCGIWNAME */
3175         (iw_handler) NULL,      /* SIOCSIWNWID */
3176         (iw_handler) NULL,      /* SIOCGIWNWID */
3177         (iw_handler) ks_wlan_set_freq,  /* SIOCSIWFREQ */
3178         (iw_handler) ks_wlan_get_freq,  /* SIOCGIWFREQ */
3179         (iw_handler) ks_wlan_set_mode,  /* SIOCSIWMODE */
3180         (iw_handler) ks_wlan_get_mode,  /* SIOCGIWMODE */
3181 #ifndef KSC_OPNOTSUPP
3182         (iw_handler) ks_wlan_set_sens,  /* SIOCSIWSENS */
3183         (iw_handler) ks_wlan_get_sens,  /* SIOCGIWSENS */
3184 #else /* KSC_OPNOTSUPP */
3185         (iw_handler) NULL,      /* SIOCSIWSENS */
3186         (iw_handler) NULL,      /* SIOCGIWSENS */
3187 #endif /* KSC_OPNOTSUPP */
3188         (iw_handler) NULL,      /* SIOCSIWRANGE */
3189         (iw_handler) ks_wlan_get_range, /* SIOCGIWRANGE */
3190         (iw_handler) NULL,      /* SIOCSIWPRIV */
3191         (iw_handler) NULL,      /* SIOCGIWPRIV */
3192         (iw_handler) NULL,      /* SIOCSIWSTATS */
3193         (iw_handler) ks_wlan_get_iwstats,       /* SIOCGIWSTATS */
3194         (iw_handler) NULL,      /* SIOCSIWSPY */
3195         (iw_handler) NULL,      /* SIOCGIWSPY */
3196         (iw_handler) NULL,      /* SIOCSIWTHRSPY */
3197         (iw_handler) NULL,      /* SIOCGIWTHRSPY */
3198         (iw_handler) ks_wlan_set_wap,   /* SIOCSIWAP */
3199         (iw_handler) ks_wlan_get_wap,   /* SIOCGIWAP */
3200 //      (iw_handler) NULL,                      /* SIOCSIWMLME */
3201         (iw_handler) ks_wlan_set_mlme,  /* SIOCSIWMLME */
3202         (iw_handler) ks_wlan_get_aplist,        /* SIOCGIWAPLIST */
3203         (iw_handler) ks_wlan_set_scan,  /* SIOCSIWSCAN */
3204         (iw_handler) ks_wlan_get_scan,  /* SIOCGIWSCAN */
3205         (iw_handler) ks_wlan_set_essid, /* SIOCSIWESSID */
3206         (iw_handler) ks_wlan_get_essid, /* SIOCGIWESSID */
3207         (iw_handler) ks_wlan_set_nick,  /* SIOCSIWNICKN */
3208         (iw_handler) ks_wlan_get_nick,  /* SIOCGIWNICKN */
3209         (iw_handler) NULL,      /* -- hole -- */
3210         (iw_handler) NULL,      /* -- hole -- */
3211         (iw_handler) ks_wlan_set_rate,  /* SIOCSIWRATE */
3212         (iw_handler) ks_wlan_get_rate,  /* SIOCGIWRATE */
3213         (iw_handler) ks_wlan_set_rts,   /* SIOCSIWRTS */
3214         (iw_handler) ks_wlan_get_rts,   /* SIOCGIWRTS */
3215         (iw_handler) ks_wlan_set_frag,  /* SIOCSIWFRAG */
3216         (iw_handler) ks_wlan_get_frag,  /* SIOCGIWFRAG */
3217 #ifndef KSC_OPNOTSUPP
3218         (iw_handler) ks_wlan_set_txpow, /* SIOCSIWTXPOW */
3219         (iw_handler) ks_wlan_get_txpow, /* SIOCGIWTXPOW */
3220         (iw_handler) ks_wlan_set_retry, /* SIOCSIWRETRY */
3221         (iw_handler) ks_wlan_get_retry, /* SIOCGIWRETRY */
3222 #else /* KSC_OPNOTSUPP */
3223         (iw_handler) NULL,      /* SIOCSIWTXPOW */
3224         (iw_handler) NULL,      /* SIOCGIWTXPOW */
3225         (iw_handler) NULL,      /* SIOCSIWRETRY */
3226         (iw_handler) NULL,      /* SIOCGIWRETRY */
3227 #endif /* KSC_OPNOTSUPP */
3228         (iw_handler) ks_wlan_set_encode,        /* SIOCSIWENCODE */
3229         (iw_handler) ks_wlan_get_encode,        /* SIOCGIWENCODE */
3230         (iw_handler) ks_wlan_set_power, /* SIOCSIWPOWER */
3231         (iw_handler) ks_wlan_get_power, /* SIOCGIWPOWER */
3232         (iw_handler) NULL,      /* -- hole -- */
3233         (iw_handler) NULL,      /* -- hole -- */
3234 //      (iw_handler) NULL,                      /* SIOCSIWGENIE */
3235         (iw_handler) ks_wlan_set_genie, /* SIOCSIWGENIE */
3236         (iw_handler) NULL,      /* SIOCGIWGENIE */
3237         (iw_handler) ks_wlan_set_auth_mode,     /* SIOCSIWAUTH */
3238         (iw_handler) ks_wlan_get_auth_mode,     /* SIOCGIWAUTH */
3239         (iw_handler) ks_wlan_set_encode_ext,    /* SIOCSIWENCODEEXT */
3240         (iw_handler) ks_wlan_get_encode_ext,    /* SIOCGIWENCODEEXT */
3241         (iw_handler) ks_wlan_set_pmksa, /* SIOCSIWPMKSA */
3242         (iw_handler) NULL,      /* -- hole -- */
3243 };
3244
3245 /* private_handler */
3246 static const iw_handler ks_wlan_private_handler[] = {
3247         (iw_handler) NULL,      /*  0 */
3248         (iw_handler) NULL,      /*  1, used to be: KS_WLAN_GET_DRIVER_VERSION */
3249         (iw_handler) NULL,      /*  2 */
3250         (iw_handler) ks_wlan_get_firmware_version,      /*  3 KS_WLAN_GET_FIRM_VERSION */
3251 #ifdef WPS
3252         (iw_handler) ks_wlan_set_wps_enable,    /*  4 KS_WLAN_SET_WPS_ENABLE  */
3253         (iw_handler) ks_wlan_get_wps_enable,    /*  5 KS_WLAN_GET_WPS_ENABLE  */
3254         (iw_handler) ks_wlan_set_wps_probe_req, /*  6 KS_WLAN_SET_WPS_PROBE_REQ */
3255 #else
3256         (iw_handler) NULL,      /*  4 */
3257         (iw_handler) NULL,      /*  5 */
3258         (iw_handler) NULL,      /*  6 */
3259 #endif /* WPS */
3260
3261         (iw_handler) ks_wlan_get_eeprom_cksum,  /*  7 KS_WLAN_GET_CONNECT */
3262         (iw_handler) ks_wlan_set_preamble,      /*  8 KS_WLAN_SET_PREAMBLE */
3263         (iw_handler) ks_wlan_get_preamble,      /*  9 KS_WLAN_GET_PREAMBLE */
3264         (iw_handler) ks_wlan_set_powermgt,      /* 10 KS_WLAN_SET_POWER_SAVE */
3265         (iw_handler) ks_wlan_get_powermgt,      /* 11 KS_WLAN_GET_POWER_SAVE */
3266         (iw_handler) ks_wlan_set_scan_type,     /* 12 KS_WLAN_SET_SCAN_TYPE */
3267         (iw_handler) ks_wlan_get_scan_type,     /* 13 KS_WLAN_GET_SCAN_TYPE */
3268         (iw_handler) ks_wlan_set_rx_gain,       /* 14 KS_WLAN_SET_RX_GAIN */
3269         (iw_handler) ks_wlan_get_rx_gain,       /* 15 KS_WLAN_GET_RX_GAIN */
3270         (iw_handler) ks_wlan_hostt,     /* 16 KS_WLAN_HOSTT */
3271         (iw_handler) NULL,      /* 17 */
3272         (iw_handler) ks_wlan_set_beacon_lost,   /* 18 KS_WLAN_SET_BECAN_LOST */
3273         (iw_handler) ks_wlan_get_beacon_lost,   /* 19 KS_WLAN_GET_BECAN_LOST */
3274         (iw_handler) ks_wlan_set_tx_gain,       /* 20 KS_WLAN_SET_TX_GAIN */
3275         (iw_handler) ks_wlan_get_tx_gain,       /* 21 KS_WLAN_GET_TX_GAIN */
3276         (iw_handler) ks_wlan_set_phy_type,      /* 22 KS_WLAN_SET_PHY_TYPE */
3277         (iw_handler) ks_wlan_get_phy_type,      /* 23 KS_WLAN_GET_PHY_TYPE */
3278         (iw_handler) ks_wlan_set_cts_mode,      /* 24 KS_WLAN_SET_CTS_MODE */
3279         (iw_handler) ks_wlan_get_cts_mode,      /* 25 KS_WLAN_GET_CTS_MODE */
3280         (iw_handler) NULL,      /* 26 */
3281         (iw_handler) NULL,      /* 27 */
3282         (iw_handler) ks_wlan_set_sleep_mode,    /* 28 KS_WLAN_SET_SLEEP_MODE */
3283         (iw_handler) ks_wlan_get_sleep_mode,    /* 29 KS_WLAN_GET_SLEEP_MODE */
3284         (iw_handler) NULL,      /* 30 */
3285         (iw_handler) NULL,      /* 31 */
3286 };
3287
3288 static const struct iw_handler_def ks_wlan_handler_def = {
3289         .num_standard = sizeof(ks_wlan_handler) / sizeof(iw_handler),
3290         .num_private = sizeof(ks_wlan_private_handler) / sizeof(iw_handler),
3291         .num_private_args =
3292             sizeof(ks_wlan_private_args) / sizeof(struct iw_priv_args),
3293         .standard = (iw_handler *) ks_wlan_handler,
3294         .private = (iw_handler *) ks_wlan_private_handler,
3295         .private_args = (struct iw_priv_args *)ks_wlan_private_args,
3296         .get_wireless_stats = ks_get_wireless_stats,
3297 };
3298
3299 static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq,
3300                                 int cmd)
3301 {
3302         int rc = 0;
3303         struct iwreq *wrq = (struct iwreq *)rq;
3304         switch (cmd) {
3305         case SIOCIWFIRSTPRIV + 20:      /* KS_WLAN_SET_STOP_REQ */
3306                 rc = ks_wlan_set_stop_request(dev, NULL, &(wrq->u.mode), NULL);
3307                 break;
3308                 // All other calls are currently unsupported
3309         default:
3310                 rc = -EOPNOTSUPP;
3311         }
3312
3313         DPRINTK(5, "return=%d\n", rc);
3314         return rc;
3315 }
3316
3317 static
3318 struct net_device_stats *ks_wlan_get_stats(struct net_device *dev)
3319 {
3320         struct ks_wlan_private *priv = netdev_priv(dev);
3321
3322         if (priv->dev_state < DEVICE_STATE_READY) {
3323                 return NULL;    /* not finished initialize */
3324         }
3325
3326         return &priv->nstats;
3327 }
3328
3329 static
3330 int ks_wlan_set_mac_address(struct net_device *dev, void *addr)
3331 {
3332         struct ks_wlan_private *priv = netdev_priv(dev);
3333         struct sockaddr *mac_addr = (struct sockaddr *)addr;
3334         if (netif_running(dev))
3335                 return -EBUSY;
3336         memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
3337         memcpy(priv->eth_addr, mac_addr->sa_data, ETH_ALEN);
3338
3339         priv->mac_address_valid = 0;
3340         hostif_sme_enqueue(priv, SME_MACADDRESS_SET_REQUEST);
3341         printk(KERN_INFO
3342                "ks_wlan: MAC ADDRESS = %02x:%02x:%02x:%02x:%02x:%02x\n",
3343                priv->eth_addr[0], priv->eth_addr[1], priv->eth_addr[2],
3344                priv->eth_addr[3], priv->eth_addr[4], priv->eth_addr[5]);
3345         return 0;
3346 }
3347
3348 static
3349 void ks_wlan_tx_timeout(struct net_device *dev)
3350 {
3351         struct ks_wlan_private *priv = netdev_priv(dev);
3352
3353         DPRINTK(1, "head(%d) tail(%d)!!\n", priv->tx_dev.qhead,
3354                 priv->tx_dev.qtail);
3355         if (!netif_queue_stopped(dev)) {
3356                 netif_stop_queue(dev);
3357         }
3358         priv->nstats.tx_errors++;
3359         netif_wake_queue(dev);
3360
3361         return;
3362 }
3363
3364 static
3365 int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev)
3366 {
3367         struct ks_wlan_private *priv = netdev_priv(dev);
3368         int rc = 0;
3369
3370         DPRINTK(3, "in_interrupt()=%ld\n", in_interrupt());
3371
3372         if (skb == NULL) {
3373                 printk(KERN_ERR "ks_wlan:  skb == NULL!!!\n");
3374                 return 0;
3375         }
3376         if (priv->dev_state < DEVICE_STATE_READY) {
3377                 dev_kfree_skb(skb);
3378                 return 0;       /* not finished initialize */
3379         }
3380
3381         if (netif_running(dev))
3382                 netif_stop_queue(dev);
3383
3384         rc = hostif_data_request(priv, skb);
3385         netif_trans_update(dev);
3386
3387         DPRINTK(4, "rc=%d\n", rc);
3388         if (rc) {
3389                 rc = 0;
3390         }
3391
3392         return rc;
3393 }
3394
3395 void send_packet_complete(void *arg1, void *arg2)
3396 {
3397         struct ks_wlan_private *priv = (struct ks_wlan_private *)arg1;
3398         struct sk_buff *packet = (struct sk_buff *)arg2;
3399
3400         DPRINTK(3, "\n");
3401
3402         priv->nstats.tx_bytes += packet->len;
3403         priv->nstats.tx_packets++;
3404
3405         if (netif_queue_stopped(priv->net_dev))
3406                 netif_wake_queue(priv->net_dev);
3407
3408         if (packet) {
3409                 dev_kfree_skb(packet);
3410                 packet = NULL;
3411         }
3412
3413 }
3414
3415 /* Set or clear the multicast filter for this adaptor.
3416    This routine is not state sensitive and need not be SMP locked. */
3417 static
3418 void ks_wlan_set_multicast_list(struct net_device *dev)
3419 {
3420         struct ks_wlan_private *priv = netdev_priv(dev);
3421
3422         DPRINTK(4, "\n");
3423         if (priv->dev_state < DEVICE_STATE_READY) {
3424                 return; /* not finished initialize */
3425         }
3426         hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST);
3427
3428         return;
3429 }
3430
3431 static
3432 int ks_wlan_open(struct net_device *dev)
3433 {
3434         struct ks_wlan_private *priv = netdev_priv(dev);
3435
3436         priv->cur_rx = 0;
3437
3438         if (!priv->mac_address_valid) {
3439                 printk(KERN_ERR "ks_wlan : %s Not READY !!\n", dev->name);
3440                 return -EBUSY;
3441         } else
3442                 netif_start_queue(dev);
3443
3444         return 0;
3445 }
3446
3447 static
3448 int ks_wlan_close(struct net_device *dev)
3449 {
3450
3451         netif_stop_queue(dev);
3452
3453         DPRINTK(4, "%s: Shutting down ethercard, status was 0x%4.4x.\n",
3454                 dev->name, 0x00);
3455
3456         return 0;
3457 }
3458
3459 /* Operational parameters that usually are not changed. */
3460 /* Time in jiffies before concluding the transmitter is hung. */
3461 #define TX_TIMEOUT  (3*HZ)
3462 static const unsigned char dummy_addr[] =
3463     { 0x00, 0x0b, 0xe3, 0x00, 0x00, 0x00 };
3464
3465 static const struct net_device_ops ks_wlan_netdev_ops = {
3466         .ndo_start_xmit = ks_wlan_start_xmit,
3467         .ndo_open = ks_wlan_open,
3468         .ndo_stop = ks_wlan_close,
3469         .ndo_do_ioctl = ks_wlan_netdev_ioctl,
3470         .ndo_set_mac_address = ks_wlan_set_mac_address,
3471         .ndo_get_stats = ks_wlan_get_stats,
3472         .ndo_tx_timeout = ks_wlan_tx_timeout,
3473         .ndo_set_rx_mode = ks_wlan_set_multicast_list,
3474 };
3475
3476 int ks_wlan_net_start(struct net_device *dev)
3477 {
3478         struct ks_wlan_private *priv;
3479         /* int rc; */
3480
3481         priv = netdev_priv(dev);
3482         priv->mac_address_valid = 0;
3483         priv->need_commit = 0;
3484
3485         priv->device_open_status = 1;
3486
3487         /* phy information update timer */
3488         atomic_set(&update_phyinfo, 0);
3489         init_timer(&update_phyinfo_timer);
3490         update_phyinfo_timer.function = ks_wlan_update_phyinfo_timeout;
3491         update_phyinfo_timer.data = (unsigned long)priv;
3492
3493         /* dummy address set */
3494         memcpy(priv->eth_addr, dummy_addr, ETH_ALEN);
3495         dev->dev_addr[0] = priv->eth_addr[0];
3496         dev->dev_addr[1] = priv->eth_addr[1];
3497         dev->dev_addr[2] = priv->eth_addr[2];
3498         dev->dev_addr[3] = priv->eth_addr[3];
3499         dev->dev_addr[4] = priv->eth_addr[4];
3500         dev->dev_addr[5] = priv->eth_addr[5];
3501         dev->dev_addr[6] = 0x00;
3502         dev->dev_addr[7] = 0x00;
3503
3504         /* The ks_wlan-specific entries in the device structure. */
3505         dev->netdev_ops = &ks_wlan_netdev_ops;
3506         dev->wireless_handlers = (struct iw_handler_def *)&ks_wlan_handler_def;
3507         dev->watchdog_timeo = TX_TIMEOUT;
3508
3509         netif_carrier_off(dev);
3510
3511         return 0;
3512 }
3513
3514 int ks_wlan_net_stop(struct net_device *dev)
3515 {
3516         struct ks_wlan_private *priv = netdev_priv(dev);
3517
3518         int ret = 0;
3519         priv->device_open_status = 0;
3520         del_timer_sync(&update_phyinfo_timer);
3521
3522         if (netif_running(dev))
3523                 netif_stop_queue(dev);
3524
3525         return ret;
3526 }
3527
3528 int ks_wlan_reset(struct net_device *dev)
3529 {
3530         return 0;
3531 }