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" },
88 #ifdef QOS_DLS_SUPPORT
89 { SHOW_DLS_ENTRY_INFO,
90 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "dlsentryinfo" },
91 #endif // QOS_DLS_SUPPORT //
93 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "show" },
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,
124 IN PRTMP_ADAPTER pAdapter,
128 INT Set_WmmCapable_Proc(
129 IN PRTMP_ADAPTER pAd,
133 INT Set_NetworkType_Proc(
134 IN PRTMP_ADAPTER pAdapter,
137 INT Set_AuthMode_Proc(
138 IN PRTMP_ADAPTER pAdapter,
141 INT Set_EncrypType_Proc(
142 IN PRTMP_ADAPTER pAdapter,
145 INT Set_DefaultKeyID_Proc(
146 IN PRTMP_ADAPTER pAdapter,
150 IN PRTMP_ADAPTER pAdapter,
154 IN PRTMP_ADAPTER pAdapter,
158 IN PRTMP_ADAPTER pAdapter,
162 IN PRTMP_ADAPTER pAdapter,
166 IN PRTMP_ADAPTER pAdapter,
171 IN PRTMP_ADAPTER pAdapter,
174 #ifdef WPA_SUPPLICANT_SUPPORT
176 IN PRTMP_ADAPTER pAd,
178 #endif // WPA_SUPPLICANT_SUPPORT //
183 IN PRTMP_ADAPTER pAdapter,
184 IN struct iwreq *wrq);
186 VOID RTMPIoctlE2PROM(
187 IN PRTMP_ADAPTER pAdapter,
188 IN struct iwreq *wrq);
192 IN PRTMP_ADAPTER pAdapter,
193 IN struct iwreq *wrq);
198 NDIS_STATUS RTMPWPANoneAddKeyProc(
199 IN PRTMP_ADAPTER pAd,
202 INT Set_FragTest_Proc(
203 IN PRTMP_ADAPTER pAdapter,
206 #ifdef DOT11_N_SUPPORT
207 INT Set_TGnWifiTest_Proc(
208 IN PRTMP_ADAPTER pAd,
210 #endif // DOT11_N_SUPPORT //
212 INT Set_LongRetryLimit_Proc(
213 IN PRTMP_ADAPTER pAdapter,
216 INT Set_ShortRetryLimit_Proc(
217 IN PRTMP_ADAPTER pAdapter,
220 #ifdef EXT_BUILD_CHANNEL_LIST
221 INT Set_Ieee80211dClientMode_Proc(
222 IN PRTMP_ADAPTER pAdapter,
224 #endif // EXT_BUILD_CHANNEL_LIST //
226 #ifdef CARRIER_DETECTION_SUPPORT
227 INT Set_CarrierDetect_Proc(
228 IN PRTMP_ADAPTER pAd,
230 #endif // CARRIER_DETECTION_SUPPORT //
234 INT (*set_proc)(PRTMP_ADAPTER pAdapter, PUCHAR arg);
235 } *PRTMP_PRIVATE_SET_PROC, RTMP_PRIVATE_SUPPORT_PROC[] = {
236 {"DriverVersion", Set_DriverVersion_Proc},
237 {"CountryRegion", Set_CountryRegion_Proc},
238 {"CountryRegionABand", Set_CountryRegionABand_Proc},
239 {"SSID", Set_SSID_Proc},
240 {"WirelessMode", Set_WirelessMode_Proc},
241 {"TxBurst", Set_TxBurst_Proc},
242 {"TxPreamble", Set_TxPreamble_Proc},
243 {"TxPower", Set_TxPower_Proc},
244 {"Channel", Set_Channel_Proc},
245 {"BGProtection", Set_BGProtection_Proc},
246 {"RTSThreshold", Set_RTSThreshold_Proc},
247 {"FragThreshold", Set_FragThreshold_Proc},
248 #ifdef DOT11_N_SUPPORT
249 {"HtBw", Set_HtBw_Proc},
250 {"HtMcs", Set_HtMcs_Proc},
251 {"HtGi", Set_HtGi_Proc},
252 {"HtOpMode", Set_HtOpMode_Proc},
253 {"HtExtcha", Set_HtExtcha_Proc},
254 {"HtMpduDensity", Set_HtMpduDensity_Proc},
255 {"HtBaWinSize", Set_HtBaWinSize_Proc},
256 {"HtRdg", Set_HtRdg_Proc},
257 {"HtAmsdu", Set_HtAmsdu_Proc},
258 {"HtAutoBa", Set_HtAutoBa_Proc},
259 {"HtBaDecline", Set_BADecline_Proc},
260 {"HtProtect", Set_HtProtect_Proc},
261 {"HtMimoPs", Set_HtMimoPs_Proc},
262 #endif // DOT11_N_SUPPORT //
264 #ifdef AGGREGATION_SUPPORT
265 {"PktAggregate", Set_PktAggregate_Proc},
269 {"WmmCapable", Set_WmmCapable_Proc},
271 {"IEEE80211H", Set_IEEE80211H_Proc},
272 {"NetworkType", Set_NetworkType_Proc},
273 {"AuthMode", Set_AuthMode_Proc},
274 {"EncrypType", Set_EncrypType_Proc},
275 {"DefaultKeyID", Set_DefaultKeyID_Proc},
276 {"Key1", Set_Key1_Proc},
277 {"Key2", Set_Key2_Proc},
278 {"Key3", Set_Key3_Proc},
279 {"Key4", Set_Key4_Proc},
280 {"WPAPSK", Set_WPAPSK_Proc},
281 {"ResetCounter", Set_ResetStatCounter_Proc},
282 {"PSMode", Set_PSMode_Proc},
284 {"Debug", Set_Debug_Proc},
288 {"ATE", Set_ATE_Proc},
289 {"ATEDA", Set_ATE_DA_Proc},
290 {"ATESA", Set_ATE_SA_Proc},
291 {"ATEBSSID", Set_ATE_BSSID_Proc},
292 {"ATECHANNEL", Set_ATE_CHANNEL_Proc},
293 {"ATETXPOW0", Set_ATE_TX_POWER0_Proc},
294 {"ATETXPOW1", Set_ATE_TX_POWER1_Proc},
295 {"ATETXANT", Set_ATE_TX_Antenna_Proc},
296 {"ATERXANT", Set_ATE_RX_Antenna_Proc},
297 {"ATETXFREQOFFSET", Set_ATE_TX_FREQOFFSET_Proc},
298 {"ATETXBW", Set_ATE_TX_BW_Proc},
299 {"ATETXLEN", Set_ATE_TX_LENGTH_Proc},
300 {"ATETXCNT", Set_ATE_TX_COUNT_Proc},
301 {"ATETXMCS", Set_ATE_TX_MCS_Proc},
302 {"ATETXMODE", Set_ATE_TX_MODE_Proc},
303 {"ATETXGI", Set_ATE_TX_GI_Proc},
304 {"ATERXFER", Set_ATE_RX_FER_Proc},
305 {"ATERRF", Set_ATE_Read_RF_Proc},
306 {"ATEWRF1", Set_ATE_Write_RF1_Proc},
307 {"ATEWRF2", Set_ATE_Write_RF2_Proc},
308 {"ATEWRF3", Set_ATE_Write_RF3_Proc},
309 {"ATEWRF4", Set_ATE_Write_RF4_Proc},
310 {"ATELDE2P", Set_ATE_Load_E2P_Proc},
311 {"ATERE2P", Set_ATE_Read_E2P_Proc},
312 {"ATESHOW", Set_ATE_Show_Proc},
313 {"ATEHELP", Set_ATE_Help_Proc},
315 #ifdef RALINK_28xx_QA
316 {"TxStop", Set_TxStop_Proc},
317 {"RxStop", Set_RxStop_Proc},
318 #endif // RALINK_28xx_QA //
319 #endif // RALINK_ATE //
321 #ifdef WPA_SUPPLICANT_SUPPORT
322 {"WpaSupport", Set_Wpa_Support},
323 #endif // WPA_SUPPLICANT_SUPPORT //
327 {"FixedTxMode", Set_FixedTxMode_Proc},
328 #ifdef CONFIG_APSTA_MIXED_SUPPORT
329 {"OpMode", Set_OpMode_Proc},
330 #endif // CONFIG_APSTA_MIXED_SUPPORT //
331 #ifdef DOT11_N_SUPPORT
332 {"TGnWifiTest", Set_TGnWifiTest_Proc},
333 {"ForceGF", Set_ForceGF_Proc},
334 #endif // DOT11_N_SUPPORT //
335 #ifdef QOS_DLS_SUPPORT
336 {"DlsAddEntry", Set_DlsAddEntry_Proc},
337 {"DlsTearDownEntry", Set_DlsTearDownEntry_Proc},
338 #endif // QOS_DLS_SUPPORT //
339 {"LongRetry", Set_LongRetryLimit_Proc},
340 {"ShortRetry", Set_ShortRetryLimit_Proc},
341 #ifdef EXT_BUILD_CHANNEL_LIST
342 {"11dClientMode", Set_Ieee80211dClientMode_Proc},
343 #endif // EXT_BUILD_CHANNEL_LIST //
344 #ifdef CARRIER_DETECTION_SUPPORT
345 {"CarrierDetect", Set_CarrierDetect_Proc},
346 #endif // CARRIER_DETECTION_SUPPORT //
347 //2008/09/11:KH add to support efuse<--
349 {"efuseFreeNumber", set_eFuseGetFreeBlockCount_Proc},
350 {"efuseDump", set_eFusedump_Proc},
351 {"efuseLoadFromBin", set_eFuseLoadFromBin_Proc},
353 //2008/09/11:KH add to support efuse-->
359 IN PRTMP_ADAPTER pAd,
360 IN PNDIS_802_11_KEY pKey)
363 MAC_TABLE_ENTRY *pEntry;
365 DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey ------>\n"));
367 if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
369 if (pKey->KeyIndex & 0x80000000)
371 if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
373 NdisZeroMemory(pAd->StaCfg.PMK, 32);
374 NdisMoveMemory(pAd->StaCfg.PMK, pKey->KeyMaterial, pKey->KeyLength);
378 NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));
379 pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
380 NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, pKey->KeyMaterial, LEN_TKIP_EK);
381 #ifdef WPA_SUPPLICANT_SUPPORT
382 if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
384 NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
385 NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
388 #endif // WPA_SUPPLICANT_SUPPORT //
390 NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
391 NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
394 // Decide its ChiperAlg
395 if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
396 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
397 else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)
398 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
400 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_NONE;
402 // Update these related information to MAC_TABLE_ENTRY
403 pEntry = &pAd->MacTab.Content[BSSID_WCID];
404 NdisMoveMemory(pEntry->PairwiseKey.Key, pAd->SharedKey[BSS0][0].Key, LEN_TKIP_EK);
405 NdisMoveMemory(pEntry->PairwiseKey.RxMic, pAd->SharedKey[BSS0][0].RxMic, LEN_TKIP_RXMICK);
406 NdisMoveMemory(pEntry->PairwiseKey.TxMic, pAd->SharedKey[BSS0][0].TxMic, LEN_TKIP_TXMICK);
407 pEntry->PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;
409 // Update pairwise key information to ASIC Shared Key Table
410 AsicAddSharedKeyEntry(pAd,
413 pAd->SharedKey[BSS0][0].CipherAlg,
414 pAd->SharedKey[BSS0][0].Key,
415 pAd->SharedKey[BSS0][0].TxMic,
416 pAd->SharedKey[BSS0][0].RxMic);
418 // Update ASIC WCID attribute table and IVEIV table
419 RTMPAddWcidAttributeEntry(pAd,
422 pAd->SharedKey[BSS0][0].CipherAlg,
425 if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
427 // set 802.1x port control
428 //pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
429 STA_PORT_SECURED(pAd);
431 // Indicate Connected for GUI
432 pAd->IndicateMediaState = NdisMediaStateConnected;
438 pAd->StaCfg.DefaultKeyId = (pKey->KeyIndex & 0xFF);
439 NdisZeroMemory(&pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId], sizeof(CIPHER_KEY));
440 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].KeyLen = LEN_TKIP_EK;
441 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key, pKey->KeyMaterial, LEN_TKIP_EK);
442 #ifdef WPA_SUPPLICANT_SUPPORT
443 if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
445 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
446 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
449 #endif // WPA_SUPPLICANT_SUPPORT //
451 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
452 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
455 // Update Shared Key CipherAlg
456 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_NONE;
457 if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
458 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_TKIP;
459 else if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)
460 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_AES;
462 // Update group key information to ASIC Shared Key Table
463 AsicAddSharedKeyEntry(pAd,
465 pAd->StaCfg.DefaultKeyId,
466 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
467 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key,
468 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic,
469 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic);
471 // Update ASIC WCID attribute table and IVEIV table
472 RTMPAddWcidAttributeEntry(pAd,
474 pAd->StaCfg.DefaultKeyId,
475 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
478 // set 802.1x port control
479 //pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
480 STA_PORT_SECURED(pAd);
482 // Indicate Connected for GUI
483 pAd->IndicateMediaState = NdisMediaStateConnected;
486 else // dynamic WEP from wpa_supplicant
491 if(pKey->KeyLength == 32)
494 KeyIdx = pKey->KeyIndex & 0x0fffffff;
498 // it is a default shared key, for Pairwise key setting
499 if (pKey->KeyIndex & 0x80000000)
501 pEntry = MacTableLookup(pAd, pKey->BSSID);
505 DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey: Set Pair-wise Key\n"));
507 // set key material and key length
508 pEntry->PairwiseKey.KeyLen = (UCHAR)pKey->KeyLength;
509 NdisMoveMemory(pEntry->PairwiseKey.Key, &pKey->KeyMaterial, pKey->KeyLength);
512 if (pKey->KeyLength == 5)
513 pEntry->PairwiseKey.CipherAlg = CIPHER_WEP64;
515 pEntry->PairwiseKey.CipherAlg = CIPHER_WEP128;
517 // Add Pair-wise key to Asic
518 AsicAddPairwiseKeyEntry(
522 &pEntry->PairwiseKey);
524 // update WCID attribute table and IVEIV table for this entry
525 RTMPAddWcidAttributeEntry(
528 KeyIdx, // The value may be not zero
529 pEntry->PairwiseKey.CipherAlg,
536 // Default key for tx (shared key)
537 pAd->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
539 // set key material and key length
540 pAd->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pKey->KeyLength;
541 NdisMoveMemory(pAd->SharedKey[BSS0][KeyIdx].Key, &pKey->KeyMaterial, pKey->KeyLength);
544 if (pKey->KeyLength == 5)
545 pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP64;
547 pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP128;
549 CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg;
550 Key = pAd->SharedKey[BSS0][KeyIdx].Key;
552 // Set Group key material to Asic
553 AsicAddSharedKeyEntry(pAd, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
555 // Update WCID attribute table and IVEIV table for this group key table
556 RTMPAddWcidAttributeEntry(pAd, BSS0, KeyIdx, CipherAlg, NULL);
565 char * rtstrchr(const char * s, int c)
567 for(; *s != (char) c; ++s)
574 This is required for LinEX2004/kernel2.6.7 to provide iwlist scanning function
578 rt_ioctl_giwname(struct net_device *dev,
579 struct iw_request_info *info,
580 char *name, char *extra)
582 // PRTMP_ADAPTER pAdapter = dev->ml_priv;
585 strncpy(name, "RT2870 Wireless", IFNAMSIZ);
590 int rt_ioctl_siwfreq(struct net_device *dev,
591 struct iw_request_info *info,
592 struct iw_freq *freq, char *extra)
594 PRTMP_ADAPTER pAdapter = dev->ml_priv;
597 //check if the interface is down
598 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
600 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
608 if((freq->e == 0) && (freq->m <= 1000))
609 chan = freq->m; // Setting by channel number
611 MAP_KHZ_TO_CHANNEL_ID( (freq->m /100) , chan); // Setting by frequency - search the table , like 2.412G, 2.422G,
613 if (ChannelSanity(pAdapter, chan) == TRUE)
615 pAdapter->CommonCfg.Channel = chan;
616 DBGPRINT(RT_DEBUG_ERROR, ("==>rt_ioctl_siwfreq::SIOCSIWFREQ[cmd=0x%x] (Channel=%d)\n", SIOCSIWFREQ, pAdapter->CommonCfg.Channel));
623 int rt_ioctl_giwfreq(struct net_device *dev,
624 struct iw_request_info *info,
625 struct iw_freq *freq, char *extra)
627 VIRTUAL_ADAPTER *pVirtualAd = NULL;
628 PRTMP_ADAPTER pAdapter;
632 if (dev->priv_flags == INT_MAIN)
634 pAdapter = dev->ml_priv;
638 pVirtualAd = dev->ml_priv;
639 pAdapter = pVirtualAd->RtmpDev->ml_priv;
642 if (pAdapter == NULL)
644 /* if 1st open fail, pAd will be free;
645 So the net_dev->ml_priv will be NULL in 2rd open */
649 ch = pAdapter->CommonCfg.Channel;
651 DBGPRINT(RT_DEBUG_TRACE,("==>rt_ioctl_giwfreq %d\n", ch));
653 MAP_CHANNEL_ID_TO_KHZ(ch, m);
659 int rt_ioctl_siwmode(struct net_device *dev,
660 struct iw_request_info *info,
661 __u32 *mode, char *extra)
663 PRTMP_ADAPTER pAdapter = dev->ml_priv;
665 //check if the interface is down
666 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
668 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
675 Set_NetworkType_Proc(pAdapter, "Adhoc");
678 Set_NetworkType_Proc(pAdapter, "Infra");
680 case IW_MODE_MONITOR:
681 Set_NetworkType_Proc(pAdapter, "Monitor");
684 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_siwmode::SIOCSIWMODE (unknown %d)\n", *mode));
688 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
689 pAdapter->StaCfg.WpaState = SS_NOTUSE;
694 int rt_ioctl_giwmode(struct net_device *dev,
695 struct iw_request_info *info,
696 __u32 *mode, char *extra)
698 PRTMP_ADAPTER pAdapter = dev->ml_priv;
700 if (ADHOC_ON(pAdapter))
701 *mode = IW_MODE_ADHOC;
702 else if (INFRA_ON(pAdapter))
703 *mode = IW_MODE_INFRA;
704 else if (MONITOR_ON(pAdapter))
706 *mode = IW_MODE_MONITOR;
709 *mode = IW_MODE_AUTO;
711 DBGPRINT(RT_DEBUG_TRACE, ("==>rt_ioctl_giwmode(mode=%d)\n", *mode));
715 int rt_ioctl_siwsens(struct net_device *dev,
716 struct iw_request_info *info,
717 char *name, char *extra)
719 PRTMP_ADAPTER pAdapter = dev->ml_priv;
721 //check if the interface is down
722 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
724 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
731 int rt_ioctl_giwsens(struct net_device *dev,
732 struct iw_request_info *info,
733 char *name, char *extra)
738 int rt_ioctl_giwrange(struct net_device *dev,
739 struct iw_request_info *info,
740 struct iw_point *data, char *extra)
742 PRTMP_ADAPTER pAdapter = dev->ml_priv;
744 struct iw_range *range = (struct iw_range *) extra;
748 DBGPRINT(RT_DEBUG_TRACE ,("===>rt_ioctl_giwrange\n"));
749 data->length = sizeof(struct iw_range);
750 memset(range, 0, sizeof(struct iw_range));
752 range->txpower_capa = IW_TXPOW_DBM;
754 if (INFRA_ON(pAdapter)||ADHOC_ON(pAdapter))
756 range->min_pmp = 1 * 1024;
757 range->max_pmp = 65535 * 1024;
758 range->min_pmt = 1 * 1024;
759 range->max_pmt = 1000 * 1024;
760 range->pmp_flags = IW_POWER_PERIOD;
761 range->pmt_flags = IW_POWER_TIMEOUT;
762 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT |
763 IW_POWER_UNICAST_R | IW_POWER_ALL_R;
766 range->we_version_compiled = WIRELESS_EXT;
767 range->we_version_source = 14;
769 range->retry_capa = IW_RETRY_LIMIT;
770 range->retry_flags = IW_RETRY_LIMIT;
771 range->min_retry = 0;
772 range->max_retry = 255;
774 range->num_channels = pAdapter->ChannelListNum;
777 for (i = 1; i <= range->num_channels; i++)
780 range->freq[val].i = pAdapter->ChannelList[i-1].Channel;
781 MAP_CHANNEL_ID_TO_KHZ(pAdapter->ChannelList[i-1].Channel, m);
782 range->freq[val].m = m * 100; /* HZ */
784 range->freq[val].e = 1;
786 if (val == IW_MAX_FREQUENCIES)
789 range->num_frequency = val;
791 range->max_qual.qual = 100; /* what is correct max? This was not
792 * documented exactly. At least
793 * 69 has been observed. */
794 range->max_qual.level = 0; /* dB */
795 range->max_qual.noise = 0; /* dB */
797 /* What would be suitable values for "average/typical" qual? */
798 range->avg_qual.qual = 20;
799 range->avg_qual.level = -60;
800 range->avg_qual.noise = -95;
801 range->sensitivity = 3;
803 range->max_encoding_tokens = NR_WEP_KEYS;
804 range->num_encoding_sizes = 2;
805 range->encoding_size[0] = 5;
806 range->encoding_size[1] = 13;
809 range->max_rts = 2347;
810 range->min_frag = 256;
811 range->max_frag = 2346;
813 #if WIRELESS_EXT > 17
814 /* IW_ENC_CAPA_* bit field */
815 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
816 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
822 int rt_ioctl_siwap(struct net_device *dev,
823 struct iw_request_info *info,
824 struct sockaddr *ap_addr, char *extra)
826 PRTMP_ADAPTER pAdapter = dev->ml_priv;
827 NDIS_802_11_MAC_ADDRESS Bssid;
829 //check if the interface is down
830 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
832 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
836 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
838 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
839 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
842 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
843 // this request, because this request is initiated by NDIS.
844 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
845 // Prevent to connect AP again in STAMlmePeriodicExec
846 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
848 memset(Bssid, 0, MAC_ADDR_LEN);
849 memcpy(Bssid, ap_addr->sa_data, MAC_ADDR_LEN);
850 MlmeEnqueue(pAdapter,
851 MLME_CNTL_STATE_MACHINE,
853 sizeof(NDIS_802_11_MAC_ADDRESS),
856 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCSIWAP %02x:%02x:%02x:%02x:%02x:%02x\n",
857 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
862 int rt_ioctl_giwap(struct net_device *dev,
863 struct iw_request_info *info,
864 struct sockaddr *ap_addr, char *extra)
866 PRTMP_ADAPTER pAdapter = dev->ml_priv;
868 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
870 ap_addr->sa_family = ARPHRD_ETHER;
871 memcpy(ap_addr->sa_data, &pAdapter->CommonCfg.Bssid, ETH_ALEN);
873 #ifdef WPA_SUPPLICANT_SUPPORT
875 else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
877 ap_addr->sa_family = ARPHRD_ETHER;
878 memcpy(ap_addr->sa_data, &pAdapter->MlmeAux.Bssid, ETH_ALEN);
880 #endif // WPA_SUPPLICANT_SUPPORT //
883 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIWAP(=EMPTY)\n"));
891 * Units are in db above the noise floor. That means the
892 * rssi values reported in the tx/rx descriptors in the
893 * driver are the SNR expressed in db.
895 * If you assume that the noise floor is -95, which is an
896 * excellent assumption 99.5 % of the time, then you can
897 * derive the absolute signal level (i.e. -95 + rssi).
898 * There are some other slight factors to take into account
899 * depending on whether the rssi measurement is from 11b,
900 * 11g, or 11a. These differences are at most 2db and
903 * NB: various calculations are based on the orinoco/wavelan
904 * drivers for compatibility
906 static void set_quality(PRTMP_ADAPTER pAdapter,
907 struct iw_quality *iq,
914 ChannelQuality = 100;
915 else if (rssi >= -80) // between -50 ~ -80dbm
916 ChannelQuality = (__u8)(24 + ((rssi + 80) * 26)/10);
917 else if (rssi >= -90) // between -80 ~ -90dbm
918 ChannelQuality = (__u8)((rssi + 90) * 26)/10;
922 iq->qual = (__u8)ChannelQuality;
924 iq->level = (__u8)(rssi);
925 iq->noise = (pAdapter->BbpWriteLatch[66] > pAdapter->BbpTuning.FalseCcaUpperThreshold) ? ((__u8)pAdapter->BbpTuning.FalseCcaUpperThreshold) : ((__u8) pAdapter->BbpWriteLatch[66]); // noise level (dBm)
926 iq->noise += 256 - 143;
927 iq->updated = pAdapter->iw_stats.qual.updated;
930 int rt_ioctl_iwaplist(struct net_device *dev,
931 struct iw_request_info *info,
932 struct iw_point *data, char *extra)
934 PRTMP_ADAPTER pAdapter = dev->ml_priv;
936 struct sockaddr addr[IW_MAX_AP];
937 struct iw_quality qual[IW_MAX_AP];
940 //check if the interface is down
941 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
943 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
949 for (i = 0; i <IW_MAX_AP ; i++)
951 if (i >= pAdapter->ScanTab.BssNr)
953 addr[i].sa_family = ARPHRD_ETHER;
954 memcpy(addr[i].sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
955 set_quality(pAdapter, &qual[i], pAdapter->ScanTab.BssEntry[i].Rssi);
958 memcpy(extra, &addr, i*sizeof(addr[0]));
959 data->flags = 1; /* signal quality present (sort of) */
960 memcpy(extra + i*sizeof(addr[0]), &qual, i*sizeof(qual[i]));
966 int rt_ioctl_siwscan(struct net_device *dev,
967 struct iw_request_info *info,
968 struct iw_point *data, char *extra)
970 PRTMP_ADAPTER pAdapter = dev->ml_priv;
973 int Status = NDIS_STATUS_SUCCESS;
975 //check if the interface is down
976 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
978 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
982 if (MONITOR_ON(pAdapter))
984 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
989 #ifdef WPA_SUPPLICANT_SUPPORT
990 if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
992 pAdapter->StaCfg.WpaSupplicantScanCount++;
994 #endif // WPA_SUPPLICANT_SUPPORT //
996 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
997 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
1002 #ifdef WPA_SUPPLICANT_SUPPORT
1003 if ((pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE) &&
1004 (pAdapter->StaCfg.WpaSupplicantScanCount > 3))
1006 DBGPRINT(RT_DEBUG_TRACE, ("!!! WpaSupplicantScanCount > 3\n"));
1007 Status = NDIS_STATUS_SUCCESS;
1010 #endif // WPA_SUPPLICANT_SUPPORT //
1012 if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
1013 ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
1014 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) &&
1015 (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
1017 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
1018 Status = NDIS_STATUS_SUCCESS;
1022 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
1024 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
1025 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
1028 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
1029 // this request, because this request is initiated by NDIS.
1030 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
1031 // Reset allowed scan retries
1032 pAdapter->StaCfg.ScanCnt = 0;
1033 pAdapter->StaCfg.LastScanTime = Now;
1035 MlmeEnqueue(pAdapter,
1036 MLME_CNTL_STATE_MACHINE,
1037 OID_802_11_BSSID_LIST_SCAN,
1041 Status = NDIS_STATUS_SUCCESS;
1042 RT28XX_MLME_HANDLER(pAdapter);
1047 int rt_ioctl_giwscan(struct net_device *dev,
1048 struct iw_request_info *info,
1049 struct iw_point *data, char *extra)
1052 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1054 char *current_ev = extra, *previous_ev = extra;
1056 char *current_val, custom[MAX_CUSTOM_LEN] = {0};
1059 #endif // IWEVGENIE //
1060 struct iw_event iwe;
1062 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
1065 * Still scanning, indicate the caller should try again.
1071 #ifdef WPA_SUPPLICANT_SUPPORT
1072 if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
1074 pAdapter->StaCfg.WpaSupplicantScanCount = 0;
1076 #endif // WPA_SUPPLICANT_SUPPORT //
1078 if (pAdapter->ScanTab.BssNr == 0)
1084 #if WIRELESS_EXT >= 17
1085 if (data->length > 0)
1086 end_buf = extra + data->length;
1088 end_buf = extra + IW_SCAN_MAX_DATA;
1090 end_buf = extra + IW_SCAN_MAX_DATA;
1093 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
1095 if (current_ev >= end_buf)
1097 #if WIRELESS_EXT >= 17
1105 //================================
1106 memset(&iwe, 0, sizeof(iwe));
1107 iwe.cmd = SIOCGIWAP;
1108 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1109 memcpy(iwe.u.ap_addr.sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, ETH_ALEN);
1111 previous_ev = current_ev;
1112 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
1113 if (current_ev == previous_ev)
1114 #if WIRELESS_EXT >= 17
1122 it will show scanned AP's WirelessMode .
1131 memset(&iwe, 0, sizeof(iwe));
1132 iwe.cmd = SIOCGIWNAME;
1136 PBSS_ENTRY pBssEntry=&pAdapter->ScanTab.BssEntry[i];
1137 BOOLEAN isGonly=FALSE;
1140 if (pBssEntry->Channel>14)
1142 if (pBssEntry->HtCapabilityLen!=0)
1143 strcpy(iwe.u.name,"802.11a/n");
1145 strcpy(iwe.u.name,"802.11a");
1150 if one of non B mode rate is set supported rate . it mean G only.
1152 for (rateCnt=0;rateCnt<pBssEntry->SupRateLen;rateCnt++)
1155 6Mbps(140) 9Mbps(146) and >=12Mbps(152) are supported rate , it mean G only.
1157 if (pBssEntry->SupRate[rateCnt]==140 || pBssEntry->SupRate[rateCnt]==146 || pBssEntry->SupRate[rateCnt]>=152)
1161 for (rateCnt=0;rateCnt<pBssEntry->ExtRateLen;rateCnt++)
1163 if (pBssEntry->ExtRate[rateCnt]==140 || pBssEntry->ExtRate[rateCnt]==146 || pBssEntry->ExtRate[rateCnt]>=152)
1168 if (pBssEntry->HtCapabilityLen!=0)
1171 strcpy(iwe.u.name,"802.11g/n");
1173 strcpy(iwe.u.name,"802.11b/g/n");
1178 strcpy(iwe.u.name,"802.11g");
1181 if (pBssEntry->SupRateLen==4 && pBssEntry->ExtRateLen==0)
1182 strcpy(iwe.u.name,"802.11b");
1184 strcpy(iwe.u.name,"802.11b/g");
1190 previous_ev = current_ev;
1191 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
1192 if (current_ev == previous_ev)
1193 #if WIRELESS_EXT >= 17
1200 //================================
1201 memset(&iwe, 0, sizeof(iwe));
1202 iwe.cmd = SIOCGIWESSID;
1203 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].SsidLen;
1204 iwe.u.data.flags = 1;
1206 previous_ev = current_ev;
1207 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pAdapter->ScanTab.BssEntry[i].Ssid);
1208 if (current_ev == previous_ev)
1209 #if WIRELESS_EXT >= 17
1216 //================================
1217 memset(&iwe, 0, sizeof(iwe));
1218 iwe.cmd = SIOCGIWMODE;
1219 if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11IBSS)
1221 iwe.u.mode = IW_MODE_ADHOC;
1223 else if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11Infrastructure)
1225 iwe.u.mode = IW_MODE_INFRA;
1229 iwe.u.mode = IW_MODE_AUTO;
1231 iwe.len = IW_EV_UINT_LEN;
1233 previous_ev = current_ev;
1234 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
1235 if (current_ev == previous_ev)
1236 #if WIRELESS_EXT >= 17
1242 //Channel and Frequency
1243 //================================
1244 memset(&iwe, 0, sizeof(iwe));
1245 iwe.cmd = SIOCGIWFREQ;
1246 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
1247 iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
1249 iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
1253 previous_ev = current_ev;
1254 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
1255 if (current_ev == previous_ev)
1256 #if WIRELESS_EXT >= 17
1262 //Add quality statistics
1263 //================================
1264 memset(&iwe, 0, sizeof(iwe));
1266 iwe.u.qual.level = 0;
1267 iwe.u.qual.noise = 0;
1268 set_quality(pAdapter, &iwe.u.qual, pAdapter->ScanTab.BssEntry[i].Rssi);
1269 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
1270 if (current_ev == previous_ev)
1271 #if WIRELESS_EXT >= 17
1278 //================================
1279 memset(&iwe, 0, sizeof(iwe));
1280 iwe.cmd = SIOCGIWENCODE;
1281 if (CAP_IS_PRIVACY_ON (pAdapter->ScanTab.BssEntry[i].CapabilityInfo ))
1282 iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1284 iwe.u.data.flags = IW_ENCODE_DISABLED;
1286 previous_ev = current_ev;
1287 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);
1288 if (current_ev == previous_ev)
1289 #if WIRELESS_EXT >= 17
1296 //================================
1297 if (pAdapter->ScanTab.BssEntry[i].SupRateLen)
1299 UCHAR tmpRate = pAdapter->ScanTab.BssEntry[i].SupRate[pAdapter->ScanTab.BssEntry[i].SupRateLen-1];
1300 memset(&iwe, 0, sizeof(iwe));
1301 iwe.cmd = SIOCGIWRATE;
1302 current_val = current_ev + IW_EV_LCP_LEN;
1303 if (tmpRate == 0x82)
1304 iwe.u.bitrate.value = 1 * 1000000;
1305 else if (tmpRate == 0x84)
1306 iwe.u.bitrate.value = 2 * 1000000;
1307 else if (tmpRate == 0x8B)
1308 iwe.u.bitrate.value = 5.5 * 1000000;
1309 else if (tmpRate == 0x96)
1310 iwe.u.bitrate.value = 11 * 1000000;
1312 iwe.u.bitrate.value = (tmpRate/2) * 1000000;
1314 iwe.u.bitrate.disabled = 0;
1315 current_val = iwe_stream_add_value(info, current_ev,
1316 current_val, end_buf, &iwe,
1319 if((current_val-current_ev)>IW_EV_LCP_LEN)
1320 current_ev = current_val;
1322 #if WIRELESS_EXT >= 17
1331 if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
1333 memset(&iwe, 0, sizeof(iwe));
1334 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1335 memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].WpaIE.IE[0]),
1336 pAdapter->ScanTab.BssEntry[i].WpaIE.IELen);
1337 iwe.cmd = IWEVGENIE;
1338 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].WpaIE.IELen;
1339 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, custom);
1340 if (current_ev == previous_ev)
1341 #if WIRELESS_EXT >= 17
1349 if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
1351 memset(&iwe, 0, sizeof(iwe));
1352 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1353 memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].RsnIE.IE[0]),
1354 pAdapter->ScanTab.BssEntry[i].RsnIE.IELen);
1355 iwe.cmd = IWEVGENIE;
1356 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].RsnIE.IELen;
1357 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, custom);
1358 if (current_ev == previous_ev)
1359 #if WIRELESS_EXT >= 17
1367 //================================
1368 if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
1370 NdisZeroMemory(&iwe, sizeof(iwe));
1371 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1372 iwe.cmd = IWEVCUSTOM;
1373 iwe.u.data.length = (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen * 2) + 7;
1374 NdisMoveMemory(custom, "wpa_ie=", 7);
1375 for (idx = 0; idx < pAdapter->ScanTab.BssEntry[i].WpaIE.IELen; idx++)
1376 sprintf(custom, "%s%02x", custom, pAdapter->ScanTab.BssEntry[i].WpaIE.IE[idx]);
1377 previous_ev = current_ev;
1378 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, custom);
1379 if (current_ev == previous_ev)
1380 #if WIRELESS_EXT >= 17
1388 if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
1390 NdisZeroMemory(&iwe, sizeof(iwe));
1391 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1392 iwe.cmd = IWEVCUSTOM;
1393 iwe.u.data.length = (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen * 2) + 7;
1394 NdisMoveMemory(custom, "rsn_ie=", 7);
1395 for (idx = 0; idx < pAdapter->ScanTab.BssEntry[i].RsnIE.IELen; idx++)
1396 sprintf(custom, "%s%02x", custom, pAdapter->ScanTab.BssEntry[i].RsnIE.IE[idx]);
1397 previous_ev = current_ev;
1398 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, custom);
1399 if (current_ev == previous_ev)
1400 #if WIRELESS_EXT >= 17
1406 #endif // IWEVGENIE //
1409 data->length = current_ev - extra;
1410 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
1411 DBGPRINT(RT_DEBUG_ERROR ,("===>rt_ioctl_giwscan. %d(%d) BSS returned, data->length = %d\n",i , pAdapter->ScanTab.BssNr, data->length));
1416 int rt_ioctl_siwessid(struct net_device *dev,
1417 struct iw_request_info *info,
1418 struct iw_point *data, char *essid)
1420 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1422 //check if the interface is down
1423 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1425 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1431 PCHAR pSsidString = NULL;
1433 // Includes null character.
1434 if (data->length > (IW_ESSID_MAX_SIZE + 1))
1437 pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
1440 NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
1441 NdisMoveMemory(pSsidString, essid, data->length);
1442 if (Set_SSID_Proc(pAdapter, pSsidString) == FALSE)
1451 if (Set_SSID_Proc(pAdapter, "") == FALSE)
1457 int rt_ioctl_giwessid(struct net_device *dev,
1458 struct iw_request_info *info,
1459 struct iw_point *data, char *essid)
1461 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1464 if (MONITOR_ON(pAdapter))
1470 if (OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED))
1472 DBGPRINT(RT_DEBUG_TRACE ,("MediaState is connected\n"));
1473 data->length = pAdapter->CommonCfg.SsidLen;
1474 memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
1477 #ifdef WPA_SUPPLICANT_SUPPORT
1479 else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
1481 data->length = pAdapter->CommonCfg.SsidLen;
1482 memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
1484 #endif // WPA_SUPPLICANT_SUPPORT //
1487 {//the ANY ssid was specified
1489 DBGPRINT(RT_DEBUG_TRACE ,("MediaState is not connected, ess\n"));
1496 int rt_ioctl_siwnickn(struct net_device *dev,
1497 struct iw_request_info *info,
1498 struct iw_point *data, char *nickname)
1500 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1502 //check if the interface is down
1503 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1505 DBGPRINT(RT_DEBUG_TRACE ,("INFO::Network is down!\n"));
1509 if (data->length > IW_ESSID_MAX_SIZE)
1512 memset(pAdapter->nickname, 0, IW_ESSID_MAX_SIZE + 1);
1513 memcpy(pAdapter->nickname, nickname, data->length);
1519 int rt_ioctl_giwnickn(struct net_device *dev,
1520 struct iw_request_info *info,
1521 struct iw_point *data, char *nickname)
1523 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1525 if (data->length > strlen(pAdapter->nickname) + 1)
1526 data->length = strlen(pAdapter->nickname) + 1;
1527 if (data->length > 0) {
1528 memcpy(nickname, pAdapter->nickname, data->length-1);
1529 nickname[data->length-1] = '\0';
1534 int rt_ioctl_siwrts(struct net_device *dev,
1535 struct iw_request_info *info,
1536 struct iw_param *rts, char *extra)
1538 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1541 //check if the interface is down
1542 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1544 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1549 val = MAX_RTS_THRESHOLD;
1550 else if (rts->value < 0 || rts->value > MAX_RTS_THRESHOLD)
1552 else if (rts->value == 0)
1553 val = MAX_RTS_THRESHOLD;
1557 if (val != pAdapter->CommonCfg.RtsThreshold)
1558 pAdapter->CommonCfg.RtsThreshold = val;
1563 int rt_ioctl_giwrts(struct net_device *dev,
1564 struct iw_request_info *info,
1565 struct iw_param *rts, char *extra)
1567 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1569 //check if the interface is down
1570 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1572 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1576 rts->value = pAdapter->CommonCfg.RtsThreshold;
1577 rts->disabled = (rts->value == MAX_RTS_THRESHOLD);
1583 int rt_ioctl_siwfrag(struct net_device *dev,
1584 struct iw_request_info *info,
1585 struct iw_param *frag, char *extra)
1587 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1590 //check if the interface is down
1591 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1593 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1598 val = MAX_FRAG_THRESHOLD;
1599 else if (frag->value >= MIN_FRAG_THRESHOLD || frag->value <= MAX_FRAG_THRESHOLD)
1600 val = __cpu_to_le16(frag->value & ~0x1); /* even numbers only */
1601 else if (frag->value == 0)
1602 val = MAX_FRAG_THRESHOLD;
1606 pAdapter->CommonCfg.FragmentThreshold = val;
1610 int rt_ioctl_giwfrag(struct net_device *dev,
1611 struct iw_request_info *info,
1612 struct iw_param *frag, char *extra)
1614 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1616 //check if the interface is down
1617 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1619 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1623 frag->value = pAdapter->CommonCfg.FragmentThreshold;
1624 frag->disabled = (frag->value == MAX_FRAG_THRESHOLD);
1630 #define MAX_WEP_KEY_SIZE 13
1631 #define MIN_WEP_KEY_SIZE 5
1632 int rt_ioctl_siwencode(struct net_device *dev,
1633 struct iw_request_info *info,
1634 struct iw_point *erq, char *extra)
1636 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1638 //check if the interface is down
1639 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1641 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1645 if ((erq->length == 0) &&
1646 (erq->flags & IW_ENCODE_DISABLED))
1648 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
1649 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
1650 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
1651 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
1652 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1655 else if (erq->flags & IW_ENCODE_RESTRICTED || erq->flags & IW_ENCODE_OPEN)
1657 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
1658 STA_PORT_SECURED(pAdapter);
1659 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
1660 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
1661 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
1662 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
1663 if (erq->flags & IW_ENCODE_RESTRICTED)
1664 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
1666 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1669 if (erq->length > 0)
1671 int keyIdx = (erq->flags & IW_ENCODE_INDEX) - 1;
1672 /* Check the size of the key */
1673 if (erq->length > MAX_WEP_KEY_SIZE)
1677 /* Check key index */
1678 if ((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
1680 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::Wrong keyIdx=%d! Using default key instead (%d)\n",
1681 keyIdx, pAdapter->StaCfg.DefaultKeyId));
1684 keyIdx = pAdapter->StaCfg.DefaultKeyId;
1688 pAdapter->StaCfg.DefaultKeyId=keyIdx;
1691 NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
1693 if (erq->length == MAX_WEP_KEY_SIZE)
1695 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
1696 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
1698 else if (erq->length == MIN_WEP_KEY_SIZE)
1700 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
1701 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
1704 /* Disable the key */
1705 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
1707 /* Check if the key is not marked as invalid */
1708 if(!(erq->flags & IW_ENCODE_NOKEY))
1710 /* Copy the key in the driver */
1711 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, extra, erq->length);
1716 /* Do we want to just set the transmit key index ? */
1717 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
1718 if ((index >= 0) && (index < 4))
1720 pAdapter->StaCfg.DefaultKeyId = index;
1723 /* Don't complain if only change the mode */
1724 if (!(erq->flags & IW_ENCODE_MODE))
1729 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::erq->flags=%x\n",erq->flags));
1730 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::AuthMode=%x\n",pAdapter->StaCfg.AuthMode));
1731 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::DefaultKeyId=%x, KeyLen = %d\n",pAdapter->StaCfg.DefaultKeyId , pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen));
1732 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::WepStatus=%x\n",pAdapter->StaCfg.WepStatus));
1737 rt_ioctl_giwencode(struct net_device *dev,
1738 struct iw_request_info *info,
1739 struct iw_point *erq, char *key)
1741 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1744 //check if the interface is down
1745 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1747 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1751 kid = erq->flags & IW_ENCODE_INDEX;
1752 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_giwencode %d\n", erq->flags & IW_ENCODE_INDEX));
1754 if (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled)
1757 erq->flags = IW_ENCODE_DISABLED;
1759 else if ((kid > 0) && (kid <=4))
1762 erq->flags = kid ; /* NB: base 1 */
1763 if (erq->length > pAdapter->SharedKey[BSS0][kid-1].KeyLen)
1764 erq->length = pAdapter->SharedKey[BSS0][kid-1].KeyLen;
1765 memcpy(key, pAdapter->SharedKey[BSS0][kid-1].Key, erq->length);
1766 //if ((kid == pAdapter->PortCfg.DefaultKeyId))
1767 //erq->flags |= IW_ENCODE_ENABLED; /* XXX */
1768 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1769 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1771 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1776 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1777 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1779 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1780 erq->length = pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen;
1781 memcpy(key, pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key, erq->length);
1782 // copy default key ID
1783 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1784 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1786 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1787 erq->flags = pAdapter->StaCfg.DefaultKeyId + 1; /* NB: base 1 */
1788 erq->flags |= IW_ENCODE_ENABLED; /* XXX */
1796 rt_ioctl_setparam(struct net_device *dev, struct iw_request_info *info,
1797 void *w, char *extra)
1799 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1800 PRTMP_ADAPTER pAdapter;
1802 char *this_char = extra;
1806 if (dev->priv_flags == INT_MAIN)
1808 pAdapter = dev->ml_priv;
1812 pVirtualAd = dev->ml_priv;
1813 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1815 pObj = (POS_COOKIE) pAdapter->OS_Cookie;
1817 if (pAdapter == NULL)
1819 /* if 1st open fail, pAd will be free;
1820 So the net_dev->ml_priv will be NULL in 2rd open */
1825 pObj->ioctl_if_type = INT_MAIN;
1826 pObj->ioctl_if = MAIN_MBSSID;
1829 //check if the interface is down
1830 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1832 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1839 if ((value = rtstrchr(this_char, '=')) != NULL)
1845 // reject setting nothing besides ANY ssid(ssidLen=0)
1846 if (!*value && (strcmp(this_char, "SSID") != 0))
1849 for (PRTMP_PRIVATE_SET_PROC = RTMP_PRIVATE_SUPPORT_PROC; PRTMP_PRIVATE_SET_PROC->name; PRTMP_PRIVATE_SET_PROC++)
1851 if (strcmp(this_char, PRTMP_PRIVATE_SET_PROC->name) == 0)
1853 if(!PRTMP_PRIVATE_SET_PROC->set_proc(pAdapter, value))
1854 { //FALSE:Set private failed then return Invalid argument
1857 break; //Exit for loop.
1861 if(PRTMP_PRIVATE_SET_PROC->name == NULL)
1862 { //Not found argument
1864 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_setparam:: (iwpriv) Not Support Set Command [%s=%s]\n", this_char, value));
1872 rt_private_get_statistics(struct net_device *dev, struct iw_request_info *info,
1873 struct iw_point *wrq, char *extra)
1876 PRTMP_ADAPTER pAd = dev->ml_priv;
1884 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
1885 sprintf(extra, "\n\n");
1890 sprintf(extra+strlen(extra), "Tx success = %ld\n", (ULONG)pAd->ate.TxDoneCount);
1891 //sprintf(extra+strlen(extra), "Tx success without retry = %ld\n", (ULONG)pAd->ate.TxDoneCount);
1894 #endif // RALINK_ATE //
1896 sprintf(extra+strlen(extra), "Tx success = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart);
1897 sprintf(extra+strlen(extra), "Tx success without retry = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart - (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
1899 sprintf(extra+strlen(extra), "Tx success after retry = %ld\n", (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
1900 sprintf(extra+strlen(extra), "Tx fail to Rcv ACK after retry = %ld\n", (ULONG)pAd->WlanCounters.FailedCount.QuadPart);
1901 sprintf(extra+strlen(extra), "RTS Success Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSSuccessCount.QuadPart);
1902 sprintf(extra+strlen(extra), "RTS Fail Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSFailureCount.QuadPart);
1904 sprintf(extra+strlen(extra), "Rx success = %ld\n", (ULONG)pAd->WlanCounters.ReceivedFragmentCount.QuadPart);
1905 sprintf(extra+strlen(extra), "Rx with CRC = %ld\n", (ULONG)pAd->WlanCounters.FCSErrorCount.QuadPart);
1906 sprintf(extra+strlen(extra), "Rx drop due to out of resource = %ld\n", (ULONG)pAd->Counters8023.RxNoBuffer);
1907 sprintf(extra+strlen(extra), "Rx duplicate frame = %ld\n", (ULONG)pAd->WlanCounters.FrameDuplicateCount.QuadPart);
1909 sprintf(extra+strlen(extra), "False CCA (one second) = %ld\n", (ULONG)pAd->RalinkCounters.OneSecFalseCCACnt);
1913 if (pAd->ate.RxAntennaSel == 0)
1915 sprintf(extra+strlen(extra), "RSSI-A = %ld\n", (LONG)(pAd->ate.LastRssi0 - pAd->BbpRssiToDbmDelta));
1916 sprintf(extra+strlen(extra), "RSSI-B (if available) = %ld\n", (LONG)(pAd->ate.LastRssi1 - pAd->BbpRssiToDbmDelta));
1917 sprintf(extra+strlen(extra), "RSSI-C (if available) = %ld\n\n", (LONG)(pAd->ate.LastRssi2 - pAd->BbpRssiToDbmDelta));
1921 sprintf(extra+strlen(extra), "RSSI = %ld\n", (LONG)(pAd->ate.LastRssi0 - pAd->BbpRssiToDbmDelta));
1925 #endif // RALINK_ATE //
1927 sprintf(extra+strlen(extra), "RSSI-A = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi0 - pAd->BbpRssiToDbmDelta));
1928 sprintf(extra+strlen(extra), "RSSI-B (if available) = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi1 - pAd->BbpRssiToDbmDelta));
1929 sprintf(extra+strlen(extra), "RSSI-C (if available) = %ld\n\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi2 - pAd->BbpRssiToDbmDelta));
1931 #ifdef WPA_SUPPLICANT_SUPPORT
1932 sprintf(extra+strlen(extra), "WpaSupplicantUP = %d\n\n", pAd->StaCfg.WpaSupplicantUP);
1933 #endif // WPA_SUPPLICANT_SUPPORT //
1936 wrq->length = strlen(extra) + 1; // 1: size of '\0'
1937 DBGPRINT(RT_DEBUG_TRACE, ("<== rt_private_get_statistics, wrq->length = %d\n", wrq->length));
1942 #ifdef DOT11_N_SUPPORT
1944 IN PRTMP_ADAPTER pAd,
1948 BA_ORI_ENTRY *pOriBAEntry;
1949 BA_REC_ENTRY *pRecBAEntry;
1951 for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
1953 PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
1954 if (((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
1955 || (pEntry->ValidAsWDS) || (pEntry->ValidAsMesh))
1957 sprintf(pOutBuf, "%s\n%02X:%02X:%02X:%02X:%02X:%02X (Aid = %d) (AP) -\n",
1959 pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
1960 pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5], pEntry->Aid);
1962 sprintf(pOutBuf, "%s[Recipient]\n", pOutBuf);
1963 for (j=0; j < NUM_OF_TID; j++)
1965 if (pEntry->BARecWcidArray[j] != 0)
1967 pRecBAEntry =&pAd->BATable.BARecEntry[pEntry->BARecWcidArray[j]];
1968 sprintf(pOutBuf, "%sTID=%d, BAWinSize=%d, LastIndSeq=%d, ReorderingPkts=%d\n", pOutBuf, j, pRecBAEntry->BAWinSize, pRecBAEntry->LastIndSeq, pRecBAEntry->list.qlen);
1971 sprintf(pOutBuf, "%s\n", pOutBuf);
1973 sprintf(pOutBuf, "%s[Originator]\n", pOutBuf);
1974 for (j=0; j < NUM_OF_TID; j++)
1976 if (pEntry->BAOriWcidArray[j] != 0)
1978 pOriBAEntry =&pAd->BATable.BAOriEntry[pEntry->BAOriWcidArray[j]];
1979 sprintf(pOutBuf, "%sTID=%d, BAWinSize=%d, StartSeq=%d, CurTxSeq=%d\n", pOutBuf, j, pOriBAEntry->BAWinSize, pOriBAEntry->Sequence, pEntry->TxSeq[j]);
1982 sprintf(pOutBuf, "%s\n\n", pOutBuf);
1984 if (strlen(pOutBuf) > (IW_PRIV_SIZE_MASK - 30))
1990 #endif // DOT11_N_SUPPORT //
1993 rt_private_show(struct net_device *dev, struct iw_request_info *info,
1994 struct iw_point *wrq, char *extra)
1997 VIRTUAL_ADAPTER *pVirtualAd = NULL;
2000 u32 subcmd = wrq->flags;
2002 if (dev->priv_flags == INT_MAIN)
2006 pVirtualAd = dev->ml_priv;
2007 pAd = pVirtualAd->RtmpDev->ml_priv;
2009 pObj = (POS_COOKIE) pAd->OS_Cookie;
2013 /* if 1st open fail, pAd will be free;
2014 So the net_dev->ml_priv will be NULL in 2rd open */
2023 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2026 pObj->ioctl_if_type = INT_MAIN;
2027 pObj->ioctl_if = MAIN_MBSSID;
2033 case SHOW_CONN_STATUS:
2034 if (MONITOR_ON(pAd))
2036 #ifdef DOT11_N_SUPPORT
2037 if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
2038 pAd->CommonCfg.RegTransmitSetting.field.BW)
2039 sprintf(extra, "Monitor Mode(CentralChannel %d)\n", pAd->CommonCfg.CentralChannel);
2041 #endif // DOT11_N_SUPPORT //
2042 sprintf(extra, "Monitor Mode(Channel %d)\n", pAd->CommonCfg.Channel);
2046 if (pAd->IndicateMediaState == NdisMediaStateConnected)
2050 sprintf(extra, "Connected(AP: %s[%02X:%02X:%02X:%02X:%02X:%02X])\n",
2051 pAd->CommonCfg.Ssid,
2052 pAd->CommonCfg.Bssid[0],
2053 pAd->CommonCfg.Bssid[1],
2054 pAd->CommonCfg.Bssid[2],
2055 pAd->CommonCfg.Bssid[3],
2056 pAd->CommonCfg.Bssid[4],
2057 pAd->CommonCfg.Bssid[5]);
2058 DBGPRINT(RT_DEBUG_TRACE ,("Ssid=%s ,Ssidlen = %d\n",pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen));
2060 else if (ADHOC_ON(pAd))
2061 sprintf(extra, "Connected\n");
2065 sprintf(extra, "Disconnected\n");
2066 DBGPRINT(RT_DEBUG_TRACE ,("ConnStatus is not connected\n"));
2069 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2071 case SHOW_DRVIER_VERION:
2072 sprintf(extra, "Driver version-%s, %s %s\n", STA_DRIVER_VERSION, __DATE__, __TIME__ );
2073 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2075 #ifdef DOT11_N_SUPPORT
2077 getBaInfo(pAd, extra);
2078 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2080 #endif // DOT11_N_SUPPORT //
2081 case SHOW_DESC_INFO:
2083 Show_DescInfo_Proc(pAd, NULL);
2084 wrq->length = 0; // 1: size of '\0'
2088 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
2090 sprintf(extra, "Scanning\n");
2091 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2094 pAd->StaCfg.bSwRadio = FALSE;
2095 if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
2097 pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
2098 if (pAd->StaCfg.bRadio == FALSE)
2101 // Update extra information
2102 pAd->ExtraInfo = SW_RADIO_OFF;
2105 sprintf(extra, "Radio Off\n");
2106 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2109 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
2111 sprintf(extra, "Scanning\n");
2112 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2115 pAd->StaCfg.bSwRadio = TRUE;
2116 //if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
2118 pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
2119 if (pAd->StaCfg.bRadio == TRUE)
2122 // Update extra information
2123 pAd->ExtraInfo = EXTRA_INFO_CLEAR;
2126 sprintf(extra, "Radio On\n");
2127 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2131 #ifdef QOS_DLS_SUPPORT
2132 case SHOW_DLS_ENTRY_INFO:
2134 Set_DlsEntryInfo_Display_Proc(pAd, NULL);
2135 wrq->length = 0; // 1: size of '\0'
2138 #endif // QOS_DLS_SUPPORT //
2140 case SHOW_CFG_VALUE:
2142 Status = RTMPShowCfgValue(pAd, wrq->pointer, extra);
2144 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2148 DBGPRINT(RT_DEBUG_TRACE, ("%s - unknow subcmd = %d\n", __func__, subcmd));
2156 int rt_ioctl_siwmlme(struct net_device *dev,
2157 struct iw_request_info *info,
2158 union iwreq_data *wrqu,
2161 PRTMP_ADAPTER pAd = dev->ml_priv;
2162 struct iw_mlme *pMlme = (struct iw_mlme *)wrqu->data.pointer;
2163 MLME_QUEUE_ELEM MsgElem;
2164 MLME_DISASSOC_REQ_STRUCT DisAssocReq;
2165 MLME_DEAUTH_REQ_STRUCT DeAuthReq;
2167 DBGPRINT(RT_DEBUG_TRACE, ("====> %s\n", __func__));
2174 #ifdef IW_MLME_DEAUTH
2175 case IW_MLME_DEAUTH:
2176 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DEAUTH\n", __func__));
2177 COPY_MAC_ADDR(DeAuthReq.Addr, pAd->CommonCfg.Bssid);
2178 DeAuthReq.Reason = pMlme->reason_code;
2179 MsgElem.MsgLen = sizeof(MLME_DEAUTH_REQ_STRUCT);
2180 NdisMoveMemory(MsgElem.Msg, &DeAuthReq, sizeof(MLME_DEAUTH_REQ_STRUCT));
2181 MlmeDeauthReqAction(pAd, &MsgElem);
2184 LinkDown(pAd, FALSE);
2185 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
2188 #endif // IW_MLME_DEAUTH //
2189 #ifdef IW_MLME_DISASSOC
2190 case IW_MLME_DISASSOC:
2191 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DISASSOC\n", __func__));
2192 COPY_MAC_ADDR(DisAssocReq.Addr, pAd->CommonCfg.Bssid);
2193 DisAssocReq.Reason = pMlme->reason_code;
2195 MsgElem.Machine = ASSOC_STATE_MACHINE;
2196 MsgElem.MsgType = MT2_MLME_DISASSOC_REQ;
2197 MsgElem.MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
2198 NdisMoveMemory(MsgElem.Msg, &DisAssocReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
2200 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
2201 MlmeDisassocReqAction(pAd, &MsgElem);
2203 #endif // IW_MLME_DISASSOC //
2205 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - Unknow Command\n", __func__));
2211 #endif // SIOCSIWMLME //
2213 #if WIRELESS_EXT > 17
2214 int rt_ioctl_siwauth(struct net_device *dev,
2215 struct iw_request_info *info,
2216 union iwreq_data *wrqu, char *extra)
2218 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2219 struct iw_param *param = &wrqu->param;
2221 //check if the interface is down
2222 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2224 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2227 switch (param->flags & IW_AUTH_INDEX) {
2228 case IW_AUTH_WPA_VERSION:
2229 if (param->value == IW_AUTH_WPA_VERSION_WPA)
2231 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
2232 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
2233 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
2235 else if (param->value == IW_AUTH_WPA_VERSION_WPA2)
2236 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
2238 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __func__, param->value));
2240 case IW_AUTH_CIPHER_PAIRWISE:
2241 if (param->value == IW_AUTH_CIPHER_NONE)
2243 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
2244 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2245 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
2247 else if (param->value == IW_AUTH_CIPHER_WEP40 ||
2248 param->value == IW_AUTH_CIPHER_WEP104)
2250 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
2251 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2252 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
2253 #ifdef WPA_SUPPLICANT_SUPPORT
2254 pAdapter->StaCfg.IEEE8021X = FALSE;
2255 #endif // WPA_SUPPLICANT_SUPPORT //
2257 else if (param->value == IW_AUTH_CIPHER_TKIP)
2259 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
2260 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2261 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
2263 else if (param->value == IW_AUTH_CIPHER_CCMP)
2265 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
2266 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2267 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
2269 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_PAIRWISE - param->value = %d!\n", __func__, param->value));
2271 case IW_AUTH_CIPHER_GROUP:
2272 if (param->value == IW_AUTH_CIPHER_NONE)
2274 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
2276 else if (param->value == IW_AUTH_CIPHER_WEP40 ||
2277 param->value == IW_AUTH_CIPHER_WEP104)
2279 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
2281 else if (param->value == IW_AUTH_CIPHER_TKIP)
2283 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
2285 else if (param->value == IW_AUTH_CIPHER_CCMP)
2287 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
2289 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_GROUP - param->value = %d!\n", __func__, param->value));
2291 case IW_AUTH_KEY_MGMT:
2292 if (param->value == IW_AUTH_KEY_MGMT_802_1X)
2294 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)
2296 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
2297 #ifdef WPA_SUPPLICANT_SUPPORT
2298 pAdapter->StaCfg.IEEE8021X = FALSE;
2299 #endif // WPA_SUPPLICANT_SUPPORT //
2301 else if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
2303 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
2304 #ifdef WPA_SUPPLICANT_SUPPORT
2305 pAdapter->StaCfg.IEEE8021X = FALSE;
2306 #endif // WPA_SUPPLICANT_SUPPORT //
2308 #ifdef WPA_SUPPLICANT_SUPPORT
2311 pAdapter->StaCfg.IEEE8021X = TRUE;
2312 #endif // WPA_SUPPLICANT_SUPPORT //
2314 else if (param->value == 0)
2316 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2317 STA_PORT_SECURED(pAdapter);
2319 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_KEY_MGMT - param->value = %d!\n", __func__, param->value));
2321 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
2323 case IW_AUTH_PRIVACY_INVOKED:
2324 /*if (param->value == 0)
2326 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
2327 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
2328 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2329 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
2330 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
2332 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_PRIVACY_INVOKED - param->value = %d!\n", __func__, param->value));
2334 case IW_AUTH_DROP_UNENCRYPTED:
2335 if (param->value != 0)
2336 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
2339 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2340 STA_PORT_SECURED(pAdapter);
2342 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __func__, param->value));
2344 case IW_AUTH_80211_AUTH_ALG:
2345 if (param->value & IW_AUTH_ALG_SHARED_KEY)
2347 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
2349 else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
2351 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
2355 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_80211_AUTH_ALG - param->value = %d!\n", __func__, param->value));
2357 case IW_AUTH_WPA_ENABLED:
2358 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_ENABLED - Driver supports WPA!(param->value = %d)\n", __func__, param->value));
2367 int rt_ioctl_giwauth(struct net_device *dev,
2368 struct iw_request_info *info,
2369 union iwreq_data *wrqu, char *extra)
2371 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2372 struct iw_param *param = &wrqu->param;
2374 //check if the interface is down
2375 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2377 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2381 switch (param->flags & IW_AUTH_INDEX) {
2382 case IW_AUTH_DROP_UNENCRYPTED:
2383 param->value = (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled) ? 0 : 1;
2386 case IW_AUTH_80211_AUTH_ALG:
2387 param->value = (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared) ? IW_AUTH_ALG_SHARED_KEY : IW_AUTH_ALG_OPEN_SYSTEM;
2390 case IW_AUTH_WPA_ENABLED:
2391 param->value = (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) ? 1 : 0;
2397 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_giwauth::param->value = %d!\n", param->value));
2401 void fnSetCipherKey(
2402 IN PRTMP_ADAPTER pAdapter,
2406 IN struct iw_encode_ext *ext)
2408 NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
2409 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = LEN_TKIP_EK;
2410 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, LEN_TKIP_EK);
2411 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].TxMic, ext->key + LEN_TKIP_EK, LEN_TKIP_TXMICK);
2412 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].RxMic, ext->key + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
2413 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CipherAlg;
2415 // Update group key information to ASIC Shared Key Table
2416 AsicAddSharedKeyEntry(pAdapter,
2419 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2420 pAdapter->SharedKey[BSS0][keyIdx].Key,
2421 pAdapter->SharedKey[BSS0][keyIdx].TxMic,
2422 pAdapter->SharedKey[BSS0][keyIdx].RxMic);
2425 // Update ASIC WCID attribute table and IVEIV table
2426 RTMPAddWcidAttributeEntry(pAdapter,
2429 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2432 // Update ASIC WCID attribute table and IVEIV table
2433 RTMPAddWcidAttributeEntry(pAdapter,
2436 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2437 &pAdapter->MacTab.Content[BSSID_WCID]);
2440 int rt_ioctl_siwencodeext(struct net_device *dev,
2441 struct iw_request_info *info,
2442 union iwreq_data *wrqu,
2445 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2446 struct iw_point *encoding = &wrqu->encoding;
2447 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2448 int keyIdx, alg = ext->alg;
2450 //check if the interface is down
2451 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2453 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2457 if (encoding->flags & IW_ENCODE_DISABLED)
2459 keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
2460 // set BSSID wcid entry of the Pair-wise Key table as no-security mode
2461 AsicRemovePairwiseKeyEntry(pAdapter, BSS0, BSSID_WCID);
2462 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
2463 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_NONE;
2464 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)keyIdx);
2465 NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
2466 DBGPRINT(RT_DEBUG_TRACE, ("%s::Remove all keys!(encoding->flags = %x)\n", __func__, encoding->flags));
2470 // Get Key Index and convet to our own defined key index
2471 keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
2472 if((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
2475 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2477 pAdapter->StaCfg.DefaultKeyId = keyIdx;
2478 DBGPRINT(RT_DEBUG_TRACE, ("%s::DefaultKeyId = %d\n", __func__, pAdapter->StaCfg.DefaultKeyId));
2482 case IW_ENCODE_ALG_NONE:
2483 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_NONE\n", __func__));
2485 case IW_ENCODE_ALG_WEP:
2486 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_WEP - ext->key_len = %d, keyIdx = %d\n", __func__, ext->key_len, keyIdx));
2487 if (ext->key_len == MAX_WEP_KEY_SIZE)
2489 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
2490 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
2492 else if (ext->key_len == MIN_WEP_KEY_SIZE)
2494 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
2495 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
2500 NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
2501 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, ext->key_len);
2503 case IW_ENCODE_ALG_TKIP:
2504 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_TKIP - keyIdx = %d, ext->key_len = %d\n", __func__, keyIdx, ext->key_len));
2505 if (ext->key_len == 32)
2507 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2509 fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, FALSE, ext);
2510 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
2512 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2513 STA_PORT_SECURED(pAdapter);
2516 else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
2518 fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, TRUE, ext);
2520 // set 802.1x port control
2521 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2522 STA_PORT_SECURED(pAdapter);
2528 case IW_ENCODE_ALG_CCMP:
2529 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2531 fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, FALSE, ext);
2532 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
2533 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2534 STA_PORT_SECURED(pAdapter);
2536 else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
2538 fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, TRUE, ext);
2540 // set 802.1x port control
2541 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2542 STA_PORT_SECURED(pAdapter);
2554 rt_ioctl_giwencodeext(struct net_device *dev,
2555 struct iw_request_info *info,
2556 union iwreq_data *wrqu, char *extra)
2558 PRTMP_ADAPTER pAd = dev->ml_priv;
2560 struct iw_point *encoding = &wrqu->encoding;
2561 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2562 int idx, max_key_len;
2564 DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_giwencodeext\n"));
2566 max_key_len = encoding->length - sizeof(*ext);
2567 if (max_key_len < 0)
2570 idx = encoding->flags & IW_ENCODE_INDEX;
2573 if (idx < 1 || idx > 4)
2577 if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
2578 (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled))
2580 if (idx != pAd->StaCfg.DefaultKeyId)
2588 idx = pAd->StaCfg.DefaultKeyId;
2590 encoding->flags = idx + 1;
2591 memset(ext, 0, sizeof(*ext));
2594 switch(pAd->StaCfg.WepStatus) {
2595 case Ndis802_11WEPDisabled:
2596 ext->alg = IW_ENCODE_ALG_NONE;
2597 encoding->flags |= IW_ENCODE_DISABLED;
2599 case Ndis802_11WEPEnabled:
2600 ext->alg = IW_ENCODE_ALG_WEP;
2601 if (pAd->SharedKey[BSS0][idx].KeyLen > max_key_len)
2605 ext->key_len = pAd->SharedKey[BSS0][idx].KeyLen;
2606 pKey = &(pAd->SharedKey[BSS0][idx].Key[0]);
2609 case Ndis802_11Encryption2Enabled:
2610 case Ndis802_11Encryption3Enabled:
2611 if (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
2612 ext->alg = IW_ENCODE_ALG_TKIP;
2614 ext->alg = IW_ENCODE_ALG_CCMP;
2616 if (max_key_len < 32)
2621 pKey = &pAd->StaCfg.PMK[0];
2628 if (ext->key_len && pKey)
2630 encoding->flags |= IW_ENCODE_ENABLED;
2631 memcpy(ext->key, pKey, ext->key_len);
2638 int rt_ioctl_siwgenie(struct net_device *dev,
2639 struct iw_request_info *info,
2640 union iwreq_data *wrqu, char *extra)
2642 PRTMP_ADAPTER pAd = dev->ml_priv;
2644 if (wrqu->data.length > MAX_LEN_OF_RSNIE ||
2645 (wrqu->data.length && extra == NULL))
2648 if (wrqu->data.length)
2650 pAd->StaCfg.RSNIE_Len = wrqu->data.length;
2651 NdisMoveMemory(&pAd->StaCfg.RSN_IE[0], extra, pAd->StaCfg.RSNIE_Len);
2655 pAd->StaCfg.RSNIE_Len = 0;
2656 NdisZeroMemory(&pAd->StaCfg.RSN_IE[0], MAX_LEN_OF_RSNIE);
2661 #endif // SIOCSIWGENIE //
2663 int rt_ioctl_giwgenie(struct net_device *dev,
2664 struct iw_request_info *info,
2665 union iwreq_data *wrqu, char *extra)
2667 PRTMP_ADAPTER pAd = dev->ml_priv;
2669 if ((pAd->StaCfg.RSNIE_Len == 0) ||
2670 (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA))
2672 wrqu->data.length = 0;
2676 #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
2678 if (pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
2680 if (wrqu->data.length < pAd->StaCfg.RSNIE_Len)
2683 wrqu->data.length = pAd->StaCfg.RSNIE_Len;
2684 memcpy(extra, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
2687 #endif // SIOCSIWGENIE //
2688 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
2690 UCHAR RSNIe = IE_WPA;
2692 if (wrqu->data.length < (pAd->StaCfg.RSNIE_Len + 2)) // ID, Len
2694 wrqu->data.length = pAd->StaCfg.RSNIE_Len + 2;
2696 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
2697 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2))
2700 extra[0] = (char)RSNIe;
2701 extra[1] = pAd->StaCfg.RSNIE_Len;
2702 memcpy(extra+2, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
2708 int rt_ioctl_siwpmksa(struct net_device *dev,
2709 struct iw_request_info *info,
2710 union iwreq_data *wrqu,
2713 PRTMP_ADAPTER pAd = dev->ml_priv;
2714 struct iw_pmksa *pPmksa = (struct iw_pmksa *)wrqu->data.pointer;
2715 INT CachedIdx = 0, idx = 0;
2720 DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_siwpmksa\n"));
2723 case IW_PMKSA_FLUSH:
2724 NdisZeroMemory(pAd->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
2725 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_FLUSH\n"));
2727 case IW_PMKSA_REMOVE:
2728 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
2730 // compare the BSSID
2731 if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
2733 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN);
2734 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].PMKID, 16);
2735 for (idx = CachedIdx; idx < (pAd->StaCfg.SavedPMKNum - 1); idx++)
2737 NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].BSSID[0], &pAd->StaCfg.SavedPMK[idx+1].BSSID[0], MAC_ADDR_LEN);
2738 NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].PMKID[0], &pAd->StaCfg.SavedPMK[idx+1].PMKID[0], 16);
2740 pAd->StaCfg.SavedPMKNum--;
2745 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_REMOVE\n"));
2748 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
2750 // compare the BSSID
2751 if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
2755 // Found, replace it
2756 if (CachedIdx < PMKID_NO)
2758 DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
2759 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
2760 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
2761 pAd->StaCfg.SavedPMKNum++;
2763 // Not found, replace the last one
2766 // Randomly replace one
2767 CachedIdx = (pPmksa->bssid.sa_data[5] % PMKID_NO);
2768 DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
2769 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
2770 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
2773 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_ADD\n"));
2776 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - Unknow Command!!\n"));
2782 #endif // #if WIRELESS_EXT > 17
2786 rt_private_ioctl_bbp(struct net_device *dev, struct iw_request_info *info,
2787 struct iw_point *wrq, char *extra)
2792 // CHAR arg[255]={0};
2795 BOOLEAN bIsPrintAllBBP = FALSE;
2797 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2800 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2802 if (wrq->length > 1) //No parameters.
2804 sprintf(extra, "\n");
2806 //Parsing Read or Write
2807 this_char = wrq->pointer;
2808 DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s\n", this_char));
2812 if ((value = rtstrchr(this_char, '=')) != NULL)
2815 if (!value || !*value)
2817 DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s, value=%s\n", this_char, value));
2818 if (sscanf(this_char, "%d", &(bbpId)) == 1)
2824 if (bbpId <= 138) // edit by johnli, RF power sequence setup, add BBP R138 for ADC dynamic on/off control
2828 if (ATE_ON(pAdapter))
2830 ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
2833 #endif // RALINK_ATE //
2835 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
2837 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
2838 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2839 DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
2842 {//Invalid parametes, so default printk all bbp
2843 bIsPrintAllBBP = TRUE;
2848 { //Invalid parametes, so default printk all bbp
2849 bIsPrintAllBBP = TRUE;
2855 if ((sscanf(this_char, "%d", &(bbpId)) == 1) && (sscanf(value, "%x", &(bbpValue)) == 1))
2861 if (bbpId <= 138) // edit by johnli, RF power sequence setup, add BBP R138 for ADC dynamic on/off control
2865 if (ATE_ON(pAdapter))
2867 ATE_BBP_IO_WRITE8_BY_REG_ID(pAdapter, bbpId, bbpValue);
2868 //Read it back for showing
2869 ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
2872 #endif // RALINK_ATE //
2874 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, bbpId, bbpValue);
2875 //Read it back for showing
2876 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
2878 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
2879 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2880 DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
2883 {//Invalid parametes, so default printk all bbp
2884 bIsPrintAllBBP = TRUE;
2889 { //Invalid parametes, so default printk all bbp
2890 bIsPrintAllBBP = TRUE;
2896 bIsPrintAllBBP = TRUE;
2901 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2902 sprintf(extra, "\n");
2904 for (bbpId = 0; bbpId <= 136; bbpId++)
2907 for (bbpId = 0; bbpId <= 138; bbpId++) // edit by johnli, RF power sequence setup, add BBP R138 for ADC dynamic on/off control
2910 if (strlen(extra) >= (IW_PRIV_SIZE_MASK - 10))
2913 if (ATE_ON(pAdapter))
2915 ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
2918 #endif // RALINK_ATE //
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");
2925 sprintf(extra+strlen(extra), "%03d = %02X\n", bbpId, regBBP); // edit by johnli, change display format
2928 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2929 DBGPRINT(RT_DEBUG_TRACE, ("wrq->length = %d\n", wrq->length));
2932 DBGPRINT(RT_DEBUG_TRACE, ("<==rt_private_ioctl_bbp\n\n"));
2938 int rt_ioctl_siwrate(struct net_device *dev,
2939 struct iw_request_info *info,
2940 union iwreq_data *wrqu, char *extra)
2942 PRTMP_ADAPTER pAd = dev->ml_priv;
2943 UINT32 rate = wrqu->bitrate.value, fixed = wrqu->bitrate.fixed;
2945 //check if the interface is down
2946 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2948 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::Network is down!\n"));
2952 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(rate = %d, fixed = %d)\n", rate, fixed));
2953 /* rate = -1 => auto rate
2954 rate = X, fixed = 1 => (fixed rate X)
2959 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
2960 pAd->StaCfg.bAutoTxRateSwitch = TRUE;
2961 if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
2962 (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
2963 RTMPSetDesiredRates(pAd, -1);
2965 #ifdef DOT11_N_SUPPORT
2967 #endif // DOT11_N_SUPPORT //
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;
2980 #ifdef DOT11_N_SUPPORT
2982 #endif // DOT11_N_SUPPORT //
2984 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(HtMcs=%d)\n",pAd->StaCfg.DesiredTransmitSetting.field.MCS));
2988 // TODO: rate = X, fixed = 0 => (rates <= X)
2996 int rt_ioctl_giwrate(struct net_device *dev,
2997 struct iw_request_info *info,
2998 union iwreq_data *wrqu, char *extra)
3000 PRTMP_ADAPTER pAd = dev->ml_priv;
3001 int rate_index = 0, rate_count = 0;
3002 HTTRANSMIT_SETTING ht_setting;
3003 __s32 ralinkrate[] =
3004 {2, 4, 11, 22, // CCK
3005 12, 18, 24, 36, 48, 72, 96, 108, // OFDM
3006 13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260, // 20MHz, 800ns GI, MCS: 0 ~ 15
3007 39, 78, 117, 156, 234, 312, 351, 390, // 20MHz, 800ns GI, MCS: 16 ~ 23
3008 27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540, // 40MHz, 800ns GI, MCS: 0 ~ 15
3009 81, 162, 243, 324, 486, 648, 729, 810, // 40MHz, 800ns GI, MCS: 16 ~ 23
3010 14, 29, 43, 57, 87, 115, 130, 144, 29, 59, 87, 115, 173, 230, 260, 288, // 20MHz, 400ns GI, MCS: 0 ~ 15
3011 43, 87, 130, 173, 260, 317, 390, 433, // 20MHz, 400ns GI, MCS: 16 ~ 23
3012 30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600, // 40MHz, 400ns GI, MCS: 0 ~ 15
3013 90, 180, 270, 360, 540, 720, 810, 900}; // 40MHz, 400ns GI, MCS: 16 ~ 23
3015 rate_count = sizeof(ralinkrate)/sizeof(__s32);
3016 //check if the interface is down
3017 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
3019 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
3023 if ((pAd->StaCfg.bAutoTxRateSwitch == FALSE) &&
3025 ((pAd->CommonCfg.PhyMode <= PHY_11G) || (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM)))
3026 ht_setting.word = pAd->StaCfg.HTPhyMode.word;
3028 ht_setting.word = pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word;
3030 #ifdef DOT11_N_SUPPORT
3031 if (ht_setting.field.MODE >= MODE_HTMIX)
3033 // rate_index = 12 + ((UCHAR)ht_setting.field.BW *16) + ((UCHAR)ht_setting.field.ShortGI *32) + ((UCHAR)ht_setting.field.MCS);
3034 rate_index = 12 + ((UCHAR)ht_setting.field.BW *24) + ((UCHAR)ht_setting.field.ShortGI *48) + ((UCHAR)ht_setting.field.MCS);
3037 #endif // DOT11_N_SUPPORT //
3038 if (ht_setting.field.MODE == MODE_OFDM)
3039 rate_index = (UCHAR)(ht_setting.field.MCS) + 4;
3040 else if (ht_setting.field.MODE == MODE_CCK)
3041 rate_index = (UCHAR)(ht_setting.field.MCS);
3046 if (rate_index > rate_count)
3047 rate_index = rate_count;
3049 wrqu->bitrate.value = ralinkrate[rate_index] * 500000;
3050 wrqu->bitrate.disabled = 0;
3055 static const iw_handler rt_handler[] =
3057 (iw_handler) NULL, /* SIOCSIWCOMMIT */
3058 (iw_handler) rt_ioctl_giwname, /* SIOCGIWNAME */
3059 (iw_handler) NULL, /* SIOCSIWNWID */
3060 (iw_handler) NULL, /* SIOCGIWNWID */
3061 (iw_handler) rt_ioctl_siwfreq, /* SIOCSIWFREQ */
3062 (iw_handler) rt_ioctl_giwfreq, /* SIOCGIWFREQ */
3063 (iw_handler) rt_ioctl_siwmode, /* SIOCSIWMODE */
3064 (iw_handler) rt_ioctl_giwmode, /* SIOCGIWMODE */
3065 (iw_handler) NULL, /* SIOCSIWSENS */
3066 (iw_handler) NULL, /* SIOCGIWSENS */
3067 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
3068 (iw_handler) rt_ioctl_giwrange, /* SIOCGIWRANGE */
3069 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
3070 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
3071 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
3072 (iw_handler) rt28xx_get_wireless_stats /* kernel code */, /* SIOCGIWSTATS */
3073 (iw_handler) NULL, /* SIOCSIWSPY */
3074 (iw_handler) NULL, /* SIOCGIWSPY */
3075 (iw_handler) NULL, /* SIOCSIWTHRSPY */
3076 (iw_handler) NULL, /* SIOCGIWTHRSPY */
3077 (iw_handler) rt_ioctl_siwap, /* SIOCSIWAP */
3078 (iw_handler) rt_ioctl_giwap, /* SIOCGIWAP */
3080 (iw_handler) rt_ioctl_siwmlme, /* SIOCSIWMLME */
3082 (iw_handler) NULL, /* SIOCSIWMLME */
3083 #endif // SIOCSIWMLME //
3084 (iw_handler) rt_ioctl_iwaplist, /* SIOCGIWAPLIST */
3086 (iw_handler) rt_ioctl_siwscan, /* SIOCSIWSCAN */
3087 (iw_handler) rt_ioctl_giwscan, /* SIOCGIWSCAN */
3089 (iw_handler) NULL, /* SIOCSIWSCAN */
3090 (iw_handler) NULL, /* SIOCGIWSCAN */
3091 #endif /* SIOCGIWSCAN */
3092 (iw_handler) rt_ioctl_siwessid, /* SIOCSIWESSID */
3093 (iw_handler) rt_ioctl_giwessid, /* SIOCGIWESSID */
3094 (iw_handler) rt_ioctl_siwnickn, /* SIOCSIWNICKN */
3095 (iw_handler) rt_ioctl_giwnickn, /* SIOCGIWNICKN */
3096 (iw_handler) NULL, /* -- hole -- */
3097 (iw_handler) NULL, /* -- hole -- */
3098 (iw_handler) rt_ioctl_siwrate, /* SIOCSIWRATE */
3099 (iw_handler) rt_ioctl_giwrate, /* SIOCGIWRATE */
3100 (iw_handler) rt_ioctl_siwrts, /* SIOCSIWRTS */
3101 (iw_handler) rt_ioctl_giwrts, /* SIOCGIWRTS */
3102 (iw_handler) rt_ioctl_siwfrag, /* SIOCSIWFRAG */
3103 (iw_handler) rt_ioctl_giwfrag, /* SIOCGIWFRAG */
3104 (iw_handler) NULL, /* SIOCSIWTXPOW */
3105 (iw_handler) NULL, /* SIOCGIWTXPOW */
3106 (iw_handler) NULL, /* SIOCSIWRETRY */
3107 (iw_handler) NULL, /* SIOCGIWRETRY */
3108 (iw_handler) rt_ioctl_siwencode, /* SIOCSIWENCODE */
3109 (iw_handler) rt_ioctl_giwencode, /* SIOCGIWENCODE */
3110 (iw_handler) NULL, /* SIOCSIWPOWER */
3111 (iw_handler) NULL, /* SIOCGIWPOWER */
3112 (iw_handler) NULL, /* -- hole -- */
3113 (iw_handler) NULL, /* -- hole -- */
3114 #if WIRELESS_EXT > 17
3115 (iw_handler) rt_ioctl_siwgenie, /* SIOCSIWGENIE */
3116 (iw_handler) rt_ioctl_giwgenie, /* SIOCGIWGENIE */
3117 (iw_handler) rt_ioctl_siwauth, /* SIOCSIWAUTH */
3118 (iw_handler) rt_ioctl_giwauth, /* SIOCGIWAUTH */
3119 (iw_handler) rt_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
3120 (iw_handler) rt_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */
3121 (iw_handler) rt_ioctl_siwpmksa, /* SIOCSIWPMKSA */
3125 static const iw_handler rt_priv_handlers[] = {
3126 (iw_handler) NULL, /* + 0x00 */
3127 (iw_handler) NULL, /* + 0x01 */
3128 #ifndef CONFIG_AP_SUPPORT
3129 (iw_handler) rt_ioctl_setparam, /* + 0x02 */
3131 (iw_handler) NULL, /* + 0x02 */
3132 #endif // CONFIG_AP_SUPPORT //
3134 (iw_handler) rt_private_ioctl_bbp, /* + 0x03 */
3136 (iw_handler) NULL, /* + 0x03 */
3138 (iw_handler) NULL, /* + 0x04 */
3139 (iw_handler) NULL, /* + 0x05 */
3140 (iw_handler) NULL, /* + 0x06 */
3141 (iw_handler) NULL, /* + 0x07 */
3142 (iw_handler) NULL, /* + 0x08 */
3143 (iw_handler) rt_private_get_statistics, /* + 0x09 */
3144 (iw_handler) NULL, /* + 0x0A */
3145 (iw_handler) NULL, /* + 0x0B */
3146 (iw_handler) NULL, /* + 0x0C */
3147 (iw_handler) NULL, /* + 0x0D */
3148 (iw_handler) NULL, /* + 0x0E */
3149 (iw_handler) NULL, /* + 0x0F */
3150 (iw_handler) NULL, /* + 0x10 */
3151 (iw_handler) rt_private_show, /* + 0x11 */
3152 (iw_handler) NULL, /* + 0x12 */
3153 (iw_handler) NULL, /* + 0x13 */
3154 (iw_handler) NULL, /* + 0x15 */
3155 (iw_handler) NULL, /* + 0x17 */
3156 (iw_handler) NULL, /* + 0x18 */
3159 const struct iw_handler_def rt28xx_iw_handler_def =
3161 #define N(a) (sizeof (a) / sizeof (a[0]))
3162 .standard = (iw_handler *) rt_handler,
3163 .num_standard = sizeof(rt_handler) / sizeof(iw_handler),
3164 .private = (iw_handler *) rt_priv_handlers,
3165 .num_private = N(rt_priv_handlers),
3166 .private_args = (struct iw_priv_args *) privtab,
3167 .num_private_args = N(privtab),
3168 #if IW_HANDLER_VERSION >= 7
3169 .get_wireless_stats = rt28xx_get_wireless_stats,
3173 INT RTMPSetInformation(
3174 IN PRTMP_ADAPTER pAdapter,
3175 IN OUT struct ifreq *rq,
3178 struct iwreq *wrq = (struct iwreq *) rq;
3179 NDIS_802_11_SSID Ssid;
3180 NDIS_802_11_MAC_ADDRESS Bssid;
3181 RT_802_11_PHY_MODE PhyMode;
3182 RT_802_11_STA_CONFIG StaConfig;
3183 NDIS_802_11_RATES aryRates;
3184 RT_802_11_PREAMBLE Preamble;
3185 NDIS_802_11_WEP_STATUS WepStatus;
3186 NDIS_802_11_AUTHENTICATION_MODE AuthMode = Ndis802_11AuthModeMax;
3187 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
3188 NDIS_802_11_RTS_THRESHOLD RtsThresh;
3189 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
3190 NDIS_802_11_POWER_MODE PowerMode;
3191 PNDIS_802_11_KEY pKey = NULL;
3192 PNDIS_802_11_WEP pWepKey =NULL;
3193 PNDIS_802_11_REMOVE_KEY pRemoveKey = NULL;
3194 NDIS_802_11_CONFIGURATION Config, *pConfig = NULL;
3195 NDIS_802_11_NETWORK_TYPE NetType;
3198 INT Status = NDIS_STATUS_SUCCESS, MaxPhyMode = PHY_11G;
3201 BOOLEAN StateMachineTouched = FALSE;
3202 #ifdef DOT11_N_SUPPORT
3203 OID_SET_HT_PHYMODE HT_PhyMode; //11n ,kathy
3204 #endif // DOT11_N_SUPPORT //
3205 #ifdef WPA_SUPPLICANT_SUPPORT
3206 PNDIS_802_11_PMKID pPmkId = NULL;
3207 BOOLEAN IEEE8021xState = FALSE;
3208 BOOLEAN IEEE8021x_required_keys = FALSE;
3209 UCHAR wpa_supplicant_enable = 0;
3210 #endif // WPA_SUPPLICANT_SUPPORT //
3213 TX_RTY_CFG_STRUC tx_rty_cfg;
3214 ULONG ShortRetryLimit, LongRetryLimit;
3216 #endif // SNMP_SUPPORT //
3219 #ifdef DOT11_N_SUPPORT
3220 MaxPhyMode = PHY_11N_5G;
3221 #endif // DOT11_N_SUPPORT //
3224 DBGPRINT(RT_DEBUG_TRACE, ("-->RTMPSetInformation(), 0x%08x\n", cmd&0x7FFF));
3225 switch(cmd & 0x7FFF) {
3226 case RT_OID_802_11_COUNTRY_REGION:
3227 if (wrq->u.data.length < sizeof(UCHAR))
3229 // Only avaliable when EEPROM not programming
3230 else if (!(pAdapter->CommonCfg.CountryRegion & 0x80) && !(pAdapter->CommonCfg.CountryRegionForABand & 0x80))
3235 Status = copy_from_user(&Country, wrq->u.data.pointer, wrq->u.data.length);
3236 pAdapter->CommonCfg.CountryRegion = (UCHAR)(Country & 0x000000FF);
3237 pAdapter->CommonCfg.CountryRegionForABand = (UCHAR)((Country >> 8) & 0x000000FF);
3238 TmpPhy = pAdapter->CommonCfg.PhyMode;
3239 pAdapter->CommonCfg.PhyMode = 0xff;
3240 // Build all corresponding channel information
3241 RTMPSetPhyMode(pAdapter, TmpPhy);
3242 #ifdef DOT11_N_SUPPORT
3243 SetCommonHT(pAdapter);
3244 #endif // DOT11_N_SUPPORT //
3245 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_COUNTRY_REGION (A:%d B/G:%d)\n", pAdapter->CommonCfg.CountryRegionForABand,
3246 pAdapter->CommonCfg.CountryRegion));
3249 case OID_802_11_BSSID_LIST_SCAN:
3251 if (ATE_ON(pAdapter))
3253 DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
3256 #endif // RALINK_ATE //
3258 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID_LIST_SCAN, TxCnt = %d \n", pAdapter->RalinkCounters.LastOneSecTotalTxCount));
3260 if (MONITOR_ON(pAdapter))
3262 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
3266 //Benson add 20080527, when radio off, sta don't need to scan
3267 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_RADIO_OFF))
3270 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
3272 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is scanning now !!!\n"));
3273 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
3274 Status = NDIS_STATUS_SUCCESS;
3278 if (pAdapter->RalinkCounters.LastOneSecTotalTxCount > 100)
3280 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
3281 Status = NDIS_STATUS_SUCCESS;
3282 pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
3286 if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
3287 ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
3288 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
3289 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
3290 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)) &&
3291 (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
3293 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
3294 Status = NDIS_STATUS_SUCCESS;
3295 pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
3300 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3302 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3303 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3306 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
3307 // this request, because this request is initiated by NDIS.
3308 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
3309 // Reset allowed scan retries
3310 pAdapter->StaCfg.ScanCnt = 0;
3311 pAdapter->StaCfg.LastScanTime = Now;
3313 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
3314 RTMP_SET_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
3315 MlmeEnqueue(pAdapter,
3316 MLME_CNTL_STATE_MACHINE,
3317 OID_802_11_BSSID_LIST_SCAN,
3321 Status = NDIS_STATUS_SUCCESS;
3322 StateMachineTouched = TRUE;
3324 case OID_802_11_SSID:
3325 if (wrq->u.data.length != sizeof(NDIS_802_11_SSID))
3329 PCHAR pSsidString = NULL;
3330 Status = copy_from_user(&Ssid, wrq->u.data.pointer, wrq->u.data.length);
3332 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SSID (Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
3333 if (Ssid.SsidLength > MAX_LEN_OF_SSID)
3337 if (Ssid.SsidLength == 0)
3339 Set_SSID_Proc(pAdapter, "");
3343 pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
3346 NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
3347 NdisMoveMemory(pSsidString, Ssid.Ssid, Ssid.SsidLength);
3348 Set_SSID_Proc(pAdapter, pSsidString);
3357 case OID_802_11_BSSID:
3359 if (ATE_ON(pAdapter))
3361 DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
3364 #endif // RALINK_ATE //
3365 if (wrq->u.data.length != sizeof(NDIS_802_11_MAC_ADDRESS))
3369 Status = copy_from_user(&Bssid, wrq->u.data.pointer, wrq->u.data.length);
3371 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
3372 // this request, because this request is initiated by NDIS.
3373 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
3375 // Prevent to connect AP again in STAMlmePeriodicExec
3376 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
3378 // Reset allowed scan retries
3379 pAdapter->StaCfg.ScanCnt = 0;
3381 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3383 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3384 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3386 MlmeEnqueue(pAdapter,
3387 MLME_CNTL_STATE_MACHINE,
3389 sizeof(NDIS_802_11_MAC_ADDRESS),
3391 Status = NDIS_STATUS_SUCCESS;
3392 StateMachineTouched = TRUE;
3394 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID %02x:%02x:%02x:%02x:%02x:%02x\n",
3395 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
3398 case RT_OID_802_11_RADIO:
3399 if (wrq->u.data.length != sizeof(BOOLEAN))
3403 Status = copy_from_user(&RadioState, wrq->u.data.pointer, wrq->u.data.length);
3404 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RADIO (=%d)\n", RadioState));
3405 if (pAdapter->StaCfg.bSwRadio != RadioState)
3407 pAdapter->StaCfg.bSwRadio = RadioState;
3408 if (pAdapter->StaCfg.bRadio != (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio))
3410 pAdapter->StaCfg.bRadio = (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio);
3411 if (pAdapter->StaCfg.bRadio == TRUE)
3413 MlmeRadioOn(pAdapter);
3414 // Update extra information
3415 pAdapter->ExtraInfo = EXTRA_INFO_CLEAR;
3419 MlmeRadioOff(pAdapter);
3420 // Update extra information
3421 pAdapter->ExtraInfo = SW_RADIO_OFF;
3427 case RT_OID_802_11_PHY_MODE:
3428 if (wrq->u.data.length != sizeof(RT_802_11_PHY_MODE))
3432 Status = copy_from_user(&PhyMode, wrq->u.data.pointer, wrq->u.data.length);
3433 if (PhyMode <= MaxPhyMode)
3435 RTMPSetPhyMode(pAdapter, PhyMode);
3436 #ifdef DOT11_N_SUPPORT
3437 SetCommonHT(pAdapter);
3438 #endif // DOT11_N_SUPPORT //
3440 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PHY_MODE (=%d)\n", PhyMode));
3443 case RT_OID_802_11_STA_CONFIG:
3444 if (wrq->u.data.length != sizeof(RT_802_11_STA_CONFIG))
3448 Status = copy_from_user(&StaConfig, wrq->u.data.pointer, wrq->u.data.length);
3449 pAdapter->CommonCfg.bEnableTxBurst = StaConfig.EnableTxBurst;
3450 pAdapter->CommonCfg.UseBGProtection = StaConfig.UseBGProtection;
3451 pAdapter->CommonCfg.bUseShortSlotTime = 1; // 2003-10-30 always SHORT SLOT capable
3452 if ((pAdapter->CommonCfg.PhyMode != StaConfig.AdhocMode) &&
3453 (StaConfig.AdhocMode <= MaxPhyMode))
3455 // allow dynamic change of "USE OFDM rate or not" in ADHOC mode
3456 // if setting changed, need to reset current TX rate as well as BEACON frame format
3457 pAdapter->CommonCfg.PhyMode = StaConfig.AdhocMode;
3458 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
3460 RTMPSetPhyMode(pAdapter, PhyMode);
3461 MlmeUpdateTxRates(pAdapter, FALSE, 0);
3462 MakeIbssBeacon(pAdapter); // re-build BEACON frame
3463 AsicEnableIbssSync(pAdapter); // copy to on-chip memory
3466 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_STA_CONFIG (Burst=%d, Protection=%ld,ShortSlot=%d\n",
3467 pAdapter->CommonCfg.bEnableTxBurst,
3468 pAdapter->CommonCfg.UseBGProtection,
3469 pAdapter->CommonCfg.bUseShortSlotTime));
3472 case OID_802_11_DESIRED_RATES:
3473 if (wrq->u.data.length != sizeof(NDIS_802_11_RATES))
3477 Status = copy_from_user(&aryRates, wrq->u.data.pointer, wrq->u.data.length);
3478 NdisZeroMemory(pAdapter->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES);
3479 NdisMoveMemory(pAdapter->CommonCfg.DesireRate, &aryRates, sizeof(NDIS_802_11_RATES));
3480 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DESIRED_RATES (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
3481 pAdapter->CommonCfg.DesireRate[0],pAdapter->CommonCfg.DesireRate[1],
3482 pAdapter->CommonCfg.DesireRate[2],pAdapter->CommonCfg.DesireRate[3],
3483 pAdapter->CommonCfg.DesireRate[4],pAdapter->CommonCfg.DesireRate[5],
3484 pAdapter->CommonCfg.DesireRate[6],pAdapter->CommonCfg.DesireRate[7] ));
3485 // Changing DesiredRate may affect the MAX TX rate we used to TX frames out
3486 MlmeUpdateTxRates(pAdapter, FALSE, 0);
3489 case RT_OID_802_11_PREAMBLE:
3490 if (wrq->u.data.length != sizeof(RT_802_11_PREAMBLE))
3494 Status = copy_from_user(&Preamble, wrq->u.data.pointer, wrq->u.data.length);
3495 if (Preamble == Rt802_11PreambleShort)
3497 pAdapter->CommonCfg.TxPreamble = Preamble;
3498 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleShort);
3500 else if ((Preamble == Rt802_11PreambleLong) || (Preamble == Rt802_11PreambleAuto))
3502 // if user wants AUTO, initialize to LONG here, then change according to AP's
3503 // capability upon association.
3504 pAdapter->CommonCfg.TxPreamble = Preamble;
3505 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleLong);
3512 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PREAMBLE (=%d)\n", Preamble));
3515 case OID_802_11_WEP_STATUS:
3516 if (wrq->u.data.length != sizeof(NDIS_802_11_WEP_STATUS))
3520 Status = copy_from_user(&WepStatus, wrq->u.data.pointer, wrq->u.data.length);
3521 // Since TKIP, AES, WEP are all supported. It should not have any invalid setting
3522 if (WepStatus <= Ndis802_11Encryption3KeyAbsent)
3524 if (pAdapter->StaCfg.WepStatus != WepStatus)
3526 // Config has changed
3527 pAdapter->bConfigChanged = TRUE;
3529 pAdapter->StaCfg.WepStatus = WepStatus;
3530 pAdapter->StaCfg.OrigWepStatus = WepStatus;
3531 pAdapter->StaCfg.PairCipher = WepStatus;
3532 pAdapter->StaCfg.GroupCipher = WepStatus;
3539 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEP_STATUS (=%d)\n",WepStatus));
3542 case OID_802_11_AUTHENTICATION_MODE:
3543 if (wrq->u.data.length != sizeof(NDIS_802_11_AUTHENTICATION_MODE))
3547 Status = copy_from_user(&AuthMode, wrq->u.data.pointer, wrq->u.data.length);
3548 if (AuthMode > Ndis802_11AuthModeMax)
3555 if (pAdapter->StaCfg.AuthMode != AuthMode)
3557 // Config has changed
3558 pAdapter->bConfigChanged = TRUE;
3560 pAdapter->StaCfg.AuthMode = AuthMode;
3562 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
3563 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_AUTHENTICATION_MODE (=%d) \n",pAdapter->StaCfg.AuthMode));
3566 case OID_802_11_INFRASTRUCTURE_MODE:
3567 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_INFRASTRUCTURE))
3571 Status = copy_from_user(&BssType, wrq->u.data.pointer, wrq->u.data.length);
3573 if (BssType == Ndis802_11IBSS)
3574 Set_NetworkType_Proc(pAdapter, "Adhoc");
3575 else if (BssType == Ndis802_11Infrastructure)
3576 Set_NetworkType_Proc(pAdapter, "Infra");
3577 else if (BssType == Ndis802_11Monitor)
3578 Set_NetworkType_Proc(pAdapter, "Monitor");
3582 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_INFRASTRUCTURE_MODE (unknown)\n"));
3586 case OID_802_11_REMOVE_WEP:
3587 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_WEP\n"));
3588 if (wrq->u.data.length != sizeof(NDIS_802_11_KEY_INDEX))
3594 KeyIdx = *(NDIS_802_11_KEY_INDEX *) wrq->u.data.pointer;
3596 if (KeyIdx & 0x80000000)
3598 // Should never set default bit when remove key
3603 KeyIdx = KeyIdx & 0x0fffffff;
3609 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
3610 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
3611 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
3616 case RT_OID_802_11_RESET_COUNTERS:
3617 NdisZeroMemory(&pAdapter->WlanCounters, sizeof(COUNTER_802_11));
3618 NdisZeroMemory(&pAdapter->Counters8023, sizeof(COUNTER_802_3));
3619 NdisZeroMemory(&pAdapter->RalinkCounters, sizeof(COUNTER_RALINK));
3620 pAdapter->Counters8023.RxNoBuffer = 0;
3621 pAdapter->Counters8023.GoodReceives = 0;
3622 pAdapter->Counters8023.RxNoBuffer = 0;
3624 pAdapter->BulkOutComplete = 0;
3625 pAdapter->BulkOutCompleteOther= 0;
3626 pAdapter->BulkOutCompleteCancel = 0;
3627 pAdapter->BulkOutReq = 0;
3628 pAdapter->BulkInReq= 0;
3629 pAdapter->BulkInComplete = 0;
3630 pAdapter->BulkInCompleteFail = 0;
3632 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RESET_COUNTERS \n"));
3634 case OID_802_11_RTS_THRESHOLD:
3635 if (wrq->u.data.length != sizeof(NDIS_802_11_RTS_THRESHOLD))
3639 Status = copy_from_user(&RtsThresh, wrq->u.data.pointer, wrq->u.data.length);
3640 if (RtsThresh > MAX_RTS_THRESHOLD)
3643 pAdapter->CommonCfg.RtsThreshold = (USHORT)RtsThresh;
3645 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_RTS_THRESHOLD (=%ld)\n",RtsThresh));
3647 case OID_802_11_FRAGMENTATION_THRESHOLD:
3648 if (wrq->u.data.length != sizeof(NDIS_802_11_FRAGMENTATION_THRESHOLD))
3652 Status = copy_from_user(&FragThresh, wrq->u.data.pointer, wrq->u.data.length);
3653 pAdapter->CommonCfg.bUseZeroToDisableFragment = FALSE;
3654 if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
3656 if (FragThresh == 0)
3658 pAdapter->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
3659 pAdapter->CommonCfg.bUseZeroToDisableFragment = TRUE;
3665 pAdapter->CommonCfg.FragmentThreshold = (USHORT)FragThresh;
3667 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_FRAGMENTATION_THRESHOLD (=%ld) \n",FragThresh));
3669 case OID_802_11_POWER_MODE:
3670 if (wrq->u.data.length != sizeof(NDIS_802_11_POWER_MODE))
3674 Status = copy_from_user(&PowerMode, wrq->u.data.pointer, wrq->u.data.length);
3675 if (PowerMode == Ndis802_11PowerModeCAM)
3676 Set_PSMode_Proc(pAdapter, "CAM");
3677 else if (PowerMode == Ndis802_11PowerModeMAX_PSP)
3678 Set_PSMode_Proc(pAdapter, "Max_PSP");
3679 else if (PowerMode == Ndis802_11PowerModeFast_PSP)
3680 Set_PSMode_Proc(pAdapter, "Fast_PSP");
3681 else if (PowerMode == Ndis802_11PowerModeLegacy_PSP)
3682 Set_PSMode_Proc(pAdapter, "Legacy_PSP");
3686 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_POWER_MODE (=%d)\n",PowerMode));
3688 case RT_OID_802_11_TX_POWER_LEVEL_1:
3689 if (wrq->u.data.length < sizeof(ULONG))
3693 Status = copy_from_user(&PowerTemp, wrq->u.data.pointer, wrq->u.data.length);
3694 if (PowerTemp > 100)
3695 PowerTemp = 0xffffffff; // AUTO
3696 pAdapter->CommonCfg.TxPowerDefault = PowerTemp; //keep current setting.
3697 pAdapter->CommonCfg.TxPowerPercentage = pAdapter->CommonCfg.TxPowerDefault;
3698 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
3701 case OID_802_11_NETWORK_TYPE_IN_USE:
3702 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_TYPE))
3706 Status = copy_from_user(&NetType, wrq->u.data.pointer, wrq->u.data.length);
3708 if (NetType == Ndis802_11DS)
3709 RTMPSetPhyMode(pAdapter, PHY_11B);
3710 else if (NetType == Ndis802_11OFDM24)
3711 RTMPSetPhyMode(pAdapter, PHY_11BG_MIXED);
3712 else if (NetType == Ndis802_11OFDM5)
3713 RTMPSetPhyMode(pAdapter, PHY_11A);
3716 #ifdef DOT11_N_SUPPORT
3717 if (Status == NDIS_STATUS_SUCCESS)
3718 SetCommonHT(pAdapter);
3719 #endif // DOT11_N_SUPPORT //
3720 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_NETWORK_TYPE_IN_USE (=%d)\n",NetType));
3723 // For WPA PSK PMK key
3724 case RT_OID_802_11_ADD_WPA:
3725 pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3732 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
3733 if (pKey->Length != wrq->u.data.length)
3736 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!!\n"));
3740 if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
3741 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
3742 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone) )
3744 Status = -EOPNOTSUPP;
3745 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!! [AuthMode != WPAPSK/WPA2PSK/WPANONE]\n"));
3747 else if ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
3748 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
3749 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) ) // Only for WPA PSK mode
3751 NdisMoveMemory(pAdapter->StaCfg.PMK, &pKey->KeyMaterial, pKey->KeyLength);
3752 // Use RaConfig as PSK agent.
3753 // Start STA supplicant state machine
3754 if (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
3755 pAdapter->StaCfg.WpaState = SS_START;
3757 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3761 pAdapter->StaCfg.WpaState = SS_NOTUSE;
3762 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3767 case OID_802_11_REMOVE_KEY:
3768 pRemoveKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3769 if(pRemoveKey == NULL)
3775 Status = copy_from_user(pRemoveKey, wrq->u.data.pointer, wrq->u.data.length);
3776 if (pRemoveKey->Length != wrq->u.data.length)
3779 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!\n"));
3783 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3785 RTMPWPARemoveKeyProc(pAdapter, pRemoveKey);
3786 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Remove WPA Key!!\n"));
3790 KeyIdx = pRemoveKey->KeyIndex;
3792 if (KeyIdx & 0x80000000)
3794 // Should never set default bit when remove key
3796 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(Should never set default bit when remove key)\n"));
3800 KeyIdx = KeyIdx & 0x0fffffff;
3804 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(KeyId[%d] out of range)\n", KeyIdx));
3808 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
3809 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
3810 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
3811 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY (id=0x%x, Len=%d-byte)\n", pRemoveKey->KeyIndex, pRemoveKey->Length));
3819 case OID_802_11_ADD_KEY:
3820 pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3826 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
3827 if (pKey->Length != wrq->u.data.length)
3830 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY, Failed!!\n"));
3834 RTMPAddKey(pAdapter, pKey);
3835 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3839 case OID_802_11_CONFIGURATION:
3840 if (wrq->u.data.length != sizeof(NDIS_802_11_CONFIGURATION))
3844 Status = copy_from_user(&Config, wrq->u.data.pointer, wrq->u.data.length);
3847 if ((pConfig->BeaconPeriod >= 20) && (pConfig->BeaconPeriod <=400))
3848 pAdapter->CommonCfg.BeaconPeriod = (USHORT) pConfig->BeaconPeriod;
3850 pAdapter->StaActive.AtimWin = (USHORT) pConfig->ATIMWindow;
3851 MAP_KHZ_TO_CHANNEL_ID(pConfig->DSConfig, pAdapter->CommonCfg.Channel);
3853 // Save the channel on MlmeAux for CntlOidRTBssidProc used.
3855 pAdapter->MlmeAux.Channel = pAdapter->CommonCfg.Channel;
3857 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_CONFIGURATION (BeacnPeriod=%ld,AtimW=%ld,Ch=%d)\n",
3858 pConfig->BeaconPeriod, pConfig->ATIMWindow, pAdapter->CommonCfg.Channel));
3859 // Config has changed
3860 pAdapter->bConfigChanged = TRUE;
3863 #ifdef DOT11_N_SUPPORT
3864 case RT_OID_802_11_SET_HT_PHYMODE:
3865 if (wrq->u.data.length != sizeof(OID_SET_HT_PHYMODE))
3869 POID_SET_HT_PHYMODE pHTPhyMode = &HT_PhyMode;
3871 Status = copy_from_user(&HT_PhyMode, wrq->u.data.pointer, wrq->u.data.length);
3872 DBGPRINT(RT_DEBUG_TRACE, ("Set::pHTPhyMode (PhyMode = %d,TransmitNo = %d, HtMode = %d, ExtOffset = %d , MCS = %d, BW = %d, STBC = %d, SHORTGI = %d) \n",
3873 pHTPhyMode->PhyMode, pHTPhyMode->TransmitNo,pHTPhyMode->HtMode,pHTPhyMode->ExtOffset,
3874 pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->SHORTGI));
3875 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
3876 RTMPSetHT(pAdapter, pHTPhyMode);
3878 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_HT_PHYMODE(MCS=%d,BW=%d,SGI=%d,STBC=%d)\n",
3879 pAdapter->StaCfg.HTPhyMode.field.MCS, pAdapter->StaCfg.HTPhyMode.field.BW, pAdapter->StaCfg.HTPhyMode.field.ShortGI,
3880 pAdapter->StaCfg.HTPhyMode.field.STBC));
3882 #endif // DOT11_N_SUPPORT //
3883 case RT_OID_802_11_SET_APSD_SETTING:
3884 if (wrq->u.data.length != sizeof(ULONG))
3889 Status = copy_from_user(&apsd, wrq->u.data.pointer, wrq->u.data.length);
3891 /*-------------------------------------------------------------------
3892 |B31~B7 | B6~B5 | B4 | B3 | B2 | B1 | B0 |
3893 ---------------------------------------------------------------------
3894 | Rsvd | Max SP Len | AC_VO | AC_VI | AC_BK | AC_BE | APSD Capable |
3895 ---------------------------------------------------------------------*/
3896 pAdapter->CommonCfg.bAPSDCapable = (apsd & 0x00000001) ? TRUE : FALSE;
3897 pAdapter->CommonCfg.bAPSDAC_BE = ((apsd & 0x00000002) >> 1) ? TRUE : FALSE;
3898 pAdapter->CommonCfg.bAPSDAC_BK = ((apsd & 0x00000004) >> 2) ? TRUE : FALSE;
3899 pAdapter->CommonCfg.bAPSDAC_VI = ((apsd & 0x00000008) >> 3) ? TRUE : FALSE;
3900 pAdapter->CommonCfg.bAPSDAC_VO = ((apsd & 0x00000010) >> 4) ? TRUE : FALSE;
3901 pAdapter->CommonCfg.MaxSPLength = (UCHAR)((apsd & 0x00000060) >> 5);
3903 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,
3904 pAdapter->CommonCfg.bAPSDAC_BE, pAdapter->CommonCfg.bAPSDAC_BK, pAdapter->CommonCfg.bAPSDAC_VI, pAdapter->CommonCfg.bAPSDAC_VO, pAdapter->CommonCfg.MaxSPLength));
3908 case RT_OID_802_11_SET_APSD_PSM:
3909 if (wrq->u.data.length != sizeof(ULONG))
3913 // Driver needs to notify AP when PSM changes
3914 Status = copy_from_user(&pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.pointer, wrq->u.data.length);
3915 if (pAdapter->CommonCfg.bAPSDForcePowerSave != pAdapter->StaCfg.Psm)
3917 MlmeSetPsmBit(pAdapter, pAdapter->CommonCfg.bAPSDForcePowerSave);
3918 RTMPSendNullFrame(pAdapter, pAdapter->CommonCfg.TxRate, TRUE);
3920 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_APSD_PSM (bAPSDForcePowerSave:%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
3923 #ifdef QOS_DLS_SUPPORT
3924 case RT_OID_802_11_SET_DLS:
3925 if (wrq->u.data.length != sizeof(ULONG))
3929 BOOLEAN oldvalue = pAdapter->CommonCfg.bDLSCapable;
3930 Status = copy_from_user(&pAdapter->CommonCfg.bDLSCapable, wrq->u.data.pointer, wrq->u.data.length);
3931 if (oldvalue && !pAdapter->CommonCfg.bDLSCapable)
3934 // tear down local dls table entry
3935 for (i=0; i<MAX_NUM_OF_INIT_DLS_ENTRY; i++)
3937 if (pAdapter->StaCfg.DLSEntry[i].Valid && (pAdapter->StaCfg.DLSEntry[i].Status == DLS_FINISH))
3939 pAdapter->StaCfg.DLSEntry[i].Status = DLS_NONE;
3940 pAdapter->StaCfg.DLSEntry[i].Valid = FALSE;
3941 RTMPSendDLSTearDownFrame(pAdapter, pAdapter->StaCfg.DLSEntry[i].MacAddr);
3945 // tear down peer dls table entry
3946 for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
3948 if (pAdapter->StaCfg.DLSEntry[i].Valid && (pAdapter->StaCfg.DLSEntry[i].Status == DLS_FINISH))
3950 pAdapter->StaCfg.DLSEntry[i].Status = DLS_NONE;
3951 pAdapter->StaCfg.DLSEntry[i].Valid = FALSE;
3952 RTMPSendDLSTearDownFrame(pAdapter, pAdapter->StaCfg.DLSEntry[i].MacAddr);
3957 DBGPRINT(RT_DEBUG_TRACE,("Set::RT_OID_802_11_SET_DLS (=%d)\n", pAdapter->CommonCfg.bDLSCapable));
3961 case RT_OID_802_11_SET_DLS_PARAM:
3962 if (wrq->u.data.length != sizeof(RT_802_11_DLS_UI))
3968 NdisZeroMemory(&Dls, sizeof(RT_802_11_DLS));
3969 RTMPMoveMemory(&Dls, wrq->u.data.pointer, sizeof(RT_802_11_DLS_UI));
3970 MlmeEnqueue(pAdapter,
3971 MLME_CNTL_STATE_MACHINE,
3972 RT_OID_802_11_SET_DLS_PARAM,
3973 sizeof(RT_802_11_DLS),
3975 DBGPRINT(RT_DEBUG_TRACE,("Set::RT_OID_802_11_SET_DLS_PARAM \n"));
3978 #endif // QOS_DLS_SUPPORT //
3979 case RT_OID_802_11_SET_WMM:
3980 if (wrq->u.data.length != sizeof(BOOLEAN))
3984 Status = copy_from_user(&pAdapter->CommonCfg.bWmmCapable, wrq->u.data.pointer, wrq->u.data.length);
3985 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_WMM (=%d) \n", pAdapter->CommonCfg.bWmmCapable));
3989 case OID_802_11_DISASSOCIATE:
3991 if (ATE_ON(pAdapter))
3993 DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
3996 #endif // RALINK_ATE //
3998 // Set NdisRadioStateOff to TRUE, instead of called MlmeRadioOff.
3999 // Later on, NDIS_802_11_BSSID_LIST_EX->NumberOfItems should be 0
4000 // when query OID_802_11_BSSID_LIST.
4002 // TRUE: NumberOfItems will set to 0.
4003 // FALSE: NumberOfItems no change.
4005 pAdapter->CommonCfg.NdisRadioStateOff = TRUE;
4006 // Set to immediately send the media disconnect event
4007 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
4008 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DISASSOCIATE \n"));
4010 if (INFRA_ON(pAdapter))
4012 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
4014 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
4015 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
4018 MlmeEnqueue(pAdapter,
4019 MLME_CNTL_STATE_MACHINE,
4020 OID_802_11_DISASSOCIATE,
4024 StateMachineTouched = TRUE;
4028 #ifdef DOT11_N_SUPPORT
4029 case RT_OID_802_11_SET_IMME_BA_CAP:
4030 if (wrq->u.data.length != sizeof(OID_BACAP_STRUC))
4034 OID_BACAP_STRUC Orde ;
4035 Status = copy_from_user(&Orde, wrq->u.data.pointer, wrq->u.data.length);
4036 if (Orde.Policy > BA_NOTUSE)
4038 Status = NDIS_STATUS_INVALID_DATA;
4040 else if (Orde.Policy == BA_NOTUSE)
4042 pAdapter->CommonCfg.BACapability.field.Policy = BA_NOTUSE;
4043 pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
4044 pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
4045 pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
4046 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
4047 pAdapter->CommonCfg.DesiredHtPhy.MimoPs= Orde.MMPSmode;
4048 pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
4050 pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
4051 pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
4052 pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
4056 pAdapter->CommonCfg.BACapability.field.AutoBA = Orde.AutoBA;
4057 pAdapter->CommonCfg.BACapability.field.Policy = IMMED_BA; // we only support immediate BA.
4058 pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
4059 pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
4060 pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
4061 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
4062 pAdapter->CommonCfg.DesiredHtPhy.MimoPs = Orde.MMPSmode;
4063 pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
4066 pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
4067 pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
4068 pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
4070 if (pAdapter->CommonCfg.BACapability.field.RxBAWinLimit > MAX_RX_REORDERBUF)
4071 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = MAX_RX_REORDERBUF;
4075 pAdapter->CommonCfg.REGBACapability.word = pAdapter->CommonCfg.BACapability.word;
4076 DBGPRINT(RT_DEBUG_TRACE, ("Set::(Orde.AutoBA = %d) (Policy=%d)(ReBAWinLimit=%d)(TxBAWinLimit=%d)(AutoMode=%d)\n",Orde.AutoBA, pAdapter->CommonCfg.BACapability.field.Policy,
4077 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit,pAdapter->CommonCfg.BACapability.field.TxBAWinLimit, pAdapter->CommonCfg.BACapability.field.AutoBA));
4078 DBGPRINT(RT_DEBUG_TRACE, ("Set::(MimoPs = %d)(AmsduEnable = %d) (AmsduSize=%d)(MpduDensity=%d)\n",pAdapter->CommonCfg.DesiredHtPhy.MimoPs, pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable,
4079 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize, pAdapter->CommonCfg.DesiredHtPhy.MpduDensity));
4083 case RT_OID_802_11_ADD_IMME_BA:
4084 DBGPRINT(RT_DEBUG_TRACE, (" Set :: RT_OID_802_11_ADD_IMME_BA \n"));
4085 if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
4090 OID_ADD_BA_ENTRY BA;
4091 MAC_TABLE_ENTRY *pEntry;
4093 Status = copy_from_user(&BA, wrq->u.data.pointer, wrq->u.data.length);
4096 Status = NDIS_STATUS_INVALID_DATA;
4101 //BATableInsertEntry
4102 //As ad-hoc mode, BA pair is not limited to only BSSID. so add via OID.
4104 // in ad hoc mode, when adding BA pair, we should insert this entry into MACEntry too
4105 pEntry = MacTableLookup(pAdapter, BA.MACAddr);
4108 DBGPRINT(RT_DEBUG_TRACE, ("RT_OID_802_11_ADD_IMME_BA. break on no connection.----:%x:%x\n", BA.MACAddr[4], BA.MACAddr[5]));
4111 if (BA.IsRecipient == FALSE)
4113 if (pEntry->bIAmBadAtheros == TRUE)
4114 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = 0x10;
4116 BAOriSessionSetUp(pAdapter, pEntry, index, 0, 100, TRUE);
4120 //BATableInsertEntry(pAdapter, pEntry->Aid, BA.MACAddr, 0, 0xffff, BA.TID, BA.nMSDU, BA.IsRecipient);
4123 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_IMME_BA. Rec = %d. Mac = %x:%x:%x:%x:%x:%x . \n",
4124 BA.IsRecipient, BA.MACAddr[0], BA.MACAddr[1], BA.MACAddr[2], BA.MACAddr[2]
4125 , BA.MACAddr[4], BA.MACAddr[5]));
4130 case RT_OID_802_11_TEAR_IMME_BA:
4131 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA \n"));
4132 if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
4136 POID_ADD_BA_ENTRY pBA;
4137 MAC_TABLE_ENTRY *pEntry;
4139 pBA = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4143 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA kmalloc() can't allocate enough memory\n"));
4144 Status = NDIS_STATUS_FAILURE;
4148 Status = copy_from_user(pBA, wrq->u.data.pointer, wrq->u.data.length);
4149 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA(TID=%d, bAllTid=%d)\n", pBA->TID, pBA->bAllTid));
4151 if (!pBA->bAllTid && (pBA->TID > NUM_OF_TID))
4153 Status = NDIS_STATUS_INVALID_DATA;
4157 if (pBA->IsRecipient == FALSE)
4159 pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
4160 DBGPRINT(RT_DEBUG_TRACE, (" pBA->IsRecipient == FALSE\n"));
4163 DBGPRINT(RT_DEBUG_TRACE, (" pBA->pEntry\n"));
4164 BAOriSessionTearDown(pAdapter, pEntry->Aid, pBA->TID, FALSE, TRUE);
4167 DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
4171 pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
4174 BARecSessionTearDown( pAdapter, (UCHAR)pEntry->Aid, pBA->TID, TRUE);
4177 DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
4183 #endif // DOT11_N_SUPPORT //
4185 // For WPA_SUPPLICANT to set static wep key
4186 case OID_802_11_ADD_WEP:
4187 pWepKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4192 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed!!\n"));
4195 Status = copy_from_user(pWepKey, wrq->u.data.pointer, wrq->u.data.length);
4199 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (length mismatch)!!\n"));
4203 KeyIdx = pWepKey->KeyIndex & 0x0fffffff;
4204 // KeyIdx must be 0 ~ 3
4208 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (KeyIdx must be smaller than 4)!!\n"));
4212 UCHAR CipherAlg = 0;
4215 // set key material and key length
4216 NdisZeroMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, 16);
4217 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
4218 NdisMoveMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
4220 switch(pWepKey->KeyLength)
4223 CipherAlg = CIPHER_WEP64;
4226 CipherAlg = CIPHER_WEP128;
4229 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, only support CIPHER_WEP64(len:5) & CIPHER_WEP128(len:13)!!\n"));
4233 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CipherAlg;
4235 // Default key for tx (shared key)
4236 if (pWepKey->KeyIndex & 0x80000000)
4238 #ifdef WPA_SUPPLICANT_SUPPORT
4239 // set key material and key length
4240 NdisZeroMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, 16);
4241 pAdapter->StaCfg.DesireSharedKey[KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
4242 NdisMoveMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
4243 pAdapter->StaCfg.DesireSharedKeyId = KeyIdx;
4244 pAdapter->StaCfg.DesireSharedKey[KeyIdx].CipherAlg = CipherAlg;
4245 #endif // WPA_SUPPLICANT_SUPPORT //
4246 pAdapter->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
4249 #ifdef WPA_SUPPLICANT_SUPPORT
4250 if (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)
4251 #endif // WPA_SUPPLICANT_SUPPORT
4253 Key = pAdapter->SharedKey[BSS0][KeyIdx].Key;
4255 // Set key material and cipherAlg to Asic
4256 AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
4258 if (pWepKey->KeyIndex & 0x80000000)
4260 PMAC_TABLE_ENTRY pEntry = &pAdapter->MacTab.Content[BSSID_WCID];
4261 // Assign group key info
4262 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
4263 // Assign pairwise key info
4264 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, pEntry);
4267 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"));
4272 #ifdef WPA_SUPPLICANT_SUPPORT
4273 case OID_SET_COUNTERMEASURES:
4274 if (wrq->u.data.length != sizeof(int))
4279 Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
4281 pAdapter->StaCfg.bBlockAssoc = TRUE;
4283 // WPA MIC error should block association attempt for 60 seconds
4284 pAdapter->StaCfg.bBlockAssoc = FALSE;
4285 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_SET_COUNTERMEASURES bBlockAssoc=%s\n", pAdapter->StaCfg.bBlockAssoc ? "TRUE":"FALSE"));
4288 case RT_OID_WPA_SUPPLICANT_SUPPORT:
4289 if (wrq->u.data.length != sizeof(UCHAR))
4293 Status = copy_from_user(&wpa_supplicant_enable, wrq->u.data.pointer, wrq->u.data.length);
4294 pAdapter->StaCfg.WpaSupplicantUP = wpa_supplicant_enable;
4295 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
4298 case OID_802_11_DEAUTHENTICATION:
4299 if (wrq->u.data.length != sizeof(MLME_DEAUTH_REQ_STRUCT))
4303 MLME_DEAUTH_REQ_STRUCT *pInfo;
4304 MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
4306 pInfo = (MLME_DEAUTH_REQ_STRUCT *) MsgElem->Msg;
4307 Status = copy_from_user(pInfo, wrq->u.data.pointer, wrq->u.data.length);
4308 MlmeDeauthReqAction(pAdapter, MsgElem);
4311 if (INFRA_ON(pAdapter))
4313 LinkDown(pAdapter, FALSE);
4314 pAdapter->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
4316 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DEAUTHENTICATION (Reason=%d)\n", pInfo->Reason));
4319 case OID_802_11_DROP_UNENCRYPTED:
4320 if (wrq->u.data.length != sizeof(int))
4325 Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
4327 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
4329 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
4330 NdisAcquireSpinLock(&pAdapter->MacTabLock);
4331 pAdapter->MacTab.Content[BSSID_WCID].PortSecured = pAdapter->StaCfg.PortSecured;
4332 NdisReleaseSpinLock(&pAdapter->MacTabLock);
4333 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DROP_UNENCRYPTED (=%d)\n", enabled));
4336 case OID_802_11_SET_IEEE8021X:
4337 if (wrq->u.data.length != sizeof(BOOLEAN))
4341 Status = copy_from_user(&IEEE8021xState, wrq->u.data.pointer, wrq->u.data.length);
4342 pAdapter->StaCfg.IEEE8021X = IEEE8021xState;
4343 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X (=%d)\n", IEEE8021xState));
4346 case OID_802_11_SET_IEEE8021X_REQUIRE_KEY:
4347 if (wrq->u.data.length != sizeof(BOOLEAN))
4351 Status = copy_from_user(&IEEE8021x_required_keys, wrq->u.data.pointer, wrq->u.data.length);
4352 pAdapter->StaCfg.IEEE8021x_required_keys = IEEE8021x_required_keys;
4353 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X_REQUIRE_KEY (%d)\n", IEEE8021x_required_keys));
4356 case OID_802_11_PMKID:
4357 pPmkId = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4359 if(pPmkId == NULL) {
4363 Status = copy_from_user(pPmkId, wrq->u.data.pointer, wrq->u.data.length);
4365 // check the PMKID information
4366 if (pPmkId->BSSIDInfoCount == 0)
4367 NdisZeroMemory(pAdapter->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
4370 PBSSID_INFO pBssIdInfo;
4374 for (BssIdx = 0; BssIdx < pPmkId->BSSIDInfoCount; BssIdx++)
4376 // point to the indexed BSSID_INFO structure
4377 pBssIdInfo = (PBSSID_INFO) ((PUCHAR) pPmkId + 2 * sizeof(UINT) + BssIdx * sizeof(BSSID_INFO));
4378 // Find the entry in the saved data base.
4379 for (CachedIdx = 0; CachedIdx < pAdapter->StaCfg.SavedPMKNum; CachedIdx++)
4381 // compare the BSSID
4382 if (NdisEqualMemory(pBssIdInfo->BSSID, pAdapter->StaCfg.SavedPMK[CachedIdx].BSSID, sizeof(NDIS_802_11_MAC_ADDRESS)))
4386 // Found, replace it
4387 if (CachedIdx < PMKID_NO)
4389 DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
4390 NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
4391 pAdapter->StaCfg.SavedPMKNum++;
4393 // Not found, replace the last one
4396 // Randomly replace one
4397 CachedIdx = (pBssIdInfo->BSSID[5] % PMKID_NO);
4398 DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
4399 NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
4406 #endif // WPA_SUPPLICANT_SUPPORT //
4411 case OID_802_11_SHORTRETRYLIMIT:
4412 if (wrq->u.data.length != sizeof(ULONG))
4416 Status = copy_from_user(&ShortRetryLimit, wrq->u.data.pointer, wrq->u.data.length);
4417 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
4418 tx_rty_cfg.field.ShortRtyLimit = ShortRetryLimit;
4419 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
4420 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SHORTRETRYLIMIT (tx_rty_cfg.field.ShortRetryLimit=%d, ShortRetryLimit=%ld)\n", tx_rty_cfg.field.ShortRtyLimit, ShortRetryLimit));
4424 case OID_802_11_LONGRETRYLIMIT:
4425 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_LONGRETRYLIMIT \n"));
4426 if (wrq->u.data.length != sizeof(ULONG))
4430 Status = copy_from_user(&LongRetryLimit, wrq->u.data.pointer, wrq->u.data.length);
4431 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
4432 tx_rty_cfg.field.LongRtyLimit = LongRetryLimit;
4433 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
4434 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_LONGRETRYLIMIT (tx_rty_cfg.field.LongRetryLimit= %d,LongRetryLimit=%ld)\n", tx_rty_cfg.field.LongRtyLimit, LongRetryLimit));
4438 case OID_802_11_WEPDEFAULTKEYVALUE:
4439 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEPDEFAULTKEYVALUE\n"));
4440 pKey = kmalloc(wrq->u.data.length, GFP_KERNEL);
4441 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
4444 if ( pKey->Length != wrq->u.data.length)
4447 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEPDEFAULTKEYVALUE, Failed!!\n"));
4449 KeyIdx = pKey->KeyIndex & 0x0fffffff;
4450 DBGPRINT(RT_DEBUG_TRACE,("pKey->KeyIndex =%d, pKey->KeyLength=%d\n", pKey->KeyIndex, pKey->KeyLength));
4452 // it is a shared key
4457 pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen = (UCHAR) pKey->KeyLength;
4458 NdisMoveMemory(&pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key, &pKey->KeyMaterial, pKey->KeyLength);
4459 if (pKey->KeyIndex & 0x80000000)
4461 // Default key for tx (shared key)
4462 pAdapter->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
4464 //RestartAPIsRequired = TRUE;
4469 case OID_802_11_WEPDEFAULTKEYID:
4470 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEPDEFAULTKEYID \n"));
4472 if (wrq->u.data.length != sizeof(UCHAR))
4475 Status = copy_from_user(&pAdapter->StaCfg.DefaultKeyId, wrq->u.data.pointer, wrq->u.data.length);
4480 case OID_802_11_CURRENTCHANNEL:
4481 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_CURRENTCHANNEL \n"));
4482 if (wrq->u.data.length != sizeof(UCHAR))
4486 Status = copy_from_user(&ctmp, wrq->u.data.pointer, wrq->u.data.length);
4487 sprintf(&ctmp,"%d", ctmp);
4488 Set_Channel_Proc(pAdapter, &ctmp);
4496 DBGPRINT(RT_DEBUG_TRACE, ("Set::unknown IOCTL's subcmd = 0x%08x\n", cmd));
4497 Status = -EOPNOTSUPP;
4505 INT RTMPQueryInformation(
4506 IN PRTMP_ADAPTER pAdapter,
4507 IN OUT struct ifreq *rq,
4510 struct iwreq *wrq = (struct iwreq *) rq;
4511 NDIS_802_11_BSSID_LIST_EX *pBssidList = NULL;
4512 PNDIS_WLAN_BSSID_EX pBss;
4513 NDIS_802_11_SSID Ssid;
4514 NDIS_802_11_CONFIGURATION *pConfiguration = NULL;
4515 RT_802_11_LINK_STATUS *pLinkStatus = NULL;
4516 RT_802_11_STA_CONFIG *pStaConfig = NULL;
4517 NDIS_802_11_STATISTICS *pStatistics = NULL;
4518 NDIS_802_11_RTS_THRESHOLD RtsThresh;
4519 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
4520 NDIS_802_11_POWER_MODE PowerMode;
4521 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
4522 RT_802_11_PREAMBLE PreamType;
4523 NDIS_802_11_AUTHENTICATION_MODE AuthMode;
4524 NDIS_802_11_WEP_STATUS WepStatus;
4525 NDIS_MEDIA_STATE MediaState;
4526 ULONG BssBufSize, ulInfo=0, NetworkTypeList[4], apsd = 0;
4528 PUCHAR pBuf = NULL, pPtr;
4529 INT Status = NDIS_STATUS_SUCCESS;
4530 UINT we_version_compiled;
4531 UCHAR i, Padding = 0;
4533 UCHAR driverVersion[8];
4534 OID_SET_HT_PHYMODE *pHTPhyMode = NULL;
4539 DefaultKeyIdxValue *pKeyIdxValue;
4541 TX_RTY_CFG_STRUC tx_rty_cfg;
4542 ULONG ShortRetryLimit, LongRetryLimit;
4548 case RT_OID_DEVICE_NAME:
4549 wrq->u.data.length = sizeof(STA_NIC_DEVICE_NAME);
4550 Status = copy_to_user(wrq->u.data.pointer, STA_NIC_DEVICE_NAME, wrq->u.data.length);
4552 case RT_OID_VERSION_INFO:
4553 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_VERSION_INFO \n"));
4554 wrq->u.data.length = 8*sizeof(UCHAR);
4555 sprintf(&driverVersion[0], "%s", STA_DRIVER_VERSION);
4556 driverVersion[7] = '\0';
4557 if (copy_to_user(wrq->u.data.pointer, &driverVersion, wrq->u.data.length))
4563 case RT_QUERY_ATE_TXDONE_COUNT:
4564 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_QUERY_ATE_TXDONE_COUNT \n"));
4565 wrq->u.data.length = sizeof(UINT32);
4566 if (copy_to_user(wrq->u.data.pointer, &pAdapter->ate.TxDoneCount, wrq->u.data.length))
4571 #endif // RALINK_ATE //
4572 case OID_802_11_BSSID_LIST:
4573 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
4576 * Still scanning, indicate the caller should try again.
4578 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (Still scanning)\n"));
4581 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (%d BSS returned)\n",pAdapter->ScanTab.BssNr));
4582 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
4583 // Claculate total buffer size required
4584 BssBufSize = sizeof(ULONG);
4586 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
4588 // Align pointer to 4 bytes boundary.
4589 //Padding = 4 - (pAdapter->ScanTab.BssEntry[i].VarIELen & 0x0003);
4592 BssBufSize += (sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
4595 // For safety issue, we add 256 bytes just in case
4597 // Allocate the same size as passed from higher layer
4598 pBuf = kmalloc(BssBufSize, MEM_ALLOC_FLAG);
4604 // Init 802_11_BSSID_LIST_EX structure
4605 NdisZeroMemory(pBuf, BssBufSize);
4606 pBssidList = (PNDIS_802_11_BSSID_LIST_EX) pBuf;
4607 pBssidList->NumberOfItems = pAdapter->ScanTab.BssNr;
4609 // Calculate total buffer length
4610 BssLen = 4; // Consist of NumberOfItems
4611 // Point to start of NDIS_WLAN_BSSID_EX
4612 // pPtr = pBuf + sizeof(ULONG);
4613 pPtr = (PUCHAR) &pBssidList->Bssid[0];
4614 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
4616 pBss = (PNDIS_WLAN_BSSID_EX) pPtr;
4617 NdisMoveMemory(&pBss->MacAddress, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
4618 if ((pAdapter->ScanTab.BssEntry[i].Hidden == 1) && (pAdapter->StaCfg.bShowHiddenSSID == FALSE))
4621 // We must return this SSID during 4way handshaking, otherwise Aegis will failed to parse WPA infomation
4622 // and then failed to send EAPOl farame.
4624 if ((pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) && (pAdapter->StaCfg.PortSecured != WPA_802_1X_PORT_SECURED))
4626 pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
4627 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
4630 pBss->Ssid.SsidLength = 0;
4634 pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
4635 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
4637 pBss->Privacy = pAdapter->ScanTab.BssEntry[i].Privacy;
4638 pBss->Rssi = pAdapter->ScanTab.BssEntry[i].Rssi - pAdapter->BbpRssiToDbmDelta;
4639 pBss->NetworkTypeInUse = NetworkTypeInUseSanity(&pAdapter->ScanTab.BssEntry[i]);
4640 pBss->Configuration.Length = sizeof(NDIS_802_11_CONFIGURATION);
4641 pBss->Configuration.BeaconPeriod = pAdapter->ScanTab.BssEntry[i].BeaconPeriod;
4642 pBss->Configuration.ATIMWindow = pAdapter->ScanTab.BssEntry[i].AtimWin;
4644 MAP_CHANNEL_ID_TO_KHZ(pAdapter->ScanTab.BssEntry[i].Channel, pBss->Configuration.DSConfig);
4646 if (pAdapter->ScanTab.BssEntry[i].BssType == BSS_INFRA)
4647 pBss->InfrastructureMode = Ndis802_11Infrastructure;
4649 pBss->InfrastructureMode = Ndis802_11IBSS;
4651 NdisMoveMemory(pBss->SupportedRates, pAdapter->ScanTab.BssEntry[i].SupRate, pAdapter->ScanTab.BssEntry[i].SupRateLen);
4652 NdisMoveMemory(pBss->SupportedRates + pAdapter->ScanTab.BssEntry[i].SupRateLen,
4653 pAdapter->ScanTab.BssEntry[i].ExtRate,
4654 pAdapter->ScanTab.BssEntry[i].ExtRateLen);
4656 if (pAdapter->ScanTab.BssEntry[i].VarIELen == 0)
4658 pBss->IELength = sizeof(NDIS_802_11_FIXED_IEs);
4659 NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
4660 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
4664 pBss->IELength = (ULONG)(sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen);
4665 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
4666 NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
4667 NdisMoveMemory(pBss->IEs + sizeof(NDIS_802_11_FIXED_IEs), pAdapter->ScanTab.BssEntry[i].VarIEs, pAdapter->ScanTab.BssEntry[i].VarIELen);
4668 pPtr += pAdapter->ScanTab.BssEntry[i].VarIELen;
4670 pBss->Length = (ULONG)(sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
4672 #if WIRELESS_EXT < 17
4673 if ((BssLen + pBss->Length) < wrq->u.data.length)
4674 BssLen += pBss->Length;
4677 pBssidList->NumberOfItems = i;
4681 BssLen += pBss->Length;
4685 #if WIRELESS_EXT < 17
4686 wrq->u.data.length = BssLen;
4688 if (BssLen > wrq->u.data.length)
4694 wrq->u.data.length = BssLen;
4696 Status = copy_to_user(wrq->u.data.pointer, pBssidList, BssLen);
4699 case OID_802_3_CURRENT_ADDRESS:
4700 wrq->u.data.length = MAC_ADDR_LEN;
4701 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
4703 case OID_GEN_MEDIA_CONNECT_STATUS:
4704 if (pAdapter->IndicateMediaState == NdisMediaStateConnected)
4705 MediaState = NdisMediaStateConnected;
4707 MediaState = NdisMediaStateDisconnected;
4709 wrq->u.data.length = sizeof(NDIS_MEDIA_STATE);
4710 Status = copy_to_user(wrq->u.data.pointer, &MediaState, wrq->u.data.length);
4712 case OID_802_11_BSSID:
4714 if (ATE_ON(pAdapter))
4716 DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
4717 Status = NDIS_STATUS_RESOURCES;
4720 #endif // RALINK_ATE //
4721 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
4723 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Bssid, sizeof(NDIS_802_11_MAC_ADDRESS));
4728 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID(=EMPTY)\n"));
4732 case OID_802_11_SSID:
4733 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
4734 NdisZeroMemory(Ssid.Ssid, MAX_LEN_OF_SSID);
4735 Ssid.SsidLength = pAdapter->CommonCfg.SsidLen;
4736 memcpy(Ssid.Ssid, pAdapter->CommonCfg.Ssid, Ssid.SsidLength);
4737 wrq->u.data.length = sizeof(NDIS_802_11_SSID);
4738 Status = copy_to_user(wrq->u.data.pointer, &Ssid, wrq->u.data.length);
4739 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_SSID (Len=%d, ssid=%s)\n", Ssid.SsidLength,Ssid.Ssid));
4741 case RT_OID_802_11_QUERY_LINK_STATUS:
4742 pLinkStatus = (RT_802_11_LINK_STATUS *) kmalloc(sizeof(RT_802_11_LINK_STATUS), MEM_ALLOC_FLAG);
4745 pLinkStatus->CurrTxRate = RateIdTo500Kbps[pAdapter->CommonCfg.TxRate]; // unit : 500 kbps
4746 pLinkStatus->ChannelQuality = pAdapter->Mlme.ChannelQuality;
4747 pLinkStatus->RxByteCount = pAdapter->RalinkCounters.ReceivedByteCount;
4748 pLinkStatus->TxByteCount = pAdapter->RalinkCounters.TransmittedByteCount;
4749 pLinkStatus->CentralChannel = pAdapter->CommonCfg.CentralChannel;
4750 wrq->u.data.length = sizeof(RT_802_11_LINK_STATUS);
4751 Status = copy_to_user(wrq->u.data.pointer, pLinkStatus, wrq->u.data.length);
4753 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS\n"));
4757 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS(kmalloc failed)\n"));
4761 case OID_802_11_CONFIGURATION:
4762 pConfiguration = (NDIS_802_11_CONFIGURATION *) kmalloc(sizeof(NDIS_802_11_CONFIGURATION), MEM_ALLOC_FLAG);
4765 pConfiguration->Length = sizeof(NDIS_802_11_CONFIGURATION);
4766 pConfiguration->BeaconPeriod = pAdapter->CommonCfg.BeaconPeriod;
4767 pConfiguration->ATIMWindow = pAdapter->StaActive.AtimWin;
4768 MAP_CHANNEL_ID_TO_KHZ(pAdapter->CommonCfg.Channel, pConfiguration->DSConfig);
4769 wrq->u.data.length = sizeof(NDIS_802_11_CONFIGURATION);
4770 Status = copy_to_user(wrq->u.data.pointer, pConfiguration, wrq->u.data.length);
4771 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(BeaconPeriod=%ld,AtimW=%ld,Channel=%d) \n",
4772 pConfiguration->BeaconPeriod, pConfiguration->ATIMWindow, pAdapter->CommonCfg.Channel));
4773 kfree(pConfiguration);
4777 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(kmalloc failed)\n"));
4781 case RT_OID_802_11_SNR_0:
4782 if ((pAdapter->StaCfg.LastSNR0 > 0))
4784 ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR0) * 3) / 16 ;
4785 wrq->u.data.length = sizeof(ulInfo);
4786 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4787 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_SNR_0(0x=%lx)\n", ulInfo));
4792 case RT_OID_802_11_SNR_1:
4793 if ((pAdapter->Antenna.field.RxPath > 1) &&
4794 (pAdapter->StaCfg.LastSNR1 > 0))
4796 ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR1) * 3) / 16 ;
4797 wrq->u.data.length = sizeof(ulInfo);
4798 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4799 DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(0x=%lx)\n",ulInfo));
4803 DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(pAdapter->StaCfg.LastSNR1=%d)\n",pAdapter->StaCfg.LastSNR1));
4805 case OID_802_11_RSSI_TRIGGER:
4806 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0 - pAdapter->BbpRssiToDbmDelta;
4807 wrq->u.data.length = sizeof(ulInfo);
4808 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4809 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RSSI_TRIGGER(=%ld)\n", ulInfo));
4811 case OID_802_11_RSSI:
4812 case RT_OID_802_11_RSSI:
4813 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0;
4814 wrq->u.data.length = sizeof(ulInfo);
4815 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4817 case RT_OID_802_11_RSSI_1:
4818 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi1;
4819 wrq->u.data.length = sizeof(ulInfo);
4820 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4822 case RT_OID_802_11_RSSI_2:
4823 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi2;
4824 wrq->u.data.length = sizeof(ulInfo);
4825 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4827 case OID_802_11_STATISTICS:
4828 pStatistics = (NDIS_802_11_STATISTICS *) kmalloc(sizeof(NDIS_802_11_STATISTICS), MEM_ALLOC_FLAG);
4831 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS \n"));
4832 // add the most up-to-date h/w raw counters into software counters
4833 NICUpdateRawCounters(pAdapter);
4835 // Sanity check for calculation of sucessful count
4836 if (pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart < pAdapter->WlanCounters.RetryCount.QuadPart)
4837 pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
4839 pStatistics->TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart;
4840 pStatistics->MulticastTransmittedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastTransmittedFrameCount.QuadPart;
4841 pStatistics->FailedCount.QuadPart = pAdapter->WlanCounters.FailedCount.QuadPart;
4842 pStatistics->RetryCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
4843 pStatistics->MultipleRetryCount.QuadPart = pAdapter->WlanCounters.MultipleRetryCount.QuadPart;
4844 pStatistics->RTSSuccessCount.QuadPart = pAdapter->WlanCounters.RTSSuccessCount.QuadPart;
4845 pStatistics->RTSFailureCount.QuadPart = pAdapter->WlanCounters.RTSFailureCount.QuadPart;
4846 pStatistics->ACKFailureCount.QuadPart = pAdapter->WlanCounters.ACKFailureCount.QuadPart;
4847 pStatistics->FrameDuplicateCount.QuadPart = pAdapter->WlanCounters.FrameDuplicateCount.QuadPart;
4848 pStatistics->ReceivedFragmentCount.QuadPart = pAdapter->WlanCounters.ReceivedFragmentCount.QuadPart;
4849 pStatistics->MulticastReceivedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastReceivedFrameCount.QuadPart;
4851 pStatistics->FCSErrorCount = pAdapter->RalinkCounters.RealFcsErrCount;
4853 pStatistics->FCSErrorCount.QuadPart = pAdapter->WlanCounters.FCSErrorCount.QuadPart;
4854 pStatistics->FrameDuplicateCount.u.LowPart = pAdapter->WlanCounters.FrameDuplicateCount.u.LowPart / 100;
4856 wrq->u.data.length = sizeof(NDIS_802_11_STATISTICS);
4857 Status = copy_to_user(wrq->u.data.pointer, pStatistics, wrq->u.data.length);
4862 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS(kmalloc failed)\n"));
4866 case OID_GEN_RCV_OK:
4867 ulInfo = pAdapter->Counters8023.GoodReceives;
4868 wrq->u.data.length = sizeof(ulInfo);
4869 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4871 case OID_GEN_RCV_NO_BUFFER:
4872 ulInfo = pAdapter->Counters8023.RxNoBuffer;
4873 wrq->u.data.length = sizeof(ulInfo);
4874 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4876 case RT_OID_802_11_PHY_MODE:
4877 ulInfo = (ULONG)pAdapter->CommonCfg.PhyMode;
4878 wrq->u.data.length = sizeof(ulInfo);
4879 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4880 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PHY_MODE (=%ld)\n", ulInfo));
4882 case RT_OID_802_11_STA_CONFIG:
4883 pStaConfig = (RT_802_11_STA_CONFIG *) kmalloc(sizeof(RT_802_11_STA_CONFIG), MEM_ALLOC_FLAG);
4886 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG\n"));
4887 pStaConfig->EnableTxBurst = pAdapter->CommonCfg.bEnableTxBurst;
4888 pStaConfig->EnableTurboRate = 0;
4889 pStaConfig->UseBGProtection = pAdapter->CommonCfg.UseBGProtection;
4890 pStaConfig->UseShortSlotTime = pAdapter->CommonCfg.bUseShortSlotTime;
4891 //pStaConfig->AdhocMode = pAdapter->StaCfg.AdhocMode;
4892 pStaConfig->HwRadioStatus = (pAdapter->StaCfg.bHwRadio == TRUE) ? 1 : 0;
4893 pStaConfig->Rsv1 = 0;
4894 pStaConfig->SystemErrorBitmap = pAdapter->SystemErrorBitmap;
4895 wrq->u.data.length = sizeof(RT_802_11_STA_CONFIG);
4896 Status = copy_to_user(wrq->u.data.pointer, pStaConfig, wrq->u.data.length);
4901 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
4905 case OID_802_11_RTS_THRESHOLD:
4906 RtsThresh = pAdapter->CommonCfg.RtsThreshold;
4907 wrq->u.data.length = sizeof(RtsThresh);
4908 Status = copy_to_user(wrq->u.data.pointer, &RtsThresh, wrq->u.data.length);
4909 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RTS_THRESHOLD(=%ld)\n", RtsThresh));
4911 case OID_802_11_FRAGMENTATION_THRESHOLD:
4912 FragThresh = pAdapter->CommonCfg.FragmentThreshold;
4913 if (pAdapter->CommonCfg.bUseZeroToDisableFragment == TRUE)
4915 wrq->u.data.length = sizeof(FragThresh);
4916 Status = copy_to_user(wrq->u.data.pointer, &FragThresh, wrq->u.data.length);
4917 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_FRAGMENTATION_THRESHOLD(=%ld)\n", FragThresh));
4919 case OID_802_11_POWER_MODE:
4920 PowerMode = pAdapter->StaCfg.WindowsPowerMode;
4921 wrq->u.data.length = sizeof(PowerMode);
4922 Status = copy_to_user(wrq->u.data.pointer, &PowerMode, wrq->u.data.length);
4923 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_POWER_MODE(=%d)\n", PowerMode));
4925 case RT_OID_802_11_RADIO:
4926 RadioState = (BOOLEAN) pAdapter->StaCfg.bSwRadio;
4927 wrq->u.data.length = sizeof(RadioState);
4928 Status = copy_to_user(wrq->u.data.pointer, &RadioState, wrq->u.data.length);
4929 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_RADIO (=%d)\n", RadioState));
4931 case OID_802_11_INFRASTRUCTURE_MODE:
4932 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
4933 BssType = Ndis802_11IBSS;
4934 else if (pAdapter->StaCfg.BssType == BSS_INFRA)
4935 BssType = Ndis802_11Infrastructure;
4936 else if (pAdapter->StaCfg.BssType == BSS_MONITOR)
4937 BssType = Ndis802_11Monitor;
4939 BssType = Ndis802_11AutoUnknown;
4941 wrq->u.data.length = sizeof(BssType);
4942 Status = copy_to_user(wrq->u.data.pointer, &BssType, wrq->u.data.length);
4943 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_INFRASTRUCTURE_MODE(=%d)\n", BssType));
4945 case RT_OID_802_11_PREAMBLE:
4946 PreamType = pAdapter->CommonCfg.TxPreamble;
4947 wrq->u.data.length = sizeof(PreamType);
4948 Status = copy_to_user(wrq->u.data.pointer, &PreamType, wrq->u.data.length);
4949 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PREAMBLE(=%d)\n", PreamType));
4951 case OID_802_11_AUTHENTICATION_MODE:
4952 AuthMode = pAdapter->StaCfg.AuthMode;
4953 wrq->u.data.length = sizeof(AuthMode);
4954 Status = copy_to_user(wrq->u.data.pointer, &AuthMode, wrq->u.data.length);
4955 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_AUTHENTICATION_MODE(=%d)\n", AuthMode));
4957 case OID_802_11_WEP_STATUS:
4958 WepStatus = pAdapter->StaCfg.WepStatus;
4959 wrq->u.data.length = sizeof(WepStatus);
4960 Status = copy_to_user(wrq->u.data.pointer, &WepStatus, wrq->u.data.length);
4961 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_WEP_STATUS(=%d)\n", WepStatus));
4963 case OID_802_11_TX_POWER_LEVEL:
4964 wrq->u.data.length = sizeof(ULONG);
4965 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPower, wrq->u.data.length);
4966 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_TX_POWER_LEVEL %x\n",pAdapter->CommonCfg.TxPower));
4968 case RT_OID_802_11_TX_POWER_LEVEL_1:
4969 wrq->u.data.length = sizeof(ULONG);
4970 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPowerPercentage, wrq->u.data.length);
4971 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
4973 case OID_802_11_NETWORK_TYPES_SUPPORTED:
4974 if ((pAdapter->RfIcType == RFIC_2850) || (pAdapter->RfIcType == RFIC_2750))
4976 NetworkTypeList[0] = 3; // NumberOfItems = 3
4977 NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
4978 NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
4979 NetworkTypeList[3] = Ndis802_11OFDM5; // NetworkType[3] = 11a
4980 wrq->u.data.length = 16;
4981 Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
4985 NetworkTypeList[0] = 2; // NumberOfItems = 2
4986 NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
4987 NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
4988 wrq->u.data.length = 12;
4989 Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
4991 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_NETWORK_TYPES_SUPPORTED\n"));
4993 case OID_802_11_NETWORK_TYPE_IN_USE:
4994 wrq->u.data.length = sizeof(ULONG);
4995 if (pAdapter->CommonCfg.PhyMode == PHY_11A)
4996 ulInfo = Ndis802_11OFDM5;
4997 else if ((pAdapter->CommonCfg.PhyMode == PHY_11BG_MIXED) || (pAdapter->CommonCfg.PhyMode == PHY_11G))
4998 ulInfo = Ndis802_11OFDM24;
5000 ulInfo = Ndis802_11DS;
5001 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
5003 case RT_OID_802_11_QUERY_LAST_RX_RATE:
5004 ulInfo = (ULONG)pAdapter->LastRxRate;
5005 wrq->u.data.length = sizeof(ulInfo);
5006 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
5007 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_RX_RATE (=%ld)\n", ulInfo));
5009 case RT_OID_802_11_QUERY_LAST_TX_RATE:
5010 //ulInfo = (ULONG)pAdapter->LastTxRate;
5011 ulInfo = (ULONG)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word;
5012 wrq->u.data.length = sizeof(ulInfo);
5013 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
5014 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_TX_RATE (=%lx)\n", ulInfo));
5016 case RT_OID_802_11_QUERY_EEPROM_VERSION:
5017 wrq->u.data.length = sizeof(ULONG);
5018 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->EepromVersion, wrq->u.data.length);
5020 case RT_OID_802_11_QUERY_FIRMWARE_VERSION:
5021 wrq->u.data.length = sizeof(ULONG);
5022 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->FirmwareVersion, wrq->u.data.length);
5024 case RT_OID_802_11_QUERY_NOISE_LEVEL:
5025 wrq->u.data.length = sizeof(UCHAR);
5026 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->BbpWriteLatch[66], wrq->u.data.length);
5027 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_NOISE_LEVEL (=%d)\n", pAdapter->BbpWriteLatch[66]));
5029 case RT_OID_802_11_EXTRA_INFO:
5030 wrq->u.data.length = sizeof(ULONG);
5031 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->ExtraInfo, wrq->u.data.length);
5032 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_EXTRA_INFO (=%ld)\n", pAdapter->ExtraInfo));
5034 case RT_OID_WE_VERSION_COMPILED:
5035 wrq->u.data.length = sizeof(UINT);
5036 we_version_compiled = WIRELESS_EXT;
5037 Status = copy_to_user(wrq->u.data.pointer, &we_version_compiled, wrq->u.data.length);
5039 case RT_OID_802_11_QUERY_APSD_SETTING:
5040 apsd = (pAdapter->CommonCfg.bAPSDCapable | (pAdapter->CommonCfg.bAPSDAC_BE << 1) | (pAdapter->CommonCfg.bAPSDAC_BK << 2)
5041 | (pAdapter->CommonCfg.bAPSDAC_VI << 3) | (pAdapter->CommonCfg.bAPSDAC_VO << 4) | (pAdapter->CommonCfg.MaxSPLength << 5));
5043 wrq->u.data.length = sizeof(ULONG);
5044 Status = copy_to_user(wrq->u.data.pointer, &apsd, wrq->u.data.length);
5045 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",
5046 apsd,pAdapter->CommonCfg.bAPSDCapable,pAdapter->CommonCfg.bAPSDAC_BE,pAdapter->CommonCfg.bAPSDAC_BK,pAdapter->CommonCfg.bAPSDAC_VI,pAdapter->CommonCfg.bAPSDAC_VO,pAdapter->CommonCfg.MaxSPLength));
5048 case RT_OID_802_11_QUERY_APSD_PSM:
5049 wrq->u.data.length = sizeof(ULONG);
5050 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.length);
5051 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_APSD_PSM (=%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
5053 case RT_OID_802_11_QUERY_WMM:
5054 wrq->u.data.length = sizeof(BOOLEAN);
5055 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bWmmCapable, wrq->u.data.length);
5056 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_WMM (=%d)\n", pAdapter->CommonCfg.bWmmCapable));
5058 #ifdef WPA_SUPPLICANT_SUPPORT
5059 case RT_OID_NEW_DRIVER:
5062 wrq->u.data.length = sizeof(UCHAR);
5063 Status = copy_to_user(wrq->u.data.pointer, &enabled, wrq->u.data.length);
5064 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_NEW_DRIVER (=%d)\n", enabled));
5067 case RT_OID_WPA_SUPPLICANT_SUPPORT:
5068 wrq->u.data.length = sizeof(UCHAR);
5069 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->StaCfg.WpaSupplicantUP, wrq->u.data.length);
5070 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
5072 #endif // WPA_SUPPLICANT_SUPPORT //
5074 case RT_OID_DRIVER_DEVICE_NAME:
5075 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_DRIVER_DEVICE_NAME \n"));
5076 wrq->u.data.length = 16;
5077 if (copy_to_user(wrq->u.data.pointer, pAdapter->StaCfg.dev_name, wrq->u.data.length))
5082 case RT_OID_802_11_QUERY_HT_PHYMODE:
5083 pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
5086 pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
5087 pHTPhyMode->HtMode = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE;
5088 pHTPhyMode->BW = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.BW;
5089 pHTPhyMode->MCS= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MCS;
5090 pHTPhyMode->SHORTGI= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.ShortGI;
5091 pHTPhyMode->STBC= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.STBC;
5093 pHTPhyMode->ExtOffset = ((pAdapter->CommonCfg.CentralChannel < pAdapter->CommonCfg.Channel) ? (EXTCHA_BELOW) : (EXTCHA_ABOVE));
5094 wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
5095 if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
5099 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
5100 pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
5101 DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
5105 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
5109 case RT_OID_802_11_COUNTRY_REGION:
5110 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_COUNTRY_REGION \n"));
5111 wrq->u.data.length = sizeof(ulInfo);
5112 ulInfo = pAdapter->CommonCfg.CountryRegionForABand;
5113 ulInfo = (ulInfo << 8)|(pAdapter->CommonCfg.CountryRegion);
5114 if (copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length))
5119 case RT_OID_802_11_QUERY_DAT_HT_PHYMODE:
5120 pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
5123 pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
5124 pHTPhyMode->HtMode = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.HTMODE;
5125 pHTPhyMode->BW = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.BW;
5126 pHTPhyMode->MCS= (UCHAR)pAdapter->StaCfg.DesiredTransmitSetting.field.MCS;
5127 pHTPhyMode->SHORTGI= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.ShortGI;
5128 pHTPhyMode->STBC= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.STBC;
5130 wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
5131 if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
5135 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
5136 pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
5137 DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
5141 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
5145 case RT_OID_QUERY_MULTIPLE_CARD_SUPPORT:
5146 wrq->u.data.length = sizeof(UCHAR);
5148 #ifdef MULTIPLE_CARD_SUPPORT
5150 #endif // MULTIPLE_CARD_SUPPORT //
5151 if (copy_to_user(wrq->u.data.pointer, &i, wrq->u.data.length))
5155 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_QUERY_MULTIPLE_CARD_SUPPORT(=%d) \n", i));
5158 case RT_OID_802_11_MAC_ADDRESS:
5159 wrq->u.data.length = MAC_ADDR_LEN;
5160 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
5163 case RT_OID_802_11_MANUFACTUREROUI:
5164 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_MANUFACTUREROUI \n"));
5165 wrq->u.data.length = ManufacturerOUI_LEN;
5166 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
5169 case RT_OID_802_11_MANUFACTURERNAME:
5170 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_MANUFACTURERNAME \n"));
5171 wrq->u.data.length = strlen(ManufacturerNAME);
5172 Status = copy_to_user(wrq->u.data.pointer, ManufacturerNAME, wrq->u.data.length);
5175 case RT_OID_802_11_RESOURCETYPEIDNAME:
5176 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_RESOURCETYPEIDNAME \n"));
5177 wrq->u.data.length = strlen(ResourceTypeIdName);
5178 Status = copy_to_user(wrq->u.data.pointer, ResourceTypeIdName, wrq->u.data.length);
5181 case RT_OID_802_11_PRIVACYOPTIONIMPLEMENTED:
5182 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PRIVACYOPTIONIMPLEMENTED \n"));
5183 ulInfo = 1; // 1 is support wep else 2 is not support.
5184 wrq->u.data.length = sizeof(ulInfo);
5185 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
5188 case RT_OID_802_11_POWERMANAGEMENTMODE:
5189 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_POWERMANAGEMENTMODE \n"));
5190 if (pAdapter->StaCfg.Psm == PSMP_ACTION)
5191 ulInfo = 1; // 1 is power active else 2 is power save.
5195 wrq->u.data.length = sizeof(ulInfo);
5196 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
5199 case OID_802_11_WEPDEFAULTKEYVALUE:
5200 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_WEPDEFAULTKEYVALUE \n"));
5201 //KeyIdxValue.KeyIdx = pAd->PortCfg.MBSSID[pAd->IoctlIF].DefaultKeyId;
5202 pKeyIdxValue = wrq->u.data.pointer;
5203 DBGPRINT(RT_DEBUG_TRACE,("KeyIdxValue.KeyIdx = %d, \n",pKeyIdxValue->KeyIdx));
5204 valueLen = pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen;
5205 NdisMoveMemory(pKeyIdxValue->Value,
5206 &pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key,
5208 pKeyIdxValue->Value[valueLen]='\0';
5210 wrq->u.data.length = sizeof(DefaultKeyIdxValue);
5212 Status = copy_to_user(wrq->u.data.pointer, pKeyIdxValue, wrq->u.data.length);
5213 DBGPRINT(RT_DEBUG_TRACE,("DefaultKeyId = %d, total len = %d, str len=%d, KeyValue= %02x %02x %02x %02x \n", pAdapter->StaCfg.DefaultKeyId, wrq->u.data.length, pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen,
5214 pAdapter->SharedKey[BSS0][0].Key[0],
5215 pAdapter->SharedKey[BSS0][1].Key[0],
5216 pAdapter->SharedKey[BSS0][2].Key[0],
5217 pAdapter->SharedKey[BSS0][3].Key[0]));
5220 case OID_802_11_WEPDEFAULTKEYID:
5221 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_WEPDEFAULTKEYID \n"));
5222 wrq->u.data.length = sizeof(UCHAR);
5223 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->StaCfg.DefaultKeyId, wrq->u.data.length);
5224 DBGPRINT(RT_DEBUG_TRACE, ("DefaultKeyId =%d \n", pAdapter->StaCfg.DefaultKeyId));
5227 case RT_OID_802_11_WEPKEYMAPPINGLENGTH:
5228 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_WEPKEYMAPPINGLENGTH \n"));
5229 wrq->u.data.length = sizeof(UCHAR);
5230 Status = copy_to_user(wrq->u.data.pointer,
5231 &pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen,
5232 wrq->u.data.length);
5235 case OID_802_11_SHORTRETRYLIMIT:
5236 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_SHORTRETRYLIMIT \n"));
5237 wrq->u.data.length = sizeof(ULONG);
5238 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
5239 ShortRetryLimit = tx_rty_cfg.field.ShortRtyLimit;
5240 DBGPRINT(RT_DEBUG_TRACE, ("ShortRetryLimit =%ld, tx_rty_cfg.field.ShortRetryLimit=%d\n", ShortRetryLimit, tx_rty_cfg.field.ShortRtyLimit));
5241 Status = copy_to_user(wrq->u.data.pointer, &ShortRetryLimit, wrq->u.data.length);
5244 case OID_802_11_LONGRETRYLIMIT:
5245 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_LONGRETRYLIMIT \n"));
5246 wrq->u.data.length = sizeof(ULONG);
5247 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
5248 LongRetryLimit = tx_rty_cfg.field.LongRtyLimit;
5249 DBGPRINT(RT_DEBUG_TRACE, ("LongRetryLimit =%ld, tx_rty_cfg.field.LongRtyLimit=%d\n", LongRetryLimit, tx_rty_cfg.field.LongRtyLimit));
5250 Status = copy_to_user(wrq->u.data.pointer, &LongRetryLimit, wrq->u.data.length);
5253 case RT_OID_802_11_PRODUCTID:
5254 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PRODUCTID \n"));
5257 sprintf(tmp, "%04x %04x\n", ((POS_COOKIE)pAdapter->OS_Cookie)->pUsb_Dev->descriptor.idVendor ,((POS_COOKIE)pAdapter->OS_Cookie)->pUsb_Dev->descriptor.idProduct);
5260 wrq->u.data.length = strlen(tmp);
5261 Status = copy_to_user(wrq->u.data.pointer, tmp, wrq->u.data.length);
5264 case RT_OID_802_11_MANUFACTUREID:
5265 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_MANUFACTUREID \n"));
5266 wrq->u.data.length = strlen(ManufacturerNAME);
5267 Status = copy_to_user(wrq->u.data.pointer, ManufacturerNAME, wrq->u.data.length);
5270 case OID_802_11_CURRENTCHANNEL:
5271 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CURRENTCHANNEL \n"));
5272 wrq->u.data.length = sizeof(UCHAR);
5273 DBGPRINT(RT_DEBUG_TRACE, ("sizeof UCHAR=%d, channel=%d \n", sizeof(UCHAR), pAdapter->CommonCfg.Channel));
5274 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Channel, wrq->u.data.length);
5275 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5277 #endif //SNMP_SUPPORT
5279 case OID_802_11_BUILD_CHANNEL_EX:
5282 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BUILD_CHANNEL_EX \n"));
5283 wrq->u.data.length = sizeof(UCHAR);
5284 #ifdef EXT_BUILD_CHANNEL_LIST
5285 DBGPRINT(RT_DEBUG_TRACE, ("Support EXT_BUILD_CHANNEL_LIST.\n"));
5288 DBGPRINT(RT_DEBUG_TRACE, ("Doesn't support EXT_BUILD_CHANNEL_LIST.\n"));
5290 #endif // EXT_BUILD_CHANNEL_LIST //
5291 Status = copy_to_user(wrq->u.data.pointer, &value, 1);
5292 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5296 case OID_802_11_GET_CH_LIST:
5298 PRT_CHANNEL_LIST_INFO pChListBuf;
5300 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CH_LIST \n"));
5301 if (pAdapter->ChannelListNum == 0)
5303 wrq->u.data.length = 0;
5307 pChListBuf = (RT_CHANNEL_LIST_INFO *) kmalloc(sizeof(RT_CHANNEL_LIST_INFO), MEM_ALLOC_FLAG);
5308 if (pChListBuf == NULL)
5310 wrq->u.data.length = 0;
5314 pChListBuf->ChannelListNum = pAdapter->ChannelListNum;
5315 for (i = 0; i < pChListBuf->ChannelListNum; i++)
5316 pChListBuf->ChannelList[i] = pAdapter->ChannelList[i].Channel;
5318 wrq->u.data.length = sizeof(RT_CHANNEL_LIST_INFO);
5319 Status = copy_to_user(wrq->u.data.pointer, pChListBuf, sizeof(RT_CHANNEL_LIST_INFO));
5320 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5327 case OID_802_11_GET_COUNTRY_CODE:
5328 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_COUNTRY_CODE \n"));
5329 wrq->u.data.length = 2;
5330 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.CountryCode, 2);
5331 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5334 case OID_802_11_GET_CHANNEL_GEOGRAPHY:
5335 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CHANNEL_GEOGRAPHY \n"));
5336 wrq->u.data.length = 1;
5337 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Geography, 1);
5338 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5342 #ifdef QOS_DLS_SUPPORT
5343 case RT_OID_802_11_QUERY_DLS:
5344 wrq->u.data.length = sizeof(BOOLEAN);
5345 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bDLSCapable, wrq->u.data.length);
5346 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_DLS(=%d)\n", pAdapter->CommonCfg.bDLSCapable));
5349 case RT_OID_802_11_QUERY_DLS_PARAM:
5351 PRT_802_11_DLS_INFO pDlsInfo = kmalloc(sizeof(RT_802_11_DLS_INFO), GFP_ATOMIC);
5352 if (pDlsInfo == NULL)
5355 for (i=0; i<MAX_NUM_OF_DLS_ENTRY; i++)
5357 RTMPMoveMemory(&pDlsInfo->Entry[i], &pAdapter->StaCfg.DLSEntry[i], sizeof(RT_802_11_DLS_UI));
5360 pDlsInfo->num = MAX_NUM_OF_DLS_ENTRY;
5361 wrq->u.data.length = sizeof(RT_802_11_DLS_INFO);
5362 Status = copy_to_user(wrq->u.data.pointer, pDlsInfo, wrq->u.data.length);
5363 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_DLS_PARAM\n"));
5369 #endif // QOS_DLS_SUPPORT //
5371 DBGPRINT(RT_DEBUG_TRACE, ("Query::unknown IOCTL's subcmd = 0x%08x\n", cmd));
5372 Status = -EOPNOTSUPP;
5378 INT rt28xx_sta_ioctl(
5379 IN struct net_device *net_dev,
5380 IN OUT struct ifreq *rq,
5384 VIRTUAL_ADAPTER *pVirtualAd = NULL;
5385 RTMP_ADAPTER *pAd = NULL;
5386 struct iwreq *wrq = (struct iwreq *) rq;
5387 BOOLEAN StateMachineTouched = FALSE;
5388 INT Status = NDIS_STATUS_SUCCESS;
5391 if (net_dev->priv_flags == INT_MAIN)
5393 pAd = net_dev->ml_priv;
5397 pVirtualAd = net_dev->ml_priv;
5398 pAd = pVirtualAd->RtmpDev->ml_priv;
5400 pObj = (POS_COOKIE) pAd->OS_Cookie;
5404 /* if 1st open fail, pAd will be free;
5405 So the net_dev->ml_priv will be NULL in 2rd open */
5409 //check if the interface is down
5410 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
5412 #ifdef CONFIG_APSTA_MIXED_SUPPORT
5413 if (wrq->u.data.pointer == NULL)
5418 if (strstr(wrq->u.data.pointer, "OpMode") == NULL)
5419 #endif // CONFIG_APSTA_MIXED_SUPPORT //
5421 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
5426 { // determine this ioctl command is comming from which interface.
5427 pObj->ioctl_if_type = INT_MAIN;
5428 pObj->ioctl_if = MAIN_MBSSID;
5434 #ifdef RALINK_28xx_QA
5435 case RTPRIV_IOCTL_ATE:
5437 RtmpDoAte(pAd, wrq);
5440 #endif // RALINK_28xx_QA //
5441 #endif // RALINK_ATE //
5443 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIFHWADDR\n"));
5444 memcpy(wrq->u.name, pAd->CurrentAddress, ETH_ALEN);
5448 char *name=&wrq->u.name[0];
5449 rt_ioctl_giwname(net_dev, NULL, name, NULL);
5452 case SIOCGIWESSID: //Get ESSID
5454 struct iw_point *essid=&wrq->u.essid;
5455 rt_ioctl_giwessid(net_dev, NULL, essid, essid->pointer);
5458 case SIOCSIWESSID: //Set ESSID
5460 struct iw_point *essid=&wrq->u.essid;
5461 rt_ioctl_siwessid(net_dev, NULL, essid, essid->pointer);
5464 case SIOCSIWNWID: // set network id (the cell)
5465 case SIOCGIWNWID: // get network id
5466 Status = -EOPNOTSUPP;
5468 case SIOCSIWFREQ: //set channel/frequency (Hz)
5470 struct iw_freq *freq=&wrq->u.freq;
5471 rt_ioctl_siwfreq(net_dev, NULL, freq, NULL);
5474 case SIOCGIWFREQ: // get channel/frequency (Hz)
5476 struct iw_freq *freq=&wrq->u.freq;
5477 rt_ioctl_giwfreq(net_dev, NULL, freq, NULL);
5480 case SIOCSIWNICKN: //set node name/nickname
5482 struct iw_point *data=&wrq->u.data;
5483 rt_ioctl_siwnickn(net_dev, NULL, data, NULL);
5486 case SIOCGIWNICKN: //get node name/nickname
5488 struct iw_point *data=&wrq->u.data;
5489 rt_ioctl_giwnickn(net_dev, NULL, data, NULL);
5492 case SIOCGIWRATE: //get default bit rate (bps)
5493 rt_ioctl_giwrate(net_dev, NULL, &wrq->u, NULL);
5495 case SIOCSIWRATE: //set default bit rate (bps)
5496 rt_ioctl_siwrate(net_dev, NULL, &wrq->u, NULL);
5498 case SIOCGIWRTS: // get RTS/CTS threshold (bytes)
5500 struct iw_param *rts=&wrq->u.rts;
5501 rt_ioctl_giwrts(net_dev, NULL, rts, NULL);
5504 case SIOCSIWRTS: //set RTS/CTS threshold (bytes)
5506 struct iw_param *rts=&wrq->u.rts;
5507 rt_ioctl_siwrts(net_dev, NULL, rts, NULL);
5510 case SIOCGIWFRAG: //get fragmentation thr (bytes)
5512 struct iw_param *frag=&wrq->u.frag;
5513 rt_ioctl_giwfrag(net_dev, NULL, frag, NULL);
5516 case SIOCSIWFRAG: //set fragmentation thr (bytes)
5518 struct iw_param *frag=&wrq->u.frag;
5519 rt_ioctl_siwfrag(net_dev, NULL, frag, NULL);
5522 case SIOCGIWENCODE: //get encoding token & mode
5524 struct iw_point *erq=&wrq->u.encoding;
5526 rt_ioctl_giwencode(net_dev, NULL, erq, erq->pointer);
5529 case SIOCSIWENCODE: //set encoding token & mode
5531 struct iw_point *erq=&wrq->u.encoding;
5533 rt_ioctl_siwencode(net_dev, NULL, erq, erq->pointer);
5536 case SIOCGIWAP: //get access point MAC addresses
5538 struct sockaddr *ap_addr=&wrq->u.ap_addr;
5539 rt_ioctl_giwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
5542 case SIOCSIWAP: //set access point MAC addresses
5544 struct sockaddr *ap_addr=&wrq->u.ap_addr;
5545 rt_ioctl_siwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
5548 case SIOCGIWMODE: //get operation mode
5550 __u32 *mode=&wrq->u.mode;
5551 rt_ioctl_giwmode(net_dev, NULL, mode, NULL);
5554 case SIOCSIWMODE: //set operation mode
5556 __u32 *mode=&wrq->u.mode;
5557 rt_ioctl_siwmode(net_dev, NULL, mode, NULL);
5560 case SIOCGIWSENS: //get sensitivity (dBm)
5561 case SIOCSIWSENS: //set sensitivity (dBm)
5562 case SIOCGIWPOWER: //get Power Management settings
5563 case SIOCSIWPOWER: //set Power Management settings
5564 case SIOCGIWTXPOW: //get transmit power (dBm)
5565 case SIOCSIWTXPOW: //set transmit power (dBm)
5566 case SIOCGIWRANGE: //Get range of parameters
5567 case SIOCGIWRETRY: //get retry limits and lifetime
5568 case SIOCSIWRETRY: //set retry limits and lifetime
5569 Status = -EOPNOTSUPP;
5572 case RT_PRIV_IOCTL_EXT:
5573 subcmd = wrq->u.data.flags;
5574 if( subcmd & OID_GET_SET_TOGGLE)
5575 Status = RTMPSetInformation(pAd, rq, subcmd);
5577 Status = RTMPQueryInformation(pAd, rq, subcmd);
5580 if (wrq->u.data.pointer)
5582 if ( access_ok(VERIFY_WRITE, wrq->u.data.pointer, sizeof(privtab)) != TRUE)
5584 wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
5585 if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
5589 case RTPRIV_IOCTL_SET:
5590 if(access_ok(VERIFY_READ, wrq->u.data.pointer, wrq->u.data.length) != TRUE)
5592 rt_ioctl_setparam(net_dev, NULL, NULL, wrq->u.data.pointer);
5594 case RTPRIV_IOCTL_GSITESURVEY:
5595 RTMPIoctlGetSiteSurvey(pAd, wrq);
5598 case RTPRIV_IOCTL_MAC:
5599 RTMPIoctlMAC(pAd, wrq);
5601 case RTPRIV_IOCTL_E2P:
5602 RTMPIoctlE2PROM(pAd, wrq);
5605 case RTPRIV_IOCTL_RF:
5606 RTMPIoctlRF(pAd, wrq);
5613 DBGPRINT(RT_DEBUG_ERROR, ("IOCTL::unknown IOCTL's cmd = 0x%08x\n", cmd));
5614 Status = -EOPNOTSUPP;
5618 if(StateMachineTouched) // Upper layer sent a MLME-related operations
5619 RT28XX_MLME_HANDLER(pAd);
5625 ==========================================================================
5629 TRUE if all parameters are OK, FALSE otherwise
5630 ==========================================================================
5633 IN PRTMP_ADAPTER pAdapter,
5636 NDIS_802_11_SSID Ssid, *pSsid=NULL;
5637 BOOLEAN StateMachineTouched = FALSE;
5640 if( strlen(arg) <= MAX_LEN_OF_SSID)
5642 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
5643 if (strlen(arg) != 0)
5645 NdisMoveMemory(Ssid.Ssid, arg, strlen(arg));
5646 Ssid.SsidLength = strlen(arg);
5650 Ssid.SsidLength = 0;
5651 memcpy(Ssid.Ssid, "", 0);
5652 pAdapter->StaCfg.BssType = BSS_INFRA;
5653 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
5654 pAdapter->StaCfg.WepStatus = Ndis802_11EncryptionDisabled;
5658 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
5660 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
5661 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
5664 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
5665 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
5666 pAdapter->bConfigChanged = TRUE;
5668 MlmeEnqueue(pAdapter,
5669 MLME_CNTL_STATE_MACHINE,
5671 sizeof(NDIS_802_11_SSID),
5674 StateMachineTouched = TRUE;
5675 DBGPRINT(RT_DEBUG_TRACE, ("Set_SSID_Proc::(Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
5680 if (StateMachineTouched) // Upper layer sent a MLME-related operations
5681 RT28XX_MLME_HANDLER(pAdapter);
5688 ==========================================================================
5690 Set WmmCapable Enable or Disable
5692 TRUE if all parameters are OK, FALSE otherwise
5693 ==========================================================================
5695 INT Set_WmmCapable_Proc(
5696 IN PRTMP_ADAPTER pAd,
5699 BOOLEAN bWmmCapable;
5701 bWmmCapable = simple_strtol(arg, 0, 10);
5703 if ((bWmmCapable == 1)
5705 && (pAd->NumberOfPipes >= 5)
5708 pAd->CommonCfg.bWmmCapable = TRUE;
5709 else if (bWmmCapable == 0)
5710 pAd->CommonCfg.bWmmCapable = FALSE;
5712 return FALSE; //Invalid argument
5714 DBGPRINT(RT_DEBUG_TRACE, ("Set_WmmCapable_Proc::(bWmmCapable=%d)\n",
5715 pAd->CommonCfg.bWmmCapable));
5719 #endif // WMM_SUPPORT //
5722 ==========================================================================
5724 Set Network Type(Infrastructure/Adhoc mode)
5726 TRUE if all parameters are OK, FALSE otherwise
5727 ==========================================================================
5729 INT Set_NetworkType_Proc(
5730 IN PRTMP_ADAPTER pAdapter,
5735 if (strcmp(arg, "Adhoc") == 0)
5737 if (pAdapter->StaCfg.BssType != BSS_ADHOC)
5739 // Config has changed
5740 pAdapter->bConfigChanged = TRUE;
5741 if (MONITOR_ON(pAdapter))
5743 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
5744 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5746 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5747 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5748 pAdapter->StaCfg.bAutoReconnect = TRUE;
5749 LinkDown(pAdapter, FALSE);
5751 if (INFRA_ON(pAdapter))
5753 //BOOLEAN Cancelled;
5754 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
5755 // Since calling this indicate user don't want to connect to that SSID anymore.
5756 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
5757 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
5759 LinkDown(pAdapter, FALSE);
5761 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n"));
5764 pAdapter->StaCfg.BssType = BSS_ADHOC;
5765 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
5766 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(AD-HOC)\n"));
5768 else if (strcmp(arg, "Infra") == 0)
5770 if (pAdapter->StaCfg.BssType != BSS_INFRA)
5772 // Config has changed
5773 pAdapter->bConfigChanged = TRUE;
5774 if (MONITOR_ON(pAdapter))
5776 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
5777 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5779 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5780 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5781 pAdapter->StaCfg.bAutoReconnect = TRUE;
5782 LinkDown(pAdapter, FALSE);
5784 if (ADHOC_ON(pAdapter))
5786 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
5787 // Since calling this indicate user don't want to connect to that SSID anymore.
5788 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
5789 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
5791 LinkDown(pAdapter, FALSE);
5794 pAdapter->StaCfg.BssType = BSS_INFRA;
5795 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
5796 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(INFRA)\n"));
5798 pAdapter->StaCfg.BssType = BSS_INFRA;
5800 else if (strcmp(arg, "Monitor") == 0)
5803 BCN_TIME_CFG_STRUC csr;
5804 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_INFRA_ON);
5805 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_ADHOC_ON);
5806 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5807 // disable all periodic state machine
5808 pAdapter->StaCfg.bAutoReconnect = FALSE;
5809 // reset all mlme state machine
5810 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
5811 DBGPRINT(RT_DEBUG_TRACE, ("fOP_STATUS_MEDIA_STATE_CONNECTED \n"));
5812 if (pAdapter->CommonCfg.CentralChannel == 0)
5814 #ifdef DOT11_N_SUPPORT
5815 if (pAdapter->CommonCfg.PhyMode == PHY_11AN_MIXED)
5816 pAdapter->CommonCfg.CentralChannel = 36;
5818 #endif // DOT11_N_SUPPORT //
5819 pAdapter->CommonCfg.CentralChannel = 6;
5821 #ifdef DOT11_N_SUPPORT
5823 N_ChannelCheck(pAdapter);
5824 #endif // DOT11_N_SUPPORT //
5826 #ifdef DOT11_N_SUPPORT
5827 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
5828 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
5829 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_ABOVE)
5831 // 40MHz ,control channel at lower
5832 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5833 bbpValue &= (~0x18);
5835 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5836 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
5837 // RX : control channel at lower
5838 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
5839 bbpValue &= (~0x20);
5840 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
5842 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
5843 Value &= 0xfffffffe;
5844 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
5845 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel + 2;
5846 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
5847 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
5848 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
5849 pAdapter->CommonCfg.Channel,
5850 pAdapter->CommonCfg.CentralChannel));
5852 else if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
5853 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
5854 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_BELOW)
5856 // 40MHz ,control channel at upper
5857 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5858 bbpValue &= (~0x18);
5860 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5861 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
5862 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
5864 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
5866 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
5868 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
5869 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel - 2;
5870 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
5871 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
5872 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
5873 pAdapter->CommonCfg.Channel,
5874 pAdapter->CommonCfg.CentralChannel));
5877 #endif // DOT11_N_SUPPORT //
5880 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5881 bbpValue &= (~0x18);
5882 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5883 pAdapter->CommonCfg.BBPCurrentBW = BW_20;
5884 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.Channel, FALSE);
5885 AsicLockChannel(pAdapter, pAdapter->CommonCfg.Channel);
5886 DBGPRINT(RT_DEBUG_TRACE, ("BW_20, Channel(%d)\n", pAdapter->CommonCfg.Channel));
5888 // Enable Rx with promiscuous reception
5889 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, 0x3);
5890 // ASIC supporsts sniffer function with replacing RSSI with timestamp.
5891 //RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5893 //RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5895 RTMP_IO_READ32(pAdapter, BCN_TIME_CFG, &csr.word);
5896 csr.field.bBeaconGen = 0;
5897 csr.field.bTBTTEnable = 0;
5898 csr.field.TsfSyncMode = 0;
5899 RTMP_IO_WRITE32(pAdapter, BCN_TIME_CFG, csr.word);
5901 pAdapter->StaCfg.BssType = BSS_MONITOR;
5902 pAdapter->net_dev->type = ARPHRD_IEEE80211_PRISM; //ARPHRD_IEEE80211; // IEEE80211
5903 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(MONITOR)\n"));
5906 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
5907 pAdapter->StaCfg.WpaState = SS_NOTUSE;
5909 DBGPRINT(RT_DEBUG_TRACE, ("Set_NetworkType_Proc::(NetworkType=%d)\n", pAdapter->StaCfg.BssType));
5915 ==========================================================================
5917 Set Authentication mode
5919 TRUE if all parameters are OK, FALSE otherwise
5920 ==========================================================================
5922 INT Set_AuthMode_Proc(
5923 IN PRTMP_ADAPTER pAdapter,
5926 if ((strcmp(arg, "WEPAUTO") == 0) || (strcmp(arg, "wepauto") == 0))
5927 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeAutoSwitch;
5928 else if ((strcmp(arg, "OPEN") == 0) || (strcmp(arg, "open") == 0))
5929 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
5930 else if ((strcmp(arg, "SHARED") == 0) || (strcmp(arg, "shared") == 0))
5931 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
5932 else if ((strcmp(arg, "WPAPSK") == 0) || (strcmp(arg, "wpapsk") == 0))
5933 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
5934 else if ((strcmp(arg, "WPANONE") == 0) || (strcmp(arg, "wpanone") == 0))
5935 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
5936 else if ((strcmp(arg, "WPA2PSK") == 0) || (strcmp(arg, "wpa2psk") == 0))
5937 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
5938 #ifdef WPA_SUPPLICANT_SUPPORT
5939 else if ((strcmp(arg, "WPA") == 0) || (strcmp(arg, "wpa") == 0))
5940 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
5941 else if ((strcmp(arg, "WPA2") == 0) || (strcmp(arg, "wpa2") == 0))
5942 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
5943 #endif // WPA_SUPPLICANT_SUPPORT //
5947 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
5949 DBGPRINT(RT_DEBUG_TRACE, ("Set_AuthMode_Proc::(AuthMode=%d)\n", pAdapter->StaCfg.AuthMode));
5955 ==========================================================================
5959 TRUE if all parameters are OK, FALSE otherwise
5960 ==========================================================================
5962 INT Set_EncrypType_Proc(
5963 IN PRTMP_ADAPTER pAdapter,
5966 if ((strcmp(arg, "NONE") == 0) || (strcmp(arg, "none") == 0))
5968 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5969 return TRUE; // do nothing
5971 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
5972 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
5973 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
5975 else if ((strcmp(arg, "WEP") == 0) || (strcmp(arg, "wep") == 0))
5977 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5978 return TRUE; // do nothing
5980 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
5981 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
5982 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
5984 else if ((strcmp(arg, "TKIP") == 0) || (strcmp(arg, "tkip") == 0))
5986 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
5987 return TRUE; // do nothing
5989 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
5990 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
5991 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
5993 else if ((strcmp(arg, "AES") == 0) || (strcmp(arg, "aes") == 0))
5995 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
5996 return TRUE; // do nothing
5998 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
5999 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
6000 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
6005 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
6007 DBGPRINT(RT_DEBUG_TRACE, ("Set_EncrypType_Proc::(EncrypType=%d)\n", pAdapter->StaCfg.WepStatus));
6013 ==========================================================================
6017 TRUE if all parameters are OK, FALSE otherwise
6018 ==========================================================================
6020 INT Set_DefaultKeyID_Proc(
6021 IN PRTMP_ADAPTER pAdapter,
6026 KeyIdx = simple_strtol(arg, 0, 10);
6027 if((KeyIdx >= 1 ) && (KeyIdx <= 4))
6028 pAdapter->StaCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1 );
6030 return FALSE; //Invalid argument
6032 DBGPRINT(RT_DEBUG_TRACE, ("Set_DefaultKeyID_Proc::(DefaultKeyID=%d)\n", pAdapter->StaCfg.DefaultKeyId));
6038 ==========================================================================
6042 TRUE if all parameters are OK, FALSE otherwise
6043 ==========================================================================
6046 IN PRTMP_ADAPTER pAdapter,
6051 UCHAR CipherAlg=CIPHER_WEP64;
6053 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6054 return TRUE; // do nothing
6056 KeyLen = strlen(arg);
6060 case 5: //wep 40 Ascii type
6061 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
6062 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
6063 CipherAlg = CIPHER_WEP64;
6064 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
6066 case 10: //wep 40 Hex type
6067 for(i=0; i < KeyLen; i++)
6069 if( !isxdigit(*(arg+i)) )
6070 return FALSE; //Not Hex value;
6072 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
6073 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
6074 CipherAlg = CIPHER_WEP64;
6075 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
6077 case 13: //wep 104 Ascii type
6078 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
6079 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
6080 CipherAlg = CIPHER_WEP128;
6081 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
6083 case 26: //wep 104 Hex type
6084 for(i=0; i < KeyLen; i++)
6086 if( !isxdigit(*(arg+i)) )
6087 return FALSE; //Not Hex value;
6089 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
6090 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
6091 CipherAlg = CIPHER_WEP128;
6092 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
6094 default: //Invalid argument
6095 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::Invalid argument (=%s)\n", arg));
6099 pAdapter->SharedKey[BSS0][0].CipherAlg = CipherAlg;
6101 // Set keys (into ASIC)
6102 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6104 else // Old WEP stuff
6106 AsicAddSharedKeyEntry(pAdapter,
6109 pAdapter->SharedKey[BSS0][0].CipherAlg,
6110 pAdapter->SharedKey[BSS0][0].Key,
6118 ==========================================================================
6123 TRUE if all parameters are OK, FALSE otherwise
6124 ==========================================================================
6127 IN PRTMP_ADAPTER pAdapter,
6132 UCHAR CipherAlg=CIPHER_WEP64;
6134 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6135 return TRUE; // do nothing
6137 KeyLen = strlen(arg);
6141 case 5: //wep 40 Ascii type
6142 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
6143 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
6144 CipherAlg = CIPHER_WEP64;
6145 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
6147 case 10: //wep 40 Hex type
6148 for(i=0; i < KeyLen; i++)
6150 if( !isxdigit(*(arg+i)) )
6151 return FALSE; //Not Hex value;
6153 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
6154 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
6155 CipherAlg = CIPHER_WEP64;
6156 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
6158 case 13: //wep 104 Ascii type
6159 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
6160 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
6161 CipherAlg = CIPHER_WEP128;
6162 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
6164 case 26: //wep 104 Hex type
6165 for(i=0; i < KeyLen; i++)
6167 if( !isxdigit(*(arg+i)) )
6168 return FALSE; //Not Hex value;
6170 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
6171 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
6172 CipherAlg = CIPHER_WEP128;
6173 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
6175 default: //Invalid argument
6176 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::Invalid argument (=%s)\n", arg));
6179 pAdapter->SharedKey[BSS0][1].CipherAlg = CipherAlg;
6181 // Set keys (into ASIC)
6182 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6184 else // Old WEP stuff
6186 AsicAddSharedKeyEntry(pAdapter,
6189 pAdapter->SharedKey[BSS0][1].CipherAlg,
6190 pAdapter->SharedKey[BSS0][1].Key,
6198 ==========================================================================
6202 TRUE if all parameters are OK, FALSE otherwise
6203 ==========================================================================
6206 IN PRTMP_ADAPTER pAdapter,
6211 UCHAR CipherAlg=CIPHER_WEP64;
6213 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6214 return TRUE; // do nothing
6216 KeyLen = strlen(arg);
6220 case 5: //wep 40 Ascii type
6221 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
6222 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
6223 CipherAlg = CIPHER_WEP64;
6224 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
6226 case 10: //wep 40 Hex type
6227 for(i=0; i < KeyLen; i++)
6229 if( !isxdigit(*(arg+i)) )
6230 return FALSE; //Not Hex value;
6232 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
6233 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
6234 CipherAlg = CIPHER_WEP64;
6235 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
6237 case 13: //wep 104 Ascii type
6238 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
6239 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
6240 CipherAlg = CIPHER_WEP128;
6241 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
6243 case 26: //wep 104 Hex type
6244 for(i=0; i < KeyLen; i++)
6246 if( !isxdigit(*(arg+i)) )
6247 return FALSE; //Not Hex value;
6249 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
6250 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
6251 CipherAlg = CIPHER_WEP128;
6252 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
6254 default: //Invalid argument
6255 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::Invalid argument (=%s)\n", arg));
6258 pAdapter->SharedKey[BSS0][2].CipherAlg = CipherAlg;
6260 // Set keys (into ASIC)
6261 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6263 else // Old WEP stuff
6265 AsicAddSharedKeyEntry(pAdapter,
6268 pAdapter->SharedKey[BSS0][2].CipherAlg,
6269 pAdapter->SharedKey[BSS0][2].Key,
6277 ==========================================================================
6281 TRUE if all parameters are OK, FALSE otherwise
6282 ==========================================================================
6285 IN PRTMP_ADAPTER pAdapter,
6290 UCHAR CipherAlg=CIPHER_WEP64;
6292 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6293 return TRUE; // do nothing
6295 KeyLen = strlen(arg);
6299 case 5: //wep 40 Ascii type
6300 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
6301 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
6302 CipherAlg = CIPHER_WEP64;
6303 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
6305 case 10: //wep 40 Hex type
6306 for(i=0; i < KeyLen; i++)
6308 if( !isxdigit(*(arg+i)) )
6309 return FALSE; //Not Hex value;
6311 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
6312 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
6313 CipherAlg = CIPHER_WEP64;
6314 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
6316 case 13: //wep 104 Ascii type
6317 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
6318 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
6319 CipherAlg = CIPHER_WEP128;
6320 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
6322 case 26: //wep 104 Hex type
6323 for(i=0; i < KeyLen; i++)
6325 if( !isxdigit(*(arg+i)) )
6326 return FALSE; //Not Hex value;
6328 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
6329 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
6330 CipherAlg = CIPHER_WEP128;
6331 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
6333 default: //Invalid argument
6334 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::Invalid argument (=%s)\n", arg));
6337 pAdapter->SharedKey[BSS0][3].CipherAlg = CipherAlg;
6339 // Set keys (into ASIC)
6340 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6342 else // Old WEP stuff
6344 AsicAddSharedKeyEntry(pAdapter,
6347 pAdapter->SharedKey[BSS0][3].CipherAlg,
6348 pAdapter->SharedKey[BSS0][3].Key,
6357 ==========================================================================
6361 TRUE if all parameters are OK, FALSE otherwise
6362 ==========================================================================
6364 INT Set_WPAPSK_Proc(
6365 IN PRTMP_ADAPTER pAdapter,
6368 UCHAR keyMaterial[40];
6370 if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
6371 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
6372 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
6374 return TRUE; // do nothing
6376 DBGPRINT(RT_DEBUG_TRACE, ("Set_WPAPSK_Proc::(WPAPSK=%s)\n", arg));
6378 NdisZeroMemory(keyMaterial, 40);
6380 if ((strlen(arg) < 8) || (strlen(arg) > 64))
6382 DBGPRINT(RT_DEBUG_TRACE, ("Set failed!!(WPAPSK=%s), WPAPSK key-string required 8 ~ 64 characters \n", arg));
6386 if (strlen(arg) == 64)
6388 AtoH(arg, keyMaterial, 32);
6389 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
6394 PasswordHash((char *)arg, pAdapter->MlmeAux.Ssid, pAdapter->MlmeAux.SsidLen, keyMaterial);
6395 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
6400 if(pAdapter->StaCfg.BssType == BSS_ADHOC &&
6401 pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
6403 pAdapter->StaCfg.WpaState = SS_NOTUSE;
6407 // Start STA supplicant state machine
6408 pAdapter->StaCfg.WpaState = SS_START;
6415 ==========================================================================
6417 Set Power Saving mode
6419 TRUE if all parameters are OK, FALSE otherwise
6420 ==========================================================================
6422 INT Set_PSMode_Proc(
6423 IN PRTMP_ADAPTER pAdapter,
6426 if (pAdapter->StaCfg.BssType == BSS_INFRA)
6428 if ((strcmp(arg, "Max_PSP") == 0) ||
6429 (strcmp(arg, "max_psp") == 0) ||
6430 (strcmp(arg, "MAX_PSP") == 0))
6432 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6433 // to exclude certain situations.
6434 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6435 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeMAX_PSP;
6436 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeMAX_PSP;
6437 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6438 pAdapter->StaCfg.DefaultListenCount = 5;
6441 else if ((strcmp(arg, "Fast_PSP") == 0) ||
6442 (strcmp(arg, "fast_psp") == 0) ||
6443 (strcmp(arg, "FAST_PSP") == 0))
6445 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6446 // to exclude certain situations.
6447 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6448 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6449 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeFast_PSP;
6450 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeFast_PSP;
6451 pAdapter->StaCfg.DefaultListenCount = 3;
6453 else if ((strcmp(arg, "Legacy_PSP") == 0) ||
6454 (strcmp(arg, "legacy_psp") == 0) ||
6455 (strcmp(arg, "LEGACY_PSP") == 0))
6457 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6458 // to exclude certain situations.
6459 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6460 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6461 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeLegacy_PSP;
6462 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeLegacy_PSP;
6463 pAdapter->StaCfg.DefaultListenCount = 3;
6467 //Default Ndis802_11PowerModeCAM
6468 // clear PSM bit immediately
6469 MlmeSetPsmBit(pAdapter, PWR_ACTIVE);
6470 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6471 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6472 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
6473 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
6476 DBGPRINT(RT_DEBUG_TRACE, ("Set_PSMode_Proc::(PSMode=%ld)\n", pAdapter->StaCfg.WindowsPowerMode));
6485 #ifdef WPA_SUPPLICANT_SUPPORT
6487 ==========================================================================
6489 Set WpaSupport flag.
6491 0: Driver ignore wpa_supplicant.
6492 1: wpa_supplicant initiates scanning and AP selection.
6493 2: driver takes care of scanning, AP selection, and IEEE 802.11 association parameters.
6495 TRUE if all parameters are OK, FALSE otherwise
6496 ==========================================================================
6498 INT Set_Wpa_Support(
6499 IN PRTMP_ADAPTER pAd,
6503 if ( simple_strtol(arg, 0, 10) == 0)
6504 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
6505 else if ( simple_strtol(arg, 0, 10) == 1)
6506 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE;
6507 else if ( simple_strtol(arg, 0, 10) == 2)
6508 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE_WITH_WEB_UI;
6510 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
6512 DBGPRINT(RT_DEBUG_TRACE, ("Set_Wpa_Support::(WpaSupplicantUP=%d)\n", pAd->StaCfg.WpaSupplicantUP));
6516 #endif // WPA_SUPPLICANT_SUPPORT //
6520 ==========================================================================
6524 pAdapter Pointer to our adapter
6525 wrq Pointer to the ioctl argument
6532 1.) iwpriv ra0 mac 0 ==> read MAC where Addr=0x0
6533 2.) iwpriv ra0 mac 0=12 ==> write MAC where Addr=0x0, value=12
6534 ==========================================================================
6537 IN PRTMP_ADAPTER pAdapter,
6538 IN struct iwreq *wrq)
6546 UCHAR temp[16], temp2[16];
6547 UINT32 macValue = 0;
6549 BOOLEAN bIsPrintAllMAC = FALSE;
6552 memset(msg, 0x00, 1024);
6553 if (wrq->u.data.length > 1) //No parameters.
6555 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6558 //Parsing Read or Write
6563 if ((value = rtstrchr(this_char, '=')) != NULL)
6566 if (!value || !*value)
6569 if(strlen(this_char) > 4)
6572 j = strlen(this_char);
6575 if(this_char[j] > 'f' || this_char[j] < '0')
6580 k = j = strlen(this_char);
6583 this_char[4-k+j] = this_char[j];
6587 this_char[3-k++]='0';
6590 if(strlen(this_char) == 4)
6592 AtoH(this_char, temp, 2);
6593 macAddr = *temp*256 + temp[1];
6594 if (macAddr < 0xFFFF)
6596 RTMP_IO_READ32(pAdapter, macAddr, &macValue);
6597 DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%lx, MacValue=%x\n", macAddr, macValue));
6598 sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr , macValue);
6601 {//Invalid parametes, so default printk all mac
6602 bIsPrintAllMAC = TRUE;
6609 memcpy(&temp2, value, strlen(value));
6610 temp2[strlen(value)] = '\0';
6613 if((strlen(this_char) > 4) || strlen(temp2) > 8)
6616 j = strlen(this_char);
6619 if(this_char[j] > 'f' || this_char[j] < '0')
6626 if(temp2[j] > 'f' || temp2[j] < '0')
6631 k = j = strlen(this_char);
6634 this_char[4-k+j] = this_char[j];
6638 this_char[3-k++]='0';
6642 k = j = strlen(temp2);
6645 temp2[8-k+j] = temp2[j];
6653 AtoH(this_char, temp, 2);
6654 macAddr = *temp*256 + temp[1];
6656 AtoH(temp2, temp, 4);
6657 macValue = *temp*256*256*256 + temp[1]*256*256 + temp[2]*256 + temp[3];
6660 if (macAddr == (HW_DEBUG_SETTING_BASE + 4))
6662 // 0x2bf4: byte0 non-zero: enable R17 tuning, 0: disable R17 tuning
6663 if (macValue & 0x000000ff)
6665 pAdapter->BbpTuning.bEnable = TRUE;
6666 DBGPRINT(RT_DEBUG_TRACE,("turn on R17 tuning\n"));
6671 pAdapter->BbpTuning.bEnable = FALSE;
6672 R66 = 0x26 + GET_LNA_GAIN(pAdapter);
6674 if (ATE_ON(pAdapter))
6676 ATE_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R66, (0x26 + GET_LNA_GAIN(pAdapter)));
6679 #endif // RALINK_ATE //
6680 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R66, (0x26 + GET_LNA_GAIN(pAdapter)));
6681 DBGPRINT(RT_DEBUG_TRACE,("turn off R17 tuning, restore to 0x%02x\n", R66));
6686 DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%02lx, MacValue=0x%x\n", macAddr, macValue));
6688 RTMP_IO_WRITE32(pAdapter, macAddr, macValue);
6689 sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr, macValue);
6694 bIsPrintAllMAC = TRUE;
6698 struct file *file_w;
6699 PCHAR fileName = "MacDump.txt";
6700 mm_segment_t orig_fs;
6706 file_w = filp_open(fileName, O_WRONLY|O_CREAT, 0);
6709 DBGPRINT(RT_DEBUG_TRACE, ("-->2) %s: Error %ld opening %s\n", __func__, -PTR_ERR(file_w), fileName));
6713 if (file_w->f_op && file_w->f_op->write)
6718 while (macAddr <= 0x1800)
6720 RTMP_IO_READ32(pAdapter, macAddr, &macValue);
6721 sprintf(msg, "%08lx = %08X\n", macAddr, macValue);
6723 // write data to file
6724 file_w->f_op->write(file_w, msg, strlen(msg), &file_w->f_pos);
6729 sprintf(msg, "\nDump all MAC values to %s\n", fileName);
6731 filp_close(file_w, NULL);
6735 if(strlen(msg) == 1)
6736 sprintf(msg+strlen(msg), "===>Error command format!");
6738 // Copy the information into the user buffer
6739 wrq->u.data.length = strlen(msg);
6740 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6742 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlMAC\n\n"));
6746 ==========================================================================
6750 pAdapter Pointer to our adapter
6751 wrq Pointer to the ioctl argument
6758 1.) iwpriv ra0 e2p 0 ==> read E2PROM where Addr=0x0
6759 2.) iwpriv ra0 e2p 0=1234 ==> write E2PROM where Addr=0x0, value=1234
6760 ==========================================================================
6762 VOID RTMPIoctlE2PROM(
6763 IN PRTMP_ADAPTER pAdapter,
6764 IN struct iwreq *wrq)
6772 UCHAR temp[16], temp2[16];
6775 BOOLEAN bIsPrintAllE2P = FALSE;
6778 memset(msg, 0x00, 1024);
6779 if (wrq->u.data.length > 1) //No parameters.
6781 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6784 //Parsing Read or Write
6791 if ((value = rtstrchr(this_char, '=')) != NULL)
6794 if (!value || !*value)
6798 if(strlen(this_char) > 4)
6801 j = strlen(this_char);
6804 if(this_char[j] > 'f' || this_char[j] < '0')
6809 k = j = strlen(this_char);
6812 this_char[4-k+j] = this_char[j];
6816 this_char[3-k++]='0';
6819 if(strlen(this_char) == 4)
6821 AtoH(this_char, temp, 2);
6822 eepAddr = *temp*256 + temp[1];
6823 if (eepAddr < 0xFFFF)
6825 RT28xx_EEPROM_READ16(pAdapter, eepAddr, eepValue);
6826 sprintf(msg+strlen(msg), "[0x%04X]:0x%04X ", eepAddr , eepValue);
6829 {//Invalid parametes, so default printk all bbp
6830 bIsPrintAllE2P = TRUE;
6837 memcpy(&temp2, value, strlen(value));
6838 temp2[strlen(value)] = '\0';
6841 if((strlen(this_char) > 4) || strlen(temp2) > 8)
6844 j = strlen(this_char);
6847 if(this_char[j] > 'f' || this_char[j] < '0')
6853 if(temp2[j] > 'f' || temp2[j] < '0')
6858 k = j = strlen(this_char);
6861 this_char[4-k+j] = this_char[j];
6865 this_char[3-k++]='0';
6869 k = j = strlen(temp2);
6872 temp2[4-k+j] = temp2[j];
6879 AtoH(this_char, temp, 2);
6880 eepAddr = *temp*256 + temp[1];
6882 AtoH(temp2, temp, 2);
6883 eepValue = *temp*256 + temp[1];
6885 RT28xx_EEPROM_WRITE16(pAdapter, eepAddr, eepValue);
6886 sprintf(msg+strlen(msg), "[0x%02X]:%02X ", eepAddr, eepValue);
6890 bIsPrintAllE2P = TRUE;
6894 struct file *file_w;
6895 PCHAR fileName = "EEPROMDump.txt";
6896 mm_segment_t orig_fs;
6902 file_w = filp_open(fileName, O_WRONLY|O_CREAT, 0);
6905 DBGPRINT(RT_DEBUG_TRACE, ("-->2) %s: Error %ld opening %s\n", __func__, -PTR_ERR(file_w), fileName));
6909 if (file_w->f_op && file_w->f_op->write)
6914 while (eepAddr <= 0xFE)
6916 RT28xx_EEPROM_READ16(pAdapter, eepAddr, eepValue);
6917 sprintf(msg, "%08x = %04x\n", eepAddr , eepValue);
6919 // write data to file
6920 file_w->f_op->write(file_w, msg, strlen(msg), &file_w->f_pos);
6925 sprintf(msg, "\nDump all EEPROM values to %s\n", fileName);
6927 filp_close(file_w, NULL);
6931 if(strlen(msg) == 1)
6932 sprintf(msg+strlen(msg), "===>Error command format!");
6935 // Copy the information into the user buffer
6936 wrq->u.data.length = strlen(msg);
6937 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6939 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlE2PROM\n"));
6943 ==========================================================================
6945 Read / Write RF register
6947 pAdapter Pointer to our adapter
6948 wrq Pointer to the ioctl argument
6955 1.) iwpriv ra0 rf ==> read all RF registers
6956 2.) iwpriv ra0 rf 1 ==> read RF where RegID=1
6957 3.) iwpriv ra0 rf 1=10 ==> write RF R1=0x10
6958 ==========================================================================
6961 IN PRTMP_ADAPTER pAdapter,
6962 IN struct iwreq *wrq)
6972 BOOLEAN bIsPrintAllRF = FALSE;
6975 memset(msg, 0x00, 2048);
6976 if (wrq->u.data.length > 1) //No parameters.
6978 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6981 //Parsing Read or Write
6986 if ((value = strchr(this_char, '=')) != NULL)
6989 if (!value || !*value)
6991 if (sscanf(this_char, "%d", &(rfId)) == 1)
6995 // In RT2860 ATE mode, we do not load 8051 firmware.
6996 //We must access RF directly.
6997 // For RT2870 ATE mode, ATE_RF_IO_WRITE8(/READ8)_BY_REG_ID are redefined.
6999 if (ATE_ON(pAdapter))
7001 ATE_RF_IO_READ8_BY_REG_ID(pAdapter, rfId, ®RF);
7004 #endif // RALINK_ATE //
7005 // according to Andy, Gary, David require.
7006 // the command rf shall read rf register directly for dubug.
7007 // BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
7008 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
7010 sprintf(msg+strlen(msg), "R%02d[0x%02x]:%02X ", rfId, rfId*2, regRF);
7013 {//Invalid parametes, so default printk all RF
7014 bIsPrintAllRF = TRUE;
7019 { //Invalid parametes, so default printk all RF
7020 bIsPrintAllRF = TRUE;
7026 if ((sscanf(this_char, "%d", &(rfId)) == 1) && (sscanf(value, "%lx", &(rfValue)) == 1))
7030 // In RT2860 ATE mode, we do not load 8051 firmware.
7031 // We should access RF registers directly.
7032 // For RT2870 ATE mode, ATE_RF_IO_WRITE8/READ8_BY_REG_ID are redefined.
7034 if (ATE_ON(pAdapter))
7036 ATE_RF_IO_READ8_BY_REG_ID(pAdapter, rfId, ®RF);
7037 ATE_RF_IO_WRITE8_BY_REG_ID(pAdapter, (UCHAR)rfId,(UCHAR) rfValue);
7038 //Read it back for showing
7039 ATE_RF_IO_READ8_BY_REG_ID(pAdapter, rfId, ®RF);
7040 sprintf(msg+strlen(msg), "R%02d[0x%02X]:%02X\n", rfId, rfId*2, regRF);
7043 #endif // RALINK_ATE //
7045 // according to Andy, Gary, David require.
7046 // the command RF shall read/write RF register directly for dubug.
7047 //BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
7048 //BBP_IO_WRITE8_BY_REG_ID(pAdapter, (UCHAR)bbpId,(UCHAR) bbpValue);
7049 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
7050 RT30xxWriteRFRegister(pAdapter, (UCHAR)rfId,(UCHAR) rfValue);
7051 //Read it back for showing
7052 //BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
7053 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
7054 sprintf(msg+strlen(msg), "R%02d[0x%02X]:%02X\n", rfId, rfId*2, regRF);
7058 {//Invalid parametes, so default printk all RF
7059 bIsPrintAllRF = TRUE;
7063 { //Invalid parametes, so default printk all RF
7064 bIsPrintAllRF = TRUE;
7069 bIsPrintAllRF = TRUE;
7073 memset(msg, 0x00, 2048);
7075 for (rfId = 0; rfId <= 31; rfId++)
7077 // In RT2860 ATE mode, we do not load 8051 firmware.
7078 // We should access RF registers directly.
7079 // For RT2870 ATE mode, ATE_RF_IO_WRITE8/READ8_BY_REG_ID are redefined.
7081 if (ATE_ON(pAdapter))
7083 ATE_RF_IO_READ8_BY_REG_ID(pAdapter, rfId, ®RF);
7086 #endif // RALINK_ATE //
7088 // according to Andy, Gary, David require.
7089 // the command RF shall read/write RF register directly for dubug.
7090 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
7091 sprintf(msg+strlen(msg), "%03d = %02X\n", rfId, regRF);
7093 // Copy the information into the user buffer
7094 DBGPRINT(RT_DEBUG_TRACE, ("strlen(msg)=%d\n", (UINT32)strlen(msg)));
7095 wrq->u.data.length = strlen(msg);
7096 if (copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length))
7098 DBGPRINT(RT_DEBUG_TRACE, ("%s: copy_to_user() fail\n", __func__));
7103 if(strlen(msg) == 1)
7104 sprintf(msg+strlen(msg), "===>Error command format!");
7106 DBGPRINT(RT_DEBUG_TRACE, ("copy to user [msg=%s]\n", msg));
7107 // Copy the information into the user buffer
7108 DBGPRINT(RT_DEBUG_TRACE, ("strlen(msg) =%d\n", (UINT32)strlen(msg)));
7110 // Copy the information into the user buffer
7111 wrq->u.data.length = strlen(msg);
7112 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
7115 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlRF\n\n"));
7123 INT Set_TGnWifiTest_Proc(
7124 IN PRTMP_ADAPTER pAd,
7127 if (simple_strtol(arg, 0, 10) == 0)
7128 pAd->StaCfg.bTGnWifiTest = FALSE;
7130 pAd->StaCfg.bTGnWifiTest = TRUE;
7132 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_TGnWifiTest_Proc::(bTGnWifiTest=%d)\n", pAd->StaCfg.bTGnWifiTest));
7136 INT Set_LongRetryLimit_Proc(
7137 IN PRTMP_ADAPTER pAdapter,
7140 TX_RTY_CFG_STRUC tx_rty_cfg;
7141 UCHAR LongRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
7143 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
7144 tx_rty_cfg.field.LongRtyLimit = LongRetryLimit;
7145 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
7146 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_LongRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
7150 INT Set_ShortRetryLimit_Proc(
7151 IN PRTMP_ADAPTER pAdapter,
7154 TX_RTY_CFG_STRUC tx_rty_cfg;
7155 UCHAR ShortRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
7157 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
7158 tx_rty_cfg.field.ShortRtyLimit = ShortRetryLimit;
7159 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
7160 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_ShortRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
7164 #ifdef EXT_BUILD_CHANNEL_LIST
7165 INT Set_Ieee80211dClientMode_Proc(
7166 IN PRTMP_ADAPTER pAdapter,
7169 if (simple_strtol(arg, 0, 10) == 0)
7170 pAdapter->StaCfg.IEEE80211dClientMode = Rt802_11_D_None;
7171 else if (simple_strtol(arg, 0, 10) == 1)
7172 pAdapter->StaCfg.IEEE80211dClientMode = Rt802_11_D_Flexible;
7173 else if (simple_strtol(arg, 0, 10) == 2)
7174 pAdapter->StaCfg.IEEE80211dClientMode = Rt802_11_D_Strict;
7178 DBGPRINT(RT_DEBUG_TRACE, ("Set_Ieee802dMode_Proc::(IEEEE0211dMode=%d)\n", pAdapter->StaCfg.IEEE80211dClientMode));
7181 #endif // EXT_BUILD_CHANNEL_LIST //
7183 #ifdef CARRIER_DETECTION_SUPPORT
7184 INT Set_CarrierDetect_Proc(
7185 IN PRTMP_ADAPTER pAd,
7188 if (simple_strtol(arg, 0, 10) == 0)
7189 pAd->CommonCfg.CarrierDetect.Enable = FALSE;
7191 pAd->CommonCfg.CarrierDetect.Enable = TRUE;
7193 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_CarrierDetect_Proc::(CarrierDetect.Enable=%d)\n", pAd->CommonCfg.CarrierDetect.Enable));
7196 #endif // CARRIER_DETECTION_SUPPORT //