From a25b8584cb34dbb76fda64a122aa0f33175ded79 Mon Sep 17 00:00:00 2001 From: Omar Kallel Date: Thu, 19 Mar 2020 09:45:26 +0100 Subject: [PATCH] Fix bugs: Device.WiFi.Radio --- dmtree/tr181/wifi.c | 27 ++++++++++++++++++++------- libbbf_api/dmcommon.c | 2 ++ libbbf_api/dmcommon.h | 2 ++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/dmtree/tr181/wifi.c b/dmtree/tr181/wifi.c index 6ab444c5..7b238edd 100644 --- a/dmtree/tr181/wifi.c +++ b/dmtree/tr181/wifi.c @@ -5,6 +5,7 @@ * it under the terms of the GNU Lesser General Public License version 2.1 * as published by the Free Software Foundation * + * Author: Omar Kallel * Author: Anis Ellouze * Author: Amin Ben Ramdhane * @@ -357,9 +358,19 @@ static int set_radio_dfsenable(char *refparam, struct dmctx *ctx, void *data, ch /*#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) { - dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "hwmode", value); - if (strcmp(*value, "auto") == 0) + 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; } @@ -369,7 +380,7 @@ static int set_radio_operating_standard(char *refparam, struct dmctx *ctx, void switch (action) { case VALUECHECK: - if (dm_validate_string_list(value, -1, -1, -1, -1, -1, NULL, 0, NULL, 0)) + if (dm_validate_string_list(value, -1, -1, -1, -1, -1, SupportedStandards, 6, NULL, 0)) return FAULT_9007; return 0; case VALUESET: @@ -382,7 +393,7 @@ static int set_radio_operating_standard(char *refparam, struct dmctx *ctx, void } else { if (strcmp(value, "b") == 0) value = "11b"; - else if (strcmp(value, "b,g") == 0 || strcmp(value, "g,b") == 0) + else if (strcmp(value, "b,g") == 0 || strcmp(value, "g,b") == 0) //TODO: Not supported in TR181 (to check) value = "11bg"; else if (strcmp(value, "g") == 0) value = "11g"; @@ -527,13 +538,15 @@ static int get_WiFiRadio_OperatingChannelBandwidth(char *refparam, struct dmctx static int set_WiFiRadio_OperatingChannelBandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char buf[6]; switch (action) { case VALUECHECK: - if (dm_validate_string(value, -1, -1, NULL, 0, NULL, 0)) + if (dm_validate_string(value, -1, -1, SupportedOperatingChannelBandwidth, 6, NULL, 0)) return FAULT_9007; break; case VALUESET: - dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "bandwidth", value); + sscanf(value,"%[^M]", buf); + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "bandwidth", buf); break; } return 0; @@ -628,7 +641,7 @@ static int get_WiFiRadio_RegulatoryDomain(char *refparam, struct dmctx *ctx, voi dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "country", &country); arr = strsplit(country, "/", &length); if(arr && arr[0]) - dmasprintf(value, "%s", arr[0]); + dmasprintf(value, "%s ", arr[0]); else *value= ""; diff --git a/libbbf_api/dmcommon.c b/libbbf_api/dmcommon.c index 82dfa746..d61d88f1 100644 --- a/libbbf_api/dmcommon.c +++ b/libbbf_api/dmcommon.c @@ -55,6 +55,8 @@ char *DropAlgorithm[] = {"RED", "DT", "WRED", "BLUE"}; char *SchedulerAlgorithm[] = {"WFQ", "WRR", "SP"}; char *DTMFMethod[] = {"InBand", "RFC2833", "SIPInfo"}; char *ProfileEnable[] = {"Disabled", "Quiescent", "Enabled"}; +char *SupportedOperatingChannelBandwidth[] = {"20MHz", "40MHz", "80MHz", "160MHZ", "80+80MHz", "Auto"}; +char *SupportedStandards[] = {"a", "b", "g", "n", "ac", "ax"}; char *PIN[] = {"^\\d{4}|\\d{8}$"}; char *DestinationAddress[] = {"^\\d+/\\d+$"}; diff --git a/libbbf_api/dmcommon.h b/libbbf_api/dmcommon.h index 417f6017..bc39f5ef 100644 --- a/libbbf_api/dmcommon.h +++ b/libbbf_api/dmcommon.h @@ -96,6 +96,8 @@ extern char *MACAddress[]; extern char *IPPrefix[]; extern char *IPv4Prefix[]; extern char *IPv6Prefix[]; +extern char *SupportedOperatingChannelBandwidth[]; +extern char *SupportedStandards[]; #define NVRAM_FILE "/proc/nvram/WpaKey" #define MAX_DHCP_LEASES 256