From 0f1da9926250ad1ee1ae77b35edd42be9c8d06ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alperen=20=C5=9Eener?= Date: Thu, 8 Feb 2024 16:12:37 +0100 Subject: [PATCH] bluetooth: mesh: fixing light lc server and sensor for PTS failures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding that enough data is available in buffer before doing the channel decode for sensor format. Fixing the case where all property id checks fall to default switch case when regulator is enabled. Adding the missing PI property formats to return coefficient and write to correct server state. Signed-off-by: Alperen Şener --- subsys/bluetooth/mesh/light_ctrl_internal.h | 7 ++++- subsys/bluetooth/mesh/light_ctrl_srv.c | 29 +++++++-------------- subsys/bluetooth/mesh/sensor.c | 3 +++ 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/subsys/bluetooth/mesh/light_ctrl_internal.h b/subsys/bluetooth/mesh/light_ctrl_internal.h index 5743a6febf98..79a3353d2266 100644 --- a/subsys/bluetooth/mesh/light_ctrl_internal.h +++ b/subsys/bluetooth/mesh/light_ctrl_internal.h @@ -23,7 +23,7 @@ extern "C" { #endif static inline const struct bt_mesh_sensor_format * -prop_format_get(enum bt_mesh_light_ctrl_prop id) +prop_format_get(uint16_t id) { switch (id) { case BT_MESH_LIGHT_CTRL_PROP_ILLUMINANCE_ON: @@ -36,6 +36,11 @@ prop_format_get(enum bt_mesh_light_ctrl_prop id) return &bt_mesh_sensor_format_perceived_lightness; case BT_MESH_LIGHT_CTRL_PROP_REG_ACCURACY: return &bt_mesh_sensor_format_percentage_8; + case BT_MESH_LIGHT_CTRL_COEFF_KID: + case BT_MESH_LIGHT_CTRL_COEFF_KIU: + case BT_MESH_LIGHT_CTRL_COEFF_KPD: + case BT_MESH_LIGHT_CTRL_COEFF_KPU: + return &bt_mesh_sensor_format_coefficient; case BT_MESH_LIGHT_CTRL_PROP_TIME_FADE_PROLONG: case BT_MESH_LIGHT_CTRL_PROP_TIME_FADE_ON: case BT_MESH_LIGHT_CTRL_PROP_TIME_FADE_STANDBY_AUTO: diff --git a/subsys/bluetooth/mesh/light_ctrl_srv.c b/subsys/bluetooth/mesh/light_ctrl_srv.c index 9f470d0d8f24..2cdec50b2c0b 100644 --- a/subsys/bluetooth/mesh/light_ctrl_srv.c +++ b/subsys/bluetooth/mesh/light_ctrl_srv.c @@ -1273,33 +1273,24 @@ static int prop_set(struct net_buf_simple *buf, LOG_DBG("Set Prop: 0x%04x: %s", id, bt_mesh_sensor_ch_str(&val)); #if CONFIG_BT_MESH_LIGHT_CTRL_SRV_REG - /* Regulator coefficients are raw IEEE-754 floats, pull them straight - * from the buffer instead of using sensor to decode them: + /* Regulator coefficients are raw IEEE-754 floats, status will always + * be BT_MESH_SENSOR_VALUE_NUMBER: */ if (srv->reg) { switch (id) { case BT_MESH_LIGHT_CTRL_COEFF_KID: - status = bt_mesh_sensor_value_to_float( - &val, &srv->reg->cfg.ki.down); - break; + (void)bt_mesh_sensor_value_to_float(&val, &srv->reg->cfg.ki.down); + return 0; case BT_MESH_LIGHT_CTRL_COEFF_KIU: - status = bt_mesh_sensor_value_to_float( - &val, &srv->reg->cfg.ki.down); - break; + (void)bt_mesh_sensor_value_to_float(&val, &srv->reg->cfg.ki.up); + return 0; case BT_MESH_LIGHT_CTRL_COEFF_KPD: - status = bt_mesh_sensor_value_to_float( - &val, &srv->reg->cfg.ki.down); - break; + (void)bt_mesh_sensor_value_to_float(&val, &srv->reg->cfg.kp.down); + return 0; case BT_MESH_LIGHT_CTRL_COEFF_KPU: - status = bt_mesh_sensor_value_to_float( - &val, &srv->reg->cfg.ki.down); - break; - default: - return -EINVAL; + (void)bt_mesh_sensor_value_to_float(&val, &srv->reg->cfg.kp.up); + return 0; } - - return bt_mesh_sensor_value_status_is_numeric(status) ? - 0 : -EINVAL; } #endif int64_t micro; diff --git a/subsys/bluetooth/mesh/sensor.c b/subsys/bluetooth/mesh/sensor.c index 6c00de58fec9..9f9b37a5d2cc 100644 --- a/subsys/bluetooth/mesh/sensor.c +++ b/subsys/bluetooth/mesh/sensor.c @@ -313,6 +313,9 @@ int sensor_ch_decode(struct net_buf_simple *buf, return format->decode(format, buf, value); #else value->format = format; + if (buf->len < format->size) { + return -ENOMEM; + } memcpy(value->raw, net_buf_simple_pull_mem(buf, format->size), format->size); return 0;