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[];
54 typedef struct PACKED _RT_VERSION_INFO{
60 UINT DriverBuildMonth;
62 } RT_VERSION_INFO, *PRT_VERSION_INFO;
64 struct iw_priv_args privtab[] = {
66 IW_PRIV_TYPE_CHAR | 1024, 0,
69 { RTPRIV_IOCTL_SHOW, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
71 /* --- sub-ioctls definitions --- */
73 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "connStatus" },
75 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "driverVer" },
77 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "bainfo" },
79 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "descinfo" },
81 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "radio_off" },
83 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "radio_on" },
85 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "show" },
86 { SHOW_ADHOC_ENTRY_INFO,
87 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "adhocEntry" },
88 /* --- sub-ioctls relations --- */
90 { RTPRIV_IOCTL_STATISTICS,
91 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
93 { RTPRIV_IOCTL_GSITESURVEY,
94 0, IW_PRIV_TYPE_CHAR | 1024,
100 static __s32 ralinkrate[] =
101 {2, 4, 11, 22, // CCK
102 12, 18, 24, 36, 48, 72, 96, 108, // OFDM
103 13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260, // 20MHz, 800ns GI, MCS: 0 ~ 15
104 39, 78, 117, 156, 234, 312, 351, 390, // 20MHz, 800ns GI, MCS: 16 ~ 23
105 27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540, // 40MHz, 800ns GI, MCS: 0 ~ 15
106 81, 162, 243, 324, 486, 648, 729, 810, // 40MHz, 800ns GI, MCS: 16 ~ 23
107 14, 29, 43, 57, 87, 115, 130, 144, 29, 59, 87, 115, 173, 230, 260, 288, // 20MHz, 400ns GI, MCS: 0 ~ 15
108 43, 87, 130, 173, 260, 317, 390, 433, // 20MHz, 400ns GI, MCS: 16 ~ 23
109 30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600, // 40MHz, 400ns GI, MCS: 0 ~ 15
110 90, 180, 270, 360, 540, 720, 810, 900};
113 IN PRTMP_ADAPTER pAdapter,
117 INT Set_WmmCapable_Proc(
118 IN PRTMP_ADAPTER pAd,
122 INT Set_NetworkType_Proc(
123 IN PRTMP_ADAPTER pAdapter,
126 INT Set_AuthMode_Proc(
127 IN PRTMP_ADAPTER pAdapter,
130 INT Set_EncrypType_Proc(
131 IN PRTMP_ADAPTER pAdapter,
134 INT Set_DefaultKeyID_Proc(
135 IN PRTMP_ADAPTER pAdapter,
139 IN PRTMP_ADAPTER pAdapter,
143 IN PRTMP_ADAPTER pAdapter,
147 IN PRTMP_ADAPTER pAdapter,
151 IN PRTMP_ADAPTER pAdapter,
155 IN PRTMP_ADAPTER pAdapter,
160 IN PRTMP_ADAPTER pAdapter,
164 IN PRTMP_ADAPTER pAd,
167 NDIS_STATUS RTMPWPANoneAddKeyProc(
168 IN PRTMP_ADAPTER pAd,
171 INT Set_FragTest_Proc(
172 IN PRTMP_ADAPTER pAdapter,
175 INT Set_TGnWifiTest_Proc(
176 IN PRTMP_ADAPTER pAd,
179 INT Set_LongRetryLimit_Proc(
180 IN PRTMP_ADAPTER pAdapter,
183 INT Set_ShortRetryLimit_Proc(
184 IN PRTMP_ADAPTER pAdapter,
189 INT Show_Adhoc_MacTable_Proc(
190 IN PRTMP_ADAPTER pAd,
193 INT Set_BeaconLostTime_Proc(
194 IN PRTMP_ADAPTER pAd,
197 INT Set_AutoRoaming_Proc(
198 IN PRTMP_ADAPTER pAd,
201 INT Set_SiteSurvey_Proc(
202 IN PRTMP_ADAPTER pAd,
205 INT Set_ForceTxBurst_Proc(
206 IN PRTMP_ADAPTER pAd,
211 INT (*set_proc)(PRTMP_ADAPTER pAdapter, PSTRING arg);
212 } *PRTMP_PRIVATE_SET_PROC, RTMP_PRIVATE_SUPPORT_PROC[] = {
213 {"DriverVersion", Set_DriverVersion_Proc},
214 {"CountryRegion", Set_CountryRegion_Proc},
215 {"CountryRegionABand", Set_CountryRegionABand_Proc},
216 {"SSID", Set_SSID_Proc},
217 {"WirelessMode", Set_WirelessMode_Proc},
218 {"TxBurst", Set_TxBurst_Proc},
219 {"TxPreamble", Set_TxPreamble_Proc},
220 {"TxPower", Set_TxPower_Proc},
221 {"Channel", Set_Channel_Proc},
222 {"BGProtection", Set_BGProtection_Proc},
223 {"RTSThreshold", Set_RTSThreshold_Proc},
224 {"FragThreshold", Set_FragThreshold_Proc},
225 {"HtBw", Set_HtBw_Proc},
226 {"HtMcs", Set_HtMcs_Proc},
227 {"HtGi", Set_HtGi_Proc},
228 {"HtOpMode", Set_HtOpMode_Proc},
229 {"HtExtcha", Set_HtExtcha_Proc},
230 {"HtMpduDensity", Set_HtMpduDensity_Proc},
231 {"HtBaWinSize", Set_HtBaWinSize_Proc},
232 {"HtRdg", Set_HtRdg_Proc},
233 {"HtAmsdu", Set_HtAmsdu_Proc},
234 {"HtAutoBa", Set_HtAutoBa_Proc},
235 {"HtBaDecline", Set_BADecline_Proc},
236 {"HtProtect", Set_HtProtect_Proc},
237 {"HtMimoPs", Set_HtMimoPs_Proc},
238 {"HtDisallowTKIP", Set_HtDisallowTKIP_Proc},
239 #ifdef AGGREGATION_SUPPORT
240 {"PktAggregate", Set_PktAggregate_Proc},
241 #endif // AGGREGATION_SUPPORT //
244 {"WmmCapable", Set_WmmCapable_Proc},
246 {"IEEE80211H", Set_IEEE80211H_Proc},
247 {"NetworkType", Set_NetworkType_Proc},
248 {"AuthMode", Set_AuthMode_Proc},
249 {"EncrypType", Set_EncrypType_Proc},
250 {"DefaultKeyID", Set_DefaultKeyID_Proc},
251 {"Key1", Set_Key1_Proc},
252 {"Key2", Set_Key2_Proc},
253 {"Key3", Set_Key3_Proc},
254 {"Key4", Set_Key4_Proc},
255 {"WPAPSK", Set_WPAPSK_Proc},
256 {"ResetCounter", Set_ResetStatCounter_Proc},
257 {"PSMode", Set_PSMode_Proc},
259 {"Debug", Set_Debug_Proc},
263 {"WpaSupport", Set_Wpa_Support},
269 {"FixedTxMode", Set_FixedTxMode_Proc},
270 {"TGnWifiTest", Set_TGnWifiTest_Proc},
271 {"ForceGF", Set_ForceGF_Proc},
272 {"LongRetry", Set_LongRetryLimit_Proc},
273 {"ShortRetry", Set_ShortRetryLimit_Proc},
275 //2008/09/11:KH add to support efuse<--
277 #ifdef RTMP_EFUSE_SUPPORT
278 {"efuseFreeNumber", set_eFuseGetFreeBlockCount_Proc},
279 {"efuseDump", set_eFusedump_Proc},
280 {"efuseLoadFromBin", set_eFuseLoadFromBin_Proc},
281 {"efuseBufferModeWriteBack", set_eFuseBufferModeWriteBack_Proc},
282 #endif // RTMP_EFUSE_SUPPORT //
284 //2008/09/11:KH add to support efuse-->
285 {"BeaconLostTime", Set_BeaconLostTime_Proc},
286 {"AutoRoaming", Set_AutoRoaming_Proc},
287 {"SiteSurvey", Set_SiteSurvey_Proc},
288 {"ForceTxBurst", Set_ForceTxBurst_Proc},
295 IN PRTMP_ADAPTER pAd,
296 IN PNDIS_802_11_KEY pKey)
299 MAC_TABLE_ENTRY *pEntry;
301 DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey ------>\n"));
303 if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
305 if (pKey->KeyIndex & 0x80000000)
307 if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
309 NdisZeroMemory(pAd->StaCfg.PMK, 32);
310 NdisMoveMemory(pAd->StaCfg.PMK, pKey->KeyMaterial, pKey->KeyLength);
314 NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));
315 pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
316 NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, pKey->KeyMaterial, LEN_TKIP_EK);
318 if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
320 NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
321 NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
325 NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
326 NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
329 // Decide its ChiperAlg
330 if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
331 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
332 else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)
333 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
335 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_NONE;
337 // Update these related information to MAC_TABLE_ENTRY
338 pEntry = &pAd->MacTab.Content[BSSID_WCID];
339 NdisMoveMemory(pEntry->PairwiseKey.Key, pAd->SharedKey[BSS0][0].Key, LEN_TKIP_EK);
340 NdisMoveMemory(pEntry->PairwiseKey.RxMic, pAd->SharedKey[BSS0][0].RxMic, LEN_TKIP_RXMICK);
341 NdisMoveMemory(pEntry->PairwiseKey.TxMic, pAd->SharedKey[BSS0][0].TxMic, LEN_TKIP_TXMICK);
342 pEntry->PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;
344 // Update pairwise key information to ASIC Shared Key Table
345 AsicAddSharedKeyEntry(pAd,
348 pAd->SharedKey[BSS0][0].CipherAlg,
349 pAd->SharedKey[BSS0][0].Key,
350 pAd->SharedKey[BSS0][0].TxMic,
351 pAd->SharedKey[BSS0][0].RxMic);
353 // Update ASIC WCID attribute table and IVEIV table
354 RTMPAddWcidAttributeEntry(pAd,
357 pAd->SharedKey[BSS0][0].CipherAlg,
360 if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
362 // set 802.1x port control
363 //pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
364 STA_PORT_SECURED(pAd);
366 // Indicate Connected for GUI
367 pAd->IndicateMediaState = NdisMediaStateConnected;
373 pAd->StaCfg.DefaultKeyId = (pKey->KeyIndex & 0xFF);
374 NdisZeroMemory(&pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId], sizeof(CIPHER_KEY));
375 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].KeyLen = LEN_TKIP_EK;
376 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key, pKey->KeyMaterial, LEN_TKIP_EK);
378 if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
380 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
381 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
385 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
386 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
389 // Update Shared Key CipherAlg
390 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_NONE;
391 if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
392 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_TKIP;
393 else if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)
394 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_AES;
396 // Update group key information to ASIC Shared Key Table
397 AsicAddSharedKeyEntry(pAd,
399 pAd->StaCfg.DefaultKeyId,
400 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
401 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key,
402 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic,
403 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic);
405 // Update ASIC WCID attribute table and IVEIV table
406 RTMPAddWcidAttributeEntry(pAd,
408 pAd->StaCfg.DefaultKeyId,
409 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
412 // set 802.1x port control
413 //pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
414 STA_PORT_SECURED(pAd);
416 // Indicate Connected for GUI
417 pAd->IndicateMediaState = NdisMediaStateConnected;
420 else // dynamic WEP from wpa_supplicant
425 if(pKey->KeyLength == 32)
428 KeyIdx = pKey->KeyIndex & 0x0fffffff;
432 // it is a default shared key, for Pairwise key setting
433 if (pKey->KeyIndex & 0x80000000)
435 pEntry = MacTableLookup(pAd, pKey->BSSID);
439 DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey: Set Pair-wise Key\n"));
441 // set key material and key length
442 pEntry->PairwiseKey.KeyLen = (UCHAR)pKey->KeyLength;
443 NdisMoveMemory(pEntry->PairwiseKey.Key, &pKey->KeyMaterial, pKey->KeyLength);
446 if (pKey->KeyLength == 5)
447 pEntry->PairwiseKey.CipherAlg = CIPHER_WEP64;
449 pEntry->PairwiseKey.CipherAlg = CIPHER_WEP128;
451 // Add Pair-wise key to Asic
452 AsicAddPairwiseKeyEntry(
456 &pEntry->PairwiseKey);
458 // update WCID attribute table and IVEIV table for this entry
459 RTMPAddWcidAttributeEntry(
462 KeyIdx, // The value may be not zero
463 pEntry->PairwiseKey.CipherAlg,
470 // Default key for tx (shared key)
471 pAd->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
473 // set key material and key length
474 pAd->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pKey->KeyLength;
475 NdisMoveMemory(pAd->SharedKey[BSS0][KeyIdx].Key, &pKey->KeyMaterial, pKey->KeyLength);
478 if (pKey->KeyLength == 5)
479 pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP64;
481 pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP128;
483 CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg;
484 Key = pAd->SharedKey[BSS0][KeyIdx].Key;
486 // Set Group key material to Asic
487 AsicAddSharedKeyEntry(pAd, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
489 // Update WCID attribute table and IVEIV table for this group key table
490 RTMPAddWcidAttributeEntry(pAd, BSS0, KeyIdx, CipherAlg, NULL);
499 char * rtstrchr(const char * s, int c)
501 for(; *s != (char) c; ++s)
508 This is required for LinEX2004/kernel2.6.7 to provide iwlist scanning function
512 rt_ioctl_giwname(struct net_device *dev,
513 struct iw_request_info *info,
514 char *name, char *extra)
516 strncpy(name, "Ralink STA", IFNAMSIZ);
517 // RT2870 2.1.0.0 uses "RT2870 Wireless"
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 = NULL;
528 GET_PAD_FROM_NET_DEV(pAdapter, dev);
530 //check if the interface is down
531 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
533 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
541 if((freq->e == 0) && (freq->m <= 1000))
542 chan = freq->m; // Setting by channel number
544 MAP_KHZ_TO_CHANNEL_ID( (freq->m /100) , chan); // Setting by frequency - search the table , like 2.412G, 2.422G,
546 if (ChannelSanity(pAdapter, chan) == TRUE)
548 pAdapter->CommonCfg.Channel = chan;
549 DBGPRINT(RT_DEBUG_ERROR, ("==>rt_ioctl_siwfreq::SIOCSIWFREQ[cmd=0x%x] (Channel=%d)\n", SIOCSIWFREQ, pAdapter->CommonCfg.Channel));
556 int rt_ioctl_giwfreq(struct net_device *dev,
557 struct iw_request_info *info,
558 struct iw_freq *freq, char *extra)
560 PRTMP_ADAPTER pAdapter = NULL;
564 GET_PAD_FROM_NET_DEV(pAdapter, dev);
566 ch = pAdapter->CommonCfg.Channel;
568 DBGPRINT(RT_DEBUG_TRACE,("==>rt_ioctl_giwfreq %d\n", ch));
570 MAP_CHANNEL_ID_TO_KHZ(ch, m);
576 int rt_ioctl_siwmode(struct net_device *dev,
577 struct iw_request_info *info,
578 __u32 *mode, char *extra)
580 PRTMP_ADAPTER pAdapter = NULL;
582 GET_PAD_FROM_NET_DEV(pAdapter, dev);
584 //check if the interface is down
585 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
587 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
594 Set_NetworkType_Proc(pAdapter, "Adhoc");
597 Set_NetworkType_Proc(pAdapter, "Infra");
599 case IW_MODE_MONITOR:
600 Set_NetworkType_Proc(pAdapter, "Monitor");
603 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_siwmode::SIOCSIWMODE (unknown %d)\n", *mode));
607 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
608 pAdapter->StaCfg.WpaState = SS_NOTUSE;
613 int rt_ioctl_giwmode(struct net_device *dev,
614 struct iw_request_info *info,
615 __u32 *mode, char *extra)
617 PRTMP_ADAPTER pAdapter = NULL;
619 GET_PAD_FROM_NET_DEV(pAdapter, dev);
621 if (ADHOC_ON(pAdapter))
622 *mode = IW_MODE_ADHOC;
623 else if (INFRA_ON(pAdapter))
624 *mode = IW_MODE_INFRA;
625 else if (MONITOR_ON(pAdapter))
627 *mode = IW_MODE_MONITOR;
630 *mode = IW_MODE_AUTO;
632 DBGPRINT(RT_DEBUG_TRACE, ("==>rt_ioctl_giwmode(mode=%d)\n", *mode));
636 int rt_ioctl_siwsens(struct net_device *dev,
637 struct iw_request_info *info,
638 char *name, char *extra)
640 PRTMP_ADAPTER pAdapter = NULL;
642 GET_PAD_FROM_NET_DEV(pAdapter, dev);
644 //check if the interface is down
645 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
647 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
654 int rt_ioctl_giwsens(struct net_device *dev,
655 struct iw_request_info *info,
656 char *name, char *extra)
661 int rt_ioctl_giwrange(struct net_device *dev,
662 struct iw_request_info *info,
663 struct iw_point *data, char *extra)
665 PRTMP_ADAPTER pAdapter = NULL;
666 struct iw_range *range = (struct iw_range *) extra;
670 GET_PAD_FROM_NET_DEV(pAdapter, dev);
672 DBGPRINT(RT_DEBUG_TRACE ,("===>rt_ioctl_giwrange\n"));
673 data->length = sizeof(struct iw_range);
674 memset(range, 0, sizeof(struct iw_range));
676 range->txpower_capa = IW_TXPOW_DBM;
678 if (INFRA_ON(pAdapter)||ADHOC_ON(pAdapter))
680 range->min_pmp = 1 * 1024;
681 range->max_pmp = 65535 * 1024;
682 range->min_pmt = 1 * 1024;
683 range->max_pmt = 1000 * 1024;
684 range->pmp_flags = IW_POWER_PERIOD;
685 range->pmt_flags = IW_POWER_TIMEOUT;
686 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT |
687 IW_POWER_UNICAST_R | IW_POWER_ALL_R;
690 range->we_version_compiled = WIRELESS_EXT;
691 range->we_version_source = 14;
693 range->retry_capa = IW_RETRY_LIMIT;
694 range->retry_flags = IW_RETRY_LIMIT;
695 range->min_retry = 0;
696 range->max_retry = 255;
698 range->num_channels = pAdapter->ChannelListNum;
701 for (i = 1; i <= range->num_channels; i++)
704 range->freq[val].i = pAdapter->ChannelList[i-1].Channel;
705 MAP_CHANNEL_ID_TO_KHZ(pAdapter->ChannelList[i-1].Channel, m);
706 range->freq[val].m = m * 100; /* OS_HZ */
708 range->freq[val].e = 1;
710 if (val == IW_MAX_FREQUENCIES)
713 range->num_frequency = val;
715 range->max_qual.qual = 100; /* what is correct max? This was not
716 * documented exactly. At least
717 * 69 has been observed. */
718 range->max_qual.level = 0; /* dB */
719 range->max_qual.noise = 0; /* dB */
721 /* What would be suitable values for "average/typical" qual? */
722 range->avg_qual.qual = 20;
723 range->avg_qual.level = -60;
724 range->avg_qual.noise = -95;
725 range->sensitivity = 3;
727 range->max_encoding_tokens = NR_WEP_KEYS;
728 range->num_encoding_sizes = 2;
729 range->encoding_size[0] = 5;
730 range->encoding_size[1] = 13;
733 range->max_rts = 2347;
734 range->min_frag = 256;
735 range->max_frag = 2346;
737 /* IW_ENC_CAPA_* bit field */
738 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
739 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
744 int rt_ioctl_siwap(struct net_device *dev,
745 struct iw_request_info *info,
746 struct sockaddr *ap_addr, char *extra)
748 PRTMP_ADAPTER pAdapter = NULL;
749 NDIS_802_11_MAC_ADDRESS Bssid;
751 GET_PAD_FROM_NET_DEV(pAdapter, dev);
753 //check if the interface is down
754 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
756 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
760 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
762 RTMP_MLME_RESET_STATE_MACHINE(pAdapter);
763 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
766 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
767 // this request, because this request is initiated by NDIS.
768 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
769 // Prevent to connect AP again in STAMlmePeriodicExec
770 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
772 memset(Bssid, 0, MAC_ADDR_LEN);
773 memcpy(Bssid, ap_addr->sa_data, MAC_ADDR_LEN);
774 MlmeEnqueue(pAdapter,
775 MLME_CNTL_STATE_MACHINE,
777 sizeof(NDIS_802_11_MAC_ADDRESS),
780 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCSIWAP %02x:%02x:%02x:%02x:%02x:%02x\n",
781 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
786 int rt_ioctl_giwap(struct net_device *dev,
787 struct iw_request_info *info,
788 struct sockaddr *ap_addr, char *extra)
790 PRTMP_ADAPTER pAdapter = NULL;
792 GET_PAD_FROM_NET_DEV(pAdapter, dev);
794 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
796 ap_addr->sa_family = ARPHRD_ETHER;
797 memcpy(ap_addr->sa_data, &pAdapter->CommonCfg.Bssid, ETH_ALEN);
800 else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
802 ap_addr->sa_family = ARPHRD_ETHER;
803 memcpy(ap_addr->sa_data, &pAdapter->MlmeAux.Bssid, ETH_ALEN);
807 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIWAP(=EMPTY)\n"));
815 * Units are in db above the noise floor. That means the
816 * rssi values reported in the tx/rx descriptors in the
817 * driver are the SNR expressed in db.
819 * If you assume that the noise floor is -95, which is an
820 * excellent assumption 99.5 % of the time, then you can
821 * derive the absolute signal level (i.e. -95 + rssi).
822 * There are some other slight factors to take into account
823 * depending on whether the rssi measurement is from 11b,
824 * 11g, or 11a. These differences are at most 2db and
827 * NB: various calculations are based on the orinoco/wavelan
828 * drivers for compatibility
830 static void set_quality(PRTMP_ADAPTER pAdapter,
831 struct iw_quality *iq,
838 ChannelQuality = 100;
839 else if (rssi >= -80) // between -50 ~ -80dbm
840 ChannelQuality = (__u8)(24 + ((rssi + 80) * 26)/10);
841 else if (rssi >= -90) // between -80 ~ -90dbm
842 ChannelQuality = (__u8)((rssi + 90) * 26)/10;
846 iq->qual = (__u8)ChannelQuality;
848 iq->level = (__u8)(rssi);
849 iq->noise = (pAdapter->BbpWriteLatch[66] > pAdapter->BbpTuning.FalseCcaUpperThreshold) ? ((__u8)pAdapter->BbpTuning.FalseCcaUpperThreshold) : ((__u8) pAdapter->BbpWriteLatch[66]); // noise level (dBm)
850 iq->noise += 256 - 143;
851 iq->updated = pAdapter->iw_stats.qual.updated;
854 int rt_ioctl_iwaplist(struct net_device *dev,
855 struct iw_request_info *info,
856 struct iw_point *data, char *extra)
858 PRTMP_ADAPTER pAdapter = NULL;
860 struct sockaddr addr[IW_MAX_AP];
861 struct iw_quality qual[IW_MAX_AP];
864 GET_PAD_FROM_NET_DEV(pAdapter, dev);
866 //check if the interface is down
867 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
869 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
875 for (i = 0; i <IW_MAX_AP ; i++)
877 if (i >= pAdapter->ScanTab.BssNr)
879 addr[i].sa_family = ARPHRD_ETHER;
880 memcpy(addr[i].sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
881 set_quality(pAdapter, &qual[i], pAdapter->ScanTab.BssEntry[i].Rssi);
884 memcpy(extra, &addr, i*sizeof(addr[0]));
885 data->flags = 1; /* signal quality present (sort of) */
886 memcpy(extra + i*sizeof(addr[0]), &qual, i*sizeof(qual[i]));
891 int rt_ioctl_siwscan(struct net_device *dev,
892 struct iw_request_info *info,
893 struct iw_point *data, char *extra)
895 PRTMP_ADAPTER pAdapter = NULL;
898 int Status = NDIS_STATUS_SUCCESS;
900 GET_PAD_FROM_NET_DEV(pAdapter, dev);
902 //check if the interface is down
903 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
905 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
909 if (MONITOR_ON(pAdapter))
911 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
916 if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
918 pAdapter->StaCfg.WpaSupplicantScanCount++;
921 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
922 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
923 return NDIS_STATUS_SUCCESS;
927 if ((pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE) &&
928 (pAdapter->StaCfg.WpaSupplicantScanCount > 3))
930 DBGPRINT(RT_DEBUG_TRACE, ("!!! WpaSupplicantScanCount > 3\n"));
931 Status = NDIS_STATUS_SUCCESS;
935 if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
936 ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
937 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) &&
938 (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
940 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
941 Status = NDIS_STATUS_SUCCESS;
945 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
947 RTMP_MLME_RESET_STATE_MACHINE(pAdapter);
948 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
951 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
952 // this request, because this request is initiated by NDIS.
953 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
954 // Reset allowed scan retries
955 pAdapter->StaCfg.ScanCnt = 0;
956 pAdapter->StaCfg.LastScanTime = Now;
958 MlmeEnqueue(pAdapter,
959 MLME_CNTL_STATE_MACHINE,
960 OID_802_11_BSSID_LIST_SCAN,
964 Status = NDIS_STATUS_SUCCESS;
965 RTMP_MLME_HANDLER(pAdapter);
967 return NDIS_STATUS_SUCCESS;
970 int rt_ioctl_giwscan(struct net_device *dev,
971 struct iw_request_info *info,
972 struct iw_point *data, char *extra)
974 PRTMP_ADAPTER pAdapter = NULL;
976 PSTRING current_ev = extra, previous_ev = extra;
979 STRING custom[MAX_CUSTOM_LEN] = {0};
982 GET_PAD_FROM_NET_DEV(pAdapter, dev);
984 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
987 * Still scanning, indicate the caller should try again.
992 if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
994 pAdapter->StaCfg.WpaSupplicantScanCount = 0;
997 if (pAdapter->ScanTab.BssNr == 0)
1003 if (data->length > 0)
1004 end_buf = extra + data->length;
1006 end_buf = extra + IW_SCAN_MAX_DATA;
1008 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
1010 if (current_ev >= end_buf)
1016 //================================
1017 memset(&iwe, 0, sizeof(iwe));
1018 iwe.cmd = SIOCGIWAP;
1019 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1020 memcpy(iwe.u.ap_addr.sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, ETH_ALEN);
1022 previous_ev = current_ev;
1023 current_ev = iwe_stream_add_event(info, current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);
1024 if (current_ev == previous_ev)
1029 it will show scanned AP's WirelessMode .
1038 memset(&iwe, 0, sizeof(iwe));
1039 iwe.cmd = SIOCGIWNAME;
1043 PBSS_ENTRY pBssEntry=&pAdapter->ScanTab.BssEntry[i];
1044 BOOLEAN isGonly=FALSE;
1047 if (pBssEntry->Channel>14)
1049 if (pBssEntry->HtCapabilityLen!=0)
1050 strcpy(iwe.u.name,"802.11a/n");
1052 strcpy(iwe.u.name,"802.11a");
1057 if one of non B mode rate is set supported rate . it mean G only.
1059 for (rateCnt=0;rateCnt<pBssEntry->SupRateLen;rateCnt++)
1062 6Mbps(140) 9Mbps(146) and >=12Mbps(152) are supported rate , it mean G only.
1064 if (pBssEntry->SupRate[rateCnt]==140 || pBssEntry->SupRate[rateCnt]==146 || pBssEntry->SupRate[rateCnt]>=152)
1068 for (rateCnt=0;rateCnt<pBssEntry->ExtRateLen;rateCnt++)
1070 if (pBssEntry->ExtRate[rateCnt]==140 || pBssEntry->ExtRate[rateCnt]==146 || pBssEntry->ExtRate[rateCnt]>=152)
1075 if (pBssEntry->HtCapabilityLen!=0)
1078 strcpy(iwe.u.name,"802.11g/n");
1080 strcpy(iwe.u.name,"802.11b/g/n");
1085 strcpy(iwe.u.name,"802.11g");
1088 if (pBssEntry->SupRateLen==4 && pBssEntry->ExtRateLen==0)
1089 strcpy(iwe.u.name,"802.11b");
1091 strcpy(iwe.u.name,"802.11b/g");
1097 previous_ev = current_ev;
1098 current_ev = iwe_stream_add_event(info, current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);
1099 if (current_ev == previous_ev)
1103 //================================
1104 memset(&iwe, 0, sizeof(iwe));
1105 iwe.cmd = SIOCGIWESSID;
1106 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].SsidLen;
1107 iwe.u.data.flags = 1;
1109 previous_ev = current_ev;
1110 current_ev = iwe_stream_add_point(info, current_ev,end_buf, &iwe, (PSTRING) pAdapter->ScanTab.BssEntry[i].Ssid);
1111 if (current_ev == previous_ev)
1115 //================================
1116 memset(&iwe, 0, sizeof(iwe));
1117 iwe.cmd = SIOCGIWMODE;
1118 if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11IBSS)
1120 iwe.u.mode = IW_MODE_ADHOC;
1122 else if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11Infrastructure)
1124 iwe.u.mode = IW_MODE_INFRA;
1128 iwe.u.mode = IW_MODE_AUTO;
1130 iwe.len = IW_EV_UINT_LEN;
1132 previous_ev = current_ev;
1133 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
1134 if (current_ev == previous_ev)
1137 //Channel and Frequency
1138 //================================
1139 memset(&iwe, 0, sizeof(iwe));
1140 iwe.cmd = SIOCGIWFREQ;
1141 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
1142 iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
1144 iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
1148 previous_ev = current_ev;
1149 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
1150 if (current_ev == previous_ev)
1153 //Add quality statistics
1154 //================================
1155 memset(&iwe, 0, sizeof(iwe));
1157 iwe.u.qual.level = 0;
1158 iwe.u.qual.noise = 0;
1159 set_quality(pAdapter, &iwe.u.qual, pAdapter->ScanTab.BssEntry[i].Rssi);
1160 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
1161 if (current_ev == previous_ev)
1165 //================================
1166 memset(&iwe, 0, sizeof(iwe));
1167 iwe.cmd = SIOCGIWENCODE;
1168 if (CAP_IS_PRIVACY_ON (pAdapter->ScanTab.BssEntry[i].CapabilityInfo ))
1169 iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1171 iwe.u.data.flags = IW_ENCODE_DISABLED;
1173 previous_ev = current_ev;
1174 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);
1175 if (current_ev == previous_ev)
1179 //================================
1180 if (pAdapter->ScanTab.BssEntry[i].SupRateLen)
1182 UCHAR tmpRate = pAdapter->ScanTab.BssEntry[i].SupRate[pAdapter->ScanTab.BssEntry[i].SupRateLen-1];
1183 memset(&iwe, 0, sizeof(iwe));
1184 iwe.cmd = SIOCGIWRATE;
1185 current_val = current_ev + IW_EV_LCP_LEN;
1186 if (tmpRate == 0x82)
1187 iwe.u.bitrate.value = 1 * 1000000;
1188 else if (tmpRate == 0x84)
1189 iwe.u.bitrate.value = 2 * 1000000;
1190 else if (tmpRate == 0x8B)
1191 iwe.u.bitrate.value = 5.5 * 1000000;
1192 else if (tmpRate == 0x96)
1193 iwe.u.bitrate.value = 11 * 1000000;
1195 iwe.u.bitrate.value = (tmpRate/2) * 1000000;
1197 if (tmpRate == 0x6c && pAdapter->ScanTab.BssEntry[i].HtCapabilityLen > 0)
1199 int rate_count = sizeof(ralinkrate)/sizeof(__s32);
1200 HT_CAP_INFO capInfo = pAdapter->ScanTab.BssEntry[i].HtCapability.HtCapInfo;
1201 int shortGI = capInfo.ChannelWidth ? capInfo.ShortGIfor40 : capInfo.ShortGIfor20;
1202 int maxMCS = pAdapter->ScanTab.BssEntry[i].HtCapability.MCSSet[1] ? 15 : 7;
1203 int rate_index = 12 + ((UCHAR)capInfo.ChannelWidth * 24) + ((UCHAR)shortGI *48) + ((UCHAR)maxMCS);
1206 if (rate_index > rate_count)
1207 rate_index = rate_count;
1208 iwe.u.bitrate.value = ralinkrate[rate_index] * 500000;
1211 iwe.u.bitrate.disabled = 0;
1212 current_val = iwe_stream_add_value(info, current_ev,
1213 current_val, end_buf, &iwe,
1216 if((current_val-current_ev)>IW_EV_LCP_LEN)
1217 current_ev = current_val;
1223 if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
1225 memset(&iwe, 0, sizeof(iwe));
1226 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1227 memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].WpaIE.IE[0]),
1228 pAdapter->ScanTab.BssEntry[i].WpaIE.IELen);
1229 iwe.cmd = IWEVGENIE;
1230 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].WpaIE.IELen;
1231 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, custom);
1232 if (current_ev == previous_ev)
1237 if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
1239 memset(&iwe, 0, sizeof(iwe));
1240 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1241 memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].RsnIE.IE[0]),
1242 pAdapter->ScanTab.BssEntry[i].RsnIE.IELen);
1243 iwe.cmd = IWEVGENIE;
1244 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].RsnIE.IELen;
1245 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, custom);
1246 if (current_ev == previous_ev)
1251 data->length = current_ev - extra;
1252 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
1253 DBGPRINT(RT_DEBUG_ERROR ,("===>rt_ioctl_giwscan. %d(%d) BSS returned, data->length = %d\n",i , pAdapter->ScanTab.BssNr, data->length));
1257 int rt_ioctl_siwessid(struct net_device *dev,
1258 struct iw_request_info *info,
1259 struct iw_point *data, char *essid)
1261 PRTMP_ADAPTER pAdapter = NULL;
1263 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1265 //check if the interface is down
1266 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1268 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1274 PSTRING pSsidString = NULL;
1276 // Includes null character.
1277 if (data->length > (IW_ESSID_MAX_SIZE + 1))
1280 pSsidString = kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
1283 NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
1284 NdisMoveMemory(pSsidString, essid, data->length);
1285 if (Set_SSID_Proc(pAdapter, pSsidString) == FALSE)
1294 if (Set_SSID_Proc(pAdapter, "") == FALSE)
1300 int rt_ioctl_giwessid(struct net_device *dev,
1301 struct iw_request_info *info,
1302 struct iw_point *data, char *essid)
1304 PRTMP_ADAPTER pAdapter = NULL;
1306 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1309 if (MONITOR_ON(pAdapter))
1315 if (OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED))
1317 DBGPRINT(RT_DEBUG_TRACE ,("MediaState is connected\n"));
1318 data->length = pAdapter->CommonCfg.SsidLen;
1319 memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
1323 else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
1325 data->length = pAdapter->CommonCfg.SsidLen;
1326 memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
1328 #endif // RTMP_MAC_USB //
1330 {//the ANY ssid was specified
1332 DBGPRINT(RT_DEBUG_TRACE ,("MediaState is not connected, ess\n"));
1339 int rt_ioctl_siwnickn(struct net_device *dev,
1340 struct iw_request_info *info,
1341 struct iw_point *data, char *nickname)
1343 PRTMP_ADAPTER pAdapter = NULL;
1345 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1347 //check if the interface is down
1348 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1350 DBGPRINT(RT_DEBUG_TRACE ,("INFO::Network is down!\n"));
1354 if (data->length > IW_ESSID_MAX_SIZE)
1357 memset(pAdapter->nickname, 0, IW_ESSID_MAX_SIZE + 1);
1358 memcpy(pAdapter->nickname, nickname, data->length);
1364 int rt_ioctl_giwnickn(struct net_device *dev,
1365 struct iw_request_info *info,
1366 struct iw_point *data, char *nickname)
1368 PRTMP_ADAPTER pAdapter = NULL;
1370 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1372 if (data->length > strlen((PSTRING) pAdapter->nickname) + 1)
1373 data->length = strlen((PSTRING) pAdapter->nickname) + 1;
1374 if (data->length > 0) {
1375 memcpy(nickname, pAdapter->nickname, data->length-1);
1376 nickname[data->length-1] = '\0';
1381 int rt_ioctl_siwrts(struct net_device *dev,
1382 struct iw_request_info *info,
1383 struct iw_param *rts, char *extra)
1385 PRTMP_ADAPTER pAdapter = NULL;
1388 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1390 //check if the interface is down
1391 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1393 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1398 val = MAX_RTS_THRESHOLD;
1399 else if (rts->value < 0 || rts->value > MAX_RTS_THRESHOLD)
1401 else if (rts->value == 0)
1402 val = MAX_RTS_THRESHOLD;
1406 if (val != pAdapter->CommonCfg.RtsThreshold)
1407 pAdapter->CommonCfg.RtsThreshold = val;
1412 int rt_ioctl_giwrts(struct net_device *dev,
1413 struct iw_request_info *info,
1414 struct iw_param *rts, char *extra)
1416 PRTMP_ADAPTER pAdapter = NULL;
1418 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1420 //check if the interface is down
1421 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1423 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1427 rts->value = pAdapter->CommonCfg.RtsThreshold;
1428 rts->disabled = (rts->value == MAX_RTS_THRESHOLD);
1434 int rt_ioctl_siwfrag(struct net_device *dev,
1435 struct iw_request_info *info,
1436 struct iw_param *frag, char *extra)
1438 PRTMP_ADAPTER pAdapter = NULL;
1441 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1443 //check if the interface is down
1444 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1446 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1451 val = MAX_FRAG_THRESHOLD;
1452 else if (frag->value >= MIN_FRAG_THRESHOLD && frag->value <= MAX_FRAG_THRESHOLD)
1453 val = __cpu_to_le16(frag->value & ~0x1); /* even numbers only */
1454 else if (frag->value == 0)
1455 val = MAX_FRAG_THRESHOLD;
1459 pAdapter->CommonCfg.FragmentThreshold = val;
1463 int rt_ioctl_giwfrag(struct net_device *dev,
1464 struct iw_request_info *info,
1465 struct iw_param *frag, char *extra)
1467 PRTMP_ADAPTER pAdapter = NULL;
1469 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1471 //check if the interface is down
1472 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1474 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1478 frag->value = pAdapter->CommonCfg.FragmentThreshold;
1479 frag->disabled = (frag->value == MAX_FRAG_THRESHOLD);
1485 #define MAX_WEP_KEY_SIZE 13
1486 #define MIN_WEP_KEY_SIZE 5
1487 int rt_ioctl_siwencode(struct net_device *dev,
1488 struct iw_request_info *info,
1489 struct iw_point *erq, char *extra)
1491 PRTMP_ADAPTER pAdapter = NULL;
1493 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1495 //check if the interface is down
1496 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1498 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1502 if ((erq->length == 0) &&
1503 (erq->flags & IW_ENCODE_DISABLED))
1505 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
1506 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
1507 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
1508 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
1509 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1512 else if (erq->flags & IW_ENCODE_RESTRICTED || erq->flags & IW_ENCODE_OPEN)
1514 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
1515 STA_PORT_SECURED(pAdapter);
1516 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
1517 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
1518 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
1519 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
1520 if (erq->flags & IW_ENCODE_RESTRICTED)
1521 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
1523 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1526 if (erq->length > 0)
1528 int keyIdx = (erq->flags & IW_ENCODE_INDEX) - 1;
1529 /* Check the size of the key */
1530 if (erq->length > MAX_WEP_KEY_SIZE)
1534 /* Check key index */
1535 if ((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
1537 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::Wrong keyIdx=%d! Using default key instead (%d)\n",
1538 keyIdx, pAdapter->StaCfg.DefaultKeyId));
1541 keyIdx = pAdapter->StaCfg.DefaultKeyId;
1544 pAdapter->StaCfg.DefaultKeyId = keyIdx;
1546 NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
1548 if (erq->length == MAX_WEP_KEY_SIZE)
1550 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
1551 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
1553 else if (erq->length == MIN_WEP_KEY_SIZE)
1555 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
1556 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
1559 /* Disable the key */
1560 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
1562 /* Check if the key is not marked as invalid */
1563 if(!(erq->flags & IW_ENCODE_NOKEY))
1565 /* Copy the key in the driver */
1566 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, extra, erq->length);
1571 /* Do we want to just set the transmit key index ? */
1572 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
1573 if ((index >= 0) && (index < 4))
1575 pAdapter->StaCfg.DefaultKeyId = index;
1578 /* Don't complain if only change the mode */
1579 if (!(erq->flags & IW_ENCODE_MODE))
1584 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::erq->flags=%x\n",erq->flags));
1585 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::AuthMode=%x\n",pAdapter->StaCfg.AuthMode));
1586 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::DefaultKeyId=%x, KeyLen = %d\n",pAdapter->StaCfg.DefaultKeyId , pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen));
1587 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::WepStatus=%x\n",pAdapter->StaCfg.WepStatus));
1592 rt_ioctl_giwencode(struct net_device *dev,
1593 struct iw_request_info *info,
1594 struct iw_point *erq, char *key)
1597 PRTMP_ADAPTER pAdapter = NULL;
1599 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1601 //check if the interface is down
1602 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1604 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1608 kid = erq->flags & IW_ENCODE_INDEX;
1609 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_giwencode %d\n", erq->flags & IW_ENCODE_INDEX));
1611 if (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled)
1614 erq->flags = IW_ENCODE_DISABLED;
1616 else if ((kid > 0) && (kid <=4))
1619 erq->flags = kid ; /* NB: base 1 */
1620 if (erq->length > pAdapter->SharedKey[BSS0][kid-1].KeyLen)
1621 erq->length = pAdapter->SharedKey[BSS0][kid-1].KeyLen;
1622 memcpy(key, pAdapter->SharedKey[BSS0][kid-1].Key, erq->length);
1623 //if ((kid == pAdapter->PortCfg.DefaultKeyId))
1624 //erq->flags |= IW_ENCODE_ENABLED; /* XXX */
1625 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1626 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1628 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1633 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1634 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1636 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1637 erq->length = pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen;
1638 memcpy(key, pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key, erq->length);
1639 // copy default key ID
1640 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1641 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1643 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1644 erq->flags = pAdapter->StaCfg.DefaultKeyId + 1; /* NB: base 1 */
1645 erq->flags |= IW_ENCODE_ENABLED; /* XXX */
1653 rt_ioctl_setparam(struct net_device *dev, struct iw_request_info *info,
1654 void *w, char *extra)
1656 PRTMP_ADAPTER pAdapter;
1658 PSTRING this_char = extra;
1662 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1664 pObj = (POS_COOKIE) pAdapter->OS_Cookie;
1666 pObj->ioctl_if_type = INT_MAIN;
1667 pObj->ioctl_if = MAIN_MBSSID;
1670 //check if the interface is down
1671 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1673 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1680 if ((value = rtstrchr(this_char, '=')) != NULL)
1683 if (!value && (strcmp(this_char, "SiteSurvey") != 0))
1688 // reject setting nothing besides ANY ssid(ssidLen=0)
1689 if (!*value && (strcmp(this_char, "SSID") != 0))
1693 for (PRTMP_PRIVATE_SET_PROC = RTMP_PRIVATE_SUPPORT_PROC; PRTMP_PRIVATE_SET_PROC->name; PRTMP_PRIVATE_SET_PROC++)
1695 if (strcmp(this_char, PRTMP_PRIVATE_SET_PROC->name) == 0)
1697 if(!PRTMP_PRIVATE_SET_PROC->set_proc(pAdapter, value))
1698 { //FALSE:Set private failed then return Invalid argument
1701 break; //Exit for loop.
1705 if(PRTMP_PRIVATE_SET_PROC->name == NULL)
1706 { //Not found argument
1708 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_setparam:: (iwpriv) Not Support Set Command [%s=%s]\n", this_char, value));
1716 rt_private_get_statistics(struct net_device *dev, struct iw_request_info *info,
1717 struct iw_point *wrq, char *extra)
1720 PRTMP_ADAPTER pAd = NULL;
1722 GET_PAD_FROM_NET_DEV(pAd, dev);
1730 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
1731 sprintf(extra, "\n\n");
1734 sprintf(extra+strlen(extra), "Tx success = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart);
1735 sprintf(extra+strlen(extra), "Tx success without retry = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart - (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
1737 sprintf(extra+strlen(extra), "Tx success after retry = %ld\n", (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
1738 sprintf(extra+strlen(extra), "Tx fail to Rcv ACK after retry = %ld\n", (ULONG)pAd->WlanCounters.FailedCount.QuadPart);
1739 sprintf(extra+strlen(extra), "RTS Success Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSSuccessCount.QuadPart);
1740 sprintf(extra+strlen(extra), "RTS Fail Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSFailureCount.QuadPart);
1742 sprintf(extra+strlen(extra), "Rx success = %ld\n", (ULONG)pAd->WlanCounters.ReceivedFragmentCount.QuadPart);
1743 sprintf(extra+strlen(extra), "Rx with CRC = %ld\n", (ULONG)pAd->WlanCounters.FCSErrorCount.QuadPart);
1744 sprintf(extra+strlen(extra), "Rx drop due to out of resource = %ld\n", (ULONG)pAd->Counters8023.RxNoBuffer);
1745 sprintf(extra+strlen(extra), "Rx duplicate frame = %ld\n", (ULONG)pAd->WlanCounters.FrameDuplicateCount.QuadPart);
1747 sprintf(extra+strlen(extra), "False CCA (one second) = %ld\n", (ULONG)pAd->RalinkCounters.OneSecFalseCCACnt);
1749 sprintf(extra+strlen(extra), "RSSI-A = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi0 - pAd->BbpRssiToDbmDelta));
1750 sprintf(extra+strlen(extra), "RSSI-B (if available) = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi1 - pAd->BbpRssiToDbmDelta));
1751 sprintf(extra+strlen(extra), "RSSI-C (if available) = %ld\n\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi2 - pAd->BbpRssiToDbmDelta));
1753 sprintf(extra+strlen(extra), "WpaSupplicantUP = %d\n\n", pAd->StaCfg.WpaSupplicantUP);
1757 wrq->length = strlen(extra) + 1; // 1: size of '\0'
1758 DBGPRINT(RT_DEBUG_TRACE, ("<== rt_private_get_statistics, wrq->length = %d\n", wrq->length));
1764 IN PRTMP_ADAPTER pAd,
1768 BA_ORI_ENTRY *pOriBAEntry;
1769 BA_REC_ENTRY *pRecBAEntry;
1771 for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
1773 PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
1774 if (((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
1775 || (pEntry->ValidAsWDS) || (pEntry->ValidAsMesh))
1777 sprintf(pOutBuf + strlen(pOutBuf), "\n%02X:%02X:%02X:%02X:%02X:%02X (Aid = %d) (AP) -\n",
1778 pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
1779 pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5], pEntry->Aid);
1781 sprintf(pOutBuf, "%s[Recipient]\n", pOutBuf);
1782 for (j=0; j < NUM_OF_TID; j++)
1784 if (pEntry->BARecWcidArray[j] != 0)
1786 pRecBAEntry =&pAd->BATable.BARecEntry[pEntry->BARecWcidArray[j]];
1787 sprintf(pOutBuf + strlen(pOutBuf), "TID=%d, BAWinSize=%d, LastIndSeq=%d, ReorderingPkts=%d\n", j, pRecBAEntry->BAWinSize, pRecBAEntry->LastIndSeq, pRecBAEntry->list.qlen);
1790 sprintf(pOutBuf, "%s\n", pOutBuf);
1792 sprintf(pOutBuf, "%s[Originator]\n", pOutBuf);
1793 for (j=0; j < NUM_OF_TID; j++)
1795 if (pEntry->BAOriWcidArray[j] != 0)
1797 pOriBAEntry =&pAd->BATable.BAOriEntry[pEntry->BAOriWcidArray[j]];
1798 sprintf(pOutBuf + strlen(pOutBuf), "TID=%d, BAWinSize=%d, StartSeq=%d, CurTxSeq=%d\n", j, pOriBAEntry->BAWinSize, pOriBAEntry->Sequence, pEntry->TxSeq[j]);
1801 sprintf(pOutBuf, "%s\n\n", pOutBuf);
1803 if (strlen(pOutBuf) > (IW_PRIV_SIZE_MASK - 30))
1811 rt_private_show(struct net_device *dev, struct iw_request_info *info,
1812 struct iw_point *wrq, PSTRING extra)
1817 u32 subcmd = wrq->flags;
1819 GET_PAD_FROM_NET_DEV(pAd, dev);
1821 pObj = (POS_COOKIE) pAd->OS_Cookie;
1827 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
1830 pObj->ioctl_if_type = INT_MAIN;
1831 pObj->ioctl_if = MAIN_MBSSID;
1837 case SHOW_CONN_STATUS:
1838 if (MONITOR_ON(pAd))
1840 if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
1841 pAd->CommonCfg.RegTransmitSetting.field.BW)
1842 sprintf(extra, "Monitor Mode(CentralChannel %d)\n", pAd->CommonCfg.CentralChannel);
1844 sprintf(extra, "Monitor Mode(Channel %d)\n", pAd->CommonCfg.Channel);
1848 if (pAd->IndicateMediaState == NdisMediaStateConnected)
1852 sprintf(extra, "Connected(AP: %s[%02X:%02X:%02X:%02X:%02X:%02X])\n",
1853 pAd->CommonCfg.Ssid,
1854 pAd->CommonCfg.Bssid[0],
1855 pAd->CommonCfg.Bssid[1],
1856 pAd->CommonCfg.Bssid[2],
1857 pAd->CommonCfg.Bssid[3],
1858 pAd->CommonCfg.Bssid[4],
1859 pAd->CommonCfg.Bssid[5]);
1860 DBGPRINT(RT_DEBUG_TRACE ,("Ssid=%s ,Ssidlen = %d\n",pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen));
1862 else if (ADHOC_ON(pAd))
1863 sprintf(extra, "Connected\n");
1867 sprintf(extra, "Disconnected\n");
1868 DBGPRINT(RT_DEBUG_TRACE ,("ConnStatus is not connected\n"));
1871 wrq->length = strlen(extra) + 1; // 1: size of '\0'
1873 case SHOW_DRVIER_VERION:
1874 sprintf(extra, "Driver version-%s, %s %s\n", STA_DRIVER_VERSION, __DATE__, __TIME__ );
1875 wrq->length = strlen(extra) + 1; // 1: size of '\0'
1878 getBaInfo(pAd, extra);
1879 wrq->length = strlen(extra) + 1; // 1: size of '\0'
1881 case SHOW_DESC_INFO:
1883 Show_DescInfo_Proc(pAd, NULL);
1884 wrq->length = 0; // 1: size of '\0'
1888 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
1890 if (pAd->Mlme.CntlMachine.CurrState != CNTL_IDLE)
1892 RTMP_MLME_RESET_STATE_MACHINE(pAd);
1893 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
1896 pAd->StaCfg.bSwRadio = FALSE;
1897 if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
1899 pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
1900 if (pAd->StaCfg.bRadio == FALSE)
1903 // Update extra information
1904 pAd->ExtraInfo = SW_RADIO_OFF;
1907 sprintf(extra, "Radio Off\n");
1908 wrq->length = strlen(extra) + 1; // 1: size of '\0'
1911 pAd->StaCfg.bSwRadio = TRUE;
1912 //if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
1914 pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
1915 if (pAd->StaCfg.bRadio == TRUE)
1918 // Update extra information
1919 pAd->ExtraInfo = EXTRA_INFO_CLEAR;
1922 sprintf(extra, "Radio On\n");
1923 wrq->length = strlen(extra) + 1; // 1: size of '\0'
1928 case SHOW_CFG_VALUE:
1930 Status = RTMPShowCfgValue(pAd, (PSTRING) wrq->pointer, extra);
1932 wrq->length = strlen(extra) + 1; // 1: size of '\0'
1935 case SHOW_ADHOC_ENTRY_INFO:
1936 Show_Adhoc_MacTable_Proc(pAd, extra);
1937 wrq->length = strlen(extra) + 1; // 1: size of '\0'
1940 DBGPRINT(RT_DEBUG_TRACE, ("%s - unknow subcmd = %d\n", __func__, subcmd));
1947 int rt_ioctl_siwmlme(struct net_device *dev,
1948 struct iw_request_info *info,
1949 union iwreq_data *wrqu,
1952 PRTMP_ADAPTER pAd = NULL;
1953 struct iw_mlme *pMlme = (struct iw_mlme *)wrqu->data.pointer;
1954 MLME_QUEUE_ELEM MsgElem;
1955 MLME_DISASSOC_REQ_STRUCT DisAssocReq;
1956 MLME_DEAUTH_REQ_STRUCT DeAuthReq;
1958 GET_PAD_FROM_NET_DEV(pAd, dev);
1960 DBGPRINT(RT_DEBUG_TRACE, ("====> %s\n", __func__));
1967 #ifdef IW_MLME_DEAUTH
1968 case IW_MLME_DEAUTH:
1969 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DEAUTH\n", __func__));
1970 COPY_MAC_ADDR(DeAuthReq.Addr, pAd->CommonCfg.Bssid);
1971 DeAuthReq.Reason = pMlme->reason_code;
1972 MsgElem.MsgLen = sizeof(MLME_DEAUTH_REQ_STRUCT);
1973 NdisMoveMemory(MsgElem.Msg, &DeAuthReq, sizeof(MLME_DEAUTH_REQ_STRUCT));
1974 MlmeDeauthReqAction(pAd, &MsgElem);
1977 LinkDown(pAd, FALSE);
1978 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
1981 #endif // IW_MLME_DEAUTH //
1982 #ifdef IW_MLME_DISASSOC
1983 case IW_MLME_DISASSOC:
1984 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DISASSOC\n", __func__));
1985 COPY_MAC_ADDR(DisAssocReq.Addr, pAd->CommonCfg.Bssid);
1986 DisAssocReq.Reason = pMlme->reason_code;
1988 MsgElem.Machine = ASSOC_STATE_MACHINE;
1989 MsgElem.MsgType = MT2_MLME_DISASSOC_REQ;
1990 MsgElem.MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
1991 NdisMoveMemory(MsgElem.Msg, &DisAssocReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
1993 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
1994 MlmeDisassocReqAction(pAd, &MsgElem);
1996 #endif // IW_MLME_DISASSOC //
1998 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - Unknow Command\n", __func__));
2005 int rt_ioctl_siwauth(struct net_device *dev,
2006 struct iw_request_info *info,
2007 union iwreq_data *wrqu, char *extra)
2009 PRTMP_ADAPTER pAdapter = NULL;
2010 struct iw_param *param = &wrqu->param;
2012 GET_PAD_FROM_NET_DEV(pAdapter, dev);
2014 //check if the interface is down
2015 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2017 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2020 switch (param->flags & IW_AUTH_INDEX) {
2021 case IW_AUTH_WPA_VERSION:
2022 if (param->value == IW_AUTH_WPA_VERSION_WPA)
2024 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
2025 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
2026 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
2028 else if (param->value == IW_AUTH_WPA_VERSION_WPA2)
2029 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
2031 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __func__, param->value));
2033 case IW_AUTH_CIPHER_PAIRWISE:
2034 if (param->value == IW_AUTH_CIPHER_NONE)
2036 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
2037 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2038 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
2040 else if (param->value == IW_AUTH_CIPHER_WEP40 ||
2041 param->value == IW_AUTH_CIPHER_WEP104)
2043 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
2044 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2045 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
2046 pAdapter->StaCfg.IEEE8021X = FALSE;
2048 else if (param->value == IW_AUTH_CIPHER_TKIP)
2050 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
2051 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2052 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
2054 else if (param->value == IW_AUTH_CIPHER_CCMP)
2056 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
2057 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2058 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
2060 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_PAIRWISE - param->value = %d!\n", __func__, param->value));
2062 case IW_AUTH_CIPHER_GROUP:
2063 if (param->value == IW_AUTH_CIPHER_NONE)
2065 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
2067 else if (param->value == IW_AUTH_CIPHER_WEP40 ||
2068 param->value == IW_AUTH_CIPHER_WEP104)
2070 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
2072 else if (param->value == IW_AUTH_CIPHER_TKIP)
2074 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
2076 else if (param->value == IW_AUTH_CIPHER_CCMP)
2078 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
2080 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_GROUP - param->value = %d!\n", __func__, param->value));
2082 case IW_AUTH_KEY_MGMT:
2083 if (param->value == IW_AUTH_KEY_MGMT_802_1X)
2085 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)
2087 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
2088 pAdapter->StaCfg.IEEE8021X = FALSE;
2090 else if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
2092 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
2093 pAdapter->StaCfg.IEEE8021X = FALSE;
2097 pAdapter->StaCfg.IEEE8021X = TRUE;
2099 else if (param->value == 0)
2101 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2102 STA_PORT_SECURED(pAdapter);
2104 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_KEY_MGMT - param->value = %d!\n", __func__, param->value));
2106 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
2108 case IW_AUTH_PRIVACY_INVOKED:
2109 /*if (param->value == 0)
2111 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
2112 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
2113 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2114 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
2115 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
2117 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_PRIVACY_INVOKED - param->value = %d!\n", __func__, param->value));
2119 case IW_AUTH_DROP_UNENCRYPTED:
2120 if (param->value != 0)
2121 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
2124 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2125 STA_PORT_SECURED(pAdapter);
2127 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __func__, param->value));
2129 case IW_AUTH_80211_AUTH_ALG:
2130 if (param->value & IW_AUTH_ALG_SHARED_KEY)
2132 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
2134 else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
2136 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
2140 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_80211_AUTH_ALG - param->value = %d!\n", __func__, param->value));
2142 case IW_AUTH_WPA_ENABLED:
2143 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_ENABLED - Driver supports WPA!(param->value = %d)\n", __func__, param->value));
2152 int rt_ioctl_giwauth(struct net_device *dev,
2153 struct iw_request_info *info,
2154 union iwreq_data *wrqu, char *extra)
2156 PRTMP_ADAPTER pAdapter = NULL;
2157 struct iw_param *param = &wrqu->param;
2159 GET_PAD_FROM_NET_DEV(pAdapter, dev);
2161 //check if the interface is down
2162 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2164 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2168 switch (param->flags & IW_AUTH_INDEX) {
2169 case IW_AUTH_DROP_UNENCRYPTED:
2170 param->value = (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled) ? 0 : 1;
2173 case IW_AUTH_80211_AUTH_ALG:
2174 param->value = (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared) ? IW_AUTH_ALG_SHARED_KEY : IW_AUTH_ALG_OPEN_SYSTEM;
2177 case IW_AUTH_WPA_ENABLED:
2178 param->value = (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) ? 1 : 0;
2184 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_giwauth::param->value = %d!\n", param->value));
2188 void fnSetCipherKey(
2189 IN PRTMP_ADAPTER pAdapter,
2193 IN struct iw_encode_ext *ext)
2195 NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
2196 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = LEN_TKIP_EK;
2197 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, LEN_TKIP_EK);
2198 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].TxMic, ext->key + LEN_TKIP_EK, LEN_TKIP_TXMICK);
2199 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].RxMic, ext->key + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
2200 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CipherAlg;
2202 // Update group key information to ASIC Shared Key Table
2203 AsicAddSharedKeyEntry(pAdapter,
2206 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2207 pAdapter->SharedKey[BSS0][keyIdx].Key,
2208 pAdapter->SharedKey[BSS0][keyIdx].TxMic,
2209 pAdapter->SharedKey[BSS0][keyIdx].RxMic);
2212 // Update ASIC WCID attribute table and IVEIV table
2213 RTMPAddWcidAttributeEntry(pAdapter,
2216 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2219 // Update ASIC WCID attribute table and IVEIV table
2220 RTMPAddWcidAttributeEntry(pAdapter,
2223 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2224 &pAdapter->MacTab.Content[BSSID_WCID]);
2227 int rt_ioctl_siwencodeext(struct net_device *dev,
2228 struct iw_request_info *info,
2229 union iwreq_data *wrqu,
2232 PRTMP_ADAPTER pAdapter = NULL;
2233 struct iw_point *encoding = &wrqu->encoding;
2234 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2235 int keyIdx, alg = ext->alg;
2237 GET_PAD_FROM_NET_DEV(pAdapter, dev);
2239 //check if the interface is down
2240 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2242 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2246 if (encoding->flags & IW_ENCODE_DISABLED)
2248 keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
2249 // set BSSID wcid entry of the Pair-wise Key table as no-security mode
2250 AsicRemovePairwiseKeyEntry(pAdapter, BSS0, BSSID_WCID);
2251 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
2252 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_NONE;
2253 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)keyIdx);
2254 NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
2255 DBGPRINT(RT_DEBUG_TRACE, ("%s::Remove all keys!(encoding->flags = %x)\n", __func__, encoding->flags));
2259 // Get Key Index and convet to our own defined key index
2260 keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
2261 if((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
2264 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2266 pAdapter->StaCfg.DefaultKeyId = keyIdx;
2267 DBGPRINT(RT_DEBUG_TRACE, ("%s::DefaultKeyId = %d\n", __func__, pAdapter->StaCfg.DefaultKeyId));
2271 case IW_ENCODE_ALG_NONE:
2272 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_NONE\n", __func__));
2274 case IW_ENCODE_ALG_WEP:
2275 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_WEP - ext->key_len = %d, keyIdx = %d\n", __func__, ext->key_len, keyIdx));
2276 if (ext->key_len == MAX_WEP_KEY_SIZE)
2278 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
2279 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
2281 else if (ext->key_len == MIN_WEP_KEY_SIZE)
2283 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
2284 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
2289 NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
2290 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, ext->key_len);
2291 if (pAdapter->StaCfg.GroupCipher == Ndis802_11GroupWEP40Enabled ||
2292 pAdapter->StaCfg.GroupCipher == Ndis802_11GroupWEP104Enabled)
2294 // Set Group key material to Asic
2295 AsicAddSharedKeyEntry(pAdapter, BSS0, keyIdx, pAdapter->SharedKey[BSS0][keyIdx].CipherAlg, pAdapter->SharedKey[BSS0][keyIdx].Key, NULL, NULL);
2297 // Update WCID attribute table and IVEIV table for this group key table
2298 RTMPAddWcidAttributeEntry(pAdapter, BSS0, keyIdx, pAdapter->SharedKey[BSS0][keyIdx].CipherAlg, NULL);
2300 STA_PORT_SECURED(pAdapter);
2302 // Indicate Connected for GUI
2303 pAdapter->IndicateMediaState = NdisMediaStateConnected;
2306 case IW_ENCODE_ALG_TKIP:
2307 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_TKIP - keyIdx = %d, ext->key_len = %d\n", __func__, keyIdx, ext->key_len));
2308 if (ext->key_len == 32)
2310 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2312 fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, FALSE, ext);
2313 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
2315 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2316 STA_PORT_SECURED(pAdapter);
2317 pAdapter->IndicateMediaState = NdisMediaStateConnected;
2320 else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
2322 fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, TRUE, ext);
2324 // set 802.1x port control
2325 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2326 STA_PORT_SECURED(pAdapter);
2327 pAdapter->IndicateMediaState = NdisMediaStateConnected;
2333 case IW_ENCODE_ALG_CCMP:
2334 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2336 fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, FALSE, ext);
2337 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
2338 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2339 STA_PORT_SECURED(pAdapter);
2340 pAdapter->IndicateMediaState = NdisMediaStateConnected;
2342 else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
2344 fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, TRUE, ext);
2346 // set 802.1x port control
2347 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2348 STA_PORT_SECURED(pAdapter);
2349 pAdapter->IndicateMediaState = NdisMediaStateConnected;
2361 rt_ioctl_giwencodeext(struct net_device *dev,
2362 struct iw_request_info *info,
2363 union iwreq_data *wrqu, char *extra)
2365 PRTMP_ADAPTER pAd = NULL;
2367 struct iw_point *encoding = &wrqu->encoding;
2368 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2369 int idx, max_key_len;
2371 GET_PAD_FROM_NET_DEV(pAd, dev);
2373 DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_giwencodeext\n"));
2375 max_key_len = encoding->length - sizeof(*ext);
2376 if (max_key_len < 0)
2379 idx = encoding->flags & IW_ENCODE_INDEX;
2382 if (idx < 1 || idx > 4)
2386 if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
2387 (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled))
2389 if (idx != pAd->StaCfg.DefaultKeyId)
2397 idx = pAd->StaCfg.DefaultKeyId;
2399 encoding->flags = idx + 1;
2400 memset(ext, 0, sizeof(*ext));
2403 switch(pAd->StaCfg.WepStatus) {
2404 case Ndis802_11WEPDisabled:
2405 ext->alg = IW_ENCODE_ALG_NONE;
2406 encoding->flags |= IW_ENCODE_DISABLED;
2408 case Ndis802_11WEPEnabled:
2409 ext->alg = IW_ENCODE_ALG_WEP;
2410 if (pAd->SharedKey[BSS0][idx].KeyLen > max_key_len)
2414 ext->key_len = pAd->SharedKey[BSS0][idx].KeyLen;
2415 pKey = (PCHAR)&(pAd->SharedKey[BSS0][idx].Key[0]);
2418 case Ndis802_11Encryption2Enabled:
2419 case Ndis802_11Encryption3Enabled:
2420 if (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
2421 ext->alg = IW_ENCODE_ALG_TKIP;
2423 ext->alg = IW_ENCODE_ALG_CCMP;
2425 if (max_key_len < 32)
2430 pKey = (PCHAR)&pAd->StaCfg.PMK[0];
2437 if (ext->key_len && pKey)
2439 encoding->flags |= IW_ENCODE_ENABLED;
2440 memcpy(ext->key, pKey, ext->key_len);
2446 int rt_ioctl_siwgenie(struct net_device *dev,
2447 struct iw_request_info *info,
2448 union iwreq_data *wrqu, char *extra)
2450 PRTMP_ADAPTER pAd = NULL;
2452 GET_PAD_FROM_NET_DEV(pAd, dev);
2454 DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_siwgenie\n"));
2455 pAd->StaCfg.bRSN_IE_FromWpaSupplicant = FALSE;
2456 if (wrqu->data.length > MAX_LEN_OF_RSNIE ||
2457 (wrqu->data.length && extra == NULL))
2460 if (wrqu->data.length)
2462 pAd->StaCfg.RSNIE_Len = wrqu->data.length;
2463 NdisMoveMemory(&pAd->StaCfg.RSN_IE[0], extra, pAd->StaCfg.RSNIE_Len);
2464 pAd->StaCfg.bRSN_IE_FromWpaSupplicant = TRUE;
2468 pAd->StaCfg.RSNIE_Len = 0;
2469 NdisZeroMemory(&pAd->StaCfg.RSN_IE[0], MAX_LEN_OF_RSNIE);
2475 int rt_ioctl_giwgenie(struct net_device *dev,
2476 struct iw_request_info *info,
2477 union iwreq_data *wrqu, char *extra)
2479 PRTMP_ADAPTER pAd = NULL;
2481 GET_PAD_FROM_NET_DEV(pAd, dev);
2483 if ((pAd->StaCfg.RSNIE_Len == 0) ||
2484 (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA))
2486 wrqu->data.length = 0;
2490 if (pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
2492 if (wrqu->data.length < pAd->StaCfg.RSNIE_Len)
2495 wrqu->data.length = pAd->StaCfg.RSNIE_Len;
2496 memcpy(extra, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
2500 UCHAR RSNIe = IE_WPA;
2502 if (wrqu->data.length < (pAd->StaCfg.RSNIE_Len + 2)) // ID, Len
2504 wrqu->data.length = pAd->StaCfg.RSNIE_Len + 2;
2506 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
2507 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2))
2510 extra[0] = (char)RSNIe;
2511 extra[1] = pAd->StaCfg.RSNIE_Len;
2512 memcpy(extra+2, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
2518 int rt_ioctl_siwpmksa(struct net_device *dev,
2519 struct iw_request_info *info,
2520 union iwreq_data *wrqu,
2523 PRTMP_ADAPTER pAd = NULL;
2524 struct iw_pmksa *pPmksa = (struct iw_pmksa *)wrqu->data.pointer;
2525 INT CachedIdx = 0, idx = 0;
2527 GET_PAD_FROM_NET_DEV(pAd, dev);
2532 DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_siwpmksa\n"));
2535 case IW_PMKSA_FLUSH:
2536 NdisZeroMemory(pAd->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
2537 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_FLUSH\n"));
2539 case IW_PMKSA_REMOVE:
2540 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
2542 // compare the BSSID
2543 if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
2545 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN);
2546 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].PMKID, 16);
2547 for (idx = CachedIdx; idx < (pAd->StaCfg.SavedPMKNum - 1); idx++)
2549 NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].BSSID[0], &pAd->StaCfg.SavedPMK[idx+1].BSSID[0], MAC_ADDR_LEN);
2550 NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].PMKID[0], &pAd->StaCfg.SavedPMK[idx+1].PMKID[0], 16);
2552 pAd->StaCfg.SavedPMKNum--;
2557 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_REMOVE\n"));
2560 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
2562 // compare the BSSID
2563 if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
2567 // Found, replace it
2568 if (CachedIdx < PMKID_NO)
2570 DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
2571 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
2572 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
2573 pAd->StaCfg.SavedPMKNum++;
2575 // Not found, replace the last one
2578 // Randomly replace one
2579 CachedIdx = (pPmksa->bssid.sa_data[5] % PMKID_NO);
2580 DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
2581 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
2582 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
2585 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_ADD\n"));
2588 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - Unknow Command!!\n"));
2595 int rt_ioctl_siwrate(struct net_device *dev,
2596 struct iw_request_info *info,
2597 union iwreq_data *wrqu, char *extra)
2599 PRTMP_ADAPTER pAd = NULL;
2600 UINT32 rate = wrqu->bitrate.value, fixed = wrqu->bitrate.fixed;
2602 GET_PAD_FROM_NET_DEV(pAd, dev);
2604 //check if the interface is down
2605 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2607 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::Network is down!\n"));
2611 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(rate = %d, fixed = %d)\n", rate, fixed));
2612 /* rate = -1 => auto rate
2613 rate = X, fixed = 1 => (fixed rate X)
2618 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
2619 pAd->StaCfg.bAutoTxRateSwitch = TRUE;
2620 if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
2621 (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
2622 RTMPSetDesiredRates(pAd, -1);
2630 pAd->StaCfg.bAutoTxRateSwitch = FALSE;
2631 if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
2632 (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
2633 RTMPSetDesiredRates(pAd, rate);
2636 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
2639 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(HtMcs=%d)\n",pAd->StaCfg.DesiredTransmitSetting.field.MCS));
2643 // TODO: rate = X, fixed = 0 => (rates <= X)
2651 int rt_ioctl_giwrate(struct net_device *dev,
2652 struct iw_request_info *info,
2653 union iwreq_data *wrqu, char *extra)
2655 PRTMP_ADAPTER pAd = NULL;
2656 int rate_index = 0, rate_count = 0;
2657 HTTRANSMIT_SETTING ht_setting;
2658 /* Remove to global variable
2659 __s32 ralinkrate[] =
2660 {2, 4, 11, 22, // CCK
2661 12, 18, 24, 36, 48, 72, 96, 108, // OFDM
2662 13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260, // 20MHz, 800ns GI, MCS: 0 ~ 15
2663 39, 78, 117, 156, 234, 312, 351, 390, // 20MHz, 800ns GI, MCS: 16 ~ 23
2664 27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540, // 40MHz, 800ns GI, MCS: 0 ~ 15
2665 81, 162, 243, 324, 486, 648, 729, 810, // 40MHz, 800ns GI, MCS: 16 ~ 23
2666 14, 29, 43, 57, 87, 115, 130, 144, 29, 59, 87, 115, 173, 230, 260, 288, // 20MHz, 400ns GI, MCS: 0 ~ 15
2667 43, 87, 130, 173, 260, 317, 390, 433, // 20MHz, 400ns GI, MCS: 16 ~ 23
2668 30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600, // 40MHz, 400ns GI, MCS: 0 ~ 15
2669 90, 180, 270, 360, 540, 720, 810, 900}; // 40MHz, 400ns GI, MCS: 16 ~ 23
2671 GET_PAD_FROM_NET_DEV(pAd, dev);
2673 rate_count = sizeof(ralinkrate)/sizeof(__s32);
2674 //check if the interface is down
2675 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2677 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2681 if ((pAd->StaCfg.bAutoTxRateSwitch == FALSE) &&
2683 ((pAd->CommonCfg.PhyMode <= PHY_11G) || (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM)))
2684 ht_setting.word = pAd->StaCfg.HTPhyMode.word;
2686 ht_setting.word = pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word;
2688 if (ht_setting.field.MODE >= MODE_HTMIX)
2690 // rate_index = 12 + ((UCHAR)ht_setting.field.BW *16) + ((UCHAR)ht_setting.field.ShortGI *32) + ((UCHAR)ht_setting.field.MCS);
2691 rate_index = 12 + ((UCHAR)ht_setting.field.BW *24) + ((UCHAR)ht_setting.field.ShortGI *48) + ((UCHAR)ht_setting.field.MCS);
2694 if (ht_setting.field.MODE == MODE_OFDM)
2695 rate_index = (UCHAR)(ht_setting.field.MCS) + 4;
2696 else if (ht_setting.field.MODE == MODE_CCK)
2697 rate_index = (UCHAR)(ht_setting.field.MCS);
2702 if (rate_index > rate_count)
2703 rate_index = rate_count;
2705 wrqu->bitrate.value = ralinkrate[rate_index] * 500000;
2706 wrqu->bitrate.disabled = 0;
2711 static const iw_handler rt_handler[] =
2713 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2714 (iw_handler) rt_ioctl_giwname, /* SIOCGIWNAME */
2715 (iw_handler) NULL, /* SIOCSIWNWID */
2716 (iw_handler) NULL, /* SIOCGIWNWID */
2717 (iw_handler) rt_ioctl_siwfreq, /* SIOCSIWFREQ */
2718 (iw_handler) rt_ioctl_giwfreq, /* SIOCGIWFREQ */
2719 (iw_handler) rt_ioctl_siwmode, /* SIOCSIWMODE */
2720 (iw_handler) rt_ioctl_giwmode, /* SIOCGIWMODE */
2721 (iw_handler) NULL, /* SIOCSIWSENS */
2722 (iw_handler) NULL, /* SIOCGIWSENS */
2723 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
2724 (iw_handler) rt_ioctl_giwrange, /* SIOCGIWRANGE */
2725 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
2726 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
2727 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
2728 (iw_handler) rt28xx_get_wireless_stats /* kernel code */, /* SIOCGIWSTATS */
2729 (iw_handler) NULL, /* SIOCSIWSPY */
2730 (iw_handler) NULL, /* SIOCGIWSPY */
2731 (iw_handler) NULL, /* SIOCSIWTHRSPY */
2732 (iw_handler) NULL, /* SIOCGIWTHRSPY */
2733 (iw_handler) rt_ioctl_siwap, /* SIOCSIWAP */
2734 (iw_handler) rt_ioctl_giwap, /* SIOCGIWAP */
2735 (iw_handler) rt_ioctl_siwmlme, /* SIOCSIWMLME */
2736 (iw_handler) rt_ioctl_iwaplist, /* SIOCGIWAPLIST */
2737 (iw_handler) rt_ioctl_siwscan, /* SIOCSIWSCAN */
2738 (iw_handler) rt_ioctl_giwscan, /* SIOCGIWSCAN */
2739 (iw_handler) rt_ioctl_siwessid, /* SIOCSIWESSID */
2740 (iw_handler) rt_ioctl_giwessid, /* SIOCGIWESSID */
2741 (iw_handler) rt_ioctl_siwnickn, /* SIOCSIWNICKN */
2742 (iw_handler) rt_ioctl_giwnickn, /* SIOCGIWNICKN */
2743 (iw_handler) NULL, /* -- hole -- */
2744 (iw_handler) NULL, /* -- hole -- */
2745 (iw_handler) rt_ioctl_siwrate, /* SIOCSIWRATE */
2746 (iw_handler) rt_ioctl_giwrate, /* SIOCGIWRATE */
2747 (iw_handler) rt_ioctl_siwrts, /* SIOCSIWRTS */
2748 (iw_handler) rt_ioctl_giwrts, /* SIOCGIWRTS */
2749 (iw_handler) rt_ioctl_siwfrag, /* SIOCSIWFRAG */
2750 (iw_handler) rt_ioctl_giwfrag, /* SIOCGIWFRAG */
2751 (iw_handler) NULL, /* SIOCSIWTXPOW */
2752 (iw_handler) NULL, /* SIOCGIWTXPOW */
2753 (iw_handler) NULL, /* SIOCSIWRETRY */
2754 (iw_handler) NULL, /* SIOCGIWRETRY */
2755 (iw_handler) rt_ioctl_siwencode, /* SIOCSIWENCODE */
2756 (iw_handler) rt_ioctl_giwencode, /* SIOCGIWENCODE */
2757 (iw_handler) NULL, /* SIOCSIWPOWER */
2758 (iw_handler) NULL, /* SIOCGIWPOWER */
2759 (iw_handler) NULL, /* -- hole -- */
2760 (iw_handler) NULL, /* -- hole -- */
2761 (iw_handler) rt_ioctl_siwgenie, /* SIOCSIWGENIE */
2762 (iw_handler) rt_ioctl_giwgenie, /* SIOCGIWGENIE */
2763 (iw_handler) rt_ioctl_siwauth, /* SIOCSIWAUTH */
2764 (iw_handler) rt_ioctl_giwauth, /* SIOCGIWAUTH */
2765 (iw_handler) rt_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
2766 (iw_handler) rt_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */
2767 (iw_handler) rt_ioctl_siwpmksa, /* SIOCSIWPMKSA */
2770 static const iw_handler rt_priv_handlers[] = {
2771 (iw_handler) NULL, /* + 0x00 */
2772 (iw_handler) NULL, /* + 0x01 */
2773 (iw_handler) rt_ioctl_setparam, /* + 0x02 */
2774 (iw_handler) NULL, /* + 0x03 */
2775 (iw_handler) NULL, /* + 0x04 */
2776 (iw_handler) NULL, /* + 0x05 */
2777 (iw_handler) NULL, /* + 0x06 */
2778 (iw_handler) NULL, /* + 0x07 */
2779 (iw_handler) NULL, /* + 0x08 */
2780 (iw_handler) rt_private_get_statistics, /* + 0x09 */
2781 (iw_handler) NULL, /* + 0x0A */
2782 (iw_handler) NULL, /* + 0x0B */
2783 (iw_handler) NULL, /* + 0x0C */
2784 (iw_handler) NULL, /* + 0x0D */
2785 (iw_handler) NULL, /* + 0x0E */
2786 (iw_handler) NULL, /* + 0x0F */
2787 (iw_handler) NULL, /* + 0x10 */
2788 (iw_handler) rt_private_show, /* + 0x11 */
2789 (iw_handler) NULL, /* + 0x12 */
2790 (iw_handler) NULL, /* + 0x13 */
2791 (iw_handler) NULL, /* + 0x14 */
2792 (iw_handler) NULL, /* + 0x15 */
2793 (iw_handler) NULL, /* + 0x16 */
2794 (iw_handler) NULL, /* + 0x17 */
2795 (iw_handler) NULL, /* + 0x18 */
2798 const struct iw_handler_def rt28xx_iw_handler_def =
2800 #define N(a) (sizeof (a) / sizeof (a[0]))
2801 .standard = (iw_handler *) rt_handler,
2802 .num_standard = sizeof(rt_handler) / sizeof(iw_handler),
2803 .private = (iw_handler *) rt_priv_handlers,
2804 .num_private = N(rt_priv_handlers),
2805 .private_args = (struct iw_priv_args *) privtab,
2806 .num_private_args = N(privtab),
2807 #if IW_HANDLER_VERSION >= 7
2808 .get_wireless_stats = rt28xx_get_wireless_stats,
2812 INT rt28xx_sta_ioctl(
2813 IN struct net_device *net_dev,
2814 IN OUT struct ifreq *rq,
2818 RTMP_ADAPTER *pAd = NULL;
2819 struct iwreq *wrq = (struct iwreq *) rq;
2820 BOOLEAN StateMachineTouched = FALSE;
2821 INT Status = NDIS_STATUS_SUCCESS;
2823 GET_PAD_FROM_NET_DEV(pAd, net_dev);
2825 pObj = (POS_COOKIE) pAd->OS_Cookie;
2827 //check if the interface is down
2828 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2831 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2836 { // determine this ioctl command is comming from which interface.
2837 pObj->ioctl_if_type = INT_MAIN;
2838 pObj->ioctl_if = MAIN_MBSSID;
2844 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIFHWADDR\n"));
2845 memcpy(wrq->u.name, pAd->CurrentAddress, ETH_ALEN);
2849 char *name=&wrq->u.name[0];
2850 rt_ioctl_giwname(net_dev, NULL, name, NULL);
2853 case SIOCGIWESSID: //Get ESSID
2855 struct iw_point *essid=&wrq->u.essid;
2856 rt_ioctl_giwessid(net_dev, NULL, essid, essid->pointer);
2859 case SIOCSIWESSID: //Set ESSID
2861 struct iw_point *essid=&wrq->u.essid;
2862 rt_ioctl_siwessid(net_dev, NULL, essid, essid->pointer);
2865 case SIOCSIWNWID: // set network id (the cell)
2866 case SIOCGIWNWID: // get network id
2867 Status = -EOPNOTSUPP;
2869 case SIOCSIWFREQ: //set channel/frequency (Hz)
2871 struct iw_freq *freq=&wrq->u.freq;
2872 rt_ioctl_siwfreq(net_dev, NULL, freq, NULL);
2875 case SIOCGIWFREQ: // get channel/frequency (Hz)
2877 struct iw_freq *freq=&wrq->u.freq;
2878 rt_ioctl_giwfreq(net_dev, NULL, freq, NULL);
2881 case SIOCSIWNICKN: //set node name/nickname
2883 //struct iw_point *data=&wrq->u.data;
2884 //rt_ioctl_siwnickn(net_dev, NULL, data, NULL);
2887 case SIOCGIWNICKN: //get node name/nickname
2889 struct iw_point *erq = NULL;
2891 erq->length = strlen((PSTRING) pAd->nickname);
2892 Status = copy_to_user(erq->pointer, pAd->nickname, erq->length);
2895 case SIOCGIWRATE: //get default bit rate (bps)
2896 rt_ioctl_giwrate(net_dev, NULL, &wrq->u, NULL);
2898 case SIOCSIWRATE: //set default bit rate (bps)
2899 rt_ioctl_siwrate(net_dev, NULL, &wrq->u, NULL);
2901 case SIOCGIWRTS: // get RTS/CTS threshold (bytes)
2903 struct iw_param *rts=&wrq->u.rts;
2904 rt_ioctl_giwrts(net_dev, NULL, rts, NULL);
2907 case SIOCSIWRTS: //set RTS/CTS threshold (bytes)
2909 struct iw_param *rts=&wrq->u.rts;
2910 rt_ioctl_siwrts(net_dev, NULL, rts, NULL);
2913 case SIOCGIWFRAG: //get fragmentation thr (bytes)
2915 struct iw_param *frag=&wrq->u.frag;
2916 rt_ioctl_giwfrag(net_dev, NULL, frag, NULL);
2919 case SIOCSIWFRAG: //set fragmentation thr (bytes)
2921 struct iw_param *frag=&wrq->u.frag;
2922 rt_ioctl_siwfrag(net_dev, NULL, frag, NULL);
2925 case SIOCGIWENCODE: //get encoding token & mode
2927 struct iw_point *erq=&wrq->u.encoding;
2929 rt_ioctl_giwencode(net_dev, NULL, erq, erq->pointer);
2932 case SIOCSIWENCODE: //set encoding token & mode
2934 struct iw_point *erq=&wrq->u.encoding;
2936 rt_ioctl_siwencode(net_dev, NULL, erq, erq->pointer);
2939 case SIOCGIWAP: //get access point MAC addresses
2941 struct sockaddr *ap_addr=&wrq->u.ap_addr;
2942 rt_ioctl_giwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
2945 case SIOCSIWAP: //set access point MAC addresses
2947 struct sockaddr *ap_addr=&wrq->u.ap_addr;
2948 rt_ioctl_siwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
2951 case SIOCGIWMODE: //get operation mode
2953 __u32 *mode=&wrq->u.mode;
2954 rt_ioctl_giwmode(net_dev, NULL, mode, NULL);
2957 case SIOCSIWMODE: //set operation mode
2959 __u32 *mode=&wrq->u.mode;
2960 rt_ioctl_siwmode(net_dev, NULL, mode, NULL);
2963 case SIOCGIWSENS: //get sensitivity (dBm)
2964 case SIOCSIWSENS: //set sensitivity (dBm)
2965 case SIOCGIWPOWER: //get Power Management settings
2966 case SIOCSIWPOWER: //set Power Management settings
2967 case SIOCGIWTXPOW: //get transmit power (dBm)
2968 case SIOCSIWTXPOW: //set transmit power (dBm)
2969 case SIOCGIWRANGE: //Get range of parameters
2970 case SIOCGIWRETRY: //get retry limits and lifetime
2971 case SIOCSIWRETRY: //set retry limits and lifetime
2973 case RT_PRIV_IOCTL_EXT:
2974 Status = -EOPNOTSUPP;
2977 if (wrq->u.data.pointer)
2979 if ( access_ok(VERIFY_WRITE, wrq->u.data.pointer, sizeof(privtab)) != TRUE)
2981 wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
2982 if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
2986 case RTPRIV_IOCTL_SET:
2987 if(access_ok(VERIFY_READ, wrq->u.data.pointer, wrq->u.data.length) != TRUE)
2989 rt_ioctl_setparam(net_dev, NULL, NULL, wrq->u.data.pointer);
2991 case RTPRIV_IOCTL_GSITESURVEY:
2992 RTMPIoctlGetSiteSurvey(pAd, wrq);
2997 DBGPRINT(RT_DEBUG_ERROR, ("IOCTL::unknown IOCTL's cmd = 0x%08x\n", cmd));
2998 Status = -EOPNOTSUPP;
3002 if(StateMachineTouched) // Upper layer sent a MLME-related operations
3003 RTMP_MLME_HANDLER(pAd);
3009 ==========================================================================
3013 TRUE if all parameters are OK, FALSE otherwise
3014 ==========================================================================
3017 IN PRTMP_ADAPTER pAdapter,
3020 NDIS_802_11_SSID Ssid, *pSsid=NULL;
3021 BOOLEAN StateMachineTouched = FALSE;
3024 if( strlen(arg) <= MAX_LEN_OF_SSID)
3026 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
3027 if (strlen(arg) != 0)
3029 NdisMoveMemory(Ssid.Ssid, arg, strlen(arg));
3030 Ssid.SsidLength = strlen(arg);
3034 Ssid.SsidLength = 0;
3035 memcpy(Ssid.Ssid, "", 0);
3036 pAdapter->StaCfg.BssType = BSS_INFRA;
3037 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
3038 pAdapter->StaCfg.WepStatus = Ndis802_11EncryptionDisabled;
3042 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3044 RTMP_MLME_RESET_STATE_MACHINE(pAdapter);
3045 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3048 if ((pAdapter->StaCfg.WpaPassPhraseLen >= 8) &&
3049 (pAdapter->StaCfg.WpaPassPhraseLen <= 64))
3051 STRING passphrase_str[65] = {0};
3052 UCHAR keyMaterial[40];
3054 RTMPMoveMemory(passphrase_str, pAdapter->StaCfg.WpaPassPhrase, pAdapter->StaCfg.WpaPassPhraseLen);
3055 RTMPZeroMemory(pAdapter->StaCfg.PMK, 32);
3056 if (pAdapter->StaCfg.WpaPassPhraseLen == 64)
3058 AtoH((PSTRING) pAdapter->StaCfg.WpaPassPhrase, pAdapter->StaCfg.PMK, 32);
3062 PasswordHash((PSTRING) pAdapter->StaCfg.WpaPassPhrase, Ssid.Ssid, Ssid.SsidLength, keyMaterial);
3063 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
3067 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
3068 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
3069 pAdapter->bConfigChanged = TRUE;
3071 MlmeEnqueue(pAdapter,
3072 MLME_CNTL_STATE_MACHINE,
3074 sizeof(NDIS_802_11_SSID),
3077 StateMachineTouched = TRUE;
3078 DBGPRINT(RT_DEBUG_TRACE, ("Set_SSID_Proc::(Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
3083 if (StateMachineTouched) // Upper layer sent a MLME-related operations
3084 RTMP_MLME_HANDLER(pAdapter);
3091 ==========================================================================
3093 Set WmmCapable Enable or Disable
3095 TRUE if all parameters are OK, FALSE otherwise
3096 ==========================================================================
3098 INT Set_WmmCapable_Proc(
3099 IN PRTMP_ADAPTER pAd,
3102 BOOLEAN bWmmCapable;
3104 bWmmCapable = simple_strtol(arg, 0, 10);
3106 if ((bWmmCapable == 1)
3108 && (pAd->NumberOfPipes >= 5)
3109 #endif // RTMP_MAC_USB //
3111 pAd->CommonCfg.bWmmCapable = TRUE;
3112 else if (bWmmCapable == 0)
3113 pAd->CommonCfg.bWmmCapable = FALSE;
3115 return FALSE; //Invalid argument
3117 DBGPRINT(RT_DEBUG_TRACE, ("Set_WmmCapable_Proc::(bWmmCapable=%d)\n",
3118 pAd->CommonCfg.bWmmCapable));
3122 #endif // WMM_SUPPORT //
3125 ==========================================================================
3127 Set Network Type(Infrastructure/Adhoc mode)
3129 TRUE if all parameters are OK, FALSE otherwise
3130 ==========================================================================
3132 INT Set_NetworkType_Proc(
3133 IN PRTMP_ADAPTER pAdapter,
3138 if (strcmp(arg, "Adhoc") == 0)
3140 if (pAdapter->StaCfg.BssType != BSS_ADHOC)
3142 // Config has changed
3143 pAdapter->bConfigChanged = TRUE;
3144 if (MONITOR_ON(pAdapter))
3146 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
3147 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
3149 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
3150 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
3151 pAdapter->StaCfg.bAutoReconnect = TRUE;
3152 LinkDown(pAdapter, FALSE);
3154 if (INFRA_ON(pAdapter))
3156 //BOOLEAN Cancelled;
3157 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
3158 // Since calling this indicate user don't want to connect to that SSID anymore.
3159 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
3160 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
3162 LinkDown(pAdapter, FALSE);
3164 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n"));
3167 pAdapter->StaCfg.BssType = BSS_ADHOC;
3168 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
3169 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(AD-HOC)\n"));
3171 else if (strcmp(arg, "Infra") == 0)
3173 if (pAdapter->StaCfg.BssType != BSS_INFRA)
3175 // Config has changed
3176 pAdapter->bConfigChanged = TRUE;
3177 if (MONITOR_ON(pAdapter))
3179 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
3180 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
3182 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
3183 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
3184 pAdapter->StaCfg.bAutoReconnect = TRUE;
3185 LinkDown(pAdapter, FALSE);
3187 if (ADHOC_ON(pAdapter))
3189 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
3190 // Since calling this indicate user don't want to connect to that SSID anymore.
3191 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
3192 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
3194 LinkDown(pAdapter, FALSE);
3197 pAdapter->StaCfg.BssType = BSS_INFRA;
3198 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
3199 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(INFRA)\n"));
3201 else if (strcmp(arg, "Monitor") == 0)
3204 BCN_TIME_CFG_STRUC csr;
3205 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_INFRA_ON);
3206 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_ADHOC_ON);
3207 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
3208 // disable all periodic state machine
3209 pAdapter->StaCfg.bAutoReconnect = FALSE;
3210 // reset all mlme state machine
3211 RTMP_MLME_RESET_STATE_MACHINE(pAdapter);
3212 DBGPRINT(RT_DEBUG_TRACE, ("fOP_STATUS_MEDIA_STATE_CONNECTED \n"));
3213 if (pAdapter->CommonCfg.CentralChannel == 0)
3215 if (pAdapter->CommonCfg.PhyMode == PHY_11AN_MIXED)
3216 pAdapter->CommonCfg.CentralChannel = 36;
3218 pAdapter->CommonCfg.CentralChannel = 6;
3221 N_ChannelCheck(pAdapter);
3223 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
3224 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
3225 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_ABOVE)
3227 // 40MHz ,control channel at lower
3228 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
3229 bbpValue &= (~0x18);
3231 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
3232 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
3233 // RX : control channel at lower
3234 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
3235 bbpValue &= (~0x20);
3236 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
3238 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
3239 Value &= 0xfffffffe;
3240 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
3241 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel + 2;
3242 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
3243 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
3244 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
3245 pAdapter->CommonCfg.Channel,
3246 pAdapter->CommonCfg.CentralChannel));
3248 else if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
3249 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
3250 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_BELOW)
3252 // 40MHz ,control channel at upper
3253 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
3254 bbpValue &= (~0x18);
3256 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
3257 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
3258 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
3260 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
3262 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
3264 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
3265 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel - 2;
3266 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
3267 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
3268 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
3269 pAdapter->CommonCfg.Channel,
3270 pAdapter->CommonCfg.CentralChannel));
3275 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
3276 bbpValue &= (~0x18);
3277 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
3278 pAdapter->CommonCfg.BBPCurrentBW = BW_20;
3279 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.Channel, FALSE);
3280 AsicLockChannel(pAdapter, pAdapter->CommonCfg.Channel);
3281 DBGPRINT(RT_DEBUG_TRACE, ("BW_20, Channel(%d)\n", pAdapter->CommonCfg.Channel));
3283 // Enable Rx with promiscuous reception
3284 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, 0x3);
3285 // ASIC supporsts sniffer function with replacing RSSI with timestamp.
3286 //RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
3288 //RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
3290 RTMP_IO_READ32(pAdapter, BCN_TIME_CFG, &csr.word);
3291 csr.field.bBeaconGen = 0;
3292 csr.field.bTBTTEnable = 0;
3293 csr.field.TsfSyncMode = 0;
3294 RTMP_IO_WRITE32(pAdapter, BCN_TIME_CFG, csr.word);
3296 pAdapter->StaCfg.BssType = BSS_MONITOR;
3297 pAdapter->net_dev->type = ARPHRD_IEEE80211_PRISM; //ARPHRD_IEEE80211; // IEEE80211
3298 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(MONITOR)\n"));
3301 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
3302 pAdapter->StaCfg.WpaState = SS_NOTUSE;
3304 DBGPRINT(RT_DEBUG_TRACE, ("Set_NetworkType_Proc::(NetworkType=%d)\n", pAdapter->StaCfg.BssType));
3310 ==========================================================================
3312 Set Authentication mode
3314 TRUE if all parameters are OK, FALSE otherwise
3315 ==========================================================================
3317 INT Set_AuthMode_Proc(
3318 IN PRTMP_ADAPTER pAdapter,
3321 if ((strcmp(arg, "WEPAUTO") == 0) || (strcmp(arg, "wepauto") == 0))
3322 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeAutoSwitch;
3323 else if ((strcmp(arg, "OPEN") == 0) || (strcmp(arg, "open") == 0))
3324 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
3325 else if ((strcmp(arg, "SHARED") == 0) || (strcmp(arg, "shared") == 0))
3326 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
3327 else if ((strcmp(arg, "WPAPSK") == 0) || (strcmp(arg, "wpapsk") == 0))
3328 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
3329 else if ((strcmp(arg, "WPANONE") == 0) || (strcmp(arg, "wpanone") == 0))
3330 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
3331 else if ((strcmp(arg, "WPA2PSK") == 0) || (strcmp(arg, "wpa2psk") == 0))
3332 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
3333 else if ((strcmp(arg, "WPA") == 0) || (strcmp(arg, "wpa") == 0))
3334 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
3335 else if ((strcmp(arg, "WPA2") == 0) || (strcmp(arg, "wpa2") == 0))
3336 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
3340 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
3342 DBGPRINT(RT_DEBUG_TRACE, ("Set_AuthMode_Proc::(AuthMode=%d)\n", pAdapter->StaCfg.AuthMode));
3348 ==========================================================================
3352 TRUE if all parameters are OK, FALSE otherwise
3353 ==========================================================================
3355 INT Set_EncrypType_Proc(
3356 IN PRTMP_ADAPTER pAdapter,
3359 if ((strcmp(arg, "NONE") == 0) || (strcmp(arg, "none") == 0))
3361 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3362 return TRUE; // do nothing
3364 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
3365 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
3366 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
3368 else if ((strcmp(arg, "WEP") == 0) || (strcmp(arg, "wep") == 0))
3370 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3371 return TRUE; // do nothing
3373 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
3374 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
3375 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
3377 else if ((strcmp(arg, "TKIP") == 0) || (strcmp(arg, "tkip") == 0))
3379 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
3380 return TRUE; // do nothing
3382 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
3383 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
3384 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
3386 else if ((strcmp(arg, "AES") == 0) || (strcmp(arg, "aes") == 0))
3388 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
3389 return TRUE; // do nothing
3391 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
3392 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
3393 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
3398 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
3400 DBGPRINT(RT_DEBUG_TRACE, ("Set_EncrypType_Proc::(EncrypType=%d)\n", pAdapter->StaCfg.WepStatus));
3406 ==========================================================================
3410 TRUE if all parameters are OK, FALSE otherwise
3411 ==========================================================================
3413 INT Set_DefaultKeyID_Proc(
3414 IN PRTMP_ADAPTER pAdapter,
3419 KeyIdx = simple_strtol(arg, 0, 10);
3420 if((KeyIdx >= 1 ) && (KeyIdx <= 4))
3421 pAdapter->StaCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1 );
3423 return FALSE; //Invalid argument
3425 DBGPRINT(RT_DEBUG_TRACE, ("Set_DefaultKeyID_Proc::(DefaultKeyID=%d)\n", pAdapter->StaCfg.DefaultKeyId));
3431 ==========================================================================
3435 TRUE if all parameters are OK, FALSE otherwise
3436 ==========================================================================
3439 IN PRTMP_ADAPTER pAdapter,
3444 UCHAR CipherAlg=CIPHER_WEP64;
3446 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3447 return TRUE; // do nothing
3449 KeyLen = strlen(arg);
3453 case 5: //wep 40 Ascii type
3454 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
3455 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
3456 CipherAlg = CIPHER_WEP64;
3457 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
3459 case 10: //wep 40 Hex type
3460 for(i=0; i < KeyLen; i++)
3462 if( !isxdigit(*(arg+i)) )
3463 return FALSE; //Not Hex value;
3465 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
3466 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
3467 CipherAlg = CIPHER_WEP64;
3468 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
3470 case 13: //wep 104 Ascii type
3471 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
3472 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
3473 CipherAlg = CIPHER_WEP128;
3474 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
3476 case 26: //wep 104 Hex type
3477 for(i=0; i < KeyLen; i++)
3479 if( !isxdigit(*(arg+i)) )
3480 return FALSE; //Not Hex value;
3482 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
3483 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
3484 CipherAlg = CIPHER_WEP128;
3485 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
3487 default: //Invalid argument
3488 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::Invalid argument (=%s)\n", arg));
3492 pAdapter->SharedKey[BSS0][0].CipherAlg = CipherAlg;
3494 // Set keys (into ASIC)
3495 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3497 else // Old WEP stuff
3499 AsicAddSharedKeyEntry(pAdapter,
3502 pAdapter->SharedKey[BSS0][0].CipherAlg,
3503 pAdapter->SharedKey[BSS0][0].Key,
3511 ==========================================================================
3516 TRUE if all parameters are OK, FALSE otherwise
3517 ==========================================================================
3520 IN PRTMP_ADAPTER pAdapter,
3525 UCHAR CipherAlg=CIPHER_WEP64;
3527 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3528 return TRUE; // do nothing
3530 KeyLen = strlen(arg);
3534 case 5: //wep 40 Ascii type
3535 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
3536 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
3537 CipherAlg = CIPHER_WEP64;
3538 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
3540 case 10: //wep 40 Hex type
3541 for(i=0; i < KeyLen; i++)
3543 if( !isxdigit(*(arg+i)) )
3544 return FALSE; //Not Hex value;
3546 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
3547 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
3548 CipherAlg = CIPHER_WEP64;
3549 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
3551 case 13: //wep 104 Ascii type
3552 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
3553 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
3554 CipherAlg = CIPHER_WEP128;
3555 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
3557 case 26: //wep 104 Hex type
3558 for(i=0; i < KeyLen; i++)
3560 if( !isxdigit(*(arg+i)) )
3561 return FALSE; //Not Hex value;
3563 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
3564 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
3565 CipherAlg = CIPHER_WEP128;
3566 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
3568 default: //Invalid argument
3569 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::Invalid argument (=%s)\n", arg));
3572 pAdapter->SharedKey[BSS0][1].CipherAlg = CipherAlg;
3574 // Set keys (into ASIC)
3575 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3577 else // Old WEP stuff
3579 AsicAddSharedKeyEntry(pAdapter,
3582 pAdapter->SharedKey[BSS0][1].CipherAlg,
3583 pAdapter->SharedKey[BSS0][1].Key,
3591 ==========================================================================
3595 TRUE if all parameters are OK, FALSE otherwise
3596 ==========================================================================
3599 IN PRTMP_ADAPTER pAdapter,
3604 UCHAR CipherAlg=CIPHER_WEP64;
3606 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3607 return TRUE; // do nothing
3609 KeyLen = strlen(arg);
3613 case 5: //wep 40 Ascii type
3614 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
3615 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
3616 CipherAlg = CIPHER_WEP64;
3617 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
3619 case 10: //wep 40 Hex type
3620 for(i=0; i < KeyLen; i++)
3622 if( !isxdigit(*(arg+i)) )
3623 return FALSE; //Not Hex value;
3625 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
3626 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
3627 CipherAlg = CIPHER_WEP64;
3628 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
3630 case 13: //wep 104 Ascii type
3631 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
3632 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
3633 CipherAlg = CIPHER_WEP128;
3634 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
3636 case 26: //wep 104 Hex type
3637 for(i=0; i < KeyLen; i++)
3639 if( !isxdigit(*(arg+i)) )
3640 return FALSE; //Not Hex value;
3642 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
3643 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
3644 CipherAlg = CIPHER_WEP128;
3645 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
3647 default: //Invalid argument
3648 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::Invalid argument (=%s)\n", arg));
3651 pAdapter->SharedKey[BSS0][2].CipherAlg = CipherAlg;
3653 // Set keys (into ASIC)
3654 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3656 else // Old WEP stuff
3658 AsicAddSharedKeyEntry(pAdapter,
3661 pAdapter->SharedKey[BSS0][2].CipherAlg,
3662 pAdapter->SharedKey[BSS0][2].Key,
3670 ==========================================================================
3674 TRUE if all parameters are OK, FALSE otherwise
3675 ==========================================================================
3678 IN PRTMP_ADAPTER pAdapter,
3683 UCHAR CipherAlg=CIPHER_WEP64;
3685 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3686 return TRUE; // do nothing
3688 KeyLen = strlen(arg);
3692 case 5: //wep 40 Ascii type
3693 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
3694 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
3695 CipherAlg = CIPHER_WEP64;
3696 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
3698 case 10: //wep 40 Hex type
3699 for(i=0; i < KeyLen; i++)
3701 if( !isxdigit(*(arg+i)) )
3702 return FALSE; //Not Hex value;
3704 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
3705 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
3706 CipherAlg = CIPHER_WEP64;
3707 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
3709 case 13: //wep 104 Ascii type
3710 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
3711 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
3712 CipherAlg = CIPHER_WEP128;
3713 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
3715 case 26: //wep 104 Hex type
3716 for(i=0; i < KeyLen; i++)
3718 if( !isxdigit(*(arg+i)) )
3719 return FALSE; //Not Hex value;
3721 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
3722 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
3723 CipherAlg = CIPHER_WEP128;
3724 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
3726 default: //Invalid argument
3727 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::Invalid argument (=%s)\n", arg));
3730 pAdapter->SharedKey[BSS0][3].CipherAlg = CipherAlg;
3732 // Set keys (into ASIC)
3733 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3735 else // Old WEP stuff
3737 AsicAddSharedKeyEntry(pAdapter,
3740 pAdapter->SharedKey[BSS0][3].CipherAlg,
3741 pAdapter->SharedKey[BSS0][3].Key,
3750 ==========================================================================
3754 TRUE if all parameters are OK, FALSE otherwise
3755 ==========================================================================
3757 INT Set_WPAPSK_Proc(
3758 IN PRTMP_ADAPTER pAd,
3763 if ((pAd->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
3764 (pAd->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
3765 (pAd->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
3767 return TRUE; // do nothing
3769 DBGPRINT(RT_DEBUG_TRACE, ("Set_WPAPSK_Proc::(WPAPSK=%s)\n", arg));
3771 status = RT_CfgSetWPAPSKKey(pAd, arg, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen, pAd->StaCfg.PMK);
3772 if (status == FALSE)
3774 DBGPRINT(RT_DEBUG_TRACE, ("Set_WPAPSK_Proc(): Set key failed!\n"));
3777 NdisZeroMemory(pAd->StaCfg.WpaPassPhrase, 64);
3778 NdisMoveMemory(pAd->StaCfg.WpaPassPhrase, arg, strlen(arg));
3779 pAd->StaCfg.WpaPassPhraseLen = (UINT)strlen(arg);
3783 if(pAd->StaCfg.BssType == BSS_ADHOC &&
3784 pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
3786 pAd->StaCfg.WpaState = SS_NOTUSE;
3790 // Start STA supplicant state machine
3791 pAd->StaCfg.WpaState = SS_START;
3798 ==========================================================================
3800 Set Power Saving mode
3802 TRUE if all parameters are OK, FALSE otherwise
3803 ==========================================================================
3805 INT Set_PSMode_Proc(
3806 IN PRTMP_ADAPTER pAdapter,
3809 if (pAdapter->StaCfg.BssType == BSS_INFRA)
3811 if ((strcmp(arg, "Max_PSP") == 0) ||
3812 (strcmp(arg, "max_psp") == 0) ||
3813 (strcmp(arg, "MAX_PSP") == 0))
3815 // do NOT turn on PSM bit here, wait until MlmeCheckPsmChange()
3816 // to exclude certain situations.
3817 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
3818 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeMAX_PSP;
3819 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeMAX_PSP;
3820 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
3821 pAdapter->StaCfg.DefaultListenCount = 5;
3824 else if ((strcmp(arg, "Fast_PSP") == 0) ||
3825 (strcmp(arg, "fast_psp") == 0) ||
3826 (strcmp(arg, "FAST_PSP") == 0))
3828 // do NOT turn on PSM bit here, wait until MlmeCheckPsmChange()
3829 // to exclude certain situations.
3830 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
3831 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
3832 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeFast_PSP;
3833 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeFast_PSP;
3834 pAdapter->StaCfg.DefaultListenCount = 3;
3836 else if ((strcmp(arg, "Legacy_PSP") == 0) ||
3837 (strcmp(arg, "legacy_psp") == 0) ||
3838 (strcmp(arg, "LEGACY_PSP") == 0))
3840 // do NOT turn on PSM bit here, wait until MlmeCheckPsmChange()
3841 // to exclude certain situations.
3842 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
3843 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
3844 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeLegacy_PSP;
3845 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeLegacy_PSP;
3846 pAdapter->StaCfg.DefaultListenCount = 3;
3850 //Default Ndis802_11PowerModeCAM
3851 // clear PSM bit immediately
3852 RTMP_SET_PSM_BIT(pAdapter, PWR_ACTIVE);
3853 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
3854 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
3855 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
3856 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
3859 DBGPRINT(RT_DEBUG_TRACE, ("Set_PSMode_Proc::(PSMode=%ld)\n", pAdapter->StaCfg.WindowsPowerMode));
3869 ==========================================================================
3871 Set WpaSupport flag.
3873 0: Driver ignore wpa_supplicant.
3874 1: wpa_supplicant initiates scanning and AP selection.
3875 2: driver takes care of scanning, AP selection, and IEEE 802.11 association parameters.
3877 TRUE if all parameters are OK, FALSE otherwise
3878 ==========================================================================
3880 INT Set_Wpa_Support(
3881 IN PRTMP_ADAPTER pAd,
3885 if ( simple_strtol(arg, 0, 10) == 0)
3886 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
3887 else if ( simple_strtol(arg, 0, 10) == 1)
3888 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE;
3889 else if ( simple_strtol(arg, 0, 10) == 2)
3890 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE_WITH_WEB_UI;
3892 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
3894 DBGPRINT(RT_DEBUG_TRACE, ("Set_Wpa_Support::(WpaSupplicantUP=%d)\n", pAd->StaCfg.WpaSupplicantUP));
3899 INT Set_TGnWifiTest_Proc(
3900 IN PRTMP_ADAPTER pAd,
3903 if (simple_strtol(arg, 0, 10) == 0)
3904 pAd->StaCfg.bTGnWifiTest = FALSE;
3906 pAd->StaCfg.bTGnWifiTest = TRUE;
3908 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_TGnWifiTest_Proc::(bTGnWifiTest=%d)\n", pAd->StaCfg.bTGnWifiTest));
3915 INT Show_Adhoc_MacTable_Proc(
3916 IN PRTMP_ADAPTER pAd,
3921 sprintf(extra, "\n");
3923 sprintf(extra + strlen(extra), "HT Operating Mode : %d\n", pAd->CommonCfg.AddHTInfo.AddHtInfo2.OperaionMode);
3925 sprintf(extra + strlen(extra), "\n%-19s%-4s%-4s%-7s%-7s%-7s%-10s%-6s%-6s%-6s%-6s\n",
3926 "MAC", "AID", "BSS", "RSSI0", "RSSI1", "RSSI2", "PhMd", "BW", "MCS", "SGI", "STBC");
3928 for (i=1; i<MAX_LEN_OF_MAC_TABLE; i++)
3930 PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
3932 if (strlen(extra) > (IW_PRIV_SIZE_MASK - 30))
3934 if ((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
3936 sprintf(extra + strlen(extra), "%02X:%02X:%02X:%02X:%02X:%02X ",
3937 pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
3938 pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5]);
3939 sprintf(extra + strlen(extra), "%-4d", (int)pEntry->Aid);
3940 sprintf(extra + strlen(extra), "%-4d", (int)pEntry->apidx);
3941 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi0);
3942 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi1);
3943 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi2);
3944 sprintf(extra + strlen(extra), "%-10s", GetPhyMode(pEntry->HTPhyMode.field.MODE));
3945 sprintf(extra + strlen(extra), "%-6s", GetBW(pEntry->HTPhyMode.field.BW));
3946 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.MCS);
3947 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.ShortGI);
3948 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.STBC);
3949 sprintf(extra + strlen(extra), "%-10d, %d, %d%%\n", pEntry->DebugFIFOCount, pEntry->DebugTxCount,
3950 (pEntry->DebugTxCount) ? ((pEntry->DebugTxCount-pEntry->DebugFIFOCount)*100/pEntry->DebugTxCount) : 0);
3951 sprintf(extra, "%s\n", extra);
3959 INT Set_BeaconLostTime_Proc(
3960 IN PRTMP_ADAPTER pAd,
3963 ULONG ltmp = (ULONG)simple_strtol(arg, 0, 10);
3965 if ((ltmp != 0) && (ltmp <= 60))
3966 pAd->StaCfg.BeaconLostTime = (ltmp * OS_HZ);
3968 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_BeaconLostTime_Proc::(BeaconLostTime=%ld)\n", pAd->StaCfg.BeaconLostTime));
3972 INT Set_AutoRoaming_Proc(
3973 IN PRTMP_ADAPTER pAd,
3976 if (simple_strtol(arg, 0, 10) == 0)
3977 pAd->StaCfg.bAutoRoaming = FALSE;
3979 pAd->StaCfg.bAutoRoaming = TRUE;
3981 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_AutoRoaming_Proc::(bAutoRoaming=%d)\n", pAd->StaCfg.bAutoRoaming));
3987 ==========================================================================
3989 Issue a site survey command to driver
3991 pAdapter Pointer to our adapter
3992 wrq Pointer to the ioctl argument
3999 1.) iwpriv ra0 set site_survey
4000 ==========================================================================
4002 INT Set_SiteSurvey_Proc(
4003 IN PRTMP_ADAPTER pAd,
4006 NDIS_802_11_SSID Ssid;
4008 //check if the interface is down
4009 if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
4011 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
4015 if (MONITOR_ON(pAd))
4017 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
4021 RTMPZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
4022 Ssid.SsidLength = 0;
4023 if ((arg != NULL) &&
4024 (strlen(arg) <= MAX_LEN_OF_SSID))
4026 RTMPMoveMemory(Ssid.Ssid, arg, strlen(arg));
4027 Ssid.SsidLength = strlen(arg);
4030 pAd->StaCfg.bScanReqIsFromWebUI = TRUE;
4032 if (pAd->Mlme.CntlMachine.CurrState != CNTL_IDLE)
4034 RTMP_MLME_RESET_STATE_MACHINE(pAd);
4035 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
4038 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
4039 // this request, because this request is initiated by NDIS.
4040 pAd->MlmeAux.CurrReqIsFromNdis = FALSE;
4041 // Reset allowed scan retries
4042 pAd->StaCfg.ScanCnt = 0;
4043 NdisGetSystemUpTime(&pAd->StaCfg.LastScanTime);
4046 MLME_CNTL_STATE_MACHINE,
4047 OID_802_11_BSSID_LIST_SCAN,
4051 RTMP_MLME_HANDLER(pAd);
4053 DBGPRINT(RT_DEBUG_TRACE, ("Set_SiteSurvey_Proc\n"));
4058 INT Set_ForceTxBurst_Proc(
4059 IN PRTMP_ADAPTER pAd,
4062 if (simple_strtol(arg, 0, 10) == 0)
4063 pAd->StaCfg.bForceTxBurst = FALSE;
4065 pAd->StaCfg.bForceTxBurst = TRUE;
4067 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_ForceTxBurst_Proc::(bForceTxBurst=%d)\n", pAd->StaCfg.bForceTxBurst));