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