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 (iw_handler) rt_ioctl_setparam, /* + 0x02 */
2957 (iw_handler) rt_private_ioctl_bbp, /* + 0x03 */
2959 (iw_handler) NULL, /* + 0x03 */
2961 (iw_handler) NULL, /* + 0x04 */
2962 (iw_handler) NULL, /* + 0x05 */
2963 (iw_handler) NULL, /* + 0x06 */
2964 (iw_handler) NULL, /* + 0x07 */
2965 (iw_handler) NULL, /* + 0x08 */
2966 (iw_handler) rt_private_get_statistics, /* + 0x09 */
2967 (iw_handler) NULL, /* + 0x0A */
2968 (iw_handler) NULL, /* + 0x0B */
2969 (iw_handler) NULL, /* + 0x0C */
2970 (iw_handler) NULL, /* + 0x0D */
2971 (iw_handler) NULL, /* + 0x0E */
2972 (iw_handler) NULL, /* + 0x0F */
2973 (iw_handler) NULL, /* + 0x10 */
2974 (iw_handler) rt_private_show, /* + 0x11 */
2975 (iw_handler) NULL, /* + 0x12 */
2976 (iw_handler) NULL, /* + 0x13 */
2977 (iw_handler) NULL, /* + 0x15 */
2978 (iw_handler) NULL, /* + 0x17 */
2979 (iw_handler) NULL, /* + 0x18 */
2982 const struct iw_handler_def rt28xx_iw_handler_def =
2984 #define N(a) (sizeof (a) / sizeof (a[0]))
2985 .standard = (iw_handler *) rt_handler,
2986 .num_standard = sizeof(rt_handler) / sizeof(iw_handler),
2987 .private = (iw_handler *) rt_priv_handlers,
2988 .num_private = N(rt_priv_handlers),
2989 .private_args = (struct iw_priv_args *) privtab,
2990 .num_private_args = N(privtab),
2991 #if IW_HANDLER_VERSION >= 7
2992 .get_wireless_stats = rt28xx_get_wireless_stats,
2996 INT RTMPSetInformation(
2997 IN PRTMP_ADAPTER pAdapter,
2998 IN OUT struct ifreq *rq,
3001 struct iwreq *wrq = (struct iwreq *) rq;
3002 NDIS_802_11_SSID Ssid;
3003 NDIS_802_11_MAC_ADDRESS Bssid;
3004 RT_802_11_PHY_MODE PhyMode;
3005 RT_802_11_STA_CONFIG StaConfig;
3006 NDIS_802_11_RATES aryRates;
3007 RT_802_11_PREAMBLE Preamble;
3008 NDIS_802_11_WEP_STATUS WepStatus;
3009 NDIS_802_11_AUTHENTICATION_MODE AuthMode = Ndis802_11AuthModeMax;
3010 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
3011 NDIS_802_11_RTS_THRESHOLD RtsThresh;
3012 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
3013 NDIS_802_11_POWER_MODE PowerMode;
3014 PNDIS_802_11_KEY pKey = NULL;
3015 PNDIS_802_11_WEP pWepKey =NULL;
3016 PNDIS_802_11_REMOVE_KEY pRemoveKey = NULL;
3017 NDIS_802_11_CONFIGURATION Config, *pConfig = NULL;
3018 NDIS_802_11_NETWORK_TYPE NetType;
3021 INT Status = NDIS_STATUS_SUCCESS, MaxPhyMode = PHY_11G;
3024 BOOLEAN StateMachineTouched = FALSE;
3025 OID_SET_HT_PHYMODE HT_PhyMode; //11n ,kathy
3026 PNDIS_802_11_PMKID pPmkId = NULL;
3027 BOOLEAN IEEE8021xState = FALSE;
3028 BOOLEAN IEEE8021x_required_keys = FALSE;
3029 UCHAR wpa_supplicant_enable = 0;
3031 MaxPhyMode = PHY_11N_5G;
3033 DBGPRINT(RT_DEBUG_TRACE, ("-->RTMPSetInformation(), 0x%08x\n", cmd&0x7FFF));
3034 switch(cmd & 0x7FFF) {
3035 case RT_OID_802_11_COUNTRY_REGION:
3036 if (wrq->u.data.length < sizeof(UCHAR))
3038 // Only avaliable when EEPROM not programming
3039 else if (!(pAdapter->CommonCfg.CountryRegion & 0x80) && !(pAdapter->CommonCfg.CountryRegionForABand & 0x80))
3044 Status = copy_from_user(&Country, wrq->u.data.pointer, wrq->u.data.length);
3045 pAdapter->CommonCfg.CountryRegion = (UCHAR)(Country & 0x000000FF);
3046 pAdapter->CommonCfg.CountryRegionForABand = (UCHAR)((Country >> 8) & 0x000000FF);
3047 TmpPhy = pAdapter->CommonCfg.PhyMode;
3048 pAdapter->CommonCfg.PhyMode = 0xff;
3049 // Build all corresponding channel information
3050 RTMPSetPhyMode(pAdapter, TmpPhy);
3051 SetCommonHT(pAdapter);
3052 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_COUNTRY_REGION (A:%d B/G:%d)\n", pAdapter->CommonCfg.CountryRegionForABand,
3053 pAdapter->CommonCfg.CountryRegion));
3056 case OID_802_11_BSSID_LIST_SCAN:
3058 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID_LIST_SCAN, TxCnt = %d \n", pAdapter->RalinkCounters.LastOneSecTotalTxCount));
3060 if (MONITOR_ON(pAdapter))
3062 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
3066 //Benson add 20080527, when radio off, sta don't need to scan
3067 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_RADIO_OFF))
3070 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
3072 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is scanning now !!!\n"));
3073 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
3074 Status = NDIS_STATUS_SUCCESS;
3078 if (pAdapter->RalinkCounters.LastOneSecTotalTxCount > 100)
3080 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
3081 Status = NDIS_STATUS_SUCCESS;
3082 pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
3086 if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
3087 ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
3088 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
3089 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
3090 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)) &&
3091 (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
3093 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
3094 Status = NDIS_STATUS_SUCCESS;
3095 pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
3100 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3102 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3103 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3106 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
3107 // this request, because this request is initiated by NDIS.
3108 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
3109 // Reset allowed scan retries
3110 pAdapter->StaCfg.ScanCnt = 0;
3111 pAdapter->StaCfg.LastScanTime = Now;
3113 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
3114 RTMP_SET_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
3115 MlmeEnqueue(pAdapter,
3116 MLME_CNTL_STATE_MACHINE,
3117 OID_802_11_BSSID_LIST_SCAN,
3121 Status = NDIS_STATUS_SUCCESS;
3122 StateMachineTouched = TRUE;
3124 case OID_802_11_SSID:
3125 if (wrq->u.data.length != sizeof(NDIS_802_11_SSID))
3129 PCHAR pSsidString = NULL;
3130 Status = copy_from_user(&Ssid, wrq->u.data.pointer, wrq->u.data.length);
3132 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SSID (Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
3133 if (Ssid.SsidLength > MAX_LEN_OF_SSID)
3137 if (Ssid.SsidLength == 0)
3139 Set_SSID_Proc(pAdapter, "");
3143 pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
3146 NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
3147 NdisMoveMemory(pSsidString, Ssid.Ssid, Ssid.SsidLength);
3148 Set_SSID_Proc(pAdapter, pSsidString);
3157 case OID_802_11_BSSID:
3158 if (wrq->u.data.length != sizeof(NDIS_802_11_MAC_ADDRESS))
3162 Status = copy_from_user(&Bssid, wrq->u.data.pointer, wrq->u.data.length);
3164 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
3165 // this request, because this request is initiated by NDIS.
3166 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
3168 // Prevent to connect AP again in STAMlmePeriodicExec
3169 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
3171 // Reset allowed scan retries
3172 pAdapter->StaCfg.ScanCnt = 0;
3174 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3176 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3177 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3179 MlmeEnqueue(pAdapter,
3180 MLME_CNTL_STATE_MACHINE,
3182 sizeof(NDIS_802_11_MAC_ADDRESS),
3184 Status = NDIS_STATUS_SUCCESS;
3185 StateMachineTouched = TRUE;
3187 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID %02x:%02x:%02x:%02x:%02x:%02x\n",
3188 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
3191 case RT_OID_802_11_RADIO:
3192 if (wrq->u.data.length != sizeof(BOOLEAN))
3196 Status = copy_from_user(&RadioState, wrq->u.data.pointer, wrq->u.data.length);
3197 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RADIO (=%d)\n", RadioState));
3198 if (pAdapter->StaCfg.bSwRadio != RadioState)
3200 pAdapter->StaCfg.bSwRadio = RadioState;
3201 if (pAdapter->StaCfg.bRadio != (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio))
3203 pAdapter->StaCfg.bRadio = (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio);
3204 if (pAdapter->StaCfg.bRadio == TRUE)
3206 MlmeRadioOn(pAdapter);
3207 // Update extra information
3208 pAdapter->ExtraInfo = EXTRA_INFO_CLEAR;
3212 MlmeRadioOff(pAdapter);
3213 // Update extra information
3214 pAdapter->ExtraInfo = SW_RADIO_OFF;
3220 case RT_OID_802_11_PHY_MODE:
3221 if (wrq->u.data.length != sizeof(RT_802_11_PHY_MODE))
3225 Status = copy_from_user(&PhyMode, wrq->u.data.pointer, wrq->u.data.length);
3226 if (PhyMode <= MaxPhyMode)
3228 RTMPSetPhyMode(pAdapter, PhyMode);
3229 SetCommonHT(pAdapter);
3231 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PHY_MODE (=%d)\n", PhyMode));
3234 case RT_OID_802_11_STA_CONFIG:
3235 if (wrq->u.data.length != sizeof(RT_802_11_STA_CONFIG))
3239 Status = copy_from_user(&StaConfig, wrq->u.data.pointer, wrq->u.data.length);
3240 pAdapter->CommonCfg.bEnableTxBurst = StaConfig.EnableTxBurst;
3241 pAdapter->CommonCfg.UseBGProtection = StaConfig.UseBGProtection;
3242 pAdapter->CommonCfg.bUseShortSlotTime = 1; // 2003-10-30 always SHORT SLOT capable
3243 if ((pAdapter->CommonCfg.PhyMode != StaConfig.AdhocMode) &&
3244 (StaConfig.AdhocMode <= MaxPhyMode))
3246 // allow dynamic change of "USE OFDM rate or not" in ADHOC mode
3247 // if setting changed, need to reset current TX rate as well as BEACON frame format
3248 pAdapter->CommonCfg.PhyMode = StaConfig.AdhocMode;
3249 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
3251 RTMPSetPhyMode(pAdapter, PhyMode);
3252 MlmeUpdateTxRates(pAdapter, FALSE, 0);
3253 MakeIbssBeacon(pAdapter); // re-build BEACON frame
3254 AsicEnableIbssSync(pAdapter); // copy to on-chip memory
3257 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_STA_CONFIG (Burst=%d, Protection=%ld,ShortSlot=%d\n",
3258 pAdapter->CommonCfg.bEnableTxBurst,
3259 pAdapter->CommonCfg.UseBGProtection,
3260 pAdapter->CommonCfg.bUseShortSlotTime));
3263 case OID_802_11_DESIRED_RATES:
3264 if (wrq->u.data.length != sizeof(NDIS_802_11_RATES))
3268 Status = copy_from_user(&aryRates, wrq->u.data.pointer, wrq->u.data.length);
3269 NdisZeroMemory(pAdapter->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES);
3270 NdisMoveMemory(pAdapter->CommonCfg.DesireRate, &aryRates, sizeof(NDIS_802_11_RATES));
3271 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DESIRED_RATES (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
3272 pAdapter->CommonCfg.DesireRate[0],pAdapter->CommonCfg.DesireRate[1],
3273 pAdapter->CommonCfg.DesireRate[2],pAdapter->CommonCfg.DesireRate[3],
3274 pAdapter->CommonCfg.DesireRate[4],pAdapter->CommonCfg.DesireRate[5],
3275 pAdapter->CommonCfg.DesireRate[6],pAdapter->CommonCfg.DesireRate[7] ));
3276 // Changing DesiredRate may affect the MAX TX rate we used to TX frames out
3277 MlmeUpdateTxRates(pAdapter, FALSE, 0);
3280 case RT_OID_802_11_PREAMBLE:
3281 if (wrq->u.data.length != sizeof(RT_802_11_PREAMBLE))
3285 Status = copy_from_user(&Preamble, wrq->u.data.pointer, wrq->u.data.length);
3286 if (Preamble == Rt802_11PreambleShort)
3288 pAdapter->CommonCfg.TxPreamble = Preamble;
3289 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleShort);
3291 else if ((Preamble == Rt802_11PreambleLong) || (Preamble == Rt802_11PreambleAuto))
3293 // if user wants AUTO, initialize to LONG here, then change according to AP's
3294 // capability upon association.
3295 pAdapter->CommonCfg.TxPreamble = Preamble;
3296 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleLong);
3303 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PREAMBLE (=%d)\n", Preamble));
3306 case OID_802_11_WEP_STATUS:
3307 if (wrq->u.data.length != sizeof(NDIS_802_11_WEP_STATUS))
3311 Status = copy_from_user(&WepStatus, wrq->u.data.pointer, wrq->u.data.length);
3312 // Since TKIP, AES, WEP are all supported. It should not have any invalid setting
3313 if (WepStatus <= Ndis802_11Encryption3KeyAbsent)
3315 if (pAdapter->StaCfg.WepStatus != WepStatus)
3317 // Config has changed
3318 pAdapter->bConfigChanged = TRUE;
3320 pAdapter->StaCfg.WepStatus = WepStatus;
3321 pAdapter->StaCfg.OrigWepStatus = WepStatus;
3322 pAdapter->StaCfg.PairCipher = WepStatus;
3323 pAdapter->StaCfg.GroupCipher = WepStatus;
3330 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEP_STATUS (=%d)\n",WepStatus));
3333 case OID_802_11_AUTHENTICATION_MODE:
3334 if (wrq->u.data.length != sizeof(NDIS_802_11_AUTHENTICATION_MODE))
3338 Status = copy_from_user(&AuthMode, wrq->u.data.pointer, wrq->u.data.length);
3339 if (AuthMode > Ndis802_11AuthModeMax)
3346 if (pAdapter->StaCfg.AuthMode != AuthMode)
3348 // Config has changed
3349 pAdapter->bConfigChanged = TRUE;
3351 pAdapter->StaCfg.AuthMode = AuthMode;
3353 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
3354 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_AUTHENTICATION_MODE (=%d) \n",pAdapter->StaCfg.AuthMode));
3357 case OID_802_11_INFRASTRUCTURE_MODE:
3358 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_INFRASTRUCTURE))
3362 Status = copy_from_user(&BssType, wrq->u.data.pointer, wrq->u.data.length);
3364 if (BssType == Ndis802_11IBSS)
3365 Set_NetworkType_Proc(pAdapter, "Adhoc");
3366 else if (BssType == Ndis802_11Infrastructure)
3367 Set_NetworkType_Proc(pAdapter, "Infra");
3368 else if (BssType == Ndis802_11Monitor)
3369 Set_NetworkType_Proc(pAdapter, "Monitor");
3373 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_INFRASTRUCTURE_MODE (unknown)\n"));
3377 case OID_802_11_REMOVE_WEP:
3378 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_WEP\n"));
3379 if (wrq->u.data.length != sizeof(NDIS_802_11_KEY_INDEX))
3385 KeyIdx = *(NDIS_802_11_KEY_INDEX *) wrq->u.data.pointer;
3387 if (KeyIdx & 0x80000000)
3389 // Should never set default bit when remove key
3394 KeyIdx = KeyIdx & 0x0fffffff;
3400 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
3401 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
3402 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
3407 case RT_OID_802_11_RESET_COUNTERS:
3408 NdisZeroMemory(&pAdapter->WlanCounters, sizeof(COUNTER_802_11));
3409 NdisZeroMemory(&pAdapter->Counters8023, sizeof(COUNTER_802_3));
3410 NdisZeroMemory(&pAdapter->RalinkCounters, sizeof(COUNTER_RALINK));
3411 pAdapter->Counters8023.RxNoBuffer = 0;
3412 pAdapter->Counters8023.GoodReceives = 0;
3413 pAdapter->Counters8023.RxNoBuffer = 0;
3415 pAdapter->BulkOutComplete = 0;
3416 pAdapter->BulkOutCompleteOther= 0;
3417 pAdapter->BulkOutCompleteCancel = 0;
3418 pAdapter->BulkOutReq = 0;
3419 pAdapter->BulkInReq= 0;
3420 pAdapter->BulkInComplete = 0;
3421 pAdapter->BulkInCompleteFail = 0;
3423 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RESET_COUNTERS \n"));
3425 case OID_802_11_RTS_THRESHOLD:
3426 if (wrq->u.data.length != sizeof(NDIS_802_11_RTS_THRESHOLD))
3430 Status = copy_from_user(&RtsThresh, wrq->u.data.pointer, wrq->u.data.length);
3431 if (RtsThresh > MAX_RTS_THRESHOLD)
3434 pAdapter->CommonCfg.RtsThreshold = (USHORT)RtsThresh;
3436 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_RTS_THRESHOLD (=%ld)\n",RtsThresh));
3438 case OID_802_11_FRAGMENTATION_THRESHOLD:
3439 if (wrq->u.data.length != sizeof(NDIS_802_11_FRAGMENTATION_THRESHOLD))
3443 Status = copy_from_user(&FragThresh, wrq->u.data.pointer, wrq->u.data.length);
3444 pAdapter->CommonCfg.bUseZeroToDisableFragment = FALSE;
3445 if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
3447 if (FragThresh == 0)
3449 pAdapter->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
3450 pAdapter->CommonCfg.bUseZeroToDisableFragment = TRUE;
3456 pAdapter->CommonCfg.FragmentThreshold = (USHORT)FragThresh;
3458 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_FRAGMENTATION_THRESHOLD (=%ld) \n",FragThresh));
3460 case OID_802_11_POWER_MODE:
3461 if (wrq->u.data.length != sizeof(NDIS_802_11_POWER_MODE))
3465 Status = copy_from_user(&PowerMode, wrq->u.data.pointer, wrq->u.data.length);
3466 if (PowerMode == Ndis802_11PowerModeCAM)
3467 Set_PSMode_Proc(pAdapter, "CAM");
3468 else if (PowerMode == Ndis802_11PowerModeMAX_PSP)
3469 Set_PSMode_Proc(pAdapter, "Max_PSP");
3470 else if (PowerMode == Ndis802_11PowerModeFast_PSP)
3471 Set_PSMode_Proc(pAdapter, "Fast_PSP");
3472 else if (PowerMode == Ndis802_11PowerModeLegacy_PSP)
3473 Set_PSMode_Proc(pAdapter, "Legacy_PSP");
3477 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_POWER_MODE (=%d)\n",PowerMode));
3479 case RT_OID_802_11_TX_POWER_LEVEL_1:
3480 if (wrq->u.data.length < sizeof(ULONG))
3484 Status = copy_from_user(&PowerTemp, wrq->u.data.pointer, wrq->u.data.length);
3485 if (PowerTemp > 100)
3486 PowerTemp = 0xffffffff; // AUTO
3487 pAdapter->CommonCfg.TxPowerDefault = PowerTemp; //keep current setting.
3488 pAdapter->CommonCfg.TxPowerPercentage = pAdapter->CommonCfg.TxPowerDefault;
3489 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
3492 case OID_802_11_NETWORK_TYPE_IN_USE:
3493 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_TYPE))
3497 Status = copy_from_user(&NetType, wrq->u.data.pointer, wrq->u.data.length);
3499 if (NetType == Ndis802_11DS)
3500 RTMPSetPhyMode(pAdapter, PHY_11B);
3501 else if (NetType == Ndis802_11OFDM24)
3502 RTMPSetPhyMode(pAdapter, PHY_11BG_MIXED);
3503 else if (NetType == Ndis802_11OFDM5)
3504 RTMPSetPhyMode(pAdapter, PHY_11A);
3508 if (Status == NDIS_STATUS_SUCCESS)
3509 SetCommonHT(pAdapter);
3511 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_NETWORK_TYPE_IN_USE (=%d)\n",NetType));
3514 // For WPA PSK PMK key
3515 case RT_OID_802_11_ADD_WPA:
3516 pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3523 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
3524 if (pKey->Length != wrq->u.data.length)
3527 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!!\n"));
3531 if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
3532 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
3533 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone) )
3535 Status = -EOPNOTSUPP;
3536 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!! [AuthMode != WPAPSK/WPA2PSK/WPANONE]\n"));
3538 else if ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
3539 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
3540 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) ) // Only for WPA PSK mode
3542 NdisMoveMemory(pAdapter->StaCfg.PMK, &pKey->KeyMaterial, pKey->KeyLength);
3543 // Use RaConfig as PSK agent.
3544 // Start STA supplicant state machine
3545 if (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
3546 pAdapter->StaCfg.WpaState = SS_START;
3548 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3552 pAdapter->StaCfg.WpaState = SS_NOTUSE;
3553 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3558 case OID_802_11_REMOVE_KEY:
3559 pRemoveKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3560 if(pRemoveKey == NULL)
3566 Status = copy_from_user(pRemoveKey, wrq->u.data.pointer, wrq->u.data.length);
3567 if (pRemoveKey->Length != wrq->u.data.length)
3570 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!\n"));
3574 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3576 RTMPWPARemoveKeyProc(pAdapter, pRemoveKey);
3577 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Remove WPA Key!!\n"));
3581 KeyIdx = pRemoveKey->KeyIndex;
3583 if (KeyIdx & 0x80000000)
3585 // Should never set default bit when remove key
3587 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(Should never set default bit when remove key)\n"));
3591 KeyIdx = KeyIdx & 0x0fffffff;
3595 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(KeyId[%d] out of range)\n", KeyIdx));
3599 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
3600 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
3601 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
3602 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY (id=0x%x, Len=%d-byte)\n", pRemoveKey->KeyIndex, pRemoveKey->Length));
3610 case OID_802_11_ADD_KEY:
3611 pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3617 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
3618 if (pKey->Length != wrq->u.data.length)
3621 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY, Failed!!\n"));
3625 RTMPAddKey(pAdapter, pKey);
3626 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3630 case OID_802_11_CONFIGURATION:
3631 if (wrq->u.data.length != sizeof(NDIS_802_11_CONFIGURATION))
3635 Status = copy_from_user(&Config, wrq->u.data.pointer, wrq->u.data.length);
3638 if ((pConfig->BeaconPeriod >= 20) && (pConfig->BeaconPeriod <=400))
3639 pAdapter->CommonCfg.BeaconPeriod = (USHORT) pConfig->BeaconPeriod;
3641 pAdapter->StaActive.AtimWin = (USHORT) pConfig->ATIMWindow;
3642 MAP_KHZ_TO_CHANNEL_ID(pConfig->DSConfig, pAdapter->CommonCfg.Channel);
3644 // Save the channel on MlmeAux for CntlOidRTBssidProc used.
3646 pAdapter->MlmeAux.Channel = pAdapter->CommonCfg.Channel;
3648 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_CONFIGURATION (BeacnPeriod=%ld,AtimW=%ld,Ch=%d)\n",
3649 pConfig->BeaconPeriod, pConfig->ATIMWindow, pAdapter->CommonCfg.Channel));
3650 // Config has changed
3651 pAdapter->bConfigChanged = TRUE;
3654 case RT_OID_802_11_SET_HT_PHYMODE:
3655 if (wrq->u.data.length != sizeof(OID_SET_HT_PHYMODE))
3659 POID_SET_HT_PHYMODE pHTPhyMode = &HT_PhyMode;
3661 Status = copy_from_user(&HT_PhyMode, wrq->u.data.pointer, wrq->u.data.length);
3662 DBGPRINT(RT_DEBUG_TRACE, ("Set::pHTPhyMode (PhyMode = %d,TransmitNo = %d, HtMode = %d, ExtOffset = %d , MCS = %d, BW = %d, STBC = %d, SHORTGI = %d) \n",
3663 pHTPhyMode->PhyMode, pHTPhyMode->TransmitNo,pHTPhyMode->HtMode,pHTPhyMode->ExtOffset,
3664 pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->SHORTGI));
3665 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
3666 RTMPSetHT(pAdapter, pHTPhyMode);
3668 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_HT_PHYMODE(MCS=%d,BW=%d,SGI=%d,STBC=%d)\n",
3669 pAdapter->StaCfg.HTPhyMode.field.MCS, pAdapter->StaCfg.HTPhyMode.field.BW, pAdapter->StaCfg.HTPhyMode.field.ShortGI,
3670 pAdapter->StaCfg.HTPhyMode.field.STBC));
3672 case RT_OID_802_11_SET_APSD_SETTING:
3673 if (wrq->u.data.length != sizeof(ULONG))
3678 Status = copy_from_user(&apsd, wrq->u.data.pointer, wrq->u.data.length);
3680 /*-------------------------------------------------------------------
3681 |B31~B7 | B6~B5 | B4 | B3 | B2 | B1 | B0 |
3682 ---------------------------------------------------------------------
3683 | Rsvd | Max SP Len | AC_VO | AC_VI | AC_BK | AC_BE | APSD Capable |
3684 ---------------------------------------------------------------------*/
3685 pAdapter->CommonCfg.bAPSDCapable = (apsd & 0x00000001) ? TRUE : FALSE;
3686 pAdapter->CommonCfg.bAPSDAC_BE = ((apsd & 0x00000002) >> 1) ? TRUE : FALSE;
3687 pAdapter->CommonCfg.bAPSDAC_BK = ((apsd & 0x00000004) >> 2) ? TRUE : FALSE;
3688 pAdapter->CommonCfg.bAPSDAC_VI = ((apsd & 0x00000008) >> 3) ? TRUE : FALSE;
3689 pAdapter->CommonCfg.bAPSDAC_VO = ((apsd & 0x00000010) >> 4) ? TRUE : FALSE;
3690 pAdapter->CommonCfg.MaxSPLength = (UCHAR)((apsd & 0x00000060) >> 5);
3692 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,
3693 pAdapter->CommonCfg.bAPSDAC_BE, pAdapter->CommonCfg.bAPSDAC_BK, pAdapter->CommonCfg.bAPSDAC_VI, pAdapter->CommonCfg.bAPSDAC_VO, pAdapter->CommonCfg.MaxSPLength));
3697 case RT_OID_802_11_SET_APSD_PSM:
3698 if (wrq->u.data.length != sizeof(ULONG))
3702 // Driver needs to notify AP when PSM changes
3703 Status = copy_from_user(&pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.pointer, wrq->u.data.length);
3704 if (pAdapter->CommonCfg.bAPSDForcePowerSave != pAdapter->StaCfg.Psm)
3706 MlmeSetPsmBit(pAdapter, pAdapter->CommonCfg.bAPSDForcePowerSave);
3707 RTMPSendNullFrame(pAdapter, pAdapter->CommonCfg.TxRate, TRUE);
3709 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_APSD_PSM (bAPSDForcePowerSave:%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
3713 case RT_OID_802_11_SET_WMM:
3714 if (wrq->u.data.length != sizeof(BOOLEAN))
3718 Status = copy_from_user(&pAdapter->CommonCfg.bWmmCapable, wrq->u.data.pointer, wrq->u.data.length);
3719 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_WMM (=%d) \n", pAdapter->CommonCfg.bWmmCapable));
3723 case OID_802_11_DISASSOCIATE:
3725 // Set NdisRadioStateOff to TRUE, instead of called MlmeRadioOff.
3726 // Later on, NDIS_802_11_BSSID_LIST_EX->NumberOfItems should be 0
3727 // when query OID_802_11_BSSID_LIST.
3729 // TRUE: NumberOfItems will set to 0.
3730 // FALSE: NumberOfItems no change.
3732 pAdapter->CommonCfg.NdisRadioStateOff = TRUE;
3733 // Set to immediately send the media disconnect event
3734 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
3735 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DISASSOCIATE \n"));
3737 if (INFRA_ON(pAdapter))
3739 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3741 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3742 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3745 MlmeEnqueue(pAdapter,
3746 MLME_CNTL_STATE_MACHINE,
3747 OID_802_11_DISASSOCIATE,
3751 StateMachineTouched = TRUE;
3754 case RT_OID_802_11_SET_IMME_BA_CAP:
3755 if (wrq->u.data.length != sizeof(OID_BACAP_STRUC))
3759 OID_BACAP_STRUC Orde ;
3760 Status = copy_from_user(&Orde, wrq->u.data.pointer, wrq->u.data.length);
3761 if (Orde.Policy > BA_NOTUSE)
3763 Status = NDIS_STATUS_INVALID_DATA;
3765 else if (Orde.Policy == BA_NOTUSE)
3767 pAdapter->CommonCfg.BACapability.field.Policy = BA_NOTUSE;
3768 pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
3769 pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
3770 pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
3771 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
3772 pAdapter->CommonCfg.DesiredHtPhy.MimoPs= Orde.MMPSmode;
3773 pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
3775 pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
3776 pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
3777 pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
3781 pAdapter->CommonCfg.BACapability.field.AutoBA = Orde.AutoBA;
3782 pAdapter->CommonCfg.BACapability.field.Policy = IMMED_BA; // we only support immediate BA.
3783 pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
3784 pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
3785 pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
3786 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
3787 pAdapter->CommonCfg.DesiredHtPhy.MimoPs = Orde.MMPSmode;
3788 pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
3791 pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
3792 pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
3793 pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
3795 if (pAdapter->CommonCfg.BACapability.field.RxBAWinLimit > MAX_RX_REORDERBUF)
3796 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = MAX_RX_REORDERBUF;
3800 pAdapter->CommonCfg.REGBACapability.word = pAdapter->CommonCfg.BACapability.word;
3801 DBGPRINT(RT_DEBUG_TRACE, ("Set::(Orde.AutoBA = %d) (Policy=%d)(ReBAWinLimit=%d)(TxBAWinLimit=%d)(AutoMode=%d)\n",Orde.AutoBA, pAdapter->CommonCfg.BACapability.field.Policy,
3802 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit,pAdapter->CommonCfg.BACapability.field.TxBAWinLimit, pAdapter->CommonCfg.BACapability.field.AutoBA));
3803 DBGPRINT(RT_DEBUG_TRACE, ("Set::(MimoPs = %d)(AmsduEnable = %d) (AmsduSize=%d)(MpduDensity=%d)\n",pAdapter->CommonCfg.DesiredHtPhy.MimoPs, pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable,
3804 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize, pAdapter->CommonCfg.DesiredHtPhy.MpduDensity));
3808 case RT_OID_802_11_ADD_IMME_BA:
3809 DBGPRINT(RT_DEBUG_TRACE, (" Set :: RT_OID_802_11_ADD_IMME_BA \n"));
3810 if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
3815 OID_ADD_BA_ENTRY BA;
3816 MAC_TABLE_ENTRY *pEntry;
3818 Status = copy_from_user(&BA, wrq->u.data.pointer, wrq->u.data.length);
3821 Status = NDIS_STATUS_INVALID_DATA;
3826 //BATableInsertEntry
3827 //As ad-hoc mode, BA pair is not limited to only BSSID. so add via OID.
3829 // in ad hoc mode, when adding BA pair, we should insert this entry into MACEntry too
3830 pEntry = MacTableLookup(pAdapter, BA.MACAddr);
3833 DBGPRINT(RT_DEBUG_TRACE, ("RT_OID_802_11_ADD_IMME_BA. break on no connection.----:%x:%x\n", BA.MACAddr[4], BA.MACAddr[5]));
3836 if (BA.IsRecipient == FALSE)
3838 if (pEntry->bIAmBadAtheros == TRUE)
3839 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = 0x10;
3841 BAOriSessionSetUp(pAdapter, pEntry, index, 0, 100, TRUE);
3845 //BATableInsertEntry(pAdapter, pEntry->Aid, BA.MACAddr, 0, 0xffff, BA.TID, BA.nMSDU, BA.IsRecipient);
3848 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_IMME_BA. Rec = %d. Mac = %x:%x:%x:%x:%x:%x . \n",
3849 BA.IsRecipient, BA.MACAddr[0], BA.MACAddr[1], BA.MACAddr[2], BA.MACAddr[2]
3850 , BA.MACAddr[4], BA.MACAddr[5]));
3855 case RT_OID_802_11_TEAR_IMME_BA:
3856 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA \n"));
3857 if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
3861 POID_ADD_BA_ENTRY pBA;
3862 MAC_TABLE_ENTRY *pEntry;
3864 pBA = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3868 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA kmalloc() can't allocate enough memory\n"));
3869 Status = NDIS_STATUS_FAILURE;
3873 Status = copy_from_user(pBA, wrq->u.data.pointer, wrq->u.data.length);
3874 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA(TID=%d, bAllTid=%d)\n", pBA->TID, pBA->bAllTid));
3876 if (!pBA->bAllTid && (pBA->TID > NUM_OF_TID))
3878 Status = NDIS_STATUS_INVALID_DATA;
3882 if (pBA->IsRecipient == FALSE)
3884 pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
3885 DBGPRINT(RT_DEBUG_TRACE, (" pBA->IsRecipient == FALSE\n"));
3888 DBGPRINT(RT_DEBUG_TRACE, (" pBA->pEntry\n"));
3889 BAOriSessionTearDown(pAdapter, pEntry->Aid, pBA->TID, FALSE, TRUE);
3892 DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
3896 pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
3899 BARecSessionTearDown( pAdapter, (UCHAR)pEntry->Aid, pBA->TID, TRUE);
3902 DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
3908 // For WPA_SUPPLICANT to set static wep key
3909 case OID_802_11_ADD_WEP:
3910 pWepKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3915 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed!!\n"));
3918 Status = copy_from_user(pWepKey, wrq->u.data.pointer, wrq->u.data.length);
3922 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (length mismatch)!!\n"));
3926 KeyIdx = pWepKey->KeyIndex & 0x0fffffff;
3927 // KeyIdx must be 0 ~ 3
3931 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (KeyIdx must be smaller than 4)!!\n"));
3935 UCHAR CipherAlg = 0;
3938 // set key material and key length
3939 NdisZeroMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, 16);
3940 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
3941 NdisMoveMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
3943 switch(pWepKey->KeyLength)
3946 CipherAlg = CIPHER_WEP64;
3949 CipherAlg = CIPHER_WEP128;
3952 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, only support CIPHER_WEP64(len:5) & CIPHER_WEP128(len:13)!!\n"));
3956 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CipherAlg;
3958 // Default key for tx (shared key)
3959 if (pWepKey->KeyIndex & 0x80000000)
3961 // set key material and key length
3962 NdisZeroMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, 16);
3963 pAdapter->StaCfg.DesireSharedKey[KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
3964 NdisMoveMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
3965 pAdapter->StaCfg.DesireSharedKeyId = KeyIdx;
3966 pAdapter->StaCfg.DesireSharedKey[KeyIdx].CipherAlg = CipherAlg;
3967 pAdapter->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
3970 if (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)
3972 Key = pAdapter->SharedKey[BSS0][KeyIdx].Key;
3974 // Set key material and cipherAlg to Asic
3975 AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
3977 if (pWepKey->KeyIndex & 0x80000000)
3979 PMAC_TABLE_ENTRY pEntry = &pAdapter->MacTab.Content[BSSID_WCID];
3980 // Assign group key info
3981 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
3982 // Assign pairwise key info
3983 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, pEntry);
3986 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"));
3991 case OID_SET_COUNTERMEASURES:
3992 if (wrq->u.data.length != sizeof(int))
3997 Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
3999 pAdapter->StaCfg.bBlockAssoc = TRUE;
4001 // WPA MIC error should block association attempt for 60 seconds
4002 pAdapter->StaCfg.bBlockAssoc = FALSE;
4003 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_SET_COUNTERMEASURES bBlockAssoc=%s\n", pAdapter->StaCfg.bBlockAssoc ? "TRUE":"FALSE"));
4006 case RT_OID_WPA_SUPPLICANT_SUPPORT:
4007 if (wrq->u.data.length != sizeof(UCHAR))
4011 Status = copy_from_user(&wpa_supplicant_enable, wrq->u.data.pointer, wrq->u.data.length);
4012 pAdapter->StaCfg.WpaSupplicantUP = wpa_supplicant_enable;
4013 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
4016 case OID_802_11_DEAUTHENTICATION:
4017 if (wrq->u.data.length != sizeof(MLME_DEAUTH_REQ_STRUCT))
4021 MLME_DEAUTH_REQ_STRUCT *pInfo;
4022 MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
4024 pInfo = (MLME_DEAUTH_REQ_STRUCT *) MsgElem->Msg;
4025 Status = copy_from_user(pInfo, wrq->u.data.pointer, wrq->u.data.length);
4026 MlmeDeauthReqAction(pAdapter, MsgElem);
4029 if (INFRA_ON(pAdapter))
4031 LinkDown(pAdapter, FALSE);
4032 pAdapter->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
4034 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DEAUTHENTICATION (Reason=%d)\n", pInfo->Reason));
4037 case OID_802_11_DROP_UNENCRYPTED:
4038 if (wrq->u.data.length != sizeof(int))
4043 Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
4045 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
4047 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
4048 NdisAcquireSpinLock(&pAdapter->MacTabLock);
4049 pAdapter->MacTab.Content[BSSID_WCID].PortSecured = pAdapter->StaCfg.PortSecured;
4050 NdisReleaseSpinLock(&pAdapter->MacTabLock);
4051 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DROP_UNENCRYPTED (=%d)\n", enabled));
4054 case OID_802_11_SET_IEEE8021X:
4055 if (wrq->u.data.length != sizeof(BOOLEAN))
4059 Status = copy_from_user(&IEEE8021xState, wrq->u.data.pointer, wrq->u.data.length);
4060 pAdapter->StaCfg.IEEE8021X = IEEE8021xState;
4061 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X (=%d)\n", IEEE8021xState));
4064 case OID_802_11_SET_IEEE8021X_REQUIRE_KEY:
4065 if (wrq->u.data.length != sizeof(BOOLEAN))
4069 Status = copy_from_user(&IEEE8021x_required_keys, wrq->u.data.pointer, wrq->u.data.length);
4070 pAdapter->StaCfg.IEEE8021x_required_keys = IEEE8021x_required_keys;
4071 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X_REQUIRE_KEY (%d)\n", IEEE8021x_required_keys));
4074 case OID_802_11_PMKID:
4075 pPmkId = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4077 if(pPmkId == NULL) {
4081 Status = copy_from_user(pPmkId, wrq->u.data.pointer, wrq->u.data.length);
4083 // check the PMKID information
4084 if (pPmkId->BSSIDInfoCount == 0)
4085 NdisZeroMemory(pAdapter->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
4088 PBSSID_INFO pBssIdInfo;
4092 for (BssIdx = 0; BssIdx < pPmkId->BSSIDInfoCount; BssIdx++)
4094 // point to the indexed BSSID_INFO structure
4095 pBssIdInfo = (PBSSID_INFO) ((PUCHAR) pPmkId + 2 * sizeof(UINT) + BssIdx * sizeof(BSSID_INFO));
4096 // Find the entry in the saved data base.
4097 for (CachedIdx = 0; CachedIdx < pAdapter->StaCfg.SavedPMKNum; CachedIdx++)
4099 // compare the BSSID
4100 if (NdisEqualMemory(pBssIdInfo->BSSID, pAdapter->StaCfg.SavedPMK[CachedIdx].BSSID, sizeof(NDIS_802_11_MAC_ADDRESS)))
4104 // Found, replace it
4105 if (CachedIdx < PMKID_NO)
4107 DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
4108 NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
4109 pAdapter->StaCfg.SavedPMKNum++;
4111 // Not found, replace the last one
4114 // Randomly replace one
4115 CachedIdx = (pBssIdInfo->BSSID[5] % PMKID_NO);
4116 DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
4117 NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
4125 DBGPRINT(RT_DEBUG_TRACE, ("Set::unknown IOCTL's subcmd = 0x%08x\n", cmd));
4126 Status = -EOPNOTSUPP;
4134 INT RTMPQueryInformation(
4135 IN PRTMP_ADAPTER pAdapter,
4136 IN OUT struct ifreq *rq,
4139 struct iwreq *wrq = (struct iwreq *) rq;
4140 NDIS_802_11_BSSID_LIST_EX *pBssidList = NULL;
4141 PNDIS_WLAN_BSSID_EX pBss;
4142 NDIS_802_11_SSID Ssid;
4143 NDIS_802_11_CONFIGURATION *pConfiguration = NULL;
4144 RT_802_11_LINK_STATUS *pLinkStatus = NULL;
4145 RT_802_11_STA_CONFIG *pStaConfig = NULL;
4146 NDIS_802_11_STATISTICS *pStatistics = NULL;
4147 NDIS_802_11_RTS_THRESHOLD RtsThresh;
4148 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
4149 NDIS_802_11_POWER_MODE PowerMode;
4150 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
4151 RT_802_11_PREAMBLE PreamType;
4152 NDIS_802_11_AUTHENTICATION_MODE AuthMode;
4153 NDIS_802_11_WEP_STATUS WepStatus;
4154 NDIS_MEDIA_STATE MediaState;
4155 ULONG BssBufSize, ulInfo=0, NetworkTypeList[4], apsd = 0;
4157 PUCHAR pBuf = NULL, pPtr;
4158 INT Status = NDIS_STATUS_SUCCESS;
4159 UINT we_version_compiled;
4160 UCHAR i, Padding = 0;
4162 UCHAR driverVersion[8];
4163 OID_SET_HT_PHYMODE *pHTPhyMode = NULL;
4167 case RT_OID_DEVICE_NAME:
4168 wrq->u.data.length = sizeof(STA_NIC_DEVICE_NAME);
4169 Status = copy_to_user(wrq->u.data.pointer, STA_NIC_DEVICE_NAME, wrq->u.data.length);
4171 case RT_OID_VERSION_INFO:
4172 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_VERSION_INFO \n"));
4173 wrq->u.data.length = 8*sizeof(UCHAR);
4174 sprintf(&driverVersion[0], "%s", STA_DRIVER_VERSION);
4175 driverVersion[7] = '\0';
4176 if (copy_to_user(wrq->u.data.pointer, &driverVersion, wrq->u.data.length))
4181 case OID_802_11_BSSID_LIST:
4182 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
4185 * Still scanning, indicate the caller should try again.
4187 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (Still scanning)\n"));
4190 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (%d BSS returned)\n",pAdapter->ScanTab.BssNr));
4191 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
4192 // Claculate total buffer size required
4193 BssBufSize = sizeof(ULONG);
4195 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
4197 // Align pointer to 4 bytes boundary.
4198 //Padding = 4 - (pAdapter->ScanTab.BssEntry[i].VarIELen & 0x0003);
4201 BssBufSize += (sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
4204 // For safety issue, we add 256 bytes just in case
4206 // Allocate the same size as passed from higher layer
4207 pBuf = kmalloc(BssBufSize, MEM_ALLOC_FLAG);
4213 // Init 802_11_BSSID_LIST_EX structure
4214 NdisZeroMemory(pBuf, BssBufSize);
4215 pBssidList = (PNDIS_802_11_BSSID_LIST_EX) pBuf;
4216 pBssidList->NumberOfItems = pAdapter->ScanTab.BssNr;
4218 // Calculate total buffer length
4219 BssLen = 4; // Consist of NumberOfItems
4220 // Point to start of NDIS_WLAN_BSSID_EX
4221 // pPtr = pBuf + sizeof(ULONG);
4222 pPtr = (PUCHAR) &pBssidList->Bssid[0];
4223 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
4225 pBss = (PNDIS_WLAN_BSSID_EX) pPtr;
4226 NdisMoveMemory(&pBss->MacAddress, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
4227 if ((pAdapter->ScanTab.BssEntry[i].Hidden == 1) && (pAdapter->StaCfg.bShowHiddenSSID == FALSE))
4230 // We must return this SSID during 4way handshaking, otherwise Aegis will failed to parse WPA infomation
4231 // and then failed to send EAPOl farame.
4233 if ((pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) && (pAdapter->StaCfg.PortSecured != WPA_802_1X_PORT_SECURED))
4235 pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
4236 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
4239 pBss->Ssid.SsidLength = 0;
4243 pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
4244 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
4246 pBss->Privacy = pAdapter->ScanTab.BssEntry[i].Privacy;
4247 pBss->Rssi = pAdapter->ScanTab.BssEntry[i].Rssi - pAdapter->BbpRssiToDbmDelta;
4248 pBss->NetworkTypeInUse = NetworkTypeInUseSanity(&pAdapter->ScanTab.BssEntry[i]);
4249 pBss->Configuration.Length = sizeof(NDIS_802_11_CONFIGURATION);
4250 pBss->Configuration.BeaconPeriod = pAdapter->ScanTab.BssEntry[i].BeaconPeriod;
4251 pBss->Configuration.ATIMWindow = pAdapter->ScanTab.BssEntry[i].AtimWin;
4253 MAP_CHANNEL_ID_TO_KHZ(pAdapter->ScanTab.BssEntry[i].Channel, pBss->Configuration.DSConfig);
4255 if (pAdapter->ScanTab.BssEntry[i].BssType == BSS_INFRA)
4256 pBss->InfrastructureMode = Ndis802_11Infrastructure;
4258 pBss->InfrastructureMode = Ndis802_11IBSS;
4260 NdisMoveMemory(pBss->SupportedRates, pAdapter->ScanTab.BssEntry[i].SupRate, pAdapter->ScanTab.BssEntry[i].SupRateLen);
4261 NdisMoveMemory(pBss->SupportedRates + pAdapter->ScanTab.BssEntry[i].SupRateLen,
4262 pAdapter->ScanTab.BssEntry[i].ExtRate,
4263 pAdapter->ScanTab.BssEntry[i].ExtRateLen);
4265 if (pAdapter->ScanTab.BssEntry[i].VarIELen == 0)
4267 pBss->IELength = sizeof(NDIS_802_11_FIXED_IEs);
4268 NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
4269 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
4273 pBss->IELength = (ULONG)(sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen);
4274 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
4275 NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
4276 NdisMoveMemory(pBss->IEs + sizeof(NDIS_802_11_FIXED_IEs), pAdapter->ScanTab.BssEntry[i].VarIEs, pAdapter->ScanTab.BssEntry[i].VarIELen);
4277 pPtr += pAdapter->ScanTab.BssEntry[i].VarIELen;
4279 pBss->Length = (ULONG)(sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
4281 #if WIRELESS_EXT < 17
4282 if ((BssLen + pBss->Length) < wrq->u.data.length)
4283 BssLen += pBss->Length;
4286 pBssidList->NumberOfItems = i;
4290 BssLen += pBss->Length;
4294 #if WIRELESS_EXT < 17
4295 wrq->u.data.length = BssLen;
4297 if (BssLen > wrq->u.data.length)
4303 wrq->u.data.length = BssLen;
4305 Status = copy_to_user(wrq->u.data.pointer, pBssidList, BssLen);
4308 case OID_802_3_CURRENT_ADDRESS:
4309 wrq->u.data.length = MAC_ADDR_LEN;
4310 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
4312 case OID_GEN_MEDIA_CONNECT_STATUS:
4313 if (pAdapter->IndicateMediaState == NdisMediaStateConnected)
4314 MediaState = NdisMediaStateConnected;
4316 MediaState = NdisMediaStateDisconnected;
4318 wrq->u.data.length = sizeof(NDIS_MEDIA_STATE);
4319 Status = copy_to_user(wrq->u.data.pointer, &MediaState, wrq->u.data.length);
4321 case OID_802_11_BSSID:
4322 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
4324 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Bssid, sizeof(NDIS_802_11_MAC_ADDRESS));
4329 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID(=EMPTY)\n"));
4333 case OID_802_11_SSID:
4334 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
4335 NdisZeroMemory(Ssid.Ssid, MAX_LEN_OF_SSID);
4336 Ssid.SsidLength = pAdapter->CommonCfg.SsidLen;
4337 memcpy(Ssid.Ssid, pAdapter->CommonCfg.Ssid, Ssid.SsidLength);
4338 wrq->u.data.length = sizeof(NDIS_802_11_SSID);
4339 Status = copy_to_user(wrq->u.data.pointer, &Ssid, wrq->u.data.length);
4340 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_SSID (Len=%d, ssid=%s)\n", Ssid.SsidLength,Ssid.Ssid));
4342 case RT_OID_802_11_QUERY_LINK_STATUS:
4343 pLinkStatus = (RT_802_11_LINK_STATUS *) kmalloc(sizeof(RT_802_11_LINK_STATUS), MEM_ALLOC_FLAG);
4346 pLinkStatus->CurrTxRate = RateIdTo500Kbps[pAdapter->CommonCfg.TxRate]; // unit : 500 kbps
4347 pLinkStatus->ChannelQuality = pAdapter->Mlme.ChannelQuality;
4348 pLinkStatus->RxByteCount = pAdapter->RalinkCounters.ReceivedByteCount;
4349 pLinkStatus->TxByteCount = pAdapter->RalinkCounters.TransmittedByteCount;
4350 pLinkStatus->CentralChannel = pAdapter->CommonCfg.CentralChannel;
4351 wrq->u.data.length = sizeof(RT_802_11_LINK_STATUS);
4352 Status = copy_to_user(wrq->u.data.pointer, pLinkStatus, wrq->u.data.length);
4354 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS\n"));
4358 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS(kmalloc failed)\n"));
4362 case OID_802_11_CONFIGURATION:
4363 pConfiguration = (NDIS_802_11_CONFIGURATION *) kmalloc(sizeof(NDIS_802_11_CONFIGURATION), MEM_ALLOC_FLAG);
4366 pConfiguration->Length = sizeof(NDIS_802_11_CONFIGURATION);
4367 pConfiguration->BeaconPeriod = pAdapter->CommonCfg.BeaconPeriod;
4368 pConfiguration->ATIMWindow = pAdapter->StaActive.AtimWin;
4369 MAP_CHANNEL_ID_TO_KHZ(pAdapter->CommonCfg.Channel, pConfiguration->DSConfig);
4370 wrq->u.data.length = sizeof(NDIS_802_11_CONFIGURATION);
4371 Status = copy_to_user(wrq->u.data.pointer, pConfiguration, wrq->u.data.length);
4372 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(BeaconPeriod=%ld,AtimW=%ld,Channel=%d) \n",
4373 pConfiguration->BeaconPeriod, pConfiguration->ATIMWindow, pAdapter->CommonCfg.Channel));
4374 kfree(pConfiguration);
4378 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(kmalloc failed)\n"));
4382 case RT_OID_802_11_SNR_0:
4383 if ((pAdapter->StaCfg.LastSNR0 > 0))
4385 ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR0) * 3) / 16 ;
4386 wrq->u.data.length = sizeof(ulInfo);
4387 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4388 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_SNR_0(0x=%lx)\n", ulInfo));
4393 case RT_OID_802_11_SNR_1:
4394 if ((pAdapter->Antenna.field.RxPath > 1) &&
4395 (pAdapter->StaCfg.LastSNR1 > 0))
4397 ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR1) * 3) / 16 ;
4398 wrq->u.data.length = sizeof(ulInfo);
4399 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4400 DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(0x=%lx)\n",ulInfo));
4404 DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(pAdapter->StaCfg.LastSNR1=%d)\n",pAdapter->StaCfg.LastSNR1));
4406 case OID_802_11_RSSI_TRIGGER:
4407 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0 - pAdapter->BbpRssiToDbmDelta;
4408 wrq->u.data.length = sizeof(ulInfo);
4409 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4410 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RSSI_TRIGGER(=%ld)\n", ulInfo));
4412 case OID_802_11_RSSI:
4413 case RT_OID_802_11_RSSI:
4414 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0;
4415 wrq->u.data.length = sizeof(ulInfo);
4416 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4418 case RT_OID_802_11_RSSI_1:
4419 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi1;
4420 wrq->u.data.length = sizeof(ulInfo);
4421 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4423 case RT_OID_802_11_RSSI_2:
4424 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi2;
4425 wrq->u.data.length = sizeof(ulInfo);
4426 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4428 case OID_802_11_STATISTICS:
4429 pStatistics = (NDIS_802_11_STATISTICS *) kmalloc(sizeof(NDIS_802_11_STATISTICS), MEM_ALLOC_FLAG);
4432 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS \n"));
4433 // add the most up-to-date h/w raw counters into software counters
4434 NICUpdateRawCounters(pAdapter);
4436 // Sanity check for calculation of sucessful count
4437 if (pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart < pAdapter->WlanCounters.RetryCount.QuadPart)
4438 pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
4440 pStatistics->TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart;
4441 pStatistics->MulticastTransmittedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastTransmittedFrameCount.QuadPart;
4442 pStatistics->FailedCount.QuadPart = pAdapter->WlanCounters.FailedCount.QuadPart;
4443 pStatistics->RetryCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
4444 pStatistics->MultipleRetryCount.QuadPart = pAdapter->WlanCounters.MultipleRetryCount.QuadPart;
4445 pStatistics->RTSSuccessCount.QuadPart = pAdapter->WlanCounters.RTSSuccessCount.QuadPart;
4446 pStatistics->RTSFailureCount.QuadPart = pAdapter->WlanCounters.RTSFailureCount.QuadPart;
4447 pStatistics->ACKFailureCount.QuadPart = pAdapter->WlanCounters.ACKFailureCount.QuadPart;
4448 pStatistics->FrameDuplicateCount.QuadPart = pAdapter->WlanCounters.FrameDuplicateCount.QuadPart;
4449 pStatistics->ReceivedFragmentCount.QuadPart = pAdapter->WlanCounters.ReceivedFragmentCount.QuadPart;
4450 pStatistics->MulticastReceivedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastReceivedFrameCount.QuadPart;
4452 pStatistics->FCSErrorCount = pAdapter->RalinkCounters.RealFcsErrCount;
4454 pStatistics->FCSErrorCount.QuadPart = pAdapter->WlanCounters.FCSErrorCount.QuadPart;
4455 pStatistics->FrameDuplicateCount.u.LowPart = pAdapter->WlanCounters.FrameDuplicateCount.u.LowPart / 100;
4457 wrq->u.data.length = sizeof(NDIS_802_11_STATISTICS);
4458 Status = copy_to_user(wrq->u.data.pointer, pStatistics, wrq->u.data.length);
4463 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS(kmalloc failed)\n"));
4467 case OID_GEN_RCV_OK:
4468 ulInfo = pAdapter->Counters8023.GoodReceives;
4469 wrq->u.data.length = sizeof(ulInfo);
4470 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4472 case OID_GEN_RCV_NO_BUFFER:
4473 ulInfo = pAdapter->Counters8023.RxNoBuffer;
4474 wrq->u.data.length = sizeof(ulInfo);
4475 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4477 case RT_OID_802_11_PHY_MODE:
4478 ulInfo = (ULONG)pAdapter->CommonCfg.PhyMode;
4479 wrq->u.data.length = sizeof(ulInfo);
4480 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4481 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PHY_MODE (=%ld)\n", ulInfo));
4483 case RT_OID_802_11_STA_CONFIG:
4484 pStaConfig = (RT_802_11_STA_CONFIG *) kmalloc(sizeof(RT_802_11_STA_CONFIG), MEM_ALLOC_FLAG);
4487 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG\n"));
4488 pStaConfig->EnableTxBurst = pAdapter->CommonCfg.bEnableTxBurst;
4489 pStaConfig->EnableTurboRate = 0;
4490 pStaConfig->UseBGProtection = pAdapter->CommonCfg.UseBGProtection;
4491 pStaConfig->UseShortSlotTime = pAdapter->CommonCfg.bUseShortSlotTime;
4492 //pStaConfig->AdhocMode = pAdapter->StaCfg.AdhocMode;
4493 pStaConfig->HwRadioStatus = (pAdapter->StaCfg.bHwRadio == TRUE) ? 1 : 0;
4494 pStaConfig->Rsv1 = 0;
4495 pStaConfig->SystemErrorBitmap = pAdapter->SystemErrorBitmap;
4496 wrq->u.data.length = sizeof(RT_802_11_STA_CONFIG);
4497 Status = copy_to_user(wrq->u.data.pointer, pStaConfig, wrq->u.data.length);
4502 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
4506 case OID_802_11_RTS_THRESHOLD:
4507 RtsThresh = pAdapter->CommonCfg.RtsThreshold;
4508 wrq->u.data.length = sizeof(RtsThresh);
4509 Status = copy_to_user(wrq->u.data.pointer, &RtsThresh, wrq->u.data.length);
4510 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RTS_THRESHOLD(=%ld)\n", RtsThresh));
4512 case OID_802_11_FRAGMENTATION_THRESHOLD:
4513 FragThresh = pAdapter->CommonCfg.FragmentThreshold;
4514 if (pAdapter->CommonCfg.bUseZeroToDisableFragment == TRUE)
4516 wrq->u.data.length = sizeof(FragThresh);
4517 Status = copy_to_user(wrq->u.data.pointer, &FragThresh, wrq->u.data.length);
4518 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_FRAGMENTATION_THRESHOLD(=%ld)\n", FragThresh));
4520 case OID_802_11_POWER_MODE:
4521 PowerMode = pAdapter->StaCfg.WindowsPowerMode;
4522 wrq->u.data.length = sizeof(PowerMode);
4523 Status = copy_to_user(wrq->u.data.pointer, &PowerMode, wrq->u.data.length);
4524 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_POWER_MODE(=%d)\n", PowerMode));
4526 case RT_OID_802_11_RADIO:
4527 RadioState = (BOOLEAN) pAdapter->StaCfg.bSwRadio;
4528 wrq->u.data.length = sizeof(RadioState);
4529 Status = copy_to_user(wrq->u.data.pointer, &RadioState, wrq->u.data.length);
4530 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_RADIO (=%d)\n", RadioState));
4532 case OID_802_11_INFRASTRUCTURE_MODE:
4533 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
4534 BssType = Ndis802_11IBSS;
4535 else if (pAdapter->StaCfg.BssType == BSS_INFRA)
4536 BssType = Ndis802_11Infrastructure;
4537 else if (pAdapter->StaCfg.BssType == BSS_MONITOR)
4538 BssType = Ndis802_11Monitor;
4540 BssType = Ndis802_11AutoUnknown;
4542 wrq->u.data.length = sizeof(BssType);
4543 Status = copy_to_user(wrq->u.data.pointer, &BssType, wrq->u.data.length);
4544 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_INFRASTRUCTURE_MODE(=%d)\n", BssType));
4546 case RT_OID_802_11_PREAMBLE:
4547 PreamType = pAdapter->CommonCfg.TxPreamble;
4548 wrq->u.data.length = sizeof(PreamType);
4549 Status = copy_to_user(wrq->u.data.pointer, &PreamType, wrq->u.data.length);
4550 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PREAMBLE(=%d)\n", PreamType));
4552 case OID_802_11_AUTHENTICATION_MODE:
4553 AuthMode = pAdapter->StaCfg.AuthMode;
4554 wrq->u.data.length = sizeof(AuthMode);
4555 Status = copy_to_user(wrq->u.data.pointer, &AuthMode, wrq->u.data.length);
4556 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_AUTHENTICATION_MODE(=%d)\n", AuthMode));
4558 case OID_802_11_WEP_STATUS:
4559 WepStatus = pAdapter->StaCfg.WepStatus;
4560 wrq->u.data.length = sizeof(WepStatus);
4561 Status = copy_to_user(wrq->u.data.pointer, &WepStatus, wrq->u.data.length);
4562 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_WEP_STATUS(=%d)\n", WepStatus));
4564 case OID_802_11_TX_POWER_LEVEL:
4565 wrq->u.data.length = sizeof(ULONG);
4566 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPower, wrq->u.data.length);
4567 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_TX_POWER_LEVEL %x\n",pAdapter->CommonCfg.TxPower));
4569 case RT_OID_802_11_TX_POWER_LEVEL_1:
4570 wrq->u.data.length = sizeof(ULONG);
4571 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPowerPercentage, wrq->u.data.length);
4572 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
4574 case OID_802_11_NETWORK_TYPES_SUPPORTED:
4575 if ((pAdapter->RfIcType == RFIC_2850) || (pAdapter->RfIcType == RFIC_2750))
4577 NetworkTypeList[0] = 3; // NumberOfItems = 3
4578 NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
4579 NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
4580 NetworkTypeList[3] = Ndis802_11OFDM5; // NetworkType[3] = 11a
4581 wrq->u.data.length = 16;
4582 Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
4586 NetworkTypeList[0] = 2; // NumberOfItems = 2
4587 NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
4588 NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
4589 wrq->u.data.length = 12;
4590 Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
4592 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_NETWORK_TYPES_SUPPORTED\n"));
4594 case OID_802_11_NETWORK_TYPE_IN_USE:
4595 wrq->u.data.length = sizeof(ULONG);
4596 if (pAdapter->CommonCfg.PhyMode == PHY_11A)
4597 ulInfo = Ndis802_11OFDM5;
4598 else if ((pAdapter->CommonCfg.PhyMode == PHY_11BG_MIXED) || (pAdapter->CommonCfg.PhyMode == PHY_11G))
4599 ulInfo = Ndis802_11OFDM24;
4601 ulInfo = Ndis802_11DS;
4602 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4604 case RT_OID_802_11_QUERY_LAST_RX_RATE:
4605 ulInfo = (ULONG)pAdapter->LastRxRate;
4606 wrq->u.data.length = sizeof(ulInfo);
4607 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4608 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_RX_RATE (=%ld)\n", ulInfo));
4610 case RT_OID_802_11_QUERY_LAST_TX_RATE:
4611 //ulInfo = (ULONG)pAdapter->LastTxRate;
4612 ulInfo = (ULONG)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word;
4613 wrq->u.data.length = sizeof(ulInfo);
4614 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4615 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_TX_RATE (=%lx)\n", ulInfo));
4617 case RT_OID_802_11_QUERY_EEPROM_VERSION:
4618 wrq->u.data.length = sizeof(ULONG);
4619 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->EepromVersion, wrq->u.data.length);
4621 case RT_OID_802_11_QUERY_FIRMWARE_VERSION:
4622 wrq->u.data.length = sizeof(ULONG);
4623 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->FirmwareVersion, wrq->u.data.length);
4625 case RT_OID_802_11_QUERY_NOISE_LEVEL:
4626 wrq->u.data.length = sizeof(UCHAR);
4627 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->BbpWriteLatch[66], wrq->u.data.length);
4628 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_NOISE_LEVEL (=%d)\n", pAdapter->BbpWriteLatch[66]));
4630 case RT_OID_802_11_EXTRA_INFO:
4631 wrq->u.data.length = sizeof(ULONG);
4632 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->ExtraInfo, wrq->u.data.length);
4633 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_EXTRA_INFO (=%ld)\n", pAdapter->ExtraInfo));
4635 case RT_OID_WE_VERSION_COMPILED:
4636 wrq->u.data.length = sizeof(UINT);
4637 we_version_compiled = WIRELESS_EXT;
4638 Status = copy_to_user(wrq->u.data.pointer, &we_version_compiled, wrq->u.data.length);
4640 case RT_OID_802_11_QUERY_APSD_SETTING:
4641 apsd = (pAdapter->CommonCfg.bAPSDCapable | (pAdapter->CommonCfg.bAPSDAC_BE << 1) | (pAdapter->CommonCfg.bAPSDAC_BK << 2)
4642 | (pAdapter->CommonCfg.bAPSDAC_VI << 3) | (pAdapter->CommonCfg.bAPSDAC_VO << 4) | (pAdapter->CommonCfg.MaxSPLength << 5));
4644 wrq->u.data.length = sizeof(ULONG);
4645 Status = copy_to_user(wrq->u.data.pointer, &apsd, wrq->u.data.length);
4646 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",
4647 apsd,pAdapter->CommonCfg.bAPSDCapable,pAdapter->CommonCfg.bAPSDAC_BE,pAdapter->CommonCfg.bAPSDAC_BK,pAdapter->CommonCfg.bAPSDAC_VI,pAdapter->CommonCfg.bAPSDAC_VO,pAdapter->CommonCfg.MaxSPLength));
4649 case RT_OID_802_11_QUERY_APSD_PSM:
4650 wrq->u.data.length = sizeof(ULONG);
4651 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.length);
4652 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_APSD_PSM (=%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
4654 case RT_OID_802_11_QUERY_WMM:
4655 wrq->u.data.length = sizeof(BOOLEAN);
4656 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bWmmCapable, wrq->u.data.length);
4657 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_WMM (=%d)\n", pAdapter->CommonCfg.bWmmCapable));
4659 case RT_OID_NEW_DRIVER:
4662 wrq->u.data.length = sizeof(UCHAR);
4663 Status = copy_to_user(wrq->u.data.pointer, &enabled, wrq->u.data.length);
4664 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_NEW_DRIVER (=%d)\n", enabled));
4667 case RT_OID_WPA_SUPPLICANT_SUPPORT:
4668 wrq->u.data.length = sizeof(UCHAR);
4669 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->StaCfg.WpaSupplicantUP, wrq->u.data.length);
4670 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
4672 case RT_OID_DRIVER_DEVICE_NAME:
4673 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_DRIVER_DEVICE_NAME \n"));
4674 wrq->u.data.length = 16;
4675 if (copy_to_user(wrq->u.data.pointer, pAdapter->StaCfg.dev_name, wrq->u.data.length))
4680 case RT_OID_802_11_QUERY_HT_PHYMODE:
4681 pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
4684 pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
4685 pHTPhyMode->HtMode = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE;
4686 pHTPhyMode->BW = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.BW;
4687 pHTPhyMode->MCS= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MCS;
4688 pHTPhyMode->SHORTGI= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.ShortGI;
4689 pHTPhyMode->STBC= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.STBC;
4691 pHTPhyMode->ExtOffset = ((pAdapter->CommonCfg.CentralChannel < pAdapter->CommonCfg.Channel) ? (EXTCHA_BELOW) : (EXTCHA_ABOVE));
4692 wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
4693 if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
4697 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
4698 pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
4699 DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
4703 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
4707 case RT_OID_802_11_COUNTRY_REGION:
4708 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_COUNTRY_REGION \n"));
4709 wrq->u.data.length = sizeof(ulInfo);
4710 ulInfo = pAdapter->CommonCfg.CountryRegionForABand;
4711 ulInfo = (ulInfo << 8)|(pAdapter->CommonCfg.CountryRegion);
4712 if (copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length))
4717 case RT_OID_802_11_QUERY_DAT_HT_PHYMODE:
4718 pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
4721 pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
4722 pHTPhyMode->HtMode = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.HTMODE;
4723 pHTPhyMode->BW = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.BW;
4724 pHTPhyMode->MCS= (UCHAR)pAdapter->StaCfg.DesiredTransmitSetting.field.MCS;
4725 pHTPhyMode->SHORTGI= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.ShortGI;
4726 pHTPhyMode->STBC= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.STBC;
4728 wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
4729 if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
4733 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
4734 pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
4735 DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
4739 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
4743 case RT_OID_QUERY_MULTIPLE_CARD_SUPPORT:
4744 wrq->u.data.length = sizeof(UCHAR);
4746 if (copy_to_user(wrq->u.data.pointer, &i, wrq->u.data.length))
4750 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_QUERY_MULTIPLE_CARD_SUPPORT(=%d) \n", i));
4753 case OID_802_11_BUILD_CHANNEL_EX:
4756 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BUILD_CHANNEL_EX \n"));
4757 wrq->u.data.length = sizeof(UCHAR);
4758 DBGPRINT(RT_DEBUG_TRACE, ("Doesn't support EXT_BUILD_CHANNEL_LIST.\n"));
4760 Status = copy_to_user(wrq->u.data.pointer, &value, 1);
4761 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
4765 case OID_802_11_GET_CH_LIST:
4767 PRT_CHANNEL_LIST_INFO pChListBuf;
4769 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CH_LIST \n"));
4770 if (pAdapter->ChannelListNum == 0)
4772 wrq->u.data.length = 0;
4776 pChListBuf = (RT_CHANNEL_LIST_INFO *) kmalloc(sizeof(RT_CHANNEL_LIST_INFO), MEM_ALLOC_FLAG);
4777 if (pChListBuf == NULL)
4779 wrq->u.data.length = 0;
4783 pChListBuf->ChannelListNum = pAdapter->ChannelListNum;
4784 for (i = 0; i < pChListBuf->ChannelListNum; i++)
4785 pChListBuf->ChannelList[i] = pAdapter->ChannelList[i].Channel;
4787 wrq->u.data.length = sizeof(RT_CHANNEL_LIST_INFO);
4788 Status = copy_to_user(wrq->u.data.pointer, pChListBuf, sizeof(RT_CHANNEL_LIST_INFO));
4789 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
4796 case OID_802_11_GET_COUNTRY_CODE:
4797 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_COUNTRY_CODE \n"));
4798 wrq->u.data.length = 2;
4799 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.CountryCode, 2);
4800 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
4803 case OID_802_11_GET_CHANNEL_GEOGRAPHY:
4804 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CHANNEL_GEOGRAPHY \n"));
4805 wrq->u.data.length = 1;
4806 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Geography, 1);
4807 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
4811 DBGPRINT(RT_DEBUG_TRACE, ("Query::unknown IOCTL's subcmd = 0x%08x\n", cmd));
4812 Status = -EOPNOTSUPP;
4818 INT rt28xx_sta_ioctl(
4819 IN struct net_device *net_dev,
4820 IN OUT struct ifreq *rq,
4824 VIRTUAL_ADAPTER *pVirtualAd = NULL;
4825 RTMP_ADAPTER *pAd = NULL;
4826 struct iwreq *wrq = (struct iwreq *) rq;
4827 BOOLEAN StateMachineTouched = FALSE;
4828 INT Status = NDIS_STATUS_SUCCESS;
4831 if (net_dev->priv_flags == INT_MAIN)
4833 pAd = net_dev->ml_priv;
4837 pVirtualAd = net_dev->ml_priv;
4838 pAd = pVirtualAd->RtmpDev->ml_priv;
4840 pObj = (POS_COOKIE) pAd->OS_Cookie;
4844 /* if 1st open fail, pAd will be free;
4845 So the net_dev->ml_priv will be NULL in 2rd open */
4849 //check if the interface is down
4850 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
4853 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
4858 { // determine this ioctl command is comming from which interface.
4859 pObj->ioctl_if_type = INT_MAIN;
4860 pObj->ioctl_if = MAIN_MBSSID;
4866 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIFHWADDR\n"));
4867 memcpy(wrq->u.name, pAd->CurrentAddress, ETH_ALEN);
4871 char *name=&wrq->u.name[0];
4872 rt_ioctl_giwname(net_dev, NULL, name, NULL);
4875 case SIOCGIWESSID: //Get ESSID
4877 struct iw_point *essid=&wrq->u.essid;
4878 rt_ioctl_giwessid(net_dev, NULL, essid, essid->pointer);
4881 case SIOCSIWESSID: //Set ESSID
4883 struct iw_point *essid=&wrq->u.essid;
4884 rt_ioctl_siwessid(net_dev, NULL, essid, essid->pointer);
4887 case SIOCSIWNWID: // set network id (the cell)
4888 case SIOCGIWNWID: // get network id
4889 Status = -EOPNOTSUPP;
4891 case SIOCSIWFREQ: //set channel/frequency (Hz)
4893 struct iw_freq *freq=&wrq->u.freq;
4894 rt_ioctl_siwfreq(net_dev, NULL, freq, NULL);
4897 case SIOCGIWFREQ: // get channel/frequency (Hz)
4899 struct iw_freq *freq=&wrq->u.freq;
4900 rt_ioctl_giwfreq(net_dev, NULL, freq, NULL);
4903 case SIOCSIWNICKN: //set node name/nickname
4905 struct iw_point *data=&wrq->u.data;
4906 rt_ioctl_siwnickn(net_dev, NULL, data, NULL);
4909 case SIOCGIWNICKN: //get node name/nickname
4911 struct iw_point *data=&wrq->u.data;
4912 rt_ioctl_giwnickn(net_dev, NULL, data, NULL);
4915 case SIOCGIWRATE: //get default bit rate (bps)
4916 rt_ioctl_giwrate(net_dev, NULL, &wrq->u, NULL);
4918 case SIOCSIWRATE: //set default bit rate (bps)
4919 rt_ioctl_siwrate(net_dev, NULL, &wrq->u, NULL);
4921 case SIOCGIWRTS: // get RTS/CTS threshold (bytes)
4923 struct iw_param *rts=&wrq->u.rts;
4924 rt_ioctl_giwrts(net_dev, NULL, rts, NULL);
4927 case SIOCSIWRTS: //set RTS/CTS threshold (bytes)
4929 struct iw_param *rts=&wrq->u.rts;
4930 rt_ioctl_siwrts(net_dev, NULL, rts, NULL);
4933 case SIOCGIWFRAG: //get fragmentation thr (bytes)
4935 struct iw_param *frag=&wrq->u.frag;
4936 rt_ioctl_giwfrag(net_dev, NULL, frag, NULL);
4939 case SIOCSIWFRAG: //set fragmentation thr (bytes)
4941 struct iw_param *frag=&wrq->u.frag;
4942 rt_ioctl_siwfrag(net_dev, NULL, frag, NULL);
4945 case SIOCGIWENCODE: //get encoding token & mode
4947 struct iw_point *erq=&wrq->u.encoding;
4949 rt_ioctl_giwencode(net_dev, NULL, erq, erq->pointer);
4952 case SIOCSIWENCODE: //set encoding token & mode
4954 struct iw_point *erq=&wrq->u.encoding;
4956 rt_ioctl_siwencode(net_dev, NULL, erq, erq->pointer);
4959 case SIOCGIWAP: //get access point MAC addresses
4961 struct sockaddr *ap_addr=&wrq->u.ap_addr;
4962 rt_ioctl_giwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
4965 case SIOCSIWAP: //set access point MAC addresses
4967 struct sockaddr *ap_addr=&wrq->u.ap_addr;
4968 rt_ioctl_siwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
4971 case SIOCGIWMODE: //get operation mode
4973 __u32 *mode=&wrq->u.mode;
4974 rt_ioctl_giwmode(net_dev, NULL, mode, NULL);
4977 case SIOCSIWMODE: //set operation mode
4979 __u32 *mode=&wrq->u.mode;
4980 rt_ioctl_siwmode(net_dev, NULL, mode, NULL);
4983 case SIOCGIWSENS: //get sensitivity (dBm)
4984 case SIOCSIWSENS: //set sensitivity (dBm)
4985 case SIOCGIWPOWER: //get Power Management settings
4986 case SIOCSIWPOWER: //set Power Management settings
4987 case SIOCGIWTXPOW: //get transmit power (dBm)
4988 case SIOCSIWTXPOW: //set transmit power (dBm)
4989 case SIOCGIWRANGE: //Get range of parameters
4990 case SIOCGIWRETRY: //get retry limits and lifetime
4991 case SIOCSIWRETRY: //set retry limits and lifetime
4992 Status = -EOPNOTSUPP;
4995 case RT_PRIV_IOCTL_EXT:
4996 subcmd = wrq->u.data.flags;
4997 if( subcmd & OID_GET_SET_TOGGLE)
4998 Status = RTMPSetInformation(pAd, rq, subcmd);
5000 Status = RTMPQueryInformation(pAd, rq, subcmd);
5003 if (wrq->u.data.pointer)
5005 if ( access_ok(VERIFY_WRITE, wrq->u.data.pointer, sizeof(privtab)) != TRUE)
5007 wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
5008 if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
5012 case RTPRIV_IOCTL_SET:
5013 if(access_ok(VERIFY_READ, wrq->u.data.pointer, wrq->u.data.length) != TRUE)
5015 rt_ioctl_setparam(net_dev, NULL, NULL, wrq->u.data.pointer);
5017 case RTPRIV_IOCTL_GSITESURVEY:
5018 RTMPIoctlGetSiteSurvey(pAd, wrq);
5021 case RTPRIV_IOCTL_MAC:
5022 RTMPIoctlMAC(pAd, wrq);
5024 case RTPRIV_IOCTL_E2P:
5025 RTMPIoctlE2PROM(pAd, wrq);
5028 case RTPRIV_IOCTL_RF:
5029 RTMPIoctlRF(pAd, wrq);
5036 DBGPRINT(RT_DEBUG_ERROR, ("IOCTL::unknown IOCTL's cmd = 0x%08x\n", cmd));
5037 Status = -EOPNOTSUPP;
5041 if(StateMachineTouched) // Upper layer sent a MLME-related operations
5042 RT28XX_MLME_HANDLER(pAd);
5048 ==========================================================================
5052 TRUE if all parameters are OK, FALSE otherwise
5053 ==========================================================================
5056 IN PRTMP_ADAPTER pAdapter,
5059 NDIS_802_11_SSID Ssid, *pSsid=NULL;
5060 BOOLEAN StateMachineTouched = FALSE;
5063 if( strlen(arg) <= MAX_LEN_OF_SSID)
5065 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
5066 if (strlen(arg) != 0)
5068 NdisMoveMemory(Ssid.Ssid, arg, strlen(arg));
5069 Ssid.SsidLength = strlen(arg);
5073 Ssid.SsidLength = 0;
5074 memcpy(Ssid.Ssid, "", 0);
5075 pAdapter->StaCfg.BssType = BSS_INFRA;
5076 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
5077 pAdapter->StaCfg.WepStatus = Ndis802_11EncryptionDisabled;
5081 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
5083 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
5084 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
5087 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
5088 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
5089 pAdapter->bConfigChanged = TRUE;
5091 MlmeEnqueue(pAdapter,
5092 MLME_CNTL_STATE_MACHINE,
5094 sizeof(NDIS_802_11_SSID),
5097 StateMachineTouched = TRUE;
5098 DBGPRINT(RT_DEBUG_TRACE, ("Set_SSID_Proc::(Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
5103 if (StateMachineTouched) // Upper layer sent a MLME-related operations
5104 RT28XX_MLME_HANDLER(pAdapter);
5111 ==========================================================================
5113 Set WmmCapable Enable or Disable
5115 TRUE if all parameters are OK, FALSE otherwise
5116 ==========================================================================
5118 INT Set_WmmCapable_Proc(
5119 IN PRTMP_ADAPTER pAd,
5122 BOOLEAN bWmmCapable;
5124 bWmmCapable = simple_strtol(arg, 0, 10);
5126 if ((bWmmCapable == 1)
5128 && (pAd->NumberOfPipes >= 5)
5131 pAd->CommonCfg.bWmmCapable = TRUE;
5132 else if (bWmmCapable == 0)
5133 pAd->CommonCfg.bWmmCapable = FALSE;
5135 return FALSE; //Invalid argument
5137 DBGPRINT(RT_DEBUG_TRACE, ("Set_WmmCapable_Proc::(bWmmCapable=%d)\n",
5138 pAd->CommonCfg.bWmmCapable));
5142 #endif // WMM_SUPPORT //
5145 ==========================================================================
5147 Set Network Type(Infrastructure/Adhoc mode)
5149 TRUE if all parameters are OK, FALSE otherwise
5150 ==========================================================================
5152 INT Set_NetworkType_Proc(
5153 IN PRTMP_ADAPTER pAdapter,
5158 if (strcmp(arg, "Adhoc") == 0)
5160 if (pAdapter->StaCfg.BssType != BSS_ADHOC)
5162 // Config has changed
5163 pAdapter->bConfigChanged = TRUE;
5164 if (MONITOR_ON(pAdapter))
5166 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
5167 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5169 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5170 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5171 pAdapter->StaCfg.bAutoReconnect = TRUE;
5172 LinkDown(pAdapter, FALSE);
5174 if (INFRA_ON(pAdapter))
5176 //BOOLEAN Cancelled;
5177 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
5178 // Since calling this indicate user don't want to connect to that SSID anymore.
5179 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
5180 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
5182 LinkDown(pAdapter, FALSE);
5184 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n"));
5187 pAdapter->StaCfg.BssType = BSS_ADHOC;
5188 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
5189 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(AD-HOC)\n"));
5191 else if (strcmp(arg, "Infra") == 0)
5193 if (pAdapter->StaCfg.BssType != BSS_INFRA)
5195 // Config has changed
5196 pAdapter->bConfigChanged = TRUE;
5197 if (MONITOR_ON(pAdapter))
5199 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
5200 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5202 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5203 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5204 pAdapter->StaCfg.bAutoReconnect = TRUE;
5205 LinkDown(pAdapter, FALSE);
5207 if (ADHOC_ON(pAdapter))
5209 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
5210 // Since calling this indicate user don't want to connect to that SSID anymore.
5211 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
5212 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
5214 LinkDown(pAdapter, FALSE);
5217 pAdapter->StaCfg.BssType = BSS_INFRA;
5218 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
5219 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(INFRA)\n"));
5221 pAdapter->StaCfg.BssType = BSS_INFRA;
5223 else if (strcmp(arg, "Monitor") == 0)
5226 BCN_TIME_CFG_STRUC csr;
5227 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_INFRA_ON);
5228 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_ADHOC_ON);
5229 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5230 // disable all periodic state machine
5231 pAdapter->StaCfg.bAutoReconnect = FALSE;
5232 // reset all mlme state machine
5233 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
5234 DBGPRINT(RT_DEBUG_TRACE, ("fOP_STATUS_MEDIA_STATE_CONNECTED \n"));
5235 if (pAdapter->CommonCfg.CentralChannel == 0)
5237 if (pAdapter->CommonCfg.PhyMode == PHY_11AN_MIXED)
5238 pAdapter->CommonCfg.CentralChannel = 36;
5240 pAdapter->CommonCfg.CentralChannel = 6;
5243 N_ChannelCheck(pAdapter);
5245 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
5246 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
5247 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_ABOVE)
5249 // 40MHz ,control channel at lower
5250 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5251 bbpValue &= (~0x18);
5253 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5254 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
5255 // RX : control channel at lower
5256 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
5257 bbpValue &= (~0x20);
5258 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
5260 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
5261 Value &= 0xfffffffe;
5262 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
5263 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel + 2;
5264 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
5265 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
5266 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
5267 pAdapter->CommonCfg.Channel,
5268 pAdapter->CommonCfg.CentralChannel));
5270 else if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
5271 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
5272 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_BELOW)
5274 // 40MHz ,control channel at upper
5275 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5276 bbpValue &= (~0x18);
5278 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5279 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
5280 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
5282 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
5284 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
5286 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
5287 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel - 2;
5288 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
5289 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
5290 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
5291 pAdapter->CommonCfg.Channel,
5292 pAdapter->CommonCfg.CentralChannel));
5297 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5298 bbpValue &= (~0x18);
5299 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5300 pAdapter->CommonCfg.BBPCurrentBW = BW_20;
5301 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.Channel, FALSE);
5302 AsicLockChannel(pAdapter, pAdapter->CommonCfg.Channel);
5303 DBGPRINT(RT_DEBUG_TRACE, ("BW_20, Channel(%d)\n", pAdapter->CommonCfg.Channel));
5305 // Enable Rx with promiscuous reception
5306 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, 0x3);
5307 // ASIC supporsts sniffer function with replacing RSSI with timestamp.
5308 //RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5310 //RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5312 RTMP_IO_READ32(pAdapter, BCN_TIME_CFG, &csr.word);
5313 csr.field.bBeaconGen = 0;
5314 csr.field.bTBTTEnable = 0;
5315 csr.field.TsfSyncMode = 0;
5316 RTMP_IO_WRITE32(pAdapter, BCN_TIME_CFG, csr.word);
5318 pAdapter->StaCfg.BssType = BSS_MONITOR;
5319 pAdapter->net_dev->type = ARPHRD_IEEE80211_PRISM; //ARPHRD_IEEE80211; // IEEE80211
5320 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(MONITOR)\n"));
5323 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
5324 pAdapter->StaCfg.WpaState = SS_NOTUSE;
5326 DBGPRINT(RT_DEBUG_TRACE, ("Set_NetworkType_Proc::(NetworkType=%d)\n", pAdapter->StaCfg.BssType));
5332 ==========================================================================
5334 Set Authentication mode
5336 TRUE if all parameters are OK, FALSE otherwise
5337 ==========================================================================
5339 INT Set_AuthMode_Proc(
5340 IN PRTMP_ADAPTER pAdapter,
5343 if ((strcmp(arg, "WEPAUTO") == 0) || (strcmp(arg, "wepauto") == 0))
5344 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeAutoSwitch;
5345 else if ((strcmp(arg, "OPEN") == 0) || (strcmp(arg, "open") == 0))
5346 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
5347 else if ((strcmp(arg, "SHARED") == 0) || (strcmp(arg, "shared") == 0))
5348 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
5349 else if ((strcmp(arg, "WPAPSK") == 0) || (strcmp(arg, "wpapsk") == 0))
5350 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
5351 else if ((strcmp(arg, "WPANONE") == 0) || (strcmp(arg, "wpanone") == 0))
5352 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
5353 else if ((strcmp(arg, "WPA2PSK") == 0) || (strcmp(arg, "wpa2psk") == 0))
5354 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
5355 else if ((strcmp(arg, "WPA") == 0) || (strcmp(arg, "wpa") == 0))
5356 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
5357 else if ((strcmp(arg, "WPA2") == 0) || (strcmp(arg, "wpa2") == 0))
5358 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
5362 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
5364 DBGPRINT(RT_DEBUG_TRACE, ("Set_AuthMode_Proc::(AuthMode=%d)\n", pAdapter->StaCfg.AuthMode));
5370 ==========================================================================
5374 TRUE if all parameters are OK, FALSE otherwise
5375 ==========================================================================
5377 INT Set_EncrypType_Proc(
5378 IN PRTMP_ADAPTER pAdapter,
5381 if ((strcmp(arg, "NONE") == 0) || (strcmp(arg, "none") == 0))
5383 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5384 return TRUE; // do nothing
5386 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
5387 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
5388 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
5390 else if ((strcmp(arg, "WEP") == 0) || (strcmp(arg, "wep") == 0))
5392 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5393 return TRUE; // do nothing
5395 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
5396 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
5397 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
5399 else if ((strcmp(arg, "TKIP") == 0) || (strcmp(arg, "tkip") == 0))
5401 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
5402 return TRUE; // do nothing
5404 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
5405 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
5406 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
5408 else if ((strcmp(arg, "AES") == 0) || (strcmp(arg, "aes") == 0))
5410 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
5411 return TRUE; // do nothing
5413 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
5414 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
5415 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
5420 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
5422 DBGPRINT(RT_DEBUG_TRACE, ("Set_EncrypType_Proc::(EncrypType=%d)\n", pAdapter->StaCfg.WepStatus));
5428 ==========================================================================
5432 TRUE if all parameters are OK, FALSE otherwise
5433 ==========================================================================
5435 INT Set_DefaultKeyID_Proc(
5436 IN PRTMP_ADAPTER pAdapter,
5441 KeyIdx = simple_strtol(arg, 0, 10);
5442 if((KeyIdx >= 1 ) && (KeyIdx <= 4))
5443 pAdapter->StaCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1 );
5445 return FALSE; //Invalid argument
5447 DBGPRINT(RT_DEBUG_TRACE, ("Set_DefaultKeyID_Proc::(DefaultKeyID=%d)\n", pAdapter->StaCfg.DefaultKeyId));
5453 ==========================================================================
5457 TRUE if all parameters are OK, FALSE otherwise
5458 ==========================================================================
5461 IN PRTMP_ADAPTER pAdapter,
5466 UCHAR CipherAlg=CIPHER_WEP64;
5468 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5469 return TRUE; // do nothing
5471 KeyLen = strlen(arg);
5475 case 5: //wep 40 Ascii type
5476 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
5477 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
5478 CipherAlg = CIPHER_WEP64;
5479 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
5481 case 10: //wep 40 Hex type
5482 for(i=0; i < KeyLen; i++)
5484 if( !isxdigit(*(arg+i)) )
5485 return FALSE; //Not Hex value;
5487 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
5488 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
5489 CipherAlg = CIPHER_WEP64;
5490 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
5492 case 13: //wep 104 Ascii type
5493 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
5494 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
5495 CipherAlg = CIPHER_WEP128;
5496 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
5498 case 26: //wep 104 Hex type
5499 for(i=0; i < KeyLen; i++)
5501 if( !isxdigit(*(arg+i)) )
5502 return FALSE; //Not Hex value;
5504 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
5505 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
5506 CipherAlg = CIPHER_WEP128;
5507 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
5509 default: //Invalid argument
5510 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::Invalid argument (=%s)\n", arg));
5514 pAdapter->SharedKey[BSS0][0].CipherAlg = CipherAlg;
5516 // Set keys (into ASIC)
5517 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5519 else // Old WEP stuff
5521 AsicAddSharedKeyEntry(pAdapter,
5524 pAdapter->SharedKey[BSS0][0].CipherAlg,
5525 pAdapter->SharedKey[BSS0][0].Key,
5533 ==========================================================================
5538 TRUE if all parameters are OK, FALSE otherwise
5539 ==========================================================================
5542 IN PRTMP_ADAPTER pAdapter,
5547 UCHAR CipherAlg=CIPHER_WEP64;
5549 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5550 return TRUE; // do nothing
5552 KeyLen = strlen(arg);
5556 case 5: //wep 40 Ascii type
5557 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
5558 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
5559 CipherAlg = CIPHER_WEP64;
5560 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
5562 case 10: //wep 40 Hex type
5563 for(i=0; i < KeyLen; i++)
5565 if( !isxdigit(*(arg+i)) )
5566 return FALSE; //Not Hex value;
5568 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
5569 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
5570 CipherAlg = CIPHER_WEP64;
5571 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
5573 case 13: //wep 104 Ascii type
5574 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
5575 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
5576 CipherAlg = CIPHER_WEP128;
5577 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
5579 case 26: //wep 104 Hex type
5580 for(i=0; i < KeyLen; i++)
5582 if( !isxdigit(*(arg+i)) )
5583 return FALSE; //Not Hex value;
5585 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
5586 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
5587 CipherAlg = CIPHER_WEP128;
5588 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
5590 default: //Invalid argument
5591 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::Invalid argument (=%s)\n", arg));
5594 pAdapter->SharedKey[BSS0][1].CipherAlg = CipherAlg;
5596 // Set keys (into ASIC)
5597 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5599 else // Old WEP stuff
5601 AsicAddSharedKeyEntry(pAdapter,
5604 pAdapter->SharedKey[BSS0][1].CipherAlg,
5605 pAdapter->SharedKey[BSS0][1].Key,
5613 ==========================================================================
5617 TRUE if all parameters are OK, FALSE otherwise
5618 ==========================================================================
5621 IN PRTMP_ADAPTER pAdapter,
5626 UCHAR CipherAlg=CIPHER_WEP64;
5628 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5629 return TRUE; // do nothing
5631 KeyLen = strlen(arg);
5635 case 5: //wep 40 Ascii type
5636 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
5637 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
5638 CipherAlg = CIPHER_WEP64;
5639 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
5641 case 10: //wep 40 Hex type
5642 for(i=0; i < KeyLen; i++)
5644 if( !isxdigit(*(arg+i)) )
5645 return FALSE; //Not Hex value;
5647 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
5648 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
5649 CipherAlg = CIPHER_WEP64;
5650 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
5652 case 13: //wep 104 Ascii type
5653 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
5654 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
5655 CipherAlg = CIPHER_WEP128;
5656 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
5658 case 26: //wep 104 Hex type
5659 for(i=0; i < KeyLen; i++)
5661 if( !isxdigit(*(arg+i)) )
5662 return FALSE; //Not Hex value;
5664 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
5665 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
5666 CipherAlg = CIPHER_WEP128;
5667 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
5669 default: //Invalid argument
5670 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::Invalid argument (=%s)\n", arg));
5673 pAdapter->SharedKey[BSS0][2].CipherAlg = CipherAlg;
5675 // Set keys (into ASIC)
5676 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5678 else // Old WEP stuff
5680 AsicAddSharedKeyEntry(pAdapter,
5683 pAdapter->SharedKey[BSS0][2].CipherAlg,
5684 pAdapter->SharedKey[BSS0][2].Key,
5692 ==========================================================================
5696 TRUE if all parameters are OK, FALSE otherwise
5697 ==========================================================================
5700 IN PRTMP_ADAPTER pAdapter,
5705 UCHAR CipherAlg=CIPHER_WEP64;
5707 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5708 return TRUE; // do nothing
5710 KeyLen = strlen(arg);
5714 case 5: //wep 40 Ascii type
5715 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
5716 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
5717 CipherAlg = CIPHER_WEP64;
5718 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
5720 case 10: //wep 40 Hex type
5721 for(i=0; i < KeyLen; i++)
5723 if( !isxdigit(*(arg+i)) )
5724 return FALSE; //Not Hex value;
5726 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
5727 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
5728 CipherAlg = CIPHER_WEP64;
5729 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
5731 case 13: //wep 104 Ascii type
5732 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
5733 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
5734 CipherAlg = CIPHER_WEP128;
5735 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
5737 case 26: //wep 104 Hex type
5738 for(i=0; i < KeyLen; i++)
5740 if( !isxdigit(*(arg+i)) )
5741 return FALSE; //Not Hex value;
5743 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
5744 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
5745 CipherAlg = CIPHER_WEP128;
5746 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
5748 default: //Invalid argument
5749 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::Invalid argument (=%s)\n", arg));
5752 pAdapter->SharedKey[BSS0][3].CipherAlg = CipherAlg;
5754 // Set keys (into ASIC)
5755 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5757 else // Old WEP stuff
5759 AsicAddSharedKeyEntry(pAdapter,
5762 pAdapter->SharedKey[BSS0][3].CipherAlg,
5763 pAdapter->SharedKey[BSS0][3].Key,
5772 ==========================================================================
5776 TRUE if all parameters are OK, FALSE otherwise
5777 ==========================================================================
5779 INT Set_WPAPSK_Proc(
5780 IN PRTMP_ADAPTER pAdapter,
5783 UCHAR keyMaterial[40];
5785 if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
5786 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
5787 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
5789 return TRUE; // do nothing
5791 DBGPRINT(RT_DEBUG_TRACE, ("Set_WPAPSK_Proc::(WPAPSK=%s)\n", arg));
5793 NdisZeroMemory(keyMaterial, 40);
5795 if ((strlen(arg) < 8) || (strlen(arg) > 64))
5797 DBGPRINT(RT_DEBUG_TRACE, ("Set failed!!(WPAPSK=%s), WPAPSK key-string required 8 ~ 64 characters \n", arg));
5801 if (strlen(arg) == 64)
5803 AtoH(arg, keyMaterial, 32);
5804 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
5809 PasswordHash((char *)arg, pAdapter->MlmeAux.Ssid, pAdapter->MlmeAux.SsidLen, keyMaterial);
5810 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
5815 if(pAdapter->StaCfg.BssType == BSS_ADHOC &&
5816 pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
5818 pAdapter->StaCfg.WpaState = SS_NOTUSE;
5822 // Start STA supplicant state machine
5823 pAdapter->StaCfg.WpaState = SS_START;
5830 ==========================================================================
5832 Set Power Saving mode
5834 TRUE if all parameters are OK, FALSE otherwise
5835 ==========================================================================
5837 INT Set_PSMode_Proc(
5838 IN PRTMP_ADAPTER pAdapter,
5841 if (pAdapter->StaCfg.BssType == BSS_INFRA)
5843 if ((strcmp(arg, "Max_PSP") == 0) ||
5844 (strcmp(arg, "max_psp") == 0) ||
5845 (strcmp(arg, "MAX_PSP") == 0))
5847 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
5848 // to exclude certain situations.
5849 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
5850 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeMAX_PSP;
5851 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeMAX_PSP;
5852 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
5853 pAdapter->StaCfg.DefaultListenCount = 5;
5856 else if ((strcmp(arg, "Fast_PSP") == 0) ||
5857 (strcmp(arg, "fast_psp") == 0) ||
5858 (strcmp(arg, "FAST_PSP") == 0))
5860 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
5861 // to exclude certain situations.
5862 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
5863 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
5864 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeFast_PSP;
5865 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeFast_PSP;
5866 pAdapter->StaCfg.DefaultListenCount = 3;
5868 else if ((strcmp(arg, "Legacy_PSP") == 0) ||
5869 (strcmp(arg, "legacy_psp") == 0) ||
5870 (strcmp(arg, "LEGACY_PSP") == 0))
5872 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
5873 // to exclude certain situations.
5874 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
5875 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
5876 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeLegacy_PSP;
5877 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeLegacy_PSP;
5878 pAdapter->StaCfg.DefaultListenCount = 3;
5882 //Default Ndis802_11PowerModeCAM
5883 // clear PSM bit immediately
5884 MlmeSetPsmBit(pAdapter, PWR_ACTIVE);
5885 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
5886 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
5887 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
5888 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
5891 DBGPRINT(RT_DEBUG_TRACE, ("Set_PSMode_Proc::(PSMode=%ld)\n", pAdapter->StaCfg.WindowsPowerMode));
5901 ==========================================================================
5903 Set WpaSupport flag.
5905 0: Driver ignore wpa_supplicant.
5906 1: wpa_supplicant initiates scanning and AP selection.
5907 2: driver takes care of scanning, AP selection, and IEEE 802.11 association parameters.
5909 TRUE if all parameters are OK, FALSE otherwise
5910 ==========================================================================
5912 INT Set_Wpa_Support(
5913 IN PRTMP_ADAPTER pAd,
5917 if ( simple_strtol(arg, 0, 10) == 0)
5918 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
5919 else if ( simple_strtol(arg, 0, 10) == 1)
5920 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE;
5921 else if ( simple_strtol(arg, 0, 10) == 2)
5922 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE_WITH_WEB_UI;
5924 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
5926 DBGPRINT(RT_DEBUG_TRACE, ("Set_Wpa_Support::(WpaSupplicantUP=%d)\n", pAd->StaCfg.WpaSupplicantUP));
5933 ==========================================================================
5937 pAdapter Pointer to our adapter
5938 wrq Pointer to the ioctl argument
5945 1.) iwpriv ra0 mac 0 ==> read MAC where Addr=0x0
5946 2.) iwpriv ra0 mac 0=12 ==> write MAC where Addr=0x0, value=12
5947 ==========================================================================
5950 IN PRTMP_ADAPTER pAdapter,
5951 IN struct iwreq *wrq)
5959 UCHAR temp[16], temp2[16];
5960 UINT32 macValue = 0;
5962 BOOLEAN bIsPrintAllMAC = FALSE;
5965 memset(msg, 0x00, 1024);
5966 if (wrq->u.data.length > 1) //No parameters.
5968 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
5971 //Parsing Read or Write
5976 if ((value = rtstrchr(this_char, '=')) != NULL)
5979 if (!value || !*value)
5982 if(strlen(this_char) > 4)
5985 j = strlen(this_char);
5988 if(this_char[j] > 'f' || this_char[j] < '0')
5993 k = j = strlen(this_char);
5996 this_char[4-k+j] = this_char[j];
6000 this_char[3-k++]='0';
6003 if(strlen(this_char) == 4)
6005 AtoH(this_char, temp, 2);
6006 macAddr = *temp*256 + temp[1];
6007 if (macAddr < 0xFFFF)
6009 RTMP_IO_READ32(pAdapter, macAddr, &macValue);
6010 DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%lx, MacValue=%x\n", macAddr, macValue));
6011 sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr , macValue);
6014 {//Invalid parametes, so default printk all mac
6015 bIsPrintAllMAC = TRUE;
6022 memcpy(&temp2, value, strlen(value));
6023 temp2[strlen(value)] = '\0';
6026 if((strlen(this_char) > 4) || strlen(temp2) > 8)
6029 j = strlen(this_char);
6032 if(this_char[j] > 'f' || this_char[j] < '0')
6039 if(temp2[j] > 'f' || temp2[j] < '0')
6044 k = j = strlen(this_char);
6047 this_char[4-k+j] = this_char[j];
6051 this_char[3-k++]='0';
6055 k = j = strlen(temp2);
6058 temp2[8-k+j] = temp2[j];
6066 AtoH(this_char, temp, 2);
6067 macAddr = *temp*256 + temp[1];
6069 AtoH(temp2, temp, 4);
6070 macValue = *temp*256*256*256 + temp[1]*256*256 + temp[2]*256 + temp[3];
6073 if (macAddr == (HW_DEBUG_SETTING_BASE + 4))
6075 // 0x2bf4: byte0 non-zero: enable R17 tuning, 0: disable R17 tuning
6076 if (macValue & 0x000000ff)
6078 pAdapter->BbpTuning.bEnable = TRUE;
6079 DBGPRINT(RT_DEBUG_TRACE,("turn on R17 tuning\n"));
6084 pAdapter->BbpTuning.bEnable = FALSE;
6085 R66 = 0x26 + GET_LNA_GAIN(pAdapter);
6086 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R66, (0x26 + GET_LNA_GAIN(pAdapter)));
6087 DBGPRINT(RT_DEBUG_TRACE,("turn off R17 tuning, restore to 0x%02x\n", R66));
6092 DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%02lx, MacValue=0x%x\n", macAddr, macValue));
6094 RTMP_IO_WRITE32(pAdapter, macAddr, macValue);
6095 sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr, macValue);
6100 bIsPrintAllMAC = TRUE;
6104 struct file *file_w;
6105 PCHAR fileName = "MacDump.txt";
6106 mm_segment_t orig_fs;
6112 file_w = filp_open(fileName, O_WRONLY|O_CREAT, 0);
6115 DBGPRINT(RT_DEBUG_TRACE, ("-->2) %s: Error %ld opening %s\n", __func__, -PTR_ERR(file_w), fileName));
6119 if (file_w->f_op && file_w->f_op->write)
6124 while (macAddr <= 0x1800)
6126 RTMP_IO_READ32(pAdapter, macAddr, &macValue);
6127 sprintf(msg, "%08lx = %08X\n", macAddr, macValue);
6129 // write data to file
6130 file_w->f_op->write(file_w, msg, strlen(msg), &file_w->f_pos);
6135 sprintf(msg, "\nDump all MAC values to %s\n", fileName);
6137 filp_close(file_w, NULL);
6141 if(strlen(msg) == 1)
6142 sprintf(msg+strlen(msg), "===>Error command format!");
6144 // Copy the information into the user buffer
6145 wrq->u.data.length = strlen(msg);
6146 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6148 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlMAC\n\n"));
6152 ==========================================================================
6156 pAdapter Pointer to our adapter
6157 wrq Pointer to the ioctl argument
6164 1.) iwpriv ra0 e2p 0 ==> read E2PROM where Addr=0x0
6165 2.) iwpriv ra0 e2p 0=1234 ==> write E2PROM where Addr=0x0, value=1234
6166 ==========================================================================
6168 VOID RTMPIoctlE2PROM(
6169 IN PRTMP_ADAPTER pAdapter,
6170 IN struct iwreq *wrq)
6178 UCHAR temp[16], temp2[16];
6181 BOOLEAN bIsPrintAllE2P = FALSE;
6184 memset(msg, 0x00, 1024);
6185 if (wrq->u.data.length > 1) //No parameters.
6187 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6190 //Parsing Read or Write
6197 if ((value = rtstrchr(this_char, '=')) != NULL)
6200 if (!value || !*value)
6204 if(strlen(this_char) > 4)
6207 j = strlen(this_char);
6210 if(this_char[j] > 'f' || this_char[j] < '0')
6215 k = j = strlen(this_char);
6218 this_char[4-k+j] = this_char[j];
6222 this_char[3-k++]='0';
6225 if(strlen(this_char) == 4)
6227 AtoH(this_char, temp, 2);
6228 eepAddr = *temp*256 + temp[1];
6229 if (eepAddr < 0xFFFF)
6231 RT28xx_EEPROM_READ16(pAdapter, eepAddr, eepValue);
6232 sprintf(msg+strlen(msg), "[0x%04X]:0x%04X ", eepAddr , eepValue);
6235 {//Invalid parametes, so default printk all bbp
6236 bIsPrintAllE2P = TRUE;
6243 memcpy(&temp2, value, strlen(value));
6244 temp2[strlen(value)] = '\0';
6247 if((strlen(this_char) > 4) || strlen(temp2) > 8)
6250 j = strlen(this_char);
6253 if(this_char[j] > 'f' || this_char[j] < '0')
6259 if(temp2[j] > 'f' || temp2[j] < '0')
6264 k = j = strlen(this_char);
6267 this_char[4-k+j] = this_char[j];
6271 this_char[3-k++]='0';
6275 k = j = strlen(temp2);
6278 temp2[4-k+j] = temp2[j];
6285 AtoH(this_char, temp, 2);
6286 eepAddr = *temp*256 + temp[1];
6288 AtoH(temp2, temp, 2);
6289 eepValue = *temp*256 + temp[1];
6291 RT28xx_EEPROM_WRITE16(pAdapter, eepAddr, eepValue);
6292 sprintf(msg+strlen(msg), "[0x%02X]:%02X ", eepAddr, eepValue);
6296 bIsPrintAllE2P = TRUE;
6300 struct file *file_w;
6301 PCHAR fileName = "EEPROMDump.txt";
6302 mm_segment_t orig_fs;
6308 file_w = filp_open(fileName, O_WRONLY|O_CREAT, 0);
6311 DBGPRINT(RT_DEBUG_TRACE, ("-->2) %s: Error %ld opening %s\n", __func__, -PTR_ERR(file_w), fileName));
6315 if (file_w->f_op && file_w->f_op->write)
6320 while (eepAddr <= 0xFE)
6322 RT28xx_EEPROM_READ16(pAdapter, eepAddr, eepValue);
6323 sprintf(msg, "%08x = %04x\n", eepAddr , eepValue);
6325 // write data to file
6326 file_w->f_op->write(file_w, msg, strlen(msg), &file_w->f_pos);
6331 sprintf(msg, "\nDump all EEPROM values to %s\n", fileName);
6333 filp_close(file_w, NULL);
6337 if(strlen(msg) == 1)
6338 sprintf(msg+strlen(msg), "===>Error command format!");
6341 // Copy the information into the user buffer
6342 wrq->u.data.length = strlen(msg);
6343 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6345 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlE2PROM\n"));
6349 ==========================================================================
6351 Read / Write RF register
6353 pAdapter Pointer to our adapter
6354 wrq Pointer to the ioctl argument
6361 1.) iwpriv ra0 rf ==> read all RF registers
6362 2.) iwpriv ra0 rf 1 ==> read RF where RegID=1
6363 3.) iwpriv ra0 rf 1=10 ==> write RF R1=0x10
6364 ==========================================================================
6367 IN PRTMP_ADAPTER pAdapter,
6368 IN struct iwreq *wrq)
6378 BOOLEAN bIsPrintAllRF = FALSE;
6381 memset(msg, 0x00, 2048);
6382 if (wrq->u.data.length > 1) //No parameters.
6384 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6387 //Parsing Read or Write
6392 if ((value = strchr(this_char, '=')) != NULL)
6395 if (!value || !*value)
6397 if (sscanf(this_char, "%d", &(rfId)) == 1)
6401 // In RT2860 ATE mode, we do not load 8051 firmware.
6402 //We must access RF directly.
6403 // For RT2870 ATE mode, ATE_RF_IO_WRITE8(/READ8)_BY_REG_ID are redefined.
6404 // according to Andy, Gary, David require.
6405 // the command rf shall read rf register directly for dubug.
6406 // BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
6407 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
6409 sprintf(msg+strlen(msg), "R%02d[0x%02x]:%02X ", rfId, rfId*2, regRF);
6412 {//Invalid parametes, so default printk all RF
6413 bIsPrintAllRF = TRUE;
6418 { //Invalid parametes, so default printk all RF
6419 bIsPrintAllRF = TRUE;
6425 if ((sscanf(this_char, "%d", &(rfId)) == 1) && (sscanf(value, "%lx", &(rfValue)) == 1))
6429 // In RT2860 ATE mode, we do not load 8051 firmware.
6430 // We should access RF registers directly.
6431 // For RT2870 ATE mode, ATE_RF_IO_WRITE8/READ8_BY_REG_ID are redefined.
6433 // according to Andy, Gary, David require.
6434 // the command RF shall read/write RF register directly for dubug.
6435 //BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
6436 //BBP_IO_WRITE8_BY_REG_ID(pAdapter, (UCHAR)bbpId,(UCHAR) bbpValue);
6437 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
6438 RT30xxWriteRFRegister(pAdapter, (UCHAR)rfId,(UCHAR) rfValue);
6439 //Read it back for showing
6440 //BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, ®BBP);
6441 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
6442 sprintf(msg+strlen(msg), "R%02d[0x%02X]:%02X\n", rfId, rfId*2, regRF);
6446 {//Invalid parametes, so default printk all RF
6447 bIsPrintAllRF = TRUE;
6451 { //Invalid parametes, so default printk all RF
6452 bIsPrintAllRF = TRUE;
6457 bIsPrintAllRF = TRUE;
6461 memset(msg, 0x00, 2048);
6463 for (rfId = 0; rfId <= 31; rfId++)
6465 // according to Andy, Gary, David require.
6466 // the command RF shall read/write RF register directly for dubug.
6467 RT30xxReadRFRegister(pAdapter, rfId, ®RF);
6468 sprintf(msg+strlen(msg), "%03d = %02X\n", rfId, regRF);
6470 // Copy the information into the user buffer
6471 DBGPRINT(RT_DEBUG_TRACE, ("strlen(msg)=%d\n", (UINT32)strlen(msg)));
6472 wrq->u.data.length = strlen(msg);
6473 if (copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length))
6475 DBGPRINT(RT_DEBUG_TRACE, ("%s: copy_to_user() fail\n", __func__));
6480 if(strlen(msg) == 1)
6481 sprintf(msg+strlen(msg), "===>Error command format!");
6483 DBGPRINT(RT_DEBUG_TRACE, ("copy to user [msg=%s]\n", msg));
6484 // Copy the information into the user buffer
6485 DBGPRINT(RT_DEBUG_TRACE, ("strlen(msg) =%d\n", (UINT32)strlen(msg)));
6487 // Copy the information into the user buffer
6488 wrq->u.data.length = strlen(msg);
6489 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6492 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlRF\n\n"));
6500 INT Set_TGnWifiTest_Proc(
6501 IN PRTMP_ADAPTER pAd,
6504 if (simple_strtol(arg, 0, 10) == 0)
6505 pAd->StaCfg.bTGnWifiTest = FALSE;
6507 pAd->StaCfg.bTGnWifiTest = TRUE;
6509 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_TGnWifiTest_Proc::(bTGnWifiTest=%d)\n", pAd->StaCfg.bTGnWifiTest));
6513 INT Set_LongRetryLimit_Proc(
6514 IN PRTMP_ADAPTER pAdapter,
6517 TX_RTY_CFG_STRUC tx_rty_cfg;
6518 UCHAR LongRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
6520 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
6521 tx_rty_cfg.field.LongRtyLimit = LongRetryLimit;
6522 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
6523 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_LongRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
6527 INT Set_ShortRetryLimit_Proc(
6528 IN PRTMP_ADAPTER pAdapter,
6531 TX_RTY_CFG_STRUC tx_rty_cfg;
6532 UCHAR ShortRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
6534 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
6535 tx_rty_cfg.field.ShortRtyLimit = ShortRetryLimit;
6536 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
6537 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_ShortRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));