From 05128c98ec424c37150817a965a7b51b6de140c6 Mon Sep 17 00:00:00 2001 From: lly Date: Mon, 2 Sep 2019 15:12:12 +0800 Subject: [PATCH] ble_mesh: fix heartbeat sending on friendship established/lost --- components/bt/esp_ble_mesh/mesh_core/lpn.c | 12 ++++++++++++ components/bt/esp_ble_mesh/mesh_core/transport.c | 4 +--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_core/lpn.c b/components/bt/esp_ble_mesh/mesh_core/lpn.c index 7788ee7503..ad301db06e 100644 --- a/components/bt/esp_ble_mesh/mesh_core/lpn.c +++ b/components/bt/esp_ble_mesh/mesh_core/lpn.c @@ -26,6 +26,7 @@ #include "beacon.h" #include "foundation.h" #include "lpn.h" +#include "cfg_srv.h" #ifdef CONFIG_BLE_MESH_LOW_POWER @@ -201,6 +202,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); @@ -248,6 +250,10 @@ static void clear_friendship(bool force, bool disable) */ lpn->groups_changed = 1U; + if (cfg->hb_pub.feat & BLE_MESH_FEAT_LOW_POWER) { + bt_mesh_heartbeat_send(); + } + if (disable) { lpn_set_state(BLE_MESH_LPN_DISABLED); return; @@ -952,6 +958,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 @@ -966,6 +974,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 & BLE_MESH_FEAT_LOW_POWER) { + bt_mesh_heartbeat_send(); + } + if (lpn_cb) { lpn_cb(lpn->frnd, true); } diff --git a/components/bt/esp_ble_mesh/mesh_core/transport.c b/components/bt/esp_ble_mesh/mesh_core/transport.c index ed244ccb8f..d358d9d446 100644 --- a/components/bt/esp_ble_mesh/mesh_core/transport.c +++ b/components/bt/esp_ble_mesh/mesh_core/transport.c @@ -1633,11 +1633,9 @@ void bt_mesh_heartbeat_send(void) feat |= BLE_MESH_FEAT_FRIEND; } -#if defined(CONFIG_BLE_MESH_LOW_POWER) - if (bt_mesh.lpn.state != BLE_MESH_LPN_DISABLED) { + if (bt_mesh_lpn_established()) { feat |= BLE_MESH_FEAT_LOW_POWER; } -#endif hb.feat = sys_cpu_to_be16(feat);