Staging: vt6655 textual cleanup in prep for driver merge
[safe/jmp/linux-2.6] / drivers / staging / vt6655 / iwctl.c
1 /*
2  * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3  * All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * File: iwctl.c
20  *
21  * Purpose:  wireless ext & ioctl functions
22  *
23  * Author: Lyndon Chen
24  *
25  * Date: July 5, 2006
26  *
27  * Functions:
28  *
29  * Revision History:
30  *
31  */
32
33
34 #if !defined(__DEVICE_H__)
35 #include "device.h"
36 #endif
37 #if !defined(__IOCTL_H__)
38 #include "ioctl.h"
39 #endif
40 #if !defined(__IOCMD_H__)
41 #include "iocmd.h"
42 #endif
43 #if !defined(__MAC_H__)
44 #include "mac.h"
45 #endif
46 #if !defined(__CARD_H__)
47 #include "card.h"
48 #endif
49 #if !defined(__HOSTAP_H__)
50 #include "hostap.h"
51 #endif
52 #if !defined(__UMEM_H__)
53 #include "umem.h"
54 #endif
55 #if !defined(__POWER_H__)
56 #include "power.h"
57 #endif
58 #if !defined(__RF_H__)
59 #include "rf.h"
60 #endif
61
62 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
63 #if !defined(__IOWPA_H__)
64 #include "iowpa.h"
65 #endif
66 #if !defined(__WPACTL_H__)
67 #include "wpactl.h"
68 #endif
69 #endif
70
71 #include <net/iw_handler.h>
72 extern WORD TxRate_iwconfig;//2008-5-8 <add> by chester
73
74 /*---------------------  Static Definitions -------------------------*/
75
76 //2008-0409-07, <Add> by Einsn Liu
77 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
78 #define SUPPORTED_WIRELESS_EXT                  18
79 #else
80 #define SUPPORTED_WIRELESS_EXT                  17
81 #endif
82
83 static const long frequency_list[] = {
84     2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
85     4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
86     5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210, 5220, 5230, 5240,
87     5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680,
88     5700, 5745, 5765, 5785, 5805, 5825
89         };
90
91
92 /*---------------------  Static Classes  ----------------------------*/
93
94
95 //static int          msglevel                =MSG_LEVEL_DEBUG;
96 static int          msglevel                =MSG_LEVEL_INFO;
97
98
99 /*---------------------  Static Variables  --------------------------*/
100 /*---------------------  Static Functions  --------------------------*/
101
102 /*---------------------  Export Variables  --------------------------*/
103
104 struct iw_statistics *iwctl_get_wireless_stats(struct net_device *dev)
105 {
106         PSDevice pDevice = netdev_priv(dev);
107         long ldBm;
108         pDevice->wstats.status = pDevice->eOPMode;
109         #ifdef Calcu_LinkQual
110          #if 0
111           if(pDevice->byBBType == BB_TYPE_11B) {
112              if(pDevice->byCurrSQ > 120)
113                   pDevice->scStatistic.LinkQuality = 100;
114              else
115                  pDevice->scStatistic.LinkQuality = pDevice->byCurrSQ*100/120;
116             }
117           else if(pDevice->byBBType == BB_TYPE_11G) {
118                 if(pDevice->byCurrSQ < 20)
119                    pDevice->scStatistic.LinkQuality = 100;
120                else if(pDevice->byCurrSQ >96)
121                    pDevice->scStatistic.LinkQuality  = 0;
122                else
123                    pDevice->scStatistic.LinkQuality = (96-pDevice->byCurrSQ)*100/76;
124            }
125            if(pDevice->bLinkPass !=TRUE)
126                pDevice->scStatistic.LinkQuality = 0;
127           #endif
128            if(pDevice->scStatistic.LinkQuality > 100)
129                pDevice->scStatistic.LinkQuality = 100;
130                pDevice->wstats.qual.qual =(BYTE) pDevice->scStatistic.LinkQuality;
131         #else
132         pDevice->wstats.qual.qual = pDevice->byCurrSQ;
133         #endif
134         RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm);
135         pDevice->wstats.qual.level = ldBm;
136         //pDevice->wstats.qual.level = 0x100 - pDevice->uCurrRSSI;
137         pDevice->wstats.qual.noise = 0;
138         pDevice->wstats.qual.updated = 1;
139         pDevice->wstats.discard.nwid = 0;
140         pDevice->wstats.discard.code = 0;
141         pDevice->wstats.discard.fragment = 0;
142         pDevice->wstats.discard.retries = (U32)pDevice->scStatistic.dwTsrErr;
143         pDevice->wstats.discard.misc = 0;
144         pDevice->wstats.miss.beacon = 0;
145
146         return &pDevice->wstats;
147 }
148
149
150
151 /*------------------------------------------------------------------*/
152
153
154 static int iwctl_commit(struct net_device *dev,
155                               struct iw_request_info *info,
156                               void *wrq,
157                               char *extra)
158 {
159     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWCOMMIT \n");
160
161         return 0;
162
163 }
164
165 /*
166  * Wireless Handler : get protocol name
167  */
168
169 int iwctl_giwname(struct net_device *dev,
170                          struct iw_request_info *info,
171                          char *wrq,
172                          char *extra)
173 {
174         strcpy(wrq, "802.11-a/b/g");
175         return 0;
176 }
177
178 int iwctl_giwnwid(struct net_device *dev,
179              struct iw_request_info *info,
180                          struct iw_param *wrq,
181                    char *extra)
182 {
183         //wrq->value = 0x100;
184         //wrq->disabled = 0;
185         //wrq->fixed = 1;
186         //return 0;
187   return -EOPNOTSUPP;
188 }
189
190 /*
191  * Wireless Handler : set scan
192  */
193
194 int iwctl_siwscan(struct net_device *dev,
195              struct iw_request_info *info,
196                          struct iw_point *wrq,
197              char *extra)
198 {
199         PSDevice                pDevice = (PSDevice)netdev_priv(dev);
200                 struct iw_scan_req  *req = (struct iw_scan_req *)extra;
201                  PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
202         BYTE                abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
203         PWLAN_IE_SSID       pItemSSID=NULL;
204     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSCAN \n");
205
206
207 if(pDevice->byReAssocCount > 0) {   //reject scan when re-associating!
208 //send scan event to wpa_Supplicant
209   union iwreq_data wrqu;
210  printk("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
211  memset(&wrqu, 0, sizeof(wrqu));
212  wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
213   return 0;
214 }
215
216         spin_lock_irq(&pDevice->lock);
217            BSSvClearBSSList((HANDLE)pDevice, pDevice->bLinkPass);
218
219 //mike add: active scan OR passive scan OR desire_ssid scan
220  if(wrq->length == sizeof(struct iw_scan_req)) {
221    if (wrq->flags & IW_SCAN_THIS_ESSID)  {                               //desire_ssid scan
222        memset(abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
223        pItemSSID = (PWLAN_IE_SSID)abyScanSSID;
224        pItemSSID->byElementID = WLAN_EID_SSID;
225        memcpy(pItemSSID->abySSID, req->essid, (int)req->essid_len);
226          if (pItemSSID->abySSID[req->essid_len - 1] == '\0') {
227            if(req->essid_len>0)
228                 pItemSSID->len = req->essid_len - 1;
229          }
230         else
231           pItemSSID->len = req->essid_len;
232           pMgmt->eScanType = WMAC_SCAN_PASSIVE;
233          printk("SIOCSIWSCAN:[desired_ssid=%s,len=%d]\n",((PWLAN_IE_SSID)abyScanSSID)->abySSID,
234                                                                                                         ((PWLAN_IE_SSID)abyScanSSID)->len);
235         bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID);
236         spin_unlock_irq(&pDevice->lock);
237
238         return 0;
239    }
240    else if(req->scan_type == IW_SCAN_TYPE_PASSIVE) {          //passive scan
241        pMgmt->eScanType = WMAC_SCAN_PASSIVE;
242    }
243  }
244  else {           //active scan
245      pMgmt->eScanType = WMAC_SCAN_ACTIVE;
246  }
247
248          pMgmt->eScanType = WMAC_SCAN_PASSIVE;
249         bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
250         spin_unlock_irq(&pDevice->lock);
251
252         return 0;
253 }
254
255
256 /*
257  * Wireless Handler : get scan results
258  */
259
260 int iwctl_giwscan(struct net_device *dev,
261              struct iw_request_info *info,
262                          struct iw_point *wrq,
263              char *extra)
264 {
265     int ii, jj, kk;
266         PSDevice                pDevice = (PSDevice)netdev_priv(dev);
267     PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
268     PKnownBSS           pBSS;
269     PWLAN_IE_SSID       pItemSSID;
270     PWLAN_IE_SUPP_RATES pSuppRates, pExtSuppRates;
271         char *current_ev = extra;
272         char *end_buf = extra + IW_SCAN_MAX_DATA;
273         char *current_val = NULL;
274         struct iw_event iwe;
275         long ldBm;
276         char buf[MAX_WPA_IE_LEN * 2 + 30];
277
278
279     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSCAN \n");
280
281     if (pMgmt->eScanState ==  WMAC_IS_SCANNING) {
282         // In scanning..
283                 return -EAGAIN;
284         }
285         pBSS = &(pMgmt->sBSSList[0]);
286     for (ii = 0, jj = 0; jj < MAX_BSS_NUM ; jj++) {
287                 if (current_ev >= end_buf)
288                         break;
289         pBSS = &(pMgmt->sBSSList[jj]);
290         if (pBSS->bActive) {
291                     memset(&iwe, 0, sizeof(iwe));
292                     iwe.cmd = SIOCGIWAP;
293                     iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
294                         memcpy(iwe.u.ap_addr.sa_data, pBSS->abyBSSID, WLAN_BSSID_LEN);
295             current_ev = iwe_stream_add_event(info,current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);
296                  //ADD ssid
297                      memset(&iwe, 0, sizeof(iwe));
298                       iwe.cmd = SIOCGIWESSID;
299                       pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
300                        iwe.u.data.length = pItemSSID->len;
301                        iwe.u.data.flags = 1;
302             current_ev = iwe_stream_add_point(info,current_ev,end_buf, &iwe, pItemSSID->abySSID);
303                 //ADD mode
304                     memset(&iwe, 0, sizeof(iwe));
305                     iwe.cmd = SIOCGIWMODE;
306             if (WLAN_GET_CAP_INFO_ESS(pBSS->wCapInfo)) {
307                         iwe.u.mode = IW_MODE_INFRA;
308             }
309             else {
310                 iwe.u.mode = IW_MODE_ADHOC;
311                     }
312                 iwe.len = IW_EV_UINT_LEN;
313             current_ev = iwe_stream_add_event(info,current_ev, end_buf, &iwe,  IW_EV_UINT_LEN);
314            //ADD frequency
315             pSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abySuppRates;
316             pExtSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abyExtSuppRates;
317             memset(&iwe, 0, sizeof(iwe));
318                 iwe.cmd = SIOCGIWFREQ;
319                 iwe.u.freq.m = pBSS->uChannel;
320                 iwe.u.freq.e = 0;
321                 iwe.u.freq.i = 0;
322             current_ev = iwe_stream_add_event(info,current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
323
324
325             //2008-0409-04, <Add> by Einsn Liu
326                         {
327                         int f = (int)pBSS->uChannel - 1;
328                         if(f < 0)f = 0;
329                         iwe.u.freq.m = frequency_list[f] * 100000;
330                         iwe.u.freq.e = 1;
331                         }
332             current_ev = iwe_stream_add_event(info,current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
333                 //ADD quality
334             memset(&iwe, 0, sizeof(iwe));
335                 iwe.cmd = IWEVQUAL;
336                 RFvRSSITodBm(pDevice, (BYTE)(pBSS->uRSSI), &ldBm);
337                     iwe.u.qual.level = ldBm;
338                 iwe.u.qual.noise = 0;
339 //2008-0409-01, <Add> by Einsn Liu
340                         if(-ldBm<50){
341                                 iwe.u.qual.qual = 100;
342                         }else  if(-ldBm > 90) {
343                                  iwe.u.qual.qual = 0;
344                         }else {
345                                 iwe.u.qual.qual=(40-(-ldBm-50))*100/40;
346                         }
347                         iwe.u.qual.updated=7;
348
349               //  iwe.u.qual.qual = 0;
350             current_ev = iwe_stream_add_event(info,current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
351
352             memset(&iwe, 0, sizeof(iwe));
353             iwe.cmd = SIOCGIWENCODE;
354             iwe.u.data.length = 0;
355             if (WLAN_GET_CAP_INFO_PRIVACY(pBSS->wCapInfo)) {
356                 iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
357             }else {
358                 iwe.u.data.flags = IW_ENCODE_DISABLED;
359             }
360             current_ev = iwe_stream_add_point(info,current_ev,end_buf, &iwe, pItemSSID->abySSID);
361
362             memset(&iwe, 0, sizeof(iwe));
363             iwe.cmd = SIOCGIWRATE;
364                 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
365                 current_val = current_ev + IW_EV_LCP_LEN;
366
367                 for (kk = 0 ; kk < 12 ; kk++) {
368                         if (pSuppRates->abyRates[kk] == 0)
369                                 break;
370                         // Bit rate given in 500 kb/s units (+ 0x80)
371                         iwe.u.bitrate.value = ((pSuppRates->abyRates[kk] & 0x7f) * 500000);
372                 current_val = iwe_stream_add_value(info,current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
373                         }
374                 for (kk = 0 ; kk < 8 ; kk++) {
375                         if (pExtSuppRates->abyRates[kk] == 0)
376                                 break;
377                         // Bit rate given in 500 kb/s units (+ 0x80)
378                         iwe.u.bitrate.value = ((pExtSuppRates->abyRates[kk] & 0x7f) * 500000);
379                 current_val = iwe_stream_add_value(info,current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
380                 }
381
382                 if((current_val - current_ev) > IW_EV_LCP_LEN)
383                         current_ev = current_val;
384
385             memset(&iwe, 0, sizeof(iwe));
386             iwe.cmd = IWEVCUSTOM;
387             sprintf(buf, "bcn_int=%d", pBSS->wBeaconInterval);
388             iwe.u.data.length = strlen(buf);
389             current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, buf);
390
391             if ((pBSS->wWPALen > 0) && (pBSS->wWPALen <= MAX_WPA_IE_LEN)) {
392                 memset(&iwe, 0, sizeof(iwe));
393                 iwe.cmd = IWEVGENIE;
394                 iwe.u.data.length = pBSS->wWPALen;
395                 current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, pBSS->byWPAIE);
396             }
397
398             if ((pBSS->wRSNLen > 0) && (pBSS->wRSNLen <= MAX_WPA_IE_LEN)) {
399                 memset(&iwe, 0, sizeof(iwe));
400                 iwe.cmd = IWEVGENIE;
401                 iwe.u.data.length = pBSS->wRSNLen;
402                 current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, pBSS->byRSNIE);
403             }
404
405         }
406     }// for
407
408         wrq->length = current_ev - extra;
409         return 0;
410
411 }
412
413
414 /*
415  * Wireless Handler : set frequence or channel
416  */
417
418 int iwctl_siwfreq(struct net_device *dev,
419              struct iw_request_info *info,
420              struct iw_freq *wrq,
421              char *extra)
422 {
423         PSDevice                pDevice = (PSDevice)netdev_priv(dev);
424         int rc = 0;
425
426     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFREQ \n");
427
428         // If setting by frequency, convert to a channel
429         if((wrq->e == 1) &&
430            (wrq->m >= (int) 2.412e8) &&
431            (wrq->m <= (int) 2.487e8)) {
432                 int f = wrq->m / 100000;
433                 int c = 0;
434                 while((c < 14) && (f != frequency_list[c]))
435                         c++;
436                 wrq->e = 0;
437                 wrq->m = c + 1;
438         }
439         // Setting by channel number
440         if((wrq->m > 14) || (wrq->e > 0))
441                 rc = -EOPNOTSUPP;
442         else {
443                 int channel = wrq->m;
444                 if((channel < 1) || (channel > 14)) {
445                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: New channel value of %d is invalid!\n", dev->name, wrq->m);
446                         rc = -EINVAL;
447                 } else {
448                           // Yes ! We can set it !!!
449               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Set to channel = %d\n", channel);
450                           pDevice->uChannel = channel;
451                          //2007-0207-04,<Add> by EinsnLiu
452                          //Make change effect at once
453                           pDevice->bCommit = TRUE;
454                 }
455         }
456
457         return rc;
458 }
459
460 /*
461  * Wireless Handler : get frequence or channel
462  */
463
464 int iwctl_giwfreq(struct net_device *dev,
465              struct iw_request_info *info,
466              struct iw_freq *wrq,
467              char *extra)
468 {
469         PSDevice                pDevice = (PSDevice)netdev_priv(dev);
470     PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
471
472     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFREQ \n");
473
474 #ifdef WEXT_USECHANNELS
475         wrq->m = (int)pMgmt->uCurrChannel;
476         wrq->e = 0;
477 #else
478         {
479                 int f = (int)pMgmt->uCurrChannel - 1;
480                 if(f < 0)
481                    f = 0;
482                 wrq->m = frequency_list[f] * 100000;
483                 wrq->e = 1;
484         }
485 #endif
486
487         return 0;
488 }
489
490 /*
491  * Wireless Handler : set operation mode
492  */
493
494 int iwctl_siwmode(struct net_device *dev,
495              struct iw_request_info *info,
496              __u32 *wmode,
497              char *extra)
498 {
499         PSDevice                pDevice = (PSDevice)netdev_priv(dev);
500     PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
501     int rc = 0;
502
503     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMODE \n");
504
505     if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP && pDevice->bEnableHostapd) {
506         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Can't set operation mode, hostapd is running \n");
507         return rc;
508     }
509
510         switch(*wmode) {
511
512         case IW_MODE_ADHOC:
513             if (pMgmt->eConfigMode != WMAC_CONFIG_IBSS_STA) {
514             pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
515             if (pDevice->flags & DEVICE_FLAGS_OPENED) {
516                         pDevice->bCommit = TRUE;
517                     }
518                 }
519         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to ad-hoc \n");
520                 break;
521         case IW_MODE_AUTO:
522         case IW_MODE_INFRA:
523             if (pMgmt->eConfigMode != WMAC_CONFIG_ESS_STA) {
524             pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
525             if (pDevice->flags & DEVICE_FLAGS_OPENED) {
526                         pDevice->bCommit = TRUE;
527                     }
528                 }
529         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to infrastructure \n");
530                 break;
531         case IW_MODE_MASTER:
532
533         pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
534                 rc = -EOPNOTSUPP;
535                 break;
536
537             if (pMgmt->eConfigMode != WMAC_CONFIG_AP) {
538             pMgmt->eConfigMode = WMAC_CONFIG_AP;
539             if (pDevice->flags & DEVICE_FLAGS_OPENED) {
540                         pDevice->bCommit = TRUE;
541                     }
542                 }
543         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to Access Point \n");
544                 break;
545
546         case IW_MODE_REPEAT:
547         pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
548                 rc = -EOPNOTSUPP;
549                 break;
550         default:
551                 rc = -EINVAL;
552         }
553
554         return rc;
555 }
556
557 /*
558  * Wireless Handler : get operation mode
559  */
560
561 int iwctl_giwmode(struct net_device *dev,
562              struct iw_request_info *info,
563              __u32 *wmode,
564              char *extra)
565 {
566         PSDevice                pDevice = (PSDevice)netdev_priv(dev);
567     PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
568
569
570     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWMODE \n");
571         // If not managed, assume it's ad-hoc
572         switch (pMgmt->eConfigMode) {
573         case WMAC_CONFIG_ESS_STA:
574                 *wmode = IW_MODE_INFRA;
575                 break;
576         case WMAC_CONFIG_IBSS_STA:
577         *wmode = IW_MODE_ADHOC;
578                 break;
579         case WMAC_CONFIG_AUTO:
580                 *wmode = IW_MODE_INFRA;
581                 break;
582         case WMAC_CONFIG_AP:
583                 *wmode = IW_MODE_MASTER;
584                 break;
585         default:
586                 *wmode = IW_MODE_ADHOC;
587         }
588
589         return 0;
590 }
591
592
593 /*
594  * Wireless Handler : get capability range
595  */
596
597 int iwctl_giwrange(struct net_device *dev,
598              struct iw_request_info *info,
599              struct iw_point *wrq,
600              char *extra)
601 {
602         struct iw_range *range = (struct iw_range *) extra;
603         int             i,k;
604     BYTE abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
605
606
607     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRANGE \n");
608         if (wrq->pointer) {
609                 wrq->length = sizeof(struct iw_range);
610                 memset(range, 0, sizeof(struct iw_range));
611                 range->min_nwid = 0x0000;
612                 range->max_nwid = 0x0000;
613                 range->num_channels = 14;
614                 // Should be based on cap_rid.country to give only
615                 //  what the current card support
616                 k = 0;
617                 for(i = 0; i < 14; i++) {
618                         range->freq[k].i = i + 1; // List index
619                         range->freq[k].m = frequency_list[i] * 100000;
620                         range->freq[k++].e = 1; // Values in table in MHz -> * 10^5 * 10
621                 }
622                 range->num_frequency = k;
623                 // Hum... Should put the right values there
624              #ifdef Calcu_LinkQual
625                  range->max_qual.qual = 100;
626              #else
627                 range->max_qual.qual = 255;
628              #endif
629                 range->max_qual.level = 0;
630                 range->max_qual.noise = 0;
631                 range->sensitivity = 255;
632
633                 for(i = 0 ; i < 13 ; i++) {
634                         range->bitrate[i] = abySupportedRates[i] * 500000;
635                         if(range->bitrate[i] == 0)
636                                 break;
637                 }
638                 range->num_bitrates = i;
639
640                 // Set an indication of the max TCP throughput
641                 // in bit/s that we can expect using this interface.
642                 //  May be use for QoS stuff... Jean II
643                 if(i > 2)
644                         range->throughput = 5 * 1000 * 1000;
645                 else
646                         range->throughput = 1.5 * 1000 * 1000;
647
648                 range->min_rts = 0;
649                 range->max_rts = 2312;
650                 range->min_frag = 256;
651                 range->max_frag = 2312;
652
653
654             // the encoding capabilities
655             range->num_encoding_sizes = 3;
656             // 64(40) bits WEP
657             range->encoding_size[0] = 5;
658             // 128(104) bits WEP
659             range->encoding_size[1] = 13;
660             // 256 bits for WPA-PSK
661             range->encoding_size[2] = 32;
662             // 4 keys are allowed
663             range->max_encoding_tokens = 4;
664
665             range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
666                     IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
667
668                 range->min_pmp = 0;
669                 range->max_pmp = 1000000;// 1 secs
670                 range->min_pmt = 0;
671                 range->max_pmt = 1000000;// 1 secs
672                 range->pmp_flags = IW_POWER_PERIOD;
673                 range->pmt_flags = IW_POWER_TIMEOUT;
674                 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
675
676                 // Transmit Power - values are in mW
677
678         range->txpower[0] = 100;
679                 range->num_txpower = 1;
680                 range->txpower_capa = IW_TXPOW_MWATT;
681                 range->we_version_source = SUPPORTED_WIRELESS_EXT;
682                 range->we_version_compiled = WIRELESS_EXT;
683                 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
684                 range->retry_flags = IW_RETRY_LIMIT;
685                 range->r_time_flags = IW_RETRY_LIFETIME;
686                 range->min_retry = 1;
687                 range->max_retry = 65535;
688                 range->min_r_time = 1024;
689                 range->max_r_time = 65535 * 1024;
690                 // Experimental measurements - boundary 11/5.5 Mb/s
691                 // Note : with or without the (local->rssi), results
692                 //  are somewhat different. - Jean II
693                 range->avg_qual.qual = 6;
694                 range->avg_qual.level = 176;    // -80 dBm
695                 range->avg_qual.noise = 0;
696         }
697
698
699         return 0;
700 }
701
702
703 /*
704  * Wireless Handler : set ap mac address
705  */
706
707 int iwctl_siwap(struct net_device *dev,
708              struct iw_request_info *info,
709                          struct sockaddr *wrq,
710              char *extra)
711 {
712         PSDevice                pDevice = (PSDevice)netdev_priv(dev);
713     PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
714     int rc = 0;
715         BYTE                 ZeroBSSID[WLAN_BSSID_LEN]={0x00,0x00,0x00,0x00,0x00,0x00};
716
717     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAP \n");
718 if (pMgmt->eScanState ==  WMAC_IS_SCANNING) {
719         // In scanning..
720      printk("SIOCSIWAP(??)-->In scanning...\n");
721    //  return -EAGAIN;
722   }
723         if (wrq->sa_family != ARPHRD_ETHER)
724                 rc = -EINVAL;
725         else {
726                 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
727                 memcpy(pMgmt->abyDesireBSSID, wrq->sa_data, 6);
728                                 //2008-0409-05, <Add> by Einsn Liu
729                 if((pDevice->bLinkPass == TRUE) &&
730                      (memcmp(pMgmt->abyDesireBSSID, pMgmt->abyCurrBSSID, 6)== 0)){
731                         return rc;
732                         }
733         //mike :add
734          if ((IS_BROADCAST_ADDRESS(pMgmt->abyDesireBSSID)) ||
735              (memcmp(pMgmt->abyDesireBSSID, ZeroBSSID, 6) == 0)){
736               printk("SIOCSIWAP:invalid desired BSSID return!\n");
737                return rc;
738          }
739        //mike add: if desired AP is hidden ssid(there are two same BSSID in list),
740        //                  then ignore,because you don't known which one to be connect with??
741         {
742            UINT            ii , uSameBssidNum=0;
743                   for (ii = 0; ii < MAX_BSS_NUM; ii++) {
744                      if (pMgmt->sBSSList[ii].bActive &&
745                         IS_ETH_ADDRESS_EQUAL(pMgmt->sBSSList[ii].abyBSSID,pMgmt->abyDesireBSSID)) {
746                         uSameBssidNum++;
747                      }
748                   }
749              if(uSameBssidNum >= 2) {  //hit: desired AP is in hidden ssid mode!!!
750                  printk("SIOCSIWAP:ignore for desired AP in hidden mode\n");
751                 return rc;
752              }
753         }
754         if (pDevice->flags & DEVICE_FLAGS_OPENED) {
755                     pDevice->bCommit = TRUE;
756                 }
757         }
758         return rc;
759 }
760
761 /*
762  * Wireless Handler : get ap mac address
763  */
764
765 int iwctl_giwap(struct net_device *dev,
766              struct iw_request_info *info,
767                          struct sockaddr *wrq,
768              char *extra)
769 {
770         PSDevice                pDevice = (PSDevice)netdev_priv(dev);
771     PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
772
773
774     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAP \n");
775
776     memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
777    //2008-0410,<Modify> by Einsn Liu
778     if ((pDevice->bLinkPass == FALSE) && (pMgmt->eCurrMode != WMAC_MODE_ESS_AP))
779         memset(wrq->sa_data, 0, 6);
780
781     if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
782         memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
783     }
784
785         wrq->sa_family = ARPHRD_ETHER;
786
787         return 0;
788
789 }
790
791
792 /*
793  * Wireless Handler : get ap list
794  */
795
796 int iwctl_giwaplist(struct net_device *dev,
797              struct iw_request_info *info,
798              struct iw_point *wrq,
799              char *extra)
800 {
801         int ii,jj, rc = 0;
802         struct sockaddr sock[IW_MAX_AP];
803         struct iw_quality qual[IW_MAX_AP];
804         PSDevice                pDevice = (PSDevice)netdev_priv(dev);
805     PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
806
807
808     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAPLIST \n");
809         // Only super-user can see AP list
810
811         if (!capable(CAP_NET_ADMIN)) {
812                 rc = -EPERM;
813                 return rc;
814         }
815
816         if (wrq->pointer) {
817
818                 PKnownBSS pBSS = &(pMgmt->sBSSList[0]);
819
820                 for (ii = 0, jj= 0; ii < MAX_BSS_NUM; ii++) {
821                     pBSS = &(pMgmt->sBSSList[ii]);
822             if (!pBSS->bActive)
823                 continue;
824             if ( jj >= IW_MAX_AP)
825                 break;
826                         memcpy(sock[jj].sa_data, pBSS->abyBSSID, 6);
827                         sock[jj].sa_family = ARPHRD_ETHER;
828                         qual[jj].level = pBSS->uRSSI;
829                         qual[jj].qual = qual[jj].noise = 0;
830                         qual[jj].updated = 2;
831                         jj++;
832                 }
833
834                 wrq->flags = 1; // Should be define'd
835                 wrq->length = jj;
836                 memcpy(extra, sock, sizeof(struct sockaddr)*jj);
837                 memcpy(extra + sizeof(struct sockaddr)*jj, qual, sizeof(struct iw_quality)*jj);
838         }
839
840         return rc;
841 }
842
843
844 /*
845  * Wireless Handler : set essid
846  */
847
848 int iwctl_siwessid(struct net_device *dev,
849              struct iw_request_info *info,
850              struct iw_point *wrq,
851              char *extra)
852 {
853         PSDevice                pDevice = (PSDevice)netdev_priv(dev);
854     PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
855     PWLAN_IE_SSID       pItemSSID;
856   //2008-0409-05, <Add> by Einsn Liu
857     BYTE  len;
858
859
860     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWESSID \n");
861  pDevice->fWPA_Authened = FALSE;
862 if (pMgmt->eScanState ==  WMAC_IS_SCANNING) {
863         // In scanning..
864      printk("SIOCSIWESSID(??)-->In scanning...\n");
865    //  return -EAGAIN;
866   }
867         // Check if we asked for `any'
868         if(wrq->flags == 0) {
869                 // Just send an empty SSID list
870                 // Just send an empty SSID list
871                 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
872                   memset(pMgmt->abyDesireBSSID, 0xFF,6);
873             printk("set essid to 'any' \n");
874            #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
875              //Unknown desired AP,so here need not associate??
876             //if(pDevice->bWPASuppWextEnabled == TRUE)  {
877                   return 0;
878             // }
879             #endif
880         } else {
881                 // Set the SSID
882                 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
883         pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
884         pItemSSID->byElementID = WLAN_EID_SSID;
885                 memcpy(pItemSSID->abySSID, extra, wrq->length);
886                          if (pItemSSID->abySSID[wrq->length - 1] == '\0') {
887            if(wrq->length>0)
888                 pItemSSID->len = wrq->length - 1;
889          }
890         else
891           pItemSSID->len = wrq->length;
892         printk("set essid to %s \n",pItemSSID->abySSID);
893                 //2008-0409-05, <Add> by Einsn Liu
894        len=(pItemSSID->len > ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len)?pItemSSID->len:((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len;
895    if((pDevice->bLinkPass == TRUE) &&
896         (memcmp(pItemSSID->abySSID,((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,len)==0))
897          return 0;
898
899         //mike:need clear desiredBSSID
900      if(pItemSSID->len==0) {
901         memset(pMgmt->abyDesireBSSID, 0xFF,6);
902         return 0;
903      }
904
905 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
906  //Wext wil order another command of siwap to link with desired AP,
907  //so here need not associate??
908   if(pDevice->bWPASuppWextEnabled == TRUE)  {
909         /*******search if  in hidden ssid mode ****/
910         {
911            PKnownBSS       pCurr = NULL;
912            BYTE                   abyTmpDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
913           UINT            ii , uSameBssidNum=0;
914
915           memset(abyTmpDesireSSID,0,sizeof(abyTmpDesireSSID));
916           memcpy(abyTmpDesireSSID,pMgmt->abyDesireSSID,sizeof(abyTmpDesireSSID));
917             pCurr = BSSpSearchBSSList(pDevice,
918                                       NULL,
919                                       abyTmpDesireSSID,
920                                       pMgmt->eConfigPHYMode
921                                       );
922
923             if (pCurr == NULL){
924                printk("SIOCSIWESSID:hidden ssid site survey before associate.......\n");
925               vResetCommandTimer((HANDLE) pDevice);
926               pMgmt->eScanType = WMAC_SCAN_ACTIVE;
927                bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
928               bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
929           }
930          else {  //mike:to find out if that desired SSID is a hidden-ssid AP ,
931                      //         by means of judging if there are two same BSSID exist in list ?
932                   for (ii = 0; ii < MAX_BSS_NUM; ii++) {
933                      if (pMgmt->sBSSList[ii].bActive &&
934                         IS_ETH_ADDRESS_EQUAL(pMgmt->sBSSList[ii].abyBSSID, pCurr->abyBSSID)) {
935                         uSameBssidNum++;
936                      }
937                   }
938              if(uSameBssidNum >= 2) {  //hit: desired AP is in hidden ssid mode!!!
939                  printk("SIOCSIWESSID:hidden ssid directly associate.......\n");
940                 vResetCommandTimer((HANDLE) pDevice);
941                 pMgmt->eScanType = WMAC_SCAN_PASSIVE;          //this scan type,you'll submit scan result!
942                 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
943                 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
944              }
945          }
946         }
947      return 0;
948   }
949              #endif
950
951             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set essid = %s \n", pItemSSID->abySSID);
952 /*
953  DBG_PRT(MSG_LEVEL_INFO, KERN_INFO " SIOCSIWESSID2 \n");
954                 pItemSSID->len = wrq->length;
955              */
956         }
957
958     if (pDevice->flags & DEVICE_FLAGS_OPENED) {
959             pDevice->bCommit = TRUE;
960         }
961
962
963         return 0;
964 }
965
966
967 /*
968  * Wireless Handler : get essid
969  */
970
971 int iwctl_giwessid(struct net_device *dev,
972              struct iw_request_info *info,
973              struct iw_point *wrq,
974              char *extra)
975 {
976
977         PSDevice                pDevice = (PSDevice)netdev_priv(dev);
978     PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
979         PWLAN_IE_SSID       pItemSSID;
980
981     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWESSID \n");
982
983         // Note : if wrq->u.data.flags != 0, we should
984         // get the relevant SSID from the SSID list...
985
986         // Get the current SSID
987     pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
988         //pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
989         memcpy(extra, pItemSSID->abySSID , pItemSSID->len);
990         extra[pItemSSID->len] = '\0';
991         wrq->length = pItemSSID->len + 1;
992                 //2008-0409-03, <Add> by Einsn Liu
993         wrq->length = pItemSSID->len;
994         wrq->flags = 1; // active
995
996
997         return 0;
998 }
999
1000 /*
1001  * Wireless Handler : set data rate
1002  */
1003
1004 int iwctl_siwrate(struct net_device *dev,
1005              struct iw_request_info *info,
1006                          struct iw_param *wrq,
1007              char *extra)
1008 {
1009         PSDevice                pDevice = (PSDevice)netdev_priv(dev);
1010     int rc = 0;
1011         u8      brate = 0;
1012         int     i;
1013         BYTE abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
1014
1015
1016     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRATE \n");
1017     if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
1018         rc = -EINVAL;
1019         return rc;
1020     }
1021
1022         // First : get a valid bit rate value
1023
1024         // Which type of value
1025         if((wrq->value < 13) &&
1026            (wrq->value >= 0)) {
1027                 // Setting by rate index
1028                 // Find value in the magic rate table
1029                 brate = wrq->value;
1030         } else {
1031                 // Setting by frequency value
1032                 u8      normvalue = (u8) (wrq->value/500000);
1033
1034                 // Check if rate is valid
1035                 for(i = 0 ; i < 13 ; i++) {
1036                         if(normvalue == abySupportedRates[i]) {
1037                                 brate = i;
1038                                 break;
1039                         }
1040                 }
1041         }
1042         // -1 designed the max rate (mostly auto mode)
1043         if(wrq->value == -1) {
1044                 // Get the highest available rate
1045                 for(i = 0 ; i < 13 ; i++) {
1046                         if(abySupportedRates[i] == 0)
1047                                 break;
1048                 }
1049                 if(i != 0)
1050                         brate = i - 1;
1051
1052         }
1053         // Check that it is valid
1054         // brate is index of abySupportedRates[]
1055         if(brate > 13 ) {
1056                 rc = -EINVAL;
1057                 return rc;
1058         }
1059
1060         // Now, check if we want a fixed or auto value
1061         if(wrq->fixed != 0) {
1062                 // Fixed mode
1063                 // One rate, fixed
1064         printk("Rate Fix\n");
1065                 pDevice->bFixRate = TRUE;
1066         if ((pDevice->byBBType == BB_TYPE_11B)&& (brate > 3)) {
1067
1068                         pDevice->uConnectionRate = 3;
1069         }
1070         else {
1071             pDevice->uConnectionRate = brate;
1072             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fixed to Rate %d \n", pDevice->uConnectionRate);
1073         }
1074
1075         }
1076         else {
1077         pDevice->bFixRate = FALSE;
1078         pDevice->uConnectionRate = 13;
1079         printk("auto rate:connection_rate is 13\n");
1080 }
1081
1082         return rc;
1083 }
1084
1085 /*
1086  * Wireless Handler : get data rate
1087  */
1088
1089 int iwctl_giwrate(struct net_device *dev,
1090              struct iw_request_info *info,
1091              struct iw_param *wrq,
1092              char *extra)
1093 {
1094         PSDevice                pDevice = (PSDevice)netdev_priv(dev);
1095 //2007-0118-05,<Mark> by EinsnLiu
1096 //Mark the unnecessary sentences.
1097 //    PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
1098
1099     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRATE \n");
1100     {
1101         BYTE abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
1102             int brate = 0;
1103 //2008-5-8 <modify> by chester
1104 if(pDevice->bLinkPass){
1105 if(pDevice->bFixRate == TRUE){
1106                 if (pDevice->uConnectionRate < 13) {
1107                 brate = abySupportedRates[pDevice->uConnectionRate];
1108             }else {
1109             if (pDevice->byBBType == BB_TYPE_11B)
1110                     brate = 0x16;
1111             if (pDevice->byBBType == BB_TYPE_11G)
1112                     brate = 0x6C;
1113             if (pDevice->byBBType == BB_TYPE_11A)
1114                     brate = 0x6C;
1115             }
1116 }
1117 else
1118 {
1119
1120  brate = abySupportedRates[TxRate_iwconfig];
1121 }
1122 }
1123 else brate =0;
1124 //2007-0118-05,<Mark> by EinsnLiu
1125 //Mark the unnecessary sentences.
1126 /*
1127             if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1128             if (pDevice->byBBType == BB_TYPE_11B)
1129                     brate = 0x16;
1130             if (pDevice->byBBType == BB_TYPE_11G)
1131                     brate = 0x6C;
1132             if (pDevice->byBBType == BB_TYPE_11A)
1133                     brate = 0x6C;
1134             }
1135 */
1136
1137 //              if (pDevice->uConnectionRate == 13)
1138 //                brate = abySupportedRates[pDevice->wCurrentRate];
1139             wrq->value = brate * 500000;
1140             // If more than one rate, set auto
1141             if (pDevice->bFixRate == TRUE)
1142                 wrq->fixed = TRUE;
1143     }
1144
1145
1146         return 0;
1147 }
1148
1149
1150
1151 /*
1152  * Wireless Handler : set rts threshold
1153  */
1154
1155 int iwctl_siwrts(struct net_device *dev,
1156              struct iw_request_info *info,
1157                          struct iw_param *wrq,
1158              char *extra)
1159 {
1160         PSDevice                pDevice = (PSDevice)netdev_priv(dev);
1161         int rc = 0;
1162
1163     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRTS \n");
1164
1165         {
1166             int rthr = wrq->value;
1167             if(wrq->disabled)
1168                         rthr = 2312;
1169             if((rthr < 0) || (rthr > 2312)) {
1170                         rc = -EINVAL;
1171         }else {
1172                     pDevice->wRTSThreshold = rthr;
1173             }
1174     }
1175
1176         return 0;
1177 }
1178
1179 /*
1180  * Wireless Handler : get rts
1181  */
1182
1183 int iwctl_giwrts(struct net_device *dev,
1184              struct iw_request_info *info,
1185                          struct iw_param *wrq,
1186              char *extra)
1187 {
1188         PSDevice                pDevice = (PSDevice)netdev_priv(dev);
1189
1190     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRTS \n");
1191         wrq->value = pDevice->wRTSThreshold;
1192         wrq->disabled = (wrq->value >= 2312);
1193         wrq->fixed = 1;
1194
1195         return 0;
1196 }
1197
1198 /*
1199  * Wireless Handler : set fragment threshold
1200  */
1201
1202 int iwctl_siwfrag(struct net_device *dev,
1203              struct iw_request_info *info,
1204                          struct iw_param *wrq,
1205              char *extra)
1206 {
1207     PSDevice            pDevice = (PSDevice)netdev_priv(dev);
1208     int rc = 0;
1209     int fthr = wrq->value;
1210
1211
1212     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFRAG \n");
1213
1214
1215     if (wrq->disabled)
1216                 fthr = 2312;
1217     if((fthr < 256) || (fthr > 2312)) {
1218                 rc = -EINVAL;
1219     }else {
1220                  fthr &= ~0x1;  // Get an even value
1221              pDevice->wFragmentationThreshold = (u16)fthr;
1222     }
1223
1224         return rc;
1225 }
1226
1227 /*
1228  * Wireless Handler : get fragment threshold
1229  */
1230
1231 int iwctl_giwfrag(struct net_device *dev,
1232              struct iw_request_info *info,
1233                          struct iw_param *wrq,
1234              char *extra)
1235 {
1236     PSDevice            pDevice = (PSDevice)netdev_priv(dev);
1237
1238     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFRAG \n");
1239         wrq->value = pDevice->wFragmentationThreshold;
1240         wrq->disabled = (wrq->value >= 2312);
1241         wrq->fixed = 1;
1242
1243         return 0;
1244 }
1245
1246
1247
1248 /*
1249  * Wireless Handler : set retry threshold
1250  */
1251 int iwctl_siwretry(struct net_device *dev,
1252              struct iw_request_info *info,
1253                          struct iw_param *wrq,
1254              char *extra)
1255 {
1256     PSDevice            pDevice = (PSDevice)netdev_priv(dev);
1257     int rc = 0;
1258
1259
1260     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRETRY \n");
1261
1262         if (wrq->disabled) {
1263                 rc = -EINVAL;
1264                 return rc;
1265         }
1266
1267         if (wrq->flags & IW_RETRY_LIMIT) {
1268                 if(wrq->flags & IW_RETRY_MAX)
1269                         pDevice->byLongRetryLimit = wrq->value;
1270                 else if (wrq->flags & IW_RETRY_MIN)
1271                         pDevice->byShortRetryLimit = wrq->value;
1272                 else {
1273                         // No modifier : set both
1274                         pDevice->byShortRetryLimit = wrq->value;
1275                         pDevice->byLongRetryLimit = wrq->value;
1276                 }
1277         }
1278         if (wrq->flags & IW_RETRY_LIFETIME) {
1279                 pDevice->wMaxTransmitMSDULifetime = wrq->value;
1280         }
1281
1282
1283         return rc;
1284 }
1285
1286 /*
1287  * Wireless Handler : get retry threshold
1288  */
1289 int iwctl_giwretry(struct net_device *dev,
1290              struct iw_request_info *info,
1291                          struct iw_param *wrq,
1292              char *extra)
1293 {
1294     PSDevice            pDevice = (PSDevice)netdev_priv(dev);
1295     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRETRY \n");
1296         wrq->disabled = 0;      // Can't be disabled
1297
1298         // Note : by default, display the min retry number
1299         if((wrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1300                 wrq->flags = IW_RETRY_LIFETIME;
1301                 wrq->value = (int)pDevice->wMaxTransmitMSDULifetime; //ms
1302         } else if((wrq->flags & IW_RETRY_MAX)) {
1303                 wrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
1304                 wrq->value = (int)pDevice->byLongRetryLimit;
1305         } else {
1306                 wrq->flags = IW_RETRY_LIMIT;
1307                 wrq->value = (int)pDevice->byShortRetryLimit;
1308                 if((int)pDevice->byShortRetryLimit != (int)pDevice->byLongRetryLimit)
1309                         wrq->flags |= IW_RETRY_MIN;
1310         }
1311
1312
1313         return 0;
1314 }
1315
1316
1317 /*
1318  * Wireless Handler : set encode mode
1319  */
1320 int iwctl_siwencode(struct net_device *dev,
1321              struct iw_request_info *info,
1322              struct iw_point *wrq,
1323              char *extra)
1324 {
1325     PSDevice            pDevice = (PSDevice)netdev_priv(dev);
1326     PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
1327         DWORD dwKeyIndex = (DWORD)(wrq->flags & IW_ENCODE_INDEX);
1328         int ii,uu, rc = 0;
1329         int index = (wrq->flags & IW_ENCODE_INDEX);
1330
1331 //2007-0207-07,<Modify> by EinsnLiu
1332 //There are some problems when using iwconfig encode/key command to set the WEP key.
1333 //I almost rewrite this function.
1334 //now it support:(assume the wireless interface's name is eth0)
1335 //iwconfig eth0 key [1] 1122334455 open  /*set key stirng to index 1,and driver using key index is set to 1*/
1336 //iwconfig eth0 key [3]    /*set driver using  key index to 3,the key string no change */
1337 //iwconfig eth0 key 1122334455  /*set key string to driver using index*/
1338 //iwconfig eth0 key restricted  /*enable share key*/
1339
1340         PSKeyTable pkeytab;
1341
1342         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODE \n");
1343
1344 if((wrq->flags & IW_ENCODE_DISABLED)==0){
1345         //Not disable encryption
1346
1347         if (dwKeyIndex > WLAN_WEP_NKEYS) {
1348                 rc = -EINVAL;
1349         return rc;
1350         }
1351
1352         if(dwKeyIndex<1&&((wrq->flags&IW_ENCODE_NOKEY)==0)){//set default key
1353                 if(pDevice->byKeyIndex<WLAN_WEP_NKEYS){
1354                         dwKeyIndex=pDevice->byKeyIndex;
1355                         }
1356                 else dwKeyIndex=0;
1357                 }else dwKeyIndex--;
1358
1359
1360         // Check the size of the key
1361         if (wrq->length > WLAN_WEP232_KEYLEN) {
1362                 rc = -EINVAL;
1363         return rc;
1364         }
1365
1366         if(wrq->length>0){//have key
1367
1368         if (wrq->length ==  WLAN_WEP232_KEYLEN) {
1369             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 232 bit wep key\n");
1370         }
1371         else if (wrq->length ==  WLAN_WEP104_KEYLEN) {
1372             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 104 bit wep key\n");
1373         }
1374         else if (wrq->length == WLAN_WEP40_KEYLEN) {
1375             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 40 bit wep key, index= %d\n", (int)dwKeyIndex);
1376         }else {//no support length
1377                 rc = -EINVAL;
1378         return rc;
1379                 }
1380         memset(pDevice->abyKey, 0, WLAN_WEP232_KEYLEN);
1381         memcpy(pDevice->abyKey, extra, wrq->length);
1382
1383         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyKey: ");
1384         for (ii = 0; ii < wrq->length; ii++) {
1385             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pDevice->abyKey[ii]);
1386         }
1387
1388         if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1389             spin_lock_irq(&pDevice->lock);
1390             KeybSetDefaultKey(&(pDevice->sKey),
1391                             (DWORD)(dwKeyIndex | (1 << 31)),
1392                                 wrq->length,
1393                             NULL,
1394                             pDevice->abyKey,
1395                             KEY_CTL_WEP,
1396                             pDevice->PortOffset,
1397                             pDevice->byLocalID
1398                           );
1399             spin_unlock_irq(&pDevice->lock);
1400         }
1401         pDevice->byKeyIndex = (BYTE)dwKeyIndex;
1402         pDevice->uKeyLength = wrq->length;
1403         pDevice->bTransmitKey = TRUE;
1404         pDevice->bEncryptionEnable = TRUE;
1405         pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1406
1407                 }else if(index>0){
1408         //when the length is 0 the request only changes the default transmit key index
1409         //check the new key has a non zero lenget
1410         if(pDevice->bEncryptionEnable==FALSE)
1411         {
1412                 rc = -EINVAL;
1413                 return rc;
1414         }
1415         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Just set Default key Index:\n");
1416         pkeytab=&(pDevice->sKey.KeyTable[MAX_KEY_TABLE-1]);
1417         if(pkeytab->GroupKey[(BYTE)dwKeyIndex].uKeyLength==0){
1418                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Default key len is 0\n");
1419                 rc = -EINVAL;
1420                 return rc;
1421                 }
1422          pDevice->byKeyIndex =(BYTE)dwKeyIndex;
1423          pkeytab->dwGTKeyIndex =dwKeyIndex | (1 << 31);
1424          pkeytab->GroupKey[(BYTE)dwKeyIndex].dwKeyIndex=dwKeyIndex | (1 << 31);
1425         }
1426
1427 }else {//disable the key
1428         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable WEP function\n");
1429         if(pDevice->bEncryptionEnable==FALSE)
1430                 return 0;
1431         pMgmt->bShareKeyAlgorithm = FALSE;
1432         pDevice->bEncryptionEnable = FALSE;
1433         pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1434         if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1435             spin_lock_irq(&pDevice->lock);
1436             for(uu=0;uu<MAX_KEY_TABLE;uu++)
1437                 MACvDisableKeyEntry(pDevice->PortOffset, uu);
1438             spin_unlock_irq(&pDevice->lock);
1439         }
1440 }
1441 //End Modify,Einsn
1442
1443 /*
1444         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODE \n");
1445
1446         // Check the size of the key
1447         if (wrq->length > WLAN_WEP232_KEYLEN) {
1448                 rc = -EINVAL;
1449         return rc;
1450         }
1451
1452         if (dwKeyIndex > WLAN_WEP_NKEYS) {
1453                 rc = -EINVAL;
1454         return rc;
1455     }
1456
1457     if (dwKeyIndex > 0)
1458                 dwKeyIndex--;
1459
1460         // Send the key to the card
1461         if (wrq->length > 0) {
1462
1463         if (wrq->length ==  WLAN_WEP232_KEYLEN) {
1464             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 232 bit wep key\n");
1465         }
1466         else if (wrq->length ==  WLAN_WEP104_KEYLEN) {
1467             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 104 bit wep key\n");
1468         }
1469         else if (wrq->length == WLAN_WEP40_KEYLEN) {
1470             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 40 bit wep key, index= %d\n", (int)dwKeyIndex);
1471         }
1472         memset(pDevice->abyKey, 0, WLAN_WEP232_KEYLEN);
1473         memcpy(pDevice->abyKey, extra, wrq->length);
1474
1475         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyKey: ");
1476         for (ii = 0; ii < wrq->length; ii++) {
1477             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pDevice->abyKey[ii]);
1478         }
1479
1480         if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1481             spin_lock_irq(&pDevice->lock);
1482             KeybSetDefaultKey(&(pDevice->sKey),
1483                             (DWORD)(pDevice->byKeyIndex | (1 << 31)),
1484                             pDevice->uKeyLength,
1485                             NULL,
1486                             pDevice->abyKey,
1487                             KEY_CTL_WEP,
1488                             pDevice->PortOffset,
1489                             pDevice->byLocalID
1490                           );
1491             spin_unlock_irq(&pDevice->lock);
1492         }
1493         pDevice->byKeyIndex = (BYTE)dwKeyIndex;
1494         pDevice->uKeyLength = wrq->length;
1495         pDevice->bTransmitKey = TRUE;
1496         pDevice->bEncryptionEnable = TRUE;
1497         pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1498
1499                 // Do we want to just set the transmit key index ?
1500                 if ( index < 4 ) {
1501                     pDevice->byKeyIndex = index;
1502                 }
1503                 else if(!wrq->flags & IW_ENCODE_MODE) {
1504                                 rc = -EINVAL;
1505                                 return rc;
1506             }
1507         }
1508         // Read the flags
1509         if(wrq->flags & IW_ENCODE_DISABLED){
1510
1511         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable WEP function\n");
1512                 pMgmt->bShareKeyAlgorithm = FALSE;
1513         pDevice->bEncryptionEnable = FALSE;
1514         pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1515         if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1516             spin_lock_irq(&pDevice->lock);
1517             for(uu=0;uu<MAX_KEY_TABLE;uu++)
1518                 MACvDisableKeyEntry(pDevice->PortOffset, uu);
1519             spin_unlock_irq(&pDevice->lock);
1520         }
1521         }
1522 */
1523
1524         if(wrq->flags & IW_ENCODE_RESTRICTED) {
1525         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & ShareKey System\n");
1526                 pMgmt->bShareKeyAlgorithm = TRUE;
1527         }
1528         if(wrq->flags & IW_ENCODE_OPEN) {
1529             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & Open System\n");
1530                 pMgmt->bShareKeyAlgorithm = FALSE;
1531         }
1532         return rc;
1533 }
1534
1535 /*
1536  * Wireless Handler : get encode mode
1537  */
1538  /*
1539 int iwctl_giwencode(struct net_device *dev,
1540              struct iw_request_info *info,
1541              struct iw_point *wrq,
1542              char *extra)
1543 {
1544     PSDevice            pDevice = (PSDevice)netdev_priv(dev);
1545     PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
1546     int rc = 0;
1547     char abyKey[WLAN_WEP232_KEYLEN];
1548         UINT index = (UINT)(wrq->flags & IW_ENCODE_INDEX);
1549         PSKeyItem   pKey = NULL;
1550
1551     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODE\n");
1552 //2007-0207-06,<Add> by EinsnLiu
1553 //the key index in iwconfig is 1-4 when our driver is 0-3
1554 //so it can't be used directly.
1555 //if the index is 0,we should used the index set by driver.
1556         if (index > WLAN_WEP_NKEYS) {
1557                 rc = -EINVAL;
1558         return rc;
1559         }
1560         if(index<1){//set default key
1561                 if(pDevice->byKeyIndex<WLAN_WEP_NKEYS){
1562                         index=pDevice->byKeyIndex;
1563                         }
1564                 else index=0;
1565                 }else index--;
1566 //End Add,Einsn
1567
1568         memset(abyKey, 0, sizeof(abyKey));
1569         // Check encryption mode
1570         wrq->flags = IW_ENCODE_NOKEY;
1571         // Is WEP enabled ???
1572         if (pDevice->bEncryptionEnable)
1573                 wrq->flags |=  IW_ENCODE_ENABLED;
1574     else
1575                 wrq->flags |=  IW_ENCODE_DISABLED;
1576
1577     if (pMgmt->bShareKeyAlgorithm)
1578                 wrq->flags |=  IW_ENCODE_RESTRICTED;
1579         else
1580                 wrq->flags |=  IW_ENCODE_OPEN;
1581
1582         if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (BYTE)index , &pKey)){
1583         wrq->length = pKey->uKeyLength;
1584         memcpy(abyKey, pKey->abyKey,  pKey->uKeyLength);
1585 //2007-0207-06,<Modify> by EinsnLiu
1586 //only get key success need to  copy data
1587 //index should +1.
1588 //there is not necessary to return -EINVAL when get key failed
1589 //if return -EINVAL,the encryption item can't be display by the command "iwconfig".
1590         wrq->flags |= index+1;
1591         memcpy(extra,  abyKey, WLAN_WEP232_KEYLEN);
1592     }
1593
1594     //else {
1595     //    rc = -EINVAL;
1596    //     return rc;
1597   //  }
1598
1599
1600 //End Modify,Einsn
1601
1602         return 0;
1603 }
1604 */
1605
1606 //2008-0409-06, <Add> by Einsn Liu
1607
1608 int iwctl_giwencode(struct net_device *dev,
1609                         struct iw_request_info *info,
1610                         struct iw_point *wrq,
1611                         char *extra)
1612 {
1613         PSDevice                        pDevice = (PSDevice)netdev_priv(dev);
1614         PSMgmtObject            pMgmt = &(pDevice->sMgmtObj);
1615         char abyKey[WLAN_WEP232_KEYLEN];
1616
1617         UINT index = (UINT)(wrq->flags & IW_ENCODE_INDEX);
1618         PSKeyItem       pKey = NULL;
1619
1620         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODE\n");
1621
1622         if (index > WLAN_WEP_NKEYS) {
1623                 return  -EINVAL;
1624         }
1625         if(index<1){//get default key
1626                 if(pDevice->byKeyIndex<WLAN_WEP_NKEYS){
1627                         index=pDevice->byKeyIndex;
1628                 } else
1629                       index=0;
1630         }else
1631              index--;
1632
1633         memset(abyKey, 0, WLAN_WEP232_KEYLEN);
1634         // Check encryption mode
1635         wrq->flags = IW_ENCODE_NOKEY;
1636         // Is WEP enabled ???
1637         if (pDevice->bEncryptionEnable)
1638                 wrq->flags |=  IW_ENCODE_ENABLED;
1639         else
1640                 wrq->flags |=  IW_ENCODE_DISABLED;
1641
1642         if (pMgmt->bShareKeyAlgorithm)
1643                 wrq->flags |=  IW_ENCODE_RESTRICTED;
1644         else
1645                 wrq->flags |=  IW_ENCODE_OPEN;
1646                 wrq->length=0;
1647
1648         if((index==0)&&(pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled||
1649                 pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)){//get wpa pairwise  key
1650                         if (KeybGetKey(&(pDevice->sKey),pMgmt->abyCurrBSSID, 0xffffffff, &pKey)){
1651                            wrq->length = pKey->uKeyLength;
1652                                   memcpy(abyKey, pKey->abyKey,  pKey->uKeyLength);
1653                                   memcpy(extra,  abyKey, WLAN_WEP232_KEYLEN);
1654                            }
1655         }else if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (BYTE)index , &pKey)){
1656                         wrq->length = pKey->uKeyLength;
1657                         memcpy(abyKey, pKey->abyKey,  pKey->uKeyLength);
1658                 memcpy(extra,  abyKey, WLAN_WEP232_KEYLEN);
1659         }
1660
1661         wrq->flags |= index+1;
1662
1663         return 0;
1664 }
1665
1666 /*
1667  * Wireless Handler : set power mode
1668  */
1669 int iwctl_siwpower(struct net_device *dev,
1670              struct iw_request_info *info,
1671                          struct iw_param *wrq,
1672              char *extra)
1673 {
1674     PSDevice            pDevice = (PSDevice)netdev_priv(dev);
1675     PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
1676     int rc = 0;
1677
1678     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER \n");
1679
1680     if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
1681                  rc = -EINVAL;
1682                  return rc;
1683         }
1684
1685         if (wrq->disabled) {
1686                 pDevice->ePSMode = WMAC_POWER_CAM;
1687                 PSvDisablePowerSaving(pDevice);
1688                 return rc;
1689         }
1690         if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1691          pDevice->ePSMode = WMAC_POWER_FAST;
1692          PSvEnablePowerSaving((HANDLE)pDevice, pMgmt->wListenInterval);
1693
1694         } else if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
1695              pDevice->ePSMode = WMAC_POWER_FAST;
1696          PSvEnablePowerSaving((HANDLE)pDevice, pMgmt->wListenInterval);
1697         }
1698         switch (wrq->flags & IW_POWER_MODE) {
1699         case IW_POWER_UNICAST_R:
1700         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_UNICAST_R \n");
1701                 rc = -EINVAL;
1702                 break;
1703         case IW_POWER_ALL_R:
1704         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ALL_R \n");
1705                 rc = -EINVAL;
1706         case IW_POWER_ON:
1707         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ON \n");
1708                 break;
1709         default:
1710                 rc = -EINVAL;
1711         }
1712
1713         return rc;
1714 }
1715
1716 /*
1717  * Wireless Handler : get power mode
1718  */
1719 int iwctl_giwpower(struct net_device *dev,
1720              struct iw_request_info *info,
1721                          struct iw_param *wrq,
1722              char *extra)
1723 {
1724     PSDevice            pDevice = (PSDevice)netdev_priv(dev);
1725     PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
1726     int mode = pDevice->ePSMode;
1727
1728
1729     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPOWER \n");
1730
1731
1732         if ((wrq->disabled = (mode == WMAC_POWER_CAM)))
1733             return 0;
1734
1735         if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1736                 wrq->value = (int)((pMgmt->wListenInterval * pMgmt->wCurrBeaconPeriod) << 10);
1737                 wrq->flags = IW_POWER_TIMEOUT;
1738         } else {
1739                 wrq->value = (int)((pMgmt->wListenInterval * pMgmt->wCurrBeaconPeriod) << 10);
1740                 wrq->flags = IW_POWER_PERIOD;
1741         }
1742         wrq->flags |= IW_POWER_ALL_R;
1743
1744         return 0;
1745 }
1746
1747
1748 /*
1749  * Wireless Handler : get Sensitivity
1750  */
1751 int iwctl_giwsens(struct net_device *dev,
1752                          struct iw_request_info *info,
1753                          struct iw_param *wrq,
1754                          char *extra)
1755 {
1756     PSDevice            pDevice = (PSDevice)netdev_priv(dev);
1757     long ldBm;
1758
1759     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSENS \n");
1760     if (pDevice->bLinkPass == TRUE) {
1761         RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm);
1762             wrq->value = ldBm;
1763         }
1764         else {
1765             wrq->value = 0;
1766     };
1767         wrq->disabled = (wrq->value == 0);
1768         wrq->fixed = 1;
1769
1770
1771         return 0;
1772 }
1773
1774 //2008-0409-07, <Add> by Einsn Liu
1775 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1776
1777 int iwctl_siwauth(struct net_device *dev,
1778                           struct iw_request_info *info,
1779                           struct iw_param *wrq,
1780                           char *extra)
1781 {
1782         PSDevice                        pDevice = (PSDevice)netdev_priv(dev);
1783         PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);
1784         int ret=0;
1785         static int wpa_version=0;  //must be static to save the last value,einsn liu
1786         static int pairwise=0;
1787
1788     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH \n");
1789         switch (wrq->flags & IW_AUTH_INDEX) {
1790         case IW_AUTH_WPA_VERSION:
1791                 wpa_version = wrq->value;
1792                 if(wrq->value == IW_AUTH_WPA_VERSION_DISABLED) {
1793                        printk("iwctl_siwauth:set WPADEV to disable at 1??????\n");
1794                         //pDevice->bWPADevEnable = FALSE;
1795                 }
1796                 else if(wrq->value == IW_AUTH_WPA_VERSION_WPA) {
1797                           printk("iwctl_siwauth:set WPADEV to WPA1******\n");
1798                 }
1799                 else {
1800                           printk("iwctl_siwauth:set WPADEV to WPA2******\n");
1801                 }
1802                 //pDevice->bWPASuppWextEnabled =TRUE;
1803                 break;
1804         case IW_AUTH_CIPHER_PAIRWISE:
1805                 pairwise = wrq->value;
1806
1807                 if(pairwise == IW_AUTH_CIPHER_CCMP){
1808                         pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1809                 }else if(pairwise == IW_AUTH_CIPHER_TKIP){
1810                         pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1811                 }else if(pairwise == IW_AUTH_CIPHER_WEP40||pairwise == IW_AUTH_CIPHER_WEP104){
1812                         pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1813                 }else if(pairwise == IW_AUTH_CIPHER_NONE){
1814                         //do nothing,einsn liu
1815                 }else pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1816
1817                 break;
1818         case IW_AUTH_CIPHER_GROUP:
1819                 if(wpa_version == IW_AUTH_WPA_VERSION_DISABLED)
1820                         break;
1821                 if(pairwise == IW_AUTH_CIPHER_NONE){
1822                         if(wrq->value == IW_AUTH_CIPHER_CCMP){
1823                                 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1824                         }else {
1825                                 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1826                         }
1827                 }
1828                 break;
1829         case IW_AUTH_KEY_MGMT:
1830
1831                 if(wpa_version == IW_AUTH_WPA_VERSION_WPA2){
1832                         if(wrq->value == IW_AUTH_KEY_MGMT_PSK)
1833                                 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
1834                         else pMgmt->eAuthenMode = WMAC_AUTH_WPA2;
1835                 }else if(wpa_version == IW_AUTH_WPA_VERSION_WPA){
1836                         if(wrq->value == 0){
1837                                 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
1838                         }else if(wrq->value == IW_AUTH_KEY_MGMT_PSK)
1839                                 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
1840                         else pMgmt->eAuthenMode = WMAC_AUTH_WPA;
1841                 }
1842
1843                 break;
1844         case IW_AUTH_TKIP_COUNTERMEASURES:
1845                 break;          /* FIXME */
1846         case IW_AUTH_DROP_UNENCRYPTED:
1847                 break;
1848         case IW_AUTH_80211_AUTH_ALG:
1849                 if(wrq->value==IW_AUTH_ALG_OPEN_SYSTEM){
1850                         pMgmt->bShareKeyAlgorithm=FALSE;
1851                 }else if(wrq->value==IW_AUTH_ALG_SHARED_KEY){
1852                         pMgmt->bShareKeyAlgorithm=TRUE;
1853                 }
1854                 break;
1855         case IW_AUTH_WPA_ENABLED:
1856                 //pDevice->bWPADevEnable = !! wrq->value;
1857                 break;
1858         case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1859                 break;
1860         case IW_AUTH_ROAMING_CONTROL:
1861                 ret = -EOPNOTSUPP;
1862                 break;
1863         case IW_AUTH_PRIVACY_INVOKED:
1864                 pDevice->bEncryptionEnable = !!wrq->value;
1865                 if(pDevice->bEncryptionEnable == FALSE){
1866                         wpa_version = 0;
1867                         pairwise = 0;
1868                         pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1869                         pMgmt->bShareKeyAlgorithm = FALSE;
1870                         pMgmt->eAuthenMode = FALSE;
1871                         //pDevice->bWPADevEnable = FALSE;
1872                 }
1873
1874                 break;
1875         default:
1876                 ret = -EOPNOTSUPP;
1877                 break;
1878         }
1879 /*
1880         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_version = %d\n",wpa_version);
1881         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pairwise = %d\n",pairwise);
1882         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->eEncryptionStatus = %d\n",pDevice->eEncryptionStatus);
1883         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->eAuthenMode  = %d\n",pMgmt->eAuthenMode);
1884         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->bShareKeyAlgorithm = %s\n",pMgmt->bShareKeyAlgorithm?"TRUE":"FALSE");
1885         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->bEncryptionEnable = %s\n",pDevice->bEncryptionEnable?"TRUE":"FALSE");
1886         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->bWPADevEnable = %s\n",pDevice->bWPADevEnable?"TRUE":"FALSE");
1887 */
1888    return ret;
1889 }
1890
1891
1892 int iwctl_giwauth(struct net_device *dev,
1893                           struct iw_request_info *info,
1894                           struct iw_param *wrq,
1895                           char *extra)
1896 {
1897         return -EOPNOTSUPP;
1898 }
1899
1900
1901
1902 int iwctl_siwgenie(struct net_device *dev,
1903                           struct iw_request_info *info,
1904                           struct iw_point *wrq,
1905                           char *extra)
1906 {
1907         PSDevice                        pDevice = (PSDevice)netdev_priv(dev);
1908         PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);
1909         int ret=0;
1910
1911         if(wrq->length){
1912                 if ((wrq->length < 2) || (extra[1]+2 != wrq->length)) {
1913                         ret = -EINVAL;
1914                         goto out;
1915                 }
1916                 if(wrq->length > MAX_WPA_IE_LEN){
1917                         ret = -ENOMEM;
1918                         goto out;
1919                 }
1920                 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
1921                 if(copy_from_user(pMgmt->abyWPAIE, extra, wrq->length)){
1922                         ret = -EFAULT;
1923                         goto out;
1924                 }
1925                 pMgmt->wWPAIELen = wrq->length;
1926         }else {
1927                 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
1928                 pMgmt->wWPAIELen = 0;
1929         }
1930
1931         out://not completely ...not necessary in wpa_supplicant 0.5.8
1932         return 0;
1933 }
1934
1935 int iwctl_giwgenie(struct net_device *dev,
1936                           struct iw_request_info *info,
1937                           struct iw_point *wrq,
1938                           char *extra)
1939 {
1940         PSDevice                        pDevice = (PSDevice)netdev_priv(dev);
1941         PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);
1942         int ret=0;
1943         int space = wrq->length;
1944
1945         wrq->length = 0;
1946         if(pMgmt->wWPAIELen > 0){
1947                 wrq->length = pMgmt->wWPAIELen;
1948                 if(pMgmt->wWPAIELen <= space){
1949                         if(copy_to_user(extra, pMgmt->abyWPAIE, pMgmt->wWPAIELen)){
1950                                 ret = -EFAULT;
1951                         }
1952                 }else
1953                         ret = -E2BIG;
1954         }
1955
1956         return ret;
1957 }
1958
1959
1960 int iwctl_siwencodeext(struct net_device *dev,
1961              struct iw_request_info *info,
1962              struct iw_point *wrq,
1963              char *extra)
1964 {
1965     PSDevice            pDevice = (PSDevice)netdev_priv(dev);
1966         struct iw_encode_ext *ext = (struct iw_encode_ext*)extra;
1967     struct viawget_wpa_param *param=NULL;
1968 //original member
1969     wpa_alg alg_name;
1970     u8  addr[6];
1971     int key_idx, set_tx;
1972     u8  seq[IW_ENCODE_SEQ_MAX_SIZE];
1973     u8 key[64];
1974     size_t seq_len,key_len=0;
1975 //
1976    // int ii;
1977     u8 *buf;
1978     size_t blen;
1979     u8 key_array[64];
1980     int ret=0;
1981
1982 printk("SIOCSIWENCODEEXT...... \n");
1983
1984 blen = sizeof(*param);
1985 buf = kmalloc((int)blen, (int)GFP_KERNEL);
1986 if (buf == NULL)
1987     return -ENOMEM;
1988 memset(buf, 0, blen);
1989 param = (struct viawget_wpa_param *) buf;
1990
1991 //recover alg_name
1992 switch (ext->alg) {
1993     case IW_ENCODE_ALG_NONE:
1994                   alg_name = WPA_ALG_NONE;
1995                 break;
1996     case IW_ENCODE_ALG_WEP:
1997                   alg_name = WPA_ALG_WEP;
1998                 break;
1999     case IW_ENCODE_ALG_TKIP:
2000                   alg_name = WPA_ALG_TKIP;
2001                 break;
2002     case IW_ENCODE_ALG_CCMP:
2003                   alg_name = WPA_ALG_CCMP;
2004                 break;
2005     default:
2006                 printk("Unknown alg = %d\n",ext->alg);
2007                 ret= -ENOMEM;
2008                 goto error;
2009                 }
2010 //recover addr
2011  memcpy(addr, ext->addr.sa_data, ETH_ALEN);
2012 //recover key_idx
2013   key_idx = (wrq->flags&IW_ENCODE_INDEX) - 1;
2014 //recover set_tx
2015 if(ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2016    set_tx = 1;
2017 //recover seq,seq_len
2018         if(ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
2019    seq_len=IW_ENCODE_SEQ_MAX_SIZE;
2020    memcpy(seq, ext->rx_seq, seq_len);
2021                 }
2022 //recover key,key_len
2023 if(ext->key_len) {
2024   key_len=ext->key_len;
2025   memcpy(key, &ext->key[0], key_len);
2026         }
2027
2028 memset(key_array, 0, 64);
2029 if ( key_len > 0) {
2030      memcpy(key_array, key, key_len);
2031     if (key_len == 32) {
2032           // notice ! the oder
2033           memcpy(&key_array[16], &key[24], 8);
2034           memcpy(&key_array[24], &key[16], 8);
2035         }
2036         }
2037
2038 /**************Translate iw_encode_ext to viawget_wpa_param****************/
2039 memcpy(param->addr, addr, ETH_ALEN);
2040 param->u.wpa_key.alg_name = (int)alg_name;
2041 param->u.wpa_key.set_tx = set_tx;
2042 param->u.wpa_key.key_index = key_idx;
2043 param->u.wpa_key.key_len = key_len;
2044 param->u.wpa_key.key = (u8 *)key_array;
2045 param->u.wpa_key.seq = (u8 *)seq;
2046 param->u.wpa_key.seq_len = seq_len;
2047
2048 #if 0
2049 int ii;
2050 printk("param->u.wpa_key.alg_name =%d\n",param->u.wpa_key.alg_name);
2051 printk("param->addr=%02x:%02x:%02x:%02x:%02x:%02x\n",
2052               param->addr[0],param->addr[1],param->addr[2],
2053               param->addr[3],param->addr[4],param->addr[5]);
2054 printk("param->u.wpa_key.set_tx =%d\n",param->u.wpa_key.set_tx);
2055 printk("param->u.wpa_key.key_index =%d\n",param->u.wpa_key.key_index);
2056 printk("param->u.wpa_key.key_len =%d\n",param->u.wpa_key.key_len);
2057 printk("param->u.wpa_key.key =");
2058 for(ii=0;ii<param->u.wpa_key.key_len;ii++)
2059         printk("%02x:",param->u.wpa_key.key[ii]);
2060          printk("\n");
2061 printk("param->u.wpa_key.seq_len =%d\n",param->u.wpa_key.seq_len);
2062 printk("param->u.wpa_key.seq =");
2063 for(ii=0;ii<param->u.wpa_key.seq_len;ii++)
2064         printk("%02x:",param->u.wpa_key.seq[ii]);
2065          printk("\n");
2066
2067 printk("...........\n");
2068 #endif
2069 //****set if current action is Network Manager count??
2070 //****this method is so foolish,but there is no other way???
2071 if(param->u.wpa_key.alg_name == WPA_ALG_NONE) {
2072    if(param->u.wpa_key.key_index ==0) {
2073      pDevice->bwextcount++;
2074     }
2075    if((pDevice->bwextcount == 1)&&(param->u.wpa_key.key_index ==1)) {
2076  pDevice->bwextcount++;
2077     }
2078    if((pDevice->bwextcount ==2)&&(param->u.wpa_key.key_index ==2)) {
2079  pDevice->bwextcount++;
2080         }
2081    if((pDevice->bwextcount ==3)&&(param->u.wpa_key.key_index ==3)) {
2082  pDevice->bwextcount++;
2083         }
2084                  }
2085 if( pDevice->bwextcount == 4) {
2086     printk("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n");
2087  pDevice->bwextcount=0;
2088    pDevice->bWPASuppWextEnabled = TRUE;
2089                  }
2090 //******
2091
2092                 spin_lock_irq(&pDevice->lock);
2093  ret = wpa_set_keys(pDevice, param, TRUE);
2094                 spin_unlock_irq(&pDevice->lock);
2095
2096 error:
2097 kfree(param);
2098         return ret;
2099 }
2100
2101
2102
2103 int iwctl_giwencodeext(struct net_device *dev,
2104              struct iw_request_info *info,
2105              struct iw_point *wrq,
2106              char *extra)
2107 {
2108                 return -EOPNOTSUPP;;
2109 }
2110
2111 int iwctl_siwmlme(struct net_device *dev,
2112                                 struct iw_request_info * info,
2113                                 struct iw_point *wrq,
2114                                 char *extra)
2115 {
2116         PSDevice                        pDevice = (PSDevice)netdev_priv(dev);
2117         PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);
2118         struct iw_mlme *mlme = (struct iw_mlme *)extra;
2119         //u16 reason = cpu_to_le16(mlme->reason_code);
2120         int ret = 0;
2121
2122         if(memcmp(pMgmt->abyCurrBSSID, mlme->addr.sa_data, ETH_ALEN)){
2123                 ret = -EINVAL;
2124                 return ret;
2125         }
2126         switch(mlme->cmd){
2127         case IW_MLME_DEAUTH:
2128                 //this command seems to be not complete,please test it --einsnliu
2129                 //bScheduleCommand((HANDLE) pDevice, WLAN_CMD_DEAUTH, (PBYTE)&reason);
2130                 break;
2131         case IW_MLME_DISASSOC:
2132                 if(pDevice->bLinkPass == TRUE){
2133                                           printk("iwctl_siwmlme--->send DISASSOCIATE\n");
2134                   //clear related flags
2135                    memset(pMgmt->abyDesireBSSID, 0xFF,6);
2136                 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
2137                         bScheduleCommand((HANDLE)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
2138                 }
2139                 break;
2140         default:
2141                 ret = -EOPNOTSUPP;
2142         }
2143
2144         return ret;
2145
2146 }
2147
2148 #endif
2149
2150
2151 /*------------------------------------------------------------------*/
2152 /*
2153  * Structures to export the Wireless Handlers
2154  */
2155
2156
2157 /*
2158 static const iw_handler         iwctl_handler[] =
2159 {
2160         (iw_handler) iwctl_commit,      // SIOCSIWCOMMIT
2161         (iw_handler) iwctl_giwname,     // SIOCGIWNAME
2162         (iw_handler) NULL,                              // SIOCSIWNWID
2163         (iw_handler) NULL,                              // SIOCGIWNWID
2164         (iw_handler) iwctl_siwfreq,             // SIOCSIWFREQ
2165         (iw_handler) iwctl_giwfreq,             // SIOCGIWFREQ
2166         (iw_handler) iwctl_siwmode,             // SIOCSIWMODE
2167         (iw_handler) iwctl_giwmode,             // SIOCGIWMODE
2168         (iw_handler) NULL,                      // SIOCSIWSENS
2169         (iw_handler) iwctl_giwsens,                     // SIOCGIWSENS
2170         (iw_handler) NULL,                      // SIOCSIWRANGE
2171         (iw_handler) iwctl_giwrange,            // SIOCGIWRANGE
2172         (iw_handler) NULL,                          // SIOCSIWPRIV
2173         (iw_handler) NULL,                      // SIOCGIWPRIV
2174         (iw_handler) NULL,                      // SIOCSIWSTATS
2175         (iw_handler) NULL,                  // SIOCGIWSTATS
2176     (iw_handler) NULL,                  // SIOCSIWSPY
2177         (iw_handler) NULL,                          // SIOCGIWSPY
2178         (iw_handler) NULL,                                  // -- hole --
2179         (iw_handler) NULL,                                  // -- hole --
2180         (iw_handler) iwctl_siwap,                   // SIOCSIWAP
2181         (iw_handler) iwctl_giwap,                   // SIOCGIWAP
2182         (iw_handler) NULL,                                  // -- hole -- 0x16
2183         (iw_handler) iwctl_giwaplist,       // SIOCGIWAPLIST
2184         (iw_handler) iwctl_siwscan,         // SIOCSIWSCAN
2185         (iw_handler) iwctl_giwscan,         // SIOCGIWSCAN
2186         (iw_handler) iwctl_siwessid,            // SIOCSIWESSID
2187         (iw_handler) iwctl_giwessid,            // SIOCGIWESSID
2188         (iw_handler) NULL,              // SIOCSIWNICKN
2189         (iw_handler) NULL,              // SIOCGIWNICKN
2190         (iw_handler) NULL,                                  // -- hole --
2191         (iw_handler) NULL,                                  // -- hole --
2192         (iw_handler) iwctl_siwrate,             // SIOCSIWRATE 0x20
2193         (iw_handler) iwctl_giwrate,             // SIOCGIWRATE
2194         (iw_handler) iwctl_siwrts,              // SIOCSIWRTS
2195         (iw_handler) iwctl_giwrts,              // SIOCGIWRTS
2196         (iw_handler) iwctl_siwfrag,             // SIOCSIWFRAG
2197         (iw_handler) iwctl_giwfrag,             // SIOCGIWFRAG
2198         (iw_handler) NULL,              // SIOCSIWTXPOW
2199         (iw_handler) NULL,              // SIOCGIWTXPOW
2200         (iw_handler) iwctl_siwretry,            // SIOCSIWRETRY
2201         (iw_handler) iwctl_giwretry,            // SIOCGIWRETRY
2202         (iw_handler) iwctl_siwencode,           // SIOCSIWENCODE
2203         (iw_handler) iwctl_giwencode,           // SIOCGIWENCODE
2204         (iw_handler) iwctl_siwpower,            // SIOCSIWPOWER
2205         (iw_handler) iwctl_giwpower,            // SIOCGIWPOWER
2206         (iw_handler) NULL,                      // -- hole --
2207         (iw_handler) NULL,                      // -- hole --
2208         (iw_handler) iwctl_siwgenie,    // SIOCSIWGENIE
2209         (iw_handler) iwctl_giwgenie,    // SIOCGIWGENIE
2210         (iw_handler) iwctl_siwauth,             // SIOCSIWAUTH
2211         (iw_handler) iwctl_giwauth,             // SIOCGIWAUTH
2212         (iw_handler) iwctl_siwencodeext,                // SIOCSIWENCODEEXT
2213         (iw_handler) iwctl_giwencodeext,                // SIOCGIWENCODEEXT
2214         (iw_handler) NULL,                              // SIOCSIWPMKSA
2215         (iw_handler) NULL,                              // -- hole --
2216
2217 };
2218 */
2219
2220 static const iw_handler         iwctl_handler[] =
2221 {
2222         (iw_handler) iwctl_commit,      // SIOCSIWCOMMIT
2223         (iw_handler) NULL,      // SIOCGIWNAME
2224         (iw_handler) NULL,                              // SIOCSIWNWID
2225         (iw_handler) NULL,                              // SIOCGIWNWID
2226         (iw_handler) NULL,              // SIOCSIWFREQ
2227         (iw_handler) NULL,              // SIOCGIWFREQ
2228         (iw_handler) NULL,              // SIOCSIWMODE
2229         (iw_handler) NULL,              // SIOCGIWMODE
2230         (iw_handler) NULL,                      // SIOCSIWSENS
2231         (iw_handler) NULL,                      // SIOCGIWSENS
2232         (iw_handler) NULL,                      // SIOCSIWRANGE
2233         (iw_handler) iwctl_giwrange,            // SIOCGIWRANGE
2234         (iw_handler) NULL,                          // SIOCSIWPRIV
2235         (iw_handler) NULL,                      // SIOCGIWPRIV
2236         (iw_handler) NULL,                      // SIOCSIWSTATS
2237         (iw_handler) NULL,                  // SIOCGIWSTATS
2238     (iw_handler) NULL,                  // SIOCSIWSPY
2239         (iw_handler) NULL,                          // SIOCGIWSPY
2240         (iw_handler) NULL,                                  // -- hole --
2241         (iw_handler) NULL,                                  // -- hole --
2242         (iw_handler) NULL,                  // SIOCSIWAP
2243         (iw_handler) NULL,                  // SIOCGIWAP
2244         (iw_handler) NULL,                                  // -- hole -- 0x16
2245         (iw_handler) NULL,       // SIOCGIWAPLIST
2246         (iw_handler) iwctl_siwscan,         // SIOCSIWSCAN
2247         (iw_handler) iwctl_giwscan,         // SIOCGIWSCAN
2248         (iw_handler) NULL,              // SIOCSIWESSID
2249         (iw_handler) NULL,              // SIOCGIWESSID
2250         (iw_handler) NULL,              // SIOCSIWNICKN
2251         (iw_handler) NULL,              // SIOCGIWNICKN
2252         (iw_handler) NULL,              // -- hole --
2253         (iw_handler) NULL,              // -- hole --
2254         (iw_handler) NULL,              // SIOCSIWRATE 0x20
2255         (iw_handler) NULL,              // SIOCGIWRATE
2256         (iw_handler) NULL,              // SIOCSIWRTS
2257         (iw_handler) NULL,              // SIOCGIWRTS
2258         (iw_handler) NULL,              // SIOCSIWFRAG
2259         (iw_handler) NULL,              // SIOCGIWFRAG
2260         (iw_handler) NULL,              // SIOCSIWTXPOW
2261         (iw_handler) NULL,              // SIOCGIWTXPOW
2262         (iw_handler) NULL,              // SIOCSIWRETRY
2263         (iw_handler) NULL,              // SIOCGIWRETRY
2264         (iw_handler) NULL,              // SIOCSIWENCODE
2265         (iw_handler) NULL,              // SIOCGIWENCODE
2266         (iw_handler) NULL,              // SIOCSIWPOWER
2267         (iw_handler) NULL,              // SIOCGIWPOWER
2268
2269 //2008-0409-07, <Add> by Einsn Liu
2270         (iw_handler) NULL,                      // -- hole --
2271         (iw_handler) NULL,                      // -- hole --
2272         (iw_handler) NULL,    // SIOCSIWGENIE
2273         (iw_handler) NULL,    // SIOCGIWGENIE
2274         (iw_handler) NULL,              // SIOCSIWAUTH
2275         (iw_handler) NULL,              // SIOCGIWAUTH
2276         (iw_handler) NULL,              // SIOCSIWENCODEEXT
2277         (iw_handler) NULL,              // SIOCGIWENCODEEXT
2278         (iw_handler) NULL,                              // SIOCSIWPMKSA
2279         (iw_handler) NULL,                              // -- hole --
2280 };
2281
2282
2283 static const iw_handler         iwctl_private_handler[] =
2284 {
2285         NULL,                           // SIOCIWFIRSTPRIV
2286 };
2287
2288
2289 struct iw_priv_args iwctl_private_args[] = {
2290 { IOCTL_CMD_SET,
2291   IW_PRIV_TYPE_CHAR | 1024, 0,
2292   "set"},
2293 };
2294
2295
2296
2297 const struct iw_handler_def     iwctl_handler_def =
2298 {
2299         .get_wireless_stats = &iwctl_get_wireless_stats,
2300         .num_standard   = sizeof(iwctl_handler)/sizeof(iw_handler),
2301 //      .num_private    = sizeof(iwctl_private_handler)/sizeof(iw_handler),
2302 //      .num_private_args = sizeof(iwctl_private_args)/sizeof(struct iw_priv_args),
2303         .num_private    = 0,
2304         .num_private_args = 0,
2305         .standard       = (iw_handler *) iwctl_handler,
2306 //      .private        = (iw_handler *) iwctl_private_handler,
2307 //      .private_args   = (struct iw_priv_args *)iwctl_private_args,
2308         .private        = NULL,
2309         .private_args   = NULL,
2310 };