Staging: rt28x0: updates from vendor's V2.1.0.0 drivers
[linux-2.6-block.git] / drivers / staging / rt2860 / common / cmm_profile.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
31 #define ETH_MAC_ADDR_STR_LEN 17  // in format of xx:xx:xx:xx:xx:xx
32
33 // We assume the s1 is a sting, s2 is a memory space with 6 bytes. and content of s1 will be changed.
34 BOOLEAN rtstrmactohex(PSTRING s1, PSTRING s2)
35 {
36         int i = 0;
37         PSTRING ptokS = s1, ptokE = s1;
38
39         if (strlen(s1) != ETH_MAC_ADDR_STR_LEN)
40                 return FALSE;
41
42         while((*ptokS) != '\0')
43         {
44                 if((ptokE = strchr(ptokS, ':')) != NULL)
45                         *ptokE++ = '\0';
46                 if ((strlen(ptokS) != 2) || (!isxdigit(*ptokS)) || (!isxdigit(*(ptokS+1))))
47                         break; // fail
48                 AtoH(ptokS, (PUCHAR)&s2[i++], 1);
49                 ptokS = ptokE;
50                 if (i == 6)
51                         break; // parsing finished
52         }
53
54         return ( i == 6 ? TRUE : FALSE);
55
56 }
57
58
59 // we assume the s1 and s2 both are strings.
60 BOOLEAN rtstrcasecmp(PSTRING s1, PSTRING s2)
61 {
62         PSTRING p1 = s1, p2 = s2;
63
64         if (strlen(s1) != strlen(s2))
65                 return FALSE;
66
67         while(*p1 != '\0')
68         {
69                 if((*p1 != *p2) && ((*p1 ^ *p2) != 0x20))
70                         return FALSE;
71                 p1++;
72                 p2++;
73         }
74
75         return TRUE;
76 }
77
78 // we assume the s1 (buffer) and s2 (key) both are strings.
79 PSTRING rtstrstruncasecmp(PSTRING s1, PSTRING s2)
80 {
81         INT l1, l2, i;
82         char temp1, temp2;
83
84         l2 = strlen(s2);
85         if (!l2)
86                 return (char *) s1;
87
88         l1 = strlen(s1);
89
90         while (l1 >= l2)
91         {
92                 l1--;
93
94                 for(i=0; i<l2; i++)
95                 {
96                         temp1 = *(s1+i);
97                         temp2 = *(s2+i);
98
99                         if (('a' <= temp1) && (temp1 <= 'z'))
100                                 temp1 = 'A'+(temp1-'a');
101                         if (('a' <= temp2) && (temp2 <= 'z'))
102                                 temp2 = 'A'+(temp2-'a');
103
104                         if (temp1 != temp2)
105                                 break;
106                 }
107
108                 if (i == l2)
109                         return (char *) s1;
110
111                 s1++;
112         }
113
114         return NULL; // not found
115 }
116
117 //add by kathy
118
119  /**
120   * strstr - Find the first substring in a %NUL terminated string
121   * @s1: The string to be searched
122   * @s2: The string to search for
123   */
124 PSTRING rtstrstr(PSTRING s1,const PSTRING s2)
125 {
126         INT l1, l2;
127
128         l2 = strlen(s2);
129         if (!l2)
130                 return s1;
131
132         l1 = strlen(s1);
133
134         while (l1 >= l2)
135         {
136                 l1--;
137                 if (!memcmp(s1,s2,l2))
138                         return s1;
139                 s1++;
140         }
141
142         return NULL;
143 }
144
145 /**
146  * rstrtok - Split a string into tokens
147  * @s: The string to be searched
148  * @ct: The characters to search for
149  * * WARNING: strtok is deprecated, use strsep instead. However strsep is not compatible with old architecture.
150  */
151 PSTRING __rstrtok;
152 PSTRING rstrtok(PSTRING s,const PSTRING ct)
153 {
154         PSTRING sbegin, send;
155
156         sbegin  = s ? s : __rstrtok;
157         if (!sbegin)
158         {
159                 return NULL;
160         }
161
162         sbegin += strspn(sbegin,ct);
163         if (*sbegin == '\0')
164         {
165                 __rstrtok = NULL;
166                 return( NULL );
167         }
168
169         send = strpbrk( sbegin, ct);
170         if (send && *send != '\0')
171                 *send++ = '\0';
172
173         __rstrtok = send;
174
175         return (sbegin);
176 }
177
178 /**
179  * delimitcnt - return the count of a given delimiter in a given string.
180  * @s: The string to be searched.
181  * @ct: The delimiter to search for.
182  * Notice : We suppose the delimiter is a single-char string(for example : ";").
183  */
184 INT delimitcnt(PSTRING s,PSTRING ct)
185 {
186         INT count = 0;
187         /* point to the beginning of the line */
188         PSTRING token = s;
189
190         for ( ;; )
191         {
192                 token = strpbrk(token, ct); /* search for delimiters */
193
194         if ( token == NULL )
195                 {
196                         /* advanced to the terminating null character */
197                         break;
198                 }
199                 /* skip the delimiter */
200             ++token;
201
202                 /*
203                  * Print the found text: use len with %.*s to specify field width.
204                  */
205
206                 /* accumulate delimiter count */
207             ++count;
208         }
209     return count;
210 }
211
212 /*
213   * converts the Internet host address from the standard numbers-and-dots notation
214   * into binary data.
215   * returns nonzero if the address is valid, zero if not.
216   */
217 int rtinet_aton(PSTRING cp, unsigned int *addr)
218 {
219         unsigned int    val;
220         int             base, n;
221         STRING          c;
222         unsigned int    parts[4];
223         unsigned int    *pp = parts;
224
225         for (;;)
226     {
227          /*
228           * Collect number up to ``.''.
229           * Values are specified as for C:
230           *     0x=hex, 0=octal, other=decimal.
231           */
232          val = 0;
233          base = 10;
234          if (*cp == '0')
235          {
236              if (*++cp == 'x' || *cp == 'X')
237                  base = 16, cp++;
238              else
239                  base = 8;
240          }
241          while ((c = *cp) != '\0')
242          {
243              if (isdigit((unsigned char) c))
244              {
245                  val = (val * base) + (c - '0');
246                  cp++;
247                  continue;
248              }
249              if (base == 16 && isxdigit((unsigned char) c))
250              {
251                  val = (val << 4) +
252                      (c + 10 - (islower((unsigned char) c) ? 'a' : 'A'));
253                  cp++;
254                  continue;
255              }
256              break;
257          }
258          if (*cp == '.')
259          {
260              /*
261               * Internet format: a.b.c.d a.b.c   (with c treated as 16-bits)
262               * a.b     (with b treated as 24 bits)
263               */
264              if (pp >= parts + 3 || val > 0xff)
265                  return 0;
266              *pp++ = val, cp++;
267          }
268          else
269              break;
270      }
271
272      /*
273       * Check for trailing junk.
274       */
275      while (*cp)
276          if (!isspace((unsigned char) *cp++))
277              return 0;
278
279      /*
280       * Concoct the address according to the number of parts specified.
281       */
282      n = pp - parts + 1;
283      switch (n)
284      {
285
286          case 1:         /* a -- 32 bits */
287              break;
288
289          case 2:         /* a.b -- 8.24 bits */
290              if (val > 0xffffff)
291                  return 0;
292              val |= parts[0] << 24;
293              break;
294
295          case 3:         /* a.b.c -- 8.8.16 bits */
296              if (val > 0xffff)
297                  return 0;
298              val |= (parts[0] << 24) | (parts[1] << 16);
299              break;
300
301          case 4:         /* a.b.c.d -- 8.8.8.8 bits */
302              if (val > 0xff)
303                  return 0;
304              val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
305              break;
306      }
307
308      *addr = htonl(val);
309      return 1;
310
311 }
312
313 /*
314     ========================================================================
315
316     Routine Description:
317         Find key section for Get key parameter.
318
319     Arguments:
320         buffer                      Pointer to the buffer to start find the key section
321         section                     the key of the secion to be find
322
323     Return Value:
324         NULL                        Fail
325         Others                      Success
326     ========================================================================
327 */
328 PSTRING RTMPFindSection(
329     IN  PSTRING   buffer)
330 {
331     STRING temp_buf[32];
332     PSTRING  ptr;
333
334     strcpy(temp_buf, "Default");
335
336     if((ptr = rtstrstr(buffer, temp_buf)) != NULL)
337             return (ptr+strlen("\n"));
338         else
339             return NULL;
340 }
341
342 /*
343     ========================================================================
344
345     Routine Description:
346         Get key parameter.
347
348     Arguments:
349         key                     Pointer to key string
350         dest                    Pointer to destination
351         destsize                The datasize of the destination
352         buffer          Pointer to the buffer to start find the key
353         bTrimSpace      Set true if you want to strip the space character of the result pattern
354
355     Return Value:
356         TRUE                        Success
357         FALSE                       Fail
358
359     Note:
360         This routine get the value with the matched key (case case-sensitive)
361         For SSID and security key related parameters, we SHALL NOT trim the space(' ') character.
362     ========================================================================
363 */
364 INT RTMPGetKeyParameter(
365     IN PSTRING key,
366     OUT PSTRING dest,
367     IN INT destsize,
368     IN PSTRING buffer,
369     IN BOOLEAN bTrimSpace)
370 {
371         PSTRING pMemBuf, temp_buf1 = NULL, temp_buf2 = NULL;
372         PSTRING start_ptr, end_ptr;
373         PSTRING ptr;
374         PSTRING offset = NULL;
375         INT  len, keyLen;
376
377
378         keyLen = strlen(key);
379         os_alloc_mem(NULL, (PUCHAR *)&pMemBuf, MAX_PARAM_BUFFER_SIZE  * 2);
380         if (pMemBuf == NULL)
381                 return (FALSE);
382
383         memset(pMemBuf, 0, MAX_PARAM_BUFFER_SIZE * 2);
384         temp_buf1 = pMemBuf;
385         temp_buf2 = (PSTRING)(pMemBuf + MAX_PARAM_BUFFER_SIZE);
386
387
388         //find section
389         if((offset = RTMPFindSection(buffer)) == NULL)
390         {
391                 os_free_mem(NULL, (PUCHAR)pMemBuf);
392                 return (FALSE);
393         }
394
395         strcpy(temp_buf1, "\n");
396         strcat(temp_buf1, key);
397         strcat(temp_buf1, "=");
398
399         //search key
400         if((start_ptr=rtstrstr(offset, temp_buf1)) == NULL)
401         {
402                 os_free_mem(NULL, (PUCHAR)pMemBuf);
403                 return (FALSE);
404         }
405
406         start_ptr += strlen("\n");
407         if((end_ptr = rtstrstr(start_ptr, "\n"))==NULL)
408                 end_ptr = start_ptr+strlen(start_ptr);
409
410         if (end_ptr<start_ptr)
411         {
412                 os_free_mem(NULL, (PUCHAR)pMemBuf);
413                 return (FALSE);
414         }
415
416         NdisMoveMemory(temp_buf2, start_ptr, end_ptr-start_ptr);
417         temp_buf2[end_ptr-start_ptr]='\0';
418         if((start_ptr=rtstrstr(temp_buf2, "=")) == NULL)
419         {
420                 os_free_mem(NULL, (PUCHAR)pMemBuf);
421                 return (FALSE);
422         }
423         ptr = (start_ptr +1);
424         //trim special characters, i.e.,  TAB or space
425         while(*start_ptr != 0x00)
426         {
427                 if( ((*ptr == ' ') && bTrimSpace) || (*ptr == '\t') )
428                         ptr++;
429                 else
430                         break;
431         }
432         len = strlen(start_ptr);
433
434         memset(dest, 0x00, destsize);
435         strncpy(dest, ptr, ((len >= destsize) ? destsize: len));
436
437         os_free_mem(NULL, (PUCHAR)pMemBuf);
438
439         return TRUE;
440 }
441
442
443 /*
444     ========================================================================
445
446     Routine Description:
447         Get multiple key parameter.
448
449     Arguments:
450         key                         Pointer to key string
451         dest                        Pointer to destination
452         destsize                    The datasize of the destination
453         buffer                      Pointer to the buffer to start find the key
454
455     Return Value:
456         TRUE                        Success
457         FALSE                       Fail
458
459     Note:
460         This routine get the value with the matched key (case case-sensitive)
461     ========================================================================
462 */
463 INT RTMPGetKeyParameterWithOffset(
464     IN  PSTRING   key,
465     OUT PSTRING   dest,
466     OUT USHORT  *end_offset,
467     IN  INT     destsize,
468     IN  PSTRING   buffer,
469     IN  BOOLEAN bTrimSpace)
470 {
471     PSTRING temp_buf1 = NULL;
472     PSTRING temp_buf2 = NULL;
473     PSTRING start_ptr;
474     PSTRING end_ptr;
475     PSTRING ptr;
476     PSTRING offset = 0;
477     INT  len;
478
479         if (*end_offset >= MAX_INI_BUFFER_SIZE)
480                 return (FALSE);
481
482         os_alloc_mem(NULL, (PUCHAR *)&temp_buf1, MAX_PARAM_BUFFER_SIZE);
483
484         if(temp_buf1 == NULL)
485         return (FALSE);
486
487         os_alloc_mem(NULL, (PUCHAR *)&temp_buf2, MAX_PARAM_BUFFER_SIZE);
488         if(temp_buf2 == NULL)
489         {
490                 os_free_mem(NULL, (PUCHAR)temp_buf1);
491         return (FALSE);
492         }
493
494     //find section
495         if(*end_offset == 0)
496     {
497                 if ((offset = RTMPFindSection(buffer)) == NULL)
498                 {
499                         os_free_mem(NULL, (PUCHAR)temp_buf1);
500                 os_free_mem(NULL, (PUCHAR)temp_buf2);
501             return (FALSE);
502                 }
503     }
504         else
505                 offset = buffer + (*end_offset);
506
507     strcpy(temp_buf1, "\n");
508     strcat(temp_buf1, key);
509     strcat(temp_buf1, "=");
510
511     //search key
512     if((start_ptr=rtstrstr(offset, temp_buf1))==NULL)
513     {
514                 os_free_mem(NULL, (PUCHAR)temp_buf1);
515         os_free_mem(NULL, (PUCHAR)temp_buf2);
516         return (FALSE);
517     }
518
519     start_ptr+=strlen("\n");
520     if((end_ptr=rtstrstr(start_ptr, "\n"))==NULL)
521        end_ptr=start_ptr+strlen(start_ptr);
522
523     if (end_ptr<start_ptr)
524     {
525                 os_free_mem(NULL, (PUCHAR)temp_buf1);
526         os_free_mem(NULL, (PUCHAR)temp_buf2);
527         return (FALSE);
528     }
529
530         *end_offset = end_ptr - buffer;
531
532     NdisMoveMemory(temp_buf2, start_ptr, end_ptr-start_ptr);
533     temp_buf2[end_ptr-start_ptr]='\0';
534     len = strlen(temp_buf2);
535     strcpy(temp_buf1, temp_buf2);
536     if((start_ptr=rtstrstr(temp_buf1, "=")) == NULL)
537     {
538                 os_free_mem(NULL, (PUCHAR)temp_buf1);
539         os_free_mem(NULL, (PUCHAR)temp_buf2);
540         return (FALSE);
541     }
542
543     strcpy(temp_buf2, start_ptr+1);
544     ptr = temp_buf2;
545     //trim space or tab
546     while(*ptr != 0x00)
547     {
548         if((bTrimSpace && (*ptr == ' ')) || (*ptr == '\t') )
549             ptr++;
550         else
551            break;
552     }
553
554     len = strlen(ptr);
555     memset(dest, 0x00, destsize);
556     strncpy(dest, ptr, len >= destsize ?  destsize: len);
557
558         os_free_mem(NULL, (PUCHAR)temp_buf1);
559     os_free_mem(NULL, (PUCHAR)temp_buf2);
560     return TRUE;
561 }
562
563
564 static int rtmp_parse_key_buffer_from_file(IN  PRTMP_ADAPTER pAd,IN  PSTRING buffer,IN  ULONG KeyType,IN  INT BSSIdx,IN  INT KeyIdx)
565 {
566         PSTRING         keybuff;
567         //INT                   i = BSSIdx, idx = KeyIdx, retVal;
568         ULONG           KeyLen;
569         //UCHAR         CipherAlg = CIPHER_WEP64;
570         CIPHER_KEY      *pSharedKey;
571
572         keybuff = buffer;
573         KeyLen = strlen(keybuff);
574         pSharedKey = &pAd->SharedKey[BSSIdx][KeyIdx];
575
576         if(((KeyType != 0) && (KeyType != 1)) ||
577             ((KeyType == 0) && (KeyLen != 10) && (KeyLen != 26)) ||
578             ((KeyType== 1) && (KeyLen != 5) && (KeyLen != 13)))
579         {
580                 DBGPRINT(RT_DEBUG_ERROR, ("Key%dStr is Invalid key length(%ld) or Type(%ld)\n",
581                                                                 KeyIdx+1, KeyLen, KeyType));
582                 return FALSE;
583         }
584         else
585         {
586                 return RT_CfgSetWepKey(pAd, buffer, pSharedKey, KeyIdx);
587         }
588
589 }
590
591
592 static void rtmp_read_key_parms_from_file(IN  PRTMP_ADAPTER pAd, PSTRING tmpbuf, PSTRING buffer)
593 {
594         STRING          tok_str[16];
595         PSTRING         macptr;
596         INT                     i = 0, idx;
597         ULONG           KeyType[MAX_MBSSID_NUM];
598         ULONG           KeyIdx;
599
600         NdisZeroMemory(KeyType, sizeof(KeyType));
601
602         //DefaultKeyID
603         if(RTMPGetKeyParameter("DefaultKeyID", tmpbuf, 25, buffer, TRUE))
604         {
605                 {
606                         KeyIdx = simple_strtol(tmpbuf, 0, 10);
607                         if((KeyIdx >= 1 ) && (KeyIdx <= 4))
608                                 pAd->StaCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1);
609                         else
610                                 pAd->StaCfg.DefaultKeyId = 0;
611
612                         DBGPRINT(RT_DEBUG_TRACE, ("DefaultKeyID(0~3)=%d\n", pAd->StaCfg.DefaultKeyId));
613                 }
614         }
615
616
617         for (idx = 0; idx < 4; idx++)
618         {
619                 sprintf(tok_str, "Key%dType", idx + 1);
620                 //Key1Type
621                 if (RTMPGetKeyParameter(tok_str, tmpbuf, 128, buffer, TRUE))
622                 {
623                     for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++)
624                     {
625                                 /*
626                                         do sanity check for KeyType length;
627                                         or in station mode, the KeyType length > 1,
628                                         the code will overwrite the stack of caller
629                                         (RTMPSetProfileParameters) and cause srcbuf = NULL
630                                 */
631                                 if (i < MAX_MBSSID_NUM)
632                                         KeyType[i] = simple_strtol(macptr, 0, 10);
633                     }
634
635                         {
636                                 sprintf(tok_str, "Key%dStr", idx + 1);
637                                 if (RTMPGetKeyParameter(tok_str, tmpbuf, 128, buffer, FALSE))
638                                 {
639                                         rtmp_parse_key_buffer_from_file(pAd, tmpbuf, KeyType[BSS0], BSS0, idx);
640                                 }
641                         }
642                 }
643         }
644 }
645
646
647
648 static void rtmp_read_sta_wmm_parms_from_file(IN  PRTMP_ADAPTER pAd, char *tmpbuf, char *buffer)
649 {
650         PSTRING                                 macptr;
651         INT                                             i=0;
652         BOOLEAN                                 bWmmEnable = FALSE;
653
654         //WmmCapable
655         if(RTMPGetKeyParameter("WmmCapable", tmpbuf, 32, buffer, TRUE))
656         {
657                 if(simple_strtol(tmpbuf, 0, 10) != 0) //Enable
658                 {
659                         pAd->CommonCfg.bWmmCapable = TRUE;
660                         bWmmEnable = TRUE;
661                 }
662                 else //Disable
663                 {
664                         pAd->CommonCfg.bWmmCapable = FALSE;
665                 }
666
667                 DBGPRINT(RT_DEBUG_TRACE, ("WmmCapable=%d\n", pAd->CommonCfg.bWmmCapable));
668         }
669
670
671         //AckPolicy for AC_BK, AC_BE, AC_VI, AC_VO
672         if(RTMPGetKeyParameter("AckPolicy", tmpbuf, 32, buffer, TRUE))
673         {
674                 for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++)
675                 {
676                         pAd->CommonCfg.AckPolicy[i] = (UCHAR)simple_strtol(macptr, 0, 10);
677
678                         DBGPRINT(RT_DEBUG_TRACE, ("AckPolicy[%d]=%d\n", i, pAd->CommonCfg.AckPolicy[i]));
679                 }
680         }
681
682         if (bWmmEnable)
683         {
684                 //APSDCapable
685                 if(RTMPGetKeyParameter("APSDCapable", tmpbuf, 10, buffer, TRUE))
686                 {
687                         if(simple_strtol(tmpbuf, 0, 10) != 0)  //Enable
688                                 pAd->CommonCfg.bAPSDCapable = TRUE;
689                         else
690                                 pAd->CommonCfg.bAPSDCapable = FALSE;
691
692                         DBGPRINT(RT_DEBUG_TRACE, ("APSDCapable=%d\n", pAd->CommonCfg.bAPSDCapable));
693                 }
694
695                 //MaxSPLength
696                 if(RTMPGetKeyParameter("MaxSPLength", tmpbuf, 10, buffer, TRUE))
697                 {
698                         pAd->CommonCfg.MaxSPLength = simple_strtol(tmpbuf, 0, 10);
699
700                         DBGPRINT(RT_DEBUG_TRACE, ("MaxSPLength=%d\n", pAd->CommonCfg.MaxSPLength));
701                 }
702
703                 //APSDAC for AC_BE, AC_BK, AC_VI, AC_VO
704                 if(RTMPGetKeyParameter("APSDAC", tmpbuf, 32, buffer, TRUE))
705                 {
706                         BOOLEAN apsd_ac[4];
707
708                         for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++)
709                         {
710                                 apsd_ac[i] = (BOOLEAN)simple_strtol(macptr, 0, 10);
711
712                                 DBGPRINT(RT_DEBUG_TRACE, ("APSDAC%d  %d\n", i,  apsd_ac[i]));
713                         }
714
715                         pAd->CommonCfg.bAPSDAC_BE = apsd_ac[0];
716                         pAd->CommonCfg.bAPSDAC_BK = apsd_ac[1];
717                         pAd->CommonCfg.bAPSDAC_VI = apsd_ac[2];
718                         pAd->CommonCfg.bAPSDAC_VO = apsd_ac[3];
719
720                         pAd->CommonCfg.bACMAPSDTr[0] = apsd_ac[0];
721                         pAd->CommonCfg.bACMAPSDTr[1] = apsd_ac[1];
722                         pAd->CommonCfg.bACMAPSDTr[2] = apsd_ac[2];
723                         pAd->CommonCfg.bACMAPSDTr[3] = apsd_ac[3];
724                 }
725         }
726
727 }
728
729
730 static void HTParametersHook(
731         IN      PRTMP_ADAPTER pAd,
732         IN      PSTRING           pValueStr,
733         IN      PSTRING           pInput)
734 {
735
736         long Value;
737
738     if (RTMPGetKeyParameter("HT_PROTECT", pValueStr, 25, pInput, TRUE))
739     {
740         Value = simple_strtol(pValueStr, 0, 10);
741         if (Value == 0)
742         {
743             pAd->CommonCfg.bHTProtect = FALSE;
744         }
745         else
746         {
747             pAd->CommonCfg.bHTProtect = TRUE;
748         }
749         DBGPRINT(RT_DEBUG_TRACE, ("HT: Protection  = %s\n", (Value==0) ? "Disable" : "Enable"));
750     }
751
752     if (RTMPGetKeyParameter("HT_MIMOPSEnable", pValueStr, 25, pInput, TRUE))
753     {
754         Value = simple_strtol(pValueStr, 0, 10);
755         if (Value == 0)
756         {
757             pAd->CommonCfg.bMIMOPSEnable = FALSE;
758         }
759         else
760         {
761             pAd->CommonCfg.bMIMOPSEnable = TRUE;
762         }
763         DBGPRINT(RT_DEBUG_TRACE, ("HT: MIMOPSEnable  = %s\n", (Value==0) ? "Disable" : "Enable"));
764     }
765
766
767     if (RTMPGetKeyParameter("HT_MIMOPSMode", pValueStr, 25, pInput, TRUE))
768     {
769         Value = simple_strtol(pValueStr, 0, 10);
770         if (Value > MMPS_ENABLE)
771         {
772                         pAd->CommonCfg.BACapability.field.MMPSmode = MMPS_ENABLE;
773         }
774         else
775         {
776             //TODO: add mimo power saving mechanism
777             pAd->CommonCfg.BACapability.field.MMPSmode = MMPS_ENABLE;
778                         //pAd->CommonCfg.BACapability.field.MMPSmode = Value;
779         }
780         DBGPRINT(RT_DEBUG_TRACE, ("HT: MIMOPS Mode  = %d\n", (INT) Value));
781     }
782
783     if (RTMPGetKeyParameter("HT_BADecline", pValueStr, 25, pInput, TRUE))
784     {
785         Value = simple_strtol(pValueStr, 0, 10);
786         if (Value == 0)
787         {
788             pAd->CommonCfg.bBADecline = FALSE;
789         }
790         else
791         {
792             pAd->CommonCfg.bBADecline = TRUE;
793         }
794         DBGPRINT(RT_DEBUG_TRACE, ("HT: BA Decline  = %s\n", (Value==0) ? "Disable" : "Enable"));
795     }
796
797
798     if (RTMPGetKeyParameter("HT_DisableReordering", pValueStr, 25, pInput, TRUE))
799     {
800         Value = simple_strtol(pValueStr, 0, 10);
801         if (Value == 0)
802         {
803             pAd->CommonCfg.bDisableReordering = FALSE;
804         }
805         else
806         {
807             pAd->CommonCfg.bDisableReordering = TRUE;
808         }
809         DBGPRINT(RT_DEBUG_TRACE, ("HT: DisableReordering  = %s\n", (Value==0) ? "Disable" : "Enable"));
810     }
811
812     if (RTMPGetKeyParameter("HT_AutoBA", pValueStr, 25, pInput, TRUE))
813     {
814         Value = simple_strtol(pValueStr, 0, 10);
815         if (Value == 0)
816         {
817             pAd->CommonCfg.BACapability.field.AutoBA = FALSE;
818                         pAd->CommonCfg.BACapability.field.Policy = BA_NOTUSE;
819         }
820         else
821         {
822             pAd->CommonCfg.BACapability.field.AutoBA = TRUE;
823                         pAd->CommonCfg.BACapability.field.Policy = IMMED_BA;
824         }
825         pAd->CommonCfg.REGBACapability.field.AutoBA = pAd->CommonCfg.BACapability.field.AutoBA;
826         DBGPRINT(RT_DEBUG_TRACE, ("HT: Auto BA  = %s\n", (Value==0) ? "Disable" : "Enable"));
827     }
828
829         // Tx_+HTC frame
830     if (RTMPGetKeyParameter("HT_HTC", pValueStr, 25, pInput, TRUE))
831         {
832                 Value = simple_strtol(pValueStr, 0, 10);
833                 if (Value == 0)
834                 {
835                         pAd->HTCEnable = FALSE;
836                 }
837                 else
838                 {
839             pAd->HTCEnable = TRUE;
840                 }
841                 DBGPRINT(RT_DEBUG_TRACE, ("HT: Tx +HTC frame = %s\n", (Value==0) ? "Disable" : "Enable"));
842         }
843
844         // Enable HT Link Adaptation Control
845         if (RTMPGetKeyParameter("HT_LinkAdapt", pValueStr, 25, pInput, TRUE))
846         {
847                 Value = simple_strtol(pValueStr, 0, 10);
848                 if (Value == 0)
849                 {
850                         pAd->bLinkAdapt = FALSE;
851                 }
852                 else
853                 {
854                         pAd->HTCEnable = TRUE;
855                         pAd->bLinkAdapt = TRUE;
856                 }
857                 DBGPRINT(RT_DEBUG_TRACE, ("HT: Link Adaptation Control = %s\n", (Value==0) ? "Disable" : "Enable(+HTC)"));
858         }
859
860         // Reverse Direction Mechanism
861     if (RTMPGetKeyParameter("HT_RDG", pValueStr, 25, pInput, TRUE))
862         {
863                 Value = simple_strtol(pValueStr, 0, 10);
864                 if (Value == 0)
865                 {
866                         pAd->CommonCfg.bRdg = FALSE;
867                 }
868                 else
869                 {
870                         pAd->HTCEnable = TRUE;
871             pAd->CommonCfg.bRdg = TRUE;
872                 }
873                 DBGPRINT(RT_DEBUG_TRACE, ("HT: RDG = %s\n", (Value==0) ? "Disable" : "Enable(+HTC)"));
874         }
875
876
877
878
879         // Tx A-MSUD ?
880     if (RTMPGetKeyParameter("HT_AMSDU", pValueStr, 25, pInput, TRUE))
881         {
882                 Value = simple_strtol(pValueStr, 0, 10);
883                 if (Value == 0)
884                 {
885                         pAd->CommonCfg.BACapability.field.AmsduEnable = FALSE;
886                 }
887                 else
888                 {
889             pAd->CommonCfg.BACapability.field.AmsduEnable = TRUE;
890                 }
891                 DBGPRINT(RT_DEBUG_TRACE, ("HT: Tx A-MSDU = %s\n", (Value==0) ? "Disable" : "Enable"));
892         }
893
894         // MPDU Density
895     if (RTMPGetKeyParameter("HT_MpduDensity", pValueStr, 25, pInput, TRUE))
896         {
897                 Value = simple_strtol(pValueStr, 0, 10);
898                 if (Value <=7 && Value >= 0)
899                 {
900                         pAd->CommonCfg.BACapability.field.MpduDensity = Value;
901                         DBGPRINT(RT_DEBUG_TRACE, ("HT: MPDU Density = %d\n", (INT) Value));
902                 }
903                 else
904                 {
905                         pAd->CommonCfg.BACapability.field.MpduDensity = 4;
906                         DBGPRINT(RT_DEBUG_TRACE, ("HT: MPDU Density = %d (Default)\n", 4));
907                 }
908         }
909
910         // Max Rx BA Window Size
911     if (RTMPGetKeyParameter("HT_BAWinSize", pValueStr, 25, pInput, TRUE))
912         {
913                 Value = simple_strtol(pValueStr, 0, 10);
914
915                 if (Value >=1 && Value <= 64)
916                 {
917                         pAd->CommonCfg.REGBACapability.field.RxBAWinLimit = Value;
918                         pAd->CommonCfg.BACapability.field.RxBAWinLimit = Value;
919                         DBGPRINT(RT_DEBUG_TRACE, ("HT: BA Windw Size = %d\n", (INT) Value));
920                 }
921                 else
922                 {
923             pAd->CommonCfg.REGBACapability.field.RxBAWinLimit = 64;
924                         pAd->CommonCfg.BACapability.field.RxBAWinLimit = 64;
925                         DBGPRINT(RT_DEBUG_TRACE, ("HT: BA Windw Size = 64 (Defualt)\n"));
926                 }
927
928         }
929
930         // Guard Interval
931         if (RTMPGetKeyParameter("HT_GI", pValueStr, 25, pInput, TRUE))
932         {
933                 Value = simple_strtol(pValueStr, 0, 10);
934
935                 if (Value == GI_400)
936                 {
937                         pAd->CommonCfg.RegTransmitSetting.field.ShortGI = GI_400;
938                 }
939                 else
940                 {
941                         pAd->CommonCfg.RegTransmitSetting.field.ShortGI = GI_800;
942                 }
943
944                 DBGPRINT(RT_DEBUG_TRACE, ("HT: Guard Interval = %s\n", (Value==GI_400) ? "400" : "800" ));
945         }
946
947         // HT Operation Mode : Mixed Mode , Green Field
948         if (RTMPGetKeyParameter("HT_OpMode", pValueStr, 25, pInput, TRUE))
949         {
950                 Value = simple_strtol(pValueStr, 0, 10);
951
952                 if (Value == HTMODE_GF)
953                 {
954
955                         pAd->CommonCfg.RegTransmitSetting.field.HTMODE  = HTMODE_GF;
956                 }
957                 else
958                 {
959                         pAd->CommonCfg.RegTransmitSetting.field.HTMODE  = HTMODE_MM;
960                 }
961
962                 DBGPRINT(RT_DEBUG_TRACE, ("HT: Operate Mode = %s\n", (Value==HTMODE_GF) ? "Green Field" : "Mixed Mode" ));
963         }
964
965         // Fixed Tx mode : CCK, OFDM
966         if (RTMPGetKeyParameter("FixedTxMode", pValueStr, 25, pInput, TRUE))
967         {
968                 UCHAR   fix_tx_mode;
969
970                 {
971                         fix_tx_mode = FIXED_TXMODE_HT;
972
973                         if (strcmp(pValueStr, "OFDM") == 0 || strcmp(pValueStr, "ofdm") == 0)
974                         {
975                                 fix_tx_mode = FIXED_TXMODE_OFDM;
976                         }
977                         else if (strcmp(pValueStr, "CCK") == 0 || strcmp(pValueStr, "cck") == 0)
978                         {
979                         fix_tx_mode = FIXED_TXMODE_CCK;
980                         }
981                         else if (strcmp(pValueStr, "HT") == 0 || strcmp(pValueStr, "ht") == 0)
982                         {
983                         fix_tx_mode = FIXED_TXMODE_HT;
984                 }
985                 else
986                 {
987                                 Value = simple_strtol(pValueStr, 0, 10);
988                                 // 1 : CCK
989                                 // 2 : OFDM
990                                 // otherwise : HT
991                                 if (Value == FIXED_TXMODE_CCK || Value == FIXED_TXMODE_OFDM)
992                                         fix_tx_mode = Value;
993                                 else
994                                         fix_tx_mode = FIXED_TXMODE_HT;
995                 }
996
997                         pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode = fix_tx_mode;
998                         DBGPRINT(RT_DEBUG_TRACE, ("Fixed Tx Mode = %d\n", fix_tx_mode));
999
1000                 }
1001         }
1002
1003
1004         // Channel Width
1005         if (RTMPGetKeyParameter("HT_BW", pValueStr, 25, pInput, TRUE))
1006         {
1007                 Value = simple_strtol(pValueStr, 0, 10);
1008
1009                 if (Value == BW_40)
1010                 {
1011                         pAd->CommonCfg.RegTransmitSetting.field.BW  = BW_40;
1012                 }
1013                 else
1014                 {
1015             pAd->CommonCfg.RegTransmitSetting.field.BW  = BW_20;
1016                 }
1017
1018                 DBGPRINT(RT_DEBUG_TRACE, ("HT: Channel Width = %s\n", (Value==BW_40) ? "40 MHz" : "20 MHz" ));
1019         }
1020
1021         if (RTMPGetKeyParameter("HT_EXTCHA", pValueStr, 25, pInput, TRUE))
1022         {
1023                 Value = simple_strtol(pValueStr, 0, 10);
1024
1025                 if (Value == 0)
1026                 {
1027
1028                         pAd->CommonCfg.RegTransmitSetting.field.EXTCHA  = EXTCHA_BELOW;
1029                 }
1030                 else
1031                 {
1032             pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_ABOVE;
1033                 }
1034
1035                 DBGPRINT(RT_DEBUG_TRACE, ("HT: Ext Channel = %s\n", (Value==0) ? "BELOW" : "ABOVE" ));
1036         }
1037
1038         // MSC
1039         if (RTMPGetKeyParameter("HT_MCS", pValueStr, 50, pInput, TRUE))
1040         {
1041                 {
1042                         Value = simple_strtol(pValueStr, 0, 10);
1043
1044 //                      if ((Value >= 0 && Value <= 15) || (Value == 32))
1045                         if ((Value >= 0 && Value <= 23) || (Value == 32)) // 3*3
1046                 {
1047                                 pAd->StaCfg.DesiredTransmitSetting.field.MCS  = Value;
1048                                 pAd->StaCfg.bAutoTxRateSwitch = FALSE;
1049                                 DBGPRINT(RT_DEBUG_TRACE, ("HT: MCS = %d\n", pAd->StaCfg.DesiredTransmitSetting.field.MCS));
1050                 }
1051                 else
1052                 {
1053                                 pAd->StaCfg.DesiredTransmitSetting.field.MCS  = MCS_AUTO;
1054                                 pAd->StaCfg.bAutoTxRateSwitch = TRUE;
1055                                 DBGPRINT(RT_DEBUG_TRACE, ("HT: MCS = AUTO\n"));
1056                 }
1057         }
1058         }
1059
1060         // STBC
1061     if (RTMPGetKeyParameter("HT_STBC", pValueStr, 25, pInput, TRUE))
1062         {
1063                 Value = simple_strtol(pValueStr, 0, 10);
1064                 if (Value == STBC_USE)
1065                 {
1066                         pAd->CommonCfg.RegTransmitSetting.field.STBC = STBC_USE;
1067                 }
1068                 else
1069                 {
1070                         pAd->CommonCfg.RegTransmitSetting.field.STBC = STBC_NONE;
1071                 }
1072                 DBGPRINT(RT_DEBUG_TRACE, ("HT: STBC = %d\n", pAd->CommonCfg.RegTransmitSetting.field.STBC));
1073         }
1074
1075         // 40_Mhz_Intolerant
1076         if (RTMPGetKeyParameter("HT_40MHZ_INTOLERANT", pValueStr, 25, pInput, TRUE))
1077         {
1078                 Value = simple_strtol(pValueStr, 0, 10);
1079                 if (Value == 0)
1080                 {
1081                         pAd->CommonCfg.bForty_Mhz_Intolerant = FALSE;
1082                 }
1083                 else
1084                 {
1085                         pAd->CommonCfg.bForty_Mhz_Intolerant = TRUE;
1086                 }
1087                 DBGPRINT(RT_DEBUG_TRACE, ("HT: 40MHZ INTOLERANT = %d\n", pAd->CommonCfg.bForty_Mhz_Intolerant));
1088         }
1089         //HT_TxStream
1090         if(RTMPGetKeyParameter("HT_TxStream", pValueStr, 10, pInput, TRUE))
1091         {
1092                 switch (simple_strtol(pValueStr, 0, 10))
1093                 {
1094                         case 1:
1095                                 pAd->CommonCfg.TxStream = 1;
1096                                 break;
1097                         case 2:
1098                                 pAd->CommonCfg.TxStream = 2;
1099                                 break;
1100                         case 3: // 3*3
1101                         default:
1102                                 pAd->CommonCfg.TxStream = 3;
1103
1104                                 if (pAd->MACVersion < RALINK_2883_VERSION)
1105                                         pAd->CommonCfg.TxStream = 2; // only 2 tx streams for RT2860 series
1106                                 break;
1107                 }
1108                 DBGPRINT(RT_DEBUG_TRACE, ("HT: Tx Stream = %d\n", pAd->CommonCfg.TxStream));
1109         }
1110         //HT_RxStream
1111         if(RTMPGetKeyParameter("HT_RxStream", pValueStr, 10, pInput, TRUE))
1112         {
1113                 switch (simple_strtol(pValueStr, 0, 10))
1114                 {
1115                         case 1:
1116                                 pAd->CommonCfg.RxStream = 1;
1117                                 break;
1118                         case 2:
1119                                 pAd->CommonCfg.RxStream = 2;
1120                                 break;
1121                         case 3:
1122                         default:
1123                                 pAd->CommonCfg.RxStream = 3;
1124
1125                                 if (pAd->MACVersion < RALINK_2883_VERSION)
1126                                         pAd->CommonCfg.RxStream = 2; // only 2 rx streams for RT2860 series
1127                                 break;
1128                 }
1129                 DBGPRINT(RT_DEBUG_TRACE, ("HT: Rx Stream = %d\n", pAd->CommonCfg.RxStream));
1130         }
1131         //2008/11/05: KH add to support Antenna power-saving of AP<--
1132         //Green AP
1133         if(RTMPGetKeyParameter("GreenAP", pValueStr, 10, pInput, TRUE))
1134         {
1135                 Value = simple_strtol(pValueStr, 0, 10);
1136                 if (Value == 0)
1137                 {
1138                         pAd->CommonCfg.bGreenAPEnable = FALSE;
1139                 }
1140                 else
1141                 {
1142                         pAd->CommonCfg.bGreenAPEnable = TRUE;
1143                 }
1144                 DBGPRINT(RT_DEBUG_TRACE, ("HT: Green AP= %d\n", pAd->CommonCfg.bGreenAPEnable));
1145         }
1146
1147         // HT_DisallowTKIP
1148         if (RTMPGetKeyParameter("HT_DisallowTKIP", pValueStr, 25, pInput, TRUE))
1149         {
1150                 Value = simple_strtol(pValueStr, 0, 10);
1151
1152                 if (Value == 1)
1153                 {
1154                         pAd->CommonCfg.HT_DisallowTKIP = TRUE;
1155                 }
1156                 else
1157                 {
1158                         pAd->CommonCfg.HT_DisallowTKIP = FALSE;
1159                 }
1160
1161                 DBGPRINT(RT_DEBUG_TRACE, ("HT: Disallow TKIP mode = %s\n", (pAd->CommonCfg.HT_DisallowTKIP == TRUE) ? "ON" : "OFF" ));
1162         }
1163
1164
1165         //2008/11/05:KH add to support Antenna power-saving of AP-->
1166 }
1167
1168
1169 NDIS_STATUS     RTMPSetProfileParameters(
1170         IN RTMP_ADAPTER *pAd,
1171         IN PSTRING      pBuffer)
1172 {
1173         PSTRING                                 tmpbuf;
1174         ULONG                                   RtsThresh;
1175         ULONG                                   FragThresh;
1176         PSTRING                                 macptr;
1177         INT                                             i = 0, retval;
1178         tmpbuf = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
1179         if(tmpbuf == NULL)
1180                 return NDIS_STATUS_FAILURE;
1181
1182         do
1183         {
1184                 // set file parameter to portcfg
1185                 //CountryRegion
1186                 if(RTMPGetKeyParameter("CountryRegion", tmpbuf, 25, pBuffer, TRUE))
1187                 {
1188                         retval = RT_CfgSetCountryRegion(pAd, tmpbuf, BAND_24G);
1189                         DBGPRINT(RT_DEBUG_TRACE, ("CountryRegion=%d\n", pAd->CommonCfg.CountryRegion));
1190                 }
1191                 //CountryRegionABand
1192                 if(RTMPGetKeyParameter("CountryRegionABand", tmpbuf, 25, pBuffer, TRUE))
1193                 {
1194                         retval = RT_CfgSetCountryRegion(pAd, tmpbuf, BAND_5G);
1195                         DBGPRINT(RT_DEBUG_TRACE, ("CountryRegionABand=%d\n", pAd->CommonCfg.CountryRegionForABand));
1196                 }
1197 #ifdef RTMP_EFUSE_SUPPORT
1198 #ifdef RT30xx
1199                 //EfuseBufferMode
1200                 if(RTMPGetKeyParameter("EfuseBufferMode", tmpbuf, 25, pBuffer, TRUE))
1201                 {
1202                         pAd->bEEPROMFile = (UCHAR) simple_strtol(tmpbuf, 0, 10);
1203                         DBGPRINT(RT_DEBUG_TRACE, ("EfuseBufferMode=%d\n", pAd->bUseEfuse));
1204                 }
1205 #endif // RT30xx //
1206 #endif // RTMP_EFUSE_SUPPORT //
1207                 //CountryCode
1208                 if(RTMPGetKeyParameter("CountryCode", tmpbuf, 25, pBuffer, TRUE))
1209                 {
1210                         NdisMoveMemory(pAd->CommonCfg.CountryCode, tmpbuf , 2);
1211                         if (strlen((PSTRING) pAd->CommonCfg.CountryCode) != 0)
1212                         {
1213                                 pAd->CommonCfg.bCountryFlag = TRUE;
1214                         }
1215                         DBGPRINT(RT_DEBUG_TRACE, ("CountryCode=%s\n", pAd->CommonCfg.CountryCode));
1216                 }
1217                 //ChannelGeography
1218                 if(RTMPGetKeyParameter("ChannelGeography", tmpbuf, 25, pBuffer, TRUE))
1219                 {
1220                         UCHAR Geography = (UCHAR) simple_strtol(tmpbuf, 0, 10);
1221                         if (Geography <= BOTH)
1222                         {
1223                                 pAd->CommonCfg.Geography = Geography;
1224                                 pAd->CommonCfg.CountryCode[2] =
1225                                         (pAd->CommonCfg.Geography == BOTH) ? ' ' : ((pAd->CommonCfg.Geography == IDOR) ? 'I' : 'O');
1226                                 DBGPRINT(RT_DEBUG_TRACE, ("ChannelGeography=%d\n", pAd->CommonCfg.Geography));
1227                         }
1228                 }
1229                 else
1230                 {
1231                         pAd->CommonCfg.Geography = BOTH;
1232                         pAd->CommonCfg.CountryCode[2] = ' ';
1233                 }
1234
1235                 {
1236                         //SSID
1237                         if (RTMPGetKeyParameter("SSID", tmpbuf, 256, pBuffer, FALSE))
1238                         {
1239                                 if (strlen(tmpbuf) <= 32)
1240                                 {
1241                                                 pAd->CommonCfg.SsidLen = (UCHAR) strlen(tmpbuf);
1242                                         NdisZeroMemory(pAd->CommonCfg.Ssid, NDIS_802_11_LENGTH_SSID);
1243                                         NdisMoveMemory(pAd->CommonCfg.Ssid, tmpbuf, pAd->CommonCfg.SsidLen);
1244                                         pAd->MlmeAux.AutoReconnectSsidLen = pAd->CommonCfg.SsidLen;
1245                                         NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, NDIS_802_11_LENGTH_SSID);
1246                                         NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid, tmpbuf, pAd->MlmeAux.AutoReconnectSsidLen);
1247                                         pAd->MlmeAux.SsidLen = pAd->CommonCfg.SsidLen;
1248                                         NdisZeroMemory(pAd->MlmeAux.Ssid, NDIS_802_11_LENGTH_SSID);
1249                                         NdisMoveMemory(pAd->MlmeAux.Ssid, tmpbuf, pAd->MlmeAux.SsidLen);
1250                                         DBGPRINT(RT_DEBUG_TRACE, ("%s::(SSID=%s)\n", __func__, tmpbuf));
1251                                 }
1252                         }
1253                 }
1254
1255                 {
1256                         //NetworkType
1257                         if (RTMPGetKeyParameter("NetworkType", tmpbuf, 25, pBuffer, TRUE))
1258                         {
1259                                 pAd->bConfigChanged = TRUE;
1260                                 if (strcmp(tmpbuf, "Adhoc") == 0)
1261                                         pAd->StaCfg.BssType = BSS_ADHOC;
1262                                 else //Default Infrastructure mode
1263                                         pAd->StaCfg.BssType = BSS_INFRA;
1264                                 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
1265                                 pAd->StaCfg.WpaState = SS_NOTUSE;
1266                                 DBGPRINT(RT_DEBUG_TRACE, ("%s::(NetworkType=%d)\n", __func__, pAd->StaCfg.BssType));
1267                         }
1268                 }
1269                 //Channel
1270                 if(RTMPGetKeyParameter("Channel", tmpbuf, 10, pBuffer, TRUE))
1271                 {
1272                         pAd->CommonCfg.Channel = (UCHAR) simple_strtol(tmpbuf, 0, 10);
1273                         DBGPRINT(RT_DEBUG_TRACE, ("Channel=%d\n", pAd->CommonCfg.Channel));
1274                 }
1275                 //WirelessMode
1276                 if(RTMPGetKeyParameter("WirelessMode", tmpbuf, 10, pBuffer, TRUE))
1277                 {
1278                         RT_CfgSetWirelessMode(pAd, tmpbuf);
1279                         DBGPRINT(RT_DEBUG_TRACE, ("PhyMode=%d\n", pAd->CommonCfg.PhyMode));
1280                 }
1281             //BasicRate
1282                 if(RTMPGetKeyParameter("BasicRate", tmpbuf, 10, pBuffer, TRUE))
1283                 {
1284                         pAd->CommonCfg.BasicRateBitmap = (ULONG) simple_strtol(tmpbuf, 0, 10);
1285                         DBGPRINT(RT_DEBUG_TRACE, ("BasicRate=%ld\n", pAd->CommonCfg.BasicRateBitmap));
1286                 }
1287                 //BeaconPeriod
1288                 if(RTMPGetKeyParameter("BeaconPeriod", tmpbuf, 10, pBuffer, TRUE))
1289                 {
1290                         pAd->CommonCfg.BeaconPeriod = (USHORT) simple_strtol(tmpbuf, 0, 10);
1291                         DBGPRINT(RT_DEBUG_TRACE, ("BeaconPeriod=%d\n", pAd->CommonCfg.BeaconPeriod));
1292                 }
1293             //TxPower
1294                 if(RTMPGetKeyParameter("TxPower", tmpbuf, 10, pBuffer, TRUE))
1295                 {
1296                         pAd->CommonCfg.TxPowerPercentage = (ULONG) simple_strtol(tmpbuf, 0, 10);
1297                                 pAd->CommonCfg.TxPowerDefault = pAd->CommonCfg.TxPowerPercentage;
1298                         DBGPRINT(RT_DEBUG_TRACE, ("TxPower=%ld\n", pAd->CommonCfg.TxPowerPercentage));
1299                 }
1300                 //BGProtection
1301                 if(RTMPGetKeyParameter("BGProtection", tmpbuf, 10, pBuffer, TRUE))
1302                 {
1303         //#if 0 //#ifndef WIFI_TEST
1304         //              pAd->CommonCfg.UseBGProtection = 2;// disable b/g protection for throughput test
1305         //#else
1306                         switch (simple_strtol(tmpbuf, 0, 10))
1307                         {
1308                                 case 1: //Always On
1309                                         pAd->CommonCfg.UseBGProtection = 1;
1310                                         break;
1311                                 case 2: //Always OFF
1312                                         pAd->CommonCfg.UseBGProtection = 2;
1313                                         break;
1314                                 case 0: //AUTO
1315                                 default:
1316                                         pAd->CommonCfg.UseBGProtection = 0;
1317                                         break;
1318                         }
1319         //#endif
1320                         DBGPRINT(RT_DEBUG_TRACE, ("BGProtection=%ld\n", pAd->CommonCfg.UseBGProtection));
1321                 }
1322                 //OLBCDetection
1323                 if(RTMPGetKeyParameter("DisableOLBC", tmpbuf, 10, pBuffer, TRUE))
1324                 {
1325                         switch (simple_strtol(tmpbuf, 0, 10))
1326                         {
1327                                 case 1: //disable OLBC Detection
1328                                         pAd->CommonCfg.DisableOLBCDetect = 1;
1329                                         break;
1330                                 case 0: //enable OLBC Detection
1331                                         pAd->CommonCfg.DisableOLBCDetect = 0;
1332                                         break;
1333                                 default:
1334                                         pAd->CommonCfg.DisableOLBCDetect= 0;
1335                                         break;
1336                         }
1337                         DBGPRINT(RT_DEBUG_TRACE, ("OLBCDetection=%ld\n", pAd->CommonCfg.DisableOLBCDetect));
1338                 }
1339                 //TxPreamble
1340                 if(RTMPGetKeyParameter("TxPreamble", tmpbuf, 10, pBuffer, TRUE))
1341                 {
1342                         switch (simple_strtol(tmpbuf, 0, 10))
1343                         {
1344                                 case Rt802_11PreambleShort:
1345                                         pAd->CommonCfg.TxPreamble = Rt802_11PreambleShort;
1346                                         break;
1347                                 case Rt802_11PreambleLong:
1348                                 default:
1349                                         pAd->CommonCfg.TxPreamble = Rt802_11PreambleLong;
1350                                         break;
1351                         }
1352                         DBGPRINT(RT_DEBUG_TRACE, ("TxPreamble=%ld\n", pAd->CommonCfg.TxPreamble));
1353                 }
1354                 //RTSThreshold
1355                 if(RTMPGetKeyParameter("RTSThreshold", tmpbuf, 10, pBuffer, TRUE))
1356                 {
1357                         RtsThresh = simple_strtol(tmpbuf, 0, 10);
1358                         if( (RtsThresh >= 1) && (RtsThresh <= MAX_RTS_THRESHOLD) )
1359                                 pAd->CommonCfg.RtsThreshold  = (USHORT)RtsThresh;
1360                         else
1361                                 pAd->CommonCfg.RtsThreshold = MAX_RTS_THRESHOLD;
1362
1363                         DBGPRINT(RT_DEBUG_TRACE, ("RTSThreshold=%d\n", pAd->CommonCfg.RtsThreshold));
1364                 }
1365                 //FragThreshold
1366                 if(RTMPGetKeyParameter("FragThreshold", tmpbuf, 10, pBuffer, TRUE))
1367                 {
1368                         FragThresh = simple_strtol(tmpbuf, 0, 10);
1369                         pAd->CommonCfg.bUseZeroToDisableFragment = FALSE;
1370
1371                         if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
1372                         { //illegal FragThresh so we set it to default
1373                                 pAd->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
1374                                 pAd->CommonCfg.bUseZeroToDisableFragment = TRUE;
1375                         }
1376                         else if (FragThresh % 2 == 1)
1377                         {
1378                                 // The length of each fragment shall always be an even number of octets, except for the last fragment
1379                                 // of an MSDU or MMPDU, which may be either an even or an odd number of octets.
1380                                 pAd->CommonCfg.FragmentThreshold = (USHORT)(FragThresh - 1);
1381                         }
1382                         else
1383                         {
1384                                 pAd->CommonCfg.FragmentThreshold = (USHORT)FragThresh;
1385                         }
1386                         //pAd->CommonCfg.AllowFragSize = (pAd->CommonCfg.FragmentThreshold) - LENGTH_802_11 - LENGTH_CRC;
1387                         DBGPRINT(RT_DEBUG_TRACE, ("FragThreshold=%d\n", pAd->CommonCfg.FragmentThreshold));
1388                 }
1389                 //TxBurst
1390                 if(RTMPGetKeyParameter("TxBurst", tmpbuf, 10, pBuffer, TRUE))
1391                 {
1392         //#ifdef WIFI_TEST
1393         //                                              pAd->CommonCfg.bEnableTxBurst = FALSE;
1394         //#else
1395                         if(simple_strtol(tmpbuf, 0, 10) != 0)  //Enable
1396                                 pAd->CommonCfg.bEnableTxBurst = TRUE;
1397                         else //Disable
1398                                 pAd->CommonCfg.bEnableTxBurst = FALSE;
1399         //#endif
1400                         DBGPRINT(RT_DEBUG_TRACE, ("TxBurst=%d\n", pAd->CommonCfg.bEnableTxBurst));
1401                 }
1402
1403 #ifdef AGGREGATION_SUPPORT
1404                 //PktAggregate
1405                 if(RTMPGetKeyParameter("PktAggregate", tmpbuf, 10, pBuffer, TRUE))
1406                 {
1407                         if(simple_strtol(tmpbuf, 0, 10) != 0)  //Enable
1408                                 pAd->CommonCfg.bAggregationCapable = TRUE;
1409                         else //Disable
1410                                 pAd->CommonCfg.bAggregationCapable = FALSE;
1411 #ifdef PIGGYBACK_SUPPORT
1412                         pAd->CommonCfg.bPiggyBackCapable = pAd->CommonCfg.bAggregationCapable;
1413 #endif // PIGGYBACK_SUPPORT //
1414                         DBGPRINT(RT_DEBUG_TRACE, ("PktAggregate=%d\n", pAd->CommonCfg.bAggregationCapable));
1415                 }
1416 #else
1417                 pAd->CommonCfg.bAggregationCapable = FALSE;
1418                 pAd->CommonCfg.bPiggyBackCapable = FALSE;
1419 #endif // AGGREGATION_SUPPORT //
1420
1421                 // WmmCapable
1422
1423                         rtmp_read_sta_wmm_parms_from_file(pAd, tmpbuf, pBuffer);
1424
1425                 //ShortSlot
1426                 if(RTMPGetKeyParameter("ShortSlot", tmpbuf, 10, pBuffer, TRUE))
1427                 {
1428                         RT_CfgSetShortSlot(pAd, tmpbuf);
1429                         DBGPRINT(RT_DEBUG_TRACE, ("ShortSlot=%d\n", pAd->CommonCfg.bUseShortSlotTime));
1430                 }
1431                 //IEEE80211H
1432                 if(RTMPGetKeyParameter("IEEE80211H", tmpbuf, 10, pBuffer, TRUE))
1433                 {
1434                     for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++)
1435                     {
1436                                 if(simple_strtol(macptr, 0, 10) != 0)  //Enable
1437                                         pAd->CommonCfg.bIEEE80211H = TRUE;
1438                                 else //Disable
1439                                         pAd->CommonCfg.bIEEE80211H = FALSE;
1440
1441                                 DBGPRINT(RT_DEBUG_TRACE, ("IEEE80211H=%d\n", pAd->CommonCfg.bIEEE80211H));
1442                     }
1443                 }
1444                 //CSPeriod
1445                 if(RTMPGetKeyParameter("CSPeriod", tmpbuf, 10, pBuffer, TRUE))
1446                 {
1447                     if(simple_strtol(tmpbuf, 0, 10) != 0)
1448                                 pAd->CommonCfg.RadarDetect.CSPeriod = simple_strtol(tmpbuf, 0, 10);
1449                         else
1450                                 pAd->CommonCfg.RadarDetect.CSPeriod = 0;
1451
1452                                 DBGPRINT(RT_DEBUG_TRACE, ("CSPeriod=%d\n", pAd->CommonCfg.RadarDetect.CSPeriod));
1453                 }
1454
1455                 //RDRegion
1456                 if(RTMPGetKeyParameter("RDRegion", tmpbuf, 128, pBuffer, TRUE))
1457                 {
1458                                                 RADAR_DETECT_STRUCT     *pRadarDetect = &pAd->CommonCfg.RadarDetect;
1459                         if ((strncmp(tmpbuf, "JAP_W53", 7) == 0) || (strncmp(tmpbuf, "jap_w53", 7) == 0))
1460                         {
1461                                                         pRadarDetect->RDDurRegion = JAP_W53;
1462                                                         pRadarDetect->DfsSessionTime = 15;
1463                         }
1464                         else if ((strncmp(tmpbuf, "JAP_W56", 7) == 0) || (strncmp(tmpbuf, "jap_w56", 7) == 0))
1465                         {
1466                                                         pRadarDetect->RDDurRegion = JAP_W56;
1467                                                         pRadarDetect->DfsSessionTime = 13;
1468                         }
1469                         else if ((strncmp(tmpbuf, "JAP", 3) == 0) || (strncmp(tmpbuf, "jap", 3) == 0))
1470                         {
1471                                                         pRadarDetect->RDDurRegion = JAP;
1472                                                         pRadarDetect->DfsSessionTime = 5;
1473                         }
1474                         else  if ((strncmp(tmpbuf, "FCC", 3) == 0) || (strncmp(tmpbuf, "fcc", 3) == 0))
1475                         {
1476                                                         pRadarDetect->RDDurRegion = FCC;
1477                                                         pRadarDetect->DfsSessionTime = 5;
1478                         }
1479                         else if ((strncmp(tmpbuf, "CE", 2) == 0) || (strncmp(tmpbuf, "ce", 2) == 0))
1480                         {
1481                                                         pRadarDetect->RDDurRegion = CE;
1482                                                         pRadarDetect->DfsSessionTime = 13;
1483                         }
1484                         else
1485                         {
1486                                                         pRadarDetect->RDDurRegion = CE;
1487                                                         pRadarDetect->DfsSessionTime = 13;
1488                         }
1489
1490                                                 DBGPRINT(RT_DEBUG_TRACE, ("RDRegion=%d\n", pRadarDetect->RDDurRegion));
1491                 }
1492                 else
1493                 {
1494                         pAd->CommonCfg.RadarDetect.RDDurRegion = CE;
1495                         pAd->CommonCfg.RadarDetect.DfsSessionTime = 13;
1496                 }
1497
1498                 //WirelessEvent
1499                 if(RTMPGetKeyParameter("WirelessEvent", tmpbuf, 10, pBuffer, TRUE))
1500                 {
1501                     if(simple_strtol(tmpbuf, 0, 10) != 0)
1502                                 pAd->CommonCfg.bWirelessEvent = simple_strtol(tmpbuf, 0, 10);
1503                         else
1504                                 pAd->CommonCfg.bWirelessEvent = 0;      // disable
1505                                 DBGPRINT(RT_DEBUG_TRACE, ("WirelessEvent=%d\n", pAd->CommonCfg.bWirelessEvent));
1506                 }
1507                 if(RTMPGetKeyParameter("WiFiTest", tmpbuf, 10, pBuffer, TRUE))
1508                 {
1509                     if(simple_strtol(tmpbuf, 0, 10) != 0)
1510                                 pAd->CommonCfg.bWiFiTest= simple_strtol(tmpbuf, 0, 10);
1511                         else
1512                                 pAd->CommonCfg.bWiFiTest = 0;   // disable
1513
1514                                 DBGPRINT(RT_DEBUG_TRACE, ("WiFiTest=%d\n", pAd->CommonCfg.bWiFiTest));
1515                 }
1516                 //AuthMode
1517                 if(RTMPGetKeyParameter("AuthMode", tmpbuf, 128, pBuffer, TRUE))
1518                 {
1519                         {
1520                                 if ((strcmp(tmpbuf, "WEPAUTO") == 0) || (strcmp(tmpbuf, "wepauto") == 0))
1521                                     pAd->StaCfg.AuthMode = Ndis802_11AuthModeAutoSwitch;
1522                                 else if ((strcmp(tmpbuf, "SHARED") == 0) || (strcmp(tmpbuf, "shared") == 0))
1523                                     pAd->StaCfg.AuthMode = Ndis802_11AuthModeShared;
1524                                 else if ((strcmp(tmpbuf, "WPAPSK") == 0) || (strcmp(tmpbuf, "wpapsk") == 0))
1525                                     pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
1526                                 else if ((strcmp(tmpbuf, "WPANONE") == 0) || (strcmp(tmpbuf, "wpanone") == 0))
1527                                     pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
1528                                 else if ((strcmp(tmpbuf, "WPA2PSK") == 0) || (strcmp(tmpbuf, "wpa2psk") == 0))
1529                                                             pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
1530                                                         else if ((strcmp(tmpbuf, "WPA") == 0) || (strcmp(tmpbuf, "wpa") == 0))
1531                                             pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
1532                                                         else if ((strcmp(tmpbuf, "WPA2") == 0) || (strcmp(tmpbuf, "wpa2") == 0))
1533                                                             pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
1534                                 else
1535                                     pAd->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1536
1537                                 pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
1538
1539                                 DBGPRINT(RT_DEBUG_TRACE, ("%s::(AuthMode=%d)\n", __func__, pAd->StaCfg.AuthMode));
1540                         }
1541                 }
1542                 //EncrypType
1543                 if(RTMPGetKeyParameter("EncrypType", tmpbuf, 128, pBuffer, TRUE))
1544                 {
1545                         {
1546                                 if ((strcmp(tmpbuf, "WEP") == 0) || (strcmp(tmpbuf, "wep") == 0))
1547                                         pAd->StaCfg.WepStatus   = Ndis802_11WEPEnabled;
1548                                 else if ((strcmp(tmpbuf, "TKIP") == 0) || (strcmp(tmpbuf, "tkip") == 0))
1549                                         pAd->StaCfg.WepStatus   = Ndis802_11Encryption2Enabled;
1550                                 else if ((strcmp(tmpbuf, "AES") == 0) || (strcmp(tmpbuf, "aes") == 0))
1551                                         pAd->StaCfg.WepStatus   = Ndis802_11Encryption3Enabled;
1552                                 else
1553                                         pAd->StaCfg.WepStatus   = Ndis802_11WEPDisabled;
1554
1555                                 // Update all wepstatus related
1556                                 pAd->StaCfg.PairCipher          = pAd->StaCfg.WepStatus;
1557                                 pAd->StaCfg.GroupCipher         = pAd->StaCfg.WepStatus;
1558                                 pAd->StaCfg.OrigWepStatus       = pAd->StaCfg.WepStatus;
1559                                 pAd->StaCfg.bMixCipher          = FALSE;
1560
1561                                 //RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, 0);
1562                                 DBGPRINT(RT_DEBUG_TRACE, ("%s::(EncrypType=%d)\n", __func__, pAd->StaCfg.WepStatus));
1563                         }
1564                 }
1565
1566                 {
1567                         if(RTMPGetKeyParameter("WPAPSK", tmpbuf, 512, pBuffer, FALSE))
1568                         {
1569                                 int     ret = TRUE;
1570
1571                                 tmpbuf[strlen(tmpbuf)] = '\0'; // make STA can process .$^& for WPAPSK input
1572
1573                                 if ((pAd->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
1574                                         (pAd->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
1575                                         (pAd->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
1576                                         )
1577                                 {
1578                                         ret = FALSE;
1579                                 }
1580                                 else
1581                                 {
1582                                         ret = RT_CfgSetWPAPSKKey(pAd, tmpbuf, (PUCHAR)pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen, pAd->StaCfg.PMK);
1583                                 }
1584
1585                                 if (ret == TRUE)
1586                                 {
1587                         RTMPZeroMemory(pAd->StaCfg.WpaPassPhrase, 64);
1588                         RTMPMoveMemory(pAd->StaCfg.WpaPassPhrase, tmpbuf, strlen(tmpbuf));
1589                                         pAd->StaCfg.WpaPassPhraseLen= strlen(tmpbuf);
1590
1591                                         if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
1592                                                 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
1593                                         {
1594                                                 // Start STA supplicant state machine
1595                                                 pAd->StaCfg.WpaState = SS_START;
1596                                         }
1597                                         else if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
1598                                         {
1599                                                 pAd->StaCfg.WpaState = SS_NOTUSE;
1600                                         }
1601                                         DBGPRINT(RT_DEBUG_TRACE, ("%s::(WPAPSK=%s)\n", __func__, tmpbuf));
1602                                 }
1603                         }
1604                 }
1605
1606                 //DefaultKeyID, KeyType, KeyStr
1607                 rtmp_read_key_parms_from_file(pAd, tmpbuf, pBuffer);
1608
1609
1610                 //HSCounter
1611                 /*if(RTMPGetKeyParameter("HSCounter", tmpbuf, 10, pBuffer, TRUE))
1612                 {
1613                         switch (simple_strtol(tmpbuf, 0, 10))
1614                         {
1615                                 case 1: //Enable
1616                                         pAd->CommonCfg.bEnableHSCounter = TRUE;
1617                                         break;
1618                                 case 0: //Disable
1619                                 default:
1620                                         pAd->CommonCfg.bEnableHSCounter = FALSE;
1621                                         break;
1622                         }
1623                         DBGPRINT(RT_DEBUG_TRACE, "HSCounter=%d\n", pAd->CommonCfg.bEnableHSCounter);
1624                 }*/
1625
1626                 HTParametersHook(pAd, tmpbuf, pBuffer);
1627
1628                 {
1629                         //PSMode
1630                         if (RTMPGetKeyParameter("PSMode", tmpbuf, 10, pBuffer, TRUE))
1631                         {
1632                                 if (pAd->StaCfg.BssType == BSS_INFRA)
1633                                 {
1634                                         if ((strcmp(tmpbuf, "MAX_PSP") == 0) || (strcmp(tmpbuf, "max_psp") == 0))
1635                                         {
1636                                                 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
1637                                                 // to exclude certain situations.
1638                                                 //         MlmeSetPsm(pAd, PWR_SAVE);
1639                                                 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
1640                                                 if (pAd->StaCfg.bWindowsACCAMEnable == FALSE)
1641                                                         pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeMAX_PSP;
1642                                                 pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeMAX_PSP;
1643                                                 pAd->StaCfg.DefaultListenCount = 5;
1644                                         }
1645                                         else if ((strcmp(tmpbuf, "Fast_PSP") == 0) || (strcmp(tmpbuf, "fast_psp") == 0)
1646                                                 || (strcmp(tmpbuf, "FAST_PSP") == 0))
1647                                         {
1648                                                 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
1649                                                 // to exclude certain situations.
1650                                                 //         RTMP_SET_PSM_BIT(pAd, PWR_SAVE);
1651                                                 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
1652                                                 if (pAd->StaCfg.bWindowsACCAMEnable == FALSE)
1653                                                         pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeFast_PSP;
1654                                                 pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeFast_PSP;
1655                                                 pAd->StaCfg.DefaultListenCount = 3;
1656                                         }
1657                                         else if ((strcmp(tmpbuf, "Legacy_PSP") == 0) || (strcmp(tmpbuf, "legacy_psp") == 0)
1658                                                 || (strcmp(tmpbuf, "LEGACY_PSP") == 0))
1659                                         {
1660                                                 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
1661                                                 // to exclude certain situations.
1662                                                 //         RTMP_SET_PSM_BIT(pAd, PWR_SAVE);
1663                                                 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
1664                                                 if (pAd->StaCfg.bWindowsACCAMEnable == FALSE)
1665                                                         pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeLegacy_PSP;
1666                                                 pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeLegacy_PSP;
1667                                                 pAd->StaCfg.DefaultListenCount = 3;
1668                                         }
1669                                         else
1670                                         { //Default Ndis802_11PowerModeCAM
1671                                                 // clear PSM bit immediately
1672                                                 RTMP_SET_PSM_BIT(pAd, PWR_ACTIVE);
1673                                                 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
1674                                                 if (pAd->StaCfg.bWindowsACCAMEnable == FALSE)
1675                                                         pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
1676                                                 pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
1677                                         }
1678                                         DBGPRINT(RT_DEBUG_TRACE, ("PSMode=%ld\n", pAd->StaCfg.WindowsPowerMode));
1679                                 }
1680                         }
1681                         // AutoRoaming by RSSI
1682                         if (RTMPGetKeyParameter("AutoRoaming", tmpbuf, 32, pBuffer, TRUE))
1683                         {
1684                                 if (simple_strtol(tmpbuf, 0, 10) == 0)
1685                                         pAd->StaCfg.bAutoRoaming = FALSE;
1686                                 else
1687                                         pAd->StaCfg.bAutoRoaming = TRUE;
1688
1689                                 DBGPRINT(RT_DEBUG_TRACE, ("AutoRoaming=%d\n", pAd->StaCfg.bAutoRoaming));
1690                         }
1691                         // RoamThreshold
1692                         if (RTMPGetKeyParameter("RoamThreshold", tmpbuf, 32, pBuffer, TRUE))
1693                         {
1694                                 long lInfo = simple_strtol(tmpbuf, 0, 10);
1695
1696                                 if (lInfo > 90 || lInfo < 60)
1697                                         pAd->StaCfg.dBmToRoam = -70;
1698                                 else
1699                                         pAd->StaCfg.dBmToRoam = (CHAR)(-1)*lInfo;
1700
1701                                 DBGPRINT(RT_DEBUG_TRACE, ("RoamThreshold=%d  dBm\n", pAd->StaCfg.dBmToRoam));
1702                         }
1703
1704                         if(RTMPGetKeyParameter("TGnWifiTest", tmpbuf, 10, pBuffer, TRUE))
1705                         {
1706                                 if(simple_strtol(tmpbuf, 0, 10) == 0)
1707                                         pAd->StaCfg.bTGnWifiTest = FALSE;
1708                                 else
1709                                         pAd->StaCfg.bTGnWifiTest = TRUE;
1710                                         DBGPRINT(RT_DEBUG_TRACE, ("TGnWifiTest=%d\n", pAd->StaCfg.bTGnWifiTest));
1711                         }
1712
1713                         // Beacon Lost Time
1714                         if (RTMPGetKeyParameter("BeaconLostTime", tmpbuf, 32, pBuffer, TRUE))
1715                         {
1716                                 ULONG lInfo = (ULONG)simple_strtol(tmpbuf, 0, 10);
1717
1718                                 if ((lInfo != 0) && (lInfo <= 60))
1719                                         pAd->StaCfg.BeaconLostTime = (lInfo * OS_HZ);
1720                                 DBGPRINT(RT_DEBUG_TRACE, ("BeaconLostTime=%ld \n", pAd->StaCfg.BeaconLostTime));
1721                         }
1722
1723
1724                 }
1725
1726
1727
1728
1729         }while(0);
1730
1731
1732         kfree(tmpbuf);
1733
1734         return NDIS_STATUS_SUCCESS;
1735
1736 }