From c4d65b917a23bdc415b804639f095860a842d227 Mon Sep 17 00:00:00 2001 From: Omar Kallel Date: Mon, 23 Mar 2020 18:13:39 +0100 Subject: [PATCH] Get value of WiFi.AccessPoint.Status WiFi.Radio.OperatingStandards from ubus --- dmtree/tr181/os.h | 2 ++ dmtree/tr181/wifi-iopsyswrt.c | 53 +++++++++++++++++++++++++++++++++++ dmtree/tr181/wifi.c | 37 +++--------------------- 3 files changed, 59 insertions(+), 33 deletions(-) diff --git a/dmtree/tr181/os.h b/dmtree/tr181/os.h index 99448d4b..55a9fd6f 100644 --- a/dmtree/tr181/os.h +++ b/dmtree/tr181/os.h @@ -100,6 +100,8 @@ int os__browse_wifi_associated_device(struct dmctx *dmctx, DMNODE *parent_node, char * os__get_radio_frequency_nocache(const struct wifi_radio_args *args); char * os__get_radio_channel_nocache(const struct wifi_radio_args *args); void os__wifi_start_scan(const char *radio); +int os_get_wifi_access_point_status (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int os_get_radio_operating_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); /* IOPSYS-WRT only */ diff --git a/dmtree/tr181/wifi-iopsyswrt.c b/dmtree/tr181/wifi-iopsyswrt.c index a83710c7..38a7071a 100644 --- a/dmtree/tr181/wifi-iopsyswrt.c +++ b/dmtree/tr181/wifi-iopsyswrt.c @@ -265,6 +265,28 @@ int os__get_access_point_associative_device_statistics_retrans_count(char *refpa return 0; } + +/*#Device.WiFi.AccessPoint.{i}.Status!UBUS:wifi.ap.@Name/status//status*/ +int os_get_wifi_access_point_status (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + char object[32], *status = NULL, *iface; + + dmuci_get_value_by_section_string(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "device", &iface); + snprintf(object, sizeof(object), "wifi.ap.%s", iface); + dmubus_call(object, "status", UBUS_ARGS{}, 0, &res); + + DM_ASSERT(res, status = ""); + status = dmjson_get_value(res, 1, "status"); + + + if (strcmp(status, "running") == 0 || strcmp(status, "up") == 0) + *value = "Enabled"; + else + *value = "Disabled"; + return 0; +} + /*#Device.WiFi.Radio.{i}.MaxBitRate!UBUS:wifi.radio.@Name/status//maxrate*/ int os__get_radio_max_bit_rate (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { @@ -509,6 +531,37 @@ int os__get_radio_supported_standard(char *refparam, struct dmctx *ctx, void *da return 0; } +/*#Device.WiFi.Radio.{i}.OperatingStandards!UBUS:wifi.radio.@Name/status//standard*/ +int os_get_radio_operating_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + char object[32], *standard = NULL, *iface = NULL; + char **standards = NULL; + int i; + size_t length; + + *value = ""; + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "device", &iface); + snprintf(object, sizeof(object), "wifi.radio.%s", iface); + dmubus_call(object, "status", UBUS_ARGS{}, 0, &res); + + DM_ASSERT(res, standard = ""); + standard = dmjson_get_value(res, 1, "standard"); + standards = strsplit(standard, "/", &length); + + for (i=0; iwifi_ssid_sec, "disabled", value); - if (*value[0] == '\0' || *value[0] == '0') - *value = "Enabled"; - else - *value = "Disabled"; - return 0; -} - /*#Device.WiFi.SSID.{i}.SSID!UCI:wireless/wifi-iface,@i-1/ssid*/ static int get_wlan_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) @@ -243,6 +232,7 @@ static int get_WiFiSSID_MACAddress(char *refparam, struct dmctx *ctx, void *data { json_object *res; dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct wifi_ssid_args *)data)->ifname, String}}, 1, &res); + DM_ASSERT(res, *value = ""); *value = dmjson_get_value(res, 1, "macaddr"); return 0; @@ -367,25 +357,6 @@ static int set_radio_dfsenable(char *refparam, struct dmctx *ctx, void *data, ch return 0; } -/*#Device.WiFi.Radio.{i}.OperatingStandards!UCI:wireless/wifi-device,@i-1/hwmode*/ -static int get_radio_operating_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char *supst = NULL; - dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "hwmode", &supst); - if(strcmp(supst, "11n") == 0 || strcmp(supst, "auto") == 0) { - *value = "n"; - } else if (strcmp(supst, "11g") == 0) { - *value = "g"; - } else if (strcmp(supst, "11ac") == 0) { - *value = "ac"; - } else if (strcmp(supst, "11b") == 0) { - *value = "b"; - } else if (strcmp(supst, "11ax") == 0) { - *value = "ax"; - } - return 0; -} - static int set_radio_operating_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *freq; @@ -833,7 +804,7 @@ static int get_access_point_control_enable(char *refparam, struct dmctx *ctx, vo char *macfilter; dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "macfilter", &macfilter); - if (!*value || *value[0] == 0 || strcmp(macfilter, "deny") == 0 || strcmp(macfilter, "disable") == 0) + if (macfilter[0] == 0 || strcmp(macfilter, "deny") == 0 || strcmp(macfilter, "disable") == 0) *value = "false"; else *value = "true"; @@ -2475,7 +2446,7 @@ DMLEAF tWiFiRadioParams[] = { {CUSTOM_PREFIX"MaxAssociations", &DMWRITE, DMT_STRING, get_radio_maxassoc, set_radio_maxassoc, NULL, NULL, BBFDM_BOTH}, {CUSTOM_PREFIX"DFSEnable", &DMWRITE, DMT_BOOL, get_radio_dfsenable, set_radio_dfsenable, NULL, NULL, BBFDM_BOTH}, {"SupportedStandards", &DMREAD, DMT_STRING, os__get_radio_supported_standard, NULL, NULL, NULL, BBFDM_BOTH}, -{"OperatingStandards", &DMWRITE, DMT_STRING, get_radio_operating_standard, set_radio_operating_standard, NULL, NULL, BBFDM_BOTH}, +{"OperatingStandards", &DMWRITE, DMT_STRING, os_get_radio_operating_standard, set_radio_operating_standard, NULL, NULL, BBFDM_BOTH}, {"ChannelsInUse", &DMREAD, DMT_STRING, os__get_radio_channel, NULL, NULL, NULL, BBFDM_BOTH}, {"Channel", &DMWRITE, DMT_UNINT, os__get_radio_channel, set_radio_channel, NULL, NULL, BBFDM_BOTH}, {"AutoChannelEnable", &DMWRITE, DMT_BOOL, get_radio_auto_channel_enable, set_radio_auto_channel_enable, NULL, NULL, BBFDM_BOTH}, @@ -2601,7 +2572,7 @@ DMLEAF tWiFiAccessPointParams[] = { /* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ {"Alias", &DMWRITE, DMT_STRING, get_access_point_alias, set_access_point_alias, NULL, NULL, BBFDM_BOTH}, {"Enable", &DMWRITE, DMT_BOOL, get_wifi_enable, set_wifi_enable, NULL, NULL, BBFDM_BOTH}, -{"Status", &DMREAD, DMT_STRING, get_wifi_access_point_status, NULL, NULL, NULL, BBFDM_BOTH}, +{"Status", &DMREAD, DMT_STRING, os_get_wifi_access_point_status, NULL, NULL, NULL, BBFDM_BOTH}, {"SSIDReference", &DMREAD, DMT_STRING, get_ap_ssid_ref, NULL, NULL, NULL, BBFDM_BOTH}, {"SSIDAdvertisementEnabled", &DMWRITE, DMT_BOOL, get_wlan_ssid_advertisement_enable, set_wlan_ssid_advertisement_enable, NULL, NULL, BBFDM_BOTH}, {"WMMEnable", &DMWRITE, DMT_BOOL, get_wmm_enabled, set_wmm_enabled, NULL, NULL, BBFDM_BOTH},