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 //
3152 #ifdef DOT11_N_SUPPORT
3153 MaxPhyMode = PHY_11N_5G;
3154 #endif // DOT11_N_SUPPORT //
3157 DBGPRINT(RT_DEBUG_TRACE, ("-->RTMPSetInformation(), 0x%08x\n", cmd&0x7FFF));
3158 switch(cmd & 0x7FFF) {
3159 case RT_OID_802_11_COUNTRY_REGION:
3160 if (wrq->u.data.length < sizeof(UCHAR))
3162 // Only avaliable when EEPROM not programming
3163 else if (!(pAdapter->CommonCfg.CountryRegion & 0x80) && !(pAdapter->CommonCfg.CountryRegionForABand & 0x80))
3168 Status = copy_from_user(&Country, wrq->u.data.pointer, wrq->u.data.length);
3169 pAdapter->CommonCfg.CountryRegion = (UCHAR)(Country & 0x000000FF);
3170 pAdapter->CommonCfg.CountryRegionForABand = (UCHAR)((Country >> 8) & 0x000000FF);
3171 TmpPhy = pAdapter->CommonCfg.PhyMode;
3172 pAdapter->CommonCfg.PhyMode = 0xff;
3173 // Build all corresponding channel information
3174 RTMPSetPhyMode(pAdapter, TmpPhy);
3175 #ifdef DOT11_N_SUPPORT
3176 SetCommonHT(pAdapter);
3177 #endif // DOT11_N_SUPPORT //
3178 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_COUNTRY_REGION (A:%d B/G:%d)\n", pAdapter->CommonCfg.CountryRegionForABand,
3179 pAdapter->CommonCfg.CountryRegion));
3182 case OID_802_11_BSSID_LIST_SCAN:
3184 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID_LIST_SCAN, TxCnt = %d \n", pAdapter->RalinkCounters.LastOneSecTotalTxCount));
3186 if (MONITOR_ON(pAdapter))
3188 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
3192 //Benson add 20080527, when radio off, sta don't need to scan
3193 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_RADIO_OFF))
3196 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
3198 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is scanning now !!!\n"));
3199 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
3200 Status = NDIS_STATUS_SUCCESS;
3204 if (pAdapter->RalinkCounters.LastOneSecTotalTxCount > 100)
3206 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
3207 Status = NDIS_STATUS_SUCCESS;
3208 pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
3212 if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
3213 ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
3214 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
3215 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
3216 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)) &&
3217 (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
3219 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
3220 Status = NDIS_STATUS_SUCCESS;
3221 pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
3226 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3228 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3229 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3232 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
3233 // this request, because this request is initiated by NDIS.
3234 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
3235 // Reset allowed scan retries
3236 pAdapter->StaCfg.ScanCnt = 0;
3237 pAdapter->StaCfg.LastScanTime = Now;
3239 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
3240 RTMP_SET_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
3241 MlmeEnqueue(pAdapter,
3242 MLME_CNTL_STATE_MACHINE,
3243 OID_802_11_BSSID_LIST_SCAN,
3247 Status = NDIS_STATUS_SUCCESS;
3248 StateMachineTouched = TRUE;
3250 case OID_802_11_SSID:
3251 if (wrq->u.data.length != sizeof(NDIS_802_11_SSID))
3255 PCHAR pSsidString = NULL;
3256 Status = copy_from_user(&Ssid, wrq->u.data.pointer, wrq->u.data.length);
3258 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SSID (Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
3259 if (Ssid.SsidLength > MAX_LEN_OF_SSID)
3263 if (Ssid.SsidLength == 0)
3265 Set_SSID_Proc(pAdapter, "");
3269 pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
3272 NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
3273 NdisMoveMemory(pSsidString, Ssid.Ssid, Ssid.SsidLength);
3274 Set_SSID_Proc(pAdapter, pSsidString);
3283 case OID_802_11_BSSID:
3284 if (wrq->u.data.length != sizeof(NDIS_802_11_MAC_ADDRESS))
3288 Status = copy_from_user(&Bssid, wrq->u.data.pointer, wrq->u.data.length);
3290 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
3291 // this request, because this request is initiated by NDIS.
3292 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
3294 // Prevent to connect AP again in STAMlmePeriodicExec
3295 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
3297 // Reset allowed scan retries
3298 pAdapter->StaCfg.ScanCnt = 0;
3300 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3302 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3303 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3305 MlmeEnqueue(pAdapter,
3306 MLME_CNTL_STATE_MACHINE,
3308 sizeof(NDIS_802_11_MAC_ADDRESS),
3310 Status = NDIS_STATUS_SUCCESS;
3311 StateMachineTouched = TRUE;
3313 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID %02x:%02x:%02x:%02x:%02x:%02x\n",
3314 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
3317 case RT_OID_802_11_RADIO:
3318 if (wrq->u.data.length != sizeof(BOOLEAN))
3322 Status = copy_from_user(&RadioState, wrq->u.data.pointer, wrq->u.data.length);
3323 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RADIO (=%d)\n", RadioState));
3324 if (pAdapter->StaCfg.bSwRadio != RadioState)
3326 pAdapter->StaCfg.bSwRadio = RadioState;
3327 if (pAdapter->StaCfg.bRadio != (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio))
3329 pAdapter->StaCfg.bRadio = (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio);
3330 if (pAdapter->StaCfg.bRadio == TRUE)
3332 MlmeRadioOn(pAdapter);
3333 // Update extra information
3334 pAdapter->ExtraInfo = EXTRA_INFO_CLEAR;
3338 MlmeRadioOff(pAdapter);
3339 // Update extra information
3340 pAdapter->ExtraInfo = SW_RADIO_OFF;
3346 case RT_OID_802_11_PHY_MODE:
3347 if (wrq->u.data.length != sizeof(RT_802_11_PHY_MODE))
3351 Status = copy_from_user(&PhyMode, wrq->u.data.pointer, wrq->u.data.length);
3352 if (PhyMode <= MaxPhyMode)
3354 RTMPSetPhyMode(pAdapter, PhyMode);
3355 #ifdef DOT11_N_SUPPORT
3356 SetCommonHT(pAdapter);
3357 #endif // DOT11_N_SUPPORT //
3359 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PHY_MODE (=%d)\n", PhyMode));
3362 case RT_OID_802_11_STA_CONFIG:
3363 if (wrq->u.data.length != sizeof(RT_802_11_STA_CONFIG))
3367 Status = copy_from_user(&StaConfig, wrq->u.data.pointer, wrq->u.data.length);
3368 pAdapter->CommonCfg.bEnableTxBurst = StaConfig.EnableTxBurst;
3369 pAdapter->CommonCfg.UseBGProtection = StaConfig.UseBGProtection;
3370 pAdapter->CommonCfg.bUseShortSlotTime = 1; // 2003-10-30 always SHORT SLOT capable
3371 if ((pAdapter->CommonCfg.PhyMode != StaConfig.AdhocMode) &&
3372 (StaConfig.AdhocMode <= MaxPhyMode))
3374 // allow dynamic change of "USE OFDM rate or not" in ADHOC mode
3375 // if setting changed, need to reset current TX rate as well as BEACON frame format
3376 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
3378 pAdapter->CommonCfg.PhyMode = StaConfig.AdhocMode;
3379 RTMPSetPhyMode(pAdapter, PhyMode);
3380 MlmeUpdateTxRates(pAdapter, FALSE, 0);
3381 MakeIbssBeacon(pAdapter); // re-build BEACON frame
3382 AsicEnableIbssSync(pAdapter); // copy to on-chip memory
3385 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_STA_CONFIG (Burst=%d, Protection=%ld,ShortSlot=%d\n",
3386 pAdapter->CommonCfg.bEnableTxBurst,
3387 pAdapter->CommonCfg.UseBGProtection,
3388 pAdapter->CommonCfg.bUseShortSlotTime));
3391 case OID_802_11_DESIRED_RATES:
3392 if (wrq->u.data.length != sizeof(NDIS_802_11_RATES))
3396 Status = copy_from_user(&aryRates, wrq->u.data.pointer, wrq->u.data.length);
3397 NdisZeroMemory(pAdapter->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES);
3398 NdisMoveMemory(pAdapter->CommonCfg.DesireRate, &aryRates, sizeof(NDIS_802_11_RATES));
3399 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DESIRED_RATES (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
3400 pAdapter->CommonCfg.DesireRate[0],pAdapter->CommonCfg.DesireRate[1],
3401 pAdapter->CommonCfg.DesireRate[2],pAdapter->CommonCfg.DesireRate[3],
3402 pAdapter->CommonCfg.DesireRate[4],pAdapter->CommonCfg.DesireRate[5],
3403 pAdapter->CommonCfg.DesireRate[6],pAdapter->CommonCfg.DesireRate[7] ));
3404 // Changing DesiredRate may affect the MAX TX rate we used to TX frames out
3405 MlmeUpdateTxRates(pAdapter, FALSE, 0);
3408 case RT_OID_802_11_PREAMBLE:
3409 if (wrq->u.data.length != sizeof(RT_802_11_PREAMBLE))
3413 Status = copy_from_user(&Preamble, wrq->u.data.pointer, wrq->u.data.length);
3414 if (Preamble == Rt802_11PreambleShort)
3416 pAdapter->CommonCfg.TxPreamble = Preamble;
3417 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleShort);
3419 else if ((Preamble == Rt802_11PreambleLong) || (Preamble == Rt802_11PreambleAuto))
3421 // if user wants AUTO, initialize to LONG here, then change according to AP's
3422 // capability upon association.
3423 pAdapter->CommonCfg.TxPreamble = Preamble;
3424 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleLong);
3431 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PREAMBLE (=%d)\n", Preamble));
3434 case OID_802_11_WEP_STATUS:
3435 if (wrq->u.data.length != sizeof(NDIS_802_11_WEP_STATUS))
3439 Status = copy_from_user(&WepStatus, wrq->u.data.pointer, wrq->u.data.length);
3440 // Since TKIP, AES, WEP are all supported. It should not have any invalid setting
3441 if (WepStatus <= Ndis802_11Encryption3KeyAbsent)
3443 if (pAdapter->StaCfg.WepStatus != WepStatus)
3445 // Config has changed
3446 pAdapter->bConfigChanged = TRUE;
3448 pAdapter->StaCfg.WepStatus = WepStatus;
3449 pAdapter->StaCfg.OrigWepStatus = WepStatus;
3450 pAdapter->StaCfg.PairCipher = WepStatus;
3451 pAdapter->StaCfg.GroupCipher = WepStatus;
3458 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEP_STATUS (=%d)\n",WepStatus));
3461 case OID_802_11_AUTHENTICATION_MODE:
3462 if (wrq->u.data.length != sizeof(NDIS_802_11_AUTHENTICATION_MODE))
3466 Status = copy_from_user(&AuthMode, wrq->u.data.pointer, wrq->u.data.length);
3467 if (AuthMode > Ndis802_11AuthModeMax)
3474 if (pAdapter->StaCfg.AuthMode != AuthMode)
3476 // Config has changed
3477 pAdapter->bConfigChanged = TRUE;
3479 pAdapter->StaCfg.AuthMode = AuthMode;
3481 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
3482 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_AUTHENTICATION_MODE (=%d) \n",pAdapter->StaCfg.AuthMode));
3485 case OID_802_11_INFRASTRUCTURE_MODE:
3486 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_INFRASTRUCTURE))
3490 Status = copy_from_user(&BssType, wrq->u.data.pointer, wrq->u.data.length);
3492 if (BssType == Ndis802_11IBSS)
3493 Set_NetworkType_Proc(pAdapter, "Adhoc");
3494 else if (BssType == Ndis802_11Infrastructure)
3495 Set_NetworkType_Proc(pAdapter, "Infra");
3496 else if (BssType == Ndis802_11Monitor)
3497 Set_NetworkType_Proc(pAdapter, "Monitor");
3501 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_INFRASTRUCTURE_MODE (unknown)\n"));
3505 case OID_802_11_REMOVE_WEP:
3506 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_WEP\n"));
3507 if (wrq->u.data.length != sizeof(NDIS_802_11_KEY_INDEX))
3513 KeyIdx = *(NDIS_802_11_KEY_INDEX *) wrq->u.data.pointer;
3515 if (KeyIdx & 0x80000000)
3517 // Should never set default bit when remove key
3522 KeyIdx = KeyIdx & 0x0fffffff;
3528 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
3529 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
3530 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
3535 case RT_OID_802_11_RESET_COUNTERS:
3536 NdisZeroMemory(&pAdapter->WlanCounters, sizeof(COUNTER_802_11));
3537 NdisZeroMemory(&pAdapter->Counters8023, sizeof(COUNTER_802_3));
3538 NdisZeroMemory(&pAdapter->RalinkCounters, sizeof(COUNTER_RALINK));
3539 pAdapter->Counters8023.RxNoBuffer = 0;
3540 pAdapter->Counters8023.GoodReceives = 0;
3541 pAdapter->Counters8023.RxNoBuffer = 0;
3543 pAdapter->BulkOutComplete = 0;
3544 pAdapter->BulkOutCompleteOther= 0;
3545 pAdapter->BulkOutCompleteCancel = 0;
3546 pAdapter->BulkOutReq = 0;
3547 pAdapter->BulkInReq= 0;
3548 pAdapter->BulkInComplete = 0;
3549 pAdapter->BulkInCompleteFail = 0;
3551 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RESET_COUNTERS \n"));
3553 case OID_802_11_RTS_THRESHOLD:
3554 if (wrq->u.data.length != sizeof(NDIS_802_11_RTS_THRESHOLD))
3558 Status = copy_from_user(&RtsThresh, wrq->u.data.pointer, wrq->u.data.length);
3559 if (RtsThresh > MAX_RTS_THRESHOLD)
3562 pAdapter->CommonCfg.RtsThreshold = (USHORT)RtsThresh;
3564 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_RTS_THRESHOLD (=%ld)\n",RtsThresh));
3566 case OID_802_11_FRAGMENTATION_THRESHOLD:
3567 if (wrq->u.data.length != sizeof(NDIS_802_11_FRAGMENTATION_THRESHOLD))
3571 Status = copy_from_user(&FragThresh, wrq->u.data.pointer, wrq->u.data.length);
3572 pAdapter->CommonCfg.bUseZeroToDisableFragment = FALSE;
3573 if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
3575 if (FragThresh == 0)
3577 pAdapter->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
3578 pAdapter->CommonCfg.bUseZeroToDisableFragment = TRUE;
3584 pAdapter->CommonCfg.FragmentThreshold = (USHORT)FragThresh;
3586 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_FRAGMENTATION_THRESHOLD (=%ld) \n",FragThresh));
3588 case OID_802_11_POWER_MODE:
3589 if (wrq->u.data.length != sizeof(NDIS_802_11_POWER_MODE))
3593 Status = copy_from_user(&PowerMode, wrq->u.data.pointer, wrq->u.data.length);
3594 if (PowerMode == Ndis802_11PowerModeCAM)
3595 Set_PSMode_Proc(pAdapter, "CAM");
3596 else if (PowerMode == Ndis802_11PowerModeMAX_PSP)
3597 Set_PSMode_Proc(pAdapter, "Max_PSP");
3598 else if (PowerMode == Ndis802_11PowerModeFast_PSP)
3599 Set_PSMode_Proc(pAdapter, "Fast_PSP");
3600 else if (PowerMode == Ndis802_11PowerModeLegacy_PSP)
3601 Set_PSMode_Proc(pAdapter, "Legacy_PSP");
3605 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_POWER_MODE (=%d)\n",PowerMode));
3607 case RT_OID_802_11_TX_POWER_LEVEL_1:
3608 if (wrq->u.data.length < sizeof(ULONG))
3612 Status = copy_from_user(&PowerTemp, wrq->u.data.pointer, wrq->u.data.length);
3613 if (PowerTemp > 100)
3614 PowerTemp = 0xffffffff; // AUTO
3615 pAdapter->CommonCfg.TxPowerDefault = PowerTemp; //keep current setting.
3616 pAdapter->CommonCfg.TxPowerPercentage = pAdapter->CommonCfg.TxPowerDefault;
3617 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
3620 case OID_802_11_NETWORK_TYPE_IN_USE:
3621 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_TYPE))
3625 Status = copy_from_user(&NetType, wrq->u.data.pointer, wrq->u.data.length);
3627 if (NetType == Ndis802_11DS)
3628 RTMPSetPhyMode(pAdapter, PHY_11B);
3629 else if (NetType == Ndis802_11OFDM24)
3630 RTMPSetPhyMode(pAdapter, PHY_11BG_MIXED);
3631 else if (NetType == Ndis802_11OFDM5)
3632 RTMPSetPhyMode(pAdapter, PHY_11A);
3635 #ifdef DOT11_N_SUPPORT
3636 if (Status == NDIS_STATUS_SUCCESS)
3637 SetCommonHT(pAdapter);
3638 #endif // DOT11_N_SUPPORT //
3639 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_NETWORK_TYPE_IN_USE (=%d)\n",NetType));
3642 // For WPA PSK PMK key
3643 case RT_OID_802_11_ADD_WPA:
3644 pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3651 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
3652 if (pKey->Length != wrq->u.data.length)
3655 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!!\n"));
3659 if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
3660 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
3661 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone) )
3663 Status = -EOPNOTSUPP;
3664 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!! [AuthMode != WPAPSK/WPA2PSK/WPANONE]\n"));
3666 else if ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
3667 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
3668 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) ) // Only for WPA PSK mode
3670 NdisMoveMemory(pAdapter->StaCfg.PMK, &pKey->KeyMaterial, pKey->KeyLength);
3671 // Use RaConfig as PSK agent.
3672 // Start STA supplicant state machine
3673 if (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
3674 pAdapter->StaCfg.WpaState = SS_START;
3676 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3680 pAdapter->StaCfg.WpaState = SS_NOTUSE;
3681 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3686 case OID_802_11_REMOVE_KEY:
3687 pRemoveKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3688 if(pRemoveKey == NULL)
3694 Status = copy_from_user(pRemoveKey, wrq->u.data.pointer, wrq->u.data.length);
3695 if (pRemoveKey->Length != wrq->u.data.length)
3698 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!\n"));
3702 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3704 RTMPWPARemoveKeyProc(pAdapter, pRemoveKey);
3705 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Remove WPA Key!!\n"));
3709 KeyIdx = pRemoveKey->KeyIndex;
3711 if (KeyIdx & 0x80000000)
3713 // Should never set default bit when remove key
3715 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(Should never set default bit when remove key)\n"));
3719 KeyIdx = KeyIdx & 0x0fffffff;
3723 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(KeyId[%d] out of range)\n", KeyIdx));
3727 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
3728 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
3729 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
3730 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY (id=0x%x, Len=%d-byte)\n", pRemoveKey->KeyIndex, pRemoveKey->Length));
3738 case OID_802_11_ADD_KEY:
3739 pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3745 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
3746 if (pKey->Length != wrq->u.data.length)
3749 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY, Failed!!\n"));
3753 RTMPAddKey(pAdapter, pKey);
3754 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3758 case OID_802_11_CONFIGURATION:
3759 if (wrq->u.data.length != sizeof(NDIS_802_11_CONFIGURATION))
3763 Status = copy_from_user(&Config, wrq->u.data.pointer, wrq->u.data.length);
3766 if ((pConfig->BeaconPeriod >= 20) && (pConfig->BeaconPeriod <=400))
3767 pAdapter->CommonCfg.BeaconPeriod = (USHORT) pConfig->BeaconPeriod;
3769 pAdapter->StaActive.AtimWin = (USHORT) pConfig->ATIMWindow;
3770 MAP_KHZ_TO_CHANNEL_ID(pConfig->DSConfig, pAdapter->CommonCfg.Channel);
3772 // Save the channel on MlmeAux for CntlOidRTBssidProc used.
3774 pAdapter->MlmeAux.Channel = pAdapter->CommonCfg.Channel;
3776 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_CONFIGURATION (BeacnPeriod=%ld,AtimW=%ld,Ch=%d)\n",
3777 pConfig->BeaconPeriod, pConfig->ATIMWindow, pAdapter->CommonCfg.Channel));
3778 // Config has changed
3779 pAdapter->bConfigChanged = TRUE;
3782 #ifdef DOT11_N_SUPPORT
3783 case RT_OID_802_11_SET_HT_PHYMODE:
3784 if (wrq->u.data.length != sizeof(OID_SET_HT_PHYMODE))
3788 POID_SET_HT_PHYMODE pHTPhyMode = &HT_PhyMode;
3790 Status = copy_from_user(&HT_PhyMode, wrq->u.data.pointer, wrq->u.data.length);
3791 DBGPRINT(RT_DEBUG_TRACE, ("Set::pHTPhyMode (PhyMode = %d,TransmitNo = %d, HtMode = %d, ExtOffset = %d , MCS = %d, BW = %d, STBC = %d, SHORTGI = %d) \n",
3792 pHTPhyMode->PhyMode, pHTPhyMode->TransmitNo,pHTPhyMode->HtMode,pHTPhyMode->ExtOffset,
3793 pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->SHORTGI));
3794 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
3795 RTMPSetHT(pAdapter, pHTPhyMode);
3797 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_HT_PHYMODE(MCS=%d,BW=%d,SGI=%d,STBC=%d)\n",
3798 pAdapter->StaCfg.HTPhyMode.field.MCS, pAdapter->StaCfg.HTPhyMode.field.BW, pAdapter->StaCfg.HTPhyMode.field.ShortGI,
3799 pAdapter->StaCfg.HTPhyMode.field.STBC));
3801 #endif // DOT11_N_SUPPORT //
3802 case RT_OID_802_11_SET_APSD_SETTING:
3803 if (wrq->u.data.length != sizeof(ULONG))
3808 Status = copy_from_user(&apsd, wrq->u.data.pointer, wrq->u.data.length);
3810 /*-------------------------------------------------------------------
3811 |B31~B7 | B6~B5 | B4 | B3 | B2 | B1 | B0 |
3812 ---------------------------------------------------------------------
3813 | Rsvd | Max SP Len | AC_VO | AC_VI | AC_BK | AC_BE | APSD Capable |
3814 ---------------------------------------------------------------------*/
3815 pAdapter->CommonCfg.bAPSDCapable = (apsd & 0x00000001) ? TRUE : FALSE;
3816 pAdapter->CommonCfg.bAPSDAC_BE = ((apsd & 0x00000002) >> 1) ? TRUE : FALSE;
3817 pAdapter->CommonCfg.bAPSDAC_BK = ((apsd & 0x00000004) >> 2) ? TRUE : FALSE;
3818 pAdapter->CommonCfg.bAPSDAC_VI = ((apsd & 0x00000008) >> 3) ? TRUE : FALSE;
3819 pAdapter->CommonCfg.bAPSDAC_VO = ((apsd & 0x00000010) >> 4) ? TRUE : FALSE;
3820 pAdapter->CommonCfg.MaxSPLength = (UCHAR)((apsd & 0x00000060) >> 5);
3822 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,
3823 pAdapter->CommonCfg.bAPSDAC_BE, pAdapter->CommonCfg.bAPSDAC_BK, pAdapter->CommonCfg.bAPSDAC_VI, pAdapter->CommonCfg.bAPSDAC_VO, pAdapter->CommonCfg.MaxSPLength));
3827 case RT_OID_802_11_SET_APSD_PSM:
3828 if (wrq->u.data.length != sizeof(ULONG))
3832 // Driver needs to notify AP when PSM changes
3833 Status = copy_from_user(&pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.pointer, wrq->u.data.length);
3834 if (pAdapter->CommonCfg.bAPSDForcePowerSave != pAdapter->StaCfg.Psm)
3836 MlmeSetPsmBit(pAdapter, pAdapter->CommonCfg.bAPSDForcePowerSave);
3837 RTMPSendNullFrame(pAdapter, pAdapter->CommonCfg.TxRate, TRUE);
3839 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_APSD_PSM (bAPSDForcePowerSave:%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
3843 case RT_OID_802_11_SET_WMM:
3844 if (wrq->u.data.length != sizeof(BOOLEAN))
3848 Status = copy_from_user(&pAdapter->CommonCfg.bWmmCapable, wrq->u.data.pointer, wrq->u.data.length);
3849 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_WMM (=%d) \n", pAdapter->CommonCfg.bWmmCapable));
3853 case OID_802_11_DISASSOCIATE:
3855 // Set NdisRadioStateOff to TRUE, instead of called MlmeRadioOff.
3856 // Later on, NDIS_802_11_BSSID_LIST_EX->NumberOfItems should be 0
3857 // when query OID_802_11_BSSID_LIST.
3859 // TRUE: NumberOfItems will set to 0.
3860 // FALSE: NumberOfItems no change.
3862 pAdapter->CommonCfg.NdisRadioStateOff = TRUE;
3863 // Set to immediately send the media disconnect event
3864 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
3865 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DISASSOCIATE \n"));
3867 if (INFRA_ON(pAdapter))
3869 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3871 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3872 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3875 MlmeEnqueue(pAdapter,
3876 MLME_CNTL_STATE_MACHINE,
3877 OID_802_11_DISASSOCIATE,
3881 StateMachineTouched = TRUE;
3885 #ifdef DOT11_N_SUPPORT
3886 case RT_OID_802_11_SET_IMME_BA_CAP:
3887 if (wrq->u.data.length != sizeof(OID_BACAP_STRUC))
3891 OID_BACAP_STRUC Orde ;
3892 Status = copy_from_user(&Orde, wrq->u.data.pointer, wrq->u.data.length);
3893 if (Orde.Policy > BA_NOTUSE)
3895 Status = NDIS_STATUS_INVALID_DATA;
3897 else if (Orde.Policy == BA_NOTUSE)
3899 pAdapter->CommonCfg.BACapability.field.Policy = BA_NOTUSE;
3900 pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
3901 pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
3902 pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
3903 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
3904 pAdapter->CommonCfg.DesiredHtPhy.MimoPs= Orde.MMPSmode;
3905 pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
3907 pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
3908 pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
3909 pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
3913 pAdapter->CommonCfg.BACapability.field.AutoBA = Orde.AutoBA;
3914 pAdapter->CommonCfg.BACapability.field.Policy = IMMED_BA; // we only support immediate BA.
3915 pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
3916 pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
3917 pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
3918 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
3919 pAdapter->CommonCfg.DesiredHtPhy.MimoPs = Orde.MMPSmode;
3920 pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
3923 pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
3924 pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
3925 pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
3927 if (pAdapter->CommonCfg.BACapability.field.RxBAWinLimit > MAX_RX_REORDERBUF)
3928 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = MAX_RX_REORDERBUF;
3932 pAdapter->CommonCfg.REGBACapability.word = pAdapter->CommonCfg.BACapability.word;
3933 DBGPRINT(RT_DEBUG_TRACE, ("Set::(Orde.AutoBA = %d) (Policy=%d)(ReBAWinLimit=%d)(TxBAWinLimit=%d)(AutoMode=%d)\n",Orde.AutoBA, pAdapter->CommonCfg.BACapability.field.Policy,
3934 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit,pAdapter->CommonCfg.BACapability.field.TxBAWinLimit, pAdapter->CommonCfg.BACapability.field.AutoBA));
3935 DBGPRINT(RT_DEBUG_TRACE, ("Set::(MimoPs = %d)(AmsduEnable = %d) (AmsduSize=%d)(MpduDensity=%d)\n",pAdapter->CommonCfg.DesiredHtPhy.MimoPs, pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable,
3936 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize, pAdapter->CommonCfg.DesiredHtPhy.MpduDensity));
3940 case RT_OID_802_11_ADD_IMME_BA:
3941 DBGPRINT(RT_DEBUG_TRACE, (" Set :: RT_OID_802_11_ADD_IMME_BA \n"));
3942 if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
3947 OID_ADD_BA_ENTRY BA;
3948 MAC_TABLE_ENTRY *pEntry;
3950 Status = copy_from_user(&BA, wrq->u.data.pointer, wrq->u.data.length);
3953 Status = NDIS_STATUS_INVALID_DATA;
3958 //BATableInsertEntry
3959 //As ad-hoc mode, BA pair is not limited to only BSSID. so add via OID.
3961 // in ad hoc mode, when adding BA pair, we should insert this entry into MACEntry too
3962 pEntry = MacTableLookup(pAdapter, BA.MACAddr);
3965 DBGPRINT(RT_DEBUG_TRACE, ("RT_OID_802_11_ADD_IMME_BA. break on no connection.----:%x:%x\n", BA.MACAddr[4], BA.MACAddr[5]));
3968 if (BA.IsRecipient == FALSE)
3970 if (pEntry->bIAmBadAtheros == TRUE)
3971 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = 0x10;
3973 BAOriSessionSetUp(pAdapter, pEntry, index, 0, 100, TRUE);
3977 //BATableInsertEntry(pAdapter, pEntry->Aid, BA.MACAddr, 0, 0xffff, BA.TID, BA.nMSDU, BA.IsRecipient);
3980 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_IMME_BA. Rec = %d. Mac = %x:%x:%x:%x:%x:%x . \n",
3981 BA.IsRecipient, BA.MACAddr[0], BA.MACAddr[1], BA.MACAddr[2], BA.MACAddr[2]
3982 , BA.MACAddr[4], BA.MACAddr[5]));
3987 case RT_OID_802_11_TEAR_IMME_BA:
3988 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA \n"));
3989 if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
3993 POID_ADD_BA_ENTRY pBA;
3994 MAC_TABLE_ENTRY *pEntry;
3996 pBA = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4000 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA kmalloc() can't allocate enough memory\n"));
4001 Status = NDIS_STATUS_FAILURE;
4005 Status = copy_from_user(pBA, wrq->u.data.pointer, wrq->u.data.length);
4006 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA(TID=%d, bAllTid=%d)\n", pBA->TID, pBA->bAllTid));
4008 if (!pBA->bAllTid && (pBA->TID > NUM_OF_TID))
4010 Status = NDIS_STATUS_INVALID_DATA;
4014 if (pBA->IsRecipient == FALSE)
4016 pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
4017 DBGPRINT(RT_DEBUG_TRACE, (" pBA->IsRecipient == FALSE\n"));
4020 DBGPRINT(RT_DEBUG_TRACE, (" pBA->pEntry\n"));
4021 BAOriSessionTearDown(pAdapter, pEntry->Aid, pBA->TID, FALSE, TRUE);
4024 DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
4028 pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
4031 BARecSessionTearDown( pAdapter, (UCHAR)pEntry->Aid, pBA->TID, TRUE);
4034 DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
4040 #endif // DOT11_N_SUPPORT //
4042 // For WPA_SUPPLICANT to set static wep key
4043 case OID_802_11_ADD_WEP:
4044 pWepKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4049 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed!!\n"));
4052 Status = copy_from_user(pWepKey, wrq->u.data.pointer, wrq->u.data.length);
4056 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (length mismatch)!!\n"));
4060 KeyIdx = pWepKey->KeyIndex & 0x0fffffff;
4061 // KeyIdx must be 0 ~ 3
4065 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (KeyIdx must be smaller than 4)!!\n"));
4069 UCHAR CipherAlg = 0;
4072 // set key material and key length
4073 NdisZeroMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, 16);
4074 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
4075 NdisMoveMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
4077 switch(pWepKey->KeyLength)
4080 CipherAlg = CIPHER_WEP64;
4083 CipherAlg = CIPHER_WEP128;
4086 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, only support CIPHER_WEP64(len:5) & CIPHER_WEP128(len:13)!!\n"));
4090 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CipherAlg;
4092 // Default key for tx (shared key)
4093 if (pWepKey->KeyIndex & 0x80000000)
4095 #ifdef WPA_SUPPLICANT_SUPPORT
4096 // set key material and key length
4097 NdisZeroMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, 16);
4098 pAdapter->StaCfg.DesireSharedKey[KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
4099 NdisMoveMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
4100 pAdapter->StaCfg.DesireSharedKeyId = KeyIdx;
4101 pAdapter->StaCfg.DesireSharedKey[KeyIdx].CipherAlg = CipherAlg;
4102 #endif // WPA_SUPPLICANT_SUPPORT //
4103 pAdapter->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
4106 #ifdef WPA_SUPPLICANT_SUPPORT
4107 if ((pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE) &&
4108 (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA))
4110 Key = pWepKey->KeyMaterial;
4112 // Set Group key material to Asic
4113 AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
4115 // Update WCID attribute table and IVEIV table for this group key table
4116 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
4118 STA_PORT_SECURED(pAdapter);
4120 // Indicate Connected for GUI
4121 pAdapter->IndicateMediaState = NdisMediaStateConnected;
4123 else if (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)
4124 #endif // WPA_SUPPLICANT_SUPPORT
4126 Key = pAdapter->SharedKey[BSS0][KeyIdx].Key;
4128 // Set key material and cipherAlg to Asic
4129 AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
4131 if (pWepKey->KeyIndex & 0x80000000)
4133 PMAC_TABLE_ENTRY pEntry = &pAdapter->MacTab.Content[BSSID_WCID];
4134 // Assign group key info
4135 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
4136 // Assign pairwise key info
4137 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, pEntry);
4140 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"));
4145 #ifdef WPA_SUPPLICANT_SUPPORT
4146 case OID_SET_COUNTERMEASURES:
4147 if (wrq->u.data.length != sizeof(int))
4152 Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
4154 pAdapter->StaCfg.bBlockAssoc = TRUE;
4156 // WPA MIC error should block association attempt for 60 seconds
4157 pAdapter->StaCfg.bBlockAssoc = FALSE;
4158 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_SET_COUNTERMEASURES bBlockAssoc=%s\n", pAdapter->StaCfg.bBlockAssoc ? "TRUE":"FALSE"));
4161 case RT_OID_WPA_SUPPLICANT_SUPPORT:
4162 if (wrq->u.data.length != sizeof(UCHAR))
4166 Status = copy_from_user(&wpa_supplicant_enable, wrq->u.data.pointer, wrq->u.data.length);
4167 pAdapter->StaCfg.WpaSupplicantUP = wpa_supplicant_enable;
4168 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
4171 case OID_802_11_DEAUTHENTICATION:
4172 if (wrq->u.data.length != sizeof(MLME_DEAUTH_REQ_STRUCT))
4176 MLME_DEAUTH_REQ_STRUCT *pInfo;
4177 MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
4179 pInfo = (MLME_DEAUTH_REQ_STRUCT *) MsgElem->Msg;
4180 Status = copy_from_user(pInfo, wrq->u.data.pointer, wrq->u.data.length);
4181 MlmeDeauthReqAction(pAdapter, MsgElem);
4184 if (INFRA_ON(pAdapter))
4186 LinkDown(pAdapter, FALSE);
4187 pAdapter->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
4189 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DEAUTHENTICATION (Reason=%d)\n", pInfo->Reason));
4192 case OID_802_11_DROP_UNENCRYPTED:
4193 if (wrq->u.data.length != sizeof(int))
4198 Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
4200 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
4202 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
4203 NdisAcquireSpinLock(&pAdapter->MacTabLock);
4204 pAdapter->MacTab.Content[BSSID_WCID].PortSecured = pAdapter->StaCfg.PortSecured;
4205 NdisReleaseSpinLock(&pAdapter->MacTabLock);
4206 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DROP_UNENCRYPTED (=%d)\n", enabled));
4209 case OID_802_11_SET_IEEE8021X:
4210 if (wrq->u.data.length != sizeof(BOOLEAN))
4214 Status = copy_from_user(&IEEE8021xState, wrq->u.data.pointer, wrq->u.data.length);
4215 pAdapter->StaCfg.IEEE8021X = IEEE8021xState;
4216 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X (=%d)\n", IEEE8021xState));
4219 case OID_802_11_SET_IEEE8021X_REQUIRE_KEY:
4220 if (wrq->u.data.length != sizeof(BOOLEAN))
4224 Status = copy_from_user(&IEEE8021x_required_keys, wrq->u.data.pointer, wrq->u.data.length);
4225 pAdapter->StaCfg.IEEE8021x_required_keys = IEEE8021x_required_keys;
4226 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X_REQUIRE_KEY (%d)\n", IEEE8021x_required_keys));
4229 case OID_802_11_PMKID:
4230 pPmkId = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4232 if(pPmkId == NULL) {
4236 Status = copy_from_user(pPmkId, wrq->u.data.pointer, wrq->u.data.length);
4238 // check the PMKID information
4239 if (pPmkId->BSSIDInfoCount == 0)
4240 NdisZeroMemory(pAdapter->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
4243 PBSSID_INFO pBssIdInfo;
4247 for (BssIdx = 0; BssIdx < pPmkId->BSSIDInfoCount; BssIdx++)
4249 // point to the indexed BSSID_INFO structure
4250 pBssIdInfo = (PBSSID_INFO) ((PUCHAR) pPmkId + 2 * sizeof(UINT) + BssIdx * sizeof(BSSID_INFO));
4251 // Find the entry in the saved data base.
4252 for (CachedIdx = 0; CachedIdx < pAdapter->StaCfg.SavedPMKNum; CachedIdx++)
4254 // compare the BSSID
4255 if (NdisEqualMemory(pBssIdInfo->BSSID, pAdapter->StaCfg.SavedPMK[CachedIdx].BSSID, sizeof(NDIS_802_11_MAC_ADDRESS)))
4259 // Found, replace it
4260 if (CachedIdx < PMKID_NO)
4262 DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
4263 NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
4264 pAdapter->StaCfg.SavedPMKNum++;
4266 // Not found, replace the last one
4269 // Randomly replace one
4270 CachedIdx = (pBssIdInfo->BSSID[5] % PMKID_NO);
4271 DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
4272 NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
4279 #endif // WPA_SUPPLICANT_SUPPORT //
4282 DBGPRINT(RT_DEBUG_TRACE, ("Set::unknown IOCTL's subcmd = 0x%08x\n", cmd));
4283 Status = -EOPNOTSUPP;
4291 INT RTMPQueryInformation(
4292 IN PRTMP_ADAPTER pAdapter,
4293 IN OUT struct ifreq *rq,
4296 struct iwreq *wrq = (struct iwreq *) rq;
4297 NDIS_802_11_BSSID_LIST_EX *pBssidList = NULL;
4298 PNDIS_WLAN_BSSID_EX pBss;
4299 NDIS_802_11_SSID Ssid;
4300 NDIS_802_11_CONFIGURATION *pConfiguration = NULL;
4301 RT_802_11_LINK_STATUS *pLinkStatus = NULL;
4302 RT_802_11_STA_CONFIG *pStaConfig = NULL;
4303 NDIS_802_11_STATISTICS *pStatistics = NULL;
4304 NDIS_802_11_RTS_THRESHOLD RtsThresh;
4305 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
4306 NDIS_802_11_POWER_MODE PowerMode;
4307 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
4308 RT_802_11_PREAMBLE PreamType;
4309 NDIS_802_11_AUTHENTICATION_MODE AuthMode;
4310 NDIS_802_11_WEP_STATUS WepStatus;
4311 NDIS_MEDIA_STATE MediaState;
4312 ULONG BssBufSize, ulInfo=0, NetworkTypeList[4], apsd = 0;
4314 PUCHAR pBuf = NULL, pPtr;
4315 INT Status = NDIS_STATUS_SUCCESS;
4316 UINT we_version_compiled;
4317 UCHAR i, Padding = 0;
4319 UCHAR driverVersion[8];
4320 OID_SET_HT_PHYMODE *pHTPhyMode = NULL;
4324 case RT_OID_DEVICE_NAME:
4325 wrq->u.data.length = sizeof(STA_NIC_DEVICE_NAME);
4326 Status = copy_to_user(wrq->u.data.pointer, STA_NIC_DEVICE_NAME, wrq->u.data.length);
4328 case RT_OID_VERSION_INFO:
4329 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_VERSION_INFO \n"));
4330 wrq->u.data.length = 8*sizeof(UCHAR);
4331 sprintf(&driverVersion[0], "%s", STA_DRIVER_VERSION);
4332 driverVersion[7] = '\0';
4333 if (copy_to_user(wrq->u.data.pointer, &driverVersion, wrq->u.data.length))
4338 case OID_802_11_BSSID_LIST:
4339 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
4342 * Still scanning, indicate the caller should try again.
4344 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (Still scanning)\n"));
4347 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (%d BSS returned)\n",pAdapter->ScanTab.BssNr));
4348 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
4349 // Claculate total buffer size required
4350 BssBufSize = sizeof(ULONG);
4352 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
4354 // Align pointer to 4 bytes boundary.
4355 //Padding = 4 - (pAdapter->ScanTab.BssEntry[i].VarIELen & 0x0003);
4358 BssBufSize += (sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
4361 // For safety issue, we add 256 bytes just in case
4363 // Allocate the same size as passed from higher layer
4364 pBuf = kmalloc(BssBufSize, MEM_ALLOC_FLAG);
4370 // Init 802_11_BSSID_LIST_EX structure
4371 NdisZeroMemory(pBuf, BssBufSize);
4372 pBssidList = (PNDIS_802_11_BSSID_LIST_EX) pBuf;
4373 pBssidList->NumberOfItems = pAdapter->ScanTab.BssNr;
4375 // Calculate total buffer length
4376 BssLen = 4; // Consist of NumberOfItems
4377 // Point to start of NDIS_WLAN_BSSID_EX
4378 // pPtr = pBuf + sizeof(ULONG);
4379 pPtr = (PUCHAR) &pBssidList->Bssid[0];
4380 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
4382 pBss = (PNDIS_WLAN_BSSID_EX) pPtr;
4383 NdisMoveMemory(&pBss->MacAddress, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
4384 if ((pAdapter->ScanTab.BssEntry[i].Hidden == 1) && (pAdapter->StaCfg.bShowHiddenSSID == FALSE))
4387 // We must return this SSID during 4way handshaking, otherwise Aegis will failed to parse WPA infomation
4388 // and then failed to send EAPOl farame.
4390 if ((pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) && (pAdapter->StaCfg.PortSecured != WPA_802_1X_PORT_SECURED))
4392 pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
4393 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
4396 pBss->Ssid.SsidLength = 0;
4400 pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
4401 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
4403 pBss->Privacy = pAdapter->ScanTab.BssEntry[i].Privacy;
4404 pBss->Rssi = pAdapter->ScanTab.BssEntry[i].Rssi - pAdapter->BbpRssiToDbmDelta;
4405 pBss->NetworkTypeInUse = NetworkTypeInUseSanity(&pAdapter->ScanTab.BssEntry[i]);
4406 pBss->Configuration.Length = sizeof(NDIS_802_11_CONFIGURATION);
4407 pBss->Configuration.BeaconPeriod = pAdapter->ScanTab.BssEntry[i].BeaconPeriod;
4408 pBss->Configuration.ATIMWindow = pAdapter->ScanTab.BssEntry[i].AtimWin;
4410 MAP_CHANNEL_ID_TO_KHZ(pAdapter->ScanTab.BssEntry[i].Channel, pBss->Configuration.DSConfig);
4412 if (pAdapter->ScanTab.BssEntry[i].BssType == BSS_INFRA)
4413 pBss->InfrastructureMode = Ndis802_11Infrastructure;
4415 pBss->InfrastructureMode = Ndis802_11IBSS;
4417 NdisMoveMemory(pBss->SupportedRates, pAdapter->ScanTab.BssEntry[i].SupRate, pAdapter->ScanTab.BssEntry[i].SupRateLen);
4418 NdisMoveMemory(pBss->SupportedRates + pAdapter->ScanTab.BssEntry[i].SupRateLen,
4419 pAdapter->ScanTab.BssEntry[i].ExtRate,
4420 pAdapter->ScanTab.BssEntry[i].ExtRateLen);
4422 if (pAdapter->ScanTab.BssEntry[i].VarIELen == 0)
4424 pBss->IELength = sizeof(NDIS_802_11_FIXED_IEs);
4425 NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
4426 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
4430 pBss->IELength = (ULONG)(sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen);
4431 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
4432 NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
4433 NdisMoveMemory(pBss->IEs + sizeof(NDIS_802_11_FIXED_IEs), pAdapter->ScanTab.BssEntry[i].VarIEs, pAdapter->ScanTab.BssEntry[i].VarIELen);
4434 pPtr += pAdapter->ScanTab.BssEntry[i].VarIELen;
4436 pBss->Length = (ULONG)(sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
4438 #if WIRELESS_EXT < 17
4439 if ((BssLen + pBss->Length) < wrq->u.data.length)
4440 BssLen += pBss->Length;
4443 pBssidList->NumberOfItems = i;
4447 BssLen += pBss->Length;
4451 #if WIRELESS_EXT < 17
4452 wrq->u.data.length = BssLen;
4454 if (BssLen > wrq->u.data.length)
4460 wrq->u.data.length = BssLen;
4462 Status = copy_to_user(wrq->u.data.pointer, pBssidList, BssLen);
4465 case OID_802_3_CURRENT_ADDRESS:
4466 wrq->u.data.length = MAC_ADDR_LEN;
4467 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
4469 case OID_GEN_MEDIA_CONNECT_STATUS:
4470 if (pAdapter->IndicateMediaState == NdisMediaStateConnected)
4471 MediaState = NdisMediaStateConnected;
4473 MediaState = NdisMediaStateDisconnected;
4475 wrq->u.data.length = sizeof(NDIS_MEDIA_STATE);
4476 Status = copy_to_user(wrq->u.data.pointer, &MediaState, wrq->u.data.length);
4478 case OID_802_11_BSSID:
4479 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
4481 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Bssid, sizeof(NDIS_802_11_MAC_ADDRESS));
4486 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID(=EMPTY)\n"));
4490 case OID_802_11_SSID:
4491 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
4492 NdisZeroMemory(Ssid.Ssid, MAX_LEN_OF_SSID);
4493 Ssid.SsidLength = pAdapter->CommonCfg.SsidLen;
4494 memcpy(Ssid.Ssid, pAdapter->CommonCfg.Ssid, Ssid.SsidLength);
4495 wrq->u.data.length = sizeof(NDIS_802_11_SSID);
4496 Status = copy_to_user(wrq->u.data.pointer, &Ssid, wrq->u.data.length);
4497 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_SSID (Len=%d, ssid=%s)\n", Ssid.SsidLength,Ssid.Ssid));
4499 case RT_OID_802_11_QUERY_LINK_STATUS:
4500 pLinkStatus = (RT_802_11_LINK_STATUS *) kmalloc(sizeof(RT_802_11_LINK_STATUS), MEM_ALLOC_FLAG);
4503 pLinkStatus->CurrTxRate = RateIdTo500Kbps[pAdapter->CommonCfg.TxRate]; // unit : 500 kbps
4504 pLinkStatus->ChannelQuality = pAdapter->Mlme.ChannelQuality;
4505 pLinkStatus->RxByteCount = pAdapter->RalinkCounters.ReceivedByteCount;
4506 pLinkStatus->TxByteCount = pAdapter->RalinkCounters.TransmittedByteCount;
4507 pLinkStatus->CentralChannel = pAdapter->CommonCfg.CentralChannel;
4508 wrq->u.data.length = sizeof(RT_802_11_LINK_STATUS);
4509 Status = copy_to_user(wrq->u.data.pointer, pLinkStatus, wrq->u.data.length);
4511 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS\n"));
4515 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS(kmalloc failed)\n"));
4519 case OID_802_11_CONFIGURATION:
4520 pConfiguration = (NDIS_802_11_CONFIGURATION *) kmalloc(sizeof(NDIS_802_11_CONFIGURATION), MEM_ALLOC_FLAG);
4523 pConfiguration->Length = sizeof(NDIS_802_11_CONFIGURATION);
4524 pConfiguration->BeaconPeriod = pAdapter->CommonCfg.BeaconPeriod;
4525 pConfiguration->ATIMWindow = pAdapter->StaActive.AtimWin;
4526 MAP_CHANNEL_ID_TO_KHZ(pAdapter->CommonCfg.Channel, pConfiguration->DSConfig);
4527 wrq->u.data.length = sizeof(NDIS_802_11_CONFIGURATION);
4528 Status = copy_to_user(wrq->u.data.pointer, pConfiguration, wrq->u.data.length);
4529 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(BeaconPeriod=%ld,AtimW=%ld,Channel=%d) \n",
4530 pConfiguration->BeaconPeriod, pConfiguration->ATIMWindow, pAdapter->CommonCfg.Channel));
4531 kfree(pConfiguration);
4535 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(kmalloc failed)\n"));
4539 case RT_OID_802_11_SNR_0:
4540 if ((pAdapter->StaCfg.LastSNR0 > 0))
4542 ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR0) * 3) / 16 ;
4543 wrq->u.data.length = sizeof(ulInfo);
4544 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4545 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_SNR_0(0x=%lx)\n", ulInfo));
4550 case RT_OID_802_11_SNR_1:
4551 if ((pAdapter->Antenna.field.RxPath > 1) &&
4552 (pAdapter->StaCfg.LastSNR1 > 0))
4554 ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR1) * 3) / 16 ;
4555 wrq->u.data.length = sizeof(ulInfo);
4556 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4557 DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(0x=%lx)\n",ulInfo));
4561 DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(pAdapter->StaCfg.LastSNR1=%d)\n",pAdapter->StaCfg.LastSNR1));
4563 case OID_802_11_RSSI_TRIGGER:
4564 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0 - pAdapter->BbpRssiToDbmDelta;
4565 wrq->u.data.length = sizeof(ulInfo);
4566 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4567 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RSSI_TRIGGER(=%ld)\n", ulInfo));
4569 case OID_802_11_RSSI:
4570 case RT_OID_802_11_RSSI:
4571 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0;
4572 wrq->u.data.length = sizeof(ulInfo);
4573 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4575 case RT_OID_802_11_RSSI_1:
4576 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi1;
4577 wrq->u.data.length = sizeof(ulInfo);
4578 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4580 case RT_OID_802_11_RSSI_2:
4581 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi2;
4582 wrq->u.data.length = sizeof(ulInfo);
4583 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4585 case OID_802_11_STATISTICS:
4586 pStatistics = (NDIS_802_11_STATISTICS *) kmalloc(sizeof(NDIS_802_11_STATISTICS), MEM_ALLOC_FLAG);
4589 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS \n"));
4590 // add the most up-to-date h/w raw counters into software counters
4591 NICUpdateRawCounters(pAdapter);
4593 // Sanity check for calculation of sucessful count
4594 if (pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart < pAdapter->WlanCounters.RetryCount.QuadPart)
4595 pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
4597 pStatistics->TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart;
4598 pStatistics->MulticastTransmittedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastTransmittedFrameCount.QuadPart;
4599 pStatistics->FailedCount.QuadPart = pAdapter->WlanCounters.FailedCount.QuadPart;
4600 pStatistics->RetryCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
4601 pStatistics->MultipleRetryCount.QuadPart = pAdapter->WlanCounters.MultipleRetryCount.QuadPart;
4602 pStatistics->RTSSuccessCount.QuadPart = pAdapter->WlanCounters.RTSSuccessCount.QuadPart;
4603 pStatistics->RTSFailureCount.QuadPart = pAdapter->WlanCounters.RTSFailureCount.QuadPart;
4604 pStatistics->ACKFailureCount.QuadPart = pAdapter->WlanCounters.ACKFailureCount.QuadPart;
4605 pStatistics->FrameDuplicateCount.QuadPart = pAdapter->WlanCounters.FrameDuplicateCount.QuadPart;
4606 pStatistics->ReceivedFragmentCount.QuadPart = pAdapter->WlanCounters.ReceivedFragmentCount.QuadPart;
4607 pStatistics->MulticastReceivedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastReceivedFrameCount.QuadPart;
4609 pStatistics->FCSErrorCount = pAdapter->RalinkCounters.RealFcsErrCount;
4611 pStatistics->FCSErrorCount.QuadPart = pAdapter->WlanCounters.FCSErrorCount.QuadPart;
4612 pStatistics->FrameDuplicateCount.u.LowPart = pAdapter->WlanCounters.FrameDuplicateCount.u.LowPart / 100;
4614 wrq->u.data.length = sizeof(NDIS_802_11_STATISTICS);
4615 Status = copy_to_user(wrq->u.data.pointer, pStatistics, wrq->u.data.length);
4620 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS(kmalloc failed)\n"));
4624 case OID_GEN_RCV_OK:
4625 ulInfo = pAdapter->Counters8023.GoodReceives;
4626 wrq->u.data.length = sizeof(ulInfo);
4627 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4629 case OID_GEN_RCV_NO_BUFFER:
4630 ulInfo = pAdapter->Counters8023.RxNoBuffer;
4631 wrq->u.data.length = sizeof(ulInfo);
4632 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4634 case RT_OID_802_11_PHY_MODE:
4635 ulInfo = (ULONG)pAdapter->CommonCfg.PhyMode;
4636 wrq->u.data.length = sizeof(ulInfo);
4637 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4638 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PHY_MODE (=%ld)\n", ulInfo));
4640 case RT_OID_802_11_STA_CONFIG:
4641 pStaConfig = (RT_802_11_STA_CONFIG *) kmalloc(sizeof(RT_802_11_STA_CONFIG), MEM_ALLOC_FLAG);
4644 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG\n"));
4645 pStaConfig->EnableTxBurst = pAdapter->CommonCfg.bEnableTxBurst;
4646 pStaConfig->EnableTurboRate = 0;
4647 pStaConfig->UseBGProtection = pAdapter->CommonCfg.UseBGProtection;
4648 pStaConfig->UseShortSlotTime = pAdapter->CommonCfg.bUseShortSlotTime;
4649 //pStaConfig->AdhocMode = pAdapter->StaCfg.AdhocMode;
4650 pStaConfig->HwRadioStatus = (pAdapter->StaCfg.bHwRadio == TRUE) ? 1 : 0;
4651 pStaConfig->Rsv1 = 0;
4652 pStaConfig->SystemErrorBitmap = pAdapter->SystemErrorBitmap;
4653 wrq->u.data.length = sizeof(RT_802_11_STA_CONFIG);
4654 Status = copy_to_user(wrq->u.data.pointer, pStaConfig, wrq->u.data.length);
4659 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
4663 case OID_802_11_RTS_THRESHOLD:
4664 RtsThresh = pAdapter->CommonCfg.RtsThreshold;
4665 wrq->u.data.length = sizeof(RtsThresh);
4666 Status = copy_to_user(wrq->u.data.pointer, &RtsThresh, wrq->u.data.length);
4667 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RTS_THRESHOLD(=%ld)\n", RtsThresh));
4669 case OID_802_11_FRAGMENTATION_THRESHOLD:
4670 FragThresh = pAdapter->CommonCfg.FragmentThreshold;
4671 if (pAdapter->CommonCfg.bUseZeroToDisableFragment == TRUE)
4673 wrq->u.data.length = sizeof(FragThresh);
4674 Status = copy_to_user(wrq->u.data.pointer, &FragThresh, wrq->u.data.length);
4675 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_FRAGMENTATION_THRESHOLD(=%ld)\n", FragThresh));
4677 case OID_802_11_POWER_MODE:
4678 PowerMode = pAdapter->StaCfg.WindowsPowerMode;
4679 wrq->u.data.length = sizeof(PowerMode);
4680 Status = copy_to_user(wrq->u.data.pointer, &PowerMode, wrq->u.data.length);
4681 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_POWER_MODE(=%d)\n", PowerMode));
4683 case RT_OID_802_11_RADIO:
4684 RadioState = (BOOLEAN) pAdapter->StaCfg.bSwRadio;
4685 wrq->u.data.length = sizeof(RadioState);
4686 Status = copy_to_user(wrq->u.data.pointer, &RadioState, wrq->u.data.length);
4687 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_RADIO (=%d)\n", RadioState));
4689 case OID_802_11_INFRASTRUCTURE_MODE:
4690 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
4691 BssType = Ndis802_11IBSS;
4692 else if (pAdapter->StaCfg.BssType == BSS_INFRA)
4693 BssType = Ndis802_11Infrastructure;
4694 else if (pAdapter->StaCfg.BssType == BSS_MONITOR)
4695 BssType = Ndis802_11Monitor;
4697 BssType = Ndis802_11AutoUnknown;
4699 wrq->u.data.length = sizeof(BssType);
4700 Status = copy_to_user(wrq->u.data.pointer, &BssType, wrq->u.data.length);
4701 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_INFRASTRUCTURE_MODE(=%d)\n", BssType));
4703 case RT_OID_802_11_PREAMBLE:
4704 PreamType = pAdapter->CommonCfg.TxPreamble;
4705 wrq->u.data.length = sizeof(PreamType);
4706 Status = copy_to_user(wrq->u.data.pointer, &PreamType, wrq->u.data.length);
4707 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PREAMBLE(=%d)\n", PreamType));
4709 case OID_802_11_AUTHENTICATION_MODE:
4710 AuthMode = pAdapter->StaCfg.AuthMode;
4711 wrq->u.data.length = sizeof(AuthMode);
4712 Status = copy_to_user(wrq->u.data.pointer, &AuthMode, wrq->u.data.length);
4713 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_AUTHENTICATION_MODE(=%d)\n", AuthMode));
4715 case OID_802_11_WEP_STATUS:
4716 WepStatus = pAdapter->StaCfg.WepStatus;
4717 wrq->u.data.length = sizeof(WepStatus);
4718 Status = copy_to_user(wrq->u.data.pointer, &WepStatus, wrq->u.data.length);
4719 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_WEP_STATUS(=%d)\n", WepStatus));
4721 case OID_802_11_TX_POWER_LEVEL:
4722 wrq->u.data.length = sizeof(ULONG);
4723 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPower, wrq->u.data.length);
4724 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_TX_POWER_LEVEL %x\n",pAdapter->CommonCfg.TxPower));
4726 case RT_OID_802_11_TX_POWER_LEVEL_1:
4727 wrq->u.data.length = sizeof(ULONG);
4728 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPowerPercentage, wrq->u.data.length);
4729 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
4731 case OID_802_11_NETWORK_TYPES_SUPPORTED:
4732 if ((pAdapter->RfIcType == RFIC_2850) || (pAdapter->RfIcType == RFIC_2750))
4734 NetworkTypeList[0] = 3; // NumberOfItems = 3
4735 NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
4736 NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
4737 NetworkTypeList[3] = Ndis802_11OFDM5; // NetworkType[3] = 11a
4738 wrq->u.data.length = 16;
4739 Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
4743 NetworkTypeList[0] = 2; // NumberOfItems = 2
4744 NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
4745 NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
4746 wrq->u.data.length = 12;
4747 Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
4749 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_NETWORK_TYPES_SUPPORTED\n"));
4751 case OID_802_11_NETWORK_TYPE_IN_USE:
4752 wrq->u.data.length = sizeof(ULONG);
4753 if (pAdapter->CommonCfg.PhyMode == PHY_11A)
4754 ulInfo = Ndis802_11OFDM5;
4755 else if ((pAdapter->CommonCfg.PhyMode == PHY_11BG_MIXED) || (pAdapter->CommonCfg.PhyMode == PHY_11G))
4756 ulInfo = Ndis802_11OFDM24;
4758 ulInfo = Ndis802_11DS;
4759 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4761 case RT_OID_802_11_QUERY_LAST_RX_RATE:
4762 ulInfo = (ULONG)pAdapter->LastRxRate;
4763 wrq->u.data.length = sizeof(ulInfo);
4764 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4765 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_RX_RATE (=%ld)\n", ulInfo));
4767 case RT_OID_802_11_QUERY_LAST_TX_RATE:
4768 //ulInfo = (ULONG)pAdapter->LastTxRate;
4769 ulInfo = (ULONG)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word;
4770 wrq->u.data.length = sizeof(ulInfo);
4771 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4772 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_TX_RATE (=%lx)\n", ulInfo));
4774 case RT_OID_802_11_QUERY_EEPROM_VERSION:
4775 wrq->u.data.length = sizeof(ULONG);
4776 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->EepromVersion, wrq->u.data.length);
4778 case RT_OID_802_11_QUERY_FIRMWARE_VERSION:
4779 wrq->u.data.length = sizeof(ULONG);
4780 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->FirmwareVersion, wrq->u.data.length);
4782 case RT_OID_802_11_QUERY_NOISE_LEVEL:
4783 wrq->u.data.length = sizeof(UCHAR);
4784 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->BbpWriteLatch[66], wrq->u.data.length);
4785 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_NOISE_LEVEL (=%d)\n", pAdapter->BbpWriteLatch[66]));
4787 case RT_OID_802_11_EXTRA_INFO:
4788 wrq->u.data.length = sizeof(ULONG);
4789 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->ExtraInfo, wrq->u.data.length);
4790 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_EXTRA_INFO (=%ld)\n", pAdapter->ExtraInfo));
4792 case RT_OID_WE_VERSION_COMPILED:
4793 wrq->u.data.length = sizeof(UINT);
4794 we_version_compiled = WIRELESS_EXT;
4795 Status = copy_to_user(wrq->u.data.pointer, &we_version_compiled, wrq->u.data.length);
4797 case RT_OID_802_11_QUERY_APSD_SETTING:
4798 apsd = (pAdapter->CommonCfg.bAPSDCapable | (pAdapter->CommonCfg.bAPSDAC_BE << 1) | (pAdapter->CommonCfg.bAPSDAC_BK << 2)
4799 | (pAdapter->CommonCfg.bAPSDAC_VI << 3) | (pAdapter->CommonCfg.bAPSDAC_VO << 4) | (pAdapter->CommonCfg.MaxSPLength << 5));
4801 wrq->u.data.length = sizeof(ULONG);
4802 Status = copy_to_user(wrq->u.data.pointer, &apsd, wrq->u.data.length);
4803 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",
4804 apsd,pAdapter->CommonCfg.bAPSDCapable,pAdapter->CommonCfg.bAPSDAC_BE,pAdapter->CommonCfg.bAPSDAC_BK,pAdapter->CommonCfg.bAPSDAC_VI,pAdapter->CommonCfg.bAPSDAC_VO,pAdapter->CommonCfg.MaxSPLength));
4806 case RT_OID_802_11_QUERY_APSD_PSM:
4807 wrq->u.data.length = sizeof(ULONG);
4808 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.length);
4809 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_APSD_PSM (=%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
4811 case RT_OID_802_11_QUERY_WMM:
4812 wrq->u.data.length = sizeof(BOOLEAN);
4813 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bWmmCapable, wrq->u.data.length);
4814 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_WMM (=%d)\n", pAdapter->CommonCfg.bWmmCapable));
4816 #ifdef WPA_SUPPLICANT_SUPPORT
4817 case RT_OID_NEW_DRIVER:
4820 wrq->u.data.length = sizeof(UCHAR);
4821 Status = copy_to_user(wrq->u.data.pointer, &enabled, wrq->u.data.length);
4822 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_NEW_DRIVER (=%d)\n", enabled));
4825 case RT_OID_WPA_SUPPLICANT_SUPPORT:
4826 wrq->u.data.length = sizeof(UCHAR);
4827 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->StaCfg.WpaSupplicantUP, wrq->u.data.length);
4828 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
4830 #endif // WPA_SUPPLICANT_SUPPORT //
4832 case RT_OID_DRIVER_DEVICE_NAME:
4833 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_DRIVER_DEVICE_NAME \n"));
4834 wrq->u.data.length = 16;
4835 if (copy_to_user(wrq->u.data.pointer, pAdapter->StaCfg.dev_name, wrq->u.data.length))
4840 case RT_OID_802_11_QUERY_HT_PHYMODE:
4841 pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
4844 pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
4845 pHTPhyMode->HtMode = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE;
4846 pHTPhyMode->BW = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.BW;
4847 pHTPhyMode->MCS= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MCS;
4848 pHTPhyMode->SHORTGI= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.ShortGI;
4849 pHTPhyMode->STBC= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.STBC;
4851 pHTPhyMode->ExtOffset = ((pAdapter->CommonCfg.CentralChannel < pAdapter->CommonCfg.Channel) ? (EXTCHA_BELOW) : (EXTCHA_ABOVE));
4852 wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
4853 if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
4857 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
4858 pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
4859 DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
4863 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
4867 case RT_OID_802_11_COUNTRY_REGION:
4868 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_COUNTRY_REGION \n"));
4869 wrq->u.data.length = sizeof(ulInfo);
4870 ulInfo = pAdapter->CommonCfg.CountryRegionForABand;
4871 ulInfo = (ulInfo << 8)|(pAdapter->CommonCfg.CountryRegion);
4872 if (copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length))
4877 case RT_OID_802_11_QUERY_DAT_HT_PHYMODE:
4878 pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
4881 pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
4882 pHTPhyMode->HtMode = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.HTMODE;
4883 pHTPhyMode->BW = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.BW;
4884 pHTPhyMode->MCS= (UCHAR)pAdapter->StaCfg.DesiredTransmitSetting.field.MCS;
4885 pHTPhyMode->SHORTGI= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.ShortGI;
4886 pHTPhyMode->STBC= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.STBC;
4888 wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
4889 if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
4893 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
4894 pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
4895 DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
4899 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
4903 case RT_OID_QUERY_MULTIPLE_CARD_SUPPORT:
4904 wrq->u.data.length = sizeof(UCHAR);
4906 if (copy_to_user(wrq->u.data.pointer, &i, wrq->u.data.length))
4910 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_QUERY_MULTIPLE_CARD_SUPPORT(=%d) \n", i));
4913 case OID_802_11_BUILD_CHANNEL_EX:
4916 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BUILD_CHANNEL_EX \n"));
4917 wrq->u.data.length = sizeof(UCHAR);
4918 DBGPRINT(RT_DEBUG_TRACE, ("Doesn't support EXT_BUILD_CHANNEL_LIST.\n"));
4920 Status = copy_to_user(wrq->u.data.pointer, &value, 1);
4921 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
4925 case OID_802_11_GET_CH_LIST:
4927 PRT_CHANNEL_LIST_INFO pChListBuf;
4929 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CH_LIST \n"));
4930 if (pAdapter->ChannelListNum == 0)
4932 wrq->u.data.length = 0;
4936 pChListBuf = (RT_CHANNEL_LIST_INFO *) kmalloc(sizeof(RT_CHANNEL_LIST_INFO), MEM_ALLOC_FLAG);
4937 if (pChListBuf == NULL)
4939 wrq->u.data.length = 0;
4943 pChListBuf->ChannelListNum = pAdapter->ChannelListNum;
4944 for (i = 0; i < pChListBuf->ChannelListNum; i++)
4945 pChListBuf->ChannelList[i] = pAdapter->ChannelList[i].Channel;
4947 wrq->u.data.length = sizeof(RT_CHANNEL_LIST_INFO);
4948 Status = copy_to_user(wrq->u.data.pointer, pChListBuf, sizeof(RT_CHANNEL_LIST_INFO));
4949 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
4956 case OID_802_11_GET_COUNTRY_CODE:
4957 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_COUNTRY_CODE \n"));
4958 wrq->u.data.length = 2;
4959 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.CountryCode, 2);
4960 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
4963 case OID_802_11_GET_CHANNEL_GEOGRAPHY:
4964 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CHANNEL_GEOGRAPHY \n"));
4965 wrq->u.data.length = 1;
4966 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Geography, 1);
4967 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
4971 DBGPRINT(RT_DEBUG_TRACE, ("Query::unknown IOCTL's subcmd = 0x%08x\n", cmd));
4972 Status = -EOPNOTSUPP;
4978 INT rt28xx_sta_ioctl(
4979 IN struct net_device *net_dev,
4980 IN OUT struct ifreq *rq,
4984 VIRTUAL_ADAPTER *pVirtualAd = NULL;
4985 RTMP_ADAPTER *pAd = NULL;
4986 struct iwreq *wrq = (struct iwreq *) rq;
4987 BOOLEAN StateMachineTouched = FALSE;
4988 INT Status = NDIS_STATUS_SUCCESS;
4991 if (net_dev->priv_flags == INT_MAIN)
4993 pAd = net_dev->ml_priv;
4997 pVirtualAd = net_dev->ml_priv;
4998 pAd = pVirtualAd->RtmpDev->ml_priv;
5000 pObj = (POS_COOKIE) pAd->OS_Cookie;
5004 /* if 1st open fail, pAd will be free;
5005 So the net_dev->ml_priv will be NULL in 2rd open */
5009 //check if the interface is down
5010 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
5013 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
5018 { // determine this ioctl command is comming from which interface.
5019 pObj->ioctl_if_type = INT_MAIN;
5020 pObj->ioctl_if = MAIN_MBSSID;
5026 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIFHWADDR\n"));
5027 memcpy(wrq->u.name, pAd->CurrentAddress, ETH_ALEN);
5031 char *name=&wrq->u.name[0];
5032 rt_ioctl_giwname(net_dev, NULL, name, NULL);
5035 case SIOCGIWESSID: //Get ESSID
5037 struct iw_point *essid=&wrq->u.essid;
5038 rt_ioctl_giwessid(net_dev, NULL, essid, essid->pointer);
5041 case SIOCSIWESSID: //Set ESSID
5043 struct iw_point *essid=&wrq->u.essid;
5044 rt_ioctl_siwessid(net_dev, NULL, essid, essid->pointer);
5047 case SIOCSIWNWID: // set network id (the cell)
5048 case SIOCGIWNWID: // get network id
5049 Status = -EOPNOTSUPP;
5051 case SIOCSIWFREQ: //set channel/frequency (Hz)
5053 struct iw_freq *freq=&wrq->u.freq;
5054 rt_ioctl_siwfreq(net_dev, NULL, freq, NULL);
5057 case SIOCGIWFREQ: // get channel/frequency (Hz)
5059 struct iw_freq *freq=&wrq->u.freq;
5060 rt_ioctl_giwfreq(net_dev, NULL, freq, NULL);
5063 case SIOCSIWNICKN: //set node name/nickname
5065 struct iw_point *data=&wrq->u.data;
5066 rt_ioctl_siwnickn(net_dev, NULL, data, NULL);
5069 case SIOCGIWNICKN: //get node name/nickname
5071 struct iw_point *data=&wrq->u.data;
5072 rt_ioctl_giwnickn(net_dev, NULL, data, NULL);
5075 case SIOCGIWRATE: //get default bit rate (bps)
5076 rt_ioctl_giwrate(net_dev, NULL, &wrq->u, NULL);
5078 case SIOCSIWRATE: //set default bit rate (bps)
5079 rt_ioctl_siwrate(net_dev, NULL, &wrq->u, NULL);
5081 case SIOCGIWRTS: // get RTS/CTS threshold (bytes)
5083 struct iw_param *rts=&wrq->u.rts;
5084 rt_ioctl_giwrts(net_dev, NULL, rts, NULL);
5087 case SIOCSIWRTS: //set RTS/CTS threshold (bytes)
5089 struct iw_param *rts=&wrq->u.rts;
5090 rt_ioctl_siwrts(net_dev, NULL, rts, NULL);
5093 case SIOCGIWFRAG: //get fragmentation thr (bytes)
5095 struct iw_param *frag=&wrq->u.frag;
5096 rt_ioctl_giwfrag(net_dev, NULL, frag, NULL);
5099 case SIOCSIWFRAG: //set fragmentation thr (bytes)
5101 struct iw_param *frag=&wrq->u.frag;
5102 rt_ioctl_siwfrag(net_dev, NULL, frag, NULL);
5105 case SIOCGIWENCODE: //get encoding token & mode
5107 struct iw_point *erq=&wrq->u.encoding;
5109 rt_ioctl_giwencode(net_dev, NULL, erq, erq->pointer);
5112 case SIOCSIWENCODE: //set encoding token & mode
5114 struct iw_point *erq=&wrq->u.encoding;
5116 rt_ioctl_siwencode(net_dev, NULL, erq, erq->pointer);
5119 case SIOCGIWAP: //get access point MAC addresses
5121 struct sockaddr *ap_addr=&wrq->u.ap_addr;
5122 rt_ioctl_giwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
5125 case SIOCSIWAP: //set access point MAC addresses
5127 struct sockaddr *ap_addr=&wrq->u.ap_addr;
5128 rt_ioctl_siwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
5131 case SIOCGIWMODE: //get operation mode
5133 __u32 *mode=&wrq->u.mode;
5134 rt_ioctl_giwmode(net_dev, NULL, mode, NULL);
5137 case SIOCSIWMODE: //set operation mode
5139 __u32 *mode=&wrq->u.mode;
5140 rt_ioctl_siwmode(net_dev, NULL, mode, NULL);
5143 case SIOCGIWSENS: //get sensitivity (dBm)
5144 case SIOCSIWSENS: //set sensitivity (dBm)
5145 case SIOCGIWPOWER: //get Power Management settings
5146 case SIOCSIWPOWER: //set Power Management settings
5147 case SIOCGIWTXPOW: //get transmit power (dBm)
5148 case SIOCSIWTXPOW: //set transmit power (dBm)
5149 case SIOCGIWRANGE: //Get range of parameters
5150 case SIOCGIWRETRY: //get retry limits and lifetime
5151 case SIOCSIWRETRY: //set retry limits and lifetime
5152 Status = -EOPNOTSUPP;
5155 subcmd = wrq->u.data.flags;
5156 if( subcmd & OID_GET_SET_TOGGLE)
5157 Status = RTMPSetInformation(pAd, rq, subcmd);
5159 Status = RTMPQueryInformation(pAd, rq, subcmd);
5162 if (wrq->u.data.pointer)
5164 if ( access_ok(VERIFY_WRITE, wrq->u.data.pointer, sizeof(privtab)) != TRUE)
5166 wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
5167 if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
5171 case RTPRIV_IOCTL_SET:
5172 if(access_ok(VERIFY_READ, wrq->u.data.pointer, wrq->u.data.length) != TRUE)
5174 rt_ioctl_setparam(net_dev, NULL, NULL, wrq->u.data.pointer);
5176 case RTPRIV_IOCTL_GSITESURVEY:
5177 RTMPIoctlGetSiteSurvey(pAd, wrq);
5180 case RTPRIV_IOCTL_MAC:
5181 RTMPIoctlMAC(pAd, wrq);
5183 case RTPRIV_IOCTL_E2P:
5184 RTMPIoctlE2PROM(pAd, wrq);
5190 DBGPRINT(RT_DEBUG_ERROR, ("IOCTL::unknown IOCTL's cmd = 0x%08x\n", cmd));
5191 Status = -EOPNOTSUPP;
5195 if(StateMachineTouched) // Upper layer sent a MLME-related operations
5196 RT28XX_MLME_HANDLER(pAd);
5202 ==========================================================================
5206 TRUE if all parameters are OK, FALSE otherwise
5207 ==========================================================================
5210 IN PRTMP_ADAPTER pAdapter,
5213 NDIS_802_11_SSID Ssid, *pSsid=NULL;
5214 BOOLEAN StateMachineTouched = FALSE;
5217 if( strlen(arg) <= MAX_LEN_OF_SSID)
5219 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
5220 if (strlen(arg) != 0)
5222 NdisMoveMemory(Ssid.Ssid, arg, strlen(arg));
5223 Ssid.SsidLength = strlen(arg);
5227 Ssid.SsidLength = 0;
5228 memcpy(Ssid.Ssid, "", 0);
5229 pAdapter->StaCfg.BssType = BSS_INFRA;
5230 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
5231 pAdapter->StaCfg.WepStatus = Ndis802_11EncryptionDisabled;
5235 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
5237 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
5238 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
5241 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
5242 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
5243 pAdapter->bConfigChanged = TRUE;
5245 MlmeEnqueue(pAdapter,
5246 MLME_CNTL_STATE_MACHINE,
5248 sizeof(NDIS_802_11_SSID),
5251 StateMachineTouched = TRUE;
5252 DBGPRINT(RT_DEBUG_TRACE, ("Set_SSID_Proc::(Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
5257 if (StateMachineTouched) // Upper layer sent a MLME-related operations
5258 RT28XX_MLME_HANDLER(pAdapter);
5265 ==========================================================================
5267 Set WmmCapable Enable or Disable
5269 TRUE if all parameters are OK, FALSE otherwise
5270 ==========================================================================
5272 INT Set_WmmCapable_Proc(
5273 IN PRTMP_ADAPTER pAd,
5276 BOOLEAN bWmmCapable;
5278 bWmmCapable = simple_strtol(arg, 0, 10);
5280 if ((bWmmCapable == 1)
5282 && (pAd->NumberOfPipes >= 5)
5285 pAd->CommonCfg.bWmmCapable = TRUE;
5286 else if (bWmmCapable == 0)
5287 pAd->CommonCfg.bWmmCapable = FALSE;
5289 return FALSE; //Invalid argument
5291 DBGPRINT(RT_DEBUG_TRACE, ("Set_WmmCapable_Proc::(bWmmCapable=%d)\n",
5292 pAd->CommonCfg.bWmmCapable));
5296 #endif // WMM_SUPPORT //
5299 ==========================================================================
5301 Set Network Type(Infrastructure/Adhoc mode)
5303 TRUE if all parameters are OK, FALSE otherwise
5304 ==========================================================================
5306 INT Set_NetworkType_Proc(
5307 IN PRTMP_ADAPTER pAdapter,
5312 if (strcmp(arg, "Adhoc") == 0)
5314 if (pAdapter->StaCfg.BssType != BSS_ADHOC)
5316 // Config has changed
5317 pAdapter->bConfigChanged = TRUE;
5318 if (MONITOR_ON(pAdapter))
5320 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
5321 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5323 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5324 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5325 pAdapter->StaCfg.bAutoReconnect = TRUE;
5326 LinkDown(pAdapter, FALSE);
5328 if (INFRA_ON(pAdapter))
5330 //BOOLEAN Cancelled;
5331 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
5332 // Since calling this indicate user don't want to connect to that SSID anymore.
5333 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
5334 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
5336 LinkDown(pAdapter, FALSE);
5338 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n"));
5341 pAdapter->StaCfg.BssType = BSS_ADHOC;
5342 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
5343 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(AD-HOC)\n"));
5345 else if (strcmp(arg, "Infra") == 0)
5347 if (pAdapter->StaCfg.BssType != BSS_INFRA)
5349 // Config has changed
5350 pAdapter->bConfigChanged = TRUE;
5351 if (MONITOR_ON(pAdapter))
5353 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
5354 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5356 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5357 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5358 pAdapter->StaCfg.bAutoReconnect = TRUE;
5359 LinkDown(pAdapter, FALSE);
5361 if (ADHOC_ON(pAdapter))
5363 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
5364 // Since calling this indicate user don't want to connect to that SSID anymore.
5365 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
5366 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
5368 LinkDown(pAdapter, FALSE);
5371 pAdapter->StaCfg.BssType = BSS_INFRA;
5372 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
5373 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(INFRA)\n"));
5375 pAdapter->StaCfg.BssType = BSS_INFRA;
5377 else if (strcmp(arg, "Monitor") == 0)
5380 BCN_TIME_CFG_STRUC csr;
5381 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_INFRA_ON);
5382 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_ADHOC_ON);
5383 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5384 // disable all periodic state machine
5385 pAdapter->StaCfg.bAutoReconnect = FALSE;
5386 // reset all mlme state machine
5387 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
5388 DBGPRINT(RT_DEBUG_TRACE, ("fOP_STATUS_MEDIA_STATE_CONNECTED \n"));
5389 if (pAdapter->CommonCfg.CentralChannel == 0)
5391 #ifdef DOT11_N_SUPPORT
5392 if (pAdapter->CommonCfg.PhyMode == PHY_11AN_MIXED)
5393 pAdapter->CommonCfg.CentralChannel = 36;
5395 #endif // DOT11_N_SUPPORT //
5396 pAdapter->CommonCfg.CentralChannel = 6;
5398 #ifdef DOT11_N_SUPPORT
5400 N_ChannelCheck(pAdapter);
5401 #endif // DOT11_N_SUPPORT //
5403 #ifdef DOT11_N_SUPPORT
5404 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
5405 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
5406 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_ABOVE)
5408 // 40MHz ,control channel at lower
5409 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5410 bbpValue &= (~0x18);
5412 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5413 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
5414 // RX : control channel at lower
5415 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
5416 bbpValue &= (~0x20);
5417 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
5419 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
5420 Value &= 0xfffffffe;
5421 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
5422 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel + 2;
5423 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
5424 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
5425 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
5426 pAdapter->CommonCfg.Channel,
5427 pAdapter->CommonCfg.CentralChannel));
5429 else if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
5430 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
5431 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_BELOW)
5433 // 40MHz ,control channel at upper
5434 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5435 bbpValue &= (~0x18);
5437 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5438 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
5439 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
5441 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
5443 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
5445 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
5446 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel - 2;
5447 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
5448 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
5449 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
5450 pAdapter->CommonCfg.Channel,
5451 pAdapter->CommonCfg.CentralChannel));
5454 #endif // DOT11_N_SUPPORT //
5457 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5458 bbpValue &= (~0x18);
5459 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5460 pAdapter->CommonCfg.BBPCurrentBW = BW_20;
5461 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.Channel, FALSE);
5462 AsicLockChannel(pAdapter, pAdapter->CommonCfg.Channel);
5463 DBGPRINT(RT_DEBUG_TRACE, ("BW_20, Channel(%d)\n", pAdapter->CommonCfg.Channel));
5465 // Enable Rx with promiscuous reception
5466 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, 0x3);
5467 // ASIC supporsts sniffer function with replacing RSSI with timestamp.
5468 //RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5470 //RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5472 RTMP_IO_READ32(pAdapter, BCN_TIME_CFG, &csr.word);
5473 csr.field.bBeaconGen = 0;
5474 csr.field.bTBTTEnable = 0;
5475 csr.field.TsfSyncMode = 0;
5476 RTMP_IO_WRITE32(pAdapter, BCN_TIME_CFG, csr.word);
5478 pAdapter->StaCfg.BssType = BSS_MONITOR;
5479 pAdapter->net_dev->type = ARPHRD_IEEE80211_PRISM; //ARPHRD_IEEE80211; // IEEE80211
5480 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(MONITOR)\n"));
5483 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
5484 pAdapter->StaCfg.WpaState = SS_NOTUSE;
5486 DBGPRINT(RT_DEBUG_TRACE, ("Set_NetworkType_Proc::(NetworkType=%d)\n", pAdapter->StaCfg.BssType));
5492 ==========================================================================
5494 Set Authentication mode
5496 TRUE if all parameters are OK, FALSE otherwise
5497 ==========================================================================
5499 INT Set_AuthMode_Proc(
5500 IN PRTMP_ADAPTER pAdapter,
5503 if ((strcmp(arg, "WEPAUTO") == 0) || (strcmp(arg, "wepauto") == 0))
5504 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeAutoSwitch;
5505 else if ((strcmp(arg, "OPEN") == 0) || (strcmp(arg, "open") == 0))
5506 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
5507 else if ((strcmp(arg, "SHARED") == 0) || (strcmp(arg, "shared") == 0))
5508 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
5509 else if ((strcmp(arg, "WPAPSK") == 0) || (strcmp(arg, "wpapsk") == 0))
5510 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
5511 else if ((strcmp(arg, "WPANONE") == 0) || (strcmp(arg, "wpanone") == 0))
5512 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
5513 else if ((strcmp(arg, "WPA2PSK") == 0) || (strcmp(arg, "wpa2psk") == 0))
5514 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
5515 #ifdef WPA_SUPPLICANT_SUPPORT
5516 else if ((strcmp(arg, "WPA") == 0) || (strcmp(arg, "wpa") == 0))
5517 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
5518 else if ((strcmp(arg, "WPA2") == 0) || (strcmp(arg, "wpa2") == 0))
5519 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
5520 #endif // WPA_SUPPLICANT_SUPPORT //
5524 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
5526 DBGPRINT(RT_DEBUG_TRACE, ("Set_AuthMode_Proc::(AuthMode=%d)\n", pAdapter->StaCfg.AuthMode));
5532 ==========================================================================
5536 TRUE if all parameters are OK, FALSE otherwise
5537 ==========================================================================
5539 INT Set_EncrypType_Proc(
5540 IN PRTMP_ADAPTER pAdapter,
5543 if ((strcmp(arg, "NONE") == 0) || (strcmp(arg, "none") == 0))
5545 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5546 return TRUE; // do nothing
5548 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
5549 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
5550 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
5552 else if ((strcmp(arg, "WEP") == 0) || (strcmp(arg, "wep") == 0))
5554 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5555 return TRUE; // do nothing
5557 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
5558 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
5559 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
5561 else if ((strcmp(arg, "TKIP") == 0) || (strcmp(arg, "tkip") == 0))
5563 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
5564 return TRUE; // do nothing
5566 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
5567 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
5568 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
5570 else if ((strcmp(arg, "AES") == 0) || (strcmp(arg, "aes") == 0))
5572 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
5573 return TRUE; // do nothing
5575 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
5576 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
5577 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
5582 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
5584 DBGPRINT(RT_DEBUG_TRACE, ("Set_EncrypType_Proc::(EncrypType=%d)\n", pAdapter->StaCfg.WepStatus));
5590 ==========================================================================
5594 TRUE if all parameters are OK, FALSE otherwise
5595 ==========================================================================
5597 INT Set_DefaultKeyID_Proc(
5598 IN PRTMP_ADAPTER pAdapter,
5603 KeyIdx = simple_strtol(arg, 0, 10);
5604 if((KeyIdx >= 1 ) && (KeyIdx <= 4))
5605 pAdapter->StaCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1 );
5607 return FALSE; //Invalid argument
5609 DBGPRINT(RT_DEBUG_TRACE, ("Set_DefaultKeyID_Proc::(DefaultKeyID=%d)\n", pAdapter->StaCfg.DefaultKeyId));
5615 ==========================================================================
5619 TRUE if all parameters are OK, FALSE otherwise
5620 ==========================================================================
5623 IN PRTMP_ADAPTER pAdapter,
5628 UCHAR CipherAlg=CIPHER_WEP64;
5630 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5631 return TRUE; // do nothing
5633 KeyLen = strlen(arg);
5637 case 5: //wep 40 Ascii type
5638 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
5639 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
5640 CipherAlg = CIPHER_WEP64;
5641 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
5643 case 10: //wep 40 Hex type
5644 for(i=0; i < KeyLen; i++)
5646 if( !isxdigit(*(arg+i)) )
5647 return FALSE; //Not Hex value;
5649 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
5650 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
5651 CipherAlg = CIPHER_WEP64;
5652 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
5654 case 13: //wep 104 Ascii type
5655 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
5656 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
5657 CipherAlg = CIPHER_WEP128;
5658 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
5660 case 26: //wep 104 Hex type
5661 for(i=0; i < KeyLen; i++)
5663 if( !isxdigit(*(arg+i)) )
5664 return FALSE; //Not Hex value;
5666 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
5667 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
5668 CipherAlg = CIPHER_WEP128;
5669 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
5671 default: //Invalid argument
5672 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::Invalid argument (=%s)\n", arg));
5676 pAdapter->SharedKey[BSS0][0].CipherAlg = CipherAlg;
5678 // Set keys (into ASIC)
5679 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5681 else // Old WEP stuff
5683 AsicAddSharedKeyEntry(pAdapter,
5686 pAdapter->SharedKey[BSS0][0].CipherAlg,
5687 pAdapter->SharedKey[BSS0][0].Key,
5695 ==========================================================================
5700 TRUE if all parameters are OK, FALSE otherwise
5701 ==========================================================================
5704 IN PRTMP_ADAPTER pAdapter,
5709 UCHAR CipherAlg=CIPHER_WEP64;
5711 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5712 return TRUE; // do nothing
5714 KeyLen = strlen(arg);
5718 case 5: //wep 40 Ascii type
5719 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
5720 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
5721 CipherAlg = CIPHER_WEP64;
5722 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
5724 case 10: //wep 40 Hex type
5725 for(i=0; i < KeyLen; i++)
5727 if( !isxdigit(*(arg+i)) )
5728 return FALSE; //Not Hex value;
5730 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
5731 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
5732 CipherAlg = CIPHER_WEP64;
5733 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
5735 case 13: //wep 104 Ascii type
5736 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
5737 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
5738 CipherAlg = CIPHER_WEP128;
5739 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
5741 case 26: //wep 104 Hex type
5742 for(i=0; i < KeyLen; i++)
5744 if( !isxdigit(*(arg+i)) )
5745 return FALSE; //Not Hex value;
5747 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
5748 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
5749 CipherAlg = CIPHER_WEP128;
5750 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
5752 default: //Invalid argument
5753 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::Invalid argument (=%s)\n", arg));
5756 pAdapter->SharedKey[BSS0][1].CipherAlg = CipherAlg;
5758 // Set keys (into ASIC)
5759 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5761 else // Old WEP stuff
5763 AsicAddSharedKeyEntry(pAdapter,
5766 pAdapter->SharedKey[BSS0][1].CipherAlg,
5767 pAdapter->SharedKey[BSS0][1].Key,
5775 ==========================================================================
5779 TRUE if all parameters are OK, FALSE otherwise
5780 ==========================================================================
5783 IN PRTMP_ADAPTER pAdapter,
5788 UCHAR CipherAlg=CIPHER_WEP64;
5790 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5791 return TRUE; // do nothing
5793 KeyLen = strlen(arg);
5797 case 5: //wep 40 Ascii type
5798 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
5799 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
5800 CipherAlg = CIPHER_WEP64;
5801 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
5803 case 10: //wep 40 Hex type
5804 for(i=0; i < KeyLen; i++)
5806 if( !isxdigit(*(arg+i)) )
5807 return FALSE; //Not Hex value;
5809 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
5810 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
5811 CipherAlg = CIPHER_WEP64;
5812 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
5814 case 13: //wep 104 Ascii type
5815 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
5816 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
5817 CipherAlg = CIPHER_WEP128;
5818 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
5820 case 26: //wep 104 Hex type
5821 for(i=0; i < KeyLen; i++)
5823 if( !isxdigit(*(arg+i)) )
5824 return FALSE; //Not Hex value;
5826 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
5827 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
5828 CipherAlg = CIPHER_WEP128;
5829 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
5831 default: //Invalid argument
5832 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::Invalid argument (=%s)\n", arg));
5835 pAdapter->SharedKey[BSS0][2].CipherAlg = CipherAlg;
5837 // Set keys (into ASIC)
5838 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5840 else // Old WEP stuff
5842 AsicAddSharedKeyEntry(pAdapter,
5845 pAdapter->SharedKey[BSS0][2].CipherAlg,
5846 pAdapter->SharedKey[BSS0][2].Key,
5854 ==========================================================================
5858 TRUE if all parameters are OK, FALSE otherwise
5859 ==========================================================================
5862 IN PRTMP_ADAPTER pAdapter,
5867 UCHAR CipherAlg=CIPHER_WEP64;
5869 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5870 return TRUE; // do nothing
5872 KeyLen = strlen(arg);
5876 case 5: //wep 40 Ascii type
5877 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
5878 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
5879 CipherAlg = CIPHER_WEP64;
5880 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
5882 case 10: //wep 40 Hex type
5883 for(i=0; i < KeyLen; i++)
5885 if( !isxdigit(*(arg+i)) )
5886 return FALSE; //Not Hex value;
5888 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
5889 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
5890 CipherAlg = CIPHER_WEP64;
5891 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
5893 case 13: //wep 104 Ascii type
5894 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
5895 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
5896 CipherAlg = CIPHER_WEP128;
5897 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
5899 case 26: //wep 104 Hex type
5900 for(i=0; i < KeyLen; i++)
5902 if( !isxdigit(*(arg+i)) )
5903 return FALSE; //Not Hex value;
5905 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
5906 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
5907 CipherAlg = CIPHER_WEP128;
5908 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
5910 default: //Invalid argument
5911 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::Invalid argument (=%s)\n", arg));
5914 pAdapter->SharedKey[BSS0][3].CipherAlg = CipherAlg;
5916 // Set keys (into ASIC)
5917 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5919 else // Old WEP stuff
5921 AsicAddSharedKeyEntry(pAdapter,
5924 pAdapter->SharedKey[BSS0][3].CipherAlg,
5925 pAdapter->SharedKey[BSS0][3].Key,
5934 ==========================================================================
5938 TRUE if all parameters are OK, FALSE otherwise
5939 ==========================================================================
5941 INT Set_WPAPSK_Proc(
5942 IN PRTMP_ADAPTER pAdapter,
5945 UCHAR keyMaterial[40];
5947 if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
5948 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
5949 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
5951 return TRUE; // do nothing
5953 DBGPRINT(RT_DEBUG_TRACE, ("Set_WPAPSK_Proc::(WPAPSK=%s)\n", arg));
5955 NdisZeroMemory(keyMaterial, 40);
5957 if ((strlen(arg) < 8) || (strlen(arg) > 64))
5959 DBGPRINT(RT_DEBUG_TRACE, ("Set failed!!(WPAPSK=%s), WPAPSK key-string required 8 ~ 64 characters \n", arg));
5963 if (strlen(arg) == 64)
5965 AtoH(arg, keyMaterial, 32);
5966 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
5971 PasswordHash((char *)arg, pAdapter->MlmeAux.Ssid, pAdapter->MlmeAux.SsidLen, keyMaterial);
5972 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
5977 if(pAdapter->StaCfg.BssType == BSS_ADHOC &&
5978 pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
5980 pAdapter->StaCfg.WpaState = SS_NOTUSE;
5984 // Start STA supplicant state machine
5985 pAdapter->StaCfg.WpaState = SS_START;
5992 ==========================================================================
5994 Set Power Saving mode
5996 TRUE if all parameters are OK, FALSE otherwise
5997 ==========================================================================
5999 INT Set_PSMode_Proc(
6000 IN PRTMP_ADAPTER pAdapter,
6003 if (pAdapter->StaCfg.BssType == BSS_INFRA)
6005 if ((strcmp(arg, "Max_PSP") == 0) ||
6006 (strcmp(arg, "max_psp") == 0) ||
6007 (strcmp(arg, "MAX_PSP") == 0))
6009 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6010 // to exclude certain situations.
6011 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6012 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeMAX_PSP;
6013 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeMAX_PSP;
6014 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6015 pAdapter->StaCfg.DefaultListenCount = 5;
6018 else if ((strcmp(arg, "Fast_PSP") == 0) ||
6019 (strcmp(arg, "fast_psp") == 0) ||
6020 (strcmp(arg, "FAST_PSP") == 0))
6022 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6023 // to exclude certain situations.
6024 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6025 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6026 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeFast_PSP;
6027 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeFast_PSP;
6028 pAdapter->StaCfg.DefaultListenCount = 3;
6030 else if ((strcmp(arg, "Legacy_PSP") == 0) ||
6031 (strcmp(arg, "legacy_psp") == 0) ||
6032 (strcmp(arg, "LEGACY_PSP") == 0))
6034 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6035 // to exclude certain situations.
6036 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6037 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6038 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeLegacy_PSP;
6039 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeLegacy_PSP;
6040 pAdapter->StaCfg.DefaultListenCount = 3;
6044 //Default Ndis802_11PowerModeCAM
6045 // clear PSM bit immediately
6046 MlmeSetPsmBit(pAdapter, PWR_ACTIVE);
6047 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6048 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6049 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
6050 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
6053 DBGPRINT(RT_DEBUG_TRACE, ("Set_PSMode_Proc::(PSMode=%ld)\n", pAdapter->StaCfg.WindowsPowerMode));
6062 #ifdef WPA_SUPPLICANT_SUPPORT
6064 ==========================================================================
6066 Set WpaSupport flag.
6068 0: Driver ignore wpa_supplicant.
6069 1: wpa_supplicant initiates scanning and AP selection.
6070 2: driver takes care of scanning, AP selection, and IEEE 802.11 association parameters.
6072 TRUE if all parameters are OK, FALSE otherwise
6073 ==========================================================================
6075 INT Set_Wpa_Support(
6076 IN PRTMP_ADAPTER pAd,
6080 if ( simple_strtol(arg, 0, 10) == 0)
6081 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
6082 else if ( simple_strtol(arg, 0, 10) == 1)
6083 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE;
6084 else if ( simple_strtol(arg, 0, 10) == 2)
6085 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE_WITH_WEB_UI;
6087 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
6089 DBGPRINT(RT_DEBUG_TRACE, ("Set_Wpa_Support::(WpaSupplicantUP=%d)\n", pAd->StaCfg.WpaSupplicantUP));
6093 #endif // WPA_SUPPLICANT_SUPPORT //
6097 ==========================================================================
6101 pAdapter Pointer to our adapter
6102 wrq Pointer to the ioctl argument
6109 1.) iwpriv ra0 mac 0 ==> read MAC where Addr=0x0
6110 2.) iwpriv ra0 mac 0=12 ==> write MAC where Addr=0x0, value=12
6111 ==========================================================================
6114 IN PRTMP_ADAPTER pAdapter,
6115 IN struct iwreq *wrq)
6123 UCHAR temp[16], temp2[16];
6124 UINT32 macValue = 0;
6128 memset(msg, 0x00, 1024);
6129 if (wrq->u.data.length > 1) //No parameters.
6131 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6134 //Parsing Read or Write
6139 if ((value = rtstrchr(this_char, '=')) != NULL)
6142 if (!value || !*value)
6145 if(strlen(this_char) > 4)
6148 j = strlen(this_char);
6151 if(this_char[j] > 'f' || this_char[j] < '0')
6156 k = j = strlen(this_char);
6159 this_char[4-k+j] = this_char[j];
6163 this_char[3-k++]='0';
6166 if(strlen(this_char) == 4)
6168 AtoH(this_char, temp, 2);
6169 macAddr = *temp*256 + temp[1];
6170 if (macAddr < 0xFFFF)
6172 RTMP_IO_READ32(pAdapter, macAddr, &macValue);
6173 DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%lx, MacValue=%x\n", macAddr, macValue));
6174 sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr , macValue);
6177 {//Invalid parametes, so default printk all bbp
6184 memcpy(&temp2, value, strlen(value));
6185 temp2[strlen(value)] = '\0';
6188 if((strlen(this_char) > 4) || strlen(temp2) > 8)
6191 j = strlen(this_char);
6194 if(this_char[j] > 'f' || this_char[j] < '0')
6201 if(temp2[j] > 'f' || temp2[j] < '0')
6206 k = j = strlen(this_char);
6209 this_char[4-k+j] = this_char[j];
6213 this_char[3-k++]='0';
6217 k = j = strlen(temp2);
6220 temp2[8-k+j] = temp2[j];
6228 AtoH(this_char, temp, 2);
6229 macAddr = *temp*256 + temp[1];
6231 AtoH(temp2, temp, 4);
6232 macValue = *temp*256*256*256 + temp[1]*256*256 + temp[2]*256 + temp[3];
6235 if (macAddr == (HW_DEBUG_SETTING_BASE + 4))
6237 // 0x2bf4: byte0 non-zero: enable R17 tuning, 0: disable R17 tuning
6238 if (macValue & 0x000000ff)
6240 pAdapter->BbpTuning.bEnable = TRUE;
6241 DBGPRINT(RT_DEBUG_TRACE,("turn on R17 tuning\n"));
6246 pAdapter->BbpTuning.bEnable = FALSE;
6247 R66 = 0x26 + GET_LNA_GAIN(pAdapter);
6248 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R66, (0x26 + GET_LNA_GAIN(pAdapter)));
6249 DBGPRINT(RT_DEBUG_TRACE,("turn off R17 tuning, restore to 0x%02x\n", R66));
6254 DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%02lx, MacValue=0x%x\n", macAddr, macValue));
6256 RTMP_IO_WRITE32(pAdapter, macAddr, macValue);
6257 sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr, macValue);
6262 if(strlen(msg) == 1)
6263 sprintf(msg+strlen(msg), "===>Error command format!");
6265 // Copy the information into the user buffer
6266 wrq->u.data.length = strlen(msg);
6267 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6269 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlMAC\n\n"));
6273 ==========================================================================
6277 pAdapter Pointer to our adapter
6278 wrq Pointer to the ioctl argument
6285 1.) iwpriv ra0 e2p 0 ==> read E2PROM where Addr=0x0
6286 2.) iwpriv ra0 e2p 0=1234 ==> write E2PROM where Addr=0x0, value=1234
6287 ==========================================================================
6289 VOID RTMPIoctlE2PROM(
6290 IN PRTMP_ADAPTER pAdapter,
6291 IN struct iwreq *wrq)
6299 UCHAR temp[16], temp2[16];
6304 memset(msg, 0x00, 1024);
6305 if (wrq->u.data.length > 1) //No parameters.
6307 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6310 //Parsing Read or Write
6317 if ((value = rtstrchr(this_char, '=')) != NULL)
6320 if (!value || !*value)
6324 if(strlen(this_char) > 4)
6327 j = strlen(this_char);
6330 if(this_char[j] > 'f' || this_char[j] < '0')
6335 k = j = strlen(this_char);
6338 this_char[4-k+j] = this_char[j];
6342 this_char[3-k++]='0';
6345 if(strlen(this_char) == 4)
6347 AtoH(this_char, temp, 2);
6348 eepAddr = *temp*256 + temp[1];
6349 if (eepAddr < 0xFFFF)
6351 RT28xx_EEPROM_READ16(pAdapter, eepAddr, eepValue);
6352 sprintf(msg+strlen(msg), "[0x%04X]:0x%04X ", eepAddr , eepValue);
6355 {//Invalid parametes, so default printk all bbp
6362 memcpy(&temp2, value, strlen(value));
6363 temp2[strlen(value)] = '\0';
6366 if((strlen(this_char) > 4) || strlen(temp2) > 8)
6369 j = strlen(this_char);
6372 if(this_char[j] > 'f' || this_char[j] < '0')
6378 if(temp2[j] > 'f' || temp2[j] < '0')
6383 k = j = strlen(this_char);
6386 this_char[4-k+j] = this_char[j];
6390 this_char[3-k++]='0';
6394 k = j = strlen(temp2);
6397 temp2[4-k+j] = temp2[j];
6404 AtoH(this_char, temp, 2);
6405 eepAddr = *temp*256 + temp[1];
6407 AtoH(temp2, temp, 2);
6408 eepValue = *temp*256 + temp[1];
6410 RT28xx_EEPROM_WRITE16(pAdapter, eepAddr, eepValue);
6411 sprintf(msg+strlen(msg), "[0x%02X]:%02X ", eepAddr, eepValue);
6415 if(strlen(msg) == 1)
6416 sprintf(msg+strlen(msg), "===>Error command format!");
6419 // Copy the information into the user buffer
6420 wrq->u.data.length = strlen(msg);
6421 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6423 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlE2PROM\n"));
6430 INT Set_TGnWifiTest_Proc(
6431 IN PRTMP_ADAPTER pAd,
6434 if (simple_strtol(arg, 0, 10) == 0)
6435 pAd->StaCfg.bTGnWifiTest = FALSE;
6437 pAd->StaCfg.bTGnWifiTest = TRUE;
6439 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_TGnWifiTest_Proc::(bTGnWifiTest=%d)\n", pAd->StaCfg.bTGnWifiTest));
6443 INT Set_LongRetryLimit_Proc(
6444 IN PRTMP_ADAPTER pAdapter,
6447 TX_RTY_CFG_STRUC tx_rty_cfg;
6448 UCHAR LongRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
6450 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
6451 tx_rty_cfg.field.LongRtyLimit = LongRetryLimit;
6452 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
6453 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_LongRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
6457 INT Set_ShortRetryLimit_Proc(
6458 IN PRTMP_ADAPTER pAdapter,
6461 TX_RTY_CFG_STRUC tx_rty_cfg;
6462 UCHAR ShortRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
6464 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
6465 tx_rty_cfg.field.ShortRtyLimit = ShortRetryLimit;
6466 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
6467 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_ShortRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
6471 INT Show_Adhoc_MacTable_Proc(
6472 IN PRTMP_ADAPTER pAd,
6477 sprintf(extra, "\n");
6479 #ifdef DOT11_N_SUPPORT
6480 sprintf(extra + strlen(extra), "HT Operating Mode : %d\n", pAd->CommonCfg.AddHTInfo.AddHtInfo2.OperaionMode);
6481 #endif // DOT11_N_SUPPORT //
6483 sprintf(extra + strlen(extra), "\n%-19s%-4s%-4s%-7s%-7s%-7s%-10s%-6s%-6s%-6s%-6s\n",
6484 "MAC", "AID", "BSS", "RSSI0", "RSSI1", "RSSI2", "PhMd", "BW", "MCS", "SGI", "STBC");
6486 for (i=1; i<MAX_LEN_OF_MAC_TABLE; i++)
6488 PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
6490 if (strlen(extra) > (IW_PRIV_SIZE_MASK - 30))
6492 if ((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
6494 sprintf(extra + strlen(extra), "%02X:%02X:%02X:%02X:%02X:%02X ",
6495 pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
6496 pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5]);
6497 sprintf(extra + strlen(extra), "%-4d", (int)pEntry->Aid);
6498 sprintf(extra + strlen(extra), "%-4d", (int)pEntry->apidx);
6499 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi0);
6500 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi1);
6501 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi2);
6502 sprintf(extra + strlen(extra), "%-10s", GetPhyMode(pEntry->HTPhyMode.field.MODE));
6503 sprintf(extra + strlen(extra), "%-6s", GetBW(pEntry->HTPhyMode.field.BW));
6504 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.MCS);
6505 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.ShortGI);
6506 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.STBC);
6507 sprintf(extra + strlen(extra), "%-10d, %d, %d%%\n", pEntry->DebugFIFOCount, pEntry->DebugTxCount,
6508 (pEntry->DebugTxCount) ? ((pEntry->DebugTxCount-pEntry->DebugFIFOCount)*100/pEntry->DebugTxCount) : 0);
6509 sprintf(extra, "%s\n", extra);