Skip to content

Commit 3ebd9b4

Browse files
Johan Hedbergjhedberg
authored andcommitted
Bluetooth: Mesh: Fix clearing model binding and subscriptions
The code for clearing model bindings and subscriptions was flawed in that proper "cleared" entries were never stored in settings. The code must pass 0 and NULL to settings_save_one() in case the entry is desired to be cleared. Signed-off-by: Johan Hedberg <[email protected]>
1 parent dac335c commit 3ebd9b4

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

subsys/bluetooth/host/mesh/settings.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,8 @@ static void store_pending_mod_bind(struct bt_mesh_model *mod, bool vnd)
11851185
u16_t keys[CONFIG_BT_MESH_MODEL_KEY_COUNT];
11861186
char path[20];
11871187
int i, count, err;
1188+
size_t len;
1189+
void *val;
11881190

11891191
for (i = 0, count = 0; i < ARRAY_SIZE(mod->keys); i++) {
11901192
if (mod->keys[i] != BT_MESH_KEY_UNUSED) {
@@ -1193,9 +1195,17 @@ static void store_pending_mod_bind(struct bt_mesh_model *mod, bool vnd)
11931195
}
11941196
}
11951197

1198+
if (count) {
1199+
val = keys;
1200+
len = count * sizeof(keys[0]);
1201+
} else {
1202+
val = NULL;
1203+
len = 0;
1204+
}
1205+
11961206
encode_mod_path(mod, vnd, "bind", path, sizeof(path));
11971207

1198-
err = settings_save_one(path, keys, count * sizeof(keys[0]));
1208+
err = settings_save_one(path, val, len);
11991209
if (err) {
12001210
BT_ERR("Failed to store %s value", log_strdup(path));
12011211
} else {
@@ -1208,16 +1218,26 @@ static void store_pending_mod_sub(struct bt_mesh_model *mod, bool vnd)
12081218
u16_t groups[CONFIG_BT_MESH_MODEL_GROUP_COUNT];
12091219
char path[20];
12101220
int i, count, err;
1221+
size_t len;
1222+
void *val;
12111223

12121224
for (i = 0, count = 0; i < ARRAY_SIZE(mod->groups); i++) {
12131225
if (mod->groups[i] != BT_MESH_ADDR_UNASSIGNED) {
12141226
groups[count++] = mod->groups[i];
12151227
}
12161228
}
12171229

1230+
if (count) {
1231+
val = groups;
1232+
len = count * sizeof(groups[0]);
1233+
} else {
1234+
val = NULL;
1235+
len = 0;
1236+
}
1237+
12181238
encode_mod_path(mod, vnd, "sub", path, sizeof(path));
12191239

1220-
err = settings_save_one(path, groups, count * sizeof(groups[0]));
1240+
err = settings_save_one(path, val, len);
12211241
if (err) {
12221242
BT_ERR("Failed to store %s value", log_strdup(path));
12231243
} else {

0 commit comments

Comments
 (0)