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 INT Set_PCIePSLevel_Proc(
165 IN PRTMP_ADAPTER pAdapter,
170 IN PRTMP_ADAPTER pAd,
173 NDIS_STATUS RTMPWPANoneAddKeyProc(
174 IN PRTMP_ADAPTER pAd,
177 INT Set_FragTest_Proc(
178 IN PRTMP_ADAPTER pAdapter,
181 INT Set_TGnWifiTest_Proc(
182 IN PRTMP_ADAPTER pAd,
185 INT Set_LongRetryLimit_Proc(
186 IN PRTMP_ADAPTER pAdapter,
189 INT Set_ShortRetryLimit_Proc(
190 IN PRTMP_ADAPTER pAdapter,
195 INT Show_Adhoc_MacTable_Proc(
196 IN PRTMP_ADAPTER pAd,
199 INT Set_BeaconLostTime_Proc(
200 IN PRTMP_ADAPTER pAd,
203 INT Set_AutoRoaming_Proc(
204 IN PRTMP_ADAPTER pAd,
207 INT Set_SiteSurvey_Proc(
208 IN PRTMP_ADAPTER pAd,
211 INT Set_ForceTxBurst_Proc(
212 IN PRTMP_ADAPTER pAd,
217 INT (*set_proc)(PRTMP_ADAPTER pAdapter, PSTRING arg);
218 } *PRTMP_PRIVATE_SET_PROC, RTMP_PRIVATE_SUPPORT_PROC[] = {
219 {"DriverVersion", Set_DriverVersion_Proc},
220 {"CountryRegion", Set_CountryRegion_Proc},
221 {"CountryRegionABand", Set_CountryRegionABand_Proc},
222 {"SSID", Set_SSID_Proc},
223 {"WirelessMode", Set_WirelessMode_Proc},
224 {"TxBurst", Set_TxBurst_Proc},
225 {"TxPreamble", Set_TxPreamble_Proc},
226 {"TxPower", Set_TxPower_Proc},
227 {"Channel", Set_Channel_Proc},
228 {"BGProtection", Set_BGProtection_Proc},
229 {"RTSThreshold", Set_RTSThreshold_Proc},
230 {"FragThreshold", Set_FragThreshold_Proc},
231 {"HtBw", Set_HtBw_Proc},
232 {"HtMcs", Set_HtMcs_Proc},
233 {"HtGi", Set_HtGi_Proc},
234 {"HtOpMode", Set_HtOpMode_Proc},
235 {"HtExtcha", Set_HtExtcha_Proc},
236 {"HtMpduDensity", Set_HtMpduDensity_Proc},
237 {"HtBaWinSize", Set_HtBaWinSize_Proc},
238 {"HtRdg", Set_HtRdg_Proc},
239 {"HtAmsdu", Set_HtAmsdu_Proc},
240 {"HtAutoBa", Set_HtAutoBa_Proc},
241 {"HtBaDecline", Set_BADecline_Proc},
242 {"HtProtect", Set_HtProtect_Proc},
243 {"HtMimoPs", Set_HtMimoPs_Proc},
244 {"HtDisallowTKIP", Set_HtDisallowTKIP_Proc},
245 #ifdef AGGREGATION_SUPPORT
246 {"PktAggregate", Set_PktAggregate_Proc},
247 #endif // AGGREGATION_SUPPORT //
250 {"WmmCapable", Set_WmmCapable_Proc},
252 {"IEEE80211H", Set_IEEE80211H_Proc},
253 {"NetworkType", Set_NetworkType_Proc},
254 {"AuthMode", Set_AuthMode_Proc},
255 {"EncrypType", Set_EncrypType_Proc},
256 {"DefaultKeyID", Set_DefaultKeyID_Proc},
257 {"Key1", Set_Key1_Proc},
258 {"Key2", Set_Key2_Proc},
259 {"Key3", Set_Key3_Proc},
260 {"Key4", Set_Key4_Proc},
261 {"WPAPSK", Set_WPAPSK_Proc},
262 {"ResetCounter", Set_ResetStatCounter_Proc},
263 {"PSMode", Set_PSMode_Proc},
265 {"Debug", Set_Debug_Proc},
269 {"WpaSupport", Set_Wpa_Support},
275 {"FixedTxMode", Set_FixedTxMode_Proc},
276 {"TGnWifiTest", Set_TGnWifiTest_Proc},
277 {"ForceGF", Set_ForceGF_Proc},
278 {"LongRetry", Set_LongRetryLimit_Proc},
279 {"ShortRetry", Set_ShortRetryLimit_Proc},
281 //2008/09/11:KH add to support efuse<--
283 #ifdef RTMP_EFUSE_SUPPORT
284 {"efuseFreeNumber", set_eFuseGetFreeBlockCount_Proc},
285 {"efuseDump", set_eFusedump_Proc},
286 {"efuseLoadFromBin", set_eFuseLoadFromBin_Proc},
287 {"efuseBufferModeWriteBack", set_eFuseBufferModeWriteBack_Proc},
288 #endif // RTMP_EFUSE_SUPPORT //
290 //2008/09/11:KH add to support efuse-->
291 {"BeaconLostTime", Set_BeaconLostTime_Proc},
292 {"AutoRoaming", Set_AutoRoaming_Proc},
293 {"SiteSurvey", Set_SiteSurvey_Proc},
294 {"ForceTxBurst", Set_ForceTxBurst_Proc},
301 IN PRTMP_ADAPTER pAd,
302 IN PNDIS_802_11_KEY pKey)
305 MAC_TABLE_ENTRY *pEntry;
307 DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey ------>\n"));
309 if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
311 if (pKey->KeyIndex & 0x80000000)
313 if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
315 NdisZeroMemory(pAd->StaCfg.PMK, 32);
316 NdisMoveMemory(pAd->StaCfg.PMK, pKey->KeyMaterial, pKey->KeyLength);
320 NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));
321 pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
322 NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, pKey->KeyMaterial, LEN_TKIP_EK);
324 if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
326 NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
327 NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
331 NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
332 NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
335 // Decide its ChiperAlg
336 if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
337 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
338 else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)
339 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
341 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_NONE;
343 // Update these related information to MAC_TABLE_ENTRY
344 pEntry = &pAd->MacTab.Content[BSSID_WCID];
345 NdisMoveMemory(pEntry->PairwiseKey.Key, pAd->SharedKey[BSS0][0].Key, LEN_TKIP_EK);
346 NdisMoveMemory(pEntry->PairwiseKey.RxMic, pAd->SharedKey[BSS0][0].RxMic, LEN_TKIP_RXMICK);
347 NdisMoveMemory(pEntry->PairwiseKey.TxMic, pAd->SharedKey[BSS0][0].TxMic, LEN_TKIP_TXMICK);
348 pEntry->PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;
350 // Update pairwise key information to ASIC Shared Key Table
351 AsicAddSharedKeyEntry(pAd,
354 pAd->SharedKey[BSS0][0].CipherAlg,
355 pAd->SharedKey[BSS0][0].Key,
356 pAd->SharedKey[BSS0][0].TxMic,
357 pAd->SharedKey[BSS0][0].RxMic);
359 // Update ASIC WCID attribute table and IVEIV table
360 RTMPAddWcidAttributeEntry(pAd,
363 pAd->SharedKey[BSS0][0].CipherAlg,
366 if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
368 // set 802.1x port control
369 //pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
370 STA_PORT_SECURED(pAd);
372 // Indicate Connected for GUI
373 pAd->IndicateMediaState = NdisMediaStateConnected;
379 pAd->StaCfg.DefaultKeyId = (pKey->KeyIndex & 0xFF);
380 NdisZeroMemory(&pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId], sizeof(CIPHER_KEY));
381 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].KeyLen = LEN_TKIP_EK;
382 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key, pKey->KeyMaterial, LEN_TKIP_EK);
384 if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
386 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
387 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
391 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
392 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
395 // Update Shared Key CipherAlg
396 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_NONE;
397 if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
398 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_TKIP;
399 else if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)
400 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_AES;
402 // Update group key information to ASIC Shared Key Table
403 AsicAddSharedKeyEntry(pAd,
405 pAd->StaCfg.DefaultKeyId,
406 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
407 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key,
408 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic,
409 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic);
411 // Update ASIC WCID attribute table and IVEIV table
412 RTMPAddWcidAttributeEntry(pAd,
414 pAd->StaCfg.DefaultKeyId,
415 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
418 // set 802.1x port control
419 //pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
420 STA_PORT_SECURED(pAd);
422 // Indicate Connected for GUI
423 pAd->IndicateMediaState = NdisMediaStateConnected;
426 else // dynamic WEP from wpa_supplicant
431 if(pKey->KeyLength == 32)
434 KeyIdx = pKey->KeyIndex & 0x0fffffff;
438 // it is a default shared key, for Pairwise key setting
439 if (pKey->KeyIndex & 0x80000000)
441 pEntry = MacTableLookup(pAd, pKey->BSSID);
445 DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey: Set Pair-wise Key\n"));
447 // set key material and key length
448 pEntry->PairwiseKey.KeyLen = (UCHAR)pKey->KeyLength;
449 NdisMoveMemory(pEntry->PairwiseKey.Key, &pKey->KeyMaterial, pKey->KeyLength);
452 if (pKey->KeyLength == 5)
453 pEntry->PairwiseKey.CipherAlg = CIPHER_WEP64;
455 pEntry->PairwiseKey.CipherAlg = CIPHER_WEP128;
457 // Add Pair-wise key to Asic
458 AsicAddPairwiseKeyEntry(
462 &pEntry->PairwiseKey);
464 // update WCID attribute table and IVEIV table for this entry
465 RTMPAddWcidAttributeEntry(
468 KeyIdx, // The value may be not zero
469 pEntry->PairwiseKey.CipherAlg,
476 // Default key for tx (shared key)
477 pAd->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
479 // set key material and key length
480 pAd->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pKey->KeyLength;
481 NdisMoveMemory(pAd->SharedKey[BSS0][KeyIdx].Key, &pKey->KeyMaterial, pKey->KeyLength);
484 if (pKey->KeyLength == 5)
485 pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP64;
487 pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP128;
489 CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg;
490 Key = pAd->SharedKey[BSS0][KeyIdx].Key;
492 // Set Group key material to Asic
493 AsicAddSharedKeyEntry(pAd, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
495 // Update WCID attribute table and IVEIV table for this group key table
496 RTMPAddWcidAttributeEntry(pAd, BSS0, KeyIdx, CipherAlg, NULL);
505 char * rtstrchr(const char * s, int c)
507 for(; *s != (char) c; ++s)
514 This is required for LinEX2004/kernel2.6.7 to provide iwlist scanning function
518 rt_ioctl_giwname(struct net_device *dev,
519 struct iw_request_info *info,
520 char *name, char *extra)
522 strncpy(name, "Ralink STA", IFNAMSIZ);
523 // RT2870 2.1.0.0 uses "RT2870 Wireless"
524 // RT3090 2.1.0.0 uses "RT2860 Wireless"
528 int rt_ioctl_siwfreq(struct net_device *dev,
529 struct iw_request_info *info,
530 struct iw_freq *freq, char *extra)
532 PRTMP_ADAPTER pAdapter = NULL;
535 GET_PAD_FROM_NET_DEV(pAdapter, dev);
537 //check if the interface is down
538 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
540 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
548 if((freq->e == 0) && (freq->m <= 1000))
549 chan = freq->m; // Setting by channel number
551 MAP_KHZ_TO_CHANNEL_ID( (freq->m /100) , chan); // Setting by frequency - search the table , like 2.412G, 2.422G,
553 if (ChannelSanity(pAdapter, chan) == TRUE)
555 pAdapter->CommonCfg.Channel = chan;
556 DBGPRINT(RT_DEBUG_ERROR, ("==>rt_ioctl_siwfreq::SIOCSIWFREQ[cmd=0x%x] (Channel=%d)\n", SIOCSIWFREQ, pAdapter->CommonCfg.Channel));
563 int rt_ioctl_giwfreq(struct net_device *dev,
564 struct iw_request_info *info,
565 struct iw_freq *freq, char *extra)
567 PRTMP_ADAPTER pAdapter = NULL;
571 GET_PAD_FROM_NET_DEV(pAdapter, dev);
573 ch = pAdapter->CommonCfg.Channel;
575 DBGPRINT(RT_DEBUG_TRACE,("==>rt_ioctl_giwfreq %d\n", ch));
577 MAP_CHANNEL_ID_TO_KHZ(ch, m);
583 int rt_ioctl_siwmode(struct net_device *dev,
584 struct iw_request_info *info,
585 __u32 *mode, char *extra)
587 PRTMP_ADAPTER pAdapter = NULL;
589 GET_PAD_FROM_NET_DEV(pAdapter, dev);
591 //check if the interface is down
592 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
594 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
601 Set_NetworkType_Proc(pAdapter, "Adhoc");
604 Set_NetworkType_Proc(pAdapter, "Infra");
606 case IW_MODE_MONITOR:
607 Set_NetworkType_Proc(pAdapter, "Monitor");
610 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_siwmode::SIOCSIWMODE (unknown %d)\n", *mode));
614 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
615 pAdapter->StaCfg.WpaState = SS_NOTUSE;
620 int rt_ioctl_giwmode(struct net_device *dev,
621 struct iw_request_info *info,
622 __u32 *mode, char *extra)
624 PRTMP_ADAPTER pAdapter = NULL;
626 GET_PAD_FROM_NET_DEV(pAdapter, dev);
628 if (ADHOC_ON(pAdapter))
629 *mode = IW_MODE_ADHOC;
630 else if (INFRA_ON(pAdapter))
631 *mode = IW_MODE_INFRA;
632 else if (MONITOR_ON(pAdapter))
634 *mode = IW_MODE_MONITOR;
637 *mode = IW_MODE_AUTO;
639 DBGPRINT(RT_DEBUG_TRACE, ("==>rt_ioctl_giwmode(mode=%d)\n", *mode));
643 int rt_ioctl_siwsens(struct net_device *dev,
644 struct iw_request_info *info,
645 char *name, char *extra)
647 PRTMP_ADAPTER pAdapter = NULL;
649 GET_PAD_FROM_NET_DEV(pAdapter, dev);
651 //check if the interface is down
652 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
654 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
661 int rt_ioctl_giwsens(struct net_device *dev,
662 struct iw_request_info *info,
663 char *name, char *extra)
668 int rt_ioctl_giwrange(struct net_device *dev,
669 struct iw_request_info *info,
670 struct iw_point *data, char *extra)
672 PRTMP_ADAPTER pAdapter = NULL;
673 struct iw_range *range = (struct iw_range *) extra;
677 GET_PAD_FROM_NET_DEV(pAdapter, dev);
679 DBGPRINT(RT_DEBUG_TRACE ,("===>rt_ioctl_giwrange\n"));
680 data->length = sizeof(struct iw_range);
681 memset(range, 0, sizeof(struct iw_range));
683 range->txpower_capa = IW_TXPOW_DBM;
685 if (INFRA_ON(pAdapter)||ADHOC_ON(pAdapter))
687 range->min_pmp = 1 * 1024;
688 range->max_pmp = 65535 * 1024;
689 range->min_pmt = 1 * 1024;
690 range->max_pmt = 1000 * 1024;
691 range->pmp_flags = IW_POWER_PERIOD;
692 range->pmt_flags = IW_POWER_TIMEOUT;
693 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT |
694 IW_POWER_UNICAST_R | IW_POWER_ALL_R;
697 range->we_version_compiled = WIRELESS_EXT;
698 range->we_version_source = 14;
700 range->retry_capa = IW_RETRY_LIMIT;
701 range->retry_flags = IW_RETRY_LIMIT;
702 range->min_retry = 0;
703 range->max_retry = 255;
705 range->num_channels = pAdapter->ChannelListNum;
708 for (i = 1; i <= range->num_channels; i++)
711 range->freq[val].i = pAdapter->ChannelList[i-1].Channel;
712 MAP_CHANNEL_ID_TO_KHZ(pAdapter->ChannelList[i-1].Channel, m);
713 range->freq[val].m = m * 100; /* OS_HZ */
715 range->freq[val].e = 1;
717 if (val == IW_MAX_FREQUENCIES)
720 range->num_frequency = val;
722 range->max_qual.qual = 100; /* what is correct max? This was not
723 * documented exactly. At least
724 * 69 has been observed. */
725 range->max_qual.level = 0; /* dB */
726 range->max_qual.noise = 0; /* dB */
728 /* What would be suitable values for "average/typical" qual? */
729 range->avg_qual.qual = 20;
730 range->avg_qual.level = -60;
731 range->avg_qual.noise = -95;
732 range->sensitivity = 3;
734 range->max_encoding_tokens = NR_WEP_KEYS;
735 range->num_encoding_sizes = 2;
736 range->encoding_size[0] = 5;
737 range->encoding_size[1] = 13;
740 range->max_rts = 2347;
741 range->min_frag = 256;
742 range->max_frag = 2346;
744 /* IW_ENC_CAPA_* bit field */
745 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
746 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
751 int rt_ioctl_siwap(struct net_device *dev,
752 struct iw_request_info *info,
753 struct sockaddr *ap_addr, char *extra)
755 PRTMP_ADAPTER pAdapter = NULL;
756 NDIS_802_11_MAC_ADDRESS Bssid;
758 GET_PAD_FROM_NET_DEV(pAdapter, dev);
760 //check if the interface is down
761 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
763 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
767 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
769 RTMP_MLME_RESET_STATE_MACHINE(pAdapter);
770 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
773 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
774 // this request, because this request is initiated by NDIS.
775 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
776 // Prevent to connect AP again in STAMlmePeriodicExec
777 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
779 memset(Bssid, 0, MAC_ADDR_LEN);
780 memcpy(Bssid, ap_addr->sa_data, MAC_ADDR_LEN);
781 MlmeEnqueue(pAdapter,
782 MLME_CNTL_STATE_MACHINE,
784 sizeof(NDIS_802_11_MAC_ADDRESS),
787 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCSIWAP %02x:%02x:%02x:%02x:%02x:%02x\n",
788 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
793 int rt_ioctl_giwap(struct net_device *dev,
794 struct iw_request_info *info,
795 struct sockaddr *ap_addr, char *extra)
797 PRTMP_ADAPTER pAdapter = NULL;
799 GET_PAD_FROM_NET_DEV(pAdapter, dev);
801 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
803 ap_addr->sa_family = ARPHRD_ETHER;
804 memcpy(ap_addr->sa_data, &pAdapter->CommonCfg.Bssid, ETH_ALEN);
807 else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
809 ap_addr->sa_family = ARPHRD_ETHER;
810 memcpy(ap_addr->sa_data, &pAdapter->MlmeAux.Bssid, ETH_ALEN);
814 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIWAP(=EMPTY)\n"));
822 * Units are in db above the noise floor. That means the
823 * rssi values reported in the tx/rx descriptors in the
824 * driver are the SNR expressed in db.
826 * If you assume that the noise floor is -95, which is an
827 * excellent assumption 99.5 % of the time, then you can
828 * derive the absolute signal level (i.e. -95 + rssi).
829 * There are some other slight factors to take into account
830 * depending on whether the rssi measurement is from 11b,
831 * 11g, or 11a. These differences are at most 2db and
834 * NB: various calculations are based on the orinoco/wavelan
835 * drivers for compatibility
837 static void set_quality(PRTMP_ADAPTER pAdapter,
838 struct iw_quality *iq,
845 ChannelQuality = 100;
846 else if (rssi >= -80) // between -50 ~ -80dbm
847 ChannelQuality = (__u8)(24 + ((rssi + 80) * 26)/10);
848 else if (rssi >= -90) // between -80 ~ -90dbm
849 ChannelQuality = (__u8)((rssi + 90) * 26)/10;
853 iq->qual = (__u8)ChannelQuality;
855 iq->level = (__u8)(rssi);
856 iq->noise = (pAdapter->BbpWriteLatch[66] > pAdapter->BbpTuning.FalseCcaUpperThreshold) ? ((__u8)pAdapter->BbpTuning.FalseCcaUpperThreshold) : ((__u8) pAdapter->BbpWriteLatch[66]); // noise level (dBm)
857 iq->noise += 256 - 143;
858 iq->updated = pAdapter->iw_stats.qual.updated;
861 int rt_ioctl_iwaplist(struct net_device *dev,
862 struct iw_request_info *info,
863 struct iw_point *data, char *extra)
865 PRTMP_ADAPTER pAdapter = NULL;
867 struct sockaddr addr[IW_MAX_AP];
868 struct iw_quality qual[IW_MAX_AP];
871 GET_PAD_FROM_NET_DEV(pAdapter, dev);
873 //check if the interface is down
874 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
876 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
882 for (i = 0; i <IW_MAX_AP ; i++)
884 if (i >= pAdapter->ScanTab.BssNr)
886 addr[i].sa_family = ARPHRD_ETHER;
887 memcpy(addr[i].sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
888 set_quality(pAdapter, &qual[i], pAdapter->ScanTab.BssEntry[i].Rssi);
891 memcpy(extra, &addr, i*sizeof(addr[0]));
892 data->flags = 1; /* signal quality present (sort of) */
893 memcpy(extra + i*sizeof(addr[0]), &qual, i*sizeof(qual[i]));
898 int rt_ioctl_siwscan(struct net_device *dev,
899 struct iw_request_info *info,
900 struct iw_point *data, char *extra)
902 PRTMP_ADAPTER pAdapter = NULL;
905 int Status = NDIS_STATUS_SUCCESS;
907 GET_PAD_FROM_NET_DEV(pAdapter, dev);
909 //check if the interface is down
910 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
912 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
916 if (MONITOR_ON(pAdapter))
918 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
923 if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
925 pAdapter->StaCfg.WpaSupplicantScanCount++;
928 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
929 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
930 return NDIS_STATUS_SUCCESS;
934 if ((pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE) &&
935 (pAdapter->StaCfg.WpaSupplicantScanCount > 3))
937 DBGPRINT(RT_DEBUG_TRACE, ("!!! WpaSupplicantScanCount > 3\n"));
938 Status = NDIS_STATUS_SUCCESS;
942 if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
943 ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
944 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) &&
945 (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
947 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
948 Status = NDIS_STATUS_SUCCESS;
952 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
954 RTMP_MLME_RESET_STATE_MACHINE(pAdapter);
955 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
958 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
959 // this request, because this request is initiated by NDIS.
960 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
961 // Reset allowed scan retries
962 pAdapter->StaCfg.ScanCnt = 0;
963 pAdapter->StaCfg.LastScanTime = Now;
965 MlmeEnqueue(pAdapter,
966 MLME_CNTL_STATE_MACHINE,
967 OID_802_11_BSSID_LIST_SCAN,
971 Status = NDIS_STATUS_SUCCESS;
972 RTMP_MLME_HANDLER(pAdapter);
974 return NDIS_STATUS_SUCCESS;
977 int rt_ioctl_giwscan(struct net_device *dev,
978 struct iw_request_info *info,
979 struct iw_point *data, char *extra)
981 PRTMP_ADAPTER pAdapter = NULL;
983 PSTRING current_ev = extra, previous_ev = extra;
986 STRING custom[MAX_CUSTOM_LEN] = {0};
989 GET_PAD_FROM_NET_DEV(pAdapter, dev);
991 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
994 * Still scanning, indicate the caller should try again.
999 if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
1001 pAdapter->StaCfg.WpaSupplicantScanCount = 0;
1004 if (pAdapter->ScanTab.BssNr == 0)
1010 if (data->length > 0)
1011 end_buf = extra + data->length;
1013 end_buf = extra + IW_SCAN_MAX_DATA;
1015 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
1017 if (current_ev >= end_buf)
1023 //================================
1024 memset(&iwe, 0, sizeof(iwe));
1025 iwe.cmd = SIOCGIWAP;
1026 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1027 memcpy(iwe.u.ap_addr.sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, ETH_ALEN);
1029 previous_ev = current_ev;
1030 current_ev = iwe_stream_add_event(info, current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);
1031 if (current_ev == previous_ev)
1036 it will show scanned AP's WirelessMode .
1045 memset(&iwe, 0, sizeof(iwe));
1046 iwe.cmd = SIOCGIWNAME;
1050 PBSS_ENTRY pBssEntry=&pAdapter->ScanTab.BssEntry[i];
1051 BOOLEAN isGonly=FALSE;
1054 if (pBssEntry->Channel>14)
1056 if (pBssEntry->HtCapabilityLen!=0)
1057 strcpy(iwe.u.name,"802.11a/n");
1059 strcpy(iwe.u.name,"802.11a");
1064 if one of non B mode rate is set supported rate . it mean G only.
1066 for (rateCnt=0;rateCnt<pBssEntry->SupRateLen;rateCnt++)
1069 6Mbps(140) 9Mbps(146) and >=12Mbps(152) are supported rate , it mean G only.
1071 if (pBssEntry->SupRate[rateCnt]==140 || pBssEntry->SupRate[rateCnt]==146 || pBssEntry->SupRate[rateCnt]>=152)
1075 for (rateCnt=0;rateCnt<pBssEntry->ExtRateLen;rateCnt++)
1077 if (pBssEntry->ExtRate[rateCnt]==140 || pBssEntry->ExtRate[rateCnt]==146 || pBssEntry->ExtRate[rateCnt]>=152)
1082 if (pBssEntry->HtCapabilityLen!=0)
1085 strcpy(iwe.u.name,"802.11g/n");
1087 strcpy(iwe.u.name,"802.11b/g/n");
1092 strcpy(iwe.u.name,"802.11g");
1095 if (pBssEntry->SupRateLen==4 && pBssEntry->ExtRateLen==0)
1096 strcpy(iwe.u.name,"802.11b");
1098 strcpy(iwe.u.name,"802.11b/g");
1104 previous_ev = current_ev;
1105 current_ev = iwe_stream_add_event(info, current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);
1106 if (current_ev == previous_ev)
1110 //================================
1111 memset(&iwe, 0, sizeof(iwe));
1112 iwe.cmd = SIOCGIWESSID;
1113 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].SsidLen;
1114 iwe.u.data.flags = 1;
1116 previous_ev = current_ev;
1117 current_ev = iwe_stream_add_point(info, current_ev,end_buf, &iwe, (PSTRING) pAdapter->ScanTab.BssEntry[i].Ssid);
1118 if (current_ev == previous_ev)
1122 //================================
1123 memset(&iwe, 0, sizeof(iwe));
1124 iwe.cmd = SIOCGIWMODE;
1125 if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11IBSS)
1127 iwe.u.mode = IW_MODE_ADHOC;
1129 else if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11Infrastructure)
1131 iwe.u.mode = IW_MODE_INFRA;
1135 iwe.u.mode = IW_MODE_AUTO;
1137 iwe.len = IW_EV_UINT_LEN;
1139 previous_ev = current_ev;
1140 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
1141 if (current_ev == previous_ev)
1144 //Channel and Frequency
1145 //================================
1146 memset(&iwe, 0, sizeof(iwe));
1147 iwe.cmd = SIOCGIWFREQ;
1148 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
1149 iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
1151 iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
1155 previous_ev = current_ev;
1156 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
1157 if (current_ev == previous_ev)
1160 //Add quality statistics
1161 //================================
1162 memset(&iwe, 0, sizeof(iwe));
1164 iwe.u.qual.level = 0;
1165 iwe.u.qual.noise = 0;
1166 set_quality(pAdapter, &iwe.u.qual, pAdapter->ScanTab.BssEntry[i].Rssi);
1167 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
1168 if (current_ev == previous_ev)
1172 //================================
1173 memset(&iwe, 0, sizeof(iwe));
1174 iwe.cmd = SIOCGIWENCODE;
1175 if (CAP_IS_PRIVACY_ON (pAdapter->ScanTab.BssEntry[i].CapabilityInfo ))
1176 iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1178 iwe.u.data.flags = IW_ENCODE_DISABLED;
1180 previous_ev = current_ev;
1181 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);
1182 if (current_ev == previous_ev)
1186 //================================
1187 if (pAdapter->ScanTab.BssEntry[i].SupRateLen)
1189 UCHAR tmpRate = pAdapter->ScanTab.BssEntry[i].SupRate[pAdapter->ScanTab.BssEntry[i].SupRateLen-1];
1190 memset(&iwe, 0, sizeof(iwe));
1191 iwe.cmd = SIOCGIWRATE;
1192 current_val = current_ev + IW_EV_LCP_LEN;
1193 if (tmpRate == 0x82)
1194 iwe.u.bitrate.value = 1 * 1000000;
1195 else if (tmpRate == 0x84)
1196 iwe.u.bitrate.value = 2 * 1000000;
1197 else if (tmpRate == 0x8B)
1198 iwe.u.bitrate.value = 5.5 * 1000000;
1199 else if (tmpRate == 0x96)
1200 iwe.u.bitrate.value = 11 * 1000000;
1202 iwe.u.bitrate.value = (tmpRate/2) * 1000000;
1204 if (tmpRate == 0x6c && pAdapter->ScanTab.BssEntry[i].HtCapabilityLen > 0)
1206 int rate_count = sizeof(ralinkrate)/sizeof(__s32);
1207 HT_CAP_INFO capInfo = pAdapter->ScanTab.BssEntry[i].HtCapability.HtCapInfo;
1208 int shortGI = capInfo.ChannelWidth ? capInfo.ShortGIfor40 : capInfo.ShortGIfor20;
1209 int maxMCS = pAdapter->ScanTab.BssEntry[i].HtCapability.MCSSet[1] ? 15 : 7;
1210 int rate_index = 12 + ((UCHAR)capInfo.ChannelWidth * 24) + ((UCHAR)shortGI *48) + ((UCHAR)maxMCS);
1213 if (rate_index > rate_count)
1214 rate_index = rate_count;
1215 iwe.u.bitrate.value = ralinkrate[rate_index] * 500000;
1218 iwe.u.bitrate.disabled = 0;
1219 current_val = iwe_stream_add_value(info, current_ev,
1220 current_val, end_buf, &iwe,
1223 if((current_val-current_ev)>IW_EV_LCP_LEN)
1224 current_ev = current_val;
1230 if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
1232 memset(&iwe, 0, sizeof(iwe));
1233 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1234 memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].WpaIE.IE[0]),
1235 pAdapter->ScanTab.BssEntry[i].WpaIE.IELen);
1236 iwe.cmd = IWEVGENIE;
1237 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].WpaIE.IELen;
1238 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, custom);
1239 if (current_ev == previous_ev)
1244 if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
1246 memset(&iwe, 0, sizeof(iwe));
1247 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1248 memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].RsnIE.IE[0]),
1249 pAdapter->ScanTab.BssEntry[i].RsnIE.IELen);
1250 iwe.cmd = IWEVGENIE;
1251 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].RsnIE.IELen;
1252 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, custom);
1253 if (current_ev == previous_ev)
1258 data->length = current_ev - extra;
1259 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
1260 DBGPRINT(RT_DEBUG_ERROR ,("===>rt_ioctl_giwscan. %d(%d) BSS returned, data->length = %d\n",i , pAdapter->ScanTab.BssNr, data->length));
1264 int rt_ioctl_siwessid(struct net_device *dev,
1265 struct iw_request_info *info,
1266 struct iw_point *data, char *essid)
1268 PRTMP_ADAPTER pAdapter = NULL;
1270 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1272 //check if the interface is down
1273 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1275 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1281 PSTRING pSsidString = NULL;
1283 // Includes null character.
1284 if (data->length > (IW_ESSID_MAX_SIZE + 1))
1287 pSsidString = kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
1290 NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
1291 NdisMoveMemory(pSsidString, essid, data->length);
1292 if (Set_SSID_Proc(pAdapter, pSsidString) == FALSE)
1301 if (Set_SSID_Proc(pAdapter, "") == FALSE)
1307 int rt_ioctl_giwessid(struct net_device *dev,
1308 struct iw_request_info *info,
1309 struct iw_point *data, char *essid)
1311 PRTMP_ADAPTER pAdapter = NULL;
1313 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1316 if (MONITOR_ON(pAdapter))
1322 if (OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED))
1324 DBGPRINT(RT_DEBUG_TRACE ,("MediaState is connected\n"));
1325 data->length = pAdapter->CommonCfg.SsidLen;
1326 memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
1330 else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
1332 data->length = pAdapter->CommonCfg.SsidLen;
1333 memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
1335 #endif // RTMP_MAC_USB //
1337 {//the ANY ssid was specified
1339 DBGPRINT(RT_DEBUG_TRACE ,("MediaState is not connected, ess\n"));
1346 int rt_ioctl_siwnickn(struct net_device *dev,
1347 struct iw_request_info *info,
1348 struct iw_point *data, char *nickname)
1350 PRTMP_ADAPTER pAdapter = NULL;
1352 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1354 //check if the interface is down
1355 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1357 DBGPRINT(RT_DEBUG_TRACE ,("INFO::Network is down!\n"));
1361 if (data->length > IW_ESSID_MAX_SIZE)
1364 memset(pAdapter->nickname, 0, IW_ESSID_MAX_SIZE + 1);
1365 memcpy(pAdapter->nickname, nickname, data->length);
1371 int rt_ioctl_giwnickn(struct net_device *dev,
1372 struct iw_request_info *info,
1373 struct iw_point *data, char *nickname)
1375 PRTMP_ADAPTER pAdapter = NULL;
1377 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1379 if (data->length > strlen((PSTRING) pAdapter->nickname) + 1)
1380 data->length = strlen((PSTRING) pAdapter->nickname) + 1;
1381 if (data->length > 0) {
1382 memcpy(nickname, pAdapter->nickname, data->length-1);
1383 nickname[data->length-1] = '\0';
1388 int rt_ioctl_siwrts(struct net_device *dev,
1389 struct iw_request_info *info,
1390 struct iw_param *rts, char *extra)
1392 PRTMP_ADAPTER pAdapter = NULL;
1395 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1397 //check if the interface is down
1398 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1400 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1405 val = MAX_RTS_THRESHOLD;
1406 else if (rts->value < 0 || rts->value > MAX_RTS_THRESHOLD)
1408 else if (rts->value == 0)
1409 val = MAX_RTS_THRESHOLD;
1413 if (val != pAdapter->CommonCfg.RtsThreshold)
1414 pAdapter->CommonCfg.RtsThreshold = val;
1419 int rt_ioctl_giwrts(struct net_device *dev,
1420 struct iw_request_info *info,
1421 struct iw_param *rts, char *extra)
1423 PRTMP_ADAPTER pAdapter = NULL;
1425 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1427 //check if the interface is down
1428 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1430 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1434 rts->value = pAdapter->CommonCfg.RtsThreshold;
1435 rts->disabled = (rts->value == MAX_RTS_THRESHOLD);
1441 int rt_ioctl_siwfrag(struct net_device *dev,
1442 struct iw_request_info *info,
1443 struct iw_param *frag, char *extra)
1445 PRTMP_ADAPTER pAdapter = NULL;
1448 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1450 //check if the interface is down
1451 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1453 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1458 val = MAX_FRAG_THRESHOLD;
1459 else if (frag->value >= MIN_FRAG_THRESHOLD && frag->value <= MAX_FRAG_THRESHOLD)
1460 val = __cpu_to_le16(frag->value & ~0x1); /* even numbers only */
1461 else if (frag->value == 0)
1462 val = MAX_FRAG_THRESHOLD;
1466 pAdapter->CommonCfg.FragmentThreshold = val;
1470 int rt_ioctl_giwfrag(struct net_device *dev,
1471 struct iw_request_info *info,
1472 struct iw_param *frag, char *extra)
1474 PRTMP_ADAPTER pAdapter = NULL;
1476 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1478 //check if the interface is down
1479 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1481 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1485 frag->value = pAdapter->CommonCfg.FragmentThreshold;
1486 frag->disabled = (frag->value == MAX_FRAG_THRESHOLD);
1492 #define MAX_WEP_KEY_SIZE 13
1493 #define MIN_WEP_KEY_SIZE 5
1494 int rt_ioctl_siwencode(struct net_device *dev,
1495 struct iw_request_info *info,
1496 struct iw_point *erq, char *extra)
1498 PRTMP_ADAPTER pAdapter = NULL;
1500 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1502 //check if the interface is down
1503 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1505 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1509 if ((erq->length == 0) &&
1510 (erq->flags & IW_ENCODE_DISABLED))
1512 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
1513 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
1514 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
1515 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
1516 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1519 else if (erq->flags & IW_ENCODE_RESTRICTED || erq->flags & IW_ENCODE_OPEN)
1521 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
1522 STA_PORT_SECURED(pAdapter);
1523 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
1524 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
1525 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
1526 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
1527 if (erq->flags & IW_ENCODE_RESTRICTED)
1528 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
1530 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1533 if (erq->length > 0)
1535 int keyIdx = (erq->flags & IW_ENCODE_INDEX) - 1;
1536 /* Check the size of the key */
1537 if (erq->length > MAX_WEP_KEY_SIZE)
1541 /* Check key index */
1542 if ((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
1544 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::Wrong keyIdx=%d! Using default key instead (%d)\n",
1545 keyIdx, pAdapter->StaCfg.DefaultKeyId));
1548 keyIdx = pAdapter->StaCfg.DefaultKeyId;
1551 pAdapter->StaCfg.DefaultKeyId = keyIdx;
1553 NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
1555 if (erq->length == MAX_WEP_KEY_SIZE)
1557 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
1558 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
1560 else if (erq->length == MIN_WEP_KEY_SIZE)
1562 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
1563 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
1566 /* Disable the key */
1567 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
1569 /* Check if the key is not marked as invalid */
1570 if(!(erq->flags & IW_ENCODE_NOKEY))
1572 /* Copy the key in the driver */
1573 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, extra, erq->length);
1578 /* Do we want to just set the transmit key index ? */
1579 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
1580 if ((index >= 0) && (index < 4))
1582 pAdapter->StaCfg.DefaultKeyId = index;
1585 /* Don't complain if only change the mode */
1586 if (!(erq->flags & IW_ENCODE_MODE))
1591 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::erq->flags=%x\n",erq->flags));
1592 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::AuthMode=%x\n",pAdapter->StaCfg.AuthMode));
1593 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::DefaultKeyId=%x, KeyLen = %d\n",pAdapter->StaCfg.DefaultKeyId , pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen));
1594 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::WepStatus=%x\n",pAdapter->StaCfg.WepStatus));
1599 rt_ioctl_giwencode(struct net_device *dev,
1600 struct iw_request_info *info,
1601 struct iw_point *erq, char *key)
1604 PRTMP_ADAPTER pAdapter = NULL;
1606 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1608 //check if the interface is down
1609 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1611 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1615 kid = erq->flags & IW_ENCODE_INDEX;
1616 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_giwencode %d\n", erq->flags & IW_ENCODE_INDEX));
1618 if (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled)
1621 erq->flags = IW_ENCODE_DISABLED;
1623 else if ((kid > 0) && (kid <=4))
1626 erq->flags = kid ; /* NB: base 1 */
1627 if (erq->length > pAdapter->SharedKey[BSS0][kid-1].KeyLen)
1628 erq->length = pAdapter->SharedKey[BSS0][kid-1].KeyLen;
1629 memcpy(key, pAdapter->SharedKey[BSS0][kid-1].Key, erq->length);
1630 //if ((kid == pAdapter->PortCfg.DefaultKeyId))
1631 //erq->flags |= IW_ENCODE_ENABLED; /* XXX */
1632 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1633 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1635 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1640 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1641 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1643 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1644 erq->length = pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen;
1645 memcpy(key, pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key, erq->length);
1646 // copy default key ID
1647 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1648 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1650 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1651 erq->flags = pAdapter->StaCfg.DefaultKeyId + 1; /* NB: base 1 */
1652 erq->flags |= IW_ENCODE_ENABLED; /* XXX */
1660 rt_ioctl_setparam(struct net_device *dev, struct iw_request_info *info,
1661 void *w, char *extra)
1663 PRTMP_ADAPTER pAdapter;
1665 PSTRING this_char = extra;
1669 GET_PAD_FROM_NET_DEV(pAdapter, dev);
1671 pObj = (POS_COOKIE) pAdapter->OS_Cookie;
1673 pObj->ioctl_if_type = INT_MAIN;
1674 pObj->ioctl_if = MAIN_MBSSID;
1677 //check if the interface is down
1678 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1680 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1687 if ((value = rtstrchr(this_char, '=')) != NULL)
1690 if (!value && (strcmp(this_char, "SiteSurvey") != 0))
1695 // reject setting nothing besides ANY ssid(ssidLen=0)
1696 if (!*value && (strcmp(this_char, "SSID") != 0))
1700 for (PRTMP_PRIVATE_SET_PROC = RTMP_PRIVATE_SUPPORT_PROC; PRTMP_PRIVATE_SET_PROC->name; PRTMP_PRIVATE_SET_PROC++)
1702 if (strcmp(this_char, PRTMP_PRIVATE_SET_PROC->name) == 0)
1704 if(!PRTMP_PRIVATE_SET_PROC->set_proc(pAdapter, value))
1705 { //FALSE:Set private failed then return Invalid argument
1708 break; //Exit for loop.
1712 if(PRTMP_PRIVATE_SET_PROC->name == NULL)
1713 { //Not found argument
1715 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_setparam:: (iwpriv) Not Support Set Command [%s=%s]\n", this_char, value));
1723 rt_private_get_statistics(struct net_device *dev, struct iw_request_info *info,
1724 struct iw_point *wrq, char *extra)
1727 PRTMP_ADAPTER pAd = NULL;
1729 GET_PAD_FROM_NET_DEV(pAd, dev);
1737 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
1738 sprintf(extra, "\n\n");
1741 sprintf(extra+strlen(extra), "Tx success = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart);
1742 sprintf(extra+strlen(extra), "Tx success without retry = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart - (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
1744 sprintf(extra+strlen(extra), "Tx success after retry = %ld\n", (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
1745 sprintf(extra+strlen(extra), "Tx fail to Rcv ACK after retry = %ld\n", (ULONG)pAd->WlanCounters.FailedCount.QuadPart);
1746 sprintf(extra+strlen(extra), "RTS Success Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSSuccessCount.QuadPart);
1747 sprintf(extra+strlen(extra), "RTS Fail Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSFailureCount.QuadPart);
1749 sprintf(extra+strlen(extra), "Rx success = %ld\n", (ULONG)pAd->WlanCounters.ReceivedFragmentCount.QuadPart);
1750 sprintf(extra+strlen(extra), "Rx with CRC = %ld\n", (ULONG)pAd->WlanCounters.FCSErrorCount.QuadPart);
1751 sprintf(extra+strlen(extra), "Rx drop due to out of resource = %ld\n", (ULONG)pAd->Counters8023.RxNoBuffer);
1752 sprintf(extra+strlen(extra), "Rx duplicate frame = %ld\n", (ULONG)pAd->WlanCounters.FrameDuplicateCount.QuadPart);
1754 sprintf(extra+strlen(extra), "False CCA (one second) = %ld\n", (ULONG)pAd->RalinkCounters.OneSecFalseCCACnt);
1756 sprintf(extra+strlen(extra), "RSSI-A = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi0 - pAd->BbpRssiToDbmDelta));
1757 sprintf(extra+strlen(extra), "RSSI-B (if available) = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi1 - pAd->BbpRssiToDbmDelta));
1758 sprintf(extra+strlen(extra), "RSSI-C (if available) = %ld\n\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi2 - pAd->BbpRssiToDbmDelta));
1760 sprintf(extra+strlen(extra), "WpaSupplicantUP = %d\n\n", pAd->StaCfg.WpaSupplicantUP);
1764 wrq->length = strlen(extra) + 1; // 1: size of '\0'
1765 DBGPRINT(RT_DEBUG_TRACE, ("<== rt_private_get_statistics, wrq->length = %d\n", wrq->length));
1771 IN PRTMP_ADAPTER pAd,
1775 BA_ORI_ENTRY *pOriBAEntry;
1776 BA_REC_ENTRY *pRecBAEntry;
1778 for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
1780 PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
1781 if (((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
1782 || (pEntry->ValidAsWDS) || (pEntry->ValidAsMesh))
1784 sprintf(pOutBuf + strlen(pOutBuf), "\n%02X:%02X:%02X:%02X:%02X:%02X (Aid = %d) (AP) -\n",
1785 pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
1786 pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5], pEntry->Aid);
1788 sprintf(pOutBuf, "%s[Recipient]\n", pOutBuf);
1789 for (j=0; j < NUM_OF_TID; j++)
1791 if (pEntry->BARecWcidArray[j] != 0)
1793 pRecBAEntry =&pAd->BATable.BARecEntry[pEntry->BARecWcidArray[j]];
1794 sprintf(pOutBuf + strlen(pOutBuf), "TID=%d, BAWinSize=%d, LastIndSeq=%d, ReorderingPkts=%d\n", j, pRecBAEntry->BAWinSize, pRecBAEntry->LastIndSeq, pRecBAEntry->list.qlen);
1797 sprintf(pOutBuf, "%s\n", pOutBuf);
1799 sprintf(pOutBuf, "%s[Originator]\n", pOutBuf);
1800 for (j=0; j < NUM_OF_TID; j++)
1802 if (pEntry->BAOriWcidArray[j] != 0)
1804 pOriBAEntry =&pAd->BATable.BAOriEntry[pEntry->BAOriWcidArray[j]];
1805 sprintf(pOutBuf + strlen(pOutBuf), "TID=%d, BAWinSize=%d, StartSeq=%d, CurTxSeq=%d\n", j, pOriBAEntry->BAWinSize, pOriBAEntry->Sequence, pEntry->TxSeq[j]);
1808 sprintf(pOutBuf, "%s\n\n", pOutBuf);
1810 if (strlen(pOutBuf) > (IW_PRIV_SIZE_MASK - 30))
1818 rt_private_show(struct net_device *dev, struct iw_request_info *info,
1819 struct iw_point *wrq, PSTRING extra)
1824 u32 subcmd = wrq->flags;
1826 GET_PAD_FROM_NET_DEV(pAd, dev);
1828 pObj = (POS_COOKIE) pAd->OS_Cookie;
1834 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
1837 pObj->ioctl_if_type = INT_MAIN;
1838 pObj->ioctl_if = MAIN_MBSSID;
1844 case SHOW_CONN_STATUS:
1845 if (MONITOR_ON(pAd))
1847 if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
1848 pAd->CommonCfg.RegTransmitSetting.field.BW)
1849 sprintf(extra, "Monitor Mode(CentralChannel %d)\n", pAd->CommonCfg.CentralChannel);
1851 sprintf(extra, "Monitor Mode(Channel %d)\n", pAd->CommonCfg.Channel);
1855 if (pAd->IndicateMediaState == NdisMediaStateConnected)
1859 sprintf(extra, "Connected(AP: %s[%02X:%02X:%02X:%02X:%02X:%02X])\n",
1860 pAd->CommonCfg.Ssid,
1861 pAd->CommonCfg.Bssid[0],
1862 pAd->CommonCfg.Bssid[1],
1863 pAd->CommonCfg.Bssid[2],
1864 pAd->CommonCfg.Bssid[3],
1865 pAd->CommonCfg.Bssid[4],
1866 pAd->CommonCfg.Bssid[5]);
1867 DBGPRINT(RT_DEBUG_TRACE ,("Ssid=%s ,Ssidlen = %d\n",pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen));
1869 else if (ADHOC_ON(pAd))
1870 sprintf(extra, "Connected\n");
1874 sprintf(extra, "Disconnected\n");
1875 DBGPRINT(RT_DEBUG_TRACE ,("ConnStatus is not connected\n"));
1878 wrq->length = strlen(extra) + 1; // 1: size of '\0'
1880 case SHOW_DRVIER_VERION:
1881 sprintf(extra, "Driver version-%s, %s %s\n", STA_DRIVER_VERSION, __DATE__, __TIME__ );
1882 wrq->length = strlen(extra) + 1; // 1: size of '\0'
1885 getBaInfo(pAd, extra);
1886 wrq->length = strlen(extra) + 1; // 1: size of '\0'
1888 case SHOW_DESC_INFO:
1890 Show_DescInfo_Proc(pAd, NULL);
1891 wrq->length = 0; // 1: size of '\0'
1895 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
1897 if (pAd->Mlme.CntlMachine.CurrState != CNTL_IDLE)
1899 RTMP_MLME_RESET_STATE_MACHINE(pAd);
1900 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
1903 pAd->StaCfg.bSwRadio = FALSE;
1904 if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
1906 pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
1907 if (pAd->StaCfg.bRadio == FALSE)
1910 // Update extra information
1911 pAd->ExtraInfo = SW_RADIO_OFF;
1914 sprintf(extra, "Radio Off\n");
1915 wrq->length = strlen(extra) + 1; // 1: size of '\0'
1918 pAd->StaCfg.bSwRadio = TRUE;
1919 //if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
1921 pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
1922 if (pAd->StaCfg.bRadio == TRUE)
1925 // Update extra information
1926 pAd->ExtraInfo = EXTRA_INFO_CLEAR;
1929 sprintf(extra, "Radio On\n");
1930 wrq->length = strlen(extra) + 1; // 1: size of '\0'
1935 case SHOW_CFG_VALUE:
1937 Status = RTMPShowCfgValue(pAd, (PSTRING) wrq->pointer, extra);
1939 wrq->length = strlen(extra) + 1; // 1: size of '\0'
1942 case SHOW_ADHOC_ENTRY_INFO:
1943 Show_Adhoc_MacTable_Proc(pAd, extra);
1944 wrq->length = strlen(extra) + 1; // 1: size of '\0'
1947 DBGPRINT(RT_DEBUG_TRACE, ("%s - unknow subcmd = %d\n", __func__, subcmd));
1954 int rt_ioctl_siwmlme(struct net_device *dev,
1955 struct iw_request_info *info,
1956 union iwreq_data *wrqu,
1959 PRTMP_ADAPTER pAd = NULL;
1960 struct iw_mlme *pMlme = (struct iw_mlme *)wrqu->data.pointer;
1961 MLME_QUEUE_ELEM MsgElem;
1962 MLME_DISASSOC_REQ_STRUCT DisAssocReq;
1963 MLME_DEAUTH_REQ_STRUCT DeAuthReq;
1965 GET_PAD_FROM_NET_DEV(pAd, dev);
1967 DBGPRINT(RT_DEBUG_TRACE, ("====> %s\n", __func__));
1974 #ifdef IW_MLME_DEAUTH
1975 case IW_MLME_DEAUTH:
1976 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DEAUTH\n", __func__));
1977 COPY_MAC_ADDR(DeAuthReq.Addr, pAd->CommonCfg.Bssid);
1978 DeAuthReq.Reason = pMlme->reason_code;
1979 MsgElem.MsgLen = sizeof(MLME_DEAUTH_REQ_STRUCT);
1980 NdisMoveMemory(MsgElem.Msg, &DeAuthReq, sizeof(MLME_DEAUTH_REQ_STRUCT));
1981 MlmeDeauthReqAction(pAd, &MsgElem);
1984 LinkDown(pAd, FALSE);
1985 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
1988 #endif // IW_MLME_DEAUTH //
1989 #ifdef IW_MLME_DISASSOC
1990 case IW_MLME_DISASSOC:
1991 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DISASSOC\n", __func__));
1992 COPY_MAC_ADDR(DisAssocReq.Addr, pAd->CommonCfg.Bssid);
1993 DisAssocReq.Reason = pMlme->reason_code;
1995 MsgElem.Machine = ASSOC_STATE_MACHINE;
1996 MsgElem.MsgType = MT2_MLME_DISASSOC_REQ;
1997 MsgElem.MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
1998 NdisMoveMemory(MsgElem.Msg, &DisAssocReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
2000 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
2001 MlmeDisassocReqAction(pAd, &MsgElem);
2003 #endif // IW_MLME_DISASSOC //
2005 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - Unknow Command\n", __func__));
2012 int rt_ioctl_siwauth(struct net_device *dev,
2013 struct iw_request_info *info,
2014 union iwreq_data *wrqu, char *extra)
2016 PRTMP_ADAPTER pAdapter = NULL;
2017 struct iw_param *param = &wrqu->param;
2019 GET_PAD_FROM_NET_DEV(pAdapter, dev);
2021 //check if the interface is down
2022 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2024 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2027 switch (param->flags & IW_AUTH_INDEX) {
2028 case IW_AUTH_WPA_VERSION:
2029 if (param->value == IW_AUTH_WPA_VERSION_WPA)
2031 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
2032 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
2033 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
2035 else if (param->value == IW_AUTH_WPA_VERSION_WPA2)
2036 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
2038 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __func__, param->value));
2040 case IW_AUTH_CIPHER_PAIRWISE:
2041 if (param->value == IW_AUTH_CIPHER_NONE)
2043 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
2044 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2045 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
2047 else if (param->value == IW_AUTH_CIPHER_WEP40 ||
2048 param->value == IW_AUTH_CIPHER_WEP104)
2050 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
2051 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2052 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
2053 pAdapter->StaCfg.IEEE8021X = FALSE;
2055 else if (param->value == IW_AUTH_CIPHER_TKIP)
2057 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
2058 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2059 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
2061 else if (param->value == IW_AUTH_CIPHER_CCMP)
2063 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
2064 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2065 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
2067 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_PAIRWISE - param->value = %d!\n", __func__, param->value));
2069 case IW_AUTH_CIPHER_GROUP:
2070 if (param->value == IW_AUTH_CIPHER_NONE)
2072 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
2074 else if (param->value == IW_AUTH_CIPHER_WEP40 ||
2075 param->value == IW_AUTH_CIPHER_WEP104)
2077 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
2079 else if (param->value == IW_AUTH_CIPHER_TKIP)
2081 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
2083 else if (param->value == IW_AUTH_CIPHER_CCMP)
2085 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
2087 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_GROUP - param->value = %d!\n", __func__, param->value));
2089 case IW_AUTH_KEY_MGMT:
2090 if (param->value == IW_AUTH_KEY_MGMT_802_1X)
2092 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)
2094 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
2095 pAdapter->StaCfg.IEEE8021X = FALSE;
2097 else if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
2099 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
2100 pAdapter->StaCfg.IEEE8021X = FALSE;
2104 pAdapter->StaCfg.IEEE8021X = TRUE;
2106 else if (param->value == 0)
2108 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2109 STA_PORT_SECURED(pAdapter);
2111 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_KEY_MGMT - param->value = %d!\n", __func__, param->value));
2113 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
2115 case IW_AUTH_PRIVACY_INVOKED:
2116 /*if (param->value == 0)
2118 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
2119 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
2120 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2121 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
2122 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
2124 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_PRIVACY_INVOKED - param->value = %d!\n", __func__, param->value));
2126 case IW_AUTH_DROP_UNENCRYPTED:
2127 if (param->value != 0)
2128 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
2131 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2132 STA_PORT_SECURED(pAdapter);
2134 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __func__, param->value));
2136 case IW_AUTH_80211_AUTH_ALG:
2137 if (param->value & IW_AUTH_ALG_SHARED_KEY)
2139 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
2141 else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
2143 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
2147 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_80211_AUTH_ALG - param->value = %d!\n", __func__, param->value));
2149 case IW_AUTH_WPA_ENABLED:
2150 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_ENABLED - Driver supports WPA!(param->value = %d)\n", __func__, param->value));
2159 int rt_ioctl_giwauth(struct net_device *dev,
2160 struct iw_request_info *info,
2161 union iwreq_data *wrqu, char *extra)
2163 PRTMP_ADAPTER pAdapter = NULL;
2164 struct iw_param *param = &wrqu->param;
2166 GET_PAD_FROM_NET_DEV(pAdapter, dev);
2168 //check if the interface is down
2169 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2171 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2175 switch (param->flags & IW_AUTH_INDEX) {
2176 case IW_AUTH_DROP_UNENCRYPTED:
2177 param->value = (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled) ? 0 : 1;
2180 case IW_AUTH_80211_AUTH_ALG:
2181 param->value = (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared) ? IW_AUTH_ALG_SHARED_KEY : IW_AUTH_ALG_OPEN_SYSTEM;
2184 case IW_AUTH_WPA_ENABLED:
2185 param->value = (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) ? 1 : 0;
2191 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_giwauth::param->value = %d!\n", param->value));
2195 void fnSetCipherKey(
2196 IN PRTMP_ADAPTER pAdapter,
2200 IN struct iw_encode_ext *ext)
2202 NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
2203 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = LEN_TKIP_EK;
2204 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, LEN_TKIP_EK);
2205 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].TxMic, ext->key + LEN_TKIP_EK, LEN_TKIP_TXMICK);
2206 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].RxMic, ext->key + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
2207 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CipherAlg;
2209 // Update group key information to ASIC Shared Key Table
2210 AsicAddSharedKeyEntry(pAdapter,
2213 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2214 pAdapter->SharedKey[BSS0][keyIdx].Key,
2215 pAdapter->SharedKey[BSS0][keyIdx].TxMic,
2216 pAdapter->SharedKey[BSS0][keyIdx].RxMic);
2219 // Update ASIC WCID attribute table and IVEIV table
2220 RTMPAddWcidAttributeEntry(pAdapter,
2223 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2226 // Update ASIC WCID attribute table and IVEIV table
2227 RTMPAddWcidAttributeEntry(pAdapter,
2230 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2231 &pAdapter->MacTab.Content[BSSID_WCID]);
2234 int rt_ioctl_siwencodeext(struct net_device *dev,
2235 struct iw_request_info *info,
2236 union iwreq_data *wrqu,
2239 PRTMP_ADAPTER pAdapter = NULL;
2240 struct iw_point *encoding = &wrqu->encoding;
2241 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2242 int keyIdx, alg = ext->alg;
2244 GET_PAD_FROM_NET_DEV(pAdapter, dev);
2246 //check if the interface is down
2247 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2249 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2253 if (encoding->flags & IW_ENCODE_DISABLED)
2255 keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
2256 // set BSSID wcid entry of the Pair-wise Key table as no-security mode
2257 AsicRemovePairwiseKeyEntry(pAdapter, BSS0, BSSID_WCID);
2258 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
2259 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_NONE;
2260 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)keyIdx);
2261 NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
2262 DBGPRINT(RT_DEBUG_TRACE, ("%s::Remove all keys!(encoding->flags = %x)\n", __func__, encoding->flags));
2266 // Get Key Index and convet to our own defined key index
2267 keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
2268 if((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
2271 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2273 pAdapter->StaCfg.DefaultKeyId = keyIdx;
2274 DBGPRINT(RT_DEBUG_TRACE, ("%s::DefaultKeyId = %d\n", __func__, pAdapter->StaCfg.DefaultKeyId));
2278 case IW_ENCODE_ALG_NONE:
2279 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_NONE\n", __func__));
2281 case IW_ENCODE_ALG_WEP:
2282 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_WEP - ext->key_len = %d, keyIdx = %d\n", __func__, ext->key_len, keyIdx));
2283 if (ext->key_len == MAX_WEP_KEY_SIZE)
2285 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
2286 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
2288 else if (ext->key_len == MIN_WEP_KEY_SIZE)
2290 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
2291 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
2296 NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
2297 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, ext->key_len);
2298 if (pAdapter->StaCfg.GroupCipher == Ndis802_11GroupWEP40Enabled ||
2299 pAdapter->StaCfg.GroupCipher == Ndis802_11GroupWEP104Enabled)
2301 // Set Group key material to Asic
2302 AsicAddSharedKeyEntry(pAdapter, BSS0, keyIdx, pAdapter->SharedKey[BSS0][keyIdx].CipherAlg, pAdapter->SharedKey[BSS0][keyIdx].Key, NULL, NULL);
2304 // Update WCID attribute table and IVEIV table for this group key table
2305 RTMPAddWcidAttributeEntry(pAdapter, BSS0, keyIdx, pAdapter->SharedKey[BSS0][keyIdx].CipherAlg, NULL);
2307 STA_PORT_SECURED(pAdapter);
2309 // Indicate Connected for GUI
2310 pAdapter->IndicateMediaState = NdisMediaStateConnected;
2313 case IW_ENCODE_ALG_TKIP:
2314 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_TKIP - keyIdx = %d, ext->key_len = %d\n", __func__, keyIdx, ext->key_len));
2315 if (ext->key_len == 32)
2317 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2319 fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, FALSE, ext);
2320 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
2322 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2323 STA_PORT_SECURED(pAdapter);
2324 pAdapter->IndicateMediaState = NdisMediaStateConnected;
2327 else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
2329 fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, TRUE, ext);
2331 // set 802.1x port control
2332 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2333 STA_PORT_SECURED(pAdapter);
2334 pAdapter->IndicateMediaState = NdisMediaStateConnected;
2340 case IW_ENCODE_ALG_CCMP:
2341 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2343 fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, FALSE, ext);
2344 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
2345 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2346 STA_PORT_SECURED(pAdapter);
2347 pAdapter->IndicateMediaState = NdisMediaStateConnected;
2349 else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
2351 fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, TRUE, ext);
2353 // set 802.1x port control
2354 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2355 STA_PORT_SECURED(pAdapter);
2356 pAdapter->IndicateMediaState = NdisMediaStateConnected;
2368 rt_ioctl_giwencodeext(struct net_device *dev,
2369 struct iw_request_info *info,
2370 union iwreq_data *wrqu, char *extra)
2372 PRTMP_ADAPTER pAd = NULL;
2374 struct iw_point *encoding = &wrqu->encoding;
2375 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2376 int idx, max_key_len;
2378 GET_PAD_FROM_NET_DEV(pAd, dev);
2380 DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_giwencodeext\n"));
2382 max_key_len = encoding->length - sizeof(*ext);
2383 if (max_key_len < 0)
2386 idx = encoding->flags & IW_ENCODE_INDEX;
2389 if (idx < 1 || idx > 4)
2393 if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
2394 (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled))
2396 if (idx != pAd->StaCfg.DefaultKeyId)
2404 idx = pAd->StaCfg.DefaultKeyId;
2406 encoding->flags = idx + 1;
2407 memset(ext, 0, sizeof(*ext));
2410 switch(pAd->StaCfg.WepStatus) {
2411 case Ndis802_11WEPDisabled:
2412 ext->alg = IW_ENCODE_ALG_NONE;
2413 encoding->flags |= IW_ENCODE_DISABLED;
2415 case Ndis802_11WEPEnabled:
2416 ext->alg = IW_ENCODE_ALG_WEP;
2417 if (pAd->SharedKey[BSS0][idx].KeyLen > max_key_len)
2421 ext->key_len = pAd->SharedKey[BSS0][idx].KeyLen;
2422 pKey = (PCHAR)&(pAd->SharedKey[BSS0][idx].Key[0]);
2425 case Ndis802_11Encryption2Enabled:
2426 case Ndis802_11Encryption3Enabled:
2427 if (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
2428 ext->alg = IW_ENCODE_ALG_TKIP;
2430 ext->alg = IW_ENCODE_ALG_CCMP;
2432 if (max_key_len < 32)
2437 pKey = (PCHAR)&pAd->StaCfg.PMK[0];
2444 if (ext->key_len && pKey)
2446 encoding->flags |= IW_ENCODE_ENABLED;
2447 memcpy(ext->key, pKey, ext->key_len);
2453 int rt_ioctl_siwgenie(struct net_device *dev,
2454 struct iw_request_info *info,
2455 union iwreq_data *wrqu, char *extra)
2457 PRTMP_ADAPTER pAd = NULL;
2459 GET_PAD_FROM_NET_DEV(pAd, dev);
2461 DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_siwgenie\n"));
2462 pAd->StaCfg.bRSN_IE_FromWpaSupplicant = FALSE;
2463 if (wrqu->data.length > MAX_LEN_OF_RSNIE ||
2464 (wrqu->data.length && extra == NULL))
2467 if (wrqu->data.length)
2469 pAd->StaCfg.RSNIE_Len = wrqu->data.length;
2470 NdisMoveMemory(&pAd->StaCfg.RSN_IE[0], extra, pAd->StaCfg.RSNIE_Len);
2471 pAd->StaCfg.bRSN_IE_FromWpaSupplicant = TRUE;
2475 pAd->StaCfg.RSNIE_Len = 0;
2476 NdisZeroMemory(&pAd->StaCfg.RSN_IE[0], MAX_LEN_OF_RSNIE);
2482 int rt_ioctl_giwgenie(struct net_device *dev,
2483 struct iw_request_info *info,
2484 union iwreq_data *wrqu, char *extra)
2486 PRTMP_ADAPTER pAd = NULL;
2488 GET_PAD_FROM_NET_DEV(pAd, dev);
2490 if ((pAd->StaCfg.RSNIE_Len == 0) ||
2491 (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA))
2493 wrqu->data.length = 0;
2497 if (pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
2499 if (wrqu->data.length < pAd->StaCfg.RSNIE_Len)
2502 wrqu->data.length = pAd->StaCfg.RSNIE_Len;
2503 memcpy(extra, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
2507 UCHAR RSNIe = IE_WPA;
2509 if (wrqu->data.length < (pAd->StaCfg.RSNIE_Len + 2)) // ID, Len
2511 wrqu->data.length = pAd->StaCfg.RSNIE_Len + 2;
2513 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
2514 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2))
2517 extra[0] = (char)RSNIe;
2518 extra[1] = pAd->StaCfg.RSNIE_Len;
2519 memcpy(extra+2, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
2525 int rt_ioctl_siwpmksa(struct net_device *dev,
2526 struct iw_request_info *info,
2527 union iwreq_data *wrqu,
2530 PRTMP_ADAPTER pAd = NULL;
2531 struct iw_pmksa *pPmksa = (struct iw_pmksa *)wrqu->data.pointer;
2532 INT CachedIdx = 0, idx = 0;
2534 GET_PAD_FROM_NET_DEV(pAd, dev);
2539 DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_siwpmksa\n"));
2542 case IW_PMKSA_FLUSH:
2543 NdisZeroMemory(pAd->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
2544 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_FLUSH\n"));
2546 case IW_PMKSA_REMOVE:
2547 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
2549 // compare the BSSID
2550 if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
2552 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN);
2553 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].PMKID, 16);
2554 for (idx = CachedIdx; idx < (pAd->StaCfg.SavedPMKNum - 1); idx++)
2556 NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].BSSID[0], &pAd->StaCfg.SavedPMK[idx+1].BSSID[0], MAC_ADDR_LEN);
2557 NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].PMKID[0], &pAd->StaCfg.SavedPMK[idx+1].PMKID[0], 16);
2559 pAd->StaCfg.SavedPMKNum--;
2564 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_REMOVE\n"));
2567 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
2569 // compare the BSSID
2570 if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
2574 // Found, replace it
2575 if (CachedIdx < PMKID_NO)
2577 DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
2578 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
2579 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
2580 pAd->StaCfg.SavedPMKNum++;
2582 // Not found, replace the last one
2585 // Randomly replace one
2586 CachedIdx = (pPmksa->bssid.sa_data[5] % PMKID_NO);
2587 DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
2588 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
2589 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
2592 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_ADD\n"));
2595 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - Unknow Command!!\n"));
2602 int rt_ioctl_siwrate(struct net_device *dev,
2603 struct iw_request_info *info,
2604 union iwreq_data *wrqu, char *extra)
2606 PRTMP_ADAPTER pAd = NULL;
2607 UINT32 rate = wrqu->bitrate.value, fixed = wrqu->bitrate.fixed;
2609 GET_PAD_FROM_NET_DEV(pAd, dev);
2611 //check if the interface is down
2612 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2614 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::Network is down!\n"));
2618 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(rate = %d, fixed = %d)\n", rate, fixed));
2619 /* rate = -1 => auto rate
2620 rate = X, fixed = 1 => (fixed rate X)
2625 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
2626 pAd->StaCfg.bAutoTxRateSwitch = TRUE;
2627 if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
2628 (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
2629 RTMPSetDesiredRates(pAd, -1);
2637 pAd->StaCfg.bAutoTxRateSwitch = FALSE;
2638 if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
2639 (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
2640 RTMPSetDesiredRates(pAd, rate);
2643 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
2646 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(HtMcs=%d)\n",pAd->StaCfg.DesiredTransmitSetting.field.MCS));
2650 // TODO: rate = X, fixed = 0 => (rates <= X)
2658 int rt_ioctl_giwrate(struct net_device *dev,
2659 struct iw_request_info *info,
2660 union iwreq_data *wrqu, char *extra)
2662 PRTMP_ADAPTER pAd = NULL;
2663 int rate_index = 0, rate_count = 0;
2664 HTTRANSMIT_SETTING ht_setting;
2665 /* Remove to global variable
2666 __s32 ralinkrate[] =
2667 {2, 4, 11, 22, // CCK
2668 12, 18, 24, 36, 48, 72, 96, 108, // OFDM
2669 13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260, // 20MHz, 800ns GI, MCS: 0 ~ 15
2670 39, 78, 117, 156, 234, 312, 351, 390, // 20MHz, 800ns GI, MCS: 16 ~ 23
2671 27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540, // 40MHz, 800ns GI, MCS: 0 ~ 15
2672 81, 162, 243, 324, 486, 648, 729, 810, // 40MHz, 800ns GI, MCS: 16 ~ 23
2673 14, 29, 43, 57, 87, 115, 130, 144, 29, 59, 87, 115, 173, 230, 260, 288, // 20MHz, 400ns GI, MCS: 0 ~ 15
2674 43, 87, 130, 173, 260, 317, 390, 433, // 20MHz, 400ns GI, MCS: 16 ~ 23
2675 30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600, // 40MHz, 400ns GI, MCS: 0 ~ 15
2676 90, 180, 270, 360, 540, 720, 810, 900}; // 40MHz, 400ns GI, MCS: 16 ~ 23
2678 GET_PAD_FROM_NET_DEV(pAd, dev);
2680 rate_count = sizeof(ralinkrate)/sizeof(__s32);
2681 //check if the interface is down
2682 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2684 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2688 if ((pAd->StaCfg.bAutoTxRateSwitch == FALSE) &&
2690 ((pAd->CommonCfg.PhyMode <= PHY_11G) || (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM)))
2691 ht_setting.word = pAd->StaCfg.HTPhyMode.word;
2693 ht_setting.word = pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word;
2695 if (ht_setting.field.MODE >= MODE_HTMIX)
2697 // rate_index = 12 + ((UCHAR)ht_setting.field.BW *16) + ((UCHAR)ht_setting.field.ShortGI *32) + ((UCHAR)ht_setting.field.MCS);
2698 rate_index = 12 + ((UCHAR)ht_setting.field.BW *24) + ((UCHAR)ht_setting.field.ShortGI *48) + ((UCHAR)ht_setting.field.MCS);
2701 if (ht_setting.field.MODE == MODE_OFDM)
2702 rate_index = (UCHAR)(ht_setting.field.MCS) + 4;
2703 else if (ht_setting.field.MODE == MODE_CCK)
2704 rate_index = (UCHAR)(ht_setting.field.MCS);
2709 if (rate_index > rate_count)
2710 rate_index = rate_count;
2712 wrqu->bitrate.value = ralinkrate[rate_index] * 500000;
2713 wrqu->bitrate.disabled = 0;
2718 static const iw_handler rt_handler[] =
2720 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2721 (iw_handler) rt_ioctl_giwname, /* SIOCGIWNAME */
2722 (iw_handler) NULL, /* SIOCSIWNWID */
2723 (iw_handler) NULL, /* SIOCGIWNWID */
2724 (iw_handler) rt_ioctl_siwfreq, /* SIOCSIWFREQ */
2725 (iw_handler) rt_ioctl_giwfreq, /* SIOCGIWFREQ */
2726 (iw_handler) rt_ioctl_siwmode, /* SIOCSIWMODE */
2727 (iw_handler) rt_ioctl_giwmode, /* SIOCGIWMODE */
2728 (iw_handler) NULL, /* SIOCSIWSENS */
2729 (iw_handler) NULL, /* SIOCGIWSENS */
2730 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
2731 (iw_handler) rt_ioctl_giwrange, /* SIOCGIWRANGE */
2732 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
2733 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
2734 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
2735 (iw_handler) rt28xx_get_wireless_stats /* kernel code */, /* SIOCGIWSTATS */
2736 (iw_handler) NULL, /* SIOCSIWSPY */
2737 (iw_handler) NULL, /* SIOCGIWSPY */
2738 (iw_handler) NULL, /* SIOCSIWTHRSPY */
2739 (iw_handler) NULL, /* SIOCGIWTHRSPY */
2740 (iw_handler) rt_ioctl_siwap, /* SIOCSIWAP */
2741 (iw_handler) rt_ioctl_giwap, /* SIOCGIWAP */
2742 (iw_handler) rt_ioctl_siwmlme, /* SIOCSIWMLME */
2743 (iw_handler) rt_ioctl_iwaplist, /* SIOCGIWAPLIST */
2744 (iw_handler) rt_ioctl_siwscan, /* SIOCSIWSCAN */
2745 (iw_handler) rt_ioctl_giwscan, /* SIOCGIWSCAN */
2746 (iw_handler) rt_ioctl_siwessid, /* SIOCSIWESSID */
2747 (iw_handler) rt_ioctl_giwessid, /* SIOCGIWESSID */
2748 (iw_handler) rt_ioctl_siwnickn, /* SIOCSIWNICKN */
2749 (iw_handler) rt_ioctl_giwnickn, /* SIOCGIWNICKN */
2750 (iw_handler) NULL, /* -- hole -- */
2751 (iw_handler) NULL, /* -- hole -- */
2752 (iw_handler) rt_ioctl_siwrate, /* SIOCSIWRATE */
2753 (iw_handler) rt_ioctl_giwrate, /* SIOCGIWRATE */
2754 (iw_handler) rt_ioctl_siwrts, /* SIOCSIWRTS */
2755 (iw_handler) rt_ioctl_giwrts, /* SIOCGIWRTS */
2756 (iw_handler) rt_ioctl_siwfrag, /* SIOCSIWFRAG */
2757 (iw_handler) rt_ioctl_giwfrag, /* SIOCGIWFRAG */
2758 (iw_handler) NULL, /* SIOCSIWTXPOW */
2759 (iw_handler) NULL, /* SIOCGIWTXPOW */
2760 (iw_handler) NULL, /* SIOCSIWRETRY */
2761 (iw_handler) NULL, /* SIOCGIWRETRY */
2762 (iw_handler) rt_ioctl_siwencode, /* SIOCSIWENCODE */
2763 (iw_handler) rt_ioctl_giwencode, /* SIOCGIWENCODE */
2764 (iw_handler) NULL, /* SIOCSIWPOWER */
2765 (iw_handler) NULL, /* SIOCGIWPOWER */
2766 (iw_handler) NULL, /* -- hole -- */
2767 (iw_handler) NULL, /* -- hole -- */
2768 (iw_handler) rt_ioctl_siwgenie, /* SIOCSIWGENIE */
2769 (iw_handler) rt_ioctl_giwgenie, /* SIOCGIWGENIE */
2770 (iw_handler) rt_ioctl_siwauth, /* SIOCSIWAUTH */
2771 (iw_handler) rt_ioctl_giwauth, /* SIOCGIWAUTH */
2772 (iw_handler) rt_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
2773 (iw_handler) rt_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */
2774 (iw_handler) rt_ioctl_siwpmksa, /* SIOCSIWPMKSA */
2777 static const iw_handler rt_priv_handlers[] = {
2778 (iw_handler) NULL, /* + 0x00 */
2779 (iw_handler) NULL, /* + 0x01 */
2780 (iw_handler) rt_ioctl_setparam, /* + 0x02 */
2781 (iw_handler) NULL, /* + 0x03 */
2782 (iw_handler) NULL, /* + 0x04 */
2783 (iw_handler) NULL, /* + 0x05 */
2784 (iw_handler) NULL, /* + 0x06 */
2785 (iw_handler) NULL, /* + 0x07 */
2786 (iw_handler) NULL, /* + 0x08 */
2787 (iw_handler) rt_private_get_statistics, /* + 0x09 */
2788 (iw_handler) NULL, /* + 0x0A */
2789 (iw_handler) NULL, /* + 0x0B */
2790 (iw_handler) NULL, /* + 0x0C */
2791 (iw_handler) NULL, /* + 0x0D */
2792 (iw_handler) NULL, /* + 0x0E */
2793 (iw_handler) NULL, /* + 0x0F */
2794 (iw_handler) NULL, /* + 0x10 */
2795 (iw_handler) rt_private_show, /* + 0x11 */
2796 (iw_handler) NULL, /* + 0x12 */
2797 (iw_handler) NULL, /* + 0x13 */
2798 (iw_handler) NULL, /* + 0x14 */
2799 (iw_handler) NULL, /* + 0x15 */
2800 (iw_handler) NULL, /* + 0x16 */
2801 (iw_handler) NULL, /* + 0x17 */
2802 (iw_handler) NULL, /* + 0x18 */
2805 const struct iw_handler_def rt28xx_iw_handler_def =
2807 #define N(a) (sizeof (a) / sizeof (a[0]))
2808 .standard = (iw_handler *) rt_handler,
2809 .num_standard = sizeof(rt_handler) / sizeof(iw_handler),
2810 .private = (iw_handler *) rt_priv_handlers,
2811 .num_private = N(rt_priv_handlers),
2812 .private_args = (struct iw_priv_args *) privtab,
2813 .num_private_args = N(privtab),
2814 #if IW_HANDLER_VERSION >= 7
2815 .get_wireless_stats = rt28xx_get_wireless_stats,
2819 INT rt28xx_sta_ioctl(
2820 IN struct net_device *net_dev,
2821 IN OUT struct ifreq *rq,
2825 RTMP_ADAPTER *pAd = NULL;
2826 struct iwreq *wrq = (struct iwreq *) rq;
2827 BOOLEAN StateMachineTouched = FALSE;
2828 INT Status = NDIS_STATUS_SUCCESS;
2830 GET_PAD_FROM_NET_DEV(pAd, net_dev);
2832 pObj = (POS_COOKIE) pAd->OS_Cookie;
2834 //check if the interface is down
2835 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2838 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2843 { // determine this ioctl command is comming from which interface.
2844 pObj->ioctl_if_type = INT_MAIN;
2845 pObj->ioctl_if = MAIN_MBSSID;
2851 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIFHWADDR\n"));
2852 memcpy(wrq->u.name, pAd->CurrentAddress, ETH_ALEN);
2856 char *name=&wrq->u.name[0];
2857 rt_ioctl_giwname(net_dev, NULL, name, NULL);
2860 case SIOCGIWESSID: //Get ESSID
2862 struct iw_point *essid=&wrq->u.essid;
2863 rt_ioctl_giwessid(net_dev, NULL, essid, essid->pointer);
2866 case SIOCSIWESSID: //Set ESSID
2868 struct iw_point *essid=&wrq->u.essid;
2869 rt_ioctl_siwessid(net_dev, NULL, essid, essid->pointer);
2872 case SIOCSIWNWID: // set network id (the cell)
2873 case SIOCGIWNWID: // get network id
2874 Status = -EOPNOTSUPP;
2876 case SIOCSIWFREQ: //set channel/frequency (Hz)
2878 struct iw_freq *freq=&wrq->u.freq;
2879 rt_ioctl_siwfreq(net_dev, NULL, freq, NULL);
2882 case SIOCGIWFREQ: // get channel/frequency (Hz)
2884 struct iw_freq *freq=&wrq->u.freq;
2885 rt_ioctl_giwfreq(net_dev, NULL, freq, NULL);
2888 case SIOCSIWNICKN: //set node name/nickname
2890 //struct iw_point *data=&wrq->u.data;
2891 //rt_ioctl_siwnickn(net_dev, NULL, data, NULL);
2894 case SIOCGIWNICKN: //get node name/nickname
2896 struct iw_point *erq = NULL;
2898 erq->length = strlen((PSTRING) pAd->nickname);
2899 Status = copy_to_user(erq->pointer, pAd->nickname, erq->length);
2902 case SIOCGIWRATE: //get default bit rate (bps)
2903 rt_ioctl_giwrate(net_dev, NULL, &wrq->u, NULL);
2905 case SIOCSIWRATE: //set default bit rate (bps)
2906 rt_ioctl_siwrate(net_dev, NULL, &wrq->u, NULL);
2908 case SIOCGIWRTS: // get RTS/CTS threshold (bytes)
2910 struct iw_param *rts=&wrq->u.rts;
2911 rt_ioctl_giwrts(net_dev, NULL, rts, NULL);
2914 case SIOCSIWRTS: //set RTS/CTS threshold (bytes)
2916 struct iw_param *rts=&wrq->u.rts;
2917 rt_ioctl_siwrts(net_dev, NULL, rts, NULL);
2920 case SIOCGIWFRAG: //get fragmentation thr (bytes)
2922 struct iw_param *frag=&wrq->u.frag;
2923 rt_ioctl_giwfrag(net_dev, NULL, frag, NULL);
2926 case SIOCSIWFRAG: //set fragmentation thr (bytes)
2928 struct iw_param *frag=&wrq->u.frag;
2929 rt_ioctl_siwfrag(net_dev, NULL, frag, NULL);
2932 case SIOCGIWENCODE: //get encoding token & mode
2934 struct iw_point *erq=&wrq->u.encoding;
2936 rt_ioctl_giwencode(net_dev, NULL, erq, erq->pointer);
2939 case SIOCSIWENCODE: //set encoding token & mode
2941 struct iw_point *erq=&wrq->u.encoding;
2943 rt_ioctl_siwencode(net_dev, NULL, erq, erq->pointer);
2946 case SIOCGIWAP: //get access point MAC addresses
2948 struct sockaddr *ap_addr=&wrq->u.ap_addr;
2949 rt_ioctl_giwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
2952 case SIOCSIWAP: //set access point MAC addresses
2954 struct sockaddr *ap_addr=&wrq->u.ap_addr;
2955 rt_ioctl_siwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
2958 case SIOCGIWMODE: //get operation mode
2960 __u32 *mode=&wrq->u.mode;
2961 rt_ioctl_giwmode(net_dev, NULL, mode, NULL);
2964 case SIOCSIWMODE: //set operation mode
2966 __u32 *mode=&wrq->u.mode;
2967 rt_ioctl_siwmode(net_dev, NULL, mode, NULL);
2970 case SIOCGIWSENS: //get sensitivity (dBm)
2971 case SIOCSIWSENS: //set sensitivity (dBm)
2972 case SIOCGIWPOWER: //get Power Management settings
2973 case SIOCSIWPOWER: //set Power Management settings
2974 case SIOCGIWTXPOW: //get transmit power (dBm)
2975 case SIOCSIWTXPOW: //set transmit power (dBm)
2976 case SIOCGIWRANGE: //Get range of parameters
2977 case SIOCGIWRETRY: //get retry limits and lifetime
2978 case SIOCSIWRETRY: //set retry limits and lifetime
2980 case RT_PRIV_IOCTL_EXT:
2981 case RTPRIV_IOCTL_SET:
2982 Status = -EOPNOTSUPP;
2985 if (wrq->u.data.pointer)
2987 if ( access_ok(VERIFY_WRITE, wrq->u.data.pointer, sizeof(privtab)) != TRUE)
2989 wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
2990 if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
2994 case RTPRIV_IOCTL_GSITESURVEY:
2995 RTMPIoctlGetSiteSurvey(pAd, wrq);
3000 DBGPRINT(RT_DEBUG_ERROR, ("IOCTL::unknown IOCTL's cmd = 0x%08x\n", cmd));
3001 Status = -EOPNOTSUPP;
3005 if(StateMachineTouched) // Upper layer sent a MLME-related operations
3006 RTMP_MLME_HANDLER(pAd);
3012 ==========================================================================
3016 TRUE if all parameters are OK, FALSE otherwise
3017 ==========================================================================
3020 IN PRTMP_ADAPTER pAdapter,
3023 NDIS_802_11_SSID Ssid, *pSsid=NULL;
3024 BOOLEAN StateMachineTouched = FALSE;
3027 if( strlen(arg) <= MAX_LEN_OF_SSID)
3029 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
3030 if (strlen(arg) != 0)
3032 NdisMoveMemory(Ssid.Ssid, arg, strlen(arg));
3033 Ssid.SsidLength = strlen(arg);
3037 Ssid.SsidLength = 0;
3038 memcpy(Ssid.Ssid, "", 0);
3039 pAdapter->StaCfg.BssType = BSS_INFRA;
3040 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
3041 pAdapter->StaCfg.WepStatus = Ndis802_11EncryptionDisabled;
3045 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3047 RTMP_MLME_RESET_STATE_MACHINE(pAdapter);
3048 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3051 if ((pAdapter->StaCfg.WpaPassPhraseLen >= 8) &&
3052 (pAdapter->StaCfg.WpaPassPhraseLen <= 64))
3054 STRING passphrase_str[65] = {0};
3055 UCHAR keyMaterial[40];
3057 RTMPMoveMemory(passphrase_str, pAdapter->StaCfg.WpaPassPhrase, pAdapter->StaCfg.WpaPassPhraseLen);
3058 RTMPZeroMemory(pAdapter->StaCfg.PMK, 32);
3059 if (pAdapter->StaCfg.WpaPassPhraseLen == 64)
3061 AtoH((PSTRING) pAdapter->StaCfg.WpaPassPhrase, pAdapter->StaCfg.PMK, 32);
3065 PasswordHash((PSTRING) pAdapter->StaCfg.WpaPassPhrase, Ssid.Ssid, Ssid.SsidLength, keyMaterial);
3066 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
3070 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
3071 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
3072 pAdapter->bConfigChanged = TRUE;
3074 MlmeEnqueue(pAdapter,
3075 MLME_CNTL_STATE_MACHINE,
3077 sizeof(NDIS_802_11_SSID),
3080 StateMachineTouched = TRUE;
3081 DBGPRINT(RT_DEBUG_TRACE, ("Set_SSID_Proc::(Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
3086 if (StateMachineTouched) // Upper layer sent a MLME-related operations
3087 RTMP_MLME_HANDLER(pAdapter);
3094 ==========================================================================
3096 Set WmmCapable Enable or Disable
3098 TRUE if all parameters are OK, FALSE otherwise
3099 ==========================================================================
3101 INT Set_WmmCapable_Proc(
3102 IN PRTMP_ADAPTER pAd,
3105 BOOLEAN bWmmCapable;
3107 bWmmCapable = simple_strtol(arg, 0, 10);
3109 if ((bWmmCapable == 1)
3111 && (pAd->NumberOfPipes >= 5)
3112 #endif // RTMP_MAC_USB //
3114 pAd->CommonCfg.bWmmCapable = TRUE;
3115 else if (bWmmCapable == 0)
3116 pAd->CommonCfg.bWmmCapable = FALSE;
3118 return FALSE; //Invalid argument
3120 DBGPRINT(RT_DEBUG_TRACE, ("Set_WmmCapable_Proc::(bWmmCapable=%d)\n",
3121 pAd->CommonCfg.bWmmCapable));
3125 #endif // WMM_SUPPORT //
3128 ==========================================================================
3130 Set Network Type(Infrastructure/Adhoc mode)
3132 TRUE if all parameters are OK, FALSE otherwise
3133 ==========================================================================
3135 INT Set_NetworkType_Proc(
3136 IN PRTMP_ADAPTER pAdapter,
3141 if (strcmp(arg, "Adhoc") == 0)
3143 if (pAdapter->StaCfg.BssType != BSS_ADHOC)
3145 // Config has changed
3146 pAdapter->bConfigChanged = TRUE;
3147 if (MONITOR_ON(pAdapter))
3149 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
3150 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
3152 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
3153 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
3154 pAdapter->StaCfg.bAutoReconnect = TRUE;
3155 LinkDown(pAdapter, FALSE);
3157 if (INFRA_ON(pAdapter))
3159 //BOOLEAN Cancelled;
3160 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
3161 // Since calling this indicate user don't want to connect to that SSID anymore.
3162 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
3163 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
3165 LinkDown(pAdapter, FALSE);
3167 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n"));
3170 pAdapter->StaCfg.BssType = BSS_ADHOC;
3171 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
3172 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(AD-HOC)\n"));
3174 else if (strcmp(arg, "Infra") == 0)
3176 if (pAdapter->StaCfg.BssType != BSS_INFRA)
3178 // Config has changed
3179 pAdapter->bConfigChanged = TRUE;
3180 if (MONITOR_ON(pAdapter))
3182 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
3183 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
3185 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
3186 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
3187 pAdapter->StaCfg.bAutoReconnect = TRUE;
3188 LinkDown(pAdapter, FALSE);
3190 if (ADHOC_ON(pAdapter))
3192 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
3193 // Since calling this indicate user don't want to connect to that SSID anymore.
3194 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
3195 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
3197 LinkDown(pAdapter, FALSE);
3200 pAdapter->StaCfg.BssType = BSS_INFRA;
3201 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
3202 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(INFRA)\n"));
3204 else if (strcmp(arg, "Monitor") == 0)
3207 BCN_TIME_CFG_STRUC csr;
3208 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_INFRA_ON);
3209 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_ADHOC_ON);
3210 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
3211 // disable all periodic state machine
3212 pAdapter->StaCfg.bAutoReconnect = FALSE;
3213 // reset all mlme state machine
3214 RTMP_MLME_RESET_STATE_MACHINE(pAdapter);
3215 DBGPRINT(RT_DEBUG_TRACE, ("fOP_STATUS_MEDIA_STATE_CONNECTED \n"));
3216 if (pAdapter->CommonCfg.CentralChannel == 0)
3218 if (pAdapter->CommonCfg.PhyMode == PHY_11AN_MIXED)
3219 pAdapter->CommonCfg.CentralChannel = 36;
3221 pAdapter->CommonCfg.CentralChannel = 6;
3224 N_ChannelCheck(pAdapter);
3226 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
3227 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
3228 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_ABOVE)
3230 // 40MHz ,control channel at lower
3231 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
3232 bbpValue &= (~0x18);
3234 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
3235 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
3236 // RX : control channel at lower
3237 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
3238 bbpValue &= (~0x20);
3239 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
3241 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
3242 Value &= 0xfffffffe;
3243 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
3244 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel + 2;
3245 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
3246 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
3247 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
3248 pAdapter->CommonCfg.Channel,
3249 pAdapter->CommonCfg.CentralChannel));
3251 else if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
3252 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
3253 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_BELOW)
3255 // 40MHz ,control channel at upper
3256 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
3257 bbpValue &= (~0x18);
3259 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
3260 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
3261 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
3263 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
3265 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
3267 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
3268 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel - 2;
3269 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
3270 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
3271 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
3272 pAdapter->CommonCfg.Channel,
3273 pAdapter->CommonCfg.CentralChannel));
3278 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
3279 bbpValue &= (~0x18);
3280 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
3281 pAdapter->CommonCfg.BBPCurrentBW = BW_20;
3282 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.Channel, FALSE);
3283 AsicLockChannel(pAdapter, pAdapter->CommonCfg.Channel);
3284 DBGPRINT(RT_DEBUG_TRACE, ("BW_20, Channel(%d)\n", pAdapter->CommonCfg.Channel));
3286 // Enable Rx with promiscuous reception
3287 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, 0x3);
3288 // ASIC supporsts sniffer function with replacing RSSI with timestamp.
3289 //RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
3291 //RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
3293 RTMP_IO_READ32(pAdapter, BCN_TIME_CFG, &csr.word);
3294 csr.field.bBeaconGen = 0;
3295 csr.field.bTBTTEnable = 0;
3296 csr.field.TsfSyncMode = 0;
3297 RTMP_IO_WRITE32(pAdapter, BCN_TIME_CFG, csr.word);
3299 pAdapter->StaCfg.BssType = BSS_MONITOR;
3300 pAdapter->net_dev->type = ARPHRD_IEEE80211_PRISM; //ARPHRD_IEEE80211; // IEEE80211
3301 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(MONITOR)\n"));
3304 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
3305 pAdapter->StaCfg.WpaState = SS_NOTUSE;
3307 DBGPRINT(RT_DEBUG_TRACE, ("Set_NetworkType_Proc::(NetworkType=%d)\n", pAdapter->StaCfg.BssType));
3313 ==========================================================================
3315 Set Authentication mode
3317 TRUE if all parameters are OK, FALSE otherwise
3318 ==========================================================================
3320 INT Set_AuthMode_Proc(
3321 IN PRTMP_ADAPTER pAdapter,
3324 if ((strcmp(arg, "WEPAUTO") == 0) || (strcmp(arg, "wepauto") == 0))
3325 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeAutoSwitch;
3326 else if ((strcmp(arg, "OPEN") == 0) || (strcmp(arg, "open") == 0))
3327 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
3328 else if ((strcmp(arg, "SHARED") == 0) || (strcmp(arg, "shared") == 0))
3329 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
3330 else if ((strcmp(arg, "WPAPSK") == 0) || (strcmp(arg, "wpapsk") == 0))
3331 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
3332 else if ((strcmp(arg, "WPANONE") == 0) || (strcmp(arg, "wpanone") == 0))
3333 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
3334 else if ((strcmp(arg, "WPA2PSK") == 0) || (strcmp(arg, "wpa2psk") == 0))
3335 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
3336 else if ((strcmp(arg, "WPA") == 0) || (strcmp(arg, "wpa") == 0))
3337 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
3338 else if ((strcmp(arg, "WPA2") == 0) || (strcmp(arg, "wpa2") == 0))
3339 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
3343 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
3345 DBGPRINT(RT_DEBUG_TRACE, ("Set_AuthMode_Proc::(AuthMode=%d)\n", pAdapter->StaCfg.AuthMode));
3351 ==========================================================================
3355 TRUE if all parameters are OK, FALSE otherwise
3356 ==========================================================================
3358 INT Set_EncrypType_Proc(
3359 IN PRTMP_ADAPTER pAdapter,
3362 if ((strcmp(arg, "NONE") == 0) || (strcmp(arg, "none") == 0))
3364 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3365 return TRUE; // do nothing
3367 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
3368 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
3369 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
3371 else if ((strcmp(arg, "WEP") == 0) || (strcmp(arg, "wep") == 0))
3373 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3374 return TRUE; // do nothing
3376 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
3377 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
3378 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
3380 else if ((strcmp(arg, "TKIP") == 0) || (strcmp(arg, "tkip") == 0))
3382 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
3383 return TRUE; // do nothing
3385 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
3386 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
3387 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
3389 else if ((strcmp(arg, "AES") == 0) || (strcmp(arg, "aes") == 0))
3391 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
3392 return TRUE; // do nothing
3394 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
3395 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
3396 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
3401 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
3403 DBGPRINT(RT_DEBUG_TRACE, ("Set_EncrypType_Proc::(EncrypType=%d)\n", pAdapter->StaCfg.WepStatus));
3409 ==========================================================================
3413 TRUE if all parameters are OK, FALSE otherwise
3414 ==========================================================================
3416 INT Set_DefaultKeyID_Proc(
3417 IN PRTMP_ADAPTER pAdapter,
3422 KeyIdx = simple_strtol(arg, 0, 10);
3423 if((KeyIdx >= 1 ) && (KeyIdx <= 4))
3424 pAdapter->StaCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1 );
3426 return FALSE; //Invalid argument
3428 DBGPRINT(RT_DEBUG_TRACE, ("Set_DefaultKeyID_Proc::(DefaultKeyID=%d)\n", pAdapter->StaCfg.DefaultKeyId));
3434 ==========================================================================
3438 TRUE if all parameters are OK, FALSE otherwise
3439 ==========================================================================
3442 IN PRTMP_ADAPTER pAdapter,
3447 UCHAR CipherAlg=CIPHER_WEP64;
3449 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3450 return TRUE; // do nothing
3452 KeyLen = strlen(arg);
3456 case 5: //wep 40 Ascii type
3457 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
3458 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
3459 CipherAlg = CIPHER_WEP64;
3460 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
3462 case 10: //wep 40 Hex type
3463 for(i=0; i < KeyLen; i++)
3465 if( !isxdigit(*(arg+i)) )
3466 return FALSE; //Not Hex value;
3468 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
3469 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
3470 CipherAlg = CIPHER_WEP64;
3471 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
3473 case 13: //wep 104 Ascii type
3474 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
3475 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
3476 CipherAlg = CIPHER_WEP128;
3477 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
3479 case 26: //wep 104 Hex type
3480 for(i=0; i < KeyLen; i++)
3482 if( !isxdigit(*(arg+i)) )
3483 return FALSE; //Not Hex value;
3485 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
3486 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
3487 CipherAlg = CIPHER_WEP128;
3488 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
3490 default: //Invalid argument
3491 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::Invalid argument (=%s)\n", arg));
3495 pAdapter->SharedKey[BSS0][0].CipherAlg = CipherAlg;
3497 // Set keys (into ASIC)
3498 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3500 else // Old WEP stuff
3502 AsicAddSharedKeyEntry(pAdapter,
3505 pAdapter->SharedKey[BSS0][0].CipherAlg,
3506 pAdapter->SharedKey[BSS0][0].Key,
3514 ==========================================================================
3519 TRUE if all parameters are OK, FALSE otherwise
3520 ==========================================================================
3523 IN PRTMP_ADAPTER pAdapter,
3528 UCHAR CipherAlg=CIPHER_WEP64;
3530 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3531 return TRUE; // do nothing
3533 KeyLen = strlen(arg);
3537 case 5: //wep 40 Ascii type
3538 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
3539 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
3540 CipherAlg = CIPHER_WEP64;
3541 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
3543 case 10: //wep 40 Hex type
3544 for(i=0; i < KeyLen; i++)
3546 if( !isxdigit(*(arg+i)) )
3547 return FALSE; //Not Hex value;
3549 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
3550 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
3551 CipherAlg = CIPHER_WEP64;
3552 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
3554 case 13: //wep 104 Ascii type
3555 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
3556 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
3557 CipherAlg = CIPHER_WEP128;
3558 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
3560 case 26: //wep 104 Hex type
3561 for(i=0; i < KeyLen; i++)
3563 if( !isxdigit(*(arg+i)) )
3564 return FALSE; //Not Hex value;
3566 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
3567 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
3568 CipherAlg = CIPHER_WEP128;
3569 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
3571 default: //Invalid argument
3572 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::Invalid argument (=%s)\n", arg));
3575 pAdapter->SharedKey[BSS0][1].CipherAlg = CipherAlg;
3577 // Set keys (into ASIC)
3578 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3580 else // Old WEP stuff
3582 AsicAddSharedKeyEntry(pAdapter,
3585 pAdapter->SharedKey[BSS0][1].CipherAlg,
3586 pAdapter->SharedKey[BSS0][1].Key,
3594 ==========================================================================
3598 TRUE if all parameters are OK, FALSE otherwise
3599 ==========================================================================
3602 IN PRTMP_ADAPTER pAdapter,
3607 UCHAR CipherAlg=CIPHER_WEP64;
3609 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3610 return TRUE; // do nothing
3612 KeyLen = strlen(arg);
3616 case 5: //wep 40 Ascii type
3617 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
3618 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
3619 CipherAlg = CIPHER_WEP64;
3620 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
3622 case 10: //wep 40 Hex type
3623 for(i=0; i < KeyLen; i++)
3625 if( !isxdigit(*(arg+i)) )
3626 return FALSE; //Not Hex value;
3628 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
3629 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
3630 CipherAlg = CIPHER_WEP64;
3631 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
3633 case 13: //wep 104 Ascii type
3634 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
3635 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
3636 CipherAlg = CIPHER_WEP128;
3637 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
3639 case 26: //wep 104 Hex type
3640 for(i=0; i < KeyLen; i++)
3642 if( !isxdigit(*(arg+i)) )
3643 return FALSE; //Not Hex value;
3645 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
3646 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
3647 CipherAlg = CIPHER_WEP128;
3648 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
3650 default: //Invalid argument
3651 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::Invalid argument (=%s)\n", arg));
3654 pAdapter->SharedKey[BSS0][2].CipherAlg = CipherAlg;
3656 // Set keys (into ASIC)
3657 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3659 else // Old WEP stuff
3661 AsicAddSharedKeyEntry(pAdapter,
3664 pAdapter->SharedKey[BSS0][2].CipherAlg,
3665 pAdapter->SharedKey[BSS0][2].Key,
3673 ==========================================================================
3677 TRUE if all parameters are OK, FALSE otherwise
3678 ==========================================================================
3681 IN PRTMP_ADAPTER pAdapter,
3686 UCHAR CipherAlg=CIPHER_WEP64;
3688 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3689 return TRUE; // do nothing
3691 KeyLen = strlen(arg);
3695 case 5: //wep 40 Ascii type
3696 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
3697 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
3698 CipherAlg = CIPHER_WEP64;
3699 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
3701 case 10: //wep 40 Hex type
3702 for(i=0; i < KeyLen; i++)
3704 if( !isxdigit(*(arg+i)) )
3705 return FALSE; //Not Hex value;
3707 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
3708 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
3709 CipherAlg = CIPHER_WEP64;
3710 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
3712 case 13: //wep 104 Ascii type
3713 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
3714 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
3715 CipherAlg = CIPHER_WEP128;
3716 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
3718 case 26: //wep 104 Hex type
3719 for(i=0; i < KeyLen; i++)
3721 if( !isxdigit(*(arg+i)) )
3722 return FALSE; //Not Hex value;
3724 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
3725 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
3726 CipherAlg = CIPHER_WEP128;
3727 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
3729 default: //Invalid argument
3730 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::Invalid argument (=%s)\n", arg));
3733 pAdapter->SharedKey[BSS0][3].CipherAlg = CipherAlg;
3735 // Set keys (into ASIC)
3736 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3738 else // Old WEP stuff
3740 AsicAddSharedKeyEntry(pAdapter,
3743 pAdapter->SharedKey[BSS0][3].CipherAlg,
3744 pAdapter->SharedKey[BSS0][3].Key,
3753 ==========================================================================
3757 TRUE if all parameters are OK, FALSE otherwise
3758 ==========================================================================
3760 INT Set_WPAPSK_Proc(
3761 IN PRTMP_ADAPTER pAd,
3766 if ((pAd->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
3767 (pAd->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
3768 (pAd->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
3770 return TRUE; // do nothing
3772 DBGPRINT(RT_DEBUG_TRACE, ("Set_WPAPSK_Proc::(WPAPSK=%s)\n", arg));
3774 status = RT_CfgSetWPAPSKKey(pAd, arg, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen, pAd->StaCfg.PMK);
3775 if (status == FALSE)
3777 DBGPRINT(RT_DEBUG_TRACE, ("Set_WPAPSK_Proc(): Set key failed!\n"));
3780 NdisZeroMemory(pAd->StaCfg.WpaPassPhrase, 64);
3781 NdisMoveMemory(pAd->StaCfg.WpaPassPhrase, arg, strlen(arg));
3782 pAd->StaCfg.WpaPassPhraseLen = (UINT)strlen(arg);
3786 if(pAd->StaCfg.BssType == BSS_ADHOC &&
3787 pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
3789 pAd->StaCfg.WpaState = SS_NOTUSE;
3793 // Start STA supplicant state machine
3794 pAd->StaCfg.WpaState = SS_START;
3801 ==========================================================================
3803 Set Power Saving mode
3805 TRUE if all parameters are OK, FALSE otherwise
3806 ==========================================================================
3808 INT Set_PSMode_Proc(
3809 IN PRTMP_ADAPTER pAdapter,
3812 if (pAdapter->StaCfg.BssType == BSS_INFRA)
3814 if ((strcmp(arg, "Max_PSP") == 0) ||
3815 (strcmp(arg, "max_psp") == 0) ||
3816 (strcmp(arg, "MAX_PSP") == 0))
3818 // do NOT turn on PSM bit here, wait until MlmeCheckPsmChange()
3819 // to exclude certain situations.
3820 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
3821 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeMAX_PSP;
3822 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeMAX_PSP;
3823 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
3824 pAdapter->StaCfg.DefaultListenCount = 5;
3827 else if ((strcmp(arg, "Fast_PSP") == 0) ||
3828 (strcmp(arg, "fast_psp") == 0) ||
3829 (strcmp(arg, "FAST_PSP") == 0))
3831 // do NOT turn on PSM bit here, wait until MlmeCheckPsmChange()
3832 // to exclude certain situations.
3833 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
3834 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
3835 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeFast_PSP;
3836 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeFast_PSP;
3837 pAdapter->StaCfg.DefaultListenCount = 3;
3839 else if ((strcmp(arg, "Legacy_PSP") == 0) ||
3840 (strcmp(arg, "legacy_psp") == 0) ||
3841 (strcmp(arg, "LEGACY_PSP") == 0))
3843 // do NOT turn on PSM bit here, wait until MlmeCheckPsmChange()
3844 // to exclude certain situations.
3845 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
3846 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
3847 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeLegacy_PSP;
3848 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeLegacy_PSP;
3849 pAdapter->StaCfg.DefaultListenCount = 3;
3853 //Default Ndis802_11PowerModeCAM
3854 // clear PSM bit immediately
3855 RTMP_SET_PSM_BIT(pAdapter, PWR_ACTIVE);
3856 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
3857 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
3858 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
3859 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
3862 DBGPRINT(RT_DEBUG_TRACE, ("Set_PSMode_Proc::(PSMode=%ld)\n", pAdapter->StaCfg.WindowsPowerMode));
3872 ==========================================================================
3874 Set WpaSupport flag.
3876 0: Driver ignore wpa_supplicant.
3877 1: wpa_supplicant initiates scanning and AP selection.
3878 2: driver takes care of scanning, AP selection, and IEEE 802.11 association parameters.
3880 TRUE if all parameters are OK, FALSE otherwise
3881 ==========================================================================
3883 INT Set_Wpa_Support(
3884 IN PRTMP_ADAPTER pAd,
3888 if ( simple_strtol(arg, 0, 10) == 0)
3889 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
3890 else if ( simple_strtol(arg, 0, 10) == 1)
3891 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE;
3892 else if ( simple_strtol(arg, 0, 10) == 2)
3893 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE_WITH_WEB_UI;
3895 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
3897 DBGPRINT(RT_DEBUG_TRACE, ("Set_Wpa_Support::(WpaSupplicantUP=%d)\n", pAd->StaCfg.WpaSupplicantUP));
3902 INT Set_TGnWifiTest_Proc(
3903 IN PRTMP_ADAPTER pAd,
3906 if (simple_strtol(arg, 0, 10) == 0)
3907 pAd->StaCfg.bTGnWifiTest = FALSE;
3909 pAd->StaCfg.bTGnWifiTest = TRUE;
3911 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_TGnWifiTest_Proc::(bTGnWifiTest=%d)\n", pAd->StaCfg.bTGnWifiTest));
3918 INT Show_Adhoc_MacTable_Proc(
3919 IN PRTMP_ADAPTER pAd,
3924 sprintf(extra, "\n");
3926 sprintf(extra + strlen(extra), "HT Operating Mode : %d\n", pAd->CommonCfg.AddHTInfo.AddHtInfo2.OperaionMode);
3928 sprintf(extra + strlen(extra), "\n%-19s%-4s%-4s%-7s%-7s%-7s%-10s%-6s%-6s%-6s%-6s\n",
3929 "MAC", "AID", "BSS", "RSSI0", "RSSI1", "RSSI2", "PhMd", "BW", "MCS", "SGI", "STBC");
3931 for (i=1; i<MAX_LEN_OF_MAC_TABLE; i++)
3933 PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
3935 if (strlen(extra) > (IW_PRIV_SIZE_MASK - 30))
3937 if ((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
3939 sprintf(extra + strlen(extra), "%02X:%02X:%02X:%02X:%02X:%02X ",
3940 pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
3941 pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5]);
3942 sprintf(extra + strlen(extra), "%-4d", (int)pEntry->Aid);
3943 sprintf(extra + strlen(extra), "%-4d", (int)pEntry->apidx);
3944 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi0);
3945 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi1);
3946 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi2);
3947 sprintf(extra + strlen(extra), "%-10s", GetPhyMode(pEntry->HTPhyMode.field.MODE));
3948 sprintf(extra + strlen(extra), "%-6s", GetBW(pEntry->HTPhyMode.field.BW));
3949 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.MCS);
3950 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.ShortGI);
3951 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.STBC);
3952 sprintf(extra + strlen(extra), "%-10d, %d, %d%%\n", pEntry->DebugFIFOCount, pEntry->DebugTxCount,
3953 (pEntry->DebugTxCount) ? ((pEntry->DebugTxCount-pEntry->DebugFIFOCount)*100/pEntry->DebugTxCount) : 0);
3954 sprintf(extra, "%s\n", extra);
3962 INT Set_BeaconLostTime_Proc(
3963 IN PRTMP_ADAPTER pAd,
3966 ULONG ltmp = (ULONG)simple_strtol(arg, 0, 10);
3968 if ((ltmp != 0) && (ltmp <= 60))
3969 pAd->StaCfg.BeaconLostTime = (ltmp * OS_HZ);
3971 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_BeaconLostTime_Proc::(BeaconLostTime=%ld)\n", pAd->StaCfg.BeaconLostTime));
3975 INT Set_AutoRoaming_Proc(
3976 IN PRTMP_ADAPTER pAd,
3979 if (simple_strtol(arg, 0, 10) == 0)
3980 pAd->StaCfg.bAutoRoaming = FALSE;
3982 pAd->StaCfg.bAutoRoaming = TRUE;
3984 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_AutoRoaming_Proc::(bAutoRoaming=%d)\n", pAd->StaCfg.bAutoRoaming));
3990 ==========================================================================
3992 Issue a site survey command to driver
3994 pAdapter Pointer to our adapter
3995 wrq Pointer to the ioctl argument
4002 1.) iwpriv ra0 set site_survey
4003 ==========================================================================
4005 INT Set_SiteSurvey_Proc(
4006 IN PRTMP_ADAPTER pAd,
4009 NDIS_802_11_SSID Ssid;
4011 //check if the interface is down
4012 if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
4014 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
4018 if (MONITOR_ON(pAd))
4020 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
4024 RTMPZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
4025 Ssid.SsidLength = 0;
4026 if ((arg != NULL) &&
4027 (strlen(arg) <= MAX_LEN_OF_SSID))
4029 RTMPMoveMemory(Ssid.Ssid, arg, strlen(arg));
4030 Ssid.SsidLength = strlen(arg);
4033 pAd->StaCfg.bScanReqIsFromWebUI = TRUE;
4035 if (pAd->Mlme.CntlMachine.CurrState != CNTL_IDLE)
4037 RTMP_MLME_RESET_STATE_MACHINE(pAd);
4038 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
4041 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
4042 // this request, because this request is initiated by NDIS.
4043 pAd->MlmeAux.CurrReqIsFromNdis = FALSE;
4044 // Reset allowed scan retries
4045 pAd->StaCfg.ScanCnt = 0;
4046 NdisGetSystemUpTime(&pAd->StaCfg.LastScanTime);
4049 MLME_CNTL_STATE_MACHINE,
4050 OID_802_11_BSSID_LIST_SCAN,
4054 RTMP_MLME_HANDLER(pAd);
4056 DBGPRINT(RT_DEBUG_TRACE, ("Set_SiteSurvey_Proc\n"));
4061 INT Set_ForceTxBurst_Proc(
4062 IN PRTMP_ADAPTER pAd,
4065 if (simple_strtol(arg, 0, 10) == 0)
4066 pAd->StaCfg.bForceTxBurst = FALSE;
4068 pAd->StaCfg.bForceTxBurst = TRUE;
4070 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_ForceTxBurst_Proc::(bForceTxBurst=%d)\n", pAd->StaCfg.bForceTxBurst));