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