rt_profile.c

来自「ralink最新rt3070 usb wifi 无线网卡驱动程序」· C语言 代码 · 共 2,038 行 · 第 1/4 页

C
2,038
字号
    	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 tab    /* We cannot trim space(' ') for SSID and key string. */    while(*ptr != 0x00)    {        //if( (*ptr == ' ') || (*ptr == '\t') )        if( (*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 multiple 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 RTMPGetKeyParameterWithOffset(    IN  PCHAR   key,    OUT PCHAR   dest,       OUT	USHORT	*end_offset,		    IN  INT     destsize,    IN  PCHAR   buffer,    IN	BOOLEAN	bTrimSpace){    UCHAR *temp_buf1 = NULL;    UCHAR *temp_buf2 = NULL;    CHAR *start_ptr;    CHAR *end_ptr;    CHAR *ptr;    CHAR *offset = 0;    INT  len;	if (*end_offset >= MAX_INI_BUFFER_SIZE)		return (FALSE);		os_alloc_mem(NULL, &temp_buf1, MAX_PARAM_BUFFER_SIZE);	if(temp_buf1 == NULL)        return (FALSE);			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(*end_offset == 0)    {		if ((offset = RTMPFindSection(buffer)) == NULL)		{			os_free_mem(NULL, temp_buf1);	    	os_free_mem(NULL, temp_buf2);    	    return (FALSE);		}    }	else		offset = buffer + (*end_offset);			    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);    }	*end_offset = end_ptr - buffer;    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((bTrimSpace && (*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		IF_DEV_CONFIG_OPMODE_ON_STA(pAd)		{			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);		    }#ifdef CONFIG_STA_SUPPORT			IF_DEV_CONFIG_OPMODE_ON_STA(pAd)			{				sprintf(tok_str, "Key%dStr", idx + 1);				if (RTMPGetCriticalParameter(tok_str, tmpbuf, 128, buffer))				{					rtmp_parse_key_buffer_from_file(pAd, tmpbuf, KeyType[BSS0], BSS0, idx);				}			}#endif // CONFIG_STA_SUPPORT //		}	}}#ifdef CONFIG_STA_SUPPORTstatic void rtmp_read_sta_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));	}#ifdef QOS_DLS_SUPPORT	//DLSCapable	if(RTMPGetKeyParameter("DLSCapable", tmpbuf, 32, buffer))	{		if(simple_strtol(tmpbuf, 0, 10) != 0)  //Enable		{			pAd->CommonCfg.bDLSCapable = TRUE;		}		else //Disable		{			pAd->CommonCfg.bDLSCapable = FALSE;		}		DBGPRINT(RT_DEBUG_TRACE, ("bDLSCapable=%d\n", pAd->CommonCfg.bDLSCapable));	}#endif // QOS_DLS_SUPPORT //	//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]));		}	}	if (bWmmEnable)	{		//APSDCapable		if(RTMPGetKeyParameter("APSDCapable", tmpbuf, 10, buffer))		{			if(simple_strtol(tmpbuf, 0, 10) != 0)  //Enable				pAd->CommonCfg.bAPSDCapable = TRUE;			else				pAd->CommonCfg.bAPSDCapable = FALSE;			DBGPRINT(RT_DEBUG_TRACE, ("APSDCapable=%d\n", pAd->CommonCfg.bAPSDCapable));		}		//APSDAC for AC_BE, AC_BK, AC_VI, AC_VO		if(RTMPGetKeyParameter("APSDAC", tmpbuf, 32, buffer))		{			BOOLEAN apsd_ac[4];									for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++)			{				apsd_ac[i] = (BOOLEAN)simple_strtol(macptr, 0, 10);				DBGPRINT(RT_DEBUG_TRACE, ("APSDAC%d  %d\n", i,  apsd_ac[i]));			}								pAd->CommonCfg.bAPSDAC_BE = apsd_ac[0];			pAd->CommonCfg.bAPSDAC_BK = apsd_ac[1];			pAd->CommonCfg.bAPSDAC_VI = apsd_ac[2];			pAd->CommonCfg.bAPSDAC_VO = apsd_ac[3];		}	}}#endif // CONFIG_STA_SUPPORT //NDIS_STATUS	RTMPReadParametersHook(	IN	PRTMP_ADAPTER pAd){	PUCHAR					src = NULL;	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)        return NDIS_STATUS_FAILURE;	tmpbuf = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);	if(tmpbuf == NULL)	{		kfree(buffer);        return NDIS_STATUS_FAILURE;	}#ifdef CONFIG_STA_SUPPORT	IF_DEV_CONFIG_OPMODE_ON_STA(pAd)		src = STA_PROFILE_PATH;#endif // CONFIG_STA_SUPPORT //#ifdef MULTIPLE_CARD_SUPPORT	src = pAd->MC_FileName;#endif // MULTIPLE_CARD_SUPPORT //	// Save uid and gid used for filesystem access.	// Set user and group to 0 (root)		orgfsuid = current->fsuid;	orgfsgid = current->fsgid;	current->fsuid=current->fsgid = 0;    orgfs = get_fs();    set_fs(KERNEL_DS);	if (src && *src)	{		srcf = filp_open(src, O_RDONLY, 0);		if (IS_ERR(srcf)) 		{			DBGPRINT(RT_DEBUG_ERROR, ("--> Error %ld opening %s\n", -PTR_ERR(srcf),src));		}		else 		{			// The object must have a read method			if (srcf->f_op && srcf->f_op->read)			{				memset(buffer, 0x00, MAX_INI_BUFFER_SIZE);				retval=srcf->f_op->read(srcf, buffer, MAX_INI_BUFFER_SIZE, &srcf->f_pos);				if (retval < 0)				{					DBGPRINT(RT_DEBUG_TRACE, ("--> Read %s error %d\n", src, -retval));				}				else				{					// set file parameter to portcfg					//CountryRegion					if(RTMPGetKeyParameter("CountryRegion", tmpbuf, 25, buffer))					{						pAd->CommonCfg.CountryRegion = (UCHAR) simple_strtol(tmpbuf, 0, 10);						DBGPRINT(RT_DEBUG_TRACE, ("CountryRegion=%d\n", pAd->CommonCfg.CountryRegion));					}					//CountryRegionABand					if(RTMPGetKeyParameter("CountryRegionABand", tmpbuf, 25, buffer))					{						pAd->CommonCfg.CountryRegionForABand= (UCHAR) simple_strtol(tmpbuf, 0, 10);						DBGPRINT(RT_DEBUG_TRACE, ("CountryRegionABand=%d\n", pAd->CommonCfg.CountryRegionForABand));					}					//CountryCode					if(RTMPGetKeyParameter("CountryCode", tmpbuf, 25, buffer))					{						NdisMoveMemory(pAd->CommonCfg.CountryCode, tmpbuf , 2);#ifdef CONFIG_STA_SUPPORT#ifdef EXT_BUILD_CHANNEL_LIST						IF_DEV_CONFIG_OPMODE_ON_STA(pAd)							NdisMoveMemory(pAd->StaCfg.StaOriCountryCode, tmpbuf , 2);#endif // EXT_BUILD_CHANNEL_LIST //#endif // CONFIG_STA_SUPPORT //						if (strlen(pAd->CommonCfg.CountryCode) != 0)						{							pAd->CommonCfg.bCountryFlag = TRUE;						}						DBGPRINT(RT_DEBUG_TRACE, ("CountryCode=%s\n", pAd->CommonCfg.CountryCode));					}					//ChannelGeography					if(RTMPGetKeyParameter("ChannelGeography", tmpbuf, 25, buffer))					{						UCHAR Geography = (UCHAR) simple_strtol(tmpbuf, 0, 10);						if (Geography <= BOTH)						{							pAd->CommonCfg.Geography = Geography;							pAd->CommonCfg.CountryCode[2] =								(pAd->CommonCfg.Geography == BOTH) ? ' ' : ((pAd->CommonCfg.Geography == IDOR) ? 'I' : 'O');#ifdef CONFIG_STA_SUPPORT#ifdef EXT_BUILD_CHANNEL_LIST						IF_DEV_CONFIG_OPMODE_ON_STA(pAd)							pAd->StaCfg.StaOriGeography = pAd->CommonCfg.Geography;#endif // EXT_BUILD_CHANNEL_LIST //#endif // CONFIG_STA_SUPPORT //														DBGPRINT(RT_DEBUG_TRACE, ("ChannelGeography=%d\n", pAd->CommonCfg.Geography));						}					}					else					{						pAd->CommonCfg.Geography = BOTH;						pAd->CommonCfg.CountryCode[2] = ' ';					}#ifdef CONFIG_STA_SUPPORT					IF_DEV_CONFIG_OPMODE_ON_STA(pAd)					{						//SSID						if (RTMPGetCriticalParameter("SSID", tmpbuf, 256, buffer))						{							if (strlen(tmpbuf) <= 32)							{			 					pAd->CommonCfg.SsidLen = (UCHAR) strlen(tmpbuf);								NdisZeroMemory(pAd->CommonCfg.Ssid, NDIS_802_11_LENGTH_SSID);								NdisMoveMemory(pAd->CommonCfg.Ssid, tmpbuf, pAd->CommonCfg.SsidLen);								pAd->MlmeAux.AutoReconnectSsidLen = pAd->CommonCfg.SsidLen;								NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, NDIS_802_11_LENGTH_SSID);

⌨️ 快捷键说明

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