From f25640e9e5e5f49e48dba069dc989a8b92509a8c Mon Sep 17 00:00:00 2001 From: lly Date: Mon, 2 Sep 2019 12:38:49 +0800 Subject: [PATCH] ble_mesh: fix MESH/NODE/CFG/GPXY/BV-02-C & MESH/NODE/CFG/NID/BV-02-C related bug --- components/bt/esp_ble_mesh/mesh_core/proxy.c | 21 +++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_core/proxy.c b/components/bt/esp_ble_mesh/mesh_core/proxy.c index fd9807f54b..4945906fd5 100644 --- a/components/bt/esp_ble_mesh/mesh_core/proxy.c +++ b/components/bt/esp_ble_mesh/mesh_core/proxy.c @@ -1144,14 +1144,25 @@ static bool advertise_subnet(struct bt_mesh_subnet *sub) static struct bt_mesh_subnet *next_sub(void) { + struct bt_mesh_subnet *sub = NULL; int i; - for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) { - struct bt_mesh_subnet *sub; - - sub = &bt_mesh.sub[(i + next_idx) % ARRAY_SIZE(bt_mesh.sub)]; + for (i = next_idx; i < ARRAY_SIZE(bt_mesh.sub); i++) { + sub = &bt_mesh.sub[i]; if (advertise_subnet(sub)) { - next_idx = (next_idx + 1) % ARRAY_SIZE(bt_mesh.sub); + next_idx = (i + 1) % ARRAY_SIZE(bt_mesh.sub); + return sub; + } + } + + /** + * If among [next_idx, ARRAY_SIZE(bt_mesh.sub)], there is no subnet + * to advertise, then try to start advertising from Primary subnet. + */ + for (i = 0; i < next_idx; i++) { + sub = &bt_mesh.sub[i]; + if (advertise_subnet(sub)) { + next_idx = (i + 1) % ARRAY_SIZE(bt_mesh.sub); return sub; } }