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

📄 config.c

📁 Ralink RT61 SoftAP Driver source code. RT61:MiniPCI
💻 C
📖 第 1 页 / 共 2 页
字号:
        {
            conf->radius_retry_primary_interval = atoi(pos);
        }
#ifndef MULTIPLE_RADIUS
        else if (strcmp(buf, "BssidNum") == 0)
        {
            conf->SsidNum = atoi(pos);
            if(conf->SsidNum > MAX_MBSSID_NUM)
                conf->SsidNum = 1;
            DBGPRINT(RT_DEBUG_TRACE,"conf->SsidNum=%d\n", conf->SsidNum);
        }
        else if (strcmp(buf, "DefaultKeyID") == 0)
        {
            DBGPRINT(RT_DEBUG_TRACE,"DefaultKeyID: '%s'\n", pos);
            for (i = 0, tokpos = rstrtok(pos,";"); tokpos && (i < MAX_MBSSID_NUM); tokpos = rstrtok(NULL,";"), i++)
            {
            	int KeyIdx;
            
            	KeyIdx = atoi(tokpos);
            	if((KeyIdx >= 1 ) && (KeyIdx <= 4))
            	{
            		conf->DefaultKeyID[i] = KeyIdx - 1;
            	
            		if (conf->DefaultKeyID[i] == 3)
            			conf->individual_wep_key_idx[i] = 0;
            		else
            			conf->individual_wep_key_idx[i] = 3;	
            	
            		DBGPRINT(RT_DEBUG_TRACE,"conf->DefaultKeyID[%d] = %d\n", i, conf->DefaultKeyID[i]);
            	}
            	else
            	{
                	DBGPRINT(RT_DEBUG_ERROR,"Line %d: DefaultKeyID must be 1~4 for ra%d.\n", line, i);
                  errors++;		  
            }
        }
        }
        else if (strcmp(buf, "Key1Str") == 0)
        {
            DBGPRINT(RT_DEBUG_TRACE,"Key1Str: '%s'\n", pos);
            
            for (i = 0, tokpos = rstrtok(pos,";"); tokpos && (i < MAX_MBSSID_NUM); tokpos = rstrtok(NULL,";"), i++)
            {
            	// Use wep key1 material as shared key 
            	if (conf->DefaultKeyID[i] == 0)
            	{
            		int	KeyLen = 0;
            
            		KeyLen = strlen(tokpos);
	        		if ((KeyLen == 5) || (KeyLen == 13))         //Ascii
	        		{
                		conf->individual_wep_key_len[i] = KeyLen;
                		memset(conf->IEEE8021X_ikey[i], 0, WEP8021X_KEY_LEN);
                		memcpy(conf->IEEE8021X_ikey[i], tokpos, strlen(tokpos));
                		
                		DBGPRINT(RT_DEBUG_TRACE,"iface(ra%d): use Key1Str '%s' as Default Key, Key_len: %d and Type is Ascii.\n", i, tokpos, KeyLen);
	        		}
	        		else if ((KeyLen == 10) || (KeyLen == 26))   //Hex
	        		{
			    		conf->individual_wep_key_len[i] = KeyLen/2;
			    		memset(conf->IEEE8021X_ikey[i], 0, WEP8021X_KEY_LEN);
                		AtoH(tokpos, (unsigned char *)conf->IEEE8021X_ikey[i], strlen(tokpos)/2);	  
                		
                		DBGPRINT(RT_DEBUG_TRACE,"iface(ra%d): use Key1Str '%s' as Default Key, Key_len: %d and Type is Hex.\n", i, tokpos, KeyLen);
	        		}
        		}
        	}	
        }
        else if (strcmp(buf, "Key2Str") == 0)
        {
            DBGPRINT(RT_DEBUG_TRACE,"Key2Str: '%s'\n", pos);
            
            for (i = 0, tokpos = rstrtok(pos,";"); tokpos && (i < MAX_MBSSID_NUM); tokpos = rstrtok(NULL,";"), i++)
            {
            	// Use wep key2 material as shared key 
            	if (conf->DefaultKeyID[i] == 1)
            	{
            		int	KeyLen = 0;
            
            		KeyLen = strlen(tokpos);
	        		if ((KeyLen == 5) || (KeyLen == 13))         //Ascii
	        		{
                		conf->individual_wep_key_len[i] = KeyLen;
                		memset(conf->IEEE8021X_ikey[i], 0, WEP8021X_KEY_LEN);
                		memcpy(conf->IEEE8021X_ikey[i], tokpos, strlen(tokpos));
                		
                		DBGPRINT(RT_DEBUG_TRACE,"iface(ra%d): use Key2Str '%s' as Default Key, Key_len: %d and Type is Ascii.\n", i, tokpos, KeyLen);
	        		}
	        		else if ((KeyLen == 10) || (KeyLen == 26))   //Hex
	        		{
			    		conf->individual_wep_key_len[i] = KeyLen/2;
			    		memset(conf->IEEE8021X_ikey[i], 0, WEP8021X_KEY_LEN);
                		AtoH(tokpos, (unsigned char *)conf->IEEE8021X_ikey[i], strlen(tokpos)/2);	  
                		
                		DBGPRINT(RT_DEBUG_TRACE,"iface(ra%d): use Key2Str '%s' as Default Key, Key_len: %d and Type is Hex.\n", i, tokpos, KeyLen);
	        		}
        		}
        	}	
        }
        else if (strcmp(buf, "Key3Str") == 0)
        {
            DBGPRINT(RT_DEBUG_TRACE,"Key3Str: '%s'\n", pos);
            
            for (i = 0, tokpos = rstrtok(pos,";"); tokpos && (i < MAX_MBSSID_NUM); tokpos = rstrtok(NULL,";"), i++)
        {
            	// Use wep key3 material as shared key 
            	if (conf->DefaultKeyID[i] == 2)
	        {
            		int	KeyLen = 0;
            
            		KeyLen = strlen(tokpos);
	        		if ((KeyLen == 5) || (KeyLen == 13))         //Ascii
	        		{
                		conf->individual_wep_key_len[i] = KeyLen;
                		memset(conf->IEEE8021X_ikey[i], 0, WEP8021X_KEY_LEN);
                		memcpy(conf->IEEE8021X_ikey[i], tokpos, strlen(tokpos));
                		
                		DBGPRINT(RT_DEBUG_TRACE,"iface(ra%d): use Key3Str '%s' as Default Key, Key_len: %d and Type is Ascii.\n", i, tokpos, KeyLen);
	        }
	        		else if ((KeyLen == 10) || (KeyLen == 26))   //Hex
	        {
			    		conf->individual_wep_key_len[i] = KeyLen/2;
			    		memset(conf->IEEE8021X_ikey[i], 0, WEP8021X_KEY_LEN);
                		AtoH(tokpos, (unsigned char *)conf->IEEE8021X_ikey[i], strlen(tokpos)/2);	  
                		
                		DBGPRINT(RT_DEBUG_TRACE,"iface(ra%d): use Key3Str '%s' as Default Key, Key_len: %d and Type is Hex.\n", i, tokpos, KeyLen);
	        }
        		}
        	}	
        }
        else if (strcmp(buf, "Key4Str") == 0)
        {
            DBGPRINT(RT_DEBUG_TRACE,"Key4Str: '%s'\n", pos);
            
            for (i = 0, tokpos = rstrtok(pos,";"); tokpos && (i < MAX_MBSSID_NUM); tokpos = rstrtok(NULL,";"), i++)
            {
            	// Use wep key4 material as shared key 
            	if (conf->DefaultKeyID[i] == 3)
            	{
            		int	KeyLen = 0;
            
            		KeyLen = strlen(tokpos);
	        		if ((KeyLen == 5) || (KeyLen == 13))         //Ascii
	        		{
                		conf->individual_wep_key_len[i] = KeyLen;
                		memset(conf->IEEE8021X_ikey[i], 0, WEP8021X_KEY_LEN);
                		memcpy(conf->IEEE8021X_ikey[i], tokpos, strlen(tokpos));
            
                		DBGPRINT(RT_DEBUG_TRACE,"iface(ra%d): use Key4Str '%s' as Default Key, Key_len: %d and Type is Ascii.\n", i, tokpos, KeyLen);
        }
	        		else if ((KeyLen == 10) || (KeyLen == 26))   //Hex
	        		{
			    		conf->individual_wep_key_len[i] = KeyLen/2;
			    		memset(conf->IEEE8021X_ikey[i], 0, WEP8021X_KEY_LEN);
                		AtoH(tokpos, (unsigned char *)conf->IEEE8021X_ikey[i], strlen(tokpos)/2);	  

                		DBGPRINT(RT_DEBUG_TRACE,"iface(ra%d): use Key4Str '%s' as Default Key, Key_len: %d and Type is Hex.\n", i, tokpos, KeyLen);
	        		}
        		}
        	}	
        }	
#endif        
        else if ((strcmp(buf, "pid") == 0) && (pid != 0))
        {
            //fseek(f,0,SEEK_CUR);
            //fprintf(f, "pid=%4x", pid);
            flag |= 0x10;
            cur = 0;
            tmp = pid;
            while(cur <= (int)filesize)
            {  
                if ((ini_buffer[cur]=='p') && (ini_buffer[cur+1]=='i') && (ini_buffer[cur+2]=='d') )
                {
                    cur += 4;
                    for( i=4; i>=0; i--)
                    {
                        now = now/10;
                        if(ini_buffer[cur]!='\n')
                        {
                            ini_buffer[cur] = tmp/(now)+0x30;
                        }
                        else
                        {
                            prev = ini_buffer[cur];
                            ini_buffer[cur] = tmp/(now)+0x30;
                            savecur = cur+1;
                            do
                            {
                                save = ini_buffer[savecur];
                                ini_buffer[savecur] = prev;
                                prev = save;
                                savecur ++;
                            }while(savecur <= (filesize+5));
                        }  
                        cur++;
                        tmp -= ((tmp/(now))*(now));                        
                    }   
                    break;
                }
                cur++;
            }
        } 
        else if (strcmp(buf, "session_timeout_interval") == 0)
        {
            flag |= 0x20;
            conf->session_timeout_interval = atoi(pos);
            if (conf->session_timeout_interval == 0)
                conf->session_timeout_set= 0;
            else
                conf->session_timeout_set= 1;
		
            DBGPRINT(RT_DEBUG_TRACE,"session_timeout policy = %s \n", conf->session_timeout_set?"set":"not use");
            DBGPRINT(RT_DEBUG_TRACE,"Read Session Timeout Interval  %d seconds. \n", conf->session_timeout_interval);
            conf->session_timeout_interval = (atoi(pos)<60) ? REAUTH_TIMER_DEFAULT_reAuthPeriod : atoi(pos);
            DBGPRINT(RT_DEBUG_TRACE,"Set Session Timeout Interval  %d seconds. \n", conf->session_timeout_interval);
        }
        else if (strcmp(buf, "Ethifname") == 0)
        {
        	int len = strlen(pos);
            if (pos[len-1] == 0xd)
                len--;
            if (len == 0)
            {
                errors++;
            }
            memcpy(conf->ethifname, pos, len);
            DBGPRINT(RT_DEBUG_TRACE,"Ethifname: %s \n", conf->ethifname);
        }
    }
        
    fseek(f,0,SEEK_SET);
    fprintf(f, "%s", ini_buffer);    
    fclose(f);
    if ((!(flag&0x10)) && (pid != 0))
    {
        tmp = pid;
        f = fopen(fname, "r+");
        if ((buff=(char *)malloc(10))==NULL)
            return (0);   //out of memory
        buff[9]='\0';
        fseek(f,0,SEEK_END);
        strcpy(buff,"pid=");
        cur = 4;
        for( i=4; i>=0; i--)
        {
            now = now/10;
            buff[cur] = tmp/(now)+0x30;
            cur++;
            tmp -= ((tmp/(now))*(now));
        }        
        fprintf(f, buff);    
        fclose(f);
    }

    conf->auth_server = conf->auth_servers;
    if (errors )
    {
        DBGPRINT(RT_DEBUG_ERROR,"%d errors found in configuration file '%s'\n", errors, fname);
        Config_free(conf);
        conf = NULL;
    }
    if ((flag&0x0f)!=0x0f )
    {
        DBGPRINT(RT_DEBUG_ERROR,"Not enough parameters found in configuration file '%s'\n", fname);
        Config_free(conf);
        conf = NULL;
    }
    return conf;
}

static void Config_free_radius(struct hostapd_radius_server *servers, int num_servers)
{
    int i;

    for (i = 0; i < num_servers; i++)
    {
        free(servers[i].shared_secret);
    }
    free(servers);
}

void Config_free(struct rtapd_config *conf)
{
    if (conf == NULL)
        return;

    Config_free_radius(conf->auth_servers, conf->num_auth_servers);
    free(conf);
}

⌨️ 快捷键说明

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