Bluetooth: Mesh: Fix calling complete callback for bt_mesh_provision()
If the app does direct provisioning, it may still want to do common
handling through its provisioning complete callback (if it has one
registered). This also means that we always require a non-NULL
provisioning context provided to bt_enable(), and that it needs to
fail if NULL was given.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
diff --git a/subsys/bluetooth/host/mesh/main.c b/subsys/bluetooth/host/mesh/main.c
index b0f7ed2..410170b 100644
--- a/subsys/bluetooth/host/mesh/main.c
+++ b/subsys/bluetooth/host/mesh/main.c
@@ -89,6 +89,10 @@
bt_mesh_friend_init();
}
+ if (IS_ENABLED(CONFIG_BT_MESH_PROV)) {
+ bt_mesh_prov_complete(net_idx, addr);
+ }
+
return 0;
}
diff --git a/subsys/bluetooth/host/mesh/prov.c b/subsys/bluetooth/host/mesh/prov.c
index 9166732..1a01ab9 100644
--- a/subsys/bluetooth/host/mesh/prov.c
+++ b/subsys/bluetooth/host/mesh/prov.c
@@ -1049,10 +1049,6 @@
link.expect = 0;
bt_mesh_provision(pdu, net_idx, flags, iv_index, 0, addr, dev_key);
-
- if (prov->complete) {
- prov->complete(net_idx, addr);
- }
}
static void prov_complete(const u8_t *data)
@@ -1523,11 +1519,15 @@
int bt_mesh_prov_init(const struct bt_mesh_prov *prov_info)
{
- int err;
-
static struct bt_pub_key_cb pub_key_cb = {
.func = pub_key_ready,
};
+ int err;
+
+ if (!prov_info) {
+ BT_ERR("No provisioning context provided");
+ return -EINVAL;
+ }
err = bt_pub_key_gen(&pub_key_cb);
if (err) {
@@ -1559,6 +1559,13 @@
return 0;
}
+void bt_mesh_prov_complete(u16_t net_idx, u16_t addr)
+{
+ if (prov->complete) {
+ prov->complete(net_idx, addr);
+ }
+}
+
void bt_mesh_prov_reset(void)
{
if (prov->reset) {
diff --git a/subsys/bluetooth/host/mesh/prov.h b/subsys/bluetooth/host/mesh/prov.h
index 778356a..482a38f 100644
--- a/subsys/bluetooth/host/mesh/prov.h
+++ b/subsys/bluetooth/host/mesh/prov.h
@@ -18,4 +18,5 @@
int bt_mesh_prov_init(const struct bt_mesh_prov *prov);
+void bt_mesh_prov_complete(u16_t net_idx, u16_t addr);
void bt_mesh_prov_reset(void);