Bluetooth: Mesh: Fix heartbeat subscription state handling

PTS version 7.3.0 incorporates some errata which change the expected
behavior of the heartbeat subscription state. Update the code so that
the following tests pass successfully:

MESH/NODE/CFG/HBS/BV-01
MESH/NODE/CFG/HBS/BV-02
MESH/NODE/CFG/HBS/BV-03
MESH/NODE/CFG/HBS/BV-04

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2018-08-15 14:58:26 +03:00 committed by Johan Hedberg
commit bf023d6210

View file

@ -3069,19 +3069,12 @@ static void hb_sub_send_status(struct bt_mesh_model *model,
bt_mesh_model_msg_init(&msg, OP_HEARTBEAT_SUB_STATUS);
net_buf_simple_add_u8(&msg, status);
net_buf_simple_add_le16(&msg, cfg->hb_sub.src);
net_buf_simple_add_le16(&msg, cfg->hb_sub.dst);
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);
}
if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) {
BT_ERR("Unable to send Heartbeat Subscription Status");
@ -3136,12 +3129,17 @@ 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) {
/* Setting the same addresses with zero period should retain
* the addresses according to MESH/NODE/CFG/HBS/BV-02-C.
/* Only an explicit address change to unassigned should
* trigger clearing of the values according to
* MESH/NODE/CFG/HBS/BV-02-C.
*/
if (cfg->hb_sub.src != sub_src || cfg->hb_sub.dst != sub_dst) {
if (sub_src == BT_MESH_ADDR_UNASSIGNED ||
sub_dst == BT_MESH_ADDR_UNASSIGNED) {
cfg->hb_sub.src = BT_MESH_ADDR_UNASSIGNED;
cfg->hb_sub.dst = BT_MESH_ADDR_UNASSIGNED;
cfg->hb_sub.min_hops = BT_MESH_TTL_MAX;
cfg->hb_sub.max_hops = 0;
cfg->hb_sub.count = 0;
}
period_ms = 0;
@ -3166,6 +3164,13 @@ static void heartbeat_sub_set(struct bt_mesh_model *model,
}
hb_sub_send_status(model, ctx, STATUS_SUCCESS);
/* MESH/NODE/CFG/HBS/BV-01-C expects the MinHops to be 0x7f after
* disabling subscription, but 0x00 for subsequent Get requests.
*/
if (!period_ms) {
cfg->hb_sub.min_hops = 0;
}
}
const struct bt_mesh_model_op bt_mesh_cfg_srv_op[] = {