//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; }
//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 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 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; }
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; }
/*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{
//Get NVRAM System Mode int nvram_get_system_mode(int *opmode) { char buf[NVRAM_BUF_LEN] = { 0 }; ezplib_get_attr_val("system_mode", 0, "name", buf, NVRAM_BUF_LEN, EZPLIB_USE_CLI); if(!strcmp(buf, "ap")) { *opmode = OP_MODE_AP; } else if(!strcmp(buf, "normal")) { *opmode = OP_MODE_NORMAL; } else if(!strcmp(buf, "ur")) { *opmode = OP_MODE_UR; } else if(!strcmp(buf, "wisp0")) { *opmode = OP_MODE_WISP0; } else if(!strcmp(buf, "wisp1")) { *opmode = OP_MODE_WISP1; } else if(!strcmp(buf, "sta0")) { *opmode = OP_MODE_STA0; } else if(!strcmp(buf, "sta1")) { *opmode = OP_MODE_STA1; } else { MID_ERROR("Operation mode got from NVRAM is illegal!!!"); return T_FAILURE; } return T_SUCCESS; }
//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; }