From 7227e8bf89829f3781a7aae0693ea260253cfe53 Mon Sep 17 00:00:00 2001 From: Ingar Kulbrandstad Date: Fri, 28 Jun 2024 13:37:44 +0200 Subject: [PATCH] Bluetooth: Mesh: Bridge Configuration Client API Adding documentation and function calles for the API's in Bridge Configuration Client model. Signed-off-by: Ingar Kulbrandstad --- include/zephyr/bluetooth/mesh.h | 1 + include/zephyr/bluetooth/mesh/access.h | 2 + include/zephyr/bluetooth/mesh/brg_cfg.h | 86 ++++++ include/zephyr/bluetooth/mesh/brg_cfg_cli.h | 313 ++++++++++++++++++++ subsys/bluetooth/mesh/CMakeLists.txt | 2 + subsys/bluetooth/mesh/Kconfig | 6 + subsys/bluetooth/mesh/brg_cfg_cli.c | 57 ++++ tests/bsim/bluetooth/mesh/prj.conf | 1 + 8 files changed, 468 insertions(+) create mode 100644 include/zephyr/bluetooth/mesh/brg_cfg.h create mode 100644 include/zephyr/bluetooth/mesh/brg_cfg_cli.h create mode 100644 subsys/bluetooth/mesh/brg_cfg_cli.c diff --git a/include/zephyr/bluetooth/mesh.h b/include/zephyr/bluetooth/mesh.h index fc84814fa4421fb..75c87da5f5b5397 100644 --- a/include/zephyr/bluetooth/mesh.h +++ b/include/zephyr/bluetooth/mesh.h @@ -48,6 +48,7 @@ #include #include #include +#include #include #endif /* ZEPHYR_INCLUDE_BLUETOOTH_MESH_H_ */ diff --git a/include/zephyr/bluetooth/mesh/access.h b/include/zephyr/bluetooth/mesh/access.h index f1fca02783e87e6..4ce1511133e087c 100644 --- a/include/zephyr/bluetooth/mesh/access.h +++ b/include/zephyr/bluetooth/mesh/access.h @@ -187,6 +187,8 @@ struct bt_mesh_elem { #define BT_MESH_MODEL_ID_REMOTE_PROV_SRV 0x0004 /** Remote Provisioning Client */ #define BT_MESH_MODEL_ID_REMOTE_PROV_CLI 0x0005 +/** Bridge Configuration Client */ +#define BT_MESH_MODEL_ID_BRG_CFG_CLI 0x0009 /** Private Beacon Server */ #define BT_MESH_MODEL_ID_PRIV_BEACON_SRV 0x000a /** Private Beacon Client */ diff --git a/include/zephyr/bluetooth/mesh/brg_cfg.h b/include/zephyr/bluetooth/mesh/brg_cfg.h new file mode 100644 index 000000000000000..7980a885a0a8cb5 --- /dev/null +++ b/include/zephyr/bluetooth/mesh/brg_cfg.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_BRG_CFG_H__ +#define ZEPHYR_INCLUDE_BLUETOOTH_MESH_BRG_CFG_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup bt_mesh_brg_cfg Bridge Configuration common header + * @ingroup bt_mesh + * @{ + */ + +#define BT_MESH_SUBNET_BRIDGE_DISABLED 0x00 +#define BT_MESH_SUBNET_BRIDGE_ENABLED 0x01 + +/** Bridging Table state entry corresponding to a entry in the Bridging Table. */ +struct bridging_table_entry { + /** Allowed directions for the bridged traffic (or bridged traffic not allowed) */ + uint8_t directions; + /** NetKey Index of the first subnet */ + uint16_t net_idx_1; + /** NetKey Index of the second subnet */ + uint16_t net_idx_2; + /** Address of the node in the first subnet */ + uint16_t addr_1; + /** Address of the node in the second subnet */ + uint16_t addr_2; +}; + +/** Bridging Table Status response */ +struct bt_mesh_bridging_table_status { + /** Status Code of the requesting message */ + uint8_t status; + /** Requested Bridging Table entry */ + struct bridging_table_entry entry; +}; + +struct bt_mesh_filter_netkey { + uint16_t filter: 2, /* Filter applied to the set of pairs of NetKey Indexes */ + prohibited: 2, /* Prohibited */ + net_idx: 12; /* NetKey Index used for filtering or ignored */ +}; + +/** Bridged Subnets List response */ +struct bt_mesh_bridged_subnets_list { + /** Filter applied NetKey Indexes, and NetKey Index used for filtering. */ + struct bt_mesh_filter_netkey net_idx_filter; + /** Start offset in units of bridges */ + uint8_t start_idx; + /** Pointer to allocated buffer for storing filtered of NetKey Indexes */ + struct net_buf_simple *list; +}; + +/** Bridging Table List response */ +struct bt_mesh_bridging_table_list { + /** Status Code of the requesting message */ + uint8_t status; + /** NetKey Index of the first subnet */ + uint16_t net_idx_1; + /** NetKey Index of the second subnet */ + uint16_t net_idx_2; + /** Start offset in units of bridges */ + uint16_t start_idx; + /** Pointer to allocated buffer for storing list of bridged addresses and directions */ + struct net_buf_simple *list; +}; + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_INCLUDE_BLUETOOTH_MESH_BRG_CFG_H__ */ diff --git a/include/zephyr/bluetooth/mesh/brg_cfg_cli.h b/include/zephyr/bluetooth/mesh/brg_cfg_cli.h new file mode 100644 index 000000000000000..c4c60b75d520c6a --- /dev/null +++ b/include/zephyr/bluetooth/mesh/brg_cfg_cli.h @@ -0,0 +1,313 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_BRG_CFG_CLI_H__ +#define ZEPHYR_INCLUDE_BLUETOOTH_MESH_BRG_CFG_CLI_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup bt_mesh_brg_cfg_cli Bridge Configuration Client Model + * @ingroup bt_mesh + * @{ + * @brief API for the Bluetooth Mesh Bridge Configuration Client model + */ + +struct bt_mesh_brg_cfg_cli; + +/** + * @brief Bridge Configuration Client model Composition Data entry. + * + * @param _cli Pointer to a @ref bt_mesh_bfg_cfg_cli instance. + */ +#define BT_MESH_MODEL_BRG_CFG_CLI(_cli) \ + BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_BRG_CFG_CLI, _bt_mesh_brg_cfg_cli_op, NULL, _cli, \ + &_bt_mesh_brg_cfg_cli_cb) + +/** Mesh Bridge Configuration Client Status messages callback */ +struct bt_mesh_brg_cfg_cli_cb { + /** @brief Optional callback for Subnet Bridge Status message. + * + * Handles received Subnet Bridge Status messages from a Bridge + * Configuration Server. + + * @param cli Bridge Configuration Client context. + * @param addr Address of the sender. + * @param status Status received from the server. + */ + void (*subnet_bridge_status)(struct bt_mesh_brg_cfg_cli *cli, uint16_t addr, + uint8_t status); + + /** @brief Optional callback for Bridging Table Size Status message. + * + * Handles received Bridging Table Size Status messages from a Bridge + * Configuration Server. + * + * @param cli Bridge Configuration Client context. + * @param addr Address of the sender. + * @param size Size received from the server. + */ + void (*bridging_table_size_status)(struct bt_mesh_brg_cfg_cli *cli, uint16_t addr, + uint16_t size); + + /** @brief Optional callback for Bridging Table Status message. + * + * Handles received Bridging Table status messages from a Bridge + * Configuration Server. + * + * @param cli Bridge Configuration Client context. + * @param addr Address of the sender. + * @param rsp Response received from the Bridging Configuration Server. + */ + void (*bridging_table_status)(struct bt_mesh_brg_cfg_cli *cli, uint16_t addr, + struct bt_mesh_bridging_table_status *rsp); + + /** @brief Optional callback for Bridged Subnets List message. + * + * Handles received Bridged Subnets List messages from a Bridge + * Configuration Server. + * + * @param cli Bridge Configuration Client context. + * @param addr Address of the sender. + * @param rsp Response received from the Bridging Configuration Server. + */ + void (*bridged_subnets_list)(struct bt_mesh_brg_cfg_cli *cli, uint16_t addr, + struct bt_mesh_bridged_subnets_list *rsp); + + /** @brief Optional callback for Bridging Table List message. + * + * Handles received Bridging Table List messages from a Bridge + * Configuration Server. + * + * @param cli Bridge Configuration Client context. + * @param addr Address of the sender. + * @param rsp Response received from the Bridging Configuration Server. + */ + void (*bridging_table_list)(struct bt_mesh_brg_cfg_cli *cli, uint16_t addr, + struct bt_mesh_bridging_table_list *rsp); +}; + +/** Bridge Configuration Client Model Context */ +struct bt_mesh_brg_cfg_cli { + /** Bridge Configuration model entry pointer */ + const struct bt_mesh_model *model; + + /** Event handler callbacks */ + const struct bt_mesh_bdg_cfg_cli_cb *cb; + + /* Internal parameters for tracking message responses. */ + struct bt_mesh_msg_ack_ctx ack_ctx; +}; + +/** @brief Sends a Subnet Bridge Get message to the given destination address + * + * This function sends a Subnet Bridge Get message to the given destination + * address to query the value of the Subnet Bridge state of a subnet. The + * Subnet Bridge state indicates whether the subnet is bridged or not. The + * function expects a Subnet Bridge Status message as a response from the + * destination node. + * + * This method can be used asynchronously by setting @p status as NULL. This + * way the method will not wait for response and will return immediately after + * sending the command. + * + * @param net_idx Network index to encrypt the message with. + * @param addr Target node address. + * @param status Status response parameter, returns one of + * @ref BT_MESH_SUBNET_BRIDGE_DISABLED or + * @ref BT_MESH_SUBNET_BRIDGE_ENABLED on success. + * + * @return 0 on success, or (negative) error code on failure. + */ +int bt_mesh_brg_cfg_cli_subnet_bridge_get(uint16_t net_idx, uint16_t addr, uint8_t *status); + +/** @brief Sends a Subnet Bridge Set message to the given destination address + * with the given parameters + * + * This function sends a Subnet Bridge Set message to the given destination + * address with the given parameters to set the value of the Subnet Bridge + * state of a subnet. The Subnet Bridge state indicates whether the subnet is + * bridged or not. The function expects a Subnet Bridge Status message as a + * response from the destination node. + * + * This method can be used asynchronously by setting @p status as NULL. This + * way the method will not wait for response and will return immediately after + * sending the command. + * + * @param net_idx Network index to encrypt the message with. + * @param addr Target node address. + * @param val Value to set the Subnet Bridge state to. Must be one of + * @ref BT_MESH_SUBNET_BRIDGE_DISABLED or + * @ref BT_MESH_SUBNET_BRIDGE_ENABLED. + * @param status Status response parameter, returns one of + * @ref BT_MESH_SUBNET_BRIDGE_DISABLED or + * @ref BT_MESH_SUBNET_BRIDGE_ENABLED on success. + * + * @return 0 on success, or (negative) error code on failure. + */ +int bt_mesh_brg_cfg_cli_subnet_bridge_set(uint16_t net_idx, uint16_t addr, uint8_t val, + uint8_t *status); + +/** @brief Sends a Bridging Table Size Get message to the given destination + * address with the given parameters + * + * This function sends a Bridging Table Size Get message to the given + * destination address with the given parameters to get the size of the Bridging + * Table of the node. The Bridging Table size indicates the maximum number of + * entries that can be stored in the Bridging Table. The function expects a + * Bridging Table Size Status message as a response from the destination node. + * + * This method can be used asynchronously by setting @p size as NULL. This way + * the method will not wait for response and will return immediately after + * sending the command. + * + * @param net_idx Network index to encrypt the message with. + * @param addr Target node address. + * @param size Bridging Table size response parameter. + * + * @return 0 on success, or (negative) error code on failure. + */ +int bt_mesh_brg_cfg_cli_bridging_table_size_get(uint16_t net_idx, uint16_t addr, uint16_t *size); + +/** @brief Sends a Bridging Table Add message to the given destination address + * with the given parameters + * + * This function sends a Bridging Table Add message to the given destination + * address with the given parameters to add an entry to the Bridging Table. The + * Bridging Table contains the net keys and addresses that are authorized to be + * bridged by the node. The function expects a Bridging Table Status message as + * a response from the destination node. + * + * This method can be used asynchronously by setting @p rsp as NULL. This way + * the method will not wait for response and will return immediately after + * sending the command. + * + * @param net_idx Network index to encrypt the message with. + * @param addr Target node address. + * @param direction Allowed directions for the bridged traffic + * @param net_idx_1 NetKey Index of the first subnet + * @param net_idx_2 NetKey Index of the second subnet + * @param addr_1 Address of the node in the first subnet + * @param addr_2 Address of the node in the second subnet + * @param rsp Status response parameter + * + * @return 0 on success, or (negative) error code on failure. + */ +int bt_mesh_brg_cfg_cli_bridging_table_add(uint16_t net_idx, uint16_t addr, uint8_t directions, + uint16_t net_idx_1, uint16_t net_idx_2, uint16_t addr_1, + uint16_t addr_2, + struct bt_mesh_bridging_table_status *rsp); + +/** @brief Sends a Bridging Table Remove message to the given destination + * address with the given parameters + * + * This function sends a Bridging Table Remove message to the given destination + * address with the given parameters to remove an entry from the Bridging + * Table. The Bridging Table contains the net keys and addresses that are + * authorized to be bridged by the node. The function expects a Bridging Table + * Status message as a response from the destination node. + * + * This method can be used asynchronously by setting @p rsp as NULL. This way + * the method will not wait for response and will return immediately after + * sending the command. + * + * @param net_idx Network index to encrypt the message with. + * @param addr Target node address. + * @param net_idx_1 NetKey Index of the first subnet + * @param net_idx_2 NetKey Index of the second subnet + * @param addr_1 Address of the node in the first subnet + * @param addr_2 Address of the node in the second subnet + * @param rsp Pointer to a struct storing the received response from the + * server, or NULL to not wait for a response. + * + * @return 0 on success, or (negative) error code on failure. + */ +int bt_mesh_brg_cfg_cli_bridging_table_remove(uint16_t net_idx, uint16_t addr, uint16_t net_idx_1, + uint16_t net_idx_2, uint16_t addr_1, uint16_t addr_2, + struct bt_mesh_bridging_table_status *rsp); + +/** @brief Sends a Bridged Subnets Get message to the given destination address + * with the given parameters + * + * This function sends a Bridged Subnets Get message to the given destination + * address with the given parameters to get the list of subnets that are + * bridged by the node. The function expects a Bridged Subnets List message as + * a response from the destination node. + * + * This method can be used asynchronously by setting @p rsp as NULL. This way + * the method will not wait for response and will return immediately after + * sending the command. + * + * When @c rsp is set, the user is responsible for providing a buffer for the + * filtered set of N pairs of NetKey Indexes in + * @ref bt_mesh_bridged_subnets_list::list. If a buffer is not provided, the + * bridged subnets won't be copied. + + * @param net_idx Network index to encrypt the message with. + * @param addr Target node address. + * @param filter_net_idx Filter and NetKey Index used for filtering + * @param start_idx Start offset to read in units of Bridging Table state entries + * @param rsp Pointer to a struct storing the received response + * from the server, or NULL to not wait for a response. + * + * @return 0 on success, or (negative) error code on failure. + */ +int bt_mesh_brg_cfg_cli_bridged_subnets_get(uint16_t net_idx, uint16_t addr, + struct bt_mesh_filter_netkey filter_net_idx, + uint8_t start_idx, + struct bt_mesh_bridged_subnets_list *rsp); + +/** @brief Sends a Bridging Table Get message to the given destination address + * with the given parameters + * + * This function sends a Bridging Table Get message to the given destination + * address with the given parameters to get the contents of the Bridging Table. + * The Bridging Table contains the addresses that are authorized to be bridged + * by the node. The function expects a Bridging Table List message as a + * response from the destination node. + * + * This method can be used asynchronously by setting @p rsp as NULL. This way + * the method will not wait for response and will return immediately after + * sending the command. + * + * When @c rsp is set, the user is responsible for providing a buffer for the + * filtered set of N pairs of NetKey Indexes in + * @ref bt_mesh_bridging_table_list::list. If a buffer is not provided, the + * bridged addresses won't be copied. + + * @param net_idx Network index to encrypt the message with. + * @param addr Target node address. + * @param net_idx_1 NetKey Index of the first subnet. + * @param net_idx_2 NetKey Index of the second subnet. + * @param start_idx Start offset to read in units of Bridging Table state entries. + * @param rsp Pointer to a struct storing the received response from the + * server, or NULL to not wait for a response. + * + * @return 0 on success, or (negative) error code on failure. + */ +int bt_mesh_brg_cfg_cli_bridging_table_get(uint16_t net_idx, uint16_t addr, uint16_t net_idx_1, + uint16_t net_idx_2, uint16_t start_idx, + struct bt_mesh_bridging_table_list *rsp); + +/** @cond INTERNAL_HIDDEN */ +extern const struct bt_mesh_model_op _bt_mesh_brg_cfg_cli_op[]; +extern const struct bt_mesh_model_cb _bt_mesh_brg_cfg_cli_cb; +/** @endcond */ + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_INCLUDE_BLUETOOTH_MESH_BRG_CFG_CLI_H__ */ diff --git a/subsys/bluetooth/mesh/CMakeLists.txt b/subsys/bluetooth/mesh/CMakeLists.txt index 2009601f0f80703..282323581375f61 100644 --- a/subsys/bluetooth/mesh/CMakeLists.txt +++ b/subsys/bluetooth/mesh/CMakeLists.txt @@ -113,6 +113,8 @@ zephyr_library_sources_ifdef(CONFIG_BT_MESH_SOL_PDU_RPL_CLI sol_pdu_rpl_cli.c) zephyr_library_sources_ifdef(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV sol_pdu_rpl_srv.c) +zephyr_library_sources_ifdef(CONFIG_BT_MESH_BRG_CFG_CLI brg_cfg_cli.c) + zephyr_library_sources_ifdef(CONFIG_BT_MESH_SOLICITATION solicitation.c) zephyr_library_sources_ifdef(CONFIG_BT_MESH_STATISTIC statistic.c) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index bcf781e72d24410..75b06e8775758dc 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -1227,6 +1227,12 @@ config BT_MESH_SOL_PDU_RPL_CLI_TIMEOUT for a response message to arrive. This value can be changed at runtime using @ref bt_mesh_sol_pdu_rpl_cli_timeout_set. +config BT_MESH_BRG_CFG_CLI + bool "Support for Bridge Configuration Client model" + help + The Bridge Configuration Client is used to support the functionality of a + node that can configure the subnet bridge functionality of another node. + endmenu # Models menu "Proxy" diff --git a/subsys/bluetooth/mesh/brg_cfg_cli.c b/subsys/bluetooth/mesh/brg_cfg_cli.c new file mode 100644 index 000000000000000..fe5db1fd73502ef --- /dev/null +++ b/subsys/bluetooth/mesh/brg_cfg_cli.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#define LOG_LEVEL CONFIG_BT_MESH_MODEL_LOG_LEVEL +#include +LOG_MODULE_REGISTER(bt_mesh_brg_cfg_cli); + +int bt_mesh_brg_cfg_cli_subnet_bridge_get(uint16_t net_idx, uint16_t addr, uint8_t *status) +{ + return 0; +} + +int bt_mesh_brg_cfg_cli_subnet_bridge_set(uint16_t net_idx, uint16_t addr, uint8_t val, + uint8_t *status) +{ + return 0; +} + +int bt_mesh_brg_cfg_cli_bridging_table_size_get(uint16_t net_idx, uint16_t addr, uint16_t *size) +{ + return 0; +} + +int bt_mesh_brg_cfg_cli_bridging_table_add(uint16_t net_idx, uint16_t addr, uint8_t directions, + uint16_t net_idx_1, uint16_t net_idx_2, uint16_t addr_1, + uint16_t addr_2, + struct bt_mesh_bridging_table_status *rsp) +{ + return 0; +} + +int bt_mesh_brg_cfg_cli_bridging_table_remove(uint16_t net_idx, uint16_t addr, uint16_t net_idx_1, + uint16_t net_idx_2, uint16_t addr_1, uint16_t addr_2, + struct bt_mesh_bridging_table_status *rsp) +{ + return 0; +} + +int bt_mesh_brg_cfg_cli_bridged_subnets_get(uint16_t net_idx, uint16_t addr, + struct bt_mesh_filter_netkey filter_net_idx, + uint8_t start_idx, + struct bt_mesh_bridged_subnets_list *rsp) +{ + return 0; +} + +int bt_mesh_brg_cfg_cli_bridging_table_get(uint16_t net_idx, uint16_t addr, uint16_t net_idx_1, + uint16_t net_idx_2, uint16_t start_idx, + struct bt_mesh_bridging_table_list *rsp) +{ + return 0; +} diff --git a/tests/bsim/bluetooth/mesh/prj.conf b/tests/bsim/bluetooth/mesh/prj.conf index 1c343bb512f1307..6fcefc33b42891d 100644 --- a/tests/bsim/bluetooth/mesh/prj.conf +++ b/tests/bsim/bluetooth/mesh/prj.conf @@ -64,6 +64,7 @@ CONFIG_BT_MESH_PRIV_BEACON_SRV=y CONFIG_BT_MESH_PRIV_BEACON_CLI=y CONFIG_BT_MESH_OD_PRIV_PROXY_SRV=y CONFIG_BT_MESH_OD_PRIV_PROXY_CLI=y +CONFIG_BT_MESH_BRG_CFG_CLI=y CONFIG_BT_MESH_COMP_PAGE_1=y CONFIG_BT_MESH_COMP_PAGE_2=y CONFIG_BT_TESTING=y