Bluetooth: Mesh: Move network startup operations to common function

These are needed both for bt_mesh_provision() as well as persistent
storage-based network creation.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2018-05-07 15:04:21 +03:00 committed by Johan Hedberg
commit 43c7ef3959
4 changed files with 38 additions and 25 deletions

View file

@ -68,31 +68,7 @@ int bt_mesh_provision(const u8_t net_key[16], u16_t net_idx,
bt_mesh_store_iv();
}
if (bt_mesh_beacon_get() == BT_MESH_BEACON_ENABLED) {
bt_mesh_beacon_enable();
} else {
bt_mesh_beacon_disable();
}
if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY) &&
bt_mesh_gatt_proxy_get() != BT_MESH_GATT_PROXY_NOT_SUPPORTED) {
bt_mesh_proxy_gatt_enable();
bt_mesh_adv_update();
}
if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER)) {
bt_mesh_lpn_init();
} else {
bt_mesh_scan_enable();
}
if (IS_ENABLED(CONFIG_BT_MESH_FRIEND)) {
bt_mesh_friend_init();
}
if (IS_ENABLED(CONFIG_BT_MESH_PROV)) {
bt_mesh_prov_complete(net_idx, addr);
}
bt_mesh_net_start();
return 0;
}

View file

@ -34,6 +34,7 @@
#include "foundation.h"
#include "beacon.h"
#include "settings.h"
#include "prov.h"
/* Minimum valid Mesh Network PDU length. The Network headers
* themselves take up 9 bytes. After that there is a minumum of 1 byte
@ -1364,6 +1365,38 @@ static void ivu_complete(struct k_work *work)
bt_mesh_net_iv_update(bt_mesh.iv_index, false);
}
void bt_mesh_net_start(void)
{
if (bt_mesh_beacon_get() == BT_MESH_BEACON_ENABLED) {
bt_mesh_beacon_enable();
} else {
bt_mesh_beacon_disable();
}
if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY) &&
bt_mesh_gatt_proxy_get() != BT_MESH_GATT_PROXY_NOT_SUPPORTED) {
bt_mesh_proxy_gatt_enable();
bt_mesh_adv_update();
}
if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER)) {
bt_mesh_lpn_init();
} else {
bt_mesh_scan_enable();
}
if (IS_ENABLED(CONFIG_BT_MESH_FRIEND)) {
bt_mesh_friend_init();
}
if (IS_ENABLED(CONFIG_BT_MESH_PROV)) {
u16_t net_idx = bt_mesh.sub[0].net_idx;
u16_t addr = bt_mesh_primary_addr();
bt_mesh_prov_complete(net_idx, addr);
}
}
void bt_mesh_net_init(void)
{
k_delayed_work_init(&bt_mesh.ivu_complete, ivu_complete);

View file

@ -316,6 +316,8 @@ void bt_mesh_net_recv(struct net_buf_simple *data, s8_t rssi,
u32_t bt_mesh_next_seq(void);
void bt_mesh_net_start(void);
void bt_mesh_net_init(void);
/* Friendship Credential Management */

View file

@ -495,6 +495,8 @@ static int mesh_commit(void)
bt_mesh.valid = 1;
bt_mesh_net_start();
return 0;
}