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