From 35353de137b2e9f167be753b5321ae659e1803e4 Mon Sep 17 00:00:00 2001 From: lly Date: Fri, 11 Oct 2019 09:51:02 +0800 Subject: [PATCH] ble_mesh: fix not callback net_key when device is provisioned --- components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h | 1 + components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c | 3 ++- components/bt/esp_ble_mesh/mesh_core/include/mesh_main.h | 3 ++- components/bt/esp_ble_mesh/mesh_core/net.c | 3 ++- components/bt/esp_ble_mesh/mesh_core/prov.c | 4 ++-- components/bt/esp_ble_mesh/mesh_core/prov.h | 2 +- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h b/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h index 9166af62c..9696bb48c 100644 --- a/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h +++ b/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h @@ -1287,6 +1287,7 @@ typedef union { */ struct ble_mesh_provision_complete_evt_param { uint16_t net_idx; /*!< NetKey Index */ + uint8_t net_key[16]; /*!< NetKey */ uint16_t addr; /*!< Primary address */ uint8_t flags; /*!< Flags */ uint32_t iv_index; /*!< IV Index */ diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c index 12080d51b..09aa53125 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c +++ b/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; } -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}; 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__); 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.flags = flags; mesh_param.node_prov_complete.iv_index = iv_index; diff --git a/components/bt/esp_ble_mesh/mesh_core/include/mesh_main.h b/components/bt/esp_ble_mesh/mesh_core/include/mesh_main.h index 374c6a077..1a79a7a1e 100644 --- a/components/bt/esp_ble_mesh/mesh_core/include/mesh_main.h +++ b/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. * * @param net_idx NetKeyIndex given during provisioning. + * @param net_key NetKey given during provisioning. * @param addr Primary element address. * @param flags Key Refresh & IV Update flags * @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. * diff --git a/components/bt/esp_ble_mesh/mesh_core/net.c b/components/bt/esp_ble_mesh/mesh_core/net.c index ad778269a..63d875f35 100644 --- a/components/bt/esp_ble_mesh/mesh_core/net.c +++ b/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(); u32_t iv_index = bt_mesh.iv_index; 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)) { 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 diff --git a/components/bt/esp_ble_mesh/mesh_core/prov.c b/components/bt/esp_ble_mesh/mesh_core/prov.c index 63848eaa5..63ba90acb 100644 --- a/components/bt/esp_ble_mesh/mesh_core/prov.c +++ b/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; } -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) { - prov->complete(net_idx, addr, flags, iv_index); + prov->complete(net_idx, net_key, addr, flags, iv_index); } } diff --git a/components/bt/esp_ble_mesh/mesh_core/prov.h b/components/bt/esp_ble_mesh/mesh_core/prov.h index f96ed7707..610e55c6d 100644 --- a/components/bt/esp_ble_mesh/mesh_core/prov.h +++ b/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); -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); #endif /* _PROV_H_ */