]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/staging/rt2860/sta_ioctl.c
Staging: rt*: don't confuse user of rt3070 driver with rt2870 strings
[net-next-2.6.git] / drivers / staging / rt2860 / sta_ioctl.c
CommitLineData
91980990
GKH
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
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 *************************************************************************
26
27 Module Name:
28 sta_ioctl.c
29
30 Abstract:
31 IOCTL related subroutines
32
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
38*/
39
40#include "rt_config.h"
41
42#ifdef DBG
43extern ULONG RTDebugLevel;
44#endif
45
46#define NR_WEP_KEYS 4
47#define WEP_SMALL_KEY_LEN (40/8)
48#define WEP_LARGE_KEY_LEN (104/8)
49
50#define GROUP_KEY_NO 4
51
91980990
GKH
52extern UCHAR CipherWpa2Template[];
53extern UCHAR CipherWpaPskTkip[];
54extern UCHAR CipherWpaPskTkipLen;
55
56typedef struct PACKED _RT_VERSION_INFO{
57 UCHAR DriverVersionW;
58 UCHAR DriverVersionX;
59 UCHAR DriverVersionY;
60 UCHAR DriverVersionZ;
61 UINT DriverBuildYear;
62 UINT DriverBuildMonth;
63 UINT DriverBuildDay;
64} RT_VERSION_INFO, *PRT_VERSION_INFO;
65
66struct iw_priv_args privtab[] = {
67{ RTPRIV_IOCTL_SET,
68 IW_PRIV_TYPE_CHAR | 1024, 0,
69 "set"},
70
71{ RTPRIV_IOCTL_SHOW, 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
72 ""},
73{ RTPRIV_IOCTL_SHOW, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
74 ""},
75/* --- sub-ioctls definitions --- */
76 { SHOW_CONN_STATUS,
77 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "connStatus" },
78 { SHOW_DRVIER_VERION,
79 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "driverVer" },
80 { SHOW_BA_INFO,
81 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "bainfo" },
82 { SHOW_DESC_INFO,
83 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "descinfo" },
84 { RAIO_OFF,
85 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "radio_off" },
86 { RAIO_ON,
87 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "radio_on" },
91980990
GKH
88 { SHOW_CFG_VALUE,
89 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "show" },
3a32ed12
BZ
90#if !defined(RT2860) && !defined(RT30xx)
91 { SHOW_ADHOC_ENTRY_INFO,
92 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "adhocEntry" },
93#endif
91980990
GKH
94/* --- sub-ioctls relations --- */
95
96#ifdef DBG
97{ RTPRIV_IOCTL_BBP,
98 IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
99 "bbp"},
100{ RTPRIV_IOCTL_MAC,
101 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
102 "mac"},
3a32ed12
BZ
103#ifdef RT30xx
104{ RTPRIV_IOCTL_RF,
105 IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
106 "rf"},
107#endif // RT30xx //
91980990
GKH
108{ RTPRIV_IOCTL_E2P,
109 IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024,
110 "e2p"},
111#endif /* DBG */
112
113{ RTPRIV_IOCTL_STATISTICS,
114 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK,
115 "stat"},
116{ RTPRIV_IOCTL_GSITESURVEY,
117 0, IW_PRIV_TYPE_CHAR | 1024,
118 "get_site_survey"},
119};
120
121INT Set_SSID_Proc(
122 IN PRTMP_ADAPTER pAdapter,
123 IN PUCHAR arg);
124
125#ifdef WMM_SUPPORT
126INT Set_WmmCapable_Proc(
127 IN PRTMP_ADAPTER pAd,
128 IN PUCHAR arg);
129#endif
130
131INT Set_NetworkType_Proc(
132 IN PRTMP_ADAPTER pAdapter,
133 IN PUCHAR arg);
134
135INT Set_AuthMode_Proc(
136 IN PRTMP_ADAPTER pAdapter,
137 IN PUCHAR arg);
138
139INT Set_EncrypType_Proc(
140 IN PRTMP_ADAPTER pAdapter,
141 IN PUCHAR arg);
142
143INT Set_DefaultKeyID_Proc(
144 IN PRTMP_ADAPTER pAdapter,
145 IN PUCHAR arg);
146
147INT Set_Key1_Proc(
148 IN PRTMP_ADAPTER pAdapter,
149 IN PUCHAR arg);
150
151INT Set_Key2_Proc(
152 IN PRTMP_ADAPTER pAdapter,
153 IN PUCHAR arg);
154
155INT Set_Key3_Proc(
156 IN PRTMP_ADAPTER pAdapter,
157 IN PUCHAR arg);
158
159INT Set_Key4_Proc(
160 IN PRTMP_ADAPTER pAdapter,
161 IN PUCHAR arg);
162
163INT Set_WPAPSK_Proc(
164 IN PRTMP_ADAPTER pAdapter,
165 IN PUCHAR arg);
166
167
168INT Set_PSMode_Proc(
169 IN PRTMP_ADAPTER pAdapter,
170 IN PUCHAR arg);
171
91980990
GKH
172INT Set_Wpa_Support(
173 IN PRTMP_ADAPTER pAd,
174 IN PUCHAR arg);
91980990
GKH
175
176#ifdef DBG
3a32ed12 177#if !defined(RT2860) && !defined(RT30xx)
91980990
GKH
178VOID RTMPIoctlBBP(
179 IN PRTMP_ADAPTER pAdapter,
180 IN struct iwreq *wrq);
3a32ed12 181#endif
91980990
GKH
182
183VOID RTMPIoctlMAC(
184 IN PRTMP_ADAPTER pAdapter,
185 IN struct iwreq *wrq);
186
187VOID RTMPIoctlE2PROM(
188 IN PRTMP_ADAPTER pAdapter,
189 IN struct iwreq *wrq);
3a32ed12
BZ
190
191#ifdef RT30xx
192VOID RTMPIoctlRF(
193 IN PRTMP_ADAPTER pAdapter,
194 IN struct iwreq *wrq);
195#endif // RT30xx //
91980990
GKH
196#endif // DBG //
197
198
199NDIS_STATUS RTMPWPANoneAddKeyProc(
200 IN PRTMP_ADAPTER pAd,
201 IN PVOID pBuf);
202
203INT Set_FragTest_Proc(
204 IN PRTMP_ADAPTER pAdapter,
205 IN PUCHAR arg);
206
91980990
GKH
207INT Set_TGnWifiTest_Proc(
208 IN PRTMP_ADAPTER pAd,
209 IN PUCHAR arg);
91980990
GKH
210
211INT Set_LongRetryLimit_Proc(
212 IN PRTMP_ADAPTER pAdapter,
213 IN PUCHAR arg);
214
215INT Set_ShortRetryLimit_Proc(
216 IN PRTMP_ADAPTER pAdapter,
217 IN PUCHAR arg);
218
3a32ed12
BZ
219#if !defined(RT2860) && !defined(RT30xx)
220INT Show_Adhoc_MacTable_Proc(
221 IN PRTMP_ADAPTER pAd,
222 IN PCHAR extra);
223#endif
224
91980990
GKH
225static struct {
226 CHAR *name;
227 INT (*set_proc)(PRTMP_ADAPTER pAdapter, PUCHAR arg);
228} *PRTMP_PRIVATE_SET_PROC, RTMP_PRIVATE_SUPPORT_PROC[] = {
229 {"DriverVersion", Set_DriverVersion_Proc},
230 {"CountryRegion", Set_CountryRegion_Proc},
231 {"CountryRegionABand", Set_CountryRegionABand_Proc},
232 {"SSID", Set_SSID_Proc},
233 {"WirelessMode", Set_WirelessMode_Proc},
234 {"TxBurst", Set_TxBurst_Proc},
235 {"TxPreamble", Set_TxPreamble_Proc},
236 {"TxPower", Set_TxPower_Proc},
237 {"Channel", Set_Channel_Proc},
238 {"BGProtection", Set_BGProtection_Proc},
239 {"RTSThreshold", Set_RTSThreshold_Proc},
240 {"FragThreshold", Set_FragThreshold_Proc},
91980990
GKH
241 {"HtBw", Set_HtBw_Proc},
242 {"HtMcs", Set_HtMcs_Proc},
243 {"HtGi", Set_HtGi_Proc},
244 {"HtOpMode", Set_HtOpMode_Proc},
245 {"HtExtcha", Set_HtExtcha_Proc},
246 {"HtMpduDensity", Set_HtMpduDensity_Proc},
247 {"HtBaWinSize", Set_HtBaWinSize_Proc},
248 {"HtRdg", Set_HtRdg_Proc},
249 {"HtAmsdu", Set_HtAmsdu_Proc},
250 {"HtAutoBa", Set_HtAutoBa_Proc},
251 {"HtBaDecline", Set_BADecline_Proc},
252 {"HtProtect", Set_HtProtect_Proc},
253 {"HtMimoPs", Set_HtMimoPs_Proc},
91980990
GKH
254#ifdef AGGREGATION_SUPPORT
255 {"PktAggregate", Set_PktAggregate_Proc},
256#endif
257
258#ifdef WMM_SUPPORT
259 {"WmmCapable", Set_WmmCapable_Proc},
260#endif
261 {"IEEE80211H", Set_IEEE80211H_Proc},
262 {"NetworkType", Set_NetworkType_Proc},
263 {"AuthMode", Set_AuthMode_Proc},
264 {"EncrypType", Set_EncrypType_Proc},
265 {"DefaultKeyID", Set_DefaultKeyID_Proc},
266 {"Key1", Set_Key1_Proc},
267 {"Key2", Set_Key2_Proc},
268 {"Key3", Set_Key3_Proc},
269 {"Key4", Set_Key4_Proc},
270 {"WPAPSK", Set_WPAPSK_Proc},
271 {"ResetCounter", Set_ResetStatCounter_Proc},
272 {"PSMode", Set_PSMode_Proc},
273#ifdef DBG
274 {"Debug", Set_Debug_Proc},
275#endif
91980990 276 {"WpaSupport", Set_Wpa_Support},
91980990 277 {"FixedTxMode", Set_FixedTxMode_Proc},
91980990
GKH
278 {"TGnWifiTest", Set_TGnWifiTest_Proc},
279 {"ForceGF", Set_ForceGF_Proc},
91980990
GKH
280 {"LongRetry", Set_LongRetryLimit_Proc},
281 {"ShortRetry", Set_ShortRetryLimit_Proc},
3a32ed12
BZ
282//2008/09/11:KH add to support efuse<--
283#ifdef RT30xx
284 {"efuseFreeNumber", set_eFuseGetFreeBlockCount_Proc},
285 {"efuseDump", set_eFusedump_Proc},
286 {"efuseLoadFromBin", set_eFuseLoadFromBin_Proc},
287#endif // RT30xx //
288//2008/09/11:KH add to support efuse-->
91980990
GKH
289 {NULL,}
290};
291
292
293VOID RTMPAddKey(
294 IN PRTMP_ADAPTER pAd,
295 IN PNDIS_802_11_KEY pKey)
296{
297 ULONG KeyIdx;
298 MAC_TABLE_ENTRY *pEntry;
299
300 DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey ------>\n"));
301
3a32ed12 302#ifdef RT2860
ed291e80
AM
303 RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
304 if (RTMP_TEST_PSFLAG(pAd, fRTMP_PS_SET_PCI_CLK_OFF_COMMAND))
305 {
306 if (pAd->StaCfg.bRadio == FALSE)
307 {
308 RTMP_SET_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
f72c4bf5 309 return;
ed291e80
AM
310 }
311 DBGPRINT(RT_DEBUG_TRACE,("RTMPWPAAddKeyProc1==>\n"));
312 RTMPPCIeLinkCtrlValueRestore(pAd, RESTORE_HALT);
313 RTMPusecDelay(6000);
314 pAd->bPCIclkOff = FALSE;
315 }
3a32ed12 316#endif
ed291e80 317
91980990
GKH
318 if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
319 {
320 if (pKey->KeyIndex & 0x80000000)
321 {
322 if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
323 {
324 NdisZeroMemory(pAd->StaCfg.PMK, 32);
325 NdisMoveMemory(pAd->StaCfg.PMK, pKey->KeyMaterial, pKey->KeyLength);
326 goto end;
327 }
328 // Update PTK
329 NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));
330 pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
331 NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, pKey->KeyMaterial, LEN_TKIP_EK);
e08bae5a 332
91980990
GKH
333 if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
334 {
335 NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
336 NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
337 }
338 else
91980990
GKH
339 {
340 NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
341 NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
342 }
343
344 // Decide its ChiperAlg
345 if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
346 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
347 else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)
348 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
349 else
350 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_NONE;
351
352 // Update these related information to MAC_TABLE_ENTRY
353 pEntry = &pAd->MacTab.Content[BSSID_WCID];
354 NdisMoveMemory(pEntry->PairwiseKey.Key, pAd->SharedKey[BSS0][0].Key, LEN_TKIP_EK);
355 NdisMoveMemory(pEntry->PairwiseKey.RxMic, pAd->SharedKey[BSS0][0].RxMic, LEN_TKIP_RXMICK);
356 NdisMoveMemory(pEntry->PairwiseKey.TxMic, pAd->SharedKey[BSS0][0].TxMic, LEN_TKIP_TXMICK);
357 pEntry->PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;
358
359 // Update pairwise key information to ASIC Shared Key Table
360 AsicAddSharedKeyEntry(pAd,
361 BSS0,
362 0,
363 pAd->SharedKey[BSS0][0].CipherAlg,
364 pAd->SharedKey[BSS0][0].Key,
365 pAd->SharedKey[BSS0][0].TxMic,
366 pAd->SharedKey[BSS0][0].RxMic);
367
368 // Update ASIC WCID attribute table and IVEIV table
369 RTMPAddWcidAttributeEntry(pAd,
370 BSS0,
371 0,
372 pAd->SharedKey[BSS0][0].CipherAlg,
373 pEntry);
374
375 if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
376 {
377 // set 802.1x port control
378 STA_PORT_SECURED(pAd);
379
380 // Indicate Connected for GUI
381 pAd->IndicateMediaState = NdisMediaStateConnected;
382 }
383 }
384 else
385 {
386 // Update GTK
387 pAd->StaCfg.DefaultKeyId = (pKey->KeyIndex & 0xFF);
388 NdisZeroMemory(&pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId], sizeof(CIPHER_KEY));
389 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].KeyLen = LEN_TKIP_EK;
390 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key, pKey->KeyMaterial, LEN_TKIP_EK);
e08bae5a 391
91980990
GKH
392 if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
393 {
394 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
395 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
396 }
397 else
91980990
GKH
398 {
399 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);
400 NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
401 }
402
403 // Update Shared Key CipherAlg
404 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_NONE;
405 if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
406 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_TKIP;
407 else if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)
408 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_AES;
409
410 // Update group key information to ASIC Shared Key Table
411 AsicAddSharedKeyEntry(pAd,
412 BSS0,
413 pAd->StaCfg.DefaultKeyId,
414 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
415 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key,
416 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic,
417 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic);
418
419 // Update ASIC WCID attribute table and IVEIV table
420 RTMPAddWcidAttributeEntry(pAd,
421 BSS0,
422 pAd->StaCfg.DefaultKeyId,
423 pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,
424 NULL);
425
426 // set 802.1x port control
427 STA_PORT_SECURED(pAd);
428
429 // Indicate Connected for GUI
430 pAd->IndicateMediaState = NdisMediaStateConnected;
431 }
432 }
433 else // dynamic WEP from wpa_supplicant
434 {
435 UCHAR CipherAlg;
436 PUCHAR Key;
437
438 if(pKey->KeyLength == 32)
439 goto end;
440
441 KeyIdx = pKey->KeyIndex & 0x0fffffff;
442
443 if (KeyIdx < 4)
444 {
445 // it is a default shared key, for Pairwise key setting
446 if (pKey->KeyIndex & 0x80000000)
447 {
448 pEntry = MacTableLookup(pAd, pKey->BSSID);
449
450 if (pEntry)
451 {
452 DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey: Set Pair-wise Key\n"));
453
454 // set key material and key length
455 pEntry->PairwiseKey.KeyLen = (UCHAR)pKey->KeyLength;
456 NdisMoveMemory(pEntry->PairwiseKey.Key, &pKey->KeyMaterial, pKey->KeyLength);
457
458 // set Cipher type
459 if (pKey->KeyLength == 5)
460 pEntry->PairwiseKey.CipherAlg = CIPHER_WEP64;
461 else
462 pEntry->PairwiseKey.CipherAlg = CIPHER_WEP128;
463
464 // Add Pair-wise key to Asic
465 AsicAddPairwiseKeyEntry(
466 pAd,
467 pEntry->Addr,
468 (UCHAR)pEntry->Aid,
469 &pEntry->PairwiseKey);
470
471 // update WCID attribute table and IVEIV table for this entry
472 RTMPAddWcidAttributeEntry(
473 pAd,
474 BSS0,
475 KeyIdx, // The value may be not zero
476 pEntry->PairwiseKey.CipherAlg,
477 pEntry);
478
479 }
480 }
481 else
482 {
483 // Default key for tx (shared key)
484 pAd->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
485
486 // set key material and key length
487 pAd->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pKey->KeyLength;
488 NdisMoveMemory(pAd->SharedKey[BSS0][KeyIdx].Key, &pKey->KeyMaterial, pKey->KeyLength);
489
490 // Set Ciper type
491 if (pKey->KeyLength == 5)
492 pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP64;
493 else
494 pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP128;
495
496 CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg;
497 Key = pAd->SharedKey[BSS0][KeyIdx].Key;
498
499 // Set Group key material to Asic
500 AsicAddSharedKeyEntry(pAd, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
501
502 // Update WCID attribute table and IVEIV table for this group key table
503 RTMPAddWcidAttributeEntry(pAd, BSS0, KeyIdx, CipherAlg, NULL);
504
505 }
506 }
507 }
508end:
3a32ed12 509#ifdef RT2860
ed291e80
AM
510 RTMP_SET_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
511 DBGPRINT(RT_DEBUG_INFO, ("<------ RTMPAddKey\n"));
3a32ed12 512#endif
91980990
GKH
513 return;
514}
515
516char * rtstrchr(const char * s, int c)
517{
518 for(; *s != (char) c; ++s)
519 if (*s == '\0')
520 return NULL;
521 return (char *) s;
522}
523
524/*
525This is required for LinEX2004/kernel2.6.7 to provide iwlist scanning function
526*/
527
528int
529rt_ioctl_giwname(struct net_device *dev,
530 struct iw_request_info *info,
531 char *name, char *extra)
532{
739b7979 533// PRTMP_ADAPTER pAdapter = dev->ml_priv;
b8bc58c5 534 strncpy(name, RT28xx_CHIP_NAME " Wireless", IFNAMSIZ);
91980990
GKH
535 return 0;
536}
537
538int rt_ioctl_siwfreq(struct net_device *dev,
539 struct iw_request_info *info,
540 struct iw_freq *freq, char *extra)
541{
739b7979 542 PRTMP_ADAPTER pAdapter = dev->ml_priv;
91980990
GKH
543 int chan = -1;
544
545 //check if the interface is down
546 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
547 {
548 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
549 return -ENETDOWN;
550 }
551
552
553 if (freq->e > 1)
554 return -EINVAL;
555
556 if((freq->e == 0) && (freq->m <= 1000))
557 chan = freq->m; // Setting by channel number
558 else
559 MAP_KHZ_TO_CHANNEL_ID( (freq->m /100) , chan); // Setting by frequency - search the table , like 2.412G, 2.422G,
560
561 if (ChannelSanity(pAdapter, chan) == TRUE)
562 {
563 pAdapter->CommonCfg.Channel = chan;
564 DBGPRINT(RT_DEBUG_ERROR, ("==>rt_ioctl_siwfreq::SIOCSIWFREQ[cmd=0x%x] (Channel=%d)\n", SIOCSIWFREQ, pAdapter->CommonCfg.Channel));
565 }
566 else
567 return -EINVAL;
568
569 return 0;
570}
571int rt_ioctl_giwfreq(struct net_device *dev,
572 struct iw_request_info *info,
573 struct iw_freq *freq, char *extra)
574{
575 VIRTUAL_ADAPTER *pVirtualAd = NULL;
3a32ed12 576#ifndef RT30xx
91980990 577 PRTMP_ADAPTER pAdapter = NULL;
3a32ed12
BZ
578#endif
579#ifdef RT30xx
580 PRTMP_ADAPTER pAdapter;
581#endif
91980990
GKH
582 UCHAR ch;
583 ULONG m;
584
585 if (dev->priv_flags == INT_MAIN)
586 {
739b7979 587 pAdapter = dev->ml_priv;
91980990
GKH
588 }
589 else
590 {
739b7979 591 pVirtualAd = dev->ml_priv;
3a32ed12 592#ifndef RT30xx
91980990 593 if (pVirtualAd && pVirtualAd->RtmpDev)
3a32ed12 594#endif
739b7979 595 pAdapter = pVirtualAd->RtmpDev->ml_priv;
91980990
GKH
596 }
597
598 if (pAdapter == NULL)
599 {
600 /* if 1st open fail, pAd will be free;
739b7979 601 So the net_dev->ml_priv will be NULL in 2rd open */
91980990
GKH
602 return -ENETDOWN;
603 }
604
605 ch = pAdapter->CommonCfg.Channel;
606
607 DBGPRINT(RT_DEBUG_TRACE,("==>rt_ioctl_giwfreq %d\n", ch));
608
609 MAP_CHANNEL_ID_TO_KHZ(ch, m);
610 freq->m = m * 100;
611 freq->e = 1;
612 return 0;
613}
614
615int rt_ioctl_siwmode(struct net_device *dev,
616 struct iw_request_info *info,
617 __u32 *mode, char *extra)
618{
739b7979 619 PRTMP_ADAPTER pAdapter = dev->ml_priv;
91980990
GKH
620
621 //check if the interface is down
622 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
623 {
624 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
625 return -ENETDOWN;
626 }
627
628 switch (*mode)
629 {
630 case IW_MODE_ADHOC:
631 Set_NetworkType_Proc(pAdapter, "Adhoc");
632 break;
633 case IW_MODE_INFRA:
634 Set_NetworkType_Proc(pAdapter, "Infra");
635 break;
91980990
GKH
636 case IW_MODE_MONITOR:
637 Set_NetworkType_Proc(pAdapter, "Monitor");
638 break;
91980990
GKH
639 default:
640 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_siwmode::SIOCSIWMODE (unknown %d)\n", *mode));
641 return -EINVAL;
642 }
643
644 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
645 pAdapter->StaCfg.WpaState = SS_NOTUSE;
646
647 return 0;
648}
649
650int rt_ioctl_giwmode(struct net_device *dev,
651 struct iw_request_info *info,
652 __u32 *mode, char *extra)
653{
3a32ed12 654#ifndef RT30xx
91980990
GKH
655 PRTMP_ADAPTER pAdapter = NULL;
656 VIRTUAL_ADAPTER *pVirtualAd = NULL;
657
658 if (dev->priv_flags == INT_MAIN)
659 {
739b7979 660 pAdapter = dev->ml_priv;
91980990
GKH
661 }
662 else
663 {
739b7979 664 pVirtualAd = dev->ml_priv;
91980990 665 if (pVirtualAd && pVirtualAd->RtmpDev)
739b7979 666 pAdapter = pVirtualAd->RtmpDev->ml_priv;
91980990
GKH
667 }
668
669 if (pAdapter == NULL)
670 {
671 /* if 1st open fail, pAd will be free;
739b7979 672 So the net_dev->ml_priv will be NULL in 2rd open */
91980990
GKH
673 return -ENETDOWN;
674 }
3a32ed12
BZ
675#endif
676#ifdef RT30xx
677 PRTMP_ADAPTER pAdapter = dev->ml_priv;
678#endif
91980990
GKH
679
680 if (ADHOC_ON(pAdapter))
681 *mode = IW_MODE_ADHOC;
682 else if (INFRA_ON(pAdapter))
683 *mode = IW_MODE_INFRA;
91980990
GKH
684 else if (MONITOR_ON(pAdapter))
685 {
686 *mode = IW_MODE_MONITOR;
687 }
91980990
GKH
688 else
689 *mode = IW_MODE_AUTO;
690
691 DBGPRINT(RT_DEBUG_TRACE, ("==>rt_ioctl_giwmode(mode=%d)\n", *mode));
692 return 0;
693}
694
695int rt_ioctl_siwsens(struct net_device *dev,
696 struct iw_request_info *info,
697 char *name, char *extra)
698{
739b7979 699 PRTMP_ADAPTER pAdapter = dev->ml_priv;
91980990
GKH
700
701 //check if the interface is down
702 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
703 {
704 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
705 return -ENETDOWN;
706 }
707
708 return 0;
709}
710
711int rt_ioctl_giwsens(struct net_device *dev,
712 struct iw_request_info *info,
713 char *name, char *extra)
714{
715 return 0;
716}
717
718int rt_ioctl_giwrange(struct net_device *dev,
719 struct iw_request_info *info,
720 struct iw_point *data, char *extra)
721{
3a32ed12 722#ifndef RT30xx
91980990
GKH
723 PRTMP_ADAPTER pAdapter = NULL;
724 VIRTUAL_ADAPTER *pVirtualAd = NULL;
3a32ed12
BZ
725#endif
726#ifdef RT30xx
727 PRTMP_ADAPTER pAdapter = dev->ml_priv;
728#endif
91980990
GKH
729 struct iw_range *range = (struct iw_range *) extra;
730 u16 val;
731 int i;
732
3a32ed12 733#ifndef RT30xx
91980990
GKH
734 if (dev->priv_flags == INT_MAIN)
735 {
739b7979 736 pAdapter = dev->ml_priv;
91980990
GKH
737 }
738 else
739 {
739b7979 740 pVirtualAd = dev->ml_priv;
91980990 741 if (pVirtualAd && pVirtualAd->RtmpDev)
739b7979 742 pAdapter = pVirtualAd->RtmpDev->ml_priv;
91980990
GKH
743 }
744
745 if (pAdapter == NULL)
746 {
747 /* if 1st open fail, pAd will be free;
739b7979 748 So the net_dev->ml_priv will be NULL in 2rd open */
91980990
GKH
749 return -ENETDOWN;
750 }
3a32ed12 751#endif
91980990
GKH
752
753 DBGPRINT(RT_DEBUG_TRACE ,("===>rt_ioctl_giwrange\n"));
754 data->length = sizeof(struct iw_range);
755 memset(range, 0, sizeof(struct iw_range));
756
757 range->txpower_capa = IW_TXPOW_DBM;
758
759 if (INFRA_ON(pAdapter)||ADHOC_ON(pAdapter))
760 {
761 range->min_pmp = 1 * 1024;
762 range->max_pmp = 65535 * 1024;
763 range->min_pmt = 1 * 1024;
764 range->max_pmt = 1000 * 1024;
765 range->pmp_flags = IW_POWER_PERIOD;
766 range->pmt_flags = IW_POWER_TIMEOUT;
767 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT |
768 IW_POWER_UNICAST_R | IW_POWER_ALL_R;
769 }
770
771 range->we_version_compiled = WIRELESS_EXT;
772 range->we_version_source = 14;
773
774 range->retry_capa = IW_RETRY_LIMIT;
775 range->retry_flags = IW_RETRY_LIMIT;
776 range->min_retry = 0;
777 range->max_retry = 255;
778
779 range->num_channels = pAdapter->ChannelListNum;
780
781 val = 0;
782 for (i = 1; i <= range->num_channels; i++)
783 {
784 u32 m;
785 range->freq[val].i = pAdapter->ChannelList[i-1].Channel;
786 MAP_CHANNEL_ID_TO_KHZ(pAdapter->ChannelList[i-1].Channel, m);
787 range->freq[val].m = m * 100; /* HZ */
788
789 range->freq[val].e = 1;
790 val++;
791 if (val == IW_MAX_FREQUENCIES)
792 break;
793 }
794 range->num_frequency = val;
795
796 range->max_qual.qual = 100; /* what is correct max? This was not
797 * documented exactly. At least
798 * 69 has been observed. */
799 range->max_qual.level = 0; /* dB */
800 range->max_qual.noise = 0; /* dB */
801
802 /* What would be suitable values for "average/typical" qual? */
803 range->avg_qual.qual = 20;
804 range->avg_qual.level = -60;
805 range->avg_qual.noise = -95;
806 range->sensitivity = 3;
807
808 range->max_encoding_tokens = NR_WEP_KEYS;
809 range->num_encoding_sizes = 2;
810 range->encoding_size[0] = 5;
811 range->encoding_size[1] = 13;
812
813 range->min_rts = 0;
814 range->max_rts = 2347;
815 range->min_frag = 256;
816 range->max_frag = 2346;
817
818#if WIRELESS_EXT > 17
819 /* IW_ENC_CAPA_* bit field */
820 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
821 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
822#endif
823
824 return 0;
825}
826
827int rt_ioctl_siwap(struct net_device *dev,
828 struct iw_request_info *info,
829 struct sockaddr *ap_addr, char *extra)
830{
739b7979 831 PRTMP_ADAPTER pAdapter = dev->ml_priv;
91980990
GKH
832 NDIS_802_11_MAC_ADDRESS Bssid;
833
834 //check if the interface is down
835 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
836 {
837 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
838 return -ENETDOWN;
839 }
840
841 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
842 {
843 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
844 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
845 }
846
847 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
848 // this request, because this request is initiated by NDIS.
849 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
850 // Prevent to connect AP again in STAMlmePeriodicExec
851 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
852
853 memset(Bssid, 0, MAC_ADDR_LEN);
854 memcpy(Bssid, ap_addr->sa_data, MAC_ADDR_LEN);
855 MlmeEnqueue(pAdapter,
856 MLME_CNTL_STATE_MACHINE,
857 OID_802_11_BSSID,
858 sizeof(NDIS_802_11_MAC_ADDRESS),
859 (VOID *)&Bssid);
860
861 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCSIWAP %02x:%02x:%02x:%02x:%02x:%02x\n",
862 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
863
864 return 0;
865}
866
867int rt_ioctl_giwap(struct net_device *dev,
868 struct iw_request_info *info,
869 struct sockaddr *ap_addr, char *extra)
870{
3a32ed12 871#ifndef RT30xx
91980990
GKH
872 PRTMP_ADAPTER pAdapter = NULL;
873 VIRTUAL_ADAPTER *pVirtualAd = NULL;
874
875 if (dev->priv_flags == INT_MAIN)
876 {
739b7979 877 pAdapter = dev->ml_priv;
91980990
GKH
878 }
879 else
880 {
739b7979 881 pVirtualAd = dev->ml_priv;
91980990 882 if (pVirtualAd && pVirtualAd->RtmpDev)
739b7979 883 pAdapter = pVirtualAd->RtmpDev->ml_priv;
91980990
GKH
884 }
885
886 if (pAdapter == NULL)
887 {
888 /* if 1st open fail, pAd will be free;
739b7979 889 So the net_dev->ml_priv will be NULL in 2rd open */
91980990
GKH
890 return -ENETDOWN;
891 }
3a32ed12
BZ
892#endif
893#ifdef RT30xx
894 PRTMP_ADAPTER pAdapter = dev->ml_priv;
895#endif
91980990
GKH
896
897 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
898 {
899 ap_addr->sa_family = ARPHRD_ETHER;
900 memcpy(ap_addr->sa_data, &pAdapter->CommonCfg.Bssid, ETH_ALEN);
901 }
91980990
GKH
902 // Add for RT2870
903 else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
904 {
905 ap_addr->sa_family = ARPHRD_ETHER;
906 memcpy(ap_addr->sa_data, &pAdapter->MlmeAux.Bssid, ETH_ALEN);
907 }
91980990
GKH
908 else
909 {
910 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIWAP(=EMPTY)\n"));
911 return -ENOTCONN;
912 }
913
914 return 0;
915}
916
917/*
918 * Units are in db above the noise floor. That means the
919 * rssi values reported in the tx/rx descriptors in the
920 * driver are the SNR expressed in db.
921 *
922 * If you assume that the noise floor is -95, which is an
923 * excellent assumption 99.5 % of the time, then you can
924 * derive the absolute signal level (i.e. -95 + rssi).
925 * There are some other slight factors to take into account
926 * depending on whether the rssi measurement is from 11b,
927 * 11g, or 11a. These differences are at most 2db and
928 * can be documented.
929 *
930 * NB: various calculations are based on the orinoco/wavelan
931 * drivers for compatibility
932 */
933static void set_quality(PRTMP_ADAPTER pAdapter,
934 struct iw_quality *iq,
935 signed char rssi)
936{
937 __u8 ChannelQuality;
938
939 // Normalize Rssi
940 if (rssi >= -50)
941 ChannelQuality = 100;
942 else if (rssi >= -80) // between -50 ~ -80dbm
943 ChannelQuality = (__u8)(24 + ((rssi + 80) * 26)/10);
944 else if (rssi >= -90) // between -80 ~ -90dbm
945 ChannelQuality = (__u8)((rssi + 90) * 26)/10;
946 else
947 ChannelQuality = 0;
948
949 iq->qual = (__u8)ChannelQuality;
950
951 iq->level = (__u8)(rssi);
952 iq->noise = (pAdapter->BbpWriteLatch[66] > pAdapter->BbpTuning.FalseCcaUpperThreshold) ? ((__u8)pAdapter->BbpTuning.FalseCcaUpperThreshold) : ((__u8) pAdapter->BbpWriteLatch[66]); // noise level (dBm)
953 iq->noise += 256 - 143;
954 iq->updated = pAdapter->iw_stats.qual.updated;
955}
956
957int rt_ioctl_iwaplist(struct net_device *dev,
958 struct iw_request_info *info,
959 struct iw_point *data, char *extra)
960{
739b7979 961 PRTMP_ADAPTER pAdapter = dev->ml_priv;
91980990
GKH
962
963 struct sockaddr addr[IW_MAX_AP];
964 struct iw_quality qual[IW_MAX_AP];
965 int i;
966
967 //check if the interface is down
968 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
969 {
970 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
971 data->length = 0;
972 return 0;
973 //return -ENETDOWN;
974 }
975
976 for (i = 0; i <IW_MAX_AP ; i++)
977 {
978 if (i >= pAdapter->ScanTab.BssNr)
979 break;
980 addr[i].sa_family = ARPHRD_ETHER;
981 memcpy(addr[i].sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
982 set_quality(pAdapter, &qual[i], pAdapter->ScanTab.BssEntry[i].Rssi);
983 }
984 data->length = i;
985 memcpy(extra, &addr, i*sizeof(addr[0]));
986 data->flags = 1; /* signal quality present (sort of) */
987 memcpy(extra + i*sizeof(addr[0]), &qual, i*sizeof(qual[i]));
988
989 return 0;
990}
991
992#ifdef SIOCGIWSCAN
993int rt_ioctl_siwscan(struct net_device *dev,
994 struct iw_request_info *info,
995 struct iw_point *data, char *extra)
996{
739b7979 997 PRTMP_ADAPTER pAdapter = dev->ml_priv;
91980990
GKH
998
999 ULONG Now;
1000 int Status = NDIS_STATUS_SUCCESS;
1001
1002 //check if the interface is down
1003 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1004 {
1005 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1006 return -ENETDOWN;
1007 }
1008
1009 if (MONITOR_ON(pAdapter))
1010 {
1011 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
1012 return -EINVAL;
1013 }
3a32ed12 1014#ifdef RT2860
ed291e80
AM
1015 if ((pAdapter->OpMode == OPMODE_STA) && (IDLE_ON(pAdapter))
1016 && (pAdapter->StaCfg.bRadio == TRUE)
1017 && (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_IDLE_RADIO_OFF)))
1018 {
1019 RT28xxPciAsicRadioOn(pAdapter, GUI_IDLE_POWER_SAVE);
1020 }
1021 // Check if still radio off.
1022 else if (pAdapter->bPCIclkOff == TRUE)
1023 return 0;
3a32ed12 1024#endif
91980990
GKH
1025 if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
1026 {
1027 pAdapter->StaCfg.WpaSupplicantScanCount++;
1028 }
91980990
GKH
1029
1030 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
1031 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
1032 return 0;
1033 do{
1034 Now = jiffies;
1035
91980990
GKH
1036 if ((pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE) &&
1037 (pAdapter->StaCfg.WpaSupplicantScanCount > 3))
1038 {
1039 DBGPRINT(RT_DEBUG_TRACE, ("!!! WpaSupplicantScanCount > 3\n"));
1040 Status = NDIS_STATUS_SUCCESS;
1041 break;
1042 }
91980990
GKH
1043
1044 if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&
1045 ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
1046 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) &&
1047 (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
1048 {
1049 DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));
1050 Status = NDIS_STATUS_SUCCESS;
1051 break;
1052 }
1053
1054 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
1055 {
1056 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
1057 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
1058 }
1059
1060 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
1061 // this request, because this request is initiated by NDIS.
1062 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
1063 // Reset allowed scan retries
1064 pAdapter->StaCfg.ScanCnt = 0;
1065 pAdapter->StaCfg.LastScanTime = Now;
1066
1067 MlmeEnqueue(pAdapter,
1068 MLME_CNTL_STATE_MACHINE,
1069 OID_802_11_BSSID_LIST_SCAN,
1070 0,
1071 NULL);
1072
1073 Status = NDIS_STATUS_SUCCESS;
1074 RT28XX_MLME_HANDLER(pAdapter);
1075 }while(0);
1076 return 0;
1077}
1078
1079int rt_ioctl_giwscan(struct net_device *dev,
1080 struct iw_request_info *info,
1081 struct iw_point *data, char *extra)
1082{
1083
739b7979 1084 PRTMP_ADAPTER pAdapter = dev->ml_priv;
91980990
GKH
1085 int i=0;
1086 char *current_ev = extra, *previous_ev = extra;
1087 char *end_buf;
1088 char *current_val, custom[MAX_CUSTOM_LEN] = {0};
1089#ifndef IWEVGENIE
1090 char idx;
1091#endif // IWEVGENIE //
1092 struct iw_event iwe;
1093
1094 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
1095 {
1096 /*
1097 * Still scanning, indicate the caller should try again.
1098 */
1099 return -EAGAIN;
1100 }
1101
91980990
GKH
1102 if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
1103 {
1104 pAdapter->StaCfg.WpaSupplicantScanCount = 0;
1105 }
91980990
GKH
1106
1107 if (pAdapter->ScanTab.BssNr == 0)
1108 {
1109 data->length = 0;
1110 return 0;
1111 }
1112
1113#if WIRELESS_EXT >= 17
1114 if (data->length > 0)
1115 end_buf = extra + data->length;
1116 else
1117 end_buf = extra + IW_SCAN_MAX_DATA;
1118#else
1119 end_buf = extra + IW_SCAN_MAX_DATA;
1120#endif
1121
1122 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
1123 {
1124 if (current_ev >= end_buf)
1125 {
1126#if WIRELESS_EXT >= 17
1127 return -E2BIG;
1128#else
1129 break;
1130#endif
1131 }
1132
1133 //MAC address
1134 //================================
1135 memset(&iwe, 0, sizeof(iwe));
1136 iwe.cmd = SIOCGIWAP;
1137 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1138 memcpy(iwe.u.ap_addr.sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, ETH_ALEN);
1139
1140 previous_ev = current_ev;
27eff3bf 1141 current_ev = iwe_stream_add_event(info, current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);
3a32ed12
BZ
1142#ifdef RT30xx
1143 if (current_ev == previous_ev)
1144#if WIRELESS_EXT >= 17
1145 return -E2BIG;
1146#else
1147 break;
1148#endif
1149
1150 /*
1151 Protocol:
1152 it will show scanned AP's WirelessMode .
1153 it might be
1154 802.11a
1155 802.11a/n
1156 802.11g/n
1157 802.11b/g/n
1158 802.11g
1159 802.11b/g
1160 */
1161 memset(&iwe, 0, sizeof(iwe));
1162 iwe.cmd = SIOCGIWNAME;
1163
1164
1165 {
1166 PBSS_ENTRY pBssEntry=&pAdapter->ScanTab.BssEntry[i];
1167 BOOLEAN isGonly=FALSE;
1168 int rateCnt=0;
1169
1170 if (pBssEntry->Channel>14)
1171 {
1172 if (pBssEntry->HtCapabilityLen!=0)
1173 strcpy(iwe.u.name,"802.11a/n");
1174 else
1175 strcpy(iwe.u.name,"802.11a");
1176 }
1177 else
1178 {
1179 /*
1180 if one of non B mode rate is set supported rate . it mean G only.
1181 */
1182 for (rateCnt=0;rateCnt<pBssEntry->SupRateLen;rateCnt++)
1183 {
1184 /*
1185 6Mbps(140) 9Mbps(146) and >=12Mbps(152) are supported rate , it mean G only.
1186 */
1187 if (pBssEntry->SupRate[rateCnt]==140 || pBssEntry->SupRate[rateCnt]==146 || pBssEntry->SupRate[rateCnt]>=152)
1188 isGonly=TRUE;
1189 }
1190
1191 for (rateCnt=0;rateCnt<pBssEntry->ExtRateLen;rateCnt++)
1192 {
1193 if (pBssEntry->ExtRate[rateCnt]==140 || pBssEntry->ExtRate[rateCnt]==146 || pBssEntry->ExtRate[rateCnt]>=152)
1194 isGonly=TRUE;
1195 }
1196
1197
1198 if (pBssEntry->HtCapabilityLen!=0)
1199 {
1200 if (isGonly==TRUE)
1201 strcpy(iwe.u.name,"802.11g/n");
1202 else
1203 strcpy(iwe.u.name,"802.11b/g/n");
1204 }
1205 else
1206 {
1207 if (isGonly==TRUE)
1208 strcpy(iwe.u.name,"802.11g");
1209 else
1210 {
1211 if (pBssEntry->SupRateLen==4 && pBssEntry->ExtRateLen==0)
1212 strcpy(iwe.u.name,"802.11b");
1213 else
1214 strcpy(iwe.u.name,"802.11b/g");
1215 }
1216 }
1217 }
1218 }
1219
1220 previous_ev = current_ev;
1221 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
1222#endif /* RT30xx */
91980990
GKH
1223 if (current_ev == previous_ev)
1224#if WIRELESS_EXT >= 17
1225 return -E2BIG;
1226#else
1227 break;
1228#endif
1229
1230 //ESSID
1231 //================================
1232 memset(&iwe, 0, sizeof(iwe));
1233 iwe.cmd = SIOCGIWESSID;
1234 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].SsidLen;
1235 iwe.u.data.flags = 1;
1236
1237 previous_ev = current_ev;
27eff3bf 1238 current_ev = iwe_stream_add_point(info, current_ev,end_buf, &iwe, pAdapter->ScanTab.BssEntry[i].Ssid);
91980990
GKH
1239 if (current_ev == previous_ev)
1240#if WIRELESS_EXT >= 17
1241 return -E2BIG;
1242#else
1243 break;
1244#endif
1245
1246 //Network Type
1247 //================================
1248 memset(&iwe, 0, sizeof(iwe));
1249 iwe.cmd = SIOCGIWMODE;
1250 if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11IBSS)
1251 {
1252 iwe.u.mode = IW_MODE_ADHOC;
1253 }
1254 else if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11Infrastructure)
1255 {
1256 iwe.u.mode = IW_MODE_INFRA;
1257 }
1258 else
1259 {
1260 iwe.u.mode = IW_MODE_AUTO;
1261 }
1262 iwe.len = IW_EV_UINT_LEN;
1263
1264 previous_ev = current_ev;
27eff3bf 1265 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
91980990
GKH
1266 if (current_ev == previous_ev)
1267#if WIRELESS_EXT >= 17
1268 return -E2BIG;
1269#else
1270 break;
1271#endif
1272
1273 //Channel and Frequency
1274 //================================
1275 memset(&iwe, 0, sizeof(iwe));
1276 iwe.cmd = SIOCGIWFREQ;
1277 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
1278 iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
1279 else
1280 iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;
1281 iwe.u.freq.e = 0;
1282 iwe.u.freq.i = 0;
1283
1284 previous_ev = current_ev;
27eff3bf 1285 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
91980990
GKH
1286 if (current_ev == previous_ev)
1287#if WIRELESS_EXT >= 17
1288 return -E2BIG;
1289#else
1290 break;
1291#endif
1292
1293 //Add quality statistics
1294 //================================
1295 memset(&iwe, 0, sizeof(iwe));
1296 iwe.cmd = IWEVQUAL;
1297 iwe.u.qual.level = 0;
1298 iwe.u.qual.noise = 0;
1299 set_quality(pAdapter, &iwe.u.qual, pAdapter->ScanTab.BssEntry[i].Rssi);
27eff3bf 1300 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
91980990
GKH
1301 if (current_ev == previous_ev)
1302#if WIRELESS_EXT >= 17
1303 return -E2BIG;
1304#else
1305 break;
1306#endif
1307
1308 //Encyption key
1309 //================================
1310 memset(&iwe, 0, sizeof(iwe));
1311 iwe.cmd = SIOCGIWENCODE;
1312 if (CAP_IS_PRIVACY_ON (pAdapter->ScanTab.BssEntry[i].CapabilityInfo ))
1313 iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1314 else
1315 iwe.u.data.flags = IW_ENCODE_DISABLED;
1316
1317 previous_ev = current_ev;
27eff3bf 1318 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);
91980990
GKH
1319 if (current_ev == previous_ev)
1320#if WIRELESS_EXT >= 17
1321 return -E2BIG;
1322#else
1323 break;
1324#endif
1325
1326 //Bit Rate
1327 //================================
1328 if (pAdapter->ScanTab.BssEntry[i].SupRateLen)
1329 {
1330 UCHAR tmpRate = pAdapter->ScanTab.BssEntry[i].SupRate[pAdapter->ScanTab.BssEntry[i].SupRateLen-1];
1331 memset(&iwe, 0, sizeof(iwe));
1332 iwe.cmd = SIOCGIWRATE;
1333 current_val = current_ev + IW_EV_LCP_LEN;
1334 if (tmpRate == 0x82)
1335 iwe.u.bitrate.value = 1 * 1000000;
1336 else if (tmpRate == 0x84)
1337 iwe.u.bitrate.value = 2 * 1000000;
1338 else if (tmpRate == 0x8B)
1339 iwe.u.bitrate.value = 5.5 * 1000000;
1340 else if (tmpRate == 0x96)
1341 iwe.u.bitrate.value = 11 * 1000000;
1342 else
1343 iwe.u.bitrate.value = (tmpRate/2) * 1000000;
1344
1345 iwe.u.bitrate.disabled = 0;
27eff3bf 1346 current_val = iwe_stream_add_value(info, current_ev,
91980990
GKH
1347 current_val, end_buf, &iwe,
1348 IW_EV_PARAM_LEN);
1349
1350 if((current_val-current_ev)>IW_EV_LCP_LEN)
1351 current_ev = current_val;
1352 else
1353#if WIRELESS_EXT >= 17
1354 return -E2BIG;
1355#else
1356 break;
1357#endif
1358 }
1359
1360#ifdef IWEVGENIE
1361 //WPA IE
1362 if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
1363 {
1364 memset(&iwe, 0, sizeof(iwe));
1365 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1366 memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].WpaIE.IE[0]),
1367 pAdapter->ScanTab.BssEntry[i].WpaIE.IELen);
1368 iwe.cmd = IWEVGENIE;
1369 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].WpaIE.IELen;
27eff3bf 1370 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, custom);
91980990
GKH
1371 if (current_ev == previous_ev)
1372#if WIRELESS_EXT >= 17
1373 return -E2BIG;
1374#else
1375 break;
1376#endif
1377 }
1378
1379 //WPA2 IE
1380 if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
1381 {
1382 memset(&iwe, 0, sizeof(iwe));
1383 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1384 memcpy(custom, &(pAdapter->ScanTab.BssEntry[i].RsnIE.IE[0]),
1385 pAdapter->ScanTab.BssEntry[i].RsnIE.IELen);
1386 iwe.cmd = IWEVGENIE;
1387 iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].RsnIE.IELen;
27eff3bf 1388 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, custom);
91980990
GKH
1389 if (current_ev == previous_ev)
1390#if WIRELESS_EXT >= 17
1391 return -E2BIG;
1392#else
1393 break;
1394#endif
1395 }
1396#else
1397 //WPA IE
1398 //================================
1399 if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0)
1400 {
1401 NdisZeroMemory(&iwe, sizeof(iwe));
1402 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1403 iwe.cmd = IWEVCUSTOM;
1404 iwe.u.data.length = (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen * 2) + 7;
1405 NdisMoveMemory(custom, "wpa_ie=", 7);
1406 for (idx = 0; idx < pAdapter->ScanTab.BssEntry[i].WpaIE.IELen; idx++)
32c976bc 1407 sprintf(custom + strlen(custom), "%02x", pAdapter->ScanTab.BssEntry[i].WpaIE.IE[idx]);
91980990 1408 previous_ev = current_ev;
27eff3bf 1409 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, custom);
91980990
GKH
1410 if (current_ev == previous_ev)
1411#if WIRELESS_EXT >= 17
1412 return -E2BIG;
1413#else
1414 break;
1415#endif
1416 }
1417
1418 //WPA2 IE
1419 if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0)
1420 {
1421 NdisZeroMemory(&iwe, sizeof(iwe));
1422 memset(&custom[0], 0, MAX_CUSTOM_LEN);
1423 iwe.cmd = IWEVCUSTOM;
1424 iwe.u.data.length = (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen * 2) + 7;
1425 NdisMoveMemory(custom, "rsn_ie=", 7);
1426 for (idx = 0; idx < pAdapter->ScanTab.BssEntry[i].RsnIE.IELen; idx++)
32c976bc 1427 sprintf(custom + strlen(custom), "%02x", pAdapter->ScanTab.BssEntry[i].RsnIE.IE[idx]);
91980990 1428 previous_ev = current_ev;
27eff3bf 1429 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, custom);
91980990
GKH
1430 if (current_ev == previous_ev)
1431#if WIRELESS_EXT >= 17
1432 return -E2BIG;
1433#else
1434 break;
1435#endif
1436 }
1437#endif // IWEVGENIE //
1438 }
1439
1440 data->length = current_ev - extra;
1441 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
1442 DBGPRINT(RT_DEBUG_ERROR ,("===>rt_ioctl_giwscan. %d(%d) BSS returned, data->length = %d\n",i , pAdapter->ScanTab.BssNr, data->length));
1443 return 0;
1444}
1445#endif
1446
1447int rt_ioctl_siwessid(struct net_device *dev,
1448 struct iw_request_info *info,
1449 struct iw_point *data, char *essid)
1450{
739b7979 1451 PRTMP_ADAPTER pAdapter = dev->ml_priv;
91980990
GKH
1452
1453 //check if the interface is down
1454 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1455 {
1456 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1457 return -ENETDOWN;
1458 }
1459
1460 if (data->flags)
1461 {
1462 PCHAR pSsidString = NULL;
1463
1464 // Includes null character.
1465 if (data->length > (IW_ESSID_MAX_SIZE + 1))
1466 return -E2BIG;
1467
1468 pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
1469 if (pSsidString)
1470 {
1471 NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
1472 NdisMoveMemory(pSsidString, essid, data->length);
1473 if (Set_SSID_Proc(pAdapter, pSsidString) == FALSE)
1474 return -EINVAL;
1475 }
1476 else
1477 return -ENOMEM;
1478 }
1479 else
1480 {
1481 // ANY ssid
1482 if (Set_SSID_Proc(pAdapter, "") == FALSE)
1483 return -EINVAL;
1484 }
1485 return 0;
1486}
1487
1488int rt_ioctl_giwessid(struct net_device *dev,
1489 struct iw_request_info *info,
1490 struct iw_point *data, char *essid)
1491{
3a32ed12 1492#ifndef RT30xx
91980990
GKH
1493 PRTMP_ADAPTER pAdapter = NULL;
1494 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1495
1496 if (dev->priv_flags == INT_MAIN)
1497 {
739b7979 1498 pAdapter = dev->ml_priv;
91980990
GKH
1499 }
1500 else
1501 {
739b7979 1502 pVirtualAd = dev->ml_priv;
91980990 1503 if (pVirtualAd && pVirtualAd->RtmpDev)
739b7979 1504 pAdapter = pVirtualAd->RtmpDev->ml_priv;
91980990
GKH
1505 }
1506
1507 if (pAdapter == NULL)
1508 {
1509 /* if 1st open fail, pAd will be free;
739b7979 1510 So the net_dev->ml_priv will be NULL in 2rd open */
91980990
GKH
1511 return -ENETDOWN;
1512 }
3a32ed12
BZ
1513#endif
1514#ifdef RT30xx
1515 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1516#endif
91980990
GKH
1517
1518 data->flags = 1;
1519 if (MONITOR_ON(pAdapter))
1520 {
1521 data->length = 0;
1522 return 0;
1523 }
1524
1525 if (OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED))
1526 {
1527 DBGPRINT(RT_DEBUG_TRACE ,("MediaState is connected\n"));
1528 data->length = pAdapter->CommonCfg.SsidLen;
1529 memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
1530 }
3a32ed12
BZ
1531#ifdef RT2870
1532 // Add for RT2870
1533 else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE)
1534 {
1535 data->length = pAdapter->CommonCfg.SsidLen;
1536 memcpy(essid, pAdapter->CommonCfg.Ssid, pAdapter->CommonCfg.SsidLen);
1537 }
1538#endif // RT2870 //
91980990
GKH
1539 else
1540 {//the ANY ssid was specified
1541 data->length = 0;
1542 DBGPRINT(RT_DEBUG_TRACE ,("MediaState is not connected, ess\n"));
1543 }
1544
1545 return 0;
1546
1547}
1548
1549int rt_ioctl_siwnickn(struct net_device *dev,
1550 struct iw_request_info *info,
1551 struct iw_point *data, char *nickname)
1552{
739b7979 1553 PRTMP_ADAPTER pAdapter = dev->ml_priv;
91980990
GKH
1554
1555 //check if the interface is down
1556 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1557 {
1558 DBGPRINT(RT_DEBUG_TRACE ,("INFO::Network is down!\n"));
1559 return -ENETDOWN;
1560 }
1561
1562 if (data->length > IW_ESSID_MAX_SIZE)
1563 return -EINVAL;
1564
1565 memset(pAdapter->nickname, 0, IW_ESSID_MAX_SIZE + 1);
1566 memcpy(pAdapter->nickname, nickname, data->length);
1567
1568
1569 return 0;
1570}
1571
1572int rt_ioctl_giwnickn(struct net_device *dev,
1573 struct iw_request_info *info,
1574 struct iw_point *data, char *nickname)
1575{
3a32ed12 1576#ifndef RT30xx
91980990
GKH
1577 PRTMP_ADAPTER pAdapter = NULL;
1578 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1579
1580 if (dev->priv_flags == INT_MAIN)
1581 {
739b7979 1582 pAdapter = dev->ml_priv;
91980990
GKH
1583 }
1584 else
1585 {
739b7979 1586 pVirtualAd = dev->ml_priv;
91980990 1587 if (pVirtualAd && pVirtualAd->RtmpDev)
739b7979 1588 pAdapter = pVirtualAd->RtmpDev->ml_priv;
91980990
GKH
1589 }
1590
1591 if (pAdapter == NULL)
1592 {
1593 /* if 1st open fail, pAd will be free;
739b7979 1594 So the net_dev->ml_priv will be NULL in 2rd open */
91980990
GKH
1595 return -ENETDOWN;
1596 }
3a32ed12
BZ
1597#endif
1598#ifdef RT30xx
1599 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1600#endif
91980990
GKH
1601
1602 if (data->length > strlen(pAdapter->nickname) + 1)
1603 data->length = strlen(pAdapter->nickname) + 1;
1604 if (data->length > 0) {
1605 memcpy(nickname, pAdapter->nickname, data->length-1);
1606 nickname[data->length-1] = '\0';
1607 }
1608 return 0;
1609}
1610
1611int rt_ioctl_siwrts(struct net_device *dev,
1612 struct iw_request_info *info,
1613 struct iw_param *rts, char *extra)
1614{
739b7979 1615 PRTMP_ADAPTER pAdapter = dev->ml_priv;
91980990
GKH
1616 u16 val;
1617
1618 //check if the interface is down
1619 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1620 {
1621 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1622 return -ENETDOWN;
1623 }
1624
1625 if (rts->disabled)
1626 val = MAX_RTS_THRESHOLD;
1627 else if (rts->value < 0 || rts->value > MAX_RTS_THRESHOLD)
1628 return -EINVAL;
1629 else if (rts->value == 0)
1630 val = MAX_RTS_THRESHOLD;
1631 else
1632 val = rts->value;
1633
1634 if (val != pAdapter->CommonCfg.RtsThreshold)
1635 pAdapter->CommonCfg.RtsThreshold = val;
1636
1637 return 0;
1638}
1639
1640int rt_ioctl_giwrts(struct net_device *dev,
1641 struct iw_request_info *info,
1642 struct iw_param *rts, char *extra)
1643{
3a32ed12 1644#ifndef RT30xx
91980990
GKH
1645 PRTMP_ADAPTER pAdapter = NULL;
1646 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1647
1648 if (dev->priv_flags == INT_MAIN)
1649 {
739b7979 1650 pAdapter = dev->ml_priv;
91980990
GKH
1651 }
1652 else
1653 {
739b7979 1654 pVirtualAd = dev->ml_priv;
91980990 1655 if (pVirtualAd && pVirtualAd->RtmpDev)
739b7979 1656 pAdapter = pVirtualAd->RtmpDev->ml_priv;
91980990
GKH
1657 }
1658
1659 if (pAdapter == NULL)
1660 {
1661 /* if 1st open fail, pAd will be free;
739b7979 1662 So the net_dev->ml_priv will be NULL in 2rd open */
91980990
GKH
1663 return -ENETDOWN;
1664 }
3a32ed12
BZ
1665#endif
1666#ifdef RT30xx
1667 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1668#endif
91980990
GKH
1669
1670 //check if the interface is down
1671 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1672 {
1673 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1674 return -ENETDOWN;
1675 }
1676
1677 rts->value = pAdapter->CommonCfg.RtsThreshold;
1678 rts->disabled = (rts->value == MAX_RTS_THRESHOLD);
1679 rts->fixed = 1;
1680
1681 return 0;
1682}
1683
1684int rt_ioctl_siwfrag(struct net_device *dev,
1685 struct iw_request_info *info,
1686 struct iw_param *frag, char *extra)
1687{
739b7979 1688 PRTMP_ADAPTER pAdapter = dev->ml_priv;
91980990
GKH
1689 u16 val;
1690
1691 //check if the interface is down
1692 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1693 {
1694 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1695 return -ENETDOWN;
1696 }
1697
1698 if (frag->disabled)
1699 val = MAX_FRAG_THRESHOLD;
1700 else if (frag->value >= MIN_FRAG_THRESHOLD || frag->value <= MAX_FRAG_THRESHOLD)
1701 val = __cpu_to_le16(frag->value & ~0x1); /* even numbers only */
1702 else if (frag->value == 0)
1703 val = MAX_FRAG_THRESHOLD;
1704 else
1705 return -EINVAL;
1706
1707 pAdapter->CommonCfg.FragmentThreshold = val;
1708 return 0;
1709}
1710
1711int rt_ioctl_giwfrag(struct net_device *dev,
1712 struct iw_request_info *info,
1713 struct iw_param *frag, char *extra)
1714{
3a32ed12 1715#ifndef RT30xx
91980990
GKH
1716 PRTMP_ADAPTER pAdapter = NULL;
1717 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1718
1719 if (dev->priv_flags == INT_MAIN)
1720 {
739b7979 1721 pAdapter = dev->ml_priv;
91980990
GKH
1722 }
1723 else
1724 {
739b7979 1725 pVirtualAd = dev->ml_priv;
91980990 1726 if (pVirtualAd && pVirtualAd->RtmpDev)
739b7979 1727 pAdapter = pVirtualAd->RtmpDev->ml_priv;
91980990
GKH
1728 }
1729
1730 if (pAdapter == NULL)
1731 {
1732 /* if 1st open fail, pAd will be free;
739b7979 1733 So the net_dev->ml_priv will be NULL in 2rd open */
91980990
GKH
1734 return -ENETDOWN;
1735 }
3a32ed12
BZ
1736#endif
1737#ifdef RT30xx
1738 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1739#endif
91980990
GKH
1740
1741 //check if the interface is down
1742 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1743 {
1744 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1745 return -ENETDOWN;
1746 }
1747
1748 frag->value = pAdapter->CommonCfg.FragmentThreshold;
1749 frag->disabled = (frag->value == MAX_FRAG_THRESHOLD);
1750 frag->fixed = 1;
1751
1752 return 0;
1753}
1754
1755#define MAX_WEP_KEY_SIZE 13
1756#define MIN_WEP_KEY_SIZE 5
1757int rt_ioctl_siwencode(struct net_device *dev,
1758 struct iw_request_info *info,
1759 struct iw_point *erq, char *extra)
1760{
739b7979 1761 PRTMP_ADAPTER pAdapter = dev->ml_priv;
91980990
GKH
1762
1763 //check if the interface is down
1764 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1765 {
1766 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1767 return -ENETDOWN;
1768 }
1769
1770 if ((erq->length == 0) &&
1771 (erq->flags & IW_ENCODE_DISABLED))
1772 {
1773 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
1774 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
1775 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
1776 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
1777 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1778 goto done;
1779 }
3a32ed12 1780#ifndef RT30xx
91980990
GKH
1781 else if ((erq->length == 0) &&
1782 (erq->flags & IW_ENCODE_RESTRICTED || erq->flags & IW_ENCODE_OPEN))
3a32ed12
BZ
1783#endif
1784#ifdef RT30xx
1785 else if (erq->flags & IW_ENCODE_RESTRICTED || erq->flags & IW_ENCODE_OPEN)
1786#endif
91980990
GKH
1787 {
1788 STA_PORT_SECURED(pAdapter);
1789 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
1790 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
1791 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
1792 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
1793 if (erq->flags & IW_ENCODE_RESTRICTED)
1794 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
1795 else
1796 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
3a32ed12 1797#ifndef RT30xx
91980990 1798 goto done;
3a32ed12 1799#endif
91980990
GKH
1800 }
1801
1802 if (erq->length > 0)
1803 {
1804 int keyIdx = (erq->flags & IW_ENCODE_INDEX) - 1;
1805 /* Check the size of the key */
1806 if (erq->length > MAX_WEP_KEY_SIZE) {
1807 return -EINVAL;
1808 }
1809 /* Check key index */
1810 if ((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
1811 {
1812 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::Wrong keyIdx=%d! Using default key instead (%d)\n",
1813 keyIdx, pAdapter->StaCfg.DefaultKeyId));
1814
1815 //Using default key
1816 keyIdx = pAdapter->StaCfg.DefaultKeyId;
1817 }
3a32ed12
BZ
1818#ifdef RT30xx
1819 else
1820 {
1821 pAdapter->StaCfg.DefaultKeyId=keyIdx;
1822 }
1823#endif
91980990
GKH
1824
1825 NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
1826
1827 if (erq->length == MAX_WEP_KEY_SIZE)
1828 {
1829 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
1830 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
1831 }
1832 else if (erq->length == MIN_WEP_KEY_SIZE)
1833 {
1834 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
1835 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
1836 }
1837 else
1838 /* Disable the key */
1839 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
1840
1841 /* Check if the key is not marked as invalid */
1842 if(!(erq->flags & IW_ENCODE_NOKEY)) {
1843 /* Copy the key in the driver */
1844 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, extra, erq->length);
1845 }
1846 }
1847 else
1848 {
1849 /* Do we want to just set the transmit key index ? */
1850 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
1851 if ((index >= 0) && (index < 4))
1852 {
1853 pAdapter->StaCfg.DefaultKeyId = index;
1854 }
1855 else
1856 /* Don't complain if only change the mode */
7034ca4d 1857 if (!(erq->flags & IW_ENCODE_MODE)) {
91980990
GKH
1858 return -EINVAL;
1859 }
1860 }
1861
1862done:
1863 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::erq->flags=%x\n",erq->flags));
1864 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::AuthMode=%x\n",pAdapter->StaCfg.AuthMode));
1865 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::DefaultKeyId=%x, KeyLen = %d\n",pAdapter->StaCfg.DefaultKeyId , pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen));
1866 DBGPRINT(RT_DEBUG_TRACE ,("==>rt_ioctl_siwencode::WepStatus=%x\n",pAdapter->StaCfg.WepStatus));
1867 return 0;
1868}
1869
1870int
1871rt_ioctl_giwencode(struct net_device *dev,
1872 struct iw_request_info *info,
1873 struct iw_point *erq, char *key)
1874{
3a32ed12
BZ
1875#ifdef RT30xx
1876 PRTMP_ADAPTER pAdapter = dev->ml_priv;
1877#endif
91980990 1878 int kid;
3a32ed12 1879#ifndef RT30xx
91980990
GKH
1880 PRTMP_ADAPTER pAdapter = NULL;
1881 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1882
1883 if (dev->priv_flags == INT_MAIN)
1884 {
739b7979 1885 pAdapter = dev->ml_priv;
91980990
GKH
1886 }
1887 else
1888 {
739b7979 1889 pVirtualAd = dev->ml_priv;
91980990 1890 if (pVirtualAd && pVirtualAd->RtmpDev)
739b7979 1891 pAdapter = pVirtualAd->RtmpDev->ml_priv;
91980990
GKH
1892 }
1893
1894 if (pAdapter == NULL)
1895 {
1896 /* if 1st open fail, pAd will be free;
739b7979 1897 So the net_dev->ml_priv will be NULL in 2rd open */
91980990
GKH
1898 return -ENETDOWN;
1899 }
3a32ed12 1900#endif
91980990
GKH
1901
1902 //check if the interface is down
1903 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1904 {
1905 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1906 return -ENETDOWN;
1907 }
1908
1909 kid = erq->flags & IW_ENCODE_INDEX;
1910 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_giwencode %d\n", erq->flags & IW_ENCODE_INDEX));
1911
1912 if (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled)
1913 {
1914 erq->length = 0;
1915 erq->flags = IW_ENCODE_DISABLED;
1916 }
1917 else if ((kid > 0) && (kid <=4))
1918 {
1919 // copy wep key
1920 erq->flags = kid ; /* NB: base 1 */
1921 if (erq->length > pAdapter->SharedKey[BSS0][kid-1].KeyLen)
1922 erq->length = pAdapter->SharedKey[BSS0][kid-1].KeyLen;
1923 memcpy(key, pAdapter->SharedKey[BSS0][kid-1].Key, erq->length);
1924 //if ((kid == pAdapter->PortCfg.DefaultKeyId))
1925 //erq->flags |= IW_ENCODE_ENABLED; /* XXX */
1926 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1927 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1928 else
1929 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1930
1931 }
1932 else if (kid == 0)
1933 {
1934 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1935 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1936 else
1937 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1938 erq->length = pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].KeyLen;
1939 memcpy(key, pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId].Key, erq->length);
1940 // copy default key ID
1941 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared)
1942 erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */
1943 else
1944 erq->flags |= IW_ENCODE_OPEN; /* XXX */
1945 erq->flags = pAdapter->StaCfg.DefaultKeyId + 1; /* NB: base 1 */
1946 erq->flags |= IW_ENCODE_ENABLED; /* XXX */
1947 }
1948
1949 return 0;
1950
1951}
1952
1953static int
1954rt_ioctl_setparam(struct net_device *dev, struct iw_request_info *info,
1955 void *w, char *extra)
1956{
1957 VIRTUAL_ADAPTER *pVirtualAd = NULL;
1958 PRTMP_ADAPTER pAdapter;
1959 POS_COOKIE pObj;
1960 char *this_char = extra;
1961 char *value;
1962 int Status=0;
1963
1964 if (dev->priv_flags == INT_MAIN)
1965 {
739b7979 1966 pAdapter = dev->ml_priv;
91980990
GKH
1967 }
1968 else
1969 {
739b7979
GKH
1970 pVirtualAd = dev->ml_priv;
1971 pAdapter = pVirtualAd->RtmpDev->ml_priv;
91980990
GKH
1972 }
1973 pObj = (POS_COOKIE) pAdapter->OS_Cookie;
1974
1975 if (pAdapter == NULL)
1976 {
1977 /* if 1st open fail, pAd will be free;
739b7979 1978 So the net_dev->ml_priv will be NULL in 2rd open */
91980990
GKH
1979 return -ENETDOWN;
1980 }
1981
1982 {
1983 pObj->ioctl_if_type = INT_MAIN;
1984 pObj->ioctl_if = MAIN_MBSSID;
1985 }
1986
1987 //check if the interface is down
1988 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
1989 {
1990 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
1991 return -ENETDOWN;
1992 }
1993
1994 if (!*this_char)
1995 return -EINVAL;
1996
1997 if ((value = rtstrchr(this_char, '=')) != NULL)
1998 *value++ = 0;
1999
2000 if (!value)
2001 return -EINVAL;
2002
2003 // reject setting nothing besides ANY ssid(ssidLen=0)
2004 if (!*value && (strcmp(this_char, "SSID") != 0))
2005 return -EINVAL;
2006
2007 for (PRTMP_PRIVATE_SET_PROC = RTMP_PRIVATE_SUPPORT_PROC; PRTMP_PRIVATE_SET_PROC->name; PRTMP_PRIVATE_SET_PROC++)
2008 {
2009 if (strcmp(this_char, PRTMP_PRIVATE_SET_PROC->name) == 0)
2010 {
2011 if(!PRTMP_PRIVATE_SET_PROC->set_proc(pAdapter, value))
2012 { //FALSE:Set private failed then return Invalid argument
2013 Status = -EINVAL;
2014 }
2015 break; //Exit for loop.
2016 }
2017 }
2018
2019 if(PRTMP_PRIVATE_SET_PROC->name == NULL)
2020 { //Not found argument
2021 Status = -EINVAL;
2022 DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_setparam:: (iwpriv) Not Support Set Command [%s=%s]\n", this_char, value));
2023 }
2024
2025 return Status;
2026}
2027
2028
2029static int
2030rt_private_get_statistics(struct net_device *dev, struct iw_request_info *info,
2031 struct iw_point *wrq, char *extra)
2032{
2033 INT Status = 0;
739b7979 2034 PRTMP_ADAPTER pAd = dev->ml_priv;
91980990
GKH
2035
2036 if (extra == NULL)
2037 {
2038 wrq->length = 0;
2039 return -EIO;
2040 }
2041
2042 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2043 sprintf(extra, "\n\n");
2044
91980990
GKH
2045 {
2046 sprintf(extra+strlen(extra), "Tx success = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart);
2047 sprintf(extra+strlen(extra), "Tx success without retry = %ld\n", (ULONG)pAd->WlanCounters.TransmittedFragmentCount.QuadPart - (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
2048 }
2049 sprintf(extra+strlen(extra), "Tx success after retry = %ld\n", (ULONG)pAd->WlanCounters.RetryCount.QuadPart);
2050 sprintf(extra+strlen(extra), "Tx fail to Rcv ACK after retry = %ld\n", (ULONG)pAd->WlanCounters.FailedCount.QuadPart);
2051 sprintf(extra+strlen(extra), "RTS Success Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSSuccessCount.QuadPart);
2052 sprintf(extra+strlen(extra), "RTS Fail Rcv CTS = %ld\n", (ULONG)pAd->WlanCounters.RTSFailureCount.QuadPart);
2053
2054 sprintf(extra+strlen(extra), "Rx success = %ld\n", (ULONG)pAd->WlanCounters.ReceivedFragmentCount.QuadPart);
2055 sprintf(extra+strlen(extra), "Rx with CRC = %ld\n", (ULONG)pAd->WlanCounters.FCSErrorCount.QuadPart);
2056 sprintf(extra+strlen(extra), "Rx drop due to out of resource = %ld\n", (ULONG)pAd->Counters8023.RxNoBuffer);
2057 sprintf(extra+strlen(extra), "Rx duplicate frame = %ld\n", (ULONG)pAd->WlanCounters.FrameDuplicateCount.QuadPart);
2058
2059 sprintf(extra+strlen(extra), "False CCA (one second) = %ld\n", (ULONG)pAd->RalinkCounters.OneSecFalseCCACnt);
91980990
GKH
2060 {
2061 sprintf(extra+strlen(extra), "RSSI-A = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi0 - pAd->BbpRssiToDbmDelta));
2062 sprintf(extra+strlen(extra), "RSSI-B (if available) = %ld\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi1 - pAd->BbpRssiToDbmDelta));
2063 sprintf(extra+strlen(extra), "RSSI-C (if available) = %ld\n\n", (LONG)(pAd->StaCfg.RssiSample.LastRssi2 - pAd->BbpRssiToDbmDelta));
2064 }
91980990 2065 sprintf(extra+strlen(extra), "WpaSupplicantUP = %d\n\n", pAd->StaCfg.WpaSupplicantUP);
91980990
GKH
2066
2067 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2068 DBGPRINT(RT_DEBUG_TRACE, ("<== rt_private_get_statistics, wrq->length = %d\n", wrq->length));
2069
2070 return Status;
2071}
2072
91980990
GKH
2073void getBaInfo(
2074 IN PRTMP_ADAPTER pAd,
2075 IN PUCHAR pOutBuf)
2076{
2077 INT i, j;
2078 BA_ORI_ENTRY *pOriBAEntry;
2079 BA_REC_ENTRY *pRecBAEntry;
2080
2081 for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
2082 {
2083 PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
2084 if (((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
2085 || (pEntry->ValidAsWDS) || (pEntry->ValidAsMesh))
2086 {
32c976bc 2087 sprintf(pOutBuf + strlen(pOutBuf), "\n%02X:%02X:%02X:%02X:%02X:%02X (Aid = %d) (AP) -\n",
91980990
GKH
2088 pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
2089 pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5], pEntry->Aid);
2090
2091 sprintf(pOutBuf, "%s[Recipient]\n", pOutBuf);
2092 for (j=0; j < NUM_OF_TID; j++)
2093 {
2094 if (pEntry->BARecWcidArray[j] != 0)
2095 {
2096 pRecBAEntry =&pAd->BATable.BARecEntry[pEntry->BARecWcidArray[j]];
32c976bc 2097 sprintf(pOutBuf + strlen(pOutBuf), "TID=%d, BAWinSize=%d, LastIndSeq=%d, ReorderingPkts=%d\n", j, pRecBAEntry->BAWinSize, pRecBAEntry->LastIndSeq, pRecBAEntry->list.qlen);
91980990
GKH
2098 }
2099 }
2100 sprintf(pOutBuf, "%s\n", pOutBuf);
2101
2102 sprintf(pOutBuf, "%s[Originator]\n", pOutBuf);
2103 for (j=0; j < NUM_OF_TID; j++)
2104 {
2105 if (pEntry->BAOriWcidArray[j] != 0)
2106 {
2107 pOriBAEntry =&pAd->BATable.BAOriEntry[pEntry->BAOriWcidArray[j]];
32c976bc 2108 sprintf(pOutBuf + strlen(pOutBuf), "TID=%d, BAWinSize=%d, StartSeq=%d, CurTxSeq=%d\n", j, pOriBAEntry->BAWinSize, pOriBAEntry->Sequence, pEntry->TxSeq[j]);
91980990
GKH
2109 }
2110 }
2111 sprintf(pOutBuf, "%s\n\n", pOutBuf);
2112 }
2113 if (strlen(pOutBuf) > (IW_PRIV_SIZE_MASK - 30))
2114 break;
2115 }
2116
2117 return;
2118}
91980990
GKH
2119
2120static int
2121rt_private_show(struct net_device *dev, struct iw_request_info *info,
2122 struct iw_point *wrq, char *extra)
2123{
2124 INT Status = 0;
2125 VIRTUAL_ADAPTER *pVirtualAd = NULL;
2126 PRTMP_ADAPTER pAd;
2127 POS_COOKIE pObj;
2128 u32 subcmd = wrq->flags;
2129
2130 if (dev->priv_flags == INT_MAIN)
739b7979 2131 pAd = dev->ml_priv;
91980990
GKH
2132 else
2133 {
739b7979
GKH
2134 pVirtualAd = dev->ml_priv;
2135 pAd = pVirtualAd->RtmpDev->ml_priv;
91980990
GKH
2136 }
2137 pObj = (POS_COOKIE) pAd->OS_Cookie;
2138
2139 if (pAd == NULL)
2140 {
2141 /* if 1st open fail, pAd will be free;
739b7979 2142 So the net_dev->ml_priv will be NULL in 2rd open */
91980990
GKH
2143 return -ENETDOWN;
2144 }
2145
2146 if (extra == NULL)
2147 {
2148 wrq->length = 0;
2149 return -EIO;
2150 }
2151 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2152
2153 {
2154 pObj->ioctl_if_type = INT_MAIN;
2155 pObj->ioctl_if = MAIN_MBSSID;
2156 }
2157
2158 switch(subcmd)
2159 {
2160
2161 case SHOW_CONN_STATUS:
2162 if (MONITOR_ON(pAd))
2163 {
91980990
GKH
2164 if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
2165 pAd->CommonCfg.RegTransmitSetting.field.BW)
2166 sprintf(extra, "Monitor Mode(CentralChannel %d)\n", pAd->CommonCfg.CentralChannel);
2167 else
91980990
GKH
2168 sprintf(extra, "Monitor Mode(Channel %d)\n", pAd->CommonCfg.Channel);
2169 }
2170 else
2171 {
2172 if (pAd->IndicateMediaState == NdisMediaStateConnected)
2173 {
2174 if (INFRA_ON(pAd))
2175 {
2176 sprintf(extra, "Connected(AP: %s[%02X:%02X:%02X:%02X:%02X:%02X])\n",
2177 pAd->CommonCfg.Ssid,
2178 pAd->CommonCfg.Bssid[0],
2179 pAd->CommonCfg.Bssid[1],
2180 pAd->CommonCfg.Bssid[2],
2181 pAd->CommonCfg.Bssid[3],
2182 pAd->CommonCfg.Bssid[4],
2183 pAd->CommonCfg.Bssid[5]);
2184 DBGPRINT(RT_DEBUG_TRACE ,("Ssid=%s ,Ssidlen = %d\n",pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen));
2185 }
2186 else if (ADHOC_ON(pAd))
2187 sprintf(extra, "Connected\n");
2188 }
2189 else
2190 {
2191 sprintf(extra, "Disconnected\n");
2192 DBGPRINT(RT_DEBUG_TRACE ,("ConnStatus is not connected\n"));
2193 }
2194 }
2195 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2196 break;
2197 case SHOW_DRVIER_VERION:
2198 sprintf(extra, "Driver version-%s, %s %s\n", STA_DRIVER_VERSION, __DATE__, __TIME__ );
2199 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2200 break;
91980990
GKH
2201 case SHOW_BA_INFO:
2202 getBaInfo(pAd, extra);
2203 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2204 break;
91980990
GKH
2205 case SHOW_DESC_INFO:
2206 {
2207 Show_DescInfo_Proc(pAd, NULL);
2208 wrq->length = 0; // 1: size of '\0'
2209 }
2210 break;
2211 case RAIO_OFF:
2212 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
2213 {
2214 sprintf(extra, "Scanning\n");
2215 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2216 break;
2217 }
2218 pAd->StaCfg.bSwRadio = FALSE;
2219 if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
2220 {
2221 pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
2222 if (pAd->StaCfg.bRadio == FALSE)
2223 {
2224 MlmeRadioOff(pAd);
2225 // Update extra information
2226 pAd->ExtraInfo = SW_RADIO_OFF;
2227 }
2228 }
2229 sprintf(extra, "Radio Off\n");
2230 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2231 break;
2232 case RAIO_ON:
3a32ed12
BZ
2233#ifdef RT2870
2234 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
2235 {
2236 sprintf(extra, "Scanning\n");
2237 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2238 break;
2239 }
2240#endif
91980990
GKH
2241 pAd->StaCfg.bSwRadio = TRUE;
2242 //if (pAd->StaCfg.bRadio != (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio))
2243 {
2244 pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio);
2245 if (pAd->StaCfg.bRadio == TRUE)
2246 {
2247 MlmeRadioOn(pAd);
2248 // Update extra information
2249 pAd->ExtraInfo = EXTRA_INFO_CLEAR;
2250 }
2251 }
2252 sprintf(extra, "Radio On\n");
2253 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2254 break;
2255
91980990
GKH
2256 case SHOW_CFG_VALUE:
2257 {
2258 Status = RTMPShowCfgValue(pAd, wrq->pointer, extra);
2259 if (Status == 0)
2260 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2261 }
2262 break;
3a32ed12
BZ
2263#if !defined(RT2860) && !defined(RT30xx)
2264 case SHOW_ADHOC_ENTRY_INFO:
2265 Show_Adhoc_MacTable_Proc(pAd, extra);
2266 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2267 break;
2268#endif
91980990 2269 default:
d599edca 2270 DBGPRINT(RT_DEBUG_TRACE, ("%s - unknow subcmd = %d\n", __func__, subcmd));
91980990
GKH
2271 break;
2272 }
2273
2274 return Status;
2275}
2276
2277#ifdef SIOCSIWMLME
2278int rt_ioctl_siwmlme(struct net_device *dev,
2279 struct iw_request_info *info,
2280 union iwreq_data *wrqu,
2281 char *extra)
2282{
739b7979 2283 PRTMP_ADAPTER pAd = dev->ml_priv;
91980990
GKH
2284 struct iw_mlme *pMlme = (struct iw_mlme *)wrqu->data.pointer;
2285 MLME_QUEUE_ELEM MsgElem;
2286 MLME_DISASSOC_REQ_STRUCT DisAssocReq;
2287 MLME_DEAUTH_REQ_STRUCT DeAuthReq;
2288
d599edca 2289 DBGPRINT(RT_DEBUG_TRACE, ("====> %s\n", __func__));
91980990
GKH
2290
2291 if (pMlme == NULL)
2292 return -EINVAL;
2293
2294 switch(pMlme->cmd)
2295 {
2296#ifdef IW_MLME_DEAUTH
2297 case IW_MLME_DEAUTH:
d599edca 2298 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DEAUTH\n", __func__));
91980990
GKH
2299 COPY_MAC_ADDR(DeAuthReq.Addr, pAd->CommonCfg.Bssid);
2300 DeAuthReq.Reason = pMlme->reason_code;
2301 MsgElem.MsgLen = sizeof(MLME_DEAUTH_REQ_STRUCT);
2302 NdisMoveMemory(MsgElem.Msg, &DeAuthReq, sizeof(MLME_DEAUTH_REQ_STRUCT));
2303 MlmeDeauthReqAction(pAd, &MsgElem);
2304 if (INFRA_ON(pAd))
2305 {
2306 LinkDown(pAd, FALSE);
2307 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
2308 }
2309 break;
2310#endif // IW_MLME_DEAUTH //
2311#ifdef IW_MLME_DISASSOC
2312 case IW_MLME_DISASSOC:
d599edca 2313 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - IW_MLME_DISASSOC\n", __func__));
91980990
GKH
2314 COPY_MAC_ADDR(DisAssocReq.Addr, pAd->CommonCfg.Bssid);
2315 DisAssocReq.Reason = pMlme->reason_code;
2316
2317 MsgElem.Machine = ASSOC_STATE_MACHINE;
2318 MsgElem.MsgType = MT2_MLME_DISASSOC_REQ;
2319 MsgElem.MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
2320 NdisMoveMemory(MsgElem.Msg, &DisAssocReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
2321
2322 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
2323 MlmeDisassocReqAction(pAd, &MsgElem);
2324 break;
2325#endif // IW_MLME_DISASSOC //
2326 default:
d599edca 2327 DBGPRINT(RT_DEBUG_TRACE, ("====> %s - Unknow Command\n", __func__));
91980990
GKH
2328 break;
2329 }
2330
2331 return 0;
2332}
2333#endif // SIOCSIWMLME //
2334
2335#if WIRELESS_EXT > 17
2336int rt_ioctl_siwauth(struct net_device *dev,
2337 struct iw_request_info *info,
2338 union iwreq_data *wrqu, char *extra)
2339{
739b7979 2340 PRTMP_ADAPTER pAdapter = dev->ml_priv;
91980990
GKH
2341 struct iw_param *param = &wrqu->param;
2342
2343 //check if the interface is down
2344 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2345 {
2346 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2347 return -ENETDOWN;
2348 }
2349 switch (param->flags & IW_AUTH_INDEX) {
2350 case IW_AUTH_WPA_VERSION:
2351 if (param->value == IW_AUTH_WPA_VERSION_WPA)
2352 {
2353 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
2354 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
2355 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
2356 }
2357 else if (param->value == IW_AUTH_WPA_VERSION_WPA2)
2358 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
2359
d599edca 2360 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __func__, param->value));
91980990
GKH
2361 break;
2362 case IW_AUTH_CIPHER_PAIRWISE:
2363 if (param->value == IW_AUTH_CIPHER_NONE)
2364 {
2365 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
2366 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2367 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
2368 }
2369 else if (param->value == IW_AUTH_CIPHER_WEP40 ||
2370 param->value == IW_AUTH_CIPHER_WEP104)
2371 {
2372 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
2373 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2374 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
91980990 2375 pAdapter->StaCfg.IEEE8021X = FALSE;
91980990
GKH
2376 }
2377 else if (param->value == IW_AUTH_CIPHER_TKIP)
2378 {
2379 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
2380 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2381 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
2382 }
2383 else if (param->value == IW_AUTH_CIPHER_CCMP)
2384 {
2385 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
2386 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
2387 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
2388 }
d599edca 2389 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_PAIRWISE - param->value = %d!\n", __func__, param->value));
91980990
GKH
2390 break;
2391 case IW_AUTH_CIPHER_GROUP:
2392 if (param->value == IW_AUTH_CIPHER_NONE)
2393 {
2394 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
2395 }
2396 else if (param->value == IW_AUTH_CIPHER_WEP40 ||
2397 param->value == IW_AUTH_CIPHER_WEP104)
2398 {
2399 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
2400 }
2401 else if (param->value == IW_AUTH_CIPHER_TKIP)
2402 {
2403 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
2404 }
2405 else if (param->value == IW_AUTH_CIPHER_CCMP)
2406 {
2407 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
2408 }
d599edca 2409 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_CIPHER_GROUP - param->value = %d!\n", __func__, param->value));
91980990
GKH
2410 break;
2411 case IW_AUTH_KEY_MGMT:
2412 if (param->value == IW_AUTH_KEY_MGMT_802_1X)
2413 {
2414 if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)
2415 {
2416 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
91980990 2417 pAdapter->StaCfg.IEEE8021X = FALSE;
91980990
GKH
2418 }
2419 else if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
2420 {
2421 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
91980990 2422 pAdapter->StaCfg.IEEE8021X = FALSE;
91980990 2423 }
91980990
GKH
2424 else
2425 // WEP 1x
2426 pAdapter->StaCfg.IEEE8021X = TRUE;
91980990
GKH
2427 }
2428 else if (param->value == 0)
2429 {
2430 STA_PORT_SECURED(pAdapter);
2431 }
d599edca 2432 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_KEY_MGMT - param->value = %d!\n", __func__, param->value));
91980990
GKH
2433 break;
2434 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
2435 break;
2436 case IW_AUTH_PRIVACY_INVOKED:
d599edca 2437 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_PRIVACY_INVOKED - param->value = %d!\n", __func__, param->value));
91980990
GKH
2438 break;
2439 case IW_AUTH_DROP_UNENCRYPTED:
2440 if (param->value != 0)
2441 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
2442 else
2443 {
2444 STA_PORT_SECURED(pAdapter);
2445 }
d599edca 2446 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", __func__, param->value));
91980990
GKH
2447 break;
2448 case IW_AUTH_80211_AUTH_ALG:
2449 if (param->value & IW_AUTH_ALG_SHARED_KEY)
2450 {
2451 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
2452 }
2453 else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
2454 {
2455 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
2456 }
2457 else
2458 return -EINVAL;
d599edca 2459 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_80211_AUTH_ALG - param->value = %d!\n", __func__, param->value));
91980990
GKH
2460 break;
2461 case IW_AUTH_WPA_ENABLED:
d599edca 2462 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_AUTH_WPA_ENABLED - Driver supports WPA!(param->value = %d)\n", __func__, param->value));
91980990
GKH
2463 break;
2464 default:
2465 return -EOPNOTSUPP;
2466}
2467
2468 return 0;
2469}
2470
2471int rt_ioctl_giwauth(struct net_device *dev,
2472 struct iw_request_info *info,
2473 union iwreq_data *wrqu, char *extra)
2474{
739b7979 2475 PRTMP_ADAPTER pAdapter = dev->ml_priv;
91980990
GKH
2476 struct iw_param *param = &wrqu->param;
2477
2478 //check if the interface is down
2479 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2480 {
2481 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2482 return -ENETDOWN;
2483 }
2484
2485 switch (param->flags & IW_AUTH_INDEX) {
2486 case IW_AUTH_DROP_UNENCRYPTED:
2487 param->value = (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled) ? 0 : 1;
2488 break;
2489
2490 case IW_AUTH_80211_AUTH_ALG:
2491 param->value = (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared) ? IW_AUTH_ALG_SHARED_KEY : IW_AUTH_ALG_OPEN_SYSTEM;
2492 break;
2493
2494 case IW_AUTH_WPA_ENABLED:
2495 param->value = (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) ? 1 : 0;
2496 break;
2497
2498 default:
2499 return -EOPNOTSUPP;
2500 }
2501 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_giwauth::param->value = %d!\n", param->value));
2502 return 0;
2503}
2504
2505void fnSetCipherKey(
2506 IN PRTMP_ADAPTER pAdapter,
2507 IN INT keyIdx,
2508 IN UCHAR CipherAlg,
2509 IN BOOLEAN bGTK,
2510 IN struct iw_encode_ext *ext)
2511{
3a32ed12 2512#ifdef RT2860
ed291e80
AM
2513 RTMP_CLEAR_PSFLAG(pAdapter, fRTMP_PS_CAN_GO_SLEEP);
2514 if (RTMP_TEST_PSFLAG(pAdapter, fRTMP_PS_SET_PCI_CLK_OFF_COMMAND))
2515 {
2516 if (pAdapter->StaCfg.bRadio == FALSE)
2517 {
2518 RTMP_SET_PSFLAG(pAdapter, fRTMP_PS_CAN_GO_SLEEP);
f72c4bf5 2519 return;
ed291e80
AM
2520 }
2521 DBGPRINT(RT_DEBUG_TRACE,("RTMPWPAAddKeyProc1==>\n"));
2522 RTMPPCIeLinkCtrlValueRestore(pAdapter, RESTORE_HALT);
2523 RTMPusecDelay(6000);
2524 pAdapter->bPCIclkOff = FALSE;
2525 }
3a32ed12 2526#endif
91980990
GKH
2527 NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
2528 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = LEN_TKIP_EK;
2529 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, LEN_TKIP_EK);
2530 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].TxMic, ext->key + LEN_TKIP_EK, LEN_TKIP_TXMICK);
2531 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].RxMic, ext->key + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);
2532 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CipherAlg;
2533
2534 // Update group key information to ASIC Shared Key Table
2535 AsicAddSharedKeyEntry(pAdapter,
2536 BSS0,
2537 keyIdx,
2538 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2539 pAdapter->SharedKey[BSS0][keyIdx].Key,
2540 pAdapter->SharedKey[BSS0][keyIdx].TxMic,
2541 pAdapter->SharedKey[BSS0][keyIdx].RxMic);
2542
2543 if (bGTK)
2544 // Update ASIC WCID attribute table and IVEIV table
2545 RTMPAddWcidAttributeEntry(pAdapter,
2546 BSS0,
2547 keyIdx,
2548 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2549 NULL);
2550 else
2551 // Update ASIC WCID attribute table and IVEIV table
2552 RTMPAddWcidAttributeEntry(pAdapter,
2553 BSS0,
2554 keyIdx,
2555 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg,
2556 &pAdapter->MacTab.Content[BSSID_WCID]);
3a32ed12 2557#ifdef RT2860
ed291e80 2558 RTMP_SET_PSFLAG(pAdapter, fRTMP_PS_CAN_GO_SLEEP);
3a32ed12 2559#endif
91980990
GKH
2560}
2561
2562int rt_ioctl_siwencodeext(struct net_device *dev,
2563 struct iw_request_info *info,
2564 union iwreq_data *wrqu,
2565 char *extra)
2566 {
739b7979 2567 PRTMP_ADAPTER pAdapter = dev->ml_priv;
91980990
GKH
2568 struct iw_point *encoding = &wrqu->encoding;
2569 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2570 int keyIdx, alg = ext->alg;
2571
2572 //check if the interface is down
2573 if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))
2574 {
2575 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
2576 return -ENETDOWN;
2577 }
2578
2579 if (encoding->flags & IW_ENCODE_DISABLED)
2580 {
2581 keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
2582 // set BSSID wcid entry of the Pair-wise Key table as no-security mode
2583 AsicRemovePairwiseKeyEntry(pAdapter, BSS0, BSSID_WCID);
2584 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0;
2585 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_NONE;
2586 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)keyIdx);
2587 NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(CIPHER_KEY));
d599edca 2588 DBGPRINT(RT_DEBUG_TRACE, ("%s::Remove all keys!(encoding->flags = %x)\n", __func__, encoding->flags));
91980990
GKH
2589 }
2590 else
2591 {
2592 // Get Key Index and convet to our own defined key index
2593 keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1;
2594 if((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS))
2595 return -EINVAL;
2596
2597 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2598 {
2599 pAdapter->StaCfg.DefaultKeyId = keyIdx;
d599edca 2600 DBGPRINT(RT_DEBUG_TRACE, ("%s::DefaultKeyId = %d\n", __func__, pAdapter->StaCfg.DefaultKeyId));
91980990
GKH
2601 }
2602
2603 switch (alg) {
2604 case IW_ENCODE_ALG_NONE:
d599edca 2605 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_NONE\n", __func__));
91980990
GKH
2606 break;
2607 case IW_ENCODE_ALG_WEP:
d599edca 2608 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_WEP - ext->key_len = %d, keyIdx = %d\n", __func__, ext->key_len, keyIdx));
91980990
GKH
2609 if (ext->key_len == MAX_WEP_KEY_SIZE)
2610 {
2611 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MAX_WEP_KEY_SIZE;
2612 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP128;
2613 }
2614 else if (ext->key_len == MIN_WEP_KEY_SIZE)
2615 {
2616 pAdapter->SharedKey[BSS0][keyIdx].KeyLen = MIN_WEP_KEY_SIZE;
2617 pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_WEP64;
2618 }
2619 else
2620 return -EINVAL;
2621
2622 NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16);
2623 NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, ext->key_len);
3a32ed12 2624#ifndef RT30xx
ed291e80
AM
2625 if (pAdapter->StaCfg.GroupCipher == Ndis802_11GroupWEP40Enabled ||
2626 pAdapter->StaCfg.GroupCipher == Ndis802_11GroupWEP104Enabled)
2627 {
2628 // Set Group key material to Asic
2629 AsicAddSharedKeyEntry(pAdapter, BSS0, keyIdx, pAdapter->SharedKey[BSS0][keyIdx].CipherAlg, pAdapter->SharedKey[BSS0][keyIdx].Key, NULL, NULL);
2630
2631 // Update WCID attribute table and IVEIV table for this group key table
2632 RTMPAddWcidAttributeEntry(pAdapter, BSS0, keyIdx, pAdapter->SharedKey[BSS0][keyIdx].CipherAlg, NULL);
2633
2634 STA_PORT_SECURED(pAdapter);
2635
2636 // Indicate Connected for GUI
2637 pAdapter->IndicateMediaState = NdisMediaStateConnected;
2638 }
3a32ed12 2639#endif
91980990
GKH
2640 break;
2641 case IW_ENCODE_ALG_TKIP:
d599edca 2642 DBGPRINT(RT_DEBUG_TRACE, ("%s::IW_ENCODE_ALG_TKIP - keyIdx = %d, ext->key_len = %d\n", __func__, keyIdx, ext->key_len));
91980990
GKH
2643 if (ext->key_len == 32)
2644 {
2645 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2646 {
2647 fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, FALSE, ext);
2648 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
2649 {
2650 STA_PORT_SECURED(pAdapter);
2651 }
2652 }
2653 else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
2654 {
2655 fnSetCipherKey(pAdapter, keyIdx, CIPHER_TKIP, TRUE, ext);
2656
2657 // set 802.1x port control
2658 STA_PORT_SECURED(pAdapter);
2659 }
2660 }
2661 else
2662 return -EINVAL;
2663 break;
2664 case IW_ENCODE_ALG_CCMP:
2665 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2666 {
2667 fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, FALSE, ext);
2668 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)
2669 STA_PORT_SECURED(pAdapter);
2670 }
2671 else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
2672 {
2673 fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, TRUE, ext);
2674
2675 // set 802.1x port control
2676 STA_PORT_SECURED(pAdapter);
2677 }
2678 break;
2679 default:
2680 return -EINVAL;
2681 }
2682 }
2683
2684 return 0;
2685}
2686
2687int
2688rt_ioctl_giwencodeext(struct net_device *dev,
2689 struct iw_request_info *info,
2690 union iwreq_data *wrqu, char *extra)
2691{
739b7979 2692 PRTMP_ADAPTER pAd = dev->ml_priv;
91980990
GKH
2693 PCHAR pKey = NULL;
2694 struct iw_point *encoding = &wrqu->encoding;
2695 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2696 int idx, max_key_len;
2697
2698 DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_giwencodeext\n"));
2699
2700 max_key_len = encoding->length - sizeof(*ext);
2701 if (max_key_len < 0)
2702 return -EINVAL;
2703
2704 idx = encoding->flags & IW_ENCODE_INDEX;
2705 if (idx)
2706 {
2707 if (idx < 1 || idx > 4)
2708 return -EINVAL;
2709 idx--;
2710
2711 if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
2712 (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled))
2713 {
2714 if (idx != pAd->StaCfg.DefaultKeyId)
2715 {
2716 ext->key_len = 0;
2717 return 0;
2718 }
2719 }
2720 }
2721 else
2722 idx = pAd->StaCfg.DefaultKeyId;
2723
2724 encoding->flags = idx + 1;
2725 memset(ext, 0, sizeof(*ext));
2726
2727 ext->key_len = 0;
2728 switch(pAd->StaCfg.WepStatus) {
2729 case Ndis802_11WEPDisabled:
2730 ext->alg = IW_ENCODE_ALG_NONE;
2731 encoding->flags |= IW_ENCODE_DISABLED;
2732 break;
2733 case Ndis802_11WEPEnabled:
2734 ext->alg = IW_ENCODE_ALG_WEP;
2735 if (pAd->SharedKey[BSS0][idx].KeyLen > max_key_len)
2736 return -E2BIG;
2737 else
2738 {
2739 ext->key_len = pAd->SharedKey[BSS0][idx].KeyLen;
2740 pKey = &(pAd->SharedKey[BSS0][idx].Key[0]);
2741 }
2742 break;
2743 case Ndis802_11Encryption2Enabled:
2744 case Ndis802_11Encryption3Enabled:
2745 if (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
2746 ext->alg = IW_ENCODE_ALG_TKIP;
2747 else
2748 ext->alg = IW_ENCODE_ALG_CCMP;
2749
2750 if (max_key_len < 32)
2751 return -E2BIG;
2752 else
2753 {
2754 ext->key_len = 32;
2755 pKey = &pAd->StaCfg.PMK[0];
2756 }
2757 break;
2758 default:
2759 return -EINVAL;
2760 }
2761
2762 if (ext->key_len && pKey)
2763 {
2764 encoding->flags |= IW_ENCODE_ENABLED;
2765 memcpy(ext->key, pKey, ext->key_len);
2766 }
2767
2768 return 0;
2769}
2770
2771#ifdef SIOCSIWGENIE
2772int rt_ioctl_siwgenie(struct net_device *dev,
2773 struct iw_request_info *info,
2774 union iwreq_data *wrqu, char *extra)
2775{
739b7979 2776 PRTMP_ADAPTER pAd = dev->ml_priv;
91980990
GKH
2777
2778 if (wrqu->data.length > MAX_LEN_OF_RSNIE ||
2779 (wrqu->data.length && extra == NULL))
2780 return -EINVAL;
2781
2782 if (wrqu->data.length)
2783 {
2784 pAd->StaCfg.RSNIE_Len = wrqu->data.length;
2785 NdisMoveMemory(&pAd->StaCfg.RSN_IE[0], extra, pAd->StaCfg.RSNIE_Len);
2786 }
2787 else
2788 {
2789 pAd->StaCfg.RSNIE_Len = 0;
2790 NdisZeroMemory(&pAd->StaCfg.RSN_IE[0], MAX_LEN_OF_RSNIE);
2791 }
2792
2793 return 0;
2794}
2795#endif // SIOCSIWGENIE //
2796
2797int rt_ioctl_giwgenie(struct net_device *dev,
2798 struct iw_request_info *info,
2799 union iwreq_data *wrqu, char *extra)
2800{
739b7979 2801 PRTMP_ADAPTER pAd = dev->ml_priv;
91980990
GKH
2802
2803 if ((pAd->StaCfg.RSNIE_Len == 0) ||
2804 (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA))
2805 {
2806 wrqu->data.length = 0;
2807 return 0;
2808 }
2809
91980990
GKH
2810#ifdef SIOCSIWGENIE
2811 if (pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE)
2812 {
2813 if (wrqu->data.length < pAd->StaCfg.RSNIE_Len)
2814 return -E2BIG;
2815
2816 wrqu->data.length = pAd->StaCfg.RSNIE_Len;
2817 memcpy(extra, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
2818 }
2819 else
2820#endif // SIOCSIWGENIE //
91980990
GKH
2821 {
2822 UCHAR RSNIe = IE_WPA;
2823
2824 if (wrqu->data.length < (pAd->StaCfg.RSNIE_Len + 2)) // ID, Len
2825 return -E2BIG;
2826 wrqu->data.length = pAd->StaCfg.RSNIE_Len + 2;
2827
2828 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
2829 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2))
2830 RSNIe = IE_RSN;
2831
2832 extra[0] = (char)RSNIe;
2833 extra[1] = pAd->StaCfg.RSNIE_Len;
2834 memcpy(extra+2, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len);
2835 }
2836
2837 return 0;
2838}
2839
2840int rt_ioctl_siwpmksa(struct net_device *dev,
2841 struct iw_request_info *info,
2842 union iwreq_data *wrqu,
2843 char *extra)
2844{
739b7979 2845 PRTMP_ADAPTER pAd = dev->ml_priv;
91980990
GKH
2846 struct iw_pmksa *pPmksa = (struct iw_pmksa *)wrqu->data.pointer;
2847 INT CachedIdx = 0, idx = 0;
2848
2849 if (pPmksa == NULL)
2850 return -EINVAL;
2851
2852 DBGPRINT(RT_DEBUG_TRACE ,("===> rt_ioctl_siwpmksa\n"));
2853 switch(pPmksa->cmd)
2854 {
2855 case IW_PMKSA_FLUSH:
2856 NdisZeroMemory(pAd->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
2857 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_FLUSH\n"));
2858 break;
2859 case IW_PMKSA_REMOVE:
2860 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
2861 {
2862 // compare the BSSID
2863 if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
2864 {
2865 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN);
2866 NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx].PMKID, 16);
2867 for (idx = CachedIdx; idx < (pAd->StaCfg.SavedPMKNum - 1); idx++)
2868 {
2869 NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].BSSID[0], &pAd->StaCfg.SavedPMK[idx+1].BSSID[0], MAC_ADDR_LEN);
2870 NdisMoveMemory(&pAd->StaCfg.SavedPMK[idx].PMKID[0], &pAd->StaCfg.SavedPMK[idx+1].PMKID[0], 16);
2871 }
2872 pAd->StaCfg.SavedPMKNum--;
2873 break;
2874 }
2875 }
2876
2877 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_REMOVE\n"));
2878 break;
2879 case IW_PMKSA_ADD:
2880 for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; CachedIdx++)
2881 {
2882 // compare the BSSID
2883 if (NdisEqualMemory(pPmksa->bssid.sa_data, pAd->StaCfg.SavedPMK[CachedIdx].BSSID, MAC_ADDR_LEN))
2884 break;
2885 }
2886
2887 // Found, replace it
2888 if (CachedIdx < PMKID_NO)
2889 {
2890 DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
2891 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
2892 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
2893 pAd->StaCfg.SavedPMKNum++;
2894 }
2895 // Not found, replace the last one
2896 else
2897 {
2898 // Randomly replace one
2899 CachedIdx = (pPmksa->bssid.sa_data[5] % PMKID_NO);
2900 DBGPRINT(RT_DEBUG_OFF, ("Update PMKID, idx = %d\n", CachedIdx));
2901 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].BSSID[0], pPmksa->bssid.sa_data, MAC_ADDR_LEN);
2902 NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx].PMKID[0], pPmksa->pmkid, 16);
2903 }
2904
2905 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - IW_PMKSA_ADD\n"));
2906 break;
2907 default:
2908 DBGPRINT(RT_DEBUG_TRACE ,("rt_ioctl_siwpmksa - Unknow Command!!\n"));
2909 break;
2910 }
2911
2912 return 0;
2913}
2914#endif // #if WIRELESS_EXT > 17
2915
2916#ifdef DBG
2917static int
2918rt_private_ioctl_bbp(struct net_device *dev, struct iw_request_info *info,
2919 struct iw_point *wrq, char *extra)
2920 {
2921 CHAR *this_char;
2922 CHAR *value = NULL;
2923 UCHAR regBBP = 0;
2924 UINT32 bbpId;
2925 UINT32 bbpValue;
2926 BOOLEAN bIsPrintAllBBP = FALSE;
2927 INT Status = 0;
739b7979 2928 PRTMP_ADAPTER pAdapter = dev->ml_priv;
91980990
GKH
2929
2930
2931 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
2932
2933 if (wrq->length > 1) //No parameters.
2934 {
2935 sprintf(extra, "\n");
2936
2937 //Parsing Read or Write
2938 this_char = wrq->pointer;
2939 DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s\n", this_char));
2940 if (!*this_char)
2941 goto next;
2942
2943 if ((value = rtstrchr(this_char, '=')) != NULL)
2944 *value++ = 0;
2945
2946 if (!value || !*value)
2947 { //Read
2948 DBGPRINT(RT_DEBUG_TRACE, ("this_char=%s, value=%s\n", this_char, value));
2949 if (sscanf(this_char, "%d", &(bbpId)) == 1)
2950 {
3a32ed12 2951#ifndef RT30xx
91980990 2952 if (bbpId <= 136)
3a32ed12
BZ
2953#endif // RT30xx //
2954#ifdef RT30xx
2955 if (bbpId <= 138) // edit by johnli, RF power sequence setup, add BBP R138 for ADC dynamic on/off control
2956#endif // RT30xx //
91980990 2957 {
91980990
GKH
2958 {
2959 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
2960 }
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));
2964 }
2965 else
2966 {//Invalid parametes, so default printk all bbp
2967 bIsPrintAllBBP = TRUE;
2968 goto next;
2969 }
2970 }
2971 else
2972 { //Invalid parametes, so default printk all bbp
2973 bIsPrintAllBBP = TRUE;
2974 goto next;
2975 }
2976 }
2977 else
2978 { //Write
2979 if ((sscanf(this_char, "%d", &(bbpId)) == 1) && (sscanf(value, "%x", &(bbpValue)) == 1))
2980 {
3a32ed12 2981#ifndef RT30xx
91980990 2982 if (bbpId <= 136)
3a32ed12
BZ
2983#endif // RT30xx //
2984#ifdef RT30xx
2985 if (bbpId <= 138) // edit by johnli, RF power sequence setup, add BBP R138 for ADC dynamic on/off control
2986#endif // RT30xx //
91980990 2987 {
91980990
GKH
2988 {
2989 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, bbpId, bbpValue);
2990 //Read it back for showing
2991 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
2992 }
2993 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X\n", bbpId, bbpId*2, regBBP);
2994 wrq->length = strlen(extra) + 1; // 1: size of '\0'
2995 DBGPRINT(RT_DEBUG_TRACE, ("msg=%s\n", extra));
2996 }
2997 else
2998 {//Invalid parametes, so default printk all bbp
2999 bIsPrintAllBBP = TRUE;
3000 goto next;
3001 }
3002 }
3003 else
3004 { //Invalid parametes, so default printk all bbp
3005 bIsPrintAllBBP = TRUE;
3006 goto next;
3007 }
3008 }
3009 }
3010 else
3011 bIsPrintAllBBP = TRUE;
3012
3013next:
3014 if (bIsPrintAllBBP)
3015 {
3016 memset(extra, 0x00, IW_PRIV_SIZE_MASK);
3017 sprintf(extra, "\n");
3a32ed12 3018#ifndef RT30xx
91980990 3019 for (bbpId = 0; bbpId <= 136; bbpId++)
3a32ed12
BZ
3020#endif // RT30xx //
3021#ifdef RT30xx
3022 for (bbpId = 0; bbpId <= 138; bbpId++) // edit by johnli, RF power sequence setup, add BBP R138 for ADC dynamic on/off control
3023#endif // RT30xx //
91980990
GKH
3024 {
3025 if (strlen(extra) >= (IW_PRIV_SIZE_MASK - 10))
3026 break;
91980990 3027 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
3a32ed12 3028#ifndef RT30xx
91980990
GKH
3029 sprintf(extra+strlen(extra), "R%02d[0x%02X]:%02X ", bbpId, bbpId*2, regBBP);
3030 if (bbpId%5 == 4)
3031 sprintf(extra+strlen(extra), "\n");
3a32ed12
BZ
3032#endif
3033#ifdef RT30xx
3034 sprintf(extra+strlen(extra), "%03d = %02X\n", bbpId, regBBP); // edit by johnli, change display format
3035#endif
91980990
GKH
3036 }
3037
3038 wrq->length = strlen(extra) + 1; // 1: size of '\0'
3039 DBGPRINT(RT_DEBUG_TRACE, ("wrq->length = %d\n", wrq->length));
3040 }
3041
3042 DBGPRINT(RT_DEBUG_TRACE, ("<==rt_private_ioctl_bbp\n\n"));
3043
3044 return Status;
3045}
3046#endif // DBG //
3047
3048int rt_ioctl_siwrate(struct net_device *dev,
3049 struct iw_request_info *info,
3050 union iwreq_data *wrqu, char *extra)
3051{
739b7979 3052 PRTMP_ADAPTER pAd = dev->ml_priv;
91980990
GKH
3053 UINT32 rate = wrqu->bitrate.value, fixed = wrqu->bitrate.fixed;
3054
3055 //check if the interface is down
3056 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
3057 {
3058 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::Network is down!\n"));
3059 return -ENETDOWN;
3060 }
3061
3062 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(rate = %d, fixed = %d)\n", rate, fixed));
3063 /* rate = -1 => auto rate
3064 rate = X, fixed = 1 => (fixed rate X)
3065 */
3066 if (rate == -1)
3067 {
3068 //Auto Rate
3069 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
3070 pAd->StaCfg.bAutoTxRateSwitch = TRUE;
3071 if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
3072 (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
3073 RTMPSetDesiredRates(pAd, -1);
3074
91980990 3075 SetCommonHT(pAd);
91980990
GKH
3076 }
3077 else
3078 {
3079 if (fixed)
3080 {
3081 pAd->StaCfg.bAutoTxRateSwitch = FALSE;
3082 if ((pAd->CommonCfg.PhyMode <= PHY_11G) ||
3083 (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
3084 RTMPSetDesiredRates(pAd, rate);
3085 else
3086 {
3087 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
91980990 3088 SetCommonHT(pAd);
91980990
GKH
3089 }
3090 DBGPRINT(RT_DEBUG_TRACE, ("rt_ioctl_siwrate::(HtMcs=%d)\n",pAd->StaCfg.DesiredTransmitSetting.field.MCS));
3091 }
3092 else
3093 {
3094 // TODO: rate = X, fixed = 0 => (rates <= X)
3095 return -EOPNOTSUPP;
3096 }
3097 }
3098
3099 return 0;
3100}
3101
3102int rt_ioctl_giwrate(struct net_device *dev,
3103 struct iw_request_info *info,
3104 union iwreq_data *wrqu, char *extra)
3105{
739b7979 3106 PRTMP_ADAPTER pAd = dev->ml_priv;
91980990
GKH
3107 int rate_index = 0, rate_count = 0;
3108 HTTRANSMIT_SETTING ht_setting;
3109 __s32 ralinkrate[] =
3110 {2, 4, 11, 22, // CCK
3111 12, 18, 24, 36, 48, 72, 96, 108, // OFDM
3112 13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260, // 20MHz, 800ns GI, MCS: 0 ~ 15
3113 39, 78, 117, 156, 234, 312, 351, 390, // 20MHz, 800ns GI, MCS: 16 ~ 23
3114 27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540, // 40MHz, 800ns GI, MCS: 0 ~ 15
3115 81, 162, 243, 324, 486, 648, 729, 810, // 40MHz, 800ns GI, MCS: 16 ~ 23
3116 14, 29, 43, 57, 87, 115, 130, 144, 29, 59, 87, 115, 173, 230, 260, 288, // 20MHz, 400ns GI, MCS: 0 ~ 15
3117 43, 87, 130, 173, 260, 317, 390, 433, // 20MHz, 400ns GI, MCS: 16 ~ 23
3118 30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600, // 40MHz, 400ns GI, MCS: 0 ~ 15
3119 90, 180, 270, 360, 540, 720, 810, 900}; // 40MHz, 400ns GI, MCS: 16 ~ 23
3120
3121 rate_count = sizeof(ralinkrate)/sizeof(__s32);
3122 //check if the interface is down
3123 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
3124 {
3125 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
3126 return -ENETDOWN;
3127 }
3128
3129 if ((pAd->StaCfg.bAutoTxRateSwitch == FALSE) &&
3130 (INFRA_ON(pAd)) &&
3131 ((pAd->CommonCfg.PhyMode <= PHY_11G) || (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM)))
3132 ht_setting.word = pAd->StaCfg.HTPhyMode.word;
3133 else
3134 ht_setting.word = pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word;
3135
91980990
GKH
3136 if (ht_setting.field.MODE >= MODE_HTMIX)
3137 {
3138 rate_index = 12 + ((UCHAR)ht_setting.field.BW *24) + ((UCHAR)ht_setting.field.ShortGI *48) + ((UCHAR)ht_setting.field.MCS);
3139 }
3140 else
91980990
GKH
3141 if (ht_setting.field.MODE == MODE_OFDM)
3142 rate_index = (UCHAR)(ht_setting.field.MCS) + 4;
3143 else if (ht_setting.field.MODE == MODE_CCK)
3144 rate_index = (UCHAR)(ht_setting.field.MCS);
3145
3146 if (rate_index < 0)
3147 rate_index = 0;
3148
3149 if (rate_index > rate_count)
3150 rate_index = rate_count;
3151
3152 wrqu->bitrate.value = ralinkrate[rate_index] * 500000;
3153 wrqu->bitrate.disabled = 0;
3154
3155 return 0;
3156}
3157
3158static const iw_handler rt_handler[] =
3159{
3160 (iw_handler) NULL, /* SIOCSIWCOMMIT */
3161 (iw_handler) rt_ioctl_giwname, /* SIOCGIWNAME */
3162 (iw_handler) NULL, /* SIOCSIWNWID */
3163 (iw_handler) NULL, /* SIOCGIWNWID */
3164 (iw_handler) rt_ioctl_siwfreq, /* SIOCSIWFREQ */
3165 (iw_handler) rt_ioctl_giwfreq, /* SIOCGIWFREQ */
3166 (iw_handler) rt_ioctl_siwmode, /* SIOCSIWMODE */
3167 (iw_handler) rt_ioctl_giwmode, /* SIOCGIWMODE */
3168 (iw_handler) NULL, /* SIOCSIWSENS */
3169 (iw_handler) NULL, /* SIOCGIWSENS */
3170 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
3171 (iw_handler) rt_ioctl_giwrange, /* SIOCGIWRANGE */
3172 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
3173 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
3174 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
3175 (iw_handler) rt28xx_get_wireless_stats /* kernel code */, /* SIOCGIWSTATS */
3176 (iw_handler) NULL, /* SIOCSIWSPY */
3177 (iw_handler) NULL, /* SIOCGIWSPY */
3178 (iw_handler) NULL, /* SIOCSIWTHRSPY */
3179 (iw_handler) NULL, /* SIOCGIWTHRSPY */
3180 (iw_handler) rt_ioctl_siwap, /* SIOCSIWAP */
3181 (iw_handler) rt_ioctl_giwap, /* SIOCGIWAP */
3182#ifdef SIOCSIWMLME
3183 (iw_handler) rt_ioctl_siwmlme, /* SIOCSIWMLME */
3184#else
3185 (iw_handler) NULL, /* SIOCSIWMLME */
3186#endif // SIOCSIWMLME //
3187 (iw_handler) rt_ioctl_iwaplist, /* SIOCGIWAPLIST */
3188#ifdef SIOCGIWSCAN
3189 (iw_handler) rt_ioctl_siwscan, /* SIOCSIWSCAN */
3190 (iw_handler) rt_ioctl_giwscan, /* SIOCGIWSCAN */
3191#else
3192 (iw_handler) NULL, /* SIOCSIWSCAN */
3193 (iw_handler) NULL, /* SIOCGIWSCAN */
3194#endif /* SIOCGIWSCAN */
3195 (iw_handler) rt_ioctl_siwessid, /* SIOCSIWESSID */
3196 (iw_handler) rt_ioctl_giwessid, /* SIOCGIWESSID */
3197 (iw_handler) rt_ioctl_siwnickn, /* SIOCSIWNICKN */
3198 (iw_handler) rt_ioctl_giwnickn, /* SIOCGIWNICKN */
3199 (iw_handler) NULL, /* -- hole -- */
3200 (iw_handler) NULL, /* -- hole -- */
3201 (iw_handler) rt_ioctl_siwrate, /* SIOCSIWRATE */
3202 (iw_handler) rt_ioctl_giwrate, /* SIOCGIWRATE */
3203 (iw_handler) rt_ioctl_siwrts, /* SIOCSIWRTS */
3204 (iw_handler) rt_ioctl_giwrts, /* SIOCGIWRTS */
3205 (iw_handler) rt_ioctl_siwfrag, /* SIOCSIWFRAG */
3206 (iw_handler) rt_ioctl_giwfrag, /* SIOCGIWFRAG */
3207 (iw_handler) NULL, /* SIOCSIWTXPOW */
3208 (iw_handler) NULL, /* SIOCGIWTXPOW */
3209 (iw_handler) NULL, /* SIOCSIWRETRY */
3210 (iw_handler) NULL, /* SIOCGIWRETRY */
3211 (iw_handler) rt_ioctl_siwencode, /* SIOCSIWENCODE */
3212 (iw_handler) rt_ioctl_giwencode, /* SIOCGIWENCODE */
3213 (iw_handler) NULL, /* SIOCSIWPOWER */
3214 (iw_handler) NULL, /* SIOCGIWPOWER */
3215 (iw_handler) NULL, /* -- hole -- */
3216 (iw_handler) NULL, /* -- hole -- */
3217#if WIRELESS_EXT > 17
3218 (iw_handler) rt_ioctl_siwgenie, /* SIOCSIWGENIE */
3219 (iw_handler) rt_ioctl_giwgenie, /* SIOCGIWGENIE */
3220 (iw_handler) rt_ioctl_siwauth, /* SIOCSIWAUTH */
3221 (iw_handler) rt_ioctl_giwauth, /* SIOCGIWAUTH */
3222 (iw_handler) rt_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
3223 (iw_handler) rt_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */
3224 (iw_handler) rt_ioctl_siwpmksa, /* SIOCSIWPMKSA */
3225#endif
3226};
3227
3228static const iw_handler rt_priv_handlers[] = {
3229 (iw_handler) NULL, /* + 0x00 */
3230 (iw_handler) NULL, /* + 0x01 */
91980990 3231 (iw_handler) rt_ioctl_setparam, /* + 0x02 */
91980990
GKH
3232#ifdef DBG
3233 (iw_handler) rt_private_ioctl_bbp, /* + 0x03 */
3234#else
3235 (iw_handler) NULL, /* + 0x03 */
3236#endif
3237 (iw_handler) NULL, /* + 0x04 */
3238 (iw_handler) NULL, /* + 0x05 */
3239 (iw_handler) NULL, /* + 0x06 */
3240 (iw_handler) NULL, /* + 0x07 */
3241 (iw_handler) NULL, /* + 0x08 */
3242 (iw_handler) rt_private_get_statistics, /* + 0x09 */
3243 (iw_handler) NULL, /* + 0x0A */
3244 (iw_handler) NULL, /* + 0x0B */
3245 (iw_handler) NULL, /* + 0x0C */
3246 (iw_handler) NULL, /* + 0x0D */
3247 (iw_handler) NULL, /* + 0x0E */
3248 (iw_handler) NULL, /* + 0x0F */
3249 (iw_handler) NULL, /* + 0x10 */
3250 (iw_handler) rt_private_show, /* + 0x11 */
3251 (iw_handler) NULL, /* + 0x12 */
3252 (iw_handler) NULL, /* + 0x13 */
3253 (iw_handler) NULL, /* + 0x15 */
3254 (iw_handler) NULL, /* + 0x17 */
3255 (iw_handler) NULL, /* + 0x18 */
3256};
3257
3258const struct iw_handler_def rt28xx_iw_handler_def =
3259{
3260#define N(a) (sizeof (a) / sizeof (a[0]))
3261 .standard = (iw_handler *) rt_handler,
3262 .num_standard = sizeof(rt_handler) / sizeof(iw_handler),
3263 .private = (iw_handler *) rt_priv_handlers,
3264 .num_private = N(rt_priv_handlers),
3265 .private_args = (struct iw_priv_args *) privtab,
3266 .num_private_args = N(privtab),
3267#if IW_HANDLER_VERSION >= 7
3268 .get_wireless_stats = rt28xx_get_wireless_stats,
3269#endif
3270};
3271
3272INT RTMPSetInformation(
3273 IN PRTMP_ADAPTER pAdapter,
3274 IN OUT struct ifreq *rq,
3275 IN INT cmd)
3276{
3277 struct iwreq *wrq = (struct iwreq *) rq;
3278 NDIS_802_11_SSID Ssid;
3279 NDIS_802_11_MAC_ADDRESS Bssid;
3280 RT_802_11_PHY_MODE PhyMode;
3281 RT_802_11_STA_CONFIG StaConfig;
3282 NDIS_802_11_RATES aryRates;
3283 RT_802_11_PREAMBLE Preamble;
3284 NDIS_802_11_WEP_STATUS WepStatus;
3285 NDIS_802_11_AUTHENTICATION_MODE AuthMode = Ndis802_11AuthModeMax;
3286 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
3287 NDIS_802_11_RTS_THRESHOLD RtsThresh;
3288 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
3289 NDIS_802_11_POWER_MODE PowerMode;
3290 PNDIS_802_11_KEY pKey = NULL;
3291 PNDIS_802_11_WEP pWepKey =NULL;
3292 PNDIS_802_11_REMOVE_KEY pRemoveKey = NULL;
3293 NDIS_802_11_CONFIGURATION Config, *pConfig = NULL;
3294 NDIS_802_11_NETWORK_TYPE NetType;
3295 ULONG Now;
3296 UINT KeyIdx = 0;
3297 INT Status = NDIS_STATUS_SUCCESS, MaxPhyMode = PHY_11G;
3298 ULONG PowerTemp;
3299 BOOLEAN RadioState;
3300 BOOLEAN StateMachineTouched = FALSE;
91980990 3301 OID_SET_HT_PHYMODE HT_PhyMode; //11n ,kathy
91980990
GKH
3302 PNDIS_802_11_PMKID pPmkId = NULL;
3303 BOOLEAN IEEE8021xState = FALSE;
3304 BOOLEAN IEEE8021x_required_keys = FALSE;
3305 UCHAR wpa_supplicant_enable = 0;
91980990 3306
91980990 3307 MaxPhyMode = PHY_11N_5G;
91980990
GKH
3308
3309 DBGPRINT(RT_DEBUG_TRACE, ("-->RTMPSetInformation(), 0x%08x\n", cmd&0x7FFF));
3310 switch(cmd & 0x7FFF) {
3311 case RT_OID_802_11_COUNTRY_REGION:
3312 if (wrq->u.data.length < sizeof(UCHAR))
3313 Status = -EINVAL;
3314 // Only avaliable when EEPROM not programming
3315 else if (!(pAdapter->CommonCfg.CountryRegion & 0x80) && !(pAdapter->CommonCfg.CountryRegionForABand & 0x80))
3316 {
3317 ULONG Country;
3318 UCHAR TmpPhy;
3319
3320 Status = copy_from_user(&Country, wrq->u.data.pointer, wrq->u.data.length);
3321 pAdapter->CommonCfg.CountryRegion = (UCHAR)(Country & 0x000000FF);
3322 pAdapter->CommonCfg.CountryRegionForABand = (UCHAR)((Country >> 8) & 0x000000FF);
3323 TmpPhy = pAdapter->CommonCfg.PhyMode;
3324 pAdapter->CommonCfg.PhyMode = 0xff;
3325 // Build all corresponding channel information
3326 RTMPSetPhyMode(pAdapter, TmpPhy);
91980990 3327 SetCommonHT(pAdapter);
91980990
GKH
3328 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_COUNTRY_REGION (A:%d B/G:%d)\n", pAdapter->CommonCfg.CountryRegionForABand,
3329 pAdapter->CommonCfg.CountryRegion));
3330 }
3331 break;
3332 case OID_802_11_BSSID_LIST_SCAN:
91980990
GKH
3333 Now = jiffies;
3334 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID_LIST_SCAN, TxCnt = %d \n", pAdapter->RalinkCounters.LastOneSecTotalTxCount));
3335
3336 if (MONITOR_ON(pAdapter))
3337 {
3338 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is in Monitor Mode now !!!\n"));
3339 break;
3340 }
3341
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;
3345
3346 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
3347 {
3348 DBGPRINT(RT_DEBUG_TRACE, ("!!! Driver is scanning now !!!\n"));
3349 pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
3350 Status = NDIS_STATUS_SUCCESS;
3351 break;
3352 }
3353
3354 if (pAdapter->RalinkCounters.LastOneSecTotalTxCount > 100)
3355 {
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;
3360 }
3361
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))
3368 {
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;
3373 }
3374
3375
3376 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3377 {
3378 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3379 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3380 }
3381
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;
3388
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,
3394 0,
3395 NULL);
3396
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
3404 {
3405 PCHAR pSsidString = NULL;
3406 Status = copy_from_user(&Ssid, wrq->u.data.pointer, wrq->u.data.length);
3407
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
3412 {
3413 if (Ssid.SsidLength == 0)
3414 {
3415 Set_SSID_Proc(pAdapter, "");
3416 }
3417 else
3418 {
3419 pSsidString = (CHAR *) kmalloc(MAX_LEN_OF_SSID+1, MEM_ALLOC_FLAG);
3420 if (pSsidString)
3421 {
3422 NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID+1);
3423 NdisMoveMemory(pSsidString, Ssid.Ssid, Ssid.SsidLength);
3424 Set_SSID_Proc(pAdapter, pSsidString);
3425 kfree(pSsidString);
3426 }
3427 else
3428 Status = -ENOMEM;
3429 }
3430 }
3431 }
3432 break;
3433 case OID_802_11_BSSID:
91980990
GKH
3434 if (wrq->u.data.length != sizeof(NDIS_802_11_MAC_ADDRESS))
3435 Status = -EINVAL;
3436 else
3437 {
3438 Status = copy_from_user(&Bssid, wrq->u.data.pointer, wrq->u.data.length);
3439
3440 // tell CNTL state machine to call NdisMSetInformationComplete() after completing
3441 // this request, because this request is initiated by NDIS.
3442 pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;
3443
3444 // Prevent to connect AP again in STAMlmePeriodicExec
3445 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
3446
3447 // Reset allowed scan retries
3448 pAdapter->StaCfg.ScanCnt = 0;
3449
3450 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
3451 {
3452 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
3453 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
3454 }
3455 MlmeEnqueue(pAdapter,
3456 MLME_CNTL_STATE_MACHINE,
3457 OID_802_11_BSSID,
3458 sizeof(NDIS_802_11_MAC_ADDRESS),
3459 (VOID *)&Bssid);
3460 Status = NDIS_STATUS_SUCCESS;
3461 StateMachineTouched = TRUE;
3462
3463 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_BSSID %02x:%02x:%02x:%02x:%02x:%02x\n",
3464 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
3465 }
3466 break;
3467 case RT_OID_802_11_RADIO:
3468 if (wrq->u.data.length != sizeof(BOOLEAN))
3469 Status = -EINVAL;
3470 else
3471 {
3472 Status = copy_from_user(&RadioState, wrq->u.data.pointer, wrq->u.data.length);
3473 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RADIO (=%d)\n", RadioState));
3474 if (pAdapter->StaCfg.bSwRadio != RadioState)
3475 {
3476 pAdapter->StaCfg.bSwRadio = RadioState;
3477 if (pAdapter->StaCfg.bRadio != (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio))
3478 {
3479 pAdapter->StaCfg.bRadio = (pAdapter->StaCfg.bHwRadio && pAdapter->StaCfg.bSwRadio);
3480 if (pAdapter->StaCfg.bRadio == TRUE)
3481 {
3482 MlmeRadioOn(pAdapter);
3483 // Update extra information
3484 pAdapter->ExtraInfo = EXTRA_INFO_CLEAR;
3485 }
3486 else
3487 {
3488 MlmeRadioOff(pAdapter);
3489 // Update extra information
3490 pAdapter->ExtraInfo = SW_RADIO_OFF;
3491 }
3492 }
3493 }
3494 }
3495 break;
3496 case RT_OID_802_11_PHY_MODE:
3497 if (wrq->u.data.length != sizeof(RT_802_11_PHY_MODE))
3498 Status = -EINVAL;
3499 else
3500 {
3501 Status = copy_from_user(&PhyMode, wrq->u.data.pointer, wrq->u.data.length);
3502 if (PhyMode <= MaxPhyMode)
3503 {
3504 RTMPSetPhyMode(pAdapter, PhyMode);
91980990 3505 SetCommonHT(pAdapter);
91980990
GKH
3506 }
3507 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PHY_MODE (=%d)\n", PhyMode));
3508 }
3509 break;
3510 case RT_OID_802_11_STA_CONFIG:
3511 if (wrq->u.data.length != sizeof(RT_802_11_STA_CONFIG))
3512 Status = -EINVAL;
3513 else
3514 {
3515 Status = copy_from_user(&StaConfig, wrq->u.data.pointer, wrq->u.data.length);
3516 pAdapter->CommonCfg.bEnableTxBurst = StaConfig.EnableTxBurst;
3517 pAdapter->CommonCfg.UseBGProtection = StaConfig.UseBGProtection;
3518 pAdapter->CommonCfg.bUseShortSlotTime = 1; // 2003-10-30 always SHORT SLOT capable
3519 if ((pAdapter->CommonCfg.PhyMode != StaConfig.AdhocMode) &&
3520 (StaConfig.AdhocMode <= MaxPhyMode))
3521 {
3522 // allow dynamic change of "USE OFDM rate or not" in ADHOC mode
3523 // if setting changed, need to reset current TX rate as well as BEACON frame format
3a32ed12
BZ
3524#ifdef RT30xx
3525 pAdapter->CommonCfg.PhyMode = StaConfig.AdhocMode;
3526#endif
91980990
GKH
3527 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
3528 {
3a32ed12 3529#ifndef RT30xx
91980990 3530 pAdapter->CommonCfg.PhyMode = StaConfig.AdhocMode;
3a32ed12 3531#endif
91980990
GKH
3532 RTMPSetPhyMode(pAdapter, PhyMode);
3533 MlmeUpdateTxRates(pAdapter, FALSE, 0);
3534 MakeIbssBeacon(pAdapter); // re-build BEACON frame
3535 AsicEnableIbssSync(pAdapter); // copy to on-chip memory
3536 }
3537 }
3538 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_STA_CONFIG (Burst=%d, Protection=%ld,ShortSlot=%d\n",
3539 pAdapter->CommonCfg.bEnableTxBurst,
3540 pAdapter->CommonCfg.UseBGProtection,
3541 pAdapter->CommonCfg.bUseShortSlotTime));
3542 }
3543 break;
3544 case OID_802_11_DESIRED_RATES:
3545 if (wrq->u.data.length != sizeof(NDIS_802_11_RATES))
3546 Status = -EINVAL;
3547 else
3548 {
3549 Status = copy_from_user(&aryRates, wrq->u.data.pointer, wrq->u.data.length);
3550 NdisZeroMemory(pAdapter->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES);
3551 NdisMoveMemory(pAdapter->CommonCfg.DesireRate, &aryRates, sizeof(NDIS_802_11_RATES));
3552 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DESIRED_RATES (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
3553 pAdapter->CommonCfg.DesireRate[0],pAdapter->CommonCfg.DesireRate[1],
3554 pAdapter->CommonCfg.DesireRate[2],pAdapter->CommonCfg.DesireRate[3],
3555 pAdapter->CommonCfg.DesireRate[4],pAdapter->CommonCfg.DesireRate[5],
3556 pAdapter->CommonCfg.DesireRate[6],pAdapter->CommonCfg.DesireRate[7] ));
3557 // Changing DesiredRate may affect the MAX TX rate we used to TX frames out
3558 MlmeUpdateTxRates(pAdapter, FALSE, 0);
3559 }
3560 break;
3561 case RT_OID_802_11_PREAMBLE:
3562 if (wrq->u.data.length != sizeof(RT_802_11_PREAMBLE))
3563 Status = -EINVAL;
3564 else
3565 {
3566 Status = copy_from_user(&Preamble, wrq->u.data.pointer, wrq->u.data.length);
3567 if (Preamble == Rt802_11PreambleShort)
3568 {
3569 pAdapter->CommonCfg.TxPreamble = Preamble;
3570 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleShort);
3571 }
3572 else if ((Preamble == Rt802_11PreambleLong) || (Preamble == Rt802_11PreambleAuto))
3573 {
3574 // if user wants AUTO, initialize to LONG here, then change according to AP's
3575 // capability upon association.
3576 pAdapter->CommonCfg.TxPreamble = Preamble;
3577 MlmeSetTxPreamble(pAdapter, Rt802_11PreambleLong);
3578 }
3579 else
3580 {
3581 Status = -EINVAL;
3582 break;
3583 }
3584 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_PREAMBLE (=%d)\n", Preamble));
3585 }
3586 break;
3587 case OID_802_11_WEP_STATUS:
3588 if (wrq->u.data.length != sizeof(NDIS_802_11_WEP_STATUS))
3589 Status = -EINVAL;
3590 else
3591 {
3592 Status = copy_from_user(&WepStatus, wrq->u.data.pointer, wrq->u.data.length);
3593 // Since TKIP, AES, WEP are all supported. It should not have any invalid setting
3594 if (WepStatus <= Ndis802_11Encryption3KeyAbsent)
3595 {
3596 if (pAdapter->StaCfg.WepStatus != WepStatus)
3597 {
3598 // Config has changed
3599 pAdapter->bConfigChanged = TRUE;
3600 }
3601 pAdapter->StaCfg.WepStatus = WepStatus;
3602 pAdapter->StaCfg.OrigWepStatus = WepStatus;
3603 pAdapter->StaCfg.PairCipher = WepStatus;
3604 pAdapter->StaCfg.GroupCipher = WepStatus;
3605 }
3606 else
3607 {
3608 Status = -EINVAL;
3609 break;
3610 }
3611 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_WEP_STATUS (=%d)\n",WepStatus));
3612 }
3613 break;
3614 case OID_802_11_AUTHENTICATION_MODE:
3615 if (wrq->u.data.length != sizeof(NDIS_802_11_AUTHENTICATION_MODE))
3616 Status = -EINVAL;
3617 else
3618 {
3619 Status = copy_from_user(&AuthMode, wrq->u.data.pointer, wrq->u.data.length);
3620 if (AuthMode > Ndis802_11AuthModeMax)
3621 {
3622 Status = -EINVAL;
3623 break;
3624 }
3625 else
3626 {
3627 if (pAdapter->StaCfg.AuthMode != AuthMode)
3628 {
3629 // Config has changed
3630 pAdapter->bConfigChanged = TRUE;
3631 }
3632 pAdapter->StaCfg.AuthMode = AuthMode;
3633 }
3634 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
3635 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_AUTHENTICATION_MODE (=%d) \n",pAdapter->StaCfg.AuthMode));
3636 }
3637 break;
3638 case OID_802_11_INFRASTRUCTURE_MODE:
3639 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_INFRASTRUCTURE))
3640 Status = -EINVAL;
3641 else
3642 {
3643 Status = copy_from_user(&BssType, wrq->u.data.pointer, wrq->u.data.length);
3644
3645 if (BssType == Ndis802_11IBSS)
3646 Set_NetworkType_Proc(pAdapter, "Adhoc");
3647 else if (BssType == Ndis802_11Infrastructure)
3648 Set_NetworkType_Proc(pAdapter, "Infra");
3649 else if (BssType == Ndis802_11Monitor)
3650 Set_NetworkType_Proc(pAdapter, "Monitor");
3651 else
3652 {
3653 Status = -EINVAL;
3654 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_INFRASTRUCTURE_MODE (unknown)\n"));
3655 }
3656 }
3657 break;
3658 case OID_802_11_REMOVE_WEP:
3659 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_WEP\n"));
3660 if (wrq->u.data.length != sizeof(NDIS_802_11_KEY_INDEX))
3661 {
3662 Status = -EINVAL;
3663 }
3664 else
3665 {
3666 KeyIdx = *(NDIS_802_11_KEY_INDEX *) wrq->u.data.pointer;
3667
3668 if (KeyIdx & 0x80000000)
3669 {
3670 // Should never set default bit when remove key
3671 Status = -EINVAL;
3672 }
3673 else
3674 {
3675 KeyIdx = KeyIdx & 0x0fffffff;
3676 if (KeyIdx >= 4){
3677 Status = -EINVAL;
3678 }
3679 else
3680 {
3681 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
3682 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
3683 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
3684 }
3685 }
3686 }
3687 break;
3688 case RT_OID_802_11_RESET_COUNTERS:
3689 NdisZeroMemory(&pAdapter->WlanCounters, sizeof(COUNTER_802_11));
3690 NdisZeroMemory(&pAdapter->Counters8023, sizeof(COUNTER_802_3));
3691 NdisZeroMemory(&pAdapter->RalinkCounters, sizeof(COUNTER_RALINK));
3692 pAdapter->Counters8023.RxNoBuffer = 0;
3693 pAdapter->Counters8023.GoodReceives = 0;
3694 pAdapter->Counters8023.RxNoBuffer = 0;
3a32ed12
BZ
3695#ifdef RT2870
3696 pAdapter->BulkOutComplete = 0;
3697 pAdapter->BulkOutCompleteOther= 0;
3698 pAdapter->BulkOutCompleteCancel = 0;
3699 pAdapter->BulkOutReq = 0;
3700 pAdapter->BulkInReq= 0;
3701 pAdapter->BulkInComplete = 0;
3702 pAdapter->BulkInCompleteFail = 0;
3703#endif // RT2870 //
91980990
GKH
3704 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_RESET_COUNTERS \n"));
3705 break;
3706 case OID_802_11_RTS_THRESHOLD:
3707 if (wrq->u.data.length != sizeof(NDIS_802_11_RTS_THRESHOLD))
3708 Status = -EINVAL;
3709 else
3710 {
3711 Status = copy_from_user(&RtsThresh, wrq->u.data.pointer, wrq->u.data.length);
3712 if (RtsThresh > MAX_RTS_THRESHOLD)
3713 Status = -EINVAL;
3714 else
3715 pAdapter->CommonCfg.RtsThreshold = (USHORT)RtsThresh;
3716 }
3717 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_RTS_THRESHOLD (=%ld)\n",RtsThresh));
3718 break;
3719 case OID_802_11_FRAGMENTATION_THRESHOLD:
3720 if (wrq->u.data.length != sizeof(NDIS_802_11_FRAGMENTATION_THRESHOLD))
3721 Status = -EINVAL;
3722 else
3723 {
3724 Status = copy_from_user(&FragThresh, wrq->u.data.pointer, wrq->u.data.length);
3725 pAdapter->CommonCfg.bUseZeroToDisableFragment = FALSE;
3726 if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
3727 {
3728 if (FragThresh == 0)
3729 {
3730 pAdapter->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
3731 pAdapter->CommonCfg.bUseZeroToDisableFragment = TRUE;
3732 }
3733 else
3734 Status = -EINVAL;
3735 }
3736 else
3737 pAdapter->CommonCfg.FragmentThreshold = (USHORT)FragThresh;
3738 }
3739 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_FRAGMENTATION_THRESHOLD (=%ld) \n",FragThresh));
3740 break;
3741 case OID_802_11_POWER_MODE:
3742 if (wrq->u.data.length != sizeof(NDIS_802_11_POWER_MODE))
3743 Status = -EINVAL;
3744 else
3745 {
3746 Status = copy_from_user(&PowerMode, wrq->u.data.pointer, wrq->u.data.length);
3747 if (PowerMode == Ndis802_11PowerModeCAM)
3748 Set_PSMode_Proc(pAdapter, "CAM");
3749 else if (PowerMode == Ndis802_11PowerModeMAX_PSP)
3750 Set_PSMode_Proc(pAdapter, "Max_PSP");
3751 else if (PowerMode == Ndis802_11PowerModeFast_PSP)
3752 Set_PSMode_Proc(pAdapter, "Fast_PSP");
3753 else if (PowerMode == Ndis802_11PowerModeLegacy_PSP)
3754 Set_PSMode_Proc(pAdapter, "Legacy_PSP");
3755 else
3756 Status = -EINVAL;
3757 }
3758 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_POWER_MODE (=%d)\n",PowerMode));
3759 break;
3760 case RT_OID_802_11_TX_POWER_LEVEL_1:
3761 if (wrq->u.data.length < sizeof(ULONG))
3762 Status = -EINVAL;
3763 else
3764 {
3765 Status = copy_from_user(&PowerTemp, wrq->u.data.pointer, wrq->u.data.length);
3766 if (PowerTemp > 100)
3767 PowerTemp = 0xffffffff; // AUTO
3768 pAdapter->CommonCfg.TxPowerDefault = PowerTemp; //keep current setting.
3769 pAdapter->CommonCfg.TxPowerPercentage = pAdapter->CommonCfg.TxPowerDefault;
3770 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
3771 }
3772 break;
3773 case OID_802_11_NETWORK_TYPE_IN_USE:
3774 if (wrq->u.data.length != sizeof(NDIS_802_11_NETWORK_TYPE))
3775 Status = -EINVAL;
3776 else
3777 {
3778 Status = copy_from_user(&NetType, wrq->u.data.pointer, wrq->u.data.length);
3779
3780 if (NetType == Ndis802_11DS)
3781 RTMPSetPhyMode(pAdapter, PHY_11B);
3782 else if (NetType == Ndis802_11OFDM24)
3783 RTMPSetPhyMode(pAdapter, PHY_11BG_MIXED);
3784 else if (NetType == Ndis802_11OFDM5)
3785 RTMPSetPhyMode(pAdapter, PHY_11A);
3786 else
3787 Status = -EINVAL;
1623267a 3788
91980990
GKH
3789 if (Status == NDIS_STATUS_SUCCESS)
3790 SetCommonHT(pAdapter);
1623267a 3791
91980990
GKH
3792 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_NETWORK_TYPE_IN_USE (=%d)\n",NetType));
3793 }
3794 break;
3795 // For WPA PSK PMK key
3796 case RT_OID_802_11_ADD_WPA:
3797 pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3798 if(pKey == NULL)
3799 {
3800 Status = -ENOMEM;
3801 break;
3802 }
3803
3804 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
3805 if (pKey->Length != wrq->u.data.length)
3806 {
3807 Status = -EINVAL;
3808 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!!\n"));
3809 }
3810 else
3811 {
3812 if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
3813 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
3814 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone) )
3815 {
3816 Status = -EOPNOTSUPP;
3817 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA, Failed!! [AuthMode != WPAPSK/WPA2PSK/WPANONE]\n"));
3818 }
3819 else if ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
3820 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
3821 (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) ) // Only for WPA PSK mode
3822 {
3823 NdisMoveMemory(pAdapter->StaCfg.PMK, &pKey->KeyMaterial, pKey->KeyLength);
3824 // Use RaConfig as PSK agent.
3825 // Start STA supplicant state machine
3826 if (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
3827 pAdapter->StaCfg.WpaState = SS_START;
3828
3829 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3830 }
3831 else
3832 {
3833 pAdapter->StaCfg.WpaState = SS_NOTUSE;
3834 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_WPA (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3835 }
3836 }
3837 kfree(pKey);
3838 break;
3839 case OID_802_11_REMOVE_KEY:
3840 pRemoveKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3841 if(pRemoveKey == NULL)
3842 {
3843 Status = -ENOMEM;
3844 break;
3845 }
3846
3847 Status = copy_from_user(pRemoveKey, wrq->u.data.pointer, wrq->u.data.length);
3848 if (pRemoveKey->Length != wrq->u.data.length)
3849 {
3850 Status = -EINVAL;
3851 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!\n"));
3852 }
3853 else
3854 {
3855 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
3856 {
3857 RTMPWPARemoveKeyProc(pAdapter, pRemoveKey);
3858 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Remove WPA Key!!\n"));
3859 }
3860 else
3861 {
3862 KeyIdx = pRemoveKey->KeyIndex;
3863
3864 if (KeyIdx & 0x80000000)
3865 {
3866 // Should never set default bit when remove key
3867 Status = -EINVAL;
3868 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(Should never set default bit when remove key)\n"));
3869 }
3870 else
3871 {
3872 KeyIdx = KeyIdx & 0x0fffffff;
3873 if (KeyIdx > 3)
3874 {
3875 Status = -EINVAL;
3876 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY, Failed!!(KeyId[%d] out of range)\n", KeyIdx));
3877 }
3878 else
3879 {
3880 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = 0;
3881 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
3882 AsicRemoveSharedKeyEntry(pAdapter, 0, (UCHAR)KeyIdx);
3883 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_REMOVE_KEY (id=0x%x, Len=%d-byte)\n", pRemoveKey->KeyIndex, pRemoveKey->Length));
3884 }
3885 }
3886 }
3887 }
3888 kfree(pRemoveKey);
3889 break;
3890 // New for WPA
3891 case OID_802_11_ADD_KEY:
3892 pKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
3893 if(pKey == NULL)
3894 {
3895 Status = -ENOMEM;
3896 break;
3897 }
3898 Status = copy_from_user(pKey, wrq->u.data.pointer, wrq->u.data.length);
3899 if (pKey->Length != wrq->u.data.length)
3900 {
3901 Status = -EINVAL;
3902 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY, Failed!!\n"));
3903 }
3904 else
3905 {
3906 RTMPAddKey(pAdapter, pKey);
3907 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_KEY (id=0x%x, Len=%d-byte)\n", pKey->KeyIndex, pKey->KeyLength));
3908 }
3909 kfree(pKey);
3910 break;
3911 case OID_802_11_CONFIGURATION:
3912 if (wrq->u.data.length != sizeof(NDIS_802_11_CONFIGURATION))
3913 Status = -EINVAL;
3914 else
3915 {
3916 Status = copy_from_user(&Config, wrq->u.data.pointer, wrq->u.data.length);
3917 pConfig = &Config;
3918
3919 if ((pConfig->BeaconPeriod >= 20) && (pConfig->BeaconPeriod <=400))
3920 pAdapter->CommonCfg.BeaconPeriod = (USHORT) pConfig->BeaconPeriod;
3921
3922 pAdapter->StaActive.AtimWin = (USHORT) pConfig->ATIMWindow;
3923 MAP_KHZ_TO_CHANNEL_ID(pConfig->DSConfig, pAdapter->CommonCfg.Channel);
3924 //
3925 // Save the channel on MlmeAux for CntlOidRTBssidProc used.
3926 //
3927 pAdapter->MlmeAux.Channel = pAdapter->CommonCfg.Channel;
3928
3929 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_CONFIGURATION (BeacnPeriod=%ld,AtimW=%ld,Ch=%d)\n",
3930 pConfig->BeaconPeriod, pConfig->ATIMWindow, pAdapter->CommonCfg.Channel));
3931 // Config has changed
3932 pAdapter->bConfigChanged = TRUE;
3933 }
3934 break;
91980990
GKH
3935 case RT_OID_802_11_SET_HT_PHYMODE:
3936 if (wrq->u.data.length != sizeof(OID_SET_HT_PHYMODE))
3937 Status = -EINVAL;
3938 else
3939 {
3940 POID_SET_HT_PHYMODE pHTPhyMode = &HT_PhyMode;
3941
3942 Status = copy_from_user(&HT_PhyMode, wrq->u.data.pointer, wrq->u.data.length);
3943 DBGPRINT(RT_DEBUG_TRACE, ("Set::pHTPhyMode (PhyMode = %d,TransmitNo = %d, HtMode = %d, ExtOffset = %d , MCS = %d, BW = %d, STBC = %d, SHORTGI = %d) \n",
3944 pHTPhyMode->PhyMode, pHTPhyMode->TransmitNo,pHTPhyMode->HtMode,pHTPhyMode->ExtOffset,
3945 pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->SHORTGI));
3946 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
3947 RTMPSetHT(pAdapter, pHTPhyMode);
3948 }
3949 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_HT_PHYMODE(MCS=%d,BW=%d,SGI=%d,STBC=%d)\n",
3950 pAdapter->StaCfg.HTPhyMode.field.MCS, pAdapter->StaCfg.HTPhyMode.field.BW, pAdapter->StaCfg.HTPhyMode.field.ShortGI,
3951 pAdapter->StaCfg.HTPhyMode.field.STBC));
3952 break;
91980990
GKH
3953 case RT_OID_802_11_SET_APSD_SETTING:
3954 if (wrq->u.data.length != sizeof(ULONG))
3955 Status = -EINVAL;
3956 else
3957 {
3958 ULONG apsd ;
3959 Status = copy_from_user(&apsd, wrq->u.data.pointer, wrq->u.data.length);
3960
3961 /*-------------------------------------------------------------------
3962 |B31~B7 | B6~B5 | B4 | B3 | B2 | B1 | B0 |
3963 ---------------------------------------------------------------------
3964 | Rsvd | Max SP Len | AC_VO | AC_VI | AC_BK | AC_BE | APSD Capable |
3965 ---------------------------------------------------------------------*/
3966 pAdapter->CommonCfg.bAPSDCapable = (apsd & 0x00000001) ? TRUE : FALSE;
3967 pAdapter->CommonCfg.bAPSDAC_BE = ((apsd & 0x00000002) >> 1) ? TRUE : FALSE;
3968 pAdapter->CommonCfg.bAPSDAC_BK = ((apsd & 0x00000004) >> 2) ? TRUE : FALSE;
3969 pAdapter->CommonCfg.bAPSDAC_VI = ((apsd & 0x00000008) >> 3) ? TRUE : FALSE;
3970 pAdapter->CommonCfg.bAPSDAC_VO = ((apsd & 0x00000010) >> 4) ? TRUE : FALSE;
3971 pAdapter->CommonCfg.MaxSPLength = (UCHAR)((apsd & 0x00000060) >> 5);
3972
3973 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,
3974 pAdapter->CommonCfg.bAPSDAC_BE, pAdapter->CommonCfg.bAPSDAC_BK, pAdapter->CommonCfg.bAPSDAC_VI, pAdapter->CommonCfg.bAPSDAC_VO, pAdapter->CommonCfg.MaxSPLength));
3975 }
3976 break;
3977
3978 case RT_OID_802_11_SET_APSD_PSM:
3979 if (wrq->u.data.length != sizeof(ULONG))
3980 Status = -EINVAL;
3981 else
3982 {
3983 // Driver needs to notify AP when PSM changes
3984 Status = copy_from_user(&pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.pointer, wrq->u.data.length);
3985 if (pAdapter->CommonCfg.bAPSDForcePowerSave != pAdapter->StaCfg.Psm)
3986 {
3987 MlmeSetPsmBit(pAdapter, pAdapter->CommonCfg.bAPSDForcePowerSave);
3988 RTMPSendNullFrame(pAdapter, pAdapter->CommonCfg.TxRate, TRUE);
3989 }
3990 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_APSD_PSM (bAPSDForcePowerSave:%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
3991 }
3992 break;
91980990 3993
91980990
GKH
3994 case RT_OID_802_11_SET_WMM:
3995 if (wrq->u.data.length != sizeof(BOOLEAN))
3996 Status = -EINVAL;
3997 else
3998 {
3999 Status = copy_from_user(&pAdapter->CommonCfg.bWmmCapable, wrq->u.data.pointer, wrq->u.data.length);
4000 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_SET_WMM (=%d) \n", pAdapter->CommonCfg.bWmmCapable));
4001 }
4002 break;
4003
4004 case OID_802_11_DISASSOCIATE:
91980990
GKH
4005 //
4006 // Set NdisRadioStateOff to TRUE, instead of called MlmeRadioOff.
4007 // Later on, NDIS_802_11_BSSID_LIST_EX->NumberOfItems should be 0
4008 // when query OID_802_11_BSSID_LIST.
4009 //
4010 // TRUE: NumberOfItems will set to 0.
4011 // FALSE: NumberOfItems no change.
4012 //
4013 pAdapter->CommonCfg.NdisRadioStateOff = TRUE;
4014 // Set to immediately send the media disconnect event
4015 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
4016 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DISASSOCIATE \n"));
4017
4018 if (INFRA_ON(pAdapter))
4019 {
4020 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
4021 {
4022 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
4023 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
4024 }
4025
4026 MlmeEnqueue(pAdapter,
4027 MLME_CNTL_STATE_MACHINE,
4028 OID_802_11_DISASSOCIATE,
4029 0,
4030 NULL);
4031
4032 StateMachineTouched = TRUE;
4033 }
4034 break;
91980990
GKH
4035 case RT_OID_802_11_SET_IMME_BA_CAP:
4036 if (wrq->u.data.length != sizeof(OID_BACAP_STRUC))
4037 Status = -EINVAL;
4038 else
4039 {
4040 OID_BACAP_STRUC Orde ;
4041 Status = copy_from_user(&Orde, wrq->u.data.pointer, wrq->u.data.length);
4042 if (Orde.Policy > BA_NOTUSE)
4043 {
4044 Status = NDIS_STATUS_INVALID_DATA;
4045 }
4046 else if (Orde.Policy == BA_NOTUSE)
4047 {
4048 pAdapter->CommonCfg.BACapability.field.Policy = BA_NOTUSE;
4049 pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
4050 pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
4051 pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
4052 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
4053 pAdapter->CommonCfg.DesiredHtPhy.MimoPs= Orde.MMPSmode;
4054 pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
4055 // UPdata to HT IE
4056 pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
4057 pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
4058 pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
4059 }
4060 else
4061 {
4062 pAdapter->CommonCfg.BACapability.field.AutoBA = Orde.AutoBA;
4063 pAdapter->CommonCfg.BACapability.field.Policy = IMMED_BA; // we only support immediate BA.
4064 pAdapter->CommonCfg.BACapability.field.MpduDensity = Orde.MpduDensity;
4065 pAdapter->CommonCfg.DesiredHtPhy.MpduDensity = Orde.MpduDensity;
4066 pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable = Orde.AmsduEnable;
4067 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize= Orde.AmsduSize;
4068 pAdapter->CommonCfg.DesiredHtPhy.MimoPs = Orde.MMPSmode;
4069 pAdapter->CommonCfg.BACapability.field.MMPSmode = Orde.MMPSmode;
4070
4071 // UPdata to HT IE
4072 pAdapter->CommonCfg.HtCapability.HtCapInfo.MimoPs = Orde.MMPSmode;
4073 pAdapter->CommonCfg.HtCapability.HtCapInfo.AMsduSize = Orde.AmsduSize;
4074 pAdapter->CommonCfg.HtCapability.HtCapParm.MpduDensity = Orde.MpduDensity;
4075
4076 if (pAdapter->CommonCfg.BACapability.field.RxBAWinLimit > MAX_RX_REORDERBUF)
4077 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = MAX_RX_REORDERBUF;
4078
4079 }
4080
4081 pAdapter->CommonCfg.REGBACapability.word = pAdapter->CommonCfg.BACapability.word;
4082 DBGPRINT(RT_DEBUG_TRACE, ("Set::(Orde.AutoBA = %d) (Policy=%d)(ReBAWinLimit=%d)(TxBAWinLimit=%d)(AutoMode=%d)\n",Orde.AutoBA, pAdapter->CommonCfg.BACapability.field.Policy,
4083 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit,pAdapter->CommonCfg.BACapability.field.TxBAWinLimit, pAdapter->CommonCfg.BACapability.field.AutoBA));
4084 DBGPRINT(RT_DEBUG_TRACE, ("Set::(MimoPs = %d)(AmsduEnable = %d) (AmsduSize=%d)(MpduDensity=%d)\n",pAdapter->CommonCfg.DesiredHtPhy.MimoPs, pAdapter->CommonCfg.DesiredHtPhy.AmsduEnable,
4085 pAdapter->CommonCfg.DesiredHtPhy.AmsduSize, pAdapter->CommonCfg.DesiredHtPhy.MpduDensity));
4086 }
4087
4088 break;
4089 case RT_OID_802_11_ADD_IMME_BA:
4090 DBGPRINT(RT_DEBUG_TRACE, (" Set :: RT_OID_802_11_ADD_IMME_BA \n"));
4091 if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
4092 Status = -EINVAL;
4093 else
4094 {
4095 UCHAR index;
4096 OID_ADD_BA_ENTRY BA;
4097 MAC_TABLE_ENTRY *pEntry;
4098
4099 Status = copy_from_user(&BA, wrq->u.data.pointer, wrq->u.data.length);
4100 if (BA.TID > 15)
4101 {
4102 Status = NDIS_STATUS_INVALID_DATA;
4103 break;
4104 }
4105 else
4106 {
4107 //BATableInsertEntry
4108 //As ad-hoc mode, BA pair is not limited to only BSSID. so add via OID.
4109 index = BA.TID;
4110 // in ad hoc mode, when adding BA pair, we should insert this entry into MACEntry too
4111 pEntry = MacTableLookup(pAdapter, BA.MACAddr);
4112 if (!pEntry)
4113 {
4114 DBGPRINT(RT_DEBUG_TRACE, ("RT_OID_802_11_ADD_IMME_BA. break on no connection.----:%x:%x\n", BA.MACAddr[4], BA.MACAddr[5]));
4115 break;
4116 }
4117 if (BA.IsRecipient == FALSE)
4118 {
4119 if (pEntry->bIAmBadAtheros == TRUE)
4120 pAdapter->CommonCfg.BACapability.field.RxBAWinLimit = 0x10;
4121
4122 BAOriSessionSetUp(pAdapter, pEntry, index, 0, 100, TRUE);
4123 }
4124 else
4125 {
4126 //BATableInsertEntry(pAdapter, pEntry->Aid, BA.MACAddr, 0, 0xffff, BA.TID, BA.nMSDU, BA.IsRecipient);
4127 }
4128
4129 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_802_11_ADD_IMME_BA. Rec = %d. Mac = %x:%x:%x:%x:%x:%x . \n",
4130 BA.IsRecipient, BA.MACAddr[0], BA.MACAddr[1], BA.MACAddr[2], BA.MACAddr[2]
4131 , BA.MACAddr[4], BA.MACAddr[5]));
4132 }
4133 }
4134 break;
4135
4136 case RT_OID_802_11_TEAR_IMME_BA:
4137 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA \n"));
4138 if (wrq->u.data.length != sizeof(OID_ADD_BA_ENTRY))
4139 Status = -EINVAL;
4140 else
4141 {
4142 POID_ADD_BA_ENTRY pBA;
4143 MAC_TABLE_ENTRY *pEntry;
4144
4145 pBA = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4146
4147 if (pBA == NULL)
4148 {
4149 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA kmalloc() can't allocate enough memory\n"));
4150 Status = NDIS_STATUS_FAILURE;
4151 }
4152 else
4153 {
4154 Status = copy_from_user(pBA, wrq->u.data.pointer, wrq->u.data.length);
4155 DBGPRINT(RT_DEBUG_TRACE, ("Set :: RT_OID_802_11_TEAR_IMME_BA(TID=%d, bAllTid=%d)\n", pBA->TID, pBA->bAllTid));
4156
4157 if (!pBA->bAllTid && (pBA->TID > NUM_OF_TID))
4158 {
4159 Status = NDIS_STATUS_INVALID_DATA;
4160 break;
4161 }
4162
4163 if (pBA->IsRecipient == FALSE)
4164 {
4165 pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
4166 DBGPRINT(RT_DEBUG_TRACE, (" pBA->IsRecipient == FALSE\n"));
4167 if (pEntry)
4168 {
4169 DBGPRINT(RT_DEBUG_TRACE, (" pBA->pEntry\n"));
4170 BAOriSessionTearDown(pAdapter, pEntry->Aid, pBA->TID, FALSE, TRUE);
4171 }
4172 else
4173 DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
4174 }
4175 else
4176 {
4177 pEntry = MacTableLookup(pAdapter, pBA->MACAddr);
4178 if (pEntry)
4179 {
4180 BARecSessionTearDown( pAdapter, (UCHAR)pEntry->Aid, pBA->TID, TRUE);
4181 }
4182 else
4183 DBGPRINT(RT_DEBUG_TRACE, ("Set :: Not found pEntry \n"));
4184 }
4185 kfree(pBA);
4186 }
4187 }
4188 break;
91980990
GKH
4189 // For WPA_SUPPLICANT to set static wep key
4190 case OID_802_11_ADD_WEP:
4191 pWepKey = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4192
4193 if(pWepKey == NULL)
4194 {
4195 Status = -ENOMEM;
4196 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed!!\n"));
4197 break;
4198 }
4199 Status = copy_from_user(pWepKey, wrq->u.data.pointer, wrq->u.data.length);
4200 if (Status)
4201 {
4202 Status = -EINVAL;
4203 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (length mismatch)!!\n"));
4204 }
4205 else
4206 {
4207 KeyIdx = pWepKey->KeyIndex & 0x0fffffff;
4208 // KeyIdx must be 0 ~ 3
4209 if (KeyIdx > 4)
4210 {
4211 Status = -EINVAL;
4212 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, Failed (KeyIdx must be smaller than 4)!!\n"));
4213 }
4214 else
4215 {
4216 UCHAR CipherAlg = 0;
4217 PUCHAR Key;
4218
4219 // set key material and key length
4220 NdisZeroMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, 16);
4221 pAdapter->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
4222 NdisMoveMemory(pAdapter->SharedKey[BSS0][KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
4223
4224 switch(pWepKey->KeyLength)
4225 {
4226 case 5:
4227 CipherAlg = CIPHER_WEP64;
4228 break;
4229 case 13:
4230 CipherAlg = CIPHER_WEP128;
4231 break;
4232 default:
4233 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_ADD_WEP, only support CIPHER_WEP64(len:5) & CIPHER_WEP128(len:13)!!\n"));
4234 Status = -EINVAL;
4235 break;
4236 }
4237 pAdapter->SharedKey[BSS0][KeyIdx].CipherAlg = CipherAlg;
4238
4239 // Default key for tx (shared key)
4240 if (pWepKey->KeyIndex & 0x80000000)
4241 {
91980990
GKH
4242 // set key material and key length
4243 NdisZeroMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, 16);
4244 pAdapter->StaCfg.DesireSharedKey[KeyIdx].KeyLen = (UCHAR) pWepKey->KeyLength;
4245 NdisMoveMemory(pAdapter->StaCfg.DesireSharedKey[KeyIdx].Key, &pWepKey->KeyMaterial, pWepKey->KeyLength);
4246 pAdapter->StaCfg.DesireSharedKeyId = KeyIdx;
4247 pAdapter->StaCfg.DesireSharedKey[KeyIdx].CipherAlg = CipherAlg;
91980990
GKH
4248 pAdapter->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;
4249 }
3a32ed12
BZ
4250#ifndef RT30xx
4251#ifdef RT2860
ed291e80 4252 if ((pAdapter->StaCfg.WpaSupplicantUP != 0) &&
3a32ed12
BZ
4253#endif
4254#ifdef RT2870
4255 if ((pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE) &&
4256#endif
ed291e80
AM
4257 (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA))
4258 {
4259 Key = pWepKey->KeyMaterial;
4260
4261 // Set Group key material to Asic
4262 AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
4263
4264 // Update WCID attribute table and IVEIV table for this group key table
4265 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
4266
4267 STA_PORT_SECURED(pAdapter);
4268
4269 // Indicate Connected for GUI
4270 pAdapter->IndicateMediaState = NdisMediaStateConnected;
4271 }
4272 else if (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)
3a32ed12
BZ
4273#endif
4274#ifdef RT30xx
4275 if (pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)
4276#endif
91980990
GKH
4277 {
4278 Key = pAdapter->SharedKey[BSS0][KeyIdx].Key;
4279
4280 // Set key material and cipherAlg to Asic
4281 AsicAddSharedKeyEntry(pAdapter, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);
4282
4283 if (pWepKey->KeyIndex & 0x80000000)
4284 {
4285 PMAC_TABLE_ENTRY pEntry = &pAdapter->MacTab.Content[BSSID_WCID];
4286 // Assign group key info
4287 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, NULL);
4288 // Assign pairwise key info
4289 RTMPAddWcidAttributeEntry(pAdapter, BSS0, KeyIdx, CipherAlg, pEntry);
4290 }
4291 }
4292 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"));
4293 }
4294 }
4295 kfree(pWepKey);
4296 break;
91980990
GKH
4297 case OID_SET_COUNTERMEASURES:
4298 if (wrq->u.data.length != sizeof(int))
4299 Status = -EINVAL;
4300 else
4301 {
4302 int enabled = 0;
4303 Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
4304 if (enabled == 1)
4305 pAdapter->StaCfg.bBlockAssoc = TRUE;
4306 else
4307 // WPA MIC error should block association attempt for 60 seconds
4308 pAdapter->StaCfg.bBlockAssoc = FALSE;
4309 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_SET_COUNTERMEASURES bBlockAssoc=%s\n", pAdapter->StaCfg.bBlockAssoc ? "TRUE":"FALSE"));
4310 }
4311 break;
4312 case RT_OID_WPA_SUPPLICANT_SUPPORT:
4313 if (wrq->u.data.length != sizeof(UCHAR))
4314 Status = -EINVAL;
4315 else
4316 {
4317 Status = copy_from_user(&wpa_supplicant_enable, wrq->u.data.pointer, wrq->u.data.length);
4318 pAdapter->StaCfg.WpaSupplicantUP = wpa_supplicant_enable;
4319 DBGPRINT(RT_DEBUG_TRACE, ("Set::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
4320 }
4321 break;
4322 case OID_802_11_DEAUTHENTICATION:
4323 if (wrq->u.data.length != sizeof(MLME_DEAUTH_REQ_STRUCT))
4324 Status = -EINVAL;
4325 else
4326 {
4327 MLME_DEAUTH_REQ_STRUCT *pInfo;
4328 MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
4329
4330 pInfo = (MLME_DEAUTH_REQ_STRUCT *) MsgElem->Msg;
4331 Status = copy_from_user(pInfo, wrq->u.data.pointer, wrq->u.data.length);
4332 MlmeDeauthReqAction(pAdapter, MsgElem);
4333 kfree(MsgElem);
4334
4335 if (INFRA_ON(pAdapter))
4336 {
4337 LinkDown(pAdapter, FALSE);
4338 pAdapter->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
4339 }
4340 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DEAUTHENTICATION (Reason=%d)\n", pInfo->Reason));
4341 }
4342 break;
4343 case OID_802_11_DROP_UNENCRYPTED:
4344 if (wrq->u.data.length != sizeof(int))
4345 Status = -EINVAL;
4346 else
4347 {
4348 int enabled = 0;
4349 Status = copy_from_user(&enabled, wrq->u.data.pointer, wrq->u.data.length);
4350 if (enabled == 1)
4351 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
4352 else
4353 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
4354 NdisAcquireSpinLock(&pAdapter->MacTabLock);
4355 pAdapter->MacTab.Content[BSSID_WCID].PortSecured = pAdapter->StaCfg.PortSecured;
4356 NdisReleaseSpinLock(&pAdapter->MacTabLock);
4357 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_DROP_UNENCRYPTED (=%d)\n", enabled));
4358 }
4359 break;
4360 case OID_802_11_SET_IEEE8021X:
4361 if (wrq->u.data.length != sizeof(BOOLEAN))
4362 Status = -EINVAL;
4363 else
4364 {
4365 Status = copy_from_user(&IEEE8021xState, wrq->u.data.pointer, wrq->u.data.length);
4366 pAdapter->StaCfg.IEEE8021X = IEEE8021xState;
4367 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X (=%d)\n", IEEE8021xState));
4368 }
4369 break;
4370 case OID_802_11_SET_IEEE8021X_REQUIRE_KEY:
4371 if (wrq->u.data.length != sizeof(BOOLEAN))
4372 Status = -EINVAL;
4373 else
4374 {
4375 Status = copy_from_user(&IEEE8021x_required_keys, wrq->u.data.pointer, wrq->u.data.length);
4376 pAdapter->StaCfg.IEEE8021x_required_keys = IEEE8021x_required_keys;
4377 DBGPRINT(RT_DEBUG_TRACE, ("Set::OID_802_11_SET_IEEE8021X_REQUIRE_KEY (%d)\n", IEEE8021x_required_keys));
4378 }
4379 break;
4380 case OID_802_11_PMKID:
4381 pPmkId = kmalloc(wrq->u.data.length, MEM_ALLOC_FLAG);
4382
4383 if(pPmkId == NULL) {
4384 Status = -ENOMEM;
4385 break;
4386 }
4387 Status = copy_from_user(pPmkId, wrq->u.data.pointer, wrq->u.data.length);
4388
4389 // check the PMKID information
4390 if (pPmkId->BSSIDInfoCount == 0)
4391 NdisZeroMemory(pAdapter->StaCfg.SavedPMK, sizeof(BSSID_INFO)*PMKID_NO);
4392 else
4393 {
4394 PBSSID_INFO pBssIdInfo;
4395 UINT BssIdx;
4396 UINT CachedIdx;
4397
4398 for (BssIdx = 0; BssIdx < pPmkId->BSSIDInfoCount; BssIdx++)
4399 {
4400 // point to the indexed BSSID_INFO structure
4401 pBssIdInfo = (PBSSID_INFO) ((PUCHAR) pPmkId + 2 * sizeof(UINT) + BssIdx * sizeof(BSSID_INFO));
4402 // Find the entry in the saved data base.
4403 for (CachedIdx = 0; CachedIdx < pAdapter->StaCfg.SavedPMKNum; CachedIdx++)
4404 {
4405 // compare the BSSID
4406 if (NdisEqualMemory(pBssIdInfo->BSSID, pAdapter->StaCfg.SavedPMK[CachedIdx].BSSID, sizeof(NDIS_802_11_MAC_ADDRESS)))
4407 break;
4408 }
4409
4410 // Found, replace it
4411 if (CachedIdx < PMKID_NO)
4412 {
4413 DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
4414 NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
4415 pAdapter->StaCfg.SavedPMKNum++;
4416 }
4417 // Not found, replace the last one
4418 else
4419 {
4420 // Randomly replace one
4421 CachedIdx = (pBssIdInfo->BSSID[5] % PMKID_NO);
4422 DBGPRINT(RT_DEBUG_OFF, ("Update OID_802_11_PMKID, idx = %d\n", CachedIdx));
4423 NdisMoveMemory(&pAdapter->StaCfg.SavedPMK[CachedIdx], pBssIdInfo, sizeof(BSSID_INFO));
4424 }
4425 }
4426 }
4427 if(pPmkId)
4428 kfree(pPmkId);
4429 break;
91980990
GKH
4430 default:
4431 DBGPRINT(RT_DEBUG_TRACE, ("Set::unknown IOCTL's subcmd = 0x%08x\n", cmd));
4432 Status = -EOPNOTSUPP;
4433 break;
4434 }
4435
4436
4437 return Status;
4438}
4439
4440INT RTMPQueryInformation(
4441 IN PRTMP_ADAPTER pAdapter,
4442 IN OUT struct ifreq *rq,
4443 IN INT cmd)
4444{
4445 struct iwreq *wrq = (struct iwreq *) rq;
4446 NDIS_802_11_BSSID_LIST_EX *pBssidList = NULL;
4447 PNDIS_WLAN_BSSID_EX pBss;
4448 NDIS_802_11_SSID Ssid;
4449 NDIS_802_11_CONFIGURATION *pConfiguration = NULL;
4450 RT_802_11_LINK_STATUS *pLinkStatus = NULL;
4451 RT_802_11_STA_CONFIG *pStaConfig = NULL;
4452 NDIS_802_11_STATISTICS *pStatistics = NULL;
4453 NDIS_802_11_RTS_THRESHOLD RtsThresh;
4454 NDIS_802_11_FRAGMENTATION_THRESHOLD FragThresh;
4455 NDIS_802_11_POWER_MODE PowerMode;
4456 NDIS_802_11_NETWORK_INFRASTRUCTURE BssType;
4457 RT_802_11_PREAMBLE PreamType;
4458 NDIS_802_11_AUTHENTICATION_MODE AuthMode;
4459 NDIS_802_11_WEP_STATUS WepStatus;
4460 NDIS_MEDIA_STATE MediaState;
4461 ULONG BssBufSize, ulInfo=0, NetworkTypeList[4], apsd = 0;
4462 USHORT BssLen = 0;
4463 PUCHAR pBuf = NULL, pPtr;
4464 INT Status = NDIS_STATUS_SUCCESS;
4465 UINT we_version_compiled;
4466 UCHAR i, Padding = 0;
4467 BOOLEAN RadioState;
4468 UCHAR driverVersion[8];
4469 OID_SET_HT_PHYMODE *pHTPhyMode = NULL;
4470
91980990
GKH
4471 switch(cmd)
4472 {
4473 case RT_OID_DEVICE_NAME:
4474 wrq->u.data.length = sizeof(STA_NIC_DEVICE_NAME);
4475 Status = copy_to_user(wrq->u.data.pointer, STA_NIC_DEVICE_NAME, wrq->u.data.length);
4476 break;
4477 case RT_OID_VERSION_INFO:
4478 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_VERSION_INFO \n"));
4479 wrq->u.data.length = 8*sizeof(UCHAR);
4480 sprintf(&driverVersion[0], "%s", STA_DRIVER_VERSION);
4481 driverVersion[7] = '\0';
4482 if (copy_to_user(wrq->u.data.pointer, &driverVersion, wrq->u.data.length))
4483 {
4484 Status = -EFAULT;
4485 }
4486 break;
91980990
GKH
4487 case OID_802_11_BSSID_LIST:
4488 if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
4489 {
4490 /*
4491 * Still scanning, indicate the caller should try again.
4492 */
4493 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (Still scanning)\n"));
4494 return -EAGAIN;
4495 }
4496 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID_LIST (%d BSS returned)\n",pAdapter->ScanTab.BssNr));
4497 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
4498 // Claculate total buffer size required
4499 BssBufSize = sizeof(ULONG);
4500
4501 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
4502 {
4503 // Align pointer to 4 bytes boundary.
4504 //Padding = 4 - (pAdapter->ScanTab.BssEntry[i].VarIELen & 0x0003);
4505 //if (Padding == 4)
4506 // Padding = 0;
4507 BssBufSize += (sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
4508 }
4509
4510 // For safety issue, we add 256 bytes just in case
4511 BssBufSize += 256;
4512 // Allocate the same size as passed from higher layer
4513 pBuf = kmalloc(BssBufSize, MEM_ALLOC_FLAG);
4514 if(pBuf == NULL)
4515 {
4516 Status = -ENOMEM;
4517 break;
4518 }
4519 // Init 802_11_BSSID_LIST_EX structure
4520 NdisZeroMemory(pBuf, BssBufSize);
4521 pBssidList = (PNDIS_802_11_BSSID_LIST_EX) pBuf;
4522 pBssidList->NumberOfItems = pAdapter->ScanTab.BssNr;
4523
4524 // Calculate total buffer length
4525 BssLen = 4; // Consist of NumberOfItems
4526 // Point to start of NDIS_WLAN_BSSID_EX
4527 // pPtr = pBuf + sizeof(ULONG);
4528 pPtr = (PUCHAR) &pBssidList->Bssid[0];
4529 for (i = 0; i < pAdapter->ScanTab.BssNr; i++)
4530 {
4531 pBss = (PNDIS_WLAN_BSSID_EX) pPtr;
4532 NdisMoveMemory(&pBss->MacAddress, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);
4533 if ((pAdapter->ScanTab.BssEntry[i].Hidden == 1) && (pAdapter->StaCfg.bShowHiddenSSID == FALSE))
4534 {
4535 //
4536 // We must return this SSID during 4way handshaking, otherwise Aegis will failed to parse WPA infomation
4537 // and then failed to send EAPOl farame.
4538 //
4539 if ((pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) && (pAdapter->StaCfg.PortSecured != WPA_802_1X_PORT_SECURED))
4540 {
4541 pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
4542 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
4543 }
4544 else
4545 pBss->Ssid.SsidLength = 0;
4546 }
4547 else
4548 {
4549 pBss->Ssid.SsidLength = pAdapter->ScanTab.BssEntry[i].SsidLen;
4550 NdisMoveMemory(pBss->Ssid.Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
4551 }
4552 pBss->Privacy = pAdapter->ScanTab.BssEntry[i].Privacy;
4553 pBss->Rssi = pAdapter->ScanTab.BssEntry[i].Rssi - pAdapter->BbpRssiToDbmDelta;
4554 pBss->NetworkTypeInUse = NetworkTypeInUseSanity(&pAdapter->ScanTab.BssEntry[i]);
4555 pBss->Configuration.Length = sizeof(NDIS_802_11_CONFIGURATION);
4556 pBss->Configuration.BeaconPeriod = pAdapter->ScanTab.BssEntry[i].BeaconPeriod;
4557 pBss->Configuration.ATIMWindow = pAdapter->ScanTab.BssEntry[i].AtimWin;
4558
4559 MAP_CHANNEL_ID_TO_KHZ(pAdapter->ScanTab.BssEntry[i].Channel, pBss->Configuration.DSConfig);
4560
4561 if (pAdapter->ScanTab.BssEntry[i].BssType == BSS_INFRA)
4562 pBss->InfrastructureMode = Ndis802_11Infrastructure;
4563 else
4564 pBss->InfrastructureMode = Ndis802_11IBSS;
4565
4566 NdisMoveMemory(pBss->SupportedRates, pAdapter->ScanTab.BssEntry[i].SupRate, pAdapter->ScanTab.BssEntry[i].SupRateLen);
4567 NdisMoveMemory(pBss->SupportedRates + pAdapter->ScanTab.BssEntry[i].SupRateLen,
4568 pAdapter->ScanTab.BssEntry[i].ExtRate,
4569 pAdapter->ScanTab.BssEntry[i].ExtRateLen);
4570
4571 if (pAdapter->ScanTab.BssEntry[i].VarIELen == 0)
4572 {
4573 pBss->IELength = sizeof(NDIS_802_11_FIXED_IEs);
4574 NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
4575 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
4576 }
4577 else
4578 {
4579 pBss->IELength = (ULONG)(sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen);
4580 pPtr = pPtr + sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs);
4581 NdisMoveMemory(pBss->IEs, &pAdapter->ScanTab.BssEntry[i].FixIEs, sizeof(NDIS_802_11_FIXED_IEs));
4582 NdisMoveMemory(pBss->IEs + sizeof(NDIS_802_11_FIXED_IEs), pAdapter->ScanTab.BssEntry[i].VarIEs, pAdapter->ScanTab.BssEntry[i].VarIELen);
4583 pPtr += pAdapter->ScanTab.BssEntry[i].VarIELen;
4584 }
4585 pBss->Length = (ULONG)(sizeof(NDIS_WLAN_BSSID_EX) - 1 + sizeof(NDIS_802_11_FIXED_IEs) + pAdapter->ScanTab.BssEntry[i].VarIELen + Padding);
4586
4587#if WIRELESS_EXT < 17
4588 if ((BssLen + pBss->Length) < wrq->u.data.length)
4589 BssLen += pBss->Length;
4590 else
4591 {
4592 pBssidList->NumberOfItems = i;
4593 break;
4594 }
4595#else
4596 BssLen += pBss->Length;
4597#endif
4598 }
4599
4600#if WIRELESS_EXT < 17
4601 wrq->u.data.length = BssLen;
4602#else
4603 if (BssLen > wrq->u.data.length)
4604 {
4605 kfree(pBssidList);
4606 return -E2BIG;
4607 }
4608 else
4609 wrq->u.data.length = BssLen;
4610#endif
4611 Status = copy_to_user(wrq->u.data.pointer, pBssidList, BssLen);
4612 kfree(pBssidList);
4613 break;
4614 case OID_802_3_CURRENT_ADDRESS:
4615 wrq->u.data.length = MAC_ADDR_LEN;
4616 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CurrentAddress, wrq->u.data.length);
4617 break;
4618 case OID_GEN_MEDIA_CONNECT_STATUS:
4619 if (pAdapter->IndicateMediaState == NdisMediaStateConnected)
4620 MediaState = NdisMediaStateConnected;
4621 else
4622 MediaState = NdisMediaStateDisconnected;
4623
4624 wrq->u.data.length = sizeof(NDIS_MEDIA_STATE);
4625 Status = copy_to_user(wrq->u.data.pointer, &MediaState, wrq->u.data.length);
4626 break;
4627 case OID_802_11_BSSID:
91980990
GKH
4628 if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))
4629 {
4630 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Bssid, sizeof(NDIS_802_11_MAC_ADDRESS));
4631
4632 }
4633 else
4634 {
4635 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BSSID(=EMPTY)\n"));
4636 Status = -ENOTCONN;
4637 }
4638 break;
4639 case OID_802_11_SSID:
4640 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
4641 NdisZeroMemory(Ssid.Ssid, MAX_LEN_OF_SSID);
4642 Ssid.SsidLength = pAdapter->CommonCfg.SsidLen;
4643 memcpy(Ssid.Ssid, pAdapter->CommonCfg.Ssid, Ssid.SsidLength);
4644 wrq->u.data.length = sizeof(NDIS_802_11_SSID);
4645 Status = copy_to_user(wrq->u.data.pointer, &Ssid, wrq->u.data.length);
4646 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_SSID (Len=%d, ssid=%s)\n", Ssid.SsidLength,Ssid.Ssid));
4647 break;
4648 case RT_OID_802_11_QUERY_LINK_STATUS:
4649 pLinkStatus = (RT_802_11_LINK_STATUS *) kmalloc(sizeof(RT_802_11_LINK_STATUS), MEM_ALLOC_FLAG);
4650 if (pLinkStatus)
4651 {
4652 pLinkStatus->CurrTxRate = RateIdTo500Kbps[pAdapter->CommonCfg.TxRate]; // unit : 500 kbps
4653 pLinkStatus->ChannelQuality = pAdapter->Mlme.ChannelQuality;
4654 pLinkStatus->RxByteCount = pAdapter->RalinkCounters.ReceivedByteCount;
4655 pLinkStatus->TxByteCount = pAdapter->RalinkCounters.TransmittedByteCount;
4656 pLinkStatus->CentralChannel = pAdapter->CommonCfg.CentralChannel;
4657 wrq->u.data.length = sizeof(RT_802_11_LINK_STATUS);
4658 Status = copy_to_user(wrq->u.data.pointer, pLinkStatus, wrq->u.data.length);
4659 kfree(pLinkStatus);
4660 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS\n"));
4661 }
4662 else
4663 {
4664 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LINK_STATUS(kmalloc failed)\n"));
4665 Status = -EFAULT;
4666 }
4667 break;
4668 case OID_802_11_CONFIGURATION:
4669 pConfiguration = (NDIS_802_11_CONFIGURATION *) kmalloc(sizeof(NDIS_802_11_CONFIGURATION), MEM_ALLOC_FLAG);
4670 if (pConfiguration)
4671 {
4672 pConfiguration->Length = sizeof(NDIS_802_11_CONFIGURATION);
4673 pConfiguration->BeaconPeriod = pAdapter->CommonCfg.BeaconPeriod;
4674 pConfiguration->ATIMWindow = pAdapter->StaActive.AtimWin;
4675 MAP_CHANNEL_ID_TO_KHZ(pAdapter->CommonCfg.Channel, pConfiguration->DSConfig);
4676 wrq->u.data.length = sizeof(NDIS_802_11_CONFIGURATION);
4677 Status = copy_to_user(wrq->u.data.pointer, pConfiguration, wrq->u.data.length);
4678 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(BeaconPeriod=%ld,AtimW=%ld,Channel=%d) \n",
4679 pConfiguration->BeaconPeriod, pConfiguration->ATIMWindow, pAdapter->CommonCfg.Channel));
4680 kfree(pConfiguration);
4681 }
4682 else
4683 {
4684 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_CONFIGURATION(kmalloc failed)\n"));
4685 Status = -EFAULT;
4686 }
4687 break;
4688 case RT_OID_802_11_SNR_0:
4689 if ((pAdapter->StaCfg.LastSNR0 > 0))
4690 {
4691 ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR0) * 3) / 16 ;
4692 wrq->u.data.length = sizeof(ulInfo);
4693 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4694 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_SNR_0(0x=%lx)\n", ulInfo));
4695 }
4696 else
4697 Status = -EFAULT;
4698 break;
4699 case RT_OID_802_11_SNR_1:
4700 if ((pAdapter->Antenna.field.RxPath > 1) &&
4701 (pAdapter->StaCfg.LastSNR1 > 0))
4702 {
4703 ulInfo = ((0xeb - pAdapter->StaCfg.LastSNR1) * 3) / 16 ;
4704 wrq->u.data.length = sizeof(ulInfo);
4705 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4706 DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(0x=%lx)\n",ulInfo));
4707 }
4708 else
4709 Status = -EFAULT;
4710 DBGPRINT(RT_DEBUG_TRACE,("Query::RT_OID_802_11_SNR_1(pAdapter->StaCfg.LastSNR1=%d)\n",pAdapter->StaCfg.LastSNR1));
4711 break;
4712 case OID_802_11_RSSI_TRIGGER:
4713 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0 - pAdapter->BbpRssiToDbmDelta;
4714 wrq->u.data.length = sizeof(ulInfo);
4715 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4716 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RSSI_TRIGGER(=%ld)\n", ulInfo));
4717 break;
4718 case OID_802_11_RSSI:
4719 case RT_OID_802_11_RSSI:
4720 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi0;
4721 wrq->u.data.length = sizeof(ulInfo);
4722 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4723 break;
4724 case RT_OID_802_11_RSSI_1:
4725 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi1;
4726 wrq->u.data.length = sizeof(ulInfo);
4727 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4728 break;
4729 case RT_OID_802_11_RSSI_2:
4730 ulInfo = pAdapter->StaCfg.RssiSample.LastRssi2;
4731 wrq->u.data.length = sizeof(ulInfo);
4732 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4733 break;
4734 case OID_802_11_STATISTICS:
4735 pStatistics = (NDIS_802_11_STATISTICS *) kmalloc(sizeof(NDIS_802_11_STATISTICS), MEM_ALLOC_FLAG);
4736 if (pStatistics)
4737 {
4738 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS \n"));
4739 // add the most up-to-date h/w raw counters into software counters
4740 NICUpdateRawCounters(pAdapter);
4741
4742 // Sanity check for calculation of sucessful count
4743 if (pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart < pAdapter->WlanCounters.RetryCount.QuadPart)
4744 pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
4745
4746 pStatistics->TransmittedFragmentCount.QuadPart = pAdapter->WlanCounters.TransmittedFragmentCount.QuadPart;
4747 pStatistics->MulticastTransmittedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastTransmittedFrameCount.QuadPart;
4748 pStatistics->FailedCount.QuadPart = pAdapter->WlanCounters.FailedCount.QuadPart;
4749 pStatistics->RetryCount.QuadPart = pAdapter->WlanCounters.RetryCount.QuadPart;
4750 pStatistics->MultipleRetryCount.QuadPart = pAdapter->WlanCounters.MultipleRetryCount.QuadPart;
4751 pStatistics->RTSSuccessCount.QuadPart = pAdapter->WlanCounters.RTSSuccessCount.QuadPart;
4752 pStatistics->RTSFailureCount.QuadPart = pAdapter->WlanCounters.RTSFailureCount.QuadPart;
4753 pStatistics->ACKFailureCount.QuadPart = pAdapter->WlanCounters.ACKFailureCount.QuadPart;
4754 pStatistics->FrameDuplicateCount.QuadPart = pAdapter->WlanCounters.FrameDuplicateCount.QuadPart;
4755 pStatistics->ReceivedFragmentCount.QuadPart = pAdapter->WlanCounters.ReceivedFragmentCount.QuadPart;
4756 pStatistics->MulticastReceivedFrameCount.QuadPart = pAdapter->WlanCounters.MulticastReceivedFrameCount.QuadPart;
4757#ifdef DBG
4758 pStatistics->FCSErrorCount = pAdapter->RalinkCounters.RealFcsErrCount;
4759#else
4760 pStatistics->FCSErrorCount.QuadPart = pAdapter->WlanCounters.FCSErrorCount.QuadPart;
4761 pStatistics->FrameDuplicateCount.u.LowPart = pAdapter->WlanCounters.FrameDuplicateCount.u.LowPart / 100;
4762#endif
4763 wrq->u.data.length = sizeof(NDIS_802_11_STATISTICS);
4764 Status = copy_to_user(wrq->u.data.pointer, pStatistics, wrq->u.data.length);
4765 kfree(pStatistics);
4766 }
4767 else
4768 {
4769 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_STATISTICS(kmalloc failed)\n"));
4770 Status = -EFAULT;
4771 }
4772 break;
4773 case OID_GEN_RCV_OK:
4774 ulInfo = pAdapter->Counters8023.GoodReceives;
4775 wrq->u.data.length = sizeof(ulInfo);
4776 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4777 break;
4778 case OID_GEN_RCV_NO_BUFFER:
4779 ulInfo = pAdapter->Counters8023.RxNoBuffer;
4780 wrq->u.data.length = sizeof(ulInfo);
4781 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4782 break;
4783 case RT_OID_802_11_PHY_MODE:
4784 ulInfo = (ULONG)pAdapter->CommonCfg.PhyMode;
4785 wrq->u.data.length = sizeof(ulInfo);
4786 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4787 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PHY_MODE (=%ld)\n", ulInfo));
4788 break;
4789 case RT_OID_802_11_STA_CONFIG:
4790 pStaConfig = (RT_802_11_STA_CONFIG *) kmalloc(sizeof(RT_802_11_STA_CONFIG), MEM_ALLOC_FLAG);
4791 if (pStaConfig)
4792 {
4793 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG\n"));
4794 pStaConfig->EnableTxBurst = pAdapter->CommonCfg.bEnableTxBurst;
4795 pStaConfig->EnableTurboRate = 0;
4796 pStaConfig->UseBGProtection = pAdapter->CommonCfg.UseBGProtection;
4797 pStaConfig->UseShortSlotTime = pAdapter->CommonCfg.bUseShortSlotTime;
4798 //pStaConfig->AdhocMode = pAdapter->StaCfg.AdhocMode;
4799 pStaConfig->HwRadioStatus = (pAdapter->StaCfg.bHwRadio == TRUE) ? 1 : 0;
4800 pStaConfig->Rsv1 = 0;
4801 pStaConfig->SystemErrorBitmap = pAdapter->SystemErrorBitmap;
4802 wrq->u.data.length = sizeof(RT_802_11_STA_CONFIG);
4803 Status = copy_to_user(wrq->u.data.pointer, pStaConfig, wrq->u.data.length);
4804 kfree(pStaConfig);
4805 }
4806 else
4807 {
4808 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
4809 Status = -EFAULT;
4810 }
4811 break;
4812 case OID_802_11_RTS_THRESHOLD:
4813 RtsThresh = pAdapter->CommonCfg.RtsThreshold;
4814 wrq->u.data.length = sizeof(RtsThresh);
4815 Status = copy_to_user(wrq->u.data.pointer, &RtsThresh, wrq->u.data.length);
4816 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_RTS_THRESHOLD(=%ld)\n", RtsThresh));
4817 break;
4818 case OID_802_11_FRAGMENTATION_THRESHOLD:
4819 FragThresh = pAdapter->CommonCfg.FragmentThreshold;
4820 if (pAdapter->CommonCfg.bUseZeroToDisableFragment == TRUE)
4821 FragThresh = 0;
4822 wrq->u.data.length = sizeof(FragThresh);
4823 Status = copy_to_user(wrq->u.data.pointer, &FragThresh, wrq->u.data.length);
4824 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_FRAGMENTATION_THRESHOLD(=%ld)\n", FragThresh));
4825 break;
4826 case OID_802_11_POWER_MODE:
4827 PowerMode = pAdapter->StaCfg.WindowsPowerMode;
4828 wrq->u.data.length = sizeof(PowerMode);
4829 Status = copy_to_user(wrq->u.data.pointer, &PowerMode, wrq->u.data.length);
4830 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_POWER_MODE(=%d)\n", PowerMode));
4831 break;
4832 case RT_OID_802_11_RADIO:
4833 RadioState = (BOOLEAN) pAdapter->StaCfg.bSwRadio;
4834 wrq->u.data.length = sizeof(RadioState);
4835 Status = copy_to_user(wrq->u.data.pointer, &RadioState, wrq->u.data.length);
4836 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_RADIO (=%d)\n", RadioState));
4837 break;
4838 case OID_802_11_INFRASTRUCTURE_MODE:
4839 if (pAdapter->StaCfg.BssType == BSS_ADHOC)
4840 BssType = Ndis802_11IBSS;
4841 else if (pAdapter->StaCfg.BssType == BSS_INFRA)
4842 BssType = Ndis802_11Infrastructure;
4843 else if (pAdapter->StaCfg.BssType == BSS_MONITOR)
4844 BssType = Ndis802_11Monitor;
4845 else
4846 BssType = Ndis802_11AutoUnknown;
4847
4848 wrq->u.data.length = sizeof(BssType);
4849 Status = copy_to_user(wrq->u.data.pointer, &BssType, wrq->u.data.length);
4850 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_INFRASTRUCTURE_MODE(=%d)\n", BssType));
4851 break;
4852 case RT_OID_802_11_PREAMBLE:
4853 PreamType = pAdapter->CommonCfg.TxPreamble;
4854 wrq->u.data.length = sizeof(PreamType);
4855 Status = copy_to_user(wrq->u.data.pointer, &PreamType, wrq->u.data.length);
4856 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_PREAMBLE(=%d)\n", PreamType));
4857 break;
4858 case OID_802_11_AUTHENTICATION_MODE:
4859 AuthMode = pAdapter->StaCfg.AuthMode;
4860 wrq->u.data.length = sizeof(AuthMode);
4861 Status = copy_to_user(wrq->u.data.pointer, &AuthMode, wrq->u.data.length);
4862 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_AUTHENTICATION_MODE(=%d)\n", AuthMode));
4863 break;
4864 case OID_802_11_WEP_STATUS:
4865 WepStatus = pAdapter->StaCfg.WepStatus;
4866 wrq->u.data.length = sizeof(WepStatus);
4867 Status = copy_to_user(wrq->u.data.pointer, &WepStatus, wrq->u.data.length);
4868 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_WEP_STATUS(=%d)\n", WepStatus));
4869 break;
4870 case OID_802_11_TX_POWER_LEVEL:
4871 wrq->u.data.length = sizeof(ULONG);
4872 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPower, wrq->u.data.length);
4873 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_TX_POWER_LEVEL %x\n",pAdapter->CommonCfg.TxPower));
4874 break;
4875 case RT_OID_802_11_TX_POWER_LEVEL_1:
4876 wrq->u.data.length = sizeof(ULONG);
4877 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.TxPowerPercentage, wrq->u.data.length);
4878 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_TX_POWER_LEVEL_1 (=%ld)\n", pAdapter->CommonCfg.TxPowerPercentage));
4879 break;
4880 case OID_802_11_NETWORK_TYPES_SUPPORTED:
4881 if ((pAdapter->RfIcType == RFIC_2850) || (pAdapter->RfIcType == RFIC_2750))
4882 {
4883 NetworkTypeList[0] = 3; // NumberOfItems = 3
4884 NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
4885 NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
4886 NetworkTypeList[3] = Ndis802_11OFDM5; // NetworkType[3] = 11a
4887 wrq->u.data.length = 16;
4888 Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
4889 }
4890 else
4891 {
4892 NetworkTypeList[0] = 2; // NumberOfItems = 2
4893 NetworkTypeList[1] = Ndis802_11DS; // NetworkType[1] = 11b
4894 NetworkTypeList[2] = Ndis802_11OFDM24; // NetworkType[2] = 11g
4895 wrq->u.data.length = 12;
4896 Status = copy_to_user(wrq->u.data.pointer, &NetworkTypeList[0], wrq->u.data.length);
4897 }
4898 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_NETWORK_TYPES_SUPPORTED\n"));
4899 break;
4900 case OID_802_11_NETWORK_TYPE_IN_USE:
4901 wrq->u.data.length = sizeof(ULONG);
4902 if (pAdapter->CommonCfg.PhyMode == PHY_11A)
4903 ulInfo = Ndis802_11OFDM5;
4904 else if ((pAdapter->CommonCfg.PhyMode == PHY_11BG_MIXED) || (pAdapter->CommonCfg.PhyMode == PHY_11G))
4905 ulInfo = Ndis802_11OFDM24;
4906 else
4907 ulInfo = Ndis802_11DS;
4908 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4909 break;
4910 case RT_OID_802_11_QUERY_LAST_RX_RATE:
4911 ulInfo = (ULONG)pAdapter->LastRxRate;
4912 wrq->u.data.length = sizeof(ulInfo);
4913 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4914 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_RX_RATE (=%ld)\n", ulInfo));
4915 break;
4916 case RT_OID_802_11_QUERY_LAST_TX_RATE:
4917 //ulInfo = (ULONG)pAdapter->LastTxRate;
4918 ulInfo = (ULONG)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word;
4919 wrq->u.data.length = sizeof(ulInfo);
4920 Status = copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length);
4921 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_LAST_TX_RATE (=%lx)\n", ulInfo));
4922 break;
4923 case RT_OID_802_11_QUERY_EEPROM_VERSION:
4924 wrq->u.data.length = sizeof(ULONG);
4925 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->EepromVersion, wrq->u.data.length);
4926 break;
4927 case RT_OID_802_11_QUERY_FIRMWARE_VERSION:
4928 wrq->u.data.length = sizeof(ULONG);
4929 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->FirmwareVersion, wrq->u.data.length);
4930 break;
4931 case RT_OID_802_11_QUERY_NOISE_LEVEL:
4932 wrq->u.data.length = sizeof(UCHAR);
4933 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->BbpWriteLatch[66], wrq->u.data.length);
4934 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_NOISE_LEVEL (=%d)\n", pAdapter->BbpWriteLatch[66]));
4935 break;
4936 case RT_OID_802_11_EXTRA_INFO:
4937 wrq->u.data.length = sizeof(ULONG);
4938 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->ExtraInfo, wrq->u.data.length);
4939 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_EXTRA_INFO (=%ld)\n", pAdapter->ExtraInfo));
4940 break;
4941 case RT_OID_WE_VERSION_COMPILED:
4942 wrq->u.data.length = sizeof(UINT);
4943 we_version_compiled = WIRELESS_EXT;
4944 Status = copy_to_user(wrq->u.data.pointer, &we_version_compiled, wrq->u.data.length);
4945 break;
4946 case RT_OID_802_11_QUERY_APSD_SETTING:
4947 apsd = (pAdapter->CommonCfg.bAPSDCapable | (pAdapter->CommonCfg.bAPSDAC_BE << 1) | (pAdapter->CommonCfg.bAPSDAC_BK << 2)
4948 | (pAdapter->CommonCfg.bAPSDAC_VI << 3) | (pAdapter->CommonCfg.bAPSDAC_VO << 4) | (pAdapter->CommonCfg.MaxSPLength << 5));
4949
4950 wrq->u.data.length = sizeof(ULONG);
4951 Status = copy_to_user(wrq->u.data.pointer, &apsd, wrq->u.data.length);
4952 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",
4953 apsd,pAdapter->CommonCfg.bAPSDCapable,pAdapter->CommonCfg.bAPSDAC_BE,pAdapter->CommonCfg.bAPSDAC_BK,pAdapter->CommonCfg.bAPSDAC_VI,pAdapter->CommonCfg.bAPSDAC_VO,pAdapter->CommonCfg.MaxSPLength));
4954 break;
4955 case RT_OID_802_11_QUERY_APSD_PSM:
4956 wrq->u.data.length = sizeof(ULONG);
4957 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bAPSDForcePowerSave, wrq->u.data.length);
4958 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_APSD_PSM (=%d)\n", pAdapter->CommonCfg.bAPSDForcePowerSave));
4959 break;
4960 case RT_OID_802_11_QUERY_WMM:
4961 wrq->u.data.length = sizeof(BOOLEAN);
4962 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.bWmmCapable, wrq->u.data.length);
4963 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_WMM (=%d)\n", pAdapter->CommonCfg.bWmmCapable));
4964 break;
91980990
GKH
4965 case RT_OID_NEW_DRIVER:
4966 {
4967 UCHAR enabled = 1;
4968 wrq->u.data.length = sizeof(UCHAR);
4969 Status = copy_to_user(wrq->u.data.pointer, &enabled, wrq->u.data.length);
4970 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_NEW_DRIVER (=%d)\n", enabled));
4971 }
4972 break;
4973 case RT_OID_WPA_SUPPLICANT_SUPPORT:
4974 wrq->u.data.length = sizeof(UCHAR);
4975 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->StaCfg.WpaSupplicantUP, wrq->u.data.length);
4976 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_WPA_SUPPLICANT_SUPPORT (=%d)\n", pAdapter->StaCfg.WpaSupplicantUP));
4977 break;
91980990
GKH
4978 case RT_OID_DRIVER_DEVICE_NAME:
4979 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_DRIVER_DEVICE_NAME \n"));
4980 wrq->u.data.length = 16;
4981 if (copy_to_user(wrq->u.data.pointer, pAdapter->StaCfg.dev_name, wrq->u.data.length))
4982 {
4983 Status = -EFAULT;
4984 }
4985 break;
4986 case RT_OID_802_11_QUERY_HT_PHYMODE:
4987 pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
4988 if (pHTPhyMode)
4989 {
4990 pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
4991 pHTPhyMode->HtMode = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE;
4992 pHTPhyMode->BW = (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.BW;
4993 pHTPhyMode->MCS= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.MCS;
4994 pHTPhyMode->SHORTGI= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.ShortGI;
4995 pHTPhyMode->STBC= (UCHAR)pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.field.STBC;
4996
4997 pHTPhyMode->ExtOffset = ((pAdapter->CommonCfg.CentralChannel < pAdapter->CommonCfg.Channel) ? (EXTCHA_BELOW) : (EXTCHA_ABOVE));
4998 wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
4999 if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
5000 {
5001 Status = -EFAULT;
5002 }
5003 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
5004 pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
5005 DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
5006 }
5007 else
5008 {
5009 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
5010 Status = -EFAULT;
5011 }
5012 break;
5013 case RT_OID_802_11_COUNTRY_REGION:
5014 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_COUNTRY_REGION \n"));
5015 wrq->u.data.length = sizeof(ulInfo);
5016 ulInfo = pAdapter->CommonCfg.CountryRegionForABand;
5017 ulInfo = (ulInfo << 8)|(pAdapter->CommonCfg.CountryRegion);
5018 if (copy_to_user(wrq->u.data.pointer, &ulInfo, wrq->u.data.length))
5019 {
5020 Status = -EFAULT;
5021 }
5022 break;
5023 case RT_OID_802_11_QUERY_DAT_HT_PHYMODE:
5024 pHTPhyMode = (OID_SET_HT_PHYMODE *) kmalloc(sizeof(OID_SET_HT_PHYMODE), MEM_ALLOC_FLAG);
5025 if (pHTPhyMode)
5026 {
5027 pHTPhyMode->PhyMode = pAdapter->CommonCfg.PhyMode;
5028 pHTPhyMode->HtMode = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.HTMODE;
5029 pHTPhyMode->BW = (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.BW;
5030 pHTPhyMode->MCS= (UCHAR)pAdapter->StaCfg.DesiredTransmitSetting.field.MCS;
5031 pHTPhyMode->SHORTGI= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.ShortGI;
5032 pHTPhyMode->STBC= (UCHAR)pAdapter->CommonCfg.RegTransmitSetting.field.STBC;
5033
5034 wrq->u.data.length = sizeof(OID_SET_HT_PHYMODE);
5035 if (copy_to_user(wrq->u.data.pointer, pHTPhyMode, wrq->u.data.length))
5036 {
5037 Status = -EFAULT;
5038 }
5039 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_QUERY_HT_PHYMODE (PhyMode = %d, MCS =%d, BW = %d, STBC = %d, ExtOffset=%d)\n",
5040 pHTPhyMode->HtMode, pHTPhyMode->MCS, pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->ExtOffset));
5041 DBGPRINT(RT_DEBUG_TRACE, (" MlmeUpdateTxRates (.word = %x )\n", pAdapter->MacTab.Content[BSSID_WCID].HTPhyMode.word));
5042 }
5043 else
5044 {
5045 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_802_11_STA_CONFIG(kmalloc failed)\n"));
5046 Status = -EFAULT;
5047 }
5048 break;
5049 case RT_OID_QUERY_MULTIPLE_CARD_SUPPORT:
5050 wrq->u.data.length = sizeof(UCHAR);
5051 i = 0;
91980990
GKH
5052 if (copy_to_user(wrq->u.data.pointer, &i, wrq->u.data.length))
5053 {
5054 Status = -EFAULT;
5055 }
5056 DBGPRINT(RT_DEBUG_TRACE, ("Query::RT_OID_QUERY_MULTIPLE_CARD_SUPPORT(=%d) \n", i));
5057 break;
91980990
GKH
5058
5059 case OID_802_11_BUILD_CHANNEL_EX:
5060 {
5061 UCHAR value;
5062 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_BUILD_CHANNEL_EX \n"));
5063 wrq->u.data.length = sizeof(UCHAR);
91980990
GKH
5064 DBGPRINT(RT_DEBUG_TRACE, ("Doesn't support EXT_BUILD_CHANNEL_LIST.\n"));
5065 value = 0;
91980990
GKH
5066 Status = copy_to_user(wrq->u.data.pointer, &value, 1);
5067 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5068 }
5069 break;
5070
5071 case OID_802_11_GET_CH_LIST:
5072 {
5073 PRT_CHANNEL_LIST_INFO pChListBuf;
5074
5075 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CH_LIST \n"));
5076 if (pAdapter->ChannelListNum == 0)
5077 {
5078 wrq->u.data.length = 0;
5079 break;
5080 }
5081
5082 pChListBuf = (RT_CHANNEL_LIST_INFO *) kmalloc(sizeof(RT_CHANNEL_LIST_INFO), MEM_ALLOC_FLAG);
5083 if (pChListBuf == NULL)
5084 {
5085 wrq->u.data.length = 0;
5086 break;
5087 }
5088
5089 pChListBuf->ChannelListNum = pAdapter->ChannelListNum;
5090 for (i = 0; i < pChListBuf->ChannelListNum; i++)
5091 pChListBuf->ChannelList[i] = pAdapter->ChannelList[i].Channel;
5092
5093 wrq->u.data.length = sizeof(RT_CHANNEL_LIST_INFO);
5094 Status = copy_to_user(wrq->u.data.pointer, pChListBuf, sizeof(RT_CHANNEL_LIST_INFO));
5095 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5096
5097 if (pChListBuf)
5098 kfree(pChListBuf);
5099 }
5100 break;
5101
5102 case OID_802_11_GET_COUNTRY_CODE:
5103 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_COUNTRY_CODE \n"));
5104 wrq->u.data.length = 2;
5105 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.CountryCode, 2);
5106 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5107 break;
5108
5109 case OID_802_11_GET_CHANNEL_GEOGRAPHY:
5110 DBGPRINT(RT_DEBUG_TRACE, ("Query::OID_802_11_GET_CHANNEL_GEOGRAPHY \n"));
5111 wrq->u.data.length = 1;
5112 Status = copy_to_user(wrq->u.data.pointer, &pAdapter->CommonCfg.Geography, 1);
5113 DBGPRINT(RT_DEBUG_TRACE, ("Status=%d\n", Status));
5114 break;
5115
91980990
GKH
5116 default:
5117 DBGPRINT(RT_DEBUG_TRACE, ("Query::unknown IOCTL's subcmd = 0x%08x\n", cmd));
5118 Status = -EOPNOTSUPP;
5119 break;
5120 }
5121 return Status;
5122}
5123
5124INT rt28xx_sta_ioctl(
5125 IN struct net_device *net_dev,
5126 IN OUT struct ifreq *rq,
5127 IN INT cmd)
5128{
5129 POS_COOKIE pObj;
5130 VIRTUAL_ADAPTER *pVirtualAd = NULL;
5131 RTMP_ADAPTER *pAd = NULL;
5132 struct iwreq *wrq = (struct iwreq *) rq;
5133 BOOLEAN StateMachineTouched = FALSE;
5134 INT Status = NDIS_STATUS_SUCCESS;
5135 USHORT subcmd;
5136
5137 if (net_dev->priv_flags == INT_MAIN)
5138 {
739b7979 5139 pAd = net_dev->ml_priv;
91980990
GKH
5140 }
5141 else
5142 {
739b7979
GKH
5143 pVirtualAd = net_dev->ml_priv;
5144 pAd = pVirtualAd->RtmpDev->ml_priv;
91980990
GKH
5145 }
5146 pObj = (POS_COOKIE) pAd->OS_Cookie;
5147
5148 if (pAd == NULL)
5149 {
5150 /* if 1st open fail, pAd will be free;
739b7979 5151 So the net_dev->ml_priv will be NULL in 2rd open */
91980990
GKH
5152 return -ENETDOWN;
5153 }
5154
5155 //check if the interface is down
5156 if(!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
5157 {
91980990
GKH
5158 {
5159 DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));
5160 return -ENETDOWN;
5161 }
5162 }
5163
5164 { // determine this ioctl command is comming from which interface.
5165 pObj->ioctl_if_type = INT_MAIN;
5166 pObj->ioctl_if = MAIN_MBSSID;
5167 }
5168
5169 switch(cmd)
5170 {
91980990
GKH
5171 case SIOCGIFHWADDR:
5172 DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIFHWADDR\n"));
5173 memcpy(wrq->u.name, pAd->CurrentAddress, ETH_ALEN);
5174 break;
5175 case SIOCGIWNAME:
5176 {
5177 char *name=&wrq->u.name[0];
5178 rt_ioctl_giwname(net_dev, NULL, name, NULL);
5179 break;
5180 }
5181 case SIOCGIWESSID: //Get ESSID
5182 {
5183 struct iw_point *essid=&wrq->u.essid;
5184 rt_ioctl_giwessid(net_dev, NULL, essid, essid->pointer);
5185 break;
5186 }
5187 case SIOCSIWESSID: //Set ESSID
5188 {
5189 struct iw_point *essid=&wrq->u.essid;
5190 rt_ioctl_siwessid(net_dev, NULL, essid, essid->pointer);
5191 break;
5192 }
5193 case SIOCSIWNWID: // set network id (the cell)
5194 case SIOCGIWNWID: // get network id
5195 Status = -EOPNOTSUPP;
5196 break;
5197 case SIOCSIWFREQ: //set channel/frequency (Hz)
5198 {
5199 struct iw_freq *freq=&wrq->u.freq;
5200 rt_ioctl_siwfreq(net_dev, NULL, freq, NULL);
5201 break;
5202 }
5203 case SIOCGIWFREQ: // get channel/frequency (Hz)
5204 {
5205 struct iw_freq *freq=&wrq->u.freq;
5206 rt_ioctl_giwfreq(net_dev, NULL, freq, NULL);
5207 break;
5208 }
5209 case SIOCSIWNICKN: //set node name/nickname
5210 {
5211 struct iw_point *data=&wrq->u.data;
5212 rt_ioctl_siwnickn(net_dev, NULL, data, NULL);
5213 break;
5214 }
5215 case SIOCGIWNICKN: //get node name/nickname
5216 {
5217 struct iw_point *data=&wrq->u.data;
5218 rt_ioctl_giwnickn(net_dev, NULL, data, NULL);
5219 break;
5220 }
5221 case SIOCGIWRATE: //get default bit rate (bps)
5222 rt_ioctl_giwrate(net_dev, NULL, &wrq->u, NULL);
5223 break;
5224 case SIOCSIWRATE: //set default bit rate (bps)
5225 rt_ioctl_siwrate(net_dev, NULL, &wrq->u, NULL);
5226 break;
5227 case SIOCGIWRTS: // get RTS/CTS threshold (bytes)
5228 {
5229 struct iw_param *rts=&wrq->u.rts;
5230 rt_ioctl_giwrts(net_dev, NULL, rts, NULL);
5231 break;
5232 }
5233 case SIOCSIWRTS: //set RTS/CTS threshold (bytes)
5234 {
5235 struct iw_param *rts=&wrq->u.rts;
5236 rt_ioctl_siwrts(net_dev, NULL, rts, NULL);
5237 break;
5238 }
5239 case SIOCGIWFRAG: //get fragmentation thr (bytes)
5240 {
5241 struct iw_param *frag=&wrq->u.frag;
5242 rt_ioctl_giwfrag(net_dev, NULL, frag, NULL);
5243 break;
5244 }
5245 case SIOCSIWFRAG: //set fragmentation thr (bytes)
5246 {
5247 struct iw_param *frag=&wrq->u.frag;
5248 rt_ioctl_siwfrag(net_dev, NULL, frag, NULL);
5249 break;
5250 }
5251 case SIOCGIWENCODE: //get encoding token & mode
5252 {
5253 struct iw_point *erq=&wrq->u.encoding;
5254 if(erq->pointer)
5255 rt_ioctl_giwencode(net_dev, NULL, erq, erq->pointer);
5256 break;
5257 }
5258 case SIOCSIWENCODE: //set encoding token & mode
5259 {
5260 struct iw_point *erq=&wrq->u.encoding;
5261 if(erq->pointer)
5262 rt_ioctl_siwencode(net_dev, NULL, erq, erq->pointer);
5263 break;
5264 }
5265 case SIOCGIWAP: //get access point MAC addresses
5266 {
5267 struct sockaddr *ap_addr=&wrq->u.ap_addr;
5268 rt_ioctl_giwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
5269 break;
5270 }
5271 case SIOCSIWAP: //set access point MAC addresses
5272 {
5273 struct sockaddr *ap_addr=&wrq->u.ap_addr;
5274 rt_ioctl_siwap(net_dev, NULL, ap_addr, ap_addr->sa_data);
5275 break;
5276 }
5277 case SIOCGIWMODE: //get operation mode
5278 {
5279 __u32 *mode=&wrq->u.mode;
5280 rt_ioctl_giwmode(net_dev, NULL, mode, NULL);
5281 break;
5282 }
5283 case SIOCSIWMODE: //set operation mode
5284 {
5285 __u32 *mode=&wrq->u.mode;
5286 rt_ioctl_siwmode(net_dev, NULL, mode, NULL);
5287 break;
5288 }
5289 case SIOCGIWSENS: //get sensitivity (dBm)
5290 case SIOCSIWSENS: //set sensitivity (dBm)
5291 case SIOCGIWPOWER: //get Power Management settings
5292 case SIOCSIWPOWER: //set Power Management settings
5293 case SIOCGIWTXPOW: //get transmit power (dBm)
5294 case SIOCSIWTXPOW: //set transmit power (dBm)
5295 case SIOCGIWRANGE: //Get range of parameters
5296 case SIOCGIWRETRY: //get retry limits and lifetime
5297 case SIOCSIWRETRY: //set retry limits and lifetime
5298 Status = -EOPNOTSUPP;
5299 break;
5300 case RT_PRIV_IOCTL:
3a32ed12
BZ
5301#ifdef RT30xx
5302 case RT_PRIV_IOCTL_EXT:
5303#endif
91980990
GKH
5304 subcmd = wrq->u.data.flags;
5305 if( subcmd & OID_GET_SET_TOGGLE)
5306 Status = RTMPSetInformation(pAd, rq, subcmd);
5307 else
5308 Status = RTMPQueryInformation(pAd, rq, subcmd);
5309 break;
5310 case SIOCGIWPRIV:
5311 if (wrq->u.data.pointer)
5312 {
5313 if ( access_ok(VERIFY_WRITE, wrq->u.data.pointer, sizeof(privtab)) != TRUE)
5314 break;
5315 wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
5316 if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
5317 Status = -EFAULT;
5318 }
5319 break;
5320 case RTPRIV_IOCTL_SET:
5321 if(access_ok(VERIFY_READ, wrq->u.data.pointer, wrq->u.data.length) != TRUE)
5322 break;
5323 rt_ioctl_setparam(net_dev, NULL, NULL, wrq->u.data.pointer);
5324 break;
5325 case RTPRIV_IOCTL_GSITESURVEY:
5326 RTMPIoctlGetSiteSurvey(pAd, wrq);
5327 break;
5328#ifdef DBG
5329 case RTPRIV_IOCTL_MAC:
5330 RTMPIoctlMAC(pAd, wrq);
5331 break;
5332 case RTPRIV_IOCTL_E2P:
5333 RTMPIoctlE2PROM(pAd, wrq);
5334 break;
3a32ed12
BZ
5335#ifdef RT30xx
5336 case RTPRIV_IOCTL_RF:
5337 RTMPIoctlRF(pAd, wrq);
5338 break;
5339#endif // RT30xx //
91980990
GKH
5340#endif // DBG //
5341 case SIOCETHTOOL:
5342 break;
5343 default:
5344 DBGPRINT(RT_DEBUG_ERROR, ("IOCTL::unknown IOCTL's cmd = 0x%08x\n", cmd));
5345 Status = -EOPNOTSUPP;
5346 break;
5347 }
5348
5349 if(StateMachineTouched) // Upper layer sent a MLME-related operations
5350 RT28XX_MLME_HANDLER(pAd);
5351
5352 return Status;
5353}
5354
5355/*
5356 ==========================================================================
5357 Description:
5358 Set SSID
5359 Return:
5360 TRUE if all parameters are OK, FALSE otherwise
5361 ==========================================================================
5362*/
5363INT Set_SSID_Proc(
5364 IN PRTMP_ADAPTER pAdapter,
5365 IN PUCHAR arg)
5366{
5367 NDIS_802_11_SSID Ssid, *pSsid=NULL;
5368 BOOLEAN StateMachineTouched = FALSE;
5369 int success = TRUE;
5370
5371 if( strlen(arg) <= MAX_LEN_OF_SSID)
5372 {
5373 NdisZeroMemory(&Ssid, sizeof(NDIS_802_11_SSID));
5374 if (strlen(arg) != 0)
5375 {
5376 NdisMoveMemory(Ssid.Ssid, arg, strlen(arg));
5377 Ssid.SsidLength = strlen(arg);
5378 }
5379 else //ANY ssid
5380 {
5381 Ssid.SsidLength = 0;
5382 memcpy(Ssid.Ssid, "", 0);
5383 pAdapter->StaCfg.BssType = BSS_INFRA;
5384 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
5385 pAdapter->StaCfg.WepStatus = Ndis802_11EncryptionDisabled;
5386 }
5387 pSsid = &Ssid;
5388
5389 if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)
5390 {
5391 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
5392 DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));
5393 }
5394
5395 pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE;
5396 pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
5397 pAdapter->bConfigChanged = TRUE;
5398
5399 MlmeEnqueue(pAdapter,
5400 MLME_CNTL_STATE_MACHINE,
5401 OID_802_11_SSID,
5402 sizeof(NDIS_802_11_SSID),
5403 (VOID *)pSsid);
5404
5405 StateMachineTouched = TRUE;
5406 DBGPRINT(RT_DEBUG_TRACE, ("Set_SSID_Proc::(Len=%d,Ssid=%s)\n", Ssid.SsidLength, Ssid.Ssid));
5407 }
5408 else
5409 success = FALSE;
5410
5411 if (StateMachineTouched) // Upper layer sent a MLME-related operations
5412 RT28XX_MLME_HANDLER(pAdapter);
5413
5414 return success;
5415}
5416
5417#ifdef WMM_SUPPORT
5418/*
5419 ==========================================================================
5420 Description:
5421 Set WmmCapable Enable or Disable
5422 Return:
5423 TRUE if all parameters are OK, FALSE otherwise
5424 ==========================================================================
5425*/
5426INT Set_WmmCapable_Proc(
5427 IN PRTMP_ADAPTER pAd,
5428 IN PUCHAR arg)
5429{
5430 BOOLEAN bWmmCapable;
5431
5432 bWmmCapable = simple_strtol(arg, 0, 10);
5433
5434 if ((bWmmCapable == 1)
3a32ed12
BZ
5435#ifdef RT2870
5436 && (pAd->NumberOfPipes >= 5)
5437#endif // RT2870 //
91980990
GKH
5438 )
5439 pAd->CommonCfg.bWmmCapable = TRUE;
5440 else if (bWmmCapable == 0)
5441 pAd->CommonCfg.bWmmCapable = FALSE;
5442 else
5443 return FALSE; //Invalid argument
5444
5445 DBGPRINT(RT_DEBUG_TRACE, ("Set_WmmCapable_Proc::(bWmmCapable=%d)\n",
5446 pAd->CommonCfg.bWmmCapable));
5447
5448 return TRUE;
5449}
5450#endif // WMM_SUPPORT //
5451
5452/*
5453 ==========================================================================
5454 Description:
5455 Set Network Type(Infrastructure/Adhoc mode)
5456 Return:
5457 TRUE if all parameters are OK, FALSE otherwise
5458 ==========================================================================
5459*/
5460INT Set_NetworkType_Proc(
5461 IN PRTMP_ADAPTER pAdapter,
5462 IN PUCHAR arg)
5463{
5464 UINT32 Value = 0;
5465
5466 if (strcmp(arg, "Adhoc") == 0)
5467 {
5468 if (pAdapter->StaCfg.BssType != BSS_ADHOC)
5469 {
5470 // Config has changed
5471 pAdapter->bConfigChanged = TRUE;
5472 if (MONITOR_ON(pAdapter))
5473 {
5474 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
5475 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5476 Value &= (~0x80);
5477 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5478 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5479 pAdapter->StaCfg.bAutoReconnect = TRUE;
5480 LinkDown(pAdapter, FALSE);
5481 }
5482 if (INFRA_ON(pAdapter))
5483 {
5484 //BOOLEAN Cancelled;
5485 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
5486 // Since calling this indicate user don't want to connect to that SSID anymore.
5487 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
5488 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
5489
5490 LinkDown(pAdapter, FALSE);
5491
5492 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n"));
5493 }
5494 }
5495 pAdapter->StaCfg.BssType = BSS_ADHOC;
5496 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
5497 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(AD-HOC)\n"));
5498 }
5499 else if (strcmp(arg, "Infra") == 0)
5500 {
5501 if (pAdapter->StaCfg.BssType != BSS_INFRA)
5502 {
5503 // Config has changed
5504 pAdapter->bConfigChanged = TRUE;
5505 if (MONITOR_ON(pAdapter))
5506 {
5507 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);
5508 RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5509 Value &= (~0x80);
5510 RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5511 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5512 pAdapter->StaCfg.bAutoReconnect = TRUE;
5513 LinkDown(pAdapter, FALSE);
5514 }
5515 if (ADHOC_ON(pAdapter))
5516 {
5517 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
5518 // Since calling this indicate user don't want to connect to that SSID anymore.
5519 pAdapter->MlmeAux.AutoReconnectSsidLen= 32;
5520 NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);
5521
5522 LinkDown(pAdapter, FALSE);
5523 }
5524 }
5525 pAdapter->StaCfg.BssType = BSS_INFRA;
5526 pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType;
5527 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(INFRA)\n"));
5528
5529 pAdapter->StaCfg.BssType = BSS_INFRA;
5530 }
5531 else if (strcmp(arg, "Monitor") == 0)
5532 {
5533 UCHAR bbpValue = 0;
5534 BCN_TIME_CFG_STRUC csr;
5535 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_INFRA_ON);
5536 OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_ADHOC_ON);
5537 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);
5538 // disable all periodic state machine
5539 pAdapter->StaCfg.bAutoReconnect = FALSE;
5540 // reset all mlme state machine
5541 RT28XX_MLME_RESET_STATE_MACHINE(pAdapter);
5542 DBGPRINT(RT_DEBUG_TRACE, ("fOP_STATUS_MEDIA_STATE_CONNECTED \n"));
5543 if (pAdapter->CommonCfg.CentralChannel == 0)
5544 {
91980990
GKH
5545 if (pAdapter->CommonCfg.PhyMode == PHY_11AN_MIXED)
5546 pAdapter->CommonCfg.CentralChannel = 36;
5547 else
91980990
GKH
5548 pAdapter->CommonCfg.CentralChannel = 6;
5549 }
91980990
GKH
5550 else
5551 N_ChannelCheck(pAdapter);
91980990 5552
91980990
GKH
5553 if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
5554 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
5555 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_ABOVE)
5556 {
5557 // 40MHz ,control channel at lower
5558 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5559 bbpValue &= (~0x18);
5560 bbpValue |= 0x10;
5561 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5562 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
5563 // RX : control channel at lower
5564 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
5565 bbpValue &= (~0x20);
5566 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
5567
5568 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
5569 Value &= 0xfffffffe;
5570 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
5571 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel + 2;
5572 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
5573 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
5574 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
5575 pAdapter->CommonCfg.Channel,
5576 pAdapter->CommonCfg.CentralChannel));
5577 }
5578 else if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
5579 pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 &&
5580 pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_BELOW)
5581 {
5582 // 40MHz ,control channel at upper
5583 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5584 bbpValue &= (~0x18);
5585 bbpValue |= 0x10;
5586 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5587 pAdapter->CommonCfg.BBPCurrentBW = BW_40;
5588 RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value);
5589 Value |= 0x1;
5590 RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value);
5591
5592 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, &bbpValue);
5593 bbpValue |= (0x20);
5594 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, bbpValue);
5595 pAdapter->CommonCfg.CentralChannel = pAdapter->CommonCfg.Channel - 2;
5596 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.CentralChannel, FALSE);
5597 AsicLockChannel(pAdapter, pAdapter->CommonCfg.CentralChannel);
5598 DBGPRINT(RT_DEBUG_TRACE, ("BW_40 ,control_channel(%d), CentralChannel(%d) \n",
5599 pAdapter->CommonCfg.Channel,
5600 pAdapter->CommonCfg.CentralChannel));
5601 }
5602 else
91980990
GKH
5603 {
5604 // 20MHz
5605 RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, &bbpValue);
5606 bbpValue &= (~0x18);
5607 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, bbpValue);
5608 pAdapter->CommonCfg.BBPCurrentBW = BW_20;
5609 AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.Channel, FALSE);
5610 AsicLockChannel(pAdapter, pAdapter->CommonCfg.Channel);
5611 DBGPRINT(RT_DEBUG_TRACE, ("BW_20, Channel(%d)\n", pAdapter->CommonCfg.Channel));
5612 }
5613 // Enable Rx with promiscuous reception
5614 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, 0x3);
5615 // ASIC supporsts sniffer function with replacing RSSI with timestamp.
5616 //RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);
5617 //Value |= (0x80);
5618 //RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);
5619 // disable sync
5620 RTMP_IO_READ32(pAdapter, BCN_TIME_CFG, &csr.word);
5621 csr.field.bBeaconGen = 0;
5622 csr.field.bTBTTEnable = 0;
5623 csr.field.TsfSyncMode = 0;
5624 RTMP_IO_WRITE32(pAdapter, BCN_TIME_CFG, csr.word);
5625
5626 pAdapter->StaCfg.BssType = BSS_MONITOR;
5627 pAdapter->net_dev->type = ARPHRD_IEEE80211_PRISM; //ARPHRD_IEEE80211; // IEEE80211
5628 DBGPRINT(RT_DEBUG_TRACE, ("===>Set_NetworkType_Proc::(MONITOR)\n"));
5629 }
5630
5631 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
5632 pAdapter->StaCfg.WpaState = SS_NOTUSE;
5633
5634 DBGPRINT(RT_DEBUG_TRACE, ("Set_NetworkType_Proc::(NetworkType=%d)\n", pAdapter->StaCfg.BssType));
5635
5636 return TRUE;
5637}
5638
5639/*
5640 ==========================================================================
5641 Description:
5642 Set Authentication mode
5643 Return:
5644 TRUE if all parameters are OK, FALSE otherwise
5645 ==========================================================================
5646*/
5647INT Set_AuthMode_Proc(
5648 IN PRTMP_ADAPTER pAdapter,
5649 IN PUCHAR arg)
5650{
5651 if ((strcmp(arg, "WEPAUTO") == 0) || (strcmp(arg, "wepauto") == 0))
5652 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeAutoSwitch;
5653 else if ((strcmp(arg, "OPEN") == 0) || (strcmp(arg, "open") == 0))
5654 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
5655 else if ((strcmp(arg, "SHARED") == 0) || (strcmp(arg, "shared") == 0))
5656 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared;
5657 else if ((strcmp(arg, "WPAPSK") == 0) || (strcmp(arg, "wpapsk") == 0))
5658 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
5659 else if ((strcmp(arg, "WPANONE") == 0) || (strcmp(arg, "wpanone") == 0))
5660 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
5661 else if ((strcmp(arg, "WPA2PSK") == 0) || (strcmp(arg, "wpa2psk") == 0))
5662 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
91980990
GKH
5663 else if ((strcmp(arg, "WPA") == 0) || (strcmp(arg, "wpa") == 0))
5664 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
5665 else if ((strcmp(arg, "WPA2") == 0) || (strcmp(arg, "wpa2") == 0))
5666 pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
91980990
GKH
5667 else
5668 return FALSE;
5669
5670 pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
5671
5672 DBGPRINT(RT_DEBUG_TRACE, ("Set_AuthMode_Proc::(AuthMode=%d)\n", pAdapter->StaCfg.AuthMode));
5673
5674 return TRUE;
5675}
5676
5677/*
5678 ==========================================================================
5679 Description:
5680 Set Encryption Type
5681 Return:
5682 TRUE if all parameters are OK, FALSE otherwise
5683 ==========================================================================
5684*/
5685INT Set_EncrypType_Proc(
5686 IN PRTMP_ADAPTER pAdapter,
5687 IN PUCHAR arg)
5688{
5689 if ((strcmp(arg, "NONE") == 0) || (strcmp(arg, "none") == 0))
5690 {
5691 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5692 return TRUE; // do nothing
5693
5694 pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled;
5695 pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled;
5696 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled;
5697 }
5698 else if ((strcmp(arg, "WEP") == 0) || (strcmp(arg, "wep") == 0))
5699 {
5700 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5701 return TRUE; // do nothing
5702
5703 pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled;
5704 pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled;
5705 pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled;
5706 }
5707 else if ((strcmp(arg, "TKIP") == 0) || (strcmp(arg, "tkip") == 0))
5708 {
5709 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
5710 return TRUE; // do nothing
5711
5712 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
5713 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
5714 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption2Enabled;
5715 }
5716 else if ((strcmp(arg, "AES") == 0) || (strcmp(arg, "aes") == 0))
5717 {
5718 if (pAdapter->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
5719 return TRUE; // do nothing
5720
5721 pAdapter->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
5722 pAdapter->StaCfg.PairCipher = Ndis802_11Encryption3Enabled;
5723 pAdapter->StaCfg.GroupCipher = Ndis802_11Encryption3Enabled;
5724 }
5725 else
5726 return FALSE;
5727
5728 pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus;
5729
5730 DBGPRINT(RT_DEBUG_TRACE, ("Set_EncrypType_Proc::(EncrypType=%d)\n", pAdapter->StaCfg.WepStatus));
5731
5732 return TRUE;
5733}
5734
5735/*
5736 ==========================================================================
5737 Description:
5738 Set Default Key ID
5739 Return:
5740 TRUE if all parameters are OK, FALSE otherwise
5741 ==========================================================================
5742*/
5743INT Set_DefaultKeyID_Proc(
5744 IN PRTMP_ADAPTER pAdapter,
5745 IN PUCHAR arg)
5746{
5747 ULONG KeyIdx;
5748
5749 KeyIdx = simple_strtol(arg, 0, 10);
5750 if((KeyIdx >= 1 ) && (KeyIdx <= 4))
5751 pAdapter->StaCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1 );
5752 else
5753 return FALSE; //Invalid argument
5754
5755 DBGPRINT(RT_DEBUG_TRACE, ("Set_DefaultKeyID_Proc::(DefaultKeyID=%d)\n", pAdapter->StaCfg.DefaultKeyId));
5756
5757 return TRUE;
5758}
5759
5760/*
5761 ==========================================================================
5762 Description:
5763 Set WEP KEY1
5764 Return:
5765 TRUE if all parameters are OK, FALSE otherwise
5766 ==========================================================================
5767*/
5768INT Set_Key1_Proc(
5769 IN PRTMP_ADAPTER pAdapter,
5770 IN PUCHAR arg)
5771{
5772 int KeyLen;
5773 int i;
5774 UCHAR CipherAlg=CIPHER_WEP64;
5775
5776 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5777 return TRUE; // do nothing
5778
5779 KeyLen = strlen(arg);
5780
5781 switch (KeyLen)
5782 {
5783 case 5: //wep 40 Ascii type
5784 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
5785 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
5786 CipherAlg = CIPHER_WEP64;
5787 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
5788 break;
5789 case 10: //wep 40 Hex type
5790 for(i=0; i < KeyLen; i++)
5791 {
5792 if( !isxdigit(*(arg+i)) )
5793 return FALSE; //Not Hex value;
5794 }
5795 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
5796 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
5797 CipherAlg = CIPHER_WEP64;
5798 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
5799 break;
5800 case 13: //wep 104 Ascii type
5801 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen;
5802 memcpy(pAdapter->SharedKey[BSS0][0].Key, arg, KeyLen);
5803 CipherAlg = CIPHER_WEP128;
5804 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Ascii"));
5805 break;
5806 case 26: //wep 104 Hex type
5807 for(i=0; i < KeyLen; i++)
5808 {
5809 if( !isxdigit(*(arg+i)) )
5810 return FALSE; //Not Hex value;
5811 }
5812 pAdapter->SharedKey[BSS0][0].KeyLen = KeyLen / 2 ;
5813 AtoH(arg, pAdapter->SharedKey[BSS0][0].Key, KeyLen / 2);
5814 CipherAlg = CIPHER_WEP128;
5815 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::(Key1=%s and type=%s)\n", arg, "Hex"));
5816 break;
5817 default: //Invalid argument
5818 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key1_Proc::Invalid argument (=%s)\n", arg));
5819 return FALSE;
5820 }
5821
5822 pAdapter->SharedKey[BSS0][0].CipherAlg = CipherAlg;
5823
5824 // Set keys (into ASIC)
5825 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5826 ; // not support
5827 else // Old WEP stuff
5828 {
5829 AsicAddSharedKeyEntry(pAdapter,
5830 0,
5831 0,
5832 pAdapter->SharedKey[BSS0][0].CipherAlg,
5833 pAdapter->SharedKey[BSS0][0].Key,
5834 NULL,
5835 NULL);
5836 }
5837
5838 return TRUE;
5839}
5840/*
5841 ==========================================================================
5842
5843 Description:
5844 Set WEP KEY2
5845 Return:
5846 TRUE if all parameters are OK, FALSE otherwise
5847 ==========================================================================
5848*/
5849INT Set_Key2_Proc(
5850 IN PRTMP_ADAPTER pAdapter,
5851 IN PUCHAR arg)
5852{
5853 int KeyLen;
5854 int i;
5855 UCHAR CipherAlg=CIPHER_WEP64;
5856
5857 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5858 return TRUE; // do nothing
5859
5860 KeyLen = strlen(arg);
5861
5862 switch (KeyLen)
5863 {
5864 case 5: //wep 40 Ascii type
5865 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
5866 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
5867 CipherAlg = CIPHER_WEP64;
5868 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
5869 break;
5870 case 10: //wep 40 Hex type
5871 for(i=0; i < KeyLen; i++)
5872 {
5873 if( !isxdigit(*(arg+i)) )
5874 return FALSE; //Not Hex value;
5875 }
5876 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
5877 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
5878 CipherAlg = CIPHER_WEP64;
5879 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
5880 break;
5881 case 13: //wep 104 Ascii type
5882 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen;
5883 memcpy(pAdapter->SharedKey[BSS0][1].Key, arg, KeyLen);
5884 CipherAlg = CIPHER_WEP128;
5885 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Ascii"));
5886 break;
5887 case 26: //wep 104 Hex type
5888 for(i=0; i < KeyLen; i++)
5889 {
5890 if( !isxdigit(*(arg+i)) )
5891 return FALSE; //Not Hex value;
5892 }
5893 pAdapter->SharedKey[BSS0][1].KeyLen = KeyLen / 2 ;
5894 AtoH(arg, pAdapter->SharedKey[BSS0][1].Key, KeyLen / 2);
5895 CipherAlg = CIPHER_WEP128;
5896 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::(Key2=%s and type=%s)\n", arg, "Hex"));
5897 break;
5898 default: //Invalid argument
5899 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key2_Proc::Invalid argument (=%s)\n", arg));
5900 return FALSE;
5901 }
5902 pAdapter->SharedKey[BSS0][1].CipherAlg = CipherAlg;
5903
5904 // Set keys (into ASIC)
5905 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5906 ; // not support
5907 else // Old WEP stuff
5908 {
5909 AsicAddSharedKeyEntry(pAdapter,
5910 0,
5911 1,
5912 pAdapter->SharedKey[BSS0][1].CipherAlg,
5913 pAdapter->SharedKey[BSS0][1].Key,
5914 NULL,
5915 NULL);
5916 }
5917
5918 return TRUE;
5919}
5920/*
5921 ==========================================================================
5922 Description:
5923 Set WEP KEY3
5924 Return:
5925 TRUE if all parameters are OK, FALSE otherwise
5926 ==========================================================================
5927*/
5928INT Set_Key3_Proc(
5929 IN PRTMP_ADAPTER pAdapter,
5930 IN PUCHAR arg)
5931{
5932 int KeyLen;
5933 int i;
5934 UCHAR CipherAlg=CIPHER_WEP64;
5935
5936 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5937 return TRUE; // do nothing
5938
5939 KeyLen = strlen(arg);
5940
5941 switch (KeyLen)
5942 {
5943 case 5: //wep 40 Ascii type
5944 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
5945 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
5946 CipherAlg = CIPHER_WEP64;
5947 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
5948 break;
5949 case 10: //wep 40 Hex type
5950 for(i=0; i < KeyLen; i++)
5951 {
5952 if( !isxdigit(*(arg+i)) )
5953 return FALSE; //Not Hex value;
5954 }
5955 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
5956 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
5957 CipherAlg = CIPHER_WEP64;
5958 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
5959 break;
5960 case 13: //wep 104 Ascii type
5961 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen;
5962 memcpy(pAdapter->SharedKey[BSS0][2].Key, arg, KeyLen);
5963 CipherAlg = CIPHER_WEP128;
5964 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Ascii)\n", arg));
5965 break;
5966 case 26: //wep 104 Hex type
5967 for(i=0; i < KeyLen; i++)
5968 {
5969 if( !isxdigit(*(arg+i)) )
5970 return FALSE; //Not Hex value;
5971 }
5972 pAdapter->SharedKey[BSS0][2].KeyLen = KeyLen / 2 ;
5973 AtoH(arg, pAdapter->SharedKey[BSS0][2].Key, KeyLen / 2);
5974 CipherAlg = CIPHER_WEP128;
5975 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::(Key3=%s and type=Hex)\n", arg));
5976 break;
5977 default: //Invalid argument
5978 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key3_Proc::Invalid argument (=%s)\n", arg));
5979 return FALSE;
5980 }
5981 pAdapter->SharedKey[BSS0][2].CipherAlg = CipherAlg;
5982
5983 // Set keys (into ASIC)
5984 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
5985 ; // not support
5986 else // Old WEP stuff
5987 {
5988 AsicAddSharedKeyEntry(pAdapter,
5989 0,
5990 2,
5991 pAdapter->SharedKey[BSS0][2].CipherAlg,
5992 pAdapter->SharedKey[BSS0][2].Key,
5993 NULL,
5994 NULL);
5995 }
5996
5997 return TRUE;
5998}
5999/*
6000 ==========================================================================
6001 Description:
6002 Set WEP KEY4
6003 Return:
6004 TRUE if all parameters are OK, FALSE otherwise
6005 ==========================================================================
6006*/
6007INT Set_Key4_Proc(
6008 IN PRTMP_ADAPTER pAdapter,
6009 IN PUCHAR arg)
6010{
6011 int KeyLen;
6012 int i;
6013 UCHAR CipherAlg=CIPHER_WEP64;
6014
6015 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6016 return TRUE; // do nothing
6017
6018 KeyLen = strlen(arg);
6019
6020 switch (KeyLen)
6021 {
6022 case 5: //wep 40 Ascii type
6023 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
6024 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
6025 CipherAlg = CIPHER_WEP64;
6026 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
6027 break;
6028 case 10: //wep 40 Hex type
6029 for(i=0; i < KeyLen; i++)
6030 {
6031 if( !isxdigit(*(arg+i)) )
6032 return FALSE; //Not Hex value;
6033 }
6034 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
6035 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
6036 CipherAlg = CIPHER_WEP64;
6037 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
6038 break;
6039 case 13: //wep 104 Ascii type
6040 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen;
6041 memcpy(pAdapter->SharedKey[BSS0][3].Key, arg, KeyLen);
6042 CipherAlg = CIPHER_WEP128;
6043 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Ascii"));
6044 break;
6045 case 26: //wep 104 Hex type
6046 for(i=0; i < KeyLen; i++)
6047 {
6048 if( !isxdigit(*(arg+i)) )
6049 return FALSE; //Not Hex value;
6050 }
6051 pAdapter->SharedKey[BSS0][3].KeyLen = KeyLen / 2 ;
6052 AtoH(arg, pAdapter->SharedKey[BSS0][3].Key, KeyLen / 2);
6053 CipherAlg = CIPHER_WEP128;
6054 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::(Key4=%s and type=%s)\n", arg, "Hex"));
6055 break;
6056 default: //Invalid argument
6057 DBGPRINT(RT_DEBUG_TRACE, ("Set_Key4_Proc::Invalid argument (=%s)\n", arg));
6058 return FALSE;
6059 }
6060 pAdapter->SharedKey[BSS0][3].CipherAlg = CipherAlg;
6061
6062 // Set keys (into ASIC)
6063 if (pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
6064 ; // not support
6065 else // Old WEP stuff
6066 {
6067 AsicAddSharedKeyEntry(pAdapter,
6068 0,
6069 3,
6070 pAdapter->SharedKey[BSS0][3].CipherAlg,
6071 pAdapter->SharedKey[BSS0][3].Key,
6072 NULL,
6073 NULL);
6074 }
6075
6076 return TRUE;
6077}
6078
6079/*
6080 ==========================================================================
6081 Description:
6082 Set WPA PSK key
6083 Return:
6084 TRUE if all parameters are OK, FALSE otherwise
6085 ==========================================================================
6086*/
6087INT Set_WPAPSK_Proc(
6088 IN PRTMP_ADAPTER pAdapter,
6089 IN PUCHAR arg)
6090{
6091 UCHAR keyMaterial[40];
6092
6093 if ((pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
6094 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
6095 (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
6096 )
6097 return TRUE; // do nothing
6098
6099 DBGPRINT(RT_DEBUG_TRACE, ("Set_WPAPSK_Proc::(WPAPSK=%s)\n", arg));
6100
6101 NdisZeroMemory(keyMaterial, 40);
6102
6103 if ((strlen(arg) < 8) || (strlen(arg) > 64))
6104 {
6105 DBGPRINT(RT_DEBUG_TRACE, ("Set failed!!(WPAPSK=%s), WPAPSK key-string required 8 ~ 64 characters \n", arg));
6106 return FALSE;
6107 }
6108
6109 if (strlen(arg) == 64)
6110 {
6111 AtoH(arg, keyMaterial, 32);
6112 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
6113
6114 }
6115 else
6116 {
6117 PasswordHash((char *)arg, pAdapter->MlmeAux.Ssid, pAdapter->MlmeAux.SsidLen, keyMaterial);
6118 NdisMoveMemory(pAdapter->StaCfg.PMK, keyMaterial, 32);
6119 }
6120
6121
6122
6123 if(pAdapter->StaCfg.BssType == BSS_ADHOC &&
6124 pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
6125 {
6126 pAdapter->StaCfg.WpaState = SS_NOTUSE;
6127 }
6128 else
6129 {
6130 // Start STA supplicant state machine
6131 pAdapter->StaCfg.WpaState = SS_START;
6132 }
6133
6134 return TRUE;
6135}
6136
6137/*
6138 ==========================================================================
6139 Description:
6140 Set Power Saving mode
6141 Return:
6142 TRUE if all parameters are OK, FALSE otherwise
6143 ==========================================================================
6144*/
6145INT Set_PSMode_Proc(
6146 IN PRTMP_ADAPTER pAdapter,
6147 IN PUCHAR arg)
6148{
6149 if (pAdapter->StaCfg.BssType == BSS_INFRA)
6150 {
6151 if ((strcmp(arg, "Max_PSP") == 0) ||
6152 (strcmp(arg, "max_psp") == 0) ||
6153 (strcmp(arg, "MAX_PSP") == 0))
6154 {
6155 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6156 // to exclude certain situations.
6157 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6158 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeMAX_PSP;
6159 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeMAX_PSP;
6160 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6161 pAdapter->StaCfg.DefaultListenCount = 5;
6162
6163 }
6164 else if ((strcmp(arg, "Fast_PSP") == 0) ||
6165 (strcmp(arg, "fast_psp") == 0) ||
6166 (strcmp(arg, "FAST_PSP") == 0))
6167 {
6168 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6169 // to exclude certain situations.
6170 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6171 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6172 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeFast_PSP;
6173 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeFast_PSP;
6174 pAdapter->StaCfg.DefaultListenCount = 3;
6175 }
6176 else if ((strcmp(arg, "Legacy_PSP") == 0) ||
6177 (strcmp(arg, "legacy_psp") == 0) ||
6178 (strcmp(arg, "LEGACY_PSP") == 0))
6179 {
6180 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
6181 // to exclude certain situations.
6182 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6183 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6184 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeLegacy_PSP;
6185 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeLegacy_PSP;
6186 pAdapter->StaCfg.DefaultListenCount = 3;
6187 }
6188 else
6189 {
6190 //Default Ndis802_11PowerModeCAM
6191 // clear PSM bit immediately
6192 MlmeSetPsmBit(pAdapter, PWR_ACTIVE);
6193 OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_RECEIVE_DTIM);
6194 if (pAdapter->StaCfg.bWindowsACCAMEnable == FALSE)
6195 pAdapter->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
6196 pAdapter->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
6197 }
6198
6199 DBGPRINT(RT_DEBUG_TRACE, ("Set_PSMode_Proc::(PSMode=%ld)\n", pAdapter->StaCfg.WindowsPowerMode));
6200 }
6201 else
6202 return FALSE;
6203
6204
6205 return TRUE;
6206}
6207
91980990
GKH
6208/*
6209 ==========================================================================
6210 Description:
6211 Set WpaSupport flag.
6212 Value:
6213 0: Driver ignore wpa_supplicant.
6214 1: wpa_supplicant initiates scanning and AP selection.
6215 2: driver takes care of scanning, AP selection, and IEEE 802.11 association parameters.
6216 Return:
6217 TRUE if all parameters are OK, FALSE otherwise
6218 ==========================================================================
6219*/
6220INT Set_Wpa_Support(
6221 IN PRTMP_ADAPTER pAd,
6222 IN PUCHAR arg)
6223{
6224
6225 if ( simple_strtol(arg, 0, 10) == 0)
6226 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
6227 else if ( simple_strtol(arg, 0, 10) == 1)
6228 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE;
6229 else if ( simple_strtol(arg, 0, 10) == 2)
6230 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE_WITH_WEB_UI;
6231 else
6232 pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE;
6233
6234 DBGPRINT(RT_DEBUG_TRACE, ("Set_Wpa_Support::(WpaSupplicantUP=%d)\n", pAd->StaCfg.WpaSupplicantUP));
6235
6236 return TRUE;
6237}
91980990
GKH
6238
6239#ifdef DBG
6240/*
6241 ==========================================================================
6242 Description:
6243 Read / Write MAC
6244 Arguments:
6245 pAdapter Pointer to our adapter
6246 wrq Pointer to the ioctl argument
6247
6248 Return Value:
6249 None
6250
6251 Note:
6252 Usage:
6253 1.) iwpriv ra0 mac 0 ==> read MAC where Addr=0x0
6254 2.) iwpriv ra0 mac 0=12 ==> write MAC where Addr=0x0, value=12
6255 ==========================================================================
6256*/
6257VOID RTMPIoctlMAC(
6258 IN PRTMP_ADAPTER pAdapter,
6259 IN struct iwreq *wrq)
6260{
6261 CHAR *this_char;
6262 CHAR *value;
6263 INT j = 0, k = 0;
6264 CHAR msg[1024];
6265 CHAR arg[255];
6266 ULONG macAddr = 0;
6267 UCHAR temp[16], temp2[16];
6268 UINT32 macValue = 0;
6269 INT Status;
3a32ed12
BZ
6270#ifdef RT30xx
6271 BOOLEAN bIsPrintAllMAC = FALSE;
6272#endif
91980990
GKH
6273
6274 memset(msg, 0x00, 1024);
6275 if (wrq->u.data.length > 1) //No parameters.
6276 {
6277 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6278 sprintf(msg, "\n");
6279
6280 //Parsing Read or Write
6281 this_char = arg;
6282 if (!*this_char)
6283 goto next;
6284
6285 if ((value = rtstrchr(this_char, '=')) != NULL)
6286 *value++ = 0;
6287
6288 if (!value || !*value)
6289 { //Read
6290 // Sanity check
6291 if(strlen(this_char) > 4)
6292 goto next;
6293
6294 j = strlen(this_char);
6295 while(j-- > 0)
6296 {
6297 if(this_char[j] > 'f' || this_char[j] < '0')
6298 return;
6299 }
6300
6301 // Mac Addr
6302 k = j = strlen(this_char);
6303 while(j-- > 0)
6304 {
6305 this_char[4-k+j] = this_char[j];
6306 }
6307
6308 while(k < 4)
6309 this_char[3-k++]='0';
6310 this_char[4]='\0';
6311
6312 if(strlen(this_char) == 4)
6313 {
6314 AtoH(this_char, temp, 2);
6315 macAddr = *temp*256 + temp[1];
6316 if (macAddr < 0xFFFF)
6317 {
6318 RTMP_IO_READ32(pAdapter, macAddr, &macValue);
6319 DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%lx, MacValue=%x\n", macAddr, macValue));
6320 sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr , macValue);
6321 }
6322 else
3a32ed12 6323#ifndef RT30xx
91980990 6324 {//Invalid parametes, so default printk all bbp
3a32ed12
BZ
6325#endif
6326#ifdef RT30xx
6327 {//Invalid parametes, so default printk all mac
6328 bIsPrintAllMAC = TRUE;
6329#endif
91980990
GKH
6330 goto next;
6331 }
6332 }
6333 }
6334 else
6335 { //Write
6336 memcpy(&temp2, value, strlen(value));
6337 temp2[strlen(value)] = '\0';
6338
6339 // Sanity check
6340 if((strlen(this_char) > 4) || strlen(temp2) > 8)
6341 goto next;
6342
6343 j = strlen(this_char);
6344 while(j-- > 0)
6345 {
6346 if(this_char[j] > 'f' || this_char[j] < '0')
6347 return;
6348 }
6349
6350 j = strlen(temp2);
6351 while(j-- > 0)
6352 {
6353 if(temp2[j] > 'f' || temp2[j] < '0')
6354 return;
6355 }
6356
6357 //MAC Addr
6358 k = j = strlen(this_char);
6359 while(j-- > 0)
6360 {
6361 this_char[4-k+j] = this_char[j];
6362 }
6363
6364 while(k < 4)
6365 this_char[3-k++]='0';
6366 this_char[4]='\0';
6367
6368 //MAC value
6369 k = j = strlen(temp2);
6370 while(j-- > 0)
6371 {
6372 temp2[8-k+j] = temp2[j];
6373 }
6374
6375 while(k < 8)
6376 temp2[7-k++]='0';
6377 temp2[8]='\0';
6378
6379 {
6380 AtoH(this_char, temp, 2);
6381 macAddr = *temp*256 + temp[1];
6382
6383 AtoH(temp2, temp, 4);
6384 macValue = *temp*256*256*256 + temp[1]*256*256 + temp[2]*256 + temp[3];
6385
6386 // debug mode
6387 if (macAddr == (HW_DEBUG_SETTING_BASE + 4))
6388 {
6389 // 0x2bf4: byte0 non-zero: enable R17 tuning, 0: disable R17 tuning
6390 if (macValue & 0x000000ff)
6391 {
6392 pAdapter->BbpTuning.bEnable = TRUE;
6393 DBGPRINT(RT_DEBUG_TRACE,("turn on R17 tuning\n"));
6394 }
6395 else
6396 {
6397 UCHAR R66;
6398 pAdapter->BbpTuning.bEnable = FALSE;
6399 R66 = 0x26 + GET_LNA_GAIN(pAdapter);
91980990
GKH
6400 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R66, (0x26 + GET_LNA_GAIN(pAdapter)));
6401 DBGPRINT(RT_DEBUG_TRACE,("turn off R17 tuning, restore to 0x%02x\n", R66));
6402 }
6403 return;
6404 }
6405
6406 DBGPRINT(RT_DEBUG_TRACE, ("MacAddr=%02lx, MacValue=0x%x\n", macAddr, macValue));
6407
6408 RTMP_IO_WRITE32(pAdapter, macAddr, macValue);
6409 sprintf(msg+strlen(msg), "[0x%08lX]:%08X ", macAddr, macValue);
6410 }
6411 }
6412 }
3a32ed12
BZ
6413#ifdef RT30xx
6414 else
6415 bIsPrintAllMAC = TRUE;
6416#endif
91980990 6417next:
3a32ed12
BZ
6418#ifdef RT30xx
6419 if (bIsPrintAllMAC)
6420 {
6421 struct file *file_w;
6422 PCHAR fileName = "MacDump.txt";
6423 mm_segment_t orig_fs;
6424
6425 orig_fs = get_fs();
6426 set_fs(KERNEL_DS);
6427
6428 // open file
6429 file_w = filp_open(fileName, O_WRONLY|O_CREAT, 0);
6430 if (IS_ERR(file_w))
6431 {
6432 DBGPRINT(RT_DEBUG_TRACE, ("-->2) %s: Error %ld opening %s\n", __func__, -PTR_ERR(file_w), fileName));
6433 }
6434 else
6435 {
6436 if (file_w->f_op && file_w->f_op->write)
6437 {
6438 file_w->f_pos = 0;
6439 macAddr = 0x1000;
6440
6441 while (macAddr <= 0x1800)
6442 {
6443 RTMP_IO_READ32(pAdapter, macAddr, &macValue);
6444 sprintf(msg, "%08lx = %08X\n", macAddr, macValue);
6445
6446 // write data to file
6447 file_w->f_op->write(file_w, msg, strlen(msg), &file_w->f_pos);
6448
6449 printk("%s", msg);
6450 macAddr += 4;
6451 }
6452 sprintf(msg, "\nDump all MAC values to %s\n", fileName);
6453 }
6454 filp_close(file_w, NULL);
6455 }
6456 set_fs(orig_fs);
6457 }
6458#endif /* RT30xx */
91980990
GKH
6459 if(strlen(msg) == 1)
6460 sprintf(msg+strlen(msg), "===>Error command format!");
6461
6462 // Copy the information into the user buffer
6463 wrq->u.data.length = strlen(msg);
6464 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6465
6466 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlMAC\n\n"));
6467}
6468
6469/*
6470 ==========================================================================
6471 Description:
6472 Read / Write E2PROM
6473 Arguments:
6474 pAdapter Pointer to our adapter
6475 wrq Pointer to the ioctl argument
6476
6477 Return Value:
6478 None
6479
6480 Note:
6481 Usage:
6482 1.) iwpriv ra0 e2p 0 ==> read E2PROM where Addr=0x0
6483 2.) iwpriv ra0 e2p 0=1234 ==> write E2PROM where Addr=0x0, value=1234
6484 ==========================================================================
6485*/
6486VOID RTMPIoctlE2PROM(
6487 IN PRTMP_ADAPTER pAdapter,
6488 IN struct iwreq *wrq)
6489{
6490 CHAR *this_char;
6491 CHAR *value;
6492 INT j = 0, k = 0;
6493 CHAR msg[1024];
6494 CHAR arg[255];
6495 USHORT eepAddr = 0;
6496 UCHAR temp[16], temp2[16];
6497 USHORT eepValue;
6498 int Status;
3a32ed12
BZ
6499#ifdef RT30xx
6500 BOOLEAN bIsPrintAllE2P = FALSE;
6501#endif
91980990
GKH
6502
6503 memset(msg, 0x00, 1024);
6504 if (wrq->u.data.length > 1) //No parameters.
6505 {
6506 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6507 sprintf(msg, "\n");
6508
6509 //Parsing Read or Write
6510 this_char = arg;
6511
6512
6513 if (!*this_char)
6514 goto next;
6515
6516 if ((value = rtstrchr(this_char, '=')) != NULL)
6517 *value++ = 0;
6518
6519 if (!value || !*value)
6520 { //Read
6521
6522 // Sanity check
6523 if(strlen(this_char) > 4)
6524 goto next;
6525
6526 j = strlen(this_char);
6527 while(j-- > 0)
6528 {
6529 if(this_char[j] > 'f' || this_char[j] < '0')
6530 return;
6531 }
6532
6533 // E2PROM addr
6534 k = j = strlen(this_char);
6535 while(j-- > 0)
6536 {
6537 this_char[4-k+j] = this_char[j];
6538 }
6539
6540 while(k < 4)
6541 this_char[3-k++]='0';
6542 this_char[4]='\0';
6543
6544 if(strlen(this_char) == 4)
6545 {
6546 AtoH(this_char, temp, 2);
6547 eepAddr = *temp*256 + temp[1];
6548 if (eepAddr < 0xFFFF)
6549 {
6550 RT28xx_EEPROM_READ16(pAdapter, eepAddr, eepValue);
6551 sprintf(msg+strlen(msg), "[0x%04X]:0x%04X ", eepAddr , eepValue);
6552 }
6553 else
6554 {//Invalid parametes, so default printk all bbp
3a32ed12
BZ
6555#ifdef RT30xx
6556 bIsPrintAllE2P = TRUE;
6557#endif
91980990
GKH
6558 goto next;
6559 }
6560 }
6561 }
6562 else
6563 { //Write
6564 memcpy(&temp2, value, strlen(value));
6565 temp2[strlen(value)] = '\0';
6566
6567 // Sanity check
6568 if((strlen(this_char) > 4) || strlen(temp2) > 8)
6569 goto next;
6570
6571 j = strlen(this_char);
6572 while(j-- > 0)
6573 {
6574 if(this_char[j] > 'f' || this_char[j] < '0')
6575 return;
6576 }
6577 j = strlen(temp2);
6578 while(j-- > 0)
6579 {
6580 if(temp2[j] > 'f' || temp2[j] < '0')
6581 return;
6582 }
6583
6584 //MAC Addr
6585 k = j = strlen(this_char);
6586 while(j-- > 0)
6587 {
6588 this_char[4-k+j] = this_char[j];
6589 }
6590
6591 while(k < 4)
6592 this_char[3-k++]='0';
6593 this_char[4]='\0';
6594
6595 //MAC value
6596 k = j = strlen(temp2);
6597 while(j-- > 0)
6598 {
6599 temp2[4-k+j] = temp2[j];
6600 }
6601
6602 while(k < 4)
6603 temp2[3-k++]='0';
6604 temp2[4]='\0';
6605
6606 AtoH(this_char, temp, 2);
6607 eepAddr = *temp*256 + temp[1];
6608
6609 AtoH(temp2, temp, 2);
6610 eepValue = *temp*256 + temp[1];
6611
6612 RT28xx_EEPROM_WRITE16(pAdapter, eepAddr, eepValue);
6613 sprintf(msg+strlen(msg), "[0x%02X]:%02X ", eepAddr, eepValue);
6614 }
6615 }
3a32ed12
BZ
6616#ifdef RT30xx
6617 else
6618 bIsPrintAllE2P = TRUE;
6619#endif
91980990 6620next:
3a32ed12
BZ
6621#ifdef RT30xx
6622 if (bIsPrintAllE2P)
6623 {
6624 struct file *file_w;
6625 PCHAR fileName = "EEPROMDump.txt";
6626 mm_segment_t orig_fs;
6627
6628 orig_fs = get_fs();
6629 set_fs(KERNEL_DS);
6630
6631 // open file
6632 file_w = filp_open(fileName, O_WRONLY|O_CREAT, 0);
6633 if (IS_ERR(file_w))
6634 {
6635 DBGPRINT(RT_DEBUG_TRACE, ("-->2) %s: Error %ld opening %s\n", __func__, -PTR_ERR(file_w), fileName));
6636 }
6637 else
6638 {
6639 if (file_w->f_op && file_w->f_op->write)
6640 {
6641 file_w->f_pos = 0;
6642 eepAddr = 0x00;
6643
6644 while (eepAddr <= 0xFE)
6645 {
6646 RT28xx_EEPROM_READ16(pAdapter, eepAddr, eepValue);
6647 sprintf(msg, "%08x = %04x\n", eepAddr , eepValue);
6648
6649 // write data to file
6650 file_w->f_op->write(file_w, msg, strlen(msg), &file_w->f_pos);
6651
6652 printk("%s", msg);
6653 eepAddr += 2;
6654 }
6655 sprintf(msg, "\nDump all EEPROM values to %s\n", fileName);
6656 }
6657 filp_close(file_w, NULL);
6658 }
6659 set_fs(orig_fs);
6660 }
6661#endif /* RT30xx */
91980990
GKH
6662 if(strlen(msg) == 1)
6663 sprintf(msg+strlen(msg), "===>Error command format!");
6664
6665
6666 // Copy the information into the user buffer
6667 wrq->u.data.length = strlen(msg);
6668 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6669
6670 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlE2PROM\n"));
6671}
3a32ed12
BZ
6672#ifdef RT30xx
6673/*
6674 ==========================================================================
6675 Description:
6676 Read / Write RF register
6677Arguments:
6678 pAdapter Pointer to our adapter
6679 wrq Pointer to the ioctl argument
6680
6681 Return Value:
6682 None
6683
6684 Note:
6685 Usage:
6686 1.) iwpriv ra0 rf ==> read all RF registers
6687 2.) iwpriv ra0 rf 1 ==> read RF where RegID=1
6688 3.) iwpriv ra0 rf 1=10 ==> write RF R1=0x10
6689 ==========================================================================
6690*/
6691VOID RTMPIoctlRF(
6692 IN PRTMP_ADAPTER pAdapter,
6693 IN struct iwreq *wrq)
6694{
6695 CHAR *this_char;
6696 CHAR *value;
6697 UCHAR regRF = 0;
6698 CHAR msg[2048];
6699 CHAR arg[255];
6700 INT rfId;
6701 LONG rfValue;
6702 int Status;
6703 BOOLEAN bIsPrintAllRF = FALSE;
6704
6705
6706 memset(msg, 0x00, 2048);
6707 if (wrq->u.data.length > 1) //No parameters.
6708 {
6709 Status = copy_from_user(arg, wrq->u.data.pointer, (wrq->u.data.length > 255) ? 255 : wrq->u.data.length);
6710 sprintf(msg, "\n");
6711
6712 //Parsing Read or Write
6713 this_char = arg;
6714 if (!*this_char)
6715 goto next;
6716
6717 if ((value = strchr(this_char, '=')) != NULL)
6718 *value++ = 0;
6719
6720 if (!value || !*value)
6721 { //Read
6722 if (sscanf(this_char, "%d", &(rfId)) == 1)
6723 {
6724 if (rfId <= 31)
6725 {
6726 // In RT2860 ATE mode, we do not load 8051 firmware.
6727 //We must access RF directly.
6728 // For RT2870 ATE mode, ATE_RF_IO_WRITE8(/READ8)_BY_REG_ID are redefined.
6729 // according to Andy, Gary, David require.
6730 // the command rf shall read rf register directly for dubug.
6731 // BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
6732 RT30xxReadRFRegister(pAdapter, rfId, &regRF);
6733
6734 sprintf(msg+strlen(msg), "R%02d[0x%02x]:%02X ", rfId, rfId*2, regRF);
6735 }
6736 else
6737 {//Invalid parametes, so default printk all RF
6738 bIsPrintAllRF = TRUE;
6739 goto next;
6740 }
6741 }
6742 else
6743 { //Invalid parametes, so default printk all RF
6744 bIsPrintAllRF = TRUE;
6745 goto next;
6746 }
6747 }
6748 else
6749 { //Write
6750 if ((sscanf(this_char, "%d", &(rfId)) == 1) && (sscanf(value, "%lx", &(rfValue)) == 1))
6751 {
6752 if (rfId <= 31)
6753 {
6754 // In RT2860 ATE mode, we do not load 8051 firmware.
6755 // We should access RF registers directly.
6756 // For RT2870 ATE mode, ATE_RF_IO_WRITE8/READ8_BY_REG_ID are redefined.
6757 {
6758 // according to Andy, Gary, David require.
6759 // the command RF shall read/write RF register directly for dubug.
6760 //BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
6761 //BBP_IO_WRITE8_BY_REG_ID(pAdapter, (UCHAR)bbpId,(UCHAR) bbpValue);
6762 RT30xxReadRFRegister(pAdapter, rfId, &regRF);
6763 RT30xxWriteRFRegister(pAdapter, (UCHAR)rfId,(UCHAR) rfValue);
6764 //Read it back for showing
6765 //BBP_IO_READ8_BY_REG_ID(pAdapter, bbpId, &regBBP);
6766 RT30xxReadRFRegister(pAdapter, rfId, &regRF);
6767 sprintf(msg+strlen(msg), "R%02d[0x%02X]:%02X\n", rfId, rfId*2, regRF);
6768 }
6769 }
6770 else
6771 {//Invalid parametes, so default printk all RF
6772 bIsPrintAllRF = TRUE;
6773 }
6774 }
6775 else
6776 { //Invalid parametes, so default printk all RF
6777 bIsPrintAllRF = TRUE;
6778 }
6779 }
6780 }
6781 else
6782 bIsPrintAllRF = TRUE;
6783next:
6784 if (bIsPrintAllRF)
6785 {
6786 memset(msg, 0x00, 2048);
6787 sprintf(msg, "\n");
6788 for (rfId = 0; rfId <= 31; rfId++)
6789 {
6790 // according to Andy, Gary, David require.
6791 // the command RF shall read/write RF register directly for dubug.
6792 RT30xxReadRFRegister(pAdapter, rfId, &regRF);
6793 sprintf(msg+strlen(msg), "%03d = %02X\n", rfId, regRF);
6794 }
6795 // Copy the information into the user buffer
6796 DBGPRINT(RT_DEBUG_TRACE, ("strlen(msg)=%d\n", (UINT32)strlen(msg)));
6797 wrq->u.data.length = strlen(msg);
6798 if (copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length))
6799 {
6800 DBGPRINT(RT_DEBUG_TRACE, ("%s: copy_to_user() fail\n", __func__));
6801 }
6802 }
6803 else
6804 {
6805 if(strlen(msg) == 1)
6806 sprintf(msg+strlen(msg), "===>Error command format!");
6807
6808 DBGPRINT(RT_DEBUG_TRACE, ("copy to user [msg=%s]\n", msg));
6809 // Copy the information into the user buffer
6810 DBGPRINT(RT_DEBUG_TRACE, ("strlen(msg) =%d\n", (UINT32)strlen(msg)));
6811
6812 // Copy the information into the user buffer
6813 wrq->u.data.length = strlen(msg);
6814 Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
6815 }
6816
6817 DBGPRINT(RT_DEBUG_TRACE, ("<==RTMPIoctlRF\n\n"));
6818}
6819#endif // RT30xx //
91980990
GKH
6820#endif // DBG //
6821
6822
6823
6824
6825INT Set_TGnWifiTest_Proc(
6826 IN PRTMP_ADAPTER pAd,
6827 IN PUCHAR arg)
6828{
6829 if (simple_strtol(arg, 0, 10) == 0)
6830 pAd->StaCfg.bTGnWifiTest = FALSE;
6831 else
6832 pAd->StaCfg.bTGnWifiTest = TRUE;
6833
6834 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_TGnWifiTest_Proc::(bTGnWifiTest=%d)\n", pAd->StaCfg.bTGnWifiTest));
6835 return TRUE;
6836}
6837
6838INT Set_LongRetryLimit_Proc(
6839 IN PRTMP_ADAPTER pAdapter,
6840 IN PUCHAR arg)
6841{
6842 TX_RTY_CFG_STRUC tx_rty_cfg;
6843 UCHAR LongRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
6844
6845 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
6846 tx_rty_cfg.field.LongRtyLimit = LongRetryLimit;
6847 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
6848 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_LongRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
6849 return TRUE;
6850}
6851
6852INT Set_ShortRetryLimit_Proc(
6853 IN PRTMP_ADAPTER pAdapter,
6854 IN PUCHAR arg)
6855{
6856 TX_RTY_CFG_STRUC tx_rty_cfg;
6857 UCHAR ShortRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
6858
6859 RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
6860 tx_rty_cfg.field.ShortRtyLimit = ShortRetryLimit;
6861 RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
6862 DBGPRINT(RT_DEBUG_TRACE, ("IF Set_ShortRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
6863 return TRUE;
6864}
3a32ed12
BZ
6865
6866#if !defined(RT2860) && !defined(RT30xx)
6867INT Show_Adhoc_MacTable_Proc(
6868 IN PRTMP_ADAPTER pAd,
6869 IN PCHAR extra)
6870{
6871 INT i;
6872
6873 sprintf(extra, "\n");
6874
6875 sprintf(extra + strlen(extra), "HT Operating Mode : %d\n", pAd->CommonCfg.AddHTInfo.AddHtInfo2.OperaionMode);
6876
6877 sprintf(extra + strlen(extra), "\n%-19s%-4s%-4s%-7s%-7s%-7s%-10s%-6s%-6s%-6s%-6s\n",
6878 "MAC", "AID", "BSS", "RSSI0", "RSSI1", "RSSI2", "PhMd", "BW", "MCS", "SGI", "STBC");
6879
6880 for (i=1; i<MAX_LEN_OF_MAC_TABLE; i++)
6881 {
6882 PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
6883
6884 if (strlen(extra) > (IW_PRIV_SIZE_MASK - 30))
6885 break;
6886 if ((pEntry->ValidAsCLI || pEntry->ValidAsApCli) && (pEntry->Sst == SST_ASSOC))
6887 {
6888 sprintf(extra + strlen(extra), "%02X:%02X:%02X:%02X:%02X:%02X ",
6889 pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
6890 pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5]);
6891 sprintf(extra + strlen(extra), "%-4d", (int)pEntry->Aid);
6892 sprintf(extra + strlen(extra), "%-4d", (int)pEntry->apidx);
6893 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi0);
6894 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi1);
6895 sprintf(extra + strlen(extra), "%-7d", pEntry->RssiSample.AvgRssi2);
6896 sprintf(extra + strlen(extra), "%-10s", GetPhyMode(pEntry->HTPhyMode.field.MODE));
6897 sprintf(extra + strlen(extra), "%-6s", GetBW(pEntry->HTPhyMode.field.BW));
6898 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.MCS);
6899 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.ShortGI);
6900 sprintf(extra + strlen(extra), "%-6d", pEntry->HTPhyMode.field.STBC);
6901 sprintf(extra + strlen(extra), "%-10d, %d, %d%%\n", pEntry->DebugFIFOCount, pEntry->DebugTxCount,
6902 (pEntry->DebugTxCount) ? ((pEntry->DebugTxCount-pEntry->DebugFIFOCount)*100/pEntry->DebugTxCount) : 0);
6903 sprintf(extra, "%s\n", extra);
6904 }
6905 }
6906
6907 return TRUE;
6908}
6909#endif /* RT2870 */