]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/staging/vt6656/iwctl.c
08557fa9f0074aa0d964d2eb1bed8b75d244fa76
[karo-tx-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, u8 *extra)
636 {
637         struct sockaddr *sock;
638         struct iw_quality *qual;
639         PSDevice pDevice = netdev_priv(dev);
640         PSMgmtObject pMgmt = &pDevice->sMgmtObj;
641         PKnownBSS pBSS = &pMgmt->sBSSList[0];
642         int ii;
643         int jj;
644
645         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAPLIST\n");
646         /* Only super-user can see AP list */
647
648         if (pBSS == NULL)
649                 return -ENODEV;
650
651         if (!capable(CAP_NET_ADMIN))
652                 return -EPERM;
653
654         if (!wrq->pointer)
655                 return -EINVAL;
656
657         sock = kzalloc(sizeof(struct sockaddr) * IW_MAX_AP, GFP_KERNEL);
658         if (sock == NULL)
659                 return -ENOMEM;
660         qual = kzalloc(sizeof(struct iw_quality) * IW_MAX_AP, GFP_KERNEL);
661         if (qual == NULL) {
662                 kfree(sock);
663                 return -ENOMEM;
664         }
665
666         for (ii = 0, jj = 0; ii < MAX_BSS_NUM; ii++) {
667                 if (!pBSS[ii].bActive)
668                         continue;
669                 if (jj >= IW_MAX_AP)
670                         break;
671                 memcpy(sock[jj].sa_data, pBSS[ii].abyBSSID, 6);
672                 sock[jj].sa_family = ARPHRD_ETHER;
673                 qual[jj].level = pBSS[ii].uRSSI;
674                 qual[jj].qual = qual[jj].noise = 0;
675                 qual[jj].updated = 2;
676                 jj++;
677         }
678
679         wrq->flags = 1; /* Should be defined */
680         wrq->length = jj;
681         memcpy(extra, sock, sizeof(struct sockaddr) * jj);
682         memcpy(extra + sizeof(struct sockaddr) * jj, qual,
683                 sizeof(struct iw_quality) * jj);
684
685         kfree(sock);
686         kfree(qual);
687
688         return 0;
689 }
690
691 /*
692  * Wireless Handler: set essid
693  */
694 int iwctl_siwessid(struct net_device *dev, struct iw_request_info *info,
695                 struct iw_point *wrq, char *extra)
696 {
697         PSDevice pDevice = netdev_priv(dev);
698         PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
699         PWLAN_IE_SSID pItemSSID;
700
701         if (!(pDevice->flags & DEVICE_FLAGS_OPENED))
702                 return -EINVAL;
703
704         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWESSID :\n");
705
706         pDevice->fWPA_Authened = FALSE;
707         // Check if we asked for `any'
708         if (wrq->flags == 0) {
709                 // Just send an empty SSID list
710                 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
711                 memset(pMgmt->abyDesireBSSID, 0xFF,6);
712                 PRINT_K("set essid to 'any' \n");
713                 // Unknown desired AP, so here need not associate??
714                 return 0;
715         } else {
716                 // Set the SSID
717                 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
718                 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
719                 pItemSSID->byElementID = WLAN_EID_SSID;
720
721                 memcpy(pItemSSID->abySSID, extra, wrq->length);
722                 if (pItemSSID->abySSID[wrq->length - 1] == '\0') {
723                         if (wrq->length>0)
724                                 pItemSSID->len = wrq->length - 1;
725                 } else {
726                         pItemSSID->len = wrq->length;
727                 }
728                 PRINT_K("set essid to %s \n", pItemSSID->abySSID);
729
730                 // mike: need clear desiredBSSID
731                 if (pItemSSID->len==0) {
732                         memset(pMgmt->abyDesireBSSID, 0xFF, 6);
733                         return 0;
734                 }
735
736                 // Wext wil order another command of siwap to link
737                 // with desired AP, so here need not associate??
738                 if (pDevice->bWPASuppWextEnabled == TRUE)  {
739                         /*******search if  in hidden ssid mode ****/
740                         PKnownBSS pCurr = NULL;
741                         BYTE abyTmpDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
742                         unsigned ii;
743                         unsigned uSameBssidNum = 0;
744
745                         memcpy(abyTmpDesireSSID, pMgmt->abyDesireSSID, sizeof(abyTmpDesireSSID));
746                         pCurr = BSSpSearchBSSList(pDevice, NULL,
747                                                 abyTmpDesireSSID,
748                                                 pDevice->eConfigPHYMode);
749
750                         if (pCurr == NULL) {
751                                 PRINT_K("SIOCSIWESSID:hidden ssid site survey before associate.......\n");
752                                 vResetCommandTimer((void *)pDevice);
753                                 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
754                                 bScheduleCommand((void *)pDevice,
755                                                 WLAN_CMD_BSSID_SCAN,
756                                                 pMgmt->abyDesireSSID);
757                                 bScheduleCommand((void *)pDevice,
758                                                 WLAN_CMD_SSID,
759                                                 pMgmt->abyDesireSSID);
760                         } else {  // mike: to find out if that desired SSID is a
761                                 // hidden-ssid AP, by means of judging if there
762                                 // are two same BSSID exist in list ?
763                                 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
764                                         if (pMgmt->sBSSList[ii].bActive &&
765                                                 !compare_ether_addr(pMgmt->sBSSList[ii].abyBSSID,
766                                                                 pCurr->abyBSSID)) {
767                                                 uSameBssidNum++;
768                                         }
769                                 }
770                                 if (uSameBssidNum >= 2) { // hit: desired AP is in hidden ssid mode!!!
771                                         PRINT_K("SIOCSIWESSID:hidden ssid directly associate.......\n");
772                                         vResetCommandTimer((void *)pDevice);
773                                         pMgmt->eScanType = WMAC_SCAN_PASSIVE; // this scan type, you'll submit scan result!
774                                         bScheduleCommand((void *)pDevice,
775                                                         WLAN_CMD_BSSID_SCAN,
776                                                         pMgmt->abyDesireSSID);
777                                         bScheduleCommand((void *)pDevice,
778                                                         WLAN_CMD_SSID,
779                                                         pMgmt->abyDesireSSID);
780                                 }
781                         }
782                         return 0;
783                 }
784
785                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set essid = %s \n", pItemSSID->abySSID);
786         }
787
788         if (pDevice->flags & DEVICE_FLAGS_OPENED)
789                 pDevice->bCommit = TRUE;
790
791         return 0;
792 }
793
794 /*
795  * Wireless Handler: get essid
796  */
797 void iwctl_giwessid(struct net_device *dev, struct iw_request_info *info,
798                 struct iw_point *wrq, char *extra)
799 {
800         PSDevice pDevice = netdev_priv(dev);
801         PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
802         PWLAN_IE_SSID pItemSSID;
803
804         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWESSID \n");
805
806         // Note: if wrq->u.data.flags != 0, we should get the relevant
807         // SSID from the SSID list...
808
809         // Get the current SSID
810         pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
811         memcpy(extra, pItemSSID->abySSID, pItemSSID->len);
812         extra[pItemSSID->len] = '\0';
813
814         wrq->length = pItemSSID->len;
815         wrq->flags = 1; // active
816 }
817
818 /*
819  * Wireless Handler: set data rate
820  */
821 int iwctl_siwrate(struct net_device *dev, struct iw_request_info *info,
822                 struct iw_param *wrq, char *extra)
823 {
824         PSDevice pDevice = netdev_priv(dev);
825         int rc = 0;
826         u8 brate = 0;
827         int i;
828         BYTE abySupportedRates[13] = {
829                 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48,
830                 0x60, 0x6C, 0x90
831         };
832
833         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRATE \n");
834         if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
835                 rc = -EINVAL;
836                 return rc;
837         }
838
839         // First: get a valid bit rate value
840
841         // Which type of value
842         if ((wrq->value < 13) && (wrq->value >= 0)) {
843                 // Setting by rate index
844                 // Find value in the magic rate table
845                 brate = wrq->value;
846         } else {
847                 // Setting by frequency value
848                 u8 normvalue = (u8)(wrq->value/500000);
849
850                 // Check if rate is valid
851                 for (i = 0; i < 13; i++) {
852                         if (normvalue == abySupportedRates[i]) {
853                                 brate = i;
854                                 break;
855                         }
856                 }
857         }
858         // -1 designed the max rate (mostly auto mode)
859         if (wrq->value == -1) {
860                 // Get the highest available rate
861                 for (i = 0; i < 13; i++) {
862                         if (abySupportedRates[i] == 0)
863                                 break;
864                 }
865                 if (i != 0)
866                         brate = i - 1;
867
868         }
869         // Check that it is valid
870         // brate is index of abySupportedRates[]
871         if (brate > 13 ) {
872                 rc = -EINVAL;
873                 return rc;
874         }
875
876         // Now, check if we want a fixed or auto value
877         if (wrq->fixed != 0) {
878                 // Fixed mode
879                 // One rate, fixed
880                 pDevice->bFixRate = TRUE;
881                 if ((pDevice->byBBType == BB_TYPE_11B) && (brate > 3)) {
882                         pDevice->uConnectionRate = 3;
883                 } else {
884                         pDevice->uConnectionRate = brate;
885                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fixed to Rate %d \n", pDevice->uConnectionRate);
886                 }
887         } else {
888                 pDevice->bFixRate = FALSE;
889                 pDevice->uConnectionRate = 13;
890         }
891
892         return rc;
893 }
894
895 /*
896  * Wireless Handler: get data rate
897  */
898 void iwctl_giwrate(struct net_device *dev, struct iw_request_info *info,
899                 struct iw_param *wrq, char *extra)
900 {
901         PSDevice pDevice = netdev_priv(dev);
902         PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
903
904         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRATE \n");
905         {
906                 BYTE abySupportedRates[13] = {
907                         0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30,
908                         0x48, 0x60, 0x6C, 0x90
909                 };
910                 int brate = 0;
911
912                 if (pDevice->uConnectionRate < 13) {
913                         brate = abySupportedRates[pDevice->uConnectionRate];
914                 } else {
915                         if (pDevice->byBBType == BB_TYPE_11B)
916                                 brate = 0x16;
917                         if (pDevice->byBBType == BB_TYPE_11G)
918                                 brate = 0x6C;
919                         if (pDevice->byBBType == BB_TYPE_11A)
920                                 brate = 0x6C;
921                 }
922                 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
923                         if (pDevice->byBBType == BB_TYPE_11B)
924                                 brate = 0x16;
925                         if (pDevice->byBBType == BB_TYPE_11G)
926                                 brate = 0x6C;
927                         if (pDevice->byBBType == BB_TYPE_11A)
928                                 brate = 0x6C;
929                 }
930                 if (pDevice->uConnectionRate == 13)
931                         brate = abySupportedRates[pDevice->wCurrentRate];
932                 wrq->value = brate * 500000;
933                 // If more than one rate, set auto
934                 if (pDevice->bFixRate == TRUE)
935                         wrq->fixed = TRUE;
936         }
937 }
938
939 /*
940  * Wireless Handler: set rts threshold
941  */
942 int iwctl_siwrts(struct net_device *dev, struct iw_param *wrq)
943 {
944         PSDevice pDevice = netdev_priv(dev);
945
946         if ((wrq->value < 0 || wrq->value > 2312) && !wrq->disabled)
947                 return -EINVAL;
948
949         else if (wrq->disabled)
950                 pDevice->wRTSThreshold = 2312;
951         else
952                 pDevice->wRTSThreshold = wrq->value;
953
954         return 0;
955 }
956
957 /*
958  * Wireless Handler: get rts
959  */
960 int iwctl_giwrts(struct net_device *dev, struct iw_request_info *info,
961                 struct iw_param *wrq, char *extra)
962 {
963         PSDevice pDevice = netdev_priv(dev);
964
965         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRTS \n");
966         wrq->value = pDevice->wRTSThreshold;
967         wrq->disabled = (wrq->value >= 2312);
968         wrq->fixed = 1;
969         return 0;
970 }
971
972 /*
973  * Wireless Handler: set fragment threshold
974  */
975 int iwctl_siwfrag(struct net_device *dev, struct iw_request_info *info,
976                 struct iw_param *wrq, char *extra)
977 {
978         PSDevice pDevice = netdev_priv(dev);
979         int rc = 0;
980         int fthr = wrq->value;
981
982         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFRAG \n");
983
984         if (wrq->disabled)
985                 fthr = 2312;
986         if ((fthr < 256) || (fthr > 2312)) {
987                 rc = -EINVAL;
988         } else {
989                 fthr &= ~0x1; // Get an even value
990                 pDevice->wFragmentationThreshold = (u16)fthr;
991         }
992         return rc;
993 }
994
995 /*
996  * Wireless Handler: get fragment threshold
997  */
998 int iwctl_giwfrag(struct net_device *dev, struct iw_request_info *info,
999                 struct iw_param *wrq, char *extra)
1000 {
1001         PSDevice pDevice = netdev_priv(dev);
1002
1003         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFRAG \n");
1004         wrq->value = pDevice->wFragmentationThreshold;
1005         wrq->disabled = (wrq->value >= 2312);
1006         wrq->fixed = 1;
1007         return 0;
1008 }
1009
1010 /*
1011  * Wireless Handler: set retry threshold
1012  */
1013 int iwctl_siwretry(struct net_device *dev, struct iw_request_info *info,
1014                 struct iw_param *wrq, char *extra)
1015 {
1016         PSDevice pDevice = netdev_priv(dev);
1017         int rc = 0;
1018
1019         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRETRY \n");
1020
1021         if (wrq->disabled) {
1022                 rc = -EINVAL;
1023                 return rc;
1024         }
1025
1026         if (wrq->flags & IW_RETRY_LIMIT) {
1027                 if (wrq->flags & IW_RETRY_MAX) {
1028                         pDevice->byLongRetryLimit = wrq->value;
1029                 } else if (wrq->flags & IW_RETRY_MIN) {
1030                         pDevice->byShortRetryLimit = wrq->value;
1031                 } else {
1032                         // No modifier : set both
1033                         pDevice->byShortRetryLimit = wrq->value;
1034                         pDevice->byLongRetryLimit = wrq->value;
1035                 }
1036         }
1037         if (wrq->flags & IW_RETRY_LIFETIME)
1038                 pDevice->wMaxTransmitMSDULifetime = wrq->value;
1039         return rc;
1040 }
1041
1042 /*
1043  * Wireless Handler: get retry threshold
1044  */
1045 int iwctl_giwretry(struct net_device *dev, struct iw_request_info *info,
1046                 struct iw_param *wrq, char *extra)
1047 {
1048         PSDevice pDevice = netdev_priv(dev);
1049         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRETRY \n");
1050         wrq->disabled = 0; // Can't be disabled
1051
1052         // Note: by default, display the min retry number
1053         if ((wrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1054                 wrq->flags = IW_RETRY_LIFETIME;
1055                 wrq->value = (int)pDevice->wMaxTransmitMSDULifetime; // ms
1056         } else if ((wrq->flags & IW_RETRY_MAX)) {
1057                 wrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
1058                 wrq->value = (int)pDevice->byLongRetryLimit;
1059         } else {
1060                 wrq->flags = IW_RETRY_LIMIT;
1061                 wrq->value = (int)pDevice->byShortRetryLimit;
1062                 if ((int)pDevice->byShortRetryLimit != (int)pDevice->byLongRetryLimit)
1063                         wrq->flags |= IW_RETRY_MIN;
1064         }
1065         return 0;
1066 }
1067
1068 /*
1069  * Wireless Handler: set encode mode
1070  */
1071 int iwctl_siwencode(struct net_device *dev, struct iw_request_info *info,
1072                 struct iw_point *wrq, char *extra)
1073 {
1074         PSDevice pDevice = netdev_priv(dev);
1075         PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1076         DWORD dwKeyIndex = (DWORD)(wrq->flags & IW_ENCODE_INDEX);
1077         int ii;
1078         int uu;
1079         int rc = 0;
1080         int index = (wrq->flags & IW_ENCODE_INDEX);
1081
1082         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODE \n");
1083
1084         // Check the size of the key
1085         if (wrq->length > WLAN_WEP232_KEYLEN) {
1086                 rc = -EINVAL;
1087                 return rc;
1088         }
1089
1090         if (dwKeyIndex > WLAN_WEP_NKEYS) {
1091                 rc = -EINVAL;
1092                 return rc;
1093         }
1094
1095         if (dwKeyIndex > 0)
1096                 dwKeyIndex--;
1097
1098         // Send the key to the card
1099         if (wrq->length > 0) {
1100                 if (wrq->length == WLAN_WEP232_KEYLEN) {
1101                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 232 bit wep key\n");
1102                 } else if (wrq->length == WLAN_WEP104_KEYLEN) {
1103                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 104 bit wep key\n");
1104                 } else if (wrq->length == WLAN_WEP40_KEYLEN) {
1105                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 40 bit wep key, index= %d\n", (int)dwKeyIndex);
1106                 }
1107                 memset(pDevice->abyKey, 0, WLAN_WEP232_KEYLEN);
1108                 memcpy(pDevice->abyKey, extra, wrq->length);
1109
1110                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyKey: ");
1111                 for (ii = 0; ii < wrq->length; ii++)
1112                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pDevice->abyKey[ii]);
1113
1114                 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1115                         spin_lock_irq(&pDevice->lock);
1116                         KeybSetDefaultKey(pDevice,
1117                                         &(pDevice->sKey),
1118                                         dwKeyIndex | (1 << 31),
1119                                         wrq->length, NULL,
1120                                         pDevice->abyKey,
1121                                         KEY_CTL_WEP);
1122                         spin_unlock_irq(&pDevice->lock);
1123                 }
1124                 pDevice->byKeyIndex = (BYTE)dwKeyIndex;
1125                 pDevice->uKeyLength = wrq->length;
1126                 pDevice->bTransmitKey = TRUE;
1127                 pDevice->bEncryptionEnable = TRUE;
1128                 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1129
1130                 // Do we want to just set the transmit key index?
1131                 if (index < 4) {
1132                         pDevice->byKeyIndex = index;
1133                 } else if (!(wrq->flags & IW_ENCODE_MODE)) {
1134                         rc = -EINVAL;
1135                         return rc;
1136                 }
1137         }
1138         // Read the flags
1139         if (wrq->flags & IW_ENCODE_DISABLED) {
1140                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable WEP function\n");
1141                 pMgmt->bShareKeyAlgorithm = FALSE;
1142                 pDevice->bEncryptionEnable = FALSE;
1143                 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1144                 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1145                         spin_lock_irq(&pDevice->lock);
1146                         for (uu = 0; uu < MAX_KEY_TABLE; uu++)
1147                                 MACvDisableKeyEntry(pDevice, uu);
1148                         spin_unlock_irq(&pDevice->lock);
1149                 }
1150         }
1151         if (wrq->flags & IW_ENCODE_RESTRICTED) {
1152                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & ShareKey System\n");
1153                 pMgmt->bShareKeyAlgorithm = TRUE;
1154         }
1155         if (wrq->flags & IW_ENCODE_OPEN) {
1156                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & Open System\n");
1157                 pMgmt->bShareKeyAlgorithm = FALSE;
1158         }
1159
1160         memset(pMgmt->abyDesireBSSID, 0xFF, 6);
1161
1162         return rc;
1163 }
1164
1165 int iwctl_giwencode(struct net_device *dev, struct iw_request_info *info,
1166                 struct iw_point *wrq, char *extra)
1167 {
1168         PSDevice pDevice = netdev_priv(dev);
1169         PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1170         char abyKey[WLAN_WEP232_KEYLEN];
1171
1172         unsigned index = (unsigned)(wrq->flags & IW_ENCODE_INDEX);
1173         PSKeyItem pKey = NULL;
1174
1175         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODE\n");
1176
1177         if (index > WLAN_WEP_NKEYS)
1178                 return  -EINVAL;
1179         if (index < 1) { // get default key
1180                 if (pDevice->byKeyIndex < WLAN_WEP_NKEYS)
1181                         index = pDevice->byKeyIndex;
1182                 else
1183                         index = 0;
1184         } else {
1185                 index--;
1186         }
1187
1188         memset(abyKey, 0, WLAN_WEP232_KEYLEN);
1189         // Check encryption mode
1190         wrq->flags = IW_ENCODE_NOKEY;
1191         // Is WEP enabled ???
1192         if (pDevice->bEncryptionEnable)
1193                 wrq->flags |= IW_ENCODE_ENABLED;
1194         else
1195                 wrq->flags |= IW_ENCODE_DISABLED;
1196
1197         if (pMgmt->bShareKeyAlgorithm)
1198                 wrq->flags |= IW_ENCODE_RESTRICTED;
1199         else
1200                 wrq->flags |= IW_ENCODE_OPEN;
1201         wrq->length = 0;
1202
1203         if ((index == 0) && (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled ||
1204                                 pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)) { // get wpa pairwise  key
1205                 if (KeybGetKey(&(pDevice->sKey), pMgmt->abyCurrBSSID, 0xffffffff, &pKey)) {
1206                         wrq->length = pKey->uKeyLength;
1207                         memcpy(abyKey, pKey->abyKey,    pKey->uKeyLength);
1208                         memcpy(extra,  abyKey, WLAN_WEP232_KEYLEN);
1209                 }
1210         } else if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (BYTE)index, &pKey)) {
1211                 wrq->length = pKey->uKeyLength;
1212                 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1213                 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1214         }
1215
1216         wrq->flags |= index + 1;
1217         return 0;
1218 }
1219
1220 /*
1221  * Wireless Handler: set power mode
1222  */
1223 int iwctl_siwpower(struct net_device *dev, struct iw_request_info *info,
1224                 struct iw_param *wrq, char *extra)
1225 {
1226         PSDevice pDevice = netdev_priv(dev);
1227         PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1228         int rc = 0;
1229
1230         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER \n");
1231
1232         if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
1233                 rc = -EINVAL;
1234                 return rc;
1235         }
1236
1237         if (wrq->disabled) {
1238                 pDevice->ePSMode = WMAC_POWER_CAM;
1239                 PSvDisablePowerSaving(pDevice);
1240                 return rc;
1241         }
1242         if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1243                 pDevice->ePSMode = WMAC_POWER_FAST;
1244                 PSvEnablePowerSaving((void *)pDevice, pMgmt->wListenInterval);
1245
1246         } else if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
1247                 pDevice->ePSMode = WMAC_POWER_FAST;
1248                 PSvEnablePowerSaving((void *)pDevice, pMgmt->wListenInterval);
1249         }
1250         switch (wrq->flags & IW_POWER_MODE) {
1251         case IW_POWER_UNICAST_R:
1252                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_UNICAST_R \n");
1253                 rc = -EINVAL;
1254                 break;
1255         case IW_POWER_ALL_R:
1256                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ALL_R \n");
1257                 rc = -EINVAL;
1258         case IW_POWER_ON:
1259                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ON \n");
1260                 break;
1261         default:
1262                 rc = -EINVAL;
1263         }
1264
1265         return rc;
1266 }
1267
1268 /*
1269  * Wireless Handler: get power mode
1270  */
1271 int iwctl_giwpower(struct net_device *dev, struct iw_request_info *info,
1272                 struct iw_param *wrq, char *extra)
1273 {
1274         PSDevice pDevice = netdev_priv(dev);
1275         PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1276         int mode = pDevice->ePSMode;
1277
1278         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPOWER \n");
1279
1280         if ((wrq->disabled = (mode == WMAC_POWER_CAM)))
1281                 return 0;
1282
1283         if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1284                 wrq->value = (int)((pMgmt->wListenInterval * pMgmt->wCurrBeaconPeriod) << 10);
1285                 wrq->flags = IW_POWER_TIMEOUT;
1286         } else {
1287                 wrq->value = (int)((pMgmt->wListenInterval * pMgmt->wCurrBeaconPeriod) << 10);
1288                 wrq->flags = IW_POWER_PERIOD;
1289         }
1290         wrq->flags |= IW_POWER_ALL_R;
1291         return 0;
1292 }
1293
1294 /*
1295  * Wireless Handler: get Sensitivity
1296  */
1297 int iwctl_giwsens(struct net_device *dev, struct iw_request_info *info,
1298                 struct iw_param *wrq, char *extra)
1299 {
1300         PSDevice pDevice = netdev_priv(dev);
1301         long ldBm;
1302
1303         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSENS \n");
1304         if (pDevice->bLinkPass == TRUE) {
1305                 RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm);
1306                 wrq->value = ldBm;
1307         } else {
1308                 wrq->value = 0;
1309         }
1310         wrq->disabled = (wrq->value == 0);
1311         wrq->fixed = 1;
1312         return 0;
1313 }
1314
1315 int iwctl_siwauth(struct net_device *dev, struct iw_request_info *info,
1316                 struct iw_param *wrq, char *extra)
1317 {
1318         PSDevice pDevice = netdev_priv(dev);
1319         PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1320         int ret = 0;
1321         static int wpa_version = 0; // must be static to save the last value, einsn liu
1322         static int pairwise = 0;
1323
1324         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH \n");
1325         switch (wrq->flags & IW_AUTH_INDEX) {
1326         case IW_AUTH_WPA_VERSION:
1327                 wpa_version = wrq->value;
1328                 if (wrq->value == IW_AUTH_WPA_VERSION_DISABLED) {
1329                         PRINT_K("iwctl_siwauth:set WPADEV to disable at 1??????\n");
1330                 } else if (wrq->value == IW_AUTH_WPA_VERSION_WPA) {
1331                         PRINT_K("iwctl_siwauth:set WPADEV to WPA1******\n");
1332                 } else {
1333                         PRINT_K("iwctl_siwauth:set WPADEV to WPA2******\n");
1334                 }
1335                 break;
1336         case IW_AUTH_CIPHER_PAIRWISE:
1337                 pairwise = wrq->value;
1338                 PRINT_K("iwctl_siwauth:set pairwise=%d\n", pairwise);
1339                 if (pairwise == IW_AUTH_CIPHER_CCMP){
1340                         pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1341                 } else if (pairwise == IW_AUTH_CIPHER_TKIP) {
1342                         pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1343                 } else if (pairwise == IW_AUTH_CIPHER_WEP40 ||
1344                         pairwise == IW_AUTH_CIPHER_WEP104) {
1345                         pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1346                 } else if (pairwise == IW_AUTH_CIPHER_NONE) {
1347                         // do nothing, einsn liu
1348                 } else {
1349                         pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1350                 }
1351                 break;
1352         case IW_AUTH_CIPHER_GROUP:
1353                 PRINT_K("iwctl_siwauth:set GROUP=%d\n", wrq->value);
1354                 if (wpa_version == IW_AUTH_WPA_VERSION_DISABLED)
1355                         break;
1356                 if (pairwise == IW_AUTH_CIPHER_NONE) {
1357                         if (wrq->value == IW_AUTH_CIPHER_CCMP)
1358                                 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1359                         else
1360                                 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1361                 }
1362                 break;
1363         case IW_AUTH_KEY_MGMT:
1364                 PRINT_K("iwctl_siwauth(wpa_version=%d):set KEY_MGMT=%d\n", wpa_version,wrq->value);
1365                 if (wpa_version == IW_AUTH_WPA_VERSION_WPA2){
1366                         if (wrq->value == IW_AUTH_KEY_MGMT_PSK)
1367                                 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
1368                         else pMgmt->eAuthenMode = WMAC_AUTH_WPA2;
1369                 } else if (wpa_version == IW_AUTH_WPA_VERSION_WPA) {
1370                         if (wrq->value == 0){
1371                                 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
1372                         } else if (wrq->value == IW_AUTH_KEY_MGMT_PSK)
1373                                 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
1374                 } else {
1375                         pMgmt->eAuthenMode = WMAC_AUTH_WPA;
1376                 }
1377                 break;
1378         case IW_AUTH_TKIP_COUNTERMEASURES:
1379                 break; /* FIXME */
1380         case IW_AUTH_DROP_UNENCRYPTED:
1381                 break;
1382         case IW_AUTH_80211_AUTH_ALG:
1383                 PRINT_K("iwctl_siwauth:set AUTH_ALG=%d\n", wrq->value);
1384                 if (wrq->value == IW_AUTH_ALG_OPEN_SYSTEM)
1385                         pMgmt->bShareKeyAlgorithm = FALSE;
1386                 else if (wrq->value == IW_AUTH_ALG_SHARED_KEY)
1387                         pMgmt->bShareKeyAlgorithm = TRUE;
1388                 break;
1389         case IW_AUTH_WPA_ENABLED:
1390                 break;
1391         case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1392                 break;
1393         case IW_AUTH_ROAMING_CONTROL:
1394                 ret = -EOPNOTSUPP;
1395                 break;
1396         case IW_AUTH_PRIVACY_INVOKED:
1397                 pDevice->bEncryptionEnable = !!wrq->value;
1398                 if (pDevice->bEncryptionEnable == FALSE) {
1399                         wpa_version = 0;
1400                         pairwise = 0;
1401                         pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1402                         pMgmt->bShareKeyAlgorithm = FALSE;
1403                         pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
1404                         PRINT_K("iwctl_siwauth:set WPADEV to disaable at 2?????\n");
1405                 }
1406                 break;
1407         default:
1408                 ret = -EOPNOTSUPP;
1409                 break;
1410         }
1411         return ret;
1412 }
1413
1414 int iwctl_giwauth(struct net_device *dev, struct iw_request_info *info,
1415                 struct iw_param *wrq, char *extra)
1416 {
1417         return -EOPNOTSUPP;
1418 }
1419
1420 int iwctl_siwgenie(struct net_device *dev, struct iw_request_info *info,
1421                 struct iw_point *wrq, char *extra)
1422 {
1423         PSDevice pDevice = netdev_priv(dev);
1424         PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1425         int ret = 0;
1426
1427         if (wrq->length){
1428                 if ((wrq->length < 2) || (extra[1] + 2 != wrq->length)) {
1429                         ret = -EINVAL;
1430                         goto out;
1431                 }
1432                 if (wrq->length > MAX_WPA_IE_LEN){
1433                         ret = -ENOMEM;
1434                         goto out;
1435                 }
1436                 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
1437                 if (copy_from_user(pMgmt->abyWPAIE, extra, wrq->length)){
1438                         ret = -EFAULT;
1439                         goto out;
1440                 }
1441                 pMgmt->wWPAIELen = wrq->length;
1442         } else {
1443                 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
1444                 pMgmt->wWPAIELen = 0;
1445         }
1446
1447 out: // not completely ...not necessary in wpa_supplicant 0.5.8
1448         return ret;
1449 }
1450
1451 int iwctl_giwgenie(struct net_device *dev, struct iw_request_info *info,
1452                 struct iw_point *wrq, char *extra)
1453 {
1454         PSDevice pDevice = netdev_priv(dev);
1455         PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1456         int ret = 0;
1457         int space = wrq->length;
1458
1459         wrq->length = 0;
1460         if (pMgmt->wWPAIELen > 0) {
1461                 wrq->length = pMgmt->wWPAIELen;
1462                 if (pMgmt->wWPAIELen <= space) {
1463                         if (copy_to_user(extra, pMgmt->abyWPAIE, pMgmt->wWPAIELen)) {
1464                                 ret = -EFAULT;
1465                         }
1466                 } else {
1467                         ret = -E2BIG;
1468                 }
1469         }
1470         return ret;
1471 }
1472
1473 int iwctl_siwencodeext(struct net_device *dev, struct iw_request_info *info,
1474                 struct iw_point *wrq, char *extra)
1475 {
1476         PSDevice pDevice = netdev_priv(dev);
1477         PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1478         struct iw_encode_ext *ext = (struct iw_encode_ext*)extra;
1479         struct viawget_wpa_param *param=NULL;
1480 // original member
1481         wpa_alg alg_name;
1482         u8 addr[6];
1483         int key_idx;
1484         int set_tx = 0;
1485         u8 seq[IW_ENCODE_SEQ_MAX_SIZE];
1486         u8 key[64];
1487         size_t seq_len = 0;
1488         size_t key_len = 0;
1489         u8 *buf;
1490         u8 key_array[64];
1491         int ret = 0;
1492
1493         PRINT_K("SIOCSIWENCODEEXT......\n");
1494
1495         buf = kzalloc(sizeof(struct viawget_wpa_param), GFP_KERNEL);
1496         if (buf == NULL)
1497                 return -ENOMEM;
1498
1499         param = (struct viawget_wpa_param *)buf;
1500
1501 // recover alg_name
1502         switch (ext->alg) {
1503         case IW_ENCODE_ALG_NONE:
1504                 alg_name = WPA_ALG_NONE;
1505                 break;
1506         case IW_ENCODE_ALG_WEP:
1507                 alg_name = WPA_ALG_WEP;
1508                 break;
1509         case IW_ENCODE_ALG_TKIP:
1510                 alg_name = WPA_ALG_TKIP;
1511                 break;
1512         case IW_ENCODE_ALG_CCMP:
1513                 alg_name = WPA_ALG_CCMP;
1514                 break;
1515         default:
1516                 PRINT_K("Unknown alg = %d\n",ext->alg);
1517                 ret= -ENOMEM;
1518                 goto error;
1519         }
1520 // recover addr
1521         memcpy(addr, ext->addr.sa_data, ETH_ALEN);
1522 // recover key_idx
1523         key_idx = (wrq->flags&IW_ENCODE_INDEX) - 1;
1524 // recover set_tx
1525         if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
1526                 set_tx = 1;
1527 // recover seq,seq_len
1528         if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
1529                 seq_len=IW_ENCODE_SEQ_MAX_SIZE;
1530                 memcpy(seq, ext->rx_seq, seq_len);
1531         }
1532 // recover key,key_len
1533         if (ext->key_len) {
1534                 key_len = ext->key_len;
1535                 memcpy(key, &ext->key[0], key_len);
1536         }
1537         memset(key_array, 0, 64);
1538         if (key_len > 0) {
1539                 memcpy(key_array, key, key_len);
1540                 if (key_len == 32) {
1541                         // notice ! the oder
1542                         memcpy(&key_array[16], &key[24], 8);
1543                         memcpy(&key_array[24], &key[16], 8);
1544                 }
1545         }
1546
1547 /**************Translate iw_encode_ext to viawget_wpa_param****************/
1548         memcpy(param->addr, addr, ETH_ALEN);
1549         param->u.wpa_key.alg_name = (int)alg_name;
1550         param->u.wpa_key.set_tx = set_tx;
1551         param->u.wpa_key.key_index = key_idx;
1552         param->u.wpa_key.key_len = key_len;
1553         param->u.wpa_key.key = (u8 *)key_array;
1554         param->u.wpa_key.seq = (u8 *)seq;
1555         param->u.wpa_key.seq_len = seq_len;
1556
1557 /****set if current action is Network Manager count?? */
1558 /****this method is so foolish,but there is no other way??? */
1559         if (param->u.wpa_key.alg_name == WPA_ALG_NONE) {
1560                 if (param->u.wpa_key.key_index ==0) {
1561                         pDevice->bwextstep0 = TRUE;
1562                 }
1563                 if ((pDevice->bwextstep0 == TRUE) && (param->u.wpa_key.key_index == 1)) {
1564                         pDevice->bwextstep0 = FALSE;
1565                         pDevice->bwextstep1 = TRUE;
1566                 }
1567                 if ((pDevice->bwextstep1 == TRUE) && (param->u.wpa_key.key_index == 2)) {
1568                         pDevice->bwextstep1 = FALSE;
1569                         pDevice->bwextstep2 = TRUE;
1570                 }
1571                 if ((pDevice->bwextstep2 == TRUE) && (param->u.wpa_key.key_index == 3)) {
1572                         pDevice->bwextstep2 = FALSE;
1573                         pDevice->bwextstep3 = TRUE;
1574                 }
1575         }
1576         if (pDevice->bwextstep3 == TRUE) {
1577                 PRINT_K("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n");
1578                 pDevice->bwextstep0 = FALSE;
1579                 pDevice->bwextstep1 = FALSE;
1580                 pDevice->bwextstep2 = FALSE;
1581                 pDevice->bwextstep3 = FALSE;
1582                 pDevice->bWPASuppWextEnabled = TRUE;
1583                 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
1584                 KeyvInitTable(pDevice, &pDevice->sKey);
1585         }
1586 /*******/
1587         spin_lock_irq(&pDevice->lock);
1588         ret = wpa_set_keys(pDevice, param, TRUE);
1589         spin_unlock_irq(&pDevice->lock);
1590
1591 error:
1592         kfree(buf);
1593         return ret;
1594 }
1595
1596 int iwctl_giwencodeext(struct net_device *dev, struct iw_request_info *info,
1597                 struct iw_point *wrq, char *extra)
1598 {
1599         return -EOPNOTSUPP;
1600 }
1601
1602 int iwctl_siwmlme(struct net_device *dev, struct iw_request_info *info,
1603                 struct iw_point *wrq, char *extra)
1604 {
1605         PSDevice pDevice = netdev_priv(dev);
1606         PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1607         struct iw_mlme *mlme = (struct iw_mlme *)extra;
1608         int ret = 0;
1609
1610         if (memcmp(pMgmt->abyCurrBSSID, mlme->addr.sa_data, ETH_ALEN)) {
1611                 ret = -EINVAL;
1612                 return ret;
1613         }
1614         switch (mlme->cmd){
1615         case IW_MLME_DEAUTH:
1616         case IW_MLME_DISASSOC:
1617                 if (pDevice->bLinkPass == TRUE) {
1618                         PRINT_K("iwctl_siwmlme--->send DISASSOCIATE\n");
1619                         bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE,
1620                                         NULL);
1621                 }
1622                 break;
1623         default:
1624                 ret = -EOPNOTSUPP;
1625         }
1626         return ret;
1627 }
1628
1629 static const iw_handler iwctl_handler[] = {
1630         (iw_handler)NULL, // SIOCSIWCOMMIT
1631         (iw_handler)NULL, // SIOCGIWNAME
1632         (iw_handler)NULL, // SIOCSIWNWID
1633         (iw_handler)NULL, // SIOCGIWNWID
1634         (iw_handler)NULL, // SIOCSIWFREQ
1635         (iw_handler)NULL, // SIOCGIWFREQ
1636         (iw_handler)NULL, // SIOCSIWMODE
1637         (iw_handler)NULL, // SIOCGIWMODE
1638         (iw_handler)NULL, // SIOCSIWSENS
1639         (iw_handler)NULL, // SIOCGIWSENS
1640         (iw_handler)NULL, // SIOCSIWRANGE
1641         (iw_handler)iwctl_giwrange, // SIOCGIWRANGE
1642         (iw_handler)NULL, // SIOCSIWPRIV
1643         (iw_handler)NULL, // SIOCGIWPRIV
1644         (iw_handler)NULL, // SIOCSIWSTATS
1645         (iw_handler)NULL, // SIOCGIWSTATS
1646         (iw_handler)NULL, // SIOCSIWSPY
1647         (iw_handler)NULL, // SIOCGIWSPY
1648         (iw_handler)NULL, // -- hole --
1649         (iw_handler)NULL, // -- hole --
1650         (iw_handler)NULL, // SIOCSIWAP
1651         (iw_handler)NULL, // SIOCGIWAP
1652         (iw_handler)NULL, // -- hole -- 0x16
1653         (iw_handler)NULL, // SIOCGIWAPLIST
1654         (iw_handler)iwctl_siwscan, // SIOCSIWSCAN
1655         (iw_handler)iwctl_giwscan, // SIOCGIWSCAN
1656         (iw_handler)NULL, // SIOCSIWESSID
1657         (iw_handler)NULL, // SIOCGIWESSID
1658         (iw_handler)NULL, // SIOCSIWNICKN
1659         (iw_handler)NULL, // SIOCGIWNICKN
1660         (iw_handler)NULL, // -- hole --
1661         (iw_handler)NULL, // -- hole --
1662         (iw_handler)NULL, // SIOCSIWRATE 0x20
1663         (iw_handler)NULL, // SIOCGIWRATE
1664         (iw_handler)NULL, // SIOCSIWRTS
1665         (iw_handler)NULL, // SIOCGIWRTS
1666         (iw_handler)NULL, // SIOCSIWFRAG
1667         (iw_handler)NULL, // SIOCGIWFRAG
1668         (iw_handler)NULL, // SIOCSIWTXPOW
1669         (iw_handler)NULL, // SIOCGIWTXPOW
1670         (iw_handler)NULL, // SIOCSIWRETRY
1671         (iw_handler)NULL, // SIOCGIWRETRY
1672         (iw_handler)NULL, // SIOCSIWENCODE
1673         (iw_handler)NULL, // SIOCGIWENCODE
1674         (iw_handler)NULL, // SIOCSIWPOWER
1675         (iw_handler)NULL, // SIOCGIWPOWER
1676         (iw_handler)NULL, // -- hole --
1677         (iw_handler)NULL, // -- hole --
1678         (iw_handler)NULL, // SIOCSIWGENIE
1679         (iw_handler)NULL, // SIOCGIWGENIE
1680         (iw_handler)NULL, // SIOCSIWAUTH
1681         (iw_handler)NULL, // SIOCGIWAUTH
1682         (iw_handler)NULL, // SIOCSIWENCODEEXT
1683         (iw_handler)NULL, // SIOCGIWENCODEEXT
1684         (iw_handler)NULL, // SIOCSIWPMKSA
1685         (iw_handler)NULL, // -- hole --
1686 };
1687
1688 static const iw_handler iwctl_private_handler[] = {
1689         NULL, // SIOCIWFIRSTPRIV
1690 };
1691
1692 struct iw_priv_args iwctl_private_args[] = {
1693         { IOCTL_CMD_SET, IW_PRIV_TYPE_CHAR | 1024, 0, "set" },
1694 };
1695
1696 const struct iw_handler_def iwctl_handler_def = {
1697         .get_wireless_stats     = &iwctl_get_wireless_stats,
1698         .num_standard           = sizeof(iwctl_handler) / sizeof(iw_handler),
1699         .num_private            = 0,
1700         .num_private_args       = 0,
1701         .standard               = (iw_handler *)iwctl_handler,
1702         .private                = NULL,
1703         .private_args           = NULL,
1704 };