mesh: Fix HB Sub Status when disabling subscription

MESH/NODE/CFG/HBS/BV-02-C expects it to be possible to do a Set with
the existing src & dst addresses but with a zero period in order to
"cancel" the current subscription. In such a case the addresses should
remain set but the period be set to zero, similar to what would happen
if the period would expire.

X-Original-Commit: e6f54bebbdaf6dcdebe863500ae20eb3b43d9d3a
This commit is contained in:
Michał Narajowski
2017-11-07 09:57:12 +01:00
parent aa8aea3563
commit 2a5dbc7e57
+19 -7
View File
@@ -2859,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,
@@ -2916,8 +2922,14 @@ 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;
/* 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 {
cfg->hb_sub.src = sub_src;