2 *************************************************************************
4 * 5F., No.36, Taiyuan St., Jhubei City,
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
25 *************************************************************************
31 IOCTL related subroutines
35 -------- ---------- ----------------------------------------------
36 Rory Chen 01-03-2003 created
37 Rory Chen 02-14-2005 modify to support RT61
40 #include "rt_config.h"
43 extern ULONG RTDebugLevel;
47 #define WEP_SMALL_KEY_LEN (40/8)
48 #define WEP_LARGE_KEY_LEN (104/8)
50 #define GROUP_KEY_NO 4
52 extern UCHAR CipherWpa2Template[];
53 extern UCHAR CipherWpaPskTkip[];
54 extern UCHAR CipherWpaPskTkipLen;
56 typedef struct PACKED _RT_VERSION_INFO{
62 UINT DriverBuildMonth;
64 } RT_VERSION_INFO, *PRT_VERSION_INFO;
66 struct iw_priv_args privtab[] = {
68 IW_PRIV_TYPE_CHAR | 1024, 0,
71 { RTPRIV_IOCTL_SHOW, 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
73 { RTPRIV_IOCTL_SHOW, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
75 /* --- sub-ioctls definitions --- */
77 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "connStatus" },
79 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "driverVer" },
81 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "bainfo" },
83 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "descinfo" },
85 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "radio_off" },
87 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "radio_on" },
89 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "show" },
90 #if !defined(RT2860) && !defined(RT30xx)
91 { SHOW_ADHOC_ENTRY_INFO,
92 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "adhocEntry" },
94 /* --- sub-ioctls relations --- */
98 IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
101 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
105 IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
109 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
113 { RTPRIV_IOCTL_STATISTICS,
114 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
116 { RTPRIV_IOCTL_GSITESURVEY,
117 0, IW_PRIV_TYPE_CHAR | 1024,
122 IN PRTMP_ADAPTER pAdapter,
126 INT Set_WmmCapable_Proc(
127 IN PRTMP_ADAPTER pAd,
131 INT Set_NetworkType_Proc(
132 IN PRTMP_ADAPTER pAdapter,
135 INT Set_AuthMode_Proc(
136 IN PRTMP_ADAPTER pAdapter,
139 INT Set_EncrypType_Proc(
140 IN PRTMP_ADAPTER pAdapter,
143 INT Set_DefaultKeyID_Proc(
144 IN PRTMP_ADAPTER pAdapter,
148 IN PRTMP_ADAPTER pAdapter,
152 IN PRTMP_ADAPTER pAdapter,
156 IN PRTMP_ADAPTER pAdapter,
160 IN PRTMP_ADAPTER pAdapter,
164 IN PRTMP_ADAPTER pAdapter,
169 IN PRTMP_ADAPTER pAdapter,
173 IN PRTMP_ADAPTER pAd,
177 #if !defined(RT2860) && !defined(RT30xx)
179 IN PRTMP_ADAPTER pAdapter,
180 IN struct iwreq *wrq);
184 IN PRTMP_ADAPTER pAdapter,
185 IN struct iwreq *wrq);
187 VOID RTMPIoctlE2PROM(
188 IN PRTMP_ADAPTER pAdapter,
189 IN struct iwreq *wrq);
193 IN PRTMP_ADAPTER pAdapter,
194 IN struct iwreq *wrq);
199 NDIS_STATUS RTMPWPANoneAddKeyProc(
200 IN PRTMP_ADAPTER pAd,
203 INT Set_FragTest_Proc(
204 IN PRTMP_ADAPTER pAdapter,
207 INT Set_TGnWifiTest_Proc(
208 IN PRTMP_ADAPTER pAd,
211 INT Set_LongRetryLimit_Proc(
212 IN PRTMP_ADAPTER pAdapter,
215 INT Set_ShortRetryLimit_Proc(
216 IN PRTMP_ADAPTER pAdapter,
219 #if !defined(RT2860) && !defined(RT30xx)
220 INT Show_Adhoc_MacTable_Proc(
221 IN PRTMP_ADAPTER pAd,
227 INT (*set_proc)(PRTMP_ADAPTER pAdapter, PUCHAR arg);
228 } *PRTMP_PRIVATE_SET_PROC, RTMP_PRIVATE_SUPPORT_PROC[] = {
229 {"DriverVersion", Set_DriverVersion_Proc},
230 {"CountryRegion", Set_CountryRegion_Proc},
231 {"CountryRegionABand", Set_CountryRegionABand_Proc},
232 {"SSID", Set_SSID_Proc},
233 {"WirelessMode", Set_WirelessMode_Proc},
234 {"TxBurst", Set_TxBurst_Proc},
235 {"TxPreamble", Set_TxPreamble_Proc},
236 {"TxPower", Set_TxPower_Proc},
237 {"Channel", Set_Channel_Proc},
238 {"BGProtection", Set_BGProtection_Proc},
239 {"RTSThreshold", Set_RTSThreshold_Proc},
240 {"FragThreshold", Set_FragThreshold_Proc},
241 {"HtBw", Set_HtBw_Proc},
242 {"HtMcs", Set_HtMcs_Proc},
243 {"HtGi", Set_HtGi_Proc},
244 {"HtOpMode", Set_HtOpMode_Proc},
245 {"HtExtcha", Set_HtExtcha_Proc},
246 {"HtMpduDensity", Set_HtMpduDensity_Proc},
247 {"HtBaWinSize", Set_HtBaWinSize_Proc},
248 {"HtRdg", Set_HtRdg_Proc},
249 {"HtAmsdu", Set_HtAmsdu_Proc},
250 {"HtAutoBa", Set_HtAutoBa_Proc},
251 {"HtBaDecline", Set_BADecline_Proc},
252 {"HtProtect", Set_HtProtect_Proc},
253 {"HtMimoPs", Set_HtMimoPs_Proc},
254 #ifdef AGGREGATION_SUPPORT
255 {"PktAggregate", Set_PktAggregate_Proc},
259 {"WmmCapable", Set_WmmCapable_Proc},
261 {"IEEE80211H", Set_IEEE80211H_Proc},
262 {"NetworkType", Set_NetworkType_Proc},
263 {"AuthMode", Set_AuthMode_Proc},
264 {"EncrypType", Set_EncrypType_Proc},
265 {"DefaultKeyID", Set_DefaultKeyID_Proc},
266 {"Key1", Set_Key1_Proc},
267 {"Key2", Set_Key2_Proc},
268 {"Key3", Set_Key3_Proc},
269 {"Key4", Set_Key4_Proc},
270 {"WPAPSK", Set_WPAPSK_Proc},
271 {"ResetCounter", Set_ResetStatCounter_Proc},
272 {"PSMode", Set_PSMode_Proc},
274 {"Debug", Set_Debug_Proc},
276 {"WpaSupport", Set_Wpa_Support},
277 {"FixedTxMode", Set_FixedTxMode_Proc},
278 {"TGnWifiTest", Set_TGnWifiTest_Proc},
279 {"ForceGF", Set_ForceGF_Proc},
280 {"LongRetry", Set_LongRetryLimit_Proc},
281 {"ShortRetry", Set_ShortRetryLimit_Proc},
282 //2008/09/11:KH add to support efuse<--
284 {"efuseFreeNumber", set_eFuseGetFreeBlockCount_Proc},
285 {"efuseDump", set_eFusedump_Proc},
286 {"efuseLoadFromBin", set_eFuseLoadFromBin_Proc},
288 //2008/09/11:KH add to support efuse-->
294 IN PRTMP_ADAPTER pAd,
295 IN PNDIS_802_11_KEY pKey)
298 MAC_TABLE_ENTRY *pEntry;
300 DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey ------>\n"));
303 RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
304 if (RTMP_TEST_PSFLAG(pAd, fRTMP_PS_SET_PCI_CLK_OFF_COMMAND))
306 if (pAd->StaCfg.bRadio == FALSE)
308 RTMP_SET_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
311 DBGPRINT(RT_DEBUG_TRACE,("RTMPWPAAddKeyProc1==>\n"));
312 RTMPPCIeLinkCtrlValueRestore(pAd, RESTORE_HALT);
314 pAd->bPCIclkOff = FALSE;
318 if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
320 if (pKey->KeyIndex & 0x80000000)
322 if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
324 NdisZeroMemory(pAd->StaCfg.PMK, 32);
325 NdisMoveMemory(pAd->StaCfg.PMK, pKey->KeyMaterial, pKey->KeyLength);
329 NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));
330 pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
331 NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, pKey->KeyMaterial, LEN_TKIP_EK);
333 if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
335 NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
336 NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
340 NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
341 NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
344 // Decide its ChiperAlg
345 if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
346 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
347 else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)
348 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
350 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_NONE;
352 // Update these related information to MAC_TABLE_ENTRY
353 pEntry = &pAd->MacTab.Content[BSSID_WCID];
354 NdisMoveMemory(pEntry->PairwiseKey.Key, pAd->SharedKey[BSS0][0].Key, LEN_TKIP_EK);
355 NdisMoveMemory(pEntry->PairwiseKey.RxMic, pAd->SharedKey[BSS0][0].RxMic, LEN_TKIP_RXMICK);
356 NdisMoveMemory(pEntry->PairwiseKey.TxMic, pAd->SharedKey[BSS0][0].TxMic, LEN_TKIP_TXMICK);
357 pEntry->PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;
359 // Update pairwise key information to ASIC Shared Key Table
360 AsicAddSharedKeyEntry(pAd,
363 pAd->SharedKey[BSS0][0].CipherAlg,
364 pAd->SharedKey[BSS0][0].Key,
365 pAd->SharedKey[BSS0][0].TxMic,
366 pAd->SharedKey[BSS0][0].RxMic);
368 // Update ASIC WCID attribute table and IVEIV table
369 RTMPAddWcidAttributeEntry(pAd,
372 pAd->SharedKey[BSS0][0].CipherAlg,
375 if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
377 // set 802.1x port control
378 STA_PORT_SECURED(pAd);
380 // Indicate Connected for GUI
381 pAd->IndicateMediaState = NdisMediaStateConnected;
387 pAd->StaCfg.DefaultKeyId = (pKey->KeyIndex & 0xFF);
388 NdisZeroMemory(&pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId], sizeof(CIPHER_KEY));
389 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].KeyLen = LEN_TKIP_EK;
390 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key, pKey->KeyMaterial, LEN_TKIP_EK);
392 if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
394 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
395 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
399 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
400 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
403 // Update Shared Key CipherAlg
404 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_NONE;
405 if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
406 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_TKIP;
407 else if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)
408 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_AES;
410 // Update group key information to ASIC Shared Key Table
411 AsicAddSharedKeyEntry(pAd,
413 pAd->StaCfg.DefaultKeyId,
414 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
415 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key,
416 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic,
417 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic);
419 // Update ASIC WCID attribute table and IVEIV table
420 RTMPAddWcidAttributeEntry(pAd,
422 pAd->StaCfg.DefaultKeyId,
423 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
426 // set 802.1x port control
427 STA_PORT_SECURED(pAd);
429 // Indicate Connected for GUI
430 pAd->IndicateMediaState = NdisMediaStateConnected;
433 else // dynamic WEP from wpa_supplicant
438 if(pKey->KeyLength == 32)
441 KeyIdx = pKey->KeyIndex & 0x0fffffff;
445 // it is a default shared key, for Pairwise key setting
446 if (pKey->KeyIndex & 0x80000000)
448 pEntry = MacTableLookup(pAd, pKey->BSSID);
452 DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey: Set Pair-wise Key\n"));
454 // set key material and key length
455 pEntry->PairwiseKey.KeyLen = (UCHAR)pKey->KeyLength;
456 NdisMoveMemory(pEntry->PairwiseKey.Key, &pKey->KeyMaterial, pKey->KeyLength);
459 if (pKey->KeyLength == 5)
460 pEntry->PairwiseKey.CipherAlg = CIPHER_WEP64;
462 pEntry->PairwiseKey.CipherAlg = CIPHER_WEP128;
464 // Add Pair-wise key to Asic
465 AsicAddPairwiseKeyEntry(
469 &pEntry->PairwiseKey);
471 // update WCID attribute table and IVEIV table for this entry
472 RTMPAddWcidAttributeEntry(
475 KeyIdx, // The value may be not zero
476 pEntry->PairwiseKey.CipherAlg,
483 // Default key for tx (shared key)
484 pAd->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
486 // set key material and key length
487 pAd->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pKey->KeyLength;
488 NdisMoveMemory(pAd->SharedKey[BSS0][KeyIdx].Key, &pKey->KeyMaterial, pKey->KeyLength);
491 if (pKey->KeyLength == 5)
492 pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP64;
494 pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP128;
496 CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg;
497 Key = pAd->SharedKey[BSS0][KeyIdx].Key;
499 // Set Group key material to Asic
500 AsicAddSharedKeyEntry(pAd, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
502 // Update WCID attribute table and IVEIV table for this group key table
503 RTMPAddWcidAttributeEntry(pAd, BSS0, KeyIdx, CipherAlg, NULL);
510 RTMP_SET_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
511 DBGPRINT(RT_DEBUG_INFO, ("<------ RTMPAddKey\n"));
516 char * rtstrchr(const char * s, int c)
518 for(; *s != (char) c; ++s)
525 This is required for LinEX2004/kernel2.6.7 to provide iwlist scanning function
529 rt_ioctl_giwname(struct net_device *dev,
530 struct iw_request_info *info,
531 char *name, char *extra)
533 // PRTMP_ADAPTER pAdapter = dev->ml_priv;
535 strncpy(name, "RT2860 Wireless", IFNAMSIZ);
538 strncpy(name, "RT2870 Wireless", IFNAMSIZ);
543 int rt_ioctl_siwfreq(struct net_device *dev,
544 struct iw_request_info *info,
545 struct iw_freq *freq, char *extra)
547 PRTMP_ADAPTER pAdapter = dev->ml_priv;
550 //check if the interface is down
551 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
553 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
561 if((freq->e == 0) && (freq->m <= 1000))
562 chan = freq->m; // Setting by channel number
564 MAP_KHZ_TO_CHANNEL_ID( (freq->m /100) , chan); // Setting by frequency - search the table , like 2.412G, 2.422G,
566 if (ChannelSanity(pAdapter, chan) == TRUE)
568 pAdapter->CommonCfg.Channel = chan;
569 DBGPRINT(RT_DEBUG_ERROR, ("==>rt_ioctl_siwfreq::SIOCSIWFREQ[cmd=0x%x] (Channel=%d)\n", SIOCSIWFREQ, pAdapter->CommonCfg.Channel));
576 int rt_ioctl_giwfreq(struct net_device *dev,
577 struct iw_request_info *info,
578 struct iw_freq *freq, char *extra)
580 VIRTUAL_ADAPTER *pVirtualAd = NULL;
582 PRTMP_ADAPTER pAdapter = NULL;
585 PRTMP_ADAPTER pAdapter;
590 if (dev->priv_flags == INT_MAIN)
592 pAdapter = dev->ml_priv;
596 pVirtualAd = dev->ml_priv;
598 if (pVirtualAd && pVirtualAd->RtmpDev)
600 pAdapter = pVirtualAd->RtmpDev->ml_priv;
603 if (pAdapter == NULL)
605 /* if 1st open fail, pAd will be free;
606 So the net_dev->ml_priv will be NULL in 2rd open */
610 ch = pAdapter->CommonCfg.Channel;
612 DBGPRINT(RT_DEBUG_TRACE,("==>rt_ioctl_giwfreq %d\n", ch));
614 MAP_CHANNEL_ID_TO_KHZ(ch, m);
620 int rt_ioctl_siwmode(struct net_device *dev,
621 struct iw_request_info *info,
622 __u32 *mode, char *extra)
624 PRTMP_ADAPTER pAdapter = dev->ml_priv;
626 //check if the interface is down
627 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
629 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
636 Set_NetworkType_Proc(pAdapter, "Adhoc");
639 Set_NetworkType_Proc(pAdapter, "Infra");
641 case IW_MODE_MONITOR:
642 Set_NetworkType_Proc(pAdapter, "Monitor");
645 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_siwmode::SIOCSIWMODE (unknown %d)\n", *mode));
649 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
650 pAdapter->StaCfg.WpaState = SS_NOTUSE;
655 int rt_ioctl_giwmode(struct net_device *dev,
656 struct iw_request_info *info,
657 __u32 *mode, char *extra)
660 PRTMP_ADAPTER pAdapter = NULL;
661 VIRTUAL_ADAPTER *pVirtualAd = NULL;
663 if (dev->priv_flags == INT_MAIN)
665 pAdapter = dev->ml_priv;
669 pVirtualAd = dev->ml_priv;
670 if (pVirtualAd && pVirtualAd->RtmpDev)
671 pAdapter = pVirtualAd->RtmpDev->ml_priv;
674 if (pAdapter == NULL)
676 /* if 1st open fail, pAd will be free;
677 So the net_dev->ml_priv will be NULL in 2rd open */
682 PRTMP_ADAPTER pAdapter = dev->ml_priv;
685 if (ADHOC_ON(pAdapter))
686 *mode = IW_MODE_ADHOC;
687 else if (INFRA_ON(pAdapter))
688 *mode = IW_MODE_INFRA;
689 else if (MONITOR_ON(pAdapter))
691 *mode = IW_MODE_MONITOR;
694 *mode = IW_MODE_AUTO;
696 DBGPRINT(RT_DEBUG_TRACE, ("==>rt_ioctl_giwmode(mode=%d)\n", *mode));
700 int rt_ioctl_siwsens(struct net_device *dev,
701 struct iw_request_info *info,
702 char *name, char *extra)
704 PRTMP_ADAPTER pAdapter = dev->ml_priv;
706 //check if the interface is down
707 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
709 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
716 int rt_ioctl_giwsens(struct net_device *dev,
717 struct iw_request_info *info,
718 char *name, char *extra)
723 int rt_ioctl_giwrange(struct net_device *dev,
724 struct iw_request_info *info,
725 struct iw_point *data, char *extra)
728 PRTMP_ADAPTER pAdapter = NULL;
729 VIRTUAL_ADAPTER *pVirtualAd = NULL;
732 PRTMP_ADAPTER pAdapter = dev->ml_priv;
734 struct iw_range *range = (struct iw_range *) extra;
739 if (dev->priv_flags == INT_MAIN)
741 pAdapter = dev->ml_priv;
745 pVirtualAd = dev->ml_priv;
746 if (pVirtualAd && pVirtualAd->RtmpDev)
747 pAdapter = pVirtualAd->RtmpDev->ml_priv;
750 if (pAdapter == NULL)
752 /* if 1st open fail, pAd will be free;
753 So the net_dev->ml_priv will be NULL in 2rd open */
758 DBGPRINT(RT_DEBUG_TRACE ,("===>rt_ioctl_giwrange\n"));
759 data->length = sizeof(struct iw_range);
760 memset(range, 0, sizeof(struct iw_range));
762 range->txpower_capa = IW_TXPOW_DBM;
764 if (INFRA_ON(pAdapter)||ADHOC_ON(pAdapter))
766 range->min_pmp = 1 * 1024;
767 range->max_pmp = 65535 * 1024;
768 range->min_pmt = 1 * 1024;
769 range->max_pmt = 1000 * 1024;
770 range->pmp_flags = IW_POWER_PERIOD;
771 range->pmt_flags = IW_POWER_TIMEOUT;
772 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT |
773 IW_POWER_UNICAST_R | IW_POWER_ALL_R;
776 range->we_version_compiled = WIRELESS_EXT;
777 range->we_version_source = 14;
779 range->retry_capa = IW_RETRY_LIMIT;
780 range->retry_flags = IW_RETRY_LIMIT;
781 range->min_retry = 0;
782 range->max_retry = 255;
784 range->num_channels = pAdapter->ChannelListNum;
787 for (i = 1; i <= range->num_channels; i++)
790 range->freq[val].i = pAdapter->ChannelList[i-1].Channel;
791 MAP_CHANNEL_ID_TO_KHZ(pAdapter->ChannelList[i-1].Channel, m);
792 range->freq[val].m = m * 100; /* HZ */
794 range->freq[val].e = 1;
796 if (val == IW_MAX_FREQUENCIES)
799 range->num_frequency = val;
801 range->max_qual.qual = 100; /* what is correct max? This was not
802 * documented exactly. At least
803 * 69 has been observed. */
804 range->max_qual.level = 0; /* dB */
805 range->max_qual.noise = 0; /* dB */
807 /* What would be suitable values for "average/typical" qual? */
808 range->avg_qual.qual = 20;
809 range->avg_qual.level = -60;
810 range->avg_qual.noise = -95;
811 range->sensitivity = 3;
813 range->max_encoding_tokens = NR_WEP_KEYS;
814 range->num_encoding_sizes = 2;
815 range->encoding_size[0] = 5;
816 range->encoding_size[1] = 13;
819 range->max_rts = 2347;
820 range->min_frag = 256;
821 range->max_frag = 2346;
823 #if WIRELESS_EXT > 17
824 /* IW_ENC_CAPA_* bit field */
825 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
826 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
832 int rt_ioctl_siwap(struct net_device *dev,
833 struct iw_request_info *info,
834 struct sockaddr *ap_addr, char *extra)
836 PRTMP_ADAPTER pAdapter = dev->ml_priv;
837 NDIS_802_11_MAC_ADDRESS Bssid;
839 //check if the interface is down
840 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
842 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
846 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
848 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
849 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
852 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
853 // this request, because this request is initiated by NDIS.
854 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
855 // Prevent to connect AP again in STAMlmePeriodicExec
856 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
858 memset(Bssid, 0, MAC_ADDR_LEN);
859 memcpy(Bssid, ap_addr->sa_data, MAC_ADDR_LEN);
860 MlmeEnqueue(pAdapter,
861 MLME_CNTL_STATE_MACHINE,
863 sizeof(NDIS_802_11_MAC_ADDRESS),
866 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCSIWAP %02x:%02x:%02x:%02x:%02x:%02x\n",
867 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
872 int rt_ioctl_giwap(struct net_device *dev,
873 struct iw_request_info *info,
874 struct sockaddr *ap_addr, char *extra)
877 PRTMP_ADAPTER pAdapter = NULL;
878 VIRTUAL_ADAPTER *pVirtualAd = NULL;
880 if (dev->priv_flags == INT_MAIN)
882 pAdapter = dev->ml_priv;
886 pVirtualAd = dev->ml_priv;
887 if (pVirtualAd && pVirtualAd->RtmpDev)
888 pAdapter = pVirtualAd->RtmpDev->ml_priv;
891 if (pAdapter == NULL)
893 /* if 1st open fail, pAd will be free;
894 So the net_dev->ml_priv will be NULL in 2rd open */
899 PRTMP_ADAPTER pAdapter = dev->ml_priv;
902 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
904 ap_addr->sa_family = ARPHRD_ETHER;
905 memcpy(ap_addr->sa_data, &pAdapter->CommonCfg.Bssid, ETH_ALEN);
908 else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
910 ap_addr->sa_family = ARPHRD_ETHER;
911 memcpy(ap_addr->sa_data, &pAdapter->MlmeAux.Bssid, ETH_ALEN);
915 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIWAP(=EMPTY)\n"));
923 * Units are in db above the noise floor. That means the
924 * rssi values reported in the tx/rx descriptors in the
925 * driver are the SNR expressed in db.
927 * If you assume that the noise floor is -95, which is an
928 * excellent assumption 99.5 % of the time, then you can
929 * derive the absolute signal level (i.e. -95 + rssi).
930 * There are some other slight factors to take into account
931 * depending on whether the rssi measurement is from 11b,
932 * 11g, or 11a. These differences are at most 2db and
935 * NB: various calculations are based on the orinoco/wavelan
936 * drivers for compatibility
938 static void set_quality(PRTMP_ADAPTER pAdapter,
939 struct iw_quality *iq,
946 ChannelQuality = 100;
947 else if (rssi >= -80) // between -50 ~ -80dbm
948 ChannelQuality = (__u8)(24 + ((rssi + 80) * 26)/10);
949 else if (rssi >= -90) // between -80 ~ -90dbm
950 ChannelQuality = (__u8)((rssi + 90) * 26)/10;
954 iq->qual = (__u8)ChannelQuality;
956 iq->level = (__u8)(rssi);
957 iq->noise = (pAdapter->BbpWriteLatch[66] > pAdapter->BbpTuning.FalseCcaUpperThreshold) ? ((__u8)pAdapter->BbpTuning.FalseCcaUpperThreshold) : ((__u8) pAdapter->BbpWriteLatch[66]); // noise level (dBm)
958 iq->noise += 256 - 143;
959 iq->updated = pAdapter->iw_stats.qual.updated;
962 int rt_ioctl_iwaplist(struct net_device *dev,
963 struct iw_request_info *info,
964 struct iw_point *data, char *extra)
966 PRTMP_ADAPTER pAdapter = dev->ml_priv;
968 struct sockaddr addr[IW_MAX_AP];
969 struct iw_quality qual[IW_MAX_AP];
972 //check if the interface is down
973 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
975 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
981 for (i = 0; i <IW_MAX_AP ; i++)
983 if (i >= pAdapter->ScanTab.BssNr)
985 addr[i].sa_family = ARPHRD_ETHER;
986 memcpy(addr[i].sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
987 set_quality(pAdapter, &qual[i], pAdapter->ScanTab.BssEntry[i].Rssi);
990 memcpy(extra, &addr, i*sizeof(addr[0]));
991 data->flags = 1; /* signal quality present (sort of) */
992 memcpy(extra + i*sizeof(addr[0]), &qual, i*sizeof(qual[i]));
998 int rt_ioctl_siwscan(struct net_device *dev,
999 struct iw_request_info *info,
1000 struct iw_point *data, char *extra)
1002 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1005 int Status = NDIS_STATUS_SUCCESS;
1007 //check if the interface is down
1008 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1010 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1014 if (MONITOR_ON(pAdapter))
1016 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
1020 if ((pAdapter->OpMode == OPMODE_STA) && (IDLE_ON(pAdapter))
1021 && (pAdapter->StaCfg.bRadio == TRUE)
1022 && (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_IDLE_RADIO_OFF)))
1024 RT28xxPciAsicRadioOn(pAdapter, GUI_IDLE_POWER_SAVE);
1026 // Check if still radio off.
1027 else if (pAdapter->bPCIclkOff == TRUE)
1030 if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
1032 pAdapter->StaCfg.WpaSupplicantScanCount++;
1035 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
1036 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
1041 if ((pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE) &&
1042 (pAdapter->StaCfg.WpaSupplicantScanCount > 3))
1044 DBGPRINT(RT_DEBUG_TRACE, ("!!! WpaSupplicantScanCount > 3\n"));
1045 Status = NDIS_STATUS_SUCCESS;
1049 if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
1050 ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
1051 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) &&
1052 (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
1054 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
1055 Status = NDIS_STATUS_SUCCESS;
1059 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
1061 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
1062 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
1065 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
1066 // this request, because this request is initiated by NDIS.
1067 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
1068 // Reset allowed scan retries
1069 pAdapter->StaCfg.ScanCnt = 0;
1070 pAdapter->StaCfg.LastScanTime = Now;
1072 MlmeEnqueue(pAdapter,
1073 MLME_CNTL_STATE_MACHINE,
1074 OID_802_11_BSSID_LIST_SCAN,
1078 Status = NDIS_STATUS_SUCCESS;
1079 RT28XX_MLME_HANDLER(pAdapter);
1084 int rt_ioctl_giwscan(struct net_device *dev,
1085 struct iw_request_info *info,
1086 struct iw_point *data, char *extra)
1089 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1091 char *current_ev = extra, *previous_ev = extra;
1093 char *current_val, custom[MAX_CUSTOM_LEN] = {0};
1096 #endif // IWEVGENIE //
1097 struct iw_event iwe;
1099 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
1102 * Still scanning, indicate the caller should try again.
1107 if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
1109 pAdapter->StaCfg.WpaSupplicantScanCount = 0;
1112 if (pAdapter->ScanTab.BssNr == 0)
1118 #if WIRELESS_EXT >= 17
1119 if (data->length > 0)
1120 end_buf = extra + data->length;
1122 end_buf = extra + IW_SCAN_MAX_DATA;
1124 end_buf = extra + IW_SCAN_MAX_DATA;
1127 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
1129 if (current_ev >= end_buf)
1131 #if WIRELESS_EXT >= 17
1139 //================================
1140 memset(&iwe, 0, sizeof(iwe));
1141 iwe.cmd = SIOCGIWAP;
1142 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1143 memcpy(iwe.u.ap_addr.sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, ETH_ALEN);
1145 previous_ev = current_ev;
1146 current_ev = iwe_stream_add_event(info, current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);
1148 if (current_ev == previous_ev)
1149 #if WIRELESS_EXT >= 17
1157 it will show scanned AP's WirelessMode .
1166 memset(&iwe, 0, sizeof(iwe));
1167 iwe.cmd = SIOCGIWNAME;
1171 PBSS_ENTRY pBssEntry=&pAdapter->ScanTab.BssEntry[i];
1172 BOOLEAN isGonly=FALSE;
1175 if (pBssEntry->Channel>14)
1177 if (pBssEntry->HtCapabilityLen!=0)
1178 strcpy(iwe.u.name,"802.11a/n");
1180 strcpy(iwe.u.name,"802.11a");
1185 if one of non B mode rate is set supported rate . it mean G only.
1187 for (rateCnt=0;rateCnt<pBssEntry->SupRateLen;rateCnt++)
1190 6Mbps(140) 9Mbps(146) and >=12Mbps(152) are supported rate , it mean G only.
1192 if (pBssEntry->SupRate[rateCnt]==140 || pBssEntry->SupRate[rateCnt]==146 || pBssEntry->SupRate[rateCnt]>=152)
1196 for (rateCnt=0;rateCnt<pBssEntry->ExtRateLen;rateCnt++)
1198 if (pBssEntry->ExtRate[rateCnt]==140 || pBssEntry->ExtRate[rateCnt]==146 || pBssEntry->ExtRate[rateCnt]>=152)
1203 if (pBssEntry->HtCapabilityLen!=0)
1206 strcpy(iwe.u.name,"802.11g/n");
1208 strcpy(iwe.u.name,"802.11b/g/n");
1213 strcpy(iwe.u.name,"802.11g");
1216 if (pBssEntry->SupRateLen==4 && pBssEntry->ExtRateLen==0)
1217 strcpy(iwe.u.name,"802.11b");
1219 strcpy(iwe.u.name,"802.11b/g");
1225 previous_ev = current_ev;
1226 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
1228 if (current_ev == previous_ev)
1229 #if WIRELESS_EXT >= 17
1236 //================================
1237 memset(&iwe, 0, sizeof(iwe));
1238 iwe.cmd = SIOCGIWESSID;
1239 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].SsidLen;
1240 iwe.u.data.flags = 1;
1242 previous_ev = current_ev;
1243 current_ev = iwe_stream_add_point(info, current_ev,end_buf, &iwe, pAdapter->ScanTab.BssEntry[i].Ssid);
1244 if (current_ev == previous_ev)
1245 #if WIRELESS_EXT >= 17
1252 //================================
1253 memset(&iwe, 0, sizeof(iwe));
1254 iwe.cmd = SIOCGIWMODE;
1255 if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11IBSS)
1257 iwe.u.mode = IW_MODE_ADHOC;
1259 else if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11Infrastructure)
1261 iwe.u.mode = IW_MODE_INFRA;
1265 iwe.u.mode = IW_MODE_AUTO;
1267 iwe.len = IW_EV_UINT_LEN;
1269 previous_ev = current_ev;
1270 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
1271 if (current_ev == previous_ev)
1272 #if WIRELESS_EXT >= 17
1278 //Channel and Frequency
1279 //================================
1280 memset(&iwe, 0, sizeof(iwe));
1281 iwe.cmd = SIOCGIWFREQ;
1282 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
1283 iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
1285 iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
1289 previous_ev = current_ev;
1290 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
1291 if (current_ev == previous_ev)
1292 #if WIRELESS_EXT >= 17
1298 //Add quality statistics
1299 //================================
1300 memset(&iwe, 0, sizeof(iwe));
1302 iwe.u.qual.level = 0;
1303 iwe.u.qual.noise = 0;
1304 set_quality(pAdapter, &iwe.u.qual, pAdapter->ScanTab.BssEntry[i].Rssi);
1305 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
1306 if (current_ev == previous_ev)
1307 #if WIRELESS_EXT >= 17
1314 //================================
1315 memset(&iwe, 0, sizeof(iwe));
1316 iwe.cmd = SIOCGIWENCODE;
1317 if (CAP_IS_PRIVACY_ON (pAdapter->ScanTab.BssEntry[i].CapabilityInfo ))
1318 iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1320 iwe.u.data.flags = IW_ENCODE_DISABLED;
1322 previous_ev = current_ev;
1323 current_ev = iwe_stream_add_point(info, current_ev, end_buf,&iwe, (char *)pAdapter->SharedKey[BSS0][(iwe.u.data.flags & IW_ENCODE_INDEX)-1].Key);
1324 if (current_ev == previous_ev)
1325 #if WIRELESS_EXT >= 17
1332 //================================
1333 if (pAdapter->ScanTab.BssEntry[i].SupRateLen)
1335 UCHAR tmpRate = pAdapter->ScanTab.BssEntry[i].SupRate[pAdapter->ScanTab.BssEntry[i].SupRateLen-1];
1336 memset(&iwe, 0, sizeof(iwe));
1337 iwe.cmd = SIOCGIWRATE;
1338 current_val = current_ev + IW_EV_LCP_LEN;
1339 if (tmpRate == 0x82)
1340 iwe.u.bitrate.value = 1 * 1000000;
1341 else if (tmpRate == 0x84)
1342 iwe.u.bitrate.value = 2 * 1000000;
1343 else if (tmpRate == 0x8B)
1344 iwe.u.bitrate.value = 5.5 * 1000000;
1345 else if (tmpRate == 0x96)
1346 iwe.u.bitrate.value = 11 * 1000000;
1348 iwe.u.bitrate.value = (tmpRate/2) * 1000000;
1350 iwe.u.bitrate.disabled = 0;
1351 current_val = iwe_stream_add_value(info, current_ev,
1352 current_val, end_buf, &iwe,
1355 if((current_val-current_ev)>IW_EV_LCP_LEN)
1356 current_ev = current_val;
1358 #if WIRELESS_EXT >= 17
1367 if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
1369 memset(&iwe, 0, sizeof(iwe));
1370 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1371 memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].WpaIE.IE[0]),
1372 pAdapter->ScanTab.BssEntry[i].WpaIE.IELen);
1373 iwe.cmd = IWEVGENIE;
1374 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].WpaIE.IELen;
1375 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, custom);
1376 if (current_ev == previous_ev)
1377 #if WIRELESS_EXT >= 17
1385 if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
1387 memset(&iwe, 0, sizeof(iwe));
1388 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1389 memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].RsnIE.IE[0]),
1390 pAdapter->ScanTab.BssEntry[i].RsnIE.IELen);
1391 iwe.cmd = IWEVGENIE;
1392 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].RsnIE.IELen;
1393 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, custom);
1394 if (current_ev == previous_ev)
1395 #if WIRELESS_EXT >= 17
1403 //================================
1404 if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
1406 NdisZeroMemory(&iwe, sizeof(iwe));
1407 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1408 iwe.cmd = IWEVCUSTOM;
1409 iwe.u.data.length = (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen * 2) + 7;
1410 NdisMoveMemory(custom, "wpa_ie=", 7);
1411 for (idx = 0; idx < pAdapter->ScanTab.BssEntry[i].WpaIE.IELen; idx++)
1412 sprintf(custom + strlen(custom), "%02x", pAdapter->ScanTab.BssEntry[i].WpaIE.IE[idx]);
1413 previous_ev = current_ev;
1414 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, custom);
1415 if (current_ev == previous_ev)
1416 #if WIRELESS_EXT >= 17
1424 if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
1426 NdisZeroMemory(&iwe, sizeof(iwe));
1427 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1428 iwe.cmd = IWEVCUSTOM;
1429 iwe.u.data.length = (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen * 2) + 7;
1430 NdisMoveMemory(custom, "rsn_ie=", 7);
1431 for (idx = 0; idx < pAdapter->ScanTab.BssEntry[i].RsnIE.IELen; idx++)
1432 sprintf(custom + strlen(custom), "%02x", pAdapter->ScanTab.BssEntry[i].RsnIE.IE[idx]);
1433 previous_ev = current_ev;
1434 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, custom);
1435 if (current_ev == previous_ev)
1436 #if WIRELESS_EXT >= 17
1442 #endif // IWEVGENIE //
1445 data->length = current_ev - extra;
1446 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
1447 DBGPRINT(RT_DEBUG_ERROR ,("===>rt_ioctl_giwscan. %d(%d) BSS returned, data->length = %d\n",i , pAdapter->ScanTab.BssNr, data->length));
1452 int rt_ioctl_siwessid(struct net_device *dev,
1453 struct iw_request_info *info,
1454 struct iw_point *data, char *essid)
1456 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1458 //check if the interface is down
1459 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1461 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1467 PCHAR pSsidString = NULL;
1469 // Includes null character.
1470 if (data->length > (IW_ESSID_MAX_SIZE + 1))
1473 pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
1476 NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
1477 NdisMoveMemory(pSsidString, essid, data->length);
1478 if (Set_SSID_Proc(pAdapter, pSsidString) == FALSE)
1487 if (Set_SSID_Proc(pAdapter, "") == FALSE)
1493 int rt_ioctl_giwessid(struct net_device *dev,
1494 struct iw_request_info *info,
1495 struct iw_point *data, char *essid)
1498 PRTMP_ADAPTER pAdapter = NULL;
1499 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1501 if (dev->priv_flags == INT_MAIN)
1503 pAdapter = dev->ml_priv;
1507 pVirtualAd = dev->ml_priv;
1508 if (pVirtualAd && pVirtualAd->RtmpDev)
1509 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1512 if (pAdapter == NULL)
1514 /* if 1st open fail, pAd will be free;
1515 So the net_dev->ml_priv will be NULL in 2rd open */
1520 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1524 if (MONITOR_ON(pAdapter))
1530 if (OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED))
1532 DBGPRINT(RT_DEBUG_TRACE ,("MediaState is connected\n"));
1533 data->length = pAdapter->CommonCfg.SsidLen;
1534 memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
1538 else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
1540 data->length = pAdapter->CommonCfg.SsidLen;
1541 memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
1545 {//the ANY ssid was specified
1547 DBGPRINT(RT_DEBUG_TRACE ,("MediaState is not connected, ess\n"));
1554 int rt_ioctl_siwnickn(struct net_device *dev,
1555 struct iw_request_info *info,
1556 struct iw_point *data, char *nickname)
1558 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1560 //check if the interface is down
1561 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1563 DBGPRINT(RT_DEBUG_TRACE ,("INFO::Network is down!\n"));
1567 if (data->length > IW_ESSID_MAX_SIZE)
1570 memset(pAdapter->nickname, 0, IW_ESSID_MAX_SIZE + 1);
1571 memcpy(pAdapter->nickname, nickname, data->length);
1577 int rt_ioctl_giwnickn(struct net_device *dev,
1578 struct iw_request_info *info,
1579 struct iw_point *data, char *nickname)
1582 PRTMP_ADAPTER pAdapter = NULL;
1583 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1585 if (dev->priv_flags == INT_MAIN)
1587 pAdapter = dev->ml_priv;
1591 pVirtualAd = dev->ml_priv;
1592 if (pVirtualAd && pVirtualAd->RtmpDev)
1593 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1596 if (pAdapter == NULL)
1598 /* if 1st open fail, pAd will be free;
1599 So the net_dev->ml_priv will be NULL in 2rd open */
1604 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1607 if (data->length > strlen(pAdapter->nickname) + 1)
1608 data->length = strlen(pAdapter->nickname) + 1;
1609 if (data->length > 0) {
1610 memcpy(nickname, pAdapter->nickname, data->length-1);
1611 nickname[data->length-1] = '\0';
1616 int rt_ioctl_siwrts(struct net_device *dev,
1617 struct iw_request_info *info,
1618 struct iw_param *rts, char *extra)
1620 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1623 //check if the interface is down
1624 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1626 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1631 val = MAX_RTS_THRESHOLD;
1632 else if (rts->value < 0 || rts->value > MAX_RTS_THRESHOLD)
1634 else if (rts->value == 0)
1635 val = MAX_RTS_THRESHOLD;
1639 if (val != pAdapter->CommonCfg.RtsThreshold)
1640 pAdapter->CommonCfg.RtsThreshold = val;
1645 int rt_ioctl_giwrts(struct net_device *dev,
1646 struct iw_request_info *info,
1647 struct iw_param *rts, char *extra)
1650 PRTMP_ADAPTER pAdapter = NULL;
1651 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1653 if (dev->priv_flags == INT_MAIN)
1655 pAdapter = dev->ml_priv;
1659 pVirtualAd = dev->ml_priv;
1660 if (pVirtualAd && pVirtualAd->RtmpDev)
1661 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1664 if (pAdapter == NULL)
1666 /* if 1st open fail, pAd will be free;
1667 So the net_dev->ml_priv will be NULL in 2rd open */
1672 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1675 //check if the interface is down
1676 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1678 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1682 rts->value = pAdapter->CommonCfg.RtsThreshold;
1683 rts->disabled = (rts->value == MAX_RTS_THRESHOLD);
1689 int rt_ioctl_siwfrag(struct net_device *dev,
1690 struct iw_request_info *info,
1691 struct iw_param *frag, char *extra)
1693 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1696 //check if the interface is down
1697 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1699 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1704 val = MAX_FRAG_THRESHOLD;
1705 else if (frag->value >= MIN_FRAG_THRESHOLD || frag->value <= MAX_FRAG_THRESHOLD)
1706 val = __cpu_to_le16(frag->value & ~0x1); /* even numbers only */
1707 else if (frag->value == 0)
1708 val = MAX_FRAG_THRESHOLD;
1712 pAdapter->CommonCfg.FragmentThreshold = val;
1716 int rt_ioctl_giwfrag(struct net_device *dev,
1717 struct iw_request_info *info,
1718 struct iw_param *frag, char *extra)
1721 PRTMP_ADAPTER pAdapter = NULL;
1722 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1724 if (dev->priv_flags == INT_MAIN)
1726 pAdapter = dev->ml_priv;
1730 pVirtualAd = dev->ml_priv;
1731 if (pVirtualAd && pVirtualAd->RtmpDev)
1732 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1735 if (pAdapter == NULL)
1737 /* if 1st open fail, pAd will be free;
1738 So the net_dev->ml_priv will be NULL in 2rd open */
1743 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1746 //check if the interface is down
1747 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1749 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1753 frag->value = pAdapter->CommonCfg.FragmentThreshold;
1754 frag->disabled = (frag->value == MAX_FRAG_THRESHOLD);
1760 #define MAX_WEP_KEY_SIZE 13
1761 #define MIN_WEP_KEY_SIZE 5
1762 int rt_ioctl_siwencode(struct net_device *dev,
1763 struct iw_request_info *info,
1764 struct iw_point *erq, char *extra)
1766 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1768 //check if the interface is down
1769 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1771 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1775 if ((erq->length == 0) &&
1776 (erq->flags & IW_ENCODE_DISABLED))
1778 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
1779 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
1780 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
1781 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
1782 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1786 else if ((erq->length == 0) &&
1787 (erq->flags & IW_ENCODE_RESTRICTED || erq->flags & IW_ENCODE_OPEN))
1790 else if (erq->flags & IW_ENCODE_RESTRICTED || erq->flags & IW_ENCODE_OPEN)
1793 STA_PORT_SECURED(pAdapter);
1794 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
1795 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
1796 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
1797 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
1798 if (erq->flags & IW_ENCODE_RESTRICTED)
1799 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
1801 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1807 if (erq->length > 0)
1809 int keyIdx = (erq->flags & IW_ENCODE_INDEX) - 1;
1810 /* Check the size of the key */
1811 if (erq->length > MAX_WEP_KEY_SIZE) {
1814 /* Check key index */
1815 if ((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
1817 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::Wrong keyIdx=%d! Using default key instead (%d)\n",
1818 keyIdx, pAdapter->StaCfg.DefaultKeyId));
1821 keyIdx = pAdapter->StaCfg.DefaultKeyId;
1826 pAdapter->StaCfg.DefaultKeyId=keyIdx;
1830 NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
1832 if (erq->length == MAX_WEP_KEY_SIZE)
1834 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
1835 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
1837 else if (erq->length == MIN_WEP_KEY_SIZE)
1839 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
1840 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
1843 /* Disable the key */
1844 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
1846 /* Check if the key is not marked as invalid */
1847 if(!(erq->flags & IW_ENCODE_NOKEY)) {
1848 /* Copy the key in the driver */
1849 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, extra, erq->length);
1854 /* Do we want to just set the transmit key index ? */
1855 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
1856 if ((index >= 0) && (index < 4))
1858 pAdapter->StaCfg.DefaultKeyId = index;
1861 /* Don't complain if only change the mode */
1862 if (!(erq->flags & IW_ENCODE_MODE)) {
1868 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::erq->flags=%x\n",erq->flags));
1869 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::AuthMode=%x\n",pAdapter->StaCfg.AuthMode));
1870 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::DefaultKeyId=%x, KeyLen = %d\n",pAdapter->StaCfg.DefaultKeyId , pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen));
1871 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::WepStatus=%x\n",pAdapter->StaCfg.WepStatus));
1876 rt_ioctl_giwencode(struct net_device *dev,
1877 struct iw_request_info *info,
1878 struct iw_point *erq, char *key)
1881 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1885 PRTMP_ADAPTER pAdapter = NULL;
1886 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1888 if (dev->priv_flags == INT_MAIN)
1890 pAdapter = dev->ml_priv;
1894 pVirtualAd = dev->ml_priv;
1895 if (pVirtualAd && pVirtualAd->RtmpDev)
1896 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1899 if (pAdapter == NULL)
1901 /* if 1st open fail, pAd will be free;
1902 So the net_dev->ml_priv will be NULL in 2rd open */
1907 //check if the interface is down
1908 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1910 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1914 kid = erq->flags & IW_ENCODE_INDEX;
1915 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_giwencode %d\n", erq->flags & IW_ENCODE_INDEX));
1917 if (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled)
1920 erq->flags = IW_ENCODE_DISABLED;
1922 else if ((kid > 0) && (kid <=4))
1925 erq->flags = kid ; /* NB: base 1 */
1926 if (erq->length > pAdapter->SharedKey[BSS0][kid-1].KeyLen)
1927 erq->length = pAdapter->SharedKey[BSS0][kid-1].KeyLen;
1928 memcpy(key, pAdapter->SharedKey[BSS0][kid-1].Key, erq->length);
1929 //if ((kid == pAdapter->PortCfg.DefaultKeyId))
1930 //erq->flags |= IW_ENCODE_ENABLED; /* XXX */
1931 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1932 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1934 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1939 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1940 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1942 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1943 erq->length = pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen;
1944 memcpy(key, pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key, erq->length);
1945 // copy default key ID
1946 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1947 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1949 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1950 erq->flags = pAdapter->StaCfg.DefaultKeyId + 1; /* NB: base 1 */
1951 erq->flags |= IW_ENCODE_ENABLED; /* XXX */
1959 rt_ioctl_setparam(struct net_device *dev, struct iw_request_info *info,
1960 void *w, char *extra)
1962 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1963 PRTMP_ADAPTER pAdapter;
1965 char *this_char = extra;
1969 if (dev->priv_flags == INT_MAIN)
1971 pAdapter = dev->ml_priv;
1975 pVirtualAd = dev->ml_priv;
1976 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1978 pObj = (POS_COOKIE) pAdapter->OS_Cookie;
1980 if (pAdapter == NULL)
1982 /* if 1st open fail, pAd will be free;
1983 So the net_dev->ml_priv will be NULL in 2rd open */
1988 pObj->ioctl_if_type = INT_MAIN;
1989 pObj->ioctl_if = MAIN_MBSSID;
1992 //check if the interface is down
1993 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1995 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2002 if ((value = rtstrchr(this_char, '=')) != NULL)
2008 // reject setting nothing besides ANY ssid(ssidLen=0)
2009 if (!*value && (strcmp(this_char, "SSID") != 0))
2012 for (PRTMP_PRIVATE_SET_PROC = RTMP_PRIVATE_SUPPORT_PROC; PRTMP_PRIVATE_SET_PROC->name; PRTMP_PRIVATE_SET_PROC++)
2014 if (strcmp(this_char, PRTMP_PRIVATE_SET_PROC->name) == 0)
2016 if(!PRTMP_PRIVATE_SET_PROC->set_proc(pAdapter, value))
2017 { //FALSE:Set private failed then return Invalid argument
2020 break; //Exit for loop.
2024 if(PRTMP_PRIVATE_SET_PROC->name == NULL)
2025 { //Not found argument
2027 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_setparam:: (iwpriv) Not Support Set Command [%s=%s]\n", this_char, value));
2035 rt_private_get_statistics(struct net_device *dev, struct iw_request_info *info,
2036 struct iw_point *wrq, char *extra)
2039 PRTMP_ADAPTER pAd = dev->ml_priv;
2047 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2048 sprintf(extra, "\n\n");
2051 sprintf(extra+strlen(extra), "Tx success = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart);
2052 sprintf(extra+strlen(extra), "Tx success without retry = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart - (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
2054 sprintf(extra+strlen(extra), "Tx success after retry = %ld\n", (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
2055 sprintf(extra+strlen(extra), "Tx fail to Rcv ACK after retry = %ld\n", (ULONG)pAd->WlanCounters.FailedCount.QuadPart);
2056 sprintf(extra+strlen(extra), "RTS Success Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSSuccessCount.QuadPart);
2057 sprintf(extra+strlen(extra), "RTS Fail Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSFailureCount.QuadPart);
2059 sprintf(extra+strlen(extra), "Rx success = %ld\n", (ULONG)pAd->WlanCounters.ReceivedFragmentCount.QuadPart);
2060 sprintf(extra+strlen(extra), "Rx with CRC = %ld\n", (ULONG)pAd->WlanCounters.FCSErrorCount.QuadPart);
2061 sprintf(extra+strlen(extra), "Rx drop due to out of resource = %ld\n", (ULONG)pAd->Counters8023.RxNoBuffer);
2062 sprintf(extra+strlen(extra), "Rx duplicate frame = %ld\n", (ULONG)pAd->WlanCounters.FrameDuplicateCount.QuadPart);
2064 sprintf(extra+strlen(extra), "False CCA (one second) = %ld\n", (ULONG)pAd->RalinkCounters.OneSecFalseCCACnt);
2066 sprintf(extra+strlen(extra), "RSSI-A = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi0 - pAd->BbpRssiToDbmDelta));
2067 sprintf(extra+strlen(extra), "RSSI-B (if available) = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi1 - pAd->BbpRssiToDbmDelta));
2068 sprintf(extra+strlen(extra), "RSSI-C (if available) = %ld\n\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi2 - pAd->BbpRssiToDbmDelta));
2070 sprintf(extra+strlen(extra), "WpaSupplicantUP = %d\n\n", pAd->StaCfg.WpaSupplicantUP);
2072 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2073 DBGPRINT(RT_DEBUG_TRACE, ("<== rt_private_get_statistics, wrq->length = %d\n", wrq->length));
2079 IN PRTMP_ADAPTER pAd,
2083 BA_ORI_ENTRY *pOriBAEntry;
2084 BA_REC_ENTRY *pRecBAEntry;
2086 for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
2088 PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
2089 if (((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
2090 || (pEntry->ValidAsWDS) || (pEntry->ValidAsMesh))
2092 sprintf(pOutBuf + strlen(pOutBuf), "\n%02X:%02X:%02X:%02X:%02X:%02X (Aid = %d) (AP) -\n",
2093 pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
2094 pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5], pEntry->Aid);
2096 sprintf(pOutBuf, "%s[Recipient]\n", pOutBuf);
2097 for (j=0; j < NUM_OF_TID; j++)
2099 if (pEntry->BARecWcidArray[j] != 0)
2101 pRecBAEntry =&pAd->BATable.BARecEntry[pEntry->BARecWcidArray[j]];
2102 sprintf(pOutBuf + strlen(pOutBuf), "TID=%d, BAWinSize=%d, LastIndSeq=%d, ReorderingPkts=%d\n", j, pRecBAEntry->BAWinSize, pRecBAEntry->LastIndSeq, pRecBAEntry->list.qlen);
2105 sprintf(pOutBuf, "%s\n", pOutBuf);
2107 sprintf(pOutBuf, "%s[Originator]\n", pOutBuf);
2108 for (j=0; j < NUM_OF_TID; j++)
2110 if (pEntry->BAOriWcidArray[j] != 0)
2112 pOriBAEntry =&pAd->BATable.BAOriEntry[pEntry->BAOriWcidArray[j]];
2113 sprintf(pOutBuf + strlen(pOutBuf), "TID=%d, BAWinSize=%d, StartSeq=%d, CurTxSeq=%d\n", j, pOriBAEntry->BAWinSize, pOriBAEntry->Sequence, pEntry->TxSeq[j]);
2116 sprintf(pOutBuf, "%s\n\n", pOutBuf);
2118 if (strlen(pOutBuf) > (IW_PRIV_SIZE_MASK - 30))
2126 rt_private_show(struct net_device *dev, struct iw_request_info *info,
2127 struct iw_point *wrq, char *extra)
2130 VIRTUAL_ADAPTER *pVirtualAd = NULL;
2133 u32 subcmd = wrq->flags;
2135 if (dev->priv_flags == INT_MAIN)
2139 pVirtualAd = dev->ml_priv;
2140 pAd = pVirtualAd->RtmpDev->ml_priv;
2142 pObj = (POS_COOKIE) pAd->OS_Cookie;
2146 /* if 1st open fail, pAd will be free;
2147 So the net_dev->ml_priv will be NULL in 2rd open */
2156 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2159 pObj->ioctl_if_type = INT_MAIN;
2160 pObj->ioctl_if = MAIN_MBSSID;
2166 case SHOW_CONN_STATUS:
2167 if (MONITOR_ON(pAd))
2169 if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
2170 pAd->CommonCfg.RegTransmitSetting.field.BW)
2171 sprintf(extra, "Monitor Mode(CentralChannel %d)\n", pAd->CommonCfg.CentralChannel);
2173 sprintf(extra, "Monitor Mode(Channel %d)\n", pAd->CommonCfg.Channel);
2177 if (pAd->IndicateMediaState == NdisMediaStateConnected)
2181 sprintf(extra, "Connected(AP: %s[%02X:%02X:%02X:%02X:%02X:%02X])\n",
2182 pAd->CommonCfg.Ssid,
2183 pAd->CommonCfg.Bssid[0],
2184 pAd->CommonCfg.Bssid[1],
2185 pAd->CommonCfg.Bssid[2],
2186 pAd->CommonCfg.Bssid[3],
2187 pAd->CommonCfg.Bssid[4],
2188 pAd->CommonCfg.Bssid[5]);
2189 DBGPRINT(RT_DEBUG_TRACE ,("Ssid=%s ,Ssidlen = %d\n",pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen));
2191 else if (ADHOC_ON(pAd))
2192 sprintf(extra, "Connected\n");
2196 sprintf(extra, "Disconnected\n");
2197 DBGPRINT(RT_DEBUG_TRACE ,("ConnStatus is not connected\n"));
2200 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2202 case SHOW_DRVIER_VERION:
2203 sprintf(extra, "Driver version-%s, %s %s\n", STA_DRIVER_VERSION, __DATE__, __TIME__ );
2204 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2207 getBaInfo(pAd, extra);
2208 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2210 case SHOW_DESC_INFO:
2212 Show_DescInfo_Proc(pAd, NULL);
2213 wrq->length = 0; // 1: size of '\0'
2217 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
2219 sprintf(extra, "Scanning\n");
2220 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2223 pAd->StaCfg.bSwRadio = FALSE;
2224 if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
2226 pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
2227 if (pAd->StaCfg.bRadio == FALSE)
2230 // Update extra information
2231 pAd->ExtraInfo = SW_RADIO_OFF;
2234 sprintf(extra, "Radio Off\n");
2235 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2239 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
2241 sprintf(extra, "Scanning\n");
2242 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2246 pAd->StaCfg.bSwRadio = TRUE;
2247 //if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
2249 pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
2250 if (pAd->StaCfg.bRadio == TRUE)
2253 // Update extra information
2254 pAd->ExtraInfo = EXTRA_INFO_CLEAR;
2257 sprintf(extra, "Radio On\n");
2258 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2261 case SHOW_CFG_VALUE:
2263 Status = RTMPShowCfgValue(pAd, wrq->pointer, extra);
2265 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2268 #if !defined(RT2860) && !defined(RT30xx)
2269 case SHOW_ADHOC_ENTRY_INFO:
2270 Show_Adhoc_MacTable_Proc(pAd, extra);
2271 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2275 DBGPRINT(RT_DEBUG_TRACE, ("%s - unknow subcmd = %d\n", __func__, subcmd));
2283 int rt_ioctl_siwmlme(struct net_device *dev,
2284 struct iw_request_info *info,
2285 union iwreq_data *wrqu,
2288 PRTMP_ADAPTER pAd = dev->ml_priv;
2289 struct iw_mlme *pMlme = (struct iw_mlme *)wrqu->data.pointer;
2290 MLME_QUEUE_ELEM MsgElem;
2291 MLME_DISASSOC_REQ_STRUCT DisAssocReq;
2292 MLME_DEAUTH_REQ_STRUCT DeAuthReq;
2294 DBGPRINT(RT_DEBUG_TRACE, ("====> %s\n", __func__));
2301 #ifdef IW_MLME_DEAUTH
2302 case IW_MLME_DEAUTH:
2303 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DEAUTH\n", __func__));
2304 COPY_MAC_ADDR(DeAuthReq.Addr, pAd->CommonCfg.Bssid);
2305 DeAuthReq.Reason = pMlme->reason_code;
2306 MsgElem.MsgLen = sizeof(MLME_DEAUTH_REQ_STRUCT);
2307 NdisMoveMemory(MsgElem.Msg, &DeAuthReq, sizeof(MLME_DEAUTH_REQ_STRUCT));
2308 MlmeDeauthReqAction(pAd, &MsgElem);
2311 LinkDown(pAd, FALSE);
2312 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
2315 #endif // IW_MLME_DEAUTH //
2316 #ifdef IW_MLME_DISASSOC
2317 case IW_MLME_DISASSOC:
2318 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DISASSOC\n", __func__));
2319 COPY_MAC_ADDR(DisAssocReq.Addr, pAd->CommonCfg.Bssid);
2320 DisAssocReq.Reason = pMlme->reason_code;
2322 MsgElem.Machine = ASSOC_STATE_MACHINE;
2323 MsgElem.MsgType = MT2_MLME_DISASSOC_REQ;
2324 MsgElem.MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
2325 NdisMoveMemory(MsgElem.Msg, &DisAssocReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
2327 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
2328 MlmeDisassocReqAction(pAd, &MsgElem);
2330 #endif // IW_MLME_DISASSOC //
2332 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - Unknow Command\n", __func__));
2338 #endif // SIOCSIWMLME //
2340 #if WIRELESS_EXT > 17
2341 int rt_ioctl_siwauth(struct net_device *dev,
2342 struct iw_request_info *info,
2343 union iwreq_data *wrqu, char *extra)
2345 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2346 struct iw_param *param = &wrqu->param;
2348 //check if the interface is down
2349 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2351 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2354 switch (param->flags & IW_AUTH_INDEX) {
2355 case IW_AUTH_WPA_VERSION:
2356 if (param->value == IW_AUTH_WPA_VERSION_WPA)
2358 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
2359 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
2360 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
2362 else if (param->value == IW_AUTH_WPA_VERSION_WPA2)
2363 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
2365 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __func__, param->value));
2367 case IW_AUTH_CIPHER_PAIRWISE:
2368 if (param->value == IW_AUTH_CIPHER_NONE)
2370 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
2371 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2372 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
2374 else if (param->value == IW_AUTH_CIPHER_WEP40 ||
2375 param->value == IW_AUTH_CIPHER_WEP104)
2377 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
2378 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2379 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
2380 pAdapter->StaCfg.IEEE8021X = FALSE;
2382 else if (param->value == IW_AUTH_CIPHER_TKIP)
2384 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
2385 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2386 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
2388 else if (param->value == IW_AUTH_CIPHER_CCMP)
2390 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
2391 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2392 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
2394 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_PAIRWISE - param->value = %d!\n", __func__, param->value));
2396 case IW_AUTH_CIPHER_GROUP:
2397 if (param->value == IW_AUTH_CIPHER_NONE)
2399 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
2401 else if (param->value == IW_AUTH_CIPHER_WEP40 ||
2402 param->value == IW_AUTH_CIPHER_WEP104)
2404 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
2406 else if (param->value == IW_AUTH_CIPHER_TKIP)
2408 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
2410 else if (param->value == IW_AUTH_CIPHER_CCMP)
2412 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
2414 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_GROUP - param->value = %d!\n", __func__, param->value));
2416 case IW_AUTH_KEY_MGMT:
2417 if (param->value == IW_AUTH_KEY_MGMT_802_1X)
2419 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)
2421 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
2422 pAdapter->StaCfg.IEEE8021X = FALSE;
2424 else if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
2426 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
2427 pAdapter->StaCfg.IEEE8021X = FALSE;
2431 pAdapter->StaCfg.IEEE8021X = TRUE;
2433 else if (param->value == 0)
2435 STA_PORT_SECURED(pAdapter);
2437 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_KEY_MGMT - param->value = %d!\n", __func__, param->value));
2439 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
2441 case IW_AUTH_PRIVACY_INVOKED:
2442 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_PRIVACY_INVOKED - param->value = %d!\n", __func__, param->value));
2444 case IW_AUTH_DROP_UNENCRYPTED:
2445 if (param->value != 0)
2446 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
2449 STA_PORT_SECURED(pAdapter);
2451 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __func__, param->value));
2453 case IW_AUTH_80211_AUTH_ALG:
2454 if (param->value & IW_AUTH_ALG_SHARED_KEY)
2456 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
2458 else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
2460 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
2464 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_80211_AUTH_ALG - param->value = %d!\n", __func__, param->value));
2466 case IW_AUTH_WPA_ENABLED:
2467 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_ENABLED - Driver supports WPA!(param->value = %d)\n", __func__, param->value));
2476 int rt_ioctl_giwauth(struct net_device *dev,
2477 struct iw_request_info *info,
2478 union iwreq_data *wrqu, char *extra)
2480 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2481 struct iw_param *param = &wrqu->param;
2483 //check if the interface is down
2484 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2486 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2490 switch (param->flags & IW_AUTH_INDEX) {
2491 case IW_AUTH_DROP_UNENCRYPTED:
2492 param->value = (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled) ? 0 : 1;
2495 case IW_AUTH_80211_AUTH_ALG:
2496 param->value = (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared) ? IW_AUTH_ALG_SHARED_KEY : IW_AUTH_ALG_OPEN_SYSTEM;
2499 case IW_AUTH_WPA_ENABLED:
2500 param->value = (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) ? 1 : 0;
2506 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_giwauth::param->value = %d!\n", param->value));
2510 void fnSetCipherKey(
2511 IN PRTMP_ADAPTER pAdapter,
2515 IN struct iw_encode_ext *ext)
2518 RTMP_CLEAR_PSFLAG(pAdapter, fRTMP_PS_CAN_GO_SLEEP);
2519 if (RTMP_TEST_PSFLAG(pAdapter, fRTMP_PS_SET_PCI_CLK_OFF_COMMAND))
2521 if (pAdapter->StaCfg.bRadio == FALSE)
2523 RTMP_SET_PSFLAG(pAdapter, fRTMP_PS_CAN_GO_SLEEP);
2526 DBGPRINT(RT_DEBUG_TRACE,("RTMPWPAAddKeyProc1==>\n"));
2527 RTMPPCIeLinkCtrlValueRestore(pAdapter, RESTORE_HALT);
2528 RTMPusecDelay(6000);
2529 pAdapter->bPCIclkOff = FALSE;
2532 NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
2533 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = LEN_TKIP_EK;
2534 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, LEN_TKIP_EK);
2535 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].TxMic, ext->key + LEN_TKIP_EK, LEN_TKIP_TXMICK);
2536 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].RxMic, ext->key + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
2537 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CipherAlg;
2539 // Update group key information to ASIC Shared Key Table
2540 AsicAddSharedKeyEntry(pAdapter,
2543 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2544 pAdapter->SharedKey[BSS0][keyIdx].Key,
2545 pAdapter->SharedKey[BSS0][keyIdx].TxMic,
2546 pAdapter->SharedKey[BSS0][keyIdx].RxMic);
2549 // Update ASIC WCID attribute table and IVEIV table
2550 RTMPAddWcidAttributeEntry(pAdapter,
2553 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2556 // Update ASIC WCID attribute table and IVEIV table
2557 RTMPAddWcidAttributeEntry(pAdapter,
2560 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2561 &pAdapter->MacTab.Content[BSSID_WCID]);
2563 RTMP_SET_PSFLAG(pAdapter, fRTMP_PS_CAN_GO_SLEEP);
2567 int rt_ioctl_siwencodeext(struct net_device *dev,
2568 struct iw_request_info *info,
2569 union iwreq_data *wrqu,
2572 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2573 struct iw_point *encoding = &wrqu->encoding;
2574 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2575 int keyIdx, alg = ext->alg;
2577 //check if the interface is down
2578 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2580 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2584 if (encoding->flags & IW_ENCODE_DISABLED)
2586 keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
2587 // set BSSID wcid entry of the Pair-wise Key table as no-security mode
2588 AsicRemovePairwiseKeyEntry(pAdapter, BSS0, BSSID_WCID);
2589 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
2590 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_NONE;
2591 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)keyIdx);
2592 NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
2593 DBGPRINT(RT_DEBUG_TRACE, ("%s::Remove all keys!(encoding->flags = %x)\n", __func__, encoding->flags));
2597 // Get Key Index and convet to our own defined key index
2598 keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
2599 if((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
2602 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2604 pAdapter->StaCfg.DefaultKeyId = keyIdx;
2605 DBGPRINT(RT_DEBUG_TRACE, ("%s::DefaultKeyId = %d\n", __func__, pAdapter->StaCfg.DefaultKeyId));
2609 case IW_ENCODE_ALG_NONE:
2610 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_NONE\n", __func__));
2612 case IW_ENCODE_ALG_WEP:
2613 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_WEP - ext->key_len = %d, keyIdx = %d\n", __func__, ext->key_len, keyIdx));
2614 if (ext->key_len == MAX_WEP_KEY_SIZE)
2616 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
2617 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
2619 else if (ext->key_len == MIN_WEP_KEY_SIZE)
2621 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
2622 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
2627 NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
2628 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, ext->key_len);
2630 if (pAdapter->StaCfg.GroupCipher == Ndis802_11GroupWEP40Enabled ||
2631 pAdapter->StaCfg.GroupCipher == Ndis802_11GroupWEP104Enabled)
2633 // Set Group key material to Asic
2634 AsicAddSharedKeyEntry(pAdapter, BSS0, keyIdx, pAdapter->SharedKey[BSS0][keyIdx].CipherAlg, pAdapter->SharedKey[BSS0][keyIdx].Key, NULL, NULL);
2636 // Update WCID attribute table and IVEIV table for this group key table
2637 RTMPAddWcidAttributeEntry(pAdapter, BSS0, keyIdx, pAdapter->SharedKey[BSS0][keyIdx].CipherAlg, NULL);
2639 STA_PORT_SECURED(pAdapter);
2641 // Indicate Connected for GUI
2642 pAdapter->IndicateMediaState = NdisMediaStateConnected;
2646 case IW_ENCODE_ALG_TKIP:
2647 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_TKIP - keyIdx = %d, ext->key_len = %d\n", __func__, keyIdx, ext->key_len));
2648 if (ext->key_len == 32)
2650 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2652 fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, FALSE, ext);
2653 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
2655 STA_PORT_SECURED(pAdapter);
2658 else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
2660 fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, TRUE, ext);
2662 // set 802.1x port control
2663 STA_PORT_SECURED(pAdapter);
2669 case IW_ENCODE_ALG_CCMP:
2670 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2672 fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, FALSE, ext);
2673 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
2674 STA_PORT_SECURED(pAdapter);
2676 else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
2678 fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, TRUE, ext);
2680 // set 802.1x port control
2681 STA_PORT_SECURED(pAdapter);
2693 rt_ioctl_giwencodeext(struct net_device *dev,
2694 struct iw_request_info *info,
2695 union iwreq_data *wrqu, char *extra)
2697 PRTMP_ADAPTER pAd = dev->ml_priv;
2699 struct iw_point *encoding = &wrqu->encoding;
2700 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2701 int idx, max_key_len;
2703 DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_giwencodeext\n"));
2705 max_key_len = encoding->length - sizeof(*ext);
2706 if (max_key_len < 0)
2709 idx = encoding->flags & IW_ENCODE_INDEX;
2712 if (idx < 1 || idx > 4)
2716 if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
2717 (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled))
2719 if (idx != pAd->StaCfg.DefaultKeyId)
2727 idx = pAd->StaCfg.DefaultKeyId;
2729 encoding->flags = idx + 1;
2730 memset(ext, 0, sizeof(*ext));
2733 switch(pAd->StaCfg.WepStatus) {
2734 case Ndis802_11WEPDisabled:
2735 ext->alg = IW_ENCODE_ALG_NONE;
2736 encoding->flags |= IW_ENCODE_DISABLED;
2738 case Ndis802_11WEPEnabled:
2739 ext->alg = IW_ENCODE_ALG_WEP;
2740 if (pAd->SharedKey[BSS0][idx].KeyLen > max_key_len)
2744 ext->key_len = pAd->SharedKey[BSS0][idx].KeyLen;
2745 pKey = &(pAd->SharedKey[BSS0][idx].Key[0]);
2748 case Ndis802_11Encryption2Enabled:
2749 case Ndis802_11Encryption3Enabled:
2750 if (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
2751 ext->alg = IW_ENCODE_ALG_TKIP;
2753 ext->alg = IW_ENCODE_ALG_CCMP;
2755 if (max_key_len < 32)
2760 pKey = &pAd->StaCfg.PMK[0];
2767 if (ext->key_len && pKey)
2769 encoding->flags |= IW_ENCODE_ENABLED;
2770 memcpy(ext->key, pKey, ext->key_len);
2777 int rt_ioctl_siwgenie(struct net_device *dev,
2778 struct iw_request_info *info,
2779 union iwreq_data *wrqu, char *extra)
2781 PRTMP_ADAPTER pAd = dev->ml_priv;
2783 if (wrqu->data.length > MAX_LEN_OF_RSNIE ||
2784 (wrqu->data.length && extra == NULL))
2787 if (wrqu->data.length)
2789 pAd->StaCfg.RSNIE_Len = wrqu->data.length;
2790 NdisMoveMemory(&pAd->StaCfg.RSN_IE[0], extra, pAd->StaCfg.RSNIE_Len);
2794 pAd->StaCfg.RSNIE_Len = 0;
2795 NdisZeroMemory(&pAd->StaCfg.RSN_IE[0], MAX_LEN_OF_RSNIE);
2800 #endif // SIOCSIWGENIE //
2802 int rt_ioctl_giwgenie(struct net_device *dev,
2803 struct iw_request_info *info,
2804 union iwreq_data *wrqu, char *extra)
2806 PRTMP_ADAPTER pAd = dev->ml_priv;
2808 if ((pAd->StaCfg.RSNIE_Len == 0) ||
2809 (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA))
2811 wrqu->data.length = 0;
2816 if (pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
2818 if (wrqu->data.length < pAd->StaCfg.RSNIE_Len)
2821 wrqu->data.length = pAd->StaCfg.RSNIE_Len;
2822 memcpy(extra, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
2825 #endif // SIOCSIWGENIE //
2827 UCHAR RSNIe = IE_WPA;
2829 if (wrqu->data.length < (pAd->StaCfg.RSNIE_Len + 2)) // ID, Len
2831 wrqu->data.length = pAd->StaCfg.RSNIE_Len + 2;
2833 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
2834 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2))
2837 extra[0] = (char)RSNIe;
2838 extra[1] = pAd->StaCfg.RSNIE_Len;
2839 memcpy(extra+2, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
2845 int rt_ioctl_siwpmksa(struct net_device *dev,
2846 struct iw_request_info *info,
2847 union iwreq_data *wrqu,
2850 PRTMP_ADAPTER pAd = dev->ml_priv;
2851 struct iw_pmksa *pPmksa = (struct iw_pmksa *)wrqu->data.pointer;
2852 INT CachedIdx = 0, idx = 0;
2857 DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_siwpmksa\n"));
2860 case IW_PMKSA_FLUSH:
2861 NdisZeroMemory(pAd->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
2862 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_FLUSH\n"));
2864 case IW_PMKSA_REMOVE:
2865 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
2867 // compare the BSSID
2868 if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
2870 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN);
2871 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].PMKID, 16);
2872 for (idx = CachedIdx; idx < (pAd->StaCfg.SavedPMKNum - 1); idx++)
2874 NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].BSSID[0], &pAd->StaCfg.SavedPMK[idx+1].BSSID[0], MAC_ADDR_LEN);
2875 NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].PMKID[0], &pAd->StaCfg.SavedPMK[idx+1].PMKID[0], 16);
2877 pAd->StaCfg.SavedPMKNum--;
2882 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_REMOVE\n"));
2885 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
2887 // compare the BSSID
2888 if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
2892 // Found, replace it
2893 if (CachedIdx < PMKID_NO)
2895 DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
2896 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
2897 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
2898 pAd->StaCfg.SavedPMKNum++;
2900 // Not found, replace the last one
2903 // Randomly replace one
2904 CachedIdx = (pPmksa->bssid.sa_data[5] % PMKID_NO);
2905 DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
2906 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
2907 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
2910 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_ADD\n"));
2913 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - Unknow Command!!\n"));
2919 #endif // #if WIRELESS_EXT > 17
2923 rt_private_ioctl_bbp(struct net_device *dev, struct iw_request_info *info,
2924 struct iw_point *wrq, char *extra)
2931 BOOLEAN bIsPrintAllBBP = FALSE;
2933 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2936 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2938 if (wrq->length > 1) //No parameters.
2940 sprintf(extra, "\n");
2942 //Parsing Read or Write
2943 this_char = wrq->pointer;
2944 DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s\n", this_char));
2948 if ((value = rtstrchr(this_char, '=')) != NULL)
2951 if (!value || !*value)
2953 DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s, value=%s\n", this_char, value));
2954 if (sscanf(this_char, "%d", &(bbpId)) == 1)
2960 if (bbpId <= 138) // edit by johnli, RF power sequence setup, add BBP R138 for ADC dynamic on/off control
2964 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
2966 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
2967 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2968 DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
2971 {//Invalid parametes, so default printk all bbp
2972 bIsPrintAllBBP = TRUE;
2977 { //Invalid parametes, so default printk all bbp
2978 bIsPrintAllBBP = TRUE;
2984 if ((sscanf(this_char, "%d", &(bbpId)) == 1) && (sscanf(value, "%x", &(bbpValue)) == 1))
2990 if (bbpId <= 138) // edit by johnli, RF power sequence setup, add BBP R138 for ADC dynamic on/off control
2994 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, bbpId, bbpValue);
2995 //Read it back for showing
2996 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
2998 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
2999 wrq->length = strlen(extra) + 1; // 1: size of '\0'
3000 DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
3003 {//Invalid parametes, so default printk all bbp
3004 bIsPrintAllBBP = TRUE;
3009 { //Invalid parametes, so default printk all bbp
3010 bIsPrintAllBBP = TRUE;
3016 bIsPrintAllBBP = TRUE;
3021 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
3022 sprintf(extra, "\n");
3024 for (bbpId = 0; bbpId <= 136; bbpId++)
3027 for (bbpId = 0; bbpId <= 138; bbpId++) // edit by johnli, RF power sequence setup, add BBP R138 for ADC dynamic on/off control
3030 if (strlen(extra) >= (IW_PRIV_SIZE_MASK - 10))
3032 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
3034 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X ", bbpId, bbpId*2, regBBP);
3036 sprintf(extra+strlen(extra), "\n");
3039 sprintf(extra+strlen(extra), "%03d = %02X\n", bbpId, regBBP); // edit by johnli, change display format
3043 wrq->length = strlen(extra) + 1; // 1: size of '\0'
3044 DBGPRINT(RT_DEBUG_TRACE, ("wrq->length = %d\n", wrq->length));
3047 DBGPRINT(RT_DEBUG_TRACE, ("<==rt_private_ioctl_bbp\n\n"));
3053 int rt_ioctl_siwrate(struct net_device *dev,
3054 struct iw_request_info *info,
3055 union iwreq_data *wrqu, char *extra)
3057 PRTMP_ADAPTER pAd = dev->ml_priv;
3058 UINT32 rate = wrqu->bitrate.value, fixed = wrqu->bitrate.fixed;
3060 //check if the interface is down
3061 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
3063 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::Network is down!\n"));
3067 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(rate = %d, fixed = %d)\n", rate, fixed));
3068 /* rate = -1 => auto rate
3069 rate = X, fixed = 1 => (fixed rate X)
3074 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
3075 pAd->StaCfg.bAutoTxRateSwitch = TRUE;
3076 if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
3077 (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
3078 RTMPSetDesiredRates(pAd, -1);
3086 pAd->StaCfg.bAutoTxRateSwitch = FALSE;
3087 if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
3088 (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
3089 RTMPSetDesiredRates(pAd, rate);
3092 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
3095 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(HtMcs=%d)\n",pAd->StaCfg.DesiredTransmitSetting.field.MCS));
3099 // TODO: rate = X, fixed = 0 => (rates <= X)
3107 int rt_ioctl_giwrate(struct net_device *dev,
3108 struct iw_request_info *info,
3109 union iwreq_data *wrqu, char *extra)
3111 PRTMP_ADAPTER pAd = dev->ml_priv;
3112 int rate_index = 0, rate_count = 0;
3113 HTTRANSMIT_SETTING ht_setting;
3114 __s32 ralinkrate[] =
3115 {2, 4, 11, 22, // CCK
3116 12, 18, 24, 36, 48, 72, 96, 108, // OFDM
3117 13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260, // 20MHz, 800ns GI, MCS: 0 ~ 15
3118 39, 78, 117, 156, 234, 312, 351, 390, // 20MHz, 800ns GI, MCS: 16 ~ 23
3119 27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540, // 40MHz, 800ns GI, MCS: 0 ~ 15
3120 81, 162, 243, 324, 486, 648, 729, 810, // 40MHz, 800ns GI, MCS: 16 ~ 23
3121 14, 29, 43, 57, 87, 115, 130, 144, 29, 59, 87, 115, 173, 230, 260, 288, // 20MHz, 400ns GI, MCS: 0 ~ 15
3122 43, 87, 130, 173, 260, 317, 390, 433, // 20MHz, 400ns GI, MCS: 16 ~ 23
3123 30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600, // 40MHz, 400ns GI, MCS: 0 ~ 15
3124 90, 180, 270, 360, 540, 720, 810, 900}; // 40MHz, 400ns GI, MCS: 16 ~ 23
3126 rate_count = sizeof(ralinkrate)/sizeof(__s32);
3127 //check if the interface is down
3128 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
3130 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
3134 if ((pAd->StaCfg.bAutoTxRateSwitch == FALSE) &&
3136 ((pAd->CommonCfg.PhyMode <= PHY_11G) || (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM)))
3137 ht_setting.word = pAd->StaCfg.HTPhyMode.word;
3139 ht_setting.word = pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word;
3141 if (ht_setting.field.MODE >= MODE_HTMIX)
3143 rate_index = 12 + ((UCHAR)ht_setting.field.BW *24) + ((UCHAR)ht_setting.field.ShortGI *48) + ((UCHAR)ht_setting.field.MCS);
3146 if (ht_setting.field.MODE == MODE_OFDM)
3147 rate_index = (UCHAR)(ht_setting.field.MCS) + 4;
3148 else if (ht_setting.field.MODE == MODE_CCK)
3149 rate_index = (UCHAR)(ht_setting.field.MCS);
3154 if (rate_index > rate_count)
3155 rate_index = rate_count;
3157 wrqu->bitrate.value = ralinkrate[rate_index] * 500000;
3158 wrqu->bitrate.disabled = 0;
3163 static const iw_handler rt_handler[] =
3165 (iw_handler) NULL, /* SIOCSIWCOMMIT */
3166 (iw_handler) rt_ioctl_giwname, /* SIOCGIWNAME */
3167 (iw_handler) NULL, /* SIOCSIWNWID */
3168 (iw_handler) NULL, /* SIOCGIWNWID */
3169 (iw_handler) rt_ioctl_siwfreq, /* SIOCSIWFREQ */
3170 (iw_handler) rt_ioctl_giwfreq, /* SIOCGIWFREQ */
3171 (iw_handler) rt_ioctl_siwmode, /* SIOCSIWMODE */
3172 (iw_handler) rt_ioctl_giwmode, /* SIOCGIWMODE */
3173 (iw_handler) NULL, /* SIOCSIWSENS */
3174 (iw_handler) NULL, /* SIOCGIWSENS */
3175 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
3176 (iw_handler) rt_ioctl_giwrange, /* SIOCGIWRANGE */
3177 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
3178 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
3179 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
3180 (iw_handler) rt28xx_get_wireless_stats /* kernel code */, /* SIOCGIWSTATS */
3181 (iw_handler) NULL, /* SIOCSIWSPY */
3182 (iw_handler) NULL, /* SIOCGIWSPY */
3183 (iw_handler) NULL, /* SIOCSIWTHRSPY */
3184 (iw_handler) NULL, /* SIOCGIWTHRSPY */
3185 (iw_handler) rt_ioctl_siwap, /* SIOCSIWAP */
3186 (iw_handler) rt_ioctl_giwap, /* SIOCGIWAP */
3188 (iw_handler) rt_ioctl_siwmlme, /* SIOCSIWMLME */
3190 (iw_handler) NULL, /* SIOCSIWMLME */
3191 #endif // SIOCSIWMLME //
3192 (iw_handler) rt_ioctl_iwaplist, /* SIOCGIWAPLIST */
3194 (iw_handler) rt_ioctl_siwscan, /* SIOCSIWSCAN */
3195 (iw_handler) rt_ioctl_giwscan, /* SIOCGIWSCAN */
3197 (iw_handler) NULL, /* SIOCSIWSCAN */
3198 (iw_handler) NULL, /* SIOCGIWSCAN */
3199 #endif /* SIOCGIWSCAN */
3200 (iw_handler) rt_ioctl_siwessid, /* SIOCSIWESSID */
3201 (iw_handler) rt_ioctl_giwessid, /* SIOCGIWESSID */
3202 (iw_handler) rt_ioctl_siwnickn, /* SIOCSIWNICKN */
3203 (iw_handler) rt_ioctl_giwnickn, /* SIOCGIWNICKN */
3204 (iw_handler) NULL, /* -- hole -- */
3205 (iw_handler) NULL, /* -- hole -- */
3206 (iw_handler) rt_ioctl_siwrate, /* SIOCSIWRATE */
3207 (iw_handler) rt_ioctl_giwrate, /* SIOCGIWRATE */
3208 (iw_handler) rt_ioctl_siwrts, /* SIOCSIWRTS */
3209 (iw_handler) rt_ioctl_giwrts, /* SIOCGIWRTS */
3210 (iw_handler) rt_ioctl_siwfrag, /* SIOCSIWFRAG */
3211 (iw_handler) rt_ioctl_giwfrag, /* SIOCGIWFRAG */
3212 (iw_handler) NULL, /* SIOCSIWTXPOW */
3213 (iw_handler) NULL, /* SIOCGIWTXPOW */
3214 (iw_handler) NULL, /* SIOCSIWRETRY */
3215 (iw_handler) NULL, /* SIOCGIWRETRY */
3216 (iw_handler) rt_ioctl_siwencode, /* SIOCSIWENCODE */
3217 (iw_handler) rt_ioctl_giwencode, /* SIOCGIWENCODE */
3218 (iw_handler) NULL, /* SIOCSIWPOWER */
3219 (iw_handler) NULL, /* SIOCGIWPOWER */
3220 (iw_handler) NULL, /* -- hole -- */
3221 (iw_handler) NULL, /* -- hole -- */
3222 #if WIRELESS_EXT > 17
3223 (iw_handler) rt_ioctl_siwgenie, /* SIOCSIWGENIE */
3224 (iw_handler) rt_ioctl_giwgenie, /* SIOCGIWGENIE */
3225 (iw_handler) rt_ioctl_siwauth, /* SIOCSIWAUTH */
3226 (iw_handler) rt_ioctl_giwauth, /* SIOCGIWAUTH */
3227 (iw_handler) rt_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
3228 (iw_handler) rt_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */
3229 (iw_handler) rt_ioctl_siwpmksa, /* SIOCSIWPMKSA */
3233 static const iw_handler rt_priv_handlers[] = {
3234 (iw_handler) NULL, /* + 0x00 */
3235 (iw_handler) NULL, /* + 0x01 */
3236 (iw_handler) rt_ioctl_setparam, /* + 0x02 */
3238 (iw_handler) rt_private_ioctl_bbp, /* + 0x03 */
3240 (iw_handler) NULL, /* + 0x03 */
3242 (iw_handler) NULL, /* + 0x04 */
3243 (iw_handler) NULL, /* + 0x05 */
3244 (iw_handler) NULL, /* + 0x06 */
3245 (iw_handler) NULL, /* + 0x07 */
3246 (iw_handler) NULL, /* + 0x08 */
3247 (iw_handler) rt_private_get_statistics, /* + 0x09 */
3248 (iw_handler) NULL, /* + 0x0A */
3249 (iw_handler) NULL, /* + 0x0B */
3250 (iw_handler) NULL, /* + 0x0C */
3251 (iw_handler) NULL, /* + 0x0D */
3252 (iw_handler) NULL, /* + 0x0E */
3253 (iw_handler) NULL, /* + 0x0F */
3254 (iw_handler) NULL, /* + 0x10 */
3255 (iw_handler) rt_private_show, /* + 0x11 */
3256 (iw_handler) NULL, /* + 0x12 */
3257 (iw_handler) NULL, /* + 0x13 */
3258 (iw_handler) NULL, /* + 0x15 */
3259 (iw_handler) NULL, /* + 0x17 */
3260 (iw_handler) NULL, /* + 0x18 */
3263 const struct iw_handler_def rt28xx_iw_handler_def =
3265 #define N(a) (sizeof (a) / sizeof (a[0]))
3266 .standard = (iw_handler *) rt_handler,
3267 .num_standard = sizeof(rt_handler) / sizeof(iw_handler),
3268 .private = (iw_handler *) rt_priv_handlers,
3269 .num_private = N(rt_priv_handlers),
3270 .private_args = (struct iw_priv_args *) privtab,
3271 .num_private_args = N(privtab),
3272 #if IW_HANDLER_VERSION >= 7
3273 .get_wireless_stats = rt28xx_get_wireless_stats,
3277 INT RTMPSetInformation(
3278 IN PRTMP_ADAPTER pAdapter,
3279 IN OUT struct ifreq *rq,
3282 struct iwreq *wrq = (struct iwreq *) rq;
3283 NDIS_802_11_SSID Ssid;
3284 NDIS_802_11_MAC_ADDRESS Bssid;
3285 RT_802_11_PHY_MODE PhyMode;
3286 RT_802_11_STA_CONFIG StaConfig;
3287 NDIS_802_11_RATES aryRates;
3288 RT_802_11_PREAMBLE Preamble;
3289 NDIS_802_11_WEP_STATUS WepStatus;
3290 NDIS_802_11_AUTHENTICATION_MODE AuthMode = Ndis802_11AuthModeMax;
3291 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
3292 NDIS_802_11_RTS_THRESHOLD RtsThresh;
3293 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
3294 NDIS_802_11_POWER_MODE PowerMode;
3295 PNDIS_802_11_KEY pKey = NULL;
3296 PNDIS_802_11_WEP pWepKey =NULL;
3297 PNDIS_802_11_REMOVE_KEY pRemoveKey = NULL;
3298 NDIS_802_11_CONFIGURATION Config, *pConfig = NULL;
3299 NDIS_802_11_NETWORK_TYPE NetType;
3302 INT Status = NDIS_STATUS_SUCCESS, MaxPhyMode = PHY_11G;
3305 BOOLEAN StateMachineTouched = FALSE;
3306 OID_SET_HT_PHYMODE HT_PhyMode; //11n ,kathy
3307 PNDIS_802_11_PMKID pPmkId = NULL;
3308 BOOLEAN IEEE8021xState = FALSE;
3309 BOOLEAN IEEE8021x_required_keys = FALSE;
3310 UCHAR wpa_supplicant_enable = 0;
3312 MaxPhyMode = PHY_11N_5G;
3314 DBGPRINT(RT_DEBUG_TRACE, ("-->RTMPSetInformation(), 0x%08x\n", cmd&0x7FFF));
3315 switch(cmd & 0x7FFF) {
3316 case RT_OID_802_11_COUNTRY_REGION:
3317 if (wrq->u.data.length < sizeof(UCHAR))
3319 // Only avaliable when EEPROM not programming
3320 else if (!(pAdapter->CommonCfg.CountryRegion & 0x80) && !(pAdapter->CommonCfg.CountryRegionForABand & 0x80))
3325 Status = copy_from_user(&Country, wrq->u.data.pointer, wrq->u.data.length);
3326 pAdapter->CommonCfg.CountryRegion = (UCHAR)(Country & 0x000000FF);
3327 pAdapter->CommonCfg.CountryRegionForABand = (UCHAR)((Country >> 8) & 0x000000FF);
3328 TmpPhy = pAdapter->CommonCfg.PhyMode;
3329 pAdapter->CommonCfg.PhyMode = 0xff;
3330 // Build all corresponding channel information
3331 RTMPSetPhyMode(pAdapter, TmpPhy);
3332 SetCommonHT(pAdapter);
3333 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_COUNTRY_REGION (A:%d B/G:%d)\n", pAdapter->CommonCfg.CountryRegionForABand,
3334 pAdapter->CommonCfg.CountryRegion));
3337 case OID_802_11_BSSID_LIST_SCAN:
3339 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID_LIST_SCAN, TxCnt = %d \n", pAdapter->RalinkCounters.LastOneSecTotalTxCount));
3341 if (MONITOR_ON(pAdapter))
3343 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
3347 //Benson add 20080527, when radio off, sta don't need to scan
3348 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_RADIO_OFF))
3351 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
3353 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is scanning now !!!\n"));
3354 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
3355 Status = NDIS_STATUS_SUCCESS;
3359 if (pAdapter->RalinkCounters.LastOneSecTotalTxCount > 100)
3361 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
3362 Status = NDIS_STATUS_SUCCESS;
3363 pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
3367 if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
3368 ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
3369 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
3370 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
3371 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)) &&
3372 (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
3374 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
3375 Status = NDIS_STATUS_SUCCESS;
3376 pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
3381 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3383 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3384 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3387 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
3388 // this request, because this request is initiated by NDIS.
3389 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
3390 // Reset allowed scan retries
3391 pAdapter->StaCfg.ScanCnt = 0;
3392 pAdapter->StaCfg.LastScanTime = Now;
3394 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
3395 RTMP_SET_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
3396 MlmeEnqueue(pAdapter,
3397 MLME_CNTL_STATE_MACHINE,
3398 OID_802_11_BSSID_LIST_SCAN,
3402 Status = NDIS_STATUS_SUCCESS;
3403 StateMachineTouched = TRUE;
3405 case OID_802_11_SSID:
3406 if (wrq->u.data.length != sizeof(NDIS_802_11_SSID))
3410 PCHAR pSsidString = NULL;
3411 Status = copy_from_user(&Ssid, wrq->u.data.pointer, wrq->u.data.length);
3413 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SSID (Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
3414 if (Ssid.SsidLength > MAX_LEN_OF_SSID)
3418 if (Ssid.SsidLength == 0)
3420 Set_SSID_Proc(pAdapter, "");
3424 pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
3427 NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
3428 NdisMoveMemory(pSsidString, Ssid.Ssid, Ssid.SsidLength);
3429 Set_SSID_Proc(pAdapter, pSsidString);
3438 case OID_802_11_BSSID:
3439 if (wrq->u.data.length != sizeof(NDIS_802_11_MAC_ADDRESS))
3443 Status = copy_from_user(&Bssid, wrq->u.data.pointer, wrq->u.data.length);
3445 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
3446 // this request, because this request is initiated by NDIS.
3447 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
3449 // Prevent to connect AP again in STAMlmePeriodicExec
3450 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
3452 // Reset allowed scan retries
3453 pAdapter->StaCfg.ScanCnt = 0;
3455 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3457 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3458 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3460 MlmeEnqueue(pAdapter,
3461 MLME_CNTL_STATE_MACHINE,
3463 sizeof(NDIS_802_11_MAC_ADDRESS),
3465 Status = NDIS_STATUS_SUCCESS;
3466 StateMachineTouched = TRUE;
3468 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID %02x:%02x:%02x:%02x:%02x:%02x\n",
3469 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
3472 case RT_OID_802_11_RADIO:
3473 if (wrq->u.data.length != sizeof(BOOLEAN))
3477 Status = copy_from_user(&RadioState, wrq->u.data.pointer, wrq->u.data.length);
3478 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RADIO (=%d)\n", RadioState));
3479 if (pAdapter->StaCfg.bSwRadio != RadioState)
3481 pAdapter->StaCfg.bSwRadio = RadioState;
3482 if (pAdapter->StaCfg.bRadio != (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio))
3484 pAdapter->StaCfg.bRadio = (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio);
3485 if (pAdapter->StaCfg.bRadio == TRUE)
3487 MlmeRadioOn(pAdapter);
3488 // Update extra information
3489 pAdapter->ExtraInfo = EXTRA_INFO_CLEAR;
3493 MlmeRadioOff(pAdapter);
3494 // Update extra information
3495 pAdapter->ExtraInfo = SW_RADIO_OFF;
3501 case RT_OID_802_11_PHY_MODE:
3502 if (wrq->u.data.length != sizeof(RT_802_11_PHY_MODE))
3506 Status = copy_from_user(&PhyMode, wrq->u.data.pointer, wrq->u.data.length);
3507 if (PhyMode <= MaxPhyMode)
3509 RTMPSetPhyMode(pAdapter, PhyMode);
3510 SetCommonHT(pAdapter);
3512 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PHY_MODE (=%d)\n", PhyMode));
3515 case RT_OID_802_11_STA_CONFIG:
3516 if (wrq->u.data.length != sizeof(RT_802_11_STA_CONFIG))
3520 Status = copy_from_user(&StaConfig, wrq->u.data.pointer, wrq->u.data.length);
3521 pAdapter->CommonCfg.bEnableTxBurst = StaConfig.EnableTxBurst;
3522 pAdapter->CommonCfg.UseBGProtection = StaConfig.UseBGProtection;
3523 pAdapter->CommonCfg.bUseShortSlotTime = 1; // 2003-10-30 always SHORT SLOT capable
3524 if ((pAdapter->CommonCfg.PhyMode != StaConfig.AdhocMode) &&
3525 (StaConfig.AdhocMode <= MaxPhyMode))
3527 // allow dynamic change of "USE OFDM rate or not" in ADHOC mode
3528 // if setting changed, need to reset current TX rate as well as BEACON frame format
3530 pAdapter->CommonCfg.PhyMode = StaConfig.AdhocMode;
3532 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
3535 pAdapter->CommonCfg.PhyMode = StaConfig.AdhocMode;
3537 RTMPSetPhyMode(pAdapter, PhyMode);
3538 MlmeUpdateTxRates(pAdapter, FALSE, 0);
3539 MakeIbssBeacon(pAdapter); // re-build BEACON frame
3540 AsicEnableIbssSync(pAdapter); // copy to on-chip memory
3543 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_STA_CONFIG (Burst=%d, Protection=%ld,ShortSlot=%d\n",
3544 pAdapter->CommonCfg.bEnableTxBurst,
3545 pAdapter->CommonCfg.UseBGProtection,
3546 pAdapter->CommonCfg.bUseShortSlotTime));
3549 case OID_802_11_DESIRED_RATES:
3550 if (wrq->u.data.length != sizeof(NDIS_802_11_RATES))
3554 Status = copy_from_user(&aryRates, wrq->u.data.pointer, wrq->u.data.length);
3555 NdisZeroMemory(pAdapter->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES);
3556 NdisMoveMemory(pAdapter->CommonCfg.DesireRate, &aryRates, sizeof(NDIS_802_11_RATES));
3557 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DESIRED_RATES (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
3558 pAdapter->CommonCfg.DesireRate[0],pAdapter->CommonCfg.DesireRate[1],
3559 pAdapter->CommonCfg.DesireRate[2],pAdapter->CommonCfg.DesireRate[3],
3560 pAdapter->CommonCfg.DesireRate[4],pAdapter->CommonCfg.DesireRate[5],
3561 pAdapter->CommonCfg.DesireRate[6],pAdapter->CommonCfg.DesireRate[7] ));
3562 // Changing DesiredRate may affect the MAX TX rate we used to TX frames out
3563 MlmeUpdateTxRates(pAdapter, FALSE, 0);
3566 case RT_OID_802_11_PREAMBLE:
3567 if (wrq->u.data.length != sizeof(RT_802_11_PREAMBLE))
3571 Status = copy_from_user(&Preamble, wrq->u.data.pointer, wrq->u.data.length);
3572 if (Preamble == Rt802_11PreambleShort)
3574 pAdapter->CommonCfg.TxPreamble = Preamble;
3575 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleShort);
3577 else if ((Preamble == Rt802_11PreambleLong) || (Preamble == Rt802_11PreambleAuto))
3579 // if user wants AUTO, initialize to LONG here, then change according to AP's
3580 // capability upon association.
3581 pAdapter->CommonCfg.TxPreamble = Preamble;
3582 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleLong);
3589 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PREAMBLE (=%d)\n", Preamble));
3592 case OID_802_11_WEP_STATUS:
3593 if (wrq->u.data.length != sizeof(NDIS_802_11_WEP_STATUS))
3597 Status = copy_from_user(&WepStatus, wrq->u.data.pointer, wrq->u.data.length);
3598 // Since TKIP, AES, WEP are all supported. It should not have any invalid setting
3599 if (WepStatus <= Ndis802_11Encryption3KeyAbsent)
3601 if (pAdapter->StaCfg.WepStatus != WepStatus)
3603 // Config has changed
3604 pAdapter->bConfigChanged = TRUE;
3606 pAdapter->StaCfg.WepStatus = WepStatus;
3607 pAdapter->StaCfg.OrigWepStatus = WepStatus;
3608 pAdapter->StaCfg.PairCipher = WepStatus;
3609 pAdapter->StaCfg.GroupCipher = WepStatus;
3616 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEP_STATUS (=%d)\n",WepStatus));
3619 case OID_802_11_AUTHENTICATION_MODE:
3620 if (wrq->u.data.length != sizeof(NDIS_802_11_AUTHENTICATION_MODE))
3624 Status = copy_from_user(&AuthMode, wrq->u.data.pointer, wrq->u.data.length);
3625 if (AuthMode > Ndis802_11AuthModeMax)
3632 if (pAdapter->StaCfg.AuthMode != AuthMode)
3634 // Config has changed
3635 pAdapter->bConfigChanged = TRUE;
3637 pAdapter->StaCfg.AuthMode = AuthMode;
3639 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
3640 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_AUTHENTICATION_MODE (=%d) \n",pAdapter->StaCfg.AuthMode));
3643 case OID_802_11_INFRASTRUCTURE_MODE:
3644 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_INFRASTRUCTURE))
3648 Status = copy_from_user(&BssType, wrq->u.data.pointer, wrq->u.data.length);
3650 if (BssType == Ndis802_11IBSS)
3651 Set_NetworkType_Proc(pAdapter, "Adhoc");
3652 else if (BssType == Ndis802_11Infrastructure)
3653 Set_NetworkType_Proc(pAdapter, "Infra");
3654 else if (BssType == Ndis802_11Monitor)
3655 Set_NetworkType_Proc(pAdapter, "Monitor");
3659 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_INFRASTRUCTURE_MODE (unknown)\n"));
3663 case OID_802_11_REMOVE_WEP:
3664 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_WEP\n"));
3665 if (wrq->u.data.length != sizeof(NDIS_802_11_KEY_INDEX))
3671 KeyIdx = *(NDIS_802_11_KEY_INDEX *) wrq->u.data.pointer;
3673 if (KeyIdx & 0x80000000)
3675 // Should never set default bit when remove key
3680 KeyIdx = KeyIdx & 0x0fffffff;
3686 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
3687 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
3688 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
3693 case RT_OID_802_11_RESET_COUNTERS:
3694 NdisZeroMemory(&pAdapter->WlanCounters, sizeof(COUNTER_802_11));
3695 NdisZeroMemory(&pAdapter->Counters8023, sizeof(COUNTER_802_3));
3696 NdisZeroMemory(&pAdapter->RalinkCounters, sizeof(COUNTER_RALINK));
3697 pAdapter->Counters8023.RxNoBuffer = 0;
3698 pAdapter->Counters8023.GoodReceives = 0;
3699 pAdapter->Counters8023.RxNoBuffer = 0;
3701 pAdapter->BulkOutComplete = 0;
3702 pAdapter->BulkOutCompleteOther= 0;
3703 pAdapter->BulkOutCompleteCancel = 0;
3704 pAdapter->BulkOutReq = 0;
3705 pAdapter->BulkInReq= 0;
3706 pAdapter->BulkInComplete = 0;
3707 pAdapter->BulkInCompleteFail = 0;
3709 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RESET_COUNTERS \n"));
3711 case OID_802_11_RTS_THRESHOLD:
3712 if (wrq->u.data.length != sizeof(NDIS_802_11_RTS_THRESHOLD))
3716 Status = copy_from_user(&RtsThresh, wrq->u.data.pointer, wrq->u.data.length);
3717 if (RtsThresh > MAX_RTS_THRESHOLD)
3720 pAdapter->CommonCfg.RtsThreshold = (USHORT)RtsThresh;
3722 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_RTS_THRESHOLD (=%ld)\n",RtsThresh));
3724 case OID_802_11_FRAGMENTATION_THRESHOLD:
3725 if (wrq->u.data.length != sizeof(NDIS_802_11_FRAGMENTATION_THRESHOLD))
3729 Status = copy_from_user(&FragThresh, wrq->u.data.pointer, wrq->u.data.length);
3730 pAdapter->CommonCfg.bUseZeroToDisableFragment = FALSE;
3731 if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
3733 if (FragThresh == 0)
3735 pAdapter->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
3736 pAdapter->CommonCfg.bUseZeroToDisableFragment = TRUE;
3742 pAdapter->CommonCfg.FragmentThreshold = (USHORT)FragThresh;
3744 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_FRAGMENTATION_THRESHOLD (=%ld) \n",FragThresh));
3746 case OID_802_11_POWER_MODE:
3747 if (wrq->u.data.length != sizeof(NDIS_802_11_POWER_MODE))
3751 Status = copy_from_user(&PowerMode, wrq->u.data.pointer, wrq->u.data.length);
3752 if (PowerMode == Ndis802_11PowerModeCAM)
3753 Set_PSMode_Proc(pAdapter, "CAM");
3754 else if (PowerMode == Ndis802_11PowerModeMAX_PSP)
3755 Set_PSMode_Proc(pAdapter, "Max_PSP");
3756 else if (PowerMode == Ndis802_11PowerModeFast_PSP)
3757 Set_PSMode_Proc(pAdapter, "Fast_PSP");
3758 else if (PowerMode == Ndis802_11PowerModeLegacy_PSP)
3759 Set_PSMode_Proc(pAdapter, "Legacy_PSP");
3763 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_POWER_MODE (=%d)\n",PowerMode));
3765 case RT_OID_802_11_TX_POWER_LEVEL_1:
3766 if (wrq->u.data.length < sizeof(ULONG))
3770 Status = copy_from_user(&PowerTemp, wrq->u.data.pointer, wrq->u.data.length);
3771 if (PowerTemp > 100)
3772 PowerTemp = 0xffffffff; // AUTO
3773 pAdapter->CommonCfg.TxPowerDefault = PowerTemp; //keep current setting.
3774 pAdapter->CommonCfg.TxPowerPercentage = pAdapter->CommonCfg.TxPowerDefault;
3775 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
3778 case OID_802_11_NETWORK_TYPE_IN_USE:
3779 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_TYPE))
3783 Status = copy_from_user(&NetType, wrq->u.data.pointer, wrq->u.data.length);
3785 if (NetType == Ndis802_11DS)
3786 RTMPSetPhyMode(pAdapter, PHY_11B);
3787 else if (NetType == Ndis802_11OFDM24)
3788 RTMPSetPhyMode(pAdapter, PHY_11BG_MIXED);
3789 else if (NetType == Ndis802_11OFDM5)
3790 RTMPSetPhyMode(pAdapter, PHY_11A);
3794 if (Status == NDIS_STATUS_SUCCESS)
3795 SetCommonHT(pAdapter);
3797 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_NETWORK_TYPE_IN_USE (=%d)\n",NetType));
3800 // For WPA PSK PMK key
3801 case RT_OID_802_11_ADD_WPA:
3802 pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3809 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
3810 if (pKey->Length != wrq->u.data.length)
3813 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!!\n"));
3817 if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
3818 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
3819 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone) )
3821 Status = -EOPNOTSUPP;
3822 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!! [AuthMode != WPAPSK/WPA2PSK/WPANONE]\n"));
3824 else if ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
3825 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
3826 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) ) // Only for WPA PSK mode
3828 NdisMoveMemory(pAdapter->StaCfg.PMK, &pKey->KeyMaterial, pKey->KeyLength);
3829 // Use RaConfig as PSK agent.
3830 // Start STA supplicant state machine
3831 if (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
3832 pAdapter->StaCfg.WpaState = SS_START;
3834 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3838 pAdapter->StaCfg.WpaState = SS_NOTUSE;
3839 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3844 case OID_802_11_REMOVE_KEY:
3845 pRemoveKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3846 if(pRemoveKey == NULL)
3852 Status = copy_from_user(pRemoveKey, wrq->u.data.pointer, wrq->u.data.length);
3853 if (pRemoveKey->Length != wrq->u.data.length)
3856 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!\n"));
3860 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3862 RTMPWPARemoveKeyProc(pAdapter, pRemoveKey);
3863 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Remove WPA Key!!\n"));
3867 KeyIdx = pRemoveKey->KeyIndex;
3869 if (KeyIdx & 0x80000000)
3871 // Should never set default bit when remove key
3873 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(Should never set default bit when remove key)\n"));
3877 KeyIdx = KeyIdx & 0x0fffffff;
3881 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(KeyId[%d] out of range)\n", KeyIdx));
3885 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
3886 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
3887 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
3888 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY (id=0x%x, Len=%d-byte)\n", pRemoveKey->KeyIndex, pRemoveKey->Length));
3896 case OID_802_11_ADD_KEY:
3897 pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3903 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
3904 if (pKey->Length != wrq->u.data.length)
3907 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY, Failed!!\n"));
3911 RTMPAddKey(pAdapter, pKey);
3912 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3916 case OID_802_11_CONFIGURATION:
3917 if (wrq->u.data.length != sizeof(NDIS_802_11_CONFIGURATION))
3921 Status = copy_from_user(&Config, wrq->u.data.pointer, wrq->u.data.length);
3924 if ((pConfig->BeaconPeriod >= 20) && (pConfig->BeaconPeriod <=400))
3925 pAdapter->CommonCfg.BeaconPeriod = (USHORT) pConfig->BeaconPeriod;
3927 pAdapter->StaActive.AtimWin = (USHORT) pConfig->ATIMWindow;
3928 MAP_KHZ_TO_CHANNEL_ID(pConfig->DSConfig, pAdapter->CommonCfg.Channel);
3930 // Save the channel on MlmeAux for CntlOidRTBssidProc used.
3932 pAdapter->MlmeAux.Channel = pAdapter->CommonCfg.Channel;
3934 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_CONFIGURATION (BeacnPeriod=%ld,AtimW=%ld,Ch=%d)\n",
3935 pConfig->BeaconPeriod, pConfig->ATIMWindow, pAdapter->CommonCfg.Channel));
3936 // Config has changed
3937 pAdapter->bConfigChanged = TRUE;
3940 case RT_OID_802_11_SET_HT_PHYMODE:
3941 if (wrq->u.data.length != sizeof(OID_SET_HT_PHYMODE))
3945 POID_SET_HT_PHYMODE pHTPhyMode = &HT_PhyMode;
3947 Status = copy_from_user(&HT_PhyMode, wrq->u.data.pointer, wrq->u.data.length);
3948 DBGPRINT(RT_DEBUG_TRACE, ("Set::pHTPhyMode (PhyMode = %d,TransmitNo = %d, HtMode = %d, ExtOffset = %d , MCS = %d, BW = %d, STBC = %d, SHORTGI = %d) \n",
3949 pHTPhyMode->PhyMode, pHTPhyMode->TransmitNo,pHTPhyMode->HtMode,pHTPhyMode->ExtOffset,
3950 pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->SHORTGI));
3951 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
3952 RTMPSetHT(pAdapter, pHTPhyMode);
3954 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_HT_PHYMODE(MCS=%d,BW=%d,SGI=%d,STBC=%d)\n",
3955 pAdapter->StaCfg.HTPhyMode.field.MCS, pAdapter->StaCfg.HTPhyMode.field.BW, pAdapter->StaCfg.HTPhyMode.field.ShortGI,
3956 pAdapter->StaCfg.HTPhyMode.field.STBC));
3958 case RT_OID_802_11_SET_APSD_SETTING:
3959 if (wrq->u.data.length != sizeof(ULONG))
3964 Status = copy_from_user(&apsd, wrq->u.data.pointer, wrq->u.data.length);
3966 /*-------------------------------------------------------------------
3967 |B31~B7 | B6~B5 | B4 | B3 | B2 | B1 | B0 |
3968 ---------------------------------------------------------------------
3969 | Rsvd | Max SP Len | AC_VO | AC_VI | AC_BK | AC_BE | APSD Capable |
3970 ---------------------------------------------------------------------*/
3971 pAdapter->CommonCfg.bAPSDCapable = (apsd & 0x00000001) ? TRUE : FALSE;
3972 pAdapter->CommonCfg.bAPSDAC_BE = ((apsd & 0x00000002) >> 1) ? TRUE : FALSE;
3973 pAdapter->CommonCfg.bAPSDAC_BK = ((apsd & 0x00000004) >> 2) ? TRUE : FALSE;
3974 pAdapter->CommonCfg.bAPSDAC_VI = ((apsd & 0x00000008) >> 3) ? TRUE : FALSE;
3975 pAdapter->CommonCfg.bAPSDAC_VO = ((apsd & 0x00000010) >> 4) ? TRUE : FALSE;
3976 pAdapter->CommonCfg.MaxSPLength = (UCHAR)((apsd & 0x00000060) >> 5);
3978 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_APSD_SETTING (apsd=0x%lx, APSDCap=%d, [BE,BK,VI,VO]=[%d/%d/%d/%d], MaxSPLen=%d)\n", apsd, pAdapter->CommonCfg.bAPSDCapable,
3979 pAdapter->CommonCfg.bAPSDAC_BE, pAdapter->CommonCfg.bAPSDAC_BK, pAdapter->CommonCfg.bAPSDAC_VI, pAdapter->CommonCfg.bAPSDAC_VO, pAdapter->CommonCfg.MaxSPLength));
3983 case RT_OID_802_11_SET_APSD_PSM:
3984 if (wrq->u.data.length != sizeof(ULONG))
3988 // Driver needs to notify AP when PSM changes
3989 Status = copy_from_user(&pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.pointer, wrq->u.data.length);
3990 if (pAdapter->CommonCfg.bAPSDForcePowerSave != pAdapter->StaCfg.Psm)
3992 MlmeSetPsmBit(pAdapter, pAdapter->CommonCfg.bAPSDForcePowerSave);
3993 RTMPSendNullFrame(pAdapter, pAdapter->CommonCfg.TxRate, TRUE);
3995 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_APSD_PSM (bAPSDForcePowerSave:%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
3999 case RT_OID_802_11_SET_WMM:
4000 if (wrq->u.data.length != sizeof(BOOLEAN))
4004 Status = copy_from_user(&pAdapter->CommonCfg.bWmmCapable, wrq->u.data.pointer, wrq->u.data.length);
4005 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_WMM (=%d) \n", pAdapter->CommonCfg.bWmmCapable));
4009 case OID_802_11_DISASSOCIATE:
4011 // Set NdisRadioStateOff to TRUE, instead of called MlmeRadioOff.
4012 // Later on, NDIS_802_11_BSSID_LIST_EX->NumberOfItems should be 0
4013 // when query OID_802_11_BSSID_LIST.
4015 // TRUE: NumberOfItems will set to 0.
4016 // FALSE: NumberOfItems no change.
4018 pAdapter->CommonCfg.NdisRadioStateOff = TRUE;
4019 // Set to immediately send the media disconnect event
4020 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
4021 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DISASSOCIATE \n"));
4023 if (INFRA_ON(pAdapter))
4025 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
4027 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
4028 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
4031 MlmeEnqueue(pAdapter,
4032 MLME_CNTL_STATE_MACHINE,
4033 OID_802_11_DISASSOCIATE,
4037 StateMachineTouched = TRUE;
4040 case RT_OID_802_11_SET_IMME_BA_CAP:
4041 if (wrq->u.data.length != sizeof(OID_BACAP_STRUC))
4045 OID_BACAP_STRUC Orde ;
4046 Status = copy_from_user(&Orde, wrq->u.data.pointer, wrq->u.data.length);
4047 if (Orde.Policy > BA_NOTUSE)
4049 Status = NDIS_STATUS_INVALID_DATA;
4051 else if (Orde.Policy == BA_NOTUSE)
4053 pAdapter->CommonCfg.BACapability.field.Policy = BA_NOTUSE;
4054 pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
4055 pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
4056 pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
4057 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
4058 pAdapter->CommonCfg.DesiredHtPhy.MimoPs= Orde.MMPSmode;
4059 pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
4061 pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
4062 pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
4063 pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
4067 pAdapter->CommonCfg.BACapability.field.AutoBA = Orde.AutoBA;
4068 pAdapter->CommonCfg.BACapability.field.Policy = IMMED_BA; // we only support immediate BA.
4069 pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
4070 pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
4071 pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
4072 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
4073 pAdapter->CommonCfg.DesiredHtPhy.MimoPs = Orde.MMPSmode;
4074 pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
4077 pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
4078 pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
4079 pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
4081 if (pAdapter->CommonCfg.BACapability.field.RxBAWinLimit > MAX_RX_REORDERBUF)
4082 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = MAX_RX_REORDERBUF;
4086 pAdapter->CommonCfg.REGBACapability.word = pAdapter->CommonCfg.BACapability.word;
4087 DBGPRINT(RT_DEBUG_TRACE, ("Set::(Orde.AutoBA = %d) (Policy=%d)(ReBAWinLimit=%d)(TxBAWinLimit=%d)(AutoMode=%d)\n",Orde.AutoBA, pAdapter->CommonCfg.BACapability.field.Policy,
4088 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit,pAdapter->CommonCfg.BACapability.field.TxBAWinLimit, pAdapter->CommonCfg.BACapability.field.AutoBA));
4089 DBGPRINT(RT_DEBUG_TRACE, ("Set::(MimoPs = %d)(AmsduEnable = %d) (AmsduSize=%d)(MpduDensity=%d)\n",pAdapter->CommonCfg.DesiredHtPhy.MimoPs, pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable,
4090 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize, pAdapter->CommonCfg.DesiredHtPhy.MpduDensity));
4094 case RT_OID_802_11_ADD_IMME_BA:
4095 DBGPRINT(RT_DEBUG_TRACE, (" Set :: RT_OID_802_11_ADD_IMME_BA \n"));
4096 if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
4101 OID_ADD_BA_ENTRY BA;
4102 MAC_TABLE_ENTRY *pEntry;
4104 Status = copy_from_user(&BA, wrq->u.data.pointer, wrq->u.data.length);
4107 Status = NDIS_STATUS_INVALID_DATA;
4112 //BATableInsertEntry
4113 //As ad-hoc mode, BA pair is not limited to only BSSID. so add via OID.
4115 // in ad hoc mode, when adding BA pair, we should insert this entry into MACEntry too
4116 pEntry = MacTableLookup(pAdapter, BA.MACAddr);
4119 DBGPRINT(RT_DEBUG_TRACE, ("RT_OID_802_11_ADD_IMME_BA. break on no connection.----:%x:%x\n", BA.MACAddr[4], BA.MACAddr[5]));
4122 if (BA.IsRecipient == FALSE)
4124 if (pEntry->bIAmBadAtheros == TRUE)
4125 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = 0x10;
4127 BAOriSessionSetUp(pAdapter, pEntry, index, 0, 100, TRUE);
4131 //BATableInsertEntry(pAdapter, pEntry->Aid, BA.MACAddr, 0, 0xffff, BA.TID, BA.nMSDU, BA.IsRecipient);
4134 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_IMME_BA. Rec = %d. Mac = %x:%x:%x:%x:%x:%x . \n",
4135 BA.IsRecipient, BA.MACAddr[0], BA.MACAddr[1], BA.MACAddr[2], BA.MACAddr[2]
4136 , BA.MACAddr[4], BA.MACAddr[5]));
4141 case RT_OID_802_11_TEAR_IMME_BA:
4142 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA \n"));
4143 if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
4147 POID_ADD_BA_ENTRY pBA;
4148 MAC_TABLE_ENTRY *pEntry;
4150 pBA = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4154 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA kmalloc() can't allocate enough memory\n"));
4155 Status = NDIS_STATUS_FAILURE;
4159 Status = copy_from_user(pBA, wrq->u.data.pointer, wrq->u.data.length);
4160 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA(TID=%d, bAllTid=%d)\n", pBA->TID, pBA->bAllTid));
4162 if (!pBA->bAllTid && (pBA->TID > NUM_OF_TID))
4164 Status = NDIS_STATUS_INVALID_DATA;
4168 if (pBA->IsRecipient == FALSE)
4170 pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
4171 DBGPRINT(RT_DEBUG_TRACE, (" pBA->IsRecipient == FALSE\n"));
4174 DBGPRINT(RT_DEBUG_TRACE, (" pBA->pEntry\n"));
4175 BAOriSessionTearDown(pAdapter, pEntry->Aid, pBA->TID, FALSE, TRUE);
4178 DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
4182 pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
4185 BARecSessionTearDown( pAdapter, (UCHAR)pEntry->Aid, pBA->TID, TRUE);
4188 DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
4194 // For WPA_SUPPLICANT to set static wep key
4195 case OID_802_11_ADD_WEP:
4196 pWepKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4201 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed!!\n"));
4204 Status = copy_from_user(pWepKey, wrq->u.data.pointer, wrq->u.data.length);
4208 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (length mismatch)!!\n"));
4212 KeyIdx = pWepKey->KeyIndex & 0x0fffffff;
4213 // KeyIdx must be 0 ~ 3
4217 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (KeyIdx must be smaller than 4)!!\n"));
4221 UCHAR CipherAlg = 0;
4224 // set key material and key length
4225 NdisZeroMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, 16);
4226 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
4227 NdisMoveMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
4229 switch(pWepKey->KeyLength)
4232 CipherAlg = CIPHER_WEP64;
4235 CipherAlg = CIPHER_WEP128;
4238 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, only support CIPHER_WEP64(len:5) & CIPHER_WEP128(len:13)!!\n"));
4242 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CipherAlg;
4244 // Default key for tx (shared key)
4245 if (pWepKey->KeyIndex & 0x80000000)
4247 // set key material and key length
4248 NdisZeroMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, 16);
4249 pAdapter->StaCfg.DesireSharedKey[KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
4250 NdisMoveMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
4251 pAdapter->StaCfg.DesireSharedKeyId = KeyIdx;
4252 pAdapter->StaCfg.DesireSharedKey[KeyIdx].CipherAlg = CipherAlg;
4253 pAdapter->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
4257 if ((pAdapter->StaCfg.WpaSupplicantUP != 0) &&
4260 if ((pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE) &&
4262 (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA))
4264 Key = pWepKey->KeyMaterial;
4266 // Set Group key material to Asic
4267 AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
4269 // Update WCID attribute table and IVEIV table for this group key table
4270 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
4272 STA_PORT_SECURED(pAdapter);
4274 // Indicate Connected for GUI
4275 pAdapter->IndicateMediaState = NdisMediaStateConnected;
4277 else if (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)
4280 if (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)
4283 Key = pAdapter->SharedKey[BSS0][KeyIdx].Key;
4285 // Set key material and cipherAlg to Asic
4286 AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
4288 if (pWepKey->KeyIndex & 0x80000000)
4290 PMAC_TABLE_ENTRY pEntry = &pAdapter->MacTab.Content[BSSID_WCID];
4291 // Assign group key info
4292 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
4293 // Assign pairwise key info
4294 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, pEntry);
4297 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP (id=0x%x, Len=%d-byte), %s\n", pWepKey->KeyIndex, pWepKey->KeyLength, (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED) ? "Port Secured":"Port NOT Secured"));
4302 case OID_SET_COUNTERMEASURES:
4303 if (wrq->u.data.length != sizeof(int))
4308 Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
4310 pAdapter->StaCfg.bBlockAssoc = TRUE;
4312 // WPA MIC error should block association attempt for 60 seconds
4313 pAdapter->StaCfg.bBlockAssoc = FALSE;
4314 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_SET_COUNTERMEASURES bBlockAssoc=%s\n", pAdapter->StaCfg.bBlockAssoc ? "TRUE":"FALSE"));
4317 case RT_OID_WPA_SUPPLICANT_SUPPORT:
4318 if (wrq->u.data.length != sizeof(UCHAR))
4322 Status = copy_from_user(&wpa_supplicant_enable, wrq->u.data.pointer, wrq->u.data.length);
4323 pAdapter->StaCfg.WpaSupplicantUP = wpa_supplicant_enable;
4324 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
4327 case OID_802_11_DEAUTHENTICATION:
4328 if (wrq->u.data.length != sizeof(MLME_DEAUTH_REQ_STRUCT))
4332 MLME_DEAUTH_REQ_STRUCT *pInfo;
4333 MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
4335 pInfo = (MLME_DEAUTH_REQ_STRUCT *) MsgElem->Msg;
4336 Status = copy_from_user(pInfo, wrq->u.data.pointer, wrq->u.data.length);
4337 MlmeDeauthReqAction(pAdapter, MsgElem);
4340 if (INFRA_ON(pAdapter))
4342 LinkDown(pAdapter, FALSE);
4343 pAdapter->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
4345 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DEAUTHENTICATION (Reason=%d)\n", pInfo->Reason));
4348 case OID_802_11_DROP_UNENCRYPTED:
4349 if (wrq->u.data.length != sizeof(int))
4354 Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
4356 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
4358 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
4359 NdisAcquireSpinLock(&pAdapter->MacTabLock);
4360 pAdapter->MacTab.Content[BSSID_WCID].PortSecured = pAdapter->StaCfg.PortSecured;
4361 NdisReleaseSpinLock(&pAdapter->MacTabLock);
4362 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DROP_UNENCRYPTED (=%d)\n", enabled));
4365 case OID_802_11_SET_IEEE8021X:
4366 if (wrq->u.data.length != sizeof(BOOLEAN))
4370 Status = copy_from_user(&IEEE8021xState, wrq->u.data.pointer, wrq->u.data.length);
4371 pAdapter->StaCfg.IEEE8021X = IEEE8021xState;
4372 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X (=%d)\n", IEEE8021xState));
4375 case OID_802_11_SET_IEEE8021X_REQUIRE_KEY:
4376 if (wrq->u.data.length != sizeof(BOOLEAN))
4380 Status = copy_from_user(&IEEE8021x_required_keys, wrq->u.data.pointer, wrq->u.data.length);
4381 pAdapter->StaCfg.IEEE8021x_required_keys = IEEE8021x_required_keys;
4382 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X_REQUIRE_KEY (%d)\n", IEEE8021x_required_keys));
4385 case OID_802_11_PMKID:
4386 pPmkId = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4388 if(pPmkId == NULL) {
4392 Status = copy_from_user(pPmkId, wrq->u.data.pointer, wrq->u.data.length);
4394 // check the PMKID information
4395 if (pPmkId->BSSIDInfoCount == 0)
4396 NdisZeroMemory(pAdapter->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
4399 PBSSID_INFO pBssIdInfo;
4403 for (BssIdx = 0; BssIdx < pPmkId->BSSIDInfoCount; BssIdx++)
4405 // point to the indexed BSSID_INFO structure
4406 pBssIdInfo = (PBSSID_INFO) ((PUCHAR) pPmkId + 2 * sizeof(UINT) + BssIdx * sizeof(BSSID_INFO));
4407 // Find the entry in the saved data base.
4408 for (CachedIdx = 0; CachedIdx < pAdapter->StaCfg.SavedPMKNum; CachedIdx++)
4410 // compare the BSSID
4411 if (NdisEqualMemory(pBssIdInfo->BSSID, pAdapter->StaCfg.SavedPMK[CachedIdx].BSSID, sizeof(NDIS_802_11_MAC_ADDRESS)))
4415 // Found, replace it
4416 if (CachedIdx < PMKID_NO)
4418 DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
4419 NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
4420 pAdapter->StaCfg.SavedPMKNum++;
4422 // Not found, replace the last one
4425 // Randomly replace one
4426 CachedIdx = (pBssIdInfo->BSSID[5] % PMKID_NO);
4427 DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
4428 NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
4436 DBGPRINT(RT_DEBUG_TRACE, ("Set::unknown IOCTL's subcmd = 0x%08x\n", cmd));
4437 Status = -EOPNOTSUPP;
4445 INT RTMPQueryInformation(
4446 IN PRTMP_ADAPTER pAdapter,
4447 IN OUT struct ifreq *rq,
4450 struct iwreq *wrq = (struct iwreq *) rq;
4451 NDIS_802_11_BSSID_LIST_EX *pBssidList = NULL;
4452 PNDIS_WLAN_BSSID_EX pBss;
4453 NDIS_802_11_SSID Ssid;
4454 NDIS_802_11_CONFIGURATION *pConfiguration = NULL;
4455 RT_802_11_LINK_STATUS *pLinkStatus = NULL;
4456 RT_802_11_STA_CONFIG *pStaConfig = NULL;
4457 NDIS_802_11_STATISTICS *pStatistics = NULL;
4458 NDIS_802_11_RTS_THRESHOLD RtsThresh;
4459 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
4460 NDIS_802_11_POWER_MODE PowerMode;
4461 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
4462 RT_802_11_PREAMBLE PreamType;
4463 NDIS_802_11_AUTHENTICATION_MODE AuthMode;
4464 NDIS_802_11_WEP_STATUS WepStatus;
4465 NDIS_MEDIA_STATE MediaState;
4466 ULONG BssBufSize, ulInfo=0, NetworkTypeList[4], apsd = 0;
4468 PUCHAR pBuf = NULL, pPtr;
4469 INT Status = NDIS_STATUS_SUCCESS;
4470 UINT we_version_compiled;
4471 UCHAR i, Padding = 0;
4473 UCHAR driverVersion[8];
4474 OID_SET_HT_PHYMODE *pHTPhyMode = NULL;
4478 case RT_OID_DEVICE_NAME:
4479 wrq->u.data.length = sizeof(STA_NIC_DEVICE_NAME);
4480 Status = copy_to_user(wrq->u.data.pointer, STA_NIC_DEVICE_NAME, wrq->u.data.length);
4482 case RT_OID_VERSION_INFO:
4483 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_VERSION_INFO \n"));
4484 wrq->u.data.length = 8*sizeof(UCHAR);
4485 sprintf(&driverVersion[0], "%s", STA_DRIVER_VERSION);
4486 driverVersion[7] = '\0';
4487 if (copy_to_user(wrq->u.data.pointer, &driverVersion, wrq->u.data.length))
4492 case OID_802_11_BSSID_LIST:
4493 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
4496 * Still scanning, indicate the caller should try again.
4498 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (Still scanning)\n"));
4501 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (%d BSS returned)\n",pAdapter->ScanTab.BssNr));
4502 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
4503 // Claculate total buffer size required
4504 BssBufSize = sizeof(ULONG);
4506 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
4508 // Align pointer to 4 bytes boundary.
4509 //Padding = 4 - (pAdapter->ScanTab.BssEntry[i].VarIELen & 0x0003);
4512 BssBufSize += (sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
4515 // For safety issue, we add 256 bytes just in case
4517 // Allocate the same size as passed from higher layer
4518 pBuf = kmalloc(BssBufSize, MEM_ALLOC_FLAG);
4524 // Init 802_11_BSSID_LIST_EX structure
4525 NdisZeroMemory(pBuf, BssBufSize);
4526 pBssidList = (PNDIS_802_11_BSSID_LIST_EX) pBuf;
4527 pBssidList->NumberOfItems = pAdapter->ScanTab.BssNr;
4529 // Calculate total buffer length
4530 BssLen = 4; // Consist of NumberOfItems
4531 // Point to start of NDIS_WLAN_BSSID_EX
4532 // pPtr = pBuf + sizeof(ULONG);
4533 pPtr = (PUCHAR) &pBssidList->Bssid[0];
4534 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
4536 pBss = (PNDIS_WLAN_BSSID_EX) pPtr;
4537 NdisMoveMemory(&pBss->MacAddress, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
4538 if ((pAdapter->ScanTab.BssEntry[i].Hidden == 1) && (pAdapter->StaCfg.bShowHiddenSSID == FALSE))
4541 // We must return this SSID during 4way handshaking, otherwise Aegis will failed to parse WPA infomation
4542 // and then failed to send EAPOl farame.
4544 if ((pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) && (pAdapter->StaCfg.PortSecured != WPA_802_1X_PORT_SECURED))
4546 pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
4547 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
4550 pBss->Ssid.SsidLength = 0;
4554 pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
4555 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
4557 pBss->Privacy = pAdapter->ScanTab.BssEntry[i].Privacy;
4558 pBss->Rssi = pAdapter->ScanTab.BssEntry[i].Rssi - pAdapter->BbpRssiToDbmDelta;
4559 pBss->NetworkTypeInUse = NetworkTypeInUseSanity(&pAdapter->ScanTab.BssEntry[i]);
4560 pBss->Configuration.Length = sizeof(NDIS_802_11_CONFIGURATION);
4561 pBss->Configuration.BeaconPeriod = pAdapter->ScanTab.BssEntry[i].BeaconPeriod;
4562 pBss->Configuration.ATIMWindow = pAdapter->ScanTab.BssEntry[i].AtimWin;
4564 MAP_CHANNEL_ID_TO_KHZ(pAdapter->ScanTab.BssEntry[i].Channel, pBss->Configuration.DSConfig);
4566 if (pAdapter->ScanTab.BssEntry[i].BssType == BSS_INFRA)
4567 pBss->InfrastructureMode = Ndis802_11Infrastructure;
4569 pBss->InfrastructureMode = Ndis802_11IBSS;
4571 NdisMoveMemory(pBss->SupportedRates, pAdapter->ScanTab.BssEntry[i].SupRate, pAdapter->ScanTab.BssEntry[i].SupRateLen);
4572 NdisMoveMemory(pBss->SupportedRates + pAdapter->ScanTab.BssEntry[i].SupRateLen,
4573 pAdapter->ScanTab.BssEntry[i].ExtRate,
4574 pAdapter->ScanTab.BssEntry[i].ExtRateLen);
4576 if (pAdapter->ScanTab.BssEntry[i].VarIELen == 0)
4578 pBss->IELength = sizeof(NDIS_802_11_FIXED_IEs);
4579 NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
4580 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
4584 pBss->IELength = (ULONG)(sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen);
4585 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
4586 NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
4587 NdisMoveMemory(pBss->IEs + sizeof(NDIS_802_11_FIXED_IEs), pAdapter->ScanTab.BssEntry[i].VarIEs, pAdapter->ScanTab.BssEntry[i].VarIELen);
4588 pPtr += pAdapter->ScanTab.BssEntry[i].VarIELen;
4590 pBss->Length = (ULONG)(sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
4592 #if WIRELESS_EXT < 17
4593 if ((BssLen + pBss->Length) < wrq->u.data.length)
4594 BssLen += pBss->Length;
4597 pBssidList->NumberOfItems = i;
4601 BssLen += pBss->Length;
4605 #if WIRELESS_EXT < 17
4606 wrq->u.data.length = BssLen;
4608 if (BssLen > wrq->u.data.length)
4614 wrq->u.data.length = BssLen;
4616 Status = copy_to_user(wrq->u.data.pointer, pBssidList, BssLen);
4619 case OID_802_3_CURRENT_ADDRESS:
4620 wrq->u.data.length = MAC_ADDR_LEN;
4621 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
4623 case OID_GEN_MEDIA_CONNECT_STATUS:
4624 if (pAdapter->IndicateMediaState == NdisMediaStateConnected)
4625 MediaState = NdisMediaStateConnected;
4627 MediaState = NdisMediaStateDisconnected;
4629 wrq->u.data.length = sizeof(NDIS_MEDIA_STATE);
4630 Status = copy_to_user(wrq->u.data.pointer, &MediaState, wrq->u.data.length);
4632 case OID_802_11_BSSID:
4633 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
4635 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Bssid, sizeof(NDIS_802_11_MAC_ADDRESS));
4640 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID(=EMPTY)\n"));
4644 case OID_802_11_SSID:
4645 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
4646 NdisZeroMemory(Ssid.Ssid, MAX_LEN_OF_SSID);
4647 Ssid.SsidLength = pAdapter->CommonCfg.SsidLen;
4648 memcpy(Ssid.Ssid, pAdapter->CommonCfg.Ssid, Ssid.SsidLength);
4649 wrq->u.data.length = sizeof(NDIS_802_11_SSID);
4650 Status = copy_to_user(wrq->u.data.pointer, &Ssid, wrq->u.data.length);
4651 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_SSID (Len=%d, ssid=%s)\n", Ssid.SsidLength,Ssid.Ssid));
4653 case RT_OID_802_11_QUERY_LINK_STATUS:
4654 pLinkStatus = (RT_802_11_LINK_STATUS *) kmalloc(sizeof(RT_802_11_LINK_STATUS), MEM_ALLOC_FLAG);
4657 pLinkStatus->CurrTxRate = RateIdTo500Kbps[pAdapter->CommonCfg.TxRate]; // unit : 500 kbps
4658 pLinkStatus->ChannelQuality = pAdapter->Mlme.ChannelQuality;
4659 pLinkStatus->RxByteCount = pAdapter->RalinkCounters.ReceivedByteCount;
4660 pLinkStatus->TxByteCount = pAdapter->RalinkCounters.TransmittedByteCount;
4661 pLinkStatus->CentralChannel = pAdapter->CommonCfg.CentralChannel;
4662 wrq->u.data.length = sizeof(RT_802_11_LINK_STATUS);
4663 Status = copy_to_user(wrq->u.data.pointer, pLinkStatus, wrq->u.data.length);
4665 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS\n"));
4669 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS(kmalloc failed)\n"));
4673 case OID_802_11_CONFIGURATION:
4674 pConfiguration = (NDIS_802_11_CONFIGURATION *) kmalloc(sizeof(NDIS_802_11_CONFIGURATION), MEM_ALLOC_FLAG);
4677 pConfiguration->Length = sizeof(NDIS_802_11_CONFIGURATION);
4678 pConfiguration->BeaconPeriod = pAdapter->CommonCfg.BeaconPeriod;
4679 pConfiguration->ATIMWindow = pAdapter->StaActive.AtimWin;
4680 MAP_CHANNEL_ID_TO_KHZ(pAdapter->CommonCfg.Channel, pConfiguration->DSConfig);
4681 wrq->u.data.length = sizeof(NDIS_802_11_CONFIGURATION);
4682 Status = copy_to_user(wrq->u.data.pointer, pConfiguration, wrq->u.data.length);
4683 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(BeaconPeriod=%ld,AtimW=%ld,Channel=%d) \n",
4684 pConfiguration->BeaconPeriod, pConfiguration->ATIMWindow, pAdapter->CommonCfg.Channel));
4685 kfree(pConfiguration);
4689 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(kmalloc failed)\n"));
4693 case RT_OID_802_11_SNR_0:
4694 if ((pAdapter->StaCfg.LastSNR0 > 0))
4696 ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR0) * 3) / 16 ;
4697 wrq->u.data.length = sizeof(ulInfo);
4698 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4699 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_SNR_0(0x=%lx)\n", ulInfo));
4704 case RT_OID_802_11_SNR_1:
4705 if ((pAdapter->Antenna.field.RxPath > 1) &&
4706 (pAdapter->StaCfg.LastSNR1 > 0))
4708 ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR1) * 3) / 16 ;
4709 wrq->u.data.length = sizeof(ulInfo);
4710 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4711 DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(0x=%lx)\n",ulInfo));
4715 DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(pAdapter->StaCfg.LastSNR1=%d)\n",pAdapter->StaCfg.LastSNR1));
4717 case OID_802_11_RSSI_TRIGGER:
4718 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0 - pAdapter->BbpRssiToDbmDelta;
4719 wrq->u.data.length = sizeof(ulInfo);
4720 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4721 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RSSI_TRIGGER(=%ld)\n", ulInfo));
4723 case OID_802_11_RSSI:
4724 case RT_OID_802_11_RSSI:
4725 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0;
4726 wrq->u.data.length = sizeof(ulInfo);
4727 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4729 case RT_OID_802_11_RSSI_1:
4730 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi1;
4731 wrq->u.data.length = sizeof(ulInfo);
4732 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4734 case RT_OID_802_11_RSSI_2:
4735 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi2;
4736 wrq->u.data.length = sizeof(ulInfo);
4737 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4739 case OID_802_11_STATISTICS:
4740 pStatistics = (NDIS_802_11_STATISTICS *) kmalloc(sizeof(NDIS_802_11_STATISTICS), MEM_ALLOC_FLAG);
4743 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS \n"));
4744 // add the most up-to-date h/w raw counters into software counters
4745 NICUpdateRawCounters(pAdapter);
4747 // Sanity check for calculation of sucessful count
4748 if (pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart < pAdapter->WlanCounters.RetryCount.QuadPart)
4749 pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
4751 pStatistics->TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart;
4752 pStatistics->MulticastTransmittedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastTransmittedFrameCount.QuadPart;
4753 pStatistics->FailedCount.QuadPart = pAdapter->WlanCounters.FailedCount.QuadPart;
4754 pStatistics->RetryCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
4755 pStatistics->MultipleRetryCount.QuadPart = pAdapter->WlanCounters.MultipleRetryCount.QuadPart;
4756 pStatistics->RTSSuccessCount.QuadPart = pAdapter->WlanCounters.RTSSuccessCount.QuadPart;
4757 pStatistics->RTSFailureCount.QuadPart = pAdapter->WlanCounters.RTSFailureCount.QuadPart;
4758 pStatistics->ACKFailureCount.QuadPart = pAdapter->WlanCounters.ACKFailureCount.QuadPart;
4759 pStatistics->FrameDuplicateCount.QuadPart = pAdapter->WlanCounters.FrameDuplicateCount.QuadPart;
4760 pStatistics->ReceivedFragmentCount.QuadPart = pAdapter->WlanCounters.ReceivedFragmentCount.QuadPart;
4761 pStatistics->MulticastReceivedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastReceivedFrameCount.QuadPart;
4763 pStatistics->FCSErrorCount = pAdapter->RalinkCounters.RealFcsErrCount;
4765 pStatistics->FCSErrorCount.QuadPart = pAdapter->WlanCounters.FCSErrorCount.QuadPart;
4766 pStatistics->FrameDuplicateCount.u.LowPart = pAdapter->WlanCounters.FrameDuplicateCount.u.LowPart / 100;
4768 wrq->u.data.length = sizeof(NDIS_802_11_STATISTICS);
4769 Status = copy_to_user(wrq->u.data.pointer, pStatistics, wrq->u.data.length);
4774 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS(kmalloc failed)\n"));
4778 case OID_GEN_RCV_OK:
4779 ulInfo = pAdapter->Counters8023.GoodReceives;
4780 wrq->u.data.length = sizeof(ulInfo);
4781 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4783 case OID_GEN_RCV_NO_BUFFER:
4784 ulInfo = pAdapter->Counters8023.RxNoBuffer;
4785 wrq->u.data.length = sizeof(ulInfo);
4786 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4788 case RT_OID_802_11_PHY_MODE:
4789 ulInfo = (ULONG)pAdapter->CommonCfg.PhyMode;
4790 wrq->u.data.length = sizeof(ulInfo);
4791 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4792 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PHY_MODE (=%ld)\n", ulInfo));
4794 case RT_OID_802_11_STA_CONFIG:
4795 pStaConfig = (RT_802_11_STA_CONFIG *) kmalloc(sizeof(RT_802_11_STA_CONFIG), MEM_ALLOC_FLAG);
4798 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG\n"));
4799 pStaConfig->EnableTxBurst = pAdapter->CommonCfg.bEnableTxBurst;
4800 pStaConfig->EnableTurboRate = 0;
4801 pStaConfig->UseBGProtection = pAdapter->CommonCfg.UseBGProtection;
4802 pStaConfig->UseShortSlotTime = pAdapter->CommonCfg.bUseShortSlotTime;
4803 //pStaConfig->AdhocMode = pAdapter->StaCfg.AdhocMode;
4804 pStaConfig->HwRadioStatus = (pAdapter->StaCfg.bHwRadio == TRUE) ? 1 : 0;
4805 pStaConfig->Rsv1 = 0;
4806 pStaConfig->SystemErrorBitmap = pAdapter->SystemErrorBitmap;
4807 wrq->u.data.length = sizeof(RT_802_11_STA_CONFIG);
4808 Status = copy_to_user(wrq->u.data.pointer, pStaConfig, wrq->u.data.length);
4813 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
4817 case OID_802_11_RTS_THRESHOLD:
4818 RtsThresh = pAdapter->CommonCfg.RtsThreshold;
4819 wrq->u.data.length = sizeof(RtsThresh);
4820 Status = copy_to_user(wrq->u.data.pointer, &RtsThresh, wrq->u.data.length);
4821 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RTS_THRESHOLD(=%ld)\n", RtsThresh));
4823 case OID_802_11_FRAGMENTATION_THRESHOLD:
4824 FragThresh = pAdapter->CommonCfg.FragmentThreshold;
4825 if (pAdapter->CommonCfg.bUseZeroToDisableFragment == TRUE)
4827 wrq->u.data.length = sizeof(FragThresh);
4828 Status = copy_to_user(wrq->u.data.pointer, &FragThresh, wrq->u.data.length);
4829 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_FRAGMENTATION_THRESHOLD(=%ld)\n", FragThresh));
4831 case OID_802_11_POWER_MODE:
4832 PowerMode = pAdapter->StaCfg.WindowsPowerMode;
4833 wrq->u.data.length = sizeof(PowerMode);
4834 Status = copy_to_user(wrq->u.data.pointer, &PowerMode, wrq->u.data.length);
4835 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_POWER_MODE(=%d)\n", PowerMode));
4837 case RT_OID_802_11_RADIO:
4838 RadioState = (BOOLEAN) pAdapter->StaCfg.bSwRadio;
4839 wrq->u.data.length = sizeof(RadioState);
4840 Status = copy_to_user(wrq->u.data.pointer, &RadioState, wrq->u.data.length);
4841 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_RADIO (=%d)\n", RadioState));
4843 case OID_802_11_INFRASTRUCTURE_MODE:
4844 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
4845 BssType = Ndis802_11IBSS;
4846 else if (pAdapter->StaCfg.BssType == BSS_INFRA)
4847 BssType = Ndis802_11Infrastructure;
4848 else if (pAdapter->StaCfg.BssType == BSS_MONITOR)
4849 BssType = Ndis802_11Monitor;
4851 BssType = Ndis802_11AutoUnknown;
4853 wrq->u.data.length = sizeof(BssType);
4854 Status = copy_to_user(wrq->u.data.pointer, &BssType, wrq->u.data.length);
4855 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_INFRASTRUCTURE_MODE(=%d)\n", BssType));
4857 case RT_OID_802_11_PREAMBLE:
4858 PreamType = pAdapter->CommonCfg.TxPreamble;
4859 wrq->u.data.length = sizeof(PreamType);
4860 Status = copy_to_user(wrq->u.data.pointer, &PreamType, wrq->u.data.length);
4861 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PREAMBLE(=%d)\n", PreamType));
4863 case OID_802_11_AUTHENTICATION_MODE:
4864 AuthMode = pAdapter->StaCfg.AuthMode;
4865 wrq->u.data.length = sizeof(AuthMode);
4866 Status = copy_to_user(wrq->u.data.pointer, &AuthMode, wrq->u.data.length);
4867 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_AUTHENTICATION_MODE(=%d)\n", AuthMode));
4869 case OID_802_11_WEP_STATUS:
4870 WepStatus = pAdapter->StaCfg.WepStatus;
4871 wrq->u.data.length = sizeof(WepStatus);
4872 Status = copy_to_user(wrq->u.data.pointer, &WepStatus, wrq->u.data.length);
4873 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_WEP_STATUS(=%d)\n", WepStatus));
4875 case OID_802_11_TX_POWER_LEVEL:
4876 wrq->u.data.length = sizeof(ULONG);
4877 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPower, wrq->u.data.length);
4878 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_TX_POWER_LEVEL %x\n",pAdapter->CommonCfg.TxPower));
4880 case RT_OID_802_11_TX_POWER_LEVEL_1:
4881 wrq->u.data.length = sizeof(ULONG);
4882 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPowerPercentage, wrq->u.data.length);
4883 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
4885 case OID_802_11_NETWORK_TYPES_SUPPORTED:
4886 if ((pAdapter->RfIcType == RFIC_2850) || (pAdapter->RfIcType == RFIC_2750))
4888 NetworkTypeList[0] = 3; // NumberOfItems = 3
4889 NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
4890 NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
4891 NetworkTypeList[3] = Ndis802_11OFDM5; // NetworkType[3] = 11a
4892 wrq->u.data.length = 16;
4893 Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
4897 NetworkTypeList[0] = 2; // NumberOfItems = 2
4898 NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
4899 NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
4900 wrq->u.data.length = 12;
4901 Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
4903 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_NETWORK_TYPES_SUPPORTED\n"));
4905 case OID_802_11_NETWORK_TYPE_IN_USE:
4906 wrq->u.data.length = sizeof(ULONG);
4907 if (pAdapter->CommonCfg.PhyMode == PHY_11A)
4908 ulInfo = Ndis802_11OFDM5;
4909 else if ((pAdapter->CommonCfg.PhyMode == PHY_11BG_MIXED) || (pAdapter->CommonCfg.PhyMode == PHY_11G))
4910 ulInfo = Ndis802_11OFDM24;
4912 ulInfo = Ndis802_11DS;
4913 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4915 case RT_OID_802_11_QUERY_LAST_RX_RATE:
4916 ulInfo = (ULONG)pAdapter->LastRxRate;
4917 wrq->u.data.length = sizeof(ulInfo);
4918 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4919 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_RX_RATE (=%ld)\n", ulInfo));
4921 case RT_OID_802_11_QUERY_LAST_TX_RATE:
4922 //ulInfo = (ULONG)pAdapter->LastTxRate;
4923 ulInfo = (ULONG)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word;
4924 wrq->u.data.length = sizeof(ulInfo);
4925 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4926 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_TX_RATE (=%lx)\n", ulInfo));
4928 case RT_OID_802_11_QUERY_EEPROM_VERSION:
4929 wrq->u.data.length = sizeof(ULONG);
4930 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->EepromVersion, wrq->u.data.length);
4932 case RT_OID_802_11_QUERY_FIRMWARE_VERSION:
4933 wrq->u.data.length = sizeof(ULONG);
4934 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->FirmwareVersion, wrq->u.data.length);
4936 case RT_OID_802_11_QUERY_NOISE_LEVEL:
4937 wrq->u.data.length = sizeof(UCHAR);
4938 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->BbpWriteLatch[66], wrq->u.data.length);
4939 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_NOISE_LEVEL (=%d)\n", pAdapter->BbpWriteLatch[66]));
4941 case RT_OID_802_11_EXTRA_INFO:
4942 wrq->u.data.length = sizeof(ULONG);
4943 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->ExtraInfo, wrq->u.data.length);
4944 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_EXTRA_INFO (=%ld)\n", pAdapter->ExtraInfo));
4946 case RT_OID_WE_VERSION_COMPILED:
4947 wrq->u.data.length = sizeof(UINT);
4948 we_version_compiled = WIRELESS_EXT;
4949 Status = copy_to_user(wrq->u.data.pointer, &we_version_compiled, wrq->u.data.length);
4951 case RT_OID_802_11_QUERY_APSD_SETTING:
4952 apsd = (pAdapter->CommonCfg.bAPSDCapable | (pAdapter->CommonCfg.bAPSDAC_BE << 1) | (pAdapter->CommonCfg.bAPSDAC_BK << 2)
4953 | (pAdapter->CommonCfg.bAPSDAC_VI << 3) | (pAdapter->CommonCfg.bAPSDAC_VO << 4) | (pAdapter->CommonCfg.MaxSPLength << 5));
4955 wrq->u.data.length = sizeof(ULONG);
4956 Status = copy_to_user(wrq->u.data.pointer, &apsd, wrq->u.data.length);
4957 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_APSD_SETTING (=0x%lx,APSDCap=%d,AC_BE=%d,AC_BK=%d,AC_VI=%d,AC_VO=%d,MAXSPLen=%d)\n",
4958 apsd,pAdapter->CommonCfg.bAPSDCapable,pAdapter->CommonCfg.bAPSDAC_BE,pAdapter->CommonCfg.bAPSDAC_BK,pAdapter->CommonCfg.bAPSDAC_VI,pAdapter->CommonCfg.bAPSDAC_VO,pAdapter->CommonCfg.MaxSPLength));
4960 case RT_OID_802_11_QUERY_APSD_PSM:
4961 wrq->u.data.length = sizeof(ULONG);
4962 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.length);
4963 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_APSD_PSM (=%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
4965 case RT_OID_802_11_QUERY_WMM:
4966 wrq->u.data.length = sizeof(BOOLEAN);
4967 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bWmmCapable, wrq->u.data.length);
4968 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_WMM (=%d)\n", pAdapter->CommonCfg.bWmmCapable));
4970 case RT_OID_NEW_DRIVER:
4973 wrq->u.data.length = sizeof(UCHAR);
4974 Status = copy_to_user(wrq->u.data.pointer, &enabled, wrq->u.data.length);
4975 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_NEW_DRIVER (=%d)\n", enabled));
4978 case RT_OID_WPA_SUPPLICANT_SUPPORT:
4979 wrq->u.data.length = sizeof(UCHAR);
4980 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->StaCfg.WpaSupplicantUP, wrq->u.data.length);
4981 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
4983 case RT_OID_DRIVER_DEVICE_NAME:
4984 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_DRIVER_DEVICE_NAME \n"));
4985 wrq->u.data.length = 16;
4986 if (copy_to_user(wrq->u.data.pointer, pAdapter->StaCfg.dev_name, wrq->u.data.length))
4991 case RT_OID_802_11_QUERY_HT_PHYMODE:
4992 pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
4995 pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
4996 pHTPhyMode->HtMode = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE;
4997 pHTPhyMode->BW = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.BW;
4998 pHTPhyMode->MCS= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MCS;
4999 pHTPhyMode->SHORTGI= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.ShortGI;
5000 pHTPhyMode->STBC= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.STBC;
5002 pHTPhyMode->ExtOffset = ((pAdapter->CommonCfg.CentralChannel < pAdapter->CommonCfg.Channel) ? (EXTCHA_BELOW) : (EXTCHA_ABOVE));
5003 wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
5004 if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
5008 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
5009 pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
5010 DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
5014 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
5018 case RT_OID_802_11_COUNTRY_REGION:
5019 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_COUNTRY_REGION \n"));
5020 wrq->u.data.length = sizeof(ulInfo);
5021 ulInfo = pAdapter->CommonCfg.CountryRegionForABand;
5022 ulInfo = (ulInfo << 8)|(pAdapter->CommonCfg.CountryRegion);
5023 if (copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length))
5028 case RT_OID_802_11_QUERY_DAT_HT_PHYMODE:
5029 pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
5032 pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
5033 pHTPhyMode->HtMode = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.HTMODE;
5034 pHTPhyMode->BW = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.BW;
5035 pHTPhyMode->MCS= (UCHAR)pAdapter->StaCfg.DesiredTransmitSetting.field.MCS;
5036 pHTPhyMode->SHORTGI= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.ShortGI;
5037 pHTPhyMode->STBC= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.STBC;
5039 wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
5040 if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
5044 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
5045 pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
5046 DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
5050 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
5054 case RT_OID_QUERY_MULTIPLE_CARD_SUPPORT:
5055 wrq->u.data.length = sizeof(UCHAR);
5057 if (copy_to_user(wrq->u.data.pointer, &i, wrq->u.data.length))
5061 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_QUERY_MULTIPLE_CARD_SUPPORT(=%d) \n", i));
5064 case OID_802_11_BUILD_CHANNEL_EX:
5067 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BUILD_CHANNEL_EX \n"));
5068 wrq->u.data.length = sizeof(UCHAR);
5069 DBGPRINT(RT_DEBUG_TRACE, ("Doesn't support EXT_BUILD_CHANNEL_LIST.\n"));
5071 Status = copy_to_user(wrq->u.data.pointer, &value, 1);
5072 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5076 case OID_802_11_GET_CH_LIST:
5078 PRT_CHANNEL_LIST_INFO pChListBuf;
5080 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CH_LIST \n"));
5081 if (pAdapter->ChannelListNum == 0)
5083 wrq->u.data.length = 0;
5087 pChListBuf = (RT_CHANNEL_LIST_INFO *) kmalloc(sizeof(RT_CHANNEL_LIST_INFO), MEM_ALLOC_FLAG);
5088 if (pChListBuf == NULL)
5090 wrq->u.data.length = 0;
5094 pChListBuf->ChannelListNum = pAdapter->ChannelListNum;
5095 for (i = 0; i < pChListBuf->ChannelListNum; i++)
5096 pChListBuf->ChannelList[i] = pAdapter->ChannelList[i].Channel;
5098 wrq->u.data.length = sizeof(RT_CHANNEL_LIST_INFO);
5099 Status = copy_to_user(wrq->u.data.pointer, pChListBuf, sizeof(RT_CHANNEL_LIST_INFO));
5100 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5107 case OID_802_11_GET_COUNTRY_CODE:
5108 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_COUNTRY_CODE \n"));
5109 wrq->u.data.length = 2;
5110 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.CountryCode, 2);
5111 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5114 case OID_802_11_GET_CHANNEL_GEOGRAPHY:
5115 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CHANNEL_GEOGRAPHY \n"));
5116 wrq->u.data.length = 1;
5117 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Geography, 1);
5118 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5122 DBGPRINT(RT_DEBUG_TRACE, ("Query::unknown IOCTL's subcmd = 0x%08x\n", cmd));
5123 Status = -EOPNOTSUPP;
5129 INT rt28xx_sta_ioctl(
5130 IN struct net_device *net_dev,
5131 IN OUT struct ifreq *rq,
5135 VIRTUAL_ADAPTER *pVirtualAd = NULL;
5136 RTMP_ADAPTER *pAd = NULL;
5137 struct iwreq *wrq = (struct iwreq *) rq;
5138 BOOLEAN StateMachineTouched = FALSE;
5139 INT Status = NDIS_STATUS_SUCCESS;
5142 if (net_dev->priv_flags == INT_MAIN)
5144 pAd = net_dev->ml_priv;
5148 pVirtualAd = net_dev->ml_priv;
5149 pAd = pVirtualAd->RtmpDev->ml_priv;
5151 pObj = (POS_COOKIE) pAd->OS_Cookie;
5155 /* if 1st open fail, pAd will be free;
5156 So the net_dev->ml_priv will be NULL in 2rd open */
5160 //check if the interface is down
5161 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
5164 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
5169 { // determine this ioctl command is comming from which interface.
5170 pObj->ioctl_if_type = INT_MAIN;
5171 pObj->ioctl_if = MAIN_MBSSID;
5177 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIFHWADDR\n"));
5178 memcpy(wrq->u.name, pAd->CurrentAddress, ETH_ALEN);
5182 char *name=&wrq->u.name[0];
5183 rt_ioctl_giwname(net_dev, NULL, name, NULL);
5186 case SIOCGIWESSID: //Get ESSID
5188 struct iw_point *essid=&wrq->u.essid;
5189 rt_ioctl_giwessid(net_dev, NULL, essid, essid->pointer);
5192 case SIOCSIWESSID: //Set ESSID
5194 struct iw_point *essid=&wrq->u.essid;
5195 rt_ioctl_siwessid(net_dev, NULL, essid, essid->pointer);
5198 case SIOCSIWNWID: // set network id (the cell)
5199 case SIOCGIWNWID: // get network id
5200 Status = -EOPNOTSUPP;
5202 case SIOCSIWFREQ: //set channel/frequency (Hz)
5204 struct iw_freq *freq=&wrq->u.freq;
5205 rt_ioctl_siwfreq(net_dev, NULL, freq, NULL);
5208 case SIOCGIWFREQ: // get channel/frequency (Hz)
5210 struct iw_freq *freq=&wrq->u.freq;
5211 rt_ioctl_giwfreq(net_dev, NULL, freq, NULL);
5214 case SIOCSIWNICKN: //set node name/nickname
5216 struct iw_point *data=&wrq->u.data;
5217 rt_ioctl_siwnickn(net_dev, NULL, data, NULL);
5220 case SIOCGIWNICKN: //get node name/nickname
5222 struct iw_point *data=&wrq->u.data;
5223 rt_ioctl_giwnickn(net_dev, NULL, data, NULL);
5226 case SIOCGIWRATE: //get default bit rate (bps)
5227 rt_ioctl_giwrate(net_dev, NULL, &wrq->u, NULL);
5229 case SIOCSIWRATE: //set default bit rate (bps)
5230 rt_ioctl_siwrate(net_dev, NULL, &wrq->u, NULL);
5232 case SIOCGIWRTS: // get RTS/CTS threshold (bytes)
5234 struct iw_param *rts=&wrq->u.rts;
5235 rt_ioctl_giwrts(net_dev, NULL, rts, NULL);
5238 case SIOCSIWRTS: //set RTS/CTS threshold (bytes)
5240 struct iw_param *rts=&wrq->u.rts;
5241 rt_ioctl_siwrts(net_dev, NULL, rts, NULL);
5244 case SIOCGIWFRAG: //get fragmentation thr (bytes)
5246 struct iw_param *frag=&wrq->u.frag;
5247 rt_ioctl_giwfrag(net_dev, NULL, frag, NULL);
5250 case SIOCSIWFRAG: //set fragmentation thr (bytes)
5252 struct iw_param *frag=&wrq->u.frag;
5253 rt_ioctl_siwfrag(net_dev, NULL, frag, NULL);
5256 case SIOCGIWENCODE: //get encoding token & mode
5258 struct iw_point *erq=&wrq->u.encoding;
5260 rt_ioctl_giwencode(net_dev, NULL, erq, erq->pointer);
5263 case SIOCSIWENCODE: //set encoding token & mode
5265 struct iw_point *erq=&wrq->u.encoding;
5267 rt_ioctl_siwencode(net_dev, NULL, erq, erq->pointer);
5270 case SIOCGIWAP: //get access point MAC addresses
5272 struct sockaddr *ap_addr=&wrq->u.ap_addr;
5273 rt_ioctl_giwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
5276 case SIOCSIWAP: //set access point MAC addresses
5278 struct sockaddr *ap_addr=&wrq->u.ap_addr;
5279 rt_ioctl_siwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
5282 case SIOCGIWMODE: //get operation mode
5284 __u32 *mode=&wrq->u.mode;
5285 rt_ioctl_giwmode(net_dev, NULL, mode, NULL);
5288 case SIOCSIWMODE: //set operation mode
5290 __u32 *mode=&wrq->u.mode;
5291 rt_ioctl_siwmode(net_dev, NULL, mode, NULL);
5294 case SIOCGIWSENS: //get sensitivity (dBm)
5295 case SIOCSIWSENS: //set sensitivity (dBm)
5296 case SIOCGIWPOWER: //get Power Management settings
5297 case SIOCSIWPOWER: //set Power Management settings
5298 case SIOCGIWTXPOW: //get transmit power (dBm)
5299 case SIOCSIWTXPOW: //set transmit power (dBm)
5300 case SIOCGIWRANGE: //Get range of parameters
5301 case SIOCGIWRETRY: //get retry limits and lifetime
5302 case SIOCSIWRETRY: //set retry limits and lifetime
5303 Status = -EOPNOTSUPP;
5307 case RT_PRIV_IOCTL_EXT:
5309 subcmd = wrq->u.data.flags;
5310 if( subcmd & OID_GET_SET_TOGGLE)
5311 Status = RTMPSetInformation(pAd, rq, subcmd);
5313 Status = RTMPQueryInformation(pAd, rq, subcmd);
5316 if (wrq->u.data.pointer)
5318 if ( access_ok(VERIFY_WRITE, wrq->u.data.pointer, sizeof(privtab)) != TRUE)
5320 wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
5321 if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
5325 case RTPRIV_IOCTL_SET:
5326 if(access_ok(VERIFY_READ, wrq->u.data.pointer, wrq->u.data.length) != TRUE)
5328 rt_ioctl_setparam(net_dev, NULL, NULL, wrq->u.data.pointer);
5330 case RTPRIV_IOCTL_GSITESURVEY:
5331 RTMPIoctlGetSiteSurvey(pAd, wrq);
5334 case RTPRIV_IOCTL_MAC:
5335 RTMPIoctlMAC(pAd, wrq);
5337 case RTPRIV_IOCTL_E2P:
5338 RTMPIoctlE2PROM(pAd, wrq);
5341 case RTPRIV_IOCTL_RF:
5342 RTMPIoctlRF(pAd, wrq);
5349 DBGPRINT(RT_DEBUG_ERROR, ("IOCTL::unknown IOCTL's cmd = 0x%08x\n", cmd));
5350 Status = -EOPNOTSUPP;
5354 if(StateMachineTouched) // Upper layer sent a MLME-related operations
5355 RT28XX_MLME_HANDLER(pAd);
5361 ==========================================================================
5365 TRUE if all parameters are OK, FALSE otherwise
5366 ==========================================================================
5369 IN PRTMP_ADAPTER pAdapter,
5372 NDIS_802_11_SSID Ssid, *pSsid=NULL;
5373 BOOLEAN StateMachineTouched = FALSE;
5376 if( strlen(arg) <= MAX_LEN_OF_SSID)
5378 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
5379 if (strlen(arg) != 0)
5381 NdisMoveMemory(Ssid.Ssid, arg, strlen(arg));
5382 Ssid.SsidLength = strlen(arg);
5386 Ssid.SsidLength = 0;
5387 memcpy(Ssid.Ssid, "", 0);
5388 pAdapter->StaCfg.BssType = BSS_INFRA;
5389 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
5390 pAdapter->StaCfg.WepStatus = Ndis802_11EncryptionDisabled;
5394 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
5396 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
5397 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
5400 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
5401 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
5402 pAdapter->bConfigChanged = TRUE;
5404 MlmeEnqueue(pAdapter,
5405 MLME_CNTL_STATE_MACHINE,
5407 sizeof(NDIS_802_11_SSID),
5410 StateMachineTouched = TRUE;
5411 DBGPRINT(RT_DEBUG_TRACE, ("Set_SSID_Proc::(Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
5416 if (StateMachineTouched) // Upper layer sent a MLME-related operations
5417 RT28XX_MLME_HANDLER(pAdapter);
5424 ==========================================================================
5426 Set WmmCapable Enable or Disable
5428 TRUE if all parameters are OK, FALSE otherwise
5429 ==========================================================================
5431 INT Set_WmmCapable_Proc(
5432 IN PRTMP_ADAPTER pAd,
5435 BOOLEAN bWmmCapable;
5437 bWmmCapable = simple_strtol(arg, 0, 10);
5439 if ((bWmmCapable == 1)
5441 && (pAd->NumberOfPipes >= 5)
5444 pAd->CommonCfg.bWmmCapable = TRUE;
5445 else if (bWmmCapable == 0)
5446 pAd->CommonCfg.bWmmCapable = FALSE;
5448 return FALSE; //Invalid argument
5450 DBGPRINT(RT_DEBUG_TRACE, ("Set_WmmCapable_Proc::(bWmmCapable=%d)\n",
5451 pAd->CommonCfg.bWmmCapable));
5455 #endif // WMM_SUPPORT //
5458 ==========================================================================
5460 Set Network Type(Infrastructure/Adhoc mode)
5462 TRUE if all parameters are OK, FALSE otherwise
5463 ==========================================================================
5465 INT Set_NetworkType_Proc(
5466 IN PRTMP_ADAPTER pAdapter,
5471 if (strcmp(arg, "Adhoc") == 0)
5473 if (pAdapter->StaCfg.BssType != BSS_ADHOC)
5475 // Config has changed
5476 pAdapter->bConfigChanged = TRUE;
5477 if (MONITOR_ON(pAdapter))
5479 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
5480 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5482 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5483 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5484 pAdapter->StaCfg.bAutoReconnect = TRUE;
5485 LinkDown(pAdapter, FALSE);
5487 if (INFRA_ON(pAdapter))
5489 //BOOLEAN Cancelled;
5490 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
5491 // Since calling this indicate user don't want to connect to that SSID anymore.
5492 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
5493 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
5495 LinkDown(pAdapter, FALSE);
5497 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n"));
5500 pAdapter->StaCfg.BssType = BSS_ADHOC;
5501 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
5502 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(AD-HOC)\n"));
5504 else if (strcmp(arg, "Infra") == 0)
5506 if (pAdapter->StaCfg.BssType != BSS_INFRA)
5508 // Config has changed
5509 pAdapter->bConfigChanged = TRUE;
5510 if (MONITOR_ON(pAdapter))
5512 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
5513 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5515 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5516 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5517 pAdapter->StaCfg.bAutoReconnect = TRUE;
5518 LinkDown(pAdapter, FALSE);
5520 if (ADHOC_ON(pAdapter))
5522 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
5523 // Since calling this indicate user don't want to connect to that SSID anymore.
5524 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
5525 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
5527 LinkDown(pAdapter, FALSE);
5530 pAdapter->StaCfg.BssType = BSS_INFRA;
5531 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
5532 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(INFRA)\n"));
5534 pAdapter->StaCfg.BssType = BSS_INFRA;
5536 else if (strcmp(arg, "Monitor") == 0)
5539 BCN_TIME_CFG_STRUC csr;
5540 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_INFRA_ON);
5541 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_ADHOC_ON);
5542 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5543 // disable all periodic state machine
5544 pAdapter->StaCfg.bAutoReconnect = FALSE;
5545 // reset all mlme state machine
5546 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
5547 DBGPRINT(RT_DEBUG_TRACE, ("fOP_STATUS_MEDIA_STATE_CONNECTED \n"));
5548 if (pAdapter->CommonCfg.CentralChannel == 0)
5550 if (pAdapter->CommonCfg.PhyMode == PHY_11AN_MIXED)
5551 pAdapter->CommonCfg.CentralChannel = 36;
5553 pAdapter->CommonCfg.CentralChannel = 6;
5556 N_ChannelCheck(pAdapter);
5558 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
5559 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
5560 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_ABOVE)
5562 // 40MHz ,control channel at lower
5563 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5564 bbpValue &= (~0x18);
5566 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5567 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
5568 // RX : control channel at lower
5569 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
5570 bbpValue &= (~0x20);
5571 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
5573 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
5574 Value &= 0xfffffffe;
5575 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
5576 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel + 2;
5577 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
5578 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
5579 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
5580 pAdapter->CommonCfg.Channel,
5581 pAdapter->CommonCfg.CentralChannel));
5583 else if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
5584 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
5585 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_BELOW)
5587 // 40MHz ,control channel at upper
5588 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5589 bbpValue &= (~0x18);
5591 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5592 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
5593 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
5595 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
5597 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
5599 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
5600 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel - 2;
5601 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
5602 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
5603 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
5604 pAdapter->CommonCfg.Channel,
5605 pAdapter->CommonCfg.CentralChannel));
5610 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5611 bbpValue &= (~0x18);
5612 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5613 pAdapter->CommonCfg.BBPCurrentBW = BW_20;
5614 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.Channel, FALSE);
5615 AsicLockChannel(pAdapter, pAdapter->CommonCfg.Channel);
5616 DBGPRINT(RT_DEBUG_TRACE, ("BW_20, Channel(%d)\n", pAdapter->CommonCfg.Channel));
5618 // Enable Rx with promiscuous reception
5619 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, 0x3);
5620 // ASIC supporsts sniffer function with replacing RSSI with timestamp.
5621 //RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5623 //RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5625 RTMP_IO_READ32(pAdapter, BCN_TIME_CFG, &csr.word);
5626 csr.field.bBeaconGen = 0;
5627 csr.field.bTBTTEnable = 0;
5628 csr.field.TsfSyncMode = 0;
5629 RTMP_IO_WRITE32(pAdapter, BCN_TIME_CFG, csr.word);
5631 pAdapter->StaCfg.BssType = BSS_MONITOR;
5632 pAdapter->net_dev->type = ARPHRD_IEEE80211_PRISM; //ARPHRD_IEEE80211; // IEEE80211
5633 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(MONITOR)\n"));
5636 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
5637 pAdapter->StaCfg.WpaState = SS_NOTUSE;
5639 DBGPRINT(RT_DEBUG_TRACE, ("Set_NetworkType_Proc::(NetworkType=%d)\n", pAdapter->StaCfg.BssType));
5645 ==========================================================================
5647 Set Authentication mode
5649 TRUE if all parameters are OK, FALSE otherwise
5650 ==========================================================================
5652 INT Set_AuthMode_Proc(
5653 IN PRTMP_ADAPTER pAdapter,
5656 if ((strcmp(arg, "WEPAUTO") == 0) || (strcmp(arg, "wepauto") == 0))
5657 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeAutoSwitch;
5658 else if ((strcmp(arg, "OPEN") == 0) || (strcmp(arg, "open") == 0))
5659 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
5660 else if ((strcmp(arg, "SHARED") == 0) || (strcmp(arg, "shared") == 0))
5661 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
5662 else if ((strcmp(arg, "WPAPSK") == 0) || (strcmp(arg, "wpapsk") == 0))
5663 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
5664 else if ((strcmp(arg, "WPANONE") == 0) || (strcmp(arg, "wpanone") == 0))
5665 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
5666 else if ((strcmp(arg, "WPA2PSK") == 0) || (strcmp(arg, "wpa2psk") == 0))
5667 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
5668 else if ((strcmp(arg, "WPA") == 0) || (strcmp(arg, "wpa") == 0))
5669 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
5670 else if ((strcmp(arg, "WPA2") == 0) || (strcmp(arg, "wpa2") == 0))
5671 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
5675 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
5677 DBGPRINT(RT_DEBUG_TRACE, ("Set_AuthMode_Proc::(AuthMode=%d)\n", pAdapter->StaCfg.AuthMode));
5683 ==========================================================================
5687 TRUE if all parameters are OK, FALSE otherwise
5688 ==========================================================================
5690 INT Set_EncrypType_Proc(
5691 IN PRTMP_ADAPTER pAdapter,
5694 if ((strcmp(arg, "NONE") == 0) || (strcmp(arg, "none") == 0))
5696 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5697 return TRUE; // do nothing
5699 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
5700 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
5701 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
5703 else if ((strcmp(arg, "WEP") == 0) || (strcmp(arg, "wep") == 0))
5705 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5706 return TRUE; // do nothing
5708 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
5709 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
5710 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
5712 else if ((strcmp(arg, "TKIP") == 0) || (strcmp(arg, "tkip") == 0))
5714 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
5715 return TRUE; // do nothing
5717 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
5718 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
5719 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
5721 else if ((strcmp(arg, "AES") == 0) || (strcmp(arg, "aes") == 0))
5723 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
5724 return TRUE; // do nothing
5726 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
5727 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
5728 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
5733 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
5735 DBGPRINT(RT_DEBUG_TRACE, ("Set_EncrypType_Proc::(EncrypType=%d)\n", pAdapter->StaCfg.WepStatus));
5741 ==========================================================================
5745 TRUE if all parameters are OK, FALSE otherwise
5746 ==========================================================================
5748 INT Set_DefaultKeyID_Proc(
5749 IN PRTMP_ADAPTER pAdapter,
5754 KeyIdx = simple_strtol(arg, 0, 10);
5755 if((KeyIdx >= 1 ) && (KeyIdx <= 4))
5756 pAdapter->StaCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1 );
5758 return FALSE; //Invalid argument
5760 DBGPRINT(RT_DEBUG_TRACE, ("Set_DefaultKeyID_Proc::(DefaultKeyID=%d)\n", pAdapter->StaCfg.DefaultKeyId));
5766 ==========================================================================
5770 TRUE if all parameters are OK, FALSE otherwise
5771 ==========================================================================
5774 IN PRTMP_ADAPTER pAdapter,
5779 UCHAR CipherAlg=CIPHER_WEP64;
5781 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5782 return TRUE; // do nothing
5784 KeyLen = strlen(arg);
5788 case 5: //wep 40 Ascii type
5789 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
5790 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
5791 CipherAlg = CIPHER_WEP64;
5792 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
5794 case 10: //wep 40 Hex type
5795 for(i=0; i < KeyLen; i++)
5797 if( !isxdigit(*(arg+i)) )
5798 return FALSE; //Not Hex value;
5800 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
5801 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
5802 CipherAlg = CIPHER_WEP64;
5803 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
5805 case 13: //wep 104 Ascii type
5806 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
5807 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
5808 CipherAlg = CIPHER_WEP128;
5809 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
5811 case 26: //wep 104 Hex type
5812 for(i=0; i < KeyLen; i++)
5814 if( !isxdigit(*(arg+i)) )
5815 return FALSE; //Not Hex value;
5817 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
5818 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
5819 CipherAlg = CIPHER_WEP128;
5820 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
5822 default: //Invalid argument
5823 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::Invalid argument (=%s)\n", arg));
5827 pAdapter->SharedKey[BSS0][0].CipherAlg = CipherAlg;
5829 // Set keys (into ASIC)
5830 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5832 else // Old WEP stuff
5834 AsicAddSharedKeyEntry(pAdapter,
5837 pAdapter->SharedKey[BSS0][0].CipherAlg,
5838 pAdapter->SharedKey[BSS0][0].Key,
5846 ==========================================================================
5851 TRUE if all parameters are OK, FALSE otherwise
5852 ==========================================================================
5855 IN PRTMP_ADAPTER pAdapter,
5860 UCHAR CipherAlg=CIPHER_WEP64;
5862 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5863 return TRUE; // do nothing
5865 KeyLen = strlen(arg);
5869 case 5: //wep 40 Ascii type
5870 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
5871 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
5872 CipherAlg = CIPHER_WEP64;
5873 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
5875 case 10: //wep 40 Hex type
5876 for(i=0; i < KeyLen; i++)
5878 if( !isxdigit(*(arg+i)) )
5879 return FALSE; //Not Hex value;
5881 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
5882 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
5883 CipherAlg = CIPHER_WEP64;
5884 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
5886 case 13: //wep 104 Ascii type
5887 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
5888 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
5889 CipherAlg = CIPHER_WEP128;
5890 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
5892 case 26: //wep 104 Hex type
5893 for(i=0; i < KeyLen; i++)
5895 if( !isxdigit(*(arg+i)) )
5896 return FALSE; //Not Hex value;
5898 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
5899 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
5900 CipherAlg = CIPHER_WEP128;
5901 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
5903 default: //Invalid argument
5904 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::Invalid argument (=%s)\n", arg));
5907 pAdapter->SharedKey[BSS0][1].CipherAlg = CipherAlg;
5909 // Set keys (into ASIC)
5910 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5912 else // Old WEP stuff
5914 AsicAddSharedKeyEntry(pAdapter,
5917 pAdapter->SharedKey[BSS0][1].CipherAlg,
5918 pAdapter->SharedKey[BSS0][1].Key,
5926 ==========================================================================
5930 TRUE if all parameters are OK, FALSE otherwise
5931 ==========================================================================
5934 IN PRTMP_ADAPTER pAdapter,
5939 UCHAR CipherAlg=CIPHER_WEP64;
5941 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5942 return TRUE; // do nothing
5944 KeyLen = strlen(arg);
5948 case 5: //wep 40 Ascii type
5949 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
5950 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
5951 CipherAlg = CIPHER_WEP64;
5952 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
5954 case 10: //wep 40 Hex type
5955 for(i=0; i < KeyLen; i++)
5957 if( !isxdigit(*(arg+i)) )
5958 return FALSE; //Not Hex value;
5960 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
5961 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
5962 CipherAlg = CIPHER_WEP64;
5963 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
5965 case 13: //wep 104 Ascii type
5966 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
5967 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
5968 CipherAlg = CIPHER_WEP128;
5969 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
5971 case 26: //wep 104 Hex type
5972 for(i=0; i < KeyLen; i++)
5974 if( !isxdigit(*(arg+i)) )
5975 return FALSE; //Not Hex value;
5977 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
5978 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
5979 CipherAlg = CIPHER_WEP128;
5980 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
5982 default: //Invalid argument
5983 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::Invalid argument (=%s)\n", arg));
5986 pAdapter->SharedKey[BSS0][2].CipherAlg = CipherAlg;
5988 // Set keys (into ASIC)
5989 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5991 else // Old WEP stuff
5993 AsicAddSharedKeyEntry(pAdapter,
5996 pAdapter->SharedKey[BSS0][2].CipherAlg,
5997 pAdapter->SharedKey[BSS0][2].Key,
6005 ==========================================================================
6009 TRUE if all parameters are OK, FALSE otherwise
6010 ==========================================================================
6013 IN PRTMP_ADAPTER pAdapter,
6018 UCHAR CipherAlg=CIPHER_WEP64;
6020 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6021 return TRUE; // do nothing
6023 KeyLen = strlen(arg);
6027 case 5: //wep 40 Ascii type
6028 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
6029 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
6030 CipherAlg = CIPHER_WEP64;
6031 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
6033 case 10: //wep 40 Hex type
6034 for(i=0; i < KeyLen; i++)
6036 if( !isxdigit(*(arg+i)) )
6037 return FALSE; //Not Hex value;
6039 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
6040 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
6041 CipherAlg = CIPHER_WEP64;
6042 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
6044 case 13: //wep 104 Ascii type
6045 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
6046 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
6047 CipherAlg = CIPHER_WEP128;
6048 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
6050 case 26: //wep 104 Hex type
6051 for(i=0; i < KeyLen; i++)
6053 if( !isxdigit(*(arg+i)) )
6054 return FALSE; //Not Hex value;
6056 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
6057 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
6058 CipherAlg = CIPHER_WEP128;
6059 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
6061 default: //Invalid argument
6062 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::Invalid argument (=%s)\n", arg));
6065 pAdapter->SharedKey[BSS0][3].CipherAlg = CipherAlg;
6067 // Set keys (into ASIC)
6068 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6070 else // Old WEP stuff
6072 AsicAddSharedKeyEntry(pAdapter,
6075 pAdapter->SharedKey[BSS0][3].CipherAlg,
6076 pAdapter->SharedKey[BSS0][3].Key,
6085 ==========================================================================
6089 TRUE if all parameters are OK, FALSE otherwise
6090 ==========================================================================
6092 INT Set_WPAPSK_Proc(
6093 IN PRTMP_ADAPTER pAdapter,
6096 UCHAR keyMaterial[40];
6098 if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
6099 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
6100 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
6102 return TRUE; // do nothing
6104 DBGPRINT(RT_DEBUG_TRACE, ("Set_WPAPSK_Proc::(WPAPSK=%s)\n", arg));
6106 NdisZeroMemory(keyMaterial, 40);
6108 if ((strlen(arg) < 8) || (strlen(arg) > 64))
6110 DBGPRINT(RT_DEBUG_TRACE, ("Set failed!!(WPAPSK=%s), WPAPSK key-string required 8 ~ 64 characters \n", arg));
6114 if (strlen(arg) == 64)
6116 AtoH(arg, keyMaterial, 32);
6117 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
6122 PasswordHash((char *)arg, pAdapter->MlmeAux.Ssid, pAdapter->MlmeAux.SsidLen, keyMaterial);
6123 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
6128 if(pAdapter->StaCfg.BssType == BSS_ADHOC &&
6129 pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
6131 pAdapter->StaCfg.WpaState = SS_NOTUSE;
6135 // Start STA supplicant state machine
6136 pAdapter->StaCfg.WpaState = SS_START;
6143 ==========================================================================
6145 Set Power Saving mode
6147 TRUE if all parameters are OK, FALSE otherwise
6148 ==========================================================================
6150 INT Set_PSMode_Proc(
6151 IN PRTMP_ADAPTER pAdapter,
6154 if (pAdapter->StaCfg.BssType == BSS_INFRA)
6156 if ((strcmp(arg, "Max_PSP") == 0) ||
6157 (strcmp(arg, "max_psp") == 0) ||
6158 (strcmp(arg, "MAX_PSP") == 0))
6160 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6161 // to exclude certain situations.
6162 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6163 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeMAX_PSP;
6164 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeMAX_PSP;
6165 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6166 pAdapter->StaCfg.DefaultListenCount = 5;
6169 else if ((strcmp(arg, "Fast_PSP") == 0) ||
6170 (strcmp(arg, "fast_psp") == 0) ||
6171 (strcmp(arg, "FAST_PSP") == 0))
6173 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6174 // to exclude certain situations.
6175 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6176 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6177 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeFast_PSP;
6178 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeFast_PSP;
6179 pAdapter->StaCfg.DefaultListenCount = 3;
6181 else if ((strcmp(arg, "Legacy_PSP") == 0) ||
6182 (strcmp(arg, "legacy_psp") == 0) ||
6183 (strcmp(arg, "LEGACY_PSP") == 0))
6185 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6186 // to exclude certain situations.
6187 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6188 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6189 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeLegacy_PSP;
6190 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeLegacy_PSP;
6191 pAdapter->StaCfg.DefaultListenCount = 3;
6195 //Default Ndis802_11PowerModeCAM
6196 // clear PSM bit immediately
6197 MlmeSetPsmBit(pAdapter, PWR_ACTIVE);
6198 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6199 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6200 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
6201 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
6204 DBGPRINT(RT_DEBUG_TRACE, ("Set_PSMode_Proc::(PSMode=%ld)\n", pAdapter->StaCfg.WindowsPowerMode));
6214 ==========================================================================
6216 Set WpaSupport flag.
6218 0: Driver ignore wpa_supplicant.
6219 1: wpa_supplicant initiates scanning and AP selection.
6220 2: driver takes care of scanning, AP selection, and IEEE 802.11 association parameters.
6222 TRUE if all parameters are OK, FALSE otherwise
6223 ==========================================================================
6225 INT Set_Wpa_Support(
6226 IN PRTMP_ADAPTER pAd,
6230 if ( simple_strtol(arg, 0, 10) == 0)
6231 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
6232 else if ( simple_strtol(arg, 0, 10) == 1)
6233 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE;
6234 else if ( simple_strtol(arg, 0, 10) == 2)
6235 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE_WITH_WEB_UI;
6237 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
6239 DBGPRINT(RT_DEBUG_TRACE, ("Set_Wpa_Support::(WpaSupplicantUP=%d)\n", pAd->StaCfg.WpaSupplicantUP));
6246 ==========================================================================
6250 pAdapter Pointer to our adapter
6251 wrq Pointer to the ioctl argument
6258 1.) iwpriv ra0 mac 0 ==> read MAC where Addr=0x0
6259 2.) iwpriv ra0 mac 0=12 ==> write MAC where Addr=0x0, value=12
6260 ==========================================================================
6263 IN PRTMP_ADAPTER pAdapter,
6264 IN struct iwreq *wrq)
6272 UCHAR temp[16], temp2[16];
6273 UINT32 macValue = 0;
6276 BOOLEAN bIsPrintAllMAC = FALSE;
6279 memset(msg, 0x00, 1024);
6280 if (wrq->u.data.length > 1) //No parameters.
6282 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6285 //Parsing Read or Write
6290 if ((value = rtstrchr(this_char, '=')) != NULL)
6293 if (!value || !*value)
6296 if(strlen(this_char) > 4)
6299 j = strlen(this_char);
6302 if(this_char[j] > 'f' || this_char[j] < '0')
6307 k = j = strlen(this_char);
6310 this_char[4-k+j] = this_char[j];
6314 this_char[3-k++]='0';
6317 if(strlen(this_char) == 4)
6319 AtoH(this_char, temp, 2);
6320 macAddr = *temp*256 + temp[1];
6321 if (macAddr < 0xFFFF)
6323 RTMP_IO_READ32(pAdapter, macAddr, &macValue);
6324 DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%lx, MacValue=%x\n", macAddr, macValue));
6325 sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr , macValue);
6329 {//Invalid parametes, so default printk all bbp
6332 {//Invalid parametes, so default printk all mac
6333 bIsPrintAllMAC = TRUE;
6341 memcpy(&temp2, value, strlen(value));
6342 temp2[strlen(value)] = '\0';
6345 if((strlen(this_char) > 4) || strlen(temp2) > 8)
6348 j = strlen(this_char);
6351 if(this_char[j] > 'f' || this_char[j] < '0')
6358 if(temp2[j] > 'f' || temp2[j] < '0')
6363 k = j = strlen(this_char);
6366 this_char[4-k+j] = this_char[j];
6370 this_char[3-k++]='0';
6374 k = j = strlen(temp2);
6377 temp2[8-k+j] = temp2[j];
6385 AtoH(this_char, temp, 2);
6386 macAddr = *temp*256 + temp[1];
6388 AtoH(temp2, temp, 4);
6389 macValue = *temp*256*256*256 + temp[1]*256*256 + temp[2]*256 + temp[3];
6392 if (macAddr == (HW_DEBUG_SETTING_BASE + 4))
6394 // 0x2bf4: byte0 non-zero: enable R17 tuning, 0: disable R17 tuning
6395 if (macValue & 0x000000ff)
6397 pAdapter->BbpTuning.bEnable = TRUE;
6398 DBGPRINT(RT_DEBUG_TRACE,("turn on R17 tuning\n"));
6403 pAdapter->BbpTuning.bEnable = FALSE;
6404 R66 = 0x26 + GET_LNA_GAIN(pAdapter);
6405 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R66, (0x26 + GET_LNA_GAIN(pAdapter)));
6406 DBGPRINT(RT_DEBUG_TRACE,("turn off R17 tuning, restore to 0x%02x\n", R66));
6411 DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%02lx, MacValue=0x%x\n", macAddr, macValue));
6413 RTMP_IO_WRITE32(pAdapter, macAddr, macValue);
6414 sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr, macValue);
6420 bIsPrintAllMAC = TRUE;
6426 struct file *file_w;
6427 PCHAR fileName = "MacDump.txt";
6428 mm_segment_t orig_fs;
6434 file_w = filp_open(fileName, O_WRONLY|O_CREAT, 0);
6437 DBGPRINT(RT_DEBUG_TRACE, ("-->2) %s: Error %ld opening %s\n", __func__, -PTR_ERR(file_w), fileName));
6441 if (file_w->f_op && file_w->f_op->write)
6446 while (macAddr <= 0x1800)
6448 RTMP_IO_READ32(pAdapter, macAddr, &macValue);
6449 sprintf(msg, "%08lx = %08X\n", macAddr, macValue);
6451 // write data to file
6452 file_w->f_op->write(file_w, msg, strlen(msg), &file_w->f_pos);
6457 sprintf(msg, "\nDump all MAC values to %s\n", fileName);
6459 filp_close(file_w, NULL);
6464 if(strlen(msg) == 1)
6465 sprintf(msg+strlen(msg), "===>Error command format!");
6467 // Copy the information into the user buffer
6468 wrq->u.data.length = strlen(msg);
6469 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6471 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlMAC\n\n"));
6475 ==========================================================================
6479 pAdapter Pointer to our adapter
6480 wrq Pointer to the ioctl argument
6487 1.) iwpriv ra0 e2p 0 ==> read E2PROM where Addr=0x0
6488 2.) iwpriv ra0 e2p 0=1234 ==> write E2PROM where Addr=0x0, value=1234
6489 ==========================================================================
6491 VOID RTMPIoctlE2PROM(
6492 IN PRTMP_ADAPTER pAdapter,
6493 IN struct iwreq *wrq)
6501 UCHAR temp[16], temp2[16];
6505 BOOLEAN bIsPrintAllE2P = FALSE;
6508 memset(msg, 0x00, 1024);
6509 if (wrq->u.data.length > 1) //No parameters.
6511 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6514 //Parsing Read or Write
6521 if ((value = rtstrchr(this_char, '=')) != NULL)
6524 if (!value || !*value)
6528 if(strlen(this_char) > 4)
6531 j = strlen(this_char);
6534 if(this_char[j] > 'f' || this_char[j] < '0')
6539 k = j = strlen(this_char);
6542 this_char[4-k+j] = this_char[j];
6546 this_char[3-k++]='0';
6549 if(strlen(this_char) == 4)
6551 AtoH(this_char, temp, 2);
6552 eepAddr = *temp*256 + temp[1];
6553 if (eepAddr < 0xFFFF)
6555 RT28xx_EEPROM_READ16(pAdapter, eepAddr, eepValue);
6556 sprintf(msg+strlen(msg), "[0x%04X]:0x%04X ", eepAddr , eepValue);
6559 {//Invalid parametes, so default printk all bbp
6561 bIsPrintAllE2P = TRUE;
6569 memcpy(&temp2, value, strlen(value));
6570 temp2[strlen(value)] = '\0';
6573 if((strlen(this_char) > 4) || strlen(temp2) > 8)
6576 j = strlen(this_char);
6579 if(this_char[j] > 'f' || this_char[j] < '0')
6585 if(temp2[j] > 'f' || temp2[j] < '0')
6590 k = j = strlen(this_char);
6593 this_char[4-k+j] = this_char[j];
6597 this_char[3-k++]='0';
6601 k = j = strlen(temp2);
6604 temp2[4-k+j] = temp2[j];
6611 AtoH(this_char, temp, 2);
6612 eepAddr = *temp*256 + temp[1];
6614 AtoH(temp2, temp, 2);
6615 eepValue = *temp*256 + temp[1];
6617 RT28xx_EEPROM_WRITE16(pAdapter, eepAddr, eepValue);
6618 sprintf(msg+strlen(msg), "[0x%02X]:%02X ", eepAddr, eepValue);
6623 bIsPrintAllE2P = TRUE;
6629 struct file *file_w;
6630 PCHAR fileName = "EEPROMDump.txt";
6631 mm_segment_t orig_fs;
6637 file_w = filp_open(fileName, O_WRONLY|O_CREAT, 0);
6640 DBGPRINT(RT_DEBUG_TRACE, ("-->2) %s: Error %ld opening %s\n", __func__, -PTR_ERR(file_w), fileName));
6644 if (file_w->f_op && file_w->f_op->write)
6649 while (eepAddr <= 0xFE)
6651 RT28xx_EEPROM_READ16(pAdapter, eepAddr, eepValue);
6652 sprintf(msg, "%08x = %04x\n", eepAddr , eepValue);
6654 // write data to file
6655 file_w->f_op->write(file_w, msg, strlen(msg), &file_w->f_pos);
6660 sprintf(msg, "\nDump all EEPROM values to %s\n", fileName);
6662 filp_close(file_w, NULL);
6667 if(strlen(msg) == 1)
6668 sprintf(msg+strlen(msg), "===>Error command format!");
6671 // Copy the information into the user buffer
6672 wrq->u.data.length = strlen(msg);
6673 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6675 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlE2PROM\n"));
6679 ==========================================================================
6681 Read / Write RF register
6683 pAdapter Pointer to our adapter
6684 wrq Pointer to the ioctl argument
6691 1.) iwpriv ra0 rf ==> read all RF registers
6692 2.) iwpriv ra0 rf 1 ==> read RF where RegID=1
6693 3.) iwpriv ra0 rf 1=10 ==> write RF R1=0x10
6694 ==========================================================================
6697 IN PRTMP_ADAPTER pAdapter,
6698 IN struct iwreq *wrq)
6708 BOOLEAN bIsPrintAllRF = FALSE;
6711 memset(msg, 0x00, 2048);
6712 if (wrq->u.data.length > 1) //No parameters.
6714 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6717 //Parsing Read or Write
6722 if ((value = strchr(this_char, '=')) != NULL)
6725 if (!value || !*value)
6727 if (sscanf(this_char, "%d", &(rfId)) == 1)
6731 // In RT2860 ATE mode, we do not load 8051 firmware.
6732 //We must access RF directly.
6733 // For RT2870 ATE mode, ATE_RF_IO_WRITE8(/READ8)_BY_REG_ID are redefined.
6734 // according to Andy, Gary, David require.
6735 // the command rf shall read rf register directly for dubug.
6736 // BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
6737 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
6739 sprintf(msg+strlen(msg), "R%02d[0x%02x]:%02X ", rfId, rfId*2, regRF);
6742 {//Invalid parametes, so default printk all RF
6743 bIsPrintAllRF = TRUE;
6748 { //Invalid parametes, so default printk all RF
6749 bIsPrintAllRF = TRUE;
6755 if ((sscanf(this_char, "%d", &(rfId)) == 1) && (sscanf(value, "%lx", &(rfValue)) == 1))
6759 // In RT2860 ATE mode, we do not load 8051 firmware.
6760 // We should access RF registers directly.
6761 // For RT2870 ATE mode, ATE_RF_IO_WRITE8/READ8_BY_REG_ID are redefined.
6763 // according to Andy, Gary, David require.
6764 // the command RF shall read/write RF register directly for dubug.
6765 //BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
6766 //BBP_IO_WRITE8_BY_REG_ID(pAdapter, (UCHAR)bbpId,(UCHAR) bbpValue);
6767 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
6768 RT30xxWriteRFRegister(pAdapter, (UCHAR)rfId,(UCHAR) rfValue);
6769 //Read it back for showing
6770 //BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
6771 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
6772 sprintf(msg+strlen(msg), "R%02d[0x%02X]:%02X\n", rfId, rfId*2, regRF);
6776 {//Invalid parametes, so default printk all RF
6777 bIsPrintAllRF = TRUE;
6781 { //Invalid parametes, so default printk all RF
6782 bIsPrintAllRF = TRUE;
6787 bIsPrintAllRF = TRUE;
6791 memset(msg, 0x00, 2048);
6793 for (rfId = 0; rfId <= 31; rfId++)
6795 // according to Andy, Gary, David require.
6796 // the command RF shall read/write RF register directly for dubug.
6797 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
6798 sprintf(msg+strlen(msg), "%03d = %02X\n", rfId, regRF);
6800 // Copy the information into the user buffer
6801 DBGPRINT(RT_DEBUG_TRACE, ("strlen(msg)=%d\n", (UINT32)strlen(msg)));
6802 wrq->u.data.length = strlen(msg);
6803 if (copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length))
6805 DBGPRINT(RT_DEBUG_TRACE, ("%s: copy_to_user() fail\n", __func__));
6810 if(strlen(msg) == 1)
6811 sprintf(msg+strlen(msg), "===>Error command format!");
6813 DBGPRINT(RT_DEBUG_TRACE, ("copy to user [msg=%s]\n", msg));
6814 // Copy the information into the user buffer
6815 DBGPRINT(RT_DEBUG_TRACE, ("strlen(msg) =%d\n", (UINT32)strlen(msg)));
6817 // Copy the information into the user buffer
6818 wrq->u.data.length = strlen(msg);
6819 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6822 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlRF\n\n"));
6830 INT Set_TGnWifiTest_Proc(
6831 IN PRTMP_ADAPTER pAd,
6834 if (simple_strtol(arg, 0, 10) == 0)
6835 pAd->StaCfg.bTGnWifiTest = FALSE;
6837 pAd->StaCfg.bTGnWifiTest = TRUE;
6839 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_TGnWifiTest_Proc::(bTGnWifiTest=%d)\n", pAd->StaCfg.bTGnWifiTest));
6843 INT Set_LongRetryLimit_Proc(
6844 IN PRTMP_ADAPTER pAdapter,
6847 TX_RTY_CFG_STRUC tx_rty_cfg;
6848 UCHAR LongRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
6850 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
6851 tx_rty_cfg.field.LongRtyLimit = LongRetryLimit;
6852 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
6853 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_LongRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
6857 INT Set_ShortRetryLimit_Proc(
6858 IN PRTMP_ADAPTER pAdapter,
6861 TX_RTY_CFG_STRUC tx_rty_cfg;
6862 UCHAR ShortRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
6864 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
6865 tx_rty_cfg.field.ShortRtyLimit = ShortRetryLimit;
6866 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
6867 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_ShortRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
6871 #if !defined(RT2860) && !defined(RT30xx)
6872 INT Show_Adhoc_MacTable_Proc(
6873 IN PRTMP_ADAPTER pAd,
6878 sprintf(extra, "\n");
6880 sprintf(extra + strlen(extra), "HT Operating Mode : %d\n", pAd->CommonCfg.AddHTInfo.AddHtInfo2.OperaionMode);
6882 sprintf(extra + strlen(extra), "\n%-19s%-4s%-4s%-7s%-7s%-7s%-10s%-6s%-6s%-6s%-6s\n",
6883 "MAC", "AID", "BSS", "RSSI0", "RSSI1", "RSSI2", "PhMd", "BW", "MCS", "SGI", "STBC");
6885 for (i=1; i<MAX_LEN_OF_MAC_TABLE; i++)
6887 PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
6889 if (strlen(extra) > (IW_PRIV_SIZE_MASK - 30))
6891 if ((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
6893 sprintf(extra + strlen(extra), "%02X:%02X:%02X:%02X:%02X:%02X ",
6894 pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
6895 pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5]);
6896 sprintf(extra + strlen(extra), "%-4d", (int)pEntry->Aid);
6897 sprintf(extra + strlen(extra), "%-4d", (int)pEntry->apidx);
6898 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi0);
6899 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi1);
6900 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi2);
6901 sprintf(extra + strlen(extra), "%-10s", GetPhyMode(pEntry->HTPhyMode.field.MODE));
6902 sprintf(extra + strlen(extra), "%-6s", GetBW(pEntry->HTPhyMode.field.BW));
6903 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.MCS);
6904 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.ShortGI);
6905 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.STBC);
6906 sprintf(extra + strlen(extra), "%-10d, %d, %d%%\n", pEntry->DebugFIFOCount, pEntry->DebugTxCount,
6907 (pEntry->DebugTxCount) ? ((pEntry->DebugTxCount-pEntry->DebugFIFOCount)*100/pEntry->DebugTxCount) : 0);
6908 sprintf(extra, "%s\n", extra);