//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; }
//Get NVRAM WLAN Mode int nvram_get_wlan_mode(int radio, int *wlan_mode) { char buf[NVRAM_BUF_LEN] = { 0 }; if(RADIO_2G == radio) { ezplib_get_attr_val("wl_mode_rule", 0, "mode", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } else if(RADIO_5G == radio) { ezplib_get_attr_val("wl1_mode_rule", 0, "mode", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } if(!strcmp(buf, "ap") || !strcmp(buf, "normal")) { *wlan_mode = WLAN_MODE_AP; } else if(!strcmp(buf, "client") || !strcmp(buf, "ur")) { *wlan_mode = WLAN_MODE_STA; } else { MID_ERROR("Operation mode got from NVRAM is illegal!!!"); return T_FAILURE; } return T_SUCCESS; }
/** * \brief Get NVRAM authentication mode * \return EAP_MODE NONE|TTLS|PEAP * \param[in] radio RADIO_2G or RADIO_5G * \author frank * \date 2014-01-24 */ int nvram_get_sta_eap_mode(int radio) { char buf[32] = {0}; /*Get the Radio*/ if(RADIO_2G == radio) { ezplib_get_attr_val("wl0_wpa_auth_rule", 0, "wpa_auth", buf, 32, EZPLIB_USE_CLI); } else if(RADIO_5G == radio) { ezplib_get_attr_val("wl1_wpa_auth_rule", 0, "wpa_auth", buf, 32, EZPLIB_USE_CLI); } else { fprintf(stderr, "%d@%s error!\r\n", __LINE__, __FUNCTION__); return T_FAILURE; } if (!strcmp(buf, "1")) { return EAP_MODE_PEAP; } else if (!strcmp(buf, "0")){ return EAP_MODE_TTLS; } return EAP_MODE_NONE; }
int nvram_get_security_encryptype(int radio, int vap_id, int *encryp_type) { char buf[TMP_LEN]; char crypto_s[TMP_LEN]; /*Get the Radio*/ if(RADIO_2G == radio) { ezplib_get_attr_val("wl0_sec_wpa2_rule", vap_id, "crypto", buf, TMP_LEN, EZPLIB_USE_CLI); } else if(RADIO_5G == radio) { ezplib_get_attr_val("wl1_sec_wpa2_rule", vap_id, "crypto", buf, TMP_LEN, EZPLIB_USE_CLI); } strcpy(crypto_s, buf); if(!strcmp(crypto_s, "aes")) { *encryp_type = ENCRY_AES; } else if(!strcmp(crypto_s, "tkip")) { *encryp_type = ENCRY_TKIP; } else { *encryp_type = ENCRY_TKIPAES; } return T_SUCCESS; }
/*Get NVRAM rekey mode*/ int nvram_get_ap_rekey_mode(int radio, int vap_id, int *rekey_mode) { char buf[NVRAM_BUF_LEN]; char rekeymode_s[NVRAM_BUF_LEN]; /*Get the Radio*/ if(RADIO_2G == radio) { ezplib_get_attr_val("wl0_sec_wpa2_rule", vap_id, "rekey_mode", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } else if(RADIO_5G == radio) { ezplib_get_attr_val("wl1_sec_wpa2_rule", vap_id, "rekey_mode", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } strcpy(rekeymode_s, buf); if(!strcmp(rekeymode_s, "time")) { *rekey_mode = REKEY_MODE_TIME; } else if(!strcmp(rekeymode_s, "pkt")) { *rekey_mode = REKEY_MODE_PKT; } else { *rekey_mode = REKEY_MODE_DISABLE; } return T_SUCCESS; }
int nvram_get_ap_rekey_packet_interval(int radio, int vap_id, int *interval) { char buf[NVRAM_BUF_LEN]; int rekey_mode; int ret; /*Get rekey method first*/ ret = nvram_get_ap_rekey_mode(radio, vap_id, &rekey_mode); if(T_FAILURE == ret) { printf("ERRO:Get rekey method failure!\n"); return T_FAILURE; } MID_ASSERT((REKEY_MODE_PKT == rekey_mode), "Rekey mode is not pkt"); /*Get the Radio according to rekey method*/ if(RADIO_2G == radio) { ezplib_get_attr_val("wl0_sec_wpa2_rule", vap_id, "rekey_pkt_interval", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } else if(RADIO_5G == radio) { ezplib_get_attr_val("wl1_sec_wpa2_rule", vap_id, "rekey_pkt_interval", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } *interval = atoi(buf); return T_SUCCESS; }
/** * \brief Get NVRAM Security Mode for STA mode * \return Auth Mode * \param[in] radio RADIO_2G or RADIO_5G * \author frank * \date 2014-01-24 */ int nvram_get_sta_secmode(int radio) { char secmode_s[32] = {0}; if(RADIO_2G == radio) { ezplib_get_attr_val("wl0_apcli_rule", 0, "secmode", secmode_s, 32, EZPLIB_USE_CLI); } else if(RADIO_5G == radio) { ezplib_get_attr_val("wl1_apcli_rule", 0, "secmode", secmode_s, 32, EZPLIB_USE_CLI); } else { return AUTHMODE_UNDEFINED; } if(!strcmp(secmode_s, "wep")) { return AUTHMODE_WEP; } else if(!strcmp(secmode_s, "wpa")) { return AUTHMODE_WPA; } else if(!strcmp(secmode_s, "wpa2")) { return AUTHMODE_WPA2; } else if(!strcmp(secmode_s, "psk")) { return AUTHMODE_WPAPSK; } else if(!strcmp(secmode_s, "psk2")) { return AUTHMODE_WPA2PSK; } else if(!strcmp(secmode_s, "disabled")) { return AUTHMODE_NONE; } return AUTHMODE_UNDEFINED; }
/** * \brief get WEP related stuff for STA mode * \return T_SUCCESS on success & T_FAILURE on failure * \param[in] radio RADIO_2G or RADIO_5G * \param[out] key WEP key, special chars is processed * \param[out] key_idx 1~4 * \param[out] key_type 0:HEX, 1:ASCII * \param[out] key_encmode "open" or "shared" * \param[out] wep_encry 0:64bits, 1:128bits * \author frank * \date 2014-01-20 */ int nvram_get_sta_wep(int radio, char *key, int *key_idx, int *key_type, char *key_encmode, int*wep_encry) { assert(key != NULL); assert(key_idx != NULL); assert(key_type != NULL); assert(key_encmode != NULL); char buf[27] = {0}; //max length is 2 * ASCII 13 + 1 char wep_tx_keyidx[8] = {0}; char wep_keytype[2] = {0}; char wep_encmode[16] = {0}; // "open", "shared" char encry[2] = {0}; int keyidx = 0; /*Get key from NVRAM*/ if(RADIO_2G == radio) { ezplib_get_attr_val("wl0_apcli_sec_wep_rule", 0, "key_index", wep_tx_keyidx, 8, EZPLIB_USE_CLI); keyidx = atoi(wep_tx_keyidx); sprintf(wep_tx_keyidx, "key%d", keyidx); ezplib_get_attr_val("wl0_apcli_sec_wep_rule", 0, wep_tx_keyidx, buf, 27, EZPLIB_USE_CLI); ezplib_get_attr_val("wl0_apcli_sec_wep_rule", 0, "keytype", wep_keytype, 2, EZPLIB_USE_CLI); ezplib_get_attr_val("wl0_apcli_sec_wep_rule", 0, "encmode", wep_encmode, 16, EZPLIB_USE_CLI); ezplib_get_attr_val("wl0_apcli_sec_wep_rule", 0, "wep_encry", encry, 2, EZPLIB_USE_CLI); } else if (RADIO_5G == radio) { ezplib_get_attr_val("wl1_apcli_sec_wep_rule", 0, "key_index", wep_tx_keyidx, 8, EZPLIB_USE_CLI); keyidx = atoi(wep_tx_keyidx); sprintf(wep_tx_keyidx, "key%d", keyidx); ezplib_get_attr_val("wl1_apcli_sec_wep_rule", 0, wep_tx_keyidx, buf, 27, EZPLIB_USE_CLI); ezplib_get_attr_val("wl1_apcli_sec_wep_rule", 0, "keytype", wep_keytype, 2, EZPLIB_USE_CLI); ezplib_get_attr_val("wl1_apcli_sec_wep_rule", 0, "encmode", wep_encmode, 16, EZPLIB_USE_CLI); ezplib_get_attr_val("wl1_apcli_sec_wep_rule", 0, "wep_encry", encry, 2, EZPLIB_USE_CLI); } else { fprintf(stderr, "__%d@%s error\r\n", __LINE__, __FUNCTION__); return T_FAILURE; } strcpy(key_encmode, wep_encmode); *key_type = atoi(wep_keytype); *key_idx = keyidx; *wep_encry = atoi(encry); strcpy(key, buf); #if 0 int i, j; for(i=0,j=0;j<strlen(buf);i++,j++) { if( '\"' == buf[j] || '`' == buf[j] || '\\' == buf[j]) { key[i] = '\\'; i++; } key[i] = buf[j]; } #endif return T_SUCCESS; }
/*Get NVRAM security mode*/ int nvram_get_ap_secmode(int radio, int vap_id, int *secmode) { char buf[NVRAM_BUF_LEN] = { 0 }; /*Get the Radio*/ if(RADIO_2G == radio) { ezplib_get_attr_val("wl0_sec_rule", vap_id, "secmode", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } else if(RADIO_5G == radio) { ezplib_get_attr_val("wl1_sec_rule", vap_id, "secmode", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } if(!strcmp(buf, "disabled")) { *secmode = AUTHMODE_NONE; } else if(!strcmp(buf, "wep")) { *secmode = AUTHMODE_WEP; } else if(!strcmp(buf, "psk")) { *secmode = AUTHMODE_WPAPSK; } else if(!strcmp(buf, "psk2")) { *secmode = AUTHMODE_WPA2PSK; } else if(!strcmp(buf, "psk2mixed")) { *secmode = AUTHMODE_WPAPSKWPA2PSK; } else if(!strcmp(buf, "wpa")) { *secmode = AUTHMODE_WPA; } else if(!strcmp(buf, "wpa2")) { *secmode = AUTHMODE_WPA2; } else if(!strcmp(buf, "wpa2mixed")) { *secmode = AUTHMODE_WPAWPA2; } else { MID_ERROR("Illegal authentication mode got from NVRAM"); return T_FAILURE; } return T_SUCCESS; }
/*Get NVRAM Address Mode*/ int nvram_get_sta_addrmode(int radio, int *addr_mode) { char buf[NVRAM_BUF_LEN] = {0}; if(RADIO_2G == radio) { ezplib_get_attr_val("wl0_apcli_rule", 0, "addrmode", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } else { ezplib_get_attr_val("wl1_apcli_rule", 0, "addrmode", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } *addr_mode = atoi(buf); return T_SUCCESS; }
//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; }
/** * \brief Get NVRAM STA KEY * \param[in] radio RADIO_2G or RADIO_5G * \param[out] key Pre-Shared Key (Personal Edition) * \author frank * \date 2014-01-24 */ int nvram_get_sta_psk(int radio, char *key) { assert(NULL != key); char buf[NVRAM_PSK_LEN] = {0}; int secmode = nvram_get_sta_secmode(radio); if (RADIO_2G == radio) { switch(secmode) { case AUTHMODE_WPAPSK: ezplib_get_attr_val("wl0_apcli_sec_wpa_rule", 0, "key", buf, NVRAM_PSK_LEN, EZPLIB_USE_CLI); break; case AUTHMODE_WPA2PSK: ezplib_get_attr_val("wl0_apcli_sec_wpa2_rule", 0, "key", buf, NVRAM_PSK_LEN, EZPLIB_USE_CLI); break; default: fprintf(stderr, "%d@%s" " psk is unnecessary for current secmode!\r\n" , __LINE__, __FUNCTION__); return T_FAILURE; } } else if (RADIO_5G == radio) { switch(secmode) { case AUTHMODE_WPAPSK: ezplib_get_attr_val("wl1_apcli_sec_wpa_rule", 0, "key", buf, NVRAM_PSK_LEN, EZPLIB_USE_CLI); break; case AUTHMODE_WPA2PSK: ezplib_get_attr_val("wl1_apcli_sec_wpa2_rule", 0, "key", buf, NVRAM_PSK_LEN, EZPLIB_USE_CLI); break; default: fprintf(stderr, "%d@%s" " psk is unnecessary for current secmode!\r\n" , __LINE__, __FUNCTION__); return T_FAILURE; } } else { fprintf(stderr, "%d@%s error!\r\n", __LINE__, __FUNCTION__); return T_FAILURE; } strcpy(key, buf); return T_SUCCESS; }
//Get NVRAM Hidden int nvram_get_ap_hidden(int radio, int *hidden, int vap_id) { char buf[NVRAM_BUF_LEN] = { 0 }; /*Get the hidden value from NVRAM first*/ if(RADIO_2G == radio) { ezplib_get_attr_val("wl0_basic_rule", vap_id, "hidden", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } else if(RADIO_5G == radio) { ezplib_get_attr_val("wl1_basic_rule", vap_id, "hidden", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } *hidden = atoi(buf); MID_ASSERT((*hidden == HIDE_SSID_ENABLE || *hidden == HIDE_SSID_DISABLE), "AP hidden got from NVRAM is illegal"); return T_SUCCESS; }
/** * \brief Set STA SSID * \return T_SUCCESS on success & T_FAILURE on failure * \param[in] radio RADIO_2G or RADIO_5G * \author frank * \date 2014-01-20 */ int set_sta_assoc_ssid(int radio) { char ssid[128] = {0}; char cmd[256] = {0}; char TempBuf_opmode[8] = {0}; char ifacename[16] = {0}; ezplib_get_attr_val("system_mode", 0, "name", TempBuf_opmode, 32, EZPLIB_USE_CLI); if(!strstr(TempBuf_opmode, "sta") && !strstr(TempBuf_opmode, "wisp")) { fprintf(stderr, "%d@%s unsupported mode error!\r\n", __LINE__, __FUNCTION__); return T_FAILURE; } if(T_FAILURE == construct_vap(ifacename, radio, 0, WLAN_MODE_STA)) { fprintf(stderr, "%d@%s unsupported mode error!\r\n", __LINE__, __FUNCTION__); return T_FAILURE; } /*Get STA SSID From NVRAM*/ nvram_get_sta_ssid(radio, ssid, 1); sprintf(cmd, "iwconfig %s essid \"%s\" ", ifacename, ssid); EXE_COMMAND(cmd); return T_SUCCESS; }
/*Get NVRAM radius port*/ int nvram_get_ap_radius_port(int radio, int vap_id, int *port) { char buf[NVRAM_BUF_LEN]; /*Get the Radio*/ if(RADIO_2G == radio) { ezplib_get_attr_val("wl0_sec_wpa2_rule", vap_id, "radius_port", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } else if(RADIO_5G == radio) { ezplib_get_attr_val("wl1_sec_wpa2_rule", vap_id, "radius_port", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } *port = atoi(buf); return T_SUCCESS; }
int nvram_get_vap_status(int radio, int vap_id, int *vap_status) { char buf[NVRAM_BUF_LEN] = { 0 }; /*Set VAP enable or disable*/ if(RADIO_2G == radio) { ezplib_get_attr_val("wl_ap_basic_rule", 0, "enable", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); if(!strcmp(buf, "0")) { *vap_status = VAP_DISABLE; return T_SUCCESS; } ezplib_get_attr_val("wl0_basic_rule", vap_id, "enable", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } else if(RADIO_5G == radio) { ezplib_get_attr_val("wl5g_ap_basic_rule", 0, "enable", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); if(!strcmp(buf, "0")) { *vap_status = VAP_DISABLE; return T_SUCCESS; } ezplib_get_attr_val("wl1_basic_rule", vap_id, "enable", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } if(!strcmp(buf, "1")) { *vap_status = VAP_ENABLE; } else if(!strcmp(buf, "0")) { *vap_status = VAP_DISABLE; } else { MID_ERROR("VAP status got from NVRAM illegal"); return T_FAILURE; } return T_SUCCESS; }
/** * \brief get RSSI from the associated AP * \return T_SUCCESS on successfully get BSSID, T_FAILURE on failure * \param[in] radio RADIO_2G or RADIO_5G * \param[out] rssi the result RSSI * \author frank * \date 2014-01-07 */ int get_sta_assoc_rssi(int radio, char *rssi) { char TempBuf_opmode[8] = {0}; char ifacename[16] = {0}; ezplib_get_attr_val("system_mode", 0, "name", TempBuf_opmode, 32, EZPLIB_USE_CLI); if(!strstr(TempBuf_opmode, "sta") && !strstr(TempBuf_opmode, "wisp")) { fprintf(stderr, "%d@%s unsupported mode error!\r\n", __LINE__, __FUNCTION__); return T_FAILURE; } int ret = construct_vap(ifacename, radio, 0, WLAN_MODE_STA); if(T_FAILURE == ret) { return ret; } int num = 0; int rssiV = 0; char rssiStr[8] = {0}; char cmd[256] = {0}; //Chged by Andy Yu in 20140224: Assocapinfo Information Format Chged sprintf(cmd, "wlanconfig %s list assocapinfo " "| awk '/Chain/{gsub(\"dBm\",\"\"); print substr($0,13)}' > /tmp/rssi.dat", ifacename); //EXE_COMMAND(cmd); system(cmd); FILE *fp; if (NULL == (fp = fopen("/tmp/rssi.dat", "r"))) { return T_FAILURE; } else { assert(NULL!=rssi); while(!feof(fp)) { if(EOF == fscanf(fp, "%d", &rssiV)) { //printf("Get RSSI End\n"); break; } sprintf(rssiStr, "%d", rssiV); if(num!=0) { strcat(rssi, "/"); } strcat(rssi, rssiStr); num++; } if(strcmp(rssi, "")) { strcat(rssi, " dBm"); } } fclose(fp); //EXE_COMMAND("rm -fr /tmp/rssi.dat"); system("rm -fr /tmp/rssi.dat"); return T_SUCCESS; }
/*Get NVRAM radius ip addr*/ int nvram_get_ap_radius_ipaddr(int radio, int vap_id, char *server) { char buf[NVRAM_BUF_LEN]; /*Get the Radio*/ if(RADIO_2G == radio) { ezplib_get_attr_val("wl0_sec_wpa2_rule", vap_id, "radius_ipaddr", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } else if(RADIO_5G == radio) { ezplib_get_attr_val("wl1_sec_wpa2_rule", vap_id, "radius_ipaddr", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } strcpy(server, buf); //MID_ASSERT(/*Make sure the format is IP address format*/); return T_SUCCESS; }
//int nvram_get_ap_passphrase(int radio, int vap_id, char *key, int key_len) int nvram_get_ap_passphrase(int radio, int vap_id, char *key) { char buf[NVRAM_PSK_LEN]; /*Get the Radio*/ if(RADIO_2G == radio) { ezplib_get_attr_val("wl0_sec_wpa2_rule", vap_id, "key", buf, NVRAM_PSK_LEN, EZPLIB_USE_CLI); } else if(RADIO_5G == radio) { ezplib_get_attr_val("wl1_sec_wpa2_rule", vap_id, "key", buf, NVRAM_PSK_LEN, EZPLIB_USE_CLI); } strcpy(key, buf); return T_SUCCESS; }
//Get NVRAM Channel index int nvram_get_ap_channel(int radio, int *channel) { //Get WLAN mode first char buf[NVRAM_BUF_LEN] = { 0 }; if(RADIO_2G == radio) { ezplib_get_attr_val("wl_ap_basic_rule", 0, "channel", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } else if(RADIO_5G == radio) { ezplib_get_attr_val("wl5g_ap_basic_rule", 0, "channel", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } *channel = atoi(buf); //MID_ASSERT(/*Make sure the channel number is within the llegal scale*/); return T_SUCCESS; }
//Get NVRAM Extension Channel int nvram_get_ap_ext_channel_mode(int radio, int *extcha) { //Get WLAN mode first char buf[NVRAM_BUF_LEN] = { 0 }; if(RADIO_2G == radio) { ezplib_get_attr_val("wl_ap_advanced_rule", 0, "extcha", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } else if(RADIO_5G == radio) { ezplib_get_attr_val("wl1_ap_advanced_rule", 0, "extcha", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } *extcha = atoi(buf); MID_ASSERT((EXT_CHANNEL_ABOVE == *extcha || EXT_CHANNEL_BELOW == *extcha), "Extension channel got from NVRAM is illegal"); return T_SUCCESS; }
//Get NVRAM BSS Isolation int nvram_get_ap_bss_isolation(int radio, int vap_id, int *bss_isolation) { char buf[NVRAM_BUF_LEN] = { 0 }; /*Get bss isolation of current SSID from NVRAM*/ if(RADIO_2G == radio) { ezplib_get_attr_val("wl0_basic_rule", vap_id, "isolation", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } else if(RADIO_5G == radio) { ezplib_get_attr_val("wl1_basic_rule", vap_id, "isolation", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } *bss_isolation = atoi(buf); MID_ASSERT((BSS_ISOLATION_ENABLE == *bss_isolation || BSS_ISOLATION_DISABLE == *bss_isolation), "BSS isolation got from NVRAM is illegal"); return T_SUCCESS; }
static int OpenRaCfgSocket(void) { struct ifreq ethreq; struct ifreq ifr; struct sockaddr_ll addr; struct in_addr own_ip_addr; #if defined CONFIG_RAETH_ROUTER || defined CONFIG_MAC_TO_MAC_MODE || defined CONFIG_RT_3052_ESW char *opmode; #endif //if ((sock=socket(PF_PACKET, SOCK_RAW, htons(ETH_P_RACFG)))<0) if ((sock=socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)))<0) // for testing { perror("socket"); return -1; } memset(&ifr, 0, sizeof(ifr)); memcpy(ifr.ifr_name, "eth2" , 5); #ifdef EZP_PROD_BRAND_ABOCOM ezplib_get_attr_val("wl_mode_rule", 0, "mode", opmode, sizeof(opmode), EZPLIB_USE_CLI); if (opmode != NULL && !strcmp(opmode, "normal")) { // gateway mode memcpy(ifr.ifr_name, "vlan1" , 6); } #else memcpy(ifr.ifr_name, "vlan1" , 6); #endif if (ioctl(sock, SIOCGIFINDEX, &ifr) != 0) { perror("ioctl(SIOCGIFINDEX)(eth_sock)"); goto close; } memset(&addr, 0, sizeof(addr)); addr.sll_family = AF_PACKET; addr.sll_ifindex = ifr.ifr_ifindex; if_index = ifr.ifr_ifindex; if (bind(sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) { perror("bind"); goto close; } if (ioctl(sock, SIOCGIFHWADDR, &ifr) != 0) { perror("ioctl(SIOCGIFHWADDR)(eth_sock)"); goto close; } memcpy(my_eth_addr, ifr.ifr_hwaddr.sa_data, 6); return 0; close: close(sock); sock = -1; return (-1); }
/*Get NVRAM radius key*/ int nvram_get_ap_radius_key(int radio, int vap_id, char *key) { char buf[NVRAM_8021X_PWD_LEN]; /*Get the Radio*/ if(RADIO_2G == radio) { ezplib_get_attr_val("wl0_sec_wpa2_rule", vap_id, "radius_key", buf, NVRAM_8021X_PWD_LEN, EZPLIB_USE_CLI); } else if(RADIO_5G == radio) { ezplib_get_attr_val("wl1_sec_wpa2_rule", vap_id, "radius_key", buf, NVRAM_8021X_PWD_LEN, EZPLIB_USE_CLI); } strcpy(key, buf); //Process special characters return T_SUCCESS; }
//Get NVRAM BCN int nvram_get_ap_beacon_interval(int radio, int *bcn) { //Get WLAN mode first char buf[NVRAM_BUF_LEN] = { 0 }; if(RADIO_2G == radio) { ezplib_get_attr_val("wl_ap_advanced_rule", 0, "bcn", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } else if(RADIO_5G == radio) { ezplib_get_attr_val("wl1_ap_advanced_rule", 0, "bcn", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } *bcn = atoi(buf); //MID_ASSERT(/*Make sure interval is in the llegal scale*/); return T_SUCCESS; }
/*Set STA Repeater*/ int set_sta_mac_repeater(int radio) { char buf_addrmode[32]; char buf_repeater[32]; int addrmode; int mac_repeater; char mac_repeater_s[32]; char addrmode_s[32]; char cmd[128]; char TempBuf_opmode[32]; if(!strcmp(TempBuf_opmode, "wisp0")) { fprintf(stderr, "MAC Repeater setting is not needed in WISP Mode,disable it.\n"); sprintf(cmd, "iwpriv apclii0 set MACRepeaterEn=0"); EXE_COMMAND(cmd); return T_SUCCESS; } /*Get Addr Mode*/ ezplib_get_attr_val("wl0_apcli_rule", 0, "addrmode", buf_addrmode, 32, EZPLIB_USE_CLI); /*Get STA Channel From NVRAM*/ strcpy(addrmode_s, buf_addrmode); addrmode = atoi(addrmode_s); /*Get MAC Repeater*/ ezplib_get_attr_val("wl0_apcli_rule", 0, "macrepeater", buf_repeater, 32, EZPLIB_USE_CLI); /*Get STA Channel From NVRAM*/ strcpy(mac_repeater_s, buf_repeater); mac_repeater = atoi(mac_repeater_s); if(0 == addrmode) { if(1 == mac_repeater) { sprintf(cmd, "iwpriv apclii0 set MACRepeaterEn=%d", MAC_REPEATER_ENABLE); } else { sprintf(cmd, "iwpriv apclii0 set MACRepeaterEn=%d", MAC_REPEATER_DISABLE); } } else { sprintf(cmd, "iwpriv apclii0 set MACRepeaterEn=%d", MAC_REPEATER_DISABLE); } EXE_COMMAND(cmd); return T_SUCCESS; }
/*Get NVRAM MAC Repeater*/ int nvram_get_sta_mac_repeater(int radio, int *mac_repeater) { char buf[NVRAM_BUF_LEN]; /*Get MAC Repeater*/ if(RADIO_2G == radio) { ezplib_get_attr_val("wl0_apcli_rule", 0, "macrepeater", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } else { ezplib_get_attr_val("wl1_apcli_rule", 0, "macrepeater", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } /*Get STA Channel From NVRAM*/ *mac_repeater = atoi(buf); MID_ASSERT((MAC_REPEATER_ENABLE == *mac_repeater || MAC_REPEATER_DISABLE == *mac_repeater), "MAC repeater got from NVRAM illegal"); return T_SUCCESS; }
/** * \brief get selected WEP keyid * \return the keyid [1~4] * \param[in] radio RADIO_2G or RADIO_5G * \author frank * \date 2014-01-20 */ int nvram_get_sta_wep_default_keyid(int radio) { char wep_tx_keyidx[8] = {0}; int keyidx = 0; //1~4 /*Get key id from NVRAM */ if(RADIO_2G == radio) { ezplib_get_attr_val("wl0_apcli_sec_wep_rule", 0, "key_index", wep_tx_keyidx, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } else if (RADIO_5G == radio) { ezplib_get_attr_val("wl1_apcli_sec_wep_rule", 0, "key_index", wep_tx_keyidx, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } else { fprintf(stderr, "__%d@%s error\r\n", __LINE__, __FUNCTION__); assert(radio == RADIO_2G || radio == RADIO_5G); } keyidx = atoi(wep_tx_keyidx); return keyidx; }
//Get NVRAM DTIM int nvram_get_ap_dtim(int radio, int *dtim) { //Get WLAN mode first char buf[NVRAM_BUF_LEN] = { 0 }; if(RADIO_2G == radio) { ezplib_get_attr_val("wl_ap_advanced_rule", 0, "dtim", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } else if(RADIO_5G == radio) { ezplib_get_attr_val("wl1_ap_advanced_rule", 0, "dtim", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); } *dtim = atoi(buf); //MID_ASSERT(/*Make sure dtim is within llegal scale*/); return T_SUCCESS; }
//Get NVRAM AP Isolation int nvram_get_ap_isolation(int radio, int *ap_isolation) { //Get WLAN mode first char buf[NVRAM_BUF_LEN] = { 0 }; if(RADIO_2G == radio) { ezplib_get_attr_val("wl_ap_basic_rule",0,"bisolation",buf,NVRAM_BUF_LEN,EZPLIB_USE_CLI); } else if(RADIO_5G == radio) { ezplib_get_attr_val("wl5g_ap_basic_rule",0,"bisolation",buf,NVRAM_BUF_LEN,EZPLIB_USE_CLI); } *ap_isolation = atoi(buf); MID_ASSERT((AP_ISOLATION_ENABLE == *ap_isolation || AP_ISOLATION_DISABLE == *ap_isolation), "AP isoaltion got from NVRAM is illegal"); return T_SUCCESS; }