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;
534 strncpy(name, RT28xx_CHIP_NAME " Wireless", IFNAMSIZ);
538 int rt_ioctl_siwfreq(struct net_device *dev,
539 struct iw_request_info *info,
540 struct iw_freq *freq, char *extra)
542 PRTMP_ADAPTER pAdapter = dev->ml_priv;
545 //check if the interface is down
546 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
548 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
556 if((freq->e == 0) && (freq->m <= 1000))
557 chan = freq->m; // Setting by channel number
559 MAP_KHZ_TO_CHANNEL_ID( (freq->m /100) , chan); // Setting by frequency - search the table , like 2.412G, 2.422G,
561 if (ChannelSanity(pAdapter, chan) == TRUE)
563 pAdapter->CommonCfg.Channel = chan;
564 DBGPRINT(RT_DEBUG_ERROR, ("==>rt_ioctl_siwfreq::SIOCSIWFREQ[cmd=0x%x] (Channel=%d)\n", SIOCSIWFREQ, pAdapter->CommonCfg.Channel));
571 int rt_ioctl_giwfreq(struct net_device *dev,
572 struct iw_request_info *info,
573 struct iw_freq *freq, char *extra)
575 VIRTUAL_ADAPTER *pVirtualAd = NULL;
577 PRTMP_ADAPTER pAdapter = NULL;
580 PRTMP_ADAPTER pAdapter;
585 if (dev->priv_flags == INT_MAIN)
587 pAdapter = dev->ml_priv;
591 pVirtualAd = dev->ml_priv;
593 if (pVirtualAd && pVirtualAd->RtmpDev)
595 pAdapter = pVirtualAd->RtmpDev->ml_priv;
598 if (pAdapter == NULL)
600 /* if 1st open fail, pAd will be free;
601 So the net_dev->ml_priv will be NULL in 2rd open */
605 ch = pAdapter->CommonCfg.Channel;
607 DBGPRINT(RT_DEBUG_TRACE,("==>rt_ioctl_giwfreq %d\n", ch));
609 MAP_CHANNEL_ID_TO_KHZ(ch, m);
615 int rt_ioctl_siwmode(struct net_device *dev,
616 struct iw_request_info *info,
617 __u32 *mode, char *extra)
619 PRTMP_ADAPTER pAdapter = dev->ml_priv;
621 //check if the interface is down
622 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
624 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
631 Set_NetworkType_Proc(pAdapter, "Adhoc");
634 Set_NetworkType_Proc(pAdapter, "Infra");
636 case IW_MODE_MONITOR:
637 Set_NetworkType_Proc(pAdapter, "Monitor");
640 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_siwmode::SIOCSIWMODE (unknown %d)\n", *mode));
644 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
645 pAdapter->StaCfg.WpaState = SS_NOTUSE;
650 int rt_ioctl_giwmode(struct net_device *dev,
651 struct iw_request_info *info,
652 __u32 *mode, char *extra)
655 PRTMP_ADAPTER pAdapter = NULL;
656 VIRTUAL_ADAPTER *pVirtualAd = NULL;
658 if (dev->priv_flags == INT_MAIN)
660 pAdapter = dev->ml_priv;
664 pVirtualAd = dev->ml_priv;
665 if (pVirtualAd && pVirtualAd->RtmpDev)
666 pAdapter = pVirtualAd->RtmpDev->ml_priv;
669 if (pAdapter == NULL)
671 /* if 1st open fail, pAd will be free;
672 So the net_dev->ml_priv will be NULL in 2rd open */
677 PRTMP_ADAPTER pAdapter = dev->ml_priv;
680 if (ADHOC_ON(pAdapter))
681 *mode = IW_MODE_ADHOC;
682 else if (INFRA_ON(pAdapter))
683 *mode = IW_MODE_INFRA;
684 else if (MONITOR_ON(pAdapter))
686 *mode = IW_MODE_MONITOR;
689 *mode = IW_MODE_AUTO;
691 DBGPRINT(RT_DEBUG_TRACE, ("==>rt_ioctl_giwmode(mode=%d)\n", *mode));
695 int rt_ioctl_siwsens(struct net_device *dev,
696 struct iw_request_info *info,
697 char *name, char *extra)
699 PRTMP_ADAPTER pAdapter = dev->ml_priv;
701 //check if the interface is down
702 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
704 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
711 int rt_ioctl_giwsens(struct net_device *dev,
712 struct iw_request_info *info,
713 char *name, char *extra)
718 int rt_ioctl_giwrange(struct net_device *dev,
719 struct iw_request_info *info,
720 struct iw_point *data, char *extra)
723 PRTMP_ADAPTER pAdapter = NULL;
724 VIRTUAL_ADAPTER *pVirtualAd = NULL;
727 PRTMP_ADAPTER pAdapter = dev->ml_priv;
729 struct iw_range *range = (struct iw_range *) extra;
734 if (dev->priv_flags == INT_MAIN)
736 pAdapter = dev->ml_priv;
740 pVirtualAd = dev->ml_priv;
741 if (pVirtualAd && pVirtualAd->RtmpDev)
742 pAdapter = pVirtualAd->RtmpDev->ml_priv;
745 if (pAdapter == NULL)
747 /* if 1st open fail, pAd will be free;
748 So the net_dev->ml_priv will be NULL in 2rd open */
753 DBGPRINT(RT_DEBUG_TRACE ,("===>rt_ioctl_giwrange\n"));
754 data->length = sizeof(struct iw_range);
755 memset(range, 0, sizeof(struct iw_range));
757 range->txpower_capa = IW_TXPOW_DBM;
759 if (INFRA_ON(pAdapter)||ADHOC_ON(pAdapter))
761 range->min_pmp = 1 * 1024;
762 range->max_pmp = 65535 * 1024;
763 range->min_pmt = 1 * 1024;
764 range->max_pmt = 1000 * 1024;
765 range->pmp_flags = IW_POWER_PERIOD;
766 range->pmt_flags = IW_POWER_TIMEOUT;
767 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT |
768 IW_POWER_UNICAST_R | IW_POWER_ALL_R;
771 range->we_version_compiled = WIRELESS_EXT;
772 range->we_version_source = 14;
774 range->retry_capa = IW_RETRY_LIMIT;
775 range->retry_flags = IW_RETRY_LIMIT;
776 range->min_retry = 0;
777 range->max_retry = 255;
779 range->num_channels = pAdapter->ChannelListNum;
782 for (i = 1; i <= range->num_channels; i++)
785 range->freq[val].i = pAdapter->ChannelList[i-1].Channel;
786 MAP_CHANNEL_ID_TO_KHZ(pAdapter->ChannelList[i-1].Channel, m);
787 range->freq[val].m = m * 100; /* HZ */
789 range->freq[val].e = 1;
791 if (val == IW_MAX_FREQUENCIES)
794 range->num_frequency = val;
796 range->max_qual.qual = 100; /* what is correct max? This was not
797 * documented exactly. At least
798 * 69 has been observed. */
799 range->max_qual.level = 0; /* dB */
800 range->max_qual.noise = 0; /* dB */
802 /* What would be suitable values for "average/typical" qual? */
803 range->avg_qual.qual = 20;
804 range->avg_qual.level = -60;
805 range->avg_qual.noise = -95;
806 range->sensitivity = 3;
808 range->max_encoding_tokens = NR_WEP_KEYS;
809 range->num_encoding_sizes = 2;
810 range->encoding_size[0] = 5;
811 range->encoding_size[1] = 13;
814 range->max_rts = 2347;
815 range->min_frag = 256;
816 range->max_frag = 2346;
818 #if WIRELESS_EXT > 17
819 /* IW_ENC_CAPA_* bit field */
820 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
821 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
827 int rt_ioctl_siwap(struct net_device *dev,
828 struct iw_request_info *info,
829 struct sockaddr *ap_addr, char *extra)
831 PRTMP_ADAPTER pAdapter = dev->ml_priv;
832 NDIS_802_11_MAC_ADDRESS Bssid;
834 //check if the interface is down
835 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
837 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
841 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
843 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
844 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
847 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
848 // this request, because this request is initiated by NDIS.
849 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
850 // Prevent to connect AP again in STAMlmePeriodicExec
851 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
853 memset(Bssid, 0, MAC_ADDR_LEN);
854 memcpy(Bssid, ap_addr->sa_data, MAC_ADDR_LEN);
855 MlmeEnqueue(pAdapter,
856 MLME_CNTL_STATE_MACHINE,
858 sizeof(NDIS_802_11_MAC_ADDRESS),
861 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCSIWAP %02x:%02x:%02x:%02x:%02x:%02x\n",
862 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
867 int rt_ioctl_giwap(struct net_device *dev,
868 struct iw_request_info *info,
869 struct sockaddr *ap_addr, char *extra)
872 PRTMP_ADAPTER pAdapter = NULL;
873 VIRTUAL_ADAPTER *pVirtualAd = NULL;
875 if (dev->priv_flags == INT_MAIN)
877 pAdapter = dev->ml_priv;
881 pVirtualAd = dev->ml_priv;
882 if (pVirtualAd && pVirtualAd->RtmpDev)
883 pAdapter = pVirtualAd->RtmpDev->ml_priv;
886 if (pAdapter == NULL)
888 /* if 1st open fail, pAd will be free;
889 So the net_dev->ml_priv will be NULL in 2rd open */
894 PRTMP_ADAPTER pAdapter = dev->ml_priv;
897 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
899 ap_addr->sa_family = ARPHRD_ETHER;
900 memcpy(ap_addr->sa_data, &pAdapter->CommonCfg.Bssid, ETH_ALEN);
903 else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
905 ap_addr->sa_family = ARPHRD_ETHER;
906 memcpy(ap_addr->sa_data, &pAdapter->MlmeAux.Bssid, ETH_ALEN);
910 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIWAP(=EMPTY)\n"));
918 * Units are in db above the noise floor. That means the
919 * rssi values reported in the tx/rx descriptors in the
920 * driver are the SNR expressed in db.
922 * If you assume that the noise floor is -95, which is an
923 * excellent assumption 99.5 % of the time, then you can
924 * derive the absolute signal level (i.e. -95 + rssi).
925 * There are some other slight factors to take into account
926 * depending on whether the rssi measurement is from 11b,
927 * 11g, or 11a. These differences are at most 2db and
930 * NB: various calculations are based on the orinoco/wavelan
931 * drivers for compatibility
933 static void set_quality(PRTMP_ADAPTER pAdapter,
934 struct iw_quality *iq,
941 ChannelQuality = 100;
942 else if (rssi >= -80) // between -50 ~ -80dbm
943 ChannelQuality = (__u8)(24 + ((rssi + 80) * 26)/10);
944 else if (rssi >= -90) // between -80 ~ -90dbm
945 ChannelQuality = (__u8)((rssi + 90) * 26)/10;
949 iq->qual = (__u8)ChannelQuality;
951 iq->level = (__u8)(rssi);
952 iq->noise = (pAdapter->BbpWriteLatch[66] > pAdapter->BbpTuning.FalseCcaUpperThreshold) ? ((__u8)pAdapter->BbpTuning.FalseCcaUpperThreshold) : ((__u8) pAdapter->BbpWriteLatch[66]); // noise level (dBm)
953 iq->noise += 256 - 143;
954 iq->updated = pAdapter->iw_stats.qual.updated;
957 int rt_ioctl_iwaplist(struct net_device *dev,
958 struct iw_request_info *info,
959 struct iw_point *data, char *extra)
961 PRTMP_ADAPTER pAdapter = dev->ml_priv;
963 struct sockaddr addr[IW_MAX_AP];
964 struct iw_quality qual[IW_MAX_AP];
967 //check if the interface is down
968 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
970 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
976 for (i = 0; i <IW_MAX_AP ; i++)
978 if (i >= pAdapter->ScanTab.BssNr)
980 addr[i].sa_family = ARPHRD_ETHER;
981 memcpy(addr[i].sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
982 set_quality(pAdapter, &qual[i], pAdapter->ScanTab.BssEntry[i].Rssi);
985 memcpy(extra, &addr, i*sizeof(addr[0]));
986 data->flags = 1; /* signal quality present (sort of) */
987 memcpy(extra + i*sizeof(addr[0]), &qual, i*sizeof(qual[i]));
993 int rt_ioctl_siwscan(struct net_device *dev,
994 struct iw_request_info *info,
995 struct iw_point *data, char *extra)
997 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1000 int Status = NDIS_STATUS_SUCCESS;
1002 //check if the interface is down
1003 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1005 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1009 if (MONITOR_ON(pAdapter))
1011 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
1015 if ((pAdapter->OpMode == OPMODE_STA) && (IDLE_ON(pAdapter))
1016 && (pAdapter->StaCfg.bRadio == TRUE)
1017 && (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_IDLE_RADIO_OFF)))
1019 RT28xxPciAsicRadioOn(pAdapter, GUI_IDLE_POWER_SAVE);
1021 // Check if still radio off.
1022 else if (pAdapter->bPCIclkOff == TRUE)
1025 if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
1027 pAdapter->StaCfg.WpaSupplicantScanCount++;
1030 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
1031 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
1036 if ((pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE) &&
1037 (pAdapter->StaCfg.WpaSupplicantScanCount > 3))
1039 DBGPRINT(RT_DEBUG_TRACE, ("!!! WpaSupplicantScanCount > 3\n"));
1040 Status = NDIS_STATUS_SUCCESS;
1044 if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
1045 ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
1046 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) &&
1047 (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
1049 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
1050 Status = NDIS_STATUS_SUCCESS;
1054 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
1056 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
1057 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
1060 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
1061 // this request, because this request is initiated by NDIS.
1062 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
1063 // Reset allowed scan retries
1064 pAdapter->StaCfg.ScanCnt = 0;
1065 pAdapter->StaCfg.LastScanTime = Now;
1067 MlmeEnqueue(pAdapter,
1068 MLME_CNTL_STATE_MACHINE,
1069 OID_802_11_BSSID_LIST_SCAN,
1073 Status = NDIS_STATUS_SUCCESS;
1074 RT28XX_MLME_HANDLER(pAdapter);
1079 int rt_ioctl_giwscan(struct net_device *dev,
1080 struct iw_request_info *info,
1081 struct iw_point *data, char *extra)
1084 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1086 char *current_ev = extra, *previous_ev = extra;
1088 char *current_val, custom[MAX_CUSTOM_LEN] = {0};
1091 #endif // IWEVGENIE //
1092 struct iw_event iwe;
1094 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
1097 * Still scanning, indicate the caller should try again.
1102 if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
1104 pAdapter->StaCfg.WpaSupplicantScanCount = 0;
1107 if (pAdapter->ScanTab.BssNr == 0)
1113 #if WIRELESS_EXT >= 17
1114 if (data->length > 0)
1115 end_buf = extra + data->length;
1117 end_buf = extra + IW_SCAN_MAX_DATA;
1119 end_buf = extra + IW_SCAN_MAX_DATA;
1122 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
1124 if (current_ev >= end_buf)
1126 #if WIRELESS_EXT >= 17
1134 //================================
1135 memset(&iwe, 0, sizeof(iwe));
1136 iwe.cmd = SIOCGIWAP;
1137 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1138 memcpy(iwe.u.ap_addr.sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, ETH_ALEN);
1140 previous_ev = current_ev;
1141 current_ev = iwe_stream_add_event(info, current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);
1143 if (current_ev == previous_ev)
1144 #if WIRELESS_EXT >= 17
1152 it will show scanned AP's WirelessMode .
1161 memset(&iwe, 0, sizeof(iwe));
1162 iwe.cmd = SIOCGIWNAME;
1166 PBSS_ENTRY pBssEntry=&pAdapter->ScanTab.BssEntry[i];
1167 BOOLEAN isGonly=FALSE;
1170 if (pBssEntry->Channel>14)
1172 if (pBssEntry->HtCapabilityLen!=0)
1173 strcpy(iwe.u.name,"802.11a/n");
1175 strcpy(iwe.u.name,"802.11a");
1180 if one of non B mode rate is set supported rate . it mean G only.
1182 for (rateCnt=0;rateCnt<pBssEntry->SupRateLen;rateCnt++)
1185 6Mbps(140) 9Mbps(146) and >=12Mbps(152) are supported rate , it mean G only.
1187 if (pBssEntry->SupRate[rateCnt]==140 || pBssEntry->SupRate[rateCnt]==146 || pBssEntry->SupRate[rateCnt]>=152)
1191 for (rateCnt=0;rateCnt<pBssEntry->ExtRateLen;rateCnt++)
1193 if (pBssEntry->ExtRate[rateCnt]==140 || pBssEntry->ExtRate[rateCnt]==146 || pBssEntry->ExtRate[rateCnt]>=152)
1198 if (pBssEntry->HtCapabilityLen!=0)
1201 strcpy(iwe.u.name,"802.11g/n");
1203 strcpy(iwe.u.name,"802.11b/g/n");
1208 strcpy(iwe.u.name,"802.11g");
1211 if (pBssEntry->SupRateLen==4 && pBssEntry->ExtRateLen==0)
1212 strcpy(iwe.u.name,"802.11b");
1214 strcpy(iwe.u.name,"802.11b/g");
1220 previous_ev = current_ev;
1221 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
1223 if (current_ev == previous_ev)
1224 #if WIRELESS_EXT >= 17
1231 //================================
1232 memset(&iwe, 0, sizeof(iwe));
1233 iwe.cmd = SIOCGIWESSID;
1234 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].SsidLen;
1235 iwe.u.data.flags = 1;
1237 previous_ev = current_ev;
1238 current_ev = iwe_stream_add_point(info, current_ev,end_buf, &iwe, pAdapter->ScanTab.BssEntry[i].Ssid);
1239 if (current_ev == previous_ev)
1240 #if WIRELESS_EXT >= 17
1247 //================================
1248 memset(&iwe, 0, sizeof(iwe));
1249 iwe.cmd = SIOCGIWMODE;
1250 if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11IBSS)
1252 iwe.u.mode = IW_MODE_ADHOC;
1254 else if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11Infrastructure)
1256 iwe.u.mode = IW_MODE_INFRA;
1260 iwe.u.mode = IW_MODE_AUTO;
1262 iwe.len = IW_EV_UINT_LEN;
1264 previous_ev = current_ev;
1265 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
1266 if (current_ev == previous_ev)
1267 #if WIRELESS_EXT >= 17
1273 //Channel and Frequency
1274 //================================
1275 memset(&iwe, 0, sizeof(iwe));
1276 iwe.cmd = SIOCGIWFREQ;
1277 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
1278 iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
1280 iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
1284 previous_ev = current_ev;
1285 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
1286 if (current_ev == previous_ev)
1287 #if WIRELESS_EXT >= 17
1293 //Add quality statistics
1294 //================================
1295 memset(&iwe, 0, sizeof(iwe));
1297 iwe.u.qual.level = 0;
1298 iwe.u.qual.noise = 0;
1299 set_quality(pAdapter, &iwe.u.qual, pAdapter->ScanTab.BssEntry[i].Rssi);
1300 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
1301 if (current_ev == previous_ev)
1302 #if WIRELESS_EXT >= 17
1309 //================================
1310 memset(&iwe, 0, sizeof(iwe));
1311 iwe.cmd = SIOCGIWENCODE;
1312 if (CAP_IS_PRIVACY_ON (pAdapter->ScanTab.BssEntry[i].CapabilityInfo ))
1313 iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1315 iwe.u.data.flags = IW_ENCODE_DISABLED;
1317 previous_ev = current_ev;
1318 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);
1319 if (current_ev == previous_ev)
1320 #if WIRELESS_EXT >= 17
1327 //================================
1328 if (pAdapter->ScanTab.BssEntry[i].SupRateLen)
1330 UCHAR tmpRate = pAdapter->ScanTab.BssEntry[i].SupRate[pAdapter->ScanTab.BssEntry[i].SupRateLen-1];
1331 memset(&iwe, 0, sizeof(iwe));
1332 iwe.cmd = SIOCGIWRATE;
1333 current_val = current_ev + IW_EV_LCP_LEN;
1334 if (tmpRate == 0x82)
1335 iwe.u.bitrate.value = 1 * 1000000;
1336 else if (tmpRate == 0x84)
1337 iwe.u.bitrate.value = 2 * 1000000;
1338 else if (tmpRate == 0x8B)
1339 iwe.u.bitrate.value = 5.5 * 1000000;
1340 else if (tmpRate == 0x96)
1341 iwe.u.bitrate.value = 11 * 1000000;
1343 iwe.u.bitrate.value = (tmpRate/2) * 1000000;
1345 iwe.u.bitrate.disabled = 0;
1346 current_val = iwe_stream_add_value(info, current_ev,
1347 current_val, end_buf, &iwe,
1350 if((current_val-current_ev)>IW_EV_LCP_LEN)
1351 current_ev = current_val;
1353 #if WIRELESS_EXT >= 17
1362 if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
1364 memset(&iwe, 0, sizeof(iwe));
1365 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1366 memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].WpaIE.IE[0]),
1367 pAdapter->ScanTab.BssEntry[i].WpaIE.IELen);
1368 iwe.cmd = IWEVGENIE;
1369 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].WpaIE.IELen;
1370 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, custom);
1371 if (current_ev == previous_ev)
1372 #if WIRELESS_EXT >= 17
1380 if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
1382 memset(&iwe, 0, sizeof(iwe));
1383 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1384 memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].RsnIE.IE[0]),
1385 pAdapter->ScanTab.BssEntry[i].RsnIE.IELen);
1386 iwe.cmd = IWEVGENIE;
1387 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].RsnIE.IELen;
1388 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, custom);
1389 if (current_ev == previous_ev)
1390 #if WIRELESS_EXT >= 17
1398 //================================
1399 if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
1401 NdisZeroMemory(&iwe, sizeof(iwe));
1402 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1403 iwe.cmd = IWEVCUSTOM;
1404 iwe.u.data.length = (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen * 2) + 7;
1405 NdisMoveMemory(custom, "wpa_ie=", 7);
1406 for (idx = 0; idx < pAdapter->ScanTab.BssEntry[i].WpaIE.IELen; idx++)
1407 sprintf(custom + strlen(custom), "%02x", pAdapter->ScanTab.BssEntry[i].WpaIE.IE[idx]);
1408 previous_ev = current_ev;
1409 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, custom);
1410 if (current_ev == previous_ev)
1411 #if WIRELESS_EXT >= 17
1419 if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
1421 NdisZeroMemory(&iwe, sizeof(iwe));
1422 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1423 iwe.cmd = IWEVCUSTOM;
1424 iwe.u.data.length = (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen * 2) + 7;
1425 NdisMoveMemory(custom, "rsn_ie=", 7);
1426 for (idx = 0; idx < pAdapter->ScanTab.BssEntry[i].RsnIE.IELen; idx++)
1427 sprintf(custom + strlen(custom), "%02x", pAdapter->ScanTab.BssEntry[i].RsnIE.IE[idx]);
1428 previous_ev = current_ev;
1429 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, custom);
1430 if (current_ev == previous_ev)
1431 #if WIRELESS_EXT >= 17
1437 #endif // IWEVGENIE //
1440 data->length = current_ev - extra;
1441 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
1442 DBGPRINT(RT_DEBUG_ERROR ,("===>rt_ioctl_giwscan. %d(%d) BSS returned, data->length = %d\n",i , pAdapter->ScanTab.BssNr, data->length));
1447 int rt_ioctl_siwessid(struct net_device *dev,
1448 struct iw_request_info *info,
1449 struct iw_point *data, char *essid)
1451 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1453 //check if the interface is down
1454 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1456 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1462 PCHAR pSsidString = NULL;
1464 // Includes null character.
1465 if (data->length > (IW_ESSID_MAX_SIZE + 1))
1468 pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
1471 NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
1472 NdisMoveMemory(pSsidString, essid, data->length);
1473 if (Set_SSID_Proc(pAdapter, pSsidString) == FALSE)
1482 if (Set_SSID_Proc(pAdapter, "") == FALSE)
1488 int rt_ioctl_giwessid(struct net_device *dev,
1489 struct iw_request_info *info,
1490 struct iw_point *data, char *essid)
1493 PRTMP_ADAPTER pAdapter = NULL;
1494 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1496 if (dev->priv_flags == INT_MAIN)
1498 pAdapter = dev->ml_priv;
1502 pVirtualAd = dev->ml_priv;
1503 if (pVirtualAd && pVirtualAd->RtmpDev)
1504 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1507 if (pAdapter == NULL)
1509 /* if 1st open fail, pAd will be free;
1510 So the net_dev->ml_priv will be NULL in 2rd open */
1515 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1519 if (MONITOR_ON(pAdapter))
1525 if (OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED))
1527 DBGPRINT(RT_DEBUG_TRACE ,("MediaState is connected\n"));
1528 data->length = pAdapter->CommonCfg.SsidLen;
1529 memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
1533 else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
1535 data->length = pAdapter->CommonCfg.SsidLen;
1536 memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
1540 {//the ANY ssid was specified
1542 DBGPRINT(RT_DEBUG_TRACE ,("MediaState is not connected, ess\n"));
1549 int rt_ioctl_siwnickn(struct net_device *dev,
1550 struct iw_request_info *info,
1551 struct iw_point *data, char *nickname)
1553 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1555 //check if the interface is down
1556 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1558 DBGPRINT(RT_DEBUG_TRACE ,("INFO::Network is down!\n"));
1562 if (data->length > IW_ESSID_MAX_SIZE)
1565 memset(pAdapter->nickname, 0, IW_ESSID_MAX_SIZE + 1);
1566 memcpy(pAdapter->nickname, nickname, data->length);
1572 int rt_ioctl_giwnickn(struct net_device *dev,
1573 struct iw_request_info *info,
1574 struct iw_point *data, char *nickname)
1577 PRTMP_ADAPTER pAdapter = NULL;
1578 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1580 if (dev->priv_flags == INT_MAIN)
1582 pAdapter = dev->ml_priv;
1586 pVirtualAd = dev->ml_priv;
1587 if (pVirtualAd && pVirtualAd->RtmpDev)
1588 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1591 if (pAdapter == NULL)
1593 /* if 1st open fail, pAd will be free;
1594 So the net_dev->ml_priv will be NULL in 2rd open */
1599 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1602 if (data->length > strlen(pAdapter->nickname) + 1)
1603 data->length = strlen(pAdapter->nickname) + 1;
1604 if (data->length > 0) {
1605 memcpy(nickname, pAdapter->nickname, data->length-1);
1606 nickname[data->length-1] = '\0';
1611 int rt_ioctl_siwrts(struct net_device *dev,
1612 struct iw_request_info *info,
1613 struct iw_param *rts, char *extra)
1615 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1618 //check if the interface is down
1619 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1621 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1626 val = MAX_RTS_THRESHOLD;
1627 else if (rts->value < 0 || rts->value > MAX_RTS_THRESHOLD)
1629 else if (rts->value == 0)
1630 val = MAX_RTS_THRESHOLD;
1634 if (val != pAdapter->CommonCfg.RtsThreshold)
1635 pAdapter->CommonCfg.RtsThreshold = val;
1640 int rt_ioctl_giwrts(struct net_device *dev,
1641 struct iw_request_info *info,
1642 struct iw_param *rts, char *extra)
1645 PRTMP_ADAPTER pAdapter = NULL;
1646 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1648 if (dev->priv_flags == INT_MAIN)
1650 pAdapter = dev->ml_priv;
1654 pVirtualAd = dev->ml_priv;
1655 if (pVirtualAd && pVirtualAd->RtmpDev)
1656 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1659 if (pAdapter == NULL)
1661 /* if 1st open fail, pAd will be free;
1662 So the net_dev->ml_priv will be NULL in 2rd open */
1667 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1670 //check if the interface is down
1671 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1673 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1677 rts->value = pAdapter->CommonCfg.RtsThreshold;
1678 rts->disabled = (rts->value == MAX_RTS_THRESHOLD);
1684 int rt_ioctl_siwfrag(struct net_device *dev,
1685 struct iw_request_info *info,
1686 struct iw_param *frag, char *extra)
1688 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1691 //check if the interface is down
1692 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1694 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1699 val = MAX_FRAG_THRESHOLD;
1700 else if (frag->value >= MIN_FRAG_THRESHOLD || frag->value <= MAX_FRAG_THRESHOLD)
1701 val = __cpu_to_le16(frag->value & ~0x1); /* even numbers only */
1702 else if (frag->value == 0)
1703 val = MAX_FRAG_THRESHOLD;
1707 pAdapter->CommonCfg.FragmentThreshold = val;
1711 int rt_ioctl_giwfrag(struct net_device *dev,
1712 struct iw_request_info *info,
1713 struct iw_param *frag, char *extra)
1716 PRTMP_ADAPTER pAdapter = NULL;
1717 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1719 if (dev->priv_flags == INT_MAIN)
1721 pAdapter = dev->ml_priv;
1725 pVirtualAd = dev->ml_priv;
1726 if (pVirtualAd && pVirtualAd->RtmpDev)
1727 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1730 if (pAdapter == NULL)
1732 /* if 1st open fail, pAd will be free;
1733 So the net_dev->ml_priv will be NULL in 2rd open */
1738 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1741 //check if the interface is down
1742 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1744 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1748 frag->value = pAdapter->CommonCfg.FragmentThreshold;
1749 frag->disabled = (frag->value == MAX_FRAG_THRESHOLD);
1755 #define MAX_WEP_KEY_SIZE 13
1756 #define MIN_WEP_KEY_SIZE 5
1757 int rt_ioctl_siwencode(struct net_device *dev,
1758 struct iw_request_info *info,
1759 struct iw_point *erq, char *extra)
1761 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1763 //check if the interface is down
1764 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1766 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1770 if ((erq->length == 0) &&
1771 (erq->flags & IW_ENCODE_DISABLED))
1773 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
1774 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
1775 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
1776 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
1777 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1781 else if ((erq->length == 0) &&
1782 (erq->flags & IW_ENCODE_RESTRICTED || erq->flags & IW_ENCODE_OPEN))
1785 else if (erq->flags & IW_ENCODE_RESTRICTED || erq->flags & IW_ENCODE_OPEN)
1788 STA_PORT_SECURED(pAdapter);
1789 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
1790 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
1791 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
1792 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
1793 if (erq->flags & IW_ENCODE_RESTRICTED)
1794 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
1796 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1802 if (erq->length > 0)
1804 int keyIdx = (erq->flags & IW_ENCODE_INDEX) - 1;
1805 /* Check the size of the key */
1806 if (erq->length > MAX_WEP_KEY_SIZE) {
1809 /* Check key index */
1810 if ((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
1812 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::Wrong keyIdx=%d! Using default key instead (%d)\n",
1813 keyIdx, pAdapter->StaCfg.DefaultKeyId));
1816 keyIdx = pAdapter->StaCfg.DefaultKeyId;
1821 pAdapter->StaCfg.DefaultKeyId=keyIdx;
1825 NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
1827 if (erq->length == MAX_WEP_KEY_SIZE)
1829 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
1830 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
1832 else if (erq->length == MIN_WEP_KEY_SIZE)
1834 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
1835 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
1838 /* Disable the key */
1839 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
1841 /* Check if the key is not marked as invalid */
1842 if(!(erq->flags & IW_ENCODE_NOKEY)) {
1843 /* Copy the key in the driver */
1844 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, extra, erq->length);
1849 /* Do we want to just set the transmit key index ? */
1850 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
1851 if ((index >= 0) && (index < 4))
1853 pAdapter->StaCfg.DefaultKeyId = index;
1856 /* Don't complain if only change the mode */
1857 if (!(erq->flags & IW_ENCODE_MODE)) {
1863 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::erq->flags=%x\n",erq->flags));
1864 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::AuthMode=%x\n",pAdapter->StaCfg.AuthMode));
1865 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::DefaultKeyId=%x, KeyLen = %d\n",pAdapter->StaCfg.DefaultKeyId , pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen));
1866 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::WepStatus=%x\n",pAdapter->StaCfg.WepStatus));
1871 rt_ioctl_giwencode(struct net_device *dev,
1872 struct iw_request_info *info,
1873 struct iw_point *erq, char *key)
1876 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1880 PRTMP_ADAPTER pAdapter = NULL;
1881 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1883 if (dev->priv_flags == INT_MAIN)
1885 pAdapter = dev->ml_priv;
1889 pVirtualAd = dev->ml_priv;
1890 if (pVirtualAd && pVirtualAd->RtmpDev)
1891 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1894 if (pAdapter == NULL)
1896 /* if 1st open fail, pAd will be free;
1897 So the net_dev->ml_priv will be NULL in 2rd open */
1902 //check if the interface is down
1903 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1905 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1909 kid = erq->flags & IW_ENCODE_INDEX;
1910 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_giwencode %d\n", erq->flags & IW_ENCODE_INDEX));
1912 if (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled)
1915 erq->flags = IW_ENCODE_DISABLED;
1917 else if ((kid > 0) && (kid <=4))
1920 erq->flags = kid ; /* NB: base 1 */
1921 if (erq->length > pAdapter->SharedKey[BSS0][kid-1].KeyLen)
1922 erq->length = pAdapter->SharedKey[BSS0][kid-1].KeyLen;
1923 memcpy(key, pAdapter->SharedKey[BSS0][kid-1].Key, erq->length);
1924 //if ((kid == pAdapter->PortCfg.DefaultKeyId))
1925 //erq->flags |= IW_ENCODE_ENABLED; /* XXX */
1926 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1927 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1929 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1934 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1935 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1937 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1938 erq->length = pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen;
1939 memcpy(key, pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key, erq->length);
1940 // copy default key ID
1941 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1942 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1944 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1945 erq->flags = pAdapter->StaCfg.DefaultKeyId + 1; /* NB: base 1 */
1946 erq->flags |= IW_ENCODE_ENABLED; /* XXX */
1954 rt_ioctl_setparam(struct net_device *dev, struct iw_request_info *info,
1955 void *w, char *extra)
1957 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1958 PRTMP_ADAPTER pAdapter;
1960 char *this_char = extra;
1964 if (dev->priv_flags == INT_MAIN)
1966 pAdapter = dev->ml_priv;
1970 pVirtualAd = dev->ml_priv;
1971 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1973 pObj = (POS_COOKIE) pAdapter->OS_Cookie;
1975 if (pAdapter == NULL)
1977 /* if 1st open fail, pAd will be free;
1978 So the net_dev->ml_priv will be NULL in 2rd open */
1983 pObj->ioctl_if_type = INT_MAIN;
1984 pObj->ioctl_if = MAIN_MBSSID;
1987 //check if the interface is down
1988 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1990 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1997 if ((value = rtstrchr(this_char, '=')) != NULL)
2003 // reject setting nothing besides ANY ssid(ssidLen=0)
2004 if (!*value && (strcmp(this_char, "SSID") != 0))
2007 for (PRTMP_PRIVATE_SET_PROC = RTMP_PRIVATE_SUPPORT_PROC; PRTMP_PRIVATE_SET_PROC->name; PRTMP_PRIVATE_SET_PROC++)
2009 if (strcmp(this_char, PRTMP_PRIVATE_SET_PROC->name) == 0)
2011 if(!PRTMP_PRIVATE_SET_PROC->set_proc(pAdapter, value))
2012 { //FALSE:Set private failed then return Invalid argument
2015 break; //Exit for loop.
2019 if(PRTMP_PRIVATE_SET_PROC->name == NULL)
2020 { //Not found argument
2022 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_setparam:: (iwpriv) Not Support Set Command [%s=%s]\n", this_char, value));
2030 rt_private_get_statistics(struct net_device *dev, struct iw_request_info *info,
2031 struct iw_point *wrq, char *extra)
2034 PRTMP_ADAPTER pAd = dev->ml_priv;
2042 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2043 sprintf(extra, "\n\n");
2046 sprintf(extra+strlen(extra), "Tx success = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart);
2047 sprintf(extra+strlen(extra), "Tx success without retry = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart - (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
2049 sprintf(extra+strlen(extra), "Tx success after retry = %ld\n", (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
2050 sprintf(extra+strlen(extra), "Tx fail to Rcv ACK after retry = %ld\n", (ULONG)pAd->WlanCounters.FailedCount.QuadPart);
2051 sprintf(extra+strlen(extra), "RTS Success Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSSuccessCount.QuadPart);
2052 sprintf(extra+strlen(extra), "RTS Fail Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSFailureCount.QuadPart);
2054 sprintf(extra+strlen(extra), "Rx success = %ld\n", (ULONG)pAd->WlanCounters.ReceivedFragmentCount.QuadPart);
2055 sprintf(extra+strlen(extra), "Rx with CRC = %ld\n", (ULONG)pAd->WlanCounters.FCSErrorCount.QuadPart);
2056 sprintf(extra+strlen(extra), "Rx drop due to out of resource = %ld\n", (ULONG)pAd->Counters8023.RxNoBuffer);
2057 sprintf(extra+strlen(extra), "Rx duplicate frame = %ld\n", (ULONG)pAd->WlanCounters.FrameDuplicateCount.QuadPart);
2059 sprintf(extra+strlen(extra), "False CCA (one second) = %ld\n", (ULONG)pAd->RalinkCounters.OneSecFalseCCACnt);
2061 sprintf(extra+strlen(extra), "RSSI-A = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi0 - pAd->BbpRssiToDbmDelta));
2062 sprintf(extra+strlen(extra), "RSSI-B (if available) = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi1 - pAd->BbpRssiToDbmDelta));
2063 sprintf(extra+strlen(extra), "RSSI-C (if available) = %ld\n\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi2 - pAd->BbpRssiToDbmDelta));
2065 sprintf(extra+strlen(extra), "WpaSupplicantUP = %d\n\n", pAd->StaCfg.WpaSupplicantUP);
2067 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2068 DBGPRINT(RT_DEBUG_TRACE, ("<== rt_private_get_statistics, wrq->length = %d\n", wrq->length));
2074 IN PRTMP_ADAPTER pAd,
2078 BA_ORI_ENTRY *pOriBAEntry;
2079 BA_REC_ENTRY *pRecBAEntry;
2081 for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
2083 PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
2084 if (((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
2085 || (pEntry->ValidAsWDS) || (pEntry->ValidAsMesh))
2087 sprintf(pOutBuf + strlen(pOutBuf), "\n%02X:%02X:%02X:%02X:%02X:%02X (Aid = %d) (AP) -\n",
2088 pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
2089 pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5], pEntry->Aid);
2091 sprintf(pOutBuf, "%s[Recipient]\n", pOutBuf);
2092 for (j=0; j < NUM_OF_TID; j++)
2094 if (pEntry->BARecWcidArray[j] != 0)
2096 pRecBAEntry =&pAd->BATable.BARecEntry[pEntry->BARecWcidArray[j]];
2097 sprintf(pOutBuf + strlen(pOutBuf), "TID=%d, BAWinSize=%d, LastIndSeq=%d, ReorderingPkts=%d\n", j, pRecBAEntry->BAWinSize, pRecBAEntry->LastIndSeq, pRecBAEntry->list.qlen);
2100 sprintf(pOutBuf, "%s\n", pOutBuf);
2102 sprintf(pOutBuf, "%s[Originator]\n", pOutBuf);
2103 for (j=0; j < NUM_OF_TID; j++)
2105 if (pEntry->BAOriWcidArray[j] != 0)
2107 pOriBAEntry =&pAd->BATable.BAOriEntry[pEntry->BAOriWcidArray[j]];
2108 sprintf(pOutBuf + strlen(pOutBuf), "TID=%d, BAWinSize=%d, StartSeq=%d, CurTxSeq=%d\n", j, pOriBAEntry->BAWinSize, pOriBAEntry->Sequence, pEntry->TxSeq[j]);
2111 sprintf(pOutBuf, "%s\n\n", pOutBuf);
2113 if (strlen(pOutBuf) > (IW_PRIV_SIZE_MASK - 30))
2121 rt_private_show(struct net_device *dev, struct iw_request_info *info,
2122 struct iw_point *wrq, char *extra)
2125 VIRTUAL_ADAPTER *pVirtualAd = NULL;
2128 u32 subcmd = wrq->flags;
2130 if (dev->priv_flags == INT_MAIN)
2134 pVirtualAd = dev->ml_priv;
2135 pAd = pVirtualAd->RtmpDev->ml_priv;
2137 pObj = (POS_COOKIE) pAd->OS_Cookie;
2141 /* if 1st open fail, pAd will be free;
2142 So the net_dev->ml_priv will be NULL in 2rd open */
2151 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2154 pObj->ioctl_if_type = INT_MAIN;
2155 pObj->ioctl_if = MAIN_MBSSID;
2161 case SHOW_CONN_STATUS:
2162 if (MONITOR_ON(pAd))
2164 if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
2165 pAd->CommonCfg.RegTransmitSetting.field.BW)
2166 sprintf(extra, "Monitor Mode(CentralChannel %d)\n", pAd->CommonCfg.CentralChannel);
2168 sprintf(extra, "Monitor Mode(Channel %d)\n", pAd->CommonCfg.Channel);
2172 if (pAd->IndicateMediaState == NdisMediaStateConnected)
2176 sprintf(extra, "Connected(AP: %s[%02X:%02X:%02X:%02X:%02X:%02X])\n",
2177 pAd->CommonCfg.Ssid,
2178 pAd->CommonCfg.Bssid[0],
2179 pAd->CommonCfg.Bssid[1],
2180 pAd->CommonCfg.Bssid[2],
2181 pAd->CommonCfg.Bssid[3],
2182 pAd->CommonCfg.Bssid[4],
2183 pAd->CommonCfg.Bssid[5]);
2184 DBGPRINT(RT_DEBUG_TRACE ,("Ssid=%s ,Ssidlen = %d\n",pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen));
2186 else if (ADHOC_ON(pAd))
2187 sprintf(extra, "Connected\n");
2191 sprintf(extra, "Disconnected\n");
2192 DBGPRINT(RT_DEBUG_TRACE ,("ConnStatus is not connected\n"));
2195 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2197 case SHOW_DRVIER_VERION:
2198 sprintf(extra, "Driver version-%s, %s %s\n", STA_DRIVER_VERSION, __DATE__, __TIME__ );
2199 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2202 getBaInfo(pAd, extra);
2203 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2205 case SHOW_DESC_INFO:
2207 Show_DescInfo_Proc(pAd, NULL);
2208 wrq->length = 0; // 1: size of '\0'
2212 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
2214 sprintf(extra, "Scanning\n");
2215 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2218 pAd->StaCfg.bSwRadio = FALSE;
2219 if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
2221 pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
2222 if (pAd->StaCfg.bRadio == FALSE)
2225 // Update extra information
2226 pAd->ExtraInfo = SW_RADIO_OFF;
2229 sprintf(extra, "Radio Off\n");
2230 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2234 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
2236 sprintf(extra, "Scanning\n");
2237 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2241 pAd->StaCfg.bSwRadio = TRUE;
2242 //if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
2244 pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
2245 if (pAd->StaCfg.bRadio == TRUE)
2248 // Update extra information
2249 pAd->ExtraInfo = EXTRA_INFO_CLEAR;
2252 sprintf(extra, "Radio On\n");
2253 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2256 case SHOW_CFG_VALUE:
2258 Status = RTMPShowCfgValue(pAd, wrq->pointer, extra);
2260 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2263 #if !defined(RT2860) && !defined(RT30xx)
2264 case SHOW_ADHOC_ENTRY_INFO:
2265 Show_Adhoc_MacTable_Proc(pAd, extra);
2266 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2270 DBGPRINT(RT_DEBUG_TRACE, ("%s - unknow subcmd = %d\n", __func__, subcmd));
2278 int rt_ioctl_siwmlme(struct net_device *dev,
2279 struct iw_request_info *info,
2280 union iwreq_data *wrqu,
2283 PRTMP_ADAPTER pAd = dev->ml_priv;
2284 struct iw_mlme *pMlme = (struct iw_mlme *)wrqu->data.pointer;
2285 MLME_QUEUE_ELEM MsgElem;
2286 MLME_DISASSOC_REQ_STRUCT DisAssocReq;
2287 MLME_DEAUTH_REQ_STRUCT DeAuthReq;
2289 DBGPRINT(RT_DEBUG_TRACE, ("====> %s\n", __func__));
2296 #ifdef IW_MLME_DEAUTH
2297 case IW_MLME_DEAUTH:
2298 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DEAUTH\n", __func__));
2299 COPY_MAC_ADDR(DeAuthReq.Addr, pAd->CommonCfg.Bssid);
2300 DeAuthReq.Reason = pMlme->reason_code;
2301 MsgElem.MsgLen = sizeof(MLME_DEAUTH_REQ_STRUCT);
2302 NdisMoveMemory(MsgElem.Msg, &DeAuthReq, sizeof(MLME_DEAUTH_REQ_STRUCT));
2303 MlmeDeauthReqAction(pAd, &MsgElem);
2306 LinkDown(pAd, FALSE);
2307 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
2310 #endif // IW_MLME_DEAUTH //
2311 #ifdef IW_MLME_DISASSOC
2312 case IW_MLME_DISASSOC:
2313 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DISASSOC\n", __func__));
2314 COPY_MAC_ADDR(DisAssocReq.Addr, pAd->CommonCfg.Bssid);
2315 DisAssocReq.Reason = pMlme->reason_code;
2317 MsgElem.Machine = ASSOC_STATE_MACHINE;
2318 MsgElem.MsgType = MT2_MLME_DISASSOC_REQ;
2319 MsgElem.MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
2320 NdisMoveMemory(MsgElem.Msg, &DisAssocReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
2322 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
2323 MlmeDisassocReqAction(pAd, &MsgElem);
2325 #endif // IW_MLME_DISASSOC //
2327 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - Unknow Command\n", __func__));
2333 #endif // SIOCSIWMLME //
2335 #if WIRELESS_EXT > 17
2336 int rt_ioctl_siwauth(struct net_device *dev,
2337 struct iw_request_info *info,
2338 union iwreq_data *wrqu, char *extra)
2340 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2341 struct iw_param *param = &wrqu->param;
2343 //check if the interface is down
2344 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2346 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2349 switch (param->flags & IW_AUTH_INDEX) {
2350 case IW_AUTH_WPA_VERSION:
2351 if (param->value == IW_AUTH_WPA_VERSION_WPA)
2353 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
2354 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
2355 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
2357 else if (param->value == IW_AUTH_WPA_VERSION_WPA2)
2358 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
2360 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __func__, param->value));
2362 case IW_AUTH_CIPHER_PAIRWISE:
2363 if (param->value == IW_AUTH_CIPHER_NONE)
2365 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
2366 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2367 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
2369 else if (param->value == IW_AUTH_CIPHER_WEP40 ||
2370 param->value == IW_AUTH_CIPHER_WEP104)
2372 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
2373 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2374 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
2375 pAdapter->StaCfg.IEEE8021X = FALSE;
2377 else if (param->value == IW_AUTH_CIPHER_TKIP)
2379 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
2380 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2381 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
2383 else if (param->value == IW_AUTH_CIPHER_CCMP)
2385 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
2386 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2387 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
2389 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_PAIRWISE - param->value = %d!\n", __func__, param->value));
2391 case IW_AUTH_CIPHER_GROUP:
2392 if (param->value == IW_AUTH_CIPHER_NONE)
2394 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
2396 else if (param->value == IW_AUTH_CIPHER_WEP40 ||
2397 param->value == IW_AUTH_CIPHER_WEP104)
2399 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
2401 else if (param->value == IW_AUTH_CIPHER_TKIP)
2403 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
2405 else if (param->value == IW_AUTH_CIPHER_CCMP)
2407 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
2409 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_GROUP - param->value = %d!\n", __func__, param->value));
2411 case IW_AUTH_KEY_MGMT:
2412 if (param->value == IW_AUTH_KEY_MGMT_802_1X)
2414 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)
2416 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
2417 pAdapter->StaCfg.IEEE8021X = FALSE;
2419 else if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
2421 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
2422 pAdapter->StaCfg.IEEE8021X = FALSE;
2426 pAdapter->StaCfg.IEEE8021X = TRUE;
2428 else if (param->value == 0)
2430 STA_PORT_SECURED(pAdapter);
2432 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_KEY_MGMT - param->value = %d!\n", __func__, param->value));
2434 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
2436 case IW_AUTH_PRIVACY_INVOKED:
2437 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_PRIVACY_INVOKED - param->value = %d!\n", __func__, param->value));
2439 case IW_AUTH_DROP_UNENCRYPTED:
2440 if (param->value != 0)
2441 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
2444 STA_PORT_SECURED(pAdapter);
2446 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __func__, param->value));
2448 case IW_AUTH_80211_AUTH_ALG:
2449 if (param->value & IW_AUTH_ALG_SHARED_KEY)
2451 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
2453 else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
2455 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
2459 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_80211_AUTH_ALG - param->value = %d!\n", __func__, param->value));
2461 case IW_AUTH_WPA_ENABLED:
2462 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_ENABLED - Driver supports WPA!(param->value = %d)\n", __func__, param->value));
2471 int rt_ioctl_giwauth(struct net_device *dev,
2472 struct iw_request_info *info,
2473 union iwreq_data *wrqu, char *extra)
2475 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2476 struct iw_param *param = &wrqu->param;
2478 //check if the interface is down
2479 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2481 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2485 switch (param->flags & IW_AUTH_INDEX) {
2486 case IW_AUTH_DROP_UNENCRYPTED:
2487 param->value = (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled) ? 0 : 1;
2490 case IW_AUTH_80211_AUTH_ALG:
2491 param->value = (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared) ? IW_AUTH_ALG_SHARED_KEY : IW_AUTH_ALG_OPEN_SYSTEM;
2494 case IW_AUTH_WPA_ENABLED:
2495 param->value = (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) ? 1 : 0;
2501 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_giwauth::param->value = %d!\n", param->value));
2505 void fnSetCipherKey(
2506 IN PRTMP_ADAPTER pAdapter,
2510 IN struct iw_encode_ext *ext)
2513 RTMP_CLEAR_PSFLAG(pAdapter, fRTMP_PS_CAN_GO_SLEEP);
2514 if (RTMP_TEST_PSFLAG(pAdapter, fRTMP_PS_SET_PCI_CLK_OFF_COMMAND))
2516 if (pAdapter->StaCfg.bRadio == FALSE)
2518 RTMP_SET_PSFLAG(pAdapter, fRTMP_PS_CAN_GO_SLEEP);
2521 DBGPRINT(RT_DEBUG_TRACE,("RTMPWPAAddKeyProc1==>\n"));
2522 RTMPPCIeLinkCtrlValueRestore(pAdapter, RESTORE_HALT);
2523 RTMPusecDelay(6000);
2524 pAdapter->bPCIclkOff = FALSE;
2527 NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
2528 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = LEN_TKIP_EK;
2529 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, LEN_TKIP_EK);
2530 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].TxMic, ext->key + LEN_TKIP_EK, LEN_TKIP_TXMICK);
2531 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].RxMic, ext->key + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
2532 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CipherAlg;
2534 // Update group key information to ASIC Shared Key Table
2535 AsicAddSharedKeyEntry(pAdapter,
2538 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2539 pAdapter->SharedKey[BSS0][keyIdx].Key,
2540 pAdapter->SharedKey[BSS0][keyIdx].TxMic,
2541 pAdapter->SharedKey[BSS0][keyIdx].RxMic);
2544 // Update ASIC WCID attribute table and IVEIV table
2545 RTMPAddWcidAttributeEntry(pAdapter,
2548 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2551 // Update ASIC WCID attribute table and IVEIV table
2552 RTMPAddWcidAttributeEntry(pAdapter,
2555 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2556 &pAdapter->MacTab.Content[BSSID_WCID]);
2558 RTMP_SET_PSFLAG(pAdapter, fRTMP_PS_CAN_GO_SLEEP);
2562 int rt_ioctl_siwencodeext(struct net_device *dev,
2563 struct iw_request_info *info,
2564 union iwreq_data *wrqu,
2567 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2568 struct iw_point *encoding = &wrqu->encoding;
2569 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2570 int keyIdx, alg = ext->alg;
2572 //check if the interface is down
2573 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2575 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2579 if (encoding->flags & IW_ENCODE_DISABLED)
2581 keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
2582 // set BSSID wcid entry of the Pair-wise Key table as no-security mode
2583 AsicRemovePairwiseKeyEntry(pAdapter, BSS0, BSSID_WCID);
2584 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
2585 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_NONE;
2586 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)keyIdx);
2587 NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
2588 DBGPRINT(RT_DEBUG_TRACE, ("%s::Remove all keys!(encoding->flags = %x)\n", __func__, encoding->flags));
2592 // Get Key Index and convet to our own defined key index
2593 keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
2594 if((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
2597 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2599 pAdapter->StaCfg.DefaultKeyId = keyIdx;
2600 DBGPRINT(RT_DEBUG_TRACE, ("%s::DefaultKeyId = %d\n", __func__, pAdapter->StaCfg.DefaultKeyId));
2604 case IW_ENCODE_ALG_NONE:
2605 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_NONE\n", __func__));
2607 case IW_ENCODE_ALG_WEP:
2608 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_WEP - ext->key_len = %d, keyIdx = %d\n", __func__, ext->key_len, keyIdx));
2609 if (ext->key_len == MAX_WEP_KEY_SIZE)
2611 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
2612 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
2614 else if (ext->key_len == MIN_WEP_KEY_SIZE)
2616 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
2617 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
2622 NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
2623 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, ext->key_len);
2625 if (pAdapter->StaCfg.GroupCipher == Ndis802_11GroupWEP40Enabled ||
2626 pAdapter->StaCfg.GroupCipher == Ndis802_11GroupWEP104Enabled)
2628 // Set Group key material to Asic
2629 AsicAddSharedKeyEntry(pAdapter, BSS0, keyIdx, pAdapter->SharedKey[BSS0][keyIdx].CipherAlg, pAdapter->SharedKey[BSS0][keyIdx].Key, NULL, NULL);
2631 // Update WCID attribute table and IVEIV table for this group key table
2632 RTMPAddWcidAttributeEntry(pAdapter, BSS0, keyIdx, pAdapter->SharedKey[BSS0][keyIdx].CipherAlg, NULL);
2634 STA_PORT_SECURED(pAdapter);
2636 // Indicate Connected for GUI
2637 pAdapter->IndicateMediaState = NdisMediaStateConnected;
2641 case IW_ENCODE_ALG_TKIP:
2642 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_TKIP - keyIdx = %d, ext->key_len = %d\n", __func__, keyIdx, ext->key_len));
2643 if (ext->key_len == 32)
2645 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2647 fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, FALSE, ext);
2648 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
2650 STA_PORT_SECURED(pAdapter);
2653 else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
2655 fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, TRUE, ext);
2657 // set 802.1x port control
2658 STA_PORT_SECURED(pAdapter);
2664 case IW_ENCODE_ALG_CCMP:
2665 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2667 fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, FALSE, ext);
2668 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
2669 STA_PORT_SECURED(pAdapter);
2671 else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
2673 fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, TRUE, ext);
2675 // set 802.1x port control
2676 STA_PORT_SECURED(pAdapter);
2688 rt_ioctl_giwencodeext(struct net_device *dev,
2689 struct iw_request_info *info,
2690 union iwreq_data *wrqu, char *extra)
2692 PRTMP_ADAPTER pAd = dev->ml_priv;
2694 struct iw_point *encoding = &wrqu->encoding;
2695 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2696 int idx, max_key_len;
2698 DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_giwencodeext\n"));
2700 max_key_len = encoding->length - sizeof(*ext);
2701 if (max_key_len < 0)
2704 idx = encoding->flags & IW_ENCODE_INDEX;
2707 if (idx < 1 || idx > 4)
2711 if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
2712 (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled))
2714 if (idx != pAd->StaCfg.DefaultKeyId)
2722 idx = pAd->StaCfg.DefaultKeyId;
2724 encoding->flags = idx + 1;
2725 memset(ext, 0, sizeof(*ext));
2728 switch(pAd->StaCfg.WepStatus) {
2729 case Ndis802_11WEPDisabled:
2730 ext->alg = IW_ENCODE_ALG_NONE;
2731 encoding->flags |= IW_ENCODE_DISABLED;
2733 case Ndis802_11WEPEnabled:
2734 ext->alg = IW_ENCODE_ALG_WEP;
2735 if (pAd->SharedKey[BSS0][idx].KeyLen > max_key_len)
2739 ext->key_len = pAd->SharedKey[BSS0][idx].KeyLen;
2740 pKey = &(pAd->SharedKey[BSS0][idx].Key[0]);
2743 case Ndis802_11Encryption2Enabled:
2744 case Ndis802_11Encryption3Enabled:
2745 if (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
2746 ext->alg = IW_ENCODE_ALG_TKIP;
2748 ext->alg = IW_ENCODE_ALG_CCMP;
2750 if (max_key_len < 32)
2755 pKey = &pAd->StaCfg.PMK[0];
2762 if (ext->key_len && pKey)
2764 encoding->flags |= IW_ENCODE_ENABLED;
2765 memcpy(ext->key, pKey, ext->key_len);
2772 int rt_ioctl_siwgenie(struct net_device *dev,
2773 struct iw_request_info *info,
2774 union iwreq_data *wrqu, char *extra)
2776 PRTMP_ADAPTER pAd = dev->ml_priv;
2778 if (wrqu->data.length > MAX_LEN_OF_RSNIE ||
2779 (wrqu->data.length && extra == NULL))
2782 if (wrqu->data.length)
2784 pAd->StaCfg.RSNIE_Len = wrqu->data.length;
2785 NdisMoveMemory(&pAd->StaCfg.RSN_IE[0], extra, pAd->StaCfg.RSNIE_Len);
2789 pAd->StaCfg.RSNIE_Len = 0;
2790 NdisZeroMemory(&pAd->StaCfg.RSN_IE[0], MAX_LEN_OF_RSNIE);
2795 #endif // SIOCSIWGENIE //
2797 int rt_ioctl_giwgenie(struct net_device *dev,
2798 struct iw_request_info *info,
2799 union iwreq_data *wrqu, char *extra)
2801 PRTMP_ADAPTER pAd = dev->ml_priv;
2803 if ((pAd->StaCfg.RSNIE_Len == 0) ||
2804 (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA))
2806 wrqu->data.length = 0;
2811 if (pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
2813 if (wrqu->data.length < pAd->StaCfg.RSNIE_Len)
2816 wrqu->data.length = pAd->StaCfg.RSNIE_Len;
2817 memcpy(extra, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
2820 #endif // SIOCSIWGENIE //
2822 UCHAR RSNIe = IE_WPA;
2824 if (wrqu->data.length < (pAd->StaCfg.RSNIE_Len + 2)) // ID, Len
2826 wrqu->data.length = pAd->StaCfg.RSNIE_Len + 2;
2828 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
2829 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2))
2832 extra[0] = (char)RSNIe;
2833 extra[1] = pAd->StaCfg.RSNIE_Len;
2834 memcpy(extra+2, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
2840 int rt_ioctl_siwpmksa(struct net_device *dev,
2841 struct iw_request_info *info,
2842 union iwreq_data *wrqu,
2845 PRTMP_ADAPTER pAd = dev->ml_priv;
2846 struct iw_pmksa *pPmksa = (struct iw_pmksa *)wrqu->data.pointer;
2847 INT CachedIdx = 0, idx = 0;
2852 DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_siwpmksa\n"));
2855 case IW_PMKSA_FLUSH:
2856 NdisZeroMemory(pAd->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
2857 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_FLUSH\n"));
2859 case IW_PMKSA_REMOVE:
2860 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
2862 // compare the BSSID
2863 if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
2865 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN);
2866 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].PMKID, 16);
2867 for (idx = CachedIdx; idx < (pAd->StaCfg.SavedPMKNum - 1); idx++)
2869 NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].BSSID[0], &pAd->StaCfg.SavedPMK[idx+1].BSSID[0], MAC_ADDR_LEN);
2870 NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].PMKID[0], &pAd->StaCfg.SavedPMK[idx+1].PMKID[0], 16);
2872 pAd->StaCfg.SavedPMKNum--;
2877 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_REMOVE\n"));
2880 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
2882 // compare the BSSID
2883 if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
2887 // Found, replace it
2888 if (CachedIdx < PMKID_NO)
2890 DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
2891 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
2892 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
2893 pAd->StaCfg.SavedPMKNum++;
2895 // Not found, replace the last one
2898 // Randomly replace one
2899 CachedIdx = (pPmksa->bssid.sa_data[5] % PMKID_NO);
2900 DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
2901 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
2902 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
2905 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_ADD\n"));
2908 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - Unknow Command!!\n"));
2914 #endif // #if WIRELESS_EXT > 17
2918 rt_private_ioctl_bbp(struct net_device *dev, struct iw_request_info *info,
2919 struct iw_point *wrq, char *extra)
2926 BOOLEAN bIsPrintAllBBP = FALSE;
2928 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2931 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2933 if (wrq->length > 1) //No parameters.
2935 sprintf(extra, "\n");
2937 //Parsing Read or Write
2938 this_char = wrq->pointer;
2939 DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s\n", this_char));
2943 if ((value = rtstrchr(this_char, '=')) != NULL)
2946 if (!value || !*value)
2948 DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s, value=%s\n", this_char, value));
2949 if (sscanf(this_char, "%d", &(bbpId)) == 1)
2955 if (bbpId <= 138) // edit by johnli, RF power sequence setup, add BBP R138 for ADC dynamic on/off control
2959 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
2961 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
2962 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2963 DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
2966 {//Invalid parametes, so default printk all bbp
2967 bIsPrintAllBBP = TRUE;
2972 { //Invalid parametes, so default printk all bbp
2973 bIsPrintAllBBP = TRUE;
2979 if ((sscanf(this_char, "%d", &(bbpId)) == 1) && (sscanf(value, "%x", &(bbpValue)) == 1))
2985 if (bbpId <= 138) // edit by johnli, RF power sequence setup, add BBP R138 for ADC dynamic on/off control
2989 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, bbpId, bbpValue);
2990 //Read it back for showing
2991 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
2993 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
2994 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2995 DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
2998 {//Invalid parametes, so default printk all bbp
2999 bIsPrintAllBBP = TRUE;
3004 { //Invalid parametes, so default printk all bbp
3005 bIsPrintAllBBP = TRUE;
3011 bIsPrintAllBBP = TRUE;
3016 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
3017 sprintf(extra, "\n");
3019 for (bbpId = 0; bbpId <= 136; bbpId++)
3022 for (bbpId = 0; bbpId <= 138; bbpId++) // edit by johnli, RF power sequence setup, add BBP R138 for ADC dynamic on/off control
3025 if (strlen(extra) >= (IW_PRIV_SIZE_MASK - 10))
3027 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
3029 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X ", bbpId, bbpId*2, regBBP);
3031 sprintf(extra+strlen(extra), "\n");
3034 sprintf(extra+strlen(extra), "%03d = %02X\n", bbpId, regBBP); // edit by johnli, change display format
3038 wrq->length = strlen(extra) + 1; // 1: size of '\0'
3039 DBGPRINT(RT_DEBUG_TRACE, ("wrq->length = %d\n", wrq->length));
3042 DBGPRINT(RT_DEBUG_TRACE, ("<==rt_private_ioctl_bbp\n\n"));
3048 int rt_ioctl_siwrate(struct net_device *dev,
3049 struct iw_request_info *info,
3050 union iwreq_data *wrqu, char *extra)
3052 PRTMP_ADAPTER pAd = dev->ml_priv;
3053 UINT32 rate = wrqu->bitrate.value, fixed = wrqu->bitrate.fixed;
3055 //check if the interface is down
3056 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
3058 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::Network is down!\n"));
3062 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(rate = %d, fixed = %d)\n", rate, fixed));
3063 /* rate = -1 => auto rate
3064 rate = X, fixed = 1 => (fixed rate X)
3069 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
3070 pAd->StaCfg.bAutoTxRateSwitch = TRUE;
3071 if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
3072 (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
3073 RTMPSetDesiredRates(pAd, -1);
3081 pAd->StaCfg.bAutoTxRateSwitch = FALSE;
3082 if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
3083 (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
3084 RTMPSetDesiredRates(pAd, rate);
3087 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
3090 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(HtMcs=%d)\n",pAd->StaCfg.DesiredTransmitSetting.field.MCS));
3094 // TODO: rate = X, fixed = 0 => (rates <= X)
3102 int rt_ioctl_giwrate(struct net_device *dev,
3103 struct iw_request_info *info,
3104 union iwreq_data *wrqu, char *extra)
3106 PRTMP_ADAPTER pAd = dev->ml_priv;
3107 int rate_index = 0, rate_count = 0;
3108 HTTRANSMIT_SETTING ht_setting;
3109 __s32 ralinkrate[] =
3110 {2, 4, 11, 22, // CCK
3111 12, 18, 24, 36, 48, 72, 96, 108, // OFDM
3112 13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260, // 20MHz, 800ns GI, MCS: 0 ~ 15
3113 39, 78, 117, 156, 234, 312, 351, 390, // 20MHz, 800ns GI, MCS: 16 ~ 23
3114 27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540, // 40MHz, 800ns GI, MCS: 0 ~ 15
3115 81, 162, 243, 324, 486, 648, 729, 810, // 40MHz, 800ns GI, MCS: 16 ~ 23
3116 14, 29, 43, 57, 87, 115, 130, 144, 29, 59, 87, 115, 173, 230, 260, 288, // 20MHz, 400ns GI, MCS: 0 ~ 15
3117 43, 87, 130, 173, 260, 317, 390, 433, // 20MHz, 400ns GI, MCS: 16 ~ 23
3118 30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600, // 40MHz, 400ns GI, MCS: 0 ~ 15
3119 90, 180, 270, 360, 540, 720, 810, 900}; // 40MHz, 400ns GI, MCS: 16 ~ 23
3121 rate_count = sizeof(ralinkrate)/sizeof(__s32);
3122 //check if the interface is down
3123 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
3125 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
3129 if ((pAd->StaCfg.bAutoTxRateSwitch == FALSE) &&
3131 ((pAd->CommonCfg.PhyMode <= PHY_11G) || (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM)))
3132 ht_setting.word = pAd->StaCfg.HTPhyMode.word;
3134 ht_setting.word = pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word;
3136 if (ht_setting.field.MODE >= MODE_HTMIX)
3138 rate_index = 12 + ((UCHAR)ht_setting.field.BW *24) + ((UCHAR)ht_setting.field.ShortGI *48) + ((UCHAR)ht_setting.field.MCS);
3141 if (ht_setting.field.MODE == MODE_OFDM)
3142 rate_index = (UCHAR)(ht_setting.field.MCS) + 4;
3143 else if (ht_setting.field.MODE == MODE_CCK)
3144 rate_index = (UCHAR)(ht_setting.field.MCS);
3149 if (rate_index > rate_count)
3150 rate_index = rate_count;
3152 wrqu->bitrate.value = ralinkrate[rate_index] * 500000;
3153 wrqu->bitrate.disabled = 0;
3158 static const iw_handler rt_handler[] =
3160 (iw_handler) NULL, /* SIOCSIWCOMMIT */
3161 (iw_handler) rt_ioctl_giwname, /* SIOCGIWNAME */
3162 (iw_handler) NULL, /* SIOCSIWNWID */
3163 (iw_handler) NULL, /* SIOCGIWNWID */
3164 (iw_handler) rt_ioctl_siwfreq, /* SIOCSIWFREQ */
3165 (iw_handler) rt_ioctl_giwfreq, /* SIOCGIWFREQ */
3166 (iw_handler) rt_ioctl_siwmode, /* SIOCSIWMODE */
3167 (iw_handler) rt_ioctl_giwmode, /* SIOCGIWMODE */
3168 (iw_handler) NULL, /* SIOCSIWSENS */
3169 (iw_handler) NULL, /* SIOCGIWSENS */
3170 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
3171 (iw_handler) rt_ioctl_giwrange, /* SIOCGIWRANGE */
3172 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
3173 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
3174 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
3175 (iw_handler) rt28xx_get_wireless_stats /* kernel code */, /* SIOCGIWSTATS */
3176 (iw_handler) NULL, /* SIOCSIWSPY */
3177 (iw_handler) NULL, /* SIOCGIWSPY */
3178 (iw_handler) NULL, /* SIOCSIWTHRSPY */
3179 (iw_handler) NULL, /* SIOCGIWTHRSPY */
3180 (iw_handler) rt_ioctl_siwap, /* SIOCSIWAP */
3181 (iw_handler) rt_ioctl_giwap, /* SIOCGIWAP */
3183 (iw_handler) rt_ioctl_siwmlme, /* SIOCSIWMLME */
3185 (iw_handler) NULL, /* SIOCSIWMLME */
3186 #endif // SIOCSIWMLME //
3187 (iw_handler) rt_ioctl_iwaplist, /* SIOCGIWAPLIST */
3189 (iw_handler) rt_ioctl_siwscan, /* SIOCSIWSCAN */
3190 (iw_handler) rt_ioctl_giwscan, /* SIOCGIWSCAN */
3192 (iw_handler) NULL, /* SIOCSIWSCAN */
3193 (iw_handler) NULL, /* SIOCGIWSCAN */
3194 #endif /* SIOCGIWSCAN */
3195 (iw_handler) rt_ioctl_siwessid, /* SIOCSIWESSID */
3196 (iw_handler) rt_ioctl_giwessid, /* SIOCGIWESSID */
3197 (iw_handler) rt_ioctl_siwnickn, /* SIOCSIWNICKN */
3198 (iw_handler) rt_ioctl_giwnickn, /* SIOCGIWNICKN */
3199 (iw_handler) NULL, /* -- hole -- */
3200 (iw_handler) NULL, /* -- hole -- */
3201 (iw_handler) rt_ioctl_siwrate, /* SIOCSIWRATE */
3202 (iw_handler) rt_ioctl_giwrate, /* SIOCGIWRATE */
3203 (iw_handler) rt_ioctl_siwrts, /* SIOCSIWRTS */
3204 (iw_handler) rt_ioctl_giwrts, /* SIOCGIWRTS */
3205 (iw_handler) rt_ioctl_siwfrag, /* SIOCSIWFRAG */
3206 (iw_handler) rt_ioctl_giwfrag, /* SIOCGIWFRAG */
3207 (iw_handler) NULL, /* SIOCSIWTXPOW */
3208 (iw_handler) NULL, /* SIOCGIWTXPOW */
3209 (iw_handler) NULL, /* SIOCSIWRETRY */
3210 (iw_handler) NULL, /* SIOCGIWRETRY */
3211 (iw_handler) rt_ioctl_siwencode, /* SIOCSIWENCODE */
3212 (iw_handler) rt_ioctl_giwencode, /* SIOCGIWENCODE */
3213 (iw_handler) NULL, /* SIOCSIWPOWER */
3214 (iw_handler) NULL, /* SIOCGIWPOWER */
3215 (iw_handler) NULL, /* -- hole -- */
3216 (iw_handler) NULL, /* -- hole -- */
3217 #if WIRELESS_EXT > 17
3218 (iw_handler) rt_ioctl_siwgenie, /* SIOCSIWGENIE */
3219 (iw_handler) rt_ioctl_giwgenie, /* SIOCGIWGENIE */
3220 (iw_handler) rt_ioctl_siwauth, /* SIOCSIWAUTH */
3221 (iw_handler) rt_ioctl_giwauth, /* SIOCGIWAUTH */
3222 (iw_handler) rt_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
3223 (iw_handler) rt_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */
3224 (iw_handler) rt_ioctl_siwpmksa, /* SIOCSIWPMKSA */
3228 static const iw_handler rt_priv_handlers[] = {
3229 (iw_handler) NULL, /* + 0x00 */
3230 (iw_handler) NULL, /* + 0x01 */
3231 (iw_handler) rt_ioctl_setparam, /* + 0x02 */
3233 (iw_handler) rt_private_ioctl_bbp, /* + 0x03 */
3235 (iw_handler) NULL, /* + 0x03 */
3237 (iw_handler) NULL, /* + 0x04 */
3238 (iw_handler) NULL, /* + 0x05 */
3239 (iw_handler) NULL, /* + 0x06 */
3240 (iw_handler) NULL, /* + 0x07 */
3241 (iw_handler) NULL, /* + 0x08 */
3242 (iw_handler) rt_private_get_statistics, /* + 0x09 */
3243 (iw_handler) NULL, /* + 0x0A */
3244 (iw_handler) NULL, /* + 0x0B */
3245 (iw_handler) NULL, /* + 0x0C */
3246 (iw_handler) NULL, /* + 0x0D */
3247 (iw_handler) NULL, /* + 0x0E */
3248 (iw_handler) NULL, /* + 0x0F */
3249 (iw_handler) NULL, /* + 0x10 */
3250 (iw_handler) rt_private_show, /* + 0x11 */
3251 (iw_handler) NULL, /* + 0x12 */
3252 (iw_handler) NULL, /* + 0x13 */
3253 (iw_handler) NULL, /* + 0x15 */
3254 (iw_handler) NULL, /* + 0x17 */
3255 (iw_handler) NULL, /* + 0x18 */
3258 const struct iw_handler_def rt28xx_iw_handler_def =
3260 #define N(a) (sizeof (a) / sizeof (a[0]))
3261 .standard = (iw_handler *) rt_handler,
3262 .num_standard = sizeof(rt_handler) / sizeof(iw_handler),
3263 .private = (iw_handler *) rt_priv_handlers,
3264 .num_private = N(rt_priv_handlers),
3265 .private_args = (struct iw_priv_args *) privtab,
3266 .num_private_args = N(privtab),
3267 #if IW_HANDLER_VERSION >= 7
3268 .get_wireless_stats = rt28xx_get_wireless_stats,
3272 INT RTMPSetInformation(
3273 IN PRTMP_ADAPTER pAdapter,
3274 IN OUT struct ifreq *rq,
3277 struct iwreq *wrq = (struct iwreq *) rq;
3278 NDIS_802_11_SSID Ssid;
3279 NDIS_802_11_MAC_ADDRESS Bssid;
3280 RT_802_11_PHY_MODE PhyMode;
3281 RT_802_11_STA_CONFIG StaConfig;
3282 NDIS_802_11_RATES aryRates;
3283 RT_802_11_PREAMBLE Preamble;
3284 NDIS_802_11_WEP_STATUS WepStatus;
3285 NDIS_802_11_AUTHENTICATION_MODE AuthMode = Ndis802_11AuthModeMax;
3286 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
3287 NDIS_802_11_RTS_THRESHOLD RtsThresh;
3288 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
3289 NDIS_802_11_POWER_MODE PowerMode;
3290 PNDIS_802_11_KEY pKey = NULL;
3291 PNDIS_802_11_WEP pWepKey =NULL;
3292 PNDIS_802_11_REMOVE_KEY pRemoveKey = NULL;
3293 NDIS_802_11_CONFIGURATION Config, *pConfig = NULL;
3294 NDIS_802_11_NETWORK_TYPE NetType;
3297 INT Status = NDIS_STATUS_SUCCESS, MaxPhyMode = PHY_11G;
3300 BOOLEAN StateMachineTouched = FALSE;
3301 OID_SET_HT_PHYMODE HT_PhyMode; //11n ,kathy
3302 PNDIS_802_11_PMKID pPmkId = NULL;
3303 BOOLEAN IEEE8021xState = FALSE;
3304 BOOLEAN IEEE8021x_required_keys = FALSE;
3305 UCHAR wpa_supplicant_enable = 0;
3307 MaxPhyMode = PHY_11N_5G;
3309 DBGPRINT(RT_DEBUG_TRACE, ("-->RTMPSetInformation(), 0x%08x\n", cmd&0x7FFF));
3310 switch(cmd & 0x7FFF) {
3311 case RT_OID_802_11_COUNTRY_REGION:
3312 if (wrq->u.data.length < sizeof(UCHAR))
3314 // Only avaliable when EEPROM not programming
3315 else if (!(pAdapter->CommonCfg.CountryRegion & 0x80) && !(pAdapter->CommonCfg.CountryRegionForABand & 0x80))
3320 Status = copy_from_user(&Country, wrq->u.data.pointer, wrq->u.data.length);
3321 pAdapter->CommonCfg.CountryRegion = (UCHAR)(Country & 0x000000FF);
3322 pAdapter->CommonCfg.CountryRegionForABand = (UCHAR)((Country >> 8) & 0x000000FF);
3323 TmpPhy = pAdapter->CommonCfg.PhyMode;
3324 pAdapter->CommonCfg.PhyMode = 0xff;
3325 // Build all corresponding channel information
3326 RTMPSetPhyMode(pAdapter, TmpPhy);
3327 SetCommonHT(pAdapter);
3328 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_COUNTRY_REGION (A:%d B/G:%d)\n", pAdapter->CommonCfg.CountryRegionForABand,
3329 pAdapter->CommonCfg.CountryRegion));
3332 case OID_802_11_BSSID_LIST_SCAN:
3334 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID_LIST_SCAN, TxCnt = %d \n", pAdapter->RalinkCounters.LastOneSecTotalTxCount));
3336 if (MONITOR_ON(pAdapter))
3338 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
3342 //Benson add 20080527, when radio off, sta don't need to scan
3343 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_RADIO_OFF))
3346 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
3348 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is scanning now !!!\n"));
3349 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
3350 Status = NDIS_STATUS_SUCCESS;
3354 if (pAdapter->RalinkCounters.LastOneSecTotalTxCount > 100)
3356 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
3357 Status = NDIS_STATUS_SUCCESS;
3358 pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
3362 if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
3363 ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
3364 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
3365 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
3366 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)) &&
3367 (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
3369 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
3370 Status = NDIS_STATUS_SUCCESS;
3371 pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
3376 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3378 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3379 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3382 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
3383 // this request, because this request is initiated by NDIS.
3384 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
3385 // Reset allowed scan retries
3386 pAdapter->StaCfg.ScanCnt = 0;
3387 pAdapter->StaCfg.LastScanTime = Now;
3389 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
3390 RTMP_SET_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
3391 MlmeEnqueue(pAdapter,
3392 MLME_CNTL_STATE_MACHINE,
3393 OID_802_11_BSSID_LIST_SCAN,
3397 Status = NDIS_STATUS_SUCCESS;
3398 StateMachineTouched = TRUE;
3400 case OID_802_11_SSID:
3401 if (wrq->u.data.length != sizeof(NDIS_802_11_SSID))
3405 PCHAR pSsidString = NULL;
3406 Status = copy_from_user(&Ssid, wrq->u.data.pointer, wrq->u.data.length);
3408 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SSID (Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
3409 if (Ssid.SsidLength > MAX_LEN_OF_SSID)
3413 if (Ssid.SsidLength == 0)
3415 Set_SSID_Proc(pAdapter, "");
3419 pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
3422 NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
3423 NdisMoveMemory(pSsidString, Ssid.Ssid, Ssid.SsidLength);
3424 Set_SSID_Proc(pAdapter, pSsidString);
3433 case OID_802_11_BSSID:
3434 if (wrq->u.data.length != sizeof(NDIS_802_11_MAC_ADDRESS))
3438 Status = copy_from_user(&Bssid, wrq->u.data.pointer, wrq->u.data.length);
3440 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
3441 // this request, because this request is initiated by NDIS.
3442 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
3444 // Prevent to connect AP again in STAMlmePeriodicExec
3445 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
3447 // Reset allowed scan retries
3448 pAdapter->StaCfg.ScanCnt = 0;
3450 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3452 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3453 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3455 MlmeEnqueue(pAdapter,
3456 MLME_CNTL_STATE_MACHINE,
3458 sizeof(NDIS_802_11_MAC_ADDRESS),
3460 Status = NDIS_STATUS_SUCCESS;
3461 StateMachineTouched = TRUE;
3463 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID %02x:%02x:%02x:%02x:%02x:%02x\n",
3464 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
3467 case RT_OID_802_11_RADIO:
3468 if (wrq->u.data.length != sizeof(BOOLEAN))
3472 Status = copy_from_user(&RadioState, wrq->u.data.pointer, wrq->u.data.length);
3473 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RADIO (=%d)\n", RadioState));
3474 if (pAdapter->StaCfg.bSwRadio != RadioState)
3476 pAdapter->StaCfg.bSwRadio = RadioState;
3477 if (pAdapter->StaCfg.bRadio != (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio))
3479 pAdapter->StaCfg.bRadio = (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio);
3480 if (pAdapter->StaCfg.bRadio == TRUE)
3482 MlmeRadioOn(pAdapter);
3483 // Update extra information
3484 pAdapter->ExtraInfo = EXTRA_INFO_CLEAR;
3488 MlmeRadioOff(pAdapter);
3489 // Update extra information
3490 pAdapter->ExtraInfo = SW_RADIO_OFF;
3496 case RT_OID_802_11_PHY_MODE:
3497 if (wrq->u.data.length != sizeof(RT_802_11_PHY_MODE))
3501 Status = copy_from_user(&PhyMode, wrq->u.data.pointer, wrq->u.data.length);
3502 if (PhyMode <= MaxPhyMode)
3504 RTMPSetPhyMode(pAdapter, PhyMode);
3505 SetCommonHT(pAdapter);
3507 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PHY_MODE (=%d)\n", PhyMode));
3510 case RT_OID_802_11_STA_CONFIG:
3511 if (wrq->u.data.length != sizeof(RT_802_11_STA_CONFIG))
3515 Status = copy_from_user(&StaConfig, wrq->u.data.pointer, wrq->u.data.length);
3516 pAdapter->CommonCfg.bEnableTxBurst = StaConfig.EnableTxBurst;
3517 pAdapter->CommonCfg.UseBGProtection = StaConfig.UseBGProtection;
3518 pAdapter->CommonCfg.bUseShortSlotTime = 1; // 2003-10-30 always SHORT SLOT capable
3519 if ((pAdapter->CommonCfg.PhyMode != StaConfig.AdhocMode) &&
3520 (StaConfig.AdhocMode <= MaxPhyMode))
3522 // allow dynamic change of "USE OFDM rate or not" in ADHOC mode
3523 // if setting changed, need to reset current TX rate as well as BEACON frame format
3525 pAdapter->CommonCfg.PhyMode = StaConfig.AdhocMode;
3527 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
3530 pAdapter->CommonCfg.PhyMode = StaConfig.AdhocMode;
3532 RTMPSetPhyMode(pAdapter, PhyMode);
3533 MlmeUpdateTxRates(pAdapter, FALSE, 0);
3534 MakeIbssBeacon(pAdapter); // re-build BEACON frame
3535 AsicEnableIbssSync(pAdapter); // copy to on-chip memory
3538 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_STA_CONFIG (Burst=%d, Protection=%ld,ShortSlot=%d\n",
3539 pAdapter->CommonCfg.bEnableTxBurst,
3540 pAdapter->CommonCfg.UseBGProtection,
3541 pAdapter->CommonCfg.bUseShortSlotTime));
3544 case OID_802_11_DESIRED_RATES:
3545 if (wrq->u.data.length != sizeof(NDIS_802_11_RATES))
3549 Status = copy_from_user(&aryRates, wrq->u.data.pointer, wrq->u.data.length);
3550 NdisZeroMemory(pAdapter->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES);
3551 NdisMoveMemory(pAdapter->CommonCfg.DesireRate, &aryRates, sizeof(NDIS_802_11_RATES));
3552 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DESIRED_RATES (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
3553 pAdapter->CommonCfg.DesireRate[0],pAdapter->CommonCfg.DesireRate[1],
3554 pAdapter->CommonCfg.DesireRate[2],pAdapter->CommonCfg.DesireRate[3],
3555 pAdapter->CommonCfg.DesireRate[4],pAdapter->CommonCfg.DesireRate[5],
3556 pAdapter->CommonCfg.DesireRate[6],pAdapter->CommonCfg.DesireRate[7] ));
3557 // Changing DesiredRate may affect the MAX TX rate we used to TX frames out
3558 MlmeUpdateTxRates(pAdapter, FALSE, 0);
3561 case RT_OID_802_11_PREAMBLE:
3562 if (wrq->u.data.length != sizeof(RT_802_11_PREAMBLE))
3566 Status = copy_from_user(&Preamble, wrq->u.data.pointer, wrq->u.data.length);
3567 if (Preamble == Rt802_11PreambleShort)
3569 pAdapter->CommonCfg.TxPreamble = Preamble;
3570 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleShort);
3572 else if ((Preamble == Rt802_11PreambleLong) || (Preamble == Rt802_11PreambleAuto))
3574 // if user wants AUTO, initialize to LONG here, then change according to AP's
3575 // capability upon association.
3576 pAdapter->CommonCfg.TxPreamble = Preamble;
3577 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleLong);
3584 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PREAMBLE (=%d)\n", Preamble));
3587 case OID_802_11_WEP_STATUS:
3588 if (wrq->u.data.length != sizeof(NDIS_802_11_WEP_STATUS))
3592 Status = copy_from_user(&WepStatus, wrq->u.data.pointer, wrq->u.data.length);
3593 // Since TKIP, AES, WEP are all supported. It should not have any invalid setting
3594 if (WepStatus <= Ndis802_11Encryption3KeyAbsent)
3596 if (pAdapter->StaCfg.WepStatus != WepStatus)
3598 // Config has changed
3599 pAdapter->bConfigChanged = TRUE;
3601 pAdapter->StaCfg.WepStatus = WepStatus;
3602 pAdapter->StaCfg.OrigWepStatus = WepStatus;
3603 pAdapter->StaCfg.PairCipher = WepStatus;
3604 pAdapter->StaCfg.GroupCipher = WepStatus;
3611 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEP_STATUS (=%d)\n",WepStatus));
3614 case OID_802_11_AUTHENTICATION_MODE:
3615 if (wrq->u.data.length != sizeof(NDIS_802_11_AUTHENTICATION_MODE))
3619 Status = copy_from_user(&AuthMode, wrq->u.data.pointer, wrq->u.data.length);
3620 if (AuthMode > Ndis802_11AuthModeMax)
3627 if (pAdapter->StaCfg.AuthMode != AuthMode)
3629 // Config has changed
3630 pAdapter->bConfigChanged = TRUE;
3632 pAdapter->StaCfg.AuthMode = AuthMode;
3634 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
3635 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_AUTHENTICATION_MODE (=%d) \n",pAdapter->StaCfg.AuthMode));
3638 case OID_802_11_INFRASTRUCTURE_MODE:
3639 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_INFRASTRUCTURE))
3643 Status = copy_from_user(&BssType, wrq->u.data.pointer, wrq->u.data.length);
3645 if (BssType == Ndis802_11IBSS)
3646 Set_NetworkType_Proc(pAdapter, "Adhoc");
3647 else if (BssType == Ndis802_11Infrastructure)
3648 Set_NetworkType_Proc(pAdapter, "Infra");
3649 else if (BssType == Ndis802_11Monitor)
3650 Set_NetworkType_Proc(pAdapter, "Monitor");
3654 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_INFRASTRUCTURE_MODE (unknown)\n"));
3658 case OID_802_11_REMOVE_WEP:
3659 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_WEP\n"));
3660 if (wrq->u.data.length != sizeof(NDIS_802_11_KEY_INDEX))
3666 KeyIdx = *(NDIS_802_11_KEY_INDEX *) wrq->u.data.pointer;
3668 if (KeyIdx & 0x80000000)
3670 // Should never set default bit when remove key
3675 KeyIdx = KeyIdx & 0x0fffffff;
3681 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
3682 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
3683 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
3688 case RT_OID_802_11_RESET_COUNTERS:
3689 NdisZeroMemory(&pAdapter->WlanCounters, sizeof(COUNTER_802_11));
3690 NdisZeroMemory(&pAdapter->Counters8023, sizeof(COUNTER_802_3));
3691 NdisZeroMemory(&pAdapter->RalinkCounters, sizeof(COUNTER_RALINK));
3692 pAdapter->Counters8023.RxNoBuffer = 0;
3693 pAdapter->Counters8023.GoodReceives = 0;
3694 pAdapter->Counters8023.RxNoBuffer = 0;
3696 pAdapter->BulkOutComplete = 0;
3697 pAdapter->BulkOutCompleteOther= 0;
3698 pAdapter->BulkOutCompleteCancel = 0;
3699 pAdapter->BulkOutReq = 0;
3700 pAdapter->BulkInReq= 0;
3701 pAdapter->BulkInComplete = 0;
3702 pAdapter->BulkInCompleteFail = 0;
3704 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RESET_COUNTERS \n"));
3706 case OID_802_11_RTS_THRESHOLD:
3707 if (wrq->u.data.length != sizeof(NDIS_802_11_RTS_THRESHOLD))
3711 Status = copy_from_user(&RtsThresh, wrq->u.data.pointer, wrq->u.data.length);
3712 if (RtsThresh > MAX_RTS_THRESHOLD)
3715 pAdapter->CommonCfg.RtsThreshold = (USHORT)RtsThresh;
3717 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_RTS_THRESHOLD (=%ld)\n",RtsThresh));
3719 case OID_802_11_FRAGMENTATION_THRESHOLD:
3720 if (wrq->u.data.length != sizeof(NDIS_802_11_FRAGMENTATION_THRESHOLD))
3724 Status = copy_from_user(&FragThresh, wrq->u.data.pointer, wrq->u.data.length);
3725 pAdapter->CommonCfg.bUseZeroToDisableFragment = FALSE;
3726 if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
3728 if (FragThresh == 0)
3730 pAdapter->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
3731 pAdapter->CommonCfg.bUseZeroToDisableFragment = TRUE;
3737 pAdapter->CommonCfg.FragmentThreshold = (USHORT)FragThresh;
3739 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_FRAGMENTATION_THRESHOLD (=%ld) \n",FragThresh));
3741 case OID_802_11_POWER_MODE:
3742 if (wrq->u.data.length != sizeof(NDIS_802_11_POWER_MODE))
3746 Status = copy_from_user(&PowerMode, wrq->u.data.pointer, wrq->u.data.length);
3747 if (PowerMode == Ndis802_11PowerModeCAM)
3748 Set_PSMode_Proc(pAdapter, "CAM");
3749 else if (PowerMode == Ndis802_11PowerModeMAX_PSP)
3750 Set_PSMode_Proc(pAdapter, "Max_PSP");
3751 else if (PowerMode == Ndis802_11PowerModeFast_PSP)
3752 Set_PSMode_Proc(pAdapter, "Fast_PSP");
3753 else if (PowerMode == Ndis802_11PowerModeLegacy_PSP)
3754 Set_PSMode_Proc(pAdapter, "Legacy_PSP");
3758 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_POWER_MODE (=%d)\n",PowerMode));
3760 case RT_OID_802_11_TX_POWER_LEVEL_1:
3761 if (wrq->u.data.length < sizeof(ULONG))
3765 Status = copy_from_user(&PowerTemp, wrq->u.data.pointer, wrq->u.data.length);
3766 if (PowerTemp > 100)
3767 PowerTemp = 0xffffffff; // AUTO
3768 pAdapter->CommonCfg.TxPowerDefault = PowerTemp; //keep current setting.
3769 pAdapter->CommonCfg.TxPowerPercentage = pAdapter->CommonCfg.TxPowerDefault;
3770 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
3773 case OID_802_11_NETWORK_TYPE_IN_USE:
3774 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_TYPE))
3778 Status = copy_from_user(&NetType, wrq->u.data.pointer, wrq->u.data.length);
3780 if (NetType == Ndis802_11DS)
3781 RTMPSetPhyMode(pAdapter, PHY_11B);
3782 else if (NetType == Ndis802_11OFDM24)
3783 RTMPSetPhyMode(pAdapter, PHY_11BG_MIXED);
3784 else if (NetType == Ndis802_11OFDM5)
3785 RTMPSetPhyMode(pAdapter, PHY_11A);
3789 if (Status == NDIS_STATUS_SUCCESS)
3790 SetCommonHT(pAdapter);
3792 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_NETWORK_TYPE_IN_USE (=%d)\n",NetType));
3795 // For WPA PSK PMK key
3796 case RT_OID_802_11_ADD_WPA:
3797 pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3804 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
3805 if (pKey->Length != wrq->u.data.length)
3808 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!!\n"));
3812 if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
3813 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
3814 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone) )
3816 Status = -EOPNOTSUPP;
3817 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!! [AuthMode != WPAPSK/WPA2PSK/WPANONE]\n"));
3819 else if ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
3820 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
3821 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) ) // Only for WPA PSK mode
3823 NdisMoveMemory(pAdapter->StaCfg.PMK, &pKey->KeyMaterial, pKey->KeyLength);
3824 // Use RaConfig as PSK agent.
3825 // Start STA supplicant state machine
3826 if (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
3827 pAdapter->StaCfg.WpaState = SS_START;
3829 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3833 pAdapter->StaCfg.WpaState = SS_NOTUSE;
3834 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3839 case OID_802_11_REMOVE_KEY:
3840 pRemoveKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3841 if(pRemoveKey == NULL)
3847 Status = copy_from_user(pRemoveKey, wrq->u.data.pointer, wrq->u.data.length);
3848 if (pRemoveKey->Length != wrq->u.data.length)
3851 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!\n"));
3855 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3857 RTMPWPARemoveKeyProc(pAdapter, pRemoveKey);
3858 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Remove WPA Key!!\n"));
3862 KeyIdx = pRemoveKey->KeyIndex;
3864 if (KeyIdx & 0x80000000)
3866 // Should never set default bit when remove key
3868 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(Should never set default bit when remove key)\n"));
3872 KeyIdx = KeyIdx & 0x0fffffff;
3876 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(KeyId[%d] out of range)\n", KeyIdx));
3880 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
3881 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
3882 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
3883 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY (id=0x%x, Len=%d-byte)\n", pRemoveKey->KeyIndex, pRemoveKey->Length));
3891 case OID_802_11_ADD_KEY:
3892 pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3898 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
3899 if (pKey->Length != wrq->u.data.length)
3902 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY, Failed!!\n"));
3906 RTMPAddKey(pAdapter, pKey);
3907 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3911 case OID_802_11_CONFIGURATION:
3912 if (wrq->u.data.length != sizeof(NDIS_802_11_CONFIGURATION))
3916 Status = copy_from_user(&Config, wrq->u.data.pointer, wrq->u.data.length);
3919 if ((pConfig->BeaconPeriod >= 20) && (pConfig->BeaconPeriod <=400))
3920 pAdapter->CommonCfg.BeaconPeriod = (USHORT) pConfig->BeaconPeriod;
3922 pAdapter->StaActive.AtimWin = (USHORT) pConfig->ATIMWindow;
3923 MAP_KHZ_TO_CHANNEL_ID(pConfig->DSConfig, pAdapter->CommonCfg.Channel);
3925 // Save the channel on MlmeAux for CntlOidRTBssidProc used.
3927 pAdapter->MlmeAux.Channel = pAdapter->CommonCfg.Channel;
3929 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_CONFIGURATION (BeacnPeriod=%ld,AtimW=%ld,Ch=%d)\n",
3930 pConfig->BeaconPeriod, pConfig->ATIMWindow, pAdapter->CommonCfg.Channel));
3931 // Config has changed
3932 pAdapter->bConfigChanged = TRUE;
3935 case RT_OID_802_11_SET_HT_PHYMODE:
3936 if (wrq->u.data.length != sizeof(OID_SET_HT_PHYMODE))
3940 POID_SET_HT_PHYMODE pHTPhyMode = &HT_PhyMode;
3942 Status = copy_from_user(&HT_PhyMode, wrq->u.data.pointer, wrq->u.data.length);
3943 DBGPRINT(RT_DEBUG_TRACE, ("Set::pHTPhyMode (PhyMode = %d,TransmitNo = %d, HtMode = %d, ExtOffset = %d , MCS = %d, BW = %d, STBC = %d, SHORTGI = %d) \n",
3944 pHTPhyMode->PhyMode, pHTPhyMode->TransmitNo,pHTPhyMode->HtMode,pHTPhyMode->ExtOffset,
3945 pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->SHORTGI));
3946 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
3947 RTMPSetHT(pAdapter, pHTPhyMode);
3949 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_HT_PHYMODE(MCS=%d,BW=%d,SGI=%d,STBC=%d)\n",
3950 pAdapter->StaCfg.HTPhyMode.field.MCS, pAdapter->StaCfg.HTPhyMode.field.BW, pAdapter->StaCfg.HTPhyMode.field.ShortGI,
3951 pAdapter->StaCfg.HTPhyMode.field.STBC));
3953 case RT_OID_802_11_SET_APSD_SETTING:
3954 if (wrq->u.data.length != sizeof(ULONG))
3959 Status = copy_from_user(&apsd, wrq->u.data.pointer, wrq->u.data.length);
3961 /*-------------------------------------------------------------------
3962 |B31~B7 | B6~B5 | B4 | B3 | B2 | B1 | B0 |
3963 ---------------------------------------------------------------------
3964 | Rsvd | Max SP Len | AC_VO | AC_VI | AC_BK | AC_BE | APSD Capable |
3965 ---------------------------------------------------------------------*/
3966 pAdapter->CommonCfg.bAPSDCapable = (apsd & 0x00000001) ? TRUE : FALSE;
3967 pAdapter->CommonCfg.bAPSDAC_BE = ((apsd & 0x00000002) >> 1) ? TRUE : FALSE;
3968 pAdapter->CommonCfg.bAPSDAC_BK = ((apsd & 0x00000004) >> 2) ? TRUE : FALSE;
3969 pAdapter->CommonCfg.bAPSDAC_VI = ((apsd & 0x00000008) >> 3) ? TRUE : FALSE;
3970 pAdapter->CommonCfg.bAPSDAC_VO = ((apsd & 0x00000010) >> 4) ? TRUE : FALSE;
3971 pAdapter->CommonCfg.MaxSPLength = (UCHAR)((apsd & 0x00000060) >> 5);
3973 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,
3974 pAdapter->CommonCfg.bAPSDAC_BE, pAdapter->CommonCfg.bAPSDAC_BK, pAdapter->CommonCfg.bAPSDAC_VI, pAdapter->CommonCfg.bAPSDAC_VO, pAdapter->CommonCfg.MaxSPLength));
3978 case RT_OID_802_11_SET_APSD_PSM:
3979 if (wrq->u.data.length != sizeof(ULONG))
3983 // Driver needs to notify AP when PSM changes
3984 Status = copy_from_user(&pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.pointer, wrq->u.data.length);
3985 if (pAdapter->CommonCfg.bAPSDForcePowerSave != pAdapter->StaCfg.Psm)
3987 MlmeSetPsmBit(pAdapter, pAdapter->CommonCfg.bAPSDForcePowerSave);
3988 RTMPSendNullFrame(pAdapter, pAdapter->CommonCfg.TxRate, TRUE);
3990 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_APSD_PSM (bAPSDForcePowerSave:%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
3994 case RT_OID_802_11_SET_WMM:
3995 if (wrq->u.data.length != sizeof(BOOLEAN))
3999 Status = copy_from_user(&pAdapter->CommonCfg.bWmmCapable, wrq->u.data.pointer, wrq->u.data.length);
4000 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_WMM (=%d) \n", pAdapter->CommonCfg.bWmmCapable));
4004 case OID_802_11_DISASSOCIATE:
4006 // Set NdisRadioStateOff to TRUE, instead of called MlmeRadioOff.
4007 // Later on, NDIS_802_11_BSSID_LIST_EX->NumberOfItems should be 0
4008 // when query OID_802_11_BSSID_LIST.
4010 // TRUE: NumberOfItems will set to 0.
4011 // FALSE: NumberOfItems no change.
4013 pAdapter->CommonCfg.NdisRadioStateOff = TRUE;
4014 // Set to immediately send the media disconnect event
4015 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
4016 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DISASSOCIATE \n"));
4018 if (INFRA_ON(pAdapter))
4020 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
4022 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
4023 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
4026 MlmeEnqueue(pAdapter,
4027 MLME_CNTL_STATE_MACHINE,
4028 OID_802_11_DISASSOCIATE,
4032 StateMachineTouched = TRUE;
4035 case RT_OID_802_11_SET_IMME_BA_CAP:
4036 if (wrq->u.data.length != sizeof(OID_BACAP_STRUC))
4040 OID_BACAP_STRUC Orde ;
4041 Status = copy_from_user(&Orde, wrq->u.data.pointer, wrq->u.data.length);
4042 if (Orde.Policy > BA_NOTUSE)
4044 Status = NDIS_STATUS_INVALID_DATA;
4046 else if (Orde.Policy == BA_NOTUSE)
4048 pAdapter->CommonCfg.BACapability.field.Policy = BA_NOTUSE;
4049 pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
4050 pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
4051 pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
4052 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
4053 pAdapter->CommonCfg.DesiredHtPhy.MimoPs= Orde.MMPSmode;
4054 pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
4056 pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
4057 pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
4058 pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
4062 pAdapter->CommonCfg.BACapability.field.AutoBA = Orde.AutoBA;
4063 pAdapter->CommonCfg.BACapability.field.Policy = IMMED_BA; // we only support immediate BA.
4064 pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
4065 pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
4066 pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
4067 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
4068 pAdapter->CommonCfg.DesiredHtPhy.MimoPs = Orde.MMPSmode;
4069 pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
4072 pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
4073 pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
4074 pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
4076 if (pAdapter->CommonCfg.BACapability.field.RxBAWinLimit > MAX_RX_REORDERBUF)
4077 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = MAX_RX_REORDERBUF;
4081 pAdapter->CommonCfg.REGBACapability.word = pAdapter->CommonCfg.BACapability.word;
4082 DBGPRINT(RT_DEBUG_TRACE, ("Set::(Orde.AutoBA = %d) (Policy=%d)(ReBAWinLimit=%d)(TxBAWinLimit=%d)(AutoMode=%d)\n",Orde.AutoBA, pAdapter->CommonCfg.BACapability.field.Policy,
4083 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit,pAdapter->CommonCfg.BACapability.field.TxBAWinLimit, pAdapter->CommonCfg.BACapability.field.AutoBA));
4084 DBGPRINT(RT_DEBUG_TRACE, ("Set::(MimoPs = %d)(AmsduEnable = %d) (AmsduSize=%d)(MpduDensity=%d)\n",pAdapter->CommonCfg.DesiredHtPhy.MimoPs, pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable,
4085 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize, pAdapter->CommonCfg.DesiredHtPhy.MpduDensity));
4089 case RT_OID_802_11_ADD_IMME_BA:
4090 DBGPRINT(RT_DEBUG_TRACE, (" Set :: RT_OID_802_11_ADD_IMME_BA \n"));
4091 if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
4096 OID_ADD_BA_ENTRY BA;
4097 MAC_TABLE_ENTRY *pEntry;
4099 Status = copy_from_user(&BA, wrq->u.data.pointer, wrq->u.data.length);
4102 Status = NDIS_STATUS_INVALID_DATA;
4107 //BATableInsertEntry
4108 //As ad-hoc mode, BA pair is not limited to only BSSID. so add via OID.
4110 // in ad hoc mode, when adding BA pair, we should insert this entry into MACEntry too
4111 pEntry = MacTableLookup(pAdapter, BA.MACAddr);
4114 DBGPRINT(RT_DEBUG_TRACE, ("RT_OID_802_11_ADD_IMME_BA. break on no connection.----:%x:%x\n", BA.MACAddr[4], BA.MACAddr[5]));
4117 if (BA.IsRecipient == FALSE)
4119 if (pEntry->bIAmBadAtheros == TRUE)
4120 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = 0x10;
4122 BAOriSessionSetUp(pAdapter, pEntry, index, 0, 100, TRUE);
4126 //BATableInsertEntry(pAdapter, pEntry->Aid, BA.MACAddr, 0, 0xffff, BA.TID, BA.nMSDU, BA.IsRecipient);
4129 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_IMME_BA. Rec = %d. Mac = %x:%x:%x:%x:%x:%x . \n",
4130 BA.IsRecipient, BA.MACAddr[0], BA.MACAddr[1], BA.MACAddr[2], BA.MACAddr[2]
4131 , BA.MACAddr[4], BA.MACAddr[5]));
4136 case RT_OID_802_11_TEAR_IMME_BA:
4137 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA \n"));
4138 if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
4142 POID_ADD_BA_ENTRY pBA;
4143 MAC_TABLE_ENTRY *pEntry;
4145 pBA = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4149 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA kmalloc() can't allocate enough memory\n"));
4150 Status = NDIS_STATUS_FAILURE;
4154 Status = copy_from_user(pBA, wrq->u.data.pointer, wrq->u.data.length);
4155 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA(TID=%d, bAllTid=%d)\n", pBA->TID, pBA->bAllTid));
4157 if (!pBA->bAllTid && (pBA->TID > NUM_OF_TID))
4159 Status = NDIS_STATUS_INVALID_DATA;
4163 if (pBA->IsRecipient == FALSE)
4165 pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
4166 DBGPRINT(RT_DEBUG_TRACE, (" pBA->IsRecipient == FALSE\n"));
4169 DBGPRINT(RT_DEBUG_TRACE, (" pBA->pEntry\n"));
4170 BAOriSessionTearDown(pAdapter, pEntry->Aid, pBA->TID, FALSE, TRUE);
4173 DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
4177 pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
4180 BARecSessionTearDown( pAdapter, (UCHAR)pEntry->Aid, pBA->TID, TRUE);
4183 DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
4189 // For WPA_SUPPLICANT to set static wep key
4190 case OID_802_11_ADD_WEP:
4191 pWepKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4196 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed!!\n"));
4199 Status = copy_from_user(pWepKey, wrq->u.data.pointer, wrq->u.data.length);
4203 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (length mismatch)!!\n"));
4207 KeyIdx = pWepKey->KeyIndex & 0x0fffffff;
4208 // KeyIdx must be 0 ~ 3
4212 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (KeyIdx must be smaller than 4)!!\n"));
4216 UCHAR CipherAlg = 0;
4219 // set key material and key length
4220 NdisZeroMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, 16);
4221 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
4222 NdisMoveMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
4224 switch(pWepKey->KeyLength)
4227 CipherAlg = CIPHER_WEP64;
4230 CipherAlg = CIPHER_WEP128;
4233 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, only support CIPHER_WEP64(len:5) & CIPHER_WEP128(len:13)!!\n"));
4237 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CipherAlg;
4239 // Default key for tx (shared key)
4240 if (pWepKey->KeyIndex & 0x80000000)
4242 // set key material and key length
4243 NdisZeroMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, 16);
4244 pAdapter->StaCfg.DesireSharedKey[KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
4245 NdisMoveMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
4246 pAdapter->StaCfg.DesireSharedKeyId = KeyIdx;
4247 pAdapter->StaCfg.DesireSharedKey[KeyIdx].CipherAlg = CipherAlg;
4248 pAdapter->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
4252 if ((pAdapter->StaCfg.WpaSupplicantUP != 0) &&
4255 if ((pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE) &&
4257 (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA))
4259 Key = pWepKey->KeyMaterial;
4261 // Set Group key material to Asic
4262 AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
4264 // Update WCID attribute table and IVEIV table for this group key table
4265 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
4267 STA_PORT_SECURED(pAdapter);
4269 // Indicate Connected for GUI
4270 pAdapter->IndicateMediaState = NdisMediaStateConnected;
4272 else if (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)
4275 if (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)
4278 Key = pAdapter->SharedKey[BSS0][KeyIdx].Key;
4280 // Set key material and cipherAlg to Asic
4281 AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
4283 if (pWepKey->KeyIndex & 0x80000000)
4285 PMAC_TABLE_ENTRY pEntry = &pAdapter->MacTab.Content[BSSID_WCID];
4286 // Assign group key info
4287 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
4288 // Assign pairwise key info
4289 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, pEntry);
4292 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"));
4297 case OID_SET_COUNTERMEASURES:
4298 if (wrq->u.data.length != sizeof(int))
4303 Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
4305 pAdapter->StaCfg.bBlockAssoc = TRUE;
4307 // WPA MIC error should block association attempt for 60 seconds
4308 pAdapter->StaCfg.bBlockAssoc = FALSE;
4309 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_SET_COUNTERMEASURES bBlockAssoc=%s\n", pAdapter->StaCfg.bBlockAssoc ? "TRUE":"FALSE"));
4312 case RT_OID_WPA_SUPPLICANT_SUPPORT:
4313 if (wrq->u.data.length != sizeof(UCHAR))
4317 Status = copy_from_user(&wpa_supplicant_enable, wrq->u.data.pointer, wrq->u.data.length);
4318 pAdapter->StaCfg.WpaSupplicantUP = wpa_supplicant_enable;
4319 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
4322 case OID_802_11_DEAUTHENTICATION:
4323 if (wrq->u.data.length != sizeof(MLME_DEAUTH_REQ_STRUCT))
4327 MLME_DEAUTH_REQ_STRUCT *pInfo;
4328 MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
4330 pInfo = (MLME_DEAUTH_REQ_STRUCT *) MsgElem->Msg;
4331 Status = copy_from_user(pInfo, wrq->u.data.pointer, wrq->u.data.length);
4332 MlmeDeauthReqAction(pAdapter, MsgElem);
4335 if (INFRA_ON(pAdapter))
4337 LinkDown(pAdapter, FALSE);
4338 pAdapter->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
4340 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DEAUTHENTICATION (Reason=%d)\n", pInfo->Reason));
4343 case OID_802_11_DROP_UNENCRYPTED:
4344 if (wrq->u.data.length != sizeof(int))
4349 Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
4351 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
4353 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
4354 NdisAcquireSpinLock(&pAdapter->MacTabLock);
4355 pAdapter->MacTab.Content[BSSID_WCID].PortSecured = pAdapter->StaCfg.PortSecured;
4356 NdisReleaseSpinLock(&pAdapter->MacTabLock);
4357 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DROP_UNENCRYPTED (=%d)\n", enabled));
4360 case OID_802_11_SET_IEEE8021X:
4361 if (wrq->u.data.length != sizeof(BOOLEAN))
4365 Status = copy_from_user(&IEEE8021xState, wrq->u.data.pointer, wrq->u.data.length);
4366 pAdapter->StaCfg.IEEE8021X = IEEE8021xState;
4367 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X (=%d)\n", IEEE8021xState));
4370 case OID_802_11_SET_IEEE8021X_REQUIRE_KEY:
4371 if (wrq->u.data.length != sizeof(BOOLEAN))
4375 Status = copy_from_user(&IEEE8021x_required_keys, wrq->u.data.pointer, wrq->u.data.length);
4376 pAdapter->StaCfg.IEEE8021x_required_keys = IEEE8021x_required_keys;
4377 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X_REQUIRE_KEY (%d)\n", IEEE8021x_required_keys));
4380 case OID_802_11_PMKID:
4381 pPmkId = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4383 if(pPmkId == NULL) {
4387 Status = copy_from_user(pPmkId, wrq->u.data.pointer, wrq->u.data.length);
4389 // check the PMKID information
4390 if (pPmkId->BSSIDInfoCount == 0)
4391 NdisZeroMemory(pAdapter->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
4394 PBSSID_INFO pBssIdInfo;
4398 for (BssIdx = 0; BssIdx < pPmkId->BSSIDInfoCount; BssIdx++)
4400 // point to the indexed BSSID_INFO structure
4401 pBssIdInfo = (PBSSID_INFO) ((PUCHAR) pPmkId + 2 * sizeof(UINT) + BssIdx * sizeof(BSSID_INFO));
4402 // Find the entry in the saved data base.
4403 for (CachedIdx = 0; CachedIdx < pAdapter->StaCfg.SavedPMKNum; CachedIdx++)
4405 // compare the BSSID
4406 if (NdisEqualMemory(pBssIdInfo->BSSID, pAdapter->StaCfg.SavedPMK[CachedIdx].BSSID, sizeof(NDIS_802_11_MAC_ADDRESS)))
4410 // Found, replace it
4411 if (CachedIdx < PMKID_NO)
4413 DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
4414 NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
4415 pAdapter->StaCfg.SavedPMKNum++;
4417 // Not found, replace the last one
4420 // Randomly replace one
4421 CachedIdx = (pBssIdInfo->BSSID[5] % PMKID_NO);
4422 DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
4423 NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
4431 DBGPRINT(RT_DEBUG_TRACE, ("Set::unknown IOCTL's subcmd = 0x%08x\n", cmd));
4432 Status = -EOPNOTSUPP;
4440 INT RTMPQueryInformation(
4441 IN PRTMP_ADAPTER pAdapter,
4442 IN OUT struct ifreq *rq,
4445 struct iwreq *wrq = (struct iwreq *) rq;
4446 NDIS_802_11_BSSID_LIST_EX *pBssidList = NULL;
4447 PNDIS_WLAN_BSSID_EX pBss;
4448 NDIS_802_11_SSID Ssid;
4449 NDIS_802_11_CONFIGURATION *pConfiguration = NULL;
4450 RT_802_11_LINK_STATUS *pLinkStatus = NULL;
4451 RT_802_11_STA_CONFIG *pStaConfig = NULL;
4452 NDIS_802_11_STATISTICS *pStatistics = NULL;
4453 NDIS_802_11_RTS_THRESHOLD RtsThresh;
4454 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
4455 NDIS_802_11_POWER_MODE PowerMode;
4456 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
4457 RT_802_11_PREAMBLE PreamType;
4458 NDIS_802_11_AUTHENTICATION_MODE AuthMode;
4459 NDIS_802_11_WEP_STATUS WepStatus;
4460 NDIS_MEDIA_STATE MediaState;
4461 ULONG BssBufSize, ulInfo=0, NetworkTypeList[4], apsd = 0;
4463 PUCHAR pBuf = NULL, pPtr;
4464 INT Status = NDIS_STATUS_SUCCESS;
4465 UINT we_version_compiled;
4466 UCHAR i, Padding = 0;
4468 UCHAR driverVersion[8];
4469 OID_SET_HT_PHYMODE *pHTPhyMode = NULL;
4473 case RT_OID_DEVICE_NAME:
4474 wrq->u.data.length = sizeof(STA_NIC_DEVICE_NAME);
4475 Status = copy_to_user(wrq->u.data.pointer, STA_NIC_DEVICE_NAME, wrq->u.data.length);
4477 case RT_OID_VERSION_INFO:
4478 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_VERSION_INFO \n"));
4479 wrq->u.data.length = 8*sizeof(UCHAR);
4480 sprintf(&driverVersion[0], "%s", STA_DRIVER_VERSION);
4481 driverVersion[7] = '\0';
4482 if (copy_to_user(wrq->u.data.pointer, &driverVersion, wrq->u.data.length))
4487 case OID_802_11_BSSID_LIST:
4488 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
4491 * Still scanning, indicate the caller should try again.
4493 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (Still scanning)\n"));
4496 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (%d BSS returned)\n",pAdapter->ScanTab.BssNr));
4497 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
4498 // Claculate total buffer size required
4499 BssBufSize = sizeof(ULONG);
4501 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
4503 // Align pointer to 4 bytes boundary.
4504 //Padding = 4 - (pAdapter->ScanTab.BssEntry[i].VarIELen & 0x0003);
4507 BssBufSize += (sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
4510 // For safety issue, we add 256 bytes just in case
4512 // Allocate the same size as passed from higher layer
4513 pBuf = kmalloc(BssBufSize, MEM_ALLOC_FLAG);
4519 // Init 802_11_BSSID_LIST_EX structure
4520 NdisZeroMemory(pBuf, BssBufSize);
4521 pBssidList = (PNDIS_802_11_BSSID_LIST_EX) pBuf;
4522 pBssidList->NumberOfItems = pAdapter->ScanTab.BssNr;
4524 // Calculate total buffer length
4525 BssLen = 4; // Consist of NumberOfItems
4526 // Point to start of NDIS_WLAN_BSSID_EX
4527 // pPtr = pBuf + sizeof(ULONG);
4528 pPtr = (PUCHAR) &pBssidList->Bssid[0];
4529 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
4531 pBss = (PNDIS_WLAN_BSSID_EX) pPtr;
4532 NdisMoveMemory(&pBss->MacAddress, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
4533 if ((pAdapter->ScanTab.BssEntry[i].Hidden == 1) && (pAdapter->StaCfg.bShowHiddenSSID == FALSE))
4536 // We must return this SSID during 4way handshaking, otherwise Aegis will failed to parse WPA infomation
4537 // and then failed to send EAPOl farame.
4539 if ((pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) && (pAdapter->StaCfg.PortSecured != WPA_802_1X_PORT_SECURED))
4541 pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
4542 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
4545 pBss->Ssid.SsidLength = 0;
4549 pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
4550 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
4552 pBss->Privacy = pAdapter->ScanTab.BssEntry[i].Privacy;
4553 pBss->Rssi = pAdapter->ScanTab.BssEntry[i].Rssi - pAdapter->BbpRssiToDbmDelta;
4554 pBss->NetworkTypeInUse = NetworkTypeInUseSanity(&pAdapter->ScanTab.BssEntry[i]);
4555 pBss->Configuration.Length = sizeof(NDIS_802_11_CONFIGURATION);
4556 pBss->Configuration.BeaconPeriod = pAdapter->ScanTab.BssEntry[i].BeaconPeriod;
4557 pBss->Configuration.ATIMWindow = pAdapter->ScanTab.BssEntry[i].AtimWin;
4559 MAP_CHANNEL_ID_TO_KHZ(pAdapter->ScanTab.BssEntry[i].Channel, pBss->Configuration.DSConfig);
4561 if (pAdapter->ScanTab.BssEntry[i].BssType == BSS_INFRA)
4562 pBss->InfrastructureMode = Ndis802_11Infrastructure;
4564 pBss->InfrastructureMode = Ndis802_11IBSS;
4566 NdisMoveMemory(pBss->SupportedRates, pAdapter->ScanTab.BssEntry[i].SupRate, pAdapter->ScanTab.BssEntry[i].SupRateLen);
4567 NdisMoveMemory(pBss->SupportedRates + pAdapter->ScanTab.BssEntry[i].SupRateLen,
4568 pAdapter->ScanTab.BssEntry[i].ExtRate,
4569 pAdapter->ScanTab.BssEntry[i].ExtRateLen);
4571 if (pAdapter->ScanTab.BssEntry[i].VarIELen == 0)
4573 pBss->IELength = sizeof(NDIS_802_11_FIXED_IEs);
4574 NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
4575 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
4579 pBss->IELength = (ULONG)(sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen);
4580 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
4581 NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
4582 NdisMoveMemory(pBss->IEs + sizeof(NDIS_802_11_FIXED_IEs), pAdapter->ScanTab.BssEntry[i].VarIEs, pAdapter->ScanTab.BssEntry[i].VarIELen);
4583 pPtr += pAdapter->ScanTab.BssEntry[i].VarIELen;
4585 pBss->Length = (ULONG)(sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
4587 #if WIRELESS_EXT < 17
4588 if ((BssLen + pBss->Length) < wrq->u.data.length)
4589 BssLen += pBss->Length;
4592 pBssidList->NumberOfItems = i;
4596 BssLen += pBss->Length;
4600 #if WIRELESS_EXT < 17
4601 wrq->u.data.length = BssLen;
4603 if (BssLen > wrq->u.data.length)
4609 wrq->u.data.length = BssLen;
4611 Status = copy_to_user(wrq->u.data.pointer, pBssidList, BssLen);
4614 case OID_802_3_CURRENT_ADDRESS:
4615 wrq->u.data.length = MAC_ADDR_LEN;
4616 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
4618 case OID_GEN_MEDIA_CONNECT_STATUS:
4619 if (pAdapter->IndicateMediaState == NdisMediaStateConnected)
4620 MediaState = NdisMediaStateConnected;
4622 MediaState = NdisMediaStateDisconnected;
4624 wrq->u.data.length = sizeof(NDIS_MEDIA_STATE);
4625 Status = copy_to_user(wrq->u.data.pointer, &MediaState, wrq->u.data.length);
4627 case OID_802_11_BSSID:
4628 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
4630 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Bssid, sizeof(NDIS_802_11_MAC_ADDRESS));
4635 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID(=EMPTY)\n"));
4639 case OID_802_11_SSID:
4640 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
4641 NdisZeroMemory(Ssid.Ssid, MAX_LEN_OF_SSID);
4642 Ssid.SsidLength = pAdapter->CommonCfg.SsidLen;
4643 memcpy(Ssid.Ssid, pAdapter->CommonCfg.Ssid, Ssid.SsidLength);
4644 wrq->u.data.length = sizeof(NDIS_802_11_SSID);
4645 Status = copy_to_user(wrq->u.data.pointer, &Ssid, wrq->u.data.length);
4646 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_SSID (Len=%d, ssid=%s)\n", Ssid.SsidLength,Ssid.Ssid));
4648 case RT_OID_802_11_QUERY_LINK_STATUS:
4649 pLinkStatus = (RT_802_11_LINK_STATUS *) kmalloc(sizeof(RT_802_11_LINK_STATUS), MEM_ALLOC_FLAG);
4652 pLinkStatus->CurrTxRate = RateIdTo500Kbps[pAdapter->CommonCfg.TxRate]; // unit : 500 kbps
4653 pLinkStatus->ChannelQuality = pAdapter->Mlme.ChannelQuality;
4654 pLinkStatus->RxByteCount = pAdapter->RalinkCounters.ReceivedByteCount;
4655 pLinkStatus->TxByteCount = pAdapter->RalinkCounters.TransmittedByteCount;
4656 pLinkStatus->CentralChannel = pAdapter->CommonCfg.CentralChannel;
4657 wrq->u.data.length = sizeof(RT_802_11_LINK_STATUS);
4658 Status = copy_to_user(wrq->u.data.pointer, pLinkStatus, wrq->u.data.length);
4660 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS\n"));
4664 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS(kmalloc failed)\n"));
4668 case OID_802_11_CONFIGURATION:
4669 pConfiguration = (NDIS_802_11_CONFIGURATION *) kmalloc(sizeof(NDIS_802_11_CONFIGURATION), MEM_ALLOC_FLAG);
4672 pConfiguration->Length = sizeof(NDIS_802_11_CONFIGURATION);
4673 pConfiguration->BeaconPeriod = pAdapter->CommonCfg.BeaconPeriod;
4674 pConfiguration->ATIMWindow = pAdapter->StaActive.AtimWin;
4675 MAP_CHANNEL_ID_TO_KHZ(pAdapter->CommonCfg.Channel, pConfiguration->DSConfig);
4676 wrq->u.data.length = sizeof(NDIS_802_11_CONFIGURATION);
4677 Status = copy_to_user(wrq->u.data.pointer, pConfiguration, wrq->u.data.length);
4678 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(BeaconPeriod=%ld,AtimW=%ld,Channel=%d) \n",
4679 pConfiguration->BeaconPeriod, pConfiguration->ATIMWindow, pAdapter->CommonCfg.Channel));
4680 kfree(pConfiguration);
4684 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(kmalloc failed)\n"));
4688 case RT_OID_802_11_SNR_0:
4689 if ((pAdapter->StaCfg.LastSNR0 > 0))
4691 ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR0) * 3) / 16 ;
4692 wrq->u.data.length = sizeof(ulInfo);
4693 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4694 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_SNR_0(0x=%lx)\n", ulInfo));
4699 case RT_OID_802_11_SNR_1:
4700 if ((pAdapter->Antenna.field.RxPath > 1) &&
4701 (pAdapter->StaCfg.LastSNR1 > 0))
4703 ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR1) * 3) / 16 ;
4704 wrq->u.data.length = sizeof(ulInfo);
4705 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4706 DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(0x=%lx)\n",ulInfo));
4710 DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(pAdapter->StaCfg.LastSNR1=%d)\n",pAdapter->StaCfg.LastSNR1));
4712 case OID_802_11_RSSI_TRIGGER:
4713 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0 - pAdapter->BbpRssiToDbmDelta;
4714 wrq->u.data.length = sizeof(ulInfo);
4715 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4716 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RSSI_TRIGGER(=%ld)\n", ulInfo));
4718 case OID_802_11_RSSI:
4719 case RT_OID_802_11_RSSI:
4720 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0;
4721 wrq->u.data.length = sizeof(ulInfo);
4722 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4724 case RT_OID_802_11_RSSI_1:
4725 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi1;
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_2:
4730 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi2;
4731 wrq->u.data.length = sizeof(ulInfo);
4732 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4734 case OID_802_11_STATISTICS:
4735 pStatistics = (NDIS_802_11_STATISTICS *) kmalloc(sizeof(NDIS_802_11_STATISTICS), MEM_ALLOC_FLAG);
4738 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS \n"));
4739 // add the most up-to-date h/w raw counters into software counters
4740 NICUpdateRawCounters(pAdapter);
4742 // Sanity check for calculation of sucessful count
4743 if (pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart < pAdapter->WlanCounters.RetryCount.QuadPart)
4744 pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
4746 pStatistics->TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart;
4747 pStatistics->MulticastTransmittedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastTransmittedFrameCount.QuadPart;
4748 pStatistics->FailedCount.QuadPart = pAdapter->WlanCounters.FailedCount.QuadPart;
4749 pStatistics->RetryCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
4750 pStatistics->MultipleRetryCount.QuadPart = pAdapter->WlanCounters.MultipleRetryCount.QuadPart;
4751 pStatistics->RTSSuccessCount.QuadPart = pAdapter->WlanCounters.RTSSuccessCount.QuadPart;
4752 pStatistics->RTSFailureCount.QuadPart = pAdapter->WlanCounters.RTSFailureCount.QuadPart;
4753 pStatistics->ACKFailureCount.QuadPart = pAdapter->WlanCounters.ACKFailureCount.QuadPart;
4754 pStatistics->FrameDuplicateCount.QuadPart = pAdapter->WlanCounters.FrameDuplicateCount.QuadPart;
4755 pStatistics->ReceivedFragmentCount.QuadPart = pAdapter->WlanCounters.ReceivedFragmentCount.QuadPart;
4756 pStatistics->MulticastReceivedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastReceivedFrameCount.QuadPart;
4758 pStatistics->FCSErrorCount = pAdapter->RalinkCounters.RealFcsErrCount;
4760 pStatistics->FCSErrorCount.QuadPart = pAdapter->WlanCounters.FCSErrorCount.QuadPart;
4761 pStatistics->FrameDuplicateCount.u.LowPart = pAdapter->WlanCounters.FrameDuplicateCount.u.LowPart / 100;
4763 wrq->u.data.length = sizeof(NDIS_802_11_STATISTICS);
4764 Status = copy_to_user(wrq->u.data.pointer, pStatistics, wrq->u.data.length);
4769 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS(kmalloc failed)\n"));
4773 case OID_GEN_RCV_OK:
4774 ulInfo = pAdapter->Counters8023.GoodReceives;
4775 wrq->u.data.length = sizeof(ulInfo);
4776 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4778 case OID_GEN_RCV_NO_BUFFER:
4779 ulInfo = pAdapter->Counters8023.RxNoBuffer;
4780 wrq->u.data.length = sizeof(ulInfo);
4781 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4783 case RT_OID_802_11_PHY_MODE:
4784 ulInfo = (ULONG)pAdapter->CommonCfg.PhyMode;
4785 wrq->u.data.length = sizeof(ulInfo);
4786 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4787 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PHY_MODE (=%ld)\n", ulInfo));
4789 case RT_OID_802_11_STA_CONFIG:
4790 pStaConfig = (RT_802_11_STA_CONFIG *) kmalloc(sizeof(RT_802_11_STA_CONFIG), MEM_ALLOC_FLAG);
4793 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG\n"));
4794 pStaConfig->EnableTxBurst = pAdapter->CommonCfg.bEnableTxBurst;
4795 pStaConfig->EnableTurboRate = 0;
4796 pStaConfig->UseBGProtection = pAdapter->CommonCfg.UseBGProtection;
4797 pStaConfig->UseShortSlotTime = pAdapter->CommonCfg.bUseShortSlotTime;
4798 //pStaConfig->AdhocMode = pAdapter->StaCfg.AdhocMode;
4799 pStaConfig->HwRadioStatus = (pAdapter->StaCfg.bHwRadio == TRUE) ? 1 : 0;
4800 pStaConfig->Rsv1 = 0;
4801 pStaConfig->SystemErrorBitmap = pAdapter->SystemErrorBitmap;
4802 wrq->u.data.length = sizeof(RT_802_11_STA_CONFIG);
4803 Status = copy_to_user(wrq->u.data.pointer, pStaConfig, wrq->u.data.length);
4808 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
4812 case OID_802_11_RTS_THRESHOLD:
4813 RtsThresh = pAdapter->CommonCfg.RtsThreshold;
4814 wrq->u.data.length = sizeof(RtsThresh);
4815 Status = copy_to_user(wrq->u.data.pointer, &RtsThresh, wrq->u.data.length);
4816 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RTS_THRESHOLD(=%ld)\n", RtsThresh));
4818 case OID_802_11_FRAGMENTATION_THRESHOLD:
4819 FragThresh = pAdapter->CommonCfg.FragmentThreshold;
4820 if (pAdapter->CommonCfg.bUseZeroToDisableFragment == TRUE)
4822 wrq->u.data.length = sizeof(FragThresh);
4823 Status = copy_to_user(wrq->u.data.pointer, &FragThresh, wrq->u.data.length);
4824 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_FRAGMENTATION_THRESHOLD(=%ld)\n", FragThresh));
4826 case OID_802_11_POWER_MODE:
4827 PowerMode = pAdapter->StaCfg.WindowsPowerMode;
4828 wrq->u.data.length = sizeof(PowerMode);
4829 Status = copy_to_user(wrq->u.data.pointer, &PowerMode, wrq->u.data.length);
4830 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_POWER_MODE(=%d)\n", PowerMode));
4832 case RT_OID_802_11_RADIO:
4833 RadioState = (BOOLEAN) pAdapter->StaCfg.bSwRadio;
4834 wrq->u.data.length = sizeof(RadioState);
4835 Status = copy_to_user(wrq->u.data.pointer, &RadioState, wrq->u.data.length);
4836 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_RADIO (=%d)\n", RadioState));
4838 case OID_802_11_INFRASTRUCTURE_MODE:
4839 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
4840 BssType = Ndis802_11IBSS;
4841 else if (pAdapter->StaCfg.BssType == BSS_INFRA)
4842 BssType = Ndis802_11Infrastructure;
4843 else if (pAdapter->StaCfg.BssType == BSS_MONITOR)
4844 BssType = Ndis802_11Monitor;
4846 BssType = Ndis802_11AutoUnknown;
4848 wrq->u.data.length = sizeof(BssType);
4849 Status = copy_to_user(wrq->u.data.pointer, &BssType, wrq->u.data.length);
4850 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_INFRASTRUCTURE_MODE(=%d)\n", BssType));
4852 case RT_OID_802_11_PREAMBLE:
4853 PreamType = pAdapter->CommonCfg.TxPreamble;
4854 wrq->u.data.length = sizeof(PreamType);
4855 Status = copy_to_user(wrq->u.data.pointer, &PreamType, wrq->u.data.length);
4856 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PREAMBLE(=%d)\n", PreamType));
4858 case OID_802_11_AUTHENTICATION_MODE:
4859 AuthMode = pAdapter->StaCfg.AuthMode;
4860 wrq->u.data.length = sizeof(AuthMode);
4861 Status = copy_to_user(wrq->u.data.pointer, &AuthMode, wrq->u.data.length);
4862 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_AUTHENTICATION_MODE(=%d)\n", AuthMode));
4864 case OID_802_11_WEP_STATUS:
4865 WepStatus = pAdapter->StaCfg.WepStatus;
4866 wrq->u.data.length = sizeof(WepStatus);
4867 Status = copy_to_user(wrq->u.data.pointer, &WepStatus, wrq->u.data.length);
4868 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_WEP_STATUS(=%d)\n", WepStatus));
4870 case OID_802_11_TX_POWER_LEVEL:
4871 wrq->u.data.length = sizeof(ULONG);
4872 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPower, wrq->u.data.length);
4873 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_TX_POWER_LEVEL %x\n",pAdapter->CommonCfg.TxPower));
4875 case RT_OID_802_11_TX_POWER_LEVEL_1:
4876 wrq->u.data.length = sizeof(ULONG);
4877 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPowerPercentage, wrq->u.data.length);
4878 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
4880 case OID_802_11_NETWORK_TYPES_SUPPORTED:
4881 if ((pAdapter->RfIcType == RFIC_2850) || (pAdapter->RfIcType == RFIC_2750))
4883 NetworkTypeList[0] = 3; // NumberOfItems = 3
4884 NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
4885 NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
4886 NetworkTypeList[3] = Ndis802_11OFDM5; // NetworkType[3] = 11a
4887 wrq->u.data.length = 16;
4888 Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
4892 NetworkTypeList[0] = 2; // NumberOfItems = 2
4893 NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
4894 NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
4895 wrq->u.data.length = 12;
4896 Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
4898 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_NETWORK_TYPES_SUPPORTED\n"));
4900 case OID_802_11_NETWORK_TYPE_IN_USE:
4901 wrq->u.data.length = sizeof(ULONG);
4902 if (pAdapter->CommonCfg.PhyMode == PHY_11A)
4903 ulInfo = Ndis802_11OFDM5;
4904 else if ((pAdapter->CommonCfg.PhyMode == PHY_11BG_MIXED) || (pAdapter->CommonCfg.PhyMode == PHY_11G))
4905 ulInfo = Ndis802_11OFDM24;
4907 ulInfo = Ndis802_11DS;
4908 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4910 case RT_OID_802_11_QUERY_LAST_RX_RATE:
4911 ulInfo = (ULONG)pAdapter->LastRxRate;
4912 wrq->u.data.length = sizeof(ulInfo);
4913 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4914 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_RX_RATE (=%ld)\n", ulInfo));
4916 case RT_OID_802_11_QUERY_LAST_TX_RATE:
4917 //ulInfo = (ULONG)pAdapter->LastTxRate;
4918 ulInfo = (ULONG)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word;
4919 wrq->u.data.length = sizeof(ulInfo);
4920 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4921 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_TX_RATE (=%lx)\n", ulInfo));
4923 case RT_OID_802_11_QUERY_EEPROM_VERSION:
4924 wrq->u.data.length = sizeof(ULONG);
4925 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->EepromVersion, wrq->u.data.length);
4927 case RT_OID_802_11_QUERY_FIRMWARE_VERSION:
4928 wrq->u.data.length = sizeof(ULONG);
4929 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->FirmwareVersion, wrq->u.data.length);
4931 case RT_OID_802_11_QUERY_NOISE_LEVEL:
4932 wrq->u.data.length = sizeof(UCHAR);
4933 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->BbpWriteLatch[66], wrq->u.data.length);
4934 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_NOISE_LEVEL (=%d)\n", pAdapter->BbpWriteLatch[66]));
4936 case RT_OID_802_11_EXTRA_INFO:
4937 wrq->u.data.length = sizeof(ULONG);
4938 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->ExtraInfo, wrq->u.data.length);
4939 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_EXTRA_INFO (=%ld)\n", pAdapter->ExtraInfo));
4941 case RT_OID_WE_VERSION_COMPILED:
4942 wrq->u.data.length = sizeof(UINT);
4943 we_version_compiled = WIRELESS_EXT;
4944 Status = copy_to_user(wrq->u.data.pointer, &we_version_compiled, wrq->u.data.length);
4946 case RT_OID_802_11_QUERY_APSD_SETTING:
4947 apsd = (pAdapter->CommonCfg.bAPSDCapable | (pAdapter->CommonCfg.bAPSDAC_BE << 1) | (pAdapter->CommonCfg.bAPSDAC_BK << 2)
4948 | (pAdapter->CommonCfg.bAPSDAC_VI << 3) | (pAdapter->CommonCfg.bAPSDAC_VO << 4) | (pAdapter->CommonCfg.MaxSPLength << 5));
4950 wrq->u.data.length = sizeof(ULONG);
4951 Status = copy_to_user(wrq->u.data.pointer, &apsd, wrq->u.data.length);
4952 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",
4953 apsd,pAdapter->CommonCfg.bAPSDCapable,pAdapter->CommonCfg.bAPSDAC_BE,pAdapter->CommonCfg.bAPSDAC_BK,pAdapter->CommonCfg.bAPSDAC_VI,pAdapter->CommonCfg.bAPSDAC_VO,pAdapter->CommonCfg.MaxSPLength));
4955 case RT_OID_802_11_QUERY_APSD_PSM:
4956 wrq->u.data.length = sizeof(ULONG);
4957 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.length);
4958 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_APSD_PSM (=%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
4960 case RT_OID_802_11_QUERY_WMM:
4961 wrq->u.data.length = sizeof(BOOLEAN);
4962 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bWmmCapable, wrq->u.data.length);
4963 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_WMM (=%d)\n", pAdapter->CommonCfg.bWmmCapable));
4965 case RT_OID_NEW_DRIVER:
4968 wrq->u.data.length = sizeof(UCHAR);
4969 Status = copy_to_user(wrq->u.data.pointer, &enabled, wrq->u.data.length);
4970 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_NEW_DRIVER (=%d)\n", enabled));
4973 case RT_OID_WPA_SUPPLICANT_SUPPORT:
4974 wrq->u.data.length = sizeof(UCHAR);
4975 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->StaCfg.WpaSupplicantUP, wrq->u.data.length);
4976 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
4978 case RT_OID_DRIVER_DEVICE_NAME:
4979 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_DRIVER_DEVICE_NAME \n"));
4980 wrq->u.data.length = 16;
4981 if (copy_to_user(wrq->u.data.pointer, pAdapter->StaCfg.dev_name, wrq->u.data.length))
4986 case RT_OID_802_11_QUERY_HT_PHYMODE:
4987 pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
4990 pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
4991 pHTPhyMode->HtMode = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE;
4992 pHTPhyMode->BW = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.BW;
4993 pHTPhyMode->MCS= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MCS;
4994 pHTPhyMode->SHORTGI= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.ShortGI;
4995 pHTPhyMode->STBC= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.STBC;
4997 pHTPhyMode->ExtOffset = ((pAdapter->CommonCfg.CentralChannel < pAdapter->CommonCfg.Channel) ? (EXTCHA_BELOW) : (EXTCHA_ABOVE));
4998 wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
4999 if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
5003 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
5004 pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
5005 DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
5009 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
5013 case RT_OID_802_11_COUNTRY_REGION:
5014 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_COUNTRY_REGION \n"));
5015 wrq->u.data.length = sizeof(ulInfo);
5016 ulInfo = pAdapter->CommonCfg.CountryRegionForABand;
5017 ulInfo = (ulInfo << 8)|(pAdapter->CommonCfg.CountryRegion);
5018 if (copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length))
5023 case RT_OID_802_11_QUERY_DAT_HT_PHYMODE:
5024 pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
5027 pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
5028 pHTPhyMode->HtMode = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.HTMODE;
5029 pHTPhyMode->BW = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.BW;
5030 pHTPhyMode->MCS= (UCHAR)pAdapter->StaCfg.DesiredTransmitSetting.field.MCS;
5031 pHTPhyMode->SHORTGI= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.ShortGI;
5032 pHTPhyMode->STBC= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.STBC;
5034 wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
5035 if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
5039 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
5040 pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
5041 DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
5045 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
5049 case RT_OID_QUERY_MULTIPLE_CARD_SUPPORT:
5050 wrq->u.data.length = sizeof(UCHAR);
5052 if (copy_to_user(wrq->u.data.pointer, &i, wrq->u.data.length))
5056 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_QUERY_MULTIPLE_CARD_SUPPORT(=%d) \n", i));
5059 case OID_802_11_BUILD_CHANNEL_EX:
5062 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BUILD_CHANNEL_EX \n"));
5063 wrq->u.data.length = sizeof(UCHAR);
5064 DBGPRINT(RT_DEBUG_TRACE, ("Doesn't support EXT_BUILD_CHANNEL_LIST.\n"));
5066 Status = copy_to_user(wrq->u.data.pointer, &value, 1);
5067 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5071 case OID_802_11_GET_CH_LIST:
5073 PRT_CHANNEL_LIST_INFO pChListBuf;
5075 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CH_LIST \n"));
5076 if (pAdapter->ChannelListNum == 0)
5078 wrq->u.data.length = 0;
5082 pChListBuf = (RT_CHANNEL_LIST_INFO *) kmalloc(sizeof(RT_CHANNEL_LIST_INFO), MEM_ALLOC_FLAG);
5083 if (pChListBuf == NULL)
5085 wrq->u.data.length = 0;
5089 pChListBuf->ChannelListNum = pAdapter->ChannelListNum;
5090 for (i = 0; i < pChListBuf->ChannelListNum; i++)
5091 pChListBuf->ChannelList[i] = pAdapter->ChannelList[i].Channel;
5093 wrq->u.data.length = sizeof(RT_CHANNEL_LIST_INFO);
5094 Status = copy_to_user(wrq->u.data.pointer, pChListBuf, sizeof(RT_CHANNEL_LIST_INFO));
5095 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5102 case OID_802_11_GET_COUNTRY_CODE:
5103 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_COUNTRY_CODE \n"));
5104 wrq->u.data.length = 2;
5105 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.CountryCode, 2);
5106 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5109 case OID_802_11_GET_CHANNEL_GEOGRAPHY:
5110 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CHANNEL_GEOGRAPHY \n"));
5111 wrq->u.data.length = 1;
5112 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Geography, 1);
5113 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5117 DBGPRINT(RT_DEBUG_TRACE, ("Query::unknown IOCTL's subcmd = 0x%08x\n", cmd));
5118 Status = -EOPNOTSUPP;
5124 INT rt28xx_sta_ioctl(
5125 IN struct net_device *net_dev,
5126 IN OUT struct ifreq *rq,
5130 VIRTUAL_ADAPTER *pVirtualAd = NULL;
5131 RTMP_ADAPTER *pAd = NULL;
5132 struct iwreq *wrq = (struct iwreq *) rq;
5133 BOOLEAN StateMachineTouched = FALSE;
5134 INT Status = NDIS_STATUS_SUCCESS;
5137 if (net_dev->priv_flags == INT_MAIN)
5139 pAd = net_dev->ml_priv;
5143 pVirtualAd = net_dev->ml_priv;
5144 pAd = pVirtualAd->RtmpDev->ml_priv;
5146 pObj = (POS_COOKIE) pAd->OS_Cookie;
5150 /* if 1st open fail, pAd will be free;
5151 So the net_dev->ml_priv will be NULL in 2rd open */
5155 //check if the interface is down
5156 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
5159 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
5164 { // determine this ioctl command is comming from which interface.
5165 pObj->ioctl_if_type = INT_MAIN;
5166 pObj->ioctl_if = MAIN_MBSSID;
5172 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIFHWADDR\n"));
5173 memcpy(wrq->u.name, pAd->CurrentAddress, ETH_ALEN);
5177 char *name=&wrq->u.name[0];
5178 rt_ioctl_giwname(net_dev, NULL, name, NULL);
5181 case SIOCGIWESSID: //Get ESSID
5183 struct iw_point *essid=&wrq->u.essid;
5184 rt_ioctl_giwessid(net_dev, NULL, essid, essid->pointer);
5187 case SIOCSIWESSID: //Set ESSID
5189 struct iw_point *essid=&wrq->u.essid;
5190 rt_ioctl_siwessid(net_dev, NULL, essid, essid->pointer);
5193 case SIOCSIWNWID: // set network id (the cell)
5194 case SIOCGIWNWID: // get network id
5195 Status = -EOPNOTSUPP;
5197 case SIOCSIWFREQ: //set channel/frequency (Hz)
5199 struct iw_freq *freq=&wrq->u.freq;
5200 rt_ioctl_siwfreq(net_dev, NULL, freq, NULL);
5203 case SIOCGIWFREQ: // get channel/frequency (Hz)
5205 struct iw_freq *freq=&wrq->u.freq;
5206 rt_ioctl_giwfreq(net_dev, NULL, freq, NULL);
5209 case SIOCSIWNICKN: //set node name/nickname
5211 struct iw_point *data=&wrq->u.data;
5212 rt_ioctl_siwnickn(net_dev, NULL, data, NULL);
5215 case SIOCGIWNICKN: //get node name/nickname
5217 struct iw_point *data=&wrq->u.data;
5218 rt_ioctl_giwnickn(net_dev, NULL, data, NULL);
5221 case SIOCGIWRATE: //get default bit rate (bps)
5222 rt_ioctl_giwrate(net_dev, NULL, &wrq->u, NULL);
5224 case SIOCSIWRATE: //set default bit rate (bps)
5225 rt_ioctl_siwrate(net_dev, NULL, &wrq->u, NULL);
5227 case SIOCGIWRTS: // get RTS/CTS threshold (bytes)
5229 struct iw_param *rts=&wrq->u.rts;
5230 rt_ioctl_giwrts(net_dev, NULL, rts, NULL);
5233 case SIOCSIWRTS: //set RTS/CTS threshold (bytes)
5235 struct iw_param *rts=&wrq->u.rts;
5236 rt_ioctl_siwrts(net_dev, NULL, rts, NULL);
5239 case SIOCGIWFRAG: //get fragmentation thr (bytes)
5241 struct iw_param *frag=&wrq->u.frag;
5242 rt_ioctl_giwfrag(net_dev, NULL, frag, NULL);
5245 case SIOCSIWFRAG: //set fragmentation thr (bytes)
5247 struct iw_param *frag=&wrq->u.frag;
5248 rt_ioctl_siwfrag(net_dev, NULL, frag, NULL);
5251 case SIOCGIWENCODE: //get encoding token & mode
5253 struct iw_point *erq=&wrq->u.encoding;
5255 rt_ioctl_giwencode(net_dev, NULL, erq, erq->pointer);
5258 case SIOCSIWENCODE: //set encoding token & mode
5260 struct iw_point *erq=&wrq->u.encoding;
5262 rt_ioctl_siwencode(net_dev, NULL, erq, erq->pointer);
5265 case SIOCGIWAP: //get access point MAC addresses
5267 struct sockaddr *ap_addr=&wrq->u.ap_addr;
5268 rt_ioctl_giwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
5271 case SIOCSIWAP: //set access point MAC addresses
5273 struct sockaddr *ap_addr=&wrq->u.ap_addr;
5274 rt_ioctl_siwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
5277 case SIOCGIWMODE: //get operation mode
5279 __u32 *mode=&wrq->u.mode;
5280 rt_ioctl_giwmode(net_dev, NULL, mode, NULL);
5283 case SIOCSIWMODE: //set operation mode
5285 __u32 *mode=&wrq->u.mode;
5286 rt_ioctl_siwmode(net_dev, NULL, mode, NULL);
5289 case SIOCGIWSENS: //get sensitivity (dBm)
5290 case SIOCSIWSENS: //set sensitivity (dBm)
5291 case SIOCGIWPOWER: //get Power Management settings
5292 case SIOCSIWPOWER: //set Power Management settings
5293 case SIOCGIWTXPOW: //get transmit power (dBm)
5294 case SIOCSIWTXPOW: //set transmit power (dBm)
5295 case SIOCGIWRANGE: //Get range of parameters
5296 case SIOCGIWRETRY: //get retry limits and lifetime
5297 case SIOCSIWRETRY: //set retry limits and lifetime
5298 Status = -EOPNOTSUPP;
5302 case RT_PRIV_IOCTL_EXT:
5304 subcmd = wrq->u.data.flags;
5305 if( subcmd & OID_GET_SET_TOGGLE)
5306 Status = RTMPSetInformation(pAd, rq, subcmd);
5308 Status = RTMPQueryInformation(pAd, rq, subcmd);
5311 if (wrq->u.data.pointer)
5313 if ( access_ok(VERIFY_WRITE, wrq->u.data.pointer, sizeof(privtab)) != TRUE)
5315 wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
5316 if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
5320 case RTPRIV_IOCTL_SET:
5321 if(access_ok(VERIFY_READ, wrq->u.data.pointer, wrq->u.data.length) != TRUE)
5323 rt_ioctl_setparam(net_dev, NULL, NULL, wrq->u.data.pointer);
5325 case RTPRIV_IOCTL_GSITESURVEY:
5326 RTMPIoctlGetSiteSurvey(pAd, wrq);
5329 case RTPRIV_IOCTL_MAC:
5330 RTMPIoctlMAC(pAd, wrq);
5332 case RTPRIV_IOCTL_E2P:
5333 RTMPIoctlE2PROM(pAd, wrq);
5336 case RTPRIV_IOCTL_RF:
5337 RTMPIoctlRF(pAd, wrq);
5344 DBGPRINT(RT_DEBUG_ERROR, ("IOCTL::unknown IOCTL's cmd = 0x%08x\n", cmd));
5345 Status = -EOPNOTSUPP;
5349 if(StateMachineTouched) // Upper layer sent a MLME-related operations
5350 RT28XX_MLME_HANDLER(pAd);
5356 ==========================================================================
5360 TRUE if all parameters are OK, FALSE otherwise
5361 ==========================================================================
5364 IN PRTMP_ADAPTER pAdapter,
5367 NDIS_802_11_SSID Ssid, *pSsid=NULL;
5368 BOOLEAN StateMachineTouched = FALSE;
5371 if( strlen(arg) <= MAX_LEN_OF_SSID)
5373 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
5374 if (strlen(arg) != 0)
5376 NdisMoveMemory(Ssid.Ssid, arg, strlen(arg));
5377 Ssid.SsidLength = strlen(arg);
5381 Ssid.SsidLength = 0;
5382 memcpy(Ssid.Ssid, "", 0);
5383 pAdapter->StaCfg.BssType = BSS_INFRA;
5384 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
5385 pAdapter->StaCfg.WepStatus = Ndis802_11EncryptionDisabled;
5389 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
5391 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
5392 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
5395 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
5396 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
5397 pAdapter->bConfigChanged = TRUE;
5399 MlmeEnqueue(pAdapter,
5400 MLME_CNTL_STATE_MACHINE,
5402 sizeof(NDIS_802_11_SSID),
5405 StateMachineTouched = TRUE;
5406 DBGPRINT(RT_DEBUG_TRACE, ("Set_SSID_Proc::(Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
5411 if (StateMachineTouched) // Upper layer sent a MLME-related operations
5412 RT28XX_MLME_HANDLER(pAdapter);
5419 ==========================================================================
5421 Set WmmCapable Enable or Disable
5423 TRUE if all parameters are OK, FALSE otherwise
5424 ==========================================================================
5426 INT Set_WmmCapable_Proc(
5427 IN PRTMP_ADAPTER pAd,
5430 BOOLEAN bWmmCapable;
5432 bWmmCapable = simple_strtol(arg, 0, 10);
5434 if ((bWmmCapable == 1)
5436 && (pAd->NumberOfPipes >= 5)
5439 pAd->CommonCfg.bWmmCapable = TRUE;
5440 else if (bWmmCapable == 0)
5441 pAd->CommonCfg.bWmmCapable = FALSE;
5443 return FALSE; //Invalid argument
5445 DBGPRINT(RT_DEBUG_TRACE, ("Set_WmmCapable_Proc::(bWmmCapable=%d)\n",
5446 pAd->CommonCfg.bWmmCapable));
5450 #endif // WMM_SUPPORT //
5453 ==========================================================================
5455 Set Network Type(Infrastructure/Adhoc mode)
5457 TRUE if all parameters are OK, FALSE otherwise
5458 ==========================================================================
5460 INT Set_NetworkType_Proc(
5461 IN PRTMP_ADAPTER pAdapter,
5466 if (strcmp(arg, "Adhoc") == 0)
5468 if (pAdapter->StaCfg.BssType != BSS_ADHOC)
5470 // Config has changed
5471 pAdapter->bConfigChanged = TRUE;
5472 if (MONITOR_ON(pAdapter))
5474 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
5475 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5477 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5478 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5479 pAdapter->StaCfg.bAutoReconnect = TRUE;
5480 LinkDown(pAdapter, FALSE);
5482 if (INFRA_ON(pAdapter))
5484 //BOOLEAN Cancelled;
5485 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
5486 // Since calling this indicate user don't want to connect to that SSID anymore.
5487 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
5488 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
5490 LinkDown(pAdapter, FALSE);
5492 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n"));
5495 pAdapter->StaCfg.BssType = BSS_ADHOC;
5496 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
5497 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(AD-HOC)\n"));
5499 else if (strcmp(arg, "Infra") == 0)
5501 if (pAdapter->StaCfg.BssType != BSS_INFRA)
5503 // Config has changed
5504 pAdapter->bConfigChanged = TRUE;
5505 if (MONITOR_ON(pAdapter))
5507 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
5508 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5510 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5511 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5512 pAdapter->StaCfg.bAutoReconnect = TRUE;
5513 LinkDown(pAdapter, FALSE);
5515 if (ADHOC_ON(pAdapter))
5517 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
5518 // Since calling this indicate user don't want to connect to that SSID anymore.
5519 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
5520 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
5522 LinkDown(pAdapter, FALSE);
5525 pAdapter->StaCfg.BssType = BSS_INFRA;
5526 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
5527 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(INFRA)\n"));
5529 pAdapter->StaCfg.BssType = BSS_INFRA;
5531 else if (strcmp(arg, "Monitor") == 0)
5534 BCN_TIME_CFG_STRUC csr;
5535 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_INFRA_ON);
5536 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_ADHOC_ON);
5537 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5538 // disable all periodic state machine
5539 pAdapter->StaCfg.bAutoReconnect = FALSE;
5540 // reset all mlme state machine
5541 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
5542 DBGPRINT(RT_DEBUG_TRACE, ("fOP_STATUS_MEDIA_STATE_CONNECTED \n"));
5543 if (pAdapter->CommonCfg.CentralChannel == 0)
5545 if (pAdapter->CommonCfg.PhyMode == PHY_11AN_MIXED)
5546 pAdapter->CommonCfg.CentralChannel = 36;
5548 pAdapter->CommonCfg.CentralChannel = 6;
5551 N_ChannelCheck(pAdapter);
5553 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
5554 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
5555 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_ABOVE)
5557 // 40MHz ,control channel at lower
5558 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5559 bbpValue &= (~0x18);
5561 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5562 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
5563 // RX : control channel at lower
5564 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
5565 bbpValue &= (~0x20);
5566 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
5568 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
5569 Value &= 0xfffffffe;
5570 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
5571 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel + 2;
5572 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
5573 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
5574 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
5575 pAdapter->CommonCfg.Channel,
5576 pAdapter->CommonCfg.CentralChannel));
5578 else if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
5579 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
5580 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_BELOW)
5582 // 40MHz ,control channel at upper
5583 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5584 bbpValue &= (~0x18);
5586 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5587 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
5588 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
5590 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
5592 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
5594 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
5595 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel - 2;
5596 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
5597 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
5598 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
5599 pAdapter->CommonCfg.Channel,
5600 pAdapter->CommonCfg.CentralChannel));
5605 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5606 bbpValue &= (~0x18);
5607 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5608 pAdapter->CommonCfg.BBPCurrentBW = BW_20;
5609 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.Channel, FALSE);
5610 AsicLockChannel(pAdapter, pAdapter->CommonCfg.Channel);
5611 DBGPRINT(RT_DEBUG_TRACE, ("BW_20, Channel(%d)\n", pAdapter->CommonCfg.Channel));
5613 // Enable Rx with promiscuous reception
5614 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, 0x3);
5615 // ASIC supporsts sniffer function with replacing RSSI with timestamp.
5616 //RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5618 //RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5620 RTMP_IO_READ32(pAdapter, BCN_TIME_CFG, &csr.word);
5621 csr.field.bBeaconGen = 0;
5622 csr.field.bTBTTEnable = 0;
5623 csr.field.TsfSyncMode = 0;
5624 RTMP_IO_WRITE32(pAdapter, BCN_TIME_CFG, csr.word);
5626 pAdapter->StaCfg.BssType = BSS_MONITOR;
5627 pAdapter->net_dev->type = ARPHRD_IEEE80211_PRISM; //ARPHRD_IEEE80211; // IEEE80211
5628 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(MONITOR)\n"));
5631 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
5632 pAdapter->StaCfg.WpaState = SS_NOTUSE;
5634 DBGPRINT(RT_DEBUG_TRACE, ("Set_NetworkType_Proc::(NetworkType=%d)\n", pAdapter->StaCfg.BssType));
5640 ==========================================================================
5642 Set Authentication mode
5644 TRUE if all parameters are OK, FALSE otherwise
5645 ==========================================================================
5647 INT Set_AuthMode_Proc(
5648 IN PRTMP_ADAPTER pAdapter,
5651 if ((strcmp(arg, "WEPAUTO") == 0) || (strcmp(arg, "wepauto") == 0))
5652 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeAutoSwitch;
5653 else if ((strcmp(arg, "OPEN") == 0) || (strcmp(arg, "open") == 0))
5654 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
5655 else if ((strcmp(arg, "SHARED") == 0) || (strcmp(arg, "shared") == 0))
5656 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
5657 else if ((strcmp(arg, "WPAPSK") == 0) || (strcmp(arg, "wpapsk") == 0))
5658 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
5659 else if ((strcmp(arg, "WPANONE") == 0) || (strcmp(arg, "wpanone") == 0))
5660 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
5661 else if ((strcmp(arg, "WPA2PSK") == 0) || (strcmp(arg, "wpa2psk") == 0))
5662 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
5663 else if ((strcmp(arg, "WPA") == 0) || (strcmp(arg, "wpa") == 0))
5664 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
5665 else if ((strcmp(arg, "WPA2") == 0) || (strcmp(arg, "wpa2") == 0))
5666 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
5670 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
5672 DBGPRINT(RT_DEBUG_TRACE, ("Set_AuthMode_Proc::(AuthMode=%d)\n", pAdapter->StaCfg.AuthMode));
5678 ==========================================================================
5682 TRUE if all parameters are OK, FALSE otherwise
5683 ==========================================================================
5685 INT Set_EncrypType_Proc(
5686 IN PRTMP_ADAPTER pAdapter,
5689 if ((strcmp(arg, "NONE") == 0) || (strcmp(arg, "none") == 0))
5691 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5692 return TRUE; // do nothing
5694 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
5695 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
5696 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
5698 else if ((strcmp(arg, "WEP") == 0) || (strcmp(arg, "wep") == 0))
5700 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5701 return TRUE; // do nothing
5703 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
5704 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
5705 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
5707 else if ((strcmp(arg, "TKIP") == 0) || (strcmp(arg, "tkip") == 0))
5709 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
5710 return TRUE; // do nothing
5712 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
5713 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
5714 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
5716 else if ((strcmp(arg, "AES") == 0) || (strcmp(arg, "aes") == 0))
5718 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
5719 return TRUE; // do nothing
5721 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
5722 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
5723 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
5728 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
5730 DBGPRINT(RT_DEBUG_TRACE, ("Set_EncrypType_Proc::(EncrypType=%d)\n", pAdapter->StaCfg.WepStatus));
5736 ==========================================================================
5740 TRUE if all parameters are OK, FALSE otherwise
5741 ==========================================================================
5743 INT Set_DefaultKeyID_Proc(
5744 IN PRTMP_ADAPTER pAdapter,
5749 KeyIdx = simple_strtol(arg, 0, 10);
5750 if((KeyIdx >= 1 ) && (KeyIdx <= 4))
5751 pAdapter->StaCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1 );
5753 return FALSE; //Invalid argument
5755 DBGPRINT(RT_DEBUG_TRACE, ("Set_DefaultKeyID_Proc::(DefaultKeyID=%d)\n", pAdapter->StaCfg.DefaultKeyId));
5761 ==========================================================================
5765 TRUE if all parameters are OK, FALSE otherwise
5766 ==========================================================================
5769 IN PRTMP_ADAPTER pAdapter,
5774 UCHAR CipherAlg=CIPHER_WEP64;
5776 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5777 return TRUE; // do nothing
5779 KeyLen = strlen(arg);
5783 case 5: //wep 40 Ascii type
5784 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
5785 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
5786 CipherAlg = CIPHER_WEP64;
5787 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
5789 case 10: //wep 40 Hex type
5790 for(i=0; i < KeyLen; i++)
5792 if( !isxdigit(*(arg+i)) )
5793 return FALSE; //Not Hex value;
5795 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
5796 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
5797 CipherAlg = CIPHER_WEP64;
5798 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
5800 case 13: //wep 104 Ascii type
5801 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
5802 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
5803 CipherAlg = CIPHER_WEP128;
5804 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
5806 case 26: //wep 104 Hex type
5807 for(i=0; i < KeyLen; i++)
5809 if( !isxdigit(*(arg+i)) )
5810 return FALSE; //Not Hex value;
5812 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
5813 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
5814 CipherAlg = CIPHER_WEP128;
5815 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
5817 default: //Invalid argument
5818 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::Invalid argument (=%s)\n", arg));
5822 pAdapter->SharedKey[BSS0][0].CipherAlg = CipherAlg;
5824 // Set keys (into ASIC)
5825 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5827 else // Old WEP stuff
5829 AsicAddSharedKeyEntry(pAdapter,
5832 pAdapter->SharedKey[BSS0][0].CipherAlg,
5833 pAdapter->SharedKey[BSS0][0].Key,
5841 ==========================================================================
5846 TRUE if all parameters are OK, FALSE otherwise
5847 ==========================================================================
5850 IN PRTMP_ADAPTER pAdapter,
5855 UCHAR CipherAlg=CIPHER_WEP64;
5857 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5858 return TRUE; // do nothing
5860 KeyLen = strlen(arg);
5864 case 5: //wep 40 Ascii type
5865 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
5866 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
5867 CipherAlg = CIPHER_WEP64;
5868 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
5870 case 10: //wep 40 Hex type
5871 for(i=0; i < KeyLen; i++)
5873 if( !isxdigit(*(arg+i)) )
5874 return FALSE; //Not Hex value;
5876 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
5877 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
5878 CipherAlg = CIPHER_WEP64;
5879 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
5881 case 13: //wep 104 Ascii type
5882 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
5883 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
5884 CipherAlg = CIPHER_WEP128;
5885 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
5887 case 26: //wep 104 Hex type
5888 for(i=0; i < KeyLen; i++)
5890 if( !isxdigit(*(arg+i)) )
5891 return FALSE; //Not Hex value;
5893 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
5894 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
5895 CipherAlg = CIPHER_WEP128;
5896 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
5898 default: //Invalid argument
5899 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::Invalid argument (=%s)\n", arg));
5902 pAdapter->SharedKey[BSS0][1].CipherAlg = CipherAlg;
5904 // Set keys (into ASIC)
5905 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5907 else // Old WEP stuff
5909 AsicAddSharedKeyEntry(pAdapter,
5912 pAdapter->SharedKey[BSS0][1].CipherAlg,
5913 pAdapter->SharedKey[BSS0][1].Key,
5921 ==========================================================================
5925 TRUE if all parameters are OK, FALSE otherwise
5926 ==========================================================================
5929 IN PRTMP_ADAPTER pAdapter,
5934 UCHAR CipherAlg=CIPHER_WEP64;
5936 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5937 return TRUE; // do nothing
5939 KeyLen = strlen(arg);
5943 case 5: //wep 40 Ascii type
5944 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
5945 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
5946 CipherAlg = CIPHER_WEP64;
5947 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
5949 case 10: //wep 40 Hex type
5950 for(i=0; i < KeyLen; i++)
5952 if( !isxdigit(*(arg+i)) )
5953 return FALSE; //Not Hex value;
5955 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
5956 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
5957 CipherAlg = CIPHER_WEP64;
5958 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
5960 case 13: //wep 104 Ascii type
5961 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
5962 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
5963 CipherAlg = CIPHER_WEP128;
5964 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
5966 case 26: //wep 104 Hex type
5967 for(i=0; i < KeyLen; i++)
5969 if( !isxdigit(*(arg+i)) )
5970 return FALSE; //Not Hex value;
5972 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
5973 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
5974 CipherAlg = CIPHER_WEP128;
5975 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
5977 default: //Invalid argument
5978 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::Invalid argument (=%s)\n", arg));
5981 pAdapter->SharedKey[BSS0][2].CipherAlg = CipherAlg;
5983 // Set keys (into ASIC)
5984 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5986 else // Old WEP stuff
5988 AsicAddSharedKeyEntry(pAdapter,
5991 pAdapter->SharedKey[BSS0][2].CipherAlg,
5992 pAdapter->SharedKey[BSS0][2].Key,
6000 ==========================================================================
6004 TRUE if all parameters are OK, FALSE otherwise
6005 ==========================================================================
6008 IN PRTMP_ADAPTER pAdapter,
6013 UCHAR CipherAlg=CIPHER_WEP64;
6015 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6016 return TRUE; // do nothing
6018 KeyLen = strlen(arg);
6022 case 5: //wep 40 Ascii type
6023 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
6024 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
6025 CipherAlg = CIPHER_WEP64;
6026 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
6028 case 10: //wep 40 Hex type
6029 for(i=0; i < KeyLen; i++)
6031 if( !isxdigit(*(arg+i)) )
6032 return FALSE; //Not Hex value;
6034 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
6035 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
6036 CipherAlg = CIPHER_WEP64;
6037 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
6039 case 13: //wep 104 Ascii type
6040 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
6041 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
6042 CipherAlg = CIPHER_WEP128;
6043 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
6045 case 26: //wep 104 Hex type
6046 for(i=0; i < KeyLen; i++)
6048 if( !isxdigit(*(arg+i)) )
6049 return FALSE; //Not Hex value;
6051 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
6052 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
6053 CipherAlg = CIPHER_WEP128;
6054 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
6056 default: //Invalid argument
6057 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::Invalid argument (=%s)\n", arg));
6060 pAdapter->SharedKey[BSS0][3].CipherAlg = CipherAlg;
6062 // Set keys (into ASIC)
6063 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6065 else // Old WEP stuff
6067 AsicAddSharedKeyEntry(pAdapter,
6070 pAdapter->SharedKey[BSS0][3].CipherAlg,
6071 pAdapter->SharedKey[BSS0][3].Key,
6080 ==========================================================================
6084 TRUE if all parameters are OK, FALSE otherwise
6085 ==========================================================================
6087 INT Set_WPAPSK_Proc(
6088 IN PRTMP_ADAPTER pAdapter,
6091 UCHAR keyMaterial[40];
6093 if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
6094 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
6095 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
6097 return TRUE; // do nothing
6099 DBGPRINT(RT_DEBUG_TRACE, ("Set_WPAPSK_Proc::(WPAPSK=%s)\n", arg));
6101 NdisZeroMemory(keyMaterial, 40);
6103 if ((strlen(arg) < 8) || (strlen(arg) > 64))
6105 DBGPRINT(RT_DEBUG_TRACE, ("Set failed!!(WPAPSK=%s), WPAPSK key-string required 8 ~ 64 characters \n", arg));
6109 if (strlen(arg) == 64)
6111 AtoH(arg, keyMaterial, 32);
6112 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
6117 PasswordHash((char *)arg, pAdapter->MlmeAux.Ssid, pAdapter->MlmeAux.SsidLen, keyMaterial);
6118 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
6123 if(pAdapter->StaCfg.BssType == BSS_ADHOC &&
6124 pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
6126 pAdapter->StaCfg.WpaState = SS_NOTUSE;
6130 // Start STA supplicant state machine
6131 pAdapter->StaCfg.WpaState = SS_START;
6138 ==========================================================================
6140 Set Power Saving mode
6142 TRUE if all parameters are OK, FALSE otherwise
6143 ==========================================================================
6145 INT Set_PSMode_Proc(
6146 IN PRTMP_ADAPTER pAdapter,
6149 if (pAdapter->StaCfg.BssType == BSS_INFRA)
6151 if ((strcmp(arg, "Max_PSP") == 0) ||
6152 (strcmp(arg, "max_psp") == 0) ||
6153 (strcmp(arg, "MAX_PSP") == 0))
6155 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6156 // to exclude certain situations.
6157 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6158 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeMAX_PSP;
6159 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeMAX_PSP;
6160 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6161 pAdapter->StaCfg.DefaultListenCount = 5;
6164 else if ((strcmp(arg, "Fast_PSP") == 0) ||
6165 (strcmp(arg, "fast_psp") == 0) ||
6166 (strcmp(arg, "FAST_PSP") == 0))
6168 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6169 // to exclude certain situations.
6170 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6171 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6172 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeFast_PSP;
6173 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeFast_PSP;
6174 pAdapter->StaCfg.DefaultListenCount = 3;
6176 else if ((strcmp(arg, "Legacy_PSP") == 0) ||
6177 (strcmp(arg, "legacy_psp") == 0) ||
6178 (strcmp(arg, "LEGACY_PSP") == 0))
6180 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6181 // to exclude certain situations.
6182 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6183 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6184 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeLegacy_PSP;
6185 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeLegacy_PSP;
6186 pAdapter->StaCfg.DefaultListenCount = 3;
6190 //Default Ndis802_11PowerModeCAM
6191 // clear PSM bit immediately
6192 MlmeSetPsmBit(pAdapter, PWR_ACTIVE);
6193 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6194 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6195 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
6196 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
6199 DBGPRINT(RT_DEBUG_TRACE, ("Set_PSMode_Proc::(PSMode=%ld)\n", pAdapter->StaCfg.WindowsPowerMode));
6209 ==========================================================================
6211 Set WpaSupport flag.
6213 0: Driver ignore wpa_supplicant.
6214 1: wpa_supplicant initiates scanning and AP selection.
6215 2: driver takes care of scanning, AP selection, and IEEE 802.11 association parameters.
6217 TRUE if all parameters are OK, FALSE otherwise
6218 ==========================================================================
6220 INT Set_Wpa_Support(
6221 IN PRTMP_ADAPTER pAd,
6225 if ( simple_strtol(arg, 0, 10) == 0)
6226 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
6227 else if ( simple_strtol(arg, 0, 10) == 1)
6228 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE;
6229 else if ( simple_strtol(arg, 0, 10) == 2)
6230 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE_WITH_WEB_UI;
6232 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
6234 DBGPRINT(RT_DEBUG_TRACE, ("Set_Wpa_Support::(WpaSupplicantUP=%d)\n", pAd->StaCfg.WpaSupplicantUP));
6241 ==========================================================================
6245 pAdapter Pointer to our adapter
6246 wrq Pointer to the ioctl argument
6253 1.) iwpriv ra0 mac 0 ==> read MAC where Addr=0x0
6254 2.) iwpriv ra0 mac 0=12 ==> write MAC where Addr=0x0, value=12
6255 ==========================================================================
6258 IN PRTMP_ADAPTER pAdapter,
6259 IN struct iwreq *wrq)
6267 UCHAR temp[16], temp2[16];
6268 UINT32 macValue = 0;
6271 BOOLEAN bIsPrintAllMAC = FALSE;
6274 memset(msg, 0x00, 1024);
6275 if (wrq->u.data.length > 1) //No parameters.
6277 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6280 //Parsing Read or Write
6285 if ((value = rtstrchr(this_char, '=')) != NULL)
6288 if (!value || !*value)
6291 if(strlen(this_char) > 4)
6294 j = strlen(this_char);
6297 if(this_char[j] > 'f' || this_char[j] < '0')
6302 k = j = strlen(this_char);
6305 this_char[4-k+j] = this_char[j];
6309 this_char[3-k++]='0';
6312 if(strlen(this_char) == 4)
6314 AtoH(this_char, temp, 2);
6315 macAddr = *temp*256 + temp[1];
6316 if (macAddr < 0xFFFF)
6318 RTMP_IO_READ32(pAdapter, macAddr, &macValue);
6319 DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%lx, MacValue=%x\n", macAddr, macValue));
6320 sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr , macValue);
6324 {//Invalid parametes, so default printk all bbp
6327 {//Invalid parametes, so default printk all mac
6328 bIsPrintAllMAC = TRUE;
6336 memcpy(&temp2, value, strlen(value));
6337 temp2[strlen(value)] = '\0';
6340 if((strlen(this_char) > 4) || strlen(temp2) > 8)
6343 j = strlen(this_char);
6346 if(this_char[j] > 'f' || this_char[j] < '0')
6353 if(temp2[j] > 'f' || temp2[j] < '0')
6358 k = j = strlen(this_char);
6361 this_char[4-k+j] = this_char[j];
6365 this_char[3-k++]='0';
6369 k = j = strlen(temp2);
6372 temp2[8-k+j] = temp2[j];
6380 AtoH(this_char, temp, 2);
6381 macAddr = *temp*256 + temp[1];
6383 AtoH(temp2, temp, 4);
6384 macValue = *temp*256*256*256 + temp[1]*256*256 + temp[2]*256 + temp[3];
6387 if (macAddr == (HW_DEBUG_SETTING_BASE + 4))
6389 // 0x2bf4: byte0 non-zero: enable R17 tuning, 0: disable R17 tuning
6390 if (macValue & 0x000000ff)
6392 pAdapter->BbpTuning.bEnable = TRUE;
6393 DBGPRINT(RT_DEBUG_TRACE,("turn on R17 tuning\n"));
6398 pAdapter->BbpTuning.bEnable = FALSE;
6399 R66 = 0x26 + GET_LNA_GAIN(pAdapter);
6400 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R66, (0x26 + GET_LNA_GAIN(pAdapter)));
6401 DBGPRINT(RT_DEBUG_TRACE,("turn off R17 tuning, restore to 0x%02x\n", R66));
6406 DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%02lx, MacValue=0x%x\n", macAddr, macValue));
6408 RTMP_IO_WRITE32(pAdapter, macAddr, macValue);
6409 sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr, macValue);
6415 bIsPrintAllMAC = TRUE;
6421 struct file *file_w;
6422 PCHAR fileName = "MacDump.txt";
6423 mm_segment_t orig_fs;
6429 file_w = filp_open(fileName, O_WRONLY|O_CREAT, 0);
6432 DBGPRINT(RT_DEBUG_TRACE, ("-->2) %s: Error %ld opening %s\n", __func__, -PTR_ERR(file_w), fileName));
6436 if (file_w->f_op && file_w->f_op->write)
6441 while (macAddr <= 0x1800)
6443 RTMP_IO_READ32(pAdapter, macAddr, &macValue);
6444 sprintf(msg, "%08lx = %08X\n", macAddr, macValue);
6446 // write data to file
6447 file_w->f_op->write(file_w, msg, strlen(msg), &file_w->f_pos);
6452 sprintf(msg, "\nDump all MAC values to %s\n", fileName);
6454 filp_close(file_w, NULL);
6459 if(strlen(msg) == 1)
6460 sprintf(msg+strlen(msg), "===>Error command format!");
6462 // Copy the information into the user buffer
6463 wrq->u.data.length = strlen(msg);
6464 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6466 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlMAC\n\n"));
6470 ==========================================================================
6474 pAdapter Pointer to our adapter
6475 wrq Pointer to the ioctl argument
6482 1.) iwpriv ra0 e2p 0 ==> read E2PROM where Addr=0x0
6483 2.) iwpriv ra0 e2p 0=1234 ==> write E2PROM where Addr=0x0, value=1234
6484 ==========================================================================
6486 VOID RTMPIoctlE2PROM(
6487 IN PRTMP_ADAPTER pAdapter,
6488 IN struct iwreq *wrq)
6496 UCHAR temp[16], temp2[16];
6500 BOOLEAN bIsPrintAllE2P = FALSE;
6503 memset(msg, 0x00, 1024);
6504 if (wrq->u.data.length > 1) //No parameters.
6506 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6509 //Parsing Read or Write
6516 if ((value = rtstrchr(this_char, '=')) != NULL)
6519 if (!value || !*value)
6523 if(strlen(this_char) > 4)
6526 j = strlen(this_char);
6529 if(this_char[j] > 'f' || this_char[j] < '0')
6534 k = j = strlen(this_char);
6537 this_char[4-k+j] = this_char[j];
6541 this_char[3-k++]='0';
6544 if(strlen(this_char) == 4)
6546 AtoH(this_char, temp, 2);
6547 eepAddr = *temp*256 + temp[1];
6548 if (eepAddr < 0xFFFF)
6550 RT28xx_EEPROM_READ16(pAdapter, eepAddr, eepValue);
6551 sprintf(msg+strlen(msg), "[0x%04X]:0x%04X ", eepAddr , eepValue);
6554 {//Invalid parametes, so default printk all bbp
6556 bIsPrintAllE2P = TRUE;
6564 memcpy(&temp2, value, strlen(value));
6565 temp2[strlen(value)] = '\0';
6568 if((strlen(this_char) > 4) || strlen(temp2) > 8)
6571 j = strlen(this_char);
6574 if(this_char[j] > 'f' || this_char[j] < '0')
6580 if(temp2[j] > 'f' || temp2[j] < '0')
6585 k = j = strlen(this_char);
6588 this_char[4-k+j] = this_char[j];
6592 this_char[3-k++]='0';
6596 k = j = strlen(temp2);
6599 temp2[4-k+j] = temp2[j];
6606 AtoH(this_char, temp, 2);
6607 eepAddr = *temp*256 + temp[1];
6609 AtoH(temp2, temp, 2);
6610 eepValue = *temp*256 + temp[1];
6612 RT28xx_EEPROM_WRITE16(pAdapter, eepAddr, eepValue);
6613 sprintf(msg+strlen(msg), "[0x%02X]:%02X ", eepAddr, eepValue);
6618 bIsPrintAllE2P = TRUE;
6624 struct file *file_w;
6625 PCHAR fileName = "EEPROMDump.txt";
6626 mm_segment_t orig_fs;
6632 file_w = filp_open(fileName, O_WRONLY|O_CREAT, 0);
6635 DBGPRINT(RT_DEBUG_TRACE, ("-->2) %s: Error %ld opening %s\n", __func__, -PTR_ERR(file_w), fileName));
6639 if (file_w->f_op && file_w->f_op->write)
6644 while (eepAddr <= 0xFE)
6646 RT28xx_EEPROM_READ16(pAdapter, eepAddr, eepValue);
6647 sprintf(msg, "%08x = %04x\n", eepAddr , eepValue);
6649 // write data to file
6650 file_w->f_op->write(file_w, msg, strlen(msg), &file_w->f_pos);
6655 sprintf(msg, "\nDump all EEPROM values to %s\n", fileName);
6657 filp_close(file_w, NULL);
6662 if(strlen(msg) == 1)
6663 sprintf(msg+strlen(msg), "===>Error command format!");
6666 // Copy the information into the user buffer
6667 wrq->u.data.length = strlen(msg);
6668 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6670 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlE2PROM\n"));
6674 ==========================================================================
6676 Read / Write RF register
6678 pAdapter Pointer to our adapter
6679 wrq Pointer to the ioctl argument
6686 1.) iwpriv ra0 rf ==> read all RF registers
6687 2.) iwpriv ra0 rf 1 ==> read RF where RegID=1
6688 3.) iwpriv ra0 rf 1=10 ==> write RF R1=0x10
6689 ==========================================================================
6692 IN PRTMP_ADAPTER pAdapter,
6693 IN struct iwreq *wrq)
6703 BOOLEAN bIsPrintAllRF = FALSE;
6706 memset(msg, 0x00, 2048);
6707 if (wrq->u.data.length > 1) //No parameters.
6709 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6712 //Parsing Read or Write
6717 if ((value = strchr(this_char, '=')) != NULL)
6720 if (!value || !*value)
6722 if (sscanf(this_char, "%d", &(rfId)) == 1)
6726 // In RT2860 ATE mode, we do not load 8051 firmware.
6727 //We must access RF directly.
6728 // For RT2870 ATE mode, ATE_RF_IO_WRITE8(/READ8)_BY_REG_ID are redefined.
6729 // according to Andy, Gary, David require.
6730 // the command rf shall read rf register directly for dubug.
6731 // BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
6732 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
6734 sprintf(msg+strlen(msg), "R%02d[0x%02x]:%02X ", rfId, rfId*2, regRF);
6737 {//Invalid parametes, so default printk all RF
6738 bIsPrintAllRF = TRUE;
6743 { //Invalid parametes, so default printk all RF
6744 bIsPrintAllRF = TRUE;
6750 if ((sscanf(this_char, "%d", &(rfId)) == 1) && (sscanf(value, "%lx", &(rfValue)) == 1))
6754 // In RT2860 ATE mode, we do not load 8051 firmware.
6755 // We should access RF registers directly.
6756 // For RT2870 ATE mode, ATE_RF_IO_WRITE8/READ8_BY_REG_ID are redefined.
6758 // according to Andy, Gary, David require.
6759 // the command RF shall read/write RF register directly for dubug.
6760 //BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
6761 //BBP_IO_WRITE8_BY_REG_ID(pAdapter, (UCHAR)bbpId,(UCHAR) bbpValue);
6762 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
6763 RT30xxWriteRFRegister(pAdapter, (UCHAR)rfId,(UCHAR) rfValue);
6764 //Read it back for showing
6765 //BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
6766 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
6767 sprintf(msg+strlen(msg), "R%02d[0x%02X]:%02X\n", rfId, rfId*2, regRF);
6771 {//Invalid parametes, so default printk all RF
6772 bIsPrintAllRF = TRUE;
6776 { //Invalid parametes, so default printk all RF
6777 bIsPrintAllRF = TRUE;
6782 bIsPrintAllRF = TRUE;
6786 memset(msg, 0x00, 2048);
6788 for (rfId = 0; rfId <= 31; rfId++)
6790 // according to Andy, Gary, David require.
6791 // the command RF shall read/write RF register directly for dubug.
6792 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
6793 sprintf(msg+strlen(msg), "%03d = %02X\n", rfId, regRF);
6795 // Copy the information into the user buffer
6796 DBGPRINT(RT_DEBUG_TRACE, ("strlen(msg)=%d\n", (UINT32)strlen(msg)));
6797 wrq->u.data.length = strlen(msg);
6798 if (copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length))
6800 DBGPRINT(RT_DEBUG_TRACE, ("%s: copy_to_user() fail\n", __func__));
6805 if(strlen(msg) == 1)
6806 sprintf(msg+strlen(msg), "===>Error command format!");
6808 DBGPRINT(RT_DEBUG_TRACE, ("copy to user [msg=%s]\n", msg));
6809 // Copy the information into the user buffer
6810 DBGPRINT(RT_DEBUG_TRACE, ("strlen(msg) =%d\n", (UINT32)strlen(msg)));
6812 // Copy the information into the user buffer
6813 wrq->u.data.length = strlen(msg);
6814 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6817 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlRF\n\n"));
6825 INT Set_TGnWifiTest_Proc(
6826 IN PRTMP_ADAPTER pAd,
6829 if (simple_strtol(arg, 0, 10) == 0)
6830 pAd->StaCfg.bTGnWifiTest = FALSE;
6832 pAd->StaCfg.bTGnWifiTest = TRUE;
6834 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_TGnWifiTest_Proc::(bTGnWifiTest=%d)\n", pAd->StaCfg.bTGnWifiTest));
6838 INT Set_LongRetryLimit_Proc(
6839 IN PRTMP_ADAPTER pAdapter,
6842 TX_RTY_CFG_STRUC tx_rty_cfg;
6843 UCHAR LongRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
6845 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
6846 tx_rty_cfg.field.LongRtyLimit = LongRetryLimit;
6847 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
6848 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_LongRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
6852 INT Set_ShortRetryLimit_Proc(
6853 IN PRTMP_ADAPTER pAdapter,
6856 TX_RTY_CFG_STRUC tx_rty_cfg;
6857 UCHAR ShortRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
6859 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
6860 tx_rty_cfg.field.ShortRtyLimit = ShortRetryLimit;
6861 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
6862 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_ShortRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
6866 #if !defined(RT2860) && !defined(RT30xx)
6867 INT Show_Adhoc_MacTable_Proc(
6868 IN PRTMP_ADAPTER pAd,
6873 sprintf(extra, "\n");
6875 sprintf(extra + strlen(extra), "HT Operating Mode : %d\n", pAd->CommonCfg.AddHTInfo.AddHtInfo2.OperaionMode);
6877 sprintf(extra + strlen(extra), "\n%-19s%-4s%-4s%-7s%-7s%-7s%-10s%-6s%-6s%-6s%-6s\n",
6878 "MAC", "AID", "BSS", "RSSI0", "RSSI1", "RSSI2", "PhMd", "BW", "MCS", "SGI", "STBC");
6880 for (i=1; i<MAX_LEN_OF_MAC_TABLE; i++)
6882 PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
6884 if (strlen(extra) > (IW_PRIV_SIZE_MASK - 30))
6886 if ((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
6888 sprintf(extra + strlen(extra), "%02X:%02X:%02X:%02X:%02X:%02X ",
6889 pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
6890 pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5]);
6891 sprintf(extra + strlen(extra), "%-4d", (int)pEntry->Aid);
6892 sprintf(extra + strlen(extra), "%-4d", (int)pEntry->apidx);
6893 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi0);
6894 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi1);
6895 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi2);
6896 sprintf(extra + strlen(extra), "%-10s", GetPhyMode(pEntry->HTPhyMode.field.MODE));
6897 sprintf(extra + strlen(extra), "%-6s", GetBW(pEntry->HTPhyMode.field.BW));
6898 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.MCS);
6899 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.ShortGI);
6900 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.STBC);
6901 sprintf(extra + strlen(extra), "%-10d, %d, %d%%\n", pEntry->DebugFIFOCount, pEntry->DebugTxCount,
6902 (pEntry->DebugTxCount) ? ((pEntry->DebugTxCount-pEntry->DebugFIFOCount)*100/pEntry->DebugTxCount) : 0);
6903 sprintf(extra, "%s\n", extra);