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