From 94fcb211de67ef3ab1d6775a1273a9a87c89c790 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Wed, 14 Aug 2019 13:06:13 +0300 Subject: [PATCH] Bluetooth: Mesh: Fix heartbeat sending on Friendship established/lost Mesh Profile 3.6.7.2 Publishing Heartbeat messages: " Triggered publishing of Heartbeat messages is enabled by the Heartbeat Publication Features state (see Section 4.2.17.5): ... - If the Low Power bit is set to 1, a Heartbeat message shall be published when the node establishes or loses Friendship (see Section 3.6.6.1). " Fixes #18194 Signed-off-by: Johan Hedberg --- subsys/bluetooth/mesh/lpn.c | 11 +++++++++++ subsys/bluetooth/mesh/transport.c | 4 +--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/subsys/bluetooth/mesh/lpn.c b/subsys/bluetooth/mesh/lpn.c index 28c01939c33..c1301721181 100644 --- a/subsys/bluetooth/mesh/lpn.c +++ b/subsys/bluetooth/mesh/lpn.c @@ -199,6 +199,7 @@ static int send_friend_clear(void) static void clear_friendship(bool force, bool disable) { + struct bt_mesh_cfg_srv *cfg = bt_mesh_cfg_get(); struct bt_mesh_lpn *lpn = &bt_mesh.lpn; BT_DBG("force %u disable %u", force, disable); @@ -246,6 +247,10 @@ static void clear_friendship(bool force, bool disable) */ lpn->groups_changed = 1U; + if (cfg->hb_pub.feat & BT_MESH_FEAT_LOW_POWER) { + bt_mesh_heartbeat_send(); + } + if (disable) { lpn_set_state(BT_MESH_LPN_DISABLED); return; @@ -944,6 +949,8 @@ int bt_mesh_lpn_friend_update(struct bt_mesh_net_rx *rx, } if (!lpn->established) { + struct bt_mesh_cfg_srv *cfg = bt_mesh_cfg_get(); + /* This is normally checked on the transport layer, however * in this state we're also still accepting master * credentials so we need to ensure the right ones (Friend @@ -958,6 +965,10 @@ int bt_mesh_lpn_friend_update(struct bt_mesh_net_rx *rx, BT_INFO("Friendship established with 0x%04x", lpn->frnd); + if (cfg->hb_pub.feat & BT_MESH_FEAT_LOW_POWER) { + bt_mesh_heartbeat_send(); + } + if (lpn_cb) { lpn_cb(lpn->frnd, true); } diff --git a/subsys/bluetooth/mesh/transport.c b/subsys/bluetooth/mesh/transport.c index 0fa647ee773..c9046756142 100644 --- a/subsys/bluetooth/mesh/transport.c +++ b/subsys/bluetooth/mesh/transport.c @@ -1547,11 +1547,9 @@ void bt_mesh_heartbeat_send(void) feat |= BT_MESH_FEAT_FRIEND; } -#if defined(CONFIG_BT_MESH_LOW_POWER) - if (bt_mesh.lpn.state != BT_MESH_LPN_DISABLED) { + if (bt_mesh_lpn_established()) { feat |= BT_MESH_FEAT_LOW_POWER; } -#endif hb.feat = sys_cpu_to_be16(feat);