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 ----------------------------*/
70 static int msglevel = MSG_LEVEL_INFO;
72 /*--------------------- Static Variables --------------------------*/
73 /*--------------------- Static Functions --------------------------*/
75 /*--------------------- Export Variables --------------------------*/
77 struct iw_statistics *iwctl_get_wireless_stats(struct net_device *dev)
79 struct vnt_private *pDevice = netdev_priv(dev);
82 pDevice->wstats.status = pDevice->eOPMode;
84 if (pDevice->scStatistic.LinkQuality > 100)
85 pDevice->scStatistic.LinkQuality = 100;
86 pDevice->wstats.qual.qual = (unsigned char)pDevice->scStatistic.LinkQuality;
88 pDevice->wstats.qual.qual = pDevice->byCurrSQ;
90 RFvRSSITodBm(pDevice, (unsigned char)(pDevice->uCurrRSSI), &ldBm);
91 pDevice->wstats.qual.level = ldBm;
92 pDevice->wstats.qual.noise = 0;
93 pDevice->wstats.qual.updated = 1;
94 pDevice->wstats.discard.nwid = 0;
95 pDevice->wstats.discard.code = 0;
96 pDevice->wstats.discard.fragment = 0;
97 pDevice->wstats.discard.retries = (unsigned long)pDevice->scStatistic.dwTsrErr;
98 pDevice->wstats.discard.misc = 0;
99 pDevice->wstats.miss.beacon = 0;
101 return &pDevice->wstats;
104 /*------------------------------------------------------------------*/
106 static int iwctl_commit(struct net_device *dev,
107 struct iw_request_info *info,
111 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWCOMMIT\n");
116 * Wireless Handler : get protocol name
119 int iwctl_giwname(struct net_device *dev,
120 struct iw_request_info *info,
124 strcpy(wrq, "802.11-a/b/g");
129 * Wireless Handler : set scan
132 static int iwctl_siwscan(struct net_device *dev,
133 struct iw_request_info *info,
134 struct iw_point *wrq,
137 struct vnt_private *pDevice = netdev_priv(dev);
138 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
139 struct iw_scan_req *req = (struct iw_scan_req *)extra;
140 unsigned char abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
141 PWLAN_IE_SSID pItemSSID = NULL;
143 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSCAN\n");
145 if (pDevice->byReAssocCount > 0) { //reject scan when re-associating!
146 //send scan event to wpa_Supplicant
147 union iwreq_data wrqu;
149 PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
150 memset(&wrqu, 0, sizeof(wrqu));
151 wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
155 spin_lock_irq(&pDevice->lock);
156 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
158 //mike add: active scan OR passive scan OR desire_ssid scan
159 if (wrq->length == sizeof(struct iw_scan_req)) {
160 if (wrq->flags & IW_SCAN_THIS_ESSID) { //desire_ssid scan
161 memset(abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
162 pItemSSID = (PWLAN_IE_SSID)abyScanSSID;
163 pItemSSID->byElementID = WLAN_EID_SSID;
164 memcpy(pItemSSID->abySSID, req->essid, (int)req->essid_len);
165 if (pItemSSID->abySSID[req->essid_len - 1] == '\0') {
166 if (req->essid_len > 0)
167 pItemSSID->len = req->essid_len - 1;
169 pItemSSID->len = req->essid_len;
170 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
171 PRINT_K("SIOCSIWSCAN:[desired_ssid=%s,len=%d]\n", ((PWLAN_IE_SSID)abyScanSSID)->abySSID,
172 ((PWLAN_IE_SSID)abyScanSSID)->len);
173 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID);
174 spin_unlock_irq(&pDevice->lock);
177 } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) { //passive scan
178 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
180 } else { //active scan
181 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
184 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
185 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
186 spin_unlock_irq(&pDevice->lock);
192 * Wireless Handler : get scan results
195 static int iwctl_giwscan(struct net_device *dev,
196 struct iw_request_info *info,
197 struct iw_point *wrq,
201 struct vnt_private *pDevice = netdev_priv(dev);
202 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
204 PWLAN_IE_SSID pItemSSID;
205 PWLAN_IE_SUPP_RATES pSuppRates, pExtSuppRates;
206 char *current_ev = extra;
207 char *end_buf = extra + IW_SCAN_MAX_DATA;
208 char *current_val = NULL;
211 char buf[MAX_WPA_IE_LEN * 2 + 30];
213 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSCAN\n");
215 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
219 pBSS = &(pMgmt->sBSSList[0]);
220 for (ii = 0, jj = 0; jj < MAX_BSS_NUM; jj++) {
221 if (current_ev >= end_buf)
223 pBSS = &(pMgmt->sBSSList[jj]);
226 memset(&iwe, 0, sizeof(iwe));
228 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
229 memcpy(iwe.u.ap_addr.sa_data, pBSS->abyBSSID, WLAN_BSSID_LEN);
230 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
232 memset(&iwe, 0, sizeof(iwe));
233 iwe.cmd = SIOCGIWESSID;
234 pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
235 iwe.u.data.length = pItemSSID->len;
236 iwe.u.data.flags = 1;
237 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pItemSSID->abySSID);
239 memset(&iwe, 0, sizeof(iwe));
240 iwe.cmd = SIOCGIWMODE;
241 if (WLAN_GET_CAP_INFO_ESS(pBSS->wCapInfo))
242 iwe.u.mode = IW_MODE_INFRA;
244 iwe.u.mode = IW_MODE_ADHOC;
246 iwe.len = IW_EV_UINT_LEN;
247 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
249 pSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abySuppRates;
250 pExtSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abyExtSuppRates;
251 memset(&iwe, 0, sizeof(iwe));
252 iwe.cmd = SIOCGIWFREQ;
253 iwe.u.freq.m = pBSS->uChannel;
256 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
257 //2008-0409-04, <Add> by Einsn Liu
259 int f = (int)pBSS->uChannel - 1;
262 iwe.u.freq.m = frequency_list[f] * 100000;
265 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
267 memset(&iwe, 0, sizeof(iwe));
269 RFvRSSITodBm(pDevice, (unsigned char)(pBSS->uRSSI), &ldBm);
270 iwe.u.qual.level = ldBm;
271 iwe.u.qual.noise = 0;
272 //2008-0409-01, <Add> by Einsn Liu
274 iwe.u.qual.qual = 100;
278 iwe.u.qual.qual = (40 - (-ldBm - 50)) * 100 / 40;
280 iwe.u.qual.updated = 7;
282 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
284 memset(&iwe, 0, sizeof(iwe));
285 iwe.cmd = SIOCGIWENCODE;
286 iwe.u.data.length = 0;
287 if (WLAN_GET_CAP_INFO_PRIVACY(pBSS->wCapInfo))
288 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
290 iwe.u.data.flags = IW_ENCODE_DISABLED;
292 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pItemSSID->abySSID);
294 memset(&iwe, 0, sizeof(iwe));
295 iwe.cmd = SIOCGIWRATE;
296 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
297 current_val = current_ev + IW_EV_LCP_LEN;
299 for (kk = 0; kk < 12; kk++) {
300 if (pSuppRates->abyRates[kk] == 0)
302 // Bit rate given in 500 kb/s units (+ 0x80)
303 iwe.u.bitrate.value = ((pSuppRates->abyRates[kk] & 0x7f) * 500000);
304 current_val = iwe_stream_add_value(info, current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
306 for (kk = 0; kk < 8; kk++) {
307 if (pExtSuppRates->abyRates[kk] == 0)
309 // Bit rate given in 500 kb/s units (+ 0x80)
310 iwe.u.bitrate.value = ((pExtSuppRates->abyRates[kk] & 0x7f) * 500000);
311 current_val = iwe_stream_add_value(info, current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
314 if ((current_val - current_ev) > IW_EV_LCP_LEN)
315 current_ev = current_val;
317 memset(&iwe, 0, sizeof(iwe));
318 iwe.cmd = IWEVCUSTOM;
319 sprintf(buf, "bcn_int=%d", pBSS->wBeaconInterval);
320 iwe.u.data.length = strlen(buf);
321 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, buf);
323 if ((pBSS->wWPALen > 0) && (pBSS->wWPALen <= MAX_WPA_IE_LEN)) {
324 memset(&iwe, 0, sizeof(iwe));
326 iwe.u.data.length = pBSS->wWPALen;
327 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pBSS->byWPAIE);
330 if ((pBSS->wRSNLen > 0) && (pBSS->wRSNLen <= MAX_WPA_IE_LEN)) {
331 memset(&iwe, 0, sizeof(iwe));
333 iwe.u.data.length = pBSS->wRSNLen;
334 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pBSS->byRSNIE);
340 wrq->length = current_ev - extra;
345 * Wireless Handler : set frequency or channel
348 int iwctl_siwfreq(struct net_device *dev,
349 struct iw_request_info *info,
353 struct vnt_private *pDevice = netdev_priv(dev);
356 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFREQ\n");
358 // If setting by frequency, convert to a channel
360 (wrq->m >= (int) 2.412e8) &&
361 (wrq->m <= (int) 2.487e8)) {
362 int f = wrq->m / 100000;
365 while ((c < 14) && (f != frequency_list[c]))
370 // Setting by channel number
371 if ((wrq->m > 14) || (wrq->e > 0))
374 int channel = wrq->m;
376 if ((channel < 1) || (channel > 14)) {
377 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: New channel value of %d is invalid!\n", dev->name, wrq->m);
380 // Yes ! We can set it !!!
381 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Set to channel = %d\n", channel);
382 pDevice->uChannel = channel;
383 //2007-0207-04,<Add> by EinsnLiu
384 //Make change effect at once
385 pDevice->bCommit = true;
393 * Wireless Handler : get frequency or channel
396 int iwctl_giwfreq(struct net_device *dev,
397 struct iw_request_info *info,
401 struct vnt_private *pDevice = netdev_priv(dev);
402 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
404 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFREQ\n");
406 #ifdef WEXT_USECHANNELS
407 wrq->m = (int)pMgmt->uCurrChannel;
411 int f = (int)pMgmt->uCurrChannel - 1;
415 wrq->m = frequency_list[f] * 100000;
424 * Wireless Handler : set operation mode
427 int iwctl_siwmode(struct net_device *dev,
428 struct iw_request_info *info,
432 struct vnt_private *pDevice = netdev_priv(dev);
433 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
436 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMODE\n");
438 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP && pDevice->bEnableHostapd) {
439 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Can't set operation mode, hostapd is running\n");
445 if (pMgmt->eConfigMode != WMAC_CONFIG_IBSS_STA) {
446 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
447 if (pDevice->flags & DEVICE_FLAGS_OPENED)
448 pDevice->bCommit = true;
451 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to ad-hoc\n");
455 if (pMgmt->eConfigMode != WMAC_CONFIG_ESS_STA) {
456 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
457 if (pDevice->flags & DEVICE_FLAGS_OPENED)
458 pDevice->bCommit = true;
461 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to infrastructure\n");
465 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
469 if (pMgmt->eConfigMode != WMAC_CONFIG_AP) {
470 pMgmt->eConfigMode = WMAC_CONFIG_AP;
471 if (pDevice->flags & DEVICE_FLAGS_OPENED)
472 pDevice->bCommit = true;
475 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to Access Point\n");
479 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
490 * Wireless Handler : get operation mode
493 int iwctl_giwmode(struct net_device *dev,
494 struct iw_request_info *info,
498 struct vnt_private *pDevice = netdev_priv(dev);
499 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
501 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWMODE\n");
502 // If not managed, assume it's ad-hoc
503 switch (pMgmt->eConfigMode) {
504 case WMAC_CONFIG_ESS_STA:
505 *wmode = IW_MODE_INFRA;
507 case WMAC_CONFIG_IBSS_STA:
508 *wmode = IW_MODE_ADHOC;
510 case WMAC_CONFIG_AUTO:
511 *wmode = IW_MODE_INFRA;
514 *wmode = IW_MODE_MASTER;
517 *wmode = IW_MODE_ADHOC;
524 * Wireless Handler : get capability range
527 int iwctl_giwrange(struct net_device *dev,
528 struct iw_request_info *info,
529 struct iw_point *wrq,
532 struct iw_range *range = (struct iw_range *)extra;
534 unsigned char abySupportedRates[13] = {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
536 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRANGE\n");
538 wrq->length = sizeof(struct iw_range);
539 memset(range, 0, sizeof(struct iw_range));
540 range->min_nwid = 0x0000;
541 range->max_nwid = 0x0000;
542 range->num_channels = 14;
543 // Should be based on cap_rid.country to give only
544 // what the current card support
546 for (i = 0; i < 14; i++) {
547 range->freq[k].i = i + 1; // List index
548 range->freq[k].m = frequency_list[i] * 100000;
549 range->freq[k++].e = 1; // Values in table in MHz -> * 10^5 * 10
551 range->num_frequency = k;
552 // Hum... Should put the right values there
553 #ifdef Calcu_LinkQual
554 range->max_qual.qual = 100;
556 range->max_qual.qual = 255;
558 range->max_qual.level = 0;
559 range->max_qual.noise = 0;
560 range->sensitivity = 255;
562 for (i = 0; i < 13; i++) {
563 range->bitrate[i] = abySupportedRates[i] * 500000;
564 if (range->bitrate[i] == 0)
567 range->num_bitrates = i;
569 // Set an indication of the max TCP throughput
570 // in bit/s that we can expect using this interface.
571 // May be use for QoS stuff... Jean II
573 range->throughput = 5 * 1000 * 1000;
575 range->throughput = 1.5 * 1000 * 1000;
578 range->max_rts = 2312;
579 range->min_frag = 256;
580 range->max_frag = 2312;
582 // the encoding capabilities
583 range->num_encoding_sizes = 3;
585 range->encoding_size[0] = 5;
587 range->encoding_size[1] = 13;
588 // 256 bits for WPA-PSK
589 range->encoding_size[2] = 32;
590 // 4 keys are allowed
591 range->max_encoding_tokens = 4;
593 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
594 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
597 range->max_pmp = 1000000;// 1 secs
599 range->max_pmt = 1000000;// 1 secs
600 range->pmp_flags = IW_POWER_PERIOD;
601 range->pmt_flags = IW_POWER_TIMEOUT;
602 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
604 // Transmit Power - values are in mW
606 range->txpower[0] = 100;
607 range->num_txpower = 1;
608 range->txpower_capa = IW_TXPOW_MWATT;
609 range->we_version_source = SUPPORTED_WIRELESS_EXT;
610 range->we_version_compiled = WIRELESS_EXT;
611 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
612 range->retry_flags = IW_RETRY_LIMIT;
613 range->r_time_flags = IW_RETRY_LIFETIME;
614 range->min_retry = 1;
615 range->max_retry = 65535;
616 range->min_r_time = 1024;
617 range->max_r_time = 65535 * 1024;
618 // Experimental measurements - boundary 11/5.5 Mb/s
619 // Note : with or without the (local->rssi), results
620 // are somewhat different. - Jean II
621 range->avg_qual.qual = 6;
622 range->avg_qual.level = 176; // -80 dBm
623 range->avg_qual.noise = 0;
630 * Wireless Handler : set ap mac address
633 int iwctl_siwap(struct net_device *dev,
634 struct iw_request_info *info,
635 struct sockaddr *wrq,
638 struct vnt_private *pDevice = netdev_priv(dev);
639 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
641 unsigned char ZeroBSSID[WLAN_BSSID_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
643 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAP\n");
644 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
646 pr_debug("SIOCSIWAP(??)-->In scanning..\n");
648 if (wrq->sa_family != ARPHRD_ETHER)
651 memcpy(pMgmt->abyDesireBSSID, wrq->sa_data, 6);
652 //2008-0409-05, <Add> by Einsn Liu
653 if ((pDevice->bLinkPass == true) &&
654 (memcmp(pMgmt->abyDesireBSSID, pMgmt->abyCurrBSSID, 6) == 0)) {
658 if ((is_broadcast_ether_addr(pMgmt->abyDesireBSSID)) ||
659 (memcmp(pMgmt->abyDesireBSSID, ZeroBSSID, 6) == 0)) {
660 PRINT_K("SIOCSIWAP:invalid desired BSSID return!\n");
663 //mike add: if desired AP is hidden ssid(there are two same BSSID in list),
664 // then ignore,because you don't known which one to be connect with??
666 unsigned int ii, uSameBssidNum = 0;
668 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
669 if (pMgmt->sBSSList[ii].bActive &&
670 ether_addr_equal(pMgmt->sBSSList[ii].abyBSSID,
671 pMgmt->abyDesireBSSID)) {
675 if (uSameBssidNum >= 2) { //hit: desired AP is in hidden ssid mode!!!
676 PRINT_K("SIOCSIWAP:ignore for desired AP in hidden mode\n");
681 if (pDevice->flags & DEVICE_FLAGS_OPENED)
682 pDevice->bCommit = true;
689 * Wireless Handler : get ap mac address
692 int iwctl_giwap(struct net_device *dev,
693 struct iw_request_info *info,
694 struct sockaddr *wrq,
697 struct vnt_private *pDevice = netdev_priv(dev);
698 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
700 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAP\n");
702 memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
703 //2008-0410,<Modify> by Einsn Liu
704 if ((pDevice->bLinkPass == false) && (pMgmt->eCurrMode != WMAC_MODE_ESS_AP))
705 memset(wrq->sa_data, 0, 6);
707 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)
708 memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
710 wrq->sa_family = ARPHRD_ETHER;
716 * Wireless Handler : get ap list
719 int iwctl_giwaplist(struct net_device *dev,
720 struct iw_request_info *info,
721 struct iw_point *wrq,
725 struct sockaddr *sock = NULL;
726 struct sockaddr *s = NULL;
727 struct iw_quality *qual = NULL;
728 struct iw_quality *q = NULL;
729 PKnownBSS pBSS = NULL;
731 struct vnt_private *pDevice = netdev_priv(dev);
732 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
734 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAPLIST\n");
736 if (!capable(CAP_NET_ADMIN)) {
744 sock = kmalloc_array(IW_MAX_AP, sizeof(struct sockaddr), GFP_KERNEL);
750 qual = kmalloc_array(IW_MAX_AP, sizeof(struct iw_quality), GFP_KERNEL);
756 for (ii = 0, jj = 0; ii < MAX_BSS_NUM; ii++) {
757 pBSS = &(pMgmt->sBSSList[ii]);
767 memcpy(s->sa_data, pBSS->abyBSSID, 6);
768 s->sa_family = ARPHRD_ETHER;
769 q->level = pBSS->uRSSI;
776 wrq->flags = 1; /* Should be define'd */
778 memcpy(extra, sock, sizeof(struct sockaddr) * jj);
779 memcpy(extra + sizeof(struct sockaddr) * jj,
781 sizeof(struct iw_quality) * jj);
789 * Wireless Handler : set essid
792 int iwctl_siwessid(struct net_device *dev,
793 struct iw_request_info *info,
794 struct iw_point *wrq,
797 struct vnt_private *pDevice = netdev_priv(dev);
798 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
799 PWLAN_IE_SSID pItemSSID;
800 //2008-0409-05, <Add> by Einsn Liu
803 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWESSID\n");
804 pDevice->fWPA_Authened = false;
805 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
807 pr_debug("SIOCSIWESSID(??)-->In scanning..\n");
809 // Check if we asked for `any'
810 if (wrq->flags == 0) {
811 // Just send an empty SSID list
812 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
813 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
814 PRINT_K("set essid to 'any'\n");
815 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
820 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
821 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
822 pItemSSID->byElementID = WLAN_EID_SSID;
824 memcpy(pItemSSID->abySSID, extra, wrq->length);
825 if (pItemSSID->abySSID[wrq->length - 1] == '\0') {
827 pItemSSID->len = wrq->length - 1;
829 pItemSSID->len = wrq->length;
830 pr_debug("set essid to %s\n", pItemSSID->abySSID);
831 //2008-0409-05, <Add> by Einsn Liu
832 len = (pItemSSID->len > ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) ? pItemSSID->len : ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len;
833 if ((pDevice->bLinkPass == true) &&
834 (memcmp(pItemSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID, len) == 0))
837 //mike:need clear desiredBSSID
838 if (pItemSSID->len == 0) {
839 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
843 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
844 //Wext wil order another command of siwap to link with desired AP,
845 //so here need not associate??
846 if (pDevice->bWPASuppWextEnabled == true) {
847 /*******search if in hidden ssid mode ****/
849 PKnownBSS pCurr = NULL;
850 unsigned char abyTmpDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
851 unsigned int ii, uSameBssidNum = 0;
853 memcpy(abyTmpDesireSSID, pMgmt->abyDesireSSID, sizeof(abyTmpDesireSSID));
854 pCurr = BSSpSearchBSSList(pDevice,
857 pMgmt->eConfigPHYMode
861 PRINT_K("SIOCSIWESSID:hidden ssid site survey before associate.......\n");
862 vResetCommandTimer((void *)pDevice);
863 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
864 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
865 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
866 } else { //mike:to find out if that desired SSID is a hidden-ssid AP ,
867 // by means of judging if there are two same BSSID exist in list ?
868 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
869 if (pMgmt->sBSSList[ii].bActive &&
870 ether_addr_equal(pMgmt->sBSSList[ii].abyBSSID,
875 if (uSameBssidNum >= 2) { //hit: desired AP is in hidden ssid mode!!!
876 pr_debug("SIOCSIWESSID:hidden ssid directly associate.......\n");
877 vResetCommandTimer((void *)pDevice);
878 pMgmt->eScanType = WMAC_SCAN_PASSIVE; //this scan type,you'll submit scan result!
879 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
880 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
888 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set essid = %s\n", pItemSSID->abySSID);
891 if (pDevice->flags & DEVICE_FLAGS_OPENED)
892 pDevice->bCommit = true;
898 * Wireless Handler : get essid
901 int iwctl_giwessid(struct net_device *dev,
902 struct iw_request_info *info,
903 struct iw_point *wrq,
906 struct vnt_private *pDevice = netdev_priv(dev);
907 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
908 PWLAN_IE_SSID pItemSSID;
910 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWESSID\n");
912 // Note : if wrq->u.data.flags != 0, we should
913 // get the relevant SSID from the SSID list...
915 // Get the current SSID
916 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
917 memcpy(extra, pItemSSID->abySSID , pItemSSID->len);
918 extra[pItemSSID->len] = '\0';
919 wrq->length = pItemSSID->len + 1;
920 //2008-0409-03, <Add> by Einsn Liu
921 wrq->length = pItemSSID->len;
922 wrq->flags = 1; // active
928 * Wireless Handler : set data rate
931 int iwctl_siwrate(struct net_device *dev,
932 struct iw_request_info *info,
933 struct iw_param *wrq,
936 struct vnt_private *pDevice = netdev_priv(dev);
940 unsigned char abySupportedRates[13] = {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
942 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRATE\n");
943 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
948 // First : get a valid bit rate value
950 // Which type of value
951 if ((wrq->value < 13) &&
953 // Setting by rate index
954 // Find value in the magic rate table
957 // Setting by frequency value
958 u8 normvalue = (u8) (wrq->value/500000);
960 // Check if rate is valid
961 for (i = 0; i < 13; i++) {
962 if (normvalue == abySupportedRates[i]) {
968 // -1 designed the max rate (mostly auto mode)
969 if (wrq->value == -1) {
970 // Get the highest available rate
971 for (i = 0; i < 13; i++) {
972 if (abySupportedRates[i] == 0)
979 // Check that it is valid
980 // brate is index of abySupportedRates[]
986 // Now, check if we want a fixed or auto value
987 if (wrq->fixed != 0) {
990 pr_debug("Rate Fix\n");
991 pDevice->bFixRate = true;
992 if ((pDevice->byBBType == BB_TYPE_11B) && (brate > 3)) {
993 pDevice->uConnectionRate = 3;
995 pDevice->uConnectionRate = brate;
996 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fixed to Rate %d\n", pDevice->uConnectionRate);
1000 pDevice->bFixRate = false;
1001 pDevice->uConnectionRate = 13;
1002 pr_debug("auto rate:connection_rate is 13\n");
1009 * Wireless Handler : get data rate
1012 int iwctl_giwrate(struct net_device *dev,
1013 struct iw_request_info *info,
1014 struct iw_param *wrq,
1017 struct vnt_private *pDevice = netdev_priv(dev);
1018 //2007-0118-05,<Mark> by EinsnLiu
1019 //Mark the unnecessary sentences.
1020 // PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1022 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRATE\n");
1024 unsigned char abySupportedRates[13] = {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
1026 //2008-5-8 <modify> by chester
1027 if (pDevice->bLinkPass) {
1028 if (pDevice->bFixRate == true) {
1029 if (pDevice->uConnectionRate < 13) {
1030 brate = abySupportedRates[pDevice->uConnectionRate];
1032 if (pDevice->byBBType == BB_TYPE_11B)
1034 if (pDevice->byBBType == BB_TYPE_11G)
1036 if (pDevice->byBBType == BB_TYPE_11A)
1040 brate = abySupportedRates[TxRate_iwconfig];
1044 wrq->value = brate * 500000;
1045 // If more than one rate, set auto
1046 if (pDevice->bFixRate == true)
1054 * Wireless Handler : set rts threshold
1057 int iwctl_siwrts(struct net_device *dev,
1058 struct iw_request_info *info,
1059 struct iw_param *wrq,
1062 struct vnt_private *pDevice = netdev_priv(dev);
1065 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRTS\n");
1068 int rthr = wrq->value;
1073 if ((rthr < 0) || (rthr > 2312))
1076 pDevice->wRTSThreshold = rthr;
1083 * Wireless Handler : get rts
1086 int iwctl_giwrts(struct net_device *dev,
1087 struct iw_request_info *info,
1088 struct iw_param *wrq,
1091 struct vnt_private *pDevice = netdev_priv(dev);
1093 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRTS\n");
1094 wrq->value = pDevice->wRTSThreshold;
1095 wrq->disabled = (wrq->value >= 2312);
1102 * Wireless Handler : set fragment threshold
1105 int iwctl_siwfrag(struct net_device *dev,
1106 struct iw_request_info *info,
1107 struct iw_param *wrq,
1110 struct vnt_private *pDevice = netdev_priv(dev);
1112 int fthr = wrq->value;
1114 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFRAG\n");
1118 if ((fthr < 256) || (fthr > 2312)) {
1121 fthr &= ~0x1; // Get an even value
1122 pDevice->wFragmentationThreshold = (u16)fthr;
1129 * Wireless Handler : get fragment threshold
1132 int iwctl_giwfrag(struct net_device *dev,
1133 struct iw_request_info *info,
1134 struct iw_param *wrq,
1137 struct vnt_private *pDevice = netdev_priv(dev);
1139 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFRAG\n");
1140 wrq->value = pDevice->wFragmentationThreshold;
1141 wrq->disabled = (wrq->value >= 2312);
1148 * Wireless Handler : set retry threshold
1150 int iwctl_siwretry(struct net_device *dev,
1151 struct iw_request_info *info,
1152 struct iw_param *wrq,
1155 struct vnt_private *pDevice = netdev_priv(dev);
1158 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRETRY\n");
1160 if (wrq->disabled) {
1165 if (wrq->flags & IW_RETRY_LIMIT) {
1166 if (wrq->flags & IW_RETRY_MAX)
1167 pDevice->byLongRetryLimit = wrq->value;
1168 else if (wrq->flags & IW_RETRY_MIN)
1169 pDevice->byShortRetryLimit = wrq->value;
1171 // No modifier : set both
1172 pDevice->byShortRetryLimit = wrq->value;
1173 pDevice->byLongRetryLimit = wrq->value;
1176 if (wrq->flags & IW_RETRY_LIFETIME)
1177 pDevice->wMaxTransmitMSDULifetime = wrq->value;
1183 * Wireless Handler : get retry threshold
1185 int iwctl_giwretry(struct net_device *dev,
1186 struct iw_request_info *info,
1187 struct iw_param *wrq,
1190 struct vnt_private *pDevice = netdev_priv(dev);
1192 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRETRY\n");
1193 wrq->disabled = 0; // Can't be disabled
1195 // Note : by default, display the min retry number
1196 if ((wrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1197 wrq->flags = IW_RETRY_LIFETIME;
1198 wrq->value = (int)pDevice->wMaxTransmitMSDULifetime; //ms
1199 } else if ((wrq->flags & IW_RETRY_MAX)) {
1200 wrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
1201 wrq->value = (int)pDevice->byLongRetryLimit;
1203 wrq->flags = IW_RETRY_LIMIT;
1204 wrq->value = (int)pDevice->byShortRetryLimit;
1205 if ((int)pDevice->byShortRetryLimit != (int)pDevice->byLongRetryLimit)
1206 wrq->flags |= IW_RETRY_MIN;
1213 * Wireless Handler : set encode mode
1215 int iwctl_siwencode(struct net_device *dev,
1216 struct iw_request_info *info,
1217 struct iw_point *wrq,
1220 struct vnt_private *pDevice = netdev_priv(dev);
1221 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1222 unsigned long dwKeyIndex = (unsigned long)(wrq->flags & IW_ENCODE_INDEX);
1224 int index = (wrq->flags & IW_ENCODE_INDEX);
1226 //2007-0207-07,<Modify> by EinsnLiu
1227 //There are some problems when using iwconfig encode/key command to set the WEP key.
1228 //I almost rewrite this function.
1229 //now it support:(assume the wireless interface's name is eth0)
1230 //iwconfig eth0 key [1] 1122334455 open /*set key stirng to index 1,and driver using key index is set to 1*/
1231 //iwconfig eth0 key [3] /*set driver using key index to 3,the key string no change */
1232 //iwconfig eth0 key 1122334455 /*set key string to driver using index*/
1233 //iwconfig eth0 key restricted /*enable share key*/
1237 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODE\n");
1239 if ((wrq->flags & IW_ENCODE_DISABLED) == 0) {
1240 //Not disable encryption
1242 if (dwKeyIndex > WLAN_WEP_NKEYS) {
1247 if (dwKeyIndex < 1 && ((wrq->flags & IW_ENCODE_NOKEY) == 0)) {//set default key
1248 if (pDevice->byKeyIndex < WLAN_WEP_NKEYS)
1249 dwKeyIndex = pDevice->byKeyIndex;
1256 // Check the size of the key
1257 if (wrq->length > WLAN_WEP232_KEYLEN) {
1262 if (wrq->length > 0) {//have key
1264 if (wrq->length == WLAN_WEP232_KEYLEN) {
1265 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 232 bit wep key\n");
1266 } else if (wrq->length == WLAN_WEP104_KEYLEN) {
1267 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 104 bit wep key\n");
1268 } else if (wrq->length == WLAN_WEP40_KEYLEN) {
1269 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 40 bit wep key, index= %d\n", (int)dwKeyIndex);
1270 } else {//no support length
1274 memset(pDevice->abyKey, 0, WLAN_WEP232_KEYLEN);
1275 memcpy(pDevice->abyKey, extra, wrq->length);
1277 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "abyKey: ");
1278 for (ii = 0; ii < wrq->length; ii++)
1279 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%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 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "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 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "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 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "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 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & ShareKey System\n");
1337 pMgmt->bShareKeyAlgorithm = true;
1339 if (wrq->flags & IW_ENCODE_OPEN) {
1340 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "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 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 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 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 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 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_UNICAST_R\n");
1442 case IW_POWER_ALL_R:
1443 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ALL_R\n");
1446 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 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 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 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 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 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 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 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,