Skip to content

Commit

Permalink
Bluetooth: Mesh: enable access responses randomization
Browse files Browse the repository at this point in the history
Enable by default the access layer responses random delays.
Commit also adapts all mesh models, samples and
babblesim tests to use random delay functionality correctly.

Signed-off-by: Aleksandr Khromykh <[email protected]>
  • Loading branch information
alxelax committed Jan 12, 2024
1 parent e5b3231 commit 10c1a4b
Show file tree
Hide file tree
Showing 22 changed files with 54 additions and 27 deletions.
1 change: 1 addition & 0 deletions samples/bluetooth/mesh/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ static int gen_onoff_send(bool val)
.app_idx = models[3].keys[0], /* Use the bound key */
.addr = BT_MESH_ADDR_ALL_NODES,
.send_ttl = BT_MESH_TTL_DEFAULT,
.rnd_delay = false
};
static uint8_t tid;

Expand Down
1 change: 1 addition & 0 deletions samples/bluetooth/mesh_demo/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ void board_button_1_pressed(void)
.app_idx = app_idx,
.addr = target,
.send_ttl = BT_MESH_TTL_DEFAULT,
.rnd_delay = false
};

/* Bind to Health model */
Expand Down
1 change: 1 addition & 0 deletions samples/boards/nrf/mesh/onoff-app/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ static void button_pressed_worker(struct k_work *work)
NET_BUF_SIMPLE_DEFINE(msg, 1);
struct bt_mesh_msg_ctx ctx = {
.addr = sw_idx + primary_addr,
.rnd_delay = false
};

/* This is a dummy message sufficient
Expand Down
2 changes: 2 additions & 0 deletions samples/boards/reel_board/mesh_badge/src/mesh.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ static void send_hello(struct k_work *work)
.app_idx = APP_IDX,
.addr = GROUP_ADDR,
.send_ttl = DEFAULT_TTL,
.rnd_delay = false
};
const char *name = bt_get_name();

Expand Down Expand Up @@ -555,6 +556,7 @@ static void send_baduser(struct k_work *work)
.app_idx = APP_IDX,
.addr = GROUP_ADDR,
.send_ttl = DEFAULT_TTL,
.rnd_delay = false
};
const char *name = bt_get_name();

Expand Down
5 changes: 3 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 @@ -657,14 +658,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
7 changes: 5 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,7 @@ static int element_model_recv(struct bt_mesh_msg_ctx *ctx, struct net_buf_simple
return ACCESS_STATUS_MESSAGE_NOT_UNDERSTOOD;
}

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 +1579,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
1 change: 1 addition & 0 deletions subsys/bluetooth/mesh/blob_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ static int tx(struct bt_mesh_blob_cli *cli, uint16_t addr,
.app_idx = cli->inputs->app_idx,
.addr = addr,
.send_ttl = cli->inputs->ttl,
.rnd_delay = false
};
int err;

Expand Down
1 change: 1 addition & 0 deletions subsys/bluetooth/mesh/blob_srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ static void block_report(struct bt_mesh_blob_srv *srv)
.app_idx = srv->state.app_idx,
.send_ttl = srv->state.ttl,
.addr = srv->state.cli,
.rnd_delay = false
};
int count;
int i;
Expand Down
1 change: 1 addition & 0 deletions subsys/bluetooth/mesh/dfu_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ LOG_MODULE_REGISTER(bt_mesh_dfu_cli);
{ \
.app_idx = (cli)->blob.inputs->app_idx, .addr = dst, \
.send_ttl = (cli)->blob.inputs->ttl, \
.rnd_delay = false \
}

#define DFU_CLI(blob_cli) CONTAINER_OF(blob_cli, struct bt_mesh_dfu_cli, blob)
Expand Down
1 change: 1 addition & 0 deletions subsys/bluetooth/mesh/op_agg_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ int bt_mesh_op_agg_cli_seq_send(void)
.net_idx = cli.ctx.net_idx,
.app_idx = cli.ctx.app_idx,
.addr = cli.ctx.addr,
.rnd_delay = false
};
int err;

Expand Down
1 change: 1 addition & 0 deletions subsys/bluetooth/mesh/rpr_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ BUILD_ASSERT(BT_MESH_MODEL_OP_LEN(RPR_OP_PDU_SEND) == 2, "Assumes PDU send is a
.net_idx = (_srv)->net_idx, .app_idx = BT_MESH_KEY_DEV_REMOTE, \
.addr = (_srv)->addr, .send_ttl = (_srv)->ttl, \
.send_rel = (_send_rel), \
.rnd_delay = false \
}

enum {
Expand Down
3 changes: 2 additions & 1 deletion subsys/bluetooth/mesh/rpr_srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ LOG_MODULE_REGISTER(bt_mesh_rpr_srv);
{ \
.net_idx = (_cli)->net_idx, .app_idx = BT_MESH_KEY_DEV_LOCAL, \
.addr = (_cli)->addr, .send_ttl = (_cli)->ttl, \
.send_rel = (_send_rel) \
.send_rel = (_send_rel), \
.rnd_delay = false \
}

enum {
Expand Down
4 changes: 4 additions & 0 deletions subsys/bluetooth/mesh/sar_cfg_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ int bt_mesh_sar_cfg_cli_transmitter_get(uint16_t net_idx, uint16_t addr,
.app_idx = BT_MESH_KEY_DEV,
.addr = addr,
.send_ttl = BT_MESH_TTL_DEFAULT,
.rnd_delay = false,
};
int err;

Expand Down Expand Up @@ -164,6 +165,7 @@ int bt_mesh_sar_cfg_cli_transmitter_set(uint16_t net_idx, uint16_t addr,
.app_idx = BT_MESH_KEY_DEV,
.addr = addr,
.send_ttl = BT_MESH_TTL_DEFAULT,
.rnd_delay = false,
};
int err;

Expand Down Expand Up @@ -194,6 +196,7 @@ int bt_mesh_sar_cfg_cli_receiver_get(uint16_t net_idx, uint16_t addr,
.app_idx = BT_MESH_KEY_DEV,
.addr = addr,
.send_ttl = BT_MESH_TTL_DEFAULT,
.rnd_delay = false,
};
int err;

Expand Down Expand Up @@ -224,6 +227,7 @@ int bt_mesh_sar_cfg_cli_receiver_set(uint16_t net_idx, uint16_t addr,
.app_idx = BT_MESH_KEY_DEV,
.addr = addr,
.send_ttl = BT_MESH_TTL_DEFAULT,
.rnd_delay = false,
};
int err;

Expand Down
4 changes: 4 additions & 0 deletions subsys/bluetooth/mesh/shell/dfu.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ static int cmd_dfu_target_state(const struct shell *sh, size_t argc, char *argv[
.net_idx = bt_mesh_shell_target_ctx.net_idx,
.addr = bt_mesh_shell_target_ctx.dst,
.app_idx = bt_mesh_shell_target_ctx.app_idx,
.rnd_delay = false,
};
int err;

Expand Down Expand Up @@ -636,6 +637,7 @@ static int cmd_dfu_target_imgs(const struct shell *sh, size_t argc, char *argv[]
.net_idx = bt_mesh_shell_target_ctx.net_idx,
.addr = bt_mesh_shell_target_ctx.dst,
.app_idx = bt_mesh_shell_target_ctx.app_idx,
.rnd_delay = false,
};
uint8_t img_cnt = 0xff;
int err = 0;
Expand Down Expand Up @@ -672,6 +674,7 @@ static int cmd_dfu_target_check(const struct shell *sh, size_t argc, char *argv[
.net_idx = bt_mesh_shell_target_ctx.net_idx,
.addr = bt_mesh_shell_target_ctx.dst,
.app_idx = bt_mesh_shell_target_ctx.app_idx,
.rnd_delay = false,
};
uint8_t slot_idx, img_idx;
int err = 0;
Expand Down Expand Up @@ -781,6 +784,7 @@ static int cmd_dfu_tx_cancel(const struct shell *sh, size_t argc, char *argv[])
.net_idx = bt_mesh_shell_target_ctx.net_idx,
.addr = bt_mesh_shell_target_ctx.dst,
.app_idx = bt_mesh_shell_target_ctx.app_idx,
.rnd_delay = false,
};
int err = 0;

Expand Down
13 changes: 13 additions & 0 deletions tests/bluetooth/tester/src/btp_mesh.c
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,7 @@ static uint8_t net_send(const void *cmd, uint16_t cmd_len,
.app_idx = vnd_app_key_idx,
.addr = sys_le16_to_cpu(cp->dst),
.send_ttl = cp->ttl,
.rnd_delay = false,
};

if (BT_MESH_ADDR_IS_VIRTUAL(ctx.addr)) {
Expand Down Expand Up @@ -1729,6 +1730,7 @@ static uint8_t model_send(const void *cmd, uint16_t cmd_len,
.app_idx = BT_MESH_KEY_DEV,
.addr = sys_le16_to_cpu(cp->dst),
.send_ttl = cp->ttl,
.rnd_delay = false,
};

if (BT_MESH_ADDR_IS_VIRTUAL(ctx.addr)) {
Expand Down Expand Up @@ -3365,6 +3367,7 @@ static uint8_t health_fault_get(const void *cmd, uint16_t cmd_len,
.net_idx = net.net_idx,
.addr = sys_le16_to_cpu(cp->address),
.app_idx = sys_le16_to_cpu(cp->app_idx),
.rnd_delay = false,
};
uint8_t test_id;
size_t fault_count = 16;
Expand Down Expand Up @@ -3393,6 +3396,7 @@ static uint8_t health_fault_clear(const void *cmd, uint16_t cmd_len,
.net_idx = net.net_idx,
.addr = sys_le16_to_cpu(cp->address),
.app_idx = sys_le16_to_cpu(cp->app_idx),
.rnd_delay = false,
};
uint8_t test_id = 0;
size_t fault_count = 16;
Expand Down Expand Up @@ -3447,6 +3451,7 @@ static uint8_t health_fault_test(const void *cmd, uint16_t cmd_len,
.net_idx = net.net_idx,
.addr = sys_le16_to_cpu(cp->address),
.app_idx = sys_le16_to_cpu(cp->app_idx),
.rnd_delay = false,
};
size_t fault_count = 16;
uint8_t faults[fault_count];
Expand Down Expand Up @@ -3509,6 +3514,7 @@ static uint8_t health_period_get(const void *cmd, uint16_t cmd_len,
.net_idx = net.net_idx,
.addr = sys_le16_to_cpu(cp->address),
.app_idx = sys_le16_to_cpu(cp->app_idx),
.rnd_delay = false,
};
uint8_t divisor;
int err;
Expand All @@ -3533,6 +3539,7 @@ static uint8_t health_period_set(const void *cmd, uint16_t cmd_len,
.net_idx = net.net_idx,
.addr = sys_le16_to_cpu(cp->address),
.app_idx = sys_le16_to_cpu(cp->app_idx),
.rnd_delay = false,
};
uint8_t updated_divisor;
int err;
Expand Down Expand Up @@ -3574,6 +3581,7 @@ static uint8_t health_attention_get(const void *cmd, uint16_t cmd_len,
.net_idx = net.net_idx,
.addr = sys_le16_to_cpu(cp->address),
.app_idx = sys_le16_to_cpu(cp->app_idx),
.rnd_delay = false,
};
uint8_t attention;
int err;
Expand All @@ -3598,6 +3606,7 @@ static uint8_t health_attention_set(const void *cmd, uint16_t cmd_len,
.net_idx = net.net_idx,
.addr = sys_le16_to_cpu(cp->address),
.app_idx = sys_le16_to_cpu(cp->app_idx),
.rnd_delay = false,
};
uint8_t updated_attention;
int err;
Expand Down Expand Up @@ -4007,6 +4016,7 @@ static uint8_t dfu_info_get(const void *cmd, uint16_t cmd_len,
struct bt_mesh_msg_ctx ctx = {
.net_idx = net.net_idx,
.send_ttl = BT_MESH_TTL_DEFAULT,
.rnd_delay = false,
};
uint8_t max_count;
int err = 0;
Expand Down Expand Up @@ -4042,6 +4052,7 @@ static uint8_t dfu_update_metadata_check(const void *cmd, uint16_t cmd_len,
struct bt_mesh_msg_ctx ctx = {
.net_idx = net.net_idx,
.send_ttl = BT_MESH_TTL_DEFAULT,
.rnd_delay = false,
};
struct bt_mesh_dfu_metadata_status rsp_data;
uint8_t img_idx, slot_idx;
Expand Down Expand Up @@ -4105,6 +4116,7 @@ static uint8_t dfu_firmware_update_get(const void *cmd, uint16_t cmd_len,
struct bt_mesh_msg_ctx ctx = {
.net_idx = net.net_idx,
.send_ttl = BT_MESH_TTL_DEFAULT,
.rnd_delay = false,
};
struct bt_mesh_dfu_target_status rsp_data;
struct btp_mmdl_dfu_firmware_update_rp *rp = rsp;
Expand Down Expand Up @@ -4139,6 +4151,7 @@ static uint8_t dfu_firmware_update_cancel(const void *cmd, uint16_t cmd_len,
struct bt_mesh_msg_ctx ctx = {
.net_idx = net.net_idx,
.send_ttl = BT_MESH_TTL_DEFAULT,
.rnd_delay = false,
};
int err;

Expand Down
13 changes: 9 additions & 4 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 @@ -325,7 +329,6 @@ static void common_configure(uint16_t addr)
FAIL("AppKey add failed (err %d, status %u)", err, status);
return;
}

for (int i = 0; i < ARRAY_SIZE(model_ids); i++) {
err = bt_mesh_cfg_cli_mod_app_bind(0, addr, addr, 0, model_ids[i], &status);
if (err || status) {
Expand Down Expand Up @@ -377,6 +380,7 @@ static void test_tx_ext_model(void)
.addr = GROUP_ADDR,
.send_rel = false,
.send_ttl = BT_MESH_TTL_DEFAULT,
.rnd_delay = false,
};
BT_MESH_MODEL_BUF_DEFINE(msg, TEST_MESSAGE_OP_1, 0);

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
1 change: 1 addition & 0 deletions tests/bsim/bluetooth/mesh/src/test_op_agg.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ static void common_init(uint16_t own_addr, uint16_t dst_addr, bool agg_cli_fill)
.net_idx = 0,
.app_idx = 0,
.addr = dst_addr,
.rnd_delay = false,
};

/* Populate the op_agg sequence */
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 @@ -1211,7 +1211,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 @@ -1225,15 +1224,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
Loading

0 comments on commit 10c1a4b

Please sign in to comment.