diff --git a/feeds/wlan-ap/opensync/src/platform/openwrt/src/lib/target/inc/radio.h b/feeds/wlan-ap/opensync/src/platform/openwrt/src/lib/target/inc/radio.h index 86d6197fe..bd68fdf0c 100644 --- a/feeds/wlan-ap/opensync/src/platform/openwrt/src/lib/target/inc/radio.h +++ b/feeds/wlan-ap/opensync/src/platform/openwrt/src/lib/target/inc/radio.h @@ -26,5 +26,7 @@ extern void radio_maverick(void *arg); int nl80211_channel_get(char *name, unsigned int *chan); void set_config_apply_timeout(ovsdb_update_monitor_t *mon); +bool apc_read_conf(struct schema_APC_Config *apcconf); +bool apc_read_state(struct schema_APC_State *apcst); #endif diff --git a/feeds/wlan-ap/opensync/src/platform/openwrt/src/lib/target/src/radio.c b/feeds/wlan-ap/opensync/src/platform/openwrt/src/lib/target/src/radio.c index 1b4cd6038..b7f0913bb 100755 --- a/feeds/wlan-ap/opensync/src/platform/openwrt/src/lib/target/src/radio.c +++ b/feeds/wlan-ap/opensync/src/platform/openwrt/src/lib/target/src/radio.c @@ -41,7 +41,6 @@ ovsdb_table_t table_Wifi_Inet_Config; ovsdb_table_t table_Node_Config; unsigned int radproxy_apc = 0; -extern json_t* ovsdb_table_where(ovsdb_table_t *table, void *record); static struct uci_package *wireless; struct uci_context *uci; @@ -809,32 +808,105 @@ static const struct blobmsg_policy apc_policy[__APC_ATTR_MAX] = { struct schema_APC_Config apc_conf; -void apc_state_set(struct blob_attr *msg) -{ - struct blob_attr *tb[__APC_ATTR_MAX] = { }; - struct schema_APC_Config apc_conf; - struct schema_APC_State apc_state; - json_t *where; - /* Check if apc conf is disabled, if disabled the update state - * with NC mode and return, this is to avoid the apc ubus - * notifications which come after the APC is disabled */ - where = ovsdb_table_where(&table_APC_Config, &apc_conf); - if (false == ovsdb_table_select_one_where(&table_APC_Config, - where, &apc_conf)) { - LOG(ERR, "%s: APC_State read failed", __func__); - apc_conf.enabled = true; +bool apc_read_conf(struct schema_APC_Config *apcconf) +{ + json_t *jrows; + int cnt = 0; + int i = 0; + pjs_errmsg_t perr; + + jrows = ovsdb_sync_select_where(SCHEMA_TABLE(APC_Config), NULL); + if(!jrows) + { + return false; + } + cnt = json_array_size(jrows); + if(!cnt) + { + json_decref(jrows); + return false; } - if (apc_conf.enabled == false) { + for (i = 0; i < cnt; i++) + { + if(!schema_APC_Config_from_json(apcconf, json_array_get(jrows, i), + false, perr)) + { + LOGE("Unable to parse APC Config column: %s", perr); + json_decref(jrows); + return false; + } + } + json_decref(jrows); + + return true; +} + +bool apc_read_state(struct schema_APC_State *apcst) +{ + json_t *jrows; + int cnt = 0; + int i = 0; + pjs_errmsg_t perr; + + jrows = ovsdb_sync_select_where(SCHEMA_TABLE(APC_State), NULL); + if(!jrows) + { + return false; + } + cnt = json_array_size(jrows); + if(!cnt) + { + json_decref(jrows); + return false; + } + + for (i = 0; i < cnt; i++) + { + if(!schema_APC_State_from_json(apcst, json_array_get(jrows, i), + false, perr)) + { + LOGE("Unable to parse APC State column: %s", perr); + json_decref(jrows); + return false; + } + } + json_decref(jrows); + + return true; +} + +/* Check if apc conf is disabled, if disabled the update state + * with NC mode and return, this is to avoid the apc ubus + * notifications which come after the APC is disabled */ +bool apc_conf_en() +{ + struct schema_APC_Config apcconf; + struct schema_APC_State apc_state; + + if(apc_read_conf(&apcconf) == false) + return true; + + if (apcconf.enabled == false) { SCHEMA_SET_STR(apc_state.mode, "NC"); SCHEMA_SET_STR(apc_state.dr_addr, "0.0.0.0"); SCHEMA_SET_STR(apc_state.bdr_addr, "0.0.0.0"); SCHEMA_SET_INT(apc_state.enabled, false); if (!ovsdb_table_update(&table_APC_State, &apc_state)) LOG(ERR, "APC_state: failed to update"); - return; + return false; } + return true; +} + +void apc_state_set(struct blob_attr *msg) +{ + struct blob_attr *tb[__APC_ATTR_MAX] = { }; + struct schema_APC_State apc_state; + + if(apc_conf_en() == false) + return; blobmsg_parse(apc_policy, __APC_ATTR_MAX, tb, blob_data(msg), blob_len(msg)); @@ -879,13 +951,10 @@ static int conn_since = 0; static void apc_enable(bool flag) { struct schema_APC_State apc_state; - json_t *where; LOGI("APC %s: %s APC", __func__, flag?"enable":"disable"); if (flag == false) { - where = ovsdb_table_where(&table_APC_State, &apc_state); - if (false == ovsdb_table_select_one_where(&table_APC_State, - where, &apc_state)) { + if(apc_read_state(&apc_state) == false) { LOG(ERR, "%s: APC_State read failed", __func__); apc_state.enabled = true; } @@ -918,18 +987,14 @@ apc_cld_mon_cb(struct schema_Manager *mgr) int i = 0; conn_since = 0; struct schema_APC_State apc_state; - json_t *where; int ret = 0; int link = 1; - where = ovsdb_table_where(&table_APC_State, &apc_state); - if (false == ovsdb_table_select_one_where(&table_APC_State, - where, &apc_state)) { + if(apc_read_state(&apc_state) == false) { LOG(ERR, "%s: APC_State read failed", __func__); return; } - /*Checks if wan ethernet port is down and disables apc*/ ret = system("/bin/check_wan_link.sh"); if (WIFEXITED(ret)) { diff --git a/feeds/wlan-ap/opensync/src/platform/openwrt/src/lib/target/src/radius_proxy.c b/feeds/wlan-ap/opensync/src/platform/openwrt/src/lib/target/src/radius_proxy.c index 02119648a..b70f3b724 100644 --- a/feeds/wlan-ap/opensync/src/platform/openwrt/src/lib/target/src/radius_proxy.c +++ b/feeds/wlan-ap/opensync/src/platform/openwrt/src/lib/target/src/radius_proxy.c @@ -222,14 +222,6 @@ static bool radius_proxy_config_set(struct schema_Radius_Proxy_Config *conf) char server_name[256] = {}; char acct_server_name[256] = {}; char tls_name[256] = {}; - struct schema_APC_State apc_conf; - - json_t *where = ovsdb_table_where(&table_APC_State, &apc_conf); - if (false == ovsdb_table_select_one_where(&table_APC_State, - where, &apc_conf)) { - LOG(INFO, "APC_State read failed"); - return false; - } /* Configure options block */ blob_buf_init(&uci_buf, 0); diff --git a/feeds/wlan-ap/opensync/src/platform/openwrt/src/lib/target/src/vif.c b/feeds/wlan-ap/opensync/src/platform/openwrt/src/lib/target/src/vif.c index 6b3444d68..6e4cf9a51 100755 --- a/feeds/wlan-ap/opensync/src/platform/openwrt/src/lib/target/src/vif.c +++ b/feeds/wlan-ap/opensync/src/platform/openwrt/src/lib/target/src/vif.c @@ -329,7 +329,6 @@ static struct vif_crypto { }; extern ovsdb_table_t table_APC_State; -extern json_t* ovsdb_table_where(ovsdb_table_t *table, void *record); extern unsigned int radproxy_apc; /* Custom options table */ @@ -417,12 +416,12 @@ static int vif_config_security_set(struct blob_buf *b, if (vif_config_custom_opt_get_proxy(vconf)) { /* Radius Proxy Enabled */ LOGN("%s: Apply Proxy Security Settings", vconf->if_name); - json_t *where = ovsdb_table_where(&table_APC_State, &apc_conf); - if (false == ovsdb_table_select_one_where(&table_APC_State, - where, &apc_conf)) { - LOG(INFO, "APC_State read failed"); + if(apc_read_state(&apc_conf) == false) + { + LOGI("APC_State read failed"); return -1; } + if (!strncmp(apc_conf.mode, "DR", 2)) { auth_server = local_server; acct_server = local_server; @@ -1065,8 +1064,7 @@ void vif_check_radius_proxy() int n = 0; void *buf = NULL; - json_t *where = ovsdb_table_where(&table_APC_State, &apc_conf); - if (false == ovsdb_table_select_one_where(&table_APC_State, where, &apc_conf)) + if(apc_read_state(&apc_conf) == false) { LOGI("APC_State read failed"); return;