diff --git a/libbbfdm/dmtree/tr181/wifi.c b/libbbfdm/dmtree/tr181/wifi.c index 4417ccd2..45aa8653 100644 --- a/libbbfdm/dmtree/tr181/wifi.c +++ b/libbbfdm/dmtree/tr181/wifi.c @@ -1635,12 +1635,63 @@ static int set_WiFiRadio_RegulatoryDomain(char *refparam, struct dmctx *ctx, voi return 0; } +/*#Device.WiFi.Radio.{i}.PossibleChannels!UBUS:wifi.radio.@Name/status//supp_channels[0].channels*/ +static int get_radio_possible_channels(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res = NULL, *supp_channels = NULL, *arrobj = NULL; + char object[32], *cur_opclass = NULL; + int i = 0; + + snprintf(object, sizeof(object), "wifi.radio.%s", section_name((((struct wifi_radio_args *)data)->sections)->config_section)); + dmubus_call(object, "status", UBUS_ARGS{0}, 0, &res); + DM_ASSERT(res, *value = ""); + cur_opclass = dmjson_get_value(res, 1, "opclass"); + dmjson_foreach_obj_in_array(res, arrobj, supp_channels, i, 1, "supp_channels") { + char *opclass = dmjson_get_value(supp_channels, 1, "opclass"); + if (DM_STRCMP(opclass, cur_opclass) != 0) + continue; + + *value = dmjson_get_value_array_all(supp_channels, ",", 1, "channels"); + break; + } + return 0; +} + +static int get_radio_channels_in_use(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = get_radio_option_nocache(section_name((((struct wifi_radio_args *)data)->sections)->config_section), "channel"); + return 0; +} + +static int get_radio_channel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *channel = NULL; + + dmuci_get_value_by_section_string((((struct wifi_radio_args *)data)->sections)->config_section, "channel", &channel); + + if (DM_LSTRCMP(channel, "auto") == 0 || DM_STRLEN(channel) == 0) + channel = get_radio_option_nocache(section_name((((struct wifi_radio_args *)data)->sections)->config_section), "channel"); + + *value = channel; + return 0; +} + static int set_radio_channel(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + char *supported_channels = NULL; + switch (action) { case VALUECHECK: if (dm_validate_unsignedInt(value, RANGE_ARGS{{"1","255"}}, 1)) return FAULT_9007; + + // Get the list of all supported channels + get_radio_possible_channels(refparam, ctx, data, instance, &supported_channels); + + // Check if the input value is a valid channel + if (!value_exits_in_str_list(supported_channels, ",", value)) + return FAULT_9007; + return 0; case VALUESET: dmuci_set_value_by_section((((struct wifi_radio_args *)data)->sections)->config_section, "channel", value); @@ -1649,7 +1700,6 @@ static int set_radio_channel(char *refparam, struct dmctx *ctx, void *data, char return 0; } -/*#Device.WiFi.Radio.{i}.AutoChannelEnable!UCI:wireless/wifi-device,@i-1/channel*/ static int get_radio_auto_channel_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((((struct wifi_radio_args *)data)->sections)->config_section, "channel", value); @@ -3548,20 +3598,6 @@ static int set_radio_frequency(char *refparam, struct dmctx *ctx, void *data, ch return 0; } -/*#Device.WiFi.Radio.{i}.ChannelsInUse!UCI:wireless/wifi-device,@i-1/channel*/ -static int get_radio_channel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - char object[32]; - json_object *res = NULL; - - snprintf(object, sizeof(object), "wifi.radio.%s", section_name((((struct wifi_radio_args *)data)->sections)->config_section)); - dmubus_call(object, "status", UBUS_ARGS{0}, 0, &res); - DM_ASSERT(res, *value = "0"); - *value = dmjson_get_value(res, 1, "channel"); - - return 0; -} - static int get_neighboring_wifi_diagnostics_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string_bbfdm("dmmap_wifi_neighboring", "@diagnostic_status[0]", "DiagnosticsState", value); @@ -3619,28 +3655,6 @@ static int get_neighboring_wifi_diagnostics_result_noise(char *refparam, struct return 0; } -/*#Device.WiFi.Radio.{i}.PossibleChannels!UBUS:wifi.radio.@Name/status//supp_channels[0].channels*/ -static int get_radio_possible_channels(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - json_object *res = NULL, *supp_channels = NULL, *arrobj = NULL; - char object[32], *cur_opclass = NULL; - int i = 0; - - snprintf(object, sizeof(object), "wifi.radio.%s", section_name((((struct wifi_radio_args *)data)->sections)->config_section)); - dmubus_call(object, "status", UBUS_ARGS{0}, 0, &res); - DM_ASSERT(res, *value = ""); - cur_opclass = dmjson_get_value(res, 1, "opclass"); - dmjson_foreach_obj_in_array(res, arrobj, supp_channels, i, 1, "supp_channels") { - char *opclass = dmjson_get_value(supp_channels, 1, "opclass"); - if (opclass && DM_STRCMP(opclass, cur_opclass) != 0) - continue; - - *value = dmjson_get_value_array_all(supp_channels, ",", 1, "channels"); - break; - } - return 0; -} - /*#Device.WiFi.Radio.{i}.CurrentOperatingChannelBandwidth!UBUS:wifi.radio.@Name/status//bandwidth*/ static int get_WiFiRadio_CurrentOperatingChannelBandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { @@ -6476,7 +6490,7 @@ DMLEAF tWiFiRadioParams[] = { {"OperatingFrequencyBand", &DMWRITE, DMT_STRING, get_radio_frequency, set_radio_frequency, BBFDM_BOTH, "2.0"}, {"SupportedStandards", &DMREAD, DMT_STRING, get_radio_supported_standard, NULL, BBFDM_BOTH, "2.0"}, {"OperatingStandards", &DMWRITE, DMT_STRING, get_radio_operating_standard, set_radio_operating_standard, BBFDM_BOTH, "2.0"}, -{"ChannelsInUse", &DMREAD, DMT_STRING, get_radio_channel, NULL, BBFDM_BOTH, "2.0"}, +{"ChannelsInUse", &DMREAD, DMT_STRING, get_radio_channels_in_use, NULL, BBFDM_BOTH, "2.0"}, {"Channel", &DMWRITE, DMT_UNINT, get_radio_channel, set_radio_channel, BBFDM_BOTH, "2.0"}, {"AutoChannelEnable", &DMWRITE, DMT_BOOL, get_radio_auto_channel_enable, set_radio_auto_channel_enable, BBFDM_BOTH, "2.0"}, {"PossibleChannels", &DMREAD, DMT_STRING, get_radio_possible_channels, NULL, BBFDM_BOTH, "2.0"}, diff --git a/test/cmocka/functional_test_bbfd.c b/test/cmocka/functional_test_bbfd.c index 7141f6f4..37e2edc5 100644 --- a/test/cmocka/functional_test_bbfd.c +++ b/test/cmocka/functional_test_bbfd.c @@ -51,8 +51,6 @@ static void validate_parameter(struct dmctx *ctx, const char *name, const char * { struct dm_parameter *n; - bbf_ctx_clean_sub(ctx); - bbf_ctx_init_sub(ctx, TR181_ROOT_TREE, TR181_VENDOR_EXTENSION, TR181_VENDOR_EXTENSION_EXCLUDE); list_for_each_entry(n, &ctx->list_parameter, list) { @@ -65,6 +63,9 @@ static void validate_parameter(struct dmctx *ctx, const char *name, const char * // check the returned type assert_string_equal(n->type, type); } + + bbf_ctx_clean_sub(ctx); + bbf_ctx_init_sub(ctx, TR181_ROOT_TREE, TR181_VENDOR_EXTENSION, TR181_VENDOR_EXTENSION_EXCLUDE); } static void test_api_bbfdm_get_set_standard_parameter(void **state) @@ -78,7 +79,7 @@ static void test_api_bbfdm_get_set_standard_parameter(void **state) assert_int_equal(fault, 0); // validate parameter : name, type, value - validate_parameter(ctx, "Device.WiFi.Radio.1.Channel", "1", "xsd:unsignedInt"); + validate_parameter(ctx, "Device.WiFi.Radio.1.Channel", "36", "xsd:unsignedInt"); // Set Wrong Value ==> expected "9007" error ctx->in_param = "Device.WiFi.Radio.1.Channel"; @@ -88,7 +89,7 @@ static void test_api_bbfdm_get_set_standard_parameter(void **state) // set value ==> expected "0" error ctx->in_param = "Device.WiFi.Radio.1.Channel"; - ctx->in_value = "64"; + ctx->in_value = "100"; fault = bbf_entry_method(ctx, BBF_SET_VALUE); assert_int_equal(fault, 0); @@ -98,7 +99,7 @@ static void test_api_bbfdm_get_set_standard_parameter(void **state) assert_int_equal(fault, 0); // validate parameter after setting to 64: name, type, value - validate_parameter(ctx, "Device.WiFi.Radio.1.Channel", "64", "xsd:unsignedInt"); + validate_parameter(ctx, "Device.WiFi.Radio.1.Channel", "100", "xsd:unsignedInt"); } static void test_api_bbfdm_get_set_json_parameter(void **state) @@ -112,7 +113,7 @@ static void test_api_bbfdm_get_set_json_parameter(void **state) assert_int_equal(fault, 0); // validate parameter : name, type, value - validate_parameter(ctx, "Device.WiFi.X_IOPSYS_EU_Radio.2.Noise", "-87", "xsd:int"); + validate_parameter(ctx, "Device.WiFi.X_IOPSYS_EU_Radio.1.Noise", "-87", "xsd:int"); // get value ==> expected "0" error ctx->in_param = "Device.WiFi.X_IOPSYS_EU_Radio.2.Noise"; @@ -136,7 +137,7 @@ static void test_api_bbfdm_get_set_json_parameter(void **state) assert_int_equal(fault, 0); // validate parameter : name, type, value - validate_parameter(ctx, "Device.WiFi.X_IOPSYS_EU_Radio.1.Stats.BytesSent", "14418177,", "xsd:unsignedInt"); + validate_parameter(ctx, "Device.WiFi.X_IOPSYS_EU_Radio.1.Stats.BytesSent", "14418177", "xsd:unsignedInt"); // get value ==> expected "0" error ctx->in_param = "Device.WiFi.X_IOPSYS_EU_Radio.2.Stats.BytesSent"; @@ -200,7 +201,7 @@ static void test_api_bbfdm_get_set_json_v1_parameter(void **state) assert_int_equal(fault, 0); // validate parameter : name, type, value - validate_parameter(ctx, "Device.UCI_TEST_V1.OWSD.2.IPv6", "off", "xsd:unsignedInt"); + validate_parameter(ctx, "Device.UCI_TEST_V1.OWSD.2.IPv6", "off", "xsd:string"); // set value ==> expected "0" error ctx->in_param = "Device.UCI_TEST_V1.OWSD.2.IPv6"; @@ -214,7 +215,7 @@ static void test_api_bbfdm_get_set_json_v1_parameter(void **state) assert_int_equal(fault, 0); // validate parameter : name, type, value - validate_parameter(ctx, "Device.UCI_TEST_V1.OWSD.2.IPv6", "on", "xsd:unsignedInt"); + validate_parameter(ctx, "Device.UCI_TEST_V1.OWSD.2.IPv6", "on", "xsd:string"); // get value ==> expected "0" error ctx->in_param = "Device.UCI_TEST_V1.OWSD.1.Port"; @@ -389,7 +390,7 @@ static void test_api_bbfdm_get_set_standard_parameter_alias(void **state) assert_int_equal(fault, 0); // validate parameter : name, type, value - validate_parameter(ctx, "Device.WiFi.Radio.[cpe-1].Channel", "64", "xsd:unsignedInt"); + validate_parameter(ctx, "Device.WiFi.Radio.[cpe-1].Channel", "100", "xsd:unsignedInt"); // Set Wrong Value ==> expected "9007" error ctx->in_param = "Device.WiFi.Radio.[cpe-1].Channel"; @@ -399,7 +400,7 @@ static void test_api_bbfdm_get_set_standard_parameter_alias(void **state) // set value ==> expected "0" error ctx->in_param = "Device.WiFi.Radio.[cpe-1].Channel"; - ctx->in_value = "84"; + ctx->in_value = "52"; fault = bbf_entry_method(ctx, BBF_SET_VALUE); assert_int_equal(fault, 0); @@ -409,7 +410,7 @@ static void test_api_bbfdm_get_set_standard_parameter_alias(void **state) assert_int_equal(fault, 0); // validate parameter after setting to 64: name, type, value - validate_parameter(ctx, "Device.WiFi.Radio.[cpe-1].Channel", "84", "xsd:unsignedInt"); + validate_parameter(ctx, "Device.WiFi.Radio.[cpe-1].Channel", "52", "xsd:unsignedInt"); // set value ==> expected "0" error ctx->in_param = "Device.WiFi.Radio.[cpe-1].Alias"; @@ -427,7 +428,7 @@ static void test_api_bbfdm_get_set_standard_parameter_alias(void **state) // set value ==> expected "0" error ctx->in_param = "Device.WiFi.Radio.[iopsys_test].Channel"; - ctx->in_value = "74"; + ctx->in_value = "116"; fault = bbf_entry_method(ctx, BBF_SET_VALUE); assert_int_equal(fault, 0); @@ -437,7 +438,7 @@ static void test_api_bbfdm_get_set_standard_parameter_alias(void **state) assert_int_equal(fault, 0); // validate parameter after setting to 64: name, type, value - validate_parameter(ctx, "Device.WiFi.Radio.[iopsys_test].Channel", "74", "xsd:unsignedInt"); + validate_parameter(ctx, "Device.WiFi.Radio.[iopsys_test].Channel", "116", "xsd:unsignedInt"); } #if 0