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