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
46 static const long frequency_list[] = {
47 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
48 4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
49 5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210, 5220, 5230, 5240,
50 5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680,
51 5700, 5745, 5765, 5785, 5805, 5825
54 static int msglevel = MSG_LEVEL_INFO;
56 struct iw_statistics *iwctl_get_wireless_stats(struct net_device *dev)
58 struct vnt_private *pDevice = netdev_priv(dev);
61 pDevice->wstats.status = pDevice->eOPMode;
62 if (pDevice->scStatistic.LinkQuality > 100)
63 pDevice->scStatistic.LinkQuality = 100;
64 pDevice->wstats.qual.qual =(BYTE)pDevice->scStatistic.LinkQuality;
65 RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm);
66 pDevice->wstats.qual.level = ldBm;
67 pDevice->wstats.qual.noise = 0;
68 pDevice->wstats.qual.updated = 1;
69 pDevice->wstats.discard.nwid = 0;
70 pDevice->wstats.discard.code = 0;
71 pDevice->wstats.discard.fragment = 0;
72 pDevice->wstats.discard.retries = pDevice->scStatistic.dwTsrErr;
73 pDevice->wstats.discard.misc = 0;
74 pDevice->wstats.miss.beacon = 0;
75 return &pDevice->wstats;
79 * Wireless Handler: get protocol name
81 int iwctl_giwname(struct net_device *dev, struct iw_request_info *info,
82 union iwreq_data *wrqu, char *extra)
84 strcpy(wrqu->name, "802.11-a/b/g");
89 * Wireless Handler: set scan
91 int iwctl_siwscan(struct net_device *dev, struct iw_request_info *info,
92 union iwreq_data *wrqu, char *extra)
94 struct vnt_private *pDevice = netdev_priv(dev);
95 struct iw_point *wrq = &wrqu->data;
96 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
97 struct iw_scan_req *req = (struct iw_scan_req *)extra;
98 BYTE abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
99 PWLAN_IE_SSID pItemSSID = NULL;
101 if (!(pDevice->flags & DEVICE_FLAGS_OPENED))
104 PRINT_K(" SIOCSIWSCAN\n");
109 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
111 PRINT_K("SIOCSIWSCAN(overlap??)-->In scanning...\n");
115 if (pDevice->byReAssocCount > 0) { // reject scan when re-associating!
116 // send scan event to wpa_Supplicant
117 union iwreq_data wrqu;
118 PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
119 memset(&wrqu, 0, sizeof(wrqu));
120 wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
124 spin_lock_irq(&pDevice->lock);
126 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
128 // mike add: active scan OR passive scan OR desire_ssid scan
129 if (wrq->length == sizeof(struct iw_scan_req)) {
130 if (wrq->flags & IW_SCAN_THIS_ESSID) { // desire_ssid scan
131 memset(abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
132 pItemSSID = (PWLAN_IE_SSID)abyScanSSID;
133 pItemSSID->byElementID = WLAN_EID_SSID;
134 memcpy(pItemSSID->abySSID, req->essid, (int)req->essid_len);
135 if (pItemSSID->abySSID[req->essid_len] == '\0') {
136 if (req->essid_len > 0)
137 pItemSSID->len = req->essid_len;
139 pItemSSID->len = req->essid_len;
141 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
142 PRINT_K("SIOCSIWSCAN:[desired_ssid=%s,len=%d]\n", ((PWLAN_IE_SSID)abyScanSSID)->abySSID,
143 ((PWLAN_IE_SSID)abyScanSSID)->len);
144 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID);
145 spin_unlock_irq(&pDevice->lock);
148 } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) { // passive scan
149 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
151 } else { // active scan
152 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
155 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
156 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
157 spin_unlock_irq(&pDevice->lock);
163 * Wireless Handler : get scan results
165 int iwctl_giwscan(struct net_device *dev, struct iw_request_info *info,
166 union iwreq_data *wrqu, char *extra)
168 struct iw_point *wrq = &wrqu->data;
172 struct vnt_private *pDevice = netdev_priv(dev);
173 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
175 PWLAN_IE_SSID pItemSSID;
176 PWLAN_IE_SUPP_RATES pSuppRates;
177 PWLAN_IE_SUPP_RATES pExtSuppRates;
178 char *current_ev = extra;
179 char *end_buf = extra + IW_SCAN_MAX_DATA;
180 char *current_val = NULL;
184 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSCAN\n");
189 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
193 pBSS = &(pMgmt->sBSSList[0]);
194 for (ii = 0, jj = 0; jj < MAX_BSS_NUM ; jj++) {
195 if (current_ev >= end_buf)
197 pBSS = &(pMgmt->sBSSList[jj]);
200 memset(&iwe, 0, sizeof(iwe));
202 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
203 memcpy(iwe.u.ap_addr.sa_data, pBSS->abyBSSID, WLAN_BSSID_LEN);
204 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
206 memset(&iwe, 0, sizeof(iwe));
207 iwe.cmd = SIOCGIWESSID;
208 pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
209 iwe.u.data.length = pItemSSID->len;
210 iwe.u.data.flags = 1;
211 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pItemSSID->abySSID);
213 memset(&iwe, 0, sizeof(iwe));
214 iwe.cmd = SIOCGIWMODE;
215 if (WLAN_GET_CAP_INFO_ESS(pBSS->wCapInfo))
216 iwe.u.mode = IW_MODE_INFRA;
218 iwe.u.mode = IW_MODE_ADHOC;
219 iwe.len = IW_EV_UINT_LEN;
220 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
222 pSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abySuppRates;
223 pExtSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abyExtSuppRates;
224 memset(&iwe, 0, sizeof(iwe));
225 iwe.cmd = SIOCGIWFREQ;
226 iwe.u.freq.m = pBSS->uChannel;
229 current_ev = iwe_stream_add_event(info, current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
231 int f = (int)pBSS->uChannel - 1;
234 iwe.u.freq.m = frequency_list[f] * 100000;
237 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
239 memset(&iwe, 0, sizeof(iwe));
241 RFvRSSITodBm(pDevice, (BYTE)(pBSS->uRSSI), &ldBm);
242 iwe.u.qual.level = ldBm;
243 iwe.u.qual.noise = 0;
246 iwe.u.qual.qual = 100;
250 iwe.u.qual.qual = (40 - (-ldBm - 50)) * 100 / 40;
251 iwe.u.qual.updated = 7;
253 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
255 memset(&iwe, 0, sizeof(iwe));
256 iwe.cmd = SIOCGIWENCODE;
257 iwe.u.data.length = 0;
258 if (WLAN_GET_CAP_INFO_PRIVACY(pBSS->wCapInfo))
259 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
261 iwe.u.data.flags = IW_ENCODE_DISABLED;
262 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pItemSSID->abySSID);
264 memset(&iwe, 0, sizeof(iwe));
265 iwe.cmd = SIOCGIWRATE;
266 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
267 current_val = current_ev + IW_EV_LCP_LEN;
269 for (kk = 0; kk < 12; kk++) {
270 if (pSuppRates->abyRates[kk] == 0)
272 // Bit rate given in 500 kb/s units (+ 0x80)
273 iwe.u.bitrate.value = ((pSuppRates->abyRates[kk] & 0x7f) * 500000);
274 current_val = iwe_stream_add_value(info, current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
276 for (kk = 0; kk < 8; kk++) {
277 if (pExtSuppRates->abyRates[kk] == 0)
279 // Bit rate given in 500 kb/s units (+ 0x80)
280 iwe.u.bitrate.value = ((pExtSuppRates->abyRates[kk] & 0x7f) * 500000);
281 current_val = iwe_stream_add_value(info, current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
284 if ((current_val - current_ev) > IW_EV_LCP_LEN)
285 current_ev = current_val;
287 if ((pBSS->wWPALen > 0) && (pBSS->wWPALen <= MAX_WPA_IE_LEN)) {
288 memset(&iwe, 0, sizeof(iwe));
290 iwe.u.data.length = pBSS->wWPALen;
291 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pBSS->byWPAIE);
294 if ((pBSS->wRSNLen > 0) && (pBSS->wRSNLen <= MAX_WPA_IE_LEN)) {
295 memset(&iwe, 0, sizeof(iwe));
297 iwe.u.data.length = pBSS->wRSNLen;
298 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pBSS->byRSNIE);
302 wrq->length = current_ev - extra;
307 * Wireless Handler: set frequence or channel
309 int iwctl_siwfreq(struct net_device *dev, struct iw_request_info *info,
310 union iwreq_data *wrqu, char *extra)
312 struct vnt_private *pDevice = netdev_priv(dev);
313 struct iw_freq *wrq = &wrqu->freq;
316 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFREQ\n");
318 // If setting by frequency, convert to a channel
319 if ((wrq->e == 1) && (wrq->m >= (int)2.412e8) &&
320 (wrq->m <= (int)2.487e8)) {
321 int f = wrq->m / 100000;
323 while ((c < 14) && (f != frequency_list[c]))
328 // Setting by channel number
329 if ((wrq->m > 14) || (wrq->e > 0)) {
332 int channel = wrq->m;
333 if ((channel < 1) || (channel > 14)) {
334 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: New channel value of %d is invalid!\n", dev->name, wrq->m);
337 // Yes ! We can set it !!!
338 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Set to channel = %d\n", channel);
339 pDevice->uChannel = channel;
346 * Wireless Handler: get frequence or channel
348 int iwctl_giwfreq(struct net_device *dev, struct iw_request_info *info,
349 union iwreq_data *wrqu, char *extra)
351 struct vnt_private *pDevice = netdev_priv(dev);
352 struct iw_freq *wrq = &wrqu->freq;
353 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
355 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFREQ\n");
361 #ifdef WEXT_USECHANNELS
362 wrq->m = (int)pMgmt->uCurrChannel;
366 int f = (int)pMgmt->uCurrChannel - 1;
369 wrq->m = frequency_list[f] * 100000;
377 * Wireless Handler: set operation mode
379 int iwctl_siwmode(struct net_device *dev, struct iw_request_info *info,
380 union iwreq_data *wrqu, char *extra)
382 struct vnt_private *pDevice = netdev_priv(dev);
383 __u32 *wmode = &wrqu->mode;
384 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
387 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMODE\n");
392 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP && pDevice->bEnableHostapd) {
393 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
394 "Can't set operation mode, hostapd is running\n");
400 if (pMgmt->eConfigMode != WMAC_CONFIG_IBSS_STA) {
401 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
402 if (pDevice->flags & DEVICE_FLAGS_OPENED)
403 pDevice->bCommit = true;
405 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to ad-hoc \n");
409 if (pMgmt->eConfigMode != WMAC_CONFIG_ESS_STA) {
410 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
411 if (pDevice->flags & DEVICE_FLAGS_OPENED)
412 pDevice->bCommit = true;
414 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to infrastructure \n");
418 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
422 if (pMgmt->eConfigMode != WMAC_CONFIG_AP) {
423 pMgmt->eConfigMode = WMAC_CONFIG_AP;
424 if (pDevice->flags & DEVICE_FLAGS_OPENED)
425 pDevice->bCommit = true;
427 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to Access Point \n");
431 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
438 if (pDevice->bCommit) {
439 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
440 netif_stop_queue(pDevice->dev);
441 spin_lock_irq(&pDevice->lock);
442 bScheduleCommand((void *) pDevice,
443 WLAN_CMD_RUN_AP, NULL);
444 spin_unlock_irq(&pDevice->lock);
446 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
447 "Commit the settings\n");
449 spin_lock_irq(&pDevice->lock);
451 if (pDevice->bLinkPass &&
452 memcmp(pMgmt->abyCurrSSID,
453 pMgmt->abyDesireSSID,
454 WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN)) {
455 bScheduleCommand((void *) pDevice,
456 WLAN_CMD_DISASSOCIATE, NULL);
458 pDevice->bLinkPass = false;
459 pMgmt->eCurrState = WMAC_STATE_IDLE;
460 memset(pMgmt->abyCurrBSSID, 0, 6);
463 ControlvMaskByte(pDevice,
464 MESSAGE_REQUEST_MACREG, MAC_REG_PAPEDELAY,
465 LEDSTS_STS, LEDSTS_SLOW);
467 netif_stop_queue(pDevice->dev);
469 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
471 if (!pDevice->bWPASuppWextEnabled)
472 bScheduleCommand((void *) pDevice,
474 pMgmt->abyDesireSSID);
476 bScheduleCommand((void *) pDevice,
480 spin_unlock_irq(&pDevice->lock);
482 pDevice->bCommit = false;
490 * Wireless Handler: get operation mode
492 int iwctl_giwmode(struct net_device *dev, struct iw_request_info *info,
493 union iwreq_data *wrqu, char *extra)
495 struct vnt_private *pDevice = netdev_priv(dev);
496 __u32 *wmode = &wrqu->mode;
497 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
499 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWMODE\n");
504 // If not managed, assume it's ad-hoc
505 switch (pMgmt->eConfigMode) {
506 case WMAC_CONFIG_ESS_STA:
507 *wmode = IW_MODE_INFRA;
509 case WMAC_CONFIG_IBSS_STA:
510 *wmode = IW_MODE_ADHOC;
512 case WMAC_CONFIG_AUTO:
513 *wmode = IW_MODE_INFRA;
516 *wmode = IW_MODE_MASTER;
519 *wmode = IW_MODE_ADHOC;
526 * Wireless Handler: get capability range
528 int iwctl_giwrange(struct net_device *dev, struct iw_request_info *info,
529 union iwreq_data *wrqu, char *extra)
531 struct iw_point *wrq = &wrqu->data;
532 struct iw_range *range = (struct iw_range *)extra;
535 BYTE abySupportedRates[13] = {
536 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48,
540 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRANGE\n");
542 wrq->length = sizeof(struct iw_range);
543 memset(range, 0, sizeof(struct iw_range));
544 range->min_nwid = 0x0000;
545 range->max_nwid = 0x0000;
546 range->num_channels = 14;
547 // Should be based on cap_rid.country to give only
548 // what the current card support
550 for (i = 0; i < 14; i++) {
551 range->freq[k].i = i + 1; // List index
552 range->freq[k].m = frequency_list[i] * 100000;
553 range->freq[k++].e = 1; // Values in table in MHz -> * 10^5 * 10
555 range->num_frequency = k;
556 // Hum... Should put the right values there
557 range->max_qual.qual = 100;
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
605 range->txpower[0] = 100;
606 range->num_txpower = 1;
607 range->txpower_capa = IW_TXPOW_MWATT;
608 range->we_version_source = WIRELESS_EXT;
609 range->we_version_compiled = WIRELESS_EXT;
610 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
611 range->retry_flags = IW_RETRY_LIMIT;
612 range->r_time_flags = IW_RETRY_LIFETIME;
613 range->min_retry = 1;
614 range->max_retry = 65535;
615 range->min_r_time = 1024;
616 range->max_r_time = 65535 * 1024;
617 // Experimental measurements - boundary 11/5.5 Mb/s
618 // Note : with or without the (local->rssi), results
619 // are somewhat different. - Jean II
620 range->avg_qual.qual = 6;
621 range->avg_qual.level = 176; // -80 dBm
622 range->avg_qual.noise = 0;
629 * Wireless Handler : set ap mac address
631 int iwctl_siwap(struct net_device *dev, struct iw_request_info *info,
632 union iwreq_data *wrqu, char *extra)
634 struct vnt_private *pDevice = netdev_priv(dev);
635 struct sockaddr *wrq = &wrqu->ap_addr;
636 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
638 BYTE ZeroBSSID[WLAN_BSSID_LEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
640 PRINT_K(" SIOCSIWAP\n");
645 if (wrq->sa_family != ARPHRD_ETHER) {
648 memcpy(pMgmt->abyDesireBSSID, wrq->sa_data, 6);
650 if ((is_broadcast_ether_addr(pMgmt->abyDesireBSSID)) ||
651 (memcmp(pMgmt->abyDesireBSSID, ZeroBSSID, 6) == 0)) {
652 PRINT_K("SIOCSIWAP:invalid desired BSSID return!\n");
655 // mike add: if desired AP is hidden ssid(there are
656 // two same BSSID in list), then ignore,because you
657 // don't known which one to be connect with??
660 unsigned uSameBssidNum = 0;
661 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
662 if (pMgmt->sBSSList[ii].bActive &&
663 !compare_ether_addr(pMgmt->sBSSList[ii].abyBSSID,
664 pMgmt->abyDesireBSSID)) {
668 if (uSameBssidNum >= 2) { //hit: desired AP is in hidden ssid mode!!!
669 PRINT_K("SIOCSIWAP:ignore for desired AP in hidden mode\n");
674 if (pDevice->flags & DEVICE_FLAGS_OPENED)
675 pDevice->bCommit = true;
681 * Wireless Handler: get ap mac address
683 int iwctl_giwap(struct net_device *dev, struct iw_request_info *info,
684 union iwreq_data *wrqu, char *extra)
686 struct vnt_private *pDevice = netdev_priv(dev);
687 struct sockaddr *wrq = &wrqu->ap_addr;
688 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
690 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAP\n");
695 memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
697 if ((pDevice->bLinkPass == false) && (pMgmt->eCurrMode != WMAC_MODE_ESS_AP))
698 memset(wrq->sa_data, 0, 6);
700 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)
701 memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
703 wrq->sa_family = ARPHRD_ETHER;
708 * Wireless Handler: get ap list
710 int iwctl_giwaplist(struct net_device *dev, struct iw_request_info *info,
711 union iwreq_data *wrqu, char *extra)
713 struct iw_point *wrq = &wrqu->data;
714 struct sockaddr *sock;
715 struct iw_quality *qual;
716 struct vnt_private *pDevice = netdev_priv(dev);
717 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
718 PKnownBSS pBSS = &pMgmt->sBSSList[0];
722 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAPLIST\n");
723 /* Only super-user can see AP list */
728 if (!capable(CAP_NET_ADMIN))
734 sock = kzalloc(sizeof(struct sockaddr) * IW_MAX_AP, GFP_KERNEL);
737 qual = kzalloc(sizeof(struct iw_quality) * IW_MAX_AP, GFP_KERNEL);
743 for (ii = 0, jj = 0; ii < MAX_BSS_NUM; ii++) {
744 if (!pBSS[ii].bActive)
748 memcpy(sock[jj].sa_data, pBSS[ii].abyBSSID, 6);
749 sock[jj].sa_family = ARPHRD_ETHER;
750 qual[jj].level = pBSS[ii].uRSSI;
751 qual[jj].qual = qual[jj].noise = 0;
752 qual[jj].updated = 2;
756 wrq->flags = 1; /* Should be defined */
758 memcpy(extra, sock, sizeof(struct sockaddr) * jj);
759 memcpy(extra + sizeof(struct sockaddr) * jj, qual,
760 sizeof(struct iw_quality) * jj);
769 * Wireless Handler: set essid
771 int iwctl_siwessid(struct net_device *dev, struct iw_request_info *info,
772 union iwreq_data *wrqu, char *extra)
774 struct vnt_private *pDevice = netdev_priv(dev);
775 struct iw_point *wrq = &wrqu->essid;
776 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
777 PWLAN_IE_SSID pItemSSID;
782 if (!(pDevice->flags & DEVICE_FLAGS_OPENED))
785 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWESSID :\n");
787 pDevice->fWPA_Authened = false;
788 // Check if we asked for `any'
789 if (wrq->flags == 0) {
790 // Just send an empty SSID list
791 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
792 memset(pMgmt->abyDesireBSSID, 0xFF,6);
793 PRINT_K("set essid to 'any' \n");
794 // Unknown desired AP, so here need not associate??
798 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
799 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
800 pItemSSID->byElementID = WLAN_EID_SSID;
802 memcpy(pItemSSID->abySSID, extra, wrq->length);
803 if (pItemSSID->abySSID[wrq->length] == '\0') {
805 pItemSSID->len = wrq->length;
807 pItemSSID->len = wrq->length;
809 PRINT_K("set essid to %s \n", pItemSSID->abySSID);
811 // mike: need clear desiredBSSID
812 if (pItemSSID->len==0) {
813 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
817 // Wext wil order another command of siwap to link
818 // with desired AP, so here need not associate??
819 if (pDevice->bWPASuppWextEnabled == true) {
820 /*******search if in hidden ssid mode ****/
821 PKnownBSS pCurr = NULL;
822 BYTE abyTmpDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
824 unsigned uSameBssidNum = 0;
826 memcpy(abyTmpDesireSSID, pMgmt->abyDesireSSID, sizeof(abyTmpDesireSSID));
827 pCurr = BSSpSearchBSSList(pDevice, NULL,
829 pDevice->eConfigPHYMode);
832 PRINT_K("SIOCSIWESSID:hidden ssid site survey before associate.......\n");
833 vResetCommandTimer((void *)pDevice);
834 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
835 bScheduleCommand((void *)pDevice,
837 pMgmt->abyDesireSSID);
838 bScheduleCommand((void *)pDevice,
840 pMgmt->abyDesireSSID);
841 } else { // mike: to find out if that desired SSID is a
842 // hidden-ssid AP, by means of judging if there
843 // are two same BSSID exist in list ?
844 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
845 if (pMgmt->sBSSList[ii].bActive &&
846 !compare_ether_addr(pMgmt->sBSSList[ii].abyBSSID,
851 if (uSameBssidNum >= 2) { // hit: desired AP is in hidden ssid mode!!!
852 PRINT_K("SIOCSIWESSID:hidden ssid directly associate.......\n");
853 vResetCommandTimer((void *)pDevice);
854 pMgmt->eScanType = WMAC_SCAN_PASSIVE; // this scan type, you'll submit scan result!
855 bScheduleCommand((void *)pDevice,
857 pMgmt->abyDesireSSID);
858 bScheduleCommand((void *)pDevice,
860 pMgmt->abyDesireSSID);
866 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set essid = %s \n", pItemSSID->abySSID);
869 if (pDevice->flags & DEVICE_FLAGS_OPENED)
870 pDevice->bCommit = true;
876 * Wireless Handler: get essid
878 int iwctl_giwessid(struct net_device *dev, struct iw_request_info *info,
879 union iwreq_data *wrqu, char *extra)
881 struct vnt_private *pDevice = netdev_priv(dev);
882 struct iw_point *wrq = &wrqu->essid;
883 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
884 PWLAN_IE_SSID pItemSSID;
886 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWESSID\n");
891 // Note: if wrq->u.data.flags != 0, we should get the relevant
892 // SSID from the SSID list...
894 // Get the current SSID
895 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
896 memcpy(extra, pItemSSID->abySSID, pItemSSID->len);
897 extra[pItemSSID->len] = '\0';
899 wrq->length = pItemSSID->len;
900 wrq->flags = 1; // active
906 * Wireless Handler: set data rate
908 int iwctl_siwrate(struct net_device *dev, struct iw_request_info *info,
909 union iwreq_data *wrqu, char *extra)
911 struct vnt_private *pDevice = netdev_priv(dev);
912 struct iw_param *wrq = &wrqu->bitrate;
916 BYTE abySupportedRates[13] = {
917 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48,
921 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRATE \n");
922 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
927 // First: get a valid bit rate value
929 // Which type of value
930 if ((wrq->value < 13) && (wrq->value >= 0)) {
931 // Setting by rate index
932 // Find value in the magic rate table
935 // Setting by frequency value
936 u8 normvalue = (u8)(wrq->value/500000);
938 // Check if rate is valid
939 for (i = 0; i < 13; i++) {
940 if (normvalue == abySupportedRates[i]) {
946 // -1 designed the max rate (mostly auto mode)
947 if (wrq->value == -1) {
948 // Get the highest available rate
949 for (i = 0; i < 13; i++) {
950 if (abySupportedRates[i] == 0)
957 // Check that it is valid
958 // brate is index of abySupportedRates[]
964 // Now, check if we want a fixed or auto value
965 if (wrq->fixed != 0) {
968 pDevice->bFixRate = true;
969 if ((pDevice->byBBType == BB_TYPE_11B) && (brate > 3)) {
970 pDevice->uConnectionRate = 3;
972 pDevice->uConnectionRate = brate;
973 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fixed to Rate %d \n", pDevice->uConnectionRate);
976 pDevice->bFixRate = false;
977 pDevice->uConnectionRate = 13;
984 * Wireless Handler: get data rate
986 int iwctl_giwrate(struct net_device *dev, struct iw_request_info *info,
987 union iwreq_data *wrqu, char *extra)
989 struct vnt_private *pDevice = netdev_priv(dev);
990 struct iw_param *wrq = &wrqu->bitrate;
991 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
993 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRATE\n");
999 BYTE abySupportedRates[13] = {
1000 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30,
1001 0x48, 0x60, 0x6C, 0x90
1005 if (pDevice->uConnectionRate < 13) {
1006 brate = abySupportedRates[pDevice->uConnectionRate];
1008 if (pDevice->byBBType == BB_TYPE_11B)
1010 if (pDevice->byBBType == BB_TYPE_11G)
1012 if (pDevice->byBBType == BB_TYPE_11A)
1015 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1016 if (pDevice->byBBType == BB_TYPE_11B)
1018 if (pDevice->byBBType == BB_TYPE_11G)
1020 if (pDevice->byBBType == BB_TYPE_11A)
1023 if (pDevice->uConnectionRate == 13)
1024 brate = abySupportedRates[pDevice->wCurrentRate];
1025 wrq->value = brate * 500000;
1026 // If more than one rate, set auto
1027 if (pDevice->bFixRate == true)
1035 * Wireless Handler: set rts threshold
1037 int iwctl_siwrts(struct net_device *dev, struct iw_request_info *info,
1038 union iwreq_data *wrqu, char *extra)
1040 struct vnt_private *pDevice = netdev_priv(dev);
1041 struct iw_param *wrq = &wrqu->rts;
1043 if ((wrq->value < 0 || wrq->value > 2312) && !wrq->disabled)
1046 else if (wrq->disabled)
1047 pDevice->wRTSThreshold = 2312;
1049 pDevice->wRTSThreshold = wrq->value;
1055 * Wireless Handler: get rts
1057 int iwctl_giwrts(struct net_device *dev, struct iw_request_info *info,
1058 union iwreq_data *wrqu, char *extra)
1060 struct vnt_private *pDevice = netdev_priv(dev);
1061 struct iw_param *wrq = &wrqu->rts;
1063 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRTS\n");
1064 wrq->value = pDevice->wRTSThreshold;
1065 wrq->disabled = (wrq->value >= 2312);
1071 * Wireless Handler: set fragment threshold
1073 int iwctl_siwfrag(struct net_device *dev, struct iw_request_info *info,
1074 union iwreq_data *wrqu, char *extra)
1076 struct vnt_private *pDevice = netdev_priv(dev);
1077 struct iw_param *wrq = &wrqu->frag;
1079 int fthr = wrq->value;
1081 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFRAG\n");
1085 if ((fthr < 256) || (fthr > 2312)) {
1088 fthr &= ~0x1; // Get an even value
1089 pDevice->wFragmentationThreshold = (u16)fthr;
1095 * Wireless Handler: get fragment threshold
1097 int iwctl_giwfrag(struct net_device *dev, struct iw_request_info *info,
1098 union iwreq_data *wrqu, char *extra)
1100 struct vnt_private *pDevice = netdev_priv(dev);
1101 struct iw_param *wrq = &wrqu->frag;
1103 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFRAG\n");
1104 wrq->value = pDevice->wFragmentationThreshold;
1105 wrq->disabled = (wrq->value >= 2312);
1111 * Wireless Handler: set retry threshold
1113 int iwctl_siwretry(struct net_device *dev, struct iw_request_info *info,
1114 union iwreq_data *wrqu, char *extra)
1116 struct vnt_private *pDevice = netdev_priv(dev);
1117 struct iw_param *wrq = &wrqu->retry;
1120 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRETRY\n");
1122 if (wrq->disabled) {
1127 if (wrq->flags & IW_RETRY_LIMIT) {
1128 if (wrq->flags & IW_RETRY_MAX) {
1129 pDevice->byLongRetryLimit = wrq->value;
1130 } else if (wrq->flags & IW_RETRY_MIN) {
1131 pDevice->byShortRetryLimit = wrq->value;
1133 // No modifier : set both
1134 pDevice->byShortRetryLimit = wrq->value;
1135 pDevice->byLongRetryLimit = wrq->value;
1138 if (wrq->flags & IW_RETRY_LIFETIME)
1139 pDevice->wMaxTransmitMSDULifetime = wrq->value;
1144 * Wireless Handler: get retry threshold
1146 int iwctl_giwretry(struct net_device *dev, struct iw_request_info *info,
1147 union iwreq_data *wrqu, char *extra)
1149 struct vnt_private *pDevice = netdev_priv(dev);
1150 struct iw_param *wrq = &wrqu->retry;
1151 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRETRY\n");
1152 wrq->disabled = 0; // Can't be disabled
1154 // Note: by default, display the min retry number
1155 if ((wrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1156 wrq->flags = IW_RETRY_LIFETIME;
1157 wrq->value = (int)pDevice->wMaxTransmitMSDULifetime; // ms
1158 } else if ((wrq->flags & IW_RETRY_MAX)) {
1159 wrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
1160 wrq->value = (int)pDevice->byLongRetryLimit;
1162 wrq->flags = IW_RETRY_LIMIT;
1163 wrq->value = (int)pDevice->byShortRetryLimit;
1164 if ((int)pDevice->byShortRetryLimit != (int)pDevice->byLongRetryLimit)
1165 wrq->flags |= IW_RETRY_MIN;
1171 * Wireless Handler: set encode mode
1173 int iwctl_siwencode(struct net_device *dev, struct iw_request_info *info,
1174 union iwreq_data *wrqu, char *extra)
1176 struct vnt_private *pDevice = netdev_priv(dev);
1177 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1178 struct iw_point *wrq = &wrqu->encoding;
1179 u32 dwKeyIndex = (u32)(wrq->flags & IW_ENCODE_INDEX);
1183 int index = (wrq->flags & IW_ENCODE_INDEX);
1185 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODE\n");
1190 // Check the size of the key
1191 if (wrq->length > WLAN_WEP232_KEYLEN) {
1196 if (dwKeyIndex > WLAN_WEP_NKEYS) {
1204 // Send the key to the card
1205 if (wrq->length > 0) {
1206 if (wrq->length == WLAN_WEP232_KEYLEN) {
1207 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 232 bit wep key\n");
1208 } else if (wrq->length == WLAN_WEP104_KEYLEN) {
1209 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 104 bit wep key\n");
1210 } else if (wrq->length == WLAN_WEP40_KEYLEN) {
1211 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 40 bit wep key, index= %d\n", (int)dwKeyIndex);
1213 memset(pDevice->abyKey, 0, WLAN_WEP232_KEYLEN);
1214 memcpy(pDevice->abyKey, extra, wrq->length);
1216 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyKey: ");
1217 for (ii = 0; ii < wrq->length; ii++)
1218 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pDevice->abyKey[ii]);
1220 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1221 spin_lock_irq(&pDevice->lock);
1222 KeybSetDefaultKey(pDevice,
1224 dwKeyIndex | (1 << 31),
1228 spin_unlock_irq(&pDevice->lock);
1230 pDevice->byKeyIndex = (BYTE)dwKeyIndex;
1231 pDevice->uKeyLength = wrq->length;
1232 pDevice->bTransmitKey = true;
1233 pDevice->bEncryptionEnable = true;
1234 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1236 // Do we want to just set the transmit key index?
1238 pDevice->byKeyIndex = index;
1239 } else if (!(wrq->flags & IW_ENCODE_MODE)) {
1245 if (wrq->flags & IW_ENCODE_DISABLED) {
1246 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable WEP function\n");
1247 pMgmt->bShareKeyAlgorithm = false;
1248 pDevice->bEncryptionEnable = false;
1249 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1250 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1251 spin_lock_irq(&pDevice->lock);
1252 for (uu = 0; uu < MAX_KEY_TABLE; uu++)
1253 MACvDisableKeyEntry(pDevice, uu);
1254 spin_unlock_irq(&pDevice->lock);
1257 if (wrq->flags & IW_ENCODE_RESTRICTED) {
1258 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & ShareKey System\n");
1259 pMgmt->bShareKeyAlgorithm = true;
1261 if (wrq->flags & IW_ENCODE_OPEN) {
1262 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & Open System\n");
1263 pMgmt->bShareKeyAlgorithm = false;
1266 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
1271 int iwctl_giwencode(struct net_device *dev, struct iw_request_info *info,
1272 union iwreq_data *wrqu, char *extra)
1274 struct vnt_private *pDevice = netdev_priv(dev);
1275 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1276 struct iw_point *wrq = &wrqu->encoding;
1277 char abyKey[WLAN_WEP232_KEYLEN];
1279 unsigned index = (unsigned)(wrq->flags & IW_ENCODE_INDEX);
1280 PSKeyItem pKey = NULL;
1282 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODE\n");
1287 if (index > WLAN_WEP_NKEYS)
1289 if (index < 1) { // get default key
1290 if (pDevice->byKeyIndex < WLAN_WEP_NKEYS)
1291 index = pDevice->byKeyIndex;
1298 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
1299 // Check encryption mode
1300 wrq->flags = IW_ENCODE_NOKEY;
1301 // Is WEP enabled ???
1302 if (pDevice->bEncryptionEnable)
1303 wrq->flags |= IW_ENCODE_ENABLED;
1305 wrq->flags |= IW_ENCODE_DISABLED;
1307 if (pMgmt->bShareKeyAlgorithm)
1308 wrq->flags |= IW_ENCODE_RESTRICTED;
1310 wrq->flags |= IW_ENCODE_OPEN;
1313 if ((index == 0) && (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled ||
1314 pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)) { // get wpa pairwise key
1315 if (KeybGetKey(&(pDevice->sKey), pMgmt->abyCurrBSSID, 0xffffffff, &pKey)) {
1316 wrq->length = pKey->uKeyLength;
1317 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1318 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1320 } else if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (BYTE)index, &pKey)) {
1321 wrq->length = pKey->uKeyLength;
1322 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1323 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1326 wrq->flags |= index + 1;
1331 * Wireless Handler: set power mode
1333 int iwctl_siwpower(struct net_device *dev, struct iw_request_info *info,
1334 union iwreq_data *wrqu, char *extra)
1336 struct vnt_private *pDevice = netdev_priv(dev);
1337 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1338 struct iw_param *wrq = &wrqu->power;
1341 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER\n");
1346 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
1351 if (wrq->disabled) {
1352 pDevice->ePSMode = WMAC_POWER_CAM;
1353 PSvDisablePowerSaving(pDevice);
1356 if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1357 pDevice->ePSMode = WMAC_POWER_FAST;
1358 PSvEnablePowerSaving((void *)pDevice, pMgmt->wListenInterval);
1360 } else if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
1361 pDevice->ePSMode = WMAC_POWER_FAST;
1362 PSvEnablePowerSaving((void *)pDevice, pMgmt->wListenInterval);
1364 switch (wrq->flags & IW_POWER_MODE) {
1365 case IW_POWER_UNICAST_R:
1366 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_UNICAST_R \n");
1369 case IW_POWER_ALL_R:
1370 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ALL_R \n");
1373 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ON \n");
1383 * Wireless Handler: get power mode
1385 int iwctl_giwpower(struct net_device *dev, struct iw_request_info *info,
1386 union iwreq_data *wrqu, char *extra)
1388 struct vnt_private *pDevice = netdev_priv(dev);
1389 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1390 struct iw_param *wrq = &wrqu->power;
1391 int mode = pDevice->ePSMode;
1393 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPOWER\n");
1398 if ((wrq->disabled = (mode == WMAC_POWER_CAM)))
1401 if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1402 wrq->value = (int)((pMgmt->wListenInterval *
1403 pMgmt->wCurrBeaconPeriod) / 100);
1404 wrq->flags = IW_POWER_TIMEOUT;
1406 wrq->value = (int)((pMgmt->wListenInterval *
1407 pMgmt->wCurrBeaconPeriod) / 100);
1408 wrq->flags = IW_POWER_PERIOD;
1411 wrq->flags |= IW_POWER_ALL_R;
1416 * Wireless Handler: get Sensitivity
1418 int iwctl_giwsens(struct net_device *dev, struct iw_request_info *info,
1419 union iwreq_data *wrqu, char *extra)
1421 struct vnt_private *pDevice = netdev_priv(dev);
1422 struct iw_param *wrq = &wrqu->sens;
1425 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSENS\n");
1426 if (pDevice->bLinkPass == true) {
1427 RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm);
1432 wrq->disabled = (wrq->value == 0);
1437 int iwctl_siwauth(struct net_device *dev, struct iw_request_info *info,
1438 union iwreq_data *wrqu, char *extra)
1440 struct vnt_private *pDevice = netdev_priv(dev);
1441 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1442 struct iw_param *wrq = &wrqu->param;
1444 static int wpa_version = 0; // must be static to save the last value, einsn liu
1445 static int pairwise = 0;
1450 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH\n");
1451 switch (wrq->flags & IW_AUTH_INDEX) {
1452 case IW_AUTH_WPA_VERSION:
1453 wpa_version = wrq->value;
1454 if (wrq->value == IW_AUTH_WPA_VERSION_DISABLED) {
1455 PRINT_K("iwctl_siwauth:set WPADEV to disable at 1??????\n");
1456 } else if (wrq->value == IW_AUTH_WPA_VERSION_WPA) {
1457 PRINT_K("iwctl_siwauth:set WPADEV to WPA1******\n");
1459 PRINT_K("iwctl_siwauth:set WPADEV to WPA2******\n");
1462 case IW_AUTH_CIPHER_PAIRWISE:
1463 pairwise = wrq->value;
1464 PRINT_K("iwctl_siwauth:set pairwise=%d\n", pairwise);
1465 if (pairwise == IW_AUTH_CIPHER_CCMP){
1466 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1467 } else if (pairwise == IW_AUTH_CIPHER_TKIP) {
1468 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1469 } else if (pairwise == IW_AUTH_CIPHER_WEP40 ||
1470 pairwise == IW_AUTH_CIPHER_WEP104) {
1471 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1472 } else if (pairwise == IW_AUTH_CIPHER_NONE) {
1473 // do nothing, einsn liu
1475 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1478 case IW_AUTH_CIPHER_GROUP:
1479 PRINT_K("iwctl_siwauth:set GROUP=%d\n", wrq->value);
1480 if (wpa_version == IW_AUTH_WPA_VERSION_DISABLED)
1482 if (pairwise == IW_AUTH_CIPHER_NONE) {
1483 if (wrq->value == IW_AUTH_CIPHER_CCMP)
1484 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1486 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1489 case IW_AUTH_KEY_MGMT:
1490 PRINT_K("iwctl_siwauth(wpa_version=%d):set KEY_MGMT=%d\n", wpa_version,wrq->value);
1491 if (wpa_version == IW_AUTH_WPA_VERSION_WPA2){
1492 if (wrq->value == IW_AUTH_KEY_MGMT_PSK)
1493 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
1494 else pMgmt->eAuthenMode = WMAC_AUTH_WPA2;
1495 } else if (wpa_version == IW_AUTH_WPA_VERSION_WPA) {
1496 if (wrq->value == 0){
1497 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
1498 } else if (wrq->value == IW_AUTH_KEY_MGMT_PSK)
1499 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
1501 pMgmt->eAuthenMode = WMAC_AUTH_WPA;
1504 case IW_AUTH_TKIP_COUNTERMEASURES:
1506 case IW_AUTH_DROP_UNENCRYPTED:
1508 case IW_AUTH_80211_AUTH_ALG:
1509 PRINT_K("iwctl_siwauth:set AUTH_ALG=%d\n", wrq->value);
1510 if (wrq->value == IW_AUTH_ALG_OPEN_SYSTEM)
1511 pMgmt->bShareKeyAlgorithm = false;
1512 else if (wrq->value == IW_AUTH_ALG_SHARED_KEY)
1513 pMgmt->bShareKeyAlgorithm = true;
1515 case IW_AUTH_WPA_ENABLED:
1517 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1519 case IW_AUTH_ROAMING_CONTROL:
1522 case IW_AUTH_PRIVACY_INVOKED:
1523 pDevice->bEncryptionEnable = !!wrq->value;
1524 if (pDevice->bEncryptionEnable == false) {
1527 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1528 pMgmt->bShareKeyAlgorithm = false;
1529 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
1530 PRINT_K("iwctl_siwauth:set WPADEV to disaable at 2?????\n");
1534 PRINT_K("iwctl_siwauth: not supported %x\n", wrq->flags);
1541 int iwctl_giwauth(struct net_device *dev, struct iw_request_info *info,
1542 union iwreq_data *wrqu, char *extra)
1547 int iwctl_siwgenie(struct net_device *dev, struct iw_request_info *info,
1548 union iwreq_data *wrqu, char *extra)
1550 struct vnt_private *pDevice = netdev_priv(dev);
1551 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1552 struct iw_point *wrq = &wrqu->data;
1559 if ((wrq->length < 2) || (extra[1] + 2 != wrq->length)) {
1563 if (wrq->length > MAX_WPA_IE_LEN){
1567 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
1568 if (copy_from_user(pMgmt->abyWPAIE, extra, wrq->length)){
1572 pMgmt->wWPAIELen = wrq->length;
1574 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
1575 pMgmt->wWPAIELen = 0;
1578 out: // not completely ...not necessary in wpa_supplicant 0.5.8
1582 int iwctl_giwgenie(struct net_device *dev, struct iw_request_info *info,
1583 union iwreq_data *wrqu, char *extra)
1585 struct vnt_private *pDevice = netdev_priv(dev);
1586 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1587 struct iw_point *wrq = &wrqu->data;
1589 int space = wrq->length;
1595 if (pMgmt->wWPAIELen > 0) {
1596 wrq->length = pMgmt->wWPAIELen;
1597 if (pMgmt->wWPAIELen <= space) {
1598 if (copy_to_user(extra, pMgmt->abyWPAIE, pMgmt->wWPAIELen)) {
1608 int iwctl_siwencodeext(struct net_device *dev, struct iw_request_info *info,
1609 union iwreq_data *wrqu, char *extra)
1611 struct vnt_private *pDevice = netdev_priv(dev);
1612 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1613 struct iw_point *wrq = &wrqu->encoding;
1614 struct iw_encode_ext *ext = (struct iw_encode_ext*)extra;
1615 struct viawget_wpa_param *param=NULL;
1621 u8 seq[IW_ENCODE_SEQ_MAX_SIZE];
1629 PRINT_K("SIOCSIWENCODEEXT......\n");
1634 buf = kzalloc(sizeof(struct viawget_wpa_param), GFP_KERNEL);
1638 param = (struct viawget_wpa_param *)buf;
1642 case IW_ENCODE_ALG_NONE:
1643 alg_name = WPA_ALG_NONE;
1645 case IW_ENCODE_ALG_WEP:
1646 alg_name = WPA_ALG_WEP;
1648 case IW_ENCODE_ALG_TKIP:
1649 alg_name = WPA_ALG_TKIP;
1651 case IW_ENCODE_ALG_CCMP:
1652 alg_name = WPA_ALG_CCMP;
1655 PRINT_K("Unknown alg = %d\n",ext->alg);
1660 memcpy(addr, ext->addr.sa_data, ETH_ALEN);
1662 key_idx = (wrq->flags&IW_ENCODE_INDEX) - 1;
1664 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
1666 // recover seq,seq_len
1667 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
1668 seq_len=IW_ENCODE_SEQ_MAX_SIZE;
1669 memcpy(seq, ext->rx_seq, seq_len);
1671 // recover key,key_len
1673 key_len = ext->key_len;
1674 memcpy(key, &ext->key[0], key_len);
1676 memset(key_array, 0, 64);
1678 memcpy(key_array, key, key_len);
1679 if (key_len == 32) {
1680 // notice ! the oder
1681 memcpy(&key_array[16], &key[24], 8);
1682 memcpy(&key_array[24], &key[16], 8);
1686 /**************Translate iw_encode_ext to viawget_wpa_param****************/
1687 memcpy(param->addr, addr, ETH_ALEN);
1688 param->u.wpa_key.alg_name = (int)alg_name;
1689 param->u.wpa_key.set_tx = set_tx;
1690 param->u.wpa_key.key_index = key_idx;
1691 param->u.wpa_key.key_len = key_len;
1692 param->u.wpa_key.key = (u8 *)key_array;
1693 param->u.wpa_key.seq = (u8 *)seq;
1694 param->u.wpa_key.seq_len = seq_len;
1696 /****set if current action is Network Manager count?? */
1697 /****this method is so foolish,but there is no other way??? */
1698 if (param->u.wpa_key.alg_name == WPA_ALG_NONE) {
1699 if (param->u.wpa_key.key_index ==0) {
1700 pDevice->bwextstep0 = true;
1702 if ((pDevice->bwextstep0 == true) && (param->u.wpa_key.key_index == 1)) {
1703 pDevice->bwextstep0 = false;
1704 pDevice->bwextstep1 = true;
1706 if ((pDevice->bwextstep1 == true) && (param->u.wpa_key.key_index == 2)) {
1707 pDevice->bwextstep1 = false;
1708 pDevice->bwextstep2 = true;
1710 if ((pDevice->bwextstep2 == true) && (param->u.wpa_key.key_index == 3)) {
1711 pDevice->bwextstep2 = false;
1712 pDevice->bwextstep3 = true;
1715 if (pDevice->bwextstep3 == true) {
1716 PRINT_K("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n");
1717 pDevice->bwextstep0 = false;
1718 pDevice->bwextstep1 = false;
1719 pDevice->bwextstep2 = false;
1720 pDevice->bwextstep3 = false;
1721 pDevice->bWPASuppWextEnabled = true;
1722 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
1723 KeyvInitTable(pDevice, &pDevice->sKey);
1726 spin_lock_irq(&pDevice->lock);
1727 ret = wpa_set_keys(pDevice, param);
1728 spin_unlock_irq(&pDevice->lock);
1735 int iwctl_giwencodeext(struct net_device *dev, struct iw_request_info *info,
1736 union iwreq_data *wrqu, char *extra)
1741 int iwctl_siwmlme(struct net_device *dev, struct iw_request_info *info,
1742 union iwreq_data *wrqu, char *extra)
1744 struct vnt_private *pDevice = netdev_priv(dev);
1745 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1746 struct iw_mlme *mlme = (struct iw_mlme *)extra;
1749 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMLME\n");
1754 if (memcmp(pMgmt->abyCurrBSSID, mlme->addr.sa_data, ETH_ALEN)) {
1759 case IW_MLME_DEAUTH:
1760 case IW_MLME_DISASSOC:
1761 if (pDevice->bLinkPass == true) {
1762 PRINT_K("iwctl_siwmlme--->send DISASSOCIATE\n");
1763 bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE,
1773 static int iwctl_config_commit(struct net_device *dev,
1774 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1776 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "SIOCSIWCOMMIT\n");
1781 static const iw_handler iwctl_handler[] = {
1782 IW_HANDLER(SIOCSIWCOMMIT, iwctl_config_commit),
1783 IW_HANDLER(SIOCGIWNAME, iwctl_giwname),
1784 IW_HANDLER(SIOCSIWFREQ, iwctl_siwfreq),
1785 IW_HANDLER(SIOCGIWFREQ, iwctl_giwfreq),
1786 IW_HANDLER(SIOCSIWMODE, iwctl_siwmode),
1787 IW_HANDLER(SIOCGIWMODE, iwctl_giwmode),
1788 IW_HANDLER(SIOCGIWSENS, iwctl_giwsens),
1789 IW_HANDLER(SIOCGIWRANGE, iwctl_giwrange),
1790 IW_HANDLER(SIOCSIWAP, iwctl_siwap),
1791 IW_HANDLER(SIOCGIWAP, iwctl_giwap),
1792 IW_HANDLER(SIOCSIWMLME, iwctl_siwmlme),
1793 IW_HANDLER(SIOCGIWAPLIST, iwctl_giwaplist),
1794 IW_HANDLER(SIOCSIWSCAN, iwctl_siwscan),
1795 IW_HANDLER(SIOCGIWSCAN, iwctl_giwscan),
1796 IW_HANDLER(SIOCSIWESSID, iwctl_siwessid),
1797 IW_HANDLER(SIOCGIWESSID, iwctl_giwessid),
1798 IW_HANDLER(SIOCSIWRATE, iwctl_siwrate),
1799 IW_HANDLER(SIOCGIWRATE, iwctl_giwrate),
1800 IW_HANDLER(SIOCSIWRTS, iwctl_siwrts),
1801 IW_HANDLER(SIOCGIWRTS, iwctl_giwrts),
1802 IW_HANDLER(SIOCSIWFRAG, iwctl_siwfrag),
1803 IW_HANDLER(SIOCGIWFRAG, iwctl_giwfrag),
1804 IW_HANDLER(SIOCSIWRETRY, iwctl_siwretry),
1805 IW_HANDLER(SIOCGIWRETRY, iwctl_giwretry),
1806 IW_HANDLER(SIOCSIWENCODE, iwctl_siwencode),
1807 IW_HANDLER(SIOCGIWENCODE, iwctl_giwencode),
1808 IW_HANDLER(SIOCSIWPOWER, iwctl_siwpower),
1809 IW_HANDLER(SIOCGIWPOWER, iwctl_giwpower),
1810 IW_HANDLER(SIOCSIWGENIE, iwctl_siwgenie),
1811 IW_HANDLER(SIOCGIWGENIE, iwctl_giwgenie),
1812 IW_HANDLER(SIOCSIWMLME, iwctl_siwmlme),
1813 IW_HANDLER(SIOCSIWAUTH, iwctl_siwauth),
1814 IW_HANDLER(SIOCGIWAUTH, iwctl_giwauth),
1815 IW_HANDLER(SIOCSIWENCODEEXT, iwctl_siwencodeext),
1816 IW_HANDLER(SIOCGIWENCODEEXT, iwctl_giwencodeext)
1819 static const iw_handler iwctl_private_handler[] = {
1820 NULL, // SIOCIWFIRSTPRIV
1823 const struct iw_handler_def iwctl_handler_def = {
1824 .get_wireless_stats = &iwctl_get_wireless_stats,
1825 .num_standard = ARRAY_SIZE(iwctl_handler),
1827 .num_private_args = 0,
1828 .standard = iwctl_handler,
1830 .private_args = NULL,