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 /* --- sub-ioctls relations --- */
94 IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
97 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
101 IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
105 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
109 { RTPRIV_IOCTL_STATISTICS,
110 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
112 { RTPRIV_IOCTL_GSITESURVEY,
113 0, IW_PRIV_TYPE_CHAR | 1024,
120 IN PRTMP_ADAPTER pAdapter,
124 INT Set_WmmCapable_Proc(
125 IN PRTMP_ADAPTER pAd,
129 INT Set_NetworkType_Proc(
130 IN PRTMP_ADAPTER pAdapter,
133 INT Set_AuthMode_Proc(
134 IN PRTMP_ADAPTER pAdapter,
137 INT Set_EncrypType_Proc(
138 IN PRTMP_ADAPTER pAdapter,
141 INT Set_DefaultKeyID_Proc(
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,
162 IN PRTMP_ADAPTER pAdapter,
167 IN PRTMP_ADAPTER pAdapter,
171 IN PRTMP_ADAPTER pAd,
177 IN PRTMP_ADAPTER pAdapter,
178 IN struct iwreq *wrq);
180 VOID RTMPIoctlE2PROM(
181 IN PRTMP_ADAPTER pAdapter,
182 IN struct iwreq *wrq);
186 IN PRTMP_ADAPTER pAdapter,
187 IN struct iwreq *wrq);
192 NDIS_STATUS RTMPWPANoneAddKeyProc(
193 IN PRTMP_ADAPTER pAd,
196 INT Set_FragTest_Proc(
197 IN PRTMP_ADAPTER pAdapter,
200 INT Set_TGnWifiTest_Proc(
201 IN PRTMP_ADAPTER pAd,
204 INT Set_LongRetryLimit_Proc(
205 IN PRTMP_ADAPTER pAdapter,
208 INT Set_ShortRetryLimit_Proc(
209 IN PRTMP_ADAPTER pAdapter,
214 INT (*set_proc)(PRTMP_ADAPTER pAdapter, PUCHAR arg);
215 } *PRTMP_PRIVATE_SET_PROC, RTMP_PRIVATE_SUPPORT_PROC[] = {
216 {"DriverVersion", Set_DriverVersion_Proc},
217 {"CountryRegion", Set_CountryRegion_Proc},
218 {"CountryRegionABand", Set_CountryRegionABand_Proc},
219 {"SSID", Set_SSID_Proc},
220 {"WirelessMode", Set_WirelessMode_Proc},
221 {"TxBurst", Set_TxBurst_Proc},
222 {"TxPreamble", Set_TxPreamble_Proc},
223 {"TxPower", Set_TxPower_Proc},
224 {"Channel", Set_Channel_Proc},
225 {"BGProtection", Set_BGProtection_Proc},
226 {"RTSThreshold", Set_RTSThreshold_Proc},
227 {"FragThreshold", Set_FragThreshold_Proc},
228 {"HtBw", Set_HtBw_Proc},
229 {"HtMcs", Set_HtMcs_Proc},
230 {"HtGi", Set_HtGi_Proc},
231 {"HtOpMode", Set_HtOpMode_Proc},
232 {"HtExtcha", Set_HtExtcha_Proc},
233 {"HtMpduDensity", Set_HtMpduDensity_Proc},
234 {"HtBaWinSize", Set_HtBaWinSize_Proc},
235 {"HtRdg", Set_HtRdg_Proc},
236 {"HtAmsdu", Set_HtAmsdu_Proc},
237 {"HtAutoBa", Set_HtAutoBa_Proc},
238 {"HtBaDecline", Set_BADecline_Proc},
239 {"HtProtect", Set_HtProtect_Proc},
240 {"HtMimoPs", Set_HtMimoPs_Proc},
241 #ifdef AGGREGATION_SUPPORT
242 {"PktAggregate", Set_PktAggregate_Proc},
246 {"WmmCapable", Set_WmmCapable_Proc},
248 {"IEEE80211H", Set_IEEE80211H_Proc},
249 {"NetworkType", Set_NetworkType_Proc},
250 {"AuthMode", Set_AuthMode_Proc},
251 {"EncrypType", Set_EncrypType_Proc},
252 {"DefaultKeyID", Set_DefaultKeyID_Proc},
253 {"Key1", Set_Key1_Proc},
254 {"Key2", Set_Key2_Proc},
255 {"Key3", Set_Key3_Proc},
256 {"Key4", Set_Key4_Proc},
257 {"WPAPSK", Set_WPAPSK_Proc},
258 {"ResetCounter", Set_ResetStatCounter_Proc},
259 {"PSMode", Set_PSMode_Proc},
261 {"Debug", Set_Debug_Proc},
263 {"WpaSupport", Set_Wpa_Support},
264 {"FixedTxMode", Set_FixedTxMode_Proc},
265 {"TGnWifiTest", Set_TGnWifiTest_Proc},
266 {"ForceGF", Set_ForceGF_Proc},
267 {"LongRetry", Set_LongRetryLimit_Proc},
268 {"ShortRetry", Set_ShortRetryLimit_Proc},
269 //2008/09/11:KH add to support efuse<--
271 {"efuseFreeNumber", set_eFuseGetFreeBlockCount_Proc},
272 {"efuseDump", set_eFusedump_Proc},
273 {"efuseLoadFromBin", set_eFuseLoadFromBin_Proc},
275 //2008/09/11:KH add to support efuse-->
281 IN PRTMP_ADAPTER pAd,
282 IN PNDIS_802_11_KEY pKey)
285 MAC_TABLE_ENTRY *pEntry;
287 DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey ------>\n"));
289 if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
291 if (pKey->KeyIndex & 0x80000000)
293 if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
295 NdisZeroMemory(pAd->StaCfg.PMK, 32);
296 NdisMoveMemory(pAd->StaCfg.PMK, pKey->KeyMaterial, pKey->KeyLength);
300 NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));
301 pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
302 NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, pKey->KeyMaterial, LEN_TKIP_EK);
304 if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
306 NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
307 NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
311 NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
312 NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
315 // Decide its ChiperAlg
316 if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
317 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
318 else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)
319 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
321 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_NONE;
323 // Update these related information to MAC_TABLE_ENTRY
324 pEntry = &pAd->MacTab.Content[BSSID_WCID];
325 NdisMoveMemory(pEntry->PairwiseKey.Key, pAd->SharedKey[BSS0][0].Key, LEN_TKIP_EK);
326 NdisMoveMemory(pEntry->PairwiseKey.RxMic, pAd->SharedKey[BSS0][0].RxMic, LEN_TKIP_RXMICK);
327 NdisMoveMemory(pEntry->PairwiseKey.TxMic, pAd->SharedKey[BSS0][0].TxMic, LEN_TKIP_TXMICK);
328 pEntry->PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;
330 // Update pairwise key information to ASIC Shared Key Table
331 AsicAddSharedKeyEntry(pAd,
334 pAd->SharedKey[BSS0][0].CipherAlg,
335 pAd->SharedKey[BSS0][0].Key,
336 pAd->SharedKey[BSS0][0].TxMic,
337 pAd->SharedKey[BSS0][0].RxMic);
339 // Update ASIC WCID attribute table and IVEIV table
340 RTMPAddWcidAttributeEntry(pAd,
343 pAd->SharedKey[BSS0][0].CipherAlg,
346 if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
348 // set 802.1x port control
349 //pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
350 STA_PORT_SECURED(pAd);
352 // Indicate Connected for GUI
353 pAd->IndicateMediaState = NdisMediaStateConnected;
359 pAd->StaCfg.DefaultKeyId = (pKey->KeyIndex & 0xFF);
360 NdisZeroMemory(&pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId], sizeof(CIPHER_KEY));
361 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].KeyLen = LEN_TKIP_EK;
362 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key, pKey->KeyMaterial, LEN_TKIP_EK);
364 if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
366 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
367 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
371 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
372 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
375 // Update Shared Key CipherAlg
376 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_NONE;
377 if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
378 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_TKIP;
379 else if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)
380 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_AES;
382 // Update group key information to ASIC Shared Key Table
383 AsicAddSharedKeyEntry(pAd,
385 pAd->StaCfg.DefaultKeyId,
386 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
387 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key,
388 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic,
389 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic);
391 // Update ASIC WCID attribute table and IVEIV table
392 RTMPAddWcidAttributeEntry(pAd,
394 pAd->StaCfg.DefaultKeyId,
395 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
398 // set 802.1x port control
399 //pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
400 STA_PORT_SECURED(pAd);
402 // Indicate Connected for GUI
403 pAd->IndicateMediaState = NdisMediaStateConnected;
406 else // dynamic WEP from wpa_supplicant
411 if(pKey->KeyLength == 32)
414 KeyIdx = pKey->KeyIndex & 0x0fffffff;
418 // it is a default shared key, for Pairwise key setting
419 if (pKey->KeyIndex & 0x80000000)
421 pEntry = MacTableLookup(pAd, pKey->BSSID);
425 DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey: Set Pair-wise Key\n"));
427 // set key material and key length
428 pEntry->PairwiseKey.KeyLen = (UCHAR)pKey->KeyLength;
429 NdisMoveMemory(pEntry->PairwiseKey.Key, &pKey->KeyMaterial, pKey->KeyLength);
432 if (pKey->KeyLength == 5)
433 pEntry->PairwiseKey.CipherAlg = CIPHER_WEP64;
435 pEntry->PairwiseKey.CipherAlg = CIPHER_WEP128;
437 // Add Pair-wise key to Asic
438 AsicAddPairwiseKeyEntry(
442 &pEntry->PairwiseKey);
444 // update WCID attribute table and IVEIV table for this entry
445 RTMPAddWcidAttributeEntry(
448 KeyIdx, // The value may be not zero
449 pEntry->PairwiseKey.CipherAlg,
456 // Default key for tx (shared key)
457 pAd->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
459 // set key material and key length
460 pAd->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pKey->KeyLength;
461 NdisMoveMemory(pAd->SharedKey[BSS0][KeyIdx].Key, &pKey->KeyMaterial, pKey->KeyLength);
464 if (pKey->KeyLength == 5)
465 pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP64;
467 pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP128;
469 CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg;
470 Key = pAd->SharedKey[BSS0][KeyIdx].Key;
472 // Set Group key material to Asic
473 AsicAddSharedKeyEntry(pAd, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
475 // Update WCID attribute table and IVEIV table for this group key table
476 RTMPAddWcidAttributeEntry(pAd, BSS0, KeyIdx, CipherAlg, NULL);
485 char * rtstrchr(const char * s, int c)
487 for(; *s != (char) c; ++s)
494 This is required for LinEX2004/kernel2.6.7 to provide iwlist scanning function
498 rt_ioctl_giwname(struct net_device *dev,
499 struct iw_request_info *info,
500 char *name, char *extra)
502 // PRTMP_ADAPTER pAdapter = dev->ml_priv;
505 strncpy(name, "RT2870 Wireless", IFNAMSIZ);
510 int rt_ioctl_siwfreq(struct net_device *dev,
511 struct iw_request_info *info,
512 struct iw_freq *freq, char *extra)
514 PRTMP_ADAPTER pAdapter = dev->ml_priv;
517 //check if the interface is down
518 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
520 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
528 if((freq->e == 0) && (freq->m <= 1000))
529 chan = freq->m; // Setting by channel number
531 MAP_KHZ_TO_CHANNEL_ID( (freq->m /100) , chan); // Setting by frequency - search the table , like 2.412G, 2.422G,
533 if (ChannelSanity(pAdapter, chan) == TRUE)
535 pAdapter->CommonCfg.Channel = chan;
536 DBGPRINT(RT_DEBUG_ERROR, ("==>rt_ioctl_siwfreq::SIOCSIWFREQ[cmd=0x%x] (Channel=%d)\n", SIOCSIWFREQ, pAdapter->CommonCfg.Channel));
543 int rt_ioctl_giwfreq(struct net_device *dev,
544 struct iw_request_info *info,
545 struct iw_freq *freq, char *extra)
547 VIRTUAL_ADAPTER *pVirtualAd = NULL;
548 PRTMP_ADAPTER pAdapter;
552 if (dev->priv_flags == INT_MAIN)
554 pAdapter = dev->ml_priv;
558 pVirtualAd = dev->ml_priv;
559 pAdapter = pVirtualAd->RtmpDev->ml_priv;
562 if (pAdapter == NULL)
564 /* if 1st open fail, pAd will be free;
565 So the net_dev->ml_priv will be NULL in 2rd open */
569 ch = pAdapter->CommonCfg.Channel;
571 DBGPRINT(RT_DEBUG_TRACE,("==>rt_ioctl_giwfreq %d\n", ch));
573 MAP_CHANNEL_ID_TO_KHZ(ch, m);
579 int rt_ioctl_siwmode(struct net_device *dev,
580 struct iw_request_info *info,
581 __u32 *mode, char *extra)
583 PRTMP_ADAPTER pAdapter = dev->ml_priv;
585 //check if the interface is down
586 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
588 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
595 Set_NetworkType_Proc(pAdapter, "Adhoc");
598 Set_NetworkType_Proc(pAdapter, "Infra");
600 case IW_MODE_MONITOR:
601 Set_NetworkType_Proc(pAdapter, "Monitor");
604 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_siwmode::SIOCSIWMODE (unknown %d)\n", *mode));
608 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
609 pAdapter->StaCfg.WpaState = SS_NOTUSE;
614 int rt_ioctl_giwmode(struct net_device *dev,
615 struct iw_request_info *info,
616 __u32 *mode, char *extra)
618 PRTMP_ADAPTER pAdapter = dev->ml_priv;
620 if (ADHOC_ON(pAdapter))
621 *mode = IW_MODE_ADHOC;
622 else if (INFRA_ON(pAdapter))
623 *mode = IW_MODE_INFRA;
624 else if (MONITOR_ON(pAdapter))
626 *mode = IW_MODE_MONITOR;
629 *mode = IW_MODE_AUTO;
631 DBGPRINT(RT_DEBUG_TRACE, ("==>rt_ioctl_giwmode(mode=%d)\n", *mode));
635 int rt_ioctl_siwsens(struct net_device *dev,
636 struct iw_request_info *info,
637 char *name, char *extra)
639 PRTMP_ADAPTER pAdapter = dev->ml_priv;
641 //check if the interface is down
642 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
644 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
651 int rt_ioctl_giwsens(struct net_device *dev,
652 struct iw_request_info *info,
653 char *name, char *extra)
658 int rt_ioctl_giwrange(struct net_device *dev,
659 struct iw_request_info *info,
660 struct iw_point *data, char *extra)
662 PRTMP_ADAPTER pAdapter = dev->ml_priv;
664 struct iw_range *range = (struct iw_range *) extra;
668 DBGPRINT(RT_DEBUG_TRACE ,("===>rt_ioctl_giwrange\n"));
669 data->length = sizeof(struct iw_range);
670 memset(range, 0, sizeof(struct iw_range));
672 range->txpower_capa = IW_TXPOW_DBM;
674 if (INFRA_ON(pAdapter)||ADHOC_ON(pAdapter))
676 range->min_pmp = 1 * 1024;
677 range->max_pmp = 65535 * 1024;
678 range->min_pmt = 1 * 1024;
679 range->max_pmt = 1000 * 1024;
680 range->pmp_flags = IW_POWER_PERIOD;
681 range->pmt_flags = IW_POWER_TIMEOUT;
682 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT |
683 IW_POWER_UNICAST_R | IW_POWER_ALL_R;
686 range->we_version_compiled = WIRELESS_EXT;
687 range->we_version_source = 14;
689 range->retry_capa = IW_RETRY_LIMIT;
690 range->retry_flags = IW_RETRY_LIMIT;
691 range->min_retry = 0;
692 range->max_retry = 255;
694 range->num_channels = pAdapter->ChannelListNum;
697 for (i = 1; i <= range->num_channels; i++)
700 range->freq[val].i = pAdapter->ChannelList[i-1].Channel;
701 MAP_CHANNEL_ID_TO_KHZ(pAdapter->ChannelList[i-1].Channel, m);
702 range->freq[val].m = m * 100; /* HZ */
704 range->freq[val].e = 1;
706 if (val == IW_MAX_FREQUENCIES)
709 range->num_frequency = val;
711 range->max_qual.qual = 100; /* what is correct max? This was not
712 * documented exactly. At least
713 * 69 has been observed. */
714 range->max_qual.level = 0; /* dB */
715 range->max_qual.noise = 0; /* dB */
717 /* What would be suitable values for "average/typical" qual? */
718 range->avg_qual.qual = 20;
719 range->avg_qual.level = -60;
720 range->avg_qual.noise = -95;
721 range->sensitivity = 3;
723 range->max_encoding_tokens = NR_WEP_KEYS;
724 range->num_encoding_sizes = 2;
725 range->encoding_size[0] = 5;
726 range->encoding_size[1] = 13;
729 range->max_rts = 2347;
730 range->min_frag = 256;
731 range->max_frag = 2346;
733 #if WIRELESS_EXT > 17
734 /* IW_ENC_CAPA_* bit field */
735 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
736 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
742 int rt_ioctl_siwap(struct net_device *dev,
743 struct iw_request_info *info,
744 struct sockaddr *ap_addr, char *extra)
746 PRTMP_ADAPTER pAdapter = dev->ml_priv;
747 NDIS_802_11_MAC_ADDRESS Bssid;
749 //check if the interface is down
750 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
752 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
756 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
758 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
759 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
762 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
763 // this request, because this request is initiated by NDIS.
764 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
765 // Prevent to connect AP again in STAMlmePeriodicExec
766 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
768 memset(Bssid, 0, MAC_ADDR_LEN);
769 memcpy(Bssid, ap_addr->sa_data, MAC_ADDR_LEN);
770 MlmeEnqueue(pAdapter,
771 MLME_CNTL_STATE_MACHINE,
773 sizeof(NDIS_802_11_MAC_ADDRESS),
776 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCSIWAP %02x:%02x:%02x:%02x:%02x:%02x\n",
777 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
782 int rt_ioctl_giwap(struct net_device *dev,
783 struct iw_request_info *info,
784 struct sockaddr *ap_addr, char *extra)
786 PRTMP_ADAPTER pAdapter = dev->ml_priv;
788 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
790 ap_addr->sa_family = ARPHRD_ETHER;
791 memcpy(ap_addr->sa_data, &pAdapter->CommonCfg.Bssid, ETH_ALEN);
794 else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
796 ap_addr->sa_family = ARPHRD_ETHER;
797 memcpy(ap_addr->sa_data, &pAdapter->MlmeAux.Bssid, ETH_ALEN);
801 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIWAP(=EMPTY)\n"));
809 * Units are in db above the noise floor. That means the
810 * rssi values reported in the tx/rx descriptors in the
811 * driver are the SNR expressed in db.
813 * If you assume that the noise floor is -95, which is an
814 * excellent assumption 99.5 % of the time, then you can
815 * derive the absolute signal level (i.e. -95 + rssi).
816 * There are some other slight factors to take into account
817 * depending on whether the rssi measurement is from 11b,
818 * 11g, or 11a. These differences are at most 2db and
821 * NB: various calculations are based on the orinoco/wavelan
822 * drivers for compatibility
824 static void set_quality(PRTMP_ADAPTER pAdapter,
825 struct iw_quality *iq,
832 ChannelQuality = 100;
833 else if (rssi >= -80) // between -50 ~ -80dbm
834 ChannelQuality = (__u8)(24 + ((rssi + 80) * 26)/10);
835 else if (rssi >= -90) // between -80 ~ -90dbm
836 ChannelQuality = (__u8)((rssi + 90) * 26)/10;
840 iq->qual = (__u8)ChannelQuality;
842 iq->level = (__u8)(rssi);
843 iq->noise = (pAdapter->BbpWriteLatch[66] > pAdapter->BbpTuning.FalseCcaUpperThreshold) ? ((__u8)pAdapter->BbpTuning.FalseCcaUpperThreshold) : ((__u8) pAdapter->BbpWriteLatch[66]); // noise level (dBm)
844 iq->noise += 256 - 143;
845 iq->updated = pAdapter->iw_stats.qual.updated;
848 int rt_ioctl_iwaplist(struct net_device *dev,
849 struct iw_request_info *info,
850 struct iw_point *data, char *extra)
852 PRTMP_ADAPTER pAdapter = dev->ml_priv;
854 struct sockaddr addr[IW_MAX_AP];
855 struct iw_quality qual[IW_MAX_AP];
858 //check if the interface is down
859 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
861 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
867 for (i = 0; i <IW_MAX_AP ; i++)
869 if (i >= pAdapter->ScanTab.BssNr)
871 addr[i].sa_family = ARPHRD_ETHER;
872 memcpy(addr[i].sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
873 set_quality(pAdapter, &qual[i], pAdapter->ScanTab.BssEntry[i].Rssi);
876 memcpy(extra, &addr, i*sizeof(addr[0]));
877 data->flags = 1; /* signal quality present (sort of) */
878 memcpy(extra + i*sizeof(addr[0]), &qual, i*sizeof(qual[i]));
884 int rt_ioctl_siwscan(struct net_device *dev,
885 struct iw_request_info *info,
886 struct iw_point *data, char *extra)
888 PRTMP_ADAPTER pAdapter = dev->ml_priv;
891 int Status = NDIS_STATUS_SUCCESS;
893 //check if the interface is down
894 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
896 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
900 if (MONITOR_ON(pAdapter))
902 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
907 if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
909 pAdapter->StaCfg.WpaSupplicantScanCount++;
912 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
913 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
918 if ((pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE) &&
919 (pAdapter->StaCfg.WpaSupplicantScanCount > 3))
921 DBGPRINT(RT_DEBUG_TRACE, ("!!! WpaSupplicantScanCount > 3\n"));
922 Status = NDIS_STATUS_SUCCESS;
926 if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
927 ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
928 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) &&
929 (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
931 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
932 Status = NDIS_STATUS_SUCCESS;
936 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
938 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
939 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
942 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
943 // this request, because this request is initiated by NDIS.
944 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
945 // Reset allowed scan retries
946 pAdapter->StaCfg.ScanCnt = 0;
947 pAdapter->StaCfg.LastScanTime = Now;
949 MlmeEnqueue(pAdapter,
950 MLME_CNTL_STATE_MACHINE,
951 OID_802_11_BSSID_LIST_SCAN,
955 Status = NDIS_STATUS_SUCCESS;
956 RT28XX_MLME_HANDLER(pAdapter);
961 int rt_ioctl_giwscan(struct net_device *dev,
962 struct iw_request_info *info,
963 struct iw_point *data, char *extra)
966 PRTMP_ADAPTER pAdapter = dev->ml_priv;
968 char *current_ev = extra, *previous_ev = extra;
970 char *current_val, custom[MAX_CUSTOM_LEN] = {0};
973 #endif // IWEVGENIE //
976 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
979 * Still scanning, indicate the caller should try again.
984 if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
986 pAdapter->StaCfg.WpaSupplicantScanCount = 0;
989 if (pAdapter->ScanTab.BssNr == 0)
995 #if WIRELESS_EXT >= 17
996 if (data->length > 0)
997 end_buf = extra + data->length;
999 end_buf = extra + IW_SCAN_MAX_DATA;
1001 end_buf = extra + IW_SCAN_MAX_DATA;
1004 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
1006 if (current_ev >= end_buf)
1008 #if WIRELESS_EXT >= 17
1016 //================================
1017 memset(&iwe, 0, sizeof(iwe));
1018 iwe.cmd = SIOCGIWAP;
1019 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1020 memcpy(iwe.u.ap_addr.sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, ETH_ALEN);
1022 previous_ev = current_ev;
1023 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
1024 if (current_ev == previous_ev)
1025 #if WIRELESS_EXT >= 17
1033 it will show scanned AP's WirelessMode .
1042 memset(&iwe, 0, sizeof(iwe));
1043 iwe.cmd = SIOCGIWNAME;
1047 PBSS_ENTRY pBssEntry=&pAdapter->ScanTab.BssEntry[i];
1048 BOOLEAN isGonly=FALSE;
1051 if (pBssEntry->Channel>14)
1053 if (pBssEntry->HtCapabilityLen!=0)
1054 strcpy(iwe.u.name,"802.11a/n");
1056 strcpy(iwe.u.name,"802.11a");
1061 if one of non B mode rate is set supported rate . it mean G only.
1063 for (rateCnt=0;rateCnt<pBssEntry->SupRateLen;rateCnt++)
1066 6Mbps(140) 9Mbps(146) and >=12Mbps(152) are supported rate , it mean G only.
1068 if (pBssEntry->SupRate[rateCnt]==140 || pBssEntry->SupRate[rateCnt]==146 || pBssEntry->SupRate[rateCnt]>=152)
1072 for (rateCnt=0;rateCnt<pBssEntry->ExtRateLen;rateCnt++)
1074 if (pBssEntry->ExtRate[rateCnt]==140 || pBssEntry->ExtRate[rateCnt]==146 || pBssEntry->ExtRate[rateCnt]>=152)
1079 if (pBssEntry->HtCapabilityLen!=0)
1082 strcpy(iwe.u.name,"802.11g/n");
1084 strcpy(iwe.u.name,"802.11b/g/n");
1089 strcpy(iwe.u.name,"802.11g");
1092 if (pBssEntry->SupRateLen==4 && pBssEntry->ExtRateLen==0)
1093 strcpy(iwe.u.name,"802.11b");
1095 strcpy(iwe.u.name,"802.11b/g");
1101 previous_ev = current_ev;
1102 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
1103 if (current_ev == previous_ev)
1104 #if WIRELESS_EXT >= 17
1111 //================================
1112 memset(&iwe, 0, sizeof(iwe));
1113 iwe.cmd = SIOCGIWESSID;
1114 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].SsidLen;
1115 iwe.u.data.flags = 1;
1117 previous_ev = current_ev;
1118 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pAdapter->ScanTab.BssEntry[i].Ssid);
1119 if (current_ev == previous_ev)
1120 #if WIRELESS_EXT >= 17
1127 //================================
1128 memset(&iwe, 0, sizeof(iwe));
1129 iwe.cmd = SIOCGIWMODE;
1130 if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11IBSS)
1132 iwe.u.mode = IW_MODE_ADHOC;
1134 else if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11Infrastructure)
1136 iwe.u.mode = IW_MODE_INFRA;
1140 iwe.u.mode = IW_MODE_AUTO;
1142 iwe.len = IW_EV_UINT_LEN;
1144 previous_ev = current_ev;
1145 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
1146 if (current_ev == previous_ev)
1147 #if WIRELESS_EXT >= 17
1153 //Channel and Frequency
1154 //================================
1155 memset(&iwe, 0, sizeof(iwe));
1156 iwe.cmd = SIOCGIWFREQ;
1157 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
1158 iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
1160 iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
1164 previous_ev = current_ev;
1165 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
1166 if (current_ev == previous_ev)
1167 #if WIRELESS_EXT >= 17
1173 //Add quality statistics
1174 //================================
1175 memset(&iwe, 0, sizeof(iwe));
1177 iwe.u.qual.level = 0;
1178 iwe.u.qual.noise = 0;
1179 set_quality(pAdapter, &iwe.u.qual, pAdapter->ScanTab.BssEntry[i].Rssi);
1180 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
1181 if (current_ev == previous_ev)
1182 #if WIRELESS_EXT >= 17
1189 //================================
1190 memset(&iwe, 0, sizeof(iwe));
1191 iwe.cmd = SIOCGIWENCODE;
1192 if (CAP_IS_PRIVACY_ON (pAdapter->ScanTab.BssEntry[i].CapabilityInfo ))
1193 iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1195 iwe.u.data.flags = IW_ENCODE_DISABLED;
1197 previous_ev = current_ev;
1198 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);
1199 if (current_ev == previous_ev)
1200 #if WIRELESS_EXT >= 17
1207 //================================
1208 if (pAdapter->ScanTab.BssEntry[i].SupRateLen)
1210 UCHAR tmpRate = pAdapter->ScanTab.BssEntry[i].SupRate[pAdapter->ScanTab.BssEntry[i].SupRateLen-1];
1211 memset(&iwe, 0, sizeof(iwe));
1212 iwe.cmd = SIOCGIWRATE;
1213 current_val = current_ev + IW_EV_LCP_LEN;
1214 if (tmpRate == 0x82)
1215 iwe.u.bitrate.value = 1 * 1000000;
1216 else if (tmpRate == 0x84)
1217 iwe.u.bitrate.value = 2 * 1000000;
1218 else if (tmpRate == 0x8B)
1219 iwe.u.bitrate.value = 5.5 * 1000000;
1220 else if (tmpRate == 0x96)
1221 iwe.u.bitrate.value = 11 * 1000000;
1223 iwe.u.bitrate.value = (tmpRate/2) * 1000000;
1225 iwe.u.bitrate.disabled = 0;
1226 current_val = iwe_stream_add_value(info, current_ev,
1227 current_val, end_buf, &iwe,
1230 if((current_val-current_ev)>IW_EV_LCP_LEN)
1231 current_ev = current_val;
1233 #if WIRELESS_EXT >= 17
1242 if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
1244 memset(&iwe, 0, sizeof(iwe));
1245 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1246 memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].WpaIE.IE[0]),
1247 pAdapter->ScanTab.BssEntry[i].WpaIE.IELen);
1248 iwe.cmd = IWEVGENIE;
1249 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].WpaIE.IELen;
1250 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, custom);
1251 if (current_ev == previous_ev)
1252 #if WIRELESS_EXT >= 17
1260 if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
1262 memset(&iwe, 0, sizeof(iwe));
1263 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1264 memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].RsnIE.IE[0]),
1265 pAdapter->ScanTab.BssEntry[i].RsnIE.IELen);
1266 iwe.cmd = IWEVGENIE;
1267 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].RsnIE.IELen;
1268 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, custom);
1269 if (current_ev == previous_ev)
1270 #if WIRELESS_EXT >= 17
1278 //================================
1279 if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
1281 NdisZeroMemory(&iwe, sizeof(iwe));
1282 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1283 iwe.cmd = IWEVCUSTOM;
1284 iwe.u.data.length = (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen * 2) + 7;
1285 NdisMoveMemory(custom, "wpa_ie=", 7);
1286 for (idx = 0; idx < pAdapter->ScanTab.BssEntry[i].WpaIE.IELen; idx++)
1287 sprintf(custom, "%s%02x", custom, pAdapter->ScanTab.BssEntry[i].WpaIE.IE[idx]);
1288 previous_ev = current_ev;
1289 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, custom);
1290 if (current_ev == previous_ev)
1291 #if WIRELESS_EXT >= 17
1299 if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
1301 NdisZeroMemory(&iwe, sizeof(iwe));
1302 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1303 iwe.cmd = IWEVCUSTOM;
1304 iwe.u.data.length = (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen * 2) + 7;
1305 NdisMoveMemory(custom, "rsn_ie=", 7);
1306 for (idx = 0; idx < pAdapter->ScanTab.BssEntry[i].RsnIE.IELen; idx++)
1307 sprintf(custom, "%s%02x", custom, pAdapter->ScanTab.BssEntry[i].RsnIE.IE[idx]);
1308 previous_ev = current_ev;
1309 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, custom);
1310 if (current_ev == previous_ev)
1311 #if WIRELESS_EXT >= 17
1317 #endif // IWEVGENIE //
1320 data->length = current_ev - extra;
1321 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
1322 DBGPRINT(RT_DEBUG_ERROR ,("===>rt_ioctl_giwscan. %d(%d) BSS returned, data->length = %d\n",i , pAdapter->ScanTab.BssNr, data->length));
1327 int rt_ioctl_siwessid(struct net_device *dev,
1328 struct iw_request_info *info,
1329 struct iw_point *data, char *essid)
1331 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1333 //check if the interface is down
1334 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1336 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1342 PCHAR pSsidString = NULL;
1344 // Includes null character.
1345 if (data->length > (IW_ESSID_MAX_SIZE + 1))
1348 pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
1351 NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
1352 NdisMoveMemory(pSsidString, essid, data->length);
1353 if (Set_SSID_Proc(pAdapter, pSsidString) == FALSE)
1362 if (Set_SSID_Proc(pAdapter, "") == FALSE)
1368 int rt_ioctl_giwessid(struct net_device *dev,
1369 struct iw_request_info *info,
1370 struct iw_point *data, char *essid)
1372 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1375 if (MONITOR_ON(pAdapter))
1381 if (OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED))
1383 DBGPRINT(RT_DEBUG_TRACE ,("MediaState is connected\n"));
1384 data->length = pAdapter->CommonCfg.SsidLen;
1385 memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
1389 else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
1391 data->length = pAdapter->CommonCfg.SsidLen;
1392 memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
1396 {//the ANY ssid was specified
1398 DBGPRINT(RT_DEBUG_TRACE ,("MediaState is not connected, ess\n"));
1405 int rt_ioctl_siwnickn(struct net_device *dev,
1406 struct iw_request_info *info,
1407 struct iw_point *data, char *nickname)
1409 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1411 //check if the interface is down
1412 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1414 DBGPRINT(RT_DEBUG_TRACE ,("INFO::Network is down!\n"));
1418 if (data->length > IW_ESSID_MAX_SIZE)
1421 memset(pAdapter->nickname, 0, IW_ESSID_MAX_SIZE + 1);
1422 memcpy(pAdapter->nickname, nickname, data->length);
1428 int rt_ioctl_giwnickn(struct net_device *dev,
1429 struct iw_request_info *info,
1430 struct iw_point *data, char *nickname)
1432 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1434 if (data->length > strlen(pAdapter->nickname) + 1)
1435 data->length = strlen(pAdapter->nickname) + 1;
1436 if (data->length > 0) {
1437 memcpy(nickname, pAdapter->nickname, data->length-1);
1438 nickname[data->length-1] = '\0';
1443 int rt_ioctl_siwrts(struct net_device *dev,
1444 struct iw_request_info *info,
1445 struct iw_param *rts, char *extra)
1447 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1450 //check if the interface is down
1451 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1453 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1458 val = MAX_RTS_THRESHOLD;
1459 else if (rts->value < 0 || rts->value > MAX_RTS_THRESHOLD)
1461 else if (rts->value == 0)
1462 val = MAX_RTS_THRESHOLD;
1466 if (val != pAdapter->CommonCfg.RtsThreshold)
1467 pAdapter->CommonCfg.RtsThreshold = val;
1472 int rt_ioctl_giwrts(struct net_device *dev,
1473 struct iw_request_info *info,
1474 struct iw_param *rts, char *extra)
1476 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1478 //check if the interface is down
1479 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1481 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1485 rts->value = pAdapter->CommonCfg.RtsThreshold;
1486 rts->disabled = (rts->value == MAX_RTS_THRESHOLD);
1492 int rt_ioctl_siwfrag(struct net_device *dev,
1493 struct iw_request_info *info,
1494 struct iw_param *frag, char *extra)
1496 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1499 //check if the interface is down
1500 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1502 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1507 val = MAX_FRAG_THRESHOLD;
1508 else if (frag->value >= MIN_FRAG_THRESHOLD || frag->value <= MAX_FRAG_THRESHOLD)
1509 val = __cpu_to_le16(frag->value & ~0x1); /* even numbers only */
1510 else if (frag->value == 0)
1511 val = MAX_FRAG_THRESHOLD;
1515 pAdapter->CommonCfg.FragmentThreshold = val;
1519 int rt_ioctl_giwfrag(struct net_device *dev,
1520 struct iw_request_info *info,
1521 struct iw_param *frag, char *extra)
1523 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1525 //check if the interface is down
1526 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1528 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1532 frag->value = pAdapter->CommonCfg.FragmentThreshold;
1533 frag->disabled = (frag->value == MAX_FRAG_THRESHOLD);
1539 #define MAX_WEP_KEY_SIZE 13
1540 #define MIN_WEP_KEY_SIZE 5
1541 int rt_ioctl_siwencode(struct net_device *dev,
1542 struct iw_request_info *info,
1543 struct iw_point *erq, char *extra)
1545 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1547 //check if the interface is down
1548 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1550 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1554 if ((erq->length == 0) &&
1555 (erq->flags & IW_ENCODE_DISABLED))
1557 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
1558 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
1559 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
1560 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
1561 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1564 else if (erq->flags & IW_ENCODE_RESTRICTED || erq->flags & IW_ENCODE_OPEN)
1566 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
1567 STA_PORT_SECURED(pAdapter);
1568 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
1569 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
1570 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
1571 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
1572 if (erq->flags & IW_ENCODE_RESTRICTED)
1573 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
1575 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1578 if (erq->length > 0)
1580 int keyIdx = (erq->flags & IW_ENCODE_INDEX) - 1;
1581 /* Check the size of the key */
1582 if (erq->length > MAX_WEP_KEY_SIZE)
1586 /* Check key index */
1587 if ((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
1589 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::Wrong keyIdx=%d! Using default key instead (%d)\n",
1590 keyIdx, pAdapter->StaCfg.DefaultKeyId));
1593 keyIdx = pAdapter->StaCfg.DefaultKeyId;
1597 pAdapter->StaCfg.DefaultKeyId=keyIdx;
1600 NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
1602 if (erq->length == MAX_WEP_KEY_SIZE)
1604 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
1605 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
1607 else if (erq->length == MIN_WEP_KEY_SIZE)
1609 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
1610 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
1613 /* Disable the key */
1614 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
1616 /* Check if the key is not marked as invalid */
1617 if(!(erq->flags & IW_ENCODE_NOKEY))
1619 /* Copy the key in the driver */
1620 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, extra, erq->length);
1625 /* Do we want to just set the transmit key index ? */
1626 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
1627 if ((index >= 0) && (index < 4))
1629 pAdapter->StaCfg.DefaultKeyId = index;
1632 /* Don't complain if only change the mode */
1633 if (!(erq->flags & IW_ENCODE_MODE))
1638 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::erq->flags=%x\n",erq->flags));
1639 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::AuthMode=%x\n",pAdapter->StaCfg.AuthMode));
1640 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::DefaultKeyId=%x, KeyLen = %d\n",pAdapter->StaCfg.DefaultKeyId , pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen));
1641 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::WepStatus=%x\n",pAdapter->StaCfg.WepStatus));
1646 rt_ioctl_giwencode(struct net_device *dev,
1647 struct iw_request_info *info,
1648 struct iw_point *erq, char *key)
1650 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1653 //check if the interface is down
1654 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1656 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1660 kid = erq->flags & IW_ENCODE_INDEX;
1661 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_giwencode %d\n", erq->flags & IW_ENCODE_INDEX));
1663 if (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled)
1666 erq->flags = IW_ENCODE_DISABLED;
1668 else if ((kid > 0) && (kid <=4))
1671 erq->flags = kid ; /* NB: base 1 */
1672 if (erq->length > pAdapter->SharedKey[BSS0][kid-1].KeyLen)
1673 erq->length = pAdapter->SharedKey[BSS0][kid-1].KeyLen;
1674 memcpy(key, pAdapter->SharedKey[BSS0][kid-1].Key, erq->length);
1675 //if ((kid == pAdapter->PortCfg.DefaultKeyId))
1676 //erq->flags |= IW_ENCODE_ENABLED; /* XXX */
1677 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1678 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1680 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1685 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1686 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1688 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1689 erq->length = pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen;
1690 memcpy(key, pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key, erq->length);
1691 // copy default key ID
1692 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1693 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1695 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1696 erq->flags = pAdapter->StaCfg.DefaultKeyId + 1; /* NB: base 1 */
1697 erq->flags |= IW_ENCODE_ENABLED; /* XXX */
1705 rt_ioctl_setparam(struct net_device *dev, struct iw_request_info *info,
1706 void *w, char *extra)
1708 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1709 PRTMP_ADAPTER pAdapter;
1711 char *this_char = extra;
1715 if (dev->priv_flags == INT_MAIN)
1717 pAdapter = dev->ml_priv;
1721 pVirtualAd = dev->ml_priv;
1722 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1724 pObj = (POS_COOKIE) pAdapter->OS_Cookie;
1726 if (pAdapter == NULL)
1728 /* if 1st open fail, pAd will be free;
1729 So the net_dev->ml_priv will be NULL in 2rd open */
1734 pObj->ioctl_if_type = INT_MAIN;
1735 pObj->ioctl_if = MAIN_MBSSID;
1738 //check if the interface is down
1739 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1741 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1748 if ((value = rtstrchr(this_char, '=')) != NULL)
1754 // reject setting nothing besides ANY ssid(ssidLen=0)
1755 if (!*value && (strcmp(this_char, "SSID") != 0))
1758 for (PRTMP_PRIVATE_SET_PROC = RTMP_PRIVATE_SUPPORT_PROC; PRTMP_PRIVATE_SET_PROC->name; PRTMP_PRIVATE_SET_PROC++)
1760 if (strcmp(this_char, PRTMP_PRIVATE_SET_PROC->name) == 0)
1762 if(!PRTMP_PRIVATE_SET_PROC->set_proc(pAdapter, value))
1763 { //FALSE:Set private failed then return Invalid argument
1766 break; //Exit for loop.
1770 if(PRTMP_PRIVATE_SET_PROC->name == NULL)
1771 { //Not found argument
1773 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_setparam:: (iwpriv) Not Support Set Command [%s=%s]\n", this_char, value));
1781 rt_private_get_statistics(struct net_device *dev, struct iw_request_info *info,
1782 struct iw_point *wrq, char *extra)
1785 PRTMP_ADAPTER pAd = dev->ml_priv;
1793 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
1794 sprintf(extra, "\n\n");
1797 sprintf(extra+strlen(extra), "Tx success = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart);
1798 sprintf(extra+strlen(extra), "Tx success without retry = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart - (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
1800 sprintf(extra+strlen(extra), "Tx success after retry = %ld\n", (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
1801 sprintf(extra+strlen(extra), "Tx fail to Rcv ACK after retry = %ld\n", (ULONG)pAd->WlanCounters.FailedCount.QuadPart);
1802 sprintf(extra+strlen(extra), "RTS Success Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSSuccessCount.QuadPart);
1803 sprintf(extra+strlen(extra), "RTS Fail Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSFailureCount.QuadPart);
1805 sprintf(extra+strlen(extra), "Rx success = %ld\n", (ULONG)pAd->WlanCounters.ReceivedFragmentCount.QuadPart);
1806 sprintf(extra+strlen(extra), "Rx with CRC = %ld\n", (ULONG)pAd->WlanCounters.FCSErrorCount.QuadPart);
1807 sprintf(extra+strlen(extra), "Rx drop due to out of resource = %ld\n", (ULONG)pAd->Counters8023.RxNoBuffer);
1808 sprintf(extra+strlen(extra), "Rx duplicate frame = %ld\n", (ULONG)pAd->WlanCounters.FrameDuplicateCount.QuadPart);
1810 sprintf(extra+strlen(extra), "False CCA (one second) = %ld\n", (ULONG)pAd->RalinkCounters.OneSecFalseCCACnt);
1812 sprintf(extra+strlen(extra), "RSSI-A = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi0 - pAd->BbpRssiToDbmDelta));
1813 sprintf(extra+strlen(extra), "RSSI-B (if available) = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi1 - pAd->BbpRssiToDbmDelta));
1814 sprintf(extra+strlen(extra), "RSSI-C (if available) = %ld\n\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi2 - pAd->BbpRssiToDbmDelta));
1816 sprintf(extra+strlen(extra), "WpaSupplicantUP = %d\n\n", pAd->StaCfg.WpaSupplicantUP);
1818 wrq->length = strlen(extra) + 1; // 1: size of '\0'
1819 DBGPRINT(RT_DEBUG_TRACE, ("<== rt_private_get_statistics, wrq->length = %d\n", wrq->length));
1825 IN PRTMP_ADAPTER pAd,
1829 BA_ORI_ENTRY *pOriBAEntry;
1830 BA_REC_ENTRY *pRecBAEntry;
1832 for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
1834 PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
1835 if (((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
1836 || (pEntry->ValidAsWDS) || (pEntry->ValidAsMesh))
1838 sprintf(pOutBuf, "%s\n%02X:%02X:%02X:%02X:%02X:%02X (Aid = %d) (AP) -\n",
1840 pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
1841 pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5], pEntry->Aid);
1843 sprintf(pOutBuf, "%s[Recipient]\n", pOutBuf);
1844 for (j=0; j < NUM_OF_TID; j++)
1846 if (pEntry->BARecWcidArray[j] != 0)
1848 pRecBAEntry =&pAd->BATable.BARecEntry[pEntry->BARecWcidArray[j]];
1849 sprintf(pOutBuf, "%sTID=%d, BAWinSize=%d, LastIndSeq=%d, ReorderingPkts=%d\n", pOutBuf, j, pRecBAEntry->BAWinSize, pRecBAEntry->LastIndSeq, pRecBAEntry->list.qlen);
1852 sprintf(pOutBuf, "%s\n", pOutBuf);
1854 sprintf(pOutBuf, "%s[Originator]\n", pOutBuf);
1855 for (j=0; j < NUM_OF_TID; j++)
1857 if (pEntry->BAOriWcidArray[j] != 0)
1859 pOriBAEntry =&pAd->BATable.BAOriEntry[pEntry->BAOriWcidArray[j]];
1860 sprintf(pOutBuf, "%sTID=%d, BAWinSize=%d, StartSeq=%d, CurTxSeq=%d\n", pOutBuf, j, pOriBAEntry->BAWinSize, pOriBAEntry->Sequence, pEntry->TxSeq[j]);
1863 sprintf(pOutBuf, "%s\n\n", pOutBuf);
1865 if (strlen(pOutBuf) > (IW_PRIV_SIZE_MASK - 30))
1873 rt_private_show(struct net_device *dev, struct iw_request_info *info,
1874 struct iw_point *wrq, char *extra)
1877 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1880 u32 subcmd = wrq->flags;
1882 if (dev->priv_flags == INT_MAIN)
1886 pVirtualAd = dev->ml_priv;
1887 pAd = pVirtualAd->RtmpDev->ml_priv;
1889 pObj = (POS_COOKIE) pAd->OS_Cookie;
1893 /* if 1st open fail, pAd will be free;
1894 So the net_dev->ml_priv will be NULL in 2rd open */
1903 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
1906 pObj->ioctl_if_type = INT_MAIN;
1907 pObj->ioctl_if = MAIN_MBSSID;
1913 case SHOW_CONN_STATUS:
1914 if (MONITOR_ON(pAd))
1916 if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
1917 pAd->CommonCfg.RegTransmitSetting.field.BW)
1918 sprintf(extra, "Monitor Mode(CentralChannel %d)\n", pAd->CommonCfg.CentralChannel);
1920 sprintf(extra, "Monitor Mode(Channel %d)\n", pAd->CommonCfg.Channel);
1924 if (pAd->IndicateMediaState == NdisMediaStateConnected)
1928 sprintf(extra, "Connected(AP: %s[%02X:%02X:%02X:%02X:%02X:%02X])\n",
1929 pAd->CommonCfg.Ssid,
1930 pAd->CommonCfg.Bssid[0],
1931 pAd->CommonCfg.Bssid[1],
1932 pAd->CommonCfg.Bssid[2],
1933 pAd->CommonCfg.Bssid[3],
1934 pAd->CommonCfg.Bssid[4],
1935 pAd->CommonCfg.Bssid[5]);
1936 DBGPRINT(RT_DEBUG_TRACE ,("Ssid=%s ,Ssidlen = %d\n",pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen));
1938 else if (ADHOC_ON(pAd))
1939 sprintf(extra, "Connected\n");
1943 sprintf(extra, "Disconnected\n");
1944 DBGPRINT(RT_DEBUG_TRACE ,("ConnStatus is not connected\n"));
1947 wrq->length = strlen(extra) + 1; // 1: size of '\0'
1949 case SHOW_DRVIER_VERION:
1950 sprintf(extra, "Driver version-%s, %s %s\n", STA_DRIVER_VERSION, __DATE__, __TIME__ );
1951 wrq->length = strlen(extra) + 1; // 1: size of '\0'
1954 getBaInfo(pAd, extra);
1955 wrq->length = strlen(extra) + 1; // 1: size of '\0'
1957 case SHOW_DESC_INFO:
1959 Show_DescInfo_Proc(pAd, NULL);
1960 wrq->length = 0; // 1: size of '\0'
1964 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
1966 sprintf(extra, "Scanning\n");
1967 wrq->length = strlen(extra) + 1; // 1: size of '\0'
1970 pAd->StaCfg.bSwRadio = FALSE;
1971 if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
1973 pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
1974 if (pAd->StaCfg.bRadio == FALSE)
1977 // Update extra information
1978 pAd->ExtraInfo = SW_RADIO_OFF;
1981 sprintf(extra, "Radio Off\n");
1982 wrq->length = strlen(extra) + 1; // 1: size of '\0'
1985 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
1987 sprintf(extra, "Scanning\n");
1988 wrq->length = strlen(extra) + 1; // 1: size of '\0'
1991 pAd->StaCfg.bSwRadio = TRUE;
1992 //if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
1994 pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
1995 if (pAd->StaCfg.bRadio == TRUE)
1998 // Update extra information
1999 pAd->ExtraInfo = EXTRA_INFO_CLEAR;
2002 sprintf(extra, "Radio On\n");
2003 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2006 case SHOW_CFG_VALUE:
2008 Status = RTMPShowCfgValue(pAd, wrq->pointer, extra);
2010 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2014 DBGPRINT(RT_DEBUG_TRACE, ("%s - unknow subcmd = %d\n", __func__, subcmd));
2022 int rt_ioctl_siwmlme(struct net_device *dev,
2023 struct iw_request_info *info,
2024 union iwreq_data *wrqu,
2027 PRTMP_ADAPTER pAd = dev->ml_priv;
2028 struct iw_mlme *pMlme = (struct iw_mlme *)wrqu->data.pointer;
2029 MLME_QUEUE_ELEM MsgElem;
2030 MLME_DISASSOC_REQ_STRUCT DisAssocReq;
2031 MLME_DEAUTH_REQ_STRUCT DeAuthReq;
2033 DBGPRINT(RT_DEBUG_TRACE, ("====> %s\n", __func__));
2040 #ifdef IW_MLME_DEAUTH
2041 case IW_MLME_DEAUTH:
2042 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DEAUTH\n", __func__));
2043 COPY_MAC_ADDR(DeAuthReq.Addr, pAd->CommonCfg.Bssid);
2044 DeAuthReq.Reason = pMlme->reason_code;
2045 MsgElem.MsgLen = sizeof(MLME_DEAUTH_REQ_STRUCT);
2046 NdisMoveMemory(MsgElem.Msg, &DeAuthReq, sizeof(MLME_DEAUTH_REQ_STRUCT));
2047 MlmeDeauthReqAction(pAd, &MsgElem);
2050 LinkDown(pAd, FALSE);
2051 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
2054 #endif // IW_MLME_DEAUTH //
2055 #ifdef IW_MLME_DISASSOC
2056 case IW_MLME_DISASSOC:
2057 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DISASSOC\n", __func__));
2058 COPY_MAC_ADDR(DisAssocReq.Addr, pAd->CommonCfg.Bssid);
2059 DisAssocReq.Reason = pMlme->reason_code;
2061 MsgElem.Machine = ASSOC_STATE_MACHINE;
2062 MsgElem.MsgType = MT2_MLME_DISASSOC_REQ;
2063 MsgElem.MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
2064 NdisMoveMemory(MsgElem.Msg, &DisAssocReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
2066 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
2067 MlmeDisassocReqAction(pAd, &MsgElem);
2069 #endif // IW_MLME_DISASSOC //
2071 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - Unknow Command\n", __func__));
2077 #endif // SIOCSIWMLME //
2079 #if WIRELESS_EXT > 17
2080 int rt_ioctl_siwauth(struct net_device *dev,
2081 struct iw_request_info *info,
2082 union iwreq_data *wrqu, char *extra)
2084 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2085 struct iw_param *param = &wrqu->param;
2087 //check if the interface is down
2088 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2090 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2093 switch (param->flags & IW_AUTH_INDEX) {
2094 case IW_AUTH_WPA_VERSION:
2095 if (param->value == IW_AUTH_WPA_VERSION_WPA)
2097 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
2098 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
2099 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
2101 else if (param->value == IW_AUTH_WPA_VERSION_WPA2)
2102 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
2104 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __func__, param->value));
2106 case IW_AUTH_CIPHER_PAIRWISE:
2107 if (param->value == IW_AUTH_CIPHER_NONE)
2109 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
2110 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2111 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
2113 else if (param->value == IW_AUTH_CIPHER_WEP40 ||
2114 param->value == IW_AUTH_CIPHER_WEP104)
2116 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
2117 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2118 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
2119 pAdapter->StaCfg.IEEE8021X = FALSE;
2121 else if (param->value == IW_AUTH_CIPHER_TKIP)
2123 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
2124 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2125 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
2127 else if (param->value == IW_AUTH_CIPHER_CCMP)
2129 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
2130 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2131 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
2133 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_PAIRWISE - param->value = %d!\n", __func__, param->value));
2135 case IW_AUTH_CIPHER_GROUP:
2136 if (param->value == IW_AUTH_CIPHER_NONE)
2138 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
2140 else if (param->value == IW_AUTH_CIPHER_WEP40 ||
2141 param->value == IW_AUTH_CIPHER_WEP104)
2143 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
2145 else if (param->value == IW_AUTH_CIPHER_TKIP)
2147 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
2149 else if (param->value == IW_AUTH_CIPHER_CCMP)
2151 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
2153 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_GROUP - param->value = %d!\n", __func__, param->value));
2155 case IW_AUTH_KEY_MGMT:
2156 if (param->value == IW_AUTH_KEY_MGMT_802_1X)
2158 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)
2160 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
2161 pAdapter->StaCfg.IEEE8021X = FALSE;
2163 else if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
2165 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
2166 pAdapter->StaCfg.IEEE8021X = FALSE;
2170 pAdapter->StaCfg.IEEE8021X = TRUE;
2172 else if (param->value == 0)
2174 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2175 STA_PORT_SECURED(pAdapter);
2177 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_KEY_MGMT - param->value = %d!\n", __func__, param->value));
2179 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
2181 case IW_AUTH_PRIVACY_INVOKED:
2182 /*if (param->value == 0)
2184 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
2185 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
2186 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2187 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
2188 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
2190 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_PRIVACY_INVOKED - param->value = %d!\n", __func__, param->value));
2192 case IW_AUTH_DROP_UNENCRYPTED:
2193 if (param->value != 0)
2194 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
2197 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2198 STA_PORT_SECURED(pAdapter);
2200 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __func__, param->value));
2202 case IW_AUTH_80211_AUTH_ALG:
2203 if (param->value & IW_AUTH_ALG_SHARED_KEY)
2205 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
2207 else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
2209 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
2213 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_80211_AUTH_ALG - param->value = %d!\n", __func__, param->value));
2215 case IW_AUTH_WPA_ENABLED:
2216 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_ENABLED - Driver supports WPA!(param->value = %d)\n", __func__, param->value));
2225 int rt_ioctl_giwauth(struct net_device *dev,
2226 struct iw_request_info *info,
2227 union iwreq_data *wrqu, char *extra)
2229 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2230 struct iw_param *param = &wrqu->param;
2232 //check if the interface is down
2233 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2235 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2239 switch (param->flags & IW_AUTH_INDEX) {
2240 case IW_AUTH_DROP_UNENCRYPTED:
2241 param->value = (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled) ? 0 : 1;
2244 case IW_AUTH_80211_AUTH_ALG:
2245 param->value = (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared) ? IW_AUTH_ALG_SHARED_KEY : IW_AUTH_ALG_OPEN_SYSTEM;
2248 case IW_AUTH_WPA_ENABLED:
2249 param->value = (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) ? 1 : 0;
2255 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_giwauth::param->value = %d!\n", param->value));
2259 void fnSetCipherKey(
2260 IN PRTMP_ADAPTER pAdapter,
2264 IN struct iw_encode_ext *ext)
2266 NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
2267 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = LEN_TKIP_EK;
2268 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, LEN_TKIP_EK);
2269 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].TxMic, ext->key + LEN_TKIP_EK, LEN_TKIP_TXMICK);
2270 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].RxMic, ext->key + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
2271 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CipherAlg;
2273 // Update group key information to ASIC Shared Key Table
2274 AsicAddSharedKeyEntry(pAdapter,
2277 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2278 pAdapter->SharedKey[BSS0][keyIdx].Key,
2279 pAdapter->SharedKey[BSS0][keyIdx].TxMic,
2280 pAdapter->SharedKey[BSS0][keyIdx].RxMic);
2283 // Update ASIC WCID attribute table and IVEIV table
2284 RTMPAddWcidAttributeEntry(pAdapter,
2287 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2290 // Update ASIC WCID attribute table and IVEIV table
2291 RTMPAddWcidAttributeEntry(pAdapter,
2294 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2295 &pAdapter->MacTab.Content[BSSID_WCID]);
2298 int rt_ioctl_siwencodeext(struct net_device *dev,
2299 struct iw_request_info *info,
2300 union iwreq_data *wrqu,
2303 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2304 struct iw_point *encoding = &wrqu->encoding;
2305 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2306 int keyIdx, alg = ext->alg;
2308 //check if the interface is down
2309 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2311 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2315 if (encoding->flags & IW_ENCODE_DISABLED)
2317 keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
2318 // set BSSID wcid entry of the Pair-wise Key table as no-security mode
2319 AsicRemovePairwiseKeyEntry(pAdapter, BSS0, BSSID_WCID);
2320 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
2321 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_NONE;
2322 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)keyIdx);
2323 NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
2324 DBGPRINT(RT_DEBUG_TRACE, ("%s::Remove all keys!(encoding->flags = %x)\n", __func__, encoding->flags));
2328 // Get Key Index and convet to our own defined key index
2329 keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
2330 if((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
2333 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2335 pAdapter->StaCfg.DefaultKeyId = keyIdx;
2336 DBGPRINT(RT_DEBUG_TRACE, ("%s::DefaultKeyId = %d\n", __func__, pAdapter->StaCfg.DefaultKeyId));
2340 case IW_ENCODE_ALG_NONE:
2341 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_NONE\n", __func__));
2343 case IW_ENCODE_ALG_WEP:
2344 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_WEP - ext->key_len = %d, keyIdx = %d\n", __func__, ext->key_len, keyIdx));
2345 if (ext->key_len == MAX_WEP_KEY_SIZE)
2347 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
2348 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
2350 else if (ext->key_len == MIN_WEP_KEY_SIZE)
2352 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
2353 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
2358 NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
2359 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, ext->key_len);
2361 case IW_ENCODE_ALG_TKIP:
2362 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_TKIP - keyIdx = %d, ext->key_len = %d\n", __func__, keyIdx, ext->key_len));
2363 if (ext->key_len == 32)
2365 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2367 fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, FALSE, ext);
2368 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
2370 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2371 STA_PORT_SECURED(pAdapter);
2374 else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
2376 fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, TRUE, ext);
2378 // set 802.1x port control
2379 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2380 STA_PORT_SECURED(pAdapter);
2386 case IW_ENCODE_ALG_CCMP:
2387 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2389 fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, FALSE, ext);
2390 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
2391 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2392 STA_PORT_SECURED(pAdapter);
2394 else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
2396 fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, TRUE, ext);
2398 // set 802.1x port control
2399 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2400 STA_PORT_SECURED(pAdapter);
2412 rt_ioctl_giwencodeext(struct net_device *dev,
2413 struct iw_request_info *info,
2414 union iwreq_data *wrqu, char *extra)
2416 PRTMP_ADAPTER pAd = dev->ml_priv;
2418 struct iw_point *encoding = &wrqu->encoding;
2419 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2420 int idx, max_key_len;
2422 DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_giwencodeext\n"));
2424 max_key_len = encoding->length - sizeof(*ext);
2425 if (max_key_len < 0)
2428 idx = encoding->flags & IW_ENCODE_INDEX;
2431 if (idx < 1 || idx > 4)
2435 if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
2436 (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled))
2438 if (idx != pAd->StaCfg.DefaultKeyId)
2446 idx = pAd->StaCfg.DefaultKeyId;
2448 encoding->flags = idx + 1;
2449 memset(ext, 0, sizeof(*ext));
2452 switch(pAd->StaCfg.WepStatus) {
2453 case Ndis802_11WEPDisabled:
2454 ext->alg = IW_ENCODE_ALG_NONE;
2455 encoding->flags |= IW_ENCODE_DISABLED;
2457 case Ndis802_11WEPEnabled:
2458 ext->alg = IW_ENCODE_ALG_WEP;
2459 if (pAd->SharedKey[BSS0][idx].KeyLen > max_key_len)
2463 ext->key_len = pAd->SharedKey[BSS0][idx].KeyLen;
2464 pKey = &(pAd->SharedKey[BSS0][idx].Key[0]);
2467 case Ndis802_11Encryption2Enabled:
2468 case Ndis802_11Encryption3Enabled:
2469 if (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
2470 ext->alg = IW_ENCODE_ALG_TKIP;
2472 ext->alg = IW_ENCODE_ALG_CCMP;
2474 if (max_key_len < 32)
2479 pKey = &pAd->StaCfg.PMK[0];
2486 if (ext->key_len && pKey)
2488 encoding->flags |= IW_ENCODE_ENABLED;
2489 memcpy(ext->key, pKey, ext->key_len);
2496 int rt_ioctl_siwgenie(struct net_device *dev,
2497 struct iw_request_info *info,
2498 union iwreq_data *wrqu, char *extra)
2500 PRTMP_ADAPTER pAd = dev->ml_priv;
2502 if (wrqu->data.length > MAX_LEN_OF_RSNIE ||
2503 (wrqu->data.length && extra == NULL))
2506 if (wrqu->data.length)
2508 pAd->StaCfg.RSNIE_Len = wrqu->data.length;
2509 NdisMoveMemory(&pAd->StaCfg.RSN_IE[0], extra, pAd->StaCfg.RSNIE_Len);
2513 pAd->StaCfg.RSNIE_Len = 0;
2514 NdisZeroMemory(&pAd->StaCfg.RSN_IE[0], MAX_LEN_OF_RSNIE);
2519 #endif // SIOCSIWGENIE //
2521 int rt_ioctl_giwgenie(struct net_device *dev,
2522 struct iw_request_info *info,
2523 union iwreq_data *wrqu, char *extra)
2525 PRTMP_ADAPTER pAd = dev->ml_priv;
2527 if ((pAd->StaCfg.RSNIE_Len == 0) ||
2528 (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA))
2530 wrqu->data.length = 0;
2535 if (pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
2537 if (wrqu->data.length < pAd->StaCfg.RSNIE_Len)
2540 wrqu->data.length = pAd->StaCfg.RSNIE_Len;
2541 memcpy(extra, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
2544 #endif // SIOCSIWGENIE //
2546 UCHAR RSNIe = IE_WPA;
2548 if (wrqu->data.length < (pAd->StaCfg.RSNIE_Len + 2)) // ID, Len
2550 wrqu->data.length = pAd->StaCfg.RSNIE_Len + 2;
2552 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
2553 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2))
2556 extra[0] = (char)RSNIe;
2557 extra[1] = pAd->StaCfg.RSNIE_Len;
2558 memcpy(extra+2, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
2564 int rt_ioctl_siwpmksa(struct net_device *dev,
2565 struct iw_request_info *info,
2566 union iwreq_data *wrqu,
2569 PRTMP_ADAPTER pAd = dev->ml_priv;
2570 struct iw_pmksa *pPmksa = (struct iw_pmksa *)wrqu->data.pointer;
2571 INT CachedIdx = 0, idx = 0;
2576 DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_siwpmksa\n"));
2579 case IW_PMKSA_FLUSH:
2580 NdisZeroMemory(pAd->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
2581 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_FLUSH\n"));
2583 case IW_PMKSA_REMOVE:
2584 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
2586 // compare the BSSID
2587 if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
2589 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN);
2590 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].PMKID, 16);
2591 for (idx = CachedIdx; idx < (pAd->StaCfg.SavedPMKNum - 1); idx++)
2593 NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].BSSID[0], &pAd->StaCfg.SavedPMK[idx+1].BSSID[0], MAC_ADDR_LEN);
2594 NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].PMKID[0], &pAd->StaCfg.SavedPMK[idx+1].PMKID[0], 16);
2596 pAd->StaCfg.SavedPMKNum--;
2601 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_REMOVE\n"));
2604 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
2606 // compare the BSSID
2607 if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
2611 // Found, replace it
2612 if (CachedIdx < PMKID_NO)
2614 DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
2615 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
2616 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
2617 pAd->StaCfg.SavedPMKNum++;
2619 // Not found, replace the last one
2622 // Randomly replace one
2623 CachedIdx = (pPmksa->bssid.sa_data[5] % PMKID_NO);
2624 DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
2625 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
2626 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
2629 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_ADD\n"));
2632 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - Unknow Command!!\n"));
2638 #endif // #if WIRELESS_EXT > 17
2642 rt_private_ioctl_bbp(struct net_device *dev, struct iw_request_info *info,
2643 struct iw_point *wrq, char *extra)
2648 // CHAR arg[255]={0};
2651 BOOLEAN bIsPrintAllBBP = FALSE;
2653 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2656 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2658 if (wrq->length > 1) //No parameters.
2660 sprintf(extra, "\n");
2662 //Parsing Read or Write
2663 this_char = wrq->pointer;
2664 DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s\n", this_char));
2668 if ((value = rtstrchr(this_char, '=')) != NULL)
2671 if (!value || !*value)
2673 DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s, value=%s\n", this_char, value));
2674 if (sscanf(this_char, "%d", &(bbpId)) == 1)
2680 if (bbpId <= 138) // edit by johnli, RF power sequence setup, add BBP R138 for ADC dynamic on/off control
2684 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
2686 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
2687 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2688 DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
2691 {//Invalid parametes, so default printk all bbp
2692 bIsPrintAllBBP = TRUE;
2697 { //Invalid parametes, so default printk all bbp
2698 bIsPrintAllBBP = TRUE;
2704 if ((sscanf(this_char, "%d", &(bbpId)) == 1) && (sscanf(value, "%x", &(bbpValue)) == 1))
2710 if (bbpId <= 138) // edit by johnli, RF power sequence setup, add BBP R138 for ADC dynamic on/off control
2714 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, bbpId, bbpValue);
2715 //Read it back for showing
2716 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
2718 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
2719 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2720 DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
2723 {//Invalid parametes, so default printk all bbp
2724 bIsPrintAllBBP = TRUE;
2729 { //Invalid parametes, so default printk all bbp
2730 bIsPrintAllBBP = TRUE;
2736 bIsPrintAllBBP = TRUE;
2741 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2742 sprintf(extra, "\n");
2744 for (bbpId = 0; bbpId <= 136; bbpId++)
2747 for (bbpId = 0; bbpId <= 138; bbpId++) // edit by johnli, RF power sequence setup, add BBP R138 for ADC dynamic on/off control
2750 if (strlen(extra) >= (IW_PRIV_SIZE_MASK - 10))
2752 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
2754 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X ", bbpId, bbpId*2, regBBP);
2756 sprintf(extra+strlen(extra), "\n");
2758 sprintf(extra+strlen(extra), "%03d = %02X\n", bbpId, regBBP); // edit by johnli, change display format
2761 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2762 DBGPRINT(RT_DEBUG_TRACE, ("wrq->length = %d\n", wrq->length));
2765 DBGPRINT(RT_DEBUG_TRACE, ("<==rt_private_ioctl_bbp\n\n"));
2771 int rt_ioctl_siwrate(struct net_device *dev,
2772 struct iw_request_info *info,
2773 union iwreq_data *wrqu, char *extra)
2775 PRTMP_ADAPTER pAd = dev->ml_priv;
2776 UINT32 rate = wrqu->bitrate.value, fixed = wrqu->bitrate.fixed;
2778 //check if the interface is down
2779 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2781 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::Network is down!\n"));
2785 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(rate = %d, fixed = %d)\n", rate, fixed));
2786 /* rate = -1 => auto rate
2787 rate = X, fixed = 1 => (fixed rate X)
2792 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
2793 pAd->StaCfg.bAutoTxRateSwitch = TRUE;
2794 if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
2795 (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
2796 RTMPSetDesiredRates(pAd, -1);
2804 pAd->StaCfg.bAutoTxRateSwitch = FALSE;
2805 if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
2806 (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
2807 RTMPSetDesiredRates(pAd, rate);
2810 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
2813 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(HtMcs=%d)\n",pAd->StaCfg.DesiredTransmitSetting.field.MCS));
2817 // TODO: rate = X, fixed = 0 => (rates <= X)
2825 int rt_ioctl_giwrate(struct net_device *dev,
2826 struct iw_request_info *info,
2827 union iwreq_data *wrqu, char *extra)
2829 PRTMP_ADAPTER pAd = dev->ml_priv;
2830 int rate_index = 0, rate_count = 0;
2831 HTTRANSMIT_SETTING ht_setting;
2832 __s32 ralinkrate[] =
2833 {2, 4, 11, 22, // CCK
2834 12, 18, 24, 36, 48, 72, 96, 108, // OFDM
2835 13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260, // 20MHz, 800ns GI, MCS: 0 ~ 15
2836 39, 78, 117, 156, 234, 312, 351, 390, // 20MHz, 800ns GI, MCS: 16 ~ 23
2837 27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540, // 40MHz, 800ns GI, MCS: 0 ~ 15
2838 81, 162, 243, 324, 486, 648, 729, 810, // 40MHz, 800ns GI, MCS: 16 ~ 23
2839 14, 29, 43, 57, 87, 115, 130, 144, 29, 59, 87, 115, 173, 230, 260, 288, // 20MHz, 400ns GI, MCS: 0 ~ 15
2840 43, 87, 130, 173, 260, 317, 390, 433, // 20MHz, 400ns GI, MCS: 16 ~ 23
2841 30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600, // 40MHz, 400ns GI, MCS: 0 ~ 15
2842 90, 180, 270, 360, 540, 720, 810, 900}; // 40MHz, 400ns GI, MCS: 16 ~ 23
2844 rate_count = sizeof(ralinkrate)/sizeof(__s32);
2845 //check if the interface is down
2846 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2848 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2852 if ((pAd->StaCfg.bAutoTxRateSwitch == FALSE) &&
2854 ((pAd->CommonCfg.PhyMode <= PHY_11G) || (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM)))
2855 ht_setting.word = pAd->StaCfg.HTPhyMode.word;
2857 ht_setting.word = pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word;
2859 if (ht_setting.field.MODE >= MODE_HTMIX)
2861 // rate_index = 12 + ((UCHAR)ht_setting.field.BW *16) + ((UCHAR)ht_setting.field.ShortGI *32) + ((UCHAR)ht_setting.field.MCS);
2862 rate_index = 12 + ((UCHAR)ht_setting.field.BW *24) + ((UCHAR)ht_setting.field.ShortGI *48) + ((UCHAR)ht_setting.field.MCS);
2865 if (ht_setting.field.MODE == MODE_OFDM)
2866 rate_index = (UCHAR)(ht_setting.field.MCS) + 4;
2867 else if (ht_setting.field.MODE == MODE_CCK)
2868 rate_index = (UCHAR)(ht_setting.field.MCS);
2873 if (rate_index > rate_count)
2874 rate_index = rate_count;
2876 wrqu->bitrate.value = ralinkrate[rate_index] * 500000;
2877 wrqu->bitrate.disabled = 0;
2882 static const iw_handler rt_handler[] =
2884 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2885 (iw_handler) rt_ioctl_giwname, /* SIOCGIWNAME */
2886 (iw_handler) NULL, /* SIOCSIWNWID */
2887 (iw_handler) NULL, /* SIOCGIWNWID */
2888 (iw_handler) rt_ioctl_siwfreq, /* SIOCSIWFREQ */
2889 (iw_handler) rt_ioctl_giwfreq, /* SIOCGIWFREQ */
2890 (iw_handler) rt_ioctl_siwmode, /* SIOCSIWMODE */
2891 (iw_handler) rt_ioctl_giwmode, /* SIOCGIWMODE */
2892 (iw_handler) NULL, /* SIOCSIWSENS */
2893 (iw_handler) NULL, /* SIOCGIWSENS */
2894 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
2895 (iw_handler) rt_ioctl_giwrange, /* SIOCGIWRANGE */
2896 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
2897 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
2898 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
2899 (iw_handler) rt28xx_get_wireless_stats /* kernel code */, /* SIOCGIWSTATS */
2900 (iw_handler) NULL, /* SIOCSIWSPY */
2901 (iw_handler) NULL, /* SIOCGIWSPY */
2902 (iw_handler) NULL, /* SIOCSIWTHRSPY */
2903 (iw_handler) NULL, /* SIOCGIWTHRSPY */
2904 (iw_handler) rt_ioctl_siwap, /* SIOCSIWAP */
2905 (iw_handler) rt_ioctl_giwap, /* SIOCGIWAP */
2907 (iw_handler) rt_ioctl_siwmlme, /* SIOCSIWMLME */
2909 (iw_handler) NULL, /* SIOCSIWMLME */
2910 #endif // SIOCSIWMLME //
2911 (iw_handler) rt_ioctl_iwaplist, /* SIOCGIWAPLIST */
2913 (iw_handler) rt_ioctl_siwscan, /* SIOCSIWSCAN */
2914 (iw_handler) rt_ioctl_giwscan, /* SIOCGIWSCAN */
2916 (iw_handler) NULL, /* SIOCSIWSCAN */
2917 (iw_handler) NULL, /* SIOCGIWSCAN */
2918 #endif /* SIOCGIWSCAN */
2919 (iw_handler) rt_ioctl_siwessid, /* SIOCSIWESSID */
2920 (iw_handler) rt_ioctl_giwessid, /* SIOCGIWESSID */
2921 (iw_handler) rt_ioctl_siwnickn, /* SIOCSIWNICKN */
2922 (iw_handler) rt_ioctl_giwnickn, /* SIOCGIWNICKN */
2923 (iw_handler) NULL, /* -- hole -- */
2924 (iw_handler) NULL, /* -- hole -- */
2925 (iw_handler) rt_ioctl_siwrate, /* SIOCSIWRATE */
2926 (iw_handler) rt_ioctl_giwrate, /* SIOCGIWRATE */
2927 (iw_handler) rt_ioctl_siwrts, /* SIOCSIWRTS */
2928 (iw_handler) rt_ioctl_giwrts, /* SIOCGIWRTS */
2929 (iw_handler) rt_ioctl_siwfrag, /* SIOCSIWFRAG */
2930 (iw_handler) rt_ioctl_giwfrag, /* SIOCGIWFRAG */
2931 (iw_handler) NULL, /* SIOCSIWTXPOW */
2932 (iw_handler) NULL, /* SIOCGIWTXPOW */
2933 (iw_handler) NULL, /* SIOCSIWRETRY */
2934 (iw_handler) NULL, /* SIOCGIWRETRY */
2935 (iw_handler) rt_ioctl_siwencode, /* SIOCSIWENCODE */
2936 (iw_handler) rt_ioctl_giwencode, /* SIOCGIWENCODE */
2937 (iw_handler) NULL, /* SIOCSIWPOWER */
2938 (iw_handler) NULL, /* SIOCGIWPOWER */
2939 (iw_handler) NULL, /* -- hole -- */
2940 (iw_handler) NULL, /* -- hole -- */
2941 #if WIRELESS_EXT > 17
2942 (iw_handler) rt_ioctl_siwgenie, /* SIOCSIWGENIE */
2943 (iw_handler) rt_ioctl_giwgenie, /* SIOCGIWGENIE */
2944 (iw_handler) rt_ioctl_siwauth, /* SIOCSIWAUTH */
2945 (iw_handler) rt_ioctl_giwauth, /* SIOCGIWAUTH */
2946 (iw_handler) rt_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
2947 (iw_handler) rt_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */
2948 (iw_handler) rt_ioctl_siwpmksa, /* SIOCSIWPMKSA */
2952 static const iw_handler rt_priv_handlers[] = {
2953 (iw_handler) NULL, /* + 0x00 */
2954 (iw_handler) NULL, /* + 0x01 */
2955 #ifndef CONFIG_AP_SUPPORT
2956 (iw_handler) rt_ioctl_setparam, /* + 0x02 */
2958 (iw_handler) NULL, /* + 0x02 */
2959 #endif // CONFIG_AP_SUPPORT //
2961 (iw_handler) rt_private_ioctl_bbp, /* + 0x03 */
2963 (iw_handler) NULL, /* + 0x03 */
2965 (iw_handler) NULL, /* + 0x04 */
2966 (iw_handler) NULL, /* + 0x05 */
2967 (iw_handler) NULL, /* + 0x06 */
2968 (iw_handler) NULL, /* + 0x07 */
2969 (iw_handler) NULL, /* + 0x08 */
2970 (iw_handler) rt_private_get_statistics, /* + 0x09 */
2971 (iw_handler) NULL, /* + 0x0A */
2972 (iw_handler) NULL, /* + 0x0B */
2973 (iw_handler) NULL, /* + 0x0C */
2974 (iw_handler) NULL, /* + 0x0D */
2975 (iw_handler) NULL, /* + 0x0E */
2976 (iw_handler) NULL, /* + 0x0F */
2977 (iw_handler) NULL, /* + 0x10 */
2978 (iw_handler) rt_private_show, /* + 0x11 */
2979 (iw_handler) NULL, /* + 0x12 */
2980 (iw_handler) NULL, /* + 0x13 */
2981 (iw_handler) NULL, /* + 0x15 */
2982 (iw_handler) NULL, /* + 0x17 */
2983 (iw_handler) NULL, /* + 0x18 */
2986 const struct iw_handler_def rt28xx_iw_handler_def =
2988 #define N(a) (sizeof (a) / sizeof (a[0]))
2989 .standard = (iw_handler *) rt_handler,
2990 .num_standard = sizeof(rt_handler) / sizeof(iw_handler),
2991 .private = (iw_handler *) rt_priv_handlers,
2992 .num_private = N(rt_priv_handlers),
2993 .private_args = (struct iw_priv_args *) privtab,
2994 .num_private_args = N(privtab),
2995 #if IW_HANDLER_VERSION >= 7
2996 .get_wireless_stats = rt28xx_get_wireless_stats,
3000 INT RTMPSetInformation(
3001 IN PRTMP_ADAPTER pAdapter,
3002 IN OUT struct ifreq *rq,
3005 struct iwreq *wrq = (struct iwreq *) rq;
3006 NDIS_802_11_SSID Ssid;
3007 NDIS_802_11_MAC_ADDRESS Bssid;
3008 RT_802_11_PHY_MODE PhyMode;
3009 RT_802_11_STA_CONFIG StaConfig;
3010 NDIS_802_11_RATES aryRates;
3011 RT_802_11_PREAMBLE Preamble;
3012 NDIS_802_11_WEP_STATUS WepStatus;
3013 NDIS_802_11_AUTHENTICATION_MODE AuthMode = Ndis802_11AuthModeMax;
3014 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
3015 NDIS_802_11_RTS_THRESHOLD RtsThresh;
3016 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
3017 NDIS_802_11_POWER_MODE PowerMode;
3018 PNDIS_802_11_KEY pKey = NULL;
3019 PNDIS_802_11_WEP pWepKey =NULL;
3020 PNDIS_802_11_REMOVE_KEY pRemoveKey = NULL;
3021 NDIS_802_11_CONFIGURATION Config, *pConfig = NULL;
3022 NDIS_802_11_NETWORK_TYPE NetType;
3025 INT Status = NDIS_STATUS_SUCCESS, MaxPhyMode = PHY_11G;
3028 BOOLEAN StateMachineTouched = FALSE;
3029 OID_SET_HT_PHYMODE HT_PhyMode; //11n ,kathy
3030 PNDIS_802_11_PMKID pPmkId = NULL;
3031 BOOLEAN IEEE8021xState = FALSE;
3032 BOOLEAN IEEE8021x_required_keys = FALSE;
3033 UCHAR wpa_supplicant_enable = 0;
3035 MaxPhyMode = PHY_11N_5G;
3037 DBGPRINT(RT_DEBUG_TRACE, ("-->RTMPSetInformation(), 0x%08x\n", cmd&0x7FFF));
3038 switch(cmd & 0x7FFF) {
3039 case RT_OID_802_11_COUNTRY_REGION:
3040 if (wrq->u.data.length < sizeof(UCHAR))
3042 // Only avaliable when EEPROM not programming
3043 else if (!(pAdapter->CommonCfg.CountryRegion & 0x80) && !(pAdapter->CommonCfg.CountryRegionForABand & 0x80))
3048 Status = copy_from_user(&Country, wrq->u.data.pointer, wrq->u.data.length);
3049 pAdapter->CommonCfg.CountryRegion = (UCHAR)(Country & 0x000000FF);
3050 pAdapter->CommonCfg.CountryRegionForABand = (UCHAR)((Country >> 8) & 0x000000FF);
3051 TmpPhy = pAdapter->CommonCfg.PhyMode;
3052 pAdapter->CommonCfg.PhyMode = 0xff;
3053 // Build all corresponding channel information
3054 RTMPSetPhyMode(pAdapter, TmpPhy);
3055 SetCommonHT(pAdapter);
3056 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_COUNTRY_REGION (A:%d B/G:%d)\n", pAdapter->CommonCfg.CountryRegionForABand,
3057 pAdapter->CommonCfg.CountryRegion));
3060 case OID_802_11_BSSID_LIST_SCAN:
3062 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID_LIST_SCAN, TxCnt = %d \n", pAdapter->RalinkCounters.LastOneSecTotalTxCount));
3064 if (MONITOR_ON(pAdapter))
3066 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
3070 //Benson add 20080527, when radio off, sta don't need to scan
3071 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_RADIO_OFF))
3074 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
3076 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is scanning now !!!\n"));
3077 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
3078 Status = NDIS_STATUS_SUCCESS;
3082 if (pAdapter->RalinkCounters.LastOneSecTotalTxCount > 100)
3084 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
3085 Status = NDIS_STATUS_SUCCESS;
3086 pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
3090 if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
3091 ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
3092 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
3093 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
3094 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)) &&
3095 (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
3097 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
3098 Status = NDIS_STATUS_SUCCESS;
3099 pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
3104 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3106 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3107 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3110 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
3111 // this request, because this request is initiated by NDIS.
3112 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
3113 // Reset allowed scan retries
3114 pAdapter->StaCfg.ScanCnt = 0;
3115 pAdapter->StaCfg.LastScanTime = Now;
3117 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
3118 RTMP_SET_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
3119 MlmeEnqueue(pAdapter,
3120 MLME_CNTL_STATE_MACHINE,
3121 OID_802_11_BSSID_LIST_SCAN,
3125 Status = NDIS_STATUS_SUCCESS;
3126 StateMachineTouched = TRUE;
3128 case OID_802_11_SSID:
3129 if (wrq->u.data.length != sizeof(NDIS_802_11_SSID))
3133 PCHAR pSsidString = NULL;
3134 Status = copy_from_user(&Ssid, wrq->u.data.pointer, wrq->u.data.length);
3136 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SSID (Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
3137 if (Ssid.SsidLength > MAX_LEN_OF_SSID)
3141 if (Ssid.SsidLength == 0)
3143 Set_SSID_Proc(pAdapter, "");
3147 pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
3150 NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
3151 NdisMoveMemory(pSsidString, Ssid.Ssid, Ssid.SsidLength);
3152 Set_SSID_Proc(pAdapter, pSsidString);
3161 case OID_802_11_BSSID:
3162 if (wrq->u.data.length != sizeof(NDIS_802_11_MAC_ADDRESS))
3166 Status = copy_from_user(&Bssid, wrq->u.data.pointer, wrq->u.data.length);
3168 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
3169 // this request, because this request is initiated by NDIS.
3170 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
3172 // Prevent to connect AP again in STAMlmePeriodicExec
3173 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
3175 // Reset allowed scan retries
3176 pAdapter->StaCfg.ScanCnt = 0;
3178 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3180 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3181 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3183 MlmeEnqueue(pAdapter,
3184 MLME_CNTL_STATE_MACHINE,
3186 sizeof(NDIS_802_11_MAC_ADDRESS),
3188 Status = NDIS_STATUS_SUCCESS;
3189 StateMachineTouched = TRUE;
3191 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID %02x:%02x:%02x:%02x:%02x:%02x\n",
3192 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
3195 case RT_OID_802_11_RADIO:
3196 if (wrq->u.data.length != sizeof(BOOLEAN))
3200 Status = copy_from_user(&RadioState, wrq->u.data.pointer, wrq->u.data.length);
3201 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RADIO (=%d)\n", RadioState));
3202 if (pAdapter->StaCfg.bSwRadio != RadioState)
3204 pAdapter->StaCfg.bSwRadio = RadioState;
3205 if (pAdapter->StaCfg.bRadio != (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio))
3207 pAdapter->StaCfg.bRadio = (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio);
3208 if (pAdapter->StaCfg.bRadio == TRUE)
3210 MlmeRadioOn(pAdapter);
3211 // Update extra information
3212 pAdapter->ExtraInfo = EXTRA_INFO_CLEAR;
3216 MlmeRadioOff(pAdapter);
3217 // Update extra information
3218 pAdapter->ExtraInfo = SW_RADIO_OFF;
3224 case RT_OID_802_11_PHY_MODE:
3225 if (wrq->u.data.length != sizeof(RT_802_11_PHY_MODE))
3229 Status = copy_from_user(&PhyMode, wrq->u.data.pointer, wrq->u.data.length);
3230 if (PhyMode <= MaxPhyMode)
3232 RTMPSetPhyMode(pAdapter, PhyMode);
3233 SetCommonHT(pAdapter);
3235 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PHY_MODE (=%d)\n", PhyMode));
3238 case RT_OID_802_11_STA_CONFIG:
3239 if (wrq->u.data.length != sizeof(RT_802_11_STA_CONFIG))
3243 Status = copy_from_user(&StaConfig, wrq->u.data.pointer, wrq->u.data.length);
3244 pAdapter->CommonCfg.bEnableTxBurst = StaConfig.EnableTxBurst;
3245 pAdapter->CommonCfg.UseBGProtection = StaConfig.UseBGProtection;
3246 pAdapter->CommonCfg.bUseShortSlotTime = 1; // 2003-10-30 always SHORT SLOT capable
3247 if ((pAdapter->CommonCfg.PhyMode != StaConfig.AdhocMode) &&
3248 (StaConfig.AdhocMode <= MaxPhyMode))
3250 // allow dynamic change of "USE OFDM rate or not" in ADHOC mode
3251 // if setting changed, need to reset current TX rate as well as BEACON frame format
3252 pAdapter->CommonCfg.PhyMode = StaConfig.AdhocMode;
3253 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
3255 RTMPSetPhyMode(pAdapter, PhyMode);
3256 MlmeUpdateTxRates(pAdapter, FALSE, 0);
3257 MakeIbssBeacon(pAdapter); // re-build BEACON frame
3258 AsicEnableIbssSync(pAdapter); // copy to on-chip memory
3261 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_STA_CONFIG (Burst=%d, Protection=%ld,ShortSlot=%d\n",
3262 pAdapter->CommonCfg.bEnableTxBurst,
3263 pAdapter->CommonCfg.UseBGProtection,
3264 pAdapter->CommonCfg.bUseShortSlotTime));
3267 case OID_802_11_DESIRED_RATES:
3268 if (wrq->u.data.length != sizeof(NDIS_802_11_RATES))
3272 Status = copy_from_user(&aryRates, wrq->u.data.pointer, wrq->u.data.length);
3273 NdisZeroMemory(pAdapter->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES);
3274 NdisMoveMemory(pAdapter->CommonCfg.DesireRate, &aryRates, sizeof(NDIS_802_11_RATES));
3275 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DESIRED_RATES (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
3276 pAdapter->CommonCfg.DesireRate[0],pAdapter->CommonCfg.DesireRate[1],
3277 pAdapter->CommonCfg.DesireRate[2],pAdapter->CommonCfg.DesireRate[3],
3278 pAdapter->CommonCfg.DesireRate[4],pAdapter->CommonCfg.DesireRate[5],
3279 pAdapter->CommonCfg.DesireRate[6],pAdapter->CommonCfg.DesireRate[7] ));
3280 // Changing DesiredRate may affect the MAX TX rate we used to TX frames out
3281 MlmeUpdateTxRates(pAdapter, FALSE, 0);
3284 case RT_OID_802_11_PREAMBLE:
3285 if (wrq->u.data.length != sizeof(RT_802_11_PREAMBLE))
3289 Status = copy_from_user(&Preamble, wrq->u.data.pointer, wrq->u.data.length);
3290 if (Preamble == Rt802_11PreambleShort)
3292 pAdapter->CommonCfg.TxPreamble = Preamble;
3293 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleShort);
3295 else if ((Preamble == Rt802_11PreambleLong) || (Preamble == Rt802_11PreambleAuto))
3297 // if user wants AUTO, initialize to LONG here, then change according to AP's
3298 // capability upon association.
3299 pAdapter->CommonCfg.TxPreamble = Preamble;
3300 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleLong);
3307 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PREAMBLE (=%d)\n", Preamble));
3310 case OID_802_11_WEP_STATUS:
3311 if (wrq->u.data.length != sizeof(NDIS_802_11_WEP_STATUS))
3315 Status = copy_from_user(&WepStatus, wrq->u.data.pointer, wrq->u.data.length);
3316 // Since TKIP, AES, WEP are all supported. It should not have any invalid setting
3317 if (WepStatus <= Ndis802_11Encryption3KeyAbsent)
3319 if (pAdapter->StaCfg.WepStatus != WepStatus)
3321 // Config has changed
3322 pAdapter->bConfigChanged = TRUE;
3324 pAdapter->StaCfg.WepStatus = WepStatus;
3325 pAdapter->StaCfg.OrigWepStatus = WepStatus;
3326 pAdapter->StaCfg.PairCipher = WepStatus;
3327 pAdapter->StaCfg.GroupCipher = WepStatus;
3334 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEP_STATUS (=%d)\n",WepStatus));
3337 case OID_802_11_AUTHENTICATION_MODE:
3338 if (wrq->u.data.length != sizeof(NDIS_802_11_AUTHENTICATION_MODE))
3342 Status = copy_from_user(&AuthMode, wrq->u.data.pointer, wrq->u.data.length);
3343 if (AuthMode > Ndis802_11AuthModeMax)
3350 if (pAdapter->StaCfg.AuthMode != AuthMode)
3352 // Config has changed
3353 pAdapter->bConfigChanged = TRUE;
3355 pAdapter->StaCfg.AuthMode = AuthMode;
3357 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
3358 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_AUTHENTICATION_MODE (=%d) \n",pAdapter->StaCfg.AuthMode));
3361 case OID_802_11_INFRASTRUCTURE_MODE:
3362 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_INFRASTRUCTURE))
3366 Status = copy_from_user(&BssType, wrq->u.data.pointer, wrq->u.data.length);
3368 if (BssType == Ndis802_11IBSS)
3369 Set_NetworkType_Proc(pAdapter, "Adhoc");
3370 else if (BssType == Ndis802_11Infrastructure)
3371 Set_NetworkType_Proc(pAdapter, "Infra");
3372 else if (BssType == Ndis802_11Monitor)
3373 Set_NetworkType_Proc(pAdapter, "Monitor");
3377 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_INFRASTRUCTURE_MODE (unknown)\n"));
3381 case OID_802_11_REMOVE_WEP:
3382 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_WEP\n"));
3383 if (wrq->u.data.length != sizeof(NDIS_802_11_KEY_INDEX))
3389 KeyIdx = *(NDIS_802_11_KEY_INDEX *) wrq->u.data.pointer;
3391 if (KeyIdx & 0x80000000)
3393 // Should never set default bit when remove key
3398 KeyIdx = KeyIdx & 0x0fffffff;
3404 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
3405 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
3406 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
3411 case RT_OID_802_11_RESET_COUNTERS:
3412 NdisZeroMemory(&pAdapter->WlanCounters, sizeof(COUNTER_802_11));
3413 NdisZeroMemory(&pAdapter->Counters8023, sizeof(COUNTER_802_3));
3414 NdisZeroMemory(&pAdapter->RalinkCounters, sizeof(COUNTER_RALINK));
3415 pAdapter->Counters8023.RxNoBuffer = 0;
3416 pAdapter->Counters8023.GoodReceives = 0;
3417 pAdapter->Counters8023.RxNoBuffer = 0;
3419 pAdapter->BulkOutComplete = 0;
3420 pAdapter->BulkOutCompleteOther= 0;
3421 pAdapter->BulkOutCompleteCancel = 0;
3422 pAdapter->BulkOutReq = 0;
3423 pAdapter->BulkInReq= 0;
3424 pAdapter->BulkInComplete = 0;
3425 pAdapter->BulkInCompleteFail = 0;
3427 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RESET_COUNTERS \n"));
3429 case OID_802_11_RTS_THRESHOLD:
3430 if (wrq->u.data.length != sizeof(NDIS_802_11_RTS_THRESHOLD))
3434 Status = copy_from_user(&RtsThresh, wrq->u.data.pointer, wrq->u.data.length);
3435 if (RtsThresh > MAX_RTS_THRESHOLD)
3438 pAdapter->CommonCfg.RtsThreshold = (USHORT)RtsThresh;
3440 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_RTS_THRESHOLD (=%ld)\n",RtsThresh));
3442 case OID_802_11_FRAGMENTATION_THRESHOLD:
3443 if (wrq->u.data.length != sizeof(NDIS_802_11_FRAGMENTATION_THRESHOLD))
3447 Status = copy_from_user(&FragThresh, wrq->u.data.pointer, wrq->u.data.length);
3448 pAdapter->CommonCfg.bUseZeroToDisableFragment = FALSE;
3449 if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
3451 if (FragThresh == 0)
3453 pAdapter->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
3454 pAdapter->CommonCfg.bUseZeroToDisableFragment = TRUE;
3460 pAdapter->CommonCfg.FragmentThreshold = (USHORT)FragThresh;
3462 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_FRAGMENTATION_THRESHOLD (=%ld) \n",FragThresh));
3464 case OID_802_11_POWER_MODE:
3465 if (wrq->u.data.length != sizeof(NDIS_802_11_POWER_MODE))
3469 Status = copy_from_user(&PowerMode, wrq->u.data.pointer, wrq->u.data.length);
3470 if (PowerMode == Ndis802_11PowerModeCAM)
3471 Set_PSMode_Proc(pAdapter, "CAM");
3472 else if (PowerMode == Ndis802_11PowerModeMAX_PSP)
3473 Set_PSMode_Proc(pAdapter, "Max_PSP");
3474 else if (PowerMode == Ndis802_11PowerModeFast_PSP)
3475 Set_PSMode_Proc(pAdapter, "Fast_PSP");
3476 else if (PowerMode == Ndis802_11PowerModeLegacy_PSP)
3477 Set_PSMode_Proc(pAdapter, "Legacy_PSP");
3481 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_POWER_MODE (=%d)\n",PowerMode));
3483 case RT_OID_802_11_TX_POWER_LEVEL_1:
3484 if (wrq->u.data.length < sizeof(ULONG))
3488 Status = copy_from_user(&PowerTemp, wrq->u.data.pointer, wrq->u.data.length);
3489 if (PowerTemp > 100)
3490 PowerTemp = 0xffffffff; // AUTO
3491 pAdapter->CommonCfg.TxPowerDefault = PowerTemp; //keep current setting.
3492 pAdapter->CommonCfg.TxPowerPercentage = pAdapter->CommonCfg.TxPowerDefault;
3493 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
3496 case OID_802_11_NETWORK_TYPE_IN_USE:
3497 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_TYPE))
3501 Status = copy_from_user(&NetType, wrq->u.data.pointer, wrq->u.data.length);
3503 if (NetType == Ndis802_11DS)
3504 RTMPSetPhyMode(pAdapter, PHY_11B);
3505 else if (NetType == Ndis802_11OFDM24)
3506 RTMPSetPhyMode(pAdapter, PHY_11BG_MIXED);
3507 else if (NetType == Ndis802_11OFDM5)
3508 RTMPSetPhyMode(pAdapter, PHY_11A);
3512 if (Status == NDIS_STATUS_SUCCESS)
3513 SetCommonHT(pAdapter);
3515 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_NETWORK_TYPE_IN_USE (=%d)\n",NetType));
3518 // For WPA PSK PMK key
3519 case RT_OID_802_11_ADD_WPA:
3520 pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3527 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
3528 if (pKey->Length != wrq->u.data.length)
3531 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!!\n"));
3535 if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
3536 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
3537 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone) )
3539 Status = -EOPNOTSUPP;
3540 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!! [AuthMode != WPAPSK/WPA2PSK/WPANONE]\n"));
3542 else if ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
3543 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
3544 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) ) // Only for WPA PSK mode
3546 NdisMoveMemory(pAdapter->StaCfg.PMK, &pKey->KeyMaterial, pKey->KeyLength);
3547 // Use RaConfig as PSK agent.
3548 // Start STA supplicant state machine
3549 if (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
3550 pAdapter->StaCfg.WpaState = SS_START;
3552 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3556 pAdapter->StaCfg.WpaState = SS_NOTUSE;
3557 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3562 case OID_802_11_REMOVE_KEY:
3563 pRemoveKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3564 if(pRemoveKey == NULL)
3570 Status = copy_from_user(pRemoveKey, wrq->u.data.pointer, wrq->u.data.length);
3571 if (pRemoveKey->Length != wrq->u.data.length)
3574 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!\n"));
3578 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3580 RTMPWPARemoveKeyProc(pAdapter, pRemoveKey);
3581 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Remove WPA Key!!\n"));
3585 KeyIdx = pRemoveKey->KeyIndex;
3587 if (KeyIdx & 0x80000000)
3589 // Should never set default bit when remove key
3591 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(Should never set default bit when remove key)\n"));
3595 KeyIdx = KeyIdx & 0x0fffffff;
3599 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(KeyId[%d] out of range)\n", KeyIdx));
3603 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
3604 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
3605 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
3606 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY (id=0x%x, Len=%d-byte)\n", pRemoveKey->KeyIndex, pRemoveKey->Length));
3614 case OID_802_11_ADD_KEY:
3615 pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3621 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
3622 if (pKey->Length != wrq->u.data.length)
3625 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY, Failed!!\n"));
3629 RTMPAddKey(pAdapter, pKey);
3630 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3634 case OID_802_11_CONFIGURATION:
3635 if (wrq->u.data.length != sizeof(NDIS_802_11_CONFIGURATION))
3639 Status = copy_from_user(&Config, wrq->u.data.pointer, wrq->u.data.length);
3642 if ((pConfig->BeaconPeriod >= 20) && (pConfig->BeaconPeriod <=400))
3643 pAdapter->CommonCfg.BeaconPeriod = (USHORT) pConfig->BeaconPeriod;
3645 pAdapter->StaActive.AtimWin = (USHORT) pConfig->ATIMWindow;
3646 MAP_KHZ_TO_CHANNEL_ID(pConfig->DSConfig, pAdapter->CommonCfg.Channel);
3648 // Save the channel on MlmeAux for CntlOidRTBssidProc used.
3650 pAdapter->MlmeAux.Channel = pAdapter->CommonCfg.Channel;
3652 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_CONFIGURATION (BeacnPeriod=%ld,AtimW=%ld,Ch=%d)\n",
3653 pConfig->BeaconPeriod, pConfig->ATIMWindow, pAdapter->CommonCfg.Channel));
3654 // Config has changed
3655 pAdapter->bConfigChanged = TRUE;
3658 case RT_OID_802_11_SET_HT_PHYMODE:
3659 if (wrq->u.data.length != sizeof(OID_SET_HT_PHYMODE))
3663 POID_SET_HT_PHYMODE pHTPhyMode = &HT_PhyMode;
3665 Status = copy_from_user(&HT_PhyMode, wrq->u.data.pointer, wrq->u.data.length);
3666 DBGPRINT(RT_DEBUG_TRACE, ("Set::pHTPhyMode (PhyMode = %d,TransmitNo = %d, HtMode = %d, ExtOffset = %d , MCS = %d, BW = %d, STBC = %d, SHORTGI = %d) \n",
3667 pHTPhyMode->PhyMode, pHTPhyMode->TransmitNo,pHTPhyMode->HtMode,pHTPhyMode->ExtOffset,
3668 pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->SHORTGI));
3669 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
3670 RTMPSetHT(pAdapter, pHTPhyMode);
3672 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_HT_PHYMODE(MCS=%d,BW=%d,SGI=%d,STBC=%d)\n",
3673 pAdapter->StaCfg.HTPhyMode.field.MCS, pAdapter->StaCfg.HTPhyMode.field.BW, pAdapter->StaCfg.HTPhyMode.field.ShortGI,
3674 pAdapter->StaCfg.HTPhyMode.field.STBC));
3676 case RT_OID_802_11_SET_APSD_SETTING:
3677 if (wrq->u.data.length != sizeof(ULONG))
3682 Status = copy_from_user(&apsd, wrq->u.data.pointer, wrq->u.data.length);
3684 /*-------------------------------------------------------------------
3685 |B31~B7 | B6~B5 | B4 | B3 | B2 | B1 | B0 |
3686 ---------------------------------------------------------------------
3687 | Rsvd | Max SP Len | AC_VO | AC_VI | AC_BK | AC_BE | APSD Capable |
3688 ---------------------------------------------------------------------*/
3689 pAdapter->CommonCfg.bAPSDCapable = (apsd & 0x00000001) ? TRUE : FALSE;
3690 pAdapter->CommonCfg.bAPSDAC_BE = ((apsd & 0x00000002) >> 1) ? TRUE : FALSE;
3691 pAdapter->CommonCfg.bAPSDAC_BK = ((apsd & 0x00000004) >> 2) ? TRUE : FALSE;
3692 pAdapter->CommonCfg.bAPSDAC_VI = ((apsd & 0x00000008) >> 3) ? TRUE : FALSE;
3693 pAdapter->CommonCfg.bAPSDAC_VO = ((apsd & 0x00000010) >> 4) ? TRUE : FALSE;
3694 pAdapter->CommonCfg.MaxSPLength = (UCHAR)((apsd & 0x00000060) >> 5);
3696 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,
3697 pAdapter->CommonCfg.bAPSDAC_BE, pAdapter->CommonCfg.bAPSDAC_BK, pAdapter->CommonCfg.bAPSDAC_VI, pAdapter->CommonCfg.bAPSDAC_VO, pAdapter->CommonCfg.MaxSPLength));
3701 case RT_OID_802_11_SET_APSD_PSM:
3702 if (wrq->u.data.length != sizeof(ULONG))
3706 // Driver needs to notify AP when PSM changes
3707 Status = copy_from_user(&pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.pointer, wrq->u.data.length);
3708 if (pAdapter->CommonCfg.bAPSDForcePowerSave != pAdapter->StaCfg.Psm)
3710 MlmeSetPsmBit(pAdapter, pAdapter->CommonCfg.bAPSDForcePowerSave);
3711 RTMPSendNullFrame(pAdapter, pAdapter->CommonCfg.TxRate, TRUE);
3713 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_APSD_PSM (bAPSDForcePowerSave:%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
3717 case RT_OID_802_11_SET_WMM:
3718 if (wrq->u.data.length != sizeof(BOOLEAN))
3722 Status = copy_from_user(&pAdapter->CommonCfg.bWmmCapable, wrq->u.data.pointer, wrq->u.data.length);
3723 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_WMM (=%d) \n", pAdapter->CommonCfg.bWmmCapable));
3727 case OID_802_11_DISASSOCIATE:
3729 // Set NdisRadioStateOff to TRUE, instead of called MlmeRadioOff.
3730 // Later on, NDIS_802_11_BSSID_LIST_EX->NumberOfItems should be 0
3731 // when query OID_802_11_BSSID_LIST.
3733 // TRUE: NumberOfItems will set to 0.
3734 // FALSE: NumberOfItems no change.
3736 pAdapter->CommonCfg.NdisRadioStateOff = TRUE;
3737 // Set to immediately send the media disconnect event
3738 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
3739 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DISASSOCIATE \n"));
3741 if (INFRA_ON(pAdapter))
3743 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3745 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3746 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3749 MlmeEnqueue(pAdapter,
3750 MLME_CNTL_STATE_MACHINE,
3751 OID_802_11_DISASSOCIATE,
3755 StateMachineTouched = TRUE;
3758 case RT_OID_802_11_SET_IMME_BA_CAP:
3759 if (wrq->u.data.length != sizeof(OID_BACAP_STRUC))
3763 OID_BACAP_STRUC Orde ;
3764 Status = copy_from_user(&Orde, wrq->u.data.pointer, wrq->u.data.length);
3765 if (Orde.Policy > BA_NOTUSE)
3767 Status = NDIS_STATUS_INVALID_DATA;
3769 else if (Orde.Policy == BA_NOTUSE)
3771 pAdapter->CommonCfg.BACapability.field.Policy = BA_NOTUSE;
3772 pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
3773 pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
3774 pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
3775 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
3776 pAdapter->CommonCfg.DesiredHtPhy.MimoPs= Orde.MMPSmode;
3777 pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
3779 pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
3780 pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
3781 pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
3785 pAdapter->CommonCfg.BACapability.field.AutoBA = Orde.AutoBA;
3786 pAdapter->CommonCfg.BACapability.field.Policy = IMMED_BA; // we only support immediate BA.
3787 pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
3788 pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
3789 pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
3790 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
3791 pAdapter->CommonCfg.DesiredHtPhy.MimoPs = Orde.MMPSmode;
3792 pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
3795 pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
3796 pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
3797 pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
3799 if (pAdapter->CommonCfg.BACapability.field.RxBAWinLimit > MAX_RX_REORDERBUF)
3800 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = MAX_RX_REORDERBUF;
3804 pAdapter->CommonCfg.REGBACapability.word = pAdapter->CommonCfg.BACapability.word;
3805 DBGPRINT(RT_DEBUG_TRACE, ("Set::(Orde.AutoBA = %d) (Policy=%d)(ReBAWinLimit=%d)(TxBAWinLimit=%d)(AutoMode=%d)\n",Orde.AutoBA, pAdapter->CommonCfg.BACapability.field.Policy,
3806 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit,pAdapter->CommonCfg.BACapability.field.TxBAWinLimit, pAdapter->CommonCfg.BACapability.field.AutoBA));
3807 DBGPRINT(RT_DEBUG_TRACE, ("Set::(MimoPs = %d)(AmsduEnable = %d) (AmsduSize=%d)(MpduDensity=%d)\n",pAdapter->CommonCfg.DesiredHtPhy.MimoPs, pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable,
3808 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize, pAdapter->CommonCfg.DesiredHtPhy.MpduDensity));
3812 case RT_OID_802_11_ADD_IMME_BA:
3813 DBGPRINT(RT_DEBUG_TRACE, (" Set :: RT_OID_802_11_ADD_IMME_BA \n"));
3814 if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
3819 OID_ADD_BA_ENTRY BA;
3820 MAC_TABLE_ENTRY *pEntry;
3822 Status = copy_from_user(&BA, wrq->u.data.pointer, wrq->u.data.length);
3825 Status = NDIS_STATUS_INVALID_DATA;
3830 //BATableInsertEntry
3831 //As ad-hoc mode, BA pair is not limited to only BSSID. so add via OID.
3833 // in ad hoc mode, when adding BA pair, we should insert this entry into MACEntry too
3834 pEntry = MacTableLookup(pAdapter, BA.MACAddr);
3837 DBGPRINT(RT_DEBUG_TRACE, ("RT_OID_802_11_ADD_IMME_BA. break on no connection.----:%x:%x\n", BA.MACAddr[4], BA.MACAddr[5]));
3840 if (BA.IsRecipient == FALSE)
3842 if (pEntry->bIAmBadAtheros == TRUE)
3843 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = 0x10;
3845 BAOriSessionSetUp(pAdapter, pEntry, index, 0, 100, TRUE);
3849 //BATableInsertEntry(pAdapter, pEntry->Aid, BA.MACAddr, 0, 0xffff, BA.TID, BA.nMSDU, BA.IsRecipient);
3852 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_IMME_BA. Rec = %d. Mac = %x:%x:%x:%x:%x:%x . \n",
3853 BA.IsRecipient, BA.MACAddr[0], BA.MACAddr[1], BA.MACAddr[2], BA.MACAddr[2]
3854 , BA.MACAddr[4], BA.MACAddr[5]));
3859 case RT_OID_802_11_TEAR_IMME_BA:
3860 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA \n"));
3861 if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
3865 POID_ADD_BA_ENTRY pBA;
3866 MAC_TABLE_ENTRY *pEntry;
3868 pBA = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3872 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA kmalloc() can't allocate enough memory\n"));
3873 Status = NDIS_STATUS_FAILURE;
3877 Status = copy_from_user(pBA, wrq->u.data.pointer, wrq->u.data.length);
3878 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA(TID=%d, bAllTid=%d)\n", pBA->TID, pBA->bAllTid));
3880 if (!pBA->bAllTid && (pBA->TID > NUM_OF_TID))
3882 Status = NDIS_STATUS_INVALID_DATA;
3886 if (pBA->IsRecipient == FALSE)
3888 pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
3889 DBGPRINT(RT_DEBUG_TRACE, (" pBA->IsRecipient == FALSE\n"));
3892 DBGPRINT(RT_DEBUG_TRACE, (" pBA->pEntry\n"));
3893 BAOriSessionTearDown(pAdapter, pEntry->Aid, pBA->TID, FALSE, TRUE);
3896 DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
3900 pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
3903 BARecSessionTearDown( pAdapter, (UCHAR)pEntry->Aid, pBA->TID, TRUE);
3906 DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
3912 // For WPA_SUPPLICANT to set static wep key
3913 case OID_802_11_ADD_WEP:
3914 pWepKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3919 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed!!\n"));
3922 Status = copy_from_user(pWepKey, wrq->u.data.pointer, wrq->u.data.length);
3926 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (length mismatch)!!\n"));
3930 KeyIdx = pWepKey->KeyIndex & 0x0fffffff;
3931 // KeyIdx must be 0 ~ 3
3935 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (KeyIdx must be smaller than 4)!!\n"));
3939 UCHAR CipherAlg = 0;
3942 // set key material and key length
3943 NdisZeroMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, 16);
3944 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
3945 NdisMoveMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
3947 switch(pWepKey->KeyLength)
3950 CipherAlg = CIPHER_WEP64;
3953 CipherAlg = CIPHER_WEP128;
3956 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, only support CIPHER_WEP64(len:5) & CIPHER_WEP128(len:13)!!\n"));
3960 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CipherAlg;
3962 // Default key for tx (shared key)
3963 if (pWepKey->KeyIndex & 0x80000000)
3965 // set key material and key length
3966 NdisZeroMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, 16);
3967 pAdapter->StaCfg.DesireSharedKey[KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
3968 NdisMoveMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
3969 pAdapter->StaCfg.DesireSharedKeyId = KeyIdx;
3970 pAdapter->StaCfg.DesireSharedKey[KeyIdx].CipherAlg = CipherAlg;
3971 pAdapter->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
3974 if (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)
3976 Key = pAdapter->SharedKey[BSS0][KeyIdx].Key;
3978 // Set key material and cipherAlg to Asic
3979 AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
3981 if (pWepKey->KeyIndex & 0x80000000)
3983 PMAC_TABLE_ENTRY pEntry = &pAdapter->MacTab.Content[BSSID_WCID];
3984 // Assign group key info
3985 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
3986 // Assign pairwise key info
3987 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, pEntry);
3990 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"));
3995 case OID_SET_COUNTERMEASURES:
3996 if (wrq->u.data.length != sizeof(int))
4001 Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
4003 pAdapter->StaCfg.bBlockAssoc = TRUE;
4005 // WPA MIC error should block association attempt for 60 seconds
4006 pAdapter->StaCfg.bBlockAssoc = FALSE;
4007 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_SET_COUNTERMEASURES bBlockAssoc=%s\n", pAdapter->StaCfg.bBlockAssoc ? "TRUE":"FALSE"));
4010 case RT_OID_WPA_SUPPLICANT_SUPPORT:
4011 if (wrq->u.data.length != sizeof(UCHAR))
4015 Status = copy_from_user(&wpa_supplicant_enable, wrq->u.data.pointer, wrq->u.data.length);
4016 pAdapter->StaCfg.WpaSupplicantUP = wpa_supplicant_enable;
4017 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
4020 case OID_802_11_DEAUTHENTICATION:
4021 if (wrq->u.data.length != sizeof(MLME_DEAUTH_REQ_STRUCT))
4025 MLME_DEAUTH_REQ_STRUCT *pInfo;
4026 MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
4028 pInfo = (MLME_DEAUTH_REQ_STRUCT *) MsgElem->Msg;
4029 Status = copy_from_user(pInfo, wrq->u.data.pointer, wrq->u.data.length);
4030 MlmeDeauthReqAction(pAdapter, MsgElem);
4033 if (INFRA_ON(pAdapter))
4035 LinkDown(pAdapter, FALSE);
4036 pAdapter->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
4038 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DEAUTHENTICATION (Reason=%d)\n", pInfo->Reason));
4041 case OID_802_11_DROP_UNENCRYPTED:
4042 if (wrq->u.data.length != sizeof(int))
4047 Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
4049 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
4051 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
4052 NdisAcquireSpinLock(&pAdapter->MacTabLock);
4053 pAdapter->MacTab.Content[BSSID_WCID].PortSecured = pAdapter->StaCfg.PortSecured;
4054 NdisReleaseSpinLock(&pAdapter->MacTabLock);
4055 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DROP_UNENCRYPTED (=%d)\n", enabled));
4058 case OID_802_11_SET_IEEE8021X:
4059 if (wrq->u.data.length != sizeof(BOOLEAN))
4063 Status = copy_from_user(&IEEE8021xState, wrq->u.data.pointer, wrq->u.data.length);
4064 pAdapter->StaCfg.IEEE8021X = IEEE8021xState;
4065 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X (=%d)\n", IEEE8021xState));
4068 case OID_802_11_SET_IEEE8021X_REQUIRE_KEY:
4069 if (wrq->u.data.length != sizeof(BOOLEAN))
4073 Status = copy_from_user(&IEEE8021x_required_keys, wrq->u.data.pointer, wrq->u.data.length);
4074 pAdapter->StaCfg.IEEE8021x_required_keys = IEEE8021x_required_keys;
4075 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X_REQUIRE_KEY (%d)\n", IEEE8021x_required_keys));
4078 case OID_802_11_PMKID:
4079 pPmkId = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4081 if(pPmkId == NULL) {
4085 Status = copy_from_user(pPmkId, wrq->u.data.pointer, wrq->u.data.length);
4087 // check the PMKID information
4088 if (pPmkId->BSSIDInfoCount == 0)
4089 NdisZeroMemory(pAdapter->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
4092 PBSSID_INFO pBssIdInfo;
4096 for (BssIdx = 0; BssIdx < pPmkId->BSSIDInfoCount; BssIdx++)
4098 // point to the indexed BSSID_INFO structure
4099 pBssIdInfo = (PBSSID_INFO) ((PUCHAR) pPmkId + 2 * sizeof(UINT) + BssIdx * sizeof(BSSID_INFO));
4100 // Find the entry in the saved data base.
4101 for (CachedIdx = 0; CachedIdx < pAdapter->StaCfg.SavedPMKNum; CachedIdx++)
4103 // compare the BSSID
4104 if (NdisEqualMemory(pBssIdInfo->BSSID, pAdapter->StaCfg.SavedPMK[CachedIdx].BSSID, sizeof(NDIS_802_11_MAC_ADDRESS)))
4108 // Found, replace it
4109 if (CachedIdx < PMKID_NO)
4111 DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
4112 NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
4113 pAdapter->StaCfg.SavedPMKNum++;
4115 // Not found, replace the last one
4118 // Randomly replace one
4119 CachedIdx = (pBssIdInfo->BSSID[5] % PMKID_NO);
4120 DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
4121 NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
4129 DBGPRINT(RT_DEBUG_TRACE, ("Set::unknown IOCTL's subcmd = 0x%08x\n", cmd));
4130 Status = -EOPNOTSUPP;
4138 INT RTMPQueryInformation(
4139 IN PRTMP_ADAPTER pAdapter,
4140 IN OUT struct ifreq *rq,
4143 struct iwreq *wrq = (struct iwreq *) rq;
4144 NDIS_802_11_BSSID_LIST_EX *pBssidList = NULL;
4145 PNDIS_WLAN_BSSID_EX pBss;
4146 NDIS_802_11_SSID Ssid;
4147 NDIS_802_11_CONFIGURATION *pConfiguration = NULL;
4148 RT_802_11_LINK_STATUS *pLinkStatus = NULL;
4149 RT_802_11_STA_CONFIG *pStaConfig = NULL;
4150 NDIS_802_11_STATISTICS *pStatistics = NULL;
4151 NDIS_802_11_RTS_THRESHOLD RtsThresh;
4152 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
4153 NDIS_802_11_POWER_MODE PowerMode;
4154 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
4155 RT_802_11_PREAMBLE PreamType;
4156 NDIS_802_11_AUTHENTICATION_MODE AuthMode;
4157 NDIS_802_11_WEP_STATUS WepStatus;
4158 NDIS_MEDIA_STATE MediaState;
4159 ULONG BssBufSize, ulInfo=0, NetworkTypeList[4], apsd = 0;
4161 PUCHAR pBuf = NULL, pPtr;
4162 INT Status = NDIS_STATUS_SUCCESS;
4163 UINT we_version_compiled;
4164 UCHAR i, Padding = 0;
4166 UCHAR driverVersion[8];
4167 OID_SET_HT_PHYMODE *pHTPhyMode = NULL;
4171 case RT_OID_DEVICE_NAME:
4172 wrq->u.data.length = sizeof(STA_NIC_DEVICE_NAME);
4173 Status = copy_to_user(wrq->u.data.pointer, STA_NIC_DEVICE_NAME, wrq->u.data.length);
4175 case RT_OID_VERSION_INFO:
4176 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_VERSION_INFO \n"));
4177 wrq->u.data.length = 8*sizeof(UCHAR);
4178 sprintf(&driverVersion[0], "%s", STA_DRIVER_VERSION);
4179 driverVersion[7] = '\0';
4180 if (copy_to_user(wrq->u.data.pointer, &driverVersion, wrq->u.data.length))
4185 case OID_802_11_BSSID_LIST:
4186 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
4189 * Still scanning, indicate the caller should try again.
4191 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (Still scanning)\n"));
4194 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (%d BSS returned)\n",pAdapter->ScanTab.BssNr));
4195 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
4196 // Claculate total buffer size required
4197 BssBufSize = sizeof(ULONG);
4199 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
4201 // Align pointer to 4 bytes boundary.
4202 //Padding = 4 - (pAdapter->ScanTab.BssEntry[i].VarIELen & 0x0003);
4205 BssBufSize += (sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
4208 // For safety issue, we add 256 bytes just in case
4210 // Allocate the same size as passed from higher layer
4211 pBuf = kmalloc(BssBufSize, MEM_ALLOC_FLAG);
4217 // Init 802_11_BSSID_LIST_EX structure
4218 NdisZeroMemory(pBuf, BssBufSize);
4219 pBssidList = (PNDIS_802_11_BSSID_LIST_EX) pBuf;
4220 pBssidList->NumberOfItems = pAdapter->ScanTab.BssNr;
4222 // Calculate total buffer length
4223 BssLen = 4; // Consist of NumberOfItems
4224 // Point to start of NDIS_WLAN_BSSID_EX
4225 // pPtr = pBuf + sizeof(ULONG);
4226 pPtr = (PUCHAR) &pBssidList->Bssid[0];
4227 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
4229 pBss = (PNDIS_WLAN_BSSID_EX) pPtr;
4230 NdisMoveMemory(&pBss->MacAddress, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
4231 if ((pAdapter->ScanTab.BssEntry[i].Hidden == 1) && (pAdapter->StaCfg.bShowHiddenSSID == FALSE))
4234 // We must return this SSID during 4way handshaking, otherwise Aegis will failed to parse WPA infomation
4235 // and then failed to send EAPOl farame.
4237 if ((pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) && (pAdapter->StaCfg.PortSecured != WPA_802_1X_PORT_SECURED))
4239 pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
4240 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
4243 pBss->Ssid.SsidLength = 0;
4247 pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
4248 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
4250 pBss->Privacy = pAdapter->ScanTab.BssEntry[i].Privacy;
4251 pBss->Rssi = pAdapter->ScanTab.BssEntry[i].Rssi - pAdapter->BbpRssiToDbmDelta;
4252 pBss->NetworkTypeInUse = NetworkTypeInUseSanity(&pAdapter->ScanTab.BssEntry[i]);
4253 pBss->Configuration.Length = sizeof(NDIS_802_11_CONFIGURATION);
4254 pBss->Configuration.BeaconPeriod = pAdapter->ScanTab.BssEntry[i].BeaconPeriod;
4255 pBss->Configuration.ATIMWindow = pAdapter->ScanTab.BssEntry[i].AtimWin;
4257 MAP_CHANNEL_ID_TO_KHZ(pAdapter->ScanTab.BssEntry[i].Channel, pBss->Configuration.DSConfig);
4259 if (pAdapter->ScanTab.BssEntry[i].BssType == BSS_INFRA)
4260 pBss->InfrastructureMode = Ndis802_11Infrastructure;
4262 pBss->InfrastructureMode = Ndis802_11IBSS;
4264 NdisMoveMemory(pBss->SupportedRates, pAdapter->ScanTab.BssEntry[i].SupRate, pAdapter->ScanTab.BssEntry[i].SupRateLen);
4265 NdisMoveMemory(pBss->SupportedRates + pAdapter->ScanTab.BssEntry[i].SupRateLen,
4266 pAdapter->ScanTab.BssEntry[i].ExtRate,
4267 pAdapter->ScanTab.BssEntry[i].ExtRateLen);
4269 if (pAdapter->ScanTab.BssEntry[i].VarIELen == 0)
4271 pBss->IELength = sizeof(NDIS_802_11_FIXED_IEs);
4272 NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
4273 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
4277 pBss->IELength = (ULONG)(sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen);
4278 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
4279 NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
4280 NdisMoveMemory(pBss->IEs + sizeof(NDIS_802_11_FIXED_IEs), pAdapter->ScanTab.BssEntry[i].VarIEs, pAdapter->ScanTab.BssEntry[i].VarIELen);
4281 pPtr += pAdapter->ScanTab.BssEntry[i].VarIELen;
4283 pBss->Length = (ULONG)(sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
4285 #if WIRELESS_EXT < 17
4286 if ((BssLen + pBss->Length) < wrq->u.data.length)
4287 BssLen += pBss->Length;
4290 pBssidList->NumberOfItems = i;
4294 BssLen += pBss->Length;
4298 #if WIRELESS_EXT < 17
4299 wrq->u.data.length = BssLen;
4301 if (BssLen > wrq->u.data.length)
4307 wrq->u.data.length = BssLen;
4309 Status = copy_to_user(wrq->u.data.pointer, pBssidList, BssLen);
4312 case OID_802_3_CURRENT_ADDRESS:
4313 wrq->u.data.length = MAC_ADDR_LEN;
4314 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
4316 case OID_GEN_MEDIA_CONNECT_STATUS:
4317 if (pAdapter->IndicateMediaState == NdisMediaStateConnected)
4318 MediaState = NdisMediaStateConnected;
4320 MediaState = NdisMediaStateDisconnected;
4322 wrq->u.data.length = sizeof(NDIS_MEDIA_STATE);
4323 Status = copy_to_user(wrq->u.data.pointer, &MediaState, wrq->u.data.length);
4325 case OID_802_11_BSSID:
4326 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
4328 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Bssid, sizeof(NDIS_802_11_MAC_ADDRESS));
4333 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID(=EMPTY)\n"));
4337 case OID_802_11_SSID:
4338 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
4339 NdisZeroMemory(Ssid.Ssid, MAX_LEN_OF_SSID);
4340 Ssid.SsidLength = pAdapter->CommonCfg.SsidLen;
4341 memcpy(Ssid.Ssid, pAdapter->CommonCfg.Ssid, Ssid.SsidLength);
4342 wrq->u.data.length = sizeof(NDIS_802_11_SSID);
4343 Status = copy_to_user(wrq->u.data.pointer, &Ssid, wrq->u.data.length);
4344 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_SSID (Len=%d, ssid=%s)\n", Ssid.SsidLength,Ssid.Ssid));
4346 case RT_OID_802_11_QUERY_LINK_STATUS:
4347 pLinkStatus = (RT_802_11_LINK_STATUS *) kmalloc(sizeof(RT_802_11_LINK_STATUS), MEM_ALLOC_FLAG);
4350 pLinkStatus->CurrTxRate = RateIdTo500Kbps[pAdapter->CommonCfg.TxRate]; // unit : 500 kbps
4351 pLinkStatus->ChannelQuality = pAdapter->Mlme.ChannelQuality;
4352 pLinkStatus->RxByteCount = pAdapter->RalinkCounters.ReceivedByteCount;
4353 pLinkStatus->TxByteCount = pAdapter->RalinkCounters.TransmittedByteCount;
4354 pLinkStatus->CentralChannel = pAdapter->CommonCfg.CentralChannel;
4355 wrq->u.data.length = sizeof(RT_802_11_LINK_STATUS);
4356 Status = copy_to_user(wrq->u.data.pointer, pLinkStatus, wrq->u.data.length);
4358 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS\n"));
4362 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS(kmalloc failed)\n"));
4366 case OID_802_11_CONFIGURATION:
4367 pConfiguration = (NDIS_802_11_CONFIGURATION *) kmalloc(sizeof(NDIS_802_11_CONFIGURATION), MEM_ALLOC_FLAG);
4370 pConfiguration->Length = sizeof(NDIS_802_11_CONFIGURATION);
4371 pConfiguration->BeaconPeriod = pAdapter->CommonCfg.BeaconPeriod;
4372 pConfiguration->ATIMWindow = pAdapter->StaActive.AtimWin;
4373 MAP_CHANNEL_ID_TO_KHZ(pAdapter->CommonCfg.Channel, pConfiguration->DSConfig);
4374 wrq->u.data.length = sizeof(NDIS_802_11_CONFIGURATION);
4375 Status = copy_to_user(wrq->u.data.pointer, pConfiguration, wrq->u.data.length);
4376 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(BeaconPeriod=%ld,AtimW=%ld,Channel=%d) \n",
4377 pConfiguration->BeaconPeriod, pConfiguration->ATIMWindow, pAdapter->CommonCfg.Channel));
4378 kfree(pConfiguration);
4382 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(kmalloc failed)\n"));
4386 case RT_OID_802_11_SNR_0:
4387 if ((pAdapter->StaCfg.LastSNR0 > 0))
4389 ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR0) * 3) / 16 ;
4390 wrq->u.data.length = sizeof(ulInfo);
4391 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4392 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_SNR_0(0x=%lx)\n", ulInfo));
4397 case RT_OID_802_11_SNR_1:
4398 if ((pAdapter->Antenna.field.RxPath > 1) &&
4399 (pAdapter->StaCfg.LastSNR1 > 0))
4401 ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR1) * 3) / 16 ;
4402 wrq->u.data.length = sizeof(ulInfo);
4403 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4404 DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(0x=%lx)\n",ulInfo));
4408 DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(pAdapter->StaCfg.LastSNR1=%d)\n",pAdapter->StaCfg.LastSNR1));
4410 case OID_802_11_RSSI_TRIGGER:
4411 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0 - pAdapter->BbpRssiToDbmDelta;
4412 wrq->u.data.length = sizeof(ulInfo);
4413 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4414 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RSSI_TRIGGER(=%ld)\n", ulInfo));
4416 case OID_802_11_RSSI:
4417 case RT_OID_802_11_RSSI:
4418 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0;
4419 wrq->u.data.length = sizeof(ulInfo);
4420 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4422 case RT_OID_802_11_RSSI_1:
4423 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi1;
4424 wrq->u.data.length = sizeof(ulInfo);
4425 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4427 case RT_OID_802_11_RSSI_2:
4428 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi2;
4429 wrq->u.data.length = sizeof(ulInfo);
4430 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4432 case OID_802_11_STATISTICS:
4433 pStatistics = (NDIS_802_11_STATISTICS *) kmalloc(sizeof(NDIS_802_11_STATISTICS), MEM_ALLOC_FLAG);
4436 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS \n"));
4437 // add the most up-to-date h/w raw counters into software counters
4438 NICUpdateRawCounters(pAdapter);
4440 // Sanity check for calculation of sucessful count
4441 if (pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart < pAdapter->WlanCounters.RetryCount.QuadPart)
4442 pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
4444 pStatistics->TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart;
4445 pStatistics->MulticastTransmittedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastTransmittedFrameCount.QuadPart;
4446 pStatistics->FailedCount.QuadPart = pAdapter->WlanCounters.FailedCount.QuadPart;
4447 pStatistics->RetryCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
4448 pStatistics->MultipleRetryCount.QuadPart = pAdapter->WlanCounters.MultipleRetryCount.QuadPart;
4449 pStatistics->RTSSuccessCount.QuadPart = pAdapter->WlanCounters.RTSSuccessCount.QuadPart;
4450 pStatistics->RTSFailureCount.QuadPart = pAdapter->WlanCounters.RTSFailureCount.QuadPart;
4451 pStatistics->ACKFailureCount.QuadPart = pAdapter->WlanCounters.ACKFailureCount.QuadPart;
4452 pStatistics->FrameDuplicateCount.QuadPart = pAdapter->WlanCounters.FrameDuplicateCount.QuadPart;
4453 pStatistics->ReceivedFragmentCount.QuadPart = pAdapter->WlanCounters.ReceivedFragmentCount.QuadPart;
4454 pStatistics->MulticastReceivedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastReceivedFrameCount.QuadPart;
4456 pStatistics->FCSErrorCount = pAdapter->RalinkCounters.RealFcsErrCount;
4458 pStatistics->FCSErrorCount.QuadPart = pAdapter->WlanCounters.FCSErrorCount.QuadPart;
4459 pStatistics->FrameDuplicateCount.u.LowPart = pAdapter->WlanCounters.FrameDuplicateCount.u.LowPart / 100;
4461 wrq->u.data.length = sizeof(NDIS_802_11_STATISTICS);
4462 Status = copy_to_user(wrq->u.data.pointer, pStatistics, wrq->u.data.length);
4467 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS(kmalloc failed)\n"));
4471 case OID_GEN_RCV_OK:
4472 ulInfo = pAdapter->Counters8023.GoodReceives;
4473 wrq->u.data.length = sizeof(ulInfo);
4474 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4476 case OID_GEN_RCV_NO_BUFFER:
4477 ulInfo = pAdapter->Counters8023.RxNoBuffer;
4478 wrq->u.data.length = sizeof(ulInfo);
4479 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4481 case RT_OID_802_11_PHY_MODE:
4482 ulInfo = (ULONG)pAdapter->CommonCfg.PhyMode;
4483 wrq->u.data.length = sizeof(ulInfo);
4484 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4485 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PHY_MODE (=%ld)\n", ulInfo));
4487 case RT_OID_802_11_STA_CONFIG:
4488 pStaConfig = (RT_802_11_STA_CONFIG *) kmalloc(sizeof(RT_802_11_STA_CONFIG), MEM_ALLOC_FLAG);
4491 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG\n"));
4492 pStaConfig->EnableTxBurst = pAdapter->CommonCfg.bEnableTxBurst;
4493 pStaConfig->EnableTurboRate = 0;
4494 pStaConfig->UseBGProtection = pAdapter->CommonCfg.UseBGProtection;
4495 pStaConfig->UseShortSlotTime = pAdapter->CommonCfg.bUseShortSlotTime;
4496 //pStaConfig->AdhocMode = pAdapter->StaCfg.AdhocMode;
4497 pStaConfig->HwRadioStatus = (pAdapter->StaCfg.bHwRadio == TRUE) ? 1 : 0;
4498 pStaConfig->Rsv1 = 0;
4499 pStaConfig->SystemErrorBitmap = pAdapter->SystemErrorBitmap;
4500 wrq->u.data.length = sizeof(RT_802_11_STA_CONFIG);
4501 Status = copy_to_user(wrq->u.data.pointer, pStaConfig, wrq->u.data.length);
4506 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
4510 case OID_802_11_RTS_THRESHOLD:
4511 RtsThresh = pAdapter->CommonCfg.RtsThreshold;
4512 wrq->u.data.length = sizeof(RtsThresh);
4513 Status = copy_to_user(wrq->u.data.pointer, &RtsThresh, wrq->u.data.length);
4514 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RTS_THRESHOLD(=%ld)\n", RtsThresh));
4516 case OID_802_11_FRAGMENTATION_THRESHOLD:
4517 FragThresh = pAdapter->CommonCfg.FragmentThreshold;
4518 if (pAdapter->CommonCfg.bUseZeroToDisableFragment == TRUE)
4520 wrq->u.data.length = sizeof(FragThresh);
4521 Status = copy_to_user(wrq->u.data.pointer, &FragThresh, wrq->u.data.length);
4522 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_FRAGMENTATION_THRESHOLD(=%ld)\n", FragThresh));
4524 case OID_802_11_POWER_MODE:
4525 PowerMode = pAdapter->StaCfg.WindowsPowerMode;
4526 wrq->u.data.length = sizeof(PowerMode);
4527 Status = copy_to_user(wrq->u.data.pointer, &PowerMode, wrq->u.data.length);
4528 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_POWER_MODE(=%d)\n", PowerMode));
4530 case RT_OID_802_11_RADIO:
4531 RadioState = (BOOLEAN) pAdapter->StaCfg.bSwRadio;
4532 wrq->u.data.length = sizeof(RadioState);
4533 Status = copy_to_user(wrq->u.data.pointer, &RadioState, wrq->u.data.length);
4534 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_RADIO (=%d)\n", RadioState));
4536 case OID_802_11_INFRASTRUCTURE_MODE:
4537 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
4538 BssType = Ndis802_11IBSS;
4539 else if (pAdapter->StaCfg.BssType == BSS_INFRA)
4540 BssType = Ndis802_11Infrastructure;
4541 else if (pAdapter->StaCfg.BssType == BSS_MONITOR)
4542 BssType = Ndis802_11Monitor;
4544 BssType = Ndis802_11AutoUnknown;
4546 wrq->u.data.length = sizeof(BssType);
4547 Status = copy_to_user(wrq->u.data.pointer, &BssType, wrq->u.data.length);
4548 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_INFRASTRUCTURE_MODE(=%d)\n", BssType));
4550 case RT_OID_802_11_PREAMBLE:
4551 PreamType = pAdapter->CommonCfg.TxPreamble;
4552 wrq->u.data.length = sizeof(PreamType);
4553 Status = copy_to_user(wrq->u.data.pointer, &PreamType, wrq->u.data.length);
4554 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PREAMBLE(=%d)\n", PreamType));
4556 case OID_802_11_AUTHENTICATION_MODE:
4557 AuthMode = pAdapter->StaCfg.AuthMode;
4558 wrq->u.data.length = sizeof(AuthMode);
4559 Status = copy_to_user(wrq->u.data.pointer, &AuthMode, wrq->u.data.length);
4560 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_AUTHENTICATION_MODE(=%d)\n", AuthMode));
4562 case OID_802_11_WEP_STATUS:
4563 WepStatus = pAdapter->StaCfg.WepStatus;
4564 wrq->u.data.length = sizeof(WepStatus);
4565 Status = copy_to_user(wrq->u.data.pointer, &WepStatus, wrq->u.data.length);
4566 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_WEP_STATUS(=%d)\n", WepStatus));
4568 case OID_802_11_TX_POWER_LEVEL:
4569 wrq->u.data.length = sizeof(ULONG);
4570 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPower, wrq->u.data.length);
4571 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_TX_POWER_LEVEL %x\n",pAdapter->CommonCfg.TxPower));
4573 case RT_OID_802_11_TX_POWER_LEVEL_1:
4574 wrq->u.data.length = sizeof(ULONG);
4575 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPowerPercentage, wrq->u.data.length);
4576 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
4578 case OID_802_11_NETWORK_TYPES_SUPPORTED:
4579 if ((pAdapter->RfIcType == RFIC_2850) || (pAdapter->RfIcType == RFIC_2750))
4581 NetworkTypeList[0] = 3; // NumberOfItems = 3
4582 NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
4583 NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
4584 NetworkTypeList[3] = Ndis802_11OFDM5; // NetworkType[3] = 11a
4585 wrq->u.data.length = 16;
4586 Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
4590 NetworkTypeList[0] = 2; // NumberOfItems = 2
4591 NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
4592 NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
4593 wrq->u.data.length = 12;
4594 Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
4596 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_NETWORK_TYPES_SUPPORTED\n"));
4598 case OID_802_11_NETWORK_TYPE_IN_USE:
4599 wrq->u.data.length = sizeof(ULONG);
4600 if (pAdapter->CommonCfg.PhyMode == PHY_11A)
4601 ulInfo = Ndis802_11OFDM5;
4602 else if ((pAdapter->CommonCfg.PhyMode == PHY_11BG_MIXED) || (pAdapter->CommonCfg.PhyMode == PHY_11G))
4603 ulInfo = Ndis802_11OFDM24;
4605 ulInfo = Ndis802_11DS;
4606 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4608 case RT_OID_802_11_QUERY_LAST_RX_RATE:
4609 ulInfo = (ULONG)pAdapter->LastRxRate;
4610 wrq->u.data.length = sizeof(ulInfo);
4611 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4612 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_RX_RATE (=%ld)\n", ulInfo));
4614 case RT_OID_802_11_QUERY_LAST_TX_RATE:
4615 //ulInfo = (ULONG)pAdapter->LastTxRate;
4616 ulInfo = (ULONG)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word;
4617 wrq->u.data.length = sizeof(ulInfo);
4618 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4619 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_TX_RATE (=%lx)\n", ulInfo));
4621 case RT_OID_802_11_QUERY_EEPROM_VERSION:
4622 wrq->u.data.length = sizeof(ULONG);
4623 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->EepromVersion, wrq->u.data.length);
4625 case RT_OID_802_11_QUERY_FIRMWARE_VERSION:
4626 wrq->u.data.length = sizeof(ULONG);
4627 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->FirmwareVersion, wrq->u.data.length);
4629 case RT_OID_802_11_QUERY_NOISE_LEVEL:
4630 wrq->u.data.length = sizeof(UCHAR);
4631 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->BbpWriteLatch[66], wrq->u.data.length);
4632 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_NOISE_LEVEL (=%d)\n", pAdapter->BbpWriteLatch[66]));
4634 case RT_OID_802_11_EXTRA_INFO:
4635 wrq->u.data.length = sizeof(ULONG);
4636 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->ExtraInfo, wrq->u.data.length);
4637 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_EXTRA_INFO (=%ld)\n", pAdapter->ExtraInfo));
4639 case RT_OID_WE_VERSION_COMPILED:
4640 wrq->u.data.length = sizeof(UINT);
4641 we_version_compiled = WIRELESS_EXT;
4642 Status = copy_to_user(wrq->u.data.pointer, &we_version_compiled, wrq->u.data.length);
4644 case RT_OID_802_11_QUERY_APSD_SETTING:
4645 apsd = (pAdapter->CommonCfg.bAPSDCapable | (pAdapter->CommonCfg.bAPSDAC_BE << 1) | (pAdapter->CommonCfg.bAPSDAC_BK << 2)
4646 | (pAdapter->CommonCfg.bAPSDAC_VI << 3) | (pAdapter->CommonCfg.bAPSDAC_VO << 4) | (pAdapter->CommonCfg.MaxSPLength << 5));
4648 wrq->u.data.length = sizeof(ULONG);
4649 Status = copy_to_user(wrq->u.data.pointer, &apsd, wrq->u.data.length);
4650 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",
4651 apsd,pAdapter->CommonCfg.bAPSDCapable,pAdapter->CommonCfg.bAPSDAC_BE,pAdapter->CommonCfg.bAPSDAC_BK,pAdapter->CommonCfg.bAPSDAC_VI,pAdapter->CommonCfg.bAPSDAC_VO,pAdapter->CommonCfg.MaxSPLength));
4653 case RT_OID_802_11_QUERY_APSD_PSM:
4654 wrq->u.data.length = sizeof(ULONG);
4655 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.length);
4656 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_APSD_PSM (=%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
4658 case RT_OID_802_11_QUERY_WMM:
4659 wrq->u.data.length = sizeof(BOOLEAN);
4660 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bWmmCapable, wrq->u.data.length);
4661 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_WMM (=%d)\n", pAdapter->CommonCfg.bWmmCapable));
4663 case RT_OID_NEW_DRIVER:
4666 wrq->u.data.length = sizeof(UCHAR);
4667 Status = copy_to_user(wrq->u.data.pointer, &enabled, wrq->u.data.length);
4668 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_NEW_DRIVER (=%d)\n", enabled));
4671 case RT_OID_WPA_SUPPLICANT_SUPPORT:
4672 wrq->u.data.length = sizeof(UCHAR);
4673 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->StaCfg.WpaSupplicantUP, wrq->u.data.length);
4674 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
4676 case RT_OID_DRIVER_DEVICE_NAME:
4677 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_DRIVER_DEVICE_NAME \n"));
4678 wrq->u.data.length = 16;
4679 if (copy_to_user(wrq->u.data.pointer, pAdapter->StaCfg.dev_name, wrq->u.data.length))
4684 case RT_OID_802_11_QUERY_HT_PHYMODE:
4685 pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
4688 pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
4689 pHTPhyMode->HtMode = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE;
4690 pHTPhyMode->BW = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.BW;
4691 pHTPhyMode->MCS= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MCS;
4692 pHTPhyMode->SHORTGI= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.ShortGI;
4693 pHTPhyMode->STBC= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.STBC;
4695 pHTPhyMode->ExtOffset = ((pAdapter->CommonCfg.CentralChannel < pAdapter->CommonCfg.Channel) ? (EXTCHA_BELOW) : (EXTCHA_ABOVE));
4696 wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
4697 if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
4701 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
4702 pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
4703 DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
4707 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
4711 case RT_OID_802_11_COUNTRY_REGION:
4712 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_COUNTRY_REGION \n"));
4713 wrq->u.data.length = sizeof(ulInfo);
4714 ulInfo = pAdapter->CommonCfg.CountryRegionForABand;
4715 ulInfo = (ulInfo << 8)|(pAdapter->CommonCfg.CountryRegion);
4716 if (copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length))
4721 case RT_OID_802_11_QUERY_DAT_HT_PHYMODE:
4722 pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
4725 pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
4726 pHTPhyMode->HtMode = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.HTMODE;
4727 pHTPhyMode->BW = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.BW;
4728 pHTPhyMode->MCS= (UCHAR)pAdapter->StaCfg.DesiredTransmitSetting.field.MCS;
4729 pHTPhyMode->SHORTGI= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.ShortGI;
4730 pHTPhyMode->STBC= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.STBC;
4732 wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
4733 if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
4737 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
4738 pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
4739 DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
4743 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
4747 case RT_OID_QUERY_MULTIPLE_CARD_SUPPORT:
4748 wrq->u.data.length = sizeof(UCHAR);
4750 if (copy_to_user(wrq->u.data.pointer, &i, wrq->u.data.length))
4754 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_QUERY_MULTIPLE_CARD_SUPPORT(=%d) \n", i));
4757 case OID_802_11_BUILD_CHANNEL_EX:
4760 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BUILD_CHANNEL_EX \n"));
4761 wrq->u.data.length = sizeof(UCHAR);
4762 DBGPRINT(RT_DEBUG_TRACE, ("Doesn't support EXT_BUILD_CHANNEL_LIST.\n"));
4764 Status = copy_to_user(wrq->u.data.pointer, &value, 1);
4765 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
4769 case OID_802_11_GET_CH_LIST:
4771 PRT_CHANNEL_LIST_INFO pChListBuf;
4773 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CH_LIST \n"));
4774 if (pAdapter->ChannelListNum == 0)
4776 wrq->u.data.length = 0;
4780 pChListBuf = (RT_CHANNEL_LIST_INFO *) kmalloc(sizeof(RT_CHANNEL_LIST_INFO), MEM_ALLOC_FLAG);
4781 if (pChListBuf == NULL)
4783 wrq->u.data.length = 0;
4787 pChListBuf->ChannelListNum = pAdapter->ChannelListNum;
4788 for (i = 0; i < pChListBuf->ChannelListNum; i++)
4789 pChListBuf->ChannelList[i] = pAdapter->ChannelList[i].Channel;
4791 wrq->u.data.length = sizeof(RT_CHANNEL_LIST_INFO);
4792 Status = copy_to_user(wrq->u.data.pointer, pChListBuf, sizeof(RT_CHANNEL_LIST_INFO));
4793 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
4800 case OID_802_11_GET_COUNTRY_CODE:
4801 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_COUNTRY_CODE \n"));
4802 wrq->u.data.length = 2;
4803 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.CountryCode, 2);
4804 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
4807 case OID_802_11_GET_CHANNEL_GEOGRAPHY:
4808 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CHANNEL_GEOGRAPHY \n"));
4809 wrq->u.data.length = 1;
4810 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Geography, 1);
4811 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
4815 DBGPRINT(RT_DEBUG_TRACE, ("Query::unknown IOCTL's subcmd = 0x%08x\n", cmd));
4816 Status = -EOPNOTSUPP;
4822 INT rt28xx_sta_ioctl(
4823 IN struct net_device *net_dev,
4824 IN OUT struct ifreq *rq,
4828 VIRTUAL_ADAPTER *pVirtualAd = NULL;
4829 RTMP_ADAPTER *pAd = NULL;
4830 struct iwreq *wrq = (struct iwreq *) rq;
4831 BOOLEAN StateMachineTouched = FALSE;
4832 INT Status = NDIS_STATUS_SUCCESS;
4835 if (net_dev->priv_flags == INT_MAIN)
4837 pAd = net_dev->ml_priv;
4841 pVirtualAd = net_dev->ml_priv;
4842 pAd = pVirtualAd->RtmpDev->ml_priv;
4844 pObj = (POS_COOKIE) pAd->OS_Cookie;
4848 /* if 1st open fail, pAd will be free;
4849 So the net_dev->ml_priv will be NULL in 2rd open */
4853 //check if the interface is down
4854 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
4857 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
4862 { // determine this ioctl command is comming from which interface.
4863 pObj->ioctl_if_type = INT_MAIN;
4864 pObj->ioctl_if = MAIN_MBSSID;
4870 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIFHWADDR\n"));
4871 memcpy(wrq->u.name, pAd->CurrentAddress, ETH_ALEN);
4875 char *name=&wrq->u.name[0];
4876 rt_ioctl_giwname(net_dev, NULL, name, NULL);
4879 case SIOCGIWESSID: //Get ESSID
4881 struct iw_point *essid=&wrq->u.essid;
4882 rt_ioctl_giwessid(net_dev, NULL, essid, essid->pointer);
4885 case SIOCSIWESSID: //Set ESSID
4887 struct iw_point *essid=&wrq->u.essid;
4888 rt_ioctl_siwessid(net_dev, NULL, essid, essid->pointer);
4891 case SIOCSIWNWID: // set network id (the cell)
4892 case SIOCGIWNWID: // get network id
4893 Status = -EOPNOTSUPP;
4895 case SIOCSIWFREQ: //set channel/frequency (Hz)
4897 struct iw_freq *freq=&wrq->u.freq;
4898 rt_ioctl_siwfreq(net_dev, NULL, freq, NULL);
4901 case SIOCGIWFREQ: // get channel/frequency (Hz)
4903 struct iw_freq *freq=&wrq->u.freq;
4904 rt_ioctl_giwfreq(net_dev, NULL, freq, NULL);
4907 case SIOCSIWNICKN: //set node name/nickname
4909 struct iw_point *data=&wrq->u.data;
4910 rt_ioctl_siwnickn(net_dev, NULL, data, NULL);
4913 case SIOCGIWNICKN: //get node name/nickname
4915 struct iw_point *data=&wrq->u.data;
4916 rt_ioctl_giwnickn(net_dev, NULL, data, NULL);
4919 case SIOCGIWRATE: //get default bit rate (bps)
4920 rt_ioctl_giwrate(net_dev, NULL, &wrq->u, NULL);
4922 case SIOCSIWRATE: //set default bit rate (bps)
4923 rt_ioctl_siwrate(net_dev, NULL, &wrq->u, NULL);
4925 case SIOCGIWRTS: // get RTS/CTS threshold (bytes)
4927 struct iw_param *rts=&wrq->u.rts;
4928 rt_ioctl_giwrts(net_dev, NULL, rts, NULL);
4931 case SIOCSIWRTS: //set RTS/CTS threshold (bytes)
4933 struct iw_param *rts=&wrq->u.rts;
4934 rt_ioctl_siwrts(net_dev, NULL, rts, NULL);
4937 case SIOCGIWFRAG: //get fragmentation thr (bytes)
4939 struct iw_param *frag=&wrq->u.frag;
4940 rt_ioctl_giwfrag(net_dev, NULL, frag, NULL);
4943 case SIOCSIWFRAG: //set fragmentation thr (bytes)
4945 struct iw_param *frag=&wrq->u.frag;
4946 rt_ioctl_siwfrag(net_dev, NULL, frag, NULL);
4949 case SIOCGIWENCODE: //get encoding token & mode
4951 struct iw_point *erq=&wrq->u.encoding;
4953 rt_ioctl_giwencode(net_dev, NULL, erq, erq->pointer);
4956 case SIOCSIWENCODE: //set encoding token & mode
4958 struct iw_point *erq=&wrq->u.encoding;
4960 rt_ioctl_siwencode(net_dev, NULL, erq, erq->pointer);
4963 case SIOCGIWAP: //get access point MAC addresses
4965 struct sockaddr *ap_addr=&wrq->u.ap_addr;
4966 rt_ioctl_giwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
4969 case SIOCSIWAP: //set access point MAC addresses
4971 struct sockaddr *ap_addr=&wrq->u.ap_addr;
4972 rt_ioctl_siwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
4975 case SIOCGIWMODE: //get operation mode
4977 __u32 *mode=&wrq->u.mode;
4978 rt_ioctl_giwmode(net_dev, NULL, mode, NULL);
4981 case SIOCSIWMODE: //set operation mode
4983 __u32 *mode=&wrq->u.mode;
4984 rt_ioctl_siwmode(net_dev, NULL, mode, NULL);
4987 case SIOCGIWSENS: //get sensitivity (dBm)
4988 case SIOCSIWSENS: //set sensitivity (dBm)
4989 case SIOCGIWPOWER: //get Power Management settings
4990 case SIOCSIWPOWER: //set Power Management settings
4991 case SIOCGIWTXPOW: //get transmit power (dBm)
4992 case SIOCSIWTXPOW: //set transmit power (dBm)
4993 case SIOCGIWRANGE: //Get range of parameters
4994 case SIOCGIWRETRY: //get retry limits and lifetime
4995 case SIOCSIWRETRY: //set retry limits and lifetime
4996 Status = -EOPNOTSUPP;
4999 case RT_PRIV_IOCTL_EXT:
5000 subcmd = wrq->u.data.flags;
5001 if( subcmd & OID_GET_SET_TOGGLE)
5002 Status = RTMPSetInformation(pAd, rq, subcmd);
5004 Status = RTMPQueryInformation(pAd, rq, subcmd);
5007 if (wrq->u.data.pointer)
5009 if ( access_ok(VERIFY_WRITE, wrq->u.data.pointer, sizeof(privtab)) != TRUE)
5011 wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
5012 if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
5016 case RTPRIV_IOCTL_SET:
5017 if(access_ok(VERIFY_READ, wrq->u.data.pointer, wrq->u.data.length) != TRUE)
5019 rt_ioctl_setparam(net_dev, NULL, NULL, wrq->u.data.pointer);
5021 case RTPRIV_IOCTL_GSITESURVEY:
5022 RTMPIoctlGetSiteSurvey(pAd, wrq);
5025 case RTPRIV_IOCTL_MAC:
5026 RTMPIoctlMAC(pAd, wrq);
5028 case RTPRIV_IOCTL_E2P:
5029 RTMPIoctlE2PROM(pAd, wrq);
5032 case RTPRIV_IOCTL_RF:
5033 RTMPIoctlRF(pAd, wrq);
5040 DBGPRINT(RT_DEBUG_ERROR, ("IOCTL::unknown IOCTL's cmd = 0x%08x\n", cmd));
5041 Status = -EOPNOTSUPP;
5045 if(StateMachineTouched) // Upper layer sent a MLME-related operations
5046 RT28XX_MLME_HANDLER(pAd);
5052 ==========================================================================
5056 TRUE if all parameters are OK, FALSE otherwise
5057 ==========================================================================
5060 IN PRTMP_ADAPTER pAdapter,
5063 NDIS_802_11_SSID Ssid, *pSsid=NULL;
5064 BOOLEAN StateMachineTouched = FALSE;
5067 if( strlen(arg) <= MAX_LEN_OF_SSID)
5069 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
5070 if (strlen(arg) != 0)
5072 NdisMoveMemory(Ssid.Ssid, arg, strlen(arg));
5073 Ssid.SsidLength = strlen(arg);
5077 Ssid.SsidLength = 0;
5078 memcpy(Ssid.Ssid, "", 0);
5079 pAdapter->StaCfg.BssType = BSS_INFRA;
5080 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
5081 pAdapter->StaCfg.WepStatus = Ndis802_11EncryptionDisabled;
5085 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
5087 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
5088 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
5091 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
5092 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
5093 pAdapter->bConfigChanged = TRUE;
5095 MlmeEnqueue(pAdapter,
5096 MLME_CNTL_STATE_MACHINE,
5098 sizeof(NDIS_802_11_SSID),
5101 StateMachineTouched = TRUE;
5102 DBGPRINT(RT_DEBUG_TRACE, ("Set_SSID_Proc::(Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
5107 if (StateMachineTouched) // Upper layer sent a MLME-related operations
5108 RT28XX_MLME_HANDLER(pAdapter);
5115 ==========================================================================
5117 Set WmmCapable Enable or Disable
5119 TRUE if all parameters are OK, FALSE otherwise
5120 ==========================================================================
5122 INT Set_WmmCapable_Proc(
5123 IN PRTMP_ADAPTER pAd,
5126 BOOLEAN bWmmCapable;
5128 bWmmCapable = simple_strtol(arg, 0, 10);
5130 if ((bWmmCapable == 1)
5132 && (pAd->NumberOfPipes >= 5)
5135 pAd->CommonCfg.bWmmCapable = TRUE;
5136 else if (bWmmCapable == 0)
5137 pAd->CommonCfg.bWmmCapable = FALSE;
5139 return FALSE; //Invalid argument
5141 DBGPRINT(RT_DEBUG_TRACE, ("Set_WmmCapable_Proc::(bWmmCapable=%d)\n",
5142 pAd->CommonCfg.bWmmCapable));
5146 #endif // WMM_SUPPORT //
5149 ==========================================================================
5151 Set Network Type(Infrastructure/Adhoc mode)
5153 TRUE if all parameters are OK, FALSE otherwise
5154 ==========================================================================
5156 INT Set_NetworkType_Proc(
5157 IN PRTMP_ADAPTER pAdapter,
5162 if (strcmp(arg, "Adhoc") == 0)
5164 if (pAdapter->StaCfg.BssType != BSS_ADHOC)
5166 // Config has changed
5167 pAdapter->bConfigChanged = TRUE;
5168 if (MONITOR_ON(pAdapter))
5170 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
5171 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5173 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5174 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5175 pAdapter->StaCfg.bAutoReconnect = TRUE;
5176 LinkDown(pAdapter, FALSE);
5178 if (INFRA_ON(pAdapter))
5180 //BOOLEAN Cancelled;
5181 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
5182 // Since calling this indicate user don't want to connect to that SSID anymore.
5183 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
5184 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
5186 LinkDown(pAdapter, FALSE);
5188 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n"));
5191 pAdapter->StaCfg.BssType = BSS_ADHOC;
5192 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
5193 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(AD-HOC)\n"));
5195 else if (strcmp(arg, "Infra") == 0)
5197 if (pAdapter->StaCfg.BssType != BSS_INFRA)
5199 // Config has changed
5200 pAdapter->bConfigChanged = TRUE;
5201 if (MONITOR_ON(pAdapter))
5203 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
5204 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5206 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5207 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5208 pAdapter->StaCfg.bAutoReconnect = TRUE;
5209 LinkDown(pAdapter, FALSE);
5211 if (ADHOC_ON(pAdapter))
5213 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
5214 // Since calling this indicate user don't want to connect to that SSID anymore.
5215 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
5216 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
5218 LinkDown(pAdapter, FALSE);
5221 pAdapter->StaCfg.BssType = BSS_INFRA;
5222 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
5223 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(INFRA)\n"));
5225 pAdapter->StaCfg.BssType = BSS_INFRA;
5227 else if (strcmp(arg, "Monitor") == 0)
5230 BCN_TIME_CFG_STRUC csr;
5231 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_INFRA_ON);
5232 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_ADHOC_ON);
5233 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5234 // disable all periodic state machine
5235 pAdapter->StaCfg.bAutoReconnect = FALSE;
5236 // reset all mlme state machine
5237 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
5238 DBGPRINT(RT_DEBUG_TRACE, ("fOP_STATUS_MEDIA_STATE_CONNECTED \n"));
5239 if (pAdapter->CommonCfg.CentralChannel == 0)
5241 if (pAdapter->CommonCfg.PhyMode == PHY_11AN_MIXED)
5242 pAdapter->CommonCfg.CentralChannel = 36;
5244 pAdapter->CommonCfg.CentralChannel = 6;
5247 N_ChannelCheck(pAdapter);
5249 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
5250 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
5251 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_ABOVE)
5253 // 40MHz ,control channel at lower
5254 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5255 bbpValue &= (~0x18);
5257 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5258 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
5259 // RX : control channel at lower
5260 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
5261 bbpValue &= (~0x20);
5262 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
5264 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
5265 Value &= 0xfffffffe;
5266 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
5267 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel + 2;
5268 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
5269 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
5270 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
5271 pAdapter->CommonCfg.Channel,
5272 pAdapter->CommonCfg.CentralChannel));
5274 else if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
5275 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
5276 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_BELOW)
5278 // 40MHz ,control channel at upper
5279 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5280 bbpValue &= (~0x18);
5282 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5283 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
5284 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
5286 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
5288 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
5290 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
5291 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel - 2;
5292 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
5293 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
5294 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
5295 pAdapter->CommonCfg.Channel,
5296 pAdapter->CommonCfg.CentralChannel));
5301 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5302 bbpValue &= (~0x18);
5303 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5304 pAdapter->CommonCfg.BBPCurrentBW = BW_20;
5305 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.Channel, FALSE);
5306 AsicLockChannel(pAdapter, pAdapter->CommonCfg.Channel);
5307 DBGPRINT(RT_DEBUG_TRACE, ("BW_20, Channel(%d)\n", pAdapter->CommonCfg.Channel));
5309 // Enable Rx with promiscuous reception
5310 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, 0x3);
5311 // ASIC supporsts sniffer function with replacing RSSI with timestamp.
5312 //RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5314 //RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5316 RTMP_IO_READ32(pAdapter, BCN_TIME_CFG, &csr.word);
5317 csr.field.bBeaconGen = 0;
5318 csr.field.bTBTTEnable = 0;
5319 csr.field.TsfSyncMode = 0;
5320 RTMP_IO_WRITE32(pAdapter, BCN_TIME_CFG, csr.word);
5322 pAdapter->StaCfg.BssType = BSS_MONITOR;
5323 pAdapter->net_dev->type = ARPHRD_IEEE80211_PRISM; //ARPHRD_IEEE80211; // IEEE80211
5324 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(MONITOR)\n"));
5327 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
5328 pAdapter->StaCfg.WpaState = SS_NOTUSE;
5330 DBGPRINT(RT_DEBUG_TRACE, ("Set_NetworkType_Proc::(NetworkType=%d)\n", pAdapter->StaCfg.BssType));
5336 ==========================================================================
5338 Set Authentication mode
5340 TRUE if all parameters are OK, FALSE otherwise
5341 ==========================================================================
5343 INT Set_AuthMode_Proc(
5344 IN PRTMP_ADAPTER pAdapter,
5347 if ((strcmp(arg, "WEPAUTO") == 0) || (strcmp(arg, "wepauto") == 0))
5348 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeAutoSwitch;
5349 else if ((strcmp(arg, "OPEN") == 0) || (strcmp(arg, "open") == 0))
5350 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
5351 else if ((strcmp(arg, "SHARED") == 0) || (strcmp(arg, "shared") == 0))
5352 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
5353 else if ((strcmp(arg, "WPAPSK") == 0) || (strcmp(arg, "wpapsk") == 0))
5354 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
5355 else if ((strcmp(arg, "WPANONE") == 0) || (strcmp(arg, "wpanone") == 0))
5356 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
5357 else if ((strcmp(arg, "WPA2PSK") == 0) || (strcmp(arg, "wpa2psk") == 0))
5358 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
5359 else if ((strcmp(arg, "WPA") == 0) || (strcmp(arg, "wpa") == 0))
5360 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
5361 else if ((strcmp(arg, "WPA2") == 0) || (strcmp(arg, "wpa2") == 0))
5362 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
5366 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
5368 DBGPRINT(RT_DEBUG_TRACE, ("Set_AuthMode_Proc::(AuthMode=%d)\n", pAdapter->StaCfg.AuthMode));
5374 ==========================================================================
5378 TRUE if all parameters are OK, FALSE otherwise
5379 ==========================================================================
5381 INT Set_EncrypType_Proc(
5382 IN PRTMP_ADAPTER pAdapter,
5385 if ((strcmp(arg, "NONE") == 0) || (strcmp(arg, "none") == 0))
5387 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5388 return TRUE; // do nothing
5390 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
5391 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
5392 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
5394 else if ((strcmp(arg, "WEP") == 0) || (strcmp(arg, "wep") == 0))
5396 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5397 return TRUE; // do nothing
5399 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
5400 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
5401 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
5403 else if ((strcmp(arg, "TKIP") == 0) || (strcmp(arg, "tkip") == 0))
5405 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
5406 return TRUE; // do nothing
5408 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
5409 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
5410 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
5412 else if ((strcmp(arg, "AES") == 0) || (strcmp(arg, "aes") == 0))
5414 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
5415 return TRUE; // do nothing
5417 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
5418 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
5419 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
5424 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
5426 DBGPRINT(RT_DEBUG_TRACE, ("Set_EncrypType_Proc::(EncrypType=%d)\n", pAdapter->StaCfg.WepStatus));
5432 ==========================================================================
5436 TRUE if all parameters are OK, FALSE otherwise
5437 ==========================================================================
5439 INT Set_DefaultKeyID_Proc(
5440 IN PRTMP_ADAPTER pAdapter,
5445 KeyIdx = simple_strtol(arg, 0, 10);
5446 if((KeyIdx >= 1 ) && (KeyIdx <= 4))
5447 pAdapter->StaCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1 );
5449 return FALSE; //Invalid argument
5451 DBGPRINT(RT_DEBUG_TRACE, ("Set_DefaultKeyID_Proc::(DefaultKeyID=%d)\n", pAdapter->StaCfg.DefaultKeyId));
5457 ==========================================================================
5461 TRUE if all parameters are OK, FALSE otherwise
5462 ==========================================================================
5465 IN PRTMP_ADAPTER pAdapter,
5470 UCHAR CipherAlg=CIPHER_WEP64;
5472 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5473 return TRUE; // do nothing
5475 KeyLen = strlen(arg);
5479 case 5: //wep 40 Ascii type
5480 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
5481 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
5482 CipherAlg = CIPHER_WEP64;
5483 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
5485 case 10: //wep 40 Hex type
5486 for(i=0; i < KeyLen; i++)
5488 if( !isxdigit(*(arg+i)) )
5489 return FALSE; //Not Hex value;
5491 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
5492 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
5493 CipherAlg = CIPHER_WEP64;
5494 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
5496 case 13: //wep 104 Ascii type
5497 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
5498 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
5499 CipherAlg = CIPHER_WEP128;
5500 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
5502 case 26: //wep 104 Hex type
5503 for(i=0; i < KeyLen; i++)
5505 if( !isxdigit(*(arg+i)) )
5506 return FALSE; //Not Hex value;
5508 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
5509 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
5510 CipherAlg = CIPHER_WEP128;
5511 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
5513 default: //Invalid argument
5514 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::Invalid argument (=%s)\n", arg));
5518 pAdapter->SharedKey[BSS0][0].CipherAlg = CipherAlg;
5520 // Set keys (into ASIC)
5521 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5523 else // Old WEP stuff
5525 AsicAddSharedKeyEntry(pAdapter,
5528 pAdapter->SharedKey[BSS0][0].CipherAlg,
5529 pAdapter->SharedKey[BSS0][0].Key,
5537 ==========================================================================
5542 TRUE if all parameters are OK, FALSE otherwise
5543 ==========================================================================
5546 IN PRTMP_ADAPTER pAdapter,
5551 UCHAR CipherAlg=CIPHER_WEP64;
5553 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5554 return TRUE; // do nothing
5556 KeyLen = strlen(arg);
5560 case 5: //wep 40 Ascii type
5561 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
5562 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
5563 CipherAlg = CIPHER_WEP64;
5564 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
5566 case 10: //wep 40 Hex type
5567 for(i=0; i < KeyLen; i++)
5569 if( !isxdigit(*(arg+i)) )
5570 return FALSE; //Not Hex value;
5572 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
5573 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
5574 CipherAlg = CIPHER_WEP64;
5575 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
5577 case 13: //wep 104 Ascii type
5578 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
5579 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
5580 CipherAlg = CIPHER_WEP128;
5581 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
5583 case 26: //wep 104 Hex type
5584 for(i=0; i < KeyLen; i++)
5586 if( !isxdigit(*(arg+i)) )
5587 return FALSE; //Not Hex value;
5589 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
5590 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
5591 CipherAlg = CIPHER_WEP128;
5592 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
5594 default: //Invalid argument
5595 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::Invalid argument (=%s)\n", arg));
5598 pAdapter->SharedKey[BSS0][1].CipherAlg = CipherAlg;
5600 // Set keys (into ASIC)
5601 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5603 else // Old WEP stuff
5605 AsicAddSharedKeyEntry(pAdapter,
5608 pAdapter->SharedKey[BSS0][1].CipherAlg,
5609 pAdapter->SharedKey[BSS0][1].Key,
5617 ==========================================================================
5621 TRUE if all parameters are OK, FALSE otherwise
5622 ==========================================================================
5625 IN PRTMP_ADAPTER pAdapter,
5630 UCHAR CipherAlg=CIPHER_WEP64;
5632 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5633 return TRUE; // do nothing
5635 KeyLen = strlen(arg);
5639 case 5: //wep 40 Ascii type
5640 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
5641 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
5642 CipherAlg = CIPHER_WEP64;
5643 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
5645 case 10: //wep 40 Hex type
5646 for(i=0; i < KeyLen; i++)
5648 if( !isxdigit(*(arg+i)) )
5649 return FALSE; //Not Hex value;
5651 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
5652 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
5653 CipherAlg = CIPHER_WEP64;
5654 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
5656 case 13: //wep 104 Ascii type
5657 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
5658 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
5659 CipherAlg = CIPHER_WEP128;
5660 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
5662 case 26: //wep 104 Hex type
5663 for(i=0; i < KeyLen; i++)
5665 if( !isxdigit(*(arg+i)) )
5666 return FALSE; //Not Hex value;
5668 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
5669 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
5670 CipherAlg = CIPHER_WEP128;
5671 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
5673 default: //Invalid argument
5674 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::Invalid argument (=%s)\n", arg));
5677 pAdapter->SharedKey[BSS0][2].CipherAlg = CipherAlg;
5679 // Set keys (into ASIC)
5680 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5682 else // Old WEP stuff
5684 AsicAddSharedKeyEntry(pAdapter,
5687 pAdapter->SharedKey[BSS0][2].CipherAlg,
5688 pAdapter->SharedKey[BSS0][2].Key,
5696 ==========================================================================
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][3].KeyLen = KeyLen;
5720 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
5721 CipherAlg = CIPHER_WEP64;
5722 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%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][3].KeyLen = KeyLen / 2 ;
5731 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
5732 CipherAlg = CIPHER_WEP64;
5733 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
5735 case 13: //wep 104 Ascii type
5736 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
5737 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
5738 CipherAlg = CIPHER_WEP128;
5739 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%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][3].KeyLen = KeyLen / 2 ;
5748 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
5749 CipherAlg = CIPHER_WEP128;
5750 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
5752 default: //Invalid argument
5753 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::Invalid argument (=%s)\n", arg));
5756 pAdapter->SharedKey[BSS0][3].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][3].CipherAlg,
5767 pAdapter->SharedKey[BSS0][3].Key,
5776 ==========================================================================
5780 TRUE if all parameters are OK, FALSE otherwise
5781 ==========================================================================
5783 INT Set_WPAPSK_Proc(
5784 IN PRTMP_ADAPTER pAdapter,
5787 UCHAR keyMaterial[40];
5789 if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
5790 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
5791 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
5793 return TRUE; // do nothing
5795 DBGPRINT(RT_DEBUG_TRACE, ("Set_WPAPSK_Proc::(WPAPSK=%s)\n", arg));
5797 NdisZeroMemory(keyMaterial, 40);
5799 if ((strlen(arg) < 8) || (strlen(arg) > 64))
5801 DBGPRINT(RT_DEBUG_TRACE, ("Set failed!!(WPAPSK=%s), WPAPSK key-string required 8 ~ 64 characters \n", arg));
5805 if (strlen(arg) == 64)
5807 AtoH(arg, keyMaterial, 32);
5808 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
5813 PasswordHash((char *)arg, pAdapter->MlmeAux.Ssid, pAdapter->MlmeAux.SsidLen, keyMaterial);
5814 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
5819 if(pAdapter->StaCfg.BssType == BSS_ADHOC &&
5820 pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
5822 pAdapter->StaCfg.WpaState = SS_NOTUSE;
5826 // Start STA supplicant state machine
5827 pAdapter->StaCfg.WpaState = SS_START;
5834 ==========================================================================
5836 Set Power Saving mode
5838 TRUE if all parameters are OK, FALSE otherwise
5839 ==========================================================================
5841 INT Set_PSMode_Proc(
5842 IN PRTMP_ADAPTER pAdapter,
5845 if (pAdapter->StaCfg.BssType == BSS_INFRA)
5847 if ((strcmp(arg, "Max_PSP") == 0) ||
5848 (strcmp(arg, "max_psp") == 0) ||
5849 (strcmp(arg, "MAX_PSP") == 0))
5851 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
5852 // to exclude certain situations.
5853 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
5854 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeMAX_PSP;
5855 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeMAX_PSP;
5856 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
5857 pAdapter->StaCfg.DefaultListenCount = 5;
5860 else if ((strcmp(arg, "Fast_PSP") == 0) ||
5861 (strcmp(arg, "fast_psp") == 0) ||
5862 (strcmp(arg, "FAST_PSP") == 0))
5864 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
5865 // to exclude certain situations.
5866 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
5867 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
5868 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeFast_PSP;
5869 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeFast_PSP;
5870 pAdapter->StaCfg.DefaultListenCount = 3;
5872 else if ((strcmp(arg, "Legacy_PSP") == 0) ||
5873 (strcmp(arg, "legacy_psp") == 0) ||
5874 (strcmp(arg, "LEGACY_PSP") == 0))
5876 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
5877 // to exclude certain situations.
5878 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
5879 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
5880 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeLegacy_PSP;
5881 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeLegacy_PSP;
5882 pAdapter->StaCfg.DefaultListenCount = 3;
5886 //Default Ndis802_11PowerModeCAM
5887 // clear PSM bit immediately
5888 MlmeSetPsmBit(pAdapter, PWR_ACTIVE);
5889 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
5890 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
5891 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
5892 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
5895 DBGPRINT(RT_DEBUG_TRACE, ("Set_PSMode_Proc::(PSMode=%ld)\n", pAdapter->StaCfg.WindowsPowerMode));
5905 ==========================================================================
5907 Set WpaSupport flag.
5909 0: Driver ignore wpa_supplicant.
5910 1: wpa_supplicant initiates scanning and AP selection.
5911 2: driver takes care of scanning, AP selection, and IEEE 802.11 association parameters.
5913 TRUE if all parameters are OK, FALSE otherwise
5914 ==========================================================================
5916 INT Set_Wpa_Support(
5917 IN PRTMP_ADAPTER pAd,
5921 if ( simple_strtol(arg, 0, 10) == 0)
5922 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
5923 else if ( simple_strtol(arg, 0, 10) == 1)
5924 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE;
5925 else if ( simple_strtol(arg, 0, 10) == 2)
5926 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE_WITH_WEB_UI;
5928 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
5930 DBGPRINT(RT_DEBUG_TRACE, ("Set_Wpa_Support::(WpaSupplicantUP=%d)\n", pAd->StaCfg.WpaSupplicantUP));
5937 ==========================================================================
5941 pAdapter Pointer to our adapter
5942 wrq Pointer to the ioctl argument
5949 1.) iwpriv ra0 mac 0 ==> read MAC where Addr=0x0
5950 2.) iwpriv ra0 mac 0=12 ==> write MAC where Addr=0x0, value=12
5951 ==========================================================================
5954 IN PRTMP_ADAPTER pAdapter,
5955 IN struct iwreq *wrq)
5963 UCHAR temp[16], temp2[16];
5964 UINT32 macValue = 0;
5966 BOOLEAN bIsPrintAllMAC = FALSE;
5969 memset(msg, 0x00, 1024);
5970 if (wrq->u.data.length > 1) //No parameters.
5972 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
5975 //Parsing Read or Write
5980 if ((value = rtstrchr(this_char, '=')) != NULL)
5983 if (!value || !*value)
5986 if(strlen(this_char) > 4)
5989 j = strlen(this_char);
5992 if(this_char[j] > 'f' || this_char[j] < '0')
5997 k = j = strlen(this_char);
6000 this_char[4-k+j] = this_char[j];
6004 this_char[3-k++]='0';
6007 if(strlen(this_char) == 4)
6009 AtoH(this_char, temp, 2);
6010 macAddr = *temp*256 + temp[1];
6011 if (macAddr < 0xFFFF)
6013 RTMP_IO_READ32(pAdapter, macAddr, &macValue);
6014 DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%lx, MacValue=%x\n", macAddr, macValue));
6015 sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr , macValue);
6018 {//Invalid parametes, so default printk all mac
6019 bIsPrintAllMAC = TRUE;
6026 memcpy(&temp2, value, strlen(value));
6027 temp2[strlen(value)] = '\0';
6030 if((strlen(this_char) > 4) || strlen(temp2) > 8)
6033 j = strlen(this_char);
6036 if(this_char[j] > 'f' || this_char[j] < '0')
6043 if(temp2[j] > 'f' || temp2[j] < '0')
6048 k = j = strlen(this_char);
6051 this_char[4-k+j] = this_char[j];
6055 this_char[3-k++]='0';
6059 k = j = strlen(temp2);
6062 temp2[8-k+j] = temp2[j];
6070 AtoH(this_char, temp, 2);
6071 macAddr = *temp*256 + temp[1];
6073 AtoH(temp2, temp, 4);
6074 macValue = *temp*256*256*256 + temp[1]*256*256 + temp[2]*256 + temp[3];
6077 if (macAddr == (HW_DEBUG_SETTING_BASE + 4))
6079 // 0x2bf4: byte0 non-zero: enable R17 tuning, 0: disable R17 tuning
6080 if (macValue & 0x000000ff)
6082 pAdapter->BbpTuning.bEnable = TRUE;
6083 DBGPRINT(RT_DEBUG_TRACE,("turn on R17 tuning\n"));
6088 pAdapter->BbpTuning.bEnable = FALSE;
6089 R66 = 0x26 + GET_LNA_GAIN(pAdapter);
6090 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R66, (0x26 + GET_LNA_GAIN(pAdapter)));
6091 DBGPRINT(RT_DEBUG_TRACE,("turn off R17 tuning, restore to 0x%02x\n", R66));
6096 DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%02lx, MacValue=0x%x\n", macAddr, macValue));
6098 RTMP_IO_WRITE32(pAdapter, macAddr, macValue);
6099 sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr, macValue);
6104 bIsPrintAllMAC = TRUE;
6108 struct file *file_w;
6109 PCHAR fileName = "MacDump.txt";
6110 mm_segment_t orig_fs;
6116 file_w = filp_open(fileName, O_WRONLY|O_CREAT, 0);
6119 DBGPRINT(RT_DEBUG_TRACE, ("-->2) %s: Error %ld opening %s\n", __func__, -PTR_ERR(file_w), fileName));
6123 if (file_w->f_op && file_w->f_op->write)
6128 while (macAddr <= 0x1800)
6130 RTMP_IO_READ32(pAdapter, macAddr, &macValue);
6131 sprintf(msg, "%08lx = %08X\n", macAddr, macValue);
6133 // write data to file
6134 file_w->f_op->write(file_w, msg, strlen(msg), &file_w->f_pos);
6139 sprintf(msg, "\nDump all MAC values to %s\n", fileName);
6141 filp_close(file_w, NULL);
6145 if(strlen(msg) == 1)
6146 sprintf(msg+strlen(msg), "===>Error command format!");
6148 // Copy the information into the user buffer
6149 wrq->u.data.length = strlen(msg);
6150 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6152 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlMAC\n\n"));
6156 ==========================================================================
6160 pAdapter Pointer to our adapter
6161 wrq Pointer to the ioctl argument
6168 1.) iwpriv ra0 e2p 0 ==> read E2PROM where Addr=0x0
6169 2.) iwpriv ra0 e2p 0=1234 ==> write E2PROM where Addr=0x0, value=1234
6170 ==========================================================================
6172 VOID RTMPIoctlE2PROM(
6173 IN PRTMP_ADAPTER pAdapter,
6174 IN struct iwreq *wrq)
6182 UCHAR temp[16], temp2[16];
6185 BOOLEAN bIsPrintAllE2P = FALSE;
6188 memset(msg, 0x00, 1024);
6189 if (wrq->u.data.length > 1) //No parameters.
6191 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6194 //Parsing Read or Write
6201 if ((value = rtstrchr(this_char, '=')) != NULL)
6204 if (!value || !*value)
6208 if(strlen(this_char) > 4)
6211 j = strlen(this_char);
6214 if(this_char[j] > 'f' || this_char[j] < '0')
6219 k = j = strlen(this_char);
6222 this_char[4-k+j] = this_char[j];
6226 this_char[3-k++]='0';
6229 if(strlen(this_char) == 4)
6231 AtoH(this_char, temp, 2);
6232 eepAddr = *temp*256 + temp[1];
6233 if (eepAddr < 0xFFFF)
6235 RT28xx_EEPROM_READ16(pAdapter, eepAddr, eepValue);
6236 sprintf(msg+strlen(msg), "[0x%04X]:0x%04X ", eepAddr , eepValue);
6239 {//Invalid parametes, so default printk all bbp
6240 bIsPrintAllE2P = TRUE;
6247 memcpy(&temp2, value, strlen(value));
6248 temp2[strlen(value)] = '\0';
6251 if((strlen(this_char) > 4) || strlen(temp2) > 8)
6254 j = strlen(this_char);
6257 if(this_char[j] > 'f' || this_char[j] < '0')
6263 if(temp2[j] > 'f' || temp2[j] < '0')
6268 k = j = strlen(this_char);
6271 this_char[4-k+j] = this_char[j];
6275 this_char[3-k++]='0';
6279 k = j = strlen(temp2);
6282 temp2[4-k+j] = temp2[j];
6289 AtoH(this_char, temp, 2);
6290 eepAddr = *temp*256 + temp[1];
6292 AtoH(temp2, temp, 2);
6293 eepValue = *temp*256 + temp[1];
6295 RT28xx_EEPROM_WRITE16(pAdapter, eepAddr, eepValue);
6296 sprintf(msg+strlen(msg), "[0x%02X]:%02X ", eepAddr, eepValue);
6300 bIsPrintAllE2P = TRUE;
6304 struct file *file_w;
6305 PCHAR fileName = "EEPROMDump.txt";
6306 mm_segment_t orig_fs;
6312 file_w = filp_open(fileName, O_WRONLY|O_CREAT, 0);
6315 DBGPRINT(RT_DEBUG_TRACE, ("-->2) %s: Error %ld opening %s\n", __func__, -PTR_ERR(file_w), fileName));
6319 if (file_w->f_op && file_w->f_op->write)
6324 while (eepAddr <= 0xFE)
6326 RT28xx_EEPROM_READ16(pAdapter, eepAddr, eepValue);
6327 sprintf(msg, "%08x = %04x\n", eepAddr , eepValue);
6329 // write data to file
6330 file_w->f_op->write(file_w, msg, strlen(msg), &file_w->f_pos);
6335 sprintf(msg, "\nDump all EEPROM values to %s\n", fileName);
6337 filp_close(file_w, NULL);
6341 if(strlen(msg) == 1)
6342 sprintf(msg+strlen(msg), "===>Error command format!");
6345 // Copy the information into the user buffer
6346 wrq->u.data.length = strlen(msg);
6347 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6349 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlE2PROM\n"));
6353 ==========================================================================
6355 Read / Write RF register
6357 pAdapter Pointer to our adapter
6358 wrq Pointer to the ioctl argument
6365 1.) iwpriv ra0 rf ==> read all RF registers
6366 2.) iwpriv ra0 rf 1 ==> read RF where RegID=1
6367 3.) iwpriv ra0 rf 1=10 ==> write RF R1=0x10
6368 ==========================================================================
6371 IN PRTMP_ADAPTER pAdapter,
6372 IN struct iwreq *wrq)
6382 BOOLEAN bIsPrintAllRF = FALSE;
6385 memset(msg, 0x00, 2048);
6386 if (wrq->u.data.length > 1) //No parameters.
6388 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6391 //Parsing Read or Write
6396 if ((value = strchr(this_char, '=')) != NULL)
6399 if (!value || !*value)
6401 if (sscanf(this_char, "%d", &(rfId)) == 1)
6405 // In RT2860 ATE mode, we do not load 8051 firmware.
6406 //We must access RF directly.
6407 // For RT2870 ATE mode, ATE_RF_IO_WRITE8(/READ8)_BY_REG_ID are redefined.
6408 // according to Andy, Gary, David require.
6409 // the command rf shall read rf register directly for dubug.
6410 // BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
6411 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
6413 sprintf(msg+strlen(msg), "R%02d[0x%02x]:%02X ", rfId, rfId*2, regRF);
6416 {//Invalid parametes, so default printk all RF
6417 bIsPrintAllRF = TRUE;
6422 { //Invalid parametes, so default printk all RF
6423 bIsPrintAllRF = TRUE;
6429 if ((sscanf(this_char, "%d", &(rfId)) == 1) && (sscanf(value, "%lx", &(rfValue)) == 1))
6433 // In RT2860 ATE mode, we do not load 8051 firmware.
6434 // We should access RF registers directly.
6435 // For RT2870 ATE mode, ATE_RF_IO_WRITE8/READ8_BY_REG_ID are redefined.
6437 // according to Andy, Gary, David require.
6438 // the command RF shall read/write RF register directly for dubug.
6439 //BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
6440 //BBP_IO_WRITE8_BY_REG_ID(pAdapter, (UCHAR)bbpId,(UCHAR) bbpValue);
6441 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
6442 RT30xxWriteRFRegister(pAdapter, (UCHAR)rfId,(UCHAR) rfValue);
6443 //Read it back for showing
6444 //BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
6445 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
6446 sprintf(msg+strlen(msg), "R%02d[0x%02X]:%02X\n", rfId, rfId*2, regRF);
6450 {//Invalid parametes, so default printk all RF
6451 bIsPrintAllRF = TRUE;
6455 { //Invalid parametes, so default printk all RF
6456 bIsPrintAllRF = TRUE;
6461 bIsPrintAllRF = TRUE;
6465 memset(msg, 0x00, 2048);
6467 for (rfId = 0; rfId <= 31; rfId++)
6469 // according to Andy, Gary, David require.
6470 // the command RF shall read/write RF register directly for dubug.
6471 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
6472 sprintf(msg+strlen(msg), "%03d = %02X\n", rfId, regRF);
6474 // Copy the information into the user buffer
6475 DBGPRINT(RT_DEBUG_TRACE, ("strlen(msg)=%d\n", (UINT32)strlen(msg)));
6476 wrq->u.data.length = strlen(msg);
6477 if (copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length))
6479 DBGPRINT(RT_DEBUG_TRACE, ("%s: copy_to_user() fail\n", __func__));
6484 if(strlen(msg) == 1)
6485 sprintf(msg+strlen(msg), "===>Error command format!");
6487 DBGPRINT(RT_DEBUG_TRACE, ("copy to user [msg=%s]\n", msg));
6488 // Copy the information into the user buffer
6489 DBGPRINT(RT_DEBUG_TRACE, ("strlen(msg) =%d\n", (UINT32)strlen(msg)));
6491 // Copy the information into the user buffer
6492 wrq->u.data.length = strlen(msg);
6493 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6496 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlRF\n\n"));
6504 INT Set_TGnWifiTest_Proc(
6505 IN PRTMP_ADAPTER pAd,
6508 if (simple_strtol(arg, 0, 10) == 0)
6509 pAd->StaCfg.bTGnWifiTest = FALSE;
6511 pAd->StaCfg.bTGnWifiTest = TRUE;
6513 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_TGnWifiTest_Proc::(bTGnWifiTest=%d)\n", pAd->StaCfg.bTGnWifiTest));
6517 INT Set_LongRetryLimit_Proc(
6518 IN PRTMP_ADAPTER pAdapter,
6521 TX_RTY_CFG_STRUC tx_rty_cfg;
6522 UCHAR LongRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
6524 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
6525 tx_rty_cfg.field.LongRtyLimit = LongRetryLimit;
6526 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
6527 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_LongRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
6531 INT Set_ShortRetryLimit_Proc(
6532 IN PRTMP_ADAPTER pAdapter,
6535 TX_RTY_CFG_STRUC tx_rty_cfg;
6536 UCHAR ShortRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
6538 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
6539 tx_rty_cfg.field.ShortRtyLimit = ShortRetryLimit;
6540 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
6541 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_ShortRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));