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, char *extra)
640 struct sockaddr sock[IW_MAX_AP];
641 struct iw_quality qual[IW_MAX_AP];
642 PSDevice pDevice = netdev_priv(dev);
643 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
645 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAPLIST \n");
646 // Only super-user can see AP list
648 if (!capable(CAP_NET_ADMIN)) {
654 PKnownBSS pBSS = &(pMgmt->sBSSList[0]);
656 for (ii = 0, jj= 0; ii < MAX_BSS_NUM; ii++) {
657 pBSS = &(pMgmt->sBSSList[ii]);
662 memcpy(sock[jj].sa_data, pBSS->abyBSSID, 6);
663 sock[jj].sa_family = ARPHRD_ETHER;
664 qual[jj].level = pBSS->uRSSI;
665 qual[jj].qual = qual[jj].noise = 0;
666 qual[jj].updated = 2;
670 wrq->flags = 1; // Should be defined
672 memcpy(extra, sock, sizeof(struct sockaddr) * jj);
673 memcpy(extra + sizeof(struct sockaddr) * jj, qual, sizeof(struct iw_quality) * jj);
679 * Wireless Handler: set essid
681 int iwctl_siwessid(struct net_device *dev, struct iw_request_info *info,
682 struct iw_point *wrq, char *extra)
684 PSDevice pDevice = netdev_priv(dev);
685 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
686 PWLAN_IE_SSID pItemSSID;
688 if (!(pDevice->flags & DEVICE_FLAGS_OPENED))
691 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWESSID :\n");
693 pDevice->fWPA_Authened = FALSE;
694 // Check if we asked for `any'
695 if (wrq->flags == 0) {
696 // Just send an empty SSID list
697 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
698 memset(pMgmt->abyDesireBSSID, 0xFF,6);
699 PRINT_K("set essid to 'any' \n");
700 // Unknown desired AP, so here need not associate??
704 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
705 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
706 pItemSSID->byElementID = WLAN_EID_SSID;
708 memcpy(pItemSSID->abySSID, extra, wrq->length);
709 if (pItemSSID->abySSID[wrq->length - 1] == '\0') {
711 pItemSSID->len = wrq->length - 1;
713 pItemSSID->len = wrq->length;
715 PRINT_K("set essid to %s \n", pItemSSID->abySSID);
717 // mike: need clear desiredBSSID
718 if (pItemSSID->len==0) {
719 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
723 // Wext wil order another command of siwap to link
724 // with desired AP, so here need not associate??
725 if (pDevice->bWPASuppWextEnabled == TRUE) {
726 /*******search if in hidden ssid mode ****/
727 PKnownBSS pCurr = NULL;
728 BYTE abyTmpDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
730 unsigned uSameBssidNum = 0;
732 memcpy(abyTmpDesireSSID, pMgmt->abyDesireSSID, sizeof(abyTmpDesireSSID));
733 pCurr = BSSpSearchBSSList(pDevice, NULL,
735 pDevice->eConfigPHYMode);
738 PRINT_K("SIOCSIWESSID:hidden ssid site survey before associate.......\n");
739 vResetCommandTimer((void *)pDevice);
740 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
741 bScheduleCommand((void *)pDevice,
743 pMgmt->abyDesireSSID);
744 bScheduleCommand((void *)pDevice,
746 pMgmt->abyDesireSSID);
747 } else { // mike: to find out if that desired SSID is a
748 // hidden-ssid AP, by means of judging if there
749 // are two same BSSID exist in list ?
750 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
751 if (pMgmt->sBSSList[ii].bActive &&
752 !compare_ether_addr(pMgmt->sBSSList[ii].abyBSSID,
757 if (uSameBssidNum >= 2) { // hit: desired AP is in hidden ssid mode!!!
758 PRINT_K("SIOCSIWESSID:hidden ssid directly associate.......\n");
759 vResetCommandTimer((void *)pDevice);
760 pMgmt->eScanType = WMAC_SCAN_PASSIVE; // this scan type, you'll submit scan result!
761 bScheduleCommand((void *)pDevice,
763 pMgmt->abyDesireSSID);
764 bScheduleCommand((void *)pDevice,
766 pMgmt->abyDesireSSID);
772 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set essid = %s \n", pItemSSID->abySSID);
775 if (pDevice->flags & DEVICE_FLAGS_OPENED)
776 pDevice->bCommit = TRUE;
782 * Wireless Handler: get essid
784 void iwctl_giwessid(struct net_device *dev, struct iw_request_info *info,
785 struct iw_point *wrq, char *extra)
787 PSDevice pDevice = netdev_priv(dev);
788 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
789 PWLAN_IE_SSID pItemSSID;
791 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWESSID \n");
793 // Note: if wrq->u.data.flags != 0, we should get the relevant
794 // SSID from the SSID list...
796 // Get the current SSID
797 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
798 memcpy(extra, pItemSSID->abySSID, pItemSSID->len);
799 extra[pItemSSID->len] = '\0';
801 wrq->length = pItemSSID->len;
802 wrq->flags = 1; // active
806 * Wireless Handler: set data rate
808 int iwctl_siwrate(struct net_device *dev, struct iw_request_info *info,
809 struct iw_param *wrq, char *extra)
811 PSDevice pDevice = netdev_priv(dev);
815 BYTE abySupportedRates[13] = {
816 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48,
820 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRATE \n");
821 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
826 // First: get a valid bit rate value
828 // Which type of value
829 if ((wrq->value < 13) && (wrq->value >= 0)) {
830 // Setting by rate index
831 // Find value in the magic rate table
834 // Setting by frequency value
835 u8 normvalue = (u8)(wrq->value/500000);
837 // Check if rate is valid
838 for (i = 0; i < 13; i++) {
839 if (normvalue == abySupportedRates[i]) {
845 // -1 designed the max rate (mostly auto mode)
846 if (wrq->value == -1) {
847 // Get the highest available rate
848 for (i = 0; i < 13; i++) {
849 if (abySupportedRates[i] == 0)
856 // Check that it is valid
857 // brate is index of abySupportedRates[]
863 // Now, check if we want a fixed or auto value
864 if (wrq->fixed != 0) {
867 pDevice->bFixRate = TRUE;
868 if ((pDevice->byBBType == BB_TYPE_11B) && (brate > 3)) {
869 pDevice->uConnectionRate = 3;
871 pDevice->uConnectionRate = brate;
872 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fixed to Rate %d \n", pDevice->uConnectionRate);
875 pDevice->bFixRate = FALSE;
876 pDevice->uConnectionRate = 13;
883 * Wireless Handler: get data rate
885 void iwctl_giwrate(struct net_device *dev, struct iw_request_info *info,
886 struct iw_param *wrq, char *extra)
888 PSDevice pDevice = netdev_priv(dev);
889 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
891 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRATE \n");
893 BYTE abySupportedRates[13] = {
894 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30,
895 0x48, 0x60, 0x6C, 0x90
899 if (pDevice->uConnectionRate < 13) {
900 brate = abySupportedRates[pDevice->uConnectionRate];
902 if (pDevice->byBBType == BB_TYPE_11B)
904 if (pDevice->byBBType == BB_TYPE_11G)
906 if (pDevice->byBBType == BB_TYPE_11A)
909 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
910 if (pDevice->byBBType == BB_TYPE_11B)
912 if (pDevice->byBBType == BB_TYPE_11G)
914 if (pDevice->byBBType == BB_TYPE_11A)
917 if (pDevice->uConnectionRate == 13)
918 brate = abySupportedRates[pDevice->wCurrentRate];
919 wrq->value = brate * 500000;
920 // If more than one rate, set auto
921 if (pDevice->bFixRate == TRUE)
927 * Wireless Handler: set rts threshold
929 int iwctl_siwrts(struct net_device *dev, struct iw_param *wrq)
931 PSDevice pDevice = netdev_priv(dev);
933 if ((wrq->value < 0 || wrq->value > 2312) && !wrq->disabled)
936 else if (wrq->disabled)
937 pDevice->wRTSThreshold = 2312;
939 pDevice->wRTSThreshold = wrq->value;
945 * Wireless Handler: get rts
947 int iwctl_giwrts(struct net_device *dev, struct iw_request_info *info,
948 struct iw_param *wrq, char *extra)
950 PSDevice pDevice = netdev_priv(dev);
952 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRTS \n");
953 wrq->value = pDevice->wRTSThreshold;
954 wrq->disabled = (wrq->value >= 2312);
960 * Wireless Handler: set fragment threshold
962 int iwctl_siwfrag(struct net_device *dev, struct iw_request_info *info,
963 struct iw_param *wrq, char *extra)
965 PSDevice pDevice = netdev_priv(dev);
967 int fthr = wrq->value;
969 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFRAG \n");
973 if ((fthr < 256) || (fthr > 2312)) {
976 fthr &= ~0x1; // Get an even value
977 pDevice->wFragmentationThreshold = (u16)fthr;
983 * Wireless Handler: get fragment threshold
985 int iwctl_giwfrag(struct net_device *dev, struct iw_request_info *info,
986 struct iw_param *wrq, char *extra)
988 PSDevice pDevice = netdev_priv(dev);
990 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFRAG \n");
991 wrq->value = pDevice->wFragmentationThreshold;
992 wrq->disabled = (wrq->value >= 2312);
998 * Wireless Handler: set retry threshold
1000 int iwctl_siwretry(struct net_device *dev, struct iw_request_info *info,
1001 struct iw_param *wrq, char *extra)
1003 PSDevice pDevice = netdev_priv(dev);
1006 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRETRY \n");
1008 if (wrq->disabled) {
1013 if (wrq->flags & IW_RETRY_LIMIT) {
1014 if (wrq->flags & IW_RETRY_MAX) {
1015 pDevice->byLongRetryLimit = wrq->value;
1016 } else if (wrq->flags & IW_RETRY_MIN) {
1017 pDevice->byShortRetryLimit = wrq->value;
1019 // No modifier : set both
1020 pDevice->byShortRetryLimit = wrq->value;
1021 pDevice->byLongRetryLimit = wrq->value;
1024 if (wrq->flags & IW_RETRY_LIFETIME)
1025 pDevice->wMaxTransmitMSDULifetime = wrq->value;
1030 * Wireless Handler: get retry threshold
1032 int iwctl_giwretry(struct net_device *dev, struct iw_request_info *info,
1033 struct iw_param *wrq, char *extra)
1035 PSDevice pDevice = netdev_priv(dev);
1036 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRETRY \n");
1037 wrq->disabled = 0; // Can't be disabled
1039 // Note: by default, display the min retry number
1040 if ((wrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1041 wrq->flags = IW_RETRY_LIFETIME;
1042 wrq->value = (int)pDevice->wMaxTransmitMSDULifetime; // ms
1043 } else if ((wrq->flags & IW_RETRY_MAX)) {
1044 wrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
1045 wrq->value = (int)pDevice->byLongRetryLimit;
1047 wrq->flags = IW_RETRY_LIMIT;
1048 wrq->value = (int)pDevice->byShortRetryLimit;
1049 if ((int)pDevice->byShortRetryLimit != (int)pDevice->byLongRetryLimit)
1050 wrq->flags |= IW_RETRY_MIN;
1056 * Wireless Handler: set encode mode
1058 int iwctl_siwencode(struct net_device *dev, struct iw_request_info *info,
1059 struct iw_point *wrq, char *extra)
1061 PSDevice pDevice = netdev_priv(dev);
1062 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1063 DWORD dwKeyIndex = (DWORD)(wrq->flags & IW_ENCODE_INDEX);
1067 int index = (wrq->flags & IW_ENCODE_INDEX);
1069 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODE \n");
1071 // Check the size of the key
1072 if (wrq->length > WLAN_WEP232_KEYLEN) {
1077 if (dwKeyIndex > WLAN_WEP_NKEYS) {
1085 // Send the key to the card
1086 if (wrq->length > 0) {
1087 if (wrq->length == WLAN_WEP232_KEYLEN) {
1088 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 232 bit wep key\n");
1089 } else if (wrq->length == WLAN_WEP104_KEYLEN) {
1090 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 104 bit wep key\n");
1091 } else if (wrq->length == WLAN_WEP40_KEYLEN) {
1092 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 40 bit wep key, index= %d\n", (int)dwKeyIndex);
1094 memset(pDevice->abyKey, 0, WLAN_WEP232_KEYLEN);
1095 memcpy(pDevice->abyKey, extra, wrq->length);
1097 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyKey: ");
1098 for (ii = 0; ii < wrq->length; ii++)
1099 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pDevice->abyKey[ii]);
1101 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1102 spin_lock_irq(&pDevice->lock);
1103 KeybSetDefaultKey(pDevice,
1105 dwKeyIndex | (1 << 31),
1109 spin_unlock_irq(&pDevice->lock);
1111 pDevice->byKeyIndex = (BYTE)dwKeyIndex;
1112 pDevice->uKeyLength = wrq->length;
1113 pDevice->bTransmitKey = TRUE;
1114 pDevice->bEncryptionEnable = TRUE;
1115 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1117 // Do we want to just set the transmit key index?
1119 pDevice->byKeyIndex = index;
1120 } else if (!(wrq->flags & IW_ENCODE_MODE)) {
1126 if (wrq->flags & IW_ENCODE_DISABLED) {
1127 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable WEP function\n");
1128 pMgmt->bShareKeyAlgorithm = FALSE;
1129 pDevice->bEncryptionEnable = FALSE;
1130 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1131 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1132 spin_lock_irq(&pDevice->lock);
1133 for (uu = 0; uu < MAX_KEY_TABLE; uu++)
1134 MACvDisableKeyEntry(pDevice, uu);
1135 spin_unlock_irq(&pDevice->lock);
1138 if (wrq->flags & IW_ENCODE_RESTRICTED) {
1139 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & ShareKey System\n");
1140 pMgmt->bShareKeyAlgorithm = TRUE;
1142 if (wrq->flags & IW_ENCODE_OPEN) {
1143 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & Open System\n");
1144 pMgmt->bShareKeyAlgorithm = FALSE;
1147 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
1152 int iwctl_giwencode(struct net_device *dev, struct iw_request_info *info,
1153 struct iw_point *wrq, char *extra)
1155 PSDevice pDevice = netdev_priv(dev);
1156 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1157 char abyKey[WLAN_WEP232_KEYLEN];
1159 unsigned index = (unsigned)(wrq->flags & IW_ENCODE_INDEX);
1160 PSKeyItem pKey = NULL;
1162 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODE\n");
1164 if (index > WLAN_WEP_NKEYS)
1166 if (index < 1) { // get default key
1167 if (pDevice->byKeyIndex < WLAN_WEP_NKEYS)
1168 index = pDevice->byKeyIndex;
1175 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
1176 // Check encryption mode
1177 wrq->flags = IW_ENCODE_NOKEY;
1178 // Is WEP enabled ???
1179 if (pDevice->bEncryptionEnable)
1180 wrq->flags |= IW_ENCODE_ENABLED;
1182 wrq->flags |= IW_ENCODE_DISABLED;
1184 if (pMgmt->bShareKeyAlgorithm)
1185 wrq->flags |= IW_ENCODE_RESTRICTED;
1187 wrq->flags |= IW_ENCODE_OPEN;
1190 if ((index == 0) && (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled ||
1191 pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)) { // get wpa pairwise key
1192 if (KeybGetKey(&(pDevice->sKey), pMgmt->abyCurrBSSID, 0xffffffff, &pKey)) {
1193 wrq->length = pKey->uKeyLength;
1194 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1195 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1197 } else if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (BYTE)index, &pKey)) {
1198 wrq->length = pKey->uKeyLength;
1199 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1200 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1203 wrq->flags |= index + 1;
1208 * Wireless Handler: set power mode
1210 int iwctl_siwpower(struct net_device *dev, struct iw_request_info *info,
1211 struct iw_param *wrq, char *extra)
1213 PSDevice pDevice = netdev_priv(dev);
1214 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1217 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER \n");
1219 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
1224 if (wrq->disabled) {
1225 pDevice->ePSMode = WMAC_POWER_CAM;
1226 PSvDisablePowerSaving(pDevice);
1229 if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1230 pDevice->ePSMode = WMAC_POWER_FAST;
1231 PSvEnablePowerSaving((void *)pDevice, pMgmt->wListenInterval);
1233 } else if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
1234 pDevice->ePSMode = WMAC_POWER_FAST;
1235 PSvEnablePowerSaving((void *)pDevice, pMgmt->wListenInterval);
1237 switch (wrq->flags & IW_POWER_MODE) {
1238 case IW_POWER_UNICAST_R:
1239 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_UNICAST_R \n");
1242 case IW_POWER_ALL_R:
1243 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ALL_R \n");
1246 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ON \n");
1256 * Wireless Handler: get power mode
1258 int iwctl_giwpower(struct net_device *dev, struct iw_request_info *info,
1259 struct iw_param *wrq, char *extra)
1261 PSDevice pDevice = netdev_priv(dev);
1262 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1263 int mode = pDevice->ePSMode;
1265 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPOWER \n");
1267 if ((wrq->disabled = (mode == WMAC_POWER_CAM)))
1270 if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1271 wrq->value = (int)((pMgmt->wListenInterval * pMgmt->wCurrBeaconPeriod) << 10);
1272 wrq->flags = IW_POWER_TIMEOUT;
1274 wrq->value = (int)((pMgmt->wListenInterval * pMgmt->wCurrBeaconPeriod) << 10);
1275 wrq->flags = IW_POWER_PERIOD;
1277 wrq->flags |= IW_POWER_ALL_R;
1282 * Wireless Handler: get Sensitivity
1284 int iwctl_giwsens(struct net_device *dev, struct iw_request_info *info,
1285 struct iw_param *wrq, char *extra)
1287 PSDevice pDevice = netdev_priv(dev);
1290 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSENS \n");
1291 if (pDevice->bLinkPass == TRUE) {
1292 RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm);
1297 wrq->disabled = (wrq->value == 0);
1302 int iwctl_siwauth(struct net_device *dev, struct iw_request_info *info,
1303 struct iw_param *wrq, char *extra)
1305 PSDevice pDevice = netdev_priv(dev);
1306 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1308 static int wpa_version = 0; // must be static to save the last value, einsn liu
1309 static int pairwise = 0;
1311 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH \n");
1312 switch (wrq->flags & IW_AUTH_INDEX) {
1313 case IW_AUTH_WPA_VERSION:
1314 wpa_version = wrq->value;
1315 if (wrq->value == IW_AUTH_WPA_VERSION_DISABLED) {
1316 PRINT_K("iwctl_siwauth:set WPADEV to disable at 1??????\n");
1317 } else if (wrq->value == IW_AUTH_WPA_VERSION_WPA) {
1318 PRINT_K("iwctl_siwauth:set WPADEV to WPA1******\n");
1320 PRINT_K("iwctl_siwauth:set WPADEV to WPA2******\n");
1323 case IW_AUTH_CIPHER_PAIRWISE:
1324 pairwise = wrq->value;
1325 PRINT_K("iwctl_siwauth:set pairwise=%d\n", pairwise);
1326 if (pairwise == IW_AUTH_CIPHER_CCMP){
1327 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1328 } else if (pairwise == IW_AUTH_CIPHER_TKIP) {
1329 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1330 } else if (pairwise == IW_AUTH_CIPHER_WEP40 ||
1331 pairwise == IW_AUTH_CIPHER_WEP104) {
1332 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1333 } else if (pairwise == IW_AUTH_CIPHER_NONE) {
1334 // do nothing, einsn liu
1336 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1339 case IW_AUTH_CIPHER_GROUP:
1340 PRINT_K("iwctl_siwauth:set GROUP=%d\n", wrq->value);
1341 if (wpa_version == IW_AUTH_WPA_VERSION_DISABLED)
1343 if (pairwise == IW_AUTH_CIPHER_NONE) {
1344 if (wrq->value == IW_AUTH_CIPHER_CCMP)
1345 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1347 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1350 case IW_AUTH_KEY_MGMT:
1351 PRINT_K("iwctl_siwauth(wpa_version=%d):set KEY_MGMT=%d\n", wpa_version,wrq->value);
1352 if (wpa_version == IW_AUTH_WPA_VERSION_WPA2){
1353 if (wrq->value == IW_AUTH_KEY_MGMT_PSK)
1354 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
1355 else pMgmt->eAuthenMode = WMAC_AUTH_WPA2;
1356 } else if (wpa_version == IW_AUTH_WPA_VERSION_WPA) {
1357 if (wrq->value == 0){
1358 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
1359 } else if (wrq->value == IW_AUTH_KEY_MGMT_PSK)
1360 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
1362 pMgmt->eAuthenMode = WMAC_AUTH_WPA;
1365 case IW_AUTH_TKIP_COUNTERMEASURES:
1367 case IW_AUTH_DROP_UNENCRYPTED:
1369 case IW_AUTH_80211_AUTH_ALG:
1370 PRINT_K("iwctl_siwauth:set AUTH_ALG=%d\n", wrq->value);
1371 if (wrq->value == IW_AUTH_ALG_OPEN_SYSTEM)
1372 pMgmt->bShareKeyAlgorithm = FALSE;
1373 else if (wrq->value == IW_AUTH_ALG_SHARED_KEY)
1374 pMgmt->bShareKeyAlgorithm = TRUE;
1376 case IW_AUTH_WPA_ENABLED:
1378 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1380 case IW_AUTH_ROAMING_CONTROL:
1383 case IW_AUTH_PRIVACY_INVOKED:
1384 pDevice->bEncryptionEnable = !!wrq->value;
1385 if (pDevice->bEncryptionEnable == FALSE) {
1388 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1389 pMgmt->bShareKeyAlgorithm = FALSE;
1390 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
1391 PRINT_K("iwctl_siwauth:set WPADEV to disaable at 2?????\n");
1401 int iwctl_giwauth(struct net_device *dev, struct iw_request_info *info,
1402 struct iw_param *wrq, char *extra)
1407 int iwctl_siwgenie(struct net_device *dev, struct iw_request_info *info,
1408 struct iw_point *wrq, char *extra)
1410 PSDevice pDevice = netdev_priv(dev);
1411 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1415 if ((wrq->length < 2) || (extra[1] + 2 != wrq->length)) {
1419 if (wrq->length > MAX_WPA_IE_LEN){
1423 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
1424 if (copy_from_user(pMgmt->abyWPAIE, extra, wrq->length)){
1428 pMgmt->wWPAIELen = wrq->length;
1430 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
1431 pMgmt->wWPAIELen = 0;
1434 out: // not completely ...not necessary in wpa_supplicant 0.5.8
1438 int iwctl_giwgenie(struct net_device *dev, struct iw_request_info *info,
1439 struct iw_point *wrq, char *extra)
1441 PSDevice pDevice = netdev_priv(dev);
1442 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1444 int space = wrq->length;
1447 if (pMgmt->wWPAIELen > 0) {
1448 wrq->length = pMgmt->wWPAIELen;
1449 if (pMgmt->wWPAIELen <= space) {
1450 if (copy_to_user(extra, pMgmt->abyWPAIE, pMgmt->wWPAIELen)) {
1460 int iwctl_siwencodeext(struct net_device *dev, struct iw_request_info *info,
1461 struct iw_point *wrq, char *extra)
1463 PSDevice pDevice = netdev_priv(dev);
1464 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1465 struct iw_encode_ext *ext = (struct iw_encode_ext*)extra;
1466 struct viawget_wpa_param *param=NULL;
1472 u8 seq[IW_ENCODE_SEQ_MAX_SIZE];
1480 PRINT_K("SIOCSIWENCODEEXT......\n");
1482 buf = kzalloc(sizeof(struct viawget_wpa_param), GFP_KERNEL);
1486 param = (struct viawget_wpa_param *)buf;
1490 case IW_ENCODE_ALG_NONE:
1491 alg_name = WPA_ALG_NONE;
1493 case IW_ENCODE_ALG_WEP:
1494 alg_name = WPA_ALG_WEP;
1496 case IW_ENCODE_ALG_TKIP:
1497 alg_name = WPA_ALG_TKIP;
1499 case IW_ENCODE_ALG_CCMP:
1500 alg_name = WPA_ALG_CCMP;
1503 PRINT_K("Unknown alg = %d\n",ext->alg);
1508 memcpy(addr, ext->addr.sa_data, ETH_ALEN);
1510 key_idx = (wrq->flags&IW_ENCODE_INDEX) - 1;
1512 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
1514 // recover seq,seq_len
1515 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
1516 seq_len=IW_ENCODE_SEQ_MAX_SIZE;
1517 memcpy(seq, ext->rx_seq, seq_len);
1519 // recover key,key_len
1521 key_len = ext->key_len;
1522 memcpy(key, &ext->key[0], key_len);
1524 memset(key_array, 0, 64);
1526 memcpy(key_array, key, key_len);
1527 if (key_len == 32) {
1528 // notice ! the oder
1529 memcpy(&key_array[16], &key[24], 8);
1530 memcpy(&key_array[24], &key[16], 8);
1534 /**************Translate iw_encode_ext to viawget_wpa_param****************/
1535 memcpy(param->addr, addr, ETH_ALEN);
1536 param->u.wpa_key.alg_name = (int)alg_name;
1537 param->u.wpa_key.set_tx = set_tx;
1538 param->u.wpa_key.key_index = key_idx;
1539 param->u.wpa_key.key_len = key_len;
1540 param->u.wpa_key.key = (u8 *)key_array;
1541 param->u.wpa_key.seq = (u8 *)seq;
1542 param->u.wpa_key.seq_len = seq_len;
1544 /****set if current action is Network Manager count?? */
1545 /****this method is so foolish,but there is no other way??? */
1546 if (param->u.wpa_key.alg_name == WPA_ALG_NONE) {
1547 if (param->u.wpa_key.key_index ==0) {
1548 pDevice->bwextstep0 = TRUE;
1550 if ((pDevice->bwextstep0 == TRUE) && (param->u.wpa_key.key_index == 1)) {
1551 pDevice->bwextstep0 = FALSE;
1552 pDevice->bwextstep1 = TRUE;
1554 if ((pDevice->bwextstep1 == TRUE) && (param->u.wpa_key.key_index == 2)) {
1555 pDevice->bwextstep1 = FALSE;
1556 pDevice->bwextstep2 = TRUE;
1558 if ((pDevice->bwextstep2 == TRUE) && (param->u.wpa_key.key_index == 3)) {
1559 pDevice->bwextstep2 = FALSE;
1560 pDevice->bwextstep3 = TRUE;
1563 if (pDevice->bwextstep3 == TRUE) {
1564 PRINT_K("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n");
1565 pDevice->bwextstep0 = FALSE;
1566 pDevice->bwextstep1 = FALSE;
1567 pDevice->bwextstep2 = FALSE;
1568 pDevice->bwextstep3 = FALSE;
1569 pDevice->bWPASuppWextEnabled = TRUE;
1570 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
1571 KeyvInitTable(pDevice, &pDevice->sKey);
1574 spin_lock_irq(&pDevice->lock);
1575 ret = wpa_set_keys(pDevice, param, TRUE);
1576 spin_unlock_irq(&pDevice->lock);
1583 int iwctl_giwencodeext(struct net_device *dev, struct iw_request_info *info,
1584 struct iw_point *wrq, char *extra)
1589 int iwctl_siwmlme(struct net_device *dev, struct iw_request_info *info,
1590 struct iw_point *wrq, char *extra)
1592 PSDevice pDevice = netdev_priv(dev);
1593 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1594 struct iw_mlme *mlme = (struct iw_mlme *)extra;
1597 if (memcmp(pMgmt->abyCurrBSSID, mlme->addr.sa_data, ETH_ALEN)) {
1602 case IW_MLME_DEAUTH:
1603 case IW_MLME_DISASSOC:
1604 if (pDevice->bLinkPass == TRUE) {
1605 PRINT_K("iwctl_siwmlme--->send DISASSOCIATE\n");
1606 bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE,
1616 static const iw_handler iwctl_handler[] = {
1617 (iw_handler)NULL, // SIOCSIWCOMMIT
1618 (iw_handler)NULL, // SIOCGIWNAME
1619 (iw_handler)NULL, // SIOCSIWNWID
1620 (iw_handler)NULL, // SIOCGIWNWID
1621 (iw_handler)NULL, // SIOCSIWFREQ
1622 (iw_handler)NULL, // SIOCGIWFREQ
1623 (iw_handler)NULL, // SIOCSIWMODE
1624 (iw_handler)NULL, // SIOCGIWMODE
1625 (iw_handler)NULL, // SIOCSIWSENS
1626 (iw_handler)NULL, // SIOCGIWSENS
1627 (iw_handler)NULL, // SIOCSIWRANGE
1628 (iw_handler)iwctl_giwrange, // SIOCGIWRANGE
1629 (iw_handler)NULL, // SIOCSIWPRIV
1630 (iw_handler)NULL, // SIOCGIWPRIV
1631 (iw_handler)NULL, // SIOCSIWSTATS
1632 (iw_handler)NULL, // SIOCGIWSTATS
1633 (iw_handler)NULL, // SIOCSIWSPY
1634 (iw_handler)NULL, // SIOCGIWSPY
1635 (iw_handler)NULL, // -- hole --
1636 (iw_handler)NULL, // -- hole --
1637 (iw_handler)NULL, // SIOCSIWAP
1638 (iw_handler)NULL, // SIOCGIWAP
1639 (iw_handler)NULL, // -- hole -- 0x16
1640 (iw_handler)NULL, // SIOCGIWAPLIST
1641 (iw_handler)iwctl_siwscan, // SIOCSIWSCAN
1642 (iw_handler)iwctl_giwscan, // SIOCGIWSCAN
1643 (iw_handler)NULL, // SIOCSIWESSID
1644 (iw_handler)NULL, // SIOCGIWESSID
1645 (iw_handler)NULL, // SIOCSIWNICKN
1646 (iw_handler)NULL, // SIOCGIWNICKN
1647 (iw_handler)NULL, // -- hole --
1648 (iw_handler)NULL, // -- hole --
1649 (iw_handler)NULL, // SIOCSIWRATE 0x20
1650 (iw_handler)NULL, // SIOCGIWRATE
1651 (iw_handler)NULL, // SIOCSIWRTS
1652 (iw_handler)NULL, // SIOCGIWRTS
1653 (iw_handler)NULL, // SIOCSIWFRAG
1654 (iw_handler)NULL, // SIOCGIWFRAG
1655 (iw_handler)NULL, // SIOCSIWTXPOW
1656 (iw_handler)NULL, // SIOCGIWTXPOW
1657 (iw_handler)NULL, // SIOCSIWRETRY
1658 (iw_handler)NULL, // SIOCGIWRETRY
1659 (iw_handler)NULL, // SIOCSIWENCODE
1660 (iw_handler)NULL, // SIOCGIWENCODE
1661 (iw_handler)NULL, // SIOCSIWPOWER
1662 (iw_handler)NULL, // SIOCGIWPOWER
1663 (iw_handler)NULL, // -- hole --
1664 (iw_handler)NULL, // -- hole --
1665 (iw_handler)NULL, // SIOCSIWGENIE
1666 (iw_handler)NULL, // SIOCGIWGENIE
1667 (iw_handler)NULL, // SIOCSIWAUTH
1668 (iw_handler)NULL, // SIOCGIWAUTH
1669 (iw_handler)NULL, // SIOCSIWENCODEEXT
1670 (iw_handler)NULL, // SIOCGIWENCODEEXT
1671 (iw_handler)NULL, // SIOCSIWPMKSA
1672 (iw_handler)NULL, // -- hole --
1675 static const iw_handler iwctl_private_handler[] = {
1676 NULL, // SIOCIWFIRSTPRIV
1679 struct iw_priv_args iwctl_private_args[] = {
1680 { IOCTL_CMD_SET, IW_PRIV_TYPE_CHAR | 1024, 0, "set" },
1683 const struct iw_handler_def iwctl_handler_def = {
1684 .get_wireless_stats = &iwctl_get_wireless_stats,
1685 .num_standard = sizeof(iwctl_handler) / sizeof(iw_handler),
1687 .num_private_args = 0,
1688 .standard = (iw_handler *)iwctl_handler,
1690 .private_args = NULL,