Skip to content

Commit 6dfc9ec

Browse files
PavelVPVcarlescufi
authored andcommitted
Bluetooth: Mesh: Invalidate pending entries before calling settings API
If, while storing app or net key, or changing cdb, we receive another mesh message that affects setting of the same key that the mesh currently stores, the new change won't be stored. The settings subsystem API has rescheduling point inside. The mesh settings are stored in the system workqueue and by default mesh messages are processed from BT RX thread which has higher priority than the system workqueue. When the case above happens, a new change will be written to the same cache entry. But this cache entry will be invalidated after leaving settings API, which in turns will invalidate the new change: - Receive Config AppKey Add message cfg_srv.c -> app_keys.c: bt_mesh_app_key_add() app_keys.c: update_app_key_settings() app_keys.c: bt_mesh_settings_store_schedule() - store_pending() in settings.c is scheduled settings.c -> app_keys.c: bt_mesh_app_key_pending_store() app_keys.c: store_app_key() called to store new app key app_keys.c: settings_save_one() calls flash driver and sleeps - Receive Config AppKey Delete message while in sleep, which wakes up BT RX thread before returning to the system workqueue cfg_srv.c -> app_keys.c: bt_mesh_app_key_del() app_keys.c: update_app_key_settings() app_keys.c: app_key_update_find() finds entry and returns it app_keys.c: update->clear = 1 app_keys.c: bt_mesh_settings_store_schedule() - returning back to bt_mesh_app_key_pending_store() from settings_save_one() app_keys.c: update->valid = 0 - the key won't be deleted next time store_pending() is scheduled. This change moves entry invalidation before calling settings API so that after returning from settings API, a new change won't be unintentionally invalidated. Signed-off-by: Pavel Vasilyev <[email protected]>
1 parent 7e6e3e9 commit 6dfc9ec

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

subsys/bluetooth/mesh/app_keys.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,12 +665,12 @@ void bt_mesh_app_key_pending_store(void)
665665
continue;
666666
}
667667

668+
update->valid = 0U;
669+
668670
if (update->clear) {
669671
clear_app_key(update->key_idx);
670672
} else {
671673
store_app_key(update->key_idx);
672674
}
673-
674-
update->valid = 0U;
675675
}
676676
}

subsys/bluetooth/mesh/cdb.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,27 +1023,29 @@ static void store_cdb_pending_nodes(void)
10231023

10241024
for (i = 0; i < ARRAY_SIZE(cdb_node_updates); ++i) {
10251025
struct node_update *update = &cdb_node_updates[i];
1026+
uint16_t addr;
10261027

10271028
if (update->addr == BT_MESH_ADDR_UNASSIGNED) {
10281029
continue;
10291030
}
10301031

1031-
LOG_DBG("addr: 0x%04x, clear: %d", update->addr, update->clear);
1032+
addr = update->addr;
1033+
update->addr = BT_MESH_ADDR_UNASSIGNED;
1034+
1035+
LOG_DBG("addr: 0x%04x, clear: %d", addr, update->clear);
10321036

10331037
if (update->clear) {
1034-
clear_cdb_node(update->addr);
1038+
clear_cdb_node(addr);
10351039
} else {
10361040
struct bt_mesh_cdb_node *node;
10371041

1038-
node = bt_mesh_cdb_node_get(update->addr);
1042+
node = bt_mesh_cdb_node_get(addr);
10391043
if (node) {
10401044
store_cdb_node(node);
10411045
} else {
1042-
LOG_WRN("Node 0x%04x not found", update->addr);
1046+
LOG_WRN("Node 0x%04x not found", addr);
10431047
}
10441048
}
1045-
1046-
update->addr = BT_MESH_ADDR_UNASSIGNED;
10471049
}
10481050
}
10491051

@@ -1058,6 +1060,8 @@ static void store_cdb_pending_keys(void)
10581060
continue;
10591061
}
10601062

1063+
update->valid = 0U;
1064+
10611065
if (update->clear) {
10621066
if (update->app_key) {
10631067
clear_cdb_app_key(update->key_idx);
@@ -1085,8 +1089,6 @@ static void store_cdb_pending_keys(void)
10851089
}
10861090
}
10871091
}
1088-
1089-
update->valid = 0U;
10901092
}
10911093
}
10921094

subsys/bluetooth/mesh/subnet.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,12 +831,12 @@ void bt_mesh_subnet_pending_store(void)
831831
continue;
832832
}
833833

834+
update->valid = 0U;
835+
834836
if (update->clear) {
835837
clear_net_key(update->key_idx);
836838
} else {
837839
store_subnet(update->key_idx);
838840
}
839-
840-
update->valid = 0U;
841841
}
842842
}

0 commit comments

Comments
 (0)