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