Linux-libre 4.9.46-gnu
[librecmc/linux-libre.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         DPRINTK(2, "\n");
1408
1409         if (priv->sleep_mode == SLP_SLEEP) {
1410                 return -EPERM;
1411         }
1412
1413         /* for SLEEP MODE */
1414         /* specified SSID SCAN */
1415         if (wrqu->data.length == sizeof(struct iw_scan_req)
1416             && wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1417                 req = (struct iw_scan_req *)extra;
1418                 priv->scan_ssid_len = req->essid_len;
1419                 memcpy(priv->scan_ssid, req->essid, priv->scan_ssid_len);
1420         } else {
1421                 priv->scan_ssid_len = 0;
1422         }
1423
1424         priv->sme_i.sme_flag |= SME_AP_SCAN;
1425         hostif_sme_enqueue(priv, SME_BSS_SCAN_REQUEST);
1426
1427         /* At this point, just return to the user. */
1428
1429         return 0;
1430 }
1431
1432 /*------------------------------------------------------------------*/
1433 /*
1434  * Translate scan data returned from the card to a card independent
1435  * format that the Wireless Tools will understand - Jean II
1436  */
1437 static inline char *ks_wlan_translate_scan(struct net_device *dev,
1438                                            struct iw_request_info *info,
1439                                            char *current_ev, char *end_buf,
1440                                            struct local_ap_t *ap)
1441 {
1442         /* struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; */
1443         struct iw_event iwe;    /* Temporary buffer */
1444         u16 capabilities;
1445         char *current_val;      /* For rates */
1446         int i;
1447         static const char rsn_leader[] = "rsn_ie=";
1448         static const char wpa_leader[] = "wpa_ie=";
1449         char buf0[RSN_IE_BODY_MAX * 2 + 30];
1450         char buf1[RSN_IE_BODY_MAX * 2 + 30];
1451         char *pbuf;
1452         /* First entry *MUST* be the AP MAC address */
1453         iwe.cmd = SIOCGIWAP;
1454         iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1455         memcpy(iwe.u.ap_addr.sa_data, ap->bssid, ETH_ALEN);
1456         current_ev =
1457             iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1458                                  IW_EV_ADDR_LEN);
1459
1460         /* Other entries will be displayed in the order we give them */
1461
1462         /* Add the ESSID */
1463         iwe.u.data.length = ap->ssid.size;
1464         if (iwe.u.data.length > 32)
1465                 iwe.u.data.length = 32;
1466         iwe.cmd = SIOCGIWESSID;
1467         iwe.u.data.flags = 1;
1468         current_ev =
1469             iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1470                                  &(ap->ssid.body[0]));
1471
1472         /* Add mode */
1473         iwe.cmd = SIOCGIWMODE;
1474         capabilities = le16_to_cpu(ap->capability);
1475         if (capabilities & (BSS_CAP_ESS | BSS_CAP_IBSS)) {
1476                 if (capabilities & BSS_CAP_ESS)
1477                         iwe.u.mode = IW_MODE_INFRA;
1478                 else
1479                         iwe.u.mode = IW_MODE_ADHOC;
1480                 current_ev =
1481                     iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1482                                          IW_EV_UINT_LEN);
1483         }
1484
1485         /* Add frequency */
1486         iwe.cmd = SIOCGIWFREQ;
1487         iwe.u.freq.m = ap->channel;
1488         iwe.u.freq.m = frequency_list[iwe.u.freq.m - 1] * 100000;
1489         iwe.u.freq.e = 1;
1490         current_ev =
1491             iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1492                                  IW_EV_FREQ_LEN);
1493
1494         /* Add quality statistics */
1495         iwe.cmd = IWEVQUAL;
1496         iwe.u.qual.level = 256 - ap->rssi;
1497         iwe.u.qual.qual = ap->sq;
1498         iwe.u.qual.noise = 0;   /* invalid noise value */
1499         current_ev =
1500             iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1501                                  IW_EV_QUAL_LEN);
1502
1503         /* Add encryption capability */
1504         iwe.cmd = SIOCGIWENCODE;
1505         if (capabilities & BSS_CAP_PRIVACY)
1506                 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1507         else
1508                 iwe.u.data.flags = IW_ENCODE_DISABLED;
1509         iwe.u.data.length = 0;
1510         current_ev =
1511             iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1512                                  &(ap->ssid.body[0]));
1513
1514         /* Rate : stuffing multiple values in a single event require a bit
1515          * more of magic - Jean II */
1516         current_val = current_ev + IW_EV_LCP_LEN;
1517
1518         iwe.cmd = SIOCGIWRATE;
1519         /* Those two flags are ignored... */
1520         iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
1521
1522         /* Max 16 values */
1523         for (i = 0; i < 16; i++) {
1524                 /* NULL terminated */
1525                 if (i >= ap->rate_set.size)
1526                         break;
1527                 /* Bit rate given in 500 kb/s units (+ 0x80) */
1528                 iwe.u.bitrate.value = ((ap->rate_set.body[i] & 0x7f) * 500000);
1529                 /* Add new value to event */
1530                 current_val =
1531                     iwe_stream_add_value(info, current_ev, current_val, end_buf,
1532                                          &iwe, IW_EV_PARAM_LEN);
1533         }
1534         /* Check if we added any event */
1535         if ((current_val - current_ev) > IW_EV_LCP_LEN)
1536                 current_ev = current_val;
1537
1538 #define GENERIC_INFO_ELEM_ID 0xdd
1539 #define RSN_INFO_ELEM_ID 0x30
1540         if (ap->rsn_ie.id == RSN_INFO_ELEM_ID && ap->rsn_ie.size != 0) {
1541                 pbuf = &buf0[0];
1542                 memset(&iwe, 0, sizeof(iwe));
1543                 iwe.cmd = IWEVCUSTOM;
1544                 memcpy(buf0, rsn_leader, sizeof(rsn_leader) - 1);
1545                 iwe.u.data.length += sizeof(rsn_leader) - 1;
1546                 pbuf += sizeof(rsn_leader) - 1;
1547
1548                 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.id);
1549                 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.size);
1550                 iwe.u.data.length += 4;
1551
1552                 for (i = 0; i < ap->rsn_ie.size; i++)
1553                         pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.body[i]);
1554                 iwe.u.data.length += (ap->rsn_ie.size) * 2;
1555
1556                 DPRINTK(4, "ap->rsn.size=%d\n", ap->rsn_ie.size);
1557
1558                 current_ev =
1559                     iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1560                                          &buf0[0]);
1561         }
1562         if (ap->wpa_ie.id == GENERIC_INFO_ELEM_ID && ap->wpa_ie.size != 0) {
1563                 pbuf = &buf1[0];
1564                 memset(&iwe, 0, sizeof(iwe));
1565                 iwe.cmd = IWEVCUSTOM;
1566                 memcpy(buf1, wpa_leader, sizeof(wpa_leader) - 1);
1567                 iwe.u.data.length += sizeof(wpa_leader) - 1;
1568                 pbuf += sizeof(wpa_leader) - 1;
1569
1570                 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.id);
1571                 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.size);
1572                 iwe.u.data.length += 4;
1573
1574                 for (i = 0; i < ap->wpa_ie.size; i++)
1575                         pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.body[i]);
1576                 iwe.u.data.length += (ap->wpa_ie.size) * 2;
1577
1578                 DPRINTK(4, "ap->rsn.size=%d\n", ap->wpa_ie.size);
1579                 DPRINTK(4, "iwe.u.data.length=%d\n", iwe.u.data.length);
1580
1581                 current_ev =
1582                     iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1583                                          &buf1[0]);
1584         }
1585
1586         /* The other data in the scan result are not really
1587          * interesting, so for now drop it - Jean II */
1588         return current_ev;
1589 }
1590
1591 /*------------------------------------------------------------------*/
1592 /* Wireless Handler : Read Scan Results */
1593 static int ks_wlan_get_scan(struct net_device *dev,
1594                             struct iw_request_info *info, struct iw_point *dwrq,
1595                             char *extra)
1596 {
1597         struct ks_wlan_private *priv =
1598             (struct ks_wlan_private *)netdev_priv(dev);
1599         int i;
1600         char *current_ev = extra;
1601         DPRINTK(2, "\n");
1602
1603         if (priv->sleep_mode == SLP_SLEEP) {
1604                 return -EPERM;
1605         }
1606         /* for SLEEP MODE */
1607         if (priv->sme_i.sme_flag & SME_AP_SCAN) {
1608                 DPRINTK(2, "flag AP_SCAN\n");
1609                 return -EAGAIN;
1610         }
1611
1612         if (priv->aplist.size == 0) {
1613                 /* Client error, no scan results...
1614                  * The caller need to restart the scan. */
1615                 DPRINTK(2, "aplist 0\n");
1616                 return -ENODATA;
1617         }
1618 #if 0
1619         /* current connect ap */
1620         if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
1621                 if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) {
1622                         dwrq->length = 0;
1623                         return -E2BIG;
1624                 }
1625                 current_ev = ks_wlan_translate_scan(dev, current_ev,
1626 //                                                  extra + IW_SCAN_MAX_DATA,
1627                                                     extra + dwrq->length,
1628                                                     &(priv->current_ap));
1629         }
1630 #endif
1631         /* Read and parse all entries */
1632         for (i = 0; i < priv->aplist.size; i++) {
1633                 if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) {
1634                         dwrq->length = 0;
1635                         return -E2BIG;
1636                 }
1637                 /* Translate to WE format this entry */
1638                 current_ev = ks_wlan_translate_scan(dev, info, current_ev,
1639 //                                                  extra + IW_SCAN_MAX_DATA,
1640                                                     extra + dwrq->length,
1641                                                     &(priv->aplist.ap[i]));
1642         }
1643         /* Length of data */
1644         dwrq->length = (current_ev - extra);
1645         dwrq->flags = 0;
1646
1647         return 0;
1648 }
1649
1650 /*------------------------------------------------------------------*/
1651 /* Commit handler : called after a bunch of SET operations */
1652 static int ks_wlan_config_commit(struct net_device *dev,
1653                                  struct iw_request_info *info, void *zwrq,
1654                                  char *extra)
1655 {
1656         struct ks_wlan_private *priv =
1657             (struct ks_wlan_private *)netdev_priv(dev);
1658
1659         if (!priv->need_commit)
1660                 return 0;
1661
1662         ks_wlan_setup_parameter(priv, priv->need_commit);
1663         priv->need_commit = 0;
1664         return 0;
1665 }
1666
1667 /*------------------------------------------------------------------*/
1668 /* Wireless handler : set association ie params */
1669 static int ks_wlan_set_genie(struct net_device *dev,
1670                              struct iw_request_info *info,
1671                              struct iw_point *dwrq, char *extra)
1672 {
1673         struct ks_wlan_private *priv =
1674             (struct ks_wlan_private *)netdev_priv(dev);
1675
1676         DPRINTK(2, "\n");
1677
1678         if (priv->sleep_mode == SLP_SLEEP) {
1679                 return -EPERM;
1680         }
1681         /* for SLEEP MODE */
1682         return 0;
1683 //      return -EOPNOTSUPP;
1684 }
1685
1686 /*------------------------------------------------------------------*/
1687 /* Wireless handler : set authentication mode params */
1688 static int ks_wlan_set_auth_mode(struct net_device *dev,
1689                                  struct iw_request_info *info,
1690                                  struct iw_param *vwrq, char *extra)
1691 {
1692         struct ks_wlan_private *priv =
1693             (struct ks_wlan_private *)netdev_priv(dev);
1694         int index = (vwrq->flags & IW_AUTH_INDEX);
1695         int value = vwrq->value;
1696
1697         DPRINTK(2, "index=%d:value=%08X\n", index, value);
1698
1699         if (priv->sleep_mode == SLP_SLEEP) {
1700                 return -EPERM;
1701         }
1702         /* for SLEEP MODE */
1703         switch (index) {
1704         case IW_AUTH_WPA_VERSION:       /* 0 */
1705                 switch (value) {
1706                 case IW_AUTH_WPA_VERSION_DISABLED:
1707                         priv->wpa.version = value;
1708                         if (priv->wpa.rsn_enabled) {
1709                                 priv->wpa.rsn_enabled = 0;
1710                         }
1711                         priv->need_commit |= SME_RSN;
1712                         break;
1713                 case IW_AUTH_WPA_VERSION_WPA:
1714                 case IW_AUTH_WPA_VERSION_WPA2:
1715                         priv->wpa.version = value;
1716                         if (!(priv->wpa.rsn_enabled)) {
1717                                 priv->wpa.rsn_enabled = 1;
1718                         }
1719                         priv->need_commit |= SME_RSN;
1720                         break;
1721                 default:
1722                         return -EOPNOTSUPP;
1723                 }
1724                 break;
1725         case IW_AUTH_CIPHER_PAIRWISE:   /* 1 */
1726                 switch (value) {
1727                 case IW_AUTH_CIPHER_NONE:
1728                         if (priv->reg.privacy_invoked) {
1729                                 priv->reg.privacy_invoked = 0x00;
1730                                 priv->need_commit |= SME_WEP_FLAG;
1731                         }
1732                         break;
1733                 case IW_AUTH_CIPHER_WEP40:
1734                 case IW_AUTH_CIPHER_TKIP:
1735                 case IW_AUTH_CIPHER_CCMP:
1736                 case IW_AUTH_CIPHER_WEP104:
1737                         if (!priv->reg.privacy_invoked) {
1738                                 priv->reg.privacy_invoked = 0x01;
1739                                 priv->need_commit |= SME_WEP_FLAG;
1740                         }
1741                         priv->wpa.pairwise_suite = value;
1742                         priv->need_commit |= SME_RSN_UNICAST;
1743                         break;
1744                 default:
1745                         return -EOPNOTSUPP;
1746                 }
1747                 break;
1748         case IW_AUTH_CIPHER_GROUP:      /* 2 */
1749                 switch (value) {
1750                 case IW_AUTH_CIPHER_NONE:
1751                         if (priv->reg.privacy_invoked) {
1752                                 priv->reg.privacy_invoked = 0x00;
1753                                 priv->need_commit |= SME_WEP_FLAG;
1754                         }
1755                         break;
1756                 case IW_AUTH_CIPHER_WEP40:
1757                 case IW_AUTH_CIPHER_TKIP:
1758                 case IW_AUTH_CIPHER_CCMP:
1759                 case IW_AUTH_CIPHER_WEP104:
1760                         if (!priv->reg.privacy_invoked) {
1761                                 priv->reg.privacy_invoked = 0x01;
1762                                 priv->need_commit |= SME_WEP_FLAG;
1763                         }
1764                         priv->wpa.group_suite = value;
1765                         priv->need_commit |= SME_RSN_MULTICAST;
1766                         break;
1767                 default:
1768                         return -EOPNOTSUPP;
1769                 }
1770                 break;
1771         case IW_AUTH_KEY_MGMT:  /* 3 */
1772                 switch (value) {
1773                 case IW_AUTH_KEY_MGMT_802_1X:
1774                 case IW_AUTH_KEY_MGMT_PSK:
1775                 case 0: /* NONE or 802_1X_NO_WPA */
1776                 case 4: /* WPA_NONE */
1777                         priv->wpa.key_mgmt_suite = value;
1778                         priv->need_commit |= SME_RSN_AUTH;
1779                         break;
1780                 default:
1781                         return -EOPNOTSUPP;
1782                 }
1783                 break;
1784         case IW_AUTH_80211_AUTH_ALG:    /* 6 */
1785                 switch (value) {
1786                 case IW_AUTH_ALG_OPEN_SYSTEM:
1787                         priv->wpa.auth_alg = value;
1788                         priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
1789                         break;
1790                 case IW_AUTH_ALG_SHARED_KEY:
1791                         priv->wpa.auth_alg = value;
1792                         priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
1793                         break;
1794                 case IW_AUTH_ALG_LEAP:
1795                 default:
1796                         return -EOPNOTSUPP;
1797                 }
1798                 priv->need_commit |= SME_MODE_SET;
1799                 break;
1800         case IW_AUTH_WPA_ENABLED:       /* 7 */
1801                 priv->wpa.wpa_enabled = value;
1802                 break;
1803         case IW_AUTH_PRIVACY_INVOKED:   /* 10 */
1804                 if ((value && !priv->reg.privacy_invoked) ||
1805                     (!value && priv->reg.privacy_invoked)) {
1806                         priv->reg.privacy_invoked = value ? 0x01 : 0x00;
1807                         priv->need_commit |= SME_WEP_FLAG;
1808                 }
1809                 break;
1810         case IW_AUTH_RX_UNENCRYPTED_EAPOL:      /* 4 */
1811         case IW_AUTH_TKIP_COUNTERMEASURES:      /* 5 */
1812         case IW_AUTH_DROP_UNENCRYPTED:  /* 8 */
1813         case IW_AUTH_ROAMING_CONTROL:   /* 9 */
1814         default:
1815                 break;
1816         }
1817
1818         /* return -EINPROGRESS; */
1819         if (priv->need_commit) {
1820                 ks_wlan_setup_parameter(priv, priv->need_commit);
1821                 priv->need_commit = 0;
1822         }
1823         return 0;
1824 }
1825
1826 /*------------------------------------------------------------------*/
1827 /* Wireless handler : get authentication mode params */
1828 static int ks_wlan_get_auth_mode(struct net_device *dev,
1829                                  struct iw_request_info *info,
1830                                  struct iw_param *vwrq, char *extra)
1831 {
1832         struct ks_wlan_private *priv =
1833             (struct ks_wlan_private *)netdev_priv(dev);
1834         int index = (vwrq->flags & IW_AUTH_INDEX);
1835         DPRINTK(2, "index=%d\n", index);
1836
1837         if (priv->sleep_mode == SLP_SLEEP) {
1838                 return -EPERM;
1839         }
1840
1841         /* for SLEEP MODE */
1842         /*  WPA (not used ?? wpa_supplicant) */
1843         switch (index) {
1844         case IW_AUTH_WPA_VERSION:
1845                 vwrq->value = priv->wpa.version;
1846                 break;
1847         case IW_AUTH_CIPHER_PAIRWISE:
1848                 vwrq->value = priv->wpa.pairwise_suite;
1849                 break;
1850         case IW_AUTH_CIPHER_GROUP:
1851                 vwrq->value = priv->wpa.group_suite;
1852                 break;
1853         case IW_AUTH_KEY_MGMT:
1854                 vwrq->value = priv->wpa.key_mgmt_suite;
1855                 break;
1856         case IW_AUTH_80211_AUTH_ALG:
1857                 vwrq->value = priv->wpa.auth_alg;
1858                 break;
1859         case IW_AUTH_WPA_ENABLED:
1860                 vwrq->value = priv->wpa.rsn_enabled;
1861                 break;
1862         case IW_AUTH_RX_UNENCRYPTED_EAPOL:      /* OK??? */
1863         case IW_AUTH_TKIP_COUNTERMEASURES:
1864         case IW_AUTH_DROP_UNENCRYPTED:
1865         default:
1866                 /* return -EOPNOTSUPP; */
1867                 break;
1868         }
1869         return 0;
1870 }
1871
1872 /*------------------------------------------------------------------*/
1873 /* Wireless Handler : set encoding token & mode (WPA)*/
1874 static int ks_wlan_set_encode_ext(struct net_device *dev,
1875                                   struct iw_request_info *info,
1876                                   struct iw_point *dwrq, char *extra)
1877 {
1878         struct ks_wlan_private *priv =
1879             (struct ks_wlan_private *)netdev_priv(dev);
1880         struct iw_encode_ext *enc;
1881         int index = dwrq->flags & IW_ENCODE_INDEX;
1882         unsigned int commit = 0;
1883
1884         enc = (struct iw_encode_ext *)extra;
1885
1886         DPRINTK(2, "flags=%04X:: ext_flags=%08X\n", dwrq->flags,
1887                 enc->ext_flags);
1888
1889         if (priv->sleep_mode == SLP_SLEEP) {
1890                 return -EPERM;
1891         }
1892         /* for SLEEP MODE */
1893         if (index < 1 || index > 4)
1894                 return -EINVAL;
1895         else
1896                 index--;
1897
1898         if (dwrq->flags & IW_ENCODE_DISABLED) {
1899                 priv->wpa.key[index].key_len = 0;
1900         }
1901
1902         if (enc) {
1903                 priv->wpa.key[index].ext_flags = enc->ext_flags;
1904                 if (enc->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
1905                         priv->wpa.txkey = index;
1906                         commit |= SME_WEP_INDEX;
1907                 } else if (enc->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
1908                         memcpy(&priv->wpa.key[index].rx_seq[0],
1909                                enc->rx_seq, IW_ENCODE_SEQ_MAX_SIZE);
1910                 }
1911
1912                 memcpy(&priv->wpa.key[index].addr.sa_data[0],
1913                        &enc->addr.sa_data[0], ETH_ALEN);
1914
1915                 switch (enc->alg) {
1916                 case IW_ENCODE_ALG_NONE:
1917                         if (priv->reg.privacy_invoked) {
1918                                 priv->reg.privacy_invoked = 0x00;
1919                                 commit |= SME_WEP_FLAG;
1920                         }
1921                         priv->wpa.key[index].key_len = 0;
1922
1923                         break;
1924                 case IW_ENCODE_ALG_WEP:
1925                 case IW_ENCODE_ALG_CCMP:
1926                         if (!priv->reg.privacy_invoked) {
1927                                 priv->reg.privacy_invoked = 0x01;
1928                                 commit |= SME_WEP_FLAG;
1929                         }
1930                         if (enc->key_len) {
1931                                 memcpy(&priv->wpa.key[index].key_val[0],
1932                                        &enc->key[0], enc->key_len);
1933                                 priv->wpa.key[index].key_len = enc->key_len;
1934                                 commit |= (SME_WEP_VAL1 << index);
1935                         }
1936                         break;
1937                 case IW_ENCODE_ALG_TKIP:
1938                         if (!priv->reg.privacy_invoked) {
1939                                 priv->reg.privacy_invoked = 0x01;
1940                                 commit |= SME_WEP_FLAG;
1941                         }
1942                         if (enc->key_len == 32) {
1943                                 memcpy(&priv->wpa.key[index].key_val[0],
1944                                        &enc->key[0], enc->key_len - 16);
1945                                 priv->wpa.key[index].key_len =
1946                                     enc->key_len - 16;
1947                                 if (priv->wpa.key_mgmt_suite == 4) {    /* WPA_NONE */
1948                                         memcpy(&priv->wpa.key[index].
1949                                                tx_mic_key[0], &enc->key[16], 8);
1950                                         memcpy(&priv->wpa.key[index].
1951                                                rx_mic_key[0], &enc->key[16], 8);
1952                                 } else {
1953                                         memcpy(&priv->wpa.key[index].
1954                                                tx_mic_key[0], &enc->key[16], 8);
1955                                         memcpy(&priv->wpa.key[index].
1956                                                rx_mic_key[0], &enc->key[24], 8);
1957                                 }
1958                                 commit |= (SME_WEP_VAL1 << index);
1959                         }
1960                         break;
1961                 default:
1962                         return -EINVAL;
1963                 }
1964                 priv->wpa.key[index].alg = enc->alg;
1965         } else
1966                 return -EINVAL;
1967
1968         if (commit) {
1969                 if (commit & SME_WEP_INDEX)
1970                         hostif_sme_enqueue(priv, SME_SET_TXKEY);
1971                 if (commit & SME_WEP_VAL_MASK)
1972                         hostif_sme_enqueue(priv, SME_SET_KEY1 + index);
1973                 if (commit & SME_WEP_FLAG)
1974                         hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
1975         }
1976
1977         return 0;
1978 }
1979
1980 /*------------------------------------------------------------------*/
1981 /* Wireless Handler : get encoding token & mode (WPA)*/
1982 static int ks_wlan_get_encode_ext(struct net_device *dev,
1983                                   struct iw_request_info *info,
1984                                   struct iw_point *dwrq, char *extra)
1985 {
1986         struct ks_wlan_private *priv =
1987             (struct ks_wlan_private *)netdev_priv(dev);
1988
1989         if (priv->sleep_mode == SLP_SLEEP) {
1990                 return -EPERM;
1991         }
1992
1993         /* for SLEEP MODE */
1994         /*  WPA (not used ?? wpa_supplicant)
1995            struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
1996            struct iw_encode_ext *enc;
1997            enc = (struct iw_encode_ext *)extra;
1998            int index = dwrq->flags & IW_ENCODE_INDEX;
1999            WPA (not used ?? wpa_supplicant) */
2000         return 0;
2001 }
2002
2003 /*------------------------------------------------------------------*/
2004 /* Wireless Handler : PMKSA cache operation (WPA2) */
2005 static int ks_wlan_set_pmksa(struct net_device *dev,
2006                              struct iw_request_info *info,
2007                              struct iw_point *dwrq, char *extra)
2008 {
2009         struct ks_wlan_private *priv =
2010             (struct ks_wlan_private *)netdev_priv(dev);
2011         struct iw_pmksa *pmksa;
2012         int i;
2013         struct pmk_t *pmk;
2014         struct list_head *ptr;
2015
2016         DPRINTK(2, "\n");
2017
2018         if (priv->sleep_mode == SLP_SLEEP) {
2019                 return -EPERM;
2020         }
2021         /* for SLEEP MODE */
2022         if (!extra) {
2023                 return -EINVAL;
2024         }
2025         pmksa = (struct iw_pmksa *)extra;
2026         DPRINTK(2, "cmd=%d\n", pmksa->cmd);
2027
2028         switch (pmksa->cmd) {
2029         case IW_PMKSA_ADD:
2030                 if (list_empty(&priv->pmklist.head)) {  /* new list */
2031                         for (i = 0; i < PMK_LIST_MAX; i++) {
2032                                 pmk = &priv->pmklist.pmk[i];
2033                                 if (!memcmp
2034                                     ("\x00\x00\x00\x00\x00\x00", pmk->bssid,
2035                                      ETH_ALEN))
2036                                         break;
2037                         }
2038                         memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
2039                         memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
2040                         list_add(&pmk->list, &priv->pmklist.head);
2041                         priv->pmklist.size++;
2042                 } else {        /* search cache data */
2043                         list_for_each(ptr, &priv->pmklist.head) {
2044                                 pmk = list_entry(ptr, struct pmk_t, list);
2045                                 if (!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)) {      /* match address! list move to head. */
2046                                         memcpy(pmk->pmkid, pmksa->pmkid,
2047                                                IW_PMKID_LEN);
2048                                         list_move(&pmk->list,
2049                                                   &priv->pmklist.head);
2050                                         break;
2051                                 }
2052                         }
2053                         if (ptr == &priv->pmklist.head) {       /* not find address. */
2054                                 if (PMK_LIST_MAX > priv->pmklist.size) {        /* new cache data */
2055                                         for (i = 0; i < PMK_LIST_MAX; i++) {
2056                                                 pmk = &priv->pmklist.pmk[i];
2057                                                 if (!memcmp
2058                                                     ("\x00\x00\x00\x00\x00\x00",
2059                                                      pmk->bssid, ETH_ALEN))
2060                                                         break;
2061                                         }
2062                                         memcpy(pmk->bssid, pmksa->bssid.sa_data,
2063                                                ETH_ALEN);
2064                                         memcpy(pmk->pmkid, pmksa->pmkid,
2065                                                IW_PMKID_LEN);
2066                                         list_add(&pmk->list,
2067                                                  &priv->pmklist.head);
2068                                         priv->pmklist.size++;
2069                                 } else {        /* overwrite old cache data */
2070                                         pmk =
2071                                             list_entry(priv->pmklist.head.prev,
2072                                                        struct pmk_t, list);
2073                                         memcpy(pmk->bssid, pmksa->bssid.sa_data,
2074                                                ETH_ALEN);
2075                                         memcpy(pmk->pmkid, pmksa->pmkid,
2076                                                IW_PMKID_LEN);
2077                                         list_move(&pmk->list,
2078                                                   &priv->pmklist.head);
2079                                 }
2080                         }
2081                 }
2082                 break;
2083         case IW_PMKSA_REMOVE:
2084                 if (list_empty(&priv->pmklist.head)) {  /* list empty */
2085                         return -EINVAL;
2086                 } else {        /* search cache data */
2087                         list_for_each(ptr, &priv->pmklist.head) {
2088                                 pmk = list_entry(ptr, struct pmk_t, list);
2089                                 if (!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)) {      /* match address! list del. */
2090                                         eth_zero_addr(pmk->bssid);
2091                                         memset(pmk->pmkid, 0, IW_PMKID_LEN);
2092                                         list_del_init(&pmk->list);
2093                                         break;
2094                                 }
2095                         }
2096                         if (ptr == &priv->pmklist.head) {       /* not find address. */
2097                                 return 0;
2098                         }
2099                 }
2100                 break;
2101         case IW_PMKSA_FLUSH:
2102                 memset(&(priv->pmklist), 0, sizeof(priv->pmklist));
2103                 INIT_LIST_HEAD(&priv->pmklist.head);
2104                 for (i = 0; i < PMK_LIST_MAX; i++)
2105                         INIT_LIST_HEAD(&priv->pmklist.pmk[i].list);
2106                 break;
2107         default:
2108                 return -EINVAL;
2109         }
2110
2111         hostif_sme_enqueue(priv, SME_SET_PMKSA);
2112         return 0;
2113 }
2114
2115 static struct iw_statistics *ks_get_wireless_stats(struct net_device *dev)
2116 {
2117
2118         struct ks_wlan_private *priv =
2119             (struct ks_wlan_private *)netdev_priv(dev);
2120         struct iw_statistics *wstats = &priv->wstats;
2121
2122         if (!atomic_read(&update_phyinfo)) {
2123                 if (priv->dev_state < DEVICE_STATE_READY)
2124                         return NULL;    /* not finished initialize */
2125                 else
2126                         return wstats;
2127         }
2128
2129         /* Packets discarded in the wireless adapter due to wireless
2130          * specific problems */
2131         wstats->discard.nwid = 0;       /* Rx invalid nwid      */
2132         wstats->discard.code = 0;       /* Rx invalid crypt     */
2133         wstats->discard.fragment = 0;   /* Rx invalid frag      */
2134         wstats->discard.retries = 0;    /* Tx excessive retries */
2135         wstats->discard.misc = 0;       /* Invalid misc         */
2136         wstats->miss.beacon = 0;        /* Missed beacon        */
2137
2138         return wstats;
2139 }
2140
2141 /*------------------------------------------------------------------*/
2142 /* Private handler : set stop request */
2143 static int ks_wlan_set_stop_request(struct net_device *dev,
2144                                     struct iw_request_info *info, __u32 * uwrq,
2145                                     char *extra)
2146 {
2147         struct ks_wlan_private *priv =
2148             (struct ks_wlan_private *)netdev_priv(dev);
2149         DPRINTK(2, "\n");
2150
2151         if (priv->sleep_mode == SLP_SLEEP) {
2152                 return -EPERM;
2153         }
2154         /* for SLEEP MODE */
2155         if (!(*uwrq))
2156                 return -EINVAL;
2157
2158         hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2159         return 0;
2160 }
2161
2162 /*------------------------------------------------------------------*/
2163 /* Wireless Handler : set MLME */
2164 #include <linux/ieee80211.h>
2165 static int ks_wlan_set_mlme(struct net_device *dev,
2166                             struct iw_request_info *info, struct iw_point *dwrq,
2167                             char *extra)
2168 {
2169         struct ks_wlan_private *priv =
2170             (struct ks_wlan_private *)netdev_priv(dev);
2171         struct iw_mlme *mlme = (struct iw_mlme *)extra;
2172         __u32 mode;
2173
2174         DPRINTK(2, ":%d :%d\n", mlme->cmd, mlme->reason_code);
2175
2176         if (priv->sleep_mode == SLP_SLEEP) {
2177                 return -EPERM;
2178         }
2179         /* for SLEEP MODE */
2180         switch (mlme->cmd) {
2181         case IW_MLME_DEAUTH:
2182                 if (mlme->reason_code == WLAN_REASON_MIC_FAILURE) {
2183                         return 0;
2184                 }
2185         case IW_MLME_DISASSOC:
2186                 mode = 1;
2187                 return ks_wlan_set_stop_request(dev, NULL, &mode, NULL);
2188         default:
2189                 return -EOPNOTSUPP;     /* Not Support */
2190         }
2191 }
2192
2193 /*------------------------------------------------------------------*/
2194 /* Private handler : get firemware version */
2195 static int ks_wlan_get_firmware_version(struct net_device *dev,
2196                                         struct iw_request_info *info,
2197                                         struct iw_point *dwrq, char *extra)
2198 {
2199         struct ks_wlan_private *priv =
2200             (struct ks_wlan_private *)netdev_priv(dev);
2201         strcpy(extra, &(priv->firmware_version[0]));
2202         dwrq->length = priv->version_size + 1;
2203         return 0;
2204 }
2205
2206 #if 0
2207 /*------------------------------------------------------------------*/
2208 /* Private handler : set force disconnect status */
2209 static int ks_wlan_set_detach(struct net_device *dev,
2210                               struct iw_request_info *info, __u32 * uwrq,
2211                               char *extra)
2212 {
2213         struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2214
2215         if (priv->sleep_mode == SLP_SLEEP) {
2216                 return -EPERM;
2217         }
2218         /* for SLEEP MODE */
2219         if (*uwrq == CONNECT_STATUS) {  /* 0 */
2220                 priv->connect_status &= ~FORCE_DISCONNECT;
2221                 if ((priv->connect_status & CONNECT_STATUS_MASK) ==
2222                     CONNECT_STATUS)
2223                         netif_carrier_on(dev);
2224         } else if (*uwrq == DISCONNECT_STATUS) {        /* 1 */
2225                 priv->connect_status |= FORCE_DISCONNECT;
2226                 netif_carrier_off(dev);
2227         } else
2228                 return -EINVAL;
2229         return 0;
2230 }
2231
2232 /*------------------------------------------------------------------*/
2233 /* Private handler : get force disconnect status */
2234 static int ks_wlan_get_detach(struct net_device *dev,
2235                               struct iw_request_info *info, __u32 * uwrq,
2236                               char *extra)
2237 {
2238         struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2239
2240         if (priv->sleep_mode == SLP_SLEEP) {
2241                 return -EPERM;
2242         }
2243         /* for SLEEP MODE */
2244         *uwrq = ((priv->connect_status & FORCE_DISCONNECT) ? 1 : 0);
2245         return 0;
2246 }
2247
2248 /*------------------------------------------------------------------*/
2249 /* Private handler : get connect status */
2250 static int ks_wlan_get_connect(struct net_device *dev,
2251                                struct iw_request_info *info, __u32 * uwrq,
2252                                char *extra)
2253 {
2254         struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2255
2256         if (priv->sleep_mode == SLP_SLEEP) {
2257                 return -EPERM;
2258         }
2259         /* for SLEEP MODE */
2260         *uwrq = (priv->connect_status & CONNECT_STATUS_MASK);
2261         return 0;
2262 }
2263 #endif
2264
2265 /*------------------------------------------------------------------*/
2266 /* Private handler : set preamble */
2267 static int ks_wlan_set_preamble(struct net_device *dev,
2268                                 struct iw_request_info *info, __u32 * uwrq,
2269                                 char *extra)
2270 {
2271         struct ks_wlan_private *priv =
2272             (struct ks_wlan_private *)netdev_priv(dev);
2273
2274         if (priv->sleep_mode == SLP_SLEEP) {
2275                 return -EPERM;
2276         }
2277         /* for SLEEP MODE */
2278         if (*uwrq == LONG_PREAMBLE) {   /* 0 */
2279                 priv->reg.preamble = LONG_PREAMBLE;
2280         } else if (*uwrq == SHORT_PREAMBLE) {   /* 1 */
2281                 priv->reg.preamble = SHORT_PREAMBLE;
2282         } else
2283                 return -EINVAL;
2284
2285         priv->need_commit |= SME_MODE_SET;
2286         return -EINPROGRESS;    /* Call commit handler */
2287
2288 }
2289
2290 /*------------------------------------------------------------------*/
2291 /* Private handler : get preamble */
2292 static int ks_wlan_get_preamble(struct net_device *dev,
2293                                 struct iw_request_info *info, __u32 * uwrq,
2294                                 char *extra)
2295 {
2296         struct ks_wlan_private *priv =
2297             (struct ks_wlan_private *)netdev_priv(dev);
2298
2299         if (priv->sleep_mode == SLP_SLEEP) {
2300                 return -EPERM;
2301         }
2302         /* for SLEEP MODE */
2303         *uwrq = priv->reg.preamble;
2304         return 0;
2305 }
2306
2307 /*------------------------------------------------------------------*/
2308 /* Private handler : set power save mode */
2309 static int ks_wlan_set_powermgt(struct net_device *dev,
2310                                 struct iw_request_info *info, __u32 * uwrq,
2311                                 char *extra)
2312 {
2313         struct ks_wlan_private *priv =
2314             (struct ks_wlan_private *)netdev_priv(dev);
2315
2316         if (priv->sleep_mode == SLP_SLEEP) {
2317                 return -EPERM;
2318         }
2319         /* for SLEEP MODE */
2320         if (*uwrq == POWMGT_ACTIVE_MODE) {      /* 0 */
2321                 priv->reg.powermgt = POWMGT_ACTIVE_MODE;
2322         } else if (*uwrq == POWMGT_SAVE1_MODE) {        /* 1 */
2323                 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2324                         priv->reg.powermgt = POWMGT_SAVE1_MODE;
2325                 else
2326                         return -EINVAL;
2327         } else if (*uwrq == POWMGT_SAVE2_MODE) {        /* 2 */
2328                 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2329                         priv->reg.powermgt = POWMGT_SAVE2_MODE;
2330                 else
2331                         return -EINVAL;
2332         } else
2333                 return -EINVAL;
2334
2335         hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
2336
2337         return 0;
2338 }
2339
2340 /*------------------------------------------------------------------*/
2341 /* Private handler : get power save made */
2342 static int ks_wlan_get_powermgt(struct net_device *dev,
2343                                 struct iw_request_info *info, __u32 * uwrq,
2344                                 char *extra)
2345 {
2346         struct ks_wlan_private *priv =
2347             (struct ks_wlan_private *)netdev_priv(dev);
2348
2349         if (priv->sleep_mode == SLP_SLEEP) {
2350                 return -EPERM;
2351         }
2352         /* for SLEEP MODE */
2353         *uwrq = priv->reg.powermgt;
2354         return 0;
2355 }
2356
2357 /*------------------------------------------------------------------*/
2358 /* Private handler : set scan type */
2359 static int ks_wlan_set_scan_type(struct net_device *dev,
2360                                  struct iw_request_info *info, __u32 * uwrq,
2361                                  char *extra)
2362 {
2363         struct ks_wlan_private *priv =
2364             (struct ks_wlan_private *)netdev_priv(dev);
2365
2366         if (priv->sleep_mode == SLP_SLEEP) {
2367                 return -EPERM;
2368         }
2369         /* for SLEEP MODE */
2370         if (*uwrq == ACTIVE_SCAN) {     /* 0 */
2371                 priv->reg.scan_type = ACTIVE_SCAN;
2372         } else if (*uwrq == PASSIVE_SCAN) {     /* 1 */
2373                 priv->reg.scan_type = PASSIVE_SCAN;
2374         } else
2375                 return -EINVAL;
2376
2377         return 0;
2378 }
2379
2380 /*------------------------------------------------------------------*/
2381 /* Private handler : get scan type */
2382 static int ks_wlan_get_scan_type(struct net_device *dev,
2383                                  struct iw_request_info *info, __u32 * uwrq,
2384                                  char *extra)
2385 {
2386         struct ks_wlan_private *priv =
2387             (struct ks_wlan_private *)netdev_priv(dev);
2388
2389         if (priv->sleep_mode == SLP_SLEEP) {
2390                 return -EPERM;
2391         }
2392         /* for SLEEP MODE */
2393         *uwrq = priv->reg.scan_type;
2394         return 0;
2395 }
2396
2397 #if 0
2398 /*------------------------------------------------------------------*/
2399 /* Private handler : write raw data to device */
2400 static int ks_wlan_data_write(struct net_device *dev,
2401                               struct iw_request_info *info,
2402                               struct iw_point *dwrq, char *extra)
2403 {
2404         struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2405         unsigned char *wbuff = NULL;
2406
2407         if (priv->sleep_mode == SLP_SLEEP) {
2408                 return -EPERM;
2409         }
2410         /* for SLEEP MODE */
2411         wbuff = (unsigned char *)kmalloc(dwrq->length, GFP_ATOMIC);
2412         if (!wbuff)
2413                 return -EFAULT;
2414         memcpy(wbuff, extra, dwrq->length);
2415
2416         /* write to device */
2417         ks_wlan_hw_tx(priv, wbuff, dwrq->length, NULL, NULL, NULL);
2418
2419         return 0;
2420 }
2421
2422 /*------------------------------------------------------------------*/
2423 /* Private handler : read raw data form device */
2424 static int ks_wlan_data_read(struct net_device *dev,
2425                              struct iw_request_info *info,
2426                              struct iw_point *dwrq, char *extra)
2427 {
2428         struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2429         unsigned short read_length;
2430
2431         if (priv->sleep_mode == SLP_SLEEP) {
2432                 return -EPERM;
2433         }
2434         /* for SLEEP MODE */
2435         if (!atomic_read(&priv->event_count)) {
2436                 if (priv->dev_state < DEVICE_STATE_BOOT) {      /* Remove device */
2437                         read_length = 4;
2438                         memset(extra, 0xff, read_length);
2439                         dwrq->length = read_length;
2440                         return 0;
2441                 }
2442                 read_length = 0;
2443                 memset(extra, 0, 1);
2444                 dwrq->length = 0;
2445                 return 0;
2446         }
2447
2448         if (atomic_read(&priv->event_count) > 0)
2449                 atomic_dec(&priv->event_count);
2450
2451         spin_lock(&priv->dev_read_lock);        /* request spin lock */
2452
2453         /* Copy length max size 0x07ff */
2454         if (priv->dev_size[priv->dev_count] > 2047)
2455                 read_length = 2047;
2456         else
2457                 read_length = priv->dev_size[priv->dev_count];
2458
2459         /* Copy data */
2460         memcpy(extra, &(priv->dev_data[priv->dev_count][0]), read_length);
2461
2462         spin_unlock(&priv->dev_read_lock);      /* release spin lock */
2463
2464         /* Initialize */
2465         priv->dev_data[priv->dev_count] = 0;
2466         priv->dev_size[priv->dev_count] = 0;
2467
2468         priv->dev_count++;
2469         if (priv->dev_count == DEVICE_STOCK_COUNT)
2470                 priv->dev_count = 0;
2471
2472         /* Set read size */
2473         dwrq->length = read_length;
2474
2475         return 0;
2476 }
2477 #endif
2478
2479 #if 0
2480 /*------------------------------------------------------------------*/
2481 /* Private handler : get wep string */
2482 #define WEP_ASCII_BUFF_SIZE (17+64*4+1)
2483 static int ks_wlan_get_wep_ascii(struct net_device *dev,
2484                                  struct iw_request_info *info,
2485                                  struct iw_point *dwrq, char *extra)
2486 {
2487         struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2488         int i, j, len = 0;
2489         char tmp[WEP_ASCII_BUFF_SIZE];
2490
2491         if (priv->sleep_mode == SLP_SLEEP) {
2492                 return -EPERM;
2493         }
2494         /* for SLEEP MODE */
2495         strcpy(tmp, " WEP keys ASCII \n");
2496         len += strlen(" WEP keys ASCII \n");
2497
2498         for (i = 0; i < 4; i++) {
2499                 strcpy(tmp + len, "\t[");
2500                 len += strlen("\t[");
2501                 tmp[len] = '1' + i;
2502                 len++;
2503                 strcpy(tmp + len, "] ");
2504                 len += strlen("] ");
2505                 if (priv->reg.wep_key[i].size) {
2506                         strcpy(tmp + len,
2507                                (priv->reg.wep_key[i].size <
2508                                 6 ? "(40bits) [" : "(104bits) ["));
2509                         len +=
2510                             strlen((priv->reg.wep_key[i].size <
2511                                     6 ? "(40bits) [" : "(104bits) ["));
2512                         for (j = 0; j < priv->reg.wep_key[i].size; j++, len++)
2513                                 tmp[len] =
2514                                     (isprint(priv->reg.wep_key[i].val[j]) ?
2515                                      priv->reg.wep_key[i].val[j] : ' ');
2516
2517                         strcpy(tmp + len, "]\n");
2518                         len += strlen("]\n");
2519                 } else {
2520                         strcpy(tmp + len, "off\n");
2521                         len += strlen("off\n");
2522                 }
2523         }
2524
2525         memcpy(extra, tmp, len);
2526         dwrq->length = len + 1;
2527         return 0;
2528 }
2529 #endif
2530
2531 /*------------------------------------------------------------------*/
2532 /* Private handler : set beacon lost count */
2533 static int ks_wlan_set_beacon_lost(struct net_device *dev,
2534                                    struct iw_request_info *info, __u32 * uwrq,
2535                                    char *extra)
2536 {
2537         struct ks_wlan_private *priv =
2538             (struct ks_wlan_private *)netdev_priv(dev);
2539
2540         if (priv->sleep_mode == SLP_SLEEP) {
2541                 return -EPERM;
2542         }
2543         /* for SLEEP MODE */
2544         if (*uwrq >= BEACON_LOST_COUNT_MIN && *uwrq <= BEACON_LOST_COUNT_MAX) {
2545                 priv->reg.beacon_lost_count = *uwrq;
2546         } else
2547                 return -EINVAL;
2548
2549         if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
2550                 priv->need_commit |= SME_MODE_SET;
2551                 return -EINPROGRESS;    /* Call commit handler */
2552         } else
2553                 return 0;
2554 }
2555
2556 /*------------------------------------------------------------------*/
2557 /* Private handler : get beacon lost count */
2558 static int ks_wlan_get_beacon_lost(struct net_device *dev,
2559                                    struct iw_request_info *info, __u32 * uwrq,
2560                                    char *extra)
2561 {
2562         struct ks_wlan_private *priv =
2563             (struct ks_wlan_private *)netdev_priv(dev);
2564
2565         if (priv->sleep_mode == SLP_SLEEP) {
2566                 return -EPERM;
2567         }
2568         /* for SLEEP MODE */
2569         *uwrq = priv->reg.beacon_lost_count;
2570         return 0;
2571 }
2572
2573 /*------------------------------------------------------------------*/
2574 /* Private handler : set phy type */
2575 static int ks_wlan_set_phy_type(struct net_device *dev,
2576                                 struct iw_request_info *info, __u32 * uwrq,
2577                                 char *extra)
2578 {
2579         struct ks_wlan_private *priv =
2580             (struct ks_wlan_private *)netdev_priv(dev);
2581
2582         if (priv->sleep_mode == SLP_SLEEP) {
2583                 return -EPERM;
2584         }
2585         /* for SLEEP MODE */
2586         if (*uwrq == D_11B_ONLY_MODE) { /* 0 */
2587                 priv->reg.phy_type = D_11B_ONLY_MODE;
2588         } else if (*uwrq == D_11G_ONLY_MODE) {  /* 1 */
2589                 priv->reg.phy_type = D_11G_ONLY_MODE;
2590         } else if (*uwrq == D_11BG_COMPATIBLE_MODE) {   /* 2 */
2591                 priv->reg.phy_type = D_11BG_COMPATIBLE_MODE;
2592         } else
2593                 return -EINVAL;
2594
2595         priv->need_commit |= SME_MODE_SET;
2596         return -EINPROGRESS;    /* Call commit handler */
2597 }
2598
2599 /*------------------------------------------------------------------*/
2600 /* Private handler : get phy type */
2601 static int ks_wlan_get_phy_type(struct net_device *dev,
2602                                 struct iw_request_info *info, __u32 * uwrq,
2603                                 char *extra)
2604 {
2605         struct ks_wlan_private *priv =
2606             (struct ks_wlan_private *)netdev_priv(dev);
2607
2608         if (priv->sleep_mode == SLP_SLEEP) {
2609                 return -EPERM;
2610         }
2611         /* for SLEEP MODE */
2612         *uwrq = priv->reg.phy_type;
2613         return 0;
2614 }
2615
2616 /*------------------------------------------------------------------*/
2617 /* Private handler : set cts mode */
2618 static int ks_wlan_set_cts_mode(struct net_device *dev,
2619                                 struct iw_request_info *info, __u32 * uwrq,
2620                                 char *extra)
2621 {
2622         struct ks_wlan_private *priv =
2623             (struct ks_wlan_private *)netdev_priv(dev);
2624
2625         if (priv->sleep_mode == SLP_SLEEP) {
2626                 return -EPERM;
2627         }
2628         /* for SLEEP MODE */
2629         if (*uwrq == CTS_MODE_FALSE) {  /* 0 */
2630                 priv->reg.cts_mode = CTS_MODE_FALSE;
2631         } else if (*uwrq == CTS_MODE_TRUE) {    /* 1 */
2632                 if (priv->reg.phy_type == D_11G_ONLY_MODE ||
2633                     priv->reg.phy_type == D_11BG_COMPATIBLE_MODE)
2634                         priv->reg.cts_mode = CTS_MODE_TRUE;
2635                 else
2636                         priv->reg.cts_mode = CTS_MODE_FALSE;
2637         } else
2638                 return -EINVAL;
2639
2640         priv->need_commit |= SME_MODE_SET;
2641         return -EINPROGRESS;    /* Call commit handler */
2642 }
2643
2644 /*------------------------------------------------------------------*/
2645 /* Private handler : get cts mode */
2646 static int ks_wlan_get_cts_mode(struct net_device *dev,
2647                                 struct iw_request_info *info, __u32 * uwrq,
2648                                 char *extra)
2649 {
2650         struct ks_wlan_private *priv =
2651             (struct ks_wlan_private *)netdev_priv(dev);
2652
2653         if (priv->sleep_mode == SLP_SLEEP) {
2654                 return -EPERM;
2655         }
2656         /* for SLEEP MODE */
2657         *uwrq = priv->reg.cts_mode;
2658         return 0;
2659 }
2660
2661 /*------------------------------------------------------------------*/
2662 /* Private handler : set sleep mode */
2663 static int ks_wlan_set_sleep_mode(struct net_device *dev,
2664                                   struct iw_request_info *info,
2665                                   __u32 * uwrq, char *extra)
2666 {
2667         struct ks_wlan_private *priv =
2668             (struct ks_wlan_private *)netdev_priv(dev);
2669
2670         DPRINTK(2, "\n");
2671
2672         if (*uwrq == SLP_SLEEP) {
2673                 priv->sleep_mode = *uwrq;
2674                 netdev_info(dev, "SET_SLEEP_MODE %d\n", priv->sleep_mode);
2675
2676                 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2677                 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2678
2679         } else if (*uwrq == SLP_ACTIVE) {
2680                 priv->sleep_mode = *uwrq;
2681                 netdev_info(dev, "SET_SLEEP_MODE %d\n", priv->sleep_mode);
2682                 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2683         } else {
2684                 netdev_err(dev, "SET_SLEEP_MODE %d errror\n", *uwrq);
2685                 return -EINVAL;
2686         }
2687
2688         return 0;
2689 }
2690
2691 /*------------------------------------------------------------------*/
2692 /* Private handler : get sleep mode */
2693 static int ks_wlan_get_sleep_mode(struct net_device *dev,
2694                                   struct iw_request_info *info,
2695                                   __u32 * uwrq, char *extra)
2696 {
2697         struct ks_wlan_private *priv =
2698             (struct ks_wlan_private *)netdev_priv(dev);
2699
2700         DPRINTK(2, "GET_SLEEP_MODE %d\n", priv->sleep_mode);
2701         *uwrq = priv->sleep_mode;
2702
2703         return 0;
2704 }
2705
2706 #if 0
2707 /*------------------------------------------------------------------*/
2708 /* Private handler : set phy information timer */
2709 static int ks_wlan_set_phy_information_timer(struct net_device *dev,
2710                                              struct iw_request_info *info,
2711                                              __u32 * uwrq, char *extra)
2712 {
2713         struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2714
2715         if (priv->sleep_mode == SLP_SLEEP) {
2716                 return -EPERM;
2717         }
2718         /* for SLEEP MODE */
2719         if (*uwrq >= 0 && *uwrq <= 0xFFFF)      /* 0-65535 */
2720                 priv->reg.phy_info_timer = (uint16_t) * uwrq;
2721         else
2722                 return -EINVAL;
2723
2724         hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST);
2725
2726         return 0;
2727 }
2728
2729 /*------------------------------------------------------------------*/
2730 /* Private handler : get phy information timer */
2731 static int ks_wlan_get_phy_information_timer(struct net_device *dev,
2732                                              struct iw_request_info *info,
2733                                              __u32 * uwrq, char *extra)
2734 {
2735         struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2736
2737         if (priv->sleep_mode == SLP_SLEEP) {
2738                 return -EPERM;
2739         }
2740         /* for SLEEP MODE */
2741         *uwrq = priv->reg.phy_info_timer;
2742         return 0;
2743 }
2744 #endif
2745
2746 #ifdef WPS
2747 /*------------------------------------------------------------------*/
2748 /* Private handler : set WPS enable */
2749 static int ks_wlan_set_wps_enable(struct net_device *dev,
2750                                   struct iw_request_info *info, __u32 * uwrq,
2751                                   char *extra)
2752 {
2753         struct ks_wlan_private *priv =
2754             (struct ks_wlan_private *)netdev_priv(dev);
2755         DPRINTK(2, "\n");
2756
2757         if (priv->sleep_mode == SLP_SLEEP) {
2758                 return -EPERM;
2759         }
2760         /* for SLEEP MODE */
2761         if (*uwrq == 0 || *uwrq == 1)
2762                 priv->wps.wps_enabled = *uwrq;
2763         else
2764                 return -EINVAL;
2765
2766         hostif_sme_enqueue(priv, SME_WPS_ENABLE_REQUEST);
2767
2768         return 0;
2769 }
2770
2771 /*------------------------------------------------------------------*/
2772 /* Private handler : get WPS enable */
2773 static int ks_wlan_get_wps_enable(struct net_device *dev,
2774                                   struct iw_request_info *info, __u32 * uwrq,
2775                                   char *extra)
2776 {
2777         struct ks_wlan_private *priv =
2778             (struct ks_wlan_private *)netdev_priv(dev);
2779         DPRINTK(2, "\n");
2780
2781         if (priv->sleep_mode == SLP_SLEEP) {
2782                 return -EPERM;
2783         }
2784         /* for SLEEP MODE */
2785         *uwrq = priv->wps.wps_enabled;
2786         netdev_info(dev, "return=%d\n", *uwrq);
2787
2788         return 0;
2789 }
2790
2791 /*------------------------------------------------------------------*/
2792 /* Private handler : set WPS probe req */
2793 static int ks_wlan_set_wps_probe_req(struct net_device *dev,
2794                                      struct iw_request_info *info,
2795                                      struct iw_point *dwrq, char *extra)
2796 {
2797         uint8_t *p = extra;
2798         unsigned char len;
2799         struct ks_wlan_private *priv =
2800             (struct ks_wlan_private *)netdev_priv(dev);
2801
2802         DPRINTK(2, "\n");
2803
2804         if (priv->sleep_mode == SLP_SLEEP) {
2805                 return -EPERM;
2806         }
2807         /* for SLEEP MODE */
2808         DPRINTK(2, "dwrq->length=%d\n", dwrq->length);
2809
2810         /* length check */
2811         if (p[1] + 2 != dwrq->length || dwrq->length > 256) {
2812                 return -EINVAL;
2813         }
2814
2815         priv->wps.ielen = p[1] + 2 + 1; /* IE header + IE + sizeof(len) */
2816         len = p[1] + 2; /* IE header + IE */
2817
2818         memcpy(priv->wps.ie, &len, sizeof(len));
2819         p = memcpy(priv->wps.ie + 1, p, len);
2820
2821         DPRINTK(2, "%d(%#x): %02X %02X %02X %02X ... %02X %02X %02X\n",
2822                 priv->wps.ielen, priv->wps.ielen, p[0], p[1], p[2], p[3],
2823                 p[priv->wps.ielen - 3], p[priv->wps.ielen - 2],
2824                 p[priv->wps.ielen - 1]);
2825
2826         hostif_sme_enqueue(priv, SME_WPS_PROBE_REQUEST);
2827
2828         return 0;
2829 }
2830
2831 #if 0
2832 /*------------------------------------------------------------------*/
2833 /* Private handler : get WPS probe req */
2834 static int ks_wlan_get_wps_probe_req(struct net_device *dev,
2835                                      struct iw_request_info *info,
2836                                      __u32 * uwrq, char *extra)
2837 {
2838         struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2839         DPRINTK(2, "\n");
2840
2841         if (priv->sleep_mode == SLP_SLEEP) {
2842                 return -EPERM;
2843         }
2844         /* for SLEEP MODE */
2845         return 0;
2846 }
2847 #endif
2848 #endif /* WPS */
2849
2850 /*------------------------------------------------------------------*/
2851 /* Private handler : set tx gain control value */
2852 static int ks_wlan_set_tx_gain(struct net_device *dev,
2853                                struct iw_request_info *info, __u32 * uwrq,
2854                                char *extra)
2855 {
2856         struct ks_wlan_private *priv =
2857             (struct ks_wlan_private *)netdev_priv(dev);
2858
2859         if (priv->sleep_mode == SLP_SLEEP) {
2860                 return -EPERM;
2861         }
2862         /* for SLEEP MODE */
2863         if (*uwrq >= 0 && *uwrq <= 0xFF)        /* 0-255 */
2864                 priv->gain.TxGain = (uint8_t) * uwrq;
2865         else
2866                 return -EINVAL;
2867
2868         if (priv->gain.TxGain < 0xFF)
2869                 priv->gain.TxMode = 1;
2870         else
2871                 priv->gain.TxMode = 0;
2872
2873         hostif_sme_enqueue(priv, SME_SET_GAIN);
2874         return 0;
2875 }
2876
2877 /*------------------------------------------------------------------*/
2878 /* Private handler : get tx gain control value */
2879 static int ks_wlan_get_tx_gain(struct net_device *dev,
2880                                struct iw_request_info *info, __u32 * uwrq,
2881                                char *extra)
2882 {
2883         struct ks_wlan_private *priv =
2884             (struct ks_wlan_private *)netdev_priv(dev);
2885
2886         if (priv->sleep_mode == SLP_SLEEP) {
2887                 return -EPERM;
2888         }
2889         /* for SLEEP MODE */
2890         *uwrq = priv->gain.TxGain;
2891         hostif_sme_enqueue(priv, SME_GET_GAIN);
2892         return 0;
2893 }
2894
2895 /*------------------------------------------------------------------*/
2896 /* Private handler : set rx gain control value */
2897 static int ks_wlan_set_rx_gain(struct net_device *dev,
2898                                struct iw_request_info *info, __u32 * uwrq,
2899                                char *extra)
2900 {
2901         struct ks_wlan_private *priv =
2902             (struct ks_wlan_private *)netdev_priv(dev);
2903
2904         if (priv->sleep_mode == SLP_SLEEP) {
2905                 return -EPERM;
2906         }
2907         /* for SLEEP MODE */
2908         if (*uwrq >= 0 && *uwrq <= 0xFF)        /* 0-255 */
2909                 priv->gain.RxGain = (uint8_t) * uwrq;
2910         else
2911                 return -EINVAL;
2912
2913         if (priv->gain.RxGain < 0xFF)
2914                 priv->gain.RxMode = 1;
2915         else
2916                 priv->gain.RxMode = 0;
2917
2918         hostif_sme_enqueue(priv, SME_SET_GAIN);
2919         return 0;
2920 }
2921
2922 /*------------------------------------------------------------------*/
2923 /* Private handler : get rx gain control value */
2924 static int ks_wlan_get_rx_gain(struct net_device *dev,
2925                                struct iw_request_info *info, __u32 * uwrq,
2926                                char *extra)
2927 {
2928         struct ks_wlan_private *priv =
2929             (struct ks_wlan_private *)netdev_priv(dev);
2930
2931         if (priv->sleep_mode == SLP_SLEEP) {
2932                 return -EPERM;
2933         }
2934         /* for SLEEP MODE */
2935         *uwrq = priv->gain.RxGain;
2936         hostif_sme_enqueue(priv, SME_GET_GAIN);
2937         return 0;
2938 }
2939
2940 #if 0
2941 /*------------------------------------------------------------------*/
2942 /* Private handler : set region value */
2943 static int ks_wlan_set_region(struct net_device *dev,
2944                               struct iw_request_info *info, __u32 * uwrq,
2945                               char *extra)
2946 {
2947         struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2948
2949         if (priv->sleep_mode == SLP_SLEEP) {
2950                 return -EPERM;
2951         }
2952         /* for SLEEP MODE */
2953         if (*uwrq >= 0x9 && *uwrq <= 0xF)       /* 0x9-0xf */
2954                 priv->region = (uint8_t) * uwrq;
2955         else
2956                 return -EINVAL;
2957
2958         hostif_sme_enqueue(priv, SME_SET_REGION);
2959         return 0;
2960 }
2961 #endif
2962
2963 /*------------------------------------------------------------------*/
2964 /* Private handler : get eeprom checksum result */
2965 static int ks_wlan_get_eeprom_cksum(struct net_device *dev,
2966                                     struct iw_request_info *info, __u32 * uwrq,
2967                                     char *extra)
2968 {
2969         struct ks_wlan_private *priv =
2970             (struct ks_wlan_private *)netdev_priv(dev);
2971
2972         *uwrq = priv->eeprom_checksum;
2973         return 0;
2974 }
2975
2976 static void print_hif_event(struct net_device *dev, int event)
2977 {
2978
2979         switch (event) {
2980         case HIF_DATA_REQ:
2981                 netdev_info(dev, "HIF_DATA_REQ\n");
2982                 break;
2983         case HIF_DATA_IND:
2984                 netdev_info(dev, "HIF_DATA_IND\n");
2985                 break;
2986         case HIF_MIB_GET_REQ:
2987                 netdev_info(dev, "HIF_MIB_GET_REQ\n");
2988                 break;
2989         case HIF_MIB_GET_CONF:
2990                 netdev_info(dev, "HIF_MIB_GET_CONF\n");
2991                 break;
2992         case HIF_MIB_SET_REQ:
2993                 netdev_info(dev, "HIF_MIB_SET_REQ\n");
2994                 break;
2995         case HIF_MIB_SET_CONF:
2996                 netdev_info(dev, "HIF_MIB_SET_CONF\n");
2997                 break;
2998         case HIF_POWERMGT_REQ:
2999                 netdev_info(dev, "HIF_POWERMGT_REQ\n");
3000                 break;
3001         case HIF_POWERMGT_CONF:
3002                 netdev_info(dev, "HIF_POWERMGT_CONF\n");
3003                 break;
3004         case HIF_START_REQ:
3005                 netdev_info(dev, "HIF_START_REQ\n");
3006                 break;
3007         case HIF_START_CONF:
3008                 netdev_info(dev, "HIF_START_CONF\n");
3009                 break;
3010         case HIF_CONNECT_IND:
3011                 netdev_info(dev, "HIF_CONNECT_IND\n");
3012                 break;
3013         case HIF_STOP_REQ:
3014                 netdev_info(dev, "HIF_STOP_REQ\n");
3015                 break;
3016         case HIF_STOP_CONF:
3017                 netdev_info(dev, "HIF_STOP_CONF\n");
3018                 break;
3019         case HIF_PS_ADH_SET_REQ:
3020                 netdev_info(dev, "HIF_PS_ADH_SET_REQ\n");
3021                 break;
3022         case HIF_PS_ADH_SET_CONF:
3023                 netdev_info(dev, "HIF_PS_ADH_SET_CONF\n");
3024                 break;
3025         case HIF_INFRA_SET_REQ:
3026                 netdev_info(dev, "HIF_INFRA_SET_REQ\n");
3027                 break;
3028         case HIF_INFRA_SET_CONF:
3029                 netdev_info(dev, "HIF_INFRA_SET_CONF\n");
3030                 break;
3031         case HIF_ADH_SET_REQ:
3032                 netdev_info(dev, "HIF_ADH_SET_REQ\n");
3033                 break;
3034         case HIF_ADH_SET_CONF:
3035                 netdev_info(dev, "HIF_ADH_SET_CONF\n");
3036                 break;
3037         case HIF_AP_SET_REQ:
3038                 netdev_info(dev, "HIF_AP_SET_REQ\n");
3039                 break;
3040         case HIF_AP_SET_CONF:
3041                 netdev_info(dev, "HIF_AP_SET_CONF\n");
3042                 break;
3043         case HIF_ASSOC_INFO_IND:
3044                 netdev_info(dev, "HIF_ASSOC_INFO_IND\n");
3045                 break;
3046         case HIF_MIC_FAILURE_REQ:
3047                 netdev_info(dev, "HIF_MIC_FAILURE_REQ\n");
3048                 break;
3049         case HIF_MIC_FAILURE_CONF:
3050                 netdev_info(dev, "HIF_MIC_FAILURE_CONF\n");
3051                 break;
3052         case HIF_SCAN_REQ:
3053                 netdev_info(dev, "HIF_SCAN_REQ\n");
3054                 break;
3055         case HIF_SCAN_CONF:
3056                 netdev_info(dev, "HIF_SCAN_CONF\n");
3057                 break;
3058         case HIF_PHY_INFO_REQ:
3059                 netdev_info(dev, "HIF_PHY_INFO_REQ\n");
3060                 break;
3061         case HIF_PHY_INFO_CONF:
3062                 netdev_info(dev, "HIF_PHY_INFO_CONF\n");
3063                 break;
3064         case HIF_SLEEP_REQ:
3065                 netdev_info(dev, "HIF_SLEEP_REQ\n");
3066                 break;
3067         case HIF_SLEEP_CONF:
3068                 netdev_info(dev, "HIF_SLEEP_CONF\n");
3069                 break;
3070         case HIF_PHY_INFO_IND:
3071                 netdev_info(dev, "HIF_PHY_INFO_IND\n");
3072                 break;
3073         case HIF_SCAN_IND:
3074                 netdev_info(dev, "HIF_SCAN_IND\n");
3075                 break;
3076         case HIF_INFRA_SET2_REQ:
3077                 netdev_info(dev, "HIF_INFRA_SET2_REQ\n");
3078                 break;
3079         case HIF_INFRA_SET2_CONF:
3080                 netdev_info(dev, "HIF_INFRA_SET2_CONF\n");
3081                 break;
3082         case HIF_ADH_SET2_REQ:
3083                 netdev_info(dev, "HIF_ADH_SET2_REQ\n");
3084                 break;
3085         case HIF_ADH_SET2_CONF:
3086                 netdev_info(dev, "HIF_ADH_SET2_CONF\n");
3087         }
3088 }
3089
3090 /*------------------------------------------------------------------*/
3091 /* Private handler : get host command history */
3092 static int ks_wlan_hostt(struct net_device *dev, struct iw_request_info *info,
3093                          __u32 * uwrq, char *extra)
3094 {
3095         int i, event;
3096         struct ks_wlan_private *priv =
3097             (struct ks_wlan_private *)netdev_priv(dev);
3098
3099         for (i = 63; i >= 0; i--) {
3100                 event =
3101                     priv->hostt.buff[(priv->hostt.qtail - 1 - i) %
3102                                      SME_EVENT_BUFF_SIZE];
3103                 print_hif_event(dev, event);
3104         }
3105         return 0;
3106 }
3107
3108 /* Structures to export the Wireless Handlers */
3109
3110 static const struct iw_priv_args ks_wlan_private_args[] = {
3111 /*{ cmd, set_args, get_args, name[16] } */
3112         {KS_WLAN_GET_FIRM_VERSION, IW_PRIV_TYPE_NONE,
3113          IW_PRIV_TYPE_CHAR | (128 + 1), "GetFirmwareVer"},
3114 #ifdef WPS
3115         {KS_WLAN_SET_WPS_ENABLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3116          IW_PRIV_TYPE_NONE, "SetWPSEnable"},
3117         {KS_WLAN_GET_WPS_ENABLE, IW_PRIV_TYPE_NONE,
3118          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetW"},
3119         {KS_WLAN_SET_WPS_PROBE_REQ, IW_PRIV_TYPE_BYTE | 2047, IW_PRIV_TYPE_NONE,
3120          "SetWPSProbeReq"},
3121 #endif /* WPS */
3122         {KS_WLAN_SET_PREAMBLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3123          IW_PRIV_TYPE_NONE, "SetPreamble"},
3124         {KS_WLAN_GET_PREAMBLE, IW_PRIV_TYPE_NONE,
3125          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPreamble"},
3126         {KS_WLAN_SET_POWER_SAVE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3127          IW_PRIV_TYPE_NONE, "SetPowerSave"},
3128         {KS_WLAN_GET_POWER_SAVE, IW_PRIV_TYPE_NONE,
3129          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPowerSave"},
3130         {KS_WLAN_SET_SCAN_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3131          IW_PRIV_TYPE_NONE, "SetScanType"},
3132         {KS_WLAN_GET_SCAN_TYPE, IW_PRIV_TYPE_NONE,
3133          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetScanType"},
3134         {KS_WLAN_SET_RX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3135          IW_PRIV_TYPE_NONE, "SetRxGain"},
3136         {KS_WLAN_GET_RX_GAIN, IW_PRIV_TYPE_NONE,
3137          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetRxGain"},
3138         {KS_WLAN_HOSTT, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | (128 + 1),
3139          "hostt"},
3140         {KS_WLAN_SET_BEACON_LOST, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3141          IW_PRIV_TYPE_NONE, "SetBeaconLost"},
3142         {KS_WLAN_GET_BEACON_LOST, IW_PRIV_TYPE_NONE,
3143          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetBeaconLost"},
3144         {KS_WLAN_SET_SLEEP_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3145          IW_PRIV_TYPE_NONE, "SetSleepMode"},
3146         {KS_WLAN_GET_SLEEP_MODE, IW_PRIV_TYPE_NONE,
3147          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetSleepMode"},
3148         {KS_WLAN_SET_TX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3149          IW_PRIV_TYPE_NONE, "SetTxGain"},
3150         {KS_WLAN_GET_TX_GAIN, IW_PRIV_TYPE_NONE,
3151          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetTxGain"},
3152         {KS_WLAN_SET_PHY_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3153          IW_PRIV_TYPE_NONE, "SetPhyType"},
3154         {KS_WLAN_GET_PHY_TYPE, IW_PRIV_TYPE_NONE,
3155          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPhyType"},
3156         {KS_WLAN_SET_CTS_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3157          IW_PRIV_TYPE_NONE, "SetCtsMode"},
3158         {KS_WLAN_GET_CTS_MODE, IW_PRIV_TYPE_NONE,
3159          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetCtsMode"},
3160         {KS_WLAN_GET_EEPROM_CKSUM, IW_PRIV_TYPE_NONE,
3161          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetChecksum"},
3162 };
3163
3164 static const iw_handler ks_wlan_handler[] = {
3165         (iw_handler) ks_wlan_config_commit,     /* SIOCSIWCOMMIT */
3166         (iw_handler) ks_wlan_get_name,  /* SIOCGIWNAME */
3167         (iw_handler) NULL,      /* SIOCSIWNWID */
3168         (iw_handler) NULL,      /* SIOCGIWNWID */
3169         (iw_handler) ks_wlan_set_freq,  /* SIOCSIWFREQ */
3170         (iw_handler) ks_wlan_get_freq,  /* SIOCGIWFREQ */
3171         (iw_handler) ks_wlan_set_mode,  /* SIOCSIWMODE */
3172         (iw_handler) ks_wlan_get_mode,  /* SIOCGIWMODE */
3173 #ifndef KSC_OPNOTSUPP
3174         (iw_handler) ks_wlan_set_sens,  /* SIOCSIWSENS */
3175         (iw_handler) ks_wlan_get_sens,  /* SIOCGIWSENS */
3176 #else /* KSC_OPNOTSUPP */
3177         (iw_handler) NULL,      /* SIOCSIWSENS */
3178         (iw_handler) NULL,      /* SIOCGIWSENS */
3179 #endif /* KSC_OPNOTSUPP */
3180         (iw_handler) NULL,      /* SIOCSIWRANGE */
3181         (iw_handler) ks_wlan_get_range, /* SIOCGIWRANGE */
3182         (iw_handler) NULL,      /* SIOCSIWPRIV */
3183         (iw_handler) NULL,      /* SIOCGIWPRIV */
3184         (iw_handler) NULL,      /* SIOCSIWSTATS */
3185         (iw_handler) ks_wlan_get_iwstats,       /* SIOCGIWSTATS */
3186         (iw_handler) NULL,      /* SIOCSIWSPY */
3187         (iw_handler) NULL,      /* SIOCGIWSPY */
3188         (iw_handler) NULL,      /* SIOCSIWTHRSPY */
3189         (iw_handler) NULL,      /* SIOCGIWTHRSPY */
3190         (iw_handler) ks_wlan_set_wap,   /* SIOCSIWAP */
3191         (iw_handler) ks_wlan_get_wap,   /* SIOCGIWAP */
3192 //      (iw_handler) NULL,                      /* SIOCSIWMLME */
3193         (iw_handler) ks_wlan_set_mlme,  /* SIOCSIWMLME */
3194         (iw_handler) ks_wlan_get_aplist,        /* SIOCGIWAPLIST */
3195         (iw_handler) ks_wlan_set_scan,  /* SIOCSIWSCAN */
3196         (iw_handler) ks_wlan_get_scan,  /* SIOCGIWSCAN */
3197         (iw_handler) ks_wlan_set_essid, /* SIOCSIWESSID */
3198         (iw_handler) ks_wlan_get_essid, /* SIOCGIWESSID */
3199         (iw_handler) ks_wlan_set_nick,  /* SIOCSIWNICKN */
3200         (iw_handler) ks_wlan_get_nick,  /* SIOCGIWNICKN */
3201         (iw_handler) NULL,      /* -- hole -- */
3202         (iw_handler) NULL,      /* -- hole -- */
3203         (iw_handler) ks_wlan_set_rate,  /* SIOCSIWRATE */
3204         (iw_handler) ks_wlan_get_rate,  /* SIOCGIWRATE */
3205         (iw_handler) ks_wlan_set_rts,   /* SIOCSIWRTS */
3206         (iw_handler) ks_wlan_get_rts,   /* SIOCGIWRTS */
3207         (iw_handler) ks_wlan_set_frag,  /* SIOCSIWFRAG */
3208         (iw_handler) ks_wlan_get_frag,  /* SIOCGIWFRAG */
3209 #ifndef KSC_OPNOTSUPP
3210         (iw_handler) ks_wlan_set_txpow, /* SIOCSIWTXPOW */
3211         (iw_handler) ks_wlan_get_txpow, /* SIOCGIWTXPOW */
3212         (iw_handler) ks_wlan_set_retry, /* SIOCSIWRETRY */
3213         (iw_handler) ks_wlan_get_retry, /* SIOCGIWRETRY */
3214 #else /* KSC_OPNOTSUPP */
3215         (iw_handler) NULL,      /* SIOCSIWTXPOW */
3216         (iw_handler) NULL,      /* SIOCGIWTXPOW */
3217         (iw_handler) NULL,      /* SIOCSIWRETRY */
3218         (iw_handler) NULL,      /* SIOCGIWRETRY */
3219 #endif /* KSC_OPNOTSUPP */
3220         (iw_handler) ks_wlan_set_encode,        /* SIOCSIWENCODE */
3221         (iw_handler) ks_wlan_get_encode,        /* SIOCGIWENCODE */
3222         (iw_handler) ks_wlan_set_power, /* SIOCSIWPOWER */
3223         (iw_handler) ks_wlan_get_power, /* SIOCGIWPOWER */
3224         (iw_handler) NULL,      /* -- hole -- */
3225         (iw_handler) NULL,      /* -- hole -- */
3226 //      (iw_handler) NULL,                      /* SIOCSIWGENIE */
3227         (iw_handler) ks_wlan_set_genie, /* SIOCSIWGENIE */
3228         (iw_handler) NULL,      /* SIOCGIWGENIE */
3229         (iw_handler) ks_wlan_set_auth_mode,     /* SIOCSIWAUTH */
3230         (iw_handler) ks_wlan_get_auth_mode,     /* SIOCGIWAUTH */
3231         (iw_handler) ks_wlan_set_encode_ext,    /* SIOCSIWENCODEEXT */
3232         (iw_handler) ks_wlan_get_encode_ext,    /* SIOCGIWENCODEEXT */
3233         (iw_handler) ks_wlan_set_pmksa, /* SIOCSIWPMKSA */
3234         (iw_handler) NULL,      /* -- hole -- */
3235 };
3236
3237 /* private_handler */
3238 static const iw_handler ks_wlan_private_handler[] = {
3239         (iw_handler) NULL,      /*  0 */
3240         (iw_handler) NULL,      /*  1, used to be: KS_WLAN_GET_DRIVER_VERSION */
3241         (iw_handler) NULL,      /*  2 */
3242         (iw_handler) ks_wlan_get_firmware_version,      /*  3 KS_WLAN_GET_FIRM_VERSION */
3243 #ifdef WPS
3244         (iw_handler) ks_wlan_set_wps_enable,    /*  4 KS_WLAN_SET_WPS_ENABLE  */
3245         (iw_handler) ks_wlan_get_wps_enable,    /*  5 KS_WLAN_GET_WPS_ENABLE  */
3246         (iw_handler) ks_wlan_set_wps_probe_req, /*  6 KS_WLAN_SET_WPS_PROBE_REQ */
3247 #else
3248         (iw_handler) NULL,      /*  4 */
3249         (iw_handler) NULL,      /*  5 */
3250         (iw_handler) NULL,      /*  6 */
3251 #endif /* WPS */
3252
3253         (iw_handler) ks_wlan_get_eeprom_cksum,  /*  7 KS_WLAN_GET_CONNECT */
3254         (iw_handler) ks_wlan_set_preamble,      /*  8 KS_WLAN_SET_PREAMBLE */
3255         (iw_handler) ks_wlan_get_preamble,      /*  9 KS_WLAN_GET_PREAMBLE */
3256         (iw_handler) ks_wlan_set_powermgt,      /* 10 KS_WLAN_SET_POWER_SAVE */
3257         (iw_handler) ks_wlan_get_powermgt,      /* 11 KS_WLAN_GET_POWER_SAVE */
3258         (iw_handler) ks_wlan_set_scan_type,     /* 12 KS_WLAN_SET_SCAN_TYPE */
3259         (iw_handler) ks_wlan_get_scan_type,     /* 13 KS_WLAN_GET_SCAN_TYPE */
3260         (iw_handler) ks_wlan_set_rx_gain,       /* 14 KS_WLAN_SET_RX_GAIN */
3261         (iw_handler) ks_wlan_get_rx_gain,       /* 15 KS_WLAN_GET_RX_GAIN */
3262         (iw_handler) ks_wlan_hostt,     /* 16 KS_WLAN_HOSTT */
3263         (iw_handler) NULL,      /* 17 */
3264         (iw_handler) ks_wlan_set_beacon_lost,   /* 18 KS_WLAN_SET_BECAN_LOST */
3265         (iw_handler) ks_wlan_get_beacon_lost,   /* 19 KS_WLAN_GET_BECAN_LOST */
3266         (iw_handler) ks_wlan_set_tx_gain,       /* 20 KS_WLAN_SET_TX_GAIN */
3267         (iw_handler) ks_wlan_get_tx_gain,       /* 21 KS_WLAN_GET_TX_GAIN */
3268         (iw_handler) ks_wlan_set_phy_type,      /* 22 KS_WLAN_SET_PHY_TYPE */
3269         (iw_handler) ks_wlan_get_phy_type,      /* 23 KS_WLAN_GET_PHY_TYPE */
3270         (iw_handler) ks_wlan_set_cts_mode,      /* 24 KS_WLAN_SET_CTS_MODE */
3271         (iw_handler) ks_wlan_get_cts_mode,      /* 25 KS_WLAN_GET_CTS_MODE */
3272         (iw_handler) NULL,      /* 26 */
3273         (iw_handler) NULL,      /* 27 */
3274         (iw_handler) ks_wlan_set_sleep_mode,    /* 28 KS_WLAN_SET_SLEEP_MODE */
3275         (iw_handler) ks_wlan_get_sleep_mode,    /* 29 KS_WLAN_GET_SLEEP_MODE */
3276         (iw_handler) NULL,      /* 30 */
3277         (iw_handler) NULL,      /* 31 */
3278 };
3279
3280 static const struct iw_handler_def ks_wlan_handler_def = {
3281         .num_standard = sizeof(ks_wlan_handler) / sizeof(iw_handler),
3282         .num_private = sizeof(ks_wlan_private_handler) / sizeof(iw_handler),
3283         .num_private_args =
3284             sizeof(ks_wlan_private_args) / sizeof(struct iw_priv_args),
3285         .standard = (iw_handler *) ks_wlan_handler,
3286         .private = (iw_handler *) ks_wlan_private_handler,
3287         .private_args = (struct iw_priv_args *)ks_wlan_private_args,
3288         .get_wireless_stats = ks_get_wireless_stats,
3289 };
3290
3291 static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq,
3292                                 int cmd)
3293 {
3294         int rc = 0;
3295         struct iwreq *wrq = (struct iwreq *)rq;
3296         switch (cmd) {
3297         case SIOCIWFIRSTPRIV + 20:      /* KS_WLAN_SET_STOP_REQ */
3298                 rc = ks_wlan_set_stop_request(dev, NULL, &(wrq->u.mode), NULL);
3299                 break;
3300                 // All other calls are currently unsupported
3301         default:
3302                 rc = -EOPNOTSUPP;
3303         }
3304
3305         DPRINTK(5, "return=%d\n", rc);
3306         return rc;
3307 }
3308
3309 static
3310 struct net_device_stats *ks_wlan_get_stats(struct net_device *dev)
3311 {
3312         struct ks_wlan_private *priv = netdev_priv(dev);
3313
3314         if (priv->dev_state < DEVICE_STATE_READY) {
3315                 return NULL;    /* not finished initialize */
3316         }
3317
3318         return &priv->nstats;
3319 }
3320
3321 static
3322 int ks_wlan_set_mac_address(struct net_device *dev, void *addr)
3323 {
3324         struct ks_wlan_private *priv = netdev_priv(dev);
3325         struct sockaddr *mac_addr = (struct sockaddr *)addr;
3326         if (netif_running(dev))
3327                 return -EBUSY;
3328         memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
3329         memcpy(priv->eth_addr, mac_addr->sa_data, ETH_ALEN);
3330
3331         priv->mac_address_valid = 0;
3332         hostif_sme_enqueue(priv, SME_MACADDRESS_SET_REQUEST);
3333         netdev_info(dev,
3334                "ks_wlan: MAC ADDRESS = %02x:%02x:%02x:%02x:%02x:%02x\n",
3335                priv->eth_addr[0], priv->eth_addr[1], priv->eth_addr[2],
3336                priv->eth_addr[3], priv->eth_addr[4], priv->eth_addr[5]);
3337         return 0;
3338 }
3339
3340 static
3341 void ks_wlan_tx_timeout(struct net_device *dev)
3342 {
3343         struct ks_wlan_private *priv = netdev_priv(dev);
3344
3345         DPRINTK(1, "head(%d) tail(%d)!!\n", priv->tx_dev.qhead,
3346                 priv->tx_dev.qtail);
3347         if (!netif_queue_stopped(dev)) {
3348                 netif_stop_queue(dev);
3349         }
3350         priv->nstats.tx_errors++;
3351         netif_wake_queue(dev);
3352 }
3353
3354 static
3355 int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev)
3356 {
3357         struct ks_wlan_private *priv = netdev_priv(dev);
3358         int rc = 0;
3359
3360         DPRINTK(3, "in_interrupt()=%ld\n", in_interrupt());
3361
3362         if (!skb) {
3363                 netdev_err(dev, "ks_wlan:  skb == NULL!!!\n");
3364                 return 0;
3365         }
3366         if (priv->dev_state < DEVICE_STATE_READY) {
3367                 dev_kfree_skb(skb);
3368                 return 0;       /* not finished initialize */
3369         }
3370
3371         if (netif_running(dev))
3372                 netif_stop_queue(dev);
3373
3374         rc = hostif_data_request(priv, skb);
3375         netif_trans_update(dev);
3376
3377         DPRINTK(4, "rc=%d\n", rc);
3378         if (rc) {
3379                 rc = 0;
3380         }
3381
3382         return rc;
3383 }
3384
3385 void send_packet_complete(void *arg1, void *arg2)
3386 {
3387         struct ks_wlan_private *priv = (struct ks_wlan_private *)arg1;
3388         struct sk_buff *packet = (struct sk_buff *)arg2;
3389
3390         DPRINTK(3, "\n");
3391
3392         priv->nstats.tx_packets++;
3393
3394         if (netif_queue_stopped(priv->net_dev))
3395                 netif_wake_queue(priv->net_dev);
3396
3397         if (packet) {
3398                 priv->nstats.tx_bytes += packet->len;
3399                 dev_kfree_skb(packet);
3400                 packet = NULL;
3401         }
3402
3403 }
3404
3405 /* Set or clear the multicast filter for this adaptor.
3406    This routine is not state sensitive and need not be SMP locked. */
3407 static
3408 void ks_wlan_set_multicast_list(struct net_device *dev)
3409 {
3410         struct ks_wlan_private *priv = netdev_priv(dev);
3411
3412         DPRINTK(4, "\n");
3413         if (priv->dev_state < DEVICE_STATE_READY) {
3414                 return; /* not finished initialize */
3415         }
3416         hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST);
3417 }
3418
3419 static
3420 int ks_wlan_open(struct net_device *dev)
3421 {
3422         struct ks_wlan_private *priv = netdev_priv(dev);
3423
3424         priv->cur_rx = 0;
3425
3426         if (!priv->mac_address_valid) {
3427                 netdev_err(dev, "ks_wlan : %s Not READY !!\n", dev->name);
3428                 return -EBUSY;
3429         } else
3430                 netif_start_queue(dev);
3431
3432         return 0;
3433 }
3434
3435 static
3436 int ks_wlan_close(struct net_device *dev)
3437 {
3438
3439         netif_stop_queue(dev);
3440
3441         DPRINTK(4, "%s: Shutting down ethercard, status was 0x%4.4x.\n",
3442                 dev->name, 0x00);
3443
3444         return 0;
3445 }
3446
3447 /* Operational parameters that usually are not changed. */
3448 /* Time in jiffies before concluding the transmitter is hung. */
3449 #define TX_TIMEOUT  (3*HZ)
3450 static const unsigned char dummy_addr[] =
3451     { 0x00, 0x0b, 0xe3, 0x00, 0x00, 0x00 };
3452
3453 static const struct net_device_ops ks_wlan_netdev_ops = {
3454         .ndo_start_xmit = ks_wlan_start_xmit,
3455         .ndo_open = ks_wlan_open,
3456         .ndo_stop = ks_wlan_close,
3457         .ndo_do_ioctl = ks_wlan_netdev_ioctl,
3458         .ndo_set_mac_address = ks_wlan_set_mac_address,
3459         .ndo_get_stats = ks_wlan_get_stats,
3460         .ndo_tx_timeout = ks_wlan_tx_timeout,
3461         .ndo_set_rx_mode = ks_wlan_set_multicast_list,
3462 };
3463
3464 int ks_wlan_net_start(struct net_device *dev)
3465 {
3466         struct ks_wlan_private *priv;
3467         /* int rc; */
3468
3469         priv = netdev_priv(dev);
3470         priv->mac_address_valid = 0;
3471         priv->need_commit = 0;
3472
3473         priv->device_open_status = 1;
3474
3475         /* phy information update timer */
3476         atomic_set(&update_phyinfo, 0);
3477         init_timer(&update_phyinfo_timer);
3478         update_phyinfo_timer.function = ks_wlan_update_phyinfo_timeout;
3479         update_phyinfo_timer.data = (unsigned long)priv;
3480
3481         /* dummy address set */
3482         memcpy(priv->eth_addr, dummy_addr, ETH_ALEN);
3483         dev->dev_addr[0] = priv->eth_addr[0];
3484         dev->dev_addr[1] = priv->eth_addr[1];
3485         dev->dev_addr[2] = priv->eth_addr[2];
3486         dev->dev_addr[3] = priv->eth_addr[3];
3487         dev->dev_addr[4] = priv->eth_addr[4];
3488         dev->dev_addr[5] = priv->eth_addr[5];
3489         dev->dev_addr[6] = 0x00;
3490         dev->dev_addr[7] = 0x00;
3491
3492         /* The ks_wlan-specific entries in the device structure. */
3493         dev->netdev_ops = &ks_wlan_netdev_ops;
3494         dev->wireless_handlers = (struct iw_handler_def *)&ks_wlan_handler_def;
3495         dev->watchdog_timeo = TX_TIMEOUT;
3496
3497         netif_carrier_off(dev);
3498
3499         return 0;
3500 }
3501
3502 int ks_wlan_net_stop(struct net_device *dev)
3503 {
3504         struct ks_wlan_private *priv = netdev_priv(dev);
3505
3506         priv->device_open_status = 0;
3507         del_timer_sync(&update_phyinfo_timer);
3508
3509         if (netif_running(dev))
3510                 netif_stop_queue(dev);
3511
3512         return 0;
3513 }