GNU Linux-libre 4.14.290-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                         memcpy(&key->key_val[0], &enc->key[0], enc->key_len);
1791                         key->key_len = enc->key_len;
1792                         commit |= (SME_WEP_VAL1 << index);
1793                 }
1794                 break;
1795         case IW_ENCODE_ALG_TKIP:
1796                 if (!priv->reg.privacy_invoked) {
1797                         priv->reg.privacy_invoked = 0x01;
1798                         commit |= SME_WEP_FLAG;
1799                 }
1800                 if (enc->key_len == 32) {
1801                         memcpy(&key->key_val[0], &enc->key[0], enc->key_len - 16);
1802                         key->key_len = enc->key_len - 16;
1803                         if (priv->wpa.key_mgmt_suite == 4) {    /* WPA_NONE */
1804                                 memcpy(&key->tx_mic_key[0], &enc->key[16], 8);
1805                                 memcpy(&key->rx_mic_key[0], &enc->key[16], 8);
1806                         } else {
1807                                 memcpy(&key->tx_mic_key[0], &enc->key[16], 8);
1808                                 memcpy(&key->rx_mic_key[0], &enc->key[24], 8);
1809                         }
1810                         commit |= (SME_WEP_VAL1 << index);
1811                 }
1812                 break;
1813         default:
1814                 return -EINVAL;
1815         }
1816         key->alg = enc->alg;
1817
1818         if (commit) {
1819                 if (commit & SME_WEP_INDEX)
1820                         hostif_sme_enqueue(priv, SME_SET_TXKEY);
1821                 if (commit & SME_WEP_VAL_MASK)
1822                         hostif_sme_enqueue(priv, SME_SET_KEY1 + index);
1823                 if (commit & SME_WEP_FLAG)
1824                         hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
1825         }
1826
1827         return 0;
1828 }
1829
1830 /* get encoding token & mode (WPA)*/
1831 static int ks_wlan_get_encode_ext(struct net_device *dev,
1832                                   struct iw_request_info *info,
1833                                   struct iw_point *dwrq, char *extra)
1834 {
1835         struct ks_wlan_private *priv = netdev_priv(dev);
1836
1837         if (priv->sleep_mode == SLP_SLEEP)
1838                 return -EPERM;
1839
1840         /* for SLEEP MODE */
1841         /* WPA (not used ?? wpa_supplicant)
1842          * struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
1843          * struct iw_encode_ext *enc;
1844          * enc = (struct iw_encode_ext *)extra;
1845          * int index = dwrq->flags & IW_ENCODE_INDEX;
1846          * WPA (not used ?? wpa_supplicant)
1847          */
1848         return 0;
1849 }
1850
1851 static int ks_wlan_set_pmksa(struct net_device *dev,
1852                              struct iw_request_info *info,
1853                              struct iw_point *dwrq, char *extra)
1854 {
1855         struct ks_wlan_private *priv = netdev_priv(dev);
1856         struct iw_pmksa *pmksa;
1857         int i;
1858         struct pmk_t *pmk;
1859         struct list_head *ptr;
1860
1861         DPRINTK(2, "\n");
1862
1863         if (priv->sleep_mode == SLP_SLEEP)
1864                 return -EPERM;
1865
1866         /* for SLEEP MODE */
1867         if (!extra)
1868                 return -EINVAL;
1869
1870         pmksa = (struct iw_pmksa *)extra;
1871         DPRINTK(2, "cmd=%d\n", pmksa->cmd);
1872
1873         switch (pmksa->cmd) {
1874         case IW_PMKSA_ADD:
1875                 if (list_empty(&priv->pmklist.head)) {  /* new list */
1876                         for (i = 0; i < PMK_LIST_MAX; i++) {
1877                                 pmk = &priv->pmklist.pmk[i];
1878                                 if (memcmp("\x00\x00\x00\x00\x00\x00",
1879                                            pmk->bssid, ETH_ALEN) == 0)
1880                                         break; /* loop */
1881                         }
1882                         memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
1883                         memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1884                         list_add(&pmk->list, &priv->pmklist.head);
1885                         priv->pmklist.size++;
1886                         break;  /* case */
1887                 }
1888                 /* search cache data */
1889                 list_for_each(ptr, &priv->pmklist.head) {
1890                         pmk = list_entry(ptr, struct pmk_t, list);
1891                         if (memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN) == 0) {
1892                                 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1893                                 list_move(&pmk->list, &priv->pmklist.head);
1894                                 break; /* list_for_each */
1895                         }
1896                 }
1897                 if (ptr != &priv->pmklist.head) /* not find address. */
1898                         break;  /* case */
1899
1900                 if (priv->pmklist.size < PMK_LIST_MAX) {        /* new cache data */
1901                         for (i = 0; i < PMK_LIST_MAX; i++) {
1902                                 pmk = &priv->pmklist.pmk[i];
1903                                 if (memcmp("\x00\x00\x00\x00\x00\x00",
1904                                            pmk->bssid, ETH_ALEN) == 0)
1905                                         break; /* loop */
1906                         }
1907                         memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
1908                         memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1909                         list_add(&pmk->list, &priv->pmklist.head);
1910                         priv->pmklist.size++;
1911                 } else {        /* overwrite old cache data */
1912                         pmk = list_entry(priv->pmklist.head.prev, struct pmk_t,
1913                                          list);
1914                         memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
1915                         memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1916                         list_move(&pmk->list, &priv->pmklist.head);
1917                 }
1918                 break;
1919         case IW_PMKSA_REMOVE:
1920                 if (list_empty(&priv->pmklist.head)) {  /* list empty */
1921                         return -EINVAL;
1922                 }
1923                 /* search cache data */
1924                 list_for_each(ptr, &priv->pmklist.head) {
1925                         pmk = list_entry(ptr, struct pmk_t, list);
1926                         if (memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN) == 0) {
1927                                 eth_zero_addr(pmk->bssid);
1928                                 memset(pmk->pmkid, 0, IW_PMKID_LEN);
1929                                 list_del_init(&pmk->list);
1930                                 break;
1931                         }
1932                 }
1933                 if (ptr == &priv->pmklist.head) {       /* not find address. */
1934                         return 0;
1935                 }
1936
1937                 break;
1938         case IW_PMKSA_FLUSH:
1939                 memset(&priv->pmklist, 0, sizeof(priv->pmklist));
1940                 INIT_LIST_HEAD(&priv->pmklist.head);
1941                 for (i = 0; i < PMK_LIST_MAX; i++)
1942                         INIT_LIST_HEAD(&priv->pmklist.pmk[i].list);
1943                 break;
1944         default:
1945                 return -EINVAL;
1946         }
1947
1948         hostif_sme_enqueue(priv, SME_SET_PMKSA);
1949         return 0;
1950 }
1951
1952 static struct iw_statistics *ks_get_wireless_stats(struct net_device *dev)
1953 {
1954         struct ks_wlan_private *priv = netdev_priv(dev);
1955         struct iw_statistics *wstats = &priv->wstats;
1956
1957         if (!atomic_read(&update_phyinfo)) {
1958                 if (priv->dev_state < DEVICE_STATE_READY)
1959                         return NULL;    /* not finished initialize */
1960                 else
1961                         return wstats;
1962         }
1963
1964         /* Packets discarded in the wireless adapter due to wireless
1965          * specific problems
1966          */
1967         wstats->discard.nwid = 0;       /* Rx invalid nwid      */
1968         wstats->discard.code = 0;       /* Rx invalid crypt     */
1969         wstats->discard.fragment = 0;   /* Rx invalid frag      */
1970         wstats->discard.retries = 0;    /* Tx excessive retries */
1971         wstats->discard.misc = 0;       /* Invalid misc         */
1972         wstats->miss.beacon = 0;        /* Missed beacon        */
1973
1974         return wstats;
1975 }
1976
1977 static int ks_wlan_set_stop_request(struct net_device *dev,
1978                                     struct iw_request_info *info, __u32 *uwrq,
1979                                     char *extra)
1980 {
1981         struct ks_wlan_private *priv = netdev_priv(dev);
1982
1983         DPRINTK(2, "\n");
1984
1985         if (priv->sleep_mode == SLP_SLEEP)
1986                 return -EPERM;
1987
1988         /* for SLEEP MODE */
1989         if (!(*uwrq))
1990                 return -EINVAL;
1991
1992         hostif_sme_enqueue(priv, SME_STOP_REQUEST);
1993         return 0;
1994 }
1995
1996 #include <linux/ieee80211.h>
1997 static int ks_wlan_set_mlme(struct net_device *dev,
1998                             struct iw_request_info *info, struct iw_point *dwrq,
1999                             char *extra)
2000 {
2001         struct ks_wlan_private *priv = netdev_priv(dev);
2002         struct iw_mlme *mlme = (struct iw_mlme *)extra;
2003         __u32 mode;
2004
2005         DPRINTK(2, ":%d :%d\n", mlme->cmd, mlme->reason_code);
2006
2007         if (priv->sleep_mode == SLP_SLEEP)
2008                 return -EPERM;
2009
2010         /* for SLEEP MODE */
2011         switch (mlme->cmd) {
2012         case IW_MLME_DEAUTH:
2013                 if (mlme->reason_code == WLAN_REASON_MIC_FAILURE)
2014                         return 0;
2015         case IW_MLME_DISASSOC:
2016                 mode = 1;
2017                 return ks_wlan_set_stop_request(dev, NULL, &mode, NULL);
2018         default:
2019                 return -EOPNOTSUPP;     /* Not Support */
2020         }
2021 }
2022
2023 static int ks_wlan_get_firmware_version(struct net_device *dev,
2024                                         struct iw_request_info *info,
2025                                         struct iw_point *dwrq, char *extra)
2026 {
2027         struct ks_wlan_private *priv = netdev_priv(dev);
2028
2029         strcpy(extra, priv->firmware_version);
2030         dwrq->length = priv->version_size + 1;
2031         return 0;
2032 }
2033
2034 static int ks_wlan_set_preamble(struct net_device *dev,
2035                                 struct iw_request_info *info, __u32 *uwrq,
2036                                 char *extra)
2037 {
2038         struct ks_wlan_private *priv = netdev_priv(dev);
2039
2040         if (priv->sleep_mode == SLP_SLEEP)
2041                 return -EPERM;
2042
2043         /* for SLEEP MODE */
2044         if (*uwrq == LONG_PREAMBLE) {   /* 0 */
2045                 priv->reg.preamble = LONG_PREAMBLE;
2046         } else if (*uwrq == SHORT_PREAMBLE) {   /* 1 */
2047                 priv->reg.preamble = SHORT_PREAMBLE;
2048         } else {
2049                 return -EINVAL;
2050         }
2051
2052         priv->need_commit |= SME_MODE_SET;
2053         return -EINPROGRESS;    /* Call commit handler */
2054 }
2055
2056 static int ks_wlan_get_preamble(struct net_device *dev,
2057                                 struct iw_request_info *info, __u32 *uwrq,
2058                                 char *extra)
2059 {
2060         struct ks_wlan_private *priv = netdev_priv(dev);
2061
2062         if (priv->sleep_mode == SLP_SLEEP)
2063                 return -EPERM;
2064
2065         /* for SLEEP MODE */
2066         *uwrq = priv->reg.preamble;
2067         return 0;
2068 }
2069
2070 static int ks_wlan_set_power_mgmt(struct net_device *dev,
2071                                   struct iw_request_info *info, __u32 *uwrq,
2072                                   char *extra)
2073 {
2074         struct ks_wlan_private *priv = netdev_priv(dev);
2075
2076         if (priv->sleep_mode == SLP_SLEEP)
2077                 return -EPERM;
2078
2079         /* for SLEEP MODE */
2080         if (*uwrq == POWER_MGMT_ACTIVE) {       /* 0 */
2081                 priv->reg.power_mgmt = POWER_MGMT_ACTIVE;
2082         } else if (*uwrq == POWER_MGMT_SAVE1) { /* 1 */
2083                 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2084                         priv->reg.power_mgmt = POWER_MGMT_SAVE1;
2085                 else
2086                         return -EINVAL;
2087         } else if (*uwrq == POWER_MGMT_SAVE2) { /* 2 */
2088                 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2089                         priv->reg.power_mgmt = POWER_MGMT_SAVE2;
2090                 else
2091                         return -EINVAL;
2092         } else {
2093                 return -EINVAL;
2094         }
2095
2096         hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
2097
2098         return 0;
2099 }
2100
2101 static int ks_wlan_get_power_mgmt(struct net_device *dev,
2102                                   struct iw_request_info *info, __u32 *uwrq,
2103                                   char *extra)
2104 {
2105         struct ks_wlan_private *priv = netdev_priv(dev);
2106
2107         if (priv->sleep_mode == SLP_SLEEP)
2108                 return -EPERM;
2109
2110         /* for SLEEP MODE */
2111         *uwrq = priv->reg.power_mgmt;
2112         return 0;
2113 }
2114
2115 static int ks_wlan_set_scan_type(struct net_device *dev,
2116                                  struct iw_request_info *info, __u32 *uwrq,
2117                                  char *extra)
2118 {
2119         struct ks_wlan_private *priv = netdev_priv(dev);
2120
2121         if (priv->sleep_mode == SLP_SLEEP)
2122                 return -EPERM;
2123         /* for SLEEP MODE */
2124         if (*uwrq == ACTIVE_SCAN) {     /* 0 */
2125                 priv->reg.scan_type = ACTIVE_SCAN;
2126         } else if (*uwrq == PASSIVE_SCAN) {     /* 1 */
2127                 priv->reg.scan_type = PASSIVE_SCAN;
2128         } else {
2129                 return -EINVAL;
2130         }
2131
2132         return 0;
2133 }
2134
2135 static int ks_wlan_get_scan_type(struct net_device *dev,
2136                                  struct iw_request_info *info, __u32 *uwrq,
2137                                  char *extra)
2138 {
2139         struct ks_wlan_private *priv = netdev_priv(dev);
2140
2141         if (priv->sleep_mode == SLP_SLEEP)
2142                 return -EPERM;
2143         /* for SLEEP MODE */
2144         *uwrq = priv->reg.scan_type;
2145         return 0;
2146 }
2147
2148 static int ks_wlan_set_beacon_lost(struct net_device *dev,
2149                                    struct iw_request_info *info, __u32 *uwrq,
2150                                    char *extra)
2151 {
2152         struct ks_wlan_private *priv = netdev_priv(dev);
2153
2154         if (priv->sleep_mode == SLP_SLEEP)
2155                 return -EPERM;
2156         /* for SLEEP MODE */
2157         if (*uwrq >= BEACON_LOST_COUNT_MIN && *uwrq <= BEACON_LOST_COUNT_MAX)
2158                 priv->reg.beacon_lost_count = *uwrq;
2159         else
2160                 return -EINVAL;
2161
2162         if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
2163                 priv->need_commit |= SME_MODE_SET;
2164                 return -EINPROGRESS;    /* Call commit handler */
2165         } else {
2166                 return 0;
2167         }
2168 }
2169
2170 static int ks_wlan_get_beacon_lost(struct net_device *dev,
2171                                    struct iw_request_info *info, __u32 *uwrq,
2172                                    char *extra)
2173 {
2174         struct ks_wlan_private *priv = netdev_priv(dev);
2175
2176         if (priv->sleep_mode == SLP_SLEEP)
2177                 return -EPERM;
2178         /* for SLEEP MODE */
2179         *uwrq = priv->reg.beacon_lost_count;
2180         return 0;
2181 }
2182
2183 static int ks_wlan_set_phy_type(struct net_device *dev,
2184                                 struct iw_request_info *info, __u32 *uwrq,
2185                                 char *extra)
2186 {
2187         struct ks_wlan_private *priv = netdev_priv(dev);
2188
2189         if (priv->sleep_mode == SLP_SLEEP)
2190                 return -EPERM;
2191         /* for SLEEP MODE */
2192         if (*uwrq == D_11B_ONLY_MODE) { /* 0 */
2193                 priv->reg.phy_type = D_11B_ONLY_MODE;
2194         } else if (*uwrq == D_11G_ONLY_MODE) {  /* 1 */
2195                 priv->reg.phy_type = D_11G_ONLY_MODE;
2196         } else if (*uwrq == D_11BG_COMPATIBLE_MODE) {   /* 2 */
2197                 priv->reg.phy_type = D_11BG_COMPATIBLE_MODE;
2198         } else {
2199                 return -EINVAL;
2200         }
2201
2202         priv->need_commit |= SME_MODE_SET;
2203         return -EINPROGRESS;    /* Call commit handler */
2204 }
2205
2206 static int ks_wlan_get_phy_type(struct net_device *dev,
2207                                 struct iw_request_info *info, __u32 *uwrq,
2208                                 char *extra)
2209 {
2210         struct ks_wlan_private *priv = netdev_priv(dev);
2211
2212         if (priv->sleep_mode == SLP_SLEEP)
2213                 return -EPERM;
2214         /* for SLEEP MODE */
2215         *uwrq = priv->reg.phy_type;
2216         return 0;
2217 }
2218
2219 static int ks_wlan_set_cts_mode(struct net_device *dev,
2220                                 struct iw_request_info *info, __u32 *uwrq,
2221                                 char *extra)
2222 {
2223         struct ks_wlan_private *priv = netdev_priv(dev);
2224
2225         if (priv->sleep_mode == SLP_SLEEP)
2226                 return -EPERM;
2227         /* for SLEEP MODE */
2228         if (*uwrq == CTS_MODE_FALSE) {  /* 0 */
2229                 priv->reg.cts_mode = CTS_MODE_FALSE;
2230         } else if (*uwrq == CTS_MODE_TRUE) {    /* 1 */
2231                 if (priv->reg.phy_type == D_11G_ONLY_MODE ||
2232                     priv->reg.phy_type == D_11BG_COMPATIBLE_MODE) {
2233                         priv->reg.cts_mode = CTS_MODE_TRUE;
2234                 } else {
2235                         priv->reg.cts_mode = CTS_MODE_FALSE;
2236                 }
2237         } else {
2238                 return -EINVAL;
2239         }
2240
2241         priv->need_commit |= SME_MODE_SET;
2242         return -EINPROGRESS;    /* Call commit handler */
2243 }
2244
2245 static int ks_wlan_get_cts_mode(struct net_device *dev,
2246                                 struct iw_request_info *info, __u32 *uwrq,
2247                                 char *extra)
2248 {
2249         struct ks_wlan_private *priv = netdev_priv(dev);
2250
2251         if (priv->sleep_mode == SLP_SLEEP)
2252                 return -EPERM;
2253         /* for SLEEP MODE */
2254         *uwrq = priv->reg.cts_mode;
2255         return 0;
2256 }
2257
2258 static int ks_wlan_set_sleep_mode(struct net_device *dev,
2259                                   struct iw_request_info *info,
2260                                   __u32 *uwrq, char *extra)
2261 {
2262         struct ks_wlan_private *priv = netdev_priv(dev);
2263
2264         DPRINTK(2, "\n");
2265
2266         if (*uwrq == SLP_SLEEP) {
2267                 priv->sleep_mode = *uwrq;
2268                 netdev_info(dev, "SET_SLEEP_MODE %d\n", priv->sleep_mode);
2269
2270                 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2271                 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2272
2273         } else if (*uwrq == SLP_ACTIVE) {
2274                 priv->sleep_mode = *uwrq;
2275                 netdev_info(dev, "SET_SLEEP_MODE %d\n", priv->sleep_mode);
2276                 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2277         } else {
2278                 netdev_err(dev, "SET_SLEEP_MODE %d error\n", *uwrq);
2279                 return -EINVAL;
2280         }
2281
2282         return 0;
2283 }
2284
2285 static int ks_wlan_get_sleep_mode(struct net_device *dev,
2286                                   struct iw_request_info *info,
2287                                   __u32 *uwrq, char *extra)
2288 {
2289         struct ks_wlan_private *priv = netdev_priv(dev);
2290
2291         DPRINTK(2, "GET_SLEEP_MODE %d\n", priv->sleep_mode);
2292         *uwrq = priv->sleep_mode;
2293
2294         return 0;
2295 }
2296
2297 #ifdef WPS
2298
2299 static int ks_wlan_set_wps_enable(struct net_device *dev,
2300                                   struct iw_request_info *info, __u32 *uwrq,
2301                                   char *extra)
2302 {
2303         struct ks_wlan_private *priv = netdev_priv(dev);
2304
2305         DPRINTK(2, "\n");
2306
2307         if (priv->sleep_mode == SLP_SLEEP)
2308                 return -EPERM;
2309         /* for SLEEP MODE */
2310         if (*uwrq == 0 || *uwrq == 1)
2311                 priv->wps.wps_enabled = *uwrq;
2312         else
2313                 return -EINVAL;
2314
2315         hostif_sme_enqueue(priv, SME_WPS_ENABLE_REQUEST);
2316
2317         return 0;
2318 }
2319
2320 static int ks_wlan_get_wps_enable(struct net_device *dev,
2321                                   struct iw_request_info *info, __u32 *uwrq,
2322                                   char *extra)
2323 {
2324         struct ks_wlan_private *priv = netdev_priv(dev);
2325
2326         DPRINTK(2, "\n");
2327
2328         if (priv->sleep_mode == SLP_SLEEP)
2329                 return -EPERM;
2330         /* for SLEEP MODE */
2331         *uwrq = priv->wps.wps_enabled;
2332         netdev_info(dev, "return=%d\n", *uwrq);
2333
2334         return 0;
2335 }
2336
2337 static int ks_wlan_set_wps_probe_req(struct net_device *dev,
2338                                      struct iw_request_info *info,
2339                                      struct iw_point *dwrq, char *extra)
2340 {
2341         u8 *p = extra;
2342         unsigned char len;
2343         struct ks_wlan_private *priv = netdev_priv(dev);
2344
2345         DPRINTK(2, "\n");
2346
2347         if (priv->sleep_mode == SLP_SLEEP)
2348                 return -EPERM;
2349         /* for SLEEP MODE */
2350         DPRINTK(2, "dwrq->length=%d\n", dwrq->length);
2351
2352         /* length check */
2353         if (p[1] + 2 != dwrq->length || dwrq->length > 256)
2354                 return -EINVAL;
2355
2356         priv->wps.ielen = p[1] + 2 + 1; /* IE header + IE + sizeof(len) */
2357         len = p[1] + 2; /* IE header + IE */
2358
2359         memcpy(priv->wps.ie, &len, sizeof(len));
2360         p = memcpy(priv->wps.ie + 1, p, len);
2361
2362         DPRINTK(2, "%d(%#x): %02X %02X %02X %02X ... %02X %02X %02X\n",
2363                 priv->wps.ielen, priv->wps.ielen, p[0], p[1], p[2], p[3],
2364                 p[priv->wps.ielen - 3], p[priv->wps.ielen - 2],
2365                 p[priv->wps.ielen - 1]);
2366
2367         hostif_sme_enqueue(priv, SME_WPS_PROBE_REQUEST);
2368
2369         return 0;
2370 }
2371 #endif /* WPS */
2372
2373 static int ks_wlan_set_tx_gain(struct net_device *dev,
2374                                struct iw_request_info *info, __u32 *uwrq,
2375                                char *extra)
2376 {
2377         struct ks_wlan_private *priv = netdev_priv(dev);
2378
2379         if (priv->sleep_mode == SLP_SLEEP)
2380                 return -EPERM;
2381         /* for SLEEP MODE */
2382         if (*uwrq >= 0 && *uwrq <= 0xFF)        /* 0-255 */
2383                 priv->gain.tx_gain = (uint8_t)*uwrq;
2384         else
2385                 return -EINVAL;
2386
2387         if (priv->gain.tx_gain < 0xFF)
2388                 priv->gain.tx_mode = 1;
2389         else
2390                 priv->gain.tx_mode = 0;
2391
2392         hostif_sme_enqueue(priv, SME_SET_GAIN);
2393         return 0;
2394 }
2395
2396 static int ks_wlan_get_tx_gain(struct net_device *dev,
2397                                struct iw_request_info *info, __u32 *uwrq,
2398                                char *extra)
2399 {
2400         struct ks_wlan_private *priv = netdev_priv(dev);
2401
2402         if (priv->sleep_mode == SLP_SLEEP)
2403                 return -EPERM;
2404         /* for SLEEP MODE */
2405         *uwrq = priv->gain.tx_gain;
2406         hostif_sme_enqueue(priv, SME_GET_GAIN);
2407         return 0;
2408 }
2409
2410 static int ks_wlan_set_rx_gain(struct net_device *dev,
2411                                struct iw_request_info *info, __u32 *uwrq,
2412                                char *extra)
2413 {
2414         struct ks_wlan_private *priv = netdev_priv(dev);
2415
2416         if (priv->sleep_mode == SLP_SLEEP)
2417                 return -EPERM;
2418         /* for SLEEP MODE */
2419         if (*uwrq >= 0 && *uwrq <= 0xFF)        /* 0-255 */
2420                 priv->gain.rx_gain = (uint8_t)*uwrq;
2421         else
2422                 return -EINVAL;
2423
2424         if (priv->gain.rx_gain < 0xFF)
2425                 priv->gain.rx_mode = 1;
2426         else
2427                 priv->gain.rx_mode = 0;
2428
2429         hostif_sme_enqueue(priv, SME_SET_GAIN);
2430         return 0;
2431 }
2432
2433 static int ks_wlan_get_rx_gain(struct net_device *dev,
2434                                struct iw_request_info *info, __u32 *uwrq,
2435                                char *extra)
2436 {
2437         struct ks_wlan_private *priv = netdev_priv(dev);
2438
2439         if (priv->sleep_mode == SLP_SLEEP)
2440                 return -EPERM;
2441         /* for SLEEP MODE */
2442         *uwrq = priv->gain.rx_gain;
2443         hostif_sme_enqueue(priv, SME_GET_GAIN);
2444         return 0;
2445 }
2446
2447 static int ks_wlan_get_eeprom_cksum(struct net_device *dev,
2448                                     struct iw_request_info *info, __u32 *uwrq,
2449                                     char *extra)
2450 {
2451         struct ks_wlan_private *priv = netdev_priv(dev);
2452
2453         *uwrq = priv->eeprom_checksum;
2454         return 0;
2455 }
2456
2457 static void print_hif_event(struct net_device *dev, int event)
2458 {
2459         switch (event) {
2460         case HIF_DATA_REQ:
2461                 netdev_info(dev, "HIF_DATA_REQ\n");
2462                 break;
2463         case HIF_DATA_IND:
2464                 netdev_info(dev, "HIF_DATA_IND\n");
2465                 break;
2466         case HIF_MIB_GET_REQ:
2467                 netdev_info(dev, "HIF_MIB_GET_REQ\n");
2468                 break;
2469         case HIF_MIB_GET_CONF:
2470                 netdev_info(dev, "HIF_MIB_GET_CONF\n");
2471                 break;
2472         case HIF_MIB_SET_REQ:
2473                 netdev_info(dev, "HIF_MIB_SET_REQ\n");
2474                 break;
2475         case HIF_MIB_SET_CONF:
2476                 netdev_info(dev, "HIF_MIB_SET_CONF\n");
2477                 break;
2478         case HIF_POWER_MGMT_REQ:
2479                 netdev_info(dev, "HIF_POWER_MGMT_REQ\n");
2480                 break;
2481         case HIF_POWER_MGMT_CONF:
2482                 netdev_info(dev, "HIF_POWER_MGMT_CONF\n");
2483                 break;
2484         case HIF_START_REQ:
2485                 netdev_info(dev, "HIF_START_REQ\n");
2486                 break;
2487         case HIF_START_CONF:
2488                 netdev_info(dev, "HIF_START_CONF\n");
2489                 break;
2490         case HIF_CONNECT_IND:
2491                 netdev_info(dev, "HIF_CONNECT_IND\n");
2492                 break;
2493         case HIF_STOP_REQ:
2494                 netdev_info(dev, "HIF_STOP_REQ\n");
2495                 break;
2496         case HIF_STOP_CONF:
2497                 netdev_info(dev, "HIF_STOP_CONF\n");
2498                 break;
2499         case HIF_PS_ADH_SET_REQ:
2500                 netdev_info(dev, "HIF_PS_ADH_SET_REQ\n");
2501                 break;
2502         case HIF_PS_ADH_SET_CONF:
2503                 netdev_info(dev, "HIF_PS_ADH_SET_CONF\n");
2504                 break;
2505         case HIF_INFRA_SET_REQ:
2506                 netdev_info(dev, "HIF_INFRA_SET_REQ\n");
2507                 break;
2508         case HIF_INFRA_SET_CONF:
2509                 netdev_info(dev, "HIF_INFRA_SET_CONF\n");
2510                 break;
2511         case HIF_ADH_SET_REQ:
2512                 netdev_info(dev, "HIF_ADH_SET_REQ\n");
2513                 break;
2514         case HIF_ADH_SET_CONF:
2515                 netdev_info(dev, "HIF_ADH_SET_CONF\n");
2516                 break;
2517         case HIF_AP_SET_REQ:
2518                 netdev_info(dev, "HIF_AP_SET_REQ\n");
2519                 break;
2520         case HIF_AP_SET_CONF:
2521                 netdev_info(dev, "HIF_AP_SET_CONF\n");
2522                 break;
2523         case HIF_ASSOC_INFO_IND:
2524                 netdev_info(dev, "HIF_ASSOC_INFO_IND\n");
2525                 break;
2526         case HIF_MIC_FAILURE_REQ:
2527                 netdev_info(dev, "HIF_MIC_FAILURE_REQ\n");
2528                 break;
2529         case HIF_MIC_FAILURE_CONF:
2530                 netdev_info(dev, "HIF_MIC_FAILURE_CONF\n");
2531                 break;
2532         case HIF_SCAN_REQ:
2533                 netdev_info(dev, "HIF_SCAN_REQ\n");
2534                 break;
2535         case HIF_SCAN_CONF:
2536                 netdev_info(dev, "HIF_SCAN_CONF\n");
2537                 break;
2538         case HIF_PHY_INFO_REQ:
2539                 netdev_info(dev, "HIF_PHY_INFO_REQ\n");
2540                 break;
2541         case HIF_PHY_INFO_CONF:
2542                 netdev_info(dev, "HIF_PHY_INFO_CONF\n");
2543                 break;
2544         case HIF_SLEEP_REQ:
2545                 netdev_info(dev, "HIF_SLEEP_REQ\n");
2546                 break;
2547         case HIF_SLEEP_CONF:
2548                 netdev_info(dev, "HIF_SLEEP_CONF\n");
2549                 break;
2550         case HIF_PHY_INFO_IND:
2551                 netdev_info(dev, "HIF_PHY_INFO_IND\n");
2552                 break;
2553         case HIF_SCAN_IND:
2554                 netdev_info(dev, "HIF_SCAN_IND\n");
2555                 break;
2556         case HIF_INFRA_SET2_REQ:
2557                 netdev_info(dev, "HIF_INFRA_SET2_REQ\n");
2558                 break;
2559         case HIF_INFRA_SET2_CONF:
2560                 netdev_info(dev, "HIF_INFRA_SET2_CONF\n");
2561                 break;
2562         case HIF_ADH_SET2_REQ:
2563                 netdev_info(dev, "HIF_ADH_SET2_REQ\n");
2564                 break;
2565         case HIF_ADH_SET2_CONF:
2566                 netdev_info(dev, "HIF_ADH_SET2_CONF\n");
2567         }
2568 }
2569
2570 /* get host command history */
2571 static int ks_wlan_hostt(struct net_device *dev, struct iw_request_info *info,
2572                          __u32 *uwrq, char *extra)
2573 {
2574         int i, event;
2575         struct ks_wlan_private *priv = netdev_priv(dev);
2576
2577         for (i = 63; i >= 0; i--) {
2578                 event =
2579                     priv->hostt.buff[(priv->hostt.qtail - 1 - i) %
2580                                      SME_EVENT_BUFF_SIZE];
2581                 print_hif_event(dev, event);
2582         }
2583         return 0;
2584 }
2585
2586 /* Structures to export the Wireless Handlers */
2587
2588 static const struct iw_priv_args ks_wlan_private_args[] = {
2589 /*{ cmd, set_args, get_args, name[16] } */
2590         {KS_WLAN_GET_FIRM_VERSION, IW_PRIV_TYPE_NONE,
2591          IW_PRIV_TYPE_CHAR | (128 + 1), "GetFirmwareVer"},
2592 #ifdef WPS
2593         {KS_WLAN_SET_WPS_ENABLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2594          IW_PRIV_TYPE_NONE, "SetWPSEnable"},
2595         {KS_WLAN_GET_WPS_ENABLE, IW_PRIV_TYPE_NONE,
2596          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetW"},
2597         {KS_WLAN_SET_WPS_PROBE_REQ, IW_PRIV_TYPE_BYTE | 2047, IW_PRIV_TYPE_NONE,
2598          "SetWPSProbeReq"},
2599 #endif /* WPS */
2600         {KS_WLAN_SET_PREAMBLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2601          IW_PRIV_TYPE_NONE, "SetPreamble"},
2602         {KS_WLAN_GET_PREAMBLE, IW_PRIV_TYPE_NONE,
2603          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPreamble"},
2604         {KS_WLAN_SET_POWER_SAVE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2605          IW_PRIV_TYPE_NONE, "SetPowerSave"},
2606         {KS_WLAN_GET_POWER_SAVE, IW_PRIV_TYPE_NONE,
2607          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPowerSave"},
2608         {KS_WLAN_SET_SCAN_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2609          IW_PRIV_TYPE_NONE, "SetScanType"},
2610         {KS_WLAN_GET_SCAN_TYPE, IW_PRIV_TYPE_NONE,
2611          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetScanType"},
2612         {KS_WLAN_SET_RX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2613          IW_PRIV_TYPE_NONE, "SetRxGain"},
2614         {KS_WLAN_GET_RX_GAIN, IW_PRIV_TYPE_NONE,
2615          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetRxGain"},
2616         {KS_WLAN_HOSTT, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | (128 + 1),
2617          "hostt"},
2618         {KS_WLAN_SET_BEACON_LOST, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2619          IW_PRIV_TYPE_NONE, "SetBeaconLost"},
2620         {KS_WLAN_GET_BEACON_LOST, IW_PRIV_TYPE_NONE,
2621          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetBeaconLost"},
2622         {KS_WLAN_SET_SLEEP_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2623          IW_PRIV_TYPE_NONE, "SetSleepMode"},
2624         {KS_WLAN_GET_SLEEP_MODE, IW_PRIV_TYPE_NONE,
2625          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetSleepMode"},
2626         {KS_WLAN_SET_TX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2627          IW_PRIV_TYPE_NONE, "SetTxGain"},
2628         {KS_WLAN_GET_TX_GAIN, IW_PRIV_TYPE_NONE,
2629          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetTxGain"},
2630         {KS_WLAN_SET_PHY_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2631          IW_PRIV_TYPE_NONE, "SetPhyType"},
2632         {KS_WLAN_GET_PHY_TYPE, IW_PRIV_TYPE_NONE,
2633          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPhyType"},
2634         {KS_WLAN_SET_CTS_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2635          IW_PRIV_TYPE_NONE, "SetCtsMode"},
2636         {KS_WLAN_GET_CTS_MODE, IW_PRIV_TYPE_NONE,
2637          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetCtsMode"},
2638         {KS_WLAN_GET_EEPROM_CKSUM, IW_PRIV_TYPE_NONE,
2639          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetChecksum"},
2640 };
2641
2642 static const iw_handler ks_wlan_handler[] = {
2643         (iw_handler)ks_wlan_config_commit,      /* SIOCSIWCOMMIT */
2644         (iw_handler)ks_wlan_get_name,   /* SIOCGIWNAME */
2645         (iw_handler)NULL,       /* SIOCSIWNWID */
2646         (iw_handler)NULL,       /* SIOCGIWNWID */
2647         (iw_handler)ks_wlan_set_freq,   /* SIOCSIWFREQ */
2648         (iw_handler)ks_wlan_get_freq,   /* SIOCGIWFREQ */
2649         (iw_handler)ks_wlan_set_mode,   /* SIOCSIWMODE */
2650         (iw_handler)ks_wlan_get_mode,   /* SIOCGIWMODE */
2651 #ifndef KSC_OPNOTSUPP
2652         (iw_handler)ks_wlan_set_sens,   /* SIOCSIWSENS */
2653         (iw_handler)ks_wlan_get_sens,   /* SIOCGIWSENS */
2654 #else /* KSC_OPNOTSUPP */
2655         (iw_handler)NULL,       /* SIOCSIWSENS */
2656         (iw_handler)NULL,       /* SIOCGIWSENS */
2657 #endif /* KSC_OPNOTSUPP */
2658         (iw_handler)NULL,       /* SIOCSIWRANGE */
2659         (iw_handler)ks_wlan_get_range,  /* SIOCGIWRANGE */
2660         (iw_handler)NULL,       /* SIOCSIWPRIV */
2661         (iw_handler)NULL,       /* SIOCGIWPRIV */
2662         (iw_handler)NULL,       /* SIOCSIWSTATS */
2663         (iw_handler)ks_wlan_get_iwstats,        /* SIOCGIWSTATS */
2664         (iw_handler)NULL,       /* SIOCSIWSPY */
2665         (iw_handler)NULL,       /* SIOCGIWSPY */
2666         (iw_handler)NULL,       /* SIOCSIWTHRSPY */
2667         (iw_handler)NULL,       /* SIOCGIWTHRSPY */
2668         (iw_handler)ks_wlan_set_wap,    /* SIOCSIWAP */
2669         (iw_handler)ks_wlan_get_wap,    /* SIOCGIWAP */
2670 //      (iw_handler)NULL,                      /* SIOCSIWMLME */
2671         (iw_handler)ks_wlan_set_mlme,   /* SIOCSIWMLME */
2672         (iw_handler)ks_wlan_get_aplist, /* SIOCGIWAPLIST */
2673         (iw_handler)ks_wlan_set_scan,   /* SIOCSIWSCAN */
2674         (iw_handler)ks_wlan_get_scan,   /* SIOCGIWSCAN */
2675         (iw_handler)ks_wlan_set_essid,  /* SIOCSIWESSID */
2676         (iw_handler)ks_wlan_get_essid,  /* SIOCGIWESSID */
2677         (iw_handler)ks_wlan_set_nick,   /* SIOCSIWNICKN */
2678         (iw_handler)ks_wlan_get_nick,   /* SIOCGIWNICKN */
2679         (iw_handler)NULL,       /* -- hole -- */
2680         (iw_handler)NULL,       /* -- hole -- */
2681         (iw_handler)ks_wlan_set_rate,   /* SIOCSIWRATE */
2682         (iw_handler)ks_wlan_get_rate,   /* SIOCGIWRATE */
2683         (iw_handler)ks_wlan_set_rts,    /* SIOCSIWRTS */
2684         (iw_handler)ks_wlan_get_rts,    /* SIOCGIWRTS */
2685         (iw_handler)ks_wlan_set_frag,   /* SIOCSIWFRAG */
2686         (iw_handler)ks_wlan_get_frag,   /* SIOCGIWFRAG */
2687 #ifndef KSC_OPNOTSUPP
2688         (iw_handler)ks_wlan_set_txpow,  /* SIOCSIWTXPOW */
2689         (iw_handler)ks_wlan_get_txpow,  /* SIOCGIWTXPOW */
2690         (iw_handler)ks_wlan_set_retry,  /* SIOCSIWRETRY */
2691         (iw_handler)ks_wlan_get_retry,  /* SIOCGIWRETRY */
2692 #else /* KSC_OPNOTSUPP */
2693         (iw_handler)NULL,       /* SIOCSIWTXPOW */
2694         (iw_handler)NULL,       /* SIOCGIWTXPOW */
2695         (iw_handler)NULL,       /* SIOCSIWRETRY */
2696         (iw_handler)NULL,       /* SIOCGIWRETRY */
2697 #endif /* KSC_OPNOTSUPP */
2698         (iw_handler)ks_wlan_set_encode, /* SIOCSIWENCODE */
2699         (iw_handler)ks_wlan_get_encode, /* SIOCGIWENCODE */
2700         (iw_handler)ks_wlan_set_power,  /* SIOCSIWPOWER */
2701         (iw_handler)ks_wlan_get_power,  /* SIOCGIWPOWER */
2702         (iw_handler)NULL,       /* -- hole -- */
2703         (iw_handler)NULL,       /* -- hole -- */
2704 //      (iw_handler)NULL,                      /* SIOCSIWGENIE */
2705         (iw_handler)ks_wlan_set_genie,  /* SIOCSIWGENIE */
2706         (iw_handler)NULL,       /* SIOCGIWGENIE */
2707         (iw_handler)ks_wlan_set_auth_mode,      /* SIOCSIWAUTH */
2708         (iw_handler)ks_wlan_get_auth_mode,      /* SIOCGIWAUTH */
2709         (iw_handler)ks_wlan_set_encode_ext,     /* SIOCSIWENCODEEXT */
2710         (iw_handler)ks_wlan_get_encode_ext,     /* SIOCGIWENCODEEXT */
2711         (iw_handler)ks_wlan_set_pmksa,  /* SIOCSIWPMKSA */
2712         (iw_handler)NULL,       /* -- hole -- */
2713 };
2714
2715 /* private_handler */
2716 static const iw_handler ks_wlan_private_handler[] = {
2717         (iw_handler)NULL,       /*  0 */
2718         (iw_handler)NULL,       /*  1, used to be: KS_WLAN_GET_DRIVER_VERSION */
2719         (iw_handler)NULL,       /*  2 */
2720         (iw_handler)ks_wlan_get_firmware_version,       /*  3 KS_WLAN_GET_FIRM_VERSION */
2721 #ifdef WPS
2722         (iw_handler)ks_wlan_set_wps_enable,     /*  4 KS_WLAN_SET_WPS_ENABLE  */
2723         (iw_handler)ks_wlan_get_wps_enable,     /*  5 KS_WLAN_GET_WPS_ENABLE  */
2724         (iw_handler)ks_wlan_set_wps_probe_req,  /*  6 KS_WLAN_SET_WPS_PROBE_REQ */
2725 #else
2726         (iw_handler)NULL,       /*  4 */
2727         (iw_handler)NULL,       /*  5 */
2728         (iw_handler)NULL,       /*  6 */
2729 #endif /* WPS */
2730
2731         (iw_handler)ks_wlan_get_eeprom_cksum,   /*  7 KS_WLAN_GET_CONNECT */
2732         (iw_handler)ks_wlan_set_preamble,       /*  8 KS_WLAN_SET_PREAMBLE */
2733         (iw_handler)ks_wlan_get_preamble,       /*  9 KS_WLAN_GET_PREAMBLE */
2734         (iw_handler)ks_wlan_set_power_mgmt,     /* 10 KS_WLAN_SET_POWER_SAVE */
2735         (iw_handler)ks_wlan_get_power_mgmt,     /* 11 KS_WLAN_GET_POWER_SAVE */
2736         (iw_handler)ks_wlan_set_scan_type,      /* 12 KS_WLAN_SET_SCAN_TYPE */
2737         (iw_handler)ks_wlan_get_scan_type,      /* 13 KS_WLAN_GET_SCAN_TYPE */
2738         (iw_handler)ks_wlan_set_rx_gain,        /* 14 KS_WLAN_SET_RX_GAIN */
2739         (iw_handler)ks_wlan_get_rx_gain,        /* 15 KS_WLAN_GET_RX_GAIN */
2740         (iw_handler)ks_wlan_hostt,      /* 16 KS_WLAN_HOSTT */
2741         (iw_handler)NULL,       /* 17 */
2742         (iw_handler)ks_wlan_set_beacon_lost,    /* 18 KS_WLAN_SET_BECAN_LOST */
2743         (iw_handler)ks_wlan_get_beacon_lost,    /* 19 KS_WLAN_GET_BECAN_LOST */
2744         (iw_handler)ks_wlan_set_tx_gain,        /* 20 KS_WLAN_SET_TX_GAIN */
2745         (iw_handler)ks_wlan_get_tx_gain,        /* 21 KS_WLAN_GET_TX_GAIN */
2746         (iw_handler)ks_wlan_set_phy_type,       /* 22 KS_WLAN_SET_PHY_TYPE */
2747         (iw_handler)ks_wlan_get_phy_type,       /* 23 KS_WLAN_GET_PHY_TYPE */
2748         (iw_handler)ks_wlan_set_cts_mode,       /* 24 KS_WLAN_SET_CTS_MODE */
2749         (iw_handler)ks_wlan_get_cts_mode,       /* 25 KS_WLAN_GET_CTS_MODE */
2750         (iw_handler)NULL,       /* 26 */
2751         (iw_handler)NULL,       /* 27 */
2752         (iw_handler)ks_wlan_set_sleep_mode,     /* 28 KS_WLAN_SET_SLEEP_MODE */
2753         (iw_handler)ks_wlan_get_sleep_mode,     /* 29 KS_WLAN_GET_SLEEP_MODE */
2754         (iw_handler)NULL,       /* 30 */
2755         (iw_handler)NULL,       /* 31 */
2756 };
2757
2758 static const struct iw_handler_def ks_wlan_handler_def = {
2759         .num_standard = sizeof(ks_wlan_handler) / sizeof(iw_handler),
2760         .num_private = sizeof(ks_wlan_private_handler) / sizeof(iw_handler),
2761         .num_private_args =
2762             sizeof(ks_wlan_private_args) / sizeof(struct iw_priv_args),
2763         .standard = (iw_handler *)ks_wlan_handler,
2764         .private = (iw_handler *)ks_wlan_private_handler,
2765         .private_args = (struct iw_priv_args *)ks_wlan_private_args,
2766         .get_wireless_stats = ks_get_wireless_stats,
2767 };
2768
2769 static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq,
2770                                 int cmd)
2771 {
2772         int ret;
2773         struct iwreq *wrq = (struct iwreq *)rq;
2774
2775         switch (cmd) {
2776         case SIOCIWFIRSTPRIV + 20:      /* KS_WLAN_SET_STOP_REQ */
2777                 ret = ks_wlan_set_stop_request(dev, NULL, &wrq->u.mode, NULL);
2778                 break;
2779                 // All other calls are currently unsupported
2780         default:
2781                 ret = -EOPNOTSUPP;
2782         }
2783
2784         DPRINTK(5, "return=%d\n", ret);
2785         return ret;
2786 }
2787
2788 static
2789 struct net_device_stats *ks_wlan_get_stats(struct net_device *dev)
2790 {
2791         struct ks_wlan_private *priv = netdev_priv(dev);
2792
2793         if (priv->dev_state < DEVICE_STATE_READY)
2794                 return NULL;    /* not finished initialize */
2795
2796         return &priv->nstats;
2797 }
2798
2799 static
2800 int ks_wlan_set_mac_address(struct net_device *dev, void *addr)
2801 {
2802         struct ks_wlan_private *priv = netdev_priv(dev);
2803         struct sockaddr *mac_addr = (struct sockaddr *)addr;
2804
2805         if (netif_running(dev))
2806                 return -EBUSY;
2807         memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
2808         memcpy(priv->eth_addr, mac_addr->sa_data, ETH_ALEN);
2809
2810         priv->mac_address_valid = 0;
2811         hostif_sme_enqueue(priv, SME_MACADDRESS_SET_REQUEST);
2812         netdev_info(dev, "ks_wlan:  MAC ADDRESS = %pM\n", priv->eth_addr);
2813         return 0;
2814 }
2815
2816 static
2817 void ks_wlan_tx_timeout(struct net_device *dev)
2818 {
2819         struct ks_wlan_private *priv = netdev_priv(dev);
2820
2821         DPRINTK(1, "head(%d) tail(%d)!!\n", priv->tx_dev.qhead,
2822                 priv->tx_dev.qtail);
2823         if (!netif_queue_stopped(dev))
2824                 netif_stop_queue(dev);
2825         priv->nstats.tx_errors++;
2826         netif_wake_queue(dev);
2827 }
2828
2829 static
2830 int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev)
2831 {
2832         struct ks_wlan_private *priv = netdev_priv(dev);
2833         int ret;
2834
2835         DPRINTK(3, "in_interrupt()=%ld\n", in_interrupt());
2836
2837         if (!skb) {
2838                 netdev_err(dev, "ks_wlan:  skb == NULL!!!\n");
2839                 return 0;
2840         }
2841         if (priv->dev_state < DEVICE_STATE_READY) {
2842                 dev_kfree_skb(skb);
2843                 return 0;       /* not finished initialize */
2844         }
2845
2846         if (netif_running(dev))
2847                 netif_stop_queue(dev);
2848
2849         ret = hostif_data_request(priv, skb);
2850         netif_trans_update(dev);
2851
2852         if (ret)
2853                 DPRINTK(4, "hostif_data_request error: =%d\n", ret);
2854
2855         return 0;
2856 }
2857
2858 void send_packet_complete(struct ks_wlan_private *priv, struct sk_buff *skb)
2859 {
2860         DPRINTK(3, "\n");
2861
2862         priv->nstats.tx_packets++;
2863
2864         if (netif_queue_stopped(priv->net_dev))
2865                 netif_wake_queue(priv->net_dev);
2866
2867         if (skb) {
2868                 priv->nstats.tx_bytes += skb->len;
2869                 dev_kfree_skb(skb);
2870         }
2871 }
2872
2873 /*
2874  * Set or clear the multicast filter for this adaptor.
2875  * This routine is not state sensitive and need not be SMP locked.
2876  */
2877 static
2878 void ks_wlan_set_multicast_list(struct net_device *dev)
2879 {
2880         struct ks_wlan_private *priv = netdev_priv(dev);
2881
2882         DPRINTK(4, "\n");
2883         if (priv->dev_state < DEVICE_STATE_READY)
2884                 return; /* not finished initialize */
2885         hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST);
2886 }
2887
2888 static
2889 int ks_wlan_open(struct net_device *dev)
2890 {
2891         struct ks_wlan_private *priv = netdev_priv(dev);
2892
2893         priv->cur_rx = 0;
2894
2895         if (!priv->mac_address_valid) {
2896                 netdev_err(dev, "ks_wlan : %s Not READY !!\n", dev->name);
2897                 return -EBUSY;
2898         }
2899         netif_start_queue(dev);
2900
2901         return 0;
2902 }
2903
2904 static
2905 int ks_wlan_close(struct net_device *dev)
2906 {
2907         netif_stop_queue(dev);
2908
2909         DPRINTK(4, "%s: Shutting down ethercard, status was 0x%4.4x.\n",
2910                 dev->name, 0x00);
2911
2912         return 0;
2913 }
2914
2915 /* Operational parameters that usually are not changed. */
2916 /* Time in jiffies before concluding the transmitter is hung. */
2917 #define TX_TIMEOUT  (3 * HZ)
2918 static const unsigned char dummy_addr[] = {
2919         0x00, 0x0b, 0xe3, 0x00, 0x00, 0x00
2920 };
2921
2922 static const struct net_device_ops ks_wlan_netdev_ops = {
2923         .ndo_start_xmit = ks_wlan_start_xmit,
2924         .ndo_open = ks_wlan_open,
2925         .ndo_stop = ks_wlan_close,
2926         .ndo_do_ioctl = ks_wlan_netdev_ioctl,
2927         .ndo_set_mac_address = ks_wlan_set_mac_address,
2928         .ndo_get_stats = ks_wlan_get_stats,
2929         .ndo_tx_timeout = ks_wlan_tx_timeout,
2930         .ndo_set_rx_mode = ks_wlan_set_multicast_list,
2931 };
2932
2933 int ks_wlan_net_start(struct net_device *dev)
2934 {
2935         struct ks_wlan_private *priv;
2936         /* int rc; */
2937
2938         priv = netdev_priv(dev);
2939         priv->mac_address_valid = 0;
2940         priv->need_commit = 0;
2941
2942         priv->device_open_status = 1;
2943
2944         /* phy information update timer */
2945         atomic_set(&update_phyinfo, 0);
2946         setup_timer(&update_phyinfo_timer, ks_wlan_update_phyinfo_timeout,
2947                     (unsigned long)priv);
2948
2949         /* dummy address set */
2950         memcpy(priv->eth_addr, dummy_addr, ETH_ALEN);
2951         dev->dev_addr[0] = priv->eth_addr[0];
2952         dev->dev_addr[1] = priv->eth_addr[1];
2953         dev->dev_addr[2] = priv->eth_addr[2];
2954         dev->dev_addr[3] = priv->eth_addr[3];
2955         dev->dev_addr[4] = priv->eth_addr[4];
2956         dev->dev_addr[5] = priv->eth_addr[5];
2957         dev->dev_addr[6] = 0x00;
2958         dev->dev_addr[7] = 0x00;
2959
2960         /* The ks_wlan-specific entries in the device structure. */
2961         dev->netdev_ops = &ks_wlan_netdev_ops;
2962         dev->wireless_handlers = (struct iw_handler_def *)&ks_wlan_handler_def;
2963         dev->watchdog_timeo = TX_TIMEOUT;
2964
2965         netif_carrier_off(dev);
2966
2967         return 0;
2968 }
2969
2970 int ks_wlan_net_stop(struct net_device *dev)
2971 {
2972         struct ks_wlan_private *priv = netdev_priv(dev);
2973
2974         priv->device_open_status = 0;
2975         del_timer_sync(&update_phyinfo_timer);
2976
2977         if (netif_running(dev))
2978                 netif_stop_queue(dev);
2979
2980         return 0;
2981 }
2982
2983 /**
2984  * is_connect_status() - return true if status is 'connected'
2985  * @status: high bit is used as FORCE_DISCONNECT, low bits used for
2986  *      connect status.
2987  */
2988 bool is_connect_status(u32 status)
2989 {
2990         return (status & CONNECT_STATUS_MASK) == CONNECT_STATUS;
2991 }
2992
2993 /**
2994  * is_disconnect_status() - return true if status is 'disconnected'
2995  * @status: high bit is used as FORCE_DISCONNECT, low bits used for
2996  *      disconnect status.
2997  */
2998 bool is_disconnect_status(u32 status)
2999 {
3000         return (status & CONNECT_STATUS_MASK) == DISCONNECT_STATUS;
3001 }