From 42d330406e2c5a9440ee2a4594fb77e72f4f68f4 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Thu, 11 Apr 2019 17:38:30 +0300 Subject: [PATCH] Bluetooth: Mesh: Fix qualification test MESH/SR/HM/CFS/BV-02-C The commit 8d0ef1eb8503c45f029802545eb6f14b863463f8 attempted to fix test case MESH/SR/HM/CFS/BV-02-C, however inadvertently ended up introducing a hidden bug. This bug was unearthed thanks to commit 686f5c79cff51d268d93ab87102a04578d3062aa. We have to keep always track of the FastPeriodDivisor state whether we're using it (faults > 0) or not (faults == 0). Introduce a boolean field to the model publication that's used to indicate whether the FastPeriodDivisor should be applied or not, instead of zeroing the divisor when there are no faults (this would cause wrong behavior when faults appear again). Additionally, the PTS seems to require that we wait until the end of the existing period before sending the next Health Current Status, rather than sending it immediately when the fault count changes. Fixes #15365 Signed-off-by: Johan Hedberg --- include/bluetooth/mesh/access.h | 1 + subsys/bluetooth/host/mesh/access.c | 6 +++++- subsys/bluetooth/host/mesh/health_srv.c | 13 +++++++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/include/bluetooth/mesh/access.h b/include/bluetooth/mesh/access.h index e8e46af224d..3f175d12884 100644 --- a/include/bluetooth/mesh/access.h +++ b/include/bluetooth/mesh/access.h @@ -280,6 +280,7 @@ struct bt_mesh_model_pub { u8_t period; /**< Publish Period. */ u8_t period_div:4, /**< Divisor for the Period. */ cred:1, /**< Friendship Credentials Flag. */ + fast_period:1,/**< Use FastPeriodDivisor */ count:3; /**< Retransmissions left. */ u32_t period_start; /**< Start of the current period. */ diff --git a/subsys/bluetooth/host/mesh/access.c b/subsys/bluetooth/host/mesh/access.c index 717467d4de9..f41d5f103f9 100644 --- a/subsys/bluetooth/host/mesh/access.c +++ b/subsys/bluetooth/host/mesh/access.c @@ -98,7 +98,11 @@ s32_t bt_mesh_model_pub_period_get(struct bt_mesh_model *mod) CODE_UNREACHABLE; } - return period >> mod->pub->period_div; + if (mod->pub->fast_period) { + return period >> mod->pub->period_div; + } else { + return period; + } } static s32_t next_period(struct bt_mesh_model *mod) diff --git a/subsys/bluetooth/host/mesh/health_srv.c b/subsys/bluetooth/host/mesh/health_srv.c index ce43527cb82..62abf44ca43 100644 --- a/subsys/bluetooth/host/mesh/health_srv.c +++ b/subsys/bluetooth/host/mesh/health_srv.c @@ -342,8 +342,10 @@ static int health_pub_update(struct bt_mesh_model *mod) BT_DBG(""); count = health_get_current(mod, pub->msg); - if (!count) { - pub->period_div = 0U; + if (count) { + pub->fast_period = 1U; + } else { + pub->fast_period = 0U; } return 0; @@ -358,6 +360,13 @@ int bt_mesh_fault_update(struct bt_mesh_elem *elem) return -EINVAL; } + /* Let periodic publishing, if enabled, take care of sending the + * Health Current Status. + */ + if (bt_mesh_model_pub_period_get(mod)) { + return 0; + } + health_pub_update(mod); return bt_mesh_model_publish(mod);