Skip to content

Commit

Permalink
tests: Bluetooth: Mesh: Priv Proxy GATT test
Browse files Browse the repository at this point in the history
Adds test verifying that Private Beacons are received
over a GATT proxy connection.

Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
  • Loading branch information
Andrewpini authored and carlescufi committed Oct 20, 2023
1 parent 6f2ebb9 commit 49bd77a
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/bsim/bluetooth/mesh/overlay_gatt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions tests/bsim/bluetooth/mesh/src/mesh_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
66 changes: 66 additions & 0 deletions tests/bsim/bluetooth/mesh/src/test_beacon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 49bd77a

Please sign in to comment.