2020-09-17 13:47:37 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Intel Corporation
|
|
|
|
* Copyright (c) 2020 Lingao Meng
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.
The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.
NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-25 09:58:46 +02:00
|
|
|
#include <zephyr/kernel.h>
|
2020-09-17 13:47:37 +08:00
|
|
|
#include <errno.h>
|
2022-05-06 11:12:04 +02:00
|
|
|
#include <zephyr/sys/atomic.h>
|
|
|
|
#include <zephyr/sys/util.h>
|
|
|
|
#include <zephyr/sys/byteorder.h>
|
|
|
|
|
|
|
|
#include <zephyr/net/buf.h>
|
|
|
|
#include <zephyr/bluetooth/bluetooth.h>
|
|
|
|
#include <zephyr/bluetooth/conn.h>
|
|
|
|
#include <zephyr/bluetooth/mesh.h>
|
|
|
|
#include <zephyr/bluetooth/uuid.h>
|
2020-09-17 13:47:37 +08:00
|
|
|
|
2022-10-25 08:48:54 +02:00
|
|
|
#include "common/bt_str.h"
|
2020-09-17 13:47:37 +08:00
|
|
|
|
|
|
|
#include "crypto.h"
|
|
|
|
#include "adv.h"
|
|
|
|
#include "mesh.h"
|
|
|
|
#include "net.h"
|
|
|
|
#include "rpl.h"
|
|
|
|
#include "beacon.h"
|
|
|
|
#include "access.h"
|
|
|
|
#include "foundation.h"
|
|
|
|
#include "proxy.h"
|
2021-08-19 09:25:25 +08:00
|
|
|
#include "pb_gatt_srv.h"
|
2020-09-17 13:47:37 +08:00
|
|
|
#include "prov.h"
|
|
|
|
#include "settings.h"
|
2020-03-03 12:12:53 +01:00
|
|
|
#include "rpr.h"
|
2020-09-17 13:47:37 +08:00
|
|
|
|
2022-11-02 14:31:13 +01:00
|
|
|
#define LOG_LEVEL CONFIG_BT_MESH_PROV_DEVICE_LOG_LEVEL
|
|
|
|
#include <zephyr/logging/log.h>
|
|
|
|
LOG_MODULE_REGISTER(bt_mesh_prov_device);
|
|
|
|
|
2020-03-03 12:12:53 +01:00
|
|
|
static void reprovision_fail(void);
|
2020-09-17 13:47:37 +08:00
|
|
|
|
|
|
|
static void prov_send_fail_msg(uint8_t err)
|
|
|
|
{
|
2021-06-16 15:12:57 +02:00
|
|
|
PROV_BUF(buf, PDU_LEN_FAILED);
|
2020-09-17 13:47:37 +08:00
|
|
|
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_DBG("%u", err);
|
2020-09-17 13:47:37 +08:00
|
|
|
|
|
|
|
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)) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Failed to send Provisioning Failed message");
|
2020-09-17 13:47:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2020-03-03 12:12:53 +01:00
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_BT_MESH_RPR_SRV) &&
|
|
|
|
atomic_test_bit(bt_mesh_prov_link.flags, REPROVISION)) {
|
|
|
|
reprovision_fail();
|
|
|
|
}
|
2020-09-17 13:47:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void prov_invite(const uint8_t *data)
|
|
|
|
{
|
2021-06-16 15:12:57 +02:00
|
|
|
PROV_BUF(buf, PDU_LEN_CAPABILITIES);
|
2020-09-17 13:47:37 +08:00
|
|
|
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_DBG("Attention Duration: %u seconds", data[0]);
|
2020-09-17 13:47:37 +08:00
|
|
|
|
|
|
|
if (data[0]) {
|
|
|
|
bt_mesh_attention(NULL, data[0]);
|
|
|
|
}
|
|
|
|
|
2021-06-16 15:12:57 +02:00
|
|
|
memcpy(bt_mesh_prov_link.conf_inputs.invite, data, PDU_LEN_INVITE);
|
2020-09-17 13:47:37 +08:00
|
|
|
|
|
|
|
bt_mesh_prov_buf_init(&buf, PROV_CAPABILITIES);
|
|
|
|
|
|
|
|
/* Number of Elements supported */
|
|
|
|
net_buf_simple_add_u8(&buf, bt_mesh_elem_count());
|
|
|
|
|
2021-08-09 16:43:16 +02:00
|
|
|
uint16_t algorithm_bm = 0;
|
|
|
|
uint8_t oob_type = bt_mesh_prov->static_val ?
|
|
|
|
BT_MESH_STATIC_OOB_AVAILABLE : 0;
|
|
|
|
bool oob_availability = bt_mesh_prov->output_size > 0 ||
|
|
|
|
bt_mesh_prov->input_size > 0 || bt_mesh_prov->static_val;
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_BT_MESH_ECDH_P256_HMAC_SHA256_AES_CCM)) {
|
|
|
|
algorithm_bm |= BIT(BT_MESH_PROV_AUTH_HMAC_SHA256_AES_CCM);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_BT_MESH_ECDH_P256_CMAC_AES128_AES_CCM)) {
|
|
|
|
algorithm_bm |= BIT(BT_MESH_PROV_AUTH_CMAC_AES128_AES_CCM);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oob_availability && IS_ENABLED(CONFIG_BT_MESH_OOB_AUTH_REQUIRED)) {
|
|
|
|
oob_type |= BT_MESH_OOB_AUTH_REQUIRED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Supported algorithms */
|
|
|
|
net_buf_simple_add_be16(&buf, algorithm_bm);
|
2020-09-17 13:47:37 +08:00
|
|
|
|
2021-06-09 11:01:57 +02:00
|
|
|
/* Public Key Type */
|
|
|
|
net_buf_simple_add_u8(&buf,
|
|
|
|
bt_mesh_prov->public_key_be == NULL ? PUB_KEY_NO_OOB : PUB_KEY_OOB);
|
2020-09-17 13:47:37 +08:00
|
|
|
|
|
|
|
/* Static OOB Type */
|
2021-08-09 16:43:16 +02:00
|
|
|
net_buf_simple_add_u8(&buf, oob_type);
|
2020-09-17 13:47:37 +08:00
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
2021-06-16 15:12:57 +02:00
|
|
|
memcpy(bt_mesh_prov_link.conf_inputs.capabilities, &buf.data[1], PDU_LEN_CAPABILITIES);
|
2020-09-17 13:47:37 +08:00
|
|
|
|
|
|
|
if (bt_mesh_prov_send(&buf, NULL)) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Failed to send capabilities");
|
2020-09-17 13:47:37 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_mesh_prov_link.expect = PROV_START;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void prov_start(const uint8_t *data)
|
|
|
|
{
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_DBG("Algorithm: 0x%02x", data[0]);
|
|
|
|
LOG_DBG("Public Key: 0x%02x", data[1]);
|
|
|
|
LOG_DBG("Auth Method: 0x%02x", data[2]);
|
|
|
|
LOG_DBG("Auth Action: 0x%02x", data[3]);
|
|
|
|
LOG_DBG("Auth Size: 0x%02x", data[4]);
|
2020-09-17 13:47:37 +08:00
|
|
|
|
2021-08-09 16:43:16 +02:00
|
|
|
if (IS_ENABLED(CONFIG_BT_MESH_ECDH_P256_HMAC_SHA256_AES_CCM) &&
|
|
|
|
data[0] == BT_MESH_PROV_AUTH_HMAC_SHA256_AES_CCM) {
|
|
|
|
bt_mesh_prov_link.algorithm = data[0];
|
|
|
|
} else if (IS_ENABLED(CONFIG_BT_MESH_ECDH_P256_CMAC_AES128_AES_CCM) &&
|
|
|
|
data[0] == BT_MESH_PROV_AUTH_CMAC_AES128_AES_CCM) {
|
|
|
|
bt_mesh_prov_link.algorithm = data[0];
|
|
|
|
} else {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Unknown algorithm 0x%02x", data[0]);
|
2020-09-17 13:47:37 +08:00
|
|
|
prov_fail(PROV_ERR_NVAL_FMT);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-09 16:43:16 +02:00
|
|
|
uint8_t auth_size = bt_mesh_prov_auth_size_get();
|
|
|
|
|
2021-09-02 12:58:08 +02:00
|
|
|
if (data[1] > PUB_KEY_OOB ||
|
|
|
|
(data[1] == PUB_KEY_OOB &&
|
|
|
|
(!IS_ENABLED(CONFIG_BT_MESH_PROV_OOB_PUBLIC_KEY) || !bt_mesh_prov->public_key_be))) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Invalid public key type: 0x%02x", data[1]);
|
2020-09-17 13:47:37 +08:00
|
|
|
prov_fail(PROV_ERR_NVAL_FMT);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-09 11:01:57 +02:00
|
|
|
atomic_set_bit_to(bt_mesh_prov_link.flags, OOB_PUB_KEY, data[1] == PUB_KEY_OOB);
|
|
|
|
|
2021-06-16 15:12:57 +02:00
|
|
|
memcpy(bt_mesh_prov_link.conf_inputs.start, data, PDU_LEN_START);
|
2020-09-17 13:47:37 +08:00
|
|
|
|
|
|
|
bt_mesh_prov_link.expect = PROV_PUB_KEY;
|
2021-09-01 13:05:15 +02:00
|
|
|
bt_mesh_prov_link.oob_method = data[2];
|
|
|
|
bt_mesh_prov_link.oob_action = data[3];
|
|
|
|
bt_mesh_prov_link.oob_size = data[4];
|
2020-09-17 13:47:37 +08:00
|
|
|
|
2021-09-01 13:05:15 +02:00
|
|
|
if (bt_mesh_prov_auth(false, data[2], data[3], data[4]) < 0) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Invalid authentication method: 0x%02x; "
|
2021-08-09 16:43:16 +02:00
|
|
|
"action: 0x%02x; size: 0x%02x", data[2], data[3], data[4]);
|
2020-09-17 13:47:37 +08:00
|
|
|
prov_fail(PROV_ERR_NVAL_FMT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (atomic_test_bit(bt_mesh_prov_link.flags, OOB_STATIC_KEY)) {
|
2021-08-09 16:43:16 +02:00
|
|
|
memcpy(bt_mesh_prov_link.auth + auth_size - bt_mesh_prov->static_val_len,
|
|
|
|
bt_mesh_prov->static_val, bt_mesh_prov->static_val_len);
|
|
|
|
memset(bt_mesh_prov_link.auth, 0, auth_size - bt_mesh_prov->static_val_len);
|
2020-09-17 13:47:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void send_confirm(void)
|
|
|
|
{
|
2021-06-16 15:12:57 +02:00
|
|
|
PROV_BUF(cfm, PDU_LEN_CONFIRM);
|
2021-08-09 16:43:16 +02:00
|
|
|
uint8_t auth_size = bt_mesh_prov_auth_size_get();
|
2021-06-16 15:12:57 +02:00
|
|
|
uint8_t *inputs = (uint8_t *)&bt_mesh_prov_link.conf_inputs;
|
2021-08-09 16:43:16 +02:00
|
|
|
uint8_t conf_key_input[64];
|
2020-09-17 13:47:37 +08:00
|
|
|
|
2021-08-09 16:43:16 +02:00
|
|
|
LOG_DBG("ConfInputs[0] %s", bt_hex(inputs, 32));
|
|
|
|
LOG_DBG("ConfInputs[32] %s", bt_hex(&inputs[32], 32));
|
|
|
|
LOG_DBG("ConfInputs[64] %s", bt_hex(&inputs[64], 32));
|
|
|
|
LOG_DBG("ConfInputs[96] %s", bt_hex(&inputs[96], 32));
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_DBG("ConfInputs[128] %s", bt_hex(&inputs[128], 17));
|
2020-09-17 13:47:37 +08:00
|
|
|
|
2021-08-09 16:43:16 +02:00
|
|
|
if (bt_mesh_prov_conf_salt(bt_mesh_prov_link.algorithm, inputs,
|
|
|
|
bt_mesh_prov_link.conf_salt)) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Unable to generate confirmation salt");
|
2020-09-17 13:47:37 +08:00
|
|
|
prov_fail(PROV_ERR_UNEXP_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-09 16:43:16 +02:00
|
|
|
LOG_DBG("ConfirmationSalt: %s", bt_hex(bt_mesh_prov_link.conf_salt, auth_size));
|
|
|
|
|
|
|
|
memcpy(conf_key_input, bt_mesh_prov_link.dhkey, 32);
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_BT_MESH_ECDH_P256_HMAC_SHA256_AES_CCM) &&
|
|
|
|
bt_mesh_prov_link.algorithm == BT_MESH_PROV_AUTH_HMAC_SHA256_AES_CCM) {
|
|
|
|
memcpy(&conf_key_input[32], bt_mesh_prov_link.auth, 32);
|
|
|
|
LOG_DBG("AuthValue %s", bt_hex(bt_mesh_prov_link.auth, 32));
|
|
|
|
}
|
2020-09-17 13:47:37 +08:00
|
|
|
|
2021-08-09 16:43:16 +02:00
|
|
|
if (bt_mesh_prov_conf_key(bt_mesh_prov_link.algorithm, conf_key_input,
|
|
|
|
bt_mesh_prov_link.conf_salt, bt_mesh_prov_link.conf_key)) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Unable to generate confirmation key");
|
2020-09-17 13:47:37 +08:00
|
|
|
prov_fail(PROV_ERR_UNEXP_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-09 16:43:16 +02:00
|
|
|
LOG_DBG("ConfirmationKey: %s", bt_hex(bt_mesh_prov_link.conf_key, auth_size));
|
2020-09-17 13:47:37 +08:00
|
|
|
|
2021-08-09 16:43:16 +02:00
|
|
|
if (bt_rand(bt_mesh_prov_link.rand, auth_size)) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Unable to generate random number");
|
2020-09-17 13:47:37 +08:00
|
|
|
prov_fail(PROV_ERR_UNEXP_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-09 16:43:16 +02:00
|
|
|
LOG_DBG("LocalRandom: %s", bt_hex(bt_mesh_prov_link.rand, auth_size));
|
2020-09-17 13:47:37 +08:00
|
|
|
|
|
|
|
bt_mesh_prov_buf_init(&cfm, PROV_CONFIRM);
|
|
|
|
|
2021-08-09 16:43:16 +02:00
|
|
|
if (bt_mesh_prov_conf(bt_mesh_prov_link.algorithm, bt_mesh_prov_link.conf_key,
|
|
|
|
bt_mesh_prov_link.rand, bt_mesh_prov_link.auth,
|
|
|
|
net_buf_simple_add(&cfm, auth_size))) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Unable to generate confirmation value");
|
2020-09-17 13:47:37 +08:00
|
|
|
prov_fail(PROV_ERR_UNEXP_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bt_mesh_prov_send(&cfm, NULL)) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Failed to send Provisioning Confirm");
|
2020-09-17 13:47:37 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_mesh_prov_link.expect = PROV_RANDOM;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void send_input_complete(void)
|
|
|
|
{
|
2021-06-16 15:12:57 +02:00
|
|
|
PROV_BUF(buf, PDU_LEN_INPUT_COMPLETE);
|
2020-09-17 13:47:37 +08:00
|
|
|
|
|
|
|
bt_mesh_prov_buf_init(&buf, PROV_INPUT_COMPLETE);
|
|
|
|
if (bt_mesh_prov_send(&buf, NULL)) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Failed to send Provisioning Input Complete");
|
2020-09-17 13:47:37 +08:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-09 11:01:57 +02:00
|
|
|
static void start_auth(void)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-17 13:47:37 +08:00
|
|
|
static void send_pub_key(void)
|
|
|
|
{
|
2021-06-16 15:12:57 +02:00
|
|
|
PROV_BUF(buf, PDU_LEN_PUB_KEY);
|
2020-09-17 13:47:37 +08:00
|
|
|
const uint8_t *key;
|
|
|
|
|
2023-03-29 13:11:40 +02:00
|
|
|
key = bt_mesh_pub_key_get();
|
2020-09-17 13:47:37 +08:00
|
|
|
if (!key) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("No public key available");
|
2020-09-17 13:47:37 +08:00
|
|
|
prov_fail(PROV_ERR_UNEXP_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_mesh_prov_buf_init(&buf, PROV_PUB_KEY);
|
2023-03-29 13:11:40 +02:00
|
|
|
net_buf_simple_add_mem(&buf, key, PUB_KEY_SIZE);
|
|
|
|
LOG_DBG("Local Public Key: %s", bt_hex(buf.data + 1, PUB_KEY_SIZE));
|
2021-09-29 09:50:12 +02:00
|
|
|
|
2021-06-16 15:12:57 +02:00
|
|
|
/* PublicKeyDevice */
|
|
|
|
memcpy(bt_mesh_prov_link.conf_inputs.pub_key_device, &buf.data[1], PDU_LEN_PUB_KEY);
|
2020-09-17 13:47:37 +08:00
|
|
|
|
|
|
|
if (bt_mesh_prov_send(&buf, public_key_sent)) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Failed to send Public Key");
|
2020-09-17 13:47:37 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-09 11:01:57 +02:00
|
|
|
start_auth();
|
|
|
|
}
|
|
|
|
|
2020-09-17 13:47:37 +08:00
|
|
|
static void prov_dh_key_gen(void)
|
|
|
|
{
|
2023-03-29 13:11:40 +02:00
|
|
|
const uint8_t *remote_pub_key;
|
|
|
|
const uint8_t *remote_priv_key;
|
2020-09-17 13:47:37 +08:00
|
|
|
|
2023-03-29 13:11:40 +02:00
|
|
|
remote_pub_key = bt_mesh_prov_link.conf_inputs.pub_key_provisioner;
|
2020-09-17 13:47:37 +08:00
|
|
|
|
2021-06-09 11:01:57 +02:00
|
|
|
if (IS_ENABLED(CONFIG_BT_MESH_PROV_OOB_PUBLIC_KEY) &&
|
|
|
|
atomic_test_bit(bt_mesh_prov_link.flags, OOB_PUB_KEY)) {
|
2023-03-29 13:11:40 +02:00
|
|
|
remote_priv_key = bt_mesh_prov->private_key_be;
|
|
|
|
} else {
|
|
|
|
remote_priv_key = NULL;
|
|
|
|
}
|
2022-02-04 14:16:16 +01:00
|
|
|
|
2023-03-29 13:11:40 +02:00
|
|
|
if (bt_mesh_dhkey_gen(remote_pub_key, remote_priv_key, bt_mesh_prov_link.dhkey)) {
|
|
|
|
LOG_ERR("Failed to generate DHKey");
|
|
|
|
prov_fail(PROV_ERR_UNEXP_ERR);
|
2021-06-09 11:01:57 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-29 13:11:40 +02:00
|
|
|
LOG_DBG("DHkey: %s", bt_hex(bt_mesh_prov_link.dhkey, DH_KEY_SIZE));
|
2020-09-17 13:47:37 +08:00
|
|
|
|
2023-03-29 13:11:40 +02:00
|
|
|
if (atomic_test_bit(bt_mesh_prov_link.flags, OOB_PUB_KEY)) {
|
|
|
|
start_auth();
|
|
|
|
} else {
|
|
|
|
send_pub_key();
|
2020-09-17 13:47:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void prov_pub_key(const uint8_t *data)
|
|
|
|
{
|
2023-03-29 13:11:40 +02:00
|
|
|
LOG_DBG("Remote Public Key: %s", bt_hex(data, PUB_KEY_SIZE));
|
2020-09-17 13:47:37 +08:00
|
|
|
|
|
|
|
/* PublicKeyProvisioner */
|
2021-06-16 15:12:57 +02:00
|
|
|
memcpy(bt_mesh_prov_link.conf_inputs.pub_key_provisioner, data, PDU_LEN_PUB_KEY);
|
2020-09-17 13:47:37 +08:00
|
|
|
|
2021-06-09 11:01:57 +02:00
|
|
|
if (IS_ENABLED(CONFIG_BT_MESH_PROV_OOB_PUBLIC_KEY) &&
|
|
|
|
atomic_test_bit(bt_mesh_prov_link.flags, OOB_PUB_KEY)) {
|
|
|
|
if (!bt_mesh_prov->public_key_be || !bt_mesh_prov->private_key_be) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Public or private key is not ready");
|
2021-06-09 11:01:57 +02:00
|
|
|
prov_fail(PROV_ERR_UNEXP_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No swap needed since user provides public key in big-endian */
|
2021-06-16 15:12:57 +02:00
|
|
|
memcpy(bt_mesh_prov_link.conf_inputs.pub_key_device, bt_mesh_prov->public_key_be,
|
|
|
|
PDU_LEN_PUB_KEY);
|
2020-09-17 13:47:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2021-06-16 15:12:57 +02:00
|
|
|
PROV_BUF(rnd, PDU_LEN_RANDOM);
|
2020-09-17 13:47:37 +08:00
|
|
|
|
|
|
|
bt_mesh_prov_buf_init(&rnd, PROV_RANDOM);
|
2021-08-09 16:43:16 +02:00
|
|
|
net_buf_simple_add_mem(&rnd, bt_mesh_prov_link.rand, bt_mesh_prov_auth_size_get());
|
2020-09-17 13:47:37 +08:00
|
|
|
|
|
|
|
if (bt_mesh_prov_send(&rnd, NULL)) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Failed to send Provisioning Random");
|
2020-09-17 13:47:37 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_mesh_prov_link.expect = PROV_DATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void prov_random(const uint8_t *data)
|
|
|
|
{
|
2021-08-09 16:43:16 +02:00
|
|
|
uint8_t rand_size = bt_mesh_prov_auth_size_get();
|
|
|
|
uint8_t conf_verify[PROV_AUTH_MAX_LEN];
|
2020-09-17 13:47:37 +08:00
|
|
|
|
2021-08-09 16:43:16 +02:00
|
|
|
LOG_DBG("Remote Random: %s", bt_hex(data, rand_size));
|
|
|
|
if (!memcmp(data, bt_mesh_prov_link.rand, rand_size)) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Random value is identical to ours, rejecting.");
|
2020-09-17 13:47:37 +08:00
|
|
|
prov_fail(PROV_ERR_CFM_FAILED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-09 16:43:16 +02:00
|
|
|
if (bt_mesh_prov_conf(bt_mesh_prov_link.algorithm, bt_mesh_prov_link.conf_key,
|
|
|
|
data, bt_mesh_prov_link.auth, conf_verify)) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Unable to calculate confirmation verification");
|
2020-09-17 13:47:37 +08:00
|
|
|
prov_fail(PROV_ERR_UNEXP_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-09 16:43:16 +02:00
|
|
|
if (memcmp(conf_verify, bt_mesh_prov_link.conf, rand_size)) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Invalid confirmation value");
|
2021-08-09 16:43:16 +02:00
|
|
|
LOG_DBG("Received: %s", bt_hex(bt_mesh_prov_link.conf, rand_size));
|
|
|
|
LOG_DBG("Calculated: %s", bt_hex(conf_verify, rand_size));
|
2020-09-17 13:47:37 +08:00
|
|
|
prov_fail(PROV_ERR_CFM_FAILED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-09 16:43:16 +02:00
|
|
|
if (bt_mesh_prov_salt(bt_mesh_prov_link.algorithm, bt_mesh_prov_link.conf_salt,
|
|
|
|
data, bt_mesh_prov_link.rand, bt_mesh_prov_link.prov_salt)) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Failed to generate provisioning salt");
|
2020-09-17 13:47:37 +08:00
|
|
|
prov_fail(PROV_ERR_UNEXP_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_DBG("ProvisioningSalt: %s", bt_hex(bt_mesh_prov_link.prov_salt, 16));
|
2020-09-17 13:47:37 +08:00
|
|
|
|
|
|
|
send_random();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void prov_confirm(const uint8_t *data)
|
|
|
|
{
|
2021-08-09 16:43:16 +02:00
|
|
|
uint8_t conf_size = bt_mesh_prov_auth_size_get();
|
2020-09-17 13:47:37 +08:00
|
|
|
|
2021-08-09 16:43:16 +02:00
|
|
|
LOG_DBG("Remote Confirm: %s", bt_hex(data, conf_size));
|
2020-09-17 13:47:37 +08:00
|
|
|
|
2021-08-09 16:43:16 +02:00
|
|
|
memcpy(bt_mesh_prov_link.conf, data, conf_size);
|
2020-09-17 13:47:37 +08:00
|
|
|
notify_input_complete();
|
|
|
|
|
2023-03-29 13:11:40 +02:00
|
|
|
send_confirm();
|
2020-09-17 13:47:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool is_pb_gatt(void)
|
|
|
|
{
|
|
|
|
return bt_mesh_prov_link.bearer &&
|
|
|
|
bt_mesh_prov_link.bearer->type == BT_MESH_PROV_GATT;
|
|
|
|
}
|
|
|
|
|
2020-03-03 12:12:53 +01:00
|
|
|
static bool refresh_is_valid(const uint8_t *netkey, uint16_t net_idx,
|
|
|
|
uint32_t iv_index)
|
|
|
|
{
|
|
|
|
enum bt_mesh_rpr_node_refresh proc = bt_mesh_node_refresh_get();
|
|
|
|
struct bt_mesh_subnet *sub = bt_mesh_subnet_get(net_idx);
|
|
|
|
uint16_t old_addr = bt_mesh_primary_addr();
|
|
|
|
bool valid_addr;
|
|
|
|
|
|
|
|
if (iv_index != bt_mesh.iv_index) {
|
|
|
|
LOG_ERR("Invalid IV index");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sub || memcmp(netkey, sub->keys[SUBNET_KEY_TX_IDX(sub)].net, 16)) {
|
|
|
|
LOG_ERR("Invalid netkey");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (proc == BT_MESH_RPR_NODE_REFRESH_ADDR) {
|
|
|
|
valid_addr = bt_mesh_prov_link.addr < old_addr ||
|
|
|
|
bt_mesh_prov_link.addr >= old_addr + bt_mesh_comp_get()->elem_count;
|
|
|
|
} else {
|
|
|
|
valid_addr = bt_mesh_prov_link.addr == bt_mesh_primary_addr();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!valid_addr) {
|
|
|
|
LOG_ERR("Invalid address");
|
|
|
|
}
|
|
|
|
|
|
|
|
return valid_addr;
|
|
|
|
}
|
|
|
|
|
2020-09-17 13:47:37 +08:00
|
|
|
static void prov_data(const uint8_t *data)
|
|
|
|
{
|
2021-06-16 15:12:57 +02:00
|
|
|
PROV_BUF(msg, PDU_LEN_COMPLETE);
|
2020-09-17 13:47:37 +08:00
|
|
|
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 net_idx;
|
|
|
|
int err;
|
|
|
|
bool identity_enable;
|
|
|
|
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_DBG("");
|
2020-09-17 13:47:37 +08:00
|
|
|
|
|
|
|
err = bt_mesh_session_key(bt_mesh_prov_link.dhkey,
|
|
|
|
bt_mesh_prov_link.prov_salt, session_key);
|
|
|
|
if (err) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Unable to generate session key");
|
2020-09-17 13:47:37 +08:00
|
|
|
prov_fail(PROV_ERR_UNEXP_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_DBG("SessionKey: %s", bt_hex(session_key, 16));
|
2020-09-17 13:47:37 +08:00
|
|
|
|
|
|
|
err = bt_mesh_prov_nonce(bt_mesh_prov_link.dhkey,
|
|
|
|
bt_mesh_prov_link.prov_salt, nonce);
|
|
|
|
if (err) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Unable to generate session nonce");
|
2020-09-17 13:47:37 +08:00
|
|
|
prov_fail(PROV_ERR_UNEXP_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_DBG("Nonce: %s", bt_hex(nonce, 13));
|
2020-09-17 13:47:37 +08:00
|
|
|
|
|
|
|
err = bt_mesh_prov_decrypt(session_key, nonce, data, pdu);
|
|
|
|
if (err) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Unable to decrypt provisioning data");
|
2020-09-17 13:47:37 +08:00
|
|
|
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) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Unable to generate device key");
|
2020-09-17 13:47:37 +08:00
|
|
|
prov_fail(PROV_ERR_UNEXP_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_DBG("DevKey: %s", bt_hex(dev_key, 16));
|
2020-09-17 13:47:37 +08:00
|
|
|
|
|
|
|
net_idx = sys_get_be16(&pdu[16]);
|
|
|
|
flags = pdu[18];
|
|
|
|
iv_index = sys_get_be32(&pdu[19]);
|
2020-03-03 12:12:53 +01:00
|
|
|
bt_mesh_prov_link.addr = sys_get_be16(&pdu[23]);
|
2020-09-17 13:47:37 +08:00
|
|
|
|
2020-03-03 12:12:53 +01:00
|
|
|
if (IS_ENABLED(CONFIG_BT_MESH_RPR_SRV) &&
|
|
|
|
atomic_test_bit(bt_mesh_prov_link.flags, REPROVISION) &&
|
|
|
|
!refresh_is_valid(pdu, net_idx, iv_index)) {
|
|
|
|
prov_send_fail_msg(PROV_ERR_INVALID_DATA);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_DBG("net_idx %u iv_index 0x%08x, addr 0x%04x",
|
|
|
|
net_idx, iv_index, bt_mesh_prov_link.addr);
|
2020-09-17 13:47:37 +08:00
|
|
|
|
|
|
|
bt_mesh_prov_buf_init(&msg, PROV_COMPLETE);
|
|
|
|
if (bt_mesh_prov_send(&msg, NULL)) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Failed to send Provisioning Complete");
|
2020-09-17 13:47:37 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ignore any further PDUs on this link */
|
|
|
|
bt_mesh_prov_link.expect = PROV_NO_PDU;
|
2020-03-03 12:12:53 +01:00
|
|
|
atomic_set_bit(bt_mesh_prov_link.flags, COMPLETE);
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_BT_MESH_RPR_SRV) &&
|
|
|
|
atomic_test_bit(bt_mesh_prov_link.flags, REPROVISION)) {
|
|
|
|
bt_mesh_dev_key_cand(dev_key);
|
|
|
|
return;
|
|
|
|
}
|
2020-09-17 13:47:37 +08:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
2020-03-03 12:12:53 +01:00
|
|
|
err = bt_mesh_provision(pdu, net_idx, flags, iv_index,
|
|
|
|
bt_mesh_prov_link.addr, dev_key);
|
2020-09-17 13:47:37 +08:00
|
|
|
if (err) {
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_ERR("Failed to provision (err %d)", err);
|
2020-09-17 13:47:37 +08:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-03 12:12:53 +01:00
|
|
|
static void reprovision_complete(void)
|
|
|
|
{
|
|
|
|
bt_mesh_reprovision(bt_mesh_prov_link.addr);
|
|
|
|
|
|
|
|
/* When performing the refresh composition procedure,
|
|
|
|
* the device key will be activated after the first
|
|
|
|
* successful decryption with the new key.
|
|
|
|
*/
|
|
|
|
if (bt_mesh_node_refresh_get() == BT_MESH_RPR_NODE_REFRESH_ADDR) {
|
|
|
|
bt_mesh_dev_key_cand_activate();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bt_mesh_prov->reprovisioned) {
|
|
|
|
bt_mesh_prov->reprovisioned(bt_mesh_primary_addr());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void reprovision_fail(void)
|
|
|
|
{
|
|
|
|
bt_mesh_dev_key_cand_remove();
|
|
|
|
}
|
|
|
|
|
2020-09-17 13:47:37 +08:00
|
|
|
static void local_input_complete(void)
|
|
|
|
{
|
2021-06-09 11:01:57 +02:00
|
|
|
if (atomic_test_bit(bt_mesh_prov_link.flags, PUB_KEY_SENT) ||
|
|
|
|
atomic_test_bit(bt_mesh_prov_link.flags, OOB_PUB_KEY)) {
|
2020-09-17 13:47:37 +08:00
|
|
|
send_input_complete();
|
|
|
|
} else {
|
|
|
|
atomic_set_bit(bt_mesh_prov_link.flags, INPUT_COMPLETE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-29 11:52:00 +02:00
|
|
|
static void prov_link_closed(enum prov_bearer_link_status status)
|
2020-09-17 13:47:37 +08:00
|
|
|
{
|
2020-03-03 12:12:53 +01:00
|
|
|
if (IS_ENABLED(CONFIG_BT_MESH_RPR_SRV) &&
|
|
|
|
atomic_test_bit(bt_mesh_prov_link.flags, REPROVISION)) {
|
2023-03-29 11:52:00 +02:00
|
|
|
if (atomic_test_bit(bt_mesh_prov_link.flags, COMPLETE) &&
|
|
|
|
status == PROV_BEARER_LINK_STATUS_SUCCESS) {
|
2020-03-03 12:12:53 +01:00
|
|
|
reprovision_complete();
|
|
|
|
} else {
|
|
|
|
reprovision_fail();
|
|
|
|
}
|
|
|
|
} else if (bt_mesh_prov_link.conf_inputs.invite[0]) {
|
|
|
|
/* Disable Attention Timer if it was set */
|
|
|
|
bt_mesh_attention(NULL, 0);
|
|
|
|
}
|
|
|
|
|
2023-03-29 13:11:40 +02:00
|
|
|
bt_mesh_prov_reset_state();
|
2020-09-17 13:47:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void prov_link_opened(void)
|
|
|
|
{
|
|
|
|
bt_mesh_prov_link.expect = PROV_INVITE;
|
2020-03-03 12:12:53 +01:00
|
|
|
if (IS_ENABLED(CONFIG_BT_MESH_RPR_SRV) && bt_mesh_is_provisioned()) {
|
|
|
|
atomic_set_bit(bt_mesh_prov_link.flags, REPROVISION);
|
|
|
|
}
|
2020-09-17 13:47:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2020-03-03 12:12:53 +01:00
|
|
|
if (IS_ENABLED(CONFIG_BT_MESH_RPR_SRV) &&
|
|
|
|
(bearers & BT_MESH_PROV_REMOTE)) {
|
|
|
|
pb_remote_srv.link_accept(bt_mesh_prov_bearer_cb_get(), NULL);
|
|
|
|
|
|
|
|
/* Only PB-Remote supports reprovisioning */
|
|
|
|
if (bt_mesh_is_provisioned()) {
|
|
|
|
goto role_init;
|
|
|
|
}
|
|
|
|
} else if (bt_mesh_is_provisioned()) {
|
2020-09-17 13:47:37 +08:00
|
|
|
return -EALREADY;
|
|
|
|
}
|
|
|
|
|
2023-03-27 08:44:26 +02:00
|
|
|
if (IS_ENABLED(CONFIG_BT_MESH_PROV_DEVICE_LOG_LEVEL_INF)) {
|
2020-09-17 13:47:37 +08:00
|
|
|
struct bt_uuid_128 uuid = { .uuid = { BT_UUID_TYPE_128 } };
|
|
|
|
|
|
|
|
memcpy(uuid.val, bt_mesh_prov->uuid, 16);
|
2022-11-02 14:31:13 +01:00
|
|
|
LOG_INF("Device UUID: %s", bt_uuid_str(&uuid.uuid));
|
2020-09-17 13:47:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_BT_MESH_PB_ADV) &&
|
|
|
|
(bearers & BT_MESH_PROV_ADV)) {
|
2022-09-29 10:13:51 +08:00
|
|
|
bt_mesh_pb_adv.link_accept(bt_mesh_prov_bearer_cb_get(), NULL);
|
2020-09-17 13:47:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT) &&
|
|
|
|
(bearers & BT_MESH_PROV_GATT)) {
|
2022-09-29 10:13:51 +08:00
|
|
|
bt_mesh_pb_gatt.link_accept(bt_mesh_prov_bearer_cb_get(), NULL);
|
2020-09-17 13:47:37 +08:00
|
|
|
}
|
|
|
|
|
2020-03-03 12:12:53 +01:00
|
|
|
role_init:
|
2020-09-17 13:47:37 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-07-11 18:34:27 -07:00
|
|
|
if (bt_mesh_prov_active()) {
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
2020-09-17 13:47:37 +08:00
|
|
|
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)) {
|
2022-02-08 16:44:31 +08:00
|
|
|
(void)bt_mesh_pb_gatt_srv_disable();
|
2020-09-17 13:47:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|