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 /* IW_ENC_CAPA_* bit field */
819 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
820 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
825 int rt_ioctl_siwap(struct net_device *dev,
826 struct iw_request_info *info,
827 struct sockaddr *ap_addr, char *extra)
829 PRTMP_ADAPTER pAdapter = dev->ml_priv;
830 NDIS_802_11_MAC_ADDRESS Bssid;
832 //check if the interface is down
833 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
835 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
839 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
841 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
842 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
845 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
846 // this request, because this request is initiated by NDIS.
847 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
848 // Prevent to connect AP again in STAMlmePeriodicExec
849 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
851 memset(Bssid, 0, MAC_ADDR_LEN);
852 memcpy(Bssid, ap_addr->sa_data, MAC_ADDR_LEN);
853 MlmeEnqueue(pAdapter,
854 MLME_CNTL_STATE_MACHINE,
856 sizeof(NDIS_802_11_MAC_ADDRESS),
859 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCSIWAP %02x:%02x:%02x:%02x:%02x:%02x\n",
860 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
865 int rt_ioctl_giwap(struct net_device *dev,
866 struct iw_request_info *info,
867 struct sockaddr *ap_addr, char *extra)
870 PRTMP_ADAPTER pAdapter = NULL;
871 VIRTUAL_ADAPTER *pVirtualAd = NULL;
873 if (dev->priv_flags == INT_MAIN)
875 pAdapter = dev->ml_priv;
879 pVirtualAd = dev->ml_priv;
880 if (pVirtualAd && pVirtualAd->RtmpDev)
881 pAdapter = pVirtualAd->RtmpDev->ml_priv;
884 if (pAdapter == NULL)
886 /* if 1st open fail, pAd will be free;
887 So the net_dev->ml_priv will be NULL in 2rd open */
892 PRTMP_ADAPTER pAdapter = dev->ml_priv;
895 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
897 ap_addr->sa_family = ARPHRD_ETHER;
898 memcpy(ap_addr->sa_data, &pAdapter->CommonCfg.Bssid, ETH_ALEN);
901 else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
903 ap_addr->sa_family = ARPHRD_ETHER;
904 memcpy(ap_addr->sa_data, &pAdapter->MlmeAux.Bssid, ETH_ALEN);
908 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIWAP(=EMPTY)\n"));
916 * Units are in db above the noise floor. That means the
917 * rssi values reported in the tx/rx descriptors in the
918 * driver are the SNR expressed in db.
920 * If you assume that the noise floor is -95, which is an
921 * excellent assumption 99.5 % of the time, then you can
922 * derive the absolute signal level (i.e. -95 + rssi).
923 * There are some other slight factors to take into account
924 * depending on whether the rssi measurement is from 11b,
925 * 11g, or 11a. These differences are at most 2db and
928 * NB: various calculations are based on the orinoco/wavelan
929 * drivers for compatibility
931 static void set_quality(PRTMP_ADAPTER pAdapter,
932 struct iw_quality *iq,
939 ChannelQuality = 100;
940 else if (rssi >= -80) // between -50 ~ -80dbm
941 ChannelQuality = (__u8)(24 + ((rssi + 80) * 26)/10);
942 else if (rssi >= -90) // between -80 ~ -90dbm
943 ChannelQuality = (__u8)((rssi + 90) * 26)/10;
947 iq->qual = (__u8)ChannelQuality;
949 iq->level = (__u8)(rssi);
950 iq->noise = (pAdapter->BbpWriteLatch[66] > pAdapter->BbpTuning.FalseCcaUpperThreshold) ? ((__u8)pAdapter->BbpTuning.FalseCcaUpperThreshold) : ((__u8) pAdapter->BbpWriteLatch[66]); // noise level (dBm)
951 iq->noise += 256 - 143;
952 iq->updated = pAdapter->iw_stats.qual.updated;
955 int rt_ioctl_iwaplist(struct net_device *dev,
956 struct iw_request_info *info,
957 struct iw_point *data, char *extra)
959 PRTMP_ADAPTER pAdapter = dev->ml_priv;
961 struct sockaddr addr[IW_MAX_AP];
962 struct iw_quality qual[IW_MAX_AP];
965 //check if the interface is down
966 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
968 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
974 for (i = 0; i <IW_MAX_AP ; i++)
976 if (i >= pAdapter->ScanTab.BssNr)
978 addr[i].sa_family = ARPHRD_ETHER;
979 memcpy(addr[i].sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
980 set_quality(pAdapter, &qual[i], pAdapter->ScanTab.BssEntry[i].Rssi);
983 memcpy(extra, &addr, i*sizeof(addr[0]));
984 data->flags = 1; /* signal quality present (sort of) */
985 memcpy(extra + i*sizeof(addr[0]), &qual, i*sizeof(qual[i]));
990 int rt_ioctl_siwscan(struct net_device *dev,
991 struct iw_request_info *info,
992 struct iw_point *data, char *extra)
994 PRTMP_ADAPTER pAdapter = dev->ml_priv;
997 int Status = NDIS_STATUS_SUCCESS;
999 //check if the interface is down
1000 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1002 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1006 if (MONITOR_ON(pAdapter))
1008 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
1012 if ((pAdapter->OpMode == OPMODE_STA) && (IDLE_ON(pAdapter))
1013 && (pAdapter->StaCfg.bRadio == TRUE)
1014 && (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_IDLE_RADIO_OFF)))
1016 RT28xxPciAsicRadioOn(pAdapter, GUI_IDLE_POWER_SAVE);
1018 // Check if still radio off.
1019 else if (pAdapter->bPCIclkOff == TRUE)
1022 if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
1024 pAdapter->StaCfg.WpaSupplicantScanCount++;
1027 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
1028 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
1033 if ((pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE) &&
1034 (pAdapter->StaCfg.WpaSupplicantScanCount > 3))
1036 DBGPRINT(RT_DEBUG_TRACE, ("!!! WpaSupplicantScanCount > 3\n"));
1037 Status = NDIS_STATUS_SUCCESS;
1041 if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
1042 ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
1043 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) &&
1044 (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
1046 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
1047 Status = NDIS_STATUS_SUCCESS;
1051 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
1053 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
1054 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
1057 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
1058 // this request, because this request is initiated by NDIS.
1059 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
1060 // Reset allowed scan retries
1061 pAdapter->StaCfg.ScanCnt = 0;
1062 pAdapter->StaCfg.LastScanTime = Now;
1064 MlmeEnqueue(pAdapter,
1065 MLME_CNTL_STATE_MACHINE,
1066 OID_802_11_BSSID_LIST_SCAN,
1070 Status = NDIS_STATUS_SUCCESS;
1071 RT28XX_MLME_HANDLER(pAdapter);
1076 int rt_ioctl_giwscan(struct net_device *dev,
1077 struct iw_request_info *info,
1078 struct iw_point *data, char *extra)
1081 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1083 char *current_ev = extra, *previous_ev = extra;
1085 char *current_val, custom[MAX_CUSTOM_LEN] = {0};
1086 struct iw_event iwe;
1088 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
1091 * Still scanning, indicate the caller should try again.
1096 if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
1098 pAdapter->StaCfg.WpaSupplicantScanCount = 0;
1101 if (pAdapter->ScanTab.BssNr == 0)
1107 if (data->length > 0)
1108 end_buf = extra + data->length;
1110 end_buf = extra + IW_SCAN_MAX_DATA;
1112 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
1114 if (current_ev >= end_buf)
1118 //================================
1119 memset(&iwe, 0, sizeof(iwe));
1120 iwe.cmd = SIOCGIWAP;
1121 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1122 memcpy(iwe.u.ap_addr.sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, ETH_ALEN);
1124 previous_ev = current_ev;
1125 current_ev = iwe_stream_add_event(info, current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);
1127 if (current_ev == previous_ev)
1132 it will show scanned AP's WirelessMode .
1141 memset(&iwe, 0, sizeof(iwe));
1142 iwe.cmd = SIOCGIWNAME;
1146 PBSS_ENTRY pBssEntry=&pAdapter->ScanTab.BssEntry[i];
1147 BOOLEAN isGonly=FALSE;
1150 if (pBssEntry->Channel>14)
1152 if (pBssEntry->HtCapabilityLen!=0)
1153 strcpy(iwe.u.name,"802.11a/n");
1155 strcpy(iwe.u.name,"802.11a");
1160 if one of non B mode rate is set supported rate . it mean G only.
1162 for (rateCnt=0;rateCnt<pBssEntry->SupRateLen;rateCnt++)
1165 6Mbps(140) 9Mbps(146) and >=12Mbps(152) are supported rate , it mean G only.
1167 if (pBssEntry->SupRate[rateCnt]==140 || pBssEntry->SupRate[rateCnt]==146 || pBssEntry->SupRate[rateCnt]>=152)
1171 for (rateCnt=0;rateCnt<pBssEntry->ExtRateLen;rateCnt++)
1173 if (pBssEntry->ExtRate[rateCnt]==140 || pBssEntry->ExtRate[rateCnt]==146 || pBssEntry->ExtRate[rateCnt]>=152)
1178 if (pBssEntry->HtCapabilityLen!=0)
1181 strcpy(iwe.u.name,"802.11g/n");
1183 strcpy(iwe.u.name,"802.11b/g/n");
1188 strcpy(iwe.u.name,"802.11g");
1191 if (pBssEntry->SupRateLen==4 && pBssEntry->ExtRateLen==0)
1192 strcpy(iwe.u.name,"802.11b");
1194 strcpy(iwe.u.name,"802.11b/g");
1200 previous_ev = current_ev;
1201 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
1203 if (current_ev == previous_ev)
1207 //================================
1208 memset(&iwe, 0, sizeof(iwe));
1209 iwe.cmd = SIOCGIWESSID;
1210 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].SsidLen;
1211 iwe.u.data.flags = 1;
1213 previous_ev = current_ev;
1214 current_ev = iwe_stream_add_point(info, current_ev,end_buf, &iwe, pAdapter->ScanTab.BssEntry[i].Ssid);
1215 if (current_ev == previous_ev)
1219 //================================
1220 memset(&iwe, 0, sizeof(iwe));
1221 iwe.cmd = SIOCGIWMODE;
1222 if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11IBSS)
1224 iwe.u.mode = IW_MODE_ADHOC;
1226 else if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11Infrastructure)
1228 iwe.u.mode = IW_MODE_INFRA;
1232 iwe.u.mode = IW_MODE_AUTO;
1234 iwe.len = IW_EV_UINT_LEN;
1236 previous_ev = current_ev;
1237 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
1238 if (current_ev == previous_ev)
1241 //Channel and Frequency
1242 //================================
1243 memset(&iwe, 0, sizeof(iwe));
1244 iwe.cmd = SIOCGIWFREQ;
1245 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
1246 iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
1248 iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
1252 previous_ev = current_ev;
1253 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
1254 if (current_ev == previous_ev)
1257 //Add quality statistics
1258 //================================
1259 memset(&iwe, 0, sizeof(iwe));
1261 iwe.u.qual.level = 0;
1262 iwe.u.qual.noise = 0;
1263 set_quality(pAdapter, &iwe.u.qual, pAdapter->ScanTab.BssEntry[i].Rssi);
1264 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
1265 if (current_ev == previous_ev)
1269 //================================
1270 memset(&iwe, 0, sizeof(iwe));
1271 iwe.cmd = SIOCGIWENCODE;
1272 if (CAP_IS_PRIVACY_ON (pAdapter->ScanTab.BssEntry[i].CapabilityInfo ))
1273 iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1275 iwe.u.data.flags = IW_ENCODE_DISABLED;
1277 previous_ev = current_ev;
1278 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);
1279 if (current_ev == previous_ev)
1283 //================================
1284 if (pAdapter->ScanTab.BssEntry[i].SupRateLen)
1286 UCHAR tmpRate = pAdapter->ScanTab.BssEntry[i].SupRate[pAdapter->ScanTab.BssEntry[i].SupRateLen-1];
1287 memset(&iwe, 0, sizeof(iwe));
1288 iwe.cmd = SIOCGIWRATE;
1289 current_val = current_ev + IW_EV_LCP_LEN;
1290 if (tmpRate == 0x82)
1291 iwe.u.bitrate.value = 1 * 1000000;
1292 else if (tmpRate == 0x84)
1293 iwe.u.bitrate.value = 2 * 1000000;
1294 else if (tmpRate == 0x8B)
1295 iwe.u.bitrate.value = 5.5 * 1000000;
1296 else if (tmpRate == 0x96)
1297 iwe.u.bitrate.value = 11 * 1000000;
1299 iwe.u.bitrate.value = (tmpRate/2) * 1000000;
1301 iwe.u.bitrate.disabled = 0;
1302 current_val = iwe_stream_add_value(info, current_ev,
1303 current_val, end_buf, &iwe,
1306 if((current_val-current_ev)>IW_EV_LCP_LEN)
1307 current_ev = current_val;
1313 if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
1315 memset(&iwe, 0, sizeof(iwe));
1316 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1317 memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].WpaIE.IE[0]),
1318 pAdapter->ScanTab.BssEntry[i].WpaIE.IELen);
1319 iwe.cmd = IWEVGENIE;
1320 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].WpaIE.IELen;
1321 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, custom);
1322 if (current_ev == previous_ev)
1327 if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
1329 memset(&iwe, 0, sizeof(iwe));
1330 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1331 memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].RsnIE.IE[0]),
1332 pAdapter->ScanTab.BssEntry[i].RsnIE.IELen);
1333 iwe.cmd = IWEVGENIE;
1334 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].RsnIE.IELen;
1335 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, custom);
1336 if (current_ev == previous_ev)
1341 data->length = current_ev - extra;
1342 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
1343 DBGPRINT(RT_DEBUG_ERROR ,("===>rt_ioctl_giwscan. %d(%d) BSS returned, data->length = %d\n",i , pAdapter->ScanTab.BssNr, data->length));
1347 int rt_ioctl_siwessid(struct net_device *dev,
1348 struct iw_request_info *info,
1349 struct iw_point *data, char *essid)
1351 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1353 //check if the interface is down
1354 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1356 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1362 PCHAR pSsidString = NULL;
1364 // Includes null character.
1365 if (data->length > (IW_ESSID_MAX_SIZE + 1))
1368 pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
1371 NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
1372 NdisMoveMemory(pSsidString, essid, data->length);
1373 if (Set_SSID_Proc(pAdapter, pSsidString) == FALSE)
1382 if (Set_SSID_Proc(pAdapter, "") == FALSE)
1388 int rt_ioctl_giwessid(struct net_device *dev,
1389 struct iw_request_info *info,
1390 struct iw_point *data, char *essid)
1393 PRTMP_ADAPTER pAdapter = NULL;
1394 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1396 if (dev->priv_flags == INT_MAIN)
1398 pAdapter = dev->ml_priv;
1402 pVirtualAd = dev->ml_priv;
1403 if (pVirtualAd && pVirtualAd->RtmpDev)
1404 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1407 if (pAdapter == NULL)
1409 /* if 1st open fail, pAd will be free;
1410 So the net_dev->ml_priv will be NULL in 2rd open */
1415 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1419 if (MONITOR_ON(pAdapter))
1425 if (OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED))
1427 DBGPRINT(RT_DEBUG_TRACE ,("MediaState is connected\n"));
1428 data->length = pAdapter->CommonCfg.SsidLen;
1429 memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
1433 else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
1435 data->length = pAdapter->CommonCfg.SsidLen;
1436 memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
1440 {//the ANY ssid was specified
1442 DBGPRINT(RT_DEBUG_TRACE ,("MediaState is not connected, ess\n"));
1449 int rt_ioctl_siwnickn(struct net_device *dev,
1450 struct iw_request_info *info,
1451 struct iw_point *data, char *nickname)
1453 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1455 //check if the interface is down
1456 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1458 DBGPRINT(RT_DEBUG_TRACE ,("INFO::Network is down!\n"));
1462 if (data->length > IW_ESSID_MAX_SIZE)
1465 memset(pAdapter->nickname, 0, IW_ESSID_MAX_SIZE + 1);
1466 memcpy(pAdapter->nickname, nickname, data->length);
1472 int rt_ioctl_giwnickn(struct net_device *dev,
1473 struct iw_request_info *info,
1474 struct iw_point *data, char *nickname)
1477 PRTMP_ADAPTER pAdapter = NULL;
1478 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1480 if (dev->priv_flags == INT_MAIN)
1482 pAdapter = dev->ml_priv;
1486 pVirtualAd = dev->ml_priv;
1487 if (pVirtualAd && pVirtualAd->RtmpDev)
1488 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1491 if (pAdapter == NULL)
1493 /* if 1st open fail, pAd will be free;
1494 So the net_dev->ml_priv will be NULL in 2rd open */
1499 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1502 if (data->length > strlen(pAdapter->nickname) + 1)
1503 data->length = strlen(pAdapter->nickname) + 1;
1504 if (data->length > 0) {
1505 memcpy(nickname, pAdapter->nickname, data->length-1);
1506 nickname[data->length-1] = '\0';
1511 int rt_ioctl_siwrts(struct net_device *dev,
1512 struct iw_request_info *info,
1513 struct iw_param *rts, char *extra)
1515 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1518 //check if the interface is down
1519 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1521 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1526 val = MAX_RTS_THRESHOLD;
1527 else if (rts->value < 0 || rts->value > MAX_RTS_THRESHOLD)
1529 else if (rts->value == 0)
1530 val = MAX_RTS_THRESHOLD;
1534 if (val != pAdapter->CommonCfg.RtsThreshold)
1535 pAdapter->CommonCfg.RtsThreshold = val;
1540 int rt_ioctl_giwrts(struct net_device *dev,
1541 struct iw_request_info *info,
1542 struct iw_param *rts, char *extra)
1545 PRTMP_ADAPTER pAdapter = NULL;
1546 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1548 if (dev->priv_flags == INT_MAIN)
1550 pAdapter = dev->ml_priv;
1554 pVirtualAd = dev->ml_priv;
1555 if (pVirtualAd && pVirtualAd->RtmpDev)
1556 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1559 if (pAdapter == NULL)
1561 /* if 1st open fail, pAd will be free;
1562 So the net_dev->ml_priv will be NULL in 2rd open */
1567 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1570 //check if the interface is down
1571 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1573 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1577 rts->value = pAdapter->CommonCfg.RtsThreshold;
1578 rts->disabled = (rts->value == MAX_RTS_THRESHOLD);
1584 int rt_ioctl_siwfrag(struct net_device *dev,
1585 struct iw_request_info *info,
1586 struct iw_param *frag, char *extra)
1588 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1591 //check if the interface is down
1592 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1594 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1599 val = MAX_FRAG_THRESHOLD;
1600 else if (frag->value >= MIN_FRAG_THRESHOLD || frag->value <= MAX_FRAG_THRESHOLD)
1601 val = __cpu_to_le16(frag->value & ~0x1); /* even numbers only */
1602 else if (frag->value == 0)
1603 val = MAX_FRAG_THRESHOLD;
1607 pAdapter->CommonCfg.FragmentThreshold = val;
1611 int rt_ioctl_giwfrag(struct net_device *dev,
1612 struct iw_request_info *info,
1613 struct iw_param *frag, char *extra)
1616 PRTMP_ADAPTER pAdapter = NULL;
1617 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1619 if (dev->priv_flags == INT_MAIN)
1621 pAdapter = dev->ml_priv;
1625 pVirtualAd = dev->ml_priv;
1626 if (pVirtualAd && pVirtualAd->RtmpDev)
1627 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1630 if (pAdapter == NULL)
1632 /* if 1st open fail, pAd will be free;
1633 So the net_dev->ml_priv will be NULL in 2rd open */
1638 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1641 //check if the interface is down
1642 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1644 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1648 frag->value = pAdapter->CommonCfg.FragmentThreshold;
1649 frag->disabled = (frag->value == MAX_FRAG_THRESHOLD);
1655 #define MAX_WEP_KEY_SIZE 13
1656 #define MIN_WEP_KEY_SIZE 5
1657 int rt_ioctl_siwencode(struct net_device *dev,
1658 struct iw_request_info *info,
1659 struct iw_point *erq, char *extra)
1661 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1663 //check if the interface is down
1664 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1666 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1670 if ((erq->length == 0) &&
1671 (erq->flags & IW_ENCODE_DISABLED))
1673 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
1674 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
1675 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
1676 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
1677 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1681 else if ((erq->length == 0) &&
1682 (erq->flags & IW_ENCODE_RESTRICTED || erq->flags & IW_ENCODE_OPEN))
1685 else if (erq->flags & IW_ENCODE_RESTRICTED || erq->flags & IW_ENCODE_OPEN)
1688 STA_PORT_SECURED(pAdapter);
1689 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
1690 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
1691 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
1692 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
1693 if (erq->flags & IW_ENCODE_RESTRICTED)
1694 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
1696 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1702 if (erq->length > 0)
1704 int keyIdx = (erq->flags & IW_ENCODE_INDEX) - 1;
1705 /* Check the size of the key */
1706 if (erq->length > MAX_WEP_KEY_SIZE) {
1709 /* Check key index */
1710 if ((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
1712 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::Wrong keyIdx=%d! Using default key instead (%d)\n",
1713 keyIdx, pAdapter->StaCfg.DefaultKeyId));
1716 keyIdx = pAdapter->StaCfg.DefaultKeyId;
1721 pAdapter->StaCfg.DefaultKeyId=keyIdx;
1725 NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
1727 if (erq->length == MAX_WEP_KEY_SIZE)
1729 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
1730 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
1732 else if (erq->length == MIN_WEP_KEY_SIZE)
1734 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
1735 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
1738 /* Disable the key */
1739 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
1741 /* Check if the key is not marked as invalid */
1742 if(!(erq->flags & IW_ENCODE_NOKEY)) {
1743 /* Copy the key in the driver */
1744 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, extra, erq->length);
1749 /* Do we want to just set the transmit key index ? */
1750 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
1751 if ((index >= 0) && (index < 4))
1753 pAdapter->StaCfg.DefaultKeyId = index;
1756 /* Don't complain if only change the mode */
1757 if (!(erq->flags & IW_ENCODE_MODE)) {
1763 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::erq->flags=%x\n",erq->flags));
1764 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::AuthMode=%x\n",pAdapter->StaCfg.AuthMode));
1765 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::DefaultKeyId=%x, KeyLen = %d\n",pAdapter->StaCfg.DefaultKeyId , pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen));
1766 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::WepStatus=%x\n",pAdapter->StaCfg.WepStatus));
1771 rt_ioctl_giwencode(struct net_device *dev,
1772 struct iw_request_info *info,
1773 struct iw_point *erq, char *key)
1776 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1780 PRTMP_ADAPTER pAdapter = NULL;
1781 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1783 if (dev->priv_flags == INT_MAIN)
1785 pAdapter = dev->ml_priv;
1789 pVirtualAd = dev->ml_priv;
1790 if (pVirtualAd && pVirtualAd->RtmpDev)
1791 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1794 if (pAdapter == NULL)
1796 /* if 1st open fail, pAd will be free;
1797 So the net_dev->ml_priv will be NULL in 2rd open */
1802 //check if the interface is down
1803 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1805 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1809 kid = erq->flags & IW_ENCODE_INDEX;
1810 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_giwencode %d\n", erq->flags & IW_ENCODE_INDEX));
1812 if (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled)
1815 erq->flags = IW_ENCODE_DISABLED;
1817 else if ((kid > 0) && (kid <=4))
1820 erq->flags = kid ; /* NB: base 1 */
1821 if (erq->length > pAdapter->SharedKey[BSS0][kid-1].KeyLen)
1822 erq->length = pAdapter->SharedKey[BSS0][kid-1].KeyLen;
1823 memcpy(key, pAdapter->SharedKey[BSS0][kid-1].Key, erq->length);
1824 //if ((kid == pAdapter->PortCfg.DefaultKeyId))
1825 //erq->flags |= IW_ENCODE_ENABLED; /* XXX */
1826 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1827 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1829 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1834 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1835 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1837 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1838 erq->length = pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen;
1839 memcpy(key, pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key, erq->length);
1840 // copy default key ID
1841 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1842 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1844 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1845 erq->flags = pAdapter->StaCfg.DefaultKeyId + 1; /* NB: base 1 */
1846 erq->flags |= IW_ENCODE_ENABLED; /* XXX */
1854 rt_ioctl_setparam(struct net_device *dev, struct iw_request_info *info,
1855 void *w, char *extra)
1857 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1858 PRTMP_ADAPTER pAdapter;
1860 char *this_char = extra;
1864 if (dev->priv_flags == INT_MAIN)
1866 pAdapter = dev->ml_priv;
1870 pVirtualAd = dev->ml_priv;
1871 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1873 pObj = (POS_COOKIE) pAdapter->OS_Cookie;
1875 if (pAdapter == NULL)
1877 /* if 1st open fail, pAd will be free;
1878 So the net_dev->ml_priv will be NULL in 2rd open */
1883 pObj->ioctl_if_type = INT_MAIN;
1884 pObj->ioctl_if = MAIN_MBSSID;
1887 //check if the interface is down
1888 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1890 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1897 if ((value = rtstrchr(this_char, '=')) != NULL)
1903 // reject setting nothing besides ANY ssid(ssidLen=0)
1904 if (!*value && (strcmp(this_char, "SSID") != 0))
1907 for (PRTMP_PRIVATE_SET_PROC = RTMP_PRIVATE_SUPPORT_PROC; PRTMP_PRIVATE_SET_PROC->name; PRTMP_PRIVATE_SET_PROC++)
1909 if (strcmp(this_char, PRTMP_PRIVATE_SET_PROC->name) == 0)
1911 if(!PRTMP_PRIVATE_SET_PROC->set_proc(pAdapter, value))
1912 { //FALSE:Set private failed then return Invalid argument
1915 break; //Exit for loop.
1919 if(PRTMP_PRIVATE_SET_PROC->name == NULL)
1920 { //Not found argument
1922 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_setparam:: (iwpriv) Not Support Set Command [%s=%s]\n", this_char, value));
1930 rt_private_get_statistics(struct net_device *dev, struct iw_request_info *info,
1931 struct iw_point *wrq, char *extra)
1934 PRTMP_ADAPTER pAd = dev->ml_priv;
1942 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
1943 sprintf(extra, "\n\n");
1946 sprintf(extra+strlen(extra), "Tx success = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart);
1947 sprintf(extra+strlen(extra), "Tx success without retry = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart - (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
1949 sprintf(extra+strlen(extra), "Tx success after retry = %ld\n", (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
1950 sprintf(extra+strlen(extra), "Tx fail to Rcv ACK after retry = %ld\n", (ULONG)pAd->WlanCounters.FailedCount.QuadPart);
1951 sprintf(extra+strlen(extra), "RTS Success Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSSuccessCount.QuadPart);
1952 sprintf(extra+strlen(extra), "RTS Fail Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSFailureCount.QuadPart);
1954 sprintf(extra+strlen(extra), "Rx success = %ld\n", (ULONG)pAd->WlanCounters.ReceivedFragmentCount.QuadPart);
1955 sprintf(extra+strlen(extra), "Rx with CRC = %ld\n", (ULONG)pAd->WlanCounters.FCSErrorCount.QuadPart);
1956 sprintf(extra+strlen(extra), "Rx drop due to out of resource = %ld\n", (ULONG)pAd->Counters8023.RxNoBuffer);
1957 sprintf(extra+strlen(extra), "Rx duplicate frame = %ld\n", (ULONG)pAd->WlanCounters.FrameDuplicateCount.QuadPart);
1959 sprintf(extra+strlen(extra), "False CCA (one second) = %ld\n", (ULONG)pAd->RalinkCounters.OneSecFalseCCACnt);
1961 sprintf(extra+strlen(extra), "RSSI-A = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi0 - pAd->BbpRssiToDbmDelta));
1962 sprintf(extra+strlen(extra), "RSSI-B (if available) = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi1 - pAd->BbpRssiToDbmDelta));
1963 sprintf(extra+strlen(extra), "RSSI-C (if available) = %ld\n\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi2 - pAd->BbpRssiToDbmDelta));
1965 sprintf(extra+strlen(extra), "WpaSupplicantUP = %d\n\n", pAd->StaCfg.WpaSupplicantUP);
1967 wrq->length = strlen(extra) + 1; // 1: size of '\0'
1968 DBGPRINT(RT_DEBUG_TRACE, ("<== rt_private_get_statistics, wrq->length = %d\n", wrq->length));
1974 IN PRTMP_ADAPTER pAd,
1978 BA_ORI_ENTRY *pOriBAEntry;
1979 BA_REC_ENTRY *pRecBAEntry;
1981 for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
1983 PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
1984 if (((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
1985 || (pEntry->ValidAsWDS) || (pEntry->ValidAsMesh))
1987 sprintf(pOutBuf + strlen(pOutBuf), "\n%02X:%02X:%02X:%02X:%02X:%02X (Aid = %d) (AP) -\n",
1988 pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
1989 pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5], pEntry->Aid);
1991 sprintf(pOutBuf, "%s[Recipient]\n", pOutBuf);
1992 for (j=0; j < NUM_OF_TID; j++)
1994 if (pEntry->BARecWcidArray[j] != 0)
1996 pRecBAEntry =&pAd->BATable.BARecEntry[pEntry->BARecWcidArray[j]];
1997 sprintf(pOutBuf + strlen(pOutBuf), "TID=%d, BAWinSize=%d, LastIndSeq=%d, ReorderingPkts=%d\n", j, pRecBAEntry->BAWinSize, pRecBAEntry->LastIndSeq, pRecBAEntry->list.qlen);
2000 sprintf(pOutBuf, "%s\n", pOutBuf);
2002 sprintf(pOutBuf, "%s[Originator]\n", pOutBuf);
2003 for (j=0; j < NUM_OF_TID; j++)
2005 if (pEntry->BAOriWcidArray[j] != 0)
2007 pOriBAEntry =&pAd->BATable.BAOriEntry[pEntry->BAOriWcidArray[j]];
2008 sprintf(pOutBuf + strlen(pOutBuf), "TID=%d, BAWinSize=%d, StartSeq=%d, CurTxSeq=%d\n", j, pOriBAEntry->BAWinSize, pOriBAEntry->Sequence, pEntry->TxSeq[j]);
2011 sprintf(pOutBuf, "%s\n\n", pOutBuf);
2013 if (strlen(pOutBuf) > (IW_PRIV_SIZE_MASK - 30))
2021 rt_private_show(struct net_device *dev, struct iw_request_info *info,
2022 struct iw_point *wrq, char *extra)
2025 VIRTUAL_ADAPTER *pVirtualAd = NULL;
2028 u32 subcmd = wrq->flags;
2030 if (dev->priv_flags == INT_MAIN)
2034 pVirtualAd = dev->ml_priv;
2035 pAd = pVirtualAd->RtmpDev->ml_priv;
2037 pObj = (POS_COOKIE) pAd->OS_Cookie;
2041 /* if 1st open fail, pAd will be free;
2042 So the net_dev->ml_priv will be NULL in 2rd open */
2051 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2054 pObj->ioctl_if_type = INT_MAIN;
2055 pObj->ioctl_if = MAIN_MBSSID;
2061 case SHOW_CONN_STATUS:
2062 if (MONITOR_ON(pAd))
2064 if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
2065 pAd->CommonCfg.RegTransmitSetting.field.BW)
2066 sprintf(extra, "Monitor Mode(CentralChannel %d)\n", pAd->CommonCfg.CentralChannel);
2068 sprintf(extra, "Monitor Mode(Channel %d)\n", pAd->CommonCfg.Channel);
2072 if (pAd->IndicateMediaState == NdisMediaStateConnected)
2076 sprintf(extra, "Connected(AP: %s[%02X:%02X:%02X:%02X:%02X:%02X])\n",
2077 pAd->CommonCfg.Ssid,
2078 pAd->CommonCfg.Bssid[0],
2079 pAd->CommonCfg.Bssid[1],
2080 pAd->CommonCfg.Bssid[2],
2081 pAd->CommonCfg.Bssid[3],
2082 pAd->CommonCfg.Bssid[4],
2083 pAd->CommonCfg.Bssid[5]);
2084 DBGPRINT(RT_DEBUG_TRACE ,("Ssid=%s ,Ssidlen = %d\n",pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen));
2086 else if (ADHOC_ON(pAd))
2087 sprintf(extra, "Connected\n");
2091 sprintf(extra, "Disconnected\n");
2092 DBGPRINT(RT_DEBUG_TRACE ,("ConnStatus is not connected\n"));
2095 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2097 case SHOW_DRVIER_VERION:
2098 sprintf(extra, "Driver version-%s, %s %s\n", STA_DRIVER_VERSION, __DATE__, __TIME__ );
2099 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2102 getBaInfo(pAd, extra);
2103 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2105 case SHOW_DESC_INFO:
2107 Show_DescInfo_Proc(pAd, NULL);
2108 wrq->length = 0; // 1: size of '\0'
2112 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
2114 sprintf(extra, "Scanning\n");
2115 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2118 pAd->StaCfg.bSwRadio = FALSE;
2119 if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
2121 pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
2122 if (pAd->StaCfg.bRadio == FALSE)
2125 // Update extra information
2126 pAd->ExtraInfo = SW_RADIO_OFF;
2129 sprintf(extra, "Radio Off\n");
2130 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2134 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
2136 sprintf(extra, "Scanning\n");
2137 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2141 pAd->StaCfg.bSwRadio = TRUE;
2142 //if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
2144 pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
2145 if (pAd->StaCfg.bRadio == TRUE)
2148 // Update extra information
2149 pAd->ExtraInfo = EXTRA_INFO_CLEAR;
2152 sprintf(extra, "Radio On\n");
2153 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2156 case SHOW_CFG_VALUE:
2158 Status = RTMPShowCfgValue(pAd, wrq->pointer, extra);
2160 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2163 #if !defined(RT2860) && !defined(RT30xx)
2164 case SHOW_ADHOC_ENTRY_INFO:
2165 Show_Adhoc_MacTable_Proc(pAd, extra);
2166 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2170 DBGPRINT(RT_DEBUG_TRACE, ("%s - unknow subcmd = %d\n", __func__, subcmd));
2177 int rt_ioctl_siwmlme(struct net_device *dev,
2178 struct iw_request_info *info,
2179 union iwreq_data *wrqu,
2182 PRTMP_ADAPTER pAd = dev->ml_priv;
2183 struct iw_mlme *pMlme = (struct iw_mlme *)wrqu->data.pointer;
2184 MLME_QUEUE_ELEM MsgElem;
2185 MLME_DISASSOC_REQ_STRUCT DisAssocReq;
2186 MLME_DEAUTH_REQ_STRUCT DeAuthReq;
2188 DBGPRINT(RT_DEBUG_TRACE, ("====> %s\n", __func__));
2195 #ifdef IW_MLME_DEAUTH
2196 case IW_MLME_DEAUTH:
2197 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DEAUTH\n", __func__));
2198 COPY_MAC_ADDR(DeAuthReq.Addr, pAd->CommonCfg.Bssid);
2199 DeAuthReq.Reason = pMlme->reason_code;
2200 MsgElem.MsgLen = sizeof(MLME_DEAUTH_REQ_STRUCT);
2201 NdisMoveMemory(MsgElem.Msg, &DeAuthReq, sizeof(MLME_DEAUTH_REQ_STRUCT));
2202 MlmeDeauthReqAction(pAd, &MsgElem);
2205 LinkDown(pAd, FALSE);
2206 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
2209 #endif // IW_MLME_DEAUTH //
2210 #ifdef IW_MLME_DISASSOC
2211 case IW_MLME_DISASSOC:
2212 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DISASSOC\n", __func__));
2213 COPY_MAC_ADDR(DisAssocReq.Addr, pAd->CommonCfg.Bssid);
2214 DisAssocReq.Reason = pMlme->reason_code;
2216 MsgElem.Machine = ASSOC_STATE_MACHINE;
2217 MsgElem.MsgType = MT2_MLME_DISASSOC_REQ;
2218 MsgElem.MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
2219 NdisMoveMemory(MsgElem.Msg, &DisAssocReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
2221 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
2222 MlmeDisassocReqAction(pAd, &MsgElem);
2224 #endif // IW_MLME_DISASSOC //
2226 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - Unknow Command\n", __func__));
2233 int rt_ioctl_siwauth(struct net_device *dev,
2234 struct iw_request_info *info,
2235 union iwreq_data *wrqu, char *extra)
2237 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2238 struct iw_param *param = &wrqu->param;
2240 //check if the interface is down
2241 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2243 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2246 switch (param->flags & IW_AUTH_INDEX) {
2247 case IW_AUTH_WPA_VERSION:
2248 if (param->value == IW_AUTH_WPA_VERSION_WPA)
2250 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
2251 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
2252 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
2254 else if (param->value == IW_AUTH_WPA_VERSION_WPA2)
2255 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
2257 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __func__, param->value));
2259 case IW_AUTH_CIPHER_PAIRWISE:
2260 if (param->value == IW_AUTH_CIPHER_NONE)
2262 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
2263 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2264 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
2266 else if (param->value == IW_AUTH_CIPHER_WEP40 ||
2267 param->value == IW_AUTH_CIPHER_WEP104)
2269 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
2270 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2271 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
2272 pAdapter->StaCfg.IEEE8021X = FALSE;
2274 else if (param->value == IW_AUTH_CIPHER_TKIP)
2276 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
2277 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2278 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
2280 else if (param->value == IW_AUTH_CIPHER_CCMP)
2282 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
2283 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2284 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
2286 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_PAIRWISE - param->value = %d!\n", __func__, param->value));
2288 case IW_AUTH_CIPHER_GROUP:
2289 if (param->value == IW_AUTH_CIPHER_NONE)
2291 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
2293 else if (param->value == IW_AUTH_CIPHER_WEP40 ||
2294 param->value == IW_AUTH_CIPHER_WEP104)
2296 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
2298 else if (param->value == IW_AUTH_CIPHER_TKIP)
2300 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
2302 else if (param->value == IW_AUTH_CIPHER_CCMP)
2304 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
2306 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_GROUP - param->value = %d!\n", __func__, param->value));
2308 case IW_AUTH_KEY_MGMT:
2309 if (param->value == IW_AUTH_KEY_MGMT_802_1X)
2311 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)
2313 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
2314 pAdapter->StaCfg.IEEE8021X = FALSE;
2316 else if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
2318 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
2319 pAdapter->StaCfg.IEEE8021X = FALSE;
2323 pAdapter->StaCfg.IEEE8021X = TRUE;
2325 else if (param->value == 0)
2327 STA_PORT_SECURED(pAdapter);
2329 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_KEY_MGMT - param->value = %d!\n", __func__, param->value));
2331 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
2333 case IW_AUTH_PRIVACY_INVOKED:
2334 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_PRIVACY_INVOKED - param->value = %d!\n", __func__, param->value));
2336 case IW_AUTH_DROP_UNENCRYPTED:
2337 if (param->value != 0)
2338 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
2341 STA_PORT_SECURED(pAdapter);
2343 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __func__, param->value));
2345 case IW_AUTH_80211_AUTH_ALG:
2346 if (param->value & IW_AUTH_ALG_SHARED_KEY)
2348 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
2350 else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
2352 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
2356 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_80211_AUTH_ALG - param->value = %d!\n", __func__, param->value));
2358 case IW_AUTH_WPA_ENABLED:
2359 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_ENABLED - Driver supports WPA!(param->value = %d)\n", __func__, param->value));
2368 int rt_ioctl_giwauth(struct net_device *dev,
2369 struct iw_request_info *info,
2370 union iwreq_data *wrqu, char *extra)
2372 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2373 struct iw_param *param = &wrqu->param;
2375 //check if the interface is down
2376 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2378 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2382 switch (param->flags & IW_AUTH_INDEX) {
2383 case IW_AUTH_DROP_UNENCRYPTED:
2384 param->value = (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled) ? 0 : 1;
2387 case IW_AUTH_80211_AUTH_ALG:
2388 param->value = (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared) ? IW_AUTH_ALG_SHARED_KEY : IW_AUTH_ALG_OPEN_SYSTEM;
2391 case IW_AUTH_WPA_ENABLED:
2392 param->value = (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) ? 1 : 0;
2398 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_giwauth::param->value = %d!\n", param->value));
2402 void fnSetCipherKey(
2403 IN PRTMP_ADAPTER pAdapter,
2407 IN struct iw_encode_ext *ext)
2410 RTMP_CLEAR_PSFLAG(pAdapter, fRTMP_PS_CAN_GO_SLEEP);
2411 if (RTMP_TEST_PSFLAG(pAdapter, fRTMP_PS_SET_PCI_CLK_OFF_COMMAND))
2413 if (pAdapter->StaCfg.bRadio == FALSE)
2415 RTMP_SET_PSFLAG(pAdapter, fRTMP_PS_CAN_GO_SLEEP);
2418 DBGPRINT(RT_DEBUG_TRACE,("RTMPWPAAddKeyProc1==>\n"));
2419 RTMPPCIeLinkCtrlValueRestore(pAdapter, RESTORE_HALT);
2420 RTMPusecDelay(6000);
2421 pAdapter->bPCIclkOff = FALSE;
2424 NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
2425 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = LEN_TKIP_EK;
2426 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, LEN_TKIP_EK);
2427 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].TxMic, ext->key + LEN_TKIP_EK, LEN_TKIP_TXMICK);
2428 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].RxMic, ext->key + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
2429 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CipherAlg;
2431 // Update group key information to ASIC Shared Key Table
2432 AsicAddSharedKeyEntry(pAdapter,
2435 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2436 pAdapter->SharedKey[BSS0][keyIdx].Key,
2437 pAdapter->SharedKey[BSS0][keyIdx].TxMic,
2438 pAdapter->SharedKey[BSS0][keyIdx].RxMic);
2441 // Update ASIC WCID attribute table and IVEIV table
2442 RTMPAddWcidAttributeEntry(pAdapter,
2445 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2448 // Update ASIC WCID attribute table and IVEIV table
2449 RTMPAddWcidAttributeEntry(pAdapter,
2452 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2453 &pAdapter->MacTab.Content[BSSID_WCID]);
2455 RTMP_SET_PSFLAG(pAdapter, fRTMP_PS_CAN_GO_SLEEP);
2459 int rt_ioctl_siwencodeext(struct net_device *dev,
2460 struct iw_request_info *info,
2461 union iwreq_data *wrqu,
2464 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2465 struct iw_point *encoding = &wrqu->encoding;
2466 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2467 int keyIdx, alg = ext->alg;
2469 //check if the interface is down
2470 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2472 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2476 if (encoding->flags & IW_ENCODE_DISABLED)
2478 keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
2479 // set BSSID wcid entry of the Pair-wise Key table as no-security mode
2480 AsicRemovePairwiseKeyEntry(pAdapter, BSS0, BSSID_WCID);
2481 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
2482 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_NONE;
2483 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)keyIdx);
2484 NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
2485 DBGPRINT(RT_DEBUG_TRACE, ("%s::Remove all keys!(encoding->flags = %x)\n", __func__, encoding->flags));
2489 // Get Key Index and convet to our own defined key index
2490 keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
2491 if((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
2494 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2496 pAdapter->StaCfg.DefaultKeyId = keyIdx;
2497 DBGPRINT(RT_DEBUG_TRACE, ("%s::DefaultKeyId = %d\n", __func__, pAdapter->StaCfg.DefaultKeyId));
2501 case IW_ENCODE_ALG_NONE:
2502 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_NONE\n", __func__));
2504 case IW_ENCODE_ALG_WEP:
2505 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_WEP - ext->key_len = %d, keyIdx = %d\n", __func__, ext->key_len, keyIdx));
2506 if (ext->key_len == MAX_WEP_KEY_SIZE)
2508 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
2509 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
2511 else if (ext->key_len == MIN_WEP_KEY_SIZE)
2513 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
2514 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
2519 NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
2520 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, ext->key_len);
2522 if (pAdapter->StaCfg.GroupCipher == Ndis802_11GroupWEP40Enabled ||
2523 pAdapter->StaCfg.GroupCipher == Ndis802_11GroupWEP104Enabled)
2525 // Set Group key material to Asic
2526 AsicAddSharedKeyEntry(pAdapter, BSS0, keyIdx, pAdapter->SharedKey[BSS0][keyIdx].CipherAlg, pAdapter->SharedKey[BSS0][keyIdx].Key, NULL, NULL);
2528 // Update WCID attribute table and IVEIV table for this group key table
2529 RTMPAddWcidAttributeEntry(pAdapter, BSS0, keyIdx, pAdapter->SharedKey[BSS0][keyIdx].CipherAlg, NULL);
2531 STA_PORT_SECURED(pAdapter);
2533 // Indicate Connected for GUI
2534 pAdapter->IndicateMediaState = NdisMediaStateConnected;
2538 case IW_ENCODE_ALG_TKIP:
2539 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_TKIP - keyIdx = %d, ext->key_len = %d\n", __func__, keyIdx, ext->key_len));
2540 if (ext->key_len == 32)
2542 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2544 fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, FALSE, ext);
2545 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
2547 STA_PORT_SECURED(pAdapter);
2550 else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
2552 fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, TRUE, ext);
2554 // set 802.1x port control
2555 STA_PORT_SECURED(pAdapter);
2561 case IW_ENCODE_ALG_CCMP:
2562 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2564 fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, FALSE, ext);
2565 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
2566 STA_PORT_SECURED(pAdapter);
2568 else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
2570 fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, TRUE, ext);
2572 // set 802.1x port control
2573 STA_PORT_SECURED(pAdapter);
2585 rt_ioctl_giwencodeext(struct net_device *dev,
2586 struct iw_request_info *info,
2587 union iwreq_data *wrqu, char *extra)
2589 PRTMP_ADAPTER pAd = dev->ml_priv;
2591 struct iw_point *encoding = &wrqu->encoding;
2592 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2593 int idx, max_key_len;
2595 DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_giwencodeext\n"));
2597 max_key_len = encoding->length - sizeof(*ext);
2598 if (max_key_len < 0)
2601 idx = encoding->flags & IW_ENCODE_INDEX;
2604 if (idx < 1 || idx > 4)
2608 if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
2609 (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled))
2611 if (idx != pAd->StaCfg.DefaultKeyId)
2619 idx = pAd->StaCfg.DefaultKeyId;
2621 encoding->flags = idx + 1;
2622 memset(ext, 0, sizeof(*ext));
2625 switch(pAd->StaCfg.WepStatus) {
2626 case Ndis802_11WEPDisabled:
2627 ext->alg = IW_ENCODE_ALG_NONE;
2628 encoding->flags |= IW_ENCODE_DISABLED;
2630 case Ndis802_11WEPEnabled:
2631 ext->alg = IW_ENCODE_ALG_WEP;
2632 if (pAd->SharedKey[BSS0][idx].KeyLen > max_key_len)
2636 ext->key_len = pAd->SharedKey[BSS0][idx].KeyLen;
2637 pKey = &(pAd->SharedKey[BSS0][idx].Key[0]);
2640 case Ndis802_11Encryption2Enabled:
2641 case Ndis802_11Encryption3Enabled:
2642 if (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
2643 ext->alg = IW_ENCODE_ALG_TKIP;
2645 ext->alg = IW_ENCODE_ALG_CCMP;
2647 if (max_key_len < 32)
2652 pKey = &pAd->StaCfg.PMK[0];
2659 if (ext->key_len && pKey)
2661 encoding->flags |= IW_ENCODE_ENABLED;
2662 memcpy(ext->key, pKey, ext->key_len);
2668 int rt_ioctl_siwgenie(struct net_device *dev,
2669 struct iw_request_info *info,
2670 union iwreq_data *wrqu, char *extra)
2672 PRTMP_ADAPTER pAd = dev->ml_priv;
2674 if (wrqu->data.length > MAX_LEN_OF_RSNIE ||
2675 (wrqu->data.length && extra == NULL))
2678 if (wrqu->data.length)
2680 pAd->StaCfg.RSNIE_Len = wrqu->data.length;
2681 NdisMoveMemory(&pAd->StaCfg.RSN_IE[0], extra, pAd->StaCfg.RSNIE_Len);
2685 pAd->StaCfg.RSNIE_Len = 0;
2686 NdisZeroMemory(&pAd->StaCfg.RSN_IE[0], MAX_LEN_OF_RSNIE);
2692 int rt_ioctl_giwgenie(struct net_device *dev,
2693 struct iw_request_info *info,
2694 union iwreq_data *wrqu, char *extra)
2696 PRTMP_ADAPTER pAd = dev->ml_priv;
2698 if ((pAd->StaCfg.RSNIE_Len == 0) ||
2699 (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA))
2701 wrqu->data.length = 0;
2705 if (pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
2707 if (wrqu->data.length < pAd->StaCfg.RSNIE_Len)
2710 wrqu->data.length = pAd->StaCfg.RSNIE_Len;
2711 memcpy(extra, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
2715 UCHAR RSNIe = IE_WPA;
2717 if (wrqu->data.length < (pAd->StaCfg.RSNIE_Len + 2)) // ID, Len
2719 wrqu->data.length = pAd->StaCfg.RSNIE_Len + 2;
2721 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
2722 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2))
2725 extra[0] = (char)RSNIe;
2726 extra[1] = pAd->StaCfg.RSNIE_Len;
2727 memcpy(extra+2, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
2733 int rt_ioctl_siwpmksa(struct net_device *dev,
2734 struct iw_request_info *info,
2735 union iwreq_data *wrqu,
2738 PRTMP_ADAPTER pAd = dev->ml_priv;
2739 struct iw_pmksa *pPmksa = (struct iw_pmksa *)wrqu->data.pointer;
2740 INT CachedIdx = 0, idx = 0;
2745 DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_siwpmksa\n"));
2748 case IW_PMKSA_FLUSH:
2749 NdisZeroMemory(pAd->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
2750 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_FLUSH\n"));
2752 case IW_PMKSA_REMOVE:
2753 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
2755 // compare the BSSID
2756 if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
2758 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN);
2759 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].PMKID, 16);
2760 for (idx = CachedIdx; idx < (pAd->StaCfg.SavedPMKNum - 1); idx++)
2762 NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].BSSID[0], &pAd->StaCfg.SavedPMK[idx+1].BSSID[0], MAC_ADDR_LEN);
2763 NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].PMKID[0], &pAd->StaCfg.SavedPMK[idx+1].PMKID[0], 16);
2765 pAd->StaCfg.SavedPMKNum--;
2770 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_REMOVE\n"));
2773 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
2775 // compare the BSSID
2776 if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
2780 // Found, replace it
2781 if (CachedIdx < PMKID_NO)
2783 DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
2784 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
2785 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
2786 pAd->StaCfg.SavedPMKNum++;
2788 // Not found, replace the last one
2791 // Randomly replace one
2792 CachedIdx = (pPmksa->bssid.sa_data[5] % PMKID_NO);
2793 DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
2794 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
2795 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
2798 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_ADD\n"));
2801 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - Unknow Command!!\n"));
2810 rt_private_ioctl_bbp(struct net_device *dev, struct iw_request_info *info,
2811 struct iw_point *wrq, char *extra)
2818 BOOLEAN bIsPrintAllBBP = FALSE;
2820 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2823 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2825 if (wrq->length > 1) //No parameters.
2827 sprintf(extra, "\n");
2829 //Parsing Read or Write
2830 this_char = wrq->pointer;
2831 DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s\n", this_char));
2835 if ((value = rtstrchr(this_char, '=')) != NULL)
2838 if (!value || !*value)
2840 DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s, value=%s\n", this_char, value));
2841 if (sscanf(this_char, "%d", &(bbpId)) == 1)
2847 if (bbpId <= 138) // edit by johnli, RF power sequence setup, add BBP R138 for ADC dynamic on/off control
2851 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
2853 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
2854 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2855 DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
2858 {//Invalid parametes, so default printk all bbp
2859 bIsPrintAllBBP = TRUE;
2864 { //Invalid parametes, so default printk all bbp
2865 bIsPrintAllBBP = TRUE;
2871 if ((sscanf(this_char, "%d", &(bbpId)) == 1) && (sscanf(value, "%x", &(bbpValue)) == 1))
2877 if (bbpId <= 138) // edit by johnli, RF power sequence setup, add BBP R138 for ADC dynamic on/off control
2881 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, bbpId, bbpValue);
2882 //Read it back for showing
2883 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
2885 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
2886 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2887 DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
2890 {//Invalid parametes, so default printk all bbp
2891 bIsPrintAllBBP = TRUE;
2896 { //Invalid parametes, so default printk all bbp
2897 bIsPrintAllBBP = TRUE;
2903 bIsPrintAllBBP = TRUE;
2908 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2909 sprintf(extra, "\n");
2911 for (bbpId = 0; bbpId <= 136; bbpId++)
2914 for (bbpId = 0; bbpId <= 138; bbpId++) // edit by johnli, RF power sequence setup, add BBP R138 for ADC dynamic on/off control
2917 if (strlen(extra) >= (IW_PRIV_SIZE_MASK - 10))
2919 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
2921 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X ", bbpId, bbpId*2, regBBP);
2923 sprintf(extra+strlen(extra), "\n");
2926 sprintf(extra+strlen(extra), "%03d = %02X\n", bbpId, regBBP); // edit by johnli, change display format
2930 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2931 DBGPRINT(RT_DEBUG_TRACE, ("wrq->length = %d\n", wrq->length));
2934 DBGPRINT(RT_DEBUG_TRACE, ("<==rt_private_ioctl_bbp\n\n"));
2940 int rt_ioctl_siwrate(struct net_device *dev,
2941 struct iw_request_info *info,
2942 union iwreq_data *wrqu, char *extra)
2944 PRTMP_ADAPTER pAd = dev->ml_priv;
2945 UINT32 rate = wrqu->bitrate.value, fixed = wrqu->bitrate.fixed;
2947 //check if the interface is down
2948 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2950 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::Network is down!\n"));
2954 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(rate = %d, fixed = %d)\n", rate, fixed));
2955 /* rate = -1 => auto rate
2956 rate = X, fixed = 1 => (fixed rate X)
2961 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
2962 pAd->StaCfg.bAutoTxRateSwitch = TRUE;
2963 if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
2964 (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
2965 RTMPSetDesiredRates(pAd, -1);
2973 pAd->StaCfg.bAutoTxRateSwitch = FALSE;
2974 if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
2975 (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
2976 RTMPSetDesiredRates(pAd, rate);
2979 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
2982 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(HtMcs=%d)\n",pAd->StaCfg.DesiredTransmitSetting.field.MCS));
2986 // TODO: rate = X, fixed = 0 => (rates <= X)
2994 int rt_ioctl_giwrate(struct net_device *dev,
2995 struct iw_request_info *info,
2996 union iwreq_data *wrqu, char *extra)
2998 PRTMP_ADAPTER pAd = dev->ml_priv;
2999 int rate_index = 0, rate_count = 0;
3000 HTTRANSMIT_SETTING ht_setting;
3001 __s32 ralinkrate[] =
3002 {2, 4, 11, 22, // CCK
3003 12, 18, 24, 36, 48, 72, 96, 108, // OFDM
3004 13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260, // 20MHz, 800ns GI, MCS: 0 ~ 15
3005 39, 78, 117, 156, 234, 312, 351, 390, // 20MHz, 800ns GI, MCS: 16 ~ 23
3006 27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540, // 40MHz, 800ns GI, MCS: 0 ~ 15
3007 81, 162, 243, 324, 486, 648, 729, 810, // 40MHz, 800ns GI, MCS: 16 ~ 23
3008 14, 29, 43, 57, 87, 115, 130, 144, 29, 59, 87, 115, 173, 230, 260, 288, // 20MHz, 400ns GI, MCS: 0 ~ 15
3009 43, 87, 130, 173, 260, 317, 390, 433, // 20MHz, 400ns GI, MCS: 16 ~ 23
3010 30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600, // 40MHz, 400ns GI, MCS: 0 ~ 15
3011 90, 180, 270, 360, 540, 720, 810, 900}; // 40MHz, 400ns GI, MCS: 16 ~ 23
3013 rate_count = sizeof(ralinkrate)/sizeof(__s32);
3014 //check if the interface is down
3015 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
3017 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
3021 if ((pAd->StaCfg.bAutoTxRateSwitch == FALSE) &&
3023 ((pAd->CommonCfg.PhyMode <= PHY_11G) || (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM)))
3024 ht_setting.word = pAd->StaCfg.HTPhyMode.word;
3026 ht_setting.word = pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word;
3028 if (ht_setting.field.MODE >= MODE_HTMIX)
3030 rate_index = 12 + ((UCHAR)ht_setting.field.BW *24) + ((UCHAR)ht_setting.field.ShortGI *48) + ((UCHAR)ht_setting.field.MCS);
3033 if (ht_setting.field.MODE == MODE_OFDM)
3034 rate_index = (UCHAR)(ht_setting.field.MCS) + 4;
3035 else if (ht_setting.field.MODE == MODE_CCK)
3036 rate_index = (UCHAR)(ht_setting.field.MCS);
3041 if (rate_index > rate_count)
3042 rate_index = rate_count;
3044 wrqu->bitrate.value = ralinkrate[rate_index] * 500000;
3045 wrqu->bitrate.disabled = 0;
3050 static const iw_handler rt_handler[] =
3052 (iw_handler) NULL, /* SIOCSIWCOMMIT */
3053 (iw_handler) rt_ioctl_giwname, /* SIOCGIWNAME */
3054 (iw_handler) NULL, /* SIOCSIWNWID */
3055 (iw_handler) NULL, /* SIOCGIWNWID */
3056 (iw_handler) rt_ioctl_siwfreq, /* SIOCSIWFREQ */
3057 (iw_handler) rt_ioctl_giwfreq, /* SIOCGIWFREQ */
3058 (iw_handler) rt_ioctl_siwmode, /* SIOCSIWMODE */
3059 (iw_handler) rt_ioctl_giwmode, /* SIOCGIWMODE */
3060 (iw_handler) NULL, /* SIOCSIWSENS */
3061 (iw_handler) NULL, /* SIOCGIWSENS */
3062 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
3063 (iw_handler) rt_ioctl_giwrange, /* SIOCGIWRANGE */
3064 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
3065 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
3066 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
3067 (iw_handler) rt28xx_get_wireless_stats /* kernel code */, /* SIOCGIWSTATS */
3068 (iw_handler) NULL, /* SIOCSIWSPY */
3069 (iw_handler) NULL, /* SIOCGIWSPY */
3070 (iw_handler) NULL, /* SIOCSIWTHRSPY */
3071 (iw_handler) NULL, /* SIOCGIWTHRSPY */
3072 (iw_handler) rt_ioctl_siwap, /* SIOCSIWAP */
3073 (iw_handler) rt_ioctl_giwap, /* SIOCGIWAP */
3074 (iw_handler) rt_ioctl_siwmlme, /* SIOCSIWMLME */
3075 (iw_handler) rt_ioctl_iwaplist, /* SIOCGIWAPLIST */
3076 (iw_handler) rt_ioctl_siwscan, /* SIOCSIWSCAN */
3077 (iw_handler) rt_ioctl_giwscan, /* SIOCGIWSCAN */
3078 (iw_handler) rt_ioctl_siwessid, /* SIOCSIWESSID */
3079 (iw_handler) rt_ioctl_giwessid, /* SIOCGIWESSID */
3080 (iw_handler) rt_ioctl_siwnickn, /* SIOCSIWNICKN */
3081 (iw_handler) rt_ioctl_giwnickn, /* SIOCGIWNICKN */
3082 (iw_handler) NULL, /* -- hole -- */
3083 (iw_handler) NULL, /* -- hole -- */
3084 (iw_handler) rt_ioctl_siwrate, /* SIOCSIWRATE */
3085 (iw_handler) rt_ioctl_giwrate, /* SIOCGIWRATE */
3086 (iw_handler) rt_ioctl_siwrts, /* SIOCSIWRTS */
3087 (iw_handler) rt_ioctl_giwrts, /* SIOCGIWRTS */
3088 (iw_handler) rt_ioctl_siwfrag, /* SIOCSIWFRAG */
3089 (iw_handler) rt_ioctl_giwfrag, /* SIOCGIWFRAG */
3090 (iw_handler) NULL, /* SIOCSIWTXPOW */
3091 (iw_handler) NULL, /* SIOCGIWTXPOW */
3092 (iw_handler) NULL, /* SIOCSIWRETRY */
3093 (iw_handler) NULL, /* SIOCGIWRETRY */
3094 (iw_handler) rt_ioctl_siwencode, /* SIOCSIWENCODE */
3095 (iw_handler) rt_ioctl_giwencode, /* SIOCGIWENCODE */
3096 (iw_handler) NULL, /* SIOCSIWPOWER */
3097 (iw_handler) NULL, /* SIOCGIWPOWER */
3098 (iw_handler) NULL, /* -- hole -- */
3099 (iw_handler) NULL, /* -- hole -- */
3100 (iw_handler) rt_ioctl_siwgenie, /* SIOCSIWGENIE */
3101 (iw_handler) rt_ioctl_giwgenie, /* SIOCGIWGENIE */
3102 (iw_handler) rt_ioctl_siwauth, /* SIOCSIWAUTH */
3103 (iw_handler) rt_ioctl_giwauth, /* SIOCGIWAUTH */
3104 (iw_handler) rt_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
3105 (iw_handler) rt_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */
3106 (iw_handler) rt_ioctl_siwpmksa, /* SIOCSIWPMKSA */
3109 static const iw_handler rt_priv_handlers[] = {
3110 (iw_handler) NULL, /* + 0x00 */
3111 (iw_handler) NULL, /* + 0x01 */
3112 (iw_handler) rt_ioctl_setparam, /* + 0x02 */
3114 (iw_handler) rt_private_ioctl_bbp, /* + 0x03 */
3116 (iw_handler) NULL, /* + 0x03 */
3118 (iw_handler) NULL, /* + 0x04 */
3119 (iw_handler) NULL, /* + 0x05 */
3120 (iw_handler) NULL, /* + 0x06 */
3121 (iw_handler) NULL, /* + 0x07 */
3122 (iw_handler) NULL, /* + 0x08 */
3123 (iw_handler) rt_private_get_statistics, /* + 0x09 */
3124 (iw_handler) NULL, /* + 0x0A */
3125 (iw_handler) NULL, /* + 0x0B */
3126 (iw_handler) NULL, /* + 0x0C */
3127 (iw_handler) NULL, /* + 0x0D */
3128 (iw_handler) NULL, /* + 0x0E */
3129 (iw_handler) NULL, /* + 0x0F */
3130 (iw_handler) NULL, /* + 0x10 */
3131 (iw_handler) rt_private_show, /* + 0x11 */
3132 (iw_handler) NULL, /* + 0x12 */
3133 (iw_handler) NULL, /* + 0x13 */
3134 (iw_handler) NULL, /* + 0x15 */
3135 (iw_handler) NULL, /* + 0x17 */
3136 (iw_handler) NULL, /* + 0x18 */
3139 const struct iw_handler_def rt28xx_iw_handler_def =
3141 #define N(a) (sizeof (a) / sizeof (a[0]))
3142 .standard = (iw_handler *) rt_handler,
3143 .num_standard = sizeof(rt_handler) / sizeof(iw_handler),
3144 .private = (iw_handler *) rt_priv_handlers,
3145 .num_private = N(rt_priv_handlers),
3146 .private_args = (struct iw_priv_args *) privtab,
3147 .num_private_args = N(privtab),
3148 #if IW_HANDLER_VERSION >= 7
3149 .get_wireless_stats = rt28xx_get_wireless_stats,
3153 INT RTMPSetInformation(
3154 IN PRTMP_ADAPTER pAdapter,
3155 IN OUT struct ifreq *rq,
3158 struct iwreq *wrq = (struct iwreq *) rq;
3159 NDIS_802_11_SSID Ssid;
3160 NDIS_802_11_MAC_ADDRESS Bssid;
3161 RT_802_11_PHY_MODE PhyMode;
3162 RT_802_11_STA_CONFIG StaConfig;
3163 NDIS_802_11_RATES aryRates;
3164 RT_802_11_PREAMBLE Preamble;
3165 NDIS_802_11_WEP_STATUS WepStatus;
3166 NDIS_802_11_AUTHENTICATION_MODE AuthMode = Ndis802_11AuthModeMax;
3167 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
3168 NDIS_802_11_RTS_THRESHOLD RtsThresh;
3169 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
3170 NDIS_802_11_POWER_MODE PowerMode;
3171 PNDIS_802_11_KEY pKey = NULL;
3172 PNDIS_802_11_WEP pWepKey =NULL;
3173 PNDIS_802_11_REMOVE_KEY pRemoveKey = NULL;
3174 NDIS_802_11_CONFIGURATION Config, *pConfig = NULL;
3175 NDIS_802_11_NETWORK_TYPE NetType;
3178 INT Status = NDIS_STATUS_SUCCESS, MaxPhyMode = PHY_11G;
3181 BOOLEAN StateMachineTouched = FALSE;
3182 OID_SET_HT_PHYMODE HT_PhyMode; //11n ,kathy
3183 PNDIS_802_11_PMKID pPmkId = NULL;
3184 BOOLEAN IEEE8021xState = FALSE;
3185 BOOLEAN IEEE8021x_required_keys = FALSE;
3186 UCHAR wpa_supplicant_enable = 0;
3188 MaxPhyMode = PHY_11N_5G;
3190 DBGPRINT(RT_DEBUG_TRACE, ("-->RTMPSetInformation(), 0x%08x\n", cmd&0x7FFF));
3191 switch(cmd & 0x7FFF) {
3192 case RT_OID_802_11_COUNTRY_REGION:
3193 if (wrq->u.data.length < sizeof(UCHAR))
3195 // Only avaliable when EEPROM not programming
3196 else if (!(pAdapter->CommonCfg.CountryRegion & 0x80) && !(pAdapter->CommonCfg.CountryRegionForABand & 0x80))
3201 Status = copy_from_user(&Country, wrq->u.data.pointer, wrq->u.data.length);
3202 pAdapter->CommonCfg.CountryRegion = (UCHAR)(Country & 0x000000FF);
3203 pAdapter->CommonCfg.CountryRegionForABand = (UCHAR)((Country >> 8) & 0x000000FF);
3204 TmpPhy = pAdapter->CommonCfg.PhyMode;
3205 pAdapter->CommonCfg.PhyMode = 0xff;
3206 // Build all corresponding channel information
3207 RTMPSetPhyMode(pAdapter, TmpPhy);
3208 SetCommonHT(pAdapter);
3209 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_COUNTRY_REGION (A:%d B/G:%d)\n", pAdapter->CommonCfg.CountryRegionForABand,
3210 pAdapter->CommonCfg.CountryRegion));
3213 case OID_802_11_BSSID_LIST_SCAN:
3215 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID_LIST_SCAN, TxCnt = %d \n", pAdapter->RalinkCounters.LastOneSecTotalTxCount));
3217 if (MONITOR_ON(pAdapter))
3219 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
3223 //Benson add 20080527, when radio off, sta don't need to scan
3224 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_RADIO_OFF))
3227 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
3229 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is scanning now !!!\n"));
3230 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
3231 Status = NDIS_STATUS_SUCCESS;
3235 if (pAdapter->RalinkCounters.LastOneSecTotalTxCount > 100)
3237 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
3238 Status = NDIS_STATUS_SUCCESS;
3239 pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
3243 if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
3244 ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
3245 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
3246 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
3247 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)) &&
3248 (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
3250 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
3251 Status = NDIS_STATUS_SUCCESS;
3252 pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
3257 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3259 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3260 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3263 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
3264 // this request, because this request is initiated by NDIS.
3265 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
3266 // Reset allowed scan retries
3267 pAdapter->StaCfg.ScanCnt = 0;
3268 pAdapter->StaCfg.LastScanTime = Now;
3270 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
3271 RTMP_SET_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
3272 MlmeEnqueue(pAdapter,
3273 MLME_CNTL_STATE_MACHINE,
3274 OID_802_11_BSSID_LIST_SCAN,
3278 Status = NDIS_STATUS_SUCCESS;
3279 StateMachineTouched = TRUE;
3281 case OID_802_11_SSID:
3282 if (wrq->u.data.length != sizeof(NDIS_802_11_SSID))
3286 PCHAR pSsidString = NULL;
3287 Status = copy_from_user(&Ssid, wrq->u.data.pointer, wrq->u.data.length);
3289 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SSID (Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
3290 if (Ssid.SsidLength > MAX_LEN_OF_SSID)
3294 if (Ssid.SsidLength == 0)
3296 Set_SSID_Proc(pAdapter, "");
3300 pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
3303 NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
3304 NdisMoveMemory(pSsidString, Ssid.Ssid, Ssid.SsidLength);
3305 Set_SSID_Proc(pAdapter, pSsidString);
3314 case OID_802_11_BSSID:
3315 if (wrq->u.data.length != sizeof(NDIS_802_11_MAC_ADDRESS))
3319 Status = copy_from_user(&Bssid, wrq->u.data.pointer, wrq->u.data.length);
3321 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
3322 // this request, because this request is initiated by NDIS.
3323 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
3325 // Prevent to connect AP again in STAMlmePeriodicExec
3326 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
3328 // Reset allowed scan retries
3329 pAdapter->StaCfg.ScanCnt = 0;
3331 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3333 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3334 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3336 MlmeEnqueue(pAdapter,
3337 MLME_CNTL_STATE_MACHINE,
3339 sizeof(NDIS_802_11_MAC_ADDRESS),
3341 Status = NDIS_STATUS_SUCCESS;
3342 StateMachineTouched = TRUE;
3344 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID %02x:%02x:%02x:%02x:%02x:%02x\n",
3345 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
3348 case RT_OID_802_11_RADIO:
3349 if (wrq->u.data.length != sizeof(BOOLEAN))
3353 Status = copy_from_user(&RadioState, wrq->u.data.pointer, wrq->u.data.length);
3354 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RADIO (=%d)\n", RadioState));
3355 if (pAdapter->StaCfg.bSwRadio != RadioState)
3357 pAdapter->StaCfg.bSwRadio = RadioState;
3358 if (pAdapter->StaCfg.bRadio != (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio))
3360 pAdapter->StaCfg.bRadio = (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio);
3361 if (pAdapter->StaCfg.bRadio == TRUE)
3363 MlmeRadioOn(pAdapter);
3364 // Update extra information
3365 pAdapter->ExtraInfo = EXTRA_INFO_CLEAR;
3369 MlmeRadioOff(pAdapter);
3370 // Update extra information
3371 pAdapter->ExtraInfo = SW_RADIO_OFF;
3377 case RT_OID_802_11_PHY_MODE:
3378 if (wrq->u.data.length != sizeof(RT_802_11_PHY_MODE))
3382 Status = copy_from_user(&PhyMode, wrq->u.data.pointer, wrq->u.data.length);
3383 if (PhyMode <= MaxPhyMode)
3385 RTMPSetPhyMode(pAdapter, PhyMode);
3386 SetCommonHT(pAdapter);
3388 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PHY_MODE (=%d)\n", PhyMode));
3391 case RT_OID_802_11_STA_CONFIG:
3392 if (wrq->u.data.length != sizeof(RT_802_11_STA_CONFIG))
3396 Status = copy_from_user(&StaConfig, wrq->u.data.pointer, wrq->u.data.length);
3397 pAdapter->CommonCfg.bEnableTxBurst = StaConfig.EnableTxBurst;
3398 pAdapter->CommonCfg.UseBGProtection = StaConfig.UseBGProtection;
3399 pAdapter->CommonCfg.bUseShortSlotTime = 1; // 2003-10-30 always SHORT SLOT capable
3400 if ((pAdapter->CommonCfg.PhyMode != StaConfig.AdhocMode) &&
3401 (StaConfig.AdhocMode <= MaxPhyMode))
3403 // allow dynamic change of "USE OFDM rate or not" in ADHOC mode
3404 // if setting changed, need to reset current TX rate as well as BEACON frame format
3406 pAdapter->CommonCfg.PhyMode = StaConfig.AdhocMode;
3408 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
3411 pAdapter->CommonCfg.PhyMode = StaConfig.AdhocMode;
3413 RTMPSetPhyMode(pAdapter, PhyMode);
3414 MlmeUpdateTxRates(pAdapter, FALSE, 0);
3415 MakeIbssBeacon(pAdapter); // re-build BEACON frame
3416 AsicEnableIbssSync(pAdapter); // copy to on-chip memory
3419 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_STA_CONFIG (Burst=%d, Protection=%ld,ShortSlot=%d\n",
3420 pAdapter->CommonCfg.bEnableTxBurst,
3421 pAdapter->CommonCfg.UseBGProtection,
3422 pAdapter->CommonCfg.bUseShortSlotTime));
3425 case OID_802_11_DESIRED_RATES:
3426 if (wrq->u.data.length != sizeof(NDIS_802_11_RATES))
3430 Status = copy_from_user(&aryRates, wrq->u.data.pointer, wrq->u.data.length);
3431 NdisZeroMemory(pAdapter->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES);
3432 NdisMoveMemory(pAdapter->CommonCfg.DesireRate, &aryRates, sizeof(NDIS_802_11_RATES));
3433 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DESIRED_RATES (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
3434 pAdapter->CommonCfg.DesireRate[0],pAdapter->CommonCfg.DesireRate[1],
3435 pAdapter->CommonCfg.DesireRate[2],pAdapter->CommonCfg.DesireRate[3],
3436 pAdapter->CommonCfg.DesireRate[4],pAdapter->CommonCfg.DesireRate[5],
3437 pAdapter->CommonCfg.DesireRate[6],pAdapter->CommonCfg.DesireRate[7] ));
3438 // Changing DesiredRate may affect the MAX TX rate we used to TX frames out
3439 MlmeUpdateTxRates(pAdapter, FALSE, 0);
3442 case RT_OID_802_11_PREAMBLE:
3443 if (wrq->u.data.length != sizeof(RT_802_11_PREAMBLE))
3447 Status = copy_from_user(&Preamble, wrq->u.data.pointer, wrq->u.data.length);
3448 if (Preamble == Rt802_11PreambleShort)
3450 pAdapter->CommonCfg.TxPreamble = Preamble;
3451 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleShort);
3453 else if ((Preamble == Rt802_11PreambleLong) || (Preamble == Rt802_11PreambleAuto))
3455 // if user wants AUTO, initialize to LONG here, then change according to AP's
3456 // capability upon association.
3457 pAdapter->CommonCfg.TxPreamble = Preamble;
3458 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleLong);
3465 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PREAMBLE (=%d)\n", Preamble));
3468 case OID_802_11_WEP_STATUS:
3469 if (wrq->u.data.length != sizeof(NDIS_802_11_WEP_STATUS))
3473 Status = copy_from_user(&WepStatus, wrq->u.data.pointer, wrq->u.data.length);
3474 // Since TKIP, AES, WEP are all supported. It should not have any invalid setting
3475 if (WepStatus <= Ndis802_11Encryption3KeyAbsent)
3477 if (pAdapter->StaCfg.WepStatus != WepStatus)
3479 // Config has changed
3480 pAdapter->bConfigChanged = TRUE;
3482 pAdapter->StaCfg.WepStatus = WepStatus;
3483 pAdapter->StaCfg.OrigWepStatus = WepStatus;
3484 pAdapter->StaCfg.PairCipher = WepStatus;
3485 pAdapter->StaCfg.GroupCipher = WepStatus;
3492 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEP_STATUS (=%d)\n",WepStatus));
3495 case OID_802_11_AUTHENTICATION_MODE:
3496 if (wrq->u.data.length != sizeof(NDIS_802_11_AUTHENTICATION_MODE))
3500 Status = copy_from_user(&AuthMode, wrq->u.data.pointer, wrq->u.data.length);
3501 if (AuthMode > Ndis802_11AuthModeMax)
3508 if (pAdapter->StaCfg.AuthMode != AuthMode)
3510 // Config has changed
3511 pAdapter->bConfigChanged = TRUE;
3513 pAdapter->StaCfg.AuthMode = AuthMode;
3515 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
3516 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_AUTHENTICATION_MODE (=%d) \n",pAdapter->StaCfg.AuthMode));
3519 case OID_802_11_INFRASTRUCTURE_MODE:
3520 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_INFRASTRUCTURE))
3524 Status = copy_from_user(&BssType, wrq->u.data.pointer, wrq->u.data.length);
3526 if (BssType == Ndis802_11IBSS)
3527 Set_NetworkType_Proc(pAdapter, "Adhoc");
3528 else if (BssType == Ndis802_11Infrastructure)
3529 Set_NetworkType_Proc(pAdapter, "Infra");
3530 else if (BssType == Ndis802_11Monitor)
3531 Set_NetworkType_Proc(pAdapter, "Monitor");
3535 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_INFRASTRUCTURE_MODE (unknown)\n"));
3539 case OID_802_11_REMOVE_WEP:
3540 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_WEP\n"));
3541 if (wrq->u.data.length != sizeof(NDIS_802_11_KEY_INDEX))
3547 KeyIdx = *(NDIS_802_11_KEY_INDEX *) wrq->u.data.pointer;
3549 if (KeyIdx & 0x80000000)
3551 // Should never set default bit when remove key
3556 KeyIdx = KeyIdx & 0x0fffffff;
3562 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
3563 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
3564 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
3569 case RT_OID_802_11_RESET_COUNTERS:
3570 NdisZeroMemory(&pAdapter->WlanCounters, sizeof(COUNTER_802_11));
3571 NdisZeroMemory(&pAdapter->Counters8023, sizeof(COUNTER_802_3));
3572 NdisZeroMemory(&pAdapter->RalinkCounters, sizeof(COUNTER_RALINK));
3573 pAdapter->Counters8023.RxNoBuffer = 0;
3574 pAdapter->Counters8023.GoodReceives = 0;
3575 pAdapter->Counters8023.RxNoBuffer = 0;
3577 pAdapter->BulkOutComplete = 0;
3578 pAdapter->BulkOutCompleteOther= 0;
3579 pAdapter->BulkOutCompleteCancel = 0;
3580 pAdapter->BulkOutReq = 0;
3581 pAdapter->BulkInReq= 0;
3582 pAdapter->BulkInComplete = 0;
3583 pAdapter->BulkInCompleteFail = 0;
3585 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RESET_COUNTERS \n"));
3587 case OID_802_11_RTS_THRESHOLD:
3588 if (wrq->u.data.length != sizeof(NDIS_802_11_RTS_THRESHOLD))
3592 Status = copy_from_user(&RtsThresh, wrq->u.data.pointer, wrq->u.data.length);
3593 if (RtsThresh > MAX_RTS_THRESHOLD)
3596 pAdapter->CommonCfg.RtsThreshold = (USHORT)RtsThresh;
3598 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_RTS_THRESHOLD (=%ld)\n",RtsThresh));
3600 case OID_802_11_FRAGMENTATION_THRESHOLD:
3601 if (wrq->u.data.length != sizeof(NDIS_802_11_FRAGMENTATION_THRESHOLD))
3605 Status = copy_from_user(&FragThresh, wrq->u.data.pointer, wrq->u.data.length);
3606 pAdapter->CommonCfg.bUseZeroToDisableFragment = FALSE;
3607 if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
3609 if (FragThresh == 0)
3611 pAdapter->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
3612 pAdapter->CommonCfg.bUseZeroToDisableFragment = TRUE;
3618 pAdapter->CommonCfg.FragmentThreshold = (USHORT)FragThresh;
3620 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_FRAGMENTATION_THRESHOLD (=%ld) \n",FragThresh));
3622 case OID_802_11_POWER_MODE:
3623 if (wrq->u.data.length != sizeof(NDIS_802_11_POWER_MODE))
3627 Status = copy_from_user(&PowerMode, wrq->u.data.pointer, wrq->u.data.length);
3628 if (PowerMode == Ndis802_11PowerModeCAM)
3629 Set_PSMode_Proc(pAdapter, "CAM");
3630 else if (PowerMode == Ndis802_11PowerModeMAX_PSP)
3631 Set_PSMode_Proc(pAdapter, "Max_PSP");
3632 else if (PowerMode == Ndis802_11PowerModeFast_PSP)
3633 Set_PSMode_Proc(pAdapter, "Fast_PSP");
3634 else if (PowerMode == Ndis802_11PowerModeLegacy_PSP)
3635 Set_PSMode_Proc(pAdapter, "Legacy_PSP");
3639 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_POWER_MODE (=%d)\n",PowerMode));
3641 case RT_OID_802_11_TX_POWER_LEVEL_1:
3642 if (wrq->u.data.length < sizeof(ULONG))
3646 Status = copy_from_user(&PowerTemp, wrq->u.data.pointer, wrq->u.data.length);
3647 if (PowerTemp > 100)
3648 PowerTemp = 0xffffffff; // AUTO
3649 pAdapter->CommonCfg.TxPowerDefault = PowerTemp; //keep current setting.
3650 pAdapter->CommonCfg.TxPowerPercentage = pAdapter->CommonCfg.TxPowerDefault;
3651 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
3654 case OID_802_11_NETWORK_TYPE_IN_USE:
3655 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_TYPE))
3659 Status = copy_from_user(&NetType, wrq->u.data.pointer, wrq->u.data.length);
3661 if (NetType == Ndis802_11DS)
3662 RTMPSetPhyMode(pAdapter, PHY_11B);
3663 else if (NetType == Ndis802_11OFDM24)
3664 RTMPSetPhyMode(pAdapter, PHY_11BG_MIXED);
3665 else if (NetType == Ndis802_11OFDM5)
3666 RTMPSetPhyMode(pAdapter, PHY_11A);
3670 if (Status == NDIS_STATUS_SUCCESS)
3671 SetCommonHT(pAdapter);
3673 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_NETWORK_TYPE_IN_USE (=%d)\n",NetType));
3676 // For WPA PSK PMK key
3677 case RT_OID_802_11_ADD_WPA:
3678 pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3685 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
3686 if (pKey->Length != wrq->u.data.length)
3689 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!!\n"));
3693 if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
3694 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
3695 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone) )
3697 Status = -EOPNOTSUPP;
3698 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!! [AuthMode != WPAPSK/WPA2PSK/WPANONE]\n"));
3700 else if ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
3701 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
3702 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) ) // Only for WPA PSK mode
3704 NdisMoveMemory(pAdapter->StaCfg.PMK, &pKey->KeyMaterial, pKey->KeyLength);
3705 // Use RaConfig as PSK agent.
3706 // Start STA supplicant state machine
3707 if (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
3708 pAdapter->StaCfg.WpaState = SS_START;
3710 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3714 pAdapter->StaCfg.WpaState = SS_NOTUSE;
3715 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3720 case OID_802_11_REMOVE_KEY:
3721 pRemoveKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3722 if(pRemoveKey == NULL)
3728 Status = copy_from_user(pRemoveKey, wrq->u.data.pointer, wrq->u.data.length);
3729 if (pRemoveKey->Length != wrq->u.data.length)
3732 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!\n"));
3736 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3738 RTMPWPARemoveKeyProc(pAdapter, pRemoveKey);
3739 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Remove WPA Key!!\n"));
3743 KeyIdx = pRemoveKey->KeyIndex;
3745 if (KeyIdx & 0x80000000)
3747 // Should never set default bit when remove key
3749 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(Should never set default bit when remove key)\n"));
3753 KeyIdx = KeyIdx & 0x0fffffff;
3757 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(KeyId[%d] out of range)\n", KeyIdx));
3761 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
3762 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
3763 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
3764 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY (id=0x%x, Len=%d-byte)\n", pRemoveKey->KeyIndex, pRemoveKey->Length));
3772 case OID_802_11_ADD_KEY:
3773 pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3779 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
3780 if (pKey->Length != wrq->u.data.length)
3783 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY, Failed!!\n"));
3787 RTMPAddKey(pAdapter, pKey);
3788 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3792 case OID_802_11_CONFIGURATION:
3793 if (wrq->u.data.length != sizeof(NDIS_802_11_CONFIGURATION))
3797 Status = copy_from_user(&Config, wrq->u.data.pointer, wrq->u.data.length);
3800 if ((pConfig->BeaconPeriod >= 20) && (pConfig->BeaconPeriod <=400))
3801 pAdapter->CommonCfg.BeaconPeriod = (USHORT) pConfig->BeaconPeriod;
3803 pAdapter->StaActive.AtimWin = (USHORT) pConfig->ATIMWindow;
3804 MAP_KHZ_TO_CHANNEL_ID(pConfig->DSConfig, pAdapter->CommonCfg.Channel);
3806 // Save the channel on MlmeAux for CntlOidRTBssidProc used.
3808 pAdapter->MlmeAux.Channel = pAdapter->CommonCfg.Channel;
3810 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_CONFIGURATION (BeacnPeriod=%ld,AtimW=%ld,Ch=%d)\n",
3811 pConfig->BeaconPeriod, pConfig->ATIMWindow, pAdapter->CommonCfg.Channel));
3812 // Config has changed
3813 pAdapter->bConfigChanged = TRUE;
3816 case RT_OID_802_11_SET_HT_PHYMODE:
3817 if (wrq->u.data.length != sizeof(OID_SET_HT_PHYMODE))
3821 POID_SET_HT_PHYMODE pHTPhyMode = &HT_PhyMode;
3823 Status = copy_from_user(&HT_PhyMode, wrq->u.data.pointer, wrq->u.data.length);
3824 DBGPRINT(RT_DEBUG_TRACE, ("Set::pHTPhyMode (PhyMode = %d,TransmitNo = %d, HtMode = %d, ExtOffset = %d , MCS = %d, BW = %d, STBC = %d, SHORTGI = %d) \n",
3825 pHTPhyMode->PhyMode, pHTPhyMode->TransmitNo,pHTPhyMode->HtMode,pHTPhyMode->ExtOffset,
3826 pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->SHORTGI));
3827 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
3828 RTMPSetHT(pAdapter, pHTPhyMode);
3830 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_HT_PHYMODE(MCS=%d,BW=%d,SGI=%d,STBC=%d)\n",
3831 pAdapter->StaCfg.HTPhyMode.field.MCS, pAdapter->StaCfg.HTPhyMode.field.BW, pAdapter->StaCfg.HTPhyMode.field.ShortGI,
3832 pAdapter->StaCfg.HTPhyMode.field.STBC));
3834 case RT_OID_802_11_SET_APSD_SETTING:
3835 if (wrq->u.data.length != sizeof(ULONG))
3840 Status = copy_from_user(&apsd, wrq->u.data.pointer, wrq->u.data.length);
3842 /*-------------------------------------------------------------------
3843 |B31~B7 | B6~B5 | B4 | B3 | B2 | B1 | B0 |
3844 ---------------------------------------------------------------------
3845 | Rsvd | Max SP Len | AC_VO | AC_VI | AC_BK | AC_BE | APSD Capable |
3846 ---------------------------------------------------------------------*/
3847 pAdapter->CommonCfg.bAPSDCapable = (apsd & 0x00000001) ? TRUE : FALSE;
3848 pAdapter->CommonCfg.bAPSDAC_BE = ((apsd & 0x00000002) >> 1) ? TRUE : FALSE;
3849 pAdapter->CommonCfg.bAPSDAC_BK = ((apsd & 0x00000004) >> 2) ? TRUE : FALSE;
3850 pAdapter->CommonCfg.bAPSDAC_VI = ((apsd & 0x00000008) >> 3) ? TRUE : FALSE;
3851 pAdapter->CommonCfg.bAPSDAC_VO = ((apsd & 0x00000010) >> 4) ? TRUE : FALSE;
3852 pAdapter->CommonCfg.MaxSPLength = (UCHAR)((apsd & 0x00000060) >> 5);
3854 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,
3855 pAdapter->CommonCfg.bAPSDAC_BE, pAdapter->CommonCfg.bAPSDAC_BK, pAdapter->CommonCfg.bAPSDAC_VI, pAdapter->CommonCfg.bAPSDAC_VO, pAdapter->CommonCfg.MaxSPLength));
3859 case RT_OID_802_11_SET_APSD_PSM:
3860 if (wrq->u.data.length != sizeof(ULONG))
3864 // Driver needs to notify AP when PSM changes
3865 Status = copy_from_user(&pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.pointer, wrq->u.data.length);
3866 if (pAdapter->CommonCfg.bAPSDForcePowerSave != pAdapter->StaCfg.Psm)
3868 MlmeSetPsmBit(pAdapter, pAdapter->CommonCfg.bAPSDForcePowerSave);
3869 RTMPSendNullFrame(pAdapter, pAdapter->CommonCfg.TxRate, TRUE);
3871 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_APSD_PSM (bAPSDForcePowerSave:%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
3875 case RT_OID_802_11_SET_WMM:
3876 if (wrq->u.data.length != sizeof(BOOLEAN))
3880 Status = copy_from_user(&pAdapter->CommonCfg.bWmmCapable, wrq->u.data.pointer, wrq->u.data.length);
3881 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_WMM (=%d) \n", pAdapter->CommonCfg.bWmmCapable));
3885 case OID_802_11_DISASSOCIATE:
3887 // Set NdisRadioStateOff to TRUE, instead of called MlmeRadioOff.
3888 // Later on, NDIS_802_11_BSSID_LIST_EX->NumberOfItems should be 0
3889 // when query OID_802_11_BSSID_LIST.
3891 // TRUE: NumberOfItems will set to 0.
3892 // FALSE: NumberOfItems no change.
3894 pAdapter->CommonCfg.NdisRadioStateOff = TRUE;
3895 // Set to immediately send the media disconnect event
3896 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
3897 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DISASSOCIATE \n"));
3899 if (INFRA_ON(pAdapter))
3901 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3903 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3904 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3907 MlmeEnqueue(pAdapter,
3908 MLME_CNTL_STATE_MACHINE,
3909 OID_802_11_DISASSOCIATE,
3913 StateMachineTouched = TRUE;
3916 case RT_OID_802_11_SET_IMME_BA_CAP:
3917 if (wrq->u.data.length != sizeof(OID_BACAP_STRUC))
3921 OID_BACAP_STRUC Orde ;
3922 Status = copy_from_user(&Orde, wrq->u.data.pointer, wrq->u.data.length);
3923 if (Orde.Policy > BA_NOTUSE)
3925 Status = NDIS_STATUS_INVALID_DATA;
3927 else if (Orde.Policy == BA_NOTUSE)
3929 pAdapter->CommonCfg.BACapability.field.Policy = BA_NOTUSE;
3930 pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
3931 pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
3932 pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
3933 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
3934 pAdapter->CommonCfg.DesiredHtPhy.MimoPs= Orde.MMPSmode;
3935 pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
3937 pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
3938 pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
3939 pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
3943 pAdapter->CommonCfg.BACapability.field.AutoBA = Orde.AutoBA;
3944 pAdapter->CommonCfg.BACapability.field.Policy = IMMED_BA; // we only support immediate BA.
3945 pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
3946 pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
3947 pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
3948 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
3949 pAdapter->CommonCfg.DesiredHtPhy.MimoPs = Orde.MMPSmode;
3950 pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
3953 pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
3954 pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
3955 pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
3957 if (pAdapter->CommonCfg.BACapability.field.RxBAWinLimit > MAX_RX_REORDERBUF)
3958 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = MAX_RX_REORDERBUF;
3962 pAdapter->CommonCfg.REGBACapability.word = pAdapter->CommonCfg.BACapability.word;
3963 DBGPRINT(RT_DEBUG_TRACE, ("Set::(Orde.AutoBA = %d) (Policy=%d)(ReBAWinLimit=%d)(TxBAWinLimit=%d)(AutoMode=%d)\n",Orde.AutoBA, pAdapter->CommonCfg.BACapability.field.Policy,
3964 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit,pAdapter->CommonCfg.BACapability.field.TxBAWinLimit, pAdapter->CommonCfg.BACapability.field.AutoBA));
3965 DBGPRINT(RT_DEBUG_TRACE, ("Set::(MimoPs = %d)(AmsduEnable = %d) (AmsduSize=%d)(MpduDensity=%d)\n",pAdapter->CommonCfg.DesiredHtPhy.MimoPs, pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable,
3966 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize, pAdapter->CommonCfg.DesiredHtPhy.MpduDensity));
3970 case RT_OID_802_11_ADD_IMME_BA:
3971 DBGPRINT(RT_DEBUG_TRACE, (" Set :: RT_OID_802_11_ADD_IMME_BA \n"));
3972 if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
3977 OID_ADD_BA_ENTRY BA;
3978 MAC_TABLE_ENTRY *pEntry;
3980 Status = copy_from_user(&BA, wrq->u.data.pointer, wrq->u.data.length);
3983 Status = NDIS_STATUS_INVALID_DATA;
3988 //BATableInsertEntry
3989 //As ad-hoc mode, BA pair is not limited to only BSSID. so add via OID.
3991 // in ad hoc mode, when adding BA pair, we should insert this entry into MACEntry too
3992 pEntry = MacTableLookup(pAdapter, BA.MACAddr);
3995 DBGPRINT(RT_DEBUG_TRACE, ("RT_OID_802_11_ADD_IMME_BA. break on no connection.----:%x:%x\n", BA.MACAddr[4], BA.MACAddr[5]));
3998 if (BA.IsRecipient == FALSE)
4000 if (pEntry->bIAmBadAtheros == TRUE)
4001 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = 0x10;
4003 BAOriSessionSetUp(pAdapter, pEntry, index, 0, 100, TRUE);
4007 //BATableInsertEntry(pAdapter, pEntry->Aid, BA.MACAddr, 0, 0xffff, BA.TID, BA.nMSDU, BA.IsRecipient);
4010 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_IMME_BA. Rec = %d. Mac = %x:%x:%x:%x:%x:%x . \n",
4011 BA.IsRecipient, BA.MACAddr[0], BA.MACAddr[1], BA.MACAddr[2], BA.MACAddr[2]
4012 , BA.MACAddr[4], BA.MACAddr[5]));
4017 case RT_OID_802_11_TEAR_IMME_BA:
4018 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA \n"));
4019 if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
4023 POID_ADD_BA_ENTRY pBA;
4024 MAC_TABLE_ENTRY *pEntry;
4026 pBA = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4030 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA kmalloc() can't allocate enough memory\n"));
4031 Status = NDIS_STATUS_FAILURE;
4035 Status = copy_from_user(pBA, wrq->u.data.pointer, wrq->u.data.length);
4036 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA(TID=%d, bAllTid=%d)\n", pBA->TID, pBA->bAllTid));
4038 if (!pBA->bAllTid && (pBA->TID > NUM_OF_TID))
4040 Status = NDIS_STATUS_INVALID_DATA;
4044 if (pBA->IsRecipient == FALSE)
4046 pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
4047 DBGPRINT(RT_DEBUG_TRACE, (" pBA->IsRecipient == FALSE\n"));
4050 DBGPRINT(RT_DEBUG_TRACE, (" pBA->pEntry\n"));
4051 BAOriSessionTearDown(pAdapter, pEntry->Aid, pBA->TID, FALSE, TRUE);
4054 DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
4058 pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
4061 BARecSessionTearDown( pAdapter, (UCHAR)pEntry->Aid, pBA->TID, TRUE);
4064 DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
4070 // For WPA_SUPPLICANT to set static wep key
4071 case OID_802_11_ADD_WEP:
4072 pWepKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4077 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed!!\n"));
4080 Status = copy_from_user(pWepKey, wrq->u.data.pointer, wrq->u.data.length);
4084 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (length mismatch)!!\n"));
4088 KeyIdx = pWepKey->KeyIndex & 0x0fffffff;
4089 // KeyIdx must be 0 ~ 3
4093 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (KeyIdx must be smaller than 4)!!\n"));
4097 UCHAR CipherAlg = 0;
4100 // set key material and key length
4101 NdisZeroMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, 16);
4102 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
4103 NdisMoveMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
4105 switch(pWepKey->KeyLength)
4108 CipherAlg = CIPHER_WEP64;
4111 CipherAlg = CIPHER_WEP128;
4114 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, only support CIPHER_WEP64(len:5) & CIPHER_WEP128(len:13)!!\n"));
4118 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CipherAlg;
4120 // Default key for tx (shared key)
4121 if (pWepKey->KeyIndex & 0x80000000)
4123 // set key material and key length
4124 NdisZeroMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, 16);
4125 pAdapter->StaCfg.DesireSharedKey[KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
4126 NdisMoveMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
4127 pAdapter->StaCfg.DesireSharedKeyId = KeyIdx;
4128 pAdapter->StaCfg.DesireSharedKey[KeyIdx].CipherAlg = CipherAlg;
4129 pAdapter->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
4133 if ((pAdapter->StaCfg.WpaSupplicantUP != 0) &&
4136 if ((pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE) &&
4138 (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA))
4140 Key = pWepKey->KeyMaterial;
4142 // Set Group key material to Asic
4143 AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
4145 // Update WCID attribute table and IVEIV table for this group key table
4146 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
4148 STA_PORT_SECURED(pAdapter);
4150 // Indicate Connected for GUI
4151 pAdapter->IndicateMediaState = NdisMediaStateConnected;
4153 else if (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)
4156 if (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)
4159 Key = pAdapter->SharedKey[BSS0][KeyIdx].Key;
4161 // Set key material and cipherAlg to Asic
4162 AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
4164 if (pWepKey->KeyIndex & 0x80000000)
4166 PMAC_TABLE_ENTRY pEntry = &pAdapter->MacTab.Content[BSSID_WCID];
4167 // Assign group key info
4168 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
4169 // Assign pairwise key info
4170 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, pEntry);
4173 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"));
4178 case OID_SET_COUNTERMEASURES:
4179 if (wrq->u.data.length != sizeof(int))
4184 Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
4186 pAdapter->StaCfg.bBlockAssoc = TRUE;
4188 // WPA MIC error should block association attempt for 60 seconds
4189 pAdapter->StaCfg.bBlockAssoc = FALSE;
4190 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_SET_COUNTERMEASURES bBlockAssoc=%s\n", pAdapter->StaCfg.bBlockAssoc ? "TRUE":"FALSE"));
4193 case RT_OID_WPA_SUPPLICANT_SUPPORT:
4194 if (wrq->u.data.length != sizeof(UCHAR))
4198 Status = copy_from_user(&wpa_supplicant_enable, wrq->u.data.pointer, wrq->u.data.length);
4199 pAdapter->StaCfg.WpaSupplicantUP = wpa_supplicant_enable;
4200 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
4203 case OID_802_11_DEAUTHENTICATION:
4204 if (wrq->u.data.length != sizeof(MLME_DEAUTH_REQ_STRUCT))
4208 MLME_DEAUTH_REQ_STRUCT *pInfo;
4209 MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
4211 pInfo = (MLME_DEAUTH_REQ_STRUCT *) MsgElem->Msg;
4212 Status = copy_from_user(pInfo, wrq->u.data.pointer, wrq->u.data.length);
4213 MlmeDeauthReqAction(pAdapter, MsgElem);
4216 if (INFRA_ON(pAdapter))
4218 LinkDown(pAdapter, FALSE);
4219 pAdapter->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
4221 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DEAUTHENTICATION (Reason=%d)\n", pInfo->Reason));
4224 case OID_802_11_DROP_UNENCRYPTED:
4225 if (wrq->u.data.length != sizeof(int))
4230 Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
4232 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
4234 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
4235 NdisAcquireSpinLock(&pAdapter->MacTabLock);
4236 pAdapter->MacTab.Content[BSSID_WCID].PortSecured = pAdapter->StaCfg.PortSecured;
4237 NdisReleaseSpinLock(&pAdapter->MacTabLock);
4238 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DROP_UNENCRYPTED (=%d)\n", enabled));
4241 case OID_802_11_SET_IEEE8021X:
4242 if (wrq->u.data.length != sizeof(BOOLEAN))
4246 Status = copy_from_user(&IEEE8021xState, wrq->u.data.pointer, wrq->u.data.length);
4247 pAdapter->StaCfg.IEEE8021X = IEEE8021xState;
4248 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X (=%d)\n", IEEE8021xState));
4251 case OID_802_11_SET_IEEE8021X_REQUIRE_KEY:
4252 if (wrq->u.data.length != sizeof(BOOLEAN))
4256 Status = copy_from_user(&IEEE8021x_required_keys, wrq->u.data.pointer, wrq->u.data.length);
4257 pAdapter->StaCfg.IEEE8021x_required_keys = IEEE8021x_required_keys;
4258 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X_REQUIRE_KEY (%d)\n", IEEE8021x_required_keys));
4261 case OID_802_11_PMKID:
4262 pPmkId = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4264 if(pPmkId == NULL) {
4268 Status = copy_from_user(pPmkId, wrq->u.data.pointer, wrq->u.data.length);
4270 // check the PMKID information
4271 if (pPmkId->BSSIDInfoCount == 0)
4272 NdisZeroMemory(pAdapter->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
4275 PBSSID_INFO pBssIdInfo;
4279 for (BssIdx = 0; BssIdx < pPmkId->BSSIDInfoCount; BssIdx++)
4281 // point to the indexed BSSID_INFO structure
4282 pBssIdInfo = (PBSSID_INFO) ((PUCHAR) pPmkId + 2 * sizeof(UINT) + BssIdx * sizeof(BSSID_INFO));
4283 // Find the entry in the saved data base.
4284 for (CachedIdx = 0; CachedIdx < pAdapter->StaCfg.SavedPMKNum; CachedIdx++)
4286 // compare the BSSID
4287 if (NdisEqualMemory(pBssIdInfo->BSSID, pAdapter->StaCfg.SavedPMK[CachedIdx].BSSID, sizeof(NDIS_802_11_MAC_ADDRESS)))
4291 // Found, replace it
4292 if (CachedIdx < PMKID_NO)
4294 DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
4295 NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
4296 pAdapter->StaCfg.SavedPMKNum++;
4298 // Not found, replace the last one
4301 // Randomly replace one
4302 CachedIdx = (pBssIdInfo->BSSID[5] % PMKID_NO);
4303 DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
4304 NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
4312 DBGPRINT(RT_DEBUG_TRACE, ("Set::unknown IOCTL's subcmd = 0x%08x\n", cmd));
4313 Status = -EOPNOTSUPP;
4321 INT RTMPQueryInformation(
4322 IN PRTMP_ADAPTER pAdapter,
4323 IN OUT struct ifreq *rq,
4326 struct iwreq *wrq = (struct iwreq *) rq;
4327 NDIS_802_11_BSSID_LIST_EX *pBssidList = NULL;
4328 PNDIS_WLAN_BSSID_EX pBss;
4329 NDIS_802_11_SSID Ssid;
4330 NDIS_802_11_CONFIGURATION *pConfiguration = NULL;
4331 RT_802_11_LINK_STATUS *pLinkStatus = NULL;
4332 RT_802_11_STA_CONFIG *pStaConfig = NULL;
4333 NDIS_802_11_STATISTICS *pStatistics = NULL;
4334 NDIS_802_11_RTS_THRESHOLD RtsThresh;
4335 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
4336 NDIS_802_11_POWER_MODE PowerMode;
4337 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
4338 RT_802_11_PREAMBLE PreamType;
4339 NDIS_802_11_AUTHENTICATION_MODE AuthMode;
4340 NDIS_802_11_WEP_STATUS WepStatus;
4341 NDIS_MEDIA_STATE MediaState;
4342 ULONG BssBufSize, ulInfo=0, NetworkTypeList[4], apsd = 0;
4344 PUCHAR pBuf = NULL, pPtr;
4345 INT Status = NDIS_STATUS_SUCCESS;
4346 UINT we_version_compiled;
4347 UCHAR i, Padding = 0;
4349 UCHAR driverVersion[8];
4350 OID_SET_HT_PHYMODE *pHTPhyMode = NULL;
4354 case RT_OID_DEVICE_NAME:
4355 wrq->u.data.length = sizeof(STA_NIC_DEVICE_NAME);
4356 Status = copy_to_user(wrq->u.data.pointer, STA_NIC_DEVICE_NAME, wrq->u.data.length);
4358 case RT_OID_VERSION_INFO:
4359 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_VERSION_INFO \n"));
4360 wrq->u.data.length = 8*sizeof(UCHAR);
4361 sprintf(&driverVersion[0], "%s", STA_DRIVER_VERSION);
4362 driverVersion[7] = '\0';
4363 if (copy_to_user(wrq->u.data.pointer, &driverVersion, wrq->u.data.length))
4368 case OID_802_11_BSSID_LIST:
4369 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
4372 * Still scanning, indicate the caller should try again.
4374 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (Still scanning)\n"));
4377 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (%d BSS returned)\n",pAdapter->ScanTab.BssNr));
4378 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
4379 // Claculate total buffer size required
4380 BssBufSize = sizeof(ULONG);
4382 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
4384 // Align pointer to 4 bytes boundary.
4385 //Padding = 4 - (pAdapter->ScanTab.BssEntry[i].VarIELen & 0x0003);
4388 BssBufSize += (sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
4391 // For safety issue, we add 256 bytes just in case
4393 // Allocate the same size as passed from higher layer
4394 pBuf = kmalloc(BssBufSize, MEM_ALLOC_FLAG);
4400 // Init 802_11_BSSID_LIST_EX structure
4401 NdisZeroMemory(pBuf, BssBufSize);
4402 pBssidList = (PNDIS_802_11_BSSID_LIST_EX) pBuf;
4403 pBssidList->NumberOfItems = pAdapter->ScanTab.BssNr;
4405 // Calculate total buffer length
4406 BssLen = 4; // Consist of NumberOfItems
4407 // Point to start of NDIS_WLAN_BSSID_EX
4408 // pPtr = pBuf + sizeof(ULONG);
4409 pPtr = (PUCHAR) &pBssidList->Bssid[0];
4410 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
4412 pBss = (PNDIS_WLAN_BSSID_EX) pPtr;
4413 NdisMoveMemory(&pBss->MacAddress, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
4414 if ((pAdapter->ScanTab.BssEntry[i].Hidden == 1) && (pAdapter->StaCfg.bShowHiddenSSID == FALSE))
4417 // We must return this SSID during 4way handshaking, otherwise Aegis will failed to parse WPA infomation
4418 // and then failed to send EAPOl farame.
4420 if ((pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) && (pAdapter->StaCfg.PortSecured != WPA_802_1X_PORT_SECURED))
4422 pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
4423 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
4426 pBss->Ssid.SsidLength = 0;
4430 pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
4431 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
4433 pBss->Privacy = pAdapter->ScanTab.BssEntry[i].Privacy;
4434 pBss->Rssi = pAdapter->ScanTab.BssEntry[i].Rssi - pAdapter->BbpRssiToDbmDelta;
4435 pBss->NetworkTypeInUse = NetworkTypeInUseSanity(&pAdapter->ScanTab.BssEntry[i]);
4436 pBss->Configuration.Length = sizeof(NDIS_802_11_CONFIGURATION);
4437 pBss->Configuration.BeaconPeriod = pAdapter->ScanTab.BssEntry[i].BeaconPeriod;
4438 pBss->Configuration.ATIMWindow = pAdapter->ScanTab.BssEntry[i].AtimWin;
4440 MAP_CHANNEL_ID_TO_KHZ(pAdapter->ScanTab.BssEntry[i].Channel, pBss->Configuration.DSConfig);
4442 if (pAdapter->ScanTab.BssEntry[i].BssType == BSS_INFRA)
4443 pBss->InfrastructureMode = Ndis802_11Infrastructure;
4445 pBss->InfrastructureMode = Ndis802_11IBSS;
4447 NdisMoveMemory(pBss->SupportedRates, pAdapter->ScanTab.BssEntry[i].SupRate, pAdapter->ScanTab.BssEntry[i].SupRateLen);
4448 NdisMoveMemory(pBss->SupportedRates + pAdapter->ScanTab.BssEntry[i].SupRateLen,
4449 pAdapter->ScanTab.BssEntry[i].ExtRate,
4450 pAdapter->ScanTab.BssEntry[i].ExtRateLen);
4452 if (pAdapter->ScanTab.BssEntry[i].VarIELen == 0)
4454 pBss->IELength = sizeof(NDIS_802_11_FIXED_IEs);
4455 NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
4456 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
4460 pBss->IELength = (ULONG)(sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen);
4461 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
4462 NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
4463 NdisMoveMemory(pBss->IEs + sizeof(NDIS_802_11_FIXED_IEs), pAdapter->ScanTab.BssEntry[i].VarIEs, pAdapter->ScanTab.BssEntry[i].VarIELen);
4464 pPtr += pAdapter->ScanTab.BssEntry[i].VarIELen;
4466 pBss->Length = (ULONG)(sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
4468 BssLen += pBss->Length;
4471 if (BssLen > wrq->u.data.length)
4477 wrq->u.data.length = BssLen;
4478 Status = copy_to_user(wrq->u.data.pointer, pBssidList, BssLen);
4481 case OID_802_3_CURRENT_ADDRESS:
4482 wrq->u.data.length = MAC_ADDR_LEN;
4483 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
4485 case OID_GEN_MEDIA_CONNECT_STATUS:
4486 if (pAdapter->IndicateMediaState == NdisMediaStateConnected)
4487 MediaState = NdisMediaStateConnected;
4489 MediaState = NdisMediaStateDisconnected;
4491 wrq->u.data.length = sizeof(NDIS_MEDIA_STATE);
4492 Status = copy_to_user(wrq->u.data.pointer, &MediaState, wrq->u.data.length);
4494 case OID_802_11_BSSID:
4495 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
4497 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Bssid, sizeof(NDIS_802_11_MAC_ADDRESS));
4502 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID(=EMPTY)\n"));
4506 case OID_802_11_SSID:
4507 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
4508 NdisZeroMemory(Ssid.Ssid, MAX_LEN_OF_SSID);
4509 Ssid.SsidLength = pAdapter->CommonCfg.SsidLen;
4510 memcpy(Ssid.Ssid, pAdapter->CommonCfg.Ssid, Ssid.SsidLength);
4511 wrq->u.data.length = sizeof(NDIS_802_11_SSID);
4512 Status = copy_to_user(wrq->u.data.pointer, &Ssid, wrq->u.data.length);
4513 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_SSID (Len=%d, ssid=%s)\n", Ssid.SsidLength,Ssid.Ssid));
4515 case RT_OID_802_11_QUERY_LINK_STATUS:
4516 pLinkStatus = (RT_802_11_LINK_STATUS *) kmalloc(sizeof(RT_802_11_LINK_STATUS), MEM_ALLOC_FLAG);
4519 pLinkStatus->CurrTxRate = RateIdTo500Kbps[pAdapter->CommonCfg.TxRate]; // unit : 500 kbps
4520 pLinkStatus->ChannelQuality = pAdapter->Mlme.ChannelQuality;
4521 pLinkStatus->RxByteCount = pAdapter->RalinkCounters.ReceivedByteCount;
4522 pLinkStatus->TxByteCount = pAdapter->RalinkCounters.TransmittedByteCount;
4523 pLinkStatus->CentralChannel = pAdapter->CommonCfg.CentralChannel;
4524 wrq->u.data.length = sizeof(RT_802_11_LINK_STATUS);
4525 Status = copy_to_user(wrq->u.data.pointer, pLinkStatus, wrq->u.data.length);
4527 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS\n"));
4531 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS(kmalloc failed)\n"));
4535 case OID_802_11_CONFIGURATION:
4536 pConfiguration = (NDIS_802_11_CONFIGURATION *) kmalloc(sizeof(NDIS_802_11_CONFIGURATION), MEM_ALLOC_FLAG);
4539 pConfiguration->Length = sizeof(NDIS_802_11_CONFIGURATION);
4540 pConfiguration->BeaconPeriod = pAdapter->CommonCfg.BeaconPeriod;
4541 pConfiguration->ATIMWindow = pAdapter->StaActive.AtimWin;
4542 MAP_CHANNEL_ID_TO_KHZ(pAdapter->CommonCfg.Channel, pConfiguration->DSConfig);
4543 wrq->u.data.length = sizeof(NDIS_802_11_CONFIGURATION);
4544 Status = copy_to_user(wrq->u.data.pointer, pConfiguration, wrq->u.data.length);
4545 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(BeaconPeriod=%ld,AtimW=%ld,Channel=%d) \n",
4546 pConfiguration->BeaconPeriod, pConfiguration->ATIMWindow, pAdapter->CommonCfg.Channel));
4547 kfree(pConfiguration);
4551 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(kmalloc failed)\n"));
4555 case RT_OID_802_11_SNR_0:
4556 if ((pAdapter->StaCfg.LastSNR0 > 0))
4558 ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR0) * 3) / 16 ;
4559 wrq->u.data.length = sizeof(ulInfo);
4560 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4561 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_SNR_0(0x=%lx)\n", ulInfo));
4566 case RT_OID_802_11_SNR_1:
4567 if ((pAdapter->Antenna.field.RxPath > 1) &&
4568 (pAdapter->StaCfg.LastSNR1 > 0))
4570 ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR1) * 3) / 16 ;
4571 wrq->u.data.length = sizeof(ulInfo);
4572 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4573 DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(0x=%lx)\n",ulInfo));
4577 DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(pAdapter->StaCfg.LastSNR1=%d)\n",pAdapter->StaCfg.LastSNR1));
4579 case OID_802_11_RSSI_TRIGGER:
4580 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0 - pAdapter->BbpRssiToDbmDelta;
4581 wrq->u.data.length = sizeof(ulInfo);
4582 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4583 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RSSI_TRIGGER(=%ld)\n", ulInfo));
4585 case OID_802_11_RSSI:
4586 case RT_OID_802_11_RSSI:
4587 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0;
4588 wrq->u.data.length = sizeof(ulInfo);
4589 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4591 case RT_OID_802_11_RSSI_1:
4592 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi1;
4593 wrq->u.data.length = sizeof(ulInfo);
4594 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4596 case RT_OID_802_11_RSSI_2:
4597 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi2;
4598 wrq->u.data.length = sizeof(ulInfo);
4599 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4601 case OID_802_11_STATISTICS:
4602 pStatistics = (NDIS_802_11_STATISTICS *) kmalloc(sizeof(NDIS_802_11_STATISTICS), MEM_ALLOC_FLAG);
4605 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS \n"));
4606 // add the most up-to-date h/w raw counters into software counters
4607 NICUpdateRawCounters(pAdapter);
4609 // Sanity check for calculation of sucessful count
4610 if (pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart < pAdapter->WlanCounters.RetryCount.QuadPart)
4611 pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
4613 pStatistics->TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart;
4614 pStatistics->MulticastTransmittedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastTransmittedFrameCount.QuadPart;
4615 pStatistics->FailedCount.QuadPart = pAdapter->WlanCounters.FailedCount.QuadPart;
4616 pStatistics->RetryCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
4617 pStatistics->MultipleRetryCount.QuadPart = pAdapter->WlanCounters.MultipleRetryCount.QuadPart;
4618 pStatistics->RTSSuccessCount.QuadPart = pAdapter->WlanCounters.RTSSuccessCount.QuadPart;
4619 pStatistics->RTSFailureCount.QuadPart = pAdapter->WlanCounters.RTSFailureCount.QuadPart;
4620 pStatistics->ACKFailureCount.QuadPart = pAdapter->WlanCounters.ACKFailureCount.QuadPart;
4621 pStatistics->FrameDuplicateCount.QuadPart = pAdapter->WlanCounters.FrameDuplicateCount.QuadPart;
4622 pStatistics->ReceivedFragmentCount.QuadPart = pAdapter->WlanCounters.ReceivedFragmentCount.QuadPart;
4623 pStatistics->MulticastReceivedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastReceivedFrameCount.QuadPart;
4625 pStatistics->FCSErrorCount = pAdapter->RalinkCounters.RealFcsErrCount;
4627 pStatistics->FCSErrorCount.QuadPart = pAdapter->WlanCounters.FCSErrorCount.QuadPart;
4628 pStatistics->FrameDuplicateCount.u.LowPart = pAdapter->WlanCounters.FrameDuplicateCount.u.LowPart / 100;
4630 wrq->u.data.length = sizeof(NDIS_802_11_STATISTICS);
4631 Status = copy_to_user(wrq->u.data.pointer, pStatistics, wrq->u.data.length);
4636 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS(kmalloc failed)\n"));
4640 case OID_GEN_RCV_OK:
4641 ulInfo = pAdapter->Counters8023.GoodReceives;
4642 wrq->u.data.length = sizeof(ulInfo);
4643 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4645 case OID_GEN_RCV_NO_BUFFER:
4646 ulInfo = pAdapter->Counters8023.RxNoBuffer;
4647 wrq->u.data.length = sizeof(ulInfo);
4648 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4650 case RT_OID_802_11_PHY_MODE:
4651 ulInfo = (ULONG)pAdapter->CommonCfg.PhyMode;
4652 wrq->u.data.length = sizeof(ulInfo);
4653 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4654 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PHY_MODE (=%ld)\n", ulInfo));
4656 case RT_OID_802_11_STA_CONFIG:
4657 pStaConfig = (RT_802_11_STA_CONFIG *) kmalloc(sizeof(RT_802_11_STA_CONFIG), MEM_ALLOC_FLAG);
4660 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG\n"));
4661 pStaConfig->EnableTxBurst = pAdapter->CommonCfg.bEnableTxBurst;
4662 pStaConfig->EnableTurboRate = 0;
4663 pStaConfig->UseBGProtection = pAdapter->CommonCfg.UseBGProtection;
4664 pStaConfig->UseShortSlotTime = pAdapter->CommonCfg.bUseShortSlotTime;
4665 //pStaConfig->AdhocMode = pAdapter->StaCfg.AdhocMode;
4666 pStaConfig->HwRadioStatus = (pAdapter->StaCfg.bHwRadio == TRUE) ? 1 : 0;
4667 pStaConfig->Rsv1 = 0;
4668 pStaConfig->SystemErrorBitmap = pAdapter->SystemErrorBitmap;
4669 wrq->u.data.length = sizeof(RT_802_11_STA_CONFIG);
4670 Status = copy_to_user(wrq->u.data.pointer, pStaConfig, wrq->u.data.length);
4675 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
4679 case OID_802_11_RTS_THRESHOLD:
4680 RtsThresh = pAdapter->CommonCfg.RtsThreshold;
4681 wrq->u.data.length = sizeof(RtsThresh);
4682 Status = copy_to_user(wrq->u.data.pointer, &RtsThresh, wrq->u.data.length);
4683 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RTS_THRESHOLD(=%ld)\n", RtsThresh));
4685 case OID_802_11_FRAGMENTATION_THRESHOLD:
4686 FragThresh = pAdapter->CommonCfg.FragmentThreshold;
4687 if (pAdapter->CommonCfg.bUseZeroToDisableFragment == TRUE)
4689 wrq->u.data.length = sizeof(FragThresh);
4690 Status = copy_to_user(wrq->u.data.pointer, &FragThresh, wrq->u.data.length);
4691 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_FRAGMENTATION_THRESHOLD(=%ld)\n", FragThresh));
4693 case OID_802_11_POWER_MODE:
4694 PowerMode = pAdapter->StaCfg.WindowsPowerMode;
4695 wrq->u.data.length = sizeof(PowerMode);
4696 Status = copy_to_user(wrq->u.data.pointer, &PowerMode, wrq->u.data.length);
4697 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_POWER_MODE(=%d)\n", PowerMode));
4699 case RT_OID_802_11_RADIO:
4700 RadioState = (BOOLEAN) pAdapter->StaCfg.bSwRadio;
4701 wrq->u.data.length = sizeof(RadioState);
4702 Status = copy_to_user(wrq->u.data.pointer, &RadioState, wrq->u.data.length);
4703 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_RADIO (=%d)\n", RadioState));
4705 case OID_802_11_INFRASTRUCTURE_MODE:
4706 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
4707 BssType = Ndis802_11IBSS;
4708 else if (pAdapter->StaCfg.BssType == BSS_INFRA)
4709 BssType = Ndis802_11Infrastructure;
4710 else if (pAdapter->StaCfg.BssType == BSS_MONITOR)
4711 BssType = Ndis802_11Monitor;
4713 BssType = Ndis802_11AutoUnknown;
4715 wrq->u.data.length = sizeof(BssType);
4716 Status = copy_to_user(wrq->u.data.pointer, &BssType, wrq->u.data.length);
4717 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_INFRASTRUCTURE_MODE(=%d)\n", BssType));
4719 case RT_OID_802_11_PREAMBLE:
4720 PreamType = pAdapter->CommonCfg.TxPreamble;
4721 wrq->u.data.length = sizeof(PreamType);
4722 Status = copy_to_user(wrq->u.data.pointer, &PreamType, wrq->u.data.length);
4723 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PREAMBLE(=%d)\n", PreamType));
4725 case OID_802_11_AUTHENTICATION_MODE:
4726 AuthMode = pAdapter->StaCfg.AuthMode;
4727 wrq->u.data.length = sizeof(AuthMode);
4728 Status = copy_to_user(wrq->u.data.pointer, &AuthMode, wrq->u.data.length);
4729 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_AUTHENTICATION_MODE(=%d)\n", AuthMode));
4731 case OID_802_11_WEP_STATUS:
4732 WepStatus = pAdapter->StaCfg.WepStatus;
4733 wrq->u.data.length = sizeof(WepStatus);
4734 Status = copy_to_user(wrq->u.data.pointer, &WepStatus, wrq->u.data.length);
4735 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_WEP_STATUS(=%d)\n", WepStatus));
4737 case OID_802_11_TX_POWER_LEVEL:
4738 wrq->u.data.length = sizeof(ULONG);
4739 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPower, wrq->u.data.length);
4740 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_TX_POWER_LEVEL %x\n",pAdapter->CommonCfg.TxPower));
4742 case RT_OID_802_11_TX_POWER_LEVEL_1:
4743 wrq->u.data.length = sizeof(ULONG);
4744 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPowerPercentage, wrq->u.data.length);
4745 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
4747 case OID_802_11_NETWORK_TYPES_SUPPORTED:
4748 if ((pAdapter->RfIcType == RFIC_2850) || (pAdapter->RfIcType == RFIC_2750))
4750 NetworkTypeList[0] = 3; // NumberOfItems = 3
4751 NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
4752 NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
4753 NetworkTypeList[3] = Ndis802_11OFDM5; // NetworkType[3] = 11a
4754 wrq->u.data.length = 16;
4755 Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
4759 NetworkTypeList[0] = 2; // NumberOfItems = 2
4760 NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
4761 NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
4762 wrq->u.data.length = 12;
4763 Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
4765 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_NETWORK_TYPES_SUPPORTED\n"));
4767 case OID_802_11_NETWORK_TYPE_IN_USE:
4768 wrq->u.data.length = sizeof(ULONG);
4769 if (pAdapter->CommonCfg.PhyMode == PHY_11A)
4770 ulInfo = Ndis802_11OFDM5;
4771 else if ((pAdapter->CommonCfg.PhyMode == PHY_11BG_MIXED) || (pAdapter->CommonCfg.PhyMode == PHY_11G))
4772 ulInfo = Ndis802_11OFDM24;
4774 ulInfo = Ndis802_11DS;
4775 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4777 case RT_OID_802_11_QUERY_LAST_RX_RATE:
4778 ulInfo = (ULONG)pAdapter->LastRxRate;
4779 wrq->u.data.length = sizeof(ulInfo);
4780 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4781 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_RX_RATE (=%ld)\n", ulInfo));
4783 case RT_OID_802_11_QUERY_LAST_TX_RATE:
4784 //ulInfo = (ULONG)pAdapter->LastTxRate;
4785 ulInfo = (ULONG)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word;
4786 wrq->u.data.length = sizeof(ulInfo);
4787 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4788 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_TX_RATE (=%lx)\n", ulInfo));
4790 case RT_OID_802_11_QUERY_EEPROM_VERSION:
4791 wrq->u.data.length = sizeof(ULONG);
4792 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->EepromVersion, wrq->u.data.length);
4794 case RT_OID_802_11_QUERY_FIRMWARE_VERSION:
4795 wrq->u.data.length = sizeof(ULONG);
4796 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->FirmwareVersion, wrq->u.data.length);
4798 case RT_OID_802_11_QUERY_NOISE_LEVEL:
4799 wrq->u.data.length = sizeof(UCHAR);
4800 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->BbpWriteLatch[66], wrq->u.data.length);
4801 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_NOISE_LEVEL (=%d)\n", pAdapter->BbpWriteLatch[66]));
4803 case RT_OID_802_11_EXTRA_INFO:
4804 wrq->u.data.length = sizeof(ULONG);
4805 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->ExtraInfo, wrq->u.data.length);
4806 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_EXTRA_INFO (=%ld)\n", pAdapter->ExtraInfo));
4808 case RT_OID_WE_VERSION_COMPILED:
4809 wrq->u.data.length = sizeof(UINT);
4810 we_version_compiled = WIRELESS_EXT;
4811 Status = copy_to_user(wrq->u.data.pointer, &we_version_compiled, wrq->u.data.length);
4813 case RT_OID_802_11_QUERY_APSD_SETTING:
4814 apsd = (pAdapter->CommonCfg.bAPSDCapable | (pAdapter->CommonCfg.bAPSDAC_BE << 1) | (pAdapter->CommonCfg.bAPSDAC_BK << 2)
4815 | (pAdapter->CommonCfg.bAPSDAC_VI << 3) | (pAdapter->CommonCfg.bAPSDAC_VO << 4) | (pAdapter->CommonCfg.MaxSPLength << 5));
4817 wrq->u.data.length = sizeof(ULONG);
4818 Status = copy_to_user(wrq->u.data.pointer, &apsd, wrq->u.data.length);
4819 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",
4820 apsd,pAdapter->CommonCfg.bAPSDCapable,pAdapter->CommonCfg.bAPSDAC_BE,pAdapter->CommonCfg.bAPSDAC_BK,pAdapter->CommonCfg.bAPSDAC_VI,pAdapter->CommonCfg.bAPSDAC_VO,pAdapter->CommonCfg.MaxSPLength));
4822 case RT_OID_802_11_QUERY_APSD_PSM:
4823 wrq->u.data.length = sizeof(ULONG);
4824 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.length);
4825 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_APSD_PSM (=%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
4827 case RT_OID_802_11_QUERY_WMM:
4828 wrq->u.data.length = sizeof(BOOLEAN);
4829 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bWmmCapable, wrq->u.data.length);
4830 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_WMM (=%d)\n", pAdapter->CommonCfg.bWmmCapable));
4832 case RT_OID_NEW_DRIVER:
4835 wrq->u.data.length = sizeof(UCHAR);
4836 Status = copy_to_user(wrq->u.data.pointer, &enabled, wrq->u.data.length);
4837 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_NEW_DRIVER (=%d)\n", enabled));
4840 case RT_OID_WPA_SUPPLICANT_SUPPORT:
4841 wrq->u.data.length = sizeof(UCHAR);
4842 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->StaCfg.WpaSupplicantUP, wrq->u.data.length);
4843 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
4845 case RT_OID_DRIVER_DEVICE_NAME:
4846 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_DRIVER_DEVICE_NAME \n"));
4847 wrq->u.data.length = 16;
4848 if (copy_to_user(wrq->u.data.pointer, pAdapter->StaCfg.dev_name, wrq->u.data.length))
4853 case RT_OID_802_11_QUERY_HT_PHYMODE:
4854 pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
4857 pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
4858 pHTPhyMode->HtMode = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE;
4859 pHTPhyMode->BW = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.BW;
4860 pHTPhyMode->MCS= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MCS;
4861 pHTPhyMode->SHORTGI= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.ShortGI;
4862 pHTPhyMode->STBC= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.STBC;
4864 pHTPhyMode->ExtOffset = ((pAdapter->CommonCfg.CentralChannel < pAdapter->CommonCfg.Channel) ? (EXTCHA_BELOW) : (EXTCHA_ABOVE));
4865 wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
4866 if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
4870 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
4871 pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
4872 DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
4876 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
4880 case RT_OID_802_11_COUNTRY_REGION:
4881 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_COUNTRY_REGION \n"));
4882 wrq->u.data.length = sizeof(ulInfo);
4883 ulInfo = pAdapter->CommonCfg.CountryRegionForABand;
4884 ulInfo = (ulInfo << 8)|(pAdapter->CommonCfg.CountryRegion);
4885 if (copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length))
4890 case RT_OID_802_11_QUERY_DAT_HT_PHYMODE:
4891 pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
4894 pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
4895 pHTPhyMode->HtMode = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.HTMODE;
4896 pHTPhyMode->BW = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.BW;
4897 pHTPhyMode->MCS= (UCHAR)pAdapter->StaCfg.DesiredTransmitSetting.field.MCS;
4898 pHTPhyMode->SHORTGI= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.ShortGI;
4899 pHTPhyMode->STBC= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.STBC;
4901 wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
4902 if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
4906 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
4907 pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
4908 DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
4912 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
4916 case RT_OID_QUERY_MULTIPLE_CARD_SUPPORT:
4917 wrq->u.data.length = sizeof(UCHAR);
4919 if (copy_to_user(wrq->u.data.pointer, &i, wrq->u.data.length))
4923 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_QUERY_MULTIPLE_CARD_SUPPORT(=%d) \n", i));
4926 case OID_802_11_BUILD_CHANNEL_EX:
4929 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BUILD_CHANNEL_EX \n"));
4930 wrq->u.data.length = sizeof(UCHAR);
4931 DBGPRINT(RT_DEBUG_TRACE, ("Doesn't support EXT_BUILD_CHANNEL_LIST.\n"));
4933 Status = copy_to_user(wrq->u.data.pointer, &value, 1);
4934 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
4938 case OID_802_11_GET_CH_LIST:
4940 PRT_CHANNEL_LIST_INFO pChListBuf;
4942 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CH_LIST \n"));
4943 if (pAdapter->ChannelListNum == 0)
4945 wrq->u.data.length = 0;
4949 pChListBuf = (RT_CHANNEL_LIST_INFO *) kmalloc(sizeof(RT_CHANNEL_LIST_INFO), MEM_ALLOC_FLAG);
4950 if (pChListBuf == NULL)
4952 wrq->u.data.length = 0;
4956 pChListBuf->ChannelListNum = pAdapter->ChannelListNum;
4957 for (i = 0; i < pChListBuf->ChannelListNum; i++)
4958 pChListBuf->ChannelList[i] = pAdapter->ChannelList[i].Channel;
4960 wrq->u.data.length = sizeof(RT_CHANNEL_LIST_INFO);
4961 Status = copy_to_user(wrq->u.data.pointer, pChListBuf, sizeof(RT_CHANNEL_LIST_INFO));
4962 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
4969 case OID_802_11_GET_COUNTRY_CODE:
4970 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_COUNTRY_CODE \n"));
4971 wrq->u.data.length = 2;
4972 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.CountryCode, 2);
4973 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
4976 case OID_802_11_GET_CHANNEL_GEOGRAPHY:
4977 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CHANNEL_GEOGRAPHY \n"));
4978 wrq->u.data.length = 1;
4979 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Geography, 1);
4980 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
4984 DBGPRINT(RT_DEBUG_TRACE, ("Query::unknown IOCTL's subcmd = 0x%08x\n", cmd));
4985 Status = -EOPNOTSUPP;
4991 INT rt28xx_sta_ioctl(
4992 IN struct net_device *net_dev,
4993 IN OUT struct ifreq *rq,
4997 VIRTUAL_ADAPTER *pVirtualAd = NULL;
4998 RTMP_ADAPTER *pAd = NULL;
4999 struct iwreq *wrq = (struct iwreq *) rq;
5000 BOOLEAN StateMachineTouched = FALSE;
5001 INT Status = NDIS_STATUS_SUCCESS;
5004 if (net_dev->priv_flags == INT_MAIN)
5006 pAd = net_dev->ml_priv;
5010 pVirtualAd = net_dev->ml_priv;
5011 pAd = pVirtualAd->RtmpDev->ml_priv;
5013 pObj = (POS_COOKIE) pAd->OS_Cookie;
5017 /* if 1st open fail, pAd will be free;
5018 So the net_dev->ml_priv will be NULL in 2rd open */
5022 //check if the interface is down
5023 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
5026 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
5031 { // determine this ioctl command is comming from which interface.
5032 pObj->ioctl_if_type = INT_MAIN;
5033 pObj->ioctl_if = MAIN_MBSSID;
5039 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIFHWADDR\n"));
5040 memcpy(wrq->u.name, pAd->CurrentAddress, ETH_ALEN);
5044 char *name=&wrq->u.name[0];
5045 rt_ioctl_giwname(net_dev, NULL, name, NULL);
5048 case SIOCGIWESSID: //Get ESSID
5050 struct iw_point *essid=&wrq->u.essid;
5051 rt_ioctl_giwessid(net_dev, NULL, essid, essid->pointer);
5054 case SIOCSIWESSID: //Set ESSID
5056 struct iw_point *essid=&wrq->u.essid;
5057 rt_ioctl_siwessid(net_dev, NULL, essid, essid->pointer);
5060 case SIOCSIWNWID: // set network id (the cell)
5061 case SIOCGIWNWID: // get network id
5062 Status = -EOPNOTSUPP;
5064 case SIOCSIWFREQ: //set channel/frequency (Hz)
5066 struct iw_freq *freq=&wrq->u.freq;
5067 rt_ioctl_siwfreq(net_dev, NULL, freq, NULL);
5070 case SIOCGIWFREQ: // get channel/frequency (Hz)
5072 struct iw_freq *freq=&wrq->u.freq;
5073 rt_ioctl_giwfreq(net_dev, NULL, freq, NULL);
5076 case SIOCSIWNICKN: //set node name/nickname
5078 struct iw_point *data=&wrq->u.data;
5079 rt_ioctl_siwnickn(net_dev, NULL, data, NULL);
5082 case SIOCGIWNICKN: //get node name/nickname
5084 struct iw_point *data=&wrq->u.data;
5085 rt_ioctl_giwnickn(net_dev, NULL, data, NULL);
5088 case SIOCGIWRATE: //get default bit rate (bps)
5089 rt_ioctl_giwrate(net_dev, NULL, &wrq->u, NULL);
5091 case SIOCSIWRATE: //set default bit rate (bps)
5092 rt_ioctl_siwrate(net_dev, NULL, &wrq->u, NULL);
5094 case SIOCGIWRTS: // get RTS/CTS threshold (bytes)
5096 struct iw_param *rts=&wrq->u.rts;
5097 rt_ioctl_giwrts(net_dev, NULL, rts, NULL);
5100 case SIOCSIWRTS: //set RTS/CTS threshold (bytes)
5102 struct iw_param *rts=&wrq->u.rts;
5103 rt_ioctl_siwrts(net_dev, NULL, rts, NULL);
5106 case SIOCGIWFRAG: //get fragmentation thr (bytes)
5108 struct iw_param *frag=&wrq->u.frag;
5109 rt_ioctl_giwfrag(net_dev, NULL, frag, NULL);
5112 case SIOCSIWFRAG: //set fragmentation thr (bytes)
5114 struct iw_param *frag=&wrq->u.frag;
5115 rt_ioctl_siwfrag(net_dev, NULL, frag, NULL);
5118 case SIOCGIWENCODE: //get encoding token & mode
5120 struct iw_point *erq=&wrq->u.encoding;
5122 rt_ioctl_giwencode(net_dev, NULL, erq, erq->pointer);
5125 case SIOCSIWENCODE: //set encoding token & mode
5127 struct iw_point *erq=&wrq->u.encoding;
5129 rt_ioctl_siwencode(net_dev, NULL, erq, erq->pointer);
5132 case SIOCGIWAP: //get access point MAC addresses
5134 struct sockaddr *ap_addr=&wrq->u.ap_addr;
5135 rt_ioctl_giwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
5138 case SIOCSIWAP: //set access point MAC addresses
5140 struct sockaddr *ap_addr=&wrq->u.ap_addr;
5141 rt_ioctl_siwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
5144 case SIOCGIWMODE: //get operation mode
5146 __u32 *mode=&wrq->u.mode;
5147 rt_ioctl_giwmode(net_dev, NULL, mode, NULL);
5150 case SIOCSIWMODE: //set operation mode
5152 __u32 *mode=&wrq->u.mode;
5153 rt_ioctl_siwmode(net_dev, NULL, mode, NULL);
5156 case SIOCGIWSENS: //get sensitivity (dBm)
5157 case SIOCSIWSENS: //set sensitivity (dBm)
5158 case SIOCGIWPOWER: //get Power Management settings
5159 case SIOCSIWPOWER: //set Power Management settings
5160 case SIOCGIWTXPOW: //get transmit power (dBm)
5161 case SIOCSIWTXPOW: //set transmit power (dBm)
5162 case SIOCGIWRANGE: //Get range of parameters
5163 case SIOCGIWRETRY: //get retry limits and lifetime
5164 case SIOCSIWRETRY: //set retry limits and lifetime
5165 Status = -EOPNOTSUPP;
5169 case RT_PRIV_IOCTL_EXT:
5171 subcmd = wrq->u.data.flags;
5172 if( subcmd & OID_GET_SET_TOGGLE)
5173 Status = RTMPSetInformation(pAd, rq, subcmd);
5175 Status = RTMPQueryInformation(pAd, rq, subcmd);
5178 if (wrq->u.data.pointer)
5180 if ( access_ok(VERIFY_WRITE, wrq->u.data.pointer, sizeof(privtab)) != TRUE)
5182 wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
5183 if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
5187 case RTPRIV_IOCTL_SET:
5188 if(access_ok(VERIFY_READ, wrq->u.data.pointer, wrq->u.data.length) != TRUE)
5190 rt_ioctl_setparam(net_dev, NULL, NULL, wrq->u.data.pointer);
5192 case RTPRIV_IOCTL_GSITESURVEY:
5193 RTMPIoctlGetSiteSurvey(pAd, wrq);
5196 case RTPRIV_IOCTL_MAC:
5197 RTMPIoctlMAC(pAd, wrq);
5199 case RTPRIV_IOCTL_E2P:
5200 RTMPIoctlE2PROM(pAd, wrq);
5203 case RTPRIV_IOCTL_RF:
5204 RTMPIoctlRF(pAd, wrq);
5211 DBGPRINT(RT_DEBUG_ERROR, ("IOCTL::unknown IOCTL's cmd = 0x%08x\n", cmd));
5212 Status = -EOPNOTSUPP;
5216 if(StateMachineTouched) // Upper layer sent a MLME-related operations
5217 RT28XX_MLME_HANDLER(pAd);
5223 ==========================================================================
5227 TRUE if all parameters are OK, FALSE otherwise
5228 ==========================================================================
5231 IN PRTMP_ADAPTER pAdapter,
5234 NDIS_802_11_SSID Ssid, *pSsid=NULL;
5235 BOOLEAN StateMachineTouched = FALSE;
5238 if( strlen(arg) <= MAX_LEN_OF_SSID)
5240 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
5241 if (strlen(arg) != 0)
5243 NdisMoveMemory(Ssid.Ssid, arg, strlen(arg));
5244 Ssid.SsidLength = strlen(arg);
5248 Ssid.SsidLength = 0;
5249 memcpy(Ssid.Ssid, "", 0);
5250 pAdapter->StaCfg.BssType = BSS_INFRA;
5251 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
5252 pAdapter->StaCfg.WepStatus = Ndis802_11EncryptionDisabled;
5256 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
5258 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
5259 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
5262 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
5263 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
5264 pAdapter->bConfigChanged = TRUE;
5266 MlmeEnqueue(pAdapter,
5267 MLME_CNTL_STATE_MACHINE,
5269 sizeof(NDIS_802_11_SSID),
5272 StateMachineTouched = TRUE;
5273 DBGPRINT(RT_DEBUG_TRACE, ("Set_SSID_Proc::(Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
5278 if (StateMachineTouched) // Upper layer sent a MLME-related operations
5279 RT28XX_MLME_HANDLER(pAdapter);
5286 ==========================================================================
5288 Set WmmCapable Enable or Disable
5290 TRUE if all parameters are OK, FALSE otherwise
5291 ==========================================================================
5293 INT Set_WmmCapable_Proc(
5294 IN PRTMP_ADAPTER pAd,
5297 BOOLEAN bWmmCapable;
5299 bWmmCapable = simple_strtol(arg, 0, 10);
5301 if ((bWmmCapable == 1)
5303 && (pAd->NumberOfPipes >= 5)
5306 pAd->CommonCfg.bWmmCapable = TRUE;
5307 else if (bWmmCapable == 0)
5308 pAd->CommonCfg.bWmmCapable = FALSE;
5310 return FALSE; //Invalid argument
5312 DBGPRINT(RT_DEBUG_TRACE, ("Set_WmmCapable_Proc::(bWmmCapable=%d)\n",
5313 pAd->CommonCfg.bWmmCapable));
5317 #endif // WMM_SUPPORT //
5320 ==========================================================================
5322 Set Network Type(Infrastructure/Adhoc mode)
5324 TRUE if all parameters are OK, FALSE otherwise
5325 ==========================================================================
5327 INT Set_NetworkType_Proc(
5328 IN PRTMP_ADAPTER pAdapter,
5333 if (strcmp(arg, "Adhoc") == 0)
5335 if (pAdapter->StaCfg.BssType != BSS_ADHOC)
5337 // Config has changed
5338 pAdapter->bConfigChanged = TRUE;
5339 if (MONITOR_ON(pAdapter))
5341 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
5342 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5344 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5345 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5346 pAdapter->StaCfg.bAutoReconnect = TRUE;
5347 LinkDown(pAdapter, FALSE);
5349 if (INFRA_ON(pAdapter))
5351 //BOOLEAN Cancelled;
5352 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
5353 // Since calling this indicate user don't want to connect to that SSID anymore.
5354 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
5355 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
5357 LinkDown(pAdapter, FALSE);
5359 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n"));
5362 pAdapter->StaCfg.BssType = BSS_ADHOC;
5363 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
5364 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(AD-HOC)\n"));
5366 else if (strcmp(arg, "Infra") == 0)
5368 if (pAdapter->StaCfg.BssType != BSS_INFRA)
5370 // Config has changed
5371 pAdapter->bConfigChanged = TRUE;
5372 if (MONITOR_ON(pAdapter))
5374 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
5375 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5377 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5378 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5379 pAdapter->StaCfg.bAutoReconnect = TRUE;
5380 LinkDown(pAdapter, FALSE);
5382 if (ADHOC_ON(pAdapter))
5384 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
5385 // Since calling this indicate user don't want to connect to that SSID anymore.
5386 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
5387 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
5389 LinkDown(pAdapter, FALSE);
5392 pAdapter->StaCfg.BssType = BSS_INFRA;
5393 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
5394 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(INFRA)\n"));
5396 pAdapter->StaCfg.BssType = BSS_INFRA;
5398 else if (strcmp(arg, "Monitor") == 0)
5401 BCN_TIME_CFG_STRUC csr;
5402 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_INFRA_ON);
5403 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_ADHOC_ON);
5404 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5405 // disable all periodic state machine
5406 pAdapter->StaCfg.bAutoReconnect = FALSE;
5407 // reset all mlme state machine
5408 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
5409 DBGPRINT(RT_DEBUG_TRACE, ("fOP_STATUS_MEDIA_STATE_CONNECTED \n"));
5410 if (pAdapter->CommonCfg.CentralChannel == 0)
5412 if (pAdapter->CommonCfg.PhyMode == PHY_11AN_MIXED)
5413 pAdapter->CommonCfg.CentralChannel = 36;
5415 pAdapter->CommonCfg.CentralChannel = 6;
5418 N_ChannelCheck(pAdapter);
5420 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
5421 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
5422 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_ABOVE)
5424 // 40MHz ,control channel at lower
5425 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5426 bbpValue &= (~0x18);
5428 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5429 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
5430 // RX : control channel at lower
5431 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
5432 bbpValue &= (~0x20);
5433 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
5435 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
5436 Value &= 0xfffffffe;
5437 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
5438 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel + 2;
5439 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
5440 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
5441 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
5442 pAdapter->CommonCfg.Channel,
5443 pAdapter->CommonCfg.CentralChannel));
5445 else if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
5446 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
5447 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_BELOW)
5449 // 40MHz ,control channel at upper
5450 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5451 bbpValue &= (~0x18);
5453 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5454 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
5455 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
5457 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
5459 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
5461 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
5462 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel - 2;
5463 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
5464 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
5465 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
5466 pAdapter->CommonCfg.Channel,
5467 pAdapter->CommonCfg.CentralChannel));
5472 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5473 bbpValue &= (~0x18);
5474 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5475 pAdapter->CommonCfg.BBPCurrentBW = BW_20;
5476 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.Channel, FALSE);
5477 AsicLockChannel(pAdapter, pAdapter->CommonCfg.Channel);
5478 DBGPRINT(RT_DEBUG_TRACE, ("BW_20, Channel(%d)\n", pAdapter->CommonCfg.Channel));
5480 // Enable Rx with promiscuous reception
5481 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, 0x3);
5482 // ASIC supporsts sniffer function with replacing RSSI with timestamp.
5483 //RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5485 //RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5487 RTMP_IO_READ32(pAdapter, BCN_TIME_CFG, &csr.word);
5488 csr.field.bBeaconGen = 0;
5489 csr.field.bTBTTEnable = 0;
5490 csr.field.TsfSyncMode = 0;
5491 RTMP_IO_WRITE32(pAdapter, BCN_TIME_CFG, csr.word);
5493 pAdapter->StaCfg.BssType = BSS_MONITOR;
5494 pAdapter->net_dev->type = ARPHRD_IEEE80211_PRISM; //ARPHRD_IEEE80211; // IEEE80211
5495 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(MONITOR)\n"));
5498 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
5499 pAdapter->StaCfg.WpaState = SS_NOTUSE;
5501 DBGPRINT(RT_DEBUG_TRACE, ("Set_NetworkType_Proc::(NetworkType=%d)\n", pAdapter->StaCfg.BssType));
5507 ==========================================================================
5509 Set Authentication mode
5511 TRUE if all parameters are OK, FALSE otherwise
5512 ==========================================================================
5514 INT Set_AuthMode_Proc(
5515 IN PRTMP_ADAPTER pAdapter,
5518 if ((strcmp(arg, "WEPAUTO") == 0) || (strcmp(arg, "wepauto") == 0))
5519 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeAutoSwitch;
5520 else if ((strcmp(arg, "OPEN") == 0) || (strcmp(arg, "open") == 0))
5521 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
5522 else if ((strcmp(arg, "SHARED") == 0) || (strcmp(arg, "shared") == 0))
5523 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
5524 else if ((strcmp(arg, "WPAPSK") == 0) || (strcmp(arg, "wpapsk") == 0))
5525 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
5526 else if ((strcmp(arg, "WPANONE") == 0) || (strcmp(arg, "wpanone") == 0))
5527 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
5528 else if ((strcmp(arg, "WPA2PSK") == 0) || (strcmp(arg, "wpa2psk") == 0))
5529 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
5530 else if ((strcmp(arg, "WPA") == 0) || (strcmp(arg, "wpa") == 0))
5531 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
5532 else if ((strcmp(arg, "WPA2") == 0) || (strcmp(arg, "wpa2") == 0))
5533 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
5537 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
5539 DBGPRINT(RT_DEBUG_TRACE, ("Set_AuthMode_Proc::(AuthMode=%d)\n", pAdapter->StaCfg.AuthMode));
5545 ==========================================================================
5549 TRUE if all parameters are OK, FALSE otherwise
5550 ==========================================================================
5552 INT Set_EncrypType_Proc(
5553 IN PRTMP_ADAPTER pAdapter,
5556 if ((strcmp(arg, "NONE") == 0) || (strcmp(arg, "none") == 0))
5558 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5559 return TRUE; // do nothing
5561 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
5562 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
5563 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
5565 else if ((strcmp(arg, "WEP") == 0) || (strcmp(arg, "wep") == 0))
5567 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5568 return TRUE; // do nothing
5570 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
5571 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
5572 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
5574 else if ((strcmp(arg, "TKIP") == 0) || (strcmp(arg, "tkip") == 0))
5576 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
5577 return TRUE; // do nothing
5579 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
5580 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
5581 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
5583 else if ((strcmp(arg, "AES") == 0) || (strcmp(arg, "aes") == 0))
5585 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
5586 return TRUE; // do nothing
5588 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
5589 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
5590 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
5595 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
5597 DBGPRINT(RT_DEBUG_TRACE, ("Set_EncrypType_Proc::(EncrypType=%d)\n", pAdapter->StaCfg.WepStatus));
5603 ==========================================================================
5607 TRUE if all parameters are OK, FALSE otherwise
5608 ==========================================================================
5610 INT Set_DefaultKeyID_Proc(
5611 IN PRTMP_ADAPTER pAdapter,
5616 KeyIdx = simple_strtol(arg, 0, 10);
5617 if((KeyIdx >= 1 ) && (KeyIdx <= 4))
5618 pAdapter->StaCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1 );
5620 return FALSE; //Invalid argument
5622 DBGPRINT(RT_DEBUG_TRACE, ("Set_DefaultKeyID_Proc::(DefaultKeyID=%d)\n", pAdapter->StaCfg.DefaultKeyId));
5628 ==========================================================================
5632 TRUE if all parameters are OK, FALSE otherwise
5633 ==========================================================================
5636 IN PRTMP_ADAPTER pAdapter,
5641 UCHAR CipherAlg=CIPHER_WEP64;
5643 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5644 return TRUE; // do nothing
5646 KeyLen = strlen(arg);
5650 case 5: //wep 40 Ascii type
5651 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
5652 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
5653 CipherAlg = CIPHER_WEP64;
5654 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
5656 case 10: //wep 40 Hex type
5657 for(i=0; i < KeyLen; i++)
5659 if( !isxdigit(*(arg+i)) )
5660 return FALSE; //Not Hex value;
5662 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
5663 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
5664 CipherAlg = CIPHER_WEP64;
5665 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
5667 case 13: //wep 104 Ascii type
5668 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
5669 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
5670 CipherAlg = CIPHER_WEP128;
5671 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
5673 case 26: //wep 104 Hex type
5674 for(i=0; i < KeyLen; i++)
5676 if( !isxdigit(*(arg+i)) )
5677 return FALSE; //Not Hex value;
5679 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
5680 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
5681 CipherAlg = CIPHER_WEP128;
5682 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
5684 default: //Invalid argument
5685 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::Invalid argument (=%s)\n", arg));
5689 pAdapter->SharedKey[BSS0][0].CipherAlg = CipherAlg;
5691 // Set keys (into ASIC)
5692 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5694 else // Old WEP stuff
5696 AsicAddSharedKeyEntry(pAdapter,
5699 pAdapter->SharedKey[BSS0][0].CipherAlg,
5700 pAdapter->SharedKey[BSS0][0].Key,
5708 ==========================================================================
5713 TRUE if all parameters are OK, FALSE otherwise
5714 ==========================================================================
5717 IN PRTMP_ADAPTER pAdapter,
5722 UCHAR CipherAlg=CIPHER_WEP64;
5724 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5725 return TRUE; // do nothing
5727 KeyLen = strlen(arg);
5731 case 5: //wep 40 Ascii type
5732 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
5733 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
5734 CipherAlg = CIPHER_WEP64;
5735 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
5737 case 10: //wep 40 Hex type
5738 for(i=0; i < KeyLen; i++)
5740 if( !isxdigit(*(arg+i)) )
5741 return FALSE; //Not Hex value;
5743 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
5744 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
5745 CipherAlg = CIPHER_WEP64;
5746 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
5748 case 13: //wep 104 Ascii type
5749 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
5750 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
5751 CipherAlg = CIPHER_WEP128;
5752 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
5754 case 26: //wep 104 Hex type
5755 for(i=0; i < KeyLen; i++)
5757 if( !isxdigit(*(arg+i)) )
5758 return FALSE; //Not Hex value;
5760 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
5761 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
5762 CipherAlg = CIPHER_WEP128;
5763 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
5765 default: //Invalid argument
5766 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::Invalid argument (=%s)\n", arg));
5769 pAdapter->SharedKey[BSS0][1].CipherAlg = CipherAlg;
5771 // Set keys (into ASIC)
5772 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5774 else // Old WEP stuff
5776 AsicAddSharedKeyEntry(pAdapter,
5779 pAdapter->SharedKey[BSS0][1].CipherAlg,
5780 pAdapter->SharedKey[BSS0][1].Key,
5788 ==========================================================================
5792 TRUE if all parameters are OK, FALSE otherwise
5793 ==========================================================================
5796 IN PRTMP_ADAPTER pAdapter,
5801 UCHAR CipherAlg=CIPHER_WEP64;
5803 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5804 return TRUE; // do nothing
5806 KeyLen = strlen(arg);
5810 case 5: //wep 40 Ascii type
5811 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
5812 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
5813 CipherAlg = CIPHER_WEP64;
5814 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
5816 case 10: //wep 40 Hex type
5817 for(i=0; i < KeyLen; i++)
5819 if( !isxdigit(*(arg+i)) )
5820 return FALSE; //Not Hex value;
5822 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
5823 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
5824 CipherAlg = CIPHER_WEP64;
5825 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
5827 case 13: //wep 104 Ascii type
5828 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
5829 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
5830 CipherAlg = CIPHER_WEP128;
5831 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
5833 case 26: //wep 104 Hex type
5834 for(i=0; i < KeyLen; i++)
5836 if( !isxdigit(*(arg+i)) )
5837 return FALSE; //Not Hex value;
5839 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
5840 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
5841 CipherAlg = CIPHER_WEP128;
5842 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
5844 default: //Invalid argument
5845 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::Invalid argument (=%s)\n", arg));
5848 pAdapter->SharedKey[BSS0][2].CipherAlg = CipherAlg;
5850 // Set keys (into ASIC)
5851 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5853 else // Old WEP stuff
5855 AsicAddSharedKeyEntry(pAdapter,
5858 pAdapter->SharedKey[BSS0][2].CipherAlg,
5859 pAdapter->SharedKey[BSS0][2].Key,
5867 ==========================================================================
5871 TRUE if all parameters are OK, FALSE otherwise
5872 ==========================================================================
5875 IN PRTMP_ADAPTER pAdapter,
5880 UCHAR CipherAlg=CIPHER_WEP64;
5882 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5883 return TRUE; // do nothing
5885 KeyLen = strlen(arg);
5889 case 5: //wep 40 Ascii type
5890 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
5891 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
5892 CipherAlg = CIPHER_WEP64;
5893 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
5895 case 10: //wep 40 Hex type
5896 for(i=0; i < KeyLen; i++)
5898 if( !isxdigit(*(arg+i)) )
5899 return FALSE; //Not Hex value;
5901 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
5902 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
5903 CipherAlg = CIPHER_WEP64;
5904 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
5906 case 13: //wep 104 Ascii type
5907 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
5908 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
5909 CipherAlg = CIPHER_WEP128;
5910 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
5912 case 26: //wep 104 Hex type
5913 for(i=0; i < KeyLen; i++)
5915 if( !isxdigit(*(arg+i)) )
5916 return FALSE; //Not Hex value;
5918 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
5919 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
5920 CipherAlg = CIPHER_WEP128;
5921 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
5923 default: //Invalid argument
5924 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::Invalid argument (=%s)\n", arg));
5927 pAdapter->SharedKey[BSS0][3].CipherAlg = CipherAlg;
5929 // Set keys (into ASIC)
5930 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5932 else // Old WEP stuff
5934 AsicAddSharedKeyEntry(pAdapter,
5937 pAdapter->SharedKey[BSS0][3].CipherAlg,
5938 pAdapter->SharedKey[BSS0][3].Key,
5947 ==========================================================================
5951 TRUE if all parameters are OK, FALSE otherwise
5952 ==========================================================================
5954 INT Set_WPAPSK_Proc(
5955 IN PRTMP_ADAPTER pAdapter,
5958 UCHAR keyMaterial[40];
5960 if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
5961 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
5962 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
5964 return TRUE; // do nothing
5966 DBGPRINT(RT_DEBUG_TRACE, ("Set_WPAPSK_Proc::(WPAPSK=%s)\n", arg));
5968 NdisZeroMemory(keyMaterial, 40);
5970 if ((strlen(arg) < 8) || (strlen(arg) > 64))
5972 DBGPRINT(RT_DEBUG_TRACE, ("Set failed!!(WPAPSK=%s), WPAPSK key-string required 8 ~ 64 characters \n", arg));
5976 if (strlen(arg) == 64)
5978 AtoH(arg, keyMaterial, 32);
5979 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
5984 PasswordHash((char *)arg, pAdapter->MlmeAux.Ssid, pAdapter->MlmeAux.SsidLen, keyMaterial);
5985 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
5990 if(pAdapter->StaCfg.BssType == BSS_ADHOC &&
5991 pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
5993 pAdapter->StaCfg.WpaState = SS_NOTUSE;
5997 // Start STA supplicant state machine
5998 pAdapter->StaCfg.WpaState = SS_START;
6005 ==========================================================================
6007 Set Power Saving mode
6009 TRUE if all parameters are OK, FALSE otherwise
6010 ==========================================================================
6012 INT Set_PSMode_Proc(
6013 IN PRTMP_ADAPTER pAdapter,
6016 if (pAdapter->StaCfg.BssType == BSS_INFRA)
6018 if ((strcmp(arg, "Max_PSP") == 0) ||
6019 (strcmp(arg, "max_psp") == 0) ||
6020 (strcmp(arg, "MAX_PSP") == 0))
6022 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6023 // to exclude certain situations.
6024 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6025 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeMAX_PSP;
6026 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeMAX_PSP;
6027 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6028 pAdapter->StaCfg.DefaultListenCount = 5;
6031 else if ((strcmp(arg, "Fast_PSP") == 0) ||
6032 (strcmp(arg, "fast_psp") == 0) ||
6033 (strcmp(arg, "FAST_PSP") == 0))
6035 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6036 // to exclude certain situations.
6037 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6038 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6039 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeFast_PSP;
6040 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeFast_PSP;
6041 pAdapter->StaCfg.DefaultListenCount = 3;
6043 else if ((strcmp(arg, "Legacy_PSP") == 0) ||
6044 (strcmp(arg, "legacy_psp") == 0) ||
6045 (strcmp(arg, "LEGACY_PSP") == 0))
6047 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6048 // to exclude certain situations.
6049 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6050 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6051 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeLegacy_PSP;
6052 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeLegacy_PSP;
6053 pAdapter->StaCfg.DefaultListenCount = 3;
6057 //Default Ndis802_11PowerModeCAM
6058 // clear PSM bit immediately
6059 MlmeSetPsmBit(pAdapter, PWR_ACTIVE);
6060 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6061 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6062 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
6063 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
6066 DBGPRINT(RT_DEBUG_TRACE, ("Set_PSMode_Proc::(PSMode=%ld)\n", pAdapter->StaCfg.WindowsPowerMode));
6076 ==========================================================================
6078 Set WpaSupport flag.
6080 0: Driver ignore wpa_supplicant.
6081 1: wpa_supplicant initiates scanning and AP selection.
6082 2: driver takes care of scanning, AP selection, and IEEE 802.11 association parameters.
6084 TRUE if all parameters are OK, FALSE otherwise
6085 ==========================================================================
6087 INT Set_Wpa_Support(
6088 IN PRTMP_ADAPTER pAd,
6092 if ( simple_strtol(arg, 0, 10) == 0)
6093 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
6094 else if ( simple_strtol(arg, 0, 10) == 1)
6095 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE;
6096 else if ( simple_strtol(arg, 0, 10) == 2)
6097 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE_WITH_WEB_UI;
6099 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
6101 DBGPRINT(RT_DEBUG_TRACE, ("Set_Wpa_Support::(WpaSupplicantUP=%d)\n", pAd->StaCfg.WpaSupplicantUP));
6108 ==========================================================================
6112 pAdapter Pointer to our adapter
6113 wrq Pointer to the ioctl argument
6120 1.) iwpriv ra0 mac 0 ==> read MAC where Addr=0x0
6121 2.) iwpriv ra0 mac 0=12 ==> write MAC where Addr=0x0, value=12
6122 ==========================================================================
6125 IN PRTMP_ADAPTER pAdapter,
6126 IN struct iwreq *wrq)
6134 UCHAR temp[16], temp2[16];
6135 UINT32 macValue = 0;
6138 BOOLEAN bIsPrintAllMAC = FALSE;
6141 memset(msg, 0x00, 1024);
6142 if (wrq->u.data.length > 1) //No parameters.
6144 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6147 //Parsing Read or Write
6152 if ((value = rtstrchr(this_char, '=')) != NULL)
6155 if (!value || !*value)
6158 if(strlen(this_char) > 4)
6161 j = strlen(this_char);
6164 if(this_char[j] > 'f' || this_char[j] < '0')
6169 k = j = strlen(this_char);
6172 this_char[4-k+j] = this_char[j];
6176 this_char[3-k++]='0';
6179 if(strlen(this_char) == 4)
6181 AtoH(this_char, temp, 2);
6182 macAddr = *temp*256 + temp[1];
6183 if (macAddr < 0xFFFF)
6185 RTMP_IO_READ32(pAdapter, macAddr, &macValue);
6186 DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%lx, MacValue=%x\n", macAddr, macValue));
6187 sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr , macValue);
6191 {//Invalid parametes, so default printk all bbp
6194 {//Invalid parametes, so default printk all mac
6195 bIsPrintAllMAC = TRUE;
6203 memcpy(&temp2, value, strlen(value));
6204 temp2[strlen(value)] = '\0';
6207 if((strlen(this_char) > 4) || strlen(temp2) > 8)
6210 j = strlen(this_char);
6213 if(this_char[j] > 'f' || this_char[j] < '0')
6220 if(temp2[j] > 'f' || temp2[j] < '0')
6225 k = j = strlen(this_char);
6228 this_char[4-k+j] = this_char[j];
6232 this_char[3-k++]='0';
6236 k = j = strlen(temp2);
6239 temp2[8-k+j] = temp2[j];
6247 AtoH(this_char, temp, 2);
6248 macAddr = *temp*256 + temp[1];
6250 AtoH(temp2, temp, 4);
6251 macValue = *temp*256*256*256 + temp[1]*256*256 + temp[2]*256 + temp[3];
6254 if (macAddr == (HW_DEBUG_SETTING_BASE + 4))
6256 // 0x2bf4: byte0 non-zero: enable R17 tuning, 0: disable R17 tuning
6257 if (macValue & 0x000000ff)
6259 pAdapter->BbpTuning.bEnable = TRUE;
6260 DBGPRINT(RT_DEBUG_TRACE,("turn on R17 tuning\n"));
6265 pAdapter->BbpTuning.bEnable = FALSE;
6266 R66 = 0x26 + GET_LNA_GAIN(pAdapter);
6267 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R66, (0x26 + GET_LNA_GAIN(pAdapter)));
6268 DBGPRINT(RT_DEBUG_TRACE,("turn off R17 tuning, restore to 0x%02x\n", R66));
6273 DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%02lx, MacValue=0x%x\n", macAddr, macValue));
6275 RTMP_IO_WRITE32(pAdapter, macAddr, macValue);
6276 sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr, macValue);
6282 bIsPrintAllMAC = TRUE;
6288 struct file *file_w;
6289 PCHAR fileName = "MacDump.txt";
6290 mm_segment_t orig_fs;
6296 file_w = filp_open(fileName, O_WRONLY|O_CREAT, 0);
6299 DBGPRINT(RT_DEBUG_TRACE, ("-->2) %s: Error %ld opening %s\n", __func__, -PTR_ERR(file_w), fileName));
6303 if (file_w->f_op && file_w->f_op->write)
6308 while (macAddr <= 0x1800)
6310 RTMP_IO_READ32(pAdapter, macAddr, &macValue);
6311 sprintf(msg, "%08lx = %08X\n", macAddr, macValue);
6313 // write data to file
6314 file_w->f_op->write(file_w, msg, strlen(msg), &file_w->f_pos);
6319 sprintf(msg, "\nDump all MAC values to %s\n", fileName);
6321 filp_close(file_w, NULL);
6326 if(strlen(msg) == 1)
6327 sprintf(msg+strlen(msg), "===>Error command format!");
6329 // Copy the information into the user buffer
6330 wrq->u.data.length = strlen(msg);
6331 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6333 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlMAC\n\n"));
6337 ==========================================================================
6341 pAdapter Pointer to our adapter
6342 wrq Pointer to the ioctl argument
6349 1.) iwpriv ra0 e2p 0 ==> read E2PROM where Addr=0x0
6350 2.) iwpriv ra0 e2p 0=1234 ==> write E2PROM where Addr=0x0, value=1234
6351 ==========================================================================
6353 VOID RTMPIoctlE2PROM(
6354 IN PRTMP_ADAPTER pAdapter,
6355 IN struct iwreq *wrq)
6363 UCHAR temp[16], temp2[16];
6367 BOOLEAN bIsPrintAllE2P = FALSE;
6370 memset(msg, 0x00, 1024);
6371 if (wrq->u.data.length > 1) //No parameters.
6373 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6376 //Parsing Read or Write
6383 if ((value = rtstrchr(this_char, '=')) != NULL)
6386 if (!value || !*value)
6390 if(strlen(this_char) > 4)
6393 j = strlen(this_char);
6396 if(this_char[j] > 'f' || this_char[j] < '0')
6401 k = j = strlen(this_char);
6404 this_char[4-k+j] = this_char[j];
6408 this_char[3-k++]='0';
6411 if(strlen(this_char) == 4)
6413 AtoH(this_char, temp, 2);
6414 eepAddr = *temp*256 + temp[1];
6415 if (eepAddr < 0xFFFF)
6417 RT28xx_EEPROM_READ16(pAdapter, eepAddr, eepValue);
6418 sprintf(msg+strlen(msg), "[0x%04X]:0x%04X ", eepAddr , eepValue);
6421 {//Invalid parametes, so default printk all bbp
6423 bIsPrintAllE2P = TRUE;
6431 memcpy(&temp2, value, strlen(value));
6432 temp2[strlen(value)] = '\0';
6435 if((strlen(this_char) > 4) || strlen(temp2) > 8)
6438 j = strlen(this_char);
6441 if(this_char[j] > 'f' || this_char[j] < '0')
6447 if(temp2[j] > 'f' || temp2[j] < '0')
6452 k = j = strlen(this_char);
6455 this_char[4-k+j] = this_char[j];
6459 this_char[3-k++]='0';
6463 k = j = strlen(temp2);
6466 temp2[4-k+j] = temp2[j];
6473 AtoH(this_char, temp, 2);
6474 eepAddr = *temp*256 + temp[1];
6476 AtoH(temp2, temp, 2);
6477 eepValue = *temp*256 + temp[1];
6479 RT28xx_EEPROM_WRITE16(pAdapter, eepAddr, eepValue);
6480 sprintf(msg+strlen(msg), "[0x%02X]:%02X ", eepAddr, eepValue);
6485 bIsPrintAllE2P = TRUE;
6491 struct file *file_w;
6492 PCHAR fileName = "EEPROMDump.txt";
6493 mm_segment_t orig_fs;
6499 file_w = filp_open(fileName, O_WRONLY|O_CREAT, 0);
6502 DBGPRINT(RT_DEBUG_TRACE, ("-->2) %s: Error %ld opening %s\n", __func__, -PTR_ERR(file_w), fileName));
6506 if (file_w->f_op && file_w->f_op->write)
6511 while (eepAddr <= 0xFE)
6513 RT28xx_EEPROM_READ16(pAdapter, eepAddr, eepValue);
6514 sprintf(msg, "%08x = %04x\n", eepAddr , eepValue);
6516 // write data to file
6517 file_w->f_op->write(file_w, msg, strlen(msg), &file_w->f_pos);
6522 sprintf(msg, "\nDump all EEPROM values to %s\n", fileName);
6524 filp_close(file_w, NULL);
6529 if(strlen(msg) == 1)
6530 sprintf(msg+strlen(msg), "===>Error command format!");
6533 // Copy the information into the user buffer
6534 wrq->u.data.length = strlen(msg);
6535 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6537 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlE2PROM\n"));
6541 ==========================================================================
6543 Read / Write RF register
6545 pAdapter Pointer to our adapter
6546 wrq Pointer to the ioctl argument
6553 1.) iwpriv ra0 rf ==> read all RF registers
6554 2.) iwpriv ra0 rf 1 ==> read RF where RegID=1
6555 3.) iwpriv ra0 rf 1=10 ==> write RF R1=0x10
6556 ==========================================================================
6559 IN PRTMP_ADAPTER pAdapter,
6560 IN struct iwreq *wrq)
6570 BOOLEAN bIsPrintAllRF = FALSE;
6573 memset(msg, 0x00, 2048);
6574 if (wrq->u.data.length > 1) //No parameters.
6576 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6579 //Parsing Read or Write
6584 if ((value = strchr(this_char, '=')) != NULL)
6587 if (!value || !*value)
6589 if (sscanf(this_char, "%d", &(rfId)) == 1)
6593 // In RT2860 ATE mode, we do not load 8051 firmware.
6594 //We must access RF directly.
6595 // For RT2870 ATE mode, ATE_RF_IO_WRITE8(/READ8)_BY_REG_ID are redefined.
6596 // according to Andy, Gary, David require.
6597 // the command rf shall read rf register directly for dubug.
6598 // BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
6599 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
6601 sprintf(msg+strlen(msg), "R%02d[0x%02x]:%02X ", rfId, rfId*2, regRF);
6604 {//Invalid parametes, so default printk all RF
6605 bIsPrintAllRF = TRUE;
6610 { //Invalid parametes, so default printk all RF
6611 bIsPrintAllRF = TRUE;
6617 if ((sscanf(this_char, "%d", &(rfId)) == 1) && (sscanf(value, "%lx", &(rfValue)) == 1))
6621 // In RT2860 ATE mode, we do not load 8051 firmware.
6622 // We should access RF registers directly.
6623 // For RT2870 ATE mode, ATE_RF_IO_WRITE8/READ8_BY_REG_ID are redefined.
6625 // according to Andy, Gary, David require.
6626 // the command RF shall read/write RF register directly for dubug.
6627 //BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
6628 //BBP_IO_WRITE8_BY_REG_ID(pAdapter, (UCHAR)bbpId,(UCHAR) bbpValue);
6629 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
6630 RT30xxWriteRFRegister(pAdapter, (UCHAR)rfId,(UCHAR) rfValue);
6631 //Read it back for showing
6632 //BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
6633 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
6634 sprintf(msg+strlen(msg), "R%02d[0x%02X]:%02X\n", rfId, rfId*2, regRF);
6638 {//Invalid parametes, so default printk all RF
6639 bIsPrintAllRF = TRUE;
6643 { //Invalid parametes, so default printk all RF
6644 bIsPrintAllRF = TRUE;
6649 bIsPrintAllRF = TRUE;
6653 memset(msg, 0x00, 2048);
6655 for (rfId = 0; rfId <= 31; rfId++)
6657 // according to Andy, Gary, David require.
6658 // the command RF shall read/write RF register directly for dubug.
6659 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
6660 sprintf(msg+strlen(msg), "%03d = %02X\n", rfId, regRF);
6662 // Copy the information into the user buffer
6663 DBGPRINT(RT_DEBUG_TRACE, ("strlen(msg)=%d\n", (UINT32)strlen(msg)));
6664 wrq->u.data.length = strlen(msg);
6665 if (copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length))
6667 DBGPRINT(RT_DEBUG_TRACE, ("%s: copy_to_user() fail\n", __func__));
6672 if(strlen(msg) == 1)
6673 sprintf(msg+strlen(msg), "===>Error command format!");
6675 DBGPRINT(RT_DEBUG_TRACE, ("copy to user [msg=%s]\n", msg));
6676 // Copy the information into the user buffer
6677 DBGPRINT(RT_DEBUG_TRACE, ("strlen(msg) =%d\n", (UINT32)strlen(msg)));
6679 // Copy the information into the user buffer
6680 wrq->u.data.length = strlen(msg);
6681 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6684 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlRF\n\n"));
6692 INT Set_TGnWifiTest_Proc(
6693 IN PRTMP_ADAPTER pAd,
6696 if (simple_strtol(arg, 0, 10) == 0)
6697 pAd->StaCfg.bTGnWifiTest = FALSE;
6699 pAd->StaCfg.bTGnWifiTest = TRUE;
6701 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_TGnWifiTest_Proc::(bTGnWifiTest=%d)\n", pAd->StaCfg.bTGnWifiTest));
6705 INT Set_LongRetryLimit_Proc(
6706 IN PRTMP_ADAPTER pAdapter,
6709 TX_RTY_CFG_STRUC tx_rty_cfg;
6710 UCHAR LongRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
6712 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
6713 tx_rty_cfg.field.LongRtyLimit = LongRetryLimit;
6714 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
6715 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_LongRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
6719 INT Set_ShortRetryLimit_Proc(
6720 IN PRTMP_ADAPTER pAdapter,
6723 TX_RTY_CFG_STRUC tx_rty_cfg;
6724 UCHAR ShortRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
6726 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
6727 tx_rty_cfg.field.ShortRtyLimit = ShortRetryLimit;
6728 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
6729 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_ShortRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
6733 #if !defined(RT2860) && !defined(RT30xx)
6734 INT Show_Adhoc_MacTable_Proc(
6735 IN PRTMP_ADAPTER pAd,
6740 sprintf(extra, "\n");
6742 sprintf(extra + strlen(extra), "HT Operating Mode : %d\n", pAd->CommonCfg.AddHTInfo.AddHtInfo2.OperaionMode);
6744 sprintf(extra + strlen(extra), "\n%-19s%-4s%-4s%-7s%-7s%-7s%-10s%-6s%-6s%-6s%-6s\n",
6745 "MAC", "AID", "BSS", "RSSI0", "RSSI1", "RSSI2", "PhMd", "BW", "MCS", "SGI", "STBC");
6747 for (i=1; i<MAX_LEN_OF_MAC_TABLE; i++)
6749 PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
6751 if (strlen(extra) > (IW_PRIV_SIZE_MASK - 30))
6753 if ((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
6755 sprintf(extra + strlen(extra), "%02X:%02X:%02X:%02X:%02X:%02X ",
6756 pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
6757 pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5]);
6758 sprintf(extra + strlen(extra), "%-4d", (int)pEntry->Aid);
6759 sprintf(extra + strlen(extra), "%-4d", (int)pEntry->apidx);
6760 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi0);
6761 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi1);
6762 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi2);
6763 sprintf(extra + strlen(extra), "%-10s", GetPhyMode(pEntry->HTPhyMode.field.MODE));
6764 sprintf(extra + strlen(extra), "%-6s", GetBW(pEntry->HTPhyMode.field.BW));
6765 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.MCS);
6766 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.ShortGI);
6767 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.STBC);
6768 sprintf(extra + strlen(extra), "%-10d, %d, %d%%\n", pEntry->DebugFIFOCount, pEntry->DebugTxCount,
6769 (pEntry->DebugTxCount) ? ((pEntry->DebugTxCount-pEntry->DebugFIFOCount)*100/pEntry->DebugTxCount) : 0);
6770 sprintf(extra, "%s\n", extra);