x86/amd-iommu: Add function to complete a tlb flush
[linux/fpc-iii.git] / drivers / staging / vt6655 / iwctl.c
blob108830ff3b328d9d7a4717fcb71b645eac7502d0
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
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.
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.
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.
19 * File: iwctl.c
21 * Purpose: wireless ext & ioctl functions
23 * Author: Lyndon Chen
25 * Date: July 5, 2006
27 * Functions:
29 * Revision History:
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"
42 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
43 #include "iowpa.h"
44 #include "wpactl.h"
45 #endif
47 #include <net/iw_handler.h>
48 extern WORD TxRate_iwconfig;//2008-5-8 <add> by chester
50 /*--------------------- Static Definitions -------------------------*/
52 //2008-0409-07, <Add> by Einsn Liu
53 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
54 #define SUPPORTED_WIRELESS_EXT 18
55 #else
56 #define SUPPORTED_WIRELESS_EXT 17
57 #endif
59 static const long frequency_list[] = {
60 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
61 4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
62 5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210, 5220, 5230, 5240,
63 5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680,
64 5700, 5745, 5765, 5785, 5805, 5825
68 /*--------------------- Static Classes ----------------------------*/
71 //static int msglevel =MSG_LEVEL_DEBUG;
72 static int msglevel =MSG_LEVEL_INFO;
75 /*--------------------- Static Variables --------------------------*/
76 /*--------------------- Static Functions --------------------------*/
78 /*--------------------- Export Variables --------------------------*/
80 struct iw_statistics *iwctl_get_wireless_stats(struct net_device *dev)
82 PSDevice pDevice = netdev_priv(dev);
83 long ldBm;
85 pDevice->wstats.status = pDevice->eOPMode;
86 #ifdef Calcu_LinkQual
87 #if 0
88 if(pDevice->byBBType == BB_TYPE_11B) {
89 if(pDevice->byCurrSQ > 120)
90 pDevice->scStatistic.LinkQuality = 100;
91 else
92 pDevice->scStatistic.LinkQuality = pDevice->byCurrSQ*100/120;
94 else if(pDevice->byBBType == BB_TYPE_11G) {
95 if(pDevice->byCurrSQ < 20)
96 pDevice->scStatistic.LinkQuality = 100;
97 else if(pDevice->byCurrSQ >96)
98 pDevice->scStatistic.LinkQuality = 0;
99 else
100 pDevice->scStatistic.LinkQuality = (96-pDevice->byCurrSQ)*100/76;
102 if(pDevice->bLinkPass !=TRUE)
103 pDevice->scStatistic.LinkQuality = 0;
104 #endif
105 if(pDevice->scStatistic.LinkQuality > 100)
106 pDevice->scStatistic.LinkQuality = 100;
107 pDevice->wstats.qual.qual =(BYTE) pDevice->scStatistic.LinkQuality;
108 #else
109 pDevice->wstats.qual.qual = pDevice->byCurrSQ;
110 #endif
111 RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm);
112 pDevice->wstats.qual.level = ldBm;
113 //pDevice->wstats.qual.level = 0x100 - pDevice->uCurrRSSI;
114 pDevice->wstats.qual.noise = 0;
115 pDevice->wstats.qual.updated = 1;
116 pDevice->wstats.discard.nwid = 0;
117 pDevice->wstats.discard.code = 0;
118 pDevice->wstats.discard.fragment = 0;
119 pDevice->wstats.discard.retries = (U32)pDevice->scStatistic.dwTsrErr;
120 pDevice->wstats.discard.misc = 0;
121 pDevice->wstats.miss.beacon = 0;
123 return &pDevice->wstats;
128 /*------------------------------------------------------------------*/
131 static int iwctl_commit(struct net_device *dev,
132 struct iw_request_info *info,
133 void *wrq,
134 char *extra)
136 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWCOMMIT \n");
138 return 0;
142 * Wireless Handler : get protocol name
145 int iwctl_giwname(struct net_device *dev,
146 struct iw_request_info *info,
147 char *wrq,
148 char *extra)
150 strcpy(wrq, "802.11-a/b/g");
151 return 0;
154 int iwctl_giwnwid(struct net_device *dev,
155 struct iw_request_info *info,
156 struct iw_param *wrq,
157 char *extra)
159 //wrq->value = 0x100;
160 //wrq->disabled = 0;
161 //wrq->fixed = 1;
162 //return 0;
163 return -EOPNOTSUPP;
167 * Wireless Handler : set scan
170 int iwctl_siwscan(struct net_device *dev,
171 struct iw_request_info *info,
172 struct iw_point *wrq,
173 char *extra)
175 PSDevice pDevice = (PSDevice)netdev_priv(dev);
176 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
177 struct iw_scan_req *req = (struct iw_scan_req *)extra;
178 BYTE abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
179 PWLAN_IE_SSID pItemSSID=NULL;
180 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSCAN \n");
183 if(pDevice->byReAssocCount > 0) { //reject scan when re-associating!
184 //send scan event to wpa_Supplicant
185 union iwreq_data wrqu;
186 PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
187 memset(&wrqu, 0, sizeof(wrqu));
188 wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
189 return 0;
192 spin_lock_irq(&pDevice->lock);
193 BSSvClearBSSList((HANDLE)pDevice, pDevice->bLinkPass);
195 //mike add: active scan OR passive scan OR desire_ssid scan
196 if(wrq->length == sizeof(struct iw_scan_req)) {
197 if (wrq->flags & IW_SCAN_THIS_ESSID) { //desire_ssid scan
198 memset(abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
199 pItemSSID = (PWLAN_IE_SSID)abyScanSSID;
200 pItemSSID->byElementID = WLAN_EID_SSID;
201 memcpy(pItemSSID->abySSID, req->essid, (int)req->essid_len);
202 if (pItemSSID->abySSID[req->essid_len - 1] == '\0') {
203 if(req->essid_len>0)
204 pItemSSID->len = req->essid_len - 1;
206 else
207 pItemSSID->len = req->essid_len;
208 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
209 PRINT_K("SIOCSIWSCAN:[desired_ssid=%s,len=%d]\n",((PWLAN_IE_SSID)abyScanSSID)->abySSID,
210 ((PWLAN_IE_SSID)abyScanSSID)->len);
211 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID);
212 spin_unlock_irq(&pDevice->lock);
214 return 0;
216 else if(req->scan_type == IW_SCAN_TYPE_PASSIVE) { //passive scan
217 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
220 else { //active scan
221 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
224 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
225 //printk("SIOCSIWSCAN:WLAN_CMD_BSSID_SCAN\n");
226 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
227 spin_unlock_irq(&pDevice->lock);
229 return 0;
234 * Wireless Handler : get scan results
237 int iwctl_giwscan(struct net_device *dev,
238 struct iw_request_info *info,
239 struct iw_point *wrq,
240 char *extra)
242 int ii, jj, kk;
243 PSDevice pDevice = (PSDevice)netdev_priv(dev);
244 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
245 PKnownBSS pBSS;
246 PWLAN_IE_SSID pItemSSID;
247 PWLAN_IE_SUPP_RATES pSuppRates, pExtSuppRates;
248 char *current_ev = extra;
249 char *end_buf = extra + IW_SCAN_MAX_DATA;
250 char *current_val = NULL;
251 struct iw_event iwe;
252 long ldBm;
253 char buf[MAX_WPA_IE_LEN * 2 + 30];
256 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSCAN \n");
258 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
259 // In scanning..
260 return -EAGAIN;
262 pBSS = &(pMgmt->sBSSList[0]);
263 for (ii = 0, jj = 0; jj < MAX_BSS_NUM ; jj++) {
264 if (current_ev >= end_buf)
265 break;
266 pBSS = &(pMgmt->sBSSList[jj]);
267 if (pBSS->bActive) {
268 //ADD mac address
269 memset(&iwe, 0, sizeof(iwe));
270 iwe.cmd = SIOCGIWAP;
271 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
272 memcpy(iwe.u.ap_addr.sa_data, pBSS->abyBSSID, WLAN_BSSID_LEN);
273 current_ev = iwe_stream_add_event(info,current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);
274 //ADD ssid
275 memset(&iwe, 0, sizeof(iwe));
276 iwe.cmd = SIOCGIWESSID;
277 pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
278 iwe.u.data.length = pItemSSID->len;
279 iwe.u.data.flags = 1;
280 current_ev = iwe_stream_add_point(info,current_ev,end_buf, &iwe, pItemSSID->abySSID);
281 //ADD mode
282 memset(&iwe, 0, sizeof(iwe));
283 iwe.cmd = SIOCGIWMODE;
284 if (WLAN_GET_CAP_INFO_ESS(pBSS->wCapInfo)) {
285 iwe.u.mode = IW_MODE_INFRA;
287 else {
288 iwe.u.mode = IW_MODE_ADHOC;
290 iwe.len = IW_EV_UINT_LEN;
291 current_ev = iwe_stream_add_event(info,current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
292 //ADD frequency
293 pSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abySuppRates;
294 pExtSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abyExtSuppRates;
295 memset(&iwe, 0, sizeof(iwe));
296 iwe.cmd = SIOCGIWFREQ;
297 iwe.u.freq.m = pBSS->uChannel;
298 iwe.u.freq.e = 0;
299 iwe.u.freq.i = 0;
300 current_ev = iwe_stream_add_event(info,current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
301 //2008-0409-04, <Add> by Einsn Liu
303 int f = (int)pBSS->uChannel - 1;
304 if(f < 0)f = 0;
305 iwe.u.freq.m = frequency_list[f] * 100000;
306 iwe.u.freq.e = 1;
308 current_ev = iwe_stream_add_event(info,current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
309 //ADD quality
310 memset(&iwe, 0, sizeof(iwe));
311 iwe.cmd = IWEVQUAL;
312 RFvRSSITodBm(pDevice, (BYTE)(pBSS->uRSSI), &ldBm);
313 iwe.u.qual.level = ldBm;
314 iwe.u.qual.noise = 0;
315 //2008-0409-01, <Add> by Einsn Liu
316 if(-ldBm<50){
317 iwe.u.qual.qual = 100;
318 }else if(-ldBm > 90) {
319 iwe.u.qual.qual = 0;
320 }else {
321 iwe.u.qual.qual=(40-(-ldBm-50))*100/40;
323 iwe.u.qual.updated=7;
325 // iwe.u.qual.qual = 0;
326 current_ev = iwe_stream_add_event(info,current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
328 memset(&iwe, 0, sizeof(iwe));
329 iwe.cmd = SIOCGIWENCODE;
330 iwe.u.data.length = 0;
331 if (WLAN_GET_CAP_INFO_PRIVACY(pBSS->wCapInfo)) {
332 iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
333 }else {
334 iwe.u.data.flags = IW_ENCODE_DISABLED;
336 current_ev = iwe_stream_add_point(info,current_ev,end_buf, &iwe, pItemSSID->abySSID);
338 memset(&iwe, 0, sizeof(iwe));
339 iwe.cmd = SIOCGIWRATE;
340 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
341 current_val = current_ev + IW_EV_LCP_LEN;
343 for (kk = 0 ; kk < 12 ; kk++) {
344 if (pSuppRates->abyRates[kk] == 0)
345 break;
346 // Bit rate given in 500 kb/s units (+ 0x80)
347 iwe.u.bitrate.value = ((pSuppRates->abyRates[kk] & 0x7f) * 500000);
348 current_val = iwe_stream_add_value(info,current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
350 for (kk = 0 ; kk < 8 ; kk++) {
351 if (pExtSuppRates->abyRates[kk] == 0)
352 break;
353 // Bit rate given in 500 kb/s units (+ 0x80)
354 iwe.u.bitrate.value = ((pExtSuppRates->abyRates[kk] & 0x7f) * 500000);
355 current_val = iwe_stream_add_value(info,current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
358 if((current_val - current_ev) > IW_EV_LCP_LEN)
359 current_ev = current_val;
361 memset(&iwe, 0, sizeof(iwe));
362 iwe.cmd = IWEVCUSTOM;
363 sprintf(buf, "bcn_int=%d", pBSS->wBeaconInterval);
364 iwe.u.data.length = strlen(buf);
365 current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, buf);
367 if ((pBSS->wWPALen > 0) && (pBSS->wWPALen <= MAX_WPA_IE_LEN)) {
368 memset(&iwe, 0, sizeof(iwe));
369 iwe.cmd = IWEVGENIE;
370 iwe.u.data.length = pBSS->wWPALen;
371 current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, pBSS->byWPAIE);
374 if ((pBSS->wRSNLen > 0) && (pBSS->wRSNLen <= MAX_WPA_IE_LEN)) {
375 memset(&iwe, 0, sizeof(iwe));
376 iwe.cmd = IWEVGENIE;
377 iwe.u.data.length = pBSS->wRSNLen;
378 current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, pBSS->byRSNIE);
382 }// for
384 wrq->length = current_ev - extra;
385 return 0;
391 * Wireless Handler : set frequence or channel
394 int iwctl_siwfreq(struct net_device *dev,
395 struct iw_request_info *info,
396 struct iw_freq *wrq,
397 char *extra)
399 PSDevice pDevice = (PSDevice)netdev_priv(dev);
400 int rc = 0;
402 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFREQ \n");
404 // If setting by frequency, convert to a channel
405 if((wrq->e == 1) &&
406 (wrq->m >= (int) 2.412e8) &&
407 (wrq->m <= (int) 2.487e8)) {
408 int f = wrq->m / 100000;
409 int c = 0;
410 while((c < 14) && (f != frequency_list[c]))
411 c++;
412 wrq->e = 0;
413 wrq->m = c + 1;
415 // Setting by channel number
416 if((wrq->m > 14) || (wrq->e > 0))
417 rc = -EOPNOTSUPP;
418 else {
419 int channel = wrq->m;
420 if((channel < 1) || (channel > 14)) {
421 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: New channel value of %d is invalid!\n", dev->name, wrq->m);
422 rc = -EINVAL;
423 } else {
424 // Yes ! We can set it !!!
425 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Set to channel = %d\n", channel);
426 pDevice->uChannel = channel;
427 //2007-0207-04,<Add> by EinsnLiu
428 //Make change effect at once
429 pDevice->bCommit = TRUE;
433 return rc;
437 * Wireless Handler : get frequence or channel
440 int iwctl_giwfreq(struct net_device *dev,
441 struct iw_request_info *info,
442 struct iw_freq *wrq,
443 char *extra)
445 PSDevice pDevice = (PSDevice)netdev_priv(dev);
446 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
448 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFREQ \n");
450 #ifdef WEXT_USECHANNELS
451 wrq->m = (int)pMgmt->uCurrChannel;
452 wrq->e = 0;
453 #else
455 int f = (int)pMgmt->uCurrChannel - 1;
456 if(f < 0)
457 f = 0;
458 wrq->m = frequency_list[f] * 100000;
459 wrq->e = 1;
461 #endif
463 return 0;
467 * Wireless Handler : set operation mode
470 int iwctl_siwmode(struct net_device *dev,
471 struct iw_request_info *info,
472 __u32 *wmode,
473 char *extra)
475 PSDevice pDevice = (PSDevice)netdev_priv(dev);
476 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
477 int rc = 0;
479 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMODE \n");
481 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP && pDevice->bEnableHostapd) {
482 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Can't set operation mode, hostapd is running \n");
483 return rc;
486 switch(*wmode) {
488 case IW_MODE_ADHOC:
489 if (pMgmt->eConfigMode != WMAC_CONFIG_IBSS_STA) {
490 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
491 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
492 pDevice->bCommit = TRUE;
495 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to ad-hoc \n");
496 break;
497 case IW_MODE_AUTO:
498 case IW_MODE_INFRA:
499 if (pMgmt->eConfigMode != WMAC_CONFIG_ESS_STA) {
500 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
501 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
502 pDevice->bCommit = TRUE;
505 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to infrastructure \n");
506 break;
507 case IW_MODE_MASTER:
509 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
510 rc = -EOPNOTSUPP;
511 break;
513 if (pMgmt->eConfigMode != WMAC_CONFIG_AP) {
514 pMgmt->eConfigMode = WMAC_CONFIG_AP;
515 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
516 pDevice->bCommit = TRUE;
519 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to Access Point \n");
520 break;
522 case IW_MODE_REPEAT:
523 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
524 rc = -EOPNOTSUPP;
525 break;
526 default:
527 rc = -EINVAL;
530 return rc;
534 * Wireless Handler : get operation mode
537 int iwctl_giwmode(struct net_device *dev,
538 struct iw_request_info *info,
539 __u32 *wmode,
540 char *extra)
542 PSDevice pDevice = (PSDevice)netdev_priv(dev);
543 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
546 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWMODE \n");
547 // If not managed, assume it's ad-hoc
548 switch (pMgmt->eConfigMode) {
549 case WMAC_CONFIG_ESS_STA:
550 *wmode = IW_MODE_INFRA;
551 break;
552 case WMAC_CONFIG_IBSS_STA:
553 *wmode = IW_MODE_ADHOC;
554 break;
555 case WMAC_CONFIG_AUTO:
556 *wmode = IW_MODE_INFRA;
557 break;
558 case WMAC_CONFIG_AP:
559 *wmode = IW_MODE_MASTER;
560 break;
561 default:
562 *wmode = IW_MODE_ADHOC;
565 return 0;
570 * Wireless Handler : get capability range
573 int iwctl_giwrange(struct net_device *dev,
574 struct iw_request_info *info,
575 struct iw_point *wrq,
576 char *extra)
578 struct iw_range *range = (struct iw_range *) extra;
579 int i,k;
580 BYTE abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
583 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRANGE \n");
584 if (wrq->pointer) {
585 wrq->length = sizeof(struct iw_range);
586 memset(range, 0, sizeof(struct iw_range));
587 range->min_nwid = 0x0000;
588 range->max_nwid = 0x0000;
589 range->num_channels = 14;
590 // Should be based on cap_rid.country to give only
591 // what the current card support
592 k = 0;
593 for(i = 0; i < 14; i++) {
594 range->freq[k].i = i + 1; // List index
595 range->freq[k].m = frequency_list[i] * 100000;
596 range->freq[k++].e = 1; // Values in table in MHz -> * 10^5 * 10
598 range->num_frequency = k;
599 // Hum... Should put the right values there
600 #ifdef Calcu_LinkQual
601 range->max_qual.qual = 100;
602 #else
603 range->max_qual.qual = 255;
604 #endif
605 range->max_qual.level = 0;
606 range->max_qual.noise = 0;
607 range->sensitivity = 255;
609 for(i = 0 ; i < 13 ; i++) {
610 range->bitrate[i] = abySupportedRates[i] * 500000;
611 if(range->bitrate[i] == 0)
612 break;
614 range->num_bitrates = i;
616 // Set an indication of the max TCP throughput
617 // in bit/s that we can expect using this interface.
618 // May be use for QoS stuff... Jean II
619 if(i > 2)
620 range->throughput = 5 * 1000 * 1000;
621 else
622 range->throughput = 1.5 * 1000 * 1000;
624 range->min_rts = 0;
625 range->max_rts = 2312;
626 range->min_frag = 256;
627 range->max_frag = 2312;
630 // the encoding capabilities
631 range->num_encoding_sizes = 3;
632 // 64(40) bits WEP
633 range->encoding_size[0] = 5;
634 // 128(104) bits WEP
635 range->encoding_size[1] = 13;
636 // 256 bits for WPA-PSK
637 range->encoding_size[2] = 32;
638 // 4 keys are allowed
639 range->max_encoding_tokens = 4;
641 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
642 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
644 range->min_pmp = 0;
645 range->max_pmp = 1000000;// 1 secs
646 range->min_pmt = 0;
647 range->max_pmt = 1000000;// 1 secs
648 range->pmp_flags = IW_POWER_PERIOD;
649 range->pmt_flags = IW_POWER_TIMEOUT;
650 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
652 // Transmit Power - values are in mW
654 range->txpower[0] = 100;
655 range->num_txpower = 1;
656 range->txpower_capa = IW_TXPOW_MWATT;
657 range->we_version_source = SUPPORTED_WIRELESS_EXT;
658 range->we_version_compiled = WIRELESS_EXT;
659 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
660 range->retry_flags = IW_RETRY_LIMIT;
661 range->r_time_flags = IW_RETRY_LIFETIME;
662 range->min_retry = 1;
663 range->max_retry = 65535;
664 range->min_r_time = 1024;
665 range->max_r_time = 65535 * 1024;
666 // Experimental measurements - boundary 11/5.5 Mb/s
667 // Note : with or without the (local->rssi), results
668 // are somewhat different. - Jean II
669 range->avg_qual.qual = 6;
670 range->avg_qual.level = 176; // -80 dBm
671 range->avg_qual.noise = 0;
675 return 0;
680 * Wireless Handler : set ap mac address
683 int iwctl_siwap(struct net_device *dev,
684 struct iw_request_info *info,
685 struct sockaddr *wrq,
686 char *extra)
688 PSDevice pDevice = (PSDevice)netdev_priv(dev);
689 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
690 int rc = 0;
691 BYTE ZeroBSSID[WLAN_BSSID_LEN]={0x00,0x00,0x00,0x00,0x00,0x00};
693 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAP \n");
694 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
695 // In scanning..
696 printk("SIOCSIWAP(??)-->In scanning...\n");
697 // return -EAGAIN;
699 if (wrq->sa_family != ARPHRD_ETHER)
700 rc = -EINVAL;
701 else {
702 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
703 memcpy(pMgmt->abyDesireBSSID, wrq->sa_data, 6);
704 //2008-0409-05, <Add> by Einsn Liu
705 if((pDevice->bLinkPass == TRUE) &&
706 (memcmp(pMgmt->abyDesireBSSID, pMgmt->abyCurrBSSID, 6)== 0)){
707 return rc;
709 //mike :add
710 if ((IS_BROADCAST_ADDRESS(pMgmt->abyDesireBSSID)) ||
711 (memcmp(pMgmt->abyDesireBSSID, ZeroBSSID, 6) == 0)){
712 PRINT_K("SIOCSIWAP:invalid desired BSSID return!\n");
713 return rc;
715 //mike add: if desired AP is hidden ssid(there are two same BSSID in list),
716 // then ignore,because you don't known which one to be connect with??
718 UINT ii , uSameBssidNum=0;
719 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
720 if (pMgmt->sBSSList[ii].bActive &&
721 IS_ETH_ADDRESS_EQUAL(pMgmt->sBSSList[ii].abyBSSID,pMgmt->abyDesireBSSID)) {
722 uSameBssidNum++;
725 if(uSameBssidNum >= 2) { //hit: desired AP is in hidden ssid mode!!!
726 PRINT_K("SIOCSIWAP:ignore for desired AP in hidden mode\n");
727 return rc;
731 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
732 pDevice->bCommit = TRUE;
735 return rc;
739 * Wireless Handler : get ap mac address
742 int iwctl_giwap(struct net_device *dev,
743 struct iw_request_info *info,
744 struct sockaddr *wrq,
745 char *extra)
747 PSDevice pDevice = (PSDevice)netdev_priv(dev);
748 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
751 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAP \n");
753 memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
754 //2008-0410,<Modify> by Einsn Liu
755 if ((pDevice->bLinkPass == FALSE) && (pMgmt->eCurrMode != WMAC_MODE_ESS_AP))
756 memset(wrq->sa_data, 0, 6);
758 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
759 memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
762 wrq->sa_family = ARPHRD_ETHER;
764 return 0;
770 * Wireless Handler : get ap list
773 int iwctl_giwaplist(struct net_device *dev,
774 struct iw_request_info *info,
775 struct iw_point *wrq,
776 char *extra)
778 int ii,jj, rc = 0;
779 struct sockaddr sock[IW_MAX_AP];
780 struct iw_quality qual[IW_MAX_AP];
781 PSDevice pDevice = (PSDevice)netdev_priv(dev);
782 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
785 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAPLIST \n");
786 // Only super-user can see AP list
788 if (!capable(CAP_NET_ADMIN)) {
789 rc = -EPERM;
790 return rc;
793 if (wrq->pointer) {
795 PKnownBSS pBSS = &(pMgmt->sBSSList[0]);
797 for (ii = 0, jj= 0; ii < MAX_BSS_NUM; ii++) {
798 pBSS = &(pMgmt->sBSSList[ii]);
799 if (!pBSS->bActive)
800 continue;
801 if ( jj >= IW_MAX_AP)
802 break;
803 memcpy(sock[jj].sa_data, pBSS->abyBSSID, 6);
804 sock[jj].sa_family = ARPHRD_ETHER;
805 qual[jj].level = pBSS->uRSSI;
806 qual[jj].qual = qual[jj].noise = 0;
807 qual[jj].updated = 2;
808 jj++;
811 wrq->flags = 1; // Should be define'd
812 wrq->length = jj;
813 memcpy(extra, sock, sizeof(struct sockaddr)*jj);
814 memcpy(extra + sizeof(struct sockaddr)*jj, qual, sizeof(struct iw_quality)*jj);
817 return rc;
822 * Wireless Handler : set essid
825 int iwctl_siwessid(struct net_device *dev,
826 struct iw_request_info *info,
827 struct iw_point *wrq,
828 char *extra)
830 PSDevice pDevice = (PSDevice)netdev_priv(dev);
831 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
832 PWLAN_IE_SSID pItemSSID;
833 //2008-0409-05, <Add> by Einsn Liu
834 BYTE len;
837 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWESSID \n");
838 pDevice->fWPA_Authened = FALSE;
839 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
840 // In scanning..
841 printk("SIOCSIWESSID(??)-->In scanning...\n");
842 // return -EAGAIN;
844 // Check if we asked for `any'
845 if(wrq->flags == 0) {
846 // Just send an empty SSID list
847 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
848 memset(pMgmt->abyDesireBSSID, 0xFF,6);
849 PRINT_K("set essid to 'any' \n");
850 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
851 //Unknown desired AP,so here need not associate??
852 //if(pDevice->bWPASuppWextEnabled == TRUE) {
853 return 0;
854 // }
855 #endif
856 } else {
857 // Set the SSID
858 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
859 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
860 pItemSSID->byElementID = WLAN_EID_SSID;
862 memcpy(pItemSSID->abySSID, extra, wrq->length);
863 if (pItemSSID->abySSID[wrq->length - 1] == '\0') {
864 if(wrq->length>0)
865 pItemSSID->len = wrq->length - 1;
867 else
868 pItemSSID->len = wrq->length;
869 printk("set essid to %s \n",pItemSSID->abySSID);
870 //2008-0409-05, <Add> by Einsn Liu
871 len=(pItemSSID->len > ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len)?pItemSSID->len:((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len;
872 if((pDevice->bLinkPass == TRUE) &&
873 (memcmp(pItemSSID->abySSID,((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,len)==0))
874 return 0;
876 //mike:need clear desiredBSSID
877 if(pItemSSID->len==0) {
878 memset(pMgmt->abyDesireBSSID, 0xFF,6);
879 return 0;
882 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
883 //Wext wil order another command of siwap to link with desired AP,
884 //so here need not associate??
885 if(pDevice->bWPASuppWextEnabled == TRUE) {
886 /*******search if in hidden ssid mode ****/
888 PKnownBSS pCurr = NULL;
889 BYTE abyTmpDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
890 UINT ii , uSameBssidNum=0;
892 memset(abyTmpDesireSSID,0,sizeof(abyTmpDesireSSID));
893 memcpy(abyTmpDesireSSID,pMgmt->abyDesireSSID,sizeof(abyTmpDesireSSID));
894 pCurr = BSSpSearchBSSList(pDevice,
895 NULL,
896 abyTmpDesireSSID,
897 pMgmt->eConfigPHYMode
900 if (pCurr == NULL){
901 PRINT_K("SIOCSIWESSID:hidden ssid site survey before associate.......\n");
902 vResetCommandTimer((HANDLE) pDevice);
903 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
904 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
905 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
907 else { //mike:to find out if that desired SSID is a hidden-ssid AP ,
908 // by means of judging if there are two same BSSID exist in list ?
909 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
910 if (pMgmt->sBSSList[ii].bActive &&
911 IS_ETH_ADDRESS_EQUAL(pMgmt->sBSSList[ii].abyBSSID, pCurr->abyBSSID)) {
912 uSameBssidNum++;
915 if(uSameBssidNum >= 2) { //hit: desired AP is in hidden ssid mode!!!
916 printk("SIOCSIWESSID:hidden ssid directly associate.......\n");
917 vResetCommandTimer((HANDLE) pDevice);
918 pMgmt->eScanType = WMAC_SCAN_PASSIVE; //this scan type,you'll submit scan result!
919 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
920 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
924 return 0;
926 #endif
928 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set essid = %s \n", pItemSSID->abySSID);
931 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
932 pDevice->bCommit = TRUE;
936 return 0;
941 * Wireless Handler : get essid
944 int iwctl_giwessid(struct net_device *dev,
945 struct iw_request_info *info,
946 struct iw_point *wrq,
947 char *extra)
950 PSDevice pDevice = (PSDevice)netdev_priv(dev);
951 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
952 PWLAN_IE_SSID pItemSSID;
954 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWESSID \n");
956 // Note : if wrq->u.data.flags != 0, we should
957 // get the relevant SSID from the SSID list...
959 // Get the current SSID
960 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
961 //pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
962 memcpy(extra, pItemSSID->abySSID , pItemSSID->len);
963 extra[pItemSSID->len] = '\0';
964 wrq->length = pItemSSID->len + 1;
965 //2008-0409-03, <Add> by Einsn Liu
966 wrq->length = pItemSSID->len;
967 wrq->flags = 1; // active
970 return 0;
974 * Wireless Handler : set data rate
977 int iwctl_siwrate(struct net_device *dev,
978 struct iw_request_info *info,
979 struct iw_param *wrq,
980 char *extra)
982 PSDevice pDevice = (PSDevice)netdev_priv(dev);
983 int rc = 0;
984 u8 brate = 0;
985 int i;
986 BYTE abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
989 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRATE \n");
990 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
991 rc = -EINVAL;
992 return rc;
995 // First : get a valid bit rate value
997 // Which type of value
998 if((wrq->value < 13) &&
999 (wrq->value >= 0)) {
1000 // Setting by rate index
1001 // Find value in the magic rate table
1002 brate = wrq->value;
1003 } else {
1004 // Setting by frequency value
1005 u8 normvalue = (u8) (wrq->value/500000);
1007 // Check if rate is valid
1008 for(i = 0 ; i < 13 ; i++) {
1009 if(normvalue == abySupportedRates[i]) {
1010 brate = i;
1011 break;
1015 // -1 designed the max rate (mostly auto mode)
1016 if(wrq->value == -1) {
1017 // Get the highest available rate
1018 for(i = 0 ; i < 13 ; i++) {
1019 if(abySupportedRates[i] == 0)
1020 break;
1022 if(i != 0)
1023 brate = i - 1;
1026 // Check that it is valid
1027 // brate is index of abySupportedRates[]
1028 if(brate > 13 ) {
1029 rc = -EINVAL;
1030 return rc;
1033 // Now, check if we want a fixed or auto value
1034 if(wrq->fixed != 0) {
1035 // Fixed mode
1036 // One rate, fixed
1037 printk("Rate Fix\n");
1038 pDevice->bFixRate = TRUE;
1039 if ((pDevice->byBBType == BB_TYPE_11B)&& (brate > 3)) {
1040 pDevice->uConnectionRate = 3;
1042 else {
1043 pDevice->uConnectionRate = brate;
1044 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fixed to Rate %d \n", pDevice->uConnectionRate);
1048 else {
1049 pDevice->bFixRate = FALSE;
1050 pDevice->uConnectionRate = 13;
1051 printk("auto rate:connection_rate is 13\n");
1054 return rc;
1058 * Wireless Handler : get data rate
1061 int iwctl_giwrate(struct net_device *dev,
1062 struct iw_request_info *info,
1063 struct iw_param *wrq,
1064 char *extra)
1066 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1067 //2007-0118-05,<Mark> by EinsnLiu
1068 //Mark the unnecessary sentences.
1069 // PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1071 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRATE \n");
1073 BYTE abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
1074 int brate = 0;
1075 //2008-5-8 <modify> by chester
1076 if(pDevice->bLinkPass){
1077 if(pDevice->bFixRate == TRUE){
1078 if (pDevice->uConnectionRate < 13) {
1079 brate = abySupportedRates[pDevice->uConnectionRate];
1080 }else {
1081 if (pDevice->byBBType == BB_TYPE_11B)
1082 brate = 0x16;
1083 if (pDevice->byBBType == BB_TYPE_11G)
1084 brate = 0x6C;
1085 if (pDevice->byBBType == BB_TYPE_11A)
1086 brate = 0x6C;
1089 else
1092 brate = abySupportedRates[TxRate_iwconfig];
1095 else brate =0;
1096 //2007-0118-05,<Mark> by EinsnLiu
1097 //Mark the unnecessary sentences.
1099 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1100 if (pDevice->byBBType == BB_TYPE_11B)
1101 brate = 0x16;
1102 if (pDevice->byBBType == BB_TYPE_11G)
1103 brate = 0x6C;
1104 if (pDevice->byBBType == BB_TYPE_11A)
1105 brate = 0x6C;
1109 // if (pDevice->uConnectionRate == 13)
1110 // brate = abySupportedRates[pDevice->wCurrentRate];
1111 wrq->value = brate * 500000;
1112 // If more than one rate, set auto
1113 if (pDevice->bFixRate == TRUE)
1114 wrq->fixed = TRUE;
1118 return 0;
1124 * Wireless Handler : set rts threshold
1127 int iwctl_siwrts(struct net_device *dev,
1128 struct iw_request_info *info,
1129 struct iw_param *wrq,
1130 char *extra)
1132 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1133 int rc = 0;
1135 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRTS \n");
1138 int rthr = wrq->value;
1139 if(wrq->disabled)
1140 rthr = 2312;
1141 if((rthr < 0) || (rthr > 2312)) {
1142 rc = -EINVAL;
1143 }else {
1144 pDevice->wRTSThreshold = rthr;
1148 return 0;
1152 * Wireless Handler : get rts
1155 int iwctl_giwrts(struct net_device *dev,
1156 struct iw_request_info *info,
1157 struct iw_param *wrq,
1158 char *extra)
1160 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1162 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRTS \n");
1163 wrq->value = pDevice->wRTSThreshold;
1164 wrq->disabled = (wrq->value >= 2312);
1165 wrq->fixed = 1;
1167 return 0;
1171 * Wireless Handler : set fragment threshold
1174 int iwctl_siwfrag(struct net_device *dev,
1175 struct iw_request_info *info,
1176 struct iw_param *wrq,
1177 char *extra)
1179 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1180 int rc = 0;
1181 int fthr = wrq->value;
1184 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFRAG \n");
1187 if (wrq->disabled)
1188 fthr = 2312;
1189 if((fthr < 256) || (fthr > 2312)) {
1190 rc = -EINVAL;
1191 }else {
1192 fthr &= ~0x1; // Get an even value
1193 pDevice->wFragmentationThreshold = (u16)fthr;
1196 return rc;
1200 * Wireless Handler : get fragment threshold
1203 int iwctl_giwfrag(struct net_device *dev,
1204 struct iw_request_info *info,
1205 struct iw_param *wrq,
1206 char *extra)
1208 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1210 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFRAG \n");
1211 wrq->value = pDevice->wFragmentationThreshold;
1212 wrq->disabled = (wrq->value >= 2312);
1213 wrq->fixed = 1;
1215 return 0;
1221 * Wireless Handler : set retry threshold
1223 int iwctl_siwretry(struct net_device *dev,
1224 struct iw_request_info *info,
1225 struct iw_param *wrq,
1226 char *extra)
1228 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1229 int rc = 0;
1232 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRETRY \n");
1234 if (wrq->disabled) {
1235 rc = -EINVAL;
1236 return rc;
1239 if (wrq->flags & IW_RETRY_LIMIT) {
1240 if(wrq->flags & IW_RETRY_MAX)
1241 pDevice->byLongRetryLimit = wrq->value;
1242 else if (wrq->flags & IW_RETRY_MIN)
1243 pDevice->byShortRetryLimit = wrq->value;
1244 else {
1245 // No modifier : set both
1246 pDevice->byShortRetryLimit = wrq->value;
1247 pDevice->byLongRetryLimit = wrq->value;
1250 if (wrq->flags & IW_RETRY_LIFETIME) {
1251 pDevice->wMaxTransmitMSDULifetime = wrq->value;
1255 return rc;
1259 * Wireless Handler : get retry threshold
1261 int iwctl_giwretry(struct net_device *dev,
1262 struct iw_request_info *info,
1263 struct iw_param *wrq,
1264 char *extra)
1266 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1267 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRETRY \n");
1268 wrq->disabled = 0; // Can't be disabled
1270 // Note : by default, display the min retry number
1271 if((wrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1272 wrq->flags = IW_RETRY_LIFETIME;
1273 wrq->value = (int)pDevice->wMaxTransmitMSDULifetime; //ms
1274 } else if((wrq->flags & IW_RETRY_MAX)) {
1275 wrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
1276 wrq->value = (int)pDevice->byLongRetryLimit;
1277 } else {
1278 wrq->flags = IW_RETRY_LIMIT;
1279 wrq->value = (int)pDevice->byShortRetryLimit;
1280 if((int)pDevice->byShortRetryLimit != (int)pDevice->byLongRetryLimit)
1281 wrq->flags |= IW_RETRY_MIN;
1285 return 0;
1290 * Wireless Handler : set encode mode
1292 int iwctl_siwencode(struct net_device *dev,
1293 struct iw_request_info *info,
1294 struct iw_point *wrq,
1295 char *extra)
1297 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1298 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1299 DWORD dwKeyIndex = (DWORD)(wrq->flags & IW_ENCODE_INDEX);
1300 int ii,uu, rc = 0;
1301 int index = (wrq->flags & IW_ENCODE_INDEX);
1303 //2007-0207-07,<Modify> by EinsnLiu
1304 //There are some problems when using iwconfig encode/key command to set the WEP key.
1305 //I almost rewrite this function.
1306 //now it support:(assume the wireless interface's name is eth0)
1307 //iwconfig eth0 key [1] 1122334455 open /*set key stirng to index 1,and driver using key index is set to 1*/
1308 //iwconfig eth0 key [3] /*set driver using key index to 3,the key string no change */
1309 //iwconfig eth0 key 1122334455 /*set key string to driver using index*/
1310 //iwconfig eth0 key restricted /*enable share key*/
1312 PSKeyTable pkeytab;
1314 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODE \n");
1316 if((wrq->flags & IW_ENCODE_DISABLED)==0){
1317 //Not disable encryption
1319 if (dwKeyIndex > WLAN_WEP_NKEYS) {
1320 rc = -EINVAL;
1321 return rc;
1324 if(dwKeyIndex<1&&((wrq->flags&IW_ENCODE_NOKEY)==0)){//set default key
1325 if(pDevice->byKeyIndex<WLAN_WEP_NKEYS){
1326 dwKeyIndex=pDevice->byKeyIndex;
1328 else dwKeyIndex=0;
1329 }else dwKeyIndex--;
1332 // Check the size of the key
1333 if (wrq->length > WLAN_WEP232_KEYLEN) {
1334 rc = -EINVAL;
1335 return rc;
1338 if(wrq->length>0){//have key
1340 if (wrq->length == WLAN_WEP232_KEYLEN) {
1341 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 232 bit wep key\n");
1343 else if (wrq->length == WLAN_WEP104_KEYLEN) {
1344 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 104 bit wep key\n");
1346 else if (wrq->length == WLAN_WEP40_KEYLEN) {
1347 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 40 bit wep key, index= %d\n", (int)dwKeyIndex);
1348 }else {//no support length
1349 rc = -EINVAL;
1350 return rc;
1352 memset(pDevice->abyKey, 0, WLAN_WEP232_KEYLEN);
1353 memcpy(pDevice->abyKey, extra, wrq->length);
1355 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyKey: ");
1356 for (ii = 0; ii < wrq->length; ii++) {
1357 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pDevice->abyKey[ii]);
1360 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1361 spin_lock_irq(&pDevice->lock);
1362 KeybSetDefaultKey(&(pDevice->sKey),
1363 (DWORD)(dwKeyIndex | (1 << 31)),
1364 wrq->length,
1365 NULL,
1366 pDevice->abyKey,
1367 KEY_CTL_WEP,
1368 pDevice->PortOffset,
1369 pDevice->byLocalID
1371 spin_unlock_irq(&pDevice->lock);
1373 pDevice->byKeyIndex = (BYTE)dwKeyIndex;
1374 pDevice->uKeyLength = wrq->length;
1375 pDevice->bTransmitKey = TRUE;
1376 pDevice->bEncryptionEnable = TRUE;
1377 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1379 }else if(index>0){
1380 //when the length is 0 the request only changes the default transmit key index
1381 //check the new key has a non zero lenget
1382 if(pDevice->bEncryptionEnable==FALSE)
1384 rc = -EINVAL;
1385 return rc;
1387 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Just set Default key Index:\n");
1388 pkeytab=&(pDevice->sKey.KeyTable[MAX_KEY_TABLE-1]);
1389 if(pkeytab->GroupKey[(BYTE)dwKeyIndex].uKeyLength==0){
1390 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Default key len is 0\n");
1391 rc = -EINVAL;
1392 return rc;
1394 pDevice->byKeyIndex =(BYTE)dwKeyIndex;
1395 pkeytab->dwGTKeyIndex =dwKeyIndex | (1 << 31);
1396 pkeytab->GroupKey[(BYTE)dwKeyIndex].dwKeyIndex=dwKeyIndex | (1 << 31);
1399 }else {//disable the key
1400 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable WEP function\n");
1401 if(pDevice->bEncryptionEnable==FALSE)
1402 return 0;
1403 pMgmt->bShareKeyAlgorithm = FALSE;
1404 pDevice->bEncryptionEnable = FALSE;
1405 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1406 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1407 spin_lock_irq(&pDevice->lock);
1408 for(uu=0;uu<MAX_KEY_TABLE;uu++)
1409 MACvDisableKeyEntry(pDevice->PortOffset, uu);
1410 spin_unlock_irq(&pDevice->lock);
1413 //End Modify,Einsn
1416 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODE \n");
1418 // Check the size of the key
1419 if (wrq->length > WLAN_WEP232_KEYLEN) {
1420 rc = -EINVAL;
1421 return rc;
1424 if (dwKeyIndex > WLAN_WEP_NKEYS) {
1425 rc = -EINVAL;
1426 return rc;
1429 if (dwKeyIndex > 0)
1430 dwKeyIndex--;
1432 // Send the key to the card
1433 if (wrq->length > 0) {
1435 if (wrq->length == WLAN_WEP232_KEYLEN) {
1436 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 232 bit wep key\n");
1438 else if (wrq->length == WLAN_WEP104_KEYLEN) {
1439 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 104 bit wep key\n");
1441 else if (wrq->length == WLAN_WEP40_KEYLEN) {
1442 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 40 bit wep key, index= %d\n", (int)dwKeyIndex);
1444 memset(pDevice->abyKey, 0, WLAN_WEP232_KEYLEN);
1445 memcpy(pDevice->abyKey, extra, wrq->length);
1447 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyKey: ");
1448 for (ii = 0; ii < wrq->length; ii++) {
1449 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pDevice->abyKey[ii]);
1452 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1453 spin_lock_irq(&pDevice->lock);
1454 KeybSetDefaultKey(&(pDevice->sKey),
1455 (DWORD)(pDevice->byKeyIndex | (1 << 31)),
1456 pDevice->uKeyLength,
1457 NULL,
1458 pDevice->abyKey,
1459 KEY_CTL_WEP,
1460 pDevice->PortOffset,
1461 pDevice->byLocalID
1463 spin_unlock_irq(&pDevice->lock);
1465 pDevice->byKeyIndex = (BYTE)dwKeyIndex;
1466 pDevice->uKeyLength = wrq->length;
1467 pDevice->bTransmitKey = TRUE;
1468 pDevice->bEncryptionEnable = TRUE;
1469 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1471 // Do we want to just set the transmit key index ?
1472 if ( index < 4 ) {
1473 pDevice->byKeyIndex = index;
1475 else if(!wrq->flags & IW_ENCODE_MODE) {
1476 rc = -EINVAL;
1477 return rc;
1480 // Read the flags
1481 if(wrq->flags & IW_ENCODE_DISABLED){
1483 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable WEP function\n");
1484 pMgmt->bShareKeyAlgorithm = FALSE;
1485 pDevice->bEncryptionEnable = FALSE;
1486 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1487 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1488 spin_lock_irq(&pDevice->lock);
1489 for(uu=0;uu<MAX_KEY_TABLE;uu++)
1490 MACvDisableKeyEntry(pDevice->PortOffset, uu);
1491 spin_unlock_irq(&pDevice->lock);
1496 if(wrq->flags & IW_ENCODE_RESTRICTED) {
1497 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & ShareKey System\n");
1498 pMgmt->bShareKeyAlgorithm = TRUE;
1500 if(wrq->flags & IW_ENCODE_OPEN) {
1501 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & Open System\n");
1502 pMgmt->bShareKeyAlgorithm = FALSE;
1504 return rc;
1508 * Wireless Handler : get encode mode
1511 int iwctl_giwencode(struct net_device *dev,
1512 struct iw_request_info *info,
1513 struct iw_point *wrq,
1514 char *extra)
1516 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1517 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1518 int rc = 0;
1519 char abyKey[WLAN_WEP232_KEYLEN];
1520 UINT index = (UINT)(wrq->flags & IW_ENCODE_INDEX);
1521 PSKeyItem pKey = NULL;
1523 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODE\n");
1524 //2007-0207-06,<Add> by EinsnLiu
1525 //the key index in iwconfig is 1-4 when our driver is 0-3
1526 //so it can't be used directly.
1527 //if the index is 0,we should used the index set by driver.
1528 if (index > WLAN_WEP_NKEYS) {
1529 rc = -EINVAL;
1530 return rc;
1532 if(index<1){//set default key
1533 if(pDevice->byKeyIndex<WLAN_WEP_NKEYS){
1534 index=pDevice->byKeyIndex;
1536 else index=0;
1537 }else index--;
1538 //End Add,Einsn
1540 memset(abyKey, 0, sizeof(abyKey));
1541 // Check encryption mode
1542 wrq->flags = IW_ENCODE_NOKEY;
1543 // Is WEP enabled ???
1544 if (pDevice->bEncryptionEnable)
1545 wrq->flags |= IW_ENCODE_ENABLED;
1546 else
1547 wrq->flags |= IW_ENCODE_DISABLED;
1549 if (pMgmt->bShareKeyAlgorithm)
1550 wrq->flags |= IW_ENCODE_RESTRICTED;
1551 else
1552 wrq->flags |= IW_ENCODE_OPEN;
1554 if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (BYTE)index , &pKey)){
1555 wrq->length = pKey->uKeyLength;
1556 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1557 //2007-0207-06,<Modify> by EinsnLiu
1558 //only get key success need to copy data
1559 //index should +1.
1560 //there is not necessary to return -EINVAL when get key failed
1561 //if return -EINVAL,the encryption item can't be display by the command "iwconfig".
1562 wrq->flags |= index+1;
1563 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1566 //else {
1567 // rc = -EINVAL;
1568 // return rc;
1569 // }
1572 //End Modify,Einsn
1574 return 0;
1578 //2008-0409-06, <Add> by Einsn Liu
1580 int iwctl_giwencode(struct net_device *dev,
1581 struct iw_request_info *info,
1582 struct iw_point *wrq,
1583 char *extra)
1585 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1586 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1587 char abyKey[WLAN_WEP232_KEYLEN];
1589 UINT index = (UINT)(wrq->flags & IW_ENCODE_INDEX);
1590 PSKeyItem pKey = NULL;
1592 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODE\n");
1594 if (index > WLAN_WEP_NKEYS) {
1595 return -EINVAL;
1597 if(index<1){//get default key
1598 if(pDevice->byKeyIndex<WLAN_WEP_NKEYS){
1599 index=pDevice->byKeyIndex;
1600 } else
1601 index=0;
1602 }else
1603 index--;
1605 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
1606 // Check encryption mode
1607 wrq->flags = IW_ENCODE_NOKEY;
1608 // Is WEP enabled ???
1609 if (pDevice->bEncryptionEnable)
1610 wrq->flags |= IW_ENCODE_ENABLED;
1611 else
1612 wrq->flags |= IW_ENCODE_DISABLED;
1614 if (pMgmt->bShareKeyAlgorithm)
1615 wrq->flags |= IW_ENCODE_RESTRICTED;
1616 else
1617 wrq->flags |= IW_ENCODE_OPEN;
1618 wrq->length=0;
1620 if((index==0)&&(pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled||
1621 pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)){//get wpa pairwise key
1622 if (KeybGetKey(&(pDevice->sKey),pMgmt->abyCurrBSSID, 0xffffffff, &pKey)){
1623 wrq->length = pKey->uKeyLength;
1624 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1625 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1627 }else if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (BYTE)index , &pKey)){
1628 wrq->length = pKey->uKeyLength;
1629 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1630 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1633 wrq->flags |= index+1;
1635 return 0;
1640 * Wireless Handler : set power mode
1642 int iwctl_siwpower(struct net_device *dev,
1643 struct iw_request_info *info,
1644 struct iw_param *wrq,
1645 char *extra)
1647 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1648 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1649 int rc = 0;
1651 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER \n");
1653 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
1654 rc = -EINVAL;
1655 return rc;
1658 if (wrq->disabled) {
1659 pDevice->ePSMode = WMAC_POWER_CAM;
1660 PSvDisablePowerSaving(pDevice);
1661 return rc;
1663 if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1664 pDevice->ePSMode = WMAC_POWER_FAST;
1665 PSvEnablePowerSaving((HANDLE)pDevice, pMgmt->wListenInterval);
1667 } else if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
1668 pDevice->ePSMode = WMAC_POWER_FAST;
1669 PSvEnablePowerSaving((HANDLE)pDevice, pMgmt->wListenInterval);
1671 switch (wrq->flags & IW_POWER_MODE) {
1672 case IW_POWER_UNICAST_R:
1673 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_UNICAST_R \n");
1674 rc = -EINVAL;
1675 break;
1676 case IW_POWER_ALL_R:
1677 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ALL_R \n");
1678 rc = -EINVAL;
1679 case IW_POWER_ON:
1680 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ON \n");
1681 break;
1682 default:
1683 rc = -EINVAL;
1686 return rc;
1690 * Wireless Handler : get power mode
1692 int iwctl_giwpower(struct net_device *dev,
1693 struct iw_request_info *info,
1694 struct iw_param *wrq,
1695 char *extra)
1697 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1698 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1699 int mode = pDevice->ePSMode;
1702 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPOWER \n");
1705 if ((wrq->disabled = (mode == WMAC_POWER_CAM)))
1706 return 0;
1708 if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1709 wrq->value = (int)((pMgmt->wListenInterval * pMgmt->wCurrBeaconPeriod) << 10);
1710 wrq->flags = IW_POWER_TIMEOUT;
1711 } else {
1712 wrq->value = (int)((pMgmt->wListenInterval * pMgmt->wCurrBeaconPeriod) << 10);
1713 wrq->flags = IW_POWER_PERIOD;
1715 wrq->flags |= IW_POWER_ALL_R;
1717 return 0;
1722 * Wireless Handler : get Sensitivity
1724 int iwctl_giwsens(struct net_device *dev,
1725 struct iw_request_info *info,
1726 struct iw_param *wrq,
1727 char *extra)
1729 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1730 long ldBm;
1732 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSENS \n");
1733 if (pDevice->bLinkPass == TRUE) {
1734 RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm);
1735 wrq->value = ldBm;
1737 else {
1738 wrq->value = 0;
1740 wrq->disabled = (wrq->value == 0);
1741 wrq->fixed = 1;
1744 return 0;
1747 //2008-0409-07, <Add> by Einsn Liu
1748 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1750 int iwctl_siwauth(struct net_device *dev,
1751 struct iw_request_info *info,
1752 struct iw_param *wrq,
1753 char *extra)
1755 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1756 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1757 int ret=0;
1758 static int wpa_version=0; //must be static to save the last value,einsn liu
1759 static int pairwise=0;
1761 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH \n");
1762 switch (wrq->flags & IW_AUTH_INDEX) {
1763 case IW_AUTH_WPA_VERSION:
1764 wpa_version = wrq->value;
1765 if(wrq->value == IW_AUTH_WPA_VERSION_DISABLED) {
1766 PRINT_K("iwctl_siwauth:set WPADEV to disable at 1??????\n");
1767 //pDevice->bWPADevEnable = FALSE;
1769 else if(wrq->value == IW_AUTH_WPA_VERSION_WPA) {
1770 PRINT_K("iwctl_siwauth:set WPADEV to WPA1******\n");
1772 else {
1773 PRINT_K("iwctl_siwauth:set WPADEV to WPA2******\n");
1775 //pDevice->bWPASuppWextEnabled =TRUE;
1776 break;
1777 case IW_AUTH_CIPHER_PAIRWISE:
1778 pairwise = wrq->value;
1779 if(pairwise == IW_AUTH_CIPHER_CCMP){
1780 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1781 }else if(pairwise == IW_AUTH_CIPHER_TKIP){
1782 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1783 }else if(pairwise == IW_AUTH_CIPHER_WEP40||pairwise == IW_AUTH_CIPHER_WEP104){
1784 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1785 }else if(pairwise == IW_AUTH_CIPHER_NONE){
1786 //do nothing,einsn liu
1787 }else pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1789 break;
1790 case IW_AUTH_CIPHER_GROUP:
1791 if(wpa_version == IW_AUTH_WPA_VERSION_DISABLED)
1792 break;
1793 if(pairwise == IW_AUTH_CIPHER_NONE){
1794 if(wrq->value == IW_AUTH_CIPHER_CCMP){
1795 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1796 }else {
1797 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1800 break;
1801 case IW_AUTH_KEY_MGMT:
1803 if(wpa_version == IW_AUTH_WPA_VERSION_WPA2){
1804 if(wrq->value == IW_AUTH_KEY_MGMT_PSK)
1805 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
1806 else pMgmt->eAuthenMode = WMAC_AUTH_WPA2;
1807 }else if(wpa_version == IW_AUTH_WPA_VERSION_WPA){
1808 if(wrq->value == 0){
1809 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
1810 }else if(wrq->value == IW_AUTH_KEY_MGMT_PSK)
1811 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
1812 else pMgmt->eAuthenMode = WMAC_AUTH_WPA;
1815 break;
1816 case IW_AUTH_TKIP_COUNTERMEASURES:
1817 break; /* FIXME */
1818 case IW_AUTH_DROP_UNENCRYPTED:
1819 break;
1820 case IW_AUTH_80211_AUTH_ALG:
1821 if(wrq->value==IW_AUTH_ALG_OPEN_SYSTEM){
1822 pMgmt->bShareKeyAlgorithm=FALSE;
1823 }else if(wrq->value==IW_AUTH_ALG_SHARED_KEY){
1824 pMgmt->bShareKeyAlgorithm=TRUE;
1826 break;
1827 case IW_AUTH_WPA_ENABLED:
1828 //pDevice->bWPADevEnable = !! wrq->value;
1829 break;
1830 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1831 break;
1832 case IW_AUTH_ROAMING_CONTROL:
1833 ret = -EOPNOTSUPP;
1834 break;
1835 case IW_AUTH_PRIVACY_INVOKED:
1836 pDevice->bEncryptionEnable = !!wrq->value;
1837 if(pDevice->bEncryptionEnable == FALSE){
1838 wpa_version = 0;
1839 pairwise = 0;
1840 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1841 pMgmt->bShareKeyAlgorithm = FALSE;
1842 pMgmt->eAuthenMode = FALSE;
1843 //pDevice->bWPADevEnable = FALSE;
1846 break;
1847 default:
1848 ret = -EOPNOTSUPP;
1849 break;
1852 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_version = %d\n",wpa_version);
1853 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pairwise = %d\n",pairwise);
1854 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->eEncryptionStatus = %d\n",pDevice->eEncryptionStatus);
1855 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->eAuthenMode = %d\n",pMgmt->eAuthenMode);
1856 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->bShareKeyAlgorithm = %s\n",pMgmt->bShareKeyAlgorithm?"TRUE":"FALSE");
1857 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->bEncryptionEnable = %s\n",pDevice->bEncryptionEnable?"TRUE":"FALSE");
1858 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->bWPADevEnable = %s\n",pDevice->bWPADevEnable?"TRUE":"FALSE");
1860 return ret;
1864 int iwctl_giwauth(struct net_device *dev,
1865 struct iw_request_info *info,
1866 struct iw_param *wrq,
1867 char *extra)
1869 return -EOPNOTSUPP;
1874 int iwctl_siwgenie(struct net_device *dev,
1875 struct iw_request_info *info,
1876 struct iw_point *wrq,
1877 char *extra)
1879 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1880 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1881 int ret=0;
1883 if(wrq->length){
1884 if ((wrq->length < 2) || (extra[1]+2 != wrq->length)) {
1885 ret = -EINVAL;
1886 goto out;
1888 if(wrq->length > MAX_WPA_IE_LEN){
1889 ret = -ENOMEM;
1890 goto out;
1892 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
1893 if(copy_from_user(pMgmt->abyWPAIE, extra, wrq->length)){
1894 ret = -EFAULT;
1895 goto out;
1897 pMgmt->wWPAIELen = wrq->length;
1898 }else {
1899 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
1900 pMgmt->wWPAIELen = 0;
1903 out://not completely ...not necessary in wpa_supplicant 0.5.8
1904 return 0;
1907 int iwctl_giwgenie(struct net_device *dev,
1908 struct iw_request_info *info,
1909 struct iw_point *wrq,
1910 char *extra)
1912 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1913 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1914 int ret=0;
1915 int space = wrq->length;
1917 wrq->length = 0;
1918 if(pMgmt->wWPAIELen > 0){
1919 wrq->length = pMgmt->wWPAIELen;
1920 if(pMgmt->wWPAIELen <= space){
1921 if(copy_to_user(extra, pMgmt->abyWPAIE, pMgmt->wWPAIELen)){
1922 ret = -EFAULT;
1924 }else
1925 ret = -E2BIG;
1928 return ret;
1932 int iwctl_siwencodeext(struct net_device *dev,
1933 struct iw_request_info *info,
1934 struct iw_point *wrq,
1935 char *extra)
1937 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1938 struct iw_encode_ext *ext = (struct iw_encode_ext*)extra;
1939 struct viawget_wpa_param *param=NULL;
1940 //original member
1941 wpa_alg alg_name;
1942 u8 addr[6];
1943 int key_idx, set_tx=0;
1944 u8 seq[IW_ENCODE_SEQ_MAX_SIZE];
1945 u8 key[64];
1946 size_t seq_len=0,key_len=0;
1948 // int ii;
1949 u8 *buf;
1950 size_t blen;
1951 u8 key_array[64];
1952 int ret=0;
1954 PRINT_K("SIOCSIWENCODEEXT...... \n");
1956 blen = sizeof(*param);
1957 buf = kmalloc((int)blen, (int)GFP_KERNEL);
1958 if (buf == NULL)
1959 return -ENOMEM;
1960 memset(buf, 0, blen);
1961 param = (struct viawget_wpa_param *) buf;
1963 //recover alg_name
1964 switch (ext->alg) {
1965 case IW_ENCODE_ALG_NONE:
1966 alg_name = WPA_ALG_NONE;
1967 break;
1968 case IW_ENCODE_ALG_WEP:
1969 alg_name = WPA_ALG_WEP;
1970 break;
1971 case IW_ENCODE_ALG_TKIP:
1972 alg_name = WPA_ALG_TKIP;
1973 break;
1974 case IW_ENCODE_ALG_CCMP:
1975 alg_name = WPA_ALG_CCMP;
1976 break;
1977 default:
1978 PRINT_K("Unknown alg = %d\n",ext->alg);
1979 ret= -ENOMEM;
1980 goto error;
1982 //recover addr
1983 memcpy(addr, ext->addr.sa_data, ETH_ALEN);
1984 //recover key_idx
1985 key_idx = (wrq->flags&IW_ENCODE_INDEX) - 1;
1986 //recover set_tx
1987 if(ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
1988 set_tx = 1;
1989 //recover seq,seq_len
1990 if(ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
1991 seq_len=IW_ENCODE_SEQ_MAX_SIZE;
1992 memcpy(seq, ext->rx_seq, seq_len);
1994 //recover key,key_len
1995 if(ext->key_len) {
1996 key_len=ext->key_len;
1997 memcpy(key, &ext->key[0], key_len);
2000 memset(key_array, 0, 64);
2001 if ( key_len > 0) {
2002 memcpy(key_array, key, key_len);
2003 if (key_len == 32) {
2004 // notice ! the oder
2005 memcpy(&key_array[16], &key[24], 8);
2006 memcpy(&key_array[24], &key[16], 8);
2010 /**************Translate iw_encode_ext to viawget_wpa_param****************/
2011 memcpy(param->addr, addr, ETH_ALEN);
2012 param->u.wpa_key.alg_name = (int)alg_name;
2013 param->u.wpa_key.set_tx = set_tx;
2014 param->u.wpa_key.key_index = key_idx;
2015 param->u.wpa_key.key_len = key_len;
2016 param->u.wpa_key.key = (u8 *)key_array;
2017 param->u.wpa_key.seq = (u8 *)seq;
2018 param->u.wpa_key.seq_len = seq_len;
2020 #if 0
2021 printk("param->u.wpa_key.alg_name =%d\n",param->u.wpa_key.alg_name);
2022 printk("param->addr=%02x:%02x:%02x:%02x:%02x:%02x\n",
2023 param->addr[0],param->addr[1],param->addr[2],
2024 param->addr[3],param->addr[4],param->addr[5]);
2025 printk("param->u.wpa_key.set_tx =%d\n",param->u.wpa_key.set_tx);
2026 printk("param->u.wpa_key.key_index =%d\n",param->u.wpa_key.key_index);
2027 printk("param->u.wpa_key.key_len =%d\n",param->u.wpa_key.key_len);
2028 printk("param->u.wpa_key.key =");
2029 for(ii=0;ii<param->u.wpa_key.key_len;ii++)
2030 printk("%02x:",param->u.wpa_key.key[ii]);
2031 printk("\n");
2032 printk("param->u.wpa_key.seq_len =%d\n",param->u.wpa_key.seq_len);
2033 printk("param->u.wpa_key.seq =");
2034 for(ii=0;ii<param->u.wpa_key.seq_len;ii++)
2035 printk("%02x:",param->u.wpa_key.seq[ii]);
2036 printk("\n");
2038 printk("...........\n");
2039 #endif
2040 //****set if current action is Network Manager count??
2041 //****this method is so foolish,but there is no other way???
2042 if(param->u.wpa_key.alg_name == WPA_ALG_NONE) {
2043 if(param->u.wpa_key.key_index ==0) {
2044 pDevice->bwextcount++;
2046 if((pDevice->bwextcount == 1)&&(param->u.wpa_key.key_index ==1)) {
2047 pDevice->bwextcount++;
2049 if((pDevice->bwextcount ==2)&&(param->u.wpa_key.key_index ==2)) {
2050 pDevice->bwextcount++;
2052 if((pDevice->bwextcount ==3)&&(param->u.wpa_key.key_index ==3)) {
2053 pDevice->bwextcount++;
2056 if( pDevice->bwextcount == 4) {
2057 printk("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n");
2058 pDevice->bwextcount=0;
2059 pDevice->bWPASuppWextEnabled = TRUE;
2061 //******
2063 spin_lock_irq(&pDevice->lock);
2064 ret = wpa_set_keys(pDevice, param, TRUE);
2065 spin_unlock_irq(&pDevice->lock);
2067 error:
2068 kfree(param);
2069 return ret;
2074 int iwctl_giwencodeext(struct net_device *dev,
2075 struct iw_request_info *info,
2076 struct iw_point *wrq,
2077 char *extra)
2079 return -EOPNOTSUPP;;
2082 int iwctl_siwmlme(struct net_device *dev,
2083 struct iw_request_info * info,
2084 struct iw_point *wrq,
2085 char *extra)
2087 PSDevice pDevice = (PSDevice)netdev_priv(dev);
2088 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
2089 struct iw_mlme *mlme = (struct iw_mlme *)extra;
2090 //u16 reason = cpu_to_le16(mlme->reason_code);
2091 int ret = 0;
2093 if(memcmp(pMgmt->abyCurrBSSID, mlme->addr.sa_data, ETH_ALEN)){
2094 ret = -EINVAL;
2095 return ret;
2097 switch(mlme->cmd){
2098 case IW_MLME_DEAUTH:
2099 //this command seems to be not complete,please test it --einsnliu
2100 //bScheduleCommand((HANDLE) pDevice, WLAN_CMD_DEAUTH, (PBYTE)&reason);
2101 break;
2102 case IW_MLME_DISASSOC:
2103 if(pDevice->bLinkPass == TRUE){
2104 printk("iwctl_siwmlme--->send DISASSOCIATE\n");
2105 //clear related flags
2106 memset(pMgmt->abyDesireBSSID, 0xFF,6);
2107 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
2108 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
2110 break;
2111 default:
2112 ret = -EOPNOTSUPP;
2115 return ret;
2119 #endif
2122 /*------------------------------------------------------------------*/
2124 * Structures to export the Wireless Handlers
2129 static const iw_handler iwctl_handler[] =
2131 (iw_handler) iwctl_commit, // SIOCSIWCOMMIT
2132 (iw_handler) iwctl_giwname, // SIOCGIWNAME
2133 (iw_handler) NULL, // SIOCSIWNWID
2134 (iw_handler) NULL, // SIOCGIWNWID
2135 (iw_handler) iwctl_siwfreq, // SIOCSIWFREQ
2136 (iw_handler) iwctl_giwfreq, // SIOCGIWFREQ
2137 (iw_handler) iwctl_siwmode, // SIOCSIWMODE
2138 (iw_handler) iwctl_giwmode, // SIOCGIWMODE
2139 (iw_handler) NULL, // SIOCSIWSENS
2140 (iw_handler) iwctl_giwsens, // SIOCGIWSENS
2141 (iw_handler) NULL, // SIOCSIWRANGE
2142 (iw_handler) iwctl_giwrange, // SIOCGIWRANGE
2143 (iw_handler) NULL, // SIOCSIWPRIV
2144 (iw_handler) NULL, // SIOCGIWPRIV
2145 (iw_handler) NULL, // SIOCSIWSTATS
2146 (iw_handler) NULL, // SIOCGIWSTATS
2147 (iw_handler) NULL, // SIOCSIWSPY
2148 (iw_handler) NULL, // SIOCGIWSPY
2149 (iw_handler) NULL, // -- hole --
2150 (iw_handler) NULL, // -- hole --
2151 (iw_handler) iwctl_siwap, // SIOCSIWAP
2152 (iw_handler) iwctl_giwap, // SIOCGIWAP
2153 (iw_handler) NULL, // -- hole -- 0x16
2154 (iw_handler) iwctl_giwaplist, // SIOCGIWAPLIST
2155 (iw_handler) iwctl_siwscan, // SIOCSIWSCAN
2156 (iw_handler) iwctl_giwscan, // SIOCGIWSCAN
2157 (iw_handler) iwctl_siwessid, // SIOCSIWESSID
2158 (iw_handler) iwctl_giwessid, // SIOCGIWESSID
2159 (iw_handler) NULL, // SIOCSIWNICKN
2160 (iw_handler) NULL, // SIOCGIWNICKN
2161 (iw_handler) NULL, // -- hole --
2162 (iw_handler) NULL, // -- hole --
2163 (iw_handler) iwctl_siwrate, // SIOCSIWRATE 0x20
2164 (iw_handler) iwctl_giwrate, // SIOCGIWRATE
2165 (iw_handler) iwctl_siwrts, // SIOCSIWRTS
2166 (iw_handler) iwctl_giwrts, // SIOCGIWRTS
2167 (iw_handler) iwctl_siwfrag, // SIOCSIWFRAG
2168 (iw_handler) iwctl_giwfrag, // SIOCGIWFRAG
2169 (iw_handler) NULL, // SIOCSIWTXPOW
2170 (iw_handler) NULL, // SIOCGIWTXPOW
2171 (iw_handler) iwctl_siwretry, // SIOCSIWRETRY
2172 (iw_handler) iwctl_giwretry, // SIOCGIWRETRY
2173 (iw_handler) iwctl_siwencode, // SIOCSIWENCODE
2174 (iw_handler) iwctl_giwencode, // SIOCGIWENCODE
2175 (iw_handler) iwctl_siwpower, // SIOCSIWPOWER
2176 (iw_handler) iwctl_giwpower, // SIOCGIWPOWER
2177 (iw_handler) NULL, // -- hole --
2178 (iw_handler) NULL, // -- hole --
2179 (iw_handler) iwctl_siwgenie, // SIOCSIWGENIE
2180 (iw_handler) iwctl_giwgenie, // SIOCGIWGENIE
2181 (iw_handler) iwctl_siwauth, // SIOCSIWAUTH
2182 (iw_handler) iwctl_giwauth, // SIOCGIWAUTH
2183 (iw_handler) iwctl_siwencodeext, // SIOCSIWENCODEEXT
2184 (iw_handler) iwctl_giwencodeext, // SIOCGIWENCODEEXT
2185 (iw_handler) NULL, // SIOCSIWPMKSA
2186 (iw_handler) NULL, // -- hole --
2191 static const iw_handler iwctl_handler[] =
2193 (iw_handler) iwctl_commit, // SIOCSIWCOMMIT
2194 (iw_handler) NULL, // SIOCGIWNAME
2195 (iw_handler) NULL, // SIOCSIWNWID
2196 (iw_handler) NULL, // SIOCGIWNWID
2197 (iw_handler) NULL, // SIOCSIWFREQ
2198 (iw_handler) NULL, // SIOCGIWFREQ
2199 (iw_handler) NULL, // SIOCSIWMODE
2200 (iw_handler) NULL, // SIOCGIWMODE
2201 (iw_handler) NULL, // SIOCSIWSENS
2202 (iw_handler) NULL, // SIOCGIWSENS
2203 (iw_handler) NULL, // SIOCSIWRANGE
2204 (iw_handler) iwctl_giwrange, // SIOCGIWRANGE
2205 (iw_handler) NULL, // SIOCSIWPRIV
2206 (iw_handler) NULL, // SIOCGIWPRIV
2207 (iw_handler) NULL, // SIOCSIWSTATS
2208 (iw_handler) NULL, // SIOCGIWSTATS
2209 (iw_handler) NULL, // SIOCSIWSPY
2210 (iw_handler) NULL, // SIOCGIWSPY
2211 (iw_handler) NULL, // -- hole --
2212 (iw_handler) NULL, // -- hole --
2213 (iw_handler) NULL, // SIOCSIWAP
2214 (iw_handler) NULL, // SIOCGIWAP
2215 (iw_handler) NULL, // -- hole -- 0x16
2216 (iw_handler) NULL, // SIOCGIWAPLIST
2217 (iw_handler) iwctl_siwscan, // SIOCSIWSCAN
2218 (iw_handler) iwctl_giwscan, // SIOCGIWSCAN
2219 (iw_handler) NULL, // SIOCSIWESSID
2220 (iw_handler) NULL, // SIOCGIWESSID
2221 (iw_handler) NULL, // SIOCSIWNICKN
2222 (iw_handler) NULL, // SIOCGIWNICKN
2223 (iw_handler) NULL, // -- hole --
2224 (iw_handler) NULL, // -- hole --
2225 (iw_handler) NULL, // SIOCSIWRATE 0x20
2226 (iw_handler) NULL, // SIOCGIWRATE
2227 (iw_handler) NULL, // SIOCSIWRTS
2228 (iw_handler) NULL, // SIOCGIWRTS
2229 (iw_handler) NULL, // SIOCSIWFRAG
2230 (iw_handler) NULL, // SIOCGIWFRAG
2231 (iw_handler) NULL, // SIOCSIWTXPOW
2232 (iw_handler) NULL, // SIOCGIWTXPOW
2233 (iw_handler) NULL, // SIOCSIWRETRY
2234 (iw_handler) NULL, // SIOCGIWRETRY
2235 (iw_handler) NULL, // SIOCSIWENCODE
2236 (iw_handler) NULL, // SIOCGIWENCODE
2237 (iw_handler) NULL, // SIOCSIWPOWER
2238 (iw_handler) NULL, // SIOCGIWPOWER
2240 //2008-0409-07, <Add> by Einsn Liu
2241 (iw_handler) NULL, // -- hole --
2242 (iw_handler) NULL, // -- hole --
2243 (iw_handler) NULL, // SIOCSIWGENIE
2244 (iw_handler) NULL, // SIOCGIWGENIE
2245 (iw_handler) NULL, // SIOCSIWAUTH
2246 (iw_handler) NULL, // SIOCGIWAUTH
2247 (iw_handler) NULL, // SIOCSIWENCODEEXT
2248 (iw_handler) NULL, // SIOCGIWENCODEEXT
2249 (iw_handler) NULL, // SIOCSIWPMKSA
2250 (iw_handler) NULL, // -- hole --
2254 static const iw_handler iwctl_private_handler[] =
2256 NULL, // SIOCIWFIRSTPRIV
2260 struct iw_priv_args iwctl_private_args[] = {
2261 { IOCTL_CMD_SET,
2262 IW_PRIV_TYPE_CHAR | 1024, 0,
2263 "set"},
2268 const struct iw_handler_def iwctl_handler_def =
2270 .get_wireless_stats = &iwctl_get_wireless_stats,
2271 .num_standard = sizeof(iwctl_handler)/sizeof(iw_handler),
2272 // .num_private = sizeof(iwctl_private_handler)/sizeof(iw_handler),
2273 // .num_private_args = sizeof(iwctl_private_args)/sizeof(struct iw_priv_args),
2274 .num_private = 0,
2275 .num_private_args = 0,
2276 .standard = (iw_handler *) iwctl_handler,
2277 // .private = (iw_handler *) iwctl_private_handler,
2278 // .private_args = (struct iw_priv_args *)iwctl_private_args,
2279 .private = NULL,
2280 .private_args = NULL,