diff --git a/tests/bsim/bluetooth/mesh/overlay_gatt.conf b/tests/bsim/bluetooth/mesh/overlay_gatt.conf index a8ecf87d113fb4..f94a26d623f0e9 100644 --- a/tests/bsim/bluetooth/mesh/overlay_gatt.conf +++ b/tests/bsim/bluetooth/mesh/overlay_gatt.conf @@ -4,3 +4,5 @@ CONFIG_BT_MESH_PB_GATT=y CONFIG_BT_MESH_LOW_POWER=n CONFIG_BT_MESH_FRIEND=n +CONFIG_BT_CENTRAL=y +CONFIG_BT_MESH_PROXY_CLIENT=y diff --git a/tests/bsim/bluetooth/mesh/src/mesh_test.h b/tests/bsim/bluetooth/mesh/src/mesh_test.h index cfcf5a838dc3dc..08cf217779640d 100644 --- a/tests/bsim/bluetooth/mesh/src/mesh_test.h +++ b/tests/bsim/bluetooth/mesh/src/mesh_test.h @@ -122,6 +122,23 @@ } \ } while (0) +#define WAIT_FOR_COND(cond, wait) \ + do { \ + bool _err = false; \ + for (uint8_t sec = (wait); !(cond); sec--) { \ + if (!sec) { \ + _err = true; \ + break; \ + } \ + k_sleep(K_SECONDS(1)); \ + } \ + \ + if (_err) { \ + bst_result = Failed; \ + bs_trace_error_time_line("Waiting for " #cond " timed out\n"); \ + } \ + } while (0) + struct bt_mesh_test_cfg { uint16_t addr; uint8_t dev_key[16]; diff --git a/tests/bsim/bluetooth/mesh/src/test_beacon.c b/tests/bsim/bluetooth/mesh/src/test_beacon.c index fd2477f3907387..1313791d7bb6e9 100644 --- a/tests/bsim/bluetooth/mesh/src/test_beacon.c +++ b/tests/bsim/bluetooth/mesh/src/test_beacon.c @@ -13,6 +13,8 @@ #include "mesh/foundation.h" #include "mesh/crypto.h" #include "argparse.h" +#include "mesh/proxy_cli.h" +#include "mesh/proxy.h" #define LOG_MODULE_NAME test_beacon @@ -1695,6 +1697,68 @@ static void test_rx_priv_multi_net_id(void) PASS(); } + +static void test_tx_priv_gatt_proxy(void) +{ + bt_mesh_test_cfg_set(NULL, WAIT_TIME); + bt_mesh_device_setup(&prov, &prb_comp); + provision(&tx_cfg); + bt_mesh_iv_update_test(true); + + ASSERT_TRUE(bt_mesh.iv_index == 0); + + /* Disable SNB. */ + bt_mesh_beacon_set(false); + ASSERT_OK_MSG(bt_mesh_scan_disable(), "Failed to disable scanner"); + ASSERT_OK_MSG(bt_mesh_gatt_proxy_set(BT_MESH_GATT_PROXY_DISABLED), + "Failed to disable gatt proxy"); + ASSERT_OK_MSG(bt_mesh_priv_gatt_proxy_set(BT_MESH_PRIV_GATT_PROXY_ENABLED), + "Failed to set private gatt proxy"); + + /* Wait for proxy connection to complete. */ + WAIT_FOR_COND(bt_mesh_proxy_srv_connected_cnt() == 1, 10); + + /* Wait a bit so RX device can disable scanner, then start IV update */ + k_sleep(K_SECONDS(2)); + ASSERT_TRUE(bt_mesh_iv_update()); + + /* Check that IV index has updated */ + ASSERT_TRUE(bt_mesh.iv_index == 1); + PASS(); +} + +static void test_rx_priv_gatt_proxy(void) +{ + bt_mesh_test_cfg_set(NULL, WAIT_TIME); + bt_mesh_device_setup(&prov, &prb_comp); + provision(&rx_cfg); + bt_mesh_iv_update_test(true); + + ASSERT_TRUE(bt_mesh.iv_index == 0); + + /* Disable SNB. */ + bt_mesh_beacon_set(false); + ASSERT_OK_MSG(bt_mesh_gatt_proxy_set(BT_MESH_GATT_PROXY_DISABLED), + "Failed to disable gatt proxy"); + ASSERT_OK_MSG(bt_mesh_priv_gatt_proxy_set(BT_MESH_PRIV_GATT_PROXY_ENABLED), + "Failed to set private gatt proxy"); + ASSERT_OK_MSG(bt_mesh_proxy_connect(TEST_NET_IDX1), "Failed to connect over proxy"); + + /* Wait for connection to complete, then disable scanner + * to ensure that all RX communication arrives over GATT. + */ + WAIT_FOR_COND(bt_mesh_proxy_cli_is_connected(TEST_NET_IDX1), 10); + ASSERT_OK_MSG(bt_mesh_scan_disable(), "Failed to disable scanner"); + + /* Wait for the IV index to update. + * Verifying that IV index has changed proves that a private + * beacon arrived successfully over the GATT connection. + */ + WAIT_FOR_COND(bt_mesh.iv_index == 1, 10); + + PASS(); +} + #endif #endif /* CONFIG_BT_MESH_V1d1 */ @@ -1726,6 +1790,7 @@ static const struct bst_test_instance test_beacon[] = { TEST_CASE(tx, priv_net_id, "Private Proxy: advertise Net ID"), TEST_CASE(tx, priv_node_id, "Private Proxy: advertise Node ID"), TEST_CASE(tx, priv_multi_net_id, "Private Proxy: advertise multiple Net ID"), + TEST_CASE(tx, priv_gatt_proxy, "Private Proxy: Send Private Beacons over GATT"), #endif #endif @@ -1743,6 +1808,7 @@ static const struct bst_test_instance test_beacon[] = { TEST_CASE(rx, priv_net_id, "Private Proxy: scan for Net ID"), TEST_CASE(rx, priv_node_id, "Private Proxy: scan for Node ID"), TEST_CASE(rx, priv_multi_net_id, "Private Proxy: scan for multiple Net ID"), + TEST_CASE(rx, priv_gatt_proxy, "Private Proxy: Receive Private Beacons over GATT"), #endif #endif BSTEST_END_MARKER diff --git a/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_proxy_gatt.sh b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_proxy_gatt.sh new file mode 100755 index 00000000000000..a1b9ea7d8d6713 --- /dev/null +++ b/tests/bsim/bluetooth/mesh/tests_scripts/priv_beacon/priv_proxy_gatt.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# Copyright 2023 Nordic Semiconductor +# SPDX-License-Identifier: Apache-2.0 + +source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh + +# Test Private over GATT connection +# +# Test procedure: +# 0. Both TX and RX device disables SNB and GATT proxy, and enables +# Private GATT proxy. Test mode for IV update is also enabled on both devices. +# 1. The RX device (Proxy CLI) establish a GATT connection to the TX device +# (Proxy SRV), using Private Network Identity. +# 2. Both TX and RX device disables the scanner to prevent interferance +# by the adv bearer. +# 3. The TX device (Proxy SRV) starts an IV update procedure. +# 4. Both TX and RX device verifies that the IV index has been updated. +# This proves that the RX device (Proxy CLI) successfully received +# a Private beacon over the GATT connection +conf=prj_mesh1d1_conf +overlay=overlay_gatt_conf +RunTest mesh_priv_proxy_gatt_priv_beacon \ + beacon_tx_priv_gatt_proxy \ + beacon_rx_priv_gatt_proxy + +conf=prj_mesh1d1_conf +overlay=overlay_gatt_conf_overlay_psa_conf +RunTest mesh_priv_proxy_gatt_priv_beacon \ + beacon_tx_priv_gatt_proxy \ + beacon_rx_priv_gatt_proxy