From 8e4399bf29eabf9aced01e019a42f62af0c66cf9 Mon Sep 17 00:00:00 2001 From: lly Date: Mon, 18 May 2020 10:39:51 +0800 Subject: [PATCH] ble_mesh: Add init flag for friend init/deinit Since bt_mesh_friend_init() will only be invoked when a device is provisioned or Provisioner is enabled, so we add a flag to indicate if the friend functionality is initialized in case deinit before initialization. --- components/bt/esp_ble_mesh/mesh_core/friend.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/components/bt/esp_ble_mesh/mesh_core/friend.c b/components/bt/esp_ble_mesh/mesh_core/friend.c index cf8c84642a..0c714bc9bd 100644 --- a/components/bt/esp_ble_mesh/mesh_core/friend.c +++ b/components/bt/esp_ble_mesh/mesh_core/friend.c @@ -67,6 +67,8 @@ enum { static void (*friend_cb)(bool establish, u16_t lpn_addr, u8_t reason); +static bool friend_init = false; + static struct bt_mesh_subnet *friend_subnet_get(u16_t net_idx) { struct bt_mesh_subnet *sub = NULL; @@ -1243,6 +1245,11 @@ int bt_mesh_friend_init(void) { int i; + if (friend_init == true) { + BT_WARN("%s, Already", __func__); + return -EALREADY; + } + for (i = 0; i < ARRAY_SIZE(bt_mesh.frnd); i++) { struct bt_mesh_friend *frnd = &bt_mesh.frnd[i]; int j; @@ -1259,6 +1266,8 @@ int bt_mesh_friend_init(void) } } + friend_init = true; + return 0; } @@ -1266,6 +1275,11 @@ int bt_mesh_friend_deinit(void) { int i; + if (friend_init == false) { + BT_WARN("%s, Already", __func__); + return -EALREADY; + } + bt_mesh_friend_clear_net_idx(BLE_MESH_KEY_ANY); for (i = 0; i < ARRAY_SIZE(bt_mesh.frnd); i++) { @@ -1280,6 +1294,8 @@ int bt_mesh_friend_deinit(void) bt_mesh_unref_buf_from_pool(&friend_buf_pool); memset(adv_pool, 0, sizeof(adv_pool)); + friend_init = false; + return 0; }