Bluetooth: Mesh: Fix node reset

There were some things that were working only when receiving a Node
Reset message from someone else, but not when the app called
bt_mesh_reset() directly. There was also some state cleanup missing
for the transport layer. This patch addresses all of these issues.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2017-11-20 14:51:32 +02:00 committed by Johan Hedberg
commit 95bef3694e
5 changed files with 59 additions and 27 deletions

View file

@ -2375,8 +2375,6 @@ static void node_reset(struct bt_mesh_model *model,
{
/* Needed size: opcode (2 bytes) + msg + MIC */
struct net_buf_simple *msg = NET_BUF_SIMPLE(2 + 0 + 4);
struct bt_mesh_cfg_srv *cfg = model->user_data;
int i;
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
@ -2392,28 +2390,6 @@ static void node_reset(struct bt_mesh_model *model,
BT_ERR("Unable to send Node Reset Status");
}
/* Delete all app keys */
for (i = 0; i < ARRAY_SIZE(bt_mesh.app_keys); i++) {
struct bt_mesh_app_key *key = &bt_mesh.app_keys[i];
if (key->net_idx != BT_MESH_KEY_UNUSED) {
_app_key_del(key);
}
}
for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) {
struct bt_mesh_subnet *sub = &bt_mesh.sub[i];
if (cfg->hb_pub.net_idx == sub->net_idx) {
hb_pub_disable(cfg);
}
memset(sub, 0, sizeof(*sub));
sub->net_idx = BT_MESH_KEY_UNUSED;
}
memset(labels, 0, sizeof(labels));
bt_mesh_reset();
}
@ -3048,6 +3024,42 @@ int bt_mesh_cfg_srv_init(struct bt_mesh_model *model, bool primary)
return 0;
}
void bt_mesh_cfg_reset(void)
{
struct bt_mesh_cfg_srv *cfg = conf;
int i;
if (!cfg) {
return;
}
bt_mesh_set_hb_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.expiry = 0;
hb_pub_disable(cfg);
/* Delete all app keys */
for (i = 0; i < ARRAY_SIZE(bt_mesh.app_keys); i++) {
struct bt_mesh_app_key *key = &bt_mesh.app_keys[i];
if (key->net_idx != BT_MESH_KEY_UNUSED) {
_app_key_del(key);
}
}
for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) {
struct bt_mesh_subnet *sub = &bt_mesh.sub[i];
memset(sub, 0, sizeof(*sub));
sub->net_idx = BT_MESH_KEY_UNUSED;
}
memset(labels, 0, sizeof(labels));
}
void bt_mesh_heartbeat(u16_t src, u16_t dst, u8_t hops, u16_t feat)
{
struct bt_mesh_cfg_srv *cfg = conf;

View file

@ -117,6 +117,8 @@ int bt_mesh_health_srv_init(struct bt_mesh_model *model, bool primary);
int bt_mesh_cfg_cli_init(struct bt_mesh_model *model, bool primary);
void bt_mesh_cfg_reset(void);
void bt_mesh_heartbeat(u16_t src, u16_t dst, u8_t hops, u16_t feat);
void bt_mesh_attention(struct bt_mesh_model *model, u8_t time);

View file

@ -104,14 +104,18 @@ void bt_mesh_reset(void)
bt_mesh.iv_index = 0;
bt_mesh.seq = 0;
bt_mesh.iv_update = 0;
bt_mesh.pending_update = 0;
bt_mesh.valid = 0;
bt_mesh.last_update = 0;
bt_mesh.ivu_initiator = 0;
bt_mesh_set_hb_sub_dst(BT_MESH_ADDR_UNASSIGNED);
k_delayed_work_cancel(&bt_mesh.ivu_complete);
bt_mesh_cfg_reset();
bt_mesh_rx_reset();
bt_mesh_tx_reset();
if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER)) {
bt_mesh_lpn_disable(true);
}

View file

@ -1343,7 +1343,20 @@ void bt_mesh_rx_reset(void)
BT_DBG("");
for (i = 0; i < ARRAY_SIZE(seg_rx); i++) {
seg_rx[i].in_use = 0;
seg_rx_reset(&seg_rx[i]);
seg_rx[i].src = BT_MESH_ADDR_UNASSIGNED;
seg_rx[i].dst = BT_MESH_ADDR_UNASSIGNED;
}
}
void bt_mesh_tx_reset(void)
{
int i;
BT_DBG("");
for (i = 0; i < ARRAY_SIZE(seg_tx); i++) {
seg_tx_reset(&seg_tx[i]);
}
}

View file

@ -81,6 +81,7 @@ struct bt_mesh_app_key *bt_mesh_app_key_find(u16_t app_idx);
bool bt_mesh_tx_in_progress(void);
void bt_mesh_rx_reset(void);
void bt_mesh_tx_reset(void);
int bt_mesh_ctl_send(struct bt_mesh_net_tx *tx, u8_t ctl_op, void *data,
size_t data_len, u64_t *seq_auth,