Skip to content

[nrf fromtree] Bluetooth: Mesh: enable access responses randomization #1474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions subsys/bluetooth/mesh/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ config BT_MESH_LABEL_NO_RECOVER

menuconfig BT_MESH_ACCESS_DELAYABLE_MSG
bool "Access layer tx delayable message"
default y
help
Enable following of the message transmitting recommendations, the Access layer
specification. The recommendations are optional.
Expand All @@ -647,6 +648,16 @@ menuconfig BT_MESH_ACCESS_DELAYABLE_MSG

if BT_MESH_ACCESS_DELAYABLE_MSG

config BT_MESH_ACCESS_DELAYABLE_MSG_CTX_ENABLED
bool "The delayable message in the notification message context"
default y
help
Controls whether the delayable message feature is enabled by default in
the message context of the opcode notifications. This allows the server part of any
model to not bother about additional context configuration to enable the delayable message.
Note that if this is disabled then all foundation models stop using the delayable message
functionality.

config BT_MESH_ACCESS_DELAYABLE_MSG_COUNT
int "Number of simultaneously delayed messages"
default 4
Expand All @@ -657,14 +668,14 @@ config BT_MESH_ACCESS_DELAYABLE_MSG_COUNT

config BT_MESH_ACCESS_DELAYABLE_MSG_CHUNK_SIZE
int "Maximum delayable message storage chunk"
default 20
default 10
help
Size of memory that Access layer uses to split model message to. It allocates
a sufficient number of these chunks from the pool to store the full model payload.

config BT_MESH_ACCESS_DELAYABLE_MSG_CHUNK_COUNT
int "Maximum number of available chunks"
default 20
default 40
help
The maximum number of available chunks the Access layer allocates to store model payload.
It is recommended to keep chunk size equal to the reasonable small value to prevent
Expand Down
10 changes: 8 additions & 2 deletions subsys/bluetooth/mesh/access.c
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ static void mod_publish(struct k_work *work)
return;
}

LOG_DBG("%u", k_uptime_get_32());
LOG_DBG("timestamp: %u", k_uptime_get_32());

if (pub->count) {
pub->count--;
Expand Down Expand Up @@ -1504,6 +1504,10 @@ static int element_model_recv(struct bt_mesh_msg_ctx *ctx, struct net_buf_simple
return ACCESS_STATUS_MESSAGE_NOT_UNDERSTOOD;
}

if (IS_ENABLED(CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG_CTX_ENABLED)) {
ctx->rnd_delay = true;
}

net_buf_simple_save(buf, &state);
err = op->func(model, ctx, buf);
net_buf_simple_restore(buf, &state);
Expand Down Expand Up @@ -1578,7 +1582,9 @@ int bt_mesh_model_send(const struct bt_mesh_model *model, struct bt_mesh_msg_ctx
}

#if defined CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG
if (ctx->rnd_delay) {
/* No sense to use delayable message for unicast loopback. */
if (ctx->rnd_delay &&
!(bt_mesh_has_addr(ctx->addr) && BT_MESH_ADDR_IS_UNICAST(ctx->addr))) {
return bt_mesh_delayable_msg_manage(ctx, msg, bt_mesh_model_elem(model)->rt->addr,
cb, cb_data);
}
Expand Down
4 changes: 3 additions & 1 deletion subsys/bluetooth/mesh/delayable_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,15 @@ static bool push_msg_from_delayable_msgs(void)
sys_snode_t *node;
struct delayable_msg_chunk *chunk;
struct delayable_msg_ctx *msg = peek_pending_msg();
uint16_t len = msg->len;
uint16_t len;
int err;

if (!msg) {
return false;
}

len = msg->len;

NET_BUF_SIMPLE_DEFINE(buf, BT_MESH_TX_SDU_MAX);

SYS_SLIST_FOR_EACH_NODE(&msg->chunks, node) {
Expand Down
11 changes: 8 additions & 3 deletions tests/bsim/bluetooth/mesh/src/test_access.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,15 @@ static bool publish_allow;

static int model1_update(const struct bt_mesh_model *model)
{
model->pub->msg->data[1]++;
if (!publish_allow) {
return -1;
}

model->pub->msg->data[1]++;
LOG_DBG("New pub: n: %d t: %d", model->pub->msg->data[1], k_uptime_get_32());
k_sem_give(&publish_sem);

return publish_allow ? k_sem_give(&publish_sem), 0 : -1;
return 0;
}

static int test_msgf_handler(const struct bt_mesh_model *model,
Expand Down Expand Up @@ -604,7 +608,8 @@ static void recv_delayable_check(int32_t interval, uint8_t count)

LOG_DBG("Recv time: %d delta: %d boundaries: %d/%d", (int32_t)timestamp, time_delta,
lower_boundary, upper_boundary);
ASSERT_IN_RANGE(time_delta, lower_boundary, upper_boundary + RX_JITTER_MAX);
ASSERT_IN_RANGE(time_delta, lower_boundary - RX_JITTER_MAX,
upper_boundary + RX_JITTER_MAX);
}
}

Expand Down
6 changes: 0 additions & 6 deletions tests/bsim/bluetooth/mesh/src/test_persistence.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,6 @@ static void provisioner_setup(void)
FAIL("Failed to add test_netkey (err: %d, status: %d)", err, status);
}

err = bt_mesh_cfg_cli_net_transmit_set(test_netkey_idx, TEST_PROV_ADDR,
BT_MESH_TRANSMIT(3, 50), &status);
if (err || status != BT_MESH_TRANSMIT(3, 50)) {
FAIL("Net transmit set failed (err %d, transmit %x)", err, status);
}

provisioner_ready = true;
}

Expand Down
10 changes: 0 additions & 10 deletions tests/bsim/bluetooth/mesh/src/test_provision.c
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,6 @@ static void test_provisioner_pb_remote_client_nppi_robustness(void)
uint16_t pb_remote_server_addr;
uint8_t status;
struct bt_mesh_cdb_node *node;
int err;

provisioner_pb_remote_client_setup();

Expand All @@ -1219,15 +1218,6 @@ static void test_provisioner_pb_remote_client_nppi_robustness(void)
.ttl = 3,
};

/* Set Network Transmit Count state on the remote client greater than on the remote server
* to increase probability of reception responses.
*/
err = bt_mesh_cfg_cli_net_transmit_set(0, current_dev_addr, BT_MESH_TRANSMIT(3, 50),
&status);
if (err || status != BT_MESH_TRANSMIT(3, 50)) {
FAIL("Net transmit set failed (err %d, transmit %x)", err, status);
}

ASSERT_OK(provision_remote(&srv, 2, &srv.addr));

/* Check device key by adding appkey. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ RunTest mesh_access_pub_transmit_delayable_retr_1d1 \
conf=prj_mesh1d1_conf
overlay=overlay_psa_conf
RunTest mesh_access_pub_transmit_delayable_retr_psa \
access_tx_period_delayable access_rx_period_delayable
access_tx_transmit_delayable access_rx_transmit_delayable
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh
# window. The Mesh Protocol specification does not specify exactly the
# timing for Proxy ADV messages.

# Note 3: The proxy transmitting device mandates emitting of the secure
# network beacons. This allows to check that proxy goes back to normal
# behavior after the device advertises the secure network beacons.

# Test procedure:
# 1. (0-20 seconds) A single subnet is active on the TX device with GATT
# Proxy enabled. RX device verifies that the single subnet has exclusive
Expand Down