2 *************************************************************************
4 * 5F., No.36, Taiyuan St., Jhubei City,
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
25 *************************************************************************
31 IOCTL related subroutines
35 -------- ---------- ----------------------------------------------
36 Rory Chen 01-03-2003 created
37 Rory Chen 02-14-2005 modify to support RT61
40 #include "rt_config.h"
43 extern ULONG RTDebugLevel;
47 #define WEP_SMALL_KEY_LEN (40/8)
48 #define WEP_LARGE_KEY_LEN (104/8)
50 #define GROUP_KEY_NO 4
52 extern UCHAR CipherWpa2Template[];
53 extern UCHAR CipherWpaPskTkip[];
54 extern UCHAR CipherWpaPskTkipLen;
56 typedef struct PACKED _RT_VERSION_INFO{
62 UINT DriverBuildMonth;
64 } RT_VERSION_INFO, *PRT_VERSION_INFO;
66 struct iw_priv_args privtab[] = {
68 IW_PRIV_TYPE_CHAR | 1024, 0,
71 { RTPRIV_IOCTL_SHOW, 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
73 { RTPRIV_IOCTL_SHOW, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
75 /* --- sub-ioctls definitions --- */
77 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "connStatus" },
79 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "driverVer" },
81 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "bainfo" },
83 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "descinfo" },
85 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "radio_off" },
87 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "radio_on" },
89 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "show" },
90 /* --- sub-ioctls relations --- */
94 IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
97 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
100 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
104 { RTPRIV_IOCTL_STATISTICS,
105 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
107 { RTPRIV_IOCTL_GSITESURVEY,
108 0, IW_PRIV_TYPE_CHAR | 1024,
113 IN PRTMP_ADAPTER pAdapter,
117 INT Set_WmmCapable_Proc(
118 IN PRTMP_ADAPTER pAd,
122 INT Set_NetworkType_Proc(
123 IN PRTMP_ADAPTER pAdapter,
126 INT Set_AuthMode_Proc(
127 IN PRTMP_ADAPTER pAdapter,
130 INT Set_EncrypType_Proc(
131 IN PRTMP_ADAPTER pAdapter,
134 INT Set_DefaultKeyID_Proc(
135 IN PRTMP_ADAPTER pAdapter,
139 IN PRTMP_ADAPTER pAdapter,
143 IN PRTMP_ADAPTER pAdapter,
147 IN PRTMP_ADAPTER pAdapter,
151 IN PRTMP_ADAPTER pAdapter,
155 IN PRTMP_ADAPTER pAdapter,
160 IN PRTMP_ADAPTER pAdapter,
163 #ifdef WPA_SUPPLICANT_SUPPORT
165 IN PRTMP_ADAPTER pAd,
167 #endif // WPA_SUPPLICANT_SUPPORT //
171 IN PRTMP_ADAPTER pAdapter,
172 IN struct iwreq *wrq);
175 IN PRTMP_ADAPTER pAdapter,
176 IN struct iwreq *wrq);
178 VOID RTMPIoctlE2PROM(
179 IN PRTMP_ADAPTER pAdapter,
180 IN struct iwreq *wrq);
184 NDIS_STATUS RTMPWPANoneAddKeyProc(
185 IN PRTMP_ADAPTER pAd,
188 INT Set_FragTest_Proc(
189 IN PRTMP_ADAPTER pAdapter,
192 #ifdef DOT11_N_SUPPORT
193 INT Set_TGnWifiTest_Proc(
194 IN PRTMP_ADAPTER pAd,
196 #endif // DOT11_N_SUPPORT //
198 INT Set_LongRetryLimit_Proc(
199 IN PRTMP_ADAPTER pAdapter,
202 INT Set_ShortRetryLimit_Proc(
203 IN PRTMP_ADAPTER pAdapter,
208 INT (*set_proc)(PRTMP_ADAPTER pAdapter, PUCHAR arg);
209 } *PRTMP_PRIVATE_SET_PROC, RTMP_PRIVATE_SUPPORT_PROC[] = {
210 {"DriverVersion", Set_DriverVersion_Proc},
211 {"CountryRegion", Set_CountryRegion_Proc},
212 {"CountryRegionABand", Set_CountryRegionABand_Proc},
213 {"SSID", Set_SSID_Proc},
214 {"WirelessMode", Set_WirelessMode_Proc},
215 {"TxBurst", Set_TxBurst_Proc},
216 {"TxPreamble", Set_TxPreamble_Proc},
217 {"TxPower", Set_TxPower_Proc},
218 {"Channel", Set_Channel_Proc},
219 {"BGProtection", Set_BGProtection_Proc},
220 {"RTSThreshold", Set_RTSThreshold_Proc},
221 {"FragThreshold", Set_FragThreshold_Proc},
222 #ifdef DOT11_N_SUPPORT
223 {"HtBw", Set_HtBw_Proc},
224 {"HtMcs", Set_HtMcs_Proc},
225 {"HtGi", Set_HtGi_Proc},
226 {"HtOpMode", Set_HtOpMode_Proc},
227 {"HtExtcha", Set_HtExtcha_Proc},
228 {"HtMpduDensity", Set_HtMpduDensity_Proc},
229 {"HtBaWinSize", Set_HtBaWinSize_Proc},
230 {"HtRdg", Set_HtRdg_Proc},
231 {"HtAmsdu", Set_HtAmsdu_Proc},
232 {"HtAutoBa", Set_HtAutoBa_Proc},
233 {"HtBaDecline", Set_BADecline_Proc},
234 {"HtProtect", Set_HtProtect_Proc},
235 {"HtMimoPs", Set_HtMimoPs_Proc},
236 #endif // DOT11_N_SUPPORT //
238 #ifdef AGGREGATION_SUPPORT
239 {"PktAggregate", Set_PktAggregate_Proc},
243 {"WmmCapable", Set_WmmCapable_Proc},
245 {"IEEE80211H", Set_IEEE80211H_Proc},
246 {"NetworkType", Set_NetworkType_Proc},
247 {"AuthMode", Set_AuthMode_Proc},
248 {"EncrypType", Set_EncrypType_Proc},
249 {"DefaultKeyID", Set_DefaultKeyID_Proc},
250 {"Key1", Set_Key1_Proc},
251 {"Key2", Set_Key2_Proc},
252 {"Key3", Set_Key3_Proc},
253 {"Key4", Set_Key4_Proc},
254 {"WPAPSK", Set_WPAPSK_Proc},
255 {"ResetCounter", Set_ResetStatCounter_Proc},
256 {"PSMode", Set_PSMode_Proc},
258 {"Debug", Set_Debug_Proc},
261 #ifdef WPA_SUPPLICANT_SUPPORT
262 {"WpaSupport", Set_Wpa_Support},
263 #endif // WPA_SUPPLICANT_SUPPORT //
267 {"FixedTxMode", Set_FixedTxMode_Proc},
268 #ifdef DOT11_N_SUPPORT
269 {"TGnWifiTest", Set_TGnWifiTest_Proc},
270 {"ForceGF", Set_ForceGF_Proc},
271 #endif // DOT11_N_SUPPORT //
272 {"LongRetry", Set_LongRetryLimit_Proc},
273 {"ShortRetry", Set_ShortRetryLimit_Proc},
279 IN PRTMP_ADAPTER pAd,
280 IN PNDIS_802_11_KEY pKey)
283 MAC_TABLE_ENTRY *pEntry;
285 DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey ------>\n"));
287 RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
288 if (RTMP_TEST_PSFLAG(pAd, fRTMP_PS_SET_PCI_CLK_OFF_COMMAND))
290 if (pAd->StaCfg.bRadio == FALSE)
292 RTMP_SET_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
295 DBGPRINT(RT_DEBUG_TRACE,("RTMPWPAAddKeyProc1==>\n"));
296 RTMPPCIeLinkCtrlValueRestore(pAd, RESTORE_HALT);
298 pAd->bPCIclkOff = FALSE;
301 if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
303 if (pKey->KeyIndex & 0x80000000)
305 if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
307 NdisZeroMemory(pAd->StaCfg.PMK, 32);
308 NdisMoveMemory(pAd->StaCfg.PMK, pKey->KeyMaterial, pKey->KeyLength);
312 NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));
313 pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
314 NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, pKey->KeyMaterial, LEN_TKIP_EK);
315 #ifdef WPA_SUPPLICANT_SUPPORT
316 if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
318 NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
319 NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
322 #endif // WPA_SUPPLICANT_SUPPORT //
324 NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
325 NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
328 // Decide its ChiperAlg
329 if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
330 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
331 else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)
332 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
334 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_NONE;
336 // Update these related information to MAC_TABLE_ENTRY
337 pEntry = &pAd->MacTab.Content[BSSID_WCID];
338 NdisMoveMemory(pEntry->PairwiseKey.Key, pAd->SharedKey[BSS0][0].Key, LEN_TKIP_EK);
339 NdisMoveMemory(pEntry->PairwiseKey.RxMic, pAd->SharedKey[BSS0][0].RxMic, LEN_TKIP_RXMICK);
340 NdisMoveMemory(pEntry->PairwiseKey.TxMic, pAd->SharedKey[BSS0][0].TxMic, LEN_TKIP_TXMICK);
341 pEntry->PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;
343 // Update pairwise key information to ASIC Shared Key Table
344 AsicAddSharedKeyEntry(pAd,
347 pAd->SharedKey[BSS0][0].CipherAlg,
348 pAd->SharedKey[BSS0][0].Key,
349 pAd->SharedKey[BSS0][0].TxMic,
350 pAd->SharedKey[BSS0][0].RxMic);
352 // Update ASIC WCID attribute table and IVEIV table
353 RTMPAddWcidAttributeEntry(pAd,
356 pAd->SharedKey[BSS0][0].CipherAlg,
359 if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
361 // set 802.1x port control
362 STA_PORT_SECURED(pAd);
364 // Indicate Connected for GUI
365 pAd->IndicateMediaState = NdisMediaStateConnected;
371 pAd->StaCfg.DefaultKeyId = (pKey->KeyIndex & 0xFF);
372 NdisZeroMemory(&pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId], sizeof(CIPHER_KEY));
373 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].KeyLen = LEN_TKIP_EK;
374 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key, pKey->KeyMaterial, LEN_TKIP_EK);
375 #ifdef WPA_SUPPLICANT_SUPPORT
376 if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
378 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
379 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
382 #endif // WPA_SUPPLICANT_SUPPORT //
384 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
385 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
388 // Update Shared Key CipherAlg
389 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_NONE;
390 if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
391 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_TKIP;
392 else if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)
393 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_AES;
395 // Update group key information to ASIC Shared Key Table
396 AsicAddSharedKeyEntry(pAd,
398 pAd->StaCfg.DefaultKeyId,
399 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
400 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key,
401 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic,
402 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic);
404 // Update ASIC WCID attribute table and IVEIV table
405 RTMPAddWcidAttributeEntry(pAd,
407 pAd->StaCfg.DefaultKeyId,
408 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
411 // set 802.1x port control
412 STA_PORT_SECURED(pAd);
414 // Indicate Connected for GUI
415 pAd->IndicateMediaState = NdisMediaStateConnected;
418 else // dynamic WEP from wpa_supplicant
423 if(pKey->KeyLength == 32)
426 KeyIdx = pKey->KeyIndex & 0x0fffffff;
430 // it is a default shared key, for Pairwise key setting
431 if (pKey->KeyIndex & 0x80000000)
433 pEntry = MacTableLookup(pAd, pKey->BSSID);
437 DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey: Set Pair-wise Key\n"));
439 // set key material and key length
440 pEntry->PairwiseKey.KeyLen = (UCHAR)pKey->KeyLength;
441 NdisMoveMemory(pEntry->PairwiseKey.Key, &pKey->KeyMaterial, pKey->KeyLength);
444 if (pKey->KeyLength == 5)
445 pEntry->PairwiseKey.CipherAlg = CIPHER_WEP64;
447 pEntry->PairwiseKey.CipherAlg = CIPHER_WEP128;
449 // Add Pair-wise key to Asic
450 AsicAddPairwiseKeyEntry(
454 &pEntry->PairwiseKey);
456 // update WCID attribute table and IVEIV table for this entry
457 RTMPAddWcidAttributeEntry(
460 KeyIdx, // The value may be not zero
461 pEntry->PairwiseKey.CipherAlg,
468 // Default key for tx (shared key)
469 pAd->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
471 // set key material and key length
472 pAd->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pKey->KeyLength;
473 NdisMoveMemory(pAd->SharedKey[BSS0][KeyIdx].Key, &pKey->KeyMaterial, pKey->KeyLength);
476 if (pKey->KeyLength == 5)
477 pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP64;
479 pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP128;
481 CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg;
482 Key = pAd->SharedKey[BSS0][KeyIdx].Key;
484 // Set Group key material to Asic
485 AsicAddSharedKeyEntry(pAd, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
487 // Update WCID attribute table and IVEIV table for this group key table
488 RTMPAddWcidAttributeEntry(pAd, BSS0, KeyIdx, CipherAlg, NULL);
494 RTMP_SET_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
495 DBGPRINT(RT_DEBUG_INFO, ("<------ RTMPAddKey\n"));
499 char * rtstrchr(const char * s, int c)
501 for(; *s != (char) c; ++s)
508 This is required for LinEX2004/kernel2.6.7 to provide iwlist scanning function
512 rt_ioctl_giwname(struct net_device *dev,
513 struct iw_request_info *info,
514 char *name, char *extra)
516 // PRTMP_ADAPTER pAdapter = dev->ml_priv;
518 strncpy(name, "RT2860 Wireless", IFNAMSIZ);
522 int rt_ioctl_siwfreq(struct net_device *dev,
523 struct iw_request_info *info,
524 struct iw_freq *freq, char *extra)
526 PRTMP_ADAPTER pAdapter = dev->ml_priv;
529 //check if the interface is down
530 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
532 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
540 if((freq->e == 0) && (freq->m <= 1000))
541 chan = freq->m; // Setting by channel number
543 MAP_KHZ_TO_CHANNEL_ID( (freq->m /100) , chan); // Setting by frequency - search the table , like 2.412G, 2.422G,
545 if (ChannelSanity(pAdapter, chan) == TRUE)
547 pAdapter->CommonCfg.Channel = chan;
548 DBGPRINT(RT_DEBUG_ERROR, ("==>rt_ioctl_siwfreq::SIOCSIWFREQ[cmd=0x%x] (Channel=%d)\n", SIOCSIWFREQ, pAdapter->CommonCfg.Channel));
555 int rt_ioctl_giwfreq(struct net_device *dev,
556 struct iw_request_info *info,
557 struct iw_freq *freq, char *extra)
559 VIRTUAL_ADAPTER *pVirtualAd = NULL;
560 PRTMP_ADAPTER pAdapter = NULL;
564 if (dev->priv_flags == INT_MAIN)
566 pAdapter = dev->ml_priv;
570 pVirtualAd = dev->ml_priv;
571 if (pVirtualAd && pVirtualAd->RtmpDev)
572 pAdapter = pVirtualAd->RtmpDev->ml_priv;
575 if (pAdapter == NULL)
577 /* if 1st open fail, pAd will be free;
578 So the net_dev->ml_priv will be NULL in 2rd open */
582 ch = pAdapter->CommonCfg.Channel;
584 DBGPRINT(RT_DEBUG_TRACE,("==>rt_ioctl_giwfreq %d\n", ch));
586 MAP_CHANNEL_ID_TO_KHZ(ch, m);
592 int rt_ioctl_siwmode(struct net_device *dev,
593 struct iw_request_info *info,
594 __u32 *mode, char *extra)
596 PRTMP_ADAPTER pAdapter = dev->ml_priv;
598 //check if the interface is down
599 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
601 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
608 Set_NetworkType_Proc(pAdapter, "Adhoc");
611 Set_NetworkType_Proc(pAdapter, "Infra");
613 case IW_MODE_MONITOR:
614 Set_NetworkType_Proc(pAdapter, "Monitor");
617 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_siwmode::SIOCSIWMODE (unknown %d)\n", *mode));
621 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
622 pAdapter->StaCfg.WpaState = SS_NOTUSE;
627 int rt_ioctl_giwmode(struct net_device *dev,
628 struct iw_request_info *info,
629 __u32 *mode, char *extra)
631 PRTMP_ADAPTER pAdapter = NULL;
632 VIRTUAL_ADAPTER *pVirtualAd = NULL;
634 if (dev->priv_flags == INT_MAIN)
636 pAdapter = dev->ml_priv;
640 pVirtualAd = dev->ml_priv;
641 if (pVirtualAd && pVirtualAd->RtmpDev)
642 pAdapter = pVirtualAd->RtmpDev->ml_priv;
645 if (pAdapter == NULL)
647 /* if 1st open fail, pAd will be free;
648 So the net_dev->ml_priv will be NULL in 2rd open */
652 if (ADHOC_ON(pAdapter))
653 *mode = IW_MODE_ADHOC;
654 else if (INFRA_ON(pAdapter))
655 *mode = IW_MODE_INFRA;
656 else if (MONITOR_ON(pAdapter))
658 *mode = IW_MODE_MONITOR;
661 *mode = IW_MODE_AUTO;
663 DBGPRINT(RT_DEBUG_TRACE, ("==>rt_ioctl_giwmode(mode=%d)\n", *mode));
667 int rt_ioctl_siwsens(struct net_device *dev,
668 struct iw_request_info *info,
669 char *name, char *extra)
671 PRTMP_ADAPTER pAdapter = dev->ml_priv;
673 //check if the interface is down
674 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
676 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
683 int rt_ioctl_giwsens(struct net_device *dev,
684 struct iw_request_info *info,
685 char *name, char *extra)
690 int rt_ioctl_giwrange(struct net_device *dev,
691 struct iw_request_info *info,
692 struct iw_point *data, char *extra)
694 PRTMP_ADAPTER pAdapter = NULL;
695 VIRTUAL_ADAPTER *pVirtualAd = NULL;
696 struct iw_range *range = (struct iw_range *) extra;
700 if (dev->priv_flags == INT_MAIN)
702 pAdapter = dev->ml_priv;
706 pVirtualAd = dev->ml_priv;
707 if (pVirtualAd && pVirtualAd->RtmpDev)
708 pAdapter = pVirtualAd->RtmpDev->ml_priv;
711 if (pAdapter == NULL)
713 /* if 1st open fail, pAd will be free;
714 So the net_dev->ml_priv will be NULL in 2rd open */
718 DBGPRINT(RT_DEBUG_TRACE ,("===>rt_ioctl_giwrange\n"));
719 data->length = sizeof(struct iw_range);
720 memset(range, 0, sizeof(struct iw_range));
722 range->txpower_capa = IW_TXPOW_DBM;
724 if (INFRA_ON(pAdapter)||ADHOC_ON(pAdapter))
726 range->min_pmp = 1 * 1024;
727 range->max_pmp = 65535 * 1024;
728 range->min_pmt = 1 * 1024;
729 range->max_pmt = 1000 * 1024;
730 range->pmp_flags = IW_POWER_PERIOD;
731 range->pmt_flags = IW_POWER_TIMEOUT;
732 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT |
733 IW_POWER_UNICAST_R | IW_POWER_ALL_R;
736 range->we_version_compiled = WIRELESS_EXT;
737 range->we_version_source = 14;
739 range->retry_capa = IW_RETRY_LIMIT;
740 range->retry_flags = IW_RETRY_LIMIT;
741 range->min_retry = 0;
742 range->max_retry = 255;
744 range->num_channels = pAdapter->ChannelListNum;
747 for (i = 1; i <= range->num_channels; i++)
750 range->freq[val].i = pAdapter->ChannelList[i-1].Channel;
751 MAP_CHANNEL_ID_TO_KHZ(pAdapter->ChannelList[i-1].Channel, m);
752 range->freq[val].m = m * 100; /* HZ */
754 range->freq[val].e = 1;
756 if (val == IW_MAX_FREQUENCIES)
759 range->num_frequency = val;
761 range->max_qual.qual = 100; /* what is correct max? This was not
762 * documented exactly. At least
763 * 69 has been observed. */
764 range->max_qual.level = 0; /* dB */
765 range->max_qual.noise = 0; /* dB */
767 /* What would be suitable values for "average/typical" qual? */
768 range->avg_qual.qual = 20;
769 range->avg_qual.level = -60;
770 range->avg_qual.noise = -95;
771 range->sensitivity = 3;
773 range->max_encoding_tokens = NR_WEP_KEYS;
774 range->num_encoding_sizes = 2;
775 range->encoding_size[0] = 5;
776 range->encoding_size[1] = 13;
779 range->max_rts = 2347;
780 range->min_frag = 256;
781 range->max_frag = 2346;
783 #if WIRELESS_EXT > 17
784 /* IW_ENC_CAPA_* bit field */
785 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
786 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
792 int rt_ioctl_siwap(struct net_device *dev,
793 struct iw_request_info *info,
794 struct sockaddr *ap_addr, char *extra)
796 PRTMP_ADAPTER pAdapter = dev->ml_priv;
797 NDIS_802_11_MAC_ADDRESS Bssid;
799 //check if the interface is down
800 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
802 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
806 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
808 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
809 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
812 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
813 // this request, because this request is initiated by NDIS.
814 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
815 // Prevent to connect AP again in STAMlmePeriodicExec
816 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
818 memset(Bssid, 0, MAC_ADDR_LEN);
819 memcpy(Bssid, ap_addr->sa_data, MAC_ADDR_LEN);
820 MlmeEnqueue(pAdapter,
821 MLME_CNTL_STATE_MACHINE,
823 sizeof(NDIS_802_11_MAC_ADDRESS),
826 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCSIWAP %02x:%02x:%02x:%02x:%02x:%02x\n",
827 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
832 int rt_ioctl_giwap(struct net_device *dev,
833 struct iw_request_info *info,
834 struct sockaddr *ap_addr, char *extra)
836 PRTMP_ADAPTER pAdapter = NULL;
837 VIRTUAL_ADAPTER *pVirtualAd = NULL;
839 if (dev->priv_flags == INT_MAIN)
841 pAdapter = dev->ml_priv;
845 pVirtualAd = dev->ml_priv;
846 if (pVirtualAd && pVirtualAd->RtmpDev)
847 pAdapter = pVirtualAd->RtmpDev->ml_priv;
850 if (pAdapter == NULL)
852 /* if 1st open fail, pAd will be free;
853 So the net_dev->ml_priv will be NULL in 2rd open */
857 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
859 ap_addr->sa_family = ARPHRD_ETHER;
860 memcpy(ap_addr->sa_data, &pAdapter->CommonCfg.Bssid, ETH_ALEN);
862 #ifdef WPA_SUPPLICANT_SUPPORT
864 else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
866 ap_addr->sa_family = ARPHRD_ETHER;
867 memcpy(ap_addr->sa_data, &pAdapter->MlmeAux.Bssid, ETH_ALEN);
869 #endif // WPA_SUPPLICANT_SUPPORT //
872 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIWAP(=EMPTY)\n"));
880 * Units are in db above the noise floor. That means the
881 * rssi values reported in the tx/rx descriptors in the
882 * driver are the SNR expressed in db.
884 * If you assume that the noise floor is -95, which is an
885 * excellent assumption 99.5 % of the time, then you can
886 * derive the absolute signal level (i.e. -95 + rssi).
887 * There are some other slight factors to take into account
888 * depending on whether the rssi measurement is from 11b,
889 * 11g, or 11a. These differences are at most 2db and
892 * NB: various calculations are based on the orinoco/wavelan
893 * drivers for compatibility
895 static void set_quality(PRTMP_ADAPTER pAdapter,
896 struct iw_quality *iq,
903 ChannelQuality = 100;
904 else if (rssi >= -80) // between -50 ~ -80dbm
905 ChannelQuality = (__u8)(24 + ((rssi + 80) * 26)/10);
906 else if (rssi >= -90) // between -80 ~ -90dbm
907 ChannelQuality = (__u8)((rssi + 90) * 26)/10;
911 iq->qual = (__u8)ChannelQuality;
913 iq->level = (__u8)(rssi);
914 iq->noise = (pAdapter->BbpWriteLatch[66] > pAdapter->BbpTuning.FalseCcaUpperThreshold) ? ((__u8)pAdapter->BbpTuning.FalseCcaUpperThreshold) : ((__u8) pAdapter->BbpWriteLatch[66]); // noise level (dBm)
915 iq->noise += 256 - 143;
916 iq->updated = pAdapter->iw_stats.qual.updated;
919 int rt_ioctl_iwaplist(struct net_device *dev,
920 struct iw_request_info *info,
921 struct iw_point *data, char *extra)
923 PRTMP_ADAPTER pAdapter = dev->ml_priv;
925 struct sockaddr addr[IW_MAX_AP];
926 struct iw_quality qual[IW_MAX_AP];
929 //check if the interface is down
930 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
932 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
938 for (i = 0; i <IW_MAX_AP ; i++)
940 if (i >= pAdapter->ScanTab.BssNr)
942 addr[i].sa_family = ARPHRD_ETHER;
943 memcpy(addr[i].sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
944 set_quality(pAdapter, &qual[i], pAdapter->ScanTab.BssEntry[i].Rssi);
947 memcpy(extra, &addr, i*sizeof(addr[0]));
948 data->flags = 1; /* signal quality present (sort of) */
949 memcpy(extra + i*sizeof(addr[0]), &qual, i*sizeof(qual[i]));
955 int rt_ioctl_siwscan(struct net_device *dev,
956 struct iw_request_info *info,
957 struct iw_point *data, char *extra)
959 PRTMP_ADAPTER pAdapter = dev->ml_priv;
962 int Status = NDIS_STATUS_SUCCESS;
964 //check if the interface is down
965 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
967 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
971 if (MONITOR_ON(pAdapter))
973 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
977 if ((pAdapter->OpMode == OPMODE_STA) && (IDLE_ON(pAdapter))
978 && (pAdapter->StaCfg.bRadio == TRUE)
979 && (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_IDLE_RADIO_OFF)))
981 RT28xxPciAsicRadioOn(pAdapter, GUI_IDLE_POWER_SAVE);
983 // Check if still radio off.
984 else if (pAdapter->bPCIclkOff == TRUE)
987 #ifdef WPA_SUPPLICANT_SUPPORT
988 if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
990 pAdapter->StaCfg.WpaSupplicantScanCount++;
992 #endif // WPA_SUPPLICANT_SUPPORT //
994 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
995 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
1000 #ifdef WPA_SUPPLICANT_SUPPORT
1001 if ((pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE) &&
1002 (pAdapter->StaCfg.WpaSupplicantScanCount > 3))
1004 DBGPRINT(RT_DEBUG_TRACE, ("!!! WpaSupplicantScanCount > 3\n"));
1005 Status = NDIS_STATUS_SUCCESS;
1008 #endif // WPA_SUPPLICANT_SUPPORT //
1010 if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
1011 ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
1012 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) &&
1013 (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
1015 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
1016 Status = NDIS_STATUS_SUCCESS;
1020 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
1022 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
1023 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
1026 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
1027 // this request, because this request is initiated by NDIS.
1028 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
1029 // Reset allowed scan retries
1030 pAdapter->StaCfg.ScanCnt = 0;
1031 pAdapter->StaCfg.LastScanTime = Now;
1033 MlmeEnqueue(pAdapter,
1034 MLME_CNTL_STATE_MACHINE,
1035 OID_802_11_BSSID_LIST_SCAN,
1039 Status = NDIS_STATUS_SUCCESS;
1040 RT28XX_MLME_HANDLER(pAdapter);
1045 int rt_ioctl_giwscan(struct net_device *dev,
1046 struct iw_request_info *info,
1047 struct iw_point *data, char *extra)
1050 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1052 char *current_ev = extra, *previous_ev = extra;
1054 char *current_val, custom[MAX_CUSTOM_LEN] = {0};
1057 #endif // IWEVGENIE //
1058 struct iw_event iwe;
1060 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
1063 * Still scanning, indicate the caller should try again.
1069 #ifdef WPA_SUPPLICANT_SUPPORT
1070 if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
1072 pAdapter->StaCfg.WpaSupplicantScanCount = 0;
1074 #endif // WPA_SUPPLICANT_SUPPORT //
1076 if (pAdapter->ScanTab.BssNr == 0)
1082 #if WIRELESS_EXT >= 17
1083 if (data->length > 0)
1084 end_buf = extra + data->length;
1086 end_buf = extra + IW_SCAN_MAX_DATA;
1088 end_buf = extra + IW_SCAN_MAX_DATA;
1091 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
1093 if (current_ev >= end_buf)
1095 #if WIRELESS_EXT >= 17
1103 //================================
1104 memset(&iwe, 0, sizeof(iwe));
1105 iwe.cmd = SIOCGIWAP;
1106 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1107 memcpy(iwe.u.ap_addr.sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, ETH_ALEN);
1109 previous_ev = current_ev;
1110 current_ev = iwe_stream_add_event(info, current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);
1111 if (current_ev == previous_ev)
1112 #if WIRELESS_EXT >= 17
1119 //================================
1120 memset(&iwe, 0, sizeof(iwe));
1121 iwe.cmd = SIOCGIWESSID;
1122 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].SsidLen;
1123 iwe.u.data.flags = 1;
1125 previous_ev = current_ev;
1126 current_ev = iwe_stream_add_point(info, current_ev,end_buf, &iwe, pAdapter->ScanTab.BssEntry[i].Ssid);
1127 if (current_ev == previous_ev)
1128 #if WIRELESS_EXT >= 17
1135 //================================
1136 memset(&iwe, 0, sizeof(iwe));
1137 iwe.cmd = SIOCGIWMODE;
1138 if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11IBSS)
1140 iwe.u.mode = IW_MODE_ADHOC;
1142 else if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11Infrastructure)
1144 iwe.u.mode = IW_MODE_INFRA;
1148 iwe.u.mode = IW_MODE_AUTO;
1150 iwe.len = IW_EV_UINT_LEN;
1152 previous_ev = current_ev;
1153 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
1154 if (current_ev == previous_ev)
1155 #if WIRELESS_EXT >= 17
1161 //Channel and Frequency
1162 //================================
1163 memset(&iwe, 0, sizeof(iwe));
1164 iwe.cmd = SIOCGIWFREQ;
1165 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
1166 iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
1168 iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
1172 previous_ev = current_ev;
1173 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
1174 if (current_ev == previous_ev)
1175 #if WIRELESS_EXT >= 17
1181 //Add quality statistics
1182 //================================
1183 memset(&iwe, 0, sizeof(iwe));
1185 iwe.u.qual.level = 0;
1186 iwe.u.qual.noise = 0;
1187 set_quality(pAdapter, &iwe.u.qual, pAdapter->ScanTab.BssEntry[i].Rssi);
1188 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
1189 if (current_ev == previous_ev)
1190 #if WIRELESS_EXT >= 17
1197 //================================
1198 memset(&iwe, 0, sizeof(iwe));
1199 iwe.cmd = SIOCGIWENCODE;
1200 if (CAP_IS_PRIVACY_ON (pAdapter->ScanTab.BssEntry[i].CapabilityInfo ))
1201 iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1203 iwe.u.data.flags = IW_ENCODE_DISABLED;
1205 previous_ev = current_ev;
1206 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);
1207 if (current_ev == previous_ev)
1208 #if WIRELESS_EXT >= 17
1215 //================================
1216 if (pAdapter->ScanTab.BssEntry[i].SupRateLen)
1218 UCHAR tmpRate = pAdapter->ScanTab.BssEntry[i].SupRate[pAdapter->ScanTab.BssEntry[i].SupRateLen-1];
1219 memset(&iwe, 0, sizeof(iwe));
1220 iwe.cmd = SIOCGIWRATE;
1221 current_val = current_ev + IW_EV_LCP_LEN;
1222 if (tmpRate == 0x82)
1223 iwe.u.bitrate.value = 1 * 1000000;
1224 else if (tmpRate == 0x84)
1225 iwe.u.bitrate.value = 2 * 1000000;
1226 else if (tmpRate == 0x8B)
1227 iwe.u.bitrate.value = 5.5 * 1000000;
1228 else if (tmpRate == 0x96)
1229 iwe.u.bitrate.value = 11 * 1000000;
1231 iwe.u.bitrate.value = (tmpRate/2) * 1000000;
1233 iwe.u.bitrate.disabled = 0;
1234 current_val = iwe_stream_add_value(info, current_ev,
1235 current_val, end_buf, &iwe,
1238 if((current_val-current_ev)>IW_EV_LCP_LEN)
1239 current_ev = current_val;
1241 #if WIRELESS_EXT >= 17
1250 if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
1252 memset(&iwe, 0, sizeof(iwe));
1253 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1254 memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].WpaIE.IE[0]),
1255 pAdapter->ScanTab.BssEntry[i].WpaIE.IELen);
1256 iwe.cmd = IWEVGENIE;
1257 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].WpaIE.IELen;
1258 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, custom);
1259 if (current_ev == previous_ev)
1260 #if WIRELESS_EXT >= 17
1268 if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
1270 memset(&iwe, 0, sizeof(iwe));
1271 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1272 memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].RsnIE.IE[0]),
1273 pAdapter->ScanTab.BssEntry[i].RsnIE.IELen);
1274 iwe.cmd = IWEVGENIE;
1275 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].RsnIE.IELen;
1276 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, custom);
1277 if (current_ev == previous_ev)
1278 #if WIRELESS_EXT >= 17
1286 //================================
1287 if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
1289 NdisZeroMemory(&iwe, sizeof(iwe));
1290 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1291 iwe.cmd = IWEVCUSTOM;
1292 iwe.u.data.length = (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen * 2) + 7;
1293 NdisMoveMemory(custom, "wpa_ie=", 7);
1294 for (idx = 0; idx < pAdapter->ScanTab.BssEntry[i].WpaIE.IELen; idx++)
1295 sprintf(custom + strlen(custom), "%02x", pAdapter->ScanTab.BssEntry[i].WpaIE.IE[idx]);
1296 previous_ev = current_ev;
1297 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, custom);
1298 if (current_ev == previous_ev)
1299 #if WIRELESS_EXT >= 17
1307 if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
1309 NdisZeroMemory(&iwe, sizeof(iwe));
1310 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1311 iwe.cmd = IWEVCUSTOM;
1312 iwe.u.data.length = (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen * 2) + 7;
1313 NdisMoveMemory(custom, "rsn_ie=", 7);
1314 for (idx = 0; idx < pAdapter->ScanTab.BssEntry[i].RsnIE.IELen; idx++)
1315 sprintf(custom + strlen(custom), "%02x", pAdapter->ScanTab.BssEntry[i].RsnIE.IE[idx]);
1316 previous_ev = current_ev;
1317 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, custom);
1318 if (current_ev == previous_ev)
1319 #if WIRELESS_EXT >= 17
1325 #endif // IWEVGENIE //
1328 data->length = current_ev - extra;
1329 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
1330 DBGPRINT(RT_DEBUG_ERROR ,("===>rt_ioctl_giwscan. %d(%d) BSS returned, data->length = %d\n",i , pAdapter->ScanTab.BssNr, data->length));
1335 int rt_ioctl_siwessid(struct net_device *dev,
1336 struct iw_request_info *info,
1337 struct iw_point *data, char *essid)
1339 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1341 //check if the interface is down
1342 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1344 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1350 PCHAR pSsidString = NULL;
1352 // Includes null character.
1353 if (data->length > (IW_ESSID_MAX_SIZE + 1))
1356 pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
1359 NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
1360 NdisMoveMemory(pSsidString, essid, data->length);
1361 if (Set_SSID_Proc(pAdapter, pSsidString) == FALSE)
1370 if (Set_SSID_Proc(pAdapter, "") == FALSE)
1376 int rt_ioctl_giwessid(struct net_device *dev,
1377 struct iw_request_info *info,
1378 struct iw_point *data, char *essid)
1380 PRTMP_ADAPTER pAdapter = NULL;
1381 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1383 if (dev->priv_flags == INT_MAIN)
1385 pAdapter = dev->ml_priv;
1389 pVirtualAd = dev->ml_priv;
1390 if (pVirtualAd && pVirtualAd->RtmpDev)
1391 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1394 if (pAdapter == NULL)
1396 /* if 1st open fail, pAd will be free;
1397 So the net_dev->ml_priv will be NULL in 2rd open */
1402 if (MONITOR_ON(pAdapter))
1408 if (OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED))
1410 DBGPRINT(RT_DEBUG_TRACE ,("MediaState is connected\n"));
1411 data->length = pAdapter->CommonCfg.SsidLen;
1412 memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
1415 {//the ANY ssid was specified
1417 DBGPRINT(RT_DEBUG_TRACE ,("MediaState is not connected, ess\n"));
1424 int rt_ioctl_siwnickn(struct net_device *dev,
1425 struct iw_request_info *info,
1426 struct iw_point *data, char *nickname)
1428 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1430 //check if the interface is down
1431 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1433 DBGPRINT(RT_DEBUG_TRACE ,("INFO::Network is down!\n"));
1437 if (data->length > IW_ESSID_MAX_SIZE)
1440 memset(pAdapter->nickname, 0, IW_ESSID_MAX_SIZE + 1);
1441 memcpy(pAdapter->nickname, nickname, data->length);
1447 int rt_ioctl_giwnickn(struct net_device *dev,
1448 struct iw_request_info *info,
1449 struct iw_point *data, char *nickname)
1451 PRTMP_ADAPTER pAdapter = NULL;
1452 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1454 if (dev->priv_flags == INT_MAIN)
1456 pAdapter = dev->ml_priv;
1460 pVirtualAd = dev->ml_priv;
1461 if (pVirtualAd && pVirtualAd->RtmpDev)
1462 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1465 if (pAdapter == NULL)
1467 /* if 1st open fail, pAd will be free;
1468 So the net_dev->ml_priv will be NULL in 2rd open */
1472 if (data->length > strlen(pAdapter->nickname) + 1)
1473 data->length = strlen(pAdapter->nickname) + 1;
1474 if (data->length > 0) {
1475 memcpy(nickname, pAdapter->nickname, data->length-1);
1476 nickname[data->length-1] = '\0';
1481 int rt_ioctl_siwrts(struct net_device *dev,
1482 struct iw_request_info *info,
1483 struct iw_param *rts, char *extra)
1485 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1488 //check if the interface is down
1489 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1491 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1496 val = MAX_RTS_THRESHOLD;
1497 else if (rts->value < 0 || rts->value > MAX_RTS_THRESHOLD)
1499 else if (rts->value == 0)
1500 val = MAX_RTS_THRESHOLD;
1504 if (val != pAdapter->CommonCfg.RtsThreshold)
1505 pAdapter->CommonCfg.RtsThreshold = val;
1510 int rt_ioctl_giwrts(struct net_device *dev,
1511 struct iw_request_info *info,
1512 struct iw_param *rts, char *extra)
1514 PRTMP_ADAPTER pAdapter = NULL;
1515 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1517 if (dev->priv_flags == INT_MAIN)
1519 pAdapter = dev->ml_priv;
1523 pVirtualAd = dev->ml_priv;
1524 if (pVirtualAd && pVirtualAd->RtmpDev)
1525 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1528 if (pAdapter == NULL)
1530 /* if 1st open fail, pAd will be free;
1531 So the net_dev->ml_priv will be NULL in 2rd open */
1535 //check if the interface is down
1536 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1538 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1542 rts->value = pAdapter->CommonCfg.RtsThreshold;
1543 rts->disabled = (rts->value == MAX_RTS_THRESHOLD);
1549 int rt_ioctl_siwfrag(struct net_device *dev,
1550 struct iw_request_info *info,
1551 struct iw_param *frag, char *extra)
1553 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1556 //check if the interface is down
1557 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1559 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1564 val = MAX_FRAG_THRESHOLD;
1565 else if (frag->value >= MIN_FRAG_THRESHOLD || frag->value <= MAX_FRAG_THRESHOLD)
1566 val = __cpu_to_le16(frag->value & ~0x1); /* even numbers only */
1567 else if (frag->value == 0)
1568 val = MAX_FRAG_THRESHOLD;
1572 pAdapter->CommonCfg.FragmentThreshold = val;
1576 int rt_ioctl_giwfrag(struct net_device *dev,
1577 struct iw_request_info *info,
1578 struct iw_param *frag, char *extra)
1580 PRTMP_ADAPTER pAdapter = NULL;
1581 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1583 if (dev->priv_flags == INT_MAIN)
1585 pAdapter = dev->ml_priv;
1589 pVirtualAd = dev->ml_priv;
1590 if (pVirtualAd && pVirtualAd->RtmpDev)
1591 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1594 if (pAdapter == NULL)
1596 /* if 1st open fail, pAd will be free;
1597 So the net_dev->ml_priv will be NULL in 2rd open */
1601 //check if the interface is down
1602 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1604 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1608 frag->value = pAdapter->CommonCfg.FragmentThreshold;
1609 frag->disabled = (frag->value == MAX_FRAG_THRESHOLD);
1615 #define MAX_WEP_KEY_SIZE 13
1616 #define MIN_WEP_KEY_SIZE 5
1617 int rt_ioctl_siwencode(struct net_device *dev,
1618 struct iw_request_info *info,
1619 struct iw_point *erq, char *extra)
1621 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1623 //check if the interface is down
1624 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1626 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1630 if ((erq->length == 0) &&
1631 (erq->flags & IW_ENCODE_DISABLED))
1633 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
1634 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
1635 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
1636 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
1637 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1640 else if ((erq->length == 0) &&
1641 (erq->flags & IW_ENCODE_RESTRICTED || erq->flags & IW_ENCODE_OPEN))
1643 STA_PORT_SECURED(pAdapter);
1644 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
1645 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
1646 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
1647 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
1648 if (erq->flags & IW_ENCODE_RESTRICTED)
1649 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
1651 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1655 if (erq->length > 0)
1657 int keyIdx = (erq->flags & IW_ENCODE_INDEX) - 1;
1658 /* Check the size of the key */
1659 if (erq->length > MAX_WEP_KEY_SIZE) {
1662 /* Check key index */
1663 if ((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
1665 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::Wrong keyIdx=%d! Using default key instead (%d)\n",
1666 keyIdx, pAdapter->StaCfg.DefaultKeyId));
1669 keyIdx = pAdapter->StaCfg.DefaultKeyId;
1672 NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
1674 if (erq->length == MAX_WEP_KEY_SIZE)
1676 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
1677 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
1679 else if (erq->length == MIN_WEP_KEY_SIZE)
1681 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
1682 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
1685 /* Disable the key */
1686 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
1688 /* Check if the key is not marked as invalid */
1689 if(!(erq->flags & IW_ENCODE_NOKEY)) {
1690 /* Copy the key in the driver */
1691 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, extra, erq->length);
1696 /* Do we want to just set the transmit key index ? */
1697 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
1698 if ((index >= 0) && (index < 4))
1700 pAdapter->StaCfg.DefaultKeyId = index;
1703 /* Don't complain if only change the mode */
1704 if (!(erq->flags & IW_ENCODE_MODE)) {
1710 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::erq->flags=%x\n",erq->flags));
1711 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::AuthMode=%x\n",pAdapter->StaCfg.AuthMode));
1712 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::DefaultKeyId=%x, KeyLen = %d\n",pAdapter->StaCfg.DefaultKeyId , pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen));
1713 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::WepStatus=%x\n",pAdapter->StaCfg.WepStatus));
1718 rt_ioctl_giwencode(struct net_device *dev,
1719 struct iw_request_info *info,
1720 struct iw_point *erq, char *key)
1723 PRTMP_ADAPTER pAdapter = NULL;
1724 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1726 if (dev->priv_flags == INT_MAIN)
1728 pAdapter = dev->ml_priv;
1732 pVirtualAd = dev->ml_priv;
1733 if (pVirtualAd && pVirtualAd->RtmpDev)
1734 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1737 if (pAdapter == NULL)
1739 /* if 1st open fail, pAd will be free;
1740 So the net_dev->ml_priv will be NULL in 2rd open */
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");
1888 sprintf(extra+strlen(extra), "Tx success = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart);
1889 sprintf(extra+strlen(extra), "Tx success without retry = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart - (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
1891 sprintf(extra+strlen(extra), "Tx success after retry = %ld\n", (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
1892 sprintf(extra+strlen(extra), "Tx fail to Rcv ACK after retry = %ld\n", (ULONG)pAd->WlanCounters.FailedCount.QuadPart);
1893 sprintf(extra+strlen(extra), "RTS Success Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSSuccessCount.QuadPart);
1894 sprintf(extra+strlen(extra), "RTS Fail Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSFailureCount.QuadPart);
1896 sprintf(extra+strlen(extra), "Rx success = %ld\n", (ULONG)pAd->WlanCounters.ReceivedFragmentCount.QuadPart);
1897 sprintf(extra+strlen(extra), "Rx with CRC = %ld\n", (ULONG)pAd->WlanCounters.FCSErrorCount.QuadPart);
1898 sprintf(extra+strlen(extra), "Rx drop due to out of resource = %ld\n", (ULONG)pAd->Counters8023.RxNoBuffer);
1899 sprintf(extra+strlen(extra), "Rx duplicate frame = %ld\n", (ULONG)pAd->WlanCounters.FrameDuplicateCount.QuadPart);
1901 sprintf(extra+strlen(extra), "False CCA (one second) = %ld\n", (ULONG)pAd->RalinkCounters.OneSecFalseCCACnt);
1903 sprintf(extra+strlen(extra), "RSSI-A = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi0 - pAd->BbpRssiToDbmDelta));
1904 sprintf(extra+strlen(extra), "RSSI-B (if available) = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi1 - pAd->BbpRssiToDbmDelta));
1905 sprintf(extra+strlen(extra), "RSSI-C (if available) = %ld\n\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi2 - pAd->BbpRssiToDbmDelta));
1907 #ifdef WPA_SUPPLICANT_SUPPORT
1908 sprintf(extra+strlen(extra), "WpaSupplicantUP = %d\n\n", pAd->StaCfg.WpaSupplicantUP);
1909 #endif // WPA_SUPPLICANT_SUPPORT //
1912 wrq->length = strlen(extra) + 1; // 1: size of '\0'
1913 DBGPRINT(RT_DEBUG_TRACE, ("<== rt_private_get_statistics, wrq->length = %d\n", wrq->length));
1918 #ifdef DOT11_N_SUPPORT
1920 IN PRTMP_ADAPTER pAd,
1924 BA_ORI_ENTRY *pOriBAEntry;
1925 BA_REC_ENTRY *pRecBAEntry;
1927 for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
1929 PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
1930 if (((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
1931 || (pEntry->ValidAsWDS) || (pEntry->ValidAsMesh))
1933 sprintf(pOutBuf + strlen(pOutBuf), "\n%02X:%02X:%02X:%02X:%02X:%02X (Aid = %d) (AP) -\n",
1934 pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
1935 pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5], pEntry->Aid);
1937 sprintf(pOutBuf, "%s[Recipient]\n", pOutBuf);
1938 for (j=0; j < NUM_OF_TID; j++)
1940 if (pEntry->BARecWcidArray[j] != 0)
1942 pRecBAEntry =&pAd->BATable.BARecEntry[pEntry->BARecWcidArray[j]];
1943 sprintf(pOutBuf + strlen(pOutBuf), "TID=%d, BAWinSize=%d, LastIndSeq=%d, ReorderingPkts=%d\n", j, pRecBAEntry->BAWinSize, pRecBAEntry->LastIndSeq, pRecBAEntry->list.qlen);
1946 sprintf(pOutBuf, "%s\n", pOutBuf);
1948 sprintf(pOutBuf, "%s[Originator]\n", pOutBuf);
1949 for (j=0; j < NUM_OF_TID; j++)
1951 if (pEntry->BAOriWcidArray[j] != 0)
1953 pOriBAEntry =&pAd->BATable.BAOriEntry[pEntry->BAOriWcidArray[j]];
1954 sprintf(pOutBuf + strlen(pOutBuf), "TID=%d, BAWinSize=%d, StartSeq=%d, CurTxSeq=%d\n", j, pOriBAEntry->BAWinSize, pOriBAEntry->Sequence, pEntry->TxSeq[j]);
1957 sprintf(pOutBuf, "%s\n\n", pOutBuf);
1959 if (strlen(pOutBuf) > (IW_PRIV_SIZE_MASK - 30))
1965 #endif // DOT11_N_SUPPORT //
1968 rt_private_show(struct net_device *dev, struct iw_request_info *info,
1969 struct iw_point *wrq, char *extra)
1972 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1975 u32 subcmd = wrq->flags;
1977 if (dev->priv_flags == INT_MAIN)
1981 pVirtualAd = dev->ml_priv;
1982 pAd = pVirtualAd->RtmpDev->ml_priv;
1984 pObj = (POS_COOKIE) pAd->OS_Cookie;
1988 /* if 1st open fail, pAd will be free;
1989 So the net_dev->ml_priv will be NULL in 2rd open */
1998 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2001 pObj->ioctl_if_type = INT_MAIN;
2002 pObj->ioctl_if = MAIN_MBSSID;
2008 case SHOW_CONN_STATUS:
2009 if (MONITOR_ON(pAd))
2011 #ifdef DOT11_N_SUPPORT
2012 if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
2013 pAd->CommonCfg.RegTransmitSetting.field.BW)
2014 sprintf(extra, "Monitor Mode(CentralChannel %d)\n", pAd->CommonCfg.CentralChannel);
2016 #endif // DOT11_N_SUPPORT //
2017 sprintf(extra, "Monitor Mode(Channel %d)\n", pAd->CommonCfg.Channel);
2021 if (pAd->IndicateMediaState == NdisMediaStateConnected)
2025 sprintf(extra, "Connected(AP: %s[%02X:%02X:%02X:%02X:%02X:%02X])\n",
2026 pAd->CommonCfg.Ssid,
2027 pAd->CommonCfg.Bssid[0],
2028 pAd->CommonCfg.Bssid[1],
2029 pAd->CommonCfg.Bssid[2],
2030 pAd->CommonCfg.Bssid[3],
2031 pAd->CommonCfg.Bssid[4],
2032 pAd->CommonCfg.Bssid[5]);
2033 DBGPRINT(RT_DEBUG_TRACE ,("Ssid=%s ,Ssidlen = %d\n",pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen));
2035 else if (ADHOC_ON(pAd))
2036 sprintf(extra, "Connected\n");
2040 sprintf(extra, "Disconnected\n");
2041 DBGPRINT(RT_DEBUG_TRACE ,("ConnStatus is not connected\n"));
2044 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2046 case SHOW_DRVIER_VERION:
2047 sprintf(extra, "Driver version-%s, %s %s\n", STA_DRIVER_VERSION, __DATE__, __TIME__ );
2048 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2050 #ifdef DOT11_N_SUPPORT
2052 getBaInfo(pAd, extra);
2053 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2055 #endif // DOT11_N_SUPPORT //
2056 case SHOW_DESC_INFO:
2058 Show_DescInfo_Proc(pAd, NULL);
2059 wrq->length = 0; // 1: size of '\0'
2063 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
2065 sprintf(extra, "Scanning\n");
2066 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2069 pAd->StaCfg.bSwRadio = FALSE;
2070 if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
2072 pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
2073 if (pAd->StaCfg.bRadio == FALSE)
2076 // Update extra information
2077 pAd->ExtraInfo = SW_RADIO_OFF;
2080 sprintf(extra, "Radio Off\n");
2081 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2084 pAd->StaCfg.bSwRadio = TRUE;
2085 //if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
2087 pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
2088 if (pAd->StaCfg.bRadio == TRUE)
2091 // Update extra information
2092 pAd->ExtraInfo = EXTRA_INFO_CLEAR;
2095 sprintf(extra, "Radio On\n");
2096 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2099 case SHOW_CFG_VALUE:
2101 Status = RTMPShowCfgValue(pAd, wrq->pointer, extra);
2103 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2107 DBGPRINT(RT_DEBUG_TRACE, ("%s - unknow subcmd = %d\n", __func__, subcmd));
2115 int rt_ioctl_siwmlme(struct net_device *dev,
2116 struct iw_request_info *info,
2117 union iwreq_data *wrqu,
2120 PRTMP_ADAPTER pAd = dev->ml_priv;
2121 struct iw_mlme *pMlme = (struct iw_mlme *)wrqu->data.pointer;
2122 MLME_QUEUE_ELEM MsgElem;
2123 MLME_DISASSOC_REQ_STRUCT DisAssocReq;
2124 MLME_DEAUTH_REQ_STRUCT DeAuthReq;
2126 DBGPRINT(RT_DEBUG_TRACE, ("====> %s\n", __func__));
2133 #ifdef IW_MLME_DEAUTH
2134 case IW_MLME_DEAUTH:
2135 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DEAUTH\n", __func__));
2136 COPY_MAC_ADDR(DeAuthReq.Addr, pAd->CommonCfg.Bssid);
2137 DeAuthReq.Reason = pMlme->reason_code;
2138 MsgElem.MsgLen = sizeof(MLME_DEAUTH_REQ_STRUCT);
2139 NdisMoveMemory(MsgElem.Msg, &DeAuthReq, sizeof(MLME_DEAUTH_REQ_STRUCT));
2140 MlmeDeauthReqAction(pAd, &MsgElem);
2143 LinkDown(pAd, FALSE);
2144 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
2147 #endif // IW_MLME_DEAUTH //
2148 #ifdef IW_MLME_DISASSOC
2149 case IW_MLME_DISASSOC:
2150 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DISASSOC\n", __func__));
2151 COPY_MAC_ADDR(DisAssocReq.Addr, pAd->CommonCfg.Bssid);
2152 DisAssocReq.Reason = pMlme->reason_code;
2154 MsgElem.Machine = ASSOC_STATE_MACHINE;
2155 MsgElem.MsgType = MT2_MLME_DISASSOC_REQ;
2156 MsgElem.MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
2157 NdisMoveMemory(MsgElem.Msg, &DisAssocReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
2159 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
2160 MlmeDisassocReqAction(pAd, &MsgElem);
2162 #endif // IW_MLME_DISASSOC //
2164 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - Unknow Command\n", __func__));
2170 #endif // SIOCSIWMLME //
2172 #if WIRELESS_EXT > 17
2173 int rt_ioctl_siwauth(struct net_device *dev,
2174 struct iw_request_info *info,
2175 union iwreq_data *wrqu, char *extra)
2177 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2178 struct iw_param *param = &wrqu->param;
2180 //check if the interface is down
2181 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2183 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2186 switch (param->flags & IW_AUTH_INDEX) {
2187 case IW_AUTH_WPA_VERSION:
2188 if (param->value == IW_AUTH_WPA_VERSION_WPA)
2190 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
2191 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
2192 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
2194 else if (param->value == IW_AUTH_WPA_VERSION_WPA2)
2195 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
2197 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __func__, param->value));
2199 case IW_AUTH_CIPHER_PAIRWISE:
2200 if (param->value == IW_AUTH_CIPHER_NONE)
2202 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
2203 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2204 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
2206 else if (param->value == IW_AUTH_CIPHER_WEP40 ||
2207 param->value == IW_AUTH_CIPHER_WEP104)
2209 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
2210 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2211 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
2212 #ifdef WPA_SUPPLICANT_SUPPORT
2213 pAdapter->StaCfg.IEEE8021X = FALSE;
2214 #endif // WPA_SUPPLICANT_SUPPORT //
2216 else if (param->value == IW_AUTH_CIPHER_TKIP)
2218 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
2219 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2220 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
2222 else if (param->value == IW_AUTH_CIPHER_CCMP)
2224 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
2225 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2226 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
2228 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_PAIRWISE - param->value = %d!\n", __func__, param->value));
2230 case IW_AUTH_CIPHER_GROUP:
2231 if (param->value == IW_AUTH_CIPHER_NONE)
2233 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
2235 else if (param->value == IW_AUTH_CIPHER_WEP40 ||
2236 param->value == IW_AUTH_CIPHER_WEP104)
2238 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
2240 else if (param->value == IW_AUTH_CIPHER_TKIP)
2242 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
2244 else if (param->value == IW_AUTH_CIPHER_CCMP)
2246 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
2248 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_GROUP - param->value = %d!\n", __func__, param->value));
2250 case IW_AUTH_KEY_MGMT:
2251 if (param->value == IW_AUTH_KEY_MGMT_802_1X)
2253 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)
2255 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
2256 #ifdef WPA_SUPPLICANT_SUPPORT
2257 pAdapter->StaCfg.IEEE8021X = FALSE;
2258 #endif // WPA_SUPPLICANT_SUPPORT //
2260 else if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
2262 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
2263 #ifdef WPA_SUPPLICANT_SUPPORT
2264 pAdapter->StaCfg.IEEE8021X = FALSE;
2265 #endif // WPA_SUPPLICANT_SUPPORT //
2267 #ifdef WPA_SUPPLICANT_SUPPORT
2270 pAdapter->StaCfg.IEEE8021X = TRUE;
2271 #endif // WPA_SUPPLICANT_SUPPORT //
2273 else if (param->value == 0)
2275 STA_PORT_SECURED(pAdapter);
2277 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_KEY_MGMT - param->value = %d!\n", __func__, param->value));
2279 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
2281 case IW_AUTH_PRIVACY_INVOKED:
2282 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_PRIVACY_INVOKED - param->value = %d!\n", __func__, param->value));
2284 case IW_AUTH_DROP_UNENCRYPTED:
2285 if (param->value != 0)
2286 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
2289 STA_PORT_SECURED(pAdapter);
2291 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __func__, param->value));
2293 case IW_AUTH_80211_AUTH_ALG:
2294 if (param->value & IW_AUTH_ALG_SHARED_KEY)
2296 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
2298 else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
2300 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
2304 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_80211_AUTH_ALG - param->value = %d!\n", __func__, param->value));
2306 case IW_AUTH_WPA_ENABLED:
2307 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_ENABLED - Driver supports WPA!(param->value = %d)\n", __func__, param->value));
2316 int rt_ioctl_giwauth(struct net_device *dev,
2317 struct iw_request_info *info,
2318 union iwreq_data *wrqu, char *extra)
2320 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2321 struct iw_param *param = &wrqu->param;
2323 //check if the interface is down
2324 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2326 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2330 switch (param->flags & IW_AUTH_INDEX) {
2331 case IW_AUTH_DROP_UNENCRYPTED:
2332 param->value = (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled) ? 0 : 1;
2335 case IW_AUTH_80211_AUTH_ALG:
2336 param->value = (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared) ? IW_AUTH_ALG_SHARED_KEY : IW_AUTH_ALG_OPEN_SYSTEM;
2339 case IW_AUTH_WPA_ENABLED:
2340 param->value = (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) ? 1 : 0;
2346 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_giwauth::param->value = %d!\n", param->value));
2350 void fnSetCipherKey(
2351 IN PRTMP_ADAPTER pAdapter,
2355 IN struct iw_encode_ext *ext)
2357 RTMP_CLEAR_PSFLAG(pAdapter, fRTMP_PS_CAN_GO_SLEEP);
2358 if (RTMP_TEST_PSFLAG(pAdapter, fRTMP_PS_SET_PCI_CLK_OFF_COMMAND))
2360 if (pAdapter->StaCfg.bRadio == FALSE)
2362 RTMP_SET_PSFLAG(pAdapter, fRTMP_PS_CAN_GO_SLEEP);
2365 DBGPRINT(RT_DEBUG_TRACE,("RTMPWPAAddKeyProc1==>\n"));
2366 RTMPPCIeLinkCtrlValueRestore(pAdapter, RESTORE_HALT);
2367 RTMPusecDelay(6000);
2368 pAdapter->bPCIclkOff = FALSE;
2371 NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
2372 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = LEN_TKIP_EK;
2373 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, LEN_TKIP_EK);
2374 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].TxMic, ext->key + LEN_TKIP_EK, LEN_TKIP_TXMICK);
2375 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].RxMic, ext->key + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
2376 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CipherAlg;
2378 // Update group key information to ASIC Shared Key Table
2379 AsicAddSharedKeyEntry(pAdapter,
2382 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2383 pAdapter->SharedKey[BSS0][keyIdx].Key,
2384 pAdapter->SharedKey[BSS0][keyIdx].TxMic,
2385 pAdapter->SharedKey[BSS0][keyIdx].RxMic);
2388 // Update ASIC WCID attribute table and IVEIV table
2389 RTMPAddWcidAttributeEntry(pAdapter,
2392 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2395 // Update ASIC WCID attribute table and IVEIV table
2396 RTMPAddWcidAttributeEntry(pAdapter,
2399 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2400 &pAdapter->MacTab.Content[BSSID_WCID]);
2402 RTMP_SET_PSFLAG(pAdapter, fRTMP_PS_CAN_GO_SLEEP);
2405 int rt_ioctl_siwencodeext(struct net_device *dev,
2406 struct iw_request_info *info,
2407 union iwreq_data *wrqu,
2410 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2411 struct iw_point *encoding = &wrqu->encoding;
2412 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2413 int keyIdx, alg = ext->alg;
2415 //check if the interface is down
2416 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2418 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2422 if (encoding->flags & IW_ENCODE_DISABLED)
2424 keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
2425 // set BSSID wcid entry of the Pair-wise Key table as no-security mode
2426 AsicRemovePairwiseKeyEntry(pAdapter, BSS0, BSSID_WCID);
2427 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
2428 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_NONE;
2429 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)keyIdx);
2430 NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
2431 DBGPRINT(RT_DEBUG_TRACE, ("%s::Remove all keys!(encoding->flags = %x)\n", __func__, encoding->flags));
2435 // Get Key Index and convet to our own defined key index
2436 keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
2437 if((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
2440 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2442 pAdapter->StaCfg.DefaultKeyId = keyIdx;
2443 DBGPRINT(RT_DEBUG_TRACE, ("%s::DefaultKeyId = %d\n", __func__, pAdapter->StaCfg.DefaultKeyId));
2447 case IW_ENCODE_ALG_NONE:
2448 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_NONE\n", __func__));
2450 case IW_ENCODE_ALG_WEP:
2451 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_WEP - ext->key_len = %d, keyIdx = %d\n", __func__, ext->key_len, keyIdx));
2452 if (ext->key_len == MAX_WEP_KEY_SIZE)
2454 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
2455 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
2457 else if (ext->key_len == MIN_WEP_KEY_SIZE)
2459 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
2460 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
2465 NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
2466 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, ext->key_len);
2468 if (pAdapter->StaCfg.GroupCipher == Ndis802_11GroupWEP40Enabled ||
2469 pAdapter->StaCfg.GroupCipher == Ndis802_11GroupWEP104Enabled)
2471 // Set Group key material to Asic
2472 AsicAddSharedKeyEntry(pAdapter, BSS0, keyIdx, pAdapter->SharedKey[BSS0][keyIdx].CipherAlg, pAdapter->SharedKey[BSS0][keyIdx].Key, NULL, NULL);
2474 // Update WCID attribute table and IVEIV table for this group key table
2475 RTMPAddWcidAttributeEntry(pAdapter, BSS0, keyIdx, pAdapter->SharedKey[BSS0][keyIdx].CipherAlg, NULL);
2477 STA_PORT_SECURED(pAdapter);
2479 // Indicate Connected for GUI
2480 pAdapter->IndicateMediaState = NdisMediaStateConnected;
2483 case IW_ENCODE_ALG_TKIP:
2484 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_TKIP - keyIdx = %d, ext->key_len = %d\n", __func__, keyIdx, ext->key_len));
2485 if (ext->key_len == 32)
2487 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2489 fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, FALSE, ext);
2490 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
2492 STA_PORT_SECURED(pAdapter);
2495 else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
2497 fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, TRUE, ext);
2499 // set 802.1x port control
2500 STA_PORT_SECURED(pAdapter);
2506 case IW_ENCODE_ALG_CCMP:
2507 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2509 fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, FALSE, ext);
2510 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
2511 STA_PORT_SECURED(pAdapter);
2513 else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
2515 fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, TRUE, ext);
2517 // set 802.1x port control
2518 STA_PORT_SECURED(pAdapter);
2530 rt_ioctl_giwencodeext(struct net_device *dev,
2531 struct iw_request_info *info,
2532 union iwreq_data *wrqu, char *extra)
2534 PRTMP_ADAPTER pAd = dev->ml_priv;
2536 struct iw_point *encoding = &wrqu->encoding;
2537 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2538 int idx, max_key_len;
2540 DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_giwencodeext\n"));
2542 max_key_len = encoding->length - sizeof(*ext);
2543 if (max_key_len < 0)
2546 idx = encoding->flags & IW_ENCODE_INDEX;
2549 if (idx < 1 || idx > 4)
2553 if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
2554 (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled))
2556 if (idx != pAd->StaCfg.DefaultKeyId)
2564 idx = pAd->StaCfg.DefaultKeyId;
2566 encoding->flags = idx + 1;
2567 memset(ext, 0, sizeof(*ext));
2570 switch(pAd->StaCfg.WepStatus) {
2571 case Ndis802_11WEPDisabled:
2572 ext->alg = IW_ENCODE_ALG_NONE;
2573 encoding->flags |= IW_ENCODE_DISABLED;
2575 case Ndis802_11WEPEnabled:
2576 ext->alg = IW_ENCODE_ALG_WEP;
2577 if (pAd->SharedKey[BSS0][idx].KeyLen > max_key_len)
2581 ext->key_len = pAd->SharedKey[BSS0][idx].KeyLen;
2582 pKey = &(pAd->SharedKey[BSS0][idx].Key[0]);
2585 case Ndis802_11Encryption2Enabled:
2586 case Ndis802_11Encryption3Enabled:
2587 if (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
2588 ext->alg = IW_ENCODE_ALG_TKIP;
2590 ext->alg = IW_ENCODE_ALG_CCMP;
2592 if (max_key_len < 32)
2597 pKey = &pAd->StaCfg.PMK[0];
2604 if (ext->key_len && pKey)
2606 encoding->flags |= IW_ENCODE_ENABLED;
2607 memcpy(ext->key, pKey, ext->key_len);
2614 int rt_ioctl_siwgenie(struct net_device *dev,
2615 struct iw_request_info *info,
2616 union iwreq_data *wrqu, char *extra)
2618 PRTMP_ADAPTER pAd = dev->ml_priv;
2620 if (wrqu->data.length > MAX_LEN_OF_RSNIE ||
2621 (wrqu->data.length && extra == NULL))
2624 if (wrqu->data.length)
2626 pAd->StaCfg.RSNIE_Len = wrqu->data.length;
2627 NdisMoveMemory(&pAd->StaCfg.RSN_IE[0], extra, pAd->StaCfg.RSNIE_Len);
2631 pAd->StaCfg.RSNIE_Len = 0;
2632 NdisZeroMemory(&pAd->StaCfg.RSN_IE[0], MAX_LEN_OF_RSNIE);
2637 #endif // SIOCSIWGENIE //
2639 int rt_ioctl_giwgenie(struct net_device *dev,
2640 struct iw_request_info *info,
2641 union iwreq_data *wrqu, char *extra)
2643 PRTMP_ADAPTER pAd = dev->ml_priv;
2645 if ((pAd->StaCfg.RSNIE_Len == 0) ||
2646 (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA))
2648 wrqu->data.length = 0;
2652 #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
2654 if (pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
2656 if (wrqu->data.length < pAd->StaCfg.RSNIE_Len)
2659 wrqu->data.length = pAd->StaCfg.RSNIE_Len;
2660 memcpy(extra, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
2663 #endif // SIOCSIWGENIE //
2664 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
2666 UCHAR RSNIe = IE_WPA;
2668 if (wrqu->data.length < (pAd->StaCfg.RSNIE_Len + 2)) // ID, Len
2670 wrqu->data.length = pAd->StaCfg.RSNIE_Len + 2;
2672 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
2673 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2))
2676 extra[0] = (char)RSNIe;
2677 extra[1] = pAd->StaCfg.RSNIE_Len;
2678 memcpy(extra+2, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
2684 int rt_ioctl_siwpmksa(struct net_device *dev,
2685 struct iw_request_info *info,
2686 union iwreq_data *wrqu,
2689 PRTMP_ADAPTER pAd = dev->ml_priv;
2690 struct iw_pmksa *pPmksa = (struct iw_pmksa *)wrqu->data.pointer;
2691 INT CachedIdx = 0, idx = 0;
2696 DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_siwpmksa\n"));
2699 case IW_PMKSA_FLUSH:
2700 NdisZeroMemory(pAd->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
2701 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_FLUSH\n"));
2703 case IW_PMKSA_REMOVE:
2704 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
2706 // compare the BSSID
2707 if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
2709 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN);
2710 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].PMKID, 16);
2711 for (idx = CachedIdx; idx < (pAd->StaCfg.SavedPMKNum - 1); idx++)
2713 NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].BSSID[0], &pAd->StaCfg.SavedPMK[idx+1].BSSID[0], MAC_ADDR_LEN);
2714 NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].PMKID[0], &pAd->StaCfg.SavedPMK[idx+1].PMKID[0], 16);
2716 pAd->StaCfg.SavedPMKNum--;
2721 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_REMOVE\n"));
2724 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
2726 // compare the BSSID
2727 if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
2731 // Found, replace it
2732 if (CachedIdx < PMKID_NO)
2734 DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
2735 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
2736 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
2737 pAd->StaCfg.SavedPMKNum++;
2739 // Not found, replace the last one
2742 // Randomly replace one
2743 CachedIdx = (pPmksa->bssid.sa_data[5] % PMKID_NO);
2744 DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
2745 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
2746 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
2749 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_ADD\n"));
2752 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - Unknow Command!!\n"));
2758 #endif // #if WIRELESS_EXT > 17
2762 rt_private_ioctl_bbp(struct net_device *dev, struct iw_request_info *info,
2763 struct iw_point *wrq, char *extra)
2770 BOOLEAN bIsPrintAllBBP = FALSE;
2772 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2775 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2777 if (wrq->length > 1) //No parameters.
2779 sprintf(extra, "\n");
2781 //Parsing Read or Write
2782 this_char = wrq->pointer;
2783 DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s\n", this_char));
2787 if ((value = rtstrchr(this_char, '=')) != NULL)
2790 if (!value || !*value)
2792 DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s, value=%s\n", this_char, value));
2793 if (sscanf(this_char, "%d", &(bbpId)) == 1)
2798 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
2800 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
2801 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2802 DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
2805 {//Invalid parametes, so default printk all bbp
2806 bIsPrintAllBBP = TRUE;
2811 { //Invalid parametes, so default printk all bbp
2812 bIsPrintAllBBP = TRUE;
2818 if ((sscanf(this_char, "%d", &(bbpId)) == 1) && (sscanf(value, "%x", &(bbpValue)) == 1))
2823 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, bbpId, bbpValue);
2824 //Read it back for showing
2825 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
2827 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
2828 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2829 DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
2832 {//Invalid parametes, so default printk all bbp
2833 bIsPrintAllBBP = TRUE;
2838 { //Invalid parametes, so default printk all bbp
2839 bIsPrintAllBBP = TRUE;
2845 bIsPrintAllBBP = TRUE;
2850 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2851 sprintf(extra, "\n");
2852 for (bbpId = 0; bbpId <= 136; bbpId++)
2854 if (strlen(extra) >= (IW_PRIV_SIZE_MASK - 10))
2856 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
2857 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X ", bbpId, bbpId*2, regBBP);
2859 sprintf(extra+strlen(extra), "\n");
2862 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2863 DBGPRINT(RT_DEBUG_TRACE, ("wrq->length = %d\n", wrq->length));
2866 DBGPRINT(RT_DEBUG_TRACE, ("<==rt_private_ioctl_bbp\n\n"));
2872 int rt_ioctl_siwrate(struct net_device *dev,
2873 struct iw_request_info *info,
2874 union iwreq_data *wrqu, char *extra)
2876 PRTMP_ADAPTER pAd = dev->ml_priv;
2877 UINT32 rate = wrqu->bitrate.value, fixed = wrqu->bitrate.fixed;
2879 //check if the interface is down
2880 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2882 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::Network is down!\n"));
2886 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(rate = %d, fixed = %d)\n", rate, fixed));
2887 /* rate = -1 => auto rate
2888 rate = X, fixed = 1 => (fixed rate X)
2893 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
2894 pAd->StaCfg.bAutoTxRateSwitch = TRUE;
2895 if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
2896 (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
2897 RTMPSetDesiredRates(pAd, -1);
2899 #ifdef DOT11_N_SUPPORT
2901 #endif // DOT11_N_SUPPORT //
2907 pAd->StaCfg.bAutoTxRateSwitch = FALSE;
2908 if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
2909 (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
2910 RTMPSetDesiredRates(pAd, rate);
2913 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
2914 #ifdef DOT11_N_SUPPORT
2916 #endif // DOT11_N_SUPPORT //
2918 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(HtMcs=%d)\n",pAd->StaCfg.DesiredTransmitSetting.field.MCS));
2922 // TODO: rate = X, fixed = 0 => (rates <= X)
2930 int rt_ioctl_giwrate(struct net_device *dev,
2931 struct iw_request_info *info,
2932 union iwreq_data *wrqu, char *extra)
2934 PRTMP_ADAPTER pAd = dev->ml_priv;
2935 int rate_index = 0, rate_count = 0;
2936 HTTRANSMIT_SETTING ht_setting;
2937 __s32 ralinkrate[] =
2938 {2, 4, 11, 22, // CCK
2939 12, 18, 24, 36, 48, 72, 96, 108, // OFDM
2940 13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260, // 20MHz, 800ns GI, MCS: 0 ~ 15
2941 39, 78, 117, 156, 234, 312, 351, 390, // 20MHz, 800ns GI, MCS: 16 ~ 23
2942 27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540, // 40MHz, 800ns GI, MCS: 0 ~ 15
2943 81, 162, 243, 324, 486, 648, 729, 810, // 40MHz, 800ns GI, MCS: 16 ~ 23
2944 14, 29, 43, 57, 87, 115, 130, 144, 29, 59, 87, 115, 173, 230, 260, 288, // 20MHz, 400ns GI, MCS: 0 ~ 15
2945 43, 87, 130, 173, 260, 317, 390, 433, // 20MHz, 400ns GI, MCS: 16 ~ 23
2946 30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600, // 40MHz, 400ns GI, MCS: 0 ~ 15
2947 90, 180, 270, 360, 540, 720, 810, 900}; // 40MHz, 400ns GI, MCS: 16 ~ 23
2949 rate_count = sizeof(ralinkrate)/sizeof(__s32);
2950 //check if the interface is down
2951 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2953 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2957 if ((pAd->StaCfg.bAutoTxRateSwitch == FALSE) &&
2959 ((pAd->CommonCfg.PhyMode <= PHY_11G) || (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM)))
2960 ht_setting.word = pAd->StaCfg.HTPhyMode.word;
2962 ht_setting.word = pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word;
2964 #ifdef DOT11_N_SUPPORT
2965 if (ht_setting.field.MODE >= MODE_HTMIX)
2967 rate_index = 12 + ((UCHAR)ht_setting.field.BW *24) + ((UCHAR)ht_setting.field.ShortGI *48) + ((UCHAR)ht_setting.field.MCS);
2970 #endif // DOT11_N_SUPPORT //
2971 if (ht_setting.field.MODE == MODE_OFDM)
2972 rate_index = (UCHAR)(ht_setting.field.MCS) + 4;
2973 else if (ht_setting.field.MODE == MODE_CCK)
2974 rate_index = (UCHAR)(ht_setting.field.MCS);
2979 if (rate_index > rate_count)
2980 rate_index = rate_count;
2982 wrqu->bitrate.value = ralinkrate[rate_index] * 500000;
2983 wrqu->bitrate.disabled = 0;
2988 static const iw_handler rt_handler[] =
2990 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2991 (iw_handler) rt_ioctl_giwname, /* SIOCGIWNAME */
2992 (iw_handler) NULL, /* SIOCSIWNWID */
2993 (iw_handler) NULL, /* SIOCGIWNWID */
2994 (iw_handler) rt_ioctl_siwfreq, /* SIOCSIWFREQ */
2995 (iw_handler) rt_ioctl_giwfreq, /* SIOCGIWFREQ */
2996 (iw_handler) rt_ioctl_siwmode, /* SIOCSIWMODE */
2997 (iw_handler) rt_ioctl_giwmode, /* SIOCGIWMODE */
2998 (iw_handler) NULL, /* SIOCSIWSENS */
2999 (iw_handler) NULL, /* SIOCGIWSENS */
3000 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
3001 (iw_handler) rt_ioctl_giwrange, /* SIOCGIWRANGE */
3002 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
3003 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
3004 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
3005 (iw_handler) rt28xx_get_wireless_stats /* kernel code */, /* SIOCGIWSTATS */
3006 (iw_handler) NULL, /* SIOCSIWSPY */
3007 (iw_handler) NULL, /* SIOCGIWSPY */
3008 (iw_handler) NULL, /* SIOCSIWTHRSPY */
3009 (iw_handler) NULL, /* SIOCGIWTHRSPY */
3010 (iw_handler) rt_ioctl_siwap, /* SIOCSIWAP */
3011 (iw_handler) rt_ioctl_giwap, /* SIOCGIWAP */
3013 (iw_handler) rt_ioctl_siwmlme, /* SIOCSIWMLME */
3015 (iw_handler) NULL, /* SIOCSIWMLME */
3016 #endif // SIOCSIWMLME //
3017 (iw_handler) rt_ioctl_iwaplist, /* SIOCGIWAPLIST */
3019 (iw_handler) rt_ioctl_siwscan, /* SIOCSIWSCAN */
3020 (iw_handler) rt_ioctl_giwscan, /* SIOCGIWSCAN */
3022 (iw_handler) NULL, /* SIOCSIWSCAN */
3023 (iw_handler) NULL, /* SIOCGIWSCAN */
3024 #endif /* SIOCGIWSCAN */
3025 (iw_handler) rt_ioctl_siwessid, /* SIOCSIWESSID */
3026 (iw_handler) rt_ioctl_giwessid, /* SIOCGIWESSID */
3027 (iw_handler) rt_ioctl_siwnickn, /* SIOCSIWNICKN */
3028 (iw_handler) rt_ioctl_giwnickn, /* SIOCGIWNICKN */
3029 (iw_handler) NULL, /* -- hole -- */
3030 (iw_handler) NULL, /* -- hole -- */
3031 (iw_handler) rt_ioctl_siwrate, /* SIOCSIWRATE */
3032 (iw_handler) rt_ioctl_giwrate, /* SIOCGIWRATE */
3033 (iw_handler) rt_ioctl_siwrts, /* SIOCSIWRTS */
3034 (iw_handler) rt_ioctl_giwrts, /* SIOCGIWRTS */
3035 (iw_handler) rt_ioctl_siwfrag, /* SIOCSIWFRAG */
3036 (iw_handler) rt_ioctl_giwfrag, /* SIOCGIWFRAG */
3037 (iw_handler) NULL, /* SIOCSIWTXPOW */
3038 (iw_handler) NULL, /* SIOCGIWTXPOW */
3039 (iw_handler) NULL, /* SIOCSIWRETRY */
3040 (iw_handler) NULL, /* SIOCGIWRETRY */
3041 (iw_handler) rt_ioctl_siwencode, /* SIOCSIWENCODE */
3042 (iw_handler) rt_ioctl_giwencode, /* SIOCGIWENCODE */
3043 (iw_handler) NULL, /* SIOCSIWPOWER */
3044 (iw_handler) NULL, /* SIOCGIWPOWER */
3045 (iw_handler) NULL, /* -- hole -- */
3046 (iw_handler) NULL, /* -- hole -- */
3047 #if WIRELESS_EXT > 17
3048 (iw_handler) rt_ioctl_siwgenie, /* SIOCSIWGENIE */
3049 (iw_handler) rt_ioctl_giwgenie, /* SIOCGIWGENIE */
3050 (iw_handler) rt_ioctl_siwauth, /* SIOCSIWAUTH */
3051 (iw_handler) rt_ioctl_giwauth, /* SIOCGIWAUTH */
3052 (iw_handler) rt_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
3053 (iw_handler) rt_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */
3054 (iw_handler) rt_ioctl_siwpmksa, /* SIOCSIWPMKSA */
3058 static const iw_handler rt_priv_handlers[] = {
3059 (iw_handler) NULL, /* + 0x00 */
3060 (iw_handler) NULL, /* + 0x01 */
3061 #ifndef CONFIG_AP_SUPPORT
3062 (iw_handler) rt_ioctl_setparam, /* + 0x02 */
3064 (iw_handler) NULL, /* + 0x02 */
3065 #endif // CONFIG_AP_SUPPORT //
3067 (iw_handler) rt_private_ioctl_bbp, /* + 0x03 */
3069 (iw_handler) NULL, /* + 0x03 */
3071 (iw_handler) NULL, /* + 0x04 */
3072 (iw_handler) NULL, /* + 0x05 */
3073 (iw_handler) NULL, /* + 0x06 */
3074 (iw_handler) NULL, /* + 0x07 */
3075 (iw_handler) NULL, /* + 0x08 */
3076 (iw_handler) rt_private_get_statistics, /* + 0x09 */
3077 (iw_handler) NULL, /* + 0x0A */
3078 (iw_handler) NULL, /* + 0x0B */
3079 (iw_handler) NULL, /* + 0x0C */
3080 (iw_handler) NULL, /* + 0x0D */
3081 (iw_handler) NULL, /* + 0x0E */
3082 (iw_handler) NULL, /* + 0x0F */
3083 (iw_handler) NULL, /* + 0x10 */
3084 (iw_handler) rt_private_show, /* + 0x11 */
3085 (iw_handler) NULL, /* + 0x12 */
3086 (iw_handler) NULL, /* + 0x13 */
3087 (iw_handler) NULL, /* + 0x15 */
3088 (iw_handler) NULL, /* + 0x17 */
3089 (iw_handler) NULL, /* + 0x18 */
3092 const struct iw_handler_def rt28xx_iw_handler_def =
3094 #define N(a) (sizeof (a) / sizeof (a[0]))
3095 .standard = (iw_handler *) rt_handler,
3096 .num_standard = sizeof(rt_handler) / sizeof(iw_handler),
3097 .private = (iw_handler *) rt_priv_handlers,
3098 .num_private = N(rt_priv_handlers),
3099 .private_args = (struct iw_priv_args *) privtab,
3100 .num_private_args = N(privtab),
3101 #if IW_HANDLER_VERSION >= 7
3102 .get_wireless_stats = rt28xx_get_wireless_stats,
3106 INT RTMPSetInformation(
3107 IN PRTMP_ADAPTER pAdapter,
3108 IN OUT struct ifreq *rq,
3111 struct iwreq *wrq = (struct iwreq *) rq;
3112 NDIS_802_11_SSID Ssid;
3113 NDIS_802_11_MAC_ADDRESS Bssid;
3114 RT_802_11_PHY_MODE PhyMode;
3115 RT_802_11_STA_CONFIG StaConfig;
3116 NDIS_802_11_RATES aryRates;
3117 RT_802_11_PREAMBLE Preamble;
3118 NDIS_802_11_WEP_STATUS WepStatus;
3119 NDIS_802_11_AUTHENTICATION_MODE AuthMode = Ndis802_11AuthModeMax;
3120 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
3121 NDIS_802_11_RTS_THRESHOLD RtsThresh;
3122 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
3123 NDIS_802_11_POWER_MODE PowerMode;
3124 PNDIS_802_11_KEY pKey = NULL;
3125 PNDIS_802_11_WEP pWepKey =NULL;
3126 PNDIS_802_11_REMOVE_KEY pRemoveKey = NULL;
3127 NDIS_802_11_CONFIGURATION Config, *pConfig = NULL;
3128 NDIS_802_11_NETWORK_TYPE NetType;
3131 INT Status = NDIS_STATUS_SUCCESS, MaxPhyMode = PHY_11G;
3134 BOOLEAN StateMachineTouched = FALSE;
3135 #ifdef DOT11_N_SUPPORT
3136 OID_SET_HT_PHYMODE HT_PhyMode; //11n ,kathy
3137 #endif // DOT11_N_SUPPORT //
3138 #ifdef WPA_SUPPLICANT_SUPPORT
3139 PNDIS_802_11_PMKID pPmkId = NULL;
3140 BOOLEAN IEEE8021xState = FALSE;
3141 BOOLEAN IEEE8021x_required_keys = FALSE;
3142 UCHAR wpa_supplicant_enable = 0;
3143 #endif // WPA_SUPPLICANT_SUPPORT //
3146 TX_RTY_CFG_STRUC tx_rty_cfg;
3147 ULONG ShortRetryLimit, LongRetryLimit;
3149 #endif // SNMP_SUPPORT //
3152 #ifdef DOT11_N_SUPPORT
3153 MaxPhyMode = PHY_11N_5G;
3154 #endif // DOT11_N_SUPPORT //
3157 DBGPRINT(RT_DEBUG_TRACE, ("-->RTMPSetInformation(), 0x%08x\n", cmd&0x7FFF));
3158 switch(cmd & 0x7FFF) {
3159 case RT_OID_802_11_COUNTRY_REGION:
3160 if (wrq->u.data.length < sizeof(UCHAR))
3162 // Only avaliable when EEPROM not programming
3163 else if (!(pAdapter->CommonCfg.CountryRegion & 0x80) && !(pAdapter->CommonCfg.CountryRegionForABand & 0x80))
3168 Status = copy_from_user(&Country, wrq->u.data.pointer, wrq->u.data.length);
3169 pAdapter->CommonCfg.CountryRegion = (UCHAR)(Country & 0x000000FF);
3170 pAdapter->CommonCfg.CountryRegionForABand = (UCHAR)((Country >> 8) & 0x000000FF);
3171 TmpPhy = pAdapter->CommonCfg.PhyMode;
3172 pAdapter->CommonCfg.PhyMode = 0xff;
3173 // Build all corresponding channel information
3174 RTMPSetPhyMode(pAdapter, TmpPhy);
3175 #ifdef DOT11_N_SUPPORT
3176 SetCommonHT(pAdapter);
3177 #endif // DOT11_N_SUPPORT //
3178 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_COUNTRY_REGION (A:%d B/G:%d)\n", pAdapter->CommonCfg.CountryRegionForABand,
3179 pAdapter->CommonCfg.CountryRegion));
3182 case OID_802_11_BSSID_LIST_SCAN:
3184 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID_LIST_SCAN, TxCnt = %d \n", pAdapter->RalinkCounters.LastOneSecTotalTxCount));
3186 if (MONITOR_ON(pAdapter))
3188 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
3192 //Benson add 20080527, when radio off, sta don't need to scan
3193 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_RADIO_OFF))
3196 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
3198 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is scanning now !!!\n"));
3199 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
3200 Status = NDIS_STATUS_SUCCESS;
3204 if (pAdapter->RalinkCounters.LastOneSecTotalTxCount > 100)
3206 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
3207 Status = NDIS_STATUS_SUCCESS;
3208 pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
3212 if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
3213 ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
3214 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
3215 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
3216 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)) &&
3217 (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
3219 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
3220 Status = NDIS_STATUS_SUCCESS;
3221 pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
3226 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3228 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3229 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3232 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
3233 // this request, because this request is initiated by NDIS.
3234 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
3235 // Reset allowed scan retries
3236 pAdapter->StaCfg.ScanCnt = 0;
3237 pAdapter->StaCfg.LastScanTime = Now;
3239 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
3240 RTMP_SET_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
3241 MlmeEnqueue(pAdapter,
3242 MLME_CNTL_STATE_MACHINE,
3243 OID_802_11_BSSID_LIST_SCAN,
3247 Status = NDIS_STATUS_SUCCESS;
3248 StateMachineTouched = TRUE;
3250 case OID_802_11_SSID:
3251 if (wrq->u.data.length != sizeof(NDIS_802_11_SSID))
3255 PCHAR pSsidString = NULL;
3256 Status = copy_from_user(&Ssid, wrq->u.data.pointer, wrq->u.data.length);
3258 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SSID (Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
3259 if (Ssid.SsidLength > MAX_LEN_OF_SSID)
3263 if (Ssid.SsidLength == 0)
3265 Set_SSID_Proc(pAdapter, "");
3269 pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
3272 NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
3273 NdisMoveMemory(pSsidString, Ssid.Ssid, Ssid.SsidLength);
3274 Set_SSID_Proc(pAdapter, pSsidString);
3283 case OID_802_11_BSSID:
3284 if (wrq->u.data.length != sizeof(NDIS_802_11_MAC_ADDRESS))
3288 Status = copy_from_user(&Bssid, wrq->u.data.pointer, wrq->u.data.length);
3290 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
3291 // this request, because this request is initiated by NDIS.
3292 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
3294 // Prevent to connect AP again in STAMlmePeriodicExec
3295 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
3297 // Reset allowed scan retries
3298 pAdapter->StaCfg.ScanCnt = 0;
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"));
3305 MlmeEnqueue(pAdapter,
3306 MLME_CNTL_STATE_MACHINE,
3308 sizeof(NDIS_802_11_MAC_ADDRESS),
3310 Status = NDIS_STATUS_SUCCESS;
3311 StateMachineTouched = TRUE;
3313 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID %02x:%02x:%02x:%02x:%02x:%02x\n",
3314 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
3317 case RT_OID_802_11_RADIO:
3318 if (wrq->u.data.length != sizeof(BOOLEAN))
3322 Status = copy_from_user(&RadioState, wrq->u.data.pointer, wrq->u.data.length);
3323 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RADIO (=%d)\n", RadioState));
3324 if (pAdapter->StaCfg.bSwRadio != RadioState)
3326 pAdapter->StaCfg.bSwRadio = RadioState;
3327 if (pAdapter->StaCfg.bRadio != (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio))
3329 pAdapter->StaCfg.bRadio = (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio);
3330 if (pAdapter->StaCfg.bRadio == TRUE)
3332 MlmeRadioOn(pAdapter);
3333 // Update extra information
3334 pAdapter->ExtraInfo = EXTRA_INFO_CLEAR;
3338 MlmeRadioOff(pAdapter);
3339 // Update extra information
3340 pAdapter->ExtraInfo = SW_RADIO_OFF;
3346 case RT_OID_802_11_PHY_MODE:
3347 if (wrq->u.data.length != sizeof(RT_802_11_PHY_MODE))
3351 Status = copy_from_user(&PhyMode, wrq->u.data.pointer, wrq->u.data.length);
3352 if (PhyMode <= MaxPhyMode)
3354 RTMPSetPhyMode(pAdapter, PhyMode);
3355 #ifdef DOT11_N_SUPPORT
3356 SetCommonHT(pAdapter);
3357 #endif // DOT11_N_SUPPORT //
3359 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PHY_MODE (=%d)\n", PhyMode));
3362 case RT_OID_802_11_STA_CONFIG:
3363 if (wrq->u.data.length != sizeof(RT_802_11_STA_CONFIG))
3367 Status = copy_from_user(&StaConfig, wrq->u.data.pointer, wrq->u.data.length);
3368 pAdapter->CommonCfg.bEnableTxBurst = StaConfig.EnableTxBurst;
3369 pAdapter->CommonCfg.UseBGProtection = StaConfig.UseBGProtection;
3370 pAdapter->CommonCfg.bUseShortSlotTime = 1; // 2003-10-30 always SHORT SLOT capable
3371 if ((pAdapter->CommonCfg.PhyMode != StaConfig.AdhocMode) &&
3372 (StaConfig.AdhocMode <= MaxPhyMode))
3374 // allow dynamic change of "USE OFDM rate or not" in ADHOC mode
3375 // if setting changed, need to reset current TX rate as well as BEACON frame format
3376 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
3378 pAdapter->CommonCfg.PhyMode = StaConfig.AdhocMode;
3379 RTMPSetPhyMode(pAdapter, PhyMode);
3380 MlmeUpdateTxRates(pAdapter, FALSE, 0);
3381 MakeIbssBeacon(pAdapter); // re-build BEACON frame
3382 AsicEnableIbssSync(pAdapter); // copy to on-chip memory
3385 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_STA_CONFIG (Burst=%d, Protection=%ld,ShortSlot=%d\n",
3386 pAdapter->CommonCfg.bEnableTxBurst,
3387 pAdapter->CommonCfg.UseBGProtection,
3388 pAdapter->CommonCfg.bUseShortSlotTime));
3391 case OID_802_11_DESIRED_RATES:
3392 if (wrq->u.data.length != sizeof(NDIS_802_11_RATES))
3396 Status = copy_from_user(&aryRates, wrq->u.data.pointer, wrq->u.data.length);
3397 NdisZeroMemory(pAdapter->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES);
3398 NdisMoveMemory(pAdapter->CommonCfg.DesireRate, &aryRates, sizeof(NDIS_802_11_RATES));
3399 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DESIRED_RATES (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
3400 pAdapter->CommonCfg.DesireRate[0],pAdapter->CommonCfg.DesireRate[1],
3401 pAdapter->CommonCfg.DesireRate[2],pAdapter->CommonCfg.DesireRate[3],
3402 pAdapter->CommonCfg.DesireRate[4],pAdapter->CommonCfg.DesireRate[5],
3403 pAdapter->CommonCfg.DesireRate[6],pAdapter->CommonCfg.DesireRate[7] ));
3404 // Changing DesiredRate may affect the MAX TX rate we used to TX frames out
3405 MlmeUpdateTxRates(pAdapter, FALSE, 0);
3408 case RT_OID_802_11_PREAMBLE:
3409 if (wrq->u.data.length != sizeof(RT_802_11_PREAMBLE))
3413 Status = copy_from_user(&Preamble, wrq->u.data.pointer, wrq->u.data.length);
3414 if (Preamble == Rt802_11PreambleShort)
3416 pAdapter->CommonCfg.TxPreamble = Preamble;
3417 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleShort);
3419 else if ((Preamble == Rt802_11PreambleLong) || (Preamble == Rt802_11PreambleAuto))
3421 // if user wants AUTO, initialize to LONG here, then change according to AP's
3422 // capability upon association.
3423 pAdapter->CommonCfg.TxPreamble = Preamble;
3424 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleLong);
3431 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PREAMBLE (=%d)\n", Preamble));
3434 case OID_802_11_WEP_STATUS:
3435 if (wrq->u.data.length != sizeof(NDIS_802_11_WEP_STATUS))
3439 Status = copy_from_user(&WepStatus, wrq->u.data.pointer, wrq->u.data.length);
3440 // Since TKIP, AES, WEP are all supported. It should not have any invalid setting
3441 if (WepStatus <= Ndis802_11Encryption3KeyAbsent)
3443 if (pAdapter->StaCfg.WepStatus != WepStatus)
3445 // Config has changed
3446 pAdapter->bConfigChanged = TRUE;
3448 pAdapter->StaCfg.WepStatus = WepStatus;
3449 pAdapter->StaCfg.OrigWepStatus = WepStatus;
3450 pAdapter->StaCfg.PairCipher = WepStatus;
3451 pAdapter->StaCfg.GroupCipher = WepStatus;
3458 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEP_STATUS (=%d)\n",WepStatus));
3461 case OID_802_11_AUTHENTICATION_MODE:
3462 if (wrq->u.data.length != sizeof(NDIS_802_11_AUTHENTICATION_MODE))
3466 Status = copy_from_user(&AuthMode, wrq->u.data.pointer, wrq->u.data.length);
3467 if (AuthMode > Ndis802_11AuthModeMax)
3474 if (pAdapter->StaCfg.AuthMode != AuthMode)
3476 // Config has changed
3477 pAdapter->bConfigChanged = TRUE;
3479 pAdapter->StaCfg.AuthMode = AuthMode;
3481 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
3482 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_AUTHENTICATION_MODE (=%d) \n",pAdapter->StaCfg.AuthMode));
3485 case OID_802_11_INFRASTRUCTURE_MODE:
3486 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_INFRASTRUCTURE))
3490 Status = copy_from_user(&BssType, wrq->u.data.pointer, wrq->u.data.length);
3492 if (BssType == Ndis802_11IBSS)
3493 Set_NetworkType_Proc(pAdapter, "Adhoc");
3494 else if (BssType == Ndis802_11Infrastructure)
3495 Set_NetworkType_Proc(pAdapter, "Infra");
3496 else if (BssType == Ndis802_11Monitor)
3497 Set_NetworkType_Proc(pAdapter, "Monitor");
3501 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_INFRASTRUCTURE_MODE (unknown)\n"));
3505 case OID_802_11_REMOVE_WEP:
3506 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_WEP\n"));
3507 if (wrq->u.data.length != sizeof(NDIS_802_11_KEY_INDEX))
3513 KeyIdx = *(NDIS_802_11_KEY_INDEX *) wrq->u.data.pointer;
3515 if (KeyIdx & 0x80000000)
3517 // Should never set default bit when remove key
3522 KeyIdx = KeyIdx & 0x0fffffff;
3528 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
3529 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
3530 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
3535 case RT_OID_802_11_RESET_COUNTERS:
3536 NdisZeroMemory(&pAdapter->WlanCounters, sizeof(COUNTER_802_11));
3537 NdisZeroMemory(&pAdapter->Counters8023, sizeof(COUNTER_802_3));
3538 NdisZeroMemory(&pAdapter->RalinkCounters, sizeof(COUNTER_RALINK));
3539 pAdapter->Counters8023.RxNoBuffer = 0;
3540 pAdapter->Counters8023.GoodReceives = 0;
3541 pAdapter->Counters8023.RxNoBuffer = 0;
3542 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RESET_COUNTERS \n"));
3544 case OID_802_11_RTS_THRESHOLD:
3545 if (wrq->u.data.length != sizeof(NDIS_802_11_RTS_THRESHOLD))
3549 Status = copy_from_user(&RtsThresh, wrq->u.data.pointer, wrq->u.data.length);
3550 if (RtsThresh > MAX_RTS_THRESHOLD)
3553 pAdapter->CommonCfg.RtsThreshold = (USHORT)RtsThresh;
3555 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_RTS_THRESHOLD (=%ld)\n",RtsThresh));
3557 case OID_802_11_FRAGMENTATION_THRESHOLD:
3558 if (wrq->u.data.length != sizeof(NDIS_802_11_FRAGMENTATION_THRESHOLD))
3562 Status = copy_from_user(&FragThresh, wrq->u.data.pointer, wrq->u.data.length);
3563 pAdapter->CommonCfg.bUseZeroToDisableFragment = FALSE;
3564 if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
3566 if (FragThresh == 0)
3568 pAdapter->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
3569 pAdapter->CommonCfg.bUseZeroToDisableFragment = TRUE;
3575 pAdapter->CommonCfg.FragmentThreshold = (USHORT)FragThresh;
3577 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_FRAGMENTATION_THRESHOLD (=%ld) \n",FragThresh));
3579 case OID_802_11_POWER_MODE:
3580 if (wrq->u.data.length != sizeof(NDIS_802_11_POWER_MODE))
3584 Status = copy_from_user(&PowerMode, wrq->u.data.pointer, wrq->u.data.length);
3585 if (PowerMode == Ndis802_11PowerModeCAM)
3586 Set_PSMode_Proc(pAdapter, "CAM");
3587 else if (PowerMode == Ndis802_11PowerModeMAX_PSP)
3588 Set_PSMode_Proc(pAdapter, "Max_PSP");
3589 else if (PowerMode == Ndis802_11PowerModeFast_PSP)
3590 Set_PSMode_Proc(pAdapter, "Fast_PSP");
3591 else if (PowerMode == Ndis802_11PowerModeLegacy_PSP)
3592 Set_PSMode_Proc(pAdapter, "Legacy_PSP");
3596 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_POWER_MODE (=%d)\n",PowerMode));
3598 case RT_OID_802_11_TX_POWER_LEVEL_1:
3599 if (wrq->u.data.length < sizeof(ULONG))
3603 Status = copy_from_user(&PowerTemp, wrq->u.data.pointer, wrq->u.data.length);
3604 if (PowerTemp > 100)
3605 PowerTemp = 0xffffffff; // AUTO
3606 pAdapter->CommonCfg.TxPowerDefault = PowerTemp; //keep current setting.
3607 pAdapter->CommonCfg.TxPowerPercentage = pAdapter->CommonCfg.TxPowerDefault;
3608 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
3611 case OID_802_11_NETWORK_TYPE_IN_USE:
3612 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_TYPE))
3616 Status = copy_from_user(&NetType, wrq->u.data.pointer, wrq->u.data.length);
3618 if (NetType == Ndis802_11DS)
3619 RTMPSetPhyMode(pAdapter, PHY_11B);
3620 else if (NetType == Ndis802_11OFDM24)
3621 RTMPSetPhyMode(pAdapter, PHY_11BG_MIXED);
3622 else if (NetType == Ndis802_11OFDM5)
3623 RTMPSetPhyMode(pAdapter, PHY_11A);
3626 #ifdef DOT11_N_SUPPORT
3627 if (Status == NDIS_STATUS_SUCCESS)
3628 SetCommonHT(pAdapter);
3629 #endif // DOT11_N_SUPPORT //
3630 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_NETWORK_TYPE_IN_USE (=%d)\n",NetType));
3633 // For WPA PSK PMK key
3634 case RT_OID_802_11_ADD_WPA:
3635 pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3642 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
3643 if (pKey->Length != wrq->u.data.length)
3646 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!!\n"));
3650 if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
3651 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
3652 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone) )
3654 Status = -EOPNOTSUPP;
3655 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!! [AuthMode != WPAPSK/WPA2PSK/WPANONE]\n"));
3657 else if ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
3658 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
3659 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) ) // Only for WPA PSK mode
3661 NdisMoveMemory(pAdapter->StaCfg.PMK, &pKey->KeyMaterial, pKey->KeyLength);
3662 // Use RaConfig as PSK agent.
3663 // Start STA supplicant state machine
3664 if (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
3665 pAdapter->StaCfg.WpaState = SS_START;
3667 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3671 pAdapter->StaCfg.WpaState = SS_NOTUSE;
3672 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3677 case OID_802_11_REMOVE_KEY:
3678 pRemoveKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3679 if(pRemoveKey == NULL)
3685 Status = copy_from_user(pRemoveKey, wrq->u.data.pointer, wrq->u.data.length);
3686 if (pRemoveKey->Length != wrq->u.data.length)
3689 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!\n"));
3693 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3695 RTMPWPARemoveKeyProc(pAdapter, pRemoveKey);
3696 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Remove WPA Key!!\n"));
3700 KeyIdx = pRemoveKey->KeyIndex;
3702 if (KeyIdx & 0x80000000)
3704 // Should never set default bit when remove key
3706 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(Should never set default bit when remove key)\n"));
3710 KeyIdx = KeyIdx & 0x0fffffff;
3714 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(KeyId[%d] out of range)\n", KeyIdx));
3718 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
3719 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
3720 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
3721 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY (id=0x%x, Len=%d-byte)\n", pRemoveKey->KeyIndex, pRemoveKey->Length));
3729 case OID_802_11_ADD_KEY:
3730 pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3736 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
3737 if (pKey->Length != wrq->u.data.length)
3740 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY, Failed!!\n"));
3744 RTMPAddKey(pAdapter, pKey);
3745 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3749 case OID_802_11_CONFIGURATION:
3750 if (wrq->u.data.length != sizeof(NDIS_802_11_CONFIGURATION))
3754 Status = copy_from_user(&Config, wrq->u.data.pointer, wrq->u.data.length);
3757 if ((pConfig->BeaconPeriod >= 20) && (pConfig->BeaconPeriod <=400))
3758 pAdapter->CommonCfg.BeaconPeriod = (USHORT) pConfig->BeaconPeriod;
3760 pAdapter->StaActive.AtimWin = (USHORT) pConfig->ATIMWindow;
3761 MAP_KHZ_TO_CHANNEL_ID(pConfig->DSConfig, pAdapter->CommonCfg.Channel);
3763 // Save the channel on MlmeAux for CntlOidRTBssidProc used.
3765 pAdapter->MlmeAux.Channel = pAdapter->CommonCfg.Channel;
3767 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_CONFIGURATION (BeacnPeriod=%ld,AtimW=%ld,Ch=%d)\n",
3768 pConfig->BeaconPeriod, pConfig->ATIMWindow, pAdapter->CommonCfg.Channel));
3769 // Config has changed
3770 pAdapter->bConfigChanged = TRUE;
3773 #ifdef DOT11_N_SUPPORT
3774 case RT_OID_802_11_SET_HT_PHYMODE:
3775 if (wrq->u.data.length != sizeof(OID_SET_HT_PHYMODE))
3779 POID_SET_HT_PHYMODE pHTPhyMode = &HT_PhyMode;
3781 Status = copy_from_user(&HT_PhyMode, wrq->u.data.pointer, wrq->u.data.length);
3782 DBGPRINT(RT_DEBUG_TRACE, ("Set::pHTPhyMode (PhyMode = %d,TransmitNo = %d, HtMode = %d, ExtOffset = %d , MCS = %d, BW = %d, STBC = %d, SHORTGI = %d) \n",
3783 pHTPhyMode->PhyMode, pHTPhyMode->TransmitNo,pHTPhyMode->HtMode,pHTPhyMode->ExtOffset,
3784 pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->SHORTGI));
3785 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
3786 RTMPSetHT(pAdapter, pHTPhyMode);
3788 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_HT_PHYMODE(MCS=%d,BW=%d,SGI=%d,STBC=%d)\n",
3789 pAdapter->StaCfg.HTPhyMode.field.MCS, pAdapter->StaCfg.HTPhyMode.field.BW, pAdapter->StaCfg.HTPhyMode.field.ShortGI,
3790 pAdapter->StaCfg.HTPhyMode.field.STBC));
3792 #endif // DOT11_N_SUPPORT //
3793 case RT_OID_802_11_SET_APSD_SETTING:
3794 if (wrq->u.data.length != sizeof(ULONG))
3799 Status = copy_from_user(&apsd, wrq->u.data.pointer, wrq->u.data.length);
3801 /*-------------------------------------------------------------------
3802 |B31~B7 | B6~B5 | B4 | B3 | B2 | B1 | B0 |
3803 ---------------------------------------------------------------------
3804 | Rsvd | Max SP Len | AC_VO | AC_VI | AC_BK | AC_BE | APSD Capable |
3805 ---------------------------------------------------------------------*/
3806 pAdapter->CommonCfg.bAPSDCapable = (apsd & 0x00000001) ? TRUE : FALSE;
3807 pAdapter->CommonCfg.bAPSDAC_BE = ((apsd & 0x00000002) >> 1) ? TRUE : FALSE;
3808 pAdapter->CommonCfg.bAPSDAC_BK = ((apsd & 0x00000004) >> 2) ? TRUE : FALSE;
3809 pAdapter->CommonCfg.bAPSDAC_VI = ((apsd & 0x00000008) >> 3) ? TRUE : FALSE;
3810 pAdapter->CommonCfg.bAPSDAC_VO = ((apsd & 0x00000010) >> 4) ? TRUE : FALSE;
3811 pAdapter->CommonCfg.MaxSPLength = (UCHAR)((apsd & 0x00000060) >> 5);
3813 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,
3814 pAdapter->CommonCfg.bAPSDAC_BE, pAdapter->CommonCfg.bAPSDAC_BK, pAdapter->CommonCfg.bAPSDAC_VI, pAdapter->CommonCfg.bAPSDAC_VO, pAdapter->CommonCfg.MaxSPLength));
3818 case RT_OID_802_11_SET_APSD_PSM:
3819 if (wrq->u.data.length != sizeof(ULONG))
3823 // Driver needs to notify AP when PSM changes
3824 Status = copy_from_user(&pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.pointer, wrq->u.data.length);
3825 if (pAdapter->CommonCfg.bAPSDForcePowerSave != pAdapter->StaCfg.Psm)
3827 MlmeSetPsmBit(pAdapter, pAdapter->CommonCfg.bAPSDForcePowerSave);
3828 RTMPSendNullFrame(pAdapter, pAdapter->CommonCfg.TxRate, TRUE);
3830 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_APSD_PSM (bAPSDForcePowerSave:%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
3834 case RT_OID_802_11_SET_WMM:
3835 if (wrq->u.data.length != sizeof(BOOLEAN))
3839 Status = copy_from_user(&pAdapter->CommonCfg.bWmmCapable, wrq->u.data.pointer, wrq->u.data.length);
3840 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_WMM (=%d) \n", pAdapter->CommonCfg.bWmmCapable));
3844 case OID_802_11_DISASSOCIATE:
3846 // Set NdisRadioStateOff to TRUE, instead of called MlmeRadioOff.
3847 // Later on, NDIS_802_11_BSSID_LIST_EX->NumberOfItems should be 0
3848 // when query OID_802_11_BSSID_LIST.
3850 // TRUE: NumberOfItems will set to 0.
3851 // FALSE: NumberOfItems no change.
3853 pAdapter->CommonCfg.NdisRadioStateOff = TRUE;
3854 // Set to immediately send the media disconnect event
3855 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
3856 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DISASSOCIATE \n"));
3858 if (INFRA_ON(pAdapter))
3860 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3862 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3863 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3866 MlmeEnqueue(pAdapter,
3867 MLME_CNTL_STATE_MACHINE,
3868 OID_802_11_DISASSOCIATE,
3872 StateMachineTouched = TRUE;
3876 #ifdef DOT11_N_SUPPORT
3877 case RT_OID_802_11_SET_IMME_BA_CAP:
3878 if (wrq->u.data.length != sizeof(OID_BACAP_STRUC))
3882 OID_BACAP_STRUC Orde ;
3883 Status = copy_from_user(&Orde, wrq->u.data.pointer, wrq->u.data.length);
3884 if (Orde.Policy > BA_NOTUSE)
3886 Status = NDIS_STATUS_INVALID_DATA;
3888 else if (Orde.Policy == BA_NOTUSE)
3890 pAdapter->CommonCfg.BACapability.field.Policy = BA_NOTUSE;
3891 pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
3892 pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
3893 pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
3894 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
3895 pAdapter->CommonCfg.DesiredHtPhy.MimoPs= Orde.MMPSmode;
3896 pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
3898 pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
3899 pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
3900 pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
3904 pAdapter->CommonCfg.BACapability.field.AutoBA = Orde.AutoBA;
3905 pAdapter->CommonCfg.BACapability.field.Policy = IMMED_BA; // we only support immediate BA.
3906 pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
3907 pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
3908 pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
3909 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
3910 pAdapter->CommonCfg.DesiredHtPhy.MimoPs = Orde.MMPSmode;
3911 pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
3914 pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
3915 pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
3916 pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
3918 if (pAdapter->CommonCfg.BACapability.field.RxBAWinLimit > MAX_RX_REORDERBUF)
3919 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = MAX_RX_REORDERBUF;
3923 pAdapter->CommonCfg.REGBACapability.word = pAdapter->CommonCfg.BACapability.word;
3924 DBGPRINT(RT_DEBUG_TRACE, ("Set::(Orde.AutoBA = %d) (Policy=%d)(ReBAWinLimit=%d)(TxBAWinLimit=%d)(AutoMode=%d)\n",Orde.AutoBA, pAdapter->CommonCfg.BACapability.field.Policy,
3925 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit,pAdapter->CommonCfg.BACapability.field.TxBAWinLimit, pAdapter->CommonCfg.BACapability.field.AutoBA));
3926 DBGPRINT(RT_DEBUG_TRACE, ("Set::(MimoPs = %d)(AmsduEnable = %d) (AmsduSize=%d)(MpduDensity=%d)\n",pAdapter->CommonCfg.DesiredHtPhy.MimoPs, pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable,
3927 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize, pAdapter->CommonCfg.DesiredHtPhy.MpduDensity));
3931 case RT_OID_802_11_ADD_IMME_BA:
3932 DBGPRINT(RT_DEBUG_TRACE, (" Set :: RT_OID_802_11_ADD_IMME_BA \n"));
3933 if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
3938 OID_ADD_BA_ENTRY BA;
3939 MAC_TABLE_ENTRY *pEntry;
3941 Status = copy_from_user(&BA, wrq->u.data.pointer, wrq->u.data.length);
3944 Status = NDIS_STATUS_INVALID_DATA;
3949 //BATableInsertEntry
3950 //As ad-hoc mode, BA pair is not limited to only BSSID. so add via OID.
3952 // in ad hoc mode, when adding BA pair, we should insert this entry into MACEntry too
3953 pEntry = MacTableLookup(pAdapter, BA.MACAddr);
3956 DBGPRINT(RT_DEBUG_TRACE, ("RT_OID_802_11_ADD_IMME_BA. break on no connection.----:%x:%x\n", BA.MACAddr[4], BA.MACAddr[5]));
3959 if (BA.IsRecipient == FALSE)
3961 if (pEntry->bIAmBadAtheros == TRUE)
3962 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = 0x10;
3964 BAOriSessionSetUp(pAdapter, pEntry, index, 0, 100, TRUE);
3968 //BATableInsertEntry(pAdapter, pEntry->Aid, BA.MACAddr, 0, 0xffff, BA.TID, BA.nMSDU, BA.IsRecipient);
3971 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_IMME_BA. Rec = %d. Mac = %x:%x:%x:%x:%x:%x . \n",
3972 BA.IsRecipient, BA.MACAddr[0], BA.MACAddr[1], BA.MACAddr[2], BA.MACAddr[2]
3973 , BA.MACAddr[4], BA.MACAddr[5]));
3978 case RT_OID_802_11_TEAR_IMME_BA:
3979 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA \n"));
3980 if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
3984 POID_ADD_BA_ENTRY pBA;
3985 MAC_TABLE_ENTRY *pEntry;
3987 pBA = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3991 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA kmalloc() can't allocate enough memory\n"));
3992 Status = NDIS_STATUS_FAILURE;
3996 Status = copy_from_user(pBA, wrq->u.data.pointer, wrq->u.data.length);
3997 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA(TID=%d, bAllTid=%d)\n", pBA->TID, pBA->bAllTid));
3999 if (!pBA->bAllTid && (pBA->TID > NUM_OF_TID))
4001 Status = NDIS_STATUS_INVALID_DATA;
4005 if (pBA->IsRecipient == FALSE)
4007 pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
4008 DBGPRINT(RT_DEBUG_TRACE, (" pBA->IsRecipient == FALSE\n"));
4011 DBGPRINT(RT_DEBUG_TRACE, (" pBA->pEntry\n"));
4012 BAOriSessionTearDown(pAdapter, pEntry->Aid, pBA->TID, FALSE, TRUE);
4015 DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
4019 pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
4022 BARecSessionTearDown( pAdapter, (UCHAR)pEntry->Aid, pBA->TID, TRUE);
4025 DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
4031 #endif // DOT11_N_SUPPORT //
4033 // For WPA_SUPPLICANT to set static wep key
4034 case OID_802_11_ADD_WEP:
4035 pWepKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4040 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed!!\n"));
4043 Status = copy_from_user(pWepKey, wrq->u.data.pointer, wrq->u.data.length);
4047 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (length mismatch)!!\n"));
4051 KeyIdx = pWepKey->KeyIndex & 0x0fffffff;
4052 // KeyIdx must be 0 ~ 3
4056 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (KeyIdx must be smaller than 4)!!\n"));
4060 UCHAR CipherAlg = 0;
4063 // set key material and key length
4064 NdisZeroMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, 16);
4065 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
4066 NdisMoveMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
4068 switch(pWepKey->KeyLength)
4071 CipherAlg = CIPHER_WEP64;
4074 CipherAlg = CIPHER_WEP128;
4077 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, only support CIPHER_WEP64(len:5) & CIPHER_WEP128(len:13)!!\n"));
4081 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CipherAlg;
4083 // Default key for tx (shared key)
4084 if (pWepKey->KeyIndex & 0x80000000)
4086 #ifdef WPA_SUPPLICANT_SUPPORT
4087 // set key material and key length
4088 NdisZeroMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, 16);
4089 pAdapter->StaCfg.DesireSharedKey[KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
4090 NdisMoveMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
4091 pAdapter->StaCfg.DesireSharedKeyId = KeyIdx;
4092 pAdapter->StaCfg.DesireSharedKey[KeyIdx].CipherAlg = CipherAlg;
4093 #endif // WPA_SUPPLICANT_SUPPORT //
4094 pAdapter->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
4097 #ifdef WPA_SUPPLICANT_SUPPORT
4098 if ((pAdapter->StaCfg.WpaSupplicantUP != 0) &&
4099 (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA))
4101 Key = pWepKey->KeyMaterial;
4103 // Set Group key material to Asic
4104 AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
4106 // Update WCID attribute table and IVEIV table for this group key table
4107 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
4109 STA_PORT_SECURED(pAdapter);
4111 // Indicate Connected for GUI
4112 pAdapter->IndicateMediaState = NdisMediaStateConnected;
4114 else if (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)
4115 #endif // WPA_SUPPLICANT_SUPPORT
4117 Key = pAdapter->SharedKey[BSS0][KeyIdx].Key;
4119 // Set key material and cipherAlg to Asic
4120 AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
4122 if (pWepKey->KeyIndex & 0x80000000)
4124 PMAC_TABLE_ENTRY pEntry = &pAdapter->MacTab.Content[BSSID_WCID];
4125 // Assign group key info
4126 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
4127 // Assign pairwise key info
4128 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, pEntry);
4131 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"));
4136 #ifdef WPA_SUPPLICANT_SUPPORT
4137 case OID_SET_COUNTERMEASURES:
4138 if (wrq->u.data.length != sizeof(int))
4143 Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
4145 pAdapter->StaCfg.bBlockAssoc = TRUE;
4147 // WPA MIC error should block association attempt for 60 seconds
4148 pAdapter->StaCfg.bBlockAssoc = FALSE;
4149 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_SET_COUNTERMEASURES bBlockAssoc=%s\n", pAdapter->StaCfg.bBlockAssoc ? "TRUE":"FALSE"));
4152 case RT_OID_WPA_SUPPLICANT_SUPPORT:
4153 if (wrq->u.data.length != sizeof(UCHAR))
4157 Status = copy_from_user(&wpa_supplicant_enable, wrq->u.data.pointer, wrq->u.data.length);
4158 pAdapter->StaCfg.WpaSupplicantUP = wpa_supplicant_enable;
4159 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
4162 case OID_802_11_DEAUTHENTICATION:
4163 if (wrq->u.data.length != sizeof(MLME_DEAUTH_REQ_STRUCT))
4167 MLME_DEAUTH_REQ_STRUCT *pInfo;
4168 MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
4170 pInfo = (MLME_DEAUTH_REQ_STRUCT *) MsgElem->Msg;
4171 Status = copy_from_user(pInfo, wrq->u.data.pointer, wrq->u.data.length);
4172 MlmeDeauthReqAction(pAdapter, MsgElem);
4175 if (INFRA_ON(pAdapter))
4177 LinkDown(pAdapter, FALSE);
4178 pAdapter->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
4180 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DEAUTHENTICATION (Reason=%d)\n", pInfo->Reason));
4183 case OID_802_11_DROP_UNENCRYPTED:
4184 if (wrq->u.data.length != sizeof(int))
4189 Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
4191 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
4193 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
4194 NdisAcquireSpinLock(&pAdapter->MacTabLock);
4195 pAdapter->MacTab.Content[BSSID_WCID].PortSecured = pAdapter->StaCfg.PortSecured;
4196 NdisReleaseSpinLock(&pAdapter->MacTabLock);
4197 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DROP_UNENCRYPTED (=%d)\n", enabled));
4200 case OID_802_11_SET_IEEE8021X:
4201 if (wrq->u.data.length != sizeof(BOOLEAN))
4205 Status = copy_from_user(&IEEE8021xState, wrq->u.data.pointer, wrq->u.data.length);
4206 pAdapter->StaCfg.IEEE8021X = IEEE8021xState;
4207 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X (=%d)\n", IEEE8021xState));
4210 case OID_802_11_SET_IEEE8021X_REQUIRE_KEY:
4211 if (wrq->u.data.length != sizeof(BOOLEAN))
4215 Status = copy_from_user(&IEEE8021x_required_keys, wrq->u.data.pointer, wrq->u.data.length);
4216 pAdapter->StaCfg.IEEE8021x_required_keys = IEEE8021x_required_keys;
4217 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X_REQUIRE_KEY (%d)\n", IEEE8021x_required_keys));
4220 case OID_802_11_PMKID:
4221 pPmkId = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4223 if(pPmkId == NULL) {
4227 Status = copy_from_user(pPmkId, wrq->u.data.pointer, wrq->u.data.length);
4229 // check the PMKID information
4230 if (pPmkId->BSSIDInfoCount == 0)
4231 NdisZeroMemory(pAdapter->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
4234 PBSSID_INFO pBssIdInfo;
4238 for (BssIdx = 0; BssIdx < pPmkId->BSSIDInfoCount; BssIdx++)
4240 // point to the indexed BSSID_INFO structure
4241 pBssIdInfo = (PBSSID_INFO) ((PUCHAR) pPmkId + 2 * sizeof(UINT) + BssIdx * sizeof(BSSID_INFO));
4242 // Find the entry in the saved data base.
4243 for (CachedIdx = 0; CachedIdx < pAdapter->StaCfg.SavedPMKNum; CachedIdx++)
4245 // compare the BSSID
4246 if (NdisEqualMemory(pBssIdInfo->BSSID, pAdapter->StaCfg.SavedPMK[CachedIdx].BSSID, sizeof(NDIS_802_11_MAC_ADDRESS)))
4250 // Found, replace it
4251 if (CachedIdx < PMKID_NO)
4253 DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
4254 NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
4255 pAdapter->StaCfg.SavedPMKNum++;
4257 // Not found, replace the last one
4260 // Randomly replace one
4261 CachedIdx = (pBssIdInfo->BSSID[5] % PMKID_NO);
4262 DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
4263 NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
4270 #endif // WPA_SUPPLICANT_SUPPORT //
4275 case OID_802_11_SHORTRETRYLIMIT:
4276 if (wrq->u.data.length != sizeof(ULONG))
4280 Status = copy_from_user(&ShortRetryLimit, wrq->u.data.pointer, wrq->u.data.length);
4281 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
4282 tx_rty_cfg.field.ShortRtyLimit = ShortRetryLimit;
4283 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
4284 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SHORTRETRYLIMIT (tx_rty_cfg.field.ShortRetryLimit=%d, ShortRetryLimit=%ld)\n", tx_rty_cfg.field.ShortRtyLimit, ShortRetryLimit));
4288 case OID_802_11_LONGRETRYLIMIT:
4289 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_LONGRETRYLIMIT \n"));
4290 if (wrq->u.data.length != sizeof(ULONG))
4294 Status = copy_from_user(&LongRetryLimit, wrq->u.data.pointer, wrq->u.data.length);
4295 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
4296 tx_rty_cfg.field.LongRtyLimit = LongRetryLimit;
4297 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
4298 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_LONGRETRYLIMIT (tx_rty_cfg.field.LongRetryLimit= %d,LongRetryLimit=%ld)\n", tx_rty_cfg.field.LongRtyLimit, LongRetryLimit));
4302 case OID_802_11_WEPDEFAULTKEYVALUE:
4303 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEPDEFAULTKEYVALUE\n"));
4304 pKey = kmalloc(wrq->u.data.length, GFP_KERNEL);
4305 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
4308 if ( pKey->Length != wrq->u.data.length)
4311 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEPDEFAULTKEYVALUE, Failed!!\n"));
4313 KeyIdx = pKey->KeyIndex & 0x0fffffff;
4314 DBGPRINT(RT_DEBUG_TRACE,("pKey->KeyIndex =%d, pKey->KeyLength=%d\n", pKey->KeyIndex, pKey->KeyLength));
4316 // it is a shared key
4321 pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen = (UCHAR) pKey->KeyLength;
4322 NdisMoveMemory(&pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key, &pKey->KeyMaterial, pKey->KeyLength);
4323 if (pKey->KeyIndex & 0x80000000)
4325 // Default key for tx (shared key)
4326 pAdapter->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
4328 //RestartAPIsRequired = TRUE;
4333 case OID_802_11_WEPDEFAULTKEYID:
4334 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEPDEFAULTKEYID \n"));
4336 if (wrq->u.data.length != sizeof(UCHAR))
4339 Status = copy_from_user(&pAdapter->StaCfg.DefaultKeyId, wrq->u.data.pointer, wrq->u.data.length);
4344 case OID_802_11_CURRENTCHANNEL:
4345 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_CURRENTCHANNEL \n"));
4346 if (wrq->u.data.length != sizeof(UCHAR))
4350 Status = copy_from_user(&ctmp, wrq->u.data.pointer, wrq->u.data.length);
4351 sprintf(&ctmp,"%d", ctmp);
4352 Set_Channel_Proc(pAdapter, &ctmp);
4360 DBGPRINT(RT_DEBUG_TRACE, ("Set::unknown IOCTL's subcmd = 0x%08x\n", cmd));
4361 Status = -EOPNOTSUPP;
4369 INT RTMPQueryInformation(
4370 IN PRTMP_ADAPTER pAdapter,
4371 IN OUT struct ifreq *rq,
4374 struct iwreq *wrq = (struct iwreq *) rq;
4375 NDIS_802_11_BSSID_LIST_EX *pBssidList = NULL;
4376 PNDIS_WLAN_BSSID_EX pBss;
4377 NDIS_802_11_SSID Ssid;
4378 NDIS_802_11_CONFIGURATION *pConfiguration = NULL;
4379 RT_802_11_LINK_STATUS *pLinkStatus = NULL;
4380 RT_802_11_STA_CONFIG *pStaConfig = NULL;
4381 NDIS_802_11_STATISTICS *pStatistics = NULL;
4382 NDIS_802_11_RTS_THRESHOLD RtsThresh;
4383 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
4384 NDIS_802_11_POWER_MODE PowerMode;
4385 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
4386 RT_802_11_PREAMBLE PreamType;
4387 NDIS_802_11_AUTHENTICATION_MODE AuthMode;
4388 NDIS_802_11_WEP_STATUS WepStatus;
4389 NDIS_MEDIA_STATE MediaState;
4390 ULONG BssBufSize, ulInfo=0, NetworkTypeList[4], apsd = 0;
4392 PUCHAR pBuf = NULL, pPtr;
4393 INT Status = NDIS_STATUS_SUCCESS;
4394 UINT we_version_compiled;
4395 UCHAR i, Padding = 0;
4397 UCHAR driverVersion[8];
4398 OID_SET_HT_PHYMODE *pHTPhyMode = NULL;
4403 DefaultKeyIdxValue *pKeyIdxValue;
4405 TX_RTY_CFG_STRUC tx_rty_cfg;
4406 ULONG ShortRetryLimit, LongRetryLimit;
4412 case RT_OID_DEVICE_NAME:
4413 wrq->u.data.length = sizeof(STA_NIC_DEVICE_NAME);
4414 Status = copy_to_user(wrq->u.data.pointer, STA_NIC_DEVICE_NAME, wrq->u.data.length);
4416 case RT_OID_VERSION_INFO:
4417 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_VERSION_INFO \n"));
4418 wrq->u.data.length = 8*sizeof(UCHAR);
4419 sprintf(&driverVersion[0], "%s", STA_DRIVER_VERSION);
4420 driverVersion[7] = '\0';
4421 if (copy_to_user(wrq->u.data.pointer, &driverVersion, wrq->u.data.length))
4426 case OID_802_11_BSSID_LIST:
4427 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
4430 * Still scanning, indicate the caller should try again.
4432 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (Still scanning)\n"));
4435 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (%d BSS returned)\n",pAdapter->ScanTab.BssNr));
4436 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
4437 // Claculate total buffer size required
4438 BssBufSize = sizeof(ULONG);
4440 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
4442 // Align pointer to 4 bytes boundary.
4443 //Padding = 4 - (pAdapter->ScanTab.BssEntry[i].VarIELen & 0x0003);
4446 BssBufSize += (sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
4449 // For safety issue, we add 256 bytes just in case
4451 // Allocate the same size as passed from higher layer
4452 pBuf = kmalloc(BssBufSize, MEM_ALLOC_FLAG);
4458 // Init 802_11_BSSID_LIST_EX structure
4459 NdisZeroMemory(pBuf, BssBufSize);
4460 pBssidList = (PNDIS_802_11_BSSID_LIST_EX) pBuf;
4461 pBssidList->NumberOfItems = pAdapter->ScanTab.BssNr;
4463 // Calculate total buffer length
4464 BssLen = 4; // Consist of NumberOfItems
4465 // Point to start of NDIS_WLAN_BSSID_EX
4466 // pPtr = pBuf + sizeof(ULONG);
4467 pPtr = (PUCHAR) &pBssidList->Bssid[0];
4468 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
4470 pBss = (PNDIS_WLAN_BSSID_EX) pPtr;
4471 NdisMoveMemory(&pBss->MacAddress, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
4472 if ((pAdapter->ScanTab.BssEntry[i].Hidden == 1) && (pAdapter->StaCfg.bShowHiddenSSID == FALSE))
4475 // We must return this SSID during 4way handshaking, otherwise Aegis will failed to parse WPA infomation
4476 // and then failed to send EAPOl farame.
4478 if ((pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) && (pAdapter->StaCfg.PortSecured != WPA_802_1X_PORT_SECURED))
4480 pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
4481 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
4484 pBss->Ssid.SsidLength = 0;
4488 pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
4489 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
4491 pBss->Privacy = pAdapter->ScanTab.BssEntry[i].Privacy;
4492 pBss->Rssi = pAdapter->ScanTab.BssEntry[i].Rssi - pAdapter->BbpRssiToDbmDelta;
4493 pBss->NetworkTypeInUse = NetworkTypeInUseSanity(&pAdapter->ScanTab.BssEntry[i]);
4494 pBss->Configuration.Length = sizeof(NDIS_802_11_CONFIGURATION);
4495 pBss->Configuration.BeaconPeriod = pAdapter->ScanTab.BssEntry[i].BeaconPeriod;
4496 pBss->Configuration.ATIMWindow = pAdapter->ScanTab.BssEntry[i].AtimWin;
4498 MAP_CHANNEL_ID_TO_KHZ(pAdapter->ScanTab.BssEntry[i].Channel, pBss->Configuration.DSConfig);
4500 if (pAdapter->ScanTab.BssEntry[i].BssType == BSS_INFRA)
4501 pBss->InfrastructureMode = Ndis802_11Infrastructure;
4503 pBss->InfrastructureMode = Ndis802_11IBSS;
4505 NdisMoveMemory(pBss->SupportedRates, pAdapter->ScanTab.BssEntry[i].SupRate, pAdapter->ScanTab.BssEntry[i].SupRateLen);
4506 NdisMoveMemory(pBss->SupportedRates + pAdapter->ScanTab.BssEntry[i].SupRateLen,
4507 pAdapter->ScanTab.BssEntry[i].ExtRate,
4508 pAdapter->ScanTab.BssEntry[i].ExtRateLen);
4510 if (pAdapter->ScanTab.BssEntry[i].VarIELen == 0)
4512 pBss->IELength = sizeof(NDIS_802_11_FIXED_IEs);
4513 NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
4514 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
4518 pBss->IELength = (ULONG)(sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen);
4519 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
4520 NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
4521 NdisMoveMemory(pBss->IEs + sizeof(NDIS_802_11_FIXED_IEs), pAdapter->ScanTab.BssEntry[i].VarIEs, pAdapter->ScanTab.BssEntry[i].VarIELen);
4522 pPtr += pAdapter->ScanTab.BssEntry[i].VarIELen;
4524 pBss->Length = (ULONG)(sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
4526 #if WIRELESS_EXT < 17
4527 if ((BssLen + pBss->Length) < wrq->u.data.length)
4528 BssLen += pBss->Length;
4531 pBssidList->NumberOfItems = i;
4535 BssLen += pBss->Length;
4539 #if WIRELESS_EXT < 17
4540 wrq->u.data.length = BssLen;
4542 if (BssLen > wrq->u.data.length)
4548 wrq->u.data.length = BssLen;
4550 Status = copy_to_user(wrq->u.data.pointer, pBssidList, BssLen);
4553 case OID_802_3_CURRENT_ADDRESS:
4554 wrq->u.data.length = MAC_ADDR_LEN;
4555 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
4557 case OID_GEN_MEDIA_CONNECT_STATUS:
4558 if (pAdapter->IndicateMediaState == NdisMediaStateConnected)
4559 MediaState = NdisMediaStateConnected;
4561 MediaState = NdisMediaStateDisconnected;
4563 wrq->u.data.length = sizeof(NDIS_MEDIA_STATE);
4564 Status = copy_to_user(wrq->u.data.pointer, &MediaState, wrq->u.data.length);
4566 case OID_802_11_BSSID:
4567 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
4569 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Bssid, sizeof(NDIS_802_11_MAC_ADDRESS));
4574 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID(=EMPTY)\n"));
4578 case OID_802_11_SSID:
4579 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
4580 NdisZeroMemory(Ssid.Ssid, MAX_LEN_OF_SSID);
4581 Ssid.SsidLength = pAdapter->CommonCfg.SsidLen;
4582 memcpy(Ssid.Ssid, pAdapter->CommonCfg.Ssid, Ssid.SsidLength);
4583 wrq->u.data.length = sizeof(NDIS_802_11_SSID);
4584 Status = copy_to_user(wrq->u.data.pointer, &Ssid, wrq->u.data.length);
4585 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_SSID (Len=%d, ssid=%s)\n", Ssid.SsidLength,Ssid.Ssid));
4587 case RT_OID_802_11_QUERY_LINK_STATUS:
4588 pLinkStatus = (RT_802_11_LINK_STATUS *) kmalloc(sizeof(RT_802_11_LINK_STATUS), MEM_ALLOC_FLAG);
4591 pLinkStatus->CurrTxRate = RateIdTo500Kbps[pAdapter->CommonCfg.TxRate]; // unit : 500 kbps
4592 pLinkStatus->ChannelQuality = pAdapter->Mlme.ChannelQuality;
4593 pLinkStatus->RxByteCount = pAdapter->RalinkCounters.ReceivedByteCount;
4594 pLinkStatus->TxByteCount = pAdapter->RalinkCounters.TransmittedByteCount;
4595 pLinkStatus->CentralChannel = pAdapter->CommonCfg.CentralChannel;
4596 wrq->u.data.length = sizeof(RT_802_11_LINK_STATUS);
4597 Status = copy_to_user(wrq->u.data.pointer, pLinkStatus, wrq->u.data.length);
4599 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS\n"));
4603 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS(kmalloc failed)\n"));
4607 case OID_802_11_CONFIGURATION:
4608 pConfiguration = (NDIS_802_11_CONFIGURATION *) kmalloc(sizeof(NDIS_802_11_CONFIGURATION), MEM_ALLOC_FLAG);
4611 pConfiguration->Length = sizeof(NDIS_802_11_CONFIGURATION);
4612 pConfiguration->BeaconPeriod = pAdapter->CommonCfg.BeaconPeriod;
4613 pConfiguration->ATIMWindow = pAdapter->StaActive.AtimWin;
4614 MAP_CHANNEL_ID_TO_KHZ(pAdapter->CommonCfg.Channel, pConfiguration->DSConfig);
4615 wrq->u.data.length = sizeof(NDIS_802_11_CONFIGURATION);
4616 Status = copy_to_user(wrq->u.data.pointer, pConfiguration, wrq->u.data.length);
4617 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(BeaconPeriod=%ld,AtimW=%ld,Channel=%d) \n",
4618 pConfiguration->BeaconPeriod, pConfiguration->ATIMWindow, pAdapter->CommonCfg.Channel));
4619 kfree(pConfiguration);
4623 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(kmalloc failed)\n"));
4627 case RT_OID_802_11_SNR_0:
4628 if ((pAdapter->StaCfg.LastSNR0 > 0))
4630 ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR0) * 3) / 16 ;
4631 wrq->u.data.length = sizeof(ulInfo);
4632 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4633 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_SNR_0(0x=%lx)\n", ulInfo));
4638 case RT_OID_802_11_SNR_1:
4639 if ((pAdapter->Antenna.field.RxPath > 1) &&
4640 (pAdapter->StaCfg.LastSNR1 > 0))
4642 ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR1) * 3) / 16 ;
4643 wrq->u.data.length = sizeof(ulInfo);
4644 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4645 DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(0x=%lx)\n",ulInfo));
4649 DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(pAdapter->StaCfg.LastSNR1=%d)\n",pAdapter->StaCfg.LastSNR1));
4651 case OID_802_11_RSSI_TRIGGER:
4652 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0 - pAdapter->BbpRssiToDbmDelta;
4653 wrq->u.data.length = sizeof(ulInfo);
4654 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4655 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RSSI_TRIGGER(=%ld)\n", ulInfo));
4657 case OID_802_11_RSSI:
4658 case RT_OID_802_11_RSSI:
4659 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0;
4660 wrq->u.data.length = sizeof(ulInfo);
4661 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4663 case RT_OID_802_11_RSSI_1:
4664 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi1;
4665 wrq->u.data.length = sizeof(ulInfo);
4666 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4668 case RT_OID_802_11_RSSI_2:
4669 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi2;
4670 wrq->u.data.length = sizeof(ulInfo);
4671 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4673 case OID_802_11_STATISTICS:
4674 pStatistics = (NDIS_802_11_STATISTICS *) kmalloc(sizeof(NDIS_802_11_STATISTICS), MEM_ALLOC_FLAG);
4677 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS \n"));
4678 // add the most up-to-date h/w raw counters into software counters
4679 NICUpdateRawCounters(pAdapter);
4681 // Sanity check for calculation of sucessful count
4682 if (pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart < pAdapter->WlanCounters.RetryCount.QuadPart)
4683 pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
4685 pStatistics->TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart;
4686 pStatistics->MulticastTransmittedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastTransmittedFrameCount.QuadPart;
4687 pStatistics->FailedCount.QuadPart = pAdapter->WlanCounters.FailedCount.QuadPart;
4688 pStatistics->RetryCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
4689 pStatistics->MultipleRetryCount.QuadPart = pAdapter->WlanCounters.MultipleRetryCount.QuadPart;
4690 pStatistics->RTSSuccessCount.QuadPart = pAdapter->WlanCounters.RTSSuccessCount.QuadPart;
4691 pStatistics->RTSFailureCount.QuadPart = pAdapter->WlanCounters.RTSFailureCount.QuadPart;
4692 pStatistics->ACKFailureCount.QuadPart = pAdapter->WlanCounters.ACKFailureCount.QuadPart;
4693 pStatistics->FrameDuplicateCount.QuadPart = pAdapter->WlanCounters.FrameDuplicateCount.QuadPart;
4694 pStatistics->ReceivedFragmentCount.QuadPart = pAdapter->WlanCounters.ReceivedFragmentCount.QuadPart;
4695 pStatistics->MulticastReceivedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastReceivedFrameCount.QuadPart;
4697 pStatistics->FCSErrorCount = pAdapter->RalinkCounters.RealFcsErrCount;
4699 pStatistics->FCSErrorCount.QuadPart = pAdapter->WlanCounters.FCSErrorCount.QuadPart;
4700 pStatistics->FrameDuplicateCount.u.LowPart = pAdapter->WlanCounters.FrameDuplicateCount.u.LowPart / 100;
4702 wrq->u.data.length = sizeof(NDIS_802_11_STATISTICS);
4703 Status = copy_to_user(wrq->u.data.pointer, pStatistics, wrq->u.data.length);
4708 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS(kmalloc failed)\n"));
4712 case OID_GEN_RCV_OK:
4713 ulInfo = pAdapter->Counters8023.GoodReceives;
4714 wrq->u.data.length = sizeof(ulInfo);
4715 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4717 case OID_GEN_RCV_NO_BUFFER:
4718 ulInfo = pAdapter->Counters8023.RxNoBuffer;
4719 wrq->u.data.length = sizeof(ulInfo);
4720 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4722 case RT_OID_802_11_PHY_MODE:
4723 ulInfo = (ULONG)pAdapter->CommonCfg.PhyMode;
4724 wrq->u.data.length = sizeof(ulInfo);
4725 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4726 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PHY_MODE (=%ld)\n", ulInfo));
4728 case RT_OID_802_11_STA_CONFIG:
4729 pStaConfig = (RT_802_11_STA_CONFIG *) kmalloc(sizeof(RT_802_11_STA_CONFIG), MEM_ALLOC_FLAG);
4732 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG\n"));
4733 pStaConfig->EnableTxBurst = pAdapter->CommonCfg.bEnableTxBurst;
4734 pStaConfig->EnableTurboRate = 0;
4735 pStaConfig->UseBGProtection = pAdapter->CommonCfg.UseBGProtection;
4736 pStaConfig->UseShortSlotTime = pAdapter->CommonCfg.bUseShortSlotTime;
4737 //pStaConfig->AdhocMode = pAdapter->StaCfg.AdhocMode;
4738 pStaConfig->HwRadioStatus = (pAdapter->StaCfg.bHwRadio == TRUE) ? 1 : 0;
4739 pStaConfig->Rsv1 = 0;
4740 pStaConfig->SystemErrorBitmap = pAdapter->SystemErrorBitmap;
4741 wrq->u.data.length = sizeof(RT_802_11_STA_CONFIG);
4742 Status = copy_to_user(wrq->u.data.pointer, pStaConfig, wrq->u.data.length);
4747 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
4751 case OID_802_11_RTS_THRESHOLD:
4752 RtsThresh = pAdapter->CommonCfg.RtsThreshold;
4753 wrq->u.data.length = sizeof(RtsThresh);
4754 Status = copy_to_user(wrq->u.data.pointer, &RtsThresh, wrq->u.data.length);
4755 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RTS_THRESHOLD(=%ld)\n", RtsThresh));
4757 case OID_802_11_FRAGMENTATION_THRESHOLD:
4758 FragThresh = pAdapter->CommonCfg.FragmentThreshold;
4759 if (pAdapter->CommonCfg.bUseZeroToDisableFragment == TRUE)
4761 wrq->u.data.length = sizeof(FragThresh);
4762 Status = copy_to_user(wrq->u.data.pointer, &FragThresh, wrq->u.data.length);
4763 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_FRAGMENTATION_THRESHOLD(=%ld)\n", FragThresh));
4765 case OID_802_11_POWER_MODE:
4766 PowerMode = pAdapter->StaCfg.WindowsPowerMode;
4767 wrq->u.data.length = sizeof(PowerMode);
4768 Status = copy_to_user(wrq->u.data.pointer, &PowerMode, wrq->u.data.length);
4769 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_POWER_MODE(=%d)\n", PowerMode));
4771 case RT_OID_802_11_RADIO:
4772 RadioState = (BOOLEAN) pAdapter->StaCfg.bSwRadio;
4773 wrq->u.data.length = sizeof(RadioState);
4774 Status = copy_to_user(wrq->u.data.pointer, &RadioState, wrq->u.data.length);
4775 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_RADIO (=%d)\n", RadioState));
4777 case OID_802_11_INFRASTRUCTURE_MODE:
4778 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
4779 BssType = Ndis802_11IBSS;
4780 else if (pAdapter->StaCfg.BssType == BSS_INFRA)
4781 BssType = Ndis802_11Infrastructure;
4782 else if (pAdapter->StaCfg.BssType == BSS_MONITOR)
4783 BssType = Ndis802_11Monitor;
4785 BssType = Ndis802_11AutoUnknown;
4787 wrq->u.data.length = sizeof(BssType);
4788 Status = copy_to_user(wrq->u.data.pointer, &BssType, wrq->u.data.length);
4789 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_INFRASTRUCTURE_MODE(=%d)\n", BssType));
4791 case RT_OID_802_11_PREAMBLE:
4792 PreamType = pAdapter->CommonCfg.TxPreamble;
4793 wrq->u.data.length = sizeof(PreamType);
4794 Status = copy_to_user(wrq->u.data.pointer, &PreamType, wrq->u.data.length);
4795 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PREAMBLE(=%d)\n", PreamType));
4797 case OID_802_11_AUTHENTICATION_MODE:
4798 AuthMode = pAdapter->StaCfg.AuthMode;
4799 wrq->u.data.length = sizeof(AuthMode);
4800 Status = copy_to_user(wrq->u.data.pointer, &AuthMode, wrq->u.data.length);
4801 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_AUTHENTICATION_MODE(=%d)\n", AuthMode));
4803 case OID_802_11_WEP_STATUS:
4804 WepStatus = pAdapter->StaCfg.WepStatus;
4805 wrq->u.data.length = sizeof(WepStatus);
4806 Status = copy_to_user(wrq->u.data.pointer, &WepStatus, wrq->u.data.length);
4807 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_WEP_STATUS(=%d)\n", WepStatus));
4809 case OID_802_11_TX_POWER_LEVEL:
4810 wrq->u.data.length = sizeof(ULONG);
4811 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPower, wrq->u.data.length);
4812 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_TX_POWER_LEVEL %x\n",pAdapter->CommonCfg.TxPower));
4814 case RT_OID_802_11_TX_POWER_LEVEL_1:
4815 wrq->u.data.length = sizeof(ULONG);
4816 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPowerPercentage, wrq->u.data.length);
4817 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
4819 case OID_802_11_NETWORK_TYPES_SUPPORTED:
4820 if ((pAdapter->RfIcType == RFIC_2850) || (pAdapter->RfIcType == RFIC_2750))
4822 NetworkTypeList[0] = 3; // NumberOfItems = 3
4823 NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
4824 NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
4825 NetworkTypeList[3] = Ndis802_11OFDM5; // NetworkType[3] = 11a
4826 wrq->u.data.length = 16;
4827 Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
4831 NetworkTypeList[0] = 2; // NumberOfItems = 2
4832 NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
4833 NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
4834 wrq->u.data.length = 12;
4835 Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
4837 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_NETWORK_TYPES_SUPPORTED\n"));
4839 case OID_802_11_NETWORK_TYPE_IN_USE:
4840 wrq->u.data.length = sizeof(ULONG);
4841 if (pAdapter->CommonCfg.PhyMode == PHY_11A)
4842 ulInfo = Ndis802_11OFDM5;
4843 else if ((pAdapter->CommonCfg.PhyMode == PHY_11BG_MIXED) || (pAdapter->CommonCfg.PhyMode == PHY_11G))
4844 ulInfo = Ndis802_11OFDM24;
4846 ulInfo = Ndis802_11DS;
4847 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4849 case RT_OID_802_11_QUERY_LAST_RX_RATE:
4850 ulInfo = (ULONG)pAdapter->LastRxRate;
4851 wrq->u.data.length = sizeof(ulInfo);
4852 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4853 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_RX_RATE (=%ld)\n", ulInfo));
4855 case RT_OID_802_11_QUERY_LAST_TX_RATE:
4856 //ulInfo = (ULONG)pAdapter->LastTxRate;
4857 ulInfo = (ULONG)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word;
4858 wrq->u.data.length = sizeof(ulInfo);
4859 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4860 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_TX_RATE (=%lx)\n", ulInfo));
4862 case RT_OID_802_11_QUERY_EEPROM_VERSION:
4863 wrq->u.data.length = sizeof(ULONG);
4864 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->EepromVersion, wrq->u.data.length);
4866 case RT_OID_802_11_QUERY_FIRMWARE_VERSION:
4867 wrq->u.data.length = sizeof(ULONG);
4868 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->FirmwareVersion, wrq->u.data.length);
4870 case RT_OID_802_11_QUERY_NOISE_LEVEL:
4871 wrq->u.data.length = sizeof(UCHAR);
4872 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->BbpWriteLatch[66], wrq->u.data.length);
4873 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_NOISE_LEVEL (=%d)\n", pAdapter->BbpWriteLatch[66]));
4875 case RT_OID_802_11_EXTRA_INFO:
4876 wrq->u.data.length = sizeof(ULONG);
4877 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->ExtraInfo, wrq->u.data.length);
4878 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_EXTRA_INFO (=%ld)\n", pAdapter->ExtraInfo));
4880 case RT_OID_WE_VERSION_COMPILED:
4881 wrq->u.data.length = sizeof(UINT);
4882 we_version_compiled = WIRELESS_EXT;
4883 Status = copy_to_user(wrq->u.data.pointer, &we_version_compiled, wrq->u.data.length);
4885 case RT_OID_802_11_QUERY_APSD_SETTING:
4886 apsd = (pAdapter->CommonCfg.bAPSDCapable | (pAdapter->CommonCfg.bAPSDAC_BE << 1) | (pAdapter->CommonCfg.bAPSDAC_BK << 2)
4887 | (pAdapter->CommonCfg.bAPSDAC_VI << 3) | (pAdapter->CommonCfg.bAPSDAC_VO << 4) | (pAdapter->CommonCfg.MaxSPLength << 5));
4889 wrq->u.data.length = sizeof(ULONG);
4890 Status = copy_to_user(wrq->u.data.pointer, &apsd, wrq->u.data.length);
4891 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",
4892 apsd,pAdapter->CommonCfg.bAPSDCapable,pAdapter->CommonCfg.bAPSDAC_BE,pAdapter->CommonCfg.bAPSDAC_BK,pAdapter->CommonCfg.bAPSDAC_VI,pAdapter->CommonCfg.bAPSDAC_VO,pAdapter->CommonCfg.MaxSPLength));
4894 case RT_OID_802_11_QUERY_APSD_PSM:
4895 wrq->u.data.length = sizeof(ULONG);
4896 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.length);
4897 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_APSD_PSM (=%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
4899 case RT_OID_802_11_QUERY_WMM:
4900 wrq->u.data.length = sizeof(BOOLEAN);
4901 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bWmmCapable, wrq->u.data.length);
4902 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_WMM (=%d)\n", pAdapter->CommonCfg.bWmmCapable));
4904 #ifdef WPA_SUPPLICANT_SUPPORT
4905 case RT_OID_NEW_DRIVER:
4908 wrq->u.data.length = sizeof(UCHAR);
4909 Status = copy_to_user(wrq->u.data.pointer, &enabled, wrq->u.data.length);
4910 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_NEW_DRIVER (=%d)\n", enabled));
4913 case RT_OID_WPA_SUPPLICANT_SUPPORT:
4914 wrq->u.data.length = sizeof(UCHAR);
4915 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->StaCfg.WpaSupplicantUP, wrq->u.data.length);
4916 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
4918 #endif // WPA_SUPPLICANT_SUPPORT //
4920 case RT_OID_DRIVER_DEVICE_NAME:
4921 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_DRIVER_DEVICE_NAME \n"));
4922 wrq->u.data.length = 16;
4923 if (copy_to_user(wrq->u.data.pointer, pAdapter->StaCfg.dev_name, wrq->u.data.length))
4928 case RT_OID_802_11_QUERY_HT_PHYMODE:
4929 pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
4932 pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
4933 pHTPhyMode->HtMode = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE;
4934 pHTPhyMode->BW = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.BW;
4935 pHTPhyMode->MCS= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MCS;
4936 pHTPhyMode->SHORTGI= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.ShortGI;
4937 pHTPhyMode->STBC= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.STBC;
4939 pHTPhyMode->ExtOffset = ((pAdapter->CommonCfg.CentralChannel < pAdapter->CommonCfg.Channel) ? (EXTCHA_BELOW) : (EXTCHA_ABOVE));
4940 wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
4941 if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
4945 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
4946 pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
4947 DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
4951 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
4955 case RT_OID_802_11_COUNTRY_REGION:
4956 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_COUNTRY_REGION \n"));
4957 wrq->u.data.length = sizeof(ulInfo);
4958 ulInfo = pAdapter->CommonCfg.CountryRegionForABand;
4959 ulInfo = (ulInfo << 8)|(pAdapter->CommonCfg.CountryRegion);
4960 if (copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length))
4965 case RT_OID_802_11_QUERY_DAT_HT_PHYMODE:
4966 pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
4969 pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
4970 pHTPhyMode->HtMode = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.HTMODE;
4971 pHTPhyMode->BW = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.BW;
4972 pHTPhyMode->MCS= (UCHAR)pAdapter->StaCfg.DesiredTransmitSetting.field.MCS;
4973 pHTPhyMode->SHORTGI= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.ShortGI;
4974 pHTPhyMode->STBC= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.STBC;
4976 wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
4977 if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
4981 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
4982 pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
4983 DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
4987 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
4991 case RT_OID_QUERY_MULTIPLE_CARD_SUPPORT:
4992 wrq->u.data.length = sizeof(UCHAR);
4994 if (copy_to_user(wrq->u.data.pointer, &i, wrq->u.data.length))
4998 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_QUERY_MULTIPLE_CARD_SUPPORT(=%d) \n", i));
5001 case RT_OID_802_11_MAC_ADDRESS:
5002 wrq->u.data.length = MAC_ADDR_LEN;
5003 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
5006 case RT_OID_802_11_MANUFACTUREROUI:
5007 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_MANUFACTUREROUI \n"));
5008 wrq->u.data.length = ManufacturerOUI_LEN;
5009 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
5012 case RT_OID_802_11_MANUFACTURERNAME:
5013 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_MANUFACTURERNAME \n"));
5014 wrq->u.data.length = strlen(ManufacturerNAME);
5015 Status = copy_to_user(wrq->u.data.pointer, ManufacturerNAME, wrq->u.data.length);
5018 case RT_OID_802_11_RESOURCETYPEIDNAME:
5019 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_RESOURCETYPEIDNAME \n"));
5020 wrq->u.data.length = strlen(ResourceTypeIdName);
5021 Status = copy_to_user(wrq->u.data.pointer, ResourceTypeIdName, wrq->u.data.length);
5024 case RT_OID_802_11_PRIVACYOPTIONIMPLEMENTED:
5025 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PRIVACYOPTIONIMPLEMENTED \n"));
5026 ulInfo = 1; // 1 is support wep else 2 is not support.
5027 wrq->u.data.length = sizeof(ulInfo);
5028 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
5031 case RT_OID_802_11_POWERMANAGEMENTMODE:
5032 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_POWERMANAGEMENTMODE \n"));
5033 if (pAdapter->StaCfg.Psm == PSMP_ACTION)
5034 ulInfo = 1; // 1 is power active else 2 is power save.
5038 wrq->u.data.length = sizeof(ulInfo);
5039 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
5042 case OID_802_11_WEPDEFAULTKEYVALUE:
5043 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_WEPDEFAULTKEYVALUE \n"));
5044 //KeyIdxValue.KeyIdx = pAd->PortCfg.MBSSID[pAd->IoctlIF].DefaultKeyId;
5045 pKeyIdxValue = wrq->u.data.pointer;
5046 DBGPRINT(RT_DEBUG_TRACE,("KeyIdxValue.KeyIdx = %d, \n",pKeyIdxValue->KeyIdx));
5047 valueLen = pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen;
5048 NdisMoveMemory(pKeyIdxValue->Value,
5049 &pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key,
5051 pKeyIdxValue->Value[valueLen]='\0';
5053 wrq->u.data.length = sizeof(DefaultKeyIdxValue);
5055 Status = copy_to_user(wrq->u.data.pointer, pKeyIdxValue, wrq->u.data.length);
5056 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,
5057 pAdapter->SharedKey[BSS0][0].Key[0],
5058 pAdapter->SharedKey[BSS0][1].Key[0],
5059 pAdapter->SharedKey[BSS0][2].Key[0],
5060 pAdapter->SharedKey[BSS0][3].Key[0]));
5063 case OID_802_11_WEPDEFAULTKEYID:
5064 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_WEPDEFAULTKEYID \n"));
5065 wrq->u.data.length = sizeof(UCHAR);
5066 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->StaCfg.DefaultKeyId, wrq->u.data.length);
5067 DBGPRINT(RT_DEBUG_TRACE, ("DefaultKeyId =%d \n", pAdapter->StaCfg.DefaultKeyId));
5070 case RT_OID_802_11_WEPKEYMAPPINGLENGTH:
5071 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_WEPKEYMAPPINGLENGTH \n"));
5072 wrq->u.data.length = sizeof(UCHAR);
5073 Status = copy_to_user(wrq->u.data.pointer,
5074 &pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen,
5075 wrq->u.data.length);
5078 case OID_802_11_SHORTRETRYLIMIT:
5079 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_SHORTRETRYLIMIT \n"));
5080 wrq->u.data.length = sizeof(ULONG);
5081 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
5082 ShortRetryLimit = tx_rty_cfg.field.ShortRtyLimit;
5083 DBGPRINT(RT_DEBUG_TRACE, ("ShortRetryLimit =%ld, tx_rty_cfg.field.ShortRetryLimit=%d\n", ShortRetryLimit, tx_rty_cfg.field.ShortRtyLimit));
5084 Status = copy_to_user(wrq->u.data.pointer, &ShortRetryLimit, wrq->u.data.length);
5087 case OID_802_11_LONGRETRYLIMIT:
5088 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_LONGRETRYLIMIT \n"));
5089 wrq->u.data.length = sizeof(ULONG);
5090 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
5091 LongRetryLimit = tx_rty_cfg.field.LongRtyLimit;
5092 DBGPRINT(RT_DEBUG_TRACE, ("LongRetryLimit =%ld, tx_rty_cfg.field.LongRtyLimit=%d\n", LongRetryLimit, tx_rty_cfg.field.LongRtyLimit));
5093 Status = copy_to_user(wrq->u.data.pointer, &LongRetryLimit, wrq->u.data.length);
5096 case RT_OID_802_11_PRODUCTID:
5097 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PRODUCTID \n"));
5102 if (((POS_COOKIE)pAdapter->OS_Cookie)->pci_dev != NULL)
5103 pci_read_config_word(((POS_COOKIE)pAdapter->OS_Cookie)->pci_dev, PCI_DEVICE_ID, &device_id);
5105 DBGPRINT(RT_DEBUG_TRACE, (" pci_dev = NULL\n"));
5106 sprintf(tmp, "%04x %04x\n", NIC_PCI_VENDOR_ID, device_id);
5108 wrq->u.data.length = strlen(tmp);
5109 Status = copy_to_user(wrq->u.data.pointer, tmp, wrq->u.data.length);
5112 case RT_OID_802_11_MANUFACTUREID:
5113 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_MANUFACTUREID \n"));
5114 wrq->u.data.length = strlen(ManufacturerNAME);
5115 Status = copy_to_user(wrq->u.data.pointer, ManufacturerNAME, wrq->u.data.length);
5118 case OID_802_11_CURRENTCHANNEL:
5119 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CURRENTCHANNEL \n"));
5120 wrq->u.data.length = sizeof(UCHAR);
5121 DBGPRINT(RT_DEBUG_TRACE, ("sizeof UCHAR=%d, channel=%d \n", sizeof(UCHAR), pAdapter->CommonCfg.Channel));
5122 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Channel, wrq->u.data.length);
5123 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5125 #endif //SNMP_SUPPORT
5127 case OID_802_11_BUILD_CHANNEL_EX:
5130 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BUILD_CHANNEL_EX \n"));
5131 wrq->u.data.length = sizeof(UCHAR);
5132 DBGPRINT(RT_DEBUG_TRACE, ("Doesn't support EXT_BUILD_CHANNEL_LIST.\n"));
5134 Status = copy_to_user(wrq->u.data.pointer, &value, 1);
5135 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5139 case OID_802_11_GET_CH_LIST:
5141 PRT_CHANNEL_LIST_INFO pChListBuf;
5143 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CH_LIST \n"));
5144 if (pAdapter->ChannelListNum == 0)
5146 wrq->u.data.length = 0;
5150 pChListBuf = (RT_CHANNEL_LIST_INFO *) kmalloc(sizeof(RT_CHANNEL_LIST_INFO), MEM_ALLOC_FLAG);
5151 if (pChListBuf == NULL)
5153 wrq->u.data.length = 0;
5157 pChListBuf->ChannelListNum = pAdapter->ChannelListNum;
5158 for (i = 0; i < pChListBuf->ChannelListNum; i++)
5159 pChListBuf->ChannelList[i] = pAdapter->ChannelList[i].Channel;
5161 wrq->u.data.length = sizeof(RT_CHANNEL_LIST_INFO);
5162 Status = copy_to_user(wrq->u.data.pointer, pChListBuf, sizeof(RT_CHANNEL_LIST_INFO));
5163 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5170 case OID_802_11_GET_COUNTRY_CODE:
5171 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_COUNTRY_CODE \n"));
5172 wrq->u.data.length = 2;
5173 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.CountryCode, 2);
5174 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5177 case OID_802_11_GET_CHANNEL_GEOGRAPHY:
5178 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CHANNEL_GEOGRAPHY \n"));
5179 wrq->u.data.length = 1;
5180 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Geography, 1);
5181 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5185 DBGPRINT(RT_DEBUG_TRACE, ("Query::unknown IOCTL's subcmd = 0x%08x\n", cmd));
5186 Status = -EOPNOTSUPP;
5192 INT rt28xx_sta_ioctl(
5193 IN struct net_device *net_dev,
5194 IN OUT struct ifreq *rq,
5198 VIRTUAL_ADAPTER *pVirtualAd = NULL;
5199 RTMP_ADAPTER *pAd = NULL;
5200 struct iwreq *wrq = (struct iwreq *) rq;
5201 BOOLEAN StateMachineTouched = FALSE;
5202 INT Status = NDIS_STATUS_SUCCESS;
5205 if (net_dev->priv_flags == INT_MAIN)
5207 pAd = net_dev->ml_priv;
5211 pVirtualAd = net_dev->ml_priv;
5212 pAd = pVirtualAd->RtmpDev->ml_priv;
5214 pObj = (POS_COOKIE) pAd->OS_Cookie;
5218 /* if 1st open fail, pAd will be free;
5219 So the net_dev->ml_priv will be NULL in 2rd open */
5223 //check if the interface is down
5224 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
5227 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
5232 { // determine this ioctl command is comming from which interface.
5233 pObj->ioctl_if_type = INT_MAIN;
5234 pObj->ioctl_if = MAIN_MBSSID;
5240 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIFHWADDR\n"));
5241 memcpy(wrq->u.name, pAd->CurrentAddress, ETH_ALEN);
5245 char *name=&wrq->u.name[0];
5246 rt_ioctl_giwname(net_dev, NULL, name, NULL);
5249 case SIOCGIWESSID: //Get ESSID
5251 struct iw_point *essid=&wrq->u.essid;
5252 rt_ioctl_giwessid(net_dev, NULL, essid, essid->pointer);
5255 case SIOCSIWESSID: //Set ESSID
5257 struct iw_point *essid=&wrq->u.essid;
5258 rt_ioctl_siwessid(net_dev, NULL, essid, essid->pointer);
5261 case SIOCSIWNWID: // set network id (the cell)
5262 case SIOCGIWNWID: // get network id
5263 Status = -EOPNOTSUPP;
5265 case SIOCSIWFREQ: //set channel/frequency (Hz)
5267 struct iw_freq *freq=&wrq->u.freq;
5268 rt_ioctl_siwfreq(net_dev, NULL, freq, NULL);
5271 case SIOCGIWFREQ: // get channel/frequency (Hz)
5273 struct iw_freq *freq=&wrq->u.freq;
5274 rt_ioctl_giwfreq(net_dev, NULL, freq, NULL);
5277 case SIOCSIWNICKN: //set node name/nickname
5279 struct iw_point *data=&wrq->u.data;
5280 rt_ioctl_siwnickn(net_dev, NULL, data, NULL);
5283 case SIOCGIWNICKN: //get node name/nickname
5285 struct iw_point *data=&wrq->u.data;
5286 rt_ioctl_giwnickn(net_dev, NULL, data, NULL);
5289 case SIOCGIWRATE: //get default bit rate (bps)
5290 rt_ioctl_giwrate(net_dev, NULL, &wrq->u, NULL);
5292 case SIOCSIWRATE: //set default bit rate (bps)
5293 rt_ioctl_siwrate(net_dev, NULL, &wrq->u, NULL);
5295 case SIOCGIWRTS: // get RTS/CTS threshold (bytes)
5297 struct iw_param *rts=&wrq->u.rts;
5298 rt_ioctl_giwrts(net_dev, NULL, rts, NULL);
5301 case SIOCSIWRTS: //set RTS/CTS threshold (bytes)
5303 struct iw_param *rts=&wrq->u.rts;
5304 rt_ioctl_siwrts(net_dev, NULL, rts, NULL);
5307 case SIOCGIWFRAG: //get fragmentation thr (bytes)
5309 struct iw_param *frag=&wrq->u.frag;
5310 rt_ioctl_giwfrag(net_dev, NULL, frag, NULL);
5313 case SIOCSIWFRAG: //set fragmentation thr (bytes)
5315 struct iw_param *frag=&wrq->u.frag;
5316 rt_ioctl_siwfrag(net_dev, NULL, frag, NULL);
5319 case SIOCGIWENCODE: //get encoding token & mode
5321 struct iw_point *erq=&wrq->u.encoding;
5323 rt_ioctl_giwencode(net_dev, NULL, erq, erq->pointer);
5326 case SIOCSIWENCODE: //set encoding token & mode
5328 struct iw_point *erq=&wrq->u.encoding;
5330 rt_ioctl_siwencode(net_dev, NULL, erq, erq->pointer);
5333 case SIOCGIWAP: //get access point MAC addresses
5335 struct sockaddr *ap_addr=&wrq->u.ap_addr;
5336 rt_ioctl_giwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
5339 case SIOCSIWAP: //set access point MAC addresses
5341 struct sockaddr *ap_addr=&wrq->u.ap_addr;
5342 rt_ioctl_siwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
5345 case SIOCGIWMODE: //get operation mode
5347 __u32 *mode=&wrq->u.mode;
5348 rt_ioctl_giwmode(net_dev, NULL, mode, NULL);
5351 case SIOCSIWMODE: //set operation mode
5353 __u32 *mode=&wrq->u.mode;
5354 rt_ioctl_siwmode(net_dev, NULL, mode, NULL);
5357 case SIOCGIWSENS: //get sensitivity (dBm)
5358 case SIOCSIWSENS: //set sensitivity (dBm)
5359 case SIOCGIWPOWER: //get Power Management settings
5360 case SIOCSIWPOWER: //set Power Management settings
5361 case SIOCGIWTXPOW: //get transmit power (dBm)
5362 case SIOCSIWTXPOW: //set transmit power (dBm)
5363 case SIOCGIWRANGE: //Get range of parameters
5364 case SIOCGIWRETRY: //get retry limits and lifetime
5365 case SIOCSIWRETRY: //set retry limits and lifetime
5366 Status = -EOPNOTSUPP;
5369 subcmd = wrq->u.data.flags;
5370 if( subcmd & OID_GET_SET_TOGGLE)
5371 Status = RTMPSetInformation(pAd, rq, subcmd);
5373 Status = RTMPQueryInformation(pAd, rq, subcmd);
5376 if (wrq->u.data.pointer)
5378 if ( access_ok(VERIFY_WRITE, wrq->u.data.pointer, sizeof(privtab)) != TRUE)
5380 wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
5381 if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
5385 case RTPRIV_IOCTL_SET:
5386 if(access_ok(VERIFY_READ, wrq->u.data.pointer, wrq->u.data.length) != TRUE)
5388 rt_ioctl_setparam(net_dev, NULL, NULL, wrq->u.data.pointer);
5390 case RTPRIV_IOCTL_GSITESURVEY:
5391 RTMPIoctlGetSiteSurvey(pAd, wrq);
5394 case RTPRIV_IOCTL_MAC:
5395 RTMPIoctlMAC(pAd, wrq);
5397 case RTPRIV_IOCTL_E2P:
5398 RTMPIoctlE2PROM(pAd, wrq);
5404 DBGPRINT(RT_DEBUG_ERROR, ("IOCTL::unknown IOCTL's cmd = 0x%08x\n", cmd));
5405 Status = -EOPNOTSUPP;
5409 if(StateMachineTouched) // Upper layer sent a MLME-related operations
5410 RT28XX_MLME_HANDLER(pAd);
5416 ==========================================================================
5420 TRUE if all parameters are OK, FALSE otherwise
5421 ==========================================================================
5424 IN PRTMP_ADAPTER pAdapter,
5427 NDIS_802_11_SSID Ssid, *pSsid=NULL;
5428 BOOLEAN StateMachineTouched = FALSE;
5431 if( strlen(arg) <= MAX_LEN_OF_SSID)
5433 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
5434 if (strlen(arg) != 0)
5436 NdisMoveMemory(Ssid.Ssid, arg, strlen(arg));
5437 Ssid.SsidLength = strlen(arg);
5441 Ssid.SsidLength = 0;
5442 memcpy(Ssid.Ssid, "", 0);
5443 pAdapter->StaCfg.BssType = BSS_INFRA;
5444 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
5445 pAdapter->StaCfg.WepStatus = Ndis802_11EncryptionDisabled;
5449 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
5451 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
5452 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
5455 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
5456 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
5457 pAdapter->bConfigChanged = TRUE;
5459 MlmeEnqueue(pAdapter,
5460 MLME_CNTL_STATE_MACHINE,
5462 sizeof(NDIS_802_11_SSID),
5465 StateMachineTouched = TRUE;
5466 DBGPRINT(RT_DEBUG_TRACE, ("Set_SSID_Proc::(Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
5471 if (StateMachineTouched) // Upper layer sent a MLME-related operations
5472 RT28XX_MLME_HANDLER(pAdapter);
5479 ==========================================================================
5481 Set WmmCapable Enable or Disable
5483 TRUE if all parameters are OK, FALSE otherwise
5484 ==========================================================================
5486 INT Set_WmmCapable_Proc(
5487 IN PRTMP_ADAPTER pAd,
5490 BOOLEAN bWmmCapable;
5492 bWmmCapable = simple_strtol(arg, 0, 10);
5494 if ((bWmmCapable == 1)
5496 pAd->CommonCfg.bWmmCapable = TRUE;
5497 else if (bWmmCapable == 0)
5498 pAd->CommonCfg.bWmmCapable = FALSE;
5500 return FALSE; //Invalid argument
5502 DBGPRINT(RT_DEBUG_TRACE, ("Set_WmmCapable_Proc::(bWmmCapable=%d)\n",
5503 pAd->CommonCfg.bWmmCapable));
5507 #endif // WMM_SUPPORT //
5510 ==========================================================================
5512 Set Network Type(Infrastructure/Adhoc mode)
5514 TRUE if all parameters are OK, FALSE otherwise
5515 ==========================================================================
5517 INT Set_NetworkType_Proc(
5518 IN PRTMP_ADAPTER pAdapter,
5523 if (strcmp(arg, "Adhoc") == 0)
5525 if (pAdapter->StaCfg.BssType != BSS_ADHOC)
5527 // Config has changed
5528 pAdapter->bConfigChanged = TRUE;
5529 if (MONITOR_ON(pAdapter))
5531 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
5532 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5534 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5535 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5536 pAdapter->StaCfg.bAutoReconnect = TRUE;
5537 LinkDown(pAdapter, FALSE);
5539 if (INFRA_ON(pAdapter))
5541 //BOOLEAN Cancelled;
5542 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
5543 // Since calling this indicate user don't want to connect to that SSID anymore.
5544 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
5545 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
5547 LinkDown(pAdapter, FALSE);
5549 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n"));
5552 pAdapter->StaCfg.BssType = BSS_ADHOC;
5553 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
5554 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(AD-HOC)\n"));
5556 else if (strcmp(arg, "Infra") == 0)
5558 if (pAdapter->StaCfg.BssType != BSS_INFRA)
5560 // Config has changed
5561 pAdapter->bConfigChanged = TRUE;
5562 if (MONITOR_ON(pAdapter))
5564 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
5565 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5567 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5568 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5569 pAdapter->StaCfg.bAutoReconnect = TRUE;
5570 LinkDown(pAdapter, FALSE);
5572 if (ADHOC_ON(pAdapter))
5574 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
5575 // Since calling this indicate user don't want to connect to that SSID anymore.
5576 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
5577 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
5579 LinkDown(pAdapter, FALSE);
5582 pAdapter->StaCfg.BssType = BSS_INFRA;
5583 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
5584 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(INFRA)\n"));
5586 pAdapter->StaCfg.BssType = BSS_INFRA;
5588 else if (strcmp(arg, "Monitor") == 0)
5591 BCN_TIME_CFG_STRUC csr;
5592 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_INFRA_ON);
5593 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_ADHOC_ON);
5594 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5595 // disable all periodic state machine
5596 pAdapter->StaCfg.bAutoReconnect = FALSE;
5597 // reset all mlme state machine
5598 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
5599 DBGPRINT(RT_DEBUG_TRACE, ("fOP_STATUS_MEDIA_STATE_CONNECTED \n"));
5600 if (pAdapter->CommonCfg.CentralChannel == 0)
5602 #ifdef DOT11_N_SUPPORT
5603 if (pAdapter->CommonCfg.PhyMode == PHY_11AN_MIXED)
5604 pAdapter->CommonCfg.CentralChannel = 36;
5606 #endif // DOT11_N_SUPPORT //
5607 pAdapter->CommonCfg.CentralChannel = 6;
5609 #ifdef DOT11_N_SUPPORT
5611 N_ChannelCheck(pAdapter);
5612 #endif // DOT11_N_SUPPORT //
5614 #ifdef DOT11_N_SUPPORT
5615 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
5616 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
5617 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_ABOVE)
5619 // 40MHz ,control channel at lower
5620 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5621 bbpValue &= (~0x18);
5623 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5624 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
5625 // RX : control channel at lower
5626 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
5627 bbpValue &= (~0x20);
5628 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
5630 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
5631 Value &= 0xfffffffe;
5632 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
5633 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel + 2;
5634 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
5635 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
5636 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
5637 pAdapter->CommonCfg.Channel,
5638 pAdapter->CommonCfg.CentralChannel));
5640 else if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
5641 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
5642 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_BELOW)
5644 // 40MHz ,control channel at upper
5645 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5646 bbpValue &= (~0x18);
5648 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5649 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
5650 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
5652 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
5654 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
5656 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
5657 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel - 2;
5658 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
5659 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
5660 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
5661 pAdapter->CommonCfg.Channel,
5662 pAdapter->CommonCfg.CentralChannel));
5665 #endif // DOT11_N_SUPPORT //
5668 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5669 bbpValue &= (~0x18);
5670 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5671 pAdapter->CommonCfg.BBPCurrentBW = BW_20;
5672 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.Channel, FALSE);
5673 AsicLockChannel(pAdapter, pAdapter->CommonCfg.Channel);
5674 DBGPRINT(RT_DEBUG_TRACE, ("BW_20, Channel(%d)\n", pAdapter->CommonCfg.Channel));
5676 // Enable Rx with promiscuous reception
5677 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, 0x3);
5678 // ASIC supporsts sniffer function with replacing RSSI with timestamp.
5679 //RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5681 //RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5683 RTMP_IO_READ32(pAdapter, BCN_TIME_CFG, &csr.word);
5684 csr.field.bBeaconGen = 0;
5685 csr.field.bTBTTEnable = 0;
5686 csr.field.TsfSyncMode = 0;
5687 RTMP_IO_WRITE32(pAdapter, BCN_TIME_CFG, csr.word);
5689 pAdapter->StaCfg.BssType = BSS_MONITOR;
5690 pAdapter->net_dev->type = ARPHRD_IEEE80211_PRISM; //ARPHRD_IEEE80211; // IEEE80211
5691 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(MONITOR)\n"));
5694 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
5695 pAdapter->StaCfg.WpaState = SS_NOTUSE;
5697 DBGPRINT(RT_DEBUG_TRACE, ("Set_NetworkType_Proc::(NetworkType=%d)\n", pAdapter->StaCfg.BssType));
5703 ==========================================================================
5705 Set Authentication mode
5707 TRUE if all parameters are OK, FALSE otherwise
5708 ==========================================================================
5710 INT Set_AuthMode_Proc(
5711 IN PRTMP_ADAPTER pAdapter,
5714 if ((strcmp(arg, "WEPAUTO") == 0) || (strcmp(arg, "wepauto") == 0))
5715 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeAutoSwitch;
5716 else if ((strcmp(arg, "OPEN") == 0) || (strcmp(arg, "open") == 0))
5717 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
5718 else if ((strcmp(arg, "SHARED") == 0) || (strcmp(arg, "shared") == 0))
5719 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
5720 else if ((strcmp(arg, "WPAPSK") == 0) || (strcmp(arg, "wpapsk") == 0))
5721 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
5722 else if ((strcmp(arg, "WPANONE") == 0) || (strcmp(arg, "wpanone") == 0))
5723 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
5724 else if ((strcmp(arg, "WPA2PSK") == 0) || (strcmp(arg, "wpa2psk") == 0))
5725 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
5726 #ifdef WPA_SUPPLICANT_SUPPORT
5727 else if ((strcmp(arg, "WPA") == 0) || (strcmp(arg, "wpa") == 0))
5728 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
5729 else if ((strcmp(arg, "WPA2") == 0) || (strcmp(arg, "wpa2") == 0))
5730 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
5731 #endif // WPA_SUPPLICANT_SUPPORT //
5735 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
5737 DBGPRINT(RT_DEBUG_TRACE, ("Set_AuthMode_Proc::(AuthMode=%d)\n", pAdapter->StaCfg.AuthMode));
5743 ==========================================================================
5747 TRUE if all parameters are OK, FALSE otherwise
5748 ==========================================================================
5750 INT Set_EncrypType_Proc(
5751 IN PRTMP_ADAPTER pAdapter,
5754 if ((strcmp(arg, "NONE") == 0) || (strcmp(arg, "none") == 0))
5756 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5757 return TRUE; // do nothing
5759 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
5760 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
5761 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
5763 else if ((strcmp(arg, "WEP") == 0) || (strcmp(arg, "wep") == 0))
5765 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5766 return TRUE; // do nothing
5768 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
5769 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
5770 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
5772 else if ((strcmp(arg, "TKIP") == 0) || (strcmp(arg, "tkip") == 0))
5774 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
5775 return TRUE; // do nothing
5777 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
5778 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
5779 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
5781 else if ((strcmp(arg, "AES") == 0) || (strcmp(arg, "aes") == 0))
5783 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
5784 return TRUE; // do nothing
5786 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
5787 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
5788 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
5793 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
5795 DBGPRINT(RT_DEBUG_TRACE, ("Set_EncrypType_Proc::(EncrypType=%d)\n", pAdapter->StaCfg.WepStatus));
5801 ==========================================================================
5805 TRUE if all parameters are OK, FALSE otherwise
5806 ==========================================================================
5808 INT Set_DefaultKeyID_Proc(
5809 IN PRTMP_ADAPTER pAdapter,
5814 KeyIdx = simple_strtol(arg, 0, 10);
5815 if((KeyIdx >= 1 ) && (KeyIdx <= 4))
5816 pAdapter->StaCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1 );
5818 return FALSE; //Invalid argument
5820 DBGPRINT(RT_DEBUG_TRACE, ("Set_DefaultKeyID_Proc::(DefaultKeyID=%d)\n", pAdapter->StaCfg.DefaultKeyId));
5826 ==========================================================================
5830 TRUE if all parameters are OK, FALSE otherwise
5831 ==========================================================================
5834 IN PRTMP_ADAPTER pAdapter,
5839 UCHAR CipherAlg=CIPHER_WEP64;
5841 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5842 return TRUE; // do nothing
5844 KeyLen = strlen(arg);
5848 case 5: //wep 40 Ascii type
5849 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
5850 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
5851 CipherAlg = CIPHER_WEP64;
5852 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
5854 case 10: //wep 40 Hex type
5855 for(i=0; i < KeyLen; i++)
5857 if( !isxdigit(*(arg+i)) )
5858 return FALSE; //Not Hex value;
5860 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
5861 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
5862 CipherAlg = CIPHER_WEP64;
5863 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
5865 case 13: //wep 104 Ascii type
5866 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
5867 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
5868 CipherAlg = CIPHER_WEP128;
5869 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
5871 case 26: //wep 104 Hex type
5872 for(i=0; i < KeyLen; i++)
5874 if( !isxdigit(*(arg+i)) )
5875 return FALSE; //Not Hex value;
5877 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
5878 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
5879 CipherAlg = CIPHER_WEP128;
5880 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
5882 default: //Invalid argument
5883 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::Invalid argument (=%s)\n", arg));
5887 pAdapter->SharedKey[BSS0][0].CipherAlg = CipherAlg;
5889 // Set keys (into ASIC)
5890 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5892 else // Old WEP stuff
5894 AsicAddSharedKeyEntry(pAdapter,
5897 pAdapter->SharedKey[BSS0][0].CipherAlg,
5898 pAdapter->SharedKey[BSS0][0].Key,
5906 ==========================================================================
5911 TRUE if all parameters are OK, FALSE otherwise
5912 ==========================================================================
5915 IN PRTMP_ADAPTER pAdapter,
5920 UCHAR CipherAlg=CIPHER_WEP64;
5922 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5923 return TRUE; // do nothing
5925 KeyLen = strlen(arg);
5929 case 5: //wep 40 Ascii type
5930 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
5931 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
5932 CipherAlg = CIPHER_WEP64;
5933 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
5935 case 10: //wep 40 Hex type
5936 for(i=0; i < KeyLen; i++)
5938 if( !isxdigit(*(arg+i)) )
5939 return FALSE; //Not Hex value;
5941 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
5942 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
5943 CipherAlg = CIPHER_WEP64;
5944 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
5946 case 13: //wep 104 Ascii type
5947 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
5948 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
5949 CipherAlg = CIPHER_WEP128;
5950 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
5952 case 26: //wep 104 Hex type
5953 for(i=0; i < KeyLen; i++)
5955 if( !isxdigit(*(arg+i)) )
5956 return FALSE; //Not Hex value;
5958 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
5959 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
5960 CipherAlg = CIPHER_WEP128;
5961 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
5963 default: //Invalid argument
5964 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::Invalid argument (=%s)\n", arg));
5967 pAdapter->SharedKey[BSS0][1].CipherAlg = CipherAlg;
5969 // Set keys (into ASIC)
5970 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5972 else // Old WEP stuff
5974 AsicAddSharedKeyEntry(pAdapter,
5977 pAdapter->SharedKey[BSS0][1].CipherAlg,
5978 pAdapter->SharedKey[BSS0][1].Key,
5986 ==========================================================================
5990 TRUE if all parameters are OK, FALSE otherwise
5991 ==========================================================================
5994 IN PRTMP_ADAPTER pAdapter,
5999 UCHAR CipherAlg=CIPHER_WEP64;
6001 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6002 return TRUE; // do nothing
6004 KeyLen = strlen(arg);
6008 case 5: //wep 40 Ascii type
6009 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
6010 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
6011 CipherAlg = CIPHER_WEP64;
6012 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
6014 case 10: //wep 40 Hex type
6015 for(i=0; i < KeyLen; i++)
6017 if( !isxdigit(*(arg+i)) )
6018 return FALSE; //Not Hex value;
6020 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
6021 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
6022 CipherAlg = CIPHER_WEP64;
6023 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
6025 case 13: //wep 104 Ascii type
6026 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
6027 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
6028 CipherAlg = CIPHER_WEP128;
6029 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
6031 case 26: //wep 104 Hex type
6032 for(i=0; i < KeyLen; i++)
6034 if( !isxdigit(*(arg+i)) )
6035 return FALSE; //Not Hex value;
6037 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
6038 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
6039 CipherAlg = CIPHER_WEP128;
6040 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
6042 default: //Invalid argument
6043 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::Invalid argument (=%s)\n", arg));
6046 pAdapter->SharedKey[BSS0][2].CipherAlg = CipherAlg;
6048 // Set keys (into ASIC)
6049 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6051 else // Old WEP stuff
6053 AsicAddSharedKeyEntry(pAdapter,
6056 pAdapter->SharedKey[BSS0][2].CipherAlg,
6057 pAdapter->SharedKey[BSS0][2].Key,
6065 ==========================================================================
6069 TRUE if all parameters are OK, FALSE otherwise
6070 ==========================================================================
6073 IN PRTMP_ADAPTER pAdapter,
6078 UCHAR CipherAlg=CIPHER_WEP64;
6080 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6081 return TRUE; // do nothing
6083 KeyLen = strlen(arg);
6087 case 5: //wep 40 Ascii type
6088 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
6089 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
6090 CipherAlg = CIPHER_WEP64;
6091 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
6093 case 10: //wep 40 Hex type
6094 for(i=0; i < KeyLen; i++)
6096 if( !isxdigit(*(arg+i)) )
6097 return FALSE; //Not Hex value;
6099 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
6100 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
6101 CipherAlg = CIPHER_WEP64;
6102 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
6104 case 13: //wep 104 Ascii type
6105 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
6106 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
6107 CipherAlg = CIPHER_WEP128;
6108 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
6110 case 26: //wep 104 Hex type
6111 for(i=0; i < KeyLen; i++)
6113 if( !isxdigit(*(arg+i)) )
6114 return FALSE; //Not Hex value;
6116 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
6117 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
6118 CipherAlg = CIPHER_WEP128;
6119 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
6121 default: //Invalid argument
6122 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::Invalid argument (=%s)\n", arg));
6125 pAdapter->SharedKey[BSS0][3].CipherAlg = CipherAlg;
6127 // Set keys (into ASIC)
6128 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6130 else // Old WEP stuff
6132 AsicAddSharedKeyEntry(pAdapter,
6135 pAdapter->SharedKey[BSS0][3].CipherAlg,
6136 pAdapter->SharedKey[BSS0][3].Key,
6145 ==========================================================================
6149 TRUE if all parameters are OK, FALSE otherwise
6150 ==========================================================================
6152 INT Set_WPAPSK_Proc(
6153 IN PRTMP_ADAPTER pAdapter,
6156 UCHAR keyMaterial[40];
6158 if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
6159 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
6160 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
6162 return TRUE; // do nothing
6164 DBGPRINT(RT_DEBUG_TRACE, ("Set_WPAPSK_Proc::(WPAPSK=%s)\n", arg));
6166 NdisZeroMemory(keyMaterial, 40);
6168 if ((strlen(arg) < 8) || (strlen(arg) > 64))
6170 DBGPRINT(RT_DEBUG_TRACE, ("Set failed!!(WPAPSK=%s), WPAPSK key-string required 8 ~ 64 characters \n", arg));
6174 if (strlen(arg) == 64)
6176 AtoH(arg, keyMaterial, 32);
6177 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
6182 PasswordHash((char *)arg, pAdapter->MlmeAux.Ssid, pAdapter->MlmeAux.SsidLen, keyMaterial);
6183 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
6188 if(pAdapter->StaCfg.BssType == BSS_ADHOC &&
6189 pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
6191 pAdapter->StaCfg.WpaState = SS_NOTUSE;
6195 // Start STA supplicant state machine
6196 pAdapter->StaCfg.WpaState = SS_START;
6203 ==========================================================================
6205 Set Power Saving mode
6207 TRUE if all parameters are OK, FALSE otherwise
6208 ==========================================================================
6210 INT Set_PSMode_Proc(
6211 IN PRTMP_ADAPTER pAdapter,
6214 if (pAdapter->StaCfg.BssType == BSS_INFRA)
6216 if ((strcmp(arg, "Max_PSP") == 0) ||
6217 (strcmp(arg, "max_psp") == 0) ||
6218 (strcmp(arg, "MAX_PSP") == 0))
6220 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6221 // to exclude certain situations.
6222 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6223 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeMAX_PSP;
6224 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeMAX_PSP;
6225 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6226 pAdapter->StaCfg.DefaultListenCount = 5;
6229 else if ((strcmp(arg, "Fast_PSP") == 0) ||
6230 (strcmp(arg, "fast_psp") == 0) ||
6231 (strcmp(arg, "FAST_PSP") == 0))
6233 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6234 // to exclude certain situations.
6235 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6236 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6237 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeFast_PSP;
6238 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeFast_PSP;
6239 pAdapter->StaCfg.DefaultListenCount = 3;
6241 else if ((strcmp(arg, "Legacy_PSP") == 0) ||
6242 (strcmp(arg, "legacy_psp") == 0) ||
6243 (strcmp(arg, "LEGACY_PSP") == 0))
6245 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6246 // to exclude certain situations.
6247 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6248 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6249 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeLegacy_PSP;
6250 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeLegacy_PSP;
6251 pAdapter->StaCfg.DefaultListenCount = 3;
6255 //Default Ndis802_11PowerModeCAM
6256 // clear PSM bit immediately
6257 MlmeSetPsmBit(pAdapter, PWR_ACTIVE);
6258 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6259 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6260 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
6261 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
6264 DBGPRINT(RT_DEBUG_TRACE, ("Set_PSMode_Proc::(PSMode=%ld)\n", pAdapter->StaCfg.WindowsPowerMode));
6273 #ifdef WPA_SUPPLICANT_SUPPORT
6275 ==========================================================================
6277 Set WpaSupport flag.
6279 0: Driver ignore wpa_supplicant.
6280 1: wpa_supplicant initiates scanning and AP selection.
6281 2: driver takes care of scanning, AP selection, and IEEE 802.11 association parameters.
6283 TRUE if all parameters are OK, FALSE otherwise
6284 ==========================================================================
6286 INT Set_Wpa_Support(
6287 IN PRTMP_ADAPTER pAd,
6291 if ( simple_strtol(arg, 0, 10) == 0)
6292 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
6293 else if ( simple_strtol(arg, 0, 10) == 1)
6294 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE;
6295 else if ( simple_strtol(arg, 0, 10) == 2)
6296 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE_WITH_WEB_UI;
6298 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
6300 DBGPRINT(RT_DEBUG_TRACE, ("Set_Wpa_Support::(WpaSupplicantUP=%d)\n", pAd->StaCfg.WpaSupplicantUP));
6304 #endif // WPA_SUPPLICANT_SUPPORT //
6308 ==========================================================================
6312 pAdapter Pointer to our adapter
6313 wrq Pointer to the ioctl argument
6320 1.) iwpriv ra0 mac 0 ==> read MAC where Addr=0x0
6321 2.) iwpriv ra0 mac 0=12 ==> write MAC where Addr=0x0, value=12
6322 ==========================================================================
6325 IN PRTMP_ADAPTER pAdapter,
6326 IN struct iwreq *wrq)
6334 UCHAR temp[16], temp2[16];
6335 UINT32 macValue = 0;
6339 memset(msg, 0x00, 1024);
6340 if (wrq->u.data.length > 1) //No parameters.
6342 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6345 //Parsing Read or Write
6350 if ((value = rtstrchr(this_char, '=')) != NULL)
6353 if (!value || !*value)
6356 if(strlen(this_char) > 4)
6359 j = strlen(this_char);
6362 if(this_char[j] > 'f' || this_char[j] < '0')
6367 k = j = strlen(this_char);
6370 this_char[4-k+j] = this_char[j];
6374 this_char[3-k++]='0';
6377 if(strlen(this_char) == 4)
6379 AtoH(this_char, temp, 2);
6380 macAddr = *temp*256 + temp[1];
6381 if (macAddr < 0xFFFF)
6383 RTMP_IO_READ32(pAdapter, macAddr, &macValue);
6384 DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%lx, MacValue=%x\n", macAddr, macValue));
6385 sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr , macValue);
6388 {//Invalid parametes, so default printk all bbp
6395 memcpy(&temp2, value, strlen(value));
6396 temp2[strlen(value)] = '\0';
6399 if((strlen(this_char) > 4) || strlen(temp2) > 8)
6402 j = strlen(this_char);
6405 if(this_char[j] > 'f' || this_char[j] < '0')
6412 if(temp2[j] > 'f' || temp2[j] < '0')
6417 k = j = strlen(this_char);
6420 this_char[4-k+j] = this_char[j];
6424 this_char[3-k++]='0';
6428 k = j = strlen(temp2);
6431 temp2[8-k+j] = temp2[j];
6439 AtoH(this_char, temp, 2);
6440 macAddr = *temp*256 + temp[1];
6442 AtoH(temp2, temp, 4);
6443 macValue = *temp*256*256*256 + temp[1]*256*256 + temp[2]*256 + temp[3];
6446 if (macAddr == (HW_DEBUG_SETTING_BASE + 4))
6448 // 0x2bf4: byte0 non-zero: enable R17 tuning, 0: disable R17 tuning
6449 if (macValue & 0x000000ff)
6451 pAdapter->BbpTuning.bEnable = TRUE;
6452 DBGPRINT(RT_DEBUG_TRACE,("turn on R17 tuning\n"));
6457 pAdapter->BbpTuning.bEnable = FALSE;
6458 R66 = 0x26 + GET_LNA_GAIN(pAdapter);
6459 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R66, (0x26 + GET_LNA_GAIN(pAdapter)));
6460 DBGPRINT(RT_DEBUG_TRACE,("turn off R17 tuning, restore to 0x%02x\n", R66));
6465 DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%02lx, MacValue=0x%x\n", macAddr, macValue));
6467 RTMP_IO_WRITE32(pAdapter, macAddr, macValue);
6468 sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr, macValue);
6473 if(strlen(msg) == 1)
6474 sprintf(msg+strlen(msg), "===>Error command format!");
6476 // Copy the information into the user buffer
6477 wrq->u.data.length = strlen(msg);
6478 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6480 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlMAC\n\n"));
6484 ==========================================================================
6488 pAdapter Pointer to our adapter
6489 wrq Pointer to the ioctl argument
6496 1.) iwpriv ra0 e2p 0 ==> read E2PROM where Addr=0x0
6497 2.) iwpriv ra0 e2p 0=1234 ==> write E2PROM where Addr=0x0, value=1234
6498 ==========================================================================
6500 VOID RTMPIoctlE2PROM(
6501 IN PRTMP_ADAPTER pAdapter,
6502 IN struct iwreq *wrq)
6510 UCHAR temp[16], temp2[16];
6515 memset(msg, 0x00, 1024);
6516 if (wrq->u.data.length > 1) //No parameters.
6518 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6521 //Parsing Read or Write
6528 if ((value = rtstrchr(this_char, '=')) != NULL)
6531 if (!value || !*value)
6535 if(strlen(this_char) > 4)
6538 j = strlen(this_char);
6541 if(this_char[j] > 'f' || this_char[j] < '0')
6546 k = j = strlen(this_char);
6549 this_char[4-k+j] = this_char[j];
6553 this_char[3-k++]='0';
6556 if(strlen(this_char) == 4)
6558 AtoH(this_char, temp, 2);
6559 eepAddr = *temp*256 + temp[1];
6560 if (eepAddr < 0xFFFF)
6562 RT28xx_EEPROM_READ16(pAdapter, eepAddr, eepValue);
6563 sprintf(msg+strlen(msg), "[0x%04X]:0x%04X ", eepAddr , eepValue);
6566 {//Invalid parametes, so default printk all bbp
6573 memcpy(&temp2, value, strlen(value));
6574 temp2[strlen(value)] = '\0';
6577 if((strlen(this_char) > 4) || strlen(temp2) > 8)
6580 j = strlen(this_char);
6583 if(this_char[j] > 'f' || this_char[j] < '0')
6589 if(temp2[j] > 'f' || temp2[j] < '0')
6594 k = j = strlen(this_char);
6597 this_char[4-k+j] = this_char[j];
6601 this_char[3-k++]='0';
6605 k = j = strlen(temp2);
6608 temp2[4-k+j] = temp2[j];
6615 AtoH(this_char, temp, 2);
6616 eepAddr = *temp*256 + temp[1];
6618 AtoH(temp2, temp, 2);
6619 eepValue = *temp*256 + temp[1];
6621 RT28xx_EEPROM_WRITE16(pAdapter, eepAddr, eepValue);
6622 sprintf(msg+strlen(msg), "[0x%02X]:%02X ", eepAddr, eepValue);
6626 if(strlen(msg) == 1)
6627 sprintf(msg+strlen(msg), "===>Error command format!");
6630 // Copy the information into the user buffer
6631 wrq->u.data.length = strlen(msg);
6632 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6634 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlE2PROM\n"));
6641 INT Set_TGnWifiTest_Proc(
6642 IN PRTMP_ADAPTER pAd,
6645 if (simple_strtol(arg, 0, 10) == 0)
6646 pAd->StaCfg.bTGnWifiTest = FALSE;
6648 pAd->StaCfg.bTGnWifiTest = TRUE;
6650 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_TGnWifiTest_Proc::(bTGnWifiTest=%d)\n", pAd->StaCfg.bTGnWifiTest));
6654 INT Set_LongRetryLimit_Proc(
6655 IN PRTMP_ADAPTER pAdapter,
6658 TX_RTY_CFG_STRUC tx_rty_cfg;
6659 UCHAR LongRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
6661 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
6662 tx_rty_cfg.field.LongRtyLimit = LongRetryLimit;
6663 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
6664 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_LongRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
6668 INT Set_ShortRetryLimit_Proc(
6669 IN PRTMP_ADAPTER pAdapter,
6672 TX_RTY_CFG_STRUC tx_rty_cfg;
6673 UCHAR ShortRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
6675 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
6676 tx_rty_cfg.field.ShortRtyLimit = ShortRetryLimit;
6677 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
6678 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_ShortRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));