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 #include <net/iw_handler.h>
46 #define SUPPORTED_WIRELESS_EXT 18
48 static const long frequency_list[] = {
49 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
50 4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
51 5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210, 5220, 5230, 5240,
52 5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680,
53 5700, 5745, 5765, 5785, 5805, 5825
56 static int msglevel = MSG_LEVEL_INFO;
58 struct iw_statistics *iwctl_get_wireless_stats(struct net_device *dev)
60 PSDevice pDevice = netdev_priv(dev);
63 pDevice->wstats.status = pDevice->eOPMode;
64 if (pDevice->scStatistic.LinkQuality > 100)
65 pDevice->scStatistic.LinkQuality = 100;
66 pDevice->wstats.qual.qual =(BYTE)pDevice->scStatistic.LinkQuality;
67 RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm);
68 pDevice->wstats.qual.level = ldBm;
69 pDevice->wstats.qual.noise = 0;
70 pDevice->wstats.qual.updated = 1;
71 pDevice->wstats.discard.nwid = 0;
72 pDevice->wstats.discard.code = 0;
73 pDevice->wstats.discard.fragment = 0;
74 pDevice->wstats.discard.retries = pDevice->scStatistic.dwTsrErr;
75 pDevice->wstats.discard.misc = 0;
76 pDevice->wstats.miss.beacon = 0;
77 return &pDevice->wstats;
81 * Wireless Handler: get protocol name
83 int iwctl_giwname(struct net_device *dev, struct iw_request_info *info,
84 char *wrq, char *extra)
86 strcpy(wrq, "802.11-a/b/g");
91 * Wireless Handler: set scan
93 int iwctl_siwscan(struct net_device *dev, struct iw_request_info *info,
94 struct iw_point *wrq, char *extra)
96 PSDevice pDevice = netdev_priv(dev);
97 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
98 struct iw_scan_req *req = (struct iw_scan_req *)extra;
99 BYTE abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
100 PWLAN_IE_SSID pItemSSID = NULL;
102 if (!(pDevice->flags & DEVICE_FLAGS_OPENED))
105 PRINT_K(" SIOCSIWSCAN \n");
107 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
109 PRINT_K("SIOCSIWSCAN(overlap??)-->In scanning...\n");
113 if (pDevice->byReAssocCount > 0) { // reject scan when re-associating!
114 // send scan event to wpa_Supplicant
115 union iwreq_data wrqu;
116 PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
117 memset(&wrqu, 0, sizeof(wrqu));
118 wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
122 spin_lock_irq(&pDevice->lock);
124 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
126 // mike add: active scan OR passive scan OR desire_ssid scan
127 if (wrq->length == sizeof(struct iw_scan_req)) {
128 if (wrq->flags & IW_SCAN_THIS_ESSID) { // desire_ssid scan
129 memset(abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
130 pItemSSID = (PWLAN_IE_SSID)abyScanSSID;
131 pItemSSID->byElementID = WLAN_EID_SSID;
132 memcpy(pItemSSID->abySSID, req->essid, (int)req->essid_len);
133 if (pItemSSID->abySSID[req->essid_len - 1] == '\0') {
134 if (req->essid_len > 0)
135 pItemSSID->len = req->essid_len - 1;
137 pItemSSID->len = req->essid_len;
139 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
140 PRINT_K("SIOCSIWSCAN:[desired_ssid=%s,len=%d]\n", ((PWLAN_IE_SSID)abyScanSSID)->abySSID,
141 ((PWLAN_IE_SSID)abyScanSSID)->len);
142 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID);
143 spin_unlock_irq(&pDevice->lock);
146 } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) { // passive scan
147 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
149 } else { // active scan
150 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
153 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
154 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
155 spin_unlock_irq(&pDevice->lock);
161 * Wireless Handler : get scan results
163 int iwctl_giwscan(struct net_device *dev, struct iw_request_info *info,
164 struct iw_point *wrq, char *extra)
169 PSDevice pDevice = netdev_priv(dev);
170 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
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;
180 char buf[MAX_WPA_IE_LEN * 2 + 30];
182 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSCAN\n");
184 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
188 pBSS = &(pMgmt->sBSSList[0]);
189 for (ii = 0, jj = 0; jj < MAX_BSS_NUM ; jj++) {
190 if (current_ev >= end_buf)
192 pBSS = &(pMgmt->sBSSList[jj]);
195 memset(&iwe, 0, sizeof(iwe));
197 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
198 memcpy(iwe.u.ap_addr.sa_data, pBSS->abyBSSID, WLAN_BSSID_LEN);
199 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
201 memset(&iwe, 0, sizeof(iwe));
202 iwe.cmd = SIOCGIWESSID;
203 pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
204 iwe.u.data.length = pItemSSID->len;
205 iwe.u.data.flags = 1;
206 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pItemSSID->abySSID);
208 memset(&iwe, 0, sizeof(iwe));
209 iwe.cmd = SIOCGIWMODE;
210 if (WLAN_GET_CAP_INFO_ESS(pBSS->wCapInfo))
211 iwe.u.mode = IW_MODE_INFRA;
213 iwe.u.mode = IW_MODE_ADHOC;
214 iwe.len = IW_EV_UINT_LEN;
215 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
217 pSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abySuppRates;
218 pExtSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abyExtSuppRates;
219 memset(&iwe, 0, sizeof(iwe));
220 iwe.cmd = SIOCGIWFREQ;
221 iwe.u.freq.m = pBSS->uChannel;
224 current_ev = iwe_stream_add_event(info, current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
226 int f = (int)pBSS->uChannel - 1;
229 iwe.u.freq.m = frequency_list[f] * 100000;
232 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
234 memset(&iwe, 0, sizeof(iwe));
236 RFvRSSITodBm(pDevice, (BYTE)(pBSS->uRSSI), &ldBm);
237 iwe.u.qual.level = ldBm;
238 iwe.u.qual.noise = 0;
241 iwe.u.qual.qual = 100;
245 iwe.u.qual.qual = (40 - (-ldBm - 50)) * 100 / 40;
246 iwe.u.qual.updated = 7;
248 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
250 memset(&iwe, 0, sizeof(iwe));
251 iwe.cmd = SIOCGIWENCODE;
252 iwe.u.data.length = 0;
253 if (WLAN_GET_CAP_INFO_PRIVACY(pBSS->wCapInfo))
254 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
256 iwe.u.data.flags = IW_ENCODE_DISABLED;
257 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pItemSSID->abySSID);
259 memset(&iwe, 0, sizeof(iwe));
260 iwe.cmd = SIOCGIWRATE;
261 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
262 current_val = current_ev + IW_EV_LCP_LEN;
264 for (kk = 0; kk < 12; kk++) {
265 if (pSuppRates->abyRates[kk] == 0)
267 // Bit rate given in 500 kb/s units (+ 0x80)
268 iwe.u.bitrate.value = ((pSuppRates->abyRates[kk] & 0x7f) * 500000);
269 current_val = iwe_stream_add_value(info, current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
271 for (kk = 0; kk < 8; kk++) {
272 if (pExtSuppRates->abyRates[kk] == 0)
274 // Bit rate given in 500 kb/s units (+ 0x80)
275 iwe.u.bitrate.value = ((pExtSuppRates->abyRates[kk] & 0x7f) * 500000);
276 current_val = iwe_stream_add_value(info, current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
279 if ((current_val - current_ev) > IW_EV_LCP_LEN)
280 current_ev = current_val;
282 memset(&iwe, 0, sizeof(iwe));
283 iwe.cmd = IWEVCUSTOM;
284 sprintf(buf, "bcn_int=%d", pBSS->wBeaconInterval);
285 iwe.u.data.length = strlen(buf);
286 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, buf);
288 if ((pBSS->wWPALen > 0) && (pBSS->wWPALen <= MAX_WPA_IE_LEN)) {
289 memset(&iwe, 0, sizeof(iwe));
291 iwe.u.data.length = pBSS->wWPALen;
292 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pBSS->byWPAIE);
295 if ((pBSS->wRSNLen > 0) && (pBSS->wRSNLen <= MAX_WPA_IE_LEN)) {
296 memset(&iwe, 0, sizeof(iwe));
298 iwe.u.data.length = pBSS->wRSNLen;
299 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pBSS->byRSNIE);
303 wrq->length = current_ev - extra;
308 * Wireless Handler: set frequence or channel
310 int iwctl_siwfreq(struct net_device *dev, struct iw_request_info *info,
311 struct iw_freq *wrq, char *extra)
313 PSDevice pDevice = netdev_priv(dev);
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 struct iw_freq *wrq, char *extra)
351 PSDevice pDevice = netdev_priv(dev);
352 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
354 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFREQ \n");
356 #ifdef WEXT_USECHANNELS
357 wrq->m = (int)pMgmt->uCurrChannel;
361 int f = (int)pMgmt->uCurrChannel - 1;
364 wrq->m = frequency_list[f] * 100000;
372 * Wireless Handler: set operation mode
374 int iwctl_siwmode(struct net_device *dev, struct iw_request_info *info,
375 __u32 *wmode, char *extra)
377 PSDevice pDevice = netdev_priv(dev);
378 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
381 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMODE \n");
383 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP && pDevice->bEnableHostapd) {
384 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Can't set operation mode, hostapd is running \n");
390 if (pMgmt->eConfigMode != WMAC_CONFIG_IBSS_STA) {
391 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
392 if (pDevice->flags & DEVICE_FLAGS_OPENED)
393 pDevice->bCommit = TRUE;
395 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to ad-hoc \n");
399 if (pMgmt->eConfigMode != WMAC_CONFIG_ESS_STA) {
400 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
401 if (pDevice->flags & DEVICE_FLAGS_OPENED)
402 pDevice->bCommit = TRUE;
404 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to infrastructure \n");
408 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
412 if (pMgmt->eConfigMode != WMAC_CONFIG_AP) {
413 pMgmt->eConfigMode = WMAC_CONFIG_AP;
414 if (pDevice->flags & DEVICE_FLAGS_OPENED)
415 pDevice->bCommit = TRUE;
417 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to Access Point \n");
421 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
432 * Wireless Handler: get operation mode
434 void iwctl_giwmode(struct net_device *dev, struct iw_request_info *info,
435 __u32 *wmode, char *extra)
437 PSDevice pDevice = netdev_priv(dev);
438 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
440 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWMODE \n");
441 // If not managed, assume it's ad-hoc
442 switch (pMgmt->eConfigMode) {
443 case WMAC_CONFIG_ESS_STA:
444 *wmode = IW_MODE_INFRA;
446 case WMAC_CONFIG_IBSS_STA:
447 *wmode = IW_MODE_ADHOC;
449 case WMAC_CONFIG_AUTO:
450 *wmode = IW_MODE_INFRA;
453 *wmode = IW_MODE_MASTER;
456 *wmode = IW_MODE_ADHOC;
461 * Wireless Handler: get capability range
463 void iwctl_giwrange(struct net_device *dev, struct iw_request_info *info,
464 struct iw_point *wrq, char *extra)
466 struct iw_range *range = (struct iw_range *)extra;
469 BYTE abySupportedRates[13] = {
470 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48,
474 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRANGE\n");
476 wrq->length = sizeof(struct iw_range);
477 memset(range, 0, sizeof(struct iw_range));
478 range->min_nwid = 0x0000;
479 range->max_nwid = 0x0000;
480 range->num_channels = 14;
481 // Should be based on cap_rid.country to give only
482 // what the current card support
484 for (i = 0; i < 14; i++) {
485 range->freq[k].i = i + 1; // List index
486 range->freq[k].m = frequency_list[i] * 100000;
487 range->freq[k++].e = 1; // Values in table in MHz -> * 10^5 * 10
489 range->num_frequency = k;
490 // Hum... Should put the right values there
491 range->max_qual.qual = 100;
492 range->max_qual.level = 0;
493 range->max_qual.noise = 0;
494 range->sensitivity = 255;
496 for (i = 0; i < 13; i++) {
497 range->bitrate[i] = abySupportedRates[i] * 500000;
498 if (range->bitrate[i] == 0)
501 range->num_bitrates = i;
503 // Set an indication of the max TCP throughput
504 // in bit/s that we can expect using this interface.
505 // May be use for QoS stuff... Jean II
507 range->throughput = 5 * 1000 * 1000;
509 range->throughput = 1.5 * 1000 * 1000;
512 range->max_rts = 2312;
513 range->min_frag = 256;
514 range->max_frag = 2312;
516 // the encoding capabilities
517 range->num_encoding_sizes = 3;
519 range->encoding_size[0] = 5;
521 range->encoding_size[1] = 13;
522 // 256 bits for WPA-PSK
523 range->encoding_size[2] = 32;
524 // 4 keys are allowed
525 range->max_encoding_tokens = 4;
527 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
528 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
531 range->max_pmp = 1000000; // 1 secs
533 range->max_pmt = 1000000; // 1 secs
534 range->pmp_flags = IW_POWER_PERIOD;
535 range->pmt_flags = IW_POWER_TIMEOUT;
536 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
538 // Transmit Power - values are in mW
539 range->txpower[0] = 100;
540 range->num_txpower = 1;
541 range->txpower_capa = IW_TXPOW_MWATT;
542 range->we_version_source = SUPPORTED_WIRELESS_EXT;
543 range->we_version_compiled = WIRELESS_EXT;
544 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
545 range->retry_flags = IW_RETRY_LIMIT;
546 range->r_time_flags = IW_RETRY_LIFETIME;
547 range->min_retry = 1;
548 range->max_retry = 65535;
549 range->min_r_time = 1024;
550 range->max_r_time = 65535 * 1024;
551 // Experimental measurements - boundary 11/5.5 Mb/s
552 // Note : with or without the (local->rssi), results
553 // are somewhat different. - Jean II
554 range->avg_qual.qual = 6;
555 range->avg_qual.level = 176; // -80 dBm
556 range->avg_qual.noise = 0;
561 * Wireless Handler : set ap mac address
563 int iwctl_siwap(struct net_device *dev, struct iw_request_info *info,
564 struct sockaddr *wrq, char *extra)
566 PSDevice pDevice = netdev_priv(dev);
567 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
569 BYTE ZeroBSSID[WLAN_BSSID_LEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
571 PRINT_K(" SIOCSIWAP \n");
573 if (wrq->sa_family != ARPHRD_ETHER) {
576 memcpy(pMgmt->abyDesireBSSID, wrq->sa_data, 6);
578 if ((is_broadcast_ether_addr(pMgmt->abyDesireBSSID)) ||
579 (memcmp(pMgmt->abyDesireBSSID, ZeroBSSID, 6) == 0)) {
580 PRINT_K("SIOCSIWAP:invalid desired BSSID return!\n");
583 // mike add: if desired AP is hidden ssid(there are
584 // two same BSSID in list), then ignore,because you
585 // don't known which one to be connect with??
588 unsigned uSameBssidNum = 0;
589 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
590 if (pMgmt->sBSSList[ii].bActive &&
591 !compare_ether_addr(pMgmt->sBSSList[ii].abyBSSID,
592 pMgmt->abyDesireBSSID)) {
596 if (uSameBssidNum >= 2) { //hit: desired AP is in hidden ssid mode!!!
597 PRINT_K("SIOCSIWAP:ignore for desired AP in hidden mode\n");
602 if (pDevice->flags & DEVICE_FLAGS_OPENED)
603 pDevice->bCommit = TRUE;
609 * Wireless Handler: get ap mac address
611 int iwctl_giwap(struct net_device *dev, struct iw_request_info *info,
612 struct sockaddr *wrq, char *extra)
614 PSDevice pDevice = netdev_priv(dev);
615 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
617 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAP \n");
619 memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
621 if ((pDevice->bLinkPass == FALSE) && (pMgmt->eCurrMode != WMAC_MODE_ESS_AP))
622 memset(wrq->sa_data, 0, 6);
624 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)
625 memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
627 wrq->sa_family = ARPHRD_ETHER;
632 * Wireless Handler: get ap list
634 int iwctl_giwaplist(struct net_device *dev, struct iw_request_info *info,
635 struct iw_point *wrq, u8 *extra)
637 struct sockaddr *sock;
638 struct iw_quality *qual;
639 PSDevice pDevice = netdev_priv(dev);
640 PSMgmtObject pMgmt = &pDevice->sMgmtObj;
641 PKnownBSS pBSS = &pMgmt->sBSSList[0];
645 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAPLIST\n");
646 /* Only super-user can see AP list */
651 if (!capable(CAP_NET_ADMIN))
657 sock = kzalloc(sizeof(struct sockaddr) * IW_MAX_AP, GFP_KERNEL);
660 qual = kzalloc(sizeof(struct iw_quality) * IW_MAX_AP, GFP_KERNEL);
666 for (ii = 0, jj = 0; ii < MAX_BSS_NUM; ii++) {
667 if (!pBSS[ii].bActive)
671 memcpy(sock[jj].sa_data, pBSS[ii].abyBSSID, 6);
672 sock[jj].sa_family = ARPHRD_ETHER;
673 qual[jj].level = pBSS[ii].uRSSI;
674 qual[jj].qual = qual[jj].noise = 0;
675 qual[jj].updated = 2;
679 wrq->flags = 1; /* Should be defined */
681 memcpy(extra, sock, sizeof(struct sockaddr) * jj);
682 memcpy(extra + sizeof(struct sockaddr) * jj, qual,
683 sizeof(struct iw_quality) * jj);
692 * Wireless Handler: set essid
694 int iwctl_siwessid(struct net_device *dev, struct iw_request_info *info,
695 struct iw_point *wrq, char *extra)
697 PSDevice pDevice = netdev_priv(dev);
698 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
699 PWLAN_IE_SSID pItemSSID;
701 if (!(pDevice->flags & DEVICE_FLAGS_OPENED))
704 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWESSID :\n");
706 pDevice->fWPA_Authened = FALSE;
707 // Check if we asked for `any'
708 if (wrq->flags == 0) {
709 // Just send an empty SSID list
710 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
711 memset(pMgmt->abyDesireBSSID, 0xFF,6);
712 PRINT_K("set essid to 'any' \n");
713 // Unknown desired AP, so here need not associate??
717 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
718 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
719 pItemSSID->byElementID = WLAN_EID_SSID;
721 memcpy(pItemSSID->abySSID, extra, wrq->length);
722 if (pItemSSID->abySSID[wrq->length - 1] == '\0') {
724 pItemSSID->len = wrq->length - 1;
726 pItemSSID->len = wrq->length;
728 PRINT_K("set essid to %s \n", pItemSSID->abySSID);
730 // mike: need clear desiredBSSID
731 if (pItemSSID->len==0) {
732 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
736 // Wext wil order another command of siwap to link
737 // with desired AP, so here need not associate??
738 if (pDevice->bWPASuppWextEnabled == TRUE) {
739 /*******search if in hidden ssid mode ****/
740 PKnownBSS pCurr = NULL;
741 BYTE abyTmpDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
743 unsigned uSameBssidNum = 0;
745 memcpy(abyTmpDesireSSID, pMgmt->abyDesireSSID, sizeof(abyTmpDesireSSID));
746 pCurr = BSSpSearchBSSList(pDevice, NULL,
748 pDevice->eConfigPHYMode);
751 PRINT_K("SIOCSIWESSID:hidden ssid site survey before associate.......\n");
752 vResetCommandTimer((void *)pDevice);
753 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
754 bScheduleCommand((void *)pDevice,
756 pMgmt->abyDesireSSID);
757 bScheduleCommand((void *)pDevice,
759 pMgmt->abyDesireSSID);
760 } else { // mike: to find out if that desired SSID is a
761 // hidden-ssid AP, by means of judging if there
762 // are two same BSSID exist in list ?
763 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
764 if (pMgmt->sBSSList[ii].bActive &&
765 !compare_ether_addr(pMgmt->sBSSList[ii].abyBSSID,
770 if (uSameBssidNum >= 2) { // hit: desired AP is in hidden ssid mode!!!
771 PRINT_K("SIOCSIWESSID:hidden ssid directly associate.......\n");
772 vResetCommandTimer((void *)pDevice);
773 pMgmt->eScanType = WMAC_SCAN_PASSIVE; // this scan type, you'll submit scan result!
774 bScheduleCommand((void *)pDevice,
776 pMgmt->abyDesireSSID);
777 bScheduleCommand((void *)pDevice,
779 pMgmt->abyDesireSSID);
785 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set essid = %s \n", pItemSSID->abySSID);
788 if (pDevice->flags & DEVICE_FLAGS_OPENED)
789 pDevice->bCommit = TRUE;
795 * Wireless Handler: get essid
797 void iwctl_giwessid(struct net_device *dev, struct iw_request_info *info,
798 struct iw_point *wrq, char *extra)
800 PSDevice pDevice = netdev_priv(dev);
801 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
802 PWLAN_IE_SSID pItemSSID;
804 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWESSID \n");
806 // Note: if wrq->u.data.flags != 0, we should get the relevant
807 // SSID from the SSID list...
809 // Get the current SSID
810 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
811 memcpy(extra, pItemSSID->abySSID, pItemSSID->len);
812 extra[pItemSSID->len] = '\0';
814 wrq->length = pItemSSID->len;
815 wrq->flags = 1; // active
819 * Wireless Handler: set data rate
821 int iwctl_siwrate(struct net_device *dev, struct iw_request_info *info,
822 struct iw_param *wrq, char *extra)
824 PSDevice pDevice = netdev_priv(dev);
828 BYTE abySupportedRates[13] = {
829 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48,
833 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRATE \n");
834 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
839 // First: get a valid bit rate value
841 // Which type of value
842 if ((wrq->value < 13) && (wrq->value >= 0)) {
843 // Setting by rate index
844 // Find value in the magic rate table
847 // Setting by frequency value
848 u8 normvalue = (u8)(wrq->value/500000);
850 // Check if rate is valid
851 for (i = 0; i < 13; i++) {
852 if (normvalue == abySupportedRates[i]) {
858 // -1 designed the max rate (mostly auto mode)
859 if (wrq->value == -1) {
860 // Get the highest available rate
861 for (i = 0; i < 13; i++) {
862 if (abySupportedRates[i] == 0)
869 // Check that it is valid
870 // brate is index of abySupportedRates[]
876 // Now, check if we want a fixed or auto value
877 if (wrq->fixed != 0) {
880 pDevice->bFixRate = TRUE;
881 if ((pDevice->byBBType == BB_TYPE_11B) && (brate > 3)) {
882 pDevice->uConnectionRate = 3;
884 pDevice->uConnectionRate = brate;
885 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fixed to Rate %d \n", pDevice->uConnectionRate);
888 pDevice->bFixRate = FALSE;
889 pDevice->uConnectionRate = 13;
896 * Wireless Handler: get data rate
898 void iwctl_giwrate(struct net_device *dev, struct iw_request_info *info,
899 struct iw_param *wrq, char *extra)
901 PSDevice pDevice = netdev_priv(dev);
902 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
904 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRATE \n");
906 BYTE abySupportedRates[13] = {
907 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30,
908 0x48, 0x60, 0x6C, 0x90
912 if (pDevice->uConnectionRate < 13) {
913 brate = abySupportedRates[pDevice->uConnectionRate];
915 if (pDevice->byBBType == BB_TYPE_11B)
917 if (pDevice->byBBType == BB_TYPE_11G)
919 if (pDevice->byBBType == BB_TYPE_11A)
922 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
923 if (pDevice->byBBType == BB_TYPE_11B)
925 if (pDevice->byBBType == BB_TYPE_11G)
927 if (pDevice->byBBType == BB_TYPE_11A)
930 if (pDevice->uConnectionRate == 13)
931 brate = abySupportedRates[pDevice->wCurrentRate];
932 wrq->value = brate * 500000;
933 // If more than one rate, set auto
934 if (pDevice->bFixRate == TRUE)
940 * Wireless Handler: set rts threshold
942 int iwctl_siwrts(struct net_device *dev, struct iw_param *wrq)
944 PSDevice pDevice = netdev_priv(dev);
946 if ((wrq->value < 0 || wrq->value > 2312) && !wrq->disabled)
949 else if (wrq->disabled)
950 pDevice->wRTSThreshold = 2312;
952 pDevice->wRTSThreshold = wrq->value;
958 * Wireless Handler: get rts
960 int iwctl_giwrts(struct net_device *dev, struct iw_request_info *info,
961 struct iw_param *wrq, char *extra)
963 PSDevice pDevice = netdev_priv(dev);
965 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRTS \n");
966 wrq->value = pDevice->wRTSThreshold;
967 wrq->disabled = (wrq->value >= 2312);
973 * Wireless Handler: set fragment threshold
975 int iwctl_siwfrag(struct net_device *dev, struct iw_request_info *info,
976 struct iw_param *wrq, char *extra)
978 PSDevice pDevice = netdev_priv(dev);
980 int fthr = wrq->value;
982 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFRAG \n");
986 if ((fthr < 256) || (fthr > 2312)) {
989 fthr &= ~0x1; // Get an even value
990 pDevice->wFragmentationThreshold = (u16)fthr;
996 * Wireless Handler: get fragment threshold
998 int iwctl_giwfrag(struct net_device *dev, struct iw_request_info *info,
999 struct iw_param *wrq, char *extra)
1001 PSDevice pDevice = netdev_priv(dev);
1003 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFRAG \n");
1004 wrq->value = pDevice->wFragmentationThreshold;
1005 wrq->disabled = (wrq->value >= 2312);
1011 * Wireless Handler: set retry threshold
1013 int iwctl_siwretry(struct net_device *dev, struct iw_request_info *info,
1014 struct iw_param *wrq, char *extra)
1016 PSDevice pDevice = netdev_priv(dev);
1019 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRETRY \n");
1021 if (wrq->disabled) {
1026 if (wrq->flags & IW_RETRY_LIMIT) {
1027 if (wrq->flags & IW_RETRY_MAX) {
1028 pDevice->byLongRetryLimit = wrq->value;
1029 } else if (wrq->flags & IW_RETRY_MIN) {
1030 pDevice->byShortRetryLimit = wrq->value;
1032 // No modifier : set both
1033 pDevice->byShortRetryLimit = wrq->value;
1034 pDevice->byLongRetryLimit = wrq->value;
1037 if (wrq->flags & IW_RETRY_LIFETIME)
1038 pDevice->wMaxTransmitMSDULifetime = wrq->value;
1043 * Wireless Handler: get retry threshold
1045 int iwctl_giwretry(struct net_device *dev, struct iw_request_info *info,
1046 struct iw_param *wrq, char *extra)
1048 PSDevice pDevice = netdev_priv(dev);
1049 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRETRY \n");
1050 wrq->disabled = 0; // Can't be disabled
1052 // Note: by default, display the min retry number
1053 if ((wrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1054 wrq->flags = IW_RETRY_LIFETIME;
1055 wrq->value = (int)pDevice->wMaxTransmitMSDULifetime; // ms
1056 } else if ((wrq->flags & IW_RETRY_MAX)) {
1057 wrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
1058 wrq->value = (int)pDevice->byLongRetryLimit;
1060 wrq->flags = IW_RETRY_LIMIT;
1061 wrq->value = (int)pDevice->byShortRetryLimit;
1062 if ((int)pDevice->byShortRetryLimit != (int)pDevice->byLongRetryLimit)
1063 wrq->flags |= IW_RETRY_MIN;
1069 * Wireless Handler: set encode mode
1071 int iwctl_siwencode(struct net_device *dev, struct iw_request_info *info,
1072 struct iw_point *wrq, char *extra)
1074 PSDevice pDevice = netdev_priv(dev);
1075 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1076 DWORD dwKeyIndex = (DWORD)(wrq->flags & IW_ENCODE_INDEX);
1080 int index = (wrq->flags & IW_ENCODE_INDEX);
1082 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODE \n");
1084 // Check the size of the key
1085 if (wrq->length > WLAN_WEP232_KEYLEN) {
1090 if (dwKeyIndex > WLAN_WEP_NKEYS) {
1098 // Send the key to the card
1099 if (wrq->length > 0) {
1100 if (wrq->length == WLAN_WEP232_KEYLEN) {
1101 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 232 bit wep key\n");
1102 } else if (wrq->length == WLAN_WEP104_KEYLEN) {
1103 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 104 bit wep key\n");
1104 } else if (wrq->length == WLAN_WEP40_KEYLEN) {
1105 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 40 bit wep key, index= %d\n", (int)dwKeyIndex);
1107 memset(pDevice->abyKey, 0, WLAN_WEP232_KEYLEN);
1108 memcpy(pDevice->abyKey, extra, wrq->length);
1110 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyKey: ");
1111 for (ii = 0; ii < wrq->length; ii++)
1112 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pDevice->abyKey[ii]);
1114 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1115 spin_lock_irq(&pDevice->lock);
1116 KeybSetDefaultKey(pDevice,
1118 dwKeyIndex | (1 << 31),
1122 spin_unlock_irq(&pDevice->lock);
1124 pDevice->byKeyIndex = (BYTE)dwKeyIndex;
1125 pDevice->uKeyLength = wrq->length;
1126 pDevice->bTransmitKey = TRUE;
1127 pDevice->bEncryptionEnable = TRUE;
1128 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1130 // Do we want to just set the transmit key index?
1132 pDevice->byKeyIndex = index;
1133 } else if (!(wrq->flags & IW_ENCODE_MODE)) {
1139 if (wrq->flags & IW_ENCODE_DISABLED) {
1140 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable WEP function\n");
1141 pMgmt->bShareKeyAlgorithm = FALSE;
1142 pDevice->bEncryptionEnable = FALSE;
1143 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1144 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1145 spin_lock_irq(&pDevice->lock);
1146 for (uu = 0; uu < MAX_KEY_TABLE; uu++)
1147 MACvDisableKeyEntry(pDevice, uu);
1148 spin_unlock_irq(&pDevice->lock);
1151 if (wrq->flags & IW_ENCODE_RESTRICTED) {
1152 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & ShareKey System\n");
1153 pMgmt->bShareKeyAlgorithm = TRUE;
1155 if (wrq->flags & IW_ENCODE_OPEN) {
1156 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & Open System\n");
1157 pMgmt->bShareKeyAlgorithm = FALSE;
1160 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
1165 int iwctl_giwencode(struct net_device *dev, struct iw_request_info *info,
1166 struct iw_point *wrq, char *extra)
1168 PSDevice pDevice = netdev_priv(dev);
1169 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1170 char abyKey[WLAN_WEP232_KEYLEN];
1172 unsigned index = (unsigned)(wrq->flags & IW_ENCODE_INDEX);
1173 PSKeyItem pKey = NULL;
1175 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODE\n");
1177 if (index > WLAN_WEP_NKEYS)
1179 if (index < 1) { // get default key
1180 if (pDevice->byKeyIndex < WLAN_WEP_NKEYS)
1181 index = pDevice->byKeyIndex;
1188 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
1189 // Check encryption mode
1190 wrq->flags = IW_ENCODE_NOKEY;
1191 // Is WEP enabled ???
1192 if (pDevice->bEncryptionEnable)
1193 wrq->flags |= IW_ENCODE_ENABLED;
1195 wrq->flags |= IW_ENCODE_DISABLED;
1197 if (pMgmt->bShareKeyAlgorithm)
1198 wrq->flags |= IW_ENCODE_RESTRICTED;
1200 wrq->flags |= IW_ENCODE_OPEN;
1203 if ((index == 0) && (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled ||
1204 pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)) { // get wpa pairwise key
1205 if (KeybGetKey(&(pDevice->sKey), pMgmt->abyCurrBSSID, 0xffffffff, &pKey)) {
1206 wrq->length = pKey->uKeyLength;
1207 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1208 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1210 } else if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (BYTE)index, &pKey)) {
1211 wrq->length = pKey->uKeyLength;
1212 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1213 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1216 wrq->flags |= index + 1;
1221 * Wireless Handler: set power mode
1223 int iwctl_siwpower(struct net_device *dev, struct iw_request_info *info,
1224 struct iw_param *wrq, char *extra)
1226 PSDevice pDevice = netdev_priv(dev);
1227 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1230 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER \n");
1232 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
1237 if (wrq->disabled) {
1238 pDevice->ePSMode = WMAC_POWER_CAM;
1239 PSvDisablePowerSaving(pDevice);
1242 if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1243 pDevice->ePSMode = WMAC_POWER_FAST;
1244 PSvEnablePowerSaving((void *)pDevice, pMgmt->wListenInterval);
1246 } else if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
1247 pDevice->ePSMode = WMAC_POWER_FAST;
1248 PSvEnablePowerSaving((void *)pDevice, pMgmt->wListenInterval);
1250 switch (wrq->flags & IW_POWER_MODE) {
1251 case IW_POWER_UNICAST_R:
1252 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_UNICAST_R \n");
1255 case IW_POWER_ALL_R:
1256 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ALL_R \n");
1259 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ON \n");
1269 * Wireless Handler: get power mode
1271 int iwctl_giwpower(struct net_device *dev, struct iw_request_info *info,
1272 struct iw_param *wrq, char *extra)
1274 PSDevice pDevice = netdev_priv(dev);
1275 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1276 int mode = pDevice->ePSMode;
1278 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPOWER \n");
1280 if ((wrq->disabled = (mode == WMAC_POWER_CAM)))
1283 if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1284 wrq->value = (int)((pMgmt->wListenInterval * pMgmt->wCurrBeaconPeriod) << 10);
1285 wrq->flags = IW_POWER_TIMEOUT;
1287 wrq->value = (int)((pMgmt->wListenInterval * pMgmt->wCurrBeaconPeriod) << 10);
1288 wrq->flags = IW_POWER_PERIOD;
1290 wrq->flags |= IW_POWER_ALL_R;
1295 * Wireless Handler: get Sensitivity
1297 int iwctl_giwsens(struct net_device *dev, struct iw_request_info *info,
1298 struct iw_param *wrq, char *extra)
1300 PSDevice pDevice = netdev_priv(dev);
1303 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSENS \n");
1304 if (pDevice->bLinkPass == TRUE) {
1305 RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm);
1310 wrq->disabled = (wrq->value == 0);
1315 int iwctl_siwauth(struct net_device *dev, struct iw_request_info *info,
1316 struct iw_param *wrq, char *extra)
1318 PSDevice pDevice = netdev_priv(dev);
1319 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1321 static int wpa_version = 0; // must be static to save the last value, einsn liu
1322 static int pairwise = 0;
1324 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH \n");
1325 switch (wrq->flags & IW_AUTH_INDEX) {
1326 case IW_AUTH_WPA_VERSION:
1327 wpa_version = wrq->value;
1328 if (wrq->value == IW_AUTH_WPA_VERSION_DISABLED) {
1329 PRINT_K("iwctl_siwauth:set WPADEV to disable at 1??????\n");
1330 } else if (wrq->value == IW_AUTH_WPA_VERSION_WPA) {
1331 PRINT_K("iwctl_siwauth:set WPADEV to WPA1******\n");
1333 PRINT_K("iwctl_siwauth:set WPADEV to WPA2******\n");
1336 case IW_AUTH_CIPHER_PAIRWISE:
1337 pairwise = wrq->value;
1338 PRINT_K("iwctl_siwauth:set pairwise=%d\n", pairwise);
1339 if (pairwise == IW_AUTH_CIPHER_CCMP){
1340 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1341 } else if (pairwise == IW_AUTH_CIPHER_TKIP) {
1342 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1343 } else if (pairwise == IW_AUTH_CIPHER_WEP40 ||
1344 pairwise == IW_AUTH_CIPHER_WEP104) {
1345 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1346 } else if (pairwise == IW_AUTH_CIPHER_NONE) {
1347 // do nothing, einsn liu
1349 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1352 case IW_AUTH_CIPHER_GROUP:
1353 PRINT_K("iwctl_siwauth:set GROUP=%d\n", wrq->value);
1354 if (wpa_version == IW_AUTH_WPA_VERSION_DISABLED)
1356 if (pairwise == IW_AUTH_CIPHER_NONE) {
1357 if (wrq->value == IW_AUTH_CIPHER_CCMP)
1358 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1360 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1363 case IW_AUTH_KEY_MGMT:
1364 PRINT_K("iwctl_siwauth(wpa_version=%d):set KEY_MGMT=%d\n", wpa_version,wrq->value);
1365 if (wpa_version == IW_AUTH_WPA_VERSION_WPA2){
1366 if (wrq->value == IW_AUTH_KEY_MGMT_PSK)
1367 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
1368 else pMgmt->eAuthenMode = WMAC_AUTH_WPA2;
1369 } else if (wpa_version == IW_AUTH_WPA_VERSION_WPA) {
1370 if (wrq->value == 0){
1371 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
1372 } else if (wrq->value == IW_AUTH_KEY_MGMT_PSK)
1373 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
1375 pMgmt->eAuthenMode = WMAC_AUTH_WPA;
1378 case IW_AUTH_TKIP_COUNTERMEASURES:
1380 case IW_AUTH_DROP_UNENCRYPTED:
1382 case IW_AUTH_80211_AUTH_ALG:
1383 PRINT_K("iwctl_siwauth:set AUTH_ALG=%d\n", wrq->value);
1384 if (wrq->value == IW_AUTH_ALG_OPEN_SYSTEM)
1385 pMgmt->bShareKeyAlgorithm = FALSE;
1386 else if (wrq->value == IW_AUTH_ALG_SHARED_KEY)
1387 pMgmt->bShareKeyAlgorithm = TRUE;
1389 case IW_AUTH_WPA_ENABLED:
1391 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1393 case IW_AUTH_ROAMING_CONTROL:
1396 case IW_AUTH_PRIVACY_INVOKED:
1397 pDevice->bEncryptionEnable = !!wrq->value;
1398 if (pDevice->bEncryptionEnable == FALSE) {
1401 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1402 pMgmt->bShareKeyAlgorithm = FALSE;
1403 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
1404 PRINT_K("iwctl_siwauth:set WPADEV to disaable at 2?????\n");
1414 int iwctl_giwauth(struct net_device *dev, struct iw_request_info *info,
1415 struct iw_param *wrq, char *extra)
1420 int iwctl_siwgenie(struct net_device *dev, struct iw_request_info *info,
1421 struct iw_point *wrq, char *extra)
1423 PSDevice pDevice = netdev_priv(dev);
1424 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1428 if ((wrq->length < 2) || (extra[1] + 2 != wrq->length)) {
1432 if (wrq->length > MAX_WPA_IE_LEN){
1436 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
1437 if (copy_from_user(pMgmt->abyWPAIE, extra, wrq->length)){
1441 pMgmt->wWPAIELen = wrq->length;
1443 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
1444 pMgmt->wWPAIELen = 0;
1447 out: // not completely ...not necessary in wpa_supplicant 0.5.8
1451 int iwctl_giwgenie(struct net_device *dev, struct iw_request_info *info,
1452 struct iw_point *wrq, char *extra)
1454 PSDevice pDevice = netdev_priv(dev);
1455 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1457 int space = wrq->length;
1460 if (pMgmt->wWPAIELen > 0) {
1461 wrq->length = pMgmt->wWPAIELen;
1462 if (pMgmt->wWPAIELen <= space) {
1463 if (copy_to_user(extra, pMgmt->abyWPAIE, pMgmt->wWPAIELen)) {
1473 int iwctl_siwencodeext(struct net_device *dev, struct iw_request_info *info,
1474 struct iw_point *wrq, char *extra)
1476 PSDevice pDevice = netdev_priv(dev);
1477 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1478 struct iw_encode_ext *ext = (struct iw_encode_ext*)extra;
1479 struct viawget_wpa_param *param=NULL;
1485 u8 seq[IW_ENCODE_SEQ_MAX_SIZE];
1493 PRINT_K("SIOCSIWENCODEEXT......\n");
1495 buf = kzalloc(sizeof(struct viawget_wpa_param), GFP_KERNEL);
1499 param = (struct viawget_wpa_param *)buf;
1503 case IW_ENCODE_ALG_NONE:
1504 alg_name = WPA_ALG_NONE;
1506 case IW_ENCODE_ALG_WEP:
1507 alg_name = WPA_ALG_WEP;
1509 case IW_ENCODE_ALG_TKIP:
1510 alg_name = WPA_ALG_TKIP;
1512 case IW_ENCODE_ALG_CCMP:
1513 alg_name = WPA_ALG_CCMP;
1516 PRINT_K("Unknown alg = %d\n",ext->alg);
1521 memcpy(addr, ext->addr.sa_data, ETH_ALEN);
1523 key_idx = (wrq->flags&IW_ENCODE_INDEX) - 1;
1525 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
1527 // recover seq,seq_len
1528 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
1529 seq_len=IW_ENCODE_SEQ_MAX_SIZE;
1530 memcpy(seq, ext->rx_seq, seq_len);
1532 // recover key,key_len
1534 key_len = ext->key_len;
1535 memcpy(key, &ext->key[0], key_len);
1537 memset(key_array, 0, 64);
1539 memcpy(key_array, key, key_len);
1540 if (key_len == 32) {
1541 // notice ! the oder
1542 memcpy(&key_array[16], &key[24], 8);
1543 memcpy(&key_array[24], &key[16], 8);
1547 /**************Translate iw_encode_ext to viawget_wpa_param****************/
1548 memcpy(param->addr, addr, ETH_ALEN);
1549 param->u.wpa_key.alg_name = (int)alg_name;
1550 param->u.wpa_key.set_tx = set_tx;
1551 param->u.wpa_key.key_index = key_idx;
1552 param->u.wpa_key.key_len = key_len;
1553 param->u.wpa_key.key = (u8 *)key_array;
1554 param->u.wpa_key.seq = (u8 *)seq;
1555 param->u.wpa_key.seq_len = seq_len;
1557 /****set if current action is Network Manager count?? */
1558 /****this method is so foolish,but there is no other way??? */
1559 if (param->u.wpa_key.alg_name == WPA_ALG_NONE) {
1560 if (param->u.wpa_key.key_index ==0) {
1561 pDevice->bwextstep0 = TRUE;
1563 if ((pDevice->bwextstep0 == TRUE) && (param->u.wpa_key.key_index == 1)) {
1564 pDevice->bwextstep0 = FALSE;
1565 pDevice->bwextstep1 = TRUE;
1567 if ((pDevice->bwextstep1 == TRUE) && (param->u.wpa_key.key_index == 2)) {
1568 pDevice->bwextstep1 = FALSE;
1569 pDevice->bwextstep2 = TRUE;
1571 if ((pDevice->bwextstep2 == TRUE) && (param->u.wpa_key.key_index == 3)) {
1572 pDevice->bwextstep2 = FALSE;
1573 pDevice->bwextstep3 = TRUE;
1576 if (pDevice->bwextstep3 == TRUE) {
1577 PRINT_K("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n");
1578 pDevice->bwextstep0 = FALSE;
1579 pDevice->bwextstep1 = FALSE;
1580 pDevice->bwextstep2 = FALSE;
1581 pDevice->bwextstep3 = FALSE;
1582 pDevice->bWPASuppWextEnabled = TRUE;
1583 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
1584 KeyvInitTable(pDevice, &pDevice->sKey);
1587 spin_lock_irq(&pDevice->lock);
1588 ret = wpa_set_keys(pDevice, param, TRUE);
1589 spin_unlock_irq(&pDevice->lock);
1596 int iwctl_giwencodeext(struct net_device *dev, struct iw_request_info *info,
1597 struct iw_point *wrq, char *extra)
1602 int iwctl_siwmlme(struct net_device *dev, struct iw_request_info *info,
1603 struct iw_point *wrq, char *extra)
1605 PSDevice pDevice = netdev_priv(dev);
1606 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1607 struct iw_mlme *mlme = (struct iw_mlme *)extra;
1610 if (memcmp(pMgmt->abyCurrBSSID, mlme->addr.sa_data, ETH_ALEN)) {
1615 case IW_MLME_DEAUTH:
1616 case IW_MLME_DISASSOC:
1617 if (pDevice->bLinkPass == TRUE) {
1618 PRINT_K("iwctl_siwmlme--->send DISASSOCIATE\n");
1619 bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE,
1629 static const iw_handler iwctl_handler[] = {
1630 (iw_handler)NULL, // SIOCSIWCOMMIT
1631 (iw_handler)NULL, // SIOCGIWNAME
1632 (iw_handler)NULL, // SIOCSIWNWID
1633 (iw_handler)NULL, // SIOCGIWNWID
1634 (iw_handler)NULL, // SIOCSIWFREQ
1635 (iw_handler)NULL, // SIOCGIWFREQ
1636 (iw_handler)NULL, // SIOCSIWMODE
1637 (iw_handler)NULL, // SIOCGIWMODE
1638 (iw_handler)NULL, // SIOCSIWSENS
1639 (iw_handler)NULL, // SIOCGIWSENS
1640 (iw_handler)NULL, // SIOCSIWRANGE
1641 (iw_handler)iwctl_giwrange, // SIOCGIWRANGE
1642 (iw_handler)NULL, // SIOCSIWPRIV
1643 (iw_handler)NULL, // SIOCGIWPRIV
1644 (iw_handler)NULL, // SIOCSIWSTATS
1645 (iw_handler)NULL, // SIOCGIWSTATS
1646 (iw_handler)NULL, // SIOCSIWSPY
1647 (iw_handler)NULL, // SIOCGIWSPY
1648 (iw_handler)NULL, // -- hole --
1649 (iw_handler)NULL, // -- hole --
1650 (iw_handler)NULL, // SIOCSIWAP
1651 (iw_handler)NULL, // SIOCGIWAP
1652 (iw_handler)NULL, // -- hole -- 0x16
1653 (iw_handler)NULL, // SIOCGIWAPLIST
1654 (iw_handler)iwctl_siwscan, // SIOCSIWSCAN
1655 (iw_handler)iwctl_giwscan, // SIOCGIWSCAN
1656 (iw_handler)NULL, // SIOCSIWESSID
1657 (iw_handler)NULL, // SIOCGIWESSID
1658 (iw_handler)NULL, // SIOCSIWNICKN
1659 (iw_handler)NULL, // SIOCGIWNICKN
1660 (iw_handler)NULL, // -- hole --
1661 (iw_handler)NULL, // -- hole --
1662 (iw_handler)NULL, // SIOCSIWRATE 0x20
1663 (iw_handler)NULL, // SIOCGIWRATE
1664 (iw_handler)NULL, // SIOCSIWRTS
1665 (iw_handler)NULL, // SIOCGIWRTS
1666 (iw_handler)NULL, // SIOCSIWFRAG
1667 (iw_handler)NULL, // SIOCGIWFRAG
1668 (iw_handler)NULL, // SIOCSIWTXPOW
1669 (iw_handler)NULL, // SIOCGIWTXPOW
1670 (iw_handler)NULL, // SIOCSIWRETRY
1671 (iw_handler)NULL, // SIOCGIWRETRY
1672 (iw_handler)NULL, // SIOCSIWENCODE
1673 (iw_handler)NULL, // SIOCGIWENCODE
1674 (iw_handler)NULL, // SIOCSIWPOWER
1675 (iw_handler)NULL, // SIOCGIWPOWER
1676 (iw_handler)NULL, // -- hole --
1677 (iw_handler)NULL, // -- hole --
1678 (iw_handler)NULL, // SIOCSIWGENIE
1679 (iw_handler)NULL, // SIOCGIWGENIE
1680 (iw_handler)NULL, // SIOCSIWAUTH
1681 (iw_handler)NULL, // SIOCGIWAUTH
1682 (iw_handler)NULL, // SIOCSIWENCODEEXT
1683 (iw_handler)NULL, // SIOCGIWENCODEEXT
1684 (iw_handler)NULL, // SIOCSIWPMKSA
1685 (iw_handler)NULL, // -- hole --
1688 static const iw_handler iwctl_private_handler[] = {
1689 NULL, // SIOCIWFIRSTPRIV
1692 struct iw_priv_args iwctl_private_args[] = {
1693 { IOCTL_CMD_SET, IW_PRIV_TYPE_CHAR | 1024, 0, "set" },
1696 const struct iw_handler_def iwctl_handler_def = {
1697 .get_wireless_stats = &iwctl_get_wireless_stats,
1698 .num_standard = sizeof(iwctl_handler) / sizeof(iw_handler),
1700 .num_private_args = 0,
1701 .standard = (iw_handler *)iwctl_handler,
1703 .private_args = NULL,