Esempio n. 1
0
//Get NVRAM wireless mode
int nvram_get_ap_wireless_mode(int radio, int *wmode)
{
    //Get WLAN mode first
    int wlan_mode = {0};
    char buf[NVRAM_BUF_LEN] = { 0 };
    int net_mode;

    nvram_get_wlan_mode(radio, &wlan_mode);
    MID_ASSERT((WLAN_MODE_AP == wlan_mode || WLAN_MODE_STA == wlan_mode), "WLAN mode got from NVRAM illegal");

    if(RADIO_2G == radio)
        {
            if(WLAN_MODE_AP == wlan_mode)
                {
                    ezplib_get_attr_val("wl_ap_basic_rule", 0, "net_mode", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); 
                }
            else if(WLAN_MODE_STA == wlan_mode)
                {
                    ezplib_get_attr_val("wl_basic_rule", 0, "net_mode", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); 
                }
        }
    else if(RADIO_5G == radio)
        {
            if(WLAN_MODE_AP == wlan_mode)
                {
                    ezplib_get_attr_val("wl5g_ap_basic_rule", 0, "net_mode", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); 
                }
            else if(WLAN_MODE_STA == wlan_mode)
                {
                    ezplib_get_attr_val("wl5g_basic_rule", 0, "net_mode", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); 
                }
        }


    net_mode = atoi(buf);
    switch(net_mode)
    {
        case WMODE_11BG:
        case WMODE_11B:
        case WMODE_11A:
        case WMODE_11ABG:
        case WMODE_11G:
        case WMODE_11ABGN:
        case WMODE_11N:
        case WMODE_11GN:
        case WMODE_11AN:
        case WMODE_11BGN:
        case WMODE_11AGN:
        case WMODE_11N5G:
        case WMODE_11AC_MIXED:
            *wmode = net_mode;
            break;   

        default:
            MID_ERROR("Wireless mode illegal or not supported");
            return T_FAILURE;
    }

    return T_SUCCESS;
}
Esempio n. 2
0
int set_wlan_advance(int radio)
{
    int ret;
    int wlan_mode = -1;
    nvram_get_wlan_mode(radio, &wlan_mode);
    radio_up_down(radio, RADIO_DOWN, wlan_mode);
    /*dtim*/
    ret = set_dtim(radio);
    if(T_FAILURE == ret)
        {
            printf("ERRO:Set DTIM failure!\n");
            return T_FAILURE;
        }
    /*bcn*/
    ret = set_beacon_interval(radio);
    if(T_FAILURE == ret)
        {
            printf("ERRO:Set BCN Interval failure!\n");
            return T_FAILURE;
        }

    radio_up_down(radio, RADIO_UP, wlan_mode);

    /*txpower*/
    ret = set_power(radio);
    if(T_FAILURE == ret)
        {
            printf("ERRO:Set POWER failure!\n");
            return T_FAILURE;
        }

	//Deleted by Mario Huang 2014-08-12
	//set_ap_wmm(radio, 0);
    return T_SUCCESS;
}
Esempio n. 3
0
/*get the channel current in use*/
int get_current_channel(int radio, Channel_t *channel_get)
{
    char str[256] = {0},c;
    char channel_s[8] = {0};
    char frequency_s[8] = {0};
    char vap_name[8] = {0};
    int wlan_mode = 0;
    int ret;
    FILE *fin;
    char cmd[256];
    float tmp_frequency = 0;

    nvram_get_wlan_mode(radio, &wlan_mode);
    ret = construct_vap(vap_name, radio, 0, wlan_mode);
	if (T_FAILURE == ret) {
        printf("ERROR:Get VAP Name Failure!\n");
        return T_FAILURE;
    }

    //The command I wanna is iwlist ath0 channel | grep Current  | awk '{gsub(/)/,"");print}' | awk '{print substr($5,0)}'
    sprintf(cmd, "iwlist %s channel | grep Current  | awk '{gsub(/)/,\"\");print}' | awk '{print substr($5,0)}' > /tmp/current_channel", vap_name);
    EXE_COMMAND(cmd);
    fin = fopen("/tmp/current_channel","r");
            
    while ((c=fgetc(fin)) != EOF){
        ungetc(c,fin);        
        readline(str,fin);
        strcpy_delspace(str, channel_s);
        channel_get->chan_number = atoi(channel_s);
    }

    fclose(fin);
    EXE_COMMAND("rm -f /tmp/current_channel");    

    memset(cmd, 0, sizeof(cmd));
    //The command I wanna is iwlist ath0 channel | grep Current  | awk '{gsub(/\./,"");print}' | awk '{print substr($2,11)}'
    //sprintf(cmd, "iwlist %s channel | grep Current  | awk '{gsub(/\\./,\"\");print}' | awk '{print substr($2,11)}' > /tmp/current_frequency", vap_name);
    sprintf(cmd, "iwlist %s channel | grep Current | awk '{print substr($2,11)}' > /tmp/current_frequency", vap_name);
    EXE_COMMAND(cmd);
    fin = fopen("/tmp/current_frequency","r");
            
    while ((c=fgetc(fin)) != EOF){
        ungetc(c,fin);        
        readline(str,fin);
        strcpy_delspace(str, frequency_s);
        //channel_get->frequency = atoi(frequency_s);
        tmp_frequency = atof(frequency_s);
        tmp_frequency = tmp_frequency * 1000; 
        channel_get->frequency = (int)tmp_frequency;
    }

    fclose(fin);
    EXE_COMMAND("rm -f /tmp/current_frequency");    

    return T_SUCCESS;
}
Esempio n. 4
0
//Get NVRAM if the radio enable or not
int nvram_get_radio_status(int radio, int *radio_status)
{
    char buf[NVRAM_BUF_LEN] = { 0 };
    int wlan_mode = {0};

    nvram_get_wlan_mode(radio, &wlan_mode);
    MID_ASSERT((WLAN_MODE_AP == wlan_mode || WLAN_MODE_STA == wlan_mode), "WLAN mode got from NVRAM illegal");

    if(RADIO_2G == radio)
        {
            if(WLAN_MODE_AP == wlan_mode)
                {
                    ezplib_get_attr_val("wl_ap_basic_rule", 0, "enable", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI);
                }
            else if(WLAN_MODE_STA == wlan_mode)
                {
                
                    ezplib_get_attr_val("wl_basic_rule", 0, "enable", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI);
                }
        }
    else if(RADIO_5G == radio)
        {
            if(WLAN_MODE_AP == wlan_mode)
                {
                    ezplib_get_attr_val("wl5g_ap_basic_rule", 0, "enable", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI);
                }
            else if(WLAN_MODE_STA == wlan_mode)
                {
                    ezplib_get_attr_val("wl5g_basic_rule", 0, "enable", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI);
                }
        }


    if(!strcmp(buf, "1")) 
        {
            *radio_status = RADIO_UP;
        }
    else if(!strcmp(buf, "0"))
        {
            *radio_status = RADIO_DOWN;
        }

    else
        {        
            MID_ERROR("Radio status got from NVRAM illegal");
            return T_FAILURE;
        }

    return T_SUCCESS;
}
Esempio n. 5
0
/*get the bandwidth current in use*/
int get_bandwidth(int radio, int *htbw)
{
    char str[256] ={0},c;
    //int bandwidth;
    int wlan_mode;
    char wireless_mode[32] = {0};
    char vap_name[8];
    int ret;
    FILE *fin;
    char cmd[256];

    nvram_get_wlan_mode(radio, &wlan_mode);
    ret = construct_vap(vap_name, radio, 0, wlan_mode);
	if (T_FAILURE == ret) {
        printf("ERROR:Get VAP Name Failure!\n");
        return T_FAILURE;
    }

	if(WLAN_MODE_STA == wlan_mode){
        sprintf(cmd, "iwpriv %s get_chwidth | awk -F\: '{print $2}' >> /tmp/current_chwidth", vap_name);
        EXE_COMMAND(cmd);
        fin = fopen("/tmp/current_chwidth","r");
                
        /*Parse rate from /tmp/current_chwidth file*/
        while ((c=fgetc(fin)) != EOF){
            ungetc(c,fin);        
            readline(str,fin);
            strcpy_delspace(str, wireless_mode);
        }

    	fclose(fin);
        EXE_COMMAND("rm -f /tmp/current_chwidth");

    	if (strstr(wireless_mode, "0") != NULL) {
    		*htbw = BANDWIDTH_20;
    	} else if (strstr(wireless_mode, "1") != NULL) {
    		*htbw = BANDWIDTH_40;
    	} else if (strstr(wireless_mode, "2") != NULL) {
    		*htbw = BANDWIDTH_80;
    	} else {
    		MID_ERROR("Can not get wireless mode or the wireless mode is not supported by now!");
    		return T_FAILURE;
    	}
	}else{
Esempio n. 6
0
/*Get wlan rate*/
int get_wlan_rate(int radio,int *rate)
{
    char str[256] = {0},c;
    char rate_s[8] = {0};
    char vap_name[8];
    int wlan_mode;
    int ret;
    FILE *fin = NULL;
    char cmd[256];

    //Set rate as 0 first
    *rate = 0;
 
    nvram_get_wlan_mode(radio, &wlan_mode);
    ret = construct_vap(vap_name, radio, 0, wlan_mode);
	if (T_FAILURE == ret) {
        printf("ERROR:Get VAP Name Failure!\n");
        return T_FAILURE;
    }

    sprintf(cmd, "iwconfig %s | grep Rate | awk '{print substr($2,6,3)}' > /tmp/current_wlan_rate", vap_name);
    EXE_COMMAND(cmd);
    fin = fopen("/tmp/current_wlan_rate","r");
            
    /*Parse rate from /tmp/current_wlan_rate file*/
    while ((c=fgetc(fin)) != EOF){
        ungetc(c,fin);        
        readline(str,fin);
        strcpy_delspace(str, rate_s);
        *rate = atoi(rate_s);
    }

    fclose(fin);
    EXE_COMMAND("rm -f /tmp/current_wlan_rate");    

   
    return T_SUCCESS;
}    
Esempio n. 7
0
//Get NVRAM Bandwidth
int nvram_get_bandwidth(int radio, int *htbw)
{
    //Get WLAN mode first
    int wlan_mode = {0};
    char buf[NVRAM_BUF_LEN] = { 0 };

    nvram_get_wlan_mode(radio, &wlan_mode);
    MID_ASSERT((WLAN_MODE_AP == wlan_mode || WLAN_MODE_STA == wlan_mode), "WLAN mode got from NVRAM illegal");

    if(RADIO_2G == radio)
        {
            if(WLAN_MODE_AP == wlan_mode)
                {
                    ezplib_get_attr_val("wl_ap_advanced_rule", 0, "htbw", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); 
                }
            else if(WLAN_MODE_AP == wlan_mode)
                {
                    ezplib_get_attr_val("wl_advanced_rule",0,"htbw",buf,NVRAM_BUF_LEN,EZPLIB_USE_CLI);
                }
        
        }
    else if(RADIO_5G == radio)
        {
            if(WLAN_MODE_AP == wlan_mode)
                {
                    ezplib_get_attr_val("wl1_ap_advanced_rule",0,"htbw",buf,NVRAM_BUF_LEN,EZPLIB_USE_CLI);
                }
            else if(WLAN_MODE_AP == wlan_mode)
                {
                    ezplib_get_attr_val("wl1_advanced_rule",0,"htbw",buf,NVRAM_BUF_LEN,EZPLIB_USE_CLI);
                }
        }
    
    *htbw = atoi(buf); 
    MID_ASSERT((BANDWIDTH_20 == *htbw || BANDWIDTH_40 == *htbw || BANDWIDTH_80 == *htbw), "Bandwidth illegal");

    return T_SUCCESS;
}
Esempio n. 8
0
/*get the channel current in use*/
int get_extchannel(int radio, Channel_t *extchannel_get)
{
	int ret = 0;
	int bandWidth = 0;
	int wlan_mode = 0;
	FILE *fin;
	char c;
    char str[256] = {0};
	char cmd[256] = {0};
	char exchannel[8] = {0};
	char vap_name[8] = {0};
	Channel_t channel_get;
	memset(&channel_get, 0, sizeof(Channel_t));

	ret = get_bandwidth(radio, &bandWidth);

	if (ret == T_FAILURE) {
		printf("Error: Get BandWidth Failure\n");
		return T_FAILURE;
	}

	if (BANDWIDTH_40 == bandWidth) {
		
		ret = get_current_channel(radio, &channel_get);
		
		if (T_FAILURE == ret) {
			
			printf("Error:Get Operation Channel Failure\n");
			return T_FAILURE;
			
		} else {

			nvram_get_wlan_mode(radio, &wlan_mode);
    		ret = construct_vap(vap_name, radio, 0, wlan_mode);

			if (T_FAILURE == ret) {
				
				printf("Error:Get Vap Name Failure\n");
				return T_FAILURE;
			}

			//iwpriv athN get_chextoffset | awk '{gsub(/get_chextoffset:/,"");print}' | awk '{print $2}' > /tmp/extchannel
			sprintf(cmd, "iwpriv %s get_chextoffset | awk '{gsub(/get_chextoffset:/,\"\");print}' | awk '{print $2}' > /tmp/extchannel", vap_name);
    		EXE_COMMAND(cmd);
    		fin = fopen("/tmp/extchannel","r");
            
    		while ((c=fgetc(fin)) != EOF){
        		ungetc(c,fin);        
        		readline(str,fin);
        		strcpy_delspace(str, exchannel);
   			}
			
			fclose(fin);
			EXE_COMMAND("rm -fr /tmp/extchannel");

			if (!strcmp(exchannel, "1")) {
				extchannel_get->chan_number = channel_get.chan_number + 4;
				extchannel_get->frequency = channel_get.frequency + 20;
			} else if (!strcmp(exchannel, "-1")) {
				extchannel_get->chan_number = channel_get.chan_number - 4;
				extchannel_get->frequency = channel_get.frequency - 20;
			} else {
				printf("Error: CMD get_chextoffset Failure\n");
				return T_FAILURE;
			}
		}
		
	} else {
	
		printf("Get BandWidth Not 40MHz\n");
		return T_FAILURE;
	}

	return T_SUCCESS;
}
Esempio n. 9
0
/*
Get Radio status
1: Up
0:Down
*/
int get_radio_status(int radio, int *radio_status)
{
    int ret;
    int wlan_mode;
    int wifi_status;
    int vap_status;
    int vap_num = 0;
    int i;
    //If wifi0 or wifi1 is down, the radio is down
    get_wifi_status(radio, &wifi_status);   
    if(RADIO_DOWN == wifi_status)
    {
        *radio_status = RADIO_DOWN;
        return T_SUCCESS;
    }
    //Get wlan_mode from nvram first
    nvram_get_wlan_mode(radio, &wlan_mode);
    if(WLAN_MODE_AP == wlan_mode)
    {
        //Get VAP num of the Radio
        vap_num = nvram_get_vap_num(radio);
        //search for all the VAPs, radio is DOWN while all the VAPs are down, or radio is up.
        for(i=0; i < vap_num; i++)
        {
            ret = get_vap_status(radio, i, wlan_mode, &vap_status);
            if(T_FAILURE == ret)
                {
                    printf("ERROR:Get VAP Staus Failure!\n");
                    return T_FAILURE;
                }    
    
            if(VAP_UP == vap_status)
                {
                    *radio_status = RADIO_UP;
                    return T_SUCCESS;
                }
        }
           
        *radio_status = RADIO_DOWN;
    }
    else if(WLAN_MODE_STA == wlan_mode)
    {
        ret = get_vap_status(radio, 0, wlan_mode, &vap_status);
        if(T_FAILURE == ret)
            {
                printf("ERROR:Get VAP Staus Failure!\n");
                return T_FAILURE;
            }    

        if(VAP_UP == vap_status)
            {
                *radio_status = RADIO_UP;
                return T_SUCCESS;
            }
        else
            {
                *radio_status = RADIO_DOWN;
            }
    }

    return T_SUCCESS;
}
Esempio n. 10
0
//Get NVRAM TX Power
int nvram_get_txpower(int radio, int *txpower)
{
    //Get WLAN mode first
    int wlan_mode = {0};
    char buf[NVRAM_BUF_LEN] = { 0 };
    int nvram_txpower;

    nvram_get_wlan_mode(radio, &wlan_mode);
    MID_ASSERT((WLAN_MODE_AP == wlan_mode || WLAN_MODE_STA == wlan_mode), "WLAN mode got from NVRAM illegal");

    if(RADIO_2G == radio)
        {
            if(WLAN_MODE_AP == wlan_mode)
                {
                    ezplib_get_attr_val("wl_ap_basic_rule", 0, "txpower", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI);        
                }
            else if(WLAN_MODE_AP == wlan_mode)
                {
                    ezplib_get_attr_val("wl_basic_rule", 0, "txpower", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI);    
                }
        }
    else if(RADIO_5G == radio)
        {
            if(WLAN_MODE_AP == wlan_mode)
                {
                    ezplib_get_attr_val("wl1_ap_basic_rule", 0, "txpower", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI);            
                }
            else if(WLAN_MODE_AP == wlan_mode)
                {
                    ezplib_get_attr_val("wl1_basic_rule", 0, "txpower", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI);        
                }
                    
        }
    nvram_txpower = atoi(buf);
    switch(nvram_txpower)
        {
            case 0:
                *txpower = 0;
                break;
            case 2:
                *txpower = 2;
                break;
            case 4:
                *txpower = 4;
                break;
            case 6:
                *txpower = 6;
                break;
            case 8:
                *txpower = 8;
                break;
            case 10:
                *txpower = 10;
                break;
            case 12:
                *txpower = 12;
                break;
            case 14:
                *txpower = 14;
                break;
            case 16:
                *txpower = 16;
                break;
            case 18:
                *txpower = 18;
                break;
            default:
                MID_ERROR("TxPower got from NVRAM is illegal");
                return T_FAILURE;
        }

    return T_SUCCESS;
}
Esempio n. 11
0
int set_wlan_basic(int radio)
{
    int vap_enable;
    int radio_nvram_enable;
    int i;
    int vap_num;
    int wlan_mode = -1;
    nvram_get_radio_status(radio, &radio_nvram_enable);
    nvram_get_wlan_mode(radio, &wlan_mode);

    if(RADIO_DOWN == radio_nvram_enable)
        {
            //Kill all the security daemon first
//            if(WLAN_MODE_AP == wlan_mode)
//            {
                radio_up_down(radio, RADIO_DOWN, wlan_mode);
                kill_all_authentication_daemon(radio, wlan_mode);
				//wds
				for(i=0;i<WDS_VAP_NUM;i++) {
					set_ap_wds_down(radio, i);
				}
//            }
//            else if(WLAN_MODE_STA == wlan_mode)
//            {
//                kill_all_authentication_daemon(radio, wlan_mode);
//                radio_up_down(radio, RADIO_DOWN, wlan_mode);
//            }
            return T_SUCCESS;
        }

//    if(WLAN_MODE_AP == wlan_mode)
//        {
            //Down all the VAPs first
            radio_up_down(radio, RADIO_DOWN, wlan_mode);
            //wds
			for(i=0;i<WDS_VAP_NUM;i++) {
				set_ap_wds_down(radio, i);
			}
            //Kill all the security daemon first
            kill_all_authentication_daemon(radio, wlan_mode);
//        }
//    else if(WLAN_MODE_STA == wlan_mode)
//        {
            //Kill all the security daemon first
//            kill_all_authentication_daemon(radio, wlan_mode);
            //Down all the VAPs first
//            radio_up_down(radio, RADIO_DOWN, wlan_mode);
//        }
    /*net mode and channel*/
    set_ap_wirelessmode_channel(radio);
    /*ap isolation*/
    vap_num = nvram_get_vap_num(radio); 
    //for(i=1; i < vap_num; i++)
    for(i=0; i < vap_num; i++)
	{
        nvram_get_vap_status(radio, i, &vap_enable);
        if(VAP_ENABLE == vap_enable)
            {
				set_ssid(radio, WLAN_MODE_AP, i);//add by frank
				set_acl(radio, i);
				//set_enable_ssid(radio, WLAN_MODE_AP, i);
				set_hidden_ssid(radio, WLAN_MODE_AP, i);//add by frank
				set_bss_isolation(radio, WLAN_MODE_AP, i);//add by frank
				set_ap_security(radio, i);
#if defined(VLAN_ENABLE)
				//Deleted by Mario Huang
				//set_wlan_vlan(radio,i);
                //preserve 3 seconds for main VAP
#endif
                if(0==i) {
					sleep(3);
				}
            }
        else if(VAP_DISABLE == vap_enable)
            {
                //set_disable_ssid(radio, WLAN_MODE_AP, i);
                //vap_up_down(radio, i, WLAN_MODE_AP, VAP_DOWN);
            }		
	}
	set_ap_isolation(radio);//add by frank, impl on 2014-02-17
	//Deleted by Mario Huang 2014-08-12
	//set_ap_wmm(radio, 0);
	//Added by Mario Huang for VLAN test
#if defined(VLAN_ENABLE)
	updateVlan();
#endif
	//wds
	for(i=0;i<WDS_VAP_NUM;i++) {
		set_ap_wds_up(radio, i);
	}
    return T_SUCCESS;
}