Skip to content

Commit

Permalink
Bluetooth: Mesh: Populate Bridge Config Server
Browse files Browse the repository at this point in the history
Adds implementation for the Bridge Configuration Server model.

Updates `brg_cfg` module to add sanity check for
bt_mesh_brg_cfg_tbl_remove() API. Also, updates the unit test
accordingly.

Adds documentation for the Bridge Configuration Server model

Signed-off-by: Omkar Kulkarni <omkar.kulkarni@nordicsemi.no>
  • Loading branch information
omkar3141 authored and nashif committed Sep 17, 2024
1 parent 50a4c2d commit 8210d2d
Show file tree
Hide file tree
Showing 5 changed files with 365 additions and 11 deletions.
29 changes: 29 additions & 0 deletions doc/connectivity/bluetooth/api/mesh/brg_cfg_srv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,35 @@
Bridge Configuration Server
###########################

The Bridge Configuration Server model is a foundation model defined by the Bluetooth Mesh
specification. It is an optional model, enabled with the
:kconfig:option:`CONFIG_BT_MESH_BRG_CFG_SRV` configuration option. This model extends
the :ref:`bluetooth_mesh_models_cfg_srv` model.

The Bridge Configuration Server model was introduced in the Bluetooth Mesh Protocol Specification
version 1.1, and is used for supporting and configuring the Subnet Bridge feature.

The Bridge Configuration Server model relies on a :ref:`bluetooth_mesh_models_brg_cfg_cli` to
configure it. The Bridge Configuration Server model only accepts messages encrypted with the node’s
device key.

If present, the Bridge Configuration Server model must be instantiated on the primary element.

The Bridge Configuration Server model provides access to the following three states:

* **Subnet Bridge state**: This state enables or disables the Subnet Bridge feature on a node. When
the Subnet Bridge feature is enabled on a node, the node can transfer received messages from one
subnet to another as specified by the Bridging Table state.

* **Bridging Table state**: This state holds the bridging table. This table is used to check if
incoming messages can be bridged from one subnet to another. The maximum number of rows supported
by the Bridging Table state can be configured using the
:kconfig:option:`CONFIG_BT_MESH_BRG_TABLE_ITEMS_MAX` configuration option.

* **Bridging Table Size state**: This state reports the maximum number of rows supported by the
Bridging Table state. This is a read-only state.


API reference
*************

Expand Down
19 changes: 16 additions & 3 deletions subsys/bluetooth/mesh/brg_cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ int bt_mesh_brg_cfg_tbl_add(enum bt_mesh_brg_cfg_dir direction, uint16_t net_idx
{
/* Sanity checks */
if (!BT_MESH_ADDR_IS_UNICAST(addr1) || net_idx1 == net_idx2 || addr1 == addr2 ||
net_idx1 > 0x03FF || net_idx2 > 0x03FF) {
net_idx1 > BT_MESH_BRG_CFG_KEY_INDEX_MAX || net_idx2 > BT_MESH_BRG_CFG_KEY_INDEX_MAX) {
return -EINVAL;
}

Expand Down Expand Up @@ -267,18 +267,29 @@ void bt_mesh_brg_cfg_tbl_foreach_subnet(uint16_t src, uint16_t dst, uint16_t net
}
}

void bt_mesh_brg_cfg_tbl_remove(uint16_t net_idx1, uint16_t net_idx2, uint16_t addr1,
int bt_mesh_brg_cfg_tbl_remove(uint16_t net_idx1, uint16_t net_idx2, uint16_t addr1,
uint16_t addr2)
{
#if IS_ENABLED(CONFIG_BT_SETTINGS)
bool store = false;
#endif
/* Sanity checks */
if ((!BT_MESH_ADDR_IS_UNICAST(addr1) && addr1 != BT_MESH_ADDR_UNASSIGNED) ||
addr2 == BT_MESH_ADDR_ALL_NODES) {
return -EINVAL;
}

if (net_idx1 == net_idx2 || net_idx1 > BT_MESH_BRG_CFG_KEY_INDEX_MAX ||
net_idx2 > BT_MESH_BRG_CFG_KEY_INDEX_MAX) {
return -EINVAL;
}


/* Iterate over items and set matching row to 0, if nothing exist, or nothing matches, then
* it is success (similar to add)
*/
if (bt_mesh_brg_cfg_row_cnt == 0) {
return;
return 0;
}

for (int i = 0; i < bt_mesh_brg_cfg_row_cnt; i++) {
Expand All @@ -304,4 +315,6 @@ void bt_mesh_brg_cfg_tbl_remove(uint16_t net_idx1, uint16_t net_idx2, uint16_t a
bt_mesh_settings_store_schedule(BT_MESH_SETTINGS_BRG_PENDING);
}
#endif

return 0;
}
7 changes: 6 additions & 1 deletion subsys/bluetooth/mesh/brg_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
#define ZEPHYR_SUBSYS_BLUETOOTH_MESH_BRG_CFG_H_

/** These are internal APIs. They do not sanitize input params. */

#define BT_MESH_BRG_CFG_KEY_INDEX_MAX 0x0FFF

#define BT_MESH_BRG_CFG_NKEY_PRHB_FLT_MASK 0x000C

enum bt_mesh_brg_cfg_dir {
/* Value is prohibited. */
BT_MESH_BRG_CFG_DIR_PROHIBITED = 0,
Expand Down Expand Up @@ -48,7 +53,7 @@ int bt_mesh_brg_cfg_tbl_get(const struct bt_mesh_brg_cfg_row **rows);
int bt_mesh_brg_cfg_tbl_add(enum bt_mesh_brg_cfg_dir direction, uint16_t net_idx1,
uint16_t net_idx2, uint16_t addr1, uint16_t addr2);

void bt_mesh_brg_cfg_tbl_remove(uint16_t net_idx1, uint16_t net_idx2, uint16_t addr1,
int bt_mesh_brg_cfg_tbl_remove(uint16_t net_idx1, uint16_t net_idx2, uint16_t addr1,
uint16_t addr2);

typedef void (*bt_mesh_brg_cfg_cb_t)(uint16_t new_netidx, void *user_data);
Expand Down
Loading

0 comments on commit 8210d2d

Please sign in to comment.