rt_profile.c
来自「ralink最新rt3070 usb wifi 无线网卡驱动程序」· C语言 代码 · 共 2,038 行 · 第 1/4 页
C
2,038 行
/* ************************************************************************* * Ralink Tech Inc. * 5F., No.36, Taiyuan St., Jhubei City, * Hsinchu County 302, * 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"#ifdef DOT11_N_SUPPORTstatic void HTParametersHook( IN PRTMP_ADAPTER pAd, IN CHAR *pValueStr, IN CHAR *pInput);#endif // DOT11_N_SUPPORT //#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;}// we assume the s1 (buffer) and s2 (key) both are strings.char * rtstrstruncasecmp(char * s1, char * s2){ INT l1, l2, i; char temp1, temp2; l2 = strlen(s2); if (!l2) return (char *) s1; l1 = strlen(s1); while (l1 >= l2) { l1--; for(i=0; i<l2; i++) { temp1 = *(s1+i); temp2 = *(s2+i); if (('a' <= temp1) && (temp1 <= 'z')) temp1 = 'A'+(temp1-'a'); if (('a' <= temp2) && (temp2 <= 'z')) temp2 = 'A'+(temp2-'a'); if (temp1 != temp2) break; } if (i == l2) return (char *) s1; s1++; } return NULL; // not found}//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. */ /* accumulate delimiter count */ ++count; } return count;}/* * converts the Internet host address from the standard numbers-and-dots notation * into binary data. * returns nonzero if the address is valid, zero if not. */int rtinet_aton(const char *cp, unsigned int *addr){ unsigned int val; int base, n; char c; unsigned int parts[4]; unsigned int *pp = parts; for (;;) { /* * Collect number up to ``.''. * Values are specified as for C: * 0x=hex, 0=octal, other=decimal. */ val = 0; base = 10; if (*cp == '0') { if (*++cp == 'x' || *cp == 'X') base = 16, cp++; else base = 8; } while ((c = *cp) != '\0') { if (isdigit((unsigned char) c)) { val = (val * base) + (c - '0'); cp++; continue; } if (base == 16 && isxdigit((unsigned char) c)) { val = (val << 4) + (c + 10 - (islower((unsigned char) c) ? 'a' : 'A')); cp++; continue; } break; } if (*cp == '.') { /* * Internet format: a.b.c.d a.b.c (with c treated as 16-bits) * a.b (with b treated as 24 bits) */ if (pp >= parts + 3 || val > 0xff) return 0; *pp++ = val, cp++; } else break; } /* * Check for trailing junk. */ while (*cp) if (!isspace((unsigned char) *cp++)) return 0; /* * Concoct the address according to the number of parts specified. */ n = pp - parts + 1; switch (n) { case 1: /* a -- 32 bits */ break; case 2: /* a.b -- 8.24 bits */ if (val > 0xffffff) return 0; val |= parts[0] << 24; break; case 3: /* a.b.c -- 8.8.16 bits */ if (val > 0xffff) return 0; val |= (parts[0] << 24) | (parts[1] << 16); break; case 4: /* a.b.c.d -- 8.8.8.8 bits */ if (val > 0xff) return 0; val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); break; } *addr = htonl(val); return 1;}/* ======================================================================== 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;}/* ======================================================================== 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). It is called for parsing SSID and any key string. ========================================================================*/INT RTMPGetCriticalParameter( 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);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?