mesh: split prov.c into two separate modules

Currently all provisioning procedure into common source
files call `prov.c`, that will not compile separately.

Add `BT_MESH_NODE` to control whether nodes are supported
and device provisioning is supported, this will be used in
provisioner role.

Add more provisioner OOB authentication method.

this is port of 5374245dd66e630932267663546d5f1108aff9b5 with patch
0bcd66ac36d8c02d2c3b3851c4086e8b692578a6
diff --git a/nimble/host/mesh/include/mesh/glue.h b/nimble/host/mesh/include/mesh/glue.h
index c7d104a..6d080f3 100644
--- a/nimble/host/mesh/include/mesh/glue.h
+++ b/nimble/host/mesh/include/mesh/glue.h
@@ -402,6 +402,7 @@
 #define CONFIG_BT_SETTINGS                    BLE_MESH_SETTINGS
 #define CONFIG_SETTINGS                       BLE_MESH_SETTINGS
 #define CONFIG_BT_MESH_PROVISIONER            BLE_MESH_PROVISIONER
+#define CONFIG_BT_MESH_PROV_DEVICE            BLE_MESH_PROV_DEVICE
 
 /* Above flags are used with IS_ENABLED macro */
 #define IS_ENABLED(config) MYNEWT_VAL(config)
diff --git a/nimble/host/mesh/include/mesh/main.h b/nimble/host/mesh/include/mesh/main.h
index c0ef04d..91b2e7d 100644
--- a/nimble/host/mesh/include/mesh/main.h
+++ b/nimble/host/mesh/include/mesh/main.h
@@ -59,6 +59,33 @@
 	BT_MESH_PROV_OOB_ON_DEV    = BIT(15),
 } bt_mesh_prov_oob_info_t;
 
+/** Device Capabilities. */
+struct bt_mesh_dev_capabilities {
+	/** Number of elements supported by the device */
+	uint8_t elem_count;
+
+	/** Supported algorithms and other capabilities */
+	uint16_t algorithms;
+
+	/** Supported public key types */
+	uint8_t pub_key_type;
+
+	/** Supported static OOB Types */
+	uint8_t static_oob;
+
+	/** Supported Output OOB Actions */
+	bt_mesh_output_action_t output_actions;
+
+	/** Supported Input OOB Actions */
+	bt_mesh_input_action_t input_actions;
+
+	/** Maximum size of Output OOB supported */
+	uint8_t output_size;
+
+	/** Maximum size in octets of Input OOB supported */
+	uint8_t input_size;
+};
+
 /** Provisioning properties & capabilities. */
 struct bt_mesh_prov {
 	/** The UUID that's used when advertising as unprovisioned */
@@ -89,6 +116,21 @@
 	/** Supported Input OOB Actions */
 	uint16_t       input_actions;
 
+	/** @brief Provisioning Capabilities.
+	 *
+	 *  This callback notifies the application that the provisioning capabilities
+	 *  of the unprovisioned device has been received.
+	 *
+	 *  The application can consequently call bt_mesh_auth_method_set_<*> to
+	 *  select suitable provisioning oob authentication method.
+	 *
+	 *  When this callback returns, the provisioner will start authentication with
+	 *  the chosen method.
+	 *
+	 *  @param cap capabilities supported by device.
+	 */
+	void         (*capabilities)(const struct bt_mesh_dev_capabilities *cap);
+
 	/** @brief Output of a number is requested.
 	 *
 	 *  This callback notifies the application that it should
@@ -226,6 +268,89 @@
  */
 int bt_mesh_input_number(uint32_t num);
 
+/** @brief Provide Device public key.
+ *
+ *  @param public_key Device public key.
+ *
+ *  @return Zero on success or (negative) error code otherwise.
+ */
+int bt_mesh_prov_remote_pub_key_set(const uint8_t public_key[64]);
+
+/** @brief Use Input OOB authentication.
+ *
+ *  Provisioner only.
+ *
+ *  Instruct the unprovisioned device to use the specified Input OOB
+ *  authentication action. When using @ref BT_MESH_PUSH, @ref BT_MESH_TWIST or
+ *  @ref BT_MESH_ENTER_NUMBER, the @ref bt_mesh_prov::output_number callback is
+ *  called with a random number that has to be entered on the unprovisioned
+ *  device.
+ *
+ *  When using @ref BT_MESH_ENTER_STRING, the @ref bt_mesh_prov::output_string
+ *  callback is called with a random string that has to be entered on the
+ *  unprovisioned device.
+ *
+ *  @param action Authentication action used by the unprovisioned device.
+ *  @param size Authentication size.
+ *
+ *  @return Zero on success or (negative) error code otherwise.
+ */
+int bt_mesh_auth_method_set_input(bt_mesh_input_action_t action, uint8_t size);
+
+/** @brief Use Output OOB authentication.
+ *
+ *  Provisioner only.
+ *
+ *  Instruct the unprovisioned device to use the specified Output OOB
+ *  authentication action. The @ref bt_mesh_prov::input callback will
+ *  be called.
+ *
+ *  When using @ref BT_MESH_BLINK, @ref BT_MESH_BEEP, @ref BT_MESH_VIBRATE
+ *  or @ref BT_MESH_DISPLAY_NUMBER, and the application has to call
+ *  @ref bt_mesh_input_number with the random number indicated by
+ *  the unprovisioned device.
+ *
+ *  When using @ref BT_MESH_DISPLAY_STRING, the application has to call
+ *  @ref bt_mesh_input_string with the random string displayed by the
+ *  unprovisioned device.
+ *
+ *  @param action Authentication action used by the unprovisioned device.
+ *  @param size Authentication size.
+ *
+ *  @return Zero on success or (negative) error code otherwise.
+ */
+int bt_mesh_auth_method_set_output(bt_mesh_output_action_t action, uint8_t size);
+
+/** @brief Use static OOB authentication.
+ *
+ *  Provisioner only.
+ *
+ *  Instruct the unprovisioned device to use static OOB authentication, and use
+ *  the given static authentication value when provisioning.
+ *
+ *  @param static_val Static OOB value.
+ *  @param size Static OOB value size.
+ *
+ *  @return Zero on success or (negative) error code otherwise.
+ */
+int bt_mesh_auth_method_set_static(const uint8_t *static_val, uint8_t size);
+
+/** @brief Don't use OOB authentication.
+ *
+ *  Provisioner only.
+ *
+ *  Don't use any authentication when provisioning new devices. This is the
+ *  default behavior.
+ *
+ *  @warning Not using any authentication exposes the mesh network to
+ *           impersonation attacks, where attackers can pretend to be the
+ *           unprovisioned device to gain access to the network. Authentication
+ *           is strongly encouraged.
+ *
+ *  @return Zero on success or (negative) error code otherwise.
+ */
+int bt_mesh_auth_method_set_none(void);
+
 /** @brief Enable specific provisioning bearers
  *
  *  Enable one or more provisioning bearers.
diff --git a/nimble/host/mesh/src/beacon.c b/nimble/host/mesh/src/beacon.c
index f83ed55..6ea282f 100644
--- a/nimble/host/mesh/src/beacon.c
+++ b/nimble/host/mesh/src/beacon.c
@@ -229,7 +229,7 @@
 static void beacon_send(struct ble_npl_event *work)
 {
 	/* Don't send anything if we have an active provisioning link */
-	if ((MYNEWT_VAL(BLE_MESH_PROV)) && bt_prov_active()) {
+	if (IS_ENABLED(CONFIG_BT_MESH_PB_ADV) && bt_mesh_prov_active()) {
 		k_delayed_work_submit(&beacon_timer,
 							  K_SECONDS(MYNEWT_VAL(BLE_MESH_UNPROV_BEACON_INT)));
 		return;
diff --git a/nimble/host/mesh/src/mesh.c b/nimble/host/mesh/src/mesh.c
index 0d68c25..a9b563e 100644
--- a/nimble/host/mesh/src/mesh.c
+++ b/nimble/host/mesh/src/mesh.c
@@ -18,6 +18,7 @@
 
 #include "adv.h"
 #include "prov.h"
+#include "provisioner.h"
 #include "net.h"
 #include "app_keys.h"
 #include "rpl.h"
diff --git a/nimble/host/mesh/src/pb_adv.c b/nimble/host/mesh/src/pb_adv.c
index 26c6565..40513ef 100644
--- a/nimble/host/mesh/src/pb_adv.c
+++ b/nimble/host/mesh/src/pb_adv.c
@@ -16,7 +16,7 @@
 #include "adv.h"
 #include "crypto.h"
 #include "beacon.h"
-#include "prov_bearer.h"
+#include "prov.h"
 #include "mesh/glue.h"
 
 #define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_PROV)
@@ -61,20 +61,20 @@
 #define RETRANSMITS_ACK        2
 
 enum {
-	LINK_ACTIVE,    /* Link has been opened */
-	LINK_ACK_RECVD, /* Ack for link has been received */
-	LINK_CLOSING,   /* Link is closing down */
-	LINK_INVALID,   /* Error occurred during provisioning */
-	ACK_PENDING,    /* An acknowledgment is being sent */
-	PROVISIONER,    /* The link was opened as provisioner */
+	ADV_LINK_ACTIVE,    	/* Link has been opened */
+	ADV_LINK_ACK_RECVD, 	/* Ack for link has been received */
+	ADV_LINK_CLOSING,   	/* Link is closing down */
+	ADV_LINK_INVALID,   	/* Error occurred during provisioning */
+	ADV_ACK_PENDING,    	/* An acknowledgment is being sent */
+	ADV_PROVISIONER,    	/* The link was opened as provisioner */
 
-	NUM_FLAGS,
+	ADV_NUM_FLAGS,
 };
 
 struct pb_adv {
 	uint32_t id; /* Link ID */
 
-	ATOMIC_DEFINE(flags, NUM_FLAGS);
+	ATOMIC_DEFINE(flags, ADV_NUM_FLAGS);
 
 	const struct prov_bearer_cb *cb;
 	void *cb_data;
@@ -190,7 +190,7 @@
 
 	k_delayed_work_cancel(&link.prot_timer);
 
-	if (atomic_test_bit(link.flags, PROVISIONER)) {
+	if (atomic_test_bit(link.flags, ADV_PROVISIONER)) {
 		/* Clear everything except the retransmit and protocol timer
 		 * delayed work objects.
 		 */
@@ -235,19 +235,19 @@
 static void ack_complete(uint16_t duration, int err, void *user_data)
 {
 	BT_DBG("xact 0x%x complete", (uint8_t)link.tx.pending_ack);
-	atomic_clear_bit(link.flags, ACK_PENDING);
+	atomic_clear_bit(link.flags, ADV_ACK_PENDING);
 }
 
 static bool ack_pending(void)
 {
-	return atomic_test_bit(link.flags, ACK_PENDING);
+	return atomic_test_bit(link.flags, ADV_ACK_PENDING);
 }
 
 static void prov_failed(uint8_t err)
 {
 	BT_DBG("%u", err);
 	link.cb->error(&pb_adv, link.cb_data, err);
-	atomic_set_bit(link.flags, LINK_INVALID);
+	atomic_set_bit(link.flags, ADV_LINK_INVALID);
 }
 
 static void prov_msg_recv(void)
@@ -261,7 +261,7 @@
 
 	gen_prov_ack_send(link.rx.id);
 
-	if (atomic_test_bit(link.flags, LINK_INVALID)) {
+	if (atomic_test_bit(link.flags, ADV_LINK_INVALID)) {
 		BT_WARN("Unexpected msg 0x%02x on invalidated link",
 			link.rx.buf->om_data[0]);
 		prov_failed(PROV_ERR_UNEXP_PDU);
@@ -289,7 +289,7 @@
 	};
 	const struct bt_mesh_send_cb *complete;
 	struct os_mbuf *buf;
-	bool pending = atomic_test_and_set_bit(link.flags, ACK_PENDING);
+	bool pending = atomic_test_and_set_bit(link.flags, ADV_ACK_PENDING);
 
 	BT_DBG("xact_id 0x%x", xact_id);
 
@@ -300,7 +300,7 @@
 
 	buf = adv_buf_create(RETRANSMITS_ACK);
 	if (!buf) {
-		atomic_clear_bit(link.flags, ACK_PENDING);
+		atomic_clear_bit(link.flags, ADV_ACK_PENDING);
 		return;
 	}
 
@@ -392,8 +392,8 @@
 	}
 
 	if (rx->xact_id == link.tx.id) {
-		/* Don't clear resending of LINK_CLOSE messages */
-		if (!atomic_test_bit(link.flags, LINK_CLOSING)) {
+		/* Don't clear resending of link_close messages */
+		if (!atomic_test_bit(link.flags, ADV_LINK_CLOSING)) {
 			prov_clear_tx();
 		}
 
@@ -479,14 +479,14 @@
 		link_open(rx, buf);
 		break;
 	case LINK_ACK:
-		if (!atomic_test_bit(link.flags, LINK_ACTIVE)) {
+		if (!atomic_test_bit(link.flags, ADV_LINK_ACTIVE)) {
 			return;
 		}
 
 		link_ack(rx, buf);
 		break;
 	case LINK_CLOSE:
-		if (!atomic_test_bit(link.flags, LINK_ACTIVE)) {
+		if (!atomic_test_bit(link.flags, ADV_LINK_ACTIVE)) {
 			return;
 		}
 
@@ -521,7 +521,7 @@
 		return;
 	}
 
-	if (!atomic_test_bit(link.flags, LINK_ACTIVE) &&
+	if (!atomic_test_bit(link.flags, ADV_LINK_ACTIVE) &&
 	    gen_prov[GPCF(rx->gpc)].require_link) {
 		BT_DBG("Ignoring message that requires active link");
 		return;
@@ -561,24 +561,24 @@
 
 	BT_DBG("");
 
-	if (!atomic_test_bit(link.flags, LINK_ACTIVE)) {
+	if (!atomic_test_bit(link.flags, ADV_LINK_ACTIVE)) {
 		BT_WARN("Link not active");
 		return;
 	}
 
 	/*
 	 * According to mesh profile spec (5.3.1.4.3), the close message should
-	 * be restransmitted at least three times. Retransmit the LINK_CLOSE
+	 * be restransmitted at least three times. Retransmit the link_close
 	 * message until CLOSING_TIMEOUT has elapsed.
 	 */
-	if (atomic_test_bit(link.flags, LINK_CLOSING)) {
+	if (atomic_test_bit(link.flags, ADV_LINK_CLOSING)) {
 		timeout = CLOSING_TIMEOUT;
 	} else {
 		timeout = TRANSACTION_TIMEOUT;
 	}
 
 	if (k_uptime_get() - link.tx.start > timeout) {
-		if (atomic_test_bit(link.flags, LINK_CLOSING)) {
+		if (atomic_test_bit(link.flags, ADV_LINK_CLOSING)) {
 			close_link(PROV_BEARER_LINK_STATUS_SUCCESS);
 		} else {
 			BT_WARN("Giving up transaction");
@@ -721,7 +721,7 @@
 		return;
 	}
 
-	if (atomic_test_bit(link.flags, LINK_ACTIVE)) {
+	if (atomic_test_bit(link.flags, ADV_LINK_ACTIVE)) {
 		/* Send another link ack if the provisioner missed the last */
 		if (link.id == rx->link_id && link.tx.id == 0x7F) {
 			BT_DBG("Resending link ack");
@@ -739,7 +739,7 @@
 	}
 
 	link.id = rx->link_id;
-	atomic_set_bit(link.flags, LINK_ACTIVE);
+	atomic_set_bit(link.flags, ADV_LINK_ACTIVE);
 	os_mbuf_reset(link.rx.buf);
 
 	bearer_ctl_send(LINK_ACK, NULL, 0, false);
@@ -751,8 +751,8 @@
 {
 	BT_DBG("len %u", buf->om_len);
 
-	if (atomic_test_bit(link.flags, PROVISIONER)) {
-		if (atomic_test_and_set_bit(link.flags, LINK_ACK_RECVD)) {
+	if (atomic_test_bit(link.flags, ADV_PROVISIONER)) {
+		if (atomic_test_and_set_bit(link.flags, ADV_LINK_ACK_RECVD)) {
 			return;
 		}
 
@@ -794,7 +794,7 @@
 	rx.xact_id = net_buf_simple_pull_u8(buf);
 	rx.gpc = net_buf_simple_pull_u8(buf);
 
-	if (atomic_test_bit(link.flags, LINK_ACTIVE) && link.id != rx.link_id) {
+	if (atomic_test_bit(link.flags, ADV_LINK_ACTIVE) && link.id != rx.link_id) {
 		return;
 	}
 
@@ -808,11 +808,11 @@
 {
 	BT_DBG("uuid %s", bt_hex(uuid, 16));
 
-	if (atomic_test_and_set_bit(link.flags, LINK_ACTIVE)) {
+	if (atomic_test_and_set_bit(link.flags, ADV_LINK_ACTIVE)) {
 		return -EBUSY;
 	}
 
-	atomic_set_bit(link.flags, PROVISIONER);
+	atomic_set_bit(link.flags, ADV_PROVISIONER);
 
 	bt_rand(&link.id, sizeof(link.id));
 	link.tx.id = XACT_ID_MAX;
@@ -829,7 +829,7 @@
 
 static int prov_link_accept(const struct prov_bearer_cb *cb, void *cb_data)
 {
-	if (atomic_test_bit(link.flags, LINK_ACTIVE)) {
+	if (atomic_test_bit(link.flags, ADV_LINK_ACTIVE)) {
 		return -EBUSY;
 	}
 
@@ -848,7 +848,7 @@
 
 static void prov_link_close(enum prov_bearer_link_status status)
 {
-	if (atomic_test_and_set_bit(link.flags, LINK_CLOSING)) {
+	if (atomic_test_and_set_bit(link.flags, ADV_LINK_CLOSING)) {
 		return;
 	}
 
diff --git a/nimble/host/mesh/src/pb_gatt.c b/nimble/host/mesh/src/pb_gatt.c
index 7d0f429..5af8c90 100644
--- a/nimble/host/mesh/src/pb_gatt.c
+++ b/nimble/host/mesh/src/pb_gatt.c
@@ -11,7 +11,7 @@
 #include "net.h"
 #include "proxy.h"
 #include "adv.h"
-#include "prov_bearer.h"
+#include "prov.h"
 
 #define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_PROV)
 #define LOG_MODULE_NAME bt_mesh_pb_gatt
@@ -148,6 +148,10 @@
 	k_delayed_work_init(&link.prot_timer, protocol_timeout);
 }
 
+void pb_gatt_reset(void)
+{
+	reset_state();
+}
 const struct prov_bearer pb_gatt = {
 	.type = BT_MESH_PROV_GATT,
 	.link_accept = link_accept,
diff --git a/nimble/host/mesh/src/prov.c b/nimble/host/mesh/src/prov.c
index 2d2b15f..b2baf32 100644
--- a/nimble/host/mesh/src/prov.c
+++ b/nimble/host/mesh/src/prov.c
@@ -16,344 +16,48 @@
 
 #include "crypto.h"
 #include "atomic.h"
-#include "adv.h"
 #include "net.h"
-#include "rpl.h"
-#include "beacon.h"
 #include "access.h"
 #include "foundation.h"
-#include "proxy.h"
 #include "prov.h"
 #include "testing.h"
-#include "settings.h"
-#include "prov_bearer.h"
 
-#define AUTH_METHOD_NO_OOB     0x00
-#define AUTH_METHOD_STATIC     0x01
-#define AUTH_METHOD_OUTPUT     0x02
-#define AUTH_METHOD_INPUT      0x03
+struct bt_mesh_prov_link bt_mesh_prov_link;
+const struct bt_mesh_prov *bt_mesh_prov;
 
-#define OUTPUT_OOB_BLINK       0x00
-#define OUTPUT_OOB_BEEP        0x01
-#define OUTPUT_OOB_VIBRATE     0x02
-#define OUTPUT_OOB_NUMBER      0x03
-#define OUTPUT_OOB_STRING      0x04
-
-#define INPUT_OOB_PUSH         0x00
-#define INPUT_OOB_TWIST        0x01
-#define INPUT_OOB_NUMBER       0x02
-#define INPUT_OOB_STRING       0x03
-
-#define PUB_KEY_NO_OOB         0x00
-#define PUB_KEY_OOB            0x01
-
-#define PROV_INVITE            0x00
-#define PROV_CAPABILITIES      0x01
-#define PROV_START             0x02
-#define PROV_PUB_KEY           0x03
-#define PROV_INPUT_COMPLETE    0x04
-#define PROV_CONFIRM           0x05
-#define PROV_RANDOM            0x06
-#define PROV_DATA              0x07
-#define PROV_COMPLETE          0x08
-#define PROV_FAILED            0x09
-
-#define PROV_NO_PDU            0xff
-
-#define PROV_ALG_P256          0x00
-
-enum {
-	WAIT_PUB_KEY,           /* Waiting for local PubKey to be generated */
-	LINK_ACTIVE,            /* Link has been opened */
-	WAIT_NUMBER,            /* Waiting for number input from user */
-	WAIT_STRING,            /* Waiting for string input from user */
-	NOTIFY_INPUT_COMPLETE,  /* Notify that input has been completed. */
-	PROVISIONER,            /* The link was opened as provisioner */
-	PUB_KEY_SENT,           /* Public key has been sent */
-	INPUT_COMPLETE,         /* Device input completed */
-
-	NUM_FLAGS,
-};
-
-struct provisioner_link {
-	struct bt_mesh_cdb_node *node;
-	uint16_t addr;
-	uint16_t net_idx;
-	uint8_t  attention_duration;
-	uint8_t  uuid[16];
-};
-
-struct prov_link {
-	ATOMIC_DEFINE(flags, NUM_FLAGS);
-#if defined(CONFIG_BT_MESH_PROVISIONER)
-	struct provisioner_link provisioner;
-#endif
-
-	uint8_t  dhkey[32];         /* Calculated DHKey */
-	uint8_t  expect;            /* Next expected PDU */
-
-	uint8_t  oob_method;
-	uint8_t  oob_action;
-	uint8_t  oob_size;
-
-	uint8_t  conf[16];          /* Remote Confirmation */
-	uint8_t  rand[16];          /* Local Random */
-	uint8_t  auth[16];          /* Authentication Value */
-
-	uint8_t  conf_salt[16];     /* ConfirmationSalt */
-	uint8_t  conf_key[16];      /* ConfirmationKey */
-	uint8_t  conf_inputs[145];  /* ConfirmationInputs */
-	uint8_t  prov_salt[16];     /* Provisioning Salt */
-
-	const struct prov_bearer *bearer;
-};
-
-#define PROV_BUF(len) NET_BUF_SIMPLE(PROV_BEARER_BUF_HEADROOM + len)
-
-static struct prov_link link;
-
-static const struct bt_mesh_prov *prov;
-
-static void send_pub_key(void);
-static void pub_key_ready(const uint8_t *pkey);
-
-static int reset_state(void)
+static void pub_key_ready(const uint8_t *pkey)
 {
-	static struct bt_pub_key_cb pub_key_cb = {
-		.func = pub_key_ready,
-	};
+	if (!pkey) {
+		BT_WARN("Public key not available");
+		return;
+	}
+	BT_DBG("Local public key ready");
+}
+
+int bt_mesh_prov_reset_state(void (*func)(const uint8_t key[64]))
+{
 	int err;
+	static struct bt_pub_key_cb pub_key_cb;
+	const size_t offset = offsetof(struct bt_mesh_prov_link, dhkey);
+
+	pub_key_cb.func = func ? func : pub_key_ready;
 
 	/* Disable Attention Timer if it was set */
-	if (link.conf_inputs[0]) {
+	if (bt_mesh_prov_link.conf_inputs[0]) {
 		bt_mesh_attention(NULL, 0);
 	}
 
-#if defined (CONFIG_BT_MESH_PROVISIONER)
-	if (link.provisioner.node != NULL) {
-		bt_mesh_cdb_node_del(link.provisioner.node, false);
-	}
-#endif
-
-	memset(&link, 0, sizeof(link));
+	(void)memset((uint8_t *)&bt_mesh_prov_link + offset, 0,
+		     sizeof(bt_mesh_prov_link) - offset);
 
 	err = bt_pub_key_gen(&pub_key_cb);
 	if (err) {
 		BT_ERR("Failed to generate public key (%d)", err);
 		return err;
 	}
-
 	return 0;
 }
 
-static inline int prov_send(struct os_mbuf *buf,
-			   				prov_bearer_send_complete_t cb)
-{
-	return link.bearer->send(buf, cb, NULL);
-}
-
-static void prov_buf_init(struct os_mbuf *buf, uint8_t type)
-{
-	net_buf_simple_init(buf, PROV_BEARER_BUF_HEADROOM);
-	net_buf_simple_add_u8(buf, type);
-}
-
-static void prov_link_close(enum prov_bearer_link_status status)
-{
-	BT_DBG("%u", status);
-	link.expect = PROV_NO_PDU;
-
-	link.bearer->link_close(status);
-}
-
-static void prov_send_fail_msg(uint8_t err)
-{
-	struct os_mbuf *buf = PROV_BUF(2);
-
-	BT_DBG("%u", err);
-
-	link.expect = PROV_NO_PDU;
-	
-	prov_buf_init(buf, PROV_FAILED);
-	net_buf_simple_add_u8(buf, err);
-
-	if (prov_send(buf, NULL)) {
-		BT_ERR("Failed to send Provisioning Failed message");
-	}
-
-	os_mbuf_free_chain(buf);
-}
-
-static void prov_fail(uint8_t reason)
-{
-	/* According to Bluetooth Mesh Specification v1.0.1, Section 5.4.4, the
-	 * provisioner just closes the link when something fails, while the
-	 * provisionee sends the fail message, and waits for the provisioner to
-	 * close the link.
-	 */
-	if (atomic_test_bit(link.flags, PROVISIONER)) {
-		prov_link_close(PROV_BEARER_LINK_STATUS_FAIL);
-	} else {
-		prov_send_fail_msg(reason);
-	}
-}
-
-static void prov_invite(const uint8_t *data)
-{
-	struct os_mbuf *buf = PROV_BUF(12);
-
-	BT_DBG("Attention Duration: %u seconds", data[0]);
-
-	if (data[0]) {
-		bt_mesh_attention(NULL, data[0]);
-	}
-
-	link.conf_inputs[0] = data[0];
-
-	prov_buf_init(buf, PROV_CAPABILITIES);
-
-	/* Number of Elements supported */
-	net_buf_simple_add_u8(buf, bt_mesh_elem_count());
-
-	/* Supported algorithms - FIPS P-256 Eliptic Curve */
-	net_buf_simple_add_be16(buf, BIT(PROV_ALG_P256));
-
-	/* Public Key Type, Only "No OOB" Public Key is supported*/
-	net_buf_simple_add_u8(buf, PUB_KEY_NO_OOB);
-
-	/* Static OOB Type */
-	net_buf_simple_add_u8(buf, prov->static_val ? BIT(0) : 0x00);
-
-	/* Output OOB Size */
-	net_buf_simple_add_u8(buf, prov->output_size);
-
-	/* Output OOB Action */
-	net_buf_simple_add_be16(buf, prov->output_actions);
-
-	/* Input OOB Size */
-	net_buf_simple_add_u8(buf, prov->input_size);
-
-	/* Input OOB Action */
-	net_buf_simple_add_be16(buf, prov->input_actions);
-
-	memcpy(&link.conf_inputs[1], &buf->om_data[1], 11);
-
-	if (prov_send(buf, NULL)) {
-		BT_ERR("Failed to send capabilities");
-		goto done;
-	}
-
-	link.expect = PROV_START;
-
-done:
-	os_mbuf_free_chain(buf);
-}
-
-#if defined(CONFIG_BT_MESH_PROVISIONER)
-static void start_sent(int err, void *cb_data);
-
-static void send_invite(void)
-{
-	struct os_mbuf *inv = PROV_BUF(2);
-
-	BT_DBG("");
-
-	prov_buf_init(inv, PROV_INVITE);
-	net_buf_simple_add_u8(inv, link.provisioner.attention_duration);
-
-	link.conf_inputs[0] = link.provisioner.attention_duration;
-
-	if (prov_send(inv, NULL)) {
-		BT_ERR("Failed to send invite");
-		goto done;
-	}
-
-	link.expect = PROV_CAPABILITIES;
-
-done:
-	os_mbuf_free_chain(inv);
-}
-
-static void send_start(void)
-{
-	struct os_mbuf *start = PROV_BUF(6);
-
-	BT_DBG("");
-
-	prov_buf_init(start, PROV_START);
-
-	net_buf_simple_add_u8(start, PROV_ALG_P256);
-	net_buf_simple_add_u8(start, PUB_KEY_NO_OOB);
-	net_buf_simple_add_u8(start, AUTH_METHOD_NO_OOB);
-	memset(link.auth, 0, sizeof(link.auth));
-
-	net_buf_simple_add_u8(start, 0); /* Auth Action */
-	net_buf_simple_add_u8(start, 0); /* Auth Size */
-
-	memcpy(&link.conf_inputs[12], &start->om_data[1], 5);
-
-	if (prov_send(start, start_sent)) {
-		BT_ERR("Failed to send start");
-	}
-
-	os_mbuf_free_chain(start);
-}
-
-static void start_sent(int err, void *cb_data)
-{
-	if (!bt_pub_key_get()) {
-		atomic_set_bit(link.flags, WAIT_PUB_KEY);
-		BT_WARN("Waiting for local public key");
-	} else {
-		send_pub_key();
-	}
-}
-#endif
-
-static void prov_capabilities(const uint8_t *data)
-{
-#if defined(CONFIG_BT_MESH_PROVISIONER)
-	uint16_t algorithms, output_action, input_action;
-
-	BT_DBG("Elements: %u", data[0]);
-
-	algorithms = sys_get_be16(&data[1]);
-	BT_DBG("Algorithms:        %u", algorithms);
-
-	BT_DBG("Public Key Type:   0x%02x", data[3]);
-	BT_DBG("Static OOB Type:   0x%02x", data[4]);
-	BT_DBG("Output OOB Size:   %u", data[5]);
-
-	output_action = sys_get_be16(&data[6]);
-	BT_DBG("Output OOB Action: 0x%04x", output_action);
-
-	BT_DBG("Input OOB Size:    %u", data[8]);
-
-	input_action = sys_get_be16(&data[9]);
-	BT_DBG("Input OOB Action:  0x%04x", input_action);
-
-	if (data[0] == 0) {
-		BT_ERR("Invalid number of elements");
-		prov_fail(PROV_ERR_NVAL_FMT);
-		return;
-	}
-
-	link.provisioner.node =
-		bt_mesh_cdb_node_alloc(link.provisioner.uuid,
-				       link.provisioner.addr, data[0],
-				       link.provisioner.net_idx);
-	if (link.provisioner.node == NULL) {
-		BT_ERR("Failed allocating node 0x%04x", link.provisioner.addr);
-		prov_fail(PROV_ERR_RESOURCES);
-		return;
-	}
-
-	memcpy(&link.conf_inputs[1], data, 11);
-
-	send_start();
-#endif
-}
-
 static bt_mesh_output_action_t output_action(uint8_t action)
 {
 	switch (action) {
@@ -388,7 +92,7 @@
 	}
 }
 
-static int prov_auth(uint8_t method, uint8_t action, uint8_t size)
+int bt_mesh_prov_auth(uint8_t method, uint8_t action, uint8_t size)
 {
 	bt_mesh_output_action_t output;
 	bt_mesh_input_action_t input;
@@ -399,16 +103,15 @@
 			return -EINVAL;
 		}
 
-		memset(link.auth, 0, sizeof(link.auth));
+		memset(bt_mesh_prov_link.auth, 0, sizeof(bt_mesh_prov_link.auth));
 		return 0;
 	case AUTH_METHOD_STATIC:
 		if (action || size) {
 			return -EINVAL;
 		}
 
-		memcpy(link.auth + 16 - prov->static_val_len,
-		       prov->static_val, prov->static_val_len);
-		memset(link.auth, 0, sizeof(link.auth) - prov->static_val_len);
+		atomic_set_bit(bt_mesh_prov_link.flags, OOB_STATIC_KEY);
+
 		return 0;
 
 	case AUTH_METHOD_OUTPUT:
@@ -417,15 +120,15 @@
 			return -EINVAL;
 		}
 
-		if (!(prov->output_actions & output)) {
+		if (!(bt_mesh_prov->output_actions & output)) {
 			return -EINVAL;
 		}
 
-		if (size > prov->output_size) {
+		if (size > bt_mesh_prov->output_size) {
 			return -EINVAL;
 		}
 
-		atomic_set_bit(link.flags, NOTIFY_INPUT_COMPLETE);
+		atomic_set_bit(bt_mesh_prov_link.flags, NOTIFY_INPUT_COMPLETE);
 
 		if (output == BT_MESH_DISPLAY_STRING) {
 			unsigned char str[9];
@@ -444,10 +147,11 @@
 			}
 			str[size] = '\0';
 
-			memcpy(link.auth, str, size);
-			memset(link.auth + size, 0, sizeof(link.auth) - size);
+			memcpy(bt_mesh_prov_link.auth, str, size);
+			memset(bt_mesh_prov_link.auth + size, 0,
+				     sizeof(bt_mesh_prov_link.auth) - size);
 
-			return prov->output_string((char *)str);
+			return bt_mesh_prov->output_string((char *)str);
 		} else {
 			uint32_t div[8] = { 10, 100, 1000, 10000, 100000,
 					    1000000, 10000000, 100000000 };
@@ -456,10 +160,10 @@
 			bt_rand(&num, sizeof(num));
 			num %= div[size - 1];
 
-			sys_put_be32(num, &link.auth[12]);
-			memset(link.auth, 0, 12);
+			sys_put_be32(num, &bt_mesh_prov_link.auth[12]);
+			memset(bt_mesh_prov_link.auth, 0, 12);
 
-			return prov->output_number(output, num);
+			return bt_mesh_prov->output_number(output, num);
 		}
 
 	case AUTH_METHOD_INPUT:
@@ -468,701 +172,141 @@
 			return -EINVAL;
 		}
 
-		if (!(prov->input_actions & input)) {
+		if (!(bt_mesh_prov->input_actions & input)) {
 			return -EINVAL;
 		}
 
-		if (size > prov->input_size) {
+		if (size > bt_mesh_prov->input_size) {
 			return -EINVAL;
 		}
 
 		if (input == BT_MESH_ENTER_STRING) {
-			atomic_set_bit(link.flags, WAIT_STRING);
+			atomic_set_bit(bt_mesh_prov_link.flags, WAIT_STRING);
 		} else {
-			atomic_set_bit(link.flags, WAIT_NUMBER);
+			atomic_set_bit(bt_mesh_prov_link.flags, WAIT_NUMBER);
 		}
 
-		return prov->input(input, size);
+		return bt_mesh_prov->input(input, size);
 
 	default:
 		return -EINVAL;
 	}
 }
 
-static void prov_start(const uint8_t *data)
-{
-	BT_DBG("Algorithm:   0x%02x", data[0]);
-	BT_DBG("Public Key:  0x%02x", data[1]);
-	BT_DBG("Auth Method: 0x%02x", data[2]);
-	BT_DBG("Auth Action: 0x%02x", data[3]);
-	BT_DBG("Auth Size:   0x%02x", data[4]);
-
-	if (data[0] != PROV_ALG_P256) {
-		BT_ERR("Unknown algorithm 0x%02x", data[0]);
-		prov_fail(PROV_ERR_NVAL_FMT);
-		return;
-	}
-
-	if (data[1] != PUB_KEY_NO_OOB) {
-		BT_ERR("Invalid public key type: 0x%02x", data[1]);
-		prov_fail(PROV_ERR_NVAL_FMT);
-		return;
-	}
-
-	memcpy(&link.conf_inputs[12], data, 5);
-
-	/* TODO: reset link when auth fails? */
-	link.expect = PROV_PUB_KEY;
-
-	if (prov_auth(data[2], data[3], data[4]) < 0) {
-		BT_ERR("Invalid authentication method: 0x%02x; "
-			"action: 0x%02x; size: 0x%02x", data[2], data[3],
-			data[4]);
-		prov_fail(PROV_ERR_NVAL_FMT);
-	}
-}
-
-static void send_confirm(void)
-{
-	struct os_mbuf *cfm = PROV_BUF(17);
-
-	BT_DBG("ConfInputs[0]   %s", bt_hex(link.conf_inputs, 64));
-	BT_DBG("ConfInputs[64]  %s", bt_hex(&link.conf_inputs[64], 64));
-	BT_DBG("ConfInputs[128] %s", bt_hex(&link.conf_inputs[128], 17));
-
-	if (bt_mesh_prov_conf_salt(link.conf_inputs, link.conf_salt)) {
-		BT_ERR("Unable to generate confirmation salt");
-		prov_fail(PROV_ERR_UNEXP_ERR);
-		goto done;
-	}
-
-	BT_DBG("ConfirmationSalt: %s", bt_hex(link.conf_salt, 16));
-
-	if (bt_mesh_prov_conf_key(link.dhkey, link.conf_salt, link.conf_key)) {
-		BT_ERR("Unable to generate confirmation key");
-		prov_fail(PROV_ERR_UNEXP_ERR);
-		goto done;
-	}
-
-	BT_DBG("ConfirmationKey: %s", bt_hex(link.conf_key, 16));
-
-	if (bt_rand(link.rand, 16)) {
-		BT_ERR("Unable to generate random number");
-		prov_fail(PROV_ERR_UNEXP_ERR);
-		goto done;
-	}
-
-	BT_DBG("LocalRandom: %s", bt_hex(link.rand, 16));
-
-	prov_buf_init(cfm, PROV_CONFIRM);
-
-	if (bt_mesh_prov_conf(link.conf_key, link.rand, link.auth,
-			      net_buf_simple_add(cfm, 16))) {
-		BT_ERR("Unable to generate confirmation value");
-		prov_fail(PROV_ERR_UNEXP_ERR);
-		goto done;
-	}
-
-	if (prov_send(cfm, NULL)) {
-		BT_ERR("Failed to send Provisioning Confirm");
-		goto done;
-	}
-
-	if (atomic_test_bit(link.flags, PROVISIONER)) {
-		link.expect = PROV_CONFIRM;
-	} else {
-		link.expect = PROV_RANDOM;
-	}
-
-done:
-	os_mbuf_free_chain(cfm);
-}
-
-static void send_input_complete(void)
-{
-	struct os_mbuf *buf = PROV_BUF(1);
-
-	prov_buf_init(buf, PROV_INPUT_COMPLETE);
-	if (prov_send(buf, NULL)) {
-		BT_ERR("Failed to send Provisioning Input Complete");
-	}
-	link.expect = PROV_CONFIRM;
-
-	os_mbuf_free_chain(buf);
-}
-
-static void input_complete(void)
-{
-	if (atomic_test_bit(link.flags, PUB_KEY_SENT)) {
-		send_input_complete();
-	} else {
-		atomic_set_bit(link.flags, INPUT_COMPLETE);
-	}
-}
-
 int bt_mesh_input_number(uint32_t num)
 {
 	BT_DBG("%u", (unsigned) num);
 
-	if (!atomic_test_and_clear_bit(link.flags, WAIT_NUMBER)) {
+	if (!atomic_test_and_clear_bit(bt_mesh_prov_link.flags, WAIT_NUMBER)) {
 		return -EINVAL;
 	}
 
-	sys_put_be32(num, &link.auth[12]);
+	sys_put_be32(num, &bt_mesh_prov_link.auth[12]);
 
-	input_complete();
+	bt_mesh_prov_link.role->input_complete();
 
 	return 0;
 }
 
-static void public_key_sent(int err, void *cb_data)
-{
-	atomic_set_bit(link.flags, PUB_KEY_SENT);
-
-	if (atomic_test_bit(link.flags, INPUT_COMPLETE)) {
-		send_input_complete();
-		return;
-	}
-}
-
 int bt_mesh_input_string(const char *str)
 {
 	BT_DBG("%s", str);
 
-	if (!atomic_test_and_clear_bit(link.flags, WAIT_STRING)) {
+	if (!atomic_test_and_clear_bit(bt_mesh_prov_link.flags, WAIT_STRING)) {
 		return -EINVAL;
 	}
 
-	strncpy((char *)link.auth, str, prov->input_size);
+	strncpy((char *)bt_mesh_prov_link.auth, str, bt_mesh_prov->input_size);
 
-	send_input_complete();
+	bt_mesh_prov_link.role->input_complete();
 
 	return 0;
 }
 
-static void send_pub_key(void)
+const struct bt_mesh_prov *bt_mesh_prov_get(void)
 {
-	struct os_mbuf *buf = PROV_BUF(65);
-	const uint8_t *key;
-
-	key = bt_pub_key_get();
-	if (!key) {
-		BT_ERR("No public key available");
-		prov_fail(PROV_ERR_UNEXP_ERR);
-		goto done;
-	}
-
-	BT_DBG("Local Public Key: %s", bt_hex(key, 64));
-
-	prov_buf_init(buf, PROV_PUB_KEY);
-
-	/* Swap X and Y halves independently to big-endian */
-	sys_memcpy_swap(net_buf_simple_add(buf, 32), key, 32);
-	sys_memcpy_swap(net_buf_simple_add(buf, 32), &key[32], 32);
-
-	if (atomic_test_bit(link.flags, PROVISIONER)) {
-		/* PublicKeyProvisioner */
-		memcpy(&link.conf_inputs[17], &buf->om_data[1], 64);
-	} else {
-		/* PublicKeyRemote */
-		memcpy(&link.conf_inputs[81], &buf->om_data[1], 64);
-	}
-
-	if (prov_send(buf, public_key_sent)) {
-		BT_ERR("Failed to send Public Key");
-		goto done;
-	}
-
-	if (atomic_test_bit(link.flags, PROVISIONER)) {
-		link.expect = PROV_PUB_KEY;
-	} else {
-		if (atomic_test_bit(link.flags, WAIT_NUMBER) ||
-		    atomic_test_bit(link.flags, WAIT_STRING)) {
-			link.expect = PROV_NO_PDU; /* Wait for input */
-		} else {
-			link.expect = PROV_CONFIRM;
-		}
-	}
-
-done:
-	os_mbuf_free_chain(buf);
+	return bt_mesh_prov;
 }
 
-static void prov_dh_key_cb(const uint8_t dhkey[32])
+bool bt_mesh_prov_active(void)
 {
-	BT_DBG("%p", dhkey);
-
-	if (!dhkey) {
-		BT_ERR("DHKey generation failed");
-		prov_fail(PROV_ERR_UNEXP_ERR);
-		return;
-	}
-
-	sys_memcpy_swap(link.dhkey, dhkey, 32);
-
-	BT_DBG("DHkey: %s", bt_hex(link.dhkey, 32));
-
-	if (atomic_test_bit(link.flags, PROVISIONER)) {
-		send_confirm();
-	} else {
-		send_pub_key();
-	}
+	return atomic_test_bit(bt_mesh_prov_link.flags, LINK_ACTIVE);
 }
 
-static void prov_dh_key_gen(void)
-{
-	uint8_t remote_pk_le[64], *remote_pk;
-
-	if (atomic_test_bit(link.flags, PROVISIONER)) {
-		remote_pk = &link.conf_inputs[81];
-	} else {
-		remote_pk = &link.conf_inputs[17];
-	}
-
-	/* Copy remote key in little-endian for bt_dh_key_gen().
-	 * X and Y halves are swapped independently. The bt_dh_key_gen()
-	 * will also take care of validating the remote public key.
-	 */
-	sys_memcpy_swap(remote_pk_le, remote_pk, 32);
-	sys_memcpy_swap(&remote_pk_le[32], &remote_pk[32], 32);
-
-	if (bt_dh_key_gen(remote_pk_le, prov_dh_key_cb)) {
-		BT_ERR("Failed to generate DHKey");
-		prov_fail(PROV_ERR_UNEXP_ERR);
-	}
-}
-
-static void prov_pub_key(const uint8_t *data)
-{
-	BT_DBG("Remote Public Key: %s", bt_hex(data, 64));
-
-	if (atomic_test_bit(link.flags, PROVISIONER)) {
-		/* PublicKeyDevice */
-		memcpy(&link.conf_inputs[81], data, 64);
-
-		link.bearer->clear_tx();
-	} else {
-		/* PublicKeyProvisioner */
-		memcpy(&link.conf_inputs[17], data, 64);
-
-		if (!bt_pub_key_get()) {
-			/* Clear retransmit timer */
-
-			link.bearer->clear_tx();
-			atomic_set_bit(link.flags, WAIT_PUB_KEY);
-			BT_WARN("Waiting for local public key");
-			return;
-		}
-	}
-
-	prov_dh_key_gen();
-}
-
-
-static void pub_key_ready(const uint8_t *pkey)
-{
-	if (!pkey) {
-		BT_WARN("Public key not available");
-		return;
-	}
-
-	BT_DBG("Local public key ready");
-
-	if (atomic_test_and_clear_bit(link.flags, WAIT_PUB_KEY)) {
-		if (atomic_test_bit(link.flags, PROVISIONER)) {
-			send_pub_key();
-		} else {
-			prov_dh_key_gen();
-		}
-	}
-}
-
-static void notify_input_complete(void)
-{
-	if (atomic_test_and_clear_bit(link.flags, NOTIFY_INPUT_COMPLETE) &&
-	    prov->input_complete) {
-		prov->input_complete();
-	}
-}
-
-static void prov_input_complete(const uint8_t *data)
-{
-	BT_DBG("");
-	notify_input_complete();
-}
-
-#if defined(CONFIG_BT_MESH_PROVISIONER)
-static void send_prov_data(void)
-{
-	struct os_mbuf *pdu = PROV_BUF(34);
-	struct bt_mesh_cdb_subnet *sub;
-	uint8_t session_key[16];
-	uint8_t nonce[13];
-	int err;
-
-	err = bt_mesh_session_key(link.dhkey, link.prov_salt, session_key);
-	if (err) {
-		BT_ERR("Unable to generate session key");
-		prov_fail(PROV_ERR_UNEXP_ERR);
-		goto done;
-	}
-
-	BT_DBG("SessionKey: %s", bt_hex(session_key, 16));
-
-	err = bt_mesh_prov_nonce(link.dhkey, link.prov_salt, nonce);
-	if (err) {
-		BT_ERR("Unable to generate session nonce");
-		prov_fail(PROV_ERR_UNEXP_ERR);
-		goto done;
-	}
-
-	BT_DBG("Nonce: %s", bt_hex(nonce, 13));
-
-	err = bt_mesh_dev_key(link.dhkey, link.prov_salt,
-			      link.provisioner.node->dev_key);
-	if (err) {
-		BT_ERR("Unable to generate device key");
-		prov_fail(PROV_ERR_UNEXP_ERR);
-		goto done;
-	}
-
-	BT_DBG("DevKey: %s", bt_hex(link.provisioner.node->dev_key, 16));
-
-	sub = bt_mesh_cdb_subnet_get(link.provisioner.node->net_idx);
-	if (sub == NULL) {
-		BT_ERR("No subnet with net_idx %u",
-		       link.provisioner.node->net_idx);
-		prov_fail(PROV_ERR_UNEXP_ERR);
-		goto done;
-	}
-
-	prov_buf_init(pdu, PROV_DATA);
-	net_buf_simple_add_mem(pdu, sub->keys[sub->kr_flag].net_key, 16);
-	net_buf_simple_add_be16(pdu, link.provisioner.node->net_idx);
-	net_buf_simple_add_u8(pdu, bt_mesh_cdb_subnet_flags(sub));
-	net_buf_simple_add_be32(pdu, bt_mesh_cdb.iv_index);
-	net_buf_simple_add_be16(pdu, link.provisioner.node->addr);
-	net_buf_simple_add(pdu, 8); /* For MIC */
-
-	BT_DBG("net_idx %u, iv_index 0x%08x, addr 0x%04x",
-	       link.provisioner.node->net_idx, bt_mesh.iv_index,
-	       link.provisioner.node->addr);
-
-	err = bt_mesh_prov_encrypt(session_key, nonce, &pdu->om_data[1],
-				   &pdu->om_data[1]);
-	if (err) {
-		BT_ERR("Unable to encrypt provisioning data");
-		prov_fail(PROV_ERR_DECRYPT);
-		goto done;
-	}
-
-	if (prov_send(pdu, NULL)) {
-		BT_ERR("Failed to send Provisioning Data");
-		goto done;
-	}
-
-	link.expect = PROV_COMPLETE;
-
-done:
-	os_mbuf_free_chain(pdu);
-}
-#endif
-
-static void prov_complete(const uint8_t *data)
-{
-#if defined(CONFIG_BT_MESH_PROVISIONER)
-	struct bt_mesh_cdb_node *node = link.provisioner.node;
-
-	BT_DBG("key %s, net_idx %u, num_elem %u, addr 0x%04x",
-	       bt_hex(node->dev_key, 16), node->net_idx, node->num_elem,
-	       node->addr);
-
-	if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
-		bt_mesh_store_cdb_node(node);
-	}
-
-	link.provisioner.node = NULL;
-	prov_link_close(PROV_BEARER_LINK_STATUS_SUCCESS);
-	if (prov->node_added) {
-		prov->node_added(node->net_idx, node->uuid, node->addr,
-				 node->num_elem);
-	}
-#endif
-}
-
-static void send_random(void)
-{
-	struct os_mbuf *rnd = PROV_BUF(17);
-
-	prov_buf_init(rnd, PROV_RANDOM);
-	net_buf_simple_add_mem(rnd, link.rand, 16);
-
-	if (prov_send(rnd, NULL)) {
-		BT_ERR("Failed to send Provisioning Random");
-		goto done;
-	}
-
-	if (atomic_test_bit(link.flags, PROVISIONER)) {
-		link.expect = PROV_RANDOM;
-	} else {
-		link.expect = PROV_DATA;
-	}
-
-done:
-	os_mbuf_free_chain(rnd);
-}
-
-static void prov_random(const uint8_t *data)
-{
-	uint8_t conf_verify[16];
-	const uint8_t *prov_rand, *dev_rand;
-
-	BT_DBG("Remote Random: %s", bt_hex(data, 16));
-
-	if (!memcmp(data, link.rand, 16)) {
-		BT_ERR("Random value is identical to ours, rejecting.");
-		prov_fail(PROV_ERR_CFM_FAILED);
-		return;
-	}
-
-	if (bt_mesh_prov_conf(link.conf_key, data, link.auth, conf_verify)) {
-		BT_ERR("Unable to calculate confirmation verification");
-		prov_fail(PROV_ERR_UNEXP_ERR);
-		return;
-	}
-
-	if (memcmp(conf_verify, link.conf, 16)) {
-		BT_ERR("Invalid confirmation value");
-		BT_DBG("Received:   %s", bt_hex(link.conf, 16));
-		BT_DBG("Calculated: %s",  bt_hex(conf_verify, 16));
-		prov_fail(PROV_ERR_CFM_FAILED);
-		return;
-	}
-
-	if (atomic_test_bit(link.flags, PROVISIONER)) {
-		prov_rand = link.rand;
-		dev_rand = data;
-	} else {
-		prov_rand = data;
-		dev_rand = link.rand;
-	}
-
-	if (bt_mesh_prov_salt(link.conf_salt, prov_rand, dev_rand,
-			      link.prov_salt)) {
-		BT_ERR("Failed to generate provisioning salt");
-		prov_fail(PROV_ERR_UNEXP_ERR);
-		return;
-	}
-
-	BT_DBG("ProvisioningSalt: %s", bt_hex(link.prov_salt, 16));
-
-#if defined(CONFIG_BT_MESH_PROVISIONER)
-	if (atomic_test_bit(link.flags, PROVISIONER)) {
-		send_prov_data();
-		return;
-	}
-#endif
-
-	send_random();
-}
-
-static void prov_confirm(const uint8_t *data)
-{
-	BT_DBG("Remote Confirm: %s", bt_hex(data, 16));
-
-	memcpy(link.conf, data, 16);
-
-	notify_input_complete();
-
-	if (atomic_test_bit(link.flags, PROVISIONER)) {
-		send_random();
-	} else {
-		send_confirm();
-	}
-}
-
-static inline bool is_pb_gatt(void)
-{
-	return link.bearer && link.bearer->type == BT_MESH_PROV_GATT;
-}
-
-static void prov_data(const uint8_t *data)
-{
-	struct os_mbuf *msg = PROV_BUF(1);
-	uint8_t session_key[16];
-	uint8_t nonce[13];
-	uint8_t dev_key[16];
-	uint8_t pdu[25];
-	uint8_t flags;
-	uint32_t iv_index;
-	uint16_t addr;
-	uint16_t net_idx;
-	int err;
-	bool identity_enable;
-
-	BT_DBG("");
-
-	err = bt_mesh_session_key(link.dhkey, link.prov_salt, session_key);
-	if (err) {
-		BT_ERR("Unable to generate session key");
-		prov_fail(PROV_ERR_UNEXP_ERR);
-		goto done;
-	}
-
-	BT_DBG("SessionKey: %s", bt_hex(session_key, 16));
-
-	err = bt_mesh_prov_nonce(link.dhkey, link.prov_salt, nonce);
-	if (err) {
-		BT_ERR("Unable to generate session nonce");
-		prov_fail(PROV_ERR_UNEXP_ERR);
-		goto done;
-	}
-
-	BT_DBG("Nonce: %s", bt_hex(nonce, 13));
-
-	err = bt_mesh_prov_decrypt(session_key, nonce, data, pdu);
-	if (err) {
-		BT_ERR("Unable to decrypt provisioning data");
-		prov_fail(PROV_ERR_DECRYPT);
-		goto done;
-	}
-
-	err = bt_mesh_dev_key(link.dhkey, link.prov_salt, dev_key);
-	if (err) {
-		BT_ERR("Unable to generate device key");
-		prov_fail(PROV_ERR_UNEXP_ERR);
-		goto done;
-	}
-
-	BT_DBG("DevKey: %s", bt_hex(dev_key, 16));
-
-	net_idx = sys_get_be16(&pdu[16]);
-	flags = pdu[18];
-	iv_index = sys_get_be32(&pdu[19]);
-	addr = sys_get_be16(&pdu[23]);
-
-	BT_DBG("net_idx %u iv_index 0x%08x, addr 0x%04x",
-	       net_idx, (unsigned) iv_index, addr);
-
-	prov_buf_init(msg, PROV_COMPLETE);
-	if (prov_send(msg, NULL)) {
-		BT_ERR("Failed to send Provisioning Complete");
-		goto done;
-	}
-
-	/* Ignore any further PDUs on this link */
-	link.expect = PROV_NO_PDU;
-
-	/* Store info, since bt_mesh_provision() will end up clearing it */
-	if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY)) {
-		identity_enable = is_pb_gatt();
-	} else {
-		identity_enable = false;
-	}
-
-	err = bt_mesh_provision(pdu, net_idx, flags, iv_index, addr, dev_key);
-	if (err) {
-		BT_ERR("Failed to provision (err %d)", err);
-		goto done;
-	}
-
-	/* After PB-GATT provisioning we should start advertising
-	 * using Node Identity.
-	 */
-	if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY) && identity_enable) {
-		bt_mesh_proxy_identity_enable();
-	}
-
-done:
-	os_mbuf_free_chain(msg);
-}
-
-static void prov_failed(const uint8_t *data)
-{
-	BT_WARN("Error: 0x%02x", data[0]);
-	reset_state();
-}
-
-static const struct {
-	void (*func)(const uint8_t *data);
-	uint16_t len;
-} prov_handlers[] = {
-	{ prov_invite, 1 },
-	{ prov_capabilities, 11 },
-	{ prov_start, 5, },
-	{ prov_pub_key, 64 },
-	{ prov_input_complete, 0 },
-	{ prov_confirm, 16 },
-	{ prov_random, 16 },
-	{ prov_data, 33 },
-	{ prov_complete, 0 },
-	{ prov_failed, 1 },
-};
-
 static void prov_recv(const struct prov_bearer *bearer, void *cb_data,
 		      		  struct os_mbuf *buf)
 {
+	static const uint8_t op_len[10] = {
+		[PROV_INVITE] = 1,
+		[PROV_CAPABILITIES] = 11,
+		[PROV_START] = 5,
+		[PROV_PUB_KEY] = 64,
+		[PROV_INPUT_COMPLETE] = 0,
+		[PROV_CONFIRM] = 16,
+		[PROV_RANDOM] = 16,
+		[PROV_DATA] = 33,
+		[PROV_COMPLETE] = 0,
+		[PROV_FAILED] = 1,
+	};
+
 	uint8_t type = buf->om_data[0];
 	BT_DBG("type 0x%02x len %u", type, buf->om_len);
 
-	if (type >= ARRAY_SIZE(prov_handlers)) {
+	if (type >= ARRAY_SIZE(bt_mesh_prov_link.role->op)) {
 		BT_ERR("Unknown provisioning PDU type 0x%02x", type);
-		prov_fail(PROV_ERR_NVAL_FMT);
+		bt_mesh_prov_link.role->error(PROV_ERR_NVAL_FMT);
 		return;
 	}
 
-	if (type != PROV_FAILED && type != link.expect) {
-		BT_WARN("Unexpected msg 0x%02x != 0x%02x", type, link.expect);
-		prov_fail(PROV_ERR_UNEXP_PDU);
+	if ((type != PROV_FAILED && type != bt_mesh_prov_link.expect) ||
+	    !bt_mesh_prov_link.role->op[type]) {
+		BT_WARN("Unexpected msg 0x%02x != 0x%02x", type, bt_mesh_prov_link.expect);
+		bt_mesh_prov_link.role->error(PROV_ERR_UNEXP_PDU);
 		return;
 	}
 
-	if (1 + prov_handlers[type].len != buf->om_len) {
+	if (1 + op_len[type] != buf->om_len) {
 		BT_ERR("Invalid length %u for type 0x%02x", buf->om_len, type);
-		prov_fail(PROV_ERR_NVAL_FMT);
+		bt_mesh_prov_link.role->error(PROV_ERR_NVAL_FMT);
 		return;
 	}
 
-	prov_handlers[type].func(&buf->om_data[1]);
+	bt_mesh_prov_link.role->op[type](&buf->om_data[1]);
 }
 
 static void prov_link_opened(const struct prov_bearer *bearer, void *cb_data)
 {
-	atomic_set_bit(link.flags, LINK_ACTIVE);
+	atomic_set_bit(bt_mesh_prov_link.flags, LINK_ACTIVE);
 
-	if (prov->link_open) {
-		prov->link_open(bearer->type);
+	if (bt_mesh_prov->link_open) {
+		bt_mesh_prov->link_open(bearer->type);
 	}
 
-	link.bearer = bearer;
+	bt_mesh_prov_link.bearer = bearer;
 
-#if defined(CONFIG_BT_MESH_PROVISIONER)
-	if (atomic_test_bit(link.flags, PROVISIONER)) {
-		send_invite();
-		return;
+	if (bt_mesh_prov_link.role->link_opened) {
+		bt_mesh_prov_link.role->link_opened();
 	}
-#endif
-
-	link.expect = PROV_INVITE;
 }
 
 static void prov_link_closed(const struct prov_bearer *bearer, void *cb_data,
 			     enum prov_bearer_link_status reason)
 {
-	/* Reset state before calling link_close, so a new provisioning
-	 * procedure can be started from the callback.
-	 */
-	reset_state();
+	if (bt_mesh_prov_link.role->link_closed) {
+		bt_mesh_prov_link.role->link_closed();
+	}
 
-	if (prov->link_close) {
-		prov->link_close(bearer->type);
+	if (bt_mesh_prov->link_close) {
+		bt_mesh_prov->link_close(bearer->type);
 	}
 }
 
 static void prov_bearer_error(const struct prov_bearer *bearer, void *cb_data,
 			      uint8_t err)
 {
-	prov_fail(err);
+	if (bt_mesh_prov_link.role->error) {
+		bt_mesh_prov_link.role->error(err);
+	}
 }
 
 static const struct prov_bearer_cb prov_bearer_cb = {
@@ -1172,41 +316,33 @@
 	.recv = prov_recv,
 };
 
-#if defined(CONFIG_BT_MESH_PB_ADV) && defined(CONFIG_BT_MESH_PROVISIONER)
-int bt_mesh_pb_adv_open(const uint8_t uuid[16], uint16_t net_idx, uint16_t addr,
-			uint8_t attention_duration)
+const struct prov_bearer_cb *bt_mesh_prov_bearer_cb_get(void)
 {
-	int err;
-
-	if (atomic_test_and_set_bit(link.flags, LINK_ACTIVE)) {
-		return -EBUSY;
-	}
-
-	atomic_set_bit(link.flags, PROVISIONER);
-	memcpy(link.provisioner.uuid, uuid, 16);
-	link.provisioner.addr = addr;
-	link.provisioner.net_idx = net_idx;
-	link.provisioner.attention_duration = attention_duration;
-	link.bearer = &pb_adv;
-
-	err = link.bearer->link_open(link.provisioner.uuid, PROTOCOL_TIMEOUT,
-				     &prov_bearer_cb, NULL);
-	if (err) {
-		atomic_clear_bit(link.flags, LINK_ACTIVE);
-	}
-
-	return err;
-}
-#endif
-
-const struct bt_mesh_prov *bt_mesh_prov_get(void)
-{
-	return prov;
+	return &prov_bearer_cb;
 }
 
-bool bt_prov_active(void)
+void bt_mesh_prov_complete(uint16_t net_idx, uint16_t addr)
 {
-	return atomic_test_bit(link.flags, LINK_ACTIVE);
+	if (bt_mesh_prov->complete) {
+		bt_mesh_prov->complete(net_idx, addr);
+	}
+}
+
+void bt_mesh_prov_reset(void)
+{
+	if (IS_ENABLED(CONFIG_BT_MESH_PB_ADV)) {
+		pb_adv_reset();
+	}
+
+	if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT)) {
+		pb_gatt_reset();
+	}
+
+	bt_mesh_prov_reset_state(NULL);
+
+	if (bt_mesh_prov->reset) {
+		bt_mesh_prov->reset();
+	}
 }
 
 int bt_mesh_prov_init(const struct bt_mesh_prov *prov_info)
@@ -1216,75 +352,14 @@
 		return -EINVAL;
 	}
 
-	prov = prov_info;
+	bt_mesh_prov = prov_info;
 
 	if (IS_ENABLED(CONFIG_BT_MESH_PB_ADV)) {
 		pb_adv_init();
 	}
-
 	if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT)) {
 		pb_gatt_init();
 	}
 
-	return reset_state();
-}
-
-int bt_mesh_prov_enable(bt_mesh_prov_bearer_t bearers)
-{
-	char uuid_buf[BLE_UUID_STR_LEN];
-	const struct bt_mesh_prov *prov = bt_mesh_prov_get();
-	ble_uuid_t *uuid = BLE_UUID128_DECLARE();
-
-	memcpy(BLE_UUID128(uuid)->value, prov->uuid, 16);
-	BT_INFO("Device UUID: %s", ble_uuid_to_str(uuid, uuid_buf));
-
-	if (IS_ENABLED(CONFIG_BT_MESH_PB_ADV) &&
-	    (bearers & BT_MESH_PROV_ADV)) {
-		/* Make sure we're scanning for provisioning inviations */
-		bt_mesh_scan_enable();
-		/* Enable unprovisioned beacon sending */
-		bt_mesh_beacon_enable();
-	}
-
-	if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT) &&
-	    (bearers & BT_MESH_PROV_GATT)) {
-		bt_mesh_proxy_prov_enable();
-		bt_mesh_adv_update();
-	}
-
-	return 0;
-}
-
-int bt_mesh_prov_disable(bt_mesh_prov_bearer_t bearers)
-{
-	if (bt_mesh_is_provisioned()) {
-		return -EALREADY;
-	}
-
-	if (IS_ENABLED(CONFIG_BT_MESH_PB_ADV) &&
-	    (bearers & BT_MESH_PROV_ADV)) {
-		bt_mesh_beacon_disable();
-		bt_mesh_scan_disable();
-	}
-
-	if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT) &&
-	    (bearers & BT_MESH_PROV_GATT)) {
-			bt_mesh_proxy_prov_disable(true);
-	}
-
-	return 0;
-}
-
-void bt_mesh_prov_complete(uint16_t net_idx, uint16_t addr)
-{
-	if (prov->complete) {
-		prov->complete(net_idx, addr);
-	}
-}
-
-void bt_mesh_prov_reset(void)
-{
-	if (prov->reset) {
-		prov->reset();
-	}
+	return bt_mesh_prov_reset_state(NULL);
 }
diff --git a/nimble/host/mesh/src/prov.h b/nimble/host/mesh/src/prov.h
index 96e5f3c..71ee03d 100644
--- a/nimble/host/mesh/src/prov.h
+++ b/nimble/host/mesh/src/prov.h
@@ -9,6 +9,7 @@
 #ifndef __PROV_H__
 #define __PROV_H__
 
+#include "prov_bearer.h"
 #include "os/os_mbuf.h"
 #include "mesh/mesh.h"
 #include "../src/ble_hs_conn_priv.h"
@@ -23,12 +24,116 @@
 #define PROV_ERR_UNEXP_ERR     0x07
 #define PROV_ERR_ADDR          0x08
 
-int bt_mesh_pb_adv_open(const uint8_t uuid[16], uint16_t net_idx, uint16_t addr,
-			uint8_t attention_duration);
+#define AUTH_METHOD_NO_OOB     0x00
+#define AUTH_METHOD_STATIC     0x01
+#define AUTH_METHOD_OUTPUT     0x02
+#define AUTH_METHOD_INPUT      0x03
 
-void bt_mesh_pb_adv_recv(struct os_mbuf *buf);
+#define OUTPUT_OOB_BLINK       0x00
+#define OUTPUT_OOB_BEEP        0x01
+#define OUTPUT_OOB_VIBRATE     0x02
+#define OUTPUT_OOB_NUMBER      0x03
+#define OUTPUT_OOB_STRING      0x04
 
-bool bt_prov_active(void);
+#define INPUT_OOB_PUSH         0x00
+#define INPUT_OOB_TWIST        0x01
+#define INPUT_OOB_NUMBER       0x02
+#define INPUT_OOB_STRING       0x03
+
+#define PUB_KEY_NO_OOB         0x00
+#define PUB_KEY_OOB            0x01
+
+#define PROV_INVITE            0x00
+#define PROV_CAPABILITIES      0x01
+#define PROV_START             0x02
+#define PROV_PUB_KEY           0x03
+#define PROV_INPUT_COMPLETE    0x04
+#define PROV_CONFIRM           0x05
+#define PROV_RANDOM            0x06
+#define PROV_DATA              0x07
+#define PROV_COMPLETE          0x08
+#define PROV_FAILED            0x09
+
+#define PROV_NO_PDU            0xff
+
+#define PROV_ALG_P256          0x00
+
+#define PROV_BUF(len) \
+	NET_BUF_SIMPLE(PROV_BEARER_BUF_HEADROOM + len)
+
+enum {
+	WAIT_PUB_KEY,           /* Waiting for local PubKey to be generated */
+	LINK_ACTIVE,            /* Link has been opened */
+	WAIT_NUMBER,            /* Waiting for number input from user */
+	WAIT_STRING,            /* Waiting for string input from user */
+	NOTIFY_INPUT_COMPLETE,  /* Notify that input has been completed. */
+	PROVISIONER,            /* The link was opened as provisioner */
+	OOB_PUB_KEY,            /* OOB Public key used */
+	PUB_KEY_SENT,           /* Public key has been sent */
+	REMOTE_PUB_KEY,         /* Remote key has been received */
+	INPUT_COMPLETE,         /* Device input completed */
+	WAIT_CONFIRM,           /* Wait for send confirm */
+	WAIT_AUTH,              /* Wait for auth response */
+	OOB_STATIC_KEY,         /* OOB Static Authentication */
+
+	NUM_FLAGS,
+};
+
+/** Provisioning role */
+struct bt_mesh_prov_role {
+	void (*link_opened)(void);
+
+	void (*link_closed)(void);
+
+	void (*error)(uint8_t reason);
+
+	void (*input_complete)(void);
+
+	void (*op[10])(const uint8_t *data);
+};
+
+struct bt_mesh_prov_link {
+	uint8_t oob_method;             /* Authen method */
+	uint8_t oob_action;             /* Authen action */
+	uint8_t oob_size;               /* Authen size */
+	uint8_t auth[16];               /* Authen value */
+
+	uint8_t dhkey[32];              /* Calculated DHKey */
+	uint8_t expect;                 /* Next expected PDU */
+	uint8_t conf[16];               /* Remote Confirmation */
+	uint8_t rand[16];               /* Local Random */
+
+	uint8_t conf_salt[16];          /* ConfirmationSalt */
+	uint8_t conf_key[16];           /* ConfirmationKey */
+	uint8_t conf_inputs[145];       /* ConfirmationInputs */
+	uint8_t prov_salt[16];          /* Provisioning Salt */
+
+	const struct prov_bearer *bearer;
+	const struct bt_mesh_prov_role *role;
+
+	ATOMIC_DEFINE(flags, NUM_FLAGS);
+};
+
+extern struct bt_mesh_prov_link bt_mesh_prov_link;
+extern const struct bt_mesh_prov *bt_mesh_prov;
+
+static inline int bt_mesh_prov_send(struct os_mbuf *buf,
+				    prov_bearer_send_complete_t cb)
+{
+	return bt_mesh_prov_link.bearer->send(buf, cb, NULL);
+}
+
+static inline void bt_mesh_prov_buf_init(struct os_mbuf *buf, uint8_t type)
+{
+	net_buf_reserve(buf, PROV_BEARER_BUF_HEADROOM);
+	net_buf_simple_add_u8(buf, type);
+}
+
+int bt_mesh_prov_reset_state(void (*func)(const uint8_t key[64]));
+
+bool bt_mesh_prov_active(void);
+
+int bt_mesh_prov_auth(uint8_t method, uint8_t action, uint8_t size);
 
 int bt_mesh_pb_gatt_open(uint16_t conn_handle);
 int bt_mesh_pb_gatt_close(uint16_t conn_handle);
@@ -36,12 +141,14 @@
 
 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_reset_link(void);
 
 void bt_mesh_prov_complete(uint16_t net_idx, uint16_t addr);
-void bt_mesh_prov_node_added(uint16_t net_idx, uint16_t addr, uint8_t num_elem);
 void bt_mesh_prov_reset(void);
 
+const struct prov_bearer_cb *bt_mesh_prov_bearer_cb_get(void);
+
+void bt_mesh_pb_adv_recv(struct os_mbuf *buf);
+
+int bt_mesh_prov_init(const struct bt_mesh_prov *prov);
 #endif
diff --git a/nimble/host/mesh/src/prov_bearer.h b/nimble/host/mesh/src/prov_bearer.h
index d927d11..3ae58ce 100644
--- a/nimble/host/mesh/src/prov_bearer.h
+++ b/nimble/host/mesh/src/prov_bearer.h
@@ -110,4 +110,7 @@
 extern const struct prov_bearer pb_gatt;
 
 void pb_adv_init(void);
-void pb_gatt_init(void);
\ No newline at end of file
+void pb_gatt_init(void);
+
+void pb_adv_reset(void);
+void pb_gatt_reset(void);
diff --git a/nimble/host/mesh/src/prov_device.c b/nimble/host/mesh/src/prov_device.c
new file mode 100644
index 0000000..5eb817b
--- /dev/null
+++ b/nimble/host/mesh/src/prov_device.c
@@ -0,0 +1,566 @@
+/*  Bluetooth Mesh */
+
+/*
+ * Copyright (c) 2017 Intel Corporation
+ * Copyright (c) 2020 Lingao Meng
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#define MESH_LOG_MODULE BLE_MESH_PROV_DEVICE_LOG
+
+#include "testing.h"
+#include "crypto.h"
+#include "adv.h"
+#include "mesh/mesh.h"
+#include "net.h"
+#include "rpl.h"
+#include "beacon.h"
+#include "access.h"
+#include "foundation.h"
+#include "proxy.h"
+#include "prov.h"
+#include "settings.h"
+
+static void send_pub_key(void);
+static void pub_key_ready(const uint8_t *pkey);
+
+static int reset_state(void)
+{
+	return bt_mesh_prov_reset_state(pub_key_ready);
+}
+
+static void prov_send_fail_msg(uint8_t err)
+{
+	struct os_mbuf *buf = PROV_BUF(2);
+
+	BT_DBG("%u", err);
+
+	bt_mesh_prov_link.expect = PROV_NO_PDU;
+
+	bt_mesh_prov_buf_init(buf, PROV_FAILED);
+	net_buf_simple_add_u8(buf, err);
+
+	if (bt_mesh_prov_send(buf, NULL)) {
+		BT_ERR("Failed to send Provisioning Failed message");
+	}
+}
+
+static void prov_fail(uint8_t reason)
+{
+	/* According to Bluetooth Mesh Specification v1.0.1, Section 5.4.4, the
+	 * provisioner just closes the link when something fails, while the
+	 * provisionee sends the fail message, and waits for the provisioner to
+	 * close the link.
+	 */
+	prov_send_fail_msg(reason);
+}
+
+static void prov_invite(const uint8_t *data)
+{
+	struct os_mbuf *buf = PROV_BUF(12);
+
+	BT_DBG("Attention Duration: %u seconds", data[0]);
+
+	if (data[0]) {
+		bt_mesh_attention(NULL, data[0]);
+	}
+
+	bt_mesh_prov_link.conf_inputs[0] = data[0];
+
+	bt_mesh_prov_buf_init(buf, PROV_CAPABILITIES);
+
+	/* Number of Elements supported */
+	net_buf_simple_add_u8(buf, bt_mesh_elem_count());
+
+	/* Supported algorithms - FIPS P-256 Eliptic Curve */
+	net_buf_simple_add_be16(buf, BIT(PROV_ALG_P256));
+
+	/* Public Key Type, Only "No OOB" Public Key is supported */
+	net_buf_simple_add_u8(buf, PUB_KEY_NO_OOB);
+
+	/* Static OOB Type */
+	net_buf_simple_add_u8(buf, bt_mesh_prov->static_val ? BIT(0) : 0x00);
+
+	/* Output OOB Size */
+	net_buf_simple_add_u8(buf, bt_mesh_prov->output_size);
+
+	/* Output OOB Action */
+	net_buf_simple_add_be16(buf, bt_mesh_prov->output_actions);
+
+	/* Input OOB Size */
+	net_buf_simple_add_u8(buf, bt_mesh_prov->input_size);
+
+	/* Input OOB Action */
+	net_buf_simple_add_be16(buf, bt_mesh_prov->input_actions);
+
+	memcpy(&bt_mesh_prov_link.conf_inputs[1], &buf->om_databuf[1], 11);
+
+	if (bt_mesh_prov_send(buf, NULL)) {
+		BT_ERR("Failed to send capabilities");
+		return;
+	}
+
+	bt_mesh_prov_link.expect = PROV_START;
+}
+
+static void prov_start(const uint8_t *data)
+{
+	BT_DBG("Algorithm:   0x%02x", data[0]);
+	BT_DBG("Public Key:  0x%02x", data[1]);
+	BT_DBG("Auth Method: 0x%02x", data[2]);
+	BT_DBG("Auth Action: 0x%02x", data[3]);
+	BT_DBG("Auth Size:   0x%02x", data[4]);
+
+	if (data[0] != PROV_ALG_P256) {
+		BT_ERR("Unknown algorithm 0x%02x", data[0]);
+		prov_fail(PROV_ERR_NVAL_FMT);
+		return;
+	}
+
+	if (data[1] != PUB_KEY_NO_OOB) {
+		BT_ERR("Invalid public key type: 0x%02x", data[1]);
+		prov_fail(PROV_ERR_NVAL_FMT);
+		return;
+	}
+
+	memcpy(&bt_mesh_prov_link.conf_inputs[12], data, 5);
+
+	bt_mesh_prov_link.expect = PROV_PUB_KEY;
+
+	if (bt_mesh_prov_auth(data[2], data[3], data[4]) < 0) {
+		BT_ERR("Invalid authentication method: 0x%02x; "
+		       "action: 0x%02x; size: 0x%02x", data[2], data[3],
+		       data[4]);
+		prov_fail(PROV_ERR_NVAL_FMT);
+	}
+
+	if (atomic_test_bit(bt_mesh_prov_link.flags, OOB_STATIC_KEY)) {
+		memcpy(bt_mesh_prov_link.auth + 16 - bt_mesh_prov->static_val_len,
+		       bt_mesh_prov->static_val, bt_mesh_prov->static_val_len);
+		(void)memset(bt_mesh_prov_link.auth, 0,
+			     sizeof(bt_mesh_prov_link.auth) - bt_mesh_prov->static_val_len);
+	}
+}
+
+static void send_confirm(void)
+{
+	struct os_mbuf *cfm = PROV_BUF(17);
+
+	BT_DBG("ConfInputs[0]   %s", bt_hex(bt_mesh_prov_link.conf_inputs, 64));
+	BT_DBG("ConfInputs[64]  %s", bt_hex(&bt_mesh_prov_link.conf_inputs[64], 64));
+	BT_DBG("ConfInputs[128] %s", bt_hex(&bt_mesh_prov_link.conf_inputs[128], 17));
+
+	if (bt_mesh_prov_conf_salt(bt_mesh_prov_link.conf_inputs,
+				   bt_mesh_prov_link.conf_salt)) {
+		BT_ERR("Unable to generate confirmation salt");
+		prov_fail(PROV_ERR_UNEXP_ERR);
+		return;
+	}
+
+	BT_DBG("ConfirmationSalt: %s", bt_hex(bt_mesh_prov_link.conf_salt, 16));
+
+	if (bt_mesh_prov_conf_key(bt_mesh_prov_link.dhkey, bt_mesh_prov_link.conf_salt,
+				  bt_mesh_prov_link.conf_key)) {
+		BT_ERR("Unable to generate confirmation key");
+		prov_fail(PROV_ERR_UNEXP_ERR);
+		return;
+	}
+
+	BT_DBG("ConfirmationKey: %s", bt_hex(bt_mesh_prov_link.conf_key, 16));
+
+	if (bt_rand(bt_mesh_prov_link.rand, 16)) {
+		BT_ERR("Unable to generate random number");
+		prov_fail(PROV_ERR_UNEXP_ERR);
+		return;
+	}
+
+	BT_DBG("LocalRandom: %s", bt_hex(bt_mesh_prov_link.rand, 16));
+
+	bt_mesh_prov_buf_init(cfm, PROV_CONFIRM);
+
+	if (bt_mesh_prov_conf(bt_mesh_prov_link.conf_key, bt_mesh_prov_link.rand,
+			      bt_mesh_prov_link.auth, net_buf_simple_add(cfm, 16))) {
+		BT_ERR("Unable to generate confirmation value");
+		prov_fail(PROV_ERR_UNEXP_ERR);
+		return;
+	}
+
+	if (bt_mesh_prov_send(cfm, NULL)) {
+		BT_ERR("Failed to send Provisioning Confirm");
+		return;
+	}
+
+	bt_mesh_prov_link.expect = PROV_RANDOM;
+
+}
+
+static void send_input_complete(void)
+{
+	struct os_mbuf *buf = PROV_BUF(1);
+
+	bt_mesh_prov_buf_init(buf, PROV_INPUT_COMPLETE);
+	if (bt_mesh_prov_send(buf, NULL)) {
+		BT_ERR("Failed to send Provisioning Input Complete");
+	}
+	bt_mesh_prov_link.expect = PROV_CONFIRM;
+}
+
+static void public_key_sent(int err, void *cb_data)
+{
+	atomic_set_bit(bt_mesh_prov_link.flags, PUB_KEY_SENT);
+
+	if (atomic_test_bit(bt_mesh_prov_link.flags, INPUT_COMPLETE)) {
+		send_input_complete();
+		return;
+	}
+}
+
+static void send_pub_key(void)
+{
+	struct os_mbuf *buf = PROV_BUF(65);
+	const uint8_t *key;
+
+	key = bt_pub_key_get();
+	if (!key) {
+		BT_ERR("No public key available");
+		prov_fail(PROV_ERR_UNEXP_ERR);
+		return;
+	}
+
+	BT_DBG("Local Public Key: %s", bt_hex(key, 64));
+
+	bt_mesh_prov_buf_init(buf, PROV_PUB_KEY);
+
+	/* Swap X and Y halves independently to big-endian */
+	sys_memcpy_swap(net_buf_simple_add(buf, 32), key, 32);
+	sys_memcpy_swap(net_buf_simple_add(buf, 32), &key[32], 32);
+
+	/* PublicKeyRemote */
+	memcpy(&bt_mesh_prov_link.conf_inputs[81], &buf->om_databuf[1], 64);
+
+	if (bt_mesh_prov_send(buf, public_key_sent)) {
+		BT_ERR("Failed to send Public Key");
+		return;
+	}
+
+	if (atomic_test_bit(bt_mesh_prov_link.flags, WAIT_NUMBER) ||
+	    atomic_test_bit(bt_mesh_prov_link.flags, WAIT_STRING)) {
+		bt_mesh_prov_link.expect = PROV_NO_PDU; /* Wait for input */
+	} else {
+		bt_mesh_prov_link.expect = PROV_CONFIRM;
+	}
+}
+
+static void prov_dh_key_cb(const uint8_t dhkey[32])
+{
+	BT_DBG("%p", dhkey);
+
+	if (!dhkey) {
+		BT_ERR("DHKey generation failed");
+		prov_fail(PROV_ERR_UNEXP_ERR);
+		return;
+	}
+
+	sys_memcpy_swap(bt_mesh_prov_link.dhkey, dhkey, 32);
+
+	BT_DBG("DHkey: %s", bt_hex(bt_mesh_prov_link.dhkey, 32));
+
+	send_pub_key();
+}
+
+static void prov_dh_key_gen(void)
+{
+	uint8_t remote_pk_le[64], *remote_pk;
+
+	remote_pk = &bt_mesh_prov_link.conf_inputs[17];
+
+	/* Copy remote key in little-endian for bt_dh_key_gen().
+	 * X and Y halves are swapped independently. The bt_dh_key_gen()
+	 * will also take care of validating the remote public key.
+	 */
+	sys_memcpy_swap(remote_pk_le, remote_pk, 32);
+	sys_memcpy_swap(&remote_pk_le[32], &remote_pk[32], 32);
+
+	if (bt_dh_key_gen(remote_pk_le, prov_dh_key_cb)) {
+		BT_ERR("Failed to generate DHKey");
+		prov_fail(PROV_ERR_UNEXP_ERR);
+	}
+}
+
+static void prov_pub_key(const uint8_t *data)
+{
+	BT_DBG("Remote Public Key: %s", bt_hex(data, 64));
+
+	/* PublicKeyProvisioner */
+	memcpy(&bt_mesh_prov_link.conf_inputs[17], data, 64);
+
+	if (!bt_pub_key_get()) {
+		/* Clear retransmit timer */
+		bt_mesh_prov_link.bearer->clear_tx();
+		atomic_set_bit(bt_mesh_prov_link.flags, WAIT_PUB_KEY);
+		BT_WARN("Waiting for local public key");
+		return;
+	}
+
+	prov_dh_key_gen();
+}
+
+static void pub_key_ready(const uint8_t *pkey)
+{
+	if (!pkey) {
+		BT_WARN("Public key not available");
+		return;
+	}
+
+	BT_DBG("Local public key ready");
+
+	if (atomic_test_and_clear_bit(bt_mesh_prov_link.flags, WAIT_PUB_KEY)) {
+		prov_dh_key_gen();
+	}
+}
+
+static void notify_input_complete(void)
+{
+	if (atomic_test_and_clear_bit(bt_mesh_prov_link.flags,
+				      NOTIFY_INPUT_COMPLETE) &&
+	    bt_mesh_prov->input_complete) {
+		bt_mesh_prov->input_complete();
+	}
+}
+
+static void send_random(void)
+{
+	struct os_mbuf *rnd = PROV_BUF(17);
+
+	bt_mesh_prov_buf_init(rnd, PROV_RANDOM);
+	net_buf_simple_add_mem(rnd, bt_mesh_prov_link.rand, 16);
+
+	if (bt_mesh_prov_send(rnd, NULL)) {
+		BT_ERR("Failed to send Provisioning Random");
+		return;
+	}
+
+	bt_mesh_prov_link.expect = PROV_DATA;
+}
+
+static void prov_random(const uint8_t *data)
+{
+	uint8_t conf_verify[16];
+
+	BT_DBG("Remote Random: %s", bt_hex(data, 16));
+	if (!memcmp(data, bt_mesh_prov_link.rand, 16)) {
+		BT_ERR("Random value is identical to ours, rejecting.");
+		prov_fail(PROV_ERR_CFM_FAILED);
+		return;
+	}
+
+	if (bt_mesh_prov_conf(bt_mesh_prov_link.conf_key, data,
+			      bt_mesh_prov_link.auth, conf_verify)) {
+		BT_ERR("Unable to calculate confirmation verification");
+		prov_fail(PROV_ERR_UNEXP_ERR);
+		return;
+	}
+
+	if (memcmp(conf_verify, bt_mesh_prov_link.conf, 16)) {
+		BT_ERR("Invalid confirmation value");
+		BT_DBG("Received:   %s", bt_hex(bt_mesh_prov_link.conf, 16));
+		BT_DBG("Calculated: %s",  bt_hex(conf_verify, 16));
+		prov_fail(PROV_ERR_CFM_FAILED);
+		return;
+	}
+
+	if (bt_mesh_prov_salt(bt_mesh_prov_link.conf_salt, data,
+			      bt_mesh_prov_link.rand, bt_mesh_prov_link.prov_salt)) {
+		BT_ERR("Failed to generate provisioning salt");
+		prov_fail(PROV_ERR_UNEXP_ERR);
+		return;
+	}
+
+	BT_DBG("ProvisioningSalt: %s", bt_hex(bt_mesh_prov_link.prov_salt, 16));
+
+	send_random();
+}
+
+static void prov_confirm(const uint8_t *data)
+{
+	BT_DBG("Remote Confirm: %s", bt_hex(data, 16));
+
+	memcpy(bt_mesh_prov_link.conf, data, 16);
+
+	notify_input_complete();
+
+	send_confirm();
+}
+
+static inline bool is_pb_gatt(void)
+{
+	return bt_mesh_prov_link.bearer &&
+	       bt_mesh_prov_link.bearer->type == BT_MESH_PROV_GATT;
+}
+
+static void prov_data(const uint8_t *data)
+{
+	struct os_mbuf *msg = PROV_BUF(1);
+	uint8_t session_key[16];
+	uint8_t nonce[13];
+	uint8_t dev_key[16];
+	uint8_t pdu[25];
+	uint8_t flags;
+	uint32_t iv_index;
+	uint16_t addr;
+	uint16_t net_idx;
+	int err;
+	bool identity_enable;
+
+	BT_DBG("");
+
+	err = bt_mesh_session_key(bt_mesh_prov_link.dhkey,
+				  bt_mesh_prov_link.prov_salt, session_key);
+	if (err) {
+		BT_ERR("Unable to generate session key");
+		prov_fail(PROV_ERR_UNEXP_ERR);
+		return;
+	}
+
+	BT_DBG("SessionKey: %s", bt_hex(session_key, 16));
+
+	err = bt_mesh_prov_nonce(bt_mesh_prov_link.dhkey,
+				 bt_mesh_prov_link.prov_salt, nonce);
+	if (err) {
+		BT_ERR("Unable to generate session nonce");
+		prov_fail(PROV_ERR_UNEXP_ERR);
+		return;
+	}
+
+	BT_DBG("Nonce: %s", bt_hex(nonce, 13));
+
+	err = bt_mesh_prov_decrypt(session_key, nonce, data, pdu);
+	if (err) {
+		BT_ERR("Unable to decrypt provisioning data");
+		prov_fail(PROV_ERR_DECRYPT);
+		return;
+	}
+
+	err = bt_mesh_dev_key(bt_mesh_prov_link.dhkey,
+			      bt_mesh_prov_link.prov_salt, dev_key);
+	if (err) {
+		BT_ERR("Unable to generate device key");
+		prov_fail(PROV_ERR_UNEXP_ERR);
+		return;
+	}
+
+	BT_DBG("DevKey: %s", bt_hex(dev_key, 16));
+
+	net_idx = sys_get_be16(&pdu[16]);
+	flags = pdu[18];
+	iv_index = sys_get_be32(&pdu[19]);
+	addr = sys_get_be16(&pdu[23]);
+
+	BT_DBG("net_idx %u iv_index 0x%08x, addr 0x%04x",
+	       net_idx, iv_index, addr);
+
+	bt_mesh_prov_buf_init(msg, PROV_COMPLETE);
+	if (bt_mesh_prov_send(msg, NULL)) {
+		BT_ERR("Failed to send Provisioning Complete");
+		return;
+	}
+
+	/* Ignore any further PDUs on this link */
+	bt_mesh_prov_link.expect = PROV_NO_PDU;
+
+	/* Store info, since bt_mesh_provision() will end up clearing it */
+	if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY)) {
+		identity_enable = is_pb_gatt();
+	} else {
+		identity_enable = false;
+	}
+
+	err = bt_mesh_provision(pdu, net_idx, flags, iv_index, addr, dev_key);
+	if (err) {
+		BT_ERR("Failed to provision (err %d)", err);
+		return;
+	}
+
+	/* After PB-GATT provisioning we should start advertising
+	 * using Node Identity.
+	 */
+	if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY) && identity_enable) {
+		bt_mesh_proxy_identity_enable();
+	}
+}
+
+static void local_input_complete(void)
+{
+	if (atomic_test_bit(bt_mesh_prov_link.flags, PUB_KEY_SENT)) {
+		send_input_complete();
+	} else {
+		atomic_set_bit(bt_mesh_prov_link.flags, INPUT_COMPLETE);
+	}
+}
+
+static void prov_link_closed(void)
+{
+	reset_state();
+}
+
+static void prov_link_opened(void)
+{
+	bt_mesh_prov_link.expect = PROV_INVITE;
+}
+
+static const struct bt_mesh_prov_role role_device = {
+	.input_complete = local_input_complete,
+	.link_opened = prov_link_opened,
+	.link_closed = prov_link_closed,
+	.error = prov_fail,
+	.op = {
+		[PROV_INVITE] = prov_invite,
+		[PROV_START] = prov_start,
+		[PROV_PUB_KEY] = prov_pub_key,
+		[PROV_CONFIRM] = prov_confirm,
+		[PROV_RANDOM] = prov_random,
+		[PROV_DATA] = prov_data,
+	},
+};
+
+int bt_mesh_prov_enable(bt_mesh_prov_bearer_t bearers)
+{
+	if (bt_mesh_is_provisioned()) {
+		return -EALREADY;
+	}
+
+	if (IS_ENABLED(CONFIG_BT_MESH_PB_ADV) &&
+	    (bearers & BT_MESH_PROV_ADV)) {
+		pb_adv.link_accept(bt_mesh_prov_bearer_cb_get(), NULL);
+	}
+
+	if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT) &&
+	    (bearers & BT_MESH_PROV_GATT)) {
+		pb_gatt.link_accept(bt_mesh_prov_bearer_cb_get(), NULL);
+	}
+
+	bt_mesh_prov_link.role = &role_device;
+
+	return 0;
+}
+
+int bt_mesh_prov_disable(bt_mesh_prov_bearer_t bearers)
+{
+	if (bt_mesh_is_provisioned()) {
+		return -EALREADY;
+	}
+
+	if (IS_ENABLED(CONFIG_BT_MESH_PB_ADV) &&
+	    (bearers & BT_MESH_PROV_ADV)) {
+		bt_mesh_beacon_disable();
+		bt_mesh_scan_disable();
+	}
+
+	if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT) &&
+	    (bearers & BT_MESH_PROV_GATT)) {
+		bt_mesh_proxy_prov_disable(true);
+	}
+
+	return 0;
+}
diff --git a/nimble/host/mesh/src/provisioner.c b/nimble/host/mesh/src/provisioner.c
new file mode 100644
index 0000000..48a1d90
--- /dev/null
+++ b/nimble/host/mesh/src/provisioner.c
@@ -0,0 +1,741 @@
+/*  Bluetooth Mesh */
+
+/*
+ * Copyright (c) 2017 Intel Corporation
+ * Copyright (c) 2020 Lingao Meng
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#define LOG_MODULE_NAME bt_mesh_provisioner
+
+#include "testing.h"
+
+#include "crypto.h"
+#include "adv.h"
+#include "mesh/mesh.h"
+#include "net.h"
+#include "rpl.h"
+#include "beacon.h"
+#include "access.h"
+#include "foundation.h"
+#include "proxy.h"
+#include "prov.h"
+#include "settings.h"
+
+static struct {
+	struct bt_mesh_cdb_node *node;
+	uint16_t addr;
+	uint16_t net_idx;
+	uint8_t attention_duration;
+	uint8_t uuid[16];
+} prov_device;
+
+static void send_pub_key(void);
+static void prov_dh_key_gen(void);
+static void pub_key_ready(const uint8_t *pkey);
+
+static int reset_state(void)
+{
+	if (prov_device.node != NULL) {
+		bt_mesh_cdb_node_del(prov_device.node, false);
+	}
+
+	return bt_mesh_prov_reset_state(pub_key_ready);
+}
+
+static void prov_link_close(enum prov_bearer_link_status status)
+{
+	BT_DBG("%u", status);
+	bt_mesh_prov_link.expect = PROV_NO_PDU;
+
+	bt_mesh_prov_link.bearer->link_close(status);
+}
+
+static void prov_fail(uint8_t reason)
+{
+	/* According to Bluetooth Mesh Specification v1.0.1, Section 5.4.4, the
+	 * provisioner just closes the link when something fails, while the
+	 * provisionee sends the fail message, and waits for the provisioner to
+	 * close the link.
+	 */
+	prov_link_close(PROV_BEARER_LINK_STATUS_FAIL);
+}
+
+static void send_invite(void)
+{
+	struct os_mbuf *inv = PROV_BUF(2);
+
+	BT_DBG("");
+
+	bt_mesh_prov_buf_init(inv, PROV_INVITE);
+	net_buf_simple_add_u8(inv, prov_device.attention_duration);
+
+	bt_mesh_prov_link.conf_inputs[0] = prov_device.attention_duration;
+
+	if (bt_mesh_prov_send(inv, NULL)) {
+		BT_ERR("Failed to send invite");
+		return;
+	}
+
+	bt_mesh_prov_link.expect = PROV_CAPABILITIES;
+}
+
+static void start_sent(int err, void *cb_data)
+{
+	if (!bt_pub_key_get()) {
+		atomic_set_bit(bt_mesh_prov_link.flags, WAIT_PUB_KEY);
+		BT_WARN("Waiting for local public key");
+	} else {
+		send_pub_key();
+	}
+}
+
+static void send_start(void)
+{
+	BT_DBG("");
+	uint8_t method, action;
+	struct os_mbuf *start = PROV_BUF(6);
+
+	const uint8_t *data = &bt_mesh_prov_link.conf_inputs[1 + 3];
+
+	bt_mesh_prov_buf_init(start, PROV_START);
+	net_buf_simple_add_u8(start, PROV_ALG_P256);
+
+	if (atomic_test_bit(bt_mesh_prov_link.flags, REMOTE_PUB_KEY) &&
+	    *data == PUB_KEY_OOB) {
+		net_buf_simple_add_u8(start, PUB_KEY_OOB);
+		atomic_set_bit(bt_mesh_prov_link.flags, OOB_PUB_KEY);
+	} else {
+		net_buf_simple_add_u8(start, PUB_KEY_NO_OOB);
+	}
+
+	if (bt_mesh_prov_link.oob_method == AUTH_METHOD_INPUT) {
+		method = AUTH_METHOD_OUTPUT;
+		if (bt_mesh_prov_link.oob_action == INPUT_OOB_STRING) {
+			action = OUTPUT_OOB_STRING;
+		} else {
+			action = OUTPUT_OOB_NUMBER;
+		}
+
+	} else if (bt_mesh_prov_link.oob_method == AUTH_METHOD_OUTPUT) {
+		method = AUTH_METHOD_INPUT;
+		if (bt_mesh_prov_link.oob_action == OUTPUT_OOB_STRING) {
+			action = INPUT_OOB_STRING;
+		} else {
+			action = INPUT_OOB_NUMBER;
+		}
+	} else {
+		method = bt_mesh_prov_link.oob_method;
+		action = 0x00;
+	}
+
+	net_buf_simple_add_u8(start, bt_mesh_prov_link.oob_method);
+
+	net_buf_simple_add_u8(start, bt_mesh_prov_link.oob_action);
+
+	net_buf_simple_add_u8(start, bt_mesh_prov_link.oob_size);
+
+	memcpy(&bt_mesh_prov_link.conf_inputs[12], &start->om_omp[1], 5);
+
+	if (bt_mesh_prov_auth(method, action, bt_mesh_prov_link.oob_size) < 0) {
+		BT_ERR("Invalid authentication method: 0x%02x; "
+		       "action: 0x%02x; size: 0x%02x", method,
+		       action, bt_mesh_prov_link.oob_size);
+		return;
+	}
+
+	if (bt_mesh_prov_send(start, start_sent)) {
+		BT_ERR("Failed to send Provisioning Start");
+		return;
+	}
+}
+
+static bool prov_check_method(struct bt_mesh_dev_capabilities *caps)
+{
+	if (bt_mesh_prov_link.oob_method == AUTH_METHOD_STATIC) {
+		if (!caps->static_oob) {
+			BT_WARN("Device not support OOB static authentication provisioning");
+			return false;
+		}
+	} else if (bt_mesh_prov_link.oob_method == AUTH_METHOD_INPUT) {
+		if (bt_mesh_prov_link.oob_size > caps->input_size) {
+			BT_WARN("The required input length (0x%02x) "
+				"exceeds the device capacity (0x%02x)",
+				bt_mesh_prov_link.oob_size, caps->input_size);
+			return false;
+		}
+
+		if (!(BIT(bt_mesh_prov_link.oob_action) & caps->input_actions)) {
+			BT_WARN("The required input action (0x%02x) "
+				"not supported by the device (0x%02x)",
+				bt_mesh_prov_link.oob_action, caps->input_actions);
+			return false;
+		}
+
+		if (bt_mesh_prov_link.oob_action == INPUT_OOB_STRING) {
+			if (!bt_mesh_prov->output_string) {
+				BT_WARN("Not support output string");
+				return false;
+			}
+		} else {
+			if (!bt_mesh_prov->output_number) {
+				BT_WARN("Not support output number");
+				return false;
+			}
+		}
+	} else if (bt_mesh_prov_link.oob_method == AUTH_METHOD_OUTPUT) {
+		if (bt_mesh_prov_link.oob_size > caps->output_size) {
+			BT_WARN("The required output length (0x%02x) "
+				"exceeds the device capacity (0x%02x)",
+				bt_mesh_prov_link.oob_size, caps->output_size);
+			return false;
+		}
+
+		if (!(BIT(bt_mesh_prov_link.oob_action) & caps->output_actions)) {
+			BT_WARN("The required output action (0x%02x) "
+				"not supported by the device (0x%02x)",
+				bt_mesh_prov_link.oob_action, caps->output_actions);
+			return false;
+		}
+
+		if (!bt_mesh_prov->input) {
+			BT_WARN("Not support input");
+			return false;
+		}
+	}
+
+	return true;
+}
+
+static void prov_capabilities(const uint8_t *data)
+{
+	struct bt_mesh_dev_capabilities caps;
+
+	caps.elem_count = data[0];
+	BT_DBG("Elements:          %u", caps.elem_count);
+
+	caps.algorithms = sys_get_be16(&data[1]);
+	BT_DBG("Algorithms:        %u", caps.algorithms);
+
+	caps.pub_key_type = data[3];
+	caps.static_oob = data[4];
+	caps.output_size = data[5];
+	BT_DBG("Public Key Type:   0x%02x", caps.pub_key_type);
+	BT_DBG("Static OOB Type:   0x%02x", caps.static_oob);
+	BT_DBG("Output OOB Size:   %u", caps.output_size);
+
+	caps.output_actions = (bt_mesh_output_action_t)data[6];
+	caps.input_size = data[8];
+	caps.input_actions = (bt_mesh_input_action_t)data[9];
+	BT_DBG("Output OOB Action: 0x%04x", caps.output_actions);
+	BT_DBG("Input OOB Size:    %u", caps.input_size);
+	BT_DBG("Input OOB Action:  0x%04x", caps.input_actions);
+
+	if (data[0] == 0) {
+		BT_ERR("Invalid number of elements");
+		prov_fail(PROV_ERR_NVAL_FMT);
+		return;
+	}
+
+	prov_device.node =
+		bt_mesh_cdb_node_alloc(prov_device.uuid,
+				       prov_device.addr, data[0],
+				       prov_device.net_idx);
+	if (prov_device.node == NULL) {
+		BT_ERR("Failed allocating node 0x%04x", prov_device.addr);
+		prov_fail(PROV_ERR_RESOURCES);
+		return;
+	}
+
+	memcpy(&bt_mesh_prov_link.conf_inputs[1], data, 11);
+
+	if (bt_mesh_prov->capabilities) {
+		bt_mesh_prov->capabilities(&caps);
+	}
+
+	if (!prov_check_method(&caps)) {
+		prov_fail(PROV_ERR_UNEXP_ERR);
+		return;
+	}
+
+	send_start();
+}
+
+static void send_confirm(void)
+{
+	struct os_mbuf *cfm = PROV_BUF(17);
+
+	BT_DBG("ConfInputs[0]   %s", bt_hex(bt_mesh_prov_link.conf_inputs, 64));
+	BT_DBG("ConfInputs[64]  %s", bt_hex(&bt_mesh_prov_link.conf_inputs[64], 64));
+	BT_DBG("ConfInputs[128] %s", bt_hex(&bt_mesh_prov_link.conf_inputs[128], 17));
+
+	if (bt_mesh_prov_conf_salt(bt_mesh_prov_link.conf_inputs,
+				   bt_mesh_prov_link.conf_salt)) {
+		BT_ERR("Unable to generate confirmation salt");
+		prov_fail(PROV_ERR_UNEXP_ERR);
+		return;
+	}
+
+	BT_DBG("ConfirmationSalt: %s", bt_hex(bt_mesh_prov_link.conf_salt, 16));
+
+	if (bt_mesh_prov_conf_key(bt_mesh_prov_link.dhkey,
+				  bt_mesh_prov_link.conf_salt, bt_mesh_prov_link.conf_key)) {
+		BT_ERR("Unable to generate confirmation key");
+		prov_fail(PROV_ERR_UNEXP_ERR);
+		return;
+	}
+
+	BT_DBG("ConfirmationKey: %s", bt_hex(bt_mesh_prov_link.conf_key, 16));
+
+	if (bt_rand(bt_mesh_prov_link.rand, 16)) {
+		BT_ERR("Unable to generate random number");
+		prov_fail(PROV_ERR_UNEXP_ERR);
+		return;
+	}
+
+	BT_DBG("LocalRandom: %s", bt_hex(bt_mesh_prov_link.rand, 16));
+
+	bt_mesh_prov_buf_init(cfm, PROV_CONFIRM);
+
+	if (bt_mesh_prov_conf(bt_mesh_prov_link.conf_key,
+			      bt_mesh_prov_link.rand, bt_mesh_prov_link.auth,
+			      net_buf_simple_add(cfm, 16))) {
+		BT_ERR("Unable to generate confirmation value");
+		prov_fail(PROV_ERR_UNEXP_ERR);
+		return;
+	}
+
+	if (bt_mesh_prov_send(cfm, NULL)) {
+		BT_ERR("Failed to send Provisioning Confirm");
+		return;
+	}
+
+	bt_mesh_prov_link.expect = PROV_CONFIRM;
+}
+
+static void public_key_sent(int err, void *cb_data)
+{
+	atomic_set_bit(bt_mesh_prov_link.flags, PUB_KEY_SENT);
+
+	if (atomic_test_bit(bt_mesh_prov_link.flags, OOB_PUB_KEY) &&
+	    atomic_test_bit(bt_mesh_prov_link.flags, REMOTE_PUB_KEY)) {
+		prov_dh_key_gen();
+		return;
+	}
+
+	bt_mesh_prov_link.expect = PROV_PUB_KEY;
+}
+
+static void send_pub_key(void)
+{
+	struct os_mbuf *buf = PROV_BUF(65);
+	const uint8_t *key;
+
+	key = bt_pub_key_get();
+	if (!key) {
+		BT_ERR("No public key available");
+		prov_fail(PROV_ERR_UNEXP_ERR);
+		return;
+	}
+
+	BT_DBG("Local Public Key: %s", bt_hex(key, 64));
+
+	bt_mesh_prov_buf_init(buf, PROV_PUB_KEY);
+
+	/* Swap X and Y halves independently to big-endian */
+	sys_memcpy_swap(net_buf_simple_add(buf, 32), key, 32);
+	sys_memcpy_swap(net_buf_simple_add(buf, 32), &key[32], 32);
+
+	/* PublicKeyProvisioner */
+	memcpy(&bt_mesh_prov_link.conf_inputs[17], &buf->om_databuf[1], 64);
+
+	if (bt_mesh_prov_send(buf, public_key_sent)) {
+		BT_ERR("Failed to send Public Key");
+		return;
+	}
+}
+
+static void prov_dh_key_cb(const uint8_t dhkey[32])
+{
+	BT_DBG("%p", dhkey);
+
+	if (!dhkey) {
+		BT_ERR("DHKey generation failed");
+		prov_fail(PROV_ERR_UNEXP_ERR);
+		return;
+	}
+
+	sys_memcpy_swap(bt_mesh_prov_link.dhkey, dhkey, 32);
+
+	BT_DBG("DHkey: %s", bt_hex(bt_mesh_prov_link.dhkey, 32));
+
+	if (atomic_test_bit(bt_mesh_prov_link.flags, WAIT_STRING) ||
+	    atomic_test_bit(bt_mesh_prov_link.flags, WAIT_NUMBER) ||
+	    atomic_test_bit(bt_mesh_prov_link.flags, NOTIFY_INPUT_COMPLETE)) {
+		atomic_set_bit(bt_mesh_prov_link.flags, WAIT_CONFIRM);
+		return;
+	}
+
+	send_confirm();
+}
+
+static void prov_dh_key_gen(void)
+{
+	uint8_t remote_pk_le[64], *remote_pk;
+
+	remote_pk = &bt_mesh_prov_link.conf_inputs[81];
+
+	/* Copy remote key in little-endian for bt_dh_key_gen().
+	 * X and Y halves are swapped independently. The bt_dh_key_gen()
+	 * will also take care of validating the remote public key.
+	 */
+	sys_memcpy_swap(remote_pk_le, remote_pk, 32);
+	sys_memcpy_swap(&remote_pk_le[32], &remote_pk[32], 32);
+
+	if (bt_dh_key_gen(remote_pk_le, prov_dh_key_cb)) {
+		BT_ERR("Failed to generate DHKey");
+		prov_fail(PROV_ERR_UNEXP_ERR);
+	}
+
+	if (atomic_test_bit(bt_mesh_prov_link.flags, NOTIFY_INPUT_COMPLETE)) {
+		bt_mesh_prov_link.expect = PROV_INPUT_COMPLETE;
+	}
+}
+
+static void prov_pub_key(const uint8_t *data)
+{
+	BT_DBG("Remote Public Key: %s", bt_hex(data, 64));
+
+	atomic_set_bit(bt_mesh_prov_link.flags, REMOTE_PUB_KEY);
+
+	/* PublicKeyDevice */
+	memcpy(&bt_mesh_prov_link.conf_inputs[81], data, 64);
+	bt_mesh_prov_link.bearer->clear_tx();
+
+	prov_dh_key_gen();
+}
+
+static void pub_key_ready(const uint8_t *pkey)
+{
+	if (!pkey) {
+		BT_WARN("Public key not available");
+		return;
+	}
+
+	BT_DBG("Local public key ready");
+
+	if (atomic_test_and_clear_bit(bt_mesh_prov_link.flags, WAIT_PUB_KEY)) {
+		send_pub_key();
+	}
+}
+
+static void notify_input_complete(void)
+{
+	if (atomic_test_and_clear_bit(bt_mesh_prov_link.flags,
+				      NOTIFY_INPUT_COMPLETE) &&
+	    bt_mesh_prov->input_complete) {
+		bt_mesh_prov->input_complete();
+	}
+}
+
+static void prov_input_complete(const uint8_t *data)
+{
+	BT_DBG("");
+
+	notify_input_complete();
+
+	if (atomic_test_and_clear_bit(bt_mesh_prov_link.flags, WAIT_CONFIRM)) {
+		send_confirm();
+	}
+}
+
+static void send_prov_data(void)
+{
+	struct os_mbuf *pdu = PROV_BUF(34);
+	struct bt_mesh_cdb_subnet *sub;
+	uint8_t session_key[16];
+	uint8_t nonce[13];
+	int err;
+
+	err = bt_mesh_session_key(bt_mesh_prov_link.dhkey,
+				  bt_mesh_prov_link.prov_salt, session_key);
+	if (err) {
+		BT_ERR("Unable to generate session key");
+		prov_fail(PROV_ERR_UNEXP_ERR);
+		return;
+	}
+
+	BT_DBG("SessionKey: %s", bt_hex(session_key, 16));
+
+	err = bt_mesh_prov_nonce(bt_mesh_prov_link.dhkey,
+				 bt_mesh_prov_link.prov_salt, nonce);
+	if (err) {
+		BT_ERR("Unable to generate session nonce");
+		prov_fail(PROV_ERR_UNEXP_ERR);
+		return;
+	}
+
+	BT_DBG("Nonce: %s", bt_hex(nonce, 13));
+
+	err = bt_mesh_dev_key(bt_mesh_prov_link.dhkey,
+			      bt_mesh_prov_link.prov_salt, prov_device.node->dev_key);
+	if (err) {
+		BT_ERR("Unable to generate device key");
+		prov_fail(PROV_ERR_UNEXP_ERR);
+		return;
+	}
+
+	BT_DBG("DevKey: %s", bt_hex(prov_device.node->dev_key, 16));
+
+	sub = bt_mesh_cdb_subnet_get(prov_device.node->net_idx);
+	if (sub == NULL) {
+		BT_ERR("No subnet with net_idx %u",
+		       prov_device.node->net_idx);
+		prov_fail(PROV_ERR_UNEXP_ERR);
+		return;
+	}
+
+	bt_mesh_prov_buf_init(pdu, PROV_DATA);
+	net_buf_simple_add_mem(pdu, sub->keys[sub->kr_flag].net_key, 16);
+	net_buf_simple_add_be16(pdu, prov_device.node->net_idx);
+	net_buf_simple_add_u8(pdu, bt_mesh_cdb_subnet_flags(sub));
+	net_buf_simple_add_be32(pdu, bt_mesh_cdb.iv_index);
+	net_buf_simple_add_be16(pdu, prov_device.node->addr);
+	net_buf_simple_add(pdu, 8); /* For MIC */
+
+	BT_DBG("net_idx %u, iv_index 0x%08x, addr 0x%04x",
+	       prov_device.node->net_idx, bt_mesh.iv_index,
+	       prov_device.node->addr);
+
+	err = bt_mesh_prov_encrypt(session_key, nonce, &pdu->om_databuf[1],
+				   &pdu->om_databuf[1]);
+	if (err) {
+		BT_ERR("Unable to encrypt provisioning data");
+		prov_fail(PROV_ERR_DECRYPT);
+		return;
+	}
+
+	if (bt_mesh_prov_send(pdu, NULL)) {
+		BT_ERR("Failed to send Provisioning Data");
+		return;
+	}
+
+	bt_mesh_prov_link.expect = PROV_COMPLETE;
+}
+
+static void prov_complete(const uint8_t *data)
+{
+	struct bt_mesh_cdb_node *node = prov_device.node;
+
+	BT_DBG("key %s, net_idx %u, num_elem %u, addr 0x%04x",
+	       bt_hex(node->dev_key, 16), node->net_idx, node->num_elem,
+	       node->addr);
+
+	if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
+		bt_mesh_store_cdb_node(node);
+	}
+
+	prov_device.node = NULL;
+	prov_link_close(PROV_BEARER_LINK_STATUS_SUCCESS);
+
+	if (bt_mesh_prov->node_added) {
+		bt_mesh_prov->node_added(node->net_idx, node->uuid, node->addr,
+					 node->num_elem);
+	}
+}
+
+static void send_random(void)
+{
+	struct os_mbuf *rnd = PROV_BUF(17);
+
+	bt_mesh_prov_buf_init(rnd, PROV_RANDOM);
+	net_buf_simple_add_mem(rnd, bt_mesh_prov_link.rand, 16);
+
+	if (bt_mesh_prov_send(rnd, NULL)) {
+		BT_ERR("Failed to send Provisioning Random");
+		return;
+	}
+
+	bt_mesh_prov_link.expect = PROV_RANDOM;
+}
+
+static void prov_random(const uint8_t *data)
+{
+	uint8_t conf_verify[16];
+
+	BT_DBG("Remote Random: %s", bt_hex(data, 16));
+	if (!memcmp(data, bt_mesh_prov_link.rand, 16)) {
+		BT_ERR("Random value is identical to ours, rejecting.");
+		prov_fail(PROV_ERR_CFM_FAILED);
+		return;
+	}
+
+	if (bt_mesh_prov_conf(bt_mesh_prov_link.conf_key,
+			      data, bt_mesh_prov_link.auth, conf_verify)) {
+		BT_ERR("Unable to calculate confirmation verification");
+		prov_fail(PROV_ERR_UNEXP_ERR);
+		return;
+	}
+
+	if (memcmp(conf_verify, bt_mesh_prov_link.conf, 16)) {
+		BT_ERR("Invalid confirmation value");
+		BT_DBG("Received:   %s", bt_hex(bt_mesh_prov_link.conf, 16));
+		BT_DBG("Calculated: %s",  bt_hex(conf_verify, 16));
+		prov_fail(PROV_ERR_CFM_FAILED);
+		return;
+	}
+
+	if (bt_mesh_prov_salt(bt_mesh_prov_link.conf_salt,
+			      bt_mesh_prov_link.rand, data, bt_mesh_prov_link.prov_salt)) {
+		BT_ERR("Failed to generate provisioning salt");
+		prov_fail(PROV_ERR_UNEXP_ERR);
+		return;
+	}
+
+	BT_DBG("ProvisioningSalt: %s", bt_hex(bt_mesh_prov_link.prov_salt, 16));
+
+	send_prov_data();
+}
+
+static void prov_confirm(const uint8_t *data)
+{
+	BT_DBG("Remote Confirm: %s", bt_hex(data, 16));
+
+	memcpy(bt_mesh_prov_link.conf, data, 16);
+
+	send_random();
+}
+
+static void prov_failed(const uint8_t *data)
+{
+	BT_WARN("Error: 0x%02x", data[0]);
+	reset_state();
+}
+
+static void local_input_complete(void)
+{
+	if (atomic_test_and_clear_bit(bt_mesh_prov_link.flags, WAIT_CONFIRM)) {
+		send_confirm();
+	}
+}
+
+static void prov_link_closed(void)
+{
+	reset_state();
+}
+
+static void prov_link_opened(void)
+{
+	send_invite();
+}
+
+static const struct bt_mesh_prov_role role_provisioner = {
+	.input_complete = local_input_complete,
+	.link_opened = prov_link_opened,
+	.link_closed = prov_link_closed,
+	.error = prov_fail,
+	.op = {
+		[PROV_CAPABILITIES] = prov_capabilities,
+		[PROV_PUB_KEY] = prov_pub_key,
+		[PROV_INPUT_COMPLETE] = prov_input_complete,
+		[PROV_CONFIRM] = prov_confirm,
+		[PROV_RANDOM] = prov_random,
+		[PROV_COMPLETE] = prov_complete,
+		[PROV_FAILED] = prov_failed,
+	},
+};
+
+static void prov_set_method(uint8_t method, uint8_t action, uint8_t size)
+{
+	bt_mesh_prov_link.oob_method = method;
+	bt_mesh_prov_link.oob_action = action;
+	bt_mesh_prov_link.oob_size = size;
+}
+
+int bt_mesh_auth_method_set_input(bt_mesh_input_action_t action, uint8_t size)
+{
+	if (!action || !size || size > 8) {
+		return -EINVAL;
+	}
+
+	prov_set_method(AUTH_METHOD_INPUT, find_msb_set(action) - 1, size);
+	return 0;
+}
+
+int bt_mesh_auth_method_set_output(bt_mesh_output_action_t action, uint8_t size)
+{
+	if (!action || !size || size > 8) {
+		return -EINVAL;
+	}
+
+	prov_set_method(AUTH_METHOD_OUTPUT, find_msb_set(action) - 1, size);
+	return 0;
+}
+
+int bt_mesh_auth_method_set_static(const uint8_t *static_val, uint8_t size)
+{
+	if (!size || !static_val || size > 16) {
+		return -EINVAL;
+	}
+
+	prov_set_method(AUTH_METHOD_STATIC, 0, 0);
+
+	memcpy(bt_mesh_prov_link.auth + 16 - size, static_val, size);
+	if (size < 16) {
+		(void)memset(bt_mesh_prov_link.auth, 0,
+			     sizeof(bt_mesh_prov_link.auth) - size);
+	}
+	return 0;
+}
+
+int bt_mesh_auth_method_set_none(void)
+{
+	prov_set_method(AUTH_METHOD_NO_OOB, 0, 0);
+	return 0;
+}
+
+int bt_mesh_prov_remote_pub_key_set(const uint8_t public_key[64])
+{
+	if (public_key == NULL) {
+		return -EINVAL;
+	}
+
+	if (atomic_test_and_set_bit(bt_mesh_prov_link.flags, REMOTE_PUB_KEY)) {
+		return -EALREADY;
+	}
+
+	/* Swap X and Y halves independently to big-endian */
+	memcpy(&bt_mesh_prov_link.conf_inputs[81], public_key, 32);
+	memcpy(&bt_mesh_prov_link.conf_inputs[81 + 32], &public_key[32], 32);
+
+	return 0;
+}
+
+#if defined(CONFIG_BT_MESH_PB_ADV)
+int bt_mesh_pb_adv_open(const uint8_t uuid[16], uint16_t net_idx, uint16_t addr,
+			uint8_t attention_duration)
+{
+	int err;
+
+	if (atomic_test_and_set_bit(bt_mesh_prov_link.flags, LINK_ACTIVE)) {
+		return -EBUSY;
+	}
+
+	atomic_set_bit(bt_mesh_prov_link.flags, PROVISIONER);
+	memcpy(prov_device.uuid, uuid, 16);
+	prov_device.addr = addr;
+	prov_device.net_idx = net_idx;
+	prov_device.attention_duration = attention_duration;
+	bt_mesh_prov_link.bearer = &pb_adv;
+	bt_mesh_prov_link.role = &role_provisioner;
+
+	err = bt_mesh_prov_link.bearer->link_open(prov_device.uuid, PROTOCOL_TIMEOUT,
+						  bt_mesh_prov_bearer_cb_get(), NULL);
+	if (err) {
+		atomic_clear_bit(bt_mesh_prov_link.flags, LINK_ACTIVE);
+	}
+
+	return err;
+}
+#endif
\ No newline at end of file
diff --git a/nimble/host/mesh/src/provisioner.h b/nimble/host/mesh/src/provisioner.h
new file mode 100644
index 0000000..ccda47e
--- /dev/null
+++ b/nimble/host/mesh/src/provisioner.h
@@ -0,0 +1,10 @@
+/*  Bluetooth Mesh */
+
+/*
+ * Copyright (c) 2017 Intel Corporation
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+int bt_mesh_pb_adv_open(const uint8_t uuid[16], uint16_t net_idx, uint16_t addr,
+			uint8_t attention_duration);
\ No newline at end of file
diff --git a/nimble/host/mesh/src/shell.c b/nimble/host/mesh/src/shell.c
index e845418..7108728 100644
--- a/nimble/host/mesh/src/shell.c
+++ b/nimble/host/mesh/src/shell.c
@@ -2229,7 +2229,7 @@
 
 #endif /* MYNEWT_VAL(BLE_MESH_CFG_CLI) */
 
-#if MYNEWT_VAL(BLE_MESH_PROV)
+#if MYNEWT_VAL(BLE_MESH_PROV_DEVICE)
 static int cmd_pb(bt_mesh_prov_bearer_t bearer, int argc, char *argv[])
 {
 	int err;
diff --git a/nimble/host/mesh/syscfg.yml b/nimble/host/mesh/syscfg.yml
index 446aee1..d31238f 100644
--- a/nimble/host/mesh/syscfg.yml
+++ b/nimble/host/mesh/syscfg.yml
@@ -40,12 +40,19 @@
            Timeout value of retransmit provisioning PDUs.
         value: 500
 
+    BLE_MESH_PROV_DEVICE:
+        description: >
+           Enable this option to allow the device to be provisioned into a mesh network.
+        value: 1
+        restrictions: BLE_MESH_PROV
+
     BLE_MESH_PROVISIONER:
         description: >
             Enable this option to have support for provisioning remote devices.
-        value: 0
+        value: 1
         restrictions:
-            - (BLE_MESH_PROV)
+            - BLE_MESH_PROV
+            - BLE_MESH_PB_ADV
 
     BLE_MESH_CDB:
         description: >
@@ -697,6 +704,24 @@
             Minimum level for the BLE Mesh Replay protection list log.
         value: 1
 
+    BLE_MESH_PROV_DEVICE_LOG_MOD:
+        description: >
+            Numeric module ID to use for BLE Mesh Replay protection list messages.
+        value: 24
+    BLE_MESH_PROV_DEVICE_LOG_LVL:
+        description: >
+            Minimum level for the BLE Mesh Replay protection list log.
+        value: 1
+
+    BLE_MESH_PROVISIONER_LOG_MOD:
+        description: >
+            Numeric module ID to use for BLE Mesh Replay protection list messages.
+        value: 25
+    BLE_MESH_PROVISIONER_LOG_LVL:
+        description: >
+            Minimum level for the BLE Mesh Replay protection list log.
+        value: 1
+
 syscfg.logs:
     BLE_MESH_LOG:
         module: MYNEWT_VAL(BLE_MESH_LOG_MOD)
@@ -758,6 +783,14 @@
         module: MYNEWT_VAL(BLE_MESH_NET_KEYS_LOG_MOD)
         level: MYNEWT_VAL(BLE_MESH_NET_KEYS_LOG_LVL)
 
+    BLE_MESH_PROV_DEVICE_LOG:
+        module: MYNEWT_VAL(BLE_MESH_PROV_DEVICE_LOG_MOD)
+        level: MYNEWT_VAL(BLE_MESH_PROV_DEVICE_LOG_LVL)
+
+    BLE_MESH_PROVISIONER_LOG:
+        module: MYNEWT_VAL(BLE_MESH_PROVISIONER_LOG_MOD)
+        level: MYNEWT_VAL(BLE_MESH_PROVISIONER_LOG_LVL)
+
 syscfg.vals.BLE_MESH_SHELL:
     BLE_MESH_CFG_CLI: 1
     BLE_MESH_HEALTH_CLI: 1
diff --git a/porting/examples/linux_blemesh/include/logcfg/logcfg.h b/porting/examples/linux_blemesh/include/logcfg/logcfg.h
index 6eff5ef..d2903ed 100644
--- a/porting/examples/linux_blemesh/include/logcfg/logcfg.h
+++ b/porting/examples/linux_blemesh/include/logcfg/logcfg.h
@@ -120,6 +120,13 @@
 #define BLE_MESH_NET_KEYS_LOG_CRITICAL(...) MODLOG_CRITICAL(23, __VA_ARGS__)
 #define BLE_MESH_NET_KEYS_LOG_DISABLED(...) MODLOG_DISABLED(23, __VA_ARGS__)
 
+#define BLE_MESH_PROV_DEVICE_LOG_DEBUG(...) IGNORE(__VA_ARGS__)
+#define BLE_MESH_PROV_DEVICE_LOG_INFO(...) MODLOG_INFO(24, __VA_ARGS__)
+#define BLE_MESH_PROV_DEVICE_LOG_WARN(...) MODLOG_WARN(24, __VA_ARGS__)
+#define BLE_MESH_PROV_DEVICE_LOG_ERROR(...) MODLOG_ERROR(24, __VA_ARGS__)
+#define BLE_MESH_PROV_DEVICE_LOG_CRITICAL(...) MODLOG_CRITICAL(24, __VA_ARGS__)
+#define BLE_MESH_PROV_DEVICE_LOG_DISABLED(...) MODLOG_DISABLED(24, __VA_ARGS__)
+
 #define DFLT_LOG_DEBUG(...) IGNORE(__VA_ARGS__)
 #define DFLT_LOG_INFO(...) MODLOG_INFO(0, __VA_ARGS__)
 #define DFLT_LOG_WARN(...) MODLOG_WARN(0, __VA_ARGS__)