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;
2657 #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
2659 if (pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
2661 if (wrqu->data.length < pAd->StaCfg.RSNIE_Len)
2664 wrqu->data.length = pAd->StaCfg.RSNIE_Len;
2665 memcpy(extra, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
2668 #endif // SIOCSIWGENIE //
2669 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
2671 UCHAR RSNIe = IE_WPA;
2673 if (wrqu->data.length < (pAd->StaCfg.RSNIE_Len + 2)) // ID, Len
2675 wrqu->data.length = pAd->StaCfg.RSNIE_Len + 2;
2677 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
2678 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2))
2681 extra[0] = (char)RSNIe;
2682 extra[1] = pAd->StaCfg.RSNIE_Len;
2683 memcpy(extra+2, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
2689 int rt_ioctl_siwpmksa(struct net_device *dev,
2690 struct iw_request_info *info,
2691 union iwreq_data *wrqu,
2694 PRTMP_ADAPTER pAd = dev->ml_priv;
2695 struct iw_pmksa *pPmksa = (struct iw_pmksa *)wrqu->data.pointer;
2696 INT CachedIdx = 0, idx = 0;
2701 DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_siwpmksa\n"));
2704 case IW_PMKSA_FLUSH:
2705 NdisZeroMemory(pAd->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
2706 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_FLUSH\n"));
2708 case IW_PMKSA_REMOVE:
2709 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
2711 // compare the BSSID
2712 if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
2714 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN);
2715 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].PMKID, 16);
2716 for (idx = CachedIdx; idx < (pAd->StaCfg.SavedPMKNum - 1); idx++)
2718 NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].BSSID[0], &pAd->StaCfg.SavedPMK[idx+1].BSSID[0], MAC_ADDR_LEN);
2719 NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].PMKID[0], &pAd->StaCfg.SavedPMK[idx+1].PMKID[0], 16);
2721 pAd->StaCfg.SavedPMKNum--;
2726 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_REMOVE\n"));
2729 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
2731 // compare the BSSID
2732 if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
2736 // Found, replace it
2737 if (CachedIdx < PMKID_NO)
2739 DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
2740 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
2741 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
2742 pAd->StaCfg.SavedPMKNum++;
2744 // Not found, replace the last one
2747 // Randomly replace one
2748 CachedIdx = (pPmksa->bssid.sa_data[5] % PMKID_NO);
2749 DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
2750 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
2751 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
2754 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_ADD\n"));
2757 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - Unknow Command!!\n"));
2763 #endif // #if WIRELESS_EXT > 17
2767 rt_private_ioctl_bbp(struct net_device *dev, struct iw_request_info *info,
2768 struct iw_point *wrq, char *extra)
2773 // CHAR arg[255]={0};
2776 BOOLEAN bIsPrintAllBBP = FALSE;
2778 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2781 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2783 if (wrq->length > 1) //No parameters.
2785 sprintf(extra, "\n");
2787 //Parsing Read or Write
2788 this_char = wrq->pointer;
2789 DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s\n", this_char));
2793 if ((value = rtstrchr(this_char, '=')) != NULL)
2796 if (!value || !*value)
2798 DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s, value=%s\n", this_char, value));
2799 if (sscanf(this_char, "%d", &(bbpId)) == 1)
2804 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
2806 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
2807 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2808 DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
2811 {//Invalid parametes, so default printk all bbp
2812 bIsPrintAllBBP = TRUE;
2817 { //Invalid parametes, so default printk all bbp
2818 bIsPrintAllBBP = TRUE;
2824 if ((sscanf(this_char, "%d", &(bbpId)) == 1) && (sscanf(value, "%x", &(bbpValue)) == 1))
2829 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, bbpId, bbpValue);
2830 //Read it back for showing
2831 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
2833 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
2834 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2835 DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
2838 {//Invalid parametes, so default printk all bbp
2839 bIsPrintAllBBP = TRUE;
2844 { //Invalid parametes, so default printk all bbp
2845 bIsPrintAllBBP = TRUE;
2851 bIsPrintAllBBP = TRUE;
2856 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2857 sprintf(extra, "\n");
2858 for (bbpId = 0; bbpId <= 136; bbpId++)
2860 if (strlen(extra) >= (IW_PRIV_SIZE_MASK - 10))
2862 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
2863 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X ", bbpId, bbpId*2, regBBP);
2865 sprintf(extra+strlen(extra), "\n");
2868 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2869 DBGPRINT(RT_DEBUG_TRACE, ("wrq->length = %d\n", wrq->length));
2872 DBGPRINT(RT_DEBUG_TRACE, ("<==rt_private_ioctl_bbp\n\n"));
2878 int rt_ioctl_siwrate(struct net_device *dev,
2879 struct iw_request_info *info,
2880 union iwreq_data *wrqu, char *extra)
2882 PRTMP_ADAPTER pAd = dev->ml_priv;
2883 UINT32 rate = wrqu->bitrate.value, fixed = wrqu->bitrate.fixed;
2885 //check if the interface is down
2886 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2888 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::Network is down!\n"));
2892 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(rate = %d, fixed = %d)\n", rate, fixed));
2893 /* rate = -1 => auto rate
2894 rate = X, fixed = 1 => (fixed rate X)
2899 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
2900 pAd->StaCfg.bAutoTxRateSwitch = TRUE;
2901 if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
2902 (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
2903 RTMPSetDesiredRates(pAd, -1);
2905 #ifdef DOT11_N_SUPPORT
2907 #endif // DOT11_N_SUPPORT //
2913 pAd->StaCfg.bAutoTxRateSwitch = FALSE;
2914 if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
2915 (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
2916 RTMPSetDesiredRates(pAd, rate);
2919 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
2920 #ifdef DOT11_N_SUPPORT
2922 #endif // DOT11_N_SUPPORT //
2924 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(HtMcs=%d)\n",pAd->StaCfg.DesiredTransmitSetting.field.MCS));
2928 // TODO: rate = X, fixed = 0 => (rates <= X)
2936 int rt_ioctl_giwrate(struct net_device *dev,
2937 struct iw_request_info *info,
2938 union iwreq_data *wrqu, char *extra)
2940 PRTMP_ADAPTER pAd = dev->ml_priv;
2941 int rate_index = 0, rate_count = 0;
2942 HTTRANSMIT_SETTING ht_setting;
2943 __s32 ralinkrate[] =
2944 {2, 4, 11, 22, // CCK
2945 12, 18, 24, 36, 48, 72, 96, 108, // OFDM
2946 13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260, // 20MHz, 800ns GI, MCS: 0 ~ 15
2947 39, 78, 117, 156, 234, 312, 351, 390, // 20MHz, 800ns GI, MCS: 16 ~ 23
2948 27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540, // 40MHz, 800ns GI, MCS: 0 ~ 15
2949 81, 162, 243, 324, 486, 648, 729, 810, // 40MHz, 800ns GI, MCS: 16 ~ 23
2950 14, 29, 43, 57, 87, 115, 130, 144, 29, 59, 87, 115, 173, 230, 260, 288, // 20MHz, 400ns GI, MCS: 0 ~ 15
2951 43, 87, 130, 173, 260, 317, 390, 433, // 20MHz, 400ns GI, MCS: 16 ~ 23
2952 30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600, // 40MHz, 400ns GI, MCS: 0 ~ 15
2953 90, 180, 270, 360, 540, 720, 810, 900}; // 40MHz, 400ns GI, MCS: 16 ~ 23
2955 rate_count = sizeof(ralinkrate)/sizeof(__s32);
2956 //check if the interface is down
2957 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2959 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2963 if ((pAd->StaCfg.bAutoTxRateSwitch == FALSE) &&
2965 ((pAd->CommonCfg.PhyMode <= PHY_11G) || (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM)))
2966 ht_setting.word = pAd->StaCfg.HTPhyMode.word;
2968 ht_setting.word = pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word;
2970 #ifdef DOT11_N_SUPPORT
2971 if (ht_setting.field.MODE >= MODE_HTMIX)
2973 // rate_index = 12 + ((UCHAR)ht_setting.field.BW *16) + ((UCHAR)ht_setting.field.ShortGI *32) + ((UCHAR)ht_setting.field.MCS);
2974 rate_index = 12 + ((UCHAR)ht_setting.field.BW *24) + ((UCHAR)ht_setting.field.ShortGI *48) + ((UCHAR)ht_setting.field.MCS);
2977 #endif // DOT11_N_SUPPORT //
2978 if (ht_setting.field.MODE == MODE_OFDM)
2979 rate_index = (UCHAR)(ht_setting.field.MCS) + 4;
2980 else if (ht_setting.field.MODE == MODE_CCK)
2981 rate_index = (UCHAR)(ht_setting.field.MCS);
2986 if (rate_index > rate_count)
2987 rate_index = rate_count;
2989 wrqu->bitrate.value = ralinkrate[rate_index] * 500000;
2990 wrqu->bitrate.disabled = 0;
2995 static const iw_handler rt_handler[] =
2997 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2998 (iw_handler) rt_ioctl_giwname, /* SIOCGIWNAME */
2999 (iw_handler) NULL, /* SIOCSIWNWID */
3000 (iw_handler) NULL, /* SIOCGIWNWID */
3001 (iw_handler) rt_ioctl_siwfreq, /* SIOCSIWFREQ */
3002 (iw_handler) rt_ioctl_giwfreq, /* SIOCGIWFREQ */
3003 (iw_handler) rt_ioctl_siwmode, /* SIOCSIWMODE */
3004 (iw_handler) rt_ioctl_giwmode, /* SIOCGIWMODE */
3005 (iw_handler) NULL, /* SIOCSIWSENS */
3006 (iw_handler) NULL, /* SIOCGIWSENS */
3007 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
3008 (iw_handler) rt_ioctl_giwrange, /* SIOCGIWRANGE */
3009 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
3010 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
3011 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
3012 (iw_handler) rt28xx_get_wireless_stats /* kernel code */, /* SIOCGIWSTATS */
3013 (iw_handler) NULL, /* SIOCSIWSPY */
3014 (iw_handler) NULL, /* SIOCGIWSPY */
3015 (iw_handler) NULL, /* SIOCSIWTHRSPY */
3016 (iw_handler) NULL, /* SIOCGIWTHRSPY */
3017 (iw_handler) rt_ioctl_siwap, /* SIOCSIWAP */
3018 (iw_handler) rt_ioctl_giwap, /* SIOCGIWAP */
3020 (iw_handler) rt_ioctl_siwmlme, /* SIOCSIWMLME */
3022 (iw_handler) NULL, /* SIOCSIWMLME */
3023 #endif // SIOCSIWMLME //
3024 (iw_handler) rt_ioctl_iwaplist, /* SIOCGIWAPLIST */
3026 (iw_handler) rt_ioctl_siwscan, /* SIOCSIWSCAN */
3027 (iw_handler) rt_ioctl_giwscan, /* SIOCGIWSCAN */
3029 (iw_handler) NULL, /* SIOCSIWSCAN */
3030 (iw_handler) NULL, /* SIOCGIWSCAN */
3031 #endif /* SIOCGIWSCAN */
3032 (iw_handler) rt_ioctl_siwessid, /* SIOCSIWESSID */
3033 (iw_handler) rt_ioctl_giwessid, /* SIOCGIWESSID */
3034 (iw_handler) rt_ioctl_siwnickn, /* SIOCSIWNICKN */
3035 (iw_handler) rt_ioctl_giwnickn, /* SIOCGIWNICKN */
3036 (iw_handler) NULL, /* -- hole -- */
3037 (iw_handler) NULL, /* -- hole -- */
3038 (iw_handler) rt_ioctl_siwrate, /* SIOCSIWRATE */
3039 (iw_handler) rt_ioctl_giwrate, /* SIOCGIWRATE */
3040 (iw_handler) rt_ioctl_siwrts, /* SIOCSIWRTS */
3041 (iw_handler) rt_ioctl_giwrts, /* SIOCGIWRTS */
3042 (iw_handler) rt_ioctl_siwfrag, /* SIOCSIWFRAG */
3043 (iw_handler) rt_ioctl_giwfrag, /* SIOCGIWFRAG */
3044 (iw_handler) NULL, /* SIOCSIWTXPOW */
3045 (iw_handler) NULL, /* SIOCGIWTXPOW */
3046 (iw_handler) NULL, /* SIOCSIWRETRY */
3047 (iw_handler) NULL, /* SIOCGIWRETRY */
3048 (iw_handler) rt_ioctl_siwencode, /* SIOCSIWENCODE */
3049 (iw_handler) rt_ioctl_giwencode, /* SIOCGIWENCODE */
3050 (iw_handler) NULL, /* SIOCSIWPOWER */
3051 (iw_handler) NULL, /* SIOCGIWPOWER */
3052 (iw_handler) NULL, /* -- hole -- */
3053 (iw_handler) NULL, /* -- hole -- */
3054 #if WIRELESS_EXT > 17
3055 (iw_handler) rt_ioctl_siwgenie, /* SIOCSIWGENIE */
3056 (iw_handler) rt_ioctl_giwgenie, /* SIOCGIWGENIE */
3057 (iw_handler) rt_ioctl_siwauth, /* SIOCSIWAUTH */
3058 (iw_handler) rt_ioctl_giwauth, /* SIOCGIWAUTH */
3059 (iw_handler) rt_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
3060 (iw_handler) rt_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */
3061 (iw_handler) rt_ioctl_siwpmksa, /* SIOCSIWPMKSA */
3065 static const iw_handler rt_priv_handlers[] = {
3066 (iw_handler) NULL, /* + 0x00 */
3067 (iw_handler) NULL, /* + 0x01 */
3068 #ifndef CONFIG_AP_SUPPORT
3069 (iw_handler) rt_ioctl_setparam, /* + 0x02 */
3071 (iw_handler) NULL, /* + 0x02 */
3072 #endif // CONFIG_AP_SUPPORT //
3074 (iw_handler) rt_private_ioctl_bbp, /* + 0x03 */
3076 (iw_handler) NULL, /* + 0x03 */
3078 (iw_handler) NULL, /* + 0x04 */
3079 (iw_handler) NULL, /* + 0x05 */
3080 (iw_handler) NULL, /* + 0x06 */
3081 (iw_handler) NULL, /* + 0x07 */
3082 (iw_handler) NULL, /* + 0x08 */
3083 (iw_handler) rt_private_get_statistics, /* + 0x09 */
3084 (iw_handler) NULL, /* + 0x0A */
3085 (iw_handler) NULL, /* + 0x0B */
3086 (iw_handler) NULL, /* + 0x0C */
3087 (iw_handler) NULL, /* + 0x0D */
3088 (iw_handler) NULL, /* + 0x0E */
3089 (iw_handler) NULL, /* + 0x0F */
3090 (iw_handler) NULL, /* + 0x10 */
3091 (iw_handler) rt_private_show, /* + 0x11 */
3092 (iw_handler) NULL, /* + 0x12 */
3093 (iw_handler) NULL, /* + 0x13 */
3094 (iw_handler) NULL, /* + 0x15 */
3095 (iw_handler) NULL, /* + 0x17 */
3096 (iw_handler) NULL, /* + 0x18 */
3099 const struct iw_handler_def rt28xx_iw_handler_def =
3101 #define N(a) (sizeof (a) / sizeof (a[0]))
3102 .standard = (iw_handler *) rt_handler,
3103 .num_standard = sizeof(rt_handler) / sizeof(iw_handler),
3104 .private = (iw_handler *) rt_priv_handlers,
3105 .num_private = N(rt_priv_handlers),
3106 .private_args = (struct iw_priv_args *) privtab,
3107 .num_private_args = N(privtab),
3108 #if IW_HANDLER_VERSION >= 7
3109 .get_wireless_stats = rt28xx_get_wireless_stats,
3113 INT RTMPSetInformation(
3114 IN PRTMP_ADAPTER pAdapter,
3115 IN OUT struct ifreq *rq,
3118 struct iwreq *wrq = (struct iwreq *) rq;
3119 NDIS_802_11_SSID Ssid;
3120 NDIS_802_11_MAC_ADDRESS Bssid;
3121 RT_802_11_PHY_MODE PhyMode;
3122 RT_802_11_STA_CONFIG StaConfig;
3123 NDIS_802_11_RATES aryRates;
3124 RT_802_11_PREAMBLE Preamble;
3125 NDIS_802_11_WEP_STATUS WepStatus;
3126 NDIS_802_11_AUTHENTICATION_MODE AuthMode = Ndis802_11AuthModeMax;
3127 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
3128 NDIS_802_11_RTS_THRESHOLD RtsThresh;
3129 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
3130 NDIS_802_11_POWER_MODE PowerMode;
3131 PNDIS_802_11_KEY pKey = NULL;
3132 PNDIS_802_11_WEP pWepKey =NULL;
3133 PNDIS_802_11_REMOVE_KEY pRemoveKey = NULL;
3134 NDIS_802_11_CONFIGURATION Config, *pConfig = NULL;
3135 NDIS_802_11_NETWORK_TYPE NetType;
3138 INT Status = NDIS_STATUS_SUCCESS, MaxPhyMode = PHY_11G;
3141 BOOLEAN StateMachineTouched = FALSE;
3142 #ifdef DOT11_N_SUPPORT
3143 OID_SET_HT_PHYMODE HT_PhyMode; //11n ,kathy
3144 #endif // DOT11_N_SUPPORT //
3145 #ifdef WPA_SUPPLICANT_SUPPORT
3146 PNDIS_802_11_PMKID pPmkId = NULL;
3147 BOOLEAN IEEE8021xState = FALSE;
3148 BOOLEAN IEEE8021x_required_keys = FALSE;
3149 UCHAR wpa_supplicant_enable = 0;
3150 #endif // WPA_SUPPLICANT_SUPPORT //
3153 TX_RTY_CFG_STRUC tx_rty_cfg;
3154 ULONG ShortRetryLimit, LongRetryLimit;
3156 #endif // SNMP_SUPPORT //
3160 #ifdef DOT11_N_SUPPORT
3161 MaxPhyMode = PHY_11N_5G;
3162 #endif // DOT11_N_SUPPORT //
3165 DBGPRINT(RT_DEBUG_TRACE, ("-->RTMPSetInformation(), 0x%08x\n", cmd&0x7FFF));
3166 switch(cmd & 0x7FFF) {
3167 case RT_OID_802_11_COUNTRY_REGION:
3168 if (wrq->u.data.length < sizeof(UCHAR))
3170 // Only avaliable when EEPROM not programming
3171 else if (!(pAdapter->CommonCfg.CountryRegion & 0x80) && !(pAdapter->CommonCfg.CountryRegionForABand & 0x80))
3176 Status = copy_from_user(&Country, wrq->u.data.pointer, wrq->u.data.length);
3177 pAdapter->CommonCfg.CountryRegion = (UCHAR)(Country & 0x000000FF);
3178 pAdapter->CommonCfg.CountryRegionForABand = (UCHAR)((Country >> 8) & 0x000000FF);
3179 TmpPhy = pAdapter->CommonCfg.PhyMode;
3180 pAdapter->CommonCfg.PhyMode = 0xff;
3181 // Build all corresponding channel information
3182 RTMPSetPhyMode(pAdapter, TmpPhy);
3183 #ifdef DOT11_N_SUPPORT
3184 SetCommonHT(pAdapter);
3185 #endif // DOT11_N_SUPPORT //
3186 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_COUNTRY_REGION (A:%d B/G:%d)\n", pAdapter->CommonCfg.CountryRegionForABand,
3187 pAdapter->CommonCfg.CountryRegion));
3190 case OID_802_11_BSSID_LIST_SCAN:
3192 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID_LIST_SCAN, TxCnt = %d \n", pAdapter->RalinkCounters.LastOneSecTotalTxCount));
3194 if (MONITOR_ON(pAdapter))
3196 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
3200 //Benson add 20080527, when radio off, sta don't need to scan
3201 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_RADIO_OFF))
3204 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
3206 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is scanning now !!!\n"));
3207 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
3208 Status = NDIS_STATUS_SUCCESS;
3212 if (pAdapter->RalinkCounters.LastOneSecTotalTxCount > 100)
3214 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
3215 Status = NDIS_STATUS_SUCCESS;
3216 pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
3220 if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
3221 ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
3222 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
3223 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
3224 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)) &&
3225 (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
3227 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
3228 Status = NDIS_STATUS_SUCCESS;
3229 pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
3234 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3236 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3237 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3240 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
3241 // this request, because this request is initiated by NDIS.
3242 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
3243 // Reset allowed scan retries
3244 pAdapter->StaCfg.ScanCnt = 0;
3245 pAdapter->StaCfg.LastScanTime = Now;
3247 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
3248 RTMP_SET_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
3249 MlmeEnqueue(pAdapter,
3250 MLME_CNTL_STATE_MACHINE,
3251 OID_802_11_BSSID_LIST_SCAN,
3255 Status = NDIS_STATUS_SUCCESS;
3256 StateMachineTouched = TRUE;
3258 case OID_802_11_SSID:
3259 if (wrq->u.data.length != sizeof(NDIS_802_11_SSID))
3263 PCHAR pSsidString = NULL;
3264 Status = copy_from_user(&Ssid, wrq->u.data.pointer, wrq->u.data.length);
3266 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SSID (Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
3267 if (Ssid.SsidLength > MAX_LEN_OF_SSID)
3271 if (Ssid.SsidLength == 0)
3273 Set_SSID_Proc(pAdapter, "");
3277 pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
3280 NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
3281 NdisMoveMemory(pSsidString, Ssid.Ssid, Ssid.SsidLength);
3282 Set_SSID_Proc(pAdapter, pSsidString);
3291 case OID_802_11_BSSID:
3292 if (wrq->u.data.length != sizeof(NDIS_802_11_MAC_ADDRESS))
3296 Status = copy_from_user(&Bssid, wrq->u.data.pointer, wrq->u.data.length);
3298 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
3299 // this request, because this request is initiated by NDIS.
3300 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
3302 // Prevent to connect AP again in STAMlmePeriodicExec
3303 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
3305 // Reset allowed scan retries
3306 pAdapter->StaCfg.ScanCnt = 0;
3308 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3310 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3311 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3313 MlmeEnqueue(pAdapter,
3314 MLME_CNTL_STATE_MACHINE,
3316 sizeof(NDIS_802_11_MAC_ADDRESS),
3318 Status = NDIS_STATUS_SUCCESS;
3319 StateMachineTouched = TRUE;
3321 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID %02x:%02x:%02x:%02x:%02x:%02x\n",
3322 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
3325 case RT_OID_802_11_RADIO:
3326 if (wrq->u.data.length != sizeof(BOOLEAN))
3330 Status = copy_from_user(&RadioState, wrq->u.data.pointer, wrq->u.data.length);
3331 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RADIO (=%d)\n", RadioState));
3332 if (pAdapter->StaCfg.bSwRadio != RadioState)
3334 pAdapter->StaCfg.bSwRadio = RadioState;
3335 if (pAdapter->StaCfg.bRadio != (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio))
3337 pAdapter->StaCfg.bRadio = (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio);
3338 if (pAdapter->StaCfg.bRadio == TRUE)
3340 MlmeRadioOn(pAdapter);
3341 // Update extra information
3342 pAdapter->ExtraInfo = EXTRA_INFO_CLEAR;
3346 MlmeRadioOff(pAdapter);
3347 // Update extra information
3348 pAdapter->ExtraInfo = SW_RADIO_OFF;
3354 case RT_OID_802_11_PHY_MODE:
3355 if (wrq->u.data.length != sizeof(RT_802_11_PHY_MODE))
3359 Status = copy_from_user(&PhyMode, wrq->u.data.pointer, wrq->u.data.length);
3360 if (PhyMode <= MaxPhyMode)
3362 RTMPSetPhyMode(pAdapter, PhyMode);
3363 #ifdef DOT11_N_SUPPORT
3364 SetCommonHT(pAdapter);
3365 #endif // DOT11_N_SUPPORT //
3367 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PHY_MODE (=%d)\n", PhyMode));
3370 case RT_OID_802_11_STA_CONFIG:
3371 if (wrq->u.data.length != sizeof(RT_802_11_STA_CONFIG))
3375 Status = copy_from_user(&StaConfig, wrq->u.data.pointer, wrq->u.data.length);
3376 pAdapter->CommonCfg.bEnableTxBurst = StaConfig.EnableTxBurst;
3377 pAdapter->CommonCfg.UseBGProtection = StaConfig.UseBGProtection;
3378 pAdapter->CommonCfg.bUseShortSlotTime = 1; // 2003-10-30 always SHORT SLOT capable
3379 if ((pAdapter->CommonCfg.PhyMode != StaConfig.AdhocMode) &&
3380 (StaConfig.AdhocMode <= MaxPhyMode))
3382 // allow dynamic change of "USE OFDM rate or not" in ADHOC mode
3383 // if setting changed, need to reset current TX rate as well as BEACON frame format
3384 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
3386 pAdapter->CommonCfg.PhyMode = StaConfig.AdhocMode;
3387 RTMPSetPhyMode(pAdapter, PhyMode);
3388 MlmeUpdateTxRates(pAdapter, FALSE, 0);
3389 MakeIbssBeacon(pAdapter); // re-build BEACON frame
3390 AsicEnableIbssSync(pAdapter); // copy to on-chip memory
3393 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_STA_CONFIG (Burst=%d, Protection=%ld,ShortSlot=%d\n",
3394 pAdapter->CommonCfg.bEnableTxBurst,
3395 pAdapter->CommonCfg.UseBGProtection,
3396 pAdapter->CommonCfg.bUseShortSlotTime));
3399 case OID_802_11_DESIRED_RATES:
3400 if (wrq->u.data.length != sizeof(NDIS_802_11_RATES))
3404 Status = copy_from_user(&aryRates, wrq->u.data.pointer, wrq->u.data.length);
3405 NdisZeroMemory(pAdapter->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES);
3406 NdisMoveMemory(pAdapter->CommonCfg.DesireRate, &aryRates, sizeof(NDIS_802_11_RATES));
3407 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DESIRED_RATES (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
3408 pAdapter->CommonCfg.DesireRate[0],pAdapter->CommonCfg.DesireRate[1],
3409 pAdapter->CommonCfg.DesireRate[2],pAdapter->CommonCfg.DesireRate[3],
3410 pAdapter->CommonCfg.DesireRate[4],pAdapter->CommonCfg.DesireRate[5],
3411 pAdapter->CommonCfg.DesireRate[6],pAdapter->CommonCfg.DesireRate[7] ));
3412 // Changing DesiredRate may affect the MAX TX rate we used to TX frames out
3413 MlmeUpdateTxRates(pAdapter, FALSE, 0);
3416 case RT_OID_802_11_PREAMBLE:
3417 if (wrq->u.data.length != sizeof(RT_802_11_PREAMBLE))
3421 Status = copy_from_user(&Preamble, wrq->u.data.pointer, wrq->u.data.length);
3422 if (Preamble == Rt802_11PreambleShort)
3424 pAdapter->CommonCfg.TxPreamble = Preamble;
3425 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleShort);
3427 else if ((Preamble == Rt802_11PreambleLong) || (Preamble == Rt802_11PreambleAuto))
3429 // if user wants AUTO, initialize to LONG here, then change according to AP's
3430 // capability upon association.
3431 pAdapter->CommonCfg.TxPreamble = Preamble;
3432 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleLong);
3439 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PREAMBLE (=%d)\n", Preamble));
3442 case OID_802_11_WEP_STATUS:
3443 if (wrq->u.data.length != sizeof(NDIS_802_11_WEP_STATUS))
3447 Status = copy_from_user(&WepStatus, wrq->u.data.pointer, wrq->u.data.length);
3448 // Since TKIP, AES, WEP are all supported. It should not have any invalid setting
3449 if (WepStatus <= Ndis802_11Encryption3KeyAbsent)
3451 if (pAdapter->StaCfg.WepStatus != WepStatus)
3453 // Config has changed
3454 pAdapter->bConfigChanged = TRUE;
3456 pAdapter->StaCfg.WepStatus = WepStatus;
3457 pAdapter->StaCfg.OrigWepStatus = WepStatus;
3458 pAdapter->StaCfg.PairCipher = WepStatus;
3459 pAdapter->StaCfg.GroupCipher = WepStatus;
3466 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEP_STATUS (=%d)\n",WepStatus));
3469 case OID_802_11_AUTHENTICATION_MODE:
3470 if (wrq->u.data.length != sizeof(NDIS_802_11_AUTHENTICATION_MODE))
3474 Status = copy_from_user(&AuthMode, wrq->u.data.pointer, wrq->u.data.length);
3475 if (AuthMode > Ndis802_11AuthModeMax)
3482 if (pAdapter->StaCfg.AuthMode != AuthMode)
3484 // Config has changed
3485 pAdapter->bConfigChanged = TRUE;
3487 pAdapter->StaCfg.AuthMode = AuthMode;
3489 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
3490 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_AUTHENTICATION_MODE (=%d) \n",pAdapter->StaCfg.AuthMode));
3493 case OID_802_11_INFRASTRUCTURE_MODE:
3494 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_INFRASTRUCTURE))
3498 Status = copy_from_user(&BssType, wrq->u.data.pointer, wrq->u.data.length);
3500 if (BssType == Ndis802_11IBSS)
3501 Set_NetworkType_Proc(pAdapter, "Adhoc");
3502 else if (BssType == Ndis802_11Infrastructure)
3503 Set_NetworkType_Proc(pAdapter, "Infra");
3504 else if (BssType == Ndis802_11Monitor)
3505 Set_NetworkType_Proc(pAdapter, "Monitor");
3509 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_INFRASTRUCTURE_MODE (unknown)\n"));
3513 case OID_802_11_REMOVE_WEP:
3514 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_WEP\n"));
3515 if (wrq->u.data.length != sizeof(NDIS_802_11_KEY_INDEX))
3521 KeyIdx = *(NDIS_802_11_KEY_INDEX *) wrq->u.data.pointer;
3523 if (KeyIdx & 0x80000000)
3525 // Should never set default bit when remove key
3530 KeyIdx = KeyIdx & 0x0fffffff;
3536 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
3537 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
3538 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
3543 case RT_OID_802_11_RESET_COUNTERS:
3544 NdisZeroMemory(&pAdapter->WlanCounters, sizeof(COUNTER_802_11));
3545 NdisZeroMemory(&pAdapter->Counters8023, sizeof(COUNTER_802_3));
3546 NdisZeroMemory(&pAdapter->RalinkCounters, sizeof(COUNTER_RALINK));
3547 pAdapter->Counters8023.RxNoBuffer = 0;
3548 pAdapter->Counters8023.GoodReceives = 0;
3549 pAdapter->Counters8023.RxNoBuffer = 0;
3551 pAdapter->BulkOutComplete = 0;
3552 pAdapter->BulkOutCompleteOther= 0;
3553 pAdapter->BulkOutCompleteCancel = 0;
3554 pAdapter->BulkOutReq = 0;
3555 pAdapter->BulkInReq= 0;
3556 pAdapter->BulkInComplete = 0;
3557 pAdapter->BulkInCompleteFail = 0;
3559 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RESET_COUNTERS \n"));
3561 case OID_802_11_RTS_THRESHOLD:
3562 if (wrq->u.data.length != sizeof(NDIS_802_11_RTS_THRESHOLD))
3566 Status = copy_from_user(&RtsThresh, wrq->u.data.pointer, wrq->u.data.length);
3567 if (RtsThresh > MAX_RTS_THRESHOLD)
3570 pAdapter->CommonCfg.RtsThreshold = (USHORT)RtsThresh;
3572 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_RTS_THRESHOLD (=%ld)\n",RtsThresh));
3574 case OID_802_11_FRAGMENTATION_THRESHOLD:
3575 if (wrq->u.data.length != sizeof(NDIS_802_11_FRAGMENTATION_THRESHOLD))
3579 Status = copy_from_user(&FragThresh, wrq->u.data.pointer, wrq->u.data.length);
3580 pAdapter->CommonCfg.bUseZeroToDisableFragment = FALSE;
3581 if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
3583 if (FragThresh == 0)
3585 pAdapter->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
3586 pAdapter->CommonCfg.bUseZeroToDisableFragment = TRUE;
3592 pAdapter->CommonCfg.FragmentThreshold = (USHORT)FragThresh;
3594 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_FRAGMENTATION_THRESHOLD (=%ld) \n",FragThresh));
3596 case OID_802_11_POWER_MODE:
3597 if (wrq->u.data.length != sizeof(NDIS_802_11_POWER_MODE))
3601 Status = copy_from_user(&PowerMode, wrq->u.data.pointer, wrq->u.data.length);
3602 if (PowerMode == Ndis802_11PowerModeCAM)
3603 Set_PSMode_Proc(pAdapter, "CAM");
3604 else if (PowerMode == Ndis802_11PowerModeMAX_PSP)
3605 Set_PSMode_Proc(pAdapter, "Max_PSP");
3606 else if (PowerMode == Ndis802_11PowerModeFast_PSP)
3607 Set_PSMode_Proc(pAdapter, "Fast_PSP");
3608 else if (PowerMode == Ndis802_11PowerModeLegacy_PSP)
3609 Set_PSMode_Proc(pAdapter, "Legacy_PSP");
3613 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_POWER_MODE (=%d)\n",PowerMode));
3615 case RT_OID_802_11_TX_POWER_LEVEL_1:
3616 if (wrq->u.data.length < sizeof(ULONG))
3620 Status = copy_from_user(&PowerTemp, wrq->u.data.pointer, wrq->u.data.length);
3621 if (PowerTemp > 100)
3622 PowerTemp = 0xffffffff; // AUTO
3623 pAdapter->CommonCfg.TxPowerDefault = PowerTemp; //keep current setting.
3624 pAdapter->CommonCfg.TxPowerPercentage = pAdapter->CommonCfg.TxPowerDefault;
3625 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
3628 case OID_802_11_NETWORK_TYPE_IN_USE:
3629 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_TYPE))
3633 Status = copy_from_user(&NetType, wrq->u.data.pointer, wrq->u.data.length);
3635 if (NetType == Ndis802_11DS)
3636 RTMPSetPhyMode(pAdapter, PHY_11B);
3637 else if (NetType == Ndis802_11OFDM24)
3638 RTMPSetPhyMode(pAdapter, PHY_11BG_MIXED);
3639 else if (NetType == Ndis802_11OFDM5)
3640 RTMPSetPhyMode(pAdapter, PHY_11A);
3643 #ifdef DOT11_N_SUPPORT
3644 if (Status == NDIS_STATUS_SUCCESS)
3645 SetCommonHT(pAdapter);
3646 #endif // DOT11_N_SUPPORT //
3647 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_NETWORK_TYPE_IN_USE (=%d)\n",NetType));
3650 // For WPA PSK PMK key
3651 case RT_OID_802_11_ADD_WPA:
3652 pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3659 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
3660 if (pKey->Length != wrq->u.data.length)
3663 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!!\n"));
3667 if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
3668 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
3669 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone) )
3671 Status = -EOPNOTSUPP;
3672 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!! [AuthMode != WPAPSK/WPA2PSK/WPANONE]\n"));
3674 else if ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
3675 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
3676 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) ) // Only for WPA PSK mode
3678 NdisMoveMemory(pAdapter->StaCfg.PMK, &pKey->KeyMaterial, pKey->KeyLength);
3679 // Use RaConfig as PSK agent.
3680 // Start STA supplicant state machine
3681 if (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
3682 pAdapter->StaCfg.WpaState = SS_START;
3684 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3688 pAdapter->StaCfg.WpaState = SS_NOTUSE;
3689 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3694 case OID_802_11_REMOVE_KEY:
3695 pRemoveKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3696 if(pRemoveKey == NULL)
3702 Status = copy_from_user(pRemoveKey, wrq->u.data.pointer, wrq->u.data.length);
3703 if (pRemoveKey->Length != wrq->u.data.length)
3706 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!\n"));
3710 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3712 RTMPWPARemoveKeyProc(pAdapter, pRemoveKey);
3713 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Remove WPA Key!!\n"));
3717 KeyIdx = pRemoveKey->KeyIndex;
3719 if (KeyIdx & 0x80000000)
3721 // Should never set default bit when remove key
3723 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(Should never set default bit when remove key)\n"));
3727 KeyIdx = KeyIdx & 0x0fffffff;
3731 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(KeyId[%d] out of range)\n", KeyIdx));
3735 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
3736 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
3737 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
3738 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY (id=0x%x, Len=%d-byte)\n", pRemoveKey->KeyIndex, pRemoveKey->Length));
3746 case OID_802_11_ADD_KEY:
3747 pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3753 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
3754 if (pKey->Length != wrq->u.data.length)
3757 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY, Failed!!\n"));
3761 RTMPAddKey(pAdapter, pKey);
3762 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3766 case OID_802_11_CONFIGURATION:
3767 if (wrq->u.data.length != sizeof(NDIS_802_11_CONFIGURATION))
3771 Status = copy_from_user(&Config, wrq->u.data.pointer, wrq->u.data.length);
3774 if ((pConfig->BeaconPeriod >= 20) && (pConfig->BeaconPeriod <=400))
3775 pAdapter->CommonCfg.BeaconPeriod = (USHORT) pConfig->BeaconPeriod;
3777 pAdapter->StaActive.AtimWin = (USHORT) pConfig->ATIMWindow;
3778 MAP_KHZ_TO_CHANNEL_ID(pConfig->DSConfig, pAdapter->CommonCfg.Channel);
3780 // Save the channel on MlmeAux for CntlOidRTBssidProc used.
3782 pAdapter->MlmeAux.Channel = pAdapter->CommonCfg.Channel;
3784 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_CONFIGURATION (BeacnPeriod=%ld,AtimW=%ld,Ch=%d)\n",
3785 pConfig->BeaconPeriod, pConfig->ATIMWindow, pAdapter->CommonCfg.Channel));
3786 // Config has changed
3787 pAdapter->bConfigChanged = TRUE;
3790 #ifdef DOT11_N_SUPPORT
3791 case RT_OID_802_11_SET_HT_PHYMODE:
3792 if (wrq->u.data.length != sizeof(OID_SET_HT_PHYMODE))
3796 POID_SET_HT_PHYMODE pHTPhyMode = &HT_PhyMode;
3798 Status = copy_from_user(&HT_PhyMode, wrq->u.data.pointer, wrq->u.data.length);
3799 DBGPRINT(RT_DEBUG_TRACE, ("Set::pHTPhyMode (PhyMode = %d,TransmitNo = %d, HtMode = %d, ExtOffset = %d , MCS = %d, BW = %d, STBC = %d, SHORTGI = %d) \n",
3800 pHTPhyMode->PhyMode, pHTPhyMode->TransmitNo,pHTPhyMode->HtMode,pHTPhyMode->ExtOffset,
3801 pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->SHORTGI));
3802 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
3803 RTMPSetHT(pAdapter, pHTPhyMode);
3805 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_HT_PHYMODE(MCS=%d,BW=%d,SGI=%d,STBC=%d)\n",
3806 pAdapter->StaCfg.HTPhyMode.field.MCS, pAdapter->StaCfg.HTPhyMode.field.BW, pAdapter->StaCfg.HTPhyMode.field.ShortGI,
3807 pAdapter->StaCfg.HTPhyMode.field.STBC));
3809 #endif // DOT11_N_SUPPORT //
3810 case RT_OID_802_11_SET_APSD_SETTING:
3811 if (wrq->u.data.length != sizeof(ULONG))
3816 Status = copy_from_user(&apsd, wrq->u.data.pointer, wrq->u.data.length);
3818 /*-------------------------------------------------------------------
3819 |B31~B7 | B6~B5 | B4 | B3 | B2 | B1 | B0 |
3820 ---------------------------------------------------------------------
3821 | Rsvd | Max SP Len | AC_VO | AC_VI | AC_BK | AC_BE | APSD Capable |
3822 ---------------------------------------------------------------------*/
3823 pAdapter->CommonCfg.bAPSDCapable = (apsd & 0x00000001) ? TRUE : FALSE;
3824 pAdapter->CommonCfg.bAPSDAC_BE = ((apsd & 0x00000002) >> 1) ? TRUE : FALSE;
3825 pAdapter->CommonCfg.bAPSDAC_BK = ((apsd & 0x00000004) >> 2) ? TRUE : FALSE;
3826 pAdapter->CommonCfg.bAPSDAC_VI = ((apsd & 0x00000008) >> 3) ? TRUE : FALSE;
3827 pAdapter->CommonCfg.bAPSDAC_VO = ((apsd & 0x00000010) >> 4) ? TRUE : FALSE;
3828 pAdapter->CommonCfg.MaxSPLength = (UCHAR)((apsd & 0x00000060) >> 5);
3830 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,
3831 pAdapter->CommonCfg.bAPSDAC_BE, pAdapter->CommonCfg.bAPSDAC_BK, pAdapter->CommonCfg.bAPSDAC_VI, pAdapter->CommonCfg.bAPSDAC_VO, pAdapter->CommonCfg.MaxSPLength));
3835 case RT_OID_802_11_SET_APSD_PSM:
3836 if (wrq->u.data.length != sizeof(ULONG))
3840 // Driver needs to notify AP when PSM changes
3841 Status = copy_from_user(&pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.pointer, wrq->u.data.length);
3842 if (pAdapter->CommonCfg.bAPSDForcePowerSave != pAdapter->StaCfg.Psm)
3844 MlmeSetPsmBit(pAdapter, pAdapter->CommonCfg.bAPSDForcePowerSave);
3845 RTMPSendNullFrame(pAdapter, pAdapter->CommonCfg.TxRate, TRUE);
3847 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_APSD_PSM (bAPSDForcePowerSave:%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
3851 case RT_OID_802_11_SET_WMM:
3852 if (wrq->u.data.length != sizeof(BOOLEAN))
3856 Status = copy_from_user(&pAdapter->CommonCfg.bWmmCapable, wrq->u.data.pointer, wrq->u.data.length);
3857 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_WMM (=%d) \n", pAdapter->CommonCfg.bWmmCapable));
3861 case OID_802_11_DISASSOCIATE:
3863 // Set NdisRadioStateOff to TRUE, instead of called MlmeRadioOff.
3864 // Later on, NDIS_802_11_BSSID_LIST_EX->NumberOfItems should be 0
3865 // when query OID_802_11_BSSID_LIST.
3867 // TRUE: NumberOfItems will set to 0.
3868 // FALSE: NumberOfItems no change.
3870 pAdapter->CommonCfg.NdisRadioStateOff = TRUE;
3871 // Set to immediately send the media disconnect event
3872 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
3873 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DISASSOCIATE \n"));
3875 if (INFRA_ON(pAdapter))
3877 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3879 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3880 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3883 MlmeEnqueue(pAdapter,
3884 MLME_CNTL_STATE_MACHINE,
3885 OID_802_11_DISASSOCIATE,
3889 StateMachineTouched = TRUE;
3893 #ifdef DOT11_N_SUPPORT
3894 case RT_OID_802_11_SET_IMME_BA_CAP:
3895 if (wrq->u.data.length != sizeof(OID_BACAP_STRUC))
3899 OID_BACAP_STRUC Orde ;
3900 Status = copy_from_user(&Orde, wrq->u.data.pointer, wrq->u.data.length);
3901 if (Orde.Policy > BA_NOTUSE)
3903 Status = NDIS_STATUS_INVALID_DATA;
3905 else if (Orde.Policy == BA_NOTUSE)
3907 pAdapter->CommonCfg.BACapability.field.Policy = BA_NOTUSE;
3908 pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
3909 pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
3910 pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
3911 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
3912 pAdapter->CommonCfg.DesiredHtPhy.MimoPs= Orde.MMPSmode;
3913 pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
3915 pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
3916 pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
3917 pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
3921 pAdapter->CommonCfg.BACapability.field.AutoBA = Orde.AutoBA;
3922 pAdapter->CommonCfg.BACapability.field.Policy = IMMED_BA; // we only support immediate BA.
3923 pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
3924 pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
3925 pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
3926 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
3927 pAdapter->CommonCfg.DesiredHtPhy.MimoPs = Orde.MMPSmode;
3928 pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
3931 pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
3932 pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
3933 pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
3935 if (pAdapter->CommonCfg.BACapability.field.RxBAWinLimit > MAX_RX_REORDERBUF)
3936 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = MAX_RX_REORDERBUF;
3940 pAdapter->CommonCfg.REGBACapability.word = pAdapter->CommonCfg.BACapability.word;
3941 DBGPRINT(RT_DEBUG_TRACE, ("Set::(Orde.AutoBA = %d) (Policy=%d)(ReBAWinLimit=%d)(TxBAWinLimit=%d)(AutoMode=%d)\n",Orde.AutoBA, pAdapter->CommonCfg.BACapability.field.Policy,
3942 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit,pAdapter->CommonCfg.BACapability.field.TxBAWinLimit, pAdapter->CommonCfg.BACapability.field.AutoBA));
3943 DBGPRINT(RT_DEBUG_TRACE, ("Set::(MimoPs = %d)(AmsduEnable = %d) (AmsduSize=%d)(MpduDensity=%d)\n",pAdapter->CommonCfg.DesiredHtPhy.MimoPs, pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable,
3944 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize, pAdapter->CommonCfg.DesiredHtPhy.MpduDensity));
3948 case RT_OID_802_11_ADD_IMME_BA:
3949 DBGPRINT(RT_DEBUG_TRACE, (" Set :: RT_OID_802_11_ADD_IMME_BA \n"));
3950 if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
3955 OID_ADD_BA_ENTRY BA;
3956 MAC_TABLE_ENTRY *pEntry;
3958 Status = copy_from_user(&BA, wrq->u.data.pointer, wrq->u.data.length);
3961 Status = NDIS_STATUS_INVALID_DATA;
3966 //BATableInsertEntry
3967 //As ad-hoc mode, BA pair is not limited to only BSSID. so add via OID.
3969 // in ad hoc mode, when adding BA pair, we should insert this entry into MACEntry too
3970 pEntry = MacTableLookup(pAdapter, BA.MACAddr);
3973 DBGPRINT(RT_DEBUG_TRACE, ("RT_OID_802_11_ADD_IMME_BA. break on no connection.----:%x:%x\n", BA.MACAddr[4], BA.MACAddr[5]));
3976 if (BA.IsRecipient == FALSE)
3978 if (pEntry->bIAmBadAtheros == TRUE)
3979 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = 0x10;
3981 BAOriSessionSetUp(pAdapter, pEntry, index, 0, 100, TRUE);
3985 //BATableInsertEntry(pAdapter, pEntry->Aid, BA.MACAddr, 0, 0xffff, BA.TID, BA.nMSDU, BA.IsRecipient);
3988 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_IMME_BA. Rec = %d. Mac = %x:%x:%x:%x:%x:%x . \n",
3989 BA.IsRecipient, BA.MACAddr[0], BA.MACAddr[1], BA.MACAddr[2], BA.MACAddr[2]
3990 , BA.MACAddr[4], BA.MACAddr[5]));
3995 case RT_OID_802_11_TEAR_IMME_BA:
3996 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA \n"));
3997 if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
4001 POID_ADD_BA_ENTRY pBA;
4002 MAC_TABLE_ENTRY *pEntry;
4004 pBA = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4008 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA kmalloc() can't allocate enough memory\n"));
4009 Status = NDIS_STATUS_FAILURE;
4013 Status = copy_from_user(pBA, wrq->u.data.pointer, wrq->u.data.length);
4014 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA(TID=%d, bAllTid=%d)\n", pBA->TID, pBA->bAllTid));
4016 if (!pBA->bAllTid && (pBA->TID > NUM_OF_TID))
4018 Status = NDIS_STATUS_INVALID_DATA;
4022 if (pBA->IsRecipient == FALSE)
4024 pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
4025 DBGPRINT(RT_DEBUG_TRACE, (" pBA->IsRecipient == FALSE\n"));
4028 DBGPRINT(RT_DEBUG_TRACE, (" pBA->pEntry\n"));
4029 BAOriSessionTearDown(pAdapter, pEntry->Aid, pBA->TID, FALSE, TRUE);
4032 DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
4036 pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
4039 BARecSessionTearDown( pAdapter, (UCHAR)pEntry->Aid, pBA->TID, TRUE);
4042 DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
4048 #endif // DOT11_N_SUPPORT //
4050 // For WPA_SUPPLICANT to set static wep key
4051 case OID_802_11_ADD_WEP:
4052 pWepKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4057 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed!!\n"));
4060 Status = copy_from_user(pWepKey, wrq->u.data.pointer, wrq->u.data.length);
4064 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (length mismatch)!!\n"));
4068 KeyIdx = pWepKey->KeyIndex & 0x0fffffff;
4069 // KeyIdx must be 0 ~ 3
4073 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (KeyIdx must be smaller than 4)!!\n"));
4077 UCHAR CipherAlg = 0;
4080 // set key material and key length
4081 NdisZeroMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, 16);
4082 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
4083 NdisMoveMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
4085 switch(pWepKey->KeyLength)
4088 CipherAlg = CIPHER_WEP64;
4091 CipherAlg = CIPHER_WEP128;
4094 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, only support CIPHER_WEP64(len:5) & CIPHER_WEP128(len:13)!!\n"));
4098 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CipherAlg;
4100 // Default key for tx (shared key)
4101 if (pWepKey->KeyIndex & 0x80000000)
4103 #ifdef WPA_SUPPLICANT_SUPPORT
4104 // set key material and key length
4105 NdisZeroMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, 16);
4106 pAdapter->StaCfg.DesireSharedKey[KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
4107 NdisMoveMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
4108 pAdapter->StaCfg.DesireSharedKeyId = KeyIdx;
4109 pAdapter->StaCfg.DesireSharedKey[KeyIdx].CipherAlg = CipherAlg;
4110 #endif // WPA_SUPPLICANT_SUPPORT //
4111 pAdapter->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
4114 #ifdef WPA_SUPPLICANT_SUPPORT
4115 if ((pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE) &&
4116 (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA))
4118 Key = pWepKey->KeyMaterial;
4120 // Set Group key material to Asic
4121 AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
4123 // Update WCID attribute table and IVEIV table for this group key table
4124 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
4126 STA_PORT_SECURED(pAdapter);
4128 // Indicate Connected for GUI
4129 pAdapter->IndicateMediaState = NdisMediaStateConnected;
4131 else if (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)
4132 #endif // WPA_SUPPLICANT_SUPPORT
4134 Key = pAdapter->SharedKey[BSS0][KeyIdx].Key;
4136 // Set key material and cipherAlg to Asic
4137 AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
4139 if (pWepKey->KeyIndex & 0x80000000)
4141 PMAC_TABLE_ENTRY pEntry = &pAdapter->MacTab.Content[BSSID_WCID];
4142 // Assign group key info
4143 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
4144 // Assign pairwise key info
4145 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, pEntry);
4148 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"));
4153 #ifdef WPA_SUPPLICANT_SUPPORT
4154 case OID_SET_COUNTERMEASURES:
4155 if (wrq->u.data.length != sizeof(int))
4160 Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
4162 pAdapter->StaCfg.bBlockAssoc = TRUE;
4164 // WPA MIC error should block association attempt for 60 seconds
4165 pAdapter->StaCfg.bBlockAssoc = FALSE;
4166 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_SET_COUNTERMEASURES bBlockAssoc=%s\n", pAdapter->StaCfg.bBlockAssoc ? "TRUE":"FALSE"));
4169 case RT_OID_WPA_SUPPLICANT_SUPPORT:
4170 if (wrq->u.data.length != sizeof(UCHAR))
4174 Status = copy_from_user(&wpa_supplicant_enable, wrq->u.data.pointer, wrq->u.data.length);
4175 pAdapter->StaCfg.WpaSupplicantUP = wpa_supplicant_enable;
4176 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
4179 case OID_802_11_DEAUTHENTICATION:
4180 if (wrq->u.data.length != sizeof(MLME_DEAUTH_REQ_STRUCT))
4184 MLME_DEAUTH_REQ_STRUCT *pInfo;
4185 MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
4187 pInfo = (MLME_DEAUTH_REQ_STRUCT *) MsgElem->Msg;
4188 Status = copy_from_user(pInfo, wrq->u.data.pointer, wrq->u.data.length);
4189 MlmeDeauthReqAction(pAdapter, MsgElem);
4192 if (INFRA_ON(pAdapter))
4194 LinkDown(pAdapter, FALSE);
4195 pAdapter->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
4197 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DEAUTHENTICATION (Reason=%d)\n", pInfo->Reason));
4200 case OID_802_11_DROP_UNENCRYPTED:
4201 if (wrq->u.data.length != sizeof(int))
4206 Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
4208 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
4210 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
4211 NdisAcquireSpinLock(&pAdapter->MacTabLock);
4212 pAdapter->MacTab.Content[BSSID_WCID].PortSecured = pAdapter->StaCfg.PortSecured;
4213 NdisReleaseSpinLock(&pAdapter->MacTabLock);
4214 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DROP_UNENCRYPTED (=%d)\n", enabled));
4217 case OID_802_11_SET_IEEE8021X:
4218 if (wrq->u.data.length != sizeof(BOOLEAN))
4222 Status = copy_from_user(&IEEE8021xState, wrq->u.data.pointer, wrq->u.data.length);
4223 pAdapter->StaCfg.IEEE8021X = IEEE8021xState;
4224 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X (=%d)\n", IEEE8021xState));
4227 case OID_802_11_SET_IEEE8021X_REQUIRE_KEY:
4228 if (wrq->u.data.length != sizeof(BOOLEAN))
4232 Status = copy_from_user(&IEEE8021x_required_keys, wrq->u.data.pointer, wrq->u.data.length);
4233 pAdapter->StaCfg.IEEE8021x_required_keys = IEEE8021x_required_keys;
4234 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X_REQUIRE_KEY (%d)\n", IEEE8021x_required_keys));
4237 case OID_802_11_PMKID:
4238 pPmkId = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4240 if(pPmkId == NULL) {
4244 Status = copy_from_user(pPmkId, wrq->u.data.pointer, wrq->u.data.length);
4246 // check the PMKID information
4247 if (pPmkId->BSSIDInfoCount == 0)
4248 NdisZeroMemory(pAdapter->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
4251 PBSSID_INFO pBssIdInfo;
4255 for (BssIdx = 0; BssIdx < pPmkId->BSSIDInfoCount; BssIdx++)
4257 // point to the indexed BSSID_INFO structure
4258 pBssIdInfo = (PBSSID_INFO) ((PUCHAR) pPmkId + 2 * sizeof(UINT) + BssIdx * sizeof(BSSID_INFO));
4259 // Find the entry in the saved data base.
4260 for (CachedIdx = 0; CachedIdx < pAdapter->StaCfg.SavedPMKNum; CachedIdx++)
4262 // compare the BSSID
4263 if (NdisEqualMemory(pBssIdInfo->BSSID, pAdapter->StaCfg.SavedPMK[CachedIdx].BSSID, sizeof(NDIS_802_11_MAC_ADDRESS)))
4267 // Found, replace it
4268 if (CachedIdx < PMKID_NO)
4270 DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
4271 NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
4272 pAdapter->StaCfg.SavedPMKNum++;
4274 // Not found, replace the last one
4277 // Randomly replace one
4278 CachedIdx = (pBssIdInfo->BSSID[5] % PMKID_NO);
4279 DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
4280 NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
4287 #endif // WPA_SUPPLICANT_SUPPORT //
4292 case OID_802_11_SHORTRETRYLIMIT:
4293 if (wrq->u.data.length != sizeof(ULONG))
4297 Status = copy_from_user(&ShortRetryLimit, wrq->u.data.pointer, wrq->u.data.length);
4298 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
4299 tx_rty_cfg.field.ShortRtyLimit = ShortRetryLimit;
4300 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
4301 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SHORTRETRYLIMIT (tx_rty_cfg.field.ShortRetryLimit=%d, ShortRetryLimit=%ld)\n", tx_rty_cfg.field.ShortRtyLimit, ShortRetryLimit));
4305 case OID_802_11_LONGRETRYLIMIT:
4306 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_LONGRETRYLIMIT \n"));
4307 if (wrq->u.data.length != sizeof(ULONG))
4311 Status = copy_from_user(&LongRetryLimit, wrq->u.data.pointer, wrq->u.data.length);
4312 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
4313 tx_rty_cfg.field.LongRtyLimit = LongRetryLimit;
4314 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
4315 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_LONGRETRYLIMIT (tx_rty_cfg.field.LongRetryLimit= %d,LongRetryLimit=%ld)\n", tx_rty_cfg.field.LongRtyLimit, LongRetryLimit));
4319 case OID_802_11_WEPDEFAULTKEYVALUE:
4320 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEPDEFAULTKEYVALUE\n"));
4321 pKey = kmalloc(wrq->u.data.length, GFP_KERNEL);
4322 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
4325 if ( pKey->Length != wrq->u.data.length)
4328 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEPDEFAULTKEYVALUE, Failed!!\n"));
4330 KeyIdx = pKey->KeyIndex & 0x0fffffff;
4331 DBGPRINT(RT_DEBUG_TRACE,("pKey->KeyIndex =%d, pKey->KeyLength=%d\n", pKey->KeyIndex, pKey->KeyLength));
4333 // it is a shared key
4338 pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen = (UCHAR) pKey->KeyLength;
4339 NdisMoveMemory(&pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key, &pKey->KeyMaterial, pKey->KeyLength);
4340 if (pKey->KeyIndex & 0x80000000)
4342 // Default key for tx (shared key)
4343 pAdapter->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
4345 //RestartAPIsRequired = TRUE;
4350 case OID_802_11_WEPDEFAULTKEYID:
4351 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEPDEFAULTKEYID \n"));
4353 if (wrq->u.data.length != sizeof(UCHAR))
4356 Status = copy_from_user(&pAdapter->StaCfg.DefaultKeyId, wrq->u.data.pointer, wrq->u.data.length);
4361 case OID_802_11_CURRENTCHANNEL:
4362 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_CURRENTCHANNEL \n"));
4363 if (wrq->u.data.length != sizeof(UCHAR))
4367 Status = copy_from_user(&ctmp, wrq->u.data.pointer, wrq->u.data.length);
4368 sprintf(&ctmp,"%d", ctmp);
4369 Set_Channel_Proc(pAdapter, &ctmp);
4377 DBGPRINT(RT_DEBUG_TRACE, ("Set::unknown IOCTL's subcmd = 0x%08x\n", cmd));
4378 Status = -EOPNOTSUPP;
4386 INT RTMPQueryInformation(
4387 IN PRTMP_ADAPTER pAdapter,
4388 IN OUT struct ifreq *rq,
4391 struct iwreq *wrq = (struct iwreq *) rq;
4392 NDIS_802_11_BSSID_LIST_EX *pBssidList = NULL;
4393 PNDIS_WLAN_BSSID_EX pBss;
4394 NDIS_802_11_SSID Ssid;
4395 NDIS_802_11_CONFIGURATION *pConfiguration = NULL;
4396 RT_802_11_LINK_STATUS *pLinkStatus = NULL;
4397 RT_802_11_STA_CONFIG *pStaConfig = NULL;
4398 NDIS_802_11_STATISTICS *pStatistics = NULL;
4399 NDIS_802_11_RTS_THRESHOLD RtsThresh;
4400 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
4401 NDIS_802_11_POWER_MODE PowerMode;
4402 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
4403 RT_802_11_PREAMBLE PreamType;
4404 NDIS_802_11_AUTHENTICATION_MODE AuthMode;
4405 NDIS_802_11_WEP_STATUS WepStatus;
4406 NDIS_MEDIA_STATE MediaState;
4407 ULONG BssBufSize, ulInfo=0, NetworkTypeList[4], apsd = 0;
4409 PUCHAR pBuf = NULL, pPtr;
4410 INT Status = NDIS_STATUS_SUCCESS;
4411 UINT we_version_compiled;
4412 UCHAR i, Padding = 0;
4414 UCHAR driverVersion[8];
4415 OID_SET_HT_PHYMODE *pHTPhyMode = NULL;
4420 DefaultKeyIdxValue *pKeyIdxValue;
4422 TX_RTY_CFG_STRUC tx_rty_cfg;
4423 ULONG ShortRetryLimit, LongRetryLimit;
4429 case RT_OID_DEVICE_NAME:
4430 wrq->u.data.length = sizeof(STA_NIC_DEVICE_NAME);
4431 Status = copy_to_user(wrq->u.data.pointer, STA_NIC_DEVICE_NAME, wrq->u.data.length);
4433 case RT_OID_VERSION_INFO:
4434 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_VERSION_INFO \n"));
4435 wrq->u.data.length = 8*sizeof(UCHAR);
4436 sprintf(&driverVersion[0], "%s", STA_DRIVER_VERSION);
4437 driverVersion[7] = '\0';
4438 if (copy_to_user(wrq->u.data.pointer, &driverVersion, wrq->u.data.length))
4443 case OID_802_11_BSSID_LIST:
4444 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
4447 * Still scanning, indicate the caller should try again.
4449 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (Still scanning)\n"));
4452 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (%d BSS returned)\n",pAdapter->ScanTab.BssNr));
4453 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
4454 // Claculate total buffer size required
4455 BssBufSize = sizeof(ULONG);
4457 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
4459 // Align pointer to 4 bytes boundary.
4460 //Padding = 4 - (pAdapter->ScanTab.BssEntry[i].VarIELen & 0x0003);
4463 BssBufSize += (sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
4466 // For safety issue, we add 256 bytes just in case
4468 // Allocate the same size as passed from higher layer
4469 pBuf = kmalloc(BssBufSize, MEM_ALLOC_FLAG);
4475 // Init 802_11_BSSID_LIST_EX structure
4476 NdisZeroMemory(pBuf, BssBufSize);
4477 pBssidList = (PNDIS_802_11_BSSID_LIST_EX) pBuf;
4478 pBssidList->NumberOfItems = pAdapter->ScanTab.BssNr;
4480 // Calculate total buffer length
4481 BssLen = 4; // Consist of NumberOfItems
4482 // Point to start of NDIS_WLAN_BSSID_EX
4483 // pPtr = pBuf + sizeof(ULONG);
4484 pPtr = (PUCHAR) &pBssidList->Bssid[0];
4485 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
4487 pBss = (PNDIS_WLAN_BSSID_EX) pPtr;
4488 NdisMoveMemory(&pBss->MacAddress, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
4489 if ((pAdapter->ScanTab.BssEntry[i].Hidden == 1) && (pAdapter->StaCfg.bShowHiddenSSID == FALSE))
4492 // We must return this SSID during 4way handshaking, otherwise Aegis will failed to parse WPA infomation
4493 // and then failed to send EAPOl farame.
4495 if ((pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) && (pAdapter->StaCfg.PortSecured != WPA_802_1X_PORT_SECURED))
4497 pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
4498 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
4501 pBss->Ssid.SsidLength = 0;
4505 pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
4506 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
4508 pBss->Privacy = pAdapter->ScanTab.BssEntry[i].Privacy;
4509 pBss->Rssi = pAdapter->ScanTab.BssEntry[i].Rssi - pAdapter->BbpRssiToDbmDelta;
4510 pBss->NetworkTypeInUse = NetworkTypeInUseSanity(&pAdapter->ScanTab.BssEntry[i]);
4511 pBss->Configuration.Length = sizeof(NDIS_802_11_CONFIGURATION);
4512 pBss->Configuration.BeaconPeriod = pAdapter->ScanTab.BssEntry[i].BeaconPeriod;
4513 pBss->Configuration.ATIMWindow = pAdapter->ScanTab.BssEntry[i].AtimWin;
4515 MAP_CHANNEL_ID_TO_KHZ(pAdapter->ScanTab.BssEntry[i].Channel, pBss->Configuration.DSConfig);
4517 if (pAdapter->ScanTab.BssEntry[i].BssType == BSS_INFRA)
4518 pBss->InfrastructureMode = Ndis802_11Infrastructure;
4520 pBss->InfrastructureMode = Ndis802_11IBSS;
4522 NdisMoveMemory(pBss->SupportedRates, pAdapter->ScanTab.BssEntry[i].SupRate, pAdapter->ScanTab.BssEntry[i].SupRateLen);
4523 NdisMoveMemory(pBss->SupportedRates + pAdapter->ScanTab.BssEntry[i].SupRateLen,
4524 pAdapter->ScanTab.BssEntry[i].ExtRate,
4525 pAdapter->ScanTab.BssEntry[i].ExtRateLen);
4527 if (pAdapter->ScanTab.BssEntry[i].VarIELen == 0)
4529 pBss->IELength = sizeof(NDIS_802_11_FIXED_IEs);
4530 NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
4531 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
4535 pBss->IELength = (ULONG)(sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen);
4536 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
4537 NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
4538 NdisMoveMemory(pBss->IEs + sizeof(NDIS_802_11_FIXED_IEs), pAdapter->ScanTab.BssEntry[i].VarIEs, pAdapter->ScanTab.BssEntry[i].VarIELen);
4539 pPtr += pAdapter->ScanTab.BssEntry[i].VarIELen;
4541 pBss->Length = (ULONG)(sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
4543 #if WIRELESS_EXT < 17
4544 if ((BssLen + pBss->Length) < wrq->u.data.length)
4545 BssLen += pBss->Length;
4548 pBssidList->NumberOfItems = i;
4552 BssLen += pBss->Length;
4556 #if WIRELESS_EXT < 17
4557 wrq->u.data.length = BssLen;
4559 if (BssLen > wrq->u.data.length)
4565 wrq->u.data.length = BssLen;
4567 Status = copy_to_user(wrq->u.data.pointer, pBssidList, BssLen);
4570 case OID_802_3_CURRENT_ADDRESS:
4571 wrq->u.data.length = MAC_ADDR_LEN;
4572 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
4574 case OID_GEN_MEDIA_CONNECT_STATUS:
4575 if (pAdapter->IndicateMediaState == NdisMediaStateConnected)
4576 MediaState = NdisMediaStateConnected;
4578 MediaState = NdisMediaStateDisconnected;
4580 wrq->u.data.length = sizeof(NDIS_MEDIA_STATE);
4581 Status = copy_to_user(wrq->u.data.pointer, &MediaState, wrq->u.data.length);
4583 case OID_802_11_BSSID:
4584 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
4586 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Bssid, sizeof(NDIS_802_11_MAC_ADDRESS));
4591 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID(=EMPTY)\n"));
4595 case OID_802_11_SSID:
4596 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
4597 NdisZeroMemory(Ssid.Ssid, MAX_LEN_OF_SSID);
4598 Ssid.SsidLength = pAdapter->CommonCfg.SsidLen;
4599 memcpy(Ssid.Ssid, pAdapter->CommonCfg.Ssid, Ssid.SsidLength);
4600 wrq->u.data.length = sizeof(NDIS_802_11_SSID);
4601 Status = copy_to_user(wrq->u.data.pointer, &Ssid, wrq->u.data.length);
4602 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_SSID (Len=%d, ssid=%s)\n", Ssid.SsidLength,Ssid.Ssid));
4604 case RT_OID_802_11_QUERY_LINK_STATUS:
4605 pLinkStatus = (RT_802_11_LINK_STATUS *) kmalloc(sizeof(RT_802_11_LINK_STATUS), MEM_ALLOC_FLAG);
4608 pLinkStatus->CurrTxRate = RateIdTo500Kbps[pAdapter->CommonCfg.TxRate]; // unit : 500 kbps
4609 pLinkStatus->ChannelQuality = pAdapter->Mlme.ChannelQuality;
4610 pLinkStatus->RxByteCount = pAdapter->RalinkCounters.ReceivedByteCount;
4611 pLinkStatus->TxByteCount = pAdapter->RalinkCounters.TransmittedByteCount;
4612 pLinkStatus->CentralChannel = pAdapter->CommonCfg.CentralChannel;
4613 wrq->u.data.length = sizeof(RT_802_11_LINK_STATUS);
4614 Status = copy_to_user(wrq->u.data.pointer, pLinkStatus, wrq->u.data.length);
4616 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS\n"));
4620 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS(kmalloc failed)\n"));
4624 case OID_802_11_CONFIGURATION:
4625 pConfiguration = (NDIS_802_11_CONFIGURATION *) kmalloc(sizeof(NDIS_802_11_CONFIGURATION), MEM_ALLOC_FLAG);
4628 pConfiguration->Length = sizeof(NDIS_802_11_CONFIGURATION);
4629 pConfiguration->BeaconPeriod = pAdapter->CommonCfg.BeaconPeriod;
4630 pConfiguration->ATIMWindow = pAdapter->StaActive.AtimWin;
4631 MAP_CHANNEL_ID_TO_KHZ(pAdapter->CommonCfg.Channel, pConfiguration->DSConfig);
4632 wrq->u.data.length = sizeof(NDIS_802_11_CONFIGURATION);
4633 Status = copy_to_user(wrq->u.data.pointer, pConfiguration, wrq->u.data.length);
4634 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(BeaconPeriod=%ld,AtimW=%ld,Channel=%d) \n",
4635 pConfiguration->BeaconPeriod, pConfiguration->ATIMWindow, pAdapter->CommonCfg.Channel));
4636 kfree(pConfiguration);
4640 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(kmalloc failed)\n"));
4644 case RT_OID_802_11_SNR_0:
4645 if ((pAdapter->StaCfg.LastSNR0 > 0))
4647 ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR0) * 3) / 16 ;
4648 wrq->u.data.length = sizeof(ulInfo);
4649 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4650 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_SNR_0(0x=%lx)\n", ulInfo));
4655 case RT_OID_802_11_SNR_1:
4656 if ((pAdapter->Antenna.field.RxPath > 1) &&
4657 (pAdapter->StaCfg.LastSNR1 > 0))
4659 ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR1) * 3) / 16 ;
4660 wrq->u.data.length = sizeof(ulInfo);
4661 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4662 DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(0x=%lx)\n",ulInfo));
4666 DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(pAdapter->StaCfg.LastSNR1=%d)\n",pAdapter->StaCfg.LastSNR1));
4668 case OID_802_11_RSSI_TRIGGER:
4669 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0 - pAdapter->BbpRssiToDbmDelta;
4670 wrq->u.data.length = sizeof(ulInfo);
4671 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4672 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RSSI_TRIGGER(=%ld)\n", ulInfo));
4674 case OID_802_11_RSSI:
4675 case RT_OID_802_11_RSSI:
4676 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0;
4677 wrq->u.data.length = sizeof(ulInfo);
4678 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4680 case RT_OID_802_11_RSSI_1:
4681 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi1;
4682 wrq->u.data.length = sizeof(ulInfo);
4683 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4685 case RT_OID_802_11_RSSI_2:
4686 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi2;
4687 wrq->u.data.length = sizeof(ulInfo);
4688 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4690 case OID_802_11_STATISTICS:
4691 pStatistics = (NDIS_802_11_STATISTICS *) kmalloc(sizeof(NDIS_802_11_STATISTICS), MEM_ALLOC_FLAG);
4694 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS \n"));
4695 // add the most up-to-date h/w raw counters into software counters
4696 NICUpdateRawCounters(pAdapter);
4698 // Sanity check for calculation of sucessful count
4699 if (pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart < pAdapter->WlanCounters.RetryCount.QuadPart)
4700 pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
4702 pStatistics->TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart;
4703 pStatistics->MulticastTransmittedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastTransmittedFrameCount.QuadPart;
4704 pStatistics->FailedCount.QuadPart = pAdapter->WlanCounters.FailedCount.QuadPart;
4705 pStatistics->RetryCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
4706 pStatistics->MultipleRetryCount.QuadPart = pAdapter->WlanCounters.MultipleRetryCount.QuadPart;
4707 pStatistics->RTSSuccessCount.QuadPart = pAdapter->WlanCounters.RTSSuccessCount.QuadPart;
4708 pStatistics->RTSFailureCount.QuadPart = pAdapter->WlanCounters.RTSFailureCount.QuadPart;
4709 pStatistics->ACKFailureCount.QuadPart = pAdapter->WlanCounters.ACKFailureCount.QuadPart;
4710 pStatistics->FrameDuplicateCount.QuadPart = pAdapter->WlanCounters.FrameDuplicateCount.QuadPart;
4711 pStatistics->ReceivedFragmentCount.QuadPart = pAdapter->WlanCounters.ReceivedFragmentCount.QuadPart;
4712 pStatistics->MulticastReceivedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastReceivedFrameCount.QuadPart;
4714 pStatistics->FCSErrorCount = pAdapter->RalinkCounters.RealFcsErrCount;
4716 pStatistics->FCSErrorCount.QuadPart = pAdapter->WlanCounters.FCSErrorCount.QuadPart;
4717 pStatistics->FrameDuplicateCount.u.LowPart = pAdapter->WlanCounters.FrameDuplicateCount.u.LowPart / 100;
4719 wrq->u.data.length = sizeof(NDIS_802_11_STATISTICS);
4720 Status = copy_to_user(wrq->u.data.pointer, pStatistics, wrq->u.data.length);
4725 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS(kmalloc failed)\n"));
4729 case OID_GEN_RCV_OK:
4730 ulInfo = pAdapter->Counters8023.GoodReceives;
4731 wrq->u.data.length = sizeof(ulInfo);
4732 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4734 case OID_GEN_RCV_NO_BUFFER:
4735 ulInfo = pAdapter->Counters8023.RxNoBuffer;
4736 wrq->u.data.length = sizeof(ulInfo);
4737 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4739 case RT_OID_802_11_PHY_MODE:
4740 ulInfo = (ULONG)pAdapter->CommonCfg.PhyMode;
4741 wrq->u.data.length = sizeof(ulInfo);
4742 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4743 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PHY_MODE (=%ld)\n", ulInfo));
4745 case RT_OID_802_11_STA_CONFIG:
4746 pStaConfig = (RT_802_11_STA_CONFIG *) kmalloc(sizeof(RT_802_11_STA_CONFIG), MEM_ALLOC_FLAG);
4749 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG\n"));
4750 pStaConfig->EnableTxBurst = pAdapter->CommonCfg.bEnableTxBurst;
4751 pStaConfig->EnableTurboRate = 0;
4752 pStaConfig->UseBGProtection = pAdapter->CommonCfg.UseBGProtection;
4753 pStaConfig->UseShortSlotTime = pAdapter->CommonCfg.bUseShortSlotTime;
4754 //pStaConfig->AdhocMode = pAdapter->StaCfg.AdhocMode;
4755 pStaConfig->HwRadioStatus = (pAdapter->StaCfg.bHwRadio == TRUE) ? 1 : 0;
4756 pStaConfig->Rsv1 = 0;
4757 pStaConfig->SystemErrorBitmap = pAdapter->SystemErrorBitmap;
4758 wrq->u.data.length = sizeof(RT_802_11_STA_CONFIG);
4759 Status = copy_to_user(wrq->u.data.pointer, pStaConfig, wrq->u.data.length);
4764 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
4768 case OID_802_11_RTS_THRESHOLD:
4769 RtsThresh = pAdapter->CommonCfg.RtsThreshold;
4770 wrq->u.data.length = sizeof(RtsThresh);
4771 Status = copy_to_user(wrq->u.data.pointer, &RtsThresh, wrq->u.data.length);
4772 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RTS_THRESHOLD(=%ld)\n", RtsThresh));
4774 case OID_802_11_FRAGMENTATION_THRESHOLD:
4775 FragThresh = pAdapter->CommonCfg.FragmentThreshold;
4776 if (pAdapter->CommonCfg.bUseZeroToDisableFragment == TRUE)
4778 wrq->u.data.length = sizeof(FragThresh);
4779 Status = copy_to_user(wrq->u.data.pointer, &FragThresh, wrq->u.data.length);
4780 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_FRAGMENTATION_THRESHOLD(=%ld)\n", FragThresh));
4782 case OID_802_11_POWER_MODE:
4783 PowerMode = pAdapter->StaCfg.WindowsPowerMode;
4784 wrq->u.data.length = sizeof(PowerMode);
4785 Status = copy_to_user(wrq->u.data.pointer, &PowerMode, wrq->u.data.length);
4786 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_POWER_MODE(=%d)\n", PowerMode));
4788 case RT_OID_802_11_RADIO:
4789 RadioState = (BOOLEAN) pAdapter->StaCfg.bSwRadio;
4790 wrq->u.data.length = sizeof(RadioState);
4791 Status = copy_to_user(wrq->u.data.pointer, &RadioState, wrq->u.data.length);
4792 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_RADIO (=%d)\n", RadioState));
4794 case OID_802_11_INFRASTRUCTURE_MODE:
4795 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
4796 BssType = Ndis802_11IBSS;
4797 else if (pAdapter->StaCfg.BssType == BSS_INFRA)
4798 BssType = Ndis802_11Infrastructure;
4799 else if (pAdapter->StaCfg.BssType == BSS_MONITOR)
4800 BssType = Ndis802_11Monitor;
4802 BssType = Ndis802_11AutoUnknown;
4804 wrq->u.data.length = sizeof(BssType);
4805 Status = copy_to_user(wrq->u.data.pointer, &BssType, wrq->u.data.length);
4806 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_INFRASTRUCTURE_MODE(=%d)\n", BssType));
4808 case RT_OID_802_11_PREAMBLE:
4809 PreamType = pAdapter->CommonCfg.TxPreamble;
4810 wrq->u.data.length = sizeof(PreamType);
4811 Status = copy_to_user(wrq->u.data.pointer, &PreamType, wrq->u.data.length);
4812 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PREAMBLE(=%d)\n", PreamType));
4814 case OID_802_11_AUTHENTICATION_MODE:
4815 AuthMode = pAdapter->StaCfg.AuthMode;
4816 wrq->u.data.length = sizeof(AuthMode);
4817 Status = copy_to_user(wrq->u.data.pointer, &AuthMode, wrq->u.data.length);
4818 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_AUTHENTICATION_MODE(=%d)\n", AuthMode));
4820 case OID_802_11_WEP_STATUS:
4821 WepStatus = pAdapter->StaCfg.WepStatus;
4822 wrq->u.data.length = sizeof(WepStatus);
4823 Status = copy_to_user(wrq->u.data.pointer, &WepStatus, wrq->u.data.length);
4824 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_WEP_STATUS(=%d)\n", WepStatus));
4826 case OID_802_11_TX_POWER_LEVEL:
4827 wrq->u.data.length = sizeof(ULONG);
4828 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPower, wrq->u.data.length);
4829 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_TX_POWER_LEVEL %x\n",pAdapter->CommonCfg.TxPower));
4831 case RT_OID_802_11_TX_POWER_LEVEL_1:
4832 wrq->u.data.length = sizeof(ULONG);
4833 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPowerPercentage, wrq->u.data.length);
4834 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
4836 case OID_802_11_NETWORK_TYPES_SUPPORTED:
4837 if ((pAdapter->RfIcType == RFIC_2850) || (pAdapter->RfIcType == RFIC_2750))
4839 NetworkTypeList[0] = 3; // NumberOfItems = 3
4840 NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
4841 NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
4842 NetworkTypeList[3] = Ndis802_11OFDM5; // NetworkType[3] = 11a
4843 wrq->u.data.length = 16;
4844 Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
4848 NetworkTypeList[0] = 2; // NumberOfItems = 2
4849 NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
4850 NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
4851 wrq->u.data.length = 12;
4852 Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
4854 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_NETWORK_TYPES_SUPPORTED\n"));
4856 case OID_802_11_NETWORK_TYPE_IN_USE:
4857 wrq->u.data.length = sizeof(ULONG);
4858 if (pAdapter->CommonCfg.PhyMode == PHY_11A)
4859 ulInfo = Ndis802_11OFDM5;
4860 else if ((pAdapter->CommonCfg.PhyMode == PHY_11BG_MIXED) || (pAdapter->CommonCfg.PhyMode == PHY_11G))
4861 ulInfo = Ndis802_11OFDM24;
4863 ulInfo = Ndis802_11DS;
4864 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4866 case RT_OID_802_11_QUERY_LAST_RX_RATE:
4867 ulInfo = (ULONG)pAdapter->LastRxRate;
4868 wrq->u.data.length = sizeof(ulInfo);
4869 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4870 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_RX_RATE (=%ld)\n", ulInfo));
4872 case RT_OID_802_11_QUERY_LAST_TX_RATE:
4873 //ulInfo = (ULONG)pAdapter->LastTxRate;
4874 ulInfo = (ULONG)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word;
4875 wrq->u.data.length = sizeof(ulInfo);
4876 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4877 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_TX_RATE (=%lx)\n", ulInfo));
4879 case RT_OID_802_11_QUERY_EEPROM_VERSION:
4880 wrq->u.data.length = sizeof(ULONG);
4881 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->EepromVersion, wrq->u.data.length);
4883 case RT_OID_802_11_QUERY_FIRMWARE_VERSION:
4884 wrq->u.data.length = sizeof(ULONG);
4885 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->FirmwareVersion, wrq->u.data.length);
4887 case RT_OID_802_11_QUERY_NOISE_LEVEL:
4888 wrq->u.data.length = sizeof(UCHAR);
4889 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->BbpWriteLatch[66], wrq->u.data.length);
4890 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_NOISE_LEVEL (=%d)\n", pAdapter->BbpWriteLatch[66]));
4892 case RT_OID_802_11_EXTRA_INFO:
4893 wrq->u.data.length = sizeof(ULONG);
4894 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->ExtraInfo, wrq->u.data.length);
4895 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_EXTRA_INFO (=%ld)\n", pAdapter->ExtraInfo));
4897 case RT_OID_WE_VERSION_COMPILED:
4898 wrq->u.data.length = sizeof(UINT);
4899 we_version_compiled = WIRELESS_EXT;
4900 Status = copy_to_user(wrq->u.data.pointer, &we_version_compiled, wrq->u.data.length);
4902 case RT_OID_802_11_QUERY_APSD_SETTING:
4903 apsd = (pAdapter->CommonCfg.bAPSDCapable | (pAdapter->CommonCfg.bAPSDAC_BE << 1) | (pAdapter->CommonCfg.bAPSDAC_BK << 2)
4904 | (pAdapter->CommonCfg.bAPSDAC_VI << 3) | (pAdapter->CommonCfg.bAPSDAC_VO << 4) | (pAdapter->CommonCfg.MaxSPLength << 5));
4906 wrq->u.data.length = sizeof(ULONG);
4907 Status = copy_to_user(wrq->u.data.pointer, &apsd, wrq->u.data.length);
4908 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",
4909 apsd,pAdapter->CommonCfg.bAPSDCapable,pAdapter->CommonCfg.bAPSDAC_BE,pAdapter->CommonCfg.bAPSDAC_BK,pAdapter->CommonCfg.bAPSDAC_VI,pAdapter->CommonCfg.bAPSDAC_VO,pAdapter->CommonCfg.MaxSPLength));
4911 case RT_OID_802_11_QUERY_APSD_PSM:
4912 wrq->u.data.length = sizeof(ULONG);
4913 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.length);
4914 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_APSD_PSM (=%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
4916 case RT_OID_802_11_QUERY_WMM:
4917 wrq->u.data.length = sizeof(BOOLEAN);
4918 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bWmmCapable, wrq->u.data.length);
4919 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_WMM (=%d)\n", pAdapter->CommonCfg.bWmmCapable));
4921 #ifdef WPA_SUPPLICANT_SUPPORT
4922 case RT_OID_NEW_DRIVER:
4925 wrq->u.data.length = sizeof(UCHAR);
4926 Status = copy_to_user(wrq->u.data.pointer, &enabled, wrq->u.data.length);
4927 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_NEW_DRIVER (=%d)\n", enabled));
4930 case RT_OID_WPA_SUPPLICANT_SUPPORT:
4931 wrq->u.data.length = sizeof(UCHAR);
4932 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->StaCfg.WpaSupplicantUP, wrq->u.data.length);
4933 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
4935 #endif // WPA_SUPPLICANT_SUPPORT //
4937 case RT_OID_DRIVER_DEVICE_NAME:
4938 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_DRIVER_DEVICE_NAME \n"));
4939 wrq->u.data.length = 16;
4940 if (copy_to_user(wrq->u.data.pointer, pAdapter->StaCfg.dev_name, wrq->u.data.length))
4945 case RT_OID_802_11_QUERY_HT_PHYMODE:
4946 pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
4949 pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
4950 pHTPhyMode->HtMode = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE;
4951 pHTPhyMode->BW = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.BW;
4952 pHTPhyMode->MCS= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MCS;
4953 pHTPhyMode->SHORTGI= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.ShortGI;
4954 pHTPhyMode->STBC= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.STBC;
4956 pHTPhyMode->ExtOffset = ((pAdapter->CommonCfg.CentralChannel < pAdapter->CommonCfg.Channel) ? (EXTCHA_BELOW) : (EXTCHA_ABOVE));
4957 wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
4958 if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
4962 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
4963 pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
4964 DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
4968 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
4972 case RT_OID_802_11_COUNTRY_REGION:
4973 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_COUNTRY_REGION \n"));
4974 wrq->u.data.length = sizeof(ulInfo);
4975 ulInfo = pAdapter->CommonCfg.CountryRegionForABand;
4976 ulInfo = (ulInfo << 8)|(pAdapter->CommonCfg.CountryRegion);
4977 if (copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length))
4982 case RT_OID_802_11_QUERY_DAT_HT_PHYMODE:
4983 pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
4986 pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
4987 pHTPhyMode->HtMode = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.HTMODE;
4988 pHTPhyMode->BW = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.BW;
4989 pHTPhyMode->MCS= (UCHAR)pAdapter->StaCfg.DesiredTransmitSetting.field.MCS;
4990 pHTPhyMode->SHORTGI= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.ShortGI;
4991 pHTPhyMode->STBC= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.STBC;
4993 wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
4994 if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
4998 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
4999 pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
5000 DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
5004 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
5008 case RT_OID_QUERY_MULTIPLE_CARD_SUPPORT:
5009 wrq->u.data.length = sizeof(UCHAR);
5011 if (copy_to_user(wrq->u.data.pointer, &i, wrq->u.data.length))
5015 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_QUERY_MULTIPLE_CARD_SUPPORT(=%d) \n", i));
5018 case RT_OID_802_11_MAC_ADDRESS:
5019 wrq->u.data.length = MAC_ADDR_LEN;
5020 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
5023 case RT_OID_802_11_MANUFACTUREROUI:
5024 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_MANUFACTUREROUI \n"));
5025 wrq->u.data.length = ManufacturerOUI_LEN;
5026 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
5029 case RT_OID_802_11_MANUFACTURERNAME:
5030 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_MANUFACTURERNAME \n"));
5031 wrq->u.data.length = strlen(ManufacturerNAME);
5032 Status = copy_to_user(wrq->u.data.pointer, ManufacturerNAME, wrq->u.data.length);
5035 case RT_OID_802_11_RESOURCETYPEIDNAME:
5036 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_RESOURCETYPEIDNAME \n"));
5037 wrq->u.data.length = strlen(ResourceTypeIdName);
5038 Status = copy_to_user(wrq->u.data.pointer, ResourceTypeIdName, wrq->u.data.length);
5041 case RT_OID_802_11_PRIVACYOPTIONIMPLEMENTED:
5042 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PRIVACYOPTIONIMPLEMENTED \n"));
5043 ulInfo = 1; // 1 is support wep else 2 is not support.
5044 wrq->u.data.length = sizeof(ulInfo);
5045 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
5048 case RT_OID_802_11_POWERMANAGEMENTMODE:
5049 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_POWERMANAGEMENTMODE \n"));
5050 if (pAdapter->StaCfg.Psm == PSMP_ACTION)
5051 ulInfo = 1; // 1 is power active else 2 is power save.
5055 wrq->u.data.length = sizeof(ulInfo);
5056 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
5059 case OID_802_11_WEPDEFAULTKEYVALUE:
5060 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_WEPDEFAULTKEYVALUE \n"));
5061 //KeyIdxValue.KeyIdx = pAd->PortCfg.MBSSID[pAd->IoctlIF].DefaultKeyId;
5062 pKeyIdxValue = wrq->u.data.pointer;
5063 DBGPRINT(RT_DEBUG_TRACE,("KeyIdxValue.KeyIdx = %d, \n",pKeyIdxValue->KeyIdx));
5064 valueLen = pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen;
5065 NdisMoveMemory(pKeyIdxValue->Value,
5066 &pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key,
5068 pKeyIdxValue->Value[valueLen]='\0';
5070 wrq->u.data.length = sizeof(DefaultKeyIdxValue);
5072 Status = copy_to_user(wrq->u.data.pointer, pKeyIdxValue, wrq->u.data.length);
5073 DBGPRINT(RT_DEBUG_TRACE,("DefaultKeyId = %d, total len = %d, str len=%d, KeyValue= %02x %02x %02x %02x \n", pAdapter->StaCfg.DefaultKeyId, wrq->u.data.length, pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen,
5074 pAdapter->SharedKey[BSS0][0].Key[0],
5075 pAdapter->SharedKey[BSS0][1].Key[0],
5076 pAdapter->SharedKey[BSS0][2].Key[0],
5077 pAdapter->SharedKey[BSS0][3].Key[0]));
5080 case OID_802_11_WEPDEFAULTKEYID:
5081 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_WEPDEFAULTKEYID \n"));
5082 wrq->u.data.length = sizeof(UCHAR);
5083 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->StaCfg.DefaultKeyId, wrq->u.data.length);
5084 DBGPRINT(RT_DEBUG_TRACE, ("DefaultKeyId =%d \n", pAdapter->StaCfg.DefaultKeyId));
5087 case RT_OID_802_11_WEPKEYMAPPINGLENGTH:
5088 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_WEPKEYMAPPINGLENGTH \n"));
5089 wrq->u.data.length = sizeof(UCHAR);
5090 Status = copy_to_user(wrq->u.data.pointer,
5091 &pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen,
5092 wrq->u.data.length);
5095 case OID_802_11_SHORTRETRYLIMIT:
5096 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_SHORTRETRYLIMIT \n"));
5097 wrq->u.data.length = sizeof(ULONG);
5098 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
5099 ShortRetryLimit = tx_rty_cfg.field.ShortRtyLimit;
5100 DBGPRINT(RT_DEBUG_TRACE, ("ShortRetryLimit =%ld, tx_rty_cfg.field.ShortRetryLimit=%d\n", ShortRetryLimit, tx_rty_cfg.field.ShortRtyLimit));
5101 Status = copy_to_user(wrq->u.data.pointer, &ShortRetryLimit, wrq->u.data.length);
5104 case OID_802_11_LONGRETRYLIMIT:
5105 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_LONGRETRYLIMIT \n"));
5106 wrq->u.data.length = sizeof(ULONG);
5107 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
5108 LongRetryLimit = tx_rty_cfg.field.LongRtyLimit;
5109 DBGPRINT(RT_DEBUG_TRACE, ("LongRetryLimit =%ld, tx_rty_cfg.field.LongRtyLimit=%d\n", LongRetryLimit, tx_rty_cfg.field.LongRtyLimit));
5110 Status = copy_to_user(wrq->u.data.pointer, &LongRetryLimit, wrq->u.data.length);
5113 case RT_OID_802_11_PRODUCTID:
5114 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PRODUCTID \n"));
5117 sprintf(tmp, "%04x %04x\n", ((POS_COOKIE)pAdapter->OS_Cookie)->pUsb_Dev->descriptor.idVendor ,((POS_COOKIE)pAdapter->OS_Cookie)->pUsb_Dev->descriptor.idProduct);
5120 wrq->u.data.length = strlen(tmp);
5121 Status = copy_to_user(wrq->u.data.pointer, tmp, wrq->u.data.length);
5124 case RT_OID_802_11_MANUFACTUREID:
5125 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_MANUFACTUREID \n"));
5126 wrq->u.data.length = strlen(ManufacturerNAME);
5127 Status = copy_to_user(wrq->u.data.pointer, ManufacturerNAME, wrq->u.data.length);
5130 case OID_802_11_CURRENTCHANNEL:
5131 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CURRENTCHANNEL \n"));
5132 wrq->u.data.length = sizeof(UCHAR);
5133 DBGPRINT(RT_DEBUG_TRACE, ("sizeof UCHAR=%d, channel=%d \n", sizeof(UCHAR), pAdapter->CommonCfg.Channel));
5134 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Channel, wrq->u.data.length);
5135 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5137 #endif //SNMP_SUPPORT
5139 case OID_802_11_BUILD_CHANNEL_EX:
5142 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BUILD_CHANNEL_EX \n"));
5143 wrq->u.data.length = sizeof(UCHAR);
5144 DBGPRINT(RT_DEBUG_TRACE, ("Doesn't support EXT_BUILD_CHANNEL_LIST.\n"));
5146 Status = copy_to_user(wrq->u.data.pointer, &value, 1);
5147 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5151 case OID_802_11_GET_CH_LIST:
5153 PRT_CHANNEL_LIST_INFO pChListBuf;
5155 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CH_LIST \n"));
5156 if (pAdapter->ChannelListNum == 0)
5158 wrq->u.data.length = 0;
5162 pChListBuf = (RT_CHANNEL_LIST_INFO *) kmalloc(sizeof(RT_CHANNEL_LIST_INFO), MEM_ALLOC_FLAG);
5163 if (pChListBuf == NULL)
5165 wrq->u.data.length = 0;
5169 pChListBuf->ChannelListNum = pAdapter->ChannelListNum;
5170 for (i = 0; i < pChListBuf->ChannelListNum; i++)
5171 pChListBuf->ChannelList[i] = pAdapter->ChannelList[i].Channel;
5173 wrq->u.data.length = sizeof(RT_CHANNEL_LIST_INFO);
5174 Status = copy_to_user(wrq->u.data.pointer, pChListBuf, sizeof(RT_CHANNEL_LIST_INFO));
5175 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5182 case OID_802_11_GET_COUNTRY_CODE:
5183 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_COUNTRY_CODE \n"));
5184 wrq->u.data.length = 2;
5185 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.CountryCode, 2);
5186 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5189 case OID_802_11_GET_CHANNEL_GEOGRAPHY:
5190 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CHANNEL_GEOGRAPHY \n"));
5191 wrq->u.data.length = 1;
5192 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Geography, 1);
5193 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5197 DBGPRINT(RT_DEBUG_TRACE, ("Query::unknown IOCTL's subcmd = 0x%08x\n", cmd));
5198 Status = -EOPNOTSUPP;
5204 INT rt28xx_sta_ioctl(
5205 IN struct net_device *net_dev,
5206 IN OUT struct ifreq *rq,
5210 VIRTUAL_ADAPTER *pVirtualAd = NULL;
5211 RTMP_ADAPTER *pAd = NULL;
5212 struct iwreq *wrq = (struct iwreq *) rq;
5213 BOOLEAN StateMachineTouched = FALSE;
5214 INT Status = NDIS_STATUS_SUCCESS;
5217 if (net_dev->priv_flags == INT_MAIN)
5219 pAd = net_dev->ml_priv;
5223 pVirtualAd = net_dev->ml_priv;
5224 pAd = pVirtualAd->RtmpDev->ml_priv;
5226 pObj = (POS_COOKIE) pAd->OS_Cookie;
5230 /* if 1st open fail, pAd will be free;
5231 So the net_dev->ml_priv will be NULL in 2rd open */
5235 //check if the interface is down
5236 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
5239 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
5244 { // determine this ioctl command is comming from which interface.
5245 pObj->ioctl_if_type = INT_MAIN;
5246 pObj->ioctl_if = MAIN_MBSSID;
5252 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIFHWADDR\n"));
5253 memcpy(wrq->u.name, pAd->CurrentAddress, ETH_ALEN);
5257 char *name=&wrq->u.name[0];
5258 rt_ioctl_giwname(net_dev, NULL, name, NULL);
5261 case SIOCGIWESSID: //Get ESSID
5263 struct iw_point *essid=&wrq->u.essid;
5264 rt_ioctl_giwessid(net_dev, NULL, essid, essid->pointer);
5267 case SIOCSIWESSID: //Set ESSID
5269 struct iw_point *essid=&wrq->u.essid;
5270 rt_ioctl_siwessid(net_dev, NULL, essid, essid->pointer);
5273 case SIOCSIWNWID: // set network id (the cell)
5274 case SIOCGIWNWID: // get network id
5275 Status = -EOPNOTSUPP;
5277 case SIOCSIWFREQ: //set channel/frequency (Hz)
5279 struct iw_freq *freq=&wrq->u.freq;
5280 rt_ioctl_siwfreq(net_dev, NULL, freq, NULL);
5283 case SIOCGIWFREQ: // get channel/frequency (Hz)
5285 struct iw_freq *freq=&wrq->u.freq;
5286 rt_ioctl_giwfreq(net_dev, NULL, freq, NULL);
5289 case SIOCSIWNICKN: //set node name/nickname
5291 struct iw_point *data=&wrq->u.data;
5292 rt_ioctl_siwnickn(net_dev, NULL, data, NULL);
5295 case SIOCGIWNICKN: //get node name/nickname
5297 struct iw_point *data=&wrq->u.data;
5298 rt_ioctl_giwnickn(net_dev, NULL, data, NULL);
5301 case SIOCGIWRATE: //get default bit rate (bps)
5302 rt_ioctl_giwrate(net_dev, NULL, &wrq->u, NULL);
5304 case SIOCSIWRATE: //set default bit rate (bps)
5305 rt_ioctl_siwrate(net_dev, NULL, &wrq->u, NULL);
5307 case SIOCGIWRTS: // get RTS/CTS threshold (bytes)
5309 struct iw_param *rts=&wrq->u.rts;
5310 rt_ioctl_giwrts(net_dev, NULL, rts, NULL);
5313 case SIOCSIWRTS: //set RTS/CTS threshold (bytes)
5315 struct iw_param *rts=&wrq->u.rts;
5316 rt_ioctl_siwrts(net_dev, NULL, rts, NULL);
5319 case SIOCGIWFRAG: //get fragmentation thr (bytes)
5321 struct iw_param *frag=&wrq->u.frag;
5322 rt_ioctl_giwfrag(net_dev, NULL, frag, NULL);
5325 case SIOCSIWFRAG: //set fragmentation thr (bytes)
5327 struct iw_param *frag=&wrq->u.frag;
5328 rt_ioctl_siwfrag(net_dev, NULL, frag, NULL);
5331 case SIOCGIWENCODE: //get encoding token & mode
5333 struct iw_point *erq=&wrq->u.encoding;
5335 rt_ioctl_giwencode(net_dev, NULL, erq, erq->pointer);
5338 case SIOCSIWENCODE: //set encoding token & mode
5340 struct iw_point *erq=&wrq->u.encoding;
5342 rt_ioctl_siwencode(net_dev, NULL, erq, erq->pointer);
5345 case SIOCGIWAP: //get access point MAC addresses
5347 struct sockaddr *ap_addr=&wrq->u.ap_addr;
5348 rt_ioctl_giwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
5351 case SIOCSIWAP: //set access point MAC addresses
5353 struct sockaddr *ap_addr=&wrq->u.ap_addr;
5354 rt_ioctl_siwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
5357 case SIOCGIWMODE: //get operation mode
5359 __u32 *mode=&wrq->u.mode;
5360 rt_ioctl_giwmode(net_dev, NULL, mode, NULL);
5363 case SIOCSIWMODE: //set operation mode
5365 __u32 *mode=&wrq->u.mode;
5366 rt_ioctl_siwmode(net_dev, NULL, mode, NULL);
5369 case SIOCGIWSENS: //get sensitivity (dBm)
5370 case SIOCSIWSENS: //set sensitivity (dBm)
5371 case SIOCGIWPOWER: //get Power Management settings
5372 case SIOCSIWPOWER: //set Power Management settings
5373 case SIOCGIWTXPOW: //get transmit power (dBm)
5374 case SIOCSIWTXPOW: //set transmit power (dBm)
5375 case SIOCGIWRANGE: //Get range of parameters
5376 case SIOCGIWRETRY: //get retry limits and lifetime
5377 case SIOCSIWRETRY: //set retry limits and lifetime
5378 Status = -EOPNOTSUPP;
5381 subcmd = wrq->u.data.flags;
5382 if( subcmd & OID_GET_SET_TOGGLE)
5383 Status = RTMPSetInformation(pAd, rq, subcmd);
5385 Status = RTMPQueryInformation(pAd, rq, subcmd);
5388 if (wrq->u.data.pointer)
5390 if ( access_ok(VERIFY_WRITE, wrq->u.data.pointer, sizeof(privtab)) != TRUE)
5392 wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
5393 if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
5397 case RTPRIV_IOCTL_SET:
5398 if(access_ok(VERIFY_READ, wrq->u.data.pointer, wrq->u.data.length) != TRUE)
5400 rt_ioctl_setparam(net_dev, NULL, NULL, wrq->u.data.pointer);
5402 case RTPRIV_IOCTL_GSITESURVEY:
5403 RTMPIoctlGetSiteSurvey(pAd, wrq);
5406 case RTPRIV_IOCTL_MAC:
5407 RTMPIoctlMAC(pAd, wrq);
5409 case RTPRIV_IOCTL_E2P:
5410 RTMPIoctlE2PROM(pAd, wrq);
5416 DBGPRINT(RT_DEBUG_ERROR, ("IOCTL::unknown IOCTL's cmd = 0x%08x\n", cmd));
5417 Status = -EOPNOTSUPP;
5421 if(StateMachineTouched) // Upper layer sent a MLME-related operations
5422 RT28XX_MLME_HANDLER(pAd);
5428 ==========================================================================
5432 TRUE if all parameters are OK, FALSE otherwise
5433 ==========================================================================
5436 IN PRTMP_ADAPTER pAdapter,
5439 NDIS_802_11_SSID Ssid, *pSsid=NULL;
5440 BOOLEAN StateMachineTouched = FALSE;
5443 if( strlen(arg) <= MAX_LEN_OF_SSID)
5445 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
5446 if (strlen(arg) != 0)
5448 NdisMoveMemory(Ssid.Ssid, arg, strlen(arg));
5449 Ssid.SsidLength = strlen(arg);
5453 Ssid.SsidLength = 0;
5454 memcpy(Ssid.Ssid, "", 0);
5455 pAdapter->StaCfg.BssType = BSS_INFRA;
5456 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
5457 pAdapter->StaCfg.WepStatus = Ndis802_11EncryptionDisabled;
5461 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
5463 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
5464 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
5467 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
5468 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
5469 pAdapter->bConfigChanged = TRUE;
5471 MlmeEnqueue(pAdapter,
5472 MLME_CNTL_STATE_MACHINE,
5474 sizeof(NDIS_802_11_SSID),
5477 StateMachineTouched = TRUE;
5478 DBGPRINT(RT_DEBUG_TRACE, ("Set_SSID_Proc::(Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
5483 if (StateMachineTouched) // Upper layer sent a MLME-related operations
5484 RT28XX_MLME_HANDLER(pAdapter);
5491 ==========================================================================
5493 Set WmmCapable Enable or Disable
5495 TRUE if all parameters are OK, FALSE otherwise
5496 ==========================================================================
5498 INT Set_WmmCapable_Proc(
5499 IN PRTMP_ADAPTER pAd,
5502 BOOLEAN bWmmCapable;
5504 bWmmCapable = simple_strtol(arg, 0, 10);
5506 if ((bWmmCapable == 1)
5508 && (pAd->NumberOfPipes >= 5)
5511 pAd->CommonCfg.bWmmCapable = TRUE;
5512 else if (bWmmCapable == 0)
5513 pAd->CommonCfg.bWmmCapable = FALSE;
5515 return FALSE; //Invalid argument
5517 DBGPRINT(RT_DEBUG_TRACE, ("Set_WmmCapable_Proc::(bWmmCapable=%d)\n",
5518 pAd->CommonCfg.bWmmCapable));
5522 #endif // WMM_SUPPORT //
5525 ==========================================================================
5527 Set Network Type(Infrastructure/Adhoc mode)
5529 TRUE if all parameters are OK, FALSE otherwise
5530 ==========================================================================
5532 INT Set_NetworkType_Proc(
5533 IN PRTMP_ADAPTER pAdapter,
5538 if (strcmp(arg, "Adhoc") == 0)
5540 if (pAdapter->StaCfg.BssType != BSS_ADHOC)
5542 // Config has changed
5543 pAdapter->bConfigChanged = TRUE;
5544 if (MONITOR_ON(pAdapter))
5546 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
5547 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5549 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5550 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5551 pAdapter->StaCfg.bAutoReconnect = TRUE;
5552 LinkDown(pAdapter, FALSE);
5554 if (INFRA_ON(pAdapter))
5556 //BOOLEAN Cancelled;
5557 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
5558 // Since calling this indicate user don't want to connect to that SSID anymore.
5559 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
5560 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
5562 LinkDown(pAdapter, FALSE);
5564 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n"));
5567 pAdapter->StaCfg.BssType = BSS_ADHOC;
5568 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
5569 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(AD-HOC)\n"));
5571 else if (strcmp(arg, "Infra") == 0)
5573 if (pAdapter->StaCfg.BssType != BSS_INFRA)
5575 // Config has changed
5576 pAdapter->bConfigChanged = TRUE;
5577 if (MONITOR_ON(pAdapter))
5579 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
5580 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5582 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5583 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5584 pAdapter->StaCfg.bAutoReconnect = TRUE;
5585 LinkDown(pAdapter, FALSE);
5587 if (ADHOC_ON(pAdapter))
5589 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
5590 // Since calling this indicate user don't want to connect to that SSID anymore.
5591 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
5592 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
5594 LinkDown(pAdapter, FALSE);
5597 pAdapter->StaCfg.BssType = BSS_INFRA;
5598 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
5599 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(INFRA)\n"));
5601 pAdapter->StaCfg.BssType = BSS_INFRA;
5603 else if (strcmp(arg, "Monitor") == 0)
5606 BCN_TIME_CFG_STRUC csr;
5607 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_INFRA_ON);
5608 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_ADHOC_ON);
5609 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5610 // disable all periodic state machine
5611 pAdapter->StaCfg.bAutoReconnect = FALSE;
5612 // reset all mlme state machine
5613 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
5614 DBGPRINT(RT_DEBUG_TRACE, ("fOP_STATUS_MEDIA_STATE_CONNECTED \n"));
5615 if (pAdapter->CommonCfg.CentralChannel == 0)
5617 #ifdef DOT11_N_SUPPORT
5618 if (pAdapter->CommonCfg.PhyMode == PHY_11AN_MIXED)
5619 pAdapter->CommonCfg.CentralChannel = 36;
5621 #endif // DOT11_N_SUPPORT //
5622 pAdapter->CommonCfg.CentralChannel = 6;
5624 #ifdef DOT11_N_SUPPORT
5626 N_ChannelCheck(pAdapter);
5627 #endif // DOT11_N_SUPPORT //
5629 #ifdef DOT11_N_SUPPORT
5630 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
5631 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
5632 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_ABOVE)
5634 // 40MHz ,control channel at lower
5635 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5636 bbpValue &= (~0x18);
5638 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5639 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
5640 // RX : control channel at lower
5641 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
5642 bbpValue &= (~0x20);
5643 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
5645 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
5646 Value &= 0xfffffffe;
5647 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
5648 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel + 2;
5649 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
5650 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
5651 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
5652 pAdapter->CommonCfg.Channel,
5653 pAdapter->CommonCfg.CentralChannel));
5655 else if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
5656 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
5657 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_BELOW)
5659 // 40MHz ,control channel at upper
5660 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5661 bbpValue &= (~0x18);
5663 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5664 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
5665 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
5667 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
5669 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
5671 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
5672 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel - 2;
5673 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
5674 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
5675 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
5676 pAdapter->CommonCfg.Channel,
5677 pAdapter->CommonCfg.CentralChannel));
5680 #endif // DOT11_N_SUPPORT //
5683 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5684 bbpValue &= (~0x18);
5685 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5686 pAdapter->CommonCfg.BBPCurrentBW = BW_20;
5687 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.Channel, FALSE);
5688 AsicLockChannel(pAdapter, pAdapter->CommonCfg.Channel);
5689 DBGPRINT(RT_DEBUG_TRACE, ("BW_20, Channel(%d)\n", pAdapter->CommonCfg.Channel));
5691 // Enable Rx with promiscuous reception
5692 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, 0x3);
5693 // ASIC supporsts sniffer function with replacing RSSI with timestamp.
5694 //RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5696 //RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5698 RTMP_IO_READ32(pAdapter, BCN_TIME_CFG, &csr.word);
5699 csr.field.bBeaconGen = 0;
5700 csr.field.bTBTTEnable = 0;
5701 csr.field.TsfSyncMode = 0;
5702 RTMP_IO_WRITE32(pAdapter, BCN_TIME_CFG, csr.word);
5704 pAdapter->StaCfg.BssType = BSS_MONITOR;
5705 pAdapter->net_dev->type = ARPHRD_IEEE80211_PRISM; //ARPHRD_IEEE80211; // IEEE80211
5706 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(MONITOR)\n"));
5709 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
5710 pAdapter->StaCfg.WpaState = SS_NOTUSE;
5712 DBGPRINT(RT_DEBUG_TRACE, ("Set_NetworkType_Proc::(NetworkType=%d)\n", pAdapter->StaCfg.BssType));
5718 ==========================================================================
5720 Set Authentication mode
5722 TRUE if all parameters are OK, FALSE otherwise
5723 ==========================================================================
5725 INT Set_AuthMode_Proc(
5726 IN PRTMP_ADAPTER pAdapter,
5729 if ((strcmp(arg, "WEPAUTO") == 0) || (strcmp(arg, "wepauto") == 0))
5730 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeAutoSwitch;
5731 else if ((strcmp(arg, "OPEN") == 0) || (strcmp(arg, "open") == 0))
5732 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
5733 else if ((strcmp(arg, "SHARED") == 0) || (strcmp(arg, "shared") == 0))
5734 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
5735 else if ((strcmp(arg, "WPAPSK") == 0) || (strcmp(arg, "wpapsk") == 0))
5736 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
5737 else if ((strcmp(arg, "WPANONE") == 0) || (strcmp(arg, "wpanone") == 0))
5738 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
5739 else if ((strcmp(arg, "WPA2PSK") == 0) || (strcmp(arg, "wpa2psk") == 0))
5740 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
5741 #ifdef WPA_SUPPLICANT_SUPPORT
5742 else if ((strcmp(arg, "WPA") == 0) || (strcmp(arg, "wpa") == 0))
5743 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
5744 else if ((strcmp(arg, "WPA2") == 0) || (strcmp(arg, "wpa2") == 0))
5745 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
5746 #endif // WPA_SUPPLICANT_SUPPORT //
5750 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
5752 DBGPRINT(RT_DEBUG_TRACE, ("Set_AuthMode_Proc::(AuthMode=%d)\n", pAdapter->StaCfg.AuthMode));
5758 ==========================================================================
5762 TRUE if all parameters are OK, FALSE otherwise
5763 ==========================================================================
5765 INT Set_EncrypType_Proc(
5766 IN PRTMP_ADAPTER pAdapter,
5769 if ((strcmp(arg, "NONE") == 0) || (strcmp(arg, "none") == 0))
5771 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5772 return TRUE; // do nothing
5774 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
5775 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
5776 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
5778 else if ((strcmp(arg, "WEP") == 0) || (strcmp(arg, "wep") == 0))
5780 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5781 return TRUE; // do nothing
5783 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
5784 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
5785 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
5787 else if ((strcmp(arg, "TKIP") == 0) || (strcmp(arg, "tkip") == 0))
5789 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
5790 return TRUE; // do nothing
5792 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
5793 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
5794 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
5796 else if ((strcmp(arg, "AES") == 0) || (strcmp(arg, "aes") == 0))
5798 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
5799 return TRUE; // do nothing
5801 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
5802 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
5803 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
5808 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
5810 DBGPRINT(RT_DEBUG_TRACE, ("Set_EncrypType_Proc::(EncrypType=%d)\n", pAdapter->StaCfg.WepStatus));
5816 ==========================================================================
5820 TRUE if all parameters are OK, FALSE otherwise
5821 ==========================================================================
5823 INT Set_DefaultKeyID_Proc(
5824 IN PRTMP_ADAPTER pAdapter,
5829 KeyIdx = simple_strtol(arg, 0, 10);
5830 if((KeyIdx >= 1 ) && (KeyIdx <= 4))
5831 pAdapter->StaCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1 );
5833 return FALSE; //Invalid argument
5835 DBGPRINT(RT_DEBUG_TRACE, ("Set_DefaultKeyID_Proc::(DefaultKeyID=%d)\n", pAdapter->StaCfg.DefaultKeyId));
5841 ==========================================================================
5845 TRUE if all parameters are OK, FALSE otherwise
5846 ==========================================================================
5849 IN PRTMP_ADAPTER pAdapter,
5854 UCHAR CipherAlg=CIPHER_WEP64;
5856 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5857 return TRUE; // do nothing
5859 KeyLen = strlen(arg);
5863 case 5: //wep 40 Ascii type
5864 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
5865 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
5866 CipherAlg = CIPHER_WEP64;
5867 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
5869 case 10: //wep 40 Hex type
5870 for(i=0; i < KeyLen; i++)
5872 if( !isxdigit(*(arg+i)) )
5873 return FALSE; //Not Hex value;
5875 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
5876 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
5877 CipherAlg = CIPHER_WEP64;
5878 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
5880 case 13: //wep 104 Ascii type
5881 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
5882 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
5883 CipherAlg = CIPHER_WEP128;
5884 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
5886 case 26: //wep 104 Hex type
5887 for(i=0; i < KeyLen; i++)
5889 if( !isxdigit(*(arg+i)) )
5890 return FALSE; //Not Hex value;
5892 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
5893 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
5894 CipherAlg = CIPHER_WEP128;
5895 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
5897 default: //Invalid argument
5898 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::Invalid argument (=%s)\n", arg));
5902 pAdapter->SharedKey[BSS0][0].CipherAlg = CipherAlg;
5904 // Set keys (into ASIC)
5905 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5907 else // Old WEP stuff
5909 AsicAddSharedKeyEntry(pAdapter,
5912 pAdapter->SharedKey[BSS0][0].CipherAlg,
5913 pAdapter->SharedKey[BSS0][0].Key,
5921 ==========================================================================
5926 TRUE if all parameters are OK, FALSE otherwise
5927 ==========================================================================
5930 IN PRTMP_ADAPTER pAdapter,
5935 UCHAR CipherAlg=CIPHER_WEP64;
5937 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5938 return TRUE; // do nothing
5940 KeyLen = strlen(arg);
5944 case 5: //wep 40 Ascii type
5945 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
5946 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
5947 CipherAlg = CIPHER_WEP64;
5948 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
5950 case 10: //wep 40 Hex type
5951 for(i=0; i < KeyLen; i++)
5953 if( !isxdigit(*(arg+i)) )
5954 return FALSE; //Not Hex value;
5956 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
5957 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
5958 CipherAlg = CIPHER_WEP64;
5959 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
5961 case 13: //wep 104 Ascii type
5962 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
5963 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
5964 CipherAlg = CIPHER_WEP128;
5965 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
5967 case 26: //wep 104 Hex type
5968 for(i=0; i < KeyLen; i++)
5970 if( !isxdigit(*(arg+i)) )
5971 return FALSE; //Not Hex value;
5973 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
5974 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
5975 CipherAlg = CIPHER_WEP128;
5976 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
5978 default: //Invalid argument
5979 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::Invalid argument (=%s)\n", arg));
5982 pAdapter->SharedKey[BSS0][1].CipherAlg = CipherAlg;
5984 // Set keys (into ASIC)
5985 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5987 else // Old WEP stuff
5989 AsicAddSharedKeyEntry(pAdapter,
5992 pAdapter->SharedKey[BSS0][1].CipherAlg,
5993 pAdapter->SharedKey[BSS0][1].Key,
6001 ==========================================================================
6005 TRUE if all parameters are OK, FALSE otherwise
6006 ==========================================================================
6009 IN PRTMP_ADAPTER pAdapter,
6014 UCHAR CipherAlg=CIPHER_WEP64;
6016 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6017 return TRUE; // do nothing
6019 KeyLen = strlen(arg);
6023 case 5: //wep 40 Ascii type
6024 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
6025 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
6026 CipherAlg = CIPHER_WEP64;
6027 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
6029 case 10: //wep 40 Hex type
6030 for(i=0; i < KeyLen; i++)
6032 if( !isxdigit(*(arg+i)) )
6033 return FALSE; //Not Hex value;
6035 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
6036 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
6037 CipherAlg = CIPHER_WEP64;
6038 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
6040 case 13: //wep 104 Ascii type
6041 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
6042 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
6043 CipherAlg = CIPHER_WEP128;
6044 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
6046 case 26: //wep 104 Hex type
6047 for(i=0; i < KeyLen; i++)
6049 if( !isxdigit(*(arg+i)) )
6050 return FALSE; //Not Hex value;
6052 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
6053 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
6054 CipherAlg = CIPHER_WEP128;
6055 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
6057 default: //Invalid argument
6058 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::Invalid argument (=%s)\n", arg));
6061 pAdapter->SharedKey[BSS0][2].CipherAlg = CipherAlg;
6063 // Set keys (into ASIC)
6064 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6066 else // Old WEP stuff
6068 AsicAddSharedKeyEntry(pAdapter,
6071 pAdapter->SharedKey[BSS0][2].CipherAlg,
6072 pAdapter->SharedKey[BSS0][2].Key,
6080 ==========================================================================
6084 TRUE if all parameters are OK, FALSE otherwise
6085 ==========================================================================
6088 IN PRTMP_ADAPTER pAdapter,
6093 UCHAR CipherAlg=CIPHER_WEP64;
6095 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6096 return TRUE; // do nothing
6098 KeyLen = strlen(arg);
6102 case 5: //wep 40 Ascii type
6103 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
6104 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
6105 CipherAlg = CIPHER_WEP64;
6106 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
6108 case 10: //wep 40 Hex type
6109 for(i=0; i < KeyLen; i++)
6111 if( !isxdigit(*(arg+i)) )
6112 return FALSE; //Not Hex value;
6114 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
6115 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
6116 CipherAlg = CIPHER_WEP64;
6117 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
6119 case 13: //wep 104 Ascii type
6120 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
6121 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
6122 CipherAlg = CIPHER_WEP128;
6123 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
6125 case 26: //wep 104 Hex type
6126 for(i=0; i < KeyLen; i++)
6128 if( !isxdigit(*(arg+i)) )
6129 return FALSE; //Not Hex value;
6131 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
6132 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
6133 CipherAlg = CIPHER_WEP128;
6134 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
6136 default: //Invalid argument
6137 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::Invalid argument (=%s)\n", arg));
6140 pAdapter->SharedKey[BSS0][3].CipherAlg = CipherAlg;
6142 // Set keys (into ASIC)
6143 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6145 else // Old WEP stuff
6147 AsicAddSharedKeyEntry(pAdapter,
6150 pAdapter->SharedKey[BSS0][3].CipherAlg,
6151 pAdapter->SharedKey[BSS0][3].Key,
6160 ==========================================================================
6164 TRUE if all parameters are OK, FALSE otherwise
6165 ==========================================================================
6167 INT Set_WPAPSK_Proc(
6168 IN PRTMP_ADAPTER pAdapter,
6171 UCHAR keyMaterial[40];
6173 if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
6174 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
6175 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
6177 return TRUE; // do nothing
6179 DBGPRINT(RT_DEBUG_TRACE, ("Set_WPAPSK_Proc::(WPAPSK=%s)\n", arg));
6181 NdisZeroMemory(keyMaterial, 40);
6183 if ((strlen(arg) < 8) || (strlen(arg) > 64))
6185 DBGPRINT(RT_DEBUG_TRACE, ("Set failed!!(WPAPSK=%s), WPAPSK key-string required 8 ~ 64 characters \n", arg));
6189 if (strlen(arg) == 64)
6191 AtoH(arg, keyMaterial, 32);
6192 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
6197 PasswordHash((char *)arg, pAdapter->MlmeAux.Ssid, pAdapter->MlmeAux.SsidLen, keyMaterial);
6198 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
6203 if(pAdapter->StaCfg.BssType == BSS_ADHOC &&
6204 pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
6206 pAdapter->StaCfg.WpaState = SS_NOTUSE;
6210 // Start STA supplicant state machine
6211 pAdapter->StaCfg.WpaState = SS_START;
6218 ==========================================================================
6220 Set Power Saving mode
6222 TRUE if all parameters are OK, FALSE otherwise
6223 ==========================================================================
6225 INT Set_PSMode_Proc(
6226 IN PRTMP_ADAPTER pAdapter,
6229 if (pAdapter->StaCfg.BssType == BSS_INFRA)
6231 if ((strcmp(arg, "Max_PSP") == 0) ||
6232 (strcmp(arg, "max_psp") == 0) ||
6233 (strcmp(arg, "MAX_PSP") == 0))
6235 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6236 // to exclude certain situations.
6237 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6238 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeMAX_PSP;
6239 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeMAX_PSP;
6240 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6241 pAdapter->StaCfg.DefaultListenCount = 5;
6244 else if ((strcmp(arg, "Fast_PSP") == 0) ||
6245 (strcmp(arg, "fast_psp") == 0) ||
6246 (strcmp(arg, "FAST_PSP") == 0))
6248 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6249 // to exclude certain situations.
6250 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6251 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6252 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeFast_PSP;
6253 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeFast_PSP;
6254 pAdapter->StaCfg.DefaultListenCount = 3;
6256 else if ((strcmp(arg, "Legacy_PSP") == 0) ||
6257 (strcmp(arg, "legacy_psp") == 0) ||
6258 (strcmp(arg, "LEGACY_PSP") == 0))
6260 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6261 // to exclude certain situations.
6262 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6263 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6264 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeLegacy_PSP;
6265 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeLegacy_PSP;
6266 pAdapter->StaCfg.DefaultListenCount = 3;
6270 //Default Ndis802_11PowerModeCAM
6271 // clear PSM bit immediately
6272 MlmeSetPsmBit(pAdapter, PWR_ACTIVE);
6273 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6274 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6275 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
6276 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
6279 DBGPRINT(RT_DEBUG_TRACE, ("Set_PSMode_Proc::(PSMode=%ld)\n", pAdapter->StaCfg.WindowsPowerMode));
6288 #ifdef WPA_SUPPLICANT_SUPPORT
6290 ==========================================================================
6292 Set WpaSupport flag.
6294 0: Driver ignore wpa_supplicant.
6295 1: wpa_supplicant initiates scanning and AP selection.
6296 2: driver takes care of scanning, AP selection, and IEEE 802.11 association parameters.
6298 TRUE if all parameters are OK, FALSE otherwise
6299 ==========================================================================
6301 INT Set_Wpa_Support(
6302 IN PRTMP_ADAPTER pAd,
6306 if ( simple_strtol(arg, 0, 10) == 0)
6307 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
6308 else if ( simple_strtol(arg, 0, 10) == 1)
6309 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE;
6310 else if ( simple_strtol(arg, 0, 10) == 2)
6311 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE_WITH_WEB_UI;
6313 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
6315 DBGPRINT(RT_DEBUG_TRACE, ("Set_Wpa_Support::(WpaSupplicantUP=%d)\n", pAd->StaCfg.WpaSupplicantUP));
6319 #endif // WPA_SUPPLICANT_SUPPORT //
6323 ==========================================================================
6327 pAdapter Pointer to our adapter
6328 wrq Pointer to the ioctl argument
6335 1.) iwpriv ra0 mac 0 ==> read MAC where Addr=0x0
6336 2.) iwpriv ra0 mac 0=12 ==> write MAC where Addr=0x0, value=12
6337 ==========================================================================
6340 IN PRTMP_ADAPTER pAdapter,
6341 IN struct iwreq *wrq)
6349 UCHAR temp[16], temp2[16];
6350 UINT32 macValue = 0;
6354 memset(msg, 0x00, 1024);
6355 if (wrq->u.data.length > 1) //No parameters.
6357 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6360 //Parsing Read or Write
6365 if ((value = rtstrchr(this_char, '=')) != NULL)
6368 if (!value || !*value)
6371 if(strlen(this_char) > 4)
6374 j = strlen(this_char);
6377 if(this_char[j] > 'f' || this_char[j] < '0')
6382 k = j = strlen(this_char);
6385 this_char[4-k+j] = this_char[j];
6389 this_char[3-k++]='0';
6392 if(strlen(this_char) == 4)
6394 AtoH(this_char, temp, 2);
6395 macAddr = *temp*256 + temp[1];
6396 if (macAddr < 0xFFFF)
6398 RTMP_IO_READ32(pAdapter, macAddr, &macValue);
6399 DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%lx, MacValue=%x\n", macAddr, macValue));
6400 sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr , macValue);
6403 {//Invalid parametes, so default printk all bbp
6410 memcpy(&temp2, value, strlen(value));
6411 temp2[strlen(value)] = '\0';
6414 if((strlen(this_char) > 4) || strlen(temp2) > 8)
6417 j = strlen(this_char);
6420 if(this_char[j] > 'f' || this_char[j] < '0')
6427 if(temp2[j] > 'f' || temp2[j] < '0')
6432 k = j = strlen(this_char);
6435 this_char[4-k+j] = this_char[j];
6439 this_char[3-k++]='0';
6443 k = j = strlen(temp2);
6446 temp2[8-k+j] = temp2[j];
6454 AtoH(this_char, temp, 2);
6455 macAddr = *temp*256 + temp[1];
6457 AtoH(temp2, temp, 4);
6458 macValue = *temp*256*256*256 + temp[1]*256*256 + temp[2]*256 + temp[3];
6461 if (macAddr == (HW_DEBUG_SETTING_BASE + 4))
6463 // 0x2bf4: byte0 non-zero: enable R17 tuning, 0: disable R17 tuning
6464 if (macValue & 0x000000ff)
6466 pAdapter->BbpTuning.bEnable = TRUE;
6467 DBGPRINT(RT_DEBUG_TRACE,("turn on R17 tuning\n"));
6472 pAdapter->BbpTuning.bEnable = FALSE;
6473 R66 = 0x26 + GET_LNA_GAIN(pAdapter);
6474 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R66, (0x26 + GET_LNA_GAIN(pAdapter)));
6475 DBGPRINT(RT_DEBUG_TRACE,("turn off R17 tuning, restore to 0x%02x\n", R66));
6480 DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%02lx, MacValue=0x%x\n", macAddr, macValue));
6482 RTMP_IO_WRITE32(pAdapter, macAddr, macValue);
6483 sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr, macValue);
6488 if(strlen(msg) == 1)
6489 sprintf(msg+strlen(msg), "===>Error command format!");
6491 // Copy the information into the user buffer
6492 wrq->u.data.length = strlen(msg);
6493 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6495 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlMAC\n\n"));
6499 ==========================================================================
6503 pAdapter Pointer to our adapter
6504 wrq Pointer to the ioctl argument
6511 1.) iwpriv ra0 e2p 0 ==> read E2PROM where Addr=0x0
6512 2.) iwpriv ra0 e2p 0=1234 ==> write E2PROM where Addr=0x0, value=1234
6513 ==========================================================================
6515 VOID RTMPIoctlE2PROM(
6516 IN PRTMP_ADAPTER pAdapter,
6517 IN struct iwreq *wrq)
6525 UCHAR temp[16], temp2[16];
6530 memset(msg, 0x00, 1024);
6531 if (wrq->u.data.length > 1) //No parameters.
6533 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6536 //Parsing Read or Write
6543 if ((value = rtstrchr(this_char, '=')) != NULL)
6546 if (!value || !*value)
6550 if(strlen(this_char) > 4)
6553 j = strlen(this_char);
6556 if(this_char[j] > 'f' || this_char[j] < '0')
6561 k = j = strlen(this_char);
6564 this_char[4-k+j] = this_char[j];
6568 this_char[3-k++]='0';
6571 if(strlen(this_char) == 4)
6573 AtoH(this_char, temp, 2);
6574 eepAddr = *temp*256 + temp[1];
6575 if (eepAddr < 0xFFFF)
6577 RT28xx_EEPROM_READ16(pAdapter, eepAddr, eepValue);
6578 sprintf(msg+strlen(msg), "[0x%04X]:0x%04X ", eepAddr , eepValue);
6581 {//Invalid parametes, so default printk all bbp
6588 memcpy(&temp2, value, strlen(value));
6589 temp2[strlen(value)] = '\0';
6592 if((strlen(this_char) > 4) || strlen(temp2) > 8)
6595 j = strlen(this_char);
6598 if(this_char[j] > 'f' || this_char[j] < '0')
6604 if(temp2[j] > 'f' || temp2[j] < '0')
6609 k = j = strlen(this_char);
6612 this_char[4-k+j] = this_char[j];
6616 this_char[3-k++]='0';
6620 k = j = strlen(temp2);
6623 temp2[4-k+j] = temp2[j];
6630 AtoH(this_char, temp, 2);
6631 eepAddr = *temp*256 + temp[1];
6633 AtoH(temp2, temp, 2);
6634 eepValue = *temp*256 + temp[1];
6636 RT28xx_EEPROM_WRITE16(pAdapter, eepAddr, eepValue);
6637 sprintf(msg+strlen(msg), "[0x%02X]:%02X ", eepAddr, eepValue);
6641 if(strlen(msg) == 1)
6642 sprintf(msg+strlen(msg), "===>Error command format!");
6645 // Copy the information into the user buffer
6646 wrq->u.data.length = strlen(msg);
6647 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6649 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlE2PROM\n"));
6656 INT Set_TGnWifiTest_Proc(
6657 IN PRTMP_ADAPTER pAd,
6660 if (simple_strtol(arg, 0, 10) == 0)
6661 pAd->StaCfg.bTGnWifiTest = FALSE;
6663 pAd->StaCfg.bTGnWifiTest = TRUE;
6665 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_TGnWifiTest_Proc::(bTGnWifiTest=%d)\n", pAd->StaCfg.bTGnWifiTest));
6669 INT Set_LongRetryLimit_Proc(
6670 IN PRTMP_ADAPTER pAdapter,
6673 TX_RTY_CFG_STRUC tx_rty_cfg;
6674 UCHAR LongRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
6676 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
6677 tx_rty_cfg.field.LongRtyLimit = LongRetryLimit;
6678 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
6679 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_LongRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
6683 INT Set_ShortRetryLimit_Proc(
6684 IN PRTMP_ADAPTER pAdapter,
6687 TX_RTY_CFG_STRUC tx_rty_cfg;
6688 UCHAR ShortRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
6690 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
6691 tx_rty_cfg.field.ShortRtyLimit = ShortRetryLimit;
6692 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
6693 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_ShortRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
6697 INT Show_Adhoc_MacTable_Proc(
6698 IN PRTMP_ADAPTER pAd,
6703 sprintf(extra, "\n");
6705 #ifdef DOT11_N_SUPPORT
6706 sprintf(extra + strlen(extra), "HT Operating Mode : %d\n", pAd->CommonCfg.AddHTInfo.AddHtInfo2.OperaionMode);
6707 #endif // DOT11_N_SUPPORT //
6709 sprintf(extra + strlen(extra), "\n%-19s%-4s%-4s%-7s%-7s%-7s%-10s%-6s%-6s%-6s%-6s\n",
6710 "MAC", "AID", "BSS", "RSSI0", "RSSI1", "RSSI2", "PhMd", "BW", "MCS", "SGI", "STBC");
6712 for (i=1; i<MAX_LEN_OF_MAC_TABLE; i++)
6714 PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
6716 if (strlen(extra) > (IW_PRIV_SIZE_MASK - 30))
6718 if ((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
6720 sprintf(extra + strlen(extra), "%02X:%02X:%02X:%02X:%02X:%02X ",
6721 pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
6722 pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5]);
6723 sprintf(extra + strlen(extra), "%-4d", (int)pEntry->Aid);
6724 sprintf(extra + strlen(extra), "%-4d", (int)pEntry->apidx);
6725 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi0);
6726 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi1);
6727 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi2);
6728 sprintf(extra + strlen(extra), "%-10s", GetPhyMode(pEntry->HTPhyMode.field.MODE));
6729 sprintf(extra + strlen(extra), "%-6s", GetBW(pEntry->HTPhyMode.field.BW));
6730 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.MCS);
6731 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.ShortGI);
6732 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.STBC);
6733 sprintf(extra + strlen(extra), "%-10d, %d, %d%%\n", pEntry->DebugFIFOCount, pEntry->DebugTxCount,
6734 (pEntry->DebugTxCount) ? ((pEntry->DebugTxCount-pEntry->DebugFIFOCount)*100/pEntry->DebugTxCount) : 0);
6735 sprintf(extra, "%s\n", extra);