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