📄 rt_profile.c
字号:
/* ************************************************************************* * Ralink Tech Inc. * 4F, No. 2 Technology 5th Rd. * Science-based Industrial Park * Hsin-chu, Taiwan, R.O.C. * * (c) Copyright 2002-2007, Ralink Technology, Inc. * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * * ************************************************************************* */#include "rt_config.h"static void HTParametersHook( IN PRTMP_ADAPTER pAd, IN CHAR *pValueStr, IN CHAR *pInput);// add by shiang#define ETH_MAC_ADDR_STR_LEN 17 // in format of xx:xx:xx:xx:xx:xx// We assume the s1 is a sting, s2 is a memory space with 6 bytes. and content of s1 will be changed.BOOLEAN rtstrmactohex(char *s1, char *s2){ int i = 0; char *ptokS = s1, *ptokE = s1; if (strlen(s1) != ETH_MAC_ADDR_STR_LEN) return FALSE; while((*ptokS) != '\0') { if((ptokE = strchr(ptokS, ':')) != NULL) *ptokE++ = '\0'; if ((strlen(ptokS) != 2) || (!isxdigit(*ptokS)) || (!isxdigit(*(ptokS+1)))) break; // fail AtoH(ptokS, &s2[i++], 1); ptokS = ptokE; if (i == 6) break; // parsing finished } return ( i == 6 ? TRUE : FALSE);}// we assume the s1 and s2 both are strings.BOOLEAN rtstrcasecmp(char *s1, char *s2){ char *p1 = s1, *p2 = s2; if (strlen(s1) != strlen(s2)) return FALSE; while(*p1 != '\0') { if((*p1 != *p2) && ((*p1 ^ *p2) != 0x20)) return FALSE; p1++; p2++; } return TRUE;}//add by kathy /** * strstr - Find the first substring in a %NUL terminated string * @s1: The string to be searched * @s2: The string to search for */char * rtstrstr(const char * s1,const char * s2){ INT l1, l2; l2 = strlen(s2); if (!l2) return (char *) s1; l1 = strlen(s1); while (l1 >= l2) { l1--; if (!memcmp(s1,s2,l2)) return (char *) s1; s1++; } return NULL;} /** * rstrtok - Split a string into tokens * @s: The string to be searched * @ct: The characters to search for * * WARNING: strtok is deprecated, use strsep instead. However strsep is not compatible with old architecture. */char * __rstrtok;char * rstrtok(char * s,const char * ct){ char *sbegin, *send; sbegin = s ? s : __rstrtok; if (!sbegin) { return NULL; } sbegin += strspn(sbegin,ct); if (*sbegin == '\0') { __rstrtok = NULL; return( NULL ); } send = strpbrk( sbegin, ct); if (send && *send != '\0') *send++ = '\0'; __rstrtok = send; return (sbegin);}/** * delimitcnt - return the count of a given delimiter in a given string. * @s: The string to be searched. * @ct: The delimiter to search for. * Notice : We suppose the delimiter is a single-char string(for example : ";"). */INT delimitcnt(char * s,const char * ct){ INT count = 0; /* point to the beginning of the line */ const char *token = s; for ( ;; ) { token = strpbrk(token, ct); /* search for delimiters */ if ( token == NULL ) { /* advanced to the terminating null character */ break; } /* skip the delimiter */ ++token; /* * Print the found text: use len with %.*s to specify field width. */ DBGPRINT(RT_DEBUG_INFO, (" -> \"%.*s\"\n", (INT)(token - s), token)); /* accumulate delimiter count */ ++count; } return count;}/* ======================================================================== Routine Description: Find key section for Get key parameter. Arguments: buffer Pointer to the buffer to start find the key section section the key of the secion to be find Return Value: NULL Fail Others Success ========================================================================*/PUCHAR RTMPFindSection( IN PCHAR buffer){ CHAR temp_buf[32]; PUCHAR ptr; strcpy(temp_buf, "Default"); if((ptr = rtstrstr(buffer, temp_buf)) != NULL) return (ptr+strlen("\n")); else return NULL;}/* ======================================================================== Routine Description: Get key parameter. Arguments: key Pointer to key string dest Pointer to destination destsize The datasize of the destination buffer Pointer to the buffer to start find the key Return Value: TRUE Success FALSE Fail Note: This routine get the value with the matched key (case case-sensitive) ========================================================================*/INT RTMPGetKeyParameter( IN PCHAR key, OUT PCHAR dest, IN INT destsize, IN PCHAR buffer){ UCHAR *temp_buf1 = NULL; UCHAR *temp_buf2 = NULL; CHAR *start_ptr; CHAR *end_ptr; CHAR *ptr; CHAR *offset = 0; INT len; //temp_buf1 = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG); os_alloc_mem(NULL, &temp_buf1, MAX_PARAM_BUFFER_SIZE); if(temp_buf1 == NULL) return (FALSE); //temp_buf2 = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG); os_alloc_mem(NULL, &temp_buf2, MAX_PARAM_BUFFER_SIZE); if(temp_buf2 == NULL) { os_free_mem(NULL, temp_buf1); return (FALSE); } //find section if((offset = RTMPFindSection(buffer)) == NULL) { os_free_mem(NULL, temp_buf1); os_free_mem(NULL, temp_buf2); return (FALSE); } strcpy(temp_buf1, "\n"); strcat(temp_buf1, key); strcat(temp_buf1, "="); //search key if((start_ptr=rtstrstr(offset, temp_buf1))==NULL) { os_free_mem(NULL, temp_buf1); os_free_mem(NULL, temp_buf2); return (FALSE); } start_ptr+=strlen("\n"); if((end_ptr=rtstrstr(start_ptr, "\n"))==NULL) end_ptr=start_ptr+strlen(start_ptr); if (end_ptr<start_ptr) { os_free_mem(NULL, temp_buf1); os_free_mem(NULL, temp_buf2); return (FALSE); } NdisMoveMemory(temp_buf2, start_ptr, end_ptr-start_ptr); temp_buf2[end_ptr-start_ptr]='\0'; len = strlen(temp_buf2); strcpy(temp_buf1, temp_buf2); if((start_ptr=rtstrstr(temp_buf1, "=")) == NULL) { os_free_mem(NULL, temp_buf1); os_free_mem(NULL, temp_buf2); return (FALSE); } strcpy(temp_buf2, start_ptr+1); ptr = temp_buf2; //trim space or tab while(*ptr != 0x00) { if( (*ptr == ' ') || (*ptr == '\t') ) ptr++; else break; } len = strlen(ptr); memset(dest, 0x00, destsize); strncpy(dest, ptr, len >= destsize ? destsize: len); os_free_mem(NULL, temp_buf1); os_free_mem(NULL, temp_buf2); return TRUE;}static int rtmp_parse_key_buffer_from_file(IN PRTMP_ADAPTER pAd,IN char *buffer,IN ULONG KeyType,IN INT BSSIdx,IN INT KeyIdx){ PUCHAR keybuff; INT i = BSSIdx, idx = KeyIdx; ULONG KeyLen; UCHAR CipherAlg = CIPHER_WEP64; keybuff = buffer; KeyLen = strlen(keybuff); if (KeyType == 1) {//Ascii if( (KeyLen == 5) || (KeyLen == 13)) { pAd->SharedKey[i][idx].KeyLen = KeyLen; NdisMoveMemory(pAd->SharedKey[i][idx].Key, keybuff, KeyLen); if (KeyLen == 5) CipherAlg = CIPHER_WEP64; else CipherAlg = CIPHER_WEP128; pAd->SharedKey[i][idx].CipherAlg = CipherAlg; DBGPRINT(RT_DEBUG_TRACE, ("I/F(ra%d) Key%dStr=%s and type=%s\n", i, idx+1, keybuff, (KeyType == 0) ? "Hex":"Ascii")); return 1; } else {//Invalid key length DBGPRINT(RT_DEBUG_ERROR, ("Key%dStr is Invalid key length! KeyLen = %ld!\n", idx+1, KeyLen)); return 0; } } else {//Hex type if( (KeyLen == 10) || (KeyLen == 26)) { pAd->SharedKey[i][idx].KeyLen = KeyLen / 2; AtoH(keybuff, pAd->SharedKey[i][idx].Key, KeyLen / 2); if (KeyLen == 10) CipherAlg = CIPHER_WEP64; else CipherAlg = CIPHER_WEP128; pAd->SharedKey[i][idx].CipherAlg = CipherAlg; DBGPRINT(RT_DEBUG_TRACE, ("I/F(ra%d) Key%dStr=%s and type=%s\n", i, idx+1, keybuff, (KeyType == 0) ? "Hex":"Ascii")); return 1; } else {//Invalid key length DBGPRINT(RT_DEBUG_ERROR, ("I/F(ra%d) Key%dStr is Invalid key length! KeyLen = %ld!\n", i, idx+1, KeyLen)); return 0; } }}static void rtmp_read_key_parms_from_file(IN PRTMP_ADAPTER pAd, char *tmpbuf, char *buffer){ char tok_str[16]; PUCHAR macptr; INT i = 0, idx; ULONG KeyType[MAX_MBSSID_NUM]; ULONG KeyIdx; NdisZeroMemory(KeyType, MAX_MBSSID_NUM); //DefaultKeyID if(RTMPGetKeyParameter("DefaultKeyID", tmpbuf, 25, buffer)) {#ifdef CONFIG_STA_SUPPORT KeyIdx = simple_strtol(tmpbuf, 0, 10); if((KeyIdx >= 1 ) && (KeyIdx <= 4)) pAd->StaCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1); else pAd->StaCfg.DefaultKeyId = 0; DBGPRINT(RT_DEBUG_TRACE, ("DefaultKeyID(0~3)=%d\n", pAd->StaCfg.DefaultKeyId));#endif // CONFIG_STA_SUPPORT // } for (idx = 0; idx < 4; idx++) { sprintf(tok_str, "Key%dType", idx + 1); //Key1Type if(RTMPGetKeyParameter(tok_str, tmpbuf, 128, buffer)) { for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++) { KeyType[i] = simple_strtol(macptr, 0, 10); } i = 0; sprintf(tok_str, "Key%dStr", idx + 1); //Key1Str if(RTMPGetKeyParameter(tok_str, tmpbuf, 128, buffer)) { { rtmp_parse_key_buffer_from_file(pAd, tmpbuf, KeyType[BSS0], BSS0, idx); } } } }}#ifdef CONFIG_STA_SUPPORTstatic void rtmp_read_wmm_parms_from_file(IN PRTMP_ADAPTER pAd, char *tmpbuf, char *buffer){ PUCHAR macptr; INT i=0; BOOLEAN bWmmEnable = FALSE; //WmmCapable if(RTMPGetKeyParameter("WmmCapable", tmpbuf, 32, buffer)) { if(simple_strtol(tmpbuf, 0, 10) != 0) //Enable { pAd->CommonCfg.bWmmCapable = TRUE; bWmmEnable = TRUE; } else //Disable { pAd->CommonCfg.bWmmCapable = FALSE; } DBGPRINT(RT_DEBUG_TRACE, ("WmmCapable=%d\n", pAd->CommonCfg.bWmmCapable)); } //AckPolicy for AC_BK, AC_BE, AC_VI, AC_VO if(RTMPGetKeyParameter("AckPolicy", tmpbuf, 32, buffer)) { for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++) { pAd->CommonCfg.AckPolicy[i] = (UCHAR)simple_strtol(macptr, 0, 10); DBGPRINT(RT_DEBUG_TRACE, ("AckPolicy[%d]=%d\n", i, pAd->CommonCfg.AckPolicy[i])); } }}#endif // CONFIG_STA_SUPPORT //NDIS_STATUS RTMPReadParametersHook( IN PRTMP_ADAPTER pAd){ PUCHAR src; struct file *srcf; INT retval, orgfsuid, orgfsgid; mm_segment_t orgfs; CHAR *buffer; CHAR *tmpbuf; ULONG RtsThresh; ULONG FragThresh;#ifdef CONFIG_STA_SUPPORT UCHAR keyMaterial[40];#endif // CONFIG_STA_SUPPORT // PUCHAR macptr; INT i = 0; buffer = kmalloc(MAX_INI_BUFFER_SIZE, MEM_ALLOC_FLAG); if(buffer == NULL)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -