Staging: vt6655: remove dependency on WIRELESS_EXT version
[linux-2.6/next.git] / drivers / staging / vt6655 / iwctl.c
blobb7c75a6b37eb9ed8c54ddcfe7f6bf3afd03a3d1f
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:
34 #if !defined(__DEVICE_H__)
35 #include "device.h"
36 #endif
37 #if !defined(__IOCTL_H__)
38 #include "ioctl.h"
39 #endif
40 #if !defined(__IOCMD_H__)
41 #include "iocmd.h"
42 #endif
43 #if !defined(__MAC_H__)
44 #include "mac.h"
45 #endif
46 #if !defined(__CARD_H__)
47 #include "card.h"
48 #endif
49 #if !defined(__HOSTAP_H__)
50 #include "hostap.h"
51 #endif
52 #if !defined(__UMEM_H__)
53 #include "umem.h"
54 #endif
55 #if !defined(__POWER_H__)
56 #include "power.h"
57 #endif
58 #if !defined(__RF_H__)
59 #include "rf.h"
60 #endif
62 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
63 #if !defined(__IOWPA_H__)
64 #include "iowpa.h"
65 #endif
66 #if !defined(__WPACTL_H__)
67 #include "wpactl.h"
68 #endif
69 #endif
71 #include <net/iw_handler.h>
72 extern WORD TxRate_iwconfig;//2008-5-8 <add> by chester
74 /*--------------------- Static Definitions -------------------------*/
76 //2008-0409-07, <Add> by Einsn Liu
77 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
78 #define SUPPORTED_WIRELESS_EXT 18
79 #else
80 #define SUPPORTED_WIRELESS_EXT 17
81 #endif
83 #ifdef WIRELESS_EXT
85 static const long frequency_list[] = {
86 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
87 4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
88 5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210, 5220, 5230, 5240,
89 5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680,
90 5700, 5745, 5765, 5785, 5805, 5825
93 #endif
96 /*--------------------- Static Classes ----------------------------*/
99 //static int msglevel =MSG_LEVEL_DEBUG;
100 static int msglevel =MSG_LEVEL_INFO;
103 /*--------------------- Static Variables --------------------------*/
104 /*--------------------- Static Functions --------------------------*/
106 /*--------------------- Export Variables --------------------------*/
108 #ifdef WIRELESS_EXT
110 struct iw_statistics *iwctl_get_wireless_stats(struct net_device *dev)
112 PSDevice pDevice = netdev_priv(dev);
113 long ldBm;
114 pDevice->wstats.status = pDevice->eOPMode;
115 #ifdef Calcu_LinkQual
116 #if 0
117 if(pDevice->byBBType == BB_TYPE_11B) {
118 if(pDevice->byCurrSQ > 120)
119 pDevice->scStatistic.LinkQuality = 100;
120 else
121 pDevice->scStatistic.LinkQuality = pDevice->byCurrSQ*100/120;
123 else if(pDevice->byBBType == BB_TYPE_11G) {
124 if(pDevice->byCurrSQ < 20)
125 pDevice->scStatistic.LinkQuality = 100;
126 else if(pDevice->byCurrSQ >96)
127 pDevice->scStatistic.LinkQuality = 0;
128 else
129 pDevice->scStatistic.LinkQuality = (96-pDevice->byCurrSQ)*100/76;
131 if(pDevice->bLinkPass !=TRUE)
132 pDevice->scStatistic.LinkQuality = 0;
133 #endif
134 if(pDevice->scStatistic.LinkQuality > 100)
135 pDevice->scStatistic.LinkQuality = 100;
136 pDevice->wstats.qual.qual =(BYTE) pDevice->scStatistic.LinkQuality;
137 #else
138 pDevice->wstats.qual.qual = pDevice->byCurrSQ;
139 #endif
140 RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm);
141 pDevice->wstats.qual.level = ldBm;
142 //pDevice->wstats.qual.level = 0x100 - pDevice->uCurrRSSI;
143 pDevice->wstats.qual.noise = 0;
144 pDevice->wstats.qual.updated = 1;
145 pDevice->wstats.discard.nwid = 0;
146 pDevice->wstats.discard.code = 0;
147 pDevice->wstats.discard.fragment = 0;
148 pDevice->wstats.discard.retries = (U32)pDevice->scStatistic.dwTsrErr;
149 pDevice->wstats.discard.misc = 0;
150 pDevice->wstats.miss.beacon = 0;
152 return &pDevice->wstats;
157 /*------------------------------------------------------------------*/
160 static int iwctl_commit(struct net_device *dev,
161 struct iw_request_info *info,
162 void *wrq,
163 char *extra)
165 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWCOMMIT \n");
167 return 0;
172 * Wireless Handler : get protocol name
175 int iwctl_giwname(struct net_device *dev,
176 struct iw_request_info *info,
177 char *wrq,
178 char *extra)
180 strcpy(wrq, "802.11-a/b/g");
181 return 0;
184 int iwctl_giwnwid(struct net_device *dev,
185 struct iw_request_info *info,
186 struct iw_param *wrq,
187 char *extra)
189 //wrq->value = 0x100;
190 //wrq->disabled = 0;
191 //wrq->fixed = 1;
192 //return 0;
193 return -EOPNOTSUPP;
197 * Wireless Handler : set scan
200 int iwctl_siwscan(struct net_device *dev,
201 struct iw_request_info *info,
202 struct iw_point *wrq,
203 char *extra)
205 PSDevice pDevice = (PSDevice)netdev_priv(dev);
206 struct iw_scan_req *req = (struct iw_scan_req *)extra;
207 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
208 BYTE abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
209 PWLAN_IE_SSID pItemSSID=NULL;
210 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSCAN \n");
213 if(pDevice->byReAssocCount > 0) { //reject scan when re-associating!
214 //send scan event to wpa_Supplicant
215 union iwreq_data wrqu;
216 printk("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
217 memset(&wrqu, 0, sizeof(wrqu));
218 wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
219 return 0;
222 spin_lock_irq(&pDevice->lock);
223 BSSvClearBSSList((HANDLE)pDevice, pDevice->bLinkPass);
225 //mike add: active scan OR passive scan OR desire_ssid scan
226 if(wrq->length == sizeof(struct iw_scan_req)) {
227 if (wrq->flags & IW_SCAN_THIS_ESSID) { //desire_ssid scan
228 memset(abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
229 pItemSSID = (PWLAN_IE_SSID)abyScanSSID;
230 pItemSSID->byElementID = WLAN_EID_SSID;
231 memcpy(pItemSSID->abySSID, req->essid, (int)req->essid_len);
232 if (pItemSSID->abySSID[req->essid_len - 1] == '\0') {
233 if(req->essid_len>0)
234 pItemSSID->len = req->essid_len - 1;
236 else
237 pItemSSID->len = req->essid_len;
238 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
239 printk("SIOCSIWSCAN:[desired_ssid=%s,len=%d]\n",((PWLAN_IE_SSID)abyScanSSID)->abySSID,
240 ((PWLAN_IE_SSID)abyScanSSID)->len);
241 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID);
242 spin_unlock_irq(&pDevice->lock);
244 return 0;
246 else if(req->scan_type == IW_SCAN_TYPE_PASSIVE) { //passive scan
247 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
250 else { //active scan
251 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
254 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
255 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
256 spin_unlock_irq(&pDevice->lock);
258 return 0;
263 * Wireless Handler : get scan results
266 int iwctl_giwscan(struct net_device *dev,
267 struct iw_request_info *info,
268 struct iw_point *wrq,
269 char *extra)
271 int ii, jj, kk;
272 PSDevice pDevice = (PSDevice)netdev_priv(dev);
273 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
274 PKnownBSS pBSS;
275 PWLAN_IE_SSID pItemSSID;
276 PWLAN_IE_SUPP_RATES pSuppRates, pExtSuppRates;
277 char *current_ev = extra;
278 char *end_buf = extra + IW_SCAN_MAX_DATA;
279 char *current_val = NULL;
280 struct iw_event iwe;
281 long ldBm;
282 char buf[MAX_WPA_IE_LEN * 2 + 30];
285 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSCAN \n");
287 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
288 // In scanning..
289 return -EAGAIN;
291 pBSS = &(pMgmt->sBSSList[0]);
292 for (ii = 0, jj = 0; jj < MAX_BSS_NUM ; jj++) {
293 if (current_ev >= end_buf)
294 break;
295 pBSS = &(pMgmt->sBSSList[jj]);
296 if (pBSS->bActive) {
297 memset(&iwe, 0, sizeof(iwe));
298 iwe.cmd = SIOCGIWAP;
299 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
300 memcpy(iwe.u.ap_addr.sa_data, pBSS->abyBSSID, WLAN_BSSID_LEN);
301 current_ev = iwe_stream_add_event(info,current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);
302 //ADD ssid
303 memset(&iwe, 0, sizeof(iwe));
304 iwe.cmd = SIOCGIWESSID;
305 pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
306 iwe.u.data.length = pItemSSID->len;
307 iwe.u.data.flags = 1;
308 current_ev = iwe_stream_add_point(info,current_ev,end_buf, &iwe, pItemSSID->abySSID);
309 //ADD mode
310 memset(&iwe, 0, sizeof(iwe));
311 iwe.cmd = SIOCGIWMODE;
312 if (WLAN_GET_CAP_INFO_ESS(pBSS->wCapInfo)) {
313 iwe.u.mode = IW_MODE_INFRA;
315 else {
316 iwe.u.mode = IW_MODE_ADHOC;
318 iwe.len = IW_EV_UINT_LEN;
319 current_ev = iwe_stream_add_event(info,current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
320 //ADD frequency
321 pSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abySuppRates;
322 pExtSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abyExtSuppRates;
323 memset(&iwe, 0, sizeof(iwe));
324 iwe.cmd = SIOCGIWFREQ;
325 iwe.u.freq.m = pBSS->uChannel;
326 iwe.u.freq.e = 0;
327 iwe.u.freq.i = 0;
328 current_ev = iwe_stream_add_event(info,current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
331 //2008-0409-04, <Add> by Einsn Liu
333 int f = (int)pBSS->uChannel - 1;
334 if(f < 0)f = 0;
335 iwe.u.freq.m = frequency_list[f] * 100000;
336 iwe.u.freq.e = 1;
338 current_ev = iwe_stream_add_event(info,current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
339 //ADD quality
340 memset(&iwe, 0, sizeof(iwe));
341 iwe.cmd = IWEVQUAL;
342 RFvRSSITodBm(pDevice, (BYTE)(pBSS->uRSSI), &ldBm);
343 iwe.u.qual.level = ldBm;
344 iwe.u.qual.noise = 0;
345 //2008-0409-01, <Add> by Einsn Liu
346 if(-ldBm<50){
347 iwe.u.qual.qual = 100;
348 }else if(-ldBm > 90) {
349 iwe.u.qual.qual = 0;
350 }else {
351 iwe.u.qual.qual=(40-(-ldBm-50))*100/40;
353 iwe.u.qual.updated=7;
355 // iwe.u.qual.qual = 0;
356 current_ev = iwe_stream_add_event(info,current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
358 memset(&iwe, 0, sizeof(iwe));
359 iwe.cmd = SIOCGIWENCODE;
360 iwe.u.data.length = 0;
361 if (WLAN_GET_CAP_INFO_PRIVACY(pBSS->wCapInfo)) {
362 iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
363 }else {
364 iwe.u.data.flags = IW_ENCODE_DISABLED;
366 current_ev = iwe_stream_add_point(info,current_ev,end_buf, &iwe, pItemSSID->abySSID);
368 memset(&iwe, 0, sizeof(iwe));
369 iwe.cmd = SIOCGIWRATE;
370 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
371 current_val = current_ev + IW_EV_LCP_LEN;
373 for (kk = 0 ; kk < 12 ; kk++) {
374 if (pSuppRates->abyRates[kk] == 0)
375 break;
376 // Bit rate given in 500 kb/s units (+ 0x80)
377 iwe.u.bitrate.value = ((pSuppRates->abyRates[kk] & 0x7f) * 500000);
378 current_val = iwe_stream_add_value(info,current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
380 for (kk = 0 ; kk < 8 ; kk++) {
381 if (pExtSuppRates->abyRates[kk] == 0)
382 break;
383 // Bit rate given in 500 kb/s units (+ 0x80)
384 iwe.u.bitrate.value = ((pExtSuppRates->abyRates[kk] & 0x7f) * 500000);
385 current_val = iwe_stream_add_value(info,current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
388 if((current_val - current_ev) > IW_EV_LCP_LEN)
389 current_ev = current_val;
391 memset(&iwe, 0, sizeof(iwe));
392 iwe.cmd = IWEVCUSTOM;
393 sprintf(buf, "bcn_int=%d", pBSS->wBeaconInterval);
394 iwe.u.data.length = strlen(buf);
395 current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, buf);
397 if ((pBSS->wWPALen > 0) && (pBSS->wWPALen <= MAX_WPA_IE_LEN)) {
398 memset(&iwe, 0, sizeof(iwe));
399 iwe.cmd = IWEVGENIE;
400 iwe.u.data.length = pBSS->wWPALen;
401 current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, pBSS->byWPAIE);
404 if ((pBSS->wRSNLen > 0) && (pBSS->wRSNLen <= MAX_WPA_IE_LEN)) {
405 memset(&iwe, 0, sizeof(iwe));
406 iwe.cmd = IWEVGENIE;
407 iwe.u.data.length = pBSS->wRSNLen;
408 current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, pBSS->byRSNIE);
412 }// for
414 wrq->length = current_ev - extra;
415 return 0;
421 * Wireless Handler : set frequence or channel
424 int iwctl_siwfreq(struct net_device *dev,
425 struct iw_request_info *info,
426 struct iw_freq *wrq,
427 char *extra)
429 PSDevice pDevice = (PSDevice)netdev_priv(dev);
430 int rc = 0;
432 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFREQ \n");
434 // If setting by frequency, convert to a channel
435 if((wrq->e == 1) &&
436 (wrq->m >= (int) 2.412e8) &&
437 (wrq->m <= (int) 2.487e8)) {
438 int f = wrq->m / 100000;
439 int c = 0;
440 while((c < 14) && (f != frequency_list[c]))
441 c++;
442 wrq->e = 0;
443 wrq->m = c + 1;
445 // Setting by channel number
446 if((wrq->m > 14) || (wrq->e > 0))
447 rc = -EOPNOTSUPP;
448 else {
449 int channel = wrq->m;
450 if((channel < 1) || (channel > 14)) {
451 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: New channel value of %d is invalid!\n", dev->name, wrq->m);
452 rc = -EINVAL;
453 } else {
454 // Yes ! We can set it !!!
455 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Set to channel = %d\n", channel);
456 pDevice->uChannel = channel;
457 //2007-0207-04,<Add> by EinsnLiu
458 //Make change effect at once
459 pDevice->bCommit = TRUE;
463 return rc;
467 * Wireless Handler : get frequence or channel
470 int iwctl_giwfreq(struct net_device *dev,
471 struct iw_request_info *info,
472 struct iw_freq *wrq,
473 char *extra)
475 PSDevice pDevice = (PSDevice)netdev_priv(dev);
476 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
478 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFREQ \n");
480 #ifdef WEXT_USECHANNELS
481 wrq->m = (int)pMgmt->uCurrChannel;
482 wrq->e = 0;
483 #else
485 int f = (int)pMgmt->uCurrChannel - 1;
486 if(f < 0)
487 f = 0;
488 wrq->m = frequency_list[f] * 100000;
489 wrq->e = 1;
491 #endif
493 return 0;
497 * Wireless Handler : set operation mode
500 int iwctl_siwmode(struct net_device *dev,
501 struct iw_request_info *info,
502 __u32 *wmode,
503 char *extra)
505 PSDevice pDevice = (PSDevice)netdev_priv(dev);
506 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
507 int rc = 0;
509 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMODE \n");
511 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP && pDevice->bEnableHostapd) {
512 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Can't set operation mode, hostapd is running \n");
513 return rc;
516 switch(*wmode) {
518 case IW_MODE_ADHOC:
519 if (pMgmt->eConfigMode != WMAC_CONFIG_IBSS_STA) {
520 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
521 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
522 pDevice->bCommit = TRUE;
525 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to ad-hoc \n");
526 break;
527 case IW_MODE_AUTO:
528 case IW_MODE_INFRA:
529 if (pMgmt->eConfigMode != WMAC_CONFIG_ESS_STA) {
530 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
531 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
532 pDevice->bCommit = TRUE;
535 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to infrastructure \n");
536 break;
537 case IW_MODE_MASTER:
539 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
540 rc = -EOPNOTSUPP;
541 break;
543 if (pMgmt->eConfigMode != WMAC_CONFIG_AP) {
544 pMgmt->eConfigMode = WMAC_CONFIG_AP;
545 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
546 pDevice->bCommit = TRUE;
549 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to Access Point \n");
550 break;
552 case IW_MODE_REPEAT:
553 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
554 rc = -EOPNOTSUPP;
555 break;
556 default:
557 rc = -EINVAL;
560 return rc;
564 * Wireless Handler : get operation mode
567 int iwctl_giwmode(struct net_device *dev,
568 struct iw_request_info *info,
569 __u32 *wmode,
570 char *extra)
572 PSDevice pDevice = (PSDevice)netdev_priv(dev);
573 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
576 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWMODE \n");
577 // If not managed, assume it's ad-hoc
578 switch (pMgmt->eConfigMode) {
579 case WMAC_CONFIG_ESS_STA:
580 *wmode = IW_MODE_INFRA;
581 break;
582 case WMAC_CONFIG_IBSS_STA:
583 *wmode = IW_MODE_ADHOC;
584 break;
585 case WMAC_CONFIG_AUTO:
586 *wmode = IW_MODE_INFRA;
587 break;
588 case WMAC_CONFIG_AP:
589 *wmode = IW_MODE_MASTER;
590 break;
591 default:
592 *wmode = IW_MODE_ADHOC;
595 return 0;
600 * Wireless Handler : get capability range
603 int iwctl_giwrange(struct net_device *dev,
604 struct iw_request_info *info,
605 struct iw_point *wrq,
606 char *extra)
608 struct iw_range *range = (struct iw_range *) extra;
609 int i,k;
610 BYTE abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
613 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRANGE \n");
614 if (wrq->pointer) {
615 wrq->length = sizeof(struct iw_range);
616 memset(range, 0, sizeof(struct iw_range));
617 range->min_nwid = 0x0000;
618 range->max_nwid = 0x0000;
619 range->num_channels = 14;
620 // Should be based on cap_rid.country to give only
621 // what the current card support
622 k = 0;
623 for(i = 0; i < 14; i++) {
624 range->freq[k].i = i + 1; // List index
625 range->freq[k].m = frequency_list[i] * 100000;
626 range->freq[k++].e = 1; // Values in table in MHz -> * 10^5 * 10
628 range->num_frequency = k;
629 // Hum... Should put the right values there
630 #ifdef Calcu_LinkQual
631 range->max_qual.qual = 100;
632 #else
633 range->max_qual.qual = 255;
634 #endif
635 range->max_qual.level = 0;
636 range->max_qual.noise = 0;
637 range->sensitivity = 255;
639 for(i = 0 ; i < 13 ; i++) {
640 range->bitrate[i] = abySupportedRates[i] * 500000;
641 if(range->bitrate[i] == 0)
642 break;
644 range->num_bitrates = i;
646 // Set an indication of the max TCP throughput
647 // in bit/s that we can expect using this interface.
648 // May be use for QoS stuff... Jean II
649 if(i > 2)
650 range->throughput = 5 * 1000 * 1000;
651 else
652 range->throughput = 1.5 * 1000 * 1000;
654 range->min_rts = 0;
655 range->max_rts = 2312;
656 range->min_frag = 256;
657 range->max_frag = 2312;
660 // the encoding capabilities
661 range->num_encoding_sizes = 3;
662 // 64(40) bits WEP
663 range->encoding_size[0] = 5;
664 // 128(104) bits WEP
665 range->encoding_size[1] = 13;
666 // 256 bits for WPA-PSK
667 range->encoding_size[2] = 32;
668 // 4 keys are allowed
669 range->max_encoding_tokens = 4;
671 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
672 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
674 range->min_pmp = 0;
675 range->max_pmp = 1000000;// 1 secs
676 range->min_pmt = 0;
677 range->max_pmt = 1000000;// 1 secs
678 range->pmp_flags = IW_POWER_PERIOD;
679 range->pmt_flags = IW_POWER_TIMEOUT;
680 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
682 // Transmit Power - values are in mW
684 range->txpower[0] = 100;
685 range->num_txpower = 1;
686 range->txpower_capa = IW_TXPOW_MWATT;
687 range->we_version_source = SUPPORTED_WIRELESS_EXT;
688 range->we_version_compiled = WIRELESS_EXT;
689 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
690 range->retry_flags = IW_RETRY_LIMIT;
691 range->r_time_flags = IW_RETRY_LIFETIME;
692 range->min_retry = 1;
693 range->max_retry = 65535;
694 range->min_r_time = 1024;
695 range->max_r_time = 65535 * 1024;
696 // Experimental measurements - boundary 11/5.5 Mb/s
697 // Note : with or without the (local->rssi), results
698 // are somewhat different. - Jean II
699 range->avg_qual.qual = 6;
700 range->avg_qual.level = 176; // -80 dBm
701 range->avg_qual.noise = 0;
705 return 0;
710 * Wireless Handler : set ap mac address
713 int iwctl_siwap(struct net_device *dev,
714 struct iw_request_info *info,
715 struct sockaddr *wrq,
716 char *extra)
718 PSDevice pDevice = (PSDevice)netdev_priv(dev);
719 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
720 int rc = 0;
721 BYTE ZeroBSSID[WLAN_BSSID_LEN]={0x00,0x00,0x00,0x00,0x00,0x00};
723 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAP \n");
724 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
725 // In scanning..
726 printk("SIOCSIWAP(??)-->In scanning...\n");
727 // return -EAGAIN;
729 if (wrq->sa_family != ARPHRD_ETHER)
730 rc = -EINVAL;
731 else {
732 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
733 memcpy(pMgmt->abyDesireBSSID, wrq->sa_data, 6);
734 //2008-0409-05, <Add> by Einsn Liu
735 if((pDevice->bLinkPass == TRUE) &&
736 (memcmp(pMgmt->abyDesireBSSID, pMgmt->abyCurrBSSID, 6)== 0)){
737 return rc;
739 //mike :add
740 if ((IS_BROADCAST_ADDRESS(pMgmt->abyDesireBSSID)) ||
741 (memcmp(pMgmt->abyDesireBSSID, ZeroBSSID, 6) == 0)){
742 printk("SIOCSIWAP:invalid desired BSSID return!\n");
743 return rc;
745 //mike add: if desired AP is hidden ssid(there are two same BSSID in list),
746 // then ignore,because you don't known which one to be connect with??
748 UINT ii , uSameBssidNum=0;
749 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
750 if (pMgmt->sBSSList[ii].bActive &&
751 IS_ETH_ADDRESS_EQUAL(pMgmt->sBSSList[ii].abyBSSID,pMgmt->abyDesireBSSID)) {
752 uSameBssidNum++;
755 if(uSameBssidNum >= 2) { //hit: desired AP is in hidden ssid mode!!!
756 printk("SIOCSIWAP:ignore for desired AP in hidden mode\n");
757 return rc;
760 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
761 pDevice->bCommit = TRUE;
764 return rc;
768 * Wireless Handler : get ap mac address
771 int iwctl_giwap(struct net_device *dev,
772 struct iw_request_info *info,
773 struct sockaddr *wrq,
774 char *extra)
776 PSDevice pDevice = (PSDevice)netdev_priv(dev);
777 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
780 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAP \n");
782 memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
783 //2008-0410,<Modify> by Einsn Liu
784 if ((pDevice->bLinkPass == FALSE) && (pMgmt->eCurrMode != WMAC_MODE_ESS_AP))
785 memset(wrq->sa_data, 0, 6);
787 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
788 memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
791 wrq->sa_family = ARPHRD_ETHER;
793 return 0;
799 * Wireless Handler : get ap list
802 int iwctl_giwaplist(struct net_device *dev,
803 struct iw_request_info *info,
804 struct iw_point *wrq,
805 char *extra)
807 int ii,jj, rc = 0;
808 struct sockaddr sock[IW_MAX_AP];
809 struct iw_quality qual[IW_MAX_AP];
810 PSDevice pDevice = (PSDevice)netdev_priv(dev);
811 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
814 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAPLIST \n");
815 // Only super-user can see AP list
817 if (!capable(CAP_NET_ADMIN)) {
818 rc = -EPERM;
819 return rc;
822 if (wrq->pointer) {
824 PKnownBSS pBSS = &(pMgmt->sBSSList[0]);
826 for (ii = 0, jj= 0; ii < MAX_BSS_NUM; ii++) {
827 pBSS = &(pMgmt->sBSSList[ii]);
828 if (!pBSS->bActive)
829 continue;
830 if ( jj >= IW_MAX_AP)
831 break;
832 memcpy(sock[jj].sa_data, pBSS->abyBSSID, 6);
833 sock[jj].sa_family = ARPHRD_ETHER;
834 qual[jj].level = pBSS->uRSSI;
835 qual[jj].qual = qual[jj].noise = 0;
836 qual[jj].updated = 2;
837 jj++;
840 wrq->flags = 1; // Should be define'd
841 wrq->length = jj;
842 memcpy(extra, sock, sizeof(struct sockaddr)*jj);
843 memcpy(extra + sizeof(struct sockaddr)*jj, qual, sizeof(struct iw_quality)*jj);
846 return rc;
851 * Wireless Handler : set essid
854 int iwctl_siwessid(struct net_device *dev,
855 struct iw_request_info *info,
856 struct iw_point *wrq,
857 char *extra)
859 PSDevice pDevice = (PSDevice)netdev_priv(dev);
860 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
861 PWLAN_IE_SSID pItemSSID;
862 //2008-0409-05, <Add> by Einsn Liu
863 BYTE len;
866 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWESSID \n");
867 pDevice->fWPA_Authened = FALSE;
868 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
869 // In scanning..
870 printk("SIOCSIWESSID(??)-->In scanning...\n");
871 // return -EAGAIN;
873 // Check if we asked for `any'
874 if(wrq->flags == 0) {
875 // Just send an empty SSID list
876 // Just send an empty SSID list
877 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
878 memset(pMgmt->abyDesireBSSID, 0xFF,6);
879 printk("set essid to 'any' \n");
880 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
881 //Unknown desired AP,so here need not associate??
882 //if(pDevice->bWPASuppWextEnabled == TRUE) {
883 return 0;
884 // }
885 #endif
886 } else {
887 // Set the SSID
888 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
889 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
890 pItemSSID->byElementID = WLAN_EID_SSID;
891 memcpy(pItemSSID->abySSID, extra, wrq->length);
892 if (pItemSSID->abySSID[wrq->length - 1] == '\0') {
893 if(wrq->length>0)
894 pItemSSID->len = wrq->length - 1;
896 else
897 pItemSSID->len = wrq->length;
898 printk("set essid to %s \n",pItemSSID->abySSID);
899 //2008-0409-05, <Add> by Einsn Liu
900 len=(pItemSSID->len > ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len)?pItemSSID->len:((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len;
901 if((pDevice->bLinkPass == TRUE) &&
902 (memcmp(pItemSSID->abySSID,((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,len)==0))
903 return 0;
905 //mike:need clear desiredBSSID
906 if(pItemSSID->len==0) {
907 memset(pMgmt->abyDesireBSSID, 0xFF,6);
908 return 0;
911 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
912 //Wext wil order another command of siwap to link with desired AP,
913 //so here need not associate??
914 if(pDevice->bWPASuppWextEnabled == TRUE) {
915 /*******search if in hidden ssid mode ****/
917 PKnownBSS pCurr = NULL;
918 BYTE abyTmpDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
919 UINT ii , uSameBssidNum=0;
921 memset(abyTmpDesireSSID,0,sizeof(abyTmpDesireSSID));
922 memcpy(abyTmpDesireSSID,pMgmt->abyDesireSSID,sizeof(abyTmpDesireSSID));
923 pCurr = BSSpSearchBSSList(pDevice,
924 NULL,
925 abyTmpDesireSSID,
926 pMgmt->eConfigPHYMode
929 if (pCurr == NULL){
930 printk("SIOCSIWESSID:hidden ssid site survey before associate.......\n");
931 vResetCommandTimer((HANDLE) pDevice);
932 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
933 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
934 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
936 else { //mike:to find out if that desired SSID is a hidden-ssid AP ,
937 // by means of judging if there are two same BSSID exist in list ?
938 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
939 if (pMgmt->sBSSList[ii].bActive &&
940 IS_ETH_ADDRESS_EQUAL(pMgmt->sBSSList[ii].abyBSSID, pCurr->abyBSSID)) {
941 uSameBssidNum++;
944 if(uSameBssidNum >= 2) { //hit: desired AP is in hidden ssid mode!!!
945 printk("SIOCSIWESSID:hidden ssid directly associate.......\n");
946 vResetCommandTimer((HANDLE) pDevice);
947 pMgmt->eScanType = WMAC_SCAN_PASSIVE; //this scan type,you'll submit scan result!
948 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
949 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
953 return 0;
955 #endif
957 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set essid = %s \n", pItemSSID->abySSID);
959 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO " SIOCSIWESSID2 \n");
960 pItemSSID->len = wrq->length;
964 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
965 pDevice->bCommit = TRUE;
969 return 0;
974 * Wireless Handler : get essid
977 int iwctl_giwessid(struct net_device *dev,
978 struct iw_request_info *info,
979 struct iw_point *wrq,
980 char *extra)
983 PSDevice pDevice = (PSDevice)netdev_priv(dev);
984 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
985 PWLAN_IE_SSID pItemSSID;
987 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWESSID \n");
989 // Note : if wrq->u.data.flags != 0, we should
990 // get the relevant SSID from the SSID list...
992 // Get the current SSID
993 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
994 //pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
995 memcpy(extra, pItemSSID->abySSID , pItemSSID->len);
996 extra[pItemSSID->len] = '\0';
997 wrq->length = pItemSSID->len + 1;
998 //2008-0409-03, <Add> by Einsn Liu
999 wrq->length = pItemSSID->len;
1000 wrq->flags = 1; // active
1003 return 0;
1007 * Wireless Handler : set data rate
1010 int iwctl_siwrate(struct net_device *dev,
1011 struct iw_request_info *info,
1012 struct iw_param *wrq,
1013 char *extra)
1015 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1016 int rc = 0;
1017 u8 brate = 0;
1018 int i;
1019 BYTE abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
1022 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRATE \n");
1023 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
1024 rc = -EINVAL;
1025 return rc;
1028 // First : get a valid bit rate value
1030 // Which type of value
1031 if((wrq->value < 13) &&
1032 (wrq->value >= 0)) {
1033 // Setting by rate index
1034 // Find value in the magic rate table
1035 brate = wrq->value;
1036 } else {
1037 // Setting by frequency value
1038 u8 normvalue = (u8) (wrq->value/500000);
1040 // Check if rate is valid
1041 for(i = 0 ; i < 13 ; i++) {
1042 if(normvalue == abySupportedRates[i]) {
1043 brate = i;
1044 break;
1048 // -1 designed the max rate (mostly auto mode)
1049 if(wrq->value == -1) {
1050 // Get the highest available rate
1051 for(i = 0 ; i < 13 ; i++) {
1052 if(abySupportedRates[i] == 0)
1053 break;
1055 if(i != 0)
1056 brate = i - 1;
1059 // Check that it is valid
1060 // brate is index of abySupportedRates[]
1061 if(brate > 13 ) {
1062 rc = -EINVAL;
1063 return rc;
1066 // Now, check if we want a fixed or auto value
1067 if(wrq->fixed != 0) {
1068 // Fixed mode
1069 // One rate, fixed
1070 printk("Rate Fix\n");
1071 pDevice->bFixRate = TRUE;
1072 if ((pDevice->byBBType == BB_TYPE_11B)&& (brate > 3)) {
1074 pDevice->uConnectionRate = 3;
1076 else {
1077 pDevice->uConnectionRate = brate;
1078 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fixed to Rate %d \n", pDevice->uConnectionRate);
1082 else {
1083 pDevice->bFixRate = FALSE;
1084 pDevice->uConnectionRate = 13;
1085 printk("auto rate:connection_rate is 13\n");
1088 return rc;
1092 * Wireless Handler : get data rate
1095 int iwctl_giwrate(struct net_device *dev,
1096 struct iw_request_info *info,
1097 struct iw_param *wrq,
1098 char *extra)
1100 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1101 //2007-0118-05,<Mark> by EinsnLiu
1102 //Mark the unnecessary sentences.
1103 // PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1105 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRATE \n");
1107 BYTE abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
1108 int brate = 0;
1109 //2008-5-8 <modify> by chester
1110 if(pDevice->bLinkPass){
1111 if(pDevice->bFixRate == TRUE){
1112 if (pDevice->uConnectionRate < 13) {
1113 brate = abySupportedRates[pDevice->uConnectionRate];
1114 }else {
1115 if (pDevice->byBBType == BB_TYPE_11B)
1116 brate = 0x16;
1117 if (pDevice->byBBType == BB_TYPE_11G)
1118 brate = 0x6C;
1119 if (pDevice->byBBType == BB_TYPE_11A)
1120 brate = 0x6C;
1123 else
1126 brate = abySupportedRates[TxRate_iwconfig];
1129 else brate =0;
1130 //2007-0118-05,<Mark> by EinsnLiu
1131 //Mark the unnecessary sentences.
1133 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1134 if (pDevice->byBBType == BB_TYPE_11B)
1135 brate = 0x16;
1136 if (pDevice->byBBType == BB_TYPE_11G)
1137 brate = 0x6C;
1138 if (pDevice->byBBType == BB_TYPE_11A)
1139 brate = 0x6C;
1143 // if (pDevice->uConnectionRate == 13)
1144 // brate = abySupportedRates[pDevice->wCurrentRate];
1145 wrq->value = brate * 500000;
1146 // If more than one rate, set auto
1147 if (pDevice->bFixRate == TRUE)
1148 wrq->fixed = TRUE;
1152 return 0;
1158 * Wireless Handler : set rts threshold
1161 int iwctl_siwrts(struct net_device *dev,
1162 struct iw_request_info *info,
1163 struct iw_param *wrq,
1164 char *extra)
1166 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1167 int rc = 0;
1169 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRTS \n");
1172 int rthr = wrq->value;
1173 if(wrq->disabled)
1174 rthr = 2312;
1175 if((rthr < 0) || (rthr > 2312)) {
1176 rc = -EINVAL;
1177 }else {
1178 pDevice->wRTSThreshold = rthr;
1182 return 0;
1186 * Wireless Handler : get rts
1189 int iwctl_giwrts(struct net_device *dev,
1190 struct iw_request_info *info,
1191 struct iw_param *wrq,
1192 char *extra)
1194 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1196 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRTS \n");
1197 wrq->value = pDevice->wRTSThreshold;
1198 wrq->disabled = (wrq->value >= 2312);
1199 wrq->fixed = 1;
1201 return 0;
1205 * Wireless Handler : set fragment threshold
1208 int iwctl_siwfrag(struct net_device *dev,
1209 struct iw_request_info *info,
1210 struct iw_param *wrq,
1211 char *extra)
1213 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1214 int rc = 0;
1215 int fthr = wrq->value;
1218 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFRAG \n");
1221 if (wrq->disabled)
1222 fthr = 2312;
1223 if((fthr < 256) || (fthr > 2312)) {
1224 rc = -EINVAL;
1225 }else {
1226 fthr &= ~0x1; // Get an even value
1227 pDevice->wFragmentationThreshold = (u16)fthr;
1230 return rc;
1234 * Wireless Handler : get fragment threshold
1237 int iwctl_giwfrag(struct net_device *dev,
1238 struct iw_request_info *info,
1239 struct iw_param *wrq,
1240 char *extra)
1242 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1244 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFRAG \n");
1245 wrq->value = pDevice->wFragmentationThreshold;
1246 wrq->disabled = (wrq->value >= 2312);
1247 wrq->fixed = 1;
1249 return 0;
1255 * Wireless Handler : set retry threshold
1257 int iwctl_siwretry(struct net_device *dev,
1258 struct iw_request_info *info,
1259 struct iw_param *wrq,
1260 char *extra)
1262 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1263 int rc = 0;
1266 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRETRY \n");
1268 if (wrq->disabled) {
1269 rc = -EINVAL;
1270 return rc;
1273 if (wrq->flags & IW_RETRY_LIMIT) {
1274 if(wrq->flags & IW_RETRY_MAX)
1275 pDevice->byLongRetryLimit = wrq->value;
1276 else if (wrq->flags & IW_RETRY_MIN)
1277 pDevice->byShortRetryLimit = wrq->value;
1278 else {
1279 // No modifier : set both
1280 pDevice->byShortRetryLimit = wrq->value;
1281 pDevice->byLongRetryLimit = wrq->value;
1284 if (wrq->flags & IW_RETRY_LIFETIME) {
1285 pDevice->wMaxTransmitMSDULifetime = wrq->value;
1289 return rc;
1293 * Wireless Handler : get retry threshold
1295 int iwctl_giwretry(struct net_device *dev,
1296 struct iw_request_info *info,
1297 struct iw_param *wrq,
1298 char *extra)
1300 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1301 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRETRY \n");
1302 wrq->disabled = 0; // Can't be disabled
1304 // Note : by default, display the min retry number
1305 if((wrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1306 wrq->flags = IW_RETRY_LIFETIME;
1307 wrq->value = (int)pDevice->wMaxTransmitMSDULifetime; //ms
1308 } else if((wrq->flags & IW_RETRY_MAX)) {
1309 wrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
1310 wrq->value = (int)pDevice->byLongRetryLimit;
1311 } else {
1312 wrq->flags = IW_RETRY_LIMIT;
1313 wrq->value = (int)pDevice->byShortRetryLimit;
1314 if((int)pDevice->byShortRetryLimit != (int)pDevice->byLongRetryLimit)
1315 wrq->flags |= IW_RETRY_MIN;
1319 return 0;
1324 * Wireless Handler : set encode mode
1326 int iwctl_siwencode(struct net_device *dev,
1327 struct iw_request_info *info,
1328 struct iw_point *wrq,
1329 char *extra)
1331 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1332 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1333 DWORD dwKeyIndex = (DWORD)(wrq->flags & IW_ENCODE_INDEX);
1334 int ii,uu, rc = 0;
1335 int index = (wrq->flags & IW_ENCODE_INDEX);
1337 //2007-0207-07,<Modify> by EinsnLiu
1338 //There are some problems when using iwconfig encode/key command to set the WEP key.
1339 //I almost rewrite this function.
1340 //now it support:(assume the wireless interface's name is eth0)
1341 //iwconfig eth0 key [1] 1122334455 open /*set key stirng to index 1,and driver using key index is set to 1*/
1342 //iwconfig eth0 key [3] /*set driver using key index to 3,the key string no change */
1343 //iwconfig eth0 key 1122334455 /*set key string to driver using index*/
1344 //iwconfig eth0 key restricted /*enable share key*/
1346 PSKeyTable pkeytab;
1348 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODE \n");
1350 if((wrq->flags & IW_ENCODE_DISABLED)==0){
1351 //Not disable encryption
1353 if (dwKeyIndex > WLAN_WEP_NKEYS) {
1354 rc = -EINVAL;
1355 return rc;
1358 if(dwKeyIndex<1&&((wrq->flags&IW_ENCODE_NOKEY)==0)){//set default key
1359 if(pDevice->byKeyIndex<WLAN_WEP_NKEYS){
1360 dwKeyIndex=pDevice->byKeyIndex;
1362 else dwKeyIndex=0;
1363 }else dwKeyIndex--;
1366 // Check the size of the key
1367 if (wrq->length > WLAN_WEP232_KEYLEN) {
1368 rc = -EINVAL;
1369 return rc;
1372 if(wrq->length>0){//have key
1374 if (wrq->length == WLAN_WEP232_KEYLEN) {
1375 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 232 bit wep key\n");
1377 else if (wrq->length == WLAN_WEP104_KEYLEN) {
1378 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 104 bit wep key\n");
1380 else if (wrq->length == WLAN_WEP40_KEYLEN) {
1381 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 40 bit wep key, index= %d\n", (int)dwKeyIndex);
1382 }else {//no support length
1383 rc = -EINVAL;
1384 return rc;
1386 memset(pDevice->abyKey, 0, WLAN_WEP232_KEYLEN);
1387 memcpy(pDevice->abyKey, extra, wrq->length);
1389 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyKey: ");
1390 for (ii = 0; ii < wrq->length; ii++) {
1391 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pDevice->abyKey[ii]);
1394 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1395 spin_lock_irq(&pDevice->lock);
1396 KeybSetDefaultKey(&(pDevice->sKey),
1397 (DWORD)(dwKeyIndex | (1 << 31)),
1398 wrq->length,
1399 NULL,
1400 pDevice->abyKey,
1401 KEY_CTL_WEP,
1402 pDevice->PortOffset,
1403 pDevice->byLocalID
1405 spin_unlock_irq(&pDevice->lock);
1407 pDevice->byKeyIndex = (BYTE)dwKeyIndex;
1408 pDevice->uKeyLength = wrq->length;
1409 pDevice->bTransmitKey = TRUE;
1410 pDevice->bEncryptionEnable = TRUE;
1411 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1413 }else if(index>0){
1414 //when the length is 0 the request only changes the default transmit key index
1415 //check the new key has a non zero lenget
1416 if(pDevice->bEncryptionEnable==FALSE)
1418 rc = -EINVAL;
1419 return rc;
1421 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Just set Default key Index:\n");
1422 pkeytab=&(pDevice->sKey.KeyTable[MAX_KEY_TABLE-1]);
1423 if(pkeytab->GroupKey[(BYTE)dwKeyIndex].uKeyLength==0){
1424 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Default key len is 0\n");
1425 rc = -EINVAL;
1426 return rc;
1428 pDevice->byKeyIndex =(BYTE)dwKeyIndex;
1429 pkeytab->dwGTKeyIndex =dwKeyIndex | (1 << 31);
1430 pkeytab->GroupKey[(BYTE)dwKeyIndex].dwKeyIndex=dwKeyIndex | (1 << 31);
1433 }else {//disable the key
1434 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable WEP function\n");
1435 if(pDevice->bEncryptionEnable==FALSE)
1436 return 0;
1437 pMgmt->bShareKeyAlgorithm = FALSE;
1438 pDevice->bEncryptionEnable = FALSE;
1439 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1440 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1441 spin_lock_irq(&pDevice->lock);
1442 for(uu=0;uu<MAX_KEY_TABLE;uu++)
1443 MACvDisableKeyEntry(pDevice->PortOffset, uu);
1444 spin_unlock_irq(&pDevice->lock);
1447 //End Modify,Einsn
1450 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODE \n");
1452 // Check the size of the key
1453 if (wrq->length > WLAN_WEP232_KEYLEN) {
1454 rc = -EINVAL;
1455 return rc;
1458 if (dwKeyIndex > WLAN_WEP_NKEYS) {
1459 rc = -EINVAL;
1460 return rc;
1463 if (dwKeyIndex > 0)
1464 dwKeyIndex--;
1466 // Send the key to the card
1467 if (wrq->length > 0) {
1469 if (wrq->length == WLAN_WEP232_KEYLEN) {
1470 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 232 bit wep key\n");
1472 else if (wrq->length == WLAN_WEP104_KEYLEN) {
1473 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 104 bit wep key\n");
1475 else if (wrq->length == WLAN_WEP40_KEYLEN) {
1476 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 40 bit wep key, index= %d\n", (int)dwKeyIndex);
1478 memset(pDevice->abyKey, 0, WLAN_WEP232_KEYLEN);
1479 memcpy(pDevice->abyKey, extra, wrq->length);
1481 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyKey: ");
1482 for (ii = 0; ii < wrq->length; ii++) {
1483 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pDevice->abyKey[ii]);
1486 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1487 spin_lock_irq(&pDevice->lock);
1488 KeybSetDefaultKey(&(pDevice->sKey),
1489 (DWORD)(pDevice->byKeyIndex | (1 << 31)),
1490 pDevice->uKeyLength,
1491 NULL,
1492 pDevice->abyKey,
1493 KEY_CTL_WEP,
1494 pDevice->PortOffset,
1495 pDevice->byLocalID
1497 spin_unlock_irq(&pDevice->lock);
1499 pDevice->byKeyIndex = (BYTE)dwKeyIndex;
1500 pDevice->uKeyLength = wrq->length;
1501 pDevice->bTransmitKey = TRUE;
1502 pDevice->bEncryptionEnable = TRUE;
1503 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1505 // Do we want to just set the transmit key index ?
1506 if ( index < 4 ) {
1507 pDevice->byKeyIndex = index;
1509 else if(!wrq->flags & IW_ENCODE_MODE) {
1510 rc = -EINVAL;
1511 return rc;
1514 // Read the flags
1515 if(wrq->flags & IW_ENCODE_DISABLED){
1517 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable WEP function\n");
1518 pMgmt->bShareKeyAlgorithm = FALSE;
1519 pDevice->bEncryptionEnable = FALSE;
1520 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1521 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1522 spin_lock_irq(&pDevice->lock);
1523 for(uu=0;uu<MAX_KEY_TABLE;uu++)
1524 MACvDisableKeyEntry(pDevice->PortOffset, uu);
1525 spin_unlock_irq(&pDevice->lock);
1530 if(wrq->flags & IW_ENCODE_RESTRICTED) {
1531 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & ShareKey System\n");
1532 pMgmt->bShareKeyAlgorithm = TRUE;
1534 if(wrq->flags & IW_ENCODE_OPEN) {
1535 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & Open System\n");
1536 pMgmt->bShareKeyAlgorithm = FALSE;
1538 return rc;
1542 * Wireless Handler : get encode mode
1545 int iwctl_giwencode(struct net_device *dev,
1546 struct iw_request_info *info,
1547 struct iw_point *wrq,
1548 char *extra)
1550 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1551 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1552 int rc = 0;
1553 char abyKey[WLAN_WEP232_KEYLEN];
1554 UINT index = (UINT)(wrq->flags & IW_ENCODE_INDEX);
1555 PSKeyItem pKey = NULL;
1557 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODE\n");
1558 //2007-0207-06,<Add> by EinsnLiu
1559 //the key index in iwconfig is 1-4 when our driver is 0-3
1560 //so it can't be used directly.
1561 //if the index is 0,we should used the index set by driver.
1562 if (index > WLAN_WEP_NKEYS) {
1563 rc = -EINVAL;
1564 return rc;
1566 if(index<1){//set default key
1567 if(pDevice->byKeyIndex<WLAN_WEP_NKEYS){
1568 index=pDevice->byKeyIndex;
1570 else index=0;
1571 }else index--;
1572 //End Add,Einsn
1574 memset(abyKey, 0, sizeof(abyKey));
1575 // Check encryption mode
1576 wrq->flags = IW_ENCODE_NOKEY;
1577 // Is WEP enabled ???
1578 if (pDevice->bEncryptionEnable)
1579 wrq->flags |= IW_ENCODE_ENABLED;
1580 else
1581 wrq->flags |= IW_ENCODE_DISABLED;
1583 if (pMgmt->bShareKeyAlgorithm)
1584 wrq->flags |= IW_ENCODE_RESTRICTED;
1585 else
1586 wrq->flags |= IW_ENCODE_OPEN;
1588 if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (BYTE)index , &pKey)){
1589 wrq->length = pKey->uKeyLength;
1590 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1591 //2007-0207-06,<Modify> by EinsnLiu
1592 //only get key success need to copy data
1593 //index should +1.
1594 //there is not necessary to return -EINVAL when get key failed
1595 //if return -EINVAL,the encryption item can't be display by the command "iwconfig".
1596 wrq->flags |= index+1;
1597 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1600 //else {
1601 // rc = -EINVAL;
1602 // return rc;
1603 // }
1606 //End Modify,Einsn
1608 return 0;
1612 //2008-0409-06, <Add> by Einsn Liu
1614 int iwctl_giwencode(struct net_device *dev,
1615 struct iw_request_info *info,
1616 struct iw_point *wrq,
1617 char *extra)
1619 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1620 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1621 char abyKey[WLAN_WEP232_KEYLEN];
1623 UINT index = (UINT)(wrq->flags & IW_ENCODE_INDEX);
1624 PSKeyItem pKey = NULL;
1626 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODE\n");
1628 if (index > WLAN_WEP_NKEYS) {
1629 return -EINVAL;
1631 if(index<1){//get default key
1632 if(pDevice->byKeyIndex<WLAN_WEP_NKEYS){
1633 index=pDevice->byKeyIndex;
1634 } else
1635 index=0;
1636 }else
1637 index--;
1639 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
1640 // Check encryption mode
1641 wrq->flags = IW_ENCODE_NOKEY;
1642 // Is WEP enabled ???
1643 if (pDevice->bEncryptionEnable)
1644 wrq->flags |= IW_ENCODE_ENABLED;
1645 else
1646 wrq->flags |= IW_ENCODE_DISABLED;
1648 if (pMgmt->bShareKeyAlgorithm)
1649 wrq->flags |= IW_ENCODE_RESTRICTED;
1650 else
1651 wrq->flags |= IW_ENCODE_OPEN;
1652 wrq->length=0;
1654 if((index==0)&&(pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled||
1655 pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)){//get wpa pairwise key
1656 if (KeybGetKey(&(pDevice->sKey),pMgmt->abyCurrBSSID, 0xffffffff, &pKey)){
1657 wrq->length = pKey->uKeyLength;
1658 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1659 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1661 }else if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (BYTE)index , &pKey)){
1662 wrq->length = pKey->uKeyLength;
1663 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1664 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1667 wrq->flags |= index+1;
1669 return 0;
1673 * Wireless Handler : set power mode
1675 int iwctl_siwpower(struct net_device *dev,
1676 struct iw_request_info *info,
1677 struct iw_param *wrq,
1678 char *extra)
1680 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1681 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1682 int rc = 0;
1684 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER \n");
1686 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
1687 rc = -EINVAL;
1688 return rc;
1691 if (wrq->disabled) {
1692 pDevice->ePSMode = WMAC_POWER_CAM;
1693 PSvDisablePowerSaving(pDevice);
1694 return rc;
1696 if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1697 pDevice->ePSMode = WMAC_POWER_FAST;
1698 PSvEnablePowerSaving((HANDLE)pDevice, pMgmt->wListenInterval);
1700 } else if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
1701 pDevice->ePSMode = WMAC_POWER_FAST;
1702 PSvEnablePowerSaving((HANDLE)pDevice, pMgmt->wListenInterval);
1704 switch (wrq->flags & IW_POWER_MODE) {
1705 case IW_POWER_UNICAST_R:
1706 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_UNICAST_R \n");
1707 rc = -EINVAL;
1708 break;
1709 case IW_POWER_ALL_R:
1710 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ALL_R \n");
1711 rc = -EINVAL;
1712 case IW_POWER_ON:
1713 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ON \n");
1714 break;
1715 default:
1716 rc = -EINVAL;
1719 return rc;
1723 * Wireless Handler : get power mode
1725 int iwctl_giwpower(struct net_device *dev,
1726 struct iw_request_info *info,
1727 struct iw_param *wrq,
1728 char *extra)
1730 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1731 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1732 int mode = pDevice->ePSMode;
1735 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPOWER \n");
1738 if ((wrq->disabled = (mode == WMAC_POWER_CAM)))
1739 return 0;
1741 if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1742 wrq->value = (int)((pMgmt->wListenInterval * pMgmt->wCurrBeaconPeriod) << 10);
1743 wrq->flags = IW_POWER_TIMEOUT;
1744 } else {
1745 wrq->value = (int)((pMgmt->wListenInterval * pMgmt->wCurrBeaconPeriod) << 10);
1746 wrq->flags = IW_POWER_PERIOD;
1748 wrq->flags |= IW_POWER_ALL_R;
1750 return 0;
1755 * Wireless Handler : get Sensitivity
1757 int iwctl_giwsens(struct net_device *dev,
1758 struct iw_request_info *info,
1759 struct iw_param *wrq,
1760 char *extra)
1762 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1763 long ldBm;
1765 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSENS \n");
1766 if (pDevice->bLinkPass == TRUE) {
1767 RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm);
1768 wrq->value = ldBm;
1770 else {
1771 wrq->value = 0;
1773 wrq->disabled = (wrq->value == 0);
1774 wrq->fixed = 1;
1777 return 0;
1780 //2008-0409-07, <Add> by Einsn Liu
1781 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1783 int iwctl_siwauth(struct net_device *dev,
1784 struct iw_request_info *info,
1785 struct iw_param *wrq,
1786 char *extra)
1788 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1789 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1790 int ret=0;
1791 static int wpa_version=0; //must be static to save the last value,einsn liu
1792 static int pairwise=0;
1794 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH \n");
1795 switch (wrq->flags & IW_AUTH_INDEX) {
1796 case IW_AUTH_WPA_VERSION:
1797 wpa_version = wrq->value;
1798 if(wrq->value == IW_AUTH_WPA_VERSION_DISABLED) {
1799 printk("iwctl_siwauth:set WPADEV to disable at 1??????\n");
1800 //pDevice->bWPADevEnable = FALSE;
1802 else if(wrq->value == IW_AUTH_WPA_VERSION_WPA) {
1803 printk("iwctl_siwauth:set WPADEV to WPA1******\n");
1805 else {
1806 printk("iwctl_siwauth:set WPADEV to WPA2******\n");
1808 //pDevice->bWPASuppWextEnabled =TRUE;
1809 break;
1810 case IW_AUTH_CIPHER_PAIRWISE:
1811 pairwise = wrq->value;
1813 if(pairwise == IW_AUTH_CIPHER_CCMP){
1814 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1815 }else if(pairwise == IW_AUTH_CIPHER_TKIP){
1816 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1817 }else if(pairwise == IW_AUTH_CIPHER_WEP40||pairwise == IW_AUTH_CIPHER_WEP104){
1818 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1819 }else if(pairwise == IW_AUTH_CIPHER_NONE){
1820 //do nothing,einsn liu
1821 }else pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1823 break;
1824 case IW_AUTH_CIPHER_GROUP:
1825 if(wpa_version == IW_AUTH_WPA_VERSION_DISABLED)
1826 break;
1827 if(pairwise == IW_AUTH_CIPHER_NONE){
1828 if(wrq->value == IW_AUTH_CIPHER_CCMP){
1829 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1830 }else {
1831 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1834 break;
1835 case IW_AUTH_KEY_MGMT:
1837 if(wpa_version == IW_AUTH_WPA_VERSION_WPA2){
1838 if(wrq->value == IW_AUTH_KEY_MGMT_PSK)
1839 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
1840 else pMgmt->eAuthenMode = WMAC_AUTH_WPA2;
1841 }else if(wpa_version == IW_AUTH_WPA_VERSION_WPA){
1842 if(wrq->value == 0){
1843 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
1844 }else if(wrq->value == IW_AUTH_KEY_MGMT_PSK)
1845 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
1846 else pMgmt->eAuthenMode = WMAC_AUTH_WPA;
1849 break;
1850 case IW_AUTH_TKIP_COUNTERMEASURES:
1851 break; /* FIXME */
1852 case IW_AUTH_DROP_UNENCRYPTED:
1853 break;
1854 case IW_AUTH_80211_AUTH_ALG:
1855 if(wrq->value==IW_AUTH_ALG_OPEN_SYSTEM){
1856 pMgmt->bShareKeyAlgorithm=FALSE;
1857 }else if(wrq->value==IW_AUTH_ALG_SHARED_KEY){
1858 pMgmt->bShareKeyAlgorithm=TRUE;
1860 break;
1861 case IW_AUTH_WPA_ENABLED:
1862 //pDevice->bWPADevEnable = !! wrq->value;
1863 break;
1864 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1865 break;
1866 case IW_AUTH_ROAMING_CONTROL:
1867 ret = -EOPNOTSUPP;
1868 break;
1869 case IW_AUTH_PRIVACY_INVOKED:
1870 pDevice->bEncryptionEnable = !!wrq->value;
1871 if(pDevice->bEncryptionEnable == FALSE){
1872 wpa_version = 0;
1873 pairwise = 0;
1874 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1875 pMgmt->bShareKeyAlgorithm = FALSE;
1876 pMgmt->eAuthenMode = FALSE;
1877 //pDevice->bWPADevEnable = FALSE;
1880 break;
1881 default:
1882 ret = -EOPNOTSUPP;
1883 break;
1886 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_version = %d\n",wpa_version);
1887 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pairwise = %d\n",pairwise);
1888 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->eEncryptionStatus = %d\n",pDevice->eEncryptionStatus);
1889 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->eAuthenMode = %d\n",pMgmt->eAuthenMode);
1890 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->bShareKeyAlgorithm = %s\n",pMgmt->bShareKeyAlgorithm?"TRUE":"FALSE");
1891 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->bEncryptionEnable = %s\n",pDevice->bEncryptionEnable?"TRUE":"FALSE");
1892 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->bWPADevEnable = %s\n",pDevice->bWPADevEnable?"TRUE":"FALSE");
1894 return ret;
1898 int iwctl_giwauth(struct net_device *dev,
1899 struct iw_request_info *info,
1900 struct iw_param *wrq,
1901 char *extra)
1903 return -EOPNOTSUPP;
1908 int iwctl_siwgenie(struct net_device *dev,
1909 struct iw_request_info *info,
1910 struct iw_point *wrq,
1911 char *extra)
1913 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1914 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1915 int ret=0;
1917 if(wrq->length){
1918 if ((wrq->length < 2) || (extra[1]+2 != wrq->length)) {
1919 ret = -EINVAL;
1920 goto out;
1922 if(wrq->length > MAX_WPA_IE_LEN){
1923 ret = -ENOMEM;
1924 goto out;
1926 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
1927 if(copy_from_user(pMgmt->abyWPAIE, extra, wrq->length)){
1928 ret = -EFAULT;
1929 goto out;
1931 pMgmt->wWPAIELen = wrq->length;
1932 }else {
1933 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
1934 pMgmt->wWPAIELen = 0;
1937 out://not completely ...not necessary in wpa_supplicant 0.5.8
1938 return 0;
1941 int iwctl_giwgenie(struct net_device *dev,
1942 struct iw_request_info *info,
1943 struct iw_point *wrq,
1944 char *extra)
1946 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1947 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1948 int ret=0;
1949 int space = wrq->length;
1951 wrq->length = 0;
1952 if(pMgmt->wWPAIELen > 0){
1953 wrq->length = pMgmt->wWPAIELen;
1954 if(pMgmt->wWPAIELen <= space){
1955 if(copy_to_user(extra, pMgmt->abyWPAIE, pMgmt->wWPAIELen)){
1956 ret = -EFAULT;
1958 }else
1959 ret = -E2BIG;
1962 return ret;
1966 int iwctl_siwencodeext(struct net_device *dev,
1967 struct iw_request_info *info,
1968 struct iw_point *wrq,
1969 char *extra)
1971 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1972 struct iw_encode_ext *ext = (struct iw_encode_ext*)extra;
1973 struct viawget_wpa_param *param=NULL;
1974 //original member
1975 wpa_alg alg_name;
1976 u8 addr[6];
1977 int key_idx, set_tx;
1978 u8 seq[IW_ENCODE_SEQ_MAX_SIZE];
1979 u8 key[64];
1980 size_t seq_len,key_len=0;
1982 // int ii;
1983 u8 *buf;
1984 size_t blen;
1985 u8 key_array[64];
1986 int ret=0;
1988 printk("SIOCSIWENCODEEXT...... \n");
1990 blen = sizeof(*param);
1991 buf = kmalloc((int)blen, (int)GFP_KERNEL);
1992 if (buf == NULL)
1993 return -ENOMEM;
1994 memset(buf, 0, blen);
1995 param = (struct viawget_wpa_param *) buf;
1997 //recover alg_name
1998 switch (ext->alg) {
1999 case IW_ENCODE_ALG_NONE:
2000 alg_name = WPA_ALG_NONE;
2001 break;
2002 case IW_ENCODE_ALG_WEP:
2003 alg_name = WPA_ALG_WEP;
2004 break;
2005 case IW_ENCODE_ALG_TKIP:
2006 alg_name = WPA_ALG_TKIP;
2007 break;
2008 case IW_ENCODE_ALG_CCMP:
2009 alg_name = WPA_ALG_CCMP;
2010 break;
2011 default:
2012 printk("Unknown alg = %d\n",ext->alg);
2013 ret= -ENOMEM;
2014 goto error;
2016 //recover addr
2017 memcpy(addr, ext->addr.sa_data, ETH_ALEN);
2018 //recover key_idx
2019 key_idx = (wrq->flags&IW_ENCODE_INDEX) - 1;
2020 //recover set_tx
2021 if(ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2022 set_tx = 1;
2023 //recover seq,seq_len
2024 if(ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
2025 seq_len=IW_ENCODE_SEQ_MAX_SIZE;
2026 memcpy(seq, ext->rx_seq, seq_len);
2028 //recover key,key_len
2029 if(ext->key_len) {
2030 key_len=ext->key_len;
2031 memcpy(key, &ext->key[0], key_len);
2034 memset(key_array, 0, 64);
2035 if ( key_len > 0) {
2036 memcpy(key_array, key, key_len);
2037 if (key_len == 32) {
2038 // notice ! the oder
2039 memcpy(&key_array[16], &key[24], 8);
2040 memcpy(&key_array[24], &key[16], 8);
2044 /**************Translate iw_encode_ext to viawget_wpa_param****************/
2045 memcpy(param->addr, addr, ETH_ALEN);
2046 param->u.wpa_key.alg_name = (int)alg_name;
2047 param->u.wpa_key.set_tx = set_tx;
2048 param->u.wpa_key.key_index = key_idx;
2049 param->u.wpa_key.key_len = key_len;
2050 param->u.wpa_key.key = (u8 *)key_array;
2051 param->u.wpa_key.seq = (u8 *)seq;
2052 param->u.wpa_key.seq_len = seq_len;
2054 #if 0
2055 int ii;
2056 printk("param->u.wpa_key.alg_name =%d\n",param->u.wpa_key.alg_name);
2057 printk("param->addr=%02x:%02x:%02x:%02x:%02x:%02x\n",
2058 param->addr[0],param->addr[1],param->addr[2],
2059 param->addr[3],param->addr[4],param->addr[5]);
2060 printk("param->u.wpa_key.set_tx =%d\n",param->u.wpa_key.set_tx);
2061 printk("param->u.wpa_key.key_index =%d\n",param->u.wpa_key.key_index);
2062 printk("param->u.wpa_key.key_len =%d\n",param->u.wpa_key.key_len);
2063 printk("param->u.wpa_key.key =");
2064 for(ii=0;ii<param->u.wpa_key.key_len;ii++)
2065 printk("%02x:",param->u.wpa_key.key[ii]);
2066 printk("\n");
2067 printk("param->u.wpa_key.seq_len =%d\n",param->u.wpa_key.seq_len);
2068 printk("param->u.wpa_key.seq =");
2069 for(ii=0;ii<param->u.wpa_key.seq_len;ii++)
2070 printk("%02x:",param->u.wpa_key.seq[ii]);
2071 printk("\n");
2073 printk("...........\n");
2074 #endif
2075 //****set if current action is Network Manager count??
2076 //****this method is so foolish,but there is no other way???
2077 if(param->u.wpa_key.alg_name == WPA_ALG_NONE) {
2078 if(param->u.wpa_key.key_index ==0) {
2079 pDevice->bwextcount++;
2081 if((pDevice->bwextcount == 1)&&(param->u.wpa_key.key_index ==1)) {
2082 pDevice->bwextcount++;
2084 if((pDevice->bwextcount ==2)&&(param->u.wpa_key.key_index ==2)) {
2085 pDevice->bwextcount++;
2087 if((pDevice->bwextcount ==3)&&(param->u.wpa_key.key_index ==3)) {
2088 pDevice->bwextcount++;
2091 if( pDevice->bwextcount == 4) {
2092 printk("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n");
2093 pDevice->bwextcount=0;
2094 pDevice->bWPASuppWextEnabled = TRUE;
2096 //******
2098 spin_lock_irq(&pDevice->lock);
2099 ret = wpa_set_keys(pDevice, param, TRUE);
2100 spin_unlock_irq(&pDevice->lock);
2102 error:
2103 kfree(param);
2104 return ret;
2109 int iwctl_giwencodeext(struct net_device *dev,
2110 struct iw_request_info *info,
2111 struct iw_point *wrq,
2112 char *extra)
2114 return -EOPNOTSUPP;;
2117 int iwctl_siwmlme(struct net_device *dev,
2118 struct iw_request_info * info,
2119 struct iw_point *wrq,
2120 char *extra)
2122 PSDevice pDevice = (PSDevice)netdev_priv(dev);
2123 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
2124 struct iw_mlme *mlme = (struct iw_mlme *)extra;
2125 //u16 reason = cpu_to_le16(mlme->reason_code);
2126 int ret = 0;
2128 if(memcmp(pMgmt->abyCurrBSSID, mlme->addr.sa_data, ETH_ALEN)){
2129 ret = -EINVAL;
2130 return ret;
2132 switch(mlme->cmd){
2133 case IW_MLME_DEAUTH:
2134 //this command seems to be not complete,please test it --einsnliu
2135 //bScheduleCommand((HANDLE) pDevice, WLAN_CMD_DEAUTH, (PBYTE)&reason);
2136 break;
2137 case IW_MLME_DISASSOC:
2138 if(pDevice->bLinkPass == TRUE){
2139 printk("iwctl_siwmlme--->send DISASSOCIATE\n");
2140 //clear related flags
2141 memset(pMgmt->abyDesireBSSID, 0xFF,6);
2142 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
2143 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
2145 break;
2146 default:
2147 ret = -EOPNOTSUPP;
2150 return ret;
2154 #endif
2157 /*------------------------------------------------------------------*/
2159 * Structures to export the Wireless Handlers
2164 static const iw_handler iwctl_handler[] =
2166 (iw_handler) iwctl_commit, // SIOCSIWCOMMIT
2167 (iw_handler) iwctl_giwname, // SIOCGIWNAME
2168 (iw_handler) NULL, // SIOCSIWNWID
2169 (iw_handler) NULL, // SIOCGIWNWID
2170 (iw_handler) iwctl_siwfreq, // SIOCSIWFREQ
2171 (iw_handler) iwctl_giwfreq, // SIOCGIWFREQ
2172 (iw_handler) iwctl_siwmode, // SIOCSIWMODE
2173 (iw_handler) iwctl_giwmode, // SIOCGIWMODE
2174 (iw_handler) NULL, // SIOCSIWSENS
2175 (iw_handler) iwctl_giwsens, // SIOCGIWSENS
2176 (iw_handler) NULL, // SIOCSIWRANGE
2177 (iw_handler) iwctl_giwrange, // SIOCGIWRANGE
2178 (iw_handler) NULL, // SIOCSIWPRIV
2179 (iw_handler) NULL, // SIOCGIWPRIV
2180 (iw_handler) NULL, // SIOCSIWSTATS
2181 (iw_handler) NULL, // SIOCGIWSTATS
2182 (iw_handler) NULL, // SIOCSIWSPY
2183 (iw_handler) NULL, // SIOCGIWSPY
2184 (iw_handler) NULL, // -- hole --
2185 (iw_handler) NULL, // -- hole --
2186 (iw_handler) iwctl_siwap, // SIOCSIWAP
2187 (iw_handler) iwctl_giwap, // SIOCGIWAP
2188 (iw_handler) NULL, // -- hole -- 0x16
2189 (iw_handler) iwctl_giwaplist, // SIOCGIWAPLIST
2190 (iw_handler) iwctl_siwscan, // SIOCSIWSCAN
2191 (iw_handler) iwctl_giwscan, // SIOCGIWSCAN
2192 (iw_handler) iwctl_siwessid, // SIOCSIWESSID
2193 (iw_handler) iwctl_giwessid, // SIOCGIWESSID
2194 (iw_handler) NULL, // SIOCSIWNICKN
2195 (iw_handler) NULL, // SIOCGIWNICKN
2196 (iw_handler) NULL, // -- hole --
2197 (iw_handler) NULL, // -- hole --
2198 (iw_handler) iwctl_siwrate, // SIOCSIWRATE 0x20
2199 (iw_handler) iwctl_giwrate, // SIOCGIWRATE
2200 (iw_handler) iwctl_siwrts, // SIOCSIWRTS
2201 (iw_handler) iwctl_giwrts, // SIOCGIWRTS
2202 (iw_handler) iwctl_siwfrag, // SIOCSIWFRAG
2203 (iw_handler) iwctl_giwfrag, // SIOCGIWFRAG
2204 (iw_handler) NULL, // SIOCSIWTXPOW
2205 (iw_handler) NULL, // SIOCGIWTXPOW
2206 (iw_handler) iwctl_siwretry, // SIOCSIWRETRY
2207 (iw_handler) iwctl_giwretry, // SIOCGIWRETRY
2208 (iw_handler) iwctl_siwencode, // SIOCSIWENCODE
2209 (iw_handler) iwctl_giwencode, // SIOCGIWENCODE
2210 (iw_handler) iwctl_siwpower, // SIOCSIWPOWER
2211 (iw_handler) iwctl_giwpower, // SIOCGIWPOWER
2212 (iw_handler) NULL, // -- hole --
2213 (iw_handler) NULL, // -- hole --
2214 (iw_handler) iwctl_siwgenie, // SIOCSIWGENIE
2215 (iw_handler) iwctl_giwgenie, // SIOCGIWGENIE
2216 (iw_handler) iwctl_siwauth, // SIOCSIWAUTH
2217 (iw_handler) iwctl_giwauth, // SIOCGIWAUTH
2218 (iw_handler) iwctl_siwencodeext, // SIOCSIWENCODEEXT
2219 (iw_handler) iwctl_giwencodeext, // SIOCGIWENCODEEXT
2220 (iw_handler) NULL, // SIOCSIWPMKSA
2221 (iw_handler) NULL, // -- hole --
2226 static const iw_handler iwctl_handler[] =
2228 (iw_handler) iwctl_commit, // SIOCSIWCOMMIT
2229 (iw_handler) NULL, // SIOCGIWNAME
2230 (iw_handler) NULL, // SIOCSIWNWID
2231 (iw_handler) NULL, // SIOCGIWNWID
2232 (iw_handler) NULL, // SIOCSIWFREQ
2233 (iw_handler) NULL, // SIOCGIWFREQ
2234 (iw_handler) NULL, // SIOCSIWMODE
2235 (iw_handler) NULL, // SIOCGIWMODE
2236 (iw_handler) NULL, // SIOCSIWSENS
2237 (iw_handler) NULL, // SIOCGIWSENS
2238 (iw_handler) NULL, // SIOCSIWRANGE
2239 (iw_handler) iwctl_giwrange, // SIOCGIWRANGE
2240 (iw_handler) NULL, // SIOCSIWPRIV
2241 (iw_handler) NULL, // SIOCGIWPRIV
2242 (iw_handler) NULL, // SIOCSIWSTATS
2243 (iw_handler) NULL, // SIOCGIWSTATS
2244 (iw_handler) NULL, // SIOCSIWSPY
2245 (iw_handler) NULL, // SIOCGIWSPY
2246 (iw_handler) NULL, // -- hole --
2247 (iw_handler) NULL, // -- hole --
2248 (iw_handler) NULL, // SIOCSIWAP
2249 (iw_handler) NULL, // SIOCGIWAP
2250 (iw_handler) NULL, // -- hole -- 0x16
2251 (iw_handler) NULL, // SIOCGIWAPLIST
2252 (iw_handler) iwctl_siwscan, // SIOCSIWSCAN
2253 (iw_handler) iwctl_giwscan, // SIOCGIWSCAN
2254 (iw_handler) NULL, // SIOCSIWESSID
2255 (iw_handler) NULL, // SIOCGIWESSID
2256 (iw_handler) NULL, // SIOCSIWNICKN
2257 (iw_handler) NULL, // SIOCGIWNICKN
2258 (iw_handler) NULL, // -- hole --
2259 (iw_handler) NULL, // -- hole --
2260 (iw_handler) NULL, // SIOCSIWRATE 0x20
2261 (iw_handler) NULL, // SIOCGIWRATE
2262 (iw_handler) NULL, // SIOCSIWRTS
2263 (iw_handler) NULL, // SIOCGIWRTS
2264 (iw_handler) NULL, // SIOCSIWFRAG
2265 (iw_handler) NULL, // SIOCGIWFRAG
2266 (iw_handler) NULL, // SIOCSIWTXPOW
2267 (iw_handler) NULL, // SIOCGIWTXPOW
2268 (iw_handler) NULL, // SIOCSIWRETRY
2269 (iw_handler) NULL, // SIOCGIWRETRY
2270 (iw_handler) NULL, // SIOCSIWENCODE
2271 (iw_handler) NULL, // SIOCGIWENCODE
2272 (iw_handler) NULL, // SIOCSIWPOWER
2273 (iw_handler) NULL, // SIOCGIWPOWER
2275 //2008-0409-07, <Add> by Einsn Liu
2276 (iw_handler) NULL, // -- hole --
2277 (iw_handler) NULL, // -- hole --
2278 (iw_handler) NULL, // SIOCSIWGENIE
2279 (iw_handler) NULL, // SIOCGIWGENIE
2280 (iw_handler) NULL, // SIOCSIWAUTH
2281 (iw_handler) NULL, // SIOCGIWAUTH
2282 (iw_handler) NULL, // SIOCSIWENCODEEXT
2283 (iw_handler) NULL, // SIOCGIWENCODEEXT
2284 (iw_handler) NULL, // SIOCSIWPMKSA
2285 (iw_handler) NULL, // -- hole --
2289 static const iw_handler iwctl_private_handler[] =
2291 NULL, // SIOCIWFIRSTPRIV
2295 struct iw_priv_args iwctl_private_args[] = {
2296 { IOCTL_CMD_SET,
2297 IW_PRIV_TYPE_CHAR | 1024, 0,
2298 "set"},
2303 const struct iw_handler_def iwctl_handler_def =
2305 .get_wireless_stats = &iwctl_get_wireless_stats,
2306 .num_standard = sizeof(iwctl_handler)/sizeof(iw_handler),
2307 // .num_private = sizeof(iwctl_private_handler)/sizeof(iw_handler),
2308 // .num_private_args = sizeof(iwctl_private_args)/sizeof(struct iw_priv_args),
2309 .num_private = 0,
2310 .num_private_args = 0,
2311 .standard = (iw_handler *) iwctl_handler,
2312 // .private = (iw_handler *) iwctl_private_handler,
2313 // .private_args = (struct iw_priv_args *)iwctl_private_args,
2314 .private = NULL,
2315 .private_args = NULL,
2320 #endif // WIRELESS_EXT