Staging: vt665x: Clean up include files, Part 2
[linux-2.6/linux-2.6-openrd.git] / drivers / staging / vt6655 / iwctl.c
blob4b1ce8691764863d1dfea8a1fbdaacedad558467
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 "umem.h"
40 #include "power.h"
41 #include "rf.h"
43 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
44 #include "iowpa.h"
45 #include "wpactl.h"
46 #endif
48 #include <net/iw_handler.h>
49 extern WORD TxRate_iwconfig;//2008-5-8 <add> by chester
51 /*--------------------- Static Definitions -------------------------*/
53 //2008-0409-07, <Add> by Einsn Liu
54 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
55 #define SUPPORTED_WIRELESS_EXT 18
56 #else
57 #define SUPPORTED_WIRELESS_EXT 17
58 #endif
60 static const long frequency_list[] = {
61 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
62 4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
63 5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210, 5220, 5230, 5240,
64 5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680,
65 5700, 5745, 5765, 5785, 5805, 5825
69 /*--------------------- Static Classes ----------------------------*/
72 //static int msglevel =MSG_LEVEL_DEBUG;
73 static int msglevel =MSG_LEVEL_INFO;
76 /*--------------------- Static Variables --------------------------*/
77 /*--------------------- Static Functions --------------------------*/
79 /*--------------------- Export Variables --------------------------*/
81 struct iw_statistics *iwctl_get_wireless_stats(struct net_device *dev)
83 PSDevice pDevice = netdev_priv(dev);
84 long ldBm;
86 pDevice->wstats.status = pDevice->eOPMode;
87 #ifdef Calcu_LinkQual
88 #if 0
89 if(pDevice->byBBType == BB_TYPE_11B) {
90 if(pDevice->byCurrSQ > 120)
91 pDevice->scStatistic.LinkQuality = 100;
92 else
93 pDevice->scStatistic.LinkQuality = pDevice->byCurrSQ*100/120;
95 else if(pDevice->byBBType == BB_TYPE_11G) {
96 if(pDevice->byCurrSQ < 20)
97 pDevice->scStatistic.LinkQuality = 100;
98 else if(pDevice->byCurrSQ >96)
99 pDevice->scStatistic.LinkQuality = 0;
100 else
101 pDevice->scStatistic.LinkQuality = (96-pDevice->byCurrSQ)*100/76;
103 if(pDevice->bLinkPass !=TRUE)
104 pDevice->scStatistic.LinkQuality = 0;
105 #endif
106 if(pDevice->scStatistic.LinkQuality > 100)
107 pDevice->scStatistic.LinkQuality = 100;
108 pDevice->wstats.qual.qual =(BYTE) pDevice->scStatistic.LinkQuality;
109 #else
110 pDevice->wstats.qual.qual = pDevice->byCurrSQ;
111 #endif
112 RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm);
113 pDevice->wstats.qual.level = ldBm;
114 //pDevice->wstats.qual.level = 0x100 - pDevice->uCurrRSSI;
115 pDevice->wstats.qual.noise = 0;
116 pDevice->wstats.qual.updated = 1;
117 pDevice->wstats.discard.nwid = 0;
118 pDevice->wstats.discard.code = 0;
119 pDevice->wstats.discard.fragment = 0;
120 pDevice->wstats.discard.retries = (U32)pDevice->scStatistic.dwTsrErr;
121 pDevice->wstats.discard.misc = 0;
122 pDevice->wstats.miss.beacon = 0;
124 return &pDevice->wstats;
129 /*------------------------------------------------------------------*/
132 static int iwctl_commit(struct net_device *dev,
133 struct iw_request_info *info,
134 void *wrq,
135 char *extra)
137 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWCOMMIT \n");
139 return 0;
143 * Wireless Handler : get protocol name
146 int iwctl_giwname(struct net_device *dev,
147 struct iw_request_info *info,
148 char *wrq,
149 char *extra)
151 strcpy(wrq, "802.11-a/b/g");
152 return 0;
155 int iwctl_giwnwid(struct net_device *dev,
156 struct iw_request_info *info,
157 struct iw_param *wrq,
158 char *extra)
160 //wrq->value = 0x100;
161 //wrq->disabled = 0;
162 //wrq->fixed = 1;
163 //return 0;
164 return -EOPNOTSUPP;
168 * Wireless Handler : set scan
171 int iwctl_siwscan(struct net_device *dev,
172 struct iw_request_info *info,
173 struct iw_point *wrq,
174 char *extra)
176 PSDevice pDevice = (PSDevice)netdev_priv(dev);
177 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
178 struct iw_scan_req *req = (struct iw_scan_req *)extra;
179 BYTE abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
180 PWLAN_IE_SSID pItemSSID=NULL;
181 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSCAN \n");
184 if(pDevice->byReAssocCount > 0) { //reject scan when re-associating!
185 //send scan event to wpa_Supplicant
186 union iwreq_data wrqu;
187 PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
188 memset(&wrqu, 0, sizeof(wrqu));
189 wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
190 return 0;
193 spin_lock_irq(&pDevice->lock);
194 BSSvClearBSSList((HANDLE)pDevice, pDevice->bLinkPass);
196 //mike add: active scan OR passive scan OR desire_ssid scan
197 if(wrq->length == sizeof(struct iw_scan_req)) {
198 if (wrq->flags & IW_SCAN_THIS_ESSID) { //desire_ssid scan
199 memset(abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
200 pItemSSID = (PWLAN_IE_SSID)abyScanSSID;
201 pItemSSID->byElementID = WLAN_EID_SSID;
202 memcpy(pItemSSID->abySSID, req->essid, (int)req->essid_len);
203 if (pItemSSID->abySSID[req->essid_len - 1] == '\0') {
204 if(req->essid_len>0)
205 pItemSSID->len = req->essid_len - 1;
207 else
208 pItemSSID->len = req->essid_len;
209 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
210 PRINT_K("SIOCSIWSCAN:[desired_ssid=%s,len=%d]\n",((PWLAN_IE_SSID)abyScanSSID)->abySSID,
211 ((PWLAN_IE_SSID)abyScanSSID)->len);
212 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID);
213 spin_unlock_irq(&pDevice->lock);
215 return 0;
217 else if(req->scan_type == IW_SCAN_TYPE_PASSIVE) { //passive scan
218 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
221 else { //active scan
222 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
225 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
226 //printk("SIOCSIWSCAN:WLAN_CMD_BSSID_SCAN\n");
227 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
228 spin_unlock_irq(&pDevice->lock);
230 return 0;
235 * Wireless Handler : get scan results
238 int iwctl_giwscan(struct net_device *dev,
239 struct iw_request_info *info,
240 struct iw_point *wrq,
241 char *extra)
243 int ii, jj, kk;
244 PSDevice pDevice = (PSDevice)netdev_priv(dev);
245 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
246 PKnownBSS pBSS;
247 PWLAN_IE_SSID pItemSSID;
248 PWLAN_IE_SUPP_RATES pSuppRates, pExtSuppRates;
249 char *current_ev = extra;
250 char *end_buf = extra + IW_SCAN_MAX_DATA;
251 char *current_val = NULL;
252 struct iw_event iwe;
253 long ldBm;
254 char buf[MAX_WPA_IE_LEN * 2 + 30];
257 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSCAN \n");
259 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
260 // In scanning..
261 return -EAGAIN;
263 pBSS = &(pMgmt->sBSSList[0]);
264 for (ii = 0, jj = 0; jj < MAX_BSS_NUM ; jj++) {
265 if (current_ev >= end_buf)
266 break;
267 pBSS = &(pMgmt->sBSSList[jj]);
268 if (pBSS->bActive) {
269 //ADD mac address
270 memset(&iwe, 0, sizeof(iwe));
271 iwe.cmd = SIOCGIWAP;
272 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
273 memcpy(iwe.u.ap_addr.sa_data, pBSS->abyBSSID, WLAN_BSSID_LEN);
274 current_ev = iwe_stream_add_event(info,current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);
275 //ADD ssid
276 memset(&iwe, 0, sizeof(iwe));
277 iwe.cmd = SIOCGIWESSID;
278 pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
279 iwe.u.data.length = pItemSSID->len;
280 iwe.u.data.flags = 1;
281 current_ev = iwe_stream_add_point(info,current_ev,end_buf, &iwe, pItemSSID->abySSID);
282 //ADD mode
283 memset(&iwe, 0, sizeof(iwe));
284 iwe.cmd = SIOCGIWMODE;
285 if (WLAN_GET_CAP_INFO_ESS(pBSS->wCapInfo)) {
286 iwe.u.mode = IW_MODE_INFRA;
288 else {
289 iwe.u.mode = IW_MODE_ADHOC;
291 iwe.len = IW_EV_UINT_LEN;
292 current_ev = iwe_stream_add_event(info,current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
293 //ADD frequency
294 pSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abySuppRates;
295 pExtSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abyExtSuppRates;
296 memset(&iwe, 0, sizeof(iwe));
297 iwe.cmd = SIOCGIWFREQ;
298 iwe.u.freq.m = pBSS->uChannel;
299 iwe.u.freq.e = 0;
300 iwe.u.freq.i = 0;
301 current_ev = iwe_stream_add_event(info,current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
302 //2008-0409-04, <Add> by Einsn Liu
304 int f = (int)pBSS->uChannel - 1;
305 if(f < 0)f = 0;
306 iwe.u.freq.m = frequency_list[f] * 100000;
307 iwe.u.freq.e = 1;
309 current_ev = iwe_stream_add_event(info,current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
310 //ADD quality
311 memset(&iwe, 0, sizeof(iwe));
312 iwe.cmd = IWEVQUAL;
313 RFvRSSITodBm(pDevice, (BYTE)(pBSS->uRSSI), &ldBm);
314 iwe.u.qual.level = ldBm;
315 iwe.u.qual.noise = 0;
316 //2008-0409-01, <Add> by Einsn Liu
317 if(-ldBm<50){
318 iwe.u.qual.qual = 100;
319 }else if(-ldBm > 90) {
320 iwe.u.qual.qual = 0;
321 }else {
322 iwe.u.qual.qual=(40-(-ldBm-50))*100/40;
324 iwe.u.qual.updated=7;
326 // iwe.u.qual.qual = 0;
327 current_ev = iwe_stream_add_event(info,current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
329 memset(&iwe, 0, sizeof(iwe));
330 iwe.cmd = SIOCGIWENCODE;
331 iwe.u.data.length = 0;
332 if (WLAN_GET_CAP_INFO_PRIVACY(pBSS->wCapInfo)) {
333 iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
334 }else {
335 iwe.u.data.flags = IW_ENCODE_DISABLED;
337 current_ev = iwe_stream_add_point(info,current_ev,end_buf, &iwe, pItemSSID->abySSID);
339 memset(&iwe, 0, sizeof(iwe));
340 iwe.cmd = SIOCGIWRATE;
341 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
342 current_val = current_ev + IW_EV_LCP_LEN;
344 for (kk = 0 ; kk < 12 ; kk++) {
345 if (pSuppRates->abyRates[kk] == 0)
346 break;
347 // Bit rate given in 500 kb/s units (+ 0x80)
348 iwe.u.bitrate.value = ((pSuppRates->abyRates[kk] & 0x7f) * 500000);
349 current_val = iwe_stream_add_value(info,current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
351 for (kk = 0 ; kk < 8 ; kk++) {
352 if (pExtSuppRates->abyRates[kk] == 0)
353 break;
354 // Bit rate given in 500 kb/s units (+ 0x80)
355 iwe.u.bitrate.value = ((pExtSuppRates->abyRates[kk] & 0x7f) * 500000);
356 current_val = iwe_stream_add_value(info,current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
359 if((current_val - current_ev) > IW_EV_LCP_LEN)
360 current_ev = current_val;
362 memset(&iwe, 0, sizeof(iwe));
363 iwe.cmd = IWEVCUSTOM;
364 sprintf(buf, "bcn_int=%d", pBSS->wBeaconInterval);
365 iwe.u.data.length = strlen(buf);
366 current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, buf);
368 if ((pBSS->wWPALen > 0) && (pBSS->wWPALen <= MAX_WPA_IE_LEN)) {
369 memset(&iwe, 0, sizeof(iwe));
370 iwe.cmd = IWEVGENIE;
371 iwe.u.data.length = pBSS->wWPALen;
372 current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, pBSS->byWPAIE);
375 if ((pBSS->wRSNLen > 0) && (pBSS->wRSNLen <= MAX_WPA_IE_LEN)) {
376 memset(&iwe, 0, sizeof(iwe));
377 iwe.cmd = IWEVGENIE;
378 iwe.u.data.length = pBSS->wRSNLen;
379 current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, pBSS->byRSNIE);
383 }// for
385 wrq->length = current_ev - extra;
386 return 0;
392 * Wireless Handler : set frequence or channel
395 int iwctl_siwfreq(struct net_device *dev,
396 struct iw_request_info *info,
397 struct iw_freq *wrq,
398 char *extra)
400 PSDevice pDevice = (PSDevice)netdev_priv(dev);
401 int rc = 0;
403 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFREQ \n");
405 // If setting by frequency, convert to a channel
406 if((wrq->e == 1) &&
407 (wrq->m >= (int) 2.412e8) &&
408 (wrq->m <= (int) 2.487e8)) {
409 int f = wrq->m / 100000;
410 int c = 0;
411 while((c < 14) && (f != frequency_list[c]))
412 c++;
413 wrq->e = 0;
414 wrq->m = c + 1;
416 // Setting by channel number
417 if((wrq->m > 14) || (wrq->e > 0))
418 rc = -EOPNOTSUPP;
419 else {
420 int channel = wrq->m;
421 if((channel < 1) || (channel > 14)) {
422 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: New channel value of %d is invalid!\n", dev->name, wrq->m);
423 rc = -EINVAL;
424 } else {
425 // Yes ! We can set it !!!
426 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Set to channel = %d\n", channel);
427 pDevice->uChannel = channel;
428 //2007-0207-04,<Add> by EinsnLiu
429 //Make change effect at once
430 pDevice->bCommit = TRUE;
434 return rc;
438 * Wireless Handler : get frequence or channel
441 int iwctl_giwfreq(struct net_device *dev,
442 struct iw_request_info *info,
443 struct iw_freq *wrq,
444 char *extra)
446 PSDevice pDevice = (PSDevice)netdev_priv(dev);
447 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
449 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFREQ \n");
451 #ifdef WEXT_USECHANNELS
452 wrq->m = (int)pMgmt->uCurrChannel;
453 wrq->e = 0;
454 #else
456 int f = (int)pMgmt->uCurrChannel - 1;
457 if(f < 0)
458 f = 0;
459 wrq->m = frequency_list[f] * 100000;
460 wrq->e = 1;
462 #endif
464 return 0;
468 * Wireless Handler : set operation mode
471 int iwctl_siwmode(struct net_device *dev,
472 struct iw_request_info *info,
473 __u32 *wmode,
474 char *extra)
476 PSDevice pDevice = (PSDevice)netdev_priv(dev);
477 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
478 int rc = 0;
480 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMODE \n");
482 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP && pDevice->bEnableHostapd) {
483 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Can't set operation mode, hostapd is running \n");
484 return rc;
487 switch(*wmode) {
489 case IW_MODE_ADHOC:
490 if (pMgmt->eConfigMode != WMAC_CONFIG_IBSS_STA) {
491 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
492 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
493 pDevice->bCommit = TRUE;
496 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to ad-hoc \n");
497 break;
498 case IW_MODE_AUTO:
499 case IW_MODE_INFRA:
500 if (pMgmt->eConfigMode != WMAC_CONFIG_ESS_STA) {
501 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
502 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
503 pDevice->bCommit = TRUE;
506 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to infrastructure \n");
507 break;
508 case IW_MODE_MASTER:
510 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
511 rc = -EOPNOTSUPP;
512 break;
514 if (pMgmt->eConfigMode != WMAC_CONFIG_AP) {
515 pMgmt->eConfigMode = WMAC_CONFIG_AP;
516 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
517 pDevice->bCommit = TRUE;
520 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to Access Point \n");
521 break;
523 case IW_MODE_REPEAT:
524 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
525 rc = -EOPNOTSUPP;
526 break;
527 default:
528 rc = -EINVAL;
531 return rc;
535 * Wireless Handler : get operation mode
538 int iwctl_giwmode(struct net_device *dev,
539 struct iw_request_info *info,
540 __u32 *wmode,
541 char *extra)
543 PSDevice pDevice = (PSDevice)netdev_priv(dev);
544 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
547 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWMODE \n");
548 // If not managed, assume it's ad-hoc
549 switch (pMgmt->eConfigMode) {
550 case WMAC_CONFIG_ESS_STA:
551 *wmode = IW_MODE_INFRA;
552 break;
553 case WMAC_CONFIG_IBSS_STA:
554 *wmode = IW_MODE_ADHOC;
555 break;
556 case WMAC_CONFIG_AUTO:
557 *wmode = IW_MODE_INFRA;
558 break;
559 case WMAC_CONFIG_AP:
560 *wmode = IW_MODE_MASTER;
561 break;
562 default:
563 *wmode = IW_MODE_ADHOC;
566 return 0;
571 * Wireless Handler : get capability range
574 int iwctl_giwrange(struct net_device *dev,
575 struct iw_request_info *info,
576 struct iw_point *wrq,
577 char *extra)
579 struct iw_range *range = (struct iw_range *) extra;
580 int i,k;
581 BYTE abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
584 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRANGE \n");
585 if (wrq->pointer) {
586 wrq->length = sizeof(struct iw_range);
587 memset(range, 0, sizeof(struct iw_range));
588 range->min_nwid = 0x0000;
589 range->max_nwid = 0x0000;
590 range->num_channels = 14;
591 // Should be based on cap_rid.country to give only
592 // what the current card support
593 k = 0;
594 for(i = 0; i < 14; i++) {
595 range->freq[k].i = i + 1; // List index
596 range->freq[k].m = frequency_list[i] * 100000;
597 range->freq[k++].e = 1; // Values in table in MHz -> * 10^5 * 10
599 range->num_frequency = k;
600 // Hum... Should put the right values there
601 #ifdef Calcu_LinkQual
602 range->max_qual.qual = 100;
603 #else
604 range->max_qual.qual = 255;
605 #endif
606 range->max_qual.level = 0;
607 range->max_qual.noise = 0;
608 range->sensitivity = 255;
610 for(i = 0 ; i < 13 ; i++) {
611 range->bitrate[i] = abySupportedRates[i] * 500000;
612 if(range->bitrate[i] == 0)
613 break;
615 range->num_bitrates = i;
617 // Set an indication of the max TCP throughput
618 // in bit/s that we can expect using this interface.
619 // May be use for QoS stuff... Jean II
620 if(i > 2)
621 range->throughput = 5 * 1000 * 1000;
622 else
623 range->throughput = 1.5 * 1000 * 1000;
625 range->min_rts = 0;
626 range->max_rts = 2312;
627 range->min_frag = 256;
628 range->max_frag = 2312;
631 // the encoding capabilities
632 range->num_encoding_sizes = 3;
633 // 64(40) bits WEP
634 range->encoding_size[0] = 5;
635 // 128(104) bits WEP
636 range->encoding_size[1] = 13;
637 // 256 bits for WPA-PSK
638 range->encoding_size[2] = 32;
639 // 4 keys are allowed
640 range->max_encoding_tokens = 4;
642 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
643 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
645 range->min_pmp = 0;
646 range->max_pmp = 1000000;// 1 secs
647 range->min_pmt = 0;
648 range->max_pmt = 1000000;// 1 secs
649 range->pmp_flags = IW_POWER_PERIOD;
650 range->pmt_flags = IW_POWER_TIMEOUT;
651 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
653 // Transmit Power - values are in mW
655 range->txpower[0] = 100;
656 range->num_txpower = 1;
657 range->txpower_capa = IW_TXPOW_MWATT;
658 range->we_version_source = SUPPORTED_WIRELESS_EXT;
659 range->we_version_compiled = WIRELESS_EXT;
660 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
661 range->retry_flags = IW_RETRY_LIMIT;
662 range->r_time_flags = IW_RETRY_LIFETIME;
663 range->min_retry = 1;
664 range->max_retry = 65535;
665 range->min_r_time = 1024;
666 range->max_r_time = 65535 * 1024;
667 // Experimental measurements - boundary 11/5.5 Mb/s
668 // Note : with or without the (local->rssi), results
669 // are somewhat different. - Jean II
670 range->avg_qual.qual = 6;
671 range->avg_qual.level = 176; // -80 dBm
672 range->avg_qual.noise = 0;
676 return 0;
681 * Wireless Handler : set ap mac address
684 int iwctl_siwap(struct net_device *dev,
685 struct iw_request_info *info,
686 struct sockaddr *wrq,
687 char *extra)
689 PSDevice pDevice = (PSDevice)netdev_priv(dev);
690 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
691 int rc = 0;
692 BYTE ZeroBSSID[WLAN_BSSID_LEN]={0x00,0x00,0x00,0x00,0x00,0x00};
694 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAP \n");
695 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
696 // In scanning..
697 printk("SIOCSIWAP(??)-->In scanning...\n");
698 // return -EAGAIN;
700 if (wrq->sa_family != ARPHRD_ETHER)
701 rc = -EINVAL;
702 else {
703 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
704 memcpy(pMgmt->abyDesireBSSID, wrq->sa_data, 6);
705 //2008-0409-05, <Add> by Einsn Liu
706 if((pDevice->bLinkPass == TRUE) &&
707 (memcmp(pMgmt->abyDesireBSSID, pMgmt->abyCurrBSSID, 6)== 0)){
708 return rc;
710 //mike :add
711 if ((IS_BROADCAST_ADDRESS(pMgmt->abyDesireBSSID)) ||
712 (memcmp(pMgmt->abyDesireBSSID, ZeroBSSID, 6) == 0)){
713 PRINT_K("SIOCSIWAP:invalid desired BSSID return!\n");
714 return rc;
716 //mike add: if desired AP is hidden ssid(there are two same BSSID in list),
717 // then ignore,because you don't known which one to be connect with??
719 UINT ii , uSameBssidNum=0;
720 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
721 if (pMgmt->sBSSList[ii].bActive &&
722 IS_ETH_ADDRESS_EQUAL(pMgmt->sBSSList[ii].abyBSSID,pMgmt->abyDesireBSSID)) {
723 uSameBssidNum++;
726 if(uSameBssidNum >= 2) { //hit: desired AP is in hidden ssid mode!!!
727 PRINT_K("SIOCSIWAP:ignore for desired AP in hidden mode\n");
728 return rc;
732 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
733 pDevice->bCommit = TRUE;
736 return rc;
740 * Wireless Handler : get ap mac address
743 int iwctl_giwap(struct net_device *dev,
744 struct iw_request_info *info,
745 struct sockaddr *wrq,
746 char *extra)
748 PSDevice pDevice = (PSDevice)netdev_priv(dev);
749 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
752 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAP \n");
754 memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
755 //2008-0410,<Modify> by Einsn Liu
756 if ((pDevice->bLinkPass == FALSE) && (pMgmt->eCurrMode != WMAC_MODE_ESS_AP))
757 memset(wrq->sa_data, 0, 6);
759 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
760 memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
763 wrq->sa_family = ARPHRD_ETHER;
765 return 0;
771 * Wireless Handler : get ap list
774 int iwctl_giwaplist(struct net_device *dev,
775 struct iw_request_info *info,
776 struct iw_point *wrq,
777 char *extra)
779 int ii,jj, rc = 0;
780 struct sockaddr sock[IW_MAX_AP];
781 struct iw_quality qual[IW_MAX_AP];
782 PSDevice pDevice = (PSDevice)netdev_priv(dev);
783 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
786 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAPLIST \n");
787 // Only super-user can see AP list
789 if (!capable(CAP_NET_ADMIN)) {
790 rc = -EPERM;
791 return rc;
794 if (wrq->pointer) {
796 PKnownBSS pBSS = &(pMgmt->sBSSList[0]);
798 for (ii = 0, jj= 0; ii < MAX_BSS_NUM; ii++) {
799 pBSS = &(pMgmt->sBSSList[ii]);
800 if (!pBSS->bActive)
801 continue;
802 if ( jj >= IW_MAX_AP)
803 break;
804 memcpy(sock[jj].sa_data, pBSS->abyBSSID, 6);
805 sock[jj].sa_family = ARPHRD_ETHER;
806 qual[jj].level = pBSS->uRSSI;
807 qual[jj].qual = qual[jj].noise = 0;
808 qual[jj].updated = 2;
809 jj++;
812 wrq->flags = 1; // Should be define'd
813 wrq->length = jj;
814 memcpy(extra, sock, sizeof(struct sockaddr)*jj);
815 memcpy(extra + sizeof(struct sockaddr)*jj, qual, sizeof(struct iw_quality)*jj);
818 return rc;
823 * Wireless Handler : set essid
826 int iwctl_siwessid(struct net_device *dev,
827 struct iw_request_info *info,
828 struct iw_point *wrq,
829 char *extra)
831 PSDevice pDevice = (PSDevice)netdev_priv(dev);
832 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
833 PWLAN_IE_SSID pItemSSID;
834 //2008-0409-05, <Add> by Einsn Liu
835 BYTE len;
838 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWESSID \n");
839 pDevice->fWPA_Authened = FALSE;
840 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
841 // In scanning..
842 printk("SIOCSIWESSID(??)-->In scanning...\n");
843 // return -EAGAIN;
845 // Check if we asked for `any'
846 if(wrq->flags == 0) {
847 // Just send an empty SSID list
848 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
849 memset(pMgmt->abyDesireBSSID, 0xFF,6);
850 PRINT_K("set essid to 'any' \n");
851 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
852 //Unknown desired AP,so here need not associate??
853 //if(pDevice->bWPASuppWextEnabled == TRUE) {
854 return 0;
855 // }
856 #endif
857 } else {
858 // Set the SSID
859 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
860 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
861 pItemSSID->byElementID = WLAN_EID_SSID;
863 memcpy(pItemSSID->abySSID, extra, wrq->length);
864 if (pItemSSID->abySSID[wrq->length - 1] == '\0') {
865 if(wrq->length>0)
866 pItemSSID->len = wrq->length - 1;
868 else
869 pItemSSID->len = wrq->length;
870 printk("set essid to %s \n",pItemSSID->abySSID);
871 //2008-0409-05, <Add> by Einsn Liu
872 len=(pItemSSID->len > ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len)?pItemSSID->len:((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len;
873 if((pDevice->bLinkPass == TRUE) &&
874 (memcmp(pItemSSID->abySSID,((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,len)==0))
875 return 0;
877 //mike:need clear desiredBSSID
878 if(pItemSSID->len==0) {
879 memset(pMgmt->abyDesireBSSID, 0xFF,6);
880 return 0;
883 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
884 //Wext wil order another command of siwap to link with desired AP,
885 //so here need not associate??
886 if(pDevice->bWPASuppWextEnabled == TRUE) {
887 /*******search if in hidden ssid mode ****/
889 PKnownBSS pCurr = NULL;
890 BYTE abyTmpDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
891 UINT ii , uSameBssidNum=0;
893 memset(abyTmpDesireSSID,0,sizeof(abyTmpDesireSSID));
894 memcpy(abyTmpDesireSSID,pMgmt->abyDesireSSID,sizeof(abyTmpDesireSSID));
895 pCurr = BSSpSearchBSSList(pDevice,
896 NULL,
897 abyTmpDesireSSID,
898 pMgmt->eConfigPHYMode
901 if (pCurr == NULL){
902 PRINT_K("SIOCSIWESSID:hidden ssid site survey before associate.......\n");
903 vResetCommandTimer((HANDLE) pDevice);
904 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
905 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
906 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
908 else { //mike:to find out if that desired SSID is a hidden-ssid AP ,
909 // by means of judging if there are two same BSSID exist in list ?
910 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
911 if (pMgmt->sBSSList[ii].bActive &&
912 IS_ETH_ADDRESS_EQUAL(pMgmt->sBSSList[ii].abyBSSID, pCurr->abyBSSID)) {
913 uSameBssidNum++;
916 if(uSameBssidNum >= 2) { //hit: desired AP is in hidden ssid mode!!!
917 printk("SIOCSIWESSID:hidden ssid directly associate.......\n");
918 vResetCommandTimer((HANDLE) pDevice);
919 pMgmt->eScanType = WMAC_SCAN_PASSIVE; //this scan type,you'll submit scan result!
920 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
921 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
925 return 0;
927 #endif
929 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set essid = %s \n", pItemSSID->abySSID);
932 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
933 pDevice->bCommit = TRUE;
937 return 0;
942 * Wireless Handler : get essid
945 int iwctl_giwessid(struct net_device *dev,
946 struct iw_request_info *info,
947 struct iw_point *wrq,
948 char *extra)
951 PSDevice pDevice = (PSDevice)netdev_priv(dev);
952 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
953 PWLAN_IE_SSID pItemSSID;
955 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWESSID \n");
957 // Note : if wrq->u.data.flags != 0, we should
958 // get the relevant SSID from the SSID list...
960 // Get the current SSID
961 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
962 //pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
963 memcpy(extra, pItemSSID->abySSID , pItemSSID->len);
964 extra[pItemSSID->len] = '\0';
965 wrq->length = pItemSSID->len + 1;
966 //2008-0409-03, <Add> by Einsn Liu
967 wrq->length = pItemSSID->len;
968 wrq->flags = 1; // active
971 return 0;
975 * Wireless Handler : set data rate
978 int iwctl_siwrate(struct net_device *dev,
979 struct iw_request_info *info,
980 struct iw_param *wrq,
981 char *extra)
983 PSDevice pDevice = (PSDevice)netdev_priv(dev);
984 int rc = 0;
985 u8 brate = 0;
986 int i;
987 BYTE abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
990 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRATE \n");
991 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
992 rc = -EINVAL;
993 return rc;
996 // First : get a valid bit rate value
998 // Which type of value
999 if((wrq->value < 13) &&
1000 (wrq->value >= 0)) {
1001 // Setting by rate index
1002 // Find value in the magic rate table
1003 brate = wrq->value;
1004 } else {
1005 // Setting by frequency value
1006 u8 normvalue = (u8) (wrq->value/500000);
1008 // Check if rate is valid
1009 for(i = 0 ; i < 13 ; i++) {
1010 if(normvalue == abySupportedRates[i]) {
1011 brate = i;
1012 break;
1016 // -1 designed the max rate (mostly auto mode)
1017 if(wrq->value == -1) {
1018 // Get the highest available rate
1019 for(i = 0 ; i < 13 ; i++) {
1020 if(abySupportedRates[i] == 0)
1021 break;
1023 if(i != 0)
1024 brate = i - 1;
1027 // Check that it is valid
1028 // brate is index of abySupportedRates[]
1029 if(brate > 13 ) {
1030 rc = -EINVAL;
1031 return rc;
1034 // Now, check if we want a fixed or auto value
1035 if(wrq->fixed != 0) {
1036 // Fixed mode
1037 // One rate, fixed
1038 printk("Rate Fix\n");
1039 pDevice->bFixRate = TRUE;
1040 if ((pDevice->byBBType == BB_TYPE_11B)&& (brate > 3)) {
1041 pDevice->uConnectionRate = 3;
1043 else {
1044 pDevice->uConnectionRate = brate;
1045 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fixed to Rate %d \n", pDevice->uConnectionRate);
1049 else {
1050 pDevice->bFixRate = FALSE;
1051 pDevice->uConnectionRate = 13;
1052 printk("auto rate:connection_rate is 13\n");
1055 return rc;
1059 * Wireless Handler : get data rate
1062 int iwctl_giwrate(struct net_device *dev,
1063 struct iw_request_info *info,
1064 struct iw_param *wrq,
1065 char *extra)
1067 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1068 //2007-0118-05,<Mark> by EinsnLiu
1069 //Mark the unnecessary sentences.
1070 // PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1072 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRATE \n");
1074 BYTE abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
1075 int brate = 0;
1076 //2008-5-8 <modify> by chester
1077 if(pDevice->bLinkPass){
1078 if(pDevice->bFixRate == TRUE){
1079 if (pDevice->uConnectionRate < 13) {
1080 brate = abySupportedRates[pDevice->uConnectionRate];
1081 }else {
1082 if (pDevice->byBBType == BB_TYPE_11B)
1083 brate = 0x16;
1084 if (pDevice->byBBType == BB_TYPE_11G)
1085 brate = 0x6C;
1086 if (pDevice->byBBType == BB_TYPE_11A)
1087 brate = 0x6C;
1090 else
1093 brate = abySupportedRates[TxRate_iwconfig];
1096 else brate =0;
1097 //2007-0118-05,<Mark> by EinsnLiu
1098 //Mark the unnecessary sentences.
1100 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1101 if (pDevice->byBBType == BB_TYPE_11B)
1102 brate = 0x16;
1103 if (pDevice->byBBType == BB_TYPE_11G)
1104 brate = 0x6C;
1105 if (pDevice->byBBType == BB_TYPE_11A)
1106 brate = 0x6C;
1110 // if (pDevice->uConnectionRate == 13)
1111 // brate = abySupportedRates[pDevice->wCurrentRate];
1112 wrq->value = brate * 500000;
1113 // If more than one rate, set auto
1114 if (pDevice->bFixRate == TRUE)
1115 wrq->fixed = TRUE;
1119 return 0;
1125 * Wireless Handler : set rts threshold
1128 int iwctl_siwrts(struct net_device *dev,
1129 struct iw_request_info *info,
1130 struct iw_param *wrq,
1131 char *extra)
1133 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1134 int rc = 0;
1136 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRTS \n");
1139 int rthr = wrq->value;
1140 if(wrq->disabled)
1141 rthr = 2312;
1142 if((rthr < 0) || (rthr > 2312)) {
1143 rc = -EINVAL;
1144 }else {
1145 pDevice->wRTSThreshold = rthr;
1149 return 0;
1153 * Wireless Handler : get rts
1156 int iwctl_giwrts(struct net_device *dev,
1157 struct iw_request_info *info,
1158 struct iw_param *wrq,
1159 char *extra)
1161 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1163 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRTS \n");
1164 wrq->value = pDevice->wRTSThreshold;
1165 wrq->disabled = (wrq->value >= 2312);
1166 wrq->fixed = 1;
1168 return 0;
1172 * Wireless Handler : set fragment threshold
1175 int iwctl_siwfrag(struct net_device *dev,
1176 struct iw_request_info *info,
1177 struct iw_param *wrq,
1178 char *extra)
1180 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1181 int rc = 0;
1182 int fthr = wrq->value;
1185 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFRAG \n");
1188 if (wrq->disabled)
1189 fthr = 2312;
1190 if((fthr < 256) || (fthr > 2312)) {
1191 rc = -EINVAL;
1192 }else {
1193 fthr &= ~0x1; // Get an even value
1194 pDevice->wFragmentationThreshold = (u16)fthr;
1197 return rc;
1201 * Wireless Handler : get fragment threshold
1204 int iwctl_giwfrag(struct net_device *dev,
1205 struct iw_request_info *info,
1206 struct iw_param *wrq,
1207 char *extra)
1209 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1211 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFRAG \n");
1212 wrq->value = pDevice->wFragmentationThreshold;
1213 wrq->disabled = (wrq->value >= 2312);
1214 wrq->fixed = 1;
1216 return 0;
1222 * Wireless Handler : set retry threshold
1224 int iwctl_siwretry(struct net_device *dev,
1225 struct iw_request_info *info,
1226 struct iw_param *wrq,
1227 char *extra)
1229 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1230 int rc = 0;
1233 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRETRY \n");
1235 if (wrq->disabled) {
1236 rc = -EINVAL;
1237 return rc;
1240 if (wrq->flags & IW_RETRY_LIMIT) {
1241 if(wrq->flags & IW_RETRY_MAX)
1242 pDevice->byLongRetryLimit = wrq->value;
1243 else if (wrq->flags & IW_RETRY_MIN)
1244 pDevice->byShortRetryLimit = wrq->value;
1245 else {
1246 // No modifier : set both
1247 pDevice->byShortRetryLimit = wrq->value;
1248 pDevice->byLongRetryLimit = wrq->value;
1251 if (wrq->flags & IW_RETRY_LIFETIME) {
1252 pDevice->wMaxTransmitMSDULifetime = wrq->value;
1256 return rc;
1260 * Wireless Handler : get retry threshold
1262 int iwctl_giwretry(struct net_device *dev,
1263 struct iw_request_info *info,
1264 struct iw_param *wrq,
1265 char *extra)
1267 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1268 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRETRY \n");
1269 wrq->disabled = 0; // Can't be disabled
1271 // Note : by default, display the min retry number
1272 if((wrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1273 wrq->flags = IW_RETRY_LIFETIME;
1274 wrq->value = (int)pDevice->wMaxTransmitMSDULifetime; //ms
1275 } else if((wrq->flags & IW_RETRY_MAX)) {
1276 wrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
1277 wrq->value = (int)pDevice->byLongRetryLimit;
1278 } else {
1279 wrq->flags = IW_RETRY_LIMIT;
1280 wrq->value = (int)pDevice->byShortRetryLimit;
1281 if((int)pDevice->byShortRetryLimit != (int)pDevice->byLongRetryLimit)
1282 wrq->flags |= IW_RETRY_MIN;
1286 return 0;
1291 * Wireless Handler : set encode mode
1293 int iwctl_siwencode(struct net_device *dev,
1294 struct iw_request_info *info,
1295 struct iw_point *wrq,
1296 char *extra)
1298 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1299 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1300 DWORD dwKeyIndex = (DWORD)(wrq->flags & IW_ENCODE_INDEX);
1301 int ii,uu, rc = 0;
1302 int index = (wrq->flags & IW_ENCODE_INDEX);
1304 //2007-0207-07,<Modify> by EinsnLiu
1305 //There are some problems when using iwconfig encode/key command to set the WEP key.
1306 //I almost rewrite this function.
1307 //now it support:(assume the wireless interface's name is eth0)
1308 //iwconfig eth0 key [1] 1122334455 open /*set key stirng to index 1,and driver using key index is set to 1*/
1309 //iwconfig eth0 key [3] /*set driver using key index to 3,the key string no change */
1310 //iwconfig eth0 key 1122334455 /*set key string to driver using index*/
1311 //iwconfig eth0 key restricted /*enable share key*/
1313 PSKeyTable pkeytab;
1315 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODE \n");
1317 if((wrq->flags & IW_ENCODE_DISABLED)==0){
1318 //Not disable encryption
1320 if (dwKeyIndex > WLAN_WEP_NKEYS) {
1321 rc = -EINVAL;
1322 return rc;
1325 if(dwKeyIndex<1&&((wrq->flags&IW_ENCODE_NOKEY)==0)){//set default key
1326 if(pDevice->byKeyIndex<WLAN_WEP_NKEYS){
1327 dwKeyIndex=pDevice->byKeyIndex;
1329 else dwKeyIndex=0;
1330 }else dwKeyIndex--;
1333 // Check the size of the key
1334 if (wrq->length > WLAN_WEP232_KEYLEN) {
1335 rc = -EINVAL;
1336 return rc;
1339 if(wrq->length>0){//have key
1341 if (wrq->length == WLAN_WEP232_KEYLEN) {
1342 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 232 bit wep key\n");
1344 else if (wrq->length == WLAN_WEP104_KEYLEN) {
1345 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 104 bit wep key\n");
1347 else if (wrq->length == WLAN_WEP40_KEYLEN) {
1348 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 40 bit wep key, index= %d\n", (int)dwKeyIndex);
1349 }else {//no support length
1350 rc = -EINVAL;
1351 return rc;
1353 memset(pDevice->abyKey, 0, WLAN_WEP232_KEYLEN);
1354 memcpy(pDevice->abyKey, extra, wrq->length);
1356 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyKey: ");
1357 for (ii = 0; ii < wrq->length; ii++) {
1358 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pDevice->abyKey[ii]);
1361 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1362 spin_lock_irq(&pDevice->lock);
1363 KeybSetDefaultKey(&(pDevice->sKey),
1364 (DWORD)(dwKeyIndex | (1 << 31)),
1365 wrq->length,
1366 NULL,
1367 pDevice->abyKey,
1368 KEY_CTL_WEP,
1369 pDevice->PortOffset,
1370 pDevice->byLocalID
1372 spin_unlock_irq(&pDevice->lock);
1374 pDevice->byKeyIndex = (BYTE)dwKeyIndex;
1375 pDevice->uKeyLength = wrq->length;
1376 pDevice->bTransmitKey = TRUE;
1377 pDevice->bEncryptionEnable = TRUE;
1378 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1380 }else if(index>0){
1381 //when the length is 0 the request only changes the default transmit key index
1382 //check the new key has a non zero lenget
1383 if(pDevice->bEncryptionEnable==FALSE)
1385 rc = -EINVAL;
1386 return rc;
1388 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Just set Default key Index:\n");
1389 pkeytab=&(pDevice->sKey.KeyTable[MAX_KEY_TABLE-1]);
1390 if(pkeytab->GroupKey[(BYTE)dwKeyIndex].uKeyLength==0){
1391 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Default key len is 0\n");
1392 rc = -EINVAL;
1393 return rc;
1395 pDevice->byKeyIndex =(BYTE)dwKeyIndex;
1396 pkeytab->dwGTKeyIndex =dwKeyIndex | (1 << 31);
1397 pkeytab->GroupKey[(BYTE)dwKeyIndex].dwKeyIndex=dwKeyIndex | (1 << 31);
1400 }else {//disable the key
1401 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable WEP function\n");
1402 if(pDevice->bEncryptionEnable==FALSE)
1403 return 0;
1404 pMgmt->bShareKeyAlgorithm = FALSE;
1405 pDevice->bEncryptionEnable = FALSE;
1406 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1407 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1408 spin_lock_irq(&pDevice->lock);
1409 for(uu=0;uu<MAX_KEY_TABLE;uu++)
1410 MACvDisableKeyEntry(pDevice->PortOffset, uu);
1411 spin_unlock_irq(&pDevice->lock);
1414 //End Modify,Einsn
1417 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODE \n");
1419 // Check the size of the key
1420 if (wrq->length > WLAN_WEP232_KEYLEN) {
1421 rc = -EINVAL;
1422 return rc;
1425 if (dwKeyIndex > WLAN_WEP_NKEYS) {
1426 rc = -EINVAL;
1427 return rc;
1430 if (dwKeyIndex > 0)
1431 dwKeyIndex--;
1433 // Send the key to the card
1434 if (wrq->length > 0) {
1436 if (wrq->length == WLAN_WEP232_KEYLEN) {
1437 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 232 bit wep key\n");
1439 else if (wrq->length == WLAN_WEP104_KEYLEN) {
1440 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 104 bit wep key\n");
1442 else if (wrq->length == WLAN_WEP40_KEYLEN) {
1443 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 40 bit wep key, index= %d\n", (int)dwKeyIndex);
1445 memset(pDevice->abyKey, 0, WLAN_WEP232_KEYLEN);
1446 memcpy(pDevice->abyKey, extra, wrq->length);
1448 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyKey: ");
1449 for (ii = 0; ii < wrq->length; ii++) {
1450 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pDevice->abyKey[ii]);
1453 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1454 spin_lock_irq(&pDevice->lock);
1455 KeybSetDefaultKey(&(pDevice->sKey),
1456 (DWORD)(pDevice->byKeyIndex | (1 << 31)),
1457 pDevice->uKeyLength,
1458 NULL,
1459 pDevice->abyKey,
1460 KEY_CTL_WEP,
1461 pDevice->PortOffset,
1462 pDevice->byLocalID
1464 spin_unlock_irq(&pDevice->lock);
1466 pDevice->byKeyIndex = (BYTE)dwKeyIndex;
1467 pDevice->uKeyLength = wrq->length;
1468 pDevice->bTransmitKey = TRUE;
1469 pDevice->bEncryptionEnable = TRUE;
1470 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1472 // Do we want to just set the transmit key index ?
1473 if ( index < 4 ) {
1474 pDevice->byKeyIndex = index;
1476 else if(!wrq->flags & IW_ENCODE_MODE) {
1477 rc = -EINVAL;
1478 return rc;
1481 // Read the flags
1482 if(wrq->flags & IW_ENCODE_DISABLED){
1484 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable WEP function\n");
1485 pMgmt->bShareKeyAlgorithm = FALSE;
1486 pDevice->bEncryptionEnable = FALSE;
1487 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1488 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1489 spin_lock_irq(&pDevice->lock);
1490 for(uu=0;uu<MAX_KEY_TABLE;uu++)
1491 MACvDisableKeyEntry(pDevice->PortOffset, uu);
1492 spin_unlock_irq(&pDevice->lock);
1497 if(wrq->flags & IW_ENCODE_RESTRICTED) {
1498 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & ShareKey System\n");
1499 pMgmt->bShareKeyAlgorithm = TRUE;
1501 if(wrq->flags & IW_ENCODE_OPEN) {
1502 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & Open System\n");
1503 pMgmt->bShareKeyAlgorithm = FALSE;
1505 return rc;
1509 * Wireless Handler : get encode mode
1512 int iwctl_giwencode(struct net_device *dev,
1513 struct iw_request_info *info,
1514 struct iw_point *wrq,
1515 char *extra)
1517 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1518 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1519 int rc = 0;
1520 char abyKey[WLAN_WEP232_KEYLEN];
1521 UINT index = (UINT)(wrq->flags & IW_ENCODE_INDEX);
1522 PSKeyItem pKey = NULL;
1524 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODE\n");
1525 //2007-0207-06,<Add> by EinsnLiu
1526 //the key index in iwconfig is 1-4 when our driver is 0-3
1527 //so it can't be used directly.
1528 //if the index is 0,we should used the index set by driver.
1529 if (index > WLAN_WEP_NKEYS) {
1530 rc = -EINVAL;
1531 return rc;
1533 if(index<1){//set default key
1534 if(pDevice->byKeyIndex<WLAN_WEP_NKEYS){
1535 index=pDevice->byKeyIndex;
1537 else index=0;
1538 }else index--;
1539 //End Add,Einsn
1541 memset(abyKey, 0, sizeof(abyKey));
1542 // Check encryption mode
1543 wrq->flags = IW_ENCODE_NOKEY;
1544 // Is WEP enabled ???
1545 if (pDevice->bEncryptionEnable)
1546 wrq->flags |= IW_ENCODE_ENABLED;
1547 else
1548 wrq->flags |= IW_ENCODE_DISABLED;
1550 if (pMgmt->bShareKeyAlgorithm)
1551 wrq->flags |= IW_ENCODE_RESTRICTED;
1552 else
1553 wrq->flags |= IW_ENCODE_OPEN;
1555 if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (BYTE)index , &pKey)){
1556 wrq->length = pKey->uKeyLength;
1557 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1558 //2007-0207-06,<Modify> by EinsnLiu
1559 //only get key success need to copy data
1560 //index should +1.
1561 //there is not necessary to return -EINVAL when get key failed
1562 //if return -EINVAL,the encryption item can't be display by the command "iwconfig".
1563 wrq->flags |= index+1;
1564 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1567 //else {
1568 // rc = -EINVAL;
1569 // return rc;
1570 // }
1573 //End Modify,Einsn
1575 return 0;
1579 //2008-0409-06, <Add> by Einsn Liu
1581 int iwctl_giwencode(struct net_device *dev,
1582 struct iw_request_info *info,
1583 struct iw_point *wrq,
1584 char *extra)
1586 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1587 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1588 char abyKey[WLAN_WEP232_KEYLEN];
1590 UINT index = (UINT)(wrq->flags & IW_ENCODE_INDEX);
1591 PSKeyItem pKey = NULL;
1593 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODE\n");
1595 if (index > WLAN_WEP_NKEYS) {
1596 return -EINVAL;
1598 if(index<1){//get default key
1599 if(pDevice->byKeyIndex<WLAN_WEP_NKEYS){
1600 index=pDevice->byKeyIndex;
1601 } else
1602 index=0;
1603 }else
1604 index--;
1606 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
1607 // Check encryption mode
1608 wrq->flags = IW_ENCODE_NOKEY;
1609 // Is WEP enabled ???
1610 if (pDevice->bEncryptionEnable)
1611 wrq->flags |= IW_ENCODE_ENABLED;
1612 else
1613 wrq->flags |= IW_ENCODE_DISABLED;
1615 if (pMgmt->bShareKeyAlgorithm)
1616 wrq->flags |= IW_ENCODE_RESTRICTED;
1617 else
1618 wrq->flags |= IW_ENCODE_OPEN;
1619 wrq->length=0;
1621 if((index==0)&&(pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled||
1622 pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)){//get wpa pairwise key
1623 if (KeybGetKey(&(pDevice->sKey),pMgmt->abyCurrBSSID, 0xffffffff, &pKey)){
1624 wrq->length = pKey->uKeyLength;
1625 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1626 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1628 }else if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (BYTE)index , &pKey)){
1629 wrq->length = pKey->uKeyLength;
1630 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1631 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1634 wrq->flags |= index+1;
1636 return 0;
1641 * Wireless Handler : set power mode
1643 int iwctl_siwpower(struct net_device *dev,
1644 struct iw_request_info *info,
1645 struct iw_param *wrq,
1646 char *extra)
1648 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1649 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1650 int rc = 0;
1652 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER \n");
1654 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
1655 rc = -EINVAL;
1656 return rc;
1659 if (wrq->disabled) {
1660 pDevice->ePSMode = WMAC_POWER_CAM;
1661 PSvDisablePowerSaving(pDevice);
1662 return rc;
1664 if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1665 pDevice->ePSMode = WMAC_POWER_FAST;
1666 PSvEnablePowerSaving((HANDLE)pDevice, pMgmt->wListenInterval);
1668 } else if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
1669 pDevice->ePSMode = WMAC_POWER_FAST;
1670 PSvEnablePowerSaving((HANDLE)pDevice, pMgmt->wListenInterval);
1672 switch (wrq->flags & IW_POWER_MODE) {
1673 case IW_POWER_UNICAST_R:
1674 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_UNICAST_R \n");
1675 rc = -EINVAL;
1676 break;
1677 case IW_POWER_ALL_R:
1678 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ALL_R \n");
1679 rc = -EINVAL;
1680 case IW_POWER_ON:
1681 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ON \n");
1682 break;
1683 default:
1684 rc = -EINVAL;
1687 return rc;
1691 * Wireless Handler : get power mode
1693 int iwctl_giwpower(struct net_device *dev,
1694 struct iw_request_info *info,
1695 struct iw_param *wrq,
1696 char *extra)
1698 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1699 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1700 int mode = pDevice->ePSMode;
1703 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPOWER \n");
1706 if ((wrq->disabled = (mode == WMAC_POWER_CAM)))
1707 return 0;
1709 if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1710 wrq->value = (int)((pMgmt->wListenInterval * pMgmt->wCurrBeaconPeriod) << 10);
1711 wrq->flags = IW_POWER_TIMEOUT;
1712 } else {
1713 wrq->value = (int)((pMgmt->wListenInterval * pMgmt->wCurrBeaconPeriod) << 10);
1714 wrq->flags = IW_POWER_PERIOD;
1716 wrq->flags |= IW_POWER_ALL_R;
1718 return 0;
1723 * Wireless Handler : get Sensitivity
1725 int iwctl_giwsens(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 long ldBm;
1733 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSENS \n");
1734 if (pDevice->bLinkPass == TRUE) {
1735 RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm);
1736 wrq->value = ldBm;
1738 else {
1739 wrq->value = 0;
1741 wrq->disabled = (wrq->value == 0);
1742 wrq->fixed = 1;
1745 return 0;
1748 //2008-0409-07, <Add> by Einsn Liu
1749 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1751 int iwctl_siwauth(struct net_device *dev,
1752 struct iw_request_info *info,
1753 struct iw_param *wrq,
1754 char *extra)
1756 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1757 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1758 int ret=0;
1759 static int wpa_version=0; //must be static to save the last value,einsn liu
1760 static int pairwise=0;
1762 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH \n");
1763 switch (wrq->flags & IW_AUTH_INDEX) {
1764 case IW_AUTH_WPA_VERSION:
1765 wpa_version = wrq->value;
1766 if(wrq->value == IW_AUTH_WPA_VERSION_DISABLED) {
1767 PRINT_K("iwctl_siwauth:set WPADEV to disable at 1??????\n");
1768 //pDevice->bWPADevEnable = FALSE;
1770 else if(wrq->value == IW_AUTH_WPA_VERSION_WPA) {
1771 PRINT_K("iwctl_siwauth:set WPADEV to WPA1******\n");
1773 else {
1774 PRINT_K("iwctl_siwauth:set WPADEV to WPA2******\n");
1776 //pDevice->bWPASuppWextEnabled =TRUE;
1777 break;
1778 case IW_AUTH_CIPHER_PAIRWISE:
1779 pairwise = wrq->value;
1780 if(pairwise == IW_AUTH_CIPHER_CCMP){
1781 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1782 }else if(pairwise == IW_AUTH_CIPHER_TKIP){
1783 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1784 }else if(pairwise == IW_AUTH_CIPHER_WEP40||pairwise == IW_AUTH_CIPHER_WEP104){
1785 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1786 }else if(pairwise == IW_AUTH_CIPHER_NONE){
1787 //do nothing,einsn liu
1788 }else pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1790 break;
1791 case IW_AUTH_CIPHER_GROUP:
1792 if(wpa_version == IW_AUTH_WPA_VERSION_DISABLED)
1793 break;
1794 if(pairwise == IW_AUTH_CIPHER_NONE){
1795 if(wrq->value == IW_AUTH_CIPHER_CCMP){
1796 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1797 }else {
1798 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1801 break;
1802 case IW_AUTH_KEY_MGMT:
1804 if(wpa_version == IW_AUTH_WPA_VERSION_WPA2){
1805 if(wrq->value == IW_AUTH_KEY_MGMT_PSK)
1806 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
1807 else pMgmt->eAuthenMode = WMAC_AUTH_WPA2;
1808 }else if(wpa_version == IW_AUTH_WPA_VERSION_WPA){
1809 if(wrq->value == 0){
1810 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
1811 }else if(wrq->value == IW_AUTH_KEY_MGMT_PSK)
1812 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
1813 else pMgmt->eAuthenMode = WMAC_AUTH_WPA;
1816 break;
1817 case IW_AUTH_TKIP_COUNTERMEASURES:
1818 break; /* FIXME */
1819 case IW_AUTH_DROP_UNENCRYPTED:
1820 break;
1821 case IW_AUTH_80211_AUTH_ALG:
1822 if(wrq->value==IW_AUTH_ALG_OPEN_SYSTEM){
1823 pMgmt->bShareKeyAlgorithm=FALSE;
1824 }else if(wrq->value==IW_AUTH_ALG_SHARED_KEY){
1825 pMgmt->bShareKeyAlgorithm=TRUE;
1827 break;
1828 case IW_AUTH_WPA_ENABLED:
1829 //pDevice->bWPADevEnable = !! wrq->value;
1830 break;
1831 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1832 break;
1833 case IW_AUTH_ROAMING_CONTROL:
1834 ret = -EOPNOTSUPP;
1835 break;
1836 case IW_AUTH_PRIVACY_INVOKED:
1837 pDevice->bEncryptionEnable = !!wrq->value;
1838 if(pDevice->bEncryptionEnable == FALSE){
1839 wpa_version = 0;
1840 pairwise = 0;
1841 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1842 pMgmt->bShareKeyAlgorithm = FALSE;
1843 pMgmt->eAuthenMode = FALSE;
1844 //pDevice->bWPADevEnable = FALSE;
1847 break;
1848 default:
1849 ret = -EOPNOTSUPP;
1850 break;
1853 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_version = %d\n",wpa_version);
1854 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pairwise = %d\n",pairwise);
1855 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->eEncryptionStatus = %d\n",pDevice->eEncryptionStatus);
1856 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->eAuthenMode = %d\n",pMgmt->eAuthenMode);
1857 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->bShareKeyAlgorithm = %s\n",pMgmt->bShareKeyAlgorithm?"TRUE":"FALSE");
1858 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->bEncryptionEnable = %s\n",pDevice->bEncryptionEnable?"TRUE":"FALSE");
1859 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->bWPADevEnable = %s\n",pDevice->bWPADevEnable?"TRUE":"FALSE");
1861 return ret;
1865 int iwctl_giwauth(struct net_device *dev,
1866 struct iw_request_info *info,
1867 struct iw_param *wrq,
1868 char *extra)
1870 return -EOPNOTSUPP;
1875 int iwctl_siwgenie(struct net_device *dev,
1876 struct iw_request_info *info,
1877 struct iw_point *wrq,
1878 char *extra)
1880 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1881 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1882 int ret=0;
1884 if(wrq->length){
1885 if ((wrq->length < 2) || (extra[1]+2 != wrq->length)) {
1886 ret = -EINVAL;
1887 goto out;
1889 if(wrq->length > MAX_WPA_IE_LEN){
1890 ret = -ENOMEM;
1891 goto out;
1893 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
1894 if(copy_from_user(pMgmt->abyWPAIE, extra, wrq->length)){
1895 ret = -EFAULT;
1896 goto out;
1898 pMgmt->wWPAIELen = wrq->length;
1899 }else {
1900 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
1901 pMgmt->wWPAIELen = 0;
1904 out://not completely ...not necessary in wpa_supplicant 0.5.8
1905 return 0;
1908 int iwctl_giwgenie(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;
1916 int space = wrq->length;
1918 wrq->length = 0;
1919 if(pMgmt->wWPAIELen > 0){
1920 wrq->length = pMgmt->wWPAIELen;
1921 if(pMgmt->wWPAIELen <= space){
1922 if(copy_to_user(extra, pMgmt->abyWPAIE, pMgmt->wWPAIELen)){
1923 ret = -EFAULT;
1925 }else
1926 ret = -E2BIG;
1929 return ret;
1933 int iwctl_siwencodeext(struct net_device *dev,
1934 struct iw_request_info *info,
1935 struct iw_point *wrq,
1936 char *extra)
1938 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1939 struct iw_encode_ext *ext = (struct iw_encode_ext*)extra;
1940 struct viawget_wpa_param *param=NULL;
1941 //original member
1942 wpa_alg alg_name;
1943 u8 addr[6];
1944 int key_idx, set_tx=0;
1945 u8 seq[IW_ENCODE_SEQ_MAX_SIZE];
1946 u8 key[64];
1947 size_t seq_len=0,key_len=0;
1949 // int ii;
1950 u8 *buf;
1951 size_t blen;
1952 u8 key_array[64];
1953 int ret=0;
1955 PRINT_K("SIOCSIWENCODEEXT...... \n");
1957 blen = sizeof(*param);
1958 buf = kmalloc((int)blen, (int)GFP_KERNEL);
1959 if (buf == NULL)
1960 return -ENOMEM;
1961 memset(buf, 0, blen);
1962 param = (struct viawget_wpa_param *) buf;
1964 //recover alg_name
1965 switch (ext->alg) {
1966 case IW_ENCODE_ALG_NONE:
1967 alg_name = WPA_ALG_NONE;
1968 break;
1969 case IW_ENCODE_ALG_WEP:
1970 alg_name = WPA_ALG_WEP;
1971 break;
1972 case IW_ENCODE_ALG_TKIP:
1973 alg_name = WPA_ALG_TKIP;
1974 break;
1975 case IW_ENCODE_ALG_CCMP:
1976 alg_name = WPA_ALG_CCMP;
1977 break;
1978 default:
1979 PRINT_K("Unknown alg = %d\n",ext->alg);
1980 ret= -ENOMEM;
1981 goto error;
1983 //recover addr
1984 memcpy(addr, ext->addr.sa_data, ETH_ALEN);
1985 //recover key_idx
1986 key_idx = (wrq->flags&IW_ENCODE_INDEX) - 1;
1987 //recover set_tx
1988 if(ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
1989 set_tx = 1;
1990 //recover seq,seq_len
1991 if(ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
1992 seq_len=IW_ENCODE_SEQ_MAX_SIZE;
1993 memcpy(seq, ext->rx_seq, seq_len);
1995 //recover key,key_len
1996 if(ext->key_len) {
1997 key_len=ext->key_len;
1998 memcpy(key, &ext->key[0], key_len);
2001 memset(key_array, 0, 64);
2002 if ( key_len > 0) {
2003 memcpy(key_array, key, key_len);
2004 if (key_len == 32) {
2005 // notice ! the oder
2006 memcpy(&key_array[16], &key[24], 8);
2007 memcpy(&key_array[24], &key[16], 8);
2011 /**************Translate iw_encode_ext to viawget_wpa_param****************/
2012 memcpy(param->addr, addr, ETH_ALEN);
2013 param->u.wpa_key.alg_name = (int)alg_name;
2014 param->u.wpa_key.set_tx = set_tx;
2015 param->u.wpa_key.key_index = key_idx;
2016 param->u.wpa_key.key_len = key_len;
2017 param->u.wpa_key.key = (u8 *)key_array;
2018 param->u.wpa_key.seq = (u8 *)seq;
2019 param->u.wpa_key.seq_len = seq_len;
2021 #if 0
2022 printk("param->u.wpa_key.alg_name =%d\n",param->u.wpa_key.alg_name);
2023 printk("param->addr=%02x:%02x:%02x:%02x:%02x:%02x\n",
2024 param->addr[0],param->addr[1],param->addr[2],
2025 param->addr[3],param->addr[4],param->addr[5]);
2026 printk("param->u.wpa_key.set_tx =%d\n",param->u.wpa_key.set_tx);
2027 printk("param->u.wpa_key.key_index =%d\n",param->u.wpa_key.key_index);
2028 printk("param->u.wpa_key.key_len =%d\n",param->u.wpa_key.key_len);
2029 printk("param->u.wpa_key.key =");
2030 for(ii=0;ii<param->u.wpa_key.key_len;ii++)
2031 printk("%02x:",param->u.wpa_key.key[ii]);
2032 printk("\n");
2033 printk("param->u.wpa_key.seq_len =%d\n",param->u.wpa_key.seq_len);
2034 printk("param->u.wpa_key.seq =");
2035 for(ii=0;ii<param->u.wpa_key.seq_len;ii++)
2036 printk("%02x:",param->u.wpa_key.seq[ii]);
2037 printk("\n");
2039 printk("...........\n");
2040 #endif
2041 //****set if current action is Network Manager count??
2042 //****this method is so foolish,but there is no other way???
2043 if(param->u.wpa_key.alg_name == WPA_ALG_NONE) {
2044 if(param->u.wpa_key.key_index ==0) {
2045 pDevice->bwextcount++;
2047 if((pDevice->bwextcount == 1)&&(param->u.wpa_key.key_index ==1)) {
2048 pDevice->bwextcount++;
2050 if((pDevice->bwextcount ==2)&&(param->u.wpa_key.key_index ==2)) {
2051 pDevice->bwextcount++;
2053 if((pDevice->bwextcount ==3)&&(param->u.wpa_key.key_index ==3)) {
2054 pDevice->bwextcount++;
2057 if( pDevice->bwextcount == 4) {
2058 printk("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n");
2059 pDevice->bwextcount=0;
2060 pDevice->bWPASuppWextEnabled = TRUE;
2062 //******
2064 spin_lock_irq(&pDevice->lock);
2065 ret = wpa_set_keys(pDevice, param, TRUE);
2066 spin_unlock_irq(&pDevice->lock);
2068 error:
2069 kfree(param);
2070 return ret;
2075 int iwctl_giwencodeext(struct net_device *dev,
2076 struct iw_request_info *info,
2077 struct iw_point *wrq,
2078 char *extra)
2080 return -EOPNOTSUPP;;
2083 int iwctl_siwmlme(struct net_device *dev,
2084 struct iw_request_info * info,
2085 struct iw_point *wrq,
2086 char *extra)
2088 PSDevice pDevice = (PSDevice)netdev_priv(dev);
2089 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
2090 struct iw_mlme *mlme = (struct iw_mlme *)extra;
2091 //u16 reason = cpu_to_le16(mlme->reason_code);
2092 int ret = 0;
2094 if(memcmp(pMgmt->abyCurrBSSID, mlme->addr.sa_data, ETH_ALEN)){
2095 ret = -EINVAL;
2096 return ret;
2098 switch(mlme->cmd){
2099 case IW_MLME_DEAUTH:
2100 //this command seems to be not complete,please test it --einsnliu
2101 //bScheduleCommand((HANDLE) pDevice, WLAN_CMD_DEAUTH, (PBYTE)&reason);
2102 break;
2103 case IW_MLME_DISASSOC:
2104 if(pDevice->bLinkPass == TRUE){
2105 printk("iwctl_siwmlme--->send DISASSOCIATE\n");
2106 //clear related flags
2107 memset(pMgmt->abyDesireBSSID, 0xFF,6);
2108 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
2109 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
2111 break;
2112 default:
2113 ret = -EOPNOTSUPP;
2116 return ret;
2120 #endif
2123 /*------------------------------------------------------------------*/
2125 * Structures to export the Wireless Handlers
2130 static const iw_handler iwctl_handler[] =
2132 (iw_handler) iwctl_commit, // SIOCSIWCOMMIT
2133 (iw_handler) iwctl_giwname, // SIOCGIWNAME
2134 (iw_handler) NULL, // SIOCSIWNWID
2135 (iw_handler) NULL, // SIOCGIWNWID
2136 (iw_handler) iwctl_siwfreq, // SIOCSIWFREQ
2137 (iw_handler) iwctl_giwfreq, // SIOCGIWFREQ
2138 (iw_handler) iwctl_siwmode, // SIOCSIWMODE
2139 (iw_handler) iwctl_giwmode, // SIOCGIWMODE
2140 (iw_handler) NULL, // SIOCSIWSENS
2141 (iw_handler) iwctl_giwsens, // SIOCGIWSENS
2142 (iw_handler) NULL, // SIOCSIWRANGE
2143 (iw_handler) iwctl_giwrange, // SIOCGIWRANGE
2144 (iw_handler) NULL, // SIOCSIWPRIV
2145 (iw_handler) NULL, // SIOCGIWPRIV
2146 (iw_handler) NULL, // SIOCSIWSTATS
2147 (iw_handler) NULL, // SIOCGIWSTATS
2148 (iw_handler) NULL, // SIOCSIWSPY
2149 (iw_handler) NULL, // SIOCGIWSPY
2150 (iw_handler) NULL, // -- hole --
2151 (iw_handler) NULL, // -- hole --
2152 (iw_handler) iwctl_siwap, // SIOCSIWAP
2153 (iw_handler) iwctl_giwap, // SIOCGIWAP
2154 (iw_handler) NULL, // -- hole -- 0x16
2155 (iw_handler) iwctl_giwaplist, // SIOCGIWAPLIST
2156 (iw_handler) iwctl_siwscan, // SIOCSIWSCAN
2157 (iw_handler) iwctl_giwscan, // SIOCGIWSCAN
2158 (iw_handler) iwctl_siwessid, // SIOCSIWESSID
2159 (iw_handler) iwctl_giwessid, // SIOCGIWESSID
2160 (iw_handler) NULL, // SIOCSIWNICKN
2161 (iw_handler) NULL, // SIOCGIWNICKN
2162 (iw_handler) NULL, // -- hole --
2163 (iw_handler) NULL, // -- hole --
2164 (iw_handler) iwctl_siwrate, // SIOCSIWRATE 0x20
2165 (iw_handler) iwctl_giwrate, // SIOCGIWRATE
2166 (iw_handler) iwctl_siwrts, // SIOCSIWRTS
2167 (iw_handler) iwctl_giwrts, // SIOCGIWRTS
2168 (iw_handler) iwctl_siwfrag, // SIOCSIWFRAG
2169 (iw_handler) iwctl_giwfrag, // SIOCGIWFRAG
2170 (iw_handler) NULL, // SIOCSIWTXPOW
2171 (iw_handler) NULL, // SIOCGIWTXPOW
2172 (iw_handler) iwctl_siwretry, // SIOCSIWRETRY
2173 (iw_handler) iwctl_giwretry, // SIOCGIWRETRY
2174 (iw_handler) iwctl_siwencode, // SIOCSIWENCODE
2175 (iw_handler) iwctl_giwencode, // SIOCGIWENCODE
2176 (iw_handler) iwctl_siwpower, // SIOCSIWPOWER
2177 (iw_handler) iwctl_giwpower, // SIOCGIWPOWER
2178 (iw_handler) NULL, // -- hole --
2179 (iw_handler) NULL, // -- hole --
2180 (iw_handler) iwctl_siwgenie, // SIOCSIWGENIE
2181 (iw_handler) iwctl_giwgenie, // SIOCGIWGENIE
2182 (iw_handler) iwctl_siwauth, // SIOCSIWAUTH
2183 (iw_handler) iwctl_giwauth, // SIOCGIWAUTH
2184 (iw_handler) iwctl_siwencodeext, // SIOCSIWENCODEEXT
2185 (iw_handler) iwctl_giwencodeext, // SIOCGIWENCODEEXT
2186 (iw_handler) NULL, // SIOCSIWPMKSA
2187 (iw_handler) NULL, // -- hole --
2192 static const iw_handler iwctl_handler[] =
2194 (iw_handler) iwctl_commit, // SIOCSIWCOMMIT
2195 (iw_handler) NULL, // SIOCGIWNAME
2196 (iw_handler) NULL, // SIOCSIWNWID
2197 (iw_handler) NULL, // SIOCGIWNWID
2198 (iw_handler) NULL, // SIOCSIWFREQ
2199 (iw_handler) NULL, // SIOCGIWFREQ
2200 (iw_handler) NULL, // SIOCSIWMODE
2201 (iw_handler) NULL, // SIOCGIWMODE
2202 (iw_handler) NULL, // SIOCSIWSENS
2203 (iw_handler) NULL, // SIOCGIWSENS
2204 (iw_handler) NULL, // SIOCSIWRANGE
2205 (iw_handler) iwctl_giwrange, // SIOCGIWRANGE
2206 (iw_handler) NULL, // SIOCSIWPRIV
2207 (iw_handler) NULL, // SIOCGIWPRIV
2208 (iw_handler) NULL, // SIOCSIWSTATS
2209 (iw_handler) NULL, // SIOCGIWSTATS
2210 (iw_handler) NULL, // SIOCSIWSPY
2211 (iw_handler) NULL, // SIOCGIWSPY
2212 (iw_handler) NULL, // -- hole --
2213 (iw_handler) NULL, // -- hole --
2214 (iw_handler) NULL, // SIOCSIWAP
2215 (iw_handler) NULL, // SIOCGIWAP
2216 (iw_handler) NULL, // -- hole -- 0x16
2217 (iw_handler) NULL, // SIOCGIWAPLIST
2218 (iw_handler) iwctl_siwscan, // SIOCSIWSCAN
2219 (iw_handler) iwctl_giwscan, // SIOCGIWSCAN
2220 (iw_handler) NULL, // SIOCSIWESSID
2221 (iw_handler) NULL, // SIOCGIWESSID
2222 (iw_handler) NULL, // SIOCSIWNICKN
2223 (iw_handler) NULL, // SIOCGIWNICKN
2224 (iw_handler) NULL, // -- hole --
2225 (iw_handler) NULL, // -- hole --
2226 (iw_handler) NULL, // SIOCSIWRATE 0x20
2227 (iw_handler) NULL, // SIOCGIWRATE
2228 (iw_handler) NULL, // SIOCSIWRTS
2229 (iw_handler) NULL, // SIOCGIWRTS
2230 (iw_handler) NULL, // SIOCSIWFRAG
2231 (iw_handler) NULL, // SIOCGIWFRAG
2232 (iw_handler) NULL, // SIOCSIWTXPOW
2233 (iw_handler) NULL, // SIOCGIWTXPOW
2234 (iw_handler) NULL, // SIOCSIWRETRY
2235 (iw_handler) NULL, // SIOCGIWRETRY
2236 (iw_handler) NULL, // SIOCSIWENCODE
2237 (iw_handler) NULL, // SIOCGIWENCODE
2238 (iw_handler) NULL, // SIOCSIWPOWER
2239 (iw_handler) NULL, // SIOCGIWPOWER
2241 //2008-0409-07, <Add> by Einsn Liu
2242 (iw_handler) NULL, // -- hole --
2243 (iw_handler) NULL, // -- hole --
2244 (iw_handler) NULL, // SIOCSIWGENIE
2245 (iw_handler) NULL, // SIOCGIWGENIE
2246 (iw_handler) NULL, // SIOCSIWAUTH
2247 (iw_handler) NULL, // SIOCGIWAUTH
2248 (iw_handler) NULL, // SIOCSIWENCODEEXT
2249 (iw_handler) NULL, // SIOCGIWENCODEEXT
2250 (iw_handler) NULL, // SIOCSIWPMKSA
2251 (iw_handler) NULL, // -- hole --
2255 static const iw_handler iwctl_private_handler[] =
2257 NULL, // SIOCIWFIRSTPRIV
2261 struct iw_priv_args iwctl_private_args[] = {
2262 { IOCTL_CMD_SET,
2263 IW_PRIV_TYPE_CHAR | 1024, 0,
2264 "set"},
2269 const struct iw_handler_def iwctl_handler_def =
2271 .get_wireless_stats = &iwctl_get_wireless_stats,
2272 .num_standard = sizeof(iwctl_handler)/sizeof(iw_handler),
2273 // .num_private = sizeof(iwctl_private_handler)/sizeof(iw_handler),
2274 // .num_private_args = sizeof(iwctl_private_args)/sizeof(struct iw_priv_args),
2275 .num_private = 0,
2276 .num_private_args = 0,
2277 .standard = (iw_handler *) iwctl_handler,
2278 // .private = (iw_handler *) iwctl_private_handler,
2279 // .private_args = (struct iw_priv_args *)iwctl_private_args,
2280 .private = NULL,
2281 .private_args = NULL,