Ejemplo n.º 1
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;
}
Ejemplo n.º 2
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{
Ejemplo n.º 3
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;
}    
Ejemplo n.º 4
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;
}
Ejemplo n.º 5
0
/*Get STA Connected AP Wireless Mode*/
int get_sta_assoc_wmode(int radio, char *wmode)
{
    char cmd[128];
    char bssid[32], converted_bssid[32];
    FILE *fp;
    char *pBssidList = (char*)malloc(256 * sizeof (char));
    char tmpBSSID[28], tmpWMODE[16];
    char bssid_get[28], wireless_mode_get[16];

    get_sta_assoc_bssid(radio, bssid);
    //printf("bssid is %s\n", bssid);
    /*Set apcli site survey as enable*/    
    sprintf(cmd, "iwpriv apclii0 set SiteSurvey=1");
    EXE_COMMAND(cmd);    
    memset(cmd, 0, sizeof(cmd));
    /*Carry out site survey, restore the result to /tmp/site_survey_middleware.dat file*/    
    format_bssid_upper(bssid, converted_bssid);
    sprintf(cmd, "iwpriv apclii0 get_site_survey | grep \"%s\" > /tmp/site_survey_middleware.dat", converted_bssid);
    EXE_COMMAND(cmd);    
    //printf("%s\n", cmd);
    memset(cmd, 0, sizeof(cmd));

    if (NULL == (fp = fopen("/tmp/site_survey_middleware.dat","r")))
        {
            printf("Ap list is NONE\n");
        free(pBssidList);
        return T_FAILURE;
        }
    else
        {
            //fgets(pBssidList, 256, fp);
            //fgets(pBssidList, 256, fp);

            while(!feof(fp)){
                memset(tmpBSSID, 0x00, sizeof(tmpBSSID));
                memset(tmpWMODE, 0x00, sizeof(tmpWMODE));
                memset(bssid_get, 0x00, sizeof(bssid_get));
                memset(wireless_mode_get, 0x00, sizeof(wireless_mode_get));

                fgets(pBssidList, 256, fp);

                snprintf(tmpBSSID, 19, "%s", pBssidList+39);
                format_bssid_upper(tmpBSSID, bssid_get);
                //printf("bssid_get is %s\n", bssid_get);

                snprintf(tmpWMODE, 9, "%s", pBssidList+90);
                strcpy_delspace(tmpWMODE, wireless_mode_get);
                //printf("wireless_mode_get is %s\n", wireless_mode_get);

                if(!strcmp(bssid, bssid_get))
                    {
                        strcpy(wmode, wireless_mode_get);             
                        //printf("wmode is %s\n", wmode);
                        break;
                    }
            }
        }

    free(pBssidList);
    fclose(fp);
    //sprintf(cmd, "rm -rf /tmp/site_survey_middleware.dat");
    //EXE_COMMAND(cmd);    

    return T_SUCCESS;
}