2 *************************************************************************
4 * 5F., No.36, Taiyuan St., Jhubei City,
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
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. *
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. *
25 *************************************************************************
28 #include "rt_config.h"
30 #ifdef DOT11_N_SUPPORT
31 static void HTParametersHook(
35 #endif // DOT11_N_SUPPORT //
37 #define ETH_MAC_ADDR_STR_LEN 17 // in format of xx:xx:xx:xx:xx:xx
39 // We assume the s1 is a sting, s2 is a memory space with 6 bytes. and content of s1 will be changed.
40 BOOLEAN rtstrmactohex(char *s1, char *s2)
43 char *ptokS = s1, *ptokE = s1;
45 if (strlen(s1) != ETH_MAC_ADDR_STR_LEN)
48 while((*ptokS) != '\0')
50 if((ptokE = strchr(ptokS, ':')) != NULL)
52 if ((strlen(ptokS) != 2) || (!isxdigit(*ptokS)) || (!isxdigit(*(ptokS+1))))
54 AtoH(ptokS, &s2[i++], 1);
57 break; // parsing finished
60 return ( i == 6 ? TRUE : FALSE);
65 // we assume the s1 and s2 both are strings.
66 BOOLEAN rtstrcasecmp(char *s1, char *s2)
68 char *p1 = s1, *p2 = s2;
70 if (strlen(s1) != strlen(s2))
75 if((*p1 != *p2) && ((*p1 ^ *p2) != 0x20))
84 // we assume the s1 (buffer) and s2 (key) both are strings.
85 char * rtstrstruncasecmp(char * s1, char * s2)
105 if (('a' <= temp1) && (temp1 <= 'z'))
106 temp1 = 'A'+(temp1-'a');
107 if (('a' <= temp2) && (temp2 <= 'z'))
108 temp2 = 'A'+(temp2-'a');
120 return NULL; // not found
126 * strstr - Find the first substring in a %NUL terminated string
127 * @s1: The string to be searched
128 * @s2: The string to search for
130 char * rtstrstr(const char * s1,const char * s2)
143 if (!memcmp(s1,s2,l2))
152 * rstrtok - Split a string into tokens
153 * @s: The string to be searched
154 * @ct: The characters to search for
155 * * WARNING: strtok is deprecated, use strsep instead. However strsep is not compatible with old architecture.
158 char * rstrtok(char * s,const char * ct)
162 sbegin = s ? s : __rstrtok;
168 sbegin += strspn(sbegin,ct);
175 send = strpbrk( sbegin, ct);
176 if (send && *send != '\0')
185 * delimitcnt - return the count of a given delimiter in a given string.
186 * @s: The string to be searched.
187 * @ct: The delimiter to search for.
188 * Notice : We suppose the delimiter is a single-char string(for example : ";").
190 INT delimitcnt(char * s,const char * ct)
193 /* point to the beginning of the line */
194 const char *token = s;
198 token = strpbrk(token, ct); /* search for delimiters */
202 /* advanced to the terminating null character */
205 /* skip the delimiter */
209 * Print the found text: use len with %.*s to specify field width.
212 /* accumulate delimiter count */
219 * converts the Internet host address from the standard numbers-and-dots notation
221 * returns nonzero if the address is valid, zero if not.
223 int rtinet_aton(const char *cp, unsigned int *addr)
228 unsigned int parts[4];
229 unsigned int *pp = parts;
234 * Collect number up to ``.''.
235 * Values are specified as for C:
236 * 0x=hex, 0=octal, other=decimal.
242 if (*++cp == 'x' || *cp == 'X')
247 while ((c = *cp) != '\0')
249 if (isdigit((unsigned char) c))
251 val = (val * base) + (c - '0');
255 if (base == 16 && isxdigit((unsigned char) c))
258 (c + 10 - (islower((unsigned char) c) ? 'a' : 'A'));
267 * Internet format: a.b.c.d a.b.c (with c treated as 16-bits)
268 * a.b (with b treated as 24 bits)
270 if (pp >= parts + 3 || val > 0xff)
279 * Check for trailing junk.
282 if (!isspace((unsigned char) *cp++))
286 * Concoct the address according to the number of parts specified.
292 case 1: /* a -- 32 bits */
295 case 2: /* a.b -- 8.24 bits */
298 val |= parts[0] << 24;
301 case 3: /* a.b.c -- 8.8.16 bits */
304 val |= (parts[0] << 24) | (parts[1] << 16);
307 case 4: /* a.b.c.d -- 8.8.8.8 bits */
310 val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
320 ========================================================================
323 Find key section for Get key parameter.
326 buffer Pointer to the buffer to start find the key section
327 section the key of the secion to be find
332 ========================================================================
334 PUCHAR RTMPFindSection(
340 strcpy(temp_buf, "Default");
342 if((ptr = rtstrstr(buffer, temp_buf)) != NULL)
343 return (ptr+strlen("\n"));
349 ========================================================================
355 key Pointer to key string
356 dest Pointer to destination
357 destsize The datasize of the destination
358 buffer Pointer to the buffer to start find the key
365 This routine get the value with the matched key (case case-sensitive)
366 ========================================================================
368 INT RTMPGetKeyParameter(
374 UCHAR *temp_buf1 = NULL;
375 UCHAR *temp_buf2 = NULL;
382 //temp_buf1 = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
383 os_alloc_mem(NULL, &temp_buf1, MAX_PARAM_BUFFER_SIZE);
385 if(temp_buf1 == NULL)
388 //temp_buf2 = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
389 os_alloc_mem(NULL, &temp_buf2, MAX_PARAM_BUFFER_SIZE);
390 if(temp_buf2 == NULL)
392 os_free_mem(NULL, temp_buf1);
397 if((offset = RTMPFindSection(buffer)) == NULL)
399 os_free_mem(NULL, temp_buf1);
400 os_free_mem(NULL, temp_buf2);
404 strcpy(temp_buf1, "\n");
405 strcat(temp_buf1, key);
406 strcat(temp_buf1, "=");
409 if((start_ptr=rtstrstr(offset, temp_buf1))==NULL)
411 os_free_mem(NULL, temp_buf1);
412 os_free_mem(NULL, temp_buf2);
416 start_ptr+=strlen("\n");
417 if((end_ptr=rtstrstr(start_ptr, "\n"))==NULL)
418 end_ptr=start_ptr+strlen(start_ptr);
420 if (end_ptr<start_ptr)
422 os_free_mem(NULL, temp_buf1);
423 os_free_mem(NULL, temp_buf2);
427 NdisMoveMemory(temp_buf2, start_ptr, end_ptr-start_ptr);
428 temp_buf2[end_ptr-start_ptr]='\0';
429 len = strlen(temp_buf2);
430 strcpy(temp_buf1, temp_buf2);
431 if((start_ptr=rtstrstr(temp_buf1, "=")) == NULL)
433 os_free_mem(NULL, temp_buf1);
434 os_free_mem(NULL, temp_buf2);
438 strcpy(temp_buf2, start_ptr+1);
443 if( (*ptr == ' ') || (*ptr == '\t') )
450 memset(dest, 0x00, destsize);
451 strncpy(dest, ptr, len >= destsize ? destsize: len);
453 os_free_mem(NULL, temp_buf1);
454 os_free_mem(NULL, temp_buf2);
459 ========================================================================
465 key Pointer to key string
466 dest Pointer to destination
467 destsize The datasize of the destination
468 buffer Pointer to the buffer to start find the key
475 This routine get the value with the matched key (case case-sensitive).
476 It is called for parsing SSID and any key string.
477 ========================================================================
479 INT RTMPGetCriticalParameter(
485 UCHAR *temp_buf1 = NULL;
486 UCHAR *temp_buf2 = NULL;
493 //temp_buf1 = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
494 os_alloc_mem(NULL, &temp_buf1, MAX_PARAM_BUFFER_SIZE);
496 if(temp_buf1 == NULL)
499 //temp_buf2 = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
500 os_alloc_mem(NULL, &temp_buf2, MAX_PARAM_BUFFER_SIZE);
501 if(temp_buf2 == NULL)
503 os_free_mem(NULL, temp_buf1);
508 if((offset = RTMPFindSection(buffer)) == NULL)
510 os_free_mem(NULL, temp_buf1);
511 os_free_mem(NULL, temp_buf2);
515 strcpy(temp_buf1, "\n");
516 strcat(temp_buf1, key);
517 strcat(temp_buf1, "=");
520 if((start_ptr=rtstrstr(offset, temp_buf1))==NULL)
522 os_free_mem(NULL, temp_buf1);
523 os_free_mem(NULL, temp_buf2);
527 start_ptr+=strlen("\n");
528 if((end_ptr=rtstrstr(start_ptr, "\n"))==NULL)
529 end_ptr=start_ptr+strlen(start_ptr);
531 if (end_ptr<start_ptr)
533 os_free_mem(NULL, temp_buf1);
534 os_free_mem(NULL, temp_buf2);
538 NdisMoveMemory(temp_buf2, start_ptr, end_ptr-start_ptr);
539 temp_buf2[end_ptr-start_ptr]='\0';
540 len = strlen(temp_buf2);
541 strcpy(temp_buf1, temp_buf2);
542 if((start_ptr=rtstrstr(temp_buf1, "=")) == NULL)
544 os_free_mem(NULL, temp_buf1);
545 os_free_mem(NULL, temp_buf2);
549 strcpy(temp_buf2, start_ptr+1);
553 /* We cannot trim space(' ') for SSID and key string. */
556 //if( (*ptr == ' ') || (*ptr == '\t') )
564 memset(dest, 0x00, destsize);
565 strncpy(dest, ptr, len >= destsize ? destsize: len);
567 os_free_mem(NULL, temp_buf1);
568 os_free_mem(NULL, temp_buf2);
573 ========================================================================
576 Get multiple key parameter.
579 key Pointer to key string
580 dest Pointer to destination
581 destsize The datasize of the destination
582 buffer Pointer to the buffer to start find the key
589 This routine get the value with the matched key (case case-sensitive)
590 ========================================================================
592 INT RTMPGetKeyParameterWithOffset(
595 OUT USHORT *end_offset,
598 IN BOOLEAN bTrimSpace)
600 UCHAR *temp_buf1 = NULL;
601 UCHAR *temp_buf2 = NULL;
608 if (*end_offset >= MAX_INI_BUFFER_SIZE)
611 os_alloc_mem(NULL, &temp_buf1, MAX_PARAM_BUFFER_SIZE);
613 if(temp_buf1 == NULL)
616 os_alloc_mem(NULL, &temp_buf2, MAX_PARAM_BUFFER_SIZE);
617 if(temp_buf2 == NULL)
619 os_free_mem(NULL, temp_buf1);
626 if ((offset = RTMPFindSection(buffer)) == NULL)
628 os_free_mem(NULL, temp_buf1);
629 os_free_mem(NULL, temp_buf2);
634 offset = buffer + (*end_offset);
636 strcpy(temp_buf1, "\n");
637 strcat(temp_buf1, key);
638 strcat(temp_buf1, "=");
641 if((start_ptr=rtstrstr(offset, temp_buf1))==NULL)
643 os_free_mem(NULL, temp_buf1);
644 os_free_mem(NULL, temp_buf2);
648 start_ptr+=strlen("\n");
649 if((end_ptr=rtstrstr(start_ptr, "\n"))==NULL)
650 end_ptr=start_ptr+strlen(start_ptr);
652 if (end_ptr<start_ptr)
654 os_free_mem(NULL, temp_buf1);
655 os_free_mem(NULL, temp_buf2);
659 *end_offset = end_ptr - buffer;
661 NdisMoveMemory(temp_buf2, start_ptr, end_ptr-start_ptr);
662 temp_buf2[end_ptr-start_ptr]='\0';
663 len = strlen(temp_buf2);
664 strcpy(temp_buf1, temp_buf2);
665 if((start_ptr=rtstrstr(temp_buf1, "=")) == NULL)
667 os_free_mem(NULL, temp_buf1);
668 os_free_mem(NULL, temp_buf2);
672 strcpy(temp_buf2, start_ptr+1);
677 if((bTrimSpace && (*ptr == ' ')) || (*ptr == '\t') )
684 memset(dest, 0x00, destsize);
685 strncpy(dest, ptr, len >= destsize ? destsize: len);
687 os_free_mem(NULL, temp_buf1);
688 os_free_mem(NULL, temp_buf2);
693 static int rtmp_parse_key_buffer_from_file(IN PRTMP_ADAPTER pAd,IN char *buffer,IN ULONG KeyType,IN INT BSSIdx,IN INT KeyIdx)
696 INT i = BSSIdx, idx = KeyIdx;
698 UCHAR CipherAlg = CIPHER_WEP64;
701 KeyLen = strlen(keybuff);
705 if( (KeyLen == 5) || (KeyLen == 13))
707 pAd->SharedKey[i][idx].KeyLen = KeyLen;
708 NdisMoveMemory(pAd->SharedKey[i][idx].Key, keybuff, KeyLen);
710 CipherAlg = CIPHER_WEP64;
712 CipherAlg = CIPHER_WEP128;
713 pAd->SharedKey[i][idx].CipherAlg = CipherAlg;
715 DBGPRINT(RT_DEBUG_TRACE, ("I/F(ra%d) Key%dStr=%s and type=%s\n", i, idx+1, keybuff, (KeyType == 0) ? "Hex":"Ascii"));
719 {//Invalid key length
720 DBGPRINT(RT_DEBUG_ERROR, ("Key%dStr is Invalid key length! KeyLen = %ld!\n", idx+1, KeyLen));
726 if( (KeyLen == 10) || (KeyLen == 26))
728 pAd->SharedKey[i][idx].KeyLen = KeyLen / 2;
729 AtoH(keybuff, pAd->SharedKey[i][idx].Key, KeyLen / 2);
731 CipherAlg = CIPHER_WEP64;
733 CipherAlg = CIPHER_WEP128;
734 pAd->SharedKey[i][idx].CipherAlg = CipherAlg;
736 DBGPRINT(RT_DEBUG_TRACE, ("I/F(ra%d) Key%dStr=%s and type=%s\n", i, idx+1, keybuff, (KeyType == 0) ? "Hex":"Ascii"));
740 {//Invalid key length
741 DBGPRINT(RT_DEBUG_ERROR, ("I/F(ra%d) Key%dStr is Invalid key length! KeyLen = %ld!\n", i, idx+1, KeyLen));
746 static void rtmp_read_key_parms_from_file(IN PRTMP_ADAPTER pAd, char *tmpbuf, char *buffer)
751 ULONG KeyType[MAX_MBSSID_NUM];
754 NdisZeroMemory(KeyType, MAX_MBSSID_NUM);
757 if(RTMPGetKeyParameter("DefaultKeyID", tmpbuf, 25, buffer))
760 #ifdef CONFIG_STA_SUPPORT
761 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
763 KeyIdx = simple_strtol(tmpbuf, 0, 10);
764 if((KeyIdx >= 1 ) && (KeyIdx <= 4))
765 pAd->StaCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1);
767 pAd->StaCfg.DefaultKeyId = 0;
769 DBGPRINT(RT_DEBUG_TRACE, ("DefaultKeyID(0~3)=%d\n", pAd->StaCfg.DefaultKeyId));
771 #endif // CONFIG_STA_SUPPORT //
775 for (idx = 0; idx < 4; idx++)
777 sprintf(tok_str, "Key%dType", idx + 1);
779 if (RTMPGetKeyParameter(tok_str, tmpbuf, 128, buffer))
781 for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++)
783 KeyType[i] = simple_strtol(macptr, 0, 10);
786 #ifdef CONFIG_STA_SUPPORT
787 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
789 sprintf(tok_str, "Key%dStr", idx + 1);
790 if (RTMPGetCriticalParameter(tok_str, tmpbuf, 128, buffer))
792 rtmp_parse_key_buffer_from_file(pAd, tmpbuf, KeyType[BSS0], BSS0, idx);
795 #endif // CONFIG_STA_SUPPORT //
801 #ifdef CONFIG_STA_SUPPORT
802 static void rtmp_read_sta_wmm_parms_from_file(IN PRTMP_ADAPTER pAd, char *tmpbuf, char *buffer)
806 BOOLEAN bWmmEnable = FALSE;
809 if(RTMPGetKeyParameter("WmmCapable", tmpbuf, 32, buffer))
811 if(simple_strtol(tmpbuf, 0, 10) != 0) //Enable
813 pAd->CommonCfg.bWmmCapable = TRUE;
818 pAd->CommonCfg.bWmmCapable = FALSE;
821 DBGPRINT(RT_DEBUG_TRACE, ("WmmCapable=%d\n", pAd->CommonCfg.bWmmCapable));
824 //AckPolicy for AC_BK, AC_BE, AC_VI, AC_VO
825 if(RTMPGetKeyParameter("AckPolicy", tmpbuf, 32, buffer))
827 for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++)
829 pAd->CommonCfg.AckPolicy[i] = (UCHAR)simple_strtol(macptr, 0, 10);
831 DBGPRINT(RT_DEBUG_TRACE, ("AckPolicy[%d]=%d\n", i, pAd->CommonCfg.AckPolicy[i]));
838 if(RTMPGetKeyParameter("APSDCapable", tmpbuf, 10, buffer))
840 if(simple_strtol(tmpbuf, 0, 10) != 0) //Enable
841 pAd->CommonCfg.bAPSDCapable = TRUE;
843 pAd->CommonCfg.bAPSDCapable = FALSE;
845 DBGPRINT(RT_DEBUG_TRACE, ("APSDCapable=%d\n", pAd->CommonCfg.bAPSDCapable));
848 //APSDAC for AC_BE, AC_BK, AC_VI, AC_VO
849 if(RTMPGetKeyParameter("APSDAC", tmpbuf, 32, buffer))
853 for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++)
855 apsd_ac[i] = (BOOLEAN)simple_strtol(macptr, 0, 10);
857 DBGPRINT(RT_DEBUG_TRACE, ("APSDAC%d %d\n", i, apsd_ac[i]));
860 pAd->CommonCfg.bAPSDAC_BE = apsd_ac[0];
861 pAd->CommonCfg.bAPSDAC_BK = apsd_ac[1];
862 pAd->CommonCfg.bAPSDAC_VI = apsd_ac[2];
863 pAd->CommonCfg.bAPSDAC_VO = apsd_ac[3];
868 #endif // CONFIG_STA_SUPPORT //
871 NDIS_STATUS RTMPReadParametersHook(
872 IN PRTMP_ADAPTER pAd)
876 INT retval, orgfsuid, orgfsgid;
882 #ifdef CONFIG_STA_SUPPORT
883 UCHAR keyMaterial[40];
884 #endif // CONFIG_STA_SUPPORT //
890 buffer = kmalloc(MAX_INI_BUFFER_SIZE, MEM_ALLOC_FLAG);
892 return NDIS_STATUS_FAILURE;
894 tmpbuf = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
898 return NDIS_STATUS_FAILURE;
901 #ifdef CONFIG_STA_SUPPORT
902 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
903 src = STA_PROFILE_PATH;
904 #endif // CONFIG_STA_SUPPORT //
906 // Save uid and gid used for filesystem access.
907 // Set user and group to 0 (root)
908 orgfsuid = current_fsuid();
909 orgfsgid = current_fsgid();
910 /* Hm, can't really do this nicely anymore, so rely on these files
911 * being set to the proper permission to read them... */
912 /* current->cred->fsuid = current->cred->fsgid = 0; */
918 srcf = filp_open(src, O_RDONLY, 0);
921 DBGPRINT(RT_DEBUG_ERROR, ("--> Error %ld opening %s\n", -PTR_ERR(srcf),src));
925 // The object must have a read method
926 if (srcf->f_op && srcf->f_op->read)
928 memset(buffer, 0x00, MAX_INI_BUFFER_SIZE);
929 retval=srcf->f_op->read(srcf, buffer, MAX_INI_BUFFER_SIZE, &srcf->f_pos);
932 DBGPRINT(RT_DEBUG_TRACE, ("--> Read %s error %d\n", src, -retval));
936 // set file parameter to portcfg
938 if(RTMPGetKeyParameter("CountryRegion", tmpbuf, 25, buffer))
940 pAd->CommonCfg.CountryRegion = (UCHAR) simple_strtol(tmpbuf, 0, 10);
941 DBGPRINT(RT_DEBUG_TRACE, ("CountryRegion=%d\n", pAd->CommonCfg.CountryRegion));
944 if(RTMPGetKeyParameter("CountryRegionABand", tmpbuf, 25, buffer))
946 pAd->CommonCfg.CountryRegionForABand= (UCHAR) simple_strtol(tmpbuf, 0, 10);
947 DBGPRINT(RT_DEBUG_TRACE, ("CountryRegionABand=%d\n", pAd->CommonCfg.CountryRegionForABand));
950 if(RTMPGetKeyParameter("CountryCode", tmpbuf, 25, buffer))
952 NdisMoveMemory(pAd->CommonCfg.CountryCode, tmpbuf , 2);
953 #ifdef CONFIG_STA_SUPPORT
954 #ifdef EXT_BUILD_CHANNEL_LIST
955 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
956 NdisMoveMemory(pAd->StaCfg.StaOriCountryCode, tmpbuf , 2);
957 #endif // EXT_BUILD_CHANNEL_LIST //
958 #endif // CONFIG_STA_SUPPORT //
959 if (strlen(pAd->CommonCfg.CountryCode) != 0)
961 pAd->CommonCfg.bCountryFlag = TRUE;
963 DBGPRINT(RT_DEBUG_TRACE, ("CountryCode=%s\n", pAd->CommonCfg.CountryCode));
966 if(RTMPGetKeyParameter("ChannelGeography", tmpbuf, 25, buffer))
968 UCHAR Geography = (UCHAR) simple_strtol(tmpbuf, 0, 10);
969 if (Geography <= BOTH)
971 pAd->CommonCfg.Geography = Geography;
972 pAd->CommonCfg.CountryCode[2] =
973 (pAd->CommonCfg.Geography == BOTH) ? ' ' : ((pAd->CommonCfg.Geography == IDOR) ? 'I' : 'O');
974 #ifdef CONFIG_STA_SUPPORT
975 #ifdef EXT_BUILD_CHANNEL_LIST
976 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
977 pAd->StaCfg.StaOriGeography = pAd->CommonCfg.Geography;
978 #endif // EXT_BUILD_CHANNEL_LIST //
979 #endif // CONFIG_STA_SUPPORT //
980 DBGPRINT(RT_DEBUG_TRACE, ("ChannelGeography=%d\n", pAd->CommonCfg.Geography));
985 pAd->CommonCfg.Geography = BOTH;
986 pAd->CommonCfg.CountryCode[2] = ' ';
990 #ifdef CONFIG_STA_SUPPORT
991 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
994 if (RTMPGetCriticalParameter("SSID", tmpbuf, 256, buffer))
996 if (strlen(tmpbuf) <= 32)
998 pAd->CommonCfg.SsidLen = (UCHAR) strlen(tmpbuf);
999 NdisZeroMemory(pAd->CommonCfg.Ssid, NDIS_802_11_LENGTH_SSID);
1000 NdisMoveMemory(pAd->CommonCfg.Ssid, tmpbuf, pAd->CommonCfg.SsidLen);
1001 pAd->MlmeAux.AutoReconnectSsidLen = pAd->CommonCfg.SsidLen;
1002 NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, NDIS_802_11_LENGTH_SSID);
1003 NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid, tmpbuf, pAd->MlmeAux.AutoReconnectSsidLen);
1004 pAd->MlmeAux.SsidLen = pAd->CommonCfg.SsidLen;
1005 NdisZeroMemory(pAd->MlmeAux.Ssid, NDIS_802_11_LENGTH_SSID);
1006 NdisMoveMemory(pAd->MlmeAux.Ssid, tmpbuf, pAd->MlmeAux.SsidLen);
1007 DBGPRINT(RT_DEBUG_TRACE, ("%s::(SSID=%s)\n", __func__, tmpbuf));
1011 #endif // CONFIG_STA_SUPPORT //
1013 #ifdef CONFIG_STA_SUPPORT
1014 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1017 if (RTMPGetKeyParameter("NetworkType", tmpbuf, 25, buffer))
1019 pAd->bConfigChanged = TRUE;
1020 if (strcmp(tmpbuf, "Adhoc") == 0)
1021 pAd->StaCfg.BssType = BSS_ADHOC;
1022 else //Default Infrastructure mode
1023 pAd->StaCfg.BssType = BSS_INFRA;
1024 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
1025 pAd->StaCfg.WpaState = SS_NOTUSE;
1026 DBGPRINT(RT_DEBUG_TRACE, ("%s::(NetworkType=%d)\n", __func__, pAd->StaCfg.BssType));
1029 #endif // CONFIG_STA_SUPPORT //
1031 if(RTMPGetKeyParameter("Channel", tmpbuf, 10, buffer))
1033 pAd->CommonCfg.Channel = (UCHAR) simple_strtol(tmpbuf, 0, 10);
1034 DBGPRINT(RT_DEBUG_TRACE, ("Channel=%d\n", pAd->CommonCfg.Channel));
1037 if(RTMPGetKeyParameter("WirelessMode", tmpbuf, 10, buffer))
1039 int value = 0, maxPhyMode = PHY_11G;
1041 #ifdef DOT11_N_SUPPORT
1042 maxPhyMode = PHY_11N_5G;
1043 #endif // DOT11_N_SUPPORT //
1045 value = simple_strtol(tmpbuf, 0, 10);
1047 if (value <= maxPhyMode)
1049 pAd->CommonCfg.PhyMode = value;
1051 DBGPRINT(RT_DEBUG_TRACE, ("PhyMode=%d\n", pAd->CommonCfg.PhyMode));
1054 if(RTMPGetKeyParameter("BasicRate", tmpbuf, 10, buffer))
1056 pAd->CommonCfg.BasicRateBitmap = (ULONG) simple_strtol(tmpbuf, 0, 10);
1057 DBGPRINT(RT_DEBUG_TRACE, ("BasicRate=%ld\n", pAd->CommonCfg.BasicRateBitmap));
1060 if(RTMPGetKeyParameter("BeaconPeriod", tmpbuf, 10, buffer))
1062 pAd->CommonCfg.BeaconPeriod = (USHORT) simple_strtol(tmpbuf, 0, 10);
1063 DBGPRINT(RT_DEBUG_TRACE, ("BeaconPeriod=%d\n", pAd->CommonCfg.BeaconPeriod));
1066 if(RTMPGetKeyParameter("TxPower", tmpbuf, 10, buffer))
1068 pAd->CommonCfg.TxPowerPercentage = (ULONG) simple_strtol(tmpbuf, 0, 10);
1069 #ifdef CONFIG_STA_SUPPORT
1070 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1071 pAd->CommonCfg.TxPowerDefault = pAd->CommonCfg.TxPowerPercentage;
1072 #endif // CONFIG_STA_SUPPORT //
1073 DBGPRINT(RT_DEBUG_TRACE, ("TxPower=%ld\n", pAd->CommonCfg.TxPowerPercentage));
1076 if(RTMPGetKeyParameter("BGProtection", tmpbuf, 10, buffer))
1078 switch (simple_strtol(tmpbuf, 0, 10))
1081 pAd->CommonCfg.UseBGProtection = 1;
1083 case 2: //Always OFF
1084 pAd->CommonCfg.UseBGProtection = 2;
1088 pAd->CommonCfg.UseBGProtection = 0;
1091 DBGPRINT(RT_DEBUG_TRACE, ("BGProtection=%ld\n", pAd->CommonCfg.UseBGProtection));
1094 if(RTMPGetKeyParameter("DisableOLBC", tmpbuf, 10, buffer))
1096 switch (simple_strtol(tmpbuf, 0, 10))
1098 case 1: //disable OLBC Detection
1099 pAd->CommonCfg.DisableOLBCDetect = 1;
1101 case 0: //enable OLBC Detection
1102 pAd->CommonCfg.DisableOLBCDetect = 0;
1105 pAd->CommonCfg.DisableOLBCDetect= 0;
1108 DBGPRINT(RT_DEBUG_TRACE, ("OLBCDetection=%ld\n", pAd->CommonCfg.DisableOLBCDetect));
1111 if(RTMPGetKeyParameter("TxPreamble", tmpbuf, 10, buffer))
1113 switch (simple_strtol(tmpbuf, 0, 10))
1115 case Rt802_11PreambleShort:
1116 pAd->CommonCfg.TxPreamble = Rt802_11PreambleShort;
1118 case Rt802_11PreambleLong:
1120 pAd->CommonCfg.TxPreamble = Rt802_11PreambleLong;
1123 DBGPRINT(RT_DEBUG_TRACE, ("TxPreamble=%ld\n", pAd->CommonCfg.TxPreamble));
1126 if(RTMPGetKeyParameter("RTSThreshold", tmpbuf, 10, buffer))
1128 RtsThresh = simple_strtol(tmpbuf, 0, 10);
1129 if( (RtsThresh >= 1) && (RtsThresh <= MAX_RTS_THRESHOLD) )
1130 pAd->CommonCfg.RtsThreshold = (USHORT)RtsThresh;
1132 pAd->CommonCfg.RtsThreshold = MAX_RTS_THRESHOLD;
1134 DBGPRINT(RT_DEBUG_TRACE, ("RTSThreshold=%d\n", pAd->CommonCfg.RtsThreshold));
1137 if(RTMPGetKeyParameter("FragThreshold", tmpbuf, 10, buffer))
1139 FragThresh = simple_strtol(tmpbuf, 0, 10);
1140 pAd->CommonCfg.bUseZeroToDisableFragment = FALSE;
1142 if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
1143 { //illegal FragThresh so we set it to default
1144 pAd->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
1145 pAd->CommonCfg.bUseZeroToDisableFragment = TRUE;
1147 else if (FragThresh % 2 == 1)
1149 // The length of each fragment shall always be an even number of octets, except for the last fragment
1150 // of an MSDU or MMPDU, which may be either an even or an odd number of octets.
1151 pAd->CommonCfg.FragmentThreshold = (USHORT)(FragThresh - 1);
1155 pAd->CommonCfg.FragmentThreshold = (USHORT)FragThresh;
1157 //pAd->CommonCfg.AllowFragSize = (pAd->CommonCfg.FragmentThreshold) - LENGTH_802_11 - LENGTH_CRC;
1158 DBGPRINT(RT_DEBUG_TRACE, ("FragThreshold=%d\n", pAd->CommonCfg.FragmentThreshold));
1161 if(RTMPGetKeyParameter("TxBurst", tmpbuf, 10, buffer))
1164 // pAd->CommonCfg.bEnableTxBurst = FALSE;
1166 if(simple_strtol(tmpbuf, 0, 10) != 0) //Enable
1167 pAd->CommonCfg.bEnableTxBurst = TRUE;
1169 pAd->CommonCfg.bEnableTxBurst = FALSE;
1171 DBGPRINT(RT_DEBUG_TRACE, ("TxBurst=%d\n", pAd->CommonCfg.bEnableTxBurst));
1174 #ifdef AGGREGATION_SUPPORT
1176 if(RTMPGetKeyParameter("PktAggregate", tmpbuf, 10, buffer))
1178 if(simple_strtol(tmpbuf, 0, 10) != 0) //Enable
1179 pAd->CommonCfg.bAggregationCapable = TRUE;
1181 pAd->CommonCfg.bAggregationCapable = FALSE;
1182 #ifdef PIGGYBACK_SUPPORT
1183 pAd->CommonCfg.bPiggyBackCapable = pAd->CommonCfg.bAggregationCapable;
1184 #endif // PIGGYBACK_SUPPORT //
1185 DBGPRINT(RT_DEBUG_TRACE, ("PktAggregate=%d\n", pAd->CommonCfg.bAggregationCapable));
1188 pAd->CommonCfg.bAggregationCapable = FALSE;
1189 pAd->CommonCfg.bPiggyBackCapable = FALSE;
1190 #endif // AGGREGATION_SUPPORT //
1194 #ifdef CONFIG_STA_SUPPORT
1195 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1196 rtmp_read_sta_wmm_parms_from_file(pAd, tmpbuf, buffer);
1197 #endif // CONFIG_STA_SUPPORT //
1200 if(RTMPGetKeyParameter("ShortSlot", tmpbuf, 10, buffer))
1202 if(simple_strtol(tmpbuf, 0, 10) != 0) //Enable
1203 pAd->CommonCfg.bUseShortSlotTime = TRUE;
1205 pAd->CommonCfg.bUseShortSlotTime = FALSE;
1207 DBGPRINT(RT_DEBUG_TRACE, ("ShortSlot=%d\n", pAd->CommonCfg.bUseShortSlotTime));
1210 if(RTMPGetKeyParameter("IEEE80211H", tmpbuf, 10, buffer))
1212 for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++)
1214 if(simple_strtol(macptr, 0, 10) != 0) //Enable
1215 pAd->CommonCfg.bIEEE80211H = TRUE;
1217 pAd->CommonCfg.bIEEE80211H = FALSE;
1219 DBGPRINT(RT_DEBUG_TRACE, ("IEEE80211H=%d\n", pAd->CommonCfg.bIEEE80211H));
1223 if(RTMPGetKeyParameter("CSPeriod", tmpbuf, 10, buffer))
1225 if(simple_strtol(tmpbuf, 0, 10) != 0)
1226 pAd->CommonCfg.RadarDetect.CSPeriod = simple_strtol(tmpbuf, 0, 10);
1228 pAd->CommonCfg.RadarDetect.CSPeriod = 0;
1230 DBGPRINT(RT_DEBUG_TRACE, ("CSPeriod=%d\n", pAd->CommonCfg.RadarDetect.CSPeriod));
1234 if(RTMPGetKeyParameter("RDRegion", tmpbuf, 128, buffer))
1236 if ((strncmp(tmpbuf, "JAP_W53", 7) == 0) || (strncmp(tmpbuf, "jap_w53", 7) == 0))
1238 pAd->CommonCfg.RadarDetect.RDDurRegion = JAP_W53;
1239 pAd->CommonCfg.RadarDetect.DfsSessionTime = 15;
1241 else if ((strncmp(tmpbuf, "JAP_W56", 7) == 0) || (strncmp(tmpbuf, "jap_w56", 7) == 0))
1243 pAd->CommonCfg.RadarDetect.RDDurRegion = JAP_W56;
1244 pAd->CommonCfg.RadarDetect.DfsSessionTime = 13;
1246 else if ((strncmp(tmpbuf, "JAP", 3) == 0) || (strncmp(tmpbuf, "jap", 3) == 0))
1248 pAd->CommonCfg.RadarDetect.RDDurRegion = JAP;
1249 pAd->CommonCfg.RadarDetect.DfsSessionTime = 5;
1251 else if ((strncmp(tmpbuf, "FCC", 3) == 0) || (strncmp(tmpbuf, "fcc", 3) == 0))
1253 pAd->CommonCfg.RadarDetect.RDDurRegion = FCC;
1254 pAd->CommonCfg.RadarDetect.DfsSessionTime = 5;
1256 else if ((strncmp(tmpbuf, "CE", 2) == 0) || (strncmp(tmpbuf, "ce", 2) == 0))
1258 pAd->CommonCfg.RadarDetect.RDDurRegion = CE;
1259 pAd->CommonCfg.RadarDetect.DfsSessionTime = 13;
1263 pAd->CommonCfg.RadarDetect.RDDurRegion = CE;
1264 pAd->CommonCfg.RadarDetect.DfsSessionTime = 13;
1267 DBGPRINT(RT_DEBUG_TRACE, ("RDRegion=%d\n", pAd->CommonCfg.RadarDetect.RDDurRegion));
1271 pAd->CommonCfg.RadarDetect.RDDurRegion = CE;
1272 pAd->CommonCfg.RadarDetect.DfsSessionTime = 13;
1276 if(RTMPGetKeyParameter("WirelessEvent", tmpbuf, 10, buffer))
1278 #if WIRELESS_EXT >= 15
1279 if(simple_strtol(tmpbuf, 0, 10) != 0)
1280 pAd->CommonCfg.bWirelessEvent = simple_strtol(tmpbuf, 0, 10);
1282 pAd->CommonCfg.bWirelessEvent = 0; // disable
1284 pAd->CommonCfg.bWirelessEvent = 0; // disable
1286 DBGPRINT(RT_DEBUG_TRACE, ("WirelessEvent=%d\n", pAd->CommonCfg.bWirelessEvent));
1288 if(RTMPGetKeyParameter("WiFiTest", tmpbuf, 10, buffer))
1290 if(simple_strtol(tmpbuf, 0, 10) != 0)
1291 pAd->CommonCfg.bWiFiTest= simple_strtol(tmpbuf, 0, 10);
1293 pAd->CommonCfg.bWiFiTest = 0; // disable
1295 DBGPRINT(RT_DEBUG_TRACE, ("WiFiTest=%d\n", pAd->CommonCfg.bWiFiTest));
1298 if(RTMPGetKeyParameter("AuthMode", tmpbuf, 128, buffer))
1300 #ifdef CONFIG_STA_SUPPORT
1301 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1303 if ((strcmp(tmpbuf, "WEPAUTO") == 0) || (strcmp(tmpbuf, "wepauto") == 0))
1304 pAd->StaCfg.AuthMode = Ndis802_11AuthModeAutoSwitch;
1305 else if ((strcmp(tmpbuf, "SHARED") == 0) || (strcmp(tmpbuf, "shared") == 0))
1306 pAd->StaCfg.AuthMode = Ndis802_11AuthModeShared;
1307 else if ((strcmp(tmpbuf, "WPAPSK") == 0) || (strcmp(tmpbuf, "wpapsk") == 0))
1308 pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
1309 else if ((strcmp(tmpbuf, "WPANONE") == 0) || (strcmp(tmpbuf, "wpanone") == 0))
1310 pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
1311 else if ((strcmp(tmpbuf, "WPA2PSK") == 0) || (strcmp(tmpbuf, "wpa2psk") == 0))
1312 pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
1313 #ifdef WPA_SUPPLICANT_SUPPORT
1314 else if ((strcmp(tmpbuf, "WPA") == 0) || (strcmp(tmpbuf, "wpa") == 0))
1315 pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
1316 else if ((strcmp(tmpbuf, "WPA2") == 0) || (strcmp(tmpbuf, "wpa2") == 0))
1317 pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
1318 #endif // WPA_SUPPLICANT_SUPPORT //
1320 pAd->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1322 pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
1324 DBGPRINT(RT_DEBUG_TRACE, ("%s::(EncrypType=%d)\n", __func__, pAd->StaCfg.WepStatus));
1326 #endif // CONFIG_STA_SUPPORT //
1329 if(RTMPGetKeyParameter("EncrypType", tmpbuf, 128, buffer))
1332 #ifdef CONFIG_STA_SUPPORT
1333 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1335 if ((strcmp(tmpbuf, "WEP") == 0) || (strcmp(tmpbuf, "wep") == 0))
1336 pAd->StaCfg.WepStatus = Ndis802_11WEPEnabled;
1337 else if ((strcmp(tmpbuf, "TKIP") == 0) || (strcmp(tmpbuf, "tkip") == 0))
1338 pAd->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
1339 else if ((strcmp(tmpbuf, "AES") == 0) || (strcmp(tmpbuf, "aes") == 0))
1340 pAd->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
1342 pAd->StaCfg.WepStatus = Ndis802_11WEPDisabled;
1344 // Update all wepstatus related
1345 pAd->StaCfg.PairCipher = pAd->StaCfg.WepStatus;
1346 pAd->StaCfg.GroupCipher = pAd->StaCfg.WepStatus;
1347 pAd->StaCfg.OrigWepStatus = pAd->StaCfg.WepStatus;
1348 pAd->StaCfg.bMixCipher = FALSE;
1350 //RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, 0);
1351 DBGPRINT(RT_DEBUG_TRACE, ("%s::(EncrypType=%d)\n", __func__, pAd->StaCfg.WepStatus));
1353 #endif // CONFIG_STA_SUPPORT //
1358 #ifdef CONFIG_STA_SUPPORT
1359 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1361 if(RTMPGetCriticalParameter("WPAPSK", tmpbuf, 512, buffer))
1365 tmpbuf[strlen(tmpbuf)] = '\0'; // make STA can process .$^& for WPAPSK input
1367 if ((pAd->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
1368 (pAd->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
1369 (pAd->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
1374 else if ((strlen(tmpbuf) >= 8) && (strlen(tmpbuf) < 64))
1376 PasswordHash((char *)tmpbuf, pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen, keyMaterial);
1377 NdisMoveMemory(pAd->StaCfg.PMK, keyMaterial, 32);
1380 else if (strlen(tmpbuf) == 64)
1382 AtoH(tmpbuf, keyMaterial, 32);
1383 NdisMoveMemory(pAd->StaCfg.PMK, keyMaterial, 32);
1388 DBGPRINT(RT_DEBUG_ERROR, ("%s::(WPAPSK key-string required 8 ~ 64 characters!)\n", __func__));
1393 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
1394 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
1396 // Start STA supplicant state machine
1397 pAd->StaCfg.WpaState = SS_START;
1399 else if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
1402 NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));
1403 pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
1404 NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, pAd->StaCfg.PMK, LEN_TKIP_EK);
1405 NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, &pAd->StaCfg.PMK[16], LEN_TKIP_RXMICK);
1406 NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, &pAd->StaCfg.PMK[16], LEN_TKIP_TXMICK);
1408 // Decide its ChiperAlg
1409 if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
1410 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
1411 else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)
1412 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
1414 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_NONE;
1416 pAd->StaCfg.WpaState = SS_NOTUSE;
1419 DBGPRINT(RT_DEBUG_TRACE, ("%s::(WPAPSK=%s)\n", __func__, tmpbuf));
1423 #endif // CONFIG_STA_SUPPORT //
1425 //DefaultKeyID, KeyType, KeyStr
1426 rtmp_read_key_parms_from_file(pAd, tmpbuf, buffer);
1430 /*if(RTMPGetKeyParameter("HSCounter", tmpbuf, 10, buffer))
1432 switch (simple_strtol(tmpbuf, 0, 10))
1435 pAd->CommonCfg.bEnableHSCounter = TRUE;
1439 pAd->CommonCfg.bEnableHSCounter = FALSE;
1442 DBGPRINT(RT_DEBUG_TRACE, "HSCounter=%d\n", pAd->CommonCfg.bEnableHSCounter);
1445 #ifdef DOT11_N_SUPPORT
1446 HTParametersHook(pAd, tmpbuf, buffer);
1447 #endif // DOT11_N_SUPPORT //
1449 #ifdef CONFIG_STA_SUPPORT
1450 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1453 if (RTMPGetKeyParameter("PSMode", tmpbuf, 10, buffer))
1455 if (pAd->StaCfg.BssType == BSS_INFRA)
1457 if ((strcmp(tmpbuf, "MAX_PSP") == 0) || (strcmp(tmpbuf, "max_psp") == 0))
1459 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
1460 // to exclude certain situations.
1461 // MlmeSetPsm(pAd, PWR_SAVE);
1462 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
1463 if (pAd->StaCfg.bWindowsACCAMEnable == FALSE)
1464 pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeMAX_PSP;
1465 pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeMAX_PSP;
1466 pAd->StaCfg.DefaultListenCount = 5;
1468 else if ((strcmp(tmpbuf, "Fast_PSP") == 0) || (strcmp(tmpbuf, "fast_psp") == 0)
1469 || (strcmp(tmpbuf, "FAST_PSP") == 0))
1471 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
1472 // to exclude certain situations.
1473 // MlmeSetPsmBit(pAd, PWR_SAVE);
1474 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
1475 if (pAd->StaCfg.bWindowsACCAMEnable == FALSE)
1476 pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeFast_PSP;
1477 pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeFast_PSP;
1478 pAd->StaCfg.DefaultListenCount = 3;
1480 else if ((strcmp(tmpbuf, "Legacy_PSP") == 0) || (strcmp(tmpbuf, "legacy_psp") == 0)
1481 || (strcmp(tmpbuf, "LEGACY_PSP") == 0))
1483 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
1484 // to exclude certain situations.
1485 // MlmeSetPsmBit(pAd, PWR_SAVE);
1486 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
1487 if (pAd->StaCfg.bWindowsACCAMEnable == FALSE)
1488 pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeLegacy_PSP;
1489 pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeLegacy_PSP;
1490 pAd->StaCfg.DefaultListenCount = 3;
1493 { //Default Ndis802_11PowerModeCAM
1494 // clear PSM bit immediately
1495 MlmeSetPsmBit(pAd, PWR_ACTIVE);
1496 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
1497 if (pAd->StaCfg.bWindowsACCAMEnable == FALSE)
1498 pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
1499 pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
1501 DBGPRINT(RT_DEBUG_TRACE, ("PSMode=%ld\n", pAd->StaCfg.WindowsPowerMode));
1505 if (RTMPGetKeyParameter("FastRoaming", tmpbuf, 32, buffer))
1507 if (simple_strtol(tmpbuf, 0, 10) == 0)
1508 pAd->StaCfg.bFastRoaming = FALSE;
1510 pAd->StaCfg.bFastRoaming = TRUE;
1512 DBGPRINT(RT_DEBUG_TRACE, ("FastRoaming=%d\n", pAd->StaCfg.bFastRoaming));
1515 if (RTMPGetKeyParameter("RoamThreshold", tmpbuf, 32, buffer))
1517 long lInfo = simple_strtol(tmpbuf, 0, 10);
1519 if (lInfo > 90 || lInfo < 60)
1520 pAd->StaCfg.dBmToRoam = -70;
1522 pAd->StaCfg.dBmToRoam = (CHAR)(-1)*lInfo;
1524 DBGPRINT(RT_DEBUG_TRACE, ("RoamThreshold=%d dBm\n", pAd->StaCfg.dBmToRoam));
1527 if(RTMPGetKeyParameter("TGnWifiTest", tmpbuf, 10, buffer))
1529 if(simple_strtol(tmpbuf, 0, 10) == 0)
1530 pAd->StaCfg.bTGnWifiTest = FALSE;
1532 pAd->StaCfg.bTGnWifiTest = TRUE;
1533 DBGPRINT(RT_DEBUG_TRACE, ("TGnWifiTest=%d\n", pAd->StaCfg.bTGnWifiTest));
1536 #endif // CONFIG_STA_SUPPORT //
1544 DBGPRINT(RT_DEBUG_TRACE, ("--> %s does not have a write method\n", src));
1547 retval=filp_close(srcf,NULL);
1551 DBGPRINT(RT_DEBUG_TRACE, ("--> Error %d closing %s\n", -retval, src));
1558 current->fsuid = orgfsuid;
1559 current->fsgid = orgfsgid;
1565 return (NDIS_STATUS_SUCCESS);
1568 #ifdef DOT11_N_SUPPORT
1569 static void HTParametersHook(
1570 IN PRTMP_ADAPTER pAd,
1577 if (RTMPGetKeyParameter("HT_PROTECT", pValueStr, 25, pInput))
1579 Value = simple_strtol(pValueStr, 0, 10);
1582 pAd->CommonCfg.bHTProtect = FALSE;
1586 pAd->CommonCfg.bHTProtect = TRUE;
1588 DBGPRINT(RT_DEBUG_TRACE, ("HT: Protection = %s\n", (Value==0) ? "Disable" : "Enable"));
1591 if (RTMPGetKeyParameter("HT_MIMOPSEnable", pValueStr, 25, pInput))
1593 Value = simple_strtol(pValueStr, 0, 10);
1596 pAd->CommonCfg.bMIMOPSEnable = FALSE;
1600 pAd->CommonCfg.bMIMOPSEnable = TRUE;
1602 DBGPRINT(RT_DEBUG_TRACE, ("HT: MIMOPSEnable = %s\n", (Value==0) ? "Disable" : "Enable"));
1606 if (RTMPGetKeyParameter("HT_MIMOPSMode", pValueStr, 25, pInput))
1608 Value = simple_strtol(pValueStr, 0, 10);
1609 if (Value > MMPS_ENABLE)
1611 pAd->CommonCfg.BACapability.field.MMPSmode = MMPS_ENABLE;
1615 //TODO: add mimo power saving mechanism
1616 pAd->CommonCfg.BACapability.field.MMPSmode = MMPS_ENABLE;
1617 //pAd->CommonCfg.BACapability.field.MMPSmode = Value;
1619 DBGPRINT(RT_DEBUG_TRACE, ("HT: MIMOPS Mode = %d\n", Value));
1622 if (RTMPGetKeyParameter("HT_BADecline", pValueStr, 25, pInput))
1624 Value = simple_strtol(pValueStr, 0, 10);
1627 pAd->CommonCfg.bBADecline = FALSE;
1631 pAd->CommonCfg.bBADecline = TRUE;
1633 DBGPRINT(RT_DEBUG_TRACE, ("HT: BA Decline = %s\n", (Value==0) ? "Disable" : "Enable"));
1637 if (RTMPGetKeyParameter("HT_DisableReordering", pValueStr, 25, pInput))
1639 Value = simple_strtol(pValueStr, 0, 10);
1642 pAd->CommonCfg.bDisableReordering = FALSE;
1646 pAd->CommonCfg.bDisableReordering = TRUE;
1648 DBGPRINT(RT_DEBUG_TRACE, ("HT: DisableReordering = %s\n", (Value==0) ? "Disable" : "Enable"));
1651 if (RTMPGetKeyParameter("HT_AutoBA", pValueStr, 25, pInput))
1653 Value = simple_strtol(pValueStr, 0, 10);
1656 pAd->CommonCfg.BACapability.field.AutoBA = FALSE;
1660 pAd->CommonCfg.BACapability.field.AutoBA = TRUE;
1662 pAd->CommonCfg.REGBACapability.field.AutoBA = pAd->CommonCfg.BACapability.field.AutoBA;
1663 DBGPRINT(RT_DEBUG_TRACE, ("HT: Auto BA = %s\n", (Value==0) ? "Disable" : "Enable"));
1667 if (RTMPGetKeyParameter("HT_HTC", pValueStr, 25, pInput))
1669 Value = simple_strtol(pValueStr, 0, 10);
1672 pAd->HTCEnable = FALSE;
1676 pAd->HTCEnable = TRUE;
1678 DBGPRINT(RT_DEBUG_TRACE, ("HT: Tx +HTC frame = %s\n", (Value==0) ? "Disable" : "Enable"));
1681 // Enable HT Link Adaptation Control
1682 if (RTMPGetKeyParameter("HT_LinkAdapt", pValueStr, 25, pInput))
1684 Value = simple_strtol(pValueStr, 0, 10);
1687 pAd->bLinkAdapt = FALSE;
1691 pAd->HTCEnable = TRUE;
1692 pAd->bLinkAdapt = TRUE;
1694 DBGPRINT(RT_DEBUG_TRACE, ("HT: Link Adaptation Control = %s\n", (Value==0) ? "Disable" : "Enable(+HTC)"));
1697 // Reverse Direction Mechanism
1698 if (RTMPGetKeyParameter("HT_RDG", pValueStr, 25, pInput))
1700 Value = simple_strtol(pValueStr, 0, 10);
1703 pAd->CommonCfg.bRdg = FALSE;
1707 pAd->HTCEnable = TRUE;
1708 pAd->CommonCfg.bRdg = TRUE;
1710 DBGPRINT(RT_DEBUG_TRACE, ("HT: RDG = %s\n", (Value==0) ? "Disable" : "Enable(+HTC)"));
1717 if (RTMPGetKeyParameter("HT_AMSDU", pValueStr, 25, pInput))
1719 Value = simple_strtol(pValueStr, 0, 10);
1722 pAd->CommonCfg.BACapability.field.AmsduEnable = FALSE;
1726 pAd->CommonCfg.BACapability.field.AmsduEnable = TRUE;
1728 DBGPRINT(RT_DEBUG_TRACE, ("HT: Tx A-MSDU = %s\n", (Value==0) ? "Disable" : "Enable"));
1732 if (RTMPGetKeyParameter("HT_MpduDensity", pValueStr, 25, pInput))
1734 Value = simple_strtol(pValueStr, 0, 10);
1735 if (Value <=7 && Value >= 0)
1737 pAd->CommonCfg.BACapability.field.MpduDensity = Value;
1738 DBGPRINT(RT_DEBUG_TRACE, ("HT: MPDU Density = %d\n", Value));
1742 pAd->CommonCfg.BACapability.field.MpduDensity = 4;
1743 DBGPRINT(RT_DEBUG_TRACE, ("HT: MPDU Density = %d (Default)\n", 4));
1747 // Max Rx BA Window Size
1748 if (RTMPGetKeyParameter("HT_BAWinSize", pValueStr, 25, pInput))
1750 Value = simple_strtol(pValueStr, 0, 10);
1752 if (Value >=1 && Value <= 64)
1754 pAd->CommonCfg.REGBACapability.field.RxBAWinLimit = Value;
1755 pAd->CommonCfg.BACapability.field.RxBAWinLimit = Value;
1756 DBGPRINT(RT_DEBUG_TRACE, ("HT: BA Windw Size = %d\n", Value));
1760 pAd->CommonCfg.REGBACapability.field.RxBAWinLimit = 64;
1761 pAd->CommonCfg.BACapability.field.RxBAWinLimit = 64;
1762 DBGPRINT(RT_DEBUG_TRACE, ("HT: BA Windw Size = 64 (Defualt)\n"));
1768 if (RTMPGetKeyParameter("HT_GI", pValueStr, 25, pInput))
1770 Value = simple_strtol(pValueStr, 0, 10);
1772 if (Value == GI_400)
1774 pAd->CommonCfg.RegTransmitSetting.field.ShortGI = GI_400;
1778 pAd->CommonCfg.RegTransmitSetting.field.ShortGI = GI_800;
1781 DBGPRINT(RT_DEBUG_TRACE, ("HT: Guard Interval = %s\n", (Value==GI_400) ? "400" : "800" ));
1784 // HT Operation Mode : Mixed Mode , Green Field
1785 if (RTMPGetKeyParameter("HT_OpMode", pValueStr, 25, pInput))
1787 Value = simple_strtol(pValueStr, 0, 10);
1789 if (Value == HTMODE_GF)
1792 pAd->CommonCfg.RegTransmitSetting.field.HTMODE = HTMODE_GF;
1796 pAd->CommonCfg.RegTransmitSetting.field.HTMODE = HTMODE_MM;
1799 DBGPRINT(RT_DEBUG_TRACE, ("HT: Operate Mode = %s\n", (Value==HTMODE_GF) ? "Green Field" : "Mixed Mode" ));
1802 // Fixed Tx mode : CCK, OFDM
1803 if (RTMPGetKeyParameter("FixedTxMode", pValueStr, 25, pInput))
1807 #ifdef CONFIG_STA_SUPPORT
1808 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1810 fix_tx_mode = FIXED_TXMODE_HT;
1812 if (strcmp(pValueStr, "OFDM") == 0 || strcmp(pValueStr, "ofdm") == 0)
1814 fix_tx_mode = FIXED_TXMODE_OFDM;
1816 else if (strcmp(pValueStr, "CCK") == 0 || strcmp(pValueStr, "cck") == 0)
1818 fix_tx_mode = FIXED_TXMODE_CCK;
1820 else if (strcmp(pValueStr, "HT") == 0 || strcmp(pValueStr, "ht") == 0)
1822 fix_tx_mode = FIXED_TXMODE_HT;
1826 Value = simple_strtol(pValueStr, 0, 10);
1830 if (Value == FIXED_TXMODE_CCK || Value == FIXED_TXMODE_OFDM)
1831 fix_tx_mode = Value;
1833 fix_tx_mode = FIXED_TXMODE_HT;
1836 pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode = fix_tx_mode;
1837 DBGPRINT(RT_DEBUG_TRACE, ("Fixed Tx Mode = %d\n", fix_tx_mode));
1840 #endif // CONFIG_STA_SUPPORT //
1845 if (RTMPGetKeyParameter("HT_BW", pValueStr, 25, pInput))
1847 Value = simple_strtol(pValueStr, 0, 10);
1851 pAd->CommonCfg.RegTransmitSetting.field.BW = BW_40;
1855 pAd->CommonCfg.RegTransmitSetting.field.BW = BW_20;
1858 #ifdef MCAST_RATE_SPECIFIC
1859 pAd->CommonCfg.MCastPhyMode.field.BW = pAd->CommonCfg.RegTransmitSetting.field.BW;
1860 #endif // MCAST_RATE_SPECIFIC //
1862 DBGPRINT(RT_DEBUG_TRACE, ("HT: Channel Width = %s\n", (Value==BW_40) ? "40 MHz" : "20 MHz" ));
1865 if (RTMPGetKeyParameter("HT_EXTCHA", pValueStr, 25, pInput))
1867 Value = simple_strtol(pValueStr, 0, 10);
1872 pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_BELOW;
1876 pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_ABOVE;
1879 DBGPRINT(RT_DEBUG_TRACE, ("HT: Ext Channel = %s\n", (Value==0) ? "BELOW" : "ABOVE" ));
1883 if (RTMPGetKeyParameter("HT_MCS", pValueStr, 50, pInput))
1886 #ifdef CONFIG_STA_SUPPORT
1887 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1889 Value = simple_strtol(pValueStr, 0, 10);
1891 // if ((Value >= 0 && Value <= 15) || (Value == 32))
1892 if ((Value >= 0 && Value <= 23) || (Value == 32)) // 3*3
1894 pAd->StaCfg.DesiredTransmitSetting.field.MCS = Value;
1895 pAd->StaCfg.bAutoTxRateSwitch = FALSE;
1896 DBGPRINT(RT_DEBUG_TRACE, ("HT: MCS = %d\n", pAd->StaCfg.DesiredTransmitSetting.field.MCS));
1900 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
1901 pAd->StaCfg.bAutoTxRateSwitch = TRUE;
1902 DBGPRINT(RT_DEBUG_TRACE, ("HT: MCS = AUTO\n"));
1905 #endif // CONFIG_STA_SUPPORT //
1909 if (RTMPGetKeyParameter("HT_STBC", pValueStr, 25, pInput))
1911 Value = simple_strtol(pValueStr, 0, 10);
1912 if (Value == STBC_USE)
1914 pAd->CommonCfg.RegTransmitSetting.field.STBC = STBC_USE;
1918 pAd->CommonCfg.RegTransmitSetting.field.STBC = STBC_NONE;
1920 DBGPRINT(RT_DEBUG_TRACE, ("HT: STBC = %d\n", pAd->CommonCfg.RegTransmitSetting.field.STBC));
1923 // 40_Mhz_Intolerant
1924 if (RTMPGetKeyParameter("HT_40MHZ_INTOLERANT", pValueStr, 25, pInput))
1926 Value = simple_strtol(pValueStr, 0, 10);
1929 pAd->CommonCfg.bForty_Mhz_Intolerant = FALSE;
1933 pAd->CommonCfg.bForty_Mhz_Intolerant = TRUE;
1935 DBGPRINT(RT_DEBUG_TRACE, ("HT: 40MHZ INTOLERANT = %d\n", pAd->CommonCfg.bForty_Mhz_Intolerant));
1938 if(RTMPGetKeyParameter("HT_TxStream", pValueStr, 10, pInput))
1940 switch (simple_strtol(pValueStr, 0, 10))
1943 pAd->CommonCfg.TxStream = 1;
1946 pAd->CommonCfg.TxStream = 2;
1950 pAd->CommonCfg.TxStream = 3;
1952 if (pAd->MACVersion < RALINK_2883_VERSION)
1953 pAd->CommonCfg.TxStream = 2; // only 2 tx streams for RT2860 series
1956 DBGPRINT(RT_DEBUG_TRACE, ("HT: Tx Stream = %d\n", pAd->CommonCfg.TxStream));
1959 if(RTMPGetKeyParameter("HT_RxStream", pValueStr, 10, pInput))
1961 switch (simple_strtol(pValueStr, 0, 10))
1964 pAd->CommonCfg.RxStream = 1;
1967 pAd->CommonCfg.RxStream = 2;
1971 pAd->CommonCfg.RxStream = 3;
1973 if (pAd->MACVersion < RALINK_2883_VERSION)
1974 pAd->CommonCfg.RxStream = 2; // only 2 rx streams for RT2860 series
1977 DBGPRINT(RT_DEBUG_TRACE, ("HT: Rx Stream = %d\n", pAd->CommonCfg.RxStream));
1981 #endif // DOT11_N_SUPPORT //