From d1dd19880d458ddc3f3b1e418f4ccaf3cb6706e7 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Thu, 5 Oct 2017 18:45:25 +0300 Subject: [PATCH] Bluetooth: Mesh: Fix revoking app keys The needed code for taking updated app keys into use and revoking the old ones was missing. Signed-off-by: Johan Hedberg --- subsys/bluetooth/host/mesh/cfg.c | 2 +- subsys/bluetooth/host/mesh/net.c | 23 +++++++++++++++++++++-- subsys/bluetooth/host/mesh/net.h | 2 ++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/subsys/bluetooth/host/mesh/cfg.c b/subsys/bluetooth/host/mesh/cfg.c index 23047eba252..c3b30df3a50 100644 --- a/subsys/bluetooth/host/mesh/cfg.c +++ b/subsys/bluetooth/host/mesh/cfg.c @@ -2582,7 +2582,7 @@ static void krp_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, } else if ((sub->kr_phase == BT_MESH_KR_PHASE_1 || sub->kr_phase == BT_MESH_KR_PHASE_2) && phase == BT_MESH_KR_PHASE_3) { - memcpy(&sub->keys[0], &sub->keys[1], sizeof(sub->keys[0])); + bt_mesh_net_revoke_keys(sub); if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER) || IS_ENABLED(CONFIG_BT_MESH_FRIEND)) { bt_mesh_friend_cred_refresh(ctx->net_idx); diff --git a/subsys/bluetooth/host/mesh/net.c b/subsys/bluetooth/host/mesh/net.c index bd9ba096348..759146e414f 100644 --- a/subsys/bluetooth/host/mesh/net.c +++ b/subsys/bluetooth/host/mesh/net.c @@ -470,6 +470,26 @@ int bt_mesh_net_create(u16_t idx, u8_t flags, const u8_t key[16], return 0; } +void bt_mesh_net_revoke_keys(struct bt_mesh_subnet *sub) +{ + int i; + + BT_DBG("idx 0x%04x", sub->net_idx); + + memcpy(&sub->keys[0], &sub->keys[1], sizeof(sub->keys[0])); + + 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 != sub->net_idx || !key->updated) { + continue; + } + + memcpy(&key->keys[0], &key->keys[1], sizeof(key->keys[0])); + key->updated = false; + } +} + bool bt_mesh_kr_update(struct bt_mesh_subnet *sub, u8_t new_kr, bool new_key) { if (new_kr != sub->kr_flag && sub->kr_phase == BT_MESH_KR_NORMAL) { @@ -501,8 +521,7 @@ bool bt_mesh_kr_update(struct bt_mesh_subnet *sub, u8_t new_kr, bool new_key) */ case BT_MESH_KR_PHASE_2: BT_DBG("KR Phase 0x%02x -> Normal", sub->kr_phase); - memcpy(&sub->keys[0], &sub->keys[1], - sizeof(sub->keys[0])); + bt_mesh_net_revoke_keys(sub); if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER) || IS_ENABLED(CONFIG_BT_MESH_FRIEND)) { bt_mesh_friend_cred_refresh(sub->net_idx); diff --git a/subsys/bluetooth/host/mesh/net.h b/subsys/bluetooth/host/mesh/net.h index fafeac3b7df..5827d1450ec 100644 --- a/subsys/bluetooth/host/mesh/net.h +++ b/subsys/bluetooth/host/mesh/net.h @@ -245,6 +245,8 @@ int bt_mesh_friend_cred_del(u16_t net_idx, u16_t addr); bool bt_mesh_kr_update(struct bt_mesh_subnet *sub, u8_t new_kr, bool new_key); +void bt_mesh_net_revoke_keys(struct bt_mesh_subnet *sub); + int bt_mesh_net_beacon_update(struct bt_mesh_subnet *sub); void bt_mesh_rpl_reset(void);