Skip to content

Commit fc4efdb

Browse files
PavelVPVtrond-snekvik
authored andcommitted
[nrf fromtree] Bluetooth: Mesh: Remove outated RPL entry from persistent
...storage This commit fixes a bug where outdated RPL entries might not be removed properly from the persistent storage making those entries dead. Signed-off-by: Pavel Vasilyev <[email protected]> (cherry picked from commit 1b129c5) Signed-off-by: Trond Einar Snekvik <[email protected]>
1 parent b284b02 commit fc4efdb

File tree

1 file changed

+33
-25
lines changed
  • subsys/bluetooth/mesh

1 file changed

+33
-25
lines changed

subsys/bluetooth/mesh/rpl.c

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,27 @@ static inline int rpl_idx(const struct bt_mesh_rpl *rpl)
4545
return rpl - &replay_list[0];
4646
}
4747

48+
static void clear_rpl(struct bt_mesh_rpl *rpl)
49+
{
50+
int err;
51+
char path[18];
52+
53+
if (!rpl->src) {
54+
return;
55+
}
56+
57+
snprintk(path, sizeof(path), "bt/mesh/RPL/%x", rpl->src);
58+
err = settings_delete(path);
59+
if (err) {
60+
BT_ERR("Failed to clear RPL");
61+
} else {
62+
BT_DBG("Cleared RPL");
63+
}
64+
65+
(void)memset(rpl, 0, sizeof(*rpl));
66+
atomic_clear_bit(store, rpl_idx(rpl));
67+
}
68+
4869
static void schedule_rpl_store(struct bt_mesh_rpl *entry)
4970
{
5071
atomic_set_bit(store, rpl_idx(entry));
@@ -184,13 +205,17 @@ void bt_mesh_rpl_reset(void)
184205

185206
if (rpl->src) {
186207
if (rpl->old_iv) {
187-
(void)memset(rpl, 0, sizeof(*rpl));
208+
if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
209+
clear_rpl(rpl);
210+
} else {
211+
(void)memset(rpl, 0, sizeof(*rpl));
212+
}
188213
} else {
189214
rpl->old_iv = true;
190-
}
191215

192-
if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
193-
schedule_rpl_store(rpl);
216+
if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
217+
schedule_rpl_store(rpl);
218+
}
194219
}
195220
}
196221
}
@@ -254,6 +279,10 @@ static void store_rpl(struct bt_mesh_rpl *entry)
254279
char path[18];
255280
int err;
256281

282+
if (!entry->src) {
283+
return;
284+
}
285+
257286
BT_DBG("src 0x%04x seq 0x%06x old_iv %u", entry->src, entry->seq,
258287
entry->old_iv);
259288

@@ -270,27 +299,6 @@ static void store_rpl(struct bt_mesh_rpl *entry)
270299
}
271300
}
272301

273-
static void clear_rpl(struct bt_mesh_rpl *rpl)
274-
{
275-
int err;
276-
char path[18];
277-
278-
if (!rpl->src) {
279-
return;
280-
}
281-
282-
snprintk(path, sizeof(path), "bt/mesh/RPL/%x", rpl->src);
283-
err = settings_delete(path);
284-
if (err) {
285-
BT_ERR("Failed to clear RPL");
286-
} else {
287-
BT_DBG("Cleared RPL");
288-
}
289-
290-
(void)memset(rpl, 0, sizeof(*rpl));
291-
atomic_clear_bit(store, rpl_idx(rpl));
292-
}
293-
294302
static void store_pending_rpl(struct bt_mesh_rpl *rpl)
295303
{
296304
BT_DBG("");

0 commit comments

Comments
 (0)