Skip to content

Commit 439fbdd

Browse files
Johan HedbergAnas Nashif
authored andcommitted
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 <[email protected]>
1 parent c67f64e commit 439fbdd

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

subsys/bluetooth/host/mesh/cfg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2582,7 +2582,7 @@ static void krp_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx,
25822582
} else if ((sub->kr_phase == BT_MESH_KR_PHASE_1 ||
25832583
sub->kr_phase == BT_MESH_KR_PHASE_2) &&
25842584
phase == BT_MESH_KR_PHASE_3) {
2585-
memcpy(&sub->keys[0], &sub->keys[1], sizeof(sub->keys[0]));
2585+
bt_mesh_net_revoke_keys(sub);
25862586
if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER) ||
25872587
IS_ENABLED(CONFIG_BT_MESH_FRIEND)) {
25882588
bt_mesh_friend_cred_refresh(ctx->net_idx);

subsys/bluetooth/host/mesh/net.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,26 @@ int bt_mesh_net_create(u16_t idx, u8_t flags, const u8_t key[16],
470470
return 0;
471471
}
472472

473+
void bt_mesh_net_revoke_keys(struct bt_mesh_subnet *sub)
474+
{
475+
int i;
476+
477+
BT_DBG("idx 0x%04x", sub->net_idx);
478+
479+
memcpy(&sub->keys[0], &sub->keys[1], sizeof(sub->keys[0]));
480+
481+
for (i = 0; i < ARRAY_SIZE(bt_mesh.app_keys); i++) {
482+
struct bt_mesh_app_key *key = &bt_mesh.app_keys[i];
483+
484+
if (key->net_idx != sub->net_idx || !key->updated) {
485+
continue;
486+
}
487+
488+
memcpy(&key->keys[0], &key->keys[1], sizeof(key->keys[0]));
489+
key->updated = false;
490+
}
491+
}
492+
473493
bool bt_mesh_kr_update(struct bt_mesh_subnet *sub, u8_t new_kr, bool new_key)
474494
{
475495
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)
501521
*/
502522
case BT_MESH_KR_PHASE_2:
503523
BT_DBG("KR Phase 0x%02x -> Normal", sub->kr_phase);
504-
memcpy(&sub->keys[0], &sub->keys[1],
505-
sizeof(sub->keys[0]));
524+
bt_mesh_net_revoke_keys(sub);
506525
if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER) ||
507526
IS_ENABLED(CONFIG_BT_MESH_FRIEND)) {
508527
bt_mesh_friend_cred_refresh(sub->net_idx);

subsys/bluetooth/host/mesh/net.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ int bt_mesh_friend_cred_del(u16_t net_idx, u16_t addr);
245245

246246
bool bt_mesh_kr_update(struct bt_mesh_subnet *sub, u8_t new_kr, bool new_key);
247247

248+
void bt_mesh_net_revoke_keys(struct bt_mesh_subnet *sub);
249+
248250
int bt_mesh_net_beacon_update(struct bt_mesh_subnet *sub);
249251

250252
void bt_mesh_rpl_reset(void);

0 commit comments

Comments
 (0)