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