Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/geert/linux...
[linux-btrfs-devel.git] / drivers / staging / vt6655 / iwctl.c
blob5e425d1476b865bcb2c4606ab6d444a80638620f
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 * File: iwctl.c
21 * Purpose: wireless ext & ioctl functions
23 * Author: Lyndon Chen
25 * Date: July 5, 2006
27 * Functions:
29 * Revision History:
33 #include "device.h"
34 #include "ioctl.h"
35 #include "iocmd.h"
36 #include "mac.h"
37 #include "card.h"
38 #include "hostap.h"
39 #include "power.h"
40 #include "rf.h"
42 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
43 #include "iowpa.h"
44 #include "wpactl.h"
45 #endif
47 #include <net/iw_handler.h>
48 extern unsigned short TxRate_iwconfig;//2008-5-8 <add> by chester
50 /*--------------------- Static Definitions -------------------------*/
52 //2008-0409-07, <Add> by Einsn Liu
53 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
54 #define SUPPORTED_WIRELESS_EXT 18
55 #else
56 #define SUPPORTED_WIRELESS_EXT 17
57 #endif
59 static const long frequency_list[] = {
60 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
61 4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
62 5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210, 5220, 5230, 5240,
63 5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680,
64 5700, 5745, 5765, 5785, 5805, 5825
68 /*--------------------- Static Classes ----------------------------*/
71 //static int msglevel =MSG_LEVEL_DEBUG;
72 static int msglevel =MSG_LEVEL_INFO;
75 /*--------------------- Static Variables --------------------------*/
76 /*--------------------- Static Functions --------------------------*/
78 /*--------------------- Export Variables --------------------------*/
80 struct iw_statistics *iwctl_get_wireless_stats(struct net_device *dev)
82 PSDevice pDevice = netdev_priv(dev);
83 long ldBm;
85 pDevice->wstats.status = pDevice->eOPMode;
86 #ifdef Calcu_LinkQual
87 #if 0
88 if(pDevice->byBBType == BB_TYPE_11B) {
89 if(pDevice->byCurrSQ > 120)
90 pDevice->scStatistic.LinkQuality = 100;
91 else
92 pDevice->scStatistic.LinkQuality = pDevice->byCurrSQ*100/120;
94 else if(pDevice->byBBType == BB_TYPE_11G) {
95 if(pDevice->byCurrSQ < 20)
96 pDevice->scStatistic.LinkQuality = 100;
97 else if(pDevice->byCurrSQ >96)
98 pDevice->scStatistic.LinkQuality = 0;
99 else
100 pDevice->scStatistic.LinkQuality = (96-pDevice->byCurrSQ)*100/76;
102 if(pDevice->bLinkPass !=true)
103 pDevice->scStatistic.LinkQuality = 0;
104 #endif
105 if(pDevice->scStatistic.LinkQuality > 100)
106 pDevice->scStatistic.LinkQuality = 100;
107 pDevice->wstats.qual.qual =(unsigned char) pDevice->scStatistic.LinkQuality;
108 #else
109 pDevice->wstats.qual.qual = pDevice->byCurrSQ;
110 #endif
111 RFvRSSITodBm(pDevice, (unsigned char)(pDevice->uCurrRSSI), &ldBm);
112 pDevice->wstats.qual.level = ldBm;
113 //pDevice->wstats.qual.level = 0x100 - pDevice->uCurrRSSI;
114 pDevice->wstats.qual.noise = 0;
115 pDevice->wstats.qual.updated = 1;
116 pDevice->wstats.discard.nwid = 0;
117 pDevice->wstats.discard.code = 0;
118 pDevice->wstats.discard.fragment = 0;
119 pDevice->wstats.discard.retries = (unsigned long)pDevice->scStatistic.dwTsrErr;
120 pDevice->wstats.discard.misc = 0;
121 pDevice->wstats.miss.beacon = 0;
123 return &pDevice->wstats;
128 /*------------------------------------------------------------------*/
131 static int iwctl_commit(struct net_device *dev,
132 struct iw_request_info *info,
133 void *wrq,
134 char *extra)
136 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWCOMMIT \n");
138 return 0;
142 * Wireless Handler : get protocol name
145 int iwctl_giwname(struct net_device *dev,
146 struct iw_request_info *info,
147 char *wrq,
148 char *extra)
150 strcpy(wrq, "802.11-a/b/g");
151 return 0;
154 int iwctl_giwnwid(struct net_device *dev,
155 struct iw_request_info *info,
156 struct iw_param *wrq,
157 char *extra)
159 //wrq->value = 0x100;
160 //wrq->disabled = 0;
161 //wrq->fixed = 1;
162 //return 0;
163 return -EOPNOTSUPP;
167 * Wireless Handler : set scan
170 int iwctl_siwscan(struct net_device *dev,
171 struct iw_request_info *info,
172 struct iw_point *wrq,
173 char *extra)
175 PSDevice pDevice = (PSDevice)netdev_priv(dev);
176 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
177 struct iw_scan_req *req = (struct iw_scan_req *)extra;
178 unsigned char abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
179 PWLAN_IE_SSID pItemSSID=NULL;
180 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSCAN \n");
183 if(pDevice->byReAssocCount > 0) { //reject scan when re-associating!
184 //send scan event to wpa_Supplicant
185 union iwreq_data wrqu;
186 PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
187 memset(&wrqu, 0, sizeof(wrqu));
188 wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
189 return 0;
192 spin_lock_irq(&pDevice->lock);
193 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
195 //mike add: active scan OR passive scan OR desire_ssid scan
196 if(wrq->length == sizeof(struct iw_scan_req)) {
197 if (wrq->flags & IW_SCAN_THIS_ESSID) { //desire_ssid scan
198 memset(abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
199 pItemSSID = (PWLAN_IE_SSID)abyScanSSID;
200 pItemSSID->byElementID = WLAN_EID_SSID;
201 memcpy(pItemSSID->abySSID, req->essid, (int)req->essid_len);
202 if (pItemSSID->abySSID[req->essid_len - 1] == '\0') {
203 if(req->essid_len>0)
204 pItemSSID->len = req->essid_len - 1;
206 else
207 pItemSSID->len = req->essid_len;
208 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
209 PRINT_K("SIOCSIWSCAN:[desired_ssid=%s,len=%d]\n",((PWLAN_IE_SSID)abyScanSSID)->abySSID,
210 ((PWLAN_IE_SSID)abyScanSSID)->len);
211 bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID);
212 spin_unlock_irq(&pDevice->lock);
214 return 0;
216 else if(req->scan_type == IW_SCAN_TYPE_PASSIVE) { //passive scan
217 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
220 else { //active scan
221 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
224 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
225 //printk("SIOCSIWSCAN:WLAN_CMD_BSSID_SCAN\n");
226 bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
227 spin_unlock_irq(&pDevice->lock);
229 return 0;
234 * Wireless Handler : get scan results
237 int iwctl_giwscan(struct net_device *dev,
238 struct iw_request_info *info,
239 struct iw_point *wrq,
240 char *extra)
242 int ii, jj, kk;
243 PSDevice pDevice = (PSDevice)netdev_priv(dev);
244 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
245 PKnownBSS pBSS;
246 PWLAN_IE_SSID pItemSSID;
247 PWLAN_IE_SUPP_RATES pSuppRates, pExtSuppRates;
248 char *current_ev = extra;
249 char *end_buf = extra + IW_SCAN_MAX_DATA;
250 char *current_val = NULL;
251 struct iw_event iwe;
252 long ldBm;
253 char buf[MAX_WPA_IE_LEN * 2 + 30];
256 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSCAN \n");
258 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
259 // In scanning..
260 return -EAGAIN;
262 pBSS = &(pMgmt->sBSSList[0]);
263 for (ii = 0, jj = 0; jj < MAX_BSS_NUM ; jj++) {
264 if (current_ev >= end_buf)
265 break;
266 pBSS = &(pMgmt->sBSSList[jj]);
267 if (pBSS->bActive) {
268 //ADD mac address
269 memset(&iwe, 0, sizeof(iwe));
270 iwe.cmd = SIOCGIWAP;
271 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
272 memcpy(iwe.u.ap_addr.sa_data, pBSS->abyBSSID, WLAN_BSSID_LEN);
273 current_ev = iwe_stream_add_event(info,current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);
274 //ADD ssid
275 memset(&iwe, 0, sizeof(iwe));
276 iwe.cmd = SIOCGIWESSID;
277 pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
278 iwe.u.data.length = pItemSSID->len;
279 iwe.u.data.flags = 1;
280 current_ev = iwe_stream_add_point(info,current_ev,end_buf, &iwe, pItemSSID->abySSID);
281 //ADD mode
282 memset(&iwe, 0, sizeof(iwe));
283 iwe.cmd = SIOCGIWMODE;
284 if (WLAN_GET_CAP_INFO_ESS(pBSS->wCapInfo)) {
285 iwe.u.mode = IW_MODE_INFRA;
287 else {
288 iwe.u.mode = IW_MODE_ADHOC;
290 iwe.len = IW_EV_UINT_LEN;
291 current_ev = iwe_stream_add_event(info,current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
292 //ADD frequency
293 pSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abySuppRates;
294 pExtSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abyExtSuppRates;
295 memset(&iwe, 0, sizeof(iwe));
296 iwe.cmd = SIOCGIWFREQ;
297 iwe.u.freq.m = pBSS->uChannel;
298 iwe.u.freq.e = 0;
299 iwe.u.freq.i = 0;
300 current_ev = iwe_stream_add_event(info,current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
301 //2008-0409-04, <Add> by Einsn Liu
303 int f = (int)pBSS->uChannel - 1;
304 if(f < 0)f = 0;
305 iwe.u.freq.m = frequency_list[f] * 100000;
306 iwe.u.freq.e = 1;
308 current_ev = iwe_stream_add_event(info,current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
309 //ADD quality
310 memset(&iwe, 0, sizeof(iwe));
311 iwe.cmd = IWEVQUAL;
312 RFvRSSITodBm(pDevice, (unsigned char)(pBSS->uRSSI), &ldBm);
313 iwe.u.qual.level = ldBm;
314 iwe.u.qual.noise = 0;
315 //2008-0409-01, <Add> by Einsn Liu
316 if(-ldBm<50){
317 iwe.u.qual.qual = 100;
318 }else if(-ldBm > 90) {
319 iwe.u.qual.qual = 0;
320 }else {
321 iwe.u.qual.qual=(40-(-ldBm-50))*100/40;
323 iwe.u.qual.updated=7;
325 // iwe.u.qual.qual = 0;
326 current_ev = iwe_stream_add_event(info,current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
328 memset(&iwe, 0, sizeof(iwe));
329 iwe.cmd = SIOCGIWENCODE;
330 iwe.u.data.length = 0;
331 if (WLAN_GET_CAP_INFO_PRIVACY(pBSS->wCapInfo)) {
332 iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
333 }else {
334 iwe.u.data.flags = IW_ENCODE_DISABLED;
336 current_ev = iwe_stream_add_point(info,current_ev,end_buf, &iwe, pItemSSID->abySSID);
338 memset(&iwe, 0, sizeof(iwe));
339 iwe.cmd = SIOCGIWRATE;
340 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
341 current_val = current_ev + IW_EV_LCP_LEN;
343 for (kk = 0 ; kk < 12 ; kk++) {
344 if (pSuppRates->abyRates[kk] == 0)
345 break;
346 // Bit rate given in 500 kb/s units (+ 0x80)
347 iwe.u.bitrate.value = ((pSuppRates->abyRates[kk] & 0x7f) * 500000);
348 current_val = iwe_stream_add_value(info,current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
350 for (kk = 0 ; kk < 8 ; kk++) {
351 if (pExtSuppRates->abyRates[kk] == 0)
352 break;
353 // Bit rate given in 500 kb/s units (+ 0x80)
354 iwe.u.bitrate.value = ((pExtSuppRates->abyRates[kk] & 0x7f) * 500000);
355 current_val = iwe_stream_add_value(info,current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
358 if((current_val - current_ev) > IW_EV_LCP_LEN)
359 current_ev = current_val;
361 memset(&iwe, 0, sizeof(iwe));
362 iwe.cmd = IWEVCUSTOM;
363 sprintf(buf, "bcn_int=%d", pBSS->wBeaconInterval);
364 iwe.u.data.length = strlen(buf);
365 current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, buf);
367 if ((pBSS->wWPALen > 0) && (pBSS->wWPALen <= MAX_WPA_IE_LEN)) {
368 memset(&iwe, 0, sizeof(iwe));
369 iwe.cmd = IWEVGENIE;
370 iwe.u.data.length = pBSS->wWPALen;
371 current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, pBSS->byWPAIE);
374 if ((pBSS->wRSNLen > 0) && (pBSS->wRSNLen <= MAX_WPA_IE_LEN)) {
375 memset(&iwe, 0, sizeof(iwe));
376 iwe.cmd = IWEVGENIE;
377 iwe.u.data.length = pBSS->wRSNLen;
378 current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, pBSS->byRSNIE);
382 }// for
384 wrq->length = current_ev - extra;
385 return 0;
391 * Wireless Handler : set frequence or channel
394 int iwctl_siwfreq(struct net_device *dev,
395 struct iw_request_info *info,
396 struct iw_freq *wrq,
397 char *extra)
399 PSDevice pDevice = (PSDevice)netdev_priv(dev);
400 int rc = 0;
402 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFREQ \n");
404 // If setting by frequency, convert to a channel
405 if((wrq->e == 1) &&
406 (wrq->m >= (int) 2.412e8) &&
407 (wrq->m <= (int) 2.487e8)) {
408 int f = wrq->m / 100000;
409 int c = 0;
410 while((c < 14) && (f != frequency_list[c]))
411 c++;
412 wrq->e = 0;
413 wrq->m = c + 1;
415 // Setting by channel number
416 if((wrq->m > 14) || (wrq->e > 0))
417 rc = -EOPNOTSUPP;
418 else {
419 int channel = wrq->m;
420 if((channel < 1) || (channel > 14)) {
421 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: New channel value of %d is invalid!\n", dev->name, wrq->m);
422 rc = -EINVAL;
423 } else {
424 // Yes ! We can set it !!!
425 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Set to channel = %d\n", channel);
426 pDevice->uChannel = channel;
427 //2007-0207-04,<Add> by EinsnLiu
428 //Make change effect at once
429 pDevice->bCommit = true;
433 return rc;
437 * Wireless Handler : get frequence or channel
440 int iwctl_giwfreq(struct net_device *dev,
441 struct iw_request_info *info,
442 struct iw_freq *wrq,
443 char *extra)
445 PSDevice pDevice = (PSDevice)netdev_priv(dev);
446 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
448 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFREQ \n");
450 #ifdef WEXT_USECHANNELS
451 wrq->m = (int)pMgmt->uCurrChannel;
452 wrq->e = 0;
453 #else
455 int f = (int)pMgmt->uCurrChannel - 1;
456 if(f < 0)
457 f = 0;
458 wrq->m = frequency_list[f] * 100000;
459 wrq->e = 1;
461 #endif
463 return 0;
467 * Wireless Handler : set operation mode
470 int iwctl_siwmode(struct net_device *dev,
471 struct iw_request_info *info,
472 __u32 *wmode,
473 char *extra)
475 PSDevice pDevice = (PSDevice)netdev_priv(dev);
476 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
477 int rc = 0;
479 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMODE \n");
481 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP && pDevice->bEnableHostapd) {
482 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Can't set operation mode, hostapd is running \n");
483 return rc;
486 switch(*wmode) {
488 case IW_MODE_ADHOC:
489 if (pMgmt->eConfigMode != WMAC_CONFIG_IBSS_STA) {
490 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
491 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
492 pDevice->bCommit = true;
495 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to ad-hoc \n");
496 break;
497 case IW_MODE_AUTO:
498 case IW_MODE_INFRA:
499 if (pMgmt->eConfigMode != WMAC_CONFIG_ESS_STA) {
500 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
501 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
502 pDevice->bCommit = true;
505 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to infrastructure \n");
506 break;
507 case IW_MODE_MASTER:
509 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
510 rc = -EOPNOTSUPP;
511 break;
513 if (pMgmt->eConfigMode != WMAC_CONFIG_AP) {
514 pMgmt->eConfigMode = WMAC_CONFIG_AP;
515 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
516 pDevice->bCommit = true;
519 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to Access Point \n");
520 break;
522 case IW_MODE_REPEAT:
523 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
524 rc = -EOPNOTSUPP;
525 break;
526 default:
527 rc = -EINVAL;
530 return rc;
534 * Wireless Handler : get operation mode
537 int iwctl_giwmode(struct net_device *dev,
538 struct iw_request_info *info,
539 __u32 *wmode,
540 char *extra)
542 PSDevice pDevice = (PSDevice)netdev_priv(dev);
543 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
546 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWMODE \n");
547 // If not managed, assume it's ad-hoc
548 switch (pMgmt->eConfigMode) {
549 case WMAC_CONFIG_ESS_STA:
550 *wmode = IW_MODE_INFRA;
551 break;
552 case WMAC_CONFIG_IBSS_STA:
553 *wmode = IW_MODE_ADHOC;
554 break;
555 case WMAC_CONFIG_AUTO:
556 *wmode = IW_MODE_INFRA;
557 break;
558 case WMAC_CONFIG_AP:
559 *wmode = IW_MODE_MASTER;
560 break;
561 default:
562 *wmode = IW_MODE_ADHOC;
565 return 0;
570 * Wireless Handler : get capability range
573 int iwctl_giwrange(struct net_device *dev,
574 struct iw_request_info *info,
575 struct iw_point *wrq,
576 char *extra)
578 struct iw_range *range = (struct iw_range *) extra;
579 int i,k;
580 unsigned char abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
583 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRANGE \n");
584 if (wrq->pointer) {
585 wrq->length = sizeof(struct iw_range);
586 memset(range, 0, sizeof(struct iw_range));
587 range->min_nwid = 0x0000;
588 range->max_nwid = 0x0000;
589 range->num_channels = 14;
590 // Should be based on cap_rid.country to give only
591 // what the current card support
592 k = 0;
593 for(i = 0; i < 14; i++) {
594 range->freq[k].i = i + 1; // List index
595 range->freq[k].m = frequency_list[i] * 100000;
596 range->freq[k++].e = 1; // Values in table in MHz -> * 10^5 * 10
598 range->num_frequency = k;
599 // Hum... Should put the right values there
600 #ifdef Calcu_LinkQual
601 range->max_qual.qual = 100;
602 #else
603 range->max_qual.qual = 255;
604 #endif
605 range->max_qual.level = 0;
606 range->max_qual.noise = 0;
607 range->sensitivity = 255;
609 for(i = 0 ; i < 13 ; i++) {
610 range->bitrate[i] = abySupportedRates[i] * 500000;
611 if(range->bitrate[i] == 0)
612 break;
614 range->num_bitrates = i;
616 // Set an indication of the max TCP throughput
617 // in bit/s that we can expect using this interface.
618 // May be use for QoS stuff... Jean II
619 if(i > 2)
620 range->throughput = 5 * 1000 * 1000;
621 else
622 range->throughput = 1.5 * 1000 * 1000;
624 range->min_rts = 0;
625 range->max_rts = 2312;
626 range->min_frag = 256;
627 range->max_frag = 2312;
630 // the encoding capabilities
631 range->num_encoding_sizes = 3;
632 // 64(40) bits WEP
633 range->encoding_size[0] = 5;
634 // 128(104) bits WEP
635 range->encoding_size[1] = 13;
636 // 256 bits for WPA-PSK
637 range->encoding_size[2] = 32;
638 // 4 keys are allowed
639 range->max_encoding_tokens = 4;
641 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
642 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
644 range->min_pmp = 0;
645 range->max_pmp = 1000000;// 1 secs
646 range->min_pmt = 0;
647 range->max_pmt = 1000000;// 1 secs
648 range->pmp_flags = IW_POWER_PERIOD;
649 range->pmt_flags = IW_POWER_TIMEOUT;
650 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
652 // Transmit Power - values are in mW
654 range->txpower[0] = 100;
655 range->num_txpower = 1;
656 range->txpower_capa = IW_TXPOW_MWATT;
657 range->we_version_source = SUPPORTED_WIRELESS_EXT;
658 range->we_version_compiled = WIRELESS_EXT;
659 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
660 range->retry_flags = IW_RETRY_LIMIT;
661 range->r_time_flags = IW_RETRY_LIFETIME;
662 range->min_retry = 1;
663 range->max_retry = 65535;
664 range->min_r_time = 1024;
665 range->max_r_time = 65535 * 1024;
666 // Experimental measurements - boundary 11/5.5 Mb/s
667 // Note : with or without the (local->rssi), results
668 // are somewhat different. - Jean II
669 range->avg_qual.qual = 6;
670 range->avg_qual.level = 176; // -80 dBm
671 range->avg_qual.noise = 0;
675 return 0;
680 * Wireless Handler : set ap mac address
683 int iwctl_siwap(struct net_device *dev,
684 struct iw_request_info *info,
685 struct sockaddr *wrq,
686 char *extra)
688 PSDevice pDevice = (PSDevice)netdev_priv(dev);
689 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
690 int rc = 0;
691 unsigned char ZeroBSSID[WLAN_BSSID_LEN]={0x00,0x00,0x00,0x00,0x00,0x00};
693 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAP \n");
694 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
695 // In scanning..
696 printk("SIOCSIWAP(??)-->In scanning...\n");
697 // return -EAGAIN;
699 if (wrq->sa_family != ARPHRD_ETHER)
700 rc = -EINVAL;
701 else {
702 memcpy(pMgmt->abyDesireBSSID, wrq->sa_data, 6);
703 //2008-0409-05, <Add> by Einsn Liu
704 if((pDevice->bLinkPass == true) &&
705 (memcmp(pMgmt->abyDesireBSSID, pMgmt->abyCurrBSSID, 6)== 0)){
706 return rc;
708 //mike :add
709 if ((is_broadcast_ether_addr(pMgmt->abyDesireBSSID)) ||
710 (memcmp(pMgmt->abyDesireBSSID, ZeroBSSID, 6) == 0)){
711 PRINT_K("SIOCSIWAP:invalid desired BSSID return!\n");
712 return rc;
714 //mike add: if desired AP is hidden ssid(there are two same BSSID in list),
715 // then ignore,because you don't known which one to be connect with??
717 unsigned int ii , uSameBssidNum=0;
718 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
719 if (pMgmt->sBSSList[ii].bActive &&
720 !compare_ether_addr(pMgmt->sBSSList[ii].abyBSSID, pMgmt->abyDesireBSSID)) {
721 uSameBssidNum++;
724 if(uSameBssidNum >= 2) { //hit: desired AP is in hidden ssid mode!!!
725 PRINT_K("SIOCSIWAP:ignore for desired AP in hidden mode\n");
726 return rc;
730 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
731 pDevice->bCommit = true;
734 return rc;
738 * Wireless Handler : get ap mac address
741 int iwctl_giwap(struct net_device *dev,
742 struct iw_request_info *info,
743 struct sockaddr *wrq,
744 char *extra)
746 PSDevice pDevice = (PSDevice)netdev_priv(dev);
747 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
750 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAP \n");
752 memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
753 //2008-0410,<Modify> by Einsn Liu
754 if ((pDevice->bLinkPass == false) && (pMgmt->eCurrMode != WMAC_MODE_ESS_AP))
755 memset(wrq->sa_data, 0, 6);
757 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
758 memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
761 wrq->sa_family = ARPHRD_ETHER;
763 return 0;
769 * Wireless Handler : get ap list
772 int iwctl_giwaplist(struct net_device *dev,
773 struct iw_request_info *info,
774 struct iw_point *wrq,
775 char *extra)
777 int ii,jj, rc = 0;
778 struct sockaddr sock[IW_MAX_AP];
779 struct iw_quality qual[IW_MAX_AP];
780 PSDevice pDevice = (PSDevice)netdev_priv(dev);
781 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
784 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAPLIST \n");
785 // Only super-user can see AP list
787 if (!capable(CAP_NET_ADMIN)) {
788 rc = -EPERM;
789 return rc;
792 if (wrq->pointer) {
794 PKnownBSS pBSS = &(pMgmt->sBSSList[0]);
796 for (ii = 0, jj= 0; ii < MAX_BSS_NUM; ii++) {
797 pBSS = &(pMgmt->sBSSList[ii]);
798 if (!pBSS->bActive)
799 continue;
800 if ( jj >= IW_MAX_AP)
801 break;
802 memcpy(sock[jj].sa_data, pBSS->abyBSSID, 6);
803 sock[jj].sa_family = ARPHRD_ETHER;
804 qual[jj].level = pBSS->uRSSI;
805 qual[jj].qual = qual[jj].noise = 0;
806 qual[jj].updated = 2;
807 jj++;
810 wrq->flags = 1; // Should be define'd
811 wrq->length = jj;
812 memcpy(extra, sock, sizeof(struct sockaddr)*jj);
813 memcpy(extra + sizeof(struct sockaddr)*jj, qual, sizeof(struct iw_quality)*jj);
816 return rc;
821 * Wireless Handler : set essid
824 int iwctl_siwessid(struct net_device *dev,
825 struct iw_request_info *info,
826 struct iw_point *wrq,
827 char *extra)
829 PSDevice pDevice = (PSDevice)netdev_priv(dev);
830 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
831 PWLAN_IE_SSID pItemSSID;
832 //2008-0409-05, <Add> by Einsn Liu
833 unsigned char len;
836 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWESSID \n");
837 pDevice->fWPA_Authened = false;
838 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
839 // In scanning..
840 printk("SIOCSIWESSID(??)-->In scanning...\n");
841 // return -EAGAIN;
843 // Check if we asked for `any'
844 if(wrq->flags == 0) {
845 // Just send an empty SSID list
846 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
847 memset(pMgmt->abyDesireBSSID, 0xFF,6);
848 PRINT_K("set essid to 'any' \n");
849 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
850 //Unknown desired AP,so here need not associate??
851 //if(pDevice->bWPASuppWextEnabled == true) {
852 return 0;
853 // }
854 #endif
855 } else {
856 // Set the SSID
857 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
858 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
859 pItemSSID->byElementID = WLAN_EID_SSID;
861 memcpy(pItemSSID->abySSID, extra, wrq->length);
862 if (pItemSSID->abySSID[wrq->length - 1] == '\0') {
863 if(wrq->length>0)
864 pItemSSID->len = wrq->length - 1;
866 else
867 pItemSSID->len = wrq->length;
868 printk("set essid to %s \n",pItemSSID->abySSID);
869 //2008-0409-05, <Add> by Einsn Liu
870 len=(pItemSSID->len > ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len)?pItemSSID->len:((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len;
871 if((pDevice->bLinkPass == true) &&
872 (memcmp(pItemSSID->abySSID,((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,len)==0))
873 return 0;
875 //mike:need clear desiredBSSID
876 if(pItemSSID->len==0) {
877 memset(pMgmt->abyDesireBSSID, 0xFF,6);
878 return 0;
881 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
882 //Wext wil order another command of siwap to link with desired AP,
883 //so here need not associate??
884 if(pDevice->bWPASuppWextEnabled == true) {
885 /*******search if in hidden ssid mode ****/
887 PKnownBSS pCurr = NULL;
888 unsigned char abyTmpDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
889 unsigned int ii , uSameBssidNum=0;
891 memcpy(abyTmpDesireSSID,pMgmt->abyDesireSSID,sizeof(abyTmpDesireSSID));
892 pCurr = BSSpSearchBSSList(pDevice,
893 NULL,
894 abyTmpDesireSSID,
895 pMgmt->eConfigPHYMode
898 if (pCurr == NULL){
899 PRINT_K("SIOCSIWESSID:hidden ssid site survey before associate.......\n");
900 vResetCommandTimer((void *) pDevice);
901 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
902 bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
903 bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
905 else { //mike:to find out if that desired SSID is a hidden-ssid AP ,
906 // by means of judging if there are two same BSSID exist in list ?
907 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
908 if (pMgmt->sBSSList[ii].bActive &&
909 !compare_ether_addr(pMgmt->sBSSList[ii].abyBSSID, pCurr->abyBSSID)) {
910 uSameBssidNum++;
913 if(uSameBssidNum >= 2) { //hit: desired AP is in hidden ssid mode!!!
914 printk("SIOCSIWESSID:hidden ssid directly associate.......\n");
915 vResetCommandTimer((void *) pDevice);
916 pMgmt->eScanType = WMAC_SCAN_PASSIVE; //this scan type,you'll submit scan result!
917 bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
918 bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
922 return 0;
924 #endif
926 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set essid = %s \n", pItemSSID->abySSID);
929 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
930 pDevice->bCommit = true;
934 return 0;
939 * Wireless Handler : get essid
942 int iwctl_giwessid(struct net_device *dev,
943 struct iw_request_info *info,
944 struct iw_point *wrq,
945 char *extra)
948 PSDevice pDevice = (PSDevice)netdev_priv(dev);
949 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
950 PWLAN_IE_SSID pItemSSID;
952 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWESSID \n");
954 // Note : if wrq->u.data.flags != 0, we should
955 // get the relevant SSID from the SSID list...
957 // Get the current SSID
958 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
959 //pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
960 memcpy(extra, pItemSSID->abySSID , pItemSSID->len);
961 extra[pItemSSID->len] = '\0';
962 wrq->length = pItemSSID->len + 1;
963 //2008-0409-03, <Add> by Einsn Liu
964 wrq->length = pItemSSID->len;
965 wrq->flags = 1; // active
968 return 0;
972 * Wireless Handler : set data rate
975 int iwctl_siwrate(struct net_device *dev,
976 struct iw_request_info *info,
977 struct iw_param *wrq,
978 char *extra)
980 PSDevice pDevice = (PSDevice)netdev_priv(dev);
981 int rc = 0;
982 u8 brate = 0;
983 int i;
984 unsigned char abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
987 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRATE \n");
988 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
989 rc = -EINVAL;
990 return rc;
993 // First : get a valid bit rate value
995 // Which type of value
996 if((wrq->value < 13) &&
997 (wrq->value >= 0)) {
998 // Setting by rate index
999 // Find value in the magic rate table
1000 brate = wrq->value;
1001 } else {
1002 // Setting by frequency value
1003 u8 normvalue = (u8) (wrq->value/500000);
1005 // Check if rate is valid
1006 for(i = 0 ; i < 13 ; i++) {
1007 if(normvalue == abySupportedRates[i]) {
1008 brate = i;
1009 break;
1013 // -1 designed the max rate (mostly auto mode)
1014 if(wrq->value == -1) {
1015 // Get the highest available rate
1016 for(i = 0 ; i < 13 ; i++) {
1017 if(abySupportedRates[i] == 0)
1018 break;
1020 if(i != 0)
1021 brate = i - 1;
1024 // Check that it is valid
1025 // brate is index of abySupportedRates[]
1026 if(brate > 13 ) {
1027 rc = -EINVAL;
1028 return rc;
1031 // Now, check if we want a fixed or auto value
1032 if(wrq->fixed != 0) {
1033 // Fixed mode
1034 // One rate, fixed
1035 printk("Rate Fix\n");
1036 pDevice->bFixRate = true;
1037 if ((pDevice->byBBType == BB_TYPE_11B)&& (brate > 3)) {
1038 pDevice->uConnectionRate = 3;
1040 else {
1041 pDevice->uConnectionRate = brate;
1042 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fixed to Rate %d \n", pDevice->uConnectionRate);
1046 else {
1047 pDevice->bFixRate = false;
1048 pDevice->uConnectionRate = 13;
1049 printk("auto rate:connection_rate is 13\n");
1052 return rc;
1056 * Wireless Handler : get data rate
1059 int iwctl_giwrate(struct net_device *dev,
1060 struct iw_request_info *info,
1061 struct iw_param *wrq,
1062 char *extra)
1064 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1065 //2007-0118-05,<Mark> by EinsnLiu
1066 //Mark the unnecessary sentences.
1067 // PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1069 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRATE \n");
1071 unsigned char abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
1072 int brate = 0;
1073 //2008-5-8 <modify> by chester
1074 if(pDevice->bLinkPass){
1075 if(pDevice->bFixRate == true){
1076 if (pDevice->uConnectionRate < 13) {
1077 brate = abySupportedRates[pDevice->uConnectionRate];
1078 }else {
1079 if (pDevice->byBBType == BB_TYPE_11B)
1080 brate = 0x16;
1081 if (pDevice->byBBType == BB_TYPE_11G)
1082 brate = 0x6C;
1083 if (pDevice->byBBType == BB_TYPE_11A)
1084 brate = 0x6C;
1087 else
1090 brate = abySupportedRates[TxRate_iwconfig];
1093 else brate =0;
1094 //2007-0118-05,<Mark> by EinsnLiu
1095 //Mark the unnecessary sentences.
1097 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1098 if (pDevice->byBBType == BB_TYPE_11B)
1099 brate = 0x16;
1100 if (pDevice->byBBType == BB_TYPE_11G)
1101 brate = 0x6C;
1102 if (pDevice->byBBType == BB_TYPE_11A)
1103 brate = 0x6C;
1107 // if (pDevice->uConnectionRate == 13)
1108 // brate = abySupportedRates[pDevice->wCurrentRate];
1109 wrq->value = brate * 500000;
1110 // If more than one rate, set auto
1111 if (pDevice->bFixRate == true)
1112 wrq->fixed = true;
1116 return 0;
1122 * Wireless Handler : set rts threshold
1125 int iwctl_siwrts(struct net_device *dev,
1126 struct iw_request_info *info,
1127 struct iw_param *wrq,
1128 char *extra)
1130 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1131 int rc = 0;
1133 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRTS \n");
1136 int rthr = wrq->value;
1137 if(wrq->disabled)
1138 rthr = 2312;
1139 if((rthr < 0) || (rthr > 2312)) {
1140 rc = -EINVAL;
1141 }else {
1142 pDevice->wRTSThreshold = rthr;
1146 return 0;
1150 * Wireless Handler : get rts
1153 int iwctl_giwrts(struct net_device *dev,
1154 struct iw_request_info *info,
1155 struct iw_param *wrq,
1156 char *extra)
1158 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1160 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRTS \n");
1161 wrq->value = pDevice->wRTSThreshold;
1162 wrq->disabled = (wrq->value >= 2312);
1163 wrq->fixed = 1;
1165 return 0;
1169 * Wireless Handler : set fragment threshold
1172 int iwctl_siwfrag(struct net_device *dev,
1173 struct iw_request_info *info,
1174 struct iw_param *wrq,
1175 char *extra)
1177 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1178 int rc = 0;
1179 int fthr = wrq->value;
1182 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFRAG \n");
1185 if (wrq->disabled)
1186 fthr = 2312;
1187 if((fthr < 256) || (fthr > 2312)) {
1188 rc = -EINVAL;
1189 }else {
1190 fthr &= ~0x1; // Get an even value
1191 pDevice->wFragmentationThreshold = (u16)fthr;
1194 return rc;
1198 * Wireless Handler : get fragment threshold
1201 int iwctl_giwfrag(struct net_device *dev,
1202 struct iw_request_info *info,
1203 struct iw_param *wrq,
1204 char *extra)
1206 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1208 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFRAG \n");
1209 wrq->value = pDevice->wFragmentationThreshold;
1210 wrq->disabled = (wrq->value >= 2312);
1211 wrq->fixed = 1;
1213 return 0;
1219 * Wireless Handler : set retry threshold
1221 int iwctl_siwretry(struct net_device *dev,
1222 struct iw_request_info *info,
1223 struct iw_param *wrq,
1224 char *extra)
1226 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1227 int rc = 0;
1230 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRETRY \n");
1232 if (wrq->disabled) {
1233 rc = -EINVAL;
1234 return rc;
1237 if (wrq->flags & IW_RETRY_LIMIT) {
1238 if(wrq->flags & IW_RETRY_MAX)
1239 pDevice->byLongRetryLimit = wrq->value;
1240 else if (wrq->flags & IW_RETRY_MIN)
1241 pDevice->byShortRetryLimit = wrq->value;
1242 else {
1243 // No modifier : set both
1244 pDevice->byShortRetryLimit = wrq->value;
1245 pDevice->byLongRetryLimit = wrq->value;
1248 if (wrq->flags & IW_RETRY_LIFETIME) {
1249 pDevice->wMaxTransmitMSDULifetime = wrq->value;
1253 return rc;
1257 * Wireless Handler : get retry threshold
1259 int iwctl_giwretry(struct net_device *dev,
1260 struct iw_request_info *info,
1261 struct iw_param *wrq,
1262 char *extra)
1264 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1265 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRETRY \n");
1266 wrq->disabled = 0; // Can't be disabled
1268 // Note : by default, display the min retry number
1269 if((wrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1270 wrq->flags = IW_RETRY_LIFETIME;
1271 wrq->value = (int)pDevice->wMaxTransmitMSDULifetime; //ms
1272 } else if((wrq->flags & IW_RETRY_MAX)) {
1273 wrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
1274 wrq->value = (int)pDevice->byLongRetryLimit;
1275 } else {
1276 wrq->flags = IW_RETRY_LIMIT;
1277 wrq->value = (int)pDevice->byShortRetryLimit;
1278 if((int)pDevice->byShortRetryLimit != (int)pDevice->byLongRetryLimit)
1279 wrq->flags |= IW_RETRY_MIN;
1283 return 0;
1288 * Wireless Handler : set encode mode
1290 int iwctl_siwencode(struct net_device *dev,
1291 struct iw_request_info *info,
1292 struct iw_point *wrq,
1293 char *extra)
1295 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1296 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1297 unsigned long dwKeyIndex = (unsigned long)(wrq->flags & IW_ENCODE_INDEX);
1298 int ii,uu, rc = 0;
1299 int index = (wrq->flags & IW_ENCODE_INDEX);
1301 //2007-0207-07,<Modify> by EinsnLiu
1302 //There are some problems when using iwconfig encode/key command to set the WEP key.
1303 //I almost rewrite this function.
1304 //now it support:(assume the wireless interface's name is eth0)
1305 //iwconfig eth0 key [1] 1122334455 open /*set key stirng to index 1,and driver using key index is set to 1*/
1306 //iwconfig eth0 key [3] /*set driver using key index to 3,the key string no change */
1307 //iwconfig eth0 key 1122334455 /*set key string to driver using index*/
1308 //iwconfig eth0 key restricted /*enable share key*/
1310 PSKeyTable pkeytab;
1312 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODE \n");
1314 if((wrq->flags & IW_ENCODE_DISABLED)==0){
1315 //Not disable encryption
1317 if (dwKeyIndex > WLAN_WEP_NKEYS) {
1318 rc = -EINVAL;
1319 return rc;
1322 if(dwKeyIndex<1&&((wrq->flags&IW_ENCODE_NOKEY)==0)){//set default key
1323 if(pDevice->byKeyIndex<WLAN_WEP_NKEYS){
1324 dwKeyIndex=pDevice->byKeyIndex;
1326 else dwKeyIndex=0;
1327 }else dwKeyIndex--;
1330 // Check the size of the key
1331 if (wrq->length > WLAN_WEP232_KEYLEN) {
1332 rc = -EINVAL;
1333 return rc;
1336 if(wrq->length>0){//have key
1338 if (wrq->length == WLAN_WEP232_KEYLEN) {
1339 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 232 bit wep key\n");
1341 else if (wrq->length == WLAN_WEP104_KEYLEN) {
1342 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 104 bit wep key\n");
1344 else if (wrq->length == WLAN_WEP40_KEYLEN) {
1345 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 40 bit wep key, index= %d\n", (int)dwKeyIndex);
1346 }else {//no support length
1347 rc = -EINVAL;
1348 return rc;
1350 memset(pDevice->abyKey, 0, WLAN_WEP232_KEYLEN);
1351 memcpy(pDevice->abyKey, extra, wrq->length);
1353 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyKey: ");
1354 for (ii = 0; ii < wrq->length; ii++) {
1355 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pDevice->abyKey[ii]);
1358 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1359 spin_lock_irq(&pDevice->lock);
1360 KeybSetDefaultKey(&(pDevice->sKey),
1361 (unsigned long)(dwKeyIndex | (1 << 31)),
1362 wrq->length,
1363 NULL,
1364 pDevice->abyKey,
1365 KEY_CTL_WEP,
1366 pDevice->PortOffset,
1367 pDevice->byLocalID
1369 spin_unlock_irq(&pDevice->lock);
1371 pDevice->byKeyIndex = (unsigned char)dwKeyIndex;
1372 pDevice->uKeyLength = wrq->length;
1373 pDevice->bTransmitKey = true;
1374 pDevice->bEncryptionEnable = true;
1375 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1377 }else if(index>0){
1378 //when the length is 0 the request only changes the default transmit key index
1379 //check the new key has a non zero lenget
1380 if(pDevice->bEncryptionEnable==false)
1382 rc = -EINVAL;
1383 return rc;
1385 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Just set Default key Index:\n");
1386 pkeytab=&(pDevice->sKey.KeyTable[MAX_KEY_TABLE-1]);
1387 if(pkeytab->GroupKey[(unsigned char)dwKeyIndex].uKeyLength==0){
1388 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Default key len is 0\n");
1389 rc = -EINVAL;
1390 return rc;
1392 pDevice->byKeyIndex =(unsigned char)dwKeyIndex;
1393 pkeytab->dwGTKeyIndex =dwKeyIndex | (1 << 31);
1394 pkeytab->GroupKey[(unsigned char)dwKeyIndex].dwKeyIndex=dwKeyIndex | (1 << 31);
1397 }else {//disable the key
1398 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable WEP function\n");
1399 if(pDevice->bEncryptionEnable==false)
1400 return 0;
1401 pMgmt->bShareKeyAlgorithm = false;
1402 pDevice->bEncryptionEnable = false;
1403 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1404 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1405 spin_lock_irq(&pDevice->lock);
1406 for(uu=0;uu<MAX_KEY_TABLE;uu++)
1407 MACvDisableKeyEntry(pDevice->PortOffset, uu);
1408 spin_unlock_irq(&pDevice->lock);
1411 //End Modify,Einsn
1414 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODE \n");
1416 // Check the size of the key
1417 if (wrq->length > WLAN_WEP232_KEYLEN) {
1418 rc = -EINVAL;
1419 return rc;
1422 if (dwKeyIndex > WLAN_WEP_NKEYS) {
1423 rc = -EINVAL;
1424 return rc;
1427 if (dwKeyIndex > 0)
1428 dwKeyIndex--;
1430 // Send the key to the card
1431 if (wrq->length > 0) {
1433 if (wrq->length == WLAN_WEP232_KEYLEN) {
1434 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 232 bit wep key\n");
1436 else if (wrq->length == WLAN_WEP104_KEYLEN) {
1437 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 104 bit wep key\n");
1439 else if (wrq->length == WLAN_WEP40_KEYLEN) {
1440 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 40 bit wep key, index= %d\n", (int)dwKeyIndex);
1442 memset(pDevice->abyKey, 0, WLAN_WEP232_KEYLEN);
1443 memcpy(pDevice->abyKey, extra, wrq->length);
1445 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyKey: ");
1446 for (ii = 0; ii < wrq->length; ii++) {
1447 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pDevice->abyKey[ii]);
1450 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1451 spin_lock_irq(&pDevice->lock);
1452 KeybSetDefaultKey(&(pDevice->sKey),
1453 (unsigned long)(pDevice->byKeyIndex | (1 << 31)),
1454 pDevice->uKeyLength,
1455 NULL,
1456 pDevice->abyKey,
1457 KEY_CTL_WEP,
1458 pDevice->PortOffset,
1459 pDevice->byLocalID
1461 spin_unlock_irq(&pDevice->lock);
1463 pDevice->byKeyIndex = (unsigned char)dwKeyIndex;
1464 pDevice->uKeyLength = wrq->length;
1465 pDevice->bTransmitKey = true;
1466 pDevice->bEncryptionEnable = true;
1467 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1469 // Do we want to just set the transmit key index ?
1470 if ( index < 4 ) {
1471 pDevice->byKeyIndex = index;
1473 else if(!(wrq->flags & IW_ENCODE_MODE)) {
1474 rc = -EINVAL;
1475 return rc;
1478 // Read the flags
1479 if(wrq->flags & IW_ENCODE_DISABLED){
1481 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable WEP function\n");
1482 pMgmt->bShareKeyAlgorithm = false;
1483 pDevice->bEncryptionEnable = false;
1484 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1485 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1486 spin_lock_irq(&pDevice->lock);
1487 for(uu=0;uu<MAX_KEY_TABLE;uu++)
1488 MACvDisableKeyEntry(pDevice->PortOffset, uu);
1489 spin_unlock_irq(&pDevice->lock);
1494 if(wrq->flags & IW_ENCODE_RESTRICTED) {
1495 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & ShareKey System\n");
1496 pMgmt->bShareKeyAlgorithm = true;
1498 if(wrq->flags & IW_ENCODE_OPEN) {
1499 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & Open System\n");
1500 pMgmt->bShareKeyAlgorithm = false;
1502 return rc;
1506 * Wireless Handler : get encode mode
1509 int iwctl_giwencode(struct net_device *dev,
1510 struct iw_request_info *info,
1511 struct iw_point *wrq,
1512 char *extra)
1514 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1515 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1516 int rc = 0;
1517 char abyKey[WLAN_WEP232_KEYLEN];
1518 unsigned int index = (unsigned int)(wrq->flags & IW_ENCODE_INDEX);
1519 PSKeyItem pKey = NULL;
1521 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODE\n");
1522 //2007-0207-06,<Add> by EinsnLiu
1523 //the key index in iwconfig is 1-4 when our driver is 0-3
1524 //so it can't be used directly.
1525 //if the index is 0,we should used the index set by driver.
1526 if (index > WLAN_WEP_NKEYS) {
1527 rc = -EINVAL;
1528 return rc;
1530 if(index<1){//set default key
1531 if(pDevice->byKeyIndex<WLAN_WEP_NKEYS){
1532 index=pDevice->byKeyIndex;
1534 else index=0;
1535 }else index--;
1536 //End Add,Einsn
1538 memset(abyKey, 0, sizeof(abyKey));
1539 // Check encryption mode
1540 wrq->flags = IW_ENCODE_NOKEY;
1541 // Is WEP enabled ???
1542 if (pDevice->bEncryptionEnable)
1543 wrq->flags |= IW_ENCODE_ENABLED;
1544 else
1545 wrq->flags |= IW_ENCODE_DISABLED;
1547 if (pMgmt->bShareKeyAlgorithm)
1548 wrq->flags |= IW_ENCODE_RESTRICTED;
1549 else
1550 wrq->flags |= IW_ENCODE_OPEN;
1552 if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (unsigned char)index , &pKey)){
1553 wrq->length = pKey->uKeyLength;
1554 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1555 //2007-0207-06,<Modify> by EinsnLiu
1556 //only get key success need to copy data
1557 //index should +1.
1558 //there is not necessary to return -EINVAL when get key failed
1559 //if return -EINVAL,the encryption item can't be display by the command "iwconfig".
1560 wrq->flags |= index+1;
1561 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1564 //else {
1565 // rc = -EINVAL;
1566 // return rc;
1567 // }
1570 //End Modify,Einsn
1572 return 0;
1576 //2008-0409-06, <Add> by Einsn Liu
1578 int iwctl_giwencode(struct net_device *dev,
1579 struct iw_request_info *info,
1580 struct iw_point *wrq,
1581 char *extra)
1583 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1584 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1585 char abyKey[WLAN_WEP232_KEYLEN];
1587 unsigned int index = (unsigned int)(wrq->flags & IW_ENCODE_INDEX);
1588 PSKeyItem pKey = NULL;
1590 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODE\n");
1592 if (index > WLAN_WEP_NKEYS) {
1593 return -EINVAL;
1595 if(index<1){//get default key
1596 if(pDevice->byKeyIndex<WLAN_WEP_NKEYS){
1597 index=pDevice->byKeyIndex;
1598 } else
1599 index=0;
1600 }else
1601 index--;
1603 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
1604 // Check encryption mode
1605 wrq->flags = IW_ENCODE_NOKEY;
1606 // Is WEP enabled ???
1607 if (pDevice->bEncryptionEnable)
1608 wrq->flags |= IW_ENCODE_ENABLED;
1609 else
1610 wrq->flags |= IW_ENCODE_DISABLED;
1612 if (pMgmt->bShareKeyAlgorithm)
1613 wrq->flags |= IW_ENCODE_RESTRICTED;
1614 else
1615 wrq->flags |= IW_ENCODE_OPEN;
1616 wrq->length=0;
1618 if((index==0)&&(pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled||
1619 pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)){//get wpa pairwise key
1620 if (KeybGetKey(&(pDevice->sKey),pMgmt->abyCurrBSSID, 0xffffffff, &pKey)){
1621 wrq->length = pKey->uKeyLength;
1622 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1623 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1625 }else if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (unsigned char)index , &pKey)){
1626 wrq->length = pKey->uKeyLength;
1627 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1628 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1631 wrq->flags |= index+1;
1633 return 0;
1638 * Wireless Handler : set power mode
1640 int iwctl_siwpower(struct net_device *dev,
1641 struct iw_request_info *info,
1642 struct iw_param *wrq,
1643 char *extra)
1645 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1646 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1647 int rc = 0;
1649 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER \n");
1651 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
1652 rc = -EINVAL;
1653 return rc;
1656 if (wrq->disabled) {
1657 pDevice->ePSMode = WMAC_POWER_CAM;
1658 PSvDisablePowerSaving(pDevice);
1659 return rc;
1661 if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1662 pDevice->ePSMode = WMAC_POWER_FAST;
1663 PSvEnablePowerSaving((void *)pDevice, pMgmt->wListenInterval);
1665 } else if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
1666 pDevice->ePSMode = WMAC_POWER_FAST;
1667 PSvEnablePowerSaving((void *)pDevice, pMgmt->wListenInterval);
1669 switch (wrq->flags & IW_POWER_MODE) {
1670 case IW_POWER_UNICAST_R:
1671 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_UNICAST_R \n");
1672 rc = -EINVAL;
1673 break;
1674 case IW_POWER_ALL_R:
1675 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ALL_R \n");
1676 rc = -EINVAL;
1677 case IW_POWER_ON:
1678 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ON \n");
1679 break;
1680 default:
1681 rc = -EINVAL;
1684 return rc;
1688 * Wireless Handler : get power mode
1690 int iwctl_giwpower(struct net_device *dev,
1691 struct iw_request_info *info,
1692 struct iw_param *wrq,
1693 char *extra)
1695 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1696 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1697 int mode = pDevice->ePSMode;
1700 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPOWER \n");
1703 wrq->disabled = (mode == WMAC_POWER_CAM);
1704 if (wrq->disabled)
1705 return 0;
1707 if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1708 wrq->value = (int)((pMgmt->wListenInterval * pMgmt->wCurrBeaconPeriod) << 10);
1709 wrq->flags = IW_POWER_TIMEOUT;
1710 } else {
1711 wrq->value = (int)((pMgmt->wListenInterval * pMgmt->wCurrBeaconPeriod) << 10);
1712 wrq->flags = IW_POWER_PERIOD;
1714 wrq->flags |= IW_POWER_ALL_R;
1716 return 0;
1721 * Wireless Handler : get Sensitivity
1723 int iwctl_giwsens(struct net_device *dev,
1724 struct iw_request_info *info,
1725 struct iw_param *wrq,
1726 char *extra)
1728 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1729 long ldBm;
1731 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSENS \n");
1732 if (pDevice->bLinkPass == true) {
1733 RFvRSSITodBm(pDevice, (unsigned char)(pDevice->uCurrRSSI), &ldBm);
1734 wrq->value = ldBm;
1736 else {
1737 wrq->value = 0;
1739 wrq->disabled = (wrq->value == 0);
1740 wrq->fixed = 1;
1743 return 0;
1746 //2008-0409-07, <Add> by Einsn Liu
1747 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1749 int iwctl_siwauth(struct net_device *dev,
1750 struct iw_request_info *info,
1751 struct iw_param *wrq,
1752 char *extra)
1754 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1755 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1756 int ret=0;
1757 static int wpa_version=0; //must be static to save the last value,einsn liu
1758 static int pairwise=0;
1760 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH \n");
1761 switch (wrq->flags & IW_AUTH_INDEX) {
1762 case IW_AUTH_WPA_VERSION:
1763 wpa_version = wrq->value;
1764 if(wrq->value == IW_AUTH_WPA_VERSION_DISABLED) {
1765 PRINT_K("iwctl_siwauth:set WPADEV to disable at 1??????\n");
1766 //pDevice->bWPADevEnable = false;
1768 else if(wrq->value == IW_AUTH_WPA_VERSION_WPA) {
1769 PRINT_K("iwctl_siwauth:set WPADEV to WPA1******\n");
1771 else {
1772 PRINT_K("iwctl_siwauth:set WPADEV to WPA2******\n");
1774 //pDevice->bWPASuppWextEnabled =true;
1775 break;
1776 case IW_AUTH_CIPHER_PAIRWISE:
1777 pairwise = wrq->value;
1778 if(pairwise == IW_AUTH_CIPHER_CCMP){
1779 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1780 }else if(pairwise == IW_AUTH_CIPHER_TKIP){
1781 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1782 }else if(pairwise == IW_AUTH_CIPHER_WEP40||pairwise == IW_AUTH_CIPHER_WEP104){
1783 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1784 }else if(pairwise == IW_AUTH_CIPHER_NONE){
1785 //do nothing,einsn liu
1786 }else pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1788 break;
1789 case IW_AUTH_CIPHER_GROUP:
1790 if(wpa_version == IW_AUTH_WPA_VERSION_DISABLED)
1791 break;
1792 if(pairwise == IW_AUTH_CIPHER_NONE){
1793 if(wrq->value == IW_AUTH_CIPHER_CCMP){
1794 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1795 }else {
1796 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1799 break;
1800 case IW_AUTH_KEY_MGMT:
1802 if(wpa_version == IW_AUTH_WPA_VERSION_WPA2){
1803 if(wrq->value == IW_AUTH_KEY_MGMT_PSK)
1804 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
1805 else pMgmt->eAuthenMode = WMAC_AUTH_WPA2;
1806 }else if(wpa_version == IW_AUTH_WPA_VERSION_WPA){
1807 if(wrq->value == 0){
1808 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
1809 }else if(wrq->value == IW_AUTH_KEY_MGMT_PSK)
1810 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
1811 else pMgmt->eAuthenMode = WMAC_AUTH_WPA;
1814 break;
1815 case IW_AUTH_TKIP_COUNTERMEASURES:
1816 break; /* FIXME */
1817 case IW_AUTH_DROP_UNENCRYPTED:
1818 break;
1819 case IW_AUTH_80211_AUTH_ALG:
1820 if(wrq->value==IW_AUTH_ALG_OPEN_SYSTEM){
1821 pMgmt->bShareKeyAlgorithm=false;
1822 }else if(wrq->value==IW_AUTH_ALG_SHARED_KEY){
1823 pMgmt->bShareKeyAlgorithm=true;
1825 break;
1826 case IW_AUTH_WPA_ENABLED:
1827 //pDevice->bWPADevEnable = !! wrq->value;
1828 break;
1829 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1830 break;
1831 case IW_AUTH_ROAMING_CONTROL:
1832 ret = -EOPNOTSUPP;
1833 break;
1834 case IW_AUTH_PRIVACY_INVOKED:
1835 pDevice->bEncryptionEnable = !!wrq->value;
1836 if(pDevice->bEncryptionEnable == false){
1837 wpa_version = 0;
1838 pairwise = 0;
1839 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1840 pMgmt->bShareKeyAlgorithm = false;
1841 pMgmt->eAuthenMode = false;
1842 //pDevice->bWPADevEnable = false;
1845 break;
1846 default:
1847 ret = -EOPNOTSUPP;
1848 break;
1851 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_version = %d\n",wpa_version);
1852 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pairwise = %d\n",pairwise);
1853 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->eEncryptionStatus = %d\n",pDevice->eEncryptionStatus);
1854 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->eAuthenMode = %d\n",pMgmt->eAuthenMode);
1855 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->bShareKeyAlgorithm = %s\n",pMgmt->bShareKeyAlgorithm?"true":"false");
1856 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->bEncryptionEnable = %s\n",pDevice->bEncryptionEnable?"true":"false");
1857 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->bWPADevEnable = %s\n",pDevice->bWPADevEnable?"true":"false");
1859 return ret;
1863 int iwctl_giwauth(struct net_device *dev,
1864 struct iw_request_info *info,
1865 struct iw_param *wrq,
1866 char *extra)
1868 return -EOPNOTSUPP;
1873 int iwctl_siwgenie(struct net_device *dev,
1874 struct iw_request_info *info,
1875 struct iw_point *wrq,
1876 char *extra)
1878 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1879 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1880 int ret=0;
1882 if(wrq->length){
1883 if ((wrq->length < 2) || (extra[1]+2 != wrq->length)) {
1884 ret = -EINVAL;
1885 goto out;
1887 if(wrq->length > MAX_WPA_IE_LEN){
1888 ret = -ENOMEM;
1889 goto out;
1891 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
1892 if(copy_from_user(pMgmt->abyWPAIE, extra, wrq->length)){
1893 ret = -EFAULT;
1894 goto out;
1896 pMgmt->wWPAIELen = wrq->length;
1897 }else {
1898 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
1899 pMgmt->wWPAIELen = 0;
1902 out://not completely ...not necessary in wpa_supplicant 0.5.8
1903 return ret;
1906 int iwctl_giwgenie(struct net_device *dev,
1907 struct iw_request_info *info,
1908 struct iw_point *wrq,
1909 char *extra)
1911 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1912 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1913 int ret=0;
1914 int space = wrq->length;
1916 wrq->length = 0;
1917 if(pMgmt->wWPAIELen > 0){
1918 wrq->length = pMgmt->wWPAIELen;
1919 if(pMgmt->wWPAIELen <= space){
1920 if(copy_to_user(extra, pMgmt->abyWPAIE, pMgmt->wWPAIELen)){
1921 ret = -EFAULT;
1923 }else
1924 ret = -E2BIG;
1927 return ret;
1931 int iwctl_siwencodeext(struct net_device *dev,
1932 struct iw_request_info *info,
1933 struct iw_point *wrq,
1934 char *extra)
1936 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1937 struct iw_encode_ext *ext = (struct iw_encode_ext*)extra;
1938 struct viawget_wpa_param *param=NULL;
1939 //original member
1940 wpa_alg alg_name;
1941 u8 addr[6];
1942 int key_idx, set_tx=0;
1943 u8 seq[IW_ENCODE_SEQ_MAX_SIZE];
1944 u8 key[64];
1945 size_t seq_len=0,key_len=0;
1947 // int ii;
1948 u8 *buf;
1949 size_t blen;
1950 u8 key_array[64];
1951 int ret=0;
1953 PRINT_K("SIOCSIWENCODEEXT...... \n");
1955 blen = sizeof(*param);
1956 buf = kmalloc((int)blen, (int)GFP_KERNEL);
1957 if (buf == NULL)
1958 return -ENOMEM;
1959 memset(buf, 0, blen);
1960 param = (struct viawget_wpa_param *) buf;
1962 //recover alg_name
1963 switch (ext->alg) {
1964 case IW_ENCODE_ALG_NONE:
1965 alg_name = WPA_ALG_NONE;
1966 break;
1967 case IW_ENCODE_ALG_WEP:
1968 alg_name = WPA_ALG_WEP;
1969 break;
1970 case IW_ENCODE_ALG_TKIP:
1971 alg_name = WPA_ALG_TKIP;
1972 break;
1973 case IW_ENCODE_ALG_CCMP:
1974 alg_name = WPA_ALG_CCMP;
1975 break;
1976 default:
1977 PRINT_K("Unknown alg = %d\n",ext->alg);
1978 ret= -ENOMEM;
1979 goto error;
1981 //recover addr
1982 memcpy(addr, ext->addr.sa_data, ETH_ALEN);
1983 //recover key_idx
1984 key_idx = (wrq->flags&IW_ENCODE_INDEX) - 1;
1985 //recover set_tx
1986 if(ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
1987 set_tx = 1;
1988 //recover seq,seq_len
1989 if(ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
1990 seq_len=IW_ENCODE_SEQ_MAX_SIZE;
1991 memcpy(seq, ext->rx_seq, seq_len);
1993 //recover key,key_len
1994 if(ext->key_len) {
1995 key_len=ext->key_len;
1996 memcpy(key, &ext->key[0], key_len);
1999 memset(key_array, 0, 64);
2000 if ( key_len > 0) {
2001 memcpy(key_array, key, key_len);
2002 if (key_len == 32) {
2003 // notice ! the oder
2004 memcpy(&key_array[16], &key[24], 8);
2005 memcpy(&key_array[24], &key[16], 8);
2009 /**************Translate iw_encode_ext to viawget_wpa_param****************/
2010 memcpy(param->addr, addr, ETH_ALEN);
2011 param->u.wpa_key.alg_name = (int)alg_name;
2012 param->u.wpa_key.set_tx = set_tx;
2013 param->u.wpa_key.key_index = key_idx;
2014 param->u.wpa_key.key_len = key_len;
2015 param->u.wpa_key.key = (u8 *)key_array;
2016 param->u.wpa_key.seq = (u8 *)seq;
2017 param->u.wpa_key.seq_len = seq_len;
2019 #if 0
2020 printk("param->u.wpa_key.alg_name =%d\n",param->u.wpa_key.alg_name);
2021 printk(KERN_DEBUG "param->addr=%pM\n", param->addr);
2022 printk("param->u.wpa_key.set_tx =%d\n",param->u.wpa_key.set_tx);
2023 printk("param->u.wpa_key.key_index =%d\n",param->u.wpa_key.key_index);
2024 printk("param->u.wpa_key.key_len =%d\n",param->u.wpa_key.key_len);
2025 printk("param->u.wpa_key.key =");
2026 for(ii=0;ii<param->u.wpa_key.key_len;ii++)
2027 printk("%02x:",param->u.wpa_key.key[ii]);
2028 printk("\n");
2029 printk("param->u.wpa_key.seq_len =%d\n",param->u.wpa_key.seq_len);
2030 printk("param->u.wpa_key.seq =");
2031 for(ii=0;ii<param->u.wpa_key.seq_len;ii++)
2032 printk("%02x:",param->u.wpa_key.seq[ii]);
2033 printk("\n");
2035 printk("...........\n");
2036 #endif
2037 //****set if current action is Network Manager count??
2038 //****this method is so foolish,but there is no other way???
2039 if(param->u.wpa_key.alg_name == WPA_ALG_NONE) {
2040 if(param->u.wpa_key.key_index ==0) {
2041 pDevice->bwextcount++;
2043 if((pDevice->bwextcount == 1)&&(param->u.wpa_key.key_index ==1)) {
2044 pDevice->bwextcount++;
2046 if((pDevice->bwextcount ==2)&&(param->u.wpa_key.key_index ==2)) {
2047 pDevice->bwextcount++;
2049 if((pDevice->bwextcount ==3)&&(param->u.wpa_key.key_index ==3)) {
2050 pDevice->bwextcount++;
2053 if( pDevice->bwextcount == 4) {
2054 printk("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n");
2055 pDevice->bwextcount=0;
2056 pDevice->bWPASuppWextEnabled = true;
2058 //******
2060 spin_lock_irq(&pDevice->lock);
2061 ret = wpa_set_keys(pDevice, param, true);
2062 spin_unlock_irq(&pDevice->lock);
2064 error:
2065 kfree(param);
2066 return ret;
2071 int iwctl_giwencodeext(struct net_device *dev,
2072 struct iw_request_info *info,
2073 struct iw_point *wrq,
2074 char *extra)
2076 return -EOPNOTSUPP;
2079 int iwctl_siwmlme(struct net_device *dev,
2080 struct iw_request_info * info,
2081 struct iw_point *wrq,
2082 char *extra)
2084 PSDevice pDevice = (PSDevice)netdev_priv(dev);
2085 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
2086 struct iw_mlme *mlme = (struct iw_mlme *)extra;
2087 //u16 reason = cpu_to_le16(mlme->reason_code);
2088 int ret = 0;
2090 if(memcmp(pMgmt->abyCurrBSSID, mlme->addr.sa_data, ETH_ALEN)){
2091 ret = -EINVAL;
2092 return ret;
2094 switch(mlme->cmd){
2095 case IW_MLME_DEAUTH:
2096 //this command seems to be not complete,please test it --einsnliu
2097 //bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (unsigned char *)&reason);
2098 break;
2099 case IW_MLME_DISASSOC:
2100 if(pDevice->bLinkPass == true){
2101 printk("iwctl_siwmlme--->send DISASSOCIATE\n");
2102 //clear related flags
2103 memset(pMgmt->abyDesireBSSID, 0xFF,6);
2104 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
2105 bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
2107 break;
2108 default:
2109 ret = -EOPNOTSUPP;
2112 return ret;
2116 #endif
2119 /*------------------------------------------------------------------*/
2121 * Structures to export the Wireless Handlers
2126 static const iw_handler iwctl_handler[] =
2128 (iw_handler) iwctl_commit, // SIOCSIWCOMMIT
2129 (iw_handler) iwctl_giwname, // SIOCGIWNAME
2130 (iw_handler) NULL, // SIOCSIWNWID
2131 (iw_handler) NULL, // SIOCGIWNWID
2132 (iw_handler) iwctl_siwfreq, // SIOCSIWFREQ
2133 (iw_handler) iwctl_giwfreq, // SIOCGIWFREQ
2134 (iw_handler) iwctl_siwmode, // SIOCSIWMODE
2135 (iw_handler) iwctl_giwmode, // SIOCGIWMODE
2136 (iw_handler) NULL, // SIOCSIWSENS
2137 (iw_handler) iwctl_giwsens, // SIOCGIWSENS
2138 (iw_handler) NULL, // SIOCSIWRANGE
2139 (iw_handler) iwctl_giwrange, // SIOCGIWRANGE
2140 (iw_handler) NULL, // SIOCSIWPRIV
2141 (iw_handler) NULL, // SIOCGIWPRIV
2142 (iw_handler) NULL, // SIOCSIWSTATS
2143 (iw_handler) NULL, // SIOCGIWSTATS
2144 (iw_handler) NULL, // SIOCSIWSPY
2145 (iw_handler) NULL, // SIOCGIWSPY
2146 (iw_handler) NULL, // -- hole --
2147 (iw_handler) NULL, // -- hole --
2148 (iw_handler) iwctl_siwap, // SIOCSIWAP
2149 (iw_handler) iwctl_giwap, // SIOCGIWAP
2150 (iw_handler) NULL, // -- hole -- 0x16
2151 (iw_handler) iwctl_giwaplist, // SIOCGIWAPLIST
2152 (iw_handler) iwctl_siwscan, // SIOCSIWSCAN
2153 (iw_handler) iwctl_giwscan, // SIOCGIWSCAN
2154 (iw_handler) iwctl_siwessid, // SIOCSIWESSID
2155 (iw_handler) iwctl_giwessid, // SIOCGIWESSID
2156 (iw_handler) NULL, // SIOCSIWNICKN
2157 (iw_handler) NULL, // SIOCGIWNICKN
2158 (iw_handler) NULL, // -- hole --
2159 (iw_handler) NULL, // -- hole --
2160 (iw_handler) iwctl_siwrate, // SIOCSIWRATE 0x20
2161 (iw_handler) iwctl_giwrate, // SIOCGIWRATE
2162 (iw_handler) iwctl_siwrts, // SIOCSIWRTS
2163 (iw_handler) iwctl_giwrts, // SIOCGIWRTS
2164 (iw_handler) iwctl_siwfrag, // SIOCSIWFRAG
2165 (iw_handler) iwctl_giwfrag, // SIOCGIWFRAG
2166 (iw_handler) NULL, // SIOCSIWTXPOW
2167 (iw_handler) NULL, // SIOCGIWTXPOW
2168 (iw_handler) iwctl_siwretry, // SIOCSIWRETRY
2169 (iw_handler) iwctl_giwretry, // SIOCGIWRETRY
2170 (iw_handler) iwctl_siwencode, // SIOCSIWENCODE
2171 (iw_handler) iwctl_giwencode, // SIOCGIWENCODE
2172 (iw_handler) iwctl_siwpower, // SIOCSIWPOWER
2173 (iw_handler) iwctl_giwpower, // SIOCGIWPOWER
2174 (iw_handler) NULL, // -- hole --
2175 (iw_handler) NULL, // -- hole --
2176 (iw_handler) iwctl_siwgenie, // SIOCSIWGENIE
2177 (iw_handler) iwctl_giwgenie, // SIOCGIWGENIE
2178 (iw_handler) iwctl_siwauth, // SIOCSIWAUTH
2179 (iw_handler) iwctl_giwauth, // SIOCGIWAUTH
2180 (iw_handler) iwctl_siwencodeext, // SIOCSIWENCODEEXT
2181 (iw_handler) iwctl_giwencodeext, // SIOCGIWENCODEEXT
2182 (iw_handler) NULL, // SIOCSIWPMKSA
2183 (iw_handler) NULL, // -- hole --
2188 static const iw_handler iwctl_handler[] =
2190 (iw_handler) iwctl_commit, // SIOCSIWCOMMIT
2191 (iw_handler) NULL, // SIOCGIWNAME
2192 (iw_handler) NULL, // SIOCSIWNWID
2193 (iw_handler) NULL, // SIOCGIWNWID
2194 (iw_handler) NULL, // SIOCSIWFREQ
2195 (iw_handler) NULL, // SIOCGIWFREQ
2196 (iw_handler) NULL, // SIOCSIWMODE
2197 (iw_handler) NULL, // SIOCGIWMODE
2198 (iw_handler) NULL, // SIOCSIWSENS
2199 (iw_handler) NULL, // SIOCGIWSENS
2200 (iw_handler) NULL, // SIOCSIWRANGE
2201 (iw_handler) iwctl_giwrange, // SIOCGIWRANGE
2202 (iw_handler) NULL, // SIOCSIWPRIV
2203 (iw_handler) NULL, // SIOCGIWPRIV
2204 (iw_handler) NULL, // SIOCSIWSTATS
2205 (iw_handler) NULL, // SIOCGIWSTATS
2206 (iw_handler) NULL, // SIOCSIWSPY
2207 (iw_handler) NULL, // SIOCGIWSPY
2208 (iw_handler) NULL, // -- hole --
2209 (iw_handler) NULL, // -- hole --
2210 (iw_handler) NULL, // SIOCSIWAP
2211 (iw_handler) NULL, // SIOCGIWAP
2212 (iw_handler) NULL, // -- hole -- 0x16
2213 (iw_handler) NULL, // SIOCGIWAPLIST
2214 (iw_handler) iwctl_siwscan, // SIOCSIWSCAN
2215 (iw_handler) iwctl_giwscan, // SIOCGIWSCAN
2216 (iw_handler) NULL, // SIOCSIWESSID
2217 (iw_handler) NULL, // SIOCGIWESSID
2218 (iw_handler) NULL, // SIOCSIWNICKN
2219 (iw_handler) NULL, // SIOCGIWNICKN
2220 (iw_handler) NULL, // -- hole --
2221 (iw_handler) NULL, // -- hole --
2222 (iw_handler) NULL, // SIOCSIWRATE 0x20
2223 (iw_handler) NULL, // SIOCGIWRATE
2224 (iw_handler) NULL, // SIOCSIWRTS
2225 (iw_handler) NULL, // SIOCGIWRTS
2226 (iw_handler) NULL, // SIOCSIWFRAG
2227 (iw_handler) NULL, // SIOCGIWFRAG
2228 (iw_handler) NULL, // SIOCSIWTXPOW
2229 (iw_handler) NULL, // SIOCGIWTXPOW
2230 (iw_handler) NULL, // SIOCSIWRETRY
2231 (iw_handler) NULL, // SIOCGIWRETRY
2232 (iw_handler) NULL, // SIOCSIWENCODE
2233 (iw_handler) NULL, // SIOCGIWENCODE
2234 (iw_handler) NULL, // SIOCSIWPOWER
2235 (iw_handler) NULL, // SIOCGIWPOWER
2237 //2008-0409-07, <Add> by Einsn Liu
2238 (iw_handler) NULL, // -- hole --
2239 (iw_handler) NULL, // -- hole --
2240 (iw_handler) NULL, // SIOCSIWGENIE
2241 (iw_handler) NULL, // SIOCGIWGENIE
2242 (iw_handler) NULL, // SIOCSIWAUTH
2243 (iw_handler) NULL, // SIOCGIWAUTH
2244 (iw_handler) NULL, // SIOCSIWENCODEEXT
2245 (iw_handler) NULL, // SIOCGIWENCODEEXT
2246 (iw_handler) NULL, // SIOCSIWPMKSA
2247 (iw_handler) NULL, // -- hole --
2251 static const iw_handler iwctl_private_handler[] =
2253 NULL, // SIOCIWFIRSTPRIV
2257 struct iw_priv_args iwctl_private_args[] = {
2258 { IOCTL_CMD_SET,
2259 IW_PRIV_TYPE_CHAR | 1024, 0,
2260 "set"},
2265 const struct iw_handler_def iwctl_handler_def =
2267 .get_wireless_stats = &iwctl_get_wireless_stats,
2268 .num_standard = sizeof(iwctl_handler)/sizeof(iw_handler),
2269 // .num_private = sizeof(iwctl_private_handler)/sizeof(iw_handler),
2270 // .num_private_args = sizeof(iwctl_private_args)/sizeof(struct iw_priv_args),
2271 .num_private = 0,
2272 .num_private_args = 0,
2273 .standard = (iw_handler *) iwctl_handler,
2274 // .private = (iw_handler *) iwctl_private_handler,
2275 // .private_args = (struct iw_priv_args *)iwctl_private_args,
2276 .private = NULL,
2277 .private_args = NULL,