From cc3830f8ed857bce1ab07abeb3dd2ea1151d0878 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Tue, 8 May 2018 10:21:26 +0300 Subject: [PATCH] Bluetooth: Mesh: Fix resetting configuration model state Instead of manually iterating all app keys and net keys, use the bt_mesh_subnet_del() helper on all subnets. This will also clear any app keys, and ensures that persistent storage is cleared as well. Signed-off-by: Johan Hedberg --- subsys/bluetooth/host/mesh/cfg_srv.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/subsys/bluetooth/host/mesh/cfg_srv.c b/subsys/bluetooth/host/mesh/cfg_srv.c index e8efee6ab0b..23bf70dea49 100644 --- a/subsys/bluetooth/host/mesh/cfg_srv.c +++ b/subsys/bluetooth/host/mesh/cfg_srv.c @@ -3137,22 +3137,15 @@ void bt_mesh_cfg_reset(void) 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) { - bt_mesh_app_key_del(key); - } - } - + /* Delete all net keys, which also takes care of all app keys which + * are associated with each net 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; + if (sub->net_idx != BT_MESH_KEY_UNUSED) { + bt_mesh_subnet_del(sub); + } } memset(labels, 0, sizeof(labels));