2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
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.
21 * Purpose: wireless ext & ioctl functions
43 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
48 #include <net/iw_handler.h>
49 extern unsigned short 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
57 #define SUPPORTED_WIRELESS_EXT 17
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
68 /*--------------------- Static Classes ----------------------------*/
69 /*--------------------- Static Variables --------------------------*/
70 /*--------------------- Static Functions --------------------------*/
72 /*--------------------- Export Variables --------------------------*/
74 struct iw_statistics *iwctl_get_wireless_stats(struct net_device *dev)
76 struct vnt_private *pDevice = netdev_priv(dev);
79 pDevice->wstats.status = pDevice->op_mode;
81 if (pDevice->scStatistic.LinkQuality > 100)
82 pDevice->scStatistic.LinkQuality = 100;
83 pDevice->wstats.qual.qual = (unsigned char)pDevice->scStatistic.LinkQuality;
85 pDevice->wstats.qual.qual = pDevice->byCurrSQ;
87 RFvRSSITodBm(pDevice, (unsigned char)(pDevice->uCurrRSSI), &ldBm);
88 pDevice->wstats.qual.level = ldBm;
89 pDevice->wstats.qual.noise = 0;
90 pDevice->wstats.qual.updated = 1;
91 pDevice->wstats.discard.nwid = 0;
92 pDevice->wstats.discard.code = 0;
93 pDevice->wstats.discard.fragment = 0;
94 pDevice->wstats.discard.retries = (unsigned long)pDevice->scStatistic.dwTsrErr;
95 pDevice->wstats.discard.misc = 0;
96 pDevice->wstats.miss.beacon = 0;
98 return &pDevice->wstats;
101 /*------------------------------------------------------------------*/
103 static int iwctl_commit(struct net_device *dev,
104 struct iw_request_info *info,
108 pr_debug(" SIOCSIWCOMMIT\n");
113 * Wireless Handler : get protocol name
116 int iwctl_giwname(struct net_device *dev,
117 struct iw_request_info *info,
121 strcpy(wrq, "802.11-a/b/g");
126 * Wireless Handler : set scan
129 static int iwctl_siwscan(struct net_device *dev,
130 struct iw_request_info *info,
131 struct iw_point *wrq,
134 struct vnt_private *pDevice = netdev_priv(dev);
135 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
136 struct iw_scan_req *req = (struct iw_scan_req *)extra;
137 unsigned char abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
138 PWLAN_IE_SSID pItemSSID = NULL;
140 pr_debug(" SIOCSIWSCAN\n");
142 if (pDevice->byReAssocCount > 0) { //reject scan when re-associating!
143 //send scan event to wpa_Supplicant
144 union iwreq_data wrqu;
146 PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
147 memset(&wrqu, 0, sizeof(wrqu));
148 wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
152 spin_lock_irq(&pDevice->lock);
153 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
155 //mike add: active scan OR passive scan OR desire_ssid scan
156 if (wrq->length == sizeof(struct iw_scan_req)) {
157 if (wrq->flags & IW_SCAN_THIS_ESSID) { //desire_ssid scan
158 memset(abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
159 pItemSSID = (PWLAN_IE_SSID)abyScanSSID;
160 pItemSSID->byElementID = WLAN_EID_SSID;
161 memcpy(pItemSSID->abySSID, req->essid, (int)req->essid_len);
162 if (pItemSSID->abySSID[req->essid_len - 1] == '\0') {
163 if (req->essid_len > 0)
164 pItemSSID->len = req->essid_len - 1;
166 pItemSSID->len = req->essid_len;
167 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
168 PRINT_K("SIOCSIWSCAN:[desired_ssid=%s,len=%d]\n", ((PWLAN_IE_SSID)abyScanSSID)->abySSID,
169 ((PWLAN_IE_SSID)abyScanSSID)->len);
170 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID);
171 spin_unlock_irq(&pDevice->lock);
174 } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) { //passive scan
175 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
177 } else { //active scan
178 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
181 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
182 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
183 spin_unlock_irq(&pDevice->lock);
189 * Wireless Handler : get scan results
192 static int iwctl_giwscan(struct net_device *dev,
193 struct iw_request_info *info,
194 struct iw_point *wrq,
198 struct vnt_private *pDevice = netdev_priv(dev);
199 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
201 PWLAN_IE_SSID pItemSSID;
202 PWLAN_IE_SUPP_RATES pSuppRates, pExtSuppRates;
203 char *current_ev = extra;
204 char *end_buf = extra + IW_SCAN_MAX_DATA;
205 char *current_val = NULL;
208 char buf[MAX_WPA_IE_LEN * 2 + 30];
210 pr_debug(" SIOCGIWSCAN\n");
212 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
216 pBSS = &(pMgmt->sBSSList[0]);
217 for (ii = 0, jj = 0; jj < MAX_BSS_NUM; jj++) {
218 if (current_ev >= end_buf)
220 pBSS = &(pMgmt->sBSSList[jj]);
223 memset(&iwe, 0, sizeof(iwe));
225 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
226 memcpy(iwe.u.ap_addr.sa_data, pBSS->abyBSSID, WLAN_BSSID_LEN);
227 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
229 memset(&iwe, 0, sizeof(iwe));
230 iwe.cmd = SIOCGIWESSID;
231 pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
232 iwe.u.data.length = pItemSSID->len;
233 iwe.u.data.flags = 1;
234 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pItemSSID->abySSID);
236 memset(&iwe, 0, sizeof(iwe));
237 iwe.cmd = SIOCGIWMODE;
238 if (WLAN_GET_CAP_INFO_ESS(pBSS->wCapInfo))
239 iwe.u.mode = IW_MODE_INFRA;
241 iwe.u.mode = IW_MODE_ADHOC;
243 iwe.len = IW_EV_UINT_LEN;
244 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
246 pSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abySuppRates;
247 pExtSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abyExtSuppRates;
248 memset(&iwe, 0, sizeof(iwe));
249 iwe.cmd = SIOCGIWFREQ;
250 iwe.u.freq.m = pBSS->uChannel;
253 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
254 //2008-0409-04, <Add> by Einsn Liu
256 int f = (int)pBSS->uChannel - 1;
259 iwe.u.freq.m = frequency_list[f] * 100000;
262 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
264 memset(&iwe, 0, sizeof(iwe));
266 RFvRSSITodBm(pDevice, (unsigned char)(pBSS->uRSSI), &ldBm);
267 iwe.u.qual.level = ldBm;
268 iwe.u.qual.noise = 0;
269 //2008-0409-01, <Add> by Einsn Liu
271 iwe.u.qual.qual = 100;
275 iwe.u.qual.qual = (40 - (-ldBm - 50)) * 100 / 40;
277 iwe.u.qual.updated = 7;
279 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
281 memset(&iwe, 0, sizeof(iwe));
282 iwe.cmd = SIOCGIWENCODE;
283 iwe.u.data.length = 0;
284 if (WLAN_GET_CAP_INFO_PRIVACY(pBSS->wCapInfo))
285 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
287 iwe.u.data.flags = IW_ENCODE_DISABLED;
289 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pItemSSID->abySSID);
291 memset(&iwe, 0, sizeof(iwe));
292 iwe.cmd = SIOCGIWRATE;
293 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
294 current_val = current_ev + IW_EV_LCP_LEN;
296 for (kk = 0; kk < 12; kk++) {
297 if (pSuppRates->abyRates[kk] == 0)
299 // Bit rate given in 500 kb/s units (+ 0x80)
300 iwe.u.bitrate.value = ((pSuppRates->abyRates[kk] & 0x7f) * 500000);
301 current_val = iwe_stream_add_value(info, current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
303 for (kk = 0; kk < 8; kk++) {
304 if (pExtSuppRates->abyRates[kk] == 0)
306 // Bit rate given in 500 kb/s units (+ 0x80)
307 iwe.u.bitrate.value = ((pExtSuppRates->abyRates[kk] & 0x7f) * 500000);
308 current_val = iwe_stream_add_value(info, current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
311 if ((current_val - current_ev) > IW_EV_LCP_LEN)
312 current_ev = current_val;
314 memset(&iwe, 0, sizeof(iwe));
315 iwe.cmd = IWEVCUSTOM;
316 sprintf(buf, "bcn_int=%d", pBSS->wBeaconInterval);
317 iwe.u.data.length = strlen(buf);
318 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, buf);
320 if ((pBSS->wWPALen > 0) && (pBSS->wWPALen <= MAX_WPA_IE_LEN)) {
321 memset(&iwe, 0, sizeof(iwe));
323 iwe.u.data.length = pBSS->wWPALen;
324 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pBSS->byWPAIE);
327 if ((pBSS->wRSNLen > 0) && (pBSS->wRSNLen <= MAX_WPA_IE_LEN)) {
328 memset(&iwe, 0, sizeof(iwe));
330 iwe.u.data.length = pBSS->wRSNLen;
331 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pBSS->byRSNIE);
337 wrq->length = current_ev - extra;
342 * Wireless Handler : set frequency or channel
345 int iwctl_siwfreq(struct net_device *dev,
346 struct iw_request_info *info,
350 struct vnt_private *pDevice = netdev_priv(dev);
353 pr_debug(" SIOCSIWFREQ\n");
355 // If setting by frequency, convert to a channel
357 (wrq->m >= (int) 2.412e8) &&
358 (wrq->m <= (int) 2.487e8)) {
359 int f = wrq->m / 100000;
362 while ((c < 14) && (f != frequency_list[c]))
367 // Setting by channel number
368 if ((wrq->m > 14) || (wrq->e > 0))
371 int channel = wrq->m;
373 if ((channel < 1) || (channel > 14)) {
374 pr_debug("%s: New channel value of %d is invalid!\n",
378 // Yes ! We can set it !!!
379 pr_debug(" Set to channel = %d\n", channel);
380 pDevice->uChannel = channel;
381 //2007-0207-04,<Add> by EinsnLiu
382 //Make change effect at once
383 pDevice->bCommit = true;
391 * Wireless Handler : get frequency or channel
394 int iwctl_giwfreq(struct net_device *dev,
395 struct iw_request_info *info,
399 struct vnt_private *pDevice = netdev_priv(dev);
400 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
402 pr_debug(" SIOCGIWFREQ\n");
404 #ifdef WEXT_USECHANNELS
405 wrq->m = (int)pMgmt->uCurrChannel;
409 int f = (int)pMgmt->uCurrChannel - 1;
413 wrq->m = frequency_list[f] * 100000;
422 * Wireless Handler : set operation mode
425 int iwctl_siwmode(struct net_device *dev,
426 struct iw_request_info *info,
430 struct vnt_private *pDevice = netdev_priv(dev);
431 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
434 pr_debug(" SIOCSIWMODE\n");
436 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP && pDevice->bEnableHostapd) {
437 pr_debug("Can't set operation mode, hostapd is running\n");
443 if (pMgmt->eConfigMode != WMAC_CONFIG_IBSS_STA) {
444 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
445 if (pDevice->flags & DEVICE_FLAGS_OPENED)
446 pDevice->bCommit = true;
449 pr_debug("set mode to ad-hoc\n");
453 if (pMgmt->eConfigMode != WMAC_CONFIG_ESS_STA) {
454 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
455 if (pDevice->flags & DEVICE_FLAGS_OPENED)
456 pDevice->bCommit = true;
459 pr_debug("set mode to infrastructure\n");
463 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
467 if (pMgmt->eConfigMode != WMAC_CONFIG_AP) {
468 pMgmt->eConfigMode = WMAC_CONFIG_AP;
469 if (pDevice->flags & DEVICE_FLAGS_OPENED)
470 pDevice->bCommit = true;
473 pr_debug("set mode to Access Point\n");
477 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
488 * Wireless Handler : get operation mode
491 int iwctl_giwmode(struct net_device *dev,
492 struct iw_request_info *info,
496 struct vnt_private *pDevice = netdev_priv(dev);
497 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
499 pr_debug(" SIOCGIWMODE\n");
500 // If not managed, assume it's ad-hoc
501 switch (pMgmt->eConfigMode) {
502 case WMAC_CONFIG_ESS_STA:
503 *wmode = IW_MODE_INFRA;
505 case WMAC_CONFIG_IBSS_STA:
506 *wmode = IW_MODE_ADHOC;
508 case WMAC_CONFIG_AUTO:
509 *wmode = IW_MODE_INFRA;
512 *wmode = IW_MODE_MASTER;
515 *wmode = IW_MODE_ADHOC;
522 * Wireless Handler : get capability range
525 int iwctl_giwrange(struct net_device *dev,
526 struct iw_request_info *info,
527 struct iw_point *wrq,
530 struct iw_range *range = (struct iw_range *)extra;
532 unsigned char abySupportedRates[13] = {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
534 pr_debug(" SIOCGIWRANGE\n");
536 wrq->length = sizeof(struct iw_range);
537 memset(range, 0, sizeof(struct iw_range));
538 range->min_nwid = 0x0000;
539 range->max_nwid = 0x0000;
540 range->num_channels = 14;
541 // Should be based on cap_rid.country to give only
542 // what the current card support
544 for (i = 0; i < 14; i++) {
545 range->freq[k].i = i + 1; // List index
546 range->freq[k].m = frequency_list[i] * 100000;
547 range->freq[k++].e = 1; // Values in table in MHz -> * 10^5 * 10
549 range->num_frequency = k;
550 // Hum... Should put the right values there
551 #ifdef Calcu_LinkQual
552 range->max_qual.qual = 100;
554 range->max_qual.qual = 255;
556 range->max_qual.level = 0;
557 range->max_qual.noise = 0;
558 range->sensitivity = 255;
560 for (i = 0; i < 13; i++) {
561 range->bitrate[i] = abySupportedRates[i] * 500000;
562 if (range->bitrate[i] == 0)
565 range->num_bitrates = i;
567 // Set an indication of the max TCP throughput
568 // in bit/s that we can expect using this interface.
569 // May be use for QoS stuff... Jean II
571 range->throughput = 5 * 1000 * 1000;
573 range->throughput = 1.5 * 1000 * 1000;
576 range->max_rts = 2312;
577 range->min_frag = 256;
578 range->max_frag = 2312;
580 // the encoding capabilities
581 range->num_encoding_sizes = 3;
583 range->encoding_size[0] = 5;
585 range->encoding_size[1] = 13;
586 // 256 bits for WPA-PSK
587 range->encoding_size[2] = 32;
588 // 4 keys are allowed
589 range->max_encoding_tokens = 4;
591 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
592 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
595 range->max_pmp = 1000000;// 1 secs
597 range->max_pmt = 1000000;// 1 secs
598 range->pmp_flags = IW_POWER_PERIOD;
599 range->pmt_flags = IW_POWER_TIMEOUT;
600 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
602 // Transmit Power - values are in mW
604 range->txpower[0] = 100;
605 range->num_txpower = 1;
606 range->txpower_capa = IW_TXPOW_MWATT;
607 range->we_version_source = SUPPORTED_WIRELESS_EXT;
608 range->we_version_compiled = WIRELESS_EXT;
609 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
610 range->retry_flags = IW_RETRY_LIMIT;
611 range->r_time_flags = IW_RETRY_LIFETIME;
612 range->min_retry = 1;
613 range->max_retry = 65535;
614 range->min_r_time = 1024;
615 range->max_r_time = 65535 * 1024;
616 // Experimental measurements - boundary 11/5.5 Mb/s
617 // Note : with or without the (local->rssi), results
618 // are somewhat different. - Jean II
619 range->avg_qual.qual = 6;
620 range->avg_qual.level = 176; // -80 dBm
621 range->avg_qual.noise = 0;
628 * Wireless Handler : set ap mac address
631 int iwctl_siwap(struct net_device *dev,
632 struct iw_request_info *info,
633 struct sockaddr *wrq,
636 struct vnt_private *pDevice = netdev_priv(dev);
637 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
639 unsigned char ZeroBSSID[WLAN_BSSID_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
641 pr_debug(" SIOCSIWAP\n");
642 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
644 pr_debug("SIOCSIWAP(??)-->In scanning..\n");
646 if (wrq->sa_family != ARPHRD_ETHER)
649 memcpy(pMgmt->abyDesireBSSID, wrq->sa_data, 6);
650 //2008-0409-05, <Add> by Einsn Liu
651 if ((pDevice->bLinkPass == true) &&
652 (memcmp(pMgmt->abyDesireBSSID, pMgmt->abyCurrBSSID, 6) == 0)) {
656 if ((is_broadcast_ether_addr(pMgmt->abyDesireBSSID)) ||
657 (memcmp(pMgmt->abyDesireBSSID, ZeroBSSID, 6) == 0)) {
658 PRINT_K("SIOCSIWAP:invalid desired BSSID return!\n");
661 //mike add: if desired AP is hidden ssid(there are two same BSSID in list),
662 // then ignore,because you don't known which one to be connect with??
664 unsigned int ii, uSameBssidNum = 0;
666 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
667 if (pMgmt->sBSSList[ii].bActive &&
668 ether_addr_equal(pMgmt->sBSSList[ii].abyBSSID,
669 pMgmt->abyDesireBSSID)) {
673 if (uSameBssidNum >= 2) { //hit: desired AP is in hidden ssid mode!!!
674 PRINT_K("SIOCSIWAP:ignore for desired AP in hidden mode\n");
679 if (pDevice->flags & DEVICE_FLAGS_OPENED)
680 pDevice->bCommit = true;
687 * Wireless Handler : get ap mac address
690 int iwctl_giwap(struct net_device *dev,
691 struct iw_request_info *info,
692 struct sockaddr *wrq,
695 struct vnt_private *pDevice = netdev_priv(dev);
696 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
698 pr_debug(" SIOCGIWAP\n");
700 memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
701 //2008-0410,<Modify> by Einsn Liu
702 if ((pDevice->bLinkPass == false) && (pMgmt->eCurrMode != WMAC_MODE_ESS_AP))
703 memset(wrq->sa_data, 0, 6);
705 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)
706 memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
708 wrq->sa_family = ARPHRD_ETHER;
714 * Wireless Handler : get ap list
717 int iwctl_giwaplist(struct net_device *dev,
718 struct iw_request_info *info,
719 struct iw_point *wrq,
723 struct sockaddr *sock = NULL;
724 struct sockaddr *s = NULL;
725 struct iw_quality *qual = NULL;
726 struct iw_quality *q = NULL;
727 PKnownBSS pBSS = NULL;
729 struct vnt_private *pDevice = netdev_priv(dev);
730 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
732 pr_debug(" SIOCGIWAPLIST\n");
734 if (!capable(CAP_NET_ADMIN)) {
742 sock = kmalloc_array(IW_MAX_AP, sizeof(struct sockaddr), GFP_KERNEL);
748 qual = kmalloc_array(IW_MAX_AP, sizeof(struct iw_quality), GFP_KERNEL);
754 for (ii = 0, jj = 0; ii < MAX_BSS_NUM; ii++) {
755 pBSS = &(pMgmt->sBSSList[ii]);
765 memcpy(s->sa_data, pBSS->abyBSSID, 6);
766 s->sa_family = ARPHRD_ETHER;
767 q->level = pBSS->uRSSI;
774 wrq->flags = 1; /* Should be define'd */
776 memcpy(extra, sock, sizeof(struct sockaddr) * jj);
777 memcpy(extra + sizeof(struct sockaddr) * jj,
779 sizeof(struct iw_quality) * jj);
787 * Wireless Handler : set essid
790 int iwctl_siwessid(struct net_device *dev,
791 struct iw_request_info *info,
792 struct iw_point *wrq,
795 struct vnt_private *pDevice = netdev_priv(dev);
796 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
797 PWLAN_IE_SSID pItemSSID;
798 //2008-0409-05, <Add> by Einsn Liu
801 pr_debug(" SIOCSIWESSID\n");
802 pDevice->fWPA_Authened = false;
803 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
805 pr_debug("SIOCSIWESSID(??)-->In scanning..\n");
807 // Check if we asked for `any'
808 if (wrq->flags == 0) {
809 // Just send an empty SSID list
810 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
811 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
812 PRINT_K("set essid to 'any'\n");
813 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
818 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
819 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
820 pItemSSID->byElementID = WLAN_EID_SSID;
822 memcpy(pItemSSID->abySSID, extra, wrq->length);
823 if (pItemSSID->abySSID[wrq->length - 1] == '\0') {
825 pItemSSID->len = wrq->length - 1;
827 pItemSSID->len = wrq->length;
828 pr_debug("set essid to %s\n", pItemSSID->abySSID);
829 //2008-0409-05, <Add> by Einsn Liu
830 len = (pItemSSID->len > ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) ? pItemSSID->len : ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len;
831 if ((pDevice->bLinkPass == true) &&
832 (memcmp(pItemSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID, len) == 0))
835 //mike:need clear desiredBSSID
836 if (pItemSSID->len == 0) {
837 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
841 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
842 //Wext wil order another command of siwap to link with desired AP,
843 //so here need not associate??
844 if (pDevice->bWPASuppWextEnabled == true) {
845 /*******search if in hidden ssid mode ****/
847 PKnownBSS pCurr = NULL;
848 unsigned char abyTmpDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
849 unsigned int ii, uSameBssidNum = 0;
851 memcpy(abyTmpDesireSSID, pMgmt->abyDesireSSID, sizeof(abyTmpDesireSSID));
852 pCurr = BSSpSearchBSSList(pDevice,
855 pMgmt->eConfigPHYMode
859 PRINT_K("SIOCSIWESSID:hidden ssid site survey before associate.......\n");
860 vResetCommandTimer((void *)pDevice);
861 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
862 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
863 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
864 } else { //mike:to find out if that desired SSID is a hidden-ssid AP ,
865 // by means of judging if there are two same BSSID exist in list ?
866 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
867 if (pMgmt->sBSSList[ii].bActive &&
868 ether_addr_equal(pMgmt->sBSSList[ii].abyBSSID,
873 if (uSameBssidNum >= 2) { //hit: desired AP is in hidden ssid mode!!!
874 pr_debug("SIOCSIWESSID:hidden ssid directly associate.......\n");
875 vResetCommandTimer((void *)pDevice);
876 pMgmt->eScanType = WMAC_SCAN_PASSIVE; //this scan type,you'll submit scan result!
877 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
878 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
886 pr_debug("set essid = %s\n", pItemSSID->abySSID);
889 if (pDevice->flags & DEVICE_FLAGS_OPENED)
890 pDevice->bCommit = true;
896 * Wireless Handler : get essid
899 int iwctl_giwessid(struct net_device *dev,
900 struct iw_request_info *info,
901 struct iw_point *wrq,
904 struct vnt_private *pDevice = netdev_priv(dev);
905 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
906 PWLAN_IE_SSID pItemSSID;
908 pr_debug(" SIOCGIWESSID\n");
910 // Note : if wrq->u.data.flags != 0, we should
911 // get the relevant SSID from the SSID list...
913 // Get the current SSID
914 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
915 memcpy(extra, pItemSSID->abySSID , pItemSSID->len);
916 extra[pItemSSID->len] = '\0';
917 wrq->length = pItemSSID->len + 1;
918 //2008-0409-03, <Add> by Einsn Liu
919 wrq->length = pItemSSID->len;
920 wrq->flags = 1; // active
926 * Wireless Handler : set data rate
929 int iwctl_siwrate(struct net_device *dev,
930 struct iw_request_info *info,
931 struct iw_param *wrq,
934 struct vnt_private *pDevice = netdev_priv(dev);
938 unsigned char abySupportedRates[13] = {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
940 pr_debug(" SIOCSIWRATE\n");
941 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
946 // First : get a valid bit rate value
948 // Which type of value
949 if ((wrq->value < 13) &&
951 // Setting by rate index
952 // Find value in the magic rate table
955 // Setting by frequency value
956 u8 normvalue = (u8) (wrq->value/500000);
958 // Check if rate is valid
959 for (i = 0; i < 13; i++) {
960 if (normvalue == abySupportedRates[i]) {
966 // -1 designed the max rate (mostly auto mode)
967 if (wrq->value == -1) {
968 // Get the highest available rate
969 for (i = 0; i < 13; i++) {
970 if (abySupportedRates[i] == 0)
977 // Check that it is valid
978 // brate is index of abySupportedRates[]
984 // Now, check if we want a fixed or auto value
985 if (wrq->fixed != 0) {
988 pr_debug("Rate Fix\n");
989 pDevice->bFixRate = true;
990 if ((pDevice->byBBType == BB_TYPE_11B) && (brate > 3)) {
991 pDevice->uConnectionRate = 3;
993 pDevice->uConnectionRate = brate;
994 pr_debug("Fixed to Rate %d\n",
995 pDevice->uConnectionRate);
999 pDevice->bFixRate = false;
1000 pDevice->uConnectionRate = 13;
1001 pr_debug("auto rate:connection_rate is 13\n");
1008 * Wireless Handler : get data rate
1011 int iwctl_giwrate(struct net_device *dev,
1012 struct iw_request_info *info,
1013 struct iw_param *wrq,
1016 struct vnt_private *pDevice = netdev_priv(dev);
1017 //2007-0118-05,<Mark> by EinsnLiu
1018 //Mark the unnecessary sentences.
1019 // PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1021 pr_debug(" SIOCGIWRATE\n");
1023 unsigned char abySupportedRates[13] = {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
1025 //2008-5-8 <modify> by chester
1026 if (pDevice->bLinkPass) {
1027 if (pDevice->bFixRate == true) {
1028 if (pDevice->uConnectionRate < 13) {
1029 brate = abySupportedRates[pDevice->uConnectionRate];
1031 if (pDevice->byBBType == BB_TYPE_11B)
1033 if (pDevice->byBBType == BB_TYPE_11G)
1035 if (pDevice->byBBType == BB_TYPE_11A)
1039 brate = abySupportedRates[TxRate_iwconfig];
1043 wrq->value = brate * 500000;
1044 // If more than one rate, set auto
1045 if (pDevice->bFixRate == true)
1053 * Wireless Handler : set rts threshold
1056 int iwctl_siwrts(struct net_device *dev,
1057 struct iw_request_info *info,
1058 struct iw_param *wrq,
1061 struct vnt_private *pDevice = netdev_priv(dev);
1064 pr_debug(" SIOCSIWRTS\n");
1067 int rthr = wrq->value;
1072 if ((rthr < 0) || (rthr > 2312))
1075 pDevice->wRTSThreshold = rthr;
1082 * Wireless Handler : get rts
1085 int iwctl_giwrts(struct net_device *dev,
1086 struct iw_request_info *info,
1087 struct iw_param *wrq,
1090 struct vnt_private *pDevice = netdev_priv(dev);
1092 pr_debug(" SIOCGIWRTS\n");
1093 wrq->value = pDevice->wRTSThreshold;
1094 wrq->disabled = (wrq->value >= 2312);
1101 * Wireless Handler : set fragment threshold
1104 int iwctl_siwfrag(struct net_device *dev,
1105 struct iw_request_info *info,
1106 struct iw_param *wrq,
1109 struct vnt_private *pDevice = netdev_priv(dev);
1111 int fthr = wrq->value;
1113 pr_debug(" SIOCSIWFRAG\n");
1117 if ((fthr < 256) || (fthr > 2312)) {
1120 fthr &= ~0x1; // Get an even value
1121 pDevice->wFragmentationThreshold = (u16)fthr;
1128 * Wireless Handler : get fragment threshold
1131 int iwctl_giwfrag(struct net_device *dev,
1132 struct iw_request_info *info,
1133 struct iw_param *wrq,
1136 struct vnt_private *pDevice = netdev_priv(dev);
1138 pr_debug(" SIOCGIWFRAG\n");
1139 wrq->value = pDevice->wFragmentationThreshold;
1140 wrq->disabled = (wrq->value >= 2312);
1147 * Wireless Handler : set retry threshold
1149 int iwctl_siwretry(struct net_device *dev,
1150 struct iw_request_info *info,
1151 struct iw_param *wrq,
1154 struct vnt_private *pDevice = netdev_priv(dev);
1157 pr_debug(" SIOCSIWRETRY\n");
1159 if (wrq->disabled) {
1164 if (wrq->flags & IW_RETRY_LIMIT) {
1165 if (wrq->flags & IW_RETRY_MAX)
1166 pDevice->byLongRetryLimit = wrq->value;
1167 else if (wrq->flags & IW_RETRY_MIN)
1168 pDevice->byShortRetryLimit = wrq->value;
1170 // No modifier : set both
1171 pDevice->byShortRetryLimit = wrq->value;
1172 pDevice->byLongRetryLimit = wrq->value;
1175 if (wrq->flags & IW_RETRY_LIFETIME)
1176 pDevice->wMaxTransmitMSDULifetime = wrq->value;
1182 * Wireless Handler : get retry threshold
1184 int iwctl_giwretry(struct net_device *dev,
1185 struct iw_request_info *info,
1186 struct iw_param *wrq,
1189 struct vnt_private *pDevice = netdev_priv(dev);
1191 pr_debug(" SIOCGIWRETRY\n");
1192 wrq->disabled = 0; // Can't be disabled
1194 // Note : by default, display the min retry number
1195 if ((wrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1196 wrq->flags = IW_RETRY_LIFETIME;
1197 wrq->value = (int)pDevice->wMaxTransmitMSDULifetime; //ms
1198 } else if ((wrq->flags & IW_RETRY_MAX)) {
1199 wrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
1200 wrq->value = (int)pDevice->byLongRetryLimit;
1202 wrq->flags = IW_RETRY_LIMIT;
1203 wrq->value = (int)pDevice->byShortRetryLimit;
1204 if ((int)pDevice->byShortRetryLimit != (int)pDevice->byLongRetryLimit)
1205 wrq->flags |= IW_RETRY_MIN;
1212 * Wireless Handler : set encode mode
1214 int iwctl_siwencode(struct net_device *dev,
1215 struct iw_request_info *info,
1216 struct iw_point *wrq,
1219 struct vnt_private *pDevice = netdev_priv(dev);
1220 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1221 unsigned long dwKeyIndex = (unsigned long)(wrq->flags & IW_ENCODE_INDEX);
1223 int index = (wrq->flags & IW_ENCODE_INDEX);
1225 //2007-0207-07,<Modify> by EinsnLiu
1226 //There are some problems when using iwconfig encode/key command to set the WEP key.
1227 //I almost rewrite this function.
1228 //now it support:(assume the wireless interface's name is eth0)
1229 //iwconfig eth0 key [1] 1122334455 open /*set key stirng to index 1,and driver using key index is set to 1*/
1230 //iwconfig eth0 key [3] /*set driver using key index to 3,the key string no change */
1231 //iwconfig eth0 key 1122334455 /*set key string to driver using index*/
1232 //iwconfig eth0 key restricted /*enable share key*/
1236 pr_debug(" SIOCSIWENCODE\n");
1238 if ((wrq->flags & IW_ENCODE_DISABLED) == 0) {
1239 //Not disable encryption
1241 if (dwKeyIndex > WLAN_WEP_NKEYS) {
1246 if (dwKeyIndex < 1 && ((wrq->flags & IW_ENCODE_NOKEY) == 0)) {//set default key
1247 if (pDevice->byKeyIndex < WLAN_WEP_NKEYS)
1248 dwKeyIndex = pDevice->byKeyIndex;
1255 // Check the size of the key
1256 if (wrq->length > WLAN_WEP232_KEYLEN) {
1261 if (wrq->length > 0) {//have key
1263 if (wrq->length == WLAN_WEP232_KEYLEN) {
1264 pr_debug("Set 232 bit wep key\n");
1265 } else if (wrq->length == WLAN_WEP104_KEYLEN) {
1266 pr_debug("Set 104 bit wep key\n");
1267 } else if (wrq->length == WLAN_WEP40_KEYLEN) {
1268 pr_debug("Set 40 bit wep key, index= %d\n",
1270 } else {//no support length
1274 memset(pDevice->abyKey, 0, WLAN_WEP232_KEYLEN);
1275 memcpy(pDevice->abyKey, extra, wrq->length);
1277 pr_debug("abyKey: ");
1278 for (ii = 0; ii < wrq->length; ii++)
1279 pr_debug("%02x ", pDevice->abyKey[ii]);
1281 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1282 spin_lock_irq(&pDevice->lock);
1283 KeybSetDefaultKey(&(pDevice->sKey),
1284 (unsigned long)(dwKeyIndex | (1 << 31)),
1289 pDevice->PortOffset,
1292 spin_unlock_irq(&pDevice->lock);
1294 pDevice->byKeyIndex = (unsigned char)dwKeyIndex;
1295 pDevice->uKeyLength = wrq->length;
1296 pDevice->bTransmitKey = true;
1297 pDevice->bEncryptionEnable = true;
1298 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1300 } else if (index > 0) {
1301 //when the length is 0 the request only changes the default transmit key index
1302 //check the new key if it has a non zero length
1303 if (pDevice->bEncryptionEnable == false) {
1307 pr_debug("Just set Default key Index:\n");
1308 pkeytab = &(pDevice->sKey.KeyTable[MAX_KEY_TABLE - 1]);
1309 if (pkeytab->GroupKey[(unsigned char)dwKeyIndex].uKeyLength == 0) {
1310 pr_debug("Default key len is 0\n");
1314 pDevice->byKeyIndex = (unsigned char)dwKeyIndex;
1315 pkeytab->dwGTKeyIndex = dwKeyIndex | (1 << 31);
1316 pkeytab->GroupKey[(unsigned char)dwKeyIndex].dwKeyIndex = dwKeyIndex | (1 << 31);
1319 } else {//disable the key
1320 pr_debug("Disable WEP function\n");
1321 if (pDevice->bEncryptionEnable == false)
1323 pMgmt->bShareKeyAlgorithm = false;
1324 pDevice->bEncryptionEnable = false;
1325 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1326 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1327 spin_lock_irq(&pDevice->lock);
1328 for (uu = 0; uu < MAX_KEY_TABLE; uu++)
1329 MACvDisableKeyEntry(pDevice->PortOffset, uu);
1330 spin_unlock_irq(&pDevice->lock);
1335 if (wrq->flags & IW_ENCODE_RESTRICTED) {
1336 pr_debug("Enable WEP & ShareKey System\n");
1337 pMgmt->bShareKeyAlgorithm = true;
1339 if (wrq->flags & IW_ENCODE_OPEN) {
1340 pr_debug("Enable WEP & Open System\n");
1341 pMgmt->bShareKeyAlgorithm = false;
1346 int iwctl_giwencode(struct net_device *dev,
1347 struct iw_request_info *info,
1348 struct iw_point *wrq,
1351 struct vnt_private *pDevice = netdev_priv(dev);
1352 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1353 char abyKey[WLAN_WEP232_KEYLEN];
1355 unsigned int index = (unsigned int)(wrq->flags & IW_ENCODE_INDEX);
1356 PSKeyItem pKey = NULL;
1358 pr_debug(" SIOCGIWENCODE\n");
1360 if (index > WLAN_WEP_NKEYS)
1363 if (index < 1) {//get default key
1364 if (pDevice->byKeyIndex < WLAN_WEP_NKEYS)
1365 index = pDevice->byKeyIndex;
1372 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
1373 // Check encryption mode
1374 wrq->flags = IW_ENCODE_NOKEY;
1375 // Is WEP enabled ???
1376 if (pDevice->bEncryptionEnable)
1377 wrq->flags |= IW_ENCODE_ENABLED;
1379 wrq->flags |= IW_ENCODE_DISABLED;
1381 if (pMgmt->bShareKeyAlgorithm)
1382 wrq->flags |= IW_ENCODE_RESTRICTED;
1384 wrq->flags |= IW_ENCODE_OPEN;
1387 if ((index == 0) && (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled ||
1388 pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)) {//get wpa pairwise key
1389 if (KeybGetKey(&(pDevice->sKey), pMgmt->abyCurrBSSID, 0xffffffff, &pKey)) {
1390 wrq->length = pKey->uKeyLength;
1391 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1392 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1394 } else if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (unsigned char)index , &pKey)) {
1395 wrq->length = pKey->uKeyLength;
1396 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1397 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1400 wrq->flags |= index+1;
1406 * Wireless Handler : set power mode
1408 int iwctl_siwpower(struct net_device *dev,
1409 struct iw_request_info *info,
1410 struct iw_param *wrq,
1413 struct vnt_private *pDevice = netdev_priv(dev);
1414 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1417 pr_debug(" SIOCSIWPOWER\n");
1419 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
1424 if (wrq->disabled) {
1425 pDevice->ePSMode = WMAC_POWER_CAM;
1426 PSvDisablePowerSaving(pDevice);
1429 if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1430 pDevice->ePSMode = WMAC_POWER_FAST;
1431 PSvEnablePowerSaving((void *)pDevice, pMgmt->wListenInterval);
1433 } else if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
1434 pDevice->ePSMode = WMAC_POWER_FAST;
1435 PSvEnablePowerSaving((void *)pDevice, pMgmt->wListenInterval);
1437 switch (wrq->flags & IW_POWER_MODE) {
1438 case IW_POWER_UNICAST_R:
1439 pr_debug(" SIOCSIWPOWER: IW_POWER_UNICAST_R\n");
1442 case IW_POWER_ALL_R:
1443 pr_debug(" SIOCSIWPOWER: IW_POWER_ALL_R\n");
1446 pr_debug(" SIOCSIWPOWER: IW_POWER_ON\n");
1456 * Wireless Handler : get power mode
1458 int iwctl_giwpower(struct net_device *dev,
1459 struct iw_request_info *info,
1460 struct iw_param *wrq,
1463 struct vnt_private *pDevice = netdev_priv(dev);
1464 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1465 int mode = pDevice->ePSMode;
1467 pr_debug(" SIOCGIWPOWER\n");
1469 wrq->disabled = (mode == WMAC_POWER_CAM);
1473 if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1474 wrq->value = (int)((pMgmt->wListenInterval * pMgmt->wCurrBeaconPeriod) << 10);
1475 wrq->flags = IW_POWER_TIMEOUT;
1477 wrq->value = (int)((pMgmt->wListenInterval * pMgmt->wCurrBeaconPeriod) << 10);
1478 wrq->flags = IW_POWER_PERIOD;
1480 wrq->flags |= IW_POWER_ALL_R;
1486 * Wireless Handler : get Sensitivity
1488 int iwctl_giwsens(struct net_device *dev,
1489 struct iw_request_info *info,
1490 struct iw_param *wrq,
1493 struct vnt_private *pDevice = netdev_priv(dev);
1496 pr_debug(" SIOCGIWSENS\n");
1497 if (pDevice->bLinkPass == true) {
1498 RFvRSSITodBm(pDevice, (unsigned char)(pDevice->uCurrRSSI), &ldBm);
1503 wrq->disabled = (wrq->value == 0);
1509 //2008-0409-07, <Add> by Einsn Liu
1510 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1512 int iwctl_siwauth(struct net_device *dev,
1513 struct iw_request_info *info,
1514 struct iw_param *wrq,
1517 struct vnt_private *pDevice = netdev_priv(dev);
1518 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1520 static int wpa_version = 0; //must be static to save the last value,einsn liu
1521 static int pairwise = 0;
1523 pr_debug(" SIOCSIWAUTH\n");
1524 switch (wrq->flags & IW_AUTH_INDEX) {
1525 case IW_AUTH_WPA_VERSION:
1526 wpa_version = wrq->value;
1527 if (wrq->value == IW_AUTH_WPA_VERSION_DISABLED)
1528 PRINT_K("iwctl_siwauth:set WPADEV to disable at 1??????\n");
1529 else if (wrq->value == IW_AUTH_WPA_VERSION_WPA)
1530 PRINT_K("iwctl_siwauth:set WPADEV to WPA1******\n");
1532 PRINT_K("iwctl_siwauth:set WPADEV to WPA2******\n");
1535 case IW_AUTH_CIPHER_PAIRWISE:
1536 pairwise = wrq->value;
1537 if (pairwise == IW_AUTH_CIPHER_CCMP)
1538 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1539 else if (pairwise == IW_AUTH_CIPHER_TKIP)
1540 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1541 else if (pairwise == IW_AUTH_CIPHER_WEP40 || pairwise == IW_AUTH_CIPHER_WEP104)
1542 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1543 else if (pairwise == IW_AUTH_CIPHER_NONE)
1544 ; /* do nothing,einsn liu */
1546 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1549 case IW_AUTH_CIPHER_GROUP:
1550 if (wpa_version == IW_AUTH_WPA_VERSION_DISABLED)
1552 if (pairwise == IW_AUTH_CIPHER_NONE) {
1553 if (wrq->value == IW_AUTH_CIPHER_CCMP)
1554 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1556 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1559 case IW_AUTH_KEY_MGMT:
1561 if (wpa_version == IW_AUTH_WPA_VERSION_WPA2) {
1562 if (wrq->value == IW_AUTH_KEY_MGMT_PSK)
1563 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
1565 pMgmt->eAuthenMode = WMAC_AUTH_WPA2;
1566 } else if (wpa_version == IW_AUTH_WPA_VERSION_WPA) {
1567 if (wrq->value == 0)
1568 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
1569 else if (wrq->value == IW_AUTH_KEY_MGMT_PSK)
1570 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
1572 pMgmt->eAuthenMode = WMAC_AUTH_WPA;
1576 case IW_AUTH_TKIP_COUNTERMEASURES:
1578 case IW_AUTH_DROP_UNENCRYPTED:
1580 case IW_AUTH_80211_AUTH_ALG:
1581 if (wrq->value == IW_AUTH_ALG_OPEN_SYSTEM)
1582 pMgmt->bShareKeyAlgorithm = false;
1583 else if (wrq->value == IW_AUTH_ALG_SHARED_KEY)
1584 pMgmt->bShareKeyAlgorithm = true;
1587 case IW_AUTH_WPA_ENABLED:
1589 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1591 case IW_AUTH_ROAMING_CONTROL:
1594 case IW_AUTH_PRIVACY_INVOKED:
1595 pDevice->bEncryptionEnable = !!wrq->value;
1596 if (pDevice->bEncryptionEnable == false) {
1599 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1600 pMgmt->bShareKeyAlgorithm = false;
1601 pMgmt->eAuthenMode = false;
1613 int iwctl_giwauth(struct net_device *dev,
1614 struct iw_request_info *info,
1615 struct iw_param *wrq,
1621 int iwctl_siwgenie(struct net_device *dev,
1622 struct iw_request_info *info,
1623 struct iw_point *wrq,
1626 struct vnt_private *pDevice = netdev_priv(dev);
1627 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1632 if (wrq->length < 2)
1635 ret = get_user(length, extra + 1);
1639 if (length + 2 != wrq->length)
1642 if (wrq->length > MAX_WPA_IE_LEN) {
1646 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
1647 if (copy_from_user(pMgmt->abyWPAIE, extra, wrq->length)) {
1651 pMgmt->wWPAIELen = wrq->length;
1653 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
1654 pMgmt->wWPAIELen = 0;
1657 out://not completely ...not necessary in wpa_supplicant 0.5.8
1661 int iwctl_giwgenie(struct net_device *dev,
1662 struct iw_request_info *info,
1663 struct iw_point *wrq,
1666 struct vnt_private *pDevice = netdev_priv(dev);
1667 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1669 int space = wrq->length;
1672 if (pMgmt->wWPAIELen > 0) {
1673 wrq->length = pMgmt->wWPAIELen;
1674 if (pMgmt->wWPAIELen <= space) {
1675 if (copy_to_user(extra, pMgmt->abyWPAIE, pMgmt->wWPAIELen))
1686 int iwctl_siwencodeext(struct net_device *dev,
1687 struct iw_request_info *info,
1688 struct iw_point *wrq,
1691 struct vnt_private *pDevice = netdev_priv(dev);
1692 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1693 struct viawget_wpa_param *param = NULL;
1695 enum wpa_alg alg_name;
1697 int key_idx, set_tx = 0;
1698 u8 seq[IW_ENCODE_SEQ_MAX_SIZE];
1700 size_t seq_len = 0, key_len = 0;
1705 PRINT_K("SIOCSIWENCODEEXT......\n");
1707 param = kzalloc(sizeof(*param), GFP_KERNEL);
1713 case IW_ENCODE_ALG_NONE:
1714 alg_name = WPA_ALG_NONE;
1716 case IW_ENCODE_ALG_WEP:
1717 alg_name = WPA_ALG_WEP;
1719 case IW_ENCODE_ALG_TKIP:
1720 alg_name = WPA_ALG_TKIP;
1722 case IW_ENCODE_ALG_CCMP:
1723 alg_name = WPA_ALG_CCMP;
1726 PRINT_K("Unknown alg = %d\n", ext->alg);
1731 memcpy(addr, ext->addr.sa_data, ETH_ALEN);
1733 key_idx = (wrq->flags&IW_ENCODE_INDEX) - 1;
1735 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
1737 //recover seq,seq_len
1738 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
1739 seq_len = IW_ENCODE_SEQ_MAX_SIZE;
1740 memcpy(seq, ext->rx_seq, seq_len);
1742 //recover key,key_len
1744 key_len = ext->key_len;
1745 memcpy(key, &ext->key[0], key_len);
1748 memset(key_array, 0, 64);
1750 memcpy(key_array, key, key_len);
1751 if (key_len == 32) {
1752 // notice ! the oder
1753 memcpy(&key_array[16], &key[24], 8);
1754 memcpy(&key_array[24], &key[16], 8);
1758 /**************Translate iw_encode_ext to viawget_wpa_param****************/
1759 memcpy(param->addr, addr, ETH_ALEN);
1760 param->u.wpa_key.alg_name = (int)alg_name;
1761 param->u.wpa_key.set_tx = set_tx;
1762 param->u.wpa_key.key_index = key_idx;
1763 param->u.wpa_key.key_len = key_len;
1764 param->u.wpa_key.key = (u8 *)key_array;
1765 param->u.wpa_key.seq = (u8 *)seq;
1766 param->u.wpa_key.seq_len = seq_len;
1768 //****set if current action is Network Manager count??
1769 //****this method is so foolish,but there is no other way???
1770 if (param->u.wpa_key.alg_name == WPA_ALG_NONE) {
1771 if (param->u.wpa_key.key_index == 0)
1772 pDevice->bwextcount++;
1774 if ((pDevice->bwextcount == 1) && (param->u.wpa_key.key_index == 1))
1775 pDevice->bwextcount++;
1777 if ((pDevice->bwextcount == 2) && (param->u.wpa_key.key_index == 2))
1778 pDevice->bwextcount++;
1780 if ((pDevice->bwextcount == 3) && (param->u.wpa_key.key_index == 3))
1781 pDevice->bwextcount++;
1784 if (pDevice->bwextcount == 4) {
1785 pr_debug("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n");
1786 pDevice->bwextcount = 0;
1787 pDevice->bWPASuppWextEnabled = true;
1791 spin_lock_irq(&pDevice->lock);
1792 ret = wpa_set_keys(pDevice, param, true);
1793 spin_unlock_irq(&pDevice->lock);
1800 int iwctl_giwencodeext(struct net_device *dev,
1801 struct iw_request_info *info,
1802 struct iw_point *wrq,
1808 int iwctl_siwmlme(struct net_device *dev,
1809 struct iw_request_info *info,
1810 struct iw_point *wrq,
1813 struct vnt_private *pDevice = netdev_priv(dev);
1814 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1815 struct iw_mlme mime;
1819 ret = copy_from_user(&mime, extra, sizeof(mime));
1823 if (memcmp(pMgmt->abyCurrBSSID, mime.addr.sa_data, ETH_ALEN)) {
1828 case IW_MLME_DEAUTH:
1829 //this command seems to be not complete,please test it --einsnliu
1830 //bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (unsigned char *)&reason);
1832 case IW_MLME_DISASSOC:
1833 if (pDevice->bLinkPass == true) {
1834 pr_debug("iwctl_siwmlme--->send DISASSOCIATE\n");
1835 //clear related flags
1836 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
1837 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
1838 bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
1850 /*------------------------------------------------------------------*/
1852 * Structures to export the Wireless Handlers
1855 static const iw_handler iwctl_handler[] =
1857 (iw_handler) iwctl_commit, // SIOCSIWCOMMIT
1858 (iw_handler) NULL, // SIOCGIWNAME
1859 (iw_handler) NULL, // SIOCSIWNWID
1860 (iw_handler) NULL, // SIOCGIWNWID
1861 (iw_handler) NULL, // SIOCSIWFREQ
1862 (iw_handler) NULL, // SIOCGIWFREQ
1863 (iw_handler) NULL, // SIOCSIWMODE
1864 (iw_handler) NULL, // SIOCGIWMODE
1865 (iw_handler) NULL, // SIOCSIWSENS
1866 (iw_handler) NULL, // SIOCGIWSENS
1867 (iw_handler) NULL, // SIOCSIWRANGE
1868 (iw_handler) iwctl_giwrange, // SIOCGIWRANGE
1869 (iw_handler) NULL, // SIOCSIWPRIV
1870 (iw_handler) NULL, // SIOCGIWPRIV
1871 (iw_handler) NULL, // SIOCSIWSTATS
1872 (iw_handler) NULL, // SIOCGIWSTATS
1873 (iw_handler) NULL, // SIOCSIWSPY
1874 (iw_handler) NULL, // SIOCGIWSPY
1875 (iw_handler) NULL, // -- hole --
1876 (iw_handler) NULL, // -- hole --
1877 (iw_handler) NULL, // SIOCSIWAP
1878 (iw_handler) NULL, // SIOCGIWAP
1879 (iw_handler) NULL, // -- hole -- 0x16
1880 (iw_handler) NULL, // SIOCGIWAPLIST
1881 (iw_handler) iwctl_siwscan, // SIOCSIWSCAN
1882 (iw_handler) iwctl_giwscan, // SIOCGIWSCAN
1883 (iw_handler) NULL, // SIOCSIWESSID
1884 (iw_handler) NULL, // SIOCGIWESSID
1885 (iw_handler) NULL, // SIOCSIWNICKN
1886 (iw_handler) NULL, // SIOCGIWNICKN
1887 (iw_handler) NULL, // -- hole --
1888 (iw_handler) NULL, // -- hole --
1889 (iw_handler) NULL, // SIOCSIWRATE 0x20
1890 (iw_handler) NULL, // SIOCGIWRATE
1891 (iw_handler) NULL, // SIOCSIWRTS
1892 (iw_handler) NULL, // SIOCGIWRTS
1893 (iw_handler) NULL, // SIOCSIWFRAG
1894 (iw_handler) NULL, // SIOCGIWFRAG
1895 (iw_handler) NULL, // SIOCSIWTXPOW
1896 (iw_handler) NULL, // SIOCGIWTXPOW
1897 (iw_handler) NULL, // SIOCSIWRETRY
1898 (iw_handler) NULL, // SIOCGIWRETRY
1899 (iw_handler) NULL, // SIOCSIWENCODE
1900 (iw_handler) NULL, // SIOCGIWENCODE
1901 (iw_handler) NULL, // SIOCSIWPOWER
1902 (iw_handler) NULL, // SIOCGIWPOWER
1904 //2008-0409-07, <Add> by Einsn Liu
1905 (iw_handler) NULL, // -- hole --
1906 (iw_handler) NULL, // -- hole --
1907 (iw_handler) NULL, // SIOCSIWGENIE
1908 (iw_handler) NULL, // SIOCGIWGENIE
1909 (iw_handler) NULL, // SIOCSIWAUTH
1910 (iw_handler) NULL, // SIOCGIWAUTH
1911 (iw_handler) NULL, // SIOCSIWENCODEEXT
1912 (iw_handler) NULL, // SIOCGIWENCODEEXT
1913 (iw_handler) NULL, // SIOCSIWPMKSA
1914 (iw_handler) NULL, // -- hole --
1917 static const iw_handler iwctl_private_handler[] =
1919 NULL, // SIOCIWFIRSTPRIV
1922 struct iw_priv_args iwctl_private_args[] = {
1924 IW_PRIV_TYPE_CHAR | 1024, 0,
1928 const struct iw_handler_def iwctl_handler_def =
1930 .get_wireless_stats = &iwctl_get_wireless_stats,
1931 .num_standard = sizeof(iwctl_handler)/sizeof(iw_handler),
1933 .num_private_args = 0,
1934 .standard = (iw_handler *)iwctl_handler,
1936 .private_args = NULL,