Skip to content
15 changes: 7 additions & 8 deletions doc/connectivity/bluetooth/api/mesh/brg_cfg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ Enabling or disabling the Subnet Bridge feature

The Bridge Configuration Client (or Configuration Manager) can enable or disable the Subnet Bridge
feature on a node by sending a **Subnet Bridge Set** message to the Bridge Configuration
Server model on the target node, using the :c:func:`bt_mesh_brg_cfg_cli_subnet_bridge_set` function.
Server model on the target node, using the :c:func:`bt_mesh_brg_cfg_cli_set` function.

Adding or removing subnets
**************************

The Bridge Configuration Client can add or remove an entry from the Bridging Table by sending a
**Bridging Table Add** or **Bridging Table Remove** message to the Bridge Configuration
Server model on the target node, calling the :c:func:`bt_mesh_brg_cfg_cli_bridging_table_add` or
:c:func:`bt_mesh_brg_cfg_cli_bridging_table_remove` functions.
Server model on the target node, calling the :c:func:`bt_mesh_brg_cfg_cli_table_add` or
:c:func:`bt_mesh_brg_cfg_cli_table_remove` functions.

.. _bluetooth_mesh_brg_cfg_states:

Expand All @@ -89,20 +89,19 @@ The Subnet Bridge has the following states:
- *Subnet Bridge*: This state indicates whether the Subnet Bridge feature is enabled or disabled on
the node.
The Bridge Configuration Client can retrieve this information by sending a **Subnet Bridge Get**
message to the Bridge Configuration Server using the
:c:func:`bt_mesh_brg_cfg_cli_subnet_bridge_get` function.
message to the Bridge Configuration Server using the :c:func:`bt_mesh_brg_cfg_cli_get` function.

- *Bridging Table*: This state holds the bridging table. The Client can request a list of
entries from a Bridging Table by sending a **Bridging Table Get** message to the target node using
the :c:func:`bt_mesh_brg_cfg_cli_bridging_table_get` function.
the :c:func:`bt_mesh_brg_cfg_cli_table_get` function.

The Client can get a list of subnets currently bridged by a Subnet Bridge by sending a
**Bridged Subnets Get** message to the target Server by calling the
:c:func:`bt_mesh_brg_cfg_cli_bridged_subnets_get` function.
:c:func:`bt_mesh_brg_cfg_cli_subnets_get` function.

- *Bridging Table Size*: This state reports the maximum number of entries the Bridging Table can
store. The Client can retrieve this information by sending a **Bridging Table Size Get** message
using the :c:func:`bt_mesh_brg_cfg_cli_bridging_table_size_get` function.
using the :c:func:`bt_mesh_brg_cfg_cli_table_size_get` function.
This is a read-only state.

Subnet bridging and replay protection
Expand Down
28 changes: 14 additions & 14 deletions include/zephyr/bluetooth/mesh/brg_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ extern "C" {
*/

/** Subnet Bridge states */
enum bt_mesh_subnet_bridge_state {
enum bt_mesh_brg_cfg_state {
/** Subnet bridge functionality is disabled. */
BT_MESH_SUBNET_BRIDGE_DISABLED,
BT_MESH_BRG_CFG_DISABLED,
/** Subnet bridge state functionality is enabled. */
BT_MESH_SUBNET_BRIDGE_ENABLED,
BT_MESH_BRG_CFG_ENABLED,
};

/* Briding from Addr1 to Addr2. */
#define BT_MESH_SUBNET_BRIDGE_DIR_ONEWAY 1
/* Bidirectional briging between Addr1 and Addr2. */
#define BT_MESH_SUBNET_BRIDGE_DIR_TWOWAY 2
/* Bridging from Addr1 to Addr2. */
#define BT_MESH_BRG_CFG_DIR_ONEWAY 1
/* Bidirectional bridging between Addr1 and Addr2. */
#define BT_MESH_BRG_CFG_DIR_TWOWAY 2

/** Bridging Table state entry corresponding to a entry in the Bridging Table. */
struct bt_mesh_bridging_table_entry {
struct bt_mesh_brg_cfg_table_entry {
/** Allowed directions for the bridged traffic (or bridged traffic not allowed) */
uint8_t directions;
/** NetKey Index of the first subnet */
Expand All @@ -48,32 +48,32 @@ struct bt_mesh_bridging_table_entry {
};

/** Bridging Table Status response */
struct bt_mesh_bridging_table_status {
struct bt_mesh_brg_cfg_table_status {
/** Status Code of the requesting message */
uint8_t status;
/** Requested Bridging Table entry */
struct bt_mesh_bridging_table_entry entry;
struct bt_mesh_brg_cfg_table_entry entry;
};

/** Used to filter set of pairs of NetKey Indexes from the Bridging Table */
struct bt_mesh_filter_netkey {
struct bt_mesh_brg_cfg_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 {
struct bt_mesh_brg_cfg_subnets_list {
/** Filter applied NetKey Indexes, and NetKey Index used for filtering. */
struct bt_mesh_filter_netkey net_idx_filter;
struct bt_mesh_brg_cfg_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 {
struct bt_mesh_brg_cfg_table_list {
/** Status Code of the requesting message */
uint8_t status;
/** NetKey Index of the first subnet */
Expand Down
76 changes: 36 additions & 40 deletions include/zephyr/bluetooth/mesh/brg_cfg_cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ struct bt_mesh_brg_cfg_cli_cb {
* @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,
enum bt_mesh_subnet_bridge_state status);
void (*bridge_status)(struct bt_mesh_brg_cfg_cli *cli, uint16_t addr,
enum bt_mesh_brg_cfg_state status);

/** @brief Optional callback for Bridging Table Size Status message.
*
Expand All @@ -54,8 +54,7 @@ struct bt_mesh_brg_cfg_cli_cb {
* @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);
void (*table_size_status)(struct bt_mesh_brg_cfg_cli *cli, uint16_t addr, uint16_t size);

/** @brief Optional callback for Bridging Table Status message.
*
Expand All @@ -66,8 +65,8 @@ struct bt_mesh_brg_cfg_cli_cb {
* @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);
void (*table_status)(struct bt_mesh_brg_cfg_cli *cli, uint16_t addr,
struct bt_mesh_brg_cfg_table_status *rsp);

/** @brief Optional callback for Bridged Subnets List message.
*
Expand All @@ -78,8 +77,8 @@ struct bt_mesh_brg_cfg_cli_cb {
* @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);
void (*subnets_list)(struct bt_mesh_brg_cfg_cli *cli, uint16_t addr,
struct bt_mesh_brg_cfg_subnets_list *rsp);

/** @brief Optional callback for Bridging Table List message.
*
Expand All @@ -90,8 +89,8 @@ struct bt_mesh_brg_cfg_cli_cb {
* @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);
void (*table_list)(struct bt_mesh_brg_cfg_cli *cli, uint16_t addr,
struct bt_mesh_brg_cfg_table_list *rsp);
};

/** Bridge Configuration Client Model Context */
Expand Down Expand Up @@ -121,13 +120,12 @@ struct bt_mesh_brg_cfg_cli {
* @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.
* @ref BT_MESH_BRG_CFG_DISABLED or
* @ref BT_MESH_BRG_CFG_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,
enum bt_mesh_subnet_bridge_state *status);
int bt_mesh_brg_cfg_cli_get(uint16_t net_idx, uint16_t addr, enum bt_mesh_brg_cfg_state *status);

/** @brief Sends a Subnet Bridge Set message to the given destination address
* with the given parameters
Expand All @@ -145,17 +143,16 @@ int bt_mesh_brg_cfg_cli_subnet_bridge_get(uint16_t net_idx, uint16_t addr,
* @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.
* @ref BT_MESH_BRG_CFG_DISABLED or
* @ref BT_MESH_BRG_CFG_ENABLED.
* @param status Status response parameter, returns one of
* @ref BT_MESH_SUBNET_BRIDGE_DISABLED or
* @ref BT_MESH_SUBNET_BRIDGE_ENABLED on success.
* @ref BT_MESH_BRG_CFG_DISABLED or
* @ref BT_MESH_BRG_CFG_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,
enum bt_mesh_subnet_bridge_state val,
enum bt_mesh_subnet_bridge_state *status);
int bt_mesh_brg_cfg_cli_set(uint16_t net_idx, uint16_t addr, enum bt_mesh_brg_cfg_state val,
enum bt_mesh_brg_cfg_state *status);

/** @brief Sends a Bridging Table Size Get message to the given destination
* address with the given parameters
Expand All @@ -176,7 +173,7 @@ int bt_mesh_brg_cfg_cli_subnet_bridge_set(uint16_t net_idx, uint16_t addr,
*
* @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);
int bt_mesh_brg_cfg_cli_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
Expand All @@ -198,9 +195,9 @@ int bt_mesh_brg_cfg_cli_bridging_table_size_get(uint16_t net_idx, uint16_t addr,
*
* @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,
struct bt_mesh_bridging_table_entry *entry,
struct bt_mesh_bridging_table_status *rsp);
int bt_mesh_brg_cfg_cli_table_add(uint16_t net_idx, uint16_t addr,
struct bt_mesh_brg_cfg_table_entry *entry,
struct bt_mesh_brg_cfg_table_status *rsp);

/** @brief Sends a Bridging Table Remove message to the given destination
* address with the given parameters
Expand All @@ -226,9 +223,9 @@ int bt_mesh_brg_cfg_cli_bridging_table_add(uint16_t net_idx, uint16_t addr,
*
* @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_idx1,
uint16_t net_idx2, uint16_t addr1, uint16_t addr2,
struct bt_mesh_bridging_table_status *rsp);
int bt_mesh_brg_cfg_cli_table_remove(uint16_t net_idx, uint16_t addr, uint16_t net_idx1,
uint16_t net_idx2, uint16_t addr1, uint16_t addr2,
struct bt_mesh_brg_cfg_table_status *rsp);

/** @brief Sends a Bridged Subnets Get message to the given destination address
* with the given parameters
Expand All @@ -244,7 +241,7 @@ int bt_mesh_brg_cfg_cli_bridging_table_remove(uint16_t net_idx, uint16_t addr, u
*
* 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
* @ref bt_mesh_brg_cfg_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.
Expand All @@ -256,10 +253,9 @@ int bt_mesh_brg_cfg_cli_bridging_table_remove(uint16_t net_idx, uint16_t addr, u
*
* @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);
int bt_mesh_brg_cfg_cli_subnets_get(uint16_t net_idx, uint16_t addr,
struct bt_mesh_brg_cfg_filter_netkey filter_net_idx,
uint8_t start_idx, struct bt_mesh_brg_cfg_subnets_list *rsp);

/** @brief Sends a Bridging Table Get message to the given destination address
* with the given parameters
Expand All @@ -276,10 +272,10 @@ int bt_mesh_brg_cfg_cli_bridged_subnets_get(uint16_t net_idx, uint16_t addr,
*
* 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. If a buffer size is shorter than received
* list, only those many entries that fit in the buffer will be copied from the
* list, and rest will be discarded.
* @ref bt_mesh_brg_cfg_table_list::list. If a buffer is not provided,
* the bridged addresses won't be copied. If a buffer size is shorter than
* received list, only those many entries that fit in the buffer will be copied
* from the list, and rest will be discarded.
*
* @param net_idx Network index to encrypt the message with.
* @param addr Target node address.
Expand All @@ -291,9 +287,9 @@ int bt_mesh_brg_cfg_cli_bridged_subnets_get(uint16_t net_idx, uint16_t addr,
*
* @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_idx1,
uint16_t net_idx2, uint16_t start_idx,
struct bt_mesh_bridging_table_list *rsp);
int bt_mesh_brg_cfg_cli_table_get(uint16_t net_idx, uint16_t addr, uint16_t net_idx1,
uint16_t net_idx2, uint16_t start_idx,
struct bt_mesh_brg_cfg_table_list *rsp);

/** @brief Get the current transmission timeout value.
*
Expand Down
43 changes: 24 additions & 19 deletions subsys/bluetooth/mesh/adv_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,28 @@ static const char * const adv_tag_to_str[] = {
[BT_MESH_ADV_TAG_PROV] = "prov adv",
};

static bool schedule_send_with_mask(struct bt_mesh_ext_adv *ext_adv, int ignore_mask)
{
if (atomic_test_and_clear_bit(ext_adv->flags, ADV_FLAG_PROXY)) {
atomic_clear_bit(ext_adv->flags, ADV_FLAG_PROXY_START);
(void)bt_le_ext_adv_stop(ext_adv->instance);

atomic_clear_bit(ext_adv->flags, ADV_FLAG_ACTIVE);
}

if (atomic_test_bit(ext_adv->flags, ADV_FLAG_ACTIVE)) {
atomic_set_bit(ext_adv->flags, ADV_FLAG_SCHEDULE_PENDING);
return false;
} else if ((~ignore_mask) & k_work_busy_get(&ext_adv->work)) {
return false;
}

atomic_clear_bit(ext_adv->flags, ADV_FLAG_SCHEDULE_PENDING);
k_work_submit(&ext_adv->work);

return true;
}

static void send_pending_adv(struct k_work *work)
{
struct bt_mesh_ext_adv *ext_adv;
Expand Down Expand Up @@ -339,30 +361,13 @@ static void send_pending_adv(struct k_work *work)
}

if (atomic_test_and_clear_bit(ext_adv->flags, ADV_FLAG_SCHEDULE_PENDING)) {
schedule_send(ext_adv);
schedule_send_with_mask(ext_adv, K_WORK_RUNNING);
}
}

static bool schedule_send(struct bt_mesh_ext_adv *ext_adv)
{
if (atomic_test_and_clear_bit(ext_adv->flags, ADV_FLAG_PROXY)) {
atomic_clear_bit(ext_adv->flags, ADV_FLAG_PROXY_START);
(void)bt_le_ext_adv_stop(ext_adv->instance);

atomic_clear_bit(ext_adv->flags, ADV_FLAG_ACTIVE);
}

if (atomic_test_bit(ext_adv->flags, ADV_FLAG_ACTIVE)) {
atomic_set_bit(ext_adv->flags, ADV_FLAG_SCHEDULE_PENDING);
return false;
} else if (k_work_is_pending(&ext_adv->work)) {
return false;
}

atomic_clear_bit(ext_adv->flags, ADV_FLAG_SCHEDULE_PENDING);
k_work_submit(&ext_adv->work);

return true;
return schedule_send_with_mask(ext_adv, 0);
}

void bt_mesh_adv_gatt_update(void)
Expand Down
Loading
Loading