From 082bd9694e23f891eddbb2516cee7e5fe0269400 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Mon, 5 Oct 2020 17:03:30 -0400 Subject: Fix frequency verb invalid frequency behavior The frequency verb was not checking if a frequency corresponds to the frequency band step the binding provides to users, add logic to do so and return an error if the frequency is invalid. While this is a change in behavior, it is believe it should not impact users, as the binding is intended to reflect user facing radio application usage. Additional tweaks: - fix error invalid frequency error message in reply JSON. - add the same band limit checks to the null implementation's frequency setting function that the other implementations do. - fix a couple of issues in README.md; the "rds" verb was missing, and the value key name for the "frequency" event was incorrect. Bug-AGL: SPEC-3620 Signed-off-by: Scott Murray Change-Id: I2adfc10448546264110f6d854f02d677087f1e47 (cherry picked from commit 8958a8a3e98085c60c9cd803395be157e78e3565) --- binding/radio-binding.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'binding/radio-binding.c') diff --git a/binding/radio-binding.c b/binding/radio-binding.c index 34eb53e..45e8ecb 100644 --- a/binding/radio-binding.c +++ b/binding/radio-binding.c @@ -90,11 +90,26 @@ static void frequency(afb_req_t request) if(value) { char *p; + radio_band_t band; + uint32_t min_frequency; + uint32_t max_frequency; + uint32_t step; + frequency = (uint32_t) strtoul(value, &p, 10); if(frequency && *p == '\0') { + band = radio_impl_ops->get_band(); + min_frequency = radio_impl_ops->get_min_frequency(band); + max_frequency = radio_impl_ops->get_max_frequency(band); + step = radio_impl_ops->get_frequency_step(band); + if(frequency < min_frequency || + frequency > max_frequency || + (frequency - min_frequency) % step) { + afb_req_reply(request, NULL, "failed", "Invalid frequency"); + return; + } radio_impl_ops->set_frequency(frequency); } else { - afb_req_reply(request, NULL, "failed", "Invalid scan direction"); + afb_req_reply(request, NULL, "failed", "Invalid frequency"); return; } } @@ -104,11 +119,12 @@ static void frequency(afb_req_t request) afb_req_reply(request, ret_json, NULL, NULL); } -/* @brief Get RDS information -* -* @param afb_req_t : an afb request structure -* -*/ +/* + * @brief Get RDS information + * + * @param afb_req_t : an afb request structure + * + */ static void rds(afb_req_t request) { json_object *ret_json; -- cgit 1.2.3-korg