You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2017/11/09 08:27:06 UTC

[GitHub] michal-narajowski closed pull request #649: mesh: Various fixes found during PTS testing

michal-narajowski closed pull request #649: mesh: Various fixes found during PTS testing
URL: https://github.com/apache/mynewt-core/pull/649
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/net/nimble/host/mesh/src/cfg.c b/net/nimble/host/mesh/src/cfg.c
index 873d8c07b..a55f53138 100644
--- a/net/nimble/host/mesh/src/cfg.c
+++ b/net/nimble/host/mesh/src/cfg.c
@@ -922,6 +922,7 @@ static void relay_set(struct bt_mesh_model *model,
 	if (!cfg) {
 		BT_WARN("No Configuration Server context available");
 	} else if (buf->om_data[0] == 0x00 || buf->om_data[0] == 0x01) {
+		bool change = (cfg->relay != buf->om_data[0]);
 		struct bt_mesh_subnet *sub;
 
 		cfg->relay = buf->om_data[0];
@@ -933,7 +934,7 @@ static void relay_set(struct bt_mesh_model *model,
 		       TRANSMIT_INT(cfg->relay_retransmit));
 
 		sub = bt_mesh_subnet_get(cfg->hb_pub.net_idx);
-		if ((cfg->hb_pub.feat & BT_MESH_FEAT_RELAY) && sub) {
+		if ((cfg->hb_pub.feat & BT_MESH_FEAT_RELAY) && sub && change) {
 			hb_send(model);
 		}
 	} else {
@@ -2681,6 +2682,19 @@ static u8_t hb_log(u16_t val)
 	}
 }
 
+static u8_t hb_pub_count_log(u16_t val)
+{
+	if (!val) {
+		return 0x00;
+	} else if (val == 0x01) {
+		return 0x01;
+	} else if (val == 0xffff) {
+		return 0xff;
+	} else {
+		return 32 - __builtin_clz(val - 1) + 1;
+	}
+}
+
 static u16_t hb_pwr2(u8_t val, u8_t sub)
 {
 	if (!val) {
@@ -2722,7 +2736,7 @@ static void hb_pub_send_status(struct bt_mesh_model *model,
 	}
 
 	net_buf_simple_add_le16(msg, cfg->hb_pub.dst);
-	net_buf_simple_add_u8(msg, hb_log(cfg->hb_pub.count));
+	net_buf_simple_add_u8(msg, hb_pub_count_log(cfg->hb_pub.count));
 	net_buf_simple_add_u8(msg, cfg->hb_pub.period);
 	net_buf_simple_add_u8(msg, cfg->hb_pub.ttl);
 	net_buf_simple_add_le16(msg, cfg->hb_pub.feat);
@@ -2845,13 +2859,19 @@ static void hb_sub_send_status(struct bt_mesh_model *model,
 
 	net_buf_simple_add_le16(msg, cfg->hb_sub.src);
 	net_buf_simple_add_le16(msg, cfg->hb_sub.dst);
-	net_buf_simple_add_u8(msg, hb_log(period));
-	net_buf_simple_add_u8(msg, hb_log(cfg->hb_sub.count));
-	net_buf_simple_add_u8(msg, cfg->hb_sub.min_hops);
-	net_buf_simple_add_u8(msg, cfg->hb_sub.max_hops);
+
+	if (cfg->hb_sub.src == BT_MESH_ADDR_UNASSIGNED ||
+	    cfg->hb_sub.dst == BT_MESH_ADDR_UNASSIGNED) {
+		memset(net_buf_simple_add(msg, 4), 0, 4);
+	} else {
+		net_buf_simple_add_u8(msg, hb_log(period));
+		net_buf_simple_add_u8(msg, hb_log(cfg->hb_sub.count));
+		net_buf_simple_add_u8(msg, cfg->hb_sub.min_hops);
+		net_buf_simple_add_u8(msg, cfg->hb_sub.max_hops);
+	}
 
 	bt_mesh_model_send(model, ctx, msg, NULL, NULL);
-    os_mbuf_free_chain(msg);
+	os_mbuf_free_chain(msg);
 }
 
 static void heartbeat_sub_get(struct bt_mesh_model *model,
@@ -2887,7 +2907,9 @@ static void heartbeat_sub_set(struct bt_mesh_model *model,
 		return;
 	}
 
-	if (BT_MESH_ADDR_IS_VIRTUAL(sub_dst)) {
+	if (BT_MESH_ADDR_IS_VIRTUAL(sub_dst) || BT_MESH_ADDR_IS_RFU(sub_dst) ||
+	    (BT_MESH_ADDR_IS_UNICAST(sub_dst) &&
+	     sub_dst != bt_mesh_primary_addr())) {
 		BT_WARN("Prohibited destination address");
 		return;
 	}
@@ -2900,10 +2922,13 @@ static void heartbeat_sub_set(struct bt_mesh_model *model,
 	if (sub_src == BT_MESH_ADDR_UNASSIGNED ||
 	    sub_dst == BT_MESH_ADDR_UNASSIGNED ||
 	    sub_period == 0x00) {
-		cfg->hb_sub.src = BT_MESH_ADDR_UNASSIGNED;
-		cfg->hb_sub.dst = BT_MESH_ADDR_UNASSIGNED;
-		cfg->hb_sub.min_hops = 0;
-		cfg->hb_sub.max_hops = 0;
+		/* Setting the same addresses with zero period should retain
+		 * the addresses according to MESH/NODE/CFG/HBS/BV-02-C.
+		 */
+		if (cfg->hb_sub.src != sub_src || cfg->hb_sub.dst != sub_dst) {
+			cfg->hb_sub.src = BT_MESH_ADDR_UNASSIGNED;
+			cfg->hb_sub.dst = BT_MESH_ADDR_UNASSIGNED;
+		}
 
 		period_ms = 0;
 	} else {
@@ -2911,14 +2936,12 @@ static void heartbeat_sub_set(struct bt_mesh_model *model,
 		cfg->hb_sub.dst = sub_dst;
 		cfg->hb_sub.min_hops = 0x7f;
 		cfg->hb_sub.max_hops = 0;
-
+		cfg->hb_sub.count = 0;
 		period_ms = hb_pwr2(sub_period, 1) * 1000;
 	}
 
 	BT_DBG("period_ms %u", period_ms);
 
-	cfg->hb_sub.count = 0;
-
 	if (period_ms) {
 		cfg->hb_sub.expiry = k_uptime_get() + period_ms;
 	} else {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services