]> granicus.if.org Git - esp-idf/commitdiff
ble_mesh: fix MESH/NODE/CFG/GPXY/BV-02-C & MESH/NODE/CFG/NID/BV-02-C related bug
authorlly <lly@espressif.com>
Mon, 2 Sep 2019 04:38:49 +0000 (12:38 +0800)
committerlly <lly@espressif.com>
Mon, 9 Sep 2019 09:15:16 +0000 (17:15 +0800)
components/bt/esp_ble_mesh/mesh_core/proxy.c

index fd9807f54bb57313a14a62060c09494086fa126c..4945906fd595afd492112c8a2af88e41d6136db5 100644 (file)
@@ -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;
+    for (i = next_idx; i < ARRAY_SIZE(bt_mesh.sub); i++) {
+        sub = &bt_mesh.sub[i];
+        if (advertise_subnet(sub)) {
+            next_idx = (i + 1) % ARRAY_SIZE(bt_mesh.sub);
+            return sub;
+        }
+    }
 
-        sub = &bt_mesh.sub[(i + next_idx) % ARRAY_SIZE(bt_mesh.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 = (next_idx + 1) % ARRAY_SIZE(bt_mesh.sub);
+            next_idx = (i + 1) % ARRAY_SIZE(bt_mesh.sub);
             return sub;
         }
     }