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.
This commit is contained in:
lly 2020-05-18 10:39:51 +08:00
parent cb4e8cef87
commit 8e4399bf29

View File

@ -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;
}