ble_mesh: fix heartbeat sending on friendship established/lost

This commit is contained in:
lly 2019-09-02 15:12:12 +08:00
parent 9f80c24b74
commit 05128c98ec
2 changed files with 13 additions and 3 deletions

View 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);
}

View 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);