Ver Fonte

Merge branch 'bugfix/not_restoring_ble_mesh_cfg_val_v4.0' into 'release/v4.0'

ble_mesh: fix not restoring ble mesh cfg value (v4.0)

See merge request espressif/esp-idf!6276
Jiang Jiang Jian há 6 anos atrás
pai
commit
054e2dbb44

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

@@ -1287,6 +1287,7 @@ typedef union {
      */
      */
     struct ble_mesh_provision_complete_evt_param {
     struct ble_mesh_provision_complete_evt_param {
         uint16_t net_idx;                       /*!< NetKey Index */
         uint16_t net_idx;                       /*!< NetKey Index */
+        uint8_t  net_key[16];                   /*!< NetKey */
         uint16_t addr;                          /*!< Primary address */
         uint16_t addr;                          /*!< Primary address */
         uint8_t  flags;                         /*!< Flags */
         uint8_t  flags;                         /*!< Flags */
         uint32_t iv_index;                      /*!< IV Index */
         uint32_t iv_index;                      /*!< IV Index */

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

@@ -522,7 +522,7 @@ static void btc_ble_mesh_link_close_cb(bt_mesh_prov_bearer_t bearer)
     return;
     return;
 }
 }
 
 
-static void btc_ble_mesh_complete_cb(u16_t net_idx, u16_t addr, u8_t flags, u32_t iv_index)
+static void btc_ble_mesh_complete_cb(u16_t net_idx, const u8_t net_key[16], u16_t addr, u8_t flags, u32_t iv_index)
 {
 {
     esp_ble_mesh_prov_cb_param_t mesh_param = {0};
     esp_ble_mesh_prov_cb_param_t mesh_param = {0};
     btc_msg_t msg = {0};
     btc_msg_t msg = {0};
@@ -531,6 +531,7 @@ static void btc_ble_mesh_complete_cb(u16_t net_idx, u16_t addr, u8_t flags, u32_
     LOG_DEBUG("%s", __func__);
     LOG_DEBUG("%s", __func__);
 
 
     mesh_param.node_prov_complete.net_idx = net_idx;
     mesh_param.node_prov_complete.net_idx = net_idx;
+    memcpy(mesh_param.node_prov_complete.net_key, net_key, 16);
     mesh_param.node_prov_complete.addr = addr;
     mesh_param.node_prov_complete.addr = addr;
     mesh_param.node_prov_complete.flags = flags;
     mesh_param.node_prov_complete.flags = flags;
     mesh_param.node_prov_complete.iv_index = iv_index;
     mesh_param.node_prov_complete.iv_index = iv_index;

+ 2 - 1
components/bt/esp_ble_mesh/mesh_core/include/mesh_main.h

@@ -164,11 +164,12 @@ struct bt_mesh_prov {
      *  assigned the specified NetKeyIndex and primary element address.
      *  assigned the specified NetKeyIndex and primary element address.
      *
      *
      *  @param net_idx  NetKeyIndex given during provisioning.
      *  @param net_idx  NetKeyIndex given during provisioning.
+     *  @param net_key  NetKey given during provisioning.
      *  @param addr     Primary element address.
      *  @param addr     Primary element address.
      *  @param flags    Key Refresh & IV Update flags
      *  @param flags    Key Refresh & IV Update flags
      *  @param iv_index IV Index.
      *  @param iv_index IV Index.
      */
      */
-    void        (*complete)(u16_t net_idx, u16_t addr, u8_t flags, u32_t iv_index);
+    void        (*complete)(u16_t net_idx, const u8_t net_key[16], u16_t addr, u8_t flags, u32_t iv_index);
 
 
     /** @brief Node has been reset.
     /** @brief Node has been reset.
      *
      *

+ 2 - 1
components/bt/esp_ble_mesh/mesh_core/net.c

@@ -1476,11 +1476,12 @@ void bt_mesh_net_start(void)
         u16_t addr = bt_mesh_primary_addr();
         u16_t addr = bt_mesh_primary_addr();
         u32_t iv_index = bt_mesh.iv_index;
         u32_t iv_index = bt_mesh.iv_index;
         u8_t flags = (u8_t)bt_mesh.sub[0].kr_flag;
         u8_t flags = (u8_t)bt_mesh.sub[0].kr_flag;
+        const u8_t *net_key = bt_mesh.sub[0].keys[flags].net;
         if (bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_IVU_IN_PROGRESS)) {
         if (bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_IVU_IN_PROGRESS)) {
             flags |= BLE_MESH_NET_FLAG_IVU;
             flags |= BLE_MESH_NET_FLAG_IVU;
         }
         }
 
 
-        bt_mesh_prov_complete(net_idx, addr, flags, iv_index);
+        bt_mesh_prov_complete(net_idx, net_key, addr, flags, iv_index);
     }
     }
 }
 }
 #endif
 #endif

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

@@ -1744,10 +1744,10 @@ int bt_mesh_prov_init(const struct bt_mesh_prov *prov_info)
     return 0;
     return 0;
 }
 }
 
 
-void bt_mesh_prov_complete(u16_t net_idx, u16_t addr, u8_t flags, u32_t iv_index)
+void bt_mesh_prov_complete(u16_t net_idx, const u8_t net_key[16], u16_t addr, u8_t flags, u32_t iv_index)
 {
 {
     if (prov->complete) {
     if (prov->complete) {
-        prov->complete(net_idx, addr, flags, iv_index);
+        prov->complete(net_idx, net_key, addr, flags, iv_index);
     }
     }
 }
 }
 
 

+ 1 - 1
components/bt/esp_ble_mesh/mesh_core/prov.h

@@ -28,7 +28,7 @@ const struct bt_mesh_prov *bt_mesh_prov_get(void);
 
 
 int bt_mesh_prov_init(const struct bt_mesh_prov *prov);
 int bt_mesh_prov_init(const struct bt_mesh_prov *prov);
 
 
-void bt_mesh_prov_complete(u16_t net_idx, u16_t addr, u8_t flags, u32_t iv_index);
+void bt_mesh_prov_complete(u16_t net_idx, const u8_t net_key[16], u16_t addr, u8_t flags, u32_t iv_index);
 void bt_mesh_prov_reset(void);
 void bt_mesh_prov_reset(void);
 
 
 #endif /* _PROV_H_ */
 #endif /* _PROV_H_ */

+ 1 - 0
components/bt/esp_ble_mesh/mesh_core/settings.c

@@ -538,6 +538,7 @@ static int cfg_set(const char *name)
         return 0;
         return 0;
     }
     }
 
 
+    memcpy(&stored_cfg.cfg, &val, sizeof(val));
     stored_cfg.valid = true;
     stored_cfg.valid = true;
     BT_DBG("Restore configuration state");
     BT_DBG("Restore configuration state");
     return 0;
     return 0;