You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ry...@apache.org on 2020/09/15 06:41:50 UTC

[mynewt-nimble] 09/09: Bluetooth: Mesh: Heartbeat period starts at tx Starts the periodic heartbeat publish period at the end of the publication, instead of at the ordering time. This ensures that the heartbeat period doesn't get shortened by other enqueued messages.

This is an automated email from the ASF dual-hosted git repository.

rymek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit f4fe7b90df01b8ca2294af771ce43b1828a70de5
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Mon Sep 7 10:21:58 2020 +0200

    Bluetooth: Mesh: Heartbeat period starts at tx
    Starts the periodic heartbeat publish period at the end of the
    publication, instead of at the ordering time. This ensures that the
    heartbeat period doesn't get shortened by other enqueued messages.
---
 nimble/host/mesh/src/cfg_srv.c   | 47 +++++++++++++++++++++++++++++-----------
 nimble/host/mesh/src/lpn.c       |  4 ++--
 nimble/host/mesh/src/transport.c |  8 +++----
 nimble/host/mesh/src/transport.h |  2 +-
 4 files changed, 41 insertions(+), 20 deletions(-)

diff --git a/nimble/host/mesh/src/cfg_srv.c b/nimble/host/mesh/src/cfg_srv.c
index 5cac1ad..c1bb631 100644
--- a/nimble/host/mesh/src/cfg_srv.c
+++ b/nimble/host/mesh/src/cfg_srv.c
@@ -808,7 +808,7 @@ static void gatt_proxy_set(struct bt_mesh_model *model,
 	bt_mesh_adv_update();
 
 	if (cfg->hb_pub.feat & BT_MESH_FEAT_PROXY) {
-		bt_mesh_heartbeat_send();
+		(void)bt_mesh_heartbeat_send(NULL, NULL);
 	}
 
 send_status:
@@ -928,7 +928,7 @@ static void relay_set(struct bt_mesh_model *model,
 		       BT_MESH_TRANSMIT_INT(cfg->relay_retransmit));
 
 		if ((cfg->hb_pub.feat & BT_MESH_FEAT_RELAY) && change) {
-			bt_mesh_heartbeat_send();
+			(void)bt_mesh_heartbeat_send(NULL, NULL);
 		}
 	} else {
 		BT_WARN("Invalid Relay value 0x%02x", buf->om_data[0]);
@@ -2782,7 +2782,7 @@ static void friend_set(struct bt_mesh_model *model,
 	}
 
 	if (cfg->hb_pub.feat & BT_MESH_FEAT_FRIEND) {
-		bt_mesh_heartbeat_send();
+		(void)bt_mesh_heartbeat_send(NULL, NULL);
 	}
 
 send_status:
@@ -3283,11 +3283,38 @@ const struct bt_mesh_model_op bt_mesh_cfg_srv_op[] = {
 	BT_MESH_MODEL_OP_END,
 };
 
+static void hb_publish_end_cb(int err, void *cb_data)
+{
+	struct bt_mesh_cfg_srv *cfg = cb_data;
+	uint16_t period_ms;
+
+	period_ms = hb_pwr2(cfg->hb_pub.period, 1) * 1000U;
+	if (period_ms && cfg->hb_pub.count > 1) {
+		k_delayed_work_submit(&cfg->hb_pub.timer, K_MSEC(period_ms));
+	}
+
+	if (cfg->hb_pub.count != 0xffff) {
+		cfg->hb_pub.count--;
+	}
+}
+
+static void hb_publish_start_cb(uint16_t duration, int err, void *cb_data)
+{
+	if (err) {
+		hb_publish_end_cb(err, cb_data);
+	}
+}
+
 static void hb_publish(struct ble_npl_event *work)
 {
+	static const struct bt_mesh_send_cb publish_cb = {
+		.start = hb_publish_start_cb,
+		.end = hb_publish_end_cb,
+	};
+
 	struct bt_mesh_cfg_srv *cfg = ble_npl_event_get_arg(work);
 	struct bt_mesh_subnet *sub;
-	u16_t period_ms;
+	int err;
 
 	BT_DBG("hb_pub.count: %u", cfg->hb_pub.count);
 
@@ -3303,15 +3330,9 @@ static void hb_publish(struct ble_npl_event *work)
 		return;
 	}
 
-	period_ms = hb_pwr2(cfg->hb_pub.period, 1) * 1000;
-	if (period_ms && cfg->hb_pub.count > 1) {
-		k_delayed_work_submit(&cfg->hb_pub.timer, period_ms);
-	}
-
-	bt_mesh_heartbeat_send();
-
-	if (cfg->hb_pub.count != 0xffff) {
-		cfg->hb_pub.count--;
+	err = bt_mesh_heartbeat_send(&publish_cb, cfg);
+	if (err) {
+		hb_publish_end_cb(err, cfg);
 	}
 }
 
diff --git a/nimble/host/mesh/src/lpn.c b/nimble/host/mesh/src/lpn.c
index ec012a5..0bfc00a 100644
--- a/nimble/host/mesh/src/lpn.c
+++ b/nimble/host/mesh/src/lpn.c
@@ -243,7 +243,7 @@ static void clear_friendship(bool force, bool disable)
 	lpn->groups_changed = 1;
 
 	if (cfg->hb_pub.feat & BT_MESH_FEAT_LOW_POWER) {
-		bt_mesh_heartbeat_send();
+		(void)bt_mesh_heartbeat_send(NULL, NULL);
 	}
 
 	if (disable) {
@@ -961,7 +961,7 @@ 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();
+			(void)bt_mesh_heartbeat_send(NULL, NULL);
 		}
 
 		if (lpn_cb) {
diff --git a/nimble/host/mesh/src/transport.c b/nimble/host/mesh/src/transport.c
index caf1b4f..e771867 100644
--- a/nimble/host/mesh/src/transport.c
+++ b/nimble/host/mesh/src/transport.c
@@ -1569,7 +1569,7 @@ void bt_mesh_rpl_clear(void)
 	memset(bt_mesh.rpl, 0, sizeof(bt_mesh.rpl));
 }
 
-void bt_mesh_heartbeat_send(void)
+int bt_mesh_heartbeat_send(const struct bt_mesh_send_cb *cb, void *cb_data)
 {
 	struct bt_mesh_cfg_srv *cfg = bt_mesh_cfg_get();
 	u16_t feat = 0U;
@@ -1592,7 +1592,7 @@ void bt_mesh_heartbeat_send(void)
 
 	/* Do nothing if heartbeat publication is not enabled */
 	if (cfg->hb_pub.dst == BT_MESH_ADDR_UNASSIGNED) {
-		return;
+		return 0;
 	}
 
 	hb.init_ttl = cfg->hb_pub.ttl;
@@ -1617,8 +1617,8 @@ void bt_mesh_heartbeat_send(void)
 
 	BT_DBG("InitTTL %u feat 0x%04x", cfg->hb_pub.ttl, feat);
 
-	bt_mesh_ctl_send(&tx, TRANS_CTL_OP_HEARTBEAT, &hb, sizeof(hb),
-			 NULL, NULL, NULL);
+	return bt_mesh_ctl_send(&tx, TRANS_CTL_OP_HEARTBEAT, &hb, sizeof(hb),
+			 NULL, cb, cb_data);
 }
 
 int bt_mesh_app_key_get(const struct bt_mesh_subnet *subnet, u16_t app_idx,
diff --git a/nimble/host/mesh/src/transport.h b/nimble/host/mesh/src/transport.h
index eff768e..8bcbff0 100644
--- a/nimble/host/mesh/src/transport.h
+++ b/nimble/host/mesh/src/transport.h
@@ -99,7 +99,7 @@ void bt_mesh_trans_init(void);
 
 void bt_mesh_rpl_clear(void);
 
-void bt_mesh_heartbeat_send(void);
+int bt_mesh_heartbeat_send(const struct bt_mesh_send_cb *cb, void *cb_data);
 
 int bt_mesh_app_key_get(const struct bt_mesh_subnet *subnet, u16_t app_idx,
 			u16_t addr, const u8_t **key, u8_t *aid);