Staging: rt2870: remove dead EXT_BUILD_CHANNEL_LIST code
[linux-2.6] / drivers / staging / rt2870 / common / cmm_info.c
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
28 #include "../rt_config.h"
29
30 INT     Show_SSID_Proc(
31         IN      PRTMP_ADAPTER   pAd,
32         OUT     PUCHAR                  pBuf);
33
34 INT     Show_WirelessMode_Proc(
35         IN      PRTMP_ADAPTER   pAd,
36         OUT     PUCHAR                  pBuf);
37
38 INT     Show_TxBurst_Proc(
39         IN      PRTMP_ADAPTER   pAd,
40         OUT     PUCHAR                  pBuf);
41
42 INT     Show_TxPreamble_Proc(
43         IN      PRTMP_ADAPTER   pAd,
44         OUT     PUCHAR                  pBuf);
45
46 INT     Show_TxPower_Proc(
47         IN      PRTMP_ADAPTER   pAd,
48         OUT     PUCHAR                  pBuf);
49
50 INT     Show_Channel_Proc(
51         IN      PRTMP_ADAPTER   pAd,
52         OUT     PUCHAR                  pBuf);
53
54 INT     Show_BGProtection_Proc(
55         IN      PRTMP_ADAPTER   pAd,
56         OUT     PUCHAR                  pBuf);
57
58 INT     Show_RTSThreshold_Proc(
59         IN      PRTMP_ADAPTER   pAd,
60         OUT     PUCHAR                  pBuf);
61
62 INT     Show_FragThreshold_Proc(
63         IN      PRTMP_ADAPTER   pAd,
64         OUT     PUCHAR                  pBuf);
65
66 #ifdef DOT11_N_SUPPORT
67 INT     Show_HtBw_Proc(
68         IN      PRTMP_ADAPTER   pAd,
69         OUT     PUCHAR                  pBuf);
70
71 INT     Show_HtMcs_Proc(
72         IN      PRTMP_ADAPTER   pAd,
73         OUT     PUCHAR                  pBuf);
74
75 INT     Show_HtGi_Proc(
76         IN      PRTMP_ADAPTER   pAd,
77         OUT     PUCHAR                  pBuf);
78
79 INT     Show_HtOpMode_Proc(
80         IN      PRTMP_ADAPTER   pAd,
81         OUT     PUCHAR                  pBuf);
82
83 INT     Show_HtExtcha_Proc(
84         IN      PRTMP_ADAPTER   pAd,
85         OUT     PUCHAR                  pBuf);
86
87 INT     Show_HtMpduDensity_Proc(
88         IN      PRTMP_ADAPTER   pAd,
89         OUT     PUCHAR                  pBuf);
90
91 INT     Show_HtBaWinSize_Proc(
92         IN      PRTMP_ADAPTER   pAd,
93         OUT     PUCHAR                  pBuf);
94
95 INT     Show_HtRdg_Proc(
96         IN      PRTMP_ADAPTER   pAd,
97         OUT     PUCHAR                  pBuf);
98
99 INT     Show_HtAmsdu_Proc(
100         IN      PRTMP_ADAPTER   pAd,
101         OUT     PUCHAR                  pBuf);
102
103 INT     Show_HtAutoBa_Proc(
104         IN      PRTMP_ADAPTER   pAd,
105         OUT     PUCHAR                  pBuf);
106 #endif // DOT11_N_SUPPORT //
107
108 INT     Show_CountryRegion_Proc(
109         IN      PRTMP_ADAPTER   pAd,
110         OUT     PUCHAR                  pBuf);
111
112 INT     Show_CountryRegionABand_Proc(
113         IN      PRTMP_ADAPTER   pAd,
114         OUT     PUCHAR                  pBuf);
115
116 INT     Show_CountryCode_Proc(
117         IN      PRTMP_ADAPTER   pAd,
118         OUT     PUCHAR                  pBuf);
119
120 #ifdef AGGREGATION_SUPPORT
121 INT     Show_PktAggregate_Proc(
122         IN      PRTMP_ADAPTER   pAd,
123         OUT     PUCHAR                  pBuf);
124 #endif // AGGREGATION_SUPPORT //
125
126 #ifdef WMM_SUPPORT
127 INT     Show_WmmCapable_Proc(
128         IN      PRTMP_ADAPTER   pAd,
129         OUT     PUCHAR                  pBuf);
130 #endif // WMM_SUPPORT //
131
132 INT     Show_IEEE80211H_Proc(
133         IN      PRTMP_ADAPTER   pAd,
134         OUT     PUCHAR                  pBuf);
135
136 #ifdef CONFIG_STA_SUPPORT
137 INT     Show_NetworkType_Proc(
138         IN      PRTMP_ADAPTER   pAd,
139         OUT     PUCHAR                  pBuf);
140 #endif // CONFIG_STA_SUPPORT //
141
142 INT     Show_AuthMode_Proc(
143         IN      PRTMP_ADAPTER   pAd,
144         OUT     PUCHAR                  pBuf);
145
146 INT     Show_EncrypType_Proc(
147         IN      PRTMP_ADAPTER   pAd,
148         OUT     PUCHAR                  pBuf);
149
150 INT     Show_DefaultKeyID_Proc(
151         IN      PRTMP_ADAPTER   pAd,
152         OUT     PUCHAR                  pBuf);
153
154 INT     Show_Key1_Proc(
155         IN      PRTMP_ADAPTER   pAd,
156         OUT     PUCHAR                  pBuf);
157
158 INT     Show_Key2_Proc(
159         IN      PRTMP_ADAPTER   pAd,
160         OUT     PUCHAR                  pBuf);
161
162 INT     Show_Key3_Proc(
163         IN      PRTMP_ADAPTER   pAd,
164         OUT     PUCHAR                  pBuf);
165
166 INT     Show_Key4_Proc(
167         IN      PRTMP_ADAPTER   pAd,
168         OUT     PUCHAR                  pBuf);
169
170 INT     Show_WPAPSK_Proc(
171         IN      PRTMP_ADAPTER   pAd,
172         OUT     PUCHAR                  pBuf);
173
174 static struct {
175         CHAR *name;
176         INT (*show_proc)(PRTMP_ADAPTER pAdapter, PUCHAR arg);
177 } *PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC, RTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC[] = {
178         {"SSID",                                        Show_SSID_Proc},
179         {"WirelessMode",                        Show_WirelessMode_Proc},
180         {"TxBurst",                                     Show_TxBurst_Proc},
181         {"TxPreamble",                          Show_TxPreamble_Proc},
182         {"TxPower",                                     Show_TxPower_Proc},
183         {"Channel",                                     Show_Channel_Proc},
184         {"BGProtection",                        Show_BGProtection_Proc},
185         {"RTSThreshold",                        Show_RTSThreshold_Proc},
186         {"FragThreshold",                       Show_FragThreshold_Proc},
187 #ifdef DOT11_N_SUPPORT
188         {"HtBw",                                        Show_HtBw_Proc},
189         {"HtMcs",                                       Show_HtMcs_Proc},
190         {"HtGi",                                        Show_HtGi_Proc},
191         {"HtOpMode",                            Show_HtOpMode_Proc},
192         {"HtExtcha",                            Show_HtExtcha_Proc},
193         {"HtMpduDensity",                       Show_HtMpduDensity_Proc},
194         {"HtBaWinSize",                 Show_HtBaWinSize_Proc},
195         {"HtRdg",                               Show_HtRdg_Proc},
196         {"HtAmsdu",                             Show_HtAmsdu_Proc},
197         {"HtAutoBa",                    Show_HtAutoBa_Proc},
198 #endif // DOT11_N_SUPPORT //
199         {"CountryRegion",                       Show_CountryRegion_Proc},
200         {"CountryRegionABand",          Show_CountryRegionABand_Proc},
201         {"CountryCode",                         Show_CountryCode_Proc},
202 #ifdef AGGREGATION_SUPPORT
203         {"PktAggregate",                        Show_PktAggregate_Proc},
204 #endif
205
206 #ifdef WMM_SUPPORT
207         {"WmmCapable",                          Show_WmmCapable_Proc},
208 #endif
209         {"IEEE80211H",                          Show_IEEE80211H_Proc},
210 #ifdef CONFIG_STA_SUPPORT
211     {"NetworkType",                             Show_NetworkType_Proc},
212 #endif // CONFIG_STA_SUPPORT //
213         {"AuthMode",                            Show_AuthMode_Proc},
214         {"EncrypType",                          Show_EncrypType_Proc},
215         {"DefaultKeyID",                        Show_DefaultKeyID_Proc},
216         {"Key1",                                        Show_Key1_Proc},
217         {"Key2",                                        Show_Key2_Proc},
218         {"Key3",                                        Show_Key3_Proc},
219         {"Key4",                                        Show_Key4_Proc},
220         {"WPAPSK",                                      Show_WPAPSK_Proc},
221         {NULL, NULL}
222 };
223
224 /*
225     ==========================================================================
226     Description:
227         Get Driver version.
228
229     Return:
230     ==========================================================================
231 */
232 INT Set_DriverVersion_Proc(
233         IN      PRTMP_ADAPTER   pAd,
234         IN      PUCHAR                  arg)
235 {
236
237 #ifdef CONFIG_STA_SUPPORT
238         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
239                 DBGPRINT(RT_DEBUG_TRACE, ("Driver version-%s\n", STA_DRIVER_VERSION));
240 #endif // CONFIG_STA_SUPPORT //
241
242     return TRUE;
243 }
244
245 /*
246     ==========================================================================
247     Description:
248         Set Country Region.
249         This command will not work, if the field of CountryRegion in eeprom is programmed.
250     Return:
251         TRUE if all parameters are OK, FALSE otherwise
252     ==========================================================================
253 */
254 INT Set_CountryRegion_Proc(
255         IN      PRTMP_ADAPTER   pAd,
256         IN      PUCHAR                  arg)
257 {
258         ULONG region;
259
260         region = simple_strtol(arg, 0, 10);
261
262         // Country can be set only when EEPROM not programmed
263         if (pAd->CommonCfg.CountryRegion & 0x80)
264         {
265                 DBGPRINT(RT_DEBUG_ERROR, ("Set_CountryRegion_Proc::parameter of CountryRegion in eeprom is programmed \n"));
266                 return FALSE;
267         }
268
269         if((region >= 0) && (region <= REGION_MAXIMUM_BG_BAND))
270         {
271                 pAd->CommonCfg.CountryRegion = (UCHAR) region;
272         }
273         else if (region == REGION_31_BG_BAND)
274         {
275                 pAd->CommonCfg.CountryRegion = (UCHAR) region;
276         }
277         else
278         {
279                 DBGPRINT(RT_DEBUG_ERROR, ("Set_CountryRegion_Proc::parameters out of range\n"));
280                 return FALSE;
281         }
282
283         // if set country region, driver needs to be reset
284         BuildChannelList(pAd);
285
286         DBGPRINT(RT_DEBUG_TRACE, ("Set_CountryRegion_Proc::(CountryRegion=%d)\n", pAd->CommonCfg.CountryRegion));
287
288         return TRUE;
289 }
290
291 /*
292     ==========================================================================
293     Description:
294         Set Country Region for A band.
295         This command will not work, if the field of CountryRegion in eeprom is programmed.
296     Return:
297         TRUE if all parameters are OK, FALSE otherwise
298     ==========================================================================
299 */
300 INT Set_CountryRegionABand_Proc(
301         IN      PRTMP_ADAPTER   pAd,
302         IN      PUCHAR                  arg)
303 {
304         ULONG region;
305
306         region = simple_strtol(arg, 0, 10);
307
308         // Country can be set only when EEPROM not programmed
309         if (pAd->CommonCfg.CountryRegionForABand & 0x80)
310         {
311                 DBGPRINT(RT_DEBUG_ERROR, ("Set_CountryRegionABand_Proc::parameter of CountryRegion in eeprom is programmed \n"));
312                 return FALSE;
313         }
314
315         if((region >= 0) && (region <= REGION_MAXIMUM_A_BAND))
316         {
317                 pAd->CommonCfg.CountryRegionForABand = (UCHAR) region;
318         }
319         else
320         {
321                 DBGPRINT(RT_DEBUG_ERROR, ("Set_CountryRegionABand_Proc::parameters out of range\n"));
322                 return FALSE;
323         }
324
325         // if set country region, driver needs to be reset
326         BuildChannelList(pAd);
327
328         DBGPRINT(RT_DEBUG_TRACE, ("Set_CountryRegionABand_Proc::(CountryRegion=%d)\n", pAd->CommonCfg.CountryRegionForABand));
329
330         return TRUE;
331 }
332
333 /*
334     ==========================================================================
335     Description:
336         Set Wireless Mode
337     Return:
338         TRUE if all parameters are OK, FALSE otherwise
339     ==========================================================================
340 */
341 INT     Set_WirelessMode_Proc(
342         IN      PRTMP_ADAPTER   pAd,
343         IN      PUCHAR                  arg)
344 {
345         ULONG   WirelessMode;
346         INT             success = TRUE;
347
348         WirelessMode = simple_strtol(arg, 0, 10);
349
350
351 #ifdef CONFIG_STA_SUPPORT
352         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
353         {
354                 INT MaxPhyMode = PHY_11G;
355
356 #ifdef DOT11_N_SUPPORT
357                 MaxPhyMode = PHY_11N_5G;
358 #endif // DOT11_N_SUPPORT //
359
360                 if (WirelessMode <= MaxPhyMode)
361                 {
362                         RTMPSetPhyMode(pAd, WirelessMode);
363 #ifdef DOT11_N_SUPPORT
364                         if (WirelessMode >= PHY_11ABGN_MIXED)
365                         {
366                                 pAd->CommonCfg.BACapability.field.AutoBA = TRUE;
367                                 pAd->CommonCfg.REGBACapability.field.AutoBA = TRUE;
368                         }
369                         else
370                         {
371                                 pAd->CommonCfg.BACapability.field.AutoBA = FALSE;
372                                 pAd->CommonCfg.REGBACapability.field.AutoBA = FALSE;
373                         }
374 #endif // DOT11_N_SUPPORT //
375                         // Set AdhocMode rates
376                         if (pAd->StaCfg.BssType == BSS_ADHOC)
377                         {
378                                 MlmeUpdateTxRates(pAd, FALSE, 0);
379                                 MakeIbssBeacon(pAd);           // re-build BEACON frame
380                                 AsicEnableIbssSync(pAd);       // copy to on-chip memory
381                         }
382                 }
383                 else
384                 {
385                         success = FALSE;
386                 }
387         }
388 #endif // CONFIG_STA_SUPPORT //
389
390         // it is needed to set SSID to take effect
391         if (success == TRUE)
392         {
393 #ifdef DOT11_N_SUPPORT
394                 SetCommonHT(pAd);
395 #endif // DOT11_N_SUPPORT //
396                 DBGPRINT(RT_DEBUG_TRACE, ("Set_WirelessMode_Proc::(=%ld)\n", WirelessMode));
397         }
398         else
399         {
400                 DBGPRINT(RT_DEBUG_ERROR, ("Set_WirelessMode_Proc::parameters out of range\n"));
401         }
402
403         return success;
404 }
405
406 /*
407     ==========================================================================
408     Description:
409         Set Channel
410     Return:
411         TRUE if all parameters are OK, FALSE otherwise
412     ==========================================================================
413 */
414 INT     Set_Channel_Proc(
415         IN      PRTMP_ADAPTER   pAd,
416         IN      PUCHAR                  arg)
417 {
418         INT             success = TRUE;
419         UCHAR   Channel;
420
421         Channel = (UCHAR) simple_strtol(arg, 0, 10);
422
423         // check if this channel is valid
424         if (ChannelSanity(pAd, Channel) == TRUE)
425         {
426 #ifdef CONFIG_STA_SUPPORT
427                 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
428                 {
429                         pAd->CommonCfg.Channel = Channel;
430
431                         if (MONITOR_ON(pAd))
432                         {
433 #ifdef DOT11_N_SUPPORT
434                                 N_ChannelCheck(pAd);
435                                 if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
436                                         pAd->CommonCfg.RegTransmitSetting.field.BW == BW_40)
437                                 {
438                                         N_SetCenCh(pAd);
439                                         AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
440                                         AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
441                                         DBGPRINT(RT_DEBUG_TRACE, ("BW_40, control_channel(%d), CentralChannel(%d) \n",
442                                                                 pAd->CommonCfg.Channel, pAd->CommonCfg.CentralChannel));
443                                 }
444                                 else
445 #endif // DOT11_N_SUPPORT //
446                                 {
447                                         AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
448                                         AsicLockChannel(pAd, pAd->CommonCfg.Channel);
449                                         DBGPRINT(RT_DEBUG_TRACE, ("BW_20, Channel(%d)\n", pAd->CommonCfg.Channel));
450                                 }
451                         }
452                 }
453 #endif // CONFIG_STA_SUPPORT //
454                 success = TRUE;
455         }
456         else
457         {
458
459 #ifdef CONFIG_STA_SUPPORT
460                 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
461                         success = FALSE;
462 #endif // CONFIG_STA_SUPPORT //
463         }
464
465
466         if (success == TRUE)
467                 DBGPRINT(RT_DEBUG_TRACE, ("Set_Channel_Proc::(Channel=%d)\n", pAd->CommonCfg.Channel));
468
469         return success;
470 }
471
472 /*
473     ==========================================================================
474     Description:
475         Set Short Slot Time Enable or Disable
476     Return:
477         TRUE if all parameters are OK, FALSE otherwise
478     ==========================================================================
479 */
480 INT     Set_ShortSlot_Proc(
481         IN      PRTMP_ADAPTER   pAd,
482         IN      PUCHAR                  arg)
483 {
484         ULONG ShortSlot;
485
486         ShortSlot = simple_strtol(arg, 0, 10);
487
488         if (ShortSlot == 1)
489                 pAd->CommonCfg.bUseShortSlotTime = TRUE;
490         else if (ShortSlot == 0)
491                 pAd->CommonCfg.bUseShortSlotTime = FALSE;
492         else
493                 return FALSE;  //Invalid argument
494
495         DBGPRINT(RT_DEBUG_TRACE, ("Set_ShortSlot_Proc::(ShortSlot=%d)\n", pAd->CommonCfg.bUseShortSlotTime));
496
497         return TRUE;
498 }
499
500 /*
501     ==========================================================================
502     Description:
503         Set Tx power
504     Return:
505         TRUE if all parameters are OK, FALSE otherwise
506     ==========================================================================
507 */
508 INT     Set_TxPower_Proc(
509         IN      PRTMP_ADAPTER   pAd,
510         IN      PUCHAR                  arg)
511 {
512         ULONG TxPower;
513         INT   success = FALSE;
514
515         TxPower = (ULONG) simple_strtol(arg, 0, 10);
516         if (TxPower <= 100)
517         {
518
519 #ifdef CONFIG_STA_SUPPORT
520                 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
521                 {
522                         pAd->CommonCfg.TxPowerDefault = TxPower;
523                         pAd->CommonCfg.TxPowerPercentage = pAd->CommonCfg.TxPowerDefault;
524                 }
525 #endif // CONFIG_STA_SUPPORT //
526                 success = TRUE;
527         }
528         else
529                 success = FALSE;
530
531         DBGPRINT(RT_DEBUG_TRACE, ("Set_TxPower_Proc::(TxPowerPercentage=%ld)\n", pAd->CommonCfg.TxPowerPercentage));
532
533         return success;
534 }
535
536 /*
537     ==========================================================================
538     Description:
539         Set 11B/11G Protection
540     Return:
541         TRUE if all parameters are OK, FALSE otherwise
542     ==========================================================================
543 */
544 INT     Set_BGProtection_Proc(
545         IN      PRTMP_ADAPTER   pAd,
546         IN      PUCHAR                  arg)
547 {
548         switch (simple_strtol(arg, 0, 10))
549         {
550                 case 0: //AUTO
551                         pAd->CommonCfg.UseBGProtection = 0;
552                         break;
553                 case 1: //Always On
554                         pAd->CommonCfg.UseBGProtection = 1;
555                         break;
556                 case 2: //Always OFF
557                         pAd->CommonCfg.UseBGProtection = 2;
558                         break;
559                 default:  //Invalid argument
560                         return FALSE;
561         }
562
563
564         DBGPRINT(RT_DEBUG_TRACE, ("Set_BGProtection_Proc::(BGProtection=%ld)\n", pAd->CommonCfg.UseBGProtection));
565
566         return TRUE;
567 }
568
569 /*
570     ==========================================================================
571     Description:
572         Set TxPreamble
573     Return:
574         TRUE if all parameters are OK, FALSE otherwise
575     ==========================================================================
576 */
577 INT     Set_TxPreamble_Proc(
578         IN      PRTMP_ADAPTER   pAd,
579         IN      PUCHAR                  arg)
580 {
581         RT_802_11_PREAMBLE      Preamble;
582
583         Preamble = simple_strtol(arg, 0, 10);
584
585
586         switch (Preamble)
587         {
588                 case Rt802_11PreambleShort:
589                         pAd->CommonCfg.TxPreamble = Preamble;
590 #ifdef CONFIG_STA_SUPPORT
591                         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
592                                 MlmeSetTxPreamble(pAd, Rt802_11PreambleShort);
593 #endif // CONFIG_STA_SUPPORT //
594                         break;
595                 case Rt802_11PreambleLong:
596 #ifdef CONFIG_STA_SUPPORT
597                 case Rt802_11PreambleAuto:
598                         // if user wants AUTO, initialize to LONG here, then change according to AP's
599                         // capability upon association.
600 #endif // CONFIG_STA_SUPPORT //
601                         pAd->CommonCfg.TxPreamble = Preamble;
602 #ifdef CONFIG_STA_SUPPORT
603                         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
604                                 MlmeSetTxPreamble(pAd, Rt802_11PreambleLong);
605 #endif // CONFIG_STA_SUPPORT //
606                         break;
607                 default: //Invalid argument
608                         return FALSE;
609         }
610
611         DBGPRINT(RT_DEBUG_TRACE, ("Set_TxPreamble_Proc::(TxPreamble=%ld)\n", pAd->CommonCfg.TxPreamble));
612
613         return TRUE;
614 }
615
616 /*
617     ==========================================================================
618     Description:
619         Set RTS Threshold
620     Return:
621         TRUE if all parameters are OK, FALSE otherwise
622     ==========================================================================
623 */
624 INT     Set_RTSThreshold_Proc(
625         IN      PRTMP_ADAPTER   pAd,
626         IN      PUCHAR                  arg)
627 {
628          NDIS_802_11_RTS_THRESHOLD           RtsThresh;
629
630         RtsThresh = simple_strtol(arg, 0, 10);
631
632         if((RtsThresh > 0) && (RtsThresh <= MAX_RTS_THRESHOLD))
633                 pAd->CommonCfg.RtsThreshold  = (USHORT)RtsThresh;
634 #ifdef CONFIG_STA_SUPPORT
635         else if (RtsThresh == 0)
636                 pAd->CommonCfg.RtsThreshold = MAX_RTS_THRESHOLD;
637 #endif // CONFIG_STA_SUPPORT //
638         else
639                 return FALSE; //Invalid argument
640
641         DBGPRINT(RT_DEBUG_TRACE, ("Set_RTSThreshold_Proc::(RTSThreshold=%d)\n", pAd->CommonCfg.RtsThreshold));
642
643         return TRUE;
644 }
645
646 /*
647     ==========================================================================
648     Description:
649         Set Fragment Threshold
650     Return:
651         TRUE if all parameters are OK, FALSE otherwise
652     ==========================================================================
653 */
654 INT     Set_FragThreshold_Proc(
655         IN      PRTMP_ADAPTER   pAd,
656         IN      PUCHAR                  arg)
657 {
658          NDIS_802_11_FRAGMENTATION_THRESHOLD     FragThresh;
659
660         FragThresh = simple_strtol(arg, 0, 10);
661
662         if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
663         {
664                 //Illegal FragThresh so we set it to default
665                 pAd->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
666         }
667         else if (FragThresh % 2 == 1)
668         {
669                 // The length of each fragment shall always be an even number of octets, except for the last fragment
670                 // of an MSDU or MMPDU, which may be either an even or an odd number of octets.
671                 pAd->CommonCfg.FragmentThreshold = (USHORT)(FragThresh - 1);
672         }
673         else
674         {
675                 pAd->CommonCfg.FragmentThreshold = (USHORT)FragThresh;
676         }
677
678 #ifdef CONFIG_STA_SUPPORT
679         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
680         {
681                 if (pAd->CommonCfg.FragmentThreshold == MAX_FRAG_THRESHOLD)
682                         pAd->CommonCfg.bUseZeroToDisableFragment = TRUE;
683                 else
684                         pAd->CommonCfg.bUseZeroToDisableFragment = FALSE;
685         }
686 #endif // CONFIG_STA_SUPPORT //
687
688         DBGPRINT(RT_DEBUG_TRACE, ("Set_FragThreshold_Proc::(FragThreshold=%d)\n", pAd->CommonCfg.FragmentThreshold));
689
690         return TRUE;
691 }
692
693 /*
694     ==========================================================================
695     Description:
696         Set TxBurst
697     Return:
698         TRUE if all parameters are OK, FALSE otherwise
699     ==========================================================================
700 */
701 INT     Set_TxBurst_Proc(
702         IN      PRTMP_ADAPTER   pAd,
703         IN      PUCHAR                  arg)
704 {
705         ULONG TxBurst;
706
707         TxBurst = simple_strtol(arg, 0, 10);
708         if (TxBurst == 1)
709                 pAd->CommonCfg.bEnableTxBurst = TRUE;
710         else if (TxBurst == 0)
711                 pAd->CommonCfg.bEnableTxBurst = FALSE;
712         else
713                 return FALSE;  //Invalid argument
714
715         DBGPRINT(RT_DEBUG_TRACE, ("Set_TxBurst_Proc::(TxBurst=%d)\n", pAd->CommonCfg.bEnableTxBurst));
716
717         return TRUE;
718 }
719
720 #ifdef AGGREGATION_SUPPORT
721 /*
722     ==========================================================================
723     Description:
724         Set TxBurst
725     Return:
726         TRUE if all parameters are OK, FALSE otherwise
727     ==========================================================================
728 */
729 INT     Set_PktAggregate_Proc(
730         IN      PRTMP_ADAPTER   pAd,
731         IN      PUCHAR                  arg)
732 {
733         ULONG aggre;
734
735         aggre = simple_strtol(arg, 0, 10);
736
737         if (aggre == 1)
738                 pAd->CommonCfg.bAggregationCapable = TRUE;
739         else if (aggre == 0)
740                 pAd->CommonCfg.bAggregationCapable = FALSE;
741         else
742                 return FALSE;  //Invalid argument
743
744
745         DBGPRINT(RT_DEBUG_TRACE, ("Set_PktAggregate_Proc::(AGGRE=%d)\n", pAd->CommonCfg.bAggregationCapable));
746
747         return TRUE;
748 }
749 #endif
750
751 /*
752     ==========================================================================
753     Description:
754         Set IEEE80211H.
755         This parameter is 1 when needs radar detection, otherwise 0
756     Return:
757         TRUE if all parameters are OK, FALSE otherwise
758     ==========================================================================
759 */
760 INT     Set_IEEE80211H_Proc(
761         IN      PRTMP_ADAPTER   pAd,
762         IN      PUCHAR                  arg)
763 {
764     ULONG ieee80211h;
765
766         ieee80211h = simple_strtol(arg, 0, 10);
767
768         if (ieee80211h == 1)
769                 pAd->CommonCfg.bIEEE80211H = TRUE;
770         else if (ieee80211h == 0)
771                 pAd->CommonCfg.bIEEE80211H = FALSE;
772         else
773                 return FALSE;  //Invalid argument
774
775         DBGPRINT(RT_DEBUG_TRACE, ("Set_IEEE80211H_Proc::(IEEE80211H=%d)\n", pAd->CommonCfg.bIEEE80211H));
776
777         return TRUE;
778 }
779
780
781 #ifdef DBG
782 /*
783     ==========================================================================
784     Description:
785         For Debug information
786     Return:
787         TRUE if all parameters are OK, FALSE otherwise
788     ==========================================================================
789 */
790 INT     Set_Debug_Proc(
791         IN      PRTMP_ADAPTER   pAd,
792         IN      PUCHAR                  arg)
793 {
794         DBGPRINT(RT_DEBUG_TRACE, ("==> Set_Debug_Proc *******************\n"));
795
796     if(simple_strtol(arg, 0, 10) <= RT_DEBUG_LOUD)
797         RTDebugLevel = simple_strtol(arg, 0, 10);
798
799         DBGPRINT(RT_DEBUG_TRACE, ("<== Set_Debug_Proc(RTDebugLevel = %ld)\n", RTDebugLevel));
800
801         return TRUE;
802 }
803 #endif
804
805 INT     Show_DescInfo_Proc(
806         IN      PRTMP_ADAPTER   pAd,
807         IN      PUCHAR                  arg)
808 {
809
810         return TRUE;
811 }
812
813 /*
814     ==========================================================================
815     Description:
816         Reset statistics counter
817
818     Arguments:
819         pAdapter            Pointer to our adapter
820         arg
821
822     Return:
823         TRUE if all parameters are OK, FALSE otherwise
824     ==========================================================================
825 */
826 INT     Set_ResetStatCounter_Proc(
827         IN      PRTMP_ADAPTER   pAd,
828         IN      PUCHAR                  arg)
829 {
830         //UCHAR           i;
831         //MAC_TABLE_ENTRY *pEntry;
832
833         DBGPRINT(RT_DEBUG_TRACE, ("==>Set_ResetStatCounter_Proc\n"));
834
835         // add the most up-to-date h/w raw counters into software counters
836         NICUpdateRawCounters(pAd);
837
838         NdisZeroMemory(&pAd->WlanCounters, sizeof(COUNTER_802_11));
839         NdisZeroMemory(&pAd->Counters8023, sizeof(COUNTER_802_3));
840         NdisZeroMemory(&pAd->RalinkCounters, sizeof(COUNTER_RALINK));
841
842         // Reset HotSpot counter
843 #if 0 // ToDo.
844         for (i = 0; i < MAX_LEN_OF_MAC_TABLE; i++)
845         {
846                 pEntry = &pAd->MacTab.Content[i];
847
848                 if ((pEntry->Valid == FALSE) || (pEntry->Sst != SST_ASSOC))
849                         continue;
850
851                 pEntry->HSCounter.LastDataPacketTime = 0;
852                 pEntry->HSCounter.TotalRxByteCount= 0;
853                 pEntry->HSCounter.TotalTxByteCount= 0;
854         }
855 #endif
856
857
858         return TRUE;
859 }
860
861 /*
862         ========================================================================
863
864         Routine Description:
865                 Add WPA key process.
866                 In Adhoc WPANONE, bPairwise = 0;  KeyIdx = 0;
867
868         Arguments:
869                 pAd                                     Pointer to our adapter
870                 pBuf                                                    Pointer to the where the key stored
871
872         Return Value:
873                 NDIS_SUCCESS                                    Add key successfully
874
875         IRQL = DISPATCH_LEVEL
876
877         Note:
878
879         ========================================================================
880 */
881 #if 0 // remove by AlbertY
882 NDIS_STATUS RTMPWPAAddKeyProc(
883         IN      PRTMP_ADAPTER   pAd,
884         IN      PVOID                   pBuf)
885 {
886         PNDIS_802_11_KEY        pKey;
887         ULONG                           KeyIdx;
888 //      NDIS_STATUS             Status;
889 //      ULONG   offset; // unused variable, snowpin 2006.07.13
890
891         PUCHAR          pTxMic, pRxMic;
892         BOOLEAN         bTxKey;                 // Set the key as transmit key
893         BOOLEAN         bPairwise;              // Indicate the key is pairwise key
894         BOOLEAN         bKeyRSC;                // indicate the receive  SC set by KeyRSC value.
895                                                                 // Otherwise, it will set by the NIC.
896         BOOLEAN         bAuthenticator; // indicate key is set by authenticator.
897         UCHAR           apidx = BSS0;
898
899         pKey = (PNDIS_802_11_KEY) pBuf;
900         KeyIdx = pKey->KeyIndex & 0xff;
901         // Bit 31 of Add-key, Tx Key
902         bTxKey             = (pKey->KeyIndex & 0x80000000) ? TRUE : FALSE;
903         // Bit 30 of Add-key PairwiseKey
904         bPairwise          = (pKey->KeyIndex & 0x40000000) ? TRUE : FALSE;
905         // Bit 29 of Add-key KeyRSC
906         bKeyRSC            = (pKey->KeyIndex & 0x20000000) ? TRUE : FALSE;
907         // Bit 28 of Add-key Authenticator
908         bAuthenticator = (pKey->KeyIndex & 0x10000000) ? TRUE : FALSE;
909
910         DBGPRINT(RT_DEBUG_TRACE,("RTMPWPAAddKeyProc==>pKey->KeyIndex = %x. bPairwise= %d\n", pKey->KeyIndex, bPairwise));
911         // 1. Check Group / Pairwise Key
912         if (bPairwise)  // Pairwise Key
913         {
914                 // 1. KeyIdx must be 0, otherwise, return NDIS_STATUS_INVALID_DATA
915                 if (KeyIdx != 0)
916                         return(NDIS_STATUS_INVALID_DATA);
917
918                 // 2. Check bTx, it must be true, otherwise, return NDIS_STATUS_INVALID_DATA
919                 if (bTxKey == FALSE)
920                         return(NDIS_STATUS_INVALID_DATA);
921
922                 // 3. If BSSID is all 0xff, return NDIS_STATUS_INVALID_DATA
923                 if (MAC_ADDR_EQUAL(pKey->BSSID, BROADCAST_ADDR))
924                         return(NDIS_STATUS_INVALID_DATA);
925
926                 // 3.1 Check Pairwise key length for TKIP key. For AES, it's always 128 bits
927                 //if ((pAdapter->PortCfg.WepStatus == Ndis802_11Encryption2Enabled) && (pKey->KeyLength != LEN_TKIP_KEY))
928                 if ((pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled) && (pKey->KeyLength != LEN_TKIP_KEY))
929                         return(NDIS_STATUS_INVALID_DATA);
930
931                 pAd->SharedKey[apidx][KeyIdx].Type = PAIRWISE_KEY;
932
933                 if (pAd->ApCfg.MBSSID[apidx].AuthMode == Ndis802_11AuthModeWPA2)
934                 {
935                         // Send media specific event to start PMKID caching
936                         RTMPIndicateWPA2Status(pAd);
937                 }
938         }
939         else
940         {
941                 // 1. Check BSSID, if not current BSSID or Bcast, return NDIS_STATUS_INVALID_DATA
942                 if ((! MAC_ADDR_EQUAL(pKey->BSSID, BROADCAST_ADDR)) &&
943                         (! MAC_ADDR_EQUAL(pKey->BSSID, pAd->ApCfg.MBSSID[apidx].Bssid)))
944                         return(NDIS_STATUS_INVALID_DATA);
945
946                 // 2. Check Key index for supported Group Key
947                 if (KeyIdx >= GROUP_KEY_NUM)
948                         return(NDIS_STATUS_INVALID_DATA);
949
950                 // 3. Set as default Tx Key if bTxKey is TRUE
951                 if (bTxKey == TRUE)
952                         pAd->ApCfg.MBSSID[apidx].DefaultKeyId = (UCHAR) KeyIdx;
953
954                 pAd->SharedKey[apidx][KeyIdx].Type = GROUP_KEY;
955         }
956
957         // 4. Select RxMic / TxMic based on Supp / Authenticator
958         if (pAd->ApCfg.MBSSID[apidx].AuthMode == Ndis802_11AuthModeWPANone)
959         {
960                 // for WPA-None Tx, Rx MIC is the same
961                 pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
962                 pRxMic = pTxMic;
963         }
964         else if (bAuthenticator == TRUE)
965         {
966                 pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
967                 pRxMic = (PUCHAR) (&pKey->KeyMaterial) + 24;
968         }
969         else
970         {
971                 pRxMic = (PUCHAR) (&pKey->KeyMaterial) + 16;
972                 pTxMic = (PUCHAR) (&pKey->KeyMaterial) + 24;
973         }
974
975         // 6. Check RxTsc
976         if (bKeyRSC == TRUE)
977         {
978                 NdisMoveMemory(pAd->SharedKey[apidx][KeyIdx].RxTsc, &pKey->KeyRSC, 6);
979                 NdisMoveMemory(pAd->MacTab.Content[BSSID_WCID].PairwiseKey.RxTsc, &pKey->KeyRSC, 6);
980         }
981         else
982         {
983                 NdisZeroMemory(pAd->SharedKey[apidx][KeyIdx].RxTsc, 6);
984         }
985
986         // 7. Copy information into Pairwise Key structure.
987         // pKey->KeyLength will include TxMic and RxMic, therefore, we use 16 bytes hardcoded.
988         pAd->SharedKey[apidx][KeyIdx].KeyLen = (UCHAR) pKey->KeyLength;
989         pAd->MacTab.Content[BSSID_WCID].PairwiseKey.KeyLen = (UCHAR)pKey->KeyLength;
990         NdisMoveMemory(pAd->SharedKey[BSS0][KeyIdx].Key, &pKey->KeyMaterial, 16);
991         NdisMoveMemory(pAd->MacTab.Content[BSSID_WCID].PairwiseKey.Key, &pKey->KeyMaterial, 16);
992         if (pKey->KeyLength == LEN_TKIP_KEY)
993         {
994                 // Only Key lenth equal to TKIP key have these
995                 NdisMoveMemory(pAd->SharedKey[apidx][KeyIdx].RxMic, pRxMic, 8);
996                 NdisMoveMemory(pAd->SharedKey[apidx][KeyIdx].TxMic, pTxMic, 8);
997                 NdisMoveMemory(pAd->MacTab.Content[BSSID_WCID].PairwiseKey.RxMic, pRxMic, 8);
998                 NdisMoveMemory(pAd->MacTab.Content[BSSID_WCID].PairwiseKey.TxMic, pTxMic, 8);
999         }
1000
1001         COPY_MAC_ADDR(pAd->SharedKey[BSS0][KeyIdx].BssId, pKey->BSSID);
1002
1003         // Init TxTsc to one based on WiFi WPA specs
1004         pAd->SharedKey[apidx][KeyIdx].TxTsc[0] = 1;
1005         pAd->SharedKey[apidx][KeyIdx].TxTsc[1] = 0;
1006         pAd->SharedKey[apidx][KeyIdx].TxTsc[2] = 0;
1007         pAd->SharedKey[apidx][KeyIdx].TxTsc[3] = 0;
1008         pAd->SharedKey[apidx][KeyIdx].TxTsc[4] = 0;
1009         pAd->SharedKey[apidx][KeyIdx].TxTsc[5] = 0;
1010         // 4. Init TxTsc to one based on WiFi WPA specs
1011         pAd->MacTab.Content[BSSID_WCID].PairwiseKey.TxTsc[0] = 1;
1012         pAd->MacTab.Content[BSSID_WCID].PairwiseKey.TxTsc[1] = 0;
1013         pAd->MacTab.Content[BSSID_WCID].PairwiseKey.TxTsc[2] = 0;
1014         pAd->MacTab.Content[BSSID_WCID].PairwiseKey.TxTsc[3] = 0;
1015         pAd->MacTab.Content[BSSID_WCID].PairwiseKey.TxTsc[4] = 0;
1016         pAd->MacTab.Content[BSSID_WCID].PairwiseKey.TxTsc[5] = 0;
1017
1018         if (pAd->ApCfg.MBSSID[apidx].WepStatus == Ndis802_11Encryption3Enabled)
1019         {
1020                 pAd->SharedKey[apidx][KeyIdx].CipherAlg = CIPHER_AES;
1021                 pAd->MacTab.Content[BSSID_WCID].PairwiseKey.CipherAlg = CIPHER_AES;
1022         }
1023         else if (pAd->ApCfg.MBSSID[apidx].WepStatus == Ndis802_11Encryption2Enabled)
1024         {
1025                 pAd->SharedKey[apidx][KeyIdx].CipherAlg = CIPHER_TKIP;
1026                 pAd->MacTab.Content[BSSID_WCID].PairwiseKey.CipherAlg = CIPHER_TKIP;
1027         }
1028         else if (pAd->ApCfg.MBSSID[apidx].WepStatus == Ndis802_11Encryption1Enabled)
1029         {
1030                 if (pAd->SharedKey[apidx][KeyIdx].KeyLen == 5)
1031                 {
1032                         pAd->SharedKey[apidx][KeyIdx].CipherAlg = CIPHER_WEP64;
1033                         pAd->MacTab.Content[BSSID_WCID].PairwiseKey.CipherAlg = CIPHER_WEP64;
1034                 }
1035                 else if (pAd->SharedKey[apidx][KeyIdx].KeyLen == 13)
1036                 {
1037                         pAd->SharedKey[apidx][KeyIdx].CipherAlg = CIPHER_WEP128;
1038                         pAd->MacTab.Content[BSSID_WCID].PairwiseKey.CipherAlg = CIPHER_WEP128;
1039                 }
1040                 else
1041                 {
1042                         pAd->SharedKey[apidx][KeyIdx].CipherAlg = CIPHER_NONE;
1043                         pAd->MacTab.Content[BSSID_WCID].PairwiseKey.CipherAlg = CIPHER_NONE;
1044                 }
1045         }
1046         else
1047         {
1048                 pAd->SharedKey[apidx][KeyIdx].CipherAlg = CIPHER_NONE;
1049                 pAd->MacTab.Content[BSSID_WCID].PairwiseKey.CipherAlg = CIPHER_NONE;
1050         }
1051
1052         if ((pAd->OpMode == OPMODE_STA))  // Pairwise Key. Add BSSID to WCTable
1053         {
1054                 pAd->MacTab.Content[BSSID_WCID].PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg;
1055                 pAd->MacTab.Content[BSSID_WCID].PairwiseKey.KeyLen = pAd->SharedKey[BSS0][KeyIdx].KeyLen;
1056         }
1057
1058         if ((pAd->ApCfg.MBSSID[apidx].AuthMode == Ndis802_11AuthModeWPA2) ||
1059                 (pAd->ApCfg.MBSSID[apidx].AuthMode == Ndis802_11AuthModeWPA2PSK))
1060         {
1061                 //
1062                 // On WPA2, Update Group Key Cipher.
1063                 //
1064                 if (!bPairwise)
1065                 {
1066                         if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)
1067                                 pAd->SharedKey[apidx][KeyIdx].CipherAlg = CIPHER_AES;
1068                         else if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)
1069                                 pAd->SharedKey[apidx][KeyIdx].CipherAlg = CIPHER_TKIP;
1070                 }
1071         }
1072
1073         DBGPRINT(RT_DEBUG_TRACE, ("pAd->SharedKey[%d][%d].CipherAlg = %d\n", apidx, KeyIdx, pAd->SharedKey[apidx][KeyIdx].CipherAlg));
1074
1075 #if 0
1076         DBGPRINT_RAW(RT_DEBUG_TRACE, ("%s Key #%d", CipherName[pAd->SharedKey[apidx][KeyIdx].CipherAlg],KeyIdx));
1077         for (i = 0; i < 16; i++)
1078         {
1079                 DBGPRINT_RAW(RT_DEBUG_TRACE, ("%02x:", pAd->SharedKey[apidx][KeyIdx].Key[i]));
1080         }
1081         DBGPRINT_RAW(RT_DEBUG_TRACE, ("\n         Rx MIC Key = "));
1082         for (i = 0; i < 8; i++)
1083         {
1084                 DBGPRINT_RAW(RT_DEBUG_TRACE, ("%02x:", pAd->SharedKey[apidx][KeyIdx].RxMic[i]));
1085         }
1086         DBGPRINT_RAW(RT_DEBUG_TRACE, ("\n         Tx MIC Key = "));
1087         for (i = 0; i < 8; i++)
1088         {
1089                 DBGPRINT_RAW(RT_DEBUG_TRACE, ("%02x:", pAd->SharedKey[apidx][KeyIdx].TxMic[i]));
1090         }
1091         DBGPRINT_RAW(RT_DEBUG_TRACE, ("\n         RxTSC = "));
1092         for (i = 0; i < 6; i++)
1093         {
1094                 DBGPRINT_RAW(RT_DEBUG_TRACE, ("%02x:", pAd->SharedKey[apidx][KeyIdx].RxTsc[i]));
1095         }
1096 #endif
1097         DBGPRINT_RAW(RT_DEBUG_TRACE, ("\n pKey-> BSSID:%02x:%02x:%02x:%02x:%02x:%02x \n",
1098                 pKey->BSSID[0],pKey->BSSID[1],pKey->BSSID[2],pKey->BSSID[3],pKey->BSSID[4],pKey->BSSID[5]));
1099
1100         if ((bTxKey) && (pAd->OpMode == OPMODE_STA))  // Pairwise Key. Add BSSID to WCTable
1101                 RTMPAddBSSIDCipher(pAd, BSSID_WCID, pKey, pAd->SharedKey[BSS0][KeyIdx].CipherAlg);
1102
1103
1104         // No matter pairwise key or what leyidx is, always has a copy at on-chip SharedKeytable.
1105         AsicAddSharedKeyEntry(pAd,
1106                                                   apidx,
1107                                                   (UCHAR)KeyIdx,
1108                                                   pAd->SharedKey[apidx][KeyIdx].CipherAlg,
1109                                                   pAd->SharedKey[apidx][KeyIdx].Key,
1110                                                   pAd->SharedKey[apidx][KeyIdx].TxMic,
1111                                                   pAd->SharedKey[apidx][KeyIdx].RxMic);
1112
1113         // The WCID key specified in used at Tx. For STA, always use pairwise key.
1114
1115         // ad-hoc mode need to specify WAP Group key with WCID index=BSS0Mcast_WCID. Let's always set this key here.
1116 /*      if (bPairwise == FALSE)
1117         {
1118                 offset = MAC_IVEIV_TABLE_BASE + (BSS0Mcast_WCID * HW_IVEIV_ENTRY_SIZE);
1119                 NdisZeroMemory(IVEIV, 8);
1120                 // 1. IV/EIV
1121                 // Specify key index to find shared key.
1122                 if ((pAd->SharedKey[BSS0][KeyIdx].CipherAlg==CIPHER_TKIP) ||
1123                         (pAd->SharedKey[BSS0][KeyIdx].CipherAlg==CIPHER_AES))
1124                 IVEIV[3] = 0x20;                // Eiv bit on. keyid always 0 for pairwise key
1125                 IVEIV[3] |= (KeyIdx<< 6);       // groupkey index is not 0
1126                 for (i=0; i<8; i++)
1127                 {
1128                         RTMP_IO_WRITE8(pAd, offset+i, IVEIV[i]);
1129                 }
1130
1131                 // 2. WCID Attribute UDF:3, BSSIdx:3, Alg:3, Keytable:use share key, BSSIdx is 0
1132                 WCIDAttri = (pAd->SharedKey[BSS0][KeyIdx].CipherAlg<<1)|PAIRWISEKEYTABLE;
1133                 offset = MAC_WCID_ATTRIBUTE_BASE + (BSS0Mcast_WCID* HW_WCID_ATTRI_SIZE);
1134                 RTMP_IO_WRITE32(pAd, offset, WCIDAttri);
1135
1136         }
1137
1138 */
1139
1140    if (pAd->SharedKey[apidx][KeyIdx].Type == GROUP_KEY)
1141         {
1142                 // 802.1x port control
1143                 pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
1144                 DBGPRINT(RT_DEBUG_TRACE,("!!WPA_802_1X_PORT_SECURED!!\n"));
1145
1146         }
1147
1148         return (NDIS_STATUS_SUCCESS);
1149 }
1150 #endif
1151
1152 BOOLEAN RTMPCheckStrPrintAble(
1153     IN  CHAR *pInPutStr,
1154     IN  UCHAR strLen)
1155 {
1156     UCHAR i=0;
1157
1158     for (i=0; i<strLen; i++)
1159     {
1160         if ((pInPutStr[i] < 0x21) ||
1161             (pInPutStr[i] > 0x7E))
1162             return FALSE;
1163     }
1164
1165     return TRUE;
1166 }
1167
1168 /*
1169         ========================================================================
1170
1171         Routine Description:
1172                 Remove WPA Key process
1173
1174         Arguments:
1175                 pAd                                     Pointer to our adapter
1176                 pBuf                                                    Pointer to the where the key stored
1177
1178         Return Value:
1179                 NDIS_SUCCESS                                    Add key successfully
1180
1181         IRQL = DISPATCH_LEVEL
1182
1183         Note:
1184
1185         ========================================================================
1186 */
1187 #ifdef CONFIG_STA_SUPPORT
1188 VOID    RTMPSetDesiredRates(
1189     IN  PRTMP_ADAPTER   pAdapter,
1190     IN  LONG            Rates)
1191 {
1192     NDIS_802_11_RATES aryRates;
1193
1194     memset(&aryRates, 0x00, sizeof(NDIS_802_11_RATES));
1195     switch (pAdapter->CommonCfg.PhyMode)
1196     {
1197         case PHY_11A: // A only
1198             switch (Rates)
1199             {
1200                 case 6000000: //6M
1201                     aryRates[0] = 0x0c; // 6M
1202                     pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_0;
1203                     break;
1204                 case 9000000: //9M
1205                     aryRates[0] = 0x12; // 9M
1206                     pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_1;
1207                     break;
1208                 case 12000000: //12M
1209                     aryRates[0] = 0x18; // 12M
1210                     pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_2;
1211                     break;
1212                 case 18000000: //18M
1213                     aryRates[0] = 0x24; // 18M
1214                     pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_3;
1215                     break;
1216                 case 24000000: //24M
1217                     aryRates[0] = 0x30; // 24M
1218                     pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_4;
1219                     break;
1220                 case 36000000: //36M
1221                     aryRates[0] = 0x48; // 36M
1222                     pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_5;
1223                     break;
1224                 case 48000000: //48M
1225                     aryRates[0] = 0x60; // 48M
1226                     pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_6;
1227                     break;
1228                 case 54000000: //54M
1229                     aryRates[0] = 0x6c; // 54M
1230                     pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_7;
1231                     break;
1232                 case -1: //Auto
1233                 default:
1234                     aryRates[0] = 0x6c; // 54Mbps
1235                     aryRates[1] = 0x60; // 48Mbps
1236                     aryRates[2] = 0x48; // 36Mbps
1237                     aryRates[3] = 0x30; // 24Mbps
1238                     aryRates[4] = 0x24; // 18M
1239                     aryRates[5] = 0x18; // 12M
1240                     aryRates[6] = 0x12; // 9M
1241                     aryRates[7] = 0x0c; // 6M
1242                     pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
1243                     break;
1244             }
1245             break;
1246         case PHY_11BG_MIXED: // B/G Mixed
1247         case PHY_11B: // B only
1248         case PHY_11ABG_MIXED: // A/B/G Mixed
1249         default:
1250             switch (Rates)
1251             {
1252                 case 1000000: //1M
1253                     aryRates[0] = 0x02;
1254                     pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_0;
1255                     break;
1256                 case 2000000: //2M
1257                     aryRates[0] = 0x04;
1258                     pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_1;
1259                     break;
1260                 case 5000000: //5.5M
1261                     aryRates[0] = 0x0b; // 5.5M
1262                     pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_2;
1263                     break;
1264                 case 11000000: //11M
1265                     aryRates[0] = 0x16; // 11M
1266                     pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_3;
1267                     break;
1268                 case 6000000: //6M
1269                     aryRates[0] = 0x0c; // 6M
1270                     pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_0;
1271                     break;
1272                 case 9000000: //9M
1273                     aryRates[0] = 0x12; // 9M
1274                     pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_1;
1275                     break;
1276                 case 12000000: //12M
1277                     aryRates[0] = 0x18; // 12M
1278                     pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_2;
1279                     break;
1280                 case 18000000: //18M
1281                     aryRates[0] = 0x24; // 18M
1282                     pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_3;
1283                     break;
1284                 case 24000000: //24M
1285                     aryRates[0] = 0x30; // 24M
1286                     pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_4;
1287                     break;
1288                 case 36000000: //36M
1289                     aryRates[0] = 0x48; // 36M
1290                     pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_5;
1291                     break;
1292                 case 48000000: //48M
1293                     aryRates[0] = 0x60; // 48M
1294                     pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_6;
1295                     break;
1296                 case 54000000: //54M
1297                     aryRates[0] = 0x6c; // 54M
1298                     pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_7;
1299                     break;
1300                 case -1: //Auto
1301                 default:
1302                     if (pAdapter->CommonCfg.PhyMode == PHY_11B)
1303                     { //B Only
1304                         aryRates[0] = 0x16; // 11Mbps
1305                         aryRates[1] = 0x0b; // 5.5Mbps
1306                         aryRates[2] = 0x04; // 2Mbps
1307                         aryRates[3] = 0x02; // 1Mbps
1308                     }
1309                     else
1310                     { //(B/G) Mixed or (A/B/G) Mixed
1311                         aryRates[0] = 0x6c; // 54Mbps
1312                         aryRates[1] = 0x60; // 48Mbps
1313                         aryRates[2] = 0x48; // 36Mbps
1314                         aryRates[3] = 0x30; // 24Mbps
1315                         aryRates[4] = 0x16; // 11Mbps
1316                         aryRates[5] = 0x0b; // 5.5Mbps
1317                         aryRates[6] = 0x04; // 2Mbps
1318                         aryRates[7] = 0x02; // 1Mbps
1319                     }
1320                     pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
1321                     break;
1322             }
1323             break;
1324     }
1325
1326     NdisZeroMemory(pAdapter->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES);
1327     NdisMoveMemory(pAdapter->CommonCfg.DesireRate, &aryRates, sizeof(NDIS_802_11_RATES));
1328     DBGPRINT(RT_DEBUG_TRACE, (" RTMPSetDesiredRates (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
1329         pAdapter->CommonCfg.DesireRate[0],pAdapter->CommonCfg.DesireRate[1],
1330         pAdapter->CommonCfg.DesireRate[2],pAdapter->CommonCfg.DesireRate[3],
1331         pAdapter->CommonCfg.DesireRate[4],pAdapter->CommonCfg.DesireRate[5],
1332         pAdapter->CommonCfg.DesireRate[6],pAdapter->CommonCfg.DesireRate[7] ));
1333     // Changing DesiredRate may affect the MAX TX rate we used to TX frames out
1334     MlmeUpdateTxRates(pAdapter, FALSE, 0);
1335 }
1336
1337 NDIS_STATUS RTMPWPARemoveKeyProc(
1338         IN      PRTMP_ADAPTER   pAd,
1339         IN      PVOID                   pBuf)
1340 {
1341         PNDIS_802_11_REMOVE_KEY pKey;
1342         ULONG                                   KeyIdx;
1343         NDIS_STATUS                     Status = NDIS_STATUS_FAILURE;
1344         BOOLEAN         bTxKey;                 // Set the key as transmit key
1345         BOOLEAN         bPairwise;              // Indicate the key is pairwise key
1346         BOOLEAN         bKeyRSC;                // indicate the receive  SC set by KeyRSC value.
1347                                                                 // Otherwise, it will set by the NIC.
1348         BOOLEAN         bAuthenticator; // indicate key is set by authenticator.
1349         INT             i;
1350
1351         DBGPRINT(RT_DEBUG_TRACE,("---> RTMPWPARemoveKeyProc\n"));
1352
1353         pKey = (PNDIS_802_11_REMOVE_KEY) pBuf;
1354         KeyIdx = pKey->KeyIndex & 0xff;
1355         // Bit 31 of Add-key, Tx Key
1356         bTxKey             = (pKey->KeyIndex & 0x80000000) ? TRUE : FALSE;
1357         // Bit 30 of Add-key PairwiseKey
1358         bPairwise          = (pKey->KeyIndex & 0x40000000) ? TRUE : FALSE;
1359         // Bit 29 of Add-key KeyRSC
1360         bKeyRSC            = (pKey->KeyIndex & 0x20000000) ? TRUE : FALSE;
1361         // Bit 28 of Add-key Authenticator
1362         bAuthenticator = (pKey->KeyIndex & 0x10000000) ? TRUE : FALSE;
1363
1364         // 1. If bTx is TRUE, return failure information
1365         if (bTxKey == TRUE)
1366                 return(NDIS_STATUS_INVALID_DATA);
1367
1368         // 2. Check Pairwise Key
1369         if (bPairwise)
1370         {
1371                 // a. If BSSID is broadcast, remove all pairwise keys.
1372                 // b. If not broadcast, remove the pairwise specified by BSSID
1373                 for (i = 0; i < SHARE_KEY_NUM; i++)
1374                 {
1375                         if (MAC_ADDR_EQUAL(pAd->SharedKey[BSS0][i].BssId, pKey->BSSID))
1376                         {
1377                                 DBGPRINT(RT_DEBUG_TRACE,("RTMPWPARemoveKeyProc(KeyIdx=%d)\n", i));
1378                                 pAd->SharedKey[BSS0][i].KeyLen = 0;
1379                                 pAd->SharedKey[BSS0][i].CipherAlg = CIPHER_NONE;
1380                                 AsicRemoveSharedKeyEntry(pAd, BSS0, (UCHAR)i);
1381                                 Status = NDIS_STATUS_SUCCESS;
1382                                 break;
1383                         }
1384                 }
1385         }
1386         // 3. Group Key
1387         else
1388         {
1389                 // a. If BSSID is broadcast, remove all group keys indexed
1390                 // b. If BSSID matched, delete the group key indexed.
1391                 DBGPRINT(RT_DEBUG_TRACE,("RTMPWPARemoveKeyProc(KeyIdx=%ld)\n", KeyIdx));
1392                 pAd->SharedKey[BSS0][KeyIdx].KeyLen = 0;
1393                 pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
1394                 AsicRemoveSharedKeyEntry(pAd, BSS0, (UCHAR)KeyIdx);
1395                 Status = NDIS_STATUS_SUCCESS;
1396         }
1397
1398         return (Status);
1399 }
1400 #endif // CONFIG_STA_SUPPORT //
1401
1402
1403 #ifdef CONFIG_STA_SUPPORT
1404 /*
1405         ========================================================================
1406
1407         Routine Description:
1408                 Remove All WPA Keys
1409
1410         Arguments:
1411                 pAd                                     Pointer to our adapter
1412
1413         Return Value:
1414                 None
1415
1416         IRQL = DISPATCH_LEVEL
1417
1418         Note:
1419
1420         ========================================================================
1421 */
1422 VOID    RTMPWPARemoveAllKeys(
1423         IN      PRTMP_ADAPTER   pAd)
1424 {
1425
1426         UCHAR   i;
1427
1428         DBGPRINT(RT_DEBUG_TRACE,("RTMPWPARemoveAllKeys(AuthMode=%d, WepStatus=%d)\n", pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus));
1429
1430         // For WEP/CKIP, there is no need to remove it, since WinXP won't set it again after
1431         // Link up. And it will be replaced if user changed it.
1432         if (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
1433                 return;
1434
1435         // For WPA-None, there is no need to remove it, since WinXP won't set it again after
1436         // Link up. And it will be replaced if user changed it.
1437         if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
1438                 return;
1439
1440         // set BSSID wcid entry of the Pair-wise Key table as no-security mode
1441         AsicRemovePairwiseKeyEntry(pAd, BSS0, BSSID_WCID);
1442
1443         // set all shared key mode as no-security.
1444         for (i = 0; i < SHARE_KEY_NUM; i++)
1445     {
1446                 DBGPRINT(RT_DEBUG_TRACE,("remove %s key #%d\n", CipherName[pAd->SharedKey[BSS0][i].CipherAlg], i));
1447                 NdisZeroMemory(&pAd->SharedKey[BSS0][i], sizeof(CIPHER_KEY));
1448
1449                 AsicRemoveSharedKeyEntry(pAd, BSS0, i);
1450         }
1451
1452 }
1453 #endif // CONFIG_STA_SUPPORT //
1454
1455 /*
1456         ========================================================================
1457         Routine Description:
1458                 Change NIC PHY mode. Re-association may be necessary. possible settings
1459                 include - PHY_11B, PHY_11BG_MIXED, PHY_11A, and PHY_11ABG_MIXED
1460
1461         Arguments:
1462                 pAd - Pointer to our adapter
1463                 phymode  -
1464
1465         IRQL = PASSIVE_LEVEL
1466         IRQL = DISPATCH_LEVEL
1467
1468         ========================================================================
1469 */
1470 VOID    RTMPSetPhyMode(
1471         IN      PRTMP_ADAPTER   pAd,
1472         IN      ULONG phymode)
1473 {
1474         INT i;
1475         // the selected phymode must be supported by the RF IC encoded in E2PROM
1476
1477         // if no change, do nothing
1478         /* bug fix
1479         if (pAd->CommonCfg.PhyMode == phymode)
1480                 return;
1481     */
1482         pAd->CommonCfg.PhyMode = (UCHAR)phymode;
1483
1484         DBGPRINT(RT_DEBUG_TRACE,("RTMPSetPhyMode : PhyMode=%d, channel=%d \n", pAd->CommonCfg.PhyMode, pAd->CommonCfg.Channel));
1485
1486         BuildChannelList(pAd);
1487
1488         // sanity check user setting
1489         for (i = 0; i < pAd->ChannelListNum; i++)
1490         {
1491                 if (pAd->CommonCfg.Channel == pAd->ChannelList[i].Channel)
1492                         break;
1493         }
1494
1495         if (i == pAd->ChannelListNum)
1496         {
1497 #ifdef CONFIG_STA_SUPPORT
1498                 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1499                         pAd->CommonCfg.Channel = FirstChannel(pAd);
1500 #endif // CONFIG_STA_SUPPORT //
1501                 DBGPRINT(RT_DEBUG_ERROR, ("RTMPSetPhyMode: channel is out of range, use first channel=%d \n", pAd->CommonCfg.Channel));
1502         }
1503
1504         NdisZeroMemory(pAd->CommonCfg.SupRate, MAX_LEN_OF_SUPPORTED_RATES);
1505         NdisZeroMemory(pAd->CommonCfg.ExtRate, MAX_LEN_OF_SUPPORTED_RATES);
1506         NdisZeroMemory(pAd->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES);
1507         switch (phymode) {
1508                 case PHY_11B:
1509                         pAd->CommonCfg.SupRate[0]  = 0x82;        // 1 mbps, in units of 0.5 Mbps, basic rate
1510                         pAd->CommonCfg.SupRate[1]  = 0x84;        // 2 mbps, in units of 0.5 Mbps, basic rate
1511                         pAd->CommonCfg.SupRate[2]  = 0x8B;        // 5.5 mbps, in units of 0.5 Mbps, basic rate
1512                         pAd->CommonCfg.SupRate[3]  = 0x96;        // 11 mbps, in units of 0.5 Mbps, basic rate
1513                         pAd->CommonCfg.SupRateLen  = 4;
1514                         pAd->CommonCfg.ExtRateLen  = 0;
1515                         pAd->CommonCfg.DesireRate[0]  = 2;         // 1 mbps, in units of 0.5 Mbps
1516                         pAd->CommonCfg.DesireRate[1]  = 4;         // 2 mbps, in units of 0.5 Mbps
1517                         pAd->CommonCfg.DesireRate[2]  = 11;    // 5.5 mbps, in units of 0.5 Mbps
1518                         pAd->CommonCfg.DesireRate[3]  = 22;    // 11 mbps, in units of 0.5 Mbps
1519                         //pAd->CommonCfg.HTPhyMode.field.MODE = MODE_CCK; // This MODE is only FYI. not use
1520                         break;
1521
1522                 case PHY_11G:
1523                 case PHY_11BG_MIXED:
1524                 case PHY_11ABG_MIXED:
1525 #ifdef DOT11_N_SUPPORT
1526                 case PHY_11N_2_4G:
1527                 case PHY_11ABGN_MIXED:
1528                 case PHY_11BGN_MIXED:
1529                 case PHY_11GN_MIXED:
1530 #endif // DOT11_N_SUPPORT //
1531                         pAd->CommonCfg.SupRate[0]  = 0x82;        // 1 mbps, in units of 0.5 Mbps, basic rate
1532                         pAd->CommonCfg.SupRate[1]  = 0x84;        // 2 mbps, in units of 0.5 Mbps, basic rate
1533                         pAd->CommonCfg.SupRate[2]  = 0x8B;        // 5.5 mbps, in units of 0.5 Mbps, basic rate
1534                         pAd->CommonCfg.SupRate[3]  = 0x96;        // 11 mbps, in units of 0.5 Mbps, basic rate
1535                         pAd->CommonCfg.SupRate[4]  = 0x12;        // 9 mbps, in units of 0.5 Mbps
1536                         pAd->CommonCfg.SupRate[5]  = 0x24;        // 18 mbps, in units of 0.5 Mbps
1537                         pAd->CommonCfg.SupRate[6]  = 0x48;        // 36 mbps, in units of 0.5 Mbps
1538                         pAd->CommonCfg.SupRate[7]  = 0x6c;        // 54 mbps, in units of 0.5 Mbps
1539                         pAd->CommonCfg.SupRateLen  = 8;
1540                         pAd->CommonCfg.ExtRate[0]  = 0x0C;        // 6 mbps, in units of 0.5 Mbps
1541                         pAd->CommonCfg.ExtRate[1]  = 0x18;        // 12 mbps, in units of 0.5 Mbps
1542                         pAd->CommonCfg.ExtRate[2]  = 0x30;        // 24 mbps, in units of 0.5 Mbps
1543                         pAd->CommonCfg.ExtRate[3]  = 0x60;        // 48 mbps, in units of 0.5 Mbps
1544                         pAd->CommonCfg.ExtRateLen  = 4;
1545                         pAd->CommonCfg.DesireRate[0]  = 2;         // 1 mbps, in units of 0.5 Mbps
1546                         pAd->CommonCfg.DesireRate[1]  = 4;         // 2 mbps, in units of 0.5 Mbps
1547                         pAd->CommonCfg.DesireRate[2]  = 11;    // 5.5 mbps, in units of 0.5 Mbps
1548                         pAd->CommonCfg.DesireRate[3]  = 22;    // 11 mbps, in units of 0.5 Mbps
1549                         pAd->CommonCfg.DesireRate[4]  = 12;    // 6 mbps, in units of 0.5 Mbps
1550                         pAd->CommonCfg.DesireRate[5]  = 18;    // 9 mbps, in units of 0.5 Mbps
1551                         pAd->CommonCfg.DesireRate[6]  = 24;    // 12 mbps, in units of 0.5 Mbps
1552                         pAd->CommonCfg.DesireRate[7]  = 36;    // 18 mbps, in units of 0.5 Mbps
1553                         pAd->CommonCfg.DesireRate[8]  = 48;    // 24 mbps, in units of 0.5 Mbps
1554                         pAd->CommonCfg.DesireRate[9]  = 72;    // 36 mbps, in units of 0.5 Mbps
1555                         pAd->CommonCfg.DesireRate[10] = 96;    // 48 mbps, in units of 0.5 Mbps
1556                         pAd->CommonCfg.DesireRate[11] = 108;   // 54 mbps, in units of 0.5 Mbps
1557                         break;
1558
1559                 case PHY_11A:
1560 #ifdef DOT11_N_SUPPORT
1561                 case PHY_11AN_MIXED:
1562                 case PHY_11AGN_MIXED:
1563                 case PHY_11N_5G:
1564 #endif // DOT11_N_SUPPORT //
1565                         pAd->CommonCfg.SupRate[0]  = 0x8C;        // 6 mbps, in units of 0.5 Mbps, basic rate
1566                         pAd->CommonCfg.SupRate[1]  = 0x12;        // 9 mbps, in units of 0.5 Mbps
1567                         pAd->CommonCfg.SupRate[2]  = 0x98;        // 12 mbps, in units of 0.5 Mbps, basic rate
1568                         pAd->CommonCfg.SupRate[3]  = 0x24;        // 18 mbps, in units of 0.5 Mbps
1569                         pAd->CommonCfg.SupRate[4]  = 0xb0;        // 24 mbps, in units of 0.5 Mbps, basic rate
1570                         pAd->CommonCfg.SupRate[5]  = 0x48;        // 36 mbps, in units of 0.5 Mbps
1571                         pAd->CommonCfg.SupRate[6]  = 0x60;        // 48 mbps, in units of 0.5 Mbps
1572                         pAd->CommonCfg.SupRate[7]  = 0x6c;        // 54 mbps, in units of 0.5 Mbps
1573                         pAd->CommonCfg.SupRateLen  = 8;
1574                         pAd->CommonCfg.ExtRateLen  = 0;
1575                         pAd->CommonCfg.DesireRate[0]  = 12;    // 6 mbps, in units of 0.5 Mbps
1576                         pAd->CommonCfg.DesireRate[1]  = 18;    // 9 mbps, in units of 0.5 Mbps
1577                         pAd->CommonCfg.DesireRate[2]  = 24;    // 12 mbps, in units of 0.5 Mbps
1578                         pAd->CommonCfg.DesireRate[3]  = 36;    // 18 mbps, in units of 0.5 Mbps
1579                         pAd->CommonCfg.DesireRate[4]  = 48;    // 24 mbps, in units of 0.5 Mbps
1580                         pAd->CommonCfg.DesireRate[5]  = 72;    // 36 mbps, in units of 0.5 Mbps
1581                         pAd->CommonCfg.DesireRate[6]  = 96;    // 48 mbps, in units of 0.5 Mbps
1582                         pAd->CommonCfg.DesireRate[7]  = 108;   // 54 mbps, in units of 0.5 Mbps
1583                         //pAd->CommonCfg.HTPhyMode.field.MODE = MODE_OFDM; // This MODE is only FYI. not use
1584                         break;
1585
1586                 default:
1587                         break;
1588         }
1589
1590
1591         pAd->CommonCfg.BandState = UNKNOWN_BAND;
1592 }
1593
1594
1595 #ifdef DOT11_N_SUPPORT
1596 /*
1597         ========================================================================
1598         Routine Description:
1599                 Caller ensures we has 802.11n support.
1600                 Calls at setting HT from AP/STASetinformation
1601
1602         Arguments:
1603                 pAd - Pointer to our adapter
1604                 phymode  -
1605
1606         ========================================================================
1607 */
1608 VOID    RTMPSetHT(
1609         IN      PRTMP_ADAPTER   pAd,
1610         IN      OID_SET_HT_PHYMODE *pHTPhyMode)
1611 {
1612         //ULONG *pmcs;
1613         UINT32  Value = 0;
1614         UCHAR   BBPValue = 0;
1615         UCHAR   BBP3Value = 0;
1616         UCHAR   RxStream = pAd->CommonCfg.RxStream;
1617
1618         DBGPRINT(RT_DEBUG_TRACE, ("RTMPSetHT : HT_mode(%d), ExtOffset(%d), MCS(%d), BW(%d), STBC(%d), SHORTGI(%d)\n",
1619                                                                                 pHTPhyMode->HtMode, pHTPhyMode->ExtOffset,
1620                                                                                 pHTPhyMode->MCS, pHTPhyMode->BW,
1621                                                                                 pHTPhyMode->STBC, pHTPhyMode->SHORTGI));
1622
1623         // Don't zero supportedHyPhy structure.
1624         RTMPZeroMemory(&pAd->CommonCfg.HtCapability, sizeof(pAd->CommonCfg.HtCapability));
1625         RTMPZeroMemory(&pAd->CommonCfg.AddHTInfo, sizeof(pAd->CommonCfg.AddHTInfo));
1626         RTMPZeroMemory(&pAd->CommonCfg.NewExtChanOffset, sizeof(pAd->CommonCfg.NewExtChanOffset));
1627         RTMPZeroMemory(&pAd->CommonCfg.DesiredHtPhy, sizeof(pAd->CommonCfg.DesiredHtPhy));
1628
1629         if (pAd->CommonCfg.bRdg)
1630         {
1631                 pAd->CommonCfg.HtCapability.ExtHtCapInfo.PlusHTC = 1;
1632                 pAd->CommonCfg.HtCapability.ExtHtCapInfo.RDGSupport = 1;
1633         }
1634         else
1635         {
1636                 pAd->CommonCfg.HtCapability.ExtHtCapInfo.PlusHTC = 0;
1637                 pAd->CommonCfg.HtCapability.ExtHtCapInfo.RDGSupport = 0;
1638         }
1639
1640         pAd->CommonCfg.HtCapability.HtCapParm.MaxRAmpduFactor = 3;
1641         pAd->CommonCfg.DesiredHtPhy.MaxRAmpduFactor = 3;
1642
1643         DBGPRINT(RT_DEBUG_TRACE, ("RTMPSetHT : RxBAWinLimit = %d\n", pAd->CommonCfg.BACapability.field.RxBAWinLimit));
1644
1645         // Mimo power save, A-MSDU size,
1646         pAd->CommonCfg.DesiredHtPhy.AmsduEnable = (USHORT)pAd->CommonCfg.BACapability.field.AmsduEnable;
1647         pAd->CommonCfg.DesiredHtPhy.AmsduSize = (UCHAR)pAd->CommonCfg.BACapability.field.AmsduSize;
1648         pAd->CommonCfg.DesiredHtPhy.MimoPs = (UCHAR)pAd->CommonCfg.BACapability.field.MMPSmode;
1649         pAd->CommonCfg.DesiredHtPhy.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
1650
1651         pAd->CommonCfg.HtCapability.HtCapInfo.AMsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
1652         pAd->CommonCfg.HtCapability.HtCapInfo.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
1653         pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
1654
1655         DBGPRINT(RT_DEBUG_TRACE, ("RTMPSetHT : AMsduSize = %d, MimoPs = %d, MpduDensity = %d, MaxRAmpduFactor = %d\n",
1656                                                                                                         pAd->CommonCfg.DesiredHtPhy.AmsduSize,
1657                                                                                                         pAd->CommonCfg.DesiredHtPhy.MimoPs,
1658                                                                                                         pAd->CommonCfg.DesiredHtPhy.MpduDensity,
1659                                                                                                         pAd->CommonCfg.DesiredHtPhy.MaxRAmpduFactor));
1660
1661         if(pHTPhyMode->HtMode == HTMODE_GF)
1662         {
1663                 pAd->CommonCfg.HtCapability.HtCapInfo.GF = 1;
1664                 pAd->CommonCfg.DesiredHtPhy.GF = 1;
1665         }
1666         else
1667                 pAd->CommonCfg.DesiredHtPhy.GF = 0;
1668
1669         // Decide Rx MCSSet
1670         switch (RxStream)
1671         {
1672                 case 1:
1673                         pAd->CommonCfg.HtCapability.MCSSet[0] =  0xff;
1674                         pAd->CommonCfg.HtCapability.MCSSet[1] =  0x00;
1675                         break;
1676
1677                 case 2:
1678                         pAd->CommonCfg.HtCapability.MCSSet[0] =  0xff;
1679                         pAd->CommonCfg.HtCapability.MCSSet[1] =  0xff;
1680                         break;
1681
1682                 case 3: // 3*3
1683                         pAd->CommonCfg.HtCapability.MCSSet[0] =  0xff;
1684                         pAd->CommonCfg.HtCapability.MCSSet[1] =  0xff;
1685                         pAd->CommonCfg.HtCapability.MCSSet[2] =  0xff;
1686                         break;
1687         }
1688
1689         if (pAd->CommonCfg.bForty_Mhz_Intolerant && (pAd->CommonCfg.Channel <= 14) && (pHTPhyMode->BW == BW_40) )
1690         {
1691                 pHTPhyMode->BW = BW_20;
1692                 pAd->CommonCfg.HtCapability.HtCapInfo.Forty_Mhz_Intolerant = 1;
1693         }
1694
1695         if(pHTPhyMode->BW == BW_40)
1696         {
1697                 pAd->CommonCfg.HtCapability.MCSSet[4] = 0x1; // MCS 32
1698                 pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth = 1;
1699                 if (pAd->CommonCfg.Channel <= 14)
1700                         pAd->CommonCfg.HtCapability.HtCapInfo.CCKmodein40 = 1;
1701
1702                 pAd->CommonCfg.DesiredHtPhy.ChannelWidth = 1;
1703                 pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth = 1;
1704                 pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset = (pHTPhyMode->ExtOffset == EXTCHA_BELOW)? (EXTCHA_BELOW): EXTCHA_ABOVE;
1705                 // Set Regsiter for extension channel position.
1706                 RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value);
1707                 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBP3Value);
1708                 if ((pHTPhyMode->ExtOffset == EXTCHA_BELOW))
1709                 {
1710                         Value |= 0x1;
1711                         BBP3Value |= (0x20);
1712                         RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
1713                 }
1714                 else if ((pHTPhyMode->ExtOffset == EXTCHA_ABOVE))
1715                 {
1716                         Value &= 0xfe;
1717                         BBP3Value &= (~0x20);
1718                         RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
1719                 }
1720
1721                 // Turn on BBP 40MHz mode now only as AP .
1722                 // Sta can turn on BBP 40MHz after connection with 40MHz AP. Sta only broadcast 40MHz capability before connection.
1723                 if ((pAd->OpMode == OPMODE_AP) || INFRA_ON(pAd) || ADHOC_ON(pAd)
1724                         )
1725                 {
1726                         RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
1727                         BBPValue &= (~0x18);
1728                         BBPValue |= 0x10;
1729                         RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
1730
1731                         RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBP3Value);
1732                         pAd->CommonCfg.BBPCurrentBW = BW_40;
1733                 }
1734         }
1735         else
1736         {
1737                 pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth = 0;
1738                 pAd->CommonCfg.DesiredHtPhy.ChannelWidth = 0;
1739                 pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth = 0;
1740                 pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset = EXTCHA_NONE;
1741                 pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel;
1742                 // Turn on BBP 20MHz mode by request here.
1743                 {
1744                         RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
1745                         BBPValue &= (~0x18);
1746                         RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
1747                         pAd->CommonCfg.BBPCurrentBW = BW_20;
1748                 }
1749         }
1750
1751         if(pHTPhyMode->STBC == STBC_USE)
1752         {
1753                 pAd->CommonCfg.HtCapability.HtCapInfo.TxSTBC = 1;
1754                 pAd->CommonCfg.DesiredHtPhy.TxSTBC = 1;
1755                 pAd->CommonCfg.HtCapability.HtCapInfo.RxSTBC = 1;
1756                 pAd->CommonCfg.DesiredHtPhy.RxSTBC = 1;
1757         }
1758         else
1759         {
1760                 pAd->CommonCfg.DesiredHtPhy.TxSTBC = 0;
1761                 pAd->CommonCfg.DesiredHtPhy.RxSTBC = 0;
1762         }
1763
1764 #ifdef RT2870
1765         /* Frank recommend ,If not, Tx maybe block in high power. Rx has no problem*/
1766         if(IS_RT3070(pAd) && ((pAd->RfIcType == RFIC_3020) || (pAd->RfIcType == RFIC_2020)))
1767         {
1768                 pAd->CommonCfg.HtCapability.HtCapInfo.TxSTBC = 0;
1769                 pAd->CommonCfg.DesiredHtPhy.TxSTBC = 0;
1770         }
1771 #endif // RT2870 //
1772
1773         if(pHTPhyMode->SHORTGI == GI_400)
1774         {
1775                 pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor20 = 1;
1776                 pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor40 = 1;
1777                 pAd->CommonCfg.DesiredHtPhy.ShortGIfor20 = 1;
1778                 pAd->CommonCfg.DesiredHtPhy.ShortGIfor40 = 1;
1779         }
1780         else
1781         {
1782                 pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor20 = 0;
1783                 pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor40 = 0;
1784                 pAd->CommonCfg.DesiredHtPhy.ShortGIfor20 = 0;
1785                 pAd->CommonCfg.DesiredHtPhy.ShortGIfor40 = 0;
1786         }
1787
1788         // We support link adaptation for unsolicit MCS feedback, set to 2.
1789         pAd->CommonCfg.HtCapability.ExtHtCapInfo.MCSFeedback = MCSFBK_NONE; //MCSFBK_UNSOLICIT;
1790         pAd->CommonCfg.AddHTInfo.ControlChan = pAd->CommonCfg.Channel;
1791         // 1, the extension channel above the control channel.
1792
1793         // EDCA parameters used for AP's own transmission
1794         if (pAd->CommonCfg.APEdcaParm.bValid == FALSE)
1795         {
1796                 pAd->CommonCfg.APEdcaParm.bValid = TRUE;
1797                 pAd->CommonCfg.APEdcaParm.Aifsn[0] = 3;
1798                 pAd->CommonCfg.APEdcaParm.Aifsn[1] = 7;
1799                 pAd->CommonCfg.APEdcaParm.Aifsn[2] = 1;
1800                 pAd->CommonCfg.APEdcaParm.Aifsn[3] = 1;
1801
1802                 pAd->CommonCfg.APEdcaParm.Cwmin[0] = 4;
1803                 pAd->CommonCfg.APEdcaParm.Cwmin[1] = 4;
1804                 pAd->CommonCfg.APEdcaParm.Cwmin[2] = 3;
1805                 pAd->CommonCfg.APEdcaParm.Cwmin[3] = 2;
1806
1807                 pAd->CommonCfg.APEdcaParm.Cwmax[0] = 6;
1808                 pAd->CommonCfg.APEdcaParm.Cwmax[1] = 10;
1809                 pAd->CommonCfg.APEdcaParm.Cwmax[2] = 4;
1810                 pAd->CommonCfg.APEdcaParm.Cwmax[3] = 3;
1811
1812                 pAd->CommonCfg.APEdcaParm.Txop[0]  = 0;
1813                 pAd->CommonCfg.APEdcaParm.Txop[1]  = 0;
1814                 pAd->CommonCfg.APEdcaParm.Txop[2]  = 94;
1815                 pAd->CommonCfg.APEdcaParm.Txop[3]  = 47;
1816         }
1817         AsicSetEdcaParm(pAd, &pAd->CommonCfg.APEdcaParm);
1818
1819
1820 #ifdef CONFIG_STA_SUPPORT
1821         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1822         {
1823                 RTMPSetIndividualHT(pAd, 0);
1824         }
1825 #endif // CONFIG_STA_SUPPORT //
1826
1827 }
1828
1829 /*
1830         ========================================================================
1831         Routine Description:
1832                 Caller ensures we has 802.11n support.
1833                 Calls at setting HT from AP/STASetinformation
1834
1835         Arguments:
1836                 pAd - Pointer to our adapter
1837                 phymode  -
1838
1839         ========================================================================
1840 */
1841 VOID    RTMPSetIndividualHT(
1842         IN      PRTMP_ADAPTER           pAd,
1843         IN      UCHAR                           apidx)
1844 {
1845         PRT_HT_PHY_INFO         pDesired_ht_phy = NULL;
1846         UCHAR   TxStream = pAd->CommonCfg.TxStream;
1847         UCHAR   DesiredMcs      = MCS_AUTO;
1848
1849         do
1850         {
1851
1852 #ifdef CONFIG_STA_SUPPORT
1853                 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1854                 {
1855                         pDesired_ht_phy = &pAd->StaCfg.DesiredHtPhyInfo;
1856                         DesiredMcs = pAd->StaCfg.DesiredTransmitSetting.field.MCS;
1857                         //pAd->StaCfg.bAutoTxRateSwitch = (DesiredMcs == MCS_AUTO) ? TRUE : FALSE;
1858                                 break;
1859                 }
1860 #endif // CONFIG_STA_SUPPORT //
1861         } while (FALSE);
1862
1863         if (pDesired_ht_phy == NULL)
1864         {
1865                 DBGPRINT(RT_DEBUG_ERROR, ("RTMPSetIndividualHT: invalid apidx(%d)\n", apidx));
1866                 return;
1867         }
1868         RTMPZeroMemory(pDesired_ht_phy, sizeof(RT_HT_PHY_INFO));
1869
1870         DBGPRINT(RT_DEBUG_TRACE, ("RTMPSetIndividualHT : Desired MCS = %d\n", DesiredMcs));
1871         // Check the validity of MCS
1872         if ((TxStream == 1) && ((DesiredMcs >= MCS_8) && (DesiredMcs <= MCS_15)))
1873         {
1874                 DBGPRINT(RT_DEBUG_WARN, ("RTMPSetIndividualHT: MCS(%d) is invalid in 1S, reset it as MCS_7\n", DesiredMcs));
1875                 DesiredMcs = MCS_7;
1876         }
1877
1878         if ((pAd->CommonCfg.DesiredHtPhy.ChannelWidth == BW_20) && (DesiredMcs == MCS_32))
1879         {
1880                 DBGPRINT(RT_DEBUG_WARN, ("RTMPSetIndividualHT: MCS_32 is only supported in 40-MHz, reset it as MCS_0\n"));
1881                 DesiredMcs = MCS_0;
1882         }
1883
1884         pDesired_ht_phy->bHtEnable = TRUE;
1885
1886         // Decide desired Tx MCS
1887         switch (TxStream)
1888         {
1889                 case 1:
1890                         if (DesiredMcs == MCS_AUTO)
1891                         {
1892                                 pDesired_ht_phy->MCSSet[0]= 0xff;
1893                                 pDesired_ht_phy->MCSSet[1]= 0x00;
1894                         }
1895                         else if (DesiredMcs <= MCS_7)
1896                         {
1897                                 pDesired_ht_phy->MCSSet[0]= 1<<DesiredMcs;
1898                                 pDesired_ht_phy->MCSSet[1]= 0x00;
1899                         }
1900                         break;
1901
1902                 case 2:
1903                         if (DesiredMcs == MCS_AUTO)
1904                         {
1905                                 pDesired_ht_phy->MCSSet[0]= 0xff;
1906                                 pDesired_ht_phy->MCSSet[1]= 0xff;
1907                         }
1908                         else if (DesiredMcs <= MCS_15)
1909                         {
1910                                 ULONG mode;
1911
1912                                 mode = DesiredMcs / 8;
1913                                 if (mode < 2)
1914                                         pDesired_ht_phy->MCSSet[mode] = (1 << (DesiredMcs - mode * 8));
1915                         }
1916                         break;
1917
1918                 case 3: // 3*3
1919                         if (DesiredMcs == MCS_AUTO)
1920                         {
1921                                 /* MCS0 ~ MCS23, 3 bytes */
1922                                 pDesired_ht_phy->MCSSet[0]= 0xff;
1923                                 pDesired_ht_phy->MCSSet[1]= 0xff;
1924                                 pDesired_ht_phy->MCSSet[2]= 0xff;
1925                         }
1926                         else if (DesiredMcs <= MCS_23)
1927                         {
1928                                 ULONG mode;
1929
1930                                 mode = DesiredMcs / 8;
1931                                 if (mode < 3)
1932                                         pDesired_ht_phy->MCSSet[mode] = (1 << (DesiredMcs - mode * 8));
1933                         }
1934                         break;
1935         }
1936
1937         if(pAd->CommonCfg.DesiredHtPhy.ChannelWidth == BW_40)
1938         {
1939                 if (DesiredMcs == MCS_AUTO || DesiredMcs == MCS_32)
1940                         pDesired_ht_phy->MCSSet[4] = 0x1;
1941         }
1942
1943         // update HT Rate setting
1944     if (pAd->OpMode == OPMODE_STA)
1945         MlmeUpdateHtTxRates(pAd, BSS0);
1946     else
1947             MlmeUpdateHtTxRates(pAd, apidx);
1948 }
1949
1950
1951 /*
1952         ========================================================================
1953         Routine Description:
1954                 Update HT IE from our capability.
1955
1956         Arguments:
1957                 Send all HT IE in beacon/probe rsp/assoc rsp/action frame.
1958
1959
1960         ========================================================================
1961 */
1962 VOID    RTMPUpdateHTIE(
1963         IN      RT_HT_CAPABILITY        *pRtHt,
1964         IN              UCHAR                           *pMcsSet,
1965         OUT             HT_CAPABILITY_IE *pHtCapability,
1966         OUT             ADD_HT_INFO_IE          *pAddHtInfo)
1967 {
1968         RTMPZeroMemory(pHtCapability, sizeof(HT_CAPABILITY_IE));
1969         RTMPZeroMemory(pAddHtInfo, sizeof(ADD_HT_INFO_IE));
1970
1971                 pHtCapability->HtCapInfo.ChannelWidth = pRtHt->ChannelWidth;
1972                 pHtCapability->HtCapInfo.MimoPs = pRtHt->MimoPs;
1973                 pHtCapability->HtCapInfo.GF = pRtHt->GF;
1974                 pHtCapability->HtCapInfo.ShortGIfor20 = pRtHt->ShortGIfor20;
1975                 pHtCapability->HtCapInfo.ShortGIfor40 = pRtHt->ShortGIfor40;
1976                 pHtCapability->HtCapInfo.TxSTBC = pRtHt->TxSTBC;
1977                 pHtCapability->HtCapInfo.RxSTBC = pRtHt->RxSTBC;
1978                 pHtCapability->HtCapInfo.AMsduSize = pRtHt->AmsduSize;
1979                 pHtCapability->HtCapParm.MaxRAmpduFactor = pRtHt->MaxRAmpduFactor;
1980                 pHtCapability->HtCapParm.MpduDensity = pRtHt->MpduDensity;
1981
1982                 pAddHtInfo->AddHtInfo.ExtChanOffset = pRtHt->ExtChanOffset ;
1983                 pAddHtInfo->AddHtInfo.RecomWidth = pRtHt->RecomWidth;
1984                 pAddHtInfo->AddHtInfo2.OperaionMode = pRtHt->OperaionMode;
1985                 pAddHtInfo->AddHtInfo2.NonGfPresent = pRtHt->NonGfPresent;
1986                 RTMPMoveMemory(pAddHtInfo->MCSSet, /*pRtHt->MCSSet*/pMcsSet, 4); // rt2860 only support MCS max=32, no need to copy all 16 uchar.
1987
1988         DBGPRINT(RT_DEBUG_TRACE,("RTMPUpdateHTIE <== \n"));
1989 }
1990 #endif // DOT11_N_SUPPORT //
1991
1992 /*
1993         ========================================================================
1994         Description:
1995                 Add Client security information into ASIC WCID table and IVEIV table.
1996     Return:
1997         ========================================================================
1998 */
1999 VOID    RTMPAddWcidAttributeEntry(
2000         IN      PRTMP_ADAPTER   pAd,
2001         IN      UCHAR                   BssIdx,
2002         IN      UCHAR                   KeyIdx,
2003         IN      UCHAR                   CipherAlg,
2004         IN      MAC_TABLE_ENTRY *pEntry)
2005 {
2006         UINT32          WCIDAttri = 0;
2007         USHORT          offset;
2008         UCHAR           IVEIV = 0;
2009         USHORT          Wcid = 0;
2010
2011         {
2012 #ifdef CONFIG_STA_SUPPORT
2013                 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
2014                 {
2015                         if (BssIdx > BSS0)
2016                         {
2017                                 DBGPRINT(RT_DEBUG_ERROR, ("RTMPAddWcidAttributeEntry: The BSS-index(%d) is out of range for Infra link. \n", BssIdx));
2018                                 return;
2019                         }
2020
2021                         // 1.   In ADHOC mode, the AID is wcid number. And NO mesh link exists.
2022                         // 2.   In Infra mode, the AID:1 MUST be wcid of infra STA.
2023                         //                                         the AID:2~ assign to mesh link entry.
2024                         if (pEntry && ADHOC_ON(pAd))
2025                                 Wcid = pEntry->Aid;
2026                         else if (pEntry && INFRA_ON(pAd))
2027                         {
2028                                 Wcid = BSSID_WCID;
2029                         }
2030                         else
2031                                 Wcid = MCAST_WCID;
2032                 }
2033 #endif // CONFIG_STA_SUPPORT //
2034         }
2035
2036         // Update WCID attribute table
2037         offset = MAC_WCID_ATTRIBUTE_BASE + (Wcid * HW_WCID_ATTRI_SIZE);
2038
2039 #ifdef CONFIG_STA_SUPPORT
2040         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
2041         {
2042                 if (pEntry && pEntry->ValidAsMesh)
2043                         WCIDAttri = (CipherAlg<<1) | PAIRWISEKEYTABLE;
2044                 else
2045                         WCIDAttri = (CipherAlg<<1) | SHAREDKEYTABLE;
2046         }
2047 #endif // CONFIG_STA_SUPPORT //
2048
2049         RTMP_IO_WRITE32(pAd, offset, WCIDAttri);
2050
2051
2052         // Update IV/EIV table
2053         offset = MAC_IVEIV_TABLE_BASE + (Wcid * HW_IVEIV_ENTRY_SIZE);
2054
2055         // WPA mode
2056         if ((CipherAlg == CIPHER_TKIP) || (CipherAlg == CIPHER_TKIP_NO_MIC) || (CipherAlg == CIPHER_AES))
2057         {
2058                 // Eiv bit on. keyid always is 0 for pairwise key
2059                 IVEIV = (KeyIdx <<6) | 0x20;
2060         }
2061         else
2062         {
2063                 // WEP KeyIdx is default tx key.
2064                 IVEIV = (KeyIdx << 6);
2065         }
2066
2067         // For key index and ext IV bit, so only need to update the position(offset+3).
2068 #ifdef RT2870
2069         RTUSBMultiWrite_OneByte(pAd, offset+3, &IVEIV);
2070 #endif // RT2870 //
2071
2072         DBGPRINT(RT_DEBUG_TRACE,("RTMPAddWcidAttributeEntry: WCID #%d, KeyIndex #%d, Alg=%s\n",Wcid, KeyIdx, CipherName[CipherAlg]));
2073         DBGPRINT(RT_DEBUG_TRACE,("      WCIDAttri = 0x%x \n",  WCIDAttri));
2074
2075 }
2076
2077 /*
2078     ==========================================================================
2079     Description:
2080         Parse encryption type
2081 Arguments:
2082     pAdapter                    Pointer to our adapter
2083     wrq                         Pointer to the ioctl argument
2084
2085     Return Value:
2086         None
2087
2088     Note:
2089     ==========================================================================
2090 */
2091 CHAR *GetEncryptType(CHAR enc)
2092 {
2093     if(enc == Ndis802_11WEPDisabled)
2094         return "NONE";
2095     if(enc == Ndis802_11WEPEnabled)
2096         return "WEP";
2097     if(enc == Ndis802_11Encryption2Enabled)
2098         return "TKIP";
2099     if(enc == Ndis802_11Encryption3Enabled)
2100         return "AES";
2101         if(enc == Ndis802_11Encryption4Enabled)
2102         return "TKIPAES";
2103     else
2104         return "UNKNOW";
2105 }
2106
2107 CHAR *GetAuthMode(CHAR auth)
2108 {
2109     if(auth == Ndis802_11AuthModeOpen)
2110         return "OPEN";
2111     if(auth == Ndis802_11AuthModeShared)
2112         return "SHARED";
2113         if(auth == Ndis802_11AuthModeAutoSwitch)
2114         return "AUTOWEP";
2115     if(auth == Ndis802_11AuthModeWPA)
2116         return "WPA";
2117     if(auth == Ndis802_11AuthModeWPAPSK)
2118         return "WPAPSK";
2119     if(auth == Ndis802_11AuthModeWPANone)
2120         return "WPANONE";
2121     if(auth == Ndis802_11AuthModeWPA2)
2122         return "WPA2";
2123     if(auth == Ndis802_11AuthModeWPA2PSK)
2124         return "WPA2PSK";
2125         if(auth == Ndis802_11AuthModeWPA1WPA2)
2126         return "WPA1WPA2";
2127         if(auth == Ndis802_11AuthModeWPA1PSKWPA2PSK)
2128         return "WPA1PSKWPA2PSK";
2129
2130         return "UNKNOW";
2131 }
2132
2133 /*
2134     ==========================================================================
2135     Description:
2136         Get site survey results
2137         Arguments:
2138             pAdapter                    Pointer to our adapter
2139             wrq                         Pointer to the ioctl argument
2140
2141     Return Value:
2142         None
2143
2144     Note:
2145         Usage:
2146                         1.) UI needs to wait 4 seconds after issue a site survey command
2147                         2.) iwpriv ra0 get_site_survey
2148                         3.) UI needs to prepare at least 4096bytes to get the results
2149     ==========================================================================
2150 */
2151 #define LINE_LEN        (4+33+20+8+10+9+7+3)    // Channel+SSID+Bssid+WepStatus+AuthMode+Signal+WiressMode+NetworkType
2152 VOID RTMPIoctlGetSiteSurvey(
2153         IN      PRTMP_ADAPTER   pAdapter,
2154         IN      struct iwreq    *wrq)
2155 {
2156         CHAR            *msg;
2157         INT             i=0;
2158         INT                     WaitCnt;
2159         INT             Status=0;
2160         CHAR            Ssid[MAX_LEN_OF_SSID +1];
2161     INT         Rssi = 0, max_len = LINE_LEN;
2162         UINT        Rssi_Quality = 0;
2163         NDIS_802_11_NETWORK_TYPE    wireless_mode;
2164
2165         os_alloc_mem(NULL, (PUCHAR *)&msg, sizeof(CHAR)*((MAX_LEN_OF_BSS_TABLE)*max_len));
2166
2167         if (msg == NULL)
2168         {
2169                 DBGPRINT(RT_DEBUG_TRACE, ("RTMPIoctlGetSiteSurvey - msg memory alloc fail.\n"));
2170                 return;
2171         }
2172
2173         memset(msg, 0 ,(MAX_LEN_OF_BSS_TABLE)*max_len );
2174         memset(Ssid, 0 ,(MAX_LEN_OF_SSID +1));
2175         sprintf(msg,"%s","\n");
2176         sprintf(msg+strlen(msg),"%-4s%-33s%-20s%-8s%-10s%-9s%-7s%-3s\n",
2177             "Ch", "SSID", "BSSID", "Enc", "Auth", "Siganl(%)", "W-Mode", " NT");
2178
2179
2180         WaitCnt = 0;
2181 #ifdef CONFIG_STA_SUPPORT
2182         pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
2183         while ((ScanRunning(pAdapter) == TRUE) && (WaitCnt++ < 200))
2184                 OS_WAIT(500);
2185 #endif // CONFIG_STA_SUPPORT //
2186
2187         for(i=0; i<pAdapter->ScanTab.BssNr ;i++)
2188         {
2189                 if( pAdapter->ScanTab.BssEntry[i].Channel==0)
2190                         break;
2191
2192                 if((strlen(msg)+max_len ) >= IW_SCAN_MAX_DATA)
2193                         break;
2194
2195                 //Channel
2196                 sprintf(msg+strlen(msg),"%-4d", pAdapter->ScanTab.BssEntry[i].Channel);
2197                 //SSID
2198                 memcpy(Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
2199                 Ssid[pAdapter->ScanTab.BssEntry[i].SsidLen] = '\0';
2200                 sprintf(msg+strlen(msg),"%-33s", Ssid);
2201                 //BSSID
2202                 sprintf(msg+strlen(msg),"%02x:%02x:%02x:%02x:%02x:%02x   ",
2203                         pAdapter->ScanTab.BssEntry[i].Bssid[0],
2204                         pAdapter->ScanTab.BssEntry[i].Bssid[1],
2205                         pAdapter->ScanTab.BssEntry[i].Bssid[2],
2206                         pAdapter->ScanTab.BssEntry[i].Bssid[3],
2207                         pAdapter->ScanTab.BssEntry[i].Bssid[4],
2208                         pAdapter->ScanTab.BssEntry[i].Bssid[5]);
2209                 //Encryption Type
2210                 sprintf(msg+strlen(msg),"%-8s",GetEncryptType(pAdapter->ScanTab.BssEntry[i].WepStatus));
2211                 //Authentication Mode
2212                 if (pAdapter->ScanTab.BssEntry[i].WepStatus == Ndis802_11WEPEnabled)
2213                         sprintf(msg+strlen(msg),"%-10s", "UNKNOW");
2214                 else
2215                         sprintf(msg+strlen(msg),"%-10s",GetAuthMode(pAdapter->ScanTab.BssEntry[i].AuthMode));
2216                 // Rssi
2217                 Rssi = (INT)pAdapter->ScanTab.BssEntry[i].Rssi;
2218                 if (Rssi >= -50)
2219                         Rssi_Quality = 100;
2220                 else if (Rssi >= -80)    // between -50 ~ -80dbm
2221                         Rssi_Quality = (UINT)(24 + ((Rssi + 80) * 26)/10);
2222                 else if (Rssi >= -90)   // between -80 ~ -90dbm
2223                         Rssi_Quality = (UINT)(((Rssi + 90) * 26)/10);
2224                 else    // < -84 dbm
2225                         Rssi_Quality = 0;
2226                 sprintf(msg+strlen(msg),"%-9d", Rssi_Quality);
2227                 // Wireless Mode
2228                 wireless_mode = NetworkTypeInUseSanity(&pAdapter->ScanTab.BssEntry[i]);
2229                 if (wireless_mode == Ndis802_11FH ||
2230                         wireless_mode == Ndis802_11DS)
2231                         sprintf(msg+strlen(msg),"%-7s", "11b");
2232                 else if (wireless_mode == Ndis802_11OFDM5)
2233                         sprintf(msg+strlen(msg),"%-7s", "11a");
2234                 else if (wireless_mode == Ndis802_11OFDM5_N)
2235                         sprintf(msg+strlen(msg),"%-7s", "11a/n");
2236                 else if (wireless_mode == Ndis802_11OFDM24)
2237                         sprintf(msg+strlen(msg),"%-7s", "11b/g");
2238                 else if (wireless_mode == Ndis802_11OFDM24_N)
2239                         sprintf(msg+strlen(msg),"%-7s", "11b/g/n");
2240                 else
2241                         sprintf(msg+strlen(msg),"%-7s", "unknow");
2242                 //Network Type
2243                 if (pAdapter->ScanTab.BssEntry[i].BssType == BSS_ADHOC)
2244                         sprintf(msg+strlen(msg),"%-3s", " Ad");
2245                 else
2246                         sprintf(msg+strlen(msg),"%-3s", " In");
2247
2248         sprintf(msg+strlen(msg),"\n");
2249         }
2250
2251 #ifdef CONFIG_STA_SUPPORT
2252         pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
2253 #endif // CONFIG_STA_SUPPORT //
2254         wrq->u.data.length = strlen(msg);
2255         Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
2256
2257         DBGPRINT(RT_DEBUG_TRACE, ("RTMPIoctlGetSiteSurvey - wrq->u.data.length = %d\n", wrq->u.data.length));
2258         os_free_mem(NULL, (PUCHAR)msg);
2259 }
2260
2261
2262 #define MAC_LINE_LEN    (14+4+4+10+10+10+6+6)   // Addr+aid+psm+datatime+rxbyte+txbyte+current tx rate+last tx rate
2263 VOID RTMPIoctlGetMacTable(
2264         IN PRTMP_ADAPTER pAd,
2265         IN struct iwreq *wrq)
2266 {
2267         INT i;
2268         RT_802_11_MAC_TABLE MacTab;
2269         char *msg;
2270
2271         MacTab.Num = 0;
2272         for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
2273         {
2274                 if (pAd->MacTab.Content[i].ValidAsCLI && (pAd->MacTab.Content[i].Sst == SST_ASSOC))
2275                 {
2276                         COPY_MAC_ADDR(MacTab.Entry[MacTab.Num].Addr, &pAd->MacTab.Content[i].Addr);
2277                         MacTab.Entry[MacTab.Num].Aid = (UCHAR)pAd->MacTab.Content[i].Aid;
2278                         MacTab.Entry[MacTab.Num].Psm = pAd->MacTab.Content[i].PsMode;
2279 #ifdef DOT11_N_SUPPORT
2280                         MacTab.Entry[MacTab.Num].MimoPs = pAd->MacTab.Content[i].MmpsMode;
2281 #endif // DOT11_N_SUPPORT //
2282
2283                         // Fill in RSSI per entry
2284                         MacTab.Entry[MacTab.Num].AvgRssi0 = pAd->MacTab.Content[i].RssiSample.AvgRssi0;
2285                         MacTab.Entry[MacTab.Num].AvgRssi1 = pAd->MacTab.Content[i].RssiSample.AvgRssi1;
2286                         MacTab.Entry[MacTab.Num].AvgRssi2 = pAd->MacTab.Content[i].RssiSample.AvgRssi2;
2287
2288                         // the connected time per entry
2289                         MacTab.Entry[MacTab.Num].ConnectedTime = pAd->MacTab.Content[i].StaConnectTime;
2290 #if 0 // ToDo
2291                         MacTab.Entry[MacTab.Num].HSCounter.LastDataPacketTime = pAd->MacTab.Content[i].HSCounter.LastDataPacketTime;
2292                         MacTab.Entry[MacTab.Num].HSCounter.TotalRxByteCount = pAd->MacTab.Content[i].HSCounter.TotalRxByteCount;
2293                         MacTab.Entry[MacTab.Num].HSCounter.TotalTxByteCount = pAd->MacTab.Content[i].HSCounter.TotalTxByteCount;
2294 #endif
2295                         MacTab.Entry[MacTab.Num].TxRate.field.MCS = pAd->MacTab.Content[i].HTPhyMode.field.MCS;
2296                         MacTab.Entry[MacTab.Num].TxRate.field.BW = pAd->MacTab.Content[i].HTPhyMode.field.BW;
2297                         MacTab.Entry[MacTab.Num].TxRate.field.ShortGI = pAd->MacTab.Content[i].HTPhyMode.field.ShortGI;
2298                         MacTab.Entry[MacTab.Num].TxRate.field.STBC = pAd->MacTab.Content[i].HTPhyMode.field.STBC;
2299                         MacTab.Entry[MacTab.Num].TxRate.field.rsv = pAd->MacTab.Content[i].HTPhyMode.field.rsv;
2300                         MacTab.Entry[MacTab.Num].TxRate.field.MODE = pAd->MacTab.Content[i].HTPhyMode.field.MODE;
2301                         MacTab.Entry[MacTab.Num].TxRate.word = pAd->MacTab.Content[i].HTPhyMode.word;
2302
2303                         MacTab.Num += 1;
2304                 }
2305         }
2306         wrq->u.data.length = sizeof(RT_802_11_MAC_TABLE);
2307         if (copy_to_user(wrq->u.data.pointer, &MacTab, wrq->u.data.length))
2308         {
2309                 DBGPRINT(RT_DEBUG_TRACE, ("%s: copy_to_user() fail\n", __func__));
2310         }
2311
2312         msg = (CHAR *) kmalloc(sizeof(CHAR)*(MAX_LEN_OF_MAC_TABLE*MAC_LINE_LEN), MEM_ALLOC_FLAG);
2313         memset(msg, 0 ,MAX_LEN_OF_MAC_TABLE*MAC_LINE_LEN );
2314         sprintf(msg,"%s","\n");
2315         sprintf(msg+strlen(msg),"%-14s%-4s%-4s%-10s%-10s%-10s%-6s%-6s\n",
2316                 "MAC", "AID", "PSM", "LDT", "RxB", "TxB","CTxR", "LTxR");
2317
2318         for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
2319         {
2320                 PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
2321                 if (pEntry->ValidAsCLI && (pEntry->Sst == SST_ASSOC))
2322                 {
2323                         if((strlen(msg)+MAC_LINE_LEN ) >= (MAX_LEN_OF_MAC_TABLE*MAC_LINE_LEN) )
2324                                 break;
2325                         sprintf(msg+strlen(msg),"%02x%02x%02x%02x%02x%02x  ",
2326                                 pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
2327                                 pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5]);
2328                         sprintf(msg+strlen(msg),"%-4d", (int)pEntry->Aid);
2329                         sprintf(msg+strlen(msg),"%-4d", (int)pEntry->PsMode);
2330                         sprintf(msg+strlen(msg),"%-10d",0/*pAd->MacTab.Content[i].HSCounter.LastDataPacketTime*/); // ToDo
2331                         sprintf(msg+strlen(msg),"%-10d",0/*pAd->MacTab.Content[i].HSCounter.TotalRxByteCount*/); // ToDo
2332                         sprintf(msg+strlen(msg),"%-10d",0/*pAd->MacTab.Content[i].HSCounter.TotalTxByteCount*/); // ToDo
2333                         sprintf(msg+strlen(msg),"%-6d",RateIdToMbps[pAd->MacTab.Content[i].CurrTxRate]);
2334                         sprintf(msg+strlen(msg),"%-6d\n",0/*RateIdToMbps[pAd->MacTab.Content[i].LastTxRate]*/); // ToDo
2335                 }
2336         }
2337         // for compatible with old API just do the printk to console
2338         //wrq->u.data.length = strlen(msg);
2339         //if (copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length))
2340         {
2341                 DBGPRINT(RT_DEBUG_TRACE, ("%s", msg));
2342         }
2343
2344         kfree(msg);
2345 }
2346
2347 #ifdef DOT11_N_SUPPORT
2348 INT     Set_BASetup_Proc(
2349         IN      PRTMP_ADAPTER   pAd,
2350         IN      PUCHAR                  arg)
2351 {
2352     UCHAR mac[6], tid;
2353         char *token, sepValue[] = ":", DASH = '-';
2354         INT i;
2355     MAC_TABLE_ENTRY *pEntry;
2356
2357 /*
2358         The BASetup inupt string format should be xx:xx:xx:xx:xx:xx-d,
2359                 =>The six 2 digit hex-decimal number previous are the Mac address,
2360                 =>The seventh decimal number is the tid value.
2361 */
2362         //printk("\n%s\n", arg);
2363
2364         if(strlen(arg) < 19)  //Mac address acceptable format 01:02:03:04:05:06 length 17 plus the "-" and tid value in decimal format.
2365                 return FALSE;
2366
2367         token = strchr(arg, DASH);
2368         if ((token != NULL) && (strlen(token)>1))
2369         {
2370                 tid = simple_strtol((token+1), 0, 10);
2371                 if (tid > 15)
2372                         return FALSE;
2373
2374                 *token = '\0';
2375                 for (i = 0, token = rstrtok(arg, &sepValue[0]); token; token = rstrtok(NULL, &sepValue[0]), i++)
2376                 {
2377                         if((strlen(token) != 2) || (!isxdigit(*token)) || (!isxdigit(*(token+1))))
2378                                 return FALSE;
2379                         AtoH(token, (PUCHAR)(&mac[i]), 1);
2380                 }
2381                 if(i != 6)
2382                         return FALSE;
2383
2384                 printk("\n%02x:%02x:%02x:%02x:%02x:%02x-%02x\n", mac[0], mac[1],
2385                                 mac[2], mac[3], mac[4], mac[5], tid);
2386
2387             pEntry = MacTableLookup(pAd, mac);
2388
2389         if (pEntry) {
2390                 printk("\nSetup BA Session: Tid = %d\n", tid);
2391                 BAOriSessionSetUp(pAd, pEntry, tid, 0, 100, TRUE);
2392         }
2393
2394                 return TRUE;
2395         }
2396
2397         return FALSE;
2398
2399 }
2400
2401 INT     Set_BADecline_Proc(
2402         IN      PRTMP_ADAPTER   pAd,
2403         IN      PUCHAR                  arg)
2404 {
2405         ULONG bBADecline;
2406
2407         bBADecline = simple_strtol(arg, 0, 10);
2408
2409         if (bBADecline == 0)
2410         {
2411                 pAd->CommonCfg.bBADecline = FALSE;
2412         }
2413         else if (bBADecline == 1)
2414         {
2415                 pAd->CommonCfg.bBADecline = TRUE;
2416         }
2417         else
2418         {
2419                 return FALSE; //Invalid argument
2420         }
2421
2422         DBGPRINT(RT_DEBUG_TRACE, ("Set_BADecline_Proc::(BADecline=%d)\n", pAd->CommonCfg.bBADecline));
2423
2424         return TRUE;
2425 }
2426
2427 INT     Set_BAOriTearDown_Proc(
2428         IN      PRTMP_ADAPTER   pAd,
2429         IN      PUCHAR                  arg)
2430 {
2431     UCHAR mac[6], tid;
2432         char *token, sepValue[] = ":", DASH = '-';
2433         INT i;
2434     MAC_TABLE_ENTRY *pEntry;
2435
2436     //printk("\n%s\n", arg);
2437 /*
2438         The BAOriTearDown inupt string format should be xx:xx:xx:xx:xx:xx-d,
2439                 =>The six 2 digit hex-decimal number previous are the Mac address,
2440                 =>The seventh decimal number is the tid value.
2441 */
2442     if(strlen(arg) < 19)  //Mac address acceptable format 01:02:03:04:05:06 length 17 plus the "-" and tid value in decimal format.
2443                 return FALSE;
2444
2445         token = strchr(arg, DASH);
2446         if ((token != NULL) && (strlen(token)>1))
2447         {
2448                 tid = simple_strtol((token+1), 0, 10);
2449                 if (tid > NUM_OF_TID)
2450                         return FALSE;
2451
2452                 *token = '\0';
2453                 for (i = 0, token = rstrtok(arg, &sepValue[0]); token; token = rstrtok(NULL, &sepValue[0]), i++)
2454                 {
2455                         if((strlen(token) != 2) || (!isxdigit(*token)) || (!isxdigit(*(token+1))))
2456                                 return FALSE;
2457                         AtoH(token, (PUCHAR)(&mac[i]), 1);
2458                 }
2459                 if(i != 6)
2460                         return FALSE;
2461
2462             printk("\n%02x:%02x:%02x:%02x:%02x:%02x-%02x", mac[0], mac[1],
2463                    mac[2], mac[3], mac[4], mac[5], tid);
2464
2465             pEntry = MacTableLookup(pAd, mac);
2466
2467             if (pEntry) {
2468                 printk("\nTear down Ori BA Session: Tid = %d\n", tid);
2469         BAOriSessionTearDown(pAd, pEntry->Aid, tid, FALSE, TRUE);
2470             }
2471
2472                 return TRUE;
2473         }
2474
2475         return FALSE;
2476
2477 }
2478
2479 INT     Set_BARecTearDown_Proc(
2480         IN      PRTMP_ADAPTER   pAd,
2481         IN      PUCHAR                  arg)
2482 {
2483     UCHAR mac[6], tid;
2484         char *token, sepValue[] = ":", DASH = '-';
2485         INT i;
2486     MAC_TABLE_ENTRY *pEntry;
2487
2488     //printk("\n%s\n", arg);
2489 /*
2490         The BARecTearDown inupt string format should be xx:xx:xx:xx:xx:xx-d,
2491                 =>The six 2 digit hex-decimal number previous are the Mac address,
2492                 =>The seventh decimal number is the tid value.
2493 */
2494     if(strlen(arg) < 19)  //Mac address acceptable format 01:02:03:04:05:06 length 17 plus the "-" and tid value in decimal format.
2495                 return FALSE;
2496
2497         token = strchr(arg, DASH);
2498         if ((token != NULL) && (strlen(token)>1))
2499         {
2500                 tid = simple_strtol((token+1), 0, 10);
2501                 if (tid > NUM_OF_TID)
2502                         return FALSE;
2503
2504                 *token = '\0';
2505                 for (i = 0, token = rstrtok(arg, &sepValue[0]); token; token = rstrtok(NULL, &sepValue[0]), i++)
2506                 {
2507                         if((strlen(token) != 2) || (!isxdigit(*token)) || (!isxdigit(*(token+1))))
2508                                 return FALSE;
2509                         AtoH(token, (PUCHAR)(&mac[i]), 1);
2510                 }
2511                 if(i != 6)
2512                         return FALSE;
2513
2514                 printk("\n%02x:%02x:%02x:%02x:%02x:%02x-%02x", mac[0], mac[1],
2515                        mac[2], mac[3], mac[4], mac[5], tid);
2516
2517                 pEntry = MacTableLookup(pAd, mac);
2518
2519                 if (pEntry) {
2520                     printk("\nTear down Rec BA Session: Tid = %d\n", tid);
2521                     BARecSessionTearDown(pAd, pEntry->Aid, tid, FALSE);
2522                 }
2523
2524                 return TRUE;
2525         }
2526
2527         return FALSE;
2528
2529 }
2530
2531 INT     Set_HtBw_Proc(
2532         IN      PRTMP_ADAPTER   pAd,
2533         IN      PUCHAR                  arg)
2534 {
2535         ULONG HtBw;
2536
2537         HtBw = simple_strtol(arg, 0, 10);
2538         if (HtBw == BW_40)
2539                 pAd->CommonCfg.RegTransmitSetting.field.BW  = BW_40;
2540         else if (HtBw == BW_20)
2541                 pAd->CommonCfg.RegTransmitSetting.field.BW  = BW_20;
2542         else
2543                 return FALSE;  //Invalid argument
2544
2545         SetCommonHT(pAd);
2546
2547         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtBw_Proc::(HtBw=%d)\n", pAd->CommonCfg.RegTransmitSetting.field.BW));
2548
2549         return TRUE;
2550 }
2551
2552 INT     Set_HtMcs_Proc(
2553         IN      PRTMP_ADAPTER   pAd,
2554         IN      PUCHAR                  arg)
2555 {
2556         ULONG HtMcs, Mcs_tmp;
2557 #ifdef CONFIG_STA_SUPPORT
2558     BOOLEAN bAutoRate = FALSE;
2559 #endif // CONFIG_STA_SUPPORT //
2560
2561         Mcs_tmp = simple_strtol(arg, 0, 10);
2562
2563         if (Mcs_tmp <= 15 || Mcs_tmp == 32)
2564                 HtMcs = Mcs_tmp;
2565         else
2566                 HtMcs = MCS_AUTO;
2567
2568 #ifdef CONFIG_STA_SUPPORT
2569         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
2570         {
2571                 pAd->StaCfg.DesiredTransmitSetting.field.MCS = HtMcs;
2572                 pAd->StaCfg.bAutoTxRateSwitch = (HtMcs == MCS_AUTO) ? TRUE:FALSE;
2573                 DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMcs_Proc::(HtMcs=%d, bAutoTxRateSwitch = %d)\n",
2574                                                 pAd->StaCfg.DesiredTransmitSetting.field.MCS, pAd->StaCfg.bAutoTxRateSwitch));
2575
2576                 if ((pAd->CommonCfg.PhyMode < PHY_11ABGN_MIXED) ||
2577                         (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE < MODE_HTMIX))
2578                 {
2579                 if ((pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO) &&
2580                                 (HtMcs >= 0 && HtMcs <= 3) &&
2581                     (pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode == FIXED_TXMODE_CCK))
2582                         {
2583                                 RTMPSetDesiredRates(pAd, (LONG) (RateIdToMbps[HtMcs] * 1000000));
2584                         }
2585                 else if ((pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO) &&
2586                                         (HtMcs >= 0 && HtMcs <= 7) &&
2587                         (pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode == FIXED_TXMODE_OFDM))
2588                         {
2589                                 RTMPSetDesiredRates(pAd, (LONG) (RateIdToMbps[HtMcs+4] * 1000000));
2590                         }
2591                         else
2592                                 bAutoRate = TRUE;
2593
2594                         if (bAutoRate)
2595                         {
2596                     pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
2597                                 RTMPSetDesiredRates(pAd, -1);
2598                         }
2599                 DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMcs_Proc::(FixedTxMode=%d)\n",pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode));
2600                 }
2601         if (ADHOC_ON(pAd))
2602             return TRUE;
2603         }
2604 #endif // CONFIG_STA_SUPPORT //
2605
2606         SetCommonHT(pAd);
2607
2608         return TRUE;
2609 }
2610
2611 INT     Set_HtGi_Proc(
2612         IN      PRTMP_ADAPTER   pAd,
2613         IN      PUCHAR                  arg)
2614 {
2615         ULONG HtGi;
2616
2617         HtGi = simple_strtol(arg, 0, 10);
2618
2619         if ( HtGi == GI_400)
2620                 pAd->CommonCfg.RegTransmitSetting.field.ShortGI = GI_400;
2621         else if ( HtGi == GI_800 )
2622                 pAd->CommonCfg.RegTransmitSetting.field.ShortGI = GI_800;
2623         else
2624                 return FALSE; //Invalid argument
2625
2626         SetCommonHT(pAd);
2627
2628         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtGi_Proc::(ShortGI=%d)\n",pAd->CommonCfg.RegTransmitSetting.field.ShortGI));
2629
2630         return TRUE;
2631 }
2632
2633
2634 INT     Set_HtTxBASize_Proc(
2635         IN      PRTMP_ADAPTER   pAd,
2636         IN      PUCHAR                  arg)
2637 {
2638         UCHAR Size;
2639
2640         Size = simple_strtol(arg, 0, 10);
2641
2642         if (Size <=0 || Size >=64)
2643         {
2644                 Size = 8;
2645         }
2646         pAd->CommonCfg.TxBASize = Size-1;
2647         DBGPRINT(RT_DEBUG_ERROR, ("Set_HtTxBASize ::(TxBASize= %d)\n", Size));
2648
2649         return TRUE;
2650 }
2651
2652
2653 INT     Set_HtOpMode_Proc(
2654         IN      PRTMP_ADAPTER   pAd,
2655         IN      PUCHAR                  arg)
2656 {
2657
2658         ULONG Value;
2659
2660         Value = simple_strtol(arg, 0, 10);
2661
2662         if (Value == HTMODE_GF)
2663                 pAd->CommonCfg.RegTransmitSetting.field.HTMODE  = HTMODE_GF;
2664         else if ( Value == HTMODE_MM )
2665                 pAd->CommonCfg.RegTransmitSetting.field.HTMODE  = HTMODE_MM;
2666         else
2667                 return FALSE; //Invalid argument
2668
2669         SetCommonHT(pAd);
2670
2671         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtOpMode_Proc::(HtOpMode=%d)\n",pAd->CommonCfg.RegTransmitSetting.field.HTMODE));
2672
2673         return TRUE;
2674
2675 }
2676
2677 INT     Set_HtStbc_Proc(
2678         IN      PRTMP_ADAPTER   pAd,
2679         IN      PUCHAR                  arg)
2680 {
2681
2682         ULONG Value;
2683
2684         Value = simple_strtol(arg, 0, 10);
2685
2686         if (Value == STBC_USE)
2687                 pAd->CommonCfg.RegTransmitSetting.field.STBC = STBC_USE;
2688         else if ( Value == STBC_NONE )
2689                 pAd->CommonCfg.RegTransmitSetting.field.STBC = STBC_NONE;
2690         else
2691                 return FALSE; //Invalid argument
2692
2693         SetCommonHT(pAd);
2694
2695         DBGPRINT(RT_DEBUG_TRACE, ("Set_Stbc_Proc::(HtStbc=%d)\n",pAd->CommonCfg.RegTransmitSetting.field.STBC));
2696
2697         return TRUE;
2698 }
2699
2700 INT     Set_HtHtc_Proc(
2701         IN      PRTMP_ADAPTER   pAd,
2702         IN      PUCHAR                  arg)
2703 {
2704
2705         ULONG Value;
2706
2707         Value = simple_strtol(arg, 0, 10);
2708         if (Value == 0)
2709                 pAd->HTCEnable = FALSE;
2710         else if ( Value ==1 )
2711                 pAd->HTCEnable = TRUE;
2712         else
2713                 return FALSE; //Invalid argument
2714
2715         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtHtc_Proc::(HtHtc=%d)\n",pAd->HTCEnable));
2716
2717         return TRUE;
2718 }
2719
2720 INT     Set_HtExtcha_Proc(
2721         IN      PRTMP_ADAPTER   pAd,
2722         IN      PUCHAR                  arg)
2723 {
2724
2725         ULONG Value;
2726
2727         Value = simple_strtol(arg, 0, 10);
2728
2729         if (Value == 0)
2730                 pAd->CommonCfg.RegTransmitSetting.field.EXTCHA  = EXTCHA_BELOW;
2731         else if ( Value ==1 )
2732         pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_ABOVE;
2733         else
2734                 return FALSE; //Invalid argument
2735
2736         SetCommonHT(pAd);
2737
2738         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtExtcha_Proc::(HtExtcha=%d)\n",pAd->CommonCfg.RegTransmitSetting.field.EXTCHA));
2739
2740         return TRUE;
2741 }
2742
2743 INT     Set_HtMpduDensity_Proc(
2744         IN      PRTMP_ADAPTER   pAd,
2745         IN      PUCHAR                  arg)
2746 {
2747         ULONG Value;
2748
2749         Value = simple_strtol(arg, 0, 10);
2750
2751         if (Value <=7 && Value >= 0)
2752                 pAd->CommonCfg.BACapability.field.MpduDensity = Value;
2753         else
2754                 pAd->CommonCfg.BACapability.field.MpduDensity = 4;
2755
2756         SetCommonHT(pAd);
2757
2758         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMpduDensity_Proc::(HtMpduDensity=%d)\n",pAd->CommonCfg.BACapability.field.MpduDensity));
2759
2760         return TRUE;
2761 }
2762
2763 INT     Set_HtBaWinSize_Proc(
2764         IN      PRTMP_ADAPTER   pAd,
2765         IN      PUCHAR                  arg)
2766 {
2767         ULONG Value;
2768
2769         Value = simple_strtol(arg, 0, 10);
2770
2771
2772         if (Value >=1 && Value <= 64)
2773         {
2774                 pAd->CommonCfg.REGBACapability.field.RxBAWinLimit = Value;
2775                 pAd->CommonCfg.BACapability.field.RxBAWinLimit = Value;
2776         }
2777         else
2778         {
2779         pAd->CommonCfg.REGBACapability.field.RxBAWinLimit = 64;
2780                 pAd->CommonCfg.BACapability.field.RxBAWinLimit = 64;
2781         }
2782
2783         SetCommonHT(pAd);
2784
2785         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtBaWinSize_Proc::(HtBaWinSize=%d)\n",pAd->CommonCfg.BACapability.field.RxBAWinLimit));
2786
2787         return TRUE;
2788 }
2789
2790 INT     Set_HtRdg_Proc(
2791         IN      PRTMP_ADAPTER   pAd,
2792         IN      PUCHAR                  arg)
2793 {
2794         ULONG Value;
2795
2796         Value = simple_strtol(arg, 0, 10);
2797
2798         if (Value == 0)
2799                 pAd->CommonCfg.bRdg = FALSE;
2800         else if ( Value ==1 )
2801         {
2802                 pAd->HTCEnable = TRUE;
2803                 pAd->CommonCfg.bRdg = TRUE;
2804         }
2805         else
2806                 return FALSE; //Invalid argument
2807
2808         SetCommonHT(pAd);
2809
2810         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtRdg_Proc::(HtRdg=%d)\n",pAd->CommonCfg.bRdg));
2811
2812         return TRUE;
2813 }
2814
2815 INT     Set_HtLinkAdapt_Proc(
2816         IN      PRTMP_ADAPTER   pAd,
2817         IN      PUCHAR                  arg)
2818 {
2819         ULONG Value;
2820
2821         Value = simple_strtol(arg, 0, 10);
2822         if (Value == 0)
2823                 pAd->bLinkAdapt = FALSE;
2824         else if ( Value ==1 )
2825         {
2826                         pAd->HTCEnable = TRUE;
2827                         pAd->bLinkAdapt = TRUE;
2828         }
2829         else
2830                 return FALSE; //Invalid argument
2831
2832         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtLinkAdapt_Proc::(HtLinkAdapt=%d)\n",pAd->bLinkAdapt));
2833
2834         return TRUE;
2835 }
2836
2837 INT     Set_HtAmsdu_Proc(
2838         IN      PRTMP_ADAPTER   pAd,
2839         IN      PUCHAR                  arg)
2840 {
2841         ULONG Value;
2842
2843         Value = simple_strtol(arg, 0, 10);
2844         if (Value == 0)
2845                 pAd->CommonCfg.BACapability.field.AmsduEnable = FALSE;
2846         else if ( Value == 1 )
2847         pAd->CommonCfg.BACapability.field.AmsduEnable = TRUE;
2848         else
2849                 return FALSE; //Invalid argument
2850
2851         SetCommonHT(pAd);
2852
2853         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtAmsdu_Proc::(HtAmsdu=%d)\n",pAd->CommonCfg.BACapability.field.AmsduEnable));
2854
2855         return TRUE;
2856 }
2857
2858 INT     Set_HtAutoBa_Proc(
2859         IN      PRTMP_ADAPTER   pAd,
2860         IN      PUCHAR                  arg)
2861 {
2862         ULONG Value;
2863
2864         Value = simple_strtol(arg, 0, 10);
2865         if (Value == 0)
2866                 pAd->CommonCfg.BACapability.field.AutoBA = FALSE;
2867     else if (Value == 1)
2868                 pAd->CommonCfg.BACapability.field.AutoBA = TRUE;
2869         else
2870                 return FALSE; //Invalid argument
2871
2872     pAd->CommonCfg.REGBACapability.field.AutoBA = pAd->CommonCfg.BACapability.field.AutoBA;
2873         SetCommonHT(pAd);
2874
2875         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtAutoBa_Proc::(HtAutoBa=%d)\n",pAd->CommonCfg.BACapability.field.AutoBA));
2876
2877         return TRUE;
2878
2879 }
2880
2881 INT     Set_HtProtect_Proc(
2882         IN      PRTMP_ADAPTER   pAd,
2883         IN      PUCHAR                  arg)
2884 {
2885         ULONG Value;
2886
2887         Value = simple_strtol(arg, 0, 10);
2888         if (Value == 0)
2889                 pAd->CommonCfg.bHTProtect = FALSE;
2890     else if (Value == 1)
2891                 pAd->CommonCfg.bHTProtect = TRUE;
2892         else
2893                 return FALSE; //Invalid argument
2894
2895         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtProtect_Proc::(HtProtect=%d)\n",pAd->CommonCfg.bHTProtect));
2896
2897         return TRUE;
2898 }
2899
2900 INT     Set_SendPSMPAction_Proc(
2901         IN      PRTMP_ADAPTER   pAd,
2902         IN      PUCHAR                  arg)
2903 {
2904     UCHAR mac[6], mode;
2905         char *token, sepValue[] = ":", DASH = '-';
2906         INT i;
2907     MAC_TABLE_ENTRY *pEntry;
2908
2909     //printk("\n%s\n", arg);
2910 /*
2911         The BARecTearDown inupt string format should be xx:xx:xx:xx:xx:xx-d,
2912                 =>The six 2 digit hex-decimal number previous are the Mac address,
2913                 =>The seventh decimal number is the mode value.
2914 */
2915     if(strlen(arg) < 19)  //Mac address acceptable format 01:02:03:04:05:06 length 17 plus the "-" and mode value in decimal format.
2916                 return FALSE;
2917
2918         token = strchr(arg, DASH);
2919         if ((token != NULL) && (strlen(token)>1))
2920         {
2921                 mode = simple_strtol((token+1), 0, 10);
2922                 if (mode > MMPS_ENABLE)
2923                         return FALSE;
2924
2925                 *token = '\0';
2926                 for (i = 0, token = rstrtok(arg, &sepValue[0]); token; token = rstrtok(NULL, &sepValue[0]), i++)
2927                 {
2928                         if((strlen(token) != 2) || (!isxdigit(*token)) || (!isxdigit(*(token+1))))
2929                                 return FALSE;
2930                         AtoH(token, (PUCHAR)(&mac[i]), 1);
2931                 }
2932                 if(i != 6)
2933                         return FALSE;
2934
2935                 printk("\n%02x:%02x:%02x:%02x:%02x:%02x-%02x", mac[0], mac[1],
2936                        mac[2], mac[3], mac[4], mac[5], mode);
2937
2938                 pEntry = MacTableLookup(pAd, mac);
2939
2940                 if (pEntry) {
2941                     printk("\nSendPSMPAction MIPS mode = %d\n", mode);
2942                     SendPSMPAction(pAd, pEntry->Aid, mode);
2943                 }
2944
2945                 return TRUE;
2946         }
2947
2948         return FALSE;
2949
2950
2951 }
2952
2953 INT     Set_HtMIMOPSmode_Proc(
2954         IN      PRTMP_ADAPTER   pAd,
2955         IN      PUCHAR                  arg)
2956 {
2957         ULONG Value;
2958
2959         Value = simple_strtol(arg, 0, 10);
2960
2961         if (Value <=3 && Value >= 0)
2962                 pAd->CommonCfg.BACapability.field.MMPSmode = Value;
2963         else
2964                 pAd->CommonCfg.BACapability.field.MMPSmode = 3;
2965
2966         SetCommonHT(pAd);
2967
2968         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMIMOPSmode_Proc::(MIMOPS mode=%d)\n",pAd->CommonCfg.BACapability.field.MMPSmode));
2969
2970         return TRUE;
2971 }
2972
2973
2974 INT     Set_ForceShortGI_Proc(
2975         IN      PRTMP_ADAPTER   pAd,
2976         IN      PUCHAR                  arg)
2977 {
2978         ULONG Value;
2979
2980         Value = simple_strtol(arg, 0, 10);
2981         if (Value == 0)
2982                 pAd->WIFItestbed.bShortGI = FALSE;
2983         else if (Value == 1)
2984                 pAd->WIFItestbed.bShortGI = TRUE;
2985         else
2986                 return FALSE; //Invalid argument
2987
2988         SetCommonHT(pAd);
2989
2990         DBGPRINT(RT_DEBUG_TRACE, ("Set_ForceShortGI_Proc::(ForceShortGI=%d)\n", pAd->WIFItestbed.bShortGI));
2991
2992         return TRUE;
2993 }
2994
2995
2996
2997 INT     Set_ForceGF_Proc(
2998         IN      PRTMP_ADAPTER   pAd,
2999         IN      PUCHAR                  arg)
3000 {
3001         ULONG Value;
3002
3003         Value = simple_strtol(arg, 0, 10);
3004         if (Value == 0)
3005                 pAd->WIFItestbed.bGreenField = FALSE;
3006         else if (Value == 1)
3007                 pAd->WIFItestbed.bGreenField = TRUE;
3008         else
3009                 return FALSE; //Invalid argument
3010
3011         SetCommonHT(pAd);
3012
3013         DBGPRINT(RT_DEBUG_TRACE, ("Set_ForceGF_Proc::(ForceGF=%d)\n", pAd->WIFItestbed.bGreenField));
3014
3015         return TRUE;
3016 }
3017
3018 INT     Set_HtMimoPs_Proc(
3019         IN      PRTMP_ADAPTER   pAd,
3020         IN      PUCHAR                  arg)
3021 {
3022         ULONG Value;
3023
3024         Value = simple_strtol(arg, 0, 10);
3025         if (Value == 0)
3026                 pAd->CommonCfg.bMIMOPSEnable = FALSE;
3027         else if (Value == 1)
3028                 pAd->CommonCfg.bMIMOPSEnable = TRUE;
3029         else
3030                 return FALSE; //Invalid argument
3031
3032         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMimoPs_Proc::(HtMimoPs=%d)\n",pAd->CommonCfg.bMIMOPSEnable));
3033
3034         return TRUE;
3035 }
3036 #endif // DOT11_N_SUPPORT //
3037
3038
3039 #ifdef DOT11_N_SUPPORT
3040 INT     SetCommonHT(
3041         IN      PRTMP_ADAPTER   pAd)
3042 {
3043         OID_SET_HT_PHYMODE              SetHT;
3044
3045         if (pAd->CommonCfg.PhyMode < PHY_11ABGN_MIXED)
3046                 return FALSE;
3047
3048         SetHT.PhyMode = pAd->CommonCfg.PhyMode;
3049         SetHT.TransmitNo = ((UCHAR)pAd->Antenna.field.TxPath);
3050         SetHT.HtMode = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.HTMODE;
3051         SetHT.ExtOffset = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.EXTCHA;
3052         SetHT.MCS = MCS_AUTO;
3053         SetHT.BW = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.BW;
3054         SetHT.STBC = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.STBC;
3055         SetHT.SHORTGI = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.ShortGI;
3056
3057         RTMPSetHT(pAd, &SetHT);
3058
3059         return TRUE;
3060 }
3061 #endif // DOT11_N_SUPPORT //
3062
3063 INT     Set_FixedTxMode_Proc(
3064         IN      PRTMP_ADAPTER   pAd,
3065         IN      PUCHAR                  arg)
3066 {
3067         UCHAR   fix_tx_mode = FIXED_TXMODE_HT;
3068
3069         if (strcmp(arg, "OFDM") == 0 || strcmp(arg, "ofdm") == 0)
3070         {
3071                 fix_tx_mode = FIXED_TXMODE_OFDM;
3072         }
3073         else if (strcmp(arg, "CCK") == 0 || strcmp(arg, "cck") == 0)
3074         {
3075         fix_tx_mode = FIXED_TXMODE_CCK;
3076         }
3077
3078 #ifdef CONFIG_STA_SUPPORT
3079         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
3080                 pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode = fix_tx_mode;
3081 #endif // CONFIG_STA_SUPPORT //
3082
3083         DBGPRINT(RT_DEBUG_TRACE, ("Set_FixedTxMode_Proc::(FixedTxMode=%d)\n", fix_tx_mode));
3084
3085         return TRUE;
3086 }
3087
3088 /////////////////////////////////////////////////////////////////////////
3089 PCHAR   RTMPGetRalinkAuthModeStr(
3090     IN  NDIS_802_11_AUTHENTICATION_MODE authMode)
3091 {
3092         switch(authMode)
3093         {
3094                 case Ndis802_11AuthModeOpen:
3095                         return "OPEN";
3096                 case Ndis802_11AuthModeWPAPSK:
3097                         return "WPAPSK";
3098                 case Ndis802_11AuthModeShared:
3099                         return "SHARED";
3100                 case Ndis802_11AuthModeWPA:
3101                         return "WPA";
3102                 case Ndis802_11AuthModeWPA2:
3103                         return "WPA2";
3104                 case Ndis802_11AuthModeWPA2PSK:
3105                         return "WPA2PSK";
3106         case Ndis802_11AuthModeWPA1PSKWPA2PSK:
3107                         return "WPAPSKWPA2PSK";
3108         case Ndis802_11AuthModeWPA1WPA2:
3109                         return "WPA1WPA2";
3110                 case Ndis802_11AuthModeWPANone:
3111                         return "WPANONE";
3112                 default:
3113                         return "UNKNOW";
3114         }
3115 }
3116
3117 PCHAR   RTMPGetRalinkEncryModeStr(
3118     IN  USHORT encryMode)
3119 {
3120         switch(encryMode)
3121         {
3122                 case Ndis802_11WEPDisabled:
3123                         return "NONE";
3124                 case Ndis802_11WEPEnabled:
3125                         return "WEP";
3126                 case Ndis802_11Encryption2Enabled:
3127                         return "TKIP";
3128                 case Ndis802_11Encryption3Enabled:
3129                         return "AES";
3130         case Ndis802_11Encryption4Enabled:
3131                         return "TKIPAES";
3132                 default:
3133                         return "UNKNOW";
3134         }
3135 }
3136
3137 INT RTMPShowCfgValue(
3138         IN      PRTMP_ADAPTER   pAd,
3139         IN      PUCHAR                  pName,
3140         IN      PUCHAR                  pBuf)
3141 {
3142         INT     Status = 0;
3143
3144         for (PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC = RTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC; PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name; PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC++)
3145         {
3146                 if (!strcmp(pName, PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name))
3147                 {
3148                         if(PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->show_proc(pAd, pBuf))
3149                                 Status = -EINVAL;
3150                         break;  //Exit for loop.
3151                 }
3152         }
3153
3154         if(PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name == NULL)
3155         {
3156                 sprintf(pBuf, "\n");
3157                 for (PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC = RTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC; PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name; PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC++)
3158                         sprintf(pBuf + strlen(pBuf), "%s\n", PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name);
3159         }
3160
3161         return Status;
3162 }
3163
3164 INT     Show_SSID_Proc(
3165         IN      PRTMP_ADAPTER   pAd,
3166         OUT     PUCHAR                  pBuf)
3167 {
3168
3169 #ifdef CONFIG_STA_SUPPORT
3170         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
3171                 sprintf(pBuf, "\t%s", pAd->CommonCfg.Ssid);
3172 #endif // CONFIG_STA_SUPPORT //
3173         return 0;
3174 }
3175
3176 INT     Show_WirelessMode_Proc(
3177         IN      PRTMP_ADAPTER   pAd,
3178         OUT     PUCHAR                  pBuf)
3179 {
3180         switch(pAd->CommonCfg.PhyMode)
3181         {
3182                 case PHY_11BG_MIXED:
3183                         sprintf(pBuf, "\t11B/G");
3184                         break;
3185                 case PHY_11B:
3186                         sprintf(pBuf, "\t11B");
3187                         break;
3188                 case PHY_11A:
3189                         sprintf(pBuf, "\t11A");
3190                         break;
3191                 case PHY_11ABG_MIXED:
3192                         sprintf(pBuf, "\t11A/B/G");
3193                         break;
3194                 case PHY_11G:
3195                         sprintf(pBuf, "\t11G");
3196                         break;
3197 #ifdef DOT11_N_SUPPORT
3198                 case PHY_11ABGN_MIXED:
3199                         sprintf(pBuf, "\t11A/B/G/N");
3200                         break;
3201                 case PHY_11N_2_4G:
3202                         sprintf(pBuf, "\t11N only with 2.4G");
3203                         break;
3204                 case PHY_11GN_MIXED:
3205                         sprintf(pBuf, "\t11G/N");
3206                         break;
3207                 case PHY_11AN_MIXED:
3208                         sprintf(pBuf, "\t11A/N");
3209                         break;
3210                 case PHY_11BGN_MIXED:
3211                         sprintf(pBuf, "\t11B/G/N");
3212                         break;
3213                 case PHY_11AGN_MIXED:
3214                         sprintf(pBuf, "\t11A/G/N");
3215                         break;
3216                 case PHY_11N_5G:
3217                         sprintf(pBuf, "\t11N only with 5G");
3218                         break;
3219 #endif // DOT11_N_SUPPORT //
3220                 default:
3221                         sprintf(pBuf, "\tUnknow Value(%d)", pAd->CommonCfg.PhyMode);
3222                         break;
3223         }
3224         return 0;
3225 }
3226
3227
3228 INT     Show_TxBurst_Proc(
3229         IN      PRTMP_ADAPTER   pAd,
3230         OUT     PUCHAR                  pBuf)
3231 {
3232         sprintf(pBuf, "\t%s", pAd->CommonCfg.bEnableTxBurst ? "TRUE":"FALSE");
3233         return 0;
3234 }
3235
3236 INT     Show_TxPreamble_Proc(
3237         IN      PRTMP_ADAPTER   pAd,
3238         OUT     PUCHAR                  pBuf)
3239 {
3240         switch(pAd->CommonCfg.TxPreamble)
3241         {
3242                 case Rt802_11PreambleShort:
3243                         sprintf(pBuf, "\tShort");
3244                         break;
3245                 case Rt802_11PreambleLong:
3246                         sprintf(pBuf, "\tLong");
3247                         break;
3248                 case Rt802_11PreambleAuto:
3249                         sprintf(pBuf, "\tAuto");
3250                         break;
3251                 default:
3252                         sprintf(pBuf, "\tUnknow Value(%lu)", pAd->CommonCfg.TxPreamble);
3253                         break;
3254         }
3255
3256         return 0;
3257 }
3258
3259 INT     Show_TxPower_Proc(
3260         IN      PRTMP_ADAPTER   pAd,
3261         OUT     PUCHAR                  pBuf)
3262 {
3263         sprintf(pBuf, "\t%lu", pAd->CommonCfg.TxPowerPercentage);
3264         return 0;
3265 }
3266
3267 INT     Show_Channel_Proc(
3268         IN      PRTMP_ADAPTER   pAd,
3269         OUT     PUCHAR                  pBuf)
3270 {
3271         sprintf(pBuf, "\t%d", pAd->CommonCfg.Channel);
3272         return 0;
3273 }
3274
3275 INT     Show_BGProtection_Proc(
3276         IN      PRTMP_ADAPTER   pAd,
3277         OUT     PUCHAR                  pBuf)
3278 {
3279         switch(pAd->CommonCfg.UseBGProtection)
3280         {
3281                 case 1: //Always On
3282                         sprintf(pBuf, "\tON");
3283                         break;
3284                 case 2: //Always OFF
3285                         sprintf(pBuf, "\tOFF");
3286                         break;
3287                 case 0: //AUTO
3288                         sprintf(pBuf, "\tAuto");
3289                         break;
3290                 default:
3291                         sprintf(pBuf, "\tUnknow Value(%lu)", pAd->CommonCfg.UseBGProtection);
3292                         break;
3293         }
3294         return 0;
3295 }
3296
3297 INT     Show_RTSThreshold_Proc(
3298         IN      PRTMP_ADAPTER   pAd,
3299         OUT     PUCHAR                  pBuf)
3300 {
3301         sprintf(pBuf, "\t%u", pAd->CommonCfg.RtsThreshold);
3302         return 0;
3303 }
3304
3305 INT     Show_FragThreshold_Proc(
3306         IN      PRTMP_ADAPTER   pAd,
3307         OUT     PUCHAR                  pBuf)
3308 {
3309         sprintf(pBuf, "\t%u", pAd->CommonCfg.FragmentThreshold);
3310         return 0;
3311 }
3312
3313 #ifdef DOT11_N_SUPPORT
3314 INT     Show_HtBw_Proc(
3315         IN      PRTMP_ADAPTER   pAd,
3316         OUT     PUCHAR                  pBuf)
3317 {
3318         if (pAd->CommonCfg.RegTransmitSetting.field.BW == BW_40)
3319         {
3320                 sprintf(pBuf, "\t40 MHz");
3321         }
3322         else
3323         {
3324         sprintf(pBuf, "\t20 MHz");
3325         }
3326         return 0;
3327 }
3328
3329 INT     Show_HtMcs_Proc(
3330         IN      PRTMP_ADAPTER   pAd,
3331         OUT     PUCHAR                  pBuf)
3332 {
3333
3334 #ifdef CONFIG_STA_SUPPORT
3335         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
3336                 sprintf(pBuf, "\t%u", pAd->StaCfg.DesiredTransmitSetting.field.MCS);
3337 #endif // CONFIG_STA_SUPPORT //
3338         return 0;
3339 }
3340
3341 INT     Show_HtGi_Proc(
3342         IN      PRTMP_ADAPTER   pAd,
3343         OUT     PUCHAR                  pBuf)
3344 {
3345         switch(pAd->CommonCfg.RegTransmitSetting.field.ShortGI)
3346         {
3347                 case GI_400:
3348                         sprintf(pBuf, "\tGI_400");
3349                         break;
3350                 case GI_800:
3351                         sprintf(pBuf, "\tGI_800");
3352                         break;
3353                 default:
3354                         sprintf(pBuf, "\tUnknow Value(%u)", pAd->CommonCfg.RegTransmitSetting.field.ShortGI);
3355                         break;
3356         }
3357         return 0;
3358 }
3359
3360 INT     Show_HtOpMode_Proc(
3361         IN      PRTMP_ADAPTER   pAd,
3362         OUT     PUCHAR                  pBuf)
3363 {
3364         switch(pAd->CommonCfg.RegTransmitSetting.field.HTMODE)
3365         {
3366                 case HTMODE_GF:
3367                         sprintf(pBuf, "\tGF");
3368                         break;
3369                 case HTMODE_MM:
3370                         sprintf(pBuf, "\tMM");
3371                         break;
3372                 default:
3373                         sprintf(pBuf, "\tUnknow Value(%u)", pAd->CommonCfg.RegTransmitSetting.field.HTMODE);
3374                         break;
3375         }
3376         return 0;
3377 }
3378
3379 INT     Show_HtExtcha_Proc(
3380         IN      PRTMP_ADAPTER   pAd,
3381         OUT     PUCHAR                  pBuf)
3382 {
3383         switch(pAd->CommonCfg.RegTransmitSetting.field.EXTCHA)
3384         {
3385                 case EXTCHA_BELOW:
3386                         sprintf(pBuf, "\tBelow");
3387                         break;
3388                 case EXTCHA_ABOVE:
3389                         sprintf(pBuf, "\tAbove");
3390                         break;
3391                 default:
3392                         sprintf(pBuf, "\tUnknow Value(%u)", pAd->CommonCfg.RegTransmitSetting.field.EXTCHA);
3393                         break;
3394         }
3395         return 0;
3396 }
3397
3398
3399 INT     Show_HtMpduDensity_Proc(
3400         IN      PRTMP_ADAPTER   pAd,
3401         OUT     PUCHAR                  pBuf)
3402 {
3403         sprintf(pBuf, "\t%u", pAd->CommonCfg.BACapability.field.MpduDensity);
3404         return 0;
3405 }
3406
3407 INT     Show_HtBaWinSize_Proc(
3408         IN      PRTMP_ADAPTER   pAd,
3409         OUT     PUCHAR                  pBuf)
3410 {
3411         sprintf(pBuf, "\t%u", pAd->CommonCfg.BACapability.field.RxBAWinLimit);
3412         return 0;
3413 }
3414
3415 INT     Show_HtRdg_Proc(
3416         IN      PRTMP_ADAPTER   pAd,
3417         OUT     PUCHAR                  pBuf)
3418 {
3419         sprintf(pBuf, "\t%s", pAd->CommonCfg.bRdg ? "TRUE":"FALSE");
3420         return 0;
3421 }
3422
3423 INT     Show_HtAmsdu_Proc(
3424         IN      PRTMP_ADAPTER   pAd,
3425         OUT     PUCHAR                  pBuf)
3426 {
3427         sprintf(pBuf, "\t%s", pAd->CommonCfg.BACapability.field.AmsduEnable ? "TRUE":"FALSE");
3428         return 0;
3429 }
3430
3431 INT     Show_HtAutoBa_Proc(
3432         IN      PRTMP_ADAPTER   pAd,
3433         OUT     PUCHAR                  pBuf)
3434 {
3435         sprintf(pBuf, "\t%s", pAd->CommonCfg.BACapability.field.AutoBA ? "TRUE":"FALSE");
3436         return 0;
3437 }
3438 #endif // DOT11_N_SUPPORT //
3439
3440 INT     Show_CountryRegion_Proc(
3441         IN      PRTMP_ADAPTER   pAd,
3442         OUT     PUCHAR                  pBuf)
3443 {
3444         sprintf(pBuf, "\t%d", pAd->CommonCfg.CountryRegion);
3445         return 0;
3446 }
3447
3448 INT     Show_CountryRegionABand_Proc(
3449         IN      PRTMP_ADAPTER   pAd,
3450         OUT     PUCHAR                  pBuf)
3451 {
3452         sprintf(pBuf, "\t%d", pAd->CommonCfg.CountryRegionForABand);
3453         return 0;
3454 }
3455
3456 INT     Show_CountryCode_Proc(
3457         IN      PRTMP_ADAPTER   pAd,
3458         OUT     PUCHAR                  pBuf)
3459 {
3460         sprintf(pBuf, "\t%s", pAd->CommonCfg.CountryCode);
3461         return 0;
3462 }
3463
3464 #ifdef AGGREGATION_SUPPORT
3465 INT     Show_PktAggregate_Proc(
3466         IN      PRTMP_ADAPTER   pAd,
3467         OUT     PUCHAR                  pBuf)
3468 {
3469         sprintf(pBuf, "\t%s", pAd->CommonCfg.bAggregationCapable ? "TRUE":"FALSE");
3470         return 0;
3471 }
3472 #endif // AGGREGATION_SUPPORT //
3473
3474 #ifdef WMM_SUPPORT
3475 INT     Show_WmmCapable_Proc(
3476         IN      PRTMP_ADAPTER   pAd,
3477         OUT     PUCHAR                  pBuf)
3478 {
3479
3480 #ifdef CONFIG_STA_SUPPORT
3481         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
3482                 sprintf(pBuf, "\t%s", pAd->CommonCfg.bWmmCapable ? "TRUE":"FALSE");
3483 #endif // CONFIG_STA_SUPPORT //
3484
3485         return 0;
3486 }
3487 #endif // WMM_SUPPORT //
3488
3489 INT     Show_IEEE80211H_Proc(
3490         IN      PRTMP_ADAPTER   pAd,
3491         OUT     PUCHAR                  pBuf)
3492 {
3493         sprintf(pBuf, "\t%s", pAd->CommonCfg.bIEEE80211H ? "TRUE":"FALSE");
3494         return 0;
3495 }
3496
3497 #ifdef CONFIG_STA_SUPPORT
3498 INT     Show_NetworkType_Proc(
3499         IN      PRTMP_ADAPTER   pAd,
3500         OUT     PUCHAR                  pBuf)
3501 {
3502         switch(pAd->StaCfg.BssType)
3503         {
3504                 case BSS_ADHOC:
3505                         sprintf(pBuf, "\tAdhoc");
3506                         break;
3507                 case BSS_INFRA:
3508                         sprintf(pBuf, "\tInfra");
3509                         break;
3510                 case BSS_ANY:
3511                         sprintf(pBuf, "\tAny");
3512                         break;
3513                 case BSS_MONITOR:
3514                         sprintf(pBuf, "\tMonitor");
3515                         break;
3516                 default:
3517                         sprintf(pBuf, "\tUnknow Value(%d)", pAd->StaCfg.BssType);
3518                         break;
3519         }
3520         return 0;
3521 }
3522 #endif // CONFIG_STA_SUPPORT //
3523
3524 INT     Show_AuthMode_Proc(
3525         IN      PRTMP_ADAPTER   pAd,
3526         OUT     PUCHAR                  pBuf)
3527 {
3528         NDIS_802_11_AUTHENTICATION_MODE AuthMode = Ndis802_11AuthModeOpen;
3529
3530 #ifdef CONFIG_STA_SUPPORT
3531         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
3532                 AuthMode = pAd->StaCfg.AuthMode;
3533 #endif // CONFIG_STA_SUPPORT //
3534
3535         if ((AuthMode >= Ndis802_11AuthModeOpen) &&
3536                 (AuthMode <= Ndis802_11AuthModeWPA1PSKWPA2PSK))
3537                 sprintf(pBuf, "\t%s", RTMPGetRalinkAuthModeStr(AuthMode));
3538         else
3539                 sprintf(pBuf, "\tUnknow Value(%d)", AuthMode);
3540
3541         return 0;
3542 }
3543
3544 INT     Show_EncrypType_Proc(
3545         IN      PRTMP_ADAPTER   pAd,
3546         OUT     PUCHAR                  pBuf)
3547 {
3548         NDIS_802_11_WEP_STATUS  WepStatus = Ndis802_11WEPDisabled;
3549
3550 #ifdef CONFIG_STA_SUPPORT
3551         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
3552                 WepStatus = pAd->StaCfg.WepStatus;
3553 #endif // CONFIG_STA_SUPPORT //
3554
3555         if ((WepStatus >= Ndis802_11WEPEnabled) &&
3556                 (WepStatus <= Ndis802_11Encryption4KeyAbsent))
3557                 sprintf(pBuf, "\t%s", RTMPGetRalinkEncryModeStr(WepStatus));
3558         else
3559                 sprintf(pBuf, "\tUnknow Value(%d)", WepStatus);
3560
3561         return 0;
3562 }
3563
3564 INT     Show_DefaultKeyID_Proc(
3565         IN      PRTMP_ADAPTER   pAd,
3566         OUT     PUCHAR                  pBuf)
3567 {
3568         UCHAR DefaultKeyId = 0;
3569
3570 #ifdef CONFIG_STA_SUPPORT
3571         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
3572                 DefaultKeyId = pAd->StaCfg.DefaultKeyId;
3573 #endif // CONFIG_STA_SUPPORT //
3574
3575         sprintf(pBuf, "\t%d", DefaultKeyId);
3576
3577         return 0;
3578 }
3579
3580 INT     Show_WepKey_Proc(
3581         IN      PRTMP_ADAPTER   pAd,
3582         IN  INT                         KeyIdx,
3583         OUT     PUCHAR                  pBuf)
3584 {
3585         UCHAR   Key[16] = {0}, KeyLength = 0;
3586         INT             index = BSS0;
3587
3588         KeyLength = pAd->SharedKey[index][KeyIdx].KeyLen;
3589         NdisMoveMemory(Key, pAd->SharedKey[index][KeyIdx].Key, KeyLength);
3590
3591         //check key string is ASCII or not
3592     if (RTMPCheckStrPrintAble(Key, KeyLength))
3593         sprintf(pBuf, "\t%s", Key);
3594     else
3595     {
3596         int idx;
3597         sprintf(pBuf, "\t");
3598         for (idx = 0; idx < KeyLength; idx++)
3599             sprintf(pBuf+strlen(pBuf), "%02X", Key[idx]);
3600     }
3601         return 0;
3602 }
3603
3604 INT     Show_Key1_Proc(
3605         IN      PRTMP_ADAPTER   pAd,
3606         OUT     PUCHAR                  pBuf)
3607 {
3608         Show_WepKey_Proc(pAd, 0, pBuf);
3609         return 0;
3610 }
3611
3612 INT     Show_Key2_Proc(
3613         IN      PRTMP_ADAPTER   pAd,
3614         OUT     PUCHAR                  pBuf)
3615 {
3616         Show_WepKey_Proc(pAd, 1, pBuf);
3617         return 0;
3618 }
3619
3620 INT     Show_Key3_Proc(
3621         IN      PRTMP_ADAPTER   pAd,
3622         OUT     PUCHAR                  pBuf)
3623 {
3624         Show_WepKey_Proc(pAd, 2, pBuf);
3625         return 0;
3626 }
3627
3628 INT     Show_Key4_Proc(
3629         IN      PRTMP_ADAPTER   pAd,
3630         OUT     PUCHAR                  pBuf)
3631 {
3632         Show_WepKey_Proc(pAd, 3, pBuf);
3633         return 0;
3634 }
3635
3636 INT     Show_WPAPSK_Proc(
3637         IN      PRTMP_ADAPTER   pAd,
3638         OUT     PUCHAR                  pBuf)
3639 {
3640         INT     idx;
3641         UCHAR   PMK[32] = {0};
3642
3643
3644 #ifdef CONFIG_STA_SUPPORT
3645         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
3646                 NdisMoveMemory(PMK, pAd->StaCfg.PMK, 32);
3647 #endif // CONFIG_STA_SUPPORT //
3648
3649     sprintf(pBuf, "\tPMK = ");
3650     for (idx = 0; idx < 32; idx++)
3651         sprintf(pBuf+strlen(pBuf), "%02X", PMK[idx]);
3652
3653         return 0;
3654 }
3655