From 9a8316061ddda7c7886601a80556f0905498f0b1 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Thu, 2 Nov 2017 20:46:15 +0300 Subject: [PATCH] Bluetooth: Mesh: Fix HB Sub Status when disabling subscription MESH/NODE/CFG/HBS/BV-02-C expects it to be possible to do a Set with the existing src & dst addresses but with a zero period in order to "cancel" the current subscription. In such a case the addresses should remain set but the period be set to zero, similar to what would happen if the period would expire. Signed-off-by: Johan Hedberg --- subsys/bluetooth/host/mesh/cfg.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/subsys/bluetooth/host/mesh/cfg.c b/subsys/bluetooth/host/mesh/cfg.c index 657ac21aaaa..4034a3d9c57 100644 --- a/subsys/bluetooth/host/mesh/cfg.c +++ b/subsys/bluetooth/host/mesh/cfg.c @@ -2793,10 +2793,16 @@ static void hb_sub_send_status(struct bt_mesh_model *model, net_buf_simple_add_le16(msg, cfg->hb_sub.src); net_buf_simple_add_le16(msg, cfg->hb_sub.dst); - net_buf_simple_add_u8(msg, hb_log(period)); - net_buf_simple_add_u8(msg, hb_log(cfg->hb_sub.count)); - net_buf_simple_add_u8(msg, cfg->hb_sub.min_hops); - net_buf_simple_add_u8(msg, cfg->hb_sub.max_hops); + + if (cfg->hb_sub.src == BT_MESH_ADDR_UNASSIGNED || + cfg->hb_sub.dst == BT_MESH_ADDR_UNASSIGNED) { + memset(net_buf_simple_add(msg, 4), 0, 4); + } else { + net_buf_simple_add_u8(msg, hb_log(period)); + net_buf_simple_add_u8(msg, hb_log(cfg->hb_sub.count)); + net_buf_simple_add_u8(msg, cfg->hb_sub.min_hops); + net_buf_simple_add_u8(msg, cfg->hb_sub.max_hops); + } bt_mesh_model_send(model, ctx, msg, NULL, NULL); } @@ -2849,8 +2855,14 @@ static void heartbeat_sub_set(struct bt_mesh_model *model, if (sub_src == BT_MESH_ADDR_UNASSIGNED || sub_dst == BT_MESH_ADDR_UNASSIGNED || sub_period == 0x00) { - cfg->hb_sub.src = BT_MESH_ADDR_UNASSIGNED; - cfg->hb_sub.dst = BT_MESH_ADDR_UNASSIGNED; + /* Setting the same addresses with zero period should retain + * the addresses according to MESH/NODE/CFG/HBS/BV-02-C. + */ + if (cfg->hb_sub.src != sub_src || cfg->hb_sub.dst != sub_dst) { + cfg->hb_sub.src = BT_MESH_ADDR_UNASSIGNED; + cfg->hb_sub.dst = BT_MESH_ADDR_UNASSIGNED; + } + period_ms = 0; } else { cfg->hb_sub.src = sub_src;