From 3e2b44a5dd43046f02a9f00e1eb7e10f627f3fd6 Mon Sep 17 00:00:00 2001 From: Aleksandr Khromykh Date: Thu, 20 Jun 2024 08:50:49 +0200 Subject: [PATCH] Bluetooth: Mesh: add extension config server by private beacon server Commit add extension of configuration server by private beacon server. Mesh Protocol v1.1 specification 4.4.11.1 The Mesh Private Beacon Server model is a main model that extends the Configuration Server model. Configuration server and private beacon server shall always exist together since they have bound states. Signed-off-by: Aleksandr Khromykh --- subsys/bluetooth/mesh/Kconfig | 1 + subsys/bluetooth/mesh/od_priv_proxy_srv.c | 22 +++++++++++----------- subsys/bluetooth/mesh/priv_beacon_srv.c | 9 +++++++-- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index ea34298eb1e..030a417d58a 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -1175,6 +1175,7 @@ if BT_MESH_PRIV_BEACONS config BT_MESH_PRIV_BEACON_SRV bool "Support for Private Beacon Server Model" + depends on BT_MESH_MODEL_EXTENSIONS help Enable support for the Private Beacon Server model. diff --git a/subsys/bluetooth/mesh/od_priv_proxy_srv.c b/subsys/bluetooth/mesh/od_priv_proxy_srv.c index e54ed88fa0c..c818521c36e 100644 --- a/subsys/bluetooth/mesh/od_priv_proxy_srv.c +++ b/subsys/bluetooth/mesh/od_priv_proxy_srv.c @@ -83,26 +83,26 @@ static int od_priv_proxy_srv_init(const struct bt_mesh_model *mod) { od_priv_proxy_srv = mod; - const struct bt_mesh_model *priv_beacon_srv = bt_mesh_model_find( - bt_mesh_model_elem(mod), BT_MESH_MODEL_ID_PRIV_BEACON_SRV); - const struct bt_mesh_model *sol_pdu_rpl_srv = bt_mesh_model_find( - bt_mesh_model_elem(mod), BT_MESH_MODEL_ID_SOL_PDU_RPL_SRV); + const struct bt_mesh_model *priv_beacon_srv = + bt_mesh_model_find(bt_mesh_model_elem(mod), BT_MESH_MODEL_ID_PRIV_BEACON_SRV); + const struct bt_mesh_model *sol_pdu_rpl_srv = + bt_mesh_model_find(bt_mesh_model_elem(mod), BT_MESH_MODEL_ID_SOL_PDU_RPL_SRV); if (priv_beacon_srv == NULL) { - return -EINVAL; - } - - if (!bt_mesh_model_in_primary(mod)) { - LOG_ERR("On-Demand Private Proxy server not in primary element"); + LOG_ERR("On-Demand Private Proxy server cannot extend Private Beacon server"); return -EINVAL; } mod->keys[0] = BT_MESH_KEY_DEV_LOCAL; mod->rt->flags |= BT_MESH_MOD_DEVKEY_ONLY; - if (IS_ENABLED(CONFIG_BT_MESH_MODEL_EXTENSIONS)) { - bt_mesh_model_extend(mod, priv_beacon_srv); + bt_mesh_model_extend(mod, priv_beacon_srv); + + if (sol_pdu_rpl_srv != NULL) { bt_mesh_model_correspond(mod, sol_pdu_rpl_srv); + } else { + LOG_WRN("On-Demand Private Proxy server cannot be corresponded by Solicitation PDU " + "RPL Configuration server"); } return 0; diff --git a/subsys/bluetooth/mesh/priv_beacon_srv.c b/subsys/bluetooth/mesh/priv_beacon_srv.c index 98be589fc22..93404a942ff 100644 --- a/subsys/bluetooth/mesh/priv_beacon_srv.c +++ b/subsys/bluetooth/mesh/priv_beacon_srv.c @@ -195,14 +195,19 @@ const struct bt_mesh_model_op bt_mesh_priv_beacon_srv_op[] = { static int priv_beacon_srv_init(const struct bt_mesh_model *mod) { - if (!bt_mesh_model_in_primary(mod)) { - LOG_ERR("Priv beacon server not in primary element"); + const struct bt_mesh_model *config_srv = + bt_mesh_model_find(bt_mesh_model_elem(mod), BT_MESH_MODEL_ID_CFG_SRV); + + if (config_srv == NULL) { + LOG_ERR("Private Beacon server cannot extend Configuration server"); return -EINVAL; } priv_beacon_srv = mod; mod->keys[0] = BT_MESH_KEY_DEV_LOCAL; + bt_mesh_model_extend(mod, config_srv); + return 0; }