Skip to content

Commit

Permalink
Bluetooth: Mesh: Rename prov_dev->provisionee
Browse files Browse the repository at this point in the history
Renames "prov device" references and options to
"provisionee" to align implementation with Mesh
Protocol specification v1.1, section 5.4.

Signed-off-by: Anders Storrø <[email protected]>
  • Loading branch information
Andrewpini authored and carlescufi committed Dec 13, 2023
1 parent 00f7c0e commit 25d44a8
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 61 deletions.
4 changes: 2 additions & 2 deletions doc/connectivity/bluetooth/api/mesh/shell.rst
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ Provisioning
============

To allow a device to broadcast connectable unprovisioned beacons, the
:kconfig:option:`CONFIG_BT_MESH_PROV_DEVICE` configuration option must be enabled, along with the
:kconfig:option:`CONFIG_BT_MESH_PROVISIONEE` configuration option must be enabled, along with the
:kconfig:option:`CONFIG_BT_MESH_PB_GATT` option.

``mesh prov pb-gatt <Val(off, on)>``
Expand All @@ -295,7 +295,7 @@ To allow a device to broadcast connectable unprovisioned beacons, the
* ``Val``: Enable or disable provisioning with GATT

To allow a device to broadcast unprovisioned beacons, the
:kconfig:option:`CONFIG_BT_MESH_PROV_DEVICE` configuration option must be enabled, along with the
:kconfig:option:`CONFIG_BT_MESH_PROVISIONEE` configuration option must be enabled, along with the
:kconfig:option:`CONFIG_BT_MESH_PB_ADV` option.

``mesh prov pb-adv <Val(off, on)>``
Expand Down
20 changes: 13 additions & 7 deletions doc/releases/migration-guide-3.6.rst
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,25 @@ Bluetooth
cleared on :c:func:`bt_enable`. Callbacks can now be registered before the initial
call to :c:func:`bt_enable`, and should no longer be re-registered after a :c:func:`bt_disable`
:c:func:`bt_enable` cycle. (:github:`63693`)
* The Bluetooth Mesh ``model`` declaration has been changed to add prefix ``const``.
The ``model->user_data``, ``model->elem_idx`` and ``model->mod_idx`` field has been changed to
the new runtime structure, replaced by ``model->rt->user_data``, ``model->rt->elem_idx`` and
``model->rt->mod_idx`` separately. (:github:`65152`)
* The Bluetooth Mesh ``element`` declaration has been changed to add prefix ``const``.
The ``elem->addr`` field has been changed to the new runtime structure, replaced by
``elem->rt->addr``. (:github:`65388`)
* The Bluetooth UUID has been modified to rodata in ``BT_UUID_DECLARE_16``, ``BT_UUID_DECLARE_32`
and ``BT_UUID_DECLARE_128`` as the return value has been changed to `const`.
Any pointer to a UUID must be prefixed with `const`, otherwise there will be a compilation warning.
For example change ``struct bt_uuid *uuid = BT_UUID_DECLARE_16(xx)`` to
``const struct bt_uuid *uuid = BT_UUID_DECLARE_16(xx)``. (:github:`66136`)

* Mesh

* The Bluetooth Mesh ``model`` declaration has been changed to add prefix ``const``.
The ``model->user_data``, ``model->elem_idx`` and ``model->mod_idx`` field has been changed to
the new runtime structure, replaced by ``model->rt->user_data``, ``model->rt->elem_idx`` and
``model->rt->mod_idx`` separately. (:github:`65152`)
* The Bluetooth Mesh ``element`` declaration has been changed to add prefix ``const``.
The ``elem->addr`` field has been changed to the new runtime structure, replaced by
``elem->rt->addr``. (:github:`65388`)
* Deprecated :kconfig:option:`CONFIG_BT_MESH_PROV_DEVICE`. This option is
replaced by new option :kconfig:option:`CONFIG_BT_MESH_PROVISIONEE` to
be aligned with Mesh Protocol Specification v1.1, section 5.4. (:github:`64252`)

LoRaWAN
=======

Expand Down
2 changes: 1 addition & 1 deletion samples/bluetooth/mesh_provisioner/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ CONFIG_BT_MESH_RELAY=y
CONFIG_BT_MESH_RELAY_RETRANSMIT_COUNT=3

CONFIG_BT_MESH_PROVISIONER=y
CONFIG_BT_MESH_PROV_DEVICE=n
CONFIG_BT_MESH_PROVISIONEE=n
CONFIG_BT_MESH_CDB=y
CONFIG_BT_MESH_CDB_NODE_COUNT=16
CONFIG_BT_MESH_CDB_SUBNET_COUNT=3
Expand Down
2 changes: 1 addition & 1 deletion subsys/bluetooth/Kconfig.logging
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ legacy-debug-sym = BT_MESH_DEBUG_PROVISIONER
module-str = "Provisioner"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"

module = BT_MESH_PROV_DEVICE
module = BT_MESH_PROVISIONEE
legacy-debug-sym = BT_MESH_DEBUG_PROV_DEVICE
module-str = "Provisioning device"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"
Expand Down
2 changes: 1 addition & 1 deletion subsys/bluetooth/mesh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ zephyr_library_sources_ifdef(CONFIG_BT_MESH_FRIEND friend.c)

zephyr_library_sources_ifdef(CONFIG_BT_MESH_PROV prov.c)

zephyr_library_sources_ifdef(CONFIG_BT_MESH_PROV_DEVICE prov_device.c)
zephyr_library_sources_ifdef(CONFIG_BT_MESH_PROVISIONEE provisionee.c)

zephyr_library_sources_ifdef(CONFIG_BT_MESH_PROVISIONER provisioner.c)

Expand Down
15 changes: 12 additions & 3 deletions subsys/bluetooth/mesh/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ config BT_MESH_PB_GATT
select BT_MESH_GATT_SERVER
select BT_MESH_PROV
select BT_MESH_PB_GATT_COMMON
select BT_MESH_PROV_DEVICE
select BT_MESH_PROVISIONEE
help
Enable this option to allow the device to be provisioned over
GATT.
Expand Down Expand Up @@ -268,15 +268,24 @@ config BT_MESH_PB_GATT_CLIENT
endif # BT_CONN

config BT_MESH_PROV_DEVICE
bool "Provisioning device role support"
bool "[DEPRECATED] Provisioning device role support"
select DEPRECATED
select BT_MESH_PROVISIONEE
help
Enable this option to allow the device to be provisioned into a mesh network.
The option is marked as deprecated and will be replaced by BT_MESH_PROVISIONEE
option.

config BT_MESH_PROVISIONEE
bool "Provisionee role support"
depends on BT_MESH_PB_ADV || BT_MESH_PB_GATT
default y
help
Enable this option to allow the device to be provisioned into a mesh network.

config BT_MESH_PROV_OOB_PUBLIC_KEY
bool "OOB Public key support"
depends on BT_MESH_PROV_DEVICE
depends on BT_MESH_PROVISIONEE
help
Enable this option if public key is to be exchanged via Out of Band (OOB) technology.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
#include "settings.h"
#include "rpr.h"

#define LOG_LEVEL CONFIG_BT_MESH_PROV_DEVICE_LOG_LEVEL
#define LOG_LEVEL CONFIG_BT_MESH_PROVISIONEE_LOG_LEVEL
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(bt_mesh_prov_device);
LOG_MODULE_REGISTER(bt_mesh_provisionee);

static void reprovision_fail(void);

Expand Down Expand Up @@ -696,8 +696,8 @@ int bt_mesh_prov_enable(bt_mesh_prov_bearer_t bearers)
return -EALREADY;
}

#if defined(CONFIG_BT_MESH_PROV_DEVICE_LOG_LEVEL)
if (CONFIG_BT_MESH_PROV_DEVICE_LOG_LEVEL > 2) {
#if defined(CONFIG_BT_MESH_PROVISIONEE_LOG_LEVEL)
if (CONFIG_BT_MESH_PROVISIONEE_LOG_LEVEL > 2) {
struct bt_uuid_128 uuid = { .uuid = { BT_UUID_TYPE_128 } };

sys_memcpy_swap(uuid.val, bt_mesh_prov->uuid, 16);
Expand Down
72 changes: 36 additions & 36 deletions subsys/bluetooth/mesh/provisioner.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ static struct {
uint8_t attention_duration;
uint8_t uuid[16];
uint8_t new_dev_key[16];
} prov_device;
} provisionee;

static void send_pub_key(void);
static void prov_dh_key_gen(void);

static int reset_state(void)
{
if (!atomic_test_bit(bt_mesh_prov_link.flags, REPROVISION) &&
prov_device.node != NULL) {
bt_mesh_cdb_node_del(prov_device.node, false);
provisionee.node != NULL) {
bt_mesh_cdb_node_del(provisionee.node, false);
}

return bt_mesh_prov_reset_state();
Expand Down Expand Up @@ -86,9 +86,9 @@ static void send_invite(void)
LOG_DBG("");

bt_mesh_prov_buf_init(&inv, PROV_INVITE);
net_buf_simple_add_u8(&inv, prov_device.attention_duration);
net_buf_simple_add_u8(&inv, provisionee.attention_duration);

memcpy(bt_mesh_prov_link.conf_inputs.invite, &prov_device.attention_duration,
memcpy(bt_mesh_prov_link.conf_inputs.invite, &provisionee.attention_duration,
PDU_LEN_INVITE);

if (bt_mesh_prov_send(&inv, NULL)) {
Expand Down Expand Up @@ -246,8 +246,8 @@ static void prov_capabilities(const uint8_t *data)
LOG_DBG("Input OOB Size: %u", caps.input_size);
LOG_DBG("Input OOB Action: 0x%04x", caps.input_actions);

prov_device.elem_count = caps.elem_count;
if (prov_device.elem_count == 0) {
provisionee.elem_count = caps.elem_count;
if (provisionee.elem_count == 0) {
LOG_ERR("Invalid number of elements");
prov_fail(PROV_ERR_NVAL_FMT);
return;
Expand All @@ -271,27 +271,27 @@ static void prov_capabilities(const uint8_t *data)
if (atomic_test_bit(bt_mesh_prov_link.flags, REPROVISION)) {
if (!bt_mesh_prov_link.addr) {
bt_mesh_prov_link.addr = bt_mesh_cdb_free_addr_get(
prov_device.elem_count);
provisionee.elem_count);
if (!bt_mesh_prov_link.addr) {
LOG_ERR("Failed allocating address for node");
prov_fail(PROV_ERR_ADDR);
return;
}
}
} else {
prov_device.node =
bt_mesh_cdb_node_alloc(prov_device.uuid,
provisionee.node =
bt_mesh_cdb_node_alloc(provisionee.uuid,
bt_mesh_prov_link.addr,
prov_device.elem_count,
prov_device.net_idx);
if (prov_device.node == NULL) {
provisionee.elem_count,
provisionee.net_idx);
if (provisionee.node == NULL) {
LOG_ERR("Failed allocating node 0x%04x", bt_mesh_prov_link.addr);
prov_fail(PROV_ERR_RESOURCES);
return;
}

/* Address might change in the alloc call */
bt_mesh_prov_link.addr = prov_device.node->addr;
bt_mesh_prov_link.addr = provisionee.node->addr;
}

memcpy(bt_mesh_prov_link.conf_inputs.capabilities, data, PDU_LEN_CAPABILITIES);
Expand Down Expand Up @@ -517,16 +517,16 @@ static void send_prov_data(void)
LOG_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.new_dev_key);
bt_mesh_prov_link.prov_salt, provisionee.new_dev_key);
if (err) {
LOG_ERR("Unable to generate device key");
prov_fail(PROV_ERR_UNEXP_ERR);
goto session_key_destructor;
}

sub = bt_mesh_cdb_subnet_get(prov_device.node->net_idx);
sub = bt_mesh_cdb_subnet_get(provisionee.node->net_idx);
if (sub == NULL) {
LOG_ERR("No subnet with net_idx %u", prov_device.node->net_idx);
LOG_ERR("No subnet with net_idx %u", provisionee.node->net_idx);
prov_fail(PROV_ERR_UNEXP_ERR);
goto session_key_destructor;
}
Expand All @@ -540,14 +540,14 @@ static void send_prov_data(void)

bt_mesh_prov_buf_init(&pdu, PROV_DATA);
net_buf_simple_add_mem(&pdu, net_key, sizeof(net_key));
net_buf_simple_add_be16(&pdu, prov_device.node->net_idx);
net_buf_simple_add_be16(&pdu, provisionee.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, bt_mesh_prov_link.addr);
net_buf_simple_add(&pdu, 8); /* For MIC */

LOG_DBG("net_idx %u, iv_index 0x%08x, addr 0x%04x",
prov_device.node->net_idx, bt_mesh.iv_index,
provisionee.node->net_idx, bt_mesh.iv_index,
bt_mesh_prov_link.addr);

err = bt_mesh_prov_encrypt(&session_key, nonce, &pdu.data[1],
Expand All @@ -571,10 +571,10 @@ static void send_prov_data(void)

static void prov_complete(const uint8_t *data)
{
struct bt_mesh_cdb_node *node = prov_device.node;
struct bt_mesh_cdb_node *node = provisionee.node;

LOG_DBG("key %s, net_idx %u, num_elem %u, addr 0x%04x",
bt_hex(&prov_device.new_dev_key, 16), node->net_idx,
bt_hex(&provisionee.new_dev_key, 16), node->net_idx,
node->num_elem, node->addr);

bt_mesh_prov_link.expect = PROV_NO_PDU;
Expand All @@ -586,15 +586,15 @@ static void prov_complete(const uint8_t *data)
static void prov_node_add(void)
{
LOG_DBG("");
struct bt_mesh_cdb_node *node = prov_device.node;
struct bt_mesh_cdb_node *node = provisionee.node;
int err;

if (atomic_test_bit(bt_mesh_prov_link.flags, REPROVISION)) {
bt_mesh_cdb_node_update(node, bt_mesh_prov_link.addr,
prov_device.elem_count);
provisionee.elem_count);
}

err = bt_mesh_cdb_node_key_import(node, prov_device.new_dev_key);
err = bt_mesh_cdb_node_key_import(node, provisionee.new_dev_key);
if (err) {
LOG_ERR("Failed to import node device key");
return;
Expand All @@ -604,7 +604,7 @@ static void prov_node_add(void)
bt_mesh_cdb_node_store(node);
}

prov_device.node = NULL;
provisionee.node = NULL;

if (bt_mesh_prov->node_added) {
bt_mesh_prov->node_added(node->net_idx, node->uuid, node->addr,
Expand Down Expand Up @@ -807,7 +807,7 @@ static int link_open(const uint8_t *uuid, const struct prov_bearer *bearer,
}

if (uuid) {
memcpy(prov_device.uuid, uuid, 16);
memcpy(provisionee.uuid, uuid, 16);

struct bt_uuid_128 uuid_repr = { .uuid = { BT_UUID_TYPE_128 } };

Expand All @@ -823,8 +823,8 @@ static int link_open(const uint8_t *uuid, const struct prov_bearer *bearer,
bt_mesh_prov_link.addr = addr;
bt_mesh_prov_link.bearer = bearer;
bt_mesh_prov_link.role = &role_provisioner;
prov_device.net_idx = net_idx;
prov_device.attention_duration = attention_duration;
provisionee.net_idx = net_idx;
provisionee.attention_duration = attention_duration;

err = bt_mesh_prov_link.bearer->link_open(
uuid, timeout, bt_mesh_prov_bearer_cb_get(), bearer_cb_data);
Expand Down Expand Up @@ -877,15 +877,15 @@ static int reprovision_local_client_server(uint16_t addr)
}

LOG_DBG("net_idx %u iv_index 0x%08x, addr 0x%04x",
prov_device.node->net_idx, bt_mesh_cdb.iv_index, addr);
provisionee.node->net_idx, bt_mesh_cdb.iv_index, addr);

atomic_set_bit(bt_mesh_prov_link.flags, REPROVISION);
atomic_set_bit(bt_mesh_prov_link.flags, PROVISIONER);
bt_mesh_prov_link.addr = addr;
bt_mesh_prov_link.bearer = &pb_remote_cli;
bt_mesh_prov_link.role = &role_provisioner;
prov_device.net_idx = prov_device.node->net_idx;
prov_device.attention_duration = 0;
provisionee.net_idx = provisionee.node->net_idx;
provisionee.attention_duration = 0;

if (IS_ENABLED(CONFIG_BT_MESH_PROV_OOB_PUBLIC_KEY) &&
bt_mesh_prov->public_key_be && bt_mesh_prov->private_key_be) {
Expand All @@ -908,13 +908,13 @@ static int reprovision_local_client_server(uint16_t addr)
LOG_DBG("DHkey: %s", bt_hex(bt_mesh_prov_link.dhkey, DH_KEY_SIZE));

err = bt_mesh_dev_key(bt_mesh_prov_link.dhkey,
bt_mesh_prov_link.prov_salt, prov_device.new_dev_key);
bt_mesh_prov_link.prov_salt, provisionee.new_dev_key);
if (err) {
LOG_ERR("Unable to generate device key");
return err;
}

bt_mesh_dev_key_cand(prov_device.new_dev_key);
bt_mesh_dev_key_cand(provisionee.new_dev_key);
/* Mark the link that was never opened as closed. */
atomic_set_bit(bt_mesh_prov_link.flags, COMPLETE);
bt_mesh_reprovision(addr);
Expand Down Expand Up @@ -943,8 +943,8 @@ int bt_mesh_pb_remote_open_node(struct bt_mesh_rpr_cli *cli,
ctx.refresh = BT_MESH_RPR_NODE_REFRESH_DEVKEY;
}

prov_device.node = bt_mesh_cdb_node_get(srv->addr);
if (!prov_device.node) {
provisionee.node = bt_mesh_cdb_node_get(srv->addr);
if (!provisionee.node) {
LOG_ERR("No CDB node for 0x%04x", srv->addr);
return -ENOENT;
}
Expand All @@ -954,7 +954,7 @@ int bt_mesh_pb_remote_open_node(struct bt_mesh_rpr_cli *cli,
return reprovision_local_client_server(addr);
}

return link_open(NULL, &pb_remote_cli, prov_device.node->net_idx, addr,
return link_open(NULL, &pb_remote_cli, provisionee.node->net_idx, addr,
0, &ctx, 0);
}
#endif
Loading

0 comments on commit 25d44a8

Please sign in to comment.