diff --git a/subsys/bluetooth/mesh/adv_ext.c b/subsys/bluetooth/mesh/adv_ext.c index 05593a3b60e..02dffc35413 100644 --- a/subsys/bluetooth/mesh/adv_ext.c +++ b/subsys/bluetooth/mesh/adv_ext.c @@ -342,12 +342,17 @@ static void start_proxy_sol_or_proxy_adv(struct bt_mesh_ext_adv *ext_adv) } } - if (IS_ENABLED(CONFIG_BT_MESH_GATT_SERVER) && - !atomic_test_and_set_bit(ext_adv->flags, ADV_FLAG_PROXY)) { - if (bt_mesh_adv_gatt_send()) { - atomic_clear_bit(ext_adv->flags, ADV_FLAG_PROXY); + if (IS_ENABLED(CONFIG_BT_MESH_GATT_SERVER)) { + if (stop_proxy_adv(ext_adv)) { return; } + + if (!atomic_test_and_set_bit(ext_adv->flags, ADV_FLAG_PROXY)) { + if (bt_mesh_adv_gatt_send()) { + atomic_clear_bit(ext_adv->flags, ADV_FLAG_PROXY); + return; + } + } } } diff --git a/subsys/bluetooth/mesh/main.c b/subsys/bluetooth/mesh/main.c index c9b6a283c08..16e66532058 100644 --- a/subsys/bluetooth/mesh/main.c +++ b/subsys/bluetooth/mesh/main.c @@ -62,7 +62,7 @@ int bt_mesh_provision(const uint8_t net_key[16], uint16_t net_idx, LOG_INF("Primary Element: 0x%04x", addr); LOG_DBG("net_idx 0x%04x flags 0x%02x iv_index 0x%04x", net_idx, flags, iv_index); - if (atomic_test_and_set_bit(bt_mesh.flags, BT_MESH_VALID)) { + if (atomic_test_bit(bt_mesh.flags, BT_MESH_VALID)) { return -EALREADY; } @@ -74,14 +74,12 @@ int bt_mesh_provision(const uint8_t net_key[16], uint16_t net_idx, comp = bt_mesh_comp_get(); if (comp == NULL) { LOG_ERR("Failed to get node composition"); - atomic_clear_bit(bt_mesh.flags, BT_MESH_VALID); return -EINVAL; } subnet = bt_mesh_cdb_subnet_get(net_idx); if (!subnet) { LOG_ERR("No subnet with idx %d", net_idx); - atomic_clear_bit(bt_mesh.flags, BT_MESH_VALID); return -ENOENT; } @@ -90,7 +88,6 @@ int bt_mesh_provision(const uint8_t net_key[16], uint16_t net_idx, comp->elem_count, net_idx); if (node == NULL) { LOG_ERR("Failed to allocate database node"); - atomic_clear_bit(bt_mesh.flags, BT_MESH_VALID); return -ENOMEM; } @@ -108,9 +105,8 @@ int bt_mesh_provision(const uint8_t net_key[16], uint16_t net_idx, net_key); if (err) { LOG_ERR("Failed to import cdb network key"); - goto end; + goto error_exit; } - bt_mesh_cdb_subnet_store(subnet); addr = node->addr; bt_mesh_cdb_iv_update(iv_index, BT_MESH_IV_UPDATE(flags)); @@ -118,32 +114,34 @@ int bt_mesh_provision(const uint8_t net_key[16], uint16_t net_idx, err = bt_mesh_cdb_node_key_import(node, dev_key); if (err) { LOG_ERR("Failed to import cdb device key"); - goto end; - } - - if (IS_ENABLED(CONFIG_BT_SETTINGS)) { - bt_mesh_cdb_node_store(node); + goto error_exit; } } err = bt_mesh_key_import(BT_MESH_KEY_TYPE_DEV, dev_key, &mesh_dev_key); if (err) { LOG_ERR("Failed to import device key"); - goto end; + goto error_exit; } is_dev_key_valid = true; err = bt_mesh_key_import(BT_MESH_KEY_TYPE_NET, net_key, &mesh_net_key); if (err) { LOG_ERR("Failed to import network key"); - goto end; + goto error_exit; } is_net_key_valid = true; err = bt_mesh_net_create(net_idx, flags, &mesh_net_key, iv_index); if (err) { - atomic_clear_bit(bt_mesh.flags, BT_MESH_VALID); - goto end; + LOG_ERR("Failed to create network"); + goto error_exit; + } + + if (IS_ENABLED(CONFIG_BT_MESH_CDB) && + atomic_test_bit(bt_mesh_cdb.flags, BT_MESH_CDB_VALID)) { + bt_mesh_cdb_subnet_store(subnet); + bt_mesh_cdb_node_store(node); } bt_mesh_net_settings_commit(); @@ -163,18 +161,21 @@ int bt_mesh_provision(const uint8_t net_key[16], uint16_t net_idx, bt_mesh_net_store(); } + atomic_set_bit(bt_mesh.flags, BT_MESH_VALID); bt_mesh_start(); -end: - if (err && node != NULL && IS_ENABLED(CONFIG_BT_MESH_CDB)) { - bt_mesh_cdb_node_del(node, true); + return 0; + +error_exit: + if (node != NULL && IS_ENABLED(CONFIG_BT_MESH_CDB)) { + bt_mesh_cdb_node_del(node, false); } - if (err && is_dev_key_valid) { + if (is_dev_key_valid) { bt_mesh_key_destroy(&mesh_dev_key); } - if (err && is_net_key_valid) { + if (is_net_key_valid) { bt_mesh_key_destroy(&mesh_net_key); } @@ -236,6 +237,8 @@ void bt_mesh_dev_key_cand_remove(void) } LOG_DBG(""); + bt_mesh_key_destroy(&bt_mesh.dev_key_cand); + memset(&bt_mesh.dev_key_cand, 0, sizeof(struct bt_mesh_key)); if (IS_ENABLED(CONFIG_BT_SETTINGS)) { bt_mesh_net_dev_key_cand_store(); @@ -397,6 +400,10 @@ void bt_mesh_reset(void) bt_mesh_key_destroy(&bt_mesh.dev_key); memset(&bt_mesh.dev_key, 0, sizeof(bt_mesh.dev_key)); + if (IS_ENABLED(CONFIG_BT_MESH_RPR_SRV)) { + bt_mesh_dev_key_cand_remove(); + } + bt_mesh_beacon_disable(); bt_mesh_comp_unprovision(); diff --git a/subsys/bluetooth/mesh/pb_adv.c b/subsys/bluetooth/mesh/pb_adv.c index 86f20497704..c6b3f778165 100644 --- a/subsys/bluetooth/mesh/pb_adv.c +++ b/subsys/bluetooth/mesh/pb_adv.c @@ -482,14 +482,16 @@ static void gen_prov_cont(struct prov_rx *rx, struct net_buf_simple *buf) { uint8_t seg = CONT_SEG_INDEX(rx->gpc); - if (link.tx.adv[0]) { - LOG_DBG("Ongoing tx transaction has not been completed yet"); - return; - } - LOG_DBG("len %u, seg_index %u", buf->len, seg); + /* When link.rx.seg is zero for a valid link.rx.id, this means that transaction + * has already been received. The other device probably missed the Transaction + * Acknowledgment PDU, so we need to resend it regardless of the active transmission. + */ if (!link.rx.seg && link.rx.id == rx->xact_id) { + /* Send ack if another ack is NOT pending for transmission. Otherwise, skip sending + * this ack for now. + */ if (!ack_pending()) { LOG_DBG("Resending ack"); gen_prov_ack_send(rx->xact_id); @@ -498,6 +500,11 @@ static void gen_prov_cont(struct prov_rx *rx, struct net_buf_simple *buf) return; } + if (link.tx.adv[0]) { + LOG_DBG("Ongoing tx transaction has not been completed yet"); + return; + } + if (!link.rx.seg && next_transaction_id(link.rx.id) == rx->xact_id) { LOG_DBG("Start segment lost"); @@ -575,21 +582,28 @@ static void gen_prov_start(struct prov_rx *rx, struct net_buf_simple *buf) { uint8_t seg = SEG_NVAL; + /* When link.rx.seg is zero for a valid link.rx.id, this means that transaction + * has already been received. The other device probably missed the Transaction + * Acknowledgment PDU, so we need to resend it regardless of the active transmission. + */ + if (rx->xact_id == link.rx.id && !link.rx.seg) { + /* Send ack if another ack is NOT pending for transmission. Otherwise, skip sending + * this ack for now. + */ + if (!ack_pending()) { + LOG_DBG("Resending ack"); + gen_prov_ack_send(rx->xact_id); + } + + return; + } + if (link.tx.adv[0]) { LOG_DBG("Ongoing tx transaction has not been completed yet"); return; } if (rx->xact_id == link.rx.id) { - if (!link.rx.seg) { - if (!ack_pending()) { - LOG_DBG("Resending ack"); - gen_prov_ack_send(rx->xact_id); - } - - return; - } - if (!(link.rx.seg & BIT(0))) { LOG_DBG("Ignoring duplicate segment"); return; @@ -1057,6 +1071,12 @@ static int prov_link_accept(const struct prov_bearer_cb *cb, void *cb_data) return 0; } +static void prov_link_cancel(void) +{ + bt_mesh_beacon_disable(); + bt_mesh_scan_disable(); +} + static void prov_link_close(enum prov_bearer_link_status status) { int err; @@ -1095,6 +1115,7 @@ const struct prov_bearer bt_mesh_pb_adv = { .type = BT_MESH_PROV_ADV, .link_open = prov_link_open, .link_accept = prov_link_accept, + .link_cancel = prov_link_cancel, .link_close = prov_link_close, .send = prov_send_adv, .clear_tx = prov_clear_tx, diff --git a/subsys/bluetooth/mesh/pb_gatt.c b/subsys/bluetooth/mesh/pb_gatt.c index 849914f4b5f..44b77f53f3e 100644 --- a/subsys/bluetooth/mesh/pb_gatt.c +++ b/subsys/bluetooth/mesh/pb_gatt.c @@ -198,6 +198,11 @@ static int link_accept(const struct prov_bearer_cb *cb, void *cb_data) return 0; } + +static void link_cancel(void) +{ + (void)bt_mesh_pb_gatt_srv_disable(); +} #endif static void buf_send_end(struct bt_conn *conn, void *user_data) @@ -246,6 +251,7 @@ const struct prov_bearer bt_mesh_pb_gatt = { #endif #if defined(CONFIG_BT_MESH_PB_GATT) .link_accept = link_accept, + .link_cancel = link_cancel, #endif .send = buf_send, .clear_tx = clear_tx, diff --git a/subsys/bluetooth/mesh/prov_bearer.h b/subsys/bluetooth/mesh/prov_bearer.h index 45885226dcd..fd6aa89e34e 100644 --- a/subsys/bluetooth/mesh/prov_bearer.h +++ b/subsys/bluetooth/mesh/prov_bearer.h @@ -76,6 +76,12 @@ struct prov_bearer { */ int (*link_accept)(const struct prov_bearer_cb *cb, void *cb_data); + /** @brief Disable link establishment as a provisionee. + * + * Stops accepting link open messages and sending unprovisioned beacons. + */ + void (*link_cancel)(void); + /** @brief Send a packet on an established link. * * @param buf Payload buffer. Requires @ref diff --git a/subsys/bluetooth/mesh/provisionee.c b/subsys/bluetooth/mesh/provisionee.c index 76581727455..59cc20fbd5a 100644 --- a/subsys/bluetooth/mesh/provisionee.c +++ b/subsys/bluetooth/mesh/provisionee.c @@ -468,12 +468,24 @@ static void prov_confirm(const uint8_t *data) send_confirm(); } -static inline bool is_pb_gatt(void) +static bool is_pb_gatt(void) { return bt_mesh_prov_link.bearer && bt_mesh_prov_link.bearer->type == BT_MESH_PROV_GATT; } +static bool is_pb_adv(void) +{ + return bt_mesh_prov_link.bearer && + bt_mesh_prov_link.bearer->type == BT_MESH_PROV_ADV; +} + +static bool is_pb_remote(void) +{ + return bt_mesh_prov_link.bearer && + bt_mesh_prov_link.bearer->type == BT_MESH_PROV_REMOTE; +} + static bool refresh_is_valid(const uint8_t *netkey, uint16_t net_idx, uint32_t iv_index) { @@ -641,6 +653,8 @@ static void local_input_complete(void) } } +static bt_mesh_prov_bearer_t active_bearers; + static void prov_link_closed(enum prov_bearer_link_status status) { if (IS_ENABLED(CONFIG_BT_MESH_RPR_SRV) && @@ -657,6 +671,28 @@ static void prov_link_closed(enum prov_bearer_link_status status) } bt_mesh_prov_reset_state(); + + /* Restore provisioning bearers stopped in prov_link_opened. If the device was provisioned, + * only re-enable the PB-Remote bearer. + */ + if (IS_ENABLED(CONFIG_BT_MESH_RPR_SRV) && !is_pb_remote() && + (active_bearers & BT_MESH_PROV_REMOTE)) { + pb_remote_srv.link_accept(bt_mesh_prov_bearer_cb_get(), NULL); + } + + if (bt_mesh_is_provisioned()) { + return; + } + + if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT) && !is_pb_gatt() && + (active_bearers & BT_MESH_PROV_GATT)) { + bt_mesh_pb_gatt.link_accept(bt_mesh_prov_bearer_cb_get(), NULL); + } + + if (IS_ENABLED(CONFIG_BT_MESH_PB_ADV) && !is_pb_adv() && + (active_bearers & BT_MESH_PROV_ADV)) { + bt_mesh_pb_adv.link_accept(bt_mesh_prov_bearer_cb_get(), NULL); + } } static void prov_link_opened(void) @@ -665,6 +701,22 @@ static void prov_link_opened(void) if (IS_ENABLED(CONFIG_BT_MESH_RPR_SRV) && bt_mesh_is_provisioned()) { atomic_set_bit(bt_mesh_prov_link.flags, REPROVISION); } + + /* Stop other provisioning bearers for the duration of the prov link. */ + if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT) && is_pb_adv() && + (active_bearers & BT_MESH_PROV_GATT)) { + bt_mesh_pb_gatt.link_cancel(); + } + + if (IS_ENABLED(CONFIG_BT_MESH_PB_ADV) && is_pb_gatt() && + (active_bearers & BT_MESH_PROV_ADV)) { + bt_mesh_pb_adv.link_cancel(); + } + + if (IS_ENABLED(CONFIG_BT_MESH_RPR_SRV) && !is_pb_remote() && + (active_bearers & BT_MESH_PROV_REMOTE)) { + pb_remote_srv.link_cancel(); + } } static const struct bt_mesh_prov_role role_device = { @@ -717,6 +769,7 @@ int bt_mesh_prov_enable(bt_mesh_prov_bearer_t bearers) role_init: bt_mesh_prov_link.role = &role_device; + active_bearers |= bearers; return 0; } @@ -733,14 +786,20 @@ int bt_mesh_prov_disable(bt_mesh_prov_bearer_t bearers) if (IS_ENABLED(CONFIG_BT_MESH_PB_ADV) && (bearers & BT_MESH_PROV_ADV)) { - bt_mesh_beacon_disable(); - bt_mesh_scan_disable(); + bt_mesh_pb_adv.link_cancel(); } if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT) && (bearers & BT_MESH_PROV_GATT)) { - (void)bt_mesh_pb_gatt_srv_disable(); + bt_mesh_pb_gatt.link_cancel(); + } + + if (IS_ENABLED(CONFIG_BT_MESH_RPR_SRV) && + (bearers & BT_MESH_PROV_REMOTE)) { + pb_remote_srv.link_cancel(); } + active_bearers &= ~bearers; + return 0; } diff --git a/subsys/bluetooth/mesh/proxy_srv.c b/subsys/bluetooth/mesh/proxy_srv.c index 8863a5ce52f..7d16a42a86e 100644 --- a/subsys/bluetooth/mesh/proxy_srv.c +++ b/subsys/bluetooth/mesh/proxy_srv.c @@ -983,6 +983,8 @@ int bt_mesh_proxy_gatt_enable(void) } } + bt_mesh_adv_gatt_update(); + return 0; } diff --git a/subsys/bluetooth/mesh/rpr_srv.c b/subsys/bluetooth/mesh/rpr_srv.c index ed8d87f3c04..96d94bae15a 100644 --- a/subsys/bluetooth/mesh/rpr_srv.c +++ b/subsys/bluetooth/mesh/rpr_srv.c @@ -1359,6 +1359,12 @@ static int node_refresh_link_accept(const struct prov_bearer_cb *cb, return 0; } +static void node_refresh_link_cancel(void) +{ + srv.refresh.cb = NULL; + srv.refresh.cb_data = NULL; +} + static void node_refresh_tx_complete(int err, void *cb_data) { if (err) { @@ -1408,6 +1414,7 @@ const struct prov_bearer pb_remote_srv = { .type = BT_MESH_PROV_REMOTE, .link_accept = node_refresh_link_accept, + .link_cancel = node_refresh_link_cancel, .send = node_refresh_buf_send, .clear_tx = node_refresh_clear_tx, }; diff --git a/subsys/bluetooth/mesh/settings.c b/subsys/bluetooth/mesh/settings.c index f02672e6d66..d746baf1258 100644 --- a/subsys/bluetooth/mesh/settings.c +++ b/subsys/bluetooth/mesh/settings.c @@ -104,10 +104,6 @@ static int mesh_commit(void) return 0; } - if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT)) { - (void)bt_mesh_pb_gatt_srv_disable(); - } - bt_mesh_net_settings_commit(); bt_mesh_model_settings_commit(); diff --git a/tests/bsim/bluetooth/mesh/src/test_provision.c b/tests/bsim/bluetooth/mesh/src/test_provision.c index 126b63f6b81..b98fe1d89ad 100644 --- a/tests/bsim/bluetooth/mesh/src/test_provision.c +++ b/tests/bsim/bluetooth/mesh/src/test_provision.c @@ -38,6 +38,8 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #define WAIT_TIME 120 /*seconds*/ #define IS_RPR_PRESENT (CONFIG_BT_MESH_RPR_SRV && CONFIG_BT_MESH_RPR_CLI) #define IMPOSTER_MODEL_ID 0xe000 +/* Rough estimate of the time it should take the provisionee to stop sending unprov beacons. */ +#define PROV_DELTA_THRESH_MS 100 enum test_flags { IS_PROVISIONER, @@ -97,6 +99,7 @@ static uint32_t link_close_timestamp; /* Set prov_bearer to non-zero invalid value. */ static bt_mesh_prov_bearer_t prov_bearer = 0xF8; +static bt_mesh_prov_bearer_t prov_to_use; static void test_args_parse(int argc, char *argv[]) { @@ -104,10 +107,18 @@ static void test_args_parse(int argc, char *argv[]) { .dest = &prov_bearer, .type = 'i', - .name = "{invalid, PB-ADV, PB-GATT}", - .option = "prov-brearer", + .name = "{invalid, PB-ADV, PB-GATT, (PB-ADV | PB-GATT)}", + .option = "prov-bearer", .descript = "Provisioning bearer that is to be used." }, + { + .dest = &prov_to_use, + .type = 'i', + .name = "{PB-ADV, PB-GATT}", + .option = "prov-to-use", + .descript = "Provisioning bearer that is to be used in the case that " + "multiple provisioning bearers are enabled in prov_bearer." + }, }; bs_args_parse_all_cmd_line(argc, argv, args_struct); @@ -275,6 +286,42 @@ static void test_terminate(void) } } +static uint64_t prov_started_time_ms; +static uint8_t prov_uuid[16]; + +static void provision(uint8_t uuid[16], bt_mesh_prov_bearer_t bearer) +{ + int err; + + switch (bearer) { + case BT_MESH_PROV_ADV: + err = bt_mesh_provision_adv(uuid, 0, prov_addr, 0); + break; + case BT_MESH_PROV_GATT: + err = bt_mesh_provision_gatt(uuid, 0, prov_addr, 0); + break; + default: + err = -ENOTSUP; + } + + if (!err) { + LOG_INF("Provisioning over %s started.", + bearer == BT_MESH_PROV_ADV ? "PB-ADV" : "PB-GATT"); + prov_started_time_ms = k_uptime_get(); + memcpy(prov_uuid, uuid, 16); + } +} + +static void provisionee_beacon_check(uint8_t uuid[16], bt_mesh_prov_bearer_t bearer) +{ + if (memcmp(uuid, prov_uuid, 16) == 0) { + ASSERT_FALSE_MSG((prov_started_time_ms && + (k_uptime_delta(&prov_started_time_ms) > PROV_DELTA_THRESH_MS)), + "Received %s beacon from provisionee after provisioning started.", + bearer == BT_MESH_PROV_ADV ? "PB-ADV" : "PB-GATT"); + } +} + static void unprovisioned_beacon(uint8_t uuid[16], bt_mesh_prov_oob_info_t oob_info, uint32_t *uri_hash) @@ -286,7 +333,12 @@ static void unprovisioned_beacon(uint8_t uuid[16], if (uuid_to_provision && memcmp(uuid, uuid_to_provision, 16)) { return; } - bt_mesh_provision_adv(uuid, 0, prov_addr, 0); + + provisionee_beacon_check(uuid, BT_MESH_PROV_ADV); + + if (!prov_to_use || prov_to_use == BT_MESH_PROV_ADV) { + provision(uuid, BT_MESH_PROV_ADV); + } } 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 return; } - bt_mesh_provision_gatt(uuid, 0, prov_addr, 0); + provisionee_beacon_check(uuid, BT_MESH_PROV_GATT); + + if (!prov_to_use || prov_to_use == BT_MESH_PROV_GATT) { + provision(uuid, BT_MESH_PROV_GATT); + } } 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, { LOG_INF("Device 0x%04x provisioned", prov_addr); current_dev_addr = prov_addr++; + prov_started_time_ms = 0; + memset(prov_uuid, 0, 16); k_sem_give(&prov_sem); } @@ -340,6 +398,7 @@ static void prov_reset(void) static bt_mesh_input_action_t gact; static uint8_t gsize; +static bool oob_wait_unprov_int; static int input(bt_mesh_input_action_t act, uint8_t size) { /* 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) gact = act; gsize = size; - k_work_reschedule(&oob_timer, K_SECONDS(1)); + k_work_reschedule(&oob_timer, oob_wait_unprov_int + ? K_SECONDS(CONFIG_BT_MESH_UNPROV_BEACON_INT + 1) + : K_SECONDS(1)); return 0; } @@ -734,6 +795,49 @@ static void test_provisioner_oob_auth_no_oob_public_key(void) PASS(); } +static void test_provisioner_pb_cancel(void) +{ + k_sem_init(&prov_sem, 0, 1); + + bt_mesh_device_setup(&prov, &comp); + + ASSERT_OK(bt_mesh_cdb_create(test_net_key)); + + ASSERT_OK(bt_mesh_provision(test_net_key, 0, 0, 0, 0x0001, dev_key)); + + prov.static_val = 0; + prov.static_val_len = 0; + prov.output_size = 0; + prov.output_actions = 0; + prov.input_size = 8; + prov.input_actions = BT_MESH_ENTER_NUMBER; + + ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(20))); + + PASS(); +} + +static void test_device_pb_cancel(void) +{ + oob_wait_unprov_int = true; + k_sem_init(&prov_sem, 0, 1); + + bt_mesh_device_setup(&prov, &comp); + + prov.static_val = 0; + prov.static_val_len = 0; + prov.output_size = 0; + prov.output_actions = 0; + prov.input_size = 8; + prov.input_actions = BT_MESH_ENTER_NUMBER; + + ASSERT_OK(bt_mesh_prov_enable(prov_bearer)); + + ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(20))); + + PASS(); +} + /** @brief Verify that the provisioner can provision multiple devices in a row */ static void test_provisioner_multi(void) @@ -1798,6 +1902,7 @@ static const struct bst_test_instance test_connect[] = { TEST_CASE_WBACKCHANNEL(device, oob_public_key, "Device: provisioning use oob public key"), TEST_CASE(device, reprovision, "Device: provisioning, reprovision"), + TEST_CASE_WBACKCHANNEL(device, pb_cancel, "Device: provisioning, cancel prov bearers."), #if IS_RPR_PRESENT TEST_CASE(device, pb_remote_server_unproved, "Device: used for remote provisioning, starts unprovisioned"), @@ -1828,6 +1933,8 @@ static const struct bst_test_instance test_connect[] = { TEST_CASE( provisioner, reprovision, "Provisioner: provisioning, resetting and reprovisioning multiple times."), + TEST_CASE_WBACKCHANNEL( + provisioner, pb_cancel, "Provisioner: provisioning, cancel prov bearers."), #if IS_RPR_PRESENT TEST_CASE(provisioner, pb_remote_client_reprovision, "Provisioner: pb-remote provisioning, resetting and reprov-ing multiple times."), diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_cancel.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_cancel.sh new file mode 100755 index 00000000000..df2723a2270 --- /dev/null +++ b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_cancel.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# Copyright 2025 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh + +# Test that PB-ADV and PB-GATT unprovisioned beacons are cancelled when a provisioning link is +# opened. +# Test procedure: +# 1. The provisioner self-provisions and starts scanning for unprovisioned devices. +# 2. The provisionee enables both the PB-ADV and PB-GATT bearers. +# 3. The provisioner finds the unprovisioned device and provisions it with OOB authentication. +# The OOB authentication is delayed by CONFIG_BT_MESH_UNPROV_BEACON_INT + 1 seconds to ensure +# that the provisioner has time observe that PB-ADV and PB-GATT beacons are cancelled. +# 4. The provisioning procedure completes. + +overlay=overlay_gatt_conf_overlay_psa_conf +RunTest mesh_prov_pb_cancel_adv \ + prov_provisioner_pb_cancel \ + prov_device_pb_cancel \ + -- -argstest prov-bearer=3 prov-to-use=1 + +overlay=overlay_gatt_conf_overlay_psa_conf +RunTest mesh_prov_pb_cancel_gatt \ + prov_provisioner_pb_cancel \ + prov_device_pb_cancel \ + -- -argstest prov-bearer=3 prov-to-use=2 diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_parallel.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_parallel.sh index 815df506d5f..536e15b9dc4 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_parallel.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_parallel.sh @@ -16,7 +16,7 @@ RunTest mesh_prov_pb_remote_parallel \ prov_device_pb_remote_server_unproved \ prov_device_no_oob \ prov_device_no_oob \ - -- -argstest prov-brearer=1 + -- -argstest prov-bearer=1 overlay=overlay_psa_conf RunTest mesh_prov_pb_remote_parallel_psa \ @@ -24,4 +24,4 @@ RunTest mesh_prov_pb_remote_parallel_psa \ prov_device_pb_remote_server_unproved \ prov_device_no_oob \ prov_device_no_oob \ - -- -argstest prov-brearer=1 + -- -argstest prov-bearer=1 diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_reprovision.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_reprovision.sh index 1e5da310bd3..e2a98272955 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_reprovision.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_reprovision.sh @@ -16,11 +16,11 @@ RunTest mesh_prov_pb_remote_reprovision \ prov_provisioner_pb_remote_client_reprovision \ prov_device_pb_remote_server_unproved \ prov_device_reprovision \ - -- -argstest prov-brearer=1 + -- -argstest prov-bearer=1 overlay=overlay_psa_conf RunTest mesh_prov_pb_remote_reprovision_psa \ prov_provisioner_pb_remote_client_reprovision \ prov_device_pb_remote_server_unproved \ prov_device_reprovision \ - -- -argstest prov-brearer=1 + -- -argstest prov-bearer=1 diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_timeout.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_timeout.sh index b332b1987ad..74d2b3fff8b 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_timeout.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/provision/pb_remote_timeout.sh @@ -27,10 +27,10 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh RunTest mesh_prov_pb_remote_provisioning_timeout \ prov_provisioner_pb_remote_client_provision_timeout \ prov_device_pb_remote_server_unproved_unresponsive \ - prov_device_unresponsive -- -argstest prov-brearer=1 + prov_device_unresponsive -- -argstest prov-bearer=1 overlay=overlay_psa_conf RunTest mesh_prov_pb_remote_provisioning_timeout_psa \ prov_provisioner_pb_remote_client_provision_timeout \ prov_device_pb_remote_server_unproved_unresponsive \ - prov_device_unresponsive -- -argstest prov-brearer=1 + prov_device_unresponsive -- -argstest prov-bearer=1 diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/provision/prov_multi.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/prov_multi.sh index bed577add24..f6ac20c38f0 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/provision/prov_multi.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/provision/prov_multi.sh @@ -12,7 +12,7 @@ RunTest mesh_prov_pb_adv_multi \ prov_device_no_oob \ prov_device_no_oob \ prov_device_no_oob \ - -- -argstest prov-brearer=1 + -- -argstest prov-bearer=1 overlay=overlay_gatt_conf_overlay_psa_conf RunTest mesh_prov_pb_gatt_multi \ @@ -20,7 +20,7 @@ RunTest mesh_prov_pb_gatt_multi \ prov_device_no_oob \ prov_device_no_oob \ prov_device_no_oob \ - -- -argstest prov-brearer=2 + -- -argstest prov-bearer=2 overlay=overlay_psa_conf RunTest mesh_prov_pb_adv_multi_psa \ @@ -28,4 +28,4 @@ RunTest mesh_prov_pb_adv_multi_psa \ prov_device_no_oob \ prov_device_no_oob \ prov_device_no_oob \ - -- -argstest prov-brearer=1 + -- -argstest prov-bearer=1 diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/provision/prov_no_oob.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/prov_no_oob.sh index 4f633b91c2c..c5e4c8d1649 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/provision/prov_no_oob.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/provision/prov_no_oob.sh @@ -7,16 +7,16 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh RunTest mesh_prov_pb_adv_on_oob \ prov_device_no_oob \ prov_provisioner_no_oob \ - -- -argstest prov-brearer=1 + -- -argstest prov-bearer=1 overlay=overlay_gatt_conf_overlay_psa_conf RunTest mesh_prov_pb_gatt_on_oob \ prov_device_no_oob \ prov_provisioner_no_oob \ - -- -argstest prov-brearer=2 + -- -argstest prov-bearer=2 overlay=overlay_psa_conf RunTest mesh_prov_pb_adv_on_oob_psa \ prov_device_no_oob \ prov_provisioner_no_oob \ - -- -argstest prov-brearer=1 + -- -argstest prov-bearer=1 diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/provision/prov_oob_auth_ib_pk.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/prov_oob_auth_ib_pk.sh index e53c6b5f254..342433a6db9 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/provision/prov_oob_auth_ib_pk.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/provision/prov_oob_auth_ib_pk.sh @@ -7,14 +7,14 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # Test provisioning with OOB authentication and with inband public key RunTest mesh_prov_pb_adv_oob_auth \ prov_device_oob_auth prov_provisioner_oob_auth \ - -- -argstest prov-brearer=1 + -- -argstest prov-bearer=1 overlay=overlay_gatt_conf_overlay_psa_conf RunTest mesh_prov_pb_gatt_oob_auth \ prov_device_oob_auth prov_provisioner_oob_auth \ - -- -argstest prov-brearer=2 + -- -argstest prov-bearer=2 overlay=overlay_psa_conf RunTest mesh_prov_pb_adv_oob_auth_psa \ prov_device_oob_auth prov_provisioner_oob_auth \ - -- -argstest prov-brearer=1 + -- -argstest prov-bearer=1 diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/provision/prov_oob_auth_ignore_oob_pk.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/prov_oob_auth_ignore_oob_pk.sh index 7ac6b5f4d75..ea746e75e99 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/provision/prov_oob_auth_ignore_oob_pk.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/provision/prov_oob_auth_ignore_oob_pk.sh @@ -8,14 +8,14 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # but provisioner doesn't have OOB public key RunTest mesh_prov_pb_adv_device_w_oob_pk_prvnr_wt_pk \ prov_device_oob_public_key prov_provisioner_oob_auth_no_oob_public_key \ - -- -argstest prov-brearer=1 + -- -argstest prov-bearer=1 overlay=overlay_gatt_conf_overlay_psa_conf RunTest mesh_prov_pb_gatt_device_w_oob_pk_prvnr_wt_pk \ prov_device_oob_public_key prov_provisioner_oob_auth_no_oob_public_key \ - -- -argstest prov-brearer=2 + -- -argstest prov-bearer=2 overlay=overlay_psa_conf RunTest mesh_prov_pb_adv_device_w_oob_pk_prvnr_wt_pk_psa \ prov_device_oob_public_key prov_provisioner_oob_auth_no_oob_public_key \ - -- -argstest prov-brearer=1 + -- -argstest prov-bearer=1 diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/provision/prov_oob_auth_oob_pk.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/prov_oob_auth_oob_pk.sh index 90375f81a50..78b9a25d99a 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/provision/prov_oob_auth_oob_pk.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/provision/prov_oob_auth_oob_pk.sh @@ -7,14 +7,14 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh # Test provisioning with OOB authentication and with OOB public key RunTest mesh_prov_pb_adv_oob_public_key \ prov_device_oob_public_key prov_provisioner_oob_public_key \ - -- -argstest prov-brearer=1 + -- -argstest prov-bearer=1 overlay=overlay_gatt_conf_overlay_psa_conf RunTest mesh_prov_pb_gatt_oob_public_key \ prov_device_oob_public_key prov_provisioner_oob_public_key \ - -- -argstest prov-brearer=2 + -- -argstest prov-bearer=2 overlay=overlay_psa_conf RunTest mesh_prov_pb_adv_oob_public_key_psa \ prov_device_oob_public_key prov_provisioner_oob_public_key \ - -- -argstest prov-brearer=1 + -- -argstest prov-bearer=1 diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/provision/prov_reprovision.sh b/tests/bsim/bluetooth/mesh/tests_scripts/provision/prov_reprovision.sh index 0143ef20c45..d629f631f4d 100755 --- a/tests/bsim/bluetooth/mesh/tests_scripts/provision/prov_reprovision.sh +++ b/tests/bsim/bluetooth/mesh/tests_scripts/provision/prov_reprovision.sh @@ -7,16 +7,16 @@ source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh RunTest mesh_prov_pb_adv_repr \ prov_device_reprovision \ prov_provisioner_reprovision \ - -- -argstest prov-brearer=1 + -- -argstest prov-bearer=1 overlay=overlay_gatt_conf_overlay_psa_conf RunTest mesh_prov_pb_gatt_repr \ prov_device_reprovision \ prov_provisioner_reprovision \ - -- -argstest prov-brearer=2 + -- -argstest prov-bearer=2 overlay=overlay_psa_conf RunTest mesh_prov_pb_adv_repr_psa \ prov_device_reprovision \ prov_provisioner_reprovision \ - -- -argstest prov-brearer=1 + -- -argstest prov-bearer=1