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
44 static const long frequency_list[] = {
45 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
46 4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
47 5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210, 5220, 5230, 5240,
48 5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680,
49 5700, 5745, 5765, 5785, 5805, 5825
52 static int msglevel = MSG_LEVEL_INFO;
54 struct iw_statistics *iwctl_get_wireless_stats(struct net_device *dev)
56 struct vnt_private *pDevice = netdev_priv(dev);
59 pDevice->wstats.status = pDevice->op_mode;
60 RFvRSSITodBm(pDevice, (u8)(pDevice->uCurrRSSI), &ldBm);
61 pDevice->wstats.qual.level = ldBm;
62 pDevice->wstats.qual.noise = 0;
63 pDevice->wstats.qual.updated = 1;
64 pDevice->wstats.discard.nwid = 0;
65 pDevice->wstats.discard.code = 0;
66 pDevice->wstats.discard.fragment = 0;
67 pDevice->wstats.discard.misc = 0;
68 pDevice->wstats.miss.beacon = 0;
69 return &pDevice->wstats;
73 * Wireless Handler: get protocol name
75 int iwctl_giwname(struct net_device *dev, struct iw_request_info *info,
76 union iwreq_data *wrqu, char *extra)
78 strcpy(wrqu->name, "802.11-a/b/g");
83 * Wireless Handler: set scan
85 int iwctl_siwscan(struct net_device *dev, struct iw_request_info *info,
86 union iwreq_data *wrqu, char *extra)
88 struct vnt_private *pDevice = netdev_priv(dev);
89 struct iw_point *wrq = &wrqu->data;
90 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
91 struct iw_scan_req *req = (struct iw_scan_req *)extra;
92 u8 abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
93 PWLAN_IE_SSID pItemSSID = NULL;
96 if (!(pDevice->flags & DEVICE_FLAGS_OPENED))
99 PRINT_K(" SIOCSIWSCAN\n");
104 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
106 PRINT_K("SIOCSIWSCAN(overlap??)-->In scanning...\n");
110 if (pDevice->byReAssocCount > 0) { // reject scan when re-associating!
111 // send scan event to wpa_Supplicant
112 union iwreq_data wrqu;
113 PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
114 memset(&wrqu, 0, sizeof(wrqu));
115 wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
119 spin_lock_irqsave(&pDevice->lock, flags);
121 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
123 // mike add: active scan OR passive scan OR desire_ssid scan
124 if (wrq->length == sizeof(struct iw_scan_req)) {
125 if (wrq->flags & IW_SCAN_THIS_ESSID) { // desire_ssid scan
126 memset(abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
127 pItemSSID = (PWLAN_IE_SSID)abyScanSSID;
128 pItemSSID->byElementID = WLAN_EID_SSID;
129 memcpy(pItemSSID->abySSID, req->essid, (int)req->essid_len);
130 if (pItemSSID->abySSID[req->essid_len] == '\0') {
131 if (req->essid_len > 0)
132 pItemSSID->len = req->essid_len;
134 pItemSSID->len = req->essid_len;
136 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
137 PRINT_K("SIOCSIWSCAN:[desired_ssid=%s,len=%d]\n", ((PWLAN_IE_SSID)abyScanSSID)->abySSID,
138 ((PWLAN_IE_SSID)abyScanSSID)->len);
139 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID);
141 spin_unlock_irqrestore(&pDevice->lock, flags);
144 } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) { // passive scan
145 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
147 } else { // active scan
148 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
151 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
152 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
154 spin_unlock_irqrestore(&pDevice->lock, flags);
160 * Wireless Handler : get scan results
162 int iwctl_giwscan(struct net_device *dev, struct iw_request_info *info,
163 union iwreq_data *wrqu, char *extra)
165 struct iw_point *wrq = &wrqu->data;
169 struct vnt_private *pDevice = netdev_priv(dev);
170 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
172 PWLAN_IE_SSID pItemSSID;
173 PWLAN_IE_SUPP_RATES pSuppRates;
174 PWLAN_IE_SUPP_RATES pExtSuppRates;
175 char *current_ev = extra;
176 char *end_buf = extra + IW_SCAN_MAX_DATA;
177 char *current_val = NULL;
181 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSCAN\n");
186 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
190 pBSS = &(pMgmt->sBSSList[0]);
191 for (ii = 0, jj = 0; jj < MAX_BSS_NUM; jj++) {
192 if (current_ev >= end_buf)
194 pBSS = &(pMgmt->sBSSList[jj]);
197 memset(&iwe, 0, sizeof(iwe));
199 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
200 memcpy(iwe.u.ap_addr.sa_data, pBSS->abyBSSID, WLAN_BSSID_LEN);
201 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
203 memset(&iwe, 0, sizeof(iwe));
204 iwe.cmd = SIOCGIWESSID;
205 pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
206 iwe.u.data.length = pItemSSID->len;
207 iwe.u.data.flags = 1;
208 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pItemSSID->abySSID);
210 memset(&iwe, 0, sizeof(iwe));
211 iwe.cmd = SIOCGIWMODE;
212 if (WLAN_GET_CAP_INFO_ESS(pBSS->wCapInfo))
213 iwe.u.mode = IW_MODE_INFRA;
215 iwe.u.mode = IW_MODE_ADHOC;
216 iwe.len = IW_EV_UINT_LEN;
217 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
219 pSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abySuppRates;
220 pExtSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abyExtSuppRates;
221 memset(&iwe, 0, sizeof(iwe));
222 iwe.cmd = SIOCGIWFREQ;
223 iwe.u.freq.m = pBSS->uChannel;
226 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
228 int f = (int)pBSS->uChannel - 1;
231 iwe.u.freq.m = frequency_list[f] * 100000;
234 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
236 memset(&iwe, 0, sizeof(iwe));
238 RFvRSSITodBm(pDevice, (u8)(pBSS->uRSSI), &ldBm);
239 iwe.u.qual.level = ldBm;
240 iwe.u.qual.noise = 0;
243 iwe.u.qual.qual = 100;
247 iwe.u.qual.qual = (40 - (-ldBm - 50)) * 100 / 40;
248 iwe.u.qual.updated = 7;
250 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
252 memset(&iwe, 0, sizeof(iwe));
253 iwe.cmd = SIOCGIWENCODE;
254 iwe.u.data.length = 0;
255 if (WLAN_GET_CAP_INFO_PRIVACY(pBSS->wCapInfo))
256 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
258 iwe.u.data.flags = IW_ENCODE_DISABLED;
259 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pItemSSID->abySSID);
261 memset(&iwe, 0, sizeof(iwe));
262 iwe.cmd = SIOCGIWRATE;
263 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
264 current_val = current_ev + IW_EV_LCP_LEN;
266 for (kk = 0; kk < 12; kk++) {
267 if (pSuppRates->abyRates[kk] == 0)
269 // Bit rate given in 500 kb/s units (+ 0x80)
270 iwe.u.bitrate.value = ((pSuppRates->abyRates[kk] & 0x7f) * 500000);
271 current_val = iwe_stream_add_value(info, current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
273 for (kk = 0; kk < 8; kk++) {
274 if (pExtSuppRates->abyRates[kk] == 0)
276 // Bit rate given in 500 kb/s units (+ 0x80)
277 iwe.u.bitrate.value = ((pExtSuppRates->abyRates[kk] & 0x7f) * 500000);
278 current_val = iwe_stream_add_value(info, current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
281 if ((current_val - current_ev) > IW_EV_LCP_LEN)
282 current_ev = current_val;
284 if ((pBSS->wWPALen > 0) && (pBSS->wWPALen <= MAX_WPA_IE_LEN)) {
285 memset(&iwe, 0, sizeof(iwe));
287 iwe.u.data.length = pBSS->wWPALen;
288 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pBSS->byWPAIE);
291 if ((pBSS->wRSNLen > 0) && (pBSS->wRSNLen <= MAX_WPA_IE_LEN)) {
292 memset(&iwe, 0, sizeof(iwe));
294 iwe.u.data.length = pBSS->wRSNLen;
295 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pBSS->byRSNIE);
299 wrq->length = current_ev - extra;
304 * Wireless Handler: set frequence or channel
306 int iwctl_siwfreq(struct net_device *dev, struct iw_request_info *info,
307 union iwreq_data *wrqu, char *extra)
309 struct vnt_private *pDevice = netdev_priv(dev);
310 struct iw_freq *wrq = &wrqu->freq;
313 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFREQ\n");
315 // If setting by frequency, convert to a channel
316 if ((wrq->e == 1) && (wrq->m >= (int)2.412e8) &&
317 (wrq->m <= (int)2.487e8)) {
318 int f = wrq->m / 100000;
320 while ((c < 14) && (f != frequency_list[c]))
325 // Setting by channel number
326 if ((wrq->m > 14) || (wrq->e > 0)) {
329 int channel = wrq->m;
330 if ((channel < 1) || (channel > 14)) {
331 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: New channel value of %d is invalid!\n", dev->name, wrq->m);
334 // Yes ! We can set it !!!
335 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Set to channel = %d\n", channel);
336 pDevice->uChannel = channel;
343 * Wireless Handler: get frequence or channel
345 int iwctl_giwfreq(struct net_device *dev, struct iw_request_info *info,
346 union iwreq_data *wrqu, char *extra)
348 struct vnt_private *pDevice = netdev_priv(dev);
349 struct iw_freq *wrq = &wrqu->freq;
350 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
352 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFREQ\n");
357 #ifdef WEXT_USECHANNELS
358 wrq->m = (int)pMgmt->uCurrChannel;
362 int f = (int)pMgmt->uCurrChannel - 1;
365 wrq->m = frequency_list[f] * 100000;
373 * Wireless Handler: set operation mode
375 int iwctl_siwmode(struct net_device *dev, struct iw_request_info *info,
376 union iwreq_data *wrqu, char *extra)
378 struct vnt_private *pDevice = netdev_priv(dev);
379 __u32 *wmode = &wrqu->mode;
380 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
384 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMODE\n");
391 if (pMgmt->eConfigMode != WMAC_CONFIG_IBSS_STA) {
392 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
393 if (pDevice->flags & DEVICE_FLAGS_OPENED)
394 pDevice->bCommit = true;
396 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to ad-hoc\n");
400 if (pMgmt->eConfigMode != WMAC_CONFIG_ESS_STA) {
401 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
402 if (pDevice->flags & DEVICE_FLAGS_OPENED)
403 pDevice->bCommit = true;
405 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to infrastructure\n");
412 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
419 if (pDevice->bCommit) {
420 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
421 netif_stop_queue(pDevice->dev);
423 spin_lock_irqsave(&pDevice->lock, flags);
425 bScheduleCommand((void *) pDevice,
426 WLAN_CMD_RUN_AP, NULL);
428 spin_unlock_irqrestore(&pDevice->lock, flags);
430 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
431 "Commit the settings\n");
433 if (pDevice->bLinkPass &&
434 memcmp(pMgmt->abyCurrSSID,
435 pMgmt->abyDesireSSID,
436 WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN)) {
437 bScheduleCommand((void *) pDevice,
438 WLAN_CMD_DISASSOCIATE, NULL);
440 pDevice->bLinkPass = false;
441 pMgmt->eCurrState = WMAC_STATE_IDLE;
442 memset(pMgmt->abyCurrBSSID, 0, 6);
445 ControlvMaskByte(pDevice,
446 MESSAGE_REQUEST_MACREG, MAC_REG_PAPEDELAY,
447 LEDSTS_STS, LEDSTS_SLOW);
449 netif_stop_queue(pDevice->dev);
451 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
453 if (!pDevice->bWPASuppWextEnabled)
454 bScheduleCommand((void *) pDevice,
456 pMgmt->abyDesireSSID);
458 bScheduleCommand((void *) pDevice,
462 pDevice->bCommit = false;
469 * Wireless Handler: get operation mode
471 int iwctl_giwmode(struct net_device *dev, struct iw_request_info *info,
472 union iwreq_data *wrqu, char *extra)
474 struct vnt_private *pDevice = netdev_priv(dev);
475 __u32 *wmode = &wrqu->mode;
476 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
478 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWMODE\n");
483 // If not managed, assume it's ad-hoc
484 switch (pMgmt->eConfigMode) {
485 case WMAC_CONFIG_ESS_STA:
486 *wmode = IW_MODE_INFRA;
488 case WMAC_CONFIG_IBSS_STA:
489 *wmode = IW_MODE_ADHOC;
491 case WMAC_CONFIG_AUTO:
492 *wmode = IW_MODE_INFRA;
495 *wmode = IW_MODE_MASTER;
498 *wmode = IW_MODE_ADHOC;
505 * Wireless Handler: get capability range
507 int iwctl_giwrange(struct net_device *dev, struct iw_request_info *info,
508 union iwreq_data *wrqu, char *extra)
510 struct iw_point *wrq = &wrqu->data;
511 struct iw_range *range = (struct iw_range *)extra;
514 u8 abySupportedRates[13] = {
515 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48,
519 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRANGE\n");
521 wrq->length = sizeof(struct iw_range);
522 memset(range, 0, sizeof(struct iw_range));
523 range->min_nwid = 0x0000;
524 range->max_nwid = 0x0000;
525 range->num_channels = 14;
526 // Should be based on cap_rid.country to give only
527 // what the current card support
529 for (i = 0; i < 14; i++) {
530 range->freq[k].i = i + 1; // List index
531 range->freq[k].m = frequency_list[i] * 100000;
532 range->freq[k++].e = 1; // Values in table in MHz -> * 10^5 * 10
534 range->num_frequency = k;
535 // Hum... Should put the right values there
536 range->max_qual.qual = 100;
537 range->max_qual.level = 0;
538 range->max_qual.noise = 0;
539 range->sensitivity = 255;
541 for (i = 0; i < 13; i++) {
542 range->bitrate[i] = abySupportedRates[i] * 500000;
543 if (range->bitrate[i] == 0)
546 range->num_bitrates = i;
548 // Set an indication of the max TCP throughput
549 // in bit/s that we can expect using this interface.
550 // May be use for QoS stuff... Jean II
552 range->throughput = 5 * 1000 * 1000;
554 range->throughput = 1.5 * 1000 * 1000;
557 range->max_rts = 2312;
558 range->min_frag = 256;
559 range->max_frag = 2312;
561 // the encoding capabilities
562 range->num_encoding_sizes = 3;
564 range->encoding_size[0] = 5;
566 range->encoding_size[1] = 13;
567 // 256 bits for WPA-PSK
568 range->encoding_size[2] = 32;
569 // 4 keys are allowed
570 range->max_encoding_tokens = 4;
572 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
573 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
576 range->max_pmp = 1000000; // 1 secs
578 range->max_pmt = 1000000; // 1 secs
579 range->pmp_flags = IW_POWER_PERIOD;
580 range->pmt_flags = IW_POWER_TIMEOUT;
581 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
583 // Transmit Power - values are in mW
584 range->txpower[0] = 100;
585 range->num_txpower = 1;
586 range->txpower_capa = IW_TXPOW_MWATT;
587 range->we_version_source = WIRELESS_EXT;
588 range->we_version_compiled = WIRELESS_EXT;
589 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
590 range->retry_flags = IW_RETRY_LIMIT;
591 range->r_time_flags = IW_RETRY_LIFETIME;
592 range->min_retry = 1;
593 range->max_retry = 65535;
594 range->min_r_time = 1024;
595 range->max_r_time = 65535 * 1024;
596 // Experimental measurements - boundary 11/5.5 Mb/s
597 // Note : with or without the (local->rssi), results
598 // are somewhat different. - Jean II
599 range->avg_qual.qual = 6;
600 range->avg_qual.level = 176; // -80 dBm
601 range->avg_qual.noise = 0;
608 * Wireless Handler : set ap mac address
610 int iwctl_siwap(struct net_device *dev, struct iw_request_info *info,
611 union iwreq_data *wrqu, char *extra)
613 struct vnt_private *pDevice = netdev_priv(dev);
614 struct sockaddr *wrq = &wrqu->ap_addr;
615 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
617 u8 ZeroBSSID[WLAN_BSSID_LEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
619 PRINT_K(" SIOCSIWAP\n");
624 if (wrq->sa_family != ARPHRD_ETHER) {
627 memcpy(pMgmt->abyDesireBSSID, wrq->sa_data, 6);
629 if ((is_broadcast_ether_addr(pMgmt->abyDesireBSSID)) ||
630 (memcmp(pMgmt->abyDesireBSSID, ZeroBSSID, 6) == 0)) {
631 PRINT_K("SIOCSIWAP:invalid desired BSSID return!\n");
634 // mike add: if desired AP is hidden ssid(there are
635 // two same BSSID in list), then ignore,because you
636 // don't known which one to be connect with??
639 unsigned uSameBssidNum = 0;
640 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
641 if (pMgmt->sBSSList[ii].bActive &&
642 ether_addr_equal(pMgmt->sBSSList[ii].abyBSSID,
643 pMgmt->abyDesireBSSID)) {
647 if (uSameBssidNum >= 2) { //hit: desired AP is in hidden ssid mode!!!
648 PRINT_K("SIOCSIWAP:ignore for desired AP in hidden mode\n");
653 if (pDevice->flags & DEVICE_FLAGS_OPENED)
654 pDevice->bCommit = true;
660 * Wireless Handler: get ap mac address
662 int iwctl_giwap(struct net_device *dev, struct iw_request_info *info,
663 union iwreq_data *wrqu, char *extra)
665 struct vnt_private *pDevice = netdev_priv(dev);
666 struct sockaddr *wrq = &wrqu->ap_addr;
667 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
669 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAP\n");
674 memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
676 if ((pDevice->bLinkPass == false) && (pMgmt->eCurrMode != WMAC_MODE_ESS_AP))
677 memset(wrq->sa_data, 0, 6);
679 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)
680 memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
682 wrq->sa_family = ARPHRD_ETHER;
687 * Wireless Handler: get ap list
689 int iwctl_giwaplist(struct net_device *dev, struct iw_request_info *info,
690 union iwreq_data *wrqu, char *extra)
692 struct iw_point *wrq = &wrqu->data;
693 struct sockaddr *sock;
694 struct iw_quality *qual;
695 struct vnt_private *pDevice = netdev_priv(dev);
696 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
697 PKnownBSS pBSS = &pMgmt->sBSSList[0];
701 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAPLIST\n");
702 /* Only super-user can see AP list */
707 if (!capable(CAP_NET_ADMIN))
713 sock = kcalloc(IW_MAX_AP, sizeof(struct sockaddr), GFP_KERNEL);
716 qual = kcalloc(IW_MAX_AP, sizeof(struct iw_quality), GFP_KERNEL);
722 for (ii = 0, jj = 0; ii < MAX_BSS_NUM; ii++) {
723 if (!pBSS[ii].bActive)
727 memcpy(sock[jj].sa_data, pBSS[ii].abyBSSID, 6);
728 sock[jj].sa_family = ARPHRD_ETHER;
729 qual[jj].level = pBSS[ii].uRSSI;
730 qual[jj].qual = qual[jj].noise = 0;
731 qual[jj].updated = 2;
735 wrq->flags = 1; /* Should be defined */
737 memcpy(extra, sock, sizeof(struct sockaddr) * jj);
738 memcpy(extra + sizeof(struct sockaddr) * jj, qual,
739 sizeof(struct iw_quality) * jj);
748 * Wireless Handler: set essid
750 int iwctl_siwessid(struct net_device *dev, struct iw_request_info *info,
751 union iwreq_data *wrqu, char *extra)
753 struct vnt_private *pDevice = netdev_priv(dev);
754 struct iw_point *wrq = &wrqu->essid;
755 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
756 PWLAN_IE_SSID pItemSSID;
761 if (!(pDevice->flags & DEVICE_FLAGS_OPENED))
764 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWESSID :\n");
766 pDevice->fWPA_Authened = false;
767 // Check if we asked for `any'
768 if (wrq->flags == 0) {
769 // Just send an empty SSID list
770 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
771 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
772 PRINT_K("set essid to 'any'\n");
773 // Unknown desired AP, so here need not associate??
777 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
778 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
779 pItemSSID->byElementID = WLAN_EID_SSID;
781 memcpy(pItemSSID->abySSID, extra, wrq->length);
782 if (pItemSSID->abySSID[wrq->length] == '\0') {
784 pItemSSID->len = wrq->length;
786 pItemSSID->len = wrq->length;
788 PRINT_K("set essid to %s\n", pItemSSID->abySSID);
790 // mike: need clear desiredBSSID
791 if (pItemSSID->len == 0) {
792 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
796 // Wext wil order another command of siwap to link
797 // with desired AP, so here need not associate??
798 if (pDevice->bWPASuppWextEnabled == true) {
799 /*******search if in hidden ssid mode ****/
800 PKnownBSS pCurr = NULL;
801 u8 abyTmpDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
803 unsigned uSameBssidNum = 0;
805 memcpy(abyTmpDesireSSID, pMgmt->abyDesireSSID, sizeof(abyTmpDesireSSID));
806 pCurr = BSSpSearchBSSList(pDevice, NULL,
808 pDevice->eConfigPHYMode);
811 PRINT_K("SIOCSIWESSID:hidden ssid site survey before associate.......\n");
812 vResetCommandTimer((void *)pDevice);
813 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
814 bScheduleCommand((void *)pDevice,
816 pMgmt->abyDesireSSID);
817 bScheduleCommand((void *)pDevice,
819 pMgmt->abyDesireSSID);
820 } else { // mike: to find out if that desired SSID is a
821 // hidden-ssid AP, by means of judging if there
822 // are two same BSSID exist in list ?
823 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
824 if (pMgmt->sBSSList[ii].bActive &&
825 ether_addr_equal(pMgmt->sBSSList[ii].abyBSSID,
830 if (uSameBssidNum >= 2) { // hit: desired AP is in hidden ssid mode!!!
831 PRINT_K("SIOCSIWESSID:hidden ssid directly associate.......\n");
832 vResetCommandTimer((void *)pDevice);
833 pMgmt->eScanType = WMAC_SCAN_PASSIVE; // this scan type, you'll submit scan result!
834 bScheduleCommand((void *)pDevice,
836 pMgmt->abyDesireSSID);
837 bScheduleCommand((void *)pDevice,
839 pMgmt->abyDesireSSID);
845 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set essid = %s\n", pItemSSID->abySSID);
848 if (pDevice->flags & DEVICE_FLAGS_OPENED)
849 pDevice->bCommit = true;
855 * Wireless Handler: get essid
857 int iwctl_giwessid(struct net_device *dev, struct iw_request_info *info,
858 union iwreq_data *wrqu, char *extra)
860 struct vnt_private *pDevice = netdev_priv(dev);
861 struct iw_point *wrq = &wrqu->essid;
862 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
863 PWLAN_IE_SSID pItemSSID;
865 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWESSID\n");
870 // Note: if wrq->u.data.flags != 0, we should get the relevant
871 // SSID from the SSID list...
873 // Get the current SSID
874 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
875 memcpy(extra, pItemSSID->abySSID, pItemSSID->len);
876 extra[pItemSSID->len] = '\0';
878 wrq->length = pItemSSID->len;
879 wrq->flags = 1; // active
885 * Wireless Handler: set data rate
887 int iwctl_siwrate(struct net_device *dev, struct iw_request_info *info,
888 union iwreq_data *wrqu, char *extra)
890 struct vnt_private *pDevice = netdev_priv(dev);
891 struct iw_param *wrq = &wrqu->bitrate;
895 u8 abySupportedRates[13] = {
896 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48,
900 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRATE\n");
901 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
906 // First: get a valid bit rate value
908 // Which type of value
909 if ((wrq->value < 13) && (wrq->value >= 0)) {
910 // Setting by rate index
911 // Find value in the magic rate table
914 // Setting by frequency value
915 u8 normvalue = (u8)(wrq->value/500000);
917 // Check if rate is valid
918 for (i = 0; i < 13; i++) {
919 if (normvalue == abySupportedRates[i]) {
925 // -1 designed the max rate (mostly auto mode)
926 if (wrq->value == -1) {
927 // Get the highest available rate
928 for (i = 0; i < 13; i++) {
929 if (abySupportedRates[i] == 0)
936 // Check that it is valid
937 // brate is index of abySupportedRates[]
943 // Now, check if we want a fixed or auto value
944 if (wrq->fixed != 0) {
947 pDevice->bFixRate = true;
948 if ((pDevice->byBBType == BB_TYPE_11B) && (brate > 3)) {
949 pDevice->uConnectionRate = 3;
951 pDevice->uConnectionRate = brate;
952 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fixed to Rate %d\n", pDevice->uConnectionRate);
955 pDevice->bFixRate = false;
956 pDevice->uConnectionRate = 13;
963 * Wireless Handler: get data rate
965 int iwctl_giwrate(struct net_device *dev, struct iw_request_info *info,
966 union iwreq_data *wrqu, char *extra)
968 struct vnt_private *pDevice = netdev_priv(dev);
969 struct iw_param *wrq = &wrqu->bitrate;
970 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
972 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRATE\n");
978 u8 abySupportedRates[13] = {
979 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30,
980 0x48, 0x60, 0x6C, 0x90
984 if (pDevice->uConnectionRate < 13) {
985 brate = abySupportedRates[pDevice->uConnectionRate];
987 if (pDevice->byBBType == BB_TYPE_11B)
989 if (pDevice->byBBType == BB_TYPE_11G)
991 if (pDevice->byBBType == BB_TYPE_11A)
994 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
995 if (pDevice->byBBType == BB_TYPE_11B)
997 if (pDevice->byBBType == BB_TYPE_11G)
999 if (pDevice->byBBType == BB_TYPE_11A)
1002 if (pDevice->uConnectionRate == 13)
1003 brate = abySupportedRates[pDevice->wCurrentRate];
1004 wrq->value = brate * 500000;
1005 // If more than one rate, set auto
1006 if (pDevice->bFixRate == true)
1014 * Wireless Handler: set rts threshold
1016 int iwctl_siwrts(struct net_device *dev, struct iw_request_info *info,
1017 union iwreq_data *wrqu, char *extra)
1019 struct vnt_private *pDevice = netdev_priv(dev);
1020 struct iw_param *wrq = &wrqu->rts;
1022 if ((wrq->value < 0 || wrq->value > 2312) && !wrq->disabled)
1025 else if (wrq->disabled)
1026 pDevice->wRTSThreshold = 2312;
1028 pDevice->wRTSThreshold = wrq->value;
1034 * Wireless Handler: get rts
1036 int iwctl_giwrts(struct net_device *dev, struct iw_request_info *info,
1037 union iwreq_data *wrqu, char *extra)
1039 struct vnt_private *pDevice = netdev_priv(dev);
1040 struct iw_param *wrq = &wrqu->rts;
1042 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRTS\n");
1043 wrq->value = pDevice->wRTSThreshold;
1044 wrq->disabled = (wrq->value >= 2312);
1050 * Wireless Handler: set fragment threshold
1052 int iwctl_siwfrag(struct net_device *dev, struct iw_request_info *info,
1053 union iwreq_data *wrqu, char *extra)
1055 struct vnt_private *pDevice = netdev_priv(dev);
1056 struct iw_param *wrq = &wrqu->frag;
1058 int fthr = wrq->value;
1060 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFRAG\n");
1064 if ((fthr < 256) || (fthr > 2312)) {
1067 fthr &= ~0x1; // Get an even value
1068 pDevice->wFragmentationThreshold = (u16)fthr;
1074 * Wireless Handler: get fragment threshold
1076 int iwctl_giwfrag(struct net_device *dev, struct iw_request_info *info,
1077 union iwreq_data *wrqu, char *extra)
1079 struct vnt_private *pDevice = netdev_priv(dev);
1080 struct iw_param *wrq = &wrqu->frag;
1082 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFRAG\n");
1083 wrq->value = pDevice->wFragmentationThreshold;
1084 wrq->disabled = (wrq->value >= 2312);
1090 * Wireless Handler: set retry threshold
1092 int iwctl_siwretry(struct net_device *dev, struct iw_request_info *info,
1093 union iwreq_data *wrqu, char *extra)
1095 struct vnt_private *pDevice = netdev_priv(dev);
1096 struct iw_param *wrq = &wrqu->retry;
1099 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRETRY\n");
1101 if (wrq->disabled) {
1106 if (wrq->flags & IW_RETRY_LIMIT) {
1107 if (wrq->flags & IW_RETRY_MAX) {
1108 pDevice->byLongRetryLimit = wrq->value;
1109 } else if (wrq->flags & IW_RETRY_MIN) {
1110 pDevice->byShortRetryLimit = wrq->value;
1112 // No modifier : set both
1113 pDevice->byShortRetryLimit = wrq->value;
1114 pDevice->byLongRetryLimit = wrq->value;
1117 if (wrq->flags & IW_RETRY_LIFETIME)
1118 pDevice->wMaxTransmitMSDULifetime = wrq->value;
1123 * Wireless Handler: get retry threshold
1125 int iwctl_giwretry(struct net_device *dev, struct iw_request_info *info,
1126 union iwreq_data *wrqu, char *extra)
1128 struct vnt_private *pDevice = netdev_priv(dev);
1129 struct iw_param *wrq = &wrqu->retry;
1130 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRETRY\n");
1131 wrq->disabled = 0; // Can't be disabled
1133 // Note: by default, display the min retry number
1134 if ((wrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1135 wrq->flags = IW_RETRY_LIFETIME;
1136 wrq->value = (int)pDevice->wMaxTransmitMSDULifetime; // ms
1137 } else if ((wrq->flags & IW_RETRY_MAX)) {
1138 wrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
1139 wrq->value = (int)pDevice->byLongRetryLimit;
1141 wrq->flags = IW_RETRY_LIMIT;
1142 wrq->value = (int)pDevice->byShortRetryLimit;
1143 if ((int)pDevice->byShortRetryLimit != (int)pDevice->byLongRetryLimit)
1144 wrq->flags |= IW_RETRY_MIN;
1150 * Wireless Handler: set encode mode
1152 int iwctl_siwencode(struct net_device *dev, struct iw_request_info *info,
1153 union iwreq_data *wrqu, char *extra)
1155 struct vnt_private *pDevice = netdev_priv(dev);
1156 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1157 struct iw_point *wrq = &wrqu->encoding;
1158 u32 dwKeyIndex = (u32)(wrq->flags & IW_ENCODE_INDEX);
1162 int index = (wrq->flags & IW_ENCODE_INDEX);
1164 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODE\n");
1169 // Check the size of the key
1170 if (wrq->length > WLAN_WEP232_KEYLEN) {
1175 if (dwKeyIndex > WLAN_WEP_NKEYS) {
1183 // Send the key to the card
1184 if (wrq->length > 0) {
1185 if (wrq->length == WLAN_WEP232_KEYLEN) {
1186 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 232 bit wep key\n");
1187 } else if (wrq->length == WLAN_WEP104_KEYLEN) {
1188 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 104 bit wep key\n");
1189 } else if (wrq->length == WLAN_WEP40_KEYLEN) {
1190 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 40 bit wep key, index= %d\n", (int)dwKeyIndex);
1192 memset(pDevice->abyKey, 0, WLAN_WEP232_KEYLEN);
1193 memcpy(pDevice->abyKey, extra, wrq->length);
1195 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyKey: ");
1196 for (ii = 0; ii < wrq->length; ii++)
1197 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pDevice->abyKey[ii]);
1199 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1200 KeybSetDefaultKey(pDevice,
1202 dwKeyIndex | (1 << 31),
1207 pDevice->byKeyIndex = (u8)dwKeyIndex;
1208 pDevice->uKeyLength = wrq->length;
1209 pDevice->bTransmitKey = true;
1210 pDevice->bEncryptionEnable = true;
1211 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1213 // Do we want to just set the transmit key index?
1215 pDevice->byKeyIndex = index;
1216 } else if (!(wrq->flags & IW_ENCODE_MODE)) {
1222 if (wrq->flags & IW_ENCODE_DISABLED) {
1223 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable WEP function\n");
1224 pMgmt->bShareKeyAlgorithm = false;
1225 pDevice->bEncryptionEnable = false;
1226 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1227 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1228 for (uu = 0; uu < MAX_KEY_TABLE; uu++)
1229 MACvDisableKeyEntry(pDevice, uu);
1232 if (wrq->flags & IW_ENCODE_RESTRICTED) {
1233 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & ShareKey System\n");
1234 pMgmt->bShareKeyAlgorithm = true;
1236 if (wrq->flags & IW_ENCODE_OPEN) {
1237 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & Open System\n");
1238 pMgmt->bShareKeyAlgorithm = false;
1241 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
1246 int iwctl_giwencode(struct net_device *dev, struct iw_request_info *info,
1247 union iwreq_data *wrqu, char *extra)
1249 struct vnt_private *pDevice = netdev_priv(dev);
1250 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1251 struct iw_point *wrq = &wrqu->encoding;
1252 char abyKey[WLAN_WEP232_KEYLEN];
1254 unsigned index = (unsigned)(wrq->flags & IW_ENCODE_INDEX);
1255 PSKeyItem pKey = NULL;
1257 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODE\n");
1262 if (index > WLAN_WEP_NKEYS)
1264 if (index < 1) { // get default key
1265 if (pDevice->byKeyIndex < WLAN_WEP_NKEYS)
1266 index = pDevice->byKeyIndex;
1273 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
1274 // Check encryption mode
1275 wrq->flags = IW_ENCODE_NOKEY;
1276 // Is WEP enabled ???
1277 if (pDevice->bEncryptionEnable)
1278 wrq->flags |= IW_ENCODE_ENABLED;
1280 wrq->flags |= IW_ENCODE_DISABLED;
1282 if (pMgmt->bShareKeyAlgorithm)
1283 wrq->flags |= IW_ENCODE_RESTRICTED;
1285 wrq->flags |= IW_ENCODE_OPEN;
1288 if ((index == 0) && (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled ||
1289 pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)) { // get wpa pairwise key
1290 if (KeybGetKey(&(pDevice->sKey), pMgmt->abyCurrBSSID, 0xffffffff, &pKey)) {
1291 wrq->length = pKey->uKeyLength;
1292 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1293 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1295 } else if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (u8)index, &pKey)) {
1296 wrq->length = pKey->uKeyLength;
1297 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1298 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1301 wrq->flags |= index + 1;
1306 * Wireless Handler: set power mode
1308 int iwctl_siwpower(struct net_device *dev, struct iw_request_info *info,
1309 union iwreq_data *wrqu, char *extra)
1311 struct vnt_private *pDevice = netdev_priv(dev);
1312 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1313 struct iw_param *wrq = &wrqu->power;
1316 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER\n");
1321 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
1326 if (wrq->disabled) {
1327 pDevice->ePSMode = WMAC_POWER_CAM;
1328 PSvDisablePowerSaving(pDevice);
1331 if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1332 pDevice->ePSMode = WMAC_POWER_FAST;
1333 PSvEnablePowerSaving((void *)pDevice, pMgmt->wListenInterval);
1335 } else if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
1336 pDevice->ePSMode = WMAC_POWER_FAST;
1337 PSvEnablePowerSaving((void *)pDevice, pMgmt->wListenInterval);
1340 switch (wrq->flags & IW_POWER_MODE) {
1341 case IW_POWER_UNICAST_R:
1342 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_UNICAST_R\n");
1345 case IW_POWER_ALL_R:
1346 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ALL_R\n");
1349 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ON\n");
1359 * Wireless Handler: get power mode
1361 int iwctl_giwpower(struct net_device *dev, struct iw_request_info *info,
1362 union iwreq_data *wrqu, char *extra)
1364 struct vnt_private *pDevice = netdev_priv(dev);
1365 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1366 struct iw_param *wrq = &wrqu->power;
1367 int mode = pDevice->ePSMode;
1369 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPOWER\n");
1374 wrq->disabled = (mode == WMAC_POWER_CAM);
1378 if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1379 wrq->value = (int)((pMgmt->wListenInterval *
1380 pMgmt->wCurrBeaconPeriod) / 100);
1381 wrq->flags = IW_POWER_TIMEOUT;
1383 wrq->value = (int)((pMgmt->wListenInterval *
1384 pMgmt->wCurrBeaconPeriod) / 100);
1385 wrq->flags = IW_POWER_PERIOD;
1388 wrq->flags |= IW_POWER_ALL_R;
1393 * Wireless Handler: get Sensitivity
1395 int iwctl_giwsens(struct net_device *dev, struct iw_request_info *info,
1396 union iwreq_data *wrqu, char *extra)
1398 struct vnt_private *pDevice = netdev_priv(dev);
1399 struct iw_param *wrq = &wrqu->sens;
1402 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSENS\n");
1403 if (pDevice->bLinkPass == true) {
1404 RFvRSSITodBm(pDevice, (u8)(pDevice->uCurrRSSI), &ldBm);
1409 wrq->disabled = (wrq->value == 0);
1414 int iwctl_siwauth(struct net_device *dev, struct iw_request_info *info,
1415 union iwreq_data *wrqu, char *extra)
1417 struct vnt_private *pDevice = netdev_priv(dev);
1418 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1419 struct iw_param *wrq = &wrqu->param;
1421 static int wpa_version = 0; // must be static to save the last value, einsn liu
1422 static int pairwise = 0;
1427 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH\n");
1428 switch (wrq->flags & IW_AUTH_INDEX) {
1429 case IW_AUTH_WPA_VERSION:
1430 wpa_version = wrq->value;
1431 if (wrq->value == IW_AUTH_WPA_VERSION_DISABLED) {
1432 PRINT_K("iwctl_siwauth:set WPADEV to disable at 1??????\n");
1433 } else if (wrq->value == IW_AUTH_WPA_VERSION_WPA) {
1434 PRINT_K("iwctl_siwauth:set WPADEV to WPA1******\n");
1436 PRINT_K("iwctl_siwauth:set WPADEV to WPA2******\n");
1439 case IW_AUTH_CIPHER_PAIRWISE:
1440 pairwise = wrq->value;
1441 PRINT_K("iwctl_siwauth:set pairwise=%d\n", pairwise);
1442 if (pairwise == IW_AUTH_CIPHER_CCMP) {
1443 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1444 } else if (pairwise == IW_AUTH_CIPHER_TKIP) {
1445 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1446 } else if (pairwise == IW_AUTH_CIPHER_WEP40 ||
1447 pairwise == IW_AUTH_CIPHER_WEP104) {
1448 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1449 } else if (pairwise == IW_AUTH_CIPHER_NONE) {
1450 // do nothing, einsn liu
1452 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1455 case IW_AUTH_CIPHER_GROUP:
1456 PRINT_K("iwctl_siwauth:set GROUP=%d\n", wrq->value);
1457 if (wpa_version == IW_AUTH_WPA_VERSION_DISABLED)
1459 if (pairwise == IW_AUTH_CIPHER_NONE) {
1460 if (wrq->value == IW_AUTH_CIPHER_CCMP)
1461 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1463 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1466 case IW_AUTH_KEY_MGMT:
1467 PRINT_K("iwctl_siwauth(wpa_version=%d):set KEY_MGMT=%d\n", wpa_version, wrq->value);
1468 if (wpa_version == IW_AUTH_WPA_VERSION_WPA2) {
1469 if (wrq->value == IW_AUTH_KEY_MGMT_PSK)
1470 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
1471 else pMgmt->eAuthenMode = WMAC_AUTH_WPA2;
1472 } else if (wpa_version == IW_AUTH_WPA_VERSION_WPA) {
1473 if (wrq->value == 0) {
1474 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
1475 } else if (wrq->value == IW_AUTH_KEY_MGMT_PSK)
1476 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
1478 pMgmt->eAuthenMode = WMAC_AUTH_WPA;
1481 case IW_AUTH_TKIP_COUNTERMEASURES:
1483 case IW_AUTH_DROP_UNENCRYPTED:
1485 case IW_AUTH_80211_AUTH_ALG:
1486 PRINT_K("iwctl_siwauth:set AUTH_ALG=%d\n", wrq->value);
1487 if (wrq->value == IW_AUTH_ALG_OPEN_SYSTEM)
1488 pMgmt->bShareKeyAlgorithm = false;
1489 else if (wrq->value == IW_AUTH_ALG_SHARED_KEY)
1490 pMgmt->bShareKeyAlgorithm = true;
1492 case IW_AUTH_WPA_ENABLED:
1494 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1496 case IW_AUTH_ROAMING_CONTROL:
1499 case IW_AUTH_PRIVACY_INVOKED:
1500 pDevice->bEncryptionEnable = !!wrq->value;
1501 if (pDevice->bEncryptionEnable == false) {
1504 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1505 pMgmt->bShareKeyAlgorithm = false;
1506 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
1507 PRINT_K("iwctl_siwauth:set WPADEV to disaable at 2?????\n");
1511 PRINT_K("iwctl_siwauth: not supported %x\n", wrq->flags);
1518 int iwctl_giwauth(struct net_device *dev, struct iw_request_info *info,
1519 union iwreq_data *wrqu, char *extra)
1524 int iwctl_siwgenie(struct net_device *dev, struct iw_request_info *info,
1525 union iwreq_data *wrqu, char *extra)
1527 struct vnt_private *pDevice = netdev_priv(dev);
1528 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1529 struct iw_point *wrq = &wrqu->data;
1536 if ((wrq->length < 2) || (extra[1] + 2 != wrq->length)) {
1540 if (wrq->length > MAX_WPA_IE_LEN) {
1544 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
1546 memcpy(pMgmt->abyWPAIE, extra, wrq->length);
1547 pMgmt->wWPAIELen = wrq->length;
1549 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
1550 pMgmt->wWPAIELen = 0;
1553 out: // not completely ...not necessary in wpa_supplicant 0.5.8
1557 int iwctl_giwgenie(struct net_device *dev, struct iw_request_info *info,
1558 union iwreq_data *wrqu, char *extra)
1560 struct vnt_private *pDevice = netdev_priv(dev);
1561 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1562 struct iw_point *wrq = &wrqu->data;
1564 int space = wrq->length;
1570 if (pMgmt->wWPAIELen > 0) {
1571 wrq->length = pMgmt->wWPAIELen;
1573 if (pMgmt->wWPAIELen <= space)
1574 memcpy(extra, pMgmt->abyWPAIE, pMgmt->wWPAIELen);
1581 int iwctl_siwencodeext(struct net_device *dev, struct iw_request_info *info,
1582 union iwreq_data *wrqu, char *extra)
1584 struct vnt_private *pDevice = netdev_priv(dev);
1585 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1586 struct iw_point *wrq = &wrqu->encoding;
1587 struct iw_encode_ext *ext = (struct iw_encode_ext*)extra;
1588 struct viawget_wpa_param *param = NULL;
1594 u8 seq[IW_ENCODE_SEQ_MAX_SIZE];
1602 PRINT_K("SIOCSIWENCODEEXT......\n");
1607 if (!(pDevice->flags & DEVICE_FLAGS_OPENED))
1610 buf = kzalloc(sizeof(struct viawget_wpa_param), GFP_KERNEL);
1614 param = (struct viawget_wpa_param *)buf;
1618 case IW_ENCODE_ALG_NONE:
1619 alg_name = WPA_ALG_NONE;
1621 case IW_ENCODE_ALG_WEP:
1622 alg_name = WPA_ALG_WEP;
1624 case IW_ENCODE_ALG_TKIP:
1625 alg_name = WPA_ALG_TKIP;
1627 case IW_ENCODE_ALG_CCMP:
1628 alg_name = WPA_ALG_CCMP;
1631 PRINT_K("Unknown alg = %d\n", ext->alg);
1636 memcpy(addr, ext->addr.sa_data, ETH_ALEN);
1638 key_idx = (wrq->flags&IW_ENCODE_INDEX) - 1;
1640 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
1642 // recover seq,seq_len
1643 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
1644 seq_len = IW_ENCODE_SEQ_MAX_SIZE;
1645 memcpy(seq, ext->rx_seq, seq_len);
1647 // recover key,key_len
1649 key_len = ext->key_len;
1650 memcpy(key, &ext->key[0], key_len);
1652 memset(key_array, 0, 64);
1654 memcpy(key_array, key, key_len);
1655 if (key_len == 32) {
1656 // notice ! the oder
1657 memcpy(&key_array[16], &key[24], 8);
1658 memcpy(&key_array[24], &key[16], 8);
1662 /**************Translate iw_encode_ext to viawget_wpa_param****************/
1663 memcpy(param->addr, addr, ETH_ALEN);
1664 param->u.wpa_key.alg_name = (int)alg_name;
1665 param->u.wpa_key.set_tx = set_tx;
1666 param->u.wpa_key.key_index = key_idx;
1667 param->u.wpa_key.key_len = key_len;
1668 param->u.wpa_key.key = (u8 *)key_array;
1669 param->u.wpa_key.seq = (u8 *)seq;
1670 param->u.wpa_key.seq_len = seq_len;
1672 /****set if current action is Network Manager count?? */
1673 /****this method is so foolish,but there is no other way??? */
1674 if (param->u.wpa_key.alg_name == WPA_ALG_NONE) {
1675 if (param->u.wpa_key.key_index == 0) {
1676 pDevice->bwextstep0 = true;
1678 if ((pDevice->bwextstep0 == true) && (param->u.wpa_key.key_index == 1)) {
1679 pDevice->bwextstep0 = false;
1680 pDevice->bwextstep1 = true;
1682 if ((pDevice->bwextstep1 == true) && (param->u.wpa_key.key_index == 2)) {
1683 pDevice->bwextstep1 = false;
1684 pDevice->bwextstep2 = true;
1686 if ((pDevice->bwextstep2 == true) && (param->u.wpa_key.key_index == 3)) {
1687 pDevice->bwextstep2 = false;
1688 pDevice->bwextstep3 = true;
1691 if (pDevice->bwextstep3 == true) {
1692 PRINT_K("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n");
1693 pDevice->bwextstep0 = false;
1694 pDevice->bwextstep1 = false;
1695 pDevice->bwextstep2 = false;
1696 pDevice->bwextstep3 = false;
1697 pDevice->bWPASuppWextEnabled = true;
1698 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
1699 KeyvInitTable(pDevice, &pDevice->sKey);
1702 ret = wpa_set_keys(pDevice, param);
1709 int iwctl_giwencodeext(struct net_device *dev, struct iw_request_info *info,
1710 union iwreq_data *wrqu, char *extra)
1715 int iwctl_siwmlme(struct net_device *dev, struct iw_request_info *info,
1716 union iwreq_data *wrqu, char *extra)
1718 struct vnt_private *pDevice = netdev_priv(dev);
1719 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1720 struct iw_mlme *mlme = (struct iw_mlme *)extra;
1723 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMLME\n");
1728 if (memcmp(pMgmt->abyCurrBSSID, mlme->addr.sa_data, ETH_ALEN)) {
1732 switch (mlme->cmd) {
1733 case IW_MLME_DEAUTH:
1734 case IW_MLME_DISASSOC:
1735 if (pDevice->bLinkPass == true) {
1736 PRINT_K("iwctl_siwmlme--->send DISASSOCIATE\n");
1737 bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE,
1747 static int iwctl_config_commit(struct net_device *dev,
1748 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1750 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "SIOCSIWCOMMIT\n");
1755 static const iw_handler iwctl_handler[] = {
1756 IW_HANDLER(SIOCSIWCOMMIT, iwctl_config_commit),
1757 IW_HANDLER(SIOCGIWNAME, iwctl_giwname),
1758 IW_HANDLER(SIOCSIWFREQ, iwctl_siwfreq),
1759 IW_HANDLER(SIOCGIWFREQ, iwctl_giwfreq),
1760 IW_HANDLER(SIOCSIWMODE, iwctl_siwmode),
1761 IW_HANDLER(SIOCGIWMODE, iwctl_giwmode),
1762 IW_HANDLER(SIOCGIWSENS, iwctl_giwsens),
1763 IW_HANDLER(SIOCGIWRANGE, iwctl_giwrange),
1764 IW_HANDLER(SIOCSIWAP, iwctl_siwap),
1765 IW_HANDLER(SIOCGIWAP, iwctl_giwap),
1766 IW_HANDLER(SIOCSIWMLME, iwctl_siwmlme),
1767 IW_HANDLER(SIOCGIWAPLIST, iwctl_giwaplist),
1768 IW_HANDLER(SIOCSIWSCAN, iwctl_siwscan),
1769 IW_HANDLER(SIOCGIWSCAN, iwctl_giwscan),
1770 IW_HANDLER(SIOCSIWESSID, iwctl_siwessid),
1771 IW_HANDLER(SIOCGIWESSID, iwctl_giwessid),
1772 IW_HANDLER(SIOCSIWRATE, iwctl_siwrate),
1773 IW_HANDLER(SIOCGIWRATE, iwctl_giwrate),
1774 IW_HANDLER(SIOCSIWRTS, iwctl_siwrts),
1775 IW_HANDLER(SIOCGIWRTS, iwctl_giwrts),
1776 IW_HANDLER(SIOCSIWFRAG, iwctl_siwfrag),
1777 IW_HANDLER(SIOCGIWFRAG, iwctl_giwfrag),
1778 IW_HANDLER(SIOCSIWRETRY, iwctl_siwretry),
1779 IW_HANDLER(SIOCGIWRETRY, iwctl_giwretry),
1780 IW_HANDLER(SIOCSIWENCODE, iwctl_siwencode),
1781 IW_HANDLER(SIOCGIWENCODE, iwctl_giwencode),
1782 IW_HANDLER(SIOCSIWPOWER, iwctl_siwpower),
1783 IW_HANDLER(SIOCGIWPOWER, iwctl_giwpower),
1784 IW_HANDLER(SIOCSIWGENIE, iwctl_siwgenie),
1785 IW_HANDLER(SIOCGIWGENIE, iwctl_giwgenie),
1786 IW_HANDLER(SIOCSIWAUTH, iwctl_siwauth),
1787 IW_HANDLER(SIOCGIWAUTH, iwctl_giwauth),
1788 IW_HANDLER(SIOCSIWENCODEEXT, iwctl_siwencodeext),
1789 IW_HANDLER(SIOCGIWENCODEEXT, iwctl_giwencodeext)
1792 static const iw_handler iwctl_private_handler[] = {
1793 NULL, // SIOCIWFIRSTPRIV
1796 const struct iw_handler_def iwctl_handler_def = {
1797 .get_wireless_stats = &iwctl_get_wireless_stats,
1798 .num_standard = ARRAY_SIZE(iwctl_handler),
1800 .num_private_args = 0,
1801 .standard = iwctl_handler,
1803 .private_args = NULL,