2 *************************************************************************
4 * 5F., No.36, Taiyuan St., Jhubei City,
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
25 *************************************************************************
31 IOCTL related subroutines
35 -------- ---------- ----------------------------------------------
36 Rory Chen 01-03-2003 created
37 Rory Chen 02-14-2005 modify to support RT61
40 #include "rt_config.h"
43 extern ULONG RTDebugLevel;
47 #define WEP_SMALL_KEY_LEN (40/8)
48 #define WEP_LARGE_KEY_LEN (104/8)
50 #define GROUP_KEY_NO 4
52 extern UCHAR CipherWpa2Template[];
53 extern UCHAR CipherWpaPskTkip[];
54 extern UCHAR CipherWpaPskTkipLen;
56 typedef struct PACKED _RT_VERSION_INFO{
62 UINT DriverBuildMonth;
64 } RT_VERSION_INFO, *PRT_VERSION_INFO;
66 struct iw_priv_args privtab[] = {
68 IW_PRIV_TYPE_CHAR | 1024, 0,
71 { RTPRIV_IOCTL_SHOW, 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
73 { RTPRIV_IOCTL_SHOW, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
75 /* --- sub-ioctls definitions --- */
77 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "connStatus" },
79 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "driverVer" },
81 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "bainfo" },
83 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "descinfo" },
85 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "radio_off" },
87 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "radio_on" },
89 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "show" },
90 { SHOW_ADHOC_ENTRY_INFO,
91 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "adhocEntry" },
93 /* --- sub-ioctls relations --- */
97 IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
100 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
103 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
107 { RTPRIV_IOCTL_STATISTICS,
108 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
110 { RTPRIV_IOCTL_GSITESURVEY,
111 0, IW_PRIV_TYPE_CHAR | 1024,
116 IN PRTMP_ADAPTER pAdapter,
120 INT Set_WmmCapable_Proc(
121 IN PRTMP_ADAPTER pAd,
125 INT Set_NetworkType_Proc(
126 IN PRTMP_ADAPTER pAdapter,
129 INT Set_AuthMode_Proc(
130 IN PRTMP_ADAPTER pAdapter,
133 INT Set_EncrypType_Proc(
134 IN PRTMP_ADAPTER pAdapter,
137 INT Set_DefaultKeyID_Proc(
138 IN PRTMP_ADAPTER pAdapter,
142 IN PRTMP_ADAPTER pAdapter,
146 IN PRTMP_ADAPTER pAdapter,
150 IN PRTMP_ADAPTER pAdapter,
154 IN PRTMP_ADAPTER pAdapter,
158 IN PRTMP_ADAPTER pAdapter,
163 IN PRTMP_ADAPTER pAdapter,
166 #ifdef WPA_SUPPLICANT_SUPPORT
168 IN PRTMP_ADAPTER pAd,
170 #endif // WPA_SUPPLICANT_SUPPORT //
174 IN PRTMP_ADAPTER pAdapter,
175 IN struct iwreq *wrq);
178 IN PRTMP_ADAPTER pAdapter,
179 IN struct iwreq *wrq);
181 VOID RTMPIoctlE2PROM(
182 IN PRTMP_ADAPTER pAdapter,
183 IN struct iwreq *wrq);
187 NDIS_STATUS RTMPWPANoneAddKeyProc(
188 IN PRTMP_ADAPTER pAd,
191 INT Set_FragTest_Proc(
192 IN PRTMP_ADAPTER pAdapter,
195 #ifdef DOT11_N_SUPPORT
196 INT Set_TGnWifiTest_Proc(
197 IN PRTMP_ADAPTER pAd,
199 #endif // DOT11_N_SUPPORT //
201 INT Set_LongRetryLimit_Proc(
202 IN PRTMP_ADAPTER pAdapter,
205 INT Set_ShortRetryLimit_Proc(
206 IN PRTMP_ADAPTER pAdapter,
209 INT Show_Adhoc_MacTable_Proc(
210 IN PRTMP_ADAPTER pAd,
215 INT (*set_proc)(PRTMP_ADAPTER pAdapter, PUCHAR arg);
216 } *PRTMP_PRIVATE_SET_PROC, RTMP_PRIVATE_SUPPORT_PROC[] = {
217 {"DriverVersion", Set_DriverVersion_Proc},
218 {"CountryRegion", Set_CountryRegion_Proc},
219 {"CountryRegionABand", Set_CountryRegionABand_Proc},
220 {"SSID", Set_SSID_Proc},
221 {"WirelessMode", Set_WirelessMode_Proc},
222 {"TxBurst", Set_TxBurst_Proc},
223 {"TxPreamble", Set_TxPreamble_Proc},
224 {"TxPower", Set_TxPower_Proc},
225 {"Channel", Set_Channel_Proc},
226 {"BGProtection", Set_BGProtection_Proc},
227 {"RTSThreshold", Set_RTSThreshold_Proc},
228 {"FragThreshold", Set_FragThreshold_Proc},
229 #ifdef DOT11_N_SUPPORT
230 {"HtBw", Set_HtBw_Proc},
231 {"HtMcs", Set_HtMcs_Proc},
232 {"HtGi", Set_HtGi_Proc},
233 {"HtOpMode", Set_HtOpMode_Proc},
234 {"HtExtcha", Set_HtExtcha_Proc},
235 {"HtMpduDensity", Set_HtMpduDensity_Proc},
236 {"HtBaWinSize", Set_HtBaWinSize_Proc},
237 {"HtRdg", Set_HtRdg_Proc},
238 {"HtAmsdu", Set_HtAmsdu_Proc},
239 {"HtAutoBa", Set_HtAutoBa_Proc},
240 {"HtBaDecline", Set_BADecline_Proc},
241 {"HtProtect", Set_HtProtect_Proc},
242 {"HtMimoPs", Set_HtMimoPs_Proc},
243 #endif // DOT11_N_SUPPORT //
245 #ifdef AGGREGATION_SUPPORT
246 {"PktAggregate", Set_PktAggregate_Proc},
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},
268 #ifdef WPA_SUPPLICANT_SUPPORT
269 {"WpaSupport", Set_Wpa_Support},
270 #endif // WPA_SUPPLICANT_SUPPORT //
274 {"FixedTxMode", Set_FixedTxMode_Proc},
275 #ifdef DOT11_N_SUPPORT
276 {"TGnWifiTest", Set_TGnWifiTest_Proc},
277 {"ForceGF", Set_ForceGF_Proc},
278 #endif // DOT11_N_SUPPORT //
279 {"LongRetry", Set_LongRetryLimit_Proc},
280 {"ShortRetry", Set_ShortRetryLimit_Proc},
286 IN PRTMP_ADAPTER pAd,
287 IN PNDIS_802_11_KEY pKey)
290 MAC_TABLE_ENTRY *pEntry;
292 DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey ------>\n"));
294 if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
296 if (pKey->KeyIndex & 0x80000000)
298 if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
300 NdisZeroMemory(pAd->StaCfg.PMK, 32);
301 NdisMoveMemory(pAd->StaCfg.PMK, pKey->KeyMaterial, pKey->KeyLength);
305 NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));
306 pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
307 NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, pKey->KeyMaterial, LEN_TKIP_EK);
308 #ifdef WPA_SUPPLICANT_SUPPORT
309 if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
311 NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
312 NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
315 #endif // WPA_SUPPLICANT_SUPPORT //
317 NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
318 NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
321 // Decide its ChiperAlg
322 if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
323 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
324 else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)
325 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
327 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_NONE;
329 // Update these related information to MAC_TABLE_ENTRY
330 pEntry = &pAd->MacTab.Content[BSSID_WCID];
331 NdisMoveMemory(pEntry->PairwiseKey.Key, pAd->SharedKey[BSS0][0].Key, LEN_TKIP_EK);
332 NdisMoveMemory(pEntry->PairwiseKey.RxMic, pAd->SharedKey[BSS0][0].RxMic, LEN_TKIP_RXMICK);
333 NdisMoveMemory(pEntry->PairwiseKey.TxMic, pAd->SharedKey[BSS0][0].TxMic, LEN_TKIP_TXMICK);
334 pEntry->PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;
336 // Update pairwise key information to ASIC Shared Key Table
337 AsicAddSharedKeyEntry(pAd,
340 pAd->SharedKey[BSS0][0].CipherAlg,
341 pAd->SharedKey[BSS0][0].Key,
342 pAd->SharedKey[BSS0][0].TxMic,
343 pAd->SharedKey[BSS0][0].RxMic);
345 // Update ASIC WCID attribute table and IVEIV table
346 RTMPAddWcidAttributeEntry(pAd,
349 pAd->SharedKey[BSS0][0].CipherAlg,
352 if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
354 // set 802.1x port control
355 //pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
356 STA_PORT_SECURED(pAd);
358 // Indicate Connected for GUI
359 pAd->IndicateMediaState = NdisMediaStateConnected;
365 pAd->StaCfg.DefaultKeyId = (pKey->KeyIndex & 0xFF);
366 NdisZeroMemory(&pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId], sizeof(CIPHER_KEY));
367 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].KeyLen = LEN_TKIP_EK;
368 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key, pKey->KeyMaterial, LEN_TKIP_EK);
369 #ifdef WPA_SUPPLICANT_SUPPORT
370 if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
372 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
373 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
376 #endif // WPA_SUPPLICANT_SUPPORT //
378 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
379 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
382 // Update Shared Key CipherAlg
383 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_NONE;
384 if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
385 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_TKIP;
386 else if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)
387 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_AES;
389 // Update group key information to ASIC Shared Key Table
390 AsicAddSharedKeyEntry(pAd,
392 pAd->StaCfg.DefaultKeyId,
393 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
394 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key,
395 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic,
396 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic);
398 // Update ASIC WCID attribute table and IVEIV table
399 RTMPAddWcidAttributeEntry(pAd,
401 pAd->StaCfg.DefaultKeyId,
402 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
405 // set 802.1x port control
406 //pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
407 STA_PORT_SECURED(pAd);
409 // Indicate Connected for GUI
410 pAd->IndicateMediaState = NdisMediaStateConnected;
413 else // dynamic WEP from wpa_supplicant
418 if(pKey->KeyLength == 32)
421 KeyIdx = pKey->KeyIndex & 0x0fffffff;
425 // it is a default shared key, for Pairwise key setting
426 if (pKey->KeyIndex & 0x80000000)
428 pEntry = MacTableLookup(pAd, pKey->BSSID);
432 DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey: Set Pair-wise Key\n"));
434 // set key material and key length
435 pEntry->PairwiseKey.KeyLen = (UCHAR)pKey->KeyLength;
436 NdisMoveMemory(pEntry->PairwiseKey.Key, &pKey->KeyMaterial, pKey->KeyLength);
439 if (pKey->KeyLength == 5)
440 pEntry->PairwiseKey.CipherAlg = CIPHER_WEP64;
442 pEntry->PairwiseKey.CipherAlg = CIPHER_WEP128;
444 // Add Pair-wise key to Asic
445 AsicAddPairwiseKeyEntry(
449 &pEntry->PairwiseKey);
451 // update WCID attribute table and IVEIV table for this entry
452 RTMPAddWcidAttributeEntry(
455 KeyIdx, // The value may be not zero
456 pEntry->PairwiseKey.CipherAlg,
463 // Default key for tx (shared key)
464 pAd->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
466 // set key material and key length
467 pAd->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pKey->KeyLength;
468 NdisMoveMemory(pAd->SharedKey[BSS0][KeyIdx].Key, &pKey->KeyMaterial, pKey->KeyLength);
471 if (pKey->KeyLength == 5)
472 pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP64;
474 pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP128;
476 CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg;
477 Key = pAd->SharedKey[BSS0][KeyIdx].Key;
479 // Set Group key material to Asic
480 AsicAddSharedKeyEntry(pAd, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
482 // Update WCID attribute table and IVEIV table for this group key table
483 RTMPAddWcidAttributeEntry(pAd, BSS0, KeyIdx, CipherAlg, NULL);
492 char * rtstrchr(const char * s, int c)
494 for(; *s != (char) c; ++s)
501 This is required for LinEX2004/kernel2.6.7 to provide iwlist scanning function
505 rt_ioctl_giwname(struct net_device *dev,
506 struct iw_request_info *info,
507 char *name, char *extra)
509 // PRTMP_ADAPTER pAdapter = dev->ml_priv;
512 strncpy(name, "RT2870 Wireless", IFNAMSIZ);
517 int rt_ioctl_siwfreq(struct net_device *dev,
518 struct iw_request_info *info,
519 struct iw_freq *freq, char *extra)
521 PRTMP_ADAPTER pAdapter = dev->ml_priv;
524 //check if the interface is down
525 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
527 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
535 if((freq->e == 0) && (freq->m <= 1000))
536 chan = freq->m; // Setting by channel number
538 MAP_KHZ_TO_CHANNEL_ID( (freq->m /100) , chan); // Setting by frequency - search the table , like 2.412G, 2.422G,
540 if (ChannelSanity(pAdapter, chan) == TRUE)
542 pAdapter->CommonCfg.Channel = chan;
543 DBGPRINT(RT_DEBUG_ERROR, ("==>rt_ioctl_siwfreq::SIOCSIWFREQ[cmd=0x%x] (Channel=%d)\n", SIOCSIWFREQ, pAdapter->CommonCfg.Channel));
550 int rt_ioctl_giwfreq(struct net_device *dev,
551 struct iw_request_info *info,
552 struct iw_freq *freq, char *extra)
554 VIRTUAL_ADAPTER *pVirtualAd = NULL;
555 PRTMP_ADAPTER pAdapter = NULL;
559 if (dev->priv_flags == INT_MAIN)
561 pAdapter = dev->ml_priv;
565 pVirtualAd = dev->ml_priv;
566 if (pVirtualAd && pVirtualAd->RtmpDev)
567 pAdapter = pVirtualAd->RtmpDev->ml_priv;
570 if (pAdapter == NULL)
572 /* if 1st open fail, pAd will be free;
573 So the net_dev->ml_priv will be NULL in 2rd open */
577 ch = pAdapter->CommonCfg.Channel;
579 DBGPRINT(RT_DEBUG_TRACE,("==>rt_ioctl_giwfreq %d\n", ch));
581 MAP_CHANNEL_ID_TO_KHZ(ch, m);
587 int rt_ioctl_siwmode(struct net_device *dev,
588 struct iw_request_info *info,
589 __u32 *mode, char *extra)
591 PRTMP_ADAPTER pAdapter = dev->ml_priv;
593 //check if the interface is down
594 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
596 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
603 Set_NetworkType_Proc(pAdapter, "Adhoc");
606 Set_NetworkType_Proc(pAdapter, "Infra");
608 case IW_MODE_MONITOR:
609 Set_NetworkType_Proc(pAdapter, "Monitor");
612 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_siwmode::SIOCSIWMODE (unknown %d)\n", *mode));
616 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
617 pAdapter->StaCfg.WpaState = SS_NOTUSE;
622 int rt_ioctl_giwmode(struct net_device *dev,
623 struct iw_request_info *info,
624 __u32 *mode, char *extra)
626 PRTMP_ADAPTER pAdapter = NULL;
627 VIRTUAL_ADAPTER *pVirtualAd = NULL;
629 if (dev->priv_flags == INT_MAIN)
631 pAdapter = dev->ml_priv;
635 pVirtualAd = dev->ml_priv;
636 if (pVirtualAd && pVirtualAd->RtmpDev)
637 pAdapter = pVirtualAd->RtmpDev->ml_priv;
640 if (pAdapter == NULL)
642 /* if 1st open fail, pAd will be free;
643 So the net_dev->ml_priv will be NULL in 2rd open */
647 if (ADHOC_ON(pAdapter))
648 *mode = IW_MODE_ADHOC;
649 else if (INFRA_ON(pAdapter))
650 *mode = IW_MODE_INFRA;
651 else if (MONITOR_ON(pAdapter))
653 *mode = IW_MODE_MONITOR;
656 *mode = IW_MODE_AUTO;
658 DBGPRINT(RT_DEBUG_TRACE, ("==>rt_ioctl_giwmode(mode=%d)\n", *mode));
662 int rt_ioctl_siwsens(struct net_device *dev,
663 struct iw_request_info *info,
664 char *name, char *extra)
666 PRTMP_ADAPTER pAdapter = dev->ml_priv;
668 //check if the interface is down
669 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
671 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
678 int rt_ioctl_giwsens(struct net_device *dev,
679 struct iw_request_info *info,
680 char *name, char *extra)
685 int rt_ioctl_giwrange(struct net_device *dev,
686 struct iw_request_info *info,
687 struct iw_point *data, char *extra)
689 PRTMP_ADAPTER pAdapter = NULL;
690 VIRTUAL_ADAPTER *pVirtualAd = NULL;
691 struct iw_range *range = (struct iw_range *) extra;
695 if (dev->priv_flags == INT_MAIN)
697 pAdapter = dev->ml_priv;
701 pVirtualAd = dev->ml_priv;
702 if (pVirtualAd && pVirtualAd->RtmpDev)
703 pAdapter = pVirtualAd->RtmpDev->ml_priv;
706 if (pAdapter == NULL)
708 /* if 1st open fail, pAd will be free;
709 So the net_dev->ml_priv will be NULL in 2rd open */
713 DBGPRINT(RT_DEBUG_TRACE ,("===>rt_ioctl_giwrange\n"));
714 data->length = sizeof(struct iw_range);
715 memset(range, 0, sizeof(struct iw_range));
717 range->txpower_capa = IW_TXPOW_DBM;
719 if (INFRA_ON(pAdapter)||ADHOC_ON(pAdapter))
721 range->min_pmp = 1 * 1024;
722 range->max_pmp = 65535 * 1024;
723 range->min_pmt = 1 * 1024;
724 range->max_pmt = 1000 * 1024;
725 range->pmp_flags = IW_POWER_PERIOD;
726 range->pmt_flags = IW_POWER_TIMEOUT;
727 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT |
728 IW_POWER_UNICAST_R | IW_POWER_ALL_R;
731 range->we_version_compiled = WIRELESS_EXT;
732 range->we_version_source = 14;
734 range->retry_capa = IW_RETRY_LIMIT;
735 range->retry_flags = IW_RETRY_LIMIT;
736 range->min_retry = 0;
737 range->max_retry = 255;
739 range->num_channels = pAdapter->ChannelListNum;
742 for (i = 1; i <= range->num_channels; i++)
745 range->freq[val].i = pAdapter->ChannelList[i-1].Channel;
746 MAP_CHANNEL_ID_TO_KHZ(pAdapter->ChannelList[i-1].Channel, m);
747 range->freq[val].m = m * 100; /* HZ */
749 range->freq[val].e = 1;
751 if (val == IW_MAX_FREQUENCIES)
754 range->num_frequency = val;
756 range->max_qual.qual = 100; /* what is correct max? This was not
757 * documented exactly. At least
758 * 69 has been observed. */
759 range->max_qual.level = 0; /* dB */
760 range->max_qual.noise = 0; /* dB */
762 /* What would be suitable values for "average/typical" qual? */
763 range->avg_qual.qual = 20;
764 range->avg_qual.level = -60;
765 range->avg_qual.noise = -95;
766 range->sensitivity = 3;
768 range->max_encoding_tokens = NR_WEP_KEYS;
769 range->num_encoding_sizes = 2;
770 range->encoding_size[0] = 5;
771 range->encoding_size[1] = 13;
774 range->max_rts = 2347;
775 range->min_frag = 256;
776 range->max_frag = 2346;
778 #if WIRELESS_EXT > 17
779 /* IW_ENC_CAPA_* bit field */
780 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
781 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
787 int rt_ioctl_siwap(struct net_device *dev,
788 struct iw_request_info *info,
789 struct sockaddr *ap_addr, char *extra)
791 PRTMP_ADAPTER pAdapter = dev->ml_priv;
792 NDIS_802_11_MAC_ADDRESS Bssid;
794 //check if the interface is down
795 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
797 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
801 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
803 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
804 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
807 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
808 // this request, because this request is initiated by NDIS.
809 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
810 // Prevent to connect AP again in STAMlmePeriodicExec
811 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
813 memset(Bssid, 0, MAC_ADDR_LEN);
814 memcpy(Bssid, ap_addr->sa_data, MAC_ADDR_LEN);
815 MlmeEnqueue(pAdapter,
816 MLME_CNTL_STATE_MACHINE,
818 sizeof(NDIS_802_11_MAC_ADDRESS),
821 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCSIWAP %02x:%02x:%02x:%02x:%02x:%02x\n",
822 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
827 int rt_ioctl_giwap(struct net_device *dev,
828 struct iw_request_info *info,
829 struct sockaddr *ap_addr, char *extra)
831 PRTMP_ADAPTER pAdapter = NULL;
832 VIRTUAL_ADAPTER *pVirtualAd = NULL;
834 if (dev->priv_flags == INT_MAIN)
836 pAdapter = dev->ml_priv;
840 pVirtualAd = dev->ml_priv;
841 if (pVirtualAd && pVirtualAd->RtmpDev)
842 pAdapter = pVirtualAd->RtmpDev->ml_priv;
845 if (pAdapter == NULL)
847 /* if 1st open fail, pAd will be free;
848 So the net_dev->ml_priv will be NULL in 2rd open */
852 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
854 ap_addr->sa_family = ARPHRD_ETHER;
855 memcpy(ap_addr->sa_data, &pAdapter->CommonCfg.Bssid, ETH_ALEN);
857 #ifdef WPA_SUPPLICANT_SUPPORT
859 else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
861 ap_addr->sa_family = ARPHRD_ETHER;
862 memcpy(ap_addr->sa_data, &pAdapter->MlmeAux.Bssid, ETH_ALEN);
864 #endif // WPA_SUPPLICANT_SUPPORT //
867 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIWAP(=EMPTY)\n"));
875 * Units are in db above the noise floor. That means the
876 * rssi values reported in the tx/rx descriptors in the
877 * driver are the SNR expressed in db.
879 * If you assume that the noise floor is -95, which is an
880 * excellent assumption 99.5 % of the time, then you can
881 * derive the absolute signal level (i.e. -95 + rssi).
882 * There are some other slight factors to take into account
883 * depending on whether the rssi measurement is from 11b,
884 * 11g, or 11a. These differences are at most 2db and
887 * NB: various calculations are based on the orinoco/wavelan
888 * drivers for compatibility
890 static void set_quality(PRTMP_ADAPTER pAdapter,
891 struct iw_quality *iq,
898 ChannelQuality = 100;
899 else if (rssi >= -80) // between -50 ~ -80dbm
900 ChannelQuality = (__u8)(24 + ((rssi + 80) * 26)/10);
901 else if (rssi >= -90) // between -80 ~ -90dbm
902 ChannelQuality = (__u8)((rssi + 90) * 26)/10;
906 iq->qual = (__u8)ChannelQuality;
908 iq->level = (__u8)(rssi);
909 iq->noise = (pAdapter->BbpWriteLatch[66] > pAdapter->BbpTuning.FalseCcaUpperThreshold) ? ((__u8)pAdapter->BbpTuning.FalseCcaUpperThreshold) : ((__u8) pAdapter->BbpWriteLatch[66]); // noise level (dBm)
910 iq->noise += 256 - 143;
911 iq->updated = pAdapter->iw_stats.qual.updated;
914 int rt_ioctl_iwaplist(struct net_device *dev,
915 struct iw_request_info *info,
916 struct iw_point *data, char *extra)
918 PRTMP_ADAPTER pAdapter = dev->ml_priv;
920 struct sockaddr addr[IW_MAX_AP];
921 struct iw_quality qual[IW_MAX_AP];
924 //check if the interface is down
925 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
927 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
933 for (i = 0; i <IW_MAX_AP ; i++)
935 if (i >= pAdapter->ScanTab.BssNr)
937 addr[i].sa_family = ARPHRD_ETHER;
938 memcpy(addr[i].sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
939 set_quality(pAdapter, &qual[i], pAdapter->ScanTab.BssEntry[i].Rssi);
942 memcpy(extra, &addr, i*sizeof(addr[0]));
943 data->flags = 1; /* signal quality present (sort of) */
944 memcpy(extra + i*sizeof(addr[0]), &qual, i*sizeof(qual[i]));
950 int rt_ioctl_siwscan(struct net_device *dev,
951 struct iw_request_info *info,
952 struct iw_point *data, char *extra)
954 PRTMP_ADAPTER pAdapter = dev->ml_priv;
957 int Status = NDIS_STATUS_SUCCESS;
959 //check if the interface is down
960 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
962 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
966 if (MONITOR_ON(pAdapter))
968 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
973 #ifdef WPA_SUPPLICANT_SUPPORT
974 if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
976 pAdapter->StaCfg.WpaSupplicantScanCount++;
978 #endif // WPA_SUPPLICANT_SUPPORT //
980 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
981 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
986 #ifdef WPA_SUPPLICANT_SUPPORT
987 if ((pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE) &&
988 (pAdapter->StaCfg.WpaSupplicantScanCount > 3))
990 DBGPRINT(RT_DEBUG_TRACE, ("!!! WpaSupplicantScanCount > 3\n"));
991 Status = NDIS_STATUS_SUCCESS;
994 #endif // WPA_SUPPLICANT_SUPPORT //
996 if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
997 ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
998 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) &&
999 (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
1001 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
1002 Status = NDIS_STATUS_SUCCESS;
1006 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
1008 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
1009 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
1012 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
1013 // this request, because this request is initiated by NDIS.
1014 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
1015 // Reset allowed scan retries
1016 pAdapter->StaCfg.ScanCnt = 0;
1017 pAdapter->StaCfg.LastScanTime = Now;
1019 MlmeEnqueue(pAdapter,
1020 MLME_CNTL_STATE_MACHINE,
1021 OID_802_11_BSSID_LIST_SCAN,
1025 Status = NDIS_STATUS_SUCCESS;
1026 RT28XX_MLME_HANDLER(pAdapter);
1031 int rt_ioctl_giwscan(struct net_device *dev,
1032 struct iw_request_info *info,
1033 struct iw_point *data, char *extra)
1036 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1038 char *current_ev = extra, *previous_ev = extra;
1040 char *current_val, custom[MAX_CUSTOM_LEN] = {0};
1043 #endif // IWEVGENIE //
1044 struct iw_event iwe;
1046 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
1049 * Still scanning, indicate the caller should try again.
1055 #ifdef WPA_SUPPLICANT_SUPPORT
1056 if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
1058 pAdapter->StaCfg.WpaSupplicantScanCount = 0;
1060 #endif // WPA_SUPPLICANT_SUPPORT //
1062 if (pAdapter->ScanTab.BssNr == 0)
1068 #if WIRELESS_EXT >= 17
1069 if (data->length > 0)
1070 end_buf = extra + data->length;
1072 end_buf = extra + IW_SCAN_MAX_DATA;
1074 end_buf = extra + IW_SCAN_MAX_DATA;
1077 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
1079 if (current_ev >= end_buf)
1081 #if WIRELESS_EXT >= 17
1089 //================================
1090 memset(&iwe, 0, sizeof(iwe));
1091 iwe.cmd = SIOCGIWAP;
1092 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1093 memcpy(iwe.u.ap_addr.sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, ETH_ALEN);
1095 previous_ev = current_ev;
1096 current_ev = iwe_stream_add_event(info, current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);
1097 if (current_ev == previous_ev)
1098 #if WIRELESS_EXT >= 17
1105 //================================
1106 memset(&iwe, 0, sizeof(iwe));
1107 iwe.cmd = SIOCGIWESSID;
1108 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].SsidLen;
1109 iwe.u.data.flags = 1;
1111 previous_ev = current_ev;
1112 current_ev = iwe_stream_add_point(info, current_ev,end_buf, &iwe, pAdapter->ScanTab.BssEntry[i].Ssid);
1113 if (current_ev == previous_ev)
1114 #if WIRELESS_EXT >= 17
1121 //================================
1122 memset(&iwe, 0, sizeof(iwe));
1123 iwe.cmd = SIOCGIWMODE;
1124 if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11IBSS)
1126 iwe.u.mode = IW_MODE_ADHOC;
1128 else if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11Infrastructure)
1130 iwe.u.mode = IW_MODE_INFRA;
1134 iwe.u.mode = IW_MODE_AUTO;
1136 iwe.len = IW_EV_UINT_LEN;
1138 previous_ev = current_ev;
1139 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
1140 if (current_ev == previous_ev)
1141 #if WIRELESS_EXT >= 17
1147 //Channel and Frequency
1148 //================================
1149 memset(&iwe, 0, sizeof(iwe));
1150 iwe.cmd = SIOCGIWFREQ;
1151 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
1152 iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
1154 iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
1158 previous_ev = current_ev;
1159 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
1160 if (current_ev == previous_ev)
1161 #if WIRELESS_EXT >= 17
1167 //Add quality statistics
1168 //================================
1169 memset(&iwe, 0, sizeof(iwe));
1171 iwe.u.qual.level = 0;
1172 iwe.u.qual.noise = 0;
1173 set_quality(pAdapter, &iwe.u.qual, pAdapter->ScanTab.BssEntry[i].Rssi);
1174 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
1175 if (current_ev == previous_ev)
1176 #if WIRELESS_EXT >= 17
1183 //================================
1184 memset(&iwe, 0, sizeof(iwe));
1185 iwe.cmd = SIOCGIWENCODE;
1186 if (CAP_IS_PRIVACY_ON (pAdapter->ScanTab.BssEntry[i].CapabilityInfo ))
1187 iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1189 iwe.u.data.flags = IW_ENCODE_DISABLED;
1191 previous_ev = current_ev;
1192 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);
1193 if (current_ev == previous_ev)
1194 #if WIRELESS_EXT >= 17
1201 //================================
1202 if (pAdapter->ScanTab.BssEntry[i].SupRateLen)
1204 UCHAR tmpRate = pAdapter->ScanTab.BssEntry[i].SupRate[pAdapter->ScanTab.BssEntry[i].SupRateLen-1];
1205 memset(&iwe, 0, sizeof(iwe));
1206 iwe.cmd = SIOCGIWRATE;
1207 current_val = current_ev + IW_EV_LCP_LEN;
1208 if (tmpRate == 0x82)
1209 iwe.u.bitrate.value = 1 * 1000000;
1210 else if (tmpRate == 0x84)
1211 iwe.u.bitrate.value = 2 * 1000000;
1212 else if (tmpRate == 0x8B)
1213 iwe.u.bitrate.value = 5.5 * 1000000;
1214 else if (tmpRate == 0x96)
1215 iwe.u.bitrate.value = 11 * 1000000;
1217 iwe.u.bitrate.value = (tmpRate/2) * 1000000;
1219 iwe.u.bitrate.disabled = 0;
1220 current_val = iwe_stream_add_value(info, current_ev,
1221 current_val, end_buf, &iwe,
1224 if((current_val-current_ev)>IW_EV_LCP_LEN)
1225 current_ev = current_val;
1227 #if WIRELESS_EXT >= 17
1236 if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
1238 memset(&iwe, 0, sizeof(iwe));
1239 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1240 memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].WpaIE.IE[0]),
1241 pAdapter->ScanTab.BssEntry[i].WpaIE.IELen);
1242 iwe.cmd = IWEVGENIE;
1243 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].WpaIE.IELen;
1244 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, custom);
1245 if (current_ev == previous_ev)
1246 #if WIRELESS_EXT >= 17
1254 if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
1256 memset(&iwe, 0, sizeof(iwe));
1257 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1258 memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].RsnIE.IE[0]),
1259 pAdapter->ScanTab.BssEntry[i].RsnIE.IELen);
1260 iwe.cmd = IWEVGENIE;
1261 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].RsnIE.IELen;
1262 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, custom);
1263 if (current_ev == previous_ev)
1264 #if WIRELESS_EXT >= 17
1272 //================================
1273 if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
1275 NdisZeroMemory(&iwe, sizeof(iwe));
1276 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1277 iwe.cmd = IWEVCUSTOM;
1278 iwe.u.data.length = (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen * 2) + 7;
1279 NdisMoveMemory(custom, "wpa_ie=", 7);
1280 for (idx = 0; idx < pAdapter->ScanTab.BssEntry[i].WpaIE.IELen; idx++)
1281 sprintf(custom + strlen(custom), "%02x", pAdapter->ScanTab.BssEntry[i].WpaIE.IE[idx]);
1282 previous_ev = current_ev;
1283 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, custom);
1284 if (current_ev == previous_ev)
1285 #if WIRELESS_EXT >= 17
1293 if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
1295 NdisZeroMemory(&iwe, sizeof(iwe));
1296 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1297 iwe.cmd = IWEVCUSTOM;
1298 iwe.u.data.length = (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen * 2) + 7;
1299 NdisMoveMemory(custom, "rsn_ie=", 7);
1300 for (idx = 0; idx < pAdapter->ScanTab.BssEntry[i].RsnIE.IELen; idx++)
1301 sprintf(custom + strlen(custom), "%02x", pAdapter->ScanTab.BssEntry[i].RsnIE.IE[idx]);
1302 previous_ev = current_ev;
1303 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, custom);
1304 if (current_ev == previous_ev)
1305 #if WIRELESS_EXT >= 17
1311 #endif // IWEVGENIE //
1314 data->length = current_ev - extra;
1315 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
1316 DBGPRINT(RT_DEBUG_ERROR ,("===>rt_ioctl_giwscan. %d(%d) BSS returned, data->length = %d\n",i , pAdapter->ScanTab.BssNr, data->length));
1321 int rt_ioctl_siwessid(struct net_device *dev,
1322 struct iw_request_info *info,
1323 struct iw_point *data, char *essid)
1325 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1327 //check if the interface is down
1328 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1330 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1336 PCHAR pSsidString = NULL;
1338 // Includes null character.
1339 if (data->length > (IW_ESSID_MAX_SIZE + 1))
1342 pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
1345 NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
1346 NdisMoveMemory(pSsidString, essid, data->length);
1347 if (Set_SSID_Proc(pAdapter, pSsidString) == FALSE)
1356 if (Set_SSID_Proc(pAdapter, "") == FALSE)
1362 int rt_ioctl_giwessid(struct net_device *dev,
1363 struct iw_request_info *info,
1364 struct iw_point *data, char *essid)
1366 PRTMP_ADAPTER pAdapter = NULL;
1367 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1369 if (dev->priv_flags == INT_MAIN)
1371 pAdapter = dev->ml_priv;
1375 pVirtualAd = dev->ml_priv;
1376 if (pVirtualAd && pVirtualAd->RtmpDev)
1377 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1380 if (pAdapter == NULL)
1382 /* if 1st open fail, pAd will be free;
1383 So the net_dev->ml_priv will be NULL in 2rd open */
1388 if (MONITOR_ON(pAdapter))
1394 if (OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED))
1396 DBGPRINT(RT_DEBUG_TRACE ,("MediaState is connected\n"));
1397 data->length = pAdapter->CommonCfg.SsidLen;
1398 memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
1401 #ifdef WPA_SUPPLICANT_SUPPORT
1403 else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
1405 data->length = pAdapter->CommonCfg.SsidLen;
1406 memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
1408 #endif // WPA_SUPPLICANT_SUPPORT //
1411 {//the ANY ssid was specified
1413 DBGPRINT(RT_DEBUG_TRACE ,("MediaState is not connected, ess\n"));
1420 int rt_ioctl_siwnickn(struct net_device *dev,
1421 struct iw_request_info *info,
1422 struct iw_point *data, char *nickname)
1424 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1426 //check if the interface is down
1427 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1429 DBGPRINT(RT_DEBUG_TRACE ,("INFO::Network is down!\n"));
1433 if (data->length > IW_ESSID_MAX_SIZE)
1436 memset(pAdapter->nickname, 0, IW_ESSID_MAX_SIZE + 1);
1437 memcpy(pAdapter->nickname, nickname, data->length);
1443 int rt_ioctl_giwnickn(struct net_device *dev,
1444 struct iw_request_info *info,
1445 struct iw_point *data, char *nickname)
1447 PRTMP_ADAPTER pAdapter = NULL;
1448 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1450 if (dev->priv_flags == INT_MAIN)
1452 pAdapter = dev->ml_priv;
1456 pVirtualAd = dev->ml_priv;
1457 if (pVirtualAd && pVirtualAd->RtmpDev)
1458 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1461 if (pAdapter == NULL)
1463 /* if 1st open fail, pAd will be free;
1464 So the net_dev->ml_priv will be NULL in 2rd open */
1468 if (data->length > strlen(pAdapter->nickname) + 1)
1469 data->length = strlen(pAdapter->nickname) + 1;
1470 if (data->length > 0) {
1471 memcpy(nickname, pAdapter->nickname, data->length-1);
1472 nickname[data->length-1] = '\0';
1477 int rt_ioctl_siwrts(struct net_device *dev,
1478 struct iw_request_info *info,
1479 struct iw_param *rts, char *extra)
1481 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1484 //check if the interface is down
1485 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1487 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1492 val = MAX_RTS_THRESHOLD;
1493 else if (rts->value < 0 || rts->value > MAX_RTS_THRESHOLD)
1495 else if (rts->value == 0)
1496 val = MAX_RTS_THRESHOLD;
1500 if (val != pAdapter->CommonCfg.RtsThreshold)
1501 pAdapter->CommonCfg.RtsThreshold = val;
1506 int rt_ioctl_giwrts(struct net_device *dev,
1507 struct iw_request_info *info,
1508 struct iw_param *rts, char *extra)
1510 PRTMP_ADAPTER pAdapter = NULL;
1511 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1513 if (dev->priv_flags == INT_MAIN)
1515 pAdapter = dev->ml_priv;
1519 pVirtualAd = dev->ml_priv;
1520 if (pVirtualAd && pVirtualAd->RtmpDev)
1521 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1524 if (pAdapter == NULL)
1526 /* if 1st open fail, pAd will be free;
1527 So the net_dev->ml_priv will be NULL in 2rd open */
1531 //check if the interface is down
1532 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1534 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1538 rts->value = pAdapter->CommonCfg.RtsThreshold;
1539 rts->disabled = (rts->value == MAX_RTS_THRESHOLD);
1545 int rt_ioctl_siwfrag(struct net_device *dev,
1546 struct iw_request_info *info,
1547 struct iw_param *frag, char *extra)
1549 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1552 //check if the interface is down
1553 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1555 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1560 val = MAX_FRAG_THRESHOLD;
1561 else if (frag->value >= MIN_FRAG_THRESHOLD || frag->value <= MAX_FRAG_THRESHOLD)
1562 val = __cpu_to_le16(frag->value & ~0x1); /* even numbers only */
1563 else if (frag->value == 0)
1564 val = MAX_FRAG_THRESHOLD;
1568 pAdapter->CommonCfg.FragmentThreshold = val;
1572 int rt_ioctl_giwfrag(struct net_device *dev,
1573 struct iw_request_info *info,
1574 struct iw_param *frag, char *extra)
1576 PRTMP_ADAPTER pAdapter = NULL;
1577 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1579 if (dev->priv_flags == INT_MAIN)
1581 pAdapter = dev->ml_priv;
1585 pVirtualAd = dev->ml_priv;
1586 if (pVirtualAd && pVirtualAd->RtmpDev)
1587 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1590 if (pAdapter == NULL)
1592 /* if 1st open fail, pAd will be free;
1593 So the net_dev->ml_priv will be NULL in 2rd open */
1597 //check if the interface is down
1598 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1600 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1604 frag->value = pAdapter->CommonCfg.FragmentThreshold;
1605 frag->disabled = (frag->value == MAX_FRAG_THRESHOLD);
1611 #define MAX_WEP_KEY_SIZE 13
1612 #define MIN_WEP_KEY_SIZE 5
1613 int rt_ioctl_siwencode(struct net_device *dev,
1614 struct iw_request_info *info,
1615 struct iw_point *erq, char *extra)
1617 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1619 //check if the interface is down
1620 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1622 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1626 if ((erq->length == 0) &&
1627 (erq->flags & IW_ENCODE_DISABLED))
1629 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
1630 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
1631 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
1632 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
1633 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1636 else if ((erq->length == 0) &&
1637 (erq->flags & IW_ENCODE_RESTRICTED || erq->flags & IW_ENCODE_OPEN))
1639 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
1640 STA_PORT_SECURED(pAdapter);
1641 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
1642 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
1643 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
1644 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
1645 if (erq->flags & IW_ENCODE_RESTRICTED)
1646 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
1648 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1652 if (erq->length > 0)
1654 int keyIdx = (erq->flags & IW_ENCODE_INDEX) - 1;
1655 /* Check the size of the key */
1656 if (erq->length > MAX_WEP_KEY_SIZE) {
1659 /* Check key index */
1660 if ((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
1662 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::Wrong keyIdx=%d! Using default key instead (%d)\n",
1663 keyIdx, pAdapter->StaCfg.DefaultKeyId));
1666 keyIdx = pAdapter->StaCfg.DefaultKeyId;
1669 NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
1671 if (erq->length == MAX_WEP_KEY_SIZE)
1673 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
1674 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
1676 else if (erq->length == MIN_WEP_KEY_SIZE)
1678 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
1679 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
1682 /* Disable the key */
1683 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
1685 /* Check if the key is not marked as invalid */
1686 if(!(erq->flags & IW_ENCODE_NOKEY)) {
1687 /* Copy the key in the driver */
1688 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, extra, erq->length);
1693 /* Do we want to just set the transmit key index ? */
1694 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
1695 if ((index >= 0) && (index < 4))
1697 pAdapter->StaCfg.DefaultKeyId = index;
1700 /* Don't complain if only change the mode */
1701 if (!(erq->flags & IW_ENCODE_MODE)) {
1707 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::erq->flags=%x\n",erq->flags));
1708 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::AuthMode=%x\n",pAdapter->StaCfg.AuthMode));
1709 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::DefaultKeyId=%x, KeyLen = %d\n",pAdapter->StaCfg.DefaultKeyId , pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen));
1710 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::WepStatus=%x\n",pAdapter->StaCfg.WepStatus));
1715 rt_ioctl_giwencode(struct net_device *dev,
1716 struct iw_request_info *info,
1717 struct iw_point *erq, char *key)
1720 PRTMP_ADAPTER pAdapter = NULL;
1721 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1723 if (dev->priv_flags == INT_MAIN)
1725 pAdapter = dev->ml_priv;
1729 pVirtualAd = dev->ml_priv;
1730 if (pVirtualAd && pVirtualAd->RtmpDev)
1731 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1734 if (pAdapter == NULL)
1736 /* if 1st open fail, pAd will be free;
1737 So the net_dev->ml_priv will be NULL in 2rd open */
1741 //check if the interface is down
1742 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1744 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1748 kid = erq->flags & IW_ENCODE_INDEX;
1749 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_giwencode %d\n", erq->flags & IW_ENCODE_INDEX));
1751 if (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled)
1754 erq->flags = IW_ENCODE_DISABLED;
1756 else if ((kid > 0) && (kid <=4))
1759 erq->flags = kid ; /* NB: base 1 */
1760 if (erq->length > pAdapter->SharedKey[BSS0][kid-1].KeyLen)
1761 erq->length = pAdapter->SharedKey[BSS0][kid-1].KeyLen;
1762 memcpy(key, pAdapter->SharedKey[BSS0][kid-1].Key, erq->length);
1763 //if ((kid == pAdapter->PortCfg.DefaultKeyId))
1764 //erq->flags |= IW_ENCODE_ENABLED; /* XXX */
1765 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1766 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1768 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1773 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1774 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1776 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1777 erq->length = pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen;
1778 memcpy(key, pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key, erq->length);
1779 // copy default key ID
1780 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1781 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1783 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1784 erq->flags = pAdapter->StaCfg.DefaultKeyId + 1; /* NB: base 1 */
1785 erq->flags |= IW_ENCODE_ENABLED; /* XXX */
1793 rt_ioctl_setparam(struct net_device *dev, struct iw_request_info *info,
1794 void *w, char *extra)
1796 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1797 PRTMP_ADAPTER pAdapter;
1799 char *this_char = extra;
1803 if (dev->priv_flags == INT_MAIN)
1805 pAdapter = dev->ml_priv;
1809 pVirtualAd = dev->ml_priv;
1810 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1812 pObj = (POS_COOKIE) pAdapter->OS_Cookie;
1814 if (pAdapter == NULL)
1816 /* if 1st open fail, pAd will be free;
1817 So the net_dev->ml_priv will be NULL in 2rd open */
1822 pObj->ioctl_if_type = INT_MAIN;
1823 pObj->ioctl_if = MAIN_MBSSID;
1826 //check if the interface is down
1827 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1829 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1836 if ((value = rtstrchr(this_char, '=')) != NULL)
1842 // reject setting nothing besides ANY ssid(ssidLen=0)
1843 if (!*value && (strcmp(this_char, "SSID") != 0))
1846 for (PRTMP_PRIVATE_SET_PROC = RTMP_PRIVATE_SUPPORT_PROC; PRTMP_PRIVATE_SET_PROC->name; PRTMP_PRIVATE_SET_PROC++)
1848 if (strcmp(this_char, PRTMP_PRIVATE_SET_PROC->name) == 0)
1850 if(!PRTMP_PRIVATE_SET_PROC->set_proc(pAdapter, value))
1851 { //FALSE:Set private failed then return Invalid argument
1854 break; //Exit for loop.
1858 if(PRTMP_PRIVATE_SET_PROC->name == NULL)
1859 { //Not found argument
1861 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_setparam:: (iwpriv) Not Support Set Command [%s=%s]\n", this_char, value));
1869 rt_private_get_statistics(struct net_device *dev, struct iw_request_info *info,
1870 struct iw_point *wrq, char *extra)
1873 PRTMP_ADAPTER pAd = dev->ml_priv;
1881 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
1882 sprintf(extra, "\n\n");
1885 sprintf(extra+strlen(extra), "Tx success = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart);
1886 sprintf(extra+strlen(extra), "Tx success without retry = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart - (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
1888 sprintf(extra+strlen(extra), "Tx success after retry = %ld\n", (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
1889 sprintf(extra+strlen(extra), "Tx fail to Rcv ACK after retry = %ld\n", (ULONG)pAd->WlanCounters.FailedCount.QuadPart);
1890 sprintf(extra+strlen(extra), "RTS Success Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSSuccessCount.QuadPart);
1891 sprintf(extra+strlen(extra), "RTS Fail Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSFailureCount.QuadPart);
1893 sprintf(extra+strlen(extra), "Rx success = %ld\n", (ULONG)pAd->WlanCounters.ReceivedFragmentCount.QuadPart);
1894 sprintf(extra+strlen(extra), "Rx with CRC = %ld\n", (ULONG)pAd->WlanCounters.FCSErrorCount.QuadPart);
1895 sprintf(extra+strlen(extra), "Rx drop due to out of resource = %ld\n", (ULONG)pAd->Counters8023.RxNoBuffer);
1896 sprintf(extra+strlen(extra), "Rx duplicate frame = %ld\n", (ULONG)pAd->WlanCounters.FrameDuplicateCount.QuadPart);
1898 sprintf(extra+strlen(extra), "False CCA (one second) = %ld\n", (ULONG)pAd->RalinkCounters.OneSecFalseCCACnt);
1900 sprintf(extra+strlen(extra), "RSSI-A = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi0 - pAd->BbpRssiToDbmDelta));
1901 sprintf(extra+strlen(extra), "RSSI-B (if available) = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi1 - pAd->BbpRssiToDbmDelta));
1902 sprintf(extra+strlen(extra), "RSSI-C (if available) = %ld\n\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi2 - pAd->BbpRssiToDbmDelta));
1904 #ifdef WPA_SUPPLICANT_SUPPORT
1905 sprintf(extra+strlen(extra), "WpaSupplicantUP = %d\n\n", pAd->StaCfg.WpaSupplicantUP);
1906 #endif // WPA_SUPPLICANT_SUPPORT //
1909 wrq->length = strlen(extra) + 1; // 1: size of '\0'
1910 DBGPRINT(RT_DEBUG_TRACE, ("<== rt_private_get_statistics, wrq->length = %d\n", wrq->length));
1915 #ifdef DOT11_N_SUPPORT
1917 IN PRTMP_ADAPTER pAd,
1921 BA_ORI_ENTRY *pOriBAEntry;
1922 BA_REC_ENTRY *pRecBAEntry;
1924 for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
1926 PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
1927 if (((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
1928 || (pEntry->ValidAsWDS) || (pEntry->ValidAsMesh))
1930 sprintf(pOutBuf + strlen(pOutBuf), "\n%02X:%02X:%02X:%02X:%02X:%02X (Aid = %d) (AP) -\n",
1931 pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
1932 pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5], pEntry->Aid);
1934 sprintf(pOutBuf, "%s[Recipient]\n", pOutBuf);
1935 for (j=0; j < NUM_OF_TID; j++)
1937 if (pEntry->BARecWcidArray[j] != 0)
1939 pRecBAEntry =&pAd->BATable.BARecEntry[pEntry->BARecWcidArray[j]];
1940 sprintf(pOutBuf + strlen(pOutBuf), "TID=%d, BAWinSize=%d, LastIndSeq=%d, ReorderingPkts=%d\n", j, pRecBAEntry->BAWinSize, pRecBAEntry->LastIndSeq, pRecBAEntry->list.qlen);
1943 sprintf(pOutBuf, "%s\n", pOutBuf);
1945 sprintf(pOutBuf, "%s[Originator]\n", pOutBuf);
1946 for (j=0; j < NUM_OF_TID; j++)
1948 if (pEntry->BAOriWcidArray[j] != 0)
1950 pOriBAEntry =&pAd->BATable.BAOriEntry[pEntry->BAOriWcidArray[j]];
1951 sprintf(pOutBuf + strlen(pOutBuf), "TID=%d, BAWinSize=%d, StartSeq=%d, CurTxSeq=%d\n", j, pOriBAEntry->BAWinSize, pOriBAEntry->Sequence, pEntry->TxSeq[j]);
1954 sprintf(pOutBuf, "%s\n\n", pOutBuf);
1956 if (strlen(pOutBuf) > (IW_PRIV_SIZE_MASK - 30))
1962 #endif // DOT11_N_SUPPORT //
1965 rt_private_show(struct net_device *dev, struct iw_request_info *info,
1966 struct iw_point *wrq, char *extra)
1969 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1972 u32 subcmd = wrq->flags;
1974 if (dev->priv_flags == INT_MAIN)
1978 pVirtualAd = dev->ml_priv;
1979 pAd = pVirtualAd->RtmpDev->ml_priv;
1981 pObj = (POS_COOKIE) pAd->OS_Cookie;
1985 /* if 1st open fail, pAd will be free;
1986 So the net_dev->ml_priv will be NULL in 2rd open */
1995 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
1998 pObj->ioctl_if_type = INT_MAIN;
1999 pObj->ioctl_if = MAIN_MBSSID;
2005 case SHOW_CONN_STATUS:
2006 if (MONITOR_ON(pAd))
2008 #ifdef DOT11_N_SUPPORT
2009 if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
2010 pAd->CommonCfg.RegTransmitSetting.field.BW)
2011 sprintf(extra, "Monitor Mode(CentralChannel %d)\n", pAd->CommonCfg.CentralChannel);
2013 #endif // DOT11_N_SUPPORT //
2014 sprintf(extra, "Monitor Mode(Channel %d)\n", pAd->CommonCfg.Channel);
2018 if (pAd->IndicateMediaState == NdisMediaStateConnected)
2022 sprintf(extra, "Connected(AP: %s[%02X:%02X:%02X:%02X:%02X:%02X])\n",
2023 pAd->CommonCfg.Ssid,
2024 pAd->CommonCfg.Bssid[0],
2025 pAd->CommonCfg.Bssid[1],
2026 pAd->CommonCfg.Bssid[2],
2027 pAd->CommonCfg.Bssid[3],
2028 pAd->CommonCfg.Bssid[4],
2029 pAd->CommonCfg.Bssid[5]);
2030 DBGPRINT(RT_DEBUG_TRACE ,("Ssid=%s ,Ssidlen = %d\n",pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen));
2032 else if (ADHOC_ON(pAd))
2033 sprintf(extra, "Connected\n");
2037 sprintf(extra, "Disconnected\n");
2038 DBGPRINT(RT_DEBUG_TRACE ,("ConnStatus is not connected\n"));
2041 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2043 case SHOW_DRVIER_VERION:
2044 sprintf(extra, "Driver version-%s, %s %s\n", STA_DRIVER_VERSION, __DATE__, __TIME__ );
2045 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2047 #ifdef DOT11_N_SUPPORT
2049 getBaInfo(pAd, extra);
2050 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2052 #endif // DOT11_N_SUPPORT //
2053 case SHOW_DESC_INFO:
2055 Show_DescInfo_Proc(pAd, NULL);
2056 wrq->length = 0; // 1: size of '\0'
2060 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
2062 sprintf(extra, "Scanning\n");
2063 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2066 pAd->StaCfg.bSwRadio = FALSE;
2067 if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
2069 pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
2070 if (pAd->StaCfg.bRadio == FALSE)
2073 // Update extra information
2074 pAd->ExtraInfo = SW_RADIO_OFF;
2077 sprintf(extra, "Radio Off\n");
2078 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2081 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
2083 sprintf(extra, "Scanning\n");
2084 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2087 pAd->StaCfg.bSwRadio = TRUE;
2088 //if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
2090 pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
2091 if (pAd->StaCfg.bRadio == TRUE)
2094 // Update extra information
2095 pAd->ExtraInfo = EXTRA_INFO_CLEAR;
2098 sprintf(extra, "Radio On\n");
2099 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2102 case SHOW_CFG_VALUE:
2104 Status = RTMPShowCfgValue(pAd, wrq->pointer, extra);
2106 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2109 case SHOW_ADHOC_ENTRY_INFO:
2110 Show_Adhoc_MacTable_Proc(pAd, extra);
2111 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2114 DBGPRINT(RT_DEBUG_TRACE, ("%s - unknow subcmd = %d\n", __func__, subcmd));
2122 int rt_ioctl_siwmlme(struct net_device *dev,
2123 struct iw_request_info *info,
2124 union iwreq_data *wrqu,
2127 PRTMP_ADAPTER pAd = dev->ml_priv;
2128 struct iw_mlme *pMlme = (struct iw_mlme *)wrqu->data.pointer;
2129 MLME_QUEUE_ELEM MsgElem;
2130 MLME_DISASSOC_REQ_STRUCT DisAssocReq;
2131 MLME_DEAUTH_REQ_STRUCT DeAuthReq;
2133 DBGPRINT(RT_DEBUG_TRACE, ("====> %s\n", __func__));
2140 #ifdef IW_MLME_DEAUTH
2141 case IW_MLME_DEAUTH:
2142 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DEAUTH\n", __func__));
2143 COPY_MAC_ADDR(DeAuthReq.Addr, pAd->CommonCfg.Bssid);
2144 DeAuthReq.Reason = pMlme->reason_code;
2145 MsgElem.MsgLen = sizeof(MLME_DEAUTH_REQ_STRUCT);
2146 NdisMoveMemory(MsgElem.Msg, &DeAuthReq, sizeof(MLME_DEAUTH_REQ_STRUCT));
2147 MlmeDeauthReqAction(pAd, &MsgElem);
2150 LinkDown(pAd, FALSE);
2151 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
2154 #endif // IW_MLME_DEAUTH //
2155 #ifdef IW_MLME_DISASSOC
2156 case IW_MLME_DISASSOC:
2157 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DISASSOC\n", __func__));
2158 COPY_MAC_ADDR(DisAssocReq.Addr, pAd->CommonCfg.Bssid);
2159 DisAssocReq.Reason = pMlme->reason_code;
2161 MsgElem.Machine = ASSOC_STATE_MACHINE;
2162 MsgElem.MsgType = MT2_MLME_DISASSOC_REQ;
2163 MsgElem.MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
2164 NdisMoveMemory(MsgElem.Msg, &DisAssocReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
2166 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
2167 MlmeDisassocReqAction(pAd, &MsgElem);
2169 #endif // IW_MLME_DISASSOC //
2171 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - Unknow Command\n", __func__));
2177 #endif // SIOCSIWMLME //
2179 #if WIRELESS_EXT > 17
2180 int rt_ioctl_siwauth(struct net_device *dev,
2181 struct iw_request_info *info,
2182 union iwreq_data *wrqu, char *extra)
2184 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2185 struct iw_param *param = &wrqu->param;
2187 //check if the interface is down
2188 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2190 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2193 switch (param->flags & IW_AUTH_INDEX) {
2194 case IW_AUTH_WPA_VERSION:
2195 if (param->value == IW_AUTH_WPA_VERSION_WPA)
2197 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
2198 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
2199 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
2201 else if (param->value == IW_AUTH_WPA_VERSION_WPA2)
2202 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
2204 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __func__, param->value));
2206 case IW_AUTH_CIPHER_PAIRWISE:
2207 if (param->value == IW_AUTH_CIPHER_NONE)
2209 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
2210 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2211 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
2213 else if (param->value == IW_AUTH_CIPHER_WEP40 ||
2214 param->value == IW_AUTH_CIPHER_WEP104)
2216 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
2217 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2218 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
2219 #ifdef WPA_SUPPLICANT_SUPPORT
2220 pAdapter->StaCfg.IEEE8021X = FALSE;
2221 #endif // WPA_SUPPLICANT_SUPPORT //
2223 else if (param->value == IW_AUTH_CIPHER_TKIP)
2225 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
2226 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2227 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
2229 else if (param->value == IW_AUTH_CIPHER_CCMP)
2231 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
2232 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2233 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
2235 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_PAIRWISE - param->value = %d!\n", __func__, param->value));
2237 case IW_AUTH_CIPHER_GROUP:
2238 if (param->value == IW_AUTH_CIPHER_NONE)
2240 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
2242 else if (param->value == IW_AUTH_CIPHER_WEP40 ||
2243 param->value == IW_AUTH_CIPHER_WEP104)
2245 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
2247 else if (param->value == IW_AUTH_CIPHER_TKIP)
2249 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
2251 else if (param->value == IW_AUTH_CIPHER_CCMP)
2253 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
2255 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_GROUP - param->value = %d!\n", __func__, param->value));
2257 case IW_AUTH_KEY_MGMT:
2258 if (param->value == IW_AUTH_KEY_MGMT_802_1X)
2260 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)
2262 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
2263 #ifdef WPA_SUPPLICANT_SUPPORT
2264 pAdapter->StaCfg.IEEE8021X = FALSE;
2265 #endif // WPA_SUPPLICANT_SUPPORT //
2267 else if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
2269 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
2270 #ifdef WPA_SUPPLICANT_SUPPORT
2271 pAdapter->StaCfg.IEEE8021X = FALSE;
2272 #endif // WPA_SUPPLICANT_SUPPORT //
2274 #ifdef WPA_SUPPLICANT_SUPPORT
2277 pAdapter->StaCfg.IEEE8021X = TRUE;
2278 #endif // WPA_SUPPLICANT_SUPPORT //
2280 else if (param->value == 0)
2282 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2283 STA_PORT_SECURED(pAdapter);
2285 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_KEY_MGMT - param->value = %d!\n", __func__, param->value));
2287 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
2289 case IW_AUTH_PRIVACY_INVOKED:
2290 /*if (param->value == 0)
2292 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
2293 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
2294 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2295 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
2296 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
2298 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_PRIVACY_INVOKED - param->value = %d!\n", __func__, param->value));
2300 case IW_AUTH_DROP_UNENCRYPTED:
2301 if (param->value != 0)
2302 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
2305 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2306 STA_PORT_SECURED(pAdapter);
2308 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __func__, param->value));
2310 case IW_AUTH_80211_AUTH_ALG:
2311 if (param->value & IW_AUTH_ALG_SHARED_KEY)
2313 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
2315 else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
2317 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
2321 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_80211_AUTH_ALG - param->value = %d!\n", __func__, param->value));
2323 case IW_AUTH_WPA_ENABLED:
2324 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_ENABLED - Driver supports WPA!(param->value = %d)\n", __func__, param->value));
2333 int rt_ioctl_giwauth(struct net_device *dev,
2334 struct iw_request_info *info,
2335 union iwreq_data *wrqu, char *extra)
2337 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2338 struct iw_param *param = &wrqu->param;
2340 //check if the interface is down
2341 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2343 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2347 switch (param->flags & IW_AUTH_INDEX) {
2348 case IW_AUTH_DROP_UNENCRYPTED:
2349 param->value = (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled) ? 0 : 1;
2352 case IW_AUTH_80211_AUTH_ALG:
2353 param->value = (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared) ? IW_AUTH_ALG_SHARED_KEY : IW_AUTH_ALG_OPEN_SYSTEM;
2356 case IW_AUTH_WPA_ENABLED:
2357 param->value = (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) ? 1 : 0;
2363 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_giwauth::param->value = %d!\n", param->value));
2367 void fnSetCipherKey(
2368 IN PRTMP_ADAPTER pAdapter,
2372 IN struct iw_encode_ext *ext)
2374 NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
2375 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = LEN_TKIP_EK;
2376 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, LEN_TKIP_EK);
2377 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].TxMic, ext->key + LEN_TKIP_EK, LEN_TKIP_TXMICK);
2378 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].RxMic, ext->key + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
2379 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CipherAlg;
2381 // Update group key information to ASIC Shared Key Table
2382 AsicAddSharedKeyEntry(pAdapter,
2385 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2386 pAdapter->SharedKey[BSS0][keyIdx].Key,
2387 pAdapter->SharedKey[BSS0][keyIdx].TxMic,
2388 pAdapter->SharedKey[BSS0][keyIdx].RxMic);
2391 // Update ASIC WCID attribute table and IVEIV table
2392 RTMPAddWcidAttributeEntry(pAdapter,
2395 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2398 // Update ASIC WCID attribute table and IVEIV table
2399 RTMPAddWcidAttributeEntry(pAdapter,
2402 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2403 &pAdapter->MacTab.Content[BSSID_WCID]);
2406 int rt_ioctl_siwencodeext(struct net_device *dev,
2407 struct iw_request_info *info,
2408 union iwreq_data *wrqu,
2411 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2412 struct iw_point *encoding = &wrqu->encoding;
2413 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2414 int keyIdx, alg = ext->alg;
2416 //check if the interface is down
2417 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2419 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2423 if (encoding->flags & IW_ENCODE_DISABLED)
2425 keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
2426 // set BSSID wcid entry of the Pair-wise Key table as no-security mode
2427 AsicRemovePairwiseKeyEntry(pAdapter, BSS0, BSSID_WCID);
2428 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
2429 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_NONE;
2430 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)keyIdx);
2431 NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
2432 DBGPRINT(RT_DEBUG_TRACE, ("%s::Remove all keys!(encoding->flags = %x)\n", __func__, encoding->flags));
2436 // Get Key Index and convet to our own defined key index
2437 keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
2438 if((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
2441 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2443 pAdapter->StaCfg.DefaultKeyId = keyIdx;
2444 DBGPRINT(RT_DEBUG_TRACE, ("%s::DefaultKeyId = %d\n", __func__, pAdapter->StaCfg.DefaultKeyId));
2448 case IW_ENCODE_ALG_NONE:
2449 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_NONE\n", __func__));
2451 case IW_ENCODE_ALG_WEP:
2452 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_WEP - ext->key_len = %d, keyIdx = %d\n", __func__, ext->key_len, keyIdx));
2453 if (ext->key_len == MAX_WEP_KEY_SIZE)
2455 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
2456 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
2458 else if (ext->key_len == MIN_WEP_KEY_SIZE)
2460 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
2461 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
2466 NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
2467 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, ext->key_len);
2469 if (pAdapter->StaCfg.GroupCipher == Ndis802_11GroupWEP40Enabled ||
2470 pAdapter->StaCfg.GroupCipher == Ndis802_11GroupWEP104Enabled)
2472 // Set Group key material to Asic
2473 AsicAddSharedKeyEntry(pAdapter, BSS0, keyIdx, pAdapter->SharedKey[BSS0][keyIdx].CipherAlg, pAdapter->SharedKey[BSS0][keyIdx].Key, NULL, NULL);
2475 // Update WCID attribute table and IVEIV table for this group key table
2476 RTMPAddWcidAttributeEntry(pAdapter, BSS0, keyIdx, pAdapter->SharedKey[BSS0][keyIdx].CipherAlg, NULL);
2478 STA_PORT_SECURED(pAdapter);
2480 // Indicate Connected for GUI
2481 pAdapter->IndicateMediaState = NdisMediaStateConnected;
2484 case IW_ENCODE_ALG_TKIP:
2485 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_TKIP - keyIdx = %d, ext->key_len = %d\n", __func__, keyIdx, ext->key_len));
2486 if (ext->key_len == 32)
2488 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2490 fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, FALSE, ext);
2491 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
2493 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2494 STA_PORT_SECURED(pAdapter);
2497 else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
2499 fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, TRUE, ext);
2501 // set 802.1x port control
2502 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2503 STA_PORT_SECURED(pAdapter);
2509 case IW_ENCODE_ALG_CCMP:
2510 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2512 fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, FALSE, ext);
2513 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
2514 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2515 STA_PORT_SECURED(pAdapter);
2517 else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
2519 fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, TRUE, ext);
2521 // set 802.1x port control
2522 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2523 STA_PORT_SECURED(pAdapter);
2535 rt_ioctl_giwencodeext(struct net_device *dev,
2536 struct iw_request_info *info,
2537 union iwreq_data *wrqu, char *extra)
2539 PRTMP_ADAPTER pAd = dev->ml_priv;
2541 struct iw_point *encoding = &wrqu->encoding;
2542 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2543 int idx, max_key_len;
2545 DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_giwencodeext\n"));
2547 max_key_len = encoding->length - sizeof(*ext);
2548 if (max_key_len < 0)
2551 idx = encoding->flags & IW_ENCODE_INDEX;
2554 if (idx < 1 || idx > 4)
2558 if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
2559 (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled))
2561 if (idx != pAd->StaCfg.DefaultKeyId)
2569 idx = pAd->StaCfg.DefaultKeyId;
2571 encoding->flags = idx + 1;
2572 memset(ext, 0, sizeof(*ext));
2575 switch(pAd->StaCfg.WepStatus) {
2576 case Ndis802_11WEPDisabled:
2577 ext->alg = IW_ENCODE_ALG_NONE;
2578 encoding->flags |= IW_ENCODE_DISABLED;
2580 case Ndis802_11WEPEnabled:
2581 ext->alg = IW_ENCODE_ALG_WEP;
2582 if (pAd->SharedKey[BSS0][idx].KeyLen > max_key_len)
2586 ext->key_len = pAd->SharedKey[BSS0][idx].KeyLen;
2587 pKey = &(pAd->SharedKey[BSS0][idx].Key[0]);
2590 case Ndis802_11Encryption2Enabled:
2591 case Ndis802_11Encryption3Enabled:
2592 if (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
2593 ext->alg = IW_ENCODE_ALG_TKIP;
2595 ext->alg = IW_ENCODE_ALG_CCMP;
2597 if (max_key_len < 32)
2602 pKey = &pAd->StaCfg.PMK[0];
2609 if (ext->key_len && pKey)
2611 encoding->flags |= IW_ENCODE_ENABLED;
2612 memcpy(ext->key, pKey, ext->key_len);
2619 int rt_ioctl_siwgenie(struct net_device *dev,
2620 struct iw_request_info *info,
2621 union iwreq_data *wrqu, char *extra)
2623 PRTMP_ADAPTER pAd = dev->ml_priv;
2625 if (wrqu->data.length > MAX_LEN_OF_RSNIE ||
2626 (wrqu->data.length && extra == NULL))
2629 if (wrqu->data.length)
2631 pAd->StaCfg.RSNIE_Len = wrqu->data.length;
2632 NdisMoveMemory(&pAd->StaCfg.RSN_IE[0], extra, pAd->StaCfg.RSNIE_Len);
2636 pAd->StaCfg.RSNIE_Len = 0;
2637 NdisZeroMemory(&pAd->StaCfg.RSN_IE[0], MAX_LEN_OF_RSNIE);
2642 #endif // SIOCSIWGENIE //
2644 int rt_ioctl_giwgenie(struct net_device *dev,
2645 struct iw_request_info *info,
2646 union iwreq_data *wrqu, char *extra)
2648 PRTMP_ADAPTER pAd = dev->ml_priv;
2650 if ((pAd->StaCfg.RSNIE_Len == 0) ||
2651 (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA))
2653 wrqu->data.length = 0;
2658 if (pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
2660 if (wrqu->data.length < pAd->StaCfg.RSNIE_Len)
2663 wrqu->data.length = pAd->StaCfg.RSNIE_Len;
2664 memcpy(extra, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
2667 #endif // SIOCSIWGENIE //
2669 UCHAR RSNIe = IE_WPA;
2671 if (wrqu->data.length < (pAd->StaCfg.RSNIE_Len + 2)) // ID, Len
2673 wrqu->data.length = pAd->StaCfg.RSNIE_Len + 2;
2675 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
2676 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2))
2679 extra[0] = (char)RSNIe;
2680 extra[1] = pAd->StaCfg.RSNIE_Len;
2681 memcpy(extra+2, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
2687 int rt_ioctl_siwpmksa(struct net_device *dev,
2688 struct iw_request_info *info,
2689 union iwreq_data *wrqu,
2692 PRTMP_ADAPTER pAd = dev->ml_priv;
2693 struct iw_pmksa *pPmksa = (struct iw_pmksa *)wrqu->data.pointer;
2694 INT CachedIdx = 0, idx = 0;
2699 DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_siwpmksa\n"));
2702 case IW_PMKSA_FLUSH:
2703 NdisZeroMemory(pAd->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
2704 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_FLUSH\n"));
2706 case IW_PMKSA_REMOVE:
2707 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
2709 // compare the BSSID
2710 if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
2712 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN);
2713 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].PMKID, 16);
2714 for (idx = CachedIdx; idx < (pAd->StaCfg.SavedPMKNum - 1); idx++)
2716 NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].BSSID[0], &pAd->StaCfg.SavedPMK[idx+1].BSSID[0], MAC_ADDR_LEN);
2717 NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].PMKID[0], &pAd->StaCfg.SavedPMK[idx+1].PMKID[0], 16);
2719 pAd->StaCfg.SavedPMKNum--;
2724 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_REMOVE\n"));
2727 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
2729 // compare the BSSID
2730 if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
2734 // Found, replace it
2735 if (CachedIdx < PMKID_NO)
2737 DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
2738 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
2739 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
2740 pAd->StaCfg.SavedPMKNum++;
2742 // Not found, replace the last one
2745 // Randomly replace one
2746 CachedIdx = (pPmksa->bssid.sa_data[5] % PMKID_NO);
2747 DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
2748 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
2749 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
2752 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_ADD\n"));
2755 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - Unknow Command!!\n"));
2761 #endif // #if WIRELESS_EXT > 17
2765 rt_private_ioctl_bbp(struct net_device *dev, struct iw_request_info *info,
2766 struct iw_point *wrq, char *extra)
2771 // CHAR arg[255]={0};
2774 BOOLEAN bIsPrintAllBBP = FALSE;
2776 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2779 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2781 if (wrq->length > 1) //No parameters.
2783 sprintf(extra, "\n");
2785 //Parsing Read or Write
2786 this_char = wrq->pointer;
2787 DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s\n", this_char));
2791 if ((value = rtstrchr(this_char, '=')) != NULL)
2794 if (!value || !*value)
2796 DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s, value=%s\n", this_char, value));
2797 if (sscanf(this_char, "%d", &(bbpId)) == 1)
2802 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
2804 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
2805 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2806 DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
2809 {//Invalid parametes, so default printk all bbp
2810 bIsPrintAllBBP = TRUE;
2815 { //Invalid parametes, so default printk all bbp
2816 bIsPrintAllBBP = TRUE;
2822 if ((sscanf(this_char, "%d", &(bbpId)) == 1) && (sscanf(value, "%x", &(bbpValue)) == 1))
2827 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, bbpId, bbpValue);
2828 //Read it back for showing
2829 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
2831 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
2832 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2833 DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
2836 {//Invalid parametes, so default printk all bbp
2837 bIsPrintAllBBP = TRUE;
2842 { //Invalid parametes, so default printk all bbp
2843 bIsPrintAllBBP = TRUE;
2849 bIsPrintAllBBP = TRUE;
2854 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2855 sprintf(extra, "\n");
2856 for (bbpId = 0; bbpId <= 136; bbpId++)
2858 if (strlen(extra) >= (IW_PRIV_SIZE_MASK - 10))
2860 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
2861 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X ", bbpId, bbpId*2, regBBP);
2863 sprintf(extra+strlen(extra), "\n");
2866 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2867 DBGPRINT(RT_DEBUG_TRACE, ("wrq->length = %d\n", wrq->length));
2870 DBGPRINT(RT_DEBUG_TRACE, ("<==rt_private_ioctl_bbp\n\n"));
2876 int rt_ioctl_siwrate(struct net_device *dev,
2877 struct iw_request_info *info,
2878 union iwreq_data *wrqu, char *extra)
2880 PRTMP_ADAPTER pAd = dev->ml_priv;
2881 UINT32 rate = wrqu->bitrate.value, fixed = wrqu->bitrate.fixed;
2883 //check if the interface is down
2884 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2886 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::Network is down!\n"));
2890 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(rate = %d, fixed = %d)\n", rate, fixed));
2891 /* rate = -1 => auto rate
2892 rate = X, fixed = 1 => (fixed rate X)
2897 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
2898 pAd->StaCfg.bAutoTxRateSwitch = TRUE;
2899 if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
2900 (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
2901 RTMPSetDesiredRates(pAd, -1);
2903 #ifdef DOT11_N_SUPPORT
2905 #endif // DOT11_N_SUPPORT //
2911 pAd->StaCfg.bAutoTxRateSwitch = FALSE;
2912 if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
2913 (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
2914 RTMPSetDesiredRates(pAd, rate);
2917 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
2918 #ifdef DOT11_N_SUPPORT
2920 #endif // DOT11_N_SUPPORT //
2922 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(HtMcs=%d)\n",pAd->StaCfg.DesiredTransmitSetting.field.MCS));
2926 // TODO: rate = X, fixed = 0 => (rates <= X)
2934 int rt_ioctl_giwrate(struct net_device *dev,
2935 struct iw_request_info *info,
2936 union iwreq_data *wrqu, char *extra)
2938 PRTMP_ADAPTER pAd = dev->ml_priv;
2939 int rate_index = 0, rate_count = 0;
2940 HTTRANSMIT_SETTING ht_setting;
2941 __s32 ralinkrate[] =
2942 {2, 4, 11, 22, // CCK
2943 12, 18, 24, 36, 48, 72, 96, 108, // OFDM
2944 13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260, // 20MHz, 800ns GI, MCS: 0 ~ 15
2945 39, 78, 117, 156, 234, 312, 351, 390, // 20MHz, 800ns GI, MCS: 16 ~ 23
2946 27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540, // 40MHz, 800ns GI, MCS: 0 ~ 15
2947 81, 162, 243, 324, 486, 648, 729, 810, // 40MHz, 800ns GI, MCS: 16 ~ 23
2948 14, 29, 43, 57, 87, 115, 130, 144, 29, 59, 87, 115, 173, 230, 260, 288, // 20MHz, 400ns GI, MCS: 0 ~ 15
2949 43, 87, 130, 173, 260, 317, 390, 433, // 20MHz, 400ns GI, MCS: 16 ~ 23
2950 30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600, // 40MHz, 400ns GI, MCS: 0 ~ 15
2951 90, 180, 270, 360, 540, 720, 810, 900}; // 40MHz, 400ns GI, MCS: 16 ~ 23
2953 rate_count = sizeof(ralinkrate)/sizeof(__s32);
2954 //check if the interface is down
2955 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2957 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2961 if ((pAd->StaCfg.bAutoTxRateSwitch == FALSE) &&
2963 ((pAd->CommonCfg.PhyMode <= PHY_11G) || (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM)))
2964 ht_setting.word = pAd->StaCfg.HTPhyMode.word;
2966 ht_setting.word = pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word;
2968 #ifdef DOT11_N_SUPPORT
2969 if (ht_setting.field.MODE >= MODE_HTMIX)
2971 // rate_index = 12 + ((UCHAR)ht_setting.field.BW *16) + ((UCHAR)ht_setting.field.ShortGI *32) + ((UCHAR)ht_setting.field.MCS);
2972 rate_index = 12 + ((UCHAR)ht_setting.field.BW *24) + ((UCHAR)ht_setting.field.ShortGI *48) + ((UCHAR)ht_setting.field.MCS);
2975 #endif // DOT11_N_SUPPORT //
2976 if (ht_setting.field.MODE == MODE_OFDM)
2977 rate_index = (UCHAR)(ht_setting.field.MCS) + 4;
2978 else if (ht_setting.field.MODE == MODE_CCK)
2979 rate_index = (UCHAR)(ht_setting.field.MCS);
2984 if (rate_index > rate_count)
2985 rate_index = rate_count;
2987 wrqu->bitrate.value = ralinkrate[rate_index] * 500000;
2988 wrqu->bitrate.disabled = 0;
2993 static const iw_handler rt_handler[] =
2995 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2996 (iw_handler) rt_ioctl_giwname, /* SIOCGIWNAME */
2997 (iw_handler) NULL, /* SIOCSIWNWID */
2998 (iw_handler) NULL, /* SIOCGIWNWID */
2999 (iw_handler) rt_ioctl_siwfreq, /* SIOCSIWFREQ */
3000 (iw_handler) rt_ioctl_giwfreq, /* SIOCGIWFREQ */
3001 (iw_handler) rt_ioctl_siwmode, /* SIOCSIWMODE */
3002 (iw_handler) rt_ioctl_giwmode, /* SIOCGIWMODE */
3003 (iw_handler) NULL, /* SIOCSIWSENS */
3004 (iw_handler) NULL, /* SIOCGIWSENS */
3005 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
3006 (iw_handler) rt_ioctl_giwrange, /* SIOCGIWRANGE */
3007 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
3008 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
3009 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
3010 (iw_handler) rt28xx_get_wireless_stats /* kernel code */, /* SIOCGIWSTATS */
3011 (iw_handler) NULL, /* SIOCSIWSPY */
3012 (iw_handler) NULL, /* SIOCGIWSPY */
3013 (iw_handler) NULL, /* SIOCSIWTHRSPY */
3014 (iw_handler) NULL, /* SIOCGIWTHRSPY */
3015 (iw_handler) rt_ioctl_siwap, /* SIOCSIWAP */
3016 (iw_handler) rt_ioctl_giwap, /* SIOCGIWAP */
3018 (iw_handler) rt_ioctl_siwmlme, /* SIOCSIWMLME */
3020 (iw_handler) NULL, /* SIOCSIWMLME */
3021 #endif // SIOCSIWMLME //
3022 (iw_handler) rt_ioctl_iwaplist, /* SIOCGIWAPLIST */
3024 (iw_handler) rt_ioctl_siwscan, /* SIOCSIWSCAN */
3025 (iw_handler) rt_ioctl_giwscan, /* SIOCGIWSCAN */
3027 (iw_handler) NULL, /* SIOCSIWSCAN */
3028 (iw_handler) NULL, /* SIOCGIWSCAN */
3029 #endif /* SIOCGIWSCAN */
3030 (iw_handler) rt_ioctl_siwessid, /* SIOCSIWESSID */
3031 (iw_handler) rt_ioctl_giwessid, /* SIOCGIWESSID */
3032 (iw_handler) rt_ioctl_siwnickn, /* SIOCSIWNICKN */
3033 (iw_handler) rt_ioctl_giwnickn, /* SIOCGIWNICKN */
3034 (iw_handler) NULL, /* -- hole -- */
3035 (iw_handler) NULL, /* -- hole -- */
3036 (iw_handler) rt_ioctl_siwrate, /* SIOCSIWRATE */
3037 (iw_handler) rt_ioctl_giwrate, /* SIOCGIWRATE */
3038 (iw_handler) rt_ioctl_siwrts, /* SIOCSIWRTS */
3039 (iw_handler) rt_ioctl_giwrts, /* SIOCGIWRTS */
3040 (iw_handler) rt_ioctl_siwfrag, /* SIOCSIWFRAG */
3041 (iw_handler) rt_ioctl_giwfrag, /* SIOCGIWFRAG */
3042 (iw_handler) NULL, /* SIOCSIWTXPOW */
3043 (iw_handler) NULL, /* SIOCGIWTXPOW */
3044 (iw_handler) NULL, /* SIOCSIWRETRY */
3045 (iw_handler) NULL, /* SIOCGIWRETRY */
3046 (iw_handler) rt_ioctl_siwencode, /* SIOCSIWENCODE */
3047 (iw_handler) rt_ioctl_giwencode, /* SIOCGIWENCODE */
3048 (iw_handler) NULL, /* SIOCSIWPOWER */
3049 (iw_handler) NULL, /* SIOCGIWPOWER */
3050 (iw_handler) NULL, /* -- hole -- */
3051 (iw_handler) NULL, /* -- hole -- */
3052 #if WIRELESS_EXT > 17
3053 (iw_handler) rt_ioctl_siwgenie, /* SIOCSIWGENIE */
3054 (iw_handler) rt_ioctl_giwgenie, /* SIOCGIWGENIE */
3055 (iw_handler) rt_ioctl_siwauth, /* SIOCSIWAUTH */
3056 (iw_handler) rt_ioctl_giwauth, /* SIOCGIWAUTH */
3057 (iw_handler) rt_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
3058 (iw_handler) rt_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */
3059 (iw_handler) rt_ioctl_siwpmksa, /* SIOCSIWPMKSA */
3063 static const iw_handler rt_priv_handlers[] = {
3064 (iw_handler) NULL, /* + 0x00 */
3065 (iw_handler) NULL, /* + 0x01 */
3066 #ifndef CONFIG_AP_SUPPORT
3067 (iw_handler) rt_ioctl_setparam, /* + 0x02 */
3069 (iw_handler) NULL, /* + 0x02 */
3070 #endif // CONFIG_AP_SUPPORT //
3072 (iw_handler) rt_private_ioctl_bbp, /* + 0x03 */
3074 (iw_handler) NULL, /* + 0x03 */
3076 (iw_handler) NULL, /* + 0x04 */
3077 (iw_handler) NULL, /* + 0x05 */
3078 (iw_handler) NULL, /* + 0x06 */
3079 (iw_handler) NULL, /* + 0x07 */
3080 (iw_handler) NULL, /* + 0x08 */
3081 (iw_handler) rt_private_get_statistics, /* + 0x09 */
3082 (iw_handler) NULL, /* + 0x0A */
3083 (iw_handler) NULL, /* + 0x0B */
3084 (iw_handler) NULL, /* + 0x0C */
3085 (iw_handler) NULL, /* + 0x0D */
3086 (iw_handler) NULL, /* + 0x0E */
3087 (iw_handler) NULL, /* + 0x0F */
3088 (iw_handler) NULL, /* + 0x10 */
3089 (iw_handler) rt_private_show, /* + 0x11 */
3090 (iw_handler) NULL, /* + 0x12 */
3091 (iw_handler) NULL, /* + 0x13 */
3092 (iw_handler) NULL, /* + 0x15 */
3093 (iw_handler) NULL, /* + 0x17 */
3094 (iw_handler) NULL, /* + 0x18 */
3097 const struct iw_handler_def rt28xx_iw_handler_def =
3099 #define N(a) (sizeof (a) / sizeof (a[0]))
3100 .standard = (iw_handler *) rt_handler,
3101 .num_standard = sizeof(rt_handler) / sizeof(iw_handler),
3102 .private = (iw_handler *) rt_priv_handlers,
3103 .num_private = N(rt_priv_handlers),
3104 .private_args = (struct iw_priv_args *) privtab,
3105 .num_private_args = N(privtab),
3106 #if IW_HANDLER_VERSION >= 7
3107 .get_wireless_stats = rt28xx_get_wireless_stats,
3111 INT RTMPSetInformation(
3112 IN PRTMP_ADAPTER pAdapter,
3113 IN OUT struct ifreq *rq,
3116 struct iwreq *wrq = (struct iwreq *) rq;
3117 NDIS_802_11_SSID Ssid;
3118 NDIS_802_11_MAC_ADDRESS Bssid;
3119 RT_802_11_PHY_MODE PhyMode;
3120 RT_802_11_STA_CONFIG StaConfig;
3121 NDIS_802_11_RATES aryRates;
3122 RT_802_11_PREAMBLE Preamble;
3123 NDIS_802_11_WEP_STATUS WepStatus;
3124 NDIS_802_11_AUTHENTICATION_MODE AuthMode = Ndis802_11AuthModeMax;
3125 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
3126 NDIS_802_11_RTS_THRESHOLD RtsThresh;
3127 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
3128 NDIS_802_11_POWER_MODE PowerMode;
3129 PNDIS_802_11_KEY pKey = NULL;
3130 PNDIS_802_11_WEP pWepKey =NULL;
3131 PNDIS_802_11_REMOVE_KEY pRemoveKey = NULL;
3132 NDIS_802_11_CONFIGURATION Config, *pConfig = NULL;
3133 NDIS_802_11_NETWORK_TYPE NetType;
3136 INT Status = NDIS_STATUS_SUCCESS, MaxPhyMode = PHY_11G;
3139 BOOLEAN StateMachineTouched = FALSE;
3140 #ifdef DOT11_N_SUPPORT
3141 OID_SET_HT_PHYMODE HT_PhyMode; //11n ,kathy
3142 #endif // DOT11_N_SUPPORT //
3143 #ifdef WPA_SUPPLICANT_SUPPORT
3144 PNDIS_802_11_PMKID pPmkId = NULL;
3145 BOOLEAN IEEE8021xState = FALSE;
3146 BOOLEAN IEEE8021x_required_keys = FALSE;
3147 UCHAR wpa_supplicant_enable = 0;
3148 #endif // WPA_SUPPLICANT_SUPPORT //
3150 #ifdef DOT11_N_SUPPORT
3151 MaxPhyMode = PHY_11N_5G;
3152 #endif // DOT11_N_SUPPORT //
3155 DBGPRINT(RT_DEBUG_TRACE, ("-->RTMPSetInformation(), 0x%08x\n", cmd&0x7FFF));
3156 switch(cmd & 0x7FFF) {
3157 case RT_OID_802_11_COUNTRY_REGION:
3158 if (wrq->u.data.length < sizeof(UCHAR))
3160 // Only avaliable when EEPROM not programming
3161 else if (!(pAdapter->CommonCfg.CountryRegion & 0x80) && !(pAdapter->CommonCfg.CountryRegionForABand & 0x80))
3166 Status = copy_from_user(&Country, wrq->u.data.pointer, wrq->u.data.length);
3167 pAdapter->CommonCfg.CountryRegion = (UCHAR)(Country & 0x000000FF);
3168 pAdapter->CommonCfg.CountryRegionForABand = (UCHAR)((Country >> 8) & 0x000000FF);
3169 TmpPhy = pAdapter->CommonCfg.PhyMode;
3170 pAdapter->CommonCfg.PhyMode = 0xff;
3171 // Build all corresponding channel information
3172 RTMPSetPhyMode(pAdapter, TmpPhy);
3173 #ifdef DOT11_N_SUPPORT
3174 SetCommonHT(pAdapter);
3175 #endif // DOT11_N_SUPPORT //
3176 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_COUNTRY_REGION (A:%d B/G:%d)\n", pAdapter->CommonCfg.CountryRegionForABand,
3177 pAdapter->CommonCfg.CountryRegion));
3180 case OID_802_11_BSSID_LIST_SCAN:
3182 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID_LIST_SCAN, TxCnt = %d \n", pAdapter->RalinkCounters.LastOneSecTotalTxCount));
3184 if (MONITOR_ON(pAdapter))
3186 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
3190 //Benson add 20080527, when radio off, sta don't need to scan
3191 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_RADIO_OFF))
3194 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
3196 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is scanning now !!!\n"));
3197 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
3198 Status = NDIS_STATUS_SUCCESS;
3202 if (pAdapter->RalinkCounters.LastOneSecTotalTxCount > 100)
3204 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
3205 Status = NDIS_STATUS_SUCCESS;
3206 pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
3210 if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
3211 ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
3212 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
3213 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
3214 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)) &&
3215 (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
3217 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
3218 Status = NDIS_STATUS_SUCCESS;
3219 pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
3224 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3226 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3227 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3230 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
3231 // this request, because this request is initiated by NDIS.
3232 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
3233 // Reset allowed scan retries
3234 pAdapter->StaCfg.ScanCnt = 0;
3235 pAdapter->StaCfg.LastScanTime = Now;
3237 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
3238 RTMP_SET_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
3239 MlmeEnqueue(pAdapter,
3240 MLME_CNTL_STATE_MACHINE,
3241 OID_802_11_BSSID_LIST_SCAN,
3245 Status = NDIS_STATUS_SUCCESS;
3246 StateMachineTouched = TRUE;
3248 case OID_802_11_SSID:
3249 if (wrq->u.data.length != sizeof(NDIS_802_11_SSID))
3253 PCHAR pSsidString = NULL;
3254 Status = copy_from_user(&Ssid, wrq->u.data.pointer, wrq->u.data.length);
3256 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SSID (Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
3257 if (Ssid.SsidLength > MAX_LEN_OF_SSID)
3261 if (Ssid.SsidLength == 0)
3263 Set_SSID_Proc(pAdapter, "");
3267 pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
3270 NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
3271 NdisMoveMemory(pSsidString, Ssid.Ssid, Ssid.SsidLength);
3272 Set_SSID_Proc(pAdapter, pSsidString);
3281 case OID_802_11_BSSID:
3282 if (wrq->u.data.length != sizeof(NDIS_802_11_MAC_ADDRESS))
3286 Status = copy_from_user(&Bssid, wrq->u.data.pointer, wrq->u.data.length);
3288 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
3289 // this request, because this request is initiated by NDIS.
3290 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
3292 // Prevent to connect AP again in STAMlmePeriodicExec
3293 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
3295 // Reset allowed scan retries
3296 pAdapter->StaCfg.ScanCnt = 0;
3298 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3300 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3301 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3303 MlmeEnqueue(pAdapter,
3304 MLME_CNTL_STATE_MACHINE,
3306 sizeof(NDIS_802_11_MAC_ADDRESS),
3308 Status = NDIS_STATUS_SUCCESS;
3309 StateMachineTouched = TRUE;
3311 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID %02x:%02x:%02x:%02x:%02x:%02x\n",
3312 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
3315 case RT_OID_802_11_RADIO:
3316 if (wrq->u.data.length != sizeof(BOOLEAN))
3320 Status = copy_from_user(&RadioState, wrq->u.data.pointer, wrq->u.data.length);
3321 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RADIO (=%d)\n", RadioState));
3322 if (pAdapter->StaCfg.bSwRadio != RadioState)
3324 pAdapter->StaCfg.bSwRadio = RadioState;
3325 if (pAdapter->StaCfg.bRadio != (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio))
3327 pAdapter->StaCfg.bRadio = (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio);
3328 if (pAdapter->StaCfg.bRadio == TRUE)
3330 MlmeRadioOn(pAdapter);
3331 // Update extra information
3332 pAdapter->ExtraInfo = EXTRA_INFO_CLEAR;
3336 MlmeRadioOff(pAdapter);
3337 // Update extra information
3338 pAdapter->ExtraInfo = SW_RADIO_OFF;
3344 case RT_OID_802_11_PHY_MODE:
3345 if (wrq->u.data.length != sizeof(RT_802_11_PHY_MODE))
3349 Status = copy_from_user(&PhyMode, wrq->u.data.pointer, wrq->u.data.length);
3350 if (PhyMode <= MaxPhyMode)
3352 RTMPSetPhyMode(pAdapter, PhyMode);
3353 #ifdef DOT11_N_SUPPORT
3354 SetCommonHT(pAdapter);
3355 #endif // DOT11_N_SUPPORT //
3357 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PHY_MODE (=%d)\n", PhyMode));
3360 case RT_OID_802_11_STA_CONFIG:
3361 if (wrq->u.data.length != sizeof(RT_802_11_STA_CONFIG))
3365 Status = copy_from_user(&StaConfig, wrq->u.data.pointer, wrq->u.data.length);
3366 pAdapter->CommonCfg.bEnableTxBurst = StaConfig.EnableTxBurst;
3367 pAdapter->CommonCfg.UseBGProtection = StaConfig.UseBGProtection;
3368 pAdapter->CommonCfg.bUseShortSlotTime = 1; // 2003-10-30 always SHORT SLOT capable
3369 if ((pAdapter->CommonCfg.PhyMode != StaConfig.AdhocMode) &&
3370 (StaConfig.AdhocMode <= MaxPhyMode))
3372 // allow dynamic change of "USE OFDM rate or not" in ADHOC mode
3373 // if setting changed, need to reset current TX rate as well as BEACON frame format
3374 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
3376 pAdapter->CommonCfg.PhyMode = StaConfig.AdhocMode;
3377 RTMPSetPhyMode(pAdapter, PhyMode);
3378 MlmeUpdateTxRates(pAdapter, FALSE, 0);
3379 MakeIbssBeacon(pAdapter); // re-build BEACON frame
3380 AsicEnableIbssSync(pAdapter); // copy to on-chip memory
3383 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_STA_CONFIG (Burst=%d, Protection=%ld,ShortSlot=%d\n",
3384 pAdapter->CommonCfg.bEnableTxBurst,
3385 pAdapter->CommonCfg.UseBGProtection,
3386 pAdapter->CommonCfg.bUseShortSlotTime));
3389 case OID_802_11_DESIRED_RATES:
3390 if (wrq->u.data.length != sizeof(NDIS_802_11_RATES))
3394 Status = copy_from_user(&aryRates, wrq->u.data.pointer, wrq->u.data.length);
3395 NdisZeroMemory(pAdapter->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES);
3396 NdisMoveMemory(pAdapter->CommonCfg.DesireRate, &aryRates, sizeof(NDIS_802_11_RATES));
3397 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DESIRED_RATES (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
3398 pAdapter->CommonCfg.DesireRate[0],pAdapter->CommonCfg.DesireRate[1],
3399 pAdapter->CommonCfg.DesireRate[2],pAdapter->CommonCfg.DesireRate[3],
3400 pAdapter->CommonCfg.DesireRate[4],pAdapter->CommonCfg.DesireRate[5],
3401 pAdapter->CommonCfg.DesireRate[6],pAdapter->CommonCfg.DesireRate[7] ));
3402 // Changing DesiredRate may affect the MAX TX rate we used to TX frames out
3403 MlmeUpdateTxRates(pAdapter, FALSE, 0);
3406 case RT_OID_802_11_PREAMBLE:
3407 if (wrq->u.data.length != sizeof(RT_802_11_PREAMBLE))
3411 Status = copy_from_user(&Preamble, wrq->u.data.pointer, wrq->u.data.length);
3412 if (Preamble == Rt802_11PreambleShort)
3414 pAdapter->CommonCfg.TxPreamble = Preamble;
3415 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleShort);
3417 else if ((Preamble == Rt802_11PreambleLong) || (Preamble == Rt802_11PreambleAuto))
3419 // if user wants AUTO, initialize to LONG here, then change according to AP's
3420 // capability upon association.
3421 pAdapter->CommonCfg.TxPreamble = Preamble;
3422 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleLong);
3429 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PREAMBLE (=%d)\n", Preamble));
3432 case OID_802_11_WEP_STATUS:
3433 if (wrq->u.data.length != sizeof(NDIS_802_11_WEP_STATUS))
3437 Status = copy_from_user(&WepStatus, wrq->u.data.pointer, wrq->u.data.length);
3438 // Since TKIP, AES, WEP are all supported. It should not have any invalid setting
3439 if (WepStatus <= Ndis802_11Encryption3KeyAbsent)
3441 if (pAdapter->StaCfg.WepStatus != WepStatus)
3443 // Config has changed
3444 pAdapter->bConfigChanged = TRUE;
3446 pAdapter->StaCfg.WepStatus = WepStatus;
3447 pAdapter->StaCfg.OrigWepStatus = WepStatus;
3448 pAdapter->StaCfg.PairCipher = WepStatus;
3449 pAdapter->StaCfg.GroupCipher = WepStatus;
3456 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEP_STATUS (=%d)\n",WepStatus));
3459 case OID_802_11_AUTHENTICATION_MODE:
3460 if (wrq->u.data.length != sizeof(NDIS_802_11_AUTHENTICATION_MODE))
3464 Status = copy_from_user(&AuthMode, wrq->u.data.pointer, wrq->u.data.length);
3465 if (AuthMode > Ndis802_11AuthModeMax)
3472 if (pAdapter->StaCfg.AuthMode != AuthMode)
3474 // Config has changed
3475 pAdapter->bConfigChanged = TRUE;
3477 pAdapter->StaCfg.AuthMode = AuthMode;
3479 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
3480 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_AUTHENTICATION_MODE (=%d) \n",pAdapter->StaCfg.AuthMode));
3483 case OID_802_11_INFRASTRUCTURE_MODE:
3484 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_INFRASTRUCTURE))
3488 Status = copy_from_user(&BssType, wrq->u.data.pointer, wrq->u.data.length);
3490 if (BssType == Ndis802_11IBSS)
3491 Set_NetworkType_Proc(pAdapter, "Adhoc");
3492 else if (BssType == Ndis802_11Infrastructure)
3493 Set_NetworkType_Proc(pAdapter, "Infra");
3494 else if (BssType == Ndis802_11Monitor)
3495 Set_NetworkType_Proc(pAdapter, "Monitor");
3499 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_INFRASTRUCTURE_MODE (unknown)\n"));
3503 case OID_802_11_REMOVE_WEP:
3504 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_WEP\n"));
3505 if (wrq->u.data.length != sizeof(NDIS_802_11_KEY_INDEX))
3511 KeyIdx = *(NDIS_802_11_KEY_INDEX *) wrq->u.data.pointer;
3513 if (KeyIdx & 0x80000000)
3515 // Should never set default bit when remove key
3520 KeyIdx = KeyIdx & 0x0fffffff;
3526 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
3527 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
3528 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
3533 case RT_OID_802_11_RESET_COUNTERS:
3534 NdisZeroMemory(&pAdapter->WlanCounters, sizeof(COUNTER_802_11));
3535 NdisZeroMemory(&pAdapter->Counters8023, sizeof(COUNTER_802_3));
3536 NdisZeroMemory(&pAdapter->RalinkCounters, sizeof(COUNTER_RALINK));
3537 pAdapter->Counters8023.RxNoBuffer = 0;
3538 pAdapter->Counters8023.GoodReceives = 0;
3539 pAdapter->Counters8023.RxNoBuffer = 0;
3541 pAdapter->BulkOutComplete = 0;
3542 pAdapter->BulkOutCompleteOther= 0;
3543 pAdapter->BulkOutCompleteCancel = 0;
3544 pAdapter->BulkOutReq = 0;
3545 pAdapter->BulkInReq= 0;
3546 pAdapter->BulkInComplete = 0;
3547 pAdapter->BulkInCompleteFail = 0;
3549 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RESET_COUNTERS \n"));
3551 case OID_802_11_RTS_THRESHOLD:
3552 if (wrq->u.data.length != sizeof(NDIS_802_11_RTS_THRESHOLD))
3556 Status = copy_from_user(&RtsThresh, wrq->u.data.pointer, wrq->u.data.length);
3557 if (RtsThresh > MAX_RTS_THRESHOLD)
3560 pAdapter->CommonCfg.RtsThreshold = (USHORT)RtsThresh;
3562 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_RTS_THRESHOLD (=%ld)\n",RtsThresh));
3564 case OID_802_11_FRAGMENTATION_THRESHOLD:
3565 if (wrq->u.data.length != sizeof(NDIS_802_11_FRAGMENTATION_THRESHOLD))
3569 Status = copy_from_user(&FragThresh, wrq->u.data.pointer, wrq->u.data.length);
3570 pAdapter->CommonCfg.bUseZeroToDisableFragment = FALSE;
3571 if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
3573 if (FragThresh == 0)
3575 pAdapter->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
3576 pAdapter->CommonCfg.bUseZeroToDisableFragment = TRUE;
3582 pAdapter->CommonCfg.FragmentThreshold = (USHORT)FragThresh;
3584 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_FRAGMENTATION_THRESHOLD (=%ld) \n",FragThresh));
3586 case OID_802_11_POWER_MODE:
3587 if (wrq->u.data.length != sizeof(NDIS_802_11_POWER_MODE))
3591 Status = copy_from_user(&PowerMode, wrq->u.data.pointer, wrq->u.data.length);
3592 if (PowerMode == Ndis802_11PowerModeCAM)
3593 Set_PSMode_Proc(pAdapter, "CAM");
3594 else if (PowerMode == Ndis802_11PowerModeMAX_PSP)
3595 Set_PSMode_Proc(pAdapter, "Max_PSP");
3596 else if (PowerMode == Ndis802_11PowerModeFast_PSP)
3597 Set_PSMode_Proc(pAdapter, "Fast_PSP");
3598 else if (PowerMode == Ndis802_11PowerModeLegacy_PSP)
3599 Set_PSMode_Proc(pAdapter, "Legacy_PSP");
3603 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_POWER_MODE (=%d)\n",PowerMode));
3605 case RT_OID_802_11_TX_POWER_LEVEL_1:
3606 if (wrq->u.data.length < sizeof(ULONG))
3610 Status = copy_from_user(&PowerTemp, wrq->u.data.pointer, wrq->u.data.length);
3611 if (PowerTemp > 100)
3612 PowerTemp = 0xffffffff; // AUTO
3613 pAdapter->CommonCfg.TxPowerDefault = PowerTemp; //keep current setting.
3614 pAdapter->CommonCfg.TxPowerPercentage = pAdapter->CommonCfg.TxPowerDefault;
3615 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
3618 case OID_802_11_NETWORK_TYPE_IN_USE:
3619 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_TYPE))
3623 Status = copy_from_user(&NetType, wrq->u.data.pointer, wrq->u.data.length);
3625 if (NetType == Ndis802_11DS)
3626 RTMPSetPhyMode(pAdapter, PHY_11B);
3627 else if (NetType == Ndis802_11OFDM24)
3628 RTMPSetPhyMode(pAdapter, PHY_11BG_MIXED);
3629 else if (NetType == Ndis802_11OFDM5)
3630 RTMPSetPhyMode(pAdapter, PHY_11A);
3633 #ifdef DOT11_N_SUPPORT
3634 if (Status == NDIS_STATUS_SUCCESS)
3635 SetCommonHT(pAdapter);
3636 #endif // DOT11_N_SUPPORT //
3637 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_NETWORK_TYPE_IN_USE (=%d)\n",NetType));
3640 // For WPA PSK PMK key
3641 case RT_OID_802_11_ADD_WPA:
3642 pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3649 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
3650 if (pKey->Length != wrq->u.data.length)
3653 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!!\n"));
3657 if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
3658 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
3659 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone) )
3661 Status = -EOPNOTSUPP;
3662 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!! [AuthMode != WPAPSK/WPA2PSK/WPANONE]\n"));
3664 else if ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
3665 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
3666 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) ) // Only for WPA PSK mode
3668 NdisMoveMemory(pAdapter->StaCfg.PMK, &pKey->KeyMaterial, pKey->KeyLength);
3669 // Use RaConfig as PSK agent.
3670 // Start STA supplicant state machine
3671 if (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
3672 pAdapter->StaCfg.WpaState = SS_START;
3674 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3678 pAdapter->StaCfg.WpaState = SS_NOTUSE;
3679 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3684 case OID_802_11_REMOVE_KEY:
3685 pRemoveKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3686 if(pRemoveKey == NULL)
3692 Status = copy_from_user(pRemoveKey, wrq->u.data.pointer, wrq->u.data.length);
3693 if (pRemoveKey->Length != wrq->u.data.length)
3696 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!\n"));
3700 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3702 RTMPWPARemoveKeyProc(pAdapter, pRemoveKey);
3703 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Remove WPA Key!!\n"));
3707 KeyIdx = pRemoveKey->KeyIndex;
3709 if (KeyIdx & 0x80000000)
3711 // Should never set default bit when remove key
3713 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(Should never set default bit when remove key)\n"));
3717 KeyIdx = KeyIdx & 0x0fffffff;
3721 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(KeyId[%d] out of range)\n", KeyIdx));
3725 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
3726 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
3727 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
3728 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY (id=0x%x, Len=%d-byte)\n", pRemoveKey->KeyIndex, pRemoveKey->Length));
3736 case OID_802_11_ADD_KEY:
3737 pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3743 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
3744 if (pKey->Length != wrq->u.data.length)
3747 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY, Failed!!\n"));
3751 RTMPAddKey(pAdapter, pKey);
3752 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3756 case OID_802_11_CONFIGURATION:
3757 if (wrq->u.data.length != sizeof(NDIS_802_11_CONFIGURATION))
3761 Status = copy_from_user(&Config, wrq->u.data.pointer, wrq->u.data.length);
3764 if ((pConfig->BeaconPeriod >= 20) && (pConfig->BeaconPeriod <=400))
3765 pAdapter->CommonCfg.BeaconPeriod = (USHORT) pConfig->BeaconPeriod;
3767 pAdapter->StaActive.AtimWin = (USHORT) pConfig->ATIMWindow;
3768 MAP_KHZ_TO_CHANNEL_ID(pConfig->DSConfig, pAdapter->CommonCfg.Channel);
3770 // Save the channel on MlmeAux for CntlOidRTBssidProc used.
3772 pAdapter->MlmeAux.Channel = pAdapter->CommonCfg.Channel;
3774 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_CONFIGURATION (BeacnPeriod=%ld,AtimW=%ld,Ch=%d)\n",
3775 pConfig->BeaconPeriod, pConfig->ATIMWindow, pAdapter->CommonCfg.Channel));
3776 // Config has changed
3777 pAdapter->bConfigChanged = TRUE;
3780 #ifdef DOT11_N_SUPPORT
3781 case RT_OID_802_11_SET_HT_PHYMODE:
3782 if (wrq->u.data.length != sizeof(OID_SET_HT_PHYMODE))
3786 POID_SET_HT_PHYMODE pHTPhyMode = &HT_PhyMode;
3788 Status = copy_from_user(&HT_PhyMode, wrq->u.data.pointer, wrq->u.data.length);
3789 DBGPRINT(RT_DEBUG_TRACE, ("Set::pHTPhyMode (PhyMode = %d,TransmitNo = %d, HtMode = %d, ExtOffset = %d , MCS = %d, BW = %d, STBC = %d, SHORTGI = %d) \n",
3790 pHTPhyMode->PhyMode, pHTPhyMode->TransmitNo,pHTPhyMode->HtMode,pHTPhyMode->ExtOffset,
3791 pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->SHORTGI));
3792 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
3793 RTMPSetHT(pAdapter, pHTPhyMode);
3795 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_HT_PHYMODE(MCS=%d,BW=%d,SGI=%d,STBC=%d)\n",
3796 pAdapter->StaCfg.HTPhyMode.field.MCS, pAdapter->StaCfg.HTPhyMode.field.BW, pAdapter->StaCfg.HTPhyMode.field.ShortGI,
3797 pAdapter->StaCfg.HTPhyMode.field.STBC));
3799 #endif // DOT11_N_SUPPORT //
3800 case RT_OID_802_11_SET_APSD_SETTING:
3801 if (wrq->u.data.length != sizeof(ULONG))
3806 Status = copy_from_user(&apsd, wrq->u.data.pointer, wrq->u.data.length);
3808 /*-------------------------------------------------------------------
3809 |B31~B7 | B6~B5 | B4 | B3 | B2 | B1 | B0 |
3810 ---------------------------------------------------------------------
3811 | Rsvd | Max SP Len | AC_VO | AC_VI | AC_BK | AC_BE | APSD Capable |
3812 ---------------------------------------------------------------------*/
3813 pAdapter->CommonCfg.bAPSDCapable = (apsd & 0x00000001) ? TRUE : FALSE;
3814 pAdapter->CommonCfg.bAPSDAC_BE = ((apsd & 0x00000002) >> 1) ? TRUE : FALSE;
3815 pAdapter->CommonCfg.bAPSDAC_BK = ((apsd & 0x00000004) >> 2) ? TRUE : FALSE;
3816 pAdapter->CommonCfg.bAPSDAC_VI = ((apsd & 0x00000008) >> 3) ? TRUE : FALSE;
3817 pAdapter->CommonCfg.bAPSDAC_VO = ((apsd & 0x00000010) >> 4) ? TRUE : FALSE;
3818 pAdapter->CommonCfg.MaxSPLength = (UCHAR)((apsd & 0x00000060) >> 5);
3820 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_APSD_SETTING (apsd=0x%lx, APSDCap=%d, [BE,BK,VI,VO]=[%d/%d/%d/%d], MaxSPLen=%d)\n", apsd, pAdapter->CommonCfg.bAPSDCapable,
3821 pAdapter->CommonCfg.bAPSDAC_BE, pAdapter->CommonCfg.bAPSDAC_BK, pAdapter->CommonCfg.bAPSDAC_VI, pAdapter->CommonCfg.bAPSDAC_VO, pAdapter->CommonCfg.MaxSPLength));
3825 case RT_OID_802_11_SET_APSD_PSM:
3826 if (wrq->u.data.length != sizeof(ULONG))
3830 // Driver needs to notify AP when PSM changes
3831 Status = copy_from_user(&pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.pointer, wrq->u.data.length);
3832 if (pAdapter->CommonCfg.bAPSDForcePowerSave != pAdapter->StaCfg.Psm)
3834 MlmeSetPsmBit(pAdapter, pAdapter->CommonCfg.bAPSDForcePowerSave);
3835 RTMPSendNullFrame(pAdapter, pAdapter->CommonCfg.TxRate, TRUE);
3837 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_APSD_PSM (bAPSDForcePowerSave:%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
3841 case RT_OID_802_11_SET_WMM:
3842 if (wrq->u.data.length != sizeof(BOOLEAN))
3846 Status = copy_from_user(&pAdapter->CommonCfg.bWmmCapable, wrq->u.data.pointer, wrq->u.data.length);
3847 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_WMM (=%d) \n", pAdapter->CommonCfg.bWmmCapable));
3851 case OID_802_11_DISASSOCIATE:
3853 // Set NdisRadioStateOff to TRUE, instead of called MlmeRadioOff.
3854 // Later on, NDIS_802_11_BSSID_LIST_EX->NumberOfItems should be 0
3855 // when query OID_802_11_BSSID_LIST.
3857 // TRUE: NumberOfItems will set to 0.
3858 // FALSE: NumberOfItems no change.
3860 pAdapter->CommonCfg.NdisRadioStateOff = TRUE;
3861 // Set to immediately send the media disconnect event
3862 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
3863 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DISASSOCIATE \n"));
3865 if (INFRA_ON(pAdapter))
3867 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3869 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3870 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3873 MlmeEnqueue(pAdapter,
3874 MLME_CNTL_STATE_MACHINE,
3875 OID_802_11_DISASSOCIATE,
3879 StateMachineTouched = TRUE;
3883 #ifdef DOT11_N_SUPPORT
3884 case RT_OID_802_11_SET_IMME_BA_CAP:
3885 if (wrq->u.data.length != sizeof(OID_BACAP_STRUC))
3889 OID_BACAP_STRUC Orde ;
3890 Status = copy_from_user(&Orde, wrq->u.data.pointer, wrq->u.data.length);
3891 if (Orde.Policy > BA_NOTUSE)
3893 Status = NDIS_STATUS_INVALID_DATA;
3895 else if (Orde.Policy == BA_NOTUSE)
3897 pAdapter->CommonCfg.BACapability.field.Policy = BA_NOTUSE;
3898 pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
3899 pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
3900 pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
3901 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
3902 pAdapter->CommonCfg.DesiredHtPhy.MimoPs= Orde.MMPSmode;
3903 pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
3905 pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
3906 pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
3907 pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
3911 pAdapter->CommonCfg.BACapability.field.AutoBA = Orde.AutoBA;
3912 pAdapter->CommonCfg.BACapability.field.Policy = IMMED_BA; // we only support immediate BA.
3913 pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
3914 pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
3915 pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
3916 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
3917 pAdapter->CommonCfg.DesiredHtPhy.MimoPs = Orde.MMPSmode;
3918 pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
3921 pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
3922 pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
3923 pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
3925 if (pAdapter->CommonCfg.BACapability.field.RxBAWinLimit > MAX_RX_REORDERBUF)
3926 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = MAX_RX_REORDERBUF;
3930 pAdapter->CommonCfg.REGBACapability.word = pAdapter->CommonCfg.BACapability.word;
3931 DBGPRINT(RT_DEBUG_TRACE, ("Set::(Orde.AutoBA = %d) (Policy=%d)(ReBAWinLimit=%d)(TxBAWinLimit=%d)(AutoMode=%d)\n",Orde.AutoBA, pAdapter->CommonCfg.BACapability.field.Policy,
3932 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit,pAdapter->CommonCfg.BACapability.field.TxBAWinLimit, pAdapter->CommonCfg.BACapability.field.AutoBA));
3933 DBGPRINT(RT_DEBUG_TRACE, ("Set::(MimoPs = %d)(AmsduEnable = %d) (AmsduSize=%d)(MpduDensity=%d)\n",pAdapter->CommonCfg.DesiredHtPhy.MimoPs, pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable,
3934 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize, pAdapter->CommonCfg.DesiredHtPhy.MpduDensity));
3938 case RT_OID_802_11_ADD_IMME_BA:
3939 DBGPRINT(RT_DEBUG_TRACE, (" Set :: RT_OID_802_11_ADD_IMME_BA \n"));
3940 if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
3945 OID_ADD_BA_ENTRY BA;
3946 MAC_TABLE_ENTRY *pEntry;
3948 Status = copy_from_user(&BA, wrq->u.data.pointer, wrq->u.data.length);
3951 Status = NDIS_STATUS_INVALID_DATA;
3956 //BATableInsertEntry
3957 //As ad-hoc mode, BA pair is not limited to only BSSID. so add via OID.
3959 // in ad hoc mode, when adding BA pair, we should insert this entry into MACEntry too
3960 pEntry = MacTableLookup(pAdapter, BA.MACAddr);
3963 DBGPRINT(RT_DEBUG_TRACE, ("RT_OID_802_11_ADD_IMME_BA. break on no connection.----:%x:%x\n", BA.MACAddr[4], BA.MACAddr[5]));
3966 if (BA.IsRecipient == FALSE)
3968 if (pEntry->bIAmBadAtheros == TRUE)
3969 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = 0x10;
3971 BAOriSessionSetUp(pAdapter, pEntry, index, 0, 100, TRUE);
3975 //BATableInsertEntry(pAdapter, pEntry->Aid, BA.MACAddr, 0, 0xffff, BA.TID, BA.nMSDU, BA.IsRecipient);
3978 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_IMME_BA. Rec = %d. Mac = %x:%x:%x:%x:%x:%x . \n",
3979 BA.IsRecipient, BA.MACAddr[0], BA.MACAddr[1], BA.MACAddr[2], BA.MACAddr[2]
3980 , BA.MACAddr[4], BA.MACAddr[5]));
3985 case RT_OID_802_11_TEAR_IMME_BA:
3986 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA \n"));
3987 if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
3991 POID_ADD_BA_ENTRY pBA;
3992 MAC_TABLE_ENTRY *pEntry;
3994 pBA = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3998 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA kmalloc() can't allocate enough memory\n"));
3999 Status = NDIS_STATUS_FAILURE;
4003 Status = copy_from_user(pBA, wrq->u.data.pointer, wrq->u.data.length);
4004 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA(TID=%d, bAllTid=%d)\n", pBA->TID, pBA->bAllTid));
4006 if (!pBA->bAllTid && (pBA->TID > NUM_OF_TID))
4008 Status = NDIS_STATUS_INVALID_DATA;
4012 if (pBA->IsRecipient == FALSE)
4014 pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
4015 DBGPRINT(RT_DEBUG_TRACE, (" pBA->IsRecipient == FALSE\n"));
4018 DBGPRINT(RT_DEBUG_TRACE, (" pBA->pEntry\n"));
4019 BAOriSessionTearDown(pAdapter, pEntry->Aid, pBA->TID, FALSE, TRUE);
4022 DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
4026 pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
4029 BARecSessionTearDown( pAdapter, (UCHAR)pEntry->Aid, pBA->TID, TRUE);
4032 DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
4038 #endif // DOT11_N_SUPPORT //
4040 // For WPA_SUPPLICANT to set static wep key
4041 case OID_802_11_ADD_WEP:
4042 pWepKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4047 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed!!\n"));
4050 Status = copy_from_user(pWepKey, wrq->u.data.pointer, wrq->u.data.length);
4054 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (length mismatch)!!\n"));
4058 KeyIdx = pWepKey->KeyIndex & 0x0fffffff;
4059 // KeyIdx must be 0 ~ 3
4063 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (KeyIdx must be smaller than 4)!!\n"));
4067 UCHAR CipherAlg = 0;
4070 // set key material and key length
4071 NdisZeroMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, 16);
4072 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
4073 NdisMoveMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
4075 switch(pWepKey->KeyLength)
4078 CipherAlg = CIPHER_WEP64;
4081 CipherAlg = CIPHER_WEP128;
4084 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, only support CIPHER_WEP64(len:5) & CIPHER_WEP128(len:13)!!\n"));
4088 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CipherAlg;
4090 // Default key for tx (shared key)
4091 if (pWepKey->KeyIndex & 0x80000000)
4093 #ifdef WPA_SUPPLICANT_SUPPORT
4094 // set key material and key length
4095 NdisZeroMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, 16);
4096 pAdapter->StaCfg.DesireSharedKey[KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
4097 NdisMoveMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
4098 pAdapter->StaCfg.DesireSharedKeyId = KeyIdx;
4099 pAdapter->StaCfg.DesireSharedKey[KeyIdx].CipherAlg = CipherAlg;
4100 #endif // WPA_SUPPLICANT_SUPPORT //
4101 pAdapter->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
4104 #ifdef WPA_SUPPLICANT_SUPPORT
4105 if ((pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE) &&
4106 (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA))
4108 Key = pWepKey->KeyMaterial;
4110 // Set Group key material to Asic
4111 AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
4113 // Update WCID attribute table and IVEIV table for this group key table
4114 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
4116 STA_PORT_SECURED(pAdapter);
4118 // Indicate Connected for GUI
4119 pAdapter->IndicateMediaState = NdisMediaStateConnected;
4121 else if (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)
4122 #endif // WPA_SUPPLICANT_SUPPORT
4124 Key = pAdapter->SharedKey[BSS0][KeyIdx].Key;
4126 // Set key material and cipherAlg to Asic
4127 AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
4129 if (pWepKey->KeyIndex & 0x80000000)
4131 PMAC_TABLE_ENTRY pEntry = &pAdapter->MacTab.Content[BSSID_WCID];
4132 // Assign group key info
4133 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
4134 // Assign pairwise key info
4135 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, pEntry);
4138 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP (id=0x%x, Len=%d-byte), %s\n", pWepKey->KeyIndex, pWepKey->KeyLength, (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED) ? "Port Secured":"Port NOT Secured"));
4143 #ifdef WPA_SUPPLICANT_SUPPORT
4144 case OID_SET_COUNTERMEASURES:
4145 if (wrq->u.data.length != sizeof(int))
4150 Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
4152 pAdapter->StaCfg.bBlockAssoc = TRUE;
4154 // WPA MIC error should block association attempt for 60 seconds
4155 pAdapter->StaCfg.bBlockAssoc = FALSE;
4156 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_SET_COUNTERMEASURES bBlockAssoc=%s\n", pAdapter->StaCfg.bBlockAssoc ? "TRUE":"FALSE"));
4159 case RT_OID_WPA_SUPPLICANT_SUPPORT:
4160 if (wrq->u.data.length != sizeof(UCHAR))
4164 Status = copy_from_user(&wpa_supplicant_enable, wrq->u.data.pointer, wrq->u.data.length);
4165 pAdapter->StaCfg.WpaSupplicantUP = wpa_supplicant_enable;
4166 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
4169 case OID_802_11_DEAUTHENTICATION:
4170 if (wrq->u.data.length != sizeof(MLME_DEAUTH_REQ_STRUCT))
4174 MLME_DEAUTH_REQ_STRUCT *pInfo;
4175 MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
4177 pInfo = (MLME_DEAUTH_REQ_STRUCT *) MsgElem->Msg;
4178 Status = copy_from_user(pInfo, wrq->u.data.pointer, wrq->u.data.length);
4179 MlmeDeauthReqAction(pAdapter, MsgElem);
4182 if (INFRA_ON(pAdapter))
4184 LinkDown(pAdapter, FALSE);
4185 pAdapter->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
4187 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DEAUTHENTICATION (Reason=%d)\n", pInfo->Reason));
4190 case OID_802_11_DROP_UNENCRYPTED:
4191 if (wrq->u.data.length != sizeof(int))
4196 Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
4198 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
4200 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
4201 NdisAcquireSpinLock(&pAdapter->MacTabLock);
4202 pAdapter->MacTab.Content[BSSID_WCID].PortSecured = pAdapter->StaCfg.PortSecured;
4203 NdisReleaseSpinLock(&pAdapter->MacTabLock);
4204 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DROP_UNENCRYPTED (=%d)\n", enabled));
4207 case OID_802_11_SET_IEEE8021X:
4208 if (wrq->u.data.length != sizeof(BOOLEAN))
4212 Status = copy_from_user(&IEEE8021xState, wrq->u.data.pointer, wrq->u.data.length);
4213 pAdapter->StaCfg.IEEE8021X = IEEE8021xState;
4214 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X (=%d)\n", IEEE8021xState));
4217 case OID_802_11_SET_IEEE8021X_REQUIRE_KEY:
4218 if (wrq->u.data.length != sizeof(BOOLEAN))
4222 Status = copy_from_user(&IEEE8021x_required_keys, wrq->u.data.pointer, wrq->u.data.length);
4223 pAdapter->StaCfg.IEEE8021x_required_keys = IEEE8021x_required_keys;
4224 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X_REQUIRE_KEY (%d)\n", IEEE8021x_required_keys));
4227 case OID_802_11_PMKID:
4228 pPmkId = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4230 if(pPmkId == NULL) {
4234 Status = copy_from_user(pPmkId, wrq->u.data.pointer, wrq->u.data.length);
4236 // check the PMKID information
4237 if (pPmkId->BSSIDInfoCount == 0)
4238 NdisZeroMemory(pAdapter->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
4241 PBSSID_INFO pBssIdInfo;
4245 for (BssIdx = 0; BssIdx < pPmkId->BSSIDInfoCount; BssIdx++)
4247 // point to the indexed BSSID_INFO structure
4248 pBssIdInfo = (PBSSID_INFO) ((PUCHAR) pPmkId + 2 * sizeof(UINT) + BssIdx * sizeof(BSSID_INFO));
4249 // Find the entry in the saved data base.
4250 for (CachedIdx = 0; CachedIdx < pAdapter->StaCfg.SavedPMKNum; CachedIdx++)
4252 // compare the BSSID
4253 if (NdisEqualMemory(pBssIdInfo->BSSID, pAdapter->StaCfg.SavedPMK[CachedIdx].BSSID, sizeof(NDIS_802_11_MAC_ADDRESS)))
4257 // Found, replace it
4258 if (CachedIdx < PMKID_NO)
4260 DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
4261 NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
4262 pAdapter->StaCfg.SavedPMKNum++;
4264 // Not found, replace the last one
4267 // Randomly replace one
4268 CachedIdx = (pBssIdInfo->BSSID[5] % PMKID_NO);
4269 DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
4270 NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
4277 #endif // WPA_SUPPLICANT_SUPPORT //
4280 DBGPRINT(RT_DEBUG_TRACE, ("Set::unknown IOCTL's subcmd = 0x%08x\n", cmd));
4281 Status = -EOPNOTSUPP;
4289 INT RTMPQueryInformation(
4290 IN PRTMP_ADAPTER pAdapter,
4291 IN OUT struct ifreq *rq,
4294 struct iwreq *wrq = (struct iwreq *) rq;
4295 NDIS_802_11_BSSID_LIST_EX *pBssidList = NULL;
4296 PNDIS_WLAN_BSSID_EX pBss;
4297 NDIS_802_11_SSID Ssid;
4298 NDIS_802_11_CONFIGURATION *pConfiguration = NULL;
4299 RT_802_11_LINK_STATUS *pLinkStatus = NULL;
4300 RT_802_11_STA_CONFIG *pStaConfig = NULL;
4301 NDIS_802_11_STATISTICS *pStatistics = NULL;
4302 NDIS_802_11_RTS_THRESHOLD RtsThresh;
4303 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
4304 NDIS_802_11_POWER_MODE PowerMode;
4305 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
4306 RT_802_11_PREAMBLE PreamType;
4307 NDIS_802_11_AUTHENTICATION_MODE AuthMode;
4308 NDIS_802_11_WEP_STATUS WepStatus;
4309 NDIS_MEDIA_STATE MediaState;
4310 ULONG BssBufSize, ulInfo=0, NetworkTypeList[4], apsd = 0;
4312 PUCHAR pBuf = NULL, pPtr;
4313 INT Status = NDIS_STATUS_SUCCESS;
4314 UINT we_version_compiled;
4315 UCHAR i, Padding = 0;
4317 UCHAR driverVersion[8];
4318 OID_SET_HT_PHYMODE *pHTPhyMode = NULL;
4322 case RT_OID_DEVICE_NAME:
4323 wrq->u.data.length = sizeof(STA_NIC_DEVICE_NAME);
4324 Status = copy_to_user(wrq->u.data.pointer, STA_NIC_DEVICE_NAME, wrq->u.data.length);
4326 case RT_OID_VERSION_INFO:
4327 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_VERSION_INFO \n"));
4328 wrq->u.data.length = 8*sizeof(UCHAR);
4329 sprintf(&driverVersion[0], "%s", STA_DRIVER_VERSION);
4330 driverVersion[7] = '\0';
4331 if (copy_to_user(wrq->u.data.pointer, &driverVersion, wrq->u.data.length))
4336 case OID_802_11_BSSID_LIST:
4337 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
4340 * Still scanning, indicate the caller should try again.
4342 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (Still scanning)\n"));
4345 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (%d BSS returned)\n",pAdapter->ScanTab.BssNr));
4346 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
4347 // Claculate total buffer size required
4348 BssBufSize = sizeof(ULONG);
4350 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
4352 // Align pointer to 4 bytes boundary.
4353 //Padding = 4 - (pAdapter->ScanTab.BssEntry[i].VarIELen & 0x0003);
4356 BssBufSize += (sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
4359 // For safety issue, we add 256 bytes just in case
4361 // Allocate the same size as passed from higher layer
4362 pBuf = kmalloc(BssBufSize, MEM_ALLOC_FLAG);
4368 // Init 802_11_BSSID_LIST_EX structure
4369 NdisZeroMemory(pBuf, BssBufSize);
4370 pBssidList = (PNDIS_802_11_BSSID_LIST_EX) pBuf;
4371 pBssidList->NumberOfItems = pAdapter->ScanTab.BssNr;
4373 // Calculate total buffer length
4374 BssLen = 4; // Consist of NumberOfItems
4375 // Point to start of NDIS_WLAN_BSSID_EX
4376 // pPtr = pBuf + sizeof(ULONG);
4377 pPtr = (PUCHAR) &pBssidList->Bssid[0];
4378 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
4380 pBss = (PNDIS_WLAN_BSSID_EX) pPtr;
4381 NdisMoveMemory(&pBss->MacAddress, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
4382 if ((pAdapter->ScanTab.BssEntry[i].Hidden == 1) && (pAdapter->StaCfg.bShowHiddenSSID == FALSE))
4385 // We must return this SSID during 4way handshaking, otherwise Aegis will failed to parse WPA infomation
4386 // and then failed to send EAPOl farame.
4388 if ((pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) && (pAdapter->StaCfg.PortSecured != WPA_802_1X_PORT_SECURED))
4390 pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
4391 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
4394 pBss->Ssid.SsidLength = 0;
4398 pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
4399 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
4401 pBss->Privacy = pAdapter->ScanTab.BssEntry[i].Privacy;
4402 pBss->Rssi = pAdapter->ScanTab.BssEntry[i].Rssi - pAdapter->BbpRssiToDbmDelta;
4403 pBss->NetworkTypeInUse = NetworkTypeInUseSanity(&pAdapter->ScanTab.BssEntry[i]);
4404 pBss->Configuration.Length = sizeof(NDIS_802_11_CONFIGURATION);
4405 pBss->Configuration.BeaconPeriod = pAdapter->ScanTab.BssEntry[i].BeaconPeriod;
4406 pBss->Configuration.ATIMWindow = pAdapter->ScanTab.BssEntry[i].AtimWin;
4408 MAP_CHANNEL_ID_TO_KHZ(pAdapter->ScanTab.BssEntry[i].Channel, pBss->Configuration.DSConfig);
4410 if (pAdapter->ScanTab.BssEntry[i].BssType == BSS_INFRA)
4411 pBss->InfrastructureMode = Ndis802_11Infrastructure;
4413 pBss->InfrastructureMode = Ndis802_11IBSS;
4415 NdisMoveMemory(pBss->SupportedRates, pAdapter->ScanTab.BssEntry[i].SupRate, pAdapter->ScanTab.BssEntry[i].SupRateLen);
4416 NdisMoveMemory(pBss->SupportedRates + pAdapter->ScanTab.BssEntry[i].SupRateLen,
4417 pAdapter->ScanTab.BssEntry[i].ExtRate,
4418 pAdapter->ScanTab.BssEntry[i].ExtRateLen);
4420 if (pAdapter->ScanTab.BssEntry[i].VarIELen == 0)
4422 pBss->IELength = sizeof(NDIS_802_11_FIXED_IEs);
4423 NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
4424 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
4428 pBss->IELength = (ULONG)(sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen);
4429 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
4430 NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
4431 NdisMoveMemory(pBss->IEs + sizeof(NDIS_802_11_FIXED_IEs), pAdapter->ScanTab.BssEntry[i].VarIEs, pAdapter->ScanTab.BssEntry[i].VarIELen);
4432 pPtr += pAdapter->ScanTab.BssEntry[i].VarIELen;
4434 pBss->Length = (ULONG)(sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
4436 #if WIRELESS_EXT < 17
4437 if ((BssLen + pBss->Length) < wrq->u.data.length)
4438 BssLen += pBss->Length;
4441 pBssidList->NumberOfItems = i;
4445 BssLen += pBss->Length;
4449 #if WIRELESS_EXT < 17
4450 wrq->u.data.length = BssLen;
4452 if (BssLen > wrq->u.data.length)
4458 wrq->u.data.length = BssLen;
4460 Status = copy_to_user(wrq->u.data.pointer, pBssidList, BssLen);
4463 case OID_802_3_CURRENT_ADDRESS:
4464 wrq->u.data.length = MAC_ADDR_LEN;
4465 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
4467 case OID_GEN_MEDIA_CONNECT_STATUS:
4468 if (pAdapter->IndicateMediaState == NdisMediaStateConnected)
4469 MediaState = NdisMediaStateConnected;
4471 MediaState = NdisMediaStateDisconnected;
4473 wrq->u.data.length = sizeof(NDIS_MEDIA_STATE);
4474 Status = copy_to_user(wrq->u.data.pointer, &MediaState, wrq->u.data.length);
4476 case OID_802_11_BSSID:
4477 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
4479 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Bssid, sizeof(NDIS_802_11_MAC_ADDRESS));
4484 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID(=EMPTY)\n"));
4488 case OID_802_11_SSID:
4489 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
4490 NdisZeroMemory(Ssid.Ssid, MAX_LEN_OF_SSID);
4491 Ssid.SsidLength = pAdapter->CommonCfg.SsidLen;
4492 memcpy(Ssid.Ssid, pAdapter->CommonCfg.Ssid, Ssid.SsidLength);
4493 wrq->u.data.length = sizeof(NDIS_802_11_SSID);
4494 Status = copy_to_user(wrq->u.data.pointer, &Ssid, wrq->u.data.length);
4495 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_SSID (Len=%d, ssid=%s)\n", Ssid.SsidLength,Ssid.Ssid));
4497 case RT_OID_802_11_QUERY_LINK_STATUS:
4498 pLinkStatus = (RT_802_11_LINK_STATUS *) kmalloc(sizeof(RT_802_11_LINK_STATUS), MEM_ALLOC_FLAG);
4501 pLinkStatus->CurrTxRate = RateIdTo500Kbps[pAdapter->CommonCfg.TxRate]; // unit : 500 kbps
4502 pLinkStatus->ChannelQuality = pAdapter->Mlme.ChannelQuality;
4503 pLinkStatus->RxByteCount = pAdapter->RalinkCounters.ReceivedByteCount;
4504 pLinkStatus->TxByteCount = pAdapter->RalinkCounters.TransmittedByteCount;
4505 pLinkStatus->CentralChannel = pAdapter->CommonCfg.CentralChannel;
4506 wrq->u.data.length = sizeof(RT_802_11_LINK_STATUS);
4507 Status = copy_to_user(wrq->u.data.pointer, pLinkStatus, wrq->u.data.length);
4509 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS\n"));
4513 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS(kmalloc failed)\n"));
4517 case OID_802_11_CONFIGURATION:
4518 pConfiguration = (NDIS_802_11_CONFIGURATION *) kmalloc(sizeof(NDIS_802_11_CONFIGURATION), MEM_ALLOC_FLAG);
4521 pConfiguration->Length = sizeof(NDIS_802_11_CONFIGURATION);
4522 pConfiguration->BeaconPeriod = pAdapter->CommonCfg.BeaconPeriod;
4523 pConfiguration->ATIMWindow = pAdapter->StaActive.AtimWin;
4524 MAP_CHANNEL_ID_TO_KHZ(pAdapter->CommonCfg.Channel, pConfiguration->DSConfig);
4525 wrq->u.data.length = sizeof(NDIS_802_11_CONFIGURATION);
4526 Status = copy_to_user(wrq->u.data.pointer, pConfiguration, wrq->u.data.length);
4527 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(BeaconPeriod=%ld,AtimW=%ld,Channel=%d) \n",
4528 pConfiguration->BeaconPeriod, pConfiguration->ATIMWindow, pAdapter->CommonCfg.Channel));
4529 kfree(pConfiguration);
4533 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(kmalloc failed)\n"));
4537 case RT_OID_802_11_SNR_0:
4538 if ((pAdapter->StaCfg.LastSNR0 > 0))
4540 ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR0) * 3) / 16 ;
4541 wrq->u.data.length = sizeof(ulInfo);
4542 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4543 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_SNR_0(0x=%lx)\n", ulInfo));
4548 case RT_OID_802_11_SNR_1:
4549 if ((pAdapter->Antenna.field.RxPath > 1) &&
4550 (pAdapter->StaCfg.LastSNR1 > 0))
4552 ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR1) * 3) / 16 ;
4553 wrq->u.data.length = sizeof(ulInfo);
4554 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4555 DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(0x=%lx)\n",ulInfo));
4559 DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(pAdapter->StaCfg.LastSNR1=%d)\n",pAdapter->StaCfg.LastSNR1));
4561 case OID_802_11_RSSI_TRIGGER:
4562 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0 - pAdapter->BbpRssiToDbmDelta;
4563 wrq->u.data.length = sizeof(ulInfo);
4564 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4565 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RSSI_TRIGGER(=%ld)\n", ulInfo));
4567 case OID_802_11_RSSI:
4568 case RT_OID_802_11_RSSI:
4569 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0;
4570 wrq->u.data.length = sizeof(ulInfo);
4571 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4573 case RT_OID_802_11_RSSI_1:
4574 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi1;
4575 wrq->u.data.length = sizeof(ulInfo);
4576 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4578 case RT_OID_802_11_RSSI_2:
4579 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi2;
4580 wrq->u.data.length = sizeof(ulInfo);
4581 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4583 case OID_802_11_STATISTICS:
4584 pStatistics = (NDIS_802_11_STATISTICS *) kmalloc(sizeof(NDIS_802_11_STATISTICS), MEM_ALLOC_FLAG);
4587 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS \n"));
4588 // add the most up-to-date h/w raw counters into software counters
4589 NICUpdateRawCounters(pAdapter);
4591 // Sanity check for calculation of sucessful count
4592 if (pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart < pAdapter->WlanCounters.RetryCount.QuadPart)
4593 pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
4595 pStatistics->TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart;
4596 pStatistics->MulticastTransmittedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastTransmittedFrameCount.QuadPart;
4597 pStatistics->FailedCount.QuadPart = pAdapter->WlanCounters.FailedCount.QuadPart;
4598 pStatistics->RetryCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
4599 pStatistics->MultipleRetryCount.QuadPart = pAdapter->WlanCounters.MultipleRetryCount.QuadPart;
4600 pStatistics->RTSSuccessCount.QuadPart = pAdapter->WlanCounters.RTSSuccessCount.QuadPart;
4601 pStatistics->RTSFailureCount.QuadPart = pAdapter->WlanCounters.RTSFailureCount.QuadPart;
4602 pStatistics->ACKFailureCount.QuadPart = pAdapter->WlanCounters.ACKFailureCount.QuadPart;
4603 pStatistics->FrameDuplicateCount.QuadPart = pAdapter->WlanCounters.FrameDuplicateCount.QuadPart;
4604 pStatistics->ReceivedFragmentCount.QuadPart = pAdapter->WlanCounters.ReceivedFragmentCount.QuadPart;
4605 pStatistics->MulticastReceivedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastReceivedFrameCount.QuadPart;
4607 pStatistics->FCSErrorCount = pAdapter->RalinkCounters.RealFcsErrCount;
4609 pStatistics->FCSErrorCount.QuadPart = pAdapter->WlanCounters.FCSErrorCount.QuadPart;
4610 pStatistics->FrameDuplicateCount.u.LowPart = pAdapter->WlanCounters.FrameDuplicateCount.u.LowPart / 100;
4612 wrq->u.data.length = sizeof(NDIS_802_11_STATISTICS);
4613 Status = copy_to_user(wrq->u.data.pointer, pStatistics, wrq->u.data.length);
4618 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS(kmalloc failed)\n"));
4622 case OID_GEN_RCV_OK:
4623 ulInfo = pAdapter->Counters8023.GoodReceives;
4624 wrq->u.data.length = sizeof(ulInfo);
4625 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4627 case OID_GEN_RCV_NO_BUFFER:
4628 ulInfo = pAdapter->Counters8023.RxNoBuffer;
4629 wrq->u.data.length = sizeof(ulInfo);
4630 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4632 case RT_OID_802_11_PHY_MODE:
4633 ulInfo = (ULONG)pAdapter->CommonCfg.PhyMode;
4634 wrq->u.data.length = sizeof(ulInfo);
4635 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4636 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PHY_MODE (=%ld)\n", ulInfo));
4638 case RT_OID_802_11_STA_CONFIG:
4639 pStaConfig = (RT_802_11_STA_CONFIG *) kmalloc(sizeof(RT_802_11_STA_CONFIG), MEM_ALLOC_FLAG);
4642 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG\n"));
4643 pStaConfig->EnableTxBurst = pAdapter->CommonCfg.bEnableTxBurst;
4644 pStaConfig->EnableTurboRate = 0;
4645 pStaConfig->UseBGProtection = pAdapter->CommonCfg.UseBGProtection;
4646 pStaConfig->UseShortSlotTime = pAdapter->CommonCfg.bUseShortSlotTime;
4647 //pStaConfig->AdhocMode = pAdapter->StaCfg.AdhocMode;
4648 pStaConfig->HwRadioStatus = (pAdapter->StaCfg.bHwRadio == TRUE) ? 1 : 0;
4649 pStaConfig->Rsv1 = 0;
4650 pStaConfig->SystemErrorBitmap = pAdapter->SystemErrorBitmap;
4651 wrq->u.data.length = sizeof(RT_802_11_STA_CONFIG);
4652 Status = copy_to_user(wrq->u.data.pointer, pStaConfig, wrq->u.data.length);
4657 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
4661 case OID_802_11_RTS_THRESHOLD:
4662 RtsThresh = pAdapter->CommonCfg.RtsThreshold;
4663 wrq->u.data.length = sizeof(RtsThresh);
4664 Status = copy_to_user(wrq->u.data.pointer, &RtsThresh, wrq->u.data.length);
4665 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RTS_THRESHOLD(=%ld)\n", RtsThresh));
4667 case OID_802_11_FRAGMENTATION_THRESHOLD:
4668 FragThresh = pAdapter->CommonCfg.FragmentThreshold;
4669 if (pAdapter->CommonCfg.bUseZeroToDisableFragment == TRUE)
4671 wrq->u.data.length = sizeof(FragThresh);
4672 Status = copy_to_user(wrq->u.data.pointer, &FragThresh, wrq->u.data.length);
4673 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_FRAGMENTATION_THRESHOLD(=%ld)\n", FragThresh));
4675 case OID_802_11_POWER_MODE:
4676 PowerMode = pAdapter->StaCfg.WindowsPowerMode;
4677 wrq->u.data.length = sizeof(PowerMode);
4678 Status = copy_to_user(wrq->u.data.pointer, &PowerMode, wrq->u.data.length);
4679 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_POWER_MODE(=%d)\n", PowerMode));
4681 case RT_OID_802_11_RADIO:
4682 RadioState = (BOOLEAN) pAdapter->StaCfg.bSwRadio;
4683 wrq->u.data.length = sizeof(RadioState);
4684 Status = copy_to_user(wrq->u.data.pointer, &RadioState, wrq->u.data.length);
4685 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_RADIO (=%d)\n", RadioState));
4687 case OID_802_11_INFRASTRUCTURE_MODE:
4688 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
4689 BssType = Ndis802_11IBSS;
4690 else if (pAdapter->StaCfg.BssType == BSS_INFRA)
4691 BssType = Ndis802_11Infrastructure;
4692 else if (pAdapter->StaCfg.BssType == BSS_MONITOR)
4693 BssType = Ndis802_11Monitor;
4695 BssType = Ndis802_11AutoUnknown;
4697 wrq->u.data.length = sizeof(BssType);
4698 Status = copy_to_user(wrq->u.data.pointer, &BssType, wrq->u.data.length);
4699 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_INFRASTRUCTURE_MODE(=%d)\n", BssType));
4701 case RT_OID_802_11_PREAMBLE:
4702 PreamType = pAdapter->CommonCfg.TxPreamble;
4703 wrq->u.data.length = sizeof(PreamType);
4704 Status = copy_to_user(wrq->u.data.pointer, &PreamType, wrq->u.data.length);
4705 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PREAMBLE(=%d)\n", PreamType));
4707 case OID_802_11_AUTHENTICATION_MODE:
4708 AuthMode = pAdapter->StaCfg.AuthMode;
4709 wrq->u.data.length = sizeof(AuthMode);
4710 Status = copy_to_user(wrq->u.data.pointer, &AuthMode, wrq->u.data.length);
4711 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_AUTHENTICATION_MODE(=%d)\n", AuthMode));
4713 case OID_802_11_WEP_STATUS:
4714 WepStatus = pAdapter->StaCfg.WepStatus;
4715 wrq->u.data.length = sizeof(WepStatus);
4716 Status = copy_to_user(wrq->u.data.pointer, &WepStatus, wrq->u.data.length);
4717 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_WEP_STATUS(=%d)\n", WepStatus));
4719 case OID_802_11_TX_POWER_LEVEL:
4720 wrq->u.data.length = sizeof(ULONG);
4721 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPower, wrq->u.data.length);
4722 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_TX_POWER_LEVEL %x\n",pAdapter->CommonCfg.TxPower));
4724 case RT_OID_802_11_TX_POWER_LEVEL_1:
4725 wrq->u.data.length = sizeof(ULONG);
4726 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPowerPercentage, wrq->u.data.length);
4727 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
4729 case OID_802_11_NETWORK_TYPES_SUPPORTED:
4730 if ((pAdapter->RfIcType == RFIC_2850) || (pAdapter->RfIcType == RFIC_2750))
4732 NetworkTypeList[0] = 3; // NumberOfItems = 3
4733 NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
4734 NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
4735 NetworkTypeList[3] = Ndis802_11OFDM5; // NetworkType[3] = 11a
4736 wrq->u.data.length = 16;
4737 Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
4741 NetworkTypeList[0] = 2; // NumberOfItems = 2
4742 NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
4743 NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
4744 wrq->u.data.length = 12;
4745 Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
4747 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_NETWORK_TYPES_SUPPORTED\n"));
4749 case OID_802_11_NETWORK_TYPE_IN_USE:
4750 wrq->u.data.length = sizeof(ULONG);
4751 if (pAdapter->CommonCfg.PhyMode == PHY_11A)
4752 ulInfo = Ndis802_11OFDM5;
4753 else if ((pAdapter->CommonCfg.PhyMode == PHY_11BG_MIXED) || (pAdapter->CommonCfg.PhyMode == PHY_11G))
4754 ulInfo = Ndis802_11OFDM24;
4756 ulInfo = Ndis802_11DS;
4757 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4759 case RT_OID_802_11_QUERY_LAST_RX_RATE:
4760 ulInfo = (ULONG)pAdapter->LastRxRate;
4761 wrq->u.data.length = sizeof(ulInfo);
4762 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4763 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_RX_RATE (=%ld)\n", ulInfo));
4765 case RT_OID_802_11_QUERY_LAST_TX_RATE:
4766 //ulInfo = (ULONG)pAdapter->LastTxRate;
4767 ulInfo = (ULONG)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word;
4768 wrq->u.data.length = sizeof(ulInfo);
4769 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4770 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_TX_RATE (=%lx)\n", ulInfo));
4772 case RT_OID_802_11_QUERY_EEPROM_VERSION:
4773 wrq->u.data.length = sizeof(ULONG);
4774 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->EepromVersion, wrq->u.data.length);
4776 case RT_OID_802_11_QUERY_FIRMWARE_VERSION:
4777 wrq->u.data.length = sizeof(ULONG);
4778 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->FirmwareVersion, wrq->u.data.length);
4780 case RT_OID_802_11_QUERY_NOISE_LEVEL:
4781 wrq->u.data.length = sizeof(UCHAR);
4782 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->BbpWriteLatch[66], wrq->u.data.length);
4783 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_NOISE_LEVEL (=%d)\n", pAdapter->BbpWriteLatch[66]));
4785 case RT_OID_802_11_EXTRA_INFO:
4786 wrq->u.data.length = sizeof(ULONG);
4787 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->ExtraInfo, wrq->u.data.length);
4788 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_EXTRA_INFO (=%ld)\n", pAdapter->ExtraInfo));
4790 case RT_OID_WE_VERSION_COMPILED:
4791 wrq->u.data.length = sizeof(UINT);
4792 we_version_compiled = WIRELESS_EXT;
4793 Status = copy_to_user(wrq->u.data.pointer, &we_version_compiled, wrq->u.data.length);
4795 case RT_OID_802_11_QUERY_APSD_SETTING:
4796 apsd = (pAdapter->CommonCfg.bAPSDCapable | (pAdapter->CommonCfg.bAPSDAC_BE << 1) | (pAdapter->CommonCfg.bAPSDAC_BK << 2)
4797 | (pAdapter->CommonCfg.bAPSDAC_VI << 3) | (pAdapter->CommonCfg.bAPSDAC_VO << 4) | (pAdapter->CommonCfg.MaxSPLength << 5));
4799 wrq->u.data.length = sizeof(ULONG);
4800 Status = copy_to_user(wrq->u.data.pointer, &apsd, wrq->u.data.length);
4801 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_APSD_SETTING (=0x%lx,APSDCap=%d,AC_BE=%d,AC_BK=%d,AC_VI=%d,AC_VO=%d,MAXSPLen=%d)\n",
4802 apsd,pAdapter->CommonCfg.bAPSDCapable,pAdapter->CommonCfg.bAPSDAC_BE,pAdapter->CommonCfg.bAPSDAC_BK,pAdapter->CommonCfg.bAPSDAC_VI,pAdapter->CommonCfg.bAPSDAC_VO,pAdapter->CommonCfg.MaxSPLength));
4804 case RT_OID_802_11_QUERY_APSD_PSM:
4805 wrq->u.data.length = sizeof(ULONG);
4806 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.length);
4807 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_APSD_PSM (=%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
4809 case RT_OID_802_11_QUERY_WMM:
4810 wrq->u.data.length = sizeof(BOOLEAN);
4811 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bWmmCapable, wrq->u.data.length);
4812 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_WMM (=%d)\n", pAdapter->CommonCfg.bWmmCapable));
4814 #ifdef WPA_SUPPLICANT_SUPPORT
4815 case RT_OID_NEW_DRIVER:
4818 wrq->u.data.length = sizeof(UCHAR);
4819 Status = copy_to_user(wrq->u.data.pointer, &enabled, wrq->u.data.length);
4820 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_NEW_DRIVER (=%d)\n", enabled));
4823 case RT_OID_WPA_SUPPLICANT_SUPPORT:
4824 wrq->u.data.length = sizeof(UCHAR);
4825 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->StaCfg.WpaSupplicantUP, wrq->u.data.length);
4826 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
4828 #endif // WPA_SUPPLICANT_SUPPORT //
4830 case RT_OID_DRIVER_DEVICE_NAME:
4831 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_DRIVER_DEVICE_NAME \n"));
4832 wrq->u.data.length = 16;
4833 if (copy_to_user(wrq->u.data.pointer, pAdapter->StaCfg.dev_name, wrq->u.data.length))
4838 case RT_OID_802_11_QUERY_HT_PHYMODE:
4839 pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
4842 pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
4843 pHTPhyMode->HtMode = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE;
4844 pHTPhyMode->BW = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.BW;
4845 pHTPhyMode->MCS= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MCS;
4846 pHTPhyMode->SHORTGI= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.ShortGI;
4847 pHTPhyMode->STBC= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.STBC;
4849 pHTPhyMode->ExtOffset = ((pAdapter->CommonCfg.CentralChannel < pAdapter->CommonCfg.Channel) ? (EXTCHA_BELOW) : (EXTCHA_ABOVE));
4850 wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
4851 if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
4855 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
4856 pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
4857 DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
4861 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
4865 case RT_OID_802_11_COUNTRY_REGION:
4866 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_COUNTRY_REGION \n"));
4867 wrq->u.data.length = sizeof(ulInfo);
4868 ulInfo = pAdapter->CommonCfg.CountryRegionForABand;
4869 ulInfo = (ulInfo << 8)|(pAdapter->CommonCfg.CountryRegion);
4870 if (copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length))
4875 case RT_OID_802_11_QUERY_DAT_HT_PHYMODE:
4876 pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
4879 pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
4880 pHTPhyMode->HtMode = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.HTMODE;
4881 pHTPhyMode->BW = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.BW;
4882 pHTPhyMode->MCS= (UCHAR)pAdapter->StaCfg.DesiredTransmitSetting.field.MCS;
4883 pHTPhyMode->SHORTGI= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.ShortGI;
4884 pHTPhyMode->STBC= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.STBC;
4886 wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
4887 if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
4891 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
4892 pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
4893 DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
4897 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
4901 case RT_OID_QUERY_MULTIPLE_CARD_SUPPORT:
4902 wrq->u.data.length = sizeof(UCHAR);
4904 if (copy_to_user(wrq->u.data.pointer, &i, wrq->u.data.length))
4908 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_QUERY_MULTIPLE_CARD_SUPPORT(=%d) \n", i));
4911 case OID_802_11_BUILD_CHANNEL_EX:
4914 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BUILD_CHANNEL_EX \n"));
4915 wrq->u.data.length = sizeof(UCHAR);
4916 DBGPRINT(RT_DEBUG_TRACE, ("Doesn't support EXT_BUILD_CHANNEL_LIST.\n"));
4918 Status = copy_to_user(wrq->u.data.pointer, &value, 1);
4919 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
4923 case OID_802_11_GET_CH_LIST:
4925 PRT_CHANNEL_LIST_INFO pChListBuf;
4927 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CH_LIST \n"));
4928 if (pAdapter->ChannelListNum == 0)
4930 wrq->u.data.length = 0;
4934 pChListBuf = (RT_CHANNEL_LIST_INFO *) kmalloc(sizeof(RT_CHANNEL_LIST_INFO), MEM_ALLOC_FLAG);
4935 if (pChListBuf == NULL)
4937 wrq->u.data.length = 0;
4941 pChListBuf->ChannelListNum = pAdapter->ChannelListNum;
4942 for (i = 0; i < pChListBuf->ChannelListNum; i++)
4943 pChListBuf->ChannelList[i] = pAdapter->ChannelList[i].Channel;
4945 wrq->u.data.length = sizeof(RT_CHANNEL_LIST_INFO);
4946 Status = copy_to_user(wrq->u.data.pointer, pChListBuf, sizeof(RT_CHANNEL_LIST_INFO));
4947 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
4954 case OID_802_11_GET_COUNTRY_CODE:
4955 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_COUNTRY_CODE \n"));
4956 wrq->u.data.length = 2;
4957 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.CountryCode, 2);
4958 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
4961 case OID_802_11_GET_CHANNEL_GEOGRAPHY:
4962 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CHANNEL_GEOGRAPHY \n"));
4963 wrq->u.data.length = 1;
4964 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Geography, 1);
4965 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
4969 DBGPRINT(RT_DEBUG_TRACE, ("Query::unknown IOCTL's subcmd = 0x%08x\n", cmd));
4970 Status = -EOPNOTSUPP;
4976 INT rt28xx_sta_ioctl(
4977 IN struct net_device *net_dev,
4978 IN OUT struct ifreq *rq,
4982 VIRTUAL_ADAPTER *pVirtualAd = NULL;
4983 RTMP_ADAPTER *pAd = NULL;
4984 struct iwreq *wrq = (struct iwreq *) rq;
4985 BOOLEAN StateMachineTouched = FALSE;
4986 INT Status = NDIS_STATUS_SUCCESS;
4989 if (net_dev->priv_flags == INT_MAIN)
4991 pAd = net_dev->ml_priv;
4995 pVirtualAd = net_dev->ml_priv;
4996 pAd = pVirtualAd->RtmpDev->ml_priv;
4998 pObj = (POS_COOKIE) pAd->OS_Cookie;
5002 /* if 1st open fail, pAd will be free;
5003 So the net_dev->ml_priv will be NULL in 2rd open */
5007 //check if the interface is down
5008 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
5011 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
5016 { // determine this ioctl command is comming from which interface.
5017 pObj->ioctl_if_type = INT_MAIN;
5018 pObj->ioctl_if = MAIN_MBSSID;
5024 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIFHWADDR\n"));
5025 memcpy(wrq->u.name, pAd->CurrentAddress, ETH_ALEN);
5029 char *name=&wrq->u.name[0];
5030 rt_ioctl_giwname(net_dev, NULL, name, NULL);
5033 case SIOCGIWESSID: //Get ESSID
5035 struct iw_point *essid=&wrq->u.essid;
5036 rt_ioctl_giwessid(net_dev, NULL, essid, essid->pointer);
5039 case SIOCSIWESSID: //Set ESSID
5041 struct iw_point *essid=&wrq->u.essid;
5042 rt_ioctl_siwessid(net_dev, NULL, essid, essid->pointer);
5045 case SIOCSIWNWID: // set network id (the cell)
5046 case SIOCGIWNWID: // get network id
5047 Status = -EOPNOTSUPP;
5049 case SIOCSIWFREQ: //set channel/frequency (Hz)
5051 struct iw_freq *freq=&wrq->u.freq;
5052 rt_ioctl_siwfreq(net_dev, NULL, freq, NULL);
5055 case SIOCGIWFREQ: // get channel/frequency (Hz)
5057 struct iw_freq *freq=&wrq->u.freq;
5058 rt_ioctl_giwfreq(net_dev, NULL, freq, NULL);
5061 case SIOCSIWNICKN: //set node name/nickname
5063 struct iw_point *data=&wrq->u.data;
5064 rt_ioctl_siwnickn(net_dev, NULL, data, NULL);
5067 case SIOCGIWNICKN: //get node name/nickname
5069 struct iw_point *data=&wrq->u.data;
5070 rt_ioctl_giwnickn(net_dev, NULL, data, NULL);
5073 case SIOCGIWRATE: //get default bit rate (bps)
5074 rt_ioctl_giwrate(net_dev, NULL, &wrq->u, NULL);
5076 case SIOCSIWRATE: //set default bit rate (bps)
5077 rt_ioctl_siwrate(net_dev, NULL, &wrq->u, NULL);
5079 case SIOCGIWRTS: // get RTS/CTS threshold (bytes)
5081 struct iw_param *rts=&wrq->u.rts;
5082 rt_ioctl_giwrts(net_dev, NULL, rts, NULL);
5085 case SIOCSIWRTS: //set RTS/CTS threshold (bytes)
5087 struct iw_param *rts=&wrq->u.rts;
5088 rt_ioctl_siwrts(net_dev, NULL, rts, NULL);
5091 case SIOCGIWFRAG: //get fragmentation thr (bytes)
5093 struct iw_param *frag=&wrq->u.frag;
5094 rt_ioctl_giwfrag(net_dev, NULL, frag, NULL);
5097 case SIOCSIWFRAG: //set fragmentation thr (bytes)
5099 struct iw_param *frag=&wrq->u.frag;
5100 rt_ioctl_siwfrag(net_dev, NULL, frag, NULL);
5103 case SIOCGIWENCODE: //get encoding token & mode
5105 struct iw_point *erq=&wrq->u.encoding;
5107 rt_ioctl_giwencode(net_dev, NULL, erq, erq->pointer);
5110 case SIOCSIWENCODE: //set encoding token & mode
5112 struct iw_point *erq=&wrq->u.encoding;
5114 rt_ioctl_siwencode(net_dev, NULL, erq, erq->pointer);
5117 case SIOCGIWAP: //get access point MAC addresses
5119 struct sockaddr *ap_addr=&wrq->u.ap_addr;
5120 rt_ioctl_giwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
5123 case SIOCSIWAP: //set access point MAC addresses
5125 struct sockaddr *ap_addr=&wrq->u.ap_addr;
5126 rt_ioctl_siwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
5129 case SIOCGIWMODE: //get operation mode
5131 __u32 *mode=&wrq->u.mode;
5132 rt_ioctl_giwmode(net_dev, NULL, mode, NULL);
5135 case SIOCSIWMODE: //set operation mode
5137 __u32 *mode=&wrq->u.mode;
5138 rt_ioctl_siwmode(net_dev, NULL, mode, NULL);
5141 case SIOCGIWSENS: //get sensitivity (dBm)
5142 case SIOCSIWSENS: //set sensitivity (dBm)
5143 case SIOCGIWPOWER: //get Power Management settings
5144 case SIOCSIWPOWER: //set Power Management settings
5145 case SIOCGIWTXPOW: //get transmit power (dBm)
5146 case SIOCSIWTXPOW: //set transmit power (dBm)
5147 case SIOCGIWRANGE: //Get range of parameters
5148 case SIOCGIWRETRY: //get retry limits and lifetime
5149 case SIOCSIWRETRY: //set retry limits and lifetime
5150 Status = -EOPNOTSUPP;
5153 subcmd = wrq->u.data.flags;
5154 if( subcmd & OID_GET_SET_TOGGLE)
5155 Status = RTMPSetInformation(pAd, rq, subcmd);
5157 Status = RTMPQueryInformation(pAd, rq, subcmd);
5160 if (wrq->u.data.pointer)
5162 if ( access_ok(VERIFY_WRITE, wrq->u.data.pointer, sizeof(privtab)) != TRUE)
5164 wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
5165 if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
5169 case RTPRIV_IOCTL_SET:
5170 if(access_ok(VERIFY_READ, wrq->u.data.pointer, wrq->u.data.length) != TRUE)
5172 rt_ioctl_setparam(net_dev, NULL, NULL, wrq->u.data.pointer);
5174 case RTPRIV_IOCTL_GSITESURVEY:
5175 RTMPIoctlGetSiteSurvey(pAd, wrq);
5178 case RTPRIV_IOCTL_MAC:
5179 RTMPIoctlMAC(pAd, wrq);
5181 case RTPRIV_IOCTL_E2P:
5182 RTMPIoctlE2PROM(pAd, wrq);
5188 DBGPRINT(RT_DEBUG_ERROR, ("IOCTL::unknown IOCTL's cmd = 0x%08x\n", cmd));
5189 Status = -EOPNOTSUPP;
5193 if(StateMachineTouched) // Upper layer sent a MLME-related operations
5194 RT28XX_MLME_HANDLER(pAd);
5200 ==========================================================================
5204 TRUE if all parameters are OK, FALSE otherwise
5205 ==========================================================================
5208 IN PRTMP_ADAPTER pAdapter,
5211 NDIS_802_11_SSID Ssid, *pSsid=NULL;
5212 BOOLEAN StateMachineTouched = FALSE;
5215 if( strlen(arg) <= MAX_LEN_OF_SSID)
5217 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
5218 if (strlen(arg) != 0)
5220 NdisMoveMemory(Ssid.Ssid, arg, strlen(arg));
5221 Ssid.SsidLength = strlen(arg);
5225 Ssid.SsidLength = 0;
5226 memcpy(Ssid.Ssid, "", 0);
5227 pAdapter->StaCfg.BssType = BSS_INFRA;
5228 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
5229 pAdapter->StaCfg.WepStatus = Ndis802_11EncryptionDisabled;
5233 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
5235 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
5236 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
5239 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
5240 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
5241 pAdapter->bConfigChanged = TRUE;
5243 MlmeEnqueue(pAdapter,
5244 MLME_CNTL_STATE_MACHINE,
5246 sizeof(NDIS_802_11_SSID),
5249 StateMachineTouched = TRUE;
5250 DBGPRINT(RT_DEBUG_TRACE, ("Set_SSID_Proc::(Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
5255 if (StateMachineTouched) // Upper layer sent a MLME-related operations
5256 RT28XX_MLME_HANDLER(pAdapter);
5263 ==========================================================================
5265 Set WmmCapable Enable or Disable
5267 TRUE if all parameters are OK, FALSE otherwise
5268 ==========================================================================
5270 INT Set_WmmCapable_Proc(
5271 IN PRTMP_ADAPTER pAd,
5274 BOOLEAN bWmmCapable;
5276 bWmmCapable = simple_strtol(arg, 0, 10);
5278 if ((bWmmCapable == 1)
5280 && (pAd->NumberOfPipes >= 5)
5283 pAd->CommonCfg.bWmmCapable = TRUE;
5284 else if (bWmmCapable == 0)
5285 pAd->CommonCfg.bWmmCapable = FALSE;
5287 return FALSE; //Invalid argument
5289 DBGPRINT(RT_DEBUG_TRACE, ("Set_WmmCapable_Proc::(bWmmCapable=%d)\n",
5290 pAd->CommonCfg.bWmmCapable));
5294 #endif // WMM_SUPPORT //
5297 ==========================================================================
5299 Set Network Type(Infrastructure/Adhoc mode)
5301 TRUE if all parameters are OK, FALSE otherwise
5302 ==========================================================================
5304 INT Set_NetworkType_Proc(
5305 IN PRTMP_ADAPTER pAdapter,
5310 if (strcmp(arg, "Adhoc") == 0)
5312 if (pAdapter->StaCfg.BssType != BSS_ADHOC)
5314 // Config has changed
5315 pAdapter->bConfigChanged = TRUE;
5316 if (MONITOR_ON(pAdapter))
5318 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
5319 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5321 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5322 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5323 pAdapter->StaCfg.bAutoReconnect = TRUE;
5324 LinkDown(pAdapter, FALSE);
5326 if (INFRA_ON(pAdapter))
5328 //BOOLEAN Cancelled;
5329 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
5330 // Since calling this indicate user don't want to connect to that SSID anymore.
5331 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
5332 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
5334 LinkDown(pAdapter, FALSE);
5336 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n"));
5339 pAdapter->StaCfg.BssType = BSS_ADHOC;
5340 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
5341 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(AD-HOC)\n"));
5343 else if (strcmp(arg, "Infra") == 0)
5345 if (pAdapter->StaCfg.BssType != BSS_INFRA)
5347 // Config has changed
5348 pAdapter->bConfigChanged = TRUE;
5349 if (MONITOR_ON(pAdapter))
5351 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
5352 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5354 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5355 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5356 pAdapter->StaCfg.bAutoReconnect = TRUE;
5357 LinkDown(pAdapter, FALSE);
5359 if (ADHOC_ON(pAdapter))
5361 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
5362 // Since calling this indicate user don't want to connect to that SSID anymore.
5363 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
5364 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
5366 LinkDown(pAdapter, FALSE);
5369 pAdapter->StaCfg.BssType = BSS_INFRA;
5370 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
5371 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(INFRA)\n"));
5373 pAdapter->StaCfg.BssType = BSS_INFRA;
5375 else if (strcmp(arg, "Monitor") == 0)
5378 BCN_TIME_CFG_STRUC csr;
5379 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_INFRA_ON);
5380 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_ADHOC_ON);
5381 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5382 // disable all periodic state machine
5383 pAdapter->StaCfg.bAutoReconnect = FALSE;
5384 // reset all mlme state machine
5385 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
5386 DBGPRINT(RT_DEBUG_TRACE, ("fOP_STATUS_MEDIA_STATE_CONNECTED \n"));
5387 if (pAdapter->CommonCfg.CentralChannel == 0)
5389 #ifdef DOT11_N_SUPPORT
5390 if (pAdapter->CommonCfg.PhyMode == PHY_11AN_MIXED)
5391 pAdapter->CommonCfg.CentralChannel = 36;
5393 #endif // DOT11_N_SUPPORT //
5394 pAdapter->CommonCfg.CentralChannel = 6;
5396 #ifdef DOT11_N_SUPPORT
5398 N_ChannelCheck(pAdapter);
5399 #endif // DOT11_N_SUPPORT //
5401 #ifdef DOT11_N_SUPPORT
5402 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
5403 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
5404 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_ABOVE)
5406 // 40MHz ,control channel at lower
5407 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5408 bbpValue &= (~0x18);
5410 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5411 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
5412 // RX : control channel at lower
5413 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
5414 bbpValue &= (~0x20);
5415 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
5417 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
5418 Value &= 0xfffffffe;
5419 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
5420 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel + 2;
5421 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
5422 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
5423 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
5424 pAdapter->CommonCfg.Channel,
5425 pAdapter->CommonCfg.CentralChannel));
5427 else if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
5428 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
5429 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_BELOW)
5431 // 40MHz ,control channel at upper
5432 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5433 bbpValue &= (~0x18);
5435 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5436 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
5437 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
5439 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
5441 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
5443 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
5444 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel - 2;
5445 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
5446 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
5447 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
5448 pAdapter->CommonCfg.Channel,
5449 pAdapter->CommonCfg.CentralChannel));
5452 #endif // DOT11_N_SUPPORT //
5455 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5456 bbpValue &= (~0x18);
5457 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5458 pAdapter->CommonCfg.BBPCurrentBW = BW_20;
5459 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.Channel, FALSE);
5460 AsicLockChannel(pAdapter, pAdapter->CommonCfg.Channel);
5461 DBGPRINT(RT_DEBUG_TRACE, ("BW_20, Channel(%d)\n", pAdapter->CommonCfg.Channel));
5463 // Enable Rx with promiscuous reception
5464 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, 0x3);
5465 // ASIC supporsts sniffer function with replacing RSSI with timestamp.
5466 //RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5468 //RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5470 RTMP_IO_READ32(pAdapter, BCN_TIME_CFG, &csr.word);
5471 csr.field.bBeaconGen = 0;
5472 csr.field.bTBTTEnable = 0;
5473 csr.field.TsfSyncMode = 0;
5474 RTMP_IO_WRITE32(pAdapter, BCN_TIME_CFG, csr.word);
5476 pAdapter->StaCfg.BssType = BSS_MONITOR;
5477 pAdapter->net_dev->type = ARPHRD_IEEE80211_PRISM; //ARPHRD_IEEE80211; // IEEE80211
5478 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(MONITOR)\n"));
5481 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
5482 pAdapter->StaCfg.WpaState = SS_NOTUSE;
5484 DBGPRINT(RT_DEBUG_TRACE, ("Set_NetworkType_Proc::(NetworkType=%d)\n", pAdapter->StaCfg.BssType));
5490 ==========================================================================
5492 Set Authentication mode
5494 TRUE if all parameters are OK, FALSE otherwise
5495 ==========================================================================
5497 INT Set_AuthMode_Proc(
5498 IN PRTMP_ADAPTER pAdapter,
5501 if ((strcmp(arg, "WEPAUTO") == 0) || (strcmp(arg, "wepauto") == 0))
5502 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeAutoSwitch;
5503 else if ((strcmp(arg, "OPEN") == 0) || (strcmp(arg, "open") == 0))
5504 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
5505 else if ((strcmp(arg, "SHARED") == 0) || (strcmp(arg, "shared") == 0))
5506 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
5507 else if ((strcmp(arg, "WPAPSK") == 0) || (strcmp(arg, "wpapsk") == 0))
5508 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
5509 else if ((strcmp(arg, "WPANONE") == 0) || (strcmp(arg, "wpanone") == 0))
5510 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
5511 else if ((strcmp(arg, "WPA2PSK") == 0) || (strcmp(arg, "wpa2psk") == 0))
5512 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
5513 #ifdef WPA_SUPPLICANT_SUPPORT
5514 else if ((strcmp(arg, "WPA") == 0) || (strcmp(arg, "wpa") == 0))
5515 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
5516 else if ((strcmp(arg, "WPA2") == 0) || (strcmp(arg, "wpa2") == 0))
5517 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
5518 #endif // WPA_SUPPLICANT_SUPPORT //
5522 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
5524 DBGPRINT(RT_DEBUG_TRACE, ("Set_AuthMode_Proc::(AuthMode=%d)\n", pAdapter->StaCfg.AuthMode));
5530 ==========================================================================
5534 TRUE if all parameters are OK, FALSE otherwise
5535 ==========================================================================
5537 INT Set_EncrypType_Proc(
5538 IN PRTMP_ADAPTER pAdapter,
5541 if ((strcmp(arg, "NONE") == 0) || (strcmp(arg, "none") == 0))
5543 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5544 return TRUE; // do nothing
5546 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
5547 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
5548 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
5550 else if ((strcmp(arg, "WEP") == 0) || (strcmp(arg, "wep") == 0))
5552 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5553 return TRUE; // do nothing
5555 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
5556 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
5557 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
5559 else if ((strcmp(arg, "TKIP") == 0) || (strcmp(arg, "tkip") == 0))
5561 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
5562 return TRUE; // do nothing
5564 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
5565 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
5566 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
5568 else if ((strcmp(arg, "AES") == 0) || (strcmp(arg, "aes") == 0))
5570 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
5571 return TRUE; // do nothing
5573 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
5574 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
5575 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
5580 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
5582 DBGPRINT(RT_DEBUG_TRACE, ("Set_EncrypType_Proc::(EncrypType=%d)\n", pAdapter->StaCfg.WepStatus));
5588 ==========================================================================
5592 TRUE if all parameters are OK, FALSE otherwise
5593 ==========================================================================
5595 INT Set_DefaultKeyID_Proc(
5596 IN PRTMP_ADAPTER pAdapter,
5601 KeyIdx = simple_strtol(arg, 0, 10);
5602 if((KeyIdx >= 1 ) && (KeyIdx <= 4))
5603 pAdapter->StaCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1 );
5605 return FALSE; //Invalid argument
5607 DBGPRINT(RT_DEBUG_TRACE, ("Set_DefaultKeyID_Proc::(DefaultKeyID=%d)\n", pAdapter->StaCfg.DefaultKeyId));
5613 ==========================================================================
5617 TRUE if all parameters are OK, FALSE otherwise
5618 ==========================================================================
5621 IN PRTMP_ADAPTER pAdapter,
5626 UCHAR CipherAlg=CIPHER_WEP64;
5628 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5629 return TRUE; // do nothing
5631 KeyLen = strlen(arg);
5635 case 5: //wep 40 Ascii type
5636 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
5637 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
5638 CipherAlg = CIPHER_WEP64;
5639 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
5641 case 10: //wep 40 Hex type
5642 for(i=0; i < KeyLen; i++)
5644 if( !isxdigit(*(arg+i)) )
5645 return FALSE; //Not Hex value;
5647 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
5648 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
5649 CipherAlg = CIPHER_WEP64;
5650 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
5652 case 13: //wep 104 Ascii type
5653 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
5654 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
5655 CipherAlg = CIPHER_WEP128;
5656 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
5658 case 26: //wep 104 Hex type
5659 for(i=0; i < KeyLen; i++)
5661 if( !isxdigit(*(arg+i)) )
5662 return FALSE; //Not Hex value;
5664 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
5665 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
5666 CipherAlg = CIPHER_WEP128;
5667 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
5669 default: //Invalid argument
5670 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::Invalid argument (=%s)\n", arg));
5674 pAdapter->SharedKey[BSS0][0].CipherAlg = CipherAlg;
5676 // Set keys (into ASIC)
5677 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5679 else // Old WEP stuff
5681 AsicAddSharedKeyEntry(pAdapter,
5684 pAdapter->SharedKey[BSS0][0].CipherAlg,
5685 pAdapter->SharedKey[BSS0][0].Key,
5693 ==========================================================================
5698 TRUE if all parameters are OK, FALSE otherwise
5699 ==========================================================================
5702 IN PRTMP_ADAPTER pAdapter,
5707 UCHAR CipherAlg=CIPHER_WEP64;
5709 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5710 return TRUE; // do nothing
5712 KeyLen = strlen(arg);
5716 case 5: //wep 40 Ascii type
5717 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
5718 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
5719 CipherAlg = CIPHER_WEP64;
5720 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
5722 case 10: //wep 40 Hex type
5723 for(i=0; i < KeyLen; i++)
5725 if( !isxdigit(*(arg+i)) )
5726 return FALSE; //Not Hex value;
5728 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
5729 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
5730 CipherAlg = CIPHER_WEP64;
5731 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
5733 case 13: //wep 104 Ascii type
5734 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
5735 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
5736 CipherAlg = CIPHER_WEP128;
5737 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
5739 case 26: //wep 104 Hex type
5740 for(i=0; i < KeyLen; i++)
5742 if( !isxdigit(*(arg+i)) )
5743 return FALSE; //Not Hex value;
5745 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
5746 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
5747 CipherAlg = CIPHER_WEP128;
5748 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
5750 default: //Invalid argument
5751 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::Invalid argument (=%s)\n", arg));
5754 pAdapter->SharedKey[BSS0][1].CipherAlg = CipherAlg;
5756 // Set keys (into ASIC)
5757 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5759 else // Old WEP stuff
5761 AsicAddSharedKeyEntry(pAdapter,
5764 pAdapter->SharedKey[BSS0][1].CipherAlg,
5765 pAdapter->SharedKey[BSS0][1].Key,
5773 ==========================================================================
5777 TRUE if all parameters are OK, FALSE otherwise
5778 ==========================================================================
5781 IN PRTMP_ADAPTER pAdapter,
5786 UCHAR CipherAlg=CIPHER_WEP64;
5788 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5789 return TRUE; // do nothing
5791 KeyLen = strlen(arg);
5795 case 5: //wep 40 Ascii type
5796 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
5797 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
5798 CipherAlg = CIPHER_WEP64;
5799 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
5801 case 10: //wep 40 Hex type
5802 for(i=0; i < KeyLen; i++)
5804 if( !isxdigit(*(arg+i)) )
5805 return FALSE; //Not Hex value;
5807 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
5808 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
5809 CipherAlg = CIPHER_WEP64;
5810 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
5812 case 13: //wep 104 Ascii type
5813 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
5814 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
5815 CipherAlg = CIPHER_WEP128;
5816 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
5818 case 26: //wep 104 Hex type
5819 for(i=0; i < KeyLen; i++)
5821 if( !isxdigit(*(arg+i)) )
5822 return FALSE; //Not Hex value;
5824 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
5825 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
5826 CipherAlg = CIPHER_WEP128;
5827 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
5829 default: //Invalid argument
5830 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::Invalid argument (=%s)\n", arg));
5833 pAdapter->SharedKey[BSS0][2].CipherAlg = CipherAlg;
5835 // Set keys (into ASIC)
5836 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5838 else // Old WEP stuff
5840 AsicAddSharedKeyEntry(pAdapter,
5843 pAdapter->SharedKey[BSS0][2].CipherAlg,
5844 pAdapter->SharedKey[BSS0][2].Key,
5852 ==========================================================================
5856 TRUE if all parameters are OK, FALSE otherwise
5857 ==========================================================================
5860 IN PRTMP_ADAPTER pAdapter,
5865 UCHAR CipherAlg=CIPHER_WEP64;
5867 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5868 return TRUE; // do nothing
5870 KeyLen = strlen(arg);
5874 case 5: //wep 40 Ascii type
5875 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
5876 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
5877 CipherAlg = CIPHER_WEP64;
5878 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
5880 case 10: //wep 40 Hex type
5881 for(i=0; i < KeyLen; i++)
5883 if( !isxdigit(*(arg+i)) )
5884 return FALSE; //Not Hex value;
5886 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
5887 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
5888 CipherAlg = CIPHER_WEP64;
5889 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
5891 case 13: //wep 104 Ascii type
5892 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
5893 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
5894 CipherAlg = CIPHER_WEP128;
5895 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
5897 case 26: //wep 104 Hex type
5898 for(i=0; i < KeyLen; i++)
5900 if( !isxdigit(*(arg+i)) )
5901 return FALSE; //Not Hex value;
5903 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
5904 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
5905 CipherAlg = CIPHER_WEP128;
5906 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
5908 default: //Invalid argument
5909 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::Invalid argument (=%s)\n", arg));
5912 pAdapter->SharedKey[BSS0][3].CipherAlg = CipherAlg;
5914 // Set keys (into ASIC)
5915 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5917 else // Old WEP stuff
5919 AsicAddSharedKeyEntry(pAdapter,
5922 pAdapter->SharedKey[BSS0][3].CipherAlg,
5923 pAdapter->SharedKey[BSS0][3].Key,
5932 ==========================================================================
5936 TRUE if all parameters are OK, FALSE otherwise
5937 ==========================================================================
5939 INT Set_WPAPSK_Proc(
5940 IN PRTMP_ADAPTER pAdapter,
5943 UCHAR keyMaterial[40];
5945 if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
5946 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
5947 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
5949 return TRUE; // do nothing
5951 DBGPRINT(RT_DEBUG_TRACE, ("Set_WPAPSK_Proc::(WPAPSK=%s)\n", arg));
5953 NdisZeroMemory(keyMaterial, 40);
5955 if ((strlen(arg) < 8) || (strlen(arg) > 64))
5957 DBGPRINT(RT_DEBUG_TRACE, ("Set failed!!(WPAPSK=%s), WPAPSK key-string required 8 ~ 64 characters \n", arg));
5961 if (strlen(arg) == 64)
5963 AtoH(arg, keyMaterial, 32);
5964 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
5969 PasswordHash((char *)arg, pAdapter->MlmeAux.Ssid, pAdapter->MlmeAux.SsidLen, keyMaterial);
5970 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
5975 if(pAdapter->StaCfg.BssType == BSS_ADHOC &&
5976 pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
5978 pAdapter->StaCfg.WpaState = SS_NOTUSE;
5982 // Start STA supplicant state machine
5983 pAdapter->StaCfg.WpaState = SS_START;
5990 ==========================================================================
5992 Set Power Saving mode
5994 TRUE if all parameters are OK, FALSE otherwise
5995 ==========================================================================
5997 INT Set_PSMode_Proc(
5998 IN PRTMP_ADAPTER pAdapter,
6001 if (pAdapter->StaCfg.BssType == BSS_INFRA)
6003 if ((strcmp(arg, "Max_PSP") == 0) ||
6004 (strcmp(arg, "max_psp") == 0) ||
6005 (strcmp(arg, "MAX_PSP") == 0))
6007 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6008 // to exclude certain situations.
6009 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6010 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeMAX_PSP;
6011 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeMAX_PSP;
6012 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6013 pAdapter->StaCfg.DefaultListenCount = 5;
6016 else if ((strcmp(arg, "Fast_PSP") == 0) ||
6017 (strcmp(arg, "fast_psp") == 0) ||
6018 (strcmp(arg, "FAST_PSP") == 0))
6020 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6021 // to exclude certain situations.
6022 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6023 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6024 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeFast_PSP;
6025 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeFast_PSP;
6026 pAdapter->StaCfg.DefaultListenCount = 3;
6028 else if ((strcmp(arg, "Legacy_PSP") == 0) ||
6029 (strcmp(arg, "legacy_psp") == 0) ||
6030 (strcmp(arg, "LEGACY_PSP") == 0))
6032 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6033 // to exclude certain situations.
6034 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6035 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6036 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeLegacy_PSP;
6037 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeLegacy_PSP;
6038 pAdapter->StaCfg.DefaultListenCount = 3;
6042 //Default Ndis802_11PowerModeCAM
6043 // clear PSM bit immediately
6044 MlmeSetPsmBit(pAdapter, PWR_ACTIVE);
6045 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6046 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6047 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
6048 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
6051 DBGPRINT(RT_DEBUG_TRACE, ("Set_PSMode_Proc::(PSMode=%ld)\n", pAdapter->StaCfg.WindowsPowerMode));
6060 #ifdef WPA_SUPPLICANT_SUPPORT
6062 ==========================================================================
6064 Set WpaSupport flag.
6066 0: Driver ignore wpa_supplicant.
6067 1: wpa_supplicant initiates scanning and AP selection.
6068 2: driver takes care of scanning, AP selection, and IEEE 802.11 association parameters.
6070 TRUE if all parameters are OK, FALSE otherwise
6071 ==========================================================================
6073 INT Set_Wpa_Support(
6074 IN PRTMP_ADAPTER pAd,
6078 if ( simple_strtol(arg, 0, 10) == 0)
6079 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
6080 else if ( simple_strtol(arg, 0, 10) == 1)
6081 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE;
6082 else if ( simple_strtol(arg, 0, 10) == 2)
6083 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE_WITH_WEB_UI;
6085 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
6087 DBGPRINT(RT_DEBUG_TRACE, ("Set_Wpa_Support::(WpaSupplicantUP=%d)\n", pAd->StaCfg.WpaSupplicantUP));
6091 #endif // WPA_SUPPLICANT_SUPPORT //
6095 ==========================================================================
6099 pAdapter Pointer to our adapter
6100 wrq Pointer to the ioctl argument
6107 1.) iwpriv ra0 mac 0 ==> read MAC where Addr=0x0
6108 2.) iwpriv ra0 mac 0=12 ==> write MAC where Addr=0x0, value=12
6109 ==========================================================================
6112 IN PRTMP_ADAPTER pAdapter,
6113 IN struct iwreq *wrq)
6121 UCHAR temp[16], temp2[16];
6122 UINT32 macValue = 0;
6126 memset(msg, 0x00, 1024);
6127 if (wrq->u.data.length > 1) //No parameters.
6129 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6132 //Parsing Read or Write
6137 if ((value = rtstrchr(this_char, '=')) != NULL)
6140 if (!value || !*value)
6143 if(strlen(this_char) > 4)
6146 j = strlen(this_char);
6149 if(this_char[j] > 'f' || this_char[j] < '0')
6154 k = j = strlen(this_char);
6157 this_char[4-k+j] = this_char[j];
6161 this_char[3-k++]='0';
6164 if(strlen(this_char) == 4)
6166 AtoH(this_char, temp, 2);
6167 macAddr = *temp*256 + temp[1];
6168 if (macAddr < 0xFFFF)
6170 RTMP_IO_READ32(pAdapter, macAddr, &macValue);
6171 DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%lx, MacValue=%x\n", macAddr, macValue));
6172 sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr , macValue);
6175 {//Invalid parametes, so default printk all bbp
6182 memcpy(&temp2, value, strlen(value));
6183 temp2[strlen(value)] = '\0';
6186 if((strlen(this_char) > 4) || strlen(temp2) > 8)
6189 j = strlen(this_char);
6192 if(this_char[j] > 'f' || this_char[j] < '0')
6199 if(temp2[j] > 'f' || temp2[j] < '0')
6204 k = j = strlen(this_char);
6207 this_char[4-k+j] = this_char[j];
6211 this_char[3-k++]='0';
6215 k = j = strlen(temp2);
6218 temp2[8-k+j] = temp2[j];
6226 AtoH(this_char, temp, 2);
6227 macAddr = *temp*256 + temp[1];
6229 AtoH(temp2, temp, 4);
6230 macValue = *temp*256*256*256 + temp[1]*256*256 + temp[2]*256 + temp[3];
6233 if (macAddr == (HW_DEBUG_SETTING_BASE + 4))
6235 // 0x2bf4: byte0 non-zero: enable R17 tuning, 0: disable R17 tuning
6236 if (macValue & 0x000000ff)
6238 pAdapter->BbpTuning.bEnable = TRUE;
6239 DBGPRINT(RT_DEBUG_TRACE,("turn on R17 tuning\n"));
6244 pAdapter->BbpTuning.bEnable = FALSE;
6245 R66 = 0x26 + GET_LNA_GAIN(pAdapter);
6246 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R66, (0x26 + GET_LNA_GAIN(pAdapter)));
6247 DBGPRINT(RT_DEBUG_TRACE,("turn off R17 tuning, restore to 0x%02x\n", R66));
6252 DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%02lx, MacValue=0x%x\n", macAddr, macValue));
6254 RTMP_IO_WRITE32(pAdapter, macAddr, macValue);
6255 sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr, macValue);
6260 if(strlen(msg) == 1)
6261 sprintf(msg+strlen(msg), "===>Error command format!");
6263 // Copy the information into the user buffer
6264 wrq->u.data.length = strlen(msg);
6265 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6267 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlMAC\n\n"));
6271 ==========================================================================
6275 pAdapter Pointer to our adapter
6276 wrq Pointer to the ioctl argument
6283 1.) iwpriv ra0 e2p 0 ==> read E2PROM where Addr=0x0
6284 2.) iwpriv ra0 e2p 0=1234 ==> write E2PROM where Addr=0x0, value=1234
6285 ==========================================================================
6287 VOID RTMPIoctlE2PROM(
6288 IN PRTMP_ADAPTER pAdapter,
6289 IN struct iwreq *wrq)
6297 UCHAR temp[16], temp2[16];
6302 memset(msg, 0x00, 1024);
6303 if (wrq->u.data.length > 1) //No parameters.
6305 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6308 //Parsing Read or Write
6315 if ((value = rtstrchr(this_char, '=')) != NULL)
6318 if (!value || !*value)
6322 if(strlen(this_char) > 4)
6325 j = strlen(this_char);
6328 if(this_char[j] > 'f' || this_char[j] < '0')
6333 k = j = strlen(this_char);
6336 this_char[4-k+j] = this_char[j];
6340 this_char[3-k++]='0';
6343 if(strlen(this_char) == 4)
6345 AtoH(this_char, temp, 2);
6346 eepAddr = *temp*256 + temp[1];
6347 if (eepAddr < 0xFFFF)
6349 RT28xx_EEPROM_READ16(pAdapter, eepAddr, eepValue);
6350 sprintf(msg+strlen(msg), "[0x%04X]:0x%04X ", eepAddr , eepValue);
6353 {//Invalid parametes, so default printk all bbp
6360 memcpy(&temp2, value, strlen(value));
6361 temp2[strlen(value)] = '\0';
6364 if((strlen(this_char) > 4) || strlen(temp2) > 8)
6367 j = strlen(this_char);
6370 if(this_char[j] > 'f' || this_char[j] < '0')
6376 if(temp2[j] > 'f' || temp2[j] < '0')
6381 k = j = strlen(this_char);
6384 this_char[4-k+j] = this_char[j];
6388 this_char[3-k++]='0';
6392 k = j = strlen(temp2);
6395 temp2[4-k+j] = temp2[j];
6402 AtoH(this_char, temp, 2);
6403 eepAddr = *temp*256 + temp[1];
6405 AtoH(temp2, temp, 2);
6406 eepValue = *temp*256 + temp[1];
6408 RT28xx_EEPROM_WRITE16(pAdapter, eepAddr, eepValue);
6409 sprintf(msg+strlen(msg), "[0x%02X]:%02X ", eepAddr, eepValue);
6413 if(strlen(msg) == 1)
6414 sprintf(msg+strlen(msg), "===>Error command format!");
6417 // Copy the information into the user buffer
6418 wrq->u.data.length = strlen(msg);
6419 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6421 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlE2PROM\n"));
6428 INT Set_TGnWifiTest_Proc(
6429 IN PRTMP_ADAPTER pAd,
6432 if (simple_strtol(arg, 0, 10) == 0)
6433 pAd->StaCfg.bTGnWifiTest = FALSE;
6435 pAd->StaCfg.bTGnWifiTest = TRUE;
6437 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_TGnWifiTest_Proc::(bTGnWifiTest=%d)\n", pAd->StaCfg.bTGnWifiTest));
6441 INT Set_LongRetryLimit_Proc(
6442 IN PRTMP_ADAPTER pAdapter,
6445 TX_RTY_CFG_STRUC tx_rty_cfg;
6446 UCHAR LongRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
6448 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
6449 tx_rty_cfg.field.LongRtyLimit = LongRetryLimit;
6450 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
6451 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_LongRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
6455 INT Set_ShortRetryLimit_Proc(
6456 IN PRTMP_ADAPTER pAdapter,
6459 TX_RTY_CFG_STRUC tx_rty_cfg;
6460 UCHAR ShortRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
6462 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
6463 tx_rty_cfg.field.ShortRtyLimit = ShortRetryLimit;
6464 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
6465 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_ShortRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
6469 INT Show_Adhoc_MacTable_Proc(
6470 IN PRTMP_ADAPTER pAd,
6475 sprintf(extra, "\n");
6477 #ifdef DOT11_N_SUPPORT
6478 sprintf(extra + strlen(extra), "HT Operating Mode : %d\n", pAd->CommonCfg.AddHTInfo.AddHtInfo2.OperaionMode);
6479 #endif // DOT11_N_SUPPORT //
6481 sprintf(extra + strlen(extra), "\n%-19s%-4s%-4s%-7s%-7s%-7s%-10s%-6s%-6s%-6s%-6s\n",
6482 "MAC", "AID", "BSS", "RSSI0", "RSSI1", "RSSI2", "PhMd", "BW", "MCS", "SGI", "STBC");
6484 for (i=1; i<MAX_LEN_OF_MAC_TABLE; i++)
6486 PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
6488 if (strlen(extra) > (IW_PRIV_SIZE_MASK - 30))
6490 if ((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
6492 sprintf(extra + strlen(extra), "%02X:%02X:%02X:%02X:%02X:%02X ",
6493 pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
6494 pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5]);
6495 sprintf(extra + strlen(extra), "%-4d", (int)pEntry->Aid);
6496 sprintf(extra + strlen(extra), "%-4d", (int)pEntry->apidx);
6497 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi0);
6498 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi1);
6499 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi2);
6500 sprintf(extra + strlen(extra), "%-10s", GetPhyMode(pEntry->HTPhyMode.field.MODE));
6501 sprintf(extra + strlen(extra), "%-6s", GetBW(pEntry->HTPhyMode.field.BW));
6502 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.MCS);
6503 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.ShortGI);
6504 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.STBC);
6505 sprintf(extra + strlen(extra), "%-10d, %d, %d%%\n", pEntry->DebugFIFOCount, pEntry->DebugTxCount,
6506 (pEntry->DebugTxCount) ? ((pEntry->DebugTxCount-pEntry->DebugFIFOCount)*100/pEntry->DebugTxCount) : 0);
6507 sprintf(extra, "%s\n", extra);