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