Exemplo n.º 1
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;
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
0
//Added By Andy Yu in 2014/01/23: Get Ethernet Client List
int get_ethernet_client_list(int radio, ETHERNET_CLIENT_LIST *client_list)
{
	int i = 0;
	int j = 0;
	int ret = 0;
	int rMode = 0;
	FILE *fp = NULL;
	char ip_buf[64] = { 0 };
	char mac_buf[20] = { 0 };
	char tmp_buf[64] = { 0 };
	char vap_name[8] = { 0 };
	char ModeTmpBuf[32] = { 0 };
	char cmd[128] = { 0 };
	client_list->client_num = 0;

	if (RADIO_2G == radio) {
		ezplib_get_attr_val("wl_mode_rule", 0, "mode", ModeTmpBuf, 32, EZPLIB_USE_CLI);
		
		if (!strcmp(ModeTmpBuf, "client")) {
			rMode = WLAN_MODE_STA;
		} else {
			printf("2.4G Not in Station Mode\n");
			return T_FAILURE;
		}
	}
	else if (RADIO_5G == radio) {
		ezplib_get_attr_val("wl1_mode_rule", 0, "mode", ModeTmpBuf, 32, EZPLIB_USE_CLI);
		
		if (!strcmp(ModeTmpBuf, "client")) {
			rMode = WLAN_MODE_STA;
		} else {
			printf("5G Not in Station Mode\n");
			return T_FAILURE;
		}
	}
	else {
		printf("ERROR:Radio error!\n");
        return T_FAILURE;
	}

	/* Get br-lan0 MAC */
	ret = get_lan_mac(tmp_buf);
	printf("++++++++++%s+++++++++++\n", tmp_buf);
	if (T_FAILURE == ret) {
		printf("ERROR: Get LAN MAC Error\n");
		return T_FAILURE;
	}

	/* Get vap name: sta0 or sta1 */
	ret = construct_vap(vap_name, radio, 0, rMode);
	if (T_FAILURE == ret) {
		printf("ERROR: Get VAP Name Error\n");
		return T_FAILURE;
	}

	sprintf(cmd, "wlanconfig %s list extsta | awk '{if(NR!=1) print $0}' > /tmp/ethCliList", vap_name);
	EXE_COMMAND(cmd);
	
	if (NULL == (fp = fopen("/tmp/ethCliList", "r"))) {
		return T_FAILURE;
	}

	i = 0;
	while (!feof(fp)) {
		ret = fscanf(fp, "%d%s%s", &j, mac_buf, ip_buf);
		if (j > 128) {
			printf("Client Max Number is 128\n");
			break;
		}
		if ( ret == EOF) {
			printf("fsacnf End\n");
			break;
		}

		if ((mac_buf[2] != ':') || (mac_buf[5] != ':') || (mac_buf[8] != ':') || (mac_buf[11] != ':')
				|| (mac_buf[14] != ':') || (!strcmp(mac_buf, tmp_buf))) {
			continue;
		}

		memset(client_list->client[i].macaddr, 0x00, sizeof(client_list->client[i].macaddr));
		memset(client_list->client[i].ipaddr, 0x00, sizeof(client_list->client[i].ipaddr));
		strcpy(client_list->client[i].macaddr, mac_buf);
		strcpy(client_list->client[i].ipaddr, ip_buf);
		printf("%d %s %s\n", i, client_list->client[i].macaddr, client_list->client[i].ipaddr);
		memset(mac_buf, 0, 20);
		memset(ip_buf, 0, 64);
		i++;
	}
	client_list->client_num = i;

	fclose(fp);
	sprintf(cmd, "rm -rf /tmp/ethCliList");
	EXE_COMMAND(cmd);
	
    return T_SUCCESS;
}
Exemplo n.º 4
0
/**
 * \brief create wpa_suplicant config files accroding to radio & authmode
 * \return T_SUCCESS on success & T_FAILURE on failure
 * \param[in] radio RADIO_2G or RADIO_5G
 * \param[in] authmode 
 * 		available collections: WPAPSK/WPA2PSK/WPA/WPA2/WEP/NONE
 * 		invalid   collections: UNDEFINED/WPAPSKWPA2PSK/WPAWPA2
 * \author frank
 * \date 2014-01-24
 * \date 2014-02-27 WPA use proto=WPA, WPA2 use proto=RSN
 */
int create_wpa_supplicant_conf(int radio, int authmode)
{
	assert(AUTHMODE_UNDEFINED != authmode);

	FILE *fp;
	char cmd[128] = {0};
	char ifacename[16] = {0};
	char buffer[14][128];
	memset(buffer, 0, sizeof(buffer));
	char buffer_write[128] = {0};
	int size = 0;

	//Both 802.1X & PSK
	char ssid[NVRAM_SSID_LEN] = {0};
	char bssid[NVRAM_BUF_LEN] = {0};
	int encryp_type =  ENCRY_NONE;
	nvram_get_sta_ssid(radio, ssid, 0);
	nvram_get_sta_bssid(radio, bssid);
	encryp_type = nvram_get_sta_crypto(radio);

	//PSK
	char psk_key[128] = {0};
	nvram_get_sta_psk(radio, psk_key);

	//802.1X
	char wpauser[NVRAM_8021X_NAME_LEN] = {0};
	char wpapasswd[NVRAM_8021X_PWD_LEN] = {0};
	int eap_mode = EAP_MODE_NONE;
	nvram_get_sta_radius_user(radio, wpauser);
	nvram_get_sta_radius_password(radio, wpapasswd);
	eap_mode = nvram_get_sta_eap_mode(radio);

	//WEP
	char key[27] = {0};
	char keyencmode[16] = {0};	// "open", "shared"
	int keyidx = 0;				//1~4
	int keytype = 0;			//0 for HEX, 1 for ASCII
	int encmode = 0;			//4 for "auto", 1 for "open", 2 for "shared"
	int wep_encry = 0;			//0 for 64bits, 1 for 128bits
	nvram_get_sta_wep(radio, key, &keyidx, &keytype, keyencmode, &wep_encry);
	if(!strcmp("open", keyencmode)) {
		encmode = 1;
	}
	else if(!strcmp("shared", keyencmode)) {
		encmode = 2;
	}
	else {
		encmode = 4;
	}


	if(T_FAILURE == construct_vap(ifacename, radio, 0, WLAN_MODE_STA)) {
		fprintf(stderr, "%d@%s unsupported mode error!", __LINE__, __FUNCTION__);
		return T_FAILURE;
	}

	sprintf(cmd, "rm -rf %s/%s.conf", WPA_SUPPLICANT_CFG_PATH, ifacename);
	EXE_COMMAND(cmd);
	memset(cmd, 0, sizeof(cmd));

	sprintf(cmd, "touch %s/%s.conf", WPA_SUPPLICANT_CFG_PATH, ifacename);
	EXE_COMMAND(cmd);
	memset(cmd, 0, sizeof(cmd));

	sprintf(cmd, "%s/%s.conf", WPA_SUPPLICANT_CFG_PATH, ifacename);

	if(!( fp = fopen(cmd, "wr")))
	{
		fprintf(stderr, "Open %s error\n", cmd);
		return T_FAILURE;
	}

	int i = 0;	
	switch(authmode) {
		case AUTHMODE_WPAPSK:
		case AUTHMODE_WPA2PSK:
			sprintf(buffer[i++], "ctrl_interface=/var/run/wpa_supplicant\n");
			sprintf(buffer[i++], "ap_scan=1\n");
			sprintf(buffer[i++], "network={\n");
			sprintf(buffer[i++], "    ssid=\"%s\"\n", ssid);
			if(0 != *bssid) {
			sprintf(buffer[i++], "    bssid=%s\n", bssid);
			}
			sprintf(buffer[i++], "    scan_ssid=1\n");
			
			//proto
			if (AUTHMODE_WPA2PSK == authmode) {
			sprintf(buffer[i++], "    proto=WPA2\n");
			}
			else if (AUTHMODE_WPAPSK == authmode) {
			sprintf(buffer[i++], "    proto=WPA\n");
			}

			sprintf(buffer[i++], "    key_mgmt=WPA-PSK\n");

			//cryption
			if (ENCRY_AES == encryp_type) {
			sprintf(buffer[i++], "    pairwise=CCMP\n");
			}
			else if (ENCRY_TKIP == encryp_type) {
			sprintf(buffer[i++], "    pairwise=TKIP\n");
			}
			sprintf(buffer[i++], "    psk=%s%s%s\n", 
					strlen(psk_key) == 64 ? "":"\"",
					psk_key,
					strlen(psk_key) == 64 ? "":"\"");
			sprintf(buffer[i++], "}\n");
			break;
		case AUTHMODE_WPA:
		case AUTHMODE_WPA2:
			sprintf(buffer[i++], "ctrl_interface=/var/run/wpa_supplicant\n");
			sprintf(buffer[i++], "ap_scan=1\n");
			sprintf(buffer[i++], "network={\n");
			sprintf(buffer[i++], "    ssid=\"%s\"\n", ssid);
			if(0 != *bssid) {
			sprintf(buffer[i++], "    bssid=%s\n", bssid);
			}

			sprintf(buffer[i++], "    scan_ssid=1\n");
			sprintf(buffer[i++], "    key_mgmt=WPA-EAP\n");

			//proto
			if (AUTHMODE_WPA == authmode) {
			sprintf(buffer[i++], "    proto=WPA\n");
			}
			else if (AUTHMODE_WPA2 == authmode) {
			sprintf(buffer[i++], "    proto=RSN\n");
			}

			//cryption
			if (ENCRY_AES == encryp_type) {
			sprintf(buffer[i++], "    pairwise=CCMP\n");
			}
			else if (ENCRY_TKIP == encryp_type) {
			sprintf(buffer[i++], "    pairwise=TKIP\n");
			}

			//EAP mode
			if(EAP_MODE_PEAP == eap_mode) {
				sprintf(buffer[i++], "    eap=PEAP\n");
			}
			else if(EAP_MODE_TTLS == eap_mode) {
				sprintf(buffer[i++], "    eap=TTLS\n");
			}

			sprintf(buffer[i++], "    identity=\"%s\"\n", wpauser);
			sprintf(buffer[i++], "    password=\"%s\"\n", wpapasswd);
			sprintf(buffer[i++], "    phase2=\"auth=MSCHAPV2\"\n");
			sprintf(buffer[i++], "}\n");
			break;

		case AUTHMODE_NONE:
			sprintf(buffer[i++], "ctrl_interface=/var/run/wpa_supplicant\n");
			sprintf(buffer[i++], "ap_scan=1\n");
			sprintf(buffer[i++], "network={\n");
			sprintf(buffer[i++], "    ssid=\"%s\"\n", ssid);
			if(0 != *bssid) {
			sprintf(buffer[i++], "    bssid=%s\n", bssid);
			}

			sprintf(buffer[i++], "    scan_ssid=1\n");
			sprintf(buffer[i++], "    key_mgmt=NONE\n");
			sprintf(buffer[i++], "}\n");
			break;

		case AUTHMODE_WEP:
			sprintf(buffer[i++], "ctrl_interface=/var/run/wpa_supplicant\n");
			sprintf(buffer[i++], "ap_scan=1\n");
			sprintf(buffer[i++], "network={\n");
			sprintf(buffer[i++], "    ssid=\"%s\"\n", ssid);
			if(0 != *bssid) {
			sprintf(buffer[i++], "    bssid=%s\n", bssid);
			}
			sprintf(buffer[i++], "    scan_ssid=1\n");
			sprintf(buffer[i++], "    key_mgmt=NONE\n");
			//group
			if (0==wep_encry) {
			sprintf(buffer[i++], "    group=WEP40\n");
			}
			else if (1==wep_encry) {
			sprintf(buffer[i++], "    group=WEP104\n");
			}

			sprintf(buffer[i++], "    wep_key%d=%s%s%s\n",
				keyidx-1, 
				1==keytype? "\"" : "", 
				key,
				1==keytype? "\"" : "");
			sprintf(buffer[i++], "    wep_tx_keyidx=%d\n", keyidx-1);
			//only for shared
			if (2==encmode) {
			sprintf(buffer[i++], "    auth_alg=SHARED\n");
			}
			sprintf(buffer[i++], "}\n");
			break;

		case AUTHMODE_UNDEFINED:
		case AUTHMODE_WPAPSKWPA2PSK:
		case AUTHMODE_WPAWPA2:
		default :
			fprintf(stderr, "%d@%s error!\r\n", __LINE__, __FUNCTION__);
			return T_FAILURE;
	}

	for(i=0; i<(sizeof(buffer)/sizeof(buffer[0])); i++) {
		memset(buffer_write, 0, sizeof(buffer_write));
		if(0 != *buffer[i]) {
			strcpy(buffer_write, buffer[i]);
		}
		else {
			break;
		}
		printf("buffer_write:%s\n",buffer_write);
		size = fwrite(buffer_write, strlen(buffer_write), 1, fp);
		if (size < 1) 
		{
			fprintf(stderr, "Write %s error\n", cmd);
		}   
	}
	fclose(fp);
	return T_SUCCESS;
}
Exemplo n.º 5
0
/**
 * \brief get AP list according to radio
 * \return T_SUCCESS on success & T_FAILURE on failure
 * \param[in] radio RADIO_2G or RADIO_5G
 * \param[out] ap_list scan AP result list
 * \author andy
 * \date 2014-01
 */
int get_ap_list(int radio, SCAN_AP_LIST *ap_list)
{
	FILE *fp;
	int ret = 0;
	int rMode = 0;
	int apNum = 0;
	int apNTWType = 0;
	int apChannel = 0;
	int apSignal = 0;
	int apEncryption = 0;
	int apAuthmode = 0;
	char cmd[128] = {0};
	char apSsid[64] = {0};
	char vap_name[8] = {0};
	char apWMode[8] = {0};
	char apBssid[32] = {0};
	char ModeTmpBuf[32] = {0};
    char *pBssidList = (char*)malloc(65536 * sizeof (char));
	
	if (RADIO_2G == radio) {
		ezplib_get_attr_val("wl_mode_rule", 0, "mode", ModeTmpBuf, 32, EZPLIB_USE_CLI);
		
		if (!strcmp(ModeTmpBuf, "ap")) {
			rMode = WLAN_MODE_AP;
		}
		else if (!strcmp(ModeTmpBuf, "client")) {
			rMode = WLAN_MODE_STA;
		}
	}
	else if (RADIO_5G == radio) {
		ezplib_get_attr_val("wl1_mode_rule", 0, "mode", ModeTmpBuf, 32, EZPLIB_USE_CLI);
		
		if (!strcmp(ModeTmpBuf, "ap")) {
			rMode = WLAN_MODE_AP;
		}
		else if (!strcmp(ModeTmpBuf, "client")) {
			rMode = WLAN_MODE_STA;
		}
	}
	else {
		fprintf(stderr, "ERROR:Radio error!\n");
        return T_FAILURE;
	}
	
	construct_vap(vap_name, radio, 0, rMode);
	
    /*iwlist staN scanning | awk -f /etc/wl/rogueap.awk*/    
    sprintf(cmd, "iwlist %s scanning | awk -f /etc/wl/rogueap.awk > /tmp/scanrlt", vap_name);
    EXE_COMMAND(cmd);    
    
    /*Set ap_num as 0 first*/
    ap_list->ap_num = 0;
    if (NULL == (fp = fopen("/tmp/scanrlt","r")))
    {
        fprintf(stderr, "Ap list is NONE\n");
        free(pBssidList);
        return T_FAILURE;        
    }
    else
    {
        while(!feof(fp)){
			memset(apBssid, 0x00, sizeof(apBssid));
			memset(apSsid, 0x00, sizeof(apSsid));
			memset(apWMode, 0x00, sizeof(apWMode));

			ret = fscanf(fp, "%d%s%d%d%d%s%d%d%[^\n]", &apNum, apBssid, 
				&apNTWType, &apChannel, &apSignal, apWMode, &apEncryption, &apAuthmode, apSsid);
			if ( 9 != ret) {
				printf("fscanf Number:%d\n", ret);
				printf("fsacnf End\n");
				break;
			}

			memset(ap_list->ap[apNum - 1].ssid, 0x00, sizeof(ap_list->ap[apNum - 1].ssid));
            memset(ap_list->ap[apNum - 1].bssid, 0x00, sizeof(ap_list->ap[apNum - 1].bssid));
			memset(ap_list->ap[apNum - 1].rssi_str, 0x00, sizeof(ap_list->ap[apNum - 1].rssi_str));
			memset(ap_list->ap[apNum - 1].wmode, 0x00, sizeof(ap_list->ap[apNum - 1].wmode));

			/* AP BSSID */
			strcpy(ap_list->ap[apNum - 1].bssid, apBssid);

			/* AP Network Type: 0->Auto; 1->Ad-hoc; 2->Managed; 3->Repeater; 4->Master; 5->Secondary; 6->Monitor; 7->Unknow*/
			if (4 == apNTWType) {
				ap_list->ap[apNum - 1].network_type = 1;
			}
			else {
				ap_list->ap[apNum - 1].network_type = 0;
			}

			/* AP Channel*/
			ap_list->ap[apNum - 1].channel = apChannel;

			/* AP Signal*/
			ap_list->ap[apNum - 1].rssi = - apSignal;
			sprintf(ap_list->ap[apNum - 1].rssi_str, "%d dBm", ap_list->ap[apNum - 1].rssi);
			
			/* AP Wireless Mode*/
			strcpy(ap_list->ap[apNum - 1].wmode, apWMode);

			/* AP Encryption*/
			ap_list->ap[apNum -1].encry = apEncryption;

			/* AP Auth_mode*/
			ap_list->ap[apNum -1].auth_mode = apAuthmode;

			/* AP SSID*/
			strncpy(ap_list->ap[apNum -1].ssid, &apSsid[2], (strlen(apSsid) - 3));

			/* AP Number */
			ap_list->ap_num = apNum;
			if(ap_list->ap_num == 128)
            {
                break;
            }
        }
    }

    free(pBssidList);
    fclose(fp);
#if 1
    sprintf(cmd, "rm -rf /tmp/scanrlt");
	EXE_COMMAND(cmd);
#else
        int ap_num = ap_list->ap_num;
        printf("ap_num after is:%d\n",ap_num);
        int j;
        for(j=0; j< ap_num; j++)
            {
                printf("SSID%d:%s\n",j,ap_list->ap[j].ssid);
                printf("BSSID%d:%s\n",j,ap_list->ap[j].bssid);
                printf("RSSI%d:%d\n",j,ap_list->ap[j].rssi);
                printf("Channel%d:%d\n",j,ap_list->ap[j].channel);
                printf("AuthMode%d:%d\n",j,ap_list->ap[j].auth_mode);
                printf("ENCRY%d:%d\n",j,ap_list->ap[j].encry);
                printf("NET_TYPE%d:%d\n",j,ap_list->ap[j].network_type);
            }
#endif

    return T_SUCCESS;    
}
Exemplo n.º 6
0
/**
 * \brief set Radio radio to STA Mode
 * \return T_SUCCESS on success & T_FAILURE on failure
 * \param[in] radio RADIO_2G or RADIO_5G
 * \author frank
 * \date 2014-02-08
 * \date 2014-02-27 add macro for compile
 */
int set_config_sta(int radio)
{
	char cmd[128] = {0};
	char ifacename[16] = {0};

	if(T_FAILURE == construct_vap(ifacename, radio, 0, WLAN_MODE_STA)) {
		fprintf(stderr, "__%d@%s error\r\n", __LINE__, __FUNCTION__);
		return T_FAILURE;
	}
	/* Down Interface first */
#if 1
        //Modified by Mario Huang,down first and terminate later
        vap_up_down(radio, 0, WLAN_MODE_STA, VAP_DOWN);
	/* use wpa_cli terminate to stop wpa_supplicant */
	sprintf(cmd, "/usr/sbin/wpa_cli -p /var/run/wpa_supplicant -i %s terminate", ifacename);
	EXE_COMMAND(cmd);
#else
	/* use kill `cat pidfile` to stop wpa_supplicant */
    vap_up_down(radio, 0, WLAN_MODE_STA, VAP_DOWN);
	kill_apcli_apd_daemon(radio);
#endif

	/* Power & Wireless Mode */
	//set_power(radio);
	set_sta_assoc_wirelessmode(radio);

    /*Get security mode of station*/
    int secmode = nvram_get_sta_secmode(radio);
	switch(secmode) {
#if 0
		/* USE original iwconfig/iwpriv to config WEP and NONE*/
		case AUTHMODE_NONE:
			sprintf(cmd, "iwconfig %s key off", ifacename);		
			EXE_COMMAND(cmd);
			sprintf(cmd, "iwpriv %s authmode 1", ifacename);		
			EXE_COMMAND(cmd);
			set_sta_assoc_ssid(radio);
			set_sta_assoc_bssid(radio);
			vap_up_down(radio, 0, WLAN_MODE_STA, VAP_UP);
			break;
		case AUTHMODE_WEP:
			sprintf(cmd, "iwconfig %s key off", ifacename);		
			EXE_COMMAND(cmd);
			set_sta_assoc_authWEP(radio);
			set_sta_assoc_ssid(radio);
			set_sta_assoc_bssid(radio);
			vap_up_down(radio, 0, WLAN_MODE_STA, VAP_UP);
			break;
#else
		/* USE wpa_supplicant to config WEP and NONE*/
		case AUTHMODE_NONE:
		case AUTHMODE_WEP:
#endif
		case AUTHMODE_WPAPSK:
		case AUTHMODE_WPA2PSK:
		case AUTHMODE_WPAPSKWPA2PSK:
		case AUTHMODE_WPA:
		case AUTHMODE_WPA2:
		case AUTHMODE_WPAWPA2:
			vap_up_down(radio, 0, WLAN_MODE_STA, VAP_UP);
			create_wpa_supplicant_conf(radio, secmode);
			start_apcli_apd_daemon(radio);
			break;
		case AUTHMODE_UNDEFINED:
			fprintf(stderr, "__%d@%s error\r\n", __LINE__, __FUNCTION__);
			break;
	}
	set_power(radio);

    return T_SUCCESS;
}
Exemplo n.º 7
0
/**
 * \brief set wirelessmode before associatation
 * \return T_SUCCESS on success & T_FAILURE on failure
 * \param[in] radio RADIO_2G or RADIO_5G
 * \author frank
 * \date 2014-01-17
 */
int set_sta_assoc_wirelessmode(int radio)
{
	char cmd[64] = {0};
	char ifacename[16] = {0};
	char htbwBuf[2] = {0};
	char ModeTmpBuf[4] = {0};
	int netmode = 0;

    int ret = construct_vap(ifacename, radio, 0, WLAN_MODE_STA);
    if(T_FAILURE == ret) {
		fprintf(stderr, "__%d@%s error\r\n", __LINE__, __FUNCTION__);
		return T_FAILURE;
	}
	
	if ( RADIO_2G == radio) {
		ezplib_get_attr_val("wl_advanced_rule", 0, "htbw", htbwBuf, 2, EZPLIB_USE_CLI);
		switch(atoi(htbwBuf)) {
			case 0:			//20MHz
				//sprintf(cmd, "iwpriv %s mode 11NGHT20", ifacename);
				sprintf(cmd, "iwpriv %s mode 11NAHT20", ifacename);
				break;
			case 1:			//20/40MHz
				//sprintf(cmd, "iwpriv %s mode 11NGHT40", ifacename);
				sprintf(cmd, "iwpriv %s mode 11NAHT40", ifacename);
				break;		
			default:
				fprintf(stderr, "__%d@%s error\r\n", __LINE__, __FUNCTION__);
				return T_FAILURE;
		}
		EXE_COMMAND(cmd);
	}
	else if (RADIO_5G == radio) {
		ezplib_get_attr_val("wl1_advanced_rule", 0, "htbw", htbwBuf, 2, EZPLIB_USE_CLI);
		ezplib_get_attr_val("wl5g_basic_rule", 0, "net_mode", ModeTmpBuf, 4, EZPLIB_USE_CLI);
		netmode = atoi(ModeTmpBuf);	
		printf("__%d@%s netmode = %d\r\n", __LINE__, __FUNCTION__, netmode);	
		/* 11a/n mode */
		if (8 == netmode) {
			switch(atoi(htbwBuf)) {
				case 0:			//20MHz
					sprintf(cmd, "iwpriv %s mode 11NAHT20", ifacename);
					break;
				case 1:			//20/40MHz
					sprintf(cmd, "iwpriv %s mode 11NAHT40", ifacename);
					break;		
				default:
					fprintf(stderr, "__%d@%s error\r\n", __LINE__, __FUNCTION__);
					return T_FAILURE;
			}
		}
		/* 11ac mode */
		else if (14 == netmode) {
			switch(atoi(htbwBuf)) {
				case 0:			//20MHz
					sprintf(cmd, "iwpriv %s mode 11ACVHT20", ifacename);
					break;
				case 1:			//40MHz
					sprintf(cmd, "iwpriv %s mode 11ACVHT40", ifacename);
					break;		
				case 2:			//80MHz
					sprintf(cmd, "iwpriv %s mode 11ACVHT80", ifacename);
					break;		
				default:
					fprintf(stderr, "__%d@%s error\r\n", __LINE__, __FUNCTION__);
					return T_FAILURE;
			}
		}
		else {
			fprintf(stderr, "__%d@%s error\r\n", __LINE__, __FUNCTION__);
			return T_FAILURE;
		}

		EXE_COMMAND(cmd);
	}
	else {
		fprintf(stderr, "__%d@%s error\r\n", __LINE__, __FUNCTION__);
		return T_FAILURE;
	}
	return T_SUCCESS;
}