Skip to content

Commit 1a6993c

Browse files
HaavardReiPavelVPV
authored andcommitted
[nrf fromtree] Bluetooth: Mesh: Test pb cancelling in bsim
Adds a provision test to check that provisioning bearers are cancelled when a provisioning link is opened. Modifies the functionality for receiving unprovisioned beacons to fail the test if a unprovisioned beacon is received from the current provisionee after a threshold. Signed-off-by: Håvard Reierstad <[email protected]> (cherry picked from commit acccd46) Signed-off-by: Pavel Vasilyev <[email protected]>
1 parent 951110a commit 1a6993c

File tree

2 files changed

+138
-4
lines changed

2 files changed

+138
-4
lines changed

tests/bsim/bluetooth/mesh/src/test_provision.c

+111-4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
3838
#define WAIT_TIME 120 /*seconds*/
3939
#define IS_RPR_PRESENT (CONFIG_BT_MESH_RPR_SRV && CONFIG_BT_MESH_RPR_CLI)
4040
#define IMPOSTER_MODEL_ID 0xe000
41+
/* Rough estimate of the time it should take the provisionee to stop sending unprov beacons. */
42+
#define PROV_DELTA_THRESH_MS 100
4143

4244
enum test_flags {
4345
IS_PROVISIONER,
@@ -97,17 +99,26 @@ static uint32_t link_close_timestamp;
9799

98100
/* Set prov_bearer to non-zero invalid value. */
99101
static bt_mesh_prov_bearer_t prov_bearer = 0xF8;
102+
static bt_mesh_prov_bearer_t prov_to_use;
100103

101104
static void test_args_parse(int argc, char *argv[])
102105
{
103106
bs_args_struct_t args_struct[] = {
104107
{
105108
.dest = &prov_bearer,
106109
.type = 'i',
107-
.name = "{invalid, PB-ADV, PB-GATT}",
110+
.name = "{invalid, PB-ADV, PB-GATT, (PB-ADV | PB-GATT)}",
108111
.option = "prov-bearer",
109112
.descript = "Provisioning bearer that is to be used."
110113
},
114+
{
115+
.dest = &prov_to_use,
116+
.type = 'i',
117+
.name = "{PB-ADV, PB-GATT}",
118+
.option = "prov-to-use",
119+
.descript = "Provisioning bearer that is to be used in the case that "
120+
"multiple provisioning bearers are enabled in prov_bearer."
121+
},
111122
};
112123

113124
bs_args_parse_all_cmd_line(argc, argv, args_struct);
@@ -275,6 +286,42 @@ static void test_terminate(void)
275286
}
276287
}
277288

289+
static uint64_t prov_started_time_ms;
290+
static uint8_t prov_uuid[16];
291+
292+
static void provision(uint8_t uuid[16], bt_mesh_prov_bearer_t bearer)
293+
{
294+
int err;
295+
296+
switch (bearer) {
297+
case BT_MESH_PROV_ADV:
298+
err = bt_mesh_provision_adv(uuid, 0, prov_addr, 0);
299+
break;
300+
case BT_MESH_PROV_GATT:
301+
err = bt_mesh_provision_gatt(uuid, 0, prov_addr, 0);
302+
break;
303+
default:
304+
err = -ENOTSUP;
305+
}
306+
307+
if (!err) {
308+
LOG_INF("Provisioning over %s started.",
309+
bearer == BT_MESH_PROV_ADV ? "PB-ADV" : "PB-GATT");
310+
prov_started_time_ms = k_uptime_get();
311+
memcpy(prov_uuid, uuid, 16);
312+
}
313+
}
314+
315+
static void provisionee_beacon_check(uint8_t uuid[16], bt_mesh_prov_bearer_t bearer)
316+
{
317+
if (memcmp(uuid, prov_uuid, 16) == 0) {
318+
ASSERT_FALSE_MSG((prov_started_time_ms &&
319+
(k_uptime_delta(&prov_started_time_ms) > PROV_DELTA_THRESH_MS)),
320+
"Received %s beacon from provisionee after provisioning started.",
321+
bearer == BT_MESH_PROV_ADV ? "PB-ADV" : "PB-GATT");
322+
}
323+
}
324+
278325
static void unprovisioned_beacon(uint8_t uuid[16],
279326
bt_mesh_prov_oob_info_t oob_info,
280327
uint32_t *uri_hash)
@@ -286,7 +333,12 @@ static void unprovisioned_beacon(uint8_t uuid[16],
286333
if (uuid_to_provision && memcmp(uuid, uuid_to_provision, 16)) {
287334
return;
288335
}
289-
bt_mesh_provision_adv(uuid, 0, prov_addr, 0);
336+
337+
provisionee_beacon_check(uuid, BT_MESH_PROV_ADV);
338+
339+
if (!prov_to_use || prov_to_use == BT_MESH_PROV_ADV) {
340+
provision(uuid, BT_MESH_PROV_ADV);
341+
}
290342
}
291343

292344
static void unprovisioned_beacon_gatt(uint8_t uuid[16], bt_mesh_prov_oob_info_t oob_info)
@@ -299,7 +351,11 @@ static void unprovisioned_beacon_gatt(uint8_t uuid[16], bt_mesh_prov_oob_info_t
299351
return;
300352
}
301353

302-
bt_mesh_provision_gatt(uuid, 0, prov_addr, 0);
354+
provisionee_beacon_check(uuid, BT_MESH_PROV_GATT);
355+
356+
if (!prov_to_use || prov_to_use == BT_MESH_PROV_GATT) {
357+
provision(uuid, BT_MESH_PROV_GATT);
358+
}
303359
}
304360

305361
static void prov_complete(uint16_t net_idx, uint16_t addr)
@@ -324,6 +380,8 @@ static void prov_node_added(uint16_t net_idx, uint8_t uuid[16], uint16_t addr,
324380
{
325381
LOG_INF("Device 0x%04x provisioned", prov_addr);
326382
current_dev_addr = prov_addr++;
383+
prov_started_time_ms = 0;
384+
memset(prov_uuid, 0, 16);
327385
k_sem_give(&prov_sem);
328386
}
329387

@@ -340,6 +398,7 @@ static void prov_reset(void)
340398

341399
static bt_mesh_input_action_t gact;
342400
static uint8_t gsize;
401+
static bool oob_wait_unprov_int;
343402
static int input(bt_mesh_input_action_t act, uint8_t size)
344403
{
345404
/* The test system requests the input OOB data earlier than
@@ -350,7 +409,9 @@ static int input(bt_mesh_input_action_t act, uint8_t size)
350409
gact = act;
351410
gsize = size;
352411

353-
k_work_reschedule(&oob_timer, K_SECONDS(1));
412+
k_work_reschedule(&oob_timer, oob_wait_unprov_int
413+
? K_SECONDS(CONFIG_BT_MESH_UNPROV_BEACON_INT + 1)
414+
: K_SECONDS(1));
354415

355416
return 0;
356417
}
@@ -734,6 +795,49 @@ static void test_provisioner_oob_auth_no_oob_public_key(void)
734795
PASS();
735796
}
736797

798+
static void test_provisioner_pb_cancel(void)
799+
{
800+
k_sem_init(&prov_sem, 0, 1);
801+
802+
bt_mesh_device_setup(&prov, &comp);
803+
804+
ASSERT_OK(bt_mesh_cdb_create(test_net_key));
805+
806+
ASSERT_OK(bt_mesh_provision(test_net_key, 0, 0, 0, 0x0001, dev_key));
807+
808+
prov.static_val = 0;
809+
prov.static_val_len = 0;
810+
prov.output_size = 0;
811+
prov.output_actions = 0;
812+
prov.input_size = 8;
813+
prov.input_actions = BT_MESH_ENTER_NUMBER;
814+
815+
ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(20)));
816+
817+
PASS();
818+
}
819+
820+
static void test_device_pb_cancel(void)
821+
{
822+
oob_wait_unprov_int = true;
823+
k_sem_init(&prov_sem, 0, 1);
824+
825+
bt_mesh_device_setup(&prov, &comp);
826+
827+
prov.static_val = 0;
828+
prov.static_val_len = 0;
829+
prov.output_size = 0;
830+
prov.output_actions = 0;
831+
prov.input_size = 8;
832+
prov.input_actions = BT_MESH_ENTER_NUMBER;
833+
834+
ASSERT_OK(bt_mesh_prov_enable(prov_bearer));
835+
836+
ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(20)));
837+
838+
PASS();
839+
}
840+
737841
/** @brief Verify that the provisioner can provision multiple devices in a row
738842
*/
739843
static void test_provisioner_multi(void)
@@ -1798,6 +1902,7 @@ static const struct bst_test_instance test_connect[] = {
17981902
TEST_CASE_WBACKCHANNEL(device, oob_public_key,
17991903
"Device: provisioning use oob public key"),
18001904
TEST_CASE(device, reprovision, "Device: provisioning, reprovision"),
1905+
TEST_CASE_WBACKCHANNEL(device, pb_cancel, "Device: provisioning, cancel prov bearers."),
18011906
#if IS_RPR_PRESENT
18021907
TEST_CASE(device, pb_remote_server_unproved,
18031908
"Device: used for remote provisioning, starts unprovisioned"),
@@ -1828,6 +1933,8 @@ static const struct bst_test_instance test_connect[] = {
18281933
TEST_CASE(
18291934
provisioner, reprovision,
18301935
"Provisioner: provisioning, resetting and reprovisioning multiple times."),
1936+
TEST_CASE_WBACKCHANNEL(
1937+
provisioner, pb_cancel, "Provisioner: provisioning, cancel prov bearers."),
18311938
#if IS_RPR_PRESENT
18321939
TEST_CASE(provisioner, pb_remote_client_reprovision,
18331940
"Provisioner: pb-remote provisioning, resetting and reprov-ing multiple times."),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2025 Nordic Semiconductor
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh
6+
7+
# Test that PB-ADV and PB-GATT unprovisioned beacons are cancelled when a provisioning link is
8+
# opened.
9+
# Test procedure:
10+
# 1. The provisioner self-provisions and starts scanning for unprovisioned devices.
11+
# 2. The provisionee enables both the PB-ADV and PB-GATT bearers.
12+
# 3. The provisioner finds the unprovisioned device and provisions it with OOB authentication.
13+
# The OOB authentication is delayed by CONFIG_BT_MESH_UNPROV_BEACON_INT + 1 seconds to ensure
14+
# that the provisioner has time observe that PB-ADV and PB-GATT beacons are cancelled.
15+
# 4. The provisioning procedure completes.
16+
17+
overlay=overlay_gatt_conf_overlay_psa_conf
18+
RunTest mesh_prov_pb_cancel_adv \
19+
prov_provisioner_pb_cancel \
20+
prov_device_pb_cancel \
21+
-- -argstest prov-bearer=3 prov-to-use=1
22+
23+
overlay=overlay_gatt_conf_overlay_psa_conf
24+
RunTest mesh_prov_pb_cancel_gatt \
25+
prov_provisioner_pb_cancel \
26+
prov_device_pb_cancel \
27+
-- -argstest prov-bearer=3 prov-to-use=2

0 commit comments

Comments
 (0)