⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmm_profile.c

📁 ralink 2870 usb无线网卡 最新驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
/* ************************************************************************* * 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"#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(PSTRING s1, PSTRING s2){	int i = 0;	PSTRING 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, (PUCHAR)&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(PSTRING s1, PSTRING s2){	PSTRING 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.PSTRING rtstrstruncasecmp(PSTRING s1, PSTRING 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  */PSTRING rtstrstr(PSTRING s1,const PSTRING s2){	INT l1, l2;	l2 = strlen(s2);	if (!l2)		return s1;		l1 = strlen(s1);		while (l1 >= l2)	{		l1--;		if (!memcmp(s1,s2,l2))			return 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. */PSTRING __rstrtok;PSTRING rstrtok(PSTRING s,const PSTRING ct){	PSTRING 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(PSTRING s,PSTRING ct){	INT count = 0;	/* point to the beginning of the line */	PSTRING 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(PSTRING cp, unsigned int *addr){	unsigned int 	val;	int         	base, n;	STRING        	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    ========================================================================*/PSTRING RTMPFindSection(    IN  PSTRING   buffer){    STRING temp_buf[32];    PSTRING  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	bTrimSpace	Set true if you want to strip the space character of the result pattern	    Return Value:        TRUE                        Success        FALSE                       Fail    Note:	This routine get the value with the matched key (case case-sensitive)	For SSID and security key related parameters, we SHALL NOT trim the space(' ') character.    ========================================================================*/INT RTMPGetKeyParameter(    IN PSTRING key,    OUT PSTRING dest,    IN INT destsize,    IN PSTRING buffer,    IN BOOLEAN bTrimSpace){	PSTRING pMemBuf, temp_buf1 = NULL, temp_buf2 = NULL;	PSTRING start_ptr, end_ptr;	PSTRING ptr;	PSTRING offset = NULL;	INT  len, keyLen;	keyLen = strlen(key);	os_alloc_mem(NULL, (PUCHAR *)&pMemBuf, MAX_PARAM_BUFFER_SIZE  * 2);	if (pMemBuf == NULL)		return (FALSE);		memset(pMemBuf, 0, MAX_PARAM_BUFFER_SIZE * 2);	temp_buf1 = pMemBuf;	temp_buf2 = (PSTRING)(pMemBuf + MAX_PARAM_BUFFER_SIZE);	//find section	if((offset = RTMPFindSection(buffer)) == NULL)	{		os_free_mem(NULL, (PUCHAR)pMemBuf);		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, (PUCHAR)pMemBuf);		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, (PUCHAR)pMemBuf);		return (FALSE);	}	NdisMoveMemory(temp_buf2, start_ptr, end_ptr-start_ptr);	temp_buf2[end_ptr-start_ptr]='\0';	if((start_ptr=rtstrstr(temp_buf2, "=")) == NULL)	{		os_free_mem(NULL, (PUCHAR)pMemBuf);		return (FALSE);	}	ptr = (start_ptr +1);	//trim special characters, i.e.,  TAB or space	while(*start_ptr != 0x00)	{		if( ((*ptr == ' ') && bTrimSpace) || (*ptr == '\t') )			ptr++;		else			break;	}	len = strlen(start_ptr);	memset(dest, 0x00, destsize);	strncpy(dest, ptr, ((len >= destsize) ? destsize: len));	os_free_mem(NULL, (PUCHAR)pMemBuf);		return TRUE;}/*    ========================================================================    Routine Description:        Get multiple key parameter.    Arguments:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -