Skip to content

Commit

Permalink
bluetooth: mesh: fixing light lc server and sensor for PTS failures
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
m-alperen-sener authored and rlubos committed Feb 12, 2024
1 parent 13775f5 commit 0f1da99
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
7 changes: 6 additions & 1 deletion subsys/bluetooth/mesh/light_ctrl_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
29 changes: 10 additions & 19 deletions subsys/bluetooth/mesh/light_ctrl_srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions subsys/bluetooth/mesh/sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0f1da99

Please sign in to comment.