]> granicus.if.org Git - esp-idf/commitdiff
ble_mesh: fix heartbeat sending on friendship established/lost
authorlly <lly@espressif.com>
Mon, 2 Sep 2019 07:12:12 +0000 (15:12 +0800)
committerlly <lly@espressif.com>
Mon, 9 Sep 2019 09:15:16 +0000 (17:15 +0800)
components/bt/esp_ble_mesh/mesh_core/lpn.c
components/bt/esp_ble_mesh/mesh_core/transport.c

index 7788ee7503d2ee4e1772c0b38d0945c2a9e7124a..ad301db06ef508481c71769c51c87680ffdfdff0 100644 (file)
@@ -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);
         }
index ed244ccb8fa0e04594a46cf6c111d377261cd534..d358d9d4466bf2fbce2bf253ca7d4ba10a4c0d0c 100644 (file)
@@ -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);