Staging: rt2870: Don't call sprintf() with overlapping input and output.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / rt2870 / sta_ioctl.c
blob04cf5e5732c80dd32cb561db35e1eccb4ab3ed16
1 /*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
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. *
14 * *
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. *
19 * *
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. *
24 * *
25 *************************************************************************
27 Module Name:
28 sta_ioctl.c
30 Abstract:
31 IOCTL related subroutines
33 Revision History:
34 Who When What
35 -------- ---------- ----------------------------------------------
36 Rory Chen 01-03-2003 created
37 Rory Chen 02-14-2005 modify to support RT61
40 #include "rt_config.h"
42 #ifdef DBG
43 extern ULONG RTDebugLevel;
44 #endif
46 #define NR_WEP_KEYS 4
47 #define WEP_SMALL_KEY_LEN (40/8)
48 #define WEP_LARGE_KEY_LEN (104/8)
50 #define GROUP_KEY_NO 4
52 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
53 #define IWE_STREAM_ADD_EVENT(_A, _B, _C, _D, _E) iwe_stream_add_event(_A, _B, _C, _D, _E)
54 #define IWE_STREAM_ADD_POINT(_A, _B, _C, _D, _E) iwe_stream_add_point(_A, _B, _C, _D, _E)
55 #define IWE_STREAM_ADD_VALUE(_A, _B, _C, _D, _E, _F) iwe_stream_add_value(_A, _B, _C, _D, _E, _F)
56 #else
57 #define IWE_STREAM_ADD_EVENT(_A, _B, _C, _D, _E) iwe_stream_add_event(_B, _C, _D, _E)
58 #define IWE_STREAM_ADD_POINT(_A, _B, _C, _D, _E) iwe_stream_add_point(_B, _C, _D, _E)
59 #define IWE_STREAM_ADD_VALUE(_A, _B, _C, _D, _E, _F) iwe_stream_add_value(_B, _C, _D, _E, _F)
60 #endif
62 extern UCHAR CipherWpa2Template[];
63 extern UCHAR CipherWpaPskTkip[];
64 extern UCHAR CipherWpaPskTkipLen;
66 typedef struct PACKED _RT_VERSION_INFO{
67 UCHAR DriverVersionW;
68 UCHAR DriverVersionX;
69 UCHAR DriverVersionY;
70 UCHAR DriverVersionZ;
71 UINT DriverBuildYear;
72 UINT DriverBuildMonth;
73 UINT DriverBuildDay;
74 } RT_VERSION_INFO, *PRT_VERSION_INFO;
76 struct iw_priv_args privtab[] = {
77 { RTPRIV_IOCTL_SET,
78 IW_PRIV_TYPE_CHAR | 1024, 0,
79 "set"},
81 { RTPRIV_IOCTL_SHOW, 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
82 ""},
83 { RTPRIV_IOCTL_SHOW, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
84 ""},
85 /* --- sub-ioctls definitions --- */
86 { SHOW_CONN_STATUS,
87 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "connStatus" },
88 { SHOW_DRVIER_VERION,
89 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "driverVer" },
90 { SHOW_BA_INFO,
91 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "bainfo" },
92 { SHOW_DESC_INFO,
93 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "descinfo" },
94 { RAIO_OFF,
95 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "radio_off" },
96 { RAIO_ON,
97 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "radio_on" },
98 #ifdef QOS_DLS_SUPPORT
99 { SHOW_DLS_ENTRY_INFO,
100 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "dlsentryinfo" },
101 #endif // QOS_DLS_SUPPORT //
102 { SHOW_CFG_VALUE,
103 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "show" },
104 { SHOW_ADHOC_ENTRY_INFO,
105 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "adhocEntry" },
107 /* --- sub-ioctls relations --- */
109 #ifdef DBG
110 { RTPRIV_IOCTL_BBP,
111 IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
112 "bbp"},
113 { RTPRIV_IOCTL_MAC,
114 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
115 "mac"},
116 { RTPRIV_IOCTL_E2P,
117 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
118 "e2p"},
119 #endif /* DBG */
121 { RTPRIV_IOCTL_STATISTICS,
122 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
123 "stat"},
124 { RTPRIV_IOCTL_GSITESURVEY,
125 0, IW_PRIV_TYPE_CHAR | 1024,
126 "get_site_survey"},
129 INT Set_SSID_Proc(
130 IN PRTMP_ADAPTER pAdapter,
131 IN PUCHAR arg);
133 #ifdef WMM_SUPPORT
134 INT Set_WmmCapable_Proc(
135 IN PRTMP_ADAPTER pAd,
136 IN PUCHAR arg);
137 #endif
139 INT Set_NetworkType_Proc(
140 IN PRTMP_ADAPTER pAdapter,
141 IN PUCHAR arg);
143 INT Set_AuthMode_Proc(
144 IN PRTMP_ADAPTER pAdapter,
145 IN PUCHAR arg);
147 INT Set_EncrypType_Proc(
148 IN PRTMP_ADAPTER pAdapter,
149 IN PUCHAR arg);
151 INT Set_DefaultKeyID_Proc(
152 IN PRTMP_ADAPTER pAdapter,
153 IN PUCHAR arg);
155 INT Set_Key1_Proc(
156 IN PRTMP_ADAPTER pAdapter,
157 IN PUCHAR arg);
159 INT Set_Key2_Proc(
160 IN PRTMP_ADAPTER pAdapter,
161 IN PUCHAR arg);
163 INT Set_Key3_Proc(
164 IN PRTMP_ADAPTER pAdapter,
165 IN PUCHAR arg);
167 INT Set_Key4_Proc(
168 IN PRTMP_ADAPTER pAdapter,
169 IN PUCHAR arg);
171 INT Set_WPAPSK_Proc(
172 IN PRTMP_ADAPTER pAdapter,
173 IN PUCHAR arg);
176 INT Set_PSMode_Proc(
177 IN PRTMP_ADAPTER pAdapter,
178 IN PUCHAR arg);
180 #ifdef WPA_SUPPLICANT_SUPPORT
181 INT Set_Wpa_Support(
182 IN PRTMP_ADAPTER pAd,
183 IN PUCHAR arg);
184 #endif // WPA_SUPPLICANT_SUPPORT //
186 #ifdef DBG
187 VOID RTMPIoctlBBP(
188 IN PRTMP_ADAPTER pAdapter,
189 IN struct iwreq *wrq);
191 VOID RTMPIoctlMAC(
192 IN PRTMP_ADAPTER pAdapter,
193 IN struct iwreq *wrq);
195 VOID RTMPIoctlE2PROM(
196 IN PRTMP_ADAPTER pAdapter,
197 IN struct iwreq *wrq);
198 #endif // DBG //
201 NDIS_STATUS RTMPWPANoneAddKeyProc(
202 IN PRTMP_ADAPTER pAd,
203 IN PVOID pBuf);
205 INT Set_FragTest_Proc(
206 IN PRTMP_ADAPTER pAdapter,
207 IN PUCHAR arg);
209 #ifdef DOT11_N_SUPPORT
210 INT Set_TGnWifiTest_Proc(
211 IN PRTMP_ADAPTER pAd,
212 IN PUCHAR arg);
213 #endif // DOT11_N_SUPPORT //
215 INT Set_LongRetryLimit_Proc(
216 IN PRTMP_ADAPTER pAdapter,
217 IN PUCHAR arg);
219 INT Set_ShortRetryLimit_Proc(
220 IN PRTMP_ADAPTER pAdapter,
221 IN PUCHAR arg);
223 #ifdef EXT_BUILD_CHANNEL_LIST
224 INT Set_Ieee80211dClientMode_Proc(
225 IN PRTMP_ADAPTER pAdapter,
226 IN PUCHAR arg);
227 #endif // EXT_BUILD_CHANNEL_LIST //
229 #ifdef CARRIER_DETECTION_SUPPORT
230 INT Set_CarrierDetect_Proc(
231 IN PRTMP_ADAPTER pAd,
232 IN PUCHAR arg);
233 #endif // CARRIER_DETECTION_SUPPORT //
235 INT Show_Adhoc_MacTable_Proc(
236 IN PRTMP_ADAPTER pAd,
237 IN PCHAR extra);
239 static struct {
240 CHAR *name;
241 INT (*set_proc)(PRTMP_ADAPTER pAdapter, PUCHAR arg);
242 } *PRTMP_PRIVATE_SET_PROC, RTMP_PRIVATE_SUPPORT_PROC[] = {
243 {"DriverVersion", Set_DriverVersion_Proc},
244 {"CountryRegion", Set_CountryRegion_Proc},
245 {"CountryRegionABand", Set_CountryRegionABand_Proc},
246 {"SSID", Set_SSID_Proc},
247 {"WirelessMode", Set_WirelessMode_Proc},
248 {"TxBurst", Set_TxBurst_Proc},
249 {"TxPreamble", Set_TxPreamble_Proc},
250 {"TxPower", Set_TxPower_Proc},
251 {"Channel", Set_Channel_Proc},
252 {"BGProtection", Set_BGProtection_Proc},
253 {"RTSThreshold", Set_RTSThreshold_Proc},
254 {"FragThreshold", Set_FragThreshold_Proc},
255 #ifdef DOT11_N_SUPPORT
256 {"HtBw", Set_HtBw_Proc},
257 {"HtMcs", Set_HtMcs_Proc},
258 {"HtGi", Set_HtGi_Proc},
259 {"HtOpMode", Set_HtOpMode_Proc},
260 {"HtExtcha", Set_HtExtcha_Proc},
261 {"HtMpduDensity", Set_HtMpduDensity_Proc},
262 {"HtBaWinSize", Set_HtBaWinSize_Proc},
263 {"HtRdg", Set_HtRdg_Proc},
264 {"HtAmsdu", Set_HtAmsdu_Proc},
265 {"HtAutoBa", Set_HtAutoBa_Proc},
266 {"HtBaDecline", Set_BADecline_Proc},
267 {"HtProtect", Set_HtProtect_Proc},
268 {"HtMimoPs", Set_HtMimoPs_Proc},
269 #endif // DOT11_N_SUPPORT //
271 #ifdef AGGREGATION_SUPPORT
272 {"PktAggregate", Set_PktAggregate_Proc},
273 #endif
275 #ifdef WMM_SUPPORT
276 {"WmmCapable", Set_WmmCapable_Proc},
277 #endif
278 {"IEEE80211H", Set_IEEE80211H_Proc},
279 {"NetworkType", Set_NetworkType_Proc},
280 {"AuthMode", Set_AuthMode_Proc},
281 {"EncrypType", Set_EncrypType_Proc},
282 {"DefaultKeyID", Set_DefaultKeyID_Proc},
283 {"Key1", Set_Key1_Proc},
284 {"Key2", Set_Key2_Proc},
285 {"Key3", Set_Key3_Proc},
286 {"Key4", Set_Key4_Proc},
287 {"WPAPSK", Set_WPAPSK_Proc},
288 {"ResetCounter", Set_ResetStatCounter_Proc},
289 {"PSMode", Set_PSMode_Proc},
290 #ifdef DBG
291 {"Debug", Set_Debug_Proc},
292 #endif
294 #ifdef RALINK_ATE
295 {"ATE", Set_ATE_Proc},
296 {"ATEDA", Set_ATE_DA_Proc},
297 {"ATESA", Set_ATE_SA_Proc},
298 {"ATEBSSID", Set_ATE_BSSID_Proc},
299 {"ATECHANNEL", Set_ATE_CHANNEL_Proc},
300 {"ATETXPOW0", Set_ATE_TX_POWER0_Proc},
301 {"ATETXPOW1", Set_ATE_TX_POWER1_Proc},
302 {"ATETXANT", Set_ATE_TX_Antenna_Proc},
303 {"ATERXANT", Set_ATE_RX_Antenna_Proc},
304 {"ATETXFREQOFFSET", Set_ATE_TX_FREQOFFSET_Proc},
305 {"ATETXBW", Set_ATE_TX_BW_Proc},
306 {"ATETXLEN", Set_ATE_TX_LENGTH_Proc},
307 {"ATETXCNT", Set_ATE_TX_COUNT_Proc},
308 {"ATETXMCS", Set_ATE_TX_MCS_Proc},
309 {"ATETXMODE", Set_ATE_TX_MODE_Proc},
310 {"ATETXGI", Set_ATE_TX_GI_Proc},
311 {"ATERXFER", Set_ATE_RX_FER_Proc},
312 {"ATERRF", Set_ATE_Read_RF_Proc},
313 {"ATEWRF1", Set_ATE_Write_RF1_Proc},
314 {"ATEWRF2", Set_ATE_Write_RF2_Proc},
315 {"ATEWRF3", Set_ATE_Write_RF3_Proc},
316 {"ATEWRF4", Set_ATE_Write_RF4_Proc},
317 {"ATELDE2P", Set_ATE_Load_E2P_Proc},
318 {"ATERE2P", Set_ATE_Read_E2P_Proc},
319 {"ATESHOW", Set_ATE_Show_Proc},
320 {"ATEHELP", Set_ATE_Help_Proc},
322 #ifdef RALINK_28xx_QA
323 {"TxStop", Set_TxStop_Proc},
324 {"RxStop", Set_RxStop_Proc},
325 #endif // RALINK_28xx_QA //
326 #endif // RALINK_ATE //
328 #ifdef WPA_SUPPLICANT_SUPPORT
329 {"WpaSupport", Set_Wpa_Support},
330 #endif // WPA_SUPPLICANT_SUPPORT //
334 {"FixedTxMode", Set_FixedTxMode_Proc},
335 #ifdef CONFIG_APSTA_MIXED_SUPPORT
336 {"OpMode", Set_OpMode_Proc},
337 #endif // CONFIG_APSTA_MIXED_SUPPORT //
338 #ifdef DOT11_N_SUPPORT
339 {"TGnWifiTest", Set_TGnWifiTest_Proc},
340 {"ForceGF", Set_ForceGF_Proc},
341 #endif // DOT11_N_SUPPORT //
342 #ifdef QOS_DLS_SUPPORT
343 {"DlsAddEntry", Set_DlsAddEntry_Proc},
344 {"DlsTearDownEntry", Set_DlsTearDownEntry_Proc},
345 #endif // QOS_DLS_SUPPORT //
346 {"LongRetry", Set_LongRetryLimit_Proc},
347 {"ShortRetry", Set_ShortRetryLimit_Proc},
348 #ifdef EXT_BUILD_CHANNEL_LIST
349 {"11dClientMode", Set_Ieee80211dClientMode_Proc},
350 #endif // EXT_BUILD_CHANNEL_LIST //
351 #ifdef CARRIER_DETECTION_SUPPORT
352 {"CarrierDetect", Set_CarrierDetect_Proc},
353 #endif // CARRIER_DETECTION_SUPPORT //
355 {NULL,}
359 VOID RTMPAddKey(
360 IN PRTMP_ADAPTER pAd,
361 IN PNDIS_802_11_KEY pKey)
363 ULONG KeyIdx;
364 MAC_TABLE_ENTRY *pEntry;
366 DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey ------>\n"));
368 if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
370 if (pKey->KeyIndex & 0x80000000)
372 if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
374 NdisZeroMemory(pAd->StaCfg.PMK, 32);
375 NdisMoveMemory(pAd->StaCfg.PMK, pKey->KeyMaterial, pKey->KeyLength);
376 goto end;
378 // Update PTK
379 NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));
380 pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
381 NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, pKey->KeyMaterial, LEN_TKIP_EK);
382 #ifdef WPA_SUPPLICANT_SUPPORT
383 if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
385 NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
386 NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
388 else
389 #endif // WPA_SUPPLICANT_SUPPORT //
391 NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
392 NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
395 // Decide its ChiperAlg
396 if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
397 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
398 else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)
399 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
400 else
401 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_NONE;
403 // Update these related information to MAC_TABLE_ENTRY
404 pEntry = &pAd->MacTab.Content[BSSID_WCID];
405 NdisMoveMemory(pEntry->PairwiseKey.Key, pAd->SharedKey[BSS0][0].Key, LEN_TKIP_EK);
406 NdisMoveMemory(pEntry->PairwiseKey.RxMic, pAd->SharedKey[BSS0][0].RxMic, LEN_TKIP_RXMICK);
407 NdisMoveMemory(pEntry->PairwiseKey.TxMic, pAd->SharedKey[BSS0][0].TxMic, LEN_TKIP_TXMICK);
408 pEntry->PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;
410 // Update pairwise key information to ASIC Shared Key Table
411 AsicAddSharedKeyEntry(pAd,
412 BSS0,
414 pAd->SharedKey[BSS0][0].CipherAlg,
415 pAd->SharedKey[BSS0][0].Key,
416 pAd->SharedKey[BSS0][0].TxMic,
417 pAd->SharedKey[BSS0][0].RxMic);
419 // Update ASIC WCID attribute table and IVEIV table
420 RTMPAddWcidAttributeEntry(pAd,
421 BSS0,
423 pAd->SharedKey[BSS0][0].CipherAlg,
424 pEntry);
426 if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
428 // set 802.1x port control
429 //pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
430 STA_PORT_SECURED(pAd);
432 // Indicate Connected for GUI
433 pAd->IndicateMediaState = NdisMediaStateConnected;
436 else
438 // Update GTK
439 pAd->StaCfg.DefaultKeyId = (pKey->KeyIndex & 0xFF);
440 NdisZeroMemory(&pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId], sizeof(CIPHER_KEY));
441 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].KeyLen = LEN_TKIP_EK;
442 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key, pKey->KeyMaterial, LEN_TKIP_EK);
443 #ifdef WPA_SUPPLICANT_SUPPORT
444 if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
446 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
447 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
449 else
450 #endif // WPA_SUPPLICANT_SUPPORT //
452 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
453 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
456 // Update Shared Key CipherAlg
457 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_NONE;
458 if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
459 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_TKIP;
460 else if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)
461 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_AES;
463 // Update group key information to ASIC Shared Key Table
464 AsicAddSharedKeyEntry(pAd,
465 BSS0,
466 pAd->StaCfg.DefaultKeyId,
467 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
468 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key,
469 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic,
470 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic);
472 // Update ASIC WCID attribute table and IVEIV table
473 RTMPAddWcidAttributeEntry(pAd,
474 BSS0,
475 pAd->StaCfg.DefaultKeyId,
476 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
477 NULL);
479 // set 802.1x port control
480 //pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
481 STA_PORT_SECURED(pAd);
483 // Indicate Connected for GUI
484 pAd->IndicateMediaState = NdisMediaStateConnected;
487 else // dynamic WEP from wpa_supplicant
489 UCHAR CipherAlg;
490 PUCHAR Key;
492 if(pKey->KeyLength == 32)
493 goto end;
495 KeyIdx = pKey->KeyIndex & 0x0fffffff;
497 if (KeyIdx < 4)
499 // it is a default shared key, for Pairwise key setting
500 if (pKey->KeyIndex & 0x80000000)
502 pEntry = MacTableLookup(pAd, pKey->BSSID);
504 if (pEntry)
506 DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey: Set Pair-wise Key\n"));
508 // set key material and key length
509 pEntry->PairwiseKey.KeyLen = (UCHAR)pKey->KeyLength;
510 NdisMoveMemory(pEntry->PairwiseKey.Key, &pKey->KeyMaterial, pKey->KeyLength);
512 // set Cipher type
513 if (pKey->KeyLength == 5)
514 pEntry->PairwiseKey.CipherAlg = CIPHER_WEP64;
515 else
516 pEntry->PairwiseKey.CipherAlg = CIPHER_WEP128;
518 // Add Pair-wise key to Asic
519 AsicAddPairwiseKeyEntry(
520 pAd,
521 pEntry->Addr,
522 (UCHAR)pEntry->Aid,
523 &pEntry->PairwiseKey);
525 // update WCID attribute table and IVEIV table for this entry
526 RTMPAddWcidAttributeEntry(
527 pAd,
528 BSS0,
529 KeyIdx, // The value may be not zero
530 pEntry->PairwiseKey.CipherAlg,
531 pEntry);
535 else
537 // Default key for tx (shared key)
538 pAd->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
540 // set key material and key length
541 pAd->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pKey->KeyLength;
542 NdisMoveMemory(pAd->SharedKey[BSS0][KeyIdx].Key, &pKey->KeyMaterial, pKey->KeyLength);
544 // Set Ciper type
545 if (pKey->KeyLength == 5)
546 pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP64;
547 else
548 pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP128;
550 CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg;
551 Key = pAd->SharedKey[BSS0][KeyIdx].Key;
553 // Set Group key material to Asic
554 AsicAddSharedKeyEntry(pAd, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
556 // Update WCID attribute table and IVEIV table for this group key table
557 RTMPAddWcidAttributeEntry(pAd, BSS0, KeyIdx, CipherAlg, NULL);
562 end:
563 return;
566 char * rtstrchr(const char * s, int c)
568 for(; *s != (char) c; ++s)
569 if (*s == '\0')
570 return NULL;
571 return (char *) s;
575 This is required for LinEX2004/kernel2.6.7 to provide iwlist scanning function
579 rt_ioctl_giwname(struct net_device *dev,
580 struct iw_request_info *info,
581 char *name, char *extra)
583 // PRTMP_ADAPTER pAdapter = dev->ml_priv;
585 #ifdef RT2870
586 strncpy(name, "RT2870 Wireless", IFNAMSIZ);
587 #endif // RT2870 //
588 return 0;
591 int rt_ioctl_siwfreq(struct net_device *dev,
592 struct iw_request_info *info,
593 struct iw_freq *freq, char *extra)
595 PRTMP_ADAPTER pAdapter = dev->ml_priv;
596 int chan = -1;
598 //check if the interface is down
599 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
601 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
602 return -ENETDOWN;
606 if (freq->e > 1)
607 return -EINVAL;
609 if((freq->e == 0) && (freq->m <= 1000))
610 chan = freq->m; // Setting by channel number
611 else
612 MAP_KHZ_TO_CHANNEL_ID( (freq->m /100) , chan); // Setting by frequency - search the table , like 2.412G, 2.422G,
614 if (ChannelSanity(pAdapter, chan) == TRUE)
616 pAdapter->CommonCfg.Channel = chan;
617 DBGPRINT(RT_DEBUG_ERROR, ("==>rt_ioctl_siwfreq::SIOCSIWFREQ[cmd=0x%x] (Channel=%d)\n", SIOCSIWFREQ, pAdapter->CommonCfg.Channel));
619 else
620 return -EINVAL;
622 return 0;
624 int rt_ioctl_giwfreq(struct net_device *dev,
625 struct iw_request_info *info,
626 struct iw_freq *freq, char *extra)
628 VIRTUAL_ADAPTER *pVirtualAd = NULL;
629 PRTMP_ADAPTER pAdapter = NULL;
630 UCHAR ch;
631 ULONG m;
633 if (dev->priv_flags == INT_MAIN)
635 pAdapter = dev->ml_priv;
637 else
639 pVirtualAd = dev->ml_priv;
640 if (pVirtualAd && pVirtualAd->RtmpDev)
641 pAdapter = pVirtualAd->RtmpDev->ml_priv;
644 if (pAdapter == NULL)
646 /* if 1st open fail, pAd will be free;
647 So the net_dev->ml_priv will be NULL in 2rd open */
648 return -ENETDOWN;
651 ch = pAdapter->CommonCfg.Channel;
653 DBGPRINT(RT_DEBUG_TRACE,("==>rt_ioctl_giwfreq %d\n", ch));
655 MAP_CHANNEL_ID_TO_KHZ(ch, m);
656 freq->m = m * 100;
657 freq->e = 1;
658 return 0;
661 int rt_ioctl_siwmode(struct net_device *dev,
662 struct iw_request_info *info,
663 __u32 *mode, char *extra)
665 PRTMP_ADAPTER pAdapter = dev->ml_priv;
667 //check if the interface is down
668 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
670 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
671 return -ENETDOWN;
674 switch (*mode)
676 case IW_MODE_ADHOC:
677 Set_NetworkType_Proc(pAdapter, "Adhoc");
678 break;
679 case IW_MODE_INFRA:
680 Set_NetworkType_Proc(pAdapter, "Infra");
681 break;
682 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,4,20))
683 case IW_MODE_MONITOR:
684 Set_NetworkType_Proc(pAdapter, "Monitor");
685 break;
686 #endif
687 default:
688 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_siwmode::SIOCSIWMODE (unknown %d)\n", *mode));
689 return -EINVAL;
692 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
693 pAdapter->StaCfg.WpaState = SS_NOTUSE;
695 return 0;
698 int rt_ioctl_giwmode(struct net_device *dev,
699 struct iw_request_info *info,
700 __u32 *mode, char *extra)
702 PRTMP_ADAPTER pAdapter = NULL;
703 VIRTUAL_ADAPTER *pVirtualAd = NULL;
705 if (dev->priv_flags == INT_MAIN)
707 pAdapter = dev->ml_priv;
709 else
711 pVirtualAd = dev->ml_priv;
712 if (pVirtualAd && pVirtualAd->RtmpDev)
713 pAdapter = pVirtualAd->RtmpDev->ml_priv;
716 if (pAdapter == NULL)
718 /* if 1st open fail, pAd will be free;
719 So the net_dev->ml_priv will be NULL in 2rd open */
720 return -ENETDOWN;
723 if (ADHOC_ON(pAdapter))
724 *mode = IW_MODE_ADHOC;
725 else if (INFRA_ON(pAdapter))
726 *mode = IW_MODE_INFRA;
727 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,4,20))
728 else if (MONITOR_ON(pAdapter))
730 *mode = IW_MODE_MONITOR;
732 #endif
733 else
734 *mode = IW_MODE_AUTO;
736 DBGPRINT(RT_DEBUG_TRACE, ("==>rt_ioctl_giwmode(mode=%d)\n", *mode));
737 return 0;
740 int rt_ioctl_siwsens(struct net_device *dev,
741 struct iw_request_info *info,
742 char *name, char *extra)
744 PRTMP_ADAPTER pAdapter = dev->ml_priv;
746 //check if the interface is down
747 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
749 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
750 return -ENETDOWN;
753 return 0;
756 int rt_ioctl_giwsens(struct net_device *dev,
757 struct iw_request_info *info,
758 char *name, char *extra)
760 return 0;
763 int rt_ioctl_giwrange(struct net_device *dev,
764 struct iw_request_info *info,
765 struct iw_point *data, char *extra)
767 PRTMP_ADAPTER pAdapter = NULL;
768 VIRTUAL_ADAPTER *pVirtualAd = NULL;
769 struct iw_range *range = (struct iw_range *) extra;
770 u16 val;
771 int i;
773 if (dev->priv_flags == INT_MAIN)
775 pAdapter = dev->ml_priv;
777 else
779 pVirtualAd = dev->ml_priv;
780 if (pVirtualAd && pVirtualAd->RtmpDev)
781 pAdapter = pVirtualAd->RtmpDev->ml_priv;
784 if (pAdapter == NULL)
786 /* if 1st open fail, pAd will be free;
787 So the net_dev->ml_priv will be NULL in 2rd open */
788 return -ENETDOWN;
791 DBGPRINT(RT_DEBUG_TRACE ,("===>rt_ioctl_giwrange\n"));
792 data->length = sizeof(struct iw_range);
793 memset(range, 0, sizeof(struct iw_range));
795 range->txpower_capa = IW_TXPOW_DBM;
797 if (INFRA_ON(pAdapter)||ADHOC_ON(pAdapter))
799 range->min_pmp = 1 * 1024;
800 range->max_pmp = 65535 * 1024;
801 range->min_pmt = 1 * 1024;
802 range->max_pmt = 1000 * 1024;
803 range->pmp_flags = IW_POWER_PERIOD;
804 range->pmt_flags = IW_POWER_TIMEOUT;
805 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT |
806 IW_POWER_UNICAST_R | IW_POWER_ALL_R;
809 range->we_version_compiled = WIRELESS_EXT;
810 range->we_version_source = 14;
812 range->retry_capa = IW_RETRY_LIMIT;
813 range->retry_flags = IW_RETRY_LIMIT;
814 range->min_retry = 0;
815 range->max_retry = 255;
817 range->num_channels = pAdapter->ChannelListNum;
819 val = 0;
820 for (i = 1; i <= range->num_channels; i++)
822 u32 m;
823 range->freq[val].i = pAdapter->ChannelList[i-1].Channel;
824 MAP_CHANNEL_ID_TO_KHZ(pAdapter->ChannelList[i-1].Channel, m);
825 range->freq[val].m = m * 100; /* HZ */
827 range->freq[val].e = 1;
828 val++;
829 if (val == IW_MAX_FREQUENCIES)
830 break;
832 range->num_frequency = val;
834 range->max_qual.qual = 100; /* what is correct max? This was not
835 * documented exactly. At least
836 * 69 has been observed. */
837 range->max_qual.level = 0; /* dB */
838 range->max_qual.noise = 0; /* dB */
840 /* What would be suitable values for "average/typical" qual? */
841 range->avg_qual.qual = 20;
842 range->avg_qual.level = -60;
843 range->avg_qual.noise = -95;
844 range->sensitivity = 3;
846 range->max_encoding_tokens = NR_WEP_KEYS;
847 range->num_encoding_sizes = 2;
848 range->encoding_size[0] = 5;
849 range->encoding_size[1] = 13;
851 range->min_rts = 0;
852 range->max_rts = 2347;
853 range->min_frag = 256;
854 range->max_frag = 2346;
856 #if WIRELESS_EXT > 17
857 /* IW_ENC_CAPA_* bit field */
858 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
859 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
860 #endif
862 return 0;
865 int rt_ioctl_siwap(struct net_device *dev,
866 struct iw_request_info *info,
867 struct sockaddr *ap_addr, char *extra)
869 PRTMP_ADAPTER pAdapter = dev->ml_priv;
870 NDIS_802_11_MAC_ADDRESS Bssid;
872 //check if the interface is down
873 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
875 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
876 return -ENETDOWN;
879 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
881 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
882 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
885 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
886 // this request, because this request is initiated by NDIS.
887 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
888 // Prevent to connect AP again in STAMlmePeriodicExec
889 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
891 memset(Bssid, 0, MAC_ADDR_LEN);
892 memcpy(Bssid, ap_addr->sa_data, MAC_ADDR_LEN);
893 MlmeEnqueue(pAdapter,
894 MLME_CNTL_STATE_MACHINE,
895 OID_802_11_BSSID,
896 sizeof(NDIS_802_11_MAC_ADDRESS),
897 (VOID *)&Bssid);
899 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCSIWAP %02x:%02x:%02x:%02x:%02x:%02x\n",
900 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
902 return 0;
905 int rt_ioctl_giwap(struct net_device *dev,
906 struct iw_request_info *info,
907 struct sockaddr *ap_addr, char *extra)
909 PRTMP_ADAPTER pAdapter = NULL;
910 VIRTUAL_ADAPTER *pVirtualAd = NULL;
912 if (dev->priv_flags == INT_MAIN)
914 pAdapter = dev->ml_priv;
916 else
918 pVirtualAd = dev->ml_priv;
919 if (pVirtualAd && pVirtualAd->RtmpDev)
920 pAdapter = pVirtualAd->RtmpDev->ml_priv;
923 if (pAdapter == NULL)
925 /* if 1st open fail, pAd will be free;
926 So the net_dev->ml_priv will be NULL in 2rd open */
927 return -ENETDOWN;
930 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
932 ap_addr->sa_family = ARPHRD_ETHER;
933 memcpy(ap_addr->sa_data, &pAdapter->CommonCfg.Bssid, ETH_ALEN);
935 #ifdef WPA_SUPPLICANT_SUPPORT
936 // Add for RT2870
937 else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
939 ap_addr->sa_family = ARPHRD_ETHER;
940 memcpy(ap_addr->sa_data, &pAdapter->MlmeAux.Bssid, ETH_ALEN);
942 #endif // WPA_SUPPLICANT_SUPPORT //
943 else
945 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIWAP(=EMPTY)\n"));
946 return -ENOTCONN;
949 return 0;
953 * Units are in db above the noise floor. That means the
954 * rssi values reported in the tx/rx descriptors in the
955 * driver are the SNR expressed in db.
957 * If you assume that the noise floor is -95, which is an
958 * excellent assumption 99.5 % of the time, then you can
959 * derive the absolute signal level (i.e. -95 + rssi).
960 * There are some other slight factors to take into account
961 * depending on whether the rssi measurement is from 11b,
962 * 11g, or 11a. These differences are at most 2db and
963 * can be documented.
965 * NB: various calculations are based on the orinoco/wavelan
966 * drivers for compatibility
968 static void set_quality(PRTMP_ADAPTER pAdapter,
969 struct iw_quality *iq,
970 signed char rssi)
972 __u8 ChannelQuality;
974 // Normalize Rssi
975 if (rssi >= -50)
976 ChannelQuality = 100;
977 else if (rssi >= -80) // between -50 ~ -80dbm
978 ChannelQuality = (__u8)(24 + ((rssi + 80) * 26)/10);
979 else if (rssi >= -90) // between -80 ~ -90dbm
980 ChannelQuality = (__u8)((rssi + 90) * 26)/10;
981 else
982 ChannelQuality = 0;
984 iq->qual = (__u8)ChannelQuality;
986 iq->level = (__u8)(rssi);
987 iq->noise = (pAdapter->BbpWriteLatch[66] > pAdapter->BbpTuning.FalseCcaUpperThreshold) ? ((__u8)pAdapter->BbpTuning.FalseCcaUpperThreshold) : ((__u8) pAdapter->BbpWriteLatch[66]); // noise level (dBm)
988 iq->noise += 256 - 143;
989 iq->updated = pAdapter->iw_stats.qual.updated;
992 int rt_ioctl_iwaplist(struct net_device *dev,
993 struct iw_request_info *info,
994 struct iw_point *data, char *extra)
996 PRTMP_ADAPTER pAdapter = dev->ml_priv;
998 struct sockaddr addr[IW_MAX_AP];
999 struct iw_quality qual[IW_MAX_AP];
1000 int i;
1002 //check if the interface is down
1003 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1005 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1006 data->length = 0;
1007 return 0;
1008 //return -ENETDOWN;
1011 for (i = 0; i <IW_MAX_AP ; i++)
1013 if (i >= pAdapter->ScanTab.BssNr)
1014 break;
1015 addr[i].sa_family = ARPHRD_ETHER;
1016 memcpy(addr[i].sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
1017 set_quality(pAdapter, &qual[i], pAdapter->ScanTab.BssEntry[i].Rssi);
1019 data->length = i;
1020 memcpy(extra, &addr, i*sizeof(addr[0]));
1021 data->flags = 1; /* signal quality present (sort of) */
1022 memcpy(extra + i*sizeof(addr[0]), &qual, i*sizeof(qual[i]));
1024 return 0;
1027 #ifdef SIOCGIWSCAN
1028 int rt_ioctl_siwscan(struct net_device *dev,
1029 struct iw_request_info *info,
1030 struct iw_point *data, char *extra)
1032 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1034 ULONG Now;
1035 int Status = NDIS_STATUS_SUCCESS;
1037 //check if the interface is down
1038 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1040 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1041 return -ENETDOWN;
1044 if (MONITOR_ON(pAdapter))
1046 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
1047 return -EINVAL;
1051 #ifdef WPA_SUPPLICANT_SUPPORT
1052 if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
1054 pAdapter->StaCfg.WpaSupplicantScanCount++;
1056 #endif // WPA_SUPPLICANT_SUPPORT //
1058 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
1059 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
1060 return 0;
1062 Now = jiffies;
1064 #ifdef WPA_SUPPLICANT_SUPPORT
1065 if ((pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE) &&
1066 (pAdapter->StaCfg.WpaSupplicantScanCount > 3))
1068 DBGPRINT(RT_DEBUG_TRACE, ("!!! WpaSupplicantScanCount > 3\n"));
1069 Status = NDIS_STATUS_SUCCESS;
1070 break;
1072 #endif // WPA_SUPPLICANT_SUPPORT //
1074 if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
1075 ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
1076 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) &&
1077 (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
1079 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
1080 Status = NDIS_STATUS_SUCCESS;
1081 break;
1084 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
1086 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
1087 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
1090 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
1091 // this request, because this request is initiated by NDIS.
1092 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
1093 // Reset allowed scan retries
1094 pAdapter->StaCfg.ScanCnt = 0;
1095 pAdapter->StaCfg.LastScanTime = Now;
1097 MlmeEnqueue(pAdapter,
1098 MLME_CNTL_STATE_MACHINE,
1099 OID_802_11_BSSID_LIST_SCAN,
1101 NULL);
1103 Status = NDIS_STATUS_SUCCESS;
1104 RT28XX_MLME_HANDLER(pAdapter);
1105 }while(0);
1106 return 0;
1109 int rt_ioctl_giwscan(struct net_device *dev,
1110 struct iw_request_info *info,
1111 struct iw_point *data, char *extra)
1114 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1115 int i=0;
1116 char *current_ev = extra, *previous_ev = extra;
1117 char *end_buf;
1118 char *current_val, custom[MAX_CUSTOM_LEN] = {0};
1119 #ifndef IWEVGENIE
1120 char idx;
1121 #endif // IWEVGENIE //
1122 struct iw_event iwe;
1124 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
1127 * Still scanning, indicate the caller should try again.
1129 return -EAGAIN;
1133 #ifdef WPA_SUPPLICANT_SUPPORT
1134 if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
1136 pAdapter->StaCfg.WpaSupplicantScanCount = 0;
1138 #endif // WPA_SUPPLICANT_SUPPORT //
1140 if (pAdapter->ScanTab.BssNr == 0)
1142 data->length = 0;
1143 return 0;
1146 #if WIRELESS_EXT >= 17
1147 if (data->length > 0)
1148 end_buf = extra + data->length;
1149 else
1150 end_buf = extra + IW_SCAN_MAX_DATA;
1151 #else
1152 end_buf = extra + IW_SCAN_MAX_DATA;
1153 #endif
1155 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
1157 if (current_ev >= end_buf)
1159 #if WIRELESS_EXT >= 17
1160 return -E2BIG;
1161 #else
1162 break;
1163 #endif
1166 //MAC address
1167 //================================
1168 memset(&iwe, 0, sizeof(iwe));
1169 iwe.cmd = SIOCGIWAP;
1170 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1171 memcpy(iwe.u.ap_addr.sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, ETH_ALEN);
1173 previous_ev = current_ev;
1174 current_ev = IWE_STREAM_ADD_EVENT(info, current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);
1175 if (current_ev == previous_ev)
1176 #if WIRELESS_EXT >= 17
1177 return -E2BIG;
1178 #else
1179 break;
1180 #endif
1182 //ESSID
1183 //================================
1184 memset(&iwe, 0, sizeof(iwe));
1185 iwe.cmd = SIOCGIWESSID;
1186 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].SsidLen;
1187 iwe.u.data.flags = 1;
1189 previous_ev = current_ev;
1190 current_ev = IWE_STREAM_ADD_POINT(info, current_ev,end_buf, &iwe, pAdapter->ScanTab.BssEntry[i].Ssid);
1191 if (current_ev == previous_ev)
1192 #if WIRELESS_EXT >= 17
1193 return -E2BIG;
1194 #else
1195 break;
1196 #endif
1198 //Network Type
1199 //================================
1200 memset(&iwe, 0, sizeof(iwe));
1201 iwe.cmd = SIOCGIWMODE;
1202 if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11IBSS)
1204 iwe.u.mode = IW_MODE_ADHOC;
1206 else if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11Infrastructure)
1208 iwe.u.mode = IW_MODE_INFRA;
1210 else
1212 iwe.u.mode = IW_MODE_AUTO;
1214 iwe.len = IW_EV_UINT_LEN;
1216 previous_ev = current_ev;
1217 current_ev = IWE_STREAM_ADD_EVENT(info, current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
1218 if (current_ev == previous_ev)
1219 #if WIRELESS_EXT >= 17
1220 return -E2BIG;
1221 #else
1222 break;
1223 #endif
1225 //Channel and Frequency
1226 //================================
1227 memset(&iwe, 0, sizeof(iwe));
1228 iwe.cmd = SIOCGIWFREQ;
1229 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
1230 iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
1231 else
1232 iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
1233 iwe.u.freq.e = 0;
1234 iwe.u.freq.i = 0;
1236 previous_ev = current_ev;
1237 current_ev = IWE_STREAM_ADD_EVENT(info, current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
1238 if (current_ev == previous_ev)
1239 #if WIRELESS_EXT >= 17
1240 return -E2BIG;
1241 #else
1242 break;
1243 #endif
1245 //Add quality statistics
1246 //================================
1247 memset(&iwe, 0, sizeof(iwe));
1248 iwe.cmd = IWEVQUAL;
1249 iwe.u.qual.level = 0;
1250 iwe.u.qual.noise = 0;
1251 set_quality(pAdapter, &iwe.u.qual, pAdapter->ScanTab.BssEntry[i].Rssi);
1252 current_ev = IWE_STREAM_ADD_EVENT(info, current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
1253 if (current_ev == previous_ev)
1254 #if WIRELESS_EXT >= 17
1255 return -E2BIG;
1256 #else
1257 break;
1258 #endif
1260 //Encyption key
1261 //================================
1262 memset(&iwe, 0, sizeof(iwe));
1263 iwe.cmd = SIOCGIWENCODE;
1264 if (CAP_IS_PRIVACY_ON (pAdapter->ScanTab.BssEntry[i].CapabilityInfo ))
1265 iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1266 else
1267 iwe.u.data.flags = IW_ENCODE_DISABLED;
1269 previous_ev = current_ev;
1270 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);
1271 if (current_ev == previous_ev)
1272 #if WIRELESS_EXT >= 17
1273 return -E2BIG;
1274 #else
1275 break;
1276 #endif
1278 //Bit Rate
1279 //================================
1280 if (pAdapter->ScanTab.BssEntry[i].SupRateLen)
1282 UCHAR tmpRate = pAdapter->ScanTab.BssEntry[i].SupRate[pAdapter->ScanTab.BssEntry[i].SupRateLen-1];
1283 memset(&iwe, 0, sizeof(iwe));
1284 iwe.cmd = SIOCGIWRATE;
1285 current_val = current_ev + IW_EV_LCP_LEN;
1286 if (tmpRate == 0x82)
1287 iwe.u.bitrate.value = 1 * 1000000;
1288 else if (tmpRate == 0x84)
1289 iwe.u.bitrate.value = 2 * 1000000;
1290 else if (tmpRate == 0x8B)
1291 iwe.u.bitrate.value = 5.5 * 1000000;
1292 else if (tmpRate == 0x96)
1293 iwe.u.bitrate.value = 11 * 1000000;
1294 else
1295 iwe.u.bitrate.value = (tmpRate/2) * 1000000;
1297 iwe.u.bitrate.disabled = 0;
1298 current_val = IWE_STREAM_ADD_VALUE(info, current_ev,
1299 current_val, end_buf, &iwe,
1300 IW_EV_PARAM_LEN);
1302 if((current_val-current_ev)>IW_EV_LCP_LEN)
1303 current_ev = current_val;
1304 else
1305 #if WIRELESS_EXT >= 17
1306 return -E2BIG;
1307 #else
1308 break;
1309 #endif
1312 #ifdef IWEVGENIE
1313 //WPA IE
1314 if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
1316 memset(&iwe, 0, sizeof(iwe));
1317 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1318 memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].WpaIE.IE[0]),
1319 pAdapter->ScanTab.BssEntry[i].WpaIE.IELen);
1320 iwe.cmd = IWEVGENIE;
1321 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].WpaIE.IELen;
1322 current_ev = IWE_STREAM_ADD_POINT(info, current_ev, end_buf, &iwe, custom);
1323 if (current_ev == previous_ev)
1324 #if WIRELESS_EXT >= 17
1325 return -E2BIG;
1326 #else
1327 break;
1328 #endif
1331 //WPA2 IE
1332 if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
1334 memset(&iwe, 0, sizeof(iwe));
1335 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1336 memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].RsnIE.IE[0]),
1337 pAdapter->ScanTab.BssEntry[i].RsnIE.IELen);
1338 iwe.cmd = IWEVGENIE;
1339 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].RsnIE.IELen;
1340 current_ev = IWE_STREAM_ADD_POINT(info, current_ev, end_buf, &iwe, custom);
1341 if (current_ev == previous_ev)
1342 #if WIRELESS_EXT >= 17
1343 return -E2BIG;
1344 #else
1345 break;
1346 #endif
1348 #else
1349 //WPA IE
1350 //================================
1351 if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
1353 NdisZeroMemory(&iwe, sizeof(iwe));
1354 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1355 iwe.cmd = IWEVCUSTOM;
1356 iwe.u.data.length = (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen * 2) + 7;
1357 NdisMoveMemory(custom, "wpa_ie=", 7);
1358 for (idx = 0; idx < pAdapter->ScanTab.BssEntry[i].WpaIE.IELen; idx++)
1359 sprintf(custom + strlen(custom), "%02x", pAdapter->ScanTab.BssEntry[i].WpaIE.IE[idx]);
1360 previous_ev = current_ev;
1361 current_ev = IWE_STREAM_ADD_POINT(info, current_ev, end_buf, &iwe, custom);
1362 if (current_ev == previous_ev)
1363 #if WIRELESS_EXT >= 17
1364 return -E2BIG;
1365 #else
1366 break;
1367 #endif
1370 //WPA2 IE
1371 if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
1373 NdisZeroMemory(&iwe, sizeof(iwe));
1374 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1375 iwe.cmd = IWEVCUSTOM;
1376 iwe.u.data.length = (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen * 2) + 7;
1377 NdisMoveMemory(custom, "rsn_ie=", 7);
1378 for (idx = 0; idx < pAdapter->ScanTab.BssEntry[i].RsnIE.IELen; idx++)
1379 sprintf(custom + strlen(custom), "%02x", pAdapter->ScanTab.BssEntry[i].RsnIE.IE[idx]);
1380 previous_ev = current_ev;
1381 current_ev = IWE_STREAM_ADD_POINT(info, current_ev, end_buf, &iwe, custom);
1382 if (current_ev == previous_ev)
1383 #if WIRELESS_EXT >= 17
1384 return -E2BIG;
1385 #else
1386 break;
1387 #endif
1389 #endif // IWEVGENIE //
1392 data->length = current_ev - extra;
1393 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
1394 DBGPRINT(RT_DEBUG_ERROR ,("===>rt_ioctl_giwscan. %d(%d) BSS returned, data->length = %d\n",i , pAdapter->ScanTab.BssNr, data->length));
1395 return 0;
1397 #endif
1399 int rt_ioctl_siwessid(struct net_device *dev,
1400 struct iw_request_info *info,
1401 struct iw_point *data, char *essid)
1403 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1405 //check if the interface is down
1406 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1408 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1409 return -ENETDOWN;
1412 if (data->flags)
1414 PCHAR pSsidString = NULL;
1416 // Includes null character.
1417 if (data->length > (IW_ESSID_MAX_SIZE + 1))
1418 return -E2BIG;
1420 pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
1421 if (pSsidString)
1423 NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
1424 NdisMoveMemory(pSsidString, essid, data->length);
1425 if (Set_SSID_Proc(pAdapter, pSsidString) == FALSE)
1426 return -EINVAL;
1428 else
1429 return -ENOMEM;
1431 else
1433 // ANY ssid
1434 if (Set_SSID_Proc(pAdapter, "") == FALSE)
1435 return -EINVAL;
1437 return 0;
1440 int rt_ioctl_giwessid(struct net_device *dev,
1441 struct iw_request_info *info,
1442 struct iw_point *data, char *essid)
1444 PRTMP_ADAPTER pAdapter = NULL;
1445 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1447 if (dev->priv_flags == INT_MAIN)
1449 pAdapter = dev->ml_priv;
1451 else
1453 pVirtualAd = dev->ml_priv;
1454 if (pVirtualAd && pVirtualAd->RtmpDev)
1455 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1458 if (pAdapter == NULL)
1460 /* if 1st open fail, pAd will be free;
1461 So the net_dev->ml_priv will be NULL in 2rd open */
1462 return -ENETDOWN;
1465 data->flags = 1;
1466 if (MONITOR_ON(pAdapter))
1468 data->length = 0;
1469 return 0;
1472 if (OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED))
1474 DBGPRINT(RT_DEBUG_TRACE ,("MediaState is connected\n"));
1475 data->length = pAdapter->CommonCfg.SsidLen;
1476 memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
1478 #ifdef RT2870
1479 #ifdef WPA_SUPPLICANT_SUPPORT
1480 // Add for RT2870
1481 else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
1483 data->length = pAdapter->CommonCfg.SsidLen;
1484 memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
1486 #endif // WPA_SUPPLICANT_SUPPORT //
1487 #endif // RT2870 //
1488 else
1489 {//the ANY ssid was specified
1490 data->length = 0;
1491 DBGPRINT(RT_DEBUG_TRACE ,("MediaState is not connected, ess\n"));
1494 return 0;
1498 int rt_ioctl_siwnickn(struct net_device *dev,
1499 struct iw_request_info *info,
1500 struct iw_point *data, char *nickname)
1502 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1504 //check if the interface is down
1505 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1507 DBGPRINT(RT_DEBUG_TRACE ,("INFO::Network is down!\n"));
1508 return -ENETDOWN;
1511 if (data->length > IW_ESSID_MAX_SIZE)
1512 return -EINVAL;
1514 memset(pAdapter->nickname, 0, IW_ESSID_MAX_SIZE + 1);
1515 memcpy(pAdapter->nickname, nickname, data->length);
1518 return 0;
1521 int rt_ioctl_giwnickn(struct net_device *dev,
1522 struct iw_request_info *info,
1523 struct iw_point *data, char *nickname)
1525 PRTMP_ADAPTER pAdapter = NULL;
1526 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1528 if (dev->priv_flags == INT_MAIN)
1530 pAdapter = dev->ml_priv;
1532 else
1534 pVirtualAd = dev->ml_priv;
1535 if (pVirtualAd && pVirtualAd->RtmpDev)
1536 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1539 if (pAdapter == NULL)
1541 /* if 1st open fail, pAd will be free;
1542 So the net_dev->ml_priv will be NULL in 2rd open */
1543 return -ENETDOWN;
1546 if (data->length > strlen(pAdapter->nickname) + 1)
1547 data->length = strlen(pAdapter->nickname) + 1;
1548 if (data->length > 0) {
1549 memcpy(nickname, pAdapter->nickname, data->length-1);
1550 nickname[data->length-1] = '\0';
1552 return 0;
1555 int rt_ioctl_siwrts(struct net_device *dev,
1556 struct iw_request_info *info,
1557 struct iw_param *rts, char *extra)
1559 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1560 u16 val;
1562 //check if the interface is down
1563 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1565 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1566 return -ENETDOWN;
1569 if (rts->disabled)
1570 val = MAX_RTS_THRESHOLD;
1571 else if (rts->value < 0 || rts->value > MAX_RTS_THRESHOLD)
1572 return -EINVAL;
1573 else if (rts->value == 0)
1574 val = MAX_RTS_THRESHOLD;
1575 else
1576 val = rts->value;
1578 if (val != pAdapter->CommonCfg.RtsThreshold)
1579 pAdapter->CommonCfg.RtsThreshold = val;
1581 return 0;
1584 int rt_ioctl_giwrts(struct net_device *dev,
1585 struct iw_request_info *info,
1586 struct iw_param *rts, char *extra)
1588 PRTMP_ADAPTER pAdapter = NULL;
1589 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1591 if (dev->priv_flags == INT_MAIN)
1593 pAdapter = dev->ml_priv;
1595 else
1597 pVirtualAd = dev->ml_priv;
1598 if (pVirtualAd && pVirtualAd->RtmpDev)
1599 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1602 if (pAdapter == NULL)
1604 /* if 1st open fail, pAd will be free;
1605 So the net_dev->ml_priv will be NULL in 2rd open */
1606 return -ENETDOWN;
1609 //check if the interface is down
1610 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1612 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1613 return -ENETDOWN;
1616 rts->value = pAdapter->CommonCfg.RtsThreshold;
1617 rts->disabled = (rts->value == MAX_RTS_THRESHOLD);
1618 rts->fixed = 1;
1620 return 0;
1623 int rt_ioctl_siwfrag(struct net_device *dev,
1624 struct iw_request_info *info,
1625 struct iw_param *frag, char *extra)
1627 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1628 u16 val;
1630 //check if the interface is down
1631 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1633 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1634 return -ENETDOWN;
1637 if (frag->disabled)
1638 val = MAX_FRAG_THRESHOLD;
1639 else if (frag->value >= MIN_FRAG_THRESHOLD || frag->value <= MAX_FRAG_THRESHOLD)
1640 val = __cpu_to_le16(frag->value & ~0x1); /* even numbers only */
1641 else if (frag->value == 0)
1642 val = MAX_FRAG_THRESHOLD;
1643 else
1644 return -EINVAL;
1646 pAdapter->CommonCfg.FragmentThreshold = val;
1647 return 0;
1650 int rt_ioctl_giwfrag(struct net_device *dev,
1651 struct iw_request_info *info,
1652 struct iw_param *frag, char *extra)
1654 PRTMP_ADAPTER pAdapter = NULL;
1655 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1657 if (dev->priv_flags == INT_MAIN)
1659 pAdapter = dev->ml_priv;
1661 else
1663 pVirtualAd = dev->ml_priv;
1664 if (pVirtualAd && pVirtualAd->RtmpDev)
1665 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1668 if (pAdapter == NULL)
1670 /* if 1st open fail, pAd will be free;
1671 So the net_dev->ml_priv will be NULL in 2rd open */
1672 return -ENETDOWN;
1675 //check if the interface is down
1676 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1678 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1679 return -ENETDOWN;
1682 frag->value = pAdapter->CommonCfg.FragmentThreshold;
1683 frag->disabled = (frag->value == MAX_FRAG_THRESHOLD);
1684 frag->fixed = 1;
1686 return 0;
1689 #define MAX_WEP_KEY_SIZE 13
1690 #define MIN_WEP_KEY_SIZE 5
1691 int rt_ioctl_siwencode(struct net_device *dev,
1692 struct iw_request_info *info,
1693 struct iw_point *erq, char *extra)
1695 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1697 //check if the interface is down
1698 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1700 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1701 return -ENETDOWN;
1704 if ((erq->length == 0) &&
1705 (erq->flags & IW_ENCODE_DISABLED))
1707 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
1708 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
1709 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
1710 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
1711 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1712 goto done;
1714 else if ((erq->length == 0) &&
1715 (erq->flags & IW_ENCODE_RESTRICTED || erq->flags & IW_ENCODE_OPEN))
1717 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
1718 STA_PORT_SECURED(pAdapter);
1719 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
1720 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
1721 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
1722 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
1723 if (erq->flags & IW_ENCODE_RESTRICTED)
1724 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
1725 else
1726 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1727 goto done;
1730 if (erq->length > 0)
1732 int keyIdx = (erq->flags & IW_ENCODE_INDEX) - 1;
1733 /* Check the size of the key */
1734 if (erq->length > MAX_WEP_KEY_SIZE) {
1735 return -EINVAL;
1737 /* Check key index */
1738 if ((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
1740 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::Wrong keyIdx=%d! Using default key instead (%d)\n",
1741 keyIdx, pAdapter->StaCfg.DefaultKeyId));
1743 //Using default key
1744 keyIdx = pAdapter->StaCfg.DefaultKeyId;
1747 NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
1749 if (erq->length == MAX_WEP_KEY_SIZE)
1751 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
1752 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
1754 else if (erq->length == MIN_WEP_KEY_SIZE)
1756 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
1757 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
1759 else
1760 /* Disable the key */
1761 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
1763 /* Check if the key is not marked as invalid */
1764 if(!(erq->flags & IW_ENCODE_NOKEY)) {
1765 /* Copy the key in the driver */
1766 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, extra, erq->length);
1769 else
1771 /* Do we want to just set the transmit key index ? */
1772 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
1773 if ((index >= 0) && (index < 4))
1775 pAdapter->StaCfg.DefaultKeyId = index;
1777 else
1778 /* Don't complain if only change the mode */
1779 if (!(erq->flags & IW_ENCODE_MODE)) {
1780 return -EINVAL;
1784 done:
1785 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::erq->flags=%x\n",erq->flags));
1786 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::AuthMode=%x\n",pAdapter->StaCfg.AuthMode));
1787 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::DefaultKeyId=%x, KeyLen = %d\n",pAdapter->StaCfg.DefaultKeyId , pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen));
1788 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::WepStatus=%x\n",pAdapter->StaCfg.WepStatus));
1789 return 0;
1793 rt_ioctl_giwencode(struct net_device *dev,
1794 struct iw_request_info *info,
1795 struct iw_point *erq, char *key)
1797 int kid;
1798 PRTMP_ADAPTER pAdapter = NULL;
1799 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1801 if (dev->priv_flags == INT_MAIN)
1803 pAdapter = dev->ml_priv;
1805 else
1807 pVirtualAd = dev->ml_priv;
1808 if (pVirtualAd && pVirtualAd->RtmpDev)
1809 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1812 if (pAdapter == NULL)
1814 /* if 1st open fail, pAd will be free;
1815 So the net_dev->ml_priv will be NULL in 2rd open */
1816 return -ENETDOWN;
1819 //check if the interface is down
1820 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1822 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1823 return -ENETDOWN;
1826 kid = erq->flags & IW_ENCODE_INDEX;
1827 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_giwencode %d\n", erq->flags & IW_ENCODE_INDEX));
1829 if (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled)
1831 erq->length = 0;
1832 erq->flags = IW_ENCODE_DISABLED;
1834 else if ((kid > 0) && (kid <=4))
1836 // copy wep key
1837 erq->flags = kid ; /* NB: base 1 */
1838 if (erq->length > pAdapter->SharedKey[BSS0][kid-1].KeyLen)
1839 erq->length = pAdapter->SharedKey[BSS0][kid-1].KeyLen;
1840 memcpy(key, pAdapter->SharedKey[BSS0][kid-1].Key, erq->length);
1841 //if ((kid == pAdapter->PortCfg.DefaultKeyId))
1842 //erq->flags |= IW_ENCODE_ENABLED; /* XXX */
1843 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1844 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1845 else
1846 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1849 else if (kid == 0)
1851 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1852 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1853 else
1854 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1855 erq->length = pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen;
1856 memcpy(key, pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key, erq->length);
1857 // copy default key ID
1858 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1859 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1860 else
1861 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1862 erq->flags = pAdapter->StaCfg.DefaultKeyId + 1; /* NB: base 1 */
1863 erq->flags |= IW_ENCODE_ENABLED; /* XXX */
1866 return 0;
1870 static int
1871 rt_ioctl_setparam(struct net_device *dev, struct iw_request_info *info,
1872 void *w, char *extra)
1874 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1875 PRTMP_ADAPTER pAdapter;
1876 POS_COOKIE pObj;
1877 char *this_char = extra;
1878 char *value;
1879 int Status=0;
1881 if (dev->priv_flags == INT_MAIN)
1883 pAdapter = dev->ml_priv;
1885 else
1887 pVirtualAd = dev->ml_priv;
1888 pAdapter = pVirtualAd->RtmpDev->ml_priv;
1890 pObj = (POS_COOKIE) pAdapter->OS_Cookie;
1892 if (pAdapter == NULL)
1894 /* if 1st open fail, pAd will be free;
1895 So the net_dev->ml_priv will be NULL in 2rd open */
1896 return -ENETDOWN;
1900 pObj->ioctl_if_type = INT_MAIN;
1901 pObj->ioctl_if = MAIN_MBSSID;
1904 //check if the interface is down
1905 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1907 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1908 return -ENETDOWN;
1911 if (!*this_char)
1912 return -EINVAL;
1914 if ((value = rtstrchr(this_char, '=')) != NULL)
1915 *value++ = 0;
1917 if (!value)
1918 return -EINVAL;
1920 // reject setting nothing besides ANY ssid(ssidLen=0)
1921 if (!*value && (strcmp(this_char, "SSID") != 0))
1922 return -EINVAL;
1924 for (PRTMP_PRIVATE_SET_PROC = RTMP_PRIVATE_SUPPORT_PROC; PRTMP_PRIVATE_SET_PROC->name; PRTMP_PRIVATE_SET_PROC++)
1926 if (strcmp(this_char, PRTMP_PRIVATE_SET_PROC->name) == 0)
1928 if(!PRTMP_PRIVATE_SET_PROC->set_proc(pAdapter, value))
1929 { //FALSE:Set private failed then return Invalid argument
1930 Status = -EINVAL;
1932 break; //Exit for loop.
1936 if(PRTMP_PRIVATE_SET_PROC->name == NULL)
1937 { //Not found argument
1938 Status = -EINVAL;
1939 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_setparam:: (iwpriv) Not Support Set Command [%s=%s]\n", this_char, value));
1942 return Status;
1946 static int
1947 rt_private_get_statistics(struct net_device *dev, struct iw_request_info *info,
1948 struct iw_point *wrq, char *extra)
1950 INT Status = 0;
1951 PRTMP_ADAPTER pAd = dev->ml_priv;
1953 if (extra == NULL)
1955 wrq->length = 0;
1956 return -EIO;
1959 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
1960 sprintf(extra, "\n\n");
1962 #ifdef RALINK_ATE
1963 if (ATE_ON(pAd))
1965 sprintf(extra+strlen(extra), "Tx success = %ld\n", (ULONG)pAd->ate.TxDoneCount);
1966 //sprintf(extra+strlen(extra), "Tx success without retry = %ld\n", (ULONG)pAd->ate.TxDoneCount);
1968 else
1969 #endif // RALINK_ATE //
1971 sprintf(extra+strlen(extra), "Tx success = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart);
1972 sprintf(extra+strlen(extra), "Tx success without retry = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart - (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
1974 sprintf(extra+strlen(extra), "Tx success after retry = %ld\n", (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
1975 sprintf(extra+strlen(extra), "Tx fail to Rcv ACK after retry = %ld\n", (ULONG)pAd->WlanCounters.FailedCount.QuadPart);
1976 sprintf(extra+strlen(extra), "RTS Success Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSSuccessCount.QuadPart);
1977 sprintf(extra+strlen(extra), "RTS Fail Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSFailureCount.QuadPart);
1979 sprintf(extra+strlen(extra), "Rx success = %ld\n", (ULONG)pAd->WlanCounters.ReceivedFragmentCount.QuadPart);
1980 sprintf(extra+strlen(extra), "Rx with CRC = %ld\n", (ULONG)pAd->WlanCounters.FCSErrorCount.QuadPart);
1981 sprintf(extra+strlen(extra), "Rx drop due to out of resource = %ld\n", (ULONG)pAd->Counters8023.RxNoBuffer);
1982 sprintf(extra+strlen(extra), "Rx duplicate frame = %ld\n", (ULONG)pAd->WlanCounters.FrameDuplicateCount.QuadPart);
1984 sprintf(extra+strlen(extra), "False CCA (one second) = %ld\n", (ULONG)pAd->RalinkCounters.OneSecFalseCCACnt);
1985 #ifdef RALINK_ATE
1986 if (ATE_ON(pAd))
1988 if (pAd->ate.RxAntennaSel == 0)
1990 sprintf(extra+strlen(extra), "RSSI-A = %ld\n", (LONG)(pAd->ate.LastRssi0 - pAd->BbpRssiToDbmDelta));
1991 sprintf(extra+strlen(extra), "RSSI-B (if available) = %ld\n", (LONG)(pAd->ate.LastRssi1 - pAd->BbpRssiToDbmDelta));
1992 sprintf(extra+strlen(extra), "RSSI-C (if available) = %ld\n\n", (LONG)(pAd->ate.LastRssi2 - pAd->BbpRssiToDbmDelta));
1994 else
1996 sprintf(extra+strlen(extra), "RSSI = %ld\n", (LONG)(pAd->ate.LastRssi0 - pAd->BbpRssiToDbmDelta));
1999 else
2000 #endif // RALINK_ATE //
2002 sprintf(extra+strlen(extra), "RSSI-A = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi0 - pAd->BbpRssiToDbmDelta));
2003 sprintf(extra+strlen(extra), "RSSI-B (if available) = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi1 - pAd->BbpRssiToDbmDelta));
2004 sprintf(extra+strlen(extra), "RSSI-C (if available) = %ld\n\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi2 - pAd->BbpRssiToDbmDelta));
2006 #ifdef WPA_SUPPLICANT_SUPPORT
2007 sprintf(extra+strlen(extra), "WpaSupplicantUP = %d\n\n", pAd->StaCfg.WpaSupplicantUP);
2008 #endif // WPA_SUPPLICANT_SUPPORT //
2011 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2012 DBGPRINT(RT_DEBUG_TRACE, ("<== rt_private_get_statistics, wrq->length = %d\n", wrq->length));
2014 return Status;
2017 #ifdef DOT11_N_SUPPORT
2018 void getBaInfo(
2019 IN PRTMP_ADAPTER pAd,
2020 IN PUCHAR pOutBuf)
2022 INT i, j;
2023 BA_ORI_ENTRY *pOriBAEntry;
2024 BA_REC_ENTRY *pRecBAEntry;
2026 for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
2028 PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
2029 if (((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
2030 || (pEntry->ValidAsWDS) || (pEntry->ValidAsMesh))
2032 sprintf(pOutBuf + strlen(pOutBuf), "\n%02X:%02X:%02X:%02X:%02X:%02X (Aid = %d) (AP) -\n",
2033 pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
2034 pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5], pEntry->Aid);
2036 sprintf(pOutBuf, "%s[Recipient]\n", pOutBuf);
2037 for (j=0; j < NUM_OF_TID; j++)
2039 if (pEntry->BARecWcidArray[j] != 0)
2041 pRecBAEntry =&pAd->BATable.BARecEntry[pEntry->BARecWcidArray[j]];
2042 sprintf(pOutBuf + strlen(pOutBuf), "TID=%d, BAWinSize=%d, LastIndSeq=%d, ReorderingPkts=%d\n", j, pRecBAEntry->BAWinSize, pRecBAEntry->LastIndSeq, pRecBAEntry->list.qlen);
2045 sprintf(pOutBuf, "%s\n", pOutBuf);
2047 sprintf(pOutBuf, "%s[Originator]\n", pOutBuf);
2048 for (j=0; j < NUM_OF_TID; j++)
2050 if (pEntry->BAOriWcidArray[j] != 0)
2052 pOriBAEntry =&pAd->BATable.BAOriEntry[pEntry->BAOriWcidArray[j]];
2053 sprintf(pOutBuf + strlen(pOutBuf), "TID=%d, BAWinSize=%d, StartSeq=%d, CurTxSeq=%d\n", j, pOriBAEntry->BAWinSize, pOriBAEntry->Sequence, pEntry->TxSeq[j]);
2056 sprintf(pOutBuf, "%s\n\n", pOutBuf);
2058 if (strlen(pOutBuf) > (IW_PRIV_SIZE_MASK - 30))
2059 break;
2062 return;
2064 #endif // DOT11_N_SUPPORT //
2066 static int
2067 rt_private_show(struct net_device *dev, struct iw_request_info *info,
2068 struct iw_point *wrq, char *extra)
2070 INT Status = 0;
2071 VIRTUAL_ADAPTER *pVirtualAd = NULL;
2072 PRTMP_ADAPTER pAd;
2073 POS_COOKIE pObj;
2074 u32 subcmd = wrq->flags;
2076 if (dev->priv_flags == INT_MAIN)
2077 pAd = dev->ml_priv;
2078 else
2080 pVirtualAd = dev->ml_priv;
2081 pAd = pVirtualAd->RtmpDev->ml_priv;
2083 pObj = (POS_COOKIE) pAd->OS_Cookie;
2085 if (pAd == NULL)
2087 /* if 1st open fail, pAd will be free;
2088 So the net_dev->ml_priv will be NULL in 2rd open */
2089 return -ENETDOWN;
2092 if (extra == NULL)
2094 wrq->length = 0;
2095 return -EIO;
2097 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2100 pObj->ioctl_if_type = INT_MAIN;
2101 pObj->ioctl_if = MAIN_MBSSID;
2104 switch(subcmd)
2107 case SHOW_CONN_STATUS:
2108 if (MONITOR_ON(pAd))
2110 #ifdef DOT11_N_SUPPORT
2111 if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
2112 pAd->CommonCfg.RegTransmitSetting.field.BW)
2113 sprintf(extra, "Monitor Mode(CentralChannel %d)\n", pAd->CommonCfg.CentralChannel);
2114 else
2115 #endif // DOT11_N_SUPPORT //
2116 sprintf(extra, "Monitor Mode(Channel %d)\n", pAd->CommonCfg.Channel);
2118 else
2120 if (pAd->IndicateMediaState == NdisMediaStateConnected)
2122 if (INFRA_ON(pAd))
2124 sprintf(extra, "Connected(AP: %s[%02X:%02X:%02X:%02X:%02X:%02X])\n",
2125 pAd->CommonCfg.Ssid,
2126 pAd->CommonCfg.Bssid[0],
2127 pAd->CommonCfg.Bssid[1],
2128 pAd->CommonCfg.Bssid[2],
2129 pAd->CommonCfg.Bssid[3],
2130 pAd->CommonCfg.Bssid[4],
2131 pAd->CommonCfg.Bssid[5]);
2132 DBGPRINT(RT_DEBUG_TRACE ,("Ssid=%s ,Ssidlen = %d\n",pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen));
2134 else if (ADHOC_ON(pAd))
2135 sprintf(extra, "Connected\n");
2137 else
2139 sprintf(extra, "Disconnected\n");
2140 DBGPRINT(RT_DEBUG_TRACE ,("ConnStatus is not connected\n"));
2143 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2144 break;
2145 case SHOW_DRVIER_VERION:
2146 sprintf(extra, "Driver version-%s, %s %s\n", STA_DRIVER_VERSION, __DATE__, __TIME__ );
2147 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2148 break;
2149 #ifdef DOT11_N_SUPPORT
2150 case SHOW_BA_INFO:
2151 getBaInfo(pAd, extra);
2152 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2153 break;
2154 #endif // DOT11_N_SUPPORT //
2155 case SHOW_DESC_INFO:
2157 Show_DescInfo_Proc(pAd, NULL);
2158 wrq->length = 0; // 1: size of '\0'
2160 break;
2161 case RAIO_OFF:
2162 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
2164 sprintf(extra, "Scanning\n");
2165 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2166 break;
2168 pAd->StaCfg.bSwRadio = FALSE;
2169 if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
2171 pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
2172 if (pAd->StaCfg.bRadio == FALSE)
2174 MlmeRadioOff(pAd);
2175 // Update extra information
2176 pAd->ExtraInfo = SW_RADIO_OFF;
2179 sprintf(extra, "Radio Off\n");
2180 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2181 break;
2182 case RAIO_ON:
2183 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
2185 sprintf(extra, "Scanning\n");
2186 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2187 break;
2189 pAd->StaCfg.bSwRadio = TRUE;
2190 //if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
2192 pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
2193 if (pAd->StaCfg.bRadio == TRUE)
2195 MlmeRadioOn(pAd);
2196 // Update extra information
2197 pAd->ExtraInfo = EXTRA_INFO_CLEAR;
2200 sprintf(extra, "Radio On\n");
2201 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2202 break;
2205 #ifdef QOS_DLS_SUPPORT
2206 case SHOW_DLS_ENTRY_INFO:
2208 Set_DlsEntryInfo_Display_Proc(pAd, NULL);
2209 wrq->length = 0; // 1: size of '\0'
2211 break;
2212 #endif // QOS_DLS_SUPPORT //
2214 case SHOW_CFG_VALUE:
2216 Status = RTMPShowCfgValue(pAd, wrq->pointer, extra);
2217 if (Status == 0)
2218 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2220 break;
2221 case SHOW_ADHOC_ENTRY_INFO:
2222 Show_Adhoc_MacTable_Proc(pAd, extra);
2223 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2224 break;
2225 default:
2226 DBGPRINT(RT_DEBUG_TRACE, ("%s - unknow subcmd = %d\n", __func__, subcmd));
2227 break;
2230 return Status;
2233 #ifdef SIOCSIWMLME
2234 int rt_ioctl_siwmlme(struct net_device *dev,
2235 struct iw_request_info *info,
2236 union iwreq_data *wrqu,
2237 char *extra)
2239 PRTMP_ADAPTER pAd = dev->ml_priv;
2240 struct iw_mlme *pMlme = (struct iw_mlme *)wrqu->data.pointer;
2241 MLME_QUEUE_ELEM MsgElem;
2242 MLME_DISASSOC_REQ_STRUCT DisAssocReq;
2243 MLME_DEAUTH_REQ_STRUCT DeAuthReq;
2245 DBGPRINT(RT_DEBUG_TRACE, ("====> %s\n", __func__));
2247 if (pMlme == NULL)
2248 return -EINVAL;
2250 switch(pMlme->cmd)
2252 #ifdef IW_MLME_DEAUTH
2253 case IW_MLME_DEAUTH:
2254 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DEAUTH\n", __func__));
2255 COPY_MAC_ADDR(DeAuthReq.Addr, pAd->CommonCfg.Bssid);
2256 DeAuthReq.Reason = pMlme->reason_code;
2257 MsgElem.MsgLen = sizeof(MLME_DEAUTH_REQ_STRUCT);
2258 NdisMoveMemory(MsgElem.Msg, &DeAuthReq, sizeof(MLME_DEAUTH_REQ_STRUCT));
2259 MlmeDeauthReqAction(pAd, &MsgElem);
2260 if (INFRA_ON(pAd))
2262 LinkDown(pAd, FALSE);
2263 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
2265 break;
2266 #endif // IW_MLME_DEAUTH //
2267 #ifdef IW_MLME_DISASSOC
2268 case IW_MLME_DISASSOC:
2269 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DISASSOC\n", __func__));
2270 COPY_MAC_ADDR(DisAssocReq.Addr, pAd->CommonCfg.Bssid);
2271 DisAssocReq.Reason = pMlme->reason_code;
2273 MsgElem.Machine = ASSOC_STATE_MACHINE;
2274 MsgElem.MsgType = MT2_MLME_DISASSOC_REQ;
2275 MsgElem.MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
2276 NdisMoveMemory(MsgElem.Msg, &DisAssocReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
2278 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
2279 MlmeDisassocReqAction(pAd, &MsgElem);
2280 break;
2281 #endif // IW_MLME_DISASSOC //
2282 default:
2283 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - Unknow Command\n", __func__));
2284 break;
2287 return 0;
2289 #endif // SIOCSIWMLME //
2291 #if WIRELESS_EXT > 17
2292 int rt_ioctl_siwauth(struct net_device *dev,
2293 struct iw_request_info *info,
2294 union iwreq_data *wrqu, char *extra)
2296 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2297 struct iw_param *param = &wrqu->param;
2299 //check if the interface is down
2300 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2302 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2303 return -ENETDOWN;
2305 switch (param->flags & IW_AUTH_INDEX) {
2306 case IW_AUTH_WPA_VERSION:
2307 if (param->value == IW_AUTH_WPA_VERSION_WPA)
2309 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
2310 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
2311 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
2313 else if (param->value == IW_AUTH_WPA_VERSION_WPA2)
2314 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
2316 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __func__, param->value));
2317 break;
2318 case IW_AUTH_CIPHER_PAIRWISE:
2319 if (param->value == IW_AUTH_CIPHER_NONE)
2321 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
2322 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2323 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
2325 else if (param->value == IW_AUTH_CIPHER_WEP40 ||
2326 param->value == IW_AUTH_CIPHER_WEP104)
2328 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
2329 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2330 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
2331 #ifdef WPA_SUPPLICANT_SUPPORT
2332 pAdapter->StaCfg.IEEE8021X = FALSE;
2333 #endif // WPA_SUPPLICANT_SUPPORT //
2335 else if (param->value == IW_AUTH_CIPHER_TKIP)
2337 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
2338 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2339 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
2341 else if (param->value == IW_AUTH_CIPHER_CCMP)
2343 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
2344 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2345 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
2347 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_PAIRWISE - param->value = %d!\n", __func__, param->value));
2348 break;
2349 case IW_AUTH_CIPHER_GROUP:
2350 if (param->value == IW_AUTH_CIPHER_NONE)
2352 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
2354 else if (param->value == IW_AUTH_CIPHER_WEP40 ||
2355 param->value == IW_AUTH_CIPHER_WEP104)
2357 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
2359 else if (param->value == IW_AUTH_CIPHER_TKIP)
2361 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
2363 else if (param->value == IW_AUTH_CIPHER_CCMP)
2365 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
2367 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_GROUP - param->value = %d!\n", __func__, param->value));
2368 break;
2369 case IW_AUTH_KEY_MGMT:
2370 if (param->value == IW_AUTH_KEY_MGMT_802_1X)
2372 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)
2374 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
2375 #ifdef WPA_SUPPLICANT_SUPPORT
2376 pAdapter->StaCfg.IEEE8021X = FALSE;
2377 #endif // WPA_SUPPLICANT_SUPPORT //
2379 else if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
2381 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
2382 #ifdef WPA_SUPPLICANT_SUPPORT
2383 pAdapter->StaCfg.IEEE8021X = FALSE;
2384 #endif // WPA_SUPPLICANT_SUPPORT //
2386 #ifdef WPA_SUPPLICANT_SUPPORT
2387 else
2388 // WEP 1x
2389 pAdapter->StaCfg.IEEE8021X = TRUE;
2390 #endif // WPA_SUPPLICANT_SUPPORT //
2392 else if (param->value == 0)
2394 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2395 STA_PORT_SECURED(pAdapter);
2397 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_KEY_MGMT - param->value = %d!\n", __func__, param->value));
2398 break;
2399 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
2400 break;
2401 case IW_AUTH_PRIVACY_INVOKED:
2402 /*if (param->value == 0)
2404 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
2405 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
2406 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2407 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
2408 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
2410 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_PRIVACY_INVOKED - param->value = %d!\n", __func__, param->value));
2411 break;
2412 case IW_AUTH_DROP_UNENCRYPTED:
2413 if (param->value != 0)
2414 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
2415 else
2417 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2418 STA_PORT_SECURED(pAdapter);
2420 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __func__, param->value));
2421 break;
2422 case IW_AUTH_80211_AUTH_ALG:
2423 if (param->value & IW_AUTH_ALG_SHARED_KEY)
2425 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
2427 else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
2429 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
2431 else
2432 return -EINVAL;
2433 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_80211_AUTH_ALG - param->value = %d!\n", __func__, param->value));
2434 break;
2435 case IW_AUTH_WPA_ENABLED:
2436 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_ENABLED - Driver supports WPA!(param->value = %d)\n", __func__, param->value));
2437 break;
2438 default:
2439 return -EOPNOTSUPP;
2442 return 0;
2445 int rt_ioctl_giwauth(struct net_device *dev,
2446 struct iw_request_info *info,
2447 union iwreq_data *wrqu, char *extra)
2449 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2450 struct iw_param *param = &wrqu->param;
2452 //check if the interface is down
2453 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2455 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2456 return -ENETDOWN;
2459 switch (param->flags & IW_AUTH_INDEX) {
2460 case IW_AUTH_DROP_UNENCRYPTED:
2461 param->value = (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled) ? 0 : 1;
2462 break;
2464 case IW_AUTH_80211_AUTH_ALG:
2465 param->value = (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared) ? IW_AUTH_ALG_SHARED_KEY : IW_AUTH_ALG_OPEN_SYSTEM;
2466 break;
2468 case IW_AUTH_WPA_ENABLED:
2469 param->value = (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) ? 1 : 0;
2470 break;
2472 default:
2473 return -EOPNOTSUPP;
2475 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_giwauth::param->value = %d!\n", param->value));
2476 return 0;
2479 void fnSetCipherKey(
2480 IN PRTMP_ADAPTER pAdapter,
2481 IN INT keyIdx,
2482 IN UCHAR CipherAlg,
2483 IN BOOLEAN bGTK,
2484 IN struct iw_encode_ext *ext)
2486 NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
2487 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = LEN_TKIP_EK;
2488 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, LEN_TKIP_EK);
2489 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].TxMic, ext->key + LEN_TKIP_EK, LEN_TKIP_TXMICK);
2490 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].RxMic, ext->key + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
2491 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CipherAlg;
2493 // Update group key information to ASIC Shared Key Table
2494 AsicAddSharedKeyEntry(pAdapter,
2495 BSS0,
2496 keyIdx,
2497 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2498 pAdapter->SharedKey[BSS0][keyIdx].Key,
2499 pAdapter->SharedKey[BSS0][keyIdx].TxMic,
2500 pAdapter->SharedKey[BSS0][keyIdx].RxMic);
2502 if (bGTK)
2503 // Update ASIC WCID attribute table and IVEIV table
2504 RTMPAddWcidAttributeEntry(pAdapter,
2505 BSS0,
2506 keyIdx,
2507 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2508 NULL);
2509 else
2510 // Update ASIC WCID attribute table and IVEIV table
2511 RTMPAddWcidAttributeEntry(pAdapter,
2512 BSS0,
2513 keyIdx,
2514 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2515 &pAdapter->MacTab.Content[BSSID_WCID]);
2518 int rt_ioctl_siwencodeext(struct net_device *dev,
2519 struct iw_request_info *info,
2520 union iwreq_data *wrqu,
2521 char *extra)
2523 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2524 struct iw_point *encoding = &wrqu->encoding;
2525 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2526 int keyIdx, alg = ext->alg;
2528 //check if the interface is down
2529 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2531 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2532 return -ENETDOWN;
2535 if (encoding->flags & IW_ENCODE_DISABLED)
2537 keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
2538 // set BSSID wcid entry of the Pair-wise Key table as no-security mode
2539 AsicRemovePairwiseKeyEntry(pAdapter, BSS0, BSSID_WCID);
2540 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
2541 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_NONE;
2542 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)keyIdx);
2543 NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
2544 DBGPRINT(RT_DEBUG_TRACE, ("%s::Remove all keys!(encoding->flags = %x)\n", __func__, encoding->flags));
2546 else
2548 // Get Key Index and convet to our own defined key index
2549 keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
2550 if((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
2551 return -EINVAL;
2553 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2555 pAdapter->StaCfg.DefaultKeyId = keyIdx;
2556 DBGPRINT(RT_DEBUG_TRACE, ("%s::DefaultKeyId = %d\n", __func__, pAdapter->StaCfg.DefaultKeyId));
2559 switch (alg) {
2560 case IW_ENCODE_ALG_NONE:
2561 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_NONE\n", __func__));
2562 break;
2563 case IW_ENCODE_ALG_WEP:
2564 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_WEP - ext->key_len = %d, keyIdx = %d\n", __func__, ext->key_len, keyIdx));
2565 if (ext->key_len == MAX_WEP_KEY_SIZE)
2567 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
2568 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
2570 else if (ext->key_len == MIN_WEP_KEY_SIZE)
2572 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
2573 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
2575 else
2576 return -EINVAL;
2578 NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
2579 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, ext->key_len);
2581 if (pAdapter->StaCfg.GroupCipher == Ndis802_11GroupWEP40Enabled ||
2582 pAdapter->StaCfg.GroupCipher == Ndis802_11GroupWEP104Enabled)
2584 // Set Group key material to Asic
2585 AsicAddSharedKeyEntry(pAdapter, BSS0, keyIdx, pAdapter->SharedKey[BSS0][keyIdx].CipherAlg, pAdapter->SharedKey[BSS0][keyIdx].Key, NULL, NULL);
2587 // Update WCID attribute table and IVEIV table for this group key table
2588 RTMPAddWcidAttributeEntry(pAdapter, BSS0, keyIdx, pAdapter->SharedKey[BSS0][keyIdx].CipherAlg, NULL);
2590 STA_PORT_SECURED(pAdapter);
2592 // Indicate Connected for GUI
2593 pAdapter->IndicateMediaState = NdisMediaStateConnected;
2595 break;
2596 case IW_ENCODE_ALG_TKIP:
2597 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_TKIP - keyIdx = %d, ext->key_len = %d\n", __func__, keyIdx, ext->key_len));
2598 if (ext->key_len == 32)
2600 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2602 fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, FALSE, ext);
2603 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
2605 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2606 STA_PORT_SECURED(pAdapter);
2609 else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
2611 fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, TRUE, ext);
2613 // set 802.1x port control
2614 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2615 STA_PORT_SECURED(pAdapter);
2618 else
2619 return -EINVAL;
2620 break;
2621 case IW_ENCODE_ALG_CCMP:
2622 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2624 fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, FALSE, ext);
2625 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
2626 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2627 STA_PORT_SECURED(pAdapter);
2629 else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
2631 fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, TRUE, ext);
2633 // set 802.1x port control
2634 //pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2635 STA_PORT_SECURED(pAdapter);
2637 break;
2638 default:
2639 return -EINVAL;
2643 return 0;
2647 rt_ioctl_giwencodeext(struct net_device *dev,
2648 struct iw_request_info *info,
2649 union iwreq_data *wrqu, char *extra)
2651 PRTMP_ADAPTER pAd = dev->ml_priv;
2652 PCHAR pKey = NULL;
2653 struct iw_point *encoding = &wrqu->encoding;
2654 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2655 int idx, max_key_len;
2657 DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_giwencodeext\n"));
2659 max_key_len = encoding->length - sizeof(*ext);
2660 if (max_key_len < 0)
2661 return -EINVAL;
2663 idx = encoding->flags & IW_ENCODE_INDEX;
2664 if (idx)
2666 if (idx < 1 || idx > 4)
2667 return -EINVAL;
2668 idx--;
2670 if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
2671 (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled))
2673 if (idx != pAd->StaCfg.DefaultKeyId)
2675 ext->key_len = 0;
2676 return 0;
2680 else
2681 idx = pAd->StaCfg.DefaultKeyId;
2683 encoding->flags = idx + 1;
2684 memset(ext, 0, sizeof(*ext));
2686 ext->key_len = 0;
2687 switch(pAd->StaCfg.WepStatus) {
2688 case Ndis802_11WEPDisabled:
2689 ext->alg = IW_ENCODE_ALG_NONE;
2690 encoding->flags |= IW_ENCODE_DISABLED;
2691 break;
2692 case Ndis802_11WEPEnabled:
2693 ext->alg = IW_ENCODE_ALG_WEP;
2694 if (pAd->SharedKey[BSS0][idx].KeyLen > max_key_len)
2695 return -E2BIG;
2696 else
2698 ext->key_len = pAd->SharedKey[BSS0][idx].KeyLen;
2699 pKey = &(pAd->SharedKey[BSS0][idx].Key[0]);
2701 break;
2702 case Ndis802_11Encryption2Enabled:
2703 case Ndis802_11Encryption3Enabled:
2704 if (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
2705 ext->alg = IW_ENCODE_ALG_TKIP;
2706 else
2707 ext->alg = IW_ENCODE_ALG_CCMP;
2709 if (max_key_len < 32)
2710 return -E2BIG;
2711 else
2713 ext->key_len = 32;
2714 pKey = &pAd->StaCfg.PMK[0];
2716 break;
2717 default:
2718 return -EINVAL;
2721 if (ext->key_len && pKey)
2723 encoding->flags |= IW_ENCODE_ENABLED;
2724 memcpy(ext->key, pKey, ext->key_len);
2727 return 0;
2730 #ifdef SIOCSIWGENIE
2731 int rt_ioctl_siwgenie(struct net_device *dev,
2732 struct iw_request_info *info,
2733 union iwreq_data *wrqu, char *extra)
2735 PRTMP_ADAPTER pAd = dev->ml_priv;
2737 if (wrqu->data.length > MAX_LEN_OF_RSNIE ||
2738 (wrqu->data.length && extra == NULL))
2739 return -EINVAL;
2741 if (wrqu->data.length)
2743 pAd->StaCfg.RSNIE_Len = wrqu->data.length;
2744 NdisMoveMemory(&pAd->StaCfg.RSN_IE[0], extra, pAd->StaCfg.RSNIE_Len);
2746 else
2748 pAd->StaCfg.RSNIE_Len = 0;
2749 NdisZeroMemory(&pAd->StaCfg.RSN_IE[0], MAX_LEN_OF_RSNIE);
2752 return 0;
2754 #endif // SIOCSIWGENIE //
2756 int rt_ioctl_giwgenie(struct net_device *dev,
2757 struct iw_request_info *info,
2758 union iwreq_data *wrqu, char *extra)
2760 PRTMP_ADAPTER pAd = dev->ml_priv;
2762 if ((pAd->StaCfg.RSNIE_Len == 0) ||
2763 (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA))
2765 wrqu->data.length = 0;
2766 return 0;
2769 #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
2770 #ifdef SIOCSIWGENIE
2771 if (pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
2773 if (wrqu->data.length < pAd->StaCfg.RSNIE_Len)
2774 return -E2BIG;
2776 wrqu->data.length = pAd->StaCfg.RSNIE_Len;
2777 memcpy(extra, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
2779 else
2780 #endif // SIOCSIWGENIE //
2781 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
2783 UCHAR RSNIe = IE_WPA;
2785 if (wrqu->data.length < (pAd->StaCfg.RSNIE_Len + 2)) // ID, Len
2786 return -E2BIG;
2787 wrqu->data.length = pAd->StaCfg.RSNIE_Len + 2;
2789 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
2790 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2))
2791 RSNIe = IE_RSN;
2793 extra[0] = (char)RSNIe;
2794 extra[1] = pAd->StaCfg.RSNIE_Len;
2795 memcpy(extra+2, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
2798 return 0;
2801 int rt_ioctl_siwpmksa(struct net_device *dev,
2802 struct iw_request_info *info,
2803 union iwreq_data *wrqu,
2804 char *extra)
2806 PRTMP_ADAPTER pAd = dev->ml_priv;
2807 struct iw_pmksa *pPmksa = (struct iw_pmksa *)wrqu->data.pointer;
2808 INT CachedIdx = 0, idx = 0;
2810 if (pPmksa == NULL)
2811 return -EINVAL;
2813 DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_siwpmksa\n"));
2814 switch(pPmksa->cmd)
2816 case IW_PMKSA_FLUSH:
2817 NdisZeroMemory(pAd->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
2818 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_FLUSH\n"));
2819 break;
2820 case IW_PMKSA_REMOVE:
2821 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
2823 // compare the BSSID
2824 if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
2826 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN);
2827 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].PMKID, 16);
2828 for (idx = CachedIdx; idx < (pAd->StaCfg.SavedPMKNum - 1); idx++)
2830 NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].BSSID[0], &pAd->StaCfg.SavedPMK[idx+1].BSSID[0], MAC_ADDR_LEN);
2831 NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].PMKID[0], &pAd->StaCfg.SavedPMK[idx+1].PMKID[0], 16);
2833 pAd->StaCfg.SavedPMKNum--;
2834 break;
2838 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_REMOVE\n"));
2839 break;
2840 case IW_PMKSA_ADD:
2841 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
2843 // compare the BSSID
2844 if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
2845 break;
2848 // Found, replace it
2849 if (CachedIdx < PMKID_NO)
2851 DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
2852 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
2853 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
2854 pAd->StaCfg.SavedPMKNum++;
2856 // Not found, replace the last one
2857 else
2859 // Randomly replace one
2860 CachedIdx = (pPmksa->bssid.sa_data[5] % PMKID_NO);
2861 DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
2862 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
2863 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
2866 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_ADD\n"));
2867 break;
2868 default:
2869 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - Unknow Command!!\n"));
2870 break;
2873 return 0;
2875 #endif // #if WIRELESS_EXT > 17
2877 #ifdef DBG
2878 static int
2879 rt_private_ioctl_bbp(struct net_device *dev, struct iw_request_info *info,
2880 struct iw_point *wrq, char *extra)
2882 CHAR *this_char;
2883 CHAR *value = NULL;
2884 UCHAR regBBP = 0;
2885 // CHAR arg[255]={0};
2886 UINT32 bbpId;
2887 UINT32 bbpValue;
2888 BOOLEAN bIsPrintAllBBP = FALSE;
2889 INT Status = 0;
2890 PRTMP_ADAPTER pAdapter = dev->ml_priv;
2893 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2895 if (wrq->length > 1) //No parameters.
2897 sprintf(extra, "\n");
2899 //Parsing Read or Write
2900 this_char = wrq->pointer;
2901 DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s\n", this_char));
2902 if (!*this_char)
2903 goto next;
2905 if ((value = rtstrchr(this_char, '=')) != NULL)
2906 *value++ = 0;
2908 if (!value || !*value)
2909 { //Read
2910 DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s, value=%s\n", this_char, value));
2911 if (sscanf(this_char, "%d", &(bbpId)) == 1)
2913 if (bbpId <= 136)
2915 #ifdef RALINK_ATE
2916 if (ATE_ON(pAdapter))
2918 ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
2920 else
2921 #endif // RALINK_ATE //
2923 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
2925 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
2926 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2927 DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
2929 else
2930 {//Invalid parametes, so default printk all bbp
2931 bIsPrintAllBBP = TRUE;
2932 goto next;
2935 else
2936 { //Invalid parametes, so default printk all bbp
2937 bIsPrintAllBBP = TRUE;
2938 goto next;
2941 else
2942 { //Write
2943 if ((sscanf(this_char, "%d", &(bbpId)) == 1) && (sscanf(value, "%x", &(bbpValue)) == 1))
2945 if (bbpId <= 136)
2947 #ifdef RALINK_ATE
2948 if (ATE_ON(pAdapter))
2950 ATE_BBP_IO_WRITE8_BY_REG_ID(pAdapter, bbpId, bbpValue);
2951 //Read it back for showing
2952 ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
2954 else
2955 #endif // RALINK_ATE //
2957 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, bbpId, bbpValue);
2958 //Read it back for showing
2959 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
2961 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
2962 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2963 DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
2965 else
2966 {//Invalid parametes, so default printk all bbp
2967 bIsPrintAllBBP = TRUE;
2968 goto next;
2971 else
2972 { //Invalid parametes, so default printk all bbp
2973 bIsPrintAllBBP = TRUE;
2974 goto next;
2978 else
2979 bIsPrintAllBBP = TRUE;
2981 next:
2982 if (bIsPrintAllBBP)
2984 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2985 sprintf(extra, "\n");
2986 for (bbpId = 0; bbpId <= 136; bbpId++)
2988 if (strlen(extra) >= (IW_PRIV_SIZE_MASK - 10))
2989 break;
2990 #ifdef RALINK_ATE
2991 if (ATE_ON(pAdapter))
2993 ATE_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
2995 else
2996 #endif // RALINK_ATE //
2997 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
2998 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X ", bbpId, bbpId*2, regBBP);
2999 if (bbpId%5 == 4)
3000 sprintf(extra+strlen(extra), "\n");
3003 wrq->length = strlen(extra) + 1; // 1: size of '\0'
3004 DBGPRINT(RT_DEBUG_TRACE, ("wrq->length = %d\n", wrq->length));
3007 DBGPRINT(RT_DEBUG_TRACE, ("<==rt_private_ioctl_bbp\n\n"));
3009 return Status;
3011 #endif // DBG //
3013 int rt_ioctl_siwrate(struct net_device *dev,
3014 struct iw_request_info *info,
3015 union iwreq_data *wrqu, char *extra)
3017 PRTMP_ADAPTER pAd = dev->ml_priv;
3018 UINT32 rate = wrqu->bitrate.value, fixed = wrqu->bitrate.fixed;
3020 //check if the interface is down
3021 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
3023 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::Network is down!\n"));
3024 return -ENETDOWN;
3027 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(rate = %d, fixed = %d)\n", rate, fixed));
3028 /* rate = -1 => auto rate
3029 rate = X, fixed = 1 => (fixed rate X)
3031 if (rate == -1)
3033 //Auto Rate
3034 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
3035 pAd->StaCfg.bAutoTxRateSwitch = TRUE;
3036 if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
3037 (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
3038 RTMPSetDesiredRates(pAd, -1);
3040 #ifdef DOT11_N_SUPPORT
3041 SetCommonHT(pAd);
3042 #endif // DOT11_N_SUPPORT //
3044 else
3046 if (fixed)
3048 pAd->StaCfg.bAutoTxRateSwitch = FALSE;
3049 if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
3050 (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
3051 RTMPSetDesiredRates(pAd, rate);
3052 else
3054 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
3055 #ifdef DOT11_N_SUPPORT
3056 SetCommonHT(pAd);
3057 #endif // DOT11_N_SUPPORT //
3059 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(HtMcs=%d)\n",pAd->StaCfg.DesiredTransmitSetting.field.MCS));
3061 else
3063 // TODO: rate = X, fixed = 0 => (rates <= X)
3064 return -EOPNOTSUPP;
3068 return 0;
3071 int rt_ioctl_giwrate(struct net_device *dev,
3072 struct iw_request_info *info,
3073 union iwreq_data *wrqu, char *extra)
3075 PRTMP_ADAPTER pAd = dev->ml_priv;
3076 int rate_index = 0, rate_count = 0;
3077 HTTRANSMIT_SETTING ht_setting;
3078 __s32 ralinkrate[] =
3079 {2, 4, 11, 22, // CCK
3080 12, 18, 24, 36, 48, 72, 96, 108, // OFDM
3081 13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260, // 20MHz, 800ns GI, MCS: 0 ~ 15
3082 39, 78, 117, 156, 234, 312, 351, 390, // 20MHz, 800ns GI, MCS: 16 ~ 23
3083 27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540, // 40MHz, 800ns GI, MCS: 0 ~ 15
3084 81, 162, 243, 324, 486, 648, 729, 810, // 40MHz, 800ns GI, MCS: 16 ~ 23
3085 14, 29, 43, 57, 87, 115, 130, 144, 29, 59, 87, 115, 173, 230, 260, 288, // 20MHz, 400ns GI, MCS: 0 ~ 15
3086 43, 87, 130, 173, 260, 317, 390, 433, // 20MHz, 400ns GI, MCS: 16 ~ 23
3087 30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600, // 40MHz, 400ns GI, MCS: 0 ~ 15
3088 90, 180, 270, 360, 540, 720, 810, 900}; // 40MHz, 400ns GI, MCS: 16 ~ 23
3090 rate_count = sizeof(ralinkrate)/sizeof(__s32);
3091 //check if the interface is down
3092 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
3094 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
3095 return -ENETDOWN;
3098 if ((pAd->StaCfg.bAutoTxRateSwitch == FALSE) &&
3099 (INFRA_ON(pAd)) &&
3100 ((pAd->CommonCfg.PhyMode <= PHY_11G) || (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM)))
3101 ht_setting.word = pAd->StaCfg.HTPhyMode.word;
3102 else
3103 ht_setting.word = pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word;
3105 #ifdef DOT11_N_SUPPORT
3106 if (ht_setting.field.MODE >= MODE_HTMIX)
3108 // rate_index = 12 + ((UCHAR)ht_setting.field.BW *16) + ((UCHAR)ht_setting.field.ShortGI *32) + ((UCHAR)ht_setting.field.MCS);
3109 rate_index = 12 + ((UCHAR)ht_setting.field.BW *24) + ((UCHAR)ht_setting.field.ShortGI *48) + ((UCHAR)ht_setting.field.MCS);
3111 else
3112 #endif // DOT11_N_SUPPORT //
3113 if (ht_setting.field.MODE == MODE_OFDM)
3114 rate_index = (UCHAR)(ht_setting.field.MCS) + 4;
3115 else if (ht_setting.field.MODE == MODE_CCK)
3116 rate_index = (UCHAR)(ht_setting.field.MCS);
3118 if (rate_index < 0)
3119 rate_index = 0;
3121 if (rate_index > rate_count)
3122 rate_index = rate_count;
3124 wrqu->bitrate.value = ralinkrate[rate_index] * 500000;
3125 wrqu->bitrate.disabled = 0;
3127 return 0;
3130 static const iw_handler rt_handler[] =
3132 (iw_handler) NULL, /* SIOCSIWCOMMIT */
3133 (iw_handler) rt_ioctl_giwname, /* SIOCGIWNAME */
3134 (iw_handler) NULL, /* SIOCSIWNWID */
3135 (iw_handler) NULL, /* SIOCGIWNWID */
3136 (iw_handler) rt_ioctl_siwfreq, /* SIOCSIWFREQ */
3137 (iw_handler) rt_ioctl_giwfreq, /* SIOCGIWFREQ */
3138 (iw_handler) rt_ioctl_siwmode, /* SIOCSIWMODE */
3139 (iw_handler) rt_ioctl_giwmode, /* SIOCGIWMODE */
3140 (iw_handler) NULL, /* SIOCSIWSENS */
3141 (iw_handler) NULL, /* SIOCGIWSENS */
3142 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
3143 (iw_handler) rt_ioctl_giwrange, /* SIOCGIWRANGE */
3144 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
3145 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
3146 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
3147 (iw_handler) rt28xx_get_wireless_stats /* kernel code */, /* SIOCGIWSTATS */
3148 (iw_handler) NULL, /* SIOCSIWSPY */
3149 (iw_handler) NULL, /* SIOCGIWSPY */
3150 (iw_handler) NULL, /* SIOCSIWTHRSPY */
3151 (iw_handler) NULL, /* SIOCGIWTHRSPY */
3152 (iw_handler) rt_ioctl_siwap, /* SIOCSIWAP */
3153 (iw_handler) rt_ioctl_giwap, /* SIOCGIWAP */
3154 #ifdef SIOCSIWMLME
3155 (iw_handler) rt_ioctl_siwmlme, /* SIOCSIWMLME */
3156 #else
3157 (iw_handler) NULL, /* SIOCSIWMLME */
3158 #endif // SIOCSIWMLME //
3159 (iw_handler) rt_ioctl_iwaplist, /* SIOCGIWAPLIST */
3160 #ifdef SIOCGIWSCAN
3161 (iw_handler) rt_ioctl_siwscan, /* SIOCSIWSCAN */
3162 (iw_handler) rt_ioctl_giwscan, /* SIOCGIWSCAN */
3163 #else
3164 (iw_handler) NULL, /* SIOCSIWSCAN */
3165 (iw_handler) NULL, /* SIOCGIWSCAN */
3166 #endif /* SIOCGIWSCAN */
3167 (iw_handler) rt_ioctl_siwessid, /* SIOCSIWESSID */
3168 (iw_handler) rt_ioctl_giwessid, /* SIOCGIWESSID */
3169 (iw_handler) rt_ioctl_siwnickn, /* SIOCSIWNICKN */
3170 (iw_handler) rt_ioctl_giwnickn, /* SIOCGIWNICKN */
3171 (iw_handler) NULL, /* -- hole -- */
3172 (iw_handler) NULL, /* -- hole -- */
3173 (iw_handler) rt_ioctl_siwrate, /* SIOCSIWRATE */
3174 (iw_handler) rt_ioctl_giwrate, /* SIOCGIWRATE */
3175 (iw_handler) rt_ioctl_siwrts, /* SIOCSIWRTS */
3176 (iw_handler) rt_ioctl_giwrts, /* SIOCGIWRTS */
3177 (iw_handler) rt_ioctl_siwfrag, /* SIOCSIWFRAG */
3178 (iw_handler) rt_ioctl_giwfrag, /* SIOCGIWFRAG */
3179 (iw_handler) NULL, /* SIOCSIWTXPOW */
3180 (iw_handler) NULL, /* SIOCGIWTXPOW */
3181 (iw_handler) NULL, /* SIOCSIWRETRY */
3182 (iw_handler) NULL, /* SIOCGIWRETRY */
3183 (iw_handler) rt_ioctl_siwencode, /* SIOCSIWENCODE */
3184 (iw_handler) rt_ioctl_giwencode, /* SIOCGIWENCODE */
3185 (iw_handler) NULL, /* SIOCSIWPOWER */
3186 (iw_handler) NULL, /* SIOCGIWPOWER */
3187 (iw_handler) NULL, /* -- hole -- */
3188 (iw_handler) NULL, /* -- hole -- */
3189 #if WIRELESS_EXT > 17
3190 (iw_handler) rt_ioctl_siwgenie, /* SIOCSIWGENIE */
3191 (iw_handler) rt_ioctl_giwgenie, /* SIOCGIWGENIE */
3192 (iw_handler) rt_ioctl_siwauth, /* SIOCSIWAUTH */
3193 (iw_handler) rt_ioctl_giwauth, /* SIOCGIWAUTH */
3194 (iw_handler) rt_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
3195 (iw_handler) rt_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */
3196 (iw_handler) rt_ioctl_siwpmksa, /* SIOCSIWPMKSA */
3197 #endif
3200 static const iw_handler rt_priv_handlers[] = {
3201 (iw_handler) NULL, /* + 0x00 */
3202 (iw_handler) NULL, /* + 0x01 */
3203 #ifndef CONFIG_AP_SUPPORT
3204 (iw_handler) rt_ioctl_setparam, /* + 0x02 */
3205 #else
3206 (iw_handler) NULL, /* + 0x02 */
3207 #endif // CONFIG_AP_SUPPORT //
3208 #ifdef DBG
3209 (iw_handler) rt_private_ioctl_bbp, /* + 0x03 */
3210 #else
3211 (iw_handler) NULL, /* + 0x03 */
3212 #endif
3213 (iw_handler) NULL, /* + 0x04 */
3214 (iw_handler) NULL, /* + 0x05 */
3215 (iw_handler) NULL, /* + 0x06 */
3216 (iw_handler) NULL, /* + 0x07 */
3217 (iw_handler) NULL, /* + 0x08 */
3218 (iw_handler) rt_private_get_statistics, /* + 0x09 */
3219 (iw_handler) NULL, /* + 0x0A */
3220 (iw_handler) NULL, /* + 0x0B */
3221 (iw_handler) NULL, /* + 0x0C */
3222 (iw_handler) NULL, /* + 0x0D */
3223 (iw_handler) NULL, /* + 0x0E */
3224 (iw_handler) NULL, /* + 0x0F */
3225 (iw_handler) NULL, /* + 0x10 */
3226 (iw_handler) rt_private_show, /* + 0x11 */
3227 (iw_handler) NULL, /* + 0x12 */
3228 (iw_handler) NULL, /* + 0x13 */
3229 (iw_handler) NULL, /* + 0x15 */
3230 (iw_handler) NULL, /* + 0x17 */
3231 (iw_handler) NULL, /* + 0x18 */
3234 const struct iw_handler_def rt28xx_iw_handler_def =
3236 #define N(a) (sizeof (a) / sizeof (a[0]))
3237 .standard = (iw_handler *) rt_handler,
3238 .num_standard = sizeof(rt_handler) / sizeof(iw_handler),
3239 .private = (iw_handler *) rt_priv_handlers,
3240 .num_private = N(rt_priv_handlers),
3241 .private_args = (struct iw_priv_args *) privtab,
3242 .num_private_args = N(privtab),
3243 #if IW_HANDLER_VERSION >= 7
3244 .get_wireless_stats = rt28xx_get_wireless_stats,
3245 #endif
3248 INT RTMPSetInformation(
3249 IN PRTMP_ADAPTER pAdapter,
3250 IN OUT struct ifreq *rq,
3251 IN INT cmd)
3253 struct iwreq *wrq = (struct iwreq *) rq;
3254 NDIS_802_11_SSID Ssid;
3255 NDIS_802_11_MAC_ADDRESS Bssid;
3256 RT_802_11_PHY_MODE PhyMode;
3257 RT_802_11_STA_CONFIG StaConfig;
3258 NDIS_802_11_RATES aryRates;
3259 RT_802_11_PREAMBLE Preamble;
3260 NDIS_802_11_WEP_STATUS WepStatus;
3261 NDIS_802_11_AUTHENTICATION_MODE AuthMode = Ndis802_11AuthModeMax;
3262 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
3263 NDIS_802_11_RTS_THRESHOLD RtsThresh;
3264 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
3265 NDIS_802_11_POWER_MODE PowerMode;
3266 PNDIS_802_11_KEY pKey = NULL;
3267 PNDIS_802_11_WEP pWepKey =NULL;
3268 PNDIS_802_11_REMOVE_KEY pRemoveKey = NULL;
3269 NDIS_802_11_CONFIGURATION Config, *pConfig = NULL;
3270 NDIS_802_11_NETWORK_TYPE NetType;
3271 ULONG Now;
3272 UINT KeyIdx = 0;
3273 INT Status = NDIS_STATUS_SUCCESS, MaxPhyMode = PHY_11G;
3274 ULONG PowerTemp;
3275 BOOLEAN RadioState;
3276 BOOLEAN StateMachineTouched = FALSE;
3277 #ifdef DOT11_N_SUPPORT
3278 OID_SET_HT_PHYMODE HT_PhyMode; //11n ,kathy
3279 #endif // DOT11_N_SUPPORT //
3280 #ifdef WPA_SUPPLICANT_SUPPORT
3281 PNDIS_802_11_PMKID pPmkId = NULL;
3282 BOOLEAN IEEE8021xState = FALSE;
3283 BOOLEAN IEEE8021x_required_keys = FALSE;
3284 UCHAR wpa_supplicant_enable = 0;
3285 #endif // WPA_SUPPLICANT_SUPPORT //
3287 #ifdef SNMP_SUPPORT
3288 TX_RTY_CFG_STRUC tx_rty_cfg;
3289 ULONG ShortRetryLimit, LongRetryLimit;
3290 UCHAR ctmp;
3291 #endif // SNMP_SUPPORT //
3295 #ifdef DOT11_N_SUPPORT
3296 MaxPhyMode = PHY_11N_5G;
3297 #endif // DOT11_N_SUPPORT //
3300 DBGPRINT(RT_DEBUG_TRACE, ("-->RTMPSetInformation(), 0x%08x\n", cmd&0x7FFF));
3301 switch(cmd & 0x7FFF) {
3302 case RT_OID_802_11_COUNTRY_REGION:
3303 if (wrq->u.data.length < sizeof(UCHAR))
3304 Status = -EINVAL;
3305 // Only avaliable when EEPROM not programming
3306 else if (!(pAdapter->CommonCfg.CountryRegion & 0x80) && !(pAdapter->CommonCfg.CountryRegionForABand & 0x80))
3308 ULONG Country;
3309 UCHAR TmpPhy;
3311 Status = copy_from_user(&Country, wrq->u.data.pointer, wrq->u.data.length);
3312 pAdapter->CommonCfg.CountryRegion = (UCHAR)(Country & 0x000000FF);
3313 pAdapter->CommonCfg.CountryRegionForABand = (UCHAR)((Country >> 8) & 0x000000FF);
3314 TmpPhy = pAdapter->CommonCfg.PhyMode;
3315 pAdapter->CommonCfg.PhyMode = 0xff;
3316 // Build all corresponding channel information
3317 RTMPSetPhyMode(pAdapter, TmpPhy);
3318 #ifdef DOT11_N_SUPPORT
3319 SetCommonHT(pAdapter);
3320 #endif // DOT11_N_SUPPORT //
3321 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_COUNTRY_REGION (A:%d B/G:%d)\n", pAdapter->CommonCfg.CountryRegionForABand,
3322 pAdapter->CommonCfg.CountryRegion));
3324 break;
3325 case OID_802_11_BSSID_LIST_SCAN:
3326 #ifdef RALINK_ATE
3327 if (ATE_ON(pAdapter))
3329 DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
3330 break;
3332 #endif // RALINK_ATE //
3333 Now = jiffies;
3334 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID_LIST_SCAN, TxCnt = %d \n", pAdapter->RalinkCounters.LastOneSecTotalTxCount));
3336 if (MONITOR_ON(pAdapter))
3338 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
3339 break;
3342 //Benson add 20080527, when radio off, sta don't need to scan
3343 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_RADIO_OFF))
3344 break;
3346 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
3348 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is scanning now !!!\n"));
3349 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
3350 Status = NDIS_STATUS_SUCCESS;
3351 break;
3354 if (pAdapter->RalinkCounters.LastOneSecTotalTxCount > 100)
3356 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
3357 Status = NDIS_STATUS_SUCCESS;
3358 pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
3359 break;
3362 if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
3363 ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
3364 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
3365 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
3366 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)) &&
3367 (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
3369 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
3370 Status = NDIS_STATUS_SUCCESS;
3371 pAdapter->StaCfg.ScanCnt = 99; // Prevent auto scan triggered by this OID
3372 break;
3376 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3378 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3379 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3382 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
3383 // this request, because this request is initiated by NDIS.
3384 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
3385 // Reset allowed scan retries
3386 pAdapter->StaCfg.ScanCnt = 0;
3387 pAdapter->StaCfg.LastScanTime = Now;
3389 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
3390 RTMP_SET_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
3391 MlmeEnqueue(pAdapter,
3392 MLME_CNTL_STATE_MACHINE,
3393 OID_802_11_BSSID_LIST_SCAN,
3395 NULL);
3397 Status = NDIS_STATUS_SUCCESS;
3398 StateMachineTouched = TRUE;
3399 break;
3400 case OID_802_11_SSID:
3401 if (wrq->u.data.length != sizeof(NDIS_802_11_SSID))
3402 Status = -EINVAL;
3403 else
3405 PCHAR pSsidString = NULL;
3406 Status = copy_from_user(&Ssid, wrq->u.data.pointer, wrq->u.data.length);
3408 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SSID (Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
3409 if (Ssid.SsidLength > MAX_LEN_OF_SSID)
3410 Status = -EINVAL;
3411 else
3413 if (Ssid.SsidLength == 0)
3415 Set_SSID_Proc(pAdapter, "");
3417 else
3419 pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
3420 if (pSsidString)
3422 NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
3423 NdisMoveMemory(pSsidString, Ssid.Ssid, Ssid.SsidLength);
3424 Set_SSID_Proc(pAdapter, pSsidString);
3425 kfree(pSsidString);
3427 else
3428 Status = -ENOMEM;
3432 break;
3433 case OID_802_11_BSSID:
3434 #ifdef RALINK_ATE
3435 if (ATE_ON(pAdapter))
3437 DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
3438 break;
3440 #endif // RALINK_ATE //
3441 if (wrq->u.data.length != sizeof(NDIS_802_11_MAC_ADDRESS))
3442 Status = -EINVAL;
3443 else
3445 Status = copy_from_user(&Bssid, wrq->u.data.pointer, wrq->u.data.length);
3447 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
3448 // this request, because this request is initiated by NDIS.
3449 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
3451 // Prevent to connect AP again in STAMlmePeriodicExec
3452 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
3454 // Reset allowed scan retries
3455 pAdapter->StaCfg.ScanCnt = 0;
3457 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3459 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3460 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3462 MlmeEnqueue(pAdapter,
3463 MLME_CNTL_STATE_MACHINE,
3464 OID_802_11_BSSID,
3465 sizeof(NDIS_802_11_MAC_ADDRESS),
3466 (VOID *)&Bssid);
3467 Status = NDIS_STATUS_SUCCESS;
3468 StateMachineTouched = TRUE;
3470 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID %02x:%02x:%02x:%02x:%02x:%02x\n",
3471 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
3473 break;
3474 case RT_OID_802_11_RADIO:
3475 if (wrq->u.data.length != sizeof(BOOLEAN))
3476 Status = -EINVAL;
3477 else
3479 Status = copy_from_user(&RadioState, wrq->u.data.pointer, wrq->u.data.length);
3480 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RADIO (=%d)\n", RadioState));
3481 if (pAdapter->StaCfg.bSwRadio != RadioState)
3483 pAdapter->StaCfg.bSwRadio = RadioState;
3484 if (pAdapter->StaCfg.bRadio != (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio))
3486 pAdapter->StaCfg.bRadio = (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio);
3487 if (pAdapter->StaCfg.bRadio == TRUE)
3489 MlmeRadioOn(pAdapter);
3490 // Update extra information
3491 pAdapter->ExtraInfo = EXTRA_INFO_CLEAR;
3493 else
3495 MlmeRadioOff(pAdapter);
3496 // Update extra information
3497 pAdapter->ExtraInfo = SW_RADIO_OFF;
3502 break;
3503 case RT_OID_802_11_PHY_MODE:
3504 if (wrq->u.data.length != sizeof(RT_802_11_PHY_MODE))
3505 Status = -EINVAL;
3506 else
3508 Status = copy_from_user(&PhyMode, wrq->u.data.pointer, wrq->u.data.length);
3509 if (PhyMode <= MaxPhyMode)
3511 RTMPSetPhyMode(pAdapter, PhyMode);
3512 #ifdef DOT11_N_SUPPORT
3513 SetCommonHT(pAdapter);
3514 #endif // DOT11_N_SUPPORT //
3516 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PHY_MODE (=%d)\n", PhyMode));
3518 break;
3519 case RT_OID_802_11_STA_CONFIG:
3520 if (wrq->u.data.length != sizeof(RT_802_11_STA_CONFIG))
3521 Status = -EINVAL;
3522 else
3524 Status = copy_from_user(&StaConfig, wrq->u.data.pointer, wrq->u.data.length);
3525 pAdapter->CommonCfg.bEnableTxBurst = StaConfig.EnableTxBurst;
3526 pAdapter->CommonCfg.UseBGProtection = StaConfig.UseBGProtection;
3527 pAdapter->CommonCfg.bUseShortSlotTime = 1; // 2003-10-30 always SHORT SLOT capable
3528 if ((pAdapter->CommonCfg.PhyMode != StaConfig.AdhocMode) &&
3529 (StaConfig.AdhocMode <= MaxPhyMode))
3531 // allow dynamic change of "USE OFDM rate or not" in ADHOC mode
3532 // if setting changed, need to reset current TX rate as well as BEACON frame format
3533 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
3535 pAdapter->CommonCfg.PhyMode = StaConfig.AdhocMode;
3536 RTMPSetPhyMode(pAdapter, PhyMode);
3537 MlmeUpdateTxRates(pAdapter, FALSE, 0);
3538 MakeIbssBeacon(pAdapter); // re-build BEACON frame
3539 AsicEnableIbssSync(pAdapter); // copy to on-chip memory
3542 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_STA_CONFIG (Burst=%d, Protection=%ld,ShortSlot=%d\n",
3543 pAdapter->CommonCfg.bEnableTxBurst,
3544 pAdapter->CommonCfg.UseBGProtection,
3545 pAdapter->CommonCfg.bUseShortSlotTime));
3547 break;
3548 case OID_802_11_DESIRED_RATES:
3549 if (wrq->u.data.length != sizeof(NDIS_802_11_RATES))
3550 Status = -EINVAL;
3551 else
3553 Status = copy_from_user(&aryRates, wrq->u.data.pointer, wrq->u.data.length);
3554 NdisZeroMemory(pAdapter->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES);
3555 NdisMoveMemory(pAdapter->CommonCfg.DesireRate, &aryRates, sizeof(NDIS_802_11_RATES));
3556 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DESIRED_RATES (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
3557 pAdapter->CommonCfg.DesireRate[0],pAdapter->CommonCfg.DesireRate[1],
3558 pAdapter->CommonCfg.DesireRate[2],pAdapter->CommonCfg.DesireRate[3],
3559 pAdapter->CommonCfg.DesireRate[4],pAdapter->CommonCfg.DesireRate[5],
3560 pAdapter->CommonCfg.DesireRate[6],pAdapter->CommonCfg.DesireRate[7] ));
3561 // Changing DesiredRate may affect the MAX TX rate we used to TX frames out
3562 MlmeUpdateTxRates(pAdapter, FALSE, 0);
3564 break;
3565 case RT_OID_802_11_PREAMBLE:
3566 if (wrq->u.data.length != sizeof(RT_802_11_PREAMBLE))
3567 Status = -EINVAL;
3568 else
3570 Status = copy_from_user(&Preamble, wrq->u.data.pointer, wrq->u.data.length);
3571 if (Preamble == Rt802_11PreambleShort)
3573 pAdapter->CommonCfg.TxPreamble = Preamble;
3574 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleShort);
3576 else if ((Preamble == Rt802_11PreambleLong) || (Preamble == Rt802_11PreambleAuto))
3578 // if user wants AUTO, initialize to LONG here, then change according to AP's
3579 // capability upon association.
3580 pAdapter->CommonCfg.TxPreamble = Preamble;
3581 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleLong);
3583 else
3585 Status = -EINVAL;
3586 break;
3588 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PREAMBLE (=%d)\n", Preamble));
3590 break;
3591 case OID_802_11_WEP_STATUS:
3592 if (wrq->u.data.length != sizeof(NDIS_802_11_WEP_STATUS))
3593 Status = -EINVAL;
3594 else
3596 Status = copy_from_user(&WepStatus, wrq->u.data.pointer, wrq->u.data.length);
3597 // Since TKIP, AES, WEP are all supported. It should not have any invalid setting
3598 if (WepStatus <= Ndis802_11Encryption3KeyAbsent)
3600 if (pAdapter->StaCfg.WepStatus != WepStatus)
3602 // Config has changed
3603 pAdapter->bConfigChanged = TRUE;
3605 pAdapter->StaCfg.WepStatus = WepStatus;
3606 pAdapter->StaCfg.OrigWepStatus = WepStatus;
3607 pAdapter->StaCfg.PairCipher = WepStatus;
3608 pAdapter->StaCfg.GroupCipher = WepStatus;
3610 else
3612 Status = -EINVAL;
3613 break;
3615 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEP_STATUS (=%d)\n",WepStatus));
3617 break;
3618 case OID_802_11_AUTHENTICATION_MODE:
3619 if (wrq->u.data.length != sizeof(NDIS_802_11_AUTHENTICATION_MODE))
3620 Status = -EINVAL;
3621 else
3623 Status = copy_from_user(&AuthMode, wrq->u.data.pointer, wrq->u.data.length);
3624 if (AuthMode > Ndis802_11AuthModeMax)
3626 Status = -EINVAL;
3627 break;
3629 else
3631 if (pAdapter->StaCfg.AuthMode != AuthMode)
3633 // Config has changed
3634 pAdapter->bConfigChanged = TRUE;
3636 pAdapter->StaCfg.AuthMode = AuthMode;
3638 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
3639 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_AUTHENTICATION_MODE (=%d) \n",pAdapter->StaCfg.AuthMode));
3641 break;
3642 case OID_802_11_INFRASTRUCTURE_MODE:
3643 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_INFRASTRUCTURE))
3644 Status = -EINVAL;
3645 else
3647 Status = copy_from_user(&BssType, wrq->u.data.pointer, wrq->u.data.length);
3649 if (BssType == Ndis802_11IBSS)
3650 Set_NetworkType_Proc(pAdapter, "Adhoc");
3651 else if (BssType == Ndis802_11Infrastructure)
3652 Set_NetworkType_Proc(pAdapter, "Infra");
3653 else if (BssType == Ndis802_11Monitor)
3654 Set_NetworkType_Proc(pAdapter, "Monitor");
3655 else
3657 Status = -EINVAL;
3658 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_INFRASTRUCTURE_MODE (unknown)\n"));
3661 break;
3662 case OID_802_11_REMOVE_WEP:
3663 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_WEP\n"));
3664 if (wrq->u.data.length != sizeof(NDIS_802_11_KEY_INDEX))
3666 Status = -EINVAL;
3668 else
3670 KeyIdx = *(NDIS_802_11_KEY_INDEX *) wrq->u.data.pointer;
3672 if (KeyIdx & 0x80000000)
3674 // Should never set default bit when remove key
3675 Status = -EINVAL;
3677 else
3679 KeyIdx = KeyIdx & 0x0fffffff;
3680 if (KeyIdx >= 4){
3681 Status = -EINVAL;
3683 else
3685 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
3686 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
3687 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
3691 break;
3692 case RT_OID_802_11_RESET_COUNTERS:
3693 NdisZeroMemory(&pAdapter->WlanCounters, sizeof(COUNTER_802_11));
3694 NdisZeroMemory(&pAdapter->Counters8023, sizeof(COUNTER_802_3));
3695 NdisZeroMemory(&pAdapter->RalinkCounters, sizeof(COUNTER_RALINK));
3696 pAdapter->Counters8023.RxNoBuffer = 0;
3697 pAdapter->Counters8023.GoodReceives = 0;
3698 pAdapter->Counters8023.RxNoBuffer = 0;
3699 #ifdef RT2870
3700 pAdapter->BulkOutComplete = 0;
3701 pAdapter->BulkOutCompleteOther= 0;
3702 pAdapter->BulkOutCompleteCancel = 0;
3703 pAdapter->BulkOutReq = 0;
3704 pAdapter->BulkInReq= 0;
3705 pAdapter->BulkInComplete = 0;
3706 pAdapter->BulkInCompleteFail = 0;
3707 #endif // RT2870 //
3708 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RESET_COUNTERS \n"));
3709 break;
3710 case OID_802_11_RTS_THRESHOLD:
3711 if (wrq->u.data.length != sizeof(NDIS_802_11_RTS_THRESHOLD))
3712 Status = -EINVAL;
3713 else
3715 Status = copy_from_user(&RtsThresh, wrq->u.data.pointer, wrq->u.data.length);
3716 if (RtsThresh > MAX_RTS_THRESHOLD)
3717 Status = -EINVAL;
3718 else
3719 pAdapter->CommonCfg.RtsThreshold = (USHORT)RtsThresh;
3721 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_RTS_THRESHOLD (=%ld)\n",RtsThresh));
3722 break;
3723 case OID_802_11_FRAGMENTATION_THRESHOLD:
3724 if (wrq->u.data.length != sizeof(NDIS_802_11_FRAGMENTATION_THRESHOLD))
3725 Status = -EINVAL;
3726 else
3728 Status = copy_from_user(&FragThresh, wrq->u.data.pointer, wrq->u.data.length);
3729 pAdapter->CommonCfg.bUseZeroToDisableFragment = FALSE;
3730 if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
3732 if (FragThresh == 0)
3734 pAdapter->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
3735 pAdapter->CommonCfg.bUseZeroToDisableFragment = TRUE;
3737 else
3738 Status = -EINVAL;
3740 else
3741 pAdapter->CommonCfg.FragmentThreshold = (USHORT)FragThresh;
3743 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_FRAGMENTATION_THRESHOLD (=%ld) \n",FragThresh));
3744 break;
3745 case OID_802_11_POWER_MODE:
3746 if (wrq->u.data.length != sizeof(NDIS_802_11_POWER_MODE))
3747 Status = -EINVAL;
3748 else
3750 Status = copy_from_user(&PowerMode, wrq->u.data.pointer, wrq->u.data.length);
3751 if (PowerMode == Ndis802_11PowerModeCAM)
3752 Set_PSMode_Proc(pAdapter, "CAM");
3753 else if (PowerMode == Ndis802_11PowerModeMAX_PSP)
3754 Set_PSMode_Proc(pAdapter, "Max_PSP");
3755 else if (PowerMode == Ndis802_11PowerModeFast_PSP)
3756 Set_PSMode_Proc(pAdapter, "Fast_PSP");
3757 else if (PowerMode == Ndis802_11PowerModeLegacy_PSP)
3758 Set_PSMode_Proc(pAdapter, "Legacy_PSP");
3759 else
3760 Status = -EINVAL;
3762 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_POWER_MODE (=%d)\n",PowerMode));
3763 break;
3764 case RT_OID_802_11_TX_POWER_LEVEL_1:
3765 if (wrq->u.data.length < sizeof(ULONG))
3766 Status = -EINVAL;
3767 else
3769 Status = copy_from_user(&PowerTemp, wrq->u.data.pointer, wrq->u.data.length);
3770 if (PowerTemp > 100)
3771 PowerTemp = 0xffffffff; // AUTO
3772 pAdapter->CommonCfg.TxPowerDefault = PowerTemp; //keep current setting.
3773 pAdapter->CommonCfg.TxPowerPercentage = pAdapter->CommonCfg.TxPowerDefault;
3774 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
3776 break;
3777 case OID_802_11_NETWORK_TYPE_IN_USE:
3778 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_TYPE))
3779 Status = -EINVAL;
3780 else
3782 Status = copy_from_user(&NetType, wrq->u.data.pointer, wrq->u.data.length);
3784 if (NetType == Ndis802_11DS)
3785 RTMPSetPhyMode(pAdapter, PHY_11B);
3786 else if (NetType == Ndis802_11OFDM24)
3787 RTMPSetPhyMode(pAdapter, PHY_11BG_MIXED);
3788 else if (NetType == Ndis802_11OFDM5)
3789 RTMPSetPhyMode(pAdapter, PHY_11A);
3790 else
3791 Status = -EINVAL;
3792 #ifdef DOT11_N_SUPPORT
3793 if (Status == NDIS_STATUS_SUCCESS)
3794 SetCommonHT(pAdapter);
3795 #endif // DOT11_N_SUPPORT //
3796 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_NETWORK_TYPE_IN_USE (=%d)\n",NetType));
3798 break;
3799 // For WPA PSK PMK key
3800 case RT_OID_802_11_ADD_WPA:
3801 pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3802 if(pKey == NULL)
3804 Status = -ENOMEM;
3805 break;
3808 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
3809 if (pKey->Length != wrq->u.data.length)
3811 Status = -EINVAL;
3812 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!!\n"));
3814 else
3816 if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
3817 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
3818 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone) )
3820 Status = -EOPNOTSUPP;
3821 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!! [AuthMode != WPAPSK/WPA2PSK/WPANONE]\n"));
3823 else if ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
3824 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
3825 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) ) // Only for WPA PSK mode
3827 NdisMoveMemory(pAdapter->StaCfg.PMK, &pKey->KeyMaterial, pKey->KeyLength);
3828 // Use RaConfig as PSK agent.
3829 // Start STA supplicant state machine
3830 if (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
3831 pAdapter->StaCfg.WpaState = SS_START;
3833 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3835 else
3837 pAdapter->StaCfg.WpaState = SS_NOTUSE;
3838 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3841 kfree(pKey);
3842 break;
3843 case OID_802_11_REMOVE_KEY:
3844 pRemoveKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3845 if(pRemoveKey == NULL)
3847 Status = -ENOMEM;
3848 break;
3851 Status = copy_from_user(pRemoveKey, wrq->u.data.pointer, wrq->u.data.length);
3852 if (pRemoveKey->Length != wrq->u.data.length)
3854 Status = -EINVAL;
3855 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!\n"));
3857 else
3859 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3861 RTMPWPARemoveKeyProc(pAdapter, pRemoveKey);
3862 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Remove WPA Key!!\n"));
3864 else
3866 KeyIdx = pRemoveKey->KeyIndex;
3868 if (KeyIdx & 0x80000000)
3870 // Should never set default bit when remove key
3871 Status = -EINVAL;
3872 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(Should never set default bit when remove key)\n"));
3874 else
3876 KeyIdx = KeyIdx & 0x0fffffff;
3877 if (KeyIdx > 3)
3879 Status = -EINVAL;
3880 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(KeyId[%d] out of range)\n", KeyIdx));
3882 else
3884 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
3885 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
3886 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
3887 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY (id=0x%x, Len=%d-byte)\n", pRemoveKey->KeyIndex, pRemoveKey->Length));
3892 kfree(pRemoveKey);
3893 break;
3894 // New for WPA
3895 case OID_802_11_ADD_KEY:
3896 pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3897 if(pKey == NULL)
3899 Status = -ENOMEM;
3900 break;
3902 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
3903 if (pKey->Length != wrq->u.data.length)
3905 Status = -EINVAL;
3906 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY, Failed!!\n"));
3908 else
3910 RTMPAddKey(pAdapter, pKey);
3911 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3913 kfree(pKey);
3914 break;
3915 case OID_802_11_CONFIGURATION:
3916 if (wrq->u.data.length != sizeof(NDIS_802_11_CONFIGURATION))
3917 Status = -EINVAL;
3918 else
3920 Status = copy_from_user(&Config, wrq->u.data.pointer, wrq->u.data.length);
3921 pConfig = &Config;
3923 if ((pConfig->BeaconPeriod >= 20) && (pConfig->BeaconPeriod <=400))
3924 pAdapter->CommonCfg.BeaconPeriod = (USHORT) pConfig->BeaconPeriod;
3926 pAdapter->StaActive.AtimWin = (USHORT) pConfig->ATIMWindow;
3927 MAP_KHZ_TO_CHANNEL_ID(pConfig->DSConfig, pAdapter->CommonCfg.Channel);
3929 // Save the channel on MlmeAux for CntlOidRTBssidProc used.
3931 pAdapter->MlmeAux.Channel = pAdapter->CommonCfg.Channel;
3933 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_CONFIGURATION (BeacnPeriod=%ld,AtimW=%ld,Ch=%d)\n",
3934 pConfig->BeaconPeriod, pConfig->ATIMWindow, pAdapter->CommonCfg.Channel));
3935 // Config has changed
3936 pAdapter->bConfigChanged = TRUE;
3938 break;
3939 #ifdef DOT11_N_SUPPORT
3940 case RT_OID_802_11_SET_HT_PHYMODE:
3941 if (wrq->u.data.length != sizeof(OID_SET_HT_PHYMODE))
3942 Status = -EINVAL;
3943 else
3945 POID_SET_HT_PHYMODE pHTPhyMode = &HT_PhyMode;
3947 Status = copy_from_user(&HT_PhyMode, wrq->u.data.pointer, wrq->u.data.length);
3948 DBGPRINT(RT_DEBUG_TRACE, ("Set::pHTPhyMode (PhyMode = %d,TransmitNo = %d, HtMode = %d, ExtOffset = %d , MCS = %d, BW = %d, STBC = %d, SHORTGI = %d) \n",
3949 pHTPhyMode->PhyMode, pHTPhyMode->TransmitNo,pHTPhyMode->HtMode,pHTPhyMode->ExtOffset,
3950 pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->SHORTGI));
3951 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
3952 RTMPSetHT(pAdapter, pHTPhyMode);
3954 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_HT_PHYMODE(MCS=%d,BW=%d,SGI=%d,STBC=%d)\n",
3955 pAdapter->StaCfg.HTPhyMode.field.MCS, pAdapter->StaCfg.HTPhyMode.field.BW, pAdapter->StaCfg.HTPhyMode.field.ShortGI,
3956 pAdapter->StaCfg.HTPhyMode.field.STBC));
3957 break;
3958 #endif // DOT11_N_SUPPORT //
3959 case RT_OID_802_11_SET_APSD_SETTING:
3960 if (wrq->u.data.length != sizeof(ULONG))
3961 Status = -EINVAL;
3962 else
3964 ULONG apsd ;
3965 Status = copy_from_user(&apsd, wrq->u.data.pointer, wrq->u.data.length);
3967 /*-------------------------------------------------------------------
3968 |B31~B7 | B6~B5 | B4 | B3 | B2 | B1 | B0 |
3969 ---------------------------------------------------------------------
3970 | Rsvd | Max SP Len | AC_VO | AC_VI | AC_BK | AC_BE | APSD Capable |
3971 ---------------------------------------------------------------------*/
3972 pAdapter->CommonCfg.bAPSDCapable = (apsd & 0x00000001) ? TRUE : FALSE;
3973 pAdapter->CommonCfg.bAPSDAC_BE = ((apsd & 0x00000002) >> 1) ? TRUE : FALSE;
3974 pAdapter->CommonCfg.bAPSDAC_BK = ((apsd & 0x00000004) >> 2) ? TRUE : FALSE;
3975 pAdapter->CommonCfg.bAPSDAC_VI = ((apsd & 0x00000008) >> 3) ? TRUE : FALSE;
3976 pAdapter->CommonCfg.bAPSDAC_VO = ((apsd & 0x00000010) >> 4) ? TRUE : FALSE;
3977 pAdapter->CommonCfg.MaxSPLength = (UCHAR)((apsd & 0x00000060) >> 5);
3979 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,
3980 pAdapter->CommonCfg.bAPSDAC_BE, pAdapter->CommonCfg.bAPSDAC_BK, pAdapter->CommonCfg.bAPSDAC_VI, pAdapter->CommonCfg.bAPSDAC_VO, pAdapter->CommonCfg.MaxSPLength));
3982 break;
3984 case RT_OID_802_11_SET_APSD_PSM:
3985 if (wrq->u.data.length != sizeof(ULONG))
3986 Status = -EINVAL;
3987 else
3989 // Driver needs to notify AP when PSM changes
3990 Status = copy_from_user(&pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.pointer, wrq->u.data.length);
3991 if (pAdapter->CommonCfg.bAPSDForcePowerSave != pAdapter->StaCfg.Psm)
3993 MlmeSetPsmBit(pAdapter, pAdapter->CommonCfg.bAPSDForcePowerSave);
3994 RTMPSendNullFrame(pAdapter, pAdapter->CommonCfg.TxRate, TRUE);
3996 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_APSD_PSM (bAPSDForcePowerSave:%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
3998 break;
3999 #ifdef QOS_DLS_SUPPORT
4000 case RT_OID_802_11_SET_DLS:
4001 if (wrq->u.data.length != sizeof(ULONG))
4002 Status = -EINVAL;
4003 else
4005 BOOLEAN oldvalue = pAdapter->CommonCfg.bDLSCapable;
4006 Status = copy_from_user(&pAdapter->CommonCfg.bDLSCapable, wrq->u.data.pointer, wrq->u.data.length);
4007 if (oldvalue && !pAdapter->CommonCfg.bDLSCapable)
4009 int i;
4010 // tear down local dls table entry
4011 for (i=0; i<MAX_NUM_OF_INIT_DLS_ENTRY; i++)
4013 if (pAdapter->StaCfg.DLSEntry[i].Valid && (pAdapter->StaCfg.DLSEntry[i].Status == DLS_FINISH))
4015 pAdapter->StaCfg.DLSEntry[i].Status = DLS_NONE;
4016 pAdapter->StaCfg.DLSEntry[i].Valid = FALSE;
4017 RTMPSendDLSTearDownFrame(pAdapter, pAdapter->StaCfg.DLSEntry[i].MacAddr);
4021 // tear down peer dls table entry
4022 for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
4024 if (pAdapter->StaCfg.DLSEntry[i].Valid && (pAdapter->StaCfg.DLSEntry[i].Status == DLS_FINISH))
4026 pAdapter->StaCfg.DLSEntry[i].Status = DLS_NONE;
4027 pAdapter->StaCfg.DLSEntry[i].Valid = FALSE;
4028 RTMPSendDLSTearDownFrame(pAdapter, pAdapter->StaCfg.DLSEntry[i].MacAddr);
4033 DBGPRINT(RT_DEBUG_TRACE,("Set::RT_OID_802_11_SET_DLS (=%d)\n", pAdapter->CommonCfg.bDLSCapable));
4035 break;
4037 case RT_OID_802_11_SET_DLS_PARAM:
4038 if (wrq->u.data.length != sizeof(RT_802_11_DLS_UI))
4039 Status = -EINVAL;
4040 else
4042 RT_802_11_DLS Dls;
4044 NdisZeroMemory(&Dls, sizeof(RT_802_11_DLS));
4045 RTMPMoveMemory(&Dls, wrq->u.data.pointer, sizeof(RT_802_11_DLS_UI));
4046 MlmeEnqueue(pAdapter,
4047 MLME_CNTL_STATE_MACHINE,
4048 RT_OID_802_11_SET_DLS_PARAM,
4049 sizeof(RT_802_11_DLS),
4050 &Dls);
4051 DBGPRINT(RT_DEBUG_TRACE,("Set::RT_OID_802_11_SET_DLS_PARAM \n"));
4053 break;
4054 #endif // QOS_DLS_SUPPORT //
4055 case RT_OID_802_11_SET_WMM:
4056 if (wrq->u.data.length != sizeof(BOOLEAN))
4057 Status = -EINVAL;
4058 else
4060 Status = copy_from_user(&pAdapter->CommonCfg.bWmmCapable, wrq->u.data.pointer, wrq->u.data.length);
4061 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_WMM (=%d) \n", pAdapter->CommonCfg.bWmmCapable));
4063 break;
4065 case OID_802_11_DISASSOCIATE:
4066 #ifdef RALINK_ATE
4067 if (ATE_ON(pAdapter))
4069 DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
4070 break;
4072 #endif // RALINK_ATE //
4074 // Set NdisRadioStateOff to TRUE, instead of called MlmeRadioOff.
4075 // Later on, NDIS_802_11_BSSID_LIST_EX->NumberOfItems should be 0
4076 // when query OID_802_11_BSSID_LIST.
4078 // TRUE: NumberOfItems will set to 0.
4079 // FALSE: NumberOfItems no change.
4081 pAdapter->CommonCfg.NdisRadioStateOff = TRUE;
4082 // Set to immediately send the media disconnect event
4083 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
4084 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DISASSOCIATE \n"));
4086 if (INFRA_ON(pAdapter))
4088 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
4090 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
4091 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
4094 MlmeEnqueue(pAdapter,
4095 MLME_CNTL_STATE_MACHINE,
4096 OID_802_11_DISASSOCIATE,
4098 NULL);
4100 StateMachineTouched = TRUE;
4102 break;
4104 #ifdef DOT11_N_SUPPORT
4105 case RT_OID_802_11_SET_IMME_BA_CAP:
4106 if (wrq->u.data.length != sizeof(OID_BACAP_STRUC))
4107 Status = -EINVAL;
4108 else
4110 OID_BACAP_STRUC Orde ;
4111 Status = copy_from_user(&Orde, wrq->u.data.pointer, wrq->u.data.length);
4112 if (Orde.Policy > BA_NOTUSE)
4114 Status = NDIS_STATUS_INVALID_DATA;
4116 else if (Orde.Policy == BA_NOTUSE)
4118 pAdapter->CommonCfg.BACapability.field.Policy = BA_NOTUSE;
4119 pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
4120 pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
4121 pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
4122 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
4123 pAdapter->CommonCfg.DesiredHtPhy.MimoPs= Orde.MMPSmode;
4124 pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
4125 // UPdata to HT IE
4126 pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
4127 pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
4128 pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
4130 else
4132 pAdapter->CommonCfg.BACapability.field.AutoBA = Orde.AutoBA;
4133 pAdapter->CommonCfg.BACapability.field.Policy = IMMED_BA; // we only support immediate BA.
4134 pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
4135 pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
4136 pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
4137 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
4138 pAdapter->CommonCfg.DesiredHtPhy.MimoPs = Orde.MMPSmode;
4139 pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
4141 // UPdata to HT IE
4142 pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
4143 pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
4144 pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
4146 if (pAdapter->CommonCfg.BACapability.field.RxBAWinLimit > MAX_RX_REORDERBUF)
4147 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = MAX_RX_REORDERBUF;
4151 pAdapter->CommonCfg.REGBACapability.word = pAdapter->CommonCfg.BACapability.word;
4152 DBGPRINT(RT_DEBUG_TRACE, ("Set::(Orde.AutoBA = %d) (Policy=%d)(ReBAWinLimit=%d)(TxBAWinLimit=%d)(AutoMode=%d)\n",Orde.AutoBA, pAdapter->CommonCfg.BACapability.field.Policy,
4153 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit,pAdapter->CommonCfg.BACapability.field.TxBAWinLimit, pAdapter->CommonCfg.BACapability.field.AutoBA));
4154 DBGPRINT(RT_DEBUG_TRACE, ("Set::(MimoPs = %d)(AmsduEnable = %d) (AmsduSize=%d)(MpduDensity=%d)\n",pAdapter->CommonCfg.DesiredHtPhy.MimoPs, pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable,
4155 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize, pAdapter->CommonCfg.DesiredHtPhy.MpduDensity));
4158 break;
4159 case RT_OID_802_11_ADD_IMME_BA:
4160 DBGPRINT(RT_DEBUG_TRACE, (" Set :: RT_OID_802_11_ADD_IMME_BA \n"));
4161 if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
4162 Status = -EINVAL;
4163 else
4165 UCHAR index;
4166 OID_ADD_BA_ENTRY BA;
4167 MAC_TABLE_ENTRY *pEntry;
4169 Status = copy_from_user(&BA, wrq->u.data.pointer, wrq->u.data.length);
4170 if (BA.TID > 15)
4172 Status = NDIS_STATUS_INVALID_DATA;
4173 break;
4175 else
4177 //BATableInsertEntry
4178 //As ad-hoc mode, BA pair is not limited to only BSSID. so add via OID.
4179 index = BA.TID;
4180 // in ad hoc mode, when adding BA pair, we should insert this entry into MACEntry too
4181 pEntry = MacTableLookup(pAdapter, BA.MACAddr);
4182 if (!pEntry)
4184 DBGPRINT(RT_DEBUG_TRACE, ("RT_OID_802_11_ADD_IMME_BA. break on no connection.----:%x:%x\n", BA.MACAddr[4], BA.MACAddr[5]));
4185 break;
4187 if (BA.IsRecipient == FALSE)
4189 if (pEntry->bIAmBadAtheros == TRUE)
4190 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = 0x10;
4192 BAOriSessionSetUp(pAdapter, pEntry, index, 0, 100, TRUE);
4194 else
4196 //BATableInsertEntry(pAdapter, pEntry->Aid, BA.MACAddr, 0, 0xffff, BA.TID, BA.nMSDU, BA.IsRecipient);
4199 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_IMME_BA. Rec = %d. Mac = %x:%x:%x:%x:%x:%x . \n",
4200 BA.IsRecipient, BA.MACAddr[0], BA.MACAddr[1], BA.MACAddr[2], BA.MACAddr[2]
4201 , BA.MACAddr[4], BA.MACAddr[5]));
4204 break;
4206 case RT_OID_802_11_TEAR_IMME_BA:
4207 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA \n"));
4208 if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
4209 Status = -EINVAL;
4210 else
4212 POID_ADD_BA_ENTRY pBA;
4213 MAC_TABLE_ENTRY *pEntry;
4215 pBA = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4217 if (pBA == NULL)
4219 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA kmalloc() can't allocate enough memory\n"));
4220 Status = NDIS_STATUS_FAILURE;
4222 else
4224 Status = copy_from_user(pBA, wrq->u.data.pointer, wrq->u.data.length);
4225 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA(TID=%d, bAllTid=%d)\n", pBA->TID, pBA->bAllTid));
4227 if (!pBA->bAllTid && (pBA->TID > NUM_OF_TID))
4229 Status = NDIS_STATUS_INVALID_DATA;
4230 break;
4233 if (pBA->IsRecipient == FALSE)
4235 pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
4236 DBGPRINT(RT_DEBUG_TRACE, (" pBA->IsRecipient == FALSE\n"));
4237 if (pEntry)
4239 DBGPRINT(RT_DEBUG_TRACE, (" pBA->pEntry\n"));
4240 BAOriSessionTearDown(pAdapter, pEntry->Aid, pBA->TID, FALSE, TRUE);
4242 else
4243 DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
4245 else
4247 pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
4248 if (pEntry)
4250 BARecSessionTearDown( pAdapter, (UCHAR)pEntry->Aid, pBA->TID, TRUE);
4252 else
4253 DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
4255 kfree(pBA);
4258 break;
4259 #endif // DOT11_N_SUPPORT //
4261 // For WPA_SUPPLICANT to set static wep key
4262 case OID_802_11_ADD_WEP:
4263 pWepKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4265 if(pWepKey == NULL)
4267 Status = -ENOMEM;
4268 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed!!\n"));
4269 break;
4271 Status = copy_from_user(pWepKey, wrq->u.data.pointer, wrq->u.data.length);
4272 if (Status)
4274 Status = -EINVAL;
4275 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (length mismatch)!!\n"));
4277 else
4279 KeyIdx = pWepKey->KeyIndex & 0x0fffffff;
4280 // KeyIdx must be 0 ~ 3
4281 if (KeyIdx > 4)
4283 Status = -EINVAL;
4284 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (KeyIdx must be smaller than 4)!!\n"));
4286 else
4288 UCHAR CipherAlg = 0;
4289 PUCHAR Key;
4291 // set key material and key length
4292 NdisZeroMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, 16);
4293 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
4294 NdisMoveMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
4296 switch(pWepKey->KeyLength)
4298 case 5:
4299 CipherAlg = CIPHER_WEP64;
4300 break;
4301 case 13:
4302 CipherAlg = CIPHER_WEP128;
4303 break;
4304 default:
4305 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, only support CIPHER_WEP64(len:5) & CIPHER_WEP128(len:13)!!\n"));
4306 Status = -EINVAL;
4307 break;
4309 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CipherAlg;
4311 // Default key for tx (shared key)
4312 if (pWepKey->KeyIndex & 0x80000000)
4314 #ifdef WPA_SUPPLICANT_SUPPORT
4315 // set key material and key length
4316 NdisZeroMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, 16);
4317 pAdapter->StaCfg.DesireSharedKey[KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
4318 NdisMoveMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
4319 pAdapter->StaCfg.DesireSharedKeyId = KeyIdx;
4320 pAdapter->StaCfg.DesireSharedKey[KeyIdx].CipherAlg = CipherAlg;
4321 #endif // WPA_SUPPLICANT_SUPPORT //
4322 pAdapter->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
4325 #ifdef WPA_SUPPLICANT_SUPPORT
4326 if ((pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE) &&
4327 (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA))
4329 Key = pWepKey->KeyMaterial;
4331 // Set Group key material to Asic
4332 AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
4334 // Update WCID attribute table and IVEIV table for this group key table
4335 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
4337 STA_PORT_SECURED(pAdapter);
4339 // Indicate Connected for GUI
4340 pAdapter->IndicateMediaState = NdisMediaStateConnected;
4342 else if (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)
4343 #endif // WPA_SUPPLICANT_SUPPORT
4345 Key = pAdapter->SharedKey[BSS0][KeyIdx].Key;
4347 // Set key material and cipherAlg to Asic
4348 AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
4350 if (pWepKey->KeyIndex & 0x80000000)
4352 PMAC_TABLE_ENTRY pEntry = &pAdapter->MacTab.Content[BSSID_WCID];
4353 // Assign group key info
4354 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
4355 // Assign pairwise key info
4356 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, pEntry);
4359 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"));
4362 kfree(pWepKey);
4363 break;
4364 #ifdef WPA_SUPPLICANT_SUPPORT
4365 case OID_SET_COUNTERMEASURES:
4366 if (wrq->u.data.length != sizeof(int))
4367 Status = -EINVAL;
4368 else
4370 int enabled = 0;
4371 Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
4372 if (enabled == 1)
4373 pAdapter->StaCfg.bBlockAssoc = TRUE;
4374 else
4375 // WPA MIC error should block association attempt for 60 seconds
4376 pAdapter->StaCfg.bBlockAssoc = FALSE;
4377 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_SET_COUNTERMEASURES bBlockAssoc=%s\n", pAdapter->StaCfg.bBlockAssoc ? "TRUE":"FALSE"));
4379 break;
4380 case RT_OID_WPA_SUPPLICANT_SUPPORT:
4381 if (wrq->u.data.length != sizeof(UCHAR))
4382 Status = -EINVAL;
4383 else
4385 Status = copy_from_user(&wpa_supplicant_enable, wrq->u.data.pointer, wrq->u.data.length);
4386 pAdapter->StaCfg.WpaSupplicantUP = wpa_supplicant_enable;
4387 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
4389 break;
4390 case OID_802_11_DEAUTHENTICATION:
4391 if (wrq->u.data.length != sizeof(MLME_DEAUTH_REQ_STRUCT))
4392 Status = -EINVAL;
4393 else
4395 MLME_DEAUTH_REQ_STRUCT *pInfo;
4396 MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
4398 pInfo = (MLME_DEAUTH_REQ_STRUCT *) MsgElem->Msg;
4399 Status = copy_from_user(pInfo, wrq->u.data.pointer, wrq->u.data.length);
4400 MlmeDeauthReqAction(pAdapter, MsgElem);
4401 kfree(MsgElem);
4403 if (INFRA_ON(pAdapter))
4405 LinkDown(pAdapter, FALSE);
4406 pAdapter->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
4408 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DEAUTHENTICATION (Reason=%d)\n", pInfo->Reason));
4410 break;
4411 case OID_802_11_DROP_UNENCRYPTED:
4412 if (wrq->u.data.length != sizeof(int))
4413 Status = -EINVAL;
4414 else
4416 int enabled = 0;
4417 Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
4418 if (enabled == 1)
4419 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
4420 else
4421 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
4422 NdisAcquireSpinLock(&pAdapter->MacTabLock);
4423 pAdapter->MacTab.Content[BSSID_WCID].PortSecured = pAdapter->StaCfg.PortSecured;
4424 NdisReleaseSpinLock(&pAdapter->MacTabLock);
4425 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DROP_UNENCRYPTED (=%d)\n", enabled));
4427 break;
4428 case OID_802_11_SET_IEEE8021X:
4429 if (wrq->u.data.length != sizeof(BOOLEAN))
4430 Status = -EINVAL;
4431 else
4433 Status = copy_from_user(&IEEE8021xState, wrq->u.data.pointer, wrq->u.data.length);
4434 pAdapter->StaCfg.IEEE8021X = IEEE8021xState;
4435 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X (=%d)\n", IEEE8021xState));
4437 break;
4438 case OID_802_11_SET_IEEE8021X_REQUIRE_KEY:
4439 if (wrq->u.data.length != sizeof(BOOLEAN))
4440 Status = -EINVAL;
4441 else
4443 Status = copy_from_user(&IEEE8021x_required_keys, wrq->u.data.pointer, wrq->u.data.length);
4444 pAdapter->StaCfg.IEEE8021x_required_keys = IEEE8021x_required_keys;
4445 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X_REQUIRE_KEY (%d)\n", IEEE8021x_required_keys));
4447 break;
4448 case OID_802_11_PMKID:
4449 pPmkId = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4451 if(pPmkId == NULL) {
4452 Status = -ENOMEM;
4453 break;
4455 Status = copy_from_user(pPmkId, wrq->u.data.pointer, wrq->u.data.length);
4457 // check the PMKID information
4458 if (pPmkId->BSSIDInfoCount == 0)
4459 NdisZeroMemory(pAdapter->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
4460 else
4462 PBSSID_INFO pBssIdInfo;
4463 UINT BssIdx;
4464 UINT CachedIdx;
4466 for (BssIdx = 0; BssIdx < pPmkId->BSSIDInfoCount; BssIdx++)
4468 // point to the indexed BSSID_INFO structure
4469 pBssIdInfo = (PBSSID_INFO) ((PUCHAR) pPmkId + 2 * sizeof(UINT) + BssIdx * sizeof(BSSID_INFO));
4470 // Find the entry in the saved data base.
4471 for (CachedIdx = 0; CachedIdx < pAdapter->StaCfg.SavedPMKNum; CachedIdx++)
4473 // compare the BSSID
4474 if (NdisEqualMemory(pBssIdInfo->BSSID, pAdapter->StaCfg.SavedPMK[CachedIdx].BSSID, sizeof(NDIS_802_11_MAC_ADDRESS)))
4475 break;
4478 // Found, replace it
4479 if (CachedIdx < PMKID_NO)
4481 DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
4482 NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
4483 pAdapter->StaCfg.SavedPMKNum++;
4485 // Not found, replace the last one
4486 else
4488 // Randomly replace one
4489 CachedIdx = (pBssIdInfo->BSSID[5] % PMKID_NO);
4490 DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
4491 NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
4495 if(pPmkId)
4496 kfree(pPmkId);
4497 break;
4498 #endif // WPA_SUPPLICANT_SUPPORT //
4502 #ifdef SNMP_SUPPORT
4503 case OID_802_11_SHORTRETRYLIMIT:
4504 if (wrq->u.data.length != sizeof(ULONG))
4505 Status = -EINVAL;
4506 else
4508 Status = copy_from_user(&ShortRetryLimit, wrq->u.data.pointer, wrq->u.data.length);
4509 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
4510 tx_rty_cfg.field.ShortRtyLimit = ShortRetryLimit;
4511 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
4512 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SHORTRETRYLIMIT (tx_rty_cfg.field.ShortRetryLimit=%d, ShortRetryLimit=%ld)\n", tx_rty_cfg.field.ShortRtyLimit, ShortRetryLimit));
4514 break;
4516 case OID_802_11_LONGRETRYLIMIT:
4517 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_LONGRETRYLIMIT \n"));
4518 if (wrq->u.data.length != sizeof(ULONG))
4519 Status = -EINVAL;
4520 else
4522 Status = copy_from_user(&LongRetryLimit, wrq->u.data.pointer, wrq->u.data.length);
4523 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
4524 tx_rty_cfg.field.LongRtyLimit = LongRetryLimit;
4525 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
4526 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_LONGRETRYLIMIT (tx_rty_cfg.field.LongRetryLimit= %d,LongRetryLimit=%ld)\n", tx_rty_cfg.field.LongRtyLimit, LongRetryLimit));
4528 break;
4530 case OID_802_11_WEPDEFAULTKEYVALUE:
4531 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEPDEFAULTKEYVALUE\n"));
4532 pKey = kmalloc(wrq->u.data.length, GFP_KERNEL);
4533 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
4534 //pKey = &WepKey;
4536 if ( pKey->Length != wrq->u.data.length)
4538 Status = -EINVAL;
4539 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEPDEFAULTKEYVALUE, Failed!!\n"));
4541 KeyIdx = pKey->KeyIndex & 0x0fffffff;
4542 DBGPRINT(RT_DEBUG_TRACE,("pKey->KeyIndex =%d, pKey->KeyLength=%d\n", pKey->KeyIndex, pKey->KeyLength));
4544 // it is a shared key
4545 if (KeyIdx > 4)
4546 Status = -EINVAL;
4547 else
4549 pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen = (UCHAR) pKey->KeyLength;
4550 NdisMoveMemory(&pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key, &pKey->KeyMaterial, pKey->KeyLength);
4551 if (pKey->KeyIndex & 0x80000000)
4553 // Default key for tx (shared key)
4554 pAdapter->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
4556 //RestartAPIsRequired = TRUE;
4558 break;
4561 case OID_802_11_WEPDEFAULTKEYID:
4562 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEPDEFAULTKEYID \n"));
4564 if (wrq->u.data.length != sizeof(UCHAR))
4565 Status = -EINVAL;
4566 else
4567 Status = copy_from_user(&pAdapter->StaCfg.DefaultKeyId, wrq->u.data.pointer, wrq->u.data.length);
4569 break;
4572 case OID_802_11_CURRENTCHANNEL:
4573 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_CURRENTCHANNEL \n"));
4574 if (wrq->u.data.length != sizeof(UCHAR))
4575 Status = -EINVAL;
4576 else
4578 Status = copy_from_user(&ctmp, wrq->u.data.pointer, wrq->u.data.length);
4579 sprintf(&ctmp,"%d", ctmp);
4580 Set_Channel_Proc(pAdapter, &ctmp);
4582 break;
4583 #endif
4587 default:
4588 DBGPRINT(RT_DEBUG_TRACE, ("Set::unknown IOCTL's subcmd = 0x%08x\n", cmd));
4589 Status = -EOPNOTSUPP;
4590 break;
4594 return Status;
4597 INT RTMPQueryInformation(
4598 IN PRTMP_ADAPTER pAdapter,
4599 IN OUT struct ifreq *rq,
4600 IN INT cmd)
4602 struct iwreq *wrq = (struct iwreq *) rq;
4603 NDIS_802_11_BSSID_LIST_EX *pBssidList = NULL;
4604 PNDIS_WLAN_BSSID_EX pBss;
4605 NDIS_802_11_SSID Ssid;
4606 NDIS_802_11_CONFIGURATION *pConfiguration = NULL;
4607 RT_802_11_LINK_STATUS *pLinkStatus = NULL;
4608 RT_802_11_STA_CONFIG *pStaConfig = NULL;
4609 NDIS_802_11_STATISTICS *pStatistics = NULL;
4610 NDIS_802_11_RTS_THRESHOLD RtsThresh;
4611 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
4612 NDIS_802_11_POWER_MODE PowerMode;
4613 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
4614 RT_802_11_PREAMBLE PreamType;
4615 NDIS_802_11_AUTHENTICATION_MODE AuthMode;
4616 NDIS_802_11_WEP_STATUS WepStatus;
4617 NDIS_MEDIA_STATE MediaState;
4618 ULONG BssBufSize, ulInfo=0, NetworkTypeList[4], apsd = 0;
4619 USHORT BssLen = 0;
4620 PUCHAR pBuf = NULL, pPtr;
4621 INT Status = NDIS_STATUS_SUCCESS;
4622 UINT we_version_compiled;
4623 UCHAR i, Padding = 0;
4624 BOOLEAN RadioState;
4625 UCHAR driverVersion[8];
4626 OID_SET_HT_PHYMODE *pHTPhyMode = NULL;
4629 #ifdef SNMP_SUPPORT
4630 //for snmp, kathy
4631 DefaultKeyIdxValue *pKeyIdxValue;
4632 INT valueLen;
4633 TX_RTY_CFG_STRUC tx_rty_cfg;
4634 ULONG ShortRetryLimit, LongRetryLimit;
4635 UCHAR tmp[64];
4636 #endif //SNMP
4638 switch(cmd)
4640 case RT_OID_DEVICE_NAME:
4641 wrq->u.data.length = sizeof(STA_NIC_DEVICE_NAME);
4642 Status = copy_to_user(wrq->u.data.pointer, STA_NIC_DEVICE_NAME, wrq->u.data.length);
4643 break;
4644 case RT_OID_VERSION_INFO:
4645 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_VERSION_INFO \n"));
4646 wrq->u.data.length = 8*sizeof(UCHAR);
4647 sprintf(&driverVersion[0], "%s", STA_DRIVER_VERSION);
4648 driverVersion[7] = '\0';
4649 if (copy_to_user(wrq->u.data.pointer, &driverVersion, wrq->u.data.length))
4651 Status = -EFAULT;
4653 break;
4654 #ifdef RALINK_ATE
4655 case RT_QUERY_ATE_TXDONE_COUNT:
4656 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_QUERY_ATE_TXDONE_COUNT \n"));
4657 wrq->u.data.length = sizeof(UINT32);
4658 if (copy_to_user(wrq->u.data.pointer, &pAdapter->ate.TxDoneCount, wrq->u.data.length))
4660 Status = -EFAULT;
4662 break;
4663 #endif // RALINK_ATE //
4664 case OID_802_11_BSSID_LIST:
4665 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
4668 * Still scanning, indicate the caller should try again.
4670 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (Still scanning)\n"));
4671 return -EAGAIN;
4673 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (%d BSS returned)\n",pAdapter->ScanTab.BssNr));
4674 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
4675 // Claculate total buffer size required
4676 BssBufSize = sizeof(ULONG);
4678 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
4680 // Align pointer to 4 bytes boundary.
4681 //Padding = 4 - (pAdapter->ScanTab.BssEntry[i].VarIELen & 0x0003);
4682 //if (Padding == 4)
4683 // Padding = 0;
4684 BssBufSize += (sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
4687 // For safety issue, we add 256 bytes just in case
4688 BssBufSize += 256;
4689 // Allocate the same size as passed from higher layer
4690 pBuf = kmalloc(BssBufSize, MEM_ALLOC_FLAG);
4691 if(pBuf == NULL)
4693 Status = -ENOMEM;
4694 break;
4696 // Init 802_11_BSSID_LIST_EX structure
4697 NdisZeroMemory(pBuf, BssBufSize);
4698 pBssidList = (PNDIS_802_11_BSSID_LIST_EX) pBuf;
4699 pBssidList->NumberOfItems = pAdapter->ScanTab.BssNr;
4701 // Calculate total buffer length
4702 BssLen = 4; // Consist of NumberOfItems
4703 // Point to start of NDIS_WLAN_BSSID_EX
4704 // pPtr = pBuf + sizeof(ULONG);
4705 pPtr = (PUCHAR) &pBssidList->Bssid[0];
4706 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
4708 pBss = (PNDIS_WLAN_BSSID_EX) pPtr;
4709 NdisMoveMemory(&pBss->MacAddress, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
4710 if ((pAdapter->ScanTab.BssEntry[i].Hidden == 1) && (pAdapter->StaCfg.bShowHiddenSSID == FALSE))
4713 // We must return this SSID during 4way handshaking, otherwise Aegis will failed to parse WPA infomation
4714 // and then failed to send EAPOl farame.
4716 if ((pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) && (pAdapter->StaCfg.PortSecured != WPA_802_1X_PORT_SECURED))
4718 pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
4719 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
4721 else
4722 pBss->Ssid.SsidLength = 0;
4724 else
4726 pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
4727 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
4729 pBss->Privacy = pAdapter->ScanTab.BssEntry[i].Privacy;
4730 pBss->Rssi = pAdapter->ScanTab.BssEntry[i].Rssi - pAdapter->BbpRssiToDbmDelta;
4731 pBss->NetworkTypeInUse = NetworkTypeInUseSanity(&pAdapter->ScanTab.BssEntry[i]);
4732 pBss->Configuration.Length = sizeof(NDIS_802_11_CONFIGURATION);
4733 pBss->Configuration.BeaconPeriod = pAdapter->ScanTab.BssEntry[i].BeaconPeriod;
4734 pBss->Configuration.ATIMWindow = pAdapter->ScanTab.BssEntry[i].AtimWin;
4736 MAP_CHANNEL_ID_TO_KHZ(pAdapter->ScanTab.BssEntry[i].Channel, pBss->Configuration.DSConfig);
4738 if (pAdapter->ScanTab.BssEntry[i].BssType == BSS_INFRA)
4739 pBss->InfrastructureMode = Ndis802_11Infrastructure;
4740 else
4741 pBss->InfrastructureMode = Ndis802_11IBSS;
4743 NdisMoveMemory(pBss->SupportedRates, pAdapter->ScanTab.BssEntry[i].SupRate, pAdapter->ScanTab.BssEntry[i].SupRateLen);
4744 NdisMoveMemory(pBss->SupportedRates + pAdapter->ScanTab.BssEntry[i].SupRateLen,
4745 pAdapter->ScanTab.BssEntry[i].ExtRate,
4746 pAdapter->ScanTab.BssEntry[i].ExtRateLen);
4748 if (pAdapter->ScanTab.BssEntry[i].VarIELen == 0)
4750 pBss->IELength = sizeof(NDIS_802_11_FIXED_IEs);
4751 NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
4752 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
4754 else
4756 pBss->IELength = (ULONG)(sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen);
4757 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
4758 NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
4759 NdisMoveMemory(pBss->IEs + sizeof(NDIS_802_11_FIXED_IEs), pAdapter->ScanTab.BssEntry[i].VarIEs, pAdapter->ScanTab.BssEntry[i].VarIELen);
4760 pPtr += pAdapter->ScanTab.BssEntry[i].VarIELen;
4762 pBss->Length = (ULONG)(sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
4764 #if WIRELESS_EXT < 17
4765 if ((BssLen + pBss->Length) < wrq->u.data.length)
4766 BssLen += pBss->Length;
4767 else
4769 pBssidList->NumberOfItems = i;
4770 break;
4772 #else
4773 BssLen += pBss->Length;
4774 #endif
4777 #if WIRELESS_EXT < 17
4778 wrq->u.data.length = BssLen;
4779 #else
4780 if (BssLen > wrq->u.data.length)
4782 kfree(pBssidList);
4783 return -E2BIG;
4785 else
4786 wrq->u.data.length = BssLen;
4787 #endif
4788 Status = copy_to_user(wrq->u.data.pointer, pBssidList, BssLen);
4789 kfree(pBssidList);
4790 break;
4791 case OID_802_3_CURRENT_ADDRESS:
4792 wrq->u.data.length = MAC_ADDR_LEN;
4793 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
4794 break;
4795 case OID_GEN_MEDIA_CONNECT_STATUS:
4796 if (pAdapter->IndicateMediaState == NdisMediaStateConnected)
4797 MediaState = NdisMediaStateConnected;
4798 else
4799 MediaState = NdisMediaStateDisconnected;
4801 wrq->u.data.length = sizeof(NDIS_MEDIA_STATE);
4802 Status = copy_to_user(wrq->u.data.pointer, &MediaState, wrq->u.data.length);
4803 break;
4804 case OID_802_11_BSSID:
4805 #ifdef RALINK_ATE
4806 if (ATE_ON(pAdapter))
4808 DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
4809 Status = NDIS_STATUS_RESOURCES;
4810 break;
4812 #endif // RALINK_ATE //
4813 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
4815 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Bssid, sizeof(NDIS_802_11_MAC_ADDRESS));
4818 else
4820 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID(=EMPTY)\n"));
4821 Status = -ENOTCONN;
4823 break;
4824 case OID_802_11_SSID:
4825 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
4826 NdisZeroMemory(Ssid.Ssid, MAX_LEN_OF_SSID);
4827 Ssid.SsidLength = pAdapter->CommonCfg.SsidLen;
4828 memcpy(Ssid.Ssid, pAdapter->CommonCfg.Ssid, Ssid.SsidLength);
4829 wrq->u.data.length = sizeof(NDIS_802_11_SSID);
4830 Status = copy_to_user(wrq->u.data.pointer, &Ssid, wrq->u.data.length);
4831 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_SSID (Len=%d, ssid=%s)\n", Ssid.SsidLength,Ssid.Ssid));
4832 break;
4833 case RT_OID_802_11_QUERY_LINK_STATUS:
4834 pLinkStatus = (RT_802_11_LINK_STATUS *) kmalloc(sizeof(RT_802_11_LINK_STATUS), MEM_ALLOC_FLAG);
4835 if (pLinkStatus)
4837 pLinkStatus->CurrTxRate = RateIdTo500Kbps[pAdapter->CommonCfg.TxRate]; // unit : 500 kbps
4838 pLinkStatus->ChannelQuality = pAdapter->Mlme.ChannelQuality;
4839 pLinkStatus->RxByteCount = pAdapter->RalinkCounters.ReceivedByteCount;
4840 pLinkStatus->TxByteCount = pAdapter->RalinkCounters.TransmittedByteCount;
4841 pLinkStatus->CentralChannel = pAdapter->CommonCfg.CentralChannel;
4842 wrq->u.data.length = sizeof(RT_802_11_LINK_STATUS);
4843 Status = copy_to_user(wrq->u.data.pointer, pLinkStatus, wrq->u.data.length);
4844 kfree(pLinkStatus);
4845 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS\n"));
4847 else
4849 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS(kmalloc failed)\n"));
4850 Status = -EFAULT;
4852 break;
4853 case OID_802_11_CONFIGURATION:
4854 pConfiguration = (NDIS_802_11_CONFIGURATION *) kmalloc(sizeof(NDIS_802_11_CONFIGURATION), MEM_ALLOC_FLAG);
4855 if (pConfiguration)
4857 pConfiguration->Length = sizeof(NDIS_802_11_CONFIGURATION);
4858 pConfiguration->BeaconPeriod = pAdapter->CommonCfg.BeaconPeriod;
4859 pConfiguration->ATIMWindow = pAdapter->StaActive.AtimWin;
4860 MAP_CHANNEL_ID_TO_KHZ(pAdapter->CommonCfg.Channel, pConfiguration->DSConfig);
4861 wrq->u.data.length = sizeof(NDIS_802_11_CONFIGURATION);
4862 Status = copy_to_user(wrq->u.data.pointer, pConfiguration, wrq->u.data.length);
4863 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(BeaconPeriod=%ld,AtimW=%ld,Channel=%d) \n",
4864 pConfiguration->BeaconPeriod, pConfiguration->ATIMWindow, pAdapter->CommonCfg.Channel));
4865 kfree(pConfiguration);
4867 else
4869 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(kmalloc failed)\n"));
4870 Status = -EFAULT;
4872 break;
4873 case RT_OID_802_11_SNR_0:
4874 if ((pAdapter->StaCfg.LastSNR0 > 0))
4876 ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR0) * 3) / 16 ;
4877 wrq->u.data.length = sizeof(ulInfo);
4878 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4879 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_SNR_0(0x=%lx)\n", ulInfo));
4881 else
4882 Status = -EFAULT;
4883 break;
4884 case RT_OID_802_11_SNR_1:
4885 if ((pAdapter->Antenna.field.RxPath > 1) &&
4886 (pAdapter->StaCfg.LastSNR1 > 0))
4888 ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR1) * 3) / 16 ;
4889 wrq->u.data.length = sizeof(ulInfo);
4890 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4891 DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(0x=%lx)\n",ulInfo));
4893 else
4894 Status = -EFAULT;
4895 DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(pAdapter->StaCfg.LastSNR1=%d)\n",pAdapter->StaCfg.LastSNR1));
4896 break;
4897 case OID_802_11_RSSI_TRIGGER:
4898 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0 - pAdapter->BbpRssiToDbmDelta;
4899 wrq->u.data.length = sizeof(ulInfo);
4900 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4901 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RSSI_TRIGGER(=%ld)\n", ulInfo));
4902 break;
4903 case OID_802_11_RSSI:
4904 case RT_OID_802_11_RSSI:
4905 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0;
4906 wrq->u.data.length = sizeof(ulInfo);
4907 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4908 break;
4909 case RT_OID_802_11_RSSI_1:
4910 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi1;
4911 wrq->u.data.length = sizeof(ulInfo);
4912 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4913 break;
4914 case RT_OID_802_11_RSSI_2:
4915 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi2;
4916 wrq->u.data.length = sizeof(ulInfo);
4917 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4918 break;
4919 case OID_802_11_STATISTICS:
4920 pStatistics = (NDIS_802_11_STATISTICS *) kmalloc(sizeof(NDIS_802_11_STATISTICS), MEM_ALLOC_FLAG);
4921 if (pStatistics)
4923 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS \n"));
4924 // add the most up-to-date h/w raw counters into software counters
4925 NICUpdateRawCounters(pAdapter);
4927 // Sanity check for calculation of sucessful count
4928 if (pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart < pAdapter->WlanCounters.RetryCount.QuadPart)
4929 pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
4931 pStatistics->TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart;
4932 pStatistics->MulticastTransmittedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastTransmittedFrameCount.QuadPart;
4933 pStatistics->FailedCount.QuadPart = pAdapter->WlanCounters.FailedCount.QuadPart;
4934 pStatistics->RetryCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
4935 pStatistics->MultipleRetryCount.QuadPart = pAdapter->WlanCounters.MultipleRetryCount.QuadPart;
4936 pStatistics->RTSSuccessCount.QuadPart = pAdapter->WlanCounters.RTSSuccessCount.QuadPart;
4937 pStatistics->RTSFailureCount.QuadPart = pAdapter->WlanCounters.RTSFailureCount.QuadPart;
4938 pStatistics->ACKFailureCount.QuadPart = pAdapter->WlanCounters.ACKFailureCount.QuadPart;
4939 pStatistics->FrameDuplicateCount.QuadPart = pAdapter->WlanCounters.FrameDuplicateCount.QuadPart;
4940 pStatistics->ReceivedFragmentCount.QuadPart = pAdapter->WlanCounters.ReceivedFragmentCount.QuadPart;
4941 pStatistics->MulticastReceivedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastReceivedFrameCount.QuadPart;
4942 #ifdef DBG
4943 pStatistics->FCSErrorCount = pAdapter->RalinkCounters.RealFcsErrCount;
4944 #else
4945 pStatistics->FCSErrorCount.QuadPart = pAdapter->WlanCounters.FCSErrorCount.QuadPart;
4946 pStatistics->FrameDuplicateCount.u.LowPart = pAdapter->WlanCounters.FrameDuplicateCount.u.LowPart / 100;
4947 #endif
4948 wrq->u.data.length = sizeof(NDIS_802_11_STATISTICS);
4949 Status = copy_to_user(wrq->u.data.pointer, pStatistics, wrq->u.data.length);
4950 kfree(pStatistics);
4952 else
4954 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS(kmalloc failed)\n"));
4955 Status = -EFAULT;
4957 break;
4958 case OID_GEN_RCV_OK:
4959 ulInfo = pAdapter->Counters8023.GoodReceives;
4960 wrq->u.data.length = sizeof(ulInfo);
4961 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4962 break;
4963 case OID_GEN_RCV_NO_BUFFER:
4964 ulInfo = pAdapter->Counters8023.RxNoBuffer;
4965 wrq->u.data.length = sizeof(ulInfo);
4966 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4967 break;
4968 case RT_OID_802_11_PHY_MODE:
4969 ulInfo = (ULONG)pAdapter->CommonCfg.PhyMode;
4970 wrq->u.data.length = sizeof(ulInfo);
4971 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4972 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PHY_MODE (=%ld)\n", ulInfo));
4973 break;
4974 case RT_OID_802_11_STA_CONFIG:
4975 pStaConfig = (RT_802_11_STA_CONFIG *) kmalloc(sizeof(RT_802_11_STA_CONFIG), MEM_ALLOC_FLAG);
4976 if (pStaConfig)
4978 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG\n"));
4979 pStaConfig->EnableTxBurst = pAdapter->CommonCfg.bEnableTxBurst;
4980 pStaConfig->EnableTurboRate = 0;
4981 pStaConfig->UseBGProtection = pAdapter->CommonCfg.UseBGProtection;
4982 pStaConfig->UseShortSlotTime = pAdapter->CommonCfg.bUseShortSlotTime;
4983 //pStaConfig->AdhocMode = pAdapter->StaCfg.AdhocMode;
4984 pStaConfig->HwRadioStatus = (pAdapter->StaCfg.bHwRadio == TRUE) ? 1 : 0;
4985 pStaConfig->Rsv1 = 0;
4986 pStaConfig->SystemErrorBitmap = pAdapter->SystemErrorBitmap;
4987 wrq->u.data.length = sizeof(RT_802_11_STA_CONFIG);
4988 Status = copy_to_user(wrq->u.data.pointer, pStaConfig, wrq->u.data.length);
4989 kfree(pStaConfig);
4991 else
4993 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
4994 Status = -EFAULT;
4996 break;
4997 case OID_802_11_RTS_THRESHOLD:
4998 RtsThresh = pAdapter->CommonCfg.RtsThreshold;
4999 wrq->u.data.length = sizeof(RtsThresh);
5000 Status = copy_to_user(wrq->u.data.pointer, &RtsThresh, wrq->u.data.length);
5001 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RTS_THRESHOLD(=%ld)\n", RtsThresh));
5002 break;
5003 case OID_802_11_FRAGMENTATION_THRESHOLD:
5004 FragThresh = pAdapter->CommonCfg.FragmentThreshold;
5005 if (pAdapter->CommonCfg.bUseZeroToDisableFragment == TRUE)
5006 FragThresh = 0;
5007 wrq->u.data.length = sizeof(FragThresh);
5008 Status = copy_to_user(wrq->u.data.pointer, &FragThresh, wrq->u.data.length);
5009 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_FRAGMENTATION_THRESHOLD(=%ld)\n", FragThresh));
5010 break;
5011 case OID_802_11_POWER_MODE:
5012 PowerMode = pAdapter->StaCfg.WindowsPowerMode;
5013 wrq->u.data.length = sizeof(PowerMode);
5014 Status = copy_to_user(wrq->u.data.pointer, &PowerMode, wrq->u.data.length);
5015 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_POWER_MODE(=%d)\n", PowerMode));
5016 break;
5017 case RT_OID_802_11_RADIO:
5018 RadioState = (BOOLEAN) pAdapter->StaCfg.bSwRadio;
5019 wrq->u.data.length = sizeof(RadioState);
5020 Status = copy_to_user(wrq->u.data.pointer, &RadioState, wrq->u.data.length);
5021 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_RADIO (=%d)\n", RadioState));
5022 break;
5023 case OID_802_11_INFRASTRUCTURE_MODE:
5024 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
5025 BssType = Ndis802_11IBSS;
5026 else if (pAdapter->StaCfg.BssType == BSS_INFRA)
5027 BssType = Ndis802_11Infrastructure;
5028 else if (pAdapter->StaCfg.BssType == BSS_MONITOR)
5029 BssType = Ndis802_11Monitor;
5030 else
5031 BssType = Ndis802_11AutoUnknown;
5033 wrq->u.data.length = sizeof(BssType);
5034 Status = copy_to_user(wrq->u.data.pointer, &BssType, wrq->u.data.length);
5035 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_INFRASTRUCTURE_MODE(=%d)\n", BssType));
5036 break;
5037 case RT_OID_802_11_PREAMBLE:
5038 PreamType = pAdapter->CommonCfg.TxPreamble;
5039 wrq->u.data.length = sizeof(PreamType);
5040 Status = copy_to_user(wrq->u.data.pointer, &PreamType, wrq->u.data.length);
5041 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PREAMBLE(=%d)\n", PreamType));
5042 break;
5043 case OID_802_11_AUTHENTICATION_MODE:
5044 AuthMode = pAdapter->StaCfg.AuthMode;
5045 wrq->u.data.length = sizeof(AuthMode);
5046 Status = copy_to_user(wrq->u.data.pointer, &AuthMode, wrq->u.data.length);
5047 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_AUTHENTICATION_MODE(=%d)\n", AuthMode));
5048 break;
5049 case OID_802_11_WEP_STATUS:
5050 WepStatus = pAdapter->StaCfg.WepStatus;
5051 wrq->u.data.length = sizeof(WepStatus);
5052 Status = copy_to_user(wrq->u.data.pointer, &WepStatus, wrq->u.data.length);
5053 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_WEP_STATUS(=%d)\n", WepStatus));
5054 break;
5055 case OID_802_11_TX_POWER_LEVEL:
5056 wrq->u.data.length = sizeof(ULONG);
5057 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPower, wrq->u.data.length);
5058 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_TX_POWER_LEVEL %x\n",pAdapter->CommonCfg.TxPower));
5059 break;
5060 case RT_OID_802_11_TX_POWER_LEVEL_1:
5061 wrq->u.data.length = sizeof(ULONG);
5062 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPowerPercentage, wrq->u.data.length);
5063 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
5064 break;
5065 case OID_802_11_NETWORK_TYPES_SUPPORTED:
5066 if ((pAdapter->RfIcType == RFIC_2850) || (pAdapter->RfIcType == RFIC_2750))
5068 NetworkTypeList[0] = 3; // NumberOfItems = 3
5069 NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
5070 NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
5071 NetworkTypeList[3] = Ndis802_11OFDM5; // NetworkType[3] = 11a
5072 wrq->u.data.length = 16;
5073 Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
5075 else
5077 NetworkTypeList[0] = 2; // NumberOfItems = 2
5078 NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
5079 NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
5080 wrq->u.data.length = 12;
5081 Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
5083 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_NETWORK_TYPES_SUPPORTED\n"));
5084 break;
5085 case OID_802_11_NETWORK_TYPE_IN_USE:
5086 wrq->u.data.length = sizeof(ULONG);
5087 if (pAdapter->CommonCfg.PhyMode == PHY_11A)
5088 ulInfo = Ndis802_11OFDM5;
5089 else if ((pAdapter->CommonCfg.PhyMode == PHY_11BG_MIXED) || (pAdapter->CommonCfg.PhyMode == PHY_11G))
5090 ulInfo = Ndis802_11OFDM24;
5091 else
5092 ulInfo = Ndis802_11DS;
5093 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
5094 break;
5095 case RT_OID_802_11_QUERY_LAST_RX_RATE:
5096 ulInfo = (ULONG)pAdapter->LastRxRate;
5097 wrq->u.data.length = sizeof(ulInfo);
5098 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
5099 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_RX_RATE (=%ld)\n", ulInfo));
5100 break;
5101 case RT_OID_802_11_QUERY_LAST_TX_RATE:
5102 //ulInfo = (ULONG)pAdapter->LastTxRate;
5103 ulInfo = (ULONG)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word;
5104 wrq->u.data.length = sizeof(ulInfo);
5105 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
5106 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_TX_RATE (=%lx)\n", ulInfo));
5107 break;
5108 case RT_OID_802_11_QUERY_EEPROM_VERSION:
5109 wrq->u.data.length = sizeof(ULONG);
5110 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->EepromVersion, wrq->u.data.length);
5111 break;
5112 case RT_OID_802_11_QUERY_FIRMWARE_VERSION:
5113 wrq->u.data.length = sizeof(ULONG);
5114 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->FirmwareVersion, wrq->u.data.length);
5115 break;
5116 case RT_OID_802_11_QUERY_NOISE_LEVEL:
5117 wrq->u.data.length = sizeof(UCHAR);
5118 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->BbpWriteLatch[66], wrq->u.data.length);
5119 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_NOISE_LEVEL (=%d)\n", pAdapter->BbpWriteLatch[66]));
5120 break;
5121 case RT_OID_802_11_EXTRA_INFO:
5122 wrq->u.data.length = sizeof(ULONG);
5123 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->ExtraInfo, wrq->u.data.length);
5124 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_EXTRA_INFO (=%ld)\n", pAdapter->ExtraInfo));
5125 break;
5126 case RT_OID_WE_VERSION_COMPILED:
5127 wrq->u.data.length = sizeof(UINT);
5128 we_version_compiled = WIRELESS_EXT;
5129 Status = copy_to_user(wrq->u.data.pointer, &we_version_compiled, wrq->u.data.length);
5130 break;
5131 case RT_OID_802_11_QUERY_APSD_SETTING:
5132 apsd = (pAdapter->CommonCfg.bAPSDCapable | (pAdapter->CommonCfg.bAPSDAC_BE << 1) | (pAdapter->CommonCfg.bAPSDAC_BK << 2)
5133 | (pAdapter->CommonCfg.bAPSDAC_VI << 3) | (pAdapter->CommonCfg.bAPSDAC_VO << 4) | (pAdapter->CommonCfg.MaxSPLength << 5));
5135 wrq->u.data.length = sizeof(ULONG);
5136 Status = copy_to_user(wrq->u.data.pointer, &apsd, wrq->u.data.length);
5137 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",
5138 apsd,pAdapter->CommonCfg.bAPSDCapable,pAdapter->CommonCfg.bAPSDAC_BE,pAdapter->CommonCfg.bAPSDAC_BK,pAdapter->CommonCfg.bAPSDAC_VI,pAdapter->CommonCfg.bAPSDAC_VO,pAdapter->CommonCfg.MaxSPLength));
5139 break;
5140 case RT_OID_802_11_QUERY_APSD_PSM:
5141 wrq->u.data.length = sizeof(ULONG);
5142 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.length);
5143 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_APSD_PSM (=%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
5144 break;
5145 case RT_OID_802_11_QUERY_WMM:
5146 wrq->u.data.length = sizeof(BOOLEAN);
5147 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bWmmCapable, wrq->u.data.length);
5148 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_WMM (=%d)\n", pAdapter->CommonCfg.bWmmCapable));
5149 break;
5150 #ifdef WPA_SUPPLICANT_SUPPORT
5151 case RT_OID_NEW_DRIVER:
5153 UCHAR enabled = 1;
5154 wrq->u.data.length = sizeof(UCHAR);
5155 Status = copy_to_user(wrq->u.data.pointer, &enabled, wrq->u.data.length);
5156 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_NEW_DRIVER (=%d)\n", enabled));
5158 break;
5159 case RT_OID_WPA_SUPPLICANT_SUPPORT:
5160 wrq->u.data.length = sizeof(UCHAR);
5161 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->StaCfg.WpaSupplicantUP, wrq->u.data.length);
5162 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
5163 break;
5164 #endif // WPA_SUPPLICANT_SUPPORT //
5166 case RT_OID_DRIVER_DEVICE_NAME:
5167 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_DRIVER_DEVICE_NAME \n"));
5168 wrq->u.data.length = 16;
5169 if (copy_to_user(wrq->u.data.pointer, pAdapter->StaCfg.dev_name, wrq->u.data.length))
5171 Status = -EFAULT;
5173 break;
5174 case RT_OID_802_11_QUERY_HT_PHYMODE:
5175 pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
5176 if (pHTPhyMode)
5178 pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
5179 pHTPhyMode->HtMode = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE;
5180 pHTPhyMode->BW = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.BW;
5181 pHTPhyMode->MCS= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MCS;
5182 pHTPhyMode->SHORTGI= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.ShortGI;
5183 pHTPhyMode->STBC= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.STBC;
5185 pHTPhyMode->ExtOffset = ((pAdapter->CommonCfg.CentralChannel < pAdapter->CommonCfg.Channel) ? (EXTCHA_BELOW) : (EXTCHA_ABOVE));
5186 wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
5187 if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
5189 Status = -EFAULT;
5191 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
5192 pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
5193 DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
5195 else
5197 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
5198 Status = -EFAULT;
5200 break;
5201 case RT_OID_802_11_COUNTRY_REGION:
5202 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_COUNTRY_REGION \n"));
5203 wrq->u.data.length = sizeof(ulInfo);
5204 ulInfo = pAdapter->CommonCfg.CountryRegionForABand;
5205 ulInfo = (ulInfo << 8)|(pAdapter->CommonCfg.CountryRegion);
5206 if (copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length))
5208 Status = -EFAULT;
5210 break;
5211 case RT_OID_802_11_QUERY_DAT_HT_PHYMODE:
5212 pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
5213 if (pHTPhyMode)
5215 pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
5216 pHTPhyMode->HtMode = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.HTMODE;
5217 pHTPhyMode->BW = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.BW;
5218 pHTPhyMode->MCS= (UCHAR)pAdapter->StaCfg.DesiredTransmitSetting.field.MCS;
5219 pHTPhyMode->SHORTGI= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.ShortGI;
5220 pHTPhyMode->STBC= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.STBC;
5222 wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
5223 if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
5225 Status = -EFAULT;
5227 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
5228 pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
5229 DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
5231 else
5233 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
5234 Status = -EFAULT;
5236 break;
5237 case RT_OID_QUERY_MULTIPLE_CARD_SUPPORT:
5238 wrq->u.data.length = sizeof(UCHAR);
5239 i = 0;
5240 #ifdef MULTIPLE_CARD_SUPPORT
5241 i = 1;
5242 #endif // MULTIPLE_CARD_SUPPORT //
5243 if (copy_to_user(wrq->u.data.pointer, &i, wrq->u.data.length))
5245 Status = -EFAULT;
5247 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_QUERY_MULTIPLE_CARD_SUPPORT(=%d) \n", i));
5248 break;
5249 #ifdef SNMP_SUPPORT
5250 case RT_OID_802_11_MAC_ADDRESS:
5251 wrq->u.data.length = MAC_ADDR_LEN;
5252 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
5253 break;
5255 case RT_OID_802_11_MANUFACTUREROUI:
5256 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_MANUFACTUREROUI \n"));
5257 wrq->u.data.length = ManufacturerOUI_LEN;
5258 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
5259 break;
5261 case RT_OID_802_11_MANUFACTURERNAME:
5262 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_MANUFACTURERNAME \n"));
5263 wrq->u.data.length = strlen(ManufacturerNAME);
5264 Status = copy_to_user(wrq->u.data.pointer, ManufacturerNAME, wrq->u.data.length);
5265 break;
5267 case RT_OID_802_11_RESOURCETYPEIDNAME:
5268 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_RESOURCETYPEIDNAME \n"));
5269 wrq->u.data.length = strlen(ResourceTypeIdName);
5270 Status = copy_to_user(wrq->u.data.pointer, ResourceTypeIdName, wrq->u.data.length);
5271 break;
5273 case RT_OID_802_11_PRIVACYOPTIONIMPLEMENTED:
5274 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PRIVACYOPTIONIMPLEMENTED \n"));
5275 ulInfo = 1; // 1 is support wep else 2 is not support.
5276 wrq->u.data.length = sizeof(ulInfo);
5277 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
5278 break;
5280 case RT_OID_802_11_POWERMANAGEMENTMODE:
5281 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_POWERMANAGEMENTMODE \n"));
5282 if (pAdapter->StaCfg.Psm == PSMP_ACTION)
5283 ulInfo = 1; // 1 is power active else 2 is power save.
5284 else
5285 ulInfo = 2;
5287 wrq->u.data.length = sizeof(ulInfo);
5288 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
5289 break;
5291 case OID_802_11_WEPDEFAULTKEYVALUE:
5292 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_WEPDEFAULTKEYVALUE \n"));
5293 //KeyIdxValue.KeyIdx = pAd->PortCfg.MBSSID[pAd->IoctlIF].DefaultKeyId;
5294 pKeyIdxValue = wrq->u.data.pointer;
5295 DBGPRINT(RT_DEBUG_TRACE,("KeyIdxValue.KeyIdx = %d, \n",pKeyIdxValue->KeyIdx));
5296 valueLen = pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen;
5297 NdisMoveMemory(pKeyIdxValue->Value,
5298 &pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key,
5299 valueLen);
5300 pKeyIdxValue->Value[valueLen]='\0';
5302 wrq->u.data.length = sizeof(DefaultKeyIdxValue);
5304 Status = copy_to_user(wrq->u.data.pointer, pKeyIdxValue, wrq->u.data.length);
5305 DBGPRINT(RT_DEBUG_TRACE,("DefaultKeyId = %d, total len = %d, str len=%d, KeyValue= %02x %02x %02x %02x \n", pAdapter->StaCfg.DefaultKeyId, wrq->u.data.length, pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen,
5306 pAdapter->SharedKey[BSS0][0].Key[0],
5307 pAdapter->SharedKey[BSS0][1].Key[0],
5308 pAdapter->SharedKey[BSS0][2].Key[0],
5309 pAdapter->SharedKey[BSS0][3].Key[0]));
5310 break;
5312 case OID_802_11_WEPDEFAULTKEYID:
5313 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_WEPDEFAULTKEYID \n"));
5314 wrq->u.data.length = sizeof(UCHAR);
5315 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->StaCfg.DefaultKeyId, wrq->u.data.length);
5316 DBGPRINT(RT_DEBUG_TRACE, ("DefaultKeyId =%d \n", pAdapter->StaCfg.DefaultKeyId));
5317 break;
5319 case RT_OID_802_11_WEPKEYMAPPINGLENGTH:
5320 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_WEPKEYMAPPINGLENGTH \n"));
5321 wrq->u.data.length = sizeof(UCHAR);
5322 Status = copy_to_user(wrq->u.data.pointer,
5323 &pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen,
5324 wrq->u.data.length);
5325 break;
5327 case OID_802_11_SHORTRETRYLIMIT:
5328 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_SHORTRETRYLIMIT \n"));
5329 wrq->u.data.length = sizeof(ULONG);
5330 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
5331 ShortRetryLimit = tx_rty_cfg.field.ShortRtyLimit;
5332 DBGPRINT(RT_DEBUG_TRACE, ("ShortRetryLimit =%ld, tx_rty_cfg.field.ShortRetryLimit=%d\n", ShortRetryLimit, tx_rty_cfg.field.ShortRtyLimit));
5333 Status = copy_to_user(wrq->u.data.pointer, &ShortRetryLimit, wrq->u.data.length);
5334 break;
5336 case OID_802_11_LONGRETRYLIMIT:
5337 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_LONGRETRYLIMIT \n"));
5338 wrq->u.data.length = sizeof(ULONG);
5339 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
5340 LongRetryLimit = tx_rty_cfg.field.LongRtyLimit;
5341 DBGPRINT(RT_DEBUG_TRACE, ("LongRetryLimit =%ld, tx_rty_cfg.field.LongRtyLimit=%d\n", LongRetryLimit, tx_rty_cfg.field.LongRtyLimit));
5342 Status = copy_to_user(wrq->u.data.pointer, &LongRetryLimit, wrq->u.data.length);
5343 break;
5345 case RT_OID_802_11_PRODUCTID:
5346 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PRODUCTID \n"));
5348 #ifdef RT2870
5349 sprintf(tmp, "%04x %04x\n", ((POS_COOKIE)pAdapter->OS_Cookie)->pUsb_Dev->descriptor.idVendor ,((POS_COOKIE)pAdapter->OS_Cookie)->pUsb_Dev->descriptor.idProduct);
5351 #endif // RT2870 //
5352 wrq->u.data.length = strlen(tmp);
5353 Status = copy_to_user(wrq->u.data.pointer, tmp, wrq->u.data.length);
5354 break;
5356 case RT_OID_802_11_MANUFACTUREID:
5357 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_MANUFACTUREID \n"));
5358 wrq->u.data.length = strlen(ManufacturerNAME);
5359 Status = copy_to_user(wrq->u.data.pointer, ManufacturerNAME, wrq->u.data.length);
5360 break;
5362 case OID_802_11_CURRENTCHANNEL:
5363 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CURRENTCHANNEL \n"));
5364 wrq->u.data.length = sizeof(UCHAR);
5365 DBGPRINT(RT_DEBUG_TRACE, ("sizeof UCHAR=%d, channel=%d \n", sizeof(UCHAR), pAdapter->CommonCfg.Channel));
5366 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Channel, wrq->u.data.length);
5367 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5368 break;
5369 #endif //SNMP_SUPPORT
5371 case OID_802_11_BUILD_CHANNEL_EX:
5373 UCHAR value;
5374 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BUILD_CHANNEL_EX \n"));
5375 wrq->u.data.length = sizeof(UCHAR);
5376 #ifdef EXT_BUILD_CHANNEL_LIST
5377 DBGPRINT(RT_DEBUG_TRACE, ("Support EXT_BUILD_CHANNEL_LIST.\n"));
5378 value = 1;
5379 #else
5380 DBGPRINT(RT_DEBUG_TRACE, ("Doesn't support EXT_BUILD_CHANNEL_LIST.\n"));
5381 value = 0;
5382 #endif // EXT_BUILD_CHANNEL_LIST //
5383 Status = copy_to_user(wrq->u.data.pointer, &value, 1);
5384 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5386 break;
5388 case OID_802_11_GET_CH_LIST:
5390 PRT_CHANNEL_LIST_INFO pChListBuf;
5392 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CH_LIST \n"));
5393 if (pAdapter->ChannelListNum == 0)
5395 wrq->u.data.length = 0;
5396 break;
5399 pChListBuf = (RT_CHANNEL_LIST_INFO *) kmalloc(sizeof(RT_CHANNEL_LIST_INFO), MEM_ALLOC_FLAG);
5400 if (pChListBuf == NULL)
5402 wrq->u.data.length = 0;
5403 break;
5406 pChListBuf->ChannelListNum = pAdapter->ChannelListNum;
5407 for (i = 0; i < pChListBuf->ChannelListNum; i++)
5408 pChListBuf->ChannelList[i] = pAdapter->ChannelList[i].Channel;
5410 wrq->u.data.length = sizeof(RT_CHANNEL_LIST_INFO);
5411 Status = copy_to_user(wrq->u.data.pointer, pChListBuf, sizeof(RT_CHANNEL_LIST_INFO));
5412 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5414 if (pChListBuf)
5415 kfree(pChListBuf);
5417 break;
5419 case OID_802_11_GET_COUNTRY_CODE:
5420 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_COUNTRY_CODE \n"));
5421 wrq->u.data.length = 2;
5422 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.CountryCode, 2);
5423 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5424 break;
5426 case OID_802_11_GET_CHANNEL_GEOGRAPHY:
5427 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CHANNEL_GEOGRAPHY \n"));
5428 wrq->u.data.length = 1;
5429 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Geography, 1);
5430 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5431 break;
5434 #ifdef QOS_DLS_SUPPORT
5435 case RT_OID_802_11_QUERY_DLS:
5436 wrq->u.data.length = sizeof(BOOLEAN);
5437 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bDLSCapable, wrq->u.data.length);
5438 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_DLS(=%d)\n", pAdapter->CommonCfg.bDLSCapable));
5439 break;
5441 case RT_OID_802_11_QUERY_DLS_PARAM:
5443 PRT_802_11_DLS_INFO pDlsInfo = kmalloc(sizeof(RT_802_11_DLS_INFO), GFP_ATOMIC);
5444 if (pDlsInfo == NULL)
5445 break;
5447 for (i=0; i<MAX_NUM_OF_DLS_ENTRY; i++)
5449 RTMPMoveMemory(&pDlsInfo->Entry[i], &pAdapter->StaCfg.DLSEntry[i], sizeof(RT_802_11_DLS_UI));
5452 pDlsInfo->num = MAX_NUM_OF_DLS_ENTRY;
5453 wrq->u.data.length = sizeof(RT_802_11_DLS_INFO);
5454 Status = copy_to_user(wrq->u.data.pointer, pDlsInfo, wrq->u.data.length);
5455 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_DLS_PARAM\n"));
5457 if (pDlsInfo)
5458 kfree(pDlsInfo);
5460 break;
5461 #endif // QOS_DLS_SUPPORT //
5462 default:
5463 DBGPRINT(RT_DEBUG_TRACE, ("Query::unknown IOCTL's subcmd = 0x%08x\n", cmd));
5464 Status = -EOPNOTSUPP;
5465 break;
5467 return Status;
5470 INT rt28xx_sta_ioctl(
5471 IN struct net_device *net_dev,
5472 IN OUT struct ifreq *rq,
5473 IN INT cmd)
5475 POS_COOKIE pObj;
5476 VIRTUAL_ADAPTER *pVirtualAd = NULL;
5477 RTMP_ADAPTER *pAd = NULL;
5478 struct iwreq *wrq = (struct iwreq *) rq;
5479 BOOLEAN StateMachineTouched = FALSE;
5480 INT Status = NDIS_STATUS_SUCCESS;
5481 USHORT subcmd;
5483 if (net_dev->priv_flags == INT_MAIN)
5485 pAd = net_dev->ml_priv;
5487 else
5489 pVirtualAd = net_dev->ml_priv;
5490 pAd = pVirtualAd->RtmpDev->ml_priv;
5492 pObj = (POS_COOKIE) pAd->OS_Cookie;
5494 if (pAd == NULL)
5496 /* if 1st open fail, pAd will be free;
5497 So the net_dev->ml_priv will be NULL in 2rd open */
5498 return -ENETDOWN;
5501 //check if the interface is down
5502 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
5504 #ifdef CONFIG_APSTA_MIXED_SUPPORT
5505 if (wrq->u.data.pointer == NULL)
5507 return Status;
5510 if (strstr(wrq->u.data.pointer, "OpMode") == NULL)
5511 #endif // CONFIG_APSTA_MIXED_SUPPORT //
5513 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
5514 return -ENETDOWN;
5518 { // determine this ioctl command is comming from which interface.
5519 pObj->ioctl_if_type = INT_MAIN;
5520 pObj->ioctl_if = MAIN_MBSSID;
5523 switch(cmd)
5525 #ifdef RALINK_ATE
5526 #ifdef RALINK_28xx_QA
5527 case RTPRIV_IOCTL_ATE:
5529 RtmpDoAte(pAd, wrq);
5531 break;
5532 #endif // RALINK_28xx_QA //
5533 #endif // RALINK_ATE //
5534 case SIOCGIFHWADDR:
5535 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIFHWADDR\n"));
5536 memcpy(wrq->u.name, pAd->CurrentAddress, ETH_ALEN);
5537 break;
5538 case SIOCGIWNAME:
5540 char *name=&wrq->u.name[0];
5541 rt_ioctl_giwname(net_dev, NULL, name, NULL);
5542 break;
5544 case SIOCGIWESSID: //Get ESSID
5546 struct iw_point *essid=&wrq->u.essid;
5547 rt_ioctl_giwessid(net_dev, NULL, essid, essid->pointer);
5548 break;
5550 case SIOCSIWESSID: //Set ESSID
5552 struct iw_point *essid=&wrq->u.essid;
5553 rt_ioctl_siwessid(net_dev, NULL, essid, essid->pointer);
5554 break;
5556 case SIOCSIWNWID: // set network id (the cell)
5557 case SIOCGIWNWID: // get network id
5558 Status = -EOPNOTSUPP;
5559 break;
5560 case SIOCSIWFREQ: //set channel/frequency (Hz)
5562 struct iw_freq *freq=&wrq->u.freq;
5563 rt_ioctl_siwfreq(net_dev, NULL, freq, NULL);
5564 break;
5566 case SIOCGIWFREQ: // get channel/frequency (Hz)
5568 struct iw_freq *freq=&wrq->u.freq;
5569 rt_ioctl_giwfreq(net_dev, NULL, freq, NULL);
5570 break;
5572 case SIOCSIWNICKN: //set node name/nickname
5574 struct iw_point *data=&wrq->u.data;
5575 rt_ioctl_siwnickn(net_dev, NULL, data, NULL);
5576 break;
5578 case SIOCGIWNICKN: //get node name/nickname
5580 struct iw_point *data=&wrq->u.data;
5581 rt_ioctl_giwnickn(net_dev, NULL, data, NULL);
5582 break;
5584 case SIOCGIWRATE: //get default bit rate (bps)
5585 rt_ioctl_giwrate(net_dev, NULL, &wrq->u, NULL);
5586 break;
5587 case SIOCSIWRATE: //set default bit rate (bps)
5588 rt_ioctl_siwrate(net_dev, NULL, &wrq->u, NULL);
5589 break;
5590 case SIOCGIWRTS: // get RTS/CTS threshold (bytes)
5592 struct iw_param *rts=&wrq->u.rts;
5593 rt_ioctl_giwrts(net_dev, NULL, rts, NULL);
5594 break;
5596 case SIOCSIWRTS: //set RTS/CTS threshold (bytes)
5598 struct iw_param *rts=&wrq->u.rts;
5599 rt_ioctl_siwrts(net_dev, NULL, rts, NULL);
5600 break;
5602 case SIOCGIWFRAG: //get fragmentation thr (bytes)
5604 struct iw_param *frag=&wrq->u.frag;
5605 rt_ioctl_giwfrag(net_dev, NULL, frag, NULL);
5606 break;
5608 case SIOCSIWFRAG: //set fragmentation thr (bytes)
5610 struct iw_param *frag=&wrq->u.frag;
5611 rt_ioctl_siwfrag(net_dev, NULL, frag, NULL);
5612 break;
5614 case SIOCGIWENCODE: //get encoding token & mode
5616 struct iw_point *erq=&wrq->u.encoding;
5617 if(erq->pointer)
5618 rt_ioctl_giwencode(net_dev, NULL, erq, erq->pointer);
5619 break;
5621 case SIOCSIWENCODE: //set encoding token & mode
5623 struct iw_point *erq=&wrq->u.encoding;
5624 if(erq->pointer)
5625 rt_ioctl_siwencode(net_dev, NULL, erq, erq->pointer);
5626 break;
5628 case SIOCGIWAP: //get access point MAC addresses
5630 struct sockaddr *ap_addr=&wrq->u.ap_addr;
5631 rt_ioctl_giwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
5632 break;
5634 case SIOCSIWAP: //set access point MAC addresses
5636 struct sockaddr *ap_addr=&wrq->u.ap_addr;
5637 rt_ioctl_siwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
5638 break;
5640 case SIOCGIWMODE: //get operation mode
5642 __u32 *mode=&wrq->u.mode;
5643 rt_ioctl_giwmode(net_dev, NULL, mode, NULL);
5644 break;
5646 case SIOCSIWMODE: //set operation mode
5648 __u32 *mode=&wrq->u.mode;
5649 rt_ioctl_siwmode(net_dev, NULL, mode, NULL);
5650 break;
5652 case SIOCGIWSENS: //get sensitivity (dBm)
5653 case SIOCSIWSENS: //set sensitivity (dBm)
5654 case SIOCGIWPOWER: //get Power Management settings
5655 case SIOCSIWPOWER: //set Power Management settings
5656 case SIOCGIWTXPOW: //get transmit power (dBm)
5657 case SIOCSIWTXPOW: //set transmit power (dBm)
5658 case SIOCGIWRANGE: //Get range of parameters
5659 case SIOCGIWRETRY: //get retry limits and lifetime
5660 case SIOCSIWRETRY: //set retry limits and lifetime
5661 Status = -EOPNOTSUPP;
5662 break;
5663 case RT_PRIV_IOCTL:
5664 subcmd = wrq->u.data.flags;
5665 if( subcmd & OID_GET_SET_TOGGLE)
5666 Status = RTMPSetInformation(pAd, rq, subcmd);
5667 else
5668 Status = RTMPQueryInformation(pAd, rq, subcmd);
5669 break;
5670 case SIOCGIWPRIV:
5671 if (wrq->u.data.pointer)
5673 if ( access_ok(VERIFY_WRITE, wrq->u.data.pointer, sizeof(privtab)) != TRUE)
5674 break;
5675 wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
5676 if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
5677 Status = -EFAULT;
5679 break;
5680 case RTPRIV_IOCTL_SET:
5681 if(access_ok(VERIFY_READ, wrq->u.data.pointer, wrq->u.data.length) != TRUE)
5682 break;
5683 rt_ioctl_setparam(net_dev, NULL, NULL, wrq->u.data.pointer);
5684 break;
5685 case RTPRIV_IOCTL_GSITESURVEY:
5686 RTMPIoctlGetSiteSurvey(pAd, wrq);
5687 break;
5688 #ifdef DBG
5689 case RTPRIV_IOCTL_MAC:
5690 RTMPIoctlMAC(pAd, wrq);
5691 break;
5692 case RTPRIV_IOCTL_E2P:
5693 RTMPIoctlE2PROM(pAd, wrq);
5694 break;
5695 #endif // DBG //
5696 case SIOCETHTOOL:
5697 break;
5698 default:
5699 DBGPRINT(RT_DEBUG_ERROR, ("IOCTL::unknown IOCTL's cmd = 0x%08x\n", cmd));
5700 Status = -EOPNOTSUPP;
5701 break;
5704 if(StateMachineTouched) // Upper layer sent a MLME-related operations
5705 RT28XX_MLME_HANDLER(pAd);
5707 return Status;
5711 ==========================================================================
5712 Description:
5713 Set SSID
5714 Return:
5715 TRUE if all parameters are OK, FALSE otherwise
5716 ==========================================================================
5718 INT Set_SSID_Proc(
5719 IN PRTMP_ADAPTER pAdapter,
5720 IN PUCHAR arg)
5722 NDIS_802_11_SSID Ssid, *pSsid=NULL;
5723 BOOLEAN StateMachineTouched = FALSE;
5724 int success = TRUE;
5726 if( strlen(arg) <= MAX_LEN_OF_SSID)
5728 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
5729 if (strlen(arg) != 0)
5731 NdisMoveMemory(Ssid.Ssid, arg, strlen(arg));
5732 Ssid.SsidLength = strlen(arg);
5734 else //ANY ssid
5736 Ssid.SsidLength = 0;
5737 memcpy(Ssid.Ssid, "", 0);
5738 pAdapter->StaCfg.BssType = BSS_INFRA;
5739 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
5740 pAdapter->StaCfg.WepStatus = Ndis802_11EncryptionDisabled;
5742 pSsid = &Ssid;
5744 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
5746 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
5747 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
5750 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
5751 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
5752 pAdapter->bConfigChanged = TRUE;
5754 MlmeEnqueue(pAdapter,
5755 MLME_CNTL_STATE_MACHINE,
5756 OID_802_11_SSID,
5757 sizeof(NDIS_802_11_SSID),
5758 (VOID *)pSsid);
5760 StateMachineTouched = TRUE;
5761 DBGPRINT(RT_DEBUG_TRACE, ("Set_SSID_Proc::(Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
5763 else
5764 success = FALSE;
5766 if (StateMachineTouched) // Upper layer sent a MLME-related operations
5767 RT28XX_MLME_HANDLER(pAdapter);
5769 return success;
5772 #ifdef WMM_SUPPORT
5774 ==========================================================================
5775 Description:
5776 Set WmmCapable Enable or Disable
5777 Return:
5778 TRUE if all parameters are OK, FALSE otherwise
5779 ==========================================================================
5781 INT Set_WmmCapable_Proc(
5782 IN PRTMP_ADAPTER pAd,
5783 IN PUCHAR arg)
5785 BOOLEAN bWmmCapable;
5787 bWmmCapable = simple_strtol(arg, 0, 10);
5789 if ((bWmmCapable == 1)
5790 #ifdef RT2870
5791 && (pAd->NumberOfPipes >= 5)
5792 #endif // RT2870 //
5794 pAd->CommonCfg.bWmmCapable = TRUE;
5795 else if (bWmmCapable == 0)
5796 pAd->CommonCfg.bWmmCapable = FALSE;
5797 else
5798 return FALSE; //Invalid argument
5800 DBGPRINT(RT_DEBUG_TRACE, ("Set_WmmCapable_Proc::(bWmmCapable=%d)\n",
5801 pAd->CommonCfg.bWmmCapable));
5803 return TRUE;
5805 #endif // WMM_SUPPORT //
5808 ==========================================================================
5809 Description:
5810 Set Network Type(Infrastructure/Adhoc mode)
5811 Return:
5812 TRUE if all parameters are OK, FALSE otherwise
5813 ==========================================================================
5815 INT Set_NetworkType_Proc(
5816 IN PRTMP_ADAPTER pAdapter,
5817 IN PUCHAR arg)
5819 UINT32 Value = 0;
5821 if (strcmp(arg, "Adhoc") == 0)
5823 if (pAdapter->StaCfg.BssType != BSS_ADHOC)
5825 // Config has changed
5826 pAdapter->bConfigChanged = TRUE;
5827 if (MONITOR_ON(pAdapter))
5829 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
5830 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5831 Value &= (~0x80);
5832 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5833 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5834 pAdapter->StaCfg.bAutoReconnect = TRUE;
5835 LinkDown(pAdapter, FALSE);
5837 if (INFRA_ON(pAdapter))
5839 //BOOLEAN Cancelled;
5840 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
5841 // Since calling this indicate user don't want to connect to that SSID anymore.
5842 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
5843 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
5845 LinkDown(pAdapter, FALSE);
5847 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n"));
5850 pAdapter->StaCfg.BssType = BSS_ADHOC;
5851 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
5852 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(AD-HOC)\n"));
5854 else if (strcmp(arg, "Infra") == 0)
5856 if (pAdapter->StaCfg.BssType != BSS_INFRA)
5858 // Config has changed
5859 pAdapter->bConfigChanged = TRUE;
5860 if (MONITOR_ON(pAdapter))
5862 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
5863 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5864 Value &= (~0x80);
5865 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5866 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5867 pAdapter->StaCfg.bAutoReconnect = TRUE;
5868 LinkDown(pAdapter, FALSE);
5870 if (ADHOC_ON(pAdapter))
5872 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
5873 // Since calling this indicate user don't want to connect to that SSID anymore.
5874 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
5875 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
5877 LinkDown(pAdapter, FALSE);
5880 pAdapter->StaCfg.BssType = BSS_INFRA;
5881 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
5882 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(INFRA)\n"));
5884 pAdapter->StaCfg.BssType = BSS_INFRA;
5886 else if (strcmp(arg, "Monitor") == 0)
5888 UCHAR bbpValue = 0;
5889 BCN_TIME_CFG_STRUC csr;
5890 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_INFRA_ON);
5891 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_ADHOC_ON);
5892 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5893 // disable all periodic state machine
5894 pAdapter->StaCfg.bAutoReconnect = FALSE;
5895 // reset all mlme state machine
5896 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
5897 DBGPRINT(RT_DEBUG_TRACE, ("fOP_STATUS_MEDIA_STATE_CONNECTED \n"));
5898 if (pAdapter->CommonCfg.CentralChannel == 0)
5900 #ifdef DOT11_N_SUPPORT
5901 if (pAdapter->CommonCfg.PhyMode == PHY_11AN_MIXED)
5902 pAdapter->CommonCfg.CentralChannel = 36;
5903 else
5904 #endif // DOT11_N_SUPPORT //
5905 pAdapter->CommonCfg.CentralChannel = 6;
5907 #ifdef DOT11_N_SUPPORT
5908 else
5909 N_ChannelCheck(pAdapter);
5910 #endif // DOT11_N_SUPPORT //
5912 #ifdef DOT11_N_SUPPORT
5913 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
5914 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
5915 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_ABOVE)
5917 // 40MHz ,control channel at lower
5918 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5919 bbpValue &= (~0x18);
5920 bbpValue |= 0x10;
5921 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5922 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
5923 // RX : control channel at lower
5924 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
5925 bbpValue &= (~0x20);
5926 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
5928 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
5929 Value &= 0xfffffffe;
5930 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
5931 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel + 2;
5932 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
5933 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
5934 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
5935 pAdapter->CommonCfg.Channel,
5936 pAdapter->CommonCfg.CentralChannel));
5938 else if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
5939 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
5940 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_BELOW)
5942 // 40MHz ,control channel at upper
5943 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5944 bbpValue &= (~0x18);
5945 bbpValue |= 0x10;
5946 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5947 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
5948 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
5949 Value |= 0x1;
5950 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
5952 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
5953 bbpValue |= (0x20);
5954 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
5955 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel - 2;
5956 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
5957 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
5958 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
5959 pAdapter->CommonCfg.Channel,
5960 pAdapter->CommonCfg.CentralChannel));
5962 else
5963 #endif // DOT11_N_SUPPORT //
5965 // 20MHz
5966 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5967 bbpValue &= (~0x18);
5968 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5969 pAdapter->CommonCfg.BBPCurrentBW = BW_20;
5970 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.Channel, FALSE);
5971 AsicLockChannel(pAdapter, pAdapter->CommonCfg.Channel);
5972 DBGPRINT(RT_DEBUG_TRACE, ("BW_20, Channel(%d)\n", pAdapter->CommonCfg.Channel));
5974 // Enable Rx with promiscuous reception
5975 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, 0x3);
5976 // ASIC supporsts sniffer function with replacing RSSI with timestamp.
5977 //RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5978 //Value |= (0x80);
5979 //RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5980 // disable sync
5981 RTMP_IO_READ32(pAdapter, BCN_TIME_CFG, &csr.word);
5982 csr.field.bBeaconGen = 0;
5983 csr.field.bTBTTEnable = 0;
5984 csr.field.TsfSyncMode = 0;
5985 RTMP_IO_WRITE32(pAdapter, BCN_TIME_CFG, csr.word);
5987 pAdapter->StaCfg.BssType = BSS_MONITOR;
5988 pAdapter->net_dev->type = ARPHRD_IEEE80211_PRISM; //ARPHRD_IEEE80211; // IEEE80211
5989 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(MONITOR)\n"));
5992 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
5993 pAdapter->StaCfg.WpaState = SS_NOTUSE;
5995 DBGPRINT(RT_DEBUG_TRACE, ("Set_NetworkType_Proc::(NetworkType=%d)\n", pAdapter->StaCfg.BssType));
5997 return TRUE;
6001 ==========================================================================
6002 Description:
6003 Set Authentication mode
6004 Return:
6005 TRUE if all parameters are OK, FALSE otherwise
6006 ==========================================================================
6008 INT Set_AuthMode_Proc(
6009 IN PRTMP_ADAPTER pAdapter,
6010 IN PUCHAR arg)
6012 if ((strcmp(arg, "WEPAUTO") == 0) || (strcmp(arg, "wepauto") == 0))
6013 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeAutoSwitch;
6014 else if ((strcmp(arg, "OPEN") == 0) || (strcmp(arg, "open") == 0))
6015 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
6016 else if ((strcmp(arg, "SHARED") == 0) || (strcmp(arg, "shared") == 0))
6017 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
6018 else if ((strcmp(arg, "WPAPSK") == 0) || (strcmp(arg, "wpapsk") == 0))
6019 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
6020 else if ((strcmp(arg, "WPANONE") == 0) || (strcmp(arg, "wpanone") == 0))
6021 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
6022 else if ((strcmp(arg, "WPA2PSK") == 0) || (strcmp(arg, "wpa2psk") == 0))
6023 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
6024 #ifdef WPA_SUPPLICANT_SUPPORT
6025 else if ((strcmp(arg, "WPA") == 0) || (strcmp(arg, "wpa") == 0))
6026 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
6027 else if ((strcmp(arg, "WPA2") == 0) || (strcmp(arg, "wpa2") == 0))
6028 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
6029 #endif // WPA_SUPPLICANT_SUPPORT //
6030 else
6031 return FALSE;
6033 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
6035 DBGPRINT(RT_DEBUG_TRACE, ("Set_AuthMode_Proc::(AuthMode=%d)\n", pAdapter->StaCfg.AuthMode));
6037 return TRUE;
6041 ==========================================================================
6042 Description:
6043 Set Encryption Type
6044 Return:
6045 TRUE if all parameters are OK, FALSE otherwise
6046 ==========================================================================
6048 INT Set_EncrypType_Proc(
6049 IN PRTMP_ADAPTER pAdapter,
6050 IN PUCHAR arg)
6052 if ((strcmp(arg, "NONE") == 0) || (strcmp(arg, "none") == 0))
6054 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6055 return TRUE; // do nothing
6057 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
6058 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
6059 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
6061 else if ((strcmp(arg, "WEP") == 0) || (strcmp(arg, "wep") == 0))
6063 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6064 return TRUE; // do nothing
6066 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
6067 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
6068 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
6070 else if ((strcmp(arg, "TKIP") == 0) || (strcmp(arg, "tkip") == 0))
6072 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
6073 return TRUE; // do nothing
6075 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
6076 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
6077 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
6079 else if ((strcmp(arg, "AES") == 0) || (strcmp(arg, "aes") == 0))
6081 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
6082 return TRUE; // do nothing
6084 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
6085 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
6086 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
6088 else
6089 return FALSE;
6091 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
6093 DBGPRINT(RT_DEBUG_TRACE, ("Set_EncrypType_Proc::(EncrypType=%d)\n", pAdapter->StaCfg.WepStatus));
6095 return TRUE;
6099 ==========================================================================
6100 Description:
6101 Set Default Key ID
6102 Return:
6103 TRUE if all parameters are OK, FALSE otherwise
6104 ==========================================================================
6106 INT Set_DefaultKeyID_Proc(
6107 IN PRTMP_ADAPTER pAdapter,
6108 IN PUCHAR arg)
6110 ULONG KeyIdx;
6112 KeyIdx = simple_strtol(arg, 0, 10);
6113 if((KeyIdx >= 1 ) && (KeyIdx <= 4))
6114 pAdapter->StaCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1 );
6115 else
6116 return FALSE; //Invalid argument
6118 DBGPRINT(RT_DEBUG_TRACE, ("Set_DefaultKeyID_Proc::(DefaultKeyID=%d)\n", pAdapter->StaCfg.DefaultKeyId));
6120 return TRUE;
6124 ==========================================================================
6125 Description:
6126 Set WEP KEY1
6127 Return:
6128 TRUE if all parameters are OK, FALSE otherwise
6129 ==========================================================================
6131 INT Set_Key1_Proc(
6132 IN PRTMP_ADAPTER pAdapter,
6133 IN PUCHAR arg)
6135 int KeyLen;
6136 int i;
6137 UCHAR CipherAlg=CIPHER_WEP64;
6139 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6140 return TRUE; // do nothing
6142 KeyLen = strlen(arg);
6144 switch (KeyLen)
6146 case 5: //wep 40 Ascii type
6147 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
6148 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
6149 CipherAlg = CIPHER_WEP64;
6150 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
6151 break;
6152 case 10: //wep 40 Hex type
6153 for(i=0; i < KeyLen; i++)
6155 if( !isxdigit(*(arg+i)) )
6156 return FALSE; //Not Hex value;
6158 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
6159 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
6160 CipherAlg = CIPHER_WEP64;
6161 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
6162 break;
6163 case 13: //wep 104 Ascii type
6164 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
6165 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
6166 CipherAlg = CIPHER_WEP128;
6167 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
6168 break;
6169 case 26: //wep 104 Hex type
6170 for(i=0; i < KeyLen; i++)
6172 if( !isxdigit(*(arg+i)) )
6173 return FALSE; //Not Hex value;
6175 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
6176 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
6177 CipherAlg = CIPHER_WEP128;
6178 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
6179 break;
6180 default: //Invalid argument
6181 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::Invalid argument (=%s)\n", arg));
6182 return FALSE;
6185 pAdapter->SharedKey[BSS0][0].CipherAlg = CipherAlg;
6187 // Set keys (into ASIC)
6188 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6189 ; // not support
6190 else // Old WEP stuff
6192 AsicAddSharedKeyEntry(pAdapter,
6195 pAdapter->SharedKey[BSS0][0].CipherAlg,
6196 pAdapter->SharedKey[BSS0][0].Key,
6197 NULL,
6198 NULL);
6201 return TRUE;
6204 ==========================================================================
6206 Description:
6207 Set WEP KEY2
6208 Return:
6209 TRUE if all parameters are OK, FALSE otherwise
6210 ==========================================================================
6212 INT Set_Key2_Proc(
6213 IN PRTMP_ADAPTER pAdapter,
6214 IN PUCHAR arg)
6216 int KeyLen;
6217 int i;
6218 UCHAR CipherAlg=CIPHER_WEP64;
6220 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6221 return TRUE; // do nothing
6223 KeyLen = strlen(arg);
6225 switch (KeyLen)
6227 case 5: //wep 40 Ascii type
6228 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
6229 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
6230 CipherAlg = CIPHER_WEP64;
6231 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
6232 break;
6233 case 10: //wep 40 Hex type
6234 for(i=0; i < KeyLen; i++)
6236 if( !isxdigit(*(arg+i)) )
6237 return FALSE; //Not Hex value;
6239 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
6240 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
6241 CipherAlg = CIPHER_WEP64;
6242 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
6243 break;
6244 case 13: //wep 104 Ascii type
6245 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
6246 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
6247 CipherAlg = CIPHER_WEP128;
6248 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
6249 break;
6250 case 26: //wep 104 Hex type
6251 for(i=0; i < KeyLen; i++)
6253 if( !isxdigit(*(arg+i)) )
6254 return FALSE; //Not Hex value;
6256 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
6257 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
6258 CipherAlg = CIPHER_WEP128;
6259 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
6260 break;
6261 default: //Invalid argument
6262 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::Invalid argument (=%s)\n", arg));
6263 return FALSE;
6265 pAdapter->SharedKey[BSS0][1].CipherAlg = CipherAlg;
6267 // Set keys (into ASIC)
6268 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6269 ; // not support
6270 else // Old WEP stuff
6272 AsicAddSharedKeyEntry(pAdapter,
6275 pAdapter->SharedKey[BSS0][1].CipherAlg,
6276 pAdapter->SharedKey[BSS0][1].Key,
6277 NULL,
6278 NULL);
6281 return TRUE;
6284 ==========================================================================
6285 Description:
6286 Set WEP KEY3
6287 Return:
6288 TRUE if all parameters are OK, FALSE otherwise
6289 ==========================================================================
6291 INT Set_Key3_Proc(
6292 IN PRTMP_ADAPTER pAdapter,
6293 IN PUCHAR arg)
6295 int KeyLen;
6296 int i;
6297 UCHAR CipherAlg=CIPHER_WEP64;
6299 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6300 return TRUE; // do nothing
6302 KeyLen = strlen(arg);
6304 switch (KeyLen)
6306 case 5: //wep 40 Ascii type
6307 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
6308 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
6309 CipherAlg = CIPHER_WEP64;
6310 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
6311 break;
6312 case 10: //wep 40 Hex type
6313 for(i=0; i < KeyLen; i++)
6315 if( !isxdigit(*(arg+i)) )
6316 return FALSE; //Not Hex value;
6318 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
6319 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
6320 CipherAlg = CIPHER_WEP64;
6321 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
6322 break;
6323 case 13: //wep 104 Ascii type
6324 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
6325 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
6326 CipherAlg = CIPHER_WEP128;
6327 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
6328 break;
6329 case 26: //wep 104 Hex type
6330 for(i=0; i < KeyLen; i++)
6332 if( !isxdigit(*(arg+i)) )
6333 return FALSE; //Not Hex value;
6335 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
6336 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
6337 CipherAlg = CIPHER_WEP128;
6338 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
6339 break;
6340 default: //Invalid argument
6341 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::Invalid argument (=%s)\n", arg));
6342 return FALSE;
6344 pAdapter->SharedKey[BSS0][2].CipherAlg = CipherAlg;
6346 // Set keys (into ASIC)
6347 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6348 ; // not support
6349 else // Old WEP stuff
6351 AsicAddSharedKeyEntry(pAdapter,
6354 pAdapter->SharedKey[BSS0][2].CipherAlg,
6355 pAdapter->SharedKey[BSS0][2].Key,
6356 NULL,
6357 NULL);
6360 return TRUE;
6363 ==========================================================================
6364 Description:
6365 Set WEP KEY4
6366 Return:
6367 TRUE if all parameters are OK, FALSE otherwise
6368 ==========================================================================
6370 INT Set_Key4_Proc(
6371 IN PRTMP_ADAPTER pAdapter,
6372 IN PUCHAR arg)
6374 int KeyLen;
6375 int i;
6376 UCHAR CipherAlg=CIPHER_WEP64;
6378 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6379 return TRUE; // do nothing
6381 KeyLen = strlen(arg);
6383 switch (KeyLen)
6385 case 5: //wep 40 Ascii type
6386 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
6387 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
6388 CipherAlg = CIPHER_WEP64;
6389 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
6390 break;
6391 case 10: //wep 40 Hex type
6392 for(i=0; i < KeyLen; i++)
6394 if( !isxdigit(*(arg+i)) )
6395 return FALSE; //Not Hex value;
6397 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
6398 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
6399 CipherAlg = CIPHER_WEP64;
6400 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
6401 break;
6402 case 13: //wep 104 Ascii type
6403 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
6404 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
6405 CipherAlg = CIPHER_WEP128;
6406 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
6407 break;
6408 case 26: //wep 104 Hex type
6409 for(i=0; i < KeyLen; i++)
6411 if( !isxdigit(*(arg+i)) )
6412 return FALSE; //Not Hex value;
6414 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
6415 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
6416 CipherAlg = CIPHER_WEP128;
6417 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
6418 break;
6419 default: //Invalid argument
6420 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::Invalid argument (=%s)\n", arg));
6421 return FALSE;
6423 pAdapter->SharedKey[BSS0][3].CipherAlg = CipherAlg;
6425 // Set keys (into ASIC)
6426 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6427 ; // not support
6428 else // Old WEP stuff
6430 AsicAddSharedKeyEntry(pAdapter,
6433 pAdapter->SharedKey[BSS0][3].CipherAlg,
6434 pAdapter->SharedKey[BSS0][3].Key,
6435 NULL,
6436 NULL);
6439 return TRUE;
6443 ==========================================================================
6444 Description:
6445 Set WPA PSK key
6446 Return:
6447 TRUE if all parameters are OK, FALSE otherwise
6448 ==========================================================================
6450 INT Set_WPAPSK_Proc(
6451 IN PRTMP_ADAPTER pAdapter,
6452 IN PUCHAR arg)
6454 UCHAR keyMaterial[40];
6456 if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
6457 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
6458 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
6460 return TRUE; // do nothing
6462 DBGPRINT(RT_DEBUG_TRACE, ("Set_WPAPSK_Proc::(WPAPSK=%s)\n", arg));
6464 NdisZeroMemory(keyMaterial, 40);
6466 if ((strlen(arg) < 8) || (strlen(arg) > 64))
6468 DBGPRINT(RT_DEBUG_TRACE, ("Set failed!!(WPAPSK=%s), WPAPSK key-string required 8 ~ 64 characters \n", arg));
6469 return FALSE;
6472 if (strlen(arg) == 64)
6474 AtoH(arg, keyMaterial, 32);
6475 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
6478 else
6480 PasswordHash((char *)arg, pAdapter->MlmeAux.Ssid, pAdapter->MlmeAux.SsidLen, keyMaterial);
6481 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
6486 if(pAdapter->StaCfg.BssType == BSS_ADHOC &&
6487 pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
6489 pAdapter->StaCfg.WpaState = SS_NOTUSE;
6491 else
6493 // Start STA supplicant state machine
6494 pAdapter->StaCfg.WpaState = SS_START;
6497 return TRUE;
6501 ==========================================================================
6502 Description:
6503 Set Power Saving mode
6504 Return:
6505 TRUE if all parameters are OK, FALSE otherwise
6506 ==========================================================================
6508 INT Set_PSMode_Proc(
6509 IN PRTMP_ADAPTER pAdapter,
6510 IN PUCHAR arg)
6512 if (pAdapter->StaCfg.BssType == BSS_INFRA)
6514 if ((strcmp(arg, "Max_PSP") == 0) ||
6515 (strcmp(arg, "max_psp") == 0) ||
6516 (strcmp(arg, "MAX_PSP") == 0))
6518 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6519 // to exclude certain situations.
6520 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6521 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeMAX_PSP;
6522 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeMAX_PSP;
6523 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6524 pAdapter->StaCfg.DefaultListenCount = 5;
6527 else if ((strcmp(arg, "Fast_PSP") == 0) ||
6528 (strcmp(arg, "fast_psp") == 0) ||
6529 (strcmp(arg, "FAST_PSP") == 0))
6531 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6532 // to exclude certain situations.
6533 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6534 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6535 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeFast_PSP;
6536 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeFast_PSP;
6537 pAdapter->StaCfg.DefaultListenCount = 3;
6539 else if ((strcmp(arg, "Legacy_PSP") == 0) ||
6540 (strcmp(arg, "legacy_psp") == 0) ||
6541 (strcmp(arg, "LEGACY_PSP") == 0))
6543 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6544 // to exclude certain situations.
6545 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6546 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6547 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeLegacy_PSP;
6548 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeLegacy_PSP;
6549 pAdapter->StaCfg.DefaultListenCount = 3;
6551 else
6553 //Default Ndis802_11PowerModeCAM
6554 // clear PSM bit immediately
6555 MlmeSetPsmBit(pAdapter, PWR_ACTIVE);
6556 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6557 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6558 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
6559 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
6562 DBGPRINT(RT_DEBUG_TRACE, ("Set_PSMode_Proc::(PSMode=%ld)\n", pAdapter->StaCfg.WindowsPowerMode));
6564 else
6565 return FALSE;
6568 return TRUE;
6571 #ifdef WPA_SUPPLICANT_SUPPORT
6573 ==========================================================================
6574 Description:
6575 Set WpaSupport flag.
6576 Value:
6577 0: Driver ignore wpa_supplicant.
6578 1: wpa_supplicant initiates scanning and AP selection.
6579 2: driver takes care of scanning, AP selection, and IEEE 802.11 association parameters.
6580 Return:
6581 TRUE if all parameters are OK, FALSE otherwise
6582 ==========================================================================
6584 INT Set_Wpa_Support(
6585 IN PRTMP_ADAPTER pAd,
6586 IN PUCHAR arg)
6589 if ( simple_strtol(arg, 0, 10) == 0)
6590 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
6591 else if ( simple_strtol(arg, 0, 10) == 1)
6592 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE;
6593 else if ( simple_strtol(arg, 0, 10) == 2)
6594 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE_WITH_WEB_UI;
6595 else
6596 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
6598 DBGPRINT(RT_DEBUG_TRACE, ("Set_Wpa_Support::(WpaSupplicantUP=%d)\n", pAd->StaCfg.WpaSupplicantUP));
6600 return TRUE;
6602 #endif // WPA_SUPPLICANT_SUPPORT //
6604 #ifdef DBG
6606 ==========================================================================
6607 Description:
6608 Read / Write MAC
6609 Arguments:
6610 pAdapter Pointer to our adapter
6611 wrq Pointer to the ioctl argument
6613 Return Value:
6614 None
6616 Note:
6617 Usage:
6618 1.) iwpriv ra0 mac 0 ==> read MAC where Addr=0x0
6619 2.) iwpriv ra0 mac 0=12 ==> write MAC where Addr=0x0, value=12
6620 ==========================================================================
6622 VOID RTMPIoctlMAC(
6623 IN PRTMP_ADAPTER pAdapter,
6624 IN struct iwreq *wrq)
6626 CHAR *this_char;
6627 CHAR *value;
6628 INT j = 0, k = 0;
6629 CHAR msg[1024];
6630 CHAR arg[255];
6631 ULONG macAddr = 0;
6632 UCHAR temp[16], temp2[16];
6633 UINT32 macValue = 0;
6634 INT Status;
6637 memset(msg, 0x00, 1024);
6638 if (wrq->u.data.length > 1) //No parameters.
6640 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6641 sprintf(msg, "\n");
6643 //Parsing Read or Write
6644 this_char = arg;
6645 if (!*this_char)
6646 goto next;
6648 if ((value = rtstrchr(this_char, '=')) != NULL)
6649 *value++ = 0;
6651 if (!value || !*value)
6652 { //Read
6653 // Sanity check
6654 if(strlen(this_char) > 4)
6655 goto next;
6657 j = strlen(this_char);
6658 while(j-- > 0)
6660 if(this_char[j] > 'f' || this_char[j] < '0')
6661 return;
6664 // Mac Addr
6665 k = j = strlen(this_char);
6666 while(j-- > 0)
6668 this_char[4-k+j] = this_char[j];
6671 while(k < 4)
6672 this_char[3-k++]='0';
6673 this_char[4]='\0';
6675 if(strlen(this_char) == 4)
6677 AtoH(this_char, temp, 2);
6678 macAddr = *temp*256 + temp[1];
6679 if (macAddr < 0xFFFF)
6681 RTMP_IO_READ32(pAdapter, macAddr, &macValue);
6682 DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%lx, MacValue=%x\n", macAddr, macValue));
6683 sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr , macValue);
6685 else
6686 {//Invalid parametes, so default printk all bbp
6687 goto next;
6691 else
6692 { //Write
6693 memcpy(&temp2, value, strlen(value));
6694 temp2[strlen(value)] = '\0';
6696 // Sanity check
6697 if((strlen(this_char) > 4) || strlen(temp2) > 8)
6698 goto next;
6700 j = strlen(this_char);
6701 while(j-- > 0)
6703 if(this_char[j] > 'f' || this_char[j] < '0')
6704 return;
6707 j = strlen(temp2);
6708 while(j-- > 0)
6710 if(temp2[j] > 'f' || temp2[j] < '0')
6711 return;
6714 //MAC Addr
6715 k = j = strlen(this_char);
6716 while(j-- > 0)
6718 this_char[4-k+j] = this_char[j];
6721 while(k < 4)
6722 this_char[3-k++]='0';
6723 this_char[4]='\0';
6725 //MAC value
6726 k = j = strlen(temp2);
6727 while(j-- > 0)
6729 temp2[8-k+j] = temp2[j];
6732 while(k < 8)
6733 temp2[7-k++]='0';
6734 temp2[8]='\0';
6737 AtoH(this_char, temp, 2);
6738 macAddr = *temp*256 + temp[1];
6740 AtoH(temp2, temp, 4);
6741 macValue = *temp*256*256*256 + temp[1]*256*256 + temp[2]*256 + temp[3];
6743 // debug mode
6744 if (macAddr == (HW_DEBUG_SETTING_BASE + 4))
6746 // 0x2bf4: byte0 non-zero: enable R17 tuning, 0: disable R17 tuning
6747 if (macValue & 0x000000ff)
6749 pAdapter->BbpTuning.bEnable = TRUE;
6750 DBGPRINT(RT_DEBUG_TRACE,("turn on R17 tuning\n"));
6752 else
6754 UCHAR R66;
6755 pAdapter->BbpTuning.bEnable = FALSE;
6756 R66 = 0x26 + GET_LNA_GAIN(pAdapter);
6757 #ifdef RALINK_ATE
6758 if (ATE_ON(pAdapter))
6760 ATE_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R66, (0x26 + GET_LNA_GAIN(pAdapter)));
6762 else
6763 #endif // RALINK_ATE //
6764 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R66, (0x26 + GET_LNA_GAIN(pAdapter)));
6765 DBGPRINT(RT_DEBUG_TRACE,("turn off R17 tuning, restore to 0x%02x\n", R66));
6767 return;
6770 DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%02lx, MacValue=0x%x\n", macAddr, macValue));
6772 RTMP_IO_WRITE32(pAdapter, macAddr, macValue);
6773 sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr, macValue);
6777 next:
6778 if(strlen(msg) == 1)
6779 sprintf(msg+strlen(msg), "===>Error command format!");
6781 // Copy the information into the user buffer
6782 wrq->u.data.length = strlen(msg);
6783 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6785 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlMAC\n\n"));
6789 ==========================================================================
6790 Description:
6791 Read / Write E2PROM
6792 Arguments:
6793 pAdapter Pointer to our adapter
6794 wrq Pointer to the ioctl argument
6796 Return Value:
6797 None
6799 Note:
6800 Usage:
6801 1.) iwpriv ra0 e2p 0 ==> read E2PROM where Addr=0x0
6802 2.) iwpriv ra0 e2p 0=1234 ==> write E2PROM where Addr=0x0, value=1234
6803 ==========================================================================
6805 VOID RTMPIoctlE2PROM(
6806 IN PRTMP_ADAPTER pAdapter,
6807 IN struct iwreq *wrq)
6809 CHAR *this_char;
6810 CHAR *value;
6811 INT j = 0, k = 0;
6812 CHAR msg[1024];
6813 CHAR arg[255];
6814 USHORT eepAddr = 0;
6815 UCHAR temp[16], temp2[16];
6816 USHORT eepValue;
6817 int Status;
6820 memset(msg, 0x00, 1024);
6821 if (wrq->u.data.length > 1) //No parameters.
6823 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6824 sprintf(msg, "\n");
6826 //Parsing Read or Write
6827 this_char = arg;
6830 if (!*this_char)
6831 goto next;
6833 if ((value = rtstrchr(this_char, '=')) != NULL)
6834 *value++ = 0;
6836 if (!value || !*value)
6837 { //Read
6839 // Sanity check
6840 if(strlen(this_char) > 4)
6841 goto next;
6843 j = strlen(this_char);
6844 while(j-- > 0)
6846 if(this_char[j] > 'f' || this_char[j] < '0')
6847 return;
6850 // E2PROM addr
6851 k = j = strlen(this_char);
6852 while(j-- > 0)
6854 this_char[4-k+j] = this_char[j];
6857 while(k < 4)
6858 this_char[3-k++]='0';
6859 this_char[4]='\0';
6861 if(strlen(this_char) == 4)
6863 AtoH(this_char, temp, 2);
6864 eepAddr = *temp*256 + temp[1];
6865 if (eepAddr < 0xFFFF)
6867 RT28xx_EEPROM_READ16(pAdapter, eepAddr, eepValue);
6868 sprintf(msg+strlen(msg), "[0x%04X]:0x%04X ", eepAddr , eepValue);
6870 else
6871 {//Invalid parametes, so default printk all bbp
6872 goto next;
6876 else
6877 { //Write
6878 memcpy(&temp2, value, strlen(value));
6879 temp2[strlen(value)] = '\0';
6881 // Sanity check
6882 if((strlen(this_char) > 4) || strlen(temp2) > 8)
6883 goto next;
6885 j = strlen(this_char);
6886 while(j-- > 0)
6888 if(this_char[j] > 'f' || this_char[j] < '0')
6889 return;
6891 j = strlen(temp2);
6892 while(j-- > 0)
6894 if(temp2[j] > 'f' || temp2[j] < '0')
6895 return;
6898 //MAC Addr
6899 k = j = strlen(this_char);
6900 while(j-- > 0)
6902 this_char[4-k+j] = this_char[j];
6905 while(k < 4)
6906 this_char[3-k++]='0';
6907 this_char[4]='\0';
6909 //MAC value
6910 k = j = strlen(temp2);
6911 while(j-- > 0)
6913 temp2[4-k+j] = temp2[j];
6916 while(k < 4)
6917 temp2[3-k++]='0';
6918 temp2[4]='\0';
6920 AtoH(this_char, temp, 2);
6921 eepAddr = *temp*256 + temp[1];
6923 AtoH(temp2, temp, 2);
6924 eepValue = *temp*256 + temp[1];
6926 RT28xx_EEPROM_WRITE16(pAdapter, eepAddr, eepValue);
6927 sprintf(msg+strlen(msg), "[0x%02X]:%02X ", eepAddr, eepValue);
6930 next:
6931 if(strlen(msg) == 1)
6932 sprintf(msg+strlen(msg), "===>Error command format!");
6935 // Copy the information into the user buffer
6936 wrq->u.data.length = strlen(msg);
6937 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6939 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlE2PROM\n"));
6941 #endif // DBG //
6946 INT Set_TGnWifiTest_Proc(
6947 IN PRTMP_ADAPTER pAd,
6948 IN PUCHAR arg)
6950 if (simple_strtol(arg, 0, 10) == 0)
6951 pAd->StaCfg.bTGnWifiTest = FALSE;
6952 else
6953 pAd->StaCfg.bTGnWifiTest = TRUE;
6955 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_TGnWifiTest_Proc::(bTGnWifiTest=%d)\n", pAd->StaCfg.bTGnWifiTest));
6956 return TRUE;
6959 INT Set_LongRetryLimit_Proc(
6960 IN PRTMP_ADAPTER pAdapter,
6961 IN PUCHAR arg)
6963 TX_RTY_CFG_STRUC tx_rty_cfg;
6964 UCHAR LongRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
6966 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
6967 tx_rty_cfg.field.LongRtyLimit = LongRetryLimit;
6968 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
6969 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_LongRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
6970 return TRUE;
6973 INT Set_ShortRetryLimit_Proc(
6974 IN PRTMP_ADAPTER pAdapter,
6975 IN PUCHAR arg)
6977 TX_RTY_CFG_STRUC tx_rty_cfg;
6978 UCHAR ShortRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
6980 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
6981 tx_rty_cfg.field.ShortRtyLimit = ShortRetryLimit;
6982 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
6983 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_ShortRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
6984 return TRUE;
6987 #ifdef EXT_BUILD_CHANNEL_LIST
6988 INT Set_Ieee80211dClientMode_Proc(
6989 IN PRTMP_ADAPTER pAdapter,
6990 IN PUCHAR arg)
6992 if (simple_strtol(arg, 0, 10) == 0)
6993 pAdapter->StaCfg.IEEE80211dClientMode = Rt802_11_D_None;
6994 else if (simple_strtol(arg, 0, 10) == 1)
6995 pAdapter->StaCfg.IEEE80211dClientMode = Rt802_11_D_Flexible;
6996 else if (simple_strtol(arg, 0, 10) == 2)
6997 pAdapter->StaCfg.IEEE80211dClientMode = Rt802_11_D_Strict;
6998 else
6999 return FALSE;
7001 DBGPRINT(RT_DEBUG_TRACE, ("Set_Ieee802dMode_Proc::(IEEEE0211dMode=%d)\n", pAdapter->StaCfg.IEEE80211dClientMode));
7002 return TRUE;
7004 #endif // EXT_BUILD_CHANNEL_LIST //
7006 #ifdef CARRIER_DETECTION_SUPPORT
7007 INT Set_CarrierDetect_Proc(
7008 IN PRTMP_ADAPTER pAd,
7009 IN PUCHAR arg)
7011 if (simple_strtol(arg, 0, 10) == 0)
7012 pAd->CommonCfg.CarrierDetect.Enable = FALSE;
7013 else
7014 pAd->CommonCfg.CarrierDetect.Enable = TRUE;
7016 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_CarrierDetect_Proc::(CarrierDetect.Enable=%d)\n", pAd->CommonCfg.CarrierDetect.Enable));
7017 return TRUE;
7019 #endif // CARRIER_DETECTION_SUPPORT //
7022 INT Show_Adhoc_MacTable_Proc(
7023 IN PRTMP_ADAPTER pAd,
7024 IN PCHAR extra)
7026 INT i;
7028 sprintf(extra, "\n");
7030 #ifdef DOT11_N_SUPPORT
7031 sprintf(extra + strlen(extra), "HT Operating Mode : %d\n", pAd->CommonCfg.AddHTInfo.AddHtInfo2.OperaionMode);
7032 #endif // DOT11_N_SUPPORT //
7034 sprintf(extra + strlen(extra), "\n%-19s%-4s%-4s%-7s%-7s%-7s%-10s%-6s%-6s%-6s%-6s\n",
7035 "MAC", "AID", "BSS", "RSSI0", "RSSI1", "RSSI2", "PhMd", "BW", "MCS", "SGI", "STBC");
7037 for (i=1; i<MAX_LEN_OF_MAC_TABLE; i++)
7039 PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
7041 if (strlen(extra) > (IW_PRIV_SIZE_MASK - 30))
7042 break;
7043 if ((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
7045 sprintf(extra + strlen(extra), "%02X:%02X:%02X:%02X:%02X:%02X ",
7046 pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
7047 pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5]);
7048 sprintf(extra + strlen(extra), "%-4d", (int)pEntry->Aid);
7049 sprintf(extra + strlen(extra), "%-4d", (int)pEntry->apidx);
7050 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi0);
7051 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi1);
7052 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi2);
7053 sprintf(extra + strlen(extra), "%-10s", GetPhyMode(pEntry->HTPhyMode.field.MODE));
7054 sprintf(extra + strlen(extra), "%-6s", GetBW(pEntry->HTPhyMode.field.BW));
7055 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.MCS);
7056 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.ShortGI);
7057 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.STBC);
7058 sprintf(extra + strlen(extra), "%-10d, %d, %d%%\n", pEntry->DebugFIFOCount, pEntry->DebugTxCount,
7059 (pEntry->DebugTxCount) ? ((pEntry->DebugTxCount-pEntry->DebugFIFOCount)*100/pEntry->DebugTxCount) : 0);
7060 sprintf(extra, "%s\n", extra);
7064 return TRUE;