Kaynağa Gözat

ble_mesh: stack: Fix storing next net_idx and app_idx

lly 5 yıl önce
ebeveyn
işleme
2c8fc5f5d6

+ 1 - 0
components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h

@@ -1132,6 +1132,7 @@ typedef union {
      */
     struct ble_mesh_provisioner_add_local_app_key_comp_param {
         int err_code;                           /*!< Indicate the result of adding local AppKey by the Provisioner */
+        uint16_t net_idx;                       /*!< NetKey Index */
         uint16_t app_idx;                       /*!< AppKey Index */
     } provisioner_add_app_key_comp;             /*!< Event parameter of ESP_BLE_MESH_PROVISIONER_ADD_LOCAL_APP_KEY_COMP_EVT */
     /**

+ 3 - 2
components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c

@@ -1823,10 +1823,11 @@ void btc_ble_mesh_prov_call_handler(btc_msg_t *msg)
             app_key = arg->add_local_app_key.app_key;
         }
         act = ESP_BLE_MESH_PROVISIONER_ADD_LOCAL_APP_KEY_COMP_EVT;
-        param.provisioner_add_app_key_comp.app_idx = arg->add_local_app_key.app_idx;
         param.provisioner_add_app_key_comp.err_code =
             bt_mesh_provisioner_local_app_key_add(app_key, arg->add_local_app_key.net_idx,
                     &arg->add_local_app_key.app_idx);
+        param.provisioner_add_app_key_comp.net_idx = arg->add_local_app_key.net_idx;
+        param.provisioner_add_app_key_comp.app_idx = arg->add_local_app_key.app_idx;
         break;
     }
     case BTC_BLE_MESH_ACT_PROVISIONER_UPDATE_LOCAL_APP_KEY:
@@ -1856,9 +1857,9 @@ void btc_ble_mesh_prov_call_handler(btc_msg_t *msg)
             net_key = arg->add_local_net_key.net_key;
         }
         act = ESP_BLE_MESH_PROVISIONER_ADD_LOCAL_NET_KEY_COMP_EVT;
-        param.provisioner_add_net_key_comp.net_idx = arg->add_local_net_key.net_idx;
         param.provisioner_add_net_key_comp.err_code =
             bt_mesh_provisioner_local_net_key_add(net_key, &arg->add_local_net_key.net_idx);
+        param.provisioner_add_net_key_comp.net_idx = arg->add_local_net_key.net_idx;
         break;
     }
     case BTC_BLE_MESH_ACT_PROVISIONER_UPDATE_LOCAL_NET_KEY:

+ 2 - 0
components/bt/esp_ble_mesh/mesh_core/provisioner_main.c

@@ -1027,6 +1027,7 @@ int bt_mesh_provisioner_local_app_key_add(const u8_t app_key[16],
             }
         }
         *app_idx = key->app_idx;
+        bt_mesh.p_app_idx_next++;
     }
     key->updated = false;
 
@@ -1283,6 +1284,7 @@ int bt_mesh_provisioner_local_net_key_add(const u8_t net_key[16], u16_t *net_idx
             }
         }
         *net_idx = sub->net_idx;
+        bt_mesh.p_net_idx_next++;
     }
     sub->kr_phase = BLE_MESH_KR_NORMAL;
     sub->kr_flag  = false;

+ 2 - 2
components/bt/esp_ble_mesh/mesh_core/settings.c

@@ -2389,7 +2389,7 @@ static void store_p_app_key(struct bt_mesh_app_key *app)
 
 void bt_mesh_store_p_net_idx(void)
 {
-    BT_DBG("p_net_idx_next 0x%03x", bt_mesh.p_net_idx_next);
+    BT_DBG("Store, p_net_idx_next 0x%03x", bt_mesh.p_net_idx_next);
 
     bt_mesh_save_core_settings("mesh/p_netidx",
         (const u8_t *)&bt_mesh.p_net_idx_next, sizeof(bt_mesh.p_net_idx_next));
@@ -2403,7 +2403,7 @@ void bt_mesh_clear_p_net_idx(void)
 
 void bt_mesh_store_p_app_idx(void)
 {
-    BT_DBG("p_app_idx_next 0x%03x", bt_mesh.p_app_idx_next);
+    BT_DBG("Store, p_app_idx_next 0x%03x", bt_mesh.p_app_idx_next);
 
     bt_mesh_save_core_settings("mesh/p_appidx",
         (const u8_t *)&bt_mesh.p_app_idx_next, sizeof(bt_mesh.p_app_idx_next));