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" },
91 { SHOW_ADHOC_ENTRY_INFO,
92 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "adhocEntry" },
94 /* --- sub-ioctls relations --- */
98 IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
101 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
105 IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
109 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
113 { RTPRIV_IOCTL_STATISTICS,
114 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
116 { RTPRIV_IOCTL_GSITESURVEY,
117 0, IW_PRIV_TYPE_CHAR | 1024,
122 IN PRTMP_ADAPTER pAdapter,
126 INT Set_WmmCapable_Proc(
127 IN PRTMP_ADAPTER pAd,
131 INT Set_NetworkType_Proc(
132 IN PRTMP_ADAPTER pAdapter,
135 INT Set_AuthMode_Proc(
136 IN PRTMP_ADAPTER pAdapter,
139 INT Set_EncrypType_Proc(
140 IN PRTMP_ADAPTER pAdapter,
143 INT Set_DefaultKeyID_Proc(
144 IN PRTMP_ADAPTER pAdapter,
148 IN PRTMP_ADAPTER pAdapter,
152 IN PRTMP_ADAPTER pAdapter,
156 IN PRTMP_ADAPTER pAdapter,
160 IN PRTMP_ADAPTER pAdapter,
164 IN PRTMP_ADAPTER pAdapter,
169 IN PRTMP_ADAPTER pAdapter,
173 IN PRTMP_ADAPTER pAd,
179 IN PRTMP_ADAPTER pAdapter,
180 IN struct iwreq *wrq);
184 IN PRTMP_ADAPTER pAdapter,
185 IN struct iwreq *wrq);
187 VOID RTMPIoctlE2PROM(
188 IN PRTMP_ADAPTER pAdapter,
189 IN struct iwreq *wrq);
193 IN PRTMP_ADAPTER pAdapter,
194 IN struct iwreq *wrq);
199 NDIS_STATUS RTMPWPANoneAddKeyProc(
200 IN PRTMP_ADAPTER pAd,
203 INT Set_FragTest_Proc(
204 IN PRTMP_ADAPTER pAdapter,
207 INT Set_TGnWifiTest_Proc(
208 IN PRTMP_ADAPTER pAd,
211 INT Set_LongRetryLimit_Proc(
212 IN PRTMP_ADAPTER pAdapter,
215 INT Set_ShortRetryLimit_Proc(
216 IN PRTMP_ADAPTER pAdapter,
220 INT Show_Adhoc_MacTable_Proc(
221 IN PRTMP_ADAPTER pAd,
227 INT (*set_proc)(PRTMP_ADAPTER pAdapter, PUCHAR arg);
228 } *PRTMP_PRIVATE_SET_PROC, RTMP_PRIVATE_SUPPORT_PROC[] = {
229 {"DriverVersion", Set_DriverVersion_Proc},
230 {"CountryRegion", Set_CountryRegion_Proc},
231 {"CountryRegionABand", Set_CountryRegionABand_Proc},
232 {"SSID", Set_SSID_Proc},
233 {"WirelessMode", Set_WirelessMode_Proc},
234 {"TxBurst", Set_TxBurst_Proc},
235 {"TxPreamble", Set_TxPreamble_Proc},
236 {"TxPower", Set_TxPower_Proc},
237 {"Channel", Set_Channel_Proc},
238 {"BGProtection", Set_BGProtection_Proc},
239 {"RTSThreshold", Set_RTSThreshold_Proc},
240 {"FragThreshold", Set_FragThreshold_Proc},
241 {"HtBw", Set_HtBw_Proc},
242 {"HtMcs", Set_HtMcs_Proc},
243 {"HtGi", Set_HtGi_Proc},
244 {"HtOpMode", Set_HtOpMode_Proc},
245 {"HtExtcha", Set_HtExtcha_Proc},
246 {"HtMpduDensity", Set_HtMpduDensity_Proc},
247 {"HtBaWinSize", Set_HtBaWinSize_Proc},
248 {"HtRdg", Set_HtRdg_Proc},
249 {"HtAmsdu", Set_HtAmsdu_Proc},
250 {"HtAutoBa", Set_HtAutoBa_Proc},
251 {"HtBaDecline", Set_BADecline_Proc},
252 {"HtProtect", Set_HtProtect_Proc},
253 {"HtMimoPs", Set_HtMimoPs_Proc},
254 #ifdef AGGREGATION_SUPPORT
255 {"PktAggregate", Set_PktAggregate_Proc},
259 {"WmmCapable", Set_WmmCapable_Proc},
261 {"IEEE80211H", Set_IEEE80211H_Proc},
262 {"NetworkType", Set_NetworkType_Proc},
263 {"AuthMode", Set_AuthMode_Proc},
264 {"EncrypType", Set_EncrypType_Proc},
265 {"DefaultKeyID", Set_DefaultKeyID_Proc},
266 {"Key1", Set_Key1_Proc},
267 {"Key2", Set_Key2_Proc},
268 {"Key3", Set_Key3_Proc},
269 {"Key4", Set_Key4_Proc},
270 {"WPAPSK", Set_WPAPSK_Proc},
271 {"ResetCounter", Set_ResetStatCounter_Proc},
272 {"PSMode", Set_PSMode_Proc},
274 {"Debug", Set_Debug_Proc},
276 {"WpaSupport", Set_Wpa_Support},
277 {"FixedTxMode", Set_FixedTxMode_Proc},
278 {"TGnWifiTest", Set_TGnWifiTest_Proc},
279 {"ForceGF", Set_ForceGF_Proc},
280 {"LongRetry", Set_LongRetryLimit_Proc},
281 {"ShortRetry", Set_ShortRetryLimit_Proc},
282 //2008/09/11:KH add to support efuse<--
284 {"efuseFreeNumber", set_eFuseGetFreeBlockCount_Proc},
285 {"efuseDump", set_eFusedump_Proc},
286 {"efuseLoadFromBin", set_eFuseLoadFromBin_Proc},
288 //2008/09/11:KH add to support efuse-->
294 IN PRTMP_ADAPTER pAd,
295 IN PNDIS_802_11_KEY pKey)
298 MAC_TABLE_ENTRY *pEntry;
300 DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey ------>\n"));
302 if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
304 if (pKey->KeyIndex & 0x80000000)
306 if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
308 NdisZeroMemory(pAd->StaCfg.PMK, 32);
309 NdisMoveMemory(pAd->StaCfg.PMK, pKey->KeyMaterial, pKey->KeyLength);
313 NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));
314 pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
315 NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, pKey->KeyMaterial, LEN_TKIP_EK);
317 if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
319 NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
320 NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
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);
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);
383 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
384 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
387 // Update Shared Key CipherAlg
388 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_NONE;
389 if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
390 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_TKIP;
391 else if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)
392 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_AES;
394 // Update group key information to ASIC Shared Key Table
395 AsicAddSharedKeyEntry(pAd,
397 pAd->StaCfg.DefaultKeyId,
398 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
399 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key,
400 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic,
401 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic);
403 // Update ASIC WCID attribute table and IVEIV table
404 RTMPAddWcidAttributeEntry(pAd,
406 pAd->StaCfg.DefaultKeyId,
407 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
410 // set 802.1x port control
411 STA_PORT_SECURED(pAd);
413 // Indicate Connected for GUI
414 pAd->IndicateMediaState = NdisMediaStateConnected;
417 else // dynamic WEP from wpa_supplicant
422 if(pKey->KeyLength == 32)
425 KeyIdx = pKey->KeyIndex & 0x0fffffff;
429 // it is a default shared key, for Pairwise key setting
430 if (pKey->KeyIndex & 0x80000000)
432 pEntry = MacTableLookup(pAd, pKey->BSSID);
436 DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey: Set Pair-wise Key\n"));
438 // set key material and key length
439 pEntry->PairwiseKey.KeyLen = (UCHAR)pKey->KeyLength;
440 NdisMoveMemory(pEntry->PairwiseKey.Key, &pKey->KeyMaterial, pKey->KeyLength);
443 if (pKey->KeyLength == 5)
444 pEntry->PairwiseKey.CipherAlg = CIPHER_WEP64;
446 pEntry->PairwiseKey.CipherAlg = CIPHER_WEP128;
448 // Add Pair-wise key to Asic
449 AsicAddPairwiseKeyEntry(
453 &pEntry->PairwiseKey);
455 // update WCID attribute table and IVEIV table for this entry
456 RTMPAddWcidAttributeEntry(
459 KeyIdx, // The value may be not zero
460 pEntry->PairwiseKey.CipherAlg,
467 // Default key for tx (shared key)
468 pAd->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
470 // set key material and key length
471 pAd->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pKey->KeyLength;
472 NdisMoveMemory(pAd->SharedKey[BSS0][KeyIdx].Key, &pKey->KeyMaterial, pKey->KeyLength);
475 if (pKey->KeyLength == 5)
476 pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP64;
478 pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP128;
480 CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg;
481 Key = pAd->SharedKey[BSS0][KeyIdx].Key;
483 // Set Group key material to Asic
484 AsicAddSharedKeyEntry(pAd, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
486 // Update WCID attribute table and IVEIV table for this group key table
487 RTMPAddWcidAttributeEntry(pAd, BSS0, KeyIdx, CipherAlg, NULL);
496 char * rtstrchr(const char * s, int c)
498 for(; *s != (char) c; ++s)
505 This is required for LinEX2004/kernel2.6.7 to provide iwlist scanning function
509 rt_ioctl_giwname(struct net_device *dev,
510 struct iw_request_info *info,
511 char *name, char *extra)
513 // PRTMP_ADAPTER pAdapter = dev->ml_priv;
516 strncpy(name, "RT2870 Wireless", IFNAMSIZ);
521 int rt_ioctl_siwfreq(struct net_device *dev,
522 struct iw_request_info *info,
523 struct iw_freq *freq, char *extra)
525 PRTMP_ADAPTER pAdapter = dev->ml_priv;
528 //check if the interface is down
529 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
531 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
539 if((freq->e == 0) && (freq->m <= 1000))
540 chan = freq->m; // Setting by channel number
542 MAP_KHZ_TO_CHANNEL_ID( (freq->m /100) , chan); // Setting by frequency - search the table , like 2.412G, 2.422G,
544 if (ChannelSanity(pAdapter, chan) == TRUE)
546 pAdapter->CommonCfg.Channel = chan;
547 DBGPRINT(RT_DEBUG_ERROR, ("==>rt_ioctl_siwfreq::SIOCSIWFREQ[cmd=0x%x] (Channel=%d)\n", SIOCSIWFREQ, pAdapter->CommonCfg.Channel));
554 int rt_ioctl_giwfreq(struct net_device *dev,
555 struct iw_request_info *info,
556 struct iw_freq *freq, char *extra)
558 VIRTUAL_ADAPTER *pVirtualAd = NULL;
560 PRTMP_ADAPTER pAdapter = NULL;
563 PRTMP_ADAPTER pAdapter;
568 if (dev->priv_flags == INT_MAIN)
570 pAdapter = dev->ml_priv;
574 pVirtualAd = dev->ml_priv;
576 if (pVirtualAd && pVirtualAd->RtmpDev)
578 pAdapter = pVirtualAd->RtmpDev->ml_priv;
581 if (pAdapter == NULL)
583 /* if 1st open fail, pAd will be free;
584 So the net_dev->ml_priv will be NULL in 2rd open */
588 ch = pAdapter->CommonCfg.Channel;
590 DBGPRINT(RT_DEBUG_TRACE,("==>rt_ioctl_giwfreq %d\n", ch));
592 MAP_CHANNEL_ID_TO_KHZ(ch, m);
598 int rt_ioctl_siwmode(struct net_device *dev,
599 struct iw_request_info *info,
600 __u32 *mode, char *extra)
602 PRTMP_ADAPTER pAdapter = dev->ml_priv;
604 //check if the interface is down
605 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
607 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
614 Set_NetworkType_Proc(pAdapter, "Adhoc");
617 Set_NetworkType_Proc(pAdapter, "Infra");
619 case IW_MODE_MONITOR:
620 Set_NetworkType_Proc(pAdapter, "Monitor");
623 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_siwmode::SIOCSIWMODE (unknown %d)\n", *mode));
627 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
628 pAdapter->StaCfg.WpaState = SS_NOTUSE;
633 int rt_ioctl_giwmode(struct net_device *dev,
634 struct iw_request_info *info,
635 __u32 *mode, char *extra)
638 PRTMP_ADAPTER pAdapter = NULL;
639 VIRTUAL_ADAPTER *pVirtualAd = NULL;
641 if (dev->priv_flags == INT_MAIN)
643 pAdapter = dev->ml_priv;
647 pVirtualAd = dev->ml_priv;
648 if (pVirtualAd && pVirtualAd->RtmpDev)
649 pAdapter = pVirtualAd->RtmpDev->ml_priv;
652 if (pAdapter == NULL)
654 /* if 1st open fail, pAd will be free;
655 So the net_dev->ml_priv will be NULL in 2rd open */
660 PRTMP_ADAPTER pAdapter = dev->ml_priv;
663 if (ADHOC_ON(pAdapter))
664 *mode = IW_MODE_ADHOC;
665 else if (INFRA_ON(pAdapter))
666 *mode = IW_MODE_INFRA;
667 else if (MONITOR_ON(pAdapter))
669 *mode = IW_MODE_MONITOR;
672 *mode = IW_MODE_AUTO;
674 DBGPRINT(RT_DEBUG_TRACE, ("==>rt_ioctl_giwmode(mode=%d)\n", *mode));
678 int rt_ioctl_siwsens(struct net_device *dev,
679 struct iw_request_info *info,
680 char *name, char *extra)
682 PRTMP_ADAPTER pAdapter = dev->ml_priv;
684 //check if the interface is down
685 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
687 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
694 int rt_ioctl_giwsens(struct net_device *dev,
695 struct iw_request_info *info,
696 char *name, char *extra)
701 int rt_ioctl_giwrange(struct net_device *dev,
702 struct iw_request_info *info,
703 struct iw_point *data, char *extra)
706 PRTMP_ADAPTER pAdapter = NULL;
707 VIRTUAL_ADAPTER *pVirtualAd = NULL;
710 PRTMP_ADAPTER pAdapter = dev->ml_priv;
712 struct iw_range *range = (struct iw_range *) extra;
717 if (dev->priv_flags == INT_MAIN)
719 pAdapter = dev->ml_priv;
723 pVirtualAd = dev->ml_priv;
724 if (pVirtualAd && pVirtualAd->RtmpDev)
725 pAdapter = pVirtualAd->RtmpDev->ml_priv;
728 if (pAdapter == NULL)
730 /* if 1st open fail, pAd will be free;
731 So the net_dev->ml_priv will be NULL in 2rd open */
736 DBGPRINT(RT_DEBUG_TRACE ,("===>rt_ioctl_giwrange\n"));
737 data->length = sizeof(struct iw_range);
738 memset(range, 0, sizeof(struct iw_range));
740 range->txpower_capa = IW_TXPOW_DBM;
742 if (INFRA_ON(pAdapter)||ADHOC_ON(pAdapter))
744 range->min_pmp = 1 * 1024;
745 range->max_pmp = 65535 * 1024;
746 range->min_pmt = 1 * 1024;
747 range->max_pmt = 1000 * 1024;
748 range->pmp_flags = IW_POWER_PERIOD;
749 range->pmt_flags = IW_POWER_TIMEOUT;
750 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT |
751 IW_POWER_UNICAST_R | IW_POWER_ALL_R;
754 range->we_version_compiled = WIRELESS_EXT;
755 range->we_version_source = 14;
757 range->retry_capa = IW_RETRY_LIMIT;
758 range->retry_flags = IW_RETRY_LIMIT;
759 range->min_retry = 0;
760 range->max_retry = 255;
762 range->num_channels = pAdapter->ChannelListNum;
765 for (i = 1; i <= range->num_channels; i++)
768 range->freq[val].i = pAdapter->ChannelList[i-1].Channel;
769 MAP_CHANNEL_ID_TO_KHZ(pAdapter->ChannelList[i-1].Channel, m);
770 range->freq[val].m = m * 100; /* HZ */
772 range->freq[val].e = 1;
774 if (val == IW_MAX_FREQUENCIES)
777 range->num_frequency = val;
779 range->max_qual.qual = 100; /* what is correct max? This was not
780 * documented exactly. At least
781 * 69 has been observed. */
782 range->max_qual.level = 0; /* dB */
783 range->max_qual.noise = 0; /* dB */
785 /* What would be suitable values for "average/typical" qual? */
786 range->avg_qual.qual = 20;
787 range->avg_qual.level = -60;
788 range->avg_qual.noise = -95;
789 range->sensitivity = 3;
791 range->max_encoding_tokens = NR_WEP_KEYS;
792 range->num_encoding_sizes = 2;
793 range->encoding_size[0] = 5;
794 range->encoding_size[1] = 13;
797 range->max_rts = 2347;
798 range->min_frag = 256;
799 range->max_frag = 2346;
801 #if WIRELESS_EXT > 17
802 /* IW_ENC_CAPA_* bit field */
803 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
804 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
810 int rt_ioctl_siwap(struct net_device *dev,
811 struct iw_request_info *info,
812 struct sockaddr *ap_addr, char *extra)
814 PRTMP_ADAPTER pAdapter = dev->ml_priv;
815 NDIS_802_11_MAC_ADDRESS Bssid;
817 //check if the interface is down
818 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
820 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
824 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
826 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
827 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
830 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
831 // this request, because this request is initiated by NDIS.
832 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
833 // Prevent to connect AP again in STAMlmePeriodicExec
834 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
836 memset(Bssid, 0, MAC_ADDR_LEN);
837 memcpy(Bssid, ap_addr->sa_data, MAC_ADDR_LEN);
838 MlmeEnqueue(pAdapter,
839 MLME_CNTL_STATE_MACHINE,
841 sizeof(NDIS_802_11_MAC_ADDRESS),
844 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCSIWAP %02x:%02x:%02x:%02x:%02x:%02x\n",
845 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
850 int rt_ioctl_giwap(struct net_device *dev,
851 struct iw_request_info *info,
852 struct sockaddr *ap_addr, char *extra)
855 PRTMP_ADAPTER pAdapter = NULL;
856 VIRTUAL_ADAPTER *pVirtualAd = NULL;
858 if (dev->priv_flags == INT_MAIN)
860 pAdapter = dev->ml_priv;
864 pVirtualAd = dev->ml_priv;
865 if (pVirtualAd && pVirtualAd->RtmpDev)
866 pAdapter = pVirtualAd->RtmpDev->ml_priv;
869 if (pAdapter == NULL)
871 /* if 1st open fail, pAd will be free;
872 So the net_dev->ml_priv will be NULL in 2rd open */
877 PRTMP_ADAPTER pAdapter = dev->ml_priv;
880 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
882 ap_addr->sa_family = ARPHRD_ETHER;
883 memcpy(ap_addr->sa_data, &pAdapter->CommonCfg.Bssid, ETH_ALEN);
886 else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
888 ap_addr->sa_family = ARPHRD_ETHER;
889 memcpy(ap_addr->sa_data, &pAdapter->MlmeAux.Bssid, ETH_ALEN);
893 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIWAP(=EMPTY)\n"));
901 * Units are in db above the noise floor. That means the
902 * rssi values reported in the tx/rx descriptors in the
903 * driver are the SNR expressed in db.
905 * If you assume that the noise floor is -95, which is an
906 * excellent assumption 99.5 % of the time, then you can
907 * derive the absolute signal level (i.e. -95 + rssi).
908 * There are some other slight factors to take into account
909 * depending on whether the rssi measurement is from 11b,
910 * 11g, or 11a. These differences are at most 2db and
913 * NB: various calculations are based on the orinoco/wavelan
914 * drivers for compatibility
916 static void set_quality(PRTMP_ADAPTER pAdapter,
917 struct iw_quality *iq,
924 ChannelQuality = 100;
925 else if (rssi >= -80) // between -50 ~ -80dbm
926 ChannelQuality = (__u8)(24 + ((rssi + 80) * 26)/10);
927 else if (rssi >= -90) // between -80 ~ -90dbm
928 ChannelQuality = (__u8)((rssi + 90) * 26)/10;
932 iq->qual = (__u8)ChannelQuality;
934 iq->level = (__u8)(rssi);
935 iq->noise = (pAdapter->BbpWriteLatch[66] > pAdapter->BbpTuning.FalseCcaUpperThreshold) ? ((__u8)pAdapter->BbpTuning.FalseCcaUpperThreshold) : ((__u8) pAdapter->BbpWriteLatch[66]); // noise level (dBm)
936 iq->noise += 256 - 143;
937 iq->updated = pAdapter->iw_stats.qual.updated;
940 int rt_ioctl_iwaplist(struct net_device *dev,
941 struct iw_request_info *info,
942 struct iw_point *data, char *extra)
944 PRTMP_ADAPTER pAdapter = dev->ml_priv;
946 struct sockaddr addr[IW_MAX_AP];
947 struct iw_quality qual[IW_MAX_AP];
950 //check if the interface is down
951 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
953 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
959 for (i = 0; i <IW_MAX_AP ; i++)
961 if (i >= pAdapter->ScanTab.BssNr)
963 addr[i].sa_family = ARPHRD_ETHER;
964 memcpy(addr[i].sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
965 set_quality(pAdapter, &qual[i], pAdapter->ScanTab.BssEntry[i].Rssi);
968 memcpy(extra, &addr, i*sizeof(addr[0]));
969 data->flags = 1; /* signal quality present (sort of) */
970 memcpy(extra + i*sizeof(addr[0]), &qual, i*sizeof(qual[i]));
976 int rt_ioctl_siwscan(struct net_device *dev,
977 struct iw_request_info *info,
978 struct iw_point *data, char *extra)
980 PRTMP_ADAPTER pAdapter = dev->ml_priv;
983 int Status = NDIS_STATUS_SUCCESS;
985 //check if the interface is down
986 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
988 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
992 if (MONITOR_ON(pAdapter))
994 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
999 if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
1001 pAdapter->StaCfg.WpaSupplicantScanCount++;
1004 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
1005 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
1010 if ((pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE) &&
1011 (pAdapter->StaCfg.WpaSupplicantScanCount > 3))
1013 DBGPRINT(RT_DEBUG_TRACE, ("!!! WpaSupplicantScanCount > 3\n"));
1014 Status = NDIS_STATUS_SUCCESS;
1018 if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
1019 ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
1020 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) &&
1021 (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
1023 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
1024 Status = NDIS_STATUS_SUCCESS;
1028 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
1030 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
1031 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
1034 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
1035 // this request, because this request is initiated by NDIS.
1036 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
1037 // Reset allowed scan retries
1038 pAdapter->StaCfg.ScanCnt = 0;
1039 pAdapter->StaCfg.LastScanTime = Now;
1041 MlmeEnqueue(pAdapter,
1042 MLME_CNTL_STATE_MACHINE,
1043 OID_802_11_BSSID_LIST_SCAN,
1047 Status = NDIS_STATUS_SUCCESS;
1048 RT28XX_MLME_HANDLER(pAdapter);
1053 int rt_ioctl_giwscan(struct net_device *dev,
1054 struct iw_request_info *info,
1055 struct iw_point *data, char *extra)
1058 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1060 char *current_ev = extra, *previous_ev = extra;
1062 char *current_val, custom[MAX_CUSTOM_LEN] = {0};
1065 #endif // IWEVGENIE //
1066 struct iw_event iwe;
1068 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
1071 * Still scanning, indicate the caller should try again.
1076 if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
1078 pAdapter->StaCfg.WpaSupplicantScanCount = 0;
1081 if (pAdapter->ScanTab.BssNr == 0)
1087 #if WIRELESS_EXT >= 17
1088 if (data->length > 0)
1089 end_buf = extra + data->length;
1091 end_buf = extra + IW_SCAN_MAX_DATA;
1093 end_buf = extra + IW_SCAN_MAX_DATA;
1096 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
1098 if (current_ev >= end_buf)
1100 #if WIRELESS_EXT >= 17
1108 //================================
1109 memset(&iwe, 0, sizeof(iwe));
1110 iwe.cmd = SIOCGIWAP;
1111 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1112 memcpy(iwe.u.ap_addr.sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, ETH_ALEN);
1114 previous_ev = current_ev;
1115 current_ev = iwe_stream_add_event(info, current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);
1117 if (current_ev == previous_ev)
1118 #if WIRELESS_EXT >= 17
1126 it will show scanned AP's WirelessMode .
1135 memset(&iwe, 0, sizeof(iwe));
1136 iwe.cmd = SIOCGIWNAME;
1140 PBSS_ENTRY pBssEntry=&pAdapter->ScanTab.BssEntry[i];
1141 BOOLEAN isGonly=FALSE;
1144 if (pBssEntry->Channel>14)
1146 if (pBssEntry->HtCapabilityLen!=0)
1147 strcpy(iwe.u.name,"802.11a/n");
1149 strcpy(iwe.u.name,"802.11a");
1154 if one of non B mode rate is set supported rate . it mean G only.
1156 for (rateCnt=0;rateCnt<pBssEntry->SupRateLen;rateCnt++)
1159 6Mbps(140) 9Mbps(146) and >=12Mbps(152) are supported rate , it mean G only.
1161 if (pBssEntry->SupRate[rateCnt]==140 || pBssEntry->SupRate[rateCnt]==146 || pBssEntry->SupRate[rateCnt]>=152)
1165 for (rateCnt=0;rateCnt<pBssEntry->ExtRateLen;rateCnt++)
1167 if (pBssEntry->ExtRate[rateCnt]==140 || pBssEntry->ExtRate[rateCnt]==146 || pBssEntry->ExtRate[rateCnt]>=152)
1172 if (pBssEntry->HtCapabilityLen!=0)
1175 strcpy(iwe.u.name,"802.11g/n");
1177 strcpy(iwe.u.name,"802.11b/g/n");
1182 strcpy(iwe.u.name,"802.11g");
1185 if (pBssEntry->SupRateLen==4 && pBssEntry->ExtRateLen==0)
1186 strcpy(iwe.u.name,"802.11b");
1188 strcpy(iwe.u.name,"802.11b/g");
1194 previous_ev = current_ev;
1195 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
1197 if (current_ev == previous_ev)
1198 #if WIRELESS_EXT >= 17
1205 //================================
1206 memset(&iwe, 0, sizeof(iwe));
1207 iwe.cmd = SIOCGIWESSID;
1208 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].SsidLen;
1209 iwe.u.data.flags = 1;
1211 previous_ev = current_ev;
1212 current_ev = iwe_stream_add_point(info, current_ev,end_buf, &iwe, pAdapter->ScanTab.BssEntry[i].Ssid);
1213 if (current_ev == previous_ev)
1214 #if WIRELESS_EXT >= 17
1221 //================================
1222 memset(&iwe, 0, sizeof(iwe));
1223 iwe.cmd = SIOCGIWMODE;
1224 if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11IBSS)
1226 iwe.u.mode = IW_MODE_ADHOC;
1228 else if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11Infrastructure)
1230 iwe.u.mode = IW_MODE_INFRA;
1234 iwe.u.mode = IW_MODE_AUTO;
1236 iwe.len = IW_EV_UINT_LEN;
1238 previous_ev = current_ev;
1239 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
1240 if (current_ev == previous_ev)
1241 #if WIRELESS_EXT >= 17
1247 //Channel and Frequency
1248 //================================
1249 memset(&iwe, 0, sizeof(iwe));
1250 iwe.cmd = SIOCGIWFREQ;
1251 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
1252 iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
1254 iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
1258 previous_ev = current_ev;
1259 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
1260 if (current_ev == previous_ev)
1261 #if WIRELESS_EXT >= 17
1267 //Add quality statistics
1268 //================================
1269 memset(&iwe, 0, sizeof(iwe));
1271 iwe.u.qual.level = 0;
1272 iwe.u.qual.noise = 0;
1273 set_quality(pAdapter, &iwe.u.qual, pAdapter->ScanTab.BssEntry[i].Rssi);
1274 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
1275 if (current_ev == previous_ev)
1276 #if WIRELESS_EXT >= 17
1283 //================================
1284 memset(&iwe, 0, sizeof(iwe));
1285 iwe.cmd = SIOCGIWENCODE;
1286 if (CAP_IS_PRIVACY_ON (pAdapter->ScanTab.BssEntry[i].CapabilityInfo ))
1287 iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1289 iwe.u.data.flags = IW_ENCODE_DISABLED;
1291 previous_ev = current_ev;
1292 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);
1293 if (current_ev == previous_ev)
1294 #if WIRELESS_EXT >= 17
1301 //================================
1302 if (pAdapter->ScanTab.BssEntry[i].SupRateLen)
1304 UCHAR tmpRate = pAdapter->ScanTab.BssEntry[i].SupRate[pAdapter->ScanTab.BssEntry[i].SupRateLen-1];
1305 memset(&iwe, 0, sizeof(iwe));
1306 iwe.cmd = SIOCGIWRATE;
1307 current_val = current_ev + IW_EV_LCP_LEN;
1308 if (tmpRate == 0x82)
1309 iwe.u.bitrate.value = 1 * 1000000;
1310 else if (tmpRate == 0x84)
1311 iwe.u.bitrate.value = 2 * 1000000;
1312 else if (tmpRate == 0x8B)
1313 iwe.u.bitrate.value = 5.5 * 1000000;
1314 else if (tmpRate == 0x96)
1315 iwe.u.bitrate.value = 11 * 1000000;
1317 iwe.u.bitrate.value = (tmpRate/2) * 1000000;
1319 iwe.u.bitrate.disabled = 0;
1320 current_val = iwe_stream_add_value(info, current_ev,
1321 current_val, end_buf, &iwe,
1324 if((current_val-current_ev)>IW_EV_LCP_LEN)
1325 current_ev = current_val;
1327 #if WIRELESS_EXT >= 17
1336 if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
1338 memset(&iwe, 0, sizeof(iwe));
1339 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1340 memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].WpaIE.IE[0]),
1341 pAdapter->ScanTab.BssEntry[i].WpaIE.IELen);
1342 iwe.cmd = IWEVGENIE;
1343 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].WpaIE.IELen;
1344 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, custom);
1345 if (current_ev == previous_ev)
1346 #if WIRELESS_EXT >= 17
1354 if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
1356 memset(&iwe, 0, sizeof(iwe));
1357 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1358 memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].RsnIE.IE[0]),
1359 pAdapter->ScanTab.BssEntry[i].RsnIE.IELen);
1360 iwe.cmd = IWEVGENIE;
1361 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].RsnIE.IELen;
1362 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, custom);
1363 if (current_ev == previous_ev)
1364 #if WIRELESS_EXT >= 17
1372 //================================
1373 if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
1375 NdisZeroMemory(&iwe, sizeof(iwe));
1376 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1377 iwe.cmd = IWEVCUSTOM;
1378 iwe.u.data.length = (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen * 2) + 7;
1379 NdisMoveMemory(custom, "wpa_ie=", 7);
1380 for (idx = 0; idx < pAdapter->ScanTab.BssEntry[i].WpaIE.IELen; idx++)
1381 sprintf(custom + strlen(custom), "%02x", pAdapter->ScanTab.BssEntry[i].WpaIE.IE[idx]);
1382 previous_ev = current_ev;
1383 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, custom);
1384 if (current_ev == previous_ev)
1385 #if WIRELESS_EXT >= 17
1393 if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
1395 NdisZeroMemory(&iwe, sizeof(iwe));
1396 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1397 iwe.cmd = IWEVCUSTOM;
1398 iwe.u.data.length = (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen * 2) + 7;
1399 NdisMoveMemory(custom, "rsn_ie=", 7);
1400 for (idx = 0; idx < pAdapter->ScanTab.BssEntry[i].RsnIE.IELen; idx++)
1401 sprintf(custom + strlen(custom), "%02x", pAdapter->ScanTab.BssEntry[i].RsnIE.IE[idx]);
1402 previous_ev = current_ev;
1403 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, custom);
1404 if (current_ev == previous_ev)
1405 #if WIRELESS_EXT >= 17
1411 #endif // IWEVGENIE //
1414 data->length = current_ev - extra;
1415 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
1416 DBGPRINT(RT_DEBUG_ERROR ,("===>rt_ioctl_giwscan. %d(%d) BSS returned, data->length = %d\n",i , pAdapter->ScanTab.BssNr, data->length));
1421 int rt_ioctl_siwessid(struct net_device *dev,
1422 struct iw_request_info *info,
1423 struct iw_point *data, char *essid)
1425 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1427 //check if the interface is down
1428 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1430 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1436 PCHAR pSsidString = NULL;
1438 // Includes null character.
1439 if (data->length > (IW_ESSID_MAX_SIZE + 1))
1442 pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
1445 NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
1446 NdisMoveMemory(pSsidString, essid, data->length);
1447 if (Set_SSID_Proc(pAdapter, pSsidString) == FALSE)
1456 if (Set_SSID_Proc(pAdapter, "") == FALSE)
1462 int rt_ioctl_giwessid(struct net_device *dev,
1463 struct iw_request_info *info,
1464 struct iw_point *data, char *essid)
1467 PRTMP_ADAPTER pAdapter = NULL;
1468 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1470 if (dev->priv_flags == INT_MAIN)
1472 pAdapter = dev->ml_priv;
1476 pVirtualAd = dev->ml_priv;
1477 if (pVirtualAd && pVirtualAd->RtmpDev)
1478 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1481 if (pAdapter == NULL)
1483 /* if 1st open fail, pAd will be free;
1484 So the net_dev->ml_priv will be NULL in 2rd open */
1489 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1493 if (MONITOR_ON(pAdapter))
1499 if (OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED))
1501 DBGPRINT(RT_DEBUG_TRACE ,("MediaState is connected\n"));
1502 data->length = pAdapter->CommonCfg.SsidLen;
1503 memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
1507 else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
1509 data->length = pAdapter->CommonCfg.SsidLen;
1510 memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
1514 {//the ANY ssid was specified
1516 DBGPRINT(RT_DEBUG_TRACE ,("MediaState is not connected, ess\n"));
1523 int rt_ioctl_siwnickn(struct net_device *dev,
1524 struct iw_request_info *info,
1525 struct iw_point *data, char *nickname)
1527 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1529 //check if the interface is down
1530 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1532 DBGPRINT(RT_DEBUG_TRACE ,("INFO::Network is down!\n"));
1536 if (data->length > IW_ESSID_MAX_SIZE)
1539 memset(pAdapter->nickname, 0, IW_ESSID_MAX_SIZE + 1);
1540 memcpy(pAdapter->nickname, nickname, data->length);
1546 int rt_ioctl_giwnickn(struct net_device *dev,
1547 struct iw_request_info *info,
1548 struct iw_point *data, char *nickname)
1551 PRTMP_ADAPTER pAdapter = NULL;
1552 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1554 if (dev->priv_flags == INT_MAIN)
1556 pAdapter = dev->ml_priv;
1560 pVirtualAd = dev->ml_priv;
1561 if (pVirtualAd && pVirtualAd->RtmpDev)
1562 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1565 if (pAdapter == NULL)
1567 /* if 1st open fail, pAd will be free;
1568 So the net_dev->ml_priv will be NULL in 2rd open */
1573 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1576 if (data->length > strlen(pAdapter->nickname) + 1)
1577 data->length = strlen(pAdapter->nickname) + 1;
1578 if (data->length > 0) {
1579 memcpy(nickname, pAdapter->nickname, data->length-1);
1580 nickname[data->length-1] = '\0';
1585 int rt_ioctl_siwrts(struct net_device *dev,
1586 struct iw_request_info *info,
1587 struct iw_param *rts, char *extra)
1589 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1592 //check if the interface is down
1593 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1595 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1600 val = MAX_RTS_THRESHOLD;
1601 else if (rts->value < 0 || rts->value > MAX_RTS_THRESHOLD)
1603 else if (rts->value == 0)
1604 val = MAX_RTS_THRESHOLD;
1608 if (val != pAdapter->CommonCfg.RtsThreshold)
1609 pAdapter->CommonCfg.RtsThreshold = val;
1614 int rt_ioctl_giwrts(struct net_device *dev,
1615 struct iw_request_info *info,
1616 struct iw_param *rts, char *extra)
1619 PRTMP_ADAPTER pAdapter = NULL;
1620 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1622 if (dev->priv_flags == INT_MAIN)
1624 pAdapter = dev->ml_priv;
1628 pVirtualAd = dev->ml_priv;
1629 if (pVirtualAd && pVirtualAd->RtmpDev)
1630 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1633 if (pAdapter == NULL)
1635 /* if 1st open fail, pAd will be free;
1636 So the net_dev->ml_priv will be NULL in 2rd open */
1641 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1644 //check if the interface is down
1645 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1647 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1651 rts->value = pAdapter->CommonCfg.RtsThreshold;
1652 rts->disabled = (rts->value == MAX_RTS_THRESHOLD);
1658 int rt_ioctl_siwfrag(struct net_device *dev,
1659 struct iw_request_info *info,
1660 struct iw_param *frag, char *extra)
1662 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1665 //check if the interface is down
1666 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1668 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1673 val = MAX_FRAG_THRESHOLD;
1674 else if (frag->value >= MIN_FRAG_THRESHOLD || frag->value <= MAX_FRAG_THRESHOLD)
1675 val = __cpu_to_le16(frag->value & ~0x1); /* even numbers only */
1676 else if (frag->value == 0)
1677 val = MAX_FRAG_THRESHOLD;
1681 pAdapter->CommonCfg.FragmentThreshold = val;
1685 int rt_ioctl_giwfrag(struct net_device *dev,
1686 struct iw_request_info *info,
1687 struct iw_param *frag, char *extra)
1690 PRTMP_ADAPTER pAdapter = NULL;
1691 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1693 if (dev->priv_flags == INT_MAIN)
1695 pAdapter = dev->ml_priv;
1699 pVirtualAd = dev->ml_priv;
1700 if (pVirtualAd && pVirtualAd->RtmpDev)
1701 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1704 if (pAdapter == NULL)
1706 /* if 1st open fail, pAd will be free;
1707 So the net_dev->ml_priv will be NULL in 2rd open */
1712 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1715 //check if the interface is down
1716 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1718 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1722 frag->value = pAdapter->CommonCfg.FragmentThreshold;
1723 frag->disabled = (frag->value == MAX_FRAG_THRESHOLD);
1729 #define MAX_WEP_KEY_SIZE 13
1730 #define MIN_WEP_KEY_SIZE 5
1731 int rt_ioctl_siwencode(struct net_device *dev,
1732 struct iw_request_info *info,
1733 struct iw_point *erq, char *extra)
1735 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1737 //check if the interface is down
1738 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1740 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1744 if ((erq->length == 0) &&
1745 (erq->flags & IW_ENCODE_DISABLED))
1747 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
1748 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
1749 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
1750 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
1751 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1755 else if ((erq->length == 0) &&
1756 (erq->flags & IW_ENCODE_RESTRICTED || erq->flags & IW_ENCODE_OPEN))
1759 else if (erq->flags & IW_ENCODE_RESTRICTED || erq->flags & IW_ENCODE_OPEN)
1762 STA_PORT_SECURED(pAdapter);
1763 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
1764 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
1765 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
1766 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
1767 if (erq->flags & IW_ENCODE_RESTRICTED)
1768 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
1770 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1776 if (erq->length > 0)
1778 int keyIdx = (erq->flags & IW_ENCODE_INDEX) - 1;
1779 /* Check the size of the key */
1780 if (erq->length > MAX_WEP_KEY_SIZE)
1784 /* Check key index */
1785 if ((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
1787 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::Wrong keyIdx=%d! Using default key instead (%d)\n",
1788 keyIdx, pAdapter->StaCfg.DefaultKeyId));
1791 keyIdx = pAdapter->StaCfg.DefaultKeyId;
1796 pAdapter->StaCfg.DefaultKeyId=keyIdx;
1800 NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
1802 if (erq->length == MAX_WEP_KEY_SIZE)
1804 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
1805 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
1807 else if (erq->length == MIN_WEP_KEY_SIZE)
1809 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
1810 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
1813 /* Disable the key */
1814 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
1816 /* Check if the key is not marked as invalid */
1817 if(!(erq->flags & IW_ENCODE_NOKEY))
1819 /* Copy the key in the driver */
1820 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, extra, erq->length);
1825 /* Do we want to just set the transmit key index ? */
1826 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
1827 if ((index >= 0) && (index < 4))
1829 pAdapter->StaCfg.DefaultKeyId = index;
1832 /* Don't complain if only change the mode */
1833 if (!(erq->flags & IW_ENCODE_MODE))
1840 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::erq->flags=%x\n",erq->flags));
1841 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::AuthMode=%x\n",pAdapter->StaCfg.AuthMode));
1842 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::DefaultKeyId=%x, KeyLen = %d\n",pAdapter->StaCfg.DefaultKeyId , pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen));
1843 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::WepStatus=%x\n",pAdapter->StaCfg.WepStatus));
1848 rt_ioctl_giwencode(struct net_device *dev,
1849 struct iw_request_info *info,
1850 struct iw_point *erq, char *key)
1853 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1857 PRTMP_ADAPTER pAdapter = NULL;
1858 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1860 if (dev->priv_flags == INT_MAIN)
1862 pAdapter = dev->ml_priv;
1866 pVirtualAd = dev->ml_priv;
1867 if (pVirtualAd && pVirtualAd->RtmpDev)
1868 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1871 if (pAdapter == NULL)
1873 /* if 1st open fail, pAd will be free;
1874 So the net_dev->ml_priv will be NULL in 2rd open */
1879 //check if the interface is down
1880 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1882 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1886 kid = erq->flags & IW_ENCODE_INDEX;
1887 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_giwencode %d\n", erq->flags & IW_ENCODE_INDEX));
1889 if (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled)
1892 erq->flags = IW_ENCODE_DISABLED;
1894 else if ((kid > 0) && (kid <=4))
1897 erq->flags = kid ; /* NB: base 1 */
1898 if (erq->length > pAdapter->SharedKey[BSS0][kid-1].KeyLen)
1899 erq->length = pAdapter->SharedKey[BSS0][kid-1].KeyLen;
1900 memcpy(key, pAdapter->SharedKey[BSS0][kid-1].Key, erq->length);
1901 //if ((kid == pAdapter->PortCfg.DefaultKeyId))
1902 //erq->flags |= IW_ENCODE_ENABLED; /* XXX */
1903 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1904 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1906 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1911 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1912 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1914 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1915 erq->length = pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen;
1916 memcpy(key, pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key, erq->length);
1917 // copy default key ID
1918 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1919 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1921 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1922 erq->flags = pAdapter->StaCfg.DefaultKeyId + 1; /* NB: base 1 */
1923 erq->flags |= IW_ENCODE_ENABLED; /* XXX */
1931 rt_ioctl_setparam(struct net_device *dev, struct iw_request_info *info,
1932 void *w, char *extra)
1934 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1935 PRTMP_ADAPTER pAdapter;
1937 char *this_char = extra;
1941 if (dev->priv_flags == INT_MAIN)
1943 pAdapter = dev->ml_priv;
1947 pVirtualAd = dev->ml_priv;
1948 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1950 pObj = (POS_COOKIE) pAdapter->OS_Cookie;
1952 if (pAdapter == NULL)
1954 /* if 1st open fail, pAd will be free;
1955 So the net_dev->ml_priv will be NULL in 2rd open */
1960 pObj->ioctl_if_type = INT_MAIN;
1961 pObj->ioctl_if = MAIN_MBSSID;
1964 //check if the interface is down
1965 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1967 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1974 if ((value = rtstrchr(this_char, '=')) != NULL)
1980 // reject setting nothing besides ANY ssid(ssidLen=0)
1981 if (!*value && (strcmp(this_char, "SSID") != 0))
1984 for (PRTMP_PRIVATE_SET_PROC = RTMP_PRIVATE_SUPPORT_PROC; PRTMP_PRIVATE_SET_PROC->name; PRTMP_PRIVATE_SET_PROC++)
1986 if (strcmp(this_char, PRTMP_PRIVATE_SET_PROC->name) == 0)
1988 if(!PRTMP_PRIVATE_SET_PROC->set_proc(pAdapter, value))
1989 { //FALSE:Set private failed then return Invalid argument
1992 break; //Exit for loop.
1996 if(PRTMP_PRIVATE_SET_PROC->name == NULL)
1997 { //Not found argument
1999 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_setparam:: (iwpriv) Not Support Set Command [%s=%s]\n", this_char, value));
2007 rt_private_get_statistics(struct net_device *dev, struct iw_request_info *info,
2008 struct iw_point *wrq, char *extra)
2011 PRTMP_ADAPTER pAd = dev->ml_priv;
2019 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2020 sprintf(extra, "\n\n");
2023 sprintf(extra+strlen(extra), "Tx success = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart);
2024 sprintf(extra+strlen(extra), "Tx success without retry = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart - (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
2026 sprintf(extra+strlen(extra), "Tx success after retry = %ld\n", (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
2027 sprintf(extra+strlen(extra), "Tx fail to Rcv ACK after retry = %ld\n", (ULONG)pAd->WlanCounters.FailedCount.QuadPart);
2028 sprintf(extra+strlen(extra), "RTS Success Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSSuccessCount.QuadPart);
2029 sprintf(extra+strlen(extra), "RTS Fail Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSFailureCount.QuadPart);
2031 sprintf(extra+strlen(extra), "Rx success = %ld\n", (ULONG)pAd->WlanCounters.ReceivedFragmentCount.QuadPart);
2032 sprintf(extra+strlen(extra), "Rx with CRC = %ld\n", (ULONG)pAd->WlanCounters.FCSErrorCount.QuadPart);
2033 sprintf(extra+strlen(extra), "Rx drop due to out of resource = %ld\n", (ULONG)pAd->Counters8023.RxNoBuffer);
2034 sprintf(extra+strlen(extra), "Rx duplicate frame = %ld\n", (ULONG)pAd->WlanCounters.FrameDuplicateCount.QuadPart);
2036 sprintf(extra+strlen(extra), "False CCA (one second) = %ld\n", (ULONG)pAd->RalinkCounters.OneSecFalseCCACnt);
2038 sprintf(extra+strlen(extra), "RSSI-A = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi0 - pAd->BbpRssiToDbmDelta));
2039 sprintf(extra+strlen(extra), "RSSI-B (if available) = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi1 - pAd->BbpRssiToDbmDelta));
2040 sprintf(extra+strlen(extra), "RSSI-C (if available) = %ld\n\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi2 - pAd->BbpRssiToDbmDelta));
2042 sprintf(extra+strlen(extra), "WpaSupplicantUP = %d\n\n", pAd->StaCfg.WpaSupplicantUP);
2044 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2045 DBGPRINT(RT_DEBUG_TRACE, ("<== rt_private_get_statistics, wrq->length = %d\n", wrq->length));
2051 IN PRTMP_ADAPTER pAd,
2055 BA_ORI_ENTRY *pOriBAEntry;
2056 BA_REC_ENTRY *pRecBAEntry;
2058 for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
2060 PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
2061 if (((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
2062 || (pEntry->ValidAsWDS) || (pEntry->ValidAsMesh))
2064 sprintf(pOutBuf + strlen(pOutBuf), "\n%02X:%02X:%02X:%02X:%02X:%02X (Aid = %d) (AP) -\n",
2065 pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
2066 pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5], pEntry->Aid);
2068 sprintf(pOutBuf, "%s[Recipient]\n", pOutBuf);
2069 for (j=0; j < NUM_OF_TID; j++)
2071 if (pEntry->BARecWcidArray[j] != 0)
2073 pRecBAEntry =&pAd->BATable.BARecEntry[pEntry->BARecWcidArray[j]];
2074 sprintf(pOutBuf + strlen(pOutBuf), "TID=%d, BAWinSize=%d, LastIndSeq=%d, ReorderingPkts=%d\n", j, pRecBAEntry->BAWinSize, pRecBAEntry->LastIndSeq, pRecBAEntry->list.qlen);
2077 sprintf(pOutBuf, "%s\n", pOutBuf);
2079 sprintf(pOutBuf, "%s[Originator]\n", pOutBuf);
2080 for (j=0; j < NUM_OF_TID; j++)
2082 if (pEntry->BAOriWcidArray[j] != 0)
2084 pOriBAEntry =&pAd->BATable.BAOriEntry[pEntry->BAOriWcidArray[j]];
2085 sprintf(pOutBuf + strlen(pOutBuf), "TID=%d, BAWinSize=%d, StartSeq=%d, CurTxSeq=%d\n", j, pOriBAEntry->BAWinSize, pOriBAEntry->Sequence, pEntry->TxSeq[j]);
2088 sprintf(pOutBuf, "%s\n\n", pOutBuf);
2090 if (strlen(pOutBuf) > (IW_PRIV_SIZE_MASK - 30))
2098 rt_private_show(struct net_device *dev, struct iw_request_info *info,
2099 struct iw_point *wrq, char *extra)
2102 VIRTUAL_ADAPTER *pVirtualAd = NULL;
2105 u32 subcmd = wrq->flags;
2107 if (dev->priv_flags == INT_MAIN)
2111 pVirtualAd = dev->ml_priv;
2112 pAd = pVirtualAd->RtmpDev->ml_priv;
2114 pObj = (POS_COOKIE) pAd->OS_Cookie;
2118 /* if 1st open fail, pAd will be free;
2119 So the net_dev->ml_priv will be NULL in 2rd open */
2128 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2131 pObj->ioctl_if_type = INT_MAIN;
2132 pObj->ioctl_if = MAIN_MBSSID;
2138 case SHOW_CONN_STATUS:
2139 if (MONITOR_ON(pAd))
2141 if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
2142 pAd->CommonCfg.RegTransmitSetting.field.BW)
2143 sprintf(extra, "Monitor Mode(CentralChannel %d)\n", pAd->CommonCfg.CentralChannel);
2145 sprintf(extra, "Monitor Mode(Channel %d)\n", pAd->CommonCfg.Channel);
2149 if (pAd->IndicateMediaState == NdisMediaStateConnected)
2153 sprintf(extra, "Connected(AP: %s[%02X:%02X:%02X:%02X:%02X:%02X])\n",
2154 pAd->CommonCfg.Ssid,
2155 pAd->CommonCfg.Bssid[0],
2156 pAd->CommonCfg.Bssid[1],
2157 pAd->CommonCfg.Bssid[2],
2158 pAd->CommonCfg.Bssid[3],
2159 pAd->CommonCfg.Bssid[4],
2160 pAd->CommonCfg.Bssid[5]);
2161 DBGPRINT(RT_DEBUG_TRACE ,("Ssid=%s ,Ssidlen = %d\n",pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen));
2163 else if (ADHOC_ON(pAd))
2164 sprintf(extra, "Connected\n");
2168 sprintf(extra, "Disconnected\n");
2169 DBGPRINT(RT_DEBUG_TRACE ,("ConnStatus is not connected\n"));
2172 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2174 case SHOW_DRVIER_VERION:
2175 sprintf(extra, "Driver version-%s, %s %s\n", STA_DRIVER_VERSION, __DATE__, __TIME__ );
2176 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2179 getBaInfo(pAd, extra);
2180 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2182 case SHOW_DESC_INFO:
2184 Show_DescInfo_Proc(pAd, NULL);
2185 wrq->length = 0; // 1: size of '\0'
2189 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
2191 sprintf(extra, "Scanning\n");
2192 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2195 pAd->StaCfg.bSwRadio = FALSE;
2196 if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
2198 pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
2199 if (pAd->StaCfg.bRadio == FALSE)
2202 // Update extra information
2203 pAd->ExtraInfo = SW_RADIO_OFF;
2206 sprintf(extra, "Radio Off\n");
2207 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2210 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
2212 sprintf(extra, "Scanning\n");
2213 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2216 pAd->StaCfg.bSwRadio = TRUE;
2217 //if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
2219 pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
2220 if (pAd->StaCfg.bRadio == TRUE)
2223 // Update extra information
2224 pAd->ExtraInfo = EXTRA_INFO_CLEAR;
2227 sprintf(extra, "Radio On\n");
2228 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2231 case SHOW_CFG_VALUE:
2233 Status = RTMPShowCfgValue(pAd, wrq->pointer, extra);
2235 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2239 case SHOW_ADHOC_ENTRY_INFO:
2240 Show_Adhoc_MacTable_Proc(pAd, extra);
2241 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2245 DBGPRINT(RT_DEBUG_TRACE, ("%s - unknow subcmd = %d\n", __func__, subcmd));
2253 int rt_ioctl_siwmlme(struct net_device *dev,
2254 struct iw_request_info *info,
2255 union iwreq_data *wrqu,
2258 PRTMP_ADAPTER pAd = dev->ml_priv;
2259 struct iw_mlme *pMlme = (struct iw_mlme *)wrqu->data.pointer;
2260 MLME_QUEUE_ELEM MsgElem;
2261 MLME_DISASSOC_REQ_STRUCT DisAssocReq;
2262 MLME_DEAUTH_REQ_STRUCT DeAuthReq;
2264 DBGPRINT(RT_DEBUG_TRACE, ("====> %s\n", __func__));
2271 #ifdef IW_MLME_DEAUTH
2272 case IW_MLME_DEAUTH:
2273 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DEAUTH\n", __func__));
2274 COPY_MAC_ADDR(DeAuthReq.Addr, pAd->CommonCfg.Bssid);
2275 DeAuthReq.Reason = pMlme->reason_code;
2276 MsgElem.MsgLen = sizeof(MLME_DEAUTH_REQ_STRUCT);
2277 NdisMoveMemory(MsgElem.Msg, &DeAuthReq, sizeof(MLME_DEAUTH_REQ_STRUCT));
2278 MlmeDeauthReqAction(pAd, &MsgElem);
2281 LinkDown(pAd, FALSE);
2282 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
2285 #endif // IW_MLME_DEAUTH //
2286 #ifdef IW_MLME_DISASSOC
2287 case IW_MLME_DISASSOC:
2288 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DISASSOC\n", __func__));
2289 COPY_MAC_ADDR(DisAssocReq.Addr, pAd->CommonCfg.Bssid);
2290 DisAssocReq.Reason = pMlme->reason_code;
2292 MsgElem.Machine = ASSOC_STATE_MACHINE;
2293 MsgElem.MsgType = MT2_MLME_DISASSOC_REQ;
2294 MsgElem.MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
2295 NdisMoveMemory(MsgElem.Msg, &DisAssocReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
2297 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
2298 MlmeDisassocReqAction(pAd, &MsgElem);
2300 #endif // IW_MLME_DISASSOC //
2302 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - Unknow Command\n", __func__));
2308 #endif // SIOCSIWMLME //
2310 #if WIRELESS_EXT > 17
2311 int rt_ioctl_siwauth(struct net_device *dev,
2312 struct iw_request_info *info,
2313 union iwreq_data *wrqu, char *extra)
2315 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2316 struct iw_param *param = &wrqu->param;
2318 //check if the interface is down
2319 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2321 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2324 switch (param->flags & IW_AUTH_INDEX) {
2325 case IW_AUTH_WPA_VERSION:
2326 if (param->value == IW_AUTH_WPA_VERSION_WPA)
2328 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
2329 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
2330 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
2332 else if (param->value == IW_AUTH_WPA_VERSION_WPA2)
2333 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
2335 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __func__, param->value));
2337 case IW_AUTH_CIPHER_PAIRWISE:
2338 if (param->value == IW_AUTH_CIPHER_NONE)
2340 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
2341 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2342 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
2344 else if (param->value == IW_AUTH_CIPHER_WEP40 ||
2345 param->value == IW_AUTH_CIPHER_WEP104)
2347 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
2348 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2349 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
2350 pAdapter->StaCfg.IEEE8021X = FALSE;
2352 else if (param->value == IW_AUTH_CIPHER_TKIP)
2354 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
2355 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2356 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
2358 else if (param->value == IW_AUTH_CIPHER_CCMP)
2360 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
2361 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2362 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
2364 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_PAIRWISE - param->value = %d!\n", __func__, param->value));
2366 case IW_AUTH_CIPHER_GROUP:
2367 if (param->value == IW_AUTH_CIPHER_NONE)
2369 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
2371 else if (param->value == IW_AUTH_CIPHER_WEP40 ||
2372 param->value == IW_AUTH_CIPHER_WEP104)
2374 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
2376 else if (param->value == IW_AUTH_CIPHER_TKIP)
2378 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
2380 else if (param->value == IW_AUTH_CIPHER_CCMP)
2382 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
2384 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_GROUP - param->value = %d!\n", __func__, param->value));
2386 case IW_AUTH_KEY_MGMT:
2387 if (param->value == IW_AUTH_KEY_MGMT_802_1X)
2389 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)
2391 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
2392 pAdapter->StaCfg.IEEE8021X = FALSE;
2394 else if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
2396 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
2397 pAdapter->StaCfg.IEEE8021X = FALSE;
2401 pAdapter->StaCfg.IEEE8021X = TRUE;
2403 else if (param->value == 0)
2405 STA_PORT_SECURED(pAdapter);
2407 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_KEY_MGMT - param->value = %d!\n", __func__, param->value));
2409 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
2411 case IW_AUTH_PRIVACY_INVOKED:
2412 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_PRIVACY_INVOKED - param->value = %d!\n", __func__, param->value));
2414 case IW_AUTH_DROP_UNENCRYPTED:
2415 if (param->value != 0)
2416 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
2419 STA_PORT_SECURED(pAdapter);
2421 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __func__, param->value));
2423 case IW_AUTH_80211_AUTH_ALG:
2424 if (param->value & IW_AUTH_ALG_SHARED_KEY)
2426 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
2428 else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
2430 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
2434 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_80211_AUTH_ALG - param->value = %d!\n", __func__, param->value));
2436 case IW_AUTH_WPA_ENABLED:
2437 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_ENABLED - Driver supports WPA!(param->value = %d)\n", __func__, param->value));
2446 int rt_ioctl_giwauth(struct net_device *dev,
2447 struct iw_request_info *info,
2448 union iwreq_data *wrqu, char *extra)
2450 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2451 struct iw_param *param = &wrqu->param;
2453 //check if the interface is down
2454 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2456 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2460 switch (param->flags & IW_AUTH_INDEX) {
2461 case IW_AUTH_DROP_UNENCRYPTED:
2462 param->value = (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled) ? 0 : 1;
2465 case IW_AUTH_80211_AUTH_ALG:
2466 param->value = (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared) ? IW_AUTH_ALG_SHARED_KEY : IW_AUTH_ALG_OPEN_SYSTEM;
2469 case IW_AUTH_WPA_ENABLED:
2470 param->value = (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) ? 1 : 0;
2476 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_giwauth::param->value = %d!\n", param->value));
2480 void fnSetCipherKey(
2481 IN PRTMP_ADAPTER pAdapter,
2485 IN struct iw_encode_ext *ext)
2487 NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
2488 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = LEN_TKIP_EK;
2489 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, LEN_TKIP_EK);
2490 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].TxMic, ext->key + LEN_TKIP_EK, LEN_TKIP_TXMICK);
2491 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].RxMic, ext->key + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
2492 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CipherAlg;
2494 // Update group key information to ASIC Shared Key Table
2495 AsicAddSharedKeyEntry(pAdapter,
2498 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2499 pAdapter->SharedKey[BSS0][keyIdx].Key,
2500 pAdapter->SharedKey[BSS0][keyIdx].TxMic,
2501 pAdapter->SharedKey[BSS0][keyIdx].RxMic);
2504 // Update ASIC WCID attribute table and IVEIV table
2505 RTMPAddWcidAttributeEntry(pAdapter,
2508 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2511 // Update ASIC WCID attribute table and IVEIV table
2512 RTMPAddWcidAttributeEntry(pAdapter,
2515 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2516 &pAdapter->MacTab.Content[BSSID_WCID]);
2519 int rt_ioctl_siwencodeext(struct net_device *dev,
2520 struct iw_request_info *info,
2521 union iwreq_data *wrqu,
2524 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2525 struct iw_point *encoding = &wrqu->encoding;
2526 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2527 int keyIdx, alg = ext->alg;
2529 //check if the interface is down
2530 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2532 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2536 if (encoding->flags & IW_ENCODE_DISABLED)
2538 keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
2539 // set BSSID wcid entry of the Pair-wise Key table as no-security mode
2540 AsicRemovePairwiseKeyEntry(pAdapter, BSS0, BSSID_WCID);
2541 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
2542 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_NONE;
2543 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)keyIdx);
2544 NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
2545 DBGPRINT(RT_DEBUG_TRACE, ("%s::Remove all keys!(encoding->flags = %x)\n", __func__, encoding->flags));
2549 // Get Key Index and convet to our own defined key index
2550 keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
2551 if((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
2554 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2556 pAdapter->StaCfg.DefaultKeyId = keyIdx;
2557 DBGPRINT(RT_DEBUG_TRACE, ("%s::DefaultKeyId = %d\n", __func__, pAdapter->StaCfg.DefaultKeyId));
2561 case IW_ENCODE_ALG_NONE:
2562 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_NONE\n", __func__));
2564 case IW_ENCODE_ALG_WEP:
2565 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_WEP - ext->key_len = %d, keyIdx = %d\n", __func__, ext->key_len, keyIdx));
2566 if (ext->key_len == MAX_WEP_KEY_SIZE)
2568 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
2569 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
2571 else if (ext->key_len == MIN_WEP_KEY_SIZE)
2573 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
2574 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
2579 NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
2580 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, ext->key_len);
2582 if (pAdapter->StaCfg.GroupCipher == Ndis802_11GroupWEP40Enabled ||
2583 pAdapter->StaCfg.GroupCipher == Ndis802_11GroupWEP104Enabled)
2585 // Set Group key material to Asic
2586 AsicAddSharedKeyEntry(pAdapter, BSS0, keyIdx, pAdapter->SharedKey[BSS0][keyIdx].CipherAlg, pAdapter->SharedKey[BSS0][keyIdx].Key, NULL, NULL);
2588 // Update WCID attribute table and IVEIV table for this group key table
2589 RTMPAddWcidAttributeEntry(pAdapter, BSS0, keyIdx, pAdapter->SharedKey[BSS0][keyIdx].CipherAlg, NULL);
2591 STA_PORT_SECURED(pAdapter);
2593 // Indicate Connected for GUI
2594 pAdapter->IndicateMediaState = NdisMediaStateConnected;
2598 case IW_ENCODE_ALG_TKIP:
2599 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_TKIP - keyIdx = %d, ext->key_len = %d\n", __func__, keyIdx, ext->key_len));
2600 if (ext->key_len == 32)
2602 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2604 fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, FALSE, ext);
2605 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
2607 STA_PORT_SECURED(pAdapter);
2610 else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
2612 fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, TRUE, ext);
2614 // set 802.1x port control
2615 STA_PORT_SECURED(pAdapter);
2621 case IW_ENCODE_ALG_CCMP:
2622 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2624 fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, FALSE, ext);
2625 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
2626 STA_PORT_SECURED(pAdapter);
2628 else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
2630 fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, TRUE, ext);
2632 // set 802.1x port control
2633 STA_PORT_SECURED(pAdapter);
2645 rt_ioctl_giwencodeext(struct net_device *dev,
2646 struct iw_request_info *info,
2647 union iwreq_data *wrqu, char *extra)
2649 PRTMP_ADAPTER pAd = dev->ml_priv;
2651 struct iw_point *encoding = &wrqu->encoding;
2652 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2653 int idx, max_key_len;
2655 DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_giwencodeext\n"));
2657 max_key_len = encoding->length - sizeof(*ext);
2658 if (max_key_len < 0)
2661 idx = encoding->flags & IW_ENCODE_INDEX;
2664 if (idx < 1 || idx > 4)
2668 if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
2669 (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled))
2671 if (idx != pAd->StaCfg.DefaultKeyId)
2679 idx = pAd->StaCfg.DefaultKeyId;
2681 encoding->flags = idx + 1;
2682 memset(ext, 0, sizeof(*ext));
2685 switch(pAd->StaCfg.WepStatus) {
2686 case Ndis802_11WEPDisabled:
2687 ext->alg = IW_ENCODE_ALG_NONE;
2688 encoding->flags |= IW_ENCODE_DISABLED;
2690 case Ndis802_11WEPEnabled:
2691 ext->alg = IW_ENCODE_ALG_WEP;
2692 if (pAd->SharedKey[BSS0][idx].KeyLen > max_key_len)
2696 ext->key_len = pAd->SharedKey[BSS0][idx].KeyLen;
2697 pKey = &(pAd->SharedKey[BSS0][idx].Key[0]);
2700 case Ndis802_11Encryption2Enabled:
2701 case Ndis802_11Encryption3Enabled:
2702 if (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
2703 ext->alg = IW_ENCODE_ALG_TKIP;
2705 ext->alg = IW_ENCODE_ALG_CCMP;
2707 if (max_key_len < 32)
2712 pKey = &pAd->StaCfg.PMK[0];
2719 if (ext->key_len && pKey)
2721 encoding->flags |= IW_ENCODE_ENABLED;
2722 memcpy(ext->key, pKey, ext->key_len);
2729 int rt_ioctl_siwgenie(struct net_device *dev,
2730 struct iw_request_info *info,
2731 union iwreq_data *wrqu, char *extra)
2733 PRTMP_ADAPTER pAd = dev->ml_priv;
2735 if (wrqu->data.length > MAX_LEN_OF_RSNIE ||
2736 (wrqu->data.length && extra == NULL))
2739 if (wrqu->data.length)
2741 pAd->StaCfg.RSNIE_Len = wrqu->data.length;
2742 NdisMoveMemory(&pAd->StaCfg.RSN_IE[0], extra, pAd->StaCfg.RSNIE_Len);
2746 pAd->StaCfg.RSNIE_Len = 0;
2747 NdisZeroMemory(&pAd->StaCfg.RSN_IE[0], MAX_LEN_OF_RSNIE);
2752 #endif // SIOCSIWGENIE //
2754 int rt_ioctl_giwgenie(struct net_device *dev,
2755 struct iw_request_info *info,
2756 union iwreq_data *wrqu, char *extra)
2758 PRTMP_ADAPTER pAd = dev->ml_priv;
2760 if ((pAd->StaCfg.RSNIE_Len == 0) ||
2761 (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA))
2763 wrqu->data.length = 0;
2768 if (pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
2770 if (wrqu->data.length < pAd->StaCfg.RSNIE_Len)
2773 wrqu->data.length = pAd->StaCfg.RSNIE_Len;
2774 memcpy(extra, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
2777 #endif // SIOCSIWGENIE //
2779 UCHAR RSNIe = IE_WPA;
2781 if (wrqu->data.length < (pAd->StaCfg.RSNIE_Len + 2)) // ID, Len
2783 wrqu->data.length = pAd->StaCfg.RSNIE_Len + 2;
2785 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
2786 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2))
2789 extra[0] = (char)RSNIe;
2790 extra[1] = pAd->StaCfg.RSNIE_Len;
2791 memcpy(extra+2, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
2797 int rt_ioctl_siwpmksa(struct net_device *dev,
2798 struct iw_request_info *info,
2799 union iwreq_data *wrqu,
2802 PRTMP_ADAPTER pAd = dev->ml_priv;
2803 struct iw_pmksa *pPmksa = (struct iw_pmksa *)wrqu->data.pointer;
2804 INT CachedIdx = 0, idx = 0;
2809 DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_siwpmksa\n"));
2812 case IW_PMKSA_FLUSH:
2813 NdisZeroMemory(pAd->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
2814 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_FLUSH\n"));
2816 case IW_PMKSA_REMOVE:
2817 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
2819 // compare the BSSID
2820 if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
2822 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN);
2823 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].PMKID, 16);
2824 for (idx = CachedIdx; idx < (pAd->StaCfg.SavedPMKNum - 1); idx++)
2826 NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].BSSID[0], &pAd->StaCfg.SavedPMK[idx+1].BSSID[0], MAC_ADDR_LEN);
2827 NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].PMKID[0], &pAd->StaCfg.SavedPMK[idx+1].PMKID[0], 16);
2829 pAd->StaCfg.SavedPMKNum--;
2834 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_REMOVE\n"));
2837 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
2839 // compare the BSSID
2840 if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
2844 // Found, replace it
2845 if (CachedIdx < PMKID_NO)
2847 DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
2848 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
2849 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
2850 pAd->StaCfg.SavedPMKNum++;
2852 // Not found, replace the last one
2855 // Randomly replace one
2856 CachedIdx = (pPmksa->bssid.sa_data[5] % PMKID_NO);
2857 DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
2858 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
2859 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
2862 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_ADD\n"));
2865 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - Unknow Command!!\n"));
2871 #endif // #if WIRELESS_EXT > 17
2875 rt_private_ioctl_bbp(struct net_device *dev, struct iw_request_info *info,
2876 struct iw_point *wrq, char *extra)
2883 BOOLEAN bIsPrintAllBBP = FALSE;
2885 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2888 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2890 if (wrq->length > 1) //No parameters.
2892 sprintf(extra, "\n");
2894 //Parsing Read or Write
2895 this_char = wrq->pointer;
2896 DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s\n", this_char));
2900 if ((value = rtstrchr(this_char, '=')) != NULL)
2903 if (!value || !*value)
2905 DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s, value=%s\n", this_char, value));
2906 if (sscanf(this_char, "%d", &(bbpId)) == 1)
2912 if (bbpId <= 138) // edit by johnli, RF power sequence setup, add BBP R138 for ADC dynamic on/off control
2916 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
2918 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
2919 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2920 DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
2923 {//Invalid parametes, so default printk all bbp
2924 bIsPrintAllBBP = TRUE;
2929 { //Invalid parametes, so default printk all bbp
2930 bIsPrintAllBBP = TRUE;
2936 if ((sscanf(this_char, "%d", &(bbpId)) == 1) && (sscanf(value, "%x", &(bbpValue)) == 1))
2942 if (bbpId <= 138) // edit by johnli, RF power sequence setup, add BBP R138 for ADC dynamic on/off control
2946 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, bbpId, bbpValue);
2947 //Read it back for showing
2948 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
2950 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
2951 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2952 DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
2955 {//Invalid parametes, so default printk all bbp
2956 bIsPrintAllBBP = TRUE;
2961 { //Invalid parametes, so default printk all bbp
2962 bIsPrintAllBBP = TRUE;
2968 bIsPrintAllBBP = TRUE;
2973 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2974 sprintf(extra, "\n");
2976 for (bbpId = 0; bbpId <= 136; bbpId++)
2979 for (bbpId = 0; bbpId <= 138; bbpId++) // edit by johnli, RF power sequence setup, add BBP R138 for ADC dynamic on/off control
2982 if (strlen(extra) >= (IW_PRIV_SIZE_MASK - 10))
2984 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
2986 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X ", bbpId, bbpId*2, regBBP);
2988 sprintf(extra+strlen(extra), "\n");
2991 sprintf(extra+strlen(extra), "%03d = %02X\n", bbpId, regBBP); // edit by johnli, change display format
2995 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2996 DBGPRINT(RT_DEBUG_TRACE, ("wrq->length = %d\n", wrq->length));
2999 DBGPRINT(RT_DEBUG_TRACE, ("<==rt_private_ioctl_bbp\n\n"));
3005 int rt_ioctl_siwrate(struct net_device *dev,
3006 struct iw_request_info *info,
3007 union iwreq_data *wrqu, char *extra)
3009 PRTMP_ADAPTER pAd = dev->ml_priv;
3010 UINT32 rate = wrqu->bitrate.value, fixed = wrqu->bitrate.fixed;
3012 //check if the interface is down
3013 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
3015 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::Network is down!\n"));
3019 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(rate = %d, fixed = %d)\n", rate, fixed));
3020 /* rate = -1 => auto rate
3021 rate = X, fixed = 1 => (fixed rate X)
3026 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
3027 pAd->StaCfg.bAutoTxRateSwitch = TRUE;
3028 if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
3029 (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
3030 RTMPSetDesiredRates(pAd, -1);
3038 pAd->StaCfg.bAutoTxRateSwitch = FALSE;
3039 if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
3040 (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
3041 RTMPSetDesiredRates(pAd, rate);
3044 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
3047 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(HtMcs=%d)\n",pAd->StaCfg.DesiredTransmitSetting.field.MCS));
3051 // TODO: rate = X, fixed = 0 => (rates <= X)
3059 int rt_ioctl_giwrate(struct net_device *dev,
3060 struct iw_request_info *info,
3061 union iwreq_data *wrqu, char *extra)
3063 PRTMP_ADAPTER pAd = dev->ml_priv;
3064 int rate_index = 0, rate_count = 0;
3065 HTTRANSMIT_SETTING ht_setting;
3066 __s32 ralinkrate[] =
3067 {2, 4, 11, 22, // CCK
3068 12, 18, 24, 36, 48, 72, 96, 108, // OFDM
3069 13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260, // 20MHz, 800ns GI, MCS: 0 ~ 15
3070 39, 78, 117, 156, 234, 312, 351, 390, // 20MHz, 800ns GI, MCS: 16 ~ 23
3071 27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540, // 40MHz, 800ns GI, MCS: 0 ~ 15
3072 81, 162, 243, 324, 486, 648, 729, 810, // 40MHz, 800ns GI, MCS: 16 ~ 23
3073 14, 29, 43, 57, 87, 115, 130, 144, 29, 59, 87, 115, 173, 230, 260, 288, // 20MHz, 400ns GI, MCS: 0 ~ 15
3074 43, 87, 130, 173, 260, 317, 390, 433, // 20MHz, 400ns GI, MCS: 16 ~ 23
3075 30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600, // 40MHz, 400ns GI, MCS: 0 ~ 15
3076 90, 180, 270, 360, 540, 720, 810, 900}; // 40MHz, 400ns GI, MCS: 16 ~ 23
3078 rate_count = sizeof(ralinkrate)/sizeof(__s32);
3079 //check if the interface is down
3080 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
3082 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
3086 if ((pAd->StaCfg.bAutoTxRateSwitch == FALSE) &&
3088 ((pAd->CommonCfg.PhyMode <= PHY_11G) || (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM)))
3089 ht_setting.word = pAd->StaCfg.HTPhyMode.word;
3091 ht_setting.word = pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word;
3093 if (ht_setting.field.MODE >= MODE_HTMIX)
3095 rate_index = 12 + ((UCHAR)ht_setting.field.BW *24) + ((UCHAR)ht_setting.field.ShortGI *48) + ((UCHAR)ht_setting.field.MCS);
3098 if (ht_setting.field.MODE == MODE_OFDM)
3099 rate_index = (UCHAR)(ht_setting.field.MCS) + 4;
3100 else if (ht_setting.field.MODE == MODE_CCK)
3101 rate_index = (UCHAR)(ht_setting.field.MCS);
3106 if (rate_index > rate_count)
3107 rate_index = rate_count;
3109 wrqu->bitrate.value = ralinkrate[rate_index] * 500000;
3110 wrqu->bitrate.disabled = 0;
3115 static const iw_handler rt_handler[] =
3117 (iw_handler) NULL, /* SIOCSIWCOMMIT */
3118 (iw_handler) rt_ioctl_giwname, /* SIOCGIWNAME */
3119 (iw_handler) NULL, /* SIOCSIWNWID */
3120 (iw_handler) NULL, /* SIOCGIWNWID */
3121 (iw_handler) rt_ioctl_siwfreq, /* SIOCSIWFREQ */
3122 (iw_handler) rt_ioctl_giwfreq, /* SIOCGIWFREQ */
3123 (iw_handler) rt_ioctl_siwmode, /* SIOCSIWMODE */
3124 (iw_handler) rt_ioctl_giwmode, /* SIOCGIWMODE */
3125 (iw_handler) NULL, /* SIOCSIWSENS */
3126 (iw_handler) NULL, /* SIOCGIWSENS */
3127 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
3128 (iw_handler) rt_ioctl_giwrange, /* SIOCGIWRANGE */
3129 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
3130 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
3131 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
3132 (iw_handler) rt28xx_get_wireless_stats /* kernel code */, /* SIOCGIWSTATS */
3133 (iw_handler) NULL, /* SIOCSIWSPY */
3134 (iw_handler) NULL, /* SIOCGIWSPY */
3135 (iw_handler) NULL, /* SIOCSIWTHRSPY */
3136 (iw_handler) NULL, /* SIOCGIWTHRSPY */
3137 (iw_handler) rt_ioctl_siwap, /* SIOCSIWAP */
3138 (iw_handler) rt_ioctl_giwap, /* SIOCGIWAP */
3140 (iw_handler) rt_ioctl_siwmlme, /* SIOCSIWMLME */
3142 (iw_handler) NULL, /* SIOCSIWMLME */
3143 #endif // SIOCSIWMLME //
3144 (iw_handler) rt_ioctl_iwaplist, /* SIOCGIWAPLIST */
3146 (iw_handler) rt_ioctl_siwscan, /* SIOCSIWSCAN */
3147 (iw_handler) rt_ioctl_giwscan, /* SIOCGIWSCAN */
3149 (iw_handler) NULL, /* SIOCSIWSCAN */
3150 (iw_handler) NULL, /* SIOCGIWSCAN */
3151 #endif /* SIOCGIWSCAN */
3152 (iw_handler) rt_ioctl_siwessid, /* SIOCSIWESSID */
3153 (iw_handler) rt_ioctl_giwessid, /* SIOCGIWESSID */
3154 (iw_handler) rt_ioctl_siwnickn, /* SIOCSIWNICKN */
3155 (iw_handler) rt_ioctl_giwnickn, /* SIOCGIWNICKN */
3156 (iw_handler) NULL, /* -- hole -- */
3157 (iw_handler) NULL, /* -- hole -- */
3158 (iw_handler) rt_ioctl_siwrate, /* SIOCSIWRATE */
3159 (iw_handler) rt_ioctl_giwrate, /* SIOCGIWRATE */
3160 (iw_handler) rt_ioctl_siwrts, /* SIOCSIWRTS */
3161 (iw_handler) rt_ioctl_giwrts, /* SIOCGIWRTS */
3162 (iw_handler) rt_ioctl_siwfrag, /* SIOCSIWFRAG */
3163 (iw_handler) rt_ioctl_giwfrag, /* SIOCGIWFRAG */
3164 (iw_handler) NULL, /* SIOCSIWTXPOW */
3165 (iw_handler) NULL, /* SIOCGIWTXPOW */
3166 (iw_handler) NULL, /* SIOCSIWRETRY */
3167 (iw_handler) NULL, /* SIOCGIWRETRY */
3168 (iw_handler) rt_ioctl_siwencode, /* SIOCSIWENCODE */
3169 (iw_handler) rt_ioctl_giwencode, /* SIOCGIWENCODE */
3170 (iw_handler) NULL, /* SIOCSIWPOWER */
3171 (iw_handler) NULL, /* SIOCGIWPOWER */
3172 (iw_handler) NULL, /* -- hole -- */
3173 (iw_handler) NULL, /* -- hole -- */
3174 #if WIRELESS_EXT > 17
3175 (iw_handler) rt_ioctl_siwgenie, /* SIOCSIWGENIE */
3176 (iw_handler) rt_ioctl_giwgenie, /* SIOCGIWGENIE */
3177 (iw_handler) rt_ioctl_siwauth, /* SIOCSIWAUTH */
3178 (iw_handler) rt_ioctl_giwauth, /* SIOCGIWAUTH */
3179 (iw_handler) rt_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
3180 (iw_handler) rt_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */
3181 (iw_handler) rt_ioctl_siwpmksa, /* SIOCSIWPMKSA */
3185 static const iw_handler rt_priv_handlers[] = {
3186 (iw_handler) NULL, /* + 0x00 */
3187 (iw_handler) NULL, /* + 0x01 */
3188 (iw_handler) rt_ioctl_setparam, /* + 0x02 */
3190 (iw_handler) rt_private_ioctl_bbp, /* + 0x03 */
3192 (iw_handler) NULL, /* + 0x03 */
3194 (iw_handler) NULL, /* + 0x04 */
3195 (iw_handler) NULL, /* + 0x05 */
3196 (iw_handler) NULL, /* + 0x06 */
3197 (iw_handler) NULL, /* + 0x07 */
3198 (iw_handler) NULL, /* + 0x08 */
3199 (iw_handler) rt_private_get_statistics, /* + 0x09 */
3200 (iw_handler) NULL, /* + 0x0A */
3201 (iw_handler) NULL, /* + 0x0B */
3202 (iw_handler) NULL, /* + 0x0C */
3203 (iw_handler) NULL, /* + 0x0D */
3204 (iw_handler) NULL, /* + 0x0E */
3205 (iw_handler) NULL, /* + 0x0F */
3206 (iw_handler) NULL, /* + 0x10 */
3207 (iw_handler) rt_private_show, /* + 0x11 */
3208 (iw_handler) NULL, /* + 0x12 */
3209 (iw_handler) NULL, /* + 0x13 */
3210 (iw_handler) NULL, /* + 0x15 */
3211 (iw_handler) NULL, /* + 0x17 */
3212 (iw_handler) NULL, /* + 0x18 */
3215 const struct iw_handler_def rt28xx_iw_handler_def =
3217 #define N(a) (sizeof (a) / sizeof (a[0]))
3218 .standard = (iw_handler *) rt_handler,
3219 .num_standard = sizeof(rt_handler) / sizeof(iw_handler),
3220 .private = (iw_handler *) rt_priv_handlers,
3221 .num_private = N(rt_priv_handlers),
3222 .private_args = (struct iw_priv_args *) privtab,
3223 .num_private_args = N(privtab),
3224 #if IW_HANDLER_VERSION >= 7
3225 .get_wireless_stats = rt28xx_get_wireless_stats,
3229 INT RTMPSetInformation(
3230 IN PRTMP_ADAPTER pAdapter,
3231 IN OUT struct ifreq *rq,
3234 struct iwreq *wrq = (struct iwreq *) rq;
3235 NDIS_802_11_SSID Ssid;
3236 NDIS_802_11_MAC_ADDRESS Bssid;
3237 RT_802_11_PHY_MODE PhyMode;
3238 RT_802_11_STA_CONFIG StaConfig;
3239 NDIS_802_11_RATES aryRates;
3240 RT_802_11_PREAMBLE Preamble;
3241 NDIS_802_11_WEP_STATUS WepStatus;
3242 NDIS_802_11_AUTHENTICATION_MODE AuthMode = Ndis802_11AuthModeMax;
3243 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
3244 NDIS_802_11_RTS_THRESHOLD RtsThresh;
3245 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
3246 NDIS_802_11_POWER_MODE PowerMode;
3247 PNDIS_802_11_KEY pKey = NULL;
3248 PNDIS_802_11_WEP pWepKey =NULL;
3249 PNDIS_802_11_REMOVE_KEY pRemoveKey = NULL;
3250 NDIS_802_11_CONFIGURATION Config, *pConfig = NULL;
3251 NDIS_802_11_NETWORK_TYPE NetType;
3254 INT Status = NDIS_STATUS_SUCCESS, MaxPhyMode = PHY_11G;
3257 BOOLEAN StateMachineTouched = FALSE;
3258 OID_SET_HT_PHYMODE HT_PhyMode; //11n ,kathy
3259 PNDIS_802_11_PMKID pPmkId = NULL;
3260 BOOLEAN IEEE8021xState = FALSE;
3261 BOOLEAN IEEE8021x_required_keys = FALSE;
3262 UCHAR wpa_supplicant_enable = 0;
3264 MaxPhyMode = PHY_11N_5G;
3266 DBGPRINT(RT_DEBUG_TRACE, ("-->RTMPSetInformation(), 0x%08x\n", cmd&0x7FFF));
3267 switch(cmd & 0x7FFF) {
3268 case RT_OID_802_11_COUNTRY_REGION:
3269 if (wrq->u.data.length < sizeof(UCHAR))
3271 // Only avaliable when EEPROM not programming
3272 else if (!(pAdapter->CommonCfg.CountryRegion & 0x80) && !(pAdapter->CommonCfg.CountryRegionForABand & 0x80))
3277 Status = copy_from_user(&Country, wrq->u.data.pointer, wrq->u.data.length);
3278 pAdapter->CommonCfg.CountryRegion = (UCHAR)(Country & 0x000000FF);
3279 pAdapter->CommonCfg.CountryRegionForABand = (UCHAR)((Country >> 8) & 0x000000FF);
3280 TmpPhy = pAdapter->CommonCfg.PhyMode;
3281 pAdapter->CommonCfg.PhyMode = 0xff;
3282 // Build all corresponding channel information
3283 RTMPSetPhyMode(pAdapter, TmpPhy);
3284 SetCommonHT(pAdapter);
3285 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_COUNTRY_REGION (A:%d B/G:%d)\n", pAdapter->CommonCfg.CountryRegionForABand,
3286 pAdapter->CommonCfg.CountryRegion));
3289 case OID_802_11_BSSID_LIST_SCAN:
3291 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID_LIST_SCAN, TxCnt = %d \n", pAdapter->RalinkCounters.LastOneSecTotalTxCount));
3293 if (MONITOR_ON(pAdapter))
3295 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
3299 //Benson add 20080527, when radio off, sta don't need to scan
3300 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_RADIO_OFF))
3303 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
3305 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is scanning now !!!\n"));
3306 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
3307 Status = NDIS_STATUS_SUCCESS;
3311 if (pAdapter->RalinkCounters.LastOneSecTotalTxCount > 100)
3313 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
3314 Status = NDIS_STATUS_SUCCESS;
3315 pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
3319 if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
3320 ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
3321 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
3322 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
3323 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)) &&
3324 (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
3326 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
3327 Status = NDIS_STATUS_SUCCESS;
3328 pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
3333 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3335 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3336 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3339 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
3340 // this request, because this request is initiated by NDIS.
3341 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
3342 // Reset allowed scan retries
3343 pAdapter->StaCfg.ScanCnt = 0;
3344 pAdapter->StaCfg.LastScanTime = Now;
3346 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
3347 RTMP_SET_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
3348 MlmeEnqueue(pAdapter,
3349 MLME_CNTL_STATE_MACHINE,
3350 OID_802_11_BSSID_LIST_SCAN,
3354 Status = NDIS_STATUS_SUCCESS;
3355 StateMachineTouched = TRUE;
3357 case OID_802_11_SSID:
3358 if (wrq->u.data.length != sizeof(NDIS_802_11_SSID))
3362 PCHAR pSsidString = NULL;
3363 Status = copy_from_user(&Ssid, wrq->u.data.pointer, wrq->u.data.length);
3365 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SSID (Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
3366 if (Ssid.SsidLength > MAX_LEN_OF_SSID)
3370 if (Ssid.SsidLength == 0)
3372 Set_SSID_Proc(pAdapter, "");
3376 pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
3379 NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
3380 NdisMoveMemory(pSsidString, Ssid.Ssid, Ssid.SsidLength);
3381 Set_SSID_Proc(pAdapter, pSsidString);
3390 case OID_802_11_BSSID:
3391 if (wrq->u.data.length != sizeof(NDIS_802_11_MAC_ADDRESS))
3395 Status = copy_from_user(&Bssid, wrq->u.data.pointer, wrq->u.data.length);
3397 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
3398 // this request, because this request is initiated by NDIS.
3399 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
3401 // Prevent to connect AP again in STAMlmePeriodicExec
3402 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
3404 // Reset allowed scan retries
3405 pAdapter->StaCfg.ScanCnt = 0;
3407 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3409 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3410 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3412 MlmeEnqueue(pAdapter,
3413 MLME_CNTL_STATE_MACHINE,
3415 sizeof(NDIS_802_11_MAC_ADDRESS),
3417 Status = NDIS_STATUS_SUCCESS;
3418 StateMachineTouched = TRUE;
3420 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID %02x:%02x:%02x:%02x:%02x:%02x\n",
3421 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
3424 case RT_OID_802_11_RADIO:
3425 if (wrq->u.data.length != sizeof(BOOLEAN))
3429 Status = copy_from_user(&RadioState, wrq->u.data.pointer, wrq->u.data.length);
3430 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RADIO (=%d)\n", RadioState));
3431 if (pAdapter->StaCfg.bSwRadio != RadioState)
3433 pAdapter->StaCfg.bSwRadio = RadioState;
3434 if (pAdapter->StaCfg.bRadio != (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio))
3436 pAdapter->StaCfg.bRadio = (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio);
3437 if (pAdapter->StaCfg.bRadio == TRUE)
3439 MlmeRadioOn(pAdapter);
3440 // Update extra information
3441 pAdapter->ExtraInfo = EXTRA_INFO_CLEAR;
3445 MlmeRadioOff(pAdapter);
3446 // Update extra information
3447 pAdapter->ExtraInfo = SW_RADIO_OFF;
3453 case RT_OID_802_11_PHY_MODE:
3454 if (wrq->u.data.length != sizeof(RT_802_11_PHY_MODE))
3458 Status = copy_from_user(&PhyMode, wrq->u.data.pointer, wrq->u.data.length);
3459 if (PhyMode <= MaxPhyMode)
3461 RTMPSetPhyMode(pAdapter, PhyMode);
3462 SetCommonHT(pAdapter);
3464 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PHY_MODE (=%d)\n", PhyMode));
3467 case RT_OID_802_11_STA_CONFIG:
3468 if (wrq->u.data.length != sizeof(RT_802_11_STA_CONFIG))
3472 Status = copy_from_user(&StaConfig, wrq->u.data.pointer, wrq->u.data.length);
3473 pAdapter->CommonCfg.bEnableTxBurst = StaConfig.EnableTxBurst;
3474 pAdapter->CommonCfg.UseBGProtection = StaConfig.UseBGProtection;
3475 pAdapter->CommonCfg.bUseShortSlotTime = 1; // 2003-10-30 always SHORT SLOT capable
3476 if ((pAdapter->CommonCfg.PhyMode != StaConfig.AdhocMode) &&
3477 (StaConfig.AdhocMode <= MaxPhyMode))
3479 // allow dynamic change of "USE OFDM rate or not" in ADHOC mode
3480 // if setting changed, need to reset current TX rate as well as BEACON frame format
3482 pAdapter->CommonCfg.PhyMode = StaConfig.AdhocMode;
3484 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
3487 pAdapter->CommonCfg.PhyMode = StaConfig.AdhocMode;
3489 RTMPSetPhyMode(pAdapter, PhyMode);
3490 MlmeUpdateTxRates(pAdapter, FALSE, 0);
3491 MakeIbssBeacon(pAdapter); // re-build BEACON frame
3492 AsicEnableIbssSync(pAdapter); // copy to on-chip memory
3495 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_STA_CONFIG (Burst=%d, Protection=%ld,ShortSlot=%d\n",
3496 pAdapter->CommonCfg.bEnableTxBurst,
3497 pAdapter->CommonCfg.UseBGProtection,
3498 pAdapter->CommonCfg.bUseShortSlotTime));
3501 case OID_802_11_DESIRED_RATES:
3502 if (wrq->u.data.length != sizeof(NDIS_802_11_RATES))
3506 Status = copy_from_user(&aryRates, wrq->u.data.pointer, wrq->u.data.length);
3507 NdisZeroMemory(pAdapter->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES);
3508 NdisMoveMemory(pAdapter->CommonCfg.DesireRate, &aryRates, sizeof(NDIS_802_11_RATES));
3509 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DESIRED_RATES (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
3510 pAdapter->CommonCfg.DesireRate[0],pAdapter->CommonCfg.DesireRate[1],
3511 pAdapter->CommonCfg.DesireRate[2],pAdapter->CommonCfg.DesireRate[3],
3512 pAdapter->CommonCfg.DesireRate[4],pAdapter->CommonCfg.DesireRate[5],
3513 pAdapter->CommonCfg.DesireRate[6],pAdapter->CommonCfg.DesireRate[7] ));
3514 // Changing DesiredRate may affect the MAX TX rate we used to TX frames out
3515 MlmeUpdateTxRates(pAdapter, FALSE, 0);
3518 case RT_OID_802_11_PREAMBLE:
3519 if (wrq->u.data.length != sizeof(RT_802_11_PREAMBLE))
3523 Status = copy_from_user(&Preamble, wrq->u.data.pointer, wrq->u.data.length);
3524 if (Preamble == Rt802_11PreambleShort)
3526 pAdapter->CommonCfg.TxPreamble = Preamble;
3527 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleShort);
3529 else if ((Preamble == Rt802_11PreambleLong) || (Preamble == Rt802_11PreambleAuto))
3531 // if user wants AUTO, initialize to LONG here, then change according to AP's
3532 // capability upon association.
3533 pAdapter->CommonCfg.TxPreamble = Preamble;
3534 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleLong);
3541 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PREAMBLE (=%d)\n", Preamble));
3544 case OID_802_11_WEP_STATUS:
3545 if (wrq->u.data.length != sizeof(NDIS_802_11_WEP_STATUS))
3549 Status = copy_from_user(&WepStatus, wrq->u.data.pointer, wrq->u.data.length);
3550 // Since TKIP, AES, WEP are all supported. It should not have any invalid setting
3551 if (WepStatus <= Ndis802_11Encryption3KeyAbsent)
3553 if (pAdapter->StaCfg.WepStatus != WepStatus)
3555 // Config has changed
3556 pAdapter->bConfigChanged = TRUE;
3558 pAdapter->StaCfg.WepStatus = WepStatus;
3559 pAdapter->StaCfg.OrigWepStatus = WepStatus;
3560 pAdapter->StaCfg.PairCipher = WepStatus;
3561 pAdapter->StaCfg.GroupCipher = WepStatus;
3568 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEP_STATUS (=%d)\n",WepStatus));
3571 case OID_802_11_AUTHENTICATION_MODE:
3572 if (wrq->u.data.length != sizeof(NDIS_802_11_AUTHENTICATION_MODE))
3576 Status = copy_from_user(&AuthMode, wrq->u.data.pointer, wrq->u.data.length);
3577 if (AuthMode > Ndis802_11AuthModeMax)
3584 if (pAdapter->StaCfg.AuthMode != AuthMode)
3586 // Config has changed
3587 pAdapter->bConfigChanged = TRUE;
3589 pAdapter->StaCfg.AuthMode = AuthMode;
3591 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
3592 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_AUTHENTICATION_MODE (=%d) \n",pAdapter->StaCfg.AuthMode));
3595 case OID_802_11_INFRASTRUCTURE_MODE:
3596 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_INFRASTRUCTURE))
3600 Status = copy_from_user(&BssType, wrq->u.data.pointer, wrq->u.data.length);
3602 if (BssType == Ndis802_11IBSS)
3603 Set_NetworkType_Proc(pAdapter, "Adhoc");
3604 else if (BssType == Ndis802_11Infrastructure)
3605 Set_NetworkType_Proc(pAdapter, "Infra");
3606 else if (BssType == Ndis802_11Monitor)
3607 Set_NetworkType_Proc(pAdapter, "Monitor");
3611 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_INFRASTRUCTURE_MODE (unknown)\n"));
3615 case OID_802_11_REMOVE_WEP:
3616 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_WEP\n"));
3617 if (wrq->u.data.length != sizeof(NDIS_802_11_KEY_INDEX))
3623 KeyIdx = *(NDIS_802_11_KEY_INDEX *) wrq->u.data.pointer;
3625 if (KeyIdx & 0x80000000)
3627 // Should never set default bit when remove key
3632 KeyIdx = KeyIdx & 0x0fffffff;
3638 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
3639 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
3640 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
3645 case RT_OID_802_11_RESET_COUNTERS:
3646 NdisZeroMemory(&pAdapter->WlanCounters, sizeof(COUNTER_802_11));
3647 NdisZeroMemory(&pAdapter->Counters8023, sizeof(COUNTER_802_3));
3648 NdisZeroMemory(&pAdapter->RalinkCounters, sizeof(COUNTER_RALINK));
3649 pAdapter->Counters8023.RxNoBuffer = 0;
3650 pAdapter->Counters8023.GoodReceives = 0;
3651 pAdapter->Counters8023.RxNoBuffer = 0;
3653 pAdapter->BulkOutComplete = 0;
3654 pAdapter->BulkOutCompleteOther= 0;
3655 pAdapter->BulkOutCompleteCancel = 0;
3656 pAdapter->BulkOutReq = 0;
3657 pAdapter->BulkInReq= 0;
3658 pAdapter->BulkInComplete = 0;
3659 pAdapter->BulkInCompleteFail = 0;
3661 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RESET_COUNTERS \n"));
3663 case OID_802_11_RTS_THRESHOLD:
3664 if (wrq->u.data.length != sizeof(NDIS_802_11_RTS_THRESHOLD))
3668 Status = copy_from_user(&RtsThresh, wrq->u.data.pointer, wrq->u.data.length);
3669 if (RtsThresh > MAX_RTS_THRESHOLD)
3672 pAdapter->CommonCfg.RtsThreshold = (USHORT)RtsThresh;
3674 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_RTS_THRESHOLD (=%ld)\n",RtsThresh));
3676 case OID_802_11_FRAGMENTATION_THRESHOLD:
3677 if (wrq->u.data.length != sizeof(NDIS_802_11_FRAGMENTATION_THRESHOLD))
3681 Status = copy_from_user(&FragThresh, wrq->u.data.pointer, wrq->u.data.length);
3682 pAdapter->CommonCfg.bUseZeroToDisableFragment = FALSE;
3683 if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
3685 if (FragThresh == 0)
3687 pAdapter->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
3688 pAdapter->CommonCfg.bUseZeroToDisableFragment = TRUE;
3694 pAdapter->CommonCfg.FragmentThreshold = (USHORT)FragThresh;
3696 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_FRAGMENTATION_THRESHOLD (=%ld) \n",FragThresh));
3698 case OID_802_11_POWER_MODE:
3699 if (wrq->u.data.length != sizeof(NDIS_802_11_POWER_MODE))
3703 Status = copy_from_user(&PowerMode, wrq->u.data.pointer, wrq->u.data.length);
3704 if (PowerMode == Ndis802_11PowerModeCAM)
3705 Set_PSMode_Proc(pAdapter, "CAM");
3706 else if (PowerMode == Ndis802_11PowerModeMAX_PSP)
3707 Set_PSMode_Proc(pAdapter, "Max_PSP");
3708 else if (PowerMode == Ndis802_11PowerModeFast_PSP)
3709 Set_PSMode_Proc(pAdapter, "Fast_PSP");
3710 else if (PowerMode == Ndis802_11PowerModeLegacy_PSP)
3711 Set_PSMode_Proc(pAdapter, "Legacy_PSP");
3715 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_POWER_MODE (=%d)\n",PowerMode));
3717 case RT_OID_802_11_TX_POWER_LEVEL_1:
3718 if (wrq->u.data.length < sizeof(ULONG))
3722 Status = copy_from_user(&PowerTemp, wrq->u.data.pointer, wrq->u.data.length);
3723 if (PowerTemp > 100)
3724 PowerTemp = 0xffffffff; // AUTO
3725 pAdapter->CommonCfg.TxPowerDefault = PowerTemp; //keep current setting.
3726 pAdapter->CommonCfg.TxPowerPercentage = pAdapter->CommonCfg.TxPowerDefault;
3727 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
3730 case OID_802_11_NETWORK_TYPE_IN_USE:
3731 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_TYPE))
3735 Status = copy_from_user(&NetType, wrq->u.data.pointer, wrq->u.data.length);
3737 if (NetType == Ndis802_11DS)
3738 RTMPSetPhyMode(pAdapter, PHY_11B);
3739 else if (NetType == Ndis802_11OFDM24)
3740 RTMPSetPhyMode(pAdapter, PHY_11BG_MIXED);
3741 else if (NetType == Ndis802_11OFDM5)
3742 RTMPSetPhyMode(pAdapter, PHY_11A);
3746 if (Status == NDIS_STATUS_SUCCESS)
3747 SetCommonHT(pAdapter);
3749 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_NETWORK_TYPE_IN_USE (=%d)\n",NetType));
3752 // For WPA PSK PMK key
3753 case RT_OID_802_11_ADD_WPA:
3754 pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3761 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
3762 if (pKey->Length != wrq->u.data.length)
3765 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!!\n"));
3769 if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
3770 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
3771 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone) )
3773 Status = -EOPNOTSUPP;
3774 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!! [AuthMode != WPAPSK/WPA2PSK/WPANONE]\n"));
3776 else if ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
3777 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
3778 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) ) // Only for WPA PSK mode
3780 NdisMoveMemory(pAdapter->StaCfg.PMK, &pKey->KeyMaterial, pKey->KeyLength);
3781 // Use RaConfig as PSK agent.
3782 // Start STA supplicant state machine
3783 if (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
3784 pAdapter->StaCfg.WpaState = SS_START;
3786 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3790 pAdapter->StaCfg.WpaState = SS_NOTUSE;
3791 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3796 case OID_802_11_REMOVE_KEY:
3797 pRemoveKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3798 if(pRemoveKey == NULL)
3804 Status = copy_from_user(pRemoveKey, wrq->u.data.pointer, wrq->u.data.length);
3805 if (pRemoveKey->Length != wrq->u.data.length)
3808 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!\n"));
3812 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3814 RTMPWPARemoveKeyProc(pAdapter, pRemoveKey);
3815 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Remove WPA Key!!\n"));
3819 KeyIdx = pRemoveKey->KeyIndex;
3821 if (KeyIdx & 0x80000000)
3823 // Should never set default bit when remove key
3825 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(Should never set default bit when remove key)\n"));
3829 KeyIdx = KeyIdx & 0x0fffffff;
3833 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(KeyId[%d] out of range)\n", KeyIdx));
3837 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
3838 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
3839 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
3840 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY (id=0x%x, Len=%d-byte)\n", pRemoveKey->KeyIndex, pRemoveKey->Length));
3848 case OID_802_11_ADD_KEY:
3849 pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3855 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
3856 if (pKey->Length != wrq->u.data.length)
3859 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY, Failed!!\n"));
3863 RTMPAddKey(pAdapter, pKey);
3864 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3868 case OID_802_11_CONFIGURATION:
3869 if (wrq->u.data.length != sizeof(NDIS_802_11_CONFIGURATION))
3873 Status = copy_from_user(&Config, wrq->u.data.pointer, wrq->u.data.length);
3876 if ((pConfig->BeaconPeriod >= 20) && (pConfig->BeaconPeriod <=400))
3877 pAdapter->CommonCfg.BeaconPeriod = (USHORT) pConfig->BeaconPeriod;
3879 pAdapter->StaActive.AtimWin = (USHORT) pConfig->ATIMWindow;
3880 MAP_KHZ_TO_CHANNEL_ID(pConfig->DSConfig, pAdapter->CommonCfg.Channel);
3882 // Save the channel on MlmeAux for CntlOidRTBssidProc used.
3884 pAdapter->MlmeAux.Channel = pAdapter->CommonCfg.Channel;
3886 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_CONFIGURATION (BeacnPeriod=%ld,AtimW=%ld,Ch=%d)\n",
3887 pConfig->BeaconPeriod, pConfig->ATIMWindow, pAdapter->CommonCfg.Channel));
3888 // Config has changed
3889 pAdapter->bConfigChanged = TRUE;
3892 case RT_OID_802_11_SET_HT_PHYMODE:
3893 if (wrq->u.data.length != sizeof(OID_SET_HT_PHYMODE))
3897 POID_SET_HT_PHYMODE pHTPhyMode = &HT_PhyMode;
3899 Status = copy_from_user(&HT_PhyMode, wrq->u.data.pointer, wrq->u.data.length);
3900 DBGPRINT(RT_DEBUG_TRACE, ("Set::pHTPhyMode (PhyMode = %d,TransmitNo = %d, HtMode = %d, ExtOffset = %d , MCS = %d, BW = %d, STBC = %d, SHORTGI = %d) \n",
3901 pHTPhyMode->PhyMode, pHTPhyMode->TransmitNo,pHTPhyMode->HtMode,pHTPhyMode->ExtOffset,
3902 pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->SHORTGI));
3903 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
3904 RTMPSetHT(pAdapter, pHTPhyMode);
3906 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_HT_PHYMODE(MCS=%d,BW=%d,SGI=%d,STBC=%d)\n",
3907 pAdapter->StaCfg.HTPhyMode.field.MCS, pAdapter->StaCfg.HTPhyMode.field.BW, pAdapter->StaCfg.HTPhyMode.field.ShortGI,
3908 pAdapter->StaCfg.HTPhyMode.field.STBC));
3910 case RT_OID_802_11_SET_APSD_SETTING:
3911 if (wrq->u.data.length != sizeof(ULONG))
3916 Status = copy_from_user(&apsd, wrq->u.data.pointer, wrq->u.data.length);
3918 /*-------------------------------------------------------------------
3919 |B31~B7 | B6~B5 | B4 | B3 | B2 | B1 | B0 |
3920 ---------------------------------------------------------------------
3921 | Rsvd | Max SP Len | AC_VO | AC_VI | AC_BK | AC_BE | APSD Capable |
3922 ---------------------------------------------------------------------*/
3923 pAdapter->CommonCfg.bAPSDCapable = (apsd & 0x00000001) ? TRUE : FALSE;
3924 pAdapter->CommonCfg.bAPSDAC_BE = ((apsd & 0x00000002) >> 1) ? TRUE : FALSE;
3925 pAdapter->CommonCfg.bAPSDAC_BK = ((apsd & 0x00000004) >> 2) ? TRUE : FALSE;
3926 pAdapter->CommonCfg.bAPSDAC_VI = ((apsd & 0x00000008) >> 3) ? TRUE : FALSE;
3927 pAdapter->CommonCfg.bAPSDAC_VO = ((apsd & 0x00000010) >> 4) ? TRUE : FALSE;
3928 pAdapter->CommonCfg.MaxSPLength = (UCHAR)((apsd & 0x00000060) >> 5);
3930 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,
3931 pAdapter->CommonCfg.bAPSDAC_BE, pAdapter->CommonCfg.bAPSDAC_BK, pAdapter->CommonCfg.bAPSDAC_VI, pAdapter->CommonCfg.bAPSDAC_VO, pAdapter->CommonCfg.MaxSPLength));
3935 case RT_OID_802_11_SET_APSD_PSM:
3936 if (wrq->u.data.length != sizeof(ULONG))
3940 // Driver needs to notify AP when PSM changes
3941 Status = copy_from_user(&pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.pointer, wrq->u.data.length);
3942 if (pAdapter->CommonCfg.bAPSDForcePowerSave != pAdapter->StaCfg.Psm)
3944 MlmeSetPsmBit(pAdapter, pAdapter->CommonCfg.bAPSDForcePowerSave);
3945 RTMPSendNullFrame(pAdapter, pAdapter->CommonCfg.TxRate, TRUE);
3947 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_APSD_PSM (bAPSDForcePowerSave:%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
3951 case RT_OID_802_11_SET_WMM:
3952 if (wrq->u.data.length != sizeof(BOOLEAN))
3956 Status = copy_from_user(&pAdapter->CommonCfg.bWmmCapable, wrq->u.data.pointer, wrq->u.data.length);
3957 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_WMM (=%d) \n", pAdapter->CommonCfg.bWmmCapable));
3961 case OID_802_11_DISASSOCIATE:
3963 // Set NdisRadioStateOff to TRUE, instead of called MlmeRadioOff.
3964 // Later on, NDIS_802_11_BSSID_LIST_EX->NumberOfItems should be 0
3965 // when query OID_802_11_BSSID_LIST.
3967 // TRUE: NumberOfItems will set to 0.
3968 // FALSE: NumberOfItems no change.
3970 pAdapter->CommonCfg.NdisRadioStateOff = TRUE;
3971 // Set to immediately send the media disconnect event
3972 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
3973 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DISASSOCIATE \n"));
3975 if (INFRA_ON(pAdapter))
3977 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3979 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3980 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3983 MlmeEnqueue(pAdapter,
3984 MLME_CNTL_STATE_MACHINE,
3985 OID_802_11_DISASSOCIATE,
3989 StateMachineTouched = TRUE;
3992 case RT_OID_802_11_SET_IMME_BA_CAP:
3993 if (wrq->u.data.length != sizeof(OID_BACAP_STRUC))
3997 OID_BACAP_STRUC Orde ;
3998 Status = copy_from_user(&Orde, wrq->u.data.pointer, wrq->u.data.length);
3999 if (Orde.Policy > BA_NOTUSE)
4001 Status = NDIS_STATUS_INVALID_DATA;
4003 else if (Orde.Policy == BA_NOTUSE)
4005 pAdapter->CommonCfg.BACapability.field.Policy = BA_NOTUSE;
4006 pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
4007 pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
4008 pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
4009 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
4010 pAdapter->CommonCfg.DesiredHtPhy.MimoPs= Orde.MMPSmode;
4011 pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
4013 pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
4014 pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
4015 pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
4019 pAdapter->CommonCfg.BACapability.field.AutoBA = Orde.AutoBA;
4020 pAdapter->CommonCfg.BACapability.field.Policy = IMMED_BA; // we only support immediate BA.
4021 pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
4022 pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
4023 pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
4024 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
4025 pAdapter->CommonCfg.DesiredHtPhy.MimoPs = Orde.MMPSmode;
4026 pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
4029 pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
4030 pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
4031 pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
4033 if (pAdapter->CommonCfg.BACapability.field.RxBAWinLimit > MAX_RX_REORDERBUF)
4034 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = MAX_RX_REORDERBUF;
4038 pAdapter->CommonCfg.REGBACapability.word = pAdapter->CommonCfg.BACapability.word;
4039 DBGPRINT(RT_DEBUG_TRACE, ("Set::(Orde.AutoBA = %d) (Policy=%d)(ReBAWinLimit=%d)(TxBAWinLimit=%d)(AutoMode=%d)\n",Orde.AutoBA, pAdapter->CommonCfg.BACapability.field.Policy,
4040 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit,pAdapter->CommonCfg.BACapability.field.TxBAWinLimit, pAdapter->CommonCfg.BACapability.field.AutoBA));
4041 DBGPRINT(RT_DEBUG_TRACE, ("Set::(MimoPs = %d)(AmsduEnable = %d) (AmsduSize=%d)(MpduDensity=%d)\n",pAdapter->CommonCfg.DesiredHtPhy.MimoPs, pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable,
4042 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize, pAdapter->CommonCfg.DesiredHtPhy.MpduDensity));
4046 case RT_OID_802_11_ADD_IMME_BA:
4047 DBGPRINT(RT_DEBUG_TRACE, (" Set :: RT_OID_802_11_ADD_IMME_BA \n"));
4048 if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
4053 OID_ADD_BA_ENTRY BA;
4054 MAC_TABLE_ENTRY *pEntry;
4056 Status = copy_from_user(&BA, wrq->u.data.pointer, wrq->u.data.length);
4059 Status = NDIS_STATUS_INVALID_DATA;
4064 //BATableInsertEntry
4065 //As ad-hoc mode, BA pair is not limited to only BSSID. so add via OID.
4067 // in ad hoc mode, when adding BA pair, we should insert this entry into MACEntry too
4068 pEntry = MacTableLookup(pAdapter, BA.MACAddr);
4071 DBGPRINT(RT_DEBUG_TRACE, ("RT_OID_802_11_ADD_IMME_BA. break on no connection.----:%x:%x\n", BA.MACAddr[4], BA.MACAddr[5]));
4074 if (BA.IsRecipient == FALSE)
4076 if (pEntry->bIAmBadAtheros == TRUE)
4077 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = 0x10;
4079 BAOriSessionSetUp(pAdapter, pEntry, index, 0, 100, TRUE);
4083 //BATableInsertEntry(pAdapter, pEntry->Aid, BA.MACAddr, 0, 0xffff, BA.TID, BA.nMSDU, BA.IsRecipient);
4086 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_IMME_BA. Rec = %d. Mac = %x:%x:%x:%x:%x:%x . \n",
4087 BA.IsRecipient, BA.MACAddr[0], BA.MACAddr[1], BA.MACAddr[2], BA.MACAddr[2]
4088 , BA.MACAddr[4], BA.MACAddr[5]));
4093 case RT_OID_802_11_TEAR_IMME_BA:
4094 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA \n"));
4095 if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
4099 POID_ADD_BA_ENTRY pBA;
4100 MAC_TABLE_ENTRY *pEntry;
4102 pBA = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4106 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA kmalloc() can't allocate enough memory\n"));
4107 Status = NDIS_STATUS_FAILURE;
4111 Status = copy_from_user(pBA, wrq->u.data.pointer, wrq->u.data.length);
4112 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA(TID=%d, bAllTid=%d)\n", pBA->TID, pBA->bAllTid));
4114 if (!pBA->bAllTid && (pBA->TID > NUM_OF_TID))
4116 Status = NDIS_STATUS_INVALID_DATA;
4120 if (pBA->IsRecipient == FALSE)
4122 pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
4123 DBGPRINT(RT_DEBUG_TRACE, (" pBA->IsRecipient == FALSE\n"));
4126 DBGPRINT(RT_DEBUG_TRACE, (" pBA->pEntry\n"));
4127 BAOriSessionTearDown(pAdapter, pEntry->Aid, pBA->TID, FALSE, TRUE);
4130 DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
4134 pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
4137 BARecSessionTearDown( pAdapter, (UCHAR)pEntry->Aid, pBA->TID, TRUE);
4140 DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
4146 // For WPA_SUPPLICANT to set static wep key
4147 case OID_802_11_ADD_WEP:
4148 pWepKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4153 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed!!\n"));
4156 Status = copy_from_user(pWepKey, wrq->u.data.pointer, wrq->u.data.length);
4160 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (length mismatch)!!\n"));
4164 KeyIdx = pWepKey->KeyIndex & 0x0fffffff;
4165 // KeyIdx must be 0 ~ 3
4169 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (KeyIdx must be smaller than 4)!!\n"));
4173 UCHAR CipherAlg = 0;
4176 // set key material and key length
4177 NdisZeroMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, 16);
4178 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
4179 NdisMoveMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
4181 switch(pWepKey->KeyLength)
4184 CipherAlg = CIPHER_WEP64;
4187 CipherAlg = CIPHER_WEP128;
4190 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, only support CIPHER_WEP64(len:5) & CIPHER_WEP128(len:13)!!\n"));
4194 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CipherAlg;
4196 // Default key for tx (shared key)
4197 if (pWepKey->KeyIndex & 0x80000000)
4199 // set key material and key length
4200 NdisZeroMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, 16);
4201 pAdapter->StaCfg.DesireSharedKey[KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
4202 NdisMoveMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
4203 pAdapter->StaCfg.DesireSharedKeyId = KeyIdx;
4204 pAdapter->StaCfg.DesireSharedKey[KeyIdx].CipherAlg = CipherAlg;
4205 pAdapter->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
4208 if ((pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE) &&
4209 (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA))
4211 Key = pWepKey->KeyMaterial;
4213 // Set Group key material to Asic
4214 AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
4216 // Update WCID attribute table and IVEIV table for this group key table
4217 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
4219 STA_PORT_SECURED(pAdapter);
4221 // Indicate Connected for GUI
4222 pAdapter->IndicateMediaState = NdisMediaStateConnected;
4224 else if (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)
4227 if (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)
4230 Key = pAdapter->SharedKey[BSS0][KeyIdx].Key;
4232 // Set key material and cipherAlg to Asic
4233 AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
4235 if (pWepKey->KeyIndex & 0x80000000)
4237 PMAC_TABLE_ENTRY pEntry = &pAdapter->MacTab.Content[BSSID_WCID];
4238 // Assign group key info
4239 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
4240 // Assign pairwise key info
4241 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, pEntry);
4244 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"));
4249 case OID_SET_COUNTERMEASURES:
4250 if (wrq->u.data.length != sizeof(int))
4255 Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
4257 pAdapter->StaCfg.bBlockAssoc = TRUE;
4259 // WPA MIC error should block association attempt for 60 seconds
4260 pAdapter->StaCfg.bBlockAssoc = FALSE;
4261 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_SET_COUNTERMEASURES bBlockAssoc=%s\n", pAdapter->StaCfg.bBlockAssoc ? "TRUE":"FALSE"));
4264 case RT_OID_WPA_SUPPLICANT_SUPPORT:
4265 if (wrq->u.data.length != sizeof(UCHAR))
4269 Status = copy_from_user(&wpa_supplicant_enable, wrq->u.data.pointer, wrq->u.data.length);
4270 pAdapter->StaCfg.WpaSupplicantUP = wpa_supplicant_enable;
4271 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
4274 case OID_802_11_DEAUTHENTICATION:
4275 if (wrq->u.data.length != sizeof(MLME_DEAUTH_REQ_STRUCT))
4279 MLME_DEAUTH_REQ_STRUCT *pInfo;
4280 MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
4282 pInfo = (MLME_DEAUTH_REQ_STRUCT *) MsgElem->Msg;
4283 Status = copy_from_user(pInfo, wrq->u.data.pointer, wrq->u.data.length);
4284 MlmeDeauthReqAction(pAdapter, MsgElem);
4287 if (INFRA_ON(pAdapter))
4289 LinkDown(pAdapter, FALSE);
4290 pAdapter->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
4292 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DEAUTHENTICATION (Reason=%d)\n", pInfo->Reason));
4295 case OID_802_11_DROP_UNENCRYPTED:
4296 if (wrq->u.data.length != sizeof(int))
4301 Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
4303 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
4305 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
4306 NdisAcquireSpinLock(&pAdapter->MacTabLock);
4307 pAdapter->MacTab.Content[BSSID_WCID].PortSecured = pAdapter->StaCfg.PortSecured;
4308 NdisReleaseSpinLock(&pAdapter->MacTabLock);
4309 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DROP_UNENCRYPTED (=%d)\n", enabled));
4312 case OID_802_11_SET_IEEE8021X:
4313 if (wrq->u.data.length != sizeof(BOOLEAN))
4317 Status = copy_from_user(&IEEE8021xState, wrq->u.data.pointer, wrq->u.data.length);
4318 pAdapter->StaCfg.IEEE8021X = IEEE8021xState;
4319 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X (=%d)\n", IEEE8021xState));
4322 case OID_802_11_SET_IEEE8021X_REQUIRE_KEY:
4323 if (wrq->u.data.length != sizeof(BOOLEAN))
4327 Status = copy_from_user(&IEEE8021x_required_keys, wrq->u.data.pointer, wrq->u.data.length);
4328 pAdapter->StaCfg.IEEE8021x_required_keys = IEEE8021x_required_keys;
4329 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X_REQUIRE_KEY (%d)\n", IEEE8021x_required_keys));
4332 case OID_802_11_PMKID:
4333 pPmkId = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4335 if(pPmkId == NULL) {
4339 Status = copy_from_user(pPmkId, wrq->u.data.pointer, wrq->u.data.length);
4341 // check the PMKID information
4342 if (pPmkId->BSSIDInfoCount == 0)
4343 NdisZeroMemory(pAdapter->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
4346 PBSSID_INFO pBssIdInfo;
4350 for (BssIdx = 0; BssIdx < pPmkId->BSSIDInfoCount; BssIdx++)
4352 // point to the indexed BSSID_INFO structure
4353 pBssIdInfo = (PBSSID_INFO) ((PUCHAR) pPmkId + 2 * sizeof(UINT) + BssIdx * sizeof(BSSID_INFO));
4354 // Find the entry in the saved data base.
4355 for (CachedIdx = 0; CachedIdx < pAdapter->StaCfg.SavedPMKNum; CachedIdx++)
4357 // compare the BSSID
4358 if (NdisEqualMemory(pBssIdInfo->BSSID, pAdapter->StaCfg.SavedPMK[CachedIdx].BSSID, sizeof(NDIS_802_11_MAC_ADDRESS)))
4362 // Found, replace it
4363 if (CachedIdx < PMKID_NO)
4365 DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
4366 NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
4367 pAdapter->StaCfg.SavedPMKNum++;
4369 // Not found, replace the last one
4372 // Randomly replace one
4373 CachedIdx = (pBssIdInfo->BSSID[5] % PMKID_NO);
4374 DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
4375 NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
4383 DBGPRINT(RT_DEBUG_TRACE, ("Set::unknown IOCTL's subcmd = 0x%08x\n", cmd));
4384 Status = -EOPNOTSUPP;
4392 INT RTMPQueryInformation(
4393 IN PRTMP_ADAPTER pAdapter,
4394 IN OUT struct ifreq *rq,
4397 struct iwreq *wrq = (struct iwreq *) rq;
4398 NDIS_802_11_BSSID_LIST_EX *pBssidList = NULL;
4399 PNDIS_WLAN_BSSID_EX pBss;
4400 NDIS_802_11_SSID Ssid;
4401 NDIS_802_11_CONFIGURATION *pConfiguration = NULL;
4402 RT_802_11_LINK_STATUS *pLinkStatus = NULL;
4403 RT_802_11_STA_CONFIG *pStaConfig = NULL;
4404 NDIS_802_11_STATISTICS *pStatistics = NULL;
4405 NDIS_802_11_RTS_THRESHOLD RtsThresh;
4406 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
4407 NDIS_802_11_POWER_MODE PowerMode;
4408 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
4409 RT_802_11_PREAMBLE PreamType;
4410 NDIS_802_11_AUTHENTICATION_MODE AuthMode;
4411 NDIS_802_11_WEP_STATUS WepStatus;
4412 NDIS_MEDIA_STATE MediaState;
4413 ULONG BssBufSize, ulInfo=0, NetworkTypeList[4], apsd = 0;
4415 PUCHAR pBuf = NULL, pPtr;
4416 INT Status = NDIS_STATUS_SUCCESS;
4417 UINT we_version_compiled;
4418 UCHAR i, Padding = 0;
4420 UCHAR driverVersion[8];
4421 OID_SET_HT_PHYMODE *pHTPhyMode = NULL;
4425 case RT_OID_DEVICE_NAME:
4426 wrq->u.data.length = sizeof(STA_NIC_DEVICE_NAME);
4427 Status = copy_to_user(wrq->u.data.pointer, STA_NIC_DEVICE_NAME, wrq->u.data.length);
4429 case RT_OID_VERSION_INFO:
4430 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_VERSION_INFO \n"));
4431 wrq->u.data.length = 8*sizeof(UCHAR);
4432 sprintf(&driverVersion[0], "%s", STA_DRIVER_VERSION);
4433 driverVersion[7] = '\0';
4434 if (copy_to_user(wrq->u.data.pointer, &driverVersion, wrq->u.data.length))
4439 case OID_802_11_BSSID_LIST:
4440 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
4443 * Still scanning, indicate the caller should try again.
4445 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (Still scanning)\n"));
4448 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (%d BSS returned)\n",pAdapter->ScanTab.BssNr));
4449 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
4450 // Claculate total buffer size required
4451 BssBufSize = sizeof(ULONG);
4453 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
4455 // Align pointer to 4 bytes boundary.
4456 //Padding = 4 - (pAdapter->ScanTab.BssEntry[i].VarIELen & 0x0003);
4459 BssBufSize += (sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
4462 // For safety issue, we add 256 bytes just in case
4464 // Allocate the same size as passed from higher layer
4465 pBuf = kmalloc(BssBufSize, MEM_ALLOC_FLAG);
4471 // Init 802_11_BSSID_LIST_EX structure
4472 NdisZeroMemory(pBuf, BssBufSize);
4473 pBssidList = (PNDIS_802_11_BSSID_LIST_EX) pBuf;
4474 pBssidList->NumberOfItems = pAdapter->ScanTab.BssNr;
4476 // Calculate total buffer length
4477 BssLen = 4; // Consist of NumberOfItems
4478 // Point to start of NDIS_WLAN_BSSID_EX
4479 // pPtr = pBuf + sizeof(ULONG);
4480 pPtr = (PUCHAR) &pBssidList->Bssid[0];
4481 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
4483 pBss = (PNDIS_WLAN_BSSID_EX) pPtr;
4484 NdisMoveMemory(&pBss->MacAddress, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
4485 if ((pAdapter->ScanTab.BssEntry[i].Hidden == 1) && (pAdapter->StaCfg.bShowHiddenSSID == FALSE))
4488 // We must return this SSID during 4way handshaking, otherwise Aegis will failed to parse WPA infomation
4489 // and then failed to send EAPOl farame.
4491 if ((pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) && (pAdapter->StaCfg.PortSecured != WPA_802_1X_PORT_SECURED))
4493 pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
4494 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
4497 pBss->Ssid.SsidLength = 0;
4501 pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
4502 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
4504 pBss->Privacy = pAdapter->ScanTab.BssEntry[i].Privacy;
4505 pBss->Rssi = pAdapter->ScanTab.BssEntry[i].Rssi - pAdapter->BbpRssiToDbmDelta;
4506 pBss->NetworkTypeInUse = NetworkTypeInUseSanity(&pAdapter->ScanTab.BssEntry[i]);
4507 pBss->Configuration.Length = sizeof(NDIS_802_11_CONFIGURATION);
4508 pBss->Configuration.BeaconPeriod = pAdapter->ScanTab.BssEntry[i].BeaconPeriod;
4509 pBss->Configuration.ATIMWindow = pAdapter->ScanTab.BssEntry[i].AtimWin;
4511 MAP_CHANNEL_ID_TO_KHZ(pAdapter->ScanTab.BssEntry[i].Channel, pBss->Configuration.DSConfig);
4513 if (pAdapter->ScanTab.BssEntry[i].BssType == BSS_INFRA)
4514 pBss->InfrastructureMode = Ndis802_11Infrastructure;
4516 pBss->InfrastructureMode = Ndis802_11IBSS;
4518 NdisMoveMemory(pBss->SupportedRates, pAdapter->ScanTab.BssEntry[i].SupRate, pAdapter->ScanTab.BssEntry[i].SupRateLen);
4519 NdisMoveMemory(pBss->SupportedRates + pAdapter->ScanTab.BssEntry[i].SupRateLen,
4520 pAdapter->ScanTab.BssEntry[i].ExtRate,
4521 pAdapter->ScanTab.BssEntry[i].ExtRateLen);
4523 if (pAdapter->ScanTab.BssEntry[i].VarIELen == 0)
4525 pBss->IELength = sizeof(NDIS_802_11_FIXED_IEs);
4526 NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
4527 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
4531 pBss->IELength = (ULONG)(sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen);
4532 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
4533 NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
4534 NdisMoveMemory(pBss->IEs + sizeof(NDIS_802_11_FIXED_IEs), pAdapter->ScanTab.BssEntry[i].VarIEs, pAdapter->ScanTab.BssEntry[i].VarIELen);
4535 pPtr += pAdapter->ScanTab.BssEntry[i].VarIELen;
4537 pBss->Length = (ULONG)(sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
4539 #if WIRELESS_EXT < 17
4540 if ((BssLen + pBss->Length) < wrq->u.data.length)
4541 BssLen += pBss->Length;
4544 pBssidList->NumberOfItems = i;
4548 BssLen += pBss->Length;
4552 #if WIRELESS_EXT < 17
4553 wrq->u.data.length = BssLen;
4555 if (BssLen > wrq->u.data.length)
4561 wrq->u.data.length = BssLen;
4563 Status = copy_to_user(wrq->u.data.pointer, pBssidList, BssLen);
4566 case OID_802_3_CURRENT_ADDRESS:
4567 wrq->u.data.length = MAC_ADDR_LEN;
4568 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
4570 case OID_GEN_MEDIA_CONNECT_STATUS:
4571 if (pAdapter->IndicateMediaState == NdisMediaStateConnected)
4572 MediaState = NdisMediaStateConnected;
4574 MediaState = NdisMediaStateDisconnected;
4576 wrq->u.data.length = sizeof(NDIS_MEDIA_STATE);
4577 Status = copy_to_user(wrq->u.data.pointer, &MediaState, wrq->u.data.length);
4579 case OID_802_11_BSSID:
4580 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
4582 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Bssid, sizeof(NDIS_802_11_MAC_ADDRESS));
4587 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID(=EMPTY)\n"));
4591 case OID_802_11_SSID:
4592 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
4593 NdisZeroMemory(Ssid.Ssid, MAX_LEN_OF_SSID);
4594 Ssid.SsidLength = pAdapter->CommonCfg.SsidLen;
4595 memcpy(Ssid.Ssid, pAdapter->CommonCfg.Ssid, Ssid.SsidLength);
4596 wrq->u.data.length = sizeof(NDIS_802_11_SSID);
4597 Status = copy_to_user(wrq->u.data.pointer, &Ssid, wrq->u.data.length);
4598 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_SSID (Len=%d, ssid=%s)\n", Ssid.SsidLength,Ssid.Ssid));
4600 case RT_OID_802_11_QUERY_LINK_STATUS:
4601 pLinkStatus = (RT_802_11_LINK_STATUS *) kmalloc(sizeof(RT_802_11_LINK_STATUS), MEM_ALLOC_FLAG);
4604 pLinkStatus->CurrTxRate = RateIdTo500Kbps[pAdapter->CommonCfg.TxRate]; // unit : 500 kbps
4605 pLinkStatus->ChannelQuality = pAdapter->Mlme.ChannelQuality;
4606 pLinkStatus->RxByteCount = pAdapter->RalinkCounters.ReceivedByteCount;
4607 pLinkStatus->TxByteCount = pAdapter->RalinkCounters.TransmittedByteCount;
4608 pLinkStatus->CentralChannel = pAdapter->CommonCfg.CentralChannel;
4609 wrq->u.data.length = sizeof(RT_802_11_LINK_STATUS);
4610 Status = copy_to_user(wrq->u.data.pointer, pLinkStatus, wrq->u.data.length);
4612 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS\n"));
4616 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS(kmalloc failed)\n"));
4620 case OID_802_11_CONFIGURATION:
4621 pConfiguration = (NDIS_802_11_CONFIGURATION *) kmalloc(sizeof(NDIS_802_11_CONFIGURATION), MEM_ALLOC_FLAG);
4624 pConfiguration->Length = sizeof(NDIS_802_11_CONFIGURATION);
4625 pConfiguration->BeaconPeriod = pAdapter->CommonCfg.BeaconPeriod;
4626 pConfiguration->ATIMWindow = pAdapter->StaActive.AtimWin;
4627 MAP_CHANNEL_ID_TO_KHZ(pAdapter->CommonCfg.Channel, pConfiguration->DSConfig);
4628 wrq->u.data.length = sizeof(NDIS_802_11_CONFIGURATION);
4629 Status = copy_to_user(wrq->u.data.pointer, pConfiguration, wrq->u.data.length);
4630 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(BeaconPeriod=%ld,AtimW=%ld,Channel=%d) \n",
4631 pConfiguration->BeaconPeriod, pConfiguration->ATIMWindow, pAdapter->CommonCfg.Channel));
4632 kfree(pConfiguration);
4636 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(kmalloc failed)\n"));
4640 case RT_OID_802_11_SNR_0:
4641 if ((pAdapter->StaCfg.LastSNR0 > 0))
4643 ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR0) * 3) / 16 ;
4644 wrq->u.data.length = sizeof(ulInfo);
4645 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4646 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_SNR_0(0x=%lx)\n", ulInfo));
4651 case RT_OID_802_11_SNR_1:
4652 if ((pAdapter->Antenna.field.RxPath > 1) &&
4653 (pAdapter->StaCfg.LastSNR1 > 0))
4655 ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR1) * 3) / 16 ;
4656 wrq->u.data.length = sizeof(ulInfo);
4657 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4658 DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(0x=%lx)\n",ulInfo));
4662 DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(pAdapter->StaCfg.LastSNR1=%d)\n",pAdapter->StaCfg.LastSNR1));
4664 case OID_802_11_RSSI_TRIGGER:
4665 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0 - pAdapter->BbpRssiToDbmDelta;
4666 wrq->u.data.length = sizeof(ulInfo);
4667 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4668 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RSSI_TRIGGER(=%ld)\n", ulInfo));
4670 case OID_802_11_RSSI:
4671 case RT_OID_802_11_RSSI:
4672 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0;
4673 wrq->u.data.length = sizeof(ulInfo);
4674 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4676 case RT_OID_802_11_RSSI_1:
4677 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi1;
4678 wrq->u.data.length = sizeof(ulInfo);
4679 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4681 case RT_OID_802_11_RSSI_2:
4682 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi2;
4683 wrq->u.data.length = sizeof(ulInfo);
4684 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4686 case OID_802_11_STATISTICS:
4687 pStatistics = (NDIS_802_11_STATISTICS *) kmalloc(sizeof(NDIS_802_11_STATISTICS), MEM_ALLOC_FLAG);
4690 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS \n"));
4691 // add the most up-to-date h/w raw counters into software counters
4692 NICUpdateRawCounters(pAdapter);
4694 // Sanity check for calculation of sucessful count
4695 if (pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart < pAdapter->WlanCounters.RetryCount.QuadPart)
4696 pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
4698 pStatistics->TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart;
4699 pStatistics->MulticastTransmittedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastTransmittedFrameCount.QuadPart;
4700 pStatistics->FailedCount.QuadPart = pAdapter->WlanCounters.FailedCount.QuadPart;
4701 pStatistics->RetryCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
4702 pStatistics->MultipleRetryCount.QuadPart = pAdapter->WlanCounters.MultipleRetryCount.QuadPart;
4703 pStatistics->RTSSuccessCount.QuadPart = pAdapter->WlanCounters.RTSSuccessCount.QuadPart;
4704 pStatistics->RTSFailureCount.QuadPart = pAdapter->WlanCounters.RTSFailureCount.QuadPart;
4705 pStatistics->ACKFailureCount.QuadPart = pAdapter->WlanCounters.ACKFailureCount.QuadPart;
4706 pStatistics->FrameDuplicateCount.QuadPart = pAdapter->WlanCounters.FrameDuplicateCount.QuadPart;
4707 pStatistics->ReceivedFragmentCount.QuadPart = pAdapter->WlanCounters.ReceivedFragmentCount.QuadPart;
4708 pStatistics->MulticastReceivedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastReceivedFrameCount.QuadPart;
4710 pStatistics->FCSErrorCount = pAdapter->RalinkCounters.RealFcsErrCount;
4712 pStatistics->FCSErrorCount.QuadPart = pAdapter->WlanCounters.FCSErrorCount.QuadPart;
4713 pStatistics->FrameDuplicateCount.u.LowPart = pAdapter->WlanCounters.FrameDuplicateCount.u.LowPart / 100;
4715 wrq->u.data.length = sizeof(NDIS_802_11_STATISTICS);
4716 Status = copy_to_user(wrq->u.data.pointer, pStatistics, wrq->u.data.length);
4721 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS(kmalloc failed)\n"));
4725 case OID_GEN_RCV_OK:
4726 ulInfo = pAdapter->Counters8023.GoodReceives;
4727 wrq->u.data.length = sizeof(ulInfo);
4728 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4730 case OID_GEN_RCV_NO_BUFFER:
4731 ulInfo = pAdapter->Counters8023.RxNoBuffer;
4732 wrq->u.data.length = sizeof(ulInfo);
4733 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4735 case RT_OID_802_11_PHY_MODE:
4736 ulInfo = (ULONG)pAdapter->CommonCfg.PhyMode;
4737 wrq->u.data.length = sizeof(ulInfo);
4738 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4739 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PHY_MODE (=%ld)\n", ulInfo));
4741 case RT_OID_802_11_STA_CONFIG:
4742 pStaConfig = (RT_802_11_STA_CONFIG *) kmalloc(sizeof(RT_802_11_STA_CONFIG), MEM_ALLOC_FLAG);
4745 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG\n"));
4746 pStaConfig->EnableTxBurst = pAdapter->CommonCfg.bEnableTxBurst;
4747 pStaConfig->EnableTurboRate = 0;
4748 pStaConfig->UseBGProtection = pAdapter->CommonCfg.UseBGProtection;
4749 pStaConfig->UseShortSlotTime = pAdapter->CommonCfg.bUseShortSlotTime;
4750 //pStaConfig->AdhocMode = pAdapter->StaCfg.AdhocMode;
4751 pStaConfig->HwRadioStatus = (pAdapter->StaCfg.bHwRadio == TRUE) ? 1 : 0;
4752 pStaConfig->Rsv1 = 0;
4753 pStaConfig->SystemErrorBitmap = pAdapter->SystemErrorBitmap;
4754 wrq->u.data.length = sizeof(RT_802_11_STA_CONFIG);
4755 Status = copy_to_user(wrq->u.data.pointer, pStaConfig, wrq->u.data.length);
4760 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
4764 case OID_802_11_RTS_THRESHOLD:
4765 RtsThresh = pAdapter->CommonCfg.RtsThreshold;
4766 wrq->u.data.length = sizeof(RtsThresh);
4767 Status = copy_to_user(wrq->u.data.pointer, &RtsThresh, wrq->u.data.length);
4768 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RTS_THRESHOLD(=%ld)\n", RtsThresh));
4770 case OID_802_11_FRAGMENTATION_THRESHOLD:
4771 FragThresh = pAdapter->CommonCfg.FragmentThreshold;
4772 if (pAdapter->CommonCfg.bUseZeroToDisableFragment == TRUE)
4774 wrq->u.data.length = sizeof(FragThresh);
4775 Status = copy_to_user(wrq->u.data.pointer, &FragThresh, wrq->u.data.length);
4776 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_FRAGMENTATION_THRESHOLD(=%ld)\n", FragThresh));
4778 case OID_802_11_POWER_MODE:
4779 PowerMode = pAdapter->StaCfg.WindowsPowerMode;
4780 wrq->u.data.length = sizeof(PowerMode);
4781 Status = copy_to_user(wrq->u.data.pointer, &PowerMode, wrq->u.data.length);
4782 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_POWER_MODE(=%d)\n", PowerMode));
4784 case RT_OID_802_11_RADIO:
4785 RadioState = (BOOLEAN) pAdapter->StaCfg.bSwRadio;
4786 wrq->u.data.length = sizeof(RadioState);
4787 Status = copy_to_user(wrq->u.data.pointer, &RadioState, wrq->u.data.length);
4788 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_RADIO (=%d)\n", RadioState));
4790 case OID_802_11_INFRASTRUCTURE_MODE:
4791 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
4792 BssType = Ndis802_11IBSS;
4793 else if (pAdapter->StaCfg.BssType == BSS_INFRA)
4794 BssType = Ndis802_11Infrastructure;
4795 else if (pAdapter->StaCfg.BssType == BSS_MONITOR)
4796 BssType = Ndis802_11Monitor;
4798 BssType = Ndis802_11AutoUnknown;
4800 wrq->u.data.length = sizeof(BssType);
4801 Status = copy_to_user(wrq->u.data.pointer, &BssType, wrq->u.data.length);
4802 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_INFRASTRUCTURE_MODE(=%d)\n", BssType));
4804 case RT_OID_802_11_PREAMBLE:
4805 PreamType = pAdapter->CommonCfg.TxPreamble;
4806 wrq->u.data.length = sizeof(PreamType);
4807 Status = copy_to_user(wrq->u.data.pointer, &PreamType, wrq->u.data.length);
4808 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PREAMBLE(=%d)\n", PreamType));
4810 case OID_802_11_AUTHENTICATION_MODE:
4811 AuthMode = pAdapter->StaCfg.AuthMode;
4812 wrq->u.data.length = sizeof(AuthMode);
4813 Status = copy_to_user(wrq->u.data.pointer, &AuthMode, wrq->u.data.length);
4814 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_AUTHENTICATION_MODE(=%d)\n", AuthMode));
4816 case OID_802_11_WEP_STATUS:
4817 WepStatus = pAdapter->StaCfg.WepStatus;
4818 wrq->u.data.length = sizeof(WepStatus);
4819 Status = copy_to_user(wrq->u.data.pointer, &WepStatus, wrq->u.data.length);
4820 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_WEP_STATUS(=%d)\n", WepStatus));
4822 case OID_802_11_TX_POWER_LEVEL:
4823 wrq->u.data.length = sizeof(ULONG);
4824 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPower, wrq->u.data.length);
4825 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_TX_POWER_LEVEL %x\n",pAdapter->CommonCfg.TxPower));
4827 case RT_OID_802_11_TX_POWER_LEVEL_1:
4828 wrq->u.data.length = sizeof(ULONG);
4829 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPowerPercentage, wrq->u.data.length);
4830 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
4832 case OID_802_11_NETWORK_TYPES_SUPPORTED:
4833 if ((pAdapter->RfIcType == RFIC_2850) || (pAdapter->RfIcType == RFIC_2750))
4835 NetworkTypeList[0] = 3; // NumberOfItems = 3
4836 NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
4837 NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
4838 NetworkTypeList[3] = Ndis802_11OFDM5; // NetworkType[3] = 11a
4839 wrq->u.data.length = 16;
4840 Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
4844 NetworkTypeList[0] = 2; // NumberOfItems = 2
4845 NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
4846 NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
4847 wrq->u.data.length = 12;
4848 Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
4850 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_NETWORK_TYPES_SUPPORTED\n"));
4852 case OID_802_11_NETWORK_TYPE_IN_USE:
4853 wrq->u.data.length = sizeof(ULONG);
4854 if (pAdapter->CommonCfg.PhyMode == PHY_11A)
4855 ulInfo = Ndis802_11OFDM5;
4856 else if ((pAdapter->CommonCfg.PhyMode == PHY_11BG_MIXED) || (pAdapter->CommonCfg.PhyMode == PHY_11G))
4857 ulInfo = Ndis802_11OFDM24;
4859 ulInfo = Ndis802_11DS;
4860 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4862 case RT_OID_802_11_QUERY_LAST_RX_RATE:
4863 ulInfo = (ULONG)pAdapter->LastRxRate;
4864 wrq->u.data.length = sizeof(ulInfo);
4865 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4866 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_RX_RATE (=%ld)\n", ulInfo));
4868 case RT_OID_802_11_QUERY_LAST_TX_RATE:
4869 //ulInfo = (ULONG)pAdapter->LastTxRate;
4870 ulInfo = (ULONG)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word;
4871 wrq->u.data.length = sizeof(ulInfo);
4872 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4873 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_TX_RATE (=%lx)\n", ulInfo));
4875 case RT_OID_802_11_QUERY_EEPROM_VERSION:
4876 wrq->u.data.length = sizeof(ULONG);
4877 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->EepromVersion, wrq->u.data.length);
4879 case RT_OID_802_11_QUERY_FIRMWARE_VERSION:
4880 wrq->u.data.length = sizeof(ULONG);
4881 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->FirmwareVersion, wrq->u.data.length);
4883 case RT_OID_802_11_QUERY_NOISE_LEVEL:
4884 wrq->u.data.length = sizeof(UCHAR);
4885 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->BbpWriteLatch[66], wrq->u.data.length);
4886 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_NOISE_LEVEL (=%d)\n", pAdapter->BbpWriteLatch[66]));
4888 case RT_OID_802_11_EXTRA_INFO:
4889 wrq->u.data.length = sizeof(ULONG);
4890 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->ExtraInfo, wrq->u.data.length);
4891 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_EXTRA_INFO (=%ld)\n", pAdapter->ExtraInfo));
4893 case RT_OID_WE_VERSION_COMPILED:
4894 wrq->u.data.length = sizeof(UINT);
4895 we_version_compiled = WIRELESS_EXT;
4896 Status = copy_to_user(wrq->u.data.pointer, &we_version_compiled, wrq->u.data.length);
4898 case RT_OID_802_11_QUERY_APSD_SETTING:
4899 apsd = (pAdapter->CommonCfg.bAPSDCapable | (pAdapter->CommonCfg.bAPSDAC_BE << 1) | (pAdapter->CommonCfg.bAPSDAC_BK << 2)
4900 | (pAdapter->CommonCfg.bAPSDAC_VI << 3) | (pAdapter->CommonCfg.bAPSDAC_VO << 4) | (pAdapter->CommonCfg.MaxSPLength << 5));
4902 wrq->u.data.length = sizeof(ULONG);
4903 Status = copy_to_user(wrq->u.data.pointer, &apsd, wrq->u.data.length);
4904 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",
4905 apsd,pAdapter->CommonCfg.bAPSDCapable,pAdapter->CommonCfg.bAPSDAC_BE,pAdapter->CommonCfg.bAPSDAC_BK,pAdapter->CommonCfg.bAPSDAC_VI,pAdapter->CommonCfg.bAPSDAC_VO,pAdapter->CommonCfg.MaxSPLength));
4907 case RT_OID_802_11_QUERY_APSD_PSM:
4908 wrq->u.data.length = sizeof(ULONG);
4909 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.length);
4910 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_APSD_PSM (=%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
4912 case RT_OID_802_11_QUERY_WMM:
4913 wrq->u.data.length = sizeof(BOOLEAN);
4914 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bWmmCapable, wrq->u.data.length);
4915 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_WMM (=%d)\n", pAdapter->CommonCfg.bWmmCapable));
4917 case RT_OID_NEW_DRIVER:
4920 wrq->u.data.length = sizeof(UCHAR);
4921 Status = copy_to_user(wrq->u.data.pointer, &enabled, wrq->u.data.length);
4922 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_NEW_DRIVER (=%d)\n", enabled));
4925 case RT_OID_WPA_SUPPLICANT_SUPPORT:
4926 wrq->u.data.length = sizeof(UCHAR);
4927 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->StaCfg.WpaSupplicantUP, wrq->u.data.length);
4928 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
4930 case RT_OID_DRIVER_DEVICE_NAME:
4931 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_DRIVER_DEVICE_NAME \n"));
4932 wrq->u.data.length = 16;
4933 if (copy_to_user(wrq->u.data.pointer, pAdapter->StaCfg.dev_name, wrq->u.data.length))
4938 case RT_OID_802_11_QUERY_HT_PHYMODE:
4939 pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
4942 pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
4943 pHTPhyMode->HtMode = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE;
4944 pHTPhyMode->BW = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.BW;
4945 pHTPhyMode->MCS= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MCS;
4946 pHTPhyMode->SHORTGI= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.ShortGI;
4947 pHTPhyMode->STBC= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.STBC;
4949 pHTPhyMode->ExtOffset = ((pAdapter->CommonCfg.CentralChannel < pAdapter->CommonCfg.Channel) ? (EXTCHA_BELOW) : (EXTCHA_ABOVE));
4950 wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
4951 if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
4955 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
4956 pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
4957 DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
4961 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
4965 case RT_OID_802_11_COUNTRY_REGION:
4966 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_COUNTRY_REGION \n"));
4967 wrq->u.data.length = sizeof(ulInfo);
4968 ulInfo = pAdapter->CommonCfg.CountryRegionForABand;
4969 ulInfo = (ulInfo << 8)|(pAdapter->CommonCfg.CountryRegion);
4970 if (copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length))
4975 case RT_OID_802_11_QUERY_DAT_HT_PHYMODE:
4976 pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
4979 pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
4980 pHTPhyMode->HtMode = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.HTMODE;
4981 pHTPhyMode->BW = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.BW;
4982 pHTPhyMode->MCS= (UCHAR)pAdapter->StaCfg.DesiredTransmitSetting.field.MCS;
4983 pHTPhyMode->SHORTGI= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.ShortGI;
4984 pHTPhyMode->STBC= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.STBC;
4986 wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
4987 if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
4991 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
4992 pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
4993 DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
4997 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
5001 case RT_OID_QUERY_MULTIPLE_CARD_SUPPORT:
5002 wrq->u.data.length = sizeof(UCHAR);
5004 if (copy_to_user(wrq->u.data.pointer, &i, wrq->u.data.length))
5008 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_QUERY_MULTIPLE_CARD_SUPPORT(=%d) \n", i));
5011 case OID_802_11_BUILD_CHANNEL_EX:
5014 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BUILD_CHANNEL_EX \n"));
5015 wrq->u.data.length = sizeof(UCHAR);
5016 DBGPRINT(RT_DEBUG_TRACE, ("Doesn't support EXT_BUILD_CHANNEL_LIST.\n"));
5018 Status = copy_to_user(wrq->u.data.pointer, &value, 1);
5019 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5023 case OID_802_11_GET_CH_LIST:
5025 PRT_CHANNEL_LIST_INFO pChListBuf;
5027 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CH_LIST \n"));
5028 if (pAdapter->ChannelListNum == 0)
5030 wrq->u.data.length = 0;
5034 pChListBuf = (RT_CHANNEL_LIST_INFO *) kmalloc(sizeof(RT_CHANNEL_LIST_INFO), MEM_ALLOC_FLAG);
5035 if (pChListBuf == NULL)
5037 wrq->u.data.length = 0;
5041 pChListBuf->ChannelListNum = pAdapter->ChannelListNum;
5042 for (i = 0; i < pChListBuf->ChannelListNum; i++)
5043 pChListBuf->ChannelList[i] = pAdapter->ChannelList[i].Channel;
5045 wrq->u.data.length = sizeof(RT_CHANNEL_LIST_INFO);
5046 Status = copy_to_user(wrq->u.data.pointer, pChListBuf, sizeof(RT_CHANNEL_LIST_INFO));
5047 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5054 case OID_802_11_GET_COUNTRY_CODE:
5055 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_COUNTRY_CODE \n"));
5056 wrq->u.data.length = 2;
5057 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.CountryCode, 2);
5058 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5061 case OID_802_11_GET_CHANNEL_GEOGRAPHY:
5062 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CHANNEL_GEOGRAPHY \n"));
5063 wrq->u.data.length = 1;
5064 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Geography, 1);
5065 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5069 DBGPRINT(RT_DEBUG_TRACE, ("Query::unknown IOCTL's subcmd = 0x%08x\n", cmd));
5070 Status = -EOPNOTSUPP;
5076 INT rt28xx_sta_ioctl(
5077 IN struct net_device *net_dev,
5078 IN OUT struct ifreq *rq,
5082 VIRTUAL_ADAPTER *pVirtualAd = NULL;
5083 RTMP_ADAPTER *pAd = NULL;
5084 struct iwreq *wrq = (struct iwreq *) rq;
5085 BOOLEAN StateMachineTouched = FALSE;
5086 INT Status = NDIS_STATUS_SUCCESS;
5089 if (net_dev->priv_flags == INT_MAIN)
5091 pAd = net_dev->ml_priv;
5095 pVirtualAd = net_dev->ml_priv;
5096 pAd = pVirtualAd->RtmpDev->ml_priv;
5098 pObj = (POS_COOKIE) pAd->OS_Cookie;
5102 /* if 1st open fail, pAd will be free;
5103 So the net_dev->ml_priv will be NULL in 2rd open */
5107 //check if the interface is down
5108 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
5111 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
5116 { // determine this ioctl command is comming from which interface.
5117 pObj->ioctl_if_type = INT_MAIN;
5118 pObj->ioctl_if = MAIN_MBSSID;
5124 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIFHWADDR\n"));
5125 memcpy(wrq->u.name, pAd->CurrentAddress, ETH_ALEN);
5129 char *name=&wrq->u.name[0];
5130 rt_ioctl_giwname(net_dev, NULL, name, NULL);
5133 case SIOCGIWESSID: //Get ESSID
5135 struct iw_point *essid=&wrq->u.essid;
5136 rt_ioctl_giwessid(net_dev, NULL, essid, essid->pointer);
5139 case SIOCSIWESSID: //Set ESSID
5141 struct iw_point *essid=&wrq->u.essid;
5142 rt_ioctl_siwessid(net_dev, NULL, essid, essid->pointer);
5145 case SIOCSIWNWID: // set network id (the cell)
5146 case SIOCGIWNWID: // get network id
5147 Status = -EOPNOTSUPP;
5149 case SIOCSIWFREQ: //set channel/frequency (Hz)
5151 struct iw_freq *freq=&wrq->u.freq;
5152 rt_ioctl_siwfreq(net_dev, NULL, freq, NULL);
5155 case SIOCGIWFREQ: // get channel/frequency (Hz)
5157 struct iw_freq *freq=&wrq->u.freq;
5158 rt_ioctl_giwfreq(net_dev, NULL, freq, NULL);
5161 case SIOCSIWNICKN: //set node name/nickname
5163 struct iw_point *data=&wrq->u.data;
5164 rt_ioctl_siwnickn(net_dev, NULL, data, NULL);
5167 case SIOCGIWNICKN: //get node name/nickname
5169 struct iw_point *data=&wrq->u.data;
5170 rt_ioctl_giwnickn(net_dev, NULL, data, NULL);
5173 case SIOCGIWRATE: //get default bit rate (bps)
5174 rt_ioctl_giwrate(net_dev, NULL, &wrq->u, NULL);
5176 case SIOCSIWRATE: //set default bit rate (bps)
5177 rt_ioctl_siwrate(net_dev, NULL, &wrq->u, NULL);
5179 case SIOCGIWRTS: // get RTS/CTS threshold (bytes)
5181 struct iw_param *rts=&wrq->u.rts;
5182 rt_ioctl_giwrts(net_dev, NULL, rts, NULL);
5185 case SIOCSIWRTS: //set RTS/CTS threshold (bytes)
5187 struct iw_param *rts=&wrq->u.rts;
5188 rt_ioctl_siwrts(net_dev, NULL, rts, NULL);
5191 case SIOCGIWFRAG: //get fragmentation thr (bytes)
5193 struct iw_param *frag=&wrq->u.frag;
5194 rt_ioctl_giwfrag(net_dev, NULL, frag, NULL);
5197 case SIOCSIWFRAG: //set fragmentation thr (bytes)
5199 struct iw_param *frag=&wrq->u.frag;
5200 rt_ioctl_siwfrag(net_dev, NULL, frag, NULL);
5203 case SIOCGIWENCODE: //get encoding token & mode
5205 struct iw_point *erq=&wrq->u.encoding;
5207 rt_ioctl_giwencode(net_dev, NULL, erq, erq->pointer);
5210 case SIOCSIWENCODE: //set encoding token & mode
5212 struct iw_point *erq=&wrq->u.encoding;
5214 rt_ioctl_siwencode(net_dev, NULL, erq, erq->pointer);
5217 case SIOCGIWAP: //get access point MAC addresses
5219 struct sockaddr *ap_addr=&wrq->u.ap_addr;
5220 rt_ioctl_giwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
5223 case SIOCSIWAP: //set access point MAC addresses
5225 struct sockaddr *ap_addr=&wrq->u.ap_addr;
5226 rt_ioctl_siwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
5229 case SIOCGIWMODE: //get operation mode
5231 __u32 *mode=&wrq->u.mode;
5232 rt_ioctl_giwmode(net_dev, NULL, mode, NULL);
5235 case SIOCSIWMODE: //set operation mode
5237 __u32 *mode=&wrq->u.mode;
5238 rt_ioctl_siwmode(net_dev, NULL, mode, NULL);
5241 case SIOCGIWSENS: //get sensitivity (dBm)
5242 case SIOCSIWSENS: //set sensitivity (dBm)
5243 case SIOCGIWPOWER: //get Power Management settings
5244 case SIOCSIWPOWER: //set Power Management settings
5245 case SIOCGIWTXPOW: //get transmit power (dBm)
5246 case SIOCSIWTXPOW: //set transmit power (dBm)
5247 case SIOCGIWRANGE: //Get range of parameters
5248 case SIOCGIWRETRY: //get retry limits and lifetime
5249 case SIOCSIWRETRY: //set retry limits and lifetime
5250 Status = -EOPNOTSUPP;
5254 case RT_PRIV_IOCTL_EXT:
5256 subcmd = wrq->u.data.flags;
5257 if( subcmd & OID_GET_SET_TOGGLE)
5258 Status = RTMPSetInformation(pAd, rq, subcmd);
5260 Status = RTMPQueryInformation(pAd, rq, subcmd);
5263 if (wrq->u.data.pointer)
5265 if ( access_ok(VERIFY_WRITE, wrq->u.data.pointer, sizeof(privtab)) != TRUE)
5267 wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
5268 if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
5272 case RTPRIV_IOCTL_SET:
5273 if(access_ok(VERIFY_READ, wrq->u.data.pointer, wrq->u.data.length) != TRUE)
5275 rt_ioctl_setparam(net_dev, NULL, NULL, wrq->u.data.pointer);
5277 case RTPRIV_IOCTL_GSITESURVEY:
5278 RTMPIoctlGetSiteSurvey(pAd, wrq);
5281 case RTPRIV_IOCTL_MAC:
5282 RTMPIoctlMAC(pAd, wrq);
5284 case RTPRIV_IOCTL_E2P:
5285 RTMPIoctlE2PROM(pAd, wrq);
5288 case RTPRIV_IOCTL_RF:
5289 RTMPIoctlRF(pAd, wrq);
5296 DBGPRINT(RT_DEBUG_ERROR, ("IOCTL::unknown IOCTL's cmd = 0x%08x\n", cmd));
5297 Status = -EOPNOTSUPP;
5301 if(StateMachineTouched) // Upper layer sent a MLME-related operations
5302 RT28XX_MLME_HANDLER(pAd);
5308 ==========================================================================
5312 TRUE if all parameters are OK, FALSE otherwise
5313 ==========================================================================
5316 IN PRTMP_ADAPTER pAdapter,
5319 NDIS_802_11_SSID Ssid, *pSsid=NULL;
5320 BOOLEAN StateMachineTouched = FALSE;
5323 if( strlen(arg) <= MAX_LEN_OF_SSID)
5325 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
5326 if (strlen(arg) != 0)
5328 NdisMoveMemory(Ssid.Ssid, arg, strlen(arg));
5329 Ssid.SsidLength = strlen(arg);
5333 Ssid.SsidLength = 0;
5334 memcpy(Ssid.Ssid, "", 0);
5335 pAdapter->StaCfg.BssType = BSS_INFRA;
5336 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
5337 pAdapter->StaCfg.WepStatus = Ndis802_11EncryptionDisabled;
5341 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
5343 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
5344 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
5347 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
5348 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
5349 pAdapter->bConfigChanged = TRUE;
5351 MlmeEnqueue(pAdapter,
5352 MLME_CNTL_STATE_MACHINE,
5354 sizeof(NDIS_802_11_SSID),
5357 StateMachineTouched = TRUE;
5358 DBGPRINT(RT_DEBUG_TRACE, ("Set_SSID_Proc::(Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
5363 if (StateMachineTouched) // Upper layer sent a MLME-related operations
5364 RT28XX_MLME_HANDLER(pAdapter);
5371 ==========================================================================
5373 Set WmmCapable Enable or Disable
5375 TRUE if all parameters are OK, FALSE otherwise
5376 ==========================================================================
5378 INT Set_WmmCapable_Proc(
5379 IN PRTMP_ADAPTER pAd,
5382 BOOLEAN bWmmCapable;
5384 bWmmCapable = simple_strtol(arg, 0, 10);
5386 if ((bWmmCapable == 1)
5388 && (pAd->NumberOfPipes >= 5)
5391 pAd->CommonCfg.bWmmCapable = TRUE;
5392 else if (bWmmCapable == 0)
5393 pAd->CommonCfg.bWmmCapable = FALSE;
5395 return FALSE; //Invalid argument
5397 DBGPRINT(RT_DEBUG_TRACE, ("Set_WmmCapable_Proc::(bWmmCapable=%d)\n",
5398 pAd->CommonCfg.bWmmCapable));
5402 #endif // WMM_SUPPORT //
5405 ==========================================================================
5407 Set Network Type(Infrastructure/Adhoc mode)
5409 TRUE if all parameters are OK, FALSE otherwise
5410 ==========================================================================
5412 INT Set_NetworkType_Proc(
5413 IN PRTMP_ADAPTER pAdapter,
5418 if (strcmp(arg, "Adhoc") == 0)
5420 if (pAdapter->StaCfg.BssType != BSS_ADHOC)
5422 // Config has changed
5423 pAdapter->bConfigChanged = TRUE;
5424 if (MONITOR_ON(pAdapter))
5426 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
5427 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5429 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5430 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5431 pAdapter->StaCfg.bAutoReconnect = TRUE;
5432 LinkDown(pAdapter, FALSE);
5434 if (INFRA_ON(pAdapter))
5436 //BOOLEAN Cancelled;
5437 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
5438 // Since calling this indicate user don't want to connect to that SSID anymore.
5439 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
5440 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
5442 LinkDown(pAdapter, FALSE);
5444 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n"));
5447 pAdapter->StaCfg.BssType = BSS_ADHOC;
5448 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
5449 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(AD-HOC)\n"));
5451 else if (strcmp(arg, "Infra") == 0)
5453 if (pAdapter->StaCfg.BssType != BSS_INFRA)
5455 // Config has changed
5456 pAdapter->bConfigChanged = TRUE;
5457 if (MONITOR_ON(pAdapter))
5459 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
5460 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5462 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5463 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5464 pAdapter->StaCfg.bAutoReconnect = TRUE;
5465 LinkDown(pAdapter, FALSE);
5467 if (ADHOC_ON(pAdapter))
5469 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
5470 // Since calling this indicate user don't want to connect to that SSID anymore.
5471 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
5472 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
5474 LinkDown(pAdapter, FALSE);
5477 pAdapter->StaCfg.BssType = BSS_INFRA;
5478 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
5479 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(INFRA)\n"));
5481 pAdapter->StaCfg.BssType = BSS_INFRA;
5483 else if (strcmp(arg, "Monitor") == 0)
5486 BCN_TIME_CFG_STRUC csr;
5487 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_INFRA_ON);
5488 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_ADHOC_ON);
5489 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5490 // disable all periodic state machine
5491 pAdapter->StaCfg.bAutoReconnect = FALSE;
5492 // reset all mlme state machine
5493 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
5494 DBGPRINT(RT_DEBUG_TRACE, ("fOP_STATUS_MEDIA_STATE_CONNECTED \n"));
5495 if (pAdapter->CommonCfg.CentralChannel == 0)
5497 if (pAdapter->CommonCfg.PhyMode == PHY_11AN_MIXED)
5498 pAdapter->CommonCfg.CentralChannel = 36;
5500 pAdapter->CommonCfg.CentralChannel = 6;
5503 N_ChannelCheck(pAdapter);
5505 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
5506 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
5507 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_ABOVE)
5509 // 40MHz ,control channel at lower
5510 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5511 bbpValue &= (~0x18);
5513 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5514 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
5515 // RX : control channel at lower
5516 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
5517 bbpValue &= (~0x20);
5518 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
5520 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
5521 Value &= 0xfffffffe;
5522 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
5523 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel + 2;
5524 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
5525 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
5526 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
5527 pAdapter->CommonCfg.Channel,
5528 pAdapter->CommonCfg.CentralChannel));
5530 else if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
5531 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
5532 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_BELOW)
5534 // 40MHz ,control channel at upper
5535 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5536 bbpValue &= (~0x18);
5538 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5539 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
5540 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
5542 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
5544 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
5546 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
5547 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel - 2;
5548 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
5549 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
5550 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
5551 pAdapter->CommonCfg.Channel,
5552 pAdapter->CommonCfg.CentralChannel));
5557 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5558 bbpValue &= (~0x18);
5559 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5560 pAdapter->CommonCfg.BBPCurrentBW = BW_20;
5561 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.Channel, FALSE);
5562 AsicLockChannel(pAdapter, pAdapter->CommonCfg.Channel);
5563 DBGPRINT(RT_DEBUG_TRACE, ("BW_20, Channel(%d)\n", pAdapter->CommonCfg.Channel));
5565 // Enable Rx with promiscuous reception
5566 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, 0x3);
5567 // ASIC supporsts sniffer function with replacing RSSI with timestamp.
5568 //RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5570 //RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5572 RTMP_IO_READ32(pAdapter, BCN_TIME_CFG, &csr.word);
5573 csr.field.bBeaconGen = 0;
5574 csr.field.bTBTTEnable = 0;
5575 csr.field.TsfSyncMode = 0;
5576 RTMP_IO_WRITE32(pAdapter, BCN_TIME_CFG, csr.word);
5578 pAdapter->StaCfg.BssType = BSS_MONITOR;
5579 pAdapter->net_dev->type = ARPHRD_IEEE80211_PRISM; //ARPHRD_IEEE80211; // IEEE80211
5580 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(MONITOR)\n"));
5583 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
5584 pAdapter->StaCfg.WpaState = SS_NOTUSE;
5586 DBGPRINT(RT_DEBUG_TRACE, ("Set_NetworkType_Proc::(NetworkType=%d)\n", pAdapter->StaCfg.BssType));
5592 ==========================================================================
5594 Set Authentication mode
5596 TRUE if all parameters are OK, FALSE otherwise
5597 ==========================================================================
5599 INT Set_AuthMode_Proc(
5600 IN PRTMP_ADAPTER pAdapter,
5603 if ((strcmp(arg, "WEPAUTO") == 0) || (strcmp(arg, "wepauto") == 0))
5604 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeAutoSwitch;
5605 else if ((strcmp(arg, "OPEN") == 0) || (strcmp(arg, "open") == 0))
5606 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
5607 else if ((strcmp(arg, "SHARED") == 0) || (strcmp(arg, "shared") == 0))
5608 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
5609 else if ((strcmp(arg, "WPAPSK") == 0) || (strcmp(arg, "wpapsk") == 0))
5610 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
5611 else if ((strcmp(arg, "WPANONE") == 0) || (strcmp(arg, "wpanone") == 0))
5612 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
5613 else if ((strcmp(arg, "WPA2PSK") == 0) || (strcmp(arg, "wpa2psk") == 0))
5614 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
5615 else if ((strcmp(arg, "WPA") == 0) || (strcmp(arg, "wpa") == 0))
5616 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
5617 else if ((strcmp(arg, "WPA2") == 0) || (strcmp(arg, "wpa2") == 0))
5618 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
5622 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
5624 DBGPRINT(RT_DEBUG_TRACE, ("Set_AuthMode_Proc::(AuthMode=%d)\n", pAdapter->StaCfg.AuthMode));
5630 ==========================================================================
5634 TRUE if all parameters are OK, FALSE otherwise
5635 ==========================================================================
5637 INT Set_EncrypType_Proc(
5638 IN PRTMP_ADAPTER pAdapter,
5641 if ((strcmp(arg, "NONE") == 0) || (strcmp(arg, "none") == 0))
5643 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5644 return TRUE; // do nothing
5646 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
5647 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
5648 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
5650 else if ((strcmp(arg, "WEP") == 0) || (strcmp(arg, "wep") == 0))
5652 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5653 return TRUE; // do nothing
5655 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
5656 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
5657 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
5659 else if ((strcmp(arg, "TKIP") == 0) || (strcmp(arg, "tkip") == 0))
5661 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
5662 return TRUE; // do nothing
5664 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
5665 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
5666 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
5668 else if ((strcmp(arg, "AES") == 0) || (strcmp(arg, "aes") == 0))
5670 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
5671 return TRUE; // do nothing
5673 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
5674 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
5675 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
5680 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
5682 DBGPRINT(RT_DEBUG_TRACE, ("Set_EncrypType_Proc::(EncrypType=%d)\n", pAdapter->StaCfg.WepStatus));
5688 ==========================================================================
5692 TRUE if all parameters are OK, FALSE otherwise
5693 ==========================================================================
5695 INT Set_DefaultKeyID_Proc(
5696 IN PRTMP_ADAPTER pAdapter,
5701 KeyIdx = simple_strtol(arg, 0, 10);
5702 if((KeyIdx >= 1 ) && (KeyIdx <= 4))
5703 pAdapter->StaCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1 );
5705 return FALSE; //Invalid argument
5707 DBGPRINT(RT_DEBUG_TRACE, ("Set_DefaultKeyID_Proc::(DefaultKeyID=%d)\n", pAdapter->StaCfg.DefaultKeyId));
5713 ==========================================================================
5717 TRUE if all parameters are OK, FALSE otherwise
5718 ==========================================================================
5721 IN PRTMP_ADAPTER pAdapter,
5726 UCHAR CipherAlg=CIPHER_WEP64;
5728 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5729 return TRUE; // do nothing
5731 KeyLen = strlen(arg);
5735 case 5: //wep 40 Ascii type
5736 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
5737 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
5738 CipherAlg = CIPHER_WEP64;
5739 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
5741 case 10: //wep 40 Hex type
5742 for(i=0; i < KeyLen; i++)
5744 if( !isxdigit(*(arg+i)) )
5745 return FALSE; //Not Hex value;
5747 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
5748 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
5749 CipherAlg = CIPHER_WEP64;
5750 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
5752 case 13: //wep 104 Ascii type
5753 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
5754 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
5755 CipherAlg = CIPHER_WEP128;
5756 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
5758 case 26: //wep 104 Hex type
5759 for(i=0; i < KeyLen; i++)
5761 if( !isxdigit(*(arg+i)) )
5762 return FALSE; //Not Hex value;
5764 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
5765 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
5766 CipherAlg = CIPHER_WEP128;
5767 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
5769 default: //Invalid argument
5770 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::Invalid argument (=%s)\n", arg));
5774 pAdapter->SharedKey[BSS0][0].CipherAlg = CipherAlg;
5776 // Set keys (into ASIC)
5777 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5779 else // Old WEP stuff
5781 AsicAddSharedKeyEntry(pAdapter,
5784 pAdapter->SharedKey[BSS0][0].CipherAlg,
5785 pAdapter->SharedKey[BSS0][0].Key,
5793 ==========================================================================
5798 TRUE if all parameters are OK, FALSE otherwise
5799 ==========================================================================
5802 IN PRTMP_ADAPTER pAdapter,
5807 UCHAR CipherAlg=CIPHER_WEP64;
5809 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5810 return TRUE; // do nothing
5812 KeyLen = strlen(arg);
5816 case 5: //wep 40 Ascii type
5817 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
5818 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
5819 CipherAlg = CIPHER_WEP64;
5820 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
5822 case 10: //wep 40 Hex type
5823 for(i=0; i < KeyLen; i++)
5825 if( !isxdigit(*(arg+i)) )
5826 return FALSE; //Not Hex value;
5828 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
5829 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
5830 CipherAlg = CIPHER_WEP64;
5831 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
5833 case 13: //wep 104 Ascii type
5834 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
5835 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
5836 CipherAlg = CIPHER_WEP128;
5837 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
5839 case 26: //wep 104 Hex type
5840 for(i=0; i < KeyLen; i++)
5842 if( !isxdigit(*(arg+i)) )
5843 return FALSE; //Not Hex value;
5845 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
5846 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
5847 CipherAlg = CIPHER_WEP128;
5848 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
5850 default: //Invalid argument
5851 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::Invalid argument (=%s)\n", arg));
5854 pAdapter->SharedKey[BSS0][1].CipherAlg = CipherAlg;
5856 // Set keys (into ASIC)
5857 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5859 else // Old WEP stuff
5861 AsicAddSharedKeyEntry(pAdapter,
5864 pAdapter->SharedKey[BSS0][1].CipherAlg,
5865 pAdapter->SharedKey[BSS0][1].Key,
5873 ==========================================================================
5877 TRUE if all parameters are OK, FALSE otherwise
5878 ==========================================================================
5881 IN PRTMP_ADAPTER pAdapter,
5886 UCHAR CipherAlg=CIPHER_WEP64;
5888 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5889 return TRUE; // do nothing
5891 KeyLen = strlen(arg);
5895 case 5: //wep 40 Ascii type
5896 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
5897 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
5898 CipherAlg = CIPHER_WEP64;
5899 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
5901 case 10: //wep 40 Hex type
5902 for(i=0; i < KeyLen; i++)
5904 if( !isxdigit(*(arg+i)) )
5905 return FALSE; //Not Hex value;
5907 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
5908 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
5909 CipherAlg = CIPHER_WEP64;
5910 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
5912 case 13: //wep 104 Ascii type
5913 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
5914 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
5915 CipherAlg = CIPHER_WEP128;
5916 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
5918 case 26: //wep 104 Hex type
5919 for(i=0; i < KeyLen; i++)
5921 if( !isxdigit(*(arg+i)) )
5922 return FALSE; //Not Hex value;
5924 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
5925 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
5926 CipherAlg = CIPHER_WEP128;
5927 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
5929 default: //Invalid argument
5930 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::Invalid argument (=%s)\n", arg));
5933 pAdapter->SharedKey[BSS0][2].CipherAlg = CipherAlg;
5935 // Set keys (into ASIC)
5936 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5938 else // Old WEP stuff
5940 AsicAddSharedKeyEntry(pAdapter,
5943 pAdapter->SharedKey[BSS0][2].CipherAlg,
5944 pAdapter->SharedKey[BSS0][2].Key,
5952 ==========================================================================
5956 TRUE if all parameters are OK, FALSE otherwise
5957 ==========================================================================
5960 IN PRTMP_ADAPTER pAdapter,
5965 UCHAR CipherAlg=CIPHER_WEP64;
5967 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5968 return TRUE; // do nothing
5970 KeyLen = strlen(arg);
5974 case 5: //wep 40 Ascii type
5975 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
5976 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
5977 CipherAlg = CIPHER_WEP64;
5978 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
5980 case 10: //wep 40 Hex type
5981 for(i=0; i < KeyLen; i++)
5983 if( !isxdigit(*(arg+i)) )
5984 return FALSE; //Not Hex value;
5986 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
5987 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
5988 CipherAlg = CIPHER_WEP64;
5989 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
5991 case 13: //wep 104 Ascii type
5992 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
5993 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
5994 CipherAlg = CIPHER_WEP128;
5995 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
5997 case 26: //wep 104 Hex type
5998 for(i=0; i < KeyLen; i++)
6000 if( !isxdigit(*(arg+i)) )
6001 return FALSE; //Not Hex value;
6003 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
6004 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
6005 CipherAlg = CIPHER_WEP128;
6006 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
6008 default: //Invalid argument
6009 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::Invalid argument (=%s)\n", arg));
6012 pAdapter->SharedKey[BSS0][3].CipherAlg = CipherAlg;
6014 // Set keys (into ASIC)
6015 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6017 else // Old WEP stuff
6019 AsicAddSharedKeyEntry(pAdapter,
6022 pAdapter->SharedKey[BSS0][3].CipherAlg,
6023 pAdapter->SharedKey[BSS0][3].Key,
6032 ==========================================================================
6036 TRUE if all parameters are OK, FALSE otherwise
6037 ==========================================================================
6039 INT Set_WPAPSK_Proc(
6040 IN PRTMP_ADAPTER pAdapter,
6043 UCHAR keyMaterial[40];
6045 if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
6046 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
6047 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
6049 return TRUE; // do nothing
6051 DBGPRINT(RT_DEBUG_TRACE, ("Set_WPAPSK_Proc::(WPAPSK=%s)\n", arg));
6053 NdisZeroMemory(keyMaterial, 40);
6055 if ((strlen(arg) < 8) || (strlen(arg) > 64))
6057 DBGPRINT(RT_DEBUG_TRACE, ("Set failed!!(WPAPSK=%s), WPAPSK key-string required 8 ~ 64 characters \n", arg));
6061 if (strlen(arg) == 64)
6063 AtoH(arg, keyMaterial, 32);
6064 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
6069 PasswordHash((char *)arg, pAdapter->MlmeAux.Ssid, pAdapter->MlmeAux.SsidLen, keyMaterial);
6070 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
6075 if(pAdapter->StaCfg.BssType == BSS_ADHOC &&
6076 pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
6078 pAdapter->StaCfg.WpaState = SS_NOTUSE;
6082 // Start STA supplicant state machine
6083 pAdapter->StaCfg.WpaState = SS_START;
6090 ==========================================================================
6092 Set Power Saving mode
6094 TRUE if all parameters are OK, FALSE otherwise
6095 ==========================================================================
6097 INT Set_PSMode_Proc(
6098 IN PRTMP_ADAPTER pAdapter,
6101 if (pAdapter->StaCfg.BssType == BSS_INFRA)
6103 if ((strcmp(arg, "Max_PSP") == 0) ||
6104 (strcmp(arg, "max_psp") == 0) ||
6105 (strcmp(arg, "MAX_PSP") == 0))
6107 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6108 // to exclude certain situations.
6109 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6110 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeMAX_PSP;
6111 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeMAX_PSP;
6112 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6113 pAdapter->StaCfg.DefaultListenCount = 5;
6116 else if ((strcmp(arg, "Fast_PSP") == 0) ||
6117 (strcmp(arg, "fast_psp") == 0) ||
6118 (strcmp(arg, "FAST_PSP") == 0))
6120 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6121 // to exclude certain situations.
6122 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6123 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6124 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeFast_PSP;
6125 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeFast_PSP;
6126 pAdapter->StaCfg.DefaultListenCount = 3;
6128 else if ((strcmp(arg, "Legacy_PSP") == 0) ||
6129 (strcmp(arg, "legacy_psp") == 0) ||
6130 (strcmp(arg, "LEGACY_PSP") == 0))
6132 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6133 // to exclude certain situations.
6134 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6135 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6136 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeLegacy_PSP;
6137 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeLegacy_PSP;
6138 pAdapter->StaCfg.DefaultListenCount = 3;
6142 //Default Ndis802_11PowerModeCAM
6143 // clear PSM bit immediately
6144 MlmeSetPsmBit(pAdapter, PWR_ACTIVE);
6145 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6146 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6147 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
6148 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
6151 DBGPRINT(RT_DEBUG_TRACE, ("Set_PSMode_Proc::(PSMode=%ld)\n", pAdapter->StaCfg.WindowsPowerMode));
6161 ==========================================================================
6163 Set WpaSupport flag.
6165 0: Driver ignore wpa_supplicant.
6166 1: wpa_supplicant initiates scanning and AP selection.
6167 2: driver takes care of scanning, AP selection, and IEEE 802.11 association parameters.
6169 TRUE if all parameters are OK, FALSE otherwise
6170 ==========================================================================
6172 INT Set_Wpa_Support(
6173 IN PRTMP_ADAPTER pAd,
6177 if ( simple_strtol(arg, 0, 10) == 0)
6178 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
6179 else if ( simple_strtol(arg, 0, 10) == 1)
6180 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE;
6181 else if ( simple_strtol(arg, 0, 10) == 2)
6182 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE_WITH_WEB_UI;
6184 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
6186 DBGPRINT(RT_DEBUG_TRACE, ("Set_Wpa_Support::(WpaSupplicantUP=%d)\n", pAd->StaCfg.WpaSupplicantUP));
6193 ==========================================================================
6197 pAdapter Pointer to our adapter
6198 wrq Pointer to the ioctl argument
6205 1.) iwpriv ra0 mac 0 ==> read MAC where Addr=0x0
6206 2.) iwpriv ra0 mac 0=12 ==> write MAC where Addr=0x0, value=12
6207 ==========================================================================
6210 IN PRTMP_ADAPTER pAdapter,
6211 IN struct iwreq *wrq)
6219 UCHAR temp[16], temp2[16];
6220 UINT32 macValue = 0;
6223 BOOLEAN bIsPrintAllMAC = FALSE;
6226 memset(msg, 0x00, 1024);
6227 if (wrq->u.data.length > 1) //No parameters.
6229 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6232 //Parsing Read or Write
6237 if ((value = rtstrchr(this_char, '=')) != NULL)
6240 if (!value || !*value)
6243 if(strlen(this_char) > 4)
6246 j = strlen(this_char);
6249 if(this_char[j] > 'f' || this_char[j] < '0')
6254 k = j = strlen(this_char);
6257 this_char[4-k+j] = this_char[j];
6261 this_char[3-k++]='0';
6264 if(strlen(this_char) == 4)
6266 AtoH(this_char, temp, 2);
6267 macAddr = *temp*256 + temp[1];
6268 if (macAddr < 0xFFFF)
6270 RTMP_IO_READ32(pAdapter, macAddr, &macValue);
6271 DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%lx, MacValue=%x\n", macAddr, macValue));
6272 sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr , macValue);
6276 {//Invalid parametes, so default printk all bbp
6279 {//Invalid parametes, so default printk all mac
6280 bIsPrintAllMAC = TRUE;
6288 memcpy(&temp2, value, strlen(value));
6289 temp2[strlen(value)] = '\0';
6292 if((strlen(this_char) > 4) || strlen(temp2) > 8)
6295 j = strlen(this_char);
6298 if(this_char[j] > 'f' || this_char[j] < '0')
6305 if(temp2[j] > 'f' || temp2[j] < '0')
6310 k = j = strlen(this_char);
6313 this_char[4-k+j] = this_char[j];
6317 this_char[3-k++]='0';
6321 k = j = strlen(temp2);
6324 temp2[8-k+j] = temp2[j];
6332 AtoH(this_char, temp, 2);
6333 macAddr = *temp*256 + temp[1];
6335 AtoH(temp2, temp, 4);
6336 macValue = *temp*256*256*256 + temp[1]*256*256 + temp[2]*256 + temp[3];
6339 if (macAddr == (HW_DEBUG_SETTING_BASE + 4))
6341 // 0x2bf4: byte0 non-zero: enable R17 tuning, 0: disable R17 tuning
6342 if (macValue & 0x000000ff)
6344 pAdapter->BbpTuning.bEnable = TRUE;
6345 DBGPRINT(RT_DEBUG_TRACE,("turn on R17 tuning\n"));
6350 pAdapter->BbpTuning.bEnable = FALSE;
6351 R66 = 0x26 + GET_LNA_GAIN(pAdapter);
6352 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R66, (0x26 + GET_LNA_GAIN(pAdapter)));
6353 DBGPRINT(RT_DEBUG_TRACE,("turn off R17 tuning, restore to 0x%02x\n", R66));
6358 DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%02lx, MacValue=0x%x\n", macAddr, macValue));
6360 RTMP_IO_WRITE32(pAdapter, macAddr, macValue);
6361 sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr, macValue);
6367 bIsPrintAllMAC = TRUE;
6373 struct file *file_w;
6374 PCHAR fileName = "MacDump.txt";
6375 mm_segment_t orig_fs;
6381 file_w = filp_open(fileName, O_WRONLY|O_CREAT, 0);
6384 DBGPRINT(RT_DEBUG_TRACE, ("-->2) %s: Error %ld opening %s\n", __func__, -PTR_ERR(file_w), fileName));
6388 if (file_w->f_op && file_w->f_op->write)
6393 while (macAddr <= 0x1800)
6395 RTMP_IO_READ32(pAdapter, macAddr, &macValue);
6396 sprintf(msg, "%08lx = %08X\n", macAddr, macValue);
6398 // write data to file
6399 file_w->f_op->write(file_w, msg, strlen(msg), &file_w->f_pos);
6404 sprintf(msg, "\nDump all MAC values to %s\n", fileName);
6406 filp_close(file_w, NULL);
6411 if(strlen(msg) == 1)
6412 sprintf(msg+strlen(msg), "===>Error command format!");
6414 // Copy the information into the user buffer
6415 wrq->u.data.length = strlen(msg);
6416 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6418 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlMAC\n\n"));
6422 ==========================================================================
6426 pAdapter Pointer to our adapter
6427 wrq Pointer to the ioctl argument
6434 1.) iwpriv ra0 e2p 0 ==> read E2PROM where Addr=0x0
6435 2.) iwpriv ra0 e2p 0=1234 ==> write E2PROM where Addr=0x0, value=1234
6436 ==========================================================================
6438 VOID RTMPIoctlE2PROM(
6439 IN PRTMP_ADAPTER pAdapter,
6440 IN struct iwreq *wrq)
6448 UCHAR temp[16], temp2[16];
6452 BOOLEAN bIsPrintAllE2P = FALSE;
6455 memset(msg, 0x00, 1024);
6456 if (wrq->u.data.length > 1) //No parameters.
6458 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6461 //Parsing Read or Write
6468 if ((value = rtstrchr(this_char, '=')) != NULL)
6471 if (!value || !*value)
6475 if(strlen(this_char) > 4)
6478 j = strlen(this_char);
6481 if(this_char[j] > 'f' || this_char[j] < '0')
6486 k = j = strlen(this_char);
6489 this_char[4-k+j] = this_char[j];
6493 this_char[3-k++]='0';
6496 if(strlen(this_char) == 4)
6498 AtoH(this_char, temp, 2);
6499 eepAddr = *temp*256 + temp[1];
6500 if (eepAddr < 0xFFFF)
6502 RT28xx_EEPROM_READ16(pAdapter, eepAddr, eepValue);
6503 sprintf(msg+strlen(msg), "[0x%04X]:0x%04X ", eepAddr , eepValue);
6506 {//Invalid parametes, so default printk all bbp
6508 bIsPrintAllE2P = TRUE;
6516 memcpy(&temp2, value, strlen(value));
6517 temp2[strlen(value)] = '\0';
6520 if((strlen(this_char) > 4) || strlen(temp2) > 8)
6523 j = strlen(this_char);
6526 if(this_char[j] > 'f' || this_char[j] < '0')
6532 if(temp2[j] > 'f' || temp2[j] < '0')
6537 k = j = strlen(this_char);
6540 this_char[4-k+j] = this_char[j];
6544 this_char[3-k++]='0';
6548 k = j = strlen(temp2);
6551 temp2[4-k+j] = temp2[j];
6558 AtoH(this_char, temp, 2);
6559 eepAddr = *temp*256 + temp[1];
6561 AtoH(temp2, temp, 2);
6562 eepValue = *temp*256 + temp[1];
6564 RT28xx_EEPROM_WRITE16(pAdapter, eepAddr, eepValue);
6565 sprintf(msg+strlen(msg), "[0x%02X]:%02X ", eepAddr, eepValue);
6570 bIsPrintAllE2P = TRUE;
6576 struct file *file_w;
6577 PCHAR fileName = "EEPROMDump.txt";
6578 mm_segment_t orig_fs;
6584 file_w = filp_open(fileName, O_WRONLY|O_CREAT, 0);
6587 DBGPRINT(RT_DEBUG_TRACE, ("-->2) %s: Error %ld opening %s\n", __func__, -PTR_ERR(file_w), fileName));
6591 if (file_w->f_op && file_w->f_op->write)
6596 while (eepAddr <= 0xFE)
6598 RT28xx_EEPROM_READ16(pAdapter, eepAddr, eepValue);
6599 sprintf(msg, "%08x = %04x\n", eepAddr , eepValue);
6601 // write data to file
6602 file_w->f_op->write(file_w, msg, strlen(msg), &file_w->f_pos);
6607 sprintf(msg, "\nDump all EEPROM values to %s\n", fileName);
6609 filp_close(file_w, NULL);
6614 if(strlen(msg) == 1)
6615 sprintf(msg+strlen(msg), "===>Error command format!");
6618 // Copy the information into the user buffer
6619 wrq->u.data.length = strlen(msg);
6620 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6622 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlE2PROM\n"));
6626 ==========================================================================
6628 Read / Write RF register
6630 pAdapter Pointer to our adapter
6631 wrq Pointer to the ioctl argument
6638 1.) iwpriv ra0 rf ==> read all RF registers
6639 2.) iwpriv ra0 rf 1 ==> read RF where RegID=1
6640 3.) iwpriv ra0 rf 1=10 ==> write RF R1=0x10
6641 ==========================================================================
6644 IN PRTMP_ADAPTER pAdapter,
6645 IN struct iwreq *wrq)
6655 BOOLEAN bIsPrintAllRF = FALSE;
6658 memset(msg, 0x00, 2048);
6659 if (wrq->u.data.length > 1) //No parameters.
6661 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6664 //Parsing Read or Write
6669 if ((value = strchr(this_char, '=')) != NULL)
6672 if (!value || !*value)
6674 if (sscanf(this_char, "%d", &(rfId)) == 1)
6678 // In RT2860 ATE mode, we do not load 8051 firmware.
6679 //We must access RF directly.
6680 // For RT2870 ATE mode, ATE_RF_IO_WRITE8(/READ8)_BY_REG_ID are redefined.
6681 // according to Andy, Gary, David require.
6682 // the command rf shall read rf register directly for dubug.
6683 // BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
6684 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
6686 sprintf(msg+strlen(msg), "R%02d[0x%02x]:%02X ", rfId, rfId*2, regRF);
6689 {//Invalid parametes, so default printk all RF
6690 bIsPrintAllRF = TRUE;
6695 { //Invalid parametes, so default printk all RF
6696 bIsPrintAllRF = TRUE;
6702 if ((sscanf(this_char, "%d", &(rfId)) == 1) && (sscanf(value, "%lx", &(rfValue)) == 1))
6706 // In RT2860 ATE mode, we do not load 8051 firmware.
6707 // We should access RF registers directly.
6708 // For RT2870 ATE mode, ATE_RF_IO_WRITE8/READ8_BY_REG_ID are redefined.
6710 // according to Andy, Gary, David require.
6711 // the command RF shall read/write RF register directly for dubug.
6712 //BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
6713 //BBP_IO_WRITE8_BY_REG_ID(pAdapter, (UCHAR)bbpId,(UCHAR) bbpValue);
6714 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
6715 RT30xxWriteRFRegister(pAdapter, (UCHAR)rfId,(UCHAR) rfValue);
6716 //Read it back for showing
6717 //BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
6718 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
6719 sprintf(msg+strlen(msg), "R%02d[0x%02X]:%02X\n", rfId, rfId*2, regRF);
6723 {//Invalid parametes, so default printk all RF
6724 bIsPrintAllRF = TRUE;
6728 { //Invalid parametes, so default printk all RF
6729 bIsPrintAllRF = TRUE;
6734 bIsPrintAllRF = TRUE;
6738 memset(msg, 0x00, 2048);
6740 for (rfId = 0; rfId <= 31; rfId++)
6742 // according to Andy, Gary, David require.
6743 // the command RF shall read/write RF register directly for dubug.
6744 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
6745 sprintf(msg+strlen(msg), "%03d = %02X\n", rfId, regRF);
6747 // Copy the information into the user buffer
6748 DBGPRINT(RT_DEBUG_TRACE, ("strlen(msg)=%d\n", (UINT32)strlen(msg)));
6749 wrq->u.data.length = strlen(msg);
6750 if (copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length))
6752 DBGPRINT(RT_DEBUG_TRACE, ("%s: copy_to_user() fail\n", __func__));
6757 if(strlen(msg) == 1)
6758 sprintf(msg+strlen(msg), "===>Error command format!");
6760 DBGPRINT(RT_DEBUG_TRACE, ("copy to user [msg=%s]\n", msg));
6761 // Copy the information into the user buffer
6762 DBGPRINT(RT_DEBUG_TRACE, ("strlen(msg) =%d\n", (UINT32)strlen(msg)));
6764 // Copy the information into the user buffer
6765 wrq->u.data.length = strlen(msg);
6766 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6769 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlRF\n\n"));
6777 INT Set_TGnWifiTest_Proc(
6778 IN PRTMP_ADAPTER pAd,
6781 if (simple_strtol(arg, 0, 10) == 0)
6782 pAd->StaCfg.bTGnWifiTest = FALSE;
6784 pAd->StaCfg.bTGnWifiTest = TRUE;
6786 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_TGnWifiTest_Proc::(bTGnWifiTest=%d)\n", pAd->StaCfg.bTGnWifiTest));
6790 INT Set_LongRetryLimit_Proc(
6791 IN PRTMP_ADAPTER pAdapter,
6794 TX_RTY_CFG_STRUC tx_rty_cfg;
6795 UCHAR LongRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
6797 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
6798 tx_rty_cfg.field.LongRtyLimit = LongRetryLimit;
6799 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
6800 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_LongRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
6804 INT Set_ShortRetryLimit_Proc(
6805 IN PRTMP_ADAPTER pAdapter,
6808 TX_RTY_CFG_STRUC tx_rty_cfg;
6809 UCHAR ShortRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
6811 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
6812 tx_rty_cfg.field.ShortRtyLimit = ShortRetryLimit;
6813 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
6814 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_ShortRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
6819 INT Show_Adhoc_MacTable_Proc(
6820 IN PRTMP_ADAPTER pAd,
6825 sprintf(extra, "\n");
6827 sprintf(extra + strlen(extra), "HT Operating Mode : %d\n", pAd->CommonCfg.AddHTInfo.AddHtInfo2.OperaionMode);
6829 sprintf(extra + strlen(extra), "\n%-19s%-4s%-4s%-7s%-7s%-7s%-10s%-6s%-6s%-6s%-6s\n",
6830 "MAC", "AID", "BSS", "RSSI0", "RSSI1", "RSSI2", "PhMd", "BW", "MCS", "SGI", "STBC");
6832 for (i=1; i<MAX_LEN_OF_MAC_TABLE; i++)
6834 PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
6836 if (strlen(extra) > (IW_PRIV_SIZE_MASK - 30))
6838 if ((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
6840 sprintf(extra + strlen(extra), "%02X:%02X:%02X:%02X:%02X:%02X ",
6841 pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
6842 pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5]);
6843 sprintf(extra + strlen(extra), "%-4d", (int)pEntry->Aid);
6844 sprintf(extra + strlen(extra), "%-4d", (int)pEntry->apidx);
6845 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi0);
6846 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi1);
6847 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi2);
6848 sprintf(extra + strlen(extra), "%-10s", GetPhyMode(pEntry->HTPhyMode.field.MODE));
6849 sprintf(extra + strlen(extra), "%-6s", GetBW(pEntry->HTPhyMode.field.BW));
6850 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.MCS);
6851 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.ShortGI);
6852 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.STBC);
6853 sprintf(extra + strlen(extra), "%-10d, %d, %d%%\n", pEntry->DebugFIFOCount, pEntry->DebugTxCount,
6854 (pEntry->DebugTxCount) ? ((pEntry->DebugTxCount-pEntry->DebugFIFOCount)*100/pEntry->DebugTxCount) : 0);
6855 sprintf(extra, "%s\n", extra);