diff --git a/drivers/fuel_gauge/Kconfig b/drivers/fuel_gauge/Kconfig index 7ec0b689aa2..a1cdd19b53f 100644 --- a/drivers/fuel_gauge/Kconfig +++ b/drivers/fuel_gauge/Kconfig @@ -13,6 +13,12 @@ module = FUEL_GAUGE module-str = fuel_gauge source "subsys/logging/Kconfig.template.log_config" +config FUEL_GAUGE_INIT_PRIORITY + int "Battery Fuel Gauge init priority" + default 90 + help + Battery fuel gauge initialization priority. + source "drivers/fuel_gauge/sbs_gauge/Kconfig" source "drivers/fuel_gauge/Kconfig.act81461" diff --git a/tests/bluetooth/bsim/README.txt b/tests/bluetooth/bsim/README.txt deleted file mode 100644 index 9edb580bd09..00000000000 --- a/tests/bluetooth/bsim/README.txt +++ /dev/null @@ -1,15 +0,0 @@ -This folder contains tests meant to be run with BabbleSim's physical layer -simulation, and therefore cannot be run directly from twister - -The compile.sh and run_parallel.sh scripts are used by the CI system to build -the needed images and execute these tests in batch. - -You can also run them manually if desired, but be sure to call them setting -the variables they expect. For example, from Zephyr's root folder, you can run: - -WORK_DIR=${ZEPHYR_BASE}/bsim_bt_out tests/bluetooth/bsim/compile.sh -RESULTS_FILE=${ZEPHYR_BASE}/myresults.xml SEARCH_PATH=tests/bluetooth/bsim tests/bluetooth/bsim/run_parallel.sh - -Or to run only a specific subset, e.g. host advertising tests: -WORK_DIR=${ZEPHYR_BASE}/bsim_bt_out tests/bluetooth/bsim/host/compile.sh -RESULTS_FILE=${ZEPHYR_BASE}/myresults.xml SEARCH_PATH=tests/bluetooth/bsim/host/adv tests/bluetooth/bsim/run_parallel.sh diff --git a/tests/bluetooth/bsim/_compile_permutate_kconfigs.sh b/tests/bluetooth/bsim/_compile_permutate_kconfigs.sh deleted file mode 100755 index bd2d6fa0249..00000000000 --- a/tests/bluetooth/bsim/_compile_permutate_kconfigs.sh +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2018 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -# Compile with all permutations of a given set of KConfigs -# Specifically for going through possible combinations of -# optional control procedures - -#set -x #uncomment this line for debugging -# set DEBUG_PERMUTATE to 'true' for extra debug output -DEBUG_PERMUTATE=false - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" -: "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" -: "${ZEPHYR_BASE:?ZEPHYR_BASE must be set to point to the zephyr root\ - directory}" - -WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_bt_out}" -BOARD="${BOARD:-nrf52_bsim}" -BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" - -mkdir -p ${WORK_DIR} - -source ${ZEPHYR_BASE}/tests/bluetooth/bsim/compile.source - - -declare -a list=( -"CONFIG_BT_CENTRAL=" -"CONFIG_BT_PERIPHERAL=" -"CONFIG_BT_CTLR_PER_INIT_FEAT_XCHG=" -"CONFIG_BT_DATA_LEN_UPDATE=" -"CONFIG_BT_PHY_UPDATE=" -"CONFIG_BT_CTLR_MIN_USED_CHAN=" -"CONFIG_BT_CTLR_LE_PING=" -"CONFIG_BT_CTLR_LE_ENC=" -"CONFIG_BT_CTLR_CONN_PARAM_REQ=" -) - -perm_compile() { - local -a results=() - # We set a unique exe-name, so that we don't overwrite the executables - # created by the compile scripts since that may mess up other tests - # We also delete the executable to avoid having artifacts from - # a previous run - local exe_name="bs_nrf52_bsim_tests_kconfig_perm" - local executable_name=${exe_name} - local executable_name=${BSIM_OUT_PATH}/bin/$executable_name - - rm -f ${executable_name} - - let idx=$2 - for (( j = 0; j < $1; j++ )); do - if (( idx % 2 )); then - results=("${results[@]}" "${list[$j]}n") - else - results=("${results[@]}" "${list[$j]}y") - fi - let idx\>\>=1 - done - printf '%s\n' "${results[@]}" > $3 - if test "$DEBUG_PERMUTATE" = "true"; then - echo "Compile with config overlay:" - cat $3 - fi - local app=tests/bluetooth/bsim/ll/edtt/hci_test_app - local conf_file=prj_dut.conf - local conf_overlay=$3 - compile - if [ ! -f ${executable_name} ]; then - compile_failures=$(expr $compile_failures + 1) - fi -} -let n=${#list[@]} -temp_conf_file=$(mktemp -p ${WORK_DIR}) -# compile_failures will be equal to the number of failed compilations -let compile_failures=0 - -for (( i = 0; i < 2**n; i++ )); do - ## don't compile for CENTRAL=n AND PERIPHERAL=n - if (( (i & 0x3) != 0x3 )); then - perm_compile $n $i ${temp_conf_file} - fi -done - -# We set exit code based on type of failure -# 0 means all configurations compiled w/o error - -trap "{ rm "${temp_conf_file}" ; exit 255; }" SIGINT -trap "{ rm "${temp_conf_file}" ; exit 254; }" SIGTERM -trap "{ rm "${temp_conf_file}" ; exit 253; }" ERR -trap "{ rm "${temp_conf_file}" ; exit ${compile_failures}; }" EXIT diff --git a/tests/bluetooth/bsim/audio/CMakeLists.txt b/tests/bluetooth/bsim/audio/CMakeLists.txt deleted file mode 100644 index d7cab913546..00000000000 --- a/tests/bluetooth/bsim/audio/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set\ - the environment variable BSIM_COMPONENTS_PATH to point to its components \ - folder. More information can be found in\ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_audio) - -FILE(GLOB app_sources src/*.c) -target_sources(app PRIVATE ${app_sources} ) - -zephyr_include_directories( - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ - ${ZEPHYR_BASE}/subsys/bluetooth/host/audio/ -) diff --git a/tests/bluetooth/bsim/audio/Kconfig b/tests/bluetooth/bsim/audio/Kconfig deleted file mode 100644 index a0fea388761..00000000000 --- a/tests/bluetooth/bsim/audio/Kconfig +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -# Workaround for pretending that the controller -# supports CIS as the host expects the controller -# to support these features. - -config BT_LL_SW_SPLIT - select BT_CTLR_SYNC_TRANSFER_RECEIVER_SUPPORT - select BT_CTLR_SYNC_TRANSFER_SENDER_SUPPORT - -menu "Zephyr Kernel" -source "Kconfig.zephyr" -endmenu diff --git a/tests/bluetooth/bsim/audio/README.txt b/tests/bluetooth/bsim/audio/README.txt deleted file mode 100644 index 4d14ee4a621..00000000000 --- a/tests/bluetooth/bsim/audio/README.txt +++ /dev/null @@ -1,5 +0,0 @@ -Zephyr test application which uses the simulated boards test hooks. -Can be compiled targeting the *_bsim boards. - -This application will, based on the command line arguments, select one of -testcases which are compiled with it. diff --git a/tests/bluetooth/bsim/audio/compile.sh b/tests/bluetooth/bsim/audio/compile.sh deleted file mode 100755 index 2f0f15f2103..00000000000 --- a/tests/bluetooth/bsim/audio/compile.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -# Compile all the applications needed by the bsim tests - -#set -x #uncomment this line for debugging -set -ue - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" -: "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" -: "${ZEPHYR_BASE:?ZEPHYR_BASE must be set to point to the zephyr root\ - directory}" - -WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_out}" -BOARD="${BOARD:-nrf52_bsim}" -BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" - -mkdir -p ${WORK_DIR} - -source ${ZEPHYR_BASE}/tests/bluetooth/bsim/compile.source - -app=tests/bluetooth/bsim/audio compile - -wait_for_background_jobs diff --git a/tests/bluetooth/bsim/audio/prj.conf b/tests/bluetooth/bsim/audio/prj.conf deleted file mode 100644 index 17faeb5d041..00000000000 --- a/tests/bluetooth/bsim/audio/prj.conf +++ /dev/null @@ -1,169 +0,0 @@ -CONFIG_TEST=y -CONFIG_BT_TESTING=y -CONFIG_CONSOLE_HANDLER=y -CONFIG_USERSPACE=n -CONFIG_NO_OPTIMIZATIONS=y - -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_DEVICE_NAME="bsim_test_audio" -CONFIG_BT_L2CAP_TX_BUF_COUNT=20 -CONFIG_BT_MAX_CONN=5 -CONFIG_BT_MAX_PAIRED=5 -CONFIG_BT_GATT_DYNAMIC_DB=y -CONFIG_BT_SMP=y - -# Needed for extended advertising -CONFIG_BT_EXT_ADV_LEGACY_SUPPORT=y - -CONFIG_BT_AUDIO=y -CONFIG_BT_BAP_UNICAST_SERVER=y -CONFIG_BT_BAP_UNICAST_CLIENT=y -CONFIG_BT_BAP_UNICAST_CLIENT_GROUP_STREAM_COUNT=2 -CONFIG_BT_BAP_BROADCAST_SOURCE=y -CONFIG_BT_BAP_BROADCAST_SINK=y -# Only 1 stream support by controller at this point -CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT=1 -CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT=1 -# Only 1 stream support by controller at this point -CONFIG_BT_BAP_BROADCAST_SNK_SUBGROUP_COUNT=1 -CONFIG_BT_BAP_BROADCAST_SNK_STREAM_COUNT=1 -CONFIG_BT_ISO_TX_BUF_COUNT=4 -CONFIG_BT_ISO_MAX_CHAN=2 - -# Needed for Periodic Advertising Sync Transfer -CONFIG_BT_PER_ADV_SYNC_TRANSFER_RECEIVER=y -CONFIG_BT_PER_ADV_SYNC_TRANSFER_SENDER=y - -# Volume Offset Control Service -CONFIG_BT_VOCS_MAX_INSTANCE_COUNT=2 -CONFIG_BT_VOCS_CLIENT_MAX_INSTANCE_COUNT=2 - -# Audio Input Control Service -CONFIG_BT_AICS_MAX_INSTANCE_COUNT=4 -CONFIG_BT_AICS_CLIENT_MAX_INSTANCE_COUNT=4 - -#Volume Control -CONFIG_BT_VCP_VOL_REND=y -CONFIG_BT_VCP_VOL_REND_VOCS_INSTANCE_COUNT=2 -CONFIG_BT_VCP_VOL_REND_AICS_INSTANCE_COUNT=2 -CONFIG_BT_VCP_VOL_CTLR=y -CONFIG_BT_VCP_VOL_CTLR_MAX_VOCS_INST=2 -CONFIG_BT_VCP_VOL_CTLR_MAX_AICS_INST=2 - -CONFIG_BT_MICP_MIC_DEV=y -CONFIG_BT_MICP_MIC_DEV_AICS_INSTANCE_COUNT=2 -CONFIG_BT_MICP_MIC_CTLR=y -CONFIG_BT_MICP_MIC_CTLR_MAX_AICS_INST=2 - -# Coordinated Set Identification -CONFIG_BT_CSIP_SET_MEMBER=y -CONFIG_BT_CSIP_SET_MEMBER_TEST_SAMPLE_DATA=y -CONFIG_BT_CSIP_SET_COORDINATOR=y -CONFIG_BT_CSIP_SET_COORDINATOR_TEST_SAMPLE_DATA=y - -# Telephone bearer service -CONFIG_BT_TBS=y -CONFIG_BT_TBS_CLIENT=y - -# Media control -CONFIG_MCTL=y -CONFIG_MCTL_LOCAL_PLAYER_CONTROL=y -CONFIG_MCTL_LOCAL_PLAYER_LOCAL_CONTROL=y -CONFIG_MCTL_LOCAL_PLAYER_REMOTE_CONTROL=y -CONFIG_MCTL_REMOTE_PLAYER_CONTROL=y -CONFIG_MCTL_REMOTE_PLAYER_CONTROL_OBJECTS=y -CONFIG_UTF8=y - -# Media player -CONFIG_BT_MPL=y -CONFIG_BT_MPL_OBJECTS=y -CONFIG_BT_MPL_MAX_OBJ_SIZE=600 - -# Media control -CONFIG_BT_MCS=y -CONFIG_BT_MCC=y -CONFIG_BT_MCC_OTS=y -CONFIG_BT_MCC_SHELL=y -CONFIG_BT_MCC_TOTAL_OBJ_CONTENT_MEM=4096 - -# Immediate Alert -CONFIG_BT_IAS=y -CONFIG_BT_IAS_CLIENT=y - -# Object Transfer -CONFIG_BT_OTS=y -CONFIG_BT_OTS_SECONDARY_SVC=y -CONFIG_BT_OTS_MAX_OBJ_CNT=0x30 -CONFIG_BT_OTS_CLIENT=y - -# Broadcast Audio Scan Service and client -CONFIG_BT_BAP_SCAN_DELEGATOR=y -CONFIG_BT_BAP_BROADCAST_ASSISTANT=y - -# Hearing Access -CONFIG_BT_HAS=y -CONFIG_BT_HAS_CLIENT=y - -# Common Audio Profile -CONFIG_BT_CAP_ACCEPTOR=y -CONFIG_BT_CAP_ACCEPTOR_SET_MEMBER=y -CONFIG_BT_CAP_INITIATOR=y - -# DEBUGGING -CONFIG_BT_DEBUG_LOG=y -CONFIG_BT_VCP_VOL_REND_LOG_LEVEL_DBG=y -CONFIG_BT_VCP_VOL_CTLR_LOG_LEVEL_DBG=y -CONFIG_BT_AICS_LOG_LEVEL_DBG=y -CONFIG_BT_AICS_CLIENT_LOG_LEVEL_DBG=y -CONFIG_BT_VOCS_LOG_LEVEL_DBG=y -CONFIG_BT_VOCS_CLIENT_LOG_LEVEL_DBG=y -CONFIG_BT_MICP_MIC_DEV_LOG_LEVEL_DBG=y -CONFIG_BT_MICP_MIC_CTLR_LOG_LEVEL_DBG=y -CONFIG_BT_MPL_LOG_LEVEL_DBG=y -CONFIG_BT_TBS_LOG_LEVEL_DBG=y -CONFIG_BT_TBS_CLIENT_LOG_LEVEL_DBG=y -CONFIG_BT_MCS_LOG_LEVEL_DBG=y -CONFIG_BT_MCC_LOG_LEVEL_DBG=y -CONFIG_BT_OTS_LOG_LEVEL_DBG=y -CONFIG_BT_OTS_CLIENT_LOG_LEVEL_DBG=y -CONFIG_MCTL_LOG_LEVEL_DBG=y -CONFIG_BT_CSIP_SET_MEMBER_LOG_LEVEL_DBG=y -CONFIG_BT_CSIP_SET_COORDINATOR_LOG_LEVEL_DBG=y -CONFIG_BT_CSIP_SET_MEMBER_CRYPTO_LOG_LEVEL_DBG=y -CONFIG_BT_BAP_UNICAST_CLIENT_LOG_LEVEL_DBG=y -CONFIG_BT_BAP_UNICAST_SERVER_LOG_LEVEL_DBG=y -CONFIG_BT_BAP_BROADCAST_SINK_LOG_LEVEL_DBG=y -CONFIG_BT_BAP_BROADCAST_SOURCE_LOG_LEVEL_DBG=y -CONFIG_BT_ASCS_LOG_LEVEL_DBG=y -CONFIG_BT_PACS_LOG_LEVEL_DBG=y -CONFIG_BT_BAP_STREAM_LOG_LEVEL_DBG=y -CONFIG_BT_BAP_ISO_LOG_LEVEL_DBG=y -CONFIG_BT_AUDIO_CODEC_LOG_LEVEL_DBG=y -CONFIG_BT_BAP_SCAN_DELEGATOR_LOG_LEVEL_DBG=y -CONFIG_BT_BAP_BROADCAST_ASSISTANT_LOG_LEVEL_DBG=y -CONFIG_BT_HAS_LOG_LEVEL_DBG=y -CONFIG_BT_HAS_CLIENT_LOG_LEVEL_DBG=y -CONFIG_BT_CAP_ACCEPTOR_LOG_LEVEL_DBG=y -CONFIG_BT_DEBUG_CAP_INITIATOR=y - -# LOGGING -CONFIG_TEST_LOGGING_DEFAULTS=n -CONFIG_LOG_MODE_IMMEDIATE=y - -# Controller Broadcast ISO configs -CONFIG_BT_CTLR_ADV_ISO=y -CONFIG_BT_CTLR_SYNC_ISO=y -CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=255 -# Supports the highest SDU size required by any BAP LC3 presets (155) -CONFIG_BT_CTLR_ISO_TX_BUFFER_SIZE=155 -CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=191 -CONFIG_BT_CTLR_ADV_ISO_STREAM_COUNT=1 -CONFIG_BT_CTLR_SYNC_ISO_STREAM_MAX=1 - -# Controller Connected ISO configs -CONFIG_BT_CTLR_CENTRAL_ISO=y -CONFIG_BT_CTLR_PERIPHERAL_ISO=y - -CONFIG_BT_CTLR_ISO_TX_BUFFERS=3 diff --git a/tests/bluetooth/bsim/audio/src/bap_broadcast_assistant_test.c b/tests/bluetooth/bsim/audio/src/bap_broadcast_assistant_test.c deleted file mode 100644 index 4552ee82d5e..00000000000 --- a/tests/bluetooth/bsim/audio/src/bap_broadcast_assistant_test.c +++ /dev/null @@ -1,518 +0,0 @@ -/* - * Copyright (c) 2021-2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifdef CONFIG_BT_BAP_BROADCAST_ASSISTANT - -#include -#include -#include -#include "../../../../../subsys/bluetooth/host/hci_core.h" -#include "common.h" - -static struct bt_conn_cb conn_callbacks; -extern enum bst_result_t bst_result; - -/* BASS variables */ -static volatile bool g_is_connected; -static volatile bool g_mtu_exchanged; -static volatile bool g_discovery_complete; -static volatile bool g_write_complete; -static volatile bool g_cb; -static volatile bool g_broadcaster_found; -static volatile bool g_pa_synced; -static volatile bool g_state_synced; -static volatile uint8_t g_src_id; -static volatile uint32_t g_broadcast_id; - -static volatile bool g_cb; -static struct bt_conn *g_conn; - -/* Broadcaster variables */ -static bt_addr_le_t g_broadcaster_addr; -static struct bt_le_scan_recv_info g_broadcaster_info; -static struct bt_le_per_adv_sync *g_pa_sync; - -static const char *phy2str(uint8_t phy) -{ - switch (phy) { - case 0: return "No packets"; - case BT_GAP_LE_PHY_1M: return "LE 1M"; - case BT_GAP_LE_PHY_2M: return "LE 2M"; - case BT_GAP_LE_PHY_CODED: return "LE Coded"; - default: return "Unknown"; - } -} - -static void bap_broadcast_assistant_discover_cb(struct bt_conn *conn, int err, - uint8_t recv_state_count) -{ - if (err != 0) { - FAIL("BASS discover failed (%d)\n", err); - return; - } - - printk("BASS discover done with %u recv states\n", recv_state_count); - g_discovery_complete = true; -} - -static void bap_broadcast_assistant_scan_cb(const struct bt_le_scan_recv_info *info, - uint32_t broadcast_id) -{ - char le_addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(info->addr, le_addr, sizeof(le_addr)); - printk("Scan Recv: [DEVICE]: %s, broadcast_id %u, " - "interval (ms) %u), SID 0x%x, RSSI %i\n", - le_addr, broadcast_id, info->interval * 5 / 4, - info->sid, info->rssi); - - (void)memcpy(&g_broadcaster_info, info, sizeof(g_broadcaster_info)); - bt_addr_le_copy(&g_broadcaster_addr, info->addr); - g_broadcast_id = broadcast_id; - g_broadcaster_found = true; -} - -static bool metadata_entry(struct bt_data *data, void *user_data) -{ - char metadata[512]; - - (void)bin2hex(data->data, data->data_len, metadata, sizeof(metadata)); - - printk("\t\tMetadata length %u, type %u, data: %s\n", - data->data_len, data->type, metadata); - - return true; -} - -static void bap_broadcast_assistant_recv_state_cb( - struct bt_conn *conn, int err, - const struct bt_bap_scan_delegator_recv_state *state) -{ - char le_addr[BT_ADDR_LE_STR_LEN]; - char bad_code[33]; - - if (err != 0) { - FAIL("BASS recv state read failed (%d)\n", err); - return; - } - - bt_addr_le_to_str(&state->addr, le_addr, sizeof(le_addr)); - (void)bin2hex(state->bad_code, BT_AUDIO_BROADCAST_CODE_SIZE, bad_code, - sizeof(bad_code)); - printk("BASS recv state: src_id %u, addr %s, sid %u, sync_state %u, " - "encrypt_state %u%s%s\n", state->src_id, le_addr, state->adv_sid, - state->pa_sync_state, state->encrypt_state, - state->encrypt_state == BT_BAP_BIG_ENC_STATE_BAD_CODE ? ", bad code" : "", - bad_code); - - for (int i = 0; i < state->num_subgroups; i++) { - const struct bt_bap_scan_delegator_subgroup *subgroup = &state->subgroups[i]; - struct net_buf_simple buf; - - printk("\t[%d]: BIS sync %u, metadata_len %u\n", - i, subgroup->bis_sync, subgroup->metadata_len); - - net_buf_simple_init_with_data(&buf, (void *)subgroup->metadata, - subgroup->metadata_len); - bt_data_parse(&buf, metadata_entry, NULL); - } - - - if (state->pa_sync_state == BT_BAP_PA_STATE_INFO_REQ) { - err = bt_le_per_adv_sync_transfer(g_pa_sync, conn, - BT_UUID_BASS_VAL); - if (err != 0) { - FAIL("Could not transfer periodic adv sync: %d\n", err); - return; - } - } - - g_state_synced = state->pa_sync_state == BT_BAP_PA_STATE_SYNCED; - - g_src_id = state->src_id; - g_cb = true; -} - -static void bap_broadcast_assistant_recv_state_removed_cb(struct bt_conn *conn, int err, - uint8_t src_id) -{ - if (err != 0) { - FAIL("BASS recv state removed failed (%d)\n", err); - return; - } - - printk("BASS recv state %u removed\n", src_id); - g_cb = true; -} - -static void bap_broadcast_assistant_scan_start_cb(struct bt_conn *conn, int err) -{ - if (err != 0) { - FAIL("BASS scan start failed (%d)\n", err); - return; - } - - printk("BASS scan start successful\n"); - g_write_complete = true; -} - -static void bap_broadcast_assistant_scan_stop_cb(struct bt_conn *conn, int err) -{ - if (err != 0) { - FAIL("BASS scan stop failed (%d)\n", err); - return; - } - - printk("BASS scan stop successful\n"); - g_write_complete = true; -} - -static void bap_broadcast_assistant_add_src_cb(struct bt_conn *conn, int err) -{ - if (err != 0) { - FAIL("BASS add source failed (%d)\n", err); - return; - } - - printk("BASS add source successful\n"); - g_write_complete = true; -} - -static void bap_broadcast_assistant_mod_src_cb(struct bt_conn *conn, int err) -{ - if (err != 0) { - FAIL("BASS modify source failed (%d)\n", err); - return; - } - - printk("BASS modify source successful\n"); - g_write_complete = true; -} - -static void bap_broadcast_assistant_broadcast_code_cb(struct bt_conn *conn, int err) -{ - if (err != 0) { - FAIL("BASS broadcast code failed (%d)\n", err); - return; - } - - printk("BASS broadcast code successful\n"); - g_write_complete = true; -} - -static void bap_broadcast_assistant_rem_src_cb(struct bt_conn *conn, int err) -{ - if (err != 0) { - FAIL("BASS remove source failed (%d)\n", err); - return; - } - - printk("BASS remove source successful\n"); - g_write_complete = true; -} - -static struct bt_bap_broadcast_assistant_cb broadcast_assistant_cbs = { - .discover = bap_broadcast_assistant_discover_cb, - .scan = bap_broadcast_assistant_scan_cb, - .recv_state = bap_broadcast_assistant_recv_state_cb, - .recv_state_removed = bap_broadcast_assistant_recv_state_removed_cb, - .scan_start = bap_broadcast_assistant_scan_start_cb, - .scan_stop = bap_broadcast_assistant_scan_stop_cb, - .add_src = bap_broadcast_assistant_add_src_cb, - .mod_src = bap_broadcast_assistant_mod_src_cb, - .broadcast_code = bap_broadcast_assistant_broadcast_code_cb, - .rem_src = bap_broadcast_assistant_rem_src_cb, -}; - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - g_conn = conn; - g_is_connected = true; -} - -static struct bt_conn_cb conn_callbacks = { - .connected = connected, - .disconnected = disconnected, -}; - -static void att_mtu_updated(struct bt_conn *conn, uint16_t tx, uint16_t rx) -{ - g_mtu_exchanged = true; -} - -static struct bt_gatt_cb gatt_callbacks = { - .att_mtu_updated = att_mtu_updated, -}; - -static void sync_cb(struct bt_le_per_adv_sync *sync, - struct bt_le_per_adv_sync_synced_info *info) -{ - char le_addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(info->addr, le_addr, sizeof(le_addr)); - - printk("PER_ADV_SYNC[%u]: [DEVICE]: %s synced, " - "Interval 0x%04x (%u ms), PHY %s\n", - bt_le_per_adv_sync_get_index(sync), le_addr, info->interval, - info->interval * 5 / 4, phy2str(info->phy)); - - g_pa_synced = true; -} - -static void term_cb(struct bt_le_per_adv_sync *sync, - const struct bt_le_per_adv_sync_term_info *info) -{ - char le_addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(info->addr, le_addr, sizeof(le_addr)); - - printk("PER_ADV_SYNC[%u]: [DEVICE]: %s sync terminated\n", - bt_le_per_adv_sync_get_index(sync), le_addr); - - g_pa_synced = false; -} - -static struct bt_le_per_adv_sync_cb sync_callbacks = { - .synced = sync_cb, - .term = term_cb, -}; - -static void test_exchange_mtu(void) -{ - WAIT_FOR_COND(g_mtu_exchanged); - printk("MTU exchanged\n"); -} - -static void test_bass_discover(void) -{ - int err; - - printk("Discovering BASS\n"); - err = bt_bap_broadcast_assistant_discover(g_conn); - if (err != 0) { - FAIL("Failed to discover BASS %d\n", err); - return; - } - - WAIT_FOR_COND(g_discovery_complete); - printk("Discovery complete\n"); -} - -static void test_bass_scan_start(void) -{ - int err; - - printk("Starting scan\n"); - g_write_complete = false; - err = bt_bap_broadcast_assistant_scan_start(g_conn, true); - if (err != 0) { - FAIL("Could not write scan start to BASS (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_write_complete && g_broadcaster_found); - printk("Scan started\n"); -} - -static void test_bass_scan_stop(void) -{ - int err; - - printk("Stopping scan\n"); - g_write_complete = false; - err = bt_bap_broadcast_assistant_scan_stop(g_conn); - if (err != 0) { - FAIL("Could not write scan stop to BASS (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_write_complete); - printk("Scan stopped\n"); -} - -static void test_bass_create_pa_sync(void) -{ - int err; - struct bt_le_per_adv_sync_param sync_create_param = { 0 }; - - printk("Creating Periodic Advertising Sync...\n"); - bt_addr_le_copy(&sync_create_param.addr, &g_broadcaster_addr); - sync_create_param.sid = g_broadcaster_info.sid; - sync_create_param.timeout = 0xa; - err = bt_le_per_adv_sync_create(&sync_create_param, &g_pa_sync); - if (err != 0) { - FAIL("Could not create PA syncs (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_pa_synced); - printk("PA synced\n"); -} - -static void test_bass_add_source(void) -{ - int err; - struct bt_bap_broadcast_assistant_add_src_param add_src_param = { 0 }; - struct bt_bap_scan_delegator_subgroup subgroup = { 0 }; - - printk("Adding source\n"); - g_cb = g_write_complete = false; - bt_addr_le_copy(&add_src_param.addr, &g_broadcaster_addr); - add_src_param.adv_sid = g_broadcaster_info.sid; - add_src_param.num_subgroups = 1; - add_src_param.pa_interval = g_broadcaster_info.interval; - add_src_param.pa_sync = false; - add_src_param.broadcast_id = g_broadcast_id; - add_src_param.subgroups = &subgroup; - subgroup.bis_sync = 0; - subgroup.metadata_len = 0; - err = bt_bap_broadcast_assistant_add_src(g_conn, &add_src_param); - if (err != 0) { - FAIL("Could not add source (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_cb && g_write_complete); - printk("Source added\n"); -} - -static void test_bass_mod_source(void) -{ - int err; - struct bt_bap_broadcast_assistant_mod_src_param mod_src_param = { 0 }; - struct bt_bap_scan_delegator_subgroup subgroup = { 0 }; - - printk("Modify source\n"); - g_cb = g_write_complete = false; - mod_src_param.src_id = g_src_id; - mod_src_param.num_subgroups = 1; - mod_src_param.pa_sync = true; - mod_src_param.subgroups = &subgroup; - mod_src_param.pa_interval = g_broadcaster_info.interval; - subgroup.bis_sync = 0; - subgroup.metadata_len = 0; - err = bt_bap_broadcast_assistant_mod_src(g_conn, &mod_src_param); - if (err != 0) { - FAIL("Could not modify source (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_cb && g_write_complete); - printk("Source added, waiting for server to PA sync\n"); - WAIT_FOR_COND(g_state_synced) - printk("Server PA synced\n"); -} - -static void test_bass_broadcast_code(void) -{ - uint8_t broadcast_code[BT_AUDIO_BROADCAST_CODE_SIZE]; - int err; - - for (int i = 0; i < ARRAY_SIZE(broadcast_code); i++) { - broadcast_code[i] = i; - } - - printk("Adding broadcast code\n"); - g_write_complete = false; - err = bt_bap_broadcast_assistant_set_broadcast_code(g_conn, g_src_id, - broadcast_code); - if (err != 0) { - FAIL("Could not add broadcast code (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_write_complete); - printk("Broadcast code added\n"); -} - -static void test_bass_remove_source(void) -{ - int err; - - printk("Removing source\n"); - g_cb = g_write_complete = false; - err = bt_bap_broadcast_assistant_rem_src(g_conn, g_src_id); - if (err != 0) { - FAIL("Could not remove source (err %d)\n", err); - return; - } - WAIT_FOR_COND(g_cb && g_write_complete); - printk("Source removed\n"); -} - -static void test_main(void) -{ - int err; - - err = bt_enable(NULL); - - if (err != 0) { - FAIL("Bluetooth enable failed (err %d)\n", err); - return; - } - - bt_conn_cb_register(&conn_callbacks); - bt_gatt_cb_register(&gatt_callbacks); - bt_bap_broadcast_assistant_register_cb(&broadcast_assistant_cbs); - bt_le_per_adv_sync_cb_register(&sync_callbacks); - - printk("Starting scan\n"); - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); - if (err != 0) { - FAIL("Scanning failed to start (err %d)\n", err); - return; - } - - printk("Scanning successfully started\n"); - - WAIT_FOR_COND(g_is_connected); - - test_exchange_mtu(); - test_bass_discover(); - test_bass_scan_start(); - test_bass_scan_stop(); - test_bass_create_pa_sync(); - test_bass_add_source(); - test_bass_mod_source(); - test_bass_broadcast_code(); - test_bass_remove_source(); - - PASS("BAP broadcast assistant Passed\n"); -} - -static const struct bst_test_instance test_bass[] = { - { - .test_id = "bap_broadcast_assistant", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_bap_broadcast_assistant_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_bass); -} - -#else - -struct bst_test_list *test_bap_broadcast_assistant_install(struct bst_test_list *tests) -{ - return tests; -} - -#endif /* CONFIG_BT_BAP_BROADCAST_ASSISTANT */ diff --git a/tests/bluetooth/bsim/audio/src/bap_scan_delegator_test.c b/tests/bluetooth/bsim/audio/src/bap_scan_delegator_test.c deleted file mode 100644 index aecdf0a0f0e..00000000000 --- a/tests/bluetooth/bsim/audio/src/bap_scan_delegator_test.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2021-2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifdef CONFIG_BT_BAP_SCAN_DELEGATOR -#include -#include "common.h" - -extern enum bst_result_t bst_result; - -static volatile bool g_cb; -static volatile bool g_pa_synced; -static struct bt_conn *g_conn; -static bool g_connected; - -static void pa_synced(struct bt_bap_scan_delegator_recv_state *recv_state, - const struct bt_le_per_adv_sync_synced_info *info) -{ - printk("Receive state %p synced\n", recv_state); - g_pa_synced = true; -} - -static void pa_term(struct bt_bap_scan_delegator_recv_state *recv_state, - const struct bt_le_per_adv_sync_term_info *info) -{ - printk("Receive state %p sync terminated\n", recv_state); - g_pa_synced = false; -} - -static void pa_recv(struct bt_bap_scan_delegator_recv_state *recv_state, - const struct bt_le_per_adv_sync_recv_info *info, - struct net_buf_simple *buf) -{ - printk("Receive state %p received data\n", recv_state); -} - -static struct bt_bap_scan_delegator_cb scan_delegator_cb = { - .pa_synced = pa_synced, - .pa_term = pa_term, - .pa_recv = pa_recv -}; - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - g_conn = conn; - g_connected = true; -} - -static struct bt_conn_cb conn_callbacks = { - .connected = connected, - .disconnected = disconnected, -}; - -static void test_main(void) -{ - int err; - - err = bt_enable(NULL); - if (err) { - FAIL("Bluetooth init failed (err %d)\n", err); - return; - } - - printk("Bluetooth initialized\n"); - - bt_bap_scan_delegator_register_cb(&scan_delegator_cb); - bt_conn_cb_register(&conn_callbacks); - - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, AD_SIZE, NULL, 0); - if (err) { - FAIL("Advertising failed to start (err %d)\n", err); - return; - } - - printk("Advertising successfully started\n"); - - WAIT_FOR_COND(g_connected); - - WAIT_FOR_COND(g_pa_synced); - - PASS("BAP Scan Delegator passed\n"); -} - -static const struct bst_test_instance test_scan_delegator[] = { - { - .test_id = "bap_scan_delegator", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_scan_delegator_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_scan_delegator); -} -#else -struct bst_test_list *test_scan_delegator_install(struct bst_test_list *tests) -{ - return tests; -} - -#endif /* CONFIG_BT_BAP_SCAN_DELEGATOR */ diff --git a/tests/bluetooth/bsim/audio/src/bap_unicast_client_test.c b/tests/bluetooth/bsim/audio/src/bap_unicast_client_test.c deleted file mode 100644 index bd921f702e0..00000000000 --- a/tests/bluetooth/bsim/audio/src/bap_unicast_client_test.c +++ /dev/null @@ -1,631 +0,0 @@ -/* - * Copyright (c) 2021-2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#if defined(CONFIG_BT_BAP_UNICAST_CLIENT) - -#include -#include -#include -#include -#include -#include "common.h" -#include "bap_unicast_common.h" - -extern enum bst_result_t bst_result; - -static struct bt_bap_stream g_streams[CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT]; -static struct bt_bap_ep *g_sinks[CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT]; - -/* Mandatory support preset by both client and server */ -static struct bt_bap_lc3_preset preset_16_2_1 = BT_BAP_LC3_UNICAST_PRESET_16_2_1( - BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED); - -CREATE_FLAG(flag_connected); -CREATE_FLAG(flag_mtu_exchanged); -CREATE_FLAG(flag_sink_discovered); -CREATE_FLAG(flag_stream_codec_configured); -static atomic_t flag_stream_qos_configured; -CREATE_FLAG(flag_stream_enabled); -CREATE_FLAG(flag_stream_started); -CREATE_FLAG(flag_stream_released); -CREATE_FLAG(flag_operation_success); - -static void stream_configured(struct bt_bap_stream *stream, - const struct bt_codec_qos_pref *pref) -{ - printk("Configured stream %p\n", stream); - - /* TODO: The preference should be used/taken into account when - * setting the QoS - */ - - SET_FLAG(flag_stream_codec_configured); -} - -static void stream_qos_set(struct bt_bap_stream *stream) -{ - printk("QoS set stream %p\n", stream); - - atomic_inc(&flag_stream_qos_configured); -} - -static void stream_enabled(struct bt_bap_stream *stream) -{ - printk("Enabled stream %p\n", stream); - - SET_FLAG(flag_stream_enabled); -} - -static void stream_started(struct bt_bap_stream *stream) -{ - printk("Started stream %p\n", stream); - - SET_FLAG(flag_stream_started); -} - -static void stream_metadata_updated(struct bt_bap_stream *stream) -{ - printk("Metadata updated stream %p\n", stream); -} - -static void stream_disabled(struct bt_bap_stream *stream) -{ - printk("Disabled stream %p\n", stream); -} - -static void stream_stopped(struct bt_bap_stream *stream, uint8_t reason) -{ - printk("Stopped stream %p with reason 0x%02X\n", stream, reason); -} - -static void stream_released(struct bt_bap_stream *stream) -{ - printk("Released stream %p\n", stream); - - SET_FLAG(flag_stream_released); -} - -static struct bt_bap_stream_ops stream_ops = { - .configured = stream_configured, - .qos_set = stream_qos_set, - .enabled = stream_enabled, - .started = stream_started, - .metadata_updated = stream_metadata_updated, - .disabled = stream_disabled, - .stopped = stream_stopped, - .released = stream_released, -}; - -static void unicast_client_location_cb(struct bt_conn *conn, - enum bt_audio_dir dir, - enum bt_audio_location loc) -{ - printk("dir %u loc %X\n", dir, loc); -} - -static void available_contexts_cb(struct bt_conn *conn, - enum bt_audio_context snk_ctx, - enum bt_audio_context src_ctx) -{ - printk("snk ctx %u src ctx %u\n", snk_ctx, src_ctx); -} - - -static void config_cb(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, - enum bt_bap_ascs_reason reason) -{ - printk("stream %p config operation rsp_code %u reason %u\n", stream, rsp_code, reason); - - if (rsp_code == BT_BAP_ASCS_RSP_CODE_SUCCESS) { - SET_FLAG(flag_operation_success); - } -} - -static void qos_cb(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, - enum bt_bap_ascs_reason reason) -{ - printk("stream %p qos operation rsp_code %u reason %u\n", stream, rsp_code, reason); - - if (rsp_code == BT_BAP_ASCS_RSP_CODE_SUCCESS) { - SET_FLAG(flag_operation_success); - } -} - -static void enable_cb(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, - enum bt_bap_ascs_reason reason) -{ - printk("stream %p enable operation rsp_code %u reason %u\n", stream, rsp_code, reason); - - if (rsp_code == BT_BAP_ASCS_RSP_CODE_SUCCESS) { - SET_FLAG(flag_operation_success); - } -} - -static void start_cb(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, - enum bt_bap_ascs_reason reason) -{ - printk("stream %p start operation rsp_code %u reason %u\n", stream, rsp_code, reason); - - if (rsp_code == BT_BAP_ASCS_RSP_CODE_SUCCESS) { - SET_FLAG(flag_operation_success); - } -} - -static void stop_cb(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, - enum bt_bap_ascs_reason reason) -{ - printk("stream %p stop operation rsp_code %u reason %u\n", stream, rsp_code, reason); - - if (rsp_code == BT_BAP_ASCS_RSP_CODE_SUCCESS) { - SET_FLAG(flag_operation_success); - } -} - -static void disable_cb(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, - enum bt_bap_ascs_reason reason) -{ - printk("stream %p disable operation rsp_code %u reason %u\n", stream, rsp_code, reason); - - if (rsp_code == BT_BAP_ASCS_RSP_CODE_SUCCESS) { - SET_FLAG(flag_operation_success); - } -} - -static void metadata_cb(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, - enum bt_bap_ascs_reason reason) -{ - printk("stream %p metadata operation rsp_code %u reason %u\n", stream, rsp_code, reason); - - if (rsp_code == BT_BAP_ASCS_RSP_CODE_SUCCESS) { - SET_FLAG(flag_operation_success); - } -} - -static void release_cb(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, - enum bt_bap_ascs_reason reason) -{ - printk("stream %p release operation rsp_code %u reason %u\n", stream, rsp_code, reason); - - if (rsp_code == BT_BAP_ASCS_RSP_CODE_SUCCESS) { - SET_FLAG(flag_operation_success); - } -} - -const struct bt_bap_unicast_client_cb unicast_client_cbs = { - .location = unicast_client_location_cb, - .available_contexts = available_contexts_cb, - .config = config_cb, - .qos = qos_cb, - .enable = enable_cb, - .start = start_cb, - .stop = stop_cb, - .disable = disable_cb, - .metadata = metadata_cb, - .release = release_cb, -}; - -static void add_remote_sink(struct bt_bap_ep *ep, uint8_t index) -{ - printk("Sink #%u: ep %p\n", index, ep); - - g_sinks[index] = ep; -} - -static void print_remote_codec(struct bt_codec *codec, int index, enum bt_audio_dir dir) -{ - printk("#%u: codec %p dir 0x%02x\n", index, codec, dir); - - print_codec(codec); -} - -static void discover_sink_cb(struct bt_conn *conn, struct bt_codec *codec, struct bt_bap_ep *ep, - struct bt_bap_unicast_client_discover_params *params) -{ - static bool codec_found; - static bool endpoint_found; - - if (params->err != 0) { - FAIL("Discovery failed: %d\n", params->err); - return; - } - - if (codec != NULL) { - print_remote_codec(codec, params->num_caps, params->dir); - codec_found = true; - return; - } - - if (ep != NULL) { - if (params->dir == BT_AUDIO_DIR_SINK) { - add_remote_sink(ep, params->num_eps); - endpoint_found = true; - } else { - FAIL("Invalid param dir: %u\n", params->dir); - } - - return; - } - - printk("Discover complete\n"); - - (void)memset(params, 0, sizeof(*params)); - - if (endpoint_found && codec_found) { - SET_FLAG(flag_sink_discovered); - } else { - FAIL("Did not discover endpoint and codec\n"); - } -} - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - (void)bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - bt_conn_unref(default_conn); - default_conn = NULL; - - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - SET_FLAG(flag_connected); -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - -static void att_mtu_updated(struct bt_conn *conn, uint16_t tx, uint16_t rx) -{ - printk("MTU exchanged\n"); - SET_FLAG(flag_mtu_exchanged); -} - -static struct bt_gatt_cb gatt_callbacks = { - .att_mtu_updated = att_mtu_updated, -}; - -static void init(void) -{ - int err; - - err = bt_enable(NULL); - if (err != 0) { - FAIL("Bluetooth enable failed (err %d)\n", err); - return; - } - - for (size_t i = 0; i < ARRAY_SIZE(g_streams); i++) { - g_streams[i].ops = &stream_ops; - } - - bt_gatt_cb_register(&gatt_callbacks); - - err = bt_bap_unicast_client_register_cb(&unicast_client_cbs); - if (err != 0) { - FAIL("Failed to register client callbacks: %d", err); - return; - } -} - -static void scan_and_connect(void) -{ - int err; - - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); - if (err != 0) { - FAIL("Scanning failed to start (err %d)\n", err); - return; - } - - printk("Scanning successfully started\n"); - WAIT_FOR_FLAG(flag_connected); -} - -static void exchange_mtu(void) -{ - WAIT_FOR_FLAG(flag_mtu_exchanged); -} - -static void discover_sink(void) -{ - static struct bt_bap_unicast_client_discover_params params; - int err; - - params.func = discover_sink_cb; - params.dir = BT_AUDIO_DIR_SINK; - - err = bt_bap_unicast_client_discover(default_conn, ¶ms); - if (err != 0) { - printk("Failed to discover sink: %d\n", err); - return; - } - - WAIT_FOR_FLAG(flag_sink_discovered); -} - -static int codec_configure_stream(struct bt_bap_stream *stream, struct bt_bap_ep *ep) -{ - int err; - - UNSET_FLAG(flag_stream_codec_configured); - UNSET_FLAG(flag_operation_success); - - err = bt_bap_stream_config(default_conn, stream, ep, - &preset_16_2_1.codec); - if (err != 0) { - FAIL("Could not configure stream: %d\n", err); - return err; - } - - WAIT_FOR_FLAG(flag_stream_codec_configured); - WAIT_FOR_FLAG(flag_operation_success); - - return 0; -} - -static void codec_configure_streams(size_t stream_cnt) -{ - for (size_t i = 0U; i < stream_cnt; i++) { - struct bt_bap_stream *stream = &g_streams[i]; - int err; - - if (g_sinks[i] == NULL) { - break; - } - - err = codec_configure_stream(stream, g_sinks[i]); - if (err != 0) { - FAIL("Unable to configure stream[%zu]: %d", i, err); - return; - } - } -} - -static void qos_configure_streams(struct bt_bap_unicast_group *unicast_group, - size_t stream_cnt) -{ - int err; - - UNSET_FLAG(flag_stream_qos_configured); - - err = bt_bap_stream_qos(default_conn, unicast_group); - if (err != 0) { - FAIL("Unable to QoS configure streams: %d", err); - - return; - } - - while (atomic_get(&flag_stream_qos_configured) != stream_cnt) { - (void)k_sleep(K_MSEC(1)); - } -} - -static int enable_stream(struct bt_bap_stream *stream) -{ - int err; - - UNSET_FLAG(flag_stream_enabled); - - err = bt_bap_stream_enable(stream, NULL, 0); - if (err != 0) { - FAIL("Could not enable stream: %d\n", err); - - return err; - } - - WAIT_FOR_FLAG(flag_stream_enabled); - - return 0; -} - -static void enable_streams(size_t stream_cnt) -{ - for (size_t i = 0U; i < stream_cnt; i++) { - struct bt_bap_stream *stream = &g_streams[i]; - int err; - - err = enable_stream(stream); - if (err != 0) { - FAIL("Unable to enable stream[%zu]: %d", - i, err); - - return; - } - } -} - -static int start_stream(struct bt_bap_stream *stream) -{ - int err; - - UNSET_FLAG(flag_stream_started); - - err = bt_bap_stream_start(stream); - if (err != 0) { - FAIL("Could not start stream: %d\n", err); - - return err; - } - - WAIT_FOR_FLAG(flag_stream_started); - - return 0; -} - -static void start_streams(size_t stream_cnt) -{ - for (size_t i = 0U; i < 1; i++) { - struct bt_bap_stream *stream = &g_streams[i]; - int err; - - err = start_stream(stream); - if (err != 0) { - FAIL("Unable to start stream[%zu]: %d", i, err); - - return; - } - } -} - -static size_t release_streams(size_t stream_cnt) -{ - for (size_t i = 0; i < stream_cnt; i++) { - int err; - - if (g_sinks[i] == NULL) { - break; - } - - UNSET_FLAG(flag_operation_success); - UNSET_FLAG(flag_stream_released); - - err = bt_bap_stream_release(&g_streams[i]); - if (err != 0) { - FAIL("Unable to release stream[%zu]: %d", i, err); - return 0; - } - - WAIT_FOR_FLAG(flag_operation_success); - WAIT_FOR_FLAG(flag_stream_released); - } - - return stream_cnt; -} - - -static size_t create_unicast_group(struct bt_bap_unicast_group **unicast_group) -{ - struct bt_bap_unicast_group_stream_pair_param pair_params[ARRAY_SIZE(g_streams)]; - struct bt_bap_unicast_group_stream_param stream_params[ARRAY_SIZE(g_streams)]; - struct bt_bap_unicast_group_param param; - size_t stream_cnt = 0; - int err; - - for (stream_cnt = 0U; - stream_cnt < MIN(ARRAY_SIZE(g_sinks), ARRAY_SIZE(g_streams)); - stream_cnt++) { - if (g_sinks[stream_cnt] == NULL) { - break; - } - - stream_params[stream_cnt].stream = &g_streams[stream_cnt]; - stream_params[stream_cnt].qos = &preset_16_2_1.qos; - pair_params[stream_cnt].rx_param = NULL; - pair_params[stream_cnt].tx_param = &stream_params[stream_cnt]; - } - - if (stream_cnt == 0U) { - FAIL("No streams added to group"); - - return 0; - } - - param.params = pair_params; - param.params_count = stream_cnt; - param.packing = BT_ISO_PACKING_SEQUENTIAL; - - /* Require controller support for CIGs */ - printk("Creating unicast group\n"); - err = bt_bap_unicast_group_create(¶m, unicast_group); - if (err != 0) { - FAIL("Unable to create unicast group: %d", err); - - return 0; - } - - return stream_cnt; -} - -static void delete_unicast_group(struct bt_bap_unicast_group *unicast_group) -{ - int err; - - /* Require controller support for CIGs */ - err = bt_bap_unicast_group_delete(unicast_group); - if (err != 0) { - FAIL("Unable to delete unicast group: %d", err); - return; - } -} - -static void test_main(void) -{ - const unsigned int iterations = 3; - - init(); - - scan_and_connect(); - - exchange_mtu(); - - discover_sink(); - - /* Run the stream setup multiple time to ensure states are properly - * set and reset - */ - for (unsigned int i = 0U; i < iterations; i++) { - struct bt_bap_unicast_group *unicast_group; - size_t stream_cnt; - - printk("\n########### Running iteration #%u\n\n", i); - - printk("Creating unicast group\n"); - stream_cnt = create_unicast_group(&unicast_group); - - printk("Codec configuring streams\n"); - codec_configure_streams(stream_cnt); - - printk("QoS configuring streams\n"); - qos_configure_streams(unicast_group, stream_cnt); - - printk("Enabling streams\n"); - enable_streams(stream_cnt); - - printk("Starting streams\n"); - start_streams(stream_cnt); - - printk("Releasing streams\n"); - release_streams(stream_cnt); - - /* Test removing streams from group after creation */ - printk("Deleting unicast group\n"); - delete_unicast_group(unicast_group); - unicast_group = NULL; - } - - - PASS("Unicast client passed\n"); -} - -static const struct bst_test_instance test_unicast_client[] = { - { - .test_id = "unicast_client", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_unicast_client_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_unicast_client); -} - -#else /* !(CONFIG_BT_BAP_UNICAST_CLIENT) */ - -struct bst_test_list *test_unicast_client_install(struct bst_test_list *tests) -{ - return tests; -} - -#endif /* CONFIG_BT_BAP_UNICAST_CLIENT */ diff --git a/tests/bluetooth/bsim/audio/src/bap_unicast_common.c b/tests/bluetooth/bsim/audio/src/bap_unicast_common.c deleted file mode 100644 index c335a1929fb..00000000000 --- a/tests/bluetooth/bsim/audio/src/bap_unicast_common.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2021-2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "common.h" -#include "bap_unicast_common.h" - -void print_hex(const uint8_t *ptr, size_t len) -{ - while (len-- != 0) { - printk("%02x", *ptr++); - } -} - -void print_codec(const struct bt_codec *codec) -{ - printk("codec 0x%02x cid 0x%04x vid 0x%04x count %u\n", - codec->id, codec->cid, codec->vid, codec->data_count); - - for (uint8_t i = 0; i < codec->data_count; i++) { - printk("data #%u: type 0x%02x len %u\n", - i, codec->data[i].data.type, - codec->data[i].data.data_len); - print_hex(codec->data[i].data.data, - codec->data[i].data.data_len - - sizeof(codec->data[i].data.type)); - printk("\n"); - } - - for (uint8_t i = 0; i < codec->meta_count; i++) { - printk("meta #%u: type 0x%02x len %u\n", - i, codec->meta[i].data.type, - codec->meta[i].data.data_len); - print_hex(codec->meta[i].data.data, - codec->meta[i].data.data_len - - sizeof(codec->meta[i].data.type)); - printk("\n"); - } -} - -void print_qos(const struct bt_codec_qos *qos) -{ - printk("QoS: interval %u framing 0x%02x phy 0x%02x sdu %u " - "rtn %u latency %u pd %u\n", - qos->interval, qos->framing, qos->phy, qos->sdu, - qos->rtn, qos->latency, qos->pd); -} diff --git a/tests/bluetooth/bsim/audio/src/bap_unicast_common.h b/tests/bluetooth/bsim/audio/src/bap_unicast_common.h deleted file mode 100644 index acc8ccd9634..00000000000 --- a/tests/bluetooth/bsim/audio/src/bap_unicast_common.h +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Common functions and helpers for unicast audio BSIM audio tests - * - * Copyright (c) 2021-2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef ZEPHYR_TEST_BSIM_BT_AUDIO_TEST_UNICAST_COMMON_ -#define ZEPHYR_TEST_BSIM_BT_AUDIO_TEST_UNICAST_COMMON_ - -#include -#include - -void print_hex(const uint8_t *ptr, size_t len); -void print_codec(const struct bt_codec *codec); -void print_qos(const struct bt_codec_qos *qos); - -#endif /* ZEPHYR_TEST_BSIM_BT_AUDIO_TEST_UNICAST_COMMON_ */ diff --git a/tests/bluetooth/bsim/audio/src/bap_unicast_server_test.c b/tests/bluetooth/bsim/audio/src/bap_unicast_server_test.c deleted file mode 100644 index 650442c8b71..00000000000 --- a/tests/bluetooth/bsim/audio/src/bap_unicast_server_test.c +++ /dev/null @@ -1,396 +0,0 @@ -/* - * Copyright (c) 2021-2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#if defined(CONFIG_BT_BAP_UNICAST_SERVER) - -#include -#include -#include -#include -#include "common.h" -#include "bap_unicast_common.h" - -extern enum bst_result_t bst_result; - -#define CHANNEL_COUNT_1 BIT(0) - -static struct bt_codec lc3_codec = - BT_CODEC_LC3(BT_CODEC_LC3_FREQ_16KHZ, BT_CODEC_LC3_DURATION_10, CHANNEL_COUNT_1, 40u, 40u, - 1u, (BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | BT_AUDIO_CONTEXT_TYPE_MEDIA)); - -static struct bt_bap_stream streams[CONFIG_BT_ASCS_ASE_SNK_COUNT + CONFIG_BT_ASCS_ASE_SRC_COUNT]; - -static const struct bt_codec_qos_pref qos_pref = - BT_CODEC_QOS_PREF(true, BT_GAP_LE_PHY_2M, 0x02, 10, 40000, 40000, 40000, 40000); - -/* TODO: Expand with BAP data */ -static const struct bt_data unicast_server_ad[] = { - BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), - BT_DATA_BYTES(BT_DATA_UUID16_ALL, BT_UUID_16_ENCODE(BT_UUID_ASCS_VAL)), -}; - -CREATE_FLAG(flag_connected); -CREATE_FLAG(flag_stream_configured); - -static void print_ase_info(struct bt_bap_ep *ep, void *user_data) -{ - struct bt_bap_ep_info info; - - bt_bap_ep_get_info(ep, &info); - printk("ASE info: id %u state %u dir %u\n", info.id, info.state, info.dir); -} - -static struct bt_bap_stream *stream_alloc(void) -{ - for (size_t i = 0; i < ARRAY_SIZE(streams); i++) { - struct bt_bap_stream *stream = &streams[i]; - - if (!stream->conn) { - return stream; - } - } - - return NULL; -} - -static int lc3_config(struct bt_conn *conn, const struct bt_bap_ep *ep, enum bt_audio_dir dir, - const struct bt_codec *codec, struct bt_bap_stream **stream, - struct bt_codec_qos_pref *const pref) -{ - printk("ASE Codec Config: conn %p ep %p dir %u\n", conn, ep, dir); - - print_codec(codec); - - *stream = stream_alloc(); - if (*stream == NULL) { - printk("No streams available\n"); - - return -ENOMEM; - } - - printk("ASE Codec Config stream %p\n", *stream); - - bt_bap_unicast_server_foreach_ep(conn, print_ase_info, NULL); - - SET_FLAG(flag_stream_configured); - - *pref = qos_pref; - - return 0; -} - -static int lc3_reconfig(struct bt_bap_stream *stream, enum bt_audio_dir dir, - const struct bt_codec *codec, struct bt_codec_qos_pref *const pref) -{ - printk("ASE Codec Reconfig: stream %p\n", stream); - - print_codec(codec); - - /* We only support one QoS at the moment, reject changes */ - return -ENOEXEC; -} - -static int lc3_qos(struct bt_bap_stream *stream, const struct bt_codec_qos *qos) -{ - printk("QoS: stream %p qos %p\n", stream, qos); - - print_qos(qos); - - return 0; -} - -static int lc3_enable(struct bt_bap_stream *stream, const struct bt_codec_data *meta, - size_t meta_count) -{ - printk("Enable: stream %p meta_count %zu\n", stream, meta_count); - - return 0; -} - -static int lc3_start(struct bt_bap_stream *stream) -{ - printk("Start: stream %p\n", stream); - - return 0; -} - -static bool valid_metadata_type(uint8_t type, uint8_t len) -{ - switch (type) { - case BT_AUDIO_METADATA_TYPE_PREF_CONTEXT: - case BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT: - if (len != 2) { - return false; - } - - return true; - case BT_AUDIO_METADATA_TYPE_STREAM_LANG: - if (len != 3) { - return false; - } - - return true; - case BT_AUDIO_METADATA_TYPE_PARENTAL_RATING: - if (len != 1) { - return false; - } - - return true; - case BT_AUDIO_METADATA_TYPE_EXTENDED: /* 1 - 255 octets */ - case BT_AUDIO_METADATA_TYPE_VENDOR: /* 1 - 255 octets */ - if (len < 1) { - return false; - } - - return true; - case BT_AUDIO_METADATA_TYPE_CCID_LIST: /* 2 - 254 octets */ - if (len < 2) { - return false; - } - - return true; - case BT_AUDIO_METADATA_TYPE_PROGRAM_INFO: /* 0 - 255 octets */ - case BT_AUDIO_METADATA_TYPE_PROGRAM_INFO_URI: /* 0 - 255 octets */ - return true; - default: - return false; - } -} - -static int lc3_metadata(struct bt_bap_stream *stream, const struct bt_codec_data *meta, - size_t meta_count) -{ - printk("Metadata: stream %p meta_count %zu\n", stream, meta_count); - - for (size_t i = 0; i < meta_count; i++) { - if (!valid_metadata_type(meta->data.type, meta->data.data_len)) { - printk("Invalid metadata type %u or length %u\n", meta->data.type, - meta->data.data_len); - - return -EINVAL; - } - } - - return 0; -} - -static int lc3_disable(struct bt_bap_stream *stream) -{ - printk("Disable: stream %p\n", stream); - - return 0; -} - -static int lc3_stop(struct bt_bap_stream *stream) -{ - printk("Stop: stream %p\n", stream); - - return 0; -} - -static int lc3_release(struct bt_bap_stream *stream) -{ - printk("Release: stream %p\n", stream); - - return 0; -} - -static const struct bt_bap_unicast_server_cb unicast_server_cb = { - .config = lc3_config, - .reconfig = lc3_reconfig, - .qos = lc3_qos, - .enable = lc3_enable, - .start = lc3_start, - .metadata = lc3_metadata, - .disable = lc3_disable, - .stop = lc3_stop, - .release = lc3_release, -}; - -static void stream_enabled_cb(struct bt_bap_stream *stream) -{ - struct bt_bap_ep_info ep_info; - int err; - - printk("Enabled: stream %p\n", stream); - - err = bt_bap_ep_get_info(stream->ep, &ep_info); - if (err != 0) { - FAIL("Failed to get ep info: %d\n", err); - return; - } - - if (ep_info.dir == BT_AUDIO_DIR_SINK) { - /* Automatically do the receiver start ready operation */ - err = bt_bap_stream_start(stream); - - if (err != 0) { - FAIL("Failed to start stream: %d\n", err); - return; - } - } -} - -static void stream_recv(struct bt_bap_stream *stream, const struct bt_iso_recv_info *info, - struct net_buf *buf) -{ - printk("Incoming audio on stream %p len %u\n", stream, buf->len); -} - -static struct bt_bap_stream_ops stream_ops = { - .enabled = stream_enabled_cb, - .recv = stream_recv -}; - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - SET_FLAG(flag_connected); -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - -static void init(void) -{ - static struct bt_pacs_cap cap = { - .codec = &lc3_codec, - }; - int err; - - err = bt_enable(NULL); - if (err != 0) { - FAIL("Bluetooth enable failed (err %d)\n", err); - return; - } - - printk("Bluetooth initialized\n"); - - bt_bap_unicast_server_register_cb(&unicast_server_cb); - - err = bt_pacs_cap_register(BT_AUDIO_DIR_SINK, &cap); - if (err != 0) { - FAIL("Failed to register capabilities: %d", err); - return; - } - - for (size_t i = 0; i < ARRAY_SIZE(streams); i++) { - bt_bap_stream_cb_register(&streams[i], &stream_ops); - } - - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, unicast_server_ad, ARRAY_SIZE(unicast_server_ad), - NULL, 0); - if (err != 0) { - FAIL("Advertising failed to start (err %d)\n", err); - return; - } -} - -static void set_location(void) -{ - int err; - - if (IS_ENABLED(CONFIG_BT_PAC_SNK_LOC)) { - err = bt_pacs_set_location(BT_AUDIO_DIR_SINK, BT_AUDIO_LOCATION_FRONT_CENTER); - if (err != 0) { - FAIL("Failed to set sink location (err %d)\n", err); - return; - } - } - - if (IS_ENABLED(CONFIG_BT_PAC_SRC_LOC)) { - err = bt_pacs_set_location(BT_AUDIO_DIR_SOURCE, (BT_AUDIO_LOCATION_FRONT_LEFT | - BT_AUDIO_LOCATION_FRONT_RIGHT)); - if (err != 0) { - FAIL("Failed to set source location (err %d)\n", err); - return; - } - } - - printk("Location successfully set\n"); -} - -static void set_available_contexts(void) -{ - int err; - - err = bt_pacs_set_supported_contexts(BT_AUDIO_DIR_SINK, - BT_AUDIO_CONTEXT_TYPE_MEDIA | - BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL); - if (IS_ENABLED(CONFIG_BT_PAC_SNK) && err != 0) { - FAIL("Failed to set sink supported contexts (err %d)\n", err); - return; - } - - err = bt_pacs_set_available_contexts(BT_AUDIO_DIR_SINK, - BT_AUDIO_CONTEXT_TYPE_MEDIA | - BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL); - if (IS_ENABLED(CONFIG_BT_PAC_SNK) && err != 0) { - FAIL("Failed to set sink available contexts (err %d)\n", err); - return; - } - - err = bt_pacs_set_supported_contexts(BT_AUDIO_DIR_SOURCE, - BT_AUDIO_CONTEXT_TYPE_NOTIFICATIONS); - if (IS_ENABLED(CONFIG_BT_PAC_SRC) && err != 0) { - FAIL("Failed to set source supported contexts (err %d)\n", err); - return; - } - - err = bt_pacs_set_available_contexts(BT_AUDIO_DIR_SOURCE, - BT_AUDIO_CONTEXT_TYPE_NOTIFICATIONS); - if (IS_ENABLED(CONFIG_BT_PAC_SRC) && err != 0) { - FAIL("Failed to set source available contexts (err %d)\n", err); - return; - } - - printk("Available contexts successfully set\n"); -} - -static void test_main(void) -{ - init(); - - set_location(); - set_available_contexts(); - - /* TODO: When babblesim supports ISO, wait for audio stream to pass */ - - WAIT_FOR_FLAG(flag_connected); - WAIT_FOR_FLAG(flag_stream_configured); - PASS("Unicast server passed\n"); -} - -static const struct bst_test_instance test_unicast_server[] = {{.test_id = "unicast_server", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main}, - BSTEST_END_MARKER}; - -struct bst_test_list *test_unicast_server_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_unicast_server); -} - -#else /* !(CONFIG_BT_BAP_UNICAST_SERVER) */ - -struct bst_test_list *test_unicast_server_install(struct bst_test_list *tests) -{ - return tests; -} - -#endif /* CONFIG_BT_BAP_UNICAST_SERVER */ diff --git a/tests/bluetooth/bsim/audio/src/bass_broadcaster_test.c b/tests/bluetooth/bsim/audio/src/bass_broadcaster_test.c deleted file mode 100644 index 2d4ed6f356c..00000000000 --- a/tests/bluetooth/bsim/audio/src/bass_broadcaster_test.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2021 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "common.h" - -extern enum bst_result_t bst_result; - -/* TODO: Deprecate in favor of broadcast_source_test */ - -#define BROADCAST_ID_ENCODE(broadcast_id) \ - (((broadcast_id) >> 0) & 0xFF), \ - (((broadcast_id) >> 8) & 0xFF), \ - (((broadcast_id) >> 16) & 0xFF) - -static void test_main(void) -{ - int err; - uint32_t broadcast_id = 1234; - struct bt_le_ext_adv *adv; - struct bt_data ad[2] = { - BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR), - BT_DATA_BYTES(BT_DATA_SVC_DATA16, - BT_UUID_16_ENCODE(BT_UUID_BROADCAST_AUDIO_VAL), - BROADCAST_ID_ENCODE(broadcast_id)) - }; - - err = bt_enable(NULL); - if (err) { - FAIL("Bluetooth init failed (err %d)\n", err); - return; - } - - printk("Bluetooth initialized\n"); - - /* Create a non-connectable non-scannable advertising set */ - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_NCONN_NAME, NULL, &adv); - if (err) { - FAIL("Failed to create advertising set (err %d)\n", err); - return; - } - - /* Set periodic advertising parameters */ - err = bt_le_per_adv_set_param(adv, BT_LE_PER_ADV_DEFAULT); - if (err) { - FAIL("Failed to set periodic advertising parameters (err %d)\n", err); - return; - } - - /* Set adv data */ - err = bt_le_ext_adv_set_data(adv, ad, ARRAY_SIZE(ad), NULL, 0); - if (err) { - FAIL("Failed to set advertising data (err %d)\n", err); - return; - } - - /* Enable Periodic Advertising */ - err = bt_le_per_adv_start(adv); - if (err) { - FAIL("Failed to enable periodic advertising (err %d)\n", err); - return; - } - - /* Start extended advertising */ - err = bt_le_ext_adv_start(adv, BT_LE_EXT_ADV_START_DEFAULT); - if (err) { - FAIL("Failed to start extended advertising (err %d)\n", err); - return; - } - - printk("Advertising successfully started\n"); - - k_sleep(K_SECONDS(10)); - - PASS("BASS broadcaster passed\n"); -} - -static const struct bst_test_instance test_bass_broadcaster[] = { - { - .test_id = "bass_broadcaster", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_bass_broadcaster_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_bass_broadcaster); -} diff --git a/tests/bluetooth/bsim/audio/src/broadcast_sink_test.c b/tests/bluetooth/bsim/audio/src/broadcast_sink_test.c deleted file mode 100644 index 94967ddcfa2..00000000000 --- a/tests/bluetooth/bsim/audio/src/broadcast_sink_test.c +++ /dev/null @@ -1,332 +0,0 @@ -/* - * Copyright (c) 2021-2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#if defined(CONFIG_BT_BAP_BROADCAST_SINK) - -#include -#include -#include -#include -#include -#include "common.h" - -extern enum bst_result_t bst_result; - -CREATE_FLAG(broadcaster_found); -CREATE_FLAG(base_received); -CREATE_FLAG(flag_base_metadata_updated); -CREATE_FLAG(pa_synced); -CREATE_FLAG(flag_syncable); -CREATE_FLAG(pa_sync_lost); -CREATE_FLAG(flag_received); - -static struct bt_bap_broadcast_sink *g_sink; -static struct bt_bap_stream broadcast_sink_streams[CONFIG_BT_BAP_BROADCAST_SNK_STREAM_COUNT]; -static struct bt_bap_stream *streams[ARRAY_SIZE(broadcast_sink_streams)]; -static struct bt_bap_lc3_preset preset_16_2_1 = BT_BAP_LC3_BROADCAST_PRESET_16_2_1( - BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED); - -static K_SEM_DEFINE(sem_started, 0U, ARRAY_SIZE(streams)); -static K_SEM_DEFINE(sem_stopped, 0U, ARRAY_SIZE(streams)); - -static struct bt_codec_data metadata[CONFIG_BT_CODEC_MAX_METADATA_COUNT]; - -/* Create a mask for the maximum BIS we can sync to using the number of streams - * we have. We add an additional 1 since the bis indexes start from 1 and not - * 0. - */ -static const uint32_t bis_index_mask = BIT_MASK(ARRAY_SIZE(streams) + 1U); -static uint32_t bis_index_bitfield; - -static bool scan_recv_cb(const struct bt_le_scan_recv_info *info, - struct net_buf_simple *ad, - uint32_t broadcast_id) -{ - SET_FLAG(broadcaster_found); - - return true; -} - -static void scan_term_cb(int err) -{ - if (err != 0) { - FAIL("Scan terminated with error: %d", err); - } -} - -static void pa_synced_cb(struct bt_bap_broadcast_sink *sink, - struct bt_le_per_adv_sync *sync, - uint32_t broadcast_id) -{ - if (g_sink != NULL) { - FAIL("Unexpected PA sync"); - return; - } - - printk("PA synced for broadcast sink %p with broadcast ID 0x%06X\n", - sink, broadcast_id); - - g_sink = sink; - - SET_FLAG(pa_synced); -} - -static void base_recv_cb(struct bt_bap_broadcast_sink *sink, const struct bt_bap_base *base) -{ - uint32_t base_bis_index_bitfield = 0U; - - if (TEST_FLAG(base_received)) { - - if (base->subgroup_count > 0 && - memcmp(metadata, base->subgroups[0].codec.meta, - sizeof(base->subgroups[0].codec.meta)) != 0) { - - (void)memcpy(metadata, base->subgroups[0].codec.meta, - sizeof(base->subgroups[0].codec.meta)); - - SET_FLAG(flag_base_metadata_updated); - } - - return; - } - - printk("Received BASE with %u subgroups from broadcast sink %p\n", - base->subgroup_count, sink); - - - for (size_t i = 0U; i < base->subgroup_count; i++) { - for (size_t j = 0U; j < base->subgroups[i].bis_count; j++) { - const uint8_t index = base->subgroups[i].bis_data[j].index; - - base_bis_index_bitfield |= BIT(index); - } - } - - bis_index_bitfield = base_bis_index_bitfield & bis_index_mask; - - SET_FLAG(base_received); -} - -static void syncable_cb(struct bt_bap_broadcast_sink *sink, bool encrypted) -{ - printk("Broadcast sink %p syncable with%s encryption\n", - sink, encrypted ? "" : "out"); - SET_FLAG(flag_syncable); -} - -static void pa_sync_lost_cb(struct bt_bap_broadcast_sink *sink) -{ - if (g_sink == NULL) { - FAIL("Unexpected PA sync lost"); - return; - } - - if (TEST_FLAG(pa_sync_lost)) { - return; - } - - printk("Sink %p disconnected\n", sink); - - g_sink = NULL; - - SET_FLAG(pa_sync_lost); -} - -static struct bt_bap_broadcast_sink_cb broadcast_sink_cbs = { - .scan_recv = scan_recv_cb, - .scan_term = scan_term_cb, - .base_recv = base_recv_cb, - .pa_synced = pa_synced_cb, - .syncable = syncable_cb, - .pa_sync_lost = pa_sync_lost_cb -}; - -static struct bt_pacs_cap cap = { - .codec = &preset_16_2_1.codec, -}; - -static void started_cb(struct bt_bap_stream *stream) -{ - printk("Stream %p started\n", stream); - k_sem_give(&sem_started); -} - -static void stopped_cb(struct bt_bap_stream *stream, uint8_t reason) -{ - printk("Stream %p stopped with reason 0x%02X\n", stream, reason); - k_sem_give(&sem_stopped); -} - -static void recv_cb(struct bt_bap_stream *stream, - const struct bt_iso_recv_info *info, - struct net_buf *buf) -{ - SET_FLAG(flag_received); -} - -static struct bt_bap_stream_ops stream_ops = { - .started = started_cb, - .stopped = stopped_cb, - .recv = recv_cb -}; - -static int init(void) -{ - int err; - - err = bt_enable(NULL); - if (err) { - FAIL("Bluetooth enable failed (err %d)\n", err); - return err; - } - - printk("Bluetooth initialized\n"); - - err = bt_pacs_cap_register(BT_AUDIO_DIR_SINK, &cap); - if (err) { - FAIL("Capability register failed (err %d)\n", err); - return err; - } - - bt_bap_broadcast_sink_register_cb(&broadcast_sink_cbs); - - UNSET_FLAG(broadcaster_found); - UNSET_FLAG(base_received); - UNSET_FLAG(pa_synced); - - for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) { - streams[i] = &broadcast_sink_streams[i]; - bt_bap_stream_cb_register(streams[i], &stream_ops); - } - - return 0; -} - -static void test_common(void) -{ - int err; - - err = init(); - if (err) { - FAIL("Init failed (err %d)\n", err); - return; - } - - printk("Scanning for broadcast sources\n"); - err = bt_bap_broadcast_sink_scan_start(BT_LE_SCAN_ACTIVE); - if (err != 0) { - FAIL("Unable to start scan for broadcast sources: %d", err); - return; - } - - WAIT_FOR_FLAG(broadcaster_found); - printk("Broadcast source found, waiting for PA sync\n"); - WAIT_FOR_FLAG(pa_synced); - printk("Broadcast source PA synced, waiting for BASE\n"); - WAIT_FOR_FLAG(base_received); - printk("BASE received\n"); - - printk("Waiting for BIG syncable\n"); - WAIT_FOR_FLAG(flag_syncable); - - printk("Syncing the sink\n"); - err = bt_bap_broadcast_sink_sync(g_sink, bis_index_bitfield, streams, NULL); - if (err != 0) { - FAIL("Unable to sync the sink: %d\n", err); - return; - } - - /* Wait for all to be started */ - printk("Waiting for streams to be started\n"); - for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) { - k_sem_take(&sem_started, K_FOREVER); - } - - printk("Waiting for data\n"); - WAIT_FOR_FLAG(flag_received); - - /* Ensure that we also see the metadata update */ - printk("Waiting for metadata update\n"); - WAIT_FOR_FLAG(flag_base_metadata_updated) - -} - -static void test_main(void) -{ - test_common(); - - /* The order of PA sync lost and BIG Sync lost is irrelevant - * and depend on timeout parameters. We just wait for PA first, but - * either way will work. - */ - printk("Waiting for PA disconnected\n"); - WAIT_FOR_FLAG(pa_sync_lost); - - printk("Waiting for streams to be stopped\n"); - for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) { - k_sem_take(&sem_stopped, K_FOREVER); - } - - PASS("Broadcast sink passed\n"); -} - -static void test_sink_disconnect(void) -{ - int err; - - test_common(); - - err = bt_bap_broadcast_sink_stop(g_sink); - if (err != 0) { - FAIL("Unable to stop sink: %d", err); - return; - } - - printk("Waiting for streams to be stopped\n"); - for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) { - k_sem_take(&sem_stopped, K_FOREVER); - } - - err = bt_bap_broadcast_sink_delete(g_sink); - if (err != 0) { - FAIL("Unable to delete sink: %d", err); - return; - } - /* No "sync lost" event is generated when we initialized the disconnect */ - g_sink = NULL; - - PASS("Broadcast sink disconnect passed\n"); -} - -static const struct bst_test_instance test_broadcast_sink[] = { - { - .test_id = "broadcast_sink", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main - }, - { - .test_id = "broadcast_sink_disconnect", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_sink_disconnect - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_broadcast_sink_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_broadcast_sink); -} - -#else /* !CONFIG_BT_BAP_BROADCAST_SINK */ - -struct bst_test_list *test_broadcast_sink_install(struct bst_test_list *tests) -{ - return tests; -} - -#endif /* CONFIG_BT_BAP_BROADCAST_SINK */ diff --git a/tests/bluetooth/bsim/audio/src/broadcast_source_test.c b/tests/bluetooth/bsim/audio/src/broadcast_source_test.c deleted file mode 100644 index 715e7826ce9..00000000000 --- a/tests/bluetooth/bsim/audio/src/broadcast_source_test.c +++ /dev/null @@ -1,387 +0,0 @@ -/* - * Copyright (c) 2021-2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#if defined(CONFIG_BT_BAP_BROADCAST_SOURCE) - -#include -#include -#include -#include -#include "common.h" - -/* When BROADCAST_ENQUEUE_COUNT > 1 we can enqueue enough buffers to ensure that - * the controller is never idle - */ -#define BROADCAST_ENQUEUE_COUNT 2U -#define TOTAL_BUF_NEEDED (BROADCAST_ENQUEUE_COUNT * CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT) - -BUILD_ASSERT(CONFIG_BT_ISO_TX_BUF_COUNT >= TOTAL_BUF_NEEDED, - "CONFIG_BT_ISO_TX_BUF_COUNT should be at least " - "BROADCAST_ENQUEUE_COUNT * CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT"); - -NET_BUF_POOL_FIXED_DEFINE(tx_pool, - TOTAL_BUF_NEEDED, - BT_ISO_SDU_BUF_SIZE(CONFIG_BT_ISO_TX_MTU), 8, NULL); - -extern enum bst_result_t bst_result; -static struct bt_bap_stream broadcast_source_streams[CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT]; -static struct bt_bap_stream *streams[ARRAY_SIZE(broadcast_source_streams)]; -static struct bt_bap_lc3_preset preset_16_2_1 = BT_BAP_LC3_BROADCAST_PRESET_16_2_1( - BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED); -static struct bt_bap_lc3_preset preset_16_2_2 = BT_BAP_LC3_BROADCAST_PRESET_16_2_2( - BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED); -CREATE_FLAG(flag_stopping); - -static K_SEM_DEFINE(sem_started, 0U, ARRAY_SIZE(streams)); -static K_SEM_DEFINE(sem_stopped, 0U, ARRAY_SIZE(streams)); - -static void started_cb(struct bt_bap_stream *stream) -{ - printk("Stream %p started\n", stream); - k_sem_give(&sem_started); -} - -static void stopped_cb(struct bt_bap_stream *stream, uint8_t reason) -{ - printk("Stream %p stopped with reason 0x%02X\n", stream, reason); - k_sem_give(&sem_stopped); -} - -static void sent_cb(struct bt_bap_stream *stream) -{ - static uint8_t mock_data[CONFIG_BT_ISO_TX_MTU]; - static bool mock_data_initialized; - static uint16_t seq_num; - struct net_buf *buf; - int ret; - - if (TEST_FLAG(flag_stopping)) { - return; - } - - if (!mock_data_initialized) { - for (size_t i = 0U; i < ARRAY_SIZE(mock_data); i++) { - /* Initialize mock data */ - mock_data[i] = (uint8_t)i; - } - mock_data_initialized = true; - } - - buf = net_buf_alloc(&tx_pool, K_FOREVER); - if (buf == NULL) { - printk("Could not allocate buffer when sending on %p\n", - stream); - return; - } - - net_buf_reserve(buf, BT_ISO_CHAN_SEND_RESERVE); - /* Use preset_16_2_1 as that is the config we end up using */ - net_buf_add_mem(buf, mock_data, preset_16_2_1.qos.sdu); - ret = bt_bap_stream_send(stream, buf, seq_num++, - BT_ISO_TIMESTAMP_NONE); - if (ret < 0) { - /* This will end broadcasting on this stream. */ - printk("Unable to broadcast data on %p: %d\n", stream, ret); - net_buf_unref(buf); - return; - } -} - -static struct bt_bap_stream_ops stream_ops = { - .started = started_cb, - .stopped = stopped_cb, - .sent = sent_cb -}; - -static int setup_broadcast_source(struct bt_bap_broadcast_source **source) -{ - struct bt_codec_data bis_codec_data = BT_CODEC_DATA(BT_CODEC_CONFIG_LC3_FREQ, - BT_CODEC_CONFIG_LC3_FREQ_16KHZ); - struct bt_bap_broadcast_source_stream_param - stream_params[ARRAY_SIZE(broadcast_source_streams)]; - struct bt_bap_broadcast_source_subgroup_param - subgroup_params[CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT]; - struct bt_bap_broadcast_source_create_param create_param; - int err; - - (void)memset(broadcast_source_streams, 0, - sizeof(broadcast_source_streams)); - - for (size_t i = 0; i < ARRAY_SIZE(stream_params); i++) { - stream_params[i].stream = &broadcast_source_streams[i]; - bt_bap_stream_cb_register(stream_params[i].stream, - &stream_ops); - stream_params[i].data_count = 1U; - stream_params[i].data = &bis_codec_data; - } - - for (size_t i = 0U; i < ARRAY_SIZE(subgroup_params); i++) { - subgroup_params[i].params_count = 1U; - subgroup_params[i].params = &stream_params[i]; - subgroup_params[i].codec = &preset_16_2_1.codec; - } - - create_param.params_count = ARRAY_SIZE(subgroup_params); - create_param.params = subgroup_params; - create_param.qos = &preset_16_2_2.qos; - create_param.packing = BT_ISO_PACKING_SEQUENTIAL; - create_param.encryption = false; - - printk("Creating broadcast source with %zu subgroups and %zu streams\n", - ARRAY_SIZE(subgroup_params), ARRAY_SIZE(stream_params)); - err = bt_bap_broadcast_source_create(&create_param, source); - if (err != 0) { - printk("Unable to create broadcast source: %d\n", err); - return err; - } - - return 0; -} - -static int setup_extended_adv(struct bt_bap_broadcast_source *source, struct bt_le_ext_adv **adv) -{ - /* Broadcast Audio Streaming Endpoint advertising data */ - NET_BUF_SIMPLE_DEFINE(ad_buf, - BT_UUID_SIZE_16 + BT_AUDIO_BROADCAST_ID_SIZE); - NET_BUF_SIMPLE_DEFINE(base_buf, 128); - struct bt_data ext_ad; - struct bt_data per_ad; - uint32_t broadcast_id; - int err; - - /* Create a non-connectable non-scannable advertising set */ - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_NCONN_NAME, NULL, adv); - if (err != 0) { - printk("Unable to create extended advertising set: %d\n", err); - return err; - } - - /* Set periodic advertising parameters */ - err = bt_le_per_adv_set_param(*adv, BT_LE_PER_ADV_DEFAULT); - if (err) { - printk("Failed to set periodic advertising parameters: %d\n", - err); - return err; - } - - err = bt_bap_broadcast_source_get_id(source, &broadcast_id); - if (err != 0) { - printk("Unable to get broadcast ID: %d\n", err); - return err; - } - - /* Setup extended advertising data */ - net_buf_simple_add_le16(&ad_buf, BT_UUID_BROADCAST_AUDIO_VAL); - net_buf_simple_add_le24(&ad_buf, broadcast_id); - ext_ad.type = BT_DATA_SVC_DATA16; - ext_ad.data_len = ad_buf.len; - ext_ad.data = ad_buf.data; - err = bt_le_ext_adv_set_data(*adv, &ext_ad, 1, NULL, 0); - if (err != 0) { - printk("Failed to set extended advertising data: %d\n", err); - return err; - } - - /* Setup periodic advertising data */ - err = bt_bap_broadcast_source_get_base(source, &base_buf); - if (err != 0) { - printk("Failed to get encoded BASE: %d\n", err); - return err; - } - - per_ad.type = BT_DATA_SVC_DATA16; - per_ad.data_len = base_buf.len; - per_ad.data = base_buf.data; - err = bt_le_per_adv_set_data(*adv, &per_ad, 1); - if (err != 0) { - printk("Failed to set periodic advertising data: %d\n", err); - return err; - } - - /* Start extended advertising */ - err = bt_le_ext_adv_start(*adv, BT_LE_EXT_ADV_START_DEFAULT); - if (err) { - printk("Failed to start extended advertising: %d\n", err); - return err; - } - - /* Enable Periodic Advertising */ - err = bt_le_per_adv_start(*adv); - if (err) { - printk("Failed to enable periodic advertising: %d\n", err); - return err; - } - - return 0; -} - -static int stop_extended_adv(struct bt_le_ext_adv *adv) -{ - int err; - - err = bt_le_per_adv_stop(adv); - if (err) { - printk("Failed to stop periodic advertising: %d\n", err); - return err; - } - - err = bt_le_ext_adv_stop(adv); - if (err) { - printk("Failed to stop extended advertising: %d\n", err); - return err; - } - - err = bt_le_ext_adv_delete(adv); - if (err) { - printk("Failed to delete extended advertising: %d\n", err); - return err; - } - - return 0; -} - -static void test_main(void) -{ - struct bt_codec_data new_metadata[1] = - BT_CODEC_LC3_CONFIG_META(BT_AUDIO_CONTEXT_TYPE_ALERTS); - struct bt_bap_broadcast_source *source; - struct bt_le_ext_adv *adv; - int err; - - err = bt_enable(NULL); - if (err) { - FAIL("Bluetooth init failed (err %d)\n", err); - return; - } - - printk("Bluetooth initialized\n"); - - err = setup_broadcast_source(&source); - if (err != 0) { - FAIL("Unable to setup broadcast source: %d\n", err); - return; - } - - err = setup_extended_adv(source, &adv); - if (err != 0) { - FAIL("Failed to setup extended advertising: %d\n", err); - return; - } - - printk("Reconfiguring broadcast source\n"); - err = bt_bap_broadcast_source_reconfig(source, &preset_16_2_1.codec, &preset_16_2_1.qos); - if (err != 0) { - FAIL("Unable to reconfigure broadcast source: %d\n", err); - return; - } - - printk("Starting broadcast source\n"); - err = bt_bap_broadcast_source_start(source, adv); - if (err != 0) { - FAIL("Unable to start broadcast source: %d\n", err); - return; - } - - /* Wait for all to be started */ - printk("Waiting for streams to be started\n"); - for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) { - k_sem_take(&sem_started, K_FOREVER); - } - - /* Initialize sending */ - for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) { - for (unsigned int j = 0U; j < BROADCAST_ENQUEUE_COUNT; j++) { - sent_cb(streams[i]); - } - } - - /* Keeping running for a little while */ - k_sleep(K_SECONDS(15)); - - /* Update metadata while streaming */ - printk("Updating metadata\n"); - err = bt_bap_broadcast_source_update_metadata(source, new_metadata, - ARRAY_SIZE(new_metadata)); - if (err != 0) { - FAIL("Failed to update metadata broadcast source: %d", err); - return; - } - - /* Keeping running for a little while */ - k_sleep(K_SECONDS(5)); - - printk("Stopping broadcast source\n"); - SET_FLAG(flag_stopping); - err = bt_bap_broadcast_source_stop(source); - if (err != 0) { - FAIL("Unable to stop broadcast source: %d\n", err); - return; - } - - /* Wait for all to be stopped */ - printk("Waiting for streams to be stopped\n"); - for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) { - k_sem_take(&sem_stopped, K_FOREVER); - } - - printk("Deleting broadcast source\n"); - err = bt_bap_broadcast_source_delete(source); - if (err != 0) { - FAIL("Unable to delete broadcast source: %d\n", err); - return; - } - source = NULL; - - - err = stop_extended_adv(adv); - if (err != 0) { - FAIL("Unable to stop extended advertising: %d\n", err); - return; - } - adv = NULL; - - /* Recreate broadcast source to verify that it's possible */ - printk("Recreating broadcast source\n"); - err = setup_broadcast_source(&source); - if (err != 0) { - FAIL("Unable to setup broadcast source: %d\n", err); - return; - } - - printk("Deleting broadcast source\n"); - err = bt_bap_broadcast_source_delete(source); - if (err != 0) { - FAIL("Unable to delete broadcast source: %d\n", err); - return; - } - source = NULL; - - PASS("Broadcast source passed\n"); -} - -static const struct bst_test_instance test_broadcast_source[] = { - { - .test_id = "broadcast_source", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_broadcast_source_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_broadcast_source); -} - -#else /* CONFIG_BT_BAP_BROADCAST_SOURCE */ - -struct bst_test_list *test_broadcast_source_install(struct bst_test_list *tests) -{ - return tests; -} - -#endif /* CONFIG_BT_BAP_BROADCAST_SOURCE */ diff --git a/tests/bluetooth/bsim/audio/src/cap_acceptor_test.c b/tests/bluetooth/bsim/audio/src/cap_acceptor_test.c deleted file mode 100644 index 71e48fac6e2..00000000000 --- a/tests/bluetooth/bsim/audio/src/cap_acceptor_test.c +++ /dev/null @@ -1,381 +0,0 @@ -/* - * Copyright (c) 2022-2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#if defined(CONFIG_BT_CAP_ACCEPTOR) - -#include -#include -#include -#include -#include "common.h" -#include "bap_unicast_common.h" - -extern enum bst_result_t bst_result; - -CREATE_FLAG(flag_broadcaster_found); -CREATE_FLAG(flag_base_received); -CREATE_FLAG(flag_pa_synced); -CREATE_FLAG(flag_syncable); -CREATE_FLAG(flag_received); -CREATE_FLAG(flag_pa_sync_lost); - -static struct bt_bap_broadcast_sink *g_broadcast_sink; -static struct bt_cap_stream broadcast_sink_streams[CONFIG_BT_BAP_BROADCAST_SNK_STREAM_COUNT]; -static struct bt_bap_lc3_preset broadcast_preset_16_2_1 = BT_BAP_LC3_BROADCAST_PRESET_16_2_1( - BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED); - -static K_SEM_DEFINE(sem_broadcast_started, 0U, ARRAY_SIZE(broadcast_sink_streams)); -static K_SEM_DEFINE(sem_broadcast_stopped, 0U, ARRAY_SIZE(broadcast_sink_streams)); - -/* Create a mask for the maximum BIS we can sync to using the number of - * broadcast_sink_streams we have. We add an additional 1 since the bis indexes - * start from 1 and not 0. - */ -static const uint32_t bis_index_mask = BIT_MASK(ARRAY_SIZE(broadcast_sink_streams) + 1U); -static uint32_t bis_index_bitfield; - -static bool scan_recv_cb(const struct bt_le_scan_recv_info *info, - struct net_buf_simple *ad, - uint32_t broadcast_id) -{ - SET_FLAG(flag_broadcaster_found); - - return true; -} - -static void scan_term_cb(int err) -{ - if (err != 0) { - FAIL("Scan terminated with error: %d", err); - } -} - -static void pa_synced_cb(struct bt_bap_broadcast_sink *sink, - struct bt_le_per_adv_sync *sync, - uint32_t broadcast_id) -{ - if (g_broadcast_sink != NULL) { - FAIL("Unexpected PA sync"); - return; - } - - printk("PA synced for broadcast sink %p with broadcast ID 0x%06X\n", - sink, broadcast_id); - - g_broadcast_sink = sink; - - SET_FLAG(flag_pa_synced); -} - -static bool valid_subgroup_metadata(const struct bt_bap_base_subgroup *subgroup) -{ - bool stream_context_found = false; - - for (size_t j = 0U; j < subgroup->codec.meta_count; j++) { - const struct bt_data *metadata = &subgroup->codec.meta[j].data; - - if (metadata->type == BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT) { - if (metadata->data_len != 2) { /* Stream context size */ - printk("Subgroup has invalid streaming context length: %u\n", - metadata->data_len); - return false; - } - - stream_context_found = true; - break; - } - } - - if (!stream_context_found) { - printk("Subgroup did not have streaming context\n"); - return false; - } - - return true; -} - -static void base_recv_cb(struct bt_bap_broadcast_sink *sink, const struct bt_bap_base *base) -{ - uint32_t base_bis_index_bitfield = 0U; - - if (TEST_FLAG(flag_base_received)) { - return; - } - - printk("Received BASE with %u subgroups from broadcast sink %p\n", - base->subgroup_count, sink); - - if (base->subgroup_count == 0) { - FAIL("base->subgroup_count was 0"); - return; - } - - - for (size_t i = 0U; i < base->subgroup_count; i++) { - const struct bt_bap_base_subgroup *subgroup = &base->subgroups[i]; - - for (size_t j = 0U; j < subgroup->bis_count; j++) { - const uint8_t index = subgroup->bis_data[j].index; - - base_bis_index_bitfield |= BIT(index); - } - - if (!valid_subgroup_metadata(subgroup)) { - FAIL("Subgroup[%zu] has invalid metadata\n", i); - return; - } - } - - bis_index_bitfield = base_bis_index_bitfield & bis_index_mask; - - SET_FLAG(flag_base_received); -} - -static void syncable_cb(struct bt_bap_broadcast_sink *sink, bool encrypted) -{ - printk("Broadcast sink %p syncable with%s encryption\n", - sink, encrypted ? "" : "out"); - SET_FLAG(flag_syncable); -} - -static void pa_sync_lost_cb(struct bt_bap_broadcast_sink *sink) -{ - if (g_broadcast_sink == NULL) { - FAIL("Unexpected PA sync lost"); - return; - } - - printk("Sink %p disconnected\n", sink); - - SET_FLAG(flag_pa_sync_lost); - - g_broadcast_sink = NULL; -} - -static struct bt_bap_broadcast_sink_cb broadcast_sink_cbs = { - .scan_recv = scan_recv_cb, - .scan_term = scan_term_cb, - .base_recv = base_recv_cb, - .pa_synced = pa_synced_cb, - .syncable = syncable_cb, - .pa_sync_lost = pa_sync_lost_cb -}; - -static void started_cb(struct bt_bap_stream *stream) -{ - printk("Stream %p started\n", stream); - k_sem_give(&sem_broadcast_started); -} - -static void stopped_cb(struct bt_bap_stream *stream, uint8_t reason) -{ - printk("Stream %p stopped with reason 0x%02X\n", stream, reason); - k_sem_give(&sem_broadcast_stopped); -} - -static void recv_cb(struct bt_bap_stream *stream, const struct bt_iso_recv_info *info, - struct net_buf *buf) -{ - SET_FLAG(flag_received); -} - -static struct bt_bap_stream_ops broadcast_stream_ops = { - .started = started_cb, .stopped = stopped_cb, .recv = recv_cb}; - -/* TODO: Expand with CAP service data */ -static const struct bt_data cap_acceptor_ad[] = { - BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), - BT_DATA_BYTES(BT_DATA_UUID16_ALL, BT_UUID_16_ENCODE(BT_UUID_CAS_VAL)), -}; - -static struct bt_csip_set_member_svc_inst *csip_set_member; - -CREATE_FLAG(flag_connected); - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - SET_FLAG(flag_connected); -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - -static void init(void) -{ - struct bt_csip_set_member_register_param csip_set_member_param = { - .set_size = 3, - .rank = 1, - .lockable = true, - /* Using the CSIP_SET_MEMBER test sample SIRK */ - .set_sirk = { 0xcd, 0xcc, 0x72, 0xdd, 0x86, 0x8c, 0xcd, 0xce, - 0x22, 0xfd, 0xa1, 0x21, 0x09, 0x7d, 0x7d, 0x45 }, - }; - - int err; - - err = bt_enable(NULL); - if (err != 0) { - FAIL("Bluetooth enable failed (err %d)\n", err); - return; - } - - printk("Bluetooth initialized\n"); - - if (IS_ENABLED(CONFIG_BT_CAP_ACCEPTOR_SET_MEMBER)) { - err = bt_cap_acceptor_register(&csip_set_member_param, - &csip_set_member); - if (err != 0) { - FAIL("CAP acceptor failed to register (err %d)\n", err); - return; - } - } - - if (IS_ENABLED(CONFIG_BT_BAP_UNICAST_SERVER)) { - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, cap_acceptor_ad, - ARRAY_SIZE(cap_acceptor_ad), NULL, 0); - if (err != 0) { - FAIL("Advertising failed to start (err %d)\n", err); - return; - } - } - - if (IS_ENABLED(CONFIG_BT_BAP_BROADCAST_SINK)) { - static struct bt_pacs_cap cap = { - .codec = &broadcast_preset_16_2_1.codec, - }; - - err = bt_pacs_cap_register(BT_AUDIO_DIR_SINK, &cap); - if (err != 0) { - FAIL("Broadcast capability register failed (err %d)\n", - err); - - return; - } - - bt_bap_broadcast_sink_register_cb(&broadcast_sink_cbs); - - UNSET_FLAG(flag_broadcaster_found); - UNSET_FLAG(flag_base_received); - UNSET_FLAG(flag_pa_synced); - - for (size_t i = 0U; i < ARRAY_SIZE(broadcast_sink_streams); i++) { - bt_cap_stream_ops_register(&broadcast_sink_streams[i], - &broadcast_stream_ops); - } - } -} - -static void test_cap_acceptor_unicast(void) -{ - init(); - - /* TODO: When babblesim supports ISO, wait for audio stream to pass */ - - WAIT_FOR_FLAG(flag_connected); - - PASS("CAP acceptor unicast passed\n"); -} - -static void test_cap_acceptor_broadcast(void) -{ - static struct bt_bap_stream *bap_streams[ARRAY_SIZE(broadcast_sink_streams)]; - int err; - - init(); - - printk("Scanning for broadcast sources\n"); - err = bt_bap_broadcast_sink_scan_start(BT_LE_SCAN_ACTIVE); - if (err != 0) { - FAIL("Unable to start scan for broadcast sources: %d", err); - return; - } - - WAIT_FOR_FLAG(flag_broadcaster_found); - printk("Broadcast source found, waiting for PA sync\n"); - WAIT_FOR_FLAG(flag_pa_synced); - printk("Broadcast source PA synced, waiting for BASE\n"); - WAIT_FOR_FLAG(flag_base_received); - printk("BASE received\n"); - - printk("Waiting for BIG syncable\n"); - WAIT_FOR_FLAG(flag_syncable); - - for (size_t i = 0U; i < ARRAY_SIZE(broadcast_sink_streams); i++) { - bap_streams[i] = &broadcast_sink_streams[i].bap_stream; - } - - printk("Syncing the sink\n"); - err = bt_bap_broadcast_sink_sync(g_broadcast_sink, bis_index_bitfield, bap_streams, NULL); - if (err != 0) { - FAIL("Unable to sync the sink: %d\n", err); - return; - } - - /* Wait for all to be started */ - printk("Waiting for broadcast_sink_streams to be started\n"); - for (size_t i = 0U; i < ARRAY_SIZE(broadcast_sink_streams); i++) { - k_sem_take(&sem_broadcast_started, K_FOREVER); - } - - printk("Waiting for data\n"); - WAIT_FOR_FLAG(flag_received); - - /* The order of PA sync lost and BIG Sync lost is irrelevant - * and depend on timeout parameters. We just wait for PA first, but - * either way will work. - */ - printk("Waiting for PA disconnected\n"); - WAIT_FOR_FLAG(flag_pa_sync_lost); - - printk("Waiting for streams to be stopped\n"); - for (size_t i = 0U; i < ARRAY_SIZE(broadcast_sink_streams); i++) { - k_sem_take(&sem_broadcast_stopped, K_FOREVER); - } - - PASS("CAP acceptor broadcast passed\n"); -} - -static const struct bst_test_instance test_cap_acceptor[] = { - { - .test_id = "cap_acceptor_unicast", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_cap_acceptor_unicast - }, - { - .test_id = "cap_acceptor_broadcast", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_cap_acceptor_broadcast - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_cap_acceptor_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_cap_acceptor); -} - -#else /* !(CONFIG_BT_CAP_ACCEPTOR) */ - -struct bst_test_list *test_cap_acceptor_install(struct bst_test_list *tests) -{ - return tests; -} - -#endif /* CONFIG_BT_CAP_ACCEPTOR */ diff --git a/tests/bluetooth/bsim/audio/src/cap_initiator_test.c b/tests/bluetooth/bsim/audio/src/cap_initiator_test.c deleted file mode 100644 index 5d6c0384f6b..00000000000 --- a/tests/bluetooth/bsim/audio/src/cap_initiator_test.c +++ /dev/null @@ -1,510 +0,0 @@ -/* - * Copyright (c) 2022-2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#if defined(CONFIG_BT_CAP_INITIATOR) - -#include -#include -#include -#include "common.h" -#include "bap_unicast_common.h" - - -/* When BROADCAST_ENQUEUE_COUNT > 1 we can enqueue enough buffers to ensure that - * the controller is never idle - */ -#define BROADCAST_ENQUEUE_COUNT 2U -#define TOTAL_BUF_NEEDED (BROADCAST_ENQUEUE_COUNT * CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT) - -BUILD_ASSERT(CONFIG_BT_ISO_TX_BUF_COUNT >= TOTAL_BUF_NEEDED, - "CONFIG_BT_ISO_TX_BUF_COUNT should be at least " - "BROADCAST_ENQUEUE_COUNT * CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT"); - -NET_BUF_POOL_FIXED_DEFINE(tx_pool, - TOTAL_BUF_NEEDED, - BT_ISO_SDU_BUF_SIZE(CONFIG_BT_ISO_TX_MTU), 8, NULL); - -extern enum bst_result_t bst_result; -static struct bt_cap_stream broadcast_source_streams[CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT]; -static struct bt_cap_stream *broadcast_streams[ARRAY_SIZE(broadcast_source_streams)]; -static struct bt_bap_lc3_preset broadcast_preset_16_2_1 = BT_BAP_LC3_BROADCAST_PRESET_16_2_1( - BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_MEDIA); - -static K_SEM_DEFINE(sem_broadcast_started, 0U, ARRAY_SIZE(broadcast_streams)); -static K_SEM_DEFINE(sem_broadcast_stopped, 0U, ARRAY_SIZE(broadcast_streams)); - -CREATE_FLAG(flag_connected); -CREATE_FLAG(flag_discovered); -CREATE_FLAG(flag_mtu_exchanged); -CREATE_FLAG(flag_broadcast_stopping); - -static void broadcast_started_cb(struct bt_bap_stream *stream) -{ - printk("Stream %p started\n", stream); - k_sem_give(&sem_broadcast_started); -} - -static void broadcast_stopped_cb(struct bt_bap_stream *stream, uint8_t reason) -{ - printk("Stream %p stopped with reason 0x%02X\n", stream, reason); - k_sem_give(&sem_broadcast_stopped); -} - -static void broadcast_sent_cb(struct bt_bap_stream *stream) -{ - static uint8_t mock_data[CONFIG_BT_ISO_TX_MTU]; - static bool mock_data_initialized; - static uint32_t seq_num; - struct net_buf *buf; - int ret; - - if (broadcast_preset_16_2_1.qos.sdu > CONFIG_BT_ISO_TX_MTU) { - FAIL("Invalid SDU %u for the MTU: %d", - broadcast_preset_16_2_1.qos.sdu, CONFIG_BT_ISO_TX_MTU); - return; - } - - if (TEST_FLAG(flag_broadcast_stopping)) { - return; - } - - if (!mock_data_initialized) { - for (size_t i = 0U; i < ARRAY_SIZE(mock_data); i++) { - /* Initialize mock data */ - mock_data[i] = (uint8_t)i; - } - mock_data_initialized = true; - } - - buf = net_buf_alloc(&tx_pool, K_FOREVER); - if (buf == NULL) { - printk("Could not allocate buffer when sending on %p\n", - stream); - return; - } - - net_buf_reserve(buf, BT_ISO_CHAN_SEND_RESERVE); - net_buf_add_mem(buf, mock_data, broadcast_preset_16_2_1.qos.sdu); - ret = bt_bap_stream_send(stream, buf, seq_num++, BT_ISO_TIMESTAMP_NONE); - if (ret < 0) { - /* This will end broadcasting on this stream. */ - printk("Unable to broadcast data on %p: %d\n", stream, ret); - net_buf_unref(buf); - return; - } -} - -static struct bt_bap_stream_ops broadcast_stream_ops = {.started = broadcast_started_cb, - .stopped = broadcast_stopped_cb, - .sent = broadcast_sent_cb}; - -static void cap_discovery_complete_cb(struct bt_conn *conn, int err, - const struct bt_csip_set_coordinator_csis_inst *csis_inst) -{ - if (err != 0) { - FAIL("Failed to discover CAS: %d", err); - - return; - } - - if (IS_ENABLED(CONFIG_BT_CAP_ACCEPTOR_SET_MEMBER)) { - if (csis_inst == NULL) { - FAIL("Failed to discover CAS CSIS"); - - return; - } - - printk("Found CAS with CSIS %p\n", csis_inst); - } else { - printk("Found CAS\n"); - } - - SET_FLAG(flag_discovered); -} - -static struct bt_cap_initiator_cb cap_cb = { - .unicast_discovery_complete = cap_discovery_complete_cb -}; - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - (void)bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - bt_conn_unref(default_conn); - default_conn = NULL; - - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - SET_FLAG(flag_connected); -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - -static void att_mtu_updated(struct bt_conn *conn, uint16_t tx, uint16_t rx) -{ - printk("MTU exchanged\n"); - SET_FLAG(flag_mtu_exchanged); -} - -static struct bt_gatt_cb gatt_callbacks = { - .att_mtu_updated = att_mtu_updated, -}; - -static void init(void) -{ - int err; - - err = bt_enable(NULL); - if (err != 0) { - FAIL("Bluetooth enable failed (err %d)\n", err); - return; - } - - if (IS_ENABLED(CONFIG_BT_BAP_UNICAST_CLIENT)) { - bt_gatt_cb_register(&gatt_callbacks); - - err = bt_cap_initiator_register_cb(&cap_cb); - if (err != 0) { - FAIL("Failed to register CAP callbacks (err %d)\n", err); - return; - } - - (void)memset(broadcast_source_streams, 0, - sizeof(broadcast_source_streams)); - - for (size_t i = 0; i < ARRAY_SIZE(broadcast_streams); i++) { - broadcast_streams[i] = &broadcast_source_streams[i]; - bt_cap_stream_ops_register(broadcast_streams[i], - &broadcast_stream_ops); - } - } -} - -static void scan_and_connect(void) -{ - int err; - - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); - if (err != 0) { - FAIL("Scanning failed to start (err %d)\n", err); - return; - } - - printk("Scanning successfully started\n"); - WAIT_FOR_FLAG(flag_connected); -} - -static void discover_cas(void) -{ - int err; - - UNSET_FLAG(flag_discovered); - - err = bt_cap_initiator_unicast_discover(default_conn); - if (err != 0) { - printk("Failed to discover CAS: %d\n", err); - return; - } - - WAIT_FOR_FLAG(flag_discovered); -} - -static void test_cap_initiator_unicast(void) -{ - init(); - - scan_and_connect(); - - WAIT_FOR_FLAG(flag_mtu_exchanged); - - discover_cas(); - - PASS("CAP initiator unicast passed\n"); -} - -static int setup_extended_adv(struct bt_le_ext_adv **adv) -{ - int err; - - /* Create a non-connectable non-scannable advertising set */ - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_NCONN_NAME, NULL, adv); - if (err != 0) { - printk("Unable to create extended advertising set: %d\n", err); - return err; - } - - /* Set periodic advertising parameters */ - err = bt_le_per_adv_set_param(*adv, BT_LE_PER_ADV_DEFAULT); - if (err) { - printk("Failed to set periodic advertising parameters: %d\n", - err); - return err; - } - - return 0; -} - -static int setup_extended_adv_data(struct bt_cap_broadcast_source *source, - struct bt_le_ext_adv *adv) -{ - /* Broadcast Audio Streaming Endpoint advertising data */ - NET_BUF_SIMPLE_DEFINE(ad_buf, - BT_UUID_SIZE_16 + BT_AUDIO_BROADCAST_ID_SIZE); - NET_BUF_SIMPLE_DEFINE(base_buf, 128); - struct bt_data ext_ad; - struct bt_data per_ad; - uint32_t broadcast_id; - int err; - - err = bt_cap_initiator_broadcast_get_id(source, &broadcast_id); - if (err != 0) { - printk("Unable to get broadcast ID: %d\n", err); - return err; - } - - /* Setup extended advertising data */ - net_buf_simple_add_le16(&ad_buf, BT_UUID_BROADCAST_AUDIO_VAL); - net_buf_simple_add_le24(&ad_buf, broadcast_id); - ext_ad.type = BT_DATA_SVC_DATA16; - ext_ad.data_len = ad_buf.len + sizeof(ext_ad.type); - ext_ad.data = ad_buf.data; - err = bt_le_ext_adv_set_data(adv, &ext_ad, 1, NULL, 0); - if (err != 0) { - printk("Failed to set extended advertising data: %d\n", err); - return err; - } - - /* Setup periodic advertising data */ - err = bt_cap_initiator_broadcast_get_base(source, &base_buf); - if (err != 0) { - printk("Failed to get encoded BASE: %d\n", err); - return err; - } - - per_ad.type = BT_DATA_SVC_DATA16; - per_ad.data_len = base_buf.len; - per_ad.data = base_buf.data; - err = bt_le_per_adv_set_data(adv, &per_ad, 1); - if (err != 0) { - printk("Failed to set periodic advertising data: %d\n", err); - return err; - } - - return 0; -} - -static int start_extended_adv(struct bt_le_ext_adv *adv) -{ - int err; - - /* Start extended advertising */ - err = bt_le_ext_adv_start(adv, BT_LE_EXT_ADV_START_DEFAULT); - if (err) { - printk("Failed to start extended advertising: %d\n", err); - return err; - } - - /* Enable Periodic Advertising */ - err = bt_le_per_adv_start(adv); - if (err) { - printk("Failed to enable periodic advertising: %d\n", err); - return err; - } - - return 0; -} - -static int stop_and_delete_extended_adv(struct bt_le_ext_adv *adv) -{ - int err; - - /* Stop extended advertising */ - err = bt_le_per_adv_stop(adv); - if (err) { - printk("Failed to stop periodic advertising: %d\n", err); - return err; - } - - err = bt_le_ext_adv_stop(adv); - if (err) { - printk("Failed to stop extended advertising: %d\n", err); - return err; - } - - err = bt_le_ext_adv_delete(adv); - if (err) { - printk("Failed to delete extended advertising: %d\n", err); - return err; - } - - return 0; -} - -static void test_cap_initiator_broadcast(void) -{ - struct bt_codec_data bis_codec_data = BT_CODEC_DATA(BT_CODEC_CONFIG_LC3_FREQ, - BT_CODEC_CONFIG_LC3_FREQ_16KHZ); - const uint16_t mock_ccid = 0x1234; - const struct bt_codec_data new_metadata[] = { - BT_CODEC_DATA(BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT, - (BT_AUDIO_CONTEXT_TYPE_MEDIA & 0xFFU), - ((BT_AUDIO_CONTEXT_TYPE_MEDIA >> 8) & 0xFFU)), - BT_CODEC_DATA(BT_AUDIO_METADATA_TYPE_CCID_LIST, - (mock_ccid & 0xFFU), - ((mock_ccid >> 8) & 0xFFU)), - }; - struct bt_cap_initiator_broadcast_stream_param - stream_params[ARRAY_SIZE(broadcast_source_streams)]; - struct bt_cap_initiator_broadcast_subgroup_param subgroup_param; - struct bt_cap_initiator_broadcast_create_param create_param; - struct bt_cap_broadcast_source *broadcast_source; - struct bt_le_ext_adv *adv; - int err; - - (void)memset(broadcast_source_streams, 0, - sizeof(broadcast_source_streams)); - - for (size_t i = 0; i < ARRAY_SIZE(broadcast_streams); i++) { - stream_params[i].stream = &broadcast_source_streams[i]; - bt_cap_stream_ops_register(stream_params[i].stream, - &broadcast_stream_ops); - stream_params[i].data_count = 1U; - stream_params[i].data = &bis_codec_data; - } - - subgroup_param.stream_count = ARRAY_SIZE(broadcast_streams); - subgroup_param.stream_params = stream_params; - subgroup_param.codec = &broadcast_preset_16_2_1.codec; - - create_param.subgroup_count = 1U; - create_param.subgroup_params = &subgroup_param; - create_param.qos = &broadcast_preset_16_2_1.qos; - create_param.packing = BT_ISO_PACKING_SEQUENTIAL; - create_param.encryption = false; - - init(); - - printk("Creating broadcast source with %zu broadcast_streams\n", - ARRAY_SIZE(broadcast_streams)); - - err = setup_extended_adv(&adv); - if (err != 0) { - FAIL("Unable to setup extended advertiser: %d\n", err); - return; - } - - err = bt_cap_initiator_broadcast_audio_start(&create_param, adv, - &broadcast_source); - if (err != 0) { - FAIL("Unable to start broadcast source: %d\n", err); - return; - } - - err = setup_extended_adv_data(broadcast_source, adv); - if (err != 0) { - FAIL("Unable to setup extended advertising data: %d\n", err); - return; - } - - err = start_extended_adv(adv); - if (err != 0) { - FAIL("Unable to start extended advertiser: %d\n", err); - return; - } - - /* Wait for all to be started */ - printk("Waiting for broadcast_streams to be started\n"); - for (size_t i = 0U; i < ARRAY_SIZE(broadcast_streams); i++) { - k_sem_take(&sem_broadcast_started, K_FOREVER); - } - - /* Initialize sending */ - for (size_t i = 0U; i < ARRAY_SIZE(broadcast_streams); i++) { - for (unsigned int j = 0U; j < BROADCAST_ENQUEUE_COUNT; j++) { - broadcast_sent_cb(&broadcast_streams[i]->bap_stream); - } - } - - /* Keeping running for a little while */ - k_sleep(K_SECONDS(5)); - - err = bt_cap_initiator_broadcast_audio_update(broadcast_source, - new_metadata, - ARRAY_SIZE(new_metadata)); - if (err != 0) { - FAIL("Failed to update broadcast source metadata: %d\n", err); - return; - } - - /* Keeping running for a little while */ - k_sleep(K_SECONDS(5)); - - err = bt_cap_initiator_broadcast_audio_stop(broadcast_source); - if (err != 0) { - FAIL("Failed to stop broadcast source: %d\n", err); - return; - } - - /* Wait for all to be stopped */ - printk("Waiting for broadcast_streams to be stopped\n"); - for (size_t i = 0U; i < ARRAY_SIZE(broadcast_streams); i++) { - k_sem_take(&sem_broadcast_stopped, K_FOREVER); - } - - err = bt_cap_initiator_broadcast_audio_delete(broadcast_source); - if (err != 0) { - FAIL("Failed to stop broadcast source: %d\n", err); - return; - } - broadcast_source = NULL; - - err = stop_and_delete_extended_adv(adv); - if (err != 0) { - FAIL("Failed to stop and delete extended advertising: %d\n", err); - return; - } - adv = NULL; - - PASS("CAP initiator broadcast passed\n"); -} - -static const struct bst_test_instance test_cap_initiator[] = { -#if defined(CONFIG_BT_BAP_UNICAST_CLIENT) - {.test_id = "cap_initiator_unicast", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_cap_initiator_unicast}, -#endif /* CONFIG_BT_BAP_UNICAST_CLIENT */ -#if defined(CONFIG_BT_BAP_BROADCAST_SOURCE) - {.test_id = "cap_initiator_broadcast", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_cap_initiator_broadcast}, -#endif /* CONFIG_BT_BAP_BROADCAST_SOURCE */ - BSTEST_END_MARKER}; - -struct bst_test_list *test_cap_initiator_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_cap_initiator); -} - -#else /* !(CONFIG_BT_CAP_INITIATOR) */ - -struct bst_test_list *test_cap_initiator_install(struct bst_test_list *tests) -{ - return tests; -} - -#endif /* CONFIG_BT_CAP_INITIATOR */ diff --git a/tests/bluetooth/bsim/audio/src/common.c b/tests/bluetooth/bsim/audio/src/common.c deleted file mode 100644 index 9111010b3d0..00000000000 --- a/tests/bluetooth/bsim/audio/src/common.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2019 Bose Corporation - * Copyright (c) 2020-2021 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "common.h" - -extern enum bst_result_t bst_result; -struct bt_conn *default_conn; - -const struct bt_data ad[AD_SIZE] = { - BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)) -}; - -void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, - struct net_buf_simple *ad) -{ - char addr_str[BT_ADDR_LE_STR_LEN]; - int err; - - if (default_conn) { - return; - } - - /* We're only interested in connectable events */ - if (type != BT_HCI_ADV_IND && type != BT_HCI_ADV_DIRECT_IND) { - return; - } - - bt_addr_le_to_str(addr, addr_str, sizeof(addr_str)); - printk("Device found: %s (RSSI %d)\n", addr_str, rssi); - - /* connect only to devices in close proximity */ - if (rssi < -70) { - FAIL("RSSI too low"); - return; - } - - printk("Stopping scan\n"); - if (bt_le_scan_stop()) { - FAIL("Could not stop scan"); - return; - } - - err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, - BT_LE_CONN_PARAM_DEFAULT, &default_conn); - if (err) { - FAIL("Could not connect to peer: %d", err); - } -} - -void disconnected(struct bt_conn *conn, uint8_t reason) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - if (conn != default_conn) { - return; - } - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - printk("Disconnected: %s (reason %u)\n", addr, reason); - - bt_conn_unref(default_conn); - default_conn = NULL; -} - -void test_tick(bs_time_t HW_device_time) -{ - if (bst_result != Passed) { - FAIL("test failed (not passed after %i seconds)\n", WAIT_SECONDS); - } -} - -void test_init(void) -{ - bst_ticker_set_next_tick_absolute(WAIT_TIME); - bst_result = In_progress; -} diff --git a/tests/bluetooth/bsim/audio/src/common.h b/tests/bluetooth/bsim/audio/src/common.h deleted file mode 100644 index b8bf8ccba40..00000000000 --- a/tests/bluetooth/bsim/audio/src/common.h +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Common functions and helpers for BSIM audio tests - * - * Copyright (c) 2019 Bose Corporation - * Copyright (c) 2020-2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef ZEPHYR_TEST_BSIM_BT_AUDIO_TEST_ -#define ZEPHYR_TEST_BSIM_BT_AUDIO_TEST_ - -#include - -#include "bs_types.h" -#include "bs_tracing.h" -#include "time_machine.h" -#include "bstests.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#define WAIT_SECONDS 30 /* seconds */ -#define WAIT_TIME (WAIT_SECONDS * USEC_PER_SEC) /* microseconds*/ - -#define WAIT_FOR_COND(cond) while (!(cond)) { k_sleep(K_MSEC(1)); } - -#define CREATE_FLAG(flag) static atomic_t flag = (atomic_t)false -#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)true) -#define UNSET_FLAG(flag) (void)atomic_clear(&flag) -#define TEST_FLAG(flag) (atomic_get(&flag) == (atomic_t)true) -#define WAIT_FOR_FLAG(flag) \ - while (!(bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } - -#define FAIL(...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, "PASSED: " __VA_ARGS__); \ - } while (0) - -#define AD_SIZE 1 -extern const struct bt_data ad[AD_SIZE]; -extern struct bt_conn *default_conn; - -void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, - struct net_buf_simple *ad); -void disconnected(struct bt_conn *conn, uint8_t reason); -void test_tick(bs_time_t HW_device_time); -void test_init(void); - -#endif /* ZEPHYR_TEST_BSIM_BT_AUDIO_TEST_ */ diff --git a/tests/bluetooth/bsim/audio/src/csip_set_coordinator_test.c b/tests/bluetooth/bsim/audio/src/csip_set_coordinator_test.c deleted file mode 100644 index 467a53a7123..00000000000 --- a/tests/bluetooth/bsim/audio/src/csip_set_coordinator_test.c +++ /dev/null @@ -1,438 +0,0 @@ -/* - * Copyright (c) 2019 Bose Corporation - * Copyright (c) 2020-2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ -#ifdef CONFIG_BT_CSIP_SET_COORDINATOR -#include -#include -#include "common.h" - -extern enum bst_result_t bst_result; -static volatile bool is_connected; -static volatile bool discovered; -static volatile bool members_discovered; -static volatile bool set_locked; -static volatile bool set_unlocked; -static volatile bool ordered_access_locked; -static volatile bool ordered_access_unlocked; -static const struct bt_csip_set_coordinator_csis_inst *inst; - -static uint8_t members_found; -static struct k_work_delayable discover_members_timer; -static bt_addr_le_t addr_found[CONFIG_BT_MAX_CONN]; -static struct bt_conn *conns[CONFIG_BT_MAX_CONN]; -static const struct bt_csip_set_coordinator_set_member *set_members[CONFIG_BT_MAX_CONN]; - -static void csip_set_coordinator_lock_set_cb(int err); - -static void csip_set_coordinator_lock_release_cb(int err) -{ - printk("%s\n", __func__); - - if (err != 0) { - FAIL("Release sets failed (%d)\n", err); - return; - } - - set_unlocked = true; -} - -static void csip_set_coordinator_lock_set_cb(int err) -{ - printk("%s\n", __func__); - - if (err != 0) { - FAIL("Lock sets failed (%d)\n", err); - return; - } - - set_locked = true; -} - -static void csip_discover_cb(struct bt_conn *conn, - const struct bt_csip_set_coordinator_set_member *member, - int err, size_t set_count) -{ - uint8_t conn_index; - - printk("%s\n", __func__); - - if (err != 0 || set_count == 0U) { - FAIL("Discover failed (%d)\n", err); - return; - } - - conn_index = bt_conn_index(conn); - - inst = &member->insts[0]; - set_members[conn_index] = member; - discovered = true; -} - -static void csip_lock_changed_cb(struct bt_csip_set_coordinator_csis_inst *inst, - bool locked) -{ - printk("Inst %p %s\n", inst, locked ? "locked" : "released"); -} - -static void csip_set_coordinator_ordered_access_cb( - const struct bt_csip_set_coordinator_set_info *set_info, int err, - bool locked, struct bt_csip_set_coordinator_set_member *member) -{ - if (err) { - FAIL("Ordered access failed with err %d\n", err); - } else if (locked) { - printk("Ordered access procedure locked member %p\n", member); - ordered_access_locked = true; - } else { - printk("Ordered access procedure finished\n"); - ordered_access_unlocked = true; - } -} - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - if (is_connected) { - return; - } - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - bt_conn_unref(default_conn); - default_conn = NULL; - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - is_connected = true; -} - -static struct bt_conn_cb conn_callbacks = { - .connected = connected, -}; - -static struct bt_csip_set_coordinator_cb cbs = { - .lock_set = csip_set_coordinator_lock_set_cb, - .release_set = csip_set_coordinator_lock_release_cb, - .discover = csip_discover_cb, - .lock_changed = csip_lock_changed_cb, - .ordered_access = csip_set_coordinator_ordered_access_cb -}; - -static bool csip_set_coordinator_oap_cb(const struct bt_csip_set_coordinator_set_info *set_info, - struct bt_csip_set_coordinator_set_member *members[], - size_t count) -{ - for (size_t i = 0; i < count; i++) { - printk("Ordered access for members[%zu]: %p\n", i, members[i]); - } - - return true; -} - -static bool is_discovered(const bt_addr_le_t *addr) -{ - for (int i = 0; i < members_found; i++) { - if (bt_addr_le_eq(addr, &addr_found[i])) { - return true; - } - } - return false; -} - -static bool csip_found(struct bt_data *data, void *user_data) -{ - if (bt_csip_set_coordinator_is_set_member(inst->info.set_sirk, data)) { - const bt_addr_le_t *addr = user_data; - char addr_str[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(addr, addr_str, sizeof(addr_str)); - printk("Found CSIP advertiser with address %s\n", addr_str); - - if (is_discovered(addr)) { - printk("Set member already found\n"); - /* Stop parsing */ - return false; - } - - bt_addr_le_copy(&addr_found[members_found++], addr); - - printk("Found member (%u / %u)\n", - members_found, inst->info.set_size); - - /* Stop parsing */ - return false; - } - /* Continue parsing */ - return true; -} - -static void csip_set_coordinator_scan_recv(const struct bt_le_scan_recv_info *info, - struct net_buf_simple *ad) -{ - /* We're only interested in connectable events */ - if (info->adv_props & BT_GAP_ADV_PROP_CONNECTABLE) { - if (inst == NULL) { - /* Scanning for the first device */ - if (members_found == 0) { - bt_addr_le_copy(&addr_found[members_found++], - info->addr); - } - } else { /* Scanning for set members */ - bt_data_parse(ad, csip_found, (void *)info->addr); - } - } -} - -static struct bt_le_scan_cb csip_set_coordinator_scan_callbacks = { - .recv = csip_set_coordinator_scan_recv -}; - -static void discover_members_timer_handler(struct k_work *work) -{ - FAIL("Could not find all members (%u / %u)\n", - members_found, inst->info.set_size); -} - -static void ordered_access(const struct bt_csip_set_coordinator_set_member **members, - size_t count, bool expect_locked) -{ - int err; - - printk("Performing ordered access, expecting %s\n", - expect_locked ? "locked" : "unlocked"); - - if (expect_locked) { - ordered_access_locked = false; - } else { - ordered_access_unlocked = false; - } - - err = bt_csip_set_coordinator_ordered_access(members, count, - &inst->info, - csip_set_coordinator_oap_cb); - if (err != 0) { - FAIL("Failed to do CSIP set coordinator ordered access (%d)", - err); - return; - } - - if (expect_locked) { - WAIT_FOR_COND(ordered_access_locked); - } else { - WAIT_FOR_COND(ordered_access_unlocked); - } -} - -static void test_main(void) -{ - int err; - char addr[BT_ADDR_LE_STR_LEN]; - const struct bt_csip_set_coordinator_set_member *locked_members[CONFIG_BT_MAX_CONN]; - uint8_t connected_member_count = 0; - - err = bt_enable(NULL); - if (err != 0) { - FAIL("Bluetooth init failed (err %d)\n", err); - return; - } - - printk("Audio Client: Bluetooth initialized\n"); - - bt_conn_cb_register(&conn_callbacks); - bt_csip_set_coordinator_register_cb(&cbs); - k_work_init_delayable(&discover_members_timer, - discover_members_timer_handler); - bt_le_scan_cb_register(&csip_set_coordinator_scan_callbacks); - - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL); - if (err != 0) { - FAIL("Scanning failed to start (err %d)\n", err); - return; - } - - printk("Scanning successfully started\n"); - - WAIT_FOR_COND(members_found == 1); - - printk("Stopping scan\n"); - err = bt_le_scan_stop(); - if (err != 0) { - FAIL("Could not stop scan"); - return; - } - - bt_addr_le_to_str(&addr_found[0], addr, sizeof(addr)); - err = bt_conn_le_create(&addr_found[0], BT_CONN_LE_CREATE_CONN, - BT_LE_CONN_PARAM_DEFAULT, &conns[0]); - if (err != 0) { - FAIL("Failed to connect to %s: %d\n", err); - return; - } - printk("Connecting to %s\n", addr); - - WAIT_FOR_COND(is_connected); - connected_member_count++; - - err = bt_csip_set_coordinator_discover(conns[0]); - if (err != 0) { - FAIL("Failed to initialize set coordinator for connection %d\n", - err); - return; - } - - WAIT_FOR_COND(discovered); - - err = bt_le_scan_start(BT_LE_SCAN_ACTIVE, NULL); - if (err != 0) { - FAIL("Could not start scan: %d", err); - return; - } - - err = k_work_reschedule(&discover_members_timer, - BT_CSIP_SET_COORDINATOR_DISCOVER_TIMER_VALUE); - if (err < 0) { /* Can return 0, 1 and 2 for success */ - FAIL("Could not schedule discover_members_timer %d", err); - return; - } - - WAIT_FOR_COND(members_found == inst->info.set_size); - - (void)k_work_cancel_delayable(&discover_members_timer); - err = bt_le_scan_stop(); - if (err != 0) { - FAIL("Scanning failed to stop (err %d)\n", err); - return; - } - - for (uint8_t i = 1; i < members_found; i++) { - bt_addr_le_to_str(&addr_found[i], addr, sizeof(addr)); - - is_connected = false; - printk("Connecting to member[%d] (%s)", i, addr); - err = bt_conn_le_create(&addr_found[i], - BT_CONN_LE_CREATE_CONN, - BT_LE_CONN_PARAM_DEFAULT, - &conns[i]); - if (err != 0) { - FAIL("Failed to connect to %s: %d\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - WAIT_FOR_COND(is_connected); - connected_member_count++; - - discovered = false; - printk("Doing discovery on member[%u]", i); - err = bt_csip_set_coordinator_discover(conns[i]); - if (err != 0) { - FAIL("Failed to initialize set coordinator for connection %d\n", - err); - return; - } - - WAIT_FOR_COND(discovered); - } - - for (size_t i = 0; i < ARRAY_SIZE(locked_members); i++) { - locked_members[i] = set_members[i]; - } - - ordered_access(locked_members, connected_member_count, false); - - printk("Locking set\n"); - err = bt_csip_set_coordinator_lock(locked_members, connected_member_count, - &inst->info); - if (err != 0) { - FAIL("Failed to do set coordinator lock (%d)", err); - return; - } - - WAIT_FOR_COND(set_locked); - - ordered_access(locked_members, connected_member_count, true); - - k_sleep(K_MSEC(1000)); /* Simulate doing stuff */ - - printk("Releasing set\n"); - err = bt_csip_set_coordinator_release(locked_members, connected_member_count, - &inst->info); - if (err != 0) { - FAIL("Failed to do set coordinator release (%d)", err); - return; - } - - WAIT_FOR_COND(set_unlocked); - - ordered_access(locked_members, connected_member_count, false); - - /* Lock and unlock again */ - set_locked = false; - set_unlocked = false; - - printk("Locking set\n"); - err = bt_csip_set_coordinator_lock(locked_members, connected_member_count, - &inst->info); - if (err != 0) { - FAIL("Failed to do set coordinator lock (%d)", err); - return; - } - - WAIT_FOR_COND(set_locked); - - k_sleep(K_MSEC(1000)); /* Simulate doing stuff */ - - printk("Releasing set\n"); - err = bt_csip_set_coordinator_release(locked_members, connected_member_count, - &inst->info); - if (err != 0) { - FAIL("Failed to do set coordinator release (%d)", err); - return; - } - - WAIT_FOR_COND(set_unlocked); - - for (uint8_t i = 0; i < members_found; i++) { - printk("Disconnecting member[%u] (%s)", i, addr); - err = bt_conn_disconnect(conns[i], - BT_HCI_ERR_REMOTE_USER_TERM_CONN); - (void)memset(&set_members[i], 0, sizeof(set_members[i])); - if (err != 0) { - FAIL("Failed to do disconnect\n", err); - return; - } - } - - PASS("All members disconnected\n"); -} - -static const struct bst_test_instance test_connect[] = { - - { - .test_id = "csip_set_coordinator", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main - }, - - BSTEST_END_MARKER -}; - -struct bst_test_list *test_csip_set_coordinator_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_connect); -} -#else -struct bst_test_list *test_csip_set_coordinator_install(struct bst_test_list *tests) -{ - return tests; -} - -#endif /* CONFIG_BT_CSIP_SET_COORDINATOR */ diff --git a/tests/bluetooth/bsim/audio/src/csip_set_member_test.c b/tests/bluetooth/bsim/audio/src/csip_set_member_test.c deleted file mode 100644 index 5321744ac7f..00000000000 --- a/tests/bluetooth/bsim/audio/src/csip_set_member_test.c +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright (c) 2019 Bose Corporation - * Copyright (c) 2020-2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ -#ifdef CONFIG_BT_CSIP_SET_MEMBER -#include - -#include "common.h" - -static struct bt_csip_set_member_svc_inst *svc_inst; -static struct bt_conn_cb conn_callbacks; -extern enum bst_result_t bst_result; -static volatile bool g_locked; -static uint8_t sirk_read_req_rsp = BT_CSIP_READ_SIRK_REQ_RSP_ACCEPT; -struct bt_csip_set_member_register_param param = { - .set_size = 3, - .rank = 1, - .lockable = true, - /* Using the CSIS test sample SIRK */ - .set_sirk = { 0xcd, 0xcc, 0x72, 0xdd, 0x86, 0x8c, 0xcd, 0xce, - 0x22, 0xfd, 0xa1, 0x21, 0x09, 0x7d, 0x7d, 0x45 }, -}; - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - printk("Connected\n"); -} - -static void csip_disconnected(struct bt_conn *conn, uint8_t reason) -{ - printk("Disconnected (reason %u)\n", reason); - - if (reason == BT_HCI_ERR_REMOTE_USER_TERM_CONN) { - PASS("Client successfully disconnected\n"); - } else { - FAIL("Client disconnected unexpectedly (0x%02x)\n", reason); - } -} - -static void csip_lock_changed_cb(struct bt_conn *conn, - struct bt_csip_set_member_svc_inst *svc_inst, - bool locked) -{ - printk("Client %p %s the lock\n", conn, locked ? "locked" : "released"); - g_locked = locked; -} - -static uint8_t sirk_read_req_cb(struct bt_conn *conn, - struct bt_csip_set_member_svc_inst *svc_inst) -{ - return sirk_read_req_rsp; -} - -static struct bt_csip_set_member_cb csip_cbs = { - .lock_changed = csip_lock_changed_cb, - .sirk_read_req = sirk_read_req_cb, -}; - -static void bt_ready(int err) -{ - uint8_t rsi[BT_CSIP_RSI_SIZE]; - struct bt_data ad[] = { - BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), - BT_CSIP_DATA_RSI(rsi), - }; - - if (err != 0) { - FAIL("Bluetooth init failed (err %d)\n", err); - return; - } - - printk("Audio Server: Bluetooth initialized\n"); - - param.cb = &csip_cbs; - - err = bt_csip_set_member_register(¶m, &svc_inst); - if (err != 0) { - FAIL("Could not register CSIP (err %d)\n", err); - return; - } - - err = bt_csip_set_member_generate_rsi(svc_inst, rsi); - if (err != 0) { - FAIL("Failed to generate RSI (err %d)\n", err); - return; - } - - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0); - if (err != 0) { - FAIL("Advertising failed to start (err %d)\n", err); - } -} - -static struct bt_conn_cb conn_callbacks = { - .connected = connected, - .disconnected = csip_disconnected, -}; - -static void test_main(void) -{ - int err; - - err = bt_enable(bt_ready); - - if (err != 0) { - FAIL("Bluetooth init failed (err %d)\n", err); - return; - } - - bt_conn_cb_register(&conn_callbacks); -} - -static void test_force_release(void) -{ - int err; - - err = bt_enable(bt_ready); - - if (err != 0) { - FAIL("Bluetooth init failed (err %d)\n", err); - return; - } - - bt_conn_cb_register(&conn_callbacks); - - WAIT_FOR_COND(g_locked); - printk("Force releasing set\n"); - bt_csip_set_member_lock(svc_inst, false, true); -} - -static void test_csip_enc(void) -{ - printk("Running %s\n", __func__); - sirk_read_req_rsp = BT_CSIP_READ_SIRK_REQ_RSP_ACCEPT_ENC; - test_main(); -} - -static void test_args(int argc, char *argv[]) -{ - for (size_t argn = 0; argn < argc; argn++) { - const char *arg = argv[argn]; - - if (strcmp(arg, "size") == 0) { - param.set_size = strtol(argv[++argn], NULL, 10); - } else if (strcmp(arg, "rank") == 0) { - param.rank = strtol(argv[++argn], NULL, 10); - } else if (strcmp(arg, "not-lockable") == 0) { - param.lockable = false; - } else if (strcmp(arg, "sirk") == 0) { - size_t len; - - argn++; - - len = hex2bin(argv[argn], strlen(argv[argn]), - param.set_sirk, sizeof(param.set_sirk)); - if (len == 0) { - FAIL("Could not parse SIRK"); - return; - } - } else { - FAIL("Invalid arg: %s", arg); - } - } -} - -static const struct bst_test_instance test_connect[] = { - { - .test_id = "csip_set_member", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main, - .test_args_f = test_args, - }, - { - .test_id = "csip_set_member_release", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_force_release, - .test_args_f = test_args, - }, - { - .test_id = "csip_set_member_enc", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_csip_enc, - .test_args_f = test_args, - }, - - BSTEST_END_MARKER -}; - -struct bst_test_list *test_csip_set_member_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_connect); -} -#else - -struct bst_test_list *test_csip_set_member_install(struct bst_test_list *tests) -{ - return tests; -} - -#endif /* CONFIG_BT_CSIP_SET_MEMBER */ diff --git a/tests/bluetooth/bsim/audio/src/has_client_test.c b/tests/bluetooth/bsim/audio/src/has_client_test.c deleted file mode 100644 index 32a7c0575c0..00000000000 --- a/tests/bluetooth/bsim/audio/src/has_client_test.c +++ /dev/null @@ -1,273 +0,0 @@ -/* - * Copyright (c) 2022 Codecoup - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifdef CONFIG_BT_HAS_CLIENT -#include - -#include "common.h" - -extern enum bst_result_t bst_result; - -extern const char *test_preset_name_1; -extern const char *test_preset_name_5; -extern const uint8_t test_preset_index_1; -extern const uint8_t test_preset_index_5; -extern const enum bt_has_properties test_preset_properties; - -CREATE_FLAG(g_is_connected); -CREATE_FLAG(g_service_discovered); -CREATE_FLAG(g_preset_switched); -CREATE_FLAG(g_preset_1_found); -CREATE_FLAG(g_preset_5_found); - -static struct bt_conn *g_conn; -static struct bt_has *g_has; -static uint8_t g_active_index; - -static void discover_cb(struct bt_conn *conn, int err, struct bt_has *has, - enum bt_has_hearing_aid_type type, enum bt_has_capabilities caps) -{ - if (err) { - FAIL("Failed to discover HAS (err %d)\n", err); - return; - } - - printk("HAS discovered type %d caps %d\n", type, caps); - - g_has = has; - SET_FLAG(g_service_discovered); -} - -static void preset_switch_cb(struct bt_has *has, int err, uint8_t index) -{ - if (err != 0) { - return; - } - - printk("Active preset index %d\n", index); - - SET_FLAG(g_preset_switched); - g_active_index = index; -} - -static void check_preset_record(const struct bt_has_preset_record *record, - enum bt_has_properties expected_properties, - const char *expected_name) -{ - if (record->properties != expected_properties || strcmp(record->name, expected_name)) { - FAIL("mismatch 0x%02x %s vs 0x%02x %s expected\n", - record->properties, record->name, expected_properties, expected_name); - } -} - -static void preset_read_rsp_cb(struct bt_has *has, int err, - const struct bt_has_preset_record *record, bool is_last) -{ - if (err) { - FAIL("%s: err %d\n", __func__, err); - return; - } - - if (record->index == test_preset_index_1) { - SET_FLAG(g_preset_1_found); - - check_preset_record(record, test_preset_properties, test_preset_name_1); - } else if (record->index == test_preset_index_5) { - SET_FLAG(g_preset_5_found); - - check_preset_record(record, test_preset_properties, test_preset_name_5); - } else { - FAIL("unexpected index 0x%02x", record->index); - } -} - -static const struct bt_has_client_cb has_cb = { - .discover = discover_cb, - .preset_switch = preset_switch_cb, - .preset_read_rsp = preset_read_rsp_cb, -}; - -static void connected(struct bt_conn *conn, uint8_t err) -{ - if (err > 0) { - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - FAIL("Failed to connect to %s (err %u)\n", addr, err); - return; - } - - g_conn = conn; - SET_FLAG(g_is_connected); -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - -static bool test_preset_switch(uint8_t index) -{ - int err; - - UNSET_FLAG(g_preset_switched); - - err = bt_has_client_preset_set(g_has, index, false); - if (err < 0) { - printk("%s (err %d)\n", __func__, err); - return false; - } - - WAIT_FOR_COND(g_preset_switched); - - return g_active_index == index; -} - -static bool test_preset_next(uint8_t active_index_expected) -{ - int err; - - UNSET_FLAG(g_preset_switched); - - err = bt_has_client_preset_next(g_has, false); - if (err < 0) { - printk("%s (err %d)\n", __func__, err); - return false; - } - - WAIT_FOR_COND(g_preset_switched); - - return g_active_index == active_index_expected; -} - -static bool test_preset_prev(uint8_t active_index_expected) -{ - int err; - - UNSET_FLAG(g_preset_switched); - - err = bt_has_client_preset_prev(g_has, false); - if (err < 0) { - printk("%s (err %d)\n", __func__, err); - return false; - } - - WAIT_FOR_COND(g_preset_switched); - - return g_active_index == active_index_expected; -} - -static void test_main(void) -{ - int err; - - err = bt_enable(NULL); - if (err < 0) { - FAIL("Bluetooth discover failed (err %d)\n", err); - return; - } - - printk("Bluetooth initialized\n"); - - err = bt_has_client_cb_register(&has_cb); - if (err < 0) { - FAIL("Failed to register callbacks (err %d)\n", err); - return; - } - - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); - if (err < 0) { - FAIL("Scanning failed to start (err %d)\n", err); - return; - } - - printk("Scanning successfully started\n"); - - WAIT_FOR_COND(g_is_connected); - - err = bt_has_client_discover(g_conn); - if (err < 0) { - FAIL("Failed to discover HAS (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_service_discovered); - WAIT_FOR_COND(g_preset_switched); - - err = bt_has_client_presets_read(g_has, BT_HAS_PRESET_INDEX_FIRST, 255); - if (err < 0) { - FAIL("Failed to read presets (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_preset_1_found); - WAIT_FOR_COND(g_preset_5_found); - - if (!test_preset_switch(test_preset_index_1)) { - FAIL("Failed to switch preset %d\n", test_preset_index_1); - return; - } - - if (!test_preset_switch(test_preset_index_5)) { - FAIL("Failed to switch preset %d\n", test_preset_index_5); - return; - } - - if (!test_preset_next(test_preset_index_1)) { - FAIL("Failed to set next preset %d\n", test_preset_index_1); - return; - } - - if (!test_preset_next(test_preset_index_5)) { - FAIL("Failed to set next preset %d\n", test_preset_index_5); - return; - } - - if (!test_preset_next(test_preset_index_1)) { - FAIL("Failed to set next preset %d\n", test_preset_index_1); - return; - } - - if (!test_preset_prev(test_preset_index_5)) { - FAIL("Failed to set previous preset %d\n", test_preset_index_5); - return; - } - - if (!test_preset_prev(test_preset_index_1)) { - FAIL("Failed to set previous preset %d\n", test_preset_index_1); - return; - } - - if (!test_preset_prev(test_preset_index_5)) { - FAIL("Failed to set previous preset %d\n", test_preset_index_5); - return; - } - - PASS("HAS main PASS\n"); -} - -static const struct bst_test_instance test_has[] = { - { - .test_id = "has_client", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main, - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_has_client_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_has); -} -#else -struct bst_test_list *test_has_client_install(struct bst_test_list *tests) -{ - return tests; -} - -#endif /* CONFIG_BT_HAS_CLIENT */ diff --git a/tests/bluetooth/bsim/audio/src/has_test.c b/tests/bluetooth/bsim/audio/src/has_test.c deleted file mode 100644 index 177d07b988a..00000000000 --- a/tests/bluetooth/bsim/audio/src/has_test.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2022 Codecoup - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifdef CONFIG_BT_HAS -#include -#include - -#include "common.h" - -extern enum bst_result_t bst_result; - -const uint8_t test_preset_index_1 = 0x01; -const uint8_t test_preset_index_5 = 0x05; -const char *test_preset_name_1 = "test_preset_name_1"; -const char *test_preset_name_5 = "test_preset_name_5"; -const enum bt_has_properties test_preset_properties = BT_HAS_PROP_AVAILABLE; - -static int preset_select(uint8_t index, bool sync) -{ - return 0; -} - -static const struct bt_has_preset_ops preset_ops = { - .select = preset_select, -}; - -static void test_main(void) -{ - struct bt_has_register_param has_param = {0}; - struct bt_has_preset_register_param preset_param; - - int err; - - err = bt_enable(NULL); - if (err) { - FAIL("Bluetooth enable failed (err %d)\n", err); - return; - } - - printk("Bluetooth initialized\n"); - - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, AD_SIZE, NULL, 0); - if (err) { - FAIL("Advertising failed to start (err %d)\n", err); - return; - } - - printk("Advertising successfully started\n"); - - has_param.type = BT_HAS_HEARING_AID_TYPE_MONAURAL; - - err = bt_has_register(&has_param); - if (err) { - FAIL("HAS register failed (err %d)\n", err); - return; - } - - preset_param.index = test_preset_index_5; - preset_param.properties = test_preset_properties; - preset_param.name = test_preset_name_5; - preset_param.ops = &preset_ops, - - err = bt_has_preset_register(&preset_param); - if (err) { - FAIL("Preset register failed (err %d)\n", err); - return; - } - - preset_param.index = test_preset_index_1; - preset_param.properties = test_preset_properties; - preset_param.name = test_preset_name_1; - - err = bt_has_preset_register(&preset_param); - if (err) { - FAIL("Preset register failed (err %d)\n", err); - return; - } - - printk("Presets registered\n"); - - PASS("HAS passed\n"); -} - -static const struct bst_test_instance test_has[] = { - { - .test_id = "has", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main, - }, - BSTEST_END_MARKER, -}; - -struct bst_test_list *test_has_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_has); -} -#else -struct bst_test_list *test_has_install(struct bst_test_list *tests) -{ - return tests; -} - -#endif /* CONFIG_BT_HAS */ diff --git a/tests/bluetooth/bsim/audio/src/ias_client_test.c b/tests/bluetooth/bsim/audio/src/ias_client_test.c deleted file mode 100644 index f7c1c19826c..00000000000 --- a/tests/bluetooth/bsim/audio/src/ias_client_test.c +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (c) 2022 Codecoup - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#ifdef CONFIG_BT_IAS_CLIENT - -#include "zephyr/bluetooth/services/ias.h" -#include "common.h" - -extern enum bst_result_t bst_result; - -CREATE_FLAG(g_is_connected); -CREATE_FLAG(g_service_discovered); - -static struct bt_conn *g_conn; - -static void discover_cb(struct bt_conn *conn, int err) -{ - if (err) { - FAIL("Failed to discover IAS (err %d)\n", err); - return; - } - - printk("IAS discovered\n"); - SET_FLAG(g_service_discovered); -} - -static const struct bt_ias_client_cb ias_client_cb = { - .discover = discover_cb, -}; - -static void connected(struct bt_conn *conn, uint8_t err) -{ - if (err > 0) { - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - FAIL("Failed to connect to %s (err %u)\n", addr, err); - return; - } - - g_conn = conn; - SET_FLAG(g_is_connected); -} - -static void test_alert_high(struct bt_conn *conn) -{ - int err; - - err = bt_ias_client_alert_write(conn, BT_IAS_ALERT_LVL_HIGH_ALERT); - if (err == 0) { - printk("High alert sent\n"); - } else { - FAIL("Failed to send high alert\n"); - } -} - -static void test_alert_mild(struct bt_conn *conn) -{ - int err; - - err = bt_ias_client_alert_write(conn, BT_IAS_ALERT_LVL_MILD_ALERT); - if (err == 0) { - printk("Mild alert sent\n"); - } else { - FAIL("Failed to send mild alert\n"); - } -} - -static void test_alert_stop(struct bt_conn *conn) -{ - int err; - - err = bt_ias_client_alert_write(conn, BT_IAS_ALERT_LVL_NO_ALERT); - if (err == 0) { - printk("Stop alert sent\n"); - } else { - FAIL("Failed to send no alert\n"); - } -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - -static void test_main(void) -{ - int err; - - err = bt_enable(NULL); - if (err < 0) { - FAIL("Bluetooth discover failed (err %d)\n", err); - return; - } - - printk("Bluetooth initialized\n"); - - err = bt_ias_client_cb_register(&ias_client_cb); - if (err < 0) { - FAIL("Failed to register callbacks (err %d)\n", err); - return; - } - - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); - if (err < 0) { - FAIL("Scanning failed to start (err %d)\n", err); - return; - } - - printk("Scanning successfully started\n"); - - WAIT_FOR_FLAG(g_is_connected); - - err = bt_ias_discover(g_conn); - if (err < 0) { - FAIL("Failed to discover IAS (err %d)\n", err); - return; - } - - WAIT_FOR_FLAG(g_service_discovered); - - /* Set alert levels with a delay to let the server handle any changes it want */ - test_alert_high(g_conn); - k_sleep(K_SECONDS(1)); - - test_alert_mild(g_conn); - k_sleep(K_SECONDS(1)); - - test_alert_stop(g_conn); - k_sleep(K_SECONDS(1)); - - PASS("IAS client PASS\n"); -} - -static const struct bst_test_instance test_ias[] = { - { - .test_id = "ias_client", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main, - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_ias_client_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_ias); -} -#else -struct bst_test_list *test_ias_client_install(struct bst_test_list *tests) -{ - return tests; -} - -#endif /* CONFIG_BT_IAS_CLIENT */ diff --git a/tests/bluetooth/bsim/audio/src/ias_test.c b/tests/bluetooth/bsim/audio/src/ias_test.c deleted file mode 100644 index 40e9d8b6e89..00000000000 --- a/tests/bluetooth/bsim/audio/src/ias_test.c +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2022 Codecoup - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#ifdef CONFIG_BT_IAS - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include - -#include "common.h" - -extern enum bst_result_t bst_result; - -CREATE_FLAG(g_is_connected); -CREATE_FLAG(g_high_alert_received); -CREATE_FLAG(g_mild_alert_received); -CREATE_FLAG(g_stop_alert_received); - -static void high_alert_cb(void) -{ - SET_FLAG(g_high_alert_received); -} - -static void mild_alert_cb(void) -{ - SET_FLAG(g_mild_alert_received); -} - -static void no_alert_cb(void) -{ - SET_FLAG(g_stop_alert_received); -} - -BT_IAS_CB_DEFINE(ias_callbacks) = { - .high_alert = high_alert_cb, - .mild_alert = mild_alert_cb, - .no_alert = no_alert_cb, -}; - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - default_conn = bt_conn_ref(conn); - g_is_connected = true; -} - -static struct bt_conn_cb conn_callbacks = { - .connected = connected, - .disconnected = disconnected, -}; - -static void test_main(void) -{ - int err; - - err = bt_enable(NULL); - if (err != 0) { - FAIL("Bluetooth init failed (err %d)\n", err); - return; - } - - bt_conn_cb_register(&conn_callbacks); - - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, AD_SIZE, NULL, 0); - if (err) { - FAIL("Advertising failed to start (err %d)\n", err); - return; - } - - printk("Advertising successfully started\n"); - - WAIT_FOR_FLAG(g_is_connected); - - WAIT_FOR_FLAG(g_high_alert_received); - printk("High alert received\n"); - - err = bt_ias_local_alert_stop(); - if (err != 0) { - FAIL("Failed to locally stop alert: %d\n", err); - return; - } - WAIT_FOR_FLAG(g_stop_alert_received); - - WAIT_FOR_FLAG(g_mild_alert_received); - printk("Mild alert received\n"); - - WAIT_FOR_FLAG(g_stop_alert_received); - printk("Stop alert received\n"); - - PASS("IAS test passed\n"); -} - -static const struct bst_test_instance test_ias[] = { - { - .test_id = "ias", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main, - - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_ias_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_ias); -} - -#endif /* CONFIG_BT_IAS */ diff --git a/tests/bluetooth/bsim/audio/src/main.c b/tests/bluetooth/bsim/audio/src/main.c deleted file mode 100644 index a296cb5036b..00000000000 --- a/tests/bluetooth/bsim/audio/src/main.c +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2020-2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bstests.h" - -extern struct bst_test_list *test_vcp_install(struct bst_test_list *tests); -extern struct bst_test_list *test_vcp_vol_ctlr_install(struct bst_test_list *tests); -extern struct bst_test_list *test_micp_install(struct bst_test_list *tests); -extern struct bst_test_list *test_micp_mic_ctlr_install(struct bst_test_list *tests); -extern struct bst_test_list *test_csip_set_member_install(struct bst_test_list *tests); -extern struct bst_test_list *test_csip_set_coordinator_install(struct bst_test_list *tests); -extern struct bst_test_list *test_tbs_install(struct bst_test_list *tests); -extern struct bst_test_list *test_tbs_client_install(struct bst_test_list *tests); -extern struct bst_test_list *test_mcs_install(struct bst_test_list *tests); -extern struct bst_test_list *test_mcc_install(struct bst_test_list *tests); -extern struct bst_test_list *test_media_controller_install(struct bst_test_list *tests); -extern struct bst_test_list *test_unicast_client_install(struct bst_test_list *tests); -extern struct bst_test_list *test_unicast_server_install(struct bst_test_list *tests); -extern struct bst_test_list *test_broadcast_source_install(struct bst_test_list *tests); -extern struct bst_test_list *test_broadcast_sink_install(struct bst_test_list *tests); -extern struct bst_test_list *test_scan_delegator_install(struct bst_test_list *tests); -extern struct bst_test_list *test_bap_broadcast_assistant_install(struct bst_test_list *tests); -extern struct bst_test_list *test_bass_broadcaster_install(struct bst_test_list *tests); -extern struct bst_test_list *test_cap_acceptor_install(struct bst_test_list *tests); -extern struct bst_test_list *test_cap_initiator_install(struct bst_test_list *tests); -extern struct bst_test_list *test_has_install(struct bst_test_list *tests); -extern struct bst_test_list *test_has_client_install(struct bst_test_list *tests); -extern struct bst_test_list *test_ias_install(struct bst_test_list *tests); -extern struct bst_test_list *test_ias_client_install(struct bst_test_list *tests); - -bst_test_install_t test_installers[] = { - test_vcp_install, - test_vcp_vol_ctlr_install, - test_micp_install, - test_micp_mic_ctlr_install, - test_csip_set_member_install, - test_csip_set_coordinator_install, - test_tbs_install, - test_tbs_client_install, - test_mcs_install, - test_mcc_install, - test_media_controller_install, - test_unicast_client_install, - test_unicast_server_install, - test_broadcast_source_install, - test_broadcast_sink_install, - test_scan_delegator_install, - test_bap_broadcast_assistant_install, - test_bass_broadcaster_install, - test_cap_acceptor_install, - test_cap_initiator_install, - test_has_install, - test_has_client_install, - test_ias_install, - test_ias_client_install, - NULL -}; - -void main(void) -{ - bst_main(); -} diff --git a/tests/bluetooth/bsim/audio/src/mcc_test.c b/tests/bluetooth/bsim/audio/src/mcc_test.c deleted file mode 100644 index 41493f1d7cc..00000000000 --- a/tests/bluetooth/bsim/audio/src/mcc_test.c +++ /dev/null @@ -1,1873 +0,0 @@ -/* - * Copyright (c) 2019 - 2021 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifdef CONFIG_BT_MCC - -#include -#include -#include - -#include "common.h" - -extern enum bst_result_t bst_result; - -static struct bt_mcc_cb mcc_cb; - -static uint64_t g_icon_object_id; -static uint64_t g_track_segments_object_id; -static uint64_t g_current_track_object_id; -static uint64_t g_next_track_object_id; -static uint64_t g_parent_group_object_id; -static uint64_t g_current_group_object_id; -static uint64_t g_search_results_object_id; - -static int32_t g_pos; -static int8_t g_pb_speed; -static uint8_t g_playing_order; -static uint8_t g_state; -static uint8_t g_command_result; -static uint8_t g_search_result; - -CREATE_FLAG(ble_is_initialized); -CREATE_FLAG(ble_link_is_ready); -CREATE_FLAG(discovery_done); -CREATE_FLAG(player_name_read); -CREATE_FLAG(icon_object_id_read); -CREATE_FLAG(icon_url_read); -CREATE_FLAG(track_change_notified); -CREATE_FLAG(track_title_read); -CREATE_FLAG(track_duration_read); -CREATE_FLAG(track_position_read); -CREATE_FLAG(track_position_set); -CREATE_FLAG(playback_speed_read); -CREATE_FLAG(playback_speed_set); -CREATE_FLAG(seeking_speed_read); -CREATE_FLAG(track_segments_object_id_read); -CREATE_FLAG(current_track_object_id_read); -CREATE_FLAG(current_track_object_id_set); -CREATE_FLAG(next_track_object_id_read); -CREATE_FLAG(next_track_object_id_set); -CREATE_FLAG(parent_group_object_id_read); -CREATE_FLAG(current_group_object_id_read); -CREATE_FLAG(current_group_object_id_set); -CREATE_FLAG(search_results_object_id_read); -CREATE_FLAG(playing_order_read); -CREATE_FLAG(playing_order_set); -CREATE_FLAG(playing_orders_supported_read); -CREATE_FLAG(ccid_read); -CREATE_FLAG(media_state_read); -CREATE_FLAG(command_sent); -CREATE_FLAG(command_notified); -CREATE_FLAG(search_sent); -CREATE_FLAG(search_notified); -CREATE_FLAG(object_selected); -CREATE_FLAG(metadata_read); -CREATE_FLAG(object_read); - - -static void mcc_discover_mcs_cb(struct bt_conn *conn, int err) -{ - if (err) { - FAIL("Discovery of MCS failed (%d)\n", err); - return; - } - - SET_FLAG(discovery_done); -} - -static void mcc_read_player_name_cb(struct bt_conn *conn, int err, const char *name) -{ - if (err) { - FAIL("Player Name read failed (%d)\n", err); - return; - } - - SET_FLAG(player_name_read); -} - -static void mcc_read_icon_obj_id_cb(struct bt_conn *conn, int err, uint64_t id) -{ - if (err) { - FAIL("Icon Object ID read failed (%d)", err); - return; - } - - g_icon_object_id = id; - SET_FLAG(icon_object_id_read); -} - -static void mcc_read_icon_url_cb(struct bt_conn *conn, int err, const char *url) -{ - if (err) { - FAIL("Icon URL read failed (%d)", err); - return; - } - - SET_FLAG(icon_url_read); -} - -static void mcc_track_changed_ntf_cb(struct bt_conn *conn, int err) -{ - if (err) { - FAIL("Track change notification failed (%d)", err); - return; - } - - SET_FLAG(track_change_notified); -} - -static void mcc_read_track_title_cb(struct bt_conn *conn, int err, const char *title) -{ - if (err) { - FAIL("Track title read failed (%d)", err); - return; - } - - SET_FLAG(track_title_read); -} - -static void mcc_read_track_duration_cb(struct bt_conn *conn, int err, int32_t dur) -{ - if (err) { - FAIL("Track duration read failed (%d)", err); - return; - } - - SET_FLAG(track_duration_read); -} - -static void mcc_read_track_position_cb(struct bt_conn *conn, int err, int32_t pos) -{ - if (err) { - FAIL("Track position read failed (%d)", err); - return; - } - - g_pos = pos; - SET_FLAG(track_position_read); -} - -static void mcc_set_track_position_cb(struct bt_conn *conn, int err, int32_t pos) -{ - if (err) { - FAIL("Track Position set failed (%d)", err); - return; - } - - g_pos = pos; - SET_FLAG(track_position_set); -} - -static void mcc_read_playback_speed_cb(struct bt_conn *conn, int err, - int8_t speed) -{ - if (err) { - FAIL("Playback speed read failed (%d)", err); - return; - } - - g_pb_speed = speed; - SET_FLAG(playback_speed_read); -} - -static void mcc_set_playback_speed_cb(struct bt_conn *conn, int err, int8_t speed) -{ - if (err) { - FAIL("Playback speed set failed (%d)", err); - return; - } - - g_pb_speed = speed; - SET_FLAG(playback_speed_set); -} - -static void mcc_read_seeking_speed_cb(struct bt_conn *conn, int err, - int8_t speed) -{ - if (err) { - FAIL("Seeking speed read failed (%d)", err); - return; - } - - SET_FLAG(seeking_speed_read); -} - -static void mcc_read_segments_obj_id_cb(struct bt_conn *conn, int err, - uint64_t id) -{ - if (err) { - FAIL("Track Segments ID read failed (%d)\n", err); - return; - } - - g_track_segments_object_id = id; - SET_FLAG(track_segments_object_id_read); -} - -static void mcc_read_current_track_obj_id_cb(struct bt_conn *conn, int err, - uint64_t id) -{ - if (err) { - FAIL("Current Track Object ID read failed (%d)\n", err); - return; - } - - g_current_track_object_id = id; - SET_FLAG(current_track_object_id_read); -} - -static void mcc_set_current_track_obj_id_cb(struct bt_conn *conn, int err, - uint64_t id) -{ - if (err) { - FAIL("Current Track Object ID set failed (%d)\n", err); - return; - } - - g_current_track_object_id = id; - SET_FLAG(current_track_object_id_set); -} - -static void mcc_read_next_track_obj_id_cb(struct bt_conn *conn, int err, - uint64_t id) -{ - if (err) { - FAIL("Next Track Object ID read failed (%d)\n", err); - return; - } - - g_next_track_object_id = id; - SET_FLAG(next_track_object_id_read); -} - -static void mcc_set_next_track_obj_id_cb(struct bt_conn *conn, int err, - uint64_t id) -{ - if (err) { - FAIL("Next Track Object ID set failed (%d)\n", err); - return; - } - - g_next_track_object_id = id; - SET_FLAG(next_track_object_id_set); -} - -static void mcc_read_parent_group_obj_id_cb(struct bt_conn *conn, int err, - uint64_t id) -{ - if (err) { - FAIL("Parent Group Object ID read failed (%d)\n", err); - return; - } - - g_parent_group_object_id = id; - SET_FLAG(parent_group_object_id_read); -} - -static void mcc_read_current_group_obj_id_cb(struct bt_conn *conn, int err, - uint64_t id) -{ - if (err) { - FAIL("Current Group Object ID read failed (%d)\n", err); - return; - } - - g_current_group_object_id = id; - SET_FLAG(current_group_object_id_read); -} - -static void mcc_set_current_group_obj_id_cb(struct bt_conn *conn, int err, - uint64_t id) -{ - if (err) { - FAIL("Current Group Object ID set failed (%d)\n", err); - return; - } - - g_current_group_object_id = id; - SET_FLAG(current_group_object_id_set); -} - -static void mcc_read_playing_order_cb(struct bt_conn *conn, int err, uint8_t order) -{ - if (err) { - FAIL("Playing order read failed (%d)", err); - return; - } - - g_playing_order = order; - SET_FLAG(playing_order_read); -} - -static void mcc_set_playing_order_cb(struct bt_conn *conn, int err, uint8_t order) -{ - if (err) { - FAIL("Playing order set failed (%d)", err); - return; - } - - g_playing_order = order; - SET_FLAG(playing_order_set); -} - -static void mcc_read_playing_orders_supported_cb(struct bt_conn *conn, int err, - uint16_t orders) -{ - if (err) { - FAIL("Playing orders supported read failed (%d)", err); - return; - } - - SET_FLAG(playing_orders_supported_read); -} - -static void mcc_read_media_state_cb(struct bt_conn *conn, int err, uint8_t state) -{ - if (err) { - FAIL("Media State read failed (%d)", err); - return; - } - - g_state = state; - SET_FLAG(media_state_read); -} - -static void mcc_send_command_cb(struct bt_conn *conn, int err, const struct mpl_cmd *cmd) -{ - if (err) { - FAIL("Command send failed (%d) - opcode: %u, param: %d", - err, cmd->opcode, cmd->param); - return; - } - - SET_FLAG(command_sent); -} - -static void mcc_cmd_ntf_cb(struct bt_conn *conn, int err, const struct mpl_cmd_ntf *ntf) -{ - if (err) { - FAIL("Command notification error (%d) - opcode: %u, result: %u", - err, ntf->requested_opcode, ntf->result_code); - return; - } - - g_command_result = ntf->result_code; - SET_FLAG(command_notified); -} - -static void mcc_send_search_cb(struct bt_conn *conn, int err, - const struct mpl_search *search) -{ - if (err) { - FAIL("Search send failed (%d)", err); - return; - } - - SET_FLAG(search_sent); -} - -static void mcc_search_ntf_cb(struct bt_conn *conn, int err, uint8_t result_code) -{ - if (err) { - FAIL("Search notification error (%d), result code: %u", - err, result_code); - return; - } - - g_search_result = result_code; - SET_FLAG(search_notified); -} - -static void mcc_read_search_results_obj_id_cb(struct bt_conn *conn, int err, - uint64_t id) -{ - if (err) { - FAIL("Search Results Object ID read failed (%d)", err); - return; - } - - g_search_results_object_id = id; - SET_FLAG(search_results_object_id_read); -} - -static void mcc_read_content_control_id_cb(struct bt_conn *conn, int err, uint8_t ccid) -{ - if (err) { - FAIL("Content control ID read failed (%d)", err); - return; - } - - SET_FLAG(ccid_read); -} - -static void mcc_otc_obj_selected_cb(struct bt_conn *conn, int err) -{ - if (err) { - FAIL("Selecting object failed (%d)\n", err); - return; - } - - SET_FLAG(object_selected); -} - -static void mcc_otc_obj_metadata_cb(struct bt_conn *conn, int err) -{ - if (err) { - FAIL("Reading object metadata failed (%d)\n", err); - return; - } - - SET_FLAG(metadata_read); -} - -static void mcc_icon_object_read_cb(struct bt_conn *conn, int err, - struct net_buf_simple *buf) -{ - if (err) { - FAIL("Reading Icon Object failed (%d)", err); - return; - } - - SET_FLAG(object_read); -} - -static void mcc_track_segments_object_read_cb(struct bt_conn *conn, int err, - struct net_buf_simple *buf) -{ - if (err) { - FAIL("Reading Track Segments Object failed (%d)", err); - return; - } - - SET_FLAG(object_read); -} - -static void mcc_otc_read_current_track_object_cb(struct bt_conn *conn, int err, - struct net_buf_simple *buf) -{ - if (err) { - FAIL("Current Track Object read failed (%d)", err); - return; - } - - SET_FLAG(object_read); -} - -static void mcc_otc_read_next_track_object_cb(struct bt_conn *conn, int err, - struct net_buf_simple *buf) -{ - if (err) { - FAIL("Next Track Object read failed (%d)", err); - return; - } - - SET_FLAG(object_read); -} - -static void mcc_otc_read_parent_group_object_cb(struct bt_conn *conn, int err, - struct net_buf_simple *buf) -{ - if (err) { - FAIL("Parent Group Object read failed (%d)", err); - return; - } - - SET_FLAG(object_read); -} - -static void mcc_otc_read_current_group_object_cb(struct bt_conn *conn, int err, - struct net_buf_simple *buf) -{ - if (err) { - FAIL("Current Group Object read failed (%d)", err); - return; - } - - SET_FLAG(object_read); -} - -int do_mcc_init(void) -{ - /* Set up the callbacks */ - mcc_cb.discover_mcs = mcc_discover_mcs_cb; - mcc_cb.read_player_name = mcc_read_player_name_cb; - mcc_cb.read_icon_obj_id = mcc_read_icon_obj_id_cb; - mcc_cb.read_icon_url = mcc_read_icon_url_cb; - mcc_cb.track_changed_ntf = mcc_track_changed_ntf_cb; - mcc_cb.read_track_title = mcc_read_track_title_cb; - mcc_cb.read_track_duration = mcc_read_track_duration_cb; - mcc_cb.read_track_position = mcc_read_track_position_cb; - mcc_cb.set_track_position = mcc_set_track_position_cb; - mcc_cb.read_playback_speed = mcc_read_playback_speed_cb; - mcc_cb.set_playback_speed = mcc_set_playback_speed_cb; - mcc_cb.read_seeking_speed = mcc_read_seeking_speed_cb; - mcc_cb.read_current_track_obj_id = mcc_read_current_track_obj_id_cb; - mcc_cb.set_current_track_obj_id = mcc_set_current_track_obj_id_cb; - mcc_cb.read_next_track_obj_id = mcc_read_next_track_obj_id_cb; - mcc_cb.set_next_track_obj_id = mcc_set_next_track_obj_id_cb; - mcc_cb.read_segments_obj_id = mcc_read_segments_obj_id_cb; - mcc_cb.read_parent_group_obj_id = mcc_read_parent_group_obj_id_cb; - mcc_cb.read_current_group_obj_id = mcc_read_current_group_obj_id_cb; - mcc_cb.set_current_group_obj_id = mcc_set_current_group_obj_id_cb; - mcc_cb.read_playing_order = mcc_read_playing_order_cb; - mcc_cb.set_playing_order = mcc_set_playing_order_cb; - mcc_cb.read_playing_orders_supported = mcc_read_playing_orders_supported_cb; - mcc_cb.read_media_state = mcc_read_media_state_cb; - mcc_cb.send_cmd = mcc_send_command_cb; - mcc_cb.cmd_ntf = mcc_cmd_ntf_cb; - mcc_cb.send_search = mcc_send_search_cb; - mcc_cb.search_ntf = mcc_search_ntf_cb; - mcc_cb.read_search_results_obj_id = mcc_read_search_results_obj_id_cb; - mcc_cb.read_content_control_id = mcc_read_content_control_id_cb; - mcc_cb.otc_obj_selected = mcc_otc_obj_selected_cb; - mcc_cb.otc_obj_metadata = mcc_otc_obj_metadata_cb; - mcc_cb.otc_icon_object = mcc_icon_object_read_cb; - mcc_cb.otc_track_segments_object = mcc_track_segments_object_read_cb; - mcc_cb.otc_current_track_object = mcc_otc_read_current_track_object_cb; - mcc_cb.otc_next_track_object = mcc_otc_read_next_track_object_cb; - mcc_cb.otc_parent_group_object = mcc_otc_read_parent_group_object_cb; - mcc_cb.otc_current_group_object = mcc_otc_read_current_group_object_cb; - - /* Initialize the module */ - return bt_mcc_init(&mcc_cb); -} - -/* Callback after Bluetoot initialization attempt */ -static void bt_ready(int err) -{ - if (err) { - FAIL("Bluetooth init failed (err %d)\n", err); - return; - } - - SET_FLAG(ble_is_initialized); -} - -/* Callback on connection */ -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err) { - bt_conn_unref(default_conn); - default_conn = NULL; - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - SET_FLAG(ble_link_is_ready); -} - -/* Helper function - select object and read the object metadata - * - * Will FAIL the test on errors calling select and read metadata. - * Will WAIT (hang) until callbacks are received. - * If callbacks are not received, the test fill FAIL due to timeout. - * - * @param object_id ID of the object to select and read metadata for - */ -static void select_read_meta(int64_t id) -{ - int err; - - /* TODO: Fix the instance pointer - it is neither valid nor used */ - UNSET_FLAG(object_selected); - err = bt_ots_client_select_id(bt_mcc_otc_inst(default_conn), - default_conn, id); - if (err) { - FAIL("Failed to select object\n"); - return; - } - - WAIT_FOR_FLAG(object_selected); - printk("Selecting object succeeded\n"); - - /* TODO: Fix the instance pointer - it is neither valid nor used */ - UNSET_FLAG(metadata_read); - err = bt_ots_client_read_object_metadata(bt_mcc_otc_inst(default_conn), - default_conn, - BT_OTS_METADATA_REQ_ALL); - if (err) { - FAIL("Failed to read object metadata\n"); - return; - } - - WAIT_FOR_FLAG(metadata_read); - printk("Reading object metadata succeeded\n"); -} - -/* Helper function to read the media state and verify that it is as expected - * Will FAIL on error reading the media state - * Will FAIL if the state is not as expected - * - * Returns true if the state is as expected - * Returns false in case of errors, or if the state is not as expected - */ -static bool test_verify_media_state_wait_flags(uint8_t expected_state) -{ - int err; - - UNSET_FLAG(media_state_read); - err = bt_mcc_read_media_state(default_conn); - if (err) { - FAIL("Failed to read media state: %d", err); - return false; - } - - WAIT_FOR_FLAG(media_state_read); - if (g_state != expected_state) { - FAIL("Server is not in expected state: %d, expected: %d\n", - g_state, expected_state); - return false; - } - - return true; -} - -/* Helper function to write commands to to the control point, including the - * flag handling. - * Will FAIL on error to send the command. - * Will WAIT for the required flags before returning. - */ -static void test_send_cmd_wait_flags(struct mpl_cmd *cmd) -{ - int err; - - /* Need both flags, even if the notification result is what we care - * about. The notification may come before the write callback, and if - * the write callback has not yet arrived, we will get EBUSY at the - * next call. - */ - UNSET_FLAG(command_sent); - UNSET_FLAG(command_notified); - err = bt_mcc_send_cmd(default_conn, cmd); - if (err) { - FAIL("Failed to send command: %d, opcode: %u", - err, cmd->opcode); - return; - } - - WAIT_FOR_FLAG(command_sent); - WAIT_FOR_FLAG(command_notified); -} - -static void test_cp_play(void) -{ - struct mpl_cmd cmd; - - cmd.opcode = BT_MCS_OPC_PLAY; - cmd.use_param = false; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) { - FAIL("PLAY command failed\n"); - return; - } - - if (test_verify_media_state_wait_flags(BT_MCS_MEDIA_STATE_PLAYING)) { - printk("PLAY command succeeded\n"); - } -} - -static void test_cp_pause(void) -{ - struct mpl_cmd cmd; - - cmd.opcode = BT_MCS_OPC_PAUSE; - cmd.use_param = false; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) { - FAIL("PAUSE command failed\n"); - return; - } - - if (test_verify_media_state_wait_flags(BT_MCS_MEDIA_STATE_PAUSED)) { - printk("PAUSE command succeeded\n"); - } -} - -static void test_cp_fast_rewind(void) -{ - struct mpl_cmd cmd; - - cmd.opcode = BT_MCS_OPC_FAST_REWIND; - cmd.use_param = false; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) { - FAIL("FAST REWIND command failed\n"); - return; - } - - if (test_verify_media_state_wait_flags(BT_MCS_MEDIA_STATE_SEEKING)) { - printk("FAST REWIND command succeeded\n"); - } -} - -static void test_cp_fast_forward(void) -{ - struct mpl_cmd cmd; - - cmd.opcode = BT_MCS_OPC_FAST_FORWARD; - cmd.use_param = false; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) { - FAIL("FAST FORWARD command failed\n"); - return; - } - - if (test_verify_media_state_wait_flags(BT_MCS_MEDIA_STATE_SEEKING)) { - printk("FAST FORWARD command succeeded\n"); - } -} - -static void test_cp_stop(void) -{ - struct mpl_cmd cmd; - - cmd.opcode = BT_MCS_OPC_STOP; - cmd.use_param = false; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) { - FAIL("STOP command failed\n"); - return; - } - - /* There is no "STOPPED" state in the spec - STOP goes to PAUSED */ - if (test_verify_media_state_wait_flags(BT_MCS_MEDIA_STATE_PAUSED)) { - printk("STOP command succeeded\n"); - } -} - -static void test_cp_move_relative(void) -{ - int err; - struct mpl_cmd cmd; - - /* Assumes that the server is in a state where it is able to change - * the current track position - * Also assumes position will not change by itself, which is wrong if - * if the player is playing. - */ - UNSET_FLAG(track_position_read); - err = bt_mcc_read_track_position(default_conn); - if (err) { - FAIL("Failed to read track position: %d\n", err); - return; - } - - WAIT_FOR_FLAG(track_position_read); - uint32_t tmp_pos = g_pos; - - cmd.opcode = BT_MCS_OPC_MOVE_RELATIVE; - cmd.use_param = true; - cmd.param = 1000; /* Position change, measured in 1/100 of a second */ - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) { - FAIL("MOVE RELATIVE command failed\n"); - return; - } - - UNSET_FLAG(track_position_read); - err = bt_mcc_read_track_position(default_conn); - if (err) { - FAIL("Failed to read track position: %d\n", err); - return; - } - - WAIT_FOR_FLAG(track_position_read); - if (g_pos == tmp_pos) { - /* Position did not change */ - FAIL("Server did not move track position\n"); - return; - } - - printk("MOVE RELATIVE command succeeded\n"); -} - -static void test_cp_prev_segment(void) -{ - struct mpl_cmd cmd; - - /* Assumes that the server is in a state where there is a current - * track that has segments, and where the server may switch between - * these - */ - - /* To properly verify track segment changes, the track segments - * object must be downloaded and parsed. That is somewhat complex, - * and is getting close to what the qualification tests do. - * Alternatively, the track position may be checked, but the server - * implementation does not set that for segment changes yet. - * For now, we will settle for seeing that the opcodes are accepted. - */ - - cmd.opcode = BT_MCS_OPC_PREV_SEGMENT; - cmd.use_param = false; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) { - FAIL("PREV SEGMENT command failed\n"); - return; - } - - printk("PREV SEGMENT command succeeded\n"); -} - -static void test_cp_next_segment(void) -{ - struct mpl_cmd cmd; - - cmd.opcode = BT_MCS_OPC_NEXT_SEGMENT; - cmd.use_param = false; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) { - FAIL("NEXT SEGMENT command failed\n"); - return; - } - - printk("NEXT SEGMENT command succeeded\n"); -} - -static void test_cp_first_segment(void) -{ - struct mpl_cmd cmd; - - cmd.opcode = BT_MCS_OPC_FIRST_SEGMENT; - cmd.use_param = false; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) { - FAIL("FIRST SEGMENT command failed\n"); - return; - } - - printk("FIRST SEGMENT command succeeded\n"); -} - -static void test_cp_last_segment(void) -{ - struct mpl_cmd cmd; - - cmd.opcode = BT_MCS_OPC_LAST_SEGMENT; - cmd.use_param = false; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) { - FAIL("LAST SEGMENT command failed\n"); - return; - } - - printk("LAST SEGMENT command succeeded\n"); -} - -static void test_cp_goto_segment(void) -{ - struct mpl_cmd cmd; - - cmd.opcode = BT_MCS_OPC_GOTO_SEGMENT; - cmd.use_param = true; - cmd.param = 2; /* Second segment - not the first, maybe not last */ - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) { - FAIL("GOTO SEGMENT command failed\n"); - return; - } - - printk("GOTO SEGMENT command succeeded\n"); -} - -/* Helper function to read the current track object ID, including flag handling - * Will FAIL on error reading object ID - * Will WAIT until the read is completed (object ID flag read flag is set) - */ -static void test_read_current_track_object_id_wait_flags(void) -{ - int err; - - UNSET_FLAG(current_track_object_id_read); - err = bt_mcc_read_current_track_obj_id(default_conn); - if (err) { - FAIL("Failed to read current track object ID: %d", err); - return; - } - - WAIT_FOR_FLAG(current_track_object_id_read); -} - -static void test_cp_prev_track(void) -{ - uint64_t object_id; - struct mpl_cmd cmd; - - /* Assumes that the server is in a state where it has multiple tracks - * and can change between them. - */ - - /* To verify that a track change has happeded, the test checks that the - * current track object ID has changed. - */ - - cmd.opcode = BT_MCS_OPC_PREV_TRACK; - cmd.use_param = false; - - test_read_current_track_object_id_wait_flags(); - object_id = g_current_track_object_id; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) { - FAIL("PREV TRACK command failed\n"); - return; - } - - test_read_current_track_object_id_wait_flags(); - - if (g_current_track_object_id == object_id) { - /* Track did not change */ - FAIL("Server did not change track\n"); - return; - } - - printk("PREV TRACK command succeeded\n"); -} - -static void test_cp_next_track_and_track_changed(void) -{ - uint64_t object_id; - struct mpl_cmd cmd; - - /* This test is also used to test the track changed notification */ - UNSET_FLAG(track_change_notified); - - cmd.opcode = BT_MCS_OPC_NEXT_TRACK; - cmd.use_param = false; - - test_read_current_track_object_id_wait_flags(); - object_id = g_current_track_object_id; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) { - FAIL("NEXT TRACK command failed\n"); - return; - } - - WAIT_FOR_FLAG(track_change_notified); - printk("Track change notified\n"); - - test_read_current_track_object_id_wait_flags(); - - if (g_current_track_object_id == object_id) { - FAIL("Server did not change track\n"); - return; - } - - printk("NEXT TRACK command succeeded\n"); -} - -static void test_cp_first_track(void) -{ - uint64_t object_id; - struct mpl_cmd cmd; - - cmd.opcode = BT_MCS_OPC_FIRST_TRACK; - cmd.use_param = false; - - test_read_current_track_object_id_wait_flags(); - object_id = g_current_track_object_id; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) { - FAIL("FIRST TRACK command failed\n"); - return; - } - - test_read_current_track_object_id_wait_flags(); - - if (g_current_track_object_id == object_id) { - FAIL("Server did not change track\n"); - return; - } - - printk("FIRST TRACK command succeeded\n"); -} - -static void test_cp_last_track(void) -{ - uint64_t object_id; - struct mpl_cmd cmd; - - cmd.opcode = BT_MCS_OPC_LAST_TRACK; - cmd.use_param = false; - - test_read_current_track_object_id_wait_flags(); - object_id = g_current_track_object_id; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) { - FAIL("LAST TRACK command failed\n"); - return; - } - - test_read_current_track_object_id_wait_flags(); - - if (g_current_track_object_id == object_id) { - FAIL("Server did not change track\n"); - return; - } - - printk("LAST TRACK command succeeded\n"); -} - -static void test_cp_goto_track(void) -{ - uint64_t object_id; - struct mpl_cmd cmd; - - cmd.opcode = BT_MCS_OPC_GOTO_TRACK; - cmd.use_param = true; - cmd.param = 2; /* Second track, not the first, maybe not the last */ - - test_read_current_track_object_id_wait_flags(); - object_id = g_current_track_object_id; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) { - FAIL("GOTO TRACK command failed\n"); - return; - } - - test_read_current_track_object_id_wait_flags(); - - if (g_current_track_object_id == object_id) { - FAIL("Server did not change track\n"); - return; - } - - printk("GOTO TRACK command succeeded\n"); -} - -/* Helper function to read the current group object ID, including flag handling - * Will FAIL on error reading object ID - * Will WAIT until the read is completed (object ID flag read flag is set) - */ -static void test_read_current_group_object_id_wait_flags(void) -{ - int err; - - UNSET_FLAG(current_group_object_id_read); - err = bt_mcc_read_current_group_obj_id(default_conn); - if (err) { - FAIL("Failed to read current group object ID: %d", err); - return; - } - - WAIT_FOR_FLAG(current_group_object_id_read); -} - -static void test_cp_prev_group(void) -{ - uint64_t object_id; - struct mpl_cmd cmd; - - /* Assumes that the server is in a state where it has multiple groups - * and can change between them. - */ - - /* To verify that a group change has happeded, the test checks that the - * current group object ID has changed. - */ - - cmd.opcode = BT_MCS_OPC_PREV_GROUP; - cmd.use_param = false; - - test_read_current_group_object_id_wait_flags(); - object_id = g_current_group_object_id; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) { - FAIL("PREV GROUP command failed\n"); - return; - } - - test_read_current_group_object_id_wait_flags(); - - if (g_current_group_object_id == object_id) { - /* Group did not change */ - FAIL("Server did not change group\n"); - return; - } - - printk("PREV GROUP command succeeded\n"); -} - -static void test_cp_next_group(void) -{ - uint64_t object_id; - struct mpl_cmd cmd; - - cmd.opcode = BT_MCS_OPC_NEXT_GROUP; - cmd.use_param = false; - - test_read_current_group_object_id_wait_flags(); - object_id = g_current_group_object_id; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) { - FAIL("NEXT GROUP command failed\n"); - return; - } - - test_read_current_group_object_id_wait_flags(); - - if (g_current_group_object_id == object_id) { - FAIL("Server did not change group\n"); - return; - } - - printk("NEXT GROUP command succeeded\n"); -} - -static void test_cp_first_group(void) -{ - uint64_t object_id; - struct mpl_cmd cmd; - - cmd.opcode = BT_MCS_OPC_FIRST_GROUP; - cmd.use_param = false; - - test_read_current_group_object_id_wait_flags(); - object_id = g_current_group_object_id; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) { - FAIL("FIRST GROUP command failed\n"); - return; - } - - test_read_current_group_object_id_wait_flags(); - - if (g_current_group_object_id == object_id) { - FAIL("Server did not change group\n"); - return; - } - - printk("FIRST GROUP command succeeded\n"); -} - -static void test_cp_last_group(void) -{ - uint64_t object_id; - struct mpl_cmd cmd; - - cmd.opcode = BT_MCS_OPC_LAST_GROUP; - cmd.use_param = false; - - test_read_current_group_object_id_wait_flags(); - object_id = g_current_group_object_id; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) { - FAIL("LAST GROUP command failed\n"); - return; - } - - test_read_current_group_object_id_wait_flags(); - - if (g_current_group_object_id == object_id) { - FAIL("Server did not change group\n"); - return; - } - - printk("LAST GROUP command succeeded\n"); -} - -static void test_cp_goto_group(void) -{ - uint64_t object_id; - struct mpl_cmd cmd; - - cmd.opcode = BT_MCS_OPC_GOTO_GROUP; - cmd.use_param = true; - cmd.param = 2; /* Second group, not the first, maybe not the last */ - - test_read_current_group_object_id_wait_flags(); - object_id = g_current_group_object_id; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != BT_MCS_OPC_NTF_SUCCESS) { - FAIL("GOTO GROUP command failed\n"); - return; - } - - test_read_current_group_object_id_wait_flags(); - - if (g_current_group_object_id == object_id) { - FAIL("Server did not change group\n"); - return; - } - - printk("GOTO GROUP command succeeded\n"); -} - -static void test_search(void) -{ - struct mpl_search search; - struct mpl_sci sci = {0}; - int err; - - /* Test outline: - * - verify that the search results object ID is zero before search - * - write a search (one search control item) to the search control point, - * get write callback and notification - * - verify that the search results object ID is non-zero - */ - - UNSET_FLAG(search_results_object_id_read); - err = bt_mcc_read_search_results_obj_id(default_conn); - - if (err) { - FAIL("Failed to read search results object ID: %d", err); - return; - } - - WAIT_FOR_FLAG(search_results_object_id_read); - - if (g_search_results_object_id != 0) { - FAIL("Search results object ID not zero before search\n"); - return; - } - - /* Set up the search control item, then the search - * Note: As of now, the server implementation only fakes the search, - * so it makes no difference what we search for. The result is the - * same anyway. - */ - sci.type = BT_MCS_SEARCH_TYPE_TRACK_NAME; - strcpy(sci.param, "Some track name"); - /* Length is length of type, plus length of param w/o termination */ - sci.len = sizeof(sci.type) + strlen(sci.param); - - search.len = 0; - memcpy(&search.search[search.len], &sci.len, sizeof(sci.len)); - search.len += sizeof(sci.len); - - memcpy(&search.search[search.len], &sci.type, sizeof(sci.type)); - search.len += sizeof(sci.type); - - memcpy(&search.search[search.len], &sci.param, strlen(sci.param)); - search.len += strlen(sci.param); - - UNSET_FLAG(search_sent); - UNSET_FLAG(search_notified); - UNSET_FLAG(search_results_object_id_read); - - err = bt_mcc_send_search(default_conn, &search); - if (err) { - FAIL("Failed to write to search control point\n"); - return; - } - - WAIT_FOR_FLAG(search_sent); - WAIT_FOR_FLAG(search_notified); - - if (g_search_result != BT_MCS_SCP_NTF_SUCCESS) { - FAIL("SEARCH operation failed\n"); - return; - } - - /* A search results object will have been created and the search - * results object ID will have been notified if the search gave results - */ - WAIT_FOR_FLAG(search_results_object_id_read); - if (g_search_results_object_id == 0) { - FAIL("No search results\n"); - return; - } - - printk("SEARCH operation succeeded\n"); -} - -/* This function tests all commands in the API in sequence - * The order of the sequence follows the order of the characterstics in the - * Media Control Service specification - */ -void test_main(void) -{ - int err; - uint64_t tmp_object_id; - - static struct bt_conn_cb conn_callbacks = { - .connected = connected, - .disconnected = disconnected, - }; - - printk("Media Control Client test application. Board: %s\n", CONFIG_BOARD); - - UNSET_FLAG(ble_is_initialized); - err = bt_enable(bt_ready); - if (err) { - FAIL("Bluetooth init failed (err %d)\n", err); - return; - } - - WAIT_FOR_FLAG(ble_is_initialized); - printk("Bluetooth initialized\n"); - - bt_conn_cb_register(&conn_callbacks); - - /* Connect ******************************************/ - UNSET_FLAG(ble_link_is_ready); - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); - if (err) { - FAIL("Failed to start scanning (err %d\n)", err); - } else { - printk("Scanning started successfully\n"); - } - - WAIT_FOR_FLAG(ble_link_is_ready); - - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(default_conn), addr, sizeof(addr)); - printk("Connected: %s\n", addr); - - /* Initialize MCC ********************************************/ - err = do_mcc_init(); - if (err) { - FAIL("Could not initialize MCC (err %d\n)", err); - } else { - printk("MCC init succeeded\n"); - } - - /* Discover MCS, subscribe to notifications *******************/ - UNSET_FLAG(discovery_done); - err = bt_mcc_discover_mcs(default_conn, true); - if (err) { - FAIL("Failed to start discovery of MCS: %d\n", err); - } - - WAIT_FOR_FLAG(discovery_done); - printk("Discovery of MCS succeeded\n"); - - /* Read media player name ******************************************/ - UNSET_FLAG(player_name_read); - err = bt_mcc_read_player_name(default_conn); - if (err) { - FAIL("Failed to read media player name ID: %d", err); - return; - } - - WAIT_FOR_FLAG(player_name_read); - printk("Player Name read succeeded\n"); - - /* Read icon object ******************************************/ - UNSET_FLAG(icon_object_id_read); - err = bt_mcc_read_icon_obj_id(default_conn); - if (err) { - FAIL("Failed to read icon object ID: %d", err); - return; - } - - WAIT_FOR_FLAG(icon_object_id_read); - printk("Icon Object ID read succeeded\n"); - - select_read_meta(g_icon_object_id); - UNSET_FLAG(object_read); - err = bt_mcc_otc_read_icon_object(default_conn); - - if (err) { - FAIL("Failed to read icon object\n"); - return; - } - - WAIT_FOR_FLAG(object_read); - printk("Reading Icon Object succeeded\n"); - - /* Read icon url *************************************************/ - UNSET_FLAG(icon_url_read); - err = bt_mcc_read_icon_url(default_conn); - if (err) { - FAIL("Failed to read icon url: %d", err); - return; - } - - WAIT_FOR_FLAG(icon_url_read); - printk("Icon URL read succeeded\n"); - - /* Track changed ************************************************ - * - * The track changed characteristic is tested as part of the control - * point next track test - */ - - /* Read track_title ******************************************/ - UNSET_FLAG(track_title_read); - err = bt_mcc_read_track_title(default_conn); - if (err) { - FAIL("Failed to read track_title: %d", err); - return; - } - - WAIT_FOR_FLAG(track_title_read); - printk("Track title read succeeded\n"); - - /* Read track_duration ******************************************/ - UNSET_FLAG(track_duration_read); - err = bt_mcc_read_track_duration(default_conn); - if (err) { - FAIL("Failed to read track_duration: %d", err); - return; - } - - WAIT_FOR_FLAG(track_duration_read); - printk("Track duration read succeeded\n"); - - /* Read and set track_position *************************************/ - UNSET_FLAG(track_position_read); - err = bt_mcc_read_track_position(default_conn); - if (err) { - FAIL("Failed to read track position: %d", err); - return; - } - - WAIT_FOR_FLAG(track_position_read); - printk("Track position read succeeded\n"); - - int32_t pos = g_pos + 1200; /*12 seconds further into the track */ - - UNSET_FLAG(track_position_set); - err = bt_mcc_set_track_position(default_conn, pos); - if (err) { - FAIL("Failed to set track position: %d", err); - return; - } - - WAIT_FOR_FLAG(track_position_set); - if (g_pos != pos) { - /* In this controlled case, we expect that the resulting */ - /* position is the position given in the set command */ - FAIL("Track position set failed: Incorrect position\n"); - } - printk("Track position set succeeded\n"); - - /* Read and set playback speed *************************************/ - UNSET_FLAG(playback_speed_read); - err = bt_mcc_read_playback_speed(default_conn); - if (err) { - FAIL("Failed to read playback speed: %d", err); - return; - } - - WAIT_FOR_FLAG(playback_speed_read); - printk("Playback speed read succeeded\n"); - - int8_t pb_speed = g_pb_speed + 8; /* 2^(8/64) faster than current speed */ - - UNSET_FLAG(playback_speed_set); - err = bt_mcc_set_playback_speed(default_conn, pb_speed); - if (err) { - FAIL("Failed to set playback speed: %d", err); - return; - } - - WAIT_FOR_FLAG(playback_speed_set); - if (g_pb_speed != pb_speed) { - FAIL("Playback speed failed: Incorrect playback speed\n"); - } - printk("Playback speed set succeeded\n"); - - /* Read seeking speed *************************************/ - UNSET_FLAG(seeking_speed_read); - err = bt_mcc_read_seeking_speed(default_conn); - if (err) { - FAIL("Failed to read seeking speed: %d", err); - return; - } - - WAIT_FOR_FLAG(seeking_speed_read); - printk("Seeking speed read succeeded\n"); - - /* Read track segments object *****************************************/ - UNSET_FLAG(track_segments_object_id_read); - err = bt_mcc_read_segments_obj_id(default_conn); - if (err) { - FAIL("Failed to read track segments object ID: %d", err); - return; - } - - WAIT_FOR_FLAG(track_segments_object_id_read); - printk("Track Segments Object ID read succeeded\n"); - - select_read_meta(g_track_segments_object_id); - UNSET_FLAG(object_read); - err = bt_mcc_otc_read_track_segments_object(default_conn); - - if (err) { - FAIL("Failed to read track segments object\n"); - return; - } - - WAIT_FOR_FLAG(object_read); - printk("Reading Track Segments Object succeeded\n"); - - /* Current track object ***************************************/ - UNSET_FLAG(current_track_object_id_set); - - tmp_object_id = 0x103; - - err = bt_mcc_set_current_track_obj_id(default_conn, tmp_object_id); - if (err) { - FAIL("Failed to set current track object ID: %d", err); - return; - } - - WAIT_FOR_FLAG(current_track_object_id_set); - if (g_current_track_object_id != tmp_object_id) { - FAIL("Current track object ID not the one that was set"); - return; - } - - printk("Current Track Object ID set succeeded\n"); - - UNSET_FLAG(current_track_object_id_read); - err = bt_mcc_read_current_track_obj_id(default_conn); - if (err) { - FAIL("Failed to read current track object ID: %d", err); - return; - } - - WAIT_FOR_FLAG(current_track_object_id_read); - if (g_current_track_object_id != tmp_object_id) { - FAIL("Current track object ID not the one that was set"); - return; - } - - printk("Current Track Object ID read succeeded\n"); - - UNSET_FLAG(object_read); - select_read_meta(g_current_track_object_id); - err = bt_mcc_otc_read_current_track_object(default_conn); - - if (err) { - FAIL("Failed to current track object\n"); - return; - } - - WAIT_FOR_FLAG(object_read); - printk("Current Track Object read succeeded\n"); - - /* Next track object ***************************************************/ - UNSET_FLAG(next_track_object_id_set); - - tmp_object_id = 0x102; - - err = bt_mcc_set_next_track_obj_id(default_conn, tmp_object_id); - if (err) { - FAIL("Failed to set next track object ID: %d", err); - return; - } - - WAIT_FOR_FLAG(next_track_object_id_set); - if (g_next_track_object_id != tmp_object_id) { - FAIL("Next track object ID not the one that was set"); - return; - } - - printk("Next Track Object ID set succeeded\n"); - - UNSET_FLAG(next_track_object_id_read); - err = bt_mcc_read_next_track_obj_id(default_conn); - if (err) { - FAIL("Failed to read next track object ID: %d", err); - return; - } - - WAIT_FOR_FLAG(next_track_object_id_read); - if (g_next_track_object_id != tmp_object_id) { - FAIL("Next track object ID not the one that was set"); - return; - } - - printk("Next Track Object ID read succeeded\n"); - - select_read_meta(g_next_track_object_id); - UNSET_FLAG(object_read); - err = bt_mcc_otc_read_next_track_object(default_conn); - - if (err) { - FAIL("Failed to read next track object\n"); - return; - } - - WAIT_FOR_FLAG(object_read); - printk("Next Track Object read succeeded\n"); - - - /* Read parent group object ******************************************/ - UNSET_FLAG(parent_group_object_id_read); - err = bt_mcc_read_parent_group_obj_id(default_conn); - if (err) { - FAIL("Failed to read parent group object ID: %d", err); - return; - } - - WAIT_FOR_FLAG(parent_group_object_id_read); - printk("Parent Group Object ID read succeeded\n"); - - select_read_meta(g_parent_group_object_id); - UNSET_FLAG(object_read); - err = bt_mcc_otc_read_parent_group_object(default_conn); - - if (err) { - FAIL("Failed to read parent group object\n"); - return; - } - - WAIT_FOR_FLAG(object_read); - printk("Parent Group Object read succeeded\n"); - - /* Current group object ******************************************/ - UNSET_FLAG(current_group_object_id_set); - - tmp_object_id = 0x10e; /* ID of third group */ - - err = bt_mcc_set_current_group_obj_id(default_conn, tmp_object_id); - if (err) { - FAIL("Failed to set current group object ID: %d", err); - return; - } - - WAIT_FOR_FLAG(current_group_object_id_set); - if (g_current_group_object_id != tmp_object_id) { - FAIL("Current group object ID not the one that was set"); - return; - } - - printk("Current Group Object ID set succeeded\n"); - - UNSET_FLAG(current_group_object_id_read); - err = bt_mcc_read_current_group_obj_id(default_conn); - if (err) { - FAIL("Failed to read current group object ID: %d", err); - return; - } - - WAIT_FOR_FLAG(current_group_object_id_read); - if (g_current_group_object_id != tmp_object_id) { - FAIL("Current group object ID not the one that was set"); - return; - } - - printk("Current Group Object ID read succeeded\n"); - - select_read_meta(g_current_group_object_id); - UNSET_FLAG(object_read); - err = bt_mcc_otc_read_current_group_object(default_conn); - - if (err) { - FAIL("Failed to read current group object\n"); - return; - } - - WAIT_FOR_FLAG(object_read); - printk("Current Group Object read succeeded\n"); - - /* Set current group back to first group, so that later tests (segments) will work. - * (Only the tracks of the first group has segments in the MPL.) - */ - UNSET_FLAG(current_group_object_id_set); - - tmp_object_id = 0x106; /* ID of first group */ - - err = bt_mcc_set_current_group_obj_id(default_conn, tmp_object_id); - if (err) { - FAIL("Failed to set current group object ID: %d", err); - return; - } - - WAIT_FOR_FLAG(current_group_object_id_set); - if (g_current_group_object_id != tmp_object_id) { - FAIL("Current group object ID not the one that was set"); - return; - } - - /* Read and set playing order *************************************/ - UNSET_FLAG(playing_order_read); - err = bt_mcc_read_playing_order(default_conn); - if (err) { - FAIL("Failed to read playing order: %d", err); - return; - } - - WAIT_FOR_FLAG(playing_order_read); - printk("Playing order read succeeded\n"); - - uint8_t playing_order; - - if (g_playing_order != BT_MCS_PLAYING_ORDER_SHUFFLE_ONCE) { - playing_order = BT_MCS_PLAYING_ORDER_SHUFFLE_ONCE; - } else { - playing_order = BT_MCS_PLAYING_ORDER_SINGLE_ONCE; - } - - UNSET_FLAG(playing_order_set); - err = bt_mcc_set_playing_order(default_conn, playing_order); - if (err) { - FAIL("Failed to set playing_order: %d", err); - return; - } - - WAIT_FOR_FLAG(playing_order_set); - if (g_playing_order != playing_order) { - FAIL("Playing order set failed: Incorrect playing_order\n"); - } - printk("Playing order set succeeded\n"); - - /* Read playing orders supported *************************************/ - UNSET_FLAG(playing_orders_supported_read); - err = bt_mcc_read_playing_orders_supported(default_conn); - if (err) { - FAIL("Failed to read playing orders supported: %d", err); - return; - } - - WAIT_FOR_FLAG(playing_orders_supported_read); - printk("Playing orders supported read succeeded\n"); - - /* Read media state ***************************************************/ - UNSET_FLAG(media_state_read); - err = bt_mcc_read_media_state(default_conn); - if (err) { - FAIL("Failed to read media state: %d", err); - return; - } - - WAIT_FOR_FLAG(media_state_read); - printk("Media state read succeeded\n"); - - /* Read content control ID *******************************************/ - UNSET_FLAG(ccid_read); - err = bt_mcc_read_content_control_id(default_conn); - if (err) { - FAIL("Failed to read content control ID: %d", err); - return; - } - - WAIT_FOR_FLAG(ccid_read); - printk("Content control ID read succeeded\n"); - - /* Control point - "state" opcodes */ - - /* This part of the test not only checks that the opcodes are accepted - * by the server, but also that they actually do lead to the expected - * state changes. This may lean too much upon knowledge or assumptions, - * and therefore be too fragile. - * It may be more robust to just give commands and check for the success - * code in the control point notifications - */ - - /* It is assumed that the server starts the test in the paused state */ - test_verify_media_state_wait_flags(BT_MCS_MEDIA_STATE_PAUSED); - - /* The tests are ordered to ensure that each command changes state */ - test_cp_play(); - test_cp_fast_forward(); - test_cp_pause(); - test_cp_fast_rewind(); - test_cp_stop(); - - - /* Control point - move relative opcode */ - test_cp_move_relative(); - - /* Control point - segment change opcodes */ - test_cp_prev_segment(); - test_cp_next_segment(); - test_cp_first_segment(); - test_cp_last_segment(); - test_cp_goto_segment(); - - - /* Control point - track change opcodes */ - /* The tests are ordered to ensure that each command changes track */ - /* Assumes we are not starting on the last track */ - test_cp_next_track_and_track_changed(); - test_cp_prev_track(); - test_cp_last_track(); - test_cp_first_track(); - test_cp_goto_track(); - - - /* Control point - group change opcodes *******************************/ - /* The tests are ordered to ensure that each command changes group */ - /* Assumes we are not starting on the last group */ - test_cp_next_group(); - test_cp_prev_group(); - test_cp_last_group(); - test_cp_first_group(); - test_cp_goto_group(); - - - /* Search control point */ - test_search(); - - - /* TEST IS COMPLETE */ - PASS("MCC passed\n"); -} - -static const struct bst_test_instance test_mcs[] = { - { - .test_id = "mcc", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_mcc_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_mcs); -} - -#else - -struct bst_test_list *test_mcc_install(struct bst_test_list *tests) -{ - return tests; -} - -#endif /* CONFIG_BT_MCC */ diff --git a/tests/bluetooth/bsim/audio/src/mcs_test.c b/tests/bluetooth/bsim/audio/src/mcs_test.c deleted file mode 100644 index 413ce60921d..00000000000 --- a/tests/bluetooth/bsim/audio/src/mcs_test.c +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2019 - 2021 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifdef CONFIG_BT_MCS - -#include - -#include "common.h" - -extern enum bst_result_t bst_result; - -CREATE_FLAG(ble_link_is_ready); - -/* Callback after Bluetoot initialization attempt */ -static void bt_ready(int err) -{ - if (err) { - FAIL("Bluetooth init failed (err %d)\n", err); - return; - } - - printk("Bluetooth initialized\n"); - - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, AD_SIZE, NULL, 0); - if (err) { - FAIL("Advertising failed to start (err %d)\n", err); - return; - } - - printk("Advertising successfully started\n"); -} - -/* Callback when connected */ -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - } else { - default_conn = bt_conn_ref(conn); - printk("Connected: %s\n", addr); - SET_FLAG(ble_link_is_ready); - } -} - -static void test_main(void) -{ - int err; - static struct bt_conn_cb conn_callbacks = { - .connected = connected, - .disconnected = disconnected, - }; - - printk("Media Control Server test application. Board: %s\n", CONFIG_BOARD); - - bt_conn_cb_register(&conn_callbacks); - - /* Initialize media player */ - err = media_proxy_pl_init(); - if (err) { - FAIL("Initializing MPL failed (err %d)", err); - return; - } - - /* Initialize Bluetooth, get connected */ - err = bt_enable(bt_ready); - if (err) { - FAIL("Bluetooth init failed (err %d)\n", err); - return; - } - - WAIT_FOR_FLAG(ble_link_is_ready); - - PASS("MCS passed\n"); -} - -static const struct bst_test_instance test_mcs[] = { - { - .test_id = "mcs", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_mcs_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_mcs); -} - -#else - -struct bst_test_list *test_mcs_install(struct bst_test_list *tests) -{ - return tests; -} - -#endif /* CONFIG_BT_MCS */ diff --git a/tests/bluetooth/bsim/audio/src/media_controller_test.c b/tests/bluetooth/bsim/audio/src/media_controller_test.c deleted file mode 100644 index 98f918ea978..00000000000 --- a/tests/bluetooth/bsim/audio/src/media_controller_test.c +++ /dev/null @@ -1,1750 +0,0 @@ -/* - * Copyright (c) 2021 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifdef CONFIG_BT_MCS - -#include -#include -#include - -#include "common.h" - -extern enum bst_result_t bst_result; - -static uint64_t g_icon_object_id; -static uint64_t g_track_segments_object_id; -static uint64_t g_current_track_object_id; -static uint64_t g_next_track_object_id; -static uint64_t g_parent_group_object_id; -static uint64_t g_current_group_object_id; -static uint64_t g_search_results_object_id; - -static int32_t g_pos; -static int8_t g_pb_speed; -static uint8_t g_playing_order; -static uint8_t g_state; -static uint8_t g_command_result; -static uint32_t g_commands_supported; -static uint8_t g_search_control_point_result_code; - -CREATE_FLAG(ble_is_initialized); -CREATE_FLAG(ble_link_is_ready); -CREATE_FLAG(local_player_instance); -CREATE_FLAG(remote_player_instance); -CREATE_FLAG(player_name_read); -CREATE_FLAG(icon_object_id_read); -CREATE_FLAG(icon_url_read); -CREATE_FLAG(track_title_read); -CREATE_FLAG(track_duration_read); -CREATE_FLAG(track_position); -CREATE_FLAG(playback_speed); -CREATE_FLAG(seeking_speed_read); -CREATE_FLAG(track_segments_object_id_read); -CREATE_FLAG(current_track_object_id_read); -CREATE_FLAG(next_track_object_id_read); -CREATE_FLAG(parent_group_object_id_read); -CREATE_FLAG(current_group_object_id_read); -CREATE_FLAG(search_results_object_id_read); -CREATE_FLAG(playing_order_flag); -CREATE_FLAG(playing_orders_supported_read); -CREATE_FLAG(ccid_read); -CREATE_FLAG(media_state_read); -CREATE_FLAG(command_sent_flag); -CREATE_FLAG(command_results_flag); -CREATE_FLAG(commands_supported); -CREATE_FLAG(search_sent_flag); -CREATE_FLAG(search_result_code_flag); - - -static struct media_proxy_ctrl_cbs cbs; -static struct media_player *local_player; -static struct media_player *remote_player; -static struct media_player *current_player; - -static void local_player_instance_cb(struct media_player *player, int err) -{ - if (err) { - FAIL("Local player instance failed (%d)", err); - return; - } - - local_player = player; - SET_FLAG(local_player_instance); -} - -static void discover_player_cb(struct media_player *player, int err) -{ - if (err) { - FAIL("Discover player failed (%d)\n", err); - return; - } - - remote_player = player; - SET_FLAG(remote_player_instance); -} - -static void player_name_cb(struct media_player *plr, int err, const char *name) -{ - if (err) { - FAIL("Player Name read failed (%d)\n", err); - return; - } - - if (plr != current_player) { - FAIL("Wrong player\n"); - return; - } - - SET_FLAG(player_name_read); -} - -static void icon_id_cb(struct media_player *plr, int err, uint64_t id) -{ - if (err) { - FAIL("Icon Object ID read failed (%d)", err); - return; - } - - if (plr != current_player) { - FAIL("Wrong player\n"); - return; - } - - g_icon_object_id = id; - SET_FLAG(icon_object_id_read); -} - -static void icon_url_cb(struct media_player *plr, int err, const char *url) -{ - if (err) { - FAIL("Icon URL read failed (%d)", err); - return; - } - - if (plr != current_player) { - FAIL("Wrong player\n"); - } - - SET_FLAG(icon_url_read); -} - -static void track_title_cb(struct media_player *plr, int err, const char *title) -{ - if (err) { - FAIL("Track title read failed (%d)", err); - return; - } - - if (plr != current_player) { - FAIL("Wrong player\n"); - return; - } - - SET_FLAG(track_title_read); -} - -static void track_duration_cb(struct media_player *plr, int err, int32_t duration) -{ - if (err) { - FAIL("Track duration read failed (%d)", err); - return; - } - - if (plr != current_player) { - FAIL("Wrong player\n"); - return; - } - - SET_FLAG(track_duration_read); -} - -static void track_position_recv_cb(struct media_player *plr, int err, int32_t position) -{ - if (err) { - FAIL("Track position read failed (%d)", err); - return; - } - - if (plr != current_player) { - FAIL("Wrong player\n"); - return; - } - - g_pos = position; - SET_FLAG(track_position); -} - -static void track_position_write_cb(struct media_player *plr, int err, int32_t position) -{ - if (err) { - FAIL("Track position write failed (%d)", err); - return; - } - - if (plr != current_player) { - FAIL("Wrong player\n"); - return; - } - - g_pos = position; - SET_FLAG(track_position); -} - -static void playback_speed_recv_cb(struct media_player *plr, int err, int8_t speed) -{ - if (err) { - FAIL("Playback speed read failed (%d)", err); - return; - } - - if (plr != current_player) { - FAIL("Wrong player\n"); - return; - } - - g_pb_speed = speed; - SET_FLAG(playback_speed); -} - -static void playback_speed_write_cb(struct media_player *plr, int err, int8_t speed) -{ - if (err) { - FAIL("Playback speed write failed (%d)", err); - return; - } - - if (plr != current_player) { - FAIL("Wrong player\n"); - return; - } - - g_pb_speed = speed; - SET_FLAG(playback_speed); -} - -static void seeking_speed_cb(struct media_player *plr, int err, int8_t speed) -{ - if (err) { - FAIL("Seeking speed read failed (%d)", err); - return; - } - - if (plr != current_player) { - FAIL("Wrong player\n"); - return; - } - - SET_FLAG(seeking_speed_read); -} - -static void track_segments_id_cb(struct media_player *plr, int err, uint64_t id) -{ - if (err) { - FAIL("Track Segments ID read failed (%d)\n", err); - return; - } - - if (plr != current_player) { - FAIL("Wrong player\n"); - return; - } - - g_track_segments_object_id = id; - SET_FLAG(track_segments_object_id_read); -} - -static void current_track_id_cb(struct media_player *plr, int err, uint64_t id) -{ - if (err) { - FAIL("Current Track Object ID read failed (%d)\n", err); - return; - } - - if (plr != current_player) { - FAIL("Wrong player\n"); - return; - } - - g_current_track_object_id = id; - SET_FLAG(current_track_object_id_read); -} - -static void next_track_id_cb(struct media_player *plr, int err, uint64_t id) -{ - if (err) { - FAIL("Next Track Object ID read failed (%d)\n", err); - return; - } - - if (plr != current_player) { - FAIL("Wrong player\n"); - return; - } - - g_next_track_object_id = id; - SET_FLAG(next_track_object_id_read); -} - -static void parent_group_id_cb(struct media_player *plr, int err, uint64_t id) -{ - if (err) { - FAIL("Parent Group Object ID read failed (%d)\n", err); - return; - } - - if (plr != current_player) { - FAIL("Wrong player\n"); - return; - } - - g_parent_group_object_id = id; - SET_FLAG(parent_group_object_id_read); -} - -static void current_group_id_cb(struct media_player *plr, int err, uint64_t id) -{ - if (err) { - FAIL("Current Group Object ID read failed (%d)\n", err); - return; - } - - if (plr != current_player) { - FAIL("Wrong player\n"); - return; - } - - g_current_group_object_id = id; - SET_FLAG(current_group_object_id_read); -} - -static void playing_order_recv_cb(struct media_player *plr, int err, uint8_t order) -{ - if (err) { - FAIL("Playing order read failed (%d)", err); - return; - } - - if (plr != current_player) { - FAIL("Wrong player\n"); - return; - } - - g_playing_order = order; - SET_FLAG(playing_order_flag); -} - -static void playing_order_write_cb(struct media_player *plr, int err, uint8_t order) -{ - if (err) { - FAIL("Playing order write failed (%d)", err); - return; - } - - if (plr != current_player) { - FAIL("Wrong player\n"); - return; - } - - g_playing_order = order; - SET_FLAG(playing_order_flag); -} - -static void playing_orders_supported_cb(struct media_player *plr, int err, uint16_t orders) -{ - if (err) { - FAIL("Playing orders supported read failed (%d)", err); - return; - } - - if (plr != current_player) { - FAIL("Wrong player\n"); - return; - } - - SET_FLAG(playing_orders_supported_read); -} - -static void media_state_cb(struct media_player *plr, int err, uint8_t state) -{ - if (err) { - FAIL("Media State read failed (%d)", err); - return; - } - - if (plr != current_player) { - FAIL("Wrong player\n"); - return; - } - - g_state = state; - SET_FLAG(media_state_read); -} - -static void command_send_cb(struct media_player *plr, int err, const struct mpl_cmd *cmd) -{ - if (err) { - FAIL("Command send failed (%d)", err); - return; - } - - if (plr != current_player) { - FAIL("Wrong player\n"); - return; - } - - SET_FLAG(command_sent_flag); -} - -static void command_recv_cb(struct media_player *plr, int err, const struct mpl_cmd_ntf *cmd_ntf) -{ - if (err) { - FAIL("Command failed (%d)", err); - return; - } - - if (plr != current_player) { - FAIL("Wrong player\n"); - return; - } - - g_command_result = cmd_ntf->result_code; - SET_FLAG(command_results_flag); -} - -static void commands_supported_cb(struct media_player *plr, int err, uint32_t opcodes) -{ - if (err) { - FAIL("Commands supported failed (%d)", err); - return; - } - - if (plr != current_player) { - FAIL("Wrong player\n"); - return; - } - - g_commands_supported = opcodes; - SET_FLAG(commands_supported); -} - - - -static void search_send_cb(struct media_player *plr, int err, const struct mpl_search *search) -{ - if (err) { - FAIL("Search failed (%d)", err); - return; - } - - if (plr != current_player) { - FAIL("Wrong player\n"); - return; - } - - SET_FLAG(search_sent_flag); -} - -static void search_recv_cb(struct media_player *plr, int err, uint8_t result_code) -{ - if (err) { - FAIL("Search failed (%d), result code: %u", err, result_code); - return; - } - - if (plr != current_player) { - FAIL("Wrong player\n"); - return; - } - - g_search_control_point_result_code = result_code; - SET_FLAG(search_result_code_flag); -} - -static void search_results_id_cb(struct media_player *plr, int err, uint64_t id) -{ - if (err) { - FAIL("Search Results Object ID read failed (%d)", err); - return; - } - - if (plr != current_player) { - FAIL("Wrong player\n"); - return; - } - - g_search_results_object_id = id; - SET_FLAG(search_results_object_id_read); -} - -static void content_ctrl_id_cb(struct media_player *plr, int err, uint8_t ccid) -{ - if (err) { - FAIL("Content control ID read failed (%d)", err); - return; - } - - if (plr != current_player) { - FAIL("Wrong player\n"); - return; - } - - SET_FLAG(ccid_read); -} - -void initialize_media(void) -{ - int err = media_proxy_pl_init(); /* TODO: Fix direct call to player */ - - if (err) { - FAIL("Could not init mpl: %d", err); - return; - } - - /* Set up the callback structure */ - cbs.local_player_instance = local_player_instance_cb; - cbs.discover_player = discover_player_cb; - cbs.player_name_recv = player_name_cb; - cbs.icon_id_recv = icon_id_cb; - cbs.icon_url_recv = icon_url_cb; - cbs.track_title_recv = track_title_cb; - cbs.track_duration_recv = track_duration_cb; - cbs.track_position_recv = track_position_recv_cb; - cbs.track_position_write = track_position_write_cb; - cbs.playback_speed_recv = playback_speed_recv_cb; - cbs.playback_speed_write = playback_speed_write_cb; - cbs.seeking_speed_recv = seeking_speed_cb; -#ifdef CONFIG_BT_OTS - cbs.track_segments_id_recv = track_segments_id_cb; - cbs.current_track_id_recv = current_track_id_cb; - cbs.next_track_id_recv = next_track_id_cb; - cbs.parent_group_id_recv = parent_group_id_cb; - cbs.current_group_id_recv = current_group_id_cb; -#endif /* CONFIG_BT_OTS */ - cbs.playing_order_recv = playing_order_recv_cb; - cbs.playing_order_write = playing_order_write_cb; - cbs.playing_orders_supported_recv = playing_orders_supported_cb; - cbs.media_state_recv = media_state_cb; - cbs.command_send = command_send_cb; - cbs.command_recv = command_recv_cb; - cbs.commands_supported_recv = commands_supported_cb; -#ifdef CONFIG_BT_OTS - cbs.search_send = search_send_cb; - cbs.search_recv = search_recv_cb; - cbs.search_results_id_recv = search_results_id_cb; -#endif /* CONFIG_BT_OTS */ - cbs.content_ctrl_id_recv = content_ctrl_id_cb; - - UNSET_FLAG(local_player_instance); - - err = media_proxy_ctrl_register(&cbs); - if (err) { - FAIL("Could not init mpl: %d", err); - return; - } - - WAIT_FOR_FLAG(local_player_instance); - printk("media init and local player instance succeeded\n"); -} - -/* Callback after Bluetoot initialization attempt */ -static void bt_ready(int err) -{ - if (err) { - FAIL("Bluetooth init failed (err %d)\n", err); - return; - } - - SET_FLAG(ble_is_initialized); -} - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected: %s\n", addr); - SET_FLAG(ble_link_is_ready); -} - -/* Helper function to read the media state and verify that it is as expected - * Will FAIL on error reading the media state - * Will FAIL if the state is not as expected - * - * Returns true if the state is as expected - * Returns false in case of errors, or if the state is not as expected - */ -static bool test_verify_media_state_wait_flags(uint8_t expected_state) -{ - int err; - - UNSET_FLAG(media_state_read); - err = media_proxy_ctrl_get_media_state(current_player); - if (err) { - FAIL("Failed to read media state: %d", err); - return false; - } - - WAIT_FOR_FLAG(media_state_read); - if (g_state != expected_state) { - FAIL("Server is not in expected state: %d, expected: %d\n", - g_state, expected_state); - return false; - } - - return true; -} - -/* Helper function to write commands to to the control point, including the - * flag handling. - * Will FAIL on error to send the command. - * Will WAIT for the required flags before returning. - */ -static void test_send_cmd_wait_flags(struct mpl_cmd *cmd) -{ - int err; - - UNSET_FLAG(command_sent_flag); - UNSET_FLAG(command_results_flag); - err = media_proxy_ctrl_send_command(current_player, cmd); - if (err) { - FAIL("Failed to send command: %d, opcode: %u", - err, cmd->opcode); - return; - } - - WAIT_FOR_FLAG(command_sent_flag); - WAIT_FOR_FLAG(command_results_flag); -} - -static void test_cp_play(void) -{ - struct mpl_cmd cmd; - - cmd.opcode = MEDIA_PROXY_OP_PLAY; - cmd.use_param = false; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) { - FAIL("PLAY command failed\n"); - return; - } - - if (test_verify_media_state_wait_flags(MEDIA_PROXY_STATE_PLAYING)) { - printk("PLAY command succeeded\n"); - } -} - -static void test_cp_pause(void) -{ - struct mpl_cmd cmd; - - cmd.opcode = MEDIA_PROXY_OP_PAUSE; - cmd.use_param = false; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) { - FAIL("PAUSE command failed\n"); - return; - } - - if (test_verify_media_state_wait_flags(MEDIA_PROXY_STATE_PAUSED)) { - printk("PAUSE command succeeded\n"); - } -} - -static void test_cp_fast_rewind(void) -{ - struct mpl_cmd cmd; - - cmd.opcode = MEDIA_PROXY_OP_FAST_REWIND; - cmd.use_param = false; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) { - FAIL("FAST REWIND command failed\n"); - return; - } - - if (test_verify_media_state_wait_flags(MEDIA_PROXY_STATE_SEEKING)) { - printk("FAST REWIND command succeeded\n"); - } -} - -static void test_cp_fast_forward(void) -{ - struct mpl_cmd cmd; - - cmd.opcode = MEDIA_PROXY_OP_FAST_FORWARD; - cmd.use_param = false; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) { - FAIL("FAST FORWARD command failed\n"); - return; - } - - if (test_verify_media_state_wait_flags(MEDIA_PROXY_STATE_SEEKING)) { - printk("FAST FORWARD command succeeded\n"); - } -} - -static void test_cp_stop(void) -{ - struct mpl_cmd cmd; - - cmd.opcode = MEDIA_PROXY_OP_STOP; - cmd.use_param = false; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) { - FAIL("STOP command failed\n"); - return; - } - - /* There is no "STOPPED" state in the spec - STOP goes to PAUSED */ - if (test_verify_media_state_wait_flags(MEDIA_PROXY_STATE_PAUSED)) { - printk("STOP command succeeded\n"); - } -} - -static void test_cp_move_relative(void) -{ - int err; - struct mpl_cmd cmd; - - /* Assumes that the server is in a state where it is able to change - * the current track position - * Also assumes position will not change by itself, which is wrong if - * if the player is playing. - */ - UNSET_FLAG(track_position); - err = media_proxy_ctrl_get_track_position(current_player); - if (err) { - FAIL("Failed to read track position: %d\n", err); - return; - } - - WAIT_FOR_FLAG(track_position); - uint32_t tmp_pos = g_pos; - - cmd.opcode = MEDIA_PROXY_OP_MOVE_RELATIVE; - cmd.use_param = true; - cmd.param = 1000; /* Position change, measured in 1/100 of a second */ - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) { - FAIL("MOVE RELATIVE command failed\n"); - return; - } - - UNSET_FLAG(track_position); - err = media_proxy_ctrl_get_track_position(current_player); - if (err) { - FAIL("Failed to read track position: %d\n", err); - return; - } - - WAIT_FOR_FLAG(track_position); - if (g_pos == tmp_pos) { - /* Position did not change */ - FAIL("Server did not move track position\n"); - return; - } - - printk("MOVE RELATIVE command succeeded\n"); -} - -static void test_cp_prev_segment(void) -{ - struct mpl_cmd cmd; - - /* Assumes that the server is in a state where there is a current - * track that has segments, and where the server may switch between - * these - */ - - /* To properly verify track segment changes, the track segments - * object must be downloaded and parsed. That is somewhat complex, - * and is getting close to what the qualification tests do. - * Alternatively, the track position may be checked, but the server - * implementation does not set that for segment changes yet. - * For now, we will settle for seeing that the opcodes are accepted. - */ - - cmd.opcode = MEDIA_PROXY_OP_PREV_SEGMENT; - cmd.use_param = false; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) { - FAIL("PREV SEGMENT command failed\n"); - return; - } - - printk("PREV SEGMENT command succeeded\n"); -} - -static void test_cp_next_segment(void) -{ - struct mpl_cmd cmd; - - cmd.opcode = MEDIA_PROXY_OP_NEXT_SEGMENT; - cmd.use_param = false; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) { - FAIL("NEXT SEGMENT command failed\n"); - return; - } - - printk("NEXT SEGMENT command succeeded\n"); -} - -static void test_cp_first_segment(void) -{ - struct mpl_cmd cmd; - - cmd.opcode = MEDIA_PROXY_OP_FIRST_SEGMENT; - cmd.use_param = false; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) { - FAIL("FIRST SEGMENT command failed\n"); - return; - } - - printk("FIRST SEGMENT command succeeded\n"); -} - -static void test_cp_last_segment(void) -{ - struct mpl_cmd cmd; - - cmd.opcode = MEDIA_PROXY_OP_LAST_SEGMENT; - cmd.use_param = false; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) { - FAIL("LAST SEGMENT command failed\n"); - return; - } - - printk("LAST SEGMENT command succeeded\n"); -} - -static void test_cp_goto_segment(void) -{ - struct mpl_cmd cmd; - - cmd.opcode = MEDIA_PROXY_OP_GOTO_SEGMENT; - cmd.use_param = true; - cmd.param = 2; /* Second segment - not the first, maybe not last */ - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) { - FAIL("GOTO SEGMENT command failed\n"); - return; - } - - printk("GOTO SEGMENT command succeeded\n"); -} - -/* Helper function to read the current track object ID, including flag handling - * Will FAIL on error reading object ID - * Will WAIT until the read is completed (object ID flag read flag is set) - */ -static void test_read_current_track_object_id_wait_flags(void) -{ - int err; - - UNSET_FLAG(current_track_object_id_read); - err = media_proxy_ctrl_get_current_track_id(current_player); - if (err) { - FAIL("Failed to read current track object ID: %d", err); - return; - } - - WAIT_FOR_FLAG(current_track_object_id_read); -} - -static void test_cp_prev_track(void) -{ - uint64_t object_id; - struct mpl_cmd cmd; - - /* Assumes that the server is in a state where it has multiple tracks - * and can change between them. - */ - - /* To verify that a track change has happeded, the test checks that the - * current track object ID has changed. - */ - - cmd.opcode = MEDIA_PROXY_OP_PREV_TRACK; - cmd.use_param = false; - - test_read_current_track_object_id_wait_flags(); - object_id = g_current_track_object_id; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) { - FAIL("PREV TRACK command failed\n"); - return; - } - - test_read_current_track_object_id_wait_flags(); - - if (g_current_track_object_id == object_id) { - /* Track did not change */ - FAIL("Server did not change track\n"); - return; - } - - printk("PREV TRACK command succeeded\n"); -} - -static void test_cp_next_track(void) -{ - uint64_t object_id; - struct mpl_cmd cmd; - - cmd.opcode = MEDIA_PROXY_OP_NEXT_TRACK; - cmd.use_param = false; - - test_read_current_track_object_id_wait_flags(); - object_id = g_current_track_object_id; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) { - FAIL("NEXT TRACK command failed\n"); - return; - } - - test_read_current_track_object_id_wait_flags(); - - if (g_current_track_object_id == object_id) { - FAIL("Server did not change track\n"); - return; - } - - printk("NEXT TRACK command succeeded\n"); -} - -static void test_cp_first_track(void) -{ - uint64_t object_id; - struct mpl_cmd cmd; - - cmd.opcode = MEDIA_PROXY_OP_FIRST_TRACK; - cmd.use_param = false; - - test_read_current_track_object_id_wait_flags(); - object_id = g_current_track_object_id; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) { - FAIL("FIRST TRACK command failed\n"); - return; - } - - test_read_current_track_object_id_wait_flags(); - - if (g_current_track_object_id == object_id) { - FAIL("Server did not change track\n"); - return; - } - - printk("FIRST TRACK command succeeded\n"); -} - -static void test_cp_last_track(void) -{ - uint64_t object_id; - struct mpl_cmd cmd; - - cmd.opcode = MEDIA_PROXY_OP_LAST_TRACK; - cmd.use_param = false; - - test_read_current_track_object_id_wait_flags(); - object_id = g_current_track_object_id; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) { - FAIL("LAST TRACK command failed\n"); - return; - } - - test_read_current_track_object_id_wait_flags(); - - if (g_current_track_object_id == object_id) { - FAIL("Server did not change track\n"); - return; - } - - printk("LAST TRACK command succeeded\n"); -} - -static void test_cp_goto_track(void) -{ - uint64_t object_id; - struct mpl_cmd cmd; - - cmd.opcode = MEDIA_PROXY_OP_GOTO_TRACK; - cmd.use_param = true; - cmd.param = 2; /* Second track, not the first, maybe not the last */ - - test_read_current_track_object_id_wait_flags(); - object_id = g_current_track_object_id; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) { - FAIL("GOTO TRACK command failed\n"); - return; - } - - test_read_current_track_object_id_wait_flags(); - - if (g_current_track_object_id == object_id) { - FAIL("Server did not change track\n"); - return; - } - - printk("GOTO TRACK command succeeded\n"); -} - -/* Helper function to read the current group object ID, including flag handling - * Will FAIL on error reading object ID - * Will WAIT until the read is completed (object ID flag read flag is set) - */ -static void test_read_current_group_object_id_wait_flags(void) -{ - int err; - - UNSET_FLAG(current_group_object_id_read); - err = media_proxy_ctrl_get_current_group_id(current_player); - if (err) { - FAIL("Failed to read current group object ID: %d", err); - return; - } - - WAIT_FOR_FLAG(current_group_object_id_read); -} - -static void test_cp_prev_group(void) -{ - uint64_t object_id; - struct mpl_cmd cmd; - - /* Assumes that the server is in a state where it has multiple groups - * and can change between them. - */ - - /* To verify that a group change has happeded, the test checks that the - * current group object ID has changed. - */ - - cmd.opcode = MEDIA_PROXY_OP_PREV_GROUP; - cmd.use_param = false; - - test_read_current_group_object_id_wait_flags(); - object_id = g_current_group_object_id; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) { - FAIL("PREV GROUP command failed\n"); - return; - } - - test_read_current_group_object_id_wait_flags(); - - if (g_current_group_object_id == object_id) { - /* Group did not change */ - FAIL("Server did not change group\n"); - return; - } - - printk("PREV GROUP command succeeded\n"); -} - -static void test_cp_next_group(void) -{ - uint64_t object_id; - struct mpl_cmd cmd; - - cmd.opcode = MEDIA_PROXY_OP_NEXT_GROUP; - cmd.use_param = false; - - test_read_current_group_object_id_wait_flags(); - object_id = g_current_group_object_id; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) { - FAIL("NEXT GROUP command failed\n"); - return; - } - - test_read_current_group_object_id_wait_flags(); - - if (g_current_group_object_id == object_id) { - FAIL("Server did not change group\n"); - return; - } - - printk("NEXT GROUP command succeeded\n"); -} - -static void test_cp_first_group(void) -{ - uint64_t object_id; - struct mpl_cmd cmd; - - cmd.opcode = MEDIA_PROXY_OP_FIRST_GROUP; - cmd.use_param = false; - - test_read_current_group_object_id_wait_flags(); - object_id = g_current_group_object_id; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) { - FAIL("FIRST GROUP command failed\n"); - return; - } - - test_read_current_group_object_id_wait_flags(); - - if (g_current_group_object_id == object_id) { - FAIL("Server did not change group\n"); - return; - } - - printk("FIRST GROUP command succeeded\n"); -} - -static void test_cp_last_group(void) -{ - uint64_t object_id; - struct mpl_cmd cmd; - - cmd.opcode = MEDIA_PROXY_OP_LAST_GROUP; - cmd.use_param = false; - - test_read_current_group_object_id_wait_flags(); - object_id = g_current_group_object_id; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) { - FAIL("LAST GROUP command failed\n"); - return; - } - - test_read_current_group_object_id_wait_flags(); - - if (g_current_group_object_id == object_id) { - FAIL("Server did not change group\n"); - return; - } - - printk("LAST GROUP command succeeded\n"); -} - -static void test_cp_goto_group(void) -{ - uint64_t object_id; - struct mpl_cmd cmd; - - cmd.opcode = MEDIA_PROXY_OP_GOTO_GROUP; - cmd.use_param = true; - cmd.param = 2; /* Second group, not the first, maybe not the last */ - - test_read_current_group_object_id_wait_flags(); - object_id = g_current_group_object_id; - - test_send_cmd_wait_flags(&cmd); - - if (g_command_result != MEDIA_PROXY_CMD_SUCCESS) { - FAIL("GOTO GROUP command failed\n"); - return; - } - - test_read_current_group_object_id_wait_flags(); - - if (g_current_group_object_id == object_id) { - FAIL("Server did not change group\n"); - return; - } - - printk("GOTO GROUP command succeeded\n"); -} - -static void test_scp(void) -{ - struct mpl_search search; - struct mpl_sci sci = {0}; - int err; - - /* Test outline: - * - verify that the search results object ID is zero before search - * - write a search (one search control item) to the search control point, - * get write callback and notification - * - verify that the search results object ID is non-zero - */ - - UNSET_FLAG(search_results_object_id_read); - err = media_proxy_ctrl_get_search_results_id(current_player); - - if (err) { - FAIL("Failed to read search results object ID: %d", err); - return; - } - - WAIT_FOR_FLAG(search_results_object_id_read); - - if (g_search_results_object_id != 0) { - FAIL("Search results object ID not zero before search\n"); - return; - } - - /* Set up the search control item, then the search - * Note: As of now, the server implementation only fakes the search, - * so it makes no difference what we search for. The result is the - * same anyway. - */ - sci.type = MEDIA_PROXY_SEARCH_TYPE_TRACK_NAME; - strcpy(sci.param, "Some track name"); - /* Length is length of type, plus length of param w/o termination */ - sci.len = sizeof(sci.type) + strlen(sci.param); - - search.len = 0; - memcpy(&search.search[search.len], &sci.len, sizeof(sci.len)); - search.len += sizeof(sci.len); - - memcpy(&search.search[search.len], &sci.type, sizeof(sci.type)); - search.len += sizeof(sci.type); - - memcpy(&search.search[search.len], &sci.param, strlen(sci.param)); - search.len += strlen(sci.param); - - UNSET_FLAG(search_sent_flag); - UNSET_FLAG(search_result_code_flag); - UNSET_FLAG(search_results_object_id_read); - - err = media_proxy_ctrl_send_search(current_player, &search); - if (err) { - FAIL("Failed to write to search control point\n"); - return; - } - - WAIT_FOR_FLAG(search_sent_flag); - WAIT_FOR_FLAG(search_result_code_flag); - - if (g_search_control_point_result_code != MEDIA_PROXY_SEARCH_SUCCESS) { - FAIL("SEARCH operation failed\n"); - return; - } - - /* A search results object will have been created and the search - * results object ID will have been notified if the search gave results - */ - WAIT_FOR_FLAG(search_results_object_id_read); - if (g_search_results_object_id == 0) { - FAIL("No search results\n"); - return; - } - - printk("SEARCH operation succeeded\n"); -} - -/* This function tests all commands in the API in sequence for the provided player. - * (Works by setting the provided player as the "current player".) - * - * The order of the sequence follows the order of the characterstics in the - * Media Control Service specification - */ -void test_media_controller_player(struct media_player *player) -{ - current_player = player; - int err; - - UNSET_FLAG(player_name_read); - err = media_proxy_ctrl_get_player_name(current_player); - if (err) { - FAIL("Failed to read media player name ID: %d", err); - return; - } - - WAIT_FOR_FLAG(player_name_read); - printk("Player Name read succeeded\n"); - - /* Read icon object id ******************************************/ - UNSET_FLAG(icon_object_id_read); - err = media_proxy_ctrl_get_icon_id(current_player); - if (err) { - FAIL("Failed to read icon object ID: %d", err); - return; - } - - WAIT_FOR_FLAG(icon_object_id_read); - printk("Icon Object ID read succeeded\n"); - - /* Read icon url *************************************************/ - UNSET_FLAG(icon_url_read); - err = media_proxy_ctrl_get_icon_url(current_player); - if (err) { - FAIL("Failed to read icon url: %d", err); - return; - } - - WAIT_FOR_FLAG(icon_url_read); - printk("Icon URL read succeeded\n"); - - /* Read track_title ******************************************/ - UNSET_FLAG(track_title_read); - err = media_proxy_ctrl_get_track_title(current_player); - if (err) { - FAIL("Failed to read track_title: %d", err); - return; - } - - WAIT_FOR_FLAG(track_title_read); - printk("Track title read succeeded\n"); - - /* Read track_duration ******************************************/ - UNSET_FLAG(track_duration_read); - err = media_proxy_ctrl_get_track_duration(current_player); - if (err) { - FAIL("Failed to read track_duration: %d", err); - return; - } - - WAIT_FOR_FLAG(track_duration_read); - printk("Track duration read succeeded\n"); - - /* Read and set track_position *************************************/ - UNSET_FLAG(track_position); - err = media_proxy_ctrl_get_track_position(current_player); - if (err) { - FAIL("Failed to read track position: %d", err); - return; - } - - WAIT_FOR_FLAG(track_position); - printk("Track position read succeeded\n"); - - int32_t pos = g_pos + 1200; /*12 seconds further into the track */ - - UNSET_FLAG(track_position); - err = media_proxy_ctrl_set_track_position(current_player, pos); - if (err) { - FAIL("Failed to set track position: %d", err); - return; - } - - WAIT_FOR_FLAG(track_position); - if (g_pos != pos) { - /* In this controlled case, we expect that the resulting */ - /* position is the position given in the set command */ - FAIL("Track position set failed: Incorrect position\n"); - } - printk("Track position set succeeded\n"); - - /* Read and set playback speed *************************************/ - UNSET_FLAG(playback_speed); - err = media_proxy_ctrl_get_playback_speed(current_player); - if (err) { - FAIL("Failed to read playback speed: %d", err); - return; - } - - WAIT_FOR_FLAG(playback_speed); - printk("Playback speed read succeeded\n"); - - int8_t pb_speed = g_pb_speed + 8; /* 2^(8/64) faster than current speed */ - - UNSET_FLAG(playback_speed); - err = media_proxy_ctrl_set_playback_speed(current_player, pb_speed); - if (err) { - FAIL("Failed to set playback speed: %d", err); - return; - } - - WAIT_FOR_FLAG(playback_speed); - if (g_pb_speed != pb_speed) { - FAIL("Playback speed failed: Incorrect playback speed\n"); - } - printk("Playback speed set succeeded\n"); - - /* Read seeking speed *************************************/ - UNSET_FLAG(seeking_speed_read); - err = media_proxy_ctrl_get_seeking_speed(current_player); - if (err) { - FAIL("Failed to read seeking speed: %d", err); - return; - } - - WAIT_FOR_FLAG(seeking_speed_read); - printk("Seeking speed read succeeded\n"); - - /* Read track segments object *****************************************/ - UNSET_FLAG(track_segments_object_id_read); - err = media_proxy_ctrl_get_track_segments_id(current_player); - if (err) { - FAIL("Failed to read track segments object ID: %d", err); - return; - } - - WAIT_FOR_FLAG(track_segments_object_id_read); - printk("Track Segments Object ID read succeeded\n"); - - /* Read current track object ******************************************/ - UNSET_FLAG(current_track_object_id_read); - err = media_proxy_ctrl_get_current_track_id(current_player); - if (err) { - FAIL("Failed to read current track object ID: %d", err); - return; - } - - WAIT_FOR_FLAG(current_track_object_id_read); - printk("Current Track Object ID read succeeded\n"); - - /* Read next track object ******************************************/ - UNSET_FLAG(next_track_object_id_read); - err = media_proxy_ctrl_get_next_track_id(current_player); - if (err) { - FAIL("Failed to read next track object ID: %d", err); - return; - } - - WAIT_FOR_FLAG(next_track_object_id_read); - printk("Next Track Object ID read succeeded\n"); - - /* Read parent group object ******************************************/ - UNSET_FLAG(parent_group_object_id_read); - err = media_proxy_ctrl_get_parent_group_id(current_player); - if (err) { - FAIL("Failed to read parent group object ID: %d", err); - return; - } - - WAIT_FOR_FLAG(parent_group_object_id_read); - printk("Parent Group Object ID read succeeded\n"); - - /* Read current group object ******************************************/ - UNSET_FLAG(current_group_object_id_read); - err = media_proxy_ctrl_get_current_group_id(current_player); - if (err) { - FAIL("Failed to read current group object ID: %d", err); - return; - } - - WAIT_FOR_FLAG(current_group_object_id_read); - printk("Current Group Object ID read succeeded\n"); - - /* Read and set playing order *************************************/ - UNSET_FLAG(playing_order_flag); - err = media_proxy_ctrl_get_playing_order(current_player); - if (err) { - FAIL("Failed to read playing order: %d", err); - return; - } - - WAIT_FOR_FLAG(playing_order_flag); - printk("Playing order read succeeded\n"); - - uint8_t playing_order; - - if (g_playing_order != MEDIA_PROXY_PLAYING_ORDER_INORDER_ONCE) { - playing_order = MEDIA_PROXY_PLAYING_ORDER_INORDER_ONCE; - } else { - playing_order = MEDIA_PROXY_PLAYING_ORDER_INORDER_REPEAT; - } - - UNSET_FLAG(playing_order_flag); - err = media_proxy_ctrl_set_playing_order(current_player, playing_order); - if (err) { - FAIL("Failed to set playing_order: %d", err); - return; - } - - WAIT_FOR_FLAG(playing_order_flag); - if (g_playing_order != playing_order) { - FAIL("Playing order set failed: Incorrect playing_order\n"); - } - printk("Playing order set succeeded\n"); - - /* Read playing orders supported *************************************/ - UNSET_FLAG(playing_orders_supported_read); - err = media_proxy_ctrl_get_playing_orders_supported(current_player); - if (err) { - FAIL("Failed to read playing orders supported: %d", err); - return; - } - - WAIT_FOR_FLAG(playing_orders_supported_read); - printk("Playing orders supported read succeeded\n"); - - /* Read media state ***************************************************/ - UNSET_FLAG(media_state_read); - err = media_proxy_ctrl_get_media_state(current_player); - if (err) { - FAIL("Failed to read media state: %d", err); - return; - } - - WAIT_FOR_FLAG(media_state_read); - printk("Media state read succeeded\n"); - - /* Read content control ID *******************************************/ - UNSET_FLAG(ccid_read); - err = media_proxy_ctrl_get_content_ctrl_id(current_player); - if (err) { - FAIL("Failed to read content control ID: %d", err); - return; - } - - WAIT_FOR_FLAG(ccid_read); - printk("Content control ID read succeeded\n"); - - /* Control point - "state" opcodes */ - - /* This part of the test not only checks that the opcodes are accepted - * by the server, but also that they actually do lead to the expected - * state changes. This may lean too much upon knowledge or assumptions, - * and therefore be too fragile. - * It may be more robust to just give commands and check for the success - * code in the control point notifications - */ - - /* It is assumed that the server starts the test in the paused state */ - test_verify_media_state_wait_flags(MEDIA_PROXY_STATE_PAUSED); - - /* The tests are ordered to ensure that each command changes state */ - test_cp_play(); - test_cp_fast_forward(); - test_cp_pause(); - test_cp_fast_rewind(); - test_cp_stop(); - - - /* Control point - move relative opcode */ - test_cp_move_relative(); - - /* Control point - segment change opcodes */ - test_cp_prev_segment(); - test_cp_next_segment(); - test_cp_first_segment(); - test_cp_last_segment(); - test_cp_goto_segment(); - - - /* Control point - track change opcodes */ - /* The tests are ordered to ensure that each command changes track */ - /* Assumes we are not starting on the last track */ - test_cp_next_track(); - test_cp_prev_track(); - test_cp_last_track(); - test_cp_first_track(); - test_cp_goto_track(); - - - /* Control point - group change opcodes *******************************/ - /* The tests are ordered to ensure that each command changes group */ - /* Assumes we are not starting on the last group */ - test_cp_next_group(); - test_cp_prev_group(); - test_cp_last_group(); - test_cp_first_group(); - test_cp_goto_group(); - - - /* Search control point */ - test_scp(); -} - -void initialize_bluetooth(void) -{ - int err; - - UNSET_FLAG(ble_is_initialized); - err = bt_enable(bt_ready); - if (err) { - FAIL("Bluetooth init failed (err %d)\n", err); - return; - } - - WAIT_FOR_FLAG(ble_is_initialized); - printk("Bluetooth initialized\n"); -} - -void scan_and_connect(void) -{ - char addr[BT_ADDR_LE_STR_LEN]; - int err; - - UNSET_FLAG(ble_link_is_ready); - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); - if (err) { - FAIL("Failed to start scanning (err %d\n)", err); - return; - } - - printk("Scanning started successfully\n"); - - WAIT_FOR_FLAG(ble_link_is_ready); - - - bt_addr_le_to_str(bt_conn_get_dst(default_conn), addr, sizeof(addr)); - printk("Connected: %s\n", addr); -} - -void discover_remote_player(void) -{ - int err; - - UNSET_FLAG(remote_player_instance); - err = media_proxy_ctrl_discover_player(default_conn); - if (err) { - FAIL("Remote player discovery failed (err %d)\n", err); - return; - } - - WAIT_FOR_FLAG(remote_player_instance); -} - -/* BabbleSim entry point for local player test */ -void test_media_controller_local_player(void) -{ - printk("Media Control local player test application. Board: %s\n", CONFIG_BOARD); - - initialize_bluetooth(); - initialize_media(); /* Sets local_player global variable */ - - printk("Local player instance: %p\n", local_player); - - test_media_controller_player(local_player); - - /* TEST IS COMPLETE */ - PASS("Test media_controller_local_player passed\n"); -} - -/* BabbleSim entry point for remote player test */ -void test_media_controller_remote_player(void) -{ - int err; - static struct bt_conn_cb conn_callbacks = { - .connected = connected, - .disconnected = disconnected, - }; - - printk("Media Control remote player test application. Board: %s\n", CONFIG_BOARD); - - bt_conn_cb_register(&conn_callbacks); - - initialize_bluetooth(); - initialize_media(); - - UNSET_FLAG(ble_link_is_ready); - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, AD_SIZE, NULL, 0); - if (err) { - FAIL("Advertising failed to start (err %d)\n", err); - } - WAIT_FOR_FLAG(ble_link_is_ready); - - discover_remote_player(); /* Sets global variable */ - printk("Remote player instance: %p\n", remote_player); - - test_media_controller_player(remote_player); - - /* TEST IS COMPLETE */ - PASS("Test media_controller_remote_player passed\n"); -} - -/* BabbleSim entry point for server for remote player test */ -void test_media_controller_server(void) -{ - static struct bt_conn_cb conn_callbacks = { - .connected = connected, - .disconnected = disconnected, - }; - - printk("Media Control server test application. Board: %s\n", CONFIG_BOARD); - - bt_conn_cb_register(&conn_callbacks); - - initialize_bluetooth(); - initialize_media(); - - /* The server side will also get callbacks, from its local player. - * And if the current player is not set, the callbacks will fail the test. - */ - printk("Local player instance: %p\n", local_player); - current_player = local_player; - - scan_and_connect(); - - /* TEST IS COMPLETE */ - PASS("Test media_controller_server passed\n"); -} - -static const struct bst_test_instance test_media_controller[] = { - { - .test_id = "media_controller_local_player", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_media_controller_local_player - }, - { - .test_id = "media_controller_remote_player", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_media_controller_remote_player - }, - { - .test_id = "media_controller_server", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_media_controller_server - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_media_controller_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_media_controller); -} - -#else - -struct bst_test_list *test_media_controller_install(struct bst_test_list *tests) -{ - return tests; -} - -#endif /* CONFIG_BT_MCS */ diff --git a/tests/bluetooth/bsim/audio/src/micp_mic_ctlr_test.c b/tests/bluetooth/bsim/audio/src/micp_mic_ctlr_test.c deleted file mode 100644 index b8c0b534a2c..00000000000 --- a/tests/bluetooth/bsim/audio/src/micp_mic_ctlr_test.c +++ /dev/null @@ -1,481 +0,0 @@ -/* - * Copyright (c) 2021-2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifdef CONFIG_BT_MICP_MIC_CTLR - -#include -#include - -#include "common.h" - -#define AICS_DESC_SIZE 64 - -extern enum bst_result_t bst_result; - -static struct bt_micp_mic_ctlr *mic_ctlr; -static struct bt_micp_included micp_included; -static volatile bool g_bt_init; -static volatile bool g_is_connected; -static volatile bool g_discovery_complete; -static volatile bool g_write_complete; - -static volatile uint8_t g_mute; -static volatile uint8_t g_aics_count; -static volatile int8_t g_aics_gain; -static volatile uint8_t g_aics_input_mute; -static volatile uint8_t g_aics_mode; -static volatile uint8_t g_aics_input_type; -static volatile uint8_t g_aics_units; -static volatile uint8_t g_aics_gain_max; -static volatile uint8_t g_aics_gain_min; -static volatile bool g_aics_active = true; -static char g_aics_desc[AICS_DESC_SIZE]; -static volatile bool g_cb; - -static void aics_state_cb(struct bt_aics *inst, int err, int8_t gain, - uint8_t mute, uint8_t mode) -{ - if (err != 0) { - FAIL("AICS state cb err (%d)", err); - return; - } - - g_aics_gain = gain; - g_aics_input_mute = mute; - g_aics_mode = mode; - - g_cb = true; -} - -static void aics_gain_setting_cb(struct bt_aics *inst, int err, uint8_t units, - int8_t minimum, int8_t maximum) -{ - if (err != 0) { - FAIL("AICS gain setting cb err (%d)", err); - return; - } - - g_aics_units = units; - g_aics_gain_min = minimum; - g_aics_gain_max = maximum; - - g_cb = true; -} - -static void aics_input_type_cb(struct bt_aics *inst, int err, - uint8_t input_type) -{ - if (err != 0) { - FAIL("AICS input type cb err (%d)", err); - return; - } - - g_aics_input_type = input_type; - - g_cb = true; -} - -static void aics_status_cb(struct bt_aics *inst, int err, bool active) -{ - if (err != 0) { - FAIL("AICS status cb err (%d)", err); - return; - } - - g_aics_active = active; - - g_cb = true; -} - -static void aics_description_cb(struct bt_aics *inst, int err, - char *description) -{ - if (err != 0) { - FAIL("AICS description cb err (%d)", err); - return; - } - - if (strlen(description) > sizeof(g_aics_desc) - 1) { - printk("Warning: AICS description (%zu) is larger than buffer (%zu)\n", - strlen(description), sizeof(g_aics_desc) - 1); - } - - strncpy(g_aics_desc, description, sizeof(g_aics_desc) - 1); - g_aics_desc[sizeof(g_aics_desc) - 1] = '\0'; - - g_cb = true; -} - -static void aics_write_cb(struct bt_aics *inst, int err) -{ - if (err != 0) { - FAIL("AICS write failed (%d)\n", err); - return; - } - - g_write_complete = true; -} - -static void micp_mic_ctlr_discover_cb(struct bt_micp_mic_ctlr *mic_ctlr, - int err, - uint8_t aics_count) -{ - if (err != 0) { - FAIL("MICS could not be discovered (%d)\n", err); - return; - } - - g_aics_count = aics_count; - g_discovery_complete = true; -} - -static void micp_mic_ctlr_mute_written_cb(struct bt_micp_mic_ctlr *mic_ctlr, - int err) -{ - if (err != 0) { - FAIL("mic_ctlr mute write failed (%d)\n", err); - return; - } - - g_write_complete = true; -} - -static void micp_mic_ctlr_unmute_written_cb(struct bt_micp_mic_ctlr *mic_ctlr, - int err) -{ - if (err != 0) { - FAIL("mic_ctlr unmute write failed (%d)\n", err); - return; - } - - g_write_complete = true; -} - -static void micp_mic_ctlr_mute_cb(struct bt_micp_mic_ctlr *mic_ctlr, int err, - uint8_t mute) -{ - if (err != 0) { - FAIL("mic_ctlr mute read failed (%d)\n", err); - return; - } - - g_mute = mute; - g_cb = true; -} - -static struct bt_micp_mic_ctlr_cb micp_mic_ctlr_cbs = { - .discover = micp_mic_ctlr_discover_cb, - .mute = micp_mic_ctlr_mute_cb, - .mute_written = micp_mic_ctlr_mute_written_cb, - .unmute_written = micp_mic_ctlr_unmute_written_cb, - .aics_cb = { - .state = aics_state_cb, - .gain_setting = aics_gain_setting_cb, - .type = aics_input_type_cb, - .status = aics_status_cb, - .description = aics_description_cb, - .set_gain = aics_write_cb, - .unmute = aics_write_cb, - .mute = aics_write_cb, - .set_manual_mode = aics_write_cb, - .set_auto_mode = aics_write_cb, - } -}; - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - bt_conn_unref(default_conn); - default_conn = NULL; - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - g_is_connected = true; -} - -static void bt_ready(int err) -{ - if (err != 0) { - FAIL("Bluetooth discover failed (err %d)\n", err); - return; - } - - g_bt_init = true; -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - -static int test_aics(void) -{ - int err; - int8_t expected_gain; - uint8_t expected_input_mute; - uint8_t expected_mode; - uint8_t expected_input_type; - char expected_aics_desc[AICS_DESC_SIZE]; - struct bt_conn *cached_conn; - - printk("Getting AICS client conn\n"); - err = bt_aics_client_conn_get(micp_included.aics[0], &cached_conn); - if (err != 0) { - FAIL("Could not get AICS client conn (err %d)\n", err); - return err; - } - if (cached_conn != default_conn) { - FAIL("Cached conn was not the conn used to discover"); - return -ENOTCONN; - } - - printk("Getting AICS state\n"); - g_cb = false; - err = bt_aics_state_get(micp_included.aics[0]); - if (err != 0) { - FAIL("Could not get AICS state (err %d)\n", err); - return err; - } - WAIT_FOR_COND(g_cb); - printk("AICS state get\n"); - - printk("Getting AICS gain setting\n"); - g_cb = false; - err = bt_aics_gain_setting_get(micp_included.aics[0]); - if (err != 0) { - FAIL("Could not get AICS gain setting (err %d)\n", err); - return err; - } - WAIT_FOR_COND(g_cb); - printk("AICS gain setting get\n"); - - printk("Getting AICS input type\n"); - expected_input_type = BT_AICS_INPUT_TYPE_UNSPECIFIED; - g_cb = false; - err = bt_aics_type_get(micp_included.aics[0]); - if (err != 0) { - FAIL("Could not get AICS input type (err %d)\n", err); - return err; - } - /* Expect and wait for input_type from init */ - WAIT_FOR_COND(g_cb && expected_input_type == g_aics_input_type); - printk("AICS input type get\n"); - - printk("Getting AICS status\n"); - g_cb = false; - err = bt_aics_status_get(micp_included.aics[0]); - if (err != 0) { - FAIL("Could not get AICS status (err %d)\n", err); - return err; - } - WAIT_FOR_COND(g_cb); - printk("AICS status get\n"); - - printk("Getting AICS description\n"); - g_cb = false; - err = bt_aics_description_get(micp_included.aics[0]); - if (err != 0) { - FAIL("Could not get AICS description (err %d)\n", err); - return err; - } - WAIT_FOR_COND(g_cb); - printk("AICS description get\n"); - - printk("Setting AICS mute\n"); - expected_input_mute = BT_AICS_STATE_MUTED; - g_write_complete = g_cb = false; - err = bt_aics_mute(micp_included.aics[0]); - if (err != 0) { - FAIL("Could not set AICS mute (err %d)\n", err); - return err; - } - WAIT_FOR_COND(g_aics_input_mute == expected_input_mute && - g_cb && g_write_complete); - printk("AICS mute set\n"); - - printk("Setting AICS unmute\n"); - expected_input_mute = BT_AICS_STATE_UNMUTED; - g_write_complete = g_cb = false; - err = bt_aics_unmute(micp_included.aics[0]); - if (err != 0) { - FAIL("Could not set AICS unmute (err %d)\n", err); - return err; - } - WAIT_FOR_COND(g_aics_input_mute == expected_input_mute && - g_cb && g_write_complete); - printk("AICS unmute set\n"); - - printk("Setting AICS auto mode\n"); - expected_mode = BT_AICS_MODE_AUTO; - g_write_complete = g_cb = false; - err = bt_aics_automatic_gain_set(micp_included.aics[0]); - if (err != 0) { - FAIL("Could not set AICS auto mode (err %d)\n", err); - return err; - } - WAIT_FOR_COND(g_aics_mode == expected_mode && g_cb && g_write_complete); - printk("AICS auto mode set\n"); - - printk("Setting AICS manual mode\n"); - expected_mode = BT_AICS_MODE_MANUAL; - g_write_complete = g_cb = false; - err = bt_aics_manual_gain_set(micp_included.aics[0]); - if (err != 0) { - FAIL("Could not set AICS manual mode (err %d)\n", err); - return err; - } - WAIT_FOR_COND(g_aics_mode == expected_mode && g_cb && g_write_complete); - printk("AICS manual mode set\n"); - - printk("Setting AICS gain\n"); - expected_gain = g_aics_gain_max - 1; - g_write_complete = g_cb = false; - err = bt_aics_gain_set(micp_included.aics[0], expected_gain); - if (err != 0) { - FAIL("Could not set AICS gain (err %d)\n", err); - return err; - } - WAIT_FOR_COND(g_aics_gain == expected_gain && g_cb && g_write_complete); - printk("AICS gain set\n"); - - printk("Setting AICS Description\n"); - strncpy(expected_aics_desc, "New Input Description", - sizeof(expected_aics_desc)); - expected_aics_desc[sizeof(expected_aics_desc) - 1] = '\0'; - g_cb = false; - err = bt_aics_description_set(micp_included.aics[0], - expected_aics_desc); - if (err != 0) { - FAIL("Could not set AICS Description (err %d)\n", err); - return err; - } - WAIT_FOR_COND(g_cb && - (strncmp(expected_aics_desc, g_aics_desc, - sizeof(expected_aics_desc)) == 0)); - printk("AICS Description set\n"); - - printk("AICS passed\n"); - return 0; -} - -static void test_main(void) -{ - int err; - uint8_t expected_mute; - struct bt_conn *cached_conn; - - err = bt_enable(bt_ready); - - if (err != 0) { - FAIL("Bluetooth discover failed (err %d)\n", err); - return; - } - - bt_micp_mic_ctlr_cb_register(&micp_mic_ctlr_cbs); - - WAIT_FOR_COND(g_bt_init); - - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); - if (err != 0) { - FAIL("Scanning failed to start (err %d)\n", err); - return; - } - printk("Scanning successfully started\n"); - WAIT_FOR_COND(g_is_connected); - - err = bt_micp_mic_ctlr_discover(default_conn, &mic_ctlr); - if (err != 0) { - FAIL("Failed to discover MICS %d", err); - } - WAIT_FOR_COND(g_discovery_complete); - - err = bt_micp_mic_ctlr_included_get(mic_ctlr, &micp_included); - if (err != 0) { - FAIL("Failed to get mic_ctlr context (err %d)\n", err); - return; - } - - printk("Getting mic_ctlr conn\n"); - err = bt_micp_mic_ctlr_conn_get(mic_ctlr, &cached_conn); - if (err != 0) { - FAIL("Failed to get mic_ctlr conn (err %d)\n", err); - return; - } - if (cached_conn != default_conn) { - FAIL("Cached conn was not the conn used to discover"); - return; - } - - printk("Getting mic_ctlr mute state\n"); - g_cb = false; - err = bt_micp_mic_ctlr_mute_get(mic_ctlr); - if (err != 0) { - FAIL("Could not get mic_ctlr mute state (err %d)\n", err); - return; - } - WAIT_FOR_COND(g_cb); - printk("mic_ctlr mute state received\n"); - - printk("Muting mic_ctlr\n"); - expected_mute = 1; - g_write_complete = g_cb = false; - err = bt_micp_mic_ctlr_mute(mic_ctlr); - if (err != 0) { - FAIL("Could not mute mic_ctlr (err %d)\n", err); - return; - } - WAIT_FOR_COND(g_mute == expected_mute && g_cb && g_write_complete); - printk("mic_ctlr muted\n"); - - printk("Unmuting mic_ctlr\n"); - expected_mute = 0; - g_write_complete = g_cb = false; - err = bt_micp_mic_ctlr_unmute(mic_ctlr); - if (err != 0) { - FAIL("Could not unmute mic_ctlr (err %d)\n", err); - return; - } - WAIT_FOR_COND(g_mute == expected_mute && g_cb && g_write_complete); - printk("mic_ctlr unmuted\n"); - - if (CONFIG_BT_MICP_MIC_CTLR_MAX_AICS_INST > 0 && g_aics_count > 0) { - if (test_aics()) { - return; - } - } - - PASS("mic_ctlr Passed\n"); -} - -static const struct bst_test_instance test_micp[] = { - { - .test_id = "micp_mic_ctlr", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_micp_mic_ctlr_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_micp); -} - -#else - -struct bst_test_list *test_micp_mic_ctlr_install(struct bst_test_list *tests) -{ - return tests; -} - -#endif /* CONFIG_BT_MICP_MIC_CTLR */ diff --git a/tests/bluetooth/bsim/audio/src/micp_mic_dev_test.c b/tests/bluetooth/bsim/audio/src/micp_mic_dev_test.c deleted file mode 100644 index 771fb767f02..00000000000 --- a/tests/bluetooth/bsim/audio/src/micp_mic_dev_test.c +++ /dev/null @@ -1,484 +0,0 @@ -/* - * Copyright (c) 2020-2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifdef CONFIG_BT_MICP_MIC_DEV -#include -#include "common.h" - -extern enum bst_result_t bst_result; - -#if defined(CONFIG_BT_AICS) -#define AICS_DESC_SIZE CONFIG_BT_AICS_MAX_INPUT_DESCRIPTION_SIZE -#else -#define AICS_DESC_SIZE 0 -#endif /* CONFIG_BT_AICS */ - -static struct bt_micp_included micp_included; - -static volatile uint8_t g_mute; -static volatile int8_t g_aics_gain; -static volatile uint8_t g_aics_input_mute; -static volatile uint8_t g_aics_mode; -static volatile uint8_t g_aics_input_type; -static volatile uint8_t g_aics_units; -static volatile uint8_t g_aics_gain_max; -static volatile uint8_t g_aics_gain_min; -static volatile bool g_aics_active = true; -static char g_aics_desc[AICS_DESC_SIZE]; -static volatile bool g_cb; -static bool g_is_connected; - -static void micp_mute_cb(uint8_t mute) -{ - g_mute = mute; - g_cb = true; -} - -static struct bt_micp_mic_dev_cb micp_cb = { - .mute = micp_mute_cb, -}; - -#if defined(CONFIG_BT_MICP_MIC_DEV_AICS) -static void aics_state_cb(struct bt_aics *inst, int err, int8_t gain, - uint8_t mute, uint8_t mode) -{ - if (err != 0) { - FAIL("AICS state cb err (%d)", err); - return; - } - - g_aics_gain = gain; - g_aics_input_mute = mute; - g_aics_mode = mode; - g_cb = true; -} - -static void aics_gain_setting_cb(struct bt_aics *inst, int err, uint8_t units, - int8_t minimum, int8_t maximum) -{ - if (err != 0) { - FAIL("AICS gain setting cb err (%d)", err); - return; - } - - g_aics_units = units; - g_aics_gain_min = minimum; - g_aics_gain_max = maximum; - g_cb = true; -} - -static void aics_input_type_cb(struct bt_aics *inst, int err, - uint8_t input_type) -{ - if (err != 0) { - FAIL("AICS input type cb err (%d)", err); - return; - } - - g_aics_input_type = input_type; - g_cb = true; -} - -static void aics_status_cb(struct bt_aics *inst, int err, bool active) -{ - if (err != 0) { - FAIL("AICS status cb err (%d)", err); - return; - } - - g_aics_active = active; - g_cb = true; -} - -static void aics_description_cb(struct bt_aics *inst, int err, - char *description) -{ - if (err != 0) { - FAIL("AICS description cb err (%d)", err); - return; - } - - - strncpy(g_aics_desc, description, sizeof(g_aics_desc) - 1); - g_aics_desc[sizeof(g_aics_desc) - 1] = '\0'; - g_cb = true; -} - -static struct bt_aics_cb aics_cb = { - .state = aics_state_cb, - .gain_setting = aics_gain_setting_cb, - .type = aics_input_type_cb, - .status = aics_status_cb, - .description = aics_description_cb -}; -#endif /* CONFIG_BT_MICP_MIC_DEV_AICS */ - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - default_conn = bt_conn_ref(conn); - g_is_connected = true; -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - -static int test_aics_server_only(void) -{ - int err; - int8_t expected_gain; - uint8_t expected_input_mute; - uint8_t expected_mode; - uint8_t expected_input_type; - bool expected_aics_active; - char expected_aics_desc[AICS_DESC_SIZE]; - - printk("Deactivating AICS\n"); - expected_aics_active = false; - err = bt_aics_deactivate(micp_included.aics[0]); - if (err != 0) { - FAIL("Could not deactivate AICS (err %d)\n", err); - return err; - } - WAIT_FOR_COND(expected_aics_active == g_aics_active); - printk("AICS deactivated\n"); - - printk("Activating AICS\n"); - expected_aics_active = true; - err = bt_aics_activate(micp_included.aics[0]); - if (err != 0) { - FAIL("Could not activate AICS (err %d)\n", err); - return err; - } - WAIT_FOR_COND(expected_aics_active == g_aics_active); - printk("AICS activated\n"); - - printk("Getting AICS state\n"); - g_cb = false; - err = bt_aics_state_get(micp_included.aics[0]); - if (err != 0) { - FAIL("Could not get AICS state (err %d)\n", err); - return err; - } - WAIT_FOR_COND(g_cb); - printk("AICS state get\n"); - - printk("Getting AICS gain setting\n"); - g_cb = false; - err = bt_aics_gain_setting_get(micp_included.aics[0]); - if (err != 0) { - FAIL("Could not get AICS gain setting (err %d)\n", err); - return err; - } - WAIT_FOR_COND(g_cb); - printk("AICS gain setting get\n"); - - printk("Getting AICS input type\n"); - g_cb = false; - expected_input_type = BT_AICS_INPUT_TYPE_DIGITAL; - err = bt_aics_type_get(micp_included.aics[0]); - if (err != 0) { - FAIL("Could not get AICS input type (err %d)\n", err); - return err; - } - /* Expect and wait for input_type from init */ - WAIT_FOR_COND(g_cb && expected_input_type == g_aics_input_type); - printk("AICS input type get\n"); - - printk("Getting AICS status\n"); - g_cb = false; - err = bt_aics_status_get(micp_included.aics[0]); - if (err != 0) { - FAIL("Could not get AICS status (err %d)\n", err); - return err; - } - WAIT_FOR_COND(g_cb); - printk("AICS status get\n"); - - printk("Getting AICS description\n"); - g_cb = false; - err = bt_aics_description_get(micp_included.aics[0]); - if (err != 0) { - FAIL("Could not get AICS description (err %d)\n", err); - return err; - } - WAIT_FOR_COND(g_cb); - printk("AICS description get\n"); - - printk("Setting AICS mute\n"); - g_cb = false; - expected_input_mute = BT_AICS_STATE_MUTED; - err = bt_aics_mute(micp_included.aics[0]); - if (err != 0) { - FAIL("Could not set AICS mute (err %d)\n", err); - return err; - } - WAIT_FOR_COND(g_cb && expected_input_mute == g_aics_input_mute); - printk("AICS mute set\n"); - - printk("Setting AICS unmute\n"); - g_cb = false; - expected_input_mute = BT_AICS_STATE_UNMUTED; - err = bt_aics_unmute(micp_included.aics[0]); - if (err != 0) { - FAIL("Could not set AICS unmute (err %d)\n", err); - return err; - } - WAIT_FOR_COND(g_cb && expected_input_mute == g_aics_input_mute); - printk("AICS unmute set\n"); - - printk("Setting AICS auto mode\n"); - g_cb = false; - expected_mode = BT_AICS_MODE_AUTO; - err = bt_aics_automatic_gain_set(micp_included.aics[0]); - if (err != 0) { - FAIL("Could not set AICS auto mode (err %d)\n", err); - return err; - } - WAIT_FOR_COND(g_cb && expected_mode == g_aics_mode); - printk("AICS auto mode set\n"); - - printk("Setting AICS manual mode\n"); - g_cb = false; - expected_mode = BT_AICS_MODE_MANUAL; - err = bt_aics_manual_gain_set(micp_included.aics[0]); - if (err != 0) { - FAIL("Could not set AICS manual mode (err %d)\n", err); - return err; - } - WAIT_FOR_COND(g_cb && expected_mode == g_aics_mode); - printk("AICS manual mode set\n"); - - printk("Setting AICS gain\n"); - g_cb = false; - expected_gain = g_aics_gain_max - 1; - err = bt_aics_gain_set(micp_included.aics[0], expected_gain); - if (err != 0) { - FAIL("Could not set AICS gain (err %d)\n", err); - return err; - } - WAIT_FOR_COND(g_cb && expected_gain == g_aics_gain); - printk("AICS gain set\n"); - - printk("Setting AICS Description\n"); - g_cb = false; - strncpy(expected_aics_desc, "New Input Description", - sizeof(expected_aics_desc)); - expected_aics_desc[sizeof(expected_aics_desc) - 1] = '\0'; - err = bt_aics_description_set(micp_included.aics[0], expected_aics_desc); - if (err != 0) { - FAIL("Could not set AICS Description (err %d)\n", err); - return err; - } - WAIT_FOR_COND(g_cb && !strncmp(expected_aics_desc, g_aics_desc, - sizeof(expected_aics_desc))); - printk("AICS Description set\n"); - - return 0; -} - -static void test_mic_dev_only(void) -{ - int err; - struct bt_micp_mic_dev_register_param micp_param; - uint8_t expected_mute; - - err = bt_enable(NULL); - if (err != 0) { - FAIL("Bluetooth init failed (err %d)\n", err); - return; - } - - printk("Bluetooth initialized\n"); - - (void)memset(&micp_param, 0, sizeof(micp_param)); - -#if defined(CONFIG_BT_MICP_MIC_DEV_AICS) - char input_desc[CONFIG_BT_MICP_MIC_DEV_AICS_INSTANCE_COUNT][16]; - - for (int i = 0; i < ARRAY_SIZE(micp_param.aics_param); i++) { - micp_param.aics_param[i].desc_writable = true; - snprintf(input_desc[i], sizeof(input_desc[i]), "Input %d", i + 1); - micp_param.aics_param[i].description = input_desc[i]; - micp_param.aics_param[i].type = BT_AICS_INPUT_TYPE_DIGITAL; - micp_param.aics_param[i].status = g_aics_active; - micp_param.aics_param[i].gain_mode = BT_AICS_MODE_MANUAL; - micp_param.aics_param[i].units = 1; - micp_param.aics_param[i].min_gain = 0; - micp_param.aics_param[i].max_gain = 100; - micp_param.aics_param[i].cb = &aics_cb; - } -#endif /* CONFIG_BT_MICP_MIC_DEV_AICS */ - - micp_param.cb = &micp_cb; - - err = bt_micp_mic_dev_register(&micp_param); - if (err != 0) { - FAIL("MICP init failed (err %d)\n", err); - return; - } - - if (IS_ENABLED(CONFIG_BT_MICP_MIC_DEV_AICS)) { - err = bt_micp_mic_dev_included_get(&micp_included); - if (err != 0) { - FAIL("MICP get failed (err %d)\n", err); - return; - } - } - - printk("MICP initialized\n"); - - printk("Getting MICP mute\n"); - g_cb = false; - err = bt_micp_mic_dev_mute_get(); - if (err != 0) { - FAIL("Could not get MICP mute (err %d)\n", err); - return; - } - WAIT_FOR_COND(g_cb); - printk("MICP mute get\n"); - - printk("Setting MICP mute\n"); - expected_mute = BT_MICP_MUTE_MUTED; - err = bt_micp_mic_dev_mute(); - if (err != 0) { - FAIL("MICP mute failed (err %d)\n", err); - return; - } - WAIT_FOR_COND(expected_mute == g_mute); - printk("MICP mute set\n"); - - printk("Setting MICP unmute\n"); - expected_mute = BT_MICP_MUTE_UNMUTED; - err = bt_micp_mic_dev_unmute(); - if (err != 0) { - FAIL("MICP unmute failed (err %d)\n", err); - return; - } - WAIT_FOR_COND(expected_mute == g_mute); - printk("MICP unmute set\n"); - - printk("Setting MICP disable\n"); - expected_mute = BT_MICP_MUTE_DISABLED; - err = bt_micp_mic_dev_mute_disable(); - if (err != 0) { - FAIL("MICP disable failed (err %d)\n", err); - return; - } - WAIT_FOR_COND(expected_mute == g_mute); - printk("MICP disable set\n"); - - if (CONFIG_BT_MICP_MIC_DEV_AICS_INSTANCE_COUNT > 0) { - if (test_aics_server_only()) { - return; - } - } - - PASS("MICP mic_dev passed\n"); -} - -static void test_main(void) -{ - int err; - struct bt_micp_mic_dev_register_param micp_param; - - err = bt_enable(NULL); - if (err != 0) { - FAIL("Bluetooth init failed (err %d)\n", err); - return; - } - - printk("Bluetooth initialized\n"); - - (void)memset(&micp_param, 0, sizeof(micp_param)); - -#if defined(CONFIG_BT_MICP_MIC_DEV_AICS) - char input_desc[CONFIG_BT_MICP_MIC_DEV_AICS_INSTANCE_COUNT][16]; - - for (int i = 0; i < ARRAY_SIZE(micp_param.aics_param); i++) { - micp_param.aics_param[i].desc_writable = true; - snprintf(input_desc[i], sizeof(input_desc[i]), - "Input %d", i + 1); - micp_param.aics_param[i].description = input_desc[i]; - micp_param.aics_param[i].type = BT_AICS_INPUT_TYPE_UNSPECIFIED; - micp_param.aics_param[i].status = g_aics_active; - micp_param.aics_param[i].gain_mode = BT_AICS_MODE_MANUAL; - micp_param.aics_param[i].units = 1; - micp_param.aics_param[i].min_gain = 0; - micp_param.aics_param[i].max_gain = 100; - micp_param.aics_param[i].cb = &aics_cb; - } -#endif /* CONFIG_BT_MICP_MIC_DEV_AICS */ - - micp_param.cb = &micp_cb; - - err = bt_micp_mic_dev_register(&micp_param); - if (err != 0) { - FAIL("MICP init failed (err %d)\n", err); - return; - } - - if (IS_ENABLED(CONFIG_BT_MICP_MIC_DEV_AICS)) { - err = bt_micp_mic_dev_included_get(&micp_included); - if (err != 0) { - FAIL("MICP get failed (err %d)\n", err); - return; - } - } - - printk("MICP initialized\n"); - - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, AD_SIZE, NULL, 0); - if (err != 0) { - FAIL("Advertising failed to start (err %d)\n", err); - return; - } - - printk("Advertising successfully started\n"); - - WAIT_FOR_COND(g_is_connected); - - PASS("MICP mic_dev passed\n"); -} - -static const struct bst_test_instance test_micp[] = { - { - .test_id = "micp_mic_dev_only", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_mic_dev_only - }, - { - .test_id = "micp_mic_dev", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_micp_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_micp); -} -#else -struct bst_test_list *test_micp_install(struct bst_test_list *tests) -{ - return tests; -} - -#endif /* CONFIG_BT_MICP_MIC_DEV */ diff --git a/tests/bluetooth/bsim/audio/src/tbs_client_test.c b/tests/bluetooth/bsim/audio/src/tbs_client_test.c deleted file mode 100644 index 38c6df6e316..00000000000 --- a/tests/bluetooth/bsim/audio/src/tbs_client_test.c +++ /dev/null @@ -1,291 +0,0 @@ -/* - * Copyright (c) 2019 Bose Corporation - * Copyright (c) 2021 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifdef CONFIG_BT_TBS_CLIENT - -#include - -#include "common.h" - -static struct bt_conn_cb conn_callbacks; -extern enum bst_result_t bst_result; -static volatile bool bt_init; -static volatile bool is_connected; -static volatile bool discovery_complete; -static volatile bool is_gtbs_found; -static volatile bool read_complete; -static volatile bool call_placed; -static volatile uint8_t call_state; -static volatile uint8_t call_index; -static volatile uint8_t tbs_count; - -CREATE_FLAG(ccid_read_flag); - -static void tbs_client_call_states_cb(struct bt_conn *conn, int err, - uint8_t index, uint8_t call_count, - const struct bt_tbs_client_call_state *call_states) -{ - if (index != 0) { - return; - } - - printk("%s\n", __func__); - printk("Index %u\n", index); - if (err != 0) { - FAIL("Call could not read call states (%d)\n", err); - return; - } - - call_index = call_states[0].index; - call_state = call_states[0].state; - printk("call index %u - state %u\n", call_index, call_state); -} - -static void tbs_client_read_bearer_provider_name(struct bt_conn *conn, int err, - uint8_t index, - const char *value) -{ - if (err != 0) { - FAIL("Call could not read bearer name (%d)\n", err); - return; - } - - printk("Index %u\n", index); - printk("Bearer name pointer: %p\n", value); - printk("Bearer name: %s\n", value); - read_complete = true; -} - -static void tbs_client_discover_cb(struct bt_conn *conn, int err, - uint8_t count, bool gtbs_found) -{ - printk("%s\n", __func__); - if (err != 0) { - FAIL("TBS_CLIENT could not be discovered (%d)\n", err); - return; - } - - tbs_count = count; - is_gtbs_found = true; - discovery_complete = true; -} - -static void tbs_client_read_ccid_cb(struct bt_conn *conn, int err, - uint8_t inst_index, uint32_t value) -{ - struct bt_tbs_instance *inst; - - if (value > UINT8_MAX) { - FAIL("Invalid CCID: %u", value); - return; - } - - printk("Read CCID %u on index %u\n", value, inst_index); - - inst = bt_tbs_client_get_by_ccid(conn, (uint8_t)value); - if (inst == NULL) { - FAIL("Could not get instance by CCID: %u", value); - return; - } - - SET_FLAG(ccid_read_flag); -} - -static const struct bt_tbs_client_cb tbs_client_cbs = { - .discover = tbs_client_discover_cb, - .originate_call = NULL, - .terminate_call = NULL, - .hold_call = NULL, - .accept_call = NULL, - .retrieve_call = NULL, - .bearer_provider_name = tbs_client_read_bearer_provider_name, - .bearer_uci = NULL, - .technology = NULL, - .uri_list = NULL, - .signal_strength = NULL, - .signal_interval = NULL, - .current_calls = NULL, - .ccid = tbs_client_read_ccid_cb, - .status_flags = NULL, - .call_uri = NULL, - .call_state = tbs_client_call_states_cb, - .termination_reason = NULL -}; - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - bt_conn_unref(default_conn); - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - is_connected = true; -} - -static void bt_ready(int err) -{ - if (err != 0) { - FAIL("Bluetooth discover failed (err %d)\n", err); - return; - } - - bt_init = true; -} - -static struct bt_conn_cb conn_callbacks = { - .connected = connected, - .disconnected = disconnected, -}; - -static void test_ccid(void) -{ - if (is_gtbs_found) { - int err; - - UNSET_FLAG(ccid_read_flag); - printk("Reading GTBS CCID\n"); - - err = bt_tbs_client_read_ccid(default_conn, BT_TBS_GTBS_INDEX); - if (err != 0) { - FAIL("Read GTBS CCID failed (%d)\n", err); - return; - } - - WAIT_FOR_FLAG(ccid_read_flag); - } - - for (uint8_t i = 0; i < tbs_count; i++) { - int err; - - UNSET_FLAG(ccid_read_flag); - printk("Reading bearer CCID on index %u\n", i); - - err = bt_tbs_client_read_ccid(default_conn, i); - if (err != 0) { - FAIL("Read bearer CCID failed (%d)\n", err); - return; - } - - WAIT_FOR_FLAG(ccid_read_flag); - } -} - -static void test_main(void) -{ - int err; - int index = 0; - int tbs_client_err; - - err = bt_enable(bt_ready); - - if (err != 0) { - FAIL("Bluetooth discover failed (err %d)\n", err); - return; - } - - bt_conn_cb_register(&conn_callbacks); - bt_tbs_client_register_cb(&tbs_client_cbs); - - WAIT_FOR_COND(bt_init); - - printk("Audio Server: Bluetooth discovered\n"); - - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, AD_SIZE, NULL, 0); - if (err != 0) { - FAIL("Advertising failed to start (err %d)\n", err); - return; - } - - printk("Advertising successfully started\n"); - - WAIT_FOR_COND(is_connected); - - tbs_client_err = bt_tbs_client_discover(default_conn, true); - if (tbs_client_err) { - FAIL("Failed to discover TBS_CLIENT for connection %d", tbs_client_err); - } - - WAIT_FOR_COND(discovery_complete); - - printk("GTBS %sfound\n", is_gtbs_found ? "" : "not "); - - printk("Placing call\n"); - err = bt_tbs_client_originate_call(default_conn, 0, "tel:123456789012"); - if (err != 0) { - FAIL("Originate call failed (%d)\n", err); - } - - /* Call transitions: - * 1) Dialing - * 2) Alerting - * 3) Active - * 4) Remotely Held - */ - printk("Waiting for remotely held\n"); - WAIT_FOR_COND(call_state == BT_TBS_CALL_STATE_REMOTELY_HELD); - - printk("Holding call\n"); - err = bt_tbs_client_hold_call(default_conn, index, call_index); - if (err != 0) { - FAIL("Hold call failed (%d)\n", err); - } - - /* Call transitions: - * 1) Locally and remotely held - * 2) Locally held - */ - WAIT_FOR_COND(call_state == BT_TBS_CALL_STATE_LOCALLY_HELD); - - printk("Retrieving call\n"); - err = bt_tbs_client_retrieve_call(default_conn, index, call_index); - if (err != 0) { - FAIL("Retrieve call failed (%d)\n", err); - } - - WAIT_FOR_COND(call_state == BT_TBS_CALL_STATE_ACTIVE); - - printk("Reading bearer provider name\n"); - err = bt_tbs_client_read_bearer_provider_name(default_conn, index); - if (err != 0) { - FAIL("Read bearer provider name failed (%d)\n", err); - } - - test_ccid(); - - WAIT_FOR_COND(read_complete); - PASS("TBS_CLIENT Passed\n"); -} - -static const struct bst_test_instance test_tbs_client[] = { - { - .test_id = "tbs_client", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_tbs_client_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_tbs_client); -} - -#else - -struct bst_test_list *test_tbs_client_install(struct bst_test_list *tests) -{ - return tests; -} - -#endif /* CONFIG_BT_TBS_CLIENT */ diff --git a/tests/bluetooth/bsim/audio/src/tbs_test.c b/tests/bluetooth/bsim/audio/src/tbs_test.c deleted file mode 100644 index 0a2042facb9..00000000000 --- a/tests/bluetooth/bsim/audio/src/tbs_test.c +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (c) 2019 Bose Corporation - * Copyright (c) 2021 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifdef CONFIG_BT_TBS -#include -#include "common.h" - -extern enum bst_result_t bst_result; -static volatile bool is_connected; -static volatile bool call_placed; -static volatile bool call_held; -static volatile bool call_id; - -static void tbs_hold_call_cb(struct bt_conn *conn, uint8_t call_index) -{ - if (call_index == call_id) { - call_held = true; - } -} - -static bool tbs_originate_call_cb(struct bt_conn *conn, uint8_t call_index, - const char *caller_id) -{ - printk("Placing call to remote with id %u to %s\n", - call_index, caller_id); - call_id = call_index; - call_placed = true; - return true; -} - -static bool tbs_authorize_cb(struct bt_conn *conn) -{ - return conn == default_conn; -} - -static struct bt_tbs_cb tbs_cbs = { - .originate_call = tbs_originate_call_cb, - .terminate_call = NULL, - .hold_call = tbs_hold_call_cb, - .accept_call = NULL, - .retrieve_call = NULL, - .join_calls = NULL, - .authorize = tbs_authorize_cb, -}; - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - - default_conn = bt_conn_ref(conn); - is_connected = true; -} - -static struct bt_conn_cb conn_callbacks = { - .connected = connected, - .disconnected = disconnected, -}; - -static void test_main(void) -{ - int err; - - err = bt_enable(NULL); - if (err != 0) { - printk("Bluetooth init failed (err %d)\n", err); - return; - } - - printk("Audio Client: Bluetooth initialized\n"); - - bt_conn_cb_register(&conn_callbacks); - bt_tbs_register_cb(&tbs_cbs); - - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); - if (err != 0) { - FAIL("Scanning failed to start (err %d)\n", err); - return; - } - - printk("Scanning successfully started\n"); - - WAIT_FOR_COND(is_connected); - - WAIT_FOR_COND(call_placed); - - err = bt_tbs_remote_answer(call_id); - if (err != BT_TBS_RESULT_CODE_SUCCESS) { - FAIL("Remote could not answer call: %d\n", err); - return; - } - printk("Remote answered %u\n", call_id); - - err = bt_tbs_remote_hold(call_id); - if (err != BT_TBS_RESULT_CODE_SUCCESS) { - FAIL("Remote could not hold call: %d\n", err); - } - printk("Remote held %u\n", call_id); - - WAIT_FOR_COND(call_held); - - err = bt_tbs_remote_retrieve(call_id); - if (err != BT_TBS_RESULT_CODE_SUCCESS) { - FAIL("Remote could not answer call: %d\n", err); - return; - } - printk("Remote retrieved %u\n", call_id); - - PASS("TBS passed\n"); -} - -static const struct bst_test_instance test_tbs[] = { - { - .test_id = "tbs", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_tbs_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_tbs); -} -#else -struct bst_test_list *test_tbs_install(struct bst_test_list *tests) -{ - return tests; -} - -#endif /* CONFIG_BT_TBS */ diff --git a/tests/bluetooth/bsim/audio/src/vcp_vol_ctlr_test.c b/tests/bluetooth/bsim/audio/src/vcp_vol_ctlr_test.c deleted file mode 100644 index 53a4c8a2533..00000000000 --- a/tests/bluetooth/bsim/audio/src/vcp_vol_ctlr_test.c +++ /dev/null @@ -1,1238 +0,0 @@ -/* - * Copyright (c) 2021-2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifdef CONFIG_BT_VCP_VOL_CTLR - -#include -#include -#include - -#include "common.h" - - -#define VOCS_DESC_SIZE 64 -#define AICS_DESC_SIZE 64 - -extern enum bst_result_t bst_result; - -static struct bt_vcp_vol_ctlr *vol_ctlr; -static struct bt_vcp_included vcp_included; -static volatile bool g_is_connected; -static volatile bool g_discovery_complete; -static volatile bool g_write_complete; - -static volatile uint8_t g_volume; -static volatile uint8_t g_mute; -static volatile uint8_t g_flags; -static volatile int16_t g_vocs_offset; -static volatile uint32_t g_vocs_location; -static char g_vocs_desc[VOCS_DESC_SIZE]; -static volatile int8_t g_aics_gain; -static volatile uint8_t g_aics_input_mute; -static volatile uint8_t g_aics_mode; -static volatile uint8_t g_aics_input_type; -static volatile uint8_t g_aics_units; -static volatile uint8_t g_aics_gain_max; -static volatile uint8_t g_aics_gain_min; -static volatile bool g_aics_active = 1; -static char g_aics_desc[AICS_DESC_SIZE]; -static volatile bool g_cb; - -static void vcs_state_cb(struct bt_vcp_vol_ctlr *vol_ctlr, int err, - uint8_t volume, uint8_t mute) -{ - if (err != 0) { - FAIL("VCP state cb err (%d)", err); - return; - } - - g_volume = volume; - g_mute = mute; - - g_cb = true; -} - -static void vcs_flags_cb(struct bt_vcp_vol_ctlr *vol_ctlr, int err, - uint8_t flags) -{ - if (err != 0) { - FAIL("VCP flags cb err (%d)", err); - return; - } - - g_flags = flags; - - g_cb = true; -} - -static void vocs_state_cb(struct bt_vocs *inst, int err, int16_t offset) -{ - if (err != 0) { - FAIL("VOCS state cb err (%d)", err); - return; - } - - g_vocs_offset = offset; - - g_cb = true; -} - -static void vocs_location_cb(struct bt_vocs *inst, int err, uint32_t location) -{ - if (err != 0) { - FAIL("VOCS location cb err (%d)", err); - return; - } - - g_vocs_location = location; - - g_cb = true; -} - -static void vocs_description_cb(struct bt_vocs *inst, int err, - char *description) -{ - if (err != 0) { - FAIL("VOCS description cb err (%d)", err); - return; - } - - if (strlen(description) > sizeof(g_vocs_desc) - 1) { - printk("Warning: VOCS description (%zu) is larger than buffer (%zu)\n", - strlen(description), sizeof(g_vocs_desc) - 1); - } - - strncpy(g_vocs_desc, description, sizeof(g_vocs_desc) - 1); - g_vocs_desc[sizeof(g_vocs_desc) - 1] = '\0'; - - g_cb = true; -} - -static void vocs_write_cb(struct bt_vocs *inst, int err) -{ - if (err != 0) { - FAIL("VOCS write failed (%d)\n", err); - return; - } - - g_write_complete = true; -} - -static void aics_state_cb(struct bt_aics *inst, int err, int8_t gain, - uint8_t mute, uint8_t mode) -{ - if (err != 0) { - FAIL("AICS state cb err (%d)", err); - return; - } - - g_aics_gain = gain; - g_aics_input_mute = mute; - g_aics_mode = mode; - - g_cb = true; -} - -static void aics_gain_setting_cb(struct bt_aics *inst, int err, uint8_t units, - int8_t minimum, int8_t maximum) -{ - if (err != 0) { - FAIL("AICS gain setting cb err (%d)", err); - return; - } - - g_aics_units = units; - g_aics_gain_min = minimum; - g_aics_gain_max = maximum; - - g_cb = true; -} - -static void aics_input_type_cb(struct bt_aics *inst, int err, - uint8_t input_type) -{ - if (err != 0) { - FAIL("AICS input type cb err (%d)", err); - return; - } - - g_aics_input_type = input_type; - - g_cb = true; -} - -static void aics_status_cb(struct bt_aics *inst, int err, bool active) -{ - if (err != 0) { - FAIL("AICS status cb err (%d)", err); - return; - } - - g_aics_active = active; - - g_cb = true; -} - -static void aics_description_cb(struct bt_aics *inst, int err, - char *description) -{ - if (err != 0) { - FAIL("AICS description cb err (%d)", err); - return; - } - - if (strlen(description) > sizeof(g_aics_desc) - 1) { - printk("Warning: AICS description (%zu) is larger than buffer (%zu)\n", - strlen(description), sizeof(g_aics_desc) - 1); - } - - strncpy(g_aics_desc, description, sizeof(g_aics_desc) - 1); - g_aics_desc[sizeof(g_aics_desc) - 1] = '\0'; - - g_cb = true; -} - -static void aics_write_cb(struct bt_aics *inst, int err) -{ - if (err != 0) { - FAIL("AICS write failed (%d)\n", err); - return; - } - - g_write_complete = true; -} - -static void vcs_discover_cb(struct bt_vcp_vol_ctlr *vol_ctlr, int err, - uint8_t vocs_count, uint8_t aics_count) -{ - if (err != 0) { - FAIL("VCP could not be discovered (%d)\n", err); - return; - } - - g_discovery_complete = true; -} - -static void vcs_write_cb(struct bt_vcp_vol_ctlr *vol_ctlr, int err) -{ - if (err != 0) { - FAIL("VCP write failed (%d)\n", err); - return; - } - - g_write_complete = true; -} - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - bt_conn_unref(default_conn); - default_conn = NULL; - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - printk("Connected to %s\n", addr); - g_is_connected = true; -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - -static void test_aics_deactivate(void) -{ - int err; - - /* Invalid behavior */ - err = bt_aics_deactivate(NULL); - if (err == 0) { - FAIL("bt_aics_deactivate with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Attempting to deactivate AICS\n"); - err = bt_aics_deactivate(vcp_included.aics[0]); - if (err == 0) { - FAIL("bt_aics_deactivate as client instance did not fail"); - return; - } -} - -static void test_aics_activate(void) -{ - int err; - - /* Invalid behavior */ - err = bt_aics_activate(NULL); - if (err == 0) { - FAIL("bt_aics_activate with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Attempting to activate AICS\n"); - err = bt_aics_activate(vcp_included.aics[0]); - if (err == 0) { - FAIL("bt_aics_activate as client instance did not fail"); - return; - } -} - -static void test_aics_state_get(void) -{ - int err; - - /* Invalid behavior */ - err = bt_aics_state_get(NULL); - if (err == 0) { - FAIL("bt_aics_state_get with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Getting AICS state\n"); - g_cb = false; - - err = bt_aics_state_get(vcp_included.aics[0]); - if (err != 0) { - FAIL("Could not get AICS state (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_cb); - printk("AICS state get\n"); -} - -static void aics_gain_setting_get(void) -{ - int err; - - /* Invalid behavior */ - err = bt_aics_gain_setting_get(NULL); - if (err == 0) { - FAIL("bt_aics_gain_setting_get with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Getting AICS gain setting\n"); - g_cb = false; - - err = bt_aics_gain_setting_get(vcp_included.aics[0]); - if (err != 0) { - FAIL("Could not get AICS gain setting (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_cb); - printk("AICS gain setting get\n"); -} - -static void aics_type_get(void) -{ - const uint8_t expected_input_type = BT_AICS_INPUT_TYPE_DIGITAL; - int err; - - /* Invalid behavior */ - err = bt_aics_type_get(NULL); - if (err == 0) { - FAIL("bt_aics_type_get with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Getting AICS input type\n"); - - err = bt_aics_type_get(vcp_included.aics[0]); - if (err != 0) { - FAIL("Could not get AICS input type (err %d)\n", err); - return; - } - - /* Expect and wait for input_type from init */ - WAIT_FOR_COND(expected_input_type == g_aics_input_type); - printk("AICS input type get\n"); -} - -static void aics_status_get(void) -{ - int err; - - /* Invalid behavior */ - err = bt_aics_status_get(NULL); - if (err == 0) { - FAIL("bt_aics_status_get with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Getting AICS status\n"); - g_cb = false; - - err = bt_aics_status_get(vcp_included.aics[0]); - if (err != 0) { - FAIL("Could not get AICS status (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_cb); - printk("AICS status get\n"); -} - -static void aics_get_description(void) -{ - int err; - - /* Invalid behavior */ - err = bt_aics_description_get(NULL); - if (err == 0) { - FAIL("bt_aics_description_get with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Getting AICS description\n"); - g_cb = false; - - err = bt_aics_description_get(vcp_included.aics[0]); - if (err != 0) { - FAIL("Could not get AICS description (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_cb); - printk("AICS description get\n"); -} - -static void test_aics_mute(void) -{ - const uint8_t expected_input_mute = BT_AICS_STATE_MUTED; - int err; - - /* Invalid behavior */ - err = bt_aics_mute(NULL); - if (err == 0) { - FAIL("bt_aics_mute with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Setting AICS mute\n"); - g_write_complete = false; - - err = bt_aics_mute(vcp_included.aics[0]); - if (err != 0) { - FAIL("Could not set AICS mute (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_write_complete && expected_input_mute == g_aics_input_mute); - printk("AICS mute set\n"); -} - -static void test_aics_unmute(void) -{ - const uint8_t expected_input_mute = BT_AICS_STATE_UNMUTED; - int err; - - /* Invalid behavior */ - err = bt_aics_unmute(NULL); - if (err == 0) { - FAIL("bt_aics_unmute with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Setting AICS unmute\n"); - g_write_complete = false; - - err = bt_aics_unmute(vcp_included.aics[0]); - if (err != 0) { - FAIL("Could not set AICS unmute (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_write_complete && expected_input_mute == g_aics_input_mute); - printk("AICS unmute set\n"); -} - -static void test_aics_automatic_gain_set(void) -{ - const uint8_t expected_mode = BT_AICS_MODE_AUTO; - int err; - - /* Invalid behavior */ - err = bt_aics_automatic_gain_set(NULL); - if (err == 0) { - FAIL("bt_aics_automatic_gain_set with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Setting AICS auto mode\n"); - g_write_complete = false; - - err = bt_aics_automatic_gain_set(vcp_included.aics[0]); - if (err != 0) { - FAIL("Could not set AICS auto mode (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_write_complete && expected_mode == g_aics_mode); - printk("AICS auto mode set\n"); -} - -static void test_aics_manual_gain_set(void) -{ - const uint8_t expected_mode = BT_AICS_MODE_MANUAL; - int err; - - /* Invalid behavior */ - err = bt_aics_manual_gain_set(NULL); - if (err == 0) { - FAIL("bt_aics_manual_gain_set with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Setting AICS manual mode\n"); - g_write_complete = false; - - err = bt_aics_manual_gain_set(vcp_included.aics[0]); - if (err != 0) { - FAIL("Could not set AICS manual mode (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_write_complete && expected_mode == g_aics_mode); - printk("AICS manual mode set\n"); -} - -static void test_aics_gain_set(void) -{ - const int8_t expected_gain = g_aics_gain_max - 1; - int err; - - /* Invalid behavior */ - err = bt_aics_gain_set(NULL, expected_gain); - if (err == 0) { - FAIL("bt_aics_gain_set with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Setting AICS gain\n"); - g_write_complete = false; - - err = bt_aics_gain_set(vcp_included.aics[0], expected_gain); - if (err != 0) { - FAIL("Could not set AICS gain (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_write_complete && expected_gain == g_aics_gain); - printk("AICS gain set\n"); -} - -static void test_aics_description_set(void) -{ - const char *expected_aics_desc = "New Input Description"; - int err; - - /* Invalid behavior */ - err = bt_aics_description_set(NULL, expected_aics_desc); - if (err == 0) { - FAIL("bt_aics_description_set with NULL inst pointer did not fail"); - return; - } - - err = bt_aics_description_set(vcp_included.aics[0], NULL); - if (err == 0) { - FAIL("bt_aics_description_set with NULL description pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Setting AICS Description\n"); - g_cb = false; - - err = bt_aics_description_set(vcp_included.aics[0], expected_aics_desc); - if (err != 0) { - FAIL("Could not set AICS Description (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_cb && - strncmp(expected_aics_desc, g_aics_desc, strlen(expected_aics_desc)) == 0); - printk("AICS Description set\n"); -} - -static void test_aics(void) -{ - test_aics_deactivate(); - test_aics_activate(); - test_aics_state_get(); - aics_gain_setting_get(); - aics_type_get(); - aics_status_get(); - aics_get_description(); - test_aics_mute(); - test_aics_unmute(); - test_aics_automatic_gain_set(); - test_aics_manual_gain_set(); - test_aics_gain_set(); - test_aics_description_set(); -} - -static void test_vocs_state_get(void) -{ - int err; - - /* Invalid behavior */ - err = bt_vocs_state_get(NULL); - if (err == 0) { - FAIL("bt_vocs_state_get with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Getting VOCS state\n"); - g_cb = false; - - err = bt_vocs_state_get(vcp_included.vocs[0]); - if (err != 0) { - FAIL("Could not get VOCS state (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_cb); - printk("VOCS state get\n"); -} - -static void test_vocs_location_get(void) -{ - int err; - - /* Invalid behavior */ - err = bt_vocs_location_get(NULL); - if (err == 0) { - FAIL("bt_vocs_location_get with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Getting VOCS location\n"); - g_cb = false; - - err = bt_vocs_location_get(vcp_included.vocs[0]); - if (err != 0) { - FAIL("Could not get VOCS location (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_cb); - printk("VOCS location get\n"); -} - -static void test_vocs_description_get(void) -{ - int err; - - /* Invalid behavior */ - err = bt_vocs_description_get(NULL); - if (err == 0) { - FAIL("bt_vocs_description_get with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Getting VOCS description\n"); - g_cb = false; - - err = bt_vocs_description_get(vcp_included.vocs[0]); - if (err != 0) { - FAIL("Could not get VOCS description (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_cb); - printk("VOCS description get\n"); -} - -static void test_vocs_location_set(void) -{ - const uint32_t expected_location = g_vocs_location + 1; - uint32_t invalid_location; - int err; - - /* Invalid behavior */ - err = bt_vocs_location_set(NULL, expected_location); - if (err == 0) { - FAIL("bt_vocs_location_set with NULL inst pointer did not fail"); - return; - } - - invalid_location = BT_AUDIO_LOCATION_PROHIBITED; - - err = bt_vocs_location_set(vcp_included.vocs[0], invalid_location); - if (err == 0) { - FAIL("bt_vocs_location_set with location 0x%08X did not fail", invalid_location); - return; - } - - invalid_location = BT_AUDIO_LOCATION_ANY + 1; - - err = bt_vocs_location_set(vcp_included.vocs[0], invalid_location); - if (err == 0) { - FAIL("bt_vocs_location_set with location 0x%08X did not fail", invalid_location); - return; - } - - /* Valid behavior */ - printk("Setting VOCS location\n"); - - err = bt_vocs_location_set(vcp_included.vocs[0], expected_location); - if (err != 0) { - FAIL("Could not set VOCS location (err %d)\n", err); - return; - } - - WAIT_FOR_COND(expected_location == g_vocs_location); - printk("VOCS location set\n"); -} - -static void test_vocs_state_set(void) -{ - const int16_t expected_offset = g_vocs_offset + 1; - int16_t invalid_offset; - int err; - - /* Invalid behavior */ - err = bt_vocs_state_set(NULL, expected_offset); - if (err == 0) { - FAIL("bt_vocs_state_set with NULL inst pointer did not fail"); - return; - } - - invalid_offset = BT_VOCS_MIN_OFFSET - 1; - - err = bt_vocs_state_set(vcp_included.vocs[0], invalid_offset); - if (err == 0) { - FAIL("bt_vocs_state_set with NULL offset %d did not fail", invalid_offset); - return; - } - - invalid_offset = BT_VOCS_MAX_OFFSET + 1; - - err = bt_vocs_state_set(vcp_included.vocs[0], invalid_offset); - if (err == 0) { - FAIL("bt_vocs_state_set with NULL offset %d did not fail", invalid_offset); - return; - } - - /* Valid behavior */ - printk("Setting VOCS state\n"); - g_write_complete = false; - - err = bt_vocs_state_set(vcp_included.vocs[0], expected_offset); - if (err != 0) { - FAIL("Could not set VOCS state (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_write_complete && expected_offset == g_vocs_offset); - printk("VOCS state set\n"); -} - -static void test_vocs_description_set(void) -{ - const char *expected_vocs_desc = "New Output Description"; - int err; - - /* Invalid behavior */ - err = bt_vocs_description_set(NULL, expected_vocs_desc); - if (err == 0) { - FAIL("bt_vocs_description_set with NULL inst pointer did not fail"); - return; - } - - err = bt_vocs_description_set(vcp_included.vocs[0], NULL); - if (err == 0) { - FAIL("bt_vocs_description_set with NULL description pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Setting VOCS description\n"); - g_cb = false; - - err = bt_vocs_description_set(vcp_included.vocs[0], expected_vocs_desc); - if (err != 0) { - FAIL("Could not set VOCS description (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_cb && - strncmp(expected_vocs_desc, g_vocs_desc, strlen(expected_vocs_desc)) == 0); - printk("VOCS description set\n"); -} - -static void test_vocs(void) -{ - test_vocs_state_get(); - test_vocs_location_get(); - test_vocs_description_get(); - test_vocs_location_set(); - test_vocs_state_set(); - test_vocs_description_set(); -} - -static void test_cb_register(void) -{ - static struct bt_vcp_vol_ctlr_cb vcp_cbs = { - .discover = vcs_discover_cb, - .vol_down = vcs_write_cb, - .vol_up = vcs_write_cb, - .mute = vcs_write_cb, - .unmute = vcs_write_cb, - .vol_down_unmute = vcs_write_cb, - .vol_up_unmute = vcs_write_cb, - .vol_set = vcs_write_cb, - .state = vcs_state_cb, - .flags = vcs_flags_cb, - .vocs_cb = { - .state = vocs_state_cb, - .location = vocs_location_cb, - .description = vocs_description_cb, - .set_offset = vocs_write_cb, - }, - .aics_cb = { - .state = aics_state_cb, - .gain_setting = aics_gain_setting_cb, - .type = aics_input_type_cb, - .status = aics_status_cb, - .description = aics_description_cb, - .set_gain = aics_write_cb, - .unmute = aics_write_cb, - .mute = aics_write_cb, - .set_manual_mode = aics_write_cb, - .set_auto_mode = aics_write_cb, - } - }; - int err; - - err = bt_vcp_vol_ctlr_cb_register(&vcp_cbs); - if (err != 0) { - FAIL("CB register failed (err %d)\n", err); - return; - } -} - -static void test_discover(void) -{ - int err; - - /* Invalid behavior */ - err = bt_vcp_vol_ctlr_discover(NULL, &vol_ctlr); - if (err == 0) { - FAIL("bt_vcp_vol_ctlr_discover with NULL conn pointer did not fail"); - return; - } - - err = bt_vcp_vol_ctlr_discover(default_conn, NULL); - if (err == 0) { - FAIL("bt_vcp_vol_ctlr_discover with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - err = bt_vcp_vol_ctlr_discover(default_conn, &vol_ctlr); - if (err != 0) { - FAIL("Failed to discover VCP %d", err); - return; - } - - WAIT_FOR_COND(g_discovery_complete); -} - -static void test_included_get(void) -{ - int err; - - /* Invalid behavior */ - err = bt_vcp_vol_ctlr_included_get(NULL, &vcp_included); - if (err == 0) { - FAIL("bt_vcp_vol_ctlr_included_get with NULL inst pointer did not fail"); - return; - } - - err = bt_vcp_vol_ctlr_included_get(vol_ctlr, NULL); - if (err == 0) { - FAIL("bt_vcp_vol_ctlr_included_get with NULL include pointer did not fail"); - return; - } - - /* Valid behavior */ - err = bt_vcp_vol_ctlr_included_get(vol_ctlr, &vcp_included); - if (err != 0) { - FAIL("Failed to get VCP included services (err %d)\n", err); - return; - } -} - -static void test_conn_get(void) -{ - struct bt_conn *cached_conn; - int err; - - /* Invalid behavior */ - err = bt_vcp_vol_ctlr_conn_get(NULL, &cached_conn); - if (err == 0) { - FAIL("bt_vcp_vol_ctlr_conn_get with NULL inst pointer did not fail"); - return; - } - - err = bt_vcp_vol_ctlr_conn_get(vol_ctlr, NULL); - if (err == 0) { - FAIL("bt_vcp_vol_ctlr_conn_get with NULL cached_conn pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Getting VCP volume controller conn\n"); - - err = bt_vcp_vol_ctlr_conn_get(vol_ctlr, &cached_conn); - if (err != 0) { - FAIL("Could not get VCP volume controller conn (err %d)\n", err); - return; - } - - if (cached_conn != default_conn) { - FAIL("Cached conn was not the conn used to discover"); - return; - } - - printk("Got VCP volume controller conn\n"); -} - -static void test_read_state(void) -{ - int err; - - /* Invalid behavior */ - err = bt_vcp_vol_ctlr_read_state(NULL); - if (err == 0) { - FAIL("bt_vcp_vol_ctlr_read_state with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Getting VCP volume state\n"); - g_cb = false; - - err = bt_vcp_vol_ctlr_read_state(vol_ctlr); - if (err != 0) { - FAIL("Could not get VCP volume (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_cb); - printk("VCP volume get\n"); -} - -static void test_read_flags(void) -{ - int err; - - /* Invalid behavior */ - err = bt_vcp_vol_ctlr_read_flags(NULL); - if (err == 0) { - FAIL("bt_vcp_vol_ctlr_read_flags with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Getting VCP flags\n"); - g_cb = false; - - err = bt_vcp_vol_ctlr_read_flags(vol_ctlr); - if (err != 0) { - FAIL("Could not get VCP flags (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_cb); - printk("VCP flags get\n"); -} - -static void test_set_vol(void) -{ - const uint8_t expected_volume = g_volume + 5; /* Overflow is OK */ - int err; - - g_write_complete = g_cb = false; - - /* Invalid behavior - No invalid volume values to attempt to set */ - err = bt_vcp_vol_ctlr_set_vol(NULL, expected_volume); - if (err == 0) { - FAIL("bt_vcp_vol_ctlr_set_vol with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - err = bt_vcp_vol_ctlr_set_vol(vol_ctlr, expected_volume); - if (err != 0) { - FAIL("Could not set VCP volume (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_volume == expected_volume && g_cb && g_write_complete); - printk("VCP volume set\n"); -} - -static void test_vol_down(void) -{ - const uint8_t previous_volume = g_volume; - int err; - - /* Invalid behavior */ - err = bt_vcp_vol_ctlr_vol_down(NULL); - if (err == 0) { - FAIL("bt_vcp_vol_ctlr_vol_down with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Downing VCP volume\n"); - g_write_complete = g_cb = false; - - err = bt_vcp_vol_ctlr_vol_down(vol_ctlr); - if (err != 0) { - FAIL("Could not get down VCP volume (err %d)\n", err); - return; - } - - WAIT_FOR_COND(previous_volume == 0 || - (g_volume < previous_volume && g_cb && g_write_complete)); - printk("VCP volume downed\n"); -} - -static void test_vol_up(void) -{ - const uint8_t previous_volume = g_volume; - int err; - - /* Invalid behavior */ - err = bt_vcp_vol_ctlr_vol_up(NULL); - if (err == 0) { - FAIL("bt_vcp_vol_ctlr_vol_up with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Upping VCP volume\n"); - g_write_complete = g_cb = false; - - err = bt_vcp_vol_ctlr_vol_up(vol_ctlr); - if (err != 0) { - FAIL("Could not up VCP volume (err %d)\n", err); - return; - } - - WAIT_FOR_COND(previous_volume == UINT8_MAX || - (g_volume > previous_volume && g_cb && g_write_complete)); - printk("VCP volume upped\n"); -} - -static void test_mute(void) -{ - const uint8_t expected_mute = BT_VCP_STATE_MUTED; - int err; - - /* Invalid behavior */ - err = bt_vcp_vol_ctlr_mute(NULL); - if (err == 0) { - FAIL("bt_vcp_vol_ctlr_mute with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Muting VCP\n"); - g_write_complete = g_cb = false; - - err = bt_vcp_vol_ctlr_mute(vol_ctlr); - if (err != 0) { - FAIL("Could not mute VCP (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_mute == expected_mute && g_cb && g_write_complete); - printk("VCP muted\n"); -} - -static void test_unmute_vol_down(void) -{ - const uint8_t expected_mute = BT_VCP_STATE_UNMUTED; - const uint8_t previous_volume = g_volume; - int err; - - /* Invalid behavior */ - err = bt_vcp_vol_ctlr_unmute_vol_down(NULL); - if (err == 0) { - FAIL("bt_vcp_vol_ctlr_unmute_vol_down with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Downing and unmuting VCP\n"); - g_write_complete = g_cb = false; - - err = bt_vcp_vol_ctlr_unmute_vol_down(vol_ctlr); - if (err != 0) { - FAIL("Could not down and unmute VCP (err %d)\n", err); - return; - } - - WAIT_FOR_COND((previous_volume == 0 || g_volume < previous_volume) && - expected_mute == g_mute && - g_cb && - g_write_complete); - printk("VCP volume downed and unmuted\n"); -} - -static void test_unmute_vol_up(void) -{ - const uint8_t expected_mute = BT_VCP_STATE_UNMUTED; - const uint8_t previous_volume = g_volume; - int err; - - /* Invalid behavior */ - err = bt_vcp_vol_ctlr_unmute_vol_up(NULL); - if (err == 0) { - FAIL("bt_vcp_vol_ctlr_unmute_vol_up with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Upping and unmuting VCP\n"); - g_write_complete = g_cb = false; - - err = bt_vcp_vol_ctlr_unmute_vol_up(vol_ctlr); - if (err != 0) { - FAIL("Could not up and unmute VCP (err %d)\n", err); - return; - } - - WAIT_FOR_COND((previous_volume == UINT8_MAX || g_volume > previous_volume) && - g_mute == expected_mute && - g_cb && - g_write_complete); - printk("VCP volume upped and unmuted\n"); -} - -static void test_unmute(void) -{ - const uint8_t expected_mute = BT_VCP_STATE_UNMUTED; - int err; - - /* Invalid behavior */ - err = bt_vcp_vol_ctlr_unmute(NULL); - if (err == 0) { - FAIL("bt_vcp_vol_ctlr_unmute with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Unmuting VCP\n"); - g_write_complete = g_cb = false; - - err = bt_vcp_vol_ctlr_unmute(vol_ctlr); - if (err != 0) { - FAIL("Could not unmute VCP (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_mute == expected_mute && g_cb && g_write_complete); - printk("VCP volume unmuted\n"); -} - -static void test_main(void) -{ - int err; - - err = bt_enable(NULL); - if (err != 0) { - FAIL("Bluetooth discover failed (err %d)\n", err); - return; - } - - test_cb_register(); - - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); - if (err != 0) { - FAIL("Scanning failed to start (err %d)\n", err); - return; - } - - printk("Scanning successfully started\n"); - - WAIT_FOR_COND(g_is_connected); - - test_discover(); - test_included_get(); - test_conn_get(); - test_read_state(); - test_read_flags(); - test_set_vol(); - test_vol_down(); - test_vol_up(); - test_mute(); - test_unmute_vol_down(); - test_mute(); - test_unmute_vol_up(); - test_mute(); - test_unmute(); - - if (CONFIG_BT_VCP_VOL_CTLR_VOCS > 0) { - test_vocs(); - } - - if (CONFIG_BT_VCP_VOL_CTLR_MAX_AICS_INST > 0) { - test_aics(); - } - - PASS("VCP volume controller Passed\n"); -} - -static const struct bst_test_instance test_vcs[] = { - { - .test_id = "vcp_vol_ctlr", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_vcp_vol_ctlr_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_vcs); -} - -#else - -struct bst_test_list *test_vcp_vol_ctlr_install(struct bst_test_list *tests) -{ - return tests; -} - -#endif /* CONFIG_BT_VCP_VOL_CTLR */ diff --git a/tests/bluetooth/bsim/audio/src/vcp_vol_rend_test.c b/tests/bluetooth/bsim/audio/src/vcp_vol_rend_test.c deleted file mode 100644 index 476491d3320..00000000000 --- a/tests/bluetooth/bsim/audio/src/vcp_vol_rend_test.c +++ /dev/null @@ -1,1103 +0,0 @@ -/* - * Copyright (c) 2019 Bose Corporation - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifdef CONFIG_BT_VCP_VOL_REND -#include -#include -#include "common.h" - -extern enum bst_result_t bst_result; - -#if defined(CONFIG_BT_VOCS) -#define VOCS_DESC_SIZE CONFIG_BT_VOCS_MAX_OUTPUT_DESCRIPTION_SIZE -#else -#define VOCS_DESC_SIZE 0 -#endif /* CONFIG_BT_VOCS */ - -#if defined(CONFIG_BT_AICS) -#define AICS_DESC_SIZE CONFIG_BT_AICS_MAX_INPUT_DESCRIPTION_SIZE -#else -#define AICS_DESC_SIZE 0 -#endif /* CONFIG_BT_AICS */ - -static struct bt_vcp_included vcp_included; - -static volatile uint8_t g_volume; -static volatile uint8_t g_mute; -static volatile uint8_t g_flags; -static volatile int16_t g_vocs_offset; -static volatile uint32_t g_vocs_location; -static char g_vocs_desc[VOCS_DESC_SIZE]; -static volatile int8_t g_aics_gain; -static volatile uint8_t g_aics_input_mute; -static volatile uint8_t g_aics_mode; -static volatile uint8_t g_aics_input_type; -static volatile uint8_t g_aics_units; -static volatile uint8_t g_aics_gain_max; -static volatile uint8_t g_aics_gain_min; -static volatile bool g_aics_active = 1; -static char g_aics_desc[AICS_DESC_SIZE]; -static volatile bool g_cb; -static bool g_is_connected; - -static void vcs_state_cb(int err, uint8_t volume, uint8_t mute) -{ - if (err != 0) { - FAIL("VCP state cb err (%d)", err); - return; - } - - g_volume = volume; - g_mute = mute; - g_cb = true; -} - -static void vcs_flags_cb(int err, uint8_t flags) -{ - if (err != 0) { - FAIL("VCP flags cb err (%d)", err); - return; - } - - g_flags = flags; - g_cb = true; -} - -static void vocs_state_cb(struct bt_vocs *inst, int err, int16_t offset) -{ - if (err != 0) { - FAIL("VOCS state cb err (%d)", err); - return; - } - - g_vocs_offset = offset; - g_cb = true; -} - -static void vocs_location_cb(struct bt_vocs *inst, int err, uint32_t location) -{ - if (err != 0) { - FAIL("VOCS location cb err (%d)", err); - return; - } - - g_vocs_location = location; - g_cb = true; -} - -static void vocs_description_cb(struct bt_vocs *inst, int err, - char *description) -{ - if (err != 0) { - FAIL("VOCS description cb err (%d)", err); - return; - } - - strncpy(g_vocs_desc, description, sizeof(g_vocs_desc) - 1); - g_vocs_desc[sizeof(g_vocs_desc) - 1] = '\0'; - g_cb = true; -} - -static void aics_state_cb(struct bt_aics *inst, int err, int8_t gain, - uint8_t mute, uint8_t mode) -{ - if (err != 0) { - FAIL("AICS state cb err (%d)", err); - return; - } - - g_aics_gain = gain; - g_aics_input_mute = mute; - g_aics_mode = mode; - g_cb = true; -} - -static void aics_gain_setting_cb(struct bt_aics *inst, int err, uint8_t units, - int8_t minimum, int8_t maximum) -{ - if (err != 0) { - FAIL("AICS gain setting cb err (%d)", err); - return; - } - - g_aics_units = units; - g_aics_gain_min = minimum; - g_aics_gain_max = maximum; - g_cb = true; -} - -static void aics_input_type_cb(struct bt_aics *inst, int err, - uint8_t input_type) -{ - if (err != 0) { - FAIL("AICS input type cb err (%d)", err); - return; - } - - g_aics_input_type = input_type; - g_cb = true; -} - -static void aics_status_cb(struct bt_aics *inst, int err, bool active) -{ - if (err != 0) { - FAIL("AICS status cb err (%d)", err); - return; - } - - g_aics_active = active; - g_cb = true; -} - -static void aics_description_cb(struct bt_aics *inst, int err, - char *description) -{ - if (err != 0) { - FAIL("AICS description cb err (%d)", err); - return; - } - - strncpy(g_aics_desc, description, sizeof(g_aics_desc) - 1); - g_aics_desc[sizeof(g_aics_desc) - 1] = '\0'; - g_cb = true; -} - -static struct bt_vcp_vol_rend_cb vcs_cb = { - .state = vcs_state_cb, - .flags = vcs_flags_cb, -}; - -static struct bt_vocs_cb vocs_cb = { - .state = vocs_state_cb, - .location = vocs_location_cb, - .description = vocs_description_cb -}; - -static struct bt_aics_cb aics_cb = { - .state = aics_state_cb, - .gain_setting = aics_gain_setting_cb, - .type = aics_input_type_cb, - .status = aics_status_cb, - .description = aics_description_cb -}; - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - printk("Connected to %s\n", addr); - default_conn = bt_conn_ref(conn); - g_is_connected = true; -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - -static void test_aics_deactivate(void) -{ - const bool expected_aics_active = false; - int err; - - /* Invalid behavior */ - err = bt_aics_deactivate(NULL); - if (err == 0) { - FAIL("bt_aics_deactivate with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Deactivating AICS\n"); - err = bt_aics_deactivate(vcp_included.aics[0]); - if (err != 0) { - FAIL("Could not deactivate AICS (err %d)\n", err); - return; - } - - WAIT_FOR_COND(expected_aics_active == g_aics_active); - printk("AICS deactivated\n"); -} - -static void test_aics_activate(void) -{ - const bool expected_aics_active = true; - int err; - - /* Invalid behavior */ - err = bt_aics_activate(NULL); - if (err == 0) { - FAIL("bt_aics_activate with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Activating AICS\n"); - err = bt_aics_activate(vcp_included.aics[0]); - if (err != 0) { - FAIL("Could not activate AICS (err %d)\n", err); - return; - } - - WAIT_FOR_COND(expected_aics_active == g_aics_active); - printk("AICS activated\n"); -} - -static void test_aics_state_get(void) -{ - int err; - - /* Invalid behavior */ - err = bt_aics_state_get(NULL); - if (err == 0) { - FAIL("bt_aics_state_get with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Getting AICS state\n"); - g_cb = false; - - err = bt_aics_state_get(vcp_included.aics[0]); - if (err != 0) { - FAIL("Could not get AICS state (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_cb); - printk("AICS state get\n"); -} - -static void aics_gain_setting_get(void) -{ - int err; - - /* Invalid behavior */ - err = bt_aics_gain_setting_get(NULL); - if (err == 0) { - FAIL("bt_aics_gain_setting_get with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Getting AICS gain setting\n"); - g_cb = false; - - err = bt_aics_gain_setting_get(vcp_included.aics[0]); - if (err != 0) { - FAIL("Could not get AICS gain setting (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_cb); - printk("AICS gain setting get\n"); -} - -static void aics_type_get(void) -{ - const uint8_t expected_input_type = BT_AICS_INPUT_TYPE_DIGITAL; - int err; - - /* Invalid behavior */ - err = bt_aics_type_get(NULL); - if (err == 0) { - FAIL("bt_aics_type_get with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Getting AICS input type\n"); - - err = bt_aics_type_get(vcp_included.aics[0]); - if (err != 0) { - FAIL("Could not get AICS input type (err %d)\n", err); - return; - } - - /* Expect and wait for input_type from init */ - WAIT_FOR_COND(expected_input_type == g_aics_input_type); - printk("AICS input type get\n"); -} - -static void aics_status_get(void) -{ - int err; - - /* Invalid behavior */ - err = bt_aics_status_get(NULL); - if (err == 0) { - FAIL("bt_aics_status_get with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Getting AICS status\n"); - g_cb = false; - - err = bt_aics_status_get(vcp_included.aics[0]); - if (err != 0) { - FAIL("Could not get AICS status (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_cb); - printk("AICS status get\n"); -} - -static void aics_get_description(void) -{ - int err; - - /* Invalid behavior */ - err = bt_aics_description_get(NULL); - if (err == 0) { - FAIL("bt_aics_description_get with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Getting AICS description\n"); - g_cb = false; - - err = bt_aics_description_get(vcp_included.aics[0]); - if (err != 0) { - FAIL("Could not get AICS description (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_cb); - printk("AICS description get\n"); -} - -static void test_aics_mute(void) -{ - const uint8_t expected_input_mute = BT_AICS_STATE_MUTED; - int err; - - /* Invalid behavior */ - err = bt_aics_mute(NULL); - if (err == 0) { - FAIL("bt_aics_mute with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Setting AICS mute\n"); - - err = bt_aics_mute(vcp_included.aics[0]); - if (err != 0) { - FAIL("Could not set AICS mute (err %d)\n", err); - return; - } - - WAIT_FOR_COND(expected_input_mute == g_aics_input_mute); - printk("AICS mute set\n"); -} - -static void test_aics_unmute(void) -{ - const uint8_t expected_input_mute = BT_AICS_STATE_UNMUTED; - int err; - - /* Invalid behavior */ - err = bt_aics_unmute(NULL); - if (err == 0) { - FAIL("bt_aics_unmute with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Setting AICS unmute\n"); - - err = bt_aics_unmute(vcp_included.aics[0]); - if (err != 0) { - FAIL("Could not set AICS unmute (err %d)\n", err); - return; - } - - WAIT_FOR_COND(expected_input_mute == g_aics_input_mute); - printk("AICS unmute set\n"); -} - -static void test_aics_automatic_gain_set(void) -{ - const uint8_t expected_mode = BT_AICS_MODE_AUTO; - int err; - - /* Invalid behavior */ - err = bt_aics_automatic_gain_set(NULL); - if (err == 0) { - FAIL("bt_aics_automatic_gain_set with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Setting AICS auto mode\n"); - - err = bt_aics_automatic_gain_set(vcp_included.aics[0]); - if (err != 0) { - FAIL("Could not set AICS auto mode (err %d)\n", err); - return; - } - - WAIT_FOR_COND(expected_mode == g_aics_mode); - printk("AICS auto mode set\n"); -} - -static void test_aics_manual_gain_set(void) -{ - const uint8_t expected_mode = BT_AICS_MODE_MANUAL; - int err; - - /* Invalid behavior */ - err = bt_aics_manual_gain_set(NULL); - if (err == 0) { - FAIL("bt_aics_manual_gain_set with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Setting AICS manual mode\n"); - - err = bt_aics_manual_gain_set(vcp_included.aics[0]); - if (err != 0) { - FAIL("Could not set AICS manual mode (err %d)\n", err); - return; - } - - WAIT_FOR_COND(expected_mode == g_aics_mode); - printk("AICS manual mode set\n"); -} - -static void test_aics_gain_set(void) -{ - const int8_t expected_gain = g_aics_gain_max - 1; - int err; - - /* Invalid behavior */ - err = bt_aics_gain_set(NULL, expected_gain); - if (err == 0) { - FAIL("bt_aics_gain_set with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Setting AICS gain\n"); - - err = bt_aics_gain_set(vcp_included.aics[0], expected_gain); - if (err != 0) { - FAIL("Could not set AICS gain (err %d)\n", err); - return; - } - - WAIT_FOR_COND(expected_gain == g_aics_gain); - printk("AICS gain set\n"); -} - -static void test_aics_description_set(void) -{ - const char *expected_aics_desc = "New Input Description"; - int err; - - /* Invalid behavior */ - err = bt_aics_description_set(NULL, expected_aics_desc); - if (err == 0) { - FAIL("bt_aics_description_set with NULL inst pointer did not fail"); - return; - } - - err = bt_aics_description_set(vcp_included.aics[0], NULL); - if (err == 0) { - FAIL("bt_aics_description_set with NULL description pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Setting AICS Description\n"); - g_cb = false; - - err = bt_aics_description_set(vcp_included.aics[0], expected_aics_desc); - if (err != 0) { - FAIL("Could not set AICS Description (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_cb && - strncmp(expected_aics_desc, g_aics_desc, strlen(expected_aics_desc)) == 0); - printk("AICS Description set\n"); -} - -static void test_aics_standalone(void) -{ - test_aics_deactivate(); - test_aics_activate(); - test_aics_state_get(); - aics_gain_setting_get(); - aics_type_get(); - aics_status_get(); - aics_get_description(); - test_aics_mute(); - test_aics_unmute(); - test_aics_automatic_gain_set(); - test_aics_manual_gain_set(); - test_aics_gain_set(); - test_aics_description_set(); -} - -static void test_vocs_state_get(void) -{ - int err; - - /* Invalid behavior */ - err = bt_vocs_state_get(NULL); - if (err == 0) { - FAIL("bt_vocs_state_get with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Getting VOCS state\n"); - g_cb = false; - - err = bt_vocs_state_get(vcp_included.vocs[0]); - if (err != 0) { - FAIL("Could not get VOCS state (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_cb); - printk("VOCS state get\n"); -} - -static void test_vocs_location_get(void) -{ - int err; - - /* Invalid behavior */ - err = bt_vocs_location_get(NULL); - if (err == 0) { - FAIL("bt_vocs_location_get with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Getting VOCS location\n"); - g_cb = false; - - err = bt_vocs_location_get(vcp_included.vocs[0]); - if (err != 0) { - FAIL("Could not get VOCS location (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_cb); - printk("VOCS location get\n"); -} - -static void test_vocs_description_get(void) -{ - int err; - - /* Invalid behavior */ - err = bt_vocs_description_get(NULL); - if (err == 0) { - FAIL("bt_vocs_description_get with NULL inst pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Getting VOCS description\n"); - g_cb = false; - - err = bt_vocs_description_get(vcp_included.vocs[0]); - if (err != 0) { - FAIL("Could not get VOCS description (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_cb); - printk("VOCS description get\n"); -} - -static void test_vocs_location_set(void) -{ - const uint32_t expected_location = g_vocs_location + 1; - uint32_t invalid_location; - int err; - - /* Invalid behavior */ - err = bt_vocs_location_set(NULL, expected_location); - if (err == 0) { - FAIL("bt_vocs_location_set with NULL inst pointer did not fail"); - return; - } - - invalid_location = BT_AUDIO_LOCATION_PROHIBITED; - - err = bt_vocs_location_set(vcp_included.vocs[0], invalid_location); - if (err == 0) { - FAIL("bt_vocs_location_set with location 0x%08X did not fail", invalid_location); - return; - } - - invalid_location = BT_AUDIO_LOCATION_ANY + 1; - - err = bt_vocs_location_set(vcp_included.vocs[0], invalid_location); - if (err == 0) { - FAIL("bt_vocs_location_set with location 0x%08X did not fail", invalid_location); - return; - } - - /* Valid behavior */ - printk("Setting VOCS location\n"); - - err = bt_vocs_location_set(vcp_included.vocs[0], expected_location); - if (err != 0) { - FAIL("Could not set VOCS location (err %d)\n", err); - return; - } - - WAIT_FOR_COND(expected_location == g_vocs_location); - printk("VOCS location set\n"); -} - -static void test_vocs_state_set(void) -{ - const int16_t expected_offset = g_vocs_offset + 1; - int16_t invalid_offset; - int err; - - /* Invalid behavior */ - err = bt_vocs_state_set(NULL, expected_offset); - if (err == 0) { - FAIL("bt_vocs_state_set with NULL inst pointer did not fail"); - return; - } - - invalid_offset = BT_VOCS_MIN_OFFSET - 1; - - err = bt_vocs_state_set(vcp_included.vocs[0], invalid_offset); - if (err == 0) { - FAIL("bt_vocs_state_set with NULL offset %d did not fail", invalid_offset); - return; - } - - invalid_offset = BT_VOCS_MAX_OFFSET + 1; - - err = bt_vocs_state_set(vcp_included.vocs[0], invalid_offset); - if (err == 0) { - FAIL("bt_vocs_state_set with NULL offset %d did not fail", invalid_offset); - return; - } - - /* Valid behavior */ - printk("Setting VOCS state\n"); - - err = bt_vocs_state_set(vcp_included.vocs[0], expected_offset); - if (err != 0) { - FAIL("Could not set VOCS state (err %d)\n", err); - return; - } - - WAIT_FOR_COND(expected_offset == g_vocs_offset); - printk("VOCS state set\n"); -} - -static void test_vocs_description_set(void) -{ - const char *expected_vocs_desc = "New Output Description"; - int err; - - /* Invalid behavior */ - err = bt_vocs_description_set(NULL, expected_vocs_desc); - if (err == 0) { - FAIL("bt_vocs_description_set with NULL inst pointer did not fail"); - return; - } - - err = bt_vocs_description_set(vcp_included.vocs[0], NULL); - if (err == 0) { - FAIL("bt_vocs_description_set with NULL description pointer did not fail"); - return; - } - - /* Valid behavior */ - printk("Setting VOCS description\n"); - g_cb = false; - - err = bt_vocs_description_set(vcp_included.vocs[0], expected_vocs_desc); - if (err != 0) { - FAIL("Could not set VOCS description (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_cb && - strncmp(expected_vocs_desc, g_vocs_desc, strlen(expected_vocs_desc)) == 0); - printk("VOCS description set\n"); -} - -static void test_vocs_standalone(void) -{ - test_vocs_state_get(); - test_vocs_location_get(); - test_vocs_description_get(); - test_vocs_location_set(); - test_vocs_state_set(); - test_vocs_description_set(); -} - -static void test_register(void) -{ - char output_desc[CONFIG_BT_VCP_VOL_REND_VOCS_INSTANCE_COUNT][16]; - char input_desc[CONFIG_BT_VCP_VOL_REND_AICS_INSTANCE_COUNT][16]; - struct bt_vcp_vol_rend_register_param vcp_register_param; - int err; - - memset(&vcp_register_param, 0, sizeof(vcp_register_param)); - - for (int i = 0; i < ARRAY_SIZE(vcp_register_param.vocs_param); i++) { - vcp_register_param.vocs_param[i].location_writable = true; - vcp_register_param.vocs_param[i].desc_writable = true; - snprintf(output_desc[i], sizeof(output_desc[i]), - "Output %d", i + 1); - vcp_register_param.vocs_param[i].output_desc = output_desc[i]; - vcp_register_param.vocs_param[i].cb = &vocs_cb; - } - - for (int i = 0; i < ARRAY_SIZE(vcp_register_param.aics_param); i++) { - vcp_register_param.aics_param[i].desc_writable = true; - snprintf(input_desc[i], sizeof(input_desc[i]), - "Input %d", i + 1); - vcp_register_param.aics_param[i].description = input_desc[i]; - vcp_register_param.aics_param[i].type = BT_AICS_INPUT_TYPE_DIGITAL; - vcp_register_param.aics_param[i].status = g_aics_active; - vcp_register_param.aics_param[i].gain_mode = BT_AICS_MODE_MANUAL; - vcp_register_param.aics_param[i].units = 1; - vcp_register_param.aics_param[i].min_gain = 0; - vcp_register_param.aics_param[i].max_gain = 100; - vcp_register_param.aics_param[i].cb = &aics_cb; - } - - vcp_register_param.step = 1; - vcp_register_param.mute = BT_VCP_STATE_UNMUTED; - vcp_register_param.volume = 100; - vcp_register_param.cb = &vcs_cb; - - /* Invalid behavior */ - err = bt_vcp_vol_rend_register(NULL); - if (err == 0) { - FAIL("bt_vcp_vol_rend_register with NULL pointer did not fail"); - return; - } - - /* Valid behavior */ - err = bt_vcp_vol_rend_register(&vcp_register_param); - if (err != 0) { - FAIL("VCP register failed (err %d)\n", err); - return; - } -} - -static void test_included_get(void) -{ - int err; - - /* Invalid behavior */ - err = bt_vcp_vol_rend_included_get(NULL); - if (err == 0) { - FAIL("bt_vcp_vol_rend_included_get with NULL pointer did not fail"); - return; - } - - /* Valid behavior */ - err = bt_vcp_vol_rend_included_get(&vcp_included); - if (err != 0) { - FAIL("VCP included get failed (err %d)\n", err); - return; - } -} - -static void test_set_step(uint8_t volume_step) -{ - int err; - - /* Invalid behavior */ - err = bt_vcp_vol_rend_set_step(0); - if (err == 0) { - FAIL("bt_vcp_vol_rend_set_step with step size 0 did not fail"); - return; - } - - /* Valid behavior */ - printk("Setting VCP step\n"); - - err = bt_vcp_vol_rend_set_step(volume_step); - if (err != 0) { - FAIL("VCP step set failed (err %d)\n", err); - return; - } - - printk("VCP step set\n"); -} - -static void test_get_state(void) -{ - int err; - - printk("Getting VCP volume state\n"); - g_cb = false; - - err = bt_vcp_vol_rend_get_state(); - if (err != 0) { - FAIL("Could not get VCP volume (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_cb); - printk("VCP volume get\n"); -} - -static void test_get_flags(void) -{ - int err; - - printk("Getting VCP flags\n"); - g_cb = false; - - err = bt_vcp_vol_rend_get_flags(); - if (err != 0) { - FAIL("Could not get VCP flags (err %d)\n", err); - return; - } - - WAIT_FOR_COND(g_cb); - printk("VCP flags get\n"); -} - -static void test_vol_down(uint8_t volume_step) -{ - const uint8_t expected_volume = g_volume > volume_step ? g_volume - volume_step : 0; - int err; - - printk("Downing VCP volume\n"); - - err = bt_vcp_vol_rend_vol_down(); - if (err != 0) { - FAIL("Could not get down VCP volume (err %d)\n", err); - return; - } - - WAIT_FOR_COND(expected_volume == g_volume); - printk("VCP volume downed\n"); -} - -static void test_vol_up(uint8_t volume_step) -{ - const uint8_t expected_volume = MIN((uint16_t)g_volume + volume_step, UINT8_MAX); - int err; - - printk("Upping VCP volume\n"); - - err = bt_vcp_vol_rend_vol_up(); - if (err != 0) { - FAIL("Could not up VCP volume (err %d)\n", err); - return; - } - - WAIT_FOR_COND(expected_volume == g_volume); - printk("VCP volume upped\n"); -} - -static void test_mute(void) -{ - const uint8_t expected_mute = BT_VCP_STATE_MUTED; - int err; - - printk("Muting VCP\n"); - - err = bt_vcp_vol_rend_mute(); - if (err != 0) { - FAIL("Could not mute VCP (err %d)\n", err); - return; - } - - WAIT_FOR_COND(expected_mute == g_mute); - printk("VCP muted\n"); -} - -static void test_unmute_vol_down(uint8_t volume_step) -{ - const uint8_t expected_volume = g_volume > volume_step ? g_volume - volume_step : 0; - const uint8_t expected_mute = BT_VCP_STATE_UNMUTED; - int err; - - printk("Downing and unmuting VCP\n"); - - err = bt_vcp_vol_rend_unmute_vol_down(); - if (err != 0) { - FAIL("Could not down and unmute VCP (err %d)\n", err); - return; - } - - WAIT_FOR_COND(expected_volume == g_volume && expected_mute == g_mute); - printk("VCP volume downed and unmuted\n"); -} - -static void test_unmute_vol_up(uint8_t volume_step) -{ - const uint8_t expected_volume = MIN((uint16_t)g_volume + volume_step, UINT8_MAX); - const uint8_t expected_mute = BT_VCP_STATE_UNMUTED; - int err; - - printk("Upping and unmuting VCP\n"); - - err = bt_vcp_vol_rend_unmute_vol_up(); - if (err != 0) { - FAIL("Could not up and unmute VCP (err %d)\n", err); - return; - } - - WAIT_FOR_COND(expected_volume == g_volume && expected_mute == g_mute); - printk("VCP volume upped and unmuted\n"); -} - -static void test_unmute(void) -{ - const uint8_t expected_mute = BT_VCP_STATE_UNMUTED; - int err; - - printk("Unmuting VCP\n"); - - err = bt_vcp_vol_rend_unmute(); - if (err != 0) { - FAIL("Could not unmute VCP (err %d)\n", err); - return; - } - - WAIT_FOR_COND(expected_mute == g_mute); - printk("VCP volume unmuted\n"); -} - -static void test_set_vol(void) -{ - const uint8_t expected_volume = g_volume - 5; /* any underflow is fine too */ - int err; - - err = bt_vcp_vol_rend_set_vol(expected_volume); - if (err != 0) { - FAIL("Could not set VCP volume (err %d)\n", err); - return; - } - - WAIT_FOR_COND(expected_volume == g_volume); - printk("VCP volume set\n"); -} - -static void test_standalone(void) -{ - const uint8_t volume_step = 5; - int err; - - err = bt_enable(NULL); - if (err != 0) { - FAIL("Bluetooth init failed (err %d)\n", err); - return; - } - - printk("Bluetooth initialized\n"); - - test_register(); - test_included_get(); - - printk("VCP initialized\n"); - test_set_step(volume_step); - test_get_state(); - test_get_flags(); - test_vol_down(volume_step); - test_vol_up(volume_step); - test_mute(); - test_unmute_vol_down(volume_step); - test_mute(); - test_unmute_vol_up(volume_step); - test_mute(); - test_unmute(); - test_set_vol(); - - if (CONFIG_BT_VCP_VOL_REND_VOCS_INSTANCE_COUNT > 0) { - test_vocs_standalone(); - } - - if (CONFIG_BT_VCP_VOL_REND_AICS_INSTANCE_COUNT > 0) { - test_aics_standalone(); - } - - PASS("VCP passed\n"); -} - -static void test_main(void) -{ - int err; - - err = bt_enable(NULL); - if (err != 0) { - FAIL("Bluetooth init failed (err %d)\n", err); - return; - } - - printk("Bluetooth initialized\n"); - - test_register(); - test_included_get(); - - printk("VCP initialized\n"); - - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, AD_SIZE, NULL, 0); - if (err != 0) { - FAIL("Advertising failed to start (err %d)\n", err); - return; - } - - printk("Advertising successfully started\n"); - - WAIT_FOR_COND(g_is_connected); - - PASS("VCP volume renderer passed\n"); -} - -static const struct bst_test_instance test_vcs[] = { - { - .test_id = "vcp_vol_rend_standalone", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_standalone - }, - { - .test_id = "vcp_vol_rend", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_vcp_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_vcs); -} -#else -struct bst_test_list *test_vcp_install(struct bst_test_list *tests) -{ - return tests; -} - -#endif /* CONFIG_BT_VCP_VOL_REND */ diff --git a/tests/bluetooth/bsim/audio/test_scripts/_cap.sh b/tests/bluetooth/bsim/audio/test_scripts/_cap.sh deleted file mode 100755 index b4ba35bb3fa..00000000000 --- a/tests/bluetooth/bsim/audio/test_scripts/_cap.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright (c) 2022 Nordic Semiconductor ASA -# -# SPDX-License-Identifier: Apache-2.0 - -dir_path=$(dirname "$0") - -$dir_path/cap_unicast.sh - -$dir_path/cap_broadcast.sh diff --git a/tests/bluetooth/bsim/audio/test_scripts/bap_bass.sh b/tests/bluetooth/bsim/audio/test_scripts/bap_bass.sh deleted file mode 100755 index a6130e08d35..00000000000 --- a/tests/bluetooth/bsim/audio/test_scripts/bap_bass.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright (c) 2020-2022 Nordic Semiconductor ASA -# -# SPDX-License-Identifier: Apache-2.0 - -SIMULATION_ID="bass" -VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 20 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -printf "\n\n======== Running BASS and BASS client test =========\n\n" - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=bap_scan_delegator \ - -rs=24 - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 \ - -testid=bap_broadcast_assistant -rs=46 - - Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=2 -testid=bass_broadcaster -rs=69 - -# Simulation time should be larger than the WAIT_TIME in common.h -Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -D=3 \ - -sim_length=60e6 $@ - -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -exit $EXIT_CODE #the last exit code != 0 diff --git a/tests/bluetooth/bsim/audio/test_scripts/bap_broadcast_audio.sh b/tests/bluetooth/bsim/audio/test_scripts/bap_broadcast_audio.sh deleted file mode 100755 index 2a4aa16ea5c..00000000000 --- a/tests/bluetooth/bsim/audio/test_scripts/bap_broadcast_audio.sh +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright (c) 2021 Nordic Semiconductor ASA -# -# SPDX-License-Identifier: Apache-2.0 - -VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 20 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -printf "\n\n======== Broadcaster test =========\n\n" - -SIMULATION_ID="broadcaster" - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=broadcast_source -rs=23 - - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=broadcast_sink -rs=27 - -# Simulation time should be larger than the WAIT_TIME in common.h -Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ - -D=2 -sim_length=60e6 $@ - -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -printf "\n\n======== Broadcaster sink disconnect test =========\n\n" - -SIMULATION_ID="broadcaster_sink_disconnect" - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=broadcast_source -rs=23 - - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 \ - -testid=broadcast_sink_disconnect -rs=27 - -# Simulation time should be larger than the WAIT_TIME in common.h -Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ - -D=2 -sim_length=60e6 $@ - -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -exit $EXIT_CODE #the last exit code != 0 diff --git a/tests/bluetooth/bsim/audio/test_scripts/bap_unicast_audio.sh b/tests/bluetooth/bsim/audio/test_scripts/bap_unicast_audio.sh deleted file mode 100755 index a1e34d1826d..00000000000 --- a/tests/bluetooth/bsim/audio/test_scripts/bap_unicast_audio.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright (c) 2021-2022 Nordic Semiconductor ASA -# -# SPDX-License-Identifier: Apache-2.0 - -SIMULATION_ID="unicast_audio" -VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 20 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -printf "\n\n======== Unicast Audio test =========\n\n" - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=unicast_client -rs=23 - - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=unicast_server -rs=27 - -# Simulation time should be larger than the WAIT_TIME in common.h -Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ - -D=2 -sim_length=60e6 $@ - -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -exit $EXIT_CODE #the last exit code != 0 diff --git a/tests/bluetooth/bsim/audio/test_scripts/cap_broadcast.sh b/tests/bluetooth/bsim/audio/test_scripts/cap_broadcast.sh deleted file mode 100755 index bf130c1d7c9..00000000000 --- a/tests/bluetooth/bsim/audio/test_scripts/cap_broadcast.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright (c) 2022 Nordic Semiconductor ASA -# -# SPDX-License-Identifier: Apache-2.0 - -SIMULATION_ID="cap_broadcast" -VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 20 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -printf "\n\n======== Running CAP broadcast test =========\n\n" - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=cap_acceptor_broadcast -rs=23 - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=cap_initiator_broadcast -rs=46 - -# Simulation time should be larger than the WAIT_TIME in common.h -Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ - -D=2 -sim_length=60e6 $@ - -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -exit $EXIT_CODE #the last exit code != 0 diff --git a/tests/bluetooth/bsim/audio/test_scripts/cap_unicast.sh b/tests/bluetooth/bsim/audio/test_scripts/cap_unicast.sh deleted file mode 100755 index d8b11220a77..00000000000 --- a/tests/bluetooth/bsim/audio/test_scripts/cap_unicast.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright (c) 2022 Nordic Semiconductor ASA -# -# SPDX-License-Identifier: Apache-2.0 - -SIMULATION_ID="cap_unicast" -VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 20 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -printf "\n\n======== Running CAP unicast test =========\n\n" - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=cap_acceptor_unicast -rs=23 - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=cap_initiator_unicast -rs=46 - -# Simulation time should be larger than the WAIT_TIME in common.h -Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ - -D=2 -sim_length=60e6 $@ - -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -exit $EXIT_CODE #the last exit code != 0 diff --git a/tests/bluetooth/bsim/audio/test_scripts/csip.sh b/tests/bluetooth/bsim/audio/test_scripts/csip.sh deleted file mode 100755 index 49487010952..00000000000 --- a/tests/bluetooth/bsim/audio/test_scripts/csip.sh +++ /dev/null @@ -1,117 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright (c) 2020-2022 Nordic Semiconductor ASA -# -# SPDX-License-Identifier: Apache-2.0 - -# Basic CSIP test. A set coordinator connects to multiple set members -# lock thems, unlocks them and disconnects. - -VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 20 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -# NORMAL TEST -printf "\n\n======== Running normal test ========\n\n" - -SIMULATION_ID="csip" - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=csip_set_coordinator \ - -RealEncryption=1 -rs=1 - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=csip_set_member \ - -RealEncryption=1 -rs=2 -argstest rank 1 - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=2 -testid=csip_set_member \ - -RealEncryption=1 -rs=3 -argstest rank 2 - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=3 -testid=csip_set_member \ - -RealEncryption=1 -rs=4 -argstest rank 3 - -# Simulation time should be larger than the WAIT_TIME in common.h -Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ - -D=4 -sim_length=60e6 $@ - -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -PROCESS_IDS=""; - -# TEST WITH FORCE RELEASE - -SIMULATION_ID="csip_forced_release" - -printf "\n\n======== Running test with forced release of lock ========\n\n" -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=csip_set_coordinator \ - -RealEncryption=1 -rs=1 - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=csip_set_member \ - -RealEncryption=1 -rs=2 -argstest rank 1 - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=2 -testid=csip_set_member \ - -RealEncryption=1 -rs=3 -argstest rank 2 - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=3 -testid=csip_set_member_release \ - -RealEncryption=1 -rs=4 -argstest rank 3 - -# Simulation time should be larger than the WAIT_TIME in common.h -Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ - -D=4 -sim_length=60e6 $@ - -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -# TEST WITH SIRK ENC - -SIMULATION_ID="csip_sirk_encrypted" - -printf "\n\n======== Running test with SIRK encrypted ========\n\n" -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=csip_set_coordinator \ - -RealEncryption=1 -rs=1 - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=csip_set_member_enc \ - -RealEncryption=1 -rs=2 -argstest rank 1 - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=2 -testid=csip_set_member_enc \ - -RealEncryption=1 -rs=3 -argstest rank 2 - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=3 -testid=csip_set_member_enc \ - -RealEncryption=1 -rs=4 -argstest rank 3 - -# Simulation time should be larger than the WAIT_TIME in common.h -Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ - -D=4 -sim_length=60e6 $@ - -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done -exit $EXIT_CODE #the last exit code != 0 diff --git a/tests/bluetooth/bsim/audio/test_scripts/has.sh b/tests/bluetooth/bsim/audio/test_scripts/has.sh deleted file mode 100755 index 65fadd1e175..00000000000 --- a/tests/bluetooth/bsim/audio/test_scripts/has.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright (c) 2022 Codecoup -# -# SPDX-License-Identifier: Apache-2.0 - -SIMULATION_ID="has" -VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 20 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -printf "\n\n======== Running HAS main (API) test =========\n\n" - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=has -rs=24 - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=has_client -rs=46 - -Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ - -D=2 -sim_length=60e6 $@ - -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -exit $EXIT_CODE #the last exit code != 0 diff --git a/tests/bluetooth/bsim/audio/test_scripts/ias.sh b/tests/bluetooth/bsim/audio/test_scripts/ias.sh deleted file mode 100755 index a3df49073b4..00000000000 --- a/tests/bluetooth/bsim/audio/test_scripts/ias.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright (c) 2022 Codecoup -# -# SPDX-License-Identifier: Apache-2.0 - -SIMULATION_ID="ias" -VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 20 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -printf "\n\n======== Running IAS main (API) test =========\n\n" - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=ias -rs=23 - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=ias_client -rs=6 - -# Simulation time should be larger than the WAIT_TIME in common.h -Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ - -D=2 -sim_length=60e6 $@ - -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -exit $EXIT_CODE #the last exit code != 0 diff --git a/tests/bluetooth/bsim/audio/test_scripts/mcs_mcc.sh b/tests/bluetooth/bsim/audio/test_scripts/mcs_mcc.sh deleted file mode 100755 index 35146c77473..00000000000 --- a/tests/bluetooth/bsim/audio/test_scripts/mcs_mcc.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright (c) 2020 Nordic Semiconductor ASA -# -# SPDX-License-Identifier: Apache-2.0 - -SIMULATION_ID="mcs_mcc" -VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 20 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -printf "\n\n======== Running MCS and MCC test =========\n\n" - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=mcc -rs=46 - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=mcs -rs=23 - -# Simulation time should be larger than the WAIT_TIME in common.h -Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ - -D=2 -sim_length=60e6 $@ - -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -exit $EXIT_CODE #the last exit code != 0 diff --git a/tests/bluetooth/bsim/audio/test_scripts/media_controller.sh b/tests/bluetooth/bsim/audio/test_scripts/media_controller.sh deleted file mode 100755 index a88d6bfda8a..00000000000 --- a/tests/bluetooth/bsim/audio/test_scripts/media_controller.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright (c) 2021 Nordic Semiconductor ASA -# -# SPDX-License-Identifier: Apache-2.0 - -SIMULATION_ID="media_controller" -VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 20 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -printf "\n\n======== Running media controller local_player test =========\n\n" - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=media_controller_local_player -rs=23 - -# Simulation time should be larger than the WAIT_TIME in common.h -Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ - -D=1 -sim_length=60e6 $@ - -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -printf "\n\n======== Running media controller remote_player test =========\n\n" - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=media_controller_remote_player -rs=46 - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=media_controller_server -rs=23 - -# Simulation time should be larger than the WAIT_TIME in common.h -Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ - -D=2 -sim_length=60e6 $@ - -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -exit $EXIT_CODE #the last exit code != 0 diff --git a/tests/bluetooth/bsim/audio/test_scripts/micp.sh b/tests/bluetooth/bsim/audio/test_scripts/micp.sh deleted file mode 100755 index 562dbe4439c..00000000000 --- a/tests/bluetooth/bsim/audio/test_scripts/micp.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright (c) 2020-2022 Nordic Semiconductor ASA -# -# SPDX-License-Identifier: Apache-2.0 - -SIMULATION_ID="micp" -VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 20 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -printf "\n\n==== Running MICP Microphone Device Only (API) test ====n\n" - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=micp_mic_dev_only -rs=23 - -# Simulation time should be larger than the WAIT_TIME in common.h -Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ - -D=1 -sim_length=60e6 $@ - -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -printf "\n\n==== Running MICP Microphone Device and MICP Microphone Controller test ====n\n" - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=micp_mic_dev -rs=23 - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=micp_mic_ctlr -rs=46 - -# Simulation time should be larger than the WAIT_TIME in common.h -Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ - -D=2 -sim_length=60e6 $@ - -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -exit $EXIT_CODE #the last exit code != 0 diff --git a/tests/bluetooth/bsim/audio/test_scripts/tbs.sh b/tests/bluetooth/bsim/audio/test_scripts/tbs.sh deleted file mode 100755 index cb73fb0f039..00000000000 --- a/tests/bluetooth/bsim/audio/test_scripts/tbs.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright (c) 2019 Bose Corporation -# Copyright (c) 2021 Nordic Semiconductor ASA -# -# SPDX-License-Identifier: Apache-2.0 - -SIMULATION_ID="tbs_ccp" -VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 20 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=tbs -rs=23 - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=tbs_client -rs=6 - -# Simulation time should be larger than the WAIT_TIME in common.h -Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ - -D=2 -sim_length=60e6 $@ - -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done -exit $EXIT_CODE #the last exit code != 0 diff --git a/tests/bluetooth/bsim/audio/test_scripts/vcp.sh b/tests/bluetooth/bsim/audio/test_scripts/vcp.sh deleted file mode 100755 index fb170d911db..00000000000 --- a/tests/bluetooth/bsim/audio/test_scripts/vcp.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright (c) 2020-2021 Nordic Semiconductor ASA -# -# SPDX-License-Identifier: Apache-2.0 - -SIMULATION_ID="vcp" -VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 20 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -printf "\n\n======== Running VCP Volume Renderer standalone (API) test =========\n\n" - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=vcp_vol_rend_standalone -rs=23 - -# Simulation time should be larger than the WAIT_TIME in common.h -Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ - -D=1 -sim_length=60e6 $@ - -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -printf "\n\n======== Running VCP Volume Renderer and VCP Volume Controller test =========\n\n" - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=0 -testid=vcp_vol_rend -rs=23 - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_audio_prj_conf \ - -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} -d=1 -testid=vcp_vol_ctlr -rs=46 - -# Simulation time should be larger than the WAIT_TIME in common.h -Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ - -D=2 -sim_length=60e6 $@ - -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done - -exit $EXIT_CODE #the last exit code != 0 diff --git a/tests/bluetooth/bsim/compile.sh b/tests/bluetooth/bsim/compile.sh deleted file mode 100755 index 858138a5659..00000000000 --- a/tests/bluetooth/bsim/compile.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2018 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -# Compile all the applications needed by the bsim tests - -#set -x #uncomment this line for debugging -set -ue - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" -: "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" -: "${ZEPHYR_BASE:?ZEPHYR_BASE must be set to point to the zephyr root\ - directory}" - -WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_out}" -BOARD="${BOARD:-nrf52_bsim}" -BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" - -mkdir -p ${WORK_DIR} - -source ${ZEPHYR_BASE}/tests/bluetooth/bsim/sh_common.source - -run_in_background ${ZEPHYR_BASE}/tests/bluetooth/bsim/audio/compile.sh -run_in_background ${ZEPHYR_BASE}/tests/bluetooth/bsim/host/compile.sh -run_in_background ${ZEPHYR_BASE}/tests/bluetooth/bsim/ll/compile.sh -run_in_background ${ZEPHYR_BASE}/tests/bluetooth/bsim/mesh/compile.sh - -wait_for_background_jobs diff --git a/tests/bluetooth/bsim/compile.source b/tests/bluetooth/bsim/compile.source deleted file mode 100644 index 0107f713517..00000000000 --- a/tests/bluetooth/bsim/compile.source +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright 2018 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -source ${ZEPHYR_BASE}/tests/bluetooth/bsim/sh_common.source - -function print_error_info(){ - echo -e "\033[0;31mFailure building ${app} ${conf_file} for ${BOARD}\033[0m\n\ - You can rebuild it with\n\ - ${cmake_cmd[@]} && ninja ${ninja_args}" -} - -function _compile(){ - : "${app:?app must be defined}" - - local app_root="${app_root:-${ZEPHYR_BASE}}" - local conf_file="${conf_file:-prj.conf}" - local conf_overlay="${conf_overlay:-""}" - - local cmake_args="${cmake_args:-"-DCONFIG_COVERAGE=y \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=ON"}" - local ninja_args="${ninja_args:-""}" - local cc_flags="${cc_flags:-"-Werror"}" - - if [ "${conf_overlay}" ]; then - local exe_name="${exe_name:-bs_${BOARD}_${app}_${conf_file}_${conf_overlay}}" - else - local exe_name="${exe_name:-bs_${BOARD}_${app}_${conf_file}}" - fi - - local exe_name=${exe_name//\//_} - local exe_name=${exe_name//./_} - local exe_name=${BSIM_OUT_PATH}/bin/$exe_name - local map_file_name=${exe_name}.Tsymbols - - if [ "${conf_overlay}" ]; then - local this_dir=${WORK_DIR}/${app}/${conf_file}_${conf_overlay} - else - local this_dir=${WORK_DIR}/${app}/${conf_file} - fi - - local modules_arg="${ZEPHYR_MODULES:+-DZEPHYR_MODULES=${ZEPHYR_MODULES}}" - - echo "Building $exe_name" - - local ret=0 - - local cmake_cmd=(cmake -GNinja -DBOARD_ROOT=${BOARD_ROOT} -DBOARD=${BOARD} \ - -DCONF_FILE=${conf_file} -DOVERLAY_CONFIG=${conf_overlay} \ - ${modules_arg} \ - ${cmake_args} -DCMAKE_C_FLAGS=\"${cc_flags}\" ${app_root}/${app}) - - # Set INCR_BUILD when calling to only do an incremental build - if [ ! -v INCR_BUILD ] || [ ! -d "${this_dir}" ]; then - [ -d "${this_dir}" ] && rm ${this_dir} -rf - mkdir -p ${this_dir} && cd ${this_dir} - ${cmake_cmd[@]} &> cmake.out || \ - { ret="$?"; print_error_info ; cat cmake.out && return $ret; } - else - cd ${this_dir} - fi - ninja ${ninja_args} &> ninja.out || \ - { ret="$?"; print_error_info ; cat ninja.out && return $ret; } - cp ${this_dir}/zephyr/zephyr.exe ${exe_name} - - nm ${exe_name} | grep -v " [U|w] " | sort | cut -d" " -f1,3 > ${map_file_name} - sed -i "1i $(wc -l ${map_file_name} | cut -d" " -f1)" ${map_file_name} -} - -function compile(){ - run_in_background _compile -} diff --git a/tests/bluetooth/bsim/host/adv/chain/CMakeLists.txt b/tests/bluetooth/bsim/host/adv/chain/CMakeLists.txt deleted file mode 100644 index 23cae985fb5..00000000000 --- a/tests/bluetooth/bsim/host/adv/chain/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set \ - the environment variable BSIM_COMPONENTS_PATH to point to its \ - components folder. More information can be found in \ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_adv_chain) - -target_sources(app PRIVATE - src/main.c - ${ZEPHYR_BASE}/samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c - ${ZEPHYR_BASE}/samples/bluetooth/observer/src/observer.c -) - -zephyr_include_directories( - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ -) diff --git a/tests/bluetooth/bsim/host/adv/chain/prj.conf b/tests/bluetooth/bsim/host/adv/chain/prj.conf deleted file mode 100644 index 3e7f11009c2..00000000000 --- a/tests/bluetooth/bsim/host/adv/chain/prj.conf +++ /dev/null @@ -1,39 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_BROADCASTER=y -CONFIG_BT_OBSERVER=y -CONFIG_BT_EXT_ADV=y -CONFIG_BT_EXT_ADV_MAX_ADV_SET=2 -CONFIG_BT_DEVICE_NAME="Broadcaster Multiple" - -# Enable Advertising Data chaining in Zephyr Bluetooth LE Controller -CONFIG_BT_CTLR_ADVANCED_FEATURES=y -CONFIG_BT_CTLR_ADV_DATA_CHAIN=y - -# Zephyr Bluetooth LE Controller will need to use chain PDUs when AD data -# length > 191 bytes -# - 31 bytes will use 22 bytes for the default name in this sample plus 9 bytes -# for manufacturer data -# - 191 bytes will use 22 bytes for the default name in this sample plus 169 -# bytes for manufacturer data -# - 277 bytes will use 22 bytes for the default name in this sample plus 255 -# bytes for manufacturer data -CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=1650 - -# Increase Advertising PDU buffers to number of advertising sets times the -# number of chain PDUs per advertising set when using Zephyr Bluetooth LE -# Controller -CONFIG_BT_CTLR_ADV_DATA_BUF_MAX=2 - -# Maximum Extended Scanning buffer size -CONFIG_BT_EXT_SCAN_BUF_SIZE=1650 - -# Set maximum scan data length for Extended Scanning in Bluetooth LE Controller -CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=1650 - -# Zephyr Bluetooth LE Controller needs 16 event buffers to generate Extended -# Advertising Report for receiving the complete 1650 bytes of data -CONFIG_BT_BUF_EVT_RX_COUNT=16 - -# Increase Zephyr Bluetooth LE Controller Rx buffer to receive complete chain -# of PDUs -CONFIG_BT_CTLR_RX_BUFFERS=9 diff --git a/tests/bluetooth/bsim/host/adv/chain/src/main.c b/tests/bluetooth/bsim/host/adv/chain/src/main.c deleted file mode 100644 index feb3c255d5e..00000000000 --- a/tests/bluetooth/bsim/host/adv/chain/src/main.c +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include - -#include -#include - -#include -#include - -#include "bs_types.h" -#include "bs_tracing.h" -#include "time_machine.h" -#include "bstests.h" - -#define FAIL(...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, __VA_ARGS__); \ - } while (0) - -#define NAME_LEN 30 -#define BT_AD_DATA_NAME_SIZE (sizeof(CONFIG_BT_DEVICE_NAME) - 1U + 2U) -#define BT_AD_DATA_MFG_DATA_SIZE (254U + 2U) -#define DATA_LEN MIN((BT_AD_DATA_NAME_SIZE + \ - BT_AD_DATA_MFG_DATA_SIZE), \ - CONFIG_BT_CTLR_ADV_DATA_LEN_MAX) - -static K_SEM_DEFINE(sem_recv, 0, 1); - -extern enum bst_result_t bst_result; - -static void test_adv_main(void) -{ - extern int broadcaster_multiple(void); - int err; - - err = broadcaster_multiple(); - if (err) { - FAIL("Adv tests failed\n"); - bs_trace_silent_exit(err); - return; - } - - /* Successfully started advertising multiple sets */ - PASS("Adv tests passed\n"); - - /* Let the scanner receive the reports */ - k_sleep(K_SECONDS(10)); -} - -static bool data_cb(struct bt_data *data, void *user_data) -{ - char *name = user_data; - uint8_t len; - - switch (data->type) { - case BT_DATA_NAME_SHORTENED: - case BT_DATA_NAME_COMPLETE: - len = MIN(data->data_len, NAME_LEN - 1); - (void)memcpy(name, data->data, len); - name[len] = '\0'; - return false; - default: - return true; - } -} - -static void scan_recv(const struct bt_le_scan_recv_info *info, - struct net_buf_simple *buf) -{ - static uint8_t sid[CONFIG_BT_EXT_ADV_MAX_ADV_SET]; - static uint8_t sid_count; - char name[NAME_LEN]; - uint8_t data_status; - uint16_t data_len; - - data_status = BT_HCI_LE_ADV_EVT_TYPE_DATA_STATUS(info->adv_props); - if (data_status) { - return; - } - - data_len = buf->len; - if (data_len != DATA_LEN) { - return; - } - - (void)memset(name, 0, sizeof(name)); - bt_data_parse(buf, data_cb, name); - - if (strcmp(name, CONFIG_BT_DEVICE_NAME)) { - return; - } - - for (uint8_t i = 0; i < sid_count; i++) { - if (sid[i] == info->sid) { - return; - } - } - - sid[sid_count++] = info->sid; - - if (sid_count < CONFIG_BT_EXT_ADV_MAX_ADV_SET) { - return; - } - - k_sem_give(&sem_recv); -} - -static struct bt_le_scan_cb scan_callbacks = { - .recv = scan_recv, -}; - -static void test_scan_main(void) -{ - extern int observer_start(void); - int err; - - err = bt_enable(NULL); - if (err) { - FAIL("Bluetooth init failed\n"); - - bs_trace_silent_exit(err); - return; - } - - bt_le_scan_cb_register(&scan_callbacks); - - err = observer_start(); - if (err) { - FAIL("Observer start failed\n"); - - bs_trace_silent_exit(err); - return; - } - - /* Let the recv callback verify the reports */ - k_sleep(K_SECONDS(10)); - - err = k_sem_take(&sem_recv, K_NO_WAIT); - if (err) { - FAIL("Scan receive failed\n"); - - bs_trace_silent_exit(err); - return; - } - - PASS("Scan tests passed\n"); - - bs_trace_silent_exit(0); -} - -static void test_adv_chain_init(void) -{ - bst_ticker_set_next_tick_absolute(60e6); - bst_result = In_progress; -} - -static void test_adv_chain_tick(bs_time_t HW_device_time) -{ - bst_result = Failed; - bs_trace_error_line("Test GATT Write finished.\n"); -} - -static const struct bst_test_instance test_def[] = { - { - .test_id = "adv", - .test_descr = "Central GATT Write", - .test_post_init_f = test_adv_chain_init, - .test_tick_f = test_adv_chain_tick, - .test_main_f = test_adv_main - }, - { - .test_id = "scan", - .test_descr = "Peripheral GATT Write", - .test_post_init_f = test_adv_chain_init, - .test_tick_f = test_adv_chain_tick, - .test_main_f = test_scan_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_adv_chain_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_def); -} - -bst_test_install_t test_installers[] = { - test_adv_chain_install, - NULL -}; - -void main(void) -{ - bst_main(); -} diff --git a/tests/bluetooth/bsim/host/adv/chain/tests_scripts/adv_chain.sh b/tests/bluetooth/bsim/host/adv/chain/tests_scripts/adv_chain.sh deleted file mode 100755 index 0ce63588fa5..00000000000 --- a/tests/bluetooth/bsim/host/adv/chain/tests_scripts/adv_chain.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2018 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -# Validate Extended Advertising AD Data fragment operation, PDU chaining and -# Extended Scanning of chain PDUs -simulation_id="adv_chain" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 10 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_adv_chain_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=adv - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_adv_chain_prj_conf\ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=scan - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=10e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/adv/periodic/CMakeLists.txt b/tests/bluetooth/bsim/host/adv/periodic/CMakeLists.txt deleted file mode 100644 index 096da439287..00000000000 --- a/tests/bluetooth/bsim/host/adv/periodic/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set\ - the environment variable BSIM_COMPONENTS_PATH to point to its components \ - folder. More information can be found in\ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_audio) - -target_sources(app PRIVATE - src/common.c - src/main.c - src/per_adv_advertiser.c - src/per_adv_syncer.c -) - -zephyr_include_directories( - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ - ${ZEPHYR_BASE}/subsys/bluetooth/host/audio/ -) diff --git a/tests/bluetooth/bsim/host/adv/periodic/prj.conf b/tests/bluetooth/bsim/host/adv/periodic/prj.conf deleted file mode 100644 index 22d11f7afbb..00000000000 --- a/tests/bluetooth/bsim/host/adv/periodic/prj.conf +++ /dev/null @@ -1,14 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_DEVICE_NAME="test_per_adv" -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_SMP=y -CONFIG_BT_PRIVACY=y - -CONFIG_BT_EXT_ADV=y -CONFIG_BT_EXT_ADV_MAX_ADV_SET=2 -CONFIG_BT_CTLR_ADVANCED_FEATURES=y -CONFIG_BT_CTLR_ADV_AUX_SET=2 -CONFIG_BT_CTLR_ADV_DATA_BUF_MAX=2 -CONFIG_BT_PER_ADV=y -CONFIG_BT_PER_ADV_SYNC=y diff --git a/tests/bluetooth/bsim/host/adv/periodic/prj_long_data.conf b/tests/bluetooth/bsim/host/adv/periodic/prj_long_data.conf deleted file mode 100644 index 44898952657..00000000000 --- a/tests/bluetooth/bsim/host/adv/periodic/prj_long_data.conf +++ /dev/null @@ -1,21 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_DEVICE_NAME="test_per_adv" -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_SMP=y -CONFIG_BT_PRIVACY=y - -CONFIG_BT_EXT_ADV=y -CONFIG_BT_EXT_ADV_MAX_ADV_SET=2 -CONFIG_BT_CTLR_ADVANCED_FEATURES=y -CONFIG_BT_CTLR_ADV_AUX_SET=2 -CONFIG_BT_CTLR_ADV_DATA_BUF_MAX=2 -CONFIG_BT_CTLR_ADV_AUX_PDU_BACK2BACK=y -CONFIG_BT_CTLR_ADV_SYNC_PDU_BACK2BACK=y -CONFIG_BT_PER_ADV=y -CONFIG_BT_PER_ADV_SYNC=y -CONFIG_BT_PER_ADV_SYNC_BUF_SIZE=1650 - -CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=1650 -CONFIG_BT_CTLR_ADV_DATA_CHAIN=y -CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=1650 diff --git a/tests/bluetooth/bsim/host/adv/periodic/src/common.c b/tests/bluetooth/bsim/host/adv/periodic/src/common.c deleted file mode 100644 index b4e4151c49a..00000000000 --- a/tests/bluetooth/bsim/host/adv/periodic/src/common.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "common.h" - -extern enum bst_result_t bst_result; - -void test_tick(bs_time_t HW_device_time) -{ - if (bst_result != Passed) { - FAIL("test failed (not passed after %i seconds)\n", WAIT_SECONDS); - } -} - -void test_init(void) -{ - bst_ticker_set_next_tick_absolute(WAIT_TIME); - bst_result = In_progress; -} - -uint8_t mfg_data[254] = { - 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, - 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, - 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, - 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, - 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, - 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, - 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, - 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, - 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, - 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, 0xA0, 0xA1, 0xA2, - 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, - 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, 0xC0, - 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, - 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, - 0xDF, 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, - 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB}; diff --git a/tests/bluetooth/bsim/host/adv/periodic/src/common.h b/tests/bluetooth/bsim/host/adv/periodic/src/common.h deleted file mode 100644 index b5bc9583ebd..00000000000 --- a/tests/bluetooth/bsim/host/adv/periodic/src/common.h +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Common functions and helpers - * - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef ZEPHYR_TEST_BSIM_BT_AUDIO_TEST_ -#define ZEPHYR_TEST_BSIM_BT_AUDIO_TEST_ - -#include - -#include "bs_types.h" -#include "bs_tracing.h" -#include "time_machine.h" -#include "bstests.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#define WAIT_SECONDS 30 /* seconds */ -#define WAIT_TIME (WAIT_SECONDS * USEC_PER_SEC) /* microseconds*/ - -#define CREATE_FLAG(flag) static atomic_t flag = (atomic_t)false -#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)true) -#define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)false) -#define TEST_FLAG(flag) (atomic_get(&flag) == (atomic_t)true) -#define WAIT_FOR_FLAG(flag) \ - while (!(bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } - -#define FAIL(...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, "PASSED: " __VA_ARGS__); \ - } while (0) - -void test_tick(bs_time_t HW_device_time); -void test_init(void); - -extern uint8_t mfg_data[254]; - -#endif /* ZEPHYR_TEST_BSIM_BT_AUDIO_TEST_ */ diff --git a/tests/bluetooth/bsim/host/adv/periodic/src/main.c b/tests/bluetooth/bsim/host/adv/periodic/src/main.c deleted file mode 100644 index 7b46cc06561..00000000000 --- a/tests/bluetooth/bsim/host/adv/periodic/src/main.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bstests.h" - -extern struct bst_test_list *test_per_adv_syncer(struct bst_test_list *tests); -extern struct bst_test_list *test_per_adv_advertiser(struct bst_test_list *tests); - -bst_test_install_t test_installers[] = { - test_per_adv_syncer, - test_per_adv_advertiser, - NULL -}; - -void main(void) -{ - bst_main(); -} diff --git a/tests/bluetooth/bsim/host/adv/periodic/src/per_adv_advertiser.c b/tests/bluetooth/bsim/host/adv/periodic/src/per_adv_advertiser.c deleted file mode 100644 index caf006a360b..00000000000 --- a/tests/bluetooth/bsim/host/adv/periodic/src/per_adv_advertiser.c +++ /dev/null @@ -1,362 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include - -#include "bs_types.h" -#include "bs_tracing.h" -#include "time_machine.h" -#include "bstests.h" - -#include -#include - -#include - -#include "common.h" - -extern enum bst_result_t bst_result; - -static struct bt_conn *g_conn; - -CREATE_FLAG(flag_connected); -CREATE_FLAG(flag_bonded); - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != BT_HCI_ERR_SUCCESS) { - FAIL("Failed to connect to %s: %u\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - g_conn = bt_conn_ref(conn); - SET_FLAG(flag_connected); -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - printk("Disconnected: %s (reason %u)\n", addr, reason); - - bt_conn_unref(g_conn); - g_conn = NULL; -} - -static struct bt_conn_cb conn_cbs = { - .connected = connected, - .disconnected = disconnected, -}; - -static void pairing_complete_cb(struct bt_conn *conn, bool bonded) -{ - if (conn == g_conn && bonded) { - SET_FLAG(flag_bonded); - } -} - -static struct bt_conn_auth_info_cb auto_info_cbs = { - .pairing_complete = pairing_complete_cb, -}; - -static void common_init(void) -{ - int err; - - err = bt_enable(NULL); - - if (err) { - FAIL("Bluetooth init failed: %d\n", err); - return; - } - printk("Bluetooth initialized\n"); - - bt_conn_cb_register(&conn_cbs); - bt_conn_auth_info_cb_register(&auto_info_cbs); -} - -static void create_per_adv_set(struct bt_le_ext_adv **adv) -{ - int err; - - printk("Creating extended advertising set..."); - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_NCONN_NAME, NULL, adv); - if (err) { - printk("Failed to create advertising set: %d\n", err); - return; - } - printk("done.\n"); - - printk("Setting periodic advertising parameters..."); - err = bt_le_per_adv_set_param(*adv, BT_LE_PER_ADV_DEFAULT); - if (err) { - printk("Failed to set periodic advertising parameters: %d\n", - err); - return; - } - printk("done.\n"); -} - -static void create_conn_adv_set(struct bt_le_ext_adv **adv) -{ - int err; - - printk("Creating connectable extended advertising set..."); - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CONN_NAME, NULL, adv); - if (err) { - printk("Failed to create advertising set: %d\n", err); - return; - } - printk("done.\n"); -} - -static void start_ext_adv_set(struct bt_le_ext_adv *adv) -{ - int err; - - printk("Starting Extended Advertising..."); - err = bt_le_ext_adv_start(adv, BT_LE_EXT_ADV_START_DEFAULT); - if (err) { - printk("Failed to start extended advertising: %d\n", err); - return; - } - printk("done.\n"); -} - -static void start_per_adv_set(struct bt_le_ext_adv *adv) -{ - int err; - - printk("Starting periodic advertising..."); - err = bt_le_per_adv_start(adv); - if (err) { - printk("Failed to start periodic advertising: %d\n", err); - return; - } - printk("done.\n"); -} - -#if (CONFIG_BT_CTLR_ADV_DATA_CHAIN) -static void set_per_adv_data(struct bt_le_ext_adv *adv) -{ - int err; - const struct bt_data ad[] = { - BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, ARRAY_SIZE(mfg_data)), - BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, ARRAY_SIZE(mfg_data))}; - - printk("Setting Periodic Advertising Data..."); - err = bt_le_per_adv_set_data(adv, ad, ARRAY_SIZE(ad)); - if (err) { - printk("Failed to set periodic advertising data: %d\n", - err); - return; - } - printk("done.\n"); -} -#endif - -static void stop_ext_adv_set(struct bt_le_ext_adv *adv) -{ - int err; - - printk("Stopping Extended Advertising..."); - err = bt_le_ext_adv_stop(adv); - if (err) { - printk("Failed to stop extended advertising: %d\n", - err); - return; - } - printk("done.\n"); -} - -static void stop_per_adv_set(struct bt_le_ext_adv *adv) -{ - int err; - - printk("Stopping Periodic Advertising..."); - err = bt_le_per_adv_stop(adv); - if (err) { - printk("Failed to stop periodic advertising: %d\n", - err); - return; - } - printk("done.\n"); -} - -static void delete_adv_set(struct bt_le_ext_adv *adv) -{ - int err; - - printk("Delete extended advertising set..."); - err = bt_le_ext_adv_delete(adv); - if (err) { - printk("Failed Delete extended advertising set: %d\n", err); - return; - } - printk("done.\n"); -} - -static void main_per_adv_advertiser(void) -{ - struct bt_le_ext_adv *per_adv; - - common_init(); - - create_per_adv_set(&per_adv); - - start_per_adv_set(per_adv); - start_ext_adv_set(per_adv); - - /* Advertise for a bit */ - k_sleep(K_SECONDS(10)); - - stop_per_adv_set(per_adv); - stop_ext_adv_set(per_adv); - - delete_adv_set(per_adv); - per_adv = NULL; - - PASS("Periodic advertiser passed\n"); -} - -static void main_per_adv_conn_advertiser(void) -{ - struct bt_le_ext_adv *conn_adv; - struct bt_le_ext_adv *per_adv; - - common_init(); - - create_per_adv_set(&per_adv); - create_conn_adv_set(&conn_adv); - - start_per_adv_set(per_adv); - start_ext_adv_set(per_adv); - start_ext_adv_set(conn_adv); - - WAIT_FOR_FLAG(flag_connected); - - /* Advertise for a bit */ - k_sleep(K_SECONDS(10)); - - stop_per_adv_set(per_adv); - stop_ext_adv_set(per_adv); - stop_ext_adv_set(conn_adv); - - delete_adv_set(per_adv); - per_adv = NULL; - delete_adv_set(conn_adv); - conn_adv = NULL; - - PASS("Periodic advertiser passed\n"); -} - -static void main_per_adv_conn_privacy_advertiser(void) -{ - struct bt_le_ext_adv *conn_adv; - struct bt_le_ext_adv *per_adv; - - common_init(); - - create_conn_adv_set(&conn_adv); - - start_ext_adv_set(conn_adv); - - WAIT_FOR_FLAG(flag_connected); - WAIT_FOR_FLAG(flag_bonded); - - /* Start periodic advertising after bonding so that the scanner gets - * the resolved address - */ - create_per_adv_set(&per_adv); - start_per_adv_set(per_adv); - start_ext_adv_set(per_adv); - - /* Advertise for a bit */ - k_sleep(K_SECONDS(10)); - - stop_per_adv_set(per_adv); - stop_ext_adv_set(per_adv); - stop_ext_adv_set(conn_adv); - - delete_adv_set(per_adv); - per_adv = NULL; - delete_adv_set(conn_adv); - conn_adv = NULL; - - PASS("Periodic advertiser passed\n"); -} - -static void main_per_adv_long_data_advertiser(void) -{ -#if (CONFIG_BT_CTLR_ADV_DATA_CHAIN) - struct bt_le_ext_adv *per_adv; - - common_init(); - - create_per_adv_set(&per_adv); - - set_per_adv_data(per_adv); - start_per_adv_set(per_adv); - start_ext_adv_set(per_adv); - - /* Advertise for a bit */ - k_sleep(K_SECONDS(10)); - - stop_per_adv_set(per_adv); - stop_ext_adv_set(per_adv); - - delete_adv_set(per_adv); - per_adv = NULL; -#endif - PASS("Periodic long data advertiser passed\n"); -} - -static const struct bst_test_instance per_adv_advertiser[] = { - { - .test_id = "per_adv_advertiser", - .test_descr = "Basic periodic advertising test. " - "Will just start periodic advertising.", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = main_per_adv_advertiser - }, - { - .test_id = "per_adv_conn_advertiser", - .test_descr = "Periodic advertising test with concurrent ACL " - "and PA sync.", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = main_per_adv_conn_advertiser - }, - { - .test_id = "per_adv_conn_privacy_advertiser", - .test_descr = "Periodic advertising test with concurrent ACL " - "with bonding and PA sync.", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = main_per_adv_conn_privacy_advertiser - }, - { - .test_id = "per_adv_long_data_advertiser", - .test_descr = "Periodic advertising test with a longer data length. " - "To test the syncers reassembly of large data packets", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = main_per_adv_long_data_advertiser - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_per_adv_advertiser(struct bst_test_list *tests) -{ - return bst_add_tests(tests, per_adv_advertiser); -} diff --git a/tests/bluetooth/bsim/host/adv/periodic/src/per_adv_syncer.c b/tests/bluetooth/bsim/host/adv/periodic/src/per_adv_syncer.c deleted file mode 100644 index 274a6ca4cec..00000000000 --- a/tests/bluetooth/bsim/host/adv/periodic/src/per_adv_syncer.c +++ /dev/null @@ -1,377 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include - -#include "bs_types.h" -#include "bs_tracing.h" -#include "time_machine.h" -#include "bstests.h" - -#include -#include - -#include - -#include "common.h" - -extern enum bst_result_t bst_result; - -static struct bt_conn *g_conn; -static bt_addr_le_t per_addr; -static uint8_t per_sid; - -CREATE_FLAG(flag_connected); -CREATE_FLAG(flag_bonded); -CREATE_FLAG(flag_per_adv); -CREATE_FLAG(flag_per_adv_sync); -CREATE_FLAG(flag_per_adv_sync_lost); -CREATE_FLAG(flag_per_adv_recv); - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != BT_HCI_ERR_SUCCESS) { - FAIL("Failed to connect to %s: %u\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - g_conn = bt_conn_ref(conn); - SET_FLAG(flag_connected); -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - printk("Disconnected: %s (reason %u)\n", addr, reason); - - bt_conn_unref(g_conn); - g_conn = NULL; -} - -static struct bt_conn_cb conn_cbs = { - .connected = connected, - .disconnected = disconnected, -}; - -static void pairing_complete_cb(struct bt_conn *conn, bool bonded) -{ - if (conn == g_conn && bonded) { - SET_FLAG(flag_bonded); - } -} - -static struct bt_conn_auth_info_cb auto_info_cbs = { - .pairing_complete = pairing_complete_cb, -}; - -static void scan_recv(const struct bt_le_scan_recv_info *info, - struct net_buf_simple *buf) -{ - if (!TEST_FLAG(flag_connected) && - info->adv_props & BT_GAP_ADV_PROP_CONNECTABLE) { - int err; - - printk("Stopping scan\n"); - err = bt_le_scan_stop(); - if (err != 0) { - FAIL("Failed to stop scan: %d", err); - return; - } - - err = bt_conn_le_create(info->addr, BT_CONN_LE_CREATE_CONN, - BT_LE_CONN_PARAM_DEFAULT, &g_conn); - if (err != 0) { - FAIL("Could not connect to peer: %d", err); - return; - } - } else if (!TEST_FLAG(flag_per_adv) && info->interval != 0U) { - - per_sid = info->sid; - bt_addr_le_copy(&per_addr, info->addr); - - SET_FLAG(flag_per_adv); - } -} - -static struct bt_le_scan_cb scan_callbacks = { - .recv = scan_recv, -}; - -static void sync_cb(struct bt_le_per_adv_sync *sync, - struct bt_le_per_adv_sync_synced_info *info) -{ - char le_addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(info->addr, le_addr, sizeof(le_addr)); - - printk("PER_ADV_SYNC[%u]: [DEVICE]: %s synced, " - "Interval 0x%04x (%u us)\n", - bt_le_per_adv_sync_get_index(sync), le_addr, - info->interval, BT_CONN_INTERVAL_TO_US(info->interval)); - - SET_FLAG(flag_per_adv_sync); -} - -static void term_cb(struct bt_le_per_adv_sync *sync, - const struct bt_le_per_adv_sync_term_info *info) -{ - char le_addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(info->addr, le_addr, sizeof(le_addr)); - - printk("PER_ADV_SYNC[%u]: [DEVICE]: %s sync terminated\n", - bt_le_per_adv_sync_get_index(sync), le_addr); - - SET_FLAG(flag_per_adv_sync_lost); -} - -static void recv_cb(struct bt_le_per_adv_sync *recv_sync, - const struct bt_le_per_adv_sync_recv_info *info, - struct net_buf_simple *buf) -{ - char le_addr[BT_ADDR_LE_STR_LEN]; - uint8_t buf_data_len; - - if (TEST_FLAG(flag_per_adv_recv)) { - return; - } - - bt_addr_le_to_str(info->addr, le_addr, sizeof(le_addr)); - printk("PER_ADV_SYNC[%u]: [DEVICE]: %s advertisment received\n", - bt_le_per_adv_sync_get_index(recv_sync), le_addr); - - while (buf->len > 0) { - buf_data_len = (uint8_t)net_buf_simple_pull_le16(buf); - if (buf->data[0] - 1 != sizeof(mfg_data) || - memcmp(buf->data, mfg_data, sizeof(mfg_data))) { - FAIL("Unexpected adv data received\n"); - } - net_buf_simple_pull(buf, ARRAY_SIZE(mfg_data)); - } - - SET_FLAG(flag_per_adv_recv); -} - -static struct bt_le_per_adv_sync_cb sync_callbacks = { - .synced = sync_cb, - .term = term_cb, - .recv = recv_cb, -}; - -static void common_init(void) -{ - int err; - - err = bt_enable(NULL); - - if (err) { - FAIL("Bluetooth init failed: %d\n", err); - return; - } - - bt_le_scan_cb_register(&scan_callbacks); - bt_le_per_adv_sync_cb_register(&sync_callbacks); - bt_conn_cb_register(&conn_cbs); - bt_conn_auth_info_cb_register(&auto_info_cbs); -} - -static void start_scan(void) -{ - int err; - - printk("Start scanning..."); - err = bt_le_scan_start(BT_LE_SCAN_ACTIVE, NULL); - if (err) { - FAIL("Failed to start scan: %d\n", err); - return; - } - printk("done.\n"); -} - -static void create_pa_sync(struct bt_le_per_adv_sync **sync) -{ - struct bt_le_per_adv_sync_param sync_create_param = { 0 }; - int err; - - printk("Creating periodic advertising sync..."); - bt_addr_le_copy(&sync_create_param.addr, &per_addr); - sync_create_param.options = 0; - sync_create_param.sid = per_sid; - sync_create_param.skip = 0; - sync_create_param.timeout = 0x0a; - err = bt_le_per_adv_sync_create(&sync_create_param, sync); - if (err) { - FAIL("Failed to create periodic advertising sync: %d\n", err); - return; - } - printk("done.\n"); - - printk("Waiting for periodic sync...\n"); - WAIT_FOR_FLAG(flag_per_adv_sync); - printk("Periodic sync established.\n"); -} - -static void start_bonding(void) -{ - int err; - - printk("Setting security..."); - err = bt_conn_set_security(g_conn, BT_SECURITY_L2); - if (err) { - FAIL("Failed to set security: %d\n", err); - return; - } - printk("done.\n"); -} - -static void main_per_adv_syncer(void) -{ - struct bt_le_per_adv_sync *sync = NULL; - - common_init(); - start_scan(); - - printk("Waiting for periodic advertising...\n"); - WAIT_FOR_FLAG(flag_per_adv); - printk("Found periodic advertising.\n"); - - create_pa_sync(&sync); - - printk("Waiting for periodic sync lost...\n"); - WAIT_FOR_FLAG(flag_per_adv_sync_lost); - - PASS("Periodic advertising syncer passed\n"); -} - -static void main_per_adv_conn_syncer(void) -{ - struct bt_le_per_adv_sync *sync = NULL; - - common_init(); - start_scan(); - - printk("Waiting for connection..."); - WAIT_FOR_FLAG(flag_connected); - printk("done.\n"); - - start_scan(); - - printk("Waiting for periodic advertising...\n"); - WAIT_FOR_FLAG(flag_per_adv); - printk("Found periodic advertising.\n"); - - create_pa_sync(&sync); - - printk("Waiting for periodic sync lost...\n"); - WAIT_FOR_FLAG(flag_per_adv_sync_lost); - - PASS("Periodic advertising syncer passed\n"); -} - -static void main_per_adv_conn_privacy_syncer(void) -{ - struct bt_le_per_adv_sync *sync = NULL; - - common_init(); - start_scan(); - - printk("Waiting for connection..."); - WAIT_FOR_FLAG(flag_connected); - printk("done.\n"); - - start_bonding(); - - printk("Waiting for bonding..."); - WAIT_FOR_FLAG(flag_bonded); - printk("done.\n"); - - start_scan(); - - printk("Waiting for periodic advertising...\n"); - WAIT_FOR_FLAG(flag_per_adv); - printk("Found periodic advertising.\n"); - - create_pa_sync(&sync); - - printk("Waiting for periodic sync lost...\n"); - WAIT_FOR_FLAG(flag_per_adv_sync_lost); - - PASS("Periodic advertising syncer passed\n"); -} - -static void main_per_adv_long_data_syncer(void) -{ -#if (CONFIG_BT_PER_ADV_SYNC_BUF_SIZE > 0) - struct bt_le_per_adv_sync *sync = NULL; - - common_init(); - start_scan(); - - printk("Waiting for periodic advertising...\n"); - WAIT_FOR_FLAG(flag_per_adv); - printk("Found periodic advertising.\n"); - - create_pa_sync(&sync); - - printk("Waiting to receive periodic advertisment...\n"); - WAIT_FOR_FLAG(flag_per_adv_recv); - - printk("Waiting for periodic sync lost...\n"); - WAIT_FOR_FLAG(flag_per_adv_sync_lost); -#endif - PASS("Periodic advertising long data syncer passed\n"); -} - -static const struct bst_test_instance per_adv_syncer[] = { - { - .test_id = "per_adv_syncer", - .test_descr = "Basic periodic advertising sync test. " - "Will just sync to a periodic advertiser.", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = main_per_adv_syncer - }, - { - .test_id = "per_adv_conn_syncer", - .test_descr = "Periodic advertising sync test, but where there " - "is a connection between the advertiser and the " - "syncer.", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = main_per_adv_conn_syncer - }, - { - .test_id = "per_adv_conn_privacy_syncer", - .test_descr = "Periodic advertising sync test, but where " - "advertiser and syncer are bonded and using " - "privacy", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = main_per_adv_conn_privacy_syncer - }, - { - .test_id = "per_adv_long_data_syncer", - .test_descr = "Periodic advertising sync test with larger " - "data length. Test is used to verify that " - "reassembly of long data is handeled correctly.", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = main_per_adv_long_data_syncer - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_per_adv_syncer(struct bst_test_list *tests) -{ - return bst_add_tests(tests, per_adv_syncer); -} diff --git a/tests/bluetooth/bsim/host/adv/periodic/tests_scripts/per_adv.sh b/tests/bluetooth/bsim/host/adv/periodic/tests_scripts/per_adv.sh deleted file mode 100755 index 19dd00fbcff..00000000000 --- a/tests/bluetooth/bsim/host/adv/periodic/tests_scripts/per_adv.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash -# Copyright (c) 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -# Basic periodic advertising sync test: an advertiser advertises with periodic -# advertising, and a scanner scans for and syncs to the periodic advertising. -simulation_id="per_adv" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 10 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_adv_periodic_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=0 \ - -testid=per_adv_advertiser -rs=23 - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_adv_periodic_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -RealEncryption=0 \ - -testid=per_adv_syncer -rs=6 - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=20e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/adv/periodic/tests_scripts/per_adv_conn.sh b/tests/bluetooth/bsim/host/adv/periodic/tests_scripts/per_adv_conn.sh deleted file mode 100755 index d7c18d01878..00000000000 --- a/tests/bluetooth/bsim/host/adv/periodic/tests_scripts/per_adv_conn.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash -# Copyright (c) 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -# Basic periodic advertising sync test: an advertiser advertises with periodic -# advertising, and a scanner scans for and syncs to the periodic advertising. -simulation_id="per_adv_conn" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 10 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_adv_periodic_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=0 \ - -testid=per_adv_conn_advertiser -rs=23 - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_adv_periodic_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -RealEncryption=0 \ - -testid=per_adv_conn_syncer -rs=6 - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=20e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/adv/periodic/tests_scripts/per_adv_conn_privacy.sh b/tests/bluetooth/bsim/host/adv/periodic/tests_scripts/per_adv_conn_privacy.sh deleted file mode 100755 index c85c52653f2..00000000000 --- a/tests/bluetooth/bsim/host/adv/periodic/tests_scripts/per_adv_conn_privacy.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash -# Copyright (c) 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -# Basic periodic advertising sync test: an advertiser advertises with periodic -# advertising, and a scanner scans for and syncs to the periodic advertising. -simulation_id="per_adv_conn_privacy" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 10 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_adv_periodic_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=0 \ - -testid=per_adv_conn_privacy_advertiser -rs=23 - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_adv_periodic_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -RealEncryption=0 \ - -testid=per_adv_conn_privacy_syncer -rs=6 - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=20e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/adv/periodic/tests_scripts/per_adv_long_data.sh b/tests/bluetooth/bsim/host/adv/periodic/tests_scripts/per_adv_long_data.sh deleted file mode 100755 index 870c73d4513..00000000000 --- a/tests/bluetooth/bsim/host/adv/periodic/tests_scripts/per_adv_long_data.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash -# Copyright (c) 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -# Basic periodic advertising sync test: an advertiser advertises with periodic -# advertising, and a scanner scans for and syncs to the periodic advertising. -simulation_id="per_adv_long_data" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 10 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_adv_periodic_prj_long_data_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=0 \ - -testid=per_adv_long_data_advertiser -rs=23 - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_adv_periodic_prj_long_data_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -RealEncryption=0 \ - -testid=per_adv_long_data_syncer -rs=6 - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=20e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/adv/resume/CMakeLists.txt b/tests/bluetooth/bsim/host/adv/resume/CMakeLists.txt deleted file mode 100644 index e6e28dea9f9..00000000000 --- a/tests/bluetooth/bsim/host/adv/resume/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set\ - the environment variable BSIM_COMPONENTS_PATH to point to its components \ - folder. More information can be found in\ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_adv_resume) - -target_sources(app PRIVATE - src/bs_bt_utils.c - src/dut.c - src/main.c - src/tester.c -) - -zephyr_include_directories( - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ - ) diff --git a/tests/bluetooth/bsim/host/adv/resume/prj.conf b/tests/bluetooth/bsim/host/adv/resume/prj.conf deleted file mode 100644 index ec138585fd7..00000000000 --- a/tests/bluetooth/bsim/host/adv/resume/prj.conf +++ /dev/null @@ -1,20 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_CENTRAL=y - -CONFIG_ASSERT=y -CONFIG_BT_TESTING=y -CONFIG_BT_DEBUG_LOG=y - -CONFIG_BT_EXT_ADV=n -CONFIG_BT_PRIVACY=n -CONFIG_BT_SCAN_WITH_IDENTITY=n -CONFIG_BT_LOG_SNIFFER_INFO=y - -CONFIG_BT_AUTO_PHY_UPDATE=n -CONFIG_BT_AUTO_DATA_LEN_UPDATE=n -CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n - -CONFIG_BT_MAX_CONN=2 -CONFIG_BT_MAX_PAIRED=2 -CONFIG_BT_ID_MAX=2 diff --git a/tests/bluetooth/bsim/host/adv/resume/prj_2.conf b/tests/bluetooth/bsim/host/adv/resume/prj_2.conf deleted file mode 100644 index 9a397930b1f..00000000000 --- a/tests/bluetooth/bsim/host/adv/resume/prj_2.conf +++ /dev/null @@ -1,18 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_CENTRAL=y - -CONFIG_ASSERT=y -CONFIG_BT_TESTING=y -CONFIG_BT_DEBUG_LOG=y - -CONFIG_BT_EXT_ADV=y -CONFIG_BT_PRIVACY=n - -CONFIG_BT_AUTO_PHY_UPDATE=n -CONFIG_BT_AUTO_DATA_LEN_UPDATE=n -CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n - -CONFIG_BT_MAX_CONN=2 -CONFIG_BT_MAX_PAIRED=2 -CONFIG_BT_ID_MAX=2 diff --git a/tests/bluetooth/bsim/host/adv/resume/src/bs_bt_utils.c b/tests/bluetooth/bsim/host/adv/resume/src/bs_bt_utils.c deleted file mode 100644 index 90a5a56ca1b..00000000000 --- a/tests/bluetooth/bsim/host/adv/resume/src/bs_bt_utils.c +++ /dev/null @@ -1,233 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bs_bt_utils.h" -#include "argparse.h" -#include "bs_pc_backchannel.h" - -BUILD_ASSERT(CONFIG_BT_MAX_PAIRED >= 2, "CONFIG_BT_MAX_PAIRED is too small."); -BUILD_ASSERT(CONFIG_BT_ID_MAX == 2, "CONFIG_BT_ID_MAX should be 2."); - -#define BS_SECONDS(dur_sec) ((bs_time_t)dur_sec * USEC_PER_SEC) -#define TEST_TIMEOUT_SIMULATED BS_SECONDS(60) - -DEFINE_FLAG(flag_is_connected); -DEFINE_FLAG(flag_test_end); - -void test_tick(bs_time_t HW_device_time) -{ - bs_trace_debug_time(0, "Simulation ends now.\n"); - if (bst_result != Passed) { - bst_result = Failed; - bs_trace_error("Test did not pass before simulation ended.\n"); - } -} - -void test_init(void) -{ - bst_ticker_set_next_tick_absolute(TEST_TIMEOUT_SIMULATED); - bst_result = In_progress; -} - -void wait_connected(void) -{ - UNSET_FLAG(flag_is_connected); - WAIT_FOR_FLAG(flag_is_connected); - printk("connected\n"); -} - -void wait_disconnected(void) -{ - SET_FLAG(flag_is_connected); - WAIT_FOR_FLAG_UNSET(flag_is_connected); - printk("disconnected\n"); -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - UNSET_FLAG(flag_is_connected); -} - -static void connected(struct bt_conn *conn, uint8_t err) -{ - if (err != 0) { - return; - } - - SET_FLAG(flag_is_connected); -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - -void bs_bt_utils_setup(void) -{ - int err; - - UNSET_FLAG(flag_test_end); - - err = bt_enable(NULL); - ASSERT(!err, "bt_enable failed.\n"); -} - -static bt_addr_le_t last_scanned_addr; - -static void scan_connect_to_first_result_device_found(const bt_addr_le_t *addr, int8_t rssi, - uint8_t type, struct net_buf_simple *ad) -{ - struct bt_conn *conn; - char addr_str[BT_ADDR_LE_STR_LEN]; - int err; - - /* We're only interested in connectable events */ - if (type != BT_HCI_ADV_IND && type != BT_HCI_ADV_DIRECT_IND) { - FAIL("Unexpected advertisement type."); - } - - bt_addr_le_to_str(addr, addr_str, sizeof(addr_str)); - printk("Got scan result, connecting.. dst %s, RSSI %d\n", - addr_str, rssi); - - err = bt_le_scan_stop(); - ASSERT(!err, "Err bt_le_scan_stop %d", err); - - err = bt_conn_le_create(addr, - BT_CONN_LE_CREATE_CONN, BT_LE_CONN_PARAM_DEFAULT, - &conn); - ASSERT(!err, "Err bt_conn_le_create %d", err); - - /* Save address for later comparison */ - memcpy(&last_scanned_addr, addr, sizeof(last_scanned_addr)); -} - -void scan_connect_to_first_result(void) -{ - int err; - - printk("start scanner\n"); - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, - scan_connect_to_first_result_device_found); - ASSERT(!err, "Err bt_le_scan_start %d", err); -} - -static void scan_expect_same_address_device_found(const bt_addr_le_t *addr, int8_t rssi, - uint8_t type, struct net_buf_simple *ad) -{ - char addr_str[BT_ADDR_LE_STR_LEN]; - char expected_addr_str[BT_ADDR_LE_STR_LEN]; - - /* We're only interested in connectable events */ - if (type != BT_HCI_ADV_IND && type != BT_HCI_ADV_DIRECT_IND) { - FAIL("Unexpected advertisement type."); - } - - if (!bt_addr_le_eq(&last_scanned_addr, addr)) { - bt_addr_le_to_str(&last_scanned_addr, - expected_addr_str, - sizeof(expected_addr_str)); - bt_addr_le_to_str(addr, addr_str, sizeof(addr_str)); - - FAIL("Expected advertiser with addr %s, got %s\n", - expected_addr_str, addr_str); - } - - PASS("Advertiser used correct address on resume\n"); -} - -void scan_expect_same_address(void) -{ - int err; - - printk("start scanner\n"); - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, - scan_expect_same_address_device_found); - ASSERT(!err, "Err bt_le_scan_start %d", err); -} - -static void disconnect_device(struct bt_conn *conn, void *data) -{ - int err; - - /* We only use a single flag to indicate connections. Since this - * function will be called multiple times in a row, we have to set it - * back after it has been unset (in the `disconnected` callback). - */ - SET_FLAG(flag_is_connected); - - err = bt_conn_disconnect(conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN); - ASSERT(!err, "Failed to initate disconnect (err %d)", err); - - printk("Waiting for disconnection...\n"); - WAIT_FOR_FLAG_UNSET(flag_is_connected); -} - -void disconnect(void) -{ - bt_conn_foreach(BT_CONN_TYPE_LE, disconnect_device, NULL); -} - -void advertise_connectable(int id, bool persist) -{ - printk("start advertiser\n"); - int err; - struct bt_le_adv_param param = {}; - - param.id = id; - param.interval_min = 0x0020; - param.interval_max = 0x4000; - param.options |= persist ? 0 : BT_LE_ADV_OPT_ONE_TIME; - param.options |= BT_LE_ADV_OPT_CONNECTABLE; - - err = bt_le_adv_start(¶m, NULL, 0, NULL, 0); - ASSERT(err == 0, "Advertising failed to start (err %d)\n", err); -} - -#define CHANNEL_ID 0 -#define MSG_SIZE 1 - -void backchannel_init(uint peer) -{ - uint device_number = get_device_nbr(); - uint device_numbers[] = { peer }; - uint channel_numbers[] = { CHANNEL_ID }; - uint *ch; - - ch = bs_open_back_channel(device_number, device_numbers, - channel_numbers, ARRAY_SIZE(channel_numbers)); - if (!ch) { - FAIL("Unable to open backchannel\n"); - } -} - -void backchannel_sync_send(void) -{ - uint8_t sync_msg[MSG_SIZE] = { get_device_nbr() }; - - printk("Sending sync\n"); - bs_bc_send_msg(CHANNEL_ID, sync_msg, ARRAY_SIZE(sync_msg)); -} - -void backchannel_sync_wait(void) -{ - uint8_t sync_msg[MSG_SIZE]; - - while (true) { - if (bs_bc_is_msg_received(CHANNEL_ID) > 0) { - bs_bc_receive_msg(CHANNEL_ID, sync_msg, - ARRAY_SIZE(sync_msg)); - if (sync_msg[0] != get_device_nbr()) { - /* Received a message from another device, exit */ - break; - } - } - - k_sleep(K_MSEC(1)); - } - - printk("Sync received\n"); -} diff --git a/tests/bluetooth/bsim/host/adv/resume/src/bs_bt_utils.h b/tests/bluetooth/bsim/host/adv/resume/src/bs_bt_utils.h deleted file mode 100644 index 90a77be66e3..00000000000 --- a/tests/bluetooth/bsim/host/adv/resume/src/bs_bt_utils.h +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Common functions and helpers for BSIM ADV tests - * - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bs_tracing.h" -#include "bs_types.h" -#include "bstests.h" -#include "time_machine.h" -#include "zephyr/sys/__assert.h" - -#include - -#include -#include -#include -#include -#include -#include -#include - -extern enum bst_result_t bst_result; - -#define DECLARE_FLAG(flag) extern atomic_t flag -#define DEFINE_FLAG(flag) atomic_t flag = (atomic_t) false -#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) true) -#define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) false) -#define WAIT_FOR_FLAG(flag) \ - while (!(bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } -#define WAIT_FOR_FLAG_UNSET(flag) \ - while ((bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } -#define TAKE_FLAG(flag) \ - while (!(bool)atomic_cas(&flag, true, false)) { \ - (void)k_sleep(K_MSEC(1)); \ - } - -#define ASSERT(expr, ...) \ - do { \ - if (!(expr)) { \ - FAIL(__VA_ARGS__); \ - } \ - } while (0) - -DECLARE_FLAG(flag_test_end); - -#define FAIL(...) \ - SET_FLAG(flag_test_end); \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - SET_FLAG(flag_test_end); \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, __VA_ARGS__); \ - } while (0) - -void test_tick(bs_time_t HW_device_time); -void test_init(void); -void backchannel_init(uint peer); -void backchannel_sync_send(void); -void backchannel_sync_wait(void); - -void bs_bt_utils_setup(void); -void wait_connected(void); -void wait_disconnected(void); -void scan_connect_to_first_result(void); -void disconnect(void); -void advertise_connectable(int id, bool persist); -void scan_expect_same_address(void); diff --git a/tests/bluetooth/bsim/host/adv/resume/src/dut.c b/tests/bluetooth/bsim/host/adv/resume/src/dut.c deleted file mode 100644 index 4a58e9f5cad..00000000000 --- a/tests/bluetooth/bsim/host/adv/resume/src/dut.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bs_bt_utils.h" -#include "zephyr/bluetooth/addr.h" -#include "zephyr/bluetooth/bluetooth.h" -#include "zephyr/bluetooth/conn.h" -#include "zephyr/toolchain/gcc.h" - -#include -#include - -void dut_procedure(void) -{ - bs_bt_utils_setup(); - - printk("DUT start\n"); - - /* start scanning (using NRPA) */ - scan_connect_to_first_result(); - - advertise_connectable(0, 0); - wait_connected(); - printk("DUT is peripheral\n"); - - /* tester advertises using a new identity - * -> will get detected and connected to by DUT - */ - wait_connected(); - printk("DUT is central & peripheral\n"); - - /* restart advertiser: it will fail because we have run out of contexts. - * But since we pass the `persist` flag, it will start up as soon as a - * peripheral role is disconnected. - * - * We can't start it with the `persist` flag the first time, because adv - * will resume straight after the peripheral's connection completes, - * 'stealing' the last conn context and preventing the scanner from - * establishing a connection. - */ - advertise_connectable(0, 1); - - wait_disconnected(); - printk("DUT is central\n"); - scan_connect_to_first_result(); - - wait_disconnected(); - printk("DUT has no connections\n"); - - PASS("PASS\n"); -} - -void dut_procedure_2(void) -{ - bs_bt_utils_setup(); - - printk("DUT start\n"); - - /* Start a resumable advertiser. */ - advertise_connectable(0, true); - - PASS("DUT done\n"); -} diff --git a/tests/bluetooth/bsim/host/adv/resume/src/main.c b/tests/bluetooth/bsim/host/adv/resume/src/main.c deleted file mode 100644 index 0535d828c29..00000000000 --- a/tests/bluetooth/bsim/host/adv/resume/src/main.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bs_bt_utils.h" -#include "bstests.h" - -void dut_procedure(void); -void tester_peripheral_procedure(void); -void tester_central_procedure(void); - -void dut_procedure_2(void); -void tester_procedure_2(void); - -static const struct bst_test_instance test_to_add[] = { - { - .test_id = "dut", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = dut_procedure, - }, - { - .test_id = "tester_peripheral", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = tester_peripheral_procedure, - }, - { - .test_id = "tester_central", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = tester_central_procedure, - }, - { - .test_id = "dut_2", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = dut_procedure_2, - }, - { - .test_id = "tester_2", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = tester_procedure_2, - }, - BSTEST_END_MARKER, -}; - -static struct bst_test_list *install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_to_add); -}; - -bst_test_install_t test_installers[] = { install, NULL }; - -void main(void) -{ - bst_main(); -} diff --git a/tests/bluetooth/bsim/host/adv/resume/src/tester.c b/tests/bluetooth/bsim/host/adv/resume/src/tester.c deleted file mode 100644 index 3c6bae7f4a7..00000000000 --- a/tests/bluetooth/bsim/host/adv/resume/src/tester.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bs_bt_utils.h" -#include "zephyr/bluetooth/addr.h" -#include "zephyr/bluetooth/conn.h" - -#include - -#include - -#define TESTER_CENTRAL_ID 1 -#define TESTER_PERIPHERAL_ID 2 - -void tester_central_procedure(void) -{ - bs_bt_utils_setup(); - backchannel_init(TESTER_PERIPHERAL_ID); - printk("central tester start\n"); - - /* connect to DUT as central */ - scan_connect_to_first_result(); - wait_connected(); - backchannel_sync_send(); - /* DUT is peripheral */ - - /* wait until DUT connects to peripheral, and that it has disconnected - * from it afterwards. - */ - backchannel_sync_wait(); - - printk("disconnect central\n"); - disconnect(); - - /* DUT starts advertising again (with scanner's NRPA) - * should give wrong address - */ - scan_expect_same_address(); - - /* PASS/FAIL is called in the `device_found` callback. */ -} - -void tester_peripheral_procedure(void) -{ - bs_bt_utils_setup(); - backchannel_init(TESTER_CENTRAL_ID); - printk("peripheral tester start\n"); - - /* wait for central to connect to DUT */ - backchannel_sync_wait(); - - /* connect to DUT as peripheral */ - advertise_connectable(0, 0); - wait_connected(); - /* DUT is central & peripheral */ - - printk("disconnect peripheral\n"); - disconnect(); - /* DUT starts scanning again (using NRPA) */ - backchannel_sync_send(); - - PASS("PASS\n"); -} - -void tester_procedure_2(void) -{ - bs_bt_utils_setup(); - - printk("Tester start\n"); - - scan_connect_to_first_result(); - wait_connected(); - - /* Verify DUT advertiser was able to resume after the connection was - * established. - */ - scan_expect_same_address(); - - WAIT_FOR_FLAG(flag_test_end); -} diff --git a/tests/bluetooth/bsim/host/adv/resume/test_scripts/_compile.sh b/tests/bluetooth/bsim/host/adv/resume/test_scripts/_compile.sh deleted file mode 100755 index 649d9f2b1bb..00000000000 --- a/tests/bluetooth/bsim/host/adv/resume/test_scripts/_compile.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -set -eu -bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" - -# Read variable definitions output by _env.sh -source "${bash_source_dir}/_env.sh" - -# Place yourself in the test's root (i.e. ./../) -west build -b nrf52_bsim -d build_test && \ - cp build_test/zephyr/zephyr.exe "${test_exe}" - -west build -b nrf52_bsim -d build_test_2 -- -DCONF_FILE=prj_2.conf && \ - cp build_test_2/zephyr/zephyr.exe "${test_2_exe}" diff --git a/tests/bluetooth/bsim/host/adv/resume/test_scripts/_env.sh b/tests/bluetooth/bsim/host/adv/resume/test_scripts/_env.sh deleted file mode 100755 index 2b315a1e9f5..00000000000 --- a/tests/bluetooth/bsim/host/adv/resume/test_scripts/_env.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 -set -eu -bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -test_name="$(basename "$(realpath "$bash_source_dir/..")")" -bsim_bin="${BSIM_OUT_PATH}/bin" -BOARD="${BOARD:-nrf52_bsim}" -test_exe="${bsim_bin}/bs_${BOARD}_tests_bluetooth_bsim_host_adv_resume_prj_conf" -test_2_exe="${bsim_bin}/bs_${BOARD}_tests_bluetooth_bsim_host_adv_resume_prj_2_conf" diff --git a/tests/bluetooth/bsim/host/adv/resume/test_scripts/run_adv_resume.sh b/tests/bluetooth/bsim/host/adv/resume/test_scripts/run_adv_resume.sh deleted file mode 100755 index 8d00beddf0a..00000000000 --- a/tests/bluetooth/bsim/host/adv/resume/test_scripts/run_adv_resume.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -set -eu -bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" - -# Read variable definitions output by _env.sh -source "${bash_source_dir}/_env.sh" - -simulation_id="${test_name}" -verbosity_level=2 -process_ids="" -exit_code=0 - -function Execute() { - if [ ! -f $1 ]; then - echo -e " \e[91m$(pwd)/$(basename $1) cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 30 $@ & - process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -cd ${BSIM_OUT_PATH}/bin - -Execute "$test_exe" \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=dut -RealEncryption=1 - -Execute "$test_exe" \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=tester_central -RealEncryption=1 - -Execute "$test_exe" \ - -v=${verbosity_level} -s=${simulation_id} -d=2 -testid=tester_peripheral -RealEncryption=1 - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=3 -sim_length=10e6 $@ - -# Uncomment (and comment the other peripheral line) to run DUT under a debugger -# gdb --args "$test_exe" \ -# -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral -RealEncryption=1 - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/adv/resume/test_scripts/run_adv_resume_2.sh b/tests/bluetooth/bsim/host/adv/resume/test_scripts/run_adv_resume_2.sh deleted file mode 100755 index c7f37565627..00000000000 --- a/tests/bluetooth/bsim/host/adv/resume/test_scripts/run_adv_resume_2.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -set -eu -bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" - -# Read variable definitions output by _env.sh -source "${bash_source_dir}/_env.sh" - -simulation_id="${test_name}_2" -verbosity_level=2 -process_ids="" -exit_code=0 - -function Execute() { - if [ ! -f $1 ]; then - echo -e " \e[91m$(pwd)/$(basename $1) cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 30 $@ & - process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -cd ${BSIM_OUT_PATH}/bin - -Execute "$test_2_exe" \ - -v=${verbosity_level} -s="${simulation_id}" -d=0 -testid=dut_2 -RealEncryption=1 - -Execute "$test_2_exe" \ - -v=${verbosity_level} -s="${simulation_id}" -d=1 -testid=tester_2 -RealEncryption=1 - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s="${simulation_id}" \ - -D=2 -sim_length=10e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/att/eatt/CMakeLists.txt b/tests/bluetooth/bsim/host/att/eatt/CMakeLists.txt deleted file mode 100644 index cf74fcc6cc8..00000000000 --- a/tests/bluetooth/bsim/host/att/eatt/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set\ - the environment variable BSIM_COMPONENTS_PATH to point to its components \ - folder. More information can be found in\ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_host) - - -target_sources(app PRIVATE - src/common.c - src/main_collision.c - src/main_autoconnect.c - src/main_reconfigure.c - src/main.c -) - - -zephyr_include_directories( - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ - ) diff --git a/tests/bluetooth/bsim/host/att/eatt/prj_autoconnect.conf b/tests/bluetooth/bsim/host/att/eatt/prj_autoconnect.conf deleted file mode 100644 index 68a6d7445e0..00000000000 --- a/tests/bluetooth/bsim/host/att/eatt/prj_autoconnect.conf +++ /dev/null @@ -1,16 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_SMP=y -CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y -CONFIG_BT_DEVICE_NAME="EATT test" -CONFIG_BT_EATT=y -CONFIG_BT_L2CAP_ECRED=y -CONFIG_BT_EATT_MAX=5 -CONFIG_BT_MAX_CONN=1 - -CONFIG_BT_TESTING=y -CONFIG_BT_DEBUG_LOG=y -CONFIG_ASSERT=y - -CONFIG_BT_L2CAP_TX_MTU=200 diff --git a/tests/bluetooth/bsim/host/att/eatt/prj_collision.conf b/tests/bluetooth/bsim/host/att/eatt/prj_collision.conf deleted file mode 100644 index 7b82b474898..00000000000 --- a/tests/bluetooth/bsim/host/att/eatt/prj_collision.conf +++ /dev/null @@ -1,15 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_SMP=y -CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y -CONFIG_BT_DEVICE_NAME="EATT test" -CONFIG_BT_EATT=y -CONFIG_BT_L2CAP_ECRED=y -CONFIG_BT_EATT_MAX=5 -CONFIG_BT_MAX_CONN=1 -CONFIG_BT_EATT_AUTO_CONNECT=n - -CONFIG_BT_TESTING=y -CONFIG_BT_DEBUG_LOG=y -CONFIG_ASSERT=y diff --git a/tests/bluetooth/bsim/host/att/eatt/prj_multiple_conn.conf b/tests/bluetooth/bsim/host/att/eatt/prj_multiple_conn.conf deleted file mode 100644 index cd05f4602c5..00000000000 --- a/tests/bluetooth/bsim/host/att/eatt/prj_multiple_conn.conf +++ /dev/null @@ -1,15 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_SMP=y -CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y -CONFIG_BT_DEVICE_NAME="EATT test" -CONFIG_BT_EATT=y -CONFIG_BT_L2CAP_ECRED=y -CONFIG_BT_EATT_MAX=5 -CONFIG_BT_MAX_CONN=2 -CONFIG_BT_EATT_AUTO_CONNECT=n - -CONFIG_BT_TESTING=y -CONFIG_BT_DEBUG_LOG=y -CONFIG_ASSERT=y diff --git a/tests/bluetooth/bsim/host/att/eatt/src/common.c b/tests/bluetooth/bsim/host/att/eatt/src/common.c deleted file mode 100644 index b7bd5b4b73f..00000000000 --- a/tests/bluetooth/bsim/host/att/eatt/src/common.c +++ /dev/null @@ -1,223 +0,0 @@ -/* common.c - Common test code */ - -/* - * Copyright (c) 2022 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "common.h" -#include "argparse.h" - -struct bt_conn *default_conn; - -static const struct bt_data ad[] = { - BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), -}; - -static volatile bool is_connected; -static volatile bool is_encrypted; - -static void connected(struct bt_conn *conn, uint8_t conn_err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (conn_err) { - if (default_conn) { - bt_conn_unref(default_conn); - default_conn = NULL; - } - - FAIL("Failed to connect to %s (%u)\n", addr, conn_err); - return; - } - - if (!default_conn) { - default_conn = bt_conn_ref(conn); - } - - printk("Connected: %s\n", addr); - is_connected = true; -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - printk("Disconnected: %s (reason 0x%02x)\n", addr, reason); - - bt_conn_unref(default_conn); - default_conn = NULL; - is_connected = false; - is_encrypted = false; -} - -static void security_changed(struct bt_conn *conn, bt_security_t level, - enum bt_security_err security_err) -{ - if (security_err == BT_SECURITY_ERR_SUCCESS && level > BT_SECURITY_L1) { - is_encrypted = true; - } -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, - .security_changed = security_changed, -}; - -static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, - struct net_buf_simple *ad) -{ - int err; - - err = bt_le_scan_stop(); - if (err) { - FAIL("Stop LE scan failed (err %d)\n", err); - } - - err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, BT_LE_CONN_PARAM_DEFAULT, - &default_conn); - if (err) { - FAIL("Create conn failed (err %d)\n", err); - } - - printk("Device connected\n"); -} - -void test_init(void) -{ - bst_ticker_set_next_tick_absolute(60e6); /* 60 seconds */ - bst_result = In_progress; -} - -void test_tick(bs_time_t HW_device_time) -{ - if (bst_result != Passed) { - bst_result = Failed; - bs_trace_error_time_line("Test eatt finished.\n"); - } -} - -void central_setup_and_connect(void) -{ - int err; - - err = bt_enable(NULL); - if (err) { - FAIL("Can't enable Bluetooth (err %d)\n", err); - } - - err = bt_le_scan_start(BT_LE_SCAN_ACTIVE, device_found); - if (err) { - FAIL("Scanning failed to start (err %d)\n", err); - } - - while (!is_connected) { - k_sleep(K_MSEC(100)); - } - - err = bt_conn_set_security(default_conn, BT_SECURITY_L2); - if (err) { - FAIL("Failed to start encryption procedure\n"); - } - - while (!is_encrypted) { - k_sleep(K_MSEC(100)); - } -} - -void peripheral_setup_and_connect(void) -{ - int err; - - err = bt_enable(NULL); - if (err) { - FAIL("Can't enable Bluetooth (err %d)\n", err); - } - - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0); - if (err) { - FAIL("Advertising failed to start (err %d)\n", err); - } - - while (!is_connected) { - k_sleep(K_MSEC(100)); - } - - /* Wait for central to start encryption */ - while (!is_encrypted) { - k_sleep(K_MSEC(100)); - } -} - -void wait_for_disconnect(void) -{ - while (is_connected) { - k_sleep(K_MSEC(100)); - } -} - -void disconnect(void) -{ - int err; - - err = bt_conn_disconnect(default_conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN); - if (err) { - FAIL("Disconnection failed (err %d)\n", err); - } - - while (is_connected) { - k_sleep(K_MSEC(100)); - } -} - - -#define CHANNEL_ID 0 -#define MSG_SIZE 1 - -void backchannel_init(void) -{ - uint device_number = get_device_nbr(); - uint peer_number = device_number ^ 1; - uint device_numbers[] = { peer_number }; - uint channel_numbers[] = { CHANNEL_ID }; - uint *ch; - - ch = bs_open_back_channel(device_number, device_numbers, channel_numbers, - ARRAY_SIZE(channel_numbers)); - if (!ch) { - FAIL("Unable to open backchannel\n"); - } -} - -void backchannel_sync_send(void) -{ - uint8_t sync_msg[MSG_SIZE] = { get_device_nbr() }; - - printk("Sending sync\n"); - bs_bc_send_msg(CHANNEL_ID, sync_msg, ARRAY_SIZE(sync_msg)); -} - -void backchannel_sync_wait(void) -{ - uint8_t sync_msg[MSG_SIZE]; - - while (true) { - if (bs_bc_is_msg_received(CHANNEL_ID) > 0) { - bs_bc_receive_msg(CHANNEL_ID, sync_msg, ARRAY_SIZE(sync_msg)); - if (sync_msg[0] != get_device_nbr()) { - /* Received a message from another device, exit */ - break; - } - } - - k_sleep(K_MSEC(1)); - } - - printk("Sync received\n"); -} diff --git a/tests/bluetooth/bsim/host/att/eatt/src/common.h b/tests/bluetooth/bsim/host/att/eatt/src/common.h deleted file mode 100644 index 49bc88f03fd..00000000000 --- a/tests/bluetooth/bsim/host/att/eatt/src/common.h +++ /dev/null @@ -1,57 +0,0 @@ -/* common.h - Common test code */ - -/* - * Copyright (c) 2022 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include -#include -#include -#include - -#include -#include -#include - -#include "bs_types.h" -#include "bs_tracing.h" -#include "bstests.h" -#include "bs_pc_backchannel.h" - -extern enum bst_result_t bst_result; - -#define CREATE_FLAG(flag) static atomic_t flag = (atomic_t)false -#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)true) -#define WAIT_FOR_FLAG(flag) \ - while (!(bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } - -#define FAIL(...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, __VA_ARGS__); \ - } while (0) - -extern volatile int num_eatt_channels; -extern struct bt_conn *default_conn; - -void central_setup_and_connect(void); -void peripheral_setup_and_connect(void); -void wait_for_disconnect(void); -void disconnect(void); -void test_init(void); -void test_tick(bs_time_t HW_device_time); -void backchannel_init(void); -void backchannel_sync_send(void); -void backchannel_sync_wait(void); diff --git a/tests/bluetooth/bsim/host/att/eatt/src/main.c b/tests/bluetooth/bsim/host/att/eatt/src/main.c deleted file mode 100644 index 70a3edcccdb..00000000000 --- a/tests/bluetooth/bsim/host/att/eatt/src/main.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bstests.h" - -extern struct bst_test_list *test_main_collision_install(struct bst_test_list *tests); -extern struct bst_test_list *test_main_autoconnect_install(struct bst_test_list *tests); -extern struct bst_test_list *test_main_reconfigure_install(struct bst_test_list *tests); - -bst_test_install_t test_installers[] = { - test_main_collision_install, - test_main_autoconnect_install, - test_main_reconfigure_install, - NULL, -}; - -void main(void) -{ - bst_main(); -} diff --git a/tests/bluetooth/bsim/host/att/eatt/src/main_autoconnect.c b/tests/bluetooth/bsim/host/att/eatt/src/main_autoconnect.c deleted file mode 100644 index fec3c7d45ed..00000000000 --- a/tests/bluetooth/bsim/host/att/eatt/src/main_autoconnect.c +++ /dev/null @@ -1,61 +0,0 @@ -/* main_connect.c - Application main entry point */ - -/* - * Copyright (c) 2022 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "common.h" - -static void test_peripheral_main(void) -{ - peripheral_setup_and_connect(); - - while (bt_eatt_count(default_conn) < CONFIG_BT_EATT_MAX) { - k_sleep(K_MSEC(10)); - } - - /* Do not disconnect until the central also has connected all channels */ - k_sleep(K_MSEC(1000)); - - disconnect(); - - PASS("EATT Peripheral tests Passed\n"); -} - -static void test_central_main(void) -{ - central_setup_and_connect(); - - while (bt_eatt_count(default_conn) < CONFIG_BT_EATT_MAX) { - k_sleep(K_MSEC(10)); - } - - wait_for_disconnect(); - - PASS("EATT Central tests Passed\n"); -} - -static const struct bst_test_instance test_def[] = { - { - .test_id = "peripheral_autoconnect", - .test_descr = "Peripheral autoconnect", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_peripheral_main, - }, - { - .test_id = "central_autoconnect", - .test_descr = "Central autoconnect", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_central_main, - }, - BSTEST_END_MARKER, -}; - -struct bst_test_list *test_main_autoconnect_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_def); -} diff --git a/tests/bluetooth/bsim/host/att/eatt/src/main_collision.c b/tests/bluetooth/bsim/host/att/eatt/src/main_collision.c deleted file mode 100644 index 9ee5f480623..00000000000 --- a/tests/bluetooth/bsim/host/att/eatt/src/main_collision.c +++ /dev/null @@ -1,88 +0,0 @@ -/* main_collision.c - Application main entry point */ - -/* - * Copyright (c) 2022 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "common.h" - -static void test_peripheral_main(void) -{ - int err; - - backchannel_init(); - - peripheral_setup_and_connect(); - - /* - * we need to sync with peer to ensure that we get collisions - */ - backchannel_sync_send(); - backchannel_sync_wait(); - - err = bt_eatt_connect(default_conn, CONFIG_BT_EATT_MAX); - if (err) { - FAIL("Sending credit based connection request failed (err %d)\n", err); - } - - while (bt_eatt_count(default_conn) < CONFIG_BT_EATT_MAX) { - k_sleep(K_MSEC(10)); - } - - /* Do not disconnect until the central also has connected all channels */ - k_sleep(K_MSEC(1000)); - - disconnect(); - - PASS("EATT Peripheral tests Passed\n"); -} - -static void test_central_main(void) -{ - int err; - - backchannel_init(); - - central_setup_and_connect(); - - backchannel_sync_wait(); - backchannel_sync_send(); - - err = bt_eatt_connect(default_conn, CONFIG_BT_EATT_MAX); - if (err) { - FAIL("Sending credit based connection request failed (err %d)\n", err); - } - - while (bt_eatt_count(default_conn) < CONFIG_BT_EATT_MAX) { - k_sleep(K_MSEC(10)); - } - - wait_for_disconnect(); - - PASS("EATT Central tests Passed\n"); -} - -static const struct bst_test_instance test_def[] = { - { - .test_id = "peripheral", - .test_descr = "Peripheral Collision", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_peripheral_main, - }, - { - .test_id = "central", - .test_descr = "Central Collision", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_central_main, - }, - BSTEST_END_MARKER, -}; - -struct bst_test_list *test_main_collision_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_def); -} diff --git a/tests/bluetooth/bsim/host/att/eatt/src/main_reconfigure.c b/tests/bluetooth/bsim/host/att/eatt/src/main_reconfigure.c deleted file mode 100644 index 04859a97994..00000000000 --- a/tests/bluetooth/bsim/host/att/eatt/src/main_reconfigure.c +++ /dev/null @@ -1,91 +0,0 @@ -/* main_reconfigure.c - Application main entry point */ - -/* - * Copyright (c) 2022 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "common.h" - -#include - -#define NEW_MTU 100 - -CREATE_FLAG(flag_reconfigured); - -void att_mtu_updated(struct bt_conn *conn, uint16_t tx, uint16_t rx) -{ - printk("MTU Updated: tx %d, rx %d\n", tx, rx); - if (rx == NEW_MTU || tx == NEW_MTU) { - SET_FLAG(flag_reconfigured); - } -} - -static struct bt_gatt_cb cb = { - .att_mtu_updated = att_mtu_updated, -}; - -static void test_peripheral_main(void) -{ - peripheral_setup_and_connect(); - - bt_gatt_cb_register(&cb); - - while (bt_eatt_count(default_conn) < CONFIG_BT_EATT_MAX) { - k_sleep(K_MSEC(10)); - } - - WAIT_FOR_FLAG(flag_reconfigured); - - disconnect(); - - PASS("EATT Peripheral tests Passed\n"); -} - -static void test_central_main(void) -{ - int err; - - central_setup_and_connect(); - - bt_gatt_cb_register(&cb); - - while (bt_eatt_count(default_conn) < CONFIG_BT_EATT_MAX) { - k_sleep(K_MSEC(10)); - } - - err = bt_eatt_reconfigure(default_conn, NEW_MTU); - if (err < 0) { - FAIL("Reconfigure failed (%d)\n", err); - } - - WAIT_FOR_FLAG(flag_reconfigured); - - wait_for_disconnect(); - - PASS("EATT Central tests Passed\n"); -} - -static const struct bst_test_instance test_def[] = { - { - .test_id = "peripheral_reconfigure", - .test_descr = "Peripheral reconfigure", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_peripheral_main, - }, - { - .test_id = "central_reconfigure", - .test_descr = "Central reconfigure", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_central_main, - }, - BSTEST_END_MARKER, -}; - -struct bst_test_list *test_main_reconfigure_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_def); -} diff --git a/tests/bluetooth/bsim/host/att/eatt/tests_scripts/autoconnect.sh b/tests/bluetooth/bsim/host/att/eatt/tests_scripts/autoconnect.sh deleted file mode 100755 index a1a0e4eccd5..00000000000 --- a/tests/bluetooth/bsim/host/att/eatt/tests_scripts/autoconnect.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bash -# Copyright (c) 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="connection" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 120 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_att_eatt_prj_autoconnect_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central_autoconnect - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_att_eatt_prj_autoconnect_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral_autoconnect - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=200e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/att/eatt/tests_scripts/collision.sh b/tests/bluetooth/bsim/host/att/eatt/tests_scripts/collision.sh deleted file mode 100755 index b040d7b6958..00000000000 --- a/tests/bluetooth/bsim/host/att/eatt/tests_scripts/collision.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bash -# Copyright (c) 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="collision" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 120 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_att_eatt_prj_collision_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_att_eatt_prj_collision_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=200e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/att/eatt/tests_scripts/multiple_conn.sh b/tests/bluetooth/bsim/host/att/eatt/tests_scripts/multiple_conn.sh deleted file mode 100755 index 0fe8fad56a3..00000000000 --- a/tests/bluetooth/bsim/host/att/eatt/tests_scripts/multiple_conn.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bash -# Copyright (c) 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="multiple_conn" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 120 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_att_eatt_prj_multiple_conn_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_att_eatt_prj_multiple_conn_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=200e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/att/eatt/tests_scripts/reconfigure.sh b/tests/bluetooth/bsim/host/att/eatt/tests_scripts/reconfigure.sh deleted file mode 100755 index c927000c04e..00000000000 --- a/tests/bluetooth/bsim/host/att/eatt/tests_scripts/reconfigure.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bash -# Copyright (c) 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="reconfigure" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 120 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_att_eatt_prj_autoconnect_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central_reconfigure - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_att_eatt_prj_autoconnect_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral_reconfigure - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=60e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/att/eatt_notif/CMakeLists.txt b/tests/bluetooth/bsim/host/att/eatt_notif/CMakeLists.txt deleted file mode 100644 index 08183de6d30..00000000000 --- a/tests/bluetooth/bsim/host/att/eatt_notif/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set\ - the environment variable BSIM_COMPONENTS_PATH to point to its components \ - folder. More information can be found in\ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_eatt_notif) - -FILE(GLOB app_sources src/*.c) -target_sources(app PRIVATE ${app_sources} ) - -zephyr_include_directories( - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ - ) diff --git a/tests/bluetooth/bsim/host/att/eatt_notif/prj.conf b/tests/bluetooth/bsim/host/att/eatt_notif/prj.conf deleted file mode 100644 index 1b4f45c4bcf..00000000000 --- a/tests/bluetooth/bsim/host/att/eatt_notif/prj.conf +++ /dev/null @@ -1,16 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_SMP=y -CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y -CONFIG_BT_DEVICE_NAME="EATT test" -CONFIG_BT_EATT=y -CONFIG_BT_TESTING=y -CONFIG_BT_EATT_AUTO_CONNECT=n -CONFIG_BT_L2CAP_ECRED=y -CONFIG_BT_EATT_MAX=16 -CONFIG_BT_MAX_CONN=1 -CONFIG_BT_GATT_CLIENT=y -CONFIG_BT_GATT_AUTO_DISCOVER_CCC=y -CONFIG_BT_ATT_PREPARE_COUNT=3 -CONFIG_ASSERT=y diff --git a/tests/bluetooth/bsim/host/att/eatt_notif/src/client_test.c b/tests/bluetooth/bsim/host/att/eatt_notif/src/client_test.c deleted file mode 100644 index 8b399c1c4c3..00000000000 --- a/tests/bluetooth/bsim/host/att/eatt_notif/src/client_test.c +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - * - * EATT notification reliability test: - * A central acting as a GATT client scans and connects - * to a peripheral acting as a GATT server. - * The GATT client will then attempt to connect a number of CONFIG_BT_EATT_MAX bearers - * over EATT, send notifications, disconnect all bearers and reconnect EATT_BEARERS_TEST - * and send start a transaction with a request, then send a lot of notifications - * before the response is received. - * The test might be expanded by checking that all the notifications all transmitted - * on EATT channels. - */ - -#include -#include -#include -#include - -#include "common.h" - -CREATE_FLAG(flag_is_connected); -CREATE_FLAG(flag_discover_complete); -CREATE_FLAG(flag_is_encrypted); - -static struct bt_conn *g_conn; -static const struct bt_gatt_attr *local_attr; -static struct bt_uuid *test_svc_uuid = TEST_SERVICE_UUID; - -#define NUM_NOTIF 100 -#define SAMPLE_DATA 1 -#define EATT_BEARERS_TEST 1 - -volatile int num_eatt_channels; - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - SET_FLAG(flag_is_connected); -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - if (conn != g_conn) { - return; - } - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - printk("Disconnected: %s (reason 0x%02x)\n", addr, reason); - - bt_conn_unref(g_conn); - - g_conn = NULL; - UNSET_FLAG(flag_is_connected); -} - -static void security_changed(struct bt_conn *conn, bt_security_t level, - enum bt_security_err security_err) -{ - if (security_err == BT_SECURITY_ERR_SUCCESS && level > BT_SECURITY_L1) { - SET_FLAG(flag_is_encrypted); - } -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, - .security_changed = security_changed, -}; - -void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, - struct net_buf_simple *ad) -{ - char addr_str[BT_ADDR_LE_STR_LEN]; - int err; - - if (g_conn != NULL) { - return; - } - - /* We're only interested in connectable events */ - if (type != BT_HCI_ADV_IND && type != BT_HCI_ADV_DIRECT_IND) { - return; - } - - bt_addr_le_to_str(addr, addr_str, sizeof(addr_str)); - printk("Device found: %s (RSSI %d)\n", addr_str, rssi); - - printk("Stopping scan\n"); - err = bt_le_scan_stop(); - if (err != 0) { - FAIL("Could not stop scan: %d"); - return; - } - - err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, - BT_LE_CONN_PARAM_DEFAULT, &g_conn); - if (err != 0) { - FAIL("Could not connect to peer: %d", err); - } -} - -void send_notification(void) -{ - const uint8_t sample_dat = SAMPLE_DATA; - int err; - - do { - err = bt_gatt_notify(g_conn, local_attr, &sample_dat, sizeof(sample_dat)); - if (!err) { - return; - } else if (err != -ENOMEM) { - printk("GATT notify failed (err %d)\n", err); - return; - } - k_sleep(K_TICKS(1)); - } while (err == -ENOMEM); -} - -static uint8_t discover_func(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - struct bt_gatt_discover_params *params) -{ - SET_FLAG(flag_discover_complete); - printk("Discover complete\n"); - - return BT_GATT_ITER_STOP; -} - -static void gatt_discover(void) -{ - static struct bt_gatt_discover_params discover_params; - int err; - - printk("Discovering services and characteristics\n"); - - discover_params.uuid = test_svc_uuid; - discover_params.func = discover_func; - discover_params.start_handle = BT_ATT_FIRST_ATTRIBUTE_HANDLE; - discover_params.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE; - discover_params.type = BT_GATT_DISCOVER_PRIMARY; - discover_params.chan_opt = BT_ATT_CHAN_OPT_NONE; - - err = bt_gatt_discover(g_conn, &discover_params); - if (err != 0) { - FAIL("Discover failed(err %d)\n", err); - } -} - -BT_GATT_SERVICE_DEFINE(g_svc, - BT_GATT_PRIMARY_SERVICE(TEST_SERVICE_UUID), - BT_GATT_CHARACTERISTIC(TEST_CHRC_UUID, BT_GATT_CHRC_NOTIFY, - BT_GATT_PERM_READ, NULL, NULL, NULL), - BT_GATT_CCC(NULL, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE)); - -static void test_main(void) -{ - int err; - - device_sync_init(PERIPHERAL_ID); - - err = bt_enable(NULL); - if (err != 0) { - FAIL("Bluetooth enable failed (err %d)\n", err); - } - - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); - if (err != 0) { - FAIL("Scanning failed to start (err %d)\n", err); - } - - printk("Scanning successfully started\n"); - - WAIT_FOR_FLAG(flag_is_connected); - - err = bt_conn_set_security(g_conn, BT_SECURITY_L2); - if (err) { - FAIL("Failed to start encryption procedure\n"); - } - - WAIT_FOR_FLAG(flag_is_encrypted); - - err = bt_eatt_connect(g_conn, CONFIG_BT_EATT_MAX); - if (err) { - FAIL("Sending credit based connection request failed (err %d)\n", err); - } - - /* Wait for the channels to be connected */ - while (bt_eatt_count(g_conn) < CONFIG_BT_EATT_MAX) { - k_sleep(K_TICKS(1)); - } - - printk("Waiting for sync\n"); - device_sync_wait(); - - local_attr = &g_svc.attrs[1]; - - printk("############# Notification test\n"); - for (int idx = 0; idx < NUM_NOTIF; idx++) { - printk("Notification %d\n", idx); - send_notification(); - } - - printk("############# Disconnect and reconnect\n"); - for (int idx = 0; idx < CONFIG_BT_EATT_MAX; idx++) { - bt_eatt_disconnect_one(g_conn); - while (bt_eatt_count(g_conn) != (CONFIG_BT_EATT_MAX - idx)) { - k_sleep(K_TICKS(1)); - } - } - - printk("Connecting %d bearers\n", EATT_BEARERS_TEST); - err = bt_eatt_connect(g_conn, EATT_BEARERS_TEST); - if (err) { - FAIL("Sending credit based connection request failed (err %d)\n", err); - } - - /* Wait for the channels to be connected */ - while (bt_eatt_count(g_conn) < EATT_BEARERS_TEST) { - k_sleep(K_TICKS(1)); - } - - printk("############# Send notifications during discovery request\n"); - gatt_discover(); - while (!TEST_FLAG(flag_discover_complete)) { - printk("Notifying...\n"); - send_notification(); - } - - printk("Sending final sync\n"); - device_sync_send(); - - PASS("Client Passed\n"); -} - -static const struct bst_test_instance test_vcs[] = { - { - .test_id = "client", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_client_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_vcs); -} diff --git a/tests/bluetooth/bsim/host/att/eatt_notif/src/common.c b/tests/bluetooth/bsim/host/att/eatt_notif/src/common.c deleted file mode 100644 index 1df3895fc3e..00000000000 --- a/tests/bluetooth/bsim/host/att/eatt_notif/src/common.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "common.h" -#include - -#define LOG_MODULE_NAME common - -LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL_DBG); - -void test_tick(bs_time_t HW_device_time) -{ - if (bst_result != Passed) { - FAIL("test failed (not passed after %i seconds)\n", WAIT_TIME); - } -} - -void test_init(void) -{ - bst_ticker_set_next_tick_absolute(WAIT_TIME); - bst_result = In_progress; -} - -/* Call in init functions*/ -void device_sync_init(uint device_nbr) -{ - uint peer; - - if (device_nbr == CENTRAL_ID) { - peer = PERIPHERAL_ID; - } else { - peer = CENTRAL_ID; - } - - uint dev_nbrs[BACK_CHANNELS] = { peer }; - uint channel_nbrs[BACK_CHANNELS] = { 0 }; - const uint *ch = bs_open_back_channel(device_nbr, dev_nbrs, channel_nbrs, BACK_CHANNELS); - - if (!ch) { - LOG_ERR("bs_open_back_channel failed!"); - } -} - -/* Call it to make peer to proceed.*/ -void device_sync_send(void) -{ - uint8_t msg[1] = "S"; - - bs_bc_send_msg(0, msg, sizeof(msg)); -} - -/* Wait until peer send sync*/ -void device_sync_wait(void) -{ - int size_msg_received = 0; - uint8_t msg; - - while (!size_msg_received) { - size_msg_received = bs_bc_is_msg_received(0); - k_sleep(K_MSEC(1)); - } - - bs_bc_receive_msg(0, &msg, size_msg_received); -} diff --git a/tests/bluetooth/bsim/host/att/eatt_notif/src/common.h b/tests/bluetooth/bsim/host/att/eatt_notif/src/common.h deleted file mode 100644 index aecbda9cbe6..00000000000 --- a/tests/bluetooth/bsim/host/att/eatt_notif/src/common.h +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Common functions and helpers for BSIM EATT notification tests - * - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include "bs_types.h" -#include "bs_tracing.h" -#include "time_machine.h" -#include "bstests.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include "bs_pc_backchannel.h" - -extern enum bst_result_t bst_result; - -#define WAIT_TIME (30 * 1e6) /*seconds*/ - -#define CREATE_FLAG(flag) static atomic_t flag = (atomic_t)false -#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)true) -#define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)false) -#define TEST_FLAG(flag) (atomic_get(&flag) == (atomic_t)true) -#define WAIT_FOR_FLAG(flag) \ - while (!(bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } - -#define FAIL(...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, __VA_ARGS__); \ - } while (0) - -#define CHRC_SIZE 10 -#define LONG_CHRC_SIZE 40 - -#define TEST_SERVICE_UUID \ - BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, \ - 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x00, 0x00) - -#define TEST_CHRC_UUID \ - BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, \ - 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xFF, 0x00) - -#define TEST_LONG_CHRC_UUID \ - BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, \ - 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xFF, 0x11) - -#define CENTRAL_ID 0 -#define PERIPHERAL_ID 1 -#define BACK_CHANNELS 1 - -void test_tick(bs_time_t HW_device_time); -void test_init(void); -void device_sync_init(uint device_nbr); -void device_sync_send(void); -void device_sync_wait(void); diff --git a/tests/bluetooth/bsim/host/att/eatt_notif/src/main.c b/tests/bluetooth/bsim/host/att/eatt_notif/src/main.c deleted file mode 100644 index 2b8cd4054df..00000000000 --- a/tests/bluetooth/bsim/host/att/eatt_notif/src/main.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bstests.h" - -extern struct bst_test_list *test_server_install(struct bst_test_list *tests); -extern struct bst_test_list *test_client_install(struct bst_test_list *tests); - -bst_test_install_t test_installers[] = { - test_server_install, - test_client_install, - NULL -}; - -void main(void) -{ - bst_main(); -} diff --git a/tests/bluetooth/bsim/host/att/eatt_notif/src/server_test.c b/tests/bluetooth/bsim/host/att/eatt_notif/src/server_test.c deleted file mode 100644 index cc20925b49e..00000000000 --- a/tests/bluetooth/bsim/host/att/eatt_notif/src/server_test.c +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "common.h" -#include -#include - -CREATE_FLAG(flag_discover_complete); - -extern enum bst_result_t bst_result; - -CREATE_FLAG(flag_is_connected); - -static struct bt_conn *g_conn; - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - g_conn = bt_conn_ref(conn); - SET_FLAG(flag_is_connected); -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - if (conn != g_conn) { - return; - } - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - printk("Disconnected: %s (reason 0x%02x)\n", addr, reason); - - bt_conn_unref(g_conn); - - g_conn = NULL; - UNSET_FLAG(flag_is_connected); -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - -static uint16_t chrc_handle; - -static uint8_t discover_func(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - struct bt_gatt_discover_params *params) -{ - int err; - - if (attr == NULL) { - if (chrc_handle == 0) { - FAIL("Did not discover chrc (%x)", chrc_handle); - } - - (void)memset(params, 0, sizeof(*params)); - - SET_FLAG(flag_discover_complete); - - return BT_GATT_ITER_STOP; - } - - printk("[ATTRIBUTE] handle %u\n", attr->handle); - - if (params->type == BT_GATT_DISCOVER_PRIMARY && - bt_uuid_cmp(params->uuid, TEST_SERVICE_UUID) == 0) { - printk("Found test service\n"); - params->uuid = NULL; - params->start_handle = attr->handle + 1; - params->type = BT_GATT_DISCOVER_CHARACTERISTIC; - - err = bt_gatt_discover(conn, params); - if (err != 0) { - FAIL("Discover failed (err %d)\n", err); - } - - return BT_GATT_ITER_STOP; - } else if (params->type == BT_GATT_DISCOVER_CHARACTERISTIC) { - const struct bt_gatt_chrc *chrc = (struct bt_gatt_chrc *)attr->user_data; - - if (bt_uuid_cmp(chrc->uuid, TEST_CHRC_UUID) == 0) { - printk("Found chrc value\n"); - chrc_handle = chrc->value_handle; - params->type = BT_GATT_DISCOVER_DESCRIPTOR; - } - } - - return BT_GATT_ITER_CONTINUE; -} - -static void gatt_discover(void) -{ - struct bt_gatt_discover_params discover_params; - int err; - - printk("Discovering services and characteristics\n"); - - discover_params.uuid = TEST_SERVICE_UUID; - discover_params.func = discover_func; - discover_params.start_handle = BT_ATT_FIRST_ATTRIBUTE_HANDLE; - discover_params.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE; - discover_params.type = BT_GATT_DISCOVER_PRIMARY; - discover_params.chan_opt = BT_ATT_CHAN_OPT_NONE; - - err = bt_gatt_discover(g_conn, &discover_params); - if (err != 0) { - FAIL("Discover failed(err %d)\n", err); - } - - printk("Discovery complete\n"); - WAIT_FOR_FLAG(flag_discover_complete); -} - -static uint8_t notify_cb(struct bt_conn *conn, - struct bt_gatt_subscribe_params *params, - const void *data, uint16_t length) -{ - if (!data) { - params->value_handle = 0U; - return BT_GATT_ITER_STOP; - } - - return BT_GATT_ITER_CONTINUE; -} - -void subscribed_cb(struct bt_conn *conn, uint8_t err, - struct bt_gatt_subscribe_params *params) -{ - printk("Subscribed ccc %x val %x\n", - params->value_handle, - params->ccc_handle); - - printk("Sending sync to peer\n"); - device_sync_send(); -} - -static struct bt_gatt_discover_params disc_params; -static struct bt_gatt_subscribe_params subscribe_params; -static void gatt_subscribe(void) -{ - int err; - - subscribe_params.value_handle = chrc_handle; - subscribe_params.notify = notify_cb; - subscribe_params.subscribe = subscribed_cb; - - /* Use the BT_GATT_AUTO_DISCOVER_CCC feature */ - subscribe_params.ccc_handle = 0; - subscribe_params.disc_params = &disc_params, - subscribe_params.value = BT_GATT_CCC_NOTIFY; - subscribe_params.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE; - subscribe_params.chan_opt = BT_ATT_CHAN_OPT_NONE; - - printk("Subscribing: val %x\n", chrc_handle); - err = bt_gatt_subscribe(g_conn, &subscribe_params); - if (err != 0) { - FAIL("Subscription failed(err %d)\n", err); - } -} - -static void test_main(void) -{ - int err; - const struct bt_data ad[] = { - BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)) - }; - - device_sync_init(CENTRAL_ID); - - err = bt_enable(NULL); - if (err != 0) { - FAIL("Bluetooth init failed (err %d)\n", err); - return; - } - - printk("Bluetooth initialized\n"); - - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0); - if (err != 0) { - FAIL("Advertising failed to start (err %d)\n", err); - return; - } - - printk("Advertising successfully started\n"); - - WAIT_FOR_FLAG(flag_is_connected); - - /* Wait for the channels to be connected */ - while (bt_eatt_count(g_conn) < CONFIG_BT_EATT_MAX) { - k_sleep(K_TICKS(1)); - } - - /* Subscribe to the server characteristic. */ - gatt_discover(); - gatt_subscribe(); - - printk("Waiting for final sync\n"); - device_sync_wait(); - - PASS("Server Passed\n"); -} - -static const struct bst_test_instance test_server[] = { - { - .test_id = "server", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_server_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_server); -} diff --git a/tests/bluetooth/bsim/host/att/eatt_notif/test_scripts/eatt_notif.sh b/tests/bluetooth/bsim/host/att/eatt_notif/test_scripts/eatt_notif.sh deleted file mode 100755 index 50201e43ae0..00000000000 --- a/tests/bluetooth/bsim/host/att/eatt_notif/test_scripts/eatt_notif.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -# EATT notification reliability test - -simulation_id="eatt_notif" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 120 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_att_eatt_notif_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=client - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_att_eatt_notif_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=server - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=60e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/att/mtu_update/CMakeLists.txt b/tests/bluetooth/bsim/host/att/mtu_update/CMakeLists.txt deleted file mode 100644 index 443a04d9fe7..00000000000 --- a/tests/bluetooth/bsim/host/att/mtu_update/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set \ - the environment variable BSIM_COMPONENTS_PATH to point to its \ - components folder. More information can be found in \ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_mtu_update) - -target_sources(app PRIVATE - src/main.c - ${ZEPHYR_BASE}/samples/bluetooth/mtu_update/central/src/central_mtu_update.c - ${ZEPHYR_BASE}/samples/bluetooth/mtu_update/peripheral/src/peripheral_mtu_update.c -) - -zephyr_include_directories( - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ -) diff --git a/tests/bluetooth/bsim/host/att/mtu_update/prj.conf b/tests/bluetooth/bsim/host/att/mtu_update/prj.conf deleted file mode 100644 index 95501689df0..00000000000 --- a/tests/bluetooth/bsim/host/att/mtu_update/prj.conf +++ /dev/null @@ -1,16 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_DEVICE_NAME="MTU Update Test" - -CONFIG_BT_GATT_CLIENT=y - -# HCI ACL buffers size -# BT_L2CAP_RX_MTU = CONFIG_BT_BUF_ACL_RX_SIZE - BT_L2CAP_HDR_SIZE -CONFIG_BT_BUF_ACL_RX_SIZE=251 - -# L2CAP SDU/PDU TX MTU -CONFIG_BT_L2CAP_TX_MTU=247 - -CONFIG_LOG=y -CONFIG_BT_L2CAP_LOG_LEVEL_DBG=y diff --git a/tests/bluetooth/bsim/host/att/mtu_update/src/main.c b/tests/bluetooth/bsim/host/att/mtu_update/src/main.c deleted file mode 100644 index f599e49d2e5..00000000000 --- a/tests/bluetooth/bsim/host/att/mtu_update/src/main.c +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -#include - -#include - -#include - -#include "bs_types.h" -#include "bs_tracing.h" -#include "time_machine.h" -#include "bstests.h" - -#include -LOG_MODULE_REGISTER(bt_bsim_mtu_update, LOG_LEVEL_DBG); - -extern void run_central_sample(void *cb); -extern void run_peripheral_sample(uint8_t *notify_data, size_t notify_data_size, uint16_t seconds); - -#define FAIL(...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, __VA_ARGS__); \ - } while (0) - -extern enum bst_result_t bst_result; - -#define CREATE_FLAG(flag) static atomic_t flag = (atomic_t)false -#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)true) -#define WAIT_FOR_FLAG(flag) \ - while (!(bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } - -#define WAIT_TIME (20e6) /* 20 seconds */ -#define PERIPHERAL_NOTIFY_TIME ((WAIT_TIME - 10e6) / 1e6) - -CREATE_FLAG(flag_notification_received); -uint8_t notify_data[100] = {}; -uint8_t is_data_equal; - -static uint8_t notify_cb(struct bt_conn *conn, struct bt_gatt_subscribe_params *params, - const void *data, uint16_t length) -{ - printk("BSIM NOTIFY_CALLBACK\n"); - - is_data_equal = (length == sizeof(notify_data) && !memcmp(notify_data, data, length)); - - LOG_HEXDUMP_DBG(data, length, "notification data"); - LOG_HEXDUMP_DBG(notify_data, sizeof(notify_data), "expected data"); - - SET_FLAG(flag_notification_received); - - return 0; -} - -static void test_central_main(void) -{ - notify_data[13] = 0x7f; - notify_data[99] = 0x55; - - run_central_sample(notify_cb); - - WAIT_FOR_FLAG(flag_notification_received); - - if (is_data_equal) { - PASS("MTU Update test passed\n"); - } else { - FAIL("MTU Update test failed\n"); - } -} - -static void test_peripheral_main(void) -{ - notify_data[13] = 0x7f; - notify_data[99] = 0x55; - - run_peripheral_sample(notify_data, sizeof(notify_data), PERIPHERAL_NOTIFY_TIME); - - PASS("MTU Update test passed\n"); -} - -void test_tick(bs_time_t HW_device_time) -{ - if (bst_result != Passed) { - FAIL("Test failed (not passed after %i seconds)\n", WAIT_TIME); - } -} - -static void test_mtu_update_init(void) -{ - bst_ticker_set_next_tick_absolute(WAIT_TIME); - bst_result = In_progress; -} - -static const struct bst_test_instance test_def[] = { - { - .test_id = "central", - .test_descr = "Central GATT MTU Update", - .test_post_init_f = test_mtu_update_init, - .test_tick_f = test_tick, - .test_main_f = test_central_main - }, - { - .test_id = "peripheral", - .test_descr = "Peripheral GATT MTU Update", - .test_post_init_f = test_mtu_update_init, - .test_tick_f = test_tick, - .test_main_f = test_peripheral_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_mtu_update_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_def); -} - -bst_test_install_t test_installers[] = { - test_mtu_update_install, - NULL -}; - -void main(void) -{ - bst_main(); -} diff --git a/tests/bluetooth/bsim/host/att/mtu_update/test_scripts/_compile.sh b/tests/bluetooth/bsim/host/att/mtu_update/test_scripts/_compile.sh deleted file mode 100755 index 10d6a94dc96..00000000000 --- a/tests/bluetooth/bsim/host/att/mtu_update/test_scripts/_compile.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -set -eu -bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" - -# Read variable definitions output by _env.sh -source <("${bash_source_dir}/_env.sh") - - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" -: "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" -: "${ZEPHYR_BASE:?ZEPHYR_BASE must be defined}" - -WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_bt_out}" -BOARD="${BOARD:-nrf52_bsim}" -BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" -INCR_BUILD=1 -mkdir -p ${WORK_DIR} -source ${ZEPHYR_BASE}/tests/bluetooth/bsim/compile.source -app="tests/bluetooth/bsim/$test_name" compile diff --git a/tests/bluetooth/bsim/host/att/mtu_update/test_scripts/_env.sh b/tests/bluetooth/bsim/host/att/mtu_update/test_scripts/_env.sh deleted file mode 100755 index e8480ac6df6..00000000000 --- a/tests/bluetooth/bsim/host/att/mtu_update/test_scripts/_env.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 -set -eu -bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -test_name="$(basename "$(realpath "$bash_source_dir/..")")" -bsim_bin="${BSIM_OUT_PATH}/bin" -verbosity_level=2 -BOARD="${BOARD:-nrf52_bsim}" -simulation_id="$test_name" -central_exe="${bsim_bin}/bs_${BOARD}_tests_bluetooth_bsim_host_att_mtu_update_prj_conf" -peripheral_exe="${central_exe}" - -function print_var { - # Print a shell-sourceable variable definition. - local var_name="$1" - local var_repr="${!var_name@Q}" - echo "$var_name=$var_repr" -} - -print_var test_name -print_var bsim_bin -print_var verbosity_level -print_var BOARD -print_var simulation_id -print_var central_exe -print_var peripheral_exe diff --git a/tests/bluetooth/bsim/host/att/mtu_update/test_scripts/run_test.sh b/tests/bluetooth/bsim/host/att/mtu_update/test_scripts/run_test.sh deleted file mode 100755 index 896508f9ed1..00000000000 --- a/tests/bluetooth/bsim/host/att/mtu_update/test_scripts/run_test.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -set -eu -bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" - -# Read variable definitions output by _env.sh -source <("${bash_source_dir}/_env.sh") - -process_ids="" -exit_code=0 - -function Execute() { - if [ ! -f $1 ]; then - echo -e " \e[91m$(pwd)/$(basename $1) cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 30 $@ & - process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -cd ${BSIM_OUT_PATH}/bin - -Execute "$central_exe" \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central -RealEncryption=1 - -Execute "$peripheral_exe" \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral -RealEncryption=1 - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=60e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/compile.sh b/tests/bluetooth/bsim/host/compile.sh deleted file mode 100755 index 5b56fb8495b..00000000000 --- a/tests/bluetooth/bsim/host/compile.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -# Compile all the applications needed by the bsim tests - -#set -x #uncomment this line for debugging -set -ue - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" -: "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" -: "${ZEPHYR_BASE:?ZEPHYR_BASE must be set to point to the zephyr root\ - directory}" - -WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_out}" -BOARD="${BOARD:-nrf52_bsim}" -BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" - -mkdir -p ${WORK_DIR} - -source ${ZEPHYR_BASE}/tests/bluetooth/bsim/compile.source - -app=tests/bluetooth/bsim/host/adv/resume compile -app=tests/bluetooth/bsim/host/adv/resume conf_file=prj_2.conf compile -app=tests/bluetooth/bsim/host/adv/chain compile -app=tests/bluetooth/bsim/host/adv/periodic compile -app=tests/bluetooth/bsim/host/adv/periodic conf_file=prj_long_data.conf compile - -app=tests/bluetooth/bsim/host/att/eatt conf_file=prj_collision.conf compile -app=tests/bluetooth/bsim/host/att/eatt conf_file=prj_multiple_conn.conf compile -app=tests/bluetooth/bsim/host/att/eatt conf_file=prj_autoconnect.conf compile -app=tests/bluetooth/bsim/host/att/eatt_notif conf_file=prj.conf compile -app=tests/bluetooth/bsim/host/att/mtu_update compile - -app=tests/bluetooth/bsim/host/gatt/caching compile -app=tests/bluetooth/bsim/host/gatt/general compile -app=tests/bluetooth/bsim/host/gatt/notify compile -app=tests/bluetooth/bsim/host/gatt/notify_multiple compile -app=tests/bluetooth/bsim/host/gatt/settings compile -app=tests/bluetooth/bsim/host/gatt/settings conf_file=prj_2.conf compile -app=tests/bluetooth/bsim/host/gatt/write compile - -app=tests/bluetooth/bsim/host/l2cap/general compile -app=tests/bluetooth/bsim/host/l2cap/userdata compile -app=tests/bluetooth/bsim/host/l2cap/stress compile - -app=tests/bluetooth/bsim/host/misc/disable compile -app=tests/bluetooth/bsim/host/misc/multiple_id compile - -app=tests/bluetooth/bsim/host/privacy/central compile -app=tests/bluetooth/bsim/host/privacy/peripheral compile -app=tests/bluetooth/bsim/host/privacy/device compile - -app=tests/bluetooth/bsim/host/security/bond_overwrite_allowed compile -app=tests/bluetooth/bsim/host/security/bond_overwrite_denied compile - -wait_for_background_jobs diff --git a/tests/bluetooth/bsim/host/gatt/caching/CMakeLists.txt b/tests/bluetooth/bsim/host/gatt/caching/CMakeLists.txt deleted file mode 100644 index 180cb3537fc..00000000000 --- a/tests/bluetooth/bsim/host/gatt/caching/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set\ - the environment variable BSIM_COMPONENTS_PATH to point to its components \ - folder. More information can be found in\ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_gatt) - -FILE(GLOB app_sources src/*.c) -target_sources(app PRIVATE ${app_sources} ) - -zephyr_include_directories( - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ - ) diff --git a/tests/bluetooth/bsim/host/gatt/caching/prj.conf b/tests/bluetooth/bsim/host/gatt/caching/prj.conf deleted file mode 100644 index b7089ee2a5d..00000000000 --- a/tests/bluetooth/bsim/host/gatt/caching/prj.conf +++ /dev/null @@ -1,16 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_DEVICE_NAME="GATT tester" -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_GATT_CLIENT=y - -CONFIG_BT_SMP=y -CONFIG_BT_GATT_DYNAMIC_DB=y -CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y -CONFIG_BT_L2CAP_ECRED=y -CONFIG_BT_EATT=y -CONFIG_BT_EATT_MAX=1 -CONFIG_BT_EATT_AUTO_CONNECT=n - -CONFIG_ASSERT=y -CONFIG_BT_TESTING=y diff --git a/tests/bluetooth/bsim/host/gatt/caching/src/common.c b/tests/bluetooth/bsim/host/gatt/caching/src/common.c deleted file mode 100644 index a7083921905..00000000000 --- a/tests/bluetooth/bsim/host/gatt/caching/src/common.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "common.h" -#include "argparse.h" - -void test_tick(bs_time_t HW_device_time) -{ - if (bst_result != Passed) { - FAIL("test failed (not passed after %i seconds)\n", WAIT_TIME); - } -} - -void test_init(void) -{ - bst_ticker_set_next_tick_absolute(WAIT_TIME); - bst_result = In_progress; -} - -#define CHANNEL_ID 0 -#define MSG_SIZE 1 - -void backchannel_init(void) -{ - uint device_number = get_device_nbr(); - uint peer_number = device_number ^ 1; - uint device_numbers[] = { peer_number }; - uint channel_numbers[] = { CHANNEL_ID }; - uint *ch; - - ch = bs_open_back_channel(device_number, device_numbers, channel_numbers, - ARRAY_SIZE(channel_numbers)); - if (!ch) { - FAIL("Unable to open backchannel\n"); - } -} - -void backchannel_sync_send(void) -{ - uint8_t sync_msg[MSG_SIZE] = { get_device_nbr() }; - - printk("Sending sync\n"); - bs_bc_send_msg(CHANNEL_ID, sync_msg, ARRAY_SIZE(sync_msg)); -} - -void backchannel_sync_wait(void) -{ - uint8_t sync_msg[MSG_SIZE]; - - while (true) { - if (bs_bc_is_msg_received(CHANNEL_ID) > 0) { - bs_bc_receive_msg(CHANNEL_ID, sync_msg, ARRAY_SIZE(sync_msg)); - if (sync_msg[0] != get_device_nbr()) { - /* Received a message from another device, exit */ - break; - } - } - - k_sleep(K_MSEC(1)); - } - - printk("Sync received\n"); -} diff --git a/tests/bluetooth/bsim/host/gatt/caching/src/common.h b/tests/bluetooth/bsim/host/gatt/caching/src/common.h deleted file mode 100644 index d01282ca035..00000000000 --- a/tests/bluetooth/bsim/host/gatt/caching/src/common.h +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Common functions and helpers for BSIM GATT tests - * - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include "bs_types.h" -#include "bs_tracing.h" -#include "time_machine.h" -#include "bstests.h" -#include "bs_pc_backchannel.h" - -#include -#include -#include - -#include -#include -#include -#include -#include - -extern enum bst_result_t bst_result; - -#define WAIT_TIME (60 * 1e6) /*seconds*/ - -#define CREATE_FLAG(flag) static atomic_t flag = (atomic_t)false -#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)true) -#define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)false) -#define WAIT_FOR_FLAG(flag) \ - while (!(bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } - -#define FAIL(...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, __VA_ARGS__); \ - } while (0) - -#define CHRC_SIZE 10 - -#define TEST_SERVICE_UUID \ - BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, \ - 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x00, 0x00) - -#define TEST_CHRC_UUID \ - BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, \ - 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xFF, 0x00) - -#define TEST_ADDITIONAL_CHRC_UUID \ - BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, \ - 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xFF, 0x11) - -void test_tick(bs_time_t HW_device_time); -void test_init(void); -void backchannel_init(void); -void backchannel_sync_send(void); -void backchannel_sync_wait(void); diff --git a/tests/bluetooth/bsim/host/gatt/caching/src/gatt_client_test.c b/tests/bluetooth/bsim/host/gatt/caching/src/gatt_client_test.c deleted file mode 100644 index f9932b62cf3..00000000000 --- a/tests/bluetooth/bsim/host/gatt/caching/src/gatt_client_test.c +++ /dev/null @@ -1,572 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -#include "common.h" - -CREATE_FLAG(flag_is_connected); -CREATE_FLAG(flag_discover_complete); -CREATE_FLAG(flag_write_complete); -CREATE_FLAG(flag_chan_1_read); -CREATE_FLAG(flag_chan_2_read); -CREATE_FLAG(flag_db_hash_read); -CREATE_FLAG(flag_encrypted); - -static struct bt_conn *g_conn; -static uint16_t chrc_handle; -static uint16_t csf_handle; -static const struct bt_uuid *test_svc_uuid = TEST_SERVICE_UUID; - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - - return; - } - - printk("Connected to %s\n", addr); - - SET_FLAG(flag_is_connected); -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - if (conn != g_conn) { - return; - } - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - printk("Disconnected: %s (reason 0x%02x)\n", addr, reason); - - bt_conn_unref(g_conn); - - g_conn = NULL; - UNSET_FLAG(flag_is_connected); -} - -void security_changed(struct bt_conn *conn, bt_security_t level, enum bt_security_err err) -{ - if (err != BT_SECURITY_ERR_SUCCESS) { - FAIL("Encryption failed\n"); - } else if (level < BT_SECURITY_L2) { - FAIL("Insufficient security\n"); - } else { - SET_FLAG(flag_encrypted); - } -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, - .security_changed = security_changed, -}; - -void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, struct net_buf_simple *ad) -{ - char addr_str[BT_ADDR_LE_STR_LEN]; - int err; - - if (g_conn != NULL) { - return; - } - - /* We're only interested in connectable events */ - if (type != BT_HCI_ADV_IND && type != BT_HCI_ADV_DIRECT_IND) { - return; - } - - bt_addr_le_to_str(addr, addr_str, sizeof(addr_str)); - printk("Device found: %s (RSSI %d)\n", addr_str, rssi); - - printk("Stopping scan\n"); - err = bt_le_scan_stop(); - if (err != 0) { - FAIL("Could not stop scan (err %d)\n"); - - return; - } - - err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, BT_LE_CONN_PARAM_DEFAULT, &g_conn); - if (err != 0) { - FAIL("Could not connect to peer (err %d)", err); - } -} - -static uint8_t discover_func(struct bt_conn *conn, const struct bt_gatt_attr *attr, - struct bt_gatt_discover_params *params) -{ - int err; - - if (attr == NULL) { - if (chrc_handle == 0) { - FAIL("Did not discover chrc (%x)\n", chrc_handle); - } - - (void)memset(params, 0, sizeof(*params)); - - SET_FLAG(flag_discover_complete); - - return BT_GATT_ITER_STOP; - } - - printk("[ATTRIBUTE] handle %u\n", attr->handle); - - if (params->type == BT_GATT_DISCOVER_PRIMARY && - bt_uuid_cmp(params->uuid, TEST_SERVICE_UUID) == 0) { - printk("Found test service\n"); - params->uuid = NULL; - params->start_handle = attr->handle + 1; - params->type = BT_GATT_DISCOVER_CHARACTERISTIC; - - err = bt_gatt_discover(conn, params); - if (err != 0) { - FAIL("Discover failed (err %d)\n", err); - } - - return BT_GATT_ITER_STOP; - } else if (params->type == BT_GATT_DISCOVER_CHARACTERISTIC) { - const struct bt_gatt_chrc *chrc = (struct bt_gatt_chrc *)attr->user_data; - - if (bt_uuid_cmp(chrc->uuid, TEST_CHRC_UUID) == 0) { - printk("Found chrc\n"); - chrc_handle = chrc->value_handle; - - } else if (bt_uuid_cmp(chrc->uuid, BT_UUID_GATT_CLIENT_FEATURES) == 0) { - printk("Found csf\n"); - csf_handle = chrc->value_handle; - } - } - - return BT_GATT_ITER_CONTINUE; -} - -static void gatt_discover(const struct bt_uuid *uuid, uint8_t type) -{ - static struct bt_gatt_discover_params discover_params; - int err; - - printk("Discovering services and characteristics\n"); - - discover_params.uuid = uuid; - discover_params.func = discover_func; - discover_params.start_handle = BT_ATT_FIRST_ATTRIBUTE_HANDLE; - discover_params.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE; - discover_params.type = type; - discover_params.chan_opt = BT_ATT_CHAN_OPT_NONE; - - UNSET_FLAG(flag_discover_complete); - - err = bt_gatt_discover(g_conn, &discover_params); - if (err != 0) { - FAIL("Discover failed(err %d)\n", err); - } - - WAIT_FOR_FLAG(flag_discover_complete); - printk("Discover complete\n"); -} -static struct bt_gatt_read_params chan_1_read = { - .handle_count = 1, - .single = { - .handle = 0, /* Will be set later */ - .offset = 0, - }, - .chan_opt = BT_ATT_CHAN_OPT_NONE, -}; -static struct bt_gatt_read_params chan_2_read = { - .handle_count = 1, - .single = { - .handle = 0, /* Will be set later */ - .offset = 0, - }, - .chan_opt = BT_ATT_CHAN_OPT_NONE, -}; -static struct bt_gatt_read_params db_hash_read = { - .handle_count = 0, - .by_uuid = { - .start_handle = BT_ATT_FIRST_ATTRIBUTE_HANDLE, - .end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE, - .uuid = BT_UUID_GATT_DB_HASH, - }, - .chan_opt = BT_ATT_CHAN_OPT_NONE, -}; - -void expect_status(uint8_t err, uint8_t status) -{ - if (err != status) { - FAIL("Unexpected status from read: 0x%02X, expected 0x%02X\n", err, status); - } -} - -static uint8_t gatt_read_expect_success_cb(struct bt_conn *conn, uint8_t err, - struct bt_gatt_read_params *params, const void *data, - uint16_t length) -{ - printk("GATT read cb: err 0x%02X\n", err); - expect_status(err, BT_ATT_ERR_SUCCESS); - - if (params == &db_hash_read) { - SET_FLAG(flag_db_hash_read); - } else if (params == &chan_1_read) { - SET_FLAG(flag_chan_1_read); - } else if (params == &chan_2_read) { - SET_FLAG(flag_chan_2_read); - } else { - FAIL("Unexpected params\n"); - } - - return 0; -} - -static uint8_t gatt_read_expect_err_unlikely_cb(struct bt_conn *conn, uint8_t err, - struct bt_gatt_read_params *params, - const void *data, uint16_t length) -{ - printk("GATT read cb: err 0x%02X\n", err); - expect_status(err, BT_ATT_ERR_UNLIKELY); - - if (params == &chan_1_read) { - SET_FLAG(flag_chan_1_read); - } else if (params == &chan_2_read) { - SET_FLAG(flag_chan_2_read); - } else { - FAIL("Unexpected params\n"); - } - - return 0; -} - -static uint8_t gatt_read_expect_err_out_of_sync_cb(struct bt_conn *conn, uint8_t err, - struct bt_gatt_read_params *params, - const void *data, uint16_t length) -{ - printk("GATT read cb: err 0x%02X\n", err); - expect_status(err, BT_ATT_ERR_DB_OUT_OF_SYNC); - - if (params == &chan_1_read) { - SET_FLAG(flag_chan_1_read); - } else if (params == &chan_2_read) { - SET_FLAG(flag_chan_2_read); - } else { - FAIL("Unexpected params\n"); - } - - return 0; -} - -static void gatt_read(struct bt_gatt_read_params *read_params) -{ - int err; - - printk("Reading\n"); - - err = bt_gatt_read(g_conn, read_params); - if (err != 0) { - FAIL("bt_gatt_read failed: %d\n", err); - } -} - -static void write_cb(struct bt_conn *conn, uint8_t err, struct bt_gatt_write_params *params) -{ - if (err != BT_ATT_ERR_SUCCESS) { - FAIL("Write failed: 0x%02X\n", err); - } - - SET_FLAG(flag_write_complete); -} - -static void enable_robust_caching(void) -{ - /* Client Supported Features Characteristic Value - * Bit 0: Robust Caching - * Bit 1: EATT - */ - static const uint8_t csf[] = { BIT(0) | BIT(1) }; - static struct bt_gatt_write_params write_params = { - .func = write_cb, - .offset = 0, - .data = csf, - .length = sizeof(csf), - .chan_opt = BT_ATT_CHAN_OPT_NONE, - }; - int err; - - printk("Writing to Client Supported Features Characteristic\n"); - - write_params.handle = csf_handle; - UNSET_FLAG(flag_write_complete); - - err = bt_gatt_write(g_conn, &write_params); - if (err) { - FAIL("bt_gatt_write failed (err %d)\n", err); - } - - WAIT_FOR_FLAG(flag_write_complete); - printk("Success\n"); -} - -static void test_main_common(bool connect_eatt) -{ - int err; - - backchannel_init(); - - err = bt_enable(NULL); - if (err != 0) { - FAIL("Bluetooth discover failed (err %d)\n", err); - } - - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); - if (err != 0) { - FAIL("Scanning failed to start (err %d)\n", err); - } - - printk("Scanning successfully started\n"); - - WAIT_FOR_FLAG(flag_is_connected); - - err = bt_conn_set_security(g_conn, BT_SECURITY_L2); - if (err) { - FAIL("Failed to start encryption procedure\n"); - } - - WAIT_FOR_FLAG(flag_encrypted); - - gatt_discover(test_svc_uuid, BT_GATT_DISCOVER_PRIMARY); - gatt_discover(BT_UUID_GATT_CLIENT_FEATURES, BT_GATT_DISCOVER_CHARACTERISTIC); - - enable_robust_caching(); - - if (connect_eatt) { - while (bt_eatt_count(g_conn) < 1) { - /* Wait for EATT channel to connect, in case it hasn't already */ - k_sleep(K_MSEC(10)); - } - } - - /* Tell the server to register additional service */ - backchannel_sync_send(); - - /* Wait for new service to be added by server */ - backchannel_sync_wait(); - - chan_1_read.single.handle = chrc_handle; - chan_2_read.single.handle = chrc_handle; -} - -static void test_main_db_hash_read_eatt(void) -{ - test_main_common(true); - - /* Read the DB hash to become change-aware */ - db_hash_read.func = gatt_read_expect_success_cb; - gatt_read(&db_hash_read); - WAIT_FOR_FLAG(flag_db_hash_read); - - /* These shall now succeed */ - chan_1_read.func = gatt_read_expect_success_cb; - chan_2_read.func = gatt_read_expect_success_cb; - UNSET_FLAG(flag_chan_1_read); - UNSET_FLAG(flag_chan_2_read); - gatt_read(&chan_1_read); - gatt_read(&chan_2_read); - WAIT_FOR_FLAG(flag_chan_1_read); - WAIT_FOR_FLAG(flag_chan_2_read); - - /* Signal to server that reads are done */ - backchannel_sync_send(); - - PASS("GATT client Passed\n"); -} - -static void test_main_out_of_sync_eatt(void) -{ - test_main_common(true); - - chan_1_read.func = gatt_read_expect_err_out_of_sync_cb; - chan_2_read.func = gatt_read_expect_err_out_of_sync_cb; - gatt_read(&chan_1_read); - gatt_read(&chan_2_read); - - /* Wait until received response on both reads. When robust caching is implemented - * on the client side, the waiting shall be done automatically by the host when - * reading the DB hash. - */ - WAIT_FOR_FLAG(flag_chan_1_read); - WAIT_FOR_FLAG(flag_chan_2_read); - - /* Read the DB hash to become change-aware */ - db_hash_read.func = gatt_read_expect_success_cb; - gatt_read(&db_hash_read); - WAIT_FOR_FLAG(flag_db_hash_read); - - /* These shall now succeed */ - chan_1_read.func = gatt_read_expect_success_cb; - chan_2_read.func = gatt_read_expect_success_cb; - UNSET_FLAG(flag_chan_1_read); - UNSET_FLAG(flag_chan_2_read); - gatt_read(&chan_1_read); - gatt_read(&chan_2_read); - WAIT_FOR_FLAG(flag_chan_1_read); - WAIT_FOR_FLAG(flag_chan_2_read); - - /* Signal to server that reads are done */ - backchannel_sync_send(); - - PASS("GATT client Passed\n"); -} - -static void test_main_retry_reads_eatt(void) -{ - test_main_common(true); - - chan_1_read.func = gatt_read_expect_err_out_of_sync_cb; - chan_2_read.func = gatt_read_expect_err_out_of_sync_cb; - gatt_read(&chan_1_read); - gatt_read(&chan_2_read); - - /* Wait until received response on both reads. When robust caching is implemented - * on the client side, the waiting shall be done automatically by the host when - * reading the DB hash. - */ - WAIT_FOR_FLAG(flag_chan_1_read); - WAIT_FOR_FLAG(flag_chan_2_read); - - /* Retry the reads, these shall time out */ - chan_1_read.func = gatt_read_expect_err_unlikely_cb; - chan_2_read.func = gatt_read_expect_err_unlikely_cb; - UNSET_FLAG(flag_chan_1_read); - UNSET_FLAG(flag_chan_2_read); - gatt_read(&chan_1_read); - gatt_read(&chan_2_read); - WAIT_FOR_FLAG(flag_chan_1_read); - WAIT_FOR_FLAG(flag_chan_2_read); - - /* Signal to server that reads are done */ - backchannel_sync_send(); - - PASS("GATT client Passed\n"); -} - -static void test_main_db_hash_read_no_eatt(void) -{ - test_main_common(false); - - /* Read the DB hash to become change-aware */ - db_hash_read.func = gatt_read_expect_success_cb; - gatt_read(&db_hash_read); - WAIT_FOR_FLAG(flag_db_hash_read); - - /* Read shall now succeed */ - chan_1_read.func = gatt_read_expect_success_cb; - UNSET_FLAG(flag_chan_1_read); - gatt_read(&chan_1_read); - WAIT_FOR_FLAG(flag_chan_1_read); - - /* Signal to server that reads are done */ - backchannel_sync_send(); - - PASS("GATT client Passed\n"); -} - -static void test_main_out_of_sync_no_eatt(void) -{ - test_main_common(false); - - chan_1_read.func = gatt_read_expect_err_out_of_sync_cb; - gatt_read(&chan_1_read); - WAIT_FOR_FLAG(flag_chan_1_read); - - /* Read the DB hash to become change-aware */ - db_hash_read.func = gatt_read_expect_success_cb; - gatt_read(&db_hash_read); - WAIT_FOR_FLAG(flag_db_hash_read); - - /* Read shall now succeed */ - chan_1_read.func = gatt_read_expect_success_cb; - UNSET_FLAG(flag_chan_1_read); - gatt_read(&chan_1_read); - WAIT_FOR_FLAG(flag_chan_1_read); - - /* Signal to server that reads are done */ - backchannel_sync_send(); - - PASS("GATT client Passed\n"); -} - -static void test_main_retry_reads_no_eatt(void) -{ - test_main_common(false); - - chan_1_read.func = gatt_read_expect_err_out_of_sync_cb; - gatt_read(&chan_1_read); - WAIT_FOR_FLAG(flag_chan_1_read); - - /* Read again to become change-aware */ - chan_1_read.func = gatt_read_expect_success_cb; - UNSET_FLAG(flag_chan_1_read); - gatt_read(&chan_1_read); - WAIT_FOR_FLAG(flag_chan_1_read); - - /* Signal to server that reads are done */ - backchannel_sync_send(); - - PASS("GATT client Passed\n"); -} - -static const struct bst_test_instance test_vcs[] = { - { - .test_id = "gatt_client_db_hash_read_eatt", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main_db_hash_read_eatt, - }, - { - .test_id = "gatt_client_out_of_sync_eatt", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main_out_of_sync_eatt, - }, - { - .test_id = "gatt_client_retry_reads_eatt", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main_retry_reads_eatt, - }, - { - .test_id = "gatt_client_db_hash_read_no_eatt", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main_db_hash_read_no_eatt, - }, - { - .test_id = "gatt_client_out_of_sync_no_eatt", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main_out_of_sync_no_eatt, - }, - { - .test_id = "gatt_client_retry_reads_no_eatt", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main_retry_reads_no_eatt, - }, - BSTEST_END_MARKER, -}; - -struct bst_test_list *test_gatt_client_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_vcs); -} diff --git a/tests/bluetooth/bsim/host/gatt/caching/src/gatt_server_test.c b/tests/bluetooth/bsim/host/gatt/caching/src/gatt_server_test.c deleted file mode 100644 index 02d8759f342..00000000000 --- a/tests/bluetooth/bsim/host/gatt/caching/src/gatt_server_test.c +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "common.h" - -extern enum bst_result_t bst_result; - -CREATE_FLAG(flag_is_connected); -CREATE_FLAG(flag_is_encrypted); - -static struct bt_conn *g_conn; - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - - return; - } - - printk("Connected to %s\n", addr); - - g_conn = bt_conn_ref(conn); - SET_FLAG(flag_is_connected); -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - if (conn != g_conn) { - return; - } - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - printk("Disconnected: %s (reason 0x%02x)\n", addr, reason); - - bt_conn_unref(g_conn); - - g_conn = NULL; - UNSET_FLAG(flag_is_connected); -} - -static void security_changed(struct bt_conn *conn, bt_security_t level, - enum bt_security_err security_err) -{ - if (security_err == BT_SECURITY_ERR_SUCCESS && level > BT_SECURITY_L1) { - SET_FLAG(flag_is_encrypted); - } -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, - .security_changed = security_changed, -}; - -#define ARRAY_ITEM(i, _) i -static const uint8_t chrc_data[] = { LISTIFY(CHRC_SIZE, ARRAY_ITEM, (,)) }; /* 1, 2, 3 ... */ - -static ssize_t read_test_chrc(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - printk("Characteristic read\n"); - - return bt_gatt_attr_read(conn, attr, buf, len, offset, (const void *)chrc_data, CHRC_SIZE); -} - -BT_GATT_SERVICE_DEFINE(test_svc, BT_GATT_PRIMARY_SERVICE(TEST_SERVICE_UUID), - BT_GATT_CHARACTERISTIC(TEST_CHRC_UUID, BT_GATT_CHRC_READ, BT_GATT_PERM_READ, - read_test_chrc, NULL, NULL)); - -static struct bt_gatt_attr additional_attributes[] = { - BT_GATT_CHARACTERISTIC(TEST_ADDITIONAL_CHRC_UUID, 0, BT_GATT_PERM_NONE, NULL, NULL, NULL), -}; - -static struct bt_gatt_service additional_gatt_service = BT_GATT_SERVICE(additional_attributes); - -static void test_main_common(bool connect_eatt) -{ - int err; - const struct bt_data ad[] = { BT_DATA_BYTES(BT_DATA_FLAGS, - (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)) }; - - backchannel_init(); - - err = bt_enable(NULL); - if (err != 0) { - FAIL("Bluetooth init failed (err %d)\n", err); - - return; - } - - printk("Bluetooth initialized\n"); - - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0); - if (err != 0) { - FAIL("Advertising failed to start (err %d)\n", err); - - return; - } - - printk("Advertising successfully started\n"); - - WAIT_FOR_FLAG(flag_is_connected); - - if (connect_eatt) { - WAIT_FOR_FLAG(flag_is_encrypted); - - err = bt_eatt_connect(g_conn, CONFIG_BT_EATT_MAX); - if (err) { - FAIL("Failed to connect EATT channels (err %d)\n", err); - - return; - } - } - - /* Wait for client to do discovery and configuration */ - backchannel_sync_wait(); - - printk("Registering additional service\n"); - err = bt_gatt_service_register(&additional_gatt_service); - if (err < 0) { - FAIL("Registering additional service failed (err %d)\n", err); - } - - /* Signal to client that additional service is registered */ - backchannel_sync_send(); - - /* Wait for client to be done reading */ - backchannel_sync_wait(); - - PASS("GATT server passed\n"); -} - -static void test_main_eatt(void) -{ - test_main_common(true); -} - -static void test_main_no_eatt(void) -{ - test_main_common(false); -} - -static const struct bst_test_instance test_gatt_server[] = { - { - .test_id = "gatt_server_eatt", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main_eatt, - }, - { - .test_id = "gatt_server_no_eatt", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main_no_eatt, - }, - BSTEST_END_MARKER, -}; - -struct bst_test_list *test_gatt_server_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_gatt_server); -} diff --git a/tests/bluetooth/bsim/host/gatt/caching/src/main.c b/tests/bluetooth/bsim/host/gatt/caching/src/main.c deleted file mode 100644 index 7e2806a0702..00000000000 --- a/tests/bluetooth/bsim/host/gatt/caching/src/main.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bstests.h" - -extern struct bst_test_list *test_gatt_server_install(struct bst_test_list *tests); -extern struct bst_test_list *test_gatt_client_install(struct bst_test_list *tests); - -bst_test_install_t test_installers[] = { - test_gatt_server_install, - test_gatt_client_install, - NULL -}; - -void main(void) -{ - bst_main(); -} diff --git a/tests/bluetooth/bsim/host/gatt/caching/test_scripts/_run_test.sh b/tests/bluetooth/bsim/host/gatt/caching/test_scripts/_run_test.sh deleted file mode 100755 index 3be231bc03d..00000000000 --- a/tests/bluetooth/bsim/host/gatt/caching/test_scripts/_run_test.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -verbosity_level=2 -process_ids="" -exit_code=0 - -function Execute() { - if [ ! -f $1 ]; then - echo -e " \e[91m$(pwd)/$(basename $1) cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 120 $@ & - process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_gatt_caching_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=${client_id} - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_gatt_caching_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=${server_id} - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=60e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_db_hash_read_eatt.sh b/tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_db_hash_read_eatt.sh deleted file mode 100755 index fc9fc3675b5..00000000000 --- a/tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_db_hash_read_eatt.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="gatt_caching_db_hash_read_eatt" \ - client_id="gatt_client_db_hash_read_eatt" \ - server_id="gatt_server_eatt" \ - $(dirname "${BASH_SOURCE[0]}")/_run_test.sh diff --git a/tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_db_hash_read_no_eatt.sh b/tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_db_hash_read_no_eatt.sh deleted file mode 100755 index acafc89515a..00000000000 --- a/tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_db_hash_read_no_eatt.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="gatt_caching_db_hash_read_no_eatt" \ - client_id="gatt_client_db_hash_read_no_eatt" \ - server_id="gatt_server_no_eatt" \ - $(dirname "${BASH_SOURCE[0]}")/_run_test.sh diff --git a/tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_out_of_sync_eatt.sh b/tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_out_of_sync_eatt.sh deleted file mode 100755 index 7326530b023..00000000000 --- a/tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_out_of_sync_eatt.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="gatt_caching_out_of_sync_eatt" \ - client_id="gatt_client_out_of_sync_eatt" \ - server_id="gatt_server_eatt" \ - $(dirname "${BASH_SOURCE[0]}")/_run_test.sh diff --git a/tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_out_of_sync_no_eatt.sh b/tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_out_of_sync_no_eatt.sh deleted file mode 100755 index bfab7cf6c85..00000000000 --- a/tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_out_of_sync_no_eatt.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="gatt_caching_out_of_sync_no_eatt" \ - client_id="gatt_client_out_of_sync_no_eatt" \ - server_id="gatt_server_no_eatt" \ - $(dirname "${BASH_SOURCE[0]}")/_run_test.sh diff --git a/tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_retry_reads_eatt.sh b/tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_retry_reads_eatt.sh deleted file mode 100755 index b9b9c960c45..00000000000 --- a/tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_retry_reads_eatt.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="gatt_caching_retry_reads_eatt" \ - client_id="gatt_client_retry_reads_eatt" \ - server_id="gatt_server_eatt" \ - $(dirname "${BASH_SOURCE[0]}")/_run_test.sh diff --git a/tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_retry_reads_no_eatt.sh b/tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_retry_reads_no_eatt.sh deleted file mode 100755 index 2b7fda8fa94..00000000000 --- a/tests/bluetooth/bsim/host/gatt/caching/test_scripts/gatt_caching_retry_reads_no_eatt.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="gatt_caching_retry_reads_no_eatt" \ - client_id="gatt_client_retry_reads_no_eatt" \ - server_id="gatt_server_no_eatt" \ - $(dirname "${BASH_SOURCE[0]}")/_run_test.sh diff --git a/tests/bluetooth/bsim/host/gatt/general/CMakeLists.txt b/tests/bluetooth/bsim/host/gatt/general/CMakeLists.txt deleted file mode 100644 index 180cb3537fc..00000000000 --- a/tests/bluetooth/bsim/host/gatt/general/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set\ - the environment variable BSIM_COMPONENTS_PATH to point to its components \ - folder. More information can be found in\ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_gatt) - -FILE(GLOB app_sources src/*.c) -target_sources(app PRIVATE ${app_sources} ) - -zephyr_include_directories( - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ - ) diff --git a/tests/bluetooth/bsim/host/gatt/general/prj.conf b/tests/bluetooth/bsim/host/gatt/general/prj.conf deleted file mode 100644 index 7bf1c2b09e8..00000000000 --- a/tests/bluetooth/bsim/host/gatt/general/prj.conf +++ /dev/null @@ -1,6 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_DEVICE_NAME="GATT tester" -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_GATT_CLIENT=y -CONFIG_BT_ATT_PREPARE_COUNT=3 diff --git a/tests/bluetooth/bsim/host/gatt/general/src/common.c b/tests/bluetooth/bsim/host/gatt/general/src/common.c deleted file mode 100644 index df438607c5f..00000000000 --- a/tests/bluetooth/bsim/host/gatt/general/src/common.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "common.h" - -void test_tick(bs_time_t HW_device_time) -{ - if (bst_result != Passed) { - FAIL("test failed (not passed after %i seconds)\n", WAIT_TIME); - } -} - -void test_init(void) -{ - bst_ticker_set_next_tick_absolute(WAIT_TIME); - bst_result = In_progress; -} diff --git a/tests/bluetooth/bsim/host/gatt/general/src/common.h b/tests/bluetooth/bsim/host/gatt/general/src/common.h deleted file mode 100644 index 3fad93c7894..00000000000 --- a/tests/bluetooth/bsim/host/gatt/general/src/common.h +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Common functions and helpers for BSIM GATT tests - * - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include "bs_types.h" -#include "bs_tracing.h" -#include "time_machine.h" -#include "bstests.h" - -#include -#include -#include - -#include -#include -#include -#include -#include - -extern enum bst_result_t bst_result; - -#define WAIT_TIME (30 * 1e6) /*seconds*/ - -#define CREATE_FLAG(flag) static atomic_t flag = (atomic_t)false -#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)true) -#define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)false) -#define WAIT_FOR_FLAG(flag) \ - while (!(bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } - -#define FAIL(...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, __VA_ARGS__); \ - } while (0) - -#define CHRC_SIZE 10 -#define LONG_CHRC_SIZE 40 - -#define TEST_SERVICE_UUID \ - BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, \ - 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x00, 0x00) - -#define TEST_CHRC_UUID \ - BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, \ - 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xFF, 0x00) - -#define TEST_LONG_CHRC_UUID \ - BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, \ - 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xFF, 0x11) - -void test_tick(bs_time_t HW_device_time); -void test_init(void); diff --git a/tests/bluetooth/bsim/host/gatt/general/src/gatt_client_test.c b/tests/bluetooth/bsim/host/gatt/general/src/gatt_client_test.c deleted file mode 100644 index 3b535965209..00000000000 --- a/tests/bluetooth/bsim/host/gatt/general/src/gatt_client_test.c +++ /dev/null @@ -1,304 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -#include "common.h" - -CREATE_FLAG(flag_is_connected); -CREATE_FLAG(flag_discover_complete); -CREATE_FLAG(flag_write_complete); -CREATE_FLAG(flag_read_complete); - -static struct bt_conn *g_conn; -static uint16_t chrc_handle; -static uint16_t long_chrc_handle; -static struct bt_uuid *test_svc_uuid = TEST_SERVICE_UUID; - -#define ARRAY_ITEM(i, _) i -static uint8_t chrc_data[] = { LISTIFY(CHRC_SIZE, ARRAY_ITEM, (,)) }; /* 1, 2, 3 ... */ -static uint8_t long_chrc_data[] = { LISTIFY(LONG_CHRC_SIZE, ARRAY_ITEM, (,)) }; /* 1, 2, 3 ... */ - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - - g_conn = conn; - SET_FLAG(flag_is_connected); -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - if (conn != g_conn) { - return; - } - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - printk("Disconnected: %s (reason 0x%02x)\n", addr, reason); - - bt_conn_unref(g_conn); - - g_conn = NULL; - UNSET_FLAG(flag_is_connected); -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - -void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, - struct net_buf_simple *ad) -{ - char addr_str[BT_ADDR_LE_STR_LEN]; - int err; - - if (g_conn != NULL) { - return; - } - - /* We're only interested in connectable events */ - if (type != BT_HCI_ADV_IND && type != BT_HCI_ADV_DIRECT_IND) { - return; - } - - bt_addr_le_to_str(addr, addr_str, sizeof(addr_str)); - printk("Device found: %s (RSSI %d)\n", addr_str, rssi); - - printk("Stopping scan\n"); - err = bt_le_scan_stop(); - if (err != 0) { - FAIL("Could not stop scan: %d"); - return; - } - - err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, - BT_LE_CONN_PARAM_DEFAULT, &g_conn); - if (err != 0) { - FAIL("Could not connect to peer: %d", err); - } -} - -static uint8_t discover_func(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - struct bt_gatt_discover_params *params) -{ - int err; - - if (attr == NULL) { - if (chrc_handle == 0 || long_chrc_handle == 0) { - FAIL("Did not discover chrc (%x) or long_chrc (%x)", - chrc_handle, long_chrc_handle); - } - - (void)memset(params, 0, sizeof(*params)); - - SET_FLAG(flag_discover_complete); - - return BT_GATT_ITER_STOP; - } - - printk("[ATTRIBUTE] handle %u\n", attr->handle); - - if (params->type == BT_GATT_DISCOVER_PRIMARY && - bt_uuid_cmp(params->uuid, TEST_SERVICE_UUID) == 0) { - printk("Found test service\n"); - params->uuid = NULL; - params->start_handle = attr->handle + 1; - params->type = BT_GATT_DISCOVER_CHARACTERISTIC; - - err = bt_gatt_discover(conn, params); - if (err != 0) { - FAIL("Discover failed (err %d)\n", err); - } - - return BT_GATT_ITER_STOP; - } else if (params->type == BT_GATT_DISCOVER_CHARACTERISTIC) { - struct bt_gatt_chrc *chrc = (struct bt_gatt_chrc *)attr->user_data; - - if (bt_uuid_cmp(chrc->uuid, TEST_CHRC_UUID) == 0) { - printk("Found chrc\n"); - chrc_handle = chrc->value_handle; - } else if (bt_uuid_cmp(chrc->uuid, TEST_LONG_CHRC_UUID) == 0) { - printk("Found long_chrc\n"); - long_chrc_handle = chrc->value_handle; - } - } - - return BT_GATT_ITER_CONTINUE; -} - -static void gatt_discover(void) -{ - static struct bt_gatt_discover_params discover_params; - int err; - - printk("Discovering services and characteristics\n"); - - discover_params.uuid = test_svc_uuid; - discover_params.func = discover_func; - discover_params.start_handle = BT_ATT_FIRST_ATTRIBUTE_HANDLE; - discover_params.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE; - discover_params.type = BT_GATT_DISCOVER_PRIMARY; - - err = bt_gatt_discover(g_conn, &discover_params); - if (err != 0) { - FAIL("Discover failed(err %d)\n", err); - } - - WAIT_FOR_FLAG(flag_discover_complete); - printk("Discover complete\n"); -} - -static void gatt_write_cb(struct bt_conn *conn, uint8_t err, - struct bt_gatt_write_params *params) -{ - if (err != BT_ATT_ERR_SUCCESS) { - FAIL("Write failed: 0x%02X\n", err); - } - - (void)memset(params, 0, sizeof(*params)); - - SET_FLAG(flag_write_complete); -} - -static void gatt_write(uint16_t handle) -{ - static struct bt_gatt_write_params write_params; - int err; - - if (handle == chrc_handle) { - printk("Writing to chrc\n"); - write_params.data = chrc_data; - write_params.length = sizeof(chrc_data); - } else if (handle) { - printk("Writing to long_chrc\n"); - write_params.data = long_chrc_data; - write_params.length = sizeof(long_chrc_data); - } - - write_params.func = gatt_write_cb; - write_params.handle = handle; - - UNSET_FLAG(flag_write_complete); - - err = bt_gatt_write(g_conn, &write_params); - if (err != 0) { - FAIL("bt_gatt_write failed: %d\n", err); - } - - WAIT_FOR_FLAG(flag_write_complete); - printk("success\n"); -} - -static uint8_t gatt_read_cb(struct bt_conn *conn, uint8_t err, - struct bt_gatt_read_params *params, - const void *data, uint16_t length) -{ - if (err != BT_ATT_ERR_SUCCESS) { - FAIL("Read failed: 0x%02X\n", err); - } - - if (params->single.handle == chrc_handle) { - if (length != CHRC_SIZE || - memcmp(data, chrc_data, length) != 0) { - FAIL("chrc data different than expected", err); - } - } else if (params->single.handle == chrc_handle) { - if (length != LONG_CHRC_SIZE || - memcmp(data, long_chrc_data, length) != 0) { - FAIL("long_chrc data different than expected", err); - } - } - - (void)memset(params, 0, sizeof(*params)); - - SET_FLAG(flag_read_complete); - - return 0; -} - -static void gatt_read(uint16_t handle) -{ - static struct bt_gatt_read_params read_params; - int err; - - printk("Reading chrc\n"); - - read_params.func = gatt_read_cb; - read_params.handle_count = 1; - read_params.single.handle = chrc_handle; - read_params.single.offset = 0; - - UNSET_FLAG(flag_read_complete); - - err = bt_gatt_read(g_conn, &read_params); - if (err != 0) { - FAIL("bt_gatt_read failed: %d\n", err); - } - - WAIT_FOR_FLAG(flag_read_complete); - printk("success\n"); -} - -static void test_main(void) -{ - int err; - - err = bt_enable(NULL); - if (err != 0) { - FAIL("Bluetooth discover failed (err %d)\n", err); - } - - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); - if (err != 0) { - FAIL("Scanning failed to start (err %d)\n", err); - } - - printk("Scanning successfully started\n"); - - WAIT_FOR_FLAG(flag_is_connected); - - gatt_discover(); - - /* Write and read a few times to ensure stateless behavior */ - for (size_t i = 0; i < 3; i++) { - gatt_write(chrc_handle); - gatt_read(chrc_handle); - gatt_write(long_chrc_handle); - gatt_read(long_chrc_handle); - } - - PASS("GATT client Passed\n"); -} - -static const struct bst_test_instance test_vcs[] = { - { - .test_id = "gatt_client", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_gatt_client_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_vcs); -} diff --git a/tests/bluetooth/bsim/host/gatt/general/src/gatt_server_test.c b/tests/bluetooth/bsim/host/gatt/general/src/gatt_server_test.c deleted file mode 100644 index 475a52d268c..00000000000 --- a/tests/bluetooth/bsim/host/gatt/general/src/gatt_server_test.c +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "common.h" - -extern enum bst_result_t bst_result; - -CREATE_FLAG(flag_is_connected); - -static struct bt_conn *g_conn; - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - - g_conn = bt_conn_ref(conn); - SET_FLAG(flag_is_connected); -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - if (conn != g_conn) { - return; - } - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - printk("Disconnected: %s (reason 0x%02x)\n", addr, reason); - - bt_conn_unref(g_conn); - - g_conn = NULL; - UNSET_FLAG(flag_is_connected); -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - -static uint8_t chrc_data[CHRC_SIZE]; -static uint8_t long_chrc_data[LONG_CHRC_SIZE]; - -static ssize_t read_test_chrc(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) -{ - return bt_gatt_attr_read(conn, attr, buf, len, offset, - (void *)chrc_data, sizeof(chrc_data)); -} - -static ssize_t write_test_chrc(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, - uint16_t offset, uint8_t flags) -{ - printk("chrc len %u offset %u\n", len, offset); - - if (len > sizeof(chrc_data)) { - printk("Invalid chrc length\n"); - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - } else if (offset + len > sizeof(chrc_data)) { - printk("Invalid chrc offset and length\n"); - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - } - - if (flags != 0) { - FAIL("Invalid flags %u\n", flags); - return BT_GATT_ERR(BT_ATT_ERR_UNLIKELY); - } - - (void)memcpy(chrc_data + offset, buf, len); - - return len; -} - -static ssize_t read_long_test_chrc(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) -{ - return bt_gatt_attr_read(conn, attr, buf, len, offset, - (void *)long_chrc_data, sizeof(long_chrc_data)); -} - -static ssize_t write_long_test_chrc(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, - uint16_t offset, uint8_t flags) -{ - static uint8_t prepare_count; - - printk("long_chrc len %u offset %u\n", len, offset); - - if (len > sizeof(long_chrc_data)) { - printk("Invalid long_chrc length\n"); - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - } else if (offset + len > sizeof(long_chrc_data)) { - printk("Invalid long_chrc offset and length\n"); - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - } - - if (flags & BT_GATT_WRITE_FLAG_PREPARE) { - printk("prepare_count %u\n", prepare_count++); - return BT_GATT_ERR(BT_ATT_ERR_SUCCESS); - } - - (void)memcpy(long_chrc_data + offset, buf, len); - prepare_count = 0; - - return len; -} - -BT_GATT_SERVICE_DEFINE(test_svc, - BT_GATT_PRIMARY_SERVICE(TEST_SERVICE_UUID), - BT_GATT_CHARACTERISTIC(TEST_CHRC_UUID, - BT_GATT_CHRC_WRITE | BT_GATT_CHRC_READ, - BT_GATT_PERM_WRITE | BT_GATT_PERM_READ, - read_test_chrc, write_test_chrc, NULL), - BT_GATT_CHARACTERISTIC(TEST_LONG_CHRC_UUID, - BT_GATT_CHRC_WRITE | BT_GATT_CHRC_READ, - BT_GATT_PERM_WRITE | BT_GATT_PERM_READ | BT_GATT_PERM_PREPARE_WRITE, - read_long_test_chrc, write_long_test_chrc, NULL), -); - -static void test_main(void) -{ - int err; - const struct bt_data ad[] = { - BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)) - }; - - err = bt_enable(NULL); - if (err != 0) { - FAIL("Bluetooth init failed (err %d)\n", err); - return; - } - - printk("Bluetooth initialized\n"); - - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0); - if (err != 0) { - FAIL("Advertising failed to start (err %d)\n", err); - return; - } - - printk("Advertising successfully started\n"); - - WAIT_FOR_FLAG(flag_is_connected); - - PASS("GATT server passed\n"); -} - -static const struct bst_test_instance test_gatt_server[] = { - { - .test_id = "gatt_server", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_gatt_server_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_gatt_server); -} diff --git a/tests/bluetooth/bsim/host/gatt/general/src/main.c b/tests/bluetooth/bsim/host/gatt/general/src/main.c deleted file mode 100644 index 7e2806a0702..00000000000 --- a/tests/bluetooth/bsim/host/gatt/general/src/main.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bstests.h" - -extern struct bst_test_list *test_gatt_server_install(struct bst_test_list *tests); -extern struct bst_test_list *test_gatt_client_install(struct bst_test_list *tests); - -bst_test_install_t test_installers[] = { - test_gatt_server_install, - test_gatt_client_install, - NULL -}; - -void main(void) -{ - bst_main(); -} diff --git a/tests/bluetooth/bsim/host/gatt/general/test_scripts/gatt.sh b/tests/bluetooth/bsim/host/gatt/general/test_scripts/gatt.sh deleted file mode 100755 index a5f1c1a10fb..00000000000 --- a/tests/bluetooth/bsim/host/gatt/general/test_scripts/gatt.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -# Basic GATT test: A central acting as a GATT client scans for and connects -# to a peripheral acting as a GATT server. The GATT client will then attempt -# to write and read to and from a few GATT characteristics. -simulation_id="gatt" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 120 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_gatt_general_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=gatt_client - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_gatt_general_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=gatt_server - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=60e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/gatt/notify/CMakeLists.txt b/tests/bluetooth/bsim/host/gatt/notify/CMakeLists.txt deleted file mode 100644 index 180cb3537fc..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set\ - the environment variable BSIM_COMPONENTS_PATH to point to its components \ - folder. More information can be found in\ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_gatt) - -FILE(GLOB app_sources src/*.c) -target_sources(app PRIVATE ${app_sources} ) - -zephyr_include_directories( - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ - ) diff --git a/tests/bluetooth/bsim/host/gatt/notify/prj.conf b/tests/bluetooth/bsim/host/gatt/notify/prj.conf deleted file mode 100644 index 3040eee6aca..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify/prj.conf +++ /dev/null @@ -1,17 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_DEVICE_NAME="GATT tester" -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_GATT_CLIENT=y - -CONFIG_BT_GATT_AUTO_DISCOVER_CCC=y - -CONFIG_BT_SMP=y -CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y -CONFIG_BT_L2CAP_ECRED=y -CONFIG_BT_EATT=y -CONFIG_BT_EATT_MAX=5 - -CONFIG_ASSERT=y -CONFIG_BT_TESTING=y -CONFIG_BT_DEBUG_LOG=y diff --git a/tests/bluetooth/bsim/host/gatt/notify/src/common.c b/tests/bluetooth/bsim/host/gatt/notify/src/common.c deleted file mode 100644 index df438607c5f..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify/src/common.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "common.h" - -void test_tick(bs_time_t HW_device_time) -{ - if (bst_result != Passed) { - FAIL("test failed (not passed after %i seconds)\n", WAIT_TIME); - } -} - -void test_init(void) -{ - bst_ticker_set_next_tick_absolute(WAIT_TIME); - bst_result = In_progress; -} diff --git a/tests/bluetooth/bsim/host/gatt/notify/src/common.h b/tests/bluetooth/bsim/host/gatt/notify/src/common.h deleted file mode 100644 index 67486b175e4..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify/src/common.h +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Common functions and helpers for BSIM GATT tests - * - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include "bs_types.h" -#include "bs_tracing.h" -#include "time_machine.h" -#include "bstests.h" - -#include -#include -#include - -#include -#include -#include -#include -#include - -extern enum bst_result_t bst_result; - -#define WAIT_TIME (60 * 1e6) /*seconds*/ - -#define CREATE_FLAG(flag) static atomic_t flag = (atomic_t)false -#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)true) -#define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)false) -#define WAIT_FOR_FLAG(flag) \ - while (!(bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } - -#define FAIL(...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, __VA_ARGS__); \ - } while (0) - -#define CHRC_SIZE 10 -#define LONG_CHRC_SIZE 40 - -#define TEST_SERVICE_UUID \ - BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, \ - 0x07, 0x08, 0x09, 0x00, 0x00) - -#define TEST_CHRC_UUID \ - BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, \ - 0x07, 0x08, 0x09, 0xFF, 0x00) - -#define TEST_LONG_CHRC_UUID \ - BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, \ - 0x07, 0x08, 0x09, 0xFF, 0x11) - -void test_tick(bs_time_t HW_device_time); -void test_init(void); - -#define NOTIFICATION_COUNT 10 -BUILD_ASSERT(NOTIFICATION_COUNT % 2 == 0); diff --git a/tests/bluetooth/bsim/host/gatt/notify/src/gatt_client_test.c b/tests/bluetooth/bsim/host/gatt/notify/src/gatt_client_test.c deleted file mode 100644 index e31c275e62e..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify/src/gatt_client_test.c +++ /dev/null @@ -1,469 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -#include "common.h" - -CREATE_FLAG(flag_is_connected); -CREATE_FLAG(flag_is_encrypted); -CREATE_FLAG(flag_discover_complete); -CREATE_FLAG(flag_short_subscribed); -CREATE_FLAG(flag_long_subscribed); - -static struct bt_conn *g_conn; -static uint16_t chrc_handle; -static uint16_t long_chrc_handle; -static struct bt_uuid *test_svc_uuid = TEST_SERVICE_UUID; - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - - SET_FLAG(flag_is_connected); -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - if (conn != g_conn) { - return; - } - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - printk("Disconnected: %s (reason 0x%02x)\n", addr, reason); - - bt_conn_unref(g_conn); - - g_conn = NULL; - UNSET_FLAG(flag_is_connected); -} - -void security_changed(struct bt_conn *conn, bt_security_t level, enum bt_security_err err) -{ - if (err) { - FAIL("Encryption failer (%d)\n", err); - } else if (level < BT_SECURITY_L2) { - FAIL("Insufficient sec level (%d)\n", level); - } else { - SET_FLAG(flag_is_encrypted); - } -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, - .security_changed = security_changed, -}; - -void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, struct net_buf_simple *ad) -{ - char addr_str[BT_ADDR_LE_STR_LEN]; - int err; - - if (g_conn != NULL) { - return; - } - - /* We're only interested in connectable events */ - if (type != BT_HCI_ADV_IND && type != BT_HCI_ADV_DIRECT_IND) { - return; - } - - bt_addr_le_to_str(addr, addr_str, sizeof(addr_str)); - printk("Device found: %s (RSSI %d)\n", addr_str, rssi); - - printk("Stopping scan\n"); - err = bt_le_scan_stop(); - if (err != 0) { - FAIL("Could not stop scan: %d"); - return; - } - - err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, BT_LE_CONN_PARAM_DEFAULT, &g_conn); - if (err != 0) { - FAIL("Could not connect to peer: %d", err); - } -} - -static uint8_t discover_func(struct bt_conn *conn, const struct bt_gatt_attr *attr, - struct bt_gatt_discover_params *params) -{ - int err; - - if (attr == NULL) { - if (chrc_handle == 0 || long_chrc_handle == 0) { - FAIL("Did not discover chrc (%x) or long_chrc (%x)", chrc_handle, - long_chrc_handle); - } - - (void)memset(params, 0, sizeof(*params)); - - SET_FLAG(flag_discover_complete); - - return BT_GATT_ITER_STOP; - } - - printk("[ATTRIBUTE] handle %u\n", attr->handle); - - if (params->type == BT_GATT_DISCOVER_PRIMARY && - bt_uuid_cmp(params->uuid, TEST_SERVICE_UUID) == 0) { - printk("Found test service\n"); - params->uuid = NULL; - params->start_handle = attr->handle + 1; - params->type = BT_GATT_DISCOVER_CHARACTERISTIC; - - err = bt_gatt_discover(conn, params); - if (err != 0) { - FAIL("Discover failed (err %d)\n", err); - } - - return BT_GATT_ITER_STOP; - } else if (params->type == BT_GATT_DISCOVER_CHARACTERISTIC) { - const struct bt_gatt_chrc *chrc = (struct bt_gatt_chrc *)attr->user_data; - - if (bt_uuid_cmp(chrc->uuid, TEST_CHRC_UUID) == 0) { - printk("Found chrc\n"); - chrc_handle = chrc->value_handle; - } else if (bt_uuid_cmp(chrc->uuid, TEST_LONG_CHRC_UUID) == 0) { - printk("Found long_chrc\n"); - long_chrc_handle = chrc->value_handle; - } - } - - return BT_GATT_ITER_CONTINUE; -} - -static void gatt_discover(enum bt_att_chan_opt opt) -{ - static struct bt_gatt_discover_params discover_params; - int err; - - printk("Discovering services and characteristics\n"); - - discover_params.uuid = test_svc_uuid; - discover_params.func = discover_func; - discover_params.start_handle = BT_ATT_FIRST_ATTRIBUTE_HANDLE; - discover_params.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE; - discover_params.type = BT_GATT_DISCOVER_PRIMARY; - discover_params.chan_opt = opt; - - err = bt_gatt_discover(g_conn, &discover_params); - if (err != 0) { - FAIL("Discover failed(err %d)\n", err); - } - - WAIT_FOR_FLAG(flag_discover_complete); - printk("Discover complete\n"); -} - -static void test_short_subscribed(struct bt_conn *conn, uint8_t err, - struct bt_gatt_write_params *params) -{ - if (err) { - FAIL("Subscribe failed (err %d)\n", err); - } - - SET_FLAG(flag_short_subscribed); - - if (!params) { - printk("params NULL\n"); - return; - } - - if (params->handle == chrc_handle) { - printk("Subscribed to short characteristic\n"); - } else { - FAIL("Unknown handle %d\n", params->handle); - } -} - -static void test_long_subscribed(struct bt_conn *conn, uint8_t err, - struct bt_gatt_write_params *params) -{ - if (err) { - FAIL("Subscribe failed (err %d)\n", err); - } - - SET_FLAG(flag_long_subscribed); - - if (!params) { - printk("params NULL\n"); - return; - } - - if (params->handle == long_chrc_handle) { - printk("Subscribed to long characteristic\n"); - } else { - FAIL("Unknown handle %d\n", params->handle); - } -} - -static volatile size_t num_notifications; -uint8_t test_notify(struct bt_conn *conn, struct bt_gatt_subscribe_params *params, const void *data, - uint16_t length) -{ - printk("Received notification #%u with length %d\n", num_notifications++, length); - - return BT_GATT_ITER_CONTINUE; -} - -static struct bt_gatt_discover_params disc_params_short; -static struct bt_gatt_subscribe_params sub_params_short = { - .notify = test_notify, - .write = test_short_subscribed, - .ccc_handle = 0, /* Auto-discover CCC*/ - .disc_params = &disc_params_short, /* Auto-discover CCC */ - .end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE, - .value = BT_GATT_CCC_NOTIFY, -}; -static struct bt_gatt_discover_params disc_params_long; -static struct bt_gatt_subscribe_params sub_params_long = { - .notify = test_notify, - .write = test_long_subscribed, - .ccc_handle = 0, /* Auto-discover CCC*/ - .disc_params = &disc_params_long, /* Auto-discover CCC */ - .end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE, - .value = BT_GATT_CCC_NOTIFY, -}; - -static void gatt_subscribe_short(enum bt_att_chan_opt opt) -{ - int err; - - sub_params_short.value_handle = chrc_handle; - sub_params_short.chan_opt = opt; - err = bt_gatt_subscribe(g_conn, &sub_params_short); - if (err < 0) { - FAIL("Failed to subscribe\n"); - } else { - printk("Subscribe request sent\n"); - } -} - -static void gatt_unsubscribe_short(enum bt_att_chan_opt opt) -{ - int err; - - sub_params_short.value_handle = chrc_handle; - sub_params_short.chan_opt = opt; - err = bt_gatt_unsubscribe(g_conn, &sub_params_short); - if (err < 0) { - FAIL("Failed to unsubscribe\n"); - } else { - printk("Unsubscribe request sent\n"); - } -} - -static void gatt_subscribe_long(enum bt_att_chan_opt opt) -{ - int err; - - UNSET_FLAG(flag_long_subscribed); - sub_params_long.value_handle = long_chrc_handle; - sub_params_long.chan_opt = opt; - err = bt_gatt_subscribe(g_conn, &sub_params_long); - if (err < 0) { - FAIL("Failed to subscribe\n"); - } else { - printk("Subscribe request sent\n"); - } -} - -static void gatt_unsubscribe_long(enum bt_att_chan_opt opt) -{ - int err; - - UNSET_FLAG(flag_long_subscribed); - sub_params_long.value_handle = long_chrc_handle; - sub_params_long.chan_opt = opt; - err = bt_gatt_unsubscribe(g_conn, &sub_params_long); - if (err < 0) { - FAIL("Failed to unsubscribe\n"); - } else { - printk("Unsubscribe request sent\n"); - } -} - -static void setup(void) -{ - int err; - - err = bt_enable(NULL); - if (err != 0) { - FAIL("Bluetooth discover failed (err %d)\n", err); - } - - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); - if (err != 0) { - FAIL("Scanning failed to start (err %d)\n", err); - } - - printk("Scanning successfully started\n"); - - WAIT_FOR_FLAG(flag_is_connected); - - err = bt_conn_set_security(g_conn, BT_SECURITY_L2); - if (err) { - FAIL("Starting encryption procedure failed (%d)\n", err); - } - - WAIT_FOR_FLAG(flag_is_encrypted); - - while (bt_eatt_count(g_conn) < CONFIG_BT_EATT_MAX) { - k_sleep(K_MSEC(10)); - } - - printk("EATT connected\n"); -} - -static void test_main_none(void) -{ - setup(); - - gatt_discover(BT_ATT_CHAN_OPT_NONE); - gatt_subscribe_short(BT_ATT_CHAN_OPT_NONE); - gatt_subscribe_long(BT_ATT_CHAN_OPT_NONE); - WAIT_FOR_FLAG(flag_short_subscribed); - WAIT_FOR_FLAG(flag_long_subscribed); - printk("Subscribed\n"); - - while (num_notifications < NOTIFICATION_COUNT) { - k_sleep(K_MSEC(100)); - } - - gatt_unsubscribe_short(BT_ATT_CHAN_OPT_NONE); - gatt_unsubscribe_long(BT_ATT_CHAN_OPT_NONE); - WAIT_FOR_FLAG(flag_short_subscribed); - WAIT_FOR_FLAG(flag_long_subscribed); - - printk("Unsubscribed\n"); - - PASS("GATT client Passed\n"); -} - -static void test_main_unenhanced(void) -{ - setup(); - - gatt_discover(BT_ATT_CHAN_OPT_UNENHANCED_ONLY); - gatt_subscribe_short(BT_ATT_CHAN_OPT_UNENHANCED_ONLY); - gatt_subscribe_long(BT_ATT_CHAN_OPT_UNENHANCED_ONLY); - WAIT_FOR_FLAG(flag_short_subscribed); - WAIT_FOR_FLAG(flag_long_subscribed); - - printk("Subscribed\n"); - - while (num_notifications < NOTIFICATION_COUNT) { - k_sleep(K_MSEC(100)); - } - - gatt_unsubscribe_short(BT_ATT_CHAN_OPT_UNENHANCED_ONLY); - gatt_unsubscribe_long(BT_ATT_CHAN_OPT_UNENHANCED_ONLY); - WAIT_FOR_FLAG(flag_short_subscribed); - WAIT_FOR_FLAG(flag_long_subscribed); - - printk("Unsubscribed\n"); - - PASS("GATT client Passed\n"); -} - -static void test_main_enhanced(void) -{ - setup(); - - gatt_discover(BT_ATT_CHAN_OPT_ENHANCED_ONLY); - gatt_subscribe_short(BT_ATT_CHAN_OPT_ENHANCED_ONLY); - gatt_subscribe_long(BT_ATT_CHAN_OPT_ENHANCED_ONLY); - WAIT_FOR_FLAG(flag_short_subscribed); - WAIT_FOR_FLAG(flag_long_subscribed); - - printk("Subscribed\n"); - - while (num_notifications < NOTIFICATION_COUNT) { - k_sleep(K_MSEC(100)); - } - - gatt_unsubscribe_short(BT_ATT_CHAN_OPT_ENHANCED_ONLY); - gatt_unsubscribe_long(BT_ATT_CHAN_OPT_ENHANCED_ONLY); - WAIT_FOR_FLAG(flag_short_subscribed); - WAIT_FOR_FLAG(flag_long_subscribed); - - printk("Unsubscribed\n"); - - PASS("GATT client Passed\n"); -} - -static void test_main_mixed(void) -{ - setup(); - - gatt_discover(BT_ATT_CHAN_OPT_ENHANCED_ONLY); - gatt_subscribe_short(BT_ATT_CHAN_OPT_ENHANCED_ONLY); - gatt_subscribe_long(BT_ATT_CHAN_OPT_UNENHANCED_ONLY); - WAIT_FOR_FLAG(flag_short_subscribed); - WAIT_FOR_FLAG(flag_long_subscribed); - - printk("Subscribed\n"); - - while (num_notifications < NOTIFICATION_COUNT) { - k_sleep(K_MSEC(100)); - } - - gatt_unsubscribe_short(BT_ATT_CHAN_OPT_UNENHANCED_ONLY); - gatt_unsubscribe_long(BT_ATT_CHAN_OPT_ENHANCED_ONLY); - WAIT_FOR_FLAG(flag_short_subscribed); - WAIT_FOR_FLAG(flag_long_subscribed); - - printk("Unsubscribed\n"); - - PASS("GATT client Passed\n"); -} - -static const struct bst_test_instance test_vcs[] = { - { - .test_id = "gatt_client_none", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main_none, - }, - { - .test_id = "gatt_client_unenhanced", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main_unenhanced, - }, - { - .test_id = "gatt_client_enhanced", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main_enhanced, - }, - { - .test_id = "gatt_client_mixed", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main_mixed, - }, - BSTEST_END_MARKER, -}; - -struct bst_test_list *test_gatt_client_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_vcs); -} diff --git a/tests/bluetooth/bsim/host/gatt/notify/src/gatt_server_test.c b/tests/bluetooth/bsim/host/gatt/notify/src/gatt_server_test.c deleted file mode 100644 index e60659876ad..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify/src/gatt_server_test.c +++ /dev/null @@ -1,300 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "common.h" - -extern enum bst_result_t bst_result; - -CREATE_FLAG(flag_is_connected); -CREATE_FLAG(flag_short_subscribe); -CREATE_FLAG(flag_long_subscribe); - -static struct bt_conn *g_conn; - -#define ARRAY_ITEM(i, _) i -const uint8_t chrc_data[] = { LISTIFY(CHRC_SIZE, ARRAY_ITEM, (,)) }; /* 1, 2, 3 ... */ -const uint8_t long_chrc_data[] = { LISTIFY(LONG_CHRC_SIZE, ARRAY_ITEM, (,)) }; /* 1, 2, 3 ... */ - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - - g_conn = bt_conn_ref(conn); - SET_FLAG(flag_is_connected); -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - if (conn != g_conn) { - return; - } - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - printk("Disconnected: %s (reason 0x%02x)\n", addr, reason); - - bt_conn_unref(g_conn); - - g_conn = NULL; - UNSET_FLAG(flag_is_connected); -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - -static ssize_t read_test_chrc(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - printk("Read short\n"); - return bt_gatt_attr_read(conn, attr, buf, len, offset, (void *)chrc_data, - sizeof(chrc_data)); -} - -static ssize_t read_long_test_chrc(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - printk("Read long\n"); - return bt_gatt_attr_read(conn, attr, buf, len, offset, (void *)long_chrc_data, - sizeof(long_chrc_data)); -} - -static void short_subscribe(const struct bt_gatt_attr *attr, uint16_t value) -{ - const bool notif_enabled = (value == BT_GATT_CCC_NOTIFY); - - if (notif_enabled) { - SET_FLAG(flag_short_subscribe); - } - - printk("Short notifications %s\n", notif_enabled ? "enabled" : "disabled"); -} - -static void long_subscribe(const struct bt_gatt_attr *attr, uint16_t value) -{ - const bool notif_enabled = (value == BT_GATT_CCC_NOTIFY); - - if (notif_enabled) { - SET_FLAG(flag_long_subscribe); - } - - printk("Long notifications %s\n", notif_enabled ? "enabled" : "disabled"); -} - -BT_GATT_SERVICE_DEFINE(test_svc, BT_GATT_PRIMARY_SERVICE(TEST_SERVICE_UUID), - BT_GATT_CHARACTERISTIC(TEST_CHRC_UUID, - BT_GATT_CHRC_NOTIFY | BT_GATT_CHRC_READ, - BT_GATT_PERM_READ, read_test_chrc, NULL, NULL), - BT_GATT_CUD("Short test_svc format description", BT_GATT_PERM_READ), - BT_GATT_CCC(short_subscribe, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE), - BT_GATT_CHARACTERISTIC(TEST_LONG_CHRC_UUID, - BT_GATT_CHRC_NOTIFY | BT_GATT_CHRC_READ, - BT_GATT_PERM_READ, read_long_test_chrc, NULL, NULL), - BT_GATT_CCC(long_subscribe, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE)); - -static volatile size_t num_notifications_sent; - -static void notification_sent(struct bt_conn *conn, void *user_data) -{ - size_t *length = user_data; - - printk("Sent notification #%u with length %d\n", num_notifications_sent++, *length); -} - -static void short_notify(enum bt_att_chan_opt opt) -{ - static size_t length = CHRC_SIZE; - static struct bt_gatt_notify_params params = { - .attr = &attr_test_svc[1], - .data = chrc_data, - .len = CHRC_SIZE, - .func = notification_sent, - .user_data = &length, - .uuid = NULL, - }; - int err; - - params.chan_opt = opt; - - do { - err = bt_gatt_notify_cb(g_conn, ¶ms); - - if (err == -ENOMEM) { - k_sleep(K_MSEC(10)); - } else if (err) { - FAIL("Short notify failed (err %d)\n", err); - } - } while (err); -} - -static void long_notify(enum bt_att_chan_opt opt) -{ - static size_t length = LONG_CHRC_SIZE; - static struct bt_gatt_notify_params params = { - .attr = &attr_test_svc[5], - .data = long_chrc_data, - .len = LONG_CHRC_SIZE, - .func = notification_sent, - .user_data = &length, - .uuid = NULL, - }; - int err; - - params.chan_opt = opt; - - do { - err = bt_gatt_notify_cb(g_conn, ¶ms); - - if (err == -ENOMEM) { - k_sleep(K_MSEC(10)); - } else if (err) { - FAIL("Long notify failed (err %d)\n", err); - } - } while (err); -} - -static void setup(void) -{ - int err; - const struct bt_data ad[] = { - BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), - }; - - err = bt_enable(NULL); - if (err != 0) { - FAIL("Bluetooth init failed (err %d)\n", err); - return; - } - - printk("Bluetooth initialized\n"); - - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0); - if (err != 0) { - FAIL("Advertising failed to start (err %d)\n", err); - return; - } - - printk("Advertising successfully started\n"); - - WAIT_FOR_FLAG(flag_is_connected); - - while (bt_eatt_count(g_conn) < CONFIG_BT_EATT_MAX) { - k_sleep(K_MSEC(100)); - } - printk("EATT connected\n"); - - WAIT_FOR_FLAG(flag_short_subscribe); - WAIT_FOR_FLAG(flag_long_subscribe); -} - -static void test_main_none(void) -{ - setup(); - - for (int i = 0; i < NOTIFICATION_COUNT / 2; i++) { - short_notify(BT_ATT_CHAN_OPT_NONE); - long_notify(BT_ATT_CHAN_OPT_NONE); - } - - while (num_notifications_sent < NOTIFICATION_COUNT) { - k_sleep(K_MSEC(100)); - } - - PASS("GATT server passed\n"); -} - -static void test_main_enhanced(void) -{ - setup(); - - for (int i = 0; i < NOTIFICATION_COUNT / 2; i++) { - short_notify(BT_ATT_CHAN_OPT_ENHANCED_ONLY); - long_notify(BT_ATT_CHAN_OPT_ENHANCED_ONLY); - } - - while (num_notifications_sent < NOTIFICATION_COUNT) { - k_sleep(K_MSEC(100)); - } - - PASS("GATT server passed\n"); -} - -static void test_main_unenhanced(void) -{ - setup(); - - for (int i = 0; i < NOTIFICATION_COUNT / 2; i++) { - short_notify(BT_ATT_CHAN_OPT_UNENHANCED_ONLY); - long_notify(BT_ATT_CHAN_OPT_UNENHANCED_ONLY); - } - - while (num_notifications_sent < NOTIFICATION_COUNT) { - k_sleep(K_MSEC(100)); - } - - PASS("GATT server passed\n"); -} - -static void test_main_mixed(void) -{ - setup(); - - for (int i = 0; i < NOTIFICATION_COUNT / 2; i++) { - short_notify(BT_ATT_CHAN_OPT_UNENHANCED_ONLY); - long_notify(BT_ATT_CHAN_OPT_ENHANCED_ONLY); - } - - while (num_notifications_sent < NOTIFICATION_COUNT) { - k_sleep(K_MSEC(100)); - } - - PASS("GATT server passed\n"); -} - -static const struct bst_test_instance test_gatt_server[] = { - { - .test_id = "gatt_server_none", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main_none, - }, - { - .test_id = "gatt_server_unenhanced", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main_unenhanced, - }, - { - .test_id = "gatt_server_enhanced", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main_enhanced, - }, - { - .test_id = "gatt_server_mixed", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main_mixed, - }, - BSTEST_END_MARKER, -}; - -struct bst_test_list *test_gatt_server_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_gatt_server); -} diff --git a/tests/bluetooth/bsim/host/gatt/notify/src/main.c b/tests/bluetooth/bsim/host/gatt/notify/src/main.c deleted file mode 100644 index 7e2806a0702..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify/src/main.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bstests.h" - -extern struct bst_test_list *test_gatt_server_install(struct bst_test_list *tests); -extern struct bst_test_list *test_gatt_client_install(struct bst_test_list *tests); - -bst_test_install_t test_installers[] = { - test_gatt_server_install, - test_gatt_client_install, - NULL -}; - -void main(void) -{ - bst_main(); -} diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/_run_test.sh b/tests/bluetooth/bsim/host/gatt/notify/test_scripts/_run_test.sh deleted file mode 100755 index 6229a794db6..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/_run_test.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -verbosity_level=2 -process_ids="" -exit_code=0 - -function Execute() { - if [ ! -f $1 ]; then - echo -e " \e[91m$(pwd)/$(basename $1) cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 30 $@ & - process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_gatt_notify_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=${client_id} - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_gatt_notify_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=${server_id} - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=60e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_enhanced_enhanced.sh b/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_enhanced_enhanced.sh deleted file mode 100755 index 68cf9409994..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_enhanced_enhanced.sh +++ /dev/null @@ -1,10 +0,0 @@ - -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="gatt_notify_enhanced_enhanced" \ - server_id="gatt_server_enhanced" \ - client_id="gatt_client_enhanced" \ - $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_enhanced_mixed.sh b/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_enhanced_mixed.sh deleted file mode 100755 index 75a4b9d83c9..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_enhanced_mixed.sh +++ /dev/null @@ -1,10 +0,0 @@ - -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="gatt_notify_enhanced_mixed" \ - server_id="gatt_server_enhanced" \ - client_id="gatt_client_mixed" \ - $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_enhanced_none.sh b/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_enhanced_none.sh deleted file mode 100755 index e89b16ca20e..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_enhanced_none.sh +++ /dev/null @@ -1,10 +0,0 @@ - -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="gatt_notify_enhanced_none" \ - server_id="gatt_server_enhanced" \ - client_id="gatt_client_none" \ - $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_enhanced_unenhanced.sh b/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_enhanced_unenhanced.sh deleted file mode 100755 index 5cc85731633..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_enhanced_unenhanced.sh +++ /dev/null @@ -1,10 +0,0 @@ - -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="gatt_notify_enhanced_unenhanced" \ - server_id="gatt_server_enhanced" \ - client_id="gatt_client_unenhanced" \ - $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_mixed_enhanced.sh b/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_mixed_enhanced.sh deleted file mode 100755 index a4ecf9d429b..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_mixed_enhanced.sh +++ /dev/null @@ -1,10 +0,0 @@ - -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="gatt_notify_mixed_enhanced" \ - server_id="gatt_server_mixed" \ - client_id="gatt_client_enhanced" \ - $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_mixed_mixed.sh b/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_mixed_mixed.sh deleted file mode 100755 index a9f38d8f37f..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_mixed_mixed.sh +++ /dev/null @@ -1,10 +0,0 @@ - -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="gatt_notify_mixed_mixed" \ - server_id="gatt_server_mixed" \ - client_id="gatt_client_mixed" \ - $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_mixed_none.sh b/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_mixed_none.sh deleted file mode 100755 index 80afe822cfd..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_mixed_none.sh +++ /dev/null @@ -1,10 +0,0 @@ - -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="gatt_notify_mixed_none" \ - server_id="gatt_server_mixed" \ - client_id="gatt_client_none" \ - $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_mixed_unenhanced.sh b/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_mixed_unenhanced.sh deleted file mode 100755 index 9ff73b2de4b..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_mixed_unenhanced.sh +++ /dev/null @@ -1,10 +0,0 @@ - -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="gatt_notify_mixed_unenhanced" \ - server_id="gatt_server_mixed" \ - client_id="gatt_client_unenhanced" \ - $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_none_enhanced.sh b/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_none_enhanced.sh deleted file mode 100755 index 74eedd15ddc..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_none_enhanced.sh +++ /dev/null @@ -1,10 +0,0 @@ - -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="gatt_notify_none_enhanced" \ - server_id="gatt_server_none" \ - client_id="gatt_client_enhanced" \ - $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_none_mixed.sh b/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_none_mixed.sh deleted file mode 100755 index 02541c6db74..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_none_mixed.sh +++ /dev/null @@ -1,10 +0,0 @@ - -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="gatt_notify_none_mixed" \ - server_id="gatt_server_none" \ - client_id="gatt_client_mixed" \ - $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_none_none.sh b/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_none_none.sh deleted file mode 100755 index 6642f8ed2b5..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_none_none.sh +++ /dev/null @@ -1,10 +0,0 @@ - -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="gatt_notify_none_none" \ - server_id="gatt_server_none" \ - client_id="gatt_client_none" \ - $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_none_unenhanced.sh b/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_none_unenhanced.sh deleted file mode 100755 index 2f2764186c7..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_none_unenhanced.sh +++ /dev/null @@ -1,10 +0,0 @@ - -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="gatt_notify_none_unenhanced" \ - server_id="gatt_server_none" \ - client_id="gatt_client_unenhanced" \ - $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_unenhanced_enhanced.sh b/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_unenhanced_enhanced.sh deleted file mode 100755 index ab91b23437d..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_unenhanced_enhanced.sh +++ /dev/null @@ -1,10 +0,0 @@ - -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="gatt_notify_unenhanced_enhanced" \ - server_id="gatt_server_unenhanced" \ - client_id="gatt_client_enhanced" \ - $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_unenhanced_mixed.sh b/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_unenhanced_mixed.sh deleted file mode 100755 index 57063ac272b..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_unenhanced_mixed.sh +++ /dev/null @@ -1,10 +0,0 @@ - -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="gatt_notify_unenhanced_mixed" \ - server_id="gatt_server_unenhanced" \ - client_id="gatt_client_mixed" \ - $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_unenhanced_none.sh b/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_unenhanced_none.sh deleted file mode 100755 index df360db4e5e..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_unenhanced_none.sh +++ /dev/null @@ -1,10 +0,0 @@ - -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="gatt_notify_unenhanced_none" \ - server_id="gatt_server_unenhanced" \ - client_id="gatt_client_none" \ - $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_unenhanced_unenhanced.sh b/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_unenhanced_unenhanced.sh deleted file mode 100755 index 7b624969d5d..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify/test_scripts/gatt_notify_unenhanced_unenhanced.sh +++ /dev/null @@ -1,10 +0,0 @@ - -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="gatt_notify_unenhanced_unenhanced" \ - server_id="gatt_server_unenhanced" \ - client_id="gatt_client_unenhanced" \ - $(dirname "${BASH_SOURCE[0]}")/_run_test.sh - diff --git a/tests/bluetooth/bsim/host/gatt/notify_multiple/CMakeLists.txt b/tests/bluetooth/bsim/host/gatt/notify_multiple/CMakeLists.txt deleted file mode 100644 index 180cb3537fc..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify_multiple/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set\ - the environment variable BSIM_COMPONENTS_PATH to point to its components \ - folder. More information can be found in\ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_gatt) - -FILE(GLOB app_sources src/*.c) -target_sources(app PRIVATE ${app_sources} ) - -zephyr_include_directories( - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ - ) diff --git a/tests/bluetooth/bsim/host/gatt/notify_multiple/prj.conf b/tests/bluetooth/bsim/host/gatt/notify_multiple/prj.conf deleted file mode 100644 index 4fd7e8952fc..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify_multiple/prj.conf +++ /dev/null @@ -1,18 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_DEVICE_NAME="GATT tester" -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_GATT_CLIENT=y - -CONFIG_BT_GATT_AUTO_DISCOVER_CCC=y - -CONFIG_BT_SMP=y -CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y -CONFIG_BT_L2CAP_ECRED=y -CONFIG_BT_EATT=y -CONFIG_BT_EATT_MAX=5 -CONFIG_BT_GATT_NOTIFY_MULTIPLE=y - -CONFIG_ASSERT=y -CONFIG_BT_TESTING=y -CONFIG_BT_DEBUG_LOG=y diff --git a/tests/bluetooth/bsim/host/gatt/notify_multiple/src/common.c b/tests/bluetooth/bsim/host/gatt/notify_multiple/src/common.c deleted file mode 100644 index df438607c5f..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify_multiple/src/common.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "common.h" - -void test_tick(bs_time_t HW_device_time) -{ - if (bst_result != Passed) { - FAIL("test failed (not passed after %i seconds)\n", WAIT_TIME); - } -} - -void test_init(void) -{ - bst_ticker_set_next_tick_absolute(WAIT_TIME); - bst_result = In_progress; -} diff --git a/tests/bluetooth/bsim/host/gatt/notify_multiple/src/common.h b/tests/bluetooth/bsim/host/gatt/notify_multiple/src/common.h deleted file mode 100644 index 56ca219497b..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify_multiple/src/common.h +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Common functions and helpers for BSIM GATT tests - * - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include "bs_types.h" -#include "bs_tracing.h" -#include "time_machine.h" -#include "bstests.h" - -#include -#include -#include - -#include -#include -#include -#include -#include - -extern enum bst_result_t bst_result; - -#define WAIT_TIME (60 * 1e6) /*seconds*/ - -#define CREATE_FLAG(flag) static atomic_t flag = (atomic_t)false -#define FORCE_FLAG(flag, val) (void)atomic_set(&flag, (atomic_t)val) -#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)true) -#define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)false) -#define WAIT_FOR_FLAG(flag) \ - while (!(bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } -#define WAIT_FOR_FLAG_UNSET(flag) \ - while ((bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } - -#define FAIL(...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, __VA_ARGS__); \ - } while (0) - -#define CHRC_SIZE 10 -#define LONG_CHRC_SIZE 40 - -#define TEST_SERVICE_UUID \ - BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, \ - 0x07, 0x08, 0x09, 0x00, 0x00) - -#define TEST_CHRC_UUID \ - BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, \ - 0x07, 0x08, 0x09, 0xFF, 0x00) - -#define TEST_LONG_CHRC_UUID \ - BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, \ - 0x07, 0x08, 0x09, 0xFF, 0x11) - -void test_tick(bs_time_t HW_device_time); -void test_init(void); - -#define NOTIFICATION_COUNT 10 -BUILD_ASSERT(NOTIFICATION_COUNT % 2 == 0); diff --git a/tests/bluetooth/bsim/host/gatt/notify_multiple/src/gatt_client_test.c b/tests/bluetooth/bsim/host/gatt/notify_multiple/src/gatt_client_test.c deleted file mode 100644 index 7266fe98ed2..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify_multiple/src/gatt_client_test.c +++ /dev/null @@ -1,378 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -#include "common.h" - -CREATE_FLAG(flag_is_connected); -CREATE_FLAG(flag_is_encrypted); -CREATE_FLAG(flag_discover_complete); -CREATE_FLAG(flag_write_complete); -CREATE_FLAG(flag_subscribed_short); -CREATE_FLAG(flag_subscribed_long); - -static struct bt_conn *g_conn; -static uint16_t chrc_handle; -static uint16_t long_chrc_handle; -static uint16_t csf_handle; -static struct bt_uuid *test_svc_uuid = TEST_SERVICE_UUID; - -static void exchange_func(struct bt_conn *conn, uint8_t err, struct bt_gatt_exchange_params *params) -{ - if (!err) { - printk("MTU exchange done\n"); - } else { - printk("MTU exchange failed (err %" PRIu8 ")\n", err); - } -} - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - static struct bt_gatt_exchange_params exchange_params; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - - SET_FLAG(flag_is_connected); - - exchange_params.func = exchange_func; - err = bt_gatt_exchange_mtu(conn, &exchange_params); - if (err) { - printk("MTU exchange failed (err %d)", err); - } -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - if (conn != g_conn) { - return; - } - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - printk("Disconnected: %s (reason 0x%02x)\n", addr, reason); - - bt_conn_unref(g_conn); - - g_conn = NULL; - UNSET_FLAG(flag_is_connected); -} - -void security_changed(struct bt_conn *conn, bt_security_t level, enum bt_security_err err) -{ - if (err) { - FAIL("Encryption failer (%d)\n", err); - } else if (level < BT_SECURITY_L2) { - FAIL("Insufficient sec level (%d)\n", level); - } else { - SET_FLAG(flag_is_encrypted); - } -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, - .security_changed = security_changed, -}; - -void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, struct net_buf_simple *ad) -{ - char addr_str[BT_ADDR_LE_STR_LEN]; - int err; - - if (g_conn != NULL) { - return; - } - - /* We're only interested in connectable events */ - if (type != BT_HCI_ADV_IND && type != BT_HCI_ADV_DIRECT_IND) { - return; - } - - bt_addr_le_to_str(addr, addr_str, sizeof(addr_str)); - printk("Device found: %s (RSSI %d)\n", addr_str, rssi); - - printk("Stopping scan\n"); - err = bt_le_scan_stop(); - if (err != 0) { - FAIL("Could not stop scan: %d"); - return; - } - - err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, BT_LE_CONN_PARAM_DEFAULT, &g_conn); - if (err != 0) { - FAIL("Could not connect to peer: %d", err); - } -} - -static uint8_t discover_func(struct bt_conn *conn, const struct bt_gatt_attr *attr, - struct bt_gatt_discover_params *params) -{ - int err; - - if (attr == NULL) { - if (chrc_handle == 0 || long_chrc_handle == 0) { - FAIL("Did not discover chrc (%x) or long_chrc (%x)", chrc_handle, - long_chrc_handle); - } - - (void)memset(params, 0, sizeof(*params)); - - SET_FLAG(flag_discover_complete); - - return BT_GATT_ITER_STOP; - } - - printk("[ATTRIBUTE] handle %u\n", attr->handle); - - if (params->type == BT_GATT_DISCOVER_PRIMARY && - bt_uuid_cmp(params->uuid, TEST_SERVICE_UUID) == 0) { - printk("Found test service\n"); - params->uuid = NULL; - params->start_handle = attr->handle + 1; - params->type = BT_GATT_DISCOVER_CHARACTERISTIC; - - err = bt_gatt_discover(conn, params); - if (err != 0) { - FAIL("Discover failed (err %d)\n", err); - } - - return BT_GATT_ITER_STOP; - } else if (params->type == BT_GATT_DISCOVER_CHARACTERISTIC) { - const struct bt_gatt_chrc *chrc = (struct bt_gatt_chrc *)attr->user_data; - - if (bt_uuid_cmp(chrc->uuid, TEST_CHRC_UUID) == 0) { - printk("Found chrc\n"); - chrc_handle = chrc->value_handle; - } else if (bt_uuid_cmp(chrc->uuid, TEST_LONG_CHRC_UUID) == 0) { - printk("Found long_chrc\n"); - long_chrc_handle = chrc->value_handle; - } else if (bt_uuid_cmp(chrc->uuid, BT_UUID_GATT_CLIENT_FEATURES) == 0) { - printk("Found csf\n"); - csf_handle = chrc->value_handle; - } - } - - return BT_GATT_ITER_CONTINUE; -} - -static void gatt_discover(const struct bt_uuid *uuid, uint8_t type) -{ - static struct bt_gatt_discover_params discover_params; - int err; - - printk("Discovering services and characteristics\n"); - - discover_params.uuid = uuid; - discover_params.func = discover_func; - discover_params.start_handle = BT_ATT_FIRST_ATTRIBUTE_HANDLE; - discover_params.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE; - discover_params.type = type; - - UNSET_FLAG(flag_discover_complete); - - err = bt_gatt_discover(g_conn, &discover_params); - if (err != 0) { - FAIL("Discover failed(err %d)\n", err); - } - - WAIT_FOR_FLAG(flag_discover_complete); - printk("Discover complete\n"); -} - -static void test_subscribed(struct bt_conn *conn, - uint8_t err, - struct bt_gatt_subscribe_params *params) -{ - if (err) { - FAIL("Subscribe failed (err %d)\n", err); - } - - if (!params) { - FAIL("params NULL\n"); - } - - if (params->value_handle == chrc_handle) { - FORCE_FLAG(flag_subscribed_short, (bool)params->value); - printk("Subscribed to short characteristic\n"); - } else if (params->value_handle == long_chrc_handle) { - FORCE_FLAG(flag_subscribed_long, (bool)params->value); - printk("Subscribed to long characteristic\n"); - } else { - FAIL("Unknown handle %d\n", params->value_handle); - } -} - -static volatile size_t num_notifications; -uint8_t test_notify(struct bt_conn *conn, struct bt_gatt_subscribe_params *params, const void *data, - uint16_t length) -{ - printk("Received notification #%u with length %d\n", num_notifications++, length); - - return BT_GATT_ITER_CONTINUE; -} - -static struct bt_gatt_discover_params disc_params_short; -static struct bt_gatt_subscribe_params sub_params_short = { - .notify = test_notify, - .subscribe = test_subscribed, - .ccc_handle = 0, /* Auto-discover CCC*/ - .disc_params = &disc_params_short, /* Auto-discover CCC */ - .end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE, - .value = BT_GATT_CCC_NOTIFY, -}; -static struct bt_gatt_discover_params disc_params_long; -static struct bt_gatt_subscribe_params sub_params_long = { - .notify = test_notify, - .subscribe = test_subscribed, - .ccc_handle = 0, /* Auto-discover CCC*/ - .disc_params = &disc_params_long, /* Auto-discover CCC */ - .end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE, - .value = BT_GATT_CCC_NOTIFY, -}; - -static void write_cb(struct bt_conn *conn, uint8_t err, struct bt_gatt_write_params *params) -{ - if (err != BT_ATT_ERR_SUCCESS) { - FAIL("Write failed: 0x%02X\n", err); - } - - SET_FLAG(flag_write_complete); -} - -static void write_csf(void) -{ - /* Client Supported Features Characteristic Value - * Bit 0: Robust Caching - * Bit 1: EATT - * Bit 2: Multiple Handle Value Notifications - */ - static const uint8_t csf[] = { BIT(2) }; - static struct bt_gatt_write_params write_params = { - .func = write_cb, - .offset = 0, - .data = csf, - .length = sizeof(csf), - }; - int err; - - printk("Writing to Client Supported Features Characteristic\n"); - - write_params.handle = csf_handle; - UNSET_FLAG(flag_write_complete); - - err = bt_gatt_write(g_conn, &write_params); - if (err) { - FAIL("bt_gatt_write failed (err %d)\n", err); - } - - WAIT_FOR_FLAG(flag_write_complete); - printk("Success\n"); -} - -static void subscribe(struct bt_gatt_subscribe_params *params, bool subscribe) -{ - int err; - - if (subscribe) { - err = bt_gatt_subscribe(g_conn, params); - } else { - err = bt_gatt_unsubscribe(g_conn, params); - } - - if (err < 0) { - FAIL("Failed to %ssubscribe (err %d)\n", subscribe ? "un":"", err); - } else { - printk("%ssubscribe request sent\n", subscribe ? "un":""); - } - -} - -static void test_main(void) -{ - int err; - - err = bt_enable(NULL); - if (err != 0) { - FAIL("Bluetooth discover failed (err %d)\n", err); - } - - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); - if (err != 0) { - FAIL("Scanning failed to start (err %d)\n", err); - } - - printk("Scanning successfully started\n"); - - WAIT_FOR_FLAG(flag_is_connected); - - err = bt_conn_set_security(g_conn, BT_SECURITY_L2); - if (err) { - FAIL("Starting encryption procedure failed (%d)\n", err); - } - - WAIT_FOR_FLAG(flag_is_encrypted); - - while (bt_eatt_count(g_conn) < CONFIG_BT_EATT_MAX) { - k_sleep(K_MSEC(10)); - } - - printk("EATT connected\n"); - - gatt_discover(test_svc_uuid, BT_GATT_DISCOVER_PRIMARY); - gatt_discover(BT_UUID_GATT_CLIENT_FEATURES, BT_GATT_DISCOVER_CHARACTERISTIC); - write_csf(); - - sub_params_short.value_handle = chrc_handle; - sub_params_long.value_handle = long_chrc_handle; - - subscribe(&sub_params_short, true); - subscribe(&sub_params_long, true); - WAIT_FOR_FLAG(flag_subscribed_short); - WAIT_FOR_FLAG(flag_subscribed_long); - - printk("Subscribed\n"); - - while (num_notifications < NOTIFICATION_COUNT) { - k_sleep(K_MSEC(100)); - } - - subscribe(&sub_params_short, false); - subscribe(&sub_params_long, false); - WAIT_FOR_FLAG_UNSET(flag_subscribed_short); - WAIT_FOR_FLAG_UNSET(flag_subscribed_long); - - - printk("Unsubscribed\n"); - - PASS("GATT client Passed\n"); -} - -static const struct bst_test_instance test_vcs[] = { - { - .test_id = "gatt_client", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main, - }, - BSTEST_END_MARKER, -}; - -struct bst_test_list *test_gatt_client_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_vcs); -} diff --git a/tests/bluetooth/bsim/host/gatt/notify_multiple/src/gatt_server_test.c b/tests/bluetooth/bsim/host/gatt/notify_multiple/src/gatt_server_test.c deleted file mode 100644 index 743cb3e269c..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify_multiple/src/gatt_server_test.c +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "common.h" - -extern enum bst_result_t bst_result; - -CREATE_FLAG(flag_is_connected); -CREATE_FLAG(flag_short_subscribe); -CREATE_FLAG(flag_long_subscribe); - -static struct bt_conn *g_conn; - -#define ARRAY_ITEM(i, _) i -const uint8_t chrc_data[] = { LISTIFY(CHRC_SIZE, ARRAY_ITEM, (,)) }; /* 1, 2, 3 ... */ -const uint8_t long_chrc_data[] = { LISTIFY(LONG_CHRC_SIZE, ARRAY_ITEM, (,)) }; /* 1, 2, 3 ... */ - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - - g_conn = bt_conn_ref(conn); - SET_FLAG(flag_is_connected); -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - if (conn != g_conn) { - return; - } - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - printk("Disconnected: %s (reason 0x%02x)\n", addr, reason); - - bt_conn_unref(g_conn); - - g_conn = NULL; - UNSET_FLAG(flag_is_connected); -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - -static void short_subscribe(const struct bt_gatt_attr *attr, uint16_t value) -{ - const bool notif_enabled = (value == BT_GATT_CCC_NOTIFY); - - if (notif_enabled) { - SET_FLAG(flag_short_subscribe); - } - - printk("Short notifications %s\n", notif_enabled ? "enabled" : "disabled"); -} - -static void long_subscribe(const struct bt_gatt_attr *attr, uint16_t value) -{ - const bool notif_enabled = (value == BT_GATT_CCC_NOTIFY); - - if (notif_enabled) { - SET_FLAG(flag_long_subscribe); - } - - printk("Long notifications %s\n", notif_enabled ? "enabled" : "disabled"); -} - -BT_GATT_SERVICE_DEFINE(test_svc, BT_GATT_PRIMARY_SERVICE(TEST_SERVICE_UUID), - BT_GATT_CHARACTERISTIC(TEST_CHRC_UUID, - BT_GATT_CHRC_NOTIFY | BT_GATT_CHRC_READ, - BT_GATT_PERM_READ, NULL, NULL, NULL), - BT_GATT_CUD("Short test_svc format description", BT_GATT_PERM_READ), - BT_GATT_CCC(short_subscribe, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE), - BT_GATT_CHARACTERISTIC(TEST_LONG_CHRC_UUID, - BT_GATT_CHRC_NOTIFY | BT_GATT_CHRC_READ, - BT_GATT_PERM_READ, NULL, NULL, NULL), - BT_GATT_CCC(long_subscribe, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE)); - -static volatile size_t num_notifications_sent; - -static void notification_sent(struct bt_conn *conn, void *user_data) -{ - printk("Sent notification #%u\n", num_notifications_sent++); -} - -static inline void multiple_notify(const struct bt_gatt_attr *attrs[2]) -{ - int err; - static struct bt_gatt_notify_params params[] = { - { - .data = long_chrc_data, - .len = LONG_CHRC_SIZE, - .func = notification_sent, - .uuid = NULL, - }, - { - .data = chrc_data, - .len = CHRC_SIZE, - .func = notification_sent, - .uuid = NULL, - }, - }; - params[0].attr = attrs[0]; - params[1].attr = attrs[1]; - - do { - err = bt_gatt_notify_multiple(g_conn, ARRAY_SIZE(params), params); - - if (err == -ENOMEM) { - k_sleep(K_MSEC(10)); - } else if (err) { - FAIL("multiple notify failed (err %d)\n", err); - } - } while (err); -} - -static void test_main(void) -{ - int err; - const struct bt_gatt_attr *attrs[2]; - const struct bt_data ad[] = { - BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), - }; - - err = bt_enable(NULL); - if (err != 0) { - FAIL("Bluetooth init failed (err %d)\n", err); - return; - } - - printk("Bluetooth initialized\n"); - - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0); - if (err != 0) { - FAIL("Advertising failed to start (err %d)\n", err); - return; - } - - printk("Advertising successfully started\n"); - - WAIT_FOR_FLAG(flag_is_connected); - WAIT_FOR_FLAG(flag_short_subscribe); - WAIT_FOR_FLAG(flag_long_subscribe); - - /* Long characteristic [attr=value] */ - attrs[0] = bt_gatt_find_by_uuid(NULL, 0, TEST_LONG_CHRC_UUID); - /* Short characteristic [attr=descriptor] */ - attrs[1] = &attr_test_svc[1]; - - for (int i = 0; i < NOTIFICATION_COUNT / 2; i++) { - multiple_notify(attrs); - } - - while (num_notifications_sent < NOTIFICATION_COUNT / 2) { - k_sleep(K_MSEC(100)); - } - - k_sleep(K_MSEC(1000)); - - if (num_notifications_sent != NOTIFICATION_COUNT) { - FAIL("Unexpected notification callback value\n"); - } - - PASS("GATT server passed\n"); -} - -static const struct bst_test_instance test_gatt_server[] = { - { - .test_id = "gatt_server", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main, - }, - BSTEST_END_MARKER, -}; - -struct bst_test_list *test_gatt_server_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_gatt_server); -} diff --git a/tests/bluetooth/bsim/host/gatt/notify_multiple/src/main.c b/tests/bluetooth/bsim/host/gatt/notify_multiple/src/main.c deleted file mode 100644 index 7e2806a0702..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify_multiple/src/main.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bstests.h" - -extern struct bst_test_list *test_gatt_server_install(struct bst_test_list *tests); -extern struct bst_test_list *test_gatt_client_install(struct bst_test_list *tests); - -bst_test_install_t test_installers[] = { - test_gatt_server_install, - test_gatt_client_install, - NULL -}; - -void main(void) -{ - bst_main(); -} diff --git a/tests/bluetooth/bsim/host/gatt/notify_multiple/test_scripts/_notify-debug.sh b/tests/bluetooth/bsim/host/gatt/notify_multiple/test_scripts/_notify-debug.sh deleted file mode 100755 index f8adec17950..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify_multiple/test_scripts/_notify-debug.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -# Usage: -# one script instance per device, e.g. to run gdb on the client: -# `_notify-debug.sh client debug` -# `_notify-debug.sh server` -# `_notify-debug.sh` -# -# GDB can be run on the two devices at the same time without issues, just append -# `debug` when running the script. - - -simulation_id="notify_multiple" -verbosity_level=2 -process_ids=""; exit_code=0 - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -if [[ $2 == "debug" ]]; then - GDB_P="gdb --args " -fi - -if [[ $1 == "client" ]]; then -$GDB_P ./bs_${BOARD}_tests_bluetooth_bsim_host_gatt_notify_multiple_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=gatt_client - -elif [[ $1 == "server" ]]; then -$GDB_P ./bs_${BOARD}_tests_bluetooth_bsim_host_gatt_notify_multiple_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=gatt_server - -else -./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=60e6 $@ - -fi diff --git a/tests/bluetooth/bsim/host/gatt/notify_multiple/test_scripts/notify.sh b/tests/bluetooth/bsim/host/gatt/notify_multiple/test_scripts/notify.sh deleted file mode 100755 index b70d41ebdf0..00000000000 --- a/tests/bluetooth/bsim/host/gatt/notify_multiple/test_scripts/notify.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="notify_multiple" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 120 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_gatt_notify_multiple_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=gatt_client - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_gatt_notify_multiple_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=gatt_server - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=60e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/gatt/settings/CMakeLists.txt b/tests/bluetooth/bsim/host/gatt/settings/CMakeLists.txt deleted file mode 100644 index 1d147dc090d..00000000000 --- a/tests/bluetooth/bsim/host/gatt/settings/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set\ - the environment variable BSIM_COMPONENTS_PATH to point to its components \ - folder. More information can be found in\ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_gatt_settings) - -target_sources(app PRIVATE - src/server.c - src/client.c - src/utils.c - src/gatt_utils.c - src/settings.c - src/main.c - ) - -zephyr_include_directories( - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ - ) diff --git a/tests/bluetooth/bsim/host/gatt/settings/prj.conf b/tests/bluetooth/bsim/host/gatt/settings/prj.conf deleted file mode 100644 index 86936059598..00000000000 --- a/tests/bluetooth/bsim/host/gatt/settings/prj.conf +++ /dev/null @@ -1,26 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_DEVICE_NAME="GATT settings" - -CONFIG_LOG=y -CONFIG_ASSERT=y -CONFIG_BT_TESTING=y - -CONFIG_BT_AUTO_PHY_UPDATE=n -CONFIG_BT_AUTO_DATA_LEN_UPDATE=n -CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n - -CONFIG_BT_SMP=y -CONFIG_BT_GATT_CLIENT=y -CONFIG_BT_GATT_DYNAMIC_DB=y -CONFIG_BT_GATT_CACHING=y - -CONFIG_SETTINGS=y -CONFIG_SETTINGS_CUSTOM=y -CONFIG_BT_SETTINGS=y - -CONFIG_BT_GATT_AUTO_DISCOVER_CCC=y -CONFIG_BT_GATT_AUTO_RESUBSCRIBE=n - -CONFIG_BT_PRIVACY=n diff --git a/tests/bluetooth/bsim/host/gatt/settings/prj_2.conf b/tests/bluetooth/bsim/host/gatt/settings/prj_2.conf deleted file mode 100644 index 96e7123aad1..00000000000 --- a/tests/bluetooth/bsim/host/gatt/settings/prj_2.conf +++ /dev/null @@ -1,26 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_DEVICE_NAME="GATT settings" - -CONFIG_LOG=y -CONFIG_ASSERT=y -CONFIG_BT_TESTING=y - -CONFIG_BT_AUTO_PHY_UPDATE=n -CONFIG_BT_AUTO_DATA_LEN_UPDATE=n -CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n - -CONFIG_BT_SMP=y -CONFIG_BT_GATT_CLIENT=y -CONFIG_BT_GATT_DYNAMIC_DB=y -CONFIG_BT_GATT_CACHING=y - -CONFIG_SETTINGS=y -CONFIG_SETTINGS_CUSTOM=y -CONFIG_BT_SETTINGS=y - -CONFIG_BT_GATT_AUTO_DISCOVER_CCC=y -CONFIG_BT_GATT_AUTO_RESUBSCRIBE=n - -CONFIG_BT_PRIVACY=y diff --git a/tests/bluetooth/bsim/host/gatt/settings/src/client.c b/tests/bluetooth/bsim/host/gatt/settings/src/client.c deleted file mode 100644 index 8720fdea219..00000000000 --- a/tests/bluetooth/bsim/host/gatt/settings/src/client.c +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "utils.h" -#include "gatt_utils.h" - -#include -#include -#include -#include -#include - -#include -#include - -void client_round_0(void) -{ - struct bt_conn *conn; - - printk("start round 0...........\n"); - - conn = connect_as_peripheral(); - printk("connected: conn %p\n", conn); - - gatt_discover(); - activate_robust_caching(); - /* subscribe to the SC indication, so we don't have to ATT read to - * become change-aware. - */ - gatt_subscribe_to_service_changed(true); - read_test_char(true); - - /* We should normally wait until we are bonded to write the CCC / CF - * characteristics, but here we bond after the fact on purpose, to - * simulate a client that has this exact behavior. - * The CCC and CF should still persist on reboot. - */ - wait_bonded(); - - disconnect(conn); -} - -void client_round_1(void) -{ - struct bt_conn *conn; - - printk("start round 1...........\n"); - - conn = connect_as_peripheral(); - printk("connected: conn %p\n", conn); - wait_secured(); - - /* server should remember we are change-aware */ - read_test_char(true); - - disconnect(conn); -} - -void client_round_2(void) -{ - struct bt_conn *conn; - - printk("start round 2...........\n"); - - conn = connect_as_peripheral(); - printk("connected: conn %p\n", conn); - wait_secured(); - - /* We are change-unaware. wait until the Service Changed indication is - * received, that should then make us change-aware. - */ - wait_for_sc_indication(); - read_test_char(true); - - /* We sleep just enough so that the server's `delayed store` work item - * is executed. We still trigger a disconnect, even though the server - * device will be unresponsive for this round. - */ - k_sleep(K_MSEC(CONFIG_BT_SETTINGS_DELAYED_STORE_MS)); - - disconnect(conn); -} - -void client_round_3(void) -{ - struct bt_conn *conn; - - printk("start round 3...........\n"); - - conn = connect_as_peripheral(); - printk("connected: conn %p\n", conn); - wait_secured(); - - /* server should remember we are change-aware */ - read_test_char(true); - - /* Unsubscribe from the SC indication. - * - * In the next round, we will be change-unaware, so the first ATT read - * will fail, but the second one will succeed and we will be marked as - * change-aware again. - */ - gatt_subscribe_to_service_changed(false); - - disconnect(conn); -} - -void client_round_4(void) -{ - struct bt_conn *conn; - - printk("start round 4...........\n"); - - conn = connect_as_peripheral(); - printk("connected: conn %p\n", conn); - wait_secured(); - - /* GATT DB has changed again. - * Before disc: svc1 - * After disc: svc1 + svc2 - * At boot: svc1 - * Expect a failure on the first read of the same GATT handle. - */ - read_test_char(false); - read_test_char(true); - - disconnect(conn); -} - -void client_round_5(void) -{ - printk("start round 5...........\n"); - printk("don't need to do anything, central will " - "not connect to us\n"); -} - -void client_round_6(void) -{ - struct bt_conn *conn; - - printk("start round 6...........\n"); - conn = connect_as_peripheral(); - printk("connected: conn %p\n", conn); - wait_secured(); - - /* GATT DB has changed again. - * Expect a failure on the first read of the same GATT handle. - */ - read_test_char(false); - read_test_char(true); - - disconnect(conn); -} - -void client_procedure(void) -{ - bt_enable(NULL); - settings_load(); - - client_round_0(); - client_round_1(); - client_round_2(); - client_round_3(); - client_round_4(); - client_round_5(); - client_round_6(); - - PASS("PASS\n"); -} diff --git a/tests/bluetooth/bsim/host/gatt/settings/src/gatt_utils.c b/tests/bluetooth/bsim/host/gatt/settings/src/gatt_utils.c deleted file mode 100644 index fae0531a0b3..00000000000 --- a/tests/bluetooth/bsim/host/gatt/settings/src/gatt_utils.c +++ /dev/null @@ -1,373 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "utils.h" -#include "argparse.h" -#include "bs_pc_backchannel.h" - -#include -#include -#include -#include - -/* Custom Service Variables */ -static struct bt_uuid_128 test_svc_uuid = BT_UUID_INIT_128( - 0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12, - 0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x12); - -static struct bt_uuid_128 test_svc_uuid_2 = BT_UUID_INIT_128( - 0xf1, 0xdd, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12, - 0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x12); - -static struct bt_uuid_128 test_chrc_uuid = BT_UUID_INIT_128( - 0xf2, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12, - 0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x12); - -static uint8_t test_value[] = { 'T', 'e', 's', 't', '\0' }; - -DEFINE_FLAG(flag_client_read); - -static ssize_t read_test(struct bt_conn *conn, const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) -{ - const char *value = attr->user_data; - - printk("Client has read from test char\n"); - SET_FLAG(flag_client_read); - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - strlen(value)); -} - -void wait_for_client_read(void) -{ - WAIT_FOR_FLAG(flag_client_read); -} - -static ssize_t write_test(struct bt_conn *conn, const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - uint8_t *value = attr->user_data; - - printk("Client has written to test char\n"); - - if (offset + len > sizeof(test_value)) { - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - } - - memcpy(value + offset, buf, len); - - return len; -} - -static struct bt_gatt_attr test_attrs[] = { - /* Vendor Primary Service Declaration */ - BT_GATT_PRIMARY_SERVICE(&test_svc_uuid), - - BT_GATT_CHARACTERISTIC(&test_chrc_uuid.uuid, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | - BT_GATT_PERM_WRITE, - read_test, write_test, test_value), -}; - -static struct bt_gatt_attr test_attrs_2[] = { - /* Vendor Primary Service Declaration */ - BT_GATT_PRIMARY_SERVICE(&test_svc_uuid_2), - - BT_GATT_CHARACTERISTIC(&test_chrc_uuid.uuid, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ_ENCRYPT | - BT_GATT_PERM_WRITE_ENCRYPT, - read_test, write_test, test_value), -}; - -static struct bt_gatt_service test_svc = BT_GATT_SERVICE(test_attrs); -static struct bt_gatt_service test_svc_2 = BT_GATT_SERVICE(test_attrs_2); - -void gatt_register_service_1(void) -{ - int err = bt_gatt_service_register(&test_svc); - - __ASSERT(!err, "Failed to register GATT service (err %d)\n", err); -} - -void gatt_register_service_2(void) -{ - /* This service is only used to trigger a GATT DB change. - * No reads or writes will be attempted. - */ - int err = bt_gatt_service_register(&test_svc_2); - - __ASSERT(!err, "Failed to register GATT service (err %d)\n", err); -} - -/* We need to discover: - * - Dynamic service - * - Client Features (to set robust caching) - * - Service Changed (to sub to indications) - */ -enum GATT_HANDLES { -CLIENT_FEATURES, -SERVICE_CHANGED, -TEST_CHAR, -NUM_HANDLES, -}; - -uint16_t gatt_handles[NUM_HANDLES] = {0}; - -DEFINE_FLAG(flag_discovered); - -static uint8_t discover_func(struct bt_conn *conn, const struct bt_gatt_attr *attr, - struct bt_gatt_discover_params *params) -{ - int err; - - if (attr == NULL) { - for (int i = 0; i < ARRAY_SIZE(gatt_handles); i++) { - printk("handle[%d] = 0x%x\n", i, gatt_handles[i]); - - if (gatt_handles[i] == 0) { - FAIL("Did not discover all characteristics\n"); - } - } - - (void)memset(params, 0, sizeof(*params)); - - SET_FLAG(flag_discovered); - - return BT_GATT_ITER_STOP; - } - - if (params->type == BT_GATT_DISCOVER_PRIMARY && - bt_uuid_cmp(params->uuid, &test_svc_uuid.uuid) == 0) { - printk("Found test service\n"); - params->uuid = NULL; - params->start_handle = attr->handle + 1; - params->type = BT_GATT_DISCOVER_CHARACTERISTIC; - - err = bt_gatt_discover(conn, params); - if (err != 0) { - FAIL("Discover failed (err %d)\n", err); - } - - return BT_GATT_ITER_STOP; - } else if (params->type == BT_GATT_DISCOVER_CHARACTERISTIC) { - const struct bt_gatt_chrc *chrc = (struct bt_gatt_chrc *)attr->user_data; - - if (bt_uuid_cmp(chrc->uuid, BT_UUID_GATT_CLIENT_FEATURES) == 0) { - printk("Found client supported features\n"); - gatt_handles[CLIENT_FEATURES] = chrc->value_handle; - - } else if (bt_uuid_cmp(chrc->uuid, BT_UUID_GATT_SC) == 0) { - printk("Found service changed\n"); - gatt_handles[SERVICE_CHANGED] = chrc->value_handle; - - } else if (bt_uuid_cmp(chrc->uuid, &test_chrc_uuid.uuid) == 0) { - printk("Found test characteristic\n"); - gatt_handles[TEST_CHAR] = chrc->value_handle; - } - } - - return BT_GATT_ITER_CONTINUE; -} - -DEFINE_FLAG(flag_sc_indicated); -static uint8_t sc_indicated(struct bt_conn *conn, - struct bt_gatt_subscribe_params *params, - const void *data, uint16_t length) -{ - if (!data) { - params->value_handle = 0U; - return BT_GATT_ITER_STOP; - } - - printk("SC received\n"); - SET_FLAG(flag_sc_indicated); - - return BT_GATT_ITER_CONTINUE; -} - -void wait_for_sc_indication(void) -{ - WAIT_FOR_FLAG(flag_sc_indicated); -} - -DEFINE_FLAG(flag_sc_subscribed); -static void sc_subscribed(struct bt_conn *conn, uint8_t err, - struct bt_gatt_subscribe_params *params) -{ - if (params->value) { - printk("SC subscribed\n"); - SET_FLAG(flag_sc_subscribed); - } else { - printk("SC unsubscribed\n"); - UNSET_FLAG(flag_sc_subscribed); - } -} - -static struct bt_gatt_discover_params disc_params; -static struct bt_gatt_subscribe_params subscribe_params; -void gatt_subscribe_to_service_changed(bool subscribe) -{ - int err; - - subscribe_params.value_handle = gatt_handles[SERVICE_CHANGED]; - subscribe_params.notify = sc_indicated; - subscribe_params.subscribe = sc_subscribed; - - if (subscribe) { - /* Use the BT_GATT_AUTO_DISCOVER_CCC feature */ - subscribe_params.ccc_handle = 0; - subscribe_params.disc_params = &disc_params, - subscribe_params.value = BT_GATT_CCC_INDICATE; - subscribe_params.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE; - - err = bt_gatt_subscribe(get_conn(), &subscribe_params); - WAIT_FOR_FLAG(flag_sc_subscribed); - } else { - /* Params are already set to the correct values by the previous - * call of this fn. - */ - err = bt_gatt_unsubscribe(get_conn(), &subscribe_params); - WAIT_FOR_FLAG_UNSET(flag_sc_subscribed); - } - - if (err != 0) { - FAIL("Subscription failed(err %d)\n", err); - } else { - printk("%subscribed %s SC indications\n", - subscribe ? "S" : "Uns", - subscribe ? "to" : "from"); - } -} - -void gatt_discover(void) -{ - static struct bt_gatt_discover_params discover_params; - int err; - - printk("Discovering services and characteristics\n"); - UNSET_FLAG(flag_discovered); - - discover_params.uuid = NULL; - discover_params.func = discover_func; - discover_params.start_handle = BT_ATT_FIRST_ATTRIBUTE_HANDLE; - discover_params.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE; - discover_params.type = BT_GATT_DISCOVER_CHARACTERISTIC; - - err = bt_gatt_discover(get_conn(), &discover_params); - if (err != 0) { - FAIL("Discover failed(err %d)\n", err); - } - - WAIT_FOR_FLAG(flag_discovered); - printk("Discover complete\n"); -} - -DEFINE_FLAG(flag_written); - -static void write_cb(struct bt_conn *conn, uint8_t err, struct bt_gatt_write_params *params) -{ - if (err != BT_ATT_ERR_SUCCESS) { - FAIL("Write failed: 0x%02X\n", err); - } - - SET_FLAG(flag_written); -} - -#define CF_BIT_ROBUST_CACHING 0 -void activate_robust_caching(void) -{ - int err; - - static const uint8_t csf = BIT(CF_BIT_ROBUST_CACHING); - static struct bt_gatt_write_params write_params = { - .func = write_cb, - .offset = 0, - .data = &csf, - .length = sizeof(csf), - }; - - write_params.handle = gatt_handles[CLIENT_FEATURES]; - - UNSET_FLAG(flag_written); - err = bt_gatt_write(get_conn(), &write_params); - - __ASSERT(!err, "Failed to enable robust caching\n"); - - WAIT_FOR_FLAG(flag_written); - printk("Robust caching enabled\n"); -} - -DEFINE_FLAG(flag_read); - -static uint8_t _expect_success(struct bt_conn *conn, uint8_t err, - struct bt_gatt_read_params *params, - const void *data, uint16_t length) -{ - /* printk("GATT read cb: err 0x%02X\n", err); */ - __ASSERT(err == 0, "Failed to read: err 0x%x\n", err); - - SET_FLAG(flag_read); - - return 0; -} - -static uint8_t _expect_out_of_sync_cb(struct bt_conn *conn, uint8_t err, - struct bt_gatt_read_params *params, - const void *data, uint16_t length) -{ - /* printk("GATT read cb: err 0x%02X\n", err); */ - __ASSERT(err == BT_ATT_ERR_DB_OUT_OF_SYNC, - "Didn't get expected error code: err 0x%x\n", err); - - SET_FLAG(flag_read); - - return 0; -} - -static void read_char(uint16_t handle, bool expect_success) -{ - int err; - - struct bt_gatt_read_params read_params = { - .handle_count = 1, - .single = { - .handle = handle, - .offset = 0, - }, - }; - - if (expect_success) { - read_params.func = _expect_success; - } else { - read_params.func = _expect_out_of_sync_cb; - } - - UNSET_FLAG(flag_read); - - err = bt_gatt_read(get_conn(), &read_params); - __ASSERT(!err, "Failed to read char\n"); - - WAIT_FOR_FLAG(flag_read); -} - -void read_test_char(bool expect_success) -{ - read_char(gatt_handles[TEST_CHAR], expect_success); -} - -void gatt_clear_flags(void) -{ - UNSET_FLAG(flag_client_read); - UNSET_FLAG(flag_discovered); - UNSET_FLAG(flag_sc_indicated); - UNSET_FLAG(flag_sc_subscribed); - UNSET_FLAG(flag_written); - UNSET_FLAG(flag_read); -} diff --git a/tests/bluetooth/bsim/host/gatt/settings/src/gatt_utils.h b/tests/bluetooth/bsim/host/gatt/settings/src/gatt_utils.h deleted file mode 100644 index a80d5ca092b..00000000000 --- a/tests/bluetooth/bsim/host/gatt/settings/src/gatt_utils.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -void gatt_register_service_1(void); -void gatt_register_service_2(void); -void gatt_discover(void); -void activate_robust_caching(void); -void read_test_char(bool expect_success); -void wait_for_client_read(void); -void gatt_subscribe_to_service_changed(bool subscribe); -void wait_for_sc_indication(void); -void gatt_clear_flags(void); diff --git a/tests/bluetooth/bsim/host/gatt/settings/src/main.c b/tests/bluetooth/bsim/host/gatt/settings/src/main.c deleted file mode 100644 index 8794faad647..00000000000 --- a/tests/bluetooth/bsim/host/gatt/settings/src/main.c +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "utils.h" -#include "main.h" -#include "argparse.h" -#include "bs_pc_backchannel.h" -#include "bstests.h" - -#include - -void server_procedure(void); -void client_procedure(void); - -#define BS_SECONDS(dur_sec) ((bs_time_t)dur_sec * USEC_PER_SEC) -#define TEST_TIMEOUT_SIMULATED BS_SECONDS(30) - -static int test_round; -static int final_round; -static char *settings_file; - -int get_test_round(void) -{ - return test_round; -} - -bool is_final_round(void) -{ - return test_round == final_round; -} - -char *get_settings_file(void) -{ - return settings_file; -} - -static void test_args(int argc, char **argv) -{ - __ASSERT(argc == 3, "Please specify only 3 test arguments\n"); - - test_round = atol(argv[0]); - final_round = atol(argv[1]); - settings_file = argv[2]; - - bs_trace_raw(0, "Test round %u\n", test_round); - bs_trace_raw(0, "Final round %u\n", final_round); -} - -void test_tick(bs_time_t HW_device_time) -{ - bs_trace_debug_time(0, "Simulation ends now.\n"); - if (bst_result != Passed) { - bst_result = Failed; - bs_trace_error("Test did not pass before simulation ended.\n"); - } -} - -void test_init(void) -{ - bst_ticker_set_next_tick_absolute(TEST_TIMEOUT_SIMULATED); - bst_result = In_progress; -} - -static const struct bst_test_instance test_to_add[] = { - { - .test_id = "server", - .test_pre_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = server_procedure, - .test_args_f = test_args, - }, - { - .test_id = "client", - .test_pre_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = client_procedure, - .test_args_f = test_args, - }, - BSTEST_END_MARKER, -}; - -static struct bst_test_list *install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_to_add); -}; - -bst_test_install_t test_installers[] = { install, NULL }; - -void main(void) -{ - bst_main(); -} - - -void backchannel_init(void) -{ - uint device_number = get_device_nbr(); - uint channel_numbers[2] = { 0, 0, }; - uint device_numbers[2]; - uint num_ch; - uint *ch; - - /* No backchannels to next/prev device if only device */ - if (get_test_round() == 0 && is_final_round()) { - return; - } - - /* Each `server` round/instance gets a connection to the previous and to - * the next instance in the chain. It waits until it is signalled by the - * previous instance, then runs its test procedure and finally signals - * the next instance in the chain. - * - * The two ends of the chain get only one channel, hence the difference - * in handling. - */ - - if (get_test_round() == 0) { - /* send only */ - device_numbers[0] = get_device_nbr() + 1; - num_ch = 1; - - } else if (is_final_round()) { - /* receive only */ - device_numbers[0] = get_device_nbr() - 1; - num_ch = 1; - - } else { - /* send signal */ - device_numbers[0] = get_device_nbr() + 1; - /* receive signal */ - device_numbers[1] = get_device_nbr() - 1; - num_ch = 2; - } - - printk("Opening backchannels\n"); - ch = bs_open_back_channel(device_number, device_numbers, - channel_numbers, num_ch); - if (!ch) { - FAIL("Unable to open backchannel\n"); - } -} - -#define MSG_SIZE 1 - -void backchannel_sync_send(uint channel) -{ - uint8_t sync_msg[MSG_SIZE] = { get_device_nbr() }; - - printk("Sending sync\n"); - bs_bc_send_msg(channel, sync_msg, ARRAY_SIZE(sync_msg)); -} - -void backchannel_sync_wait(uint channel) -{ - uint8_t sync_msg[MSG_SIZE]; - - while (true) { - if (bs_bc_is_msg_received(channel) > 0) { - bs_bc_receive_msg(channel, sync_msg, - ARRAY_SIZE(sync_msg)); - if (sync_msg[0] != get_device_nbr()) { - /* Received a message from another device, exit */ - break; - } - } - - k_sleep(K_MSEC(1)); - } - - printk("Sync received\n"); -} - -/* We can't really kill the device/process without borking the bsim - * backchannels, so the next best thing is stopping all threads from processing, - * thus stopping the Bluetooth host from processing the disconnect event (or any - * event, really) coming from the link-layer. - */ -static void stop_all_threads(void) -{ - /* promote to highest priority */ - k_thread_priority_set(k_current_get(), K_HIGHEST_THREAD_PRIO); - /* busy-wait loop */ - for (;;) { - k_busy_wait(1000); - k_yield(); - } -} - -void signal_next_test_round(void) -{ - if (!is_final_round()) { - backchannel_sync_send(0); - } - - PASS("round %d over\n", get_test_round()); - stop_all_threads(); -} - -void wait_for_round_start(void) -{ - backchannel_init(); - - if (is_final_round()) { - backchannel_sync_wait(0); - } else if (get_test_round() != 0) { - backchannel_sync_wait(1); - } -} diff --git a/tests/bluetooth/bsim/host/gatt/settings/src/main.h b/tests/bluetooth/bsim/host/gatt/settings/src/main.h deleted file mode 100644 index 0659e13c60b..00000000000 --- a/tests/bluetooth/bsim/host/gatt/settings/src/main.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -char *get_settings_file(void); -int get_test_round(void); -bool is_final_round(void); - -void signal_next_test_round(void); -void wait_for_round_start(void); diff --git a/tests/bluetooth/bsim/host/gatt/settings/src/server.c b/tests/bluetooth/bsim/host/gatt/settings/src/server.c deleted file mode 100644 index 9457febc5d4..00000000000 --- a/tests/bluetooth/bsim/host/gatt/settings/src/server.c +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "utils.h" -#include "main.h" -#include "gatt_utils.h" - -#include -#include -#include -#include -#include - -#include -#include - -void set_public_addr(void) -{ - bt_addr_le_t addr = {BT_ADDR_LE_RANDOM, - {{0x0A, 0x89, 0x67, 0x45, 0x23, 0xC1}}}; - bt_id_create(&addr, NULL); -} - -void server_round_0(void) -{ - struct bt_conn *conn; - - conn = connect_as_central(); - wait_for_client_read(); - - printk("bonding\n"); - bond(conn); -} - -void server_round_1(void) -{ - struct bt_conn *conn; - - /* Wait for GATT DB hash to complete. */ - k_sleep(K_SECONDS(2)); - conn = connect_as_central(); - printk("encrypting\n"); - set_security(conn, BT_SECURITY_L2); - - wait_for_client_read(); - wait_disconnected(); - - printk("register second service, peer will be change-unaware\n"); - gatt_register_service_2(); - /* on-disk hash will be different when round 2 (and round 4) - * start, the peer will be marked as change-unaware - */ - k_sleep(K_MSEC(100)); -} - -void server_round_2(void) -{ - struct bt_conn *conn; - - conn = connect_as_central(); - printk("encrypting\n"); - set_security(conn, BT_SECURITY_L2); - - wait_for_client_read(); - - /* Kill the power before the graceful disconnect, to make sure - * that the change-aware status has been written correctly to - * NVS. We still have to wait for the delayed work to be run. - */ - k_sleep(K_MSEC(CONFIG_BT_SETTINGS_DELAYED_STORE_MS)); -} - -void server_round_3(void) -{ - struct bt_conn *conn; - - conn = connect_as_central(); - printk("encrypting\n"); - set_security(conn, BT_SECURITY_L2); - - wait_for_client_read(); - wait_disconnected(); - - printk("register second service, peer will be change-unaware\n"); - gatt_register_service_2(); - /* on-disk hash will be different when round 2 (and round 4) - * start, the peer will be marked as change-unaware - */ - k_sleep(K_MSEC(100)); -} - -void server_round_4(void) -{ - struct bt_conn *conn; - - conn = connect_as_central(); - printk("encrypting\n"); - set_security(conn, BT_SECURITY_L2); - - wait_for_client_read(); - wait_disconnected(); -} - -void server_round_5(void) -{ - gatt_register_service_2(); - - /* sleep long enough to ensure the DB hash is stored to disk, but short - * enough to make sure the delayed storage work item is not executed. - */ - k_sleep(K_MSEC(100)); -} - -void server_round_6(void) -{ - struct bt_conn *conn; - - gatt_register_service_2(); - - conn = connect_as_central(); - printk("encrypting\n"); - set_security(conn, BT_SECURITY_L2); - - wait_for_client_read(); - wait_disconnected(); -} - -/* What is being tested: since this deals with settings it's not the rounds - * themselves, but rather the transitions that test expected behavior. - * - * Round 0 -> 1: test CCC / CF values written before bonding are stored to NVS - * if the server reboots before disconnecting. - * - * Round 1 -> 2: test change-awareness is updated if GATT DB changes _after_ the - * peer has disconnected. In round 2 we also make sure we receive the Service - * Changed indication. - * - * Round 2 -> 3: tests `CONFIG_BT_SETTINGS_CF_STORE_ON_WRITE` does its job, and - * writes the change-awareness before we get disconnected. Basically, this - * transition simulates a user yanking the power of the device before it has the - * chance to disconnect. - * - * Round 3 -> 4: same as (1->2), except this time we won't get the SC indication - * (as we have unsubscribed from it). We should instead get the - * `BT_ATT_ERR_DB_OUT_OF_SYNC` error on the first attribute read. This also - * tests that robust GATT caching is enforced. - * - * Round 4 -> 5: tests change-awareness status is still written on disconnect. - * This is a non-regression test to make sure we didn't break the previous - * behavior. - * - * Round 5 -> 6: tests DFU corner case: in this case, we are on the first boot - * of an updated firmware, that will register new services. But for some unknown - * reason, we decide to reboot before the delayed store work item has had the - * time to execute and store that the peers are now change-unaware. Round 6 then - * makes sure that we are indeed change-unaware. - */ -void server_procedure(void) -{ - uint8_t round = get_test_round(); - - wait_for_round_start(); - - printk("Start test round: %d\n", get_test_round()); - - /* Use the same public address for all instances of the central. If we - * don't do that, encryption (using the bond stored in NVS) will - * fail. - */ - set_public_addr(); - - gatt_register_service_1(); - - bt_enable(NULL); - settings_load(); - - switch (round) { - case 0: - server_round_0(); - break; - case 1: - server_round_1(); - break; - case 2: - server_round_2(); - break; - case 3: - server_round_3(); - break; - case 4: - server_round_4(); - break; - case 5: - server_round_5(); - break; - case 6: - server_round_6(); - break; - default: - FAIL("Round %d doesn't exist\n", round); - break; - } - - signal_next_test_round(); -} diff --git a/tests/bluetooth/bsim/host/gatt/settings/src/settings.c b/tests/bluetooth/bsim/host/gatt/settings/src/settings.c deleted file mode 100644 index c87a8470883..00000000000 --- a/tests/bluetooth/bsim/host/gatt/settings/src/settings.c +++ /dev/null @@ -1,233 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "main.h" - -#include -#include - -#include -#include -#include "zephyr/types.h" -#include "errno.h" -#include "argparse.h" - -#include -LOG_MODULE_REGISTER(settings_backend, 3); - -#define SETTINGS_FILE setting_file -#define SETTINGS_FILE_TMP setting_file_tmp - -#define ENTRY_LEN_SIZE (4) -#define ENTRY_NAME_MAX_LEN (SETTINGS_MAX_NAME_LEN + SETTINGS_EXTRA_LEN) -#define ENTRY_VAL_MAX_LEN (SETTINGS_MAX_VAL_LEN * 2) -#define READ_LEN_MAX (ENTRY_VAL_MAX_LEN + ENTRY_NAME_MAX_LEN + 2) - -struct line_read_ctx { - int len; - const uint8_t *val; -}; - -static char setting_file[50]; -static char setting_file_tmp[sizeof(setting_file) + 1]; - -static int entry_check_and_copy(FILE *fin, FILE *fout, const char *name) -{ - char line[READ_LEN_MAX + 1]; - char name_tmp[strlen(name) + 2]; - - snprintk(name_tmp, sizeof(name_tmp), "%s=", name); - - while (fgets(line, sizeof(line), fin) == line) { - if (strstr(line, name_tmp) != NULL) { - return 0; - } - - if (fputs(line, fout) < 0) { - return -1; - } - }; - - return 0; -} - -static ssize_t settings_line_read_cb(void *cb_arg, void *data, size_t len) -{ - struct line_read_ctx *valctx = (struct line_read_ctx *)cb_arg; - - if ((valctx->len / 2) > len) { - return -ENOBUFS; - } - - uint8_t *n = (uint8_t *) data; - - len = valctx->len / 2; - - for (int i = 0; i < len; i++, n++) { - if (sscanf(&valctx->val[i * 2], "%2hhx", n) != 1) { - return 0; - }; - } - - return len; -} - -static int settings_custom_load(struct settings_store *cs, const struct settings_load_arg *arg) -{ - FILE *fp = fopen(SETTINGS_FILE, "r+"); - - if (fp == NULL) { - LOG_INF("Settings file doesn't exist, will create it"); - return -1; - } - - if (fseek(fp, 0, SEEK_SET) < 0) { - return -1; - } - - int vallen; - char line[READ_LEN_MAX + 1]; - - while (fgets(line, sizeof(line), fp) == line) { - /* check for matching subtree */ - if (arg->subtree != NULL && !strstr(line, arg->subtree)) { - continue; - } - - char *pos = strchr(line, '='); - - if (pos <= line) { - return -1; - } - - vallen = strlen(line) - (pos - line) - 2; - LOG_DBG("loading entry: %s", line); - - struct line_read_ctx valctx; - - valctx.len = vallen; - valctx.val = pos + 1; - int err = settings_call_set_handler(line, vallen / 2, settings_line_read_cb, - &valctx, arg); - - if (err < 0) { - return err; - } - }; - - return fclose(fp); -} - -/* Entries are saved to optimize readability of the settings file for test development and - * debugging purposes. Format: - * =\n - */ -static int settings_custom_save(struct settings_store *cs, const char *name, - const char *value, size_t val_len) -{ - FILE *fcur = fopen(SETTINGS_FILE, "r+"); - FILE *fnew = NULL; - - if (fcur == NULL) { - fcur = fopen(SETTINGS_FILE, "w"); - } else { - fnew = fopen(SETTINGS_FILE_TMP, "w"); - if (fnew == NULL) { - LOG_ERR("Failed to create temporary file %s", SETTINGS_FILE_TMP); - return -1; - } - } - - if (fcur == NULL) { - LOG_ERR("Failed to create settings file: %s", SETTINGS_FILE); - return -1; - } - - if (strlen(name) > ENTRY_NAME_MAX_LEN || val_len > SETTINGS_MAX_VAL_LEN) { - return -1; - } - - if (fnew != NULL) { - if (entry_check_and_copy(fcur, fnew, name) < 0) { - return -1; - } - } - - if (val_len) { - char bufvname[ENTRY_NAME_MAX_LEN + ENTRY_LEN_SIZE + 3]; - - snprintk(bufvname, sizeof(bufvname), "%s=", name); - if (fputs(bufvname, fnew != NULL ? fnew : fcur) < 0) { - return -1; - } - - char bufval[ENTRY_VAL_MAX_LEN + 2] = {}; - size_t valcnt = 0; - - while (valcnt < (val_len * 2)) { - valcnt += snprintk(&bufval[valcnt], 3, "%02x", - (uint8_t)value[valcnt / 2]); - }; - - /* helps in making settings file readable */ - bufval[valcnt++] = '\n'; - bufval[valcnt] = 0; - - LOG_DBG("writing to disk"); - - if (fputs(bufval, fnew != NULL ? fnew : fcur) < 0) { - return -1; - } - } - - if (fnew != NULL) { - entry_check_and_copy(fcur, fnew, name); - } - - fclose(fcur); - - if (fnew != NULL) { - fclose(fnew); - - remove(SETTINGS_FILE); - rename(SETTINGS_FILE_TMP, SETTINGS_FILE); - } - - return 0; -} - -/* custom backend interface */ -static struct settings_store_itf settings_custom_itf = { - .csi_load = settings_custom_load, - .csi_save = settings_custom_save, -}; - -/* custom backend node */ -static struct settings_store settings_custom_store = { - .cs_itf = &settings_custom_itf -}; - -int settings_backend_init(void) -{ - snprintf(setting_file, sizeof(setting_file), "%s_%s.log", get_simid(), get_settings_file()); - snprintf(setting_file_tmp, sizeof(setting_file_tmp), "~%s", setting_file); - - LOG_INF("file path: %s", SETTINGS_FILE); - - /* register custom backend */ - settings_dst_register(&settings_custom_store); - settings_src_register(&settings_custom_store); - return 0; -} - -void settings_test_backend_clear(void) -{ - snprintf(setting_file, sizeof(setting_file), "%s_%s.log", get_simid(), get_settings_file()); - - if (remove(setting_file)) { - LOG_INF("error deleting file: %s", setting_file); - } -} diff --git a/tests/bluetooth/bsim/host/gatt/settings/src/utils.c b/tests/bluetooth/bsim/host/gatt/settings/src/utils.c deleted file mode 100644 index 64dc5c8ede0..00000000000 --- a/tests/bluetooth/bsim/host/gatt/settings/src/utils.c +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "utils.h" -#include "gatt_utils.h" -#include -#include - -DEFINE_FLAG(flag_is_connected); -DEFINE_FLAG(flag_test_end); - -void wait_connected(void) -{ - UNSET_FLAG(flag_is_connected); - WAIT_FOR_FLAG(flag_is_connected); - printk("connected\n"); - -} - -void wait_disconnected(void) -{ - SET_FLAG(flag_is_connected); - WAIT_FOR_FLAG_UNSET(flag_is_connected); - printk("disconnected\n"); -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - bt_conn_unref(conn); - UNSET_FLAG(flag_is_connected); - gatt_clear_flags(); -} - -static void connected(struct bt_conn *conn, uint8_t err) -{ - if (err != 0) { - return; - } - - bt_conn_ref(conn); - SET_FLAG(flag_is_connected); -} - -DEFINE_FLAG(flag_encrypted); - -void security_changed(struct bt_conn *conn, bt_security_t level, - enum bt_security_err err) -{ - __ASSERT(err == 0, "Error setting security (err %u)\n", err); - - printk("Encrypted\n"); - SET_FLAG(flag_encrypted); -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, - .security_changed = security_changed, -}; - -static void scan_connect_to_first_result_device_found(const bt_addr_le_t *addr, int8_t rssi, - uint8_t type, struct net_buf_simple *ad) -{ - struct bt_conn *conn; - char addr_str[BT_ADDR_LE_STR_LEN]; - int err; - - /* We're only interested in connectable events */ - if (type != BT_HCI_ADV_IND && type != BT_HCI_ADV_DIRECT_IND) { - FAIL("Unexpected advertisement type."); - } - - bt_addr_le_to_str(addr, addr_str, sizeof(addr_str)); - printk("Got scan result, connecting.. dst %s, RSSI %d\n", - addr_str, rssi); - - err = bt_le_scan_stop(); - __ASSERT(!err, "Err bt_le_scan_stop %d", err); - - err = bt_conn_le_create(addr, - BT_CONN_LE_CREATE_CONN, BT_LE_CONN_PARAM_DEFAULT, - &conn); - __ASSERT(!err, "Err bt_conn_le_create %d", err); -} - -void scan_connect_to_first_result(void) -{ - int err; - - printk("start scanner\n"); - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, - scan_connect_to_first_result_device_found); - __ASSERT(!err, "Err bt_le_scan_start %d", err); -} - -void advertise_connectable(void) -{ - printk("start advertiser\n"); - int err; - struct bt_le_adv_param param = {}; - - param.interval_min = 0x0020; - param.interval_max = 0x4000; - param.options |= BT_LE_ADV_OPT_ONE_TIME; - param.options |= BT_LE_ADV_OPT_CONNECTABLE; - - err = bt_le_adv_start(¶m, NULL, 0, NULL, 0); - __ASSERT(err == 0, "Advertising failed to start (err %d)\n", err); -} - -void disconnect(struct bt_conn *conn) -{ - int err; - - err = bt_conn_disconnect(conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN); - __ASSERT(!err, "Failed to initate disconnection (err %d)", err); - - printk("Waiting for disconnection...\n"); - WAIT_FOR_FLAG_UNSET(flag_is_connected); -} - -static void get_active_conn_cb(struct bt_conn *src, void *dst) -{ - *(struct bt_conn **)dst = src; -} - -struct bt_conn *get_conn(void) -{ - struct bt_conn *ret; - - bt_conn_foreach(BT_CONN_TYPE_LE, get_active_conn_cb, &ret); - - return ret; -} - -DEFINE_FLAG(flag_pairing_complete); - -static void pairing_failed(struct bt_conn *conn, enum bt_security_err reason) -{ - FAIL("Pairing failed (unexpected): reason %u", reason); -} - -static void pairing_complete(struct bt_conn *conn, bool bonded) -{ - __ASSERT(bonded, "Bonding failed\n"); - - printk("Paired\n"); - SET_FLAG(flag_pairing_complete); -} - -static struct bt_conn_auth_info_cb bt_conn_auth_info_cb = { - .pairing_failed = pairing_failed, - .pairing_complete = pairing_complete, -}; - -void set_security(struct bt_conn *conn, bt_security_t sec) -{ - int err; - - UNSET_FLAG(flag_encrypted); - - err = bt_conn_set_security(conn, sec); - __ASSERT(!err, "Err bt_conn_set_security %d", err); - - WAIT_FOR_FLAG(flag_encrypted); -} - -void wait_secured(void) -{ - UNSET_FLAG(flag_encrypted); - WAIT_FOR_FLAG(flag_encrypted); -} - -void bond(struct bt_conn *conn) -{ - UNSET_FLAG(flag_pairing_complete); - - int err = bt_conn_auth_info_cb_register(&bt_conn_auth_info_cb); - - __ASSERT(!err, "bt_conn_auth_info_cb_register failed.\n"); - - set_security(conn, BT_SECURITY_L2); - - WAIT_FOR_FLAG(flag_pairing_complete); -} - -void wait_bonded(void) -{ - UNSET_FLAG(flag_encrypted); - UNSET_FLAG(flag_pairing_complete); - - int err = bt_conn_auth_info_cb_register(&bt_conn_auth_info_cb); - - __ASSERT(!err, "bt_conn_auth_info_cb_register failed.\n"); - - WAIT_FOR_FLAG(flag_encrypted); - WAIT_FOR_FLAG(flag_pairing_complete); -} - -struct bt_conn *connect_as_central(void) -{ - struct bt_conn *conn; - - scan_connect_to_first_result(); - wait_connected(); - conn = get_conn(); - - return conn; -} - -struct bt_conn *connect_as_peripheral(void) -{ - struct bt_conn *conn; - - advertise_connectable(); - wait_connected(); - conn = get_conn(); - - return conn; -} diff --git a/tests/bluetooth/bsim/host/gatt/settings/src/utils.h b/tests/bluetooth/bsim/host/gatt/settings/src/utils.h deleted file mode 100644 index a721edc1d9c..00000000000 --- a/tests/bluetooth/bsim/host/gatt/settings/src/utils.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bs_tracing.h" -#include "bs_types.h" -#include "bstests.h" -#include "time_machine.h" - -#include - -#include - -extern enum bst_result_t bst_result; - -#define DECLARE_FLAG(flag) extern atomic_t flag -#define DEFINE_FLAG(flag) atomic_t flag = (atomic_t) false -#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) true) -#define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) false) -#define WAIT_FOR_FLAG(flag) \ - while (!(bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } -#define WAIT_FOR_FLAG_UNSET(flag) \ - while ((bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } -#define TAKE_FLAG(flag) \ - while (!(bool)atomic_cas(&flag, true, false)) { \ - (void)k_sleep(K_MSEC(1)); \ - } - -#define ASSERT(expr, ...) \ - do { \ - if (!(expr)) { \ - FAIL(__VA_ARGS__); \ - } \ - } while (0) - -DECLARE_FLAG(flag_test_end); - -#define FAIL(...) \ - SET_FLAG(flag_test_end); \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - SET_FLAG(flag_test_end); \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, __VA_ARGS__); \ - } while (0) - -void disconnect(struct bt_conn *conn); -void wait_disconnected(void); -struct bt_conn *get_conn(void); -struct bt_conn *connect_as_central(void); -struct bt_conn *connect_as_peripheral(void); - -void set_security(struct bt_conn *conn, bt_security_t sec); -void wait_secured(void); -void bond(struct bt_conn *conn); -void wait_bonded(void); diff --git a/tests/bluetooth/bsim/host/gatt/settings/test_scripts/_compile.sh b/tests/bluetooth/bsim/host/gatt/settings/test_scripts/_compile.sh deleted file mode 100755 index 1805af4f425..00000000000 --- a/tests/bluetooth/bsim/host/gatt/settings/test_scripts/_compile.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -set -eu -bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" - -# Read variable definitions output by _env.sh -source "${bash_source_dir}/_env.sh" - -# Place yourself in the test's root (i.e. ./../) -west build -b nrf52_bsim -d build_test && \ - cp build_test/zephyr/zephyr.exe "${test_exe}" - -west build -b nrf52_bsim -d build_test_2 -- -DCONF_FILE=prj_2.conf && \ - cp build_test_2/zephyr/zephyr.exe "${test_2_exe}" diff --git a/tests/bluetooth/bsim/host/gatt/settings/test_scripts/_env.sh b/tests/bluetooth/bsim/host/gatt/settings/test_scripts/_env.sh deleted file mode 100755 index aba0945a3c4..00000000000 --- a/tests/bluetooth/bsim/host/gatt/settings/test_scripts/_env.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 -set -eu -bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -test_name="$(basename "$(realpath "$bash_source_dir/..")")" -bsim_bin="${BSIM_OUT_PATH}/bin" -BOARD="${BOARD:-nrf52_bsim}" -test_exe="${bsim_bin}/bs_${BOARD}_tests_bluetooth_bsim_host_gatt_settings_prj_conf" -test_2_exe="${bsim_bin}/bs_${BOARD}_tests_bluetooth_bsim_host_gatt_settings_prj_2_conf" diff --git a/tests/bluetooth/bsim/host/gatt/settings/test_scripts/run_gatt_settings.sh b/tests/bluetooth/bsim/host/gatt/settings/test_scripts/run_gatt_settings.sh deleted file mode 100755 index dfa2fa9fe0e..00000000000 --- a/tests/bluetooth/bsim/host/gatt/settings/test_scripts/run_gatt_settings.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -set -eu -bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" - -source "${bash_source_dir}/_env.sh" -simulation_id="${test_name}" -verbosity_level=2 -process_ids="" -exit_code=0 - -function Execute() { - if [ ! -f $1 ]; then - echo -e " \e[91m$(pwd)/$(basename $1) cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - $@ & - process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -cd ${BSIM_OUT_PATH}/bin - -# Remove the files used by the custom SETTINGS backend -TO_DELETE="${simulation_id}_server.log ${simulation_id}_client.log" -echo "remove settings files ${TO_DELETE}" -rm ${TO_DELETE} || true - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s="${simulation_id}" -D=8 -sim_length=30e6 $@ - -# Only one `server` device is really running at a time. This is a necessary hack -# because bsim doesn't support plugging devices in and out of a running -# simulation, but this test needs a way to power-cycle the `server` device a few -# times. -# -# Each device will wait until the previous instance (called 'test round') has -# finished executing before starting up. -Execute "$test_exe" -v=${verbosity_level} \ - -s="${simulation_id}" -d=0 -testid=server -RealEncryption=1 -argstest 0 6 "server" -Execute "$test_exe" -v=${verbosity_level} \ - -s="${simulation_id}" -d=1 -testid=server -RealEncryption=1 -argstest 1 6 "server" -Execute "$test_exe" -v=${verbosity_level} \ - -s="${simulation_id}" -d=2 -testid=server -RealEncryption=1 -argstest 2 6 "server" -Execute "$test_exe" -v=${verbosity_level} \ - -s="${simulation_id}" -d=3 -testid=server -RealEncryption=1 -argstest 3 6 "server" -Execute "$test_exe" -v=${verbosity_level} \ - -s="${simulation_id}" -d=4 -testid=server -RealEncryption=1 -argstest 4 6 "server" -Execute "$test_exe" -v=${verbosity_level} \ - -s="${simulation_id}" -d=5 -testid=server -RealEncryption=1 -argstest 5 6 "server" -Execute "$test_exe" -v=${verbosity_level} \ - -s="${simulation_id}" -d=6 -testid=server -RealEncryption=1 -argstest 6 6 "server" - -Execute "$test_exe" -v=${verbosity_level} \ - -s="${simulation_id}" -d=7 -testid=client -RealEncryption=1 -argstest 0 0 "client" - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/gatt/settings/test_scripts/run_gatt_settings_2.sh b/tests/bluetooth/bsim/host/gatt/settings/test_scripts/run_gatt_settings_2.sh deleted file mode 100755 index fb6d4e6f45a..00000000000 --- a/tests/bluetooth/bsim/host/gatt/settings/test_scripts/run_gatt_settings_2.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -set -eu -bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" - -source "${bash_source_dir}/_env.sh" -simulation_id="${test_name}_2" -verbosity_level=2 -process_ids="" -exit_code=0 - -function Execute() { - if [ ! -f $1 ]; then - echo -e " \e[91m$(pwd)/$(basename $1) cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - $@ & - process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -cd ${BSIM_OUT_PATH}/bin - -# Remove the files used by the custom SETTINGS backend -TO_DELETE="${simulation_id}_server_2.log ${simulation_id}_client_2.log" -echo "remove settings files ${TO_DELETE}" -rm ${TO_DELETE} || true - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s="${simulation_id}" -D=8 -sim_length=30e6 $@ - -# Only one `server` device is really running at a time. This is a necessary hack -# because bsim doesn't support plugging devices in and out of a running -# simulation, but this test needs a way to power-cycle the `server` device a few -# times. -# -# Each device will wait until the previous instance (called 'test round') has -# finished executing before starting up. -Execute "$test_2_exe" -v=${verbosity_level} \ - -s="${simulation_id}" -d=0 -testid=server -RealEncryption=1 -argstest 0 6 "server_2" -Execute "$test_2_exe" -v=${verbosity_level} \ - -s="${simulation_id}" -d=1 -testid=server -RealEncryption=1 -argstest 1 6 "server_2" -Execute "$test_2_exe" -v=${verbosity_level} \ - -s="${simulation_id}" -d=2 -testid=server -RealEncryption=1 -argstest 2 6 "server_2" -Execute "$test_2_exe" -v=${verbosity_level} \ - -s="${simulation_id}" -d=3 -testid=server -RealEncryption=1 -argstest 3 6 "server_2" -Execute "$test_2_exe" -v=${verbosity_level} \ - -s="${simulation_id}" -d=4 -testid=server -RealEncryption=1 -argstest 4 6 "server_2" -Execute "$test_2_exe" -v=${verbosity_level} \ - -s="${simulation_id}" -d=5 -testid=server -RealEncryption=1 -argstest 5 6 "server_2" -Execute "$test_2_exe" -v=${verbosity_level} \ - -s="${simulation_id}" -d=6 -testid=server -RealEncryption=1 -argstest 6 6 "server_2" - -Execute "$test_2_exe" -v=${verbosity_level} \ - -s="${simulation_id}" -d=7 -testid=client -RealEncryption=1 -argstest 0 0 "client_2" - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/gatt/write/CMakeLists.txt b/tests/bluetooth/bsim/host/gatt/write/CMakeLists.txt deleted file mode 100644 index e2cd305ffdd..00000000000 --- a/tests/bluetooth/bsim/host/gatt/write/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set \ - the environment variable BSIM_COMPONENTS_PATH to point to its \ - components folder. More information can be found in \ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_gatt_write) - -target_sources(app PRIVATE - src/main.c - ${ZEPHYR_BASE}/samples/bluetooth/central_gatt_write/src/gatt_write_common.c - ${ZEPHYR_BASE}/samples/bluetooth/central_gatt_write/src/central_gatt_write.c - ${ZEPHYR_BASE}/samples/bluetooth/peripheral_gatt_write/src/peripheral_gatt_write.c -) - -zephyr_include_directories( - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ -) diff --git a/tests/bluetooth/bsim/host/gatt/write/prj.conf b/tests/bluetooth/bsim/host/gatt/write/prj.conf deleted file mode 100644 index 6f52a3d5091..00000000000 --- a/tests/bluetooth/bsim/host/gatt/write/prj.conf +++ /dev/null @@ -1,14 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_SMP=y -CONFIG_BT_GATT_CLIENT=y - -CONFIG_BT_BUF_ACL_RX_SIZE=255 -CONFIG_BT_BUF_ACL_TX_SIZE=251 -CONFIG_BT_BUF_CMD_TX_SIZE=255 -CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE=255 - -CONFIG_BT_L2CAP_TX_MTU=247 - -CONFIG_BT_CTLR_DATA_LENGTH_MAX=251 diff --git a/tests/bluetooth/bsim/host/gatt/write/src/main.c b/tests/bluetooth/bsim/host/gatt/write/src/main.c deleted file mode 100644 index 06a39a05caa..00000000000 --- a/tests/bluetooth/bsim/host/gatt/write/src/main.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include - -#include -#include - -#include "bs_types.h" -#include "bs_tracing.h" -#include "time_machine.h" -#include "bstests.h" - -#define COUNT 5000 /* Arbitrary GATT Write Cmd iterations used */ - -/* Write Throughput calculation: - * Measure interval = 1 s - * Connection interval = 50 ms - * No. of connection intervals = 20 - * Single Tx time, 2M PHY = 1064 us - * tIFS = 150 us - * Single Tx duration = 1214 us - * Full duplex Tx-Rx duration = 2428 us - * Implementation dependent event overhead = 340 us - * Max. incomplete PDU time = 1064 us - * Max. radio idle time per 1 second = (1064 + 340) * 20 = 28080 us - * Packets per 1 second = (1000000 - 28080) / 2428 = 400.297 - * GATT Write data length = 244 bytes - * Throughput = 400 * 244 * 8 = 780800 bps - */ -#define WRITE_RATE 780800 /* GATT Write bps recorded in this test */ - -extern uint32_t central_gatt_write(uint32_t count); -extern uint32_t peripheral_gatt_write(uint32_t count); - -#define FAIL(...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, __VA_ARGS__); \ - } while (0) - -extern enum bst_result_t bst_result; - -static void test_central_main(void) -{ - uint32_t write_rate; - - write_rate = central_gatt_write(COUNT); - - printk("%s: Write Rate = %u bps\n", __func__, write_rate); - if (write_rate == WRITE_RATE) { - PASS("Central tests passed\n"); - } else { - FAIL("Central tests failed\n"); - } - - /* Give extra time for peripheral side to finish its iterations */ - k_sleep(K_SECONDS(1)); - - bs_trace_silent_exit(0); -} - -static void test_peripheral_main(void) -{ - uint32_t write_rate; - - write_rate = peripheral_gatt_write(COUNT); - - printk("%s: Write Rate = %u bps\n", __func__, write_rate); - if (write_rate == WRITE_RATE) { - PASS("Peripheral tests passed\n"); - } else { - FAIL("Peripheral tests failed\n"); - } -} - -static void test_gatt_write_init(void) -{ - bst_ticker_set_next_tick_absolute(60e6); - bst_result = In_progress; -} - -static void test_gatt_write_tick(bs_time_t HW_device_time) -{ - bst_result = Failed; - bs_trace_error_line("Test GATT Write finished.\n"); -} - -static const struct bst_test_instance test_def[] = { - { - .test_id = "central", - .test_descr = "Central GATT Write", - .test_post_init_f = test_gatt_write_init, - .test_tick_f = test_gatt_write_tick, - .test_main_f = test_central_main - }, - { - .test_id = "peripheral", - .test_descr = "Peripheral GATT Write", - .test_post_init_f = test_gatt_write_init, - .test_tick_f = test_gatt_write_tick, - .test_main_f = test_peripheral_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_gatt_write_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_def); -} - -bst_test_install_t test_installers[] = { - test_gatt_write_install, - NULL -}; - -void main(void) -{ - bst_main(); -} diff --git a/tests/bluetooth/bsim/host/gatt/write/tests_scripts/gatt_write.sh b/tests/bluetooth/bsim/host/gatt/write/tests_scripts/gatt_write.sh deleted file mode 100755 index 3f087de656f..00000000000 --- a/tests/bluetooth/bsim/host/gatt/write/tests_scripts/gatt_write.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2018 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -# Multiple connection between two devices with multiple peripheral identity -simulation_id="gatt_write" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 60 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_gatt_write_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_gatt_write_prj_conf\ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=60e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/l2cap/general/CMakeLists.txt b/tests/bluetooth/bsim/host/l2cap/general/CMakeLists.txt deleted file mode 100644 index 7b1d9d202e6..00000000000 --- a/tests/bluetooth/bsim/host/l2cap/general/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set\ - the environment variable BSIM_COMPONENTS_PATH to point to its components \ - folder. More information can be found in\ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_l2cap) - -FILE(GLOB app_sources src/*.c) -target_sources(app PRIVATE ${app_sources} ) - -zephyr_include_directories( - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ - ) diff --git a/tests/bluetooth/bsim/host/l2cap/general/prj.conf b/tests/bluetooth/bsim/host/l2cap/general/prj.conf deleted file mode 100644 index 430196744e3..00000000000 --- a/tests/bluetooth/bsim/host/l2cap/general/prj.conf +++ /dev/null @@ -1,24 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_SMP=y -CONFIG_BT_BONDABLE=y -CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y -CONFIG_BT_DEVICE_NAME="L2CAP test" -CONFIG_BT_EATT=n -CONFIG_BT_L2CAP_ECRED=y - -# TODO Figure out correct settings -CONFIG_BT_L2CAP_TX_MTU=2000 -CONFIG_BT_BUF_ACL_RX_SIZE=69 -CONFIG_BT_L2CAP_TX_BUF_COUNT=4 -CONFIG_BT_BUF_ACL_TX_COUNT=4 -CONFIG_BT_BUF_ACL_TX_SIZE=69 -CONFIG_BT_CTLR_RX_BUFFERS=2 -CONFIG_BT_CTLR_DATA_LENGTH_MAX=69 - -CONFIG_LOG=y - -CONFIG_BT_L2CAP_LOG_LEVEL_DBG=y - -CONFIG_ASSERT=y diff --git a/tests/bluetooth/bsim/host/l2cap/general/src/common.c b/tests/bluetooth/bsim/host/l2cap/general/src/common.c deleted file mode 100644 index 648b58f271b..00000000000 --- a/tests/bluetooth/bsim/host/l2cap/general/src/common.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "common.h" - -#define LOG_MODULE_NAME common - -#include - -LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL_DBG); - -extern enum bst_result_t bst_result; - -void test_init(void) -{ - bst_result = In_progress; - bst_ticker_set_next_tick_absolute(WAIT_TIME); -} - -void test_tick(bs_time_t HW_device_time) -{ - if (bst_result != Passed) { - FAIL("test failed (not passed after %i us)\n", WAIT_TIME); - } -} - -/* Call in init functions*/ -void device_sync_init(uint device_nbr) -{ - uint peer = CENTRAL_ID; - - if (device_nbr == CENTRAL_ID) { - peer = PERIPHERAL_ID; - } - - uint dev_nbrs[BACK_CHANNELS] = {peer}; - uint channel_nbrs[BACK_CHANNELS] = {0}; - uint *ch = bs_open_back_channel(device_nbr, dev_nbrs, channel_nbrs, BACK_CHANNELS); - - if (!ch) { - LOG_ERR("bs_open_back_channel failed!"); - } -} - -/* Call it to make peer to proceed.*/ -void device_sync_send(void) -{ - uint8_t msg[1] = "S"; - - bs_bc_send_msg(0, msg, sizeof(msg)); -} - -/* Wait until peer send sync*/ -void device_sync_wait(void) -{ - int size_msg_received = 0; - uint8_t msg; - - while (!size_msg_received) { - size_msg_received = bs_bc_is_msg_received(0); - k_sleep(K_MSEC(1)); - } - - bs_bc_receive_msg(0, &msg, size_msg_received); -} diff --git a/tests/bluetooth/bsim/host/l2cap/general/src/common.h b/tests/bluetooth/bsim/host/l2cap/general/src/common.h deleted file mode 100644 index a399786bfd2..00000000000 --- a/tests/bluetooth/bsim/host/l2cap/general/src/common.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Common functions and helpers for L2CAP tests - * - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include -#include -#include - -#include -#include -#include -#include "bs_types.h" -#include "bs_tracing.h" -#include "bstests.h" -#include "bs_pc_backchannel.h" - -#define CREATE_FLAG(flag) static atomic_t flag = (atomic_t)false -#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)true) -#define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)false) -#define TEST_FLAG(flag) (atomic_get(&flag) == (atomic_t)true) -#define WAIT_FOR_FLAG_SET(flag) \ - while (!(bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } -#define WAIT_FOR_FLAG_UNSET(flag) \ - while ((bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } - - -#define WAIT_TIME (60e6) /* 60 seconds*/ - -#define FAIL(...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, __VA_ARGS__); \ - } while (0) - -#define CENTRAL_ID 0 -#define PERIPHERAL_ID 1 -#define BACK_CHANNELS 1 - -void test_init(void); -void test_tick(bs_time_t HW_device_time); -void device_sync_init(uint device_nbr); -void device_sync_send(void); -void device_sync_wait(void); diff --git a/tests/bluetooth/bsim/host/l2cap/general/src/main.c b/tests/bluetooth/bsim/host/l2cap/general/src/main.c deleted file mode 100644 index fccfd9d2657..00000000000 --- a/tests/bluetooth/bsim/host/l2cap/general/src/main.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bstests.h" - -extern struct bst_test_list *test_main_l2cap_ecred_install(struct bst_test_list *tests); - -bst_test_install_t test_installers[] = { - test_main_l2cap_ecred_install, - NULL -}; - -void main(void) -{ - bst_main(); -} diff --git a/tests/bluetooth/bsim/host/l2cap/general/src/main_l2cap_ecred.c b/tests/bluetooth/bsim/host/l2cap/general/src/main_l2cap_ecred.c deleted file mode 100644 index 19a18712508..00000000000 --- a/tests/bluetooth/bsim/host/l2cap/general/src/main_l2cap_ecred.c +++ /dev/null @@ -1,603 +0,0 @@ -/* main_l2cap_ecred.c - Application main entry point */ - -/* - * Copyright (c) 2022 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "common.h" - -#define LOG_MODULE_NAME main_l2cap_ecred -#include -LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL_DBG); - -extern enum bst_result_t bst_result; - -static struct bt_conn *default_conn; - -static const struct bt_data ad[] = { - BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), -}; - -#define DATA_MTU CONFIG_BT_L2CAP_TX_MTU -#define DATA_MPS 65 -#define DATA_BUF_SIZE BT_L2CAP_SDU_BUF_SIZE(DATA_MTU) -#define L2CAP_CHANNELS 2 -#define SERVERS 1 -#define SDU_SEND_COUNT 200 -#define ECRED_CHAN_MAX 5 -#define LONG_MSG (DATA_MTU - 500) -#define SHORT_MSG (DATA_MPS - 2) -#define LONG_MSG_CHAN_IDX 0 -#define SHORT_MSG_CHAN_IDX 1 - -NET_BUF_POOL_FIXED_DEFINE(rx_data_pool, L2CAP_CHANNELS, BT_L2CAP_BUF_SIZE(DATA_BUF_SIZE), 8, NULL); -NET_BUF_POOL_FIXED_DEFINE(tx_data_pool_0, 1, BT_L2CAP_BUF_SIZE(DATA_MTU), 8, NULL); -NET_BUF_POOL_FIXED_DEFINE(tx_data_pool_1, 1, BT_L2CAP_BUF_SIZE(DATA_MTU), 8, NULL); - -static struct bt_l2cap_server servers[SERVERS]; -void send_sdu_chan_worker(struct k_work *item); -struct channel { - uint8_t chan_id; /* Internal number that identifies L2CAP channel. */ - struct bt_l2cap_le_chan le; - bool in_use; - size_t sdus_received; - size_t bytes_to_send; - uint8_t iteration; - struct net_buf *buf; - struct k_work work; - struct k_work_q work_queue; - uint8_t payload[DATA_MTU]; -}; -static struct channel channels[L2CAP_CHANNELS]; - -CREATE_FLAG(is_connected); -CREATE_FLAG(unsequenced_data); - -#define T_STACK_SIZE 512 -#define T_PRIORITY 5 - -static K_THREAD_STACK_ARRAY_DEFINE(stack_area, L2CAP_CHANNELS, T_STACK_SIZE); -static K_SEM_DEFINE(chan_conn_sem, 0, L2CAP_CHANNELS); -static K_SEM_DEFINE(all_chan_conn_sem, 0, 1); -static K_SEM_DEFINE(all_chan_disconn_sem, 0, 1); -static K_SEM_DEFINE(sent_sem, 0, L2CAP_CHANNELS); - -static void init_workqs(void) -{ - for (int i = 0; i < L2CAP_CHANNELS; i++) { - k_work_queue_init(&channels[i].work_queue); - k_work_queue_start(&channels[i].work_queue, stack_area[i], - K_THREAD_STACK_SIZEOF(*stack_area), T_PRIORITY, NULL); - } -} - -static struct net_buf *chan_alloc_buf_cb(struct bt_l2cap_chan *chan) -{ - LOG_DBG("Allocated on chan %p", chan); - return net_buf_alloc(&rx_data_pool, K_FOREVER); -} - -static int chan_recv_cb(struct bt_l2cap_chan *l2cap_chan, struct net_buf *buf) -{ - struct channel *chan = CONTAINER_OF(l2cap_chan, struct channel, le); - const uint32_t received_iterration = net_buf_pull_le32(buf); - - LOG_DBG("received_iterration %i sdus_received %i, chan_id: %d, data_length: %d", - received_iterration, chan->sdus_received, chan->chan_id, buf->len); - if (!TEST_FLAG(unsequenced_data) && received_iterration != chan->sdus_received) { - FAIL("Received out of sequence data."); - } - - const int retval = memcmp(buf->data + sizeof(received_iterration), - chan->payload + sizeof(received_iterration), - buf->len - sizeof(received_iterration)); - if (retval) { - FAIL("Payload received didn't match expected value memcmp returned %i", retval); - } - - /*By the time we rx on long msg channel we should have already rx on short msg channel*/ - if (chan->chan_id == 0) { - if (channels[SHORT_MSG_CHAN_IDX].sdus_received != - (channels[LONG_MSG_CHAN_IDX].sdus_received + 1)) { - FAIL("Didn't receive on short msg channel first"); - } - } - - chan->sdus_received++; - - return 0; -} - -static void chan_sent_cb(struct bt_l2cap_chan *l2cap_chan) -{ - struct channel *chan = CONTAINER_OF(l2cap_chan, struct channel, le); - - chan->buf = 0; - k_sem_give(&sent_sem); - - LOG_DBG("chan_id: %d", chan->chan_id); -} - -static void chan_connected_cb(struct bt_l2cap_chan *l2cap_chan) -{ - struct channel *chan = CONTAINER_OF(l2cap_chan, struct channel, le); - - LOG_DBG("chan_id: %d", chan->chan_id); - - LOG_DBG("tx.mtu %d, tx.mps: %d, rx.mtu: %d, rx.mps %d", sys_cpu_to_le16(chan->le.tx.mtu), - sys_cpu_to_le16(chan->le.tx.mps), sys_cpu_to_le16(chan->le.rx.mtu), - sys_cpu_to_le16(chan->le.rx.mps)); - - k_sem_give(&chan_conn_sem); - - if (k_sem_count_get(&chan_conn_sem) == L2CAP_CHANNELS) { - k_sem_give(&all_chan_conn_sem); - k_sem_reset(&all_chan_disconn_sem); - } -} - -static void chan_disconnected_cb(struct bt_l2cap_chan *l2cap_chan) -{ - struct channel *chan = CONTAINER_OF(l2cap_chan, struct channel, le); - - LOG_DBG("chan_id: %d", chan->chan_id); - - chan->in_use = false; - k_sem_take(&chan_conn_sem, K_FOREVER); - - if (k_sem_count_get(&chan_conn_sem) == 0) { - k_sem_give(&all_chan_disconn_sem); - k_sem_reset(&all_chan_conn_sem); - } -} - -static void chan_status_cb(struct bt_l2cap_chan *l2cap_chan, atomic_t *status) -{ - struct channel *chan = CONTAINER_OF(l2cap_chan, struct channel, le); - - LOG_DBG("chan_id: %d, status: %ld", chan->chan_id, *status); -} - -static void chan_released_cb(struct bt_l2cap_chan *l2cap_chan) -{ - struct channel *chan = CONTAINER_OF(l2cap_chan, struct channel, le); - - LOG_DBG("chan_id: %d", chan->chan_id); -} - -static void chan_reconfigured_cb(struct bt_l2cap_chan *l2cap_chan) -{ - struct channel *chan = CONTAINER_OF(l2cap_chan, struct channel, le); - - LOG_DBG("chan_id: %d", chan->chan_id); -} - -static const struct bt_l2cap_chan_ops l2cap_ops = { - .alloc_buf = chan_alloc_buf_cb, - .recv = chan_recv_cb, - .sent = chan_sent_cb, - .connected = chan_connected_cb, - .disconnected = chan_disconnected_cb, - .status = chan_status_cb, - .released = chan_released_cb, - .reconfigured = chan_reconfigured_cb, -}; - -static struct channel *get_free_channel(void) -{ - for (int idx = 0; idx < L2CAP_CHANNELS; idx++) { - struct channel *chan = &channels[idx]; - - if (chan->in_use) { - continue; - } - - chan->chan_id = idx; - channels[idx].in_use = true; - (void)memset(chan->payload, idx, sizeof(chan->payload)); - k_work_init(&chan->work, send_sdu_chan_worker); - chan->le.chan.ops = &l2cap_ops; - chan->le.rx.mtu = DATA_MTU; - chan->le.rx.mps = DATA_MPS; - - return chan; - } - - return NULL; -} - -static void connect_num_channels(uint8_t num_l2cap_channels) -{ - struct bt_l2cap_chan *allocated_channels[ECRED_CHAN_MAX] = { NULL }; - - for (int i = 0; i < num_l2cap_channels; i++) { - struct channel *chan = get_free_channel(); - - if (!chan) { - FAIL("failed, chan not free"); - return; - } - - allocated_channels[i] = &chan->le.chan; - } - - const int err = bt_l2cap_ecred_chan_connect(default_conn, allocated_channels, - servers[0].psm); - - if (err) { - FAIL("can't connect ecred %d ", err); - } -} - -static void disconnect_all_channels(void) -{ - for (int i = 0; i < ARRAY_SIZE(channels); i++) { - if (channels[i].in_use) { - LOG_DBG("Disconnecting channel: %d)", channels[i].chan_id); - const int err = bt_l2cap_chan_disconnect(&channels[i].le.chan); - - if (err) { - LOG_DBG("can't disconnect channel (err: %d)", err); - } - - channels[i].in_use = false; - } - } -} - -static int accept(struct bt_conn *conn, struct bt_l2cap_chan **l2cap_chan) -{ - struct channel *chan; - - chan = get_free_channel(); - if (!chan) { - return -ENOMEM; - } - - *l2cap_chan = &chan->le.chan; - - return 0; -} - -static struct bt_l2cap_server *get_free_server(void) -{ - for (int i = 0; i < SERVERS; i++) { - if (servers[i].psm) { - continue; - } - - return &servers[i]; - } - - return NULL; -} - -static void register_l2cap_server(void) -{ - struct bt_l2cap_server *server; - - server = get_free_server(); - if (!server) { - FAIL("Failed to get free server"); - return; - } - - server->accept = accept; - server->psm = 0; - - if (bt_l2cap_server_register(server) < 0) { - FAIL("Failed to get free server"); - return; - } - - LOG_DBG("L2CAP server registered, PSM:0x%X", server->psm); -} - -static void connected(struct bt_conn *conn, uint8_t conn_err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (conn_err) { - FAIL("Failed to connect to %s (%u)", addr, conn_err); - bt_conn_unref(default_conn); - default_conn = NULL; - return; - } - - default_conn = bt_conn_ref(conn); - LOG_DBG("%s", addr); - - SET_FLAG(is_connected); -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - LOG_DBG("%s (reason 0x%02x)", addr, reason); - - if (default_conn != conn) { - FAIL("Conn mismatch disconnect %s %s)", default_conn, conn); - return; - } - - bt_conn_unref(default_conn); - default_conn = NULL; - UNSET_FLAG(is_connected); -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - -static void send_sdu(int iteration, int chan_idx, int bytes) -{ - struct bt_l2cap_chan *chan = &channels[chan_idx].le.chan; - struct net_buf *buf; - - /* First 4 bytes in sent payload is iteration count */ - sys_put_le32(iteration, channels[chan_idx].payload); - - if (channels[chan_idx].buf != 0) { - FAIL("Buf should have been deallocated by now"); - return; - } - - if (chan_idx == 0) { - buf = net_buf_alloc(&tx_data_pool_0, K_NO_WAIT); - } else { - buf = net_buf_alloc(&tx_data_pool_1, K_NO_WAIT); - } - - if (buf == NULL) { - FAIL("Failed to get buff on ch %i, iteration %i should never happen", chan_idx, - chan_idx); - } - - channels[chan_idx].buf = buf; - net_buf_reserve(buf, BT_L2CAP_CHAN_SEND_RESERVE); - net_buf_add_mem(buf, channels[chan_idx].payload, bytes); - - LOG_DBG("bt_l2cap_chan_sending ch: %i bytes: %i iteration: %i", chan_idx, bytes, iteration); - const int ret = bt_l2cap_chan_send(chan, buf); - - LOG_DBG("bt_l2cap_chan_send returned: %i", ret); - - if (ret < 0) { - FAIL("Error: send failed error: %i", ret); - channels[chan_idx].buf = 0; - net_buf_unref(buf); - } -} - -void send_sdu_chan_worker(struct k_work *item) -{ - const struct channel *ch = CONTAINER_OF(item, struct channel, work); - - send_sdu(ch->iteration, ch->chan_id, ch->bytes_to_send); -} - -static void send_sdu_concurrently(void) -{ - for (int i = 0; i < SDU_SEND_COUNT; i++) { - for (int k = 0; k < L2CAP_CHANNELS; k++) { - channels[k].iteration = i; - /* Assign the right msg to the right channel */ - channels[k].bytes_to_send = (k == LONG_MSG_CHAN_IDX) ? LONG_MSG : SHORT_MSG; - const int err = k_work_submit_to_queue(&channels[k].work_queue, - &channels[k].work); - - if (err < 0) { - FAIL("Failed to submit work to the queue, error: %d", err); - } - } - - /* Wait until messages on all of the channels has been sent */ - for (int l = 0; l < L2CAP_CHANNELS; l++) { - k_sem_take(&sent_sem, K_FOREVER); - } - } -} - -static int change_mtu_on_channels(int num_channels, int new_mtu) -{ - struct bt_l2cap_chan *reconf_channels[ECRED_CHAN_MAX] = { NULL }; - - for (int i = 0; i < num_channels; i++) { - reconf_channels[i] = &(&channels[i])->le.chan; - } - - return bt_l2cap_ecred_chan_reconfigure(reconf_channels, new_mtu); -} - -static void test_peripheral_main(void) -{ - device_sync_init(PERIPHERAL_ID); - LOG_DBG("*L2CAP ECRED Peripheral started*"); - init_workqs(); - int err; - - err = bt_enable(NULL); - if (err) { - FAIL("Can't enable Bluetooth (err %d)", err); - return; - } - - LOG_DBG("Peripheral Bluetooth initialized."); - LOG_DBG("Connectable advertising..."); - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0); - if (err) { - FAIL("Advertising failed to start (err %d)", err); - return; - } - - LOG_DBG("Advertising started."); - LOG_DBG("Peripheral waiting for connection..."); - WAIT_FOR_FLAG_SET(is_connected); - LOG_DBG("Peripheral Connected."); - register_l2cap_server(); - connect_num_channels(L2CAP_CHANNELS); - k_sem_take(&all_chan_conn_sem, K_FOREVER); - - /* Disconnect and reconnect channels *****************************************************/ - LOG_DBG("############# Disconnect and reconnect channels"); - disconnect_all_channels(); - k_sem_take(&all_chan_disconn_sem, K_FOREVER); - - connect_num_channels(L2CAP_CHANNELS); - k_sem_take(&all_chan_conn_sem, K_FOREVER); - - LOG_DBG("Send sync after reconnection"); - device_sync_send(); - - /* Send bytes on both channels and expect ch 1 to receive all of them before ch 0 *********/ - LOG_DBG("############# Send bytes on both channels concurrently"); - send_sdu_concurrently(); - - /* Change mtu size on all connected channels *********************************************/ - LOG_DBG("############# Change MTU of the channels"); - err = change_mtu_on_channels(L2CAP_CHANNELS, CONFIG_BT_L2CAP_TX_MTU + 10); - - if (err) { - FAIL("MTU change failed (err %d)\n", err); - } - - /* Read from both devices (Central and Peripheral) at the same time **********************/ - LOG_DBG("############# Read from both devices (Central and Peripheral) at the same time"); - LOG_DBG("Wait for sync before sending the msg"); - device_sync_wait(); - LOG_DBG("Received sync"); - send_sdu(0, 1, 10); - - k_sem_take(&sent_sem, K_FOREVER); - disconnect_all_channels(); - WAIT_FOR_FLAG_UNSET(is_connected); - PASS("L2CAP ECRED Peripheral tests Passed"); - bs_trace_silent_exit(0); -} - -static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, - struct net_buf_simple *ad) -{ - struct bt_le_conn_param *param; - int err; - - err = bt_le_scan_stop(); - if (err) { - FAIL("Stop LE scan failed (err %d)", err); - return; - } - - param = BT_LE_CONN_PARAM_DEFAULT; - err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, param, &default_conn); - if (err) { - FAIL("Create conn failed (err %d)", err); - return; - } -} - -static void test_central_main(void) -{ - struct bt_le_scan_param scan_param = { - .type = BT_LE_SCAN_TYPE_ACTIVE, - .options = BT_LE_SCAN_OPT_NONE, - .interval = BT_GAP_SCAN_FAST_INTERVAL, - .window = BT_GAP_SCAN_FAST_WINDOW, - }; - - device_sync_init(CENTRAL_ID); - - LOG_DBG("*L2CAP ECRED Central started*"); - int err; - - err = bt_enable(NULL); - if (err) { - FAIL("Can't enable Bluetooth (err %d)\n", err); - return; - } - LOG_DBG("Central Bluetooth initialized.\n"); - - err = bt_le_scan_start(&scan_param, device_found); - if (err) { - FAIL("Scanning failed to start (err %d)\n", err); - return; - } - - LOG_DBG("Scanning successfully started\n"); - - LOG_DBG("Central waiting for connection...\n"); - WAIT_FOR_FLAG_SET(is_connected); - LOG_DBG("Central Connected.\n"); - register_l2cap_server(); - - LOG_DBG("Wait for sync after reconnection"); - device_sync_wait(); - LOG_DBG("Received sync"); - - /* Read from both devices (Central and Peripheral) at the same time **********************/ - LOG_DBG("############# Read from both devices (Central and Peripheral) at the same time"); - LOG_DBG("Send sync for SDU send"); - SET_FLAG(unsequenced_data); - device_sync_send(); - send_sdu(0, 1, 10); - - /* Wait until all of the channels are disconnected */ - k_sem_take(&all_chan_disconn_sem, K_FOREVER); - - LOG_DBG("Both l2cap channels disconnected, test over\n"); - - UNSET_FLAG(unsequenced_data); - LOG_DBG("received PDUs on long msg channel %i and short msg channel %i", - channels[LONG_MSG_CHAN_IDX].sdus_received, - channels[SHORT_MSG_CHAN_IDX].sdus_received); - - if (channels[LONG_MSG_CHAN_IDX].sdus_received < SDU_SEND_COUNT || - channels[SHORT_MSG_CHAN_IDX].sdus_received < SDU_SEND_COUNT) { - FAIL("received less than %i", SDU_SEND_COUNT); - } - - /* Disconnect */ - LOG_DBG("Central Disconnecting...."); - err = bt_conn_disconnect(default_conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN); - bt_conn_unref(default_conn); - LOG_DBG("Central tried to disconnect"); - - if (err) { - FAIL("Disconnection failed (err %d)", err); - return; - } - - LOG_DBG("Central Disconnected."); - - PASS("L2CAP ECRED Central tests Passed\n"); -} - -static const struct bst_test_instance test_def[] = { - { - .test_id = "peripheral", - .test_descr = "Peripheral L2CAP ECRED", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_peripheral_main - }, - { - .test_id = "central", - .test_descr = "Central L2CAP ECRED", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_central_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_main_l2cap_ecred_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_def); -} diff --git a/tests/bluetooth/bsim/host/l2cap/general/tests_scripts/l2cap.sh b/tests/bluetooth/bsim/host/l2cap/general/tests_scripts/l2cap.sh deleted file mode 100755 index 16f33b90595..00000000000 --- a/tests/bluetooth/bsim/host/l2cap/general/tests_scripts/l2cap.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env bash -# Copyright (c) 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -# EATT test -simulation_id="l2cap_ecred" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 120 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_l2cap_general_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central -rs=43 - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_l2cap_general_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral -rs=42 - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=60e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/l2cap/stress/CMakeLists.txt b/tests/bluetooth/bsim/host/l2cap/stress/CMakeLists.txt deleted file mode 100644 index b101ffda47c..00000000000 --- a/tests/bluetooth/bsim/host/l2cap/stress/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set\ - the environment variable BSIM_COMPONENTS_PATH to point to its components \ - folder. More information can be found in\ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_l2cap_stress) - -FILE(GLOB app_sources src/*.c) -target_sources(app PRIVATE ${app_sources} ) - -zephyr_include_directories( - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ - ) diff --git a/tests/bluetooth/bsim/host/l2cap/stress/prj.conf b/tests/bluetooth/bsim/host/l2cap/stress/prj.conf deleted file mode 100644 index fcb08ee2217..00000000000 --- a/tests/bluetooth/bsim/host/l2cap/stress/prj.conf +++ /dev/null @@ -1,49 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_DEVICE_NAME="L2CAP stress test" - -CONFIG_BT_EATT=n -CONFIG_BT_L2CAP_ECRED=n - -CONFIG_BT_SMP=y # Next config depends on it -CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y - -# Disable auto-initiated procedures so they don't -# mess with the test's execution. -CONFIG_BT_AUTO_PHY_UPDATE=n -CONFIG_BT_AUTO_DATA_LEN_UPDATE=n -CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n - -# L2CAP MPS -# 23+27+27=77 makes exactly three full packets -CONFIG_BT_L2CAP_TX_MTU=77 - -# Use this to send L2CAP PDUs without any fragmentation. -# In this particular case, we prefer fragmenting to test that code path. -# CONFIG_BT_BUF_ACL_TX_SIZE=81 - -# L2CAP PDUs will be fragmented in 3 ACL packets. -CONFIG_BT_BUF_ACL_TX_SIZE=27 - -CONFIG_BT_BUF_ACL_TX_COUNT=4 - -# The minimum value for this is -# L2AP MPS + L2CAP header (4) -CONFIG_BT_BUF_ACL_RX_SIZE=81 - -# Governs BT_CONN_TX_MAX, and so must be >= than the max number of -# peers, since we attempt to send one SDU per peer. The test execution -# is a bit slowed down by having this at the very minimum, but we want -# to keep it that way as to stress the stack as much as possible. -CONFIG_BT_L2CAP_TX_BUF_COUNT=6 - -CONFIG_BT_CTLR_DATA_LENGTH_MAX=27 -CONFIG_BT_CTLR_RX_BUFFERS=10 - -CONFIG_BT_MAX_CONN=10 - -CONFIG_LOG=y -CONFIG_ASSERT=y -CONFIG_BT_DEBUG_LOG=y -CONFIG_NET_BUF_POOL_USAGE=y diff --git a/tests/bluetooth/bsim/host/l2cap/stress/src/common.c b/tests/bluetooth/bsim/host/l2cap/stress/src/common.c deleted file mode 100644 index 5b344c60571..00000000000 --- a/tests/bluetooth/bsim/host/l2cap/stress/src/common.c +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "common.h" - -extern enum bst_result_t bst_result; - -void test_init(void) -{ - bst_ticker_set_next_tick_absolute(WAIT_TIME); - bst_result = In_progress; -} - -void test_tick(bs_time_t HW_device_time) -{ - if (bst_result != Passed) { - FAIL("test failed (not passed after %i seconds)\n", WAIT_SECONDS); - } -} diff --git a/tests/bluetooth/bsim/host/l2cap/stress/src/common.h b/tests/bluetooth/bsim/host/l2cap/stress/src/common.h deleted file mode 100644 index d3b01cd1d68..00000000000 --- a/tests/bluetooth/bsim/host/l2cap/stress/src/common.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Common functions and helpers for L2CAP tests - * - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include -#include -#include - -#include -#include -#include -#include "bs_types.h" -#include "bs_tracing.h" -#include "bstests.h" -#include "bs_pc_backchannel.h" - -extern enum bst_result_t bst_result; - -#define CREATE_FLAG(flag) static atomic_t flag = (atomic_t)false -#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)true) -#define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)false) -#define TEST_FLAG(flag) (atomic_get(&flag) == (atomic_t)true) -#define WAIT_FOR_FLAG_SET(flag) \ - while (!(bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } -#define WAIT_FOR_FLAG_UNSET(flag) \ - while ((bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } - - -#define WAIT_SECONDS 270 /* seconds */ -#define WAIT_TIME (WAIT_SECONDS * USEC_PER_SEC) /* microseconds*/ - -#define FAIL(...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, __VA_ARGS__); \ - } while (0) - -#define ASSERT(expr, ...) if (!(expr)) {FAIL(__VA_ARGS__); } - -void test_init(void); -void test_tick(bs_time_t HW_device_time); diff --git a/tests/bluetooth/bsim/host/l2cap/stress/src/main.c b/tests/bluetooth/bsim/host/l2cap/stress/src/main.c deleted file mode 100644 index 62871d9697c..00000000000 --- a/tests/bluetooth/bsim/host/l2cap/stress/src/main.c +++ /dev/null @@ -1,469 +0,0 @@ -/* main_l2cap_stress.c - Application main entry point */ - -/* - * Copyright (c) 2022 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bstests.h" -#include "common.h" - -#define LOG_MODULE_NAME main -#include -LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL_DBG); - -CREATE_FLAG(is_connected); -CREATE_FLAG(flag_l2cap_connected); - -#define NUM_PERIPHERALS 6 -#define L2CAP_CHANS NUM_PERIPHERALS -#define INIT_CREDITS 10 -#define SDU_NUM 20 -#define SDU_LEN 1230 -#define NUM_SEGMENTS 10 - -/* Only one SDU per link will be transmitted at a time */ -NET_BUF_POOL_DEFINE(sdu_tx_pool, - CONFIG_BT_MAX_CONN, BT_L2CAP_SDU_BUF_SIZE(SDU_LEN), - 8, NULL); - -NET_BUF_POOL_DEFINE(segment_pool, - /* MTU + 4 l2cap hdr + 4 ACL hdr */ - NUM_SEGMENTS, BT_L2CAP_BUF_SIZE(CONFIG_BT_L2CAP_TX_MTU), - 8, NULL); - -/* Only one SDU per link will be received at a time */ -NET_BUF_POOL_DEFINE(sdu_rx_pool, - CONFIG_BT_MAX_CONN, BT_L2CAP_SDU_BUF_SIZE(SDU_LEN), - 8, NULL); - -static struct bt_l2cap_le_chan l2cap_channels[L2CAP_CHANS]; -static struct bt_l2cap_chan *l2cap_chans[L2CAP_CHANS]; - -static uint8_t tx_data[SDU_LEN]; -static uint8_t tx_left[L2CAP_CHANS]; -static uint16_t rx_cnt; -static uint8_t disconnect_counter; -static uint32_t max_seg_allocated; - -int l2cap_chan_send(struct bt_l2cap_chan *chan, uint8_t *data, size_t len) -{ - LOG_DBG("chan %p conn %p data %p len %d", chan, chan->conn, data, len); - - struct net_buf *buf = net_buf_alloc(&sdu_tx_pool, K_NO_WAIT); - - if (buf == NULL) { - FAIL("No more memory\n"); - return -ENOMEM; - } - - net_buf_reserve(buf, BT_L2CAP_SDU_CHAN_SEND_RESERVE); - net_buf_add_mem(buf, data, len); - - int ret = bt_l2cap_chan_send(chan, buf); - - if (ret < 0) { - FAIL("L2CAP error %d\n", ret); - net_buf_unref(buf); - } - - LOG_DBG("sent %d len %d", ret, len); - return ret; -} - -struct net_buf *alloc_seg_cb(struct bt_l2cap_chan *chan) -{ - struct net_buf *buf = net_buf_alloc(&segment_pool, K_NO_WAIT); - - if ((NUM_SEGMENTS - segment_pool.avail_count) > max_seg_allocated) { - max_seg_allocated++; - } - - ASSERT(buf, "Ran out of segment buffers"); - - return buf; -} - -struct net_buf *alloc_buf_cb(struct bt_l2cap_chan *chan) -{ - return net_buf_alloc(&sdu_rx_pool, K_NO_WAIT); -} - -static int get_l2cap_chan(struct bt_l2cap_chan *chan) -{ - for (int i = 0; i < L2CAP_CHANS; i++) { - if (l2cap_chans[i] == chan) { - return i; - } - } - - FAIL("Channel %p not found\n", chan); - return -1; -} - -static void register_channel(struct bt_l2cap_chan *chan) -{ - int i = get_l2cap_chan(NULL); - - l2cap_chans[i] = chan; -} - -void sent_cb(struct bt_l2cap_chan *chan) -{ - LOG_DBG("%p", chan); - int idx = get_l2cap_chan(chan); - - if (tx_left[idx]) { - tx_left[idx]--; - l2cap_chan_send(chan, tx_data, sizeof(tx_data)); - } else { - LOG_DBG("Done sending %p", chan->conn); - } -} - -int recv_cb(struct bt_l2cap_chan *chan, struct net_buf *buf) -{ - LOG_DBG("len %d", buf->len); - rx_cnt++; - - /* Verify SDU data matches TX'd data. */ - ASSERT(memcmp(buf->data, tx_data, buf->len) == 0, "RX data doesn't match TX"); - - return 0; -} - -void l2cap_chan_connected_cb(struct bt_l2cap_chan *l2cap_chan) -{ - struct bt_l2cap_le_chan *chan = - CONTAINER_OF(l2cap_chan, struct bt_l2cap_le_chan, chan); - - SET_FLAG(flag_l2cap_connected); - LOG_DBG("%x (tx mtu %d mps %d) (tx mtu %d mps %d)", - l2cap_chan, - chan->tx.mtu, - chan->tx.mps, - chan->rx.mtu, - chan->rx.mps); - - register_channel(l2cap_chan); -} - -void l2cap_chan_disconnected_cb(struct bt_l2cap_chan *chan) -{ - UNSET_FLAG(flag_l2cap_connected); - LOG_DBG("%x", chan); -} - -static struct bt_l2cap_chan_ops ops = { - .connected = l2cap_chan_connected_cb, - .disconnected = l2cap_chan_disconnected_cb, - .alloc_buf = alloc_buf_cb, - .alloc_seg = alloc_seg_cb, - .recv = recv_cb, - .sent = sent_cb, -}; - -struct bt_l2cap_le_chan *get_free_l2cap_le_chan(void) -{ - for (int i = 0; i < L2CAP_CHANS; i++) { - struct bt_l2cap_le_chan *le_chan = &l2cap_channels[i]; - - if (le_chan->state != BT_L2CAP_DISCONNECTED) { - continue; - } - - memset(le_chan, 0, sizeof(*le_chan)); - return le_chan; - } - - return NULL; -} - -int server_accept_cb(struct bt_conn *conn, struct bt_l2cap_chan **chan) -{ - struct bt_l2cap_le_chan *le_chan = NULL; - - le_chan = get_free_l2cap_le_chan(); - if (le_chan == NULL) { - return -ENOMEM; - } - - memset(le_chan, 0, sizeof(*le_chan)); - le_chan->chan.ops = &ops; - le_chan->rx.mtu = SDU_LEN; - le_chan->rx.init_credits = INIT_CREDITS; - le_chan->tx.init_credits = INIT_CREDITS; - *chan = &le_chan->chan; - - return 0; -} - -static struct bt_l2cap_server test_l2cap_server = { - .accept = server_accept_cb -}; - -static int l2cap_server_register(bt_security_t sec_level) -{ - test_l2cap_server.psm = 0; - test_l2cap_server.sec_level = sec_level; - - int err = bt_l2cap_server_register(&test_l2cap_server); - - ASSERT(err == 0, "Failed to register l2cap server."); - - return test_l2cap_server.psm; -} - -static void connected(struct bt_conn *conn, uint8_t conn_err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (conn_err) { - FAIL("Failed to connect to %s (%u)", addr, conn_err); - return; - } - - LOG_DBG("%s", addr); - - SET_FLAG(is_connected); -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - LOG_DBG("%p %s (reason 0x%02x)", conn, addr, reason); - - UNSET_FLAG(is_connected); - disconnect_counter++; -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - -static void disconnect_device(struct bt_conn *conn, void *data) -{ - int err; - - SET_FLAG(is_connected); - - err = bt_conn_disconnect(conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN); - ASSERT(!err, "Failed to initate disconnect (err %d)", err); - - LOG_DBG("Waiting for disconnection..."); - WAIT_FOR_FLAG_UNSET(is_connected); -} - -#define BT_LE_ADV_CONN_NAME_OT BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE | \ - BT_LE_ADV_OPT_USE_NAME | \ - BT_LE_ADV_OPT_ONE_TIME, \ - BT_GAP_ADV_FAST_INT_MIN_2, \ - BT_GAP_ADV_FAST_INT_MAX_2, NULL) - -static const struct bt_data ad[] = { - BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), -}; - -static void test_peripheral_main(void) -{ - LOG_DBG("*L2CAP STRESS Peripheral started*"); - int err; - - /* Prepare tx_data */ - for (size_t i = 0; i < sizeof(tx_data); i++) { - tx_data[i] = (uint8_t)i; - } - - err = bt_enable(NULL); - if (err) { - FAIL("Can't enable Bluetooth (err %d)", err); - return; - } - - LOG_DBG("Peripheral Bluetooth initialized."); - LOG_DBG("Connectable advertising..."); - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME_OT, ad, ARRAY_SIZE(ad), NULL, 0); - if (err) { - FAIL("Advertising failed to start (err %d)", err); - return; - } - - LOG_DBG("Advertising started."); - LOG_DBG("Peripheral waiting for connection..."); - WAIT_FOR_FLAG_SET(is_connected); - LOG_DBG("Peripheral Connected."); - - int psm = l2cap_server_register(BT_SECURITY_L1); - - LOG_DBG("Registered server PSM %x", psm); - - LOG_DBG("Peripheral waiting for transfer completion"); - while (rx_cnt < SDU_NUM) { - k_msleep(100); - } - - bt_conn_foreach(BT_CONN_TYPE_LE, disconnect_device, NULL); - WAIT_FOR_FLAG_UNSET(is_connected); - LOG_INF("Total received: %d", rx_cnt); - PASS("L2CAP STRESS Peripheral passed\n"); -} - -static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, - struct net_buf_simple *ad) -{ - struct bt_le_conn_param *param; - struct bt_conn *conn; - int err; - - err = bt_le_scan_stop(); - if (err) { - FAIL("Stop LE scan failed (err %d)", err); - return; - } - - char str[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(addr, str, sizeof(str)); - - LOG_DBG("Connecting to %s", str); - - param = BT_LE_CONN_PARAM_DEFAULT; - err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, param, &conn); - if (err) { - FAIL("Create conn failed (err %d)", err); - return; - } -} - -static void connect_peripheral(void) -{ - struct bt_le_scan_param scan_param = { - .type = BT_LE_SCAN_TYPE_ACTIVE, - .options = BT_LE_SCAN_OPT_NONE, - .interval = BT_GAP_SCAN_FAST_INTERVAL, - .window = BT_GAP_SCAN_FAST_WINDOW, - }; - - UNSET_FLAG(is_connected); - - int err = bt_le_scan_start(&scan_param, device_found); - - ASSERT(!err, "Scanning failed to start (err %d)\n", err); - - LOG_DBG("Central initiating connection..."); - WAIT_FOR_FLAG_SET(is_connected); -} - -static void connect_l2cap_channel(struct bt_conn *conn, void *data) -{ - int err; - struct bt_l2cap_le_chan *le_chan = get_free_l2cap_le_chan(); - - ASSERT(le_chan, "No more available channels\n"); - - le_chan->chan.ops = &ops; - le_chan->rx.mtu = SDU_LEN; - le_chan->rx.init_credits = INIT_CREDITS; - le_chan->tx.init_credits = INIT_CREDITS; - - UNSET_FLAG(flag_l2cap_connected); - - err = bt_l2cap_chan_connect(conn, &le_chan->chan, 0x0080); - ASSERT(!err, "Error connecting l2cap channel (err %d)\n", err); - - WAIT_FOR_FLAG_SET(flag_l2cap_connected); -} - -static void test_central_main(void) -{ - LOG_DBG("*L2CAP STRESS Central started*"); - int err; - - /* Prepare tx_data */ - for (size_t i = 0; i < sizeof(tx_data); i++) { - tx_data[i] = (uint8_t)i; - } - - err = bt_enable(NULL); - ASSERT(err == 0, "Can't enable Bluetooth (err %d)\n", err); - LOG_DBG("Central Bluetooth initialized."); - - /* Connect all peripherals */ - for (int i = 0; i < NUM_PERIPHERALS; i++) { - connect_peripheral(); - } - - /* Connect L2CAP channels */ - LOG_DBG("Connect L2CAP channels"); - bt_conn_foreach(BT_CONN_TYPE_LE, connect_l2cap_channel, NULL); - - /* Send SDU_NUM SDUs to each peripheral */ - for (int i = 0; i < NUM_PERIPHERALS; i++) { - tx_left[i] = SDU_NUM; - l2cap_chan_send(l2cap_chans[i], tx_data, sizeof(tx_data)); - } - - LOG_DBG("Wait until all transfers are completed."); - int remaining_tx_total; - - do { - k_msleep(100); - - remaining_tx_total = 0; - for (int i = 0; i < L2CAP_CHANS; i++) { - remaining_tx_total += tx_left[i]; - } - } while (remaining_tx_total); - - LOG_DBG("Waiting until all peripherals are disconnected.."); - while (disconnect_counter < NUM_PERIPHERALS) { - k_msleep(100); - } - LOG_DBG("All peripherals disconnected."); - - LOG_DBG("Max segment pool usage: %u bufs", max_seg_allocated); - - PASS("L2CAP STRESS Central passed\n"); -} - -static const struct bst_test_instance test_def[] = { - { - .test_id = "peripheral", - .test_descr = "Peripheral L2CAP STRESS", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_peripheral_main - }, - { - .test_id = "central", - .test_descr = "Central L2CAP STRESS", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_central_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_main_l2cap_stress_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_def); -} - -extern struct bst_test_list *test_main_l2cap_stress_install(struct bst_test_list *tests); - -bst_test_install_t test_installers[] = { - test_main_l2cap_stress_install, - NULL -}; - -void main(void) -{ - bst_main(); -} diff --git a/tests/bluetooth/bsim/host/l2cap/stress/tests_scripts/l2cap.sh b/tests/bluetooth/bsim/host/l2cap/stress/tests_scripts/l2cap.sh deleted file mode 100755 index adb71fc3378..00000000000 --- a/tests/bluetooth/bsim/host/l2cap/stress/tests_scripts/l2cap.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env bash -# Copyright (c) 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -# EATT test -simulation_id="l2cap_stress" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - # timeout 30 $@ & process_ids="$process_ids $!" - $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -bsim_exe=./bs_${BOARD}_tests_bluetooth_bsim_host_l2cap_stress_prj_conf - -Execute "${bsim_exe}" -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central -rs=43 - -Execute "${bsim_exe}" -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral -rs=42 -Execute "${bsim_exe}" -v=${verbosity_level} -s=${simulation_id} -d=2 -testid=peripheral -rs=10 -Execute "${bsim_exe}" -v=${verbosity_level} -s=${simulation_id} -d=3 -testid=peripheral -rs=23 -Execute "${bsim_exe}" -v=${verbosity_level} -s=${simulation_id} -d=4 -testid=peripheral -rs=7884 -Execute "${bsim_exe}" -v=${verbosity_level} -s=${simulation_id} -d=5 -testid=peripheral -rs=230 -Execute "${bsim_exe}" -v=${verbosity_level} -s=${simulation_id} -d=6 -testid=peripheral -rs=9 - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} -D=7 -sim_length=270e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/l2cap/userdata/CMakeLists.txt b/tests/bluetooth/bsim/host/l2cap/userdata/CMakeLists.txt deleted file mode 100644 index 55aed6855d2..00000000000 --- a/tests/bluetooth/bsim/host/l2cap/userdata/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set\ - the environment variable BSIM_COMPONENTS_PATH to point to its components \ - folder. More information can be found in\ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_l2cap_userdata) - -FILE(GLOB app_sources src/*.c) -target_sources(app PRIVATE ${app_sources} ) - -zephyr_include_directories( - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ - ) diff --git a/tests/bluetooth/bsim/host/l2cap/userdata/prj.conf b/tests/bluetooth/bsim/host/l2cap/userdata/prj.conf deleted file mode 100644 index 6d418003174..00000000000 --- a/tests/bluetooth/bsim/host/l2cap/userdata/prj.conf +++ /dev/null @@ -1,10 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_SMP=y -CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y -CONFIG_BT_L2CAP_ECRED=y - -CONFIG_BT_BUF_ACL_RX_SIZE=75 - -CONFIG_ASSERT=y diff --git a/tests/bluetooth/bsim/host/l2cap/userdata/src/common.c b/tests/bluetooth/bsim/host/l2cap/userdata/src/common.c deleted file mode 100644 index f725ac6129c..00000000000 --- a/tests/bluetooth/bsim/host/l2cap/userdata/src/common.c +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "common.h" - -extern enum bst_result_t bst_result; - -void test_init(void) -{ - bst_result = In_progress; - bst_ticker_set_next_tick_absolute(WAIT_TIME); -} - -void test_tick(bs_time_t HW_device_time) -{ - if (bst_result != Passed) { - FAIL("test failed (not passed after %i us)\n", WAIT_TIME); - } -} diff --git a/tests/bluetooth/bsim/host/l2cap/userdata/src/common.h b/tests/bluetooth/bsim/host/l2cap/userdata/src/common.h deleted file mode 100644 index 3b0d09c53b6..00000000000 --- a/tests/bluetooth/bsim/host/l2cap/userdata/src/common.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Common functions and helpers for L2CAP tests - * - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include "bs_types.h" -#include "bs_tracing.h" -#include "bstests.h" - -#define CREATE_FLAG(flag) static atomic_t flag = (atomic_t)false -#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)true) -#define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)false) -#define WAIT_FOR_FLAG_SET(flag) \ - while (!(bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } -#define WAIT_FOR_FLAG_UNSET(flag) \ - while ((bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } - - -#define WAIT_TIME (30e6) /* 30 seconds*/ - -#define FAIL(...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, __VA_ARGS__); \ - } while (0) - - -void test_init(void); -void test_tick(bs_time_t HW_device_time); diff --git a/tests/bluetooth/bsim/host/l2cap/userdata/src/main.c b/tests/bluetooth/bsim/host/l2cap/userdata/src/main.c deleted file mode 100644 index fccfd9d2657..00000000000 --- a/tests/bluetooth/bsim/host/l2cap/userdata/src/main.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bstests.h" - -extern struct bst_test_list *test_main_l2cap_ecred_install(struct bst_test_list *tests); - -bst_test_install_t test_installers[] = { - test_main_l2cap_ecred_install, - NULL -}; - -void main(void) -{ - bst_main(); -} diff --git a/tests/bluetooth/bsim/host/l2cap/userdata/src/main_l2cap_userdata.c b/tests/bluetooth/bsim/host/l2cap/userdata/src/main_l2cap_userdata.c deleted file mode 100644 index 9230089dd95..00000000000 --- a/tests/bluetooth/bsim/host/l2cap/userdata/src/main_l2cap_userdata.c +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "common.h" - -#include -#include - -extern enum bst_result_t bst_result; - -static struct bt_conn *default_conn; - -#define PSM 0x80 - -CREATE_FLAG(is_connected); -CREATE_FLAG(chan_connected); - -static void chan_connected_cb(struct bt_l2cap_chan *l2cap_chan) -{ - (void)l2cap_chan; - - SET_FLAG(chan_connected); -} - -static void chan_disconnected_cb(struct bt_l2cap_chan *l2cap_chan) -{ - (void)l2cap_chan; - - UNSET_FLAG(chan_connected); -} - -static int chan_recv_cb(struct bt_l2cap_chan *chan, struct net_buf *buf) -{ - (void)chan; - (void)buf; - - return 0; -} - -static const struct bt_l2cap_chan_ops l2cap_ops = { - .connected = chan_connected_cb, - .disconnected = chan_disconnected_cb, - .recv = chan_recv_cb, -}; - -static struct bt_l2cap_le_chan channel; - -static int accept(struct bt_conn *conn, struct bt_l2cap_chan **l2cap_chan) -{ - channel.chan.ops = &l2cap_ops; - *l2cap_chan = &channel.chan; - - return 0; -} - -static struct bt_l2cap_server server = { - .accept = accept, - .sec_level = BT_SECURITY_L1, - .psm = PSM, -}; - -static void connect_l2cap_channel(void) -{ - struct bt_l2cap_chan *chans[] = {&channel.chan, NULL}; - int err; - - channel.chan.ops = &l2cap_ops; - - err = bt_l2cap_ecred_chan_connect(default_conn, chans, server.psm); - if (err) { - FAIL("Failed to send ecred connection request (err %d)\n", err); - } -} - -static void register_l2cap_server(void) -{ - int err; - - err = bt_l2cap_server_register(&server); - if (err < 0) { - FAIL("Failed to get free server (err %d)\n"); - return; - } -} - -static void connected(struct bt_conn *conn, uint8_t err) -{ - if (err) { - FAIL("Failed to connect (err %d)\n", err); - bt_conn_unref(default_conn); - default_conn = NULL; - return; - } - - default_conn = bt_conn_ref(conn); - - SET_FLAG(is_connected); -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - if (default_conn != conn) { - FAIL("Connection mismatch %p %p)\n", default_conn, conn); - return; - } - - bt_conn_unref(default_conn); - default_conn = NULL; - UNSET_FLAG(is_connected); -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - -static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, - struct net_buf_simple *ad) -{ - struct bt_le_conn_param *param; - int err; - - err = bt_le_scan_stop(); - if (err) { - FAIL("Failed to stop scanning (err %d)\n", err); - return; - } - - param = BT_LE_CONN_PARAM_DEFAULT; - err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, param, &default_conn); - if (err) { - FAIL("Failed to create connection (err %d)\n", err); - return; - } -} - -static void test_peripheral_main(void) -{ - int err; - const struct bt_data ad[] = { - BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), - }; - - err = bt_enable(NULL); - if (err != 0) { - FAIL("Bluetooth init failed (err %d)\n", err); - return; - } - - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0); - if (err != 0) { - FAIL("Advertising failed to start (err %d)\n", err); - return; - } - - WAIT_FOR_FLAG_SET(is_connected); - - register_l2cap_server(); - - WAIT_FOR_FLAG_UNSET(is_connected); - - PASS("Test passed\n"); -} - -#define FILL 0xAA -#define DATA_SIZE BT_L2CAP_BUF_SIZE(BT_L2CAP_SDU_RX_MTU) + 1 -#define USER_DATA_SIZE 10 - -/* Pool to allocate a buffer that is too large to send */ -NET_BUF_POOL_DEFINE(buf_pool, 1, DATA_SIZE, USER_DATA_SIZE, NULL); - -static void test_central_main(void) -{ - struct net_buf *buf; - int err; - - err = bt_enable(NULL); - if (err != 0) { - FAIL("Bluetooth discover failed (err %d)\n", err); - } - - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); - if (err != 0) { - FAIL("Scanning failed to start (err %d)\n", err); - } - - WAIT_FOR_FLAG_SET(is_connected); - - connect_l2cap_channel(); - WAIT_FOR_FLAG_SET(chan_connected); - - buf = net_buf_alloc(&buf_pool, K_NO_WAIT); - if (!buf) { - FAIL("Buffer allcation failed\n"); - } - - /* Don't care about the content of the packet itself, just the length */ - (void)net_buf_add(buf, DATA_SIZE); - /* Fill the user data with a pattern to more easily see any changes */ - (void)memset(buf->user_data, FILL, buf->user_data_size); - - /* Try to send a buffer larger than the MTU */ - err = bt_l2cap_chan_send(&channel.chan, buf); - if (err != -EMSGSIZE) { - FAIL("Expected error code -EMSGSIZE, got %d\n", err); - } - - printk("Buffer user data (Expecting all bytes to be " STRINGIFY(FILL) "): "); - for (int i = 0; i < USER_DATA_SIZE; i++) { - printk("%02X", buf->user_data[i]); - } - - printk("\n"); - - /* Validate that the user data is unchanged */ - for (int i = 0; i < USER_DATA_SIZE; i++) { - if (buf->user_data[i] != FILL) { - FAIL("Buffer user data should not change.\n"); - } - } - - err = bt_conn_disconnect(default_conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN); - if (err) { - FAIL("Failed to disconnect (err %d)\n", err); - return; - } - - WAIT_FOR_FLAG_UNSET(is_connected); - - PASS("Test passed\n"); -} - -static const struct bst_test_instance test_def[] = { - { - .test_id = "peripheral", - .test_descr = "Peripheral", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_peripheral_main, - }, - { - .test_id = "central", - .test_descr = "Central", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_central_main, - }, - BSTEST_END_MARKER, -}; - -struct bst_test_list *test_main_l2cap_ecred_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_def); -} diff --git a/tests/bluetooth/bsim/host/l2cap/userdata/tests_scripts/l2cap.sh b/tests/bluetooth/bsim/host/l2cap/userdata/tests_scripts/l2cap.sh deleted file mode 100755 index 45a84515151..00000000000 --- a/tests/bluetooth/bsim/host/l2cap/userdata/tests_scripts/l2cap.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env bash -# Copyright (c) 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -simulation_id="l2cap_ecred_userdata" -verbosity_level=2 -process_ids="" -exit_code=0 - -function Execute() { - if [ ! -f $1 ]; then - echo -e " \e[91m$(pwd)/$(basename $1) cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 120 $@ & - process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_l2cap_userdata_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_l2cap_userdata_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=30e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/misc/disable/CMakeLists.txt b/tests/bluetooth/bsim/host/misc/disable/CMakeLists.txt deleted file mode 100644 index 1e44488a8f7..00000000000 --- a/tests/bluetooth/bsim/host/misc/disable/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set\ - the environment variable BSIM_COMPONENTS_PATH to point to its components \ - folder. More information can be found in\ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_disable) - -FILE(GLOB app_sources src/*.c) -target_sources(app PRIVATE ${app_sources} ) - -zephyr_include_directories( - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ - ) diff --git a/tests/bluetooth/bsim/host/misc/disable/prj.conf b/tests/bluetooth/bsim/host/misc/disable/prj.conf deleted file mode 100644 index 7bf1c2b09e8..00000000000 --- a/tests/bluetooth/bsim/host/misc/disable/prj.conf +++ /dev/null @@ -1,6 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_DEVICE_NAME="GATT tester" -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_GATT_CLIENT=y -CONFIG_BT_ATT_PREPARE_COUNT=3 diff --git a/tests/bluetooth/bsim/host/misc/disable/src/common.c b/tests/bluetooth/bsim/host/misc/disable/src/common.c deleted file mode 100644 index df438607c5f..00000000000 --- a/tests/bluetooth/bsim/host/misc/disable/src/common.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "common.h" - -void test_tick(bs_time_t HW_device_time) -{ - if (bst_result != Passed) { - FAIL("test failed (not passed after %i seconds)\n", WAIT_TIME); - } -} - -void test_init(void) -{ - bst_ticker_set_next_tick_absolute(WAIT_TIME); - bst_result = In_progress; -} diff --git a/tests/bluetooth/bsim/host/misc/disable/src/common.h b/tests/bluetooth/bsim/host/misc/disable/src/common.h deleted file mode 100644 index cb93d7ff71a..00000000000 --- a/tests/bluetooth/bsim/host/misc/disable/src/common.h +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Common functions and helpers for BSIM disable with GATT tests - * - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include "bs_types.h" -#include "bs_tracing.h" -#include "time_machine.h" -#include "bstests.h" - -#include -#include -#include - -#include -#include -#include -#include -#include - -extern enum bst_result_t bst_result; - -#define WAIT_TIME (600 * 1e6) /*seconds*/ - -#define CREATE_FLAG(flag) static atomic_t flag = (atomic_t)false -#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)true) -#define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)false) -#define WAIT_FOR_FLAG(flag) \ - while (!(bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } -#define WAIT_FOR_FLAG_UNSET(flag) \ - while ((bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } - -#define FAIL(...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, __VA_ARGS__); \ - } while (0) - -#define CHRC_SIZE 10 -#define LONG_CHRC_SIZE 40 - -#define TEST_SERVICE_UUID \ - BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, \ - 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x00, 0x00) - -#define TEST_CHRC_UUID \ - BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, \ - 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xFF, 0x00) - -#define TEST_LONG_CHRC_UUID \ - BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, \ - 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xFF, 0x11) - -void test_tick(bs_time_t HW_device_time); -void test_init(void); diff --git a/tests/bluetooth/bsim/host/misc/disable/src/gatt_client_test.c b/tests/bluetooth/bsim/host/misc/disable/src/gatt_client_test.c deleted file mode 100644 index 91302380ef7..00000000000 --- a/tests/bluetooth/bsim/host/misc/disable/src/gatt_client_test.c +++ /dev/null @@ -1,324 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -#include "common.h" - -CREATE_FLAG(flag_is_connected); -CREATE_FLAG(flag_discover_complete); -CREATE_FLAG(flag_write_complete); -CREATE_FLAG(flag_read_complete); - -static struct bt_conn *g_conn; -static uint16_t chrc_handle; -static uint16_t long_chrc_handle; -static struct bt_uuid *test_svc_uuid = TEST_SERVICE_UUID; - -#define NUM_ITERATIONS 10 - -#define ARRAY_ITEM(i, _) i -static uint8_t chrc_data[] = { LISTIFY(CHRC_SIZE, ARRAY_ITEM, (,)) }; /* 1, 2, 3 ... */ -static uint8_t long_chrc_data[] = { LISTIFY(LONG_CHRC_SIZE, ARRAY_ITEM, (,)) }; /* 1, 2, 3 ... */ - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - - g_conn = conn; - SET_FLAG(flag_is_connected); -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - if (conn != g_conn) { - return; - } - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - printk("Disconnected: %s (reason 0x%02x)\n", addr, reason); - - bt_conn_unref(g_conn); - - g_conn = NULL; - UNSET_FLAG(flag_is_connected); -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - -void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, - struct net_buf_simple *ad) -{ - char addr_str[BT_ADDR_LE_STR_LEN]; - int err; - - if (g_conn != NULL) { - return; - } - - /* We're only interested in connectable events */ - if (type != BT_HCI_ADV_IND && type != BT_HCI_ADV_DIRECT_IND) { - return; - } - - bt_addr_le_to_str(addr, addr_str, sizeof(addr_str)); - printk("Device found: %s (RSSI %d)\n", addr_str, rssi); - - printk("Stopping scan\n"); - err = bt_le_scan_stop(); - if (err != 0) { - FAIL("Could not stop scan: %d"); - return; - } - - err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, - BT_LE_CONN_PARAM_DEFAULT, &g_conn); - if (err != 0) { - FAIL("Could not connect to peer: %d", err); - } -} - -static uint8_t discover_func(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - struct bt_gatt_discover_params *params) -{ - int err; - - if (attr == NULL) { - if (chrc_handle == 0 || long_chrc_handle == 0) { - FAIL("Did not discover chrc (%x) or long_chrc (%x)", - chrc_handle, long_chrc_handle); - } - - (void)memset(params, 0, sizeof(*params)); - - SET_FLAG(flag_discover_complete); - - return BT_GATT_ITER_STOP; - } - - printk("[ATTRIBUTE] handle %u\n", attr->handle); - - if (params->type == BT_GATT_DISCOVER_PRIMARY && - bt_uuid_cmp(params->uuid, TEST_SERVICE_UUID) == 0) { - printk("Found test service\n"); - params->uuid = NULL; - params->start_handle = attr->handle + 1; - params->type = BT_GATT_DISCOVER_CHARACTERISTIC; - - err = bt_gatt_discover(conn, params); - if (err != 0) { - FAIL("Discover failed (err %d)\n", err); - } - - return BT_GATT_ITER_STOP; - } else if (params->type == BT_GATT_DISCOVER_CHARACTERISTIC) { - struct bt_gatt_chrc *chrc = (struct bt_gatt_chrc *)attr->user_data; - - if (bt_uuid_cmp(chrc->uuid, TEST_CHRC_UUID) == 0) { - printk("Found chrc\n"); - chrc_handle = chrc->value_handle; - } else if (bt_uuid_cmp(chrc->uuid, TEST_LONG_CHRC_UUID) == 0) { - printk("Found long_chrc\n"); - long_chrc_handle = chrc->value_handle; - } - } - - return BT_GATT_ITER_CONTINUE; -} - -static void gatt_discover(void) -{ - static struct bt_gatt_discover_params discover_params; - int err; - - printk("Discovering services and characteristics\n"); - - discover_params.uuid = test_svc_uuid; - discover_params.func = discover_func; - discover_params.start_handle = BT_ATT_FIRST_ATTRIBUTE_HANDLE; - discover_params.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE; - discover_params.type = BT_GATT_DISCOVER_PRIMARY; - - err = bt_gatt_discover(g_conn, &discover_params); - if (err != 0) { - FAIL("Discover failed(err %d)\n", err); - } - - WAIT_FOR_FLAG(flag_discover_complete); - printk("Discover complete\n"); -} - -static void gatt_write_cb(struct bt_conn *conn, uint8_t err, - struct bt_gatt_write_params *params) -{ - if (err != BT_ATT_ERR_SUCCESS) { - FAIL("Write failed: 0x%02X\n", err); - } - - (void)memset(params, 0, sizeof(*params)); - - SET_FLAG(flag_write_complete); -} - -static void gatt_write(uint16_t handle) -{ - static struct bt_gatt_write_params write_params; - int err; - - if (handle == chrc_handle) { - printk("Writing to chrc\n"); - write_params.data = chrc_data; - write_params.length = sizeof(chrc_data); - } else if (handle) { - printk("Writing to long_chrc\n"); - write_params.data = long_chrc_data; - write_params.length = sizeof(long_chrc_data); - } - - write_params.func = gatt_write_cb; - write_params.handle = handle; - - UNSET_FLAG(flag_write_complete); - - err = bt_gatt_write(g_conn, &write_params); - if (err != 0) { - FAIL("bt_gatt_write failed: %d\n", err); - } - - WAIT_FOR_FLAG(flag_write_complete); - printk("success\n"); -} - -static uint8_t gatt_read_cb(struct bt_conn *conn, uint8_t err, - struct bt_gatt_read_params *params, - const void *data, uint16_t length) -{ - if (err != BT_ATT_ERR_SUCCESS) { - FAIL("Read failed: 0x%02X\n", err); - } - - if (params->single.handle == chrc_handle) { - if (length != CHRC_SIZE || - memcmp(data, chrc_data, length) != 0) { - FAIL("chrc data different than expected", err); - } - } else if (params->single.handle == chrc_handle) { - if (length != LONG_CHRC_SIZE || - memcmp(data, long_chrc_data, length) != 0) { - FAIL("long_chrc data different than expected", err); - } - } - - (void)memset(params, 0, sizeof(*params)); - - SET_FLAG(flag_read_complete); - - return 0; -} - -static void gatt_read(uint16_t handle) -{ - static struct bt_gatt_read_params read_params; - int err; - - printk("Reading chrc\n"); - - read_params.func = gatt_read_cb; - read_params.handle_count = 1; - read_params.single.handle = chrc_handle; - read_params.single.offset = 0; - - UNSET_FLAG(flag_read_complete); - - err = bt_gatt_read(g_conn, &read_params); - if (err != 0) { - FAIL("bt_gatt_read failed: %d\n", err); - } - - WAIT_FOR_FLAG(flag_read_complete); - printk("success\n"); -} - -static void test_main(void) -{ - int err; - - for (int i = 0; i < NUM_ITERATIONS; i++) { - - err = bt_enable(NULL); - if (err != 0) { - FAIL("Bluetooth discover failed (err %d)\n", err); - } - printk("Bluetooth initialized\n"); - - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); - if (err != 0) { - FAIL("Scanning failed to start (err %d)\n", err); - } - - printk("Scanning successfully started\n"); - - WAIT_FOR_FLAG(flag_is_connected); - - gatt_discover(); - - /* Write and read a few times to ensure stateless behavior */ - for (size_t i = 0; i < 3; i++) { - gatt_write(chrc_handle); - gatt_read(chrc_handle); - gatt_write(long_chrc_handle); - gatt_read(long_chrc_handle); - } - - err = bt_conn_disconnect(g_conn, 0x13); - if (err != 0) { - FAIL("Disconnect failed (err %d)\n", err); - return; - } - - WAIT_FOR_FLAG_UNSET(flag_is_connected); - - err = bt_disable(); - if (err != 0) { - FAIL("Bluetooth disable failed (err %d)\n", err); - } - printk("Bluetooth successfully disabled\n"); - } - - PASS("GATT client Passed\n"); -} - -static const struct bst_test_instance test_vcs[] = { - { - .test_id = "gatt_client", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_gatt_client_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_vcs); -} diff --git a/tests/bluetooth/bsim/host/misc/disable/src/gatt_server_test.c b/tests/bluetooth/bsim/host/misc/disable/src/gatt_server_test.c deleted file mode 100644 index 56c8a26a7ce..00000000000 --- a/tests/bluetooth/bsim/host/misc/disable/src/gatt_server_test.c +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "common.h" - -extern enum bst_result_t bst_result; - -CREATE_FLAG(flag_is_connected); - -static struct bt_conn *g_conn; - -#define NUM_ITERATIONS 10 - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err != 0) { - FAIL("Failed to connect to %s (%u)\n", addr, err); - return; - } - - printk("Connected to %s\n", addr); - - g_conn = bt_conn_ref(conn); - SET_FLAG(flag_is_connected); -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - if (conn != g_conn) { - return; - } - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - printk("Disconnected: %s (reason 0x%02x)\n", addr, reason); - - bt_conn_unref(g_conn); - - g_conn = NULL; - UNSET_FLAG(flag_is_connected); -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - -static uint8_t chrc_data[CHRC_SIZE]; -static uint8_t long_chrc_data[LONG_CHRC_SIZE]; - -static ssize_t read_test_chrc(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) -{ - return bt_gatt_attr_read(conn, attr, buf, len, offset, - (void *)chrc_data, sizeof(chrc_data)); -} - -static ssize_t write_test_chrc(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, - uint16_t offset, uint8_t flags) -{ - printk("chrc len %u offset %u\n", len, offset); - - if (len > sizeof(chrc_data)) { - printk("Invalid chrc length\n"); - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - } else if (offset + len > sizeof(chrc_data)) { - printk("Invalid chrc offset and length\n"); - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - } - - if (flags != 0) { - FAIL("Invalid flags %u\n", flags); - return BT_GATT_ERR(BT_ATT_ERR_UNLIKELY); - } - - (void)memcpy(chrc_data + offset, buf, len); - - return len; -} - -static ssize_t read_long_test_chrc(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) -{ - return bt_gatt_attr_read(conn, attr, buf, len, offset, - (void *)long_chrc_data, sizeof(long_chrc_data)); -} - -static ssize_t write_long_test_chrc(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, - uint16_t offset, uint8_t flags) -{ - static uint8_t prepare_count; - - printk("long_chrc len %u offset %u\n", len, offset); - - if (len > sizeof(long_chrc_data)) { - printk("Invalid long_chrc length\n"); - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - } else if (offset + len > sizeof(long_chrc_data)) { - printk("Invalid long_chrc offset and length\n"); - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - } - - if (flags & BT_GATT_WRITE_FLAG_PREPARE) { - printk("prepare_count %u\n", prepare_count++); - return BT_GATT_ERR(BT_ATT_ERR_SUCCESS); - } - - (void)memcpy(long_chrc_data + offset, buf, len); - prepare_count = 0; - - return len; -} - -BT_GATT_SERVICE_DEFINE(test_svc, - BT_GATT_PRIMARY_SERVICE(TEST_SERVICE_UUID), - BT_GATT_CHARACTERISTIC(TEST_CHRC_UUID, - BT_GATT_CHRC_WRITE | BT_GATT_CHRC_READ, - BT_GATT_PERM_WRITE | BT_GATT_PERM_READ, - read_test_chrc, write_test_chrc, NULL), - BT_GATT_CHARACTERISTIC(TEST_LONG_CHRC_UUID, - BT_GATT_CHRC_WRITE | BT_GATT_CHRC_READ, - BT_GATT_PERM_WRITE | BT_GATT_PERM_READ | BT_GATT_PERM_PREPARE_WRITE, - read_long_test_chrc, write_long_test_chrc, NULL), -); - -static void test_main(void) -{ - int err; - const struct bt_data ad[] = { - BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)) - }; - - for (int i = 0; i < NUM_ITERATIONS; i++) { - err = bt_enable(NULL); - if (err != 0) { - FAIL("Bluetooth init failed (err %d)\n", err); - return; - } - - printk("Bluetooth initialized\n"); - - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0); - if (err != 0) { - FAIL("Advertising failed to start (err %d)\n", err); - return; - } - - printk("Advertising successfully started\n"); - - WAIT_FOR_FLAG(flag_is_connected); - - WAIT_FOR_FLAG_UNSET(flag_is_connected); - - err = bt_disable(); - if (err != 0) { - FAIL("Bluetooth disable failed (err %d)\n", err); - return; - } - - printk("Bluetooth disabled\n"); - } - - PASS("GATT server passed\n"); -} - -static const struct bst_test_instance test_gatt_server[] = { - { - .test_id = "gatt_server", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_gatt_server_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_gatt_server); -} diff --git a/tests/bluetooth/bsim/host/misc/disable/src/main.c b/tests/bluetooth/bsim/host/misc/disable/src/main.c deleted file mode 100644 index dcb4c12afe4..00000000000 --- a/tests/bluetooth/bsim/host/misc/disable/src/main.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bstests.h" - -extern struct bst_test_list *test_main_disable_install(struct bst_test_list *tests); -extern struct bst_test_list *test_gatt_server_install(struct bst_test_list *tests); -extern struct bst_test_list *test_gatt_client_install(struct bst_test_list *tests); - -bst_test_install_t test_installers[] = { - test_main_disable_install, - test_gatt_server_install, - test_gatt_client_install, - NULL -}; - -void main(void) -{ - bst_main(); -} diff --git a/tests/bluetooth/bsim/host/misc/disable/src/main_disable.c b/tests/bluetooth/bsim/host/misc/disable/src/main_disable.c deleted file mode 100644 index d4a6f6d904a..00000000000 --- a/tests/bluetooth/bsim/host/misc/disable/src/main_disable.c +++ /dev/null @@ -1,52 +0,0 @@ -/* main_disable.c - Application main entry point */ - -/* - * Copyright (c) 2022 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#define LOG_MODULE_NAME main_disable -#include -LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL_DBG); - -#include "common.h" - -extern enum bst_result_t bst_result; - -#define NUM_ITERATIONS 35 - -static void test_disable_main(void) -{ - for (int i = 0; i < NUM_ITERATIONS; i++) { - int err; - - err = bt_enable(NULL); - if (err != 0) { - FAIL("Enable failed (err %d)\n", err); - } - - err = bt_disable(); - if (err) { - FAIL("Enable failed (err %d)\n", err); - } - } - - PASS("Disable test passed\n"); -} - -static const struct bst_test_instance test_def[] = { - { - .test_id = "disable", - .test_descr = "disable_test", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = test_disable_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_main_disable_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_def); -} diff --git a/tests/bluetooth/bsim/host/misc/disable/tests_scripts/disable.sh b/tests/bluetooth/bsim/host/misc/disable/tests_scripts/disable.sh deleted file mode 100755 index 9ee0539fd26..00000000000 --- a/tests/bluetooth/bsim/host/misc/disable/tests_scripts/disable.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash -# Copyright (c) 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -# Disable test: bt_enable and bt_disable are called in a loop. -simulation_id="disable_test" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 120 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_misc_disable_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=disable - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=1 -sim_length=60e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/misc/disable/tests_scripts/disable_with_gatt.sh b/tests/bluetooth/bsim/host/misc/disable/tests_scripts/disable_with_gatt.sh deleted file mode 100755 index 847718012a6..00000000000 --- a/tests/bluetooth/bsim/host/misc/disable/tests_scripts/disable_with_gatt.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -# Disable with GATT test: A central acting as a GATT client scans for and connects -# to a peripheral acting as a GATT server. The GATT client will then attempt -# to write and read to and from a few GATT characteristics. Both the central and -# peripheral then disable bluetooth and the test repeats. -simulation_id="disable_with_gatt" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 120 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_misc_disable_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=gatt_client - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_misc_disable_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=gatt_server - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=600e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/misc/multiple_id/CMakeLists.txt b/tests/bluetooth/bsim/host/misc/multiple_id/CMakeLists.txt deleted file mode 100644 index 5d10630272c..00000000000 --- a/tests/bluetooth/bsim/host/misc/multiple_id/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set \ - the environment variable BSIM_COMPONENTS_PATH to point to its \ - components folder. More information can be found in \ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_multiple) - -target_sources(app PRIVATE - src/main.c - ${ZEPHYR_BASE}/samples/bluetooth/central_multilink/src/central_multilink.c - ${ZEPHYR_BASE}/samples/bluetooth/peripheral_identity/src/peripheral_identity.c -) - -zephyr_include_directories( - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ -) diff --git a/tests/bluetooth/bsim/host/misc/multiple_id/prj.conf b/tests/bluetooth/bsim/host/misc/multiple_id/prj.conf deleted file mode 100644 index 0fb600d717c..00000000000 --- a/tests/bluetooth/bsim/host/misc/multiple_id/prj.conf +++ /dev/null @@ -1,51 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_PRIVACY=y - -CONFIG_BT_DEVICE_NAME="Multiple" - -CONFIG_BT_USER_PHY_UPDATE=y -CONFIG_BT_AUTO_PHY_UPDATE=y -CONFIG_BT_USER_DATA_LEN_UPDATE=y -CONFIG_BT_AUTO_DATA_LEN_UPDATE=y - -CONFIG_BT_MAX_CONN=250 -CONFIG_BT_ID_MAX=250 - -# L2CAP, ATT and SMP usage cause data transmission deadlock due to shortage -# of buffers when transactions crossover amongst the connections in the same -# device. Hence, keeping them disabled in this test until future investigations. - -CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n - -# CONFIG_BT_GATT_CLIENT=y - -# CONFIG_BT_SMP=y -# CONFIG_BT_MAX_PAIRED=250 - -CONFIG_BT_BUF_CMD_TX_SIZE=255 -CONFIG_BT_BUF_EVT_RX_SIZE=255 -CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE=255 -CONFIG_BT_BUF_ACL_TX_SIZE=251 -CONFIG_BT_BUF_ACL_RX_SIZE=251 - -CONFIG_BT_CTLR_DATA_LENGTH_MAX=251 - -# Each PHY update can pause connections for 6 interval hence to let other -# parallel connection establishment to succeed increase Rx buffer count. -CONFIG_BT_CTLR_RX_BUFFERS=6 - -# Provide enough spacing between connections so that multiple peripheral roles -# when connected to a single peer device (peripheral_identity sample) have -# room for window widening and do not overlap with each other in that single -# peer device. This can be tuned based on connection interval and clock -# accuracy, current value here is sufficient for 500ppm at 1 second interval and -# considering required connection event length for 251 byte PDU on 2M PHY. -# (Event Overhead + Radio Ready Delay + Rx window + 1064 + 154 + 1064) -CONFIG_BT_CTLR_ADVANCED_FEATURES=y -CONFIG_BT_CTLR_CENTRAL_SPACING=3750 - -# Do not use max data PDU size time reservation for connection events spacing -# instead use lesser value as supplied in CONFIG_BT_CTLR_CENTRAL_SPACING -CONFIG_BT_CTLR_CENTRAL_RESERVE_MAX=n diff --git a/tests/bluetooth/bsim/host/misc/multiple_id/src/main.c b/tests/bluetooth/bsim/host/misc/multiple_id/src/main.c deleted file mode 100644 index 96ae150d1d3..00000000000 --- a/tests/bluetooth/bsim/host/misc/multiple_id/src/main.c +++ /dev/null @@ -1,125 +0,0 @@ -/* main.c - Application main entry point */ - -/* - * Copyright (c) 2015-2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include - -#include -#include - -#include "bs_types.h" -#include "bs_tracing.h" -#include "time_machine.h" -#include "bstests.h" - -#define ITERATIONS 10 - -int init_central(uint8_t iterations); -int init_peripheral(uint8_t iterations); - -#define FAIL(...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, __VA_ARGS__); \ - } while (0) - -extern enum bst_result_t bst_result; - -static void test_central_main(void) -{ - int err; - - err = init_central(ITERATIONS); - if (err) { - goto exit; - } - - /* Wait a little so that peripheral side completes the last - * connection establishment. - */ - k_sleep(K_SECONDS(1)); - - PASS("Central tests passed\n"); - bs_trace_silent_exit(0); - - return; - -exit: - FAIL("Central tests failed (%d)\n", err); - bs_trace_silent_exit(0); -} - -static void test_peripheral_main(void) -{ - int err; - - err = init_peripheral(ITERATIONS); - if (err) { - goto exit; - } - - PASS("Peripheral tests passed\n"); - - return; - -exit: - FAIL("Peripheral tests failed (%d)\n", err); - bs_trace_silent_exit(0); -} - -static void test_multiple_init(void) -{ - bst_ticker_set_next_tick_absolute(4500e6); - bst_result = In_progress; -} - -static void test_multiple_tick(bs_time_t HW_device_time) -{ - bst_result = Failed; - bs_trace_error_line("Test multiple finished.\n"); -} - -static const struct bst_test_instance test_def[] = { - { - .test_id = "central", - .test_descr = "Central Multilink", - .test_post_init_f = test_multiple_init, - .test_tick_f = test_multiple_tick, - .test_main_f = test_central_main - }, - { - .test_id = "peripheral", - .test_descr = "Peripheral multiple identity", - .test_post_init_f = test_multiple_init, - .test_tick_f = test_multiple_tick, - .test_main_f = test_peripheral_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_multiple_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_def); -} - -bst_test_install_t test_installers[] = { - test_multiple_install, - NULL -}; - -void main(void) -{ - bst_main(); -} diff --git a/tests/bluetooth/bsim/host/misc/multiple_id/tests_scripts/multiple.sh b/tests/bluetooth/bsim/host/misc/multiple_id/tests_scripts/multiple.sh deleted file mode 100755 index 37c6d382593..00000000000 --- a/tests/bluetooth/bsim/host/misc/multiple_id/tests_scripts/multiple.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2018 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -# Multiple connection between two devices with multiple peripheral identity -simulation_id="multiple" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 1800 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_misc_multiple_id_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_host_misc_multiple_id_prj_conf\ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=4500e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/privacy/central/CMakeLists.txt b/tests/bluetooth/bsim/host/privacy/central/CMakeLists.txt deleted file mode 100644 index 3de7a52a564..00000000000 --- a/tests/bluetooth/bsim/host/privacy/central/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set\ - the environment variable BSIM_COMPONENTS_PATH to point to its components \ - folder. More information can be found in\ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_rpa_central) - -target_sources(app PRIVATE - src/bs_bt_utils.c - src/tester.c - src/main.c - src/dut.c -) - -zephyr_include_directories( - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ - ) diff --git a/tests/bluetooth/bsim/host/privacy/central/prj.conf b/tests/bluetooth/bsim/host/privacy/central/prj.conf deleted file mode 100644 index e3fa9de43d7..00000000000 --- a/tests/bluetooth/bsim/host/privacy/central/prj.conf +++ /dev/null @@ -1,13 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_SMP=y -CONFIG_ASSERT=y - -CONFIG_BT_EXT_ADV=y -CONFIG_BT_PRIVACY=y -CONFIG_BT_RPA_TIMEOUT=10 - -CONFIG_BT_CTLR_ADV_SET=2 -CONFIG_BT_CTLR_SCAN_REQ_NOTIFY=y -CONFIG_BT_SCAN_WITH_IDENTITY=y diff --git a/tests/bluetooth/bsim/host/privacy/central/src/bs_bt_utils.c b/tests/bluetooth/bsim/host/privacy/central/src/bs_bt_utils.c deleted file mode 100644 index 6011b5d300c..00000000000 --- a/tests/bluetooth/bsim/host/privacy/central/src/bs_bt_utils.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bs_bt_utils.h" -#include "bs_pc_backchannel.h" -#include "argparse.h" - -#define BS_SECONDS(dur_sec) ((bs_time_t)dur_sec * 1000000) -#define TEST_TIMEOUT_SIMULATED BS_SECONDS(60) -#define CHANNEL_ID 0 -#define MSG_SIZE 1 - -void test_tick(bs_time_t HW_device_time) -{ - bs_trace_debug_time(0, "Simulation ends now.\n"); - if (bst_result != Passed) { - bst_result = Failed; - bs_trace_error("Test did not pass before simulation ended.\n"); - } -} - -void test_init(void) -{ - bst_ticker_set_next_tick_absolute(TEST_TIMEOUT_SIMULATED); - bst_result = In_progress; -} - -void backchannel_init(uint peer) -{ - uint device_number = get_device_nbr(); - uint device_numbers[] = {peer}; - uint channel_numbers[] = {CHANNEL_ID}; - uint *ch; - - ch = bs_open_back_channel(device_number, device_numbers, channel_numbers, - ARRAY_SIZE(channel_numbers)); - if (!ch) { - FAIL("Unable to open backchannel\n"); - } -} - -void backchannel_sync_send(void) -{ - uint8_t sync_msg[MSG_SIZE] = {get_device_nbr()}; - - bs_bc_send_msg(CHANNEL_ID, sync_msg, ARRAY_SIZE(sync_msg)); -} - -void backchannel_sync_wait(void) -{ - uint8_t sync_msg[MSG_SIZE]; - - while (true) { - if (bs_bc_is_msg_received(CHANNEL_ID) > 0) { - bs_bc_receive_msg(CHANNEL_ID, sync_msg, ARRAY_SIZE(sync_msg)); - if (sync_msg[0] != get_device_nbr()) { - /* Received a message from another device, exit */ - break; - } - } - - k_sleep(K_MSEC(1)); - } -} - -void print_address(bt_addr_le_t *addr) -{ - char array[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(addr, array, sizeof(array)); - printk("Address : %s\n", array); -} diff --git a/tests/bluetooth/bsim/host/privacy/central/src/bs_bt_utils.h b/tests/bluetooth/bsim/host/privacy/central/src/bs_bt_utils.h deleted file mode 100644 index 84fd44993bc..00000000000 --- a/tests/bluetooth/bsim/host/privacy/central/src/bs_bt_utils.h +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Common functions and helpers for BSIM ADV tests - * - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bs_tracing.h" -#include "bs_types.h" -#include "bstests.h" -#include "time_machine.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -extern enum bst_result_t bst_result; - -#define DECLARE_FLAG(flag) extern atomic_t flag -#define DEFINE_FLAG(flag) atomic_t flag = (atomic_t) false -#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) true) -#define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) false) -#define WAIT_FOR_FLAG(flag) \ - while (!(bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } -#define WAIT_FOR_FLAG_UNSET(flag) \ - while ((bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } -#define TAKE_FLAG(flag) \ - while (!(bool)atomic_cas(&flag, true, false)) { \ - (void)k_sleep(K_MSEC(1)); \ - } - -#define ASSERT(expr, ...) \ - do { \ - if (!(expr)) { \ - FAIL(__VA_ARGS__); \ - } \ - } while (0) - -#define FAIL(...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, __VA_ARGS__); \ - } while (0) - -#define DUT_CENTRAL_ID 0 -#define TESTER_PERIPHERAL_ID 1 - -void test_tick(bs_time_t HW_device_time); -void test_init(void); -void backchannel_init(uint peer); -void backchannel_sync_send(void); -void backchannel_sync_wait(void); - -void print_address(bt_addr_le_t *addr); diff --git a/tests/bluetooth/bsim/host/privacy/central/src/dut.c b/tests/bluetooth/bsim/host/privacy/central/src/dut.c deleted file mode 100644 index e80b9bc8f93..00000000000 --- a/tests/bluetooth/bsim/host/privacy/central/src/dut.c +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bs_bt_utils.h" - -#include - -#include -#include -#include - -void start_scanning(void) -{ - int err; - struct bt_le_scan_param param; - - /* Enable bluetooth */ - err = bt_enable(NULL); - if (err) { - FAIL("Failed to enable bluetooth (err %d\n)", err); - } - - /* Start active scanning */ - param.type = BT_LE_SCAN_TYPE_ACTIVE; - param.options = BT_LE_SCAN_OPT_FILTER_DUPLICATE; - param.interval = BT_GAP_SCAN_FAST_INTERVAL; - param.window = BT_GAP_SCAN_FAST_WINDOW; - param.timeout = 0; - param.interval_coded = 0; - param.window_coded = 0; - - err = bt_le_scan_start(¶m, NULL); - if (err) { - FAIL("Failed to start scanning"); - } -} - -void dut_procedure(void) -{ - start_scanning(); - - /* Nothing to do */ - - PASS("PASS\n"); -} diff --git a/tests/bluetooth/bsim/host/privacy/central/src/main.c b/tests/bluetooth/bsim/host/privacy/central/src/main.c deleted file mode 100644 index 51fb3c40085..00000000000 --- a/tests/bluetooth/bsim/host/privacy/central/src/main.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bs_bt_utils.h" -#include "bstests.h" - -void tester_procedure(void); -void dut_procedure(void); - -static const struct bst_test_instance test_to_add[] = { - { - .test_id = "central", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = dut_procedure, - }, - { - .test_id = "peripheral", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = tester_procedure, - }, - BSTEST_END_MARKER, -}; - -static struct bst_test_list *install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_to_add); -}; - -bst_test_install_t test_installers[] = {install, NULL}; - -void main(void) -{ - bst_main(); -} diff --git a/tests/bluetooth/bsim/host/privacy/central/src/tester.c b/tests/bluetooth/bsim/host/privacy/central/src/tester.c deleted file mode 100644 index d511202c450..00000000000 --- a/tests/bluetooth/bsim/host/privacy/central/src/tester.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bs_bt_utils.h" - -#include -#include - -#include -#include -#include -#include - -DEFINE_FLAG(flag_new_address); - -void scanned_cb(struct bt_le_ext_adv *adv, struct bt_le_ext_adv_scanned_info *info) -{ - static bool init; - static int64_t old_time; - static bt_addr_le_t old_addr; - bt_addr_le_t new_addr; - - if (bst_result == Passed) { - return; - } - - if (!init) { - old_addr = *info->addr; - old_time = k_uptime_get(); - init = true; - } - - new_addr = *info->addr; - - /* Check if the scan request comes from a new address */ - if (bt_addr_le_cmp(&old_addr, &new_addr)) { - int64_t new_time, diff, time_diff_ms, rpa_timeout_ms; - - printk("Scanned request from new "); - print_address(info->addr); - - /* Ensure the RPA rotation occurs within +-10% of CONFIG_BT_RPA_TIMEOUT */ - new_time = k_uptime_get(); - time_diff_ms = new_time - old_time; - rpa_timeout_ms = CONFIG_BT_RPA_TIMEOUT * MSEC_PER_SEC; - - if (time_diff_ms > rpa_timeout_ms) { - diff = time_diff_ms - rpa_timeout_ms; - } else { - diff = rpa_timeout_ms - time_diff_ms; - } - - if (diff > rpa_timeout_ms * 0.10) { - FAIL("RPA rotation did not occur within +-10%% of CONFIG_BT_RPA_TIMEOUT"); - } - old_time = new_time; - - SET_FLAG(flag_new_address); - } - - old_addr = new_addr; -} - -static struct bt_le_ext_adv_cb adv_callbacks = { - .scanned = scanned_cb, -}; - -void start_advertising(void) -{ - int err; - uint8_t mfg_data[] = {0xAB, 0xCD, 0xEF}; - const struct bt_data sd[] = {BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, 3)}; - struct bt_le_adv_param params; - struct bt_le_ext_adv_start_param start_params; - struct bt_le_ext_adv *adv; - - /* Enable bluetooth */ - err = bt_enable(NULL); - if (err) { - FAIL("Failed to enable bluetooth (err %d\n)", err); - } - - /* Create advertising set */ - params.id = BT_ID_DEFAULT; - params.sid = 0; - params.secondary_max_skip = 0; - params.options = BT_LE_ADV_OPT_EXT_ADV | BT_LE_ADV_OPT_SCANNABLE | - BT_LE_ADV_OPT_NOTIFY_SCAN_REQ | BT_LE_ADV_OPT_USE_NAME; - params.interval_min = BT_GAP_ADV_FAST_INT_MIN_1; - params.interval_max = BT_GAP_ADV_FAST_INT_MAX_1; - params.peer = NULL; - - err = bt_le_ext_adv_create(¶ms, &adv_callbacks, &adv); - if (err) { - FAIL("Failed to create advertising set (err %d)\n", err); - } - - /* Set scan data */ - err = bt_le_ext_adv_set_data(adv, NULL, 0, sd, ARRAY_SIZE(sd)); - if (err) { - FAIL("Failed to set advertising data (err %d)", err); - } - - /* Start advertising */ - start_params.timeout = 0; - start_params.num_events = 0; - - err = bt_le_ext_adv_start(adv, &start_params); - if (err) { - FAIL("Failed to start advertising (err %d)\n", err); - } -} - -void tester_procedure(void) -{ - start_advertising(); - - for (int i = 0; i < 5; i++) { - WAIT_FOR_FLAG(flag_new_address); - UNSET_FLAG(flag_new_address); - } - - PASS("PASS\n"); -} diff --git a/tests/bluetooth/bsim/host/privacy/central/test_scripts/_compile.sh b/tests/bluetooth/bsim/host/privacy/central/test_scripts/_compile.sh deleted file mode 100755 index e7a3d65a2a4..00000000000 --- a/tests/bluetooth/bsim/host/privacy/central/test_scripts/_compile.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -set -eu -bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" - -# Read variable definitions output by _env.sh -source <("${bash_source_dir}/_env.sh") - - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" -: "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" -: "${ZEPHYR_BASE:?ZEPHYR_BASE must be defined}" - - -WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_bt_out}" -BOARD="${BOARD:-nrf52_bsim}" -BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" -INCR_BUILD=1 -mkdir -p ${WORK_DIR} - -west build -b nrf52_bsim -cp build/zephyr/zephyr.exe $central_exe diff --git a/tests/bluetooth/bsim/host/privacy/central/test_scripts/_env.sh b/tests/bluetooth/bsim/host/privacy/central/test_scripts/_env.sh deleted file mode 100755 index a196afdadeb..00000000000 --- a/tests/bluetooth/bsim/host/privacy/central/test_scripts/_env.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -set -eu -bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -test_name="$(basename "$(realpath "$bash_source_dir/..")")" -bsim_bin="${BSIM_OUT_PATH}/bin" -verbosity_level=2 -BOARD="${BOARD:-nrf52_bsim}" -simulation_id="$test_name" -central_exe="${bsim_bin}/bs_${BOARD}_tests_bluetooth_bsim_host_privacy_central_prj_conf" -peripheral_exe="${central_exe}" - -function print_var { - # Print a shell-sourceable variable definition. - local var_name="$1" - local var_repr="${!var_name@Q}" - echo "$var_name=$var_repr" -} - -print_var test_name -print_var bsim_bin -print_var verbosity_level -print_var BOARD -print_var simulation_id -print_var central_exe -print_var peripheral_exe diff --git a/tests/bluetooth/bsim/host/privacy/central/test_scripts/run_test.sh b/tests/bluetooth/bsim/host/privacy/central/test_scripts/run_test.sh deleted file mode 100755 index e2a80ba51f4..00000000000 --- a/tests/bluetooth/bsim/host/privacy/central/test_scripts/run_test.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -set -eu -bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" - -# Read variable definitions output by _env.sh -source <("${bash_source_dir}/_env.sh") - -process_ids="" -exit_code=0 - -function Execute() { - if [ ! -f $1 ]; then - echo -e " \e[91m$(pwd)/$(basename $1) cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 30 $@ & - process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -cd ${BSIM_OUT_PATH}/bin - -Execute "$central_exe" \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central -RealEncryption=1 - -Execute "$peripheral_exe" \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral -RealEncryption=1 - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=60e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done - -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/privacy/device/CMakeLists.txt b/tests/bluetooth/bsim/host/privacy/device/CMakeLists.txt deleted file mode 100644 index b11be745976..00000000000 --- a/tests/bluetooth/bsim/host/privacy/device/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set \ - the environment variable BSIM_COMPONENTS_PATH to point to its \ - components folder. More information can be found in \ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_privacy) - -target_sources(app PRIVATE - src/test_undirected_main.c - src/test_undirected_central.c - src/test_undirected_peripheral.c -) - -zephyr_include_directories( - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ - ${ZEPHYR_BASE}/subsys/bluetooth/host/ -) diff --git a/tests/bluetooth/bsim/host/privacy/device/README.rst b/tests/bluetooth/bsim/host/privacy/device/README.rst deleted file mode 100644 index 7e13f0b7808..00000000000 --- a/tests/bluetooth/bsim/host/privacy/device/README.rst +++ /dev/null @@ -1,18 +0,0 @@ -.. _bsim_test_bt_privacy: - -Privacy feature test -******************** - -Tests goals -=========== - -The tests check the following aspects of the Bluetooth privacy feature: - -* In device privacy mode, a scanner shall accept advertising packets from peers with any address - type. That, even if they have previously exchanged IRK; (Core Specification version 5.4, vol. 1 - part A, 5.4.5.) -* After devices have exchanged IRK, they must correctly resolve RPA when receiving packets from the - peer. - -For references, see the Bluetooth Core specification version 5.4, vol. 1, part A, 5.4.5 and vol. 6, -part B, 6. diff --git a/tests/bluetooth/bsim/host/privacy/device/prj.conf b/tests/bluetooth/bsim/host/privacy/device/prj.conf deleted file mode 100644 index f2d7af0acda..00000000000 --- a/tests/bluetooth/bsim/host/privacy/device/prj.conf +++ /dev/null @@ -1,15 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_DEVICE_NAME="Privacy feature test" - -CONFIG_BT_SMP=y -CONFIG_BT_PRIVACY=y -CONFIG_BT_EXT_ADV=y - -CONFIG_LOG=y - -# Increase the maximum number of buffers for advertising data to be able to set the scanning data -# CONFIG_BT_CTLR_ADVANCED_FEATURES is needed to enable CONFIG_BT_CTLR_ADV_DATA_BUF_MAX -CONFIG_BT_CTLR_ADV_DATA_BUF_MAX=2 -CONFIG_BT_CTLR_ADVANCED_FEATURES=y diff --git a/tests/bluetooth/bsim/host/privacy/device/src/test_undirected_central.c b/tests/bluetooth/bsim/host/privacy/device/src/test_undirected_central.c deleted file mode 100644 index e3bb10231a2..00000000000 --- a/tests/bluetooth/bsim/host/privacy/device/src/test_undirected_central.c +++ /dev/null @@ -1,281 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -#include - -#include - -#include -#include - -#include -LOG_MODULE_DECLARE(bt_bsim_privacy, LOG_LEVEL_INF); - -#include "bs_types.h" -#include "bs_tracing.h" -#include "bstests.h" -#include "bs_cmd_line.h" - -#define CREATE_FLAG(flag) static atomic_t flag = (atomic_t) false -#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) true) -#define GET_FLAG(flag) (bool)atomic_get(&flag) -#define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) false) -#define WAIT_FOR_FLAG(flag) \ - while (!(bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } - -#define FAIL(...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, __VA_ARGS__); \ - } while (0) - -extern enum bst_result_t bst_result; - -CREATE_FLAG(paired); -CREATE_FLAG(rpa_tested); -CREATE_FLAG(identity_tested); - -static void start_scan(void); - -static struct bt_conn *default_conn; - -static bt_addr_le_t peer_rpa; -static bt_addr_le_t peer_identity; - -enum addr_type_t { - RPA, - IDENTITY_ADDR, -}; -static enum addr_type_t test_addr_type; - -static bool use_active_scan; -static bool connection_test; - -static int sim_id; - -void central_test_args_parse(int argc, char *argv[]) -{ - char *addr_type_arg = NULL; - - bs_args_struct_t args_struct[] = { - { - .dest = &sim_id, - .type = 'i', - .name = "{positive integer}", - .option = "sim-id", - .descript = "Simulation ID counter", - }, - { - .dest = &addr_type_arg, - .type = 's', - .name = "{identity, rpa}", - .option = "addr-type", - .descript = "Address type to test", - }, - { - .dest = &use_active_scan, - .type = 's', - .name = "{0, 1}", - .option = "active-scan", - .descript = "", - }, - { - .dest = &connection_test, - .type = 'b', - .name = "{0, 1}", - .option = "connection-test", - .descript = "", - }, - }; - - bs_args_parse_all_cmd_line(argc, argv, args_struct); - - if (addr_type_arg != NULL) { - if (!strcmp(addr_type_arg, "identity")) { - test_addr_type = IDENTITY_ADDR; - } else if (!strcmp(addr_type_arg, "rpa")) { - test_addr_type = RPA; - } - } -} - -static void wait_check_result(void) -{ - if (test_addr_type == IDENTITY_ADDR) { - WAIT_FOR_FLAG(identity_tested); - LOG_INF("Identity address tested"); - } else if (test_addr_type == RPA) { - WAIT_FOR_FLAG(rpa_tested); - LOG_INF("Resolvable Private Address tested"); - } -} - -static void check_addresses(const bt_addr_le_t *peer_addr) -{ - LOG_DBG("Check addresses"); - - bool addr_equal; - - if (test_addr_type == IDENTITY_ADDR) { - SET_FLAG(identity_tested); - addr_equal = bt_addr_le_eq(&peer_identity, peer_addr); - if (!addr_equal) { - FAIL("The peer address is not the same as the peer previously paired.\n"); - } - } else if (test_addr_type == RPA) { - SET_FLAG(rpa_tested); - addr_equal = bt_addr_le_eq(&peer_identity, peer_addr); - if (!addr_equal) { - FAIL("The resolved address is not the same as the peer previously " - "paired.\n"); - } - } -} - -static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, - struct net_buf_simple *ad) -{ - char addr_str[BT_ADDR_LE_STR_LEN]; - int err; - - if (default_conn) { - return; - } - - bt_addr_le_to_str(addr, addr_str, sizeof(addr_str)); - LOG_DBG("Device found: %s (RSSI %d)", addr_str, rssi); - - if (GET_FLAG(paired)) { - check_addresses(addr); - } - - if (connection_test || !GET_FLAG(paired)) { - if (bt_le_scan_stop()) { - LOG_DBG("Failed to stop scanner"); - return; - } - LOG_DBG("Scanner stopped"); - - err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, BT_LE_CONN_PARAM_DEFAULT, - &default_conn); - if (err) { - LOG_DBG("Create conn to %s failed (%u)", addr_str, err); - start_scan(); - } - } -} - -static void start_scan(void) -{ - int err; - - LOG_DBG("Using %s scan", use_active_scan ? "active" : "passive"); - - err = bt_le_scan_start(use_active_scan ? BT_LE_SCAN_ACTIVE : BT_LE_SCAN_PASSIVE, - device_found); - if (err) { - FAIL("Scanning failed to start (err %d)\n", err); - } - - LOG_DBG("Scanning successfully started"); -} - -static void connected(struct bt_conn *conn, uint8_t err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - LOG_DBG("Connected: %s", addr); -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - if (conn != default_conn) { - return; - } - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - LOG_DBG("Disconnected: %s (reason 0x%02x)", addr, reason); - - bt_conn_unref(default_conn); - default_conn = NULL; - - start_scan(); -} - -static void identity_resolved(struct bt_conn *conn, const bt_addr_le_t *rpa, - const bt_addr_le_t *identity) -{ - char addr_identity[BT_ADDR_LE_STR_LEN]; - char addr_rpa[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(identity, addr_identity, sizeof(addr_identity)); - bt_addr_le_to_str(rpa, addr_rpa, sizeof(addr_rpa)); - - LOG_DBG("Identity resolved %s -> %s", addr_rpa, addr_identity); - - bt_addr_le_copy(&peer_rpa, rpa); - bt_addr_le_copy(&peer_identity, identity); - - SET_FLAG(paired); -} - -static struct bt_conn_cb central_cb; - -void test_central(void) -{ - LOG_DBG("Central device"); - - int err; - - central_cb.connected = connected; - central_cb.disconnected = disconnected; - central_cb.identity_resolved = identity_resolved; - - bt_conn_cb_register(¢ral_cb); - - err = bt_enable(NULL); - if (err) { - FAIL("Bluetooth init failed (err %d)\n", err); - } - - start_scan(); - - wait_check_result(); -} - -void test_central_main(void) -{ - test_central(); - - char *addr_tested = ""; - - if (test_addr_type == RPA) { - addr_tested = "RPA"; - } else if (test_addr_type == IDENTITY_ADDR) { - addr_tested = "identity address"; - } - - PASS("Central test passed (id: %d; params: %s scan, %sconnectable test, testing %s)\n", - sim_id, use_active_scan ? "active" : "passive", connection_test ? "" : "non-", - addr_tested); -} diff --git a/tests/bluetooth/bsim/host/privacy/device/src/test_undirected_main.c b/tests/bluetooth/bsim/host/privacy/device/src/test_undirected_main.c deleted file mode 100644 index 9ff71f02084..00000000000 --- a/tests/bluetooth/bsim/host/privacy/device/src/test_undirected_main.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -#include - -#include - -#include "bs_types.h" -#include "bs_tracing.h" -#include "bstests.h" - -#include -LOG_MODULE_REGISTER(bt_bsim_privacy, LOG_LEVEL_INF); - -extern enum bst_result_t bst_result; - -#define WAIT_TIME_S 20 -#define WAIT_TIME (WAIT_TIME_S * 1e6) /* 20 seconds */ - -extern void central_test_args_parse(int argc, char *argv[]); -extern void peripheral_test_args_parse(int argc, char *argv[]); - -extern void test_central_main(void); -extern void test_peripheral(void); - -void sim_timeout(bs_time_t HW_device_time) -{ - if (bst_result != Passed) { - bst_result = Failed; - bs_trace_error_time_line("Test failed (not passed after %d seconds)\n", - WAIT_TIME_S); - } -} - -static void test_privacy_init(void) -{ - bst_ticker_set_next_tick_absolute(WAIT_TIME); - bst_result = In_progress; -} - -static const struct bst_test_instance test_def[] = { - { - .test_id = "central", - .test_descr = "Central device", - .test_post_init_f = test_privacy_init, - .test_tick_f = sim_timeout, - .test_main_f = test_central_main, - .test_args_f = central_test_args_parse, - }, - { - .test_id = "peripheral", - .test_descr = "Peripheral device", - .test_post_init_f = test_privacy_init, - .test_tick_f = sim_timeout, - .test_main_f = test_peripheral, - .test_args_f = peripheral_test_args_parse, - }, - BSTEST_END_MARKER}; - -struct bst_test_list *test_privacy_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_def); -} - -bst_test_install_t test_installers[] = {test_privacy_install, NULL}; - -void main(void) -{ - bst_main(); -} diff --git a/tests/bluetooth/bsim/host/privacy/device/src/test_undirected_peripheral.c b/tests/bluetooth/bsim/host/privacy/device/src/test_undirected_peripheral.c deleted file mode 100644 index c1242d6c4a9..00000000000 --- a/tests/bluetooth/bsim/host/privacy/device/src/test_undirected_peripheral.c +++ /dev/null @@ -1,455 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include - -#include - -#include - -#include -#include -#include - -#include -LOG_MODULE_DECLARE(bt_bsim_privacy, LOG_LEVEL_INF); - -#include "bs_types.h" -#include "bs_tracing.h" -#include "bstests.h" -#include "bs_cmd_line.h" - -#define FAIL(...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, __VA_ARGS__); \ - } while (0) - -extern enum bst_result_t bst_result; - -#define CREATE_FLAG(flag) static atomic_t flag = (atomic_t) false -#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) true) -#define GET_FLAG(flag) (bool)atomic_get(&flag) -#define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) false) -#define WAIT_FOR_FLAG(flag) \ - while (!(bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } - -CREATE_FLAG(paired_flag); -CREATE_FLAG(connected_flag); -CREATE_FLAG(wait_disconnection); -CREATE_FLAG(wait_scanned); - -static struct bt_conn *default_conn; - -enum adv_param_t { - CONN_SCAN, - CONN_NSCAN, - NCONN_SCAN, - NCONN_NSCAN, -}; - -enum addr_type_t { - RPA, - IDENTITY_ADDR, -}; - -static enum addr_type_t test_addr_type; - -static bool use_ext_adv; - -static bool scannable_test; -static bool connectable_test; -static enum adv_param_t adv_param; - -static int sim_id; - -void peripheral_test_args_parse(int argc, char *argv[]) -{ - char *addr_type_arg = NULL; - - bs_args_struct_t args_struct[] = { - { - .dest = &sim_id, - .type = 'i', - .name = "{positive integer}", - .option = "sim-id", - .descript = "Simulation ID counter", - }, - { - .dest = &addr_type_arg, - .type = 's', - .name = "{identity, rsa}", - .option = "addr-type", - .descript = "Address type to test", - }, - { - .dest = &use_ext_adv, - .type = 'b', - .name = "{0, 1}", - .option = "use-ext-adv", - .descript = "Use Extended Advertising", - }, - { - .dest = &scannable_test, - .type = 'b', - .name = "{0, 1}", - .option = "scannable", - .descript = "Use a scannable advertiser for the test", - }, - { - .dest = &connectable_test, - .type = 'b', - .name = "{0, 1}", - .option = "connectable", - .descript = "Use a connectable advertiser for the test", - }, - }; - - bs_args_parse_all_cmd_line(argc, argv, args_struct); - - if (addr_type_arg != NULL) { - if (!strcmp(addr_type_arg, "identity")) { - test_addr_type = IDENTITY_ADDR; - } else if (!strcmp(addr_type_arg, "rpa")) { - test_addr_type = RPA; - } - } - - if (connectable_test && scannable_test) { - if (!use_ext_adv) { - adv_param = CONN_SCAN; - } - } else if (connectable_test) { - adv_param = CONN_NSCAN; - } else if (scannable_test) { - adv_param = NCONN_SCAN; - } else { - adv_param = NCONN_NSCAN; - } -} - -static void wait_for_scanned(void) -{ - LOG_DBG("Waiting for scan request"); - WAIT_FOR_FLAG(wait_scanned); - UNSET_FLAG(wait_scanned); -} - -static void adv_scanned_cb(struct bt_le_ext_adv *adv, struct bt_le_ext_adv_scanned_info *info) -{ - LOG_DBG("Scan request received"); - SET_FLAG(wait_scanned); -} - -static struct bt_le_ext_adv_cb adv_cb = { - .scanned = adv_scanned_cb, -}; - -static void create_adv(struct bt_le_ext_adv **adv) -{ - int err; - struct bt_le_adv_param params; - - memset(¶ms, 0, sizeof(struct bt_le_adv_param)); - - params.options |= BT_LE_ADV_OPT_CONNECTABLE; - - params.id = BT_ID_DEFAULT; - params.sid = 0; - params.interval_min = BT_GAP_ADV_SLOW_INT_MIN; - params.interval_max = BT_GAP_ADV_SLOW_INT_MAX; - - err = bt_le_ext_adv_create(¶ms, &adv_cb, adv); - if (err) { - LOG_ERR("Failed to create advertiser (%d)", err); - return; - } - - LOG_DBG("Advertiser created"); -} - -static void update_adv_params(struct bt_le_ext_adv *adv, enum adv_param_t adv_params, - enum addr_type_t addr_type) -{ - int err; - struct bt_le_adv_param params; - - memset(¶ms, 0, sizeof(struct bt_le_adv_param)); - - if (adv_params == CONN_SCAN) { - params.options |= BT_LE_ADV_OPT_CONNECTABLE; - params.options |= BT_LE_ADV_OPT_SCANNABLE; - LOG_DBG("Advertiser params: CONN_SCAN"); - } else if (adv_params == CONN_NSCAN) { - params.options |= BT_LE_ADV_OPT_CONNECTABLE; - LOG_DBG("Advertiser params: CONN_NSCAN"); - } else if (adv_params == NCONN_SCAN) { - params.options |= BT_LE_ADV_OPT_SCANNABLE; - LOG_DBG("Advertiser params: NCONN_SCAN"); - } else if (adv_params == NCONN_NSCAN) { - LOG_DBG("Advertiser params: NCONN_NSCAN"); - } - - if (use_ext_adv) { - params.options |= BT_LE_ADV_OPT_EXT_ADV; - LOG_DBG("Advertiser params: EXT_ADV"); - params.options |= BT_LE_ADV_OPT_NOTIFY_SCAN_REQ; - LOG_DBG("Advertiser params: NOTIFY_SCAN_REQ"); - } else { - LOG_DBG("Advertiser params: LEGACY_ADV"); - } - - if (addr_type == IDENTITY_ADDR) { - LOG_DBG("Advertiser params: USE_IDENTITY"); - params.options |= BT_LE_ADV_OPT_USE_IDENTITY; - } else if (addr_type == RPA) { - LOG_DBG("Advertiser params: USE_RPA"); - } - - params.id = BT_ID_DEFAULT; - params.sid = 0; - params.interval_min = BT_GAP_ADV_SLOW_INT_MIN; - params.interval_max = BT_GAP_ADV_SLOW_INT_MAX; - - err = bt_le_ext_adv_update_param(adv, ¶ms); - if (err) { - LOG_ERR("Failed to update advertiser set (%d)", err); - return; - } - - if (use_ext_adv && adv_params == NCONN_SCAN) { - uint8_t data[4] = {0x61, 0x6c, 0x65, 0x64}; - struct bt_data sd; - size_t sd_len = 1; - - sd.type = 0x09; - sd.data_len = 0x05; - sd.data = data; - - err = bt_le_ext_adv_set_data(adv, NULL, 0, &sd, sd_len); - if (err) { - LOG_ERR("Failed to set advertising data (%d)", err); - } - - LOG_DBG("Advertiser data set"); - } - - LOG_DBG("Advertiser params updated"); -} - -static void start_adv(struct bt_le_ext_adv *adv) -{ - int err; - int32_t timeout = 0; - uint8_t num_events = 0; - - struct bt_le_ext_adv_start_param start_params; - - start_params.timeout = timeout; - start_params.num_events = num_events; - - err = bt_le_ext_adv_start(adv, &start_params); - - if (err) { - LOG_ERR("Failed to start advertiser (%d)", err); - return; - } - - LOG_DBG("Advertiser started"); -} - -static void stop_adv(struct bt_le_ext_adv *adv) -{ - int err; - - err = bt_le_ext_adv_stop(adv); - if (err) { - LOG_WRN("Failed to stop advertiser (%d)", err); - return; - } - - LOG_DBG("Advertiser stopped"); -} - -static void disconnect(void) -{ - LOG_DBG("Starting disconnection"); - int err; - - err = bt_conn_disconnect(default_conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN); - if (err) { - FAIL("Disconnection failed (err %d)\n", err); - } - - WAIT_FOR_FLAG(wait_disconnection); - UNSET_FLAG(wait_disconnection); -} - -static void wait_for_connection(void) -{ - WAIT_FOR_FLAG(connected_flag); - UNSET_FLAG(connected_flag); -} - -static void connected(struct bt_conn *conn, uint8_t err) -{ - LOG_DBG("Peripheral Connected function"); - - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (err) { - LOG_WRN("Failed to connect to %s (%u)", addr, err); - return; - } - - LOG_DBG("Connected: %s", addr); - - default_conn = bt_conn_ref(conn); - - if (!GET_FLAG(paired_flag)) { - if (bt_conn_set_security(conn, BT_SECURITY_L2)) { - FAIL("Failed to set security\n"); - } - } else { - SET_FLAG(connected_flag); - } -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - if (conn != default_conn) { - return; - } - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - LOG_DBG("Disconnected: %s (reason 0x%02x)", addr, reason); - - bt_conn_unref(default_conn); - default_conn = NULL; - - LOG_DBG("Disconnected"); - SET_FLAG(wait_disconnection); -} - -static void identity_resolved(struct bt_conn *conn, const bt_addr_le_t *rpa, - const bt_addr_le_t *identity) -{ - char addr_identity[BT_ADDR_LE_STR_LEN]; - char addr_rpa[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(identity, addr_identity, sizeof(addr_identity)); - bt_addr_le_to_str(rpa, addr_rpa, sizeof(addr_rpa)); - - LOG_DBG("Identity resolved %s -> %s", addr_rpa, addr_identity); -} - -static void security_changed(struct bt_conn *conn, bt_security_t level, enum bt_security_err err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (!err) { - LOG_DBG("Security changed: %s level %u", addr, level); - } else { - LOG_ERR("Security failed: %s level %u err %d", addr, level); - } -} - -static void pairing_complete(struct bt_conn *conn, bool bonded) -{ - LOG_DBG("Pairing complete"); - SET_FLAG(paired_flag); -} - -static void pairing_failed(struct bt_conn *conn, enum bt_security_err reason) -{ - LOG_WRN("Pairing failed (%d). Disconnecting.", reason); - bt_conn_disconnect(conn, BT_HCI_ERR_AUTH_FAIL); -} - -static struct bt_conn_cb peri_cb; - -static struct bt_conn_auth_info_cb auth_cb_info = { - .pairing_complete = pairing_complete, - .pairing_failed = pairing_failed, -}; - -static void test_peripheral_main(void) -{ - LOG_DBG("Peripheral device"); - - int err; - struct bt_le_ext_adv *adv = NULL; - - peri_cb.connected = connected; - peri_cb.disconnected = disconnected; - peri_cb.security_changed = security_changed; - peri_cb.identity_resolved = identity_resolved; - - bt_conn_cb_register(&peri_cb); - - err = bt_enable(NULL); - if (err) { - FAIL("Bluetooth init failed (err %d)\n", err); - } - - LOG_DBG("Bluetooth initialized"); - - bt_conn_auth_info_cb_register(&auth_cb_info); - - create_adv(&adv); - - update_adv_params(adv, CONN_NSCAN, RPA); - start_adv(adv); - WAIT_FOR_FLAG(paired_flag); - disconnect(); - stop_adv(adv); - - update_adv_params(adv, adv_param, test_addr_type); - start_adv(adv); - /* (the connection with identity should fail with privacy network mode) */ - if (connectable_test) { - wait_for_connection(); - disconnect(); - } else if (scannable_test && use_ext_adv) { - wait_for_scanned(); - } - stop_adv(adv); -} - -void test_peripheral(void) -{ - test_peripheral_main(); - - char *addr_tested = ""; - - if (test_addr_type == RPA) { - addr_tested = "RPA"; - } else if (test_addr_type == IDENTITY_ADDR) { - addr_tested = "identity address"; - } - - PASS("Peripheral test passed (id: %d; %s advertiser, %sconnectable %sscannable, testing)\n", - sim_id, use_ext_adv ? "extended" : "legacy", connectable_test ? "" : "non-", - scannable_test ? "" : "non-", addr_tested); -} diff --git a/tests/bluetooth/bsim/host/privacy/device/test_scripts/_compile.sh b/tests/bluetooth/bsim/host/privacy/device/test_scripts/_compile.sh deleted file mode 100755 index 42376ab5231..00000000000 --- a/tests/bluetooth/bsim/host/privacy/device/test_scripts/_compile.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/env bash -# Copyright 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -set -eu -bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" - -source "${bash_source_dir}/_env.sh" - -west build -b nrf52_bsim && \ - cp -v build/zephyr/zephyr.exe "${test_exe}" diff --git a/tests/bluetooth/bsim/host/privacy/device/test_scripts/_env.sh b/tests/bluetooth/bsim/host/privacy/device/test_scripts/_env.sh deleted file mode 100755 index 0b4455c9251..00000000000 --- a/tests/bluetooth/bsim/host/privacy/device/test_scripts/_env.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/env bash -# Copyright 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -set -eu -bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -test_name="$(basename "$(realpath "$bash_source_dir/..")")" -bsim_bin="${BSIM_OUT_PATH}/bin" -verbosity_level=2 -BOARD="${BOARD:-nrf52_bsim}" -simulation_id="$test_name" -test_exe="${bsim_bin}/bs_${BOARD}_tests_bluetooth_bsim_host_privacy_device_prj_conf" diff --git a/tests/bluetooth/bsim/host/privacy/device/test_scripts/run_tests.sh b/tests/bluetooth/bsim/host/privacy/device/test_scripts/run_tests.sh deleted file mode 100755 index 6c9ad8a0bbd..00000000000 --- a/tests/bluetooth/bsim/host/privacy/device/test_scripts/run_tests.sh +++ /dev/null @@ -1,85 +0,0 @@ -#!/bin/env bash -# Copyright 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -set -eu -bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" - -# Read variable definitions output by _env.sh -source "${bash_source_dir}/_env.sh" - -process_ids="" -exit_code=0 - -function Execute() { - if [ ! -f $1 ]; then - echo -e " \e[91m$(pwd)/$(basename $1) cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 30 $@ & - process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -cd ${BSIM_OUT_PATH}/bin - -TEST_ARGS=( - "leg_conn_scan_active" - "leg_conn_nscan_passive" - "ext_nconn_scan_active" - "ext_conn_nscan_passive" -) -TEST_ADDR_TYPE=("identity" "rpa") - -sim_id_count=0 -for args in ${TEST_ARGS[@]}; do - args=($(echo "${args}" | sed 's/_/ /g')) - - use_ext_adv=0 - if [ "${args[0]}" == "ext" ]; then - use_ext_adv=1 - fi - - connectable=0 - if [ "${args[1]}" == "conn" ]; then - connectable=1 - fi - - scannable=0 - if [ "${args[2]}" == "scan" ]; then - scannable=1 - fi - - use_active_scan=0 - if [ "${args[3]}" == "active" ]; then - use_active_scan=1 - fi - - for addr_type in "${TEST_ADDR_TYPE[@]}"; do - Execute "$test_exe" \ - -v=${verbosity_level} -s="${simulation_id}_${sim_id_count}" -d=0 -testid=central \ - -RealEncryption=1 -argstest sim-id=${sim_id_count} connection-test=${connectable} \ - active-scan=${use_active_scan} addr-type="${addr_type}" - - Execute "$test_exe" \ - -v=${verbosity_level} -s="${simulation_id}_${sim_id_count}" -d=1 -testid=peripheral \ - -RealEncryption=1 -argstest sim-id=${sim_id_count} addr-type="${addr_type}" \ - use-ext-adv=${use_ext_adv} scannable=${scannable} connectable=${connectable} - - Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s="${simulation_id}_${sim_id_count}" \ - -D=2 -sim_length=60e6 $@ - - sim_id_count=$(( sim_id_count + 1 )) - done -done - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" - if [ ${exit_code} -ne 0 ]; then - exit_code=1 - fi -done - -exit $exit_code # the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/privacy/peripheral/CMakeLists.txt b/tests/bluetooth/bsim/host/privacy/peripheral/CMakeLists.txt deleted file mode 100644 index 22ce36f0b6c..00000000000 --- a/tests/bluetooth/bsim/host/privacy/peripheral/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set\ - the environment variable BSIM_COMPONENTS_PATH to point to its components \ - folder. More information can be found in\ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_rpa_peripheral) - -target_sources(app PRIVATE - src/bs_bt_utils.c - src/tester.c - src/main.c - src/dut.c -) - -zephyr_include_directories( - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ - ) diff --git a/tests/bluetooth/bsim/host/privacy/peripheral/prj.conf b/tests/bluetooth/bsim/host/privacy/peripheral/prj.conf deleted file mode 100644 index 68d1a54ca7d..00000000000 --- a/tests/bluetooth/bsim/host/privacy/peripheral/prj.conf +++ /dev/null @@ -1,9 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_SMP=y -CONFIG_ASSERT=y - -CONFIG_BT_EXT_ADV=y -CONFIG_BT_PRIVACY=y -CONFIG_BT_RPA_TIMEOUT=10 diff --git a/tests/bluetooth/bsim/host/privacy/peripheral/src/bs_bt_utils.c b/tests/bluetooth/bsim/host/privacy/peripheral/src/bs_bt_utils.c deleted file mode 100644 index 0a05e2fb0d5..00000000000 --- a/tests/bluetooth/bsim/host/privacy/peripheral/src/bs_bt_utils.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bs_bt_utils.h" -#include "bs_pc_backchannel.h" -#include "argparse.h" - -#define BS_SECONDS(dur_sec) ((bs_time_t)dur_sec * 1000000) -#define TEST_TIMEOUT_SIMULATED BS_SECONDS(120) -#define CHANNEL_ID 0 -#define MSG_SIZE 1 - -void test_tick(bs_time_t HW_device_time) -{ - bs_trace_debug_time(0, "Simulation ends now.\n"); - if (bst_result != Passed) { - bst_result = Failed; - - bs_trace_error("Test did not pass before simulation ended.\n"); - } -} - -void test_init(void) -{ - bst_ticker_set_next_tick_absolute(TEST_TIMEOUT_SIMULATED); - bst_result = In_progress; -} - -void backchannel_init(uint peer) -{ - uint device_number = get_device_nbr(); - uint device_numbers[] = {peer}; - uint channel_numbers[] = {CHANNEL_ID}; - uint *ch; - - ch = bs_open_back_channel(device_number, device_numbers, channel_numbers, - ARRAY_SIZE(channel_numbers)); - if (!ch) { - FAIL("Unable to open backchannel\n"); - } -} - -void backchannel_sync_send(void) -{ - uint8_t sync_msg[MSG_SIZE] = {get_device_nbr()}; - - bs_bc_send_msg(CHANNEL_ID, sync_msg, ARRAY_SIZE(sync_msg)); -} - -void backchannel_sync_wait(void) -{ - uint8_t sync_msg[MSG_SIZE]; - - while (true) { - if (bs_bc_is_msg_received(CHANNEL_ID) > 0) { - bs_bc_receive_msg(CHANNEL_ID, sync_msg, ARRAY_SIZE(sync_msg)); - if (sync_msg[0] != get_device_nbr()) { - /* Received a message from another device, exit */ - break; - } - } - - k_sleep(K_MSEC(1)); - } -} - -void print_address(bt_addr_le_t *addr) -{ - char array[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(addr, array, sizeof(array)); - printk("Address : %s\n", array); -} diff --git a/tests/bluetooth/bsim/host/privacy/peripheral/src/bs_bt_utils.h b/tests/bluetooth/bsim/host/privacy/peripheral/src/bs_bt_utils.h deleted file mode 100644 index 48bc843dbfa..00000000000 --- a/tests/bluetooth/bsim/host/privacy/peripheral/src/bs_bt_utils.h +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Common functions and helpers for BSIM ADV tests - * - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bs_tracing.h" -#include "bs_types.h" -#include "bstests.h" -#include "time_machine.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -extern enum bst_result_t bst_result; - -#define ASSERT(expr, ...) \ - do { \ - if (!(expr)) { \ - FAIL(__VA_ARGS__); \ - } \ - } while (0) - -#define FAIL(...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, __VA_ARGS__); \ - } while (0) - -#define TESTER_CENTRAL_ID 0 -#define DUT_PERIPHERAL_ID 1 - -void test_tick(bs_time_t HW_device_time); -void test_init(void); -void backchannel_init(uint peer); -void backchannel_sync_send(void); -void backchannel_sync_wait(void); - -void print_address(bt_addr_le_t *addr); diff --git a/tests/bluetooth/bsim/host/privacy/peripheral/src/dut.c b/tests/bluetooth/bsim/host/privacy/peripheral/src/dut.c deleted file mode 100644 index a9f33b0e65b..00000000000 --- a/tests/bluetooth/bsim/host/privacy/peripheral/src/dut.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bs_bt_utils.h" - -#include -#include - -#include -#include -#include -#include - -bool cb_rpa_expired(struct bt_le_ext_adv *adv) -{ - backchannel_sync_send(); - - /* Return true to rotate the current RPA */ - return true; -} - -void start_advertising(void) -{ - int err; - static struct bt_le_ext_adv_cb cb_adv; - struct bt_le_ext_adv_start_param start_params; - struct bt_le_ext_adv *adv; - - /* Enable bluetooth */ - err = bt_enable(NULL); - if (err) { - FAIL("Failed to enable bluetooth (err %d\n)", err); - } - - /* Start non-connectable extended advertising with private address */ - start_params.timeout = 0; - start_params.num_events = 0; - cb_adv.rpa_expired = cb_rpa_expired; - - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CONN_NAME, &cb_adv, &adv); - if (err) { - FAIL("Failed to create advertising set (err %d)\n", err); - } - - err = bt_le_ext_adv_start(adv, &start_params); - if (err) { - FAIL("Failed to enable periodic advertising (err %d)\n", err); - } -} - -void dut_procedure(void) -{ - /* Setup synchronization channel */ - backchannel_init(TESTER_CENTRAL_ID); - - start_advertising(); - - /* Nothing to do */ - - PASS("PASS\n"); -} diff --git a/tests/bluetooth/bsim/host/privacy/peripheral/src/main.c b/tests/bluetooth/bsim/host/privacy/peripheral/src/main.c deleted file mode 100644 index 54828e0a419..00000000000 --- a/tests/bluetooth/bsim/host/privacy/peripheral/src/main.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bs_bt_utils.h" -#include "bstests.h" - -void tester_procedure(void); -void dut_procedure(void); - -static const struct bst_test_instance test_to_add[] = { - { - .test_id = "central", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = tester_procedure, - }, - { - .test_id = "peripheral", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = dut_procedure, - }, - BSTEST_END_MARKER, -}; - -static struct bst_test_list *install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_to_add); -}; - -bst_test_install_t test_installers[] = {install, NULL}; - -void main(void) -{ - bst_main(); -} diff --git a/tests/bluetooth/bsim/host/privacy/peripheral/src/tester.c b/tests/bluetooth/bsim/host/privacy/peripheral/src/tester.c deleted file mode 100644 index 517519ac635..00000000000 --- a/tests/bluetooth/bsim/host/privacy/peripheral/src/tester.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bs_bt_utils.h" -#include "zephyr/bluetooth/addr.h" -#include "zephyr/bluetooth/conn.h" -#include -#include - -static volatile int64_t old_time, new_time; -static bt_addr_le_t old_addr; -static bt_addr_le_t *new_addr; - -static void cb_device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, - struct net_buf_simple *ad) -{ - static bool init; - - if (!init) { - old_addr = *addr; - old_time = k_uptime_get(); - init = true; - } - - new_addr = (bt_addr_le_t *)addr; - new_time = k_uptime_get(); -} - -void start_scanning(void) -{ - int err; - struct bt_le_scan_param params; - - /* Enable bluetooth */ - err = bt_enable(NULL); - if (err) { - FAIL("Failed to enable bluetooth (err %d\n)", err); - } - - /* Start passive scanning */ - params.type = BT_LE_SCAN_TYPE_PASSIVE; - params.options = BT_LE_SCAN_OPT_FILTER_DUPLICATE; - params.interval = BT_GAP_SCAN_FAST_INTERVAL; - params.window = BT_GAP_SCAN_FAST_WINDOW; - - err = bt_le_scan_start(¶ms, cb_device_found); - if (err) { - FAIL("Failed to start scanning"); - } -} - -void tester_procedure(void) -{ - int err; - - /* Setup synchronization channel */ - backchannel_init(DUT_PERIPHERAL_ID); - - start_scanning(); - - /* Wait for the first address rotation */ - backchannel_sync_wait(); - - for (uint16_t i = 0; i < 5; i++) { - int64_t diff, time_diff_ms, rpa_timeout_ms; - - backchannel_sync_wait(); - - /* Compare old and new address */ - err = bt_addr_le_cmp(&old_addr, new_addr); - if (err == 0) { - FAIL("RPA did not rotate", err); - } - - /* Ensure the RPA rotation occurs within +-10% of CONFIG_BT_RPA_TIMEOUT */ - time_diff_ms = new_time - old_time; - rpa_timeout_ms = CONFIG_BT_RPA_TIMEOUT * MSEC_PER_SEC; - - if (time_diff_ms > rpa_timeout_ms) { - diff = time_diff_ms - rpa_timeout_ms; - } else { - diff = rpa_timeout_ms - time_diff_ms; - } - - if (diff > (rpa_timeout_ms / 10)) { - FAIL("RPA rotation did not occur within +-10%% of CONFIG_BT_RPA_TIMEOUT"); - } - - printk("Old "); - print_address(&old_addr); - printk("New "); - print_address(new_addr); - - old_addr = *new_addr; - old_time = new_time; - } - - PASS("PASS\n"); -} diff --git a/tests/bluetooth/bsim/host/privacy/peripheral/test_scripts/_compile.sh b/tests/bluetooth/bsim/host/privacy/peripheral/test_scripts/_compile.sh deleted file mode 100755 index e7a3d65a2a4..00000000000 --- a/tests/bluetooth/bsim/host/privacy/peripheral/test_scripts/_compile.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -set -eu -bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" - -# Read variable definitions output by _env.sh -source <("${bash_source_dir}/_env.sh") - - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" -: "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" -: "${ZEPHYR_BASE:?ZEPHYR_BASE must be defined}" - - -WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_bt_out}" -BOARD="${BOARD:-nrf52_bsim}" -BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" -INCR_BUILD=1 -mkdir -p ${WORK_DIR} - -west build -b nrf52_bsim -cp build/zephyr/zephyr.exe $central_exe diff --git a/tests/bluetooth/bsim/host/privacy/peripheral/test_scripts/_env.sh b/tests/bluetooth/bsim/host/privacy/peripheral/test_scripts/_env.sh deleted file mode 100755 index 9731c7178f5..00000000000 --- a/tests/bluetooth/bsim/host/privacy/peripheral/test_scripts/_env.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -set -eu -bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -test_name="$(basename "$(realpath "$bash_source_dir/..")")" -bsim_bin="${BSIM_OUT_PATH}/bin" -verbosity_level=2 -BOARD="${BOARD:-nrf52_bsim}" -simulation_id="$test_name" -central_exe="${bsim_bin}/bs_${BOARD}_tests_bluetooth_bsim_host_privacy_peripheral_prj_conf" -peripheral_exe="${central_exe}" - -function print_var { - # Print a shell-sourceable variable definition. - local var_name="$1" - local var_repr="${!var_name@Q}" - echo "$var_name=$var_repr" -} - -print_var test_name -print_var bsim_bin -print_var verbosity_level -print_var BOARD -print_var simulation_id -print_var central_exe -print_var peripheral_exe diff --git a/tests/bluetooth/bsim/host/privacy/peripheral/test_scripts/run_test.sh b/tests/bluetooth/bsim/host/privacy/peripheral/test_scripts/run_test.sh deleted file mode 100755 index 8a28a5be46a..00000000000 --- a/tests/bluetooth/bsim/host/privacy/peripheral/test_scripts/run_test.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -set -eu -bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" - -# Read variable definitions output by _env.sh -source <("${bash_source_dir}/_env.sh") - -process_ids="" -exit_code=0 - -function Execute() { - if [ ! -f $1 ]; then - echo -e " \e[91m$(pwd)/$(basename $1) cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 30 $@ & - process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -cd ${BSIM_OUT_PATH}/bin - -Execute "$central_exe" \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central -RealEncryption=1 - -Execute "$peripheral_exe" \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral -RealEncryption=1 - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=120e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done - -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/CMakeLists.txt b/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/CMakeLists.txt deleted file mode 100644 index 74244443471..00000000000 --- a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set\ - the environment variable BSIM_COMPONENTS_PATH to point to its components \ - folder. More information can be found in\ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_multi_id_bond_overwrite_deny) - -target_sources(app PRIVATE - src/bs_bt_utils.c - src/central.c - src/main.c - src/peripheral.c -) - -zephyr_include_directories( - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ - ) diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/prj.conf b/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/prj.conf deleted file mode 100644 index 8f007f7bc9e..00000000000 --- a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/prj.conf +++ /dev/null @@ -1,17 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_CENTRAL=y - -CONFIG_BT_SMP=y - -CONFIG_ASSERT=y -CONFIG_BT_TESTING=y -CONFIG_BT_DEBUG_LOG=y - -CONFIG_BT_ID_MAX=3 -CONFIG_BT_MAX_PAIRED=2 - -CONFIG_BT_PRIVACY=y - -CONFIG_BT_SMP_ALLOW_UNAUTH_OVERWRITE=y -CONFIG_BT_ID_UNPAIR_MATCHING_BONDS=y diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/src/bs_bt_utils.c b/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/src/bs_bt_utils.c deleted file mode 100644 index 0fe1f7d3ac6..00000000000 --- a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/src/bs_bt_utils.c +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bs_bt_utils.h" - -BUILD_ASSERT(CONFIG_BT_MAX_PAIRED >= 2, "CONFIG_BT_MAX_PAIRED is too small."); -BUILD_ASSERT(CONFIG_BT_ID_MAX >= 3, "CONFIG_BT_ID_MAX is too small."); - -#define BS_SECONDS(dur_sec) ((bs_time_t)dur_sec * 1000000) -#define TEST_TIMEOUT_SIMULATED BS_SECONDS(60) - -void test_tick(bs_time_t HW_device_time) -{ - bs_trace_debug_time(0, "Simulation ends now.\n"); - if (bst_result != Passed) { - bst_result = Failed; - bs_trace_error("Test did not pass before simulation ended.\n"); - } -} - -void test_init(void) -{ - bst_ticker_set_next_tick_absolute(TEST_TIMEOUT_SIMULATED); - bst_result = In_progress; -} - -DEFINE_FLAG(flag_is_connected); -struct bt_conn *g_conn; - -void wait_connected(void) -{ - WAIT_FOR_FLAG(flag_is_connected); -} - -void wait_disconnected(void) -{ - WAIT_FOR_FLAG_UNSET(flag_is_connected); -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - UNSET_FLAG(flag_is_connected); -} - -BUILD_ASSERT(CONFIG_BT_MAX_CONN == 1, "This test assumes a single link."); -static void connected(struct bt_conn *conn, uint8_t err) -{ - ASSERT((!g_conn || (conn == g_conn)), "Unexpected new connection."); - - if (!g_conn) { - g_conn = bt_conn_ref(conn); - } - - if (err != 0) { - clear_g_conn(); - return; - } - - SET_FLAG(flag_is_connected); -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - -void clear_g_conn(void) -{ - struct bt_conn *conn; - - conn = g_conn; - g_conn = NULL; - ASSERT(conn, "Test error: No g_conn!\n"); - bt_conn_unref(conn); -} - -/* The following flags are raised by events and lowered by test code. */ -DEFINE_FLAG(flag_pairing_complete); -DEFINE_FLAG(flag_pairing_failed); - -static void pairing_failed(struct bt_conn *conn, enum bt_security_err reason) -{ - SET_FLAG(flag_pairing_failed); -} - -static void pairing_complete(struct bt_conn *conn, bool bonded) -{ - SET_FLAG(flag_pairing_complete); -} - -static struct bt_conn_auth_info_cb bt_conn_auth_info_cb = { - .pairing_failed = pairing_failed, - .pairing_complete = pairing_complete, -}; - -void bs_bt_utils_setup(void) -{ - int err; - - err = bt_enable(NULL); - ASSERT(!err, "bt_enable failed.\n"); - err = bt_conn_auth_info_cb_register(&bt_conn_auth_info_cb); - ASSERT(!err, "bt_conn_auth_info_cb_register failed.\n"); -} - -static void scan_connect_to_first_result__device_found(const bt_addr_le_t *addr, int8_t rssi, - uint8_t type, struct net_buf_simple *ad) -{ - char addr_str[BT_ADDR_LE_STR_LEN]; - int err; - - if (g_conn != NULL) { - return; - } - - /* We're only interested in connectable events */ - if (type != BT_HCI_ADV_IND && type != BT_HCI_ADV_DIRECT_IND) { - FAIL("Unexpected advertisement type."); - } - - bt_addr_le_to_str(addr, addr_str, sizeof(addr_str)); - printk("Got scan result, connecting.. dst %s, RSSI %d\n", addr_str, rssi); - - err = bt_le_scan_stop(); - ASSERT(!err, "Err bt_le_scan_stop %d", err); - - err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, BT_LE_CONN_PARAM_DEFAULT, &g_conn); - ASSERT(!err, "Err bt_conn_le_create %d", err); -} - -void scan_connect_to_first_result(void) -{ - int err; - - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, scan_connect_to_first_result__device_found); - ASSERT(!err, "Err bt_le_scan_start %d", err); -} - -void disconnect(void) -{ - int err; - - err = bt_conn_disconnect(g_conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN); - ASSERT(!err, "Err bt_conn_disconnect %d", err); -} - -void set_security(bt_security_t sec) -{ - int err; - - err = bt_conn_set_security(g_conn, sec); - ASSERT(!err, "Err bt_conn_set_security %d", err); -} - -void advertise_connectable(int id, bt_addr_le_t *directed_dst) -{ - int err; - struct bt_le_adv_param param = {}; - - param.id = id; - param.interval_min = 0x0020; - param.interval_max = 0x4000; - param.options |= BT_LE_ADV_OPT_ONE_TIME; - param.options |= BT_LE_ADV_OPT_CONNECTABLE; - - if (directed_dst) { - param.options |= BT_LE_ADV_OPT_DIR_ADDR_RPA; - param.peer = directed_dst; - } - - err = bt_le_adv_start(¶m, NULL, 0, NULL, 0); - ASSERT(err == 0, "Advertising failed to start (err %d)\n", err); -} diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/src/bs_bt_utils.h b/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/src/bs_bt_utils.h deleted file mode 100644 index 1013fad20fe..00000000000 --- a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/src/bs_bt_utils.h +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Common functions and helpers for BSIM GATT tests - * - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bs_tracing.h" -#include "bs_types.h" -#include "bstests.h" -#include "time_machine.h" -#include "zephyr/sys/__assert.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -extern enum bst_result_t bst_result; - -#define DECLARE_FLAG(flag) extern atomic_t flag -#define DEFINE_FLAG(flag) atomic_t flag = (atomic_t) false -#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) true) -#define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) false) -#define WAIT_FOR_FLAG(flag) \ - while (!(bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } -#define WAIT_FOR_FLAG_UNSET(flag) \ - while ((bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } -#define TAKE_FLAG(flag) \ - while (!(bool)atomic_cas(&flag, true, false)) { \ - (void)k_sleep(K_MSEC(1)); \ - } - -#define ASSERT(expr, ...) \ - do { \ - if (!(expr)) { \ - FAIL(__VA_ARGS__); \ - } \ - } while (0) - -#define FAIL(...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, __VA_ARGS__); \ - } while (0) - -void test_tick(bs_time_t HW_device_time); -void test_init(void); - -DECLARE_FLAG(flag_pairing_complete); -DECLARE_FLAG(flag_pairing_failed); - -extern struct bt_conn *g_conn; -void wait_connected(void); -void wait_disconnected(void); -void clear_g_conn(void); -void bs_bt_utils_setup(void); -void scan_connect_to_first_result(void); -void disconnect(void); -void set_security(bt_security_t sec); -void advertise_connectable(int id, bt_addr_le_t *directed_dst); diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/src/central.c b/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/src/central.c deleted file mode 100644 index 0ea460ab122..00000000000 --- a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/src/central.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bs_bt_utils.h" -#include "zephyr/bluetooth/addr.h" -#include "zephyr/bluetooth/conn.h" - -#include - -#include - -void central(void) -{ - bt_addr_le_t id_b; - - bs_bt_utils_setup(); - - printk("== Bonding id a ==\n"); - scan_connect_to_first_result(); - wait_connected(); - set_security(BT_SECURITY_L2); - TAKE_FLAG(flag_pairing_complete); - disconnect(); - wait_disconnected(); - clear_g_conn(); - - printk("== Bonding id b ==\n"); - scan_connect_to_first_result(); - wait_connected(); - set_security(BT_SECURITY_L2); - TAKE_FLAG(flag_pairing_complete); - id_b = *bt_conn_get_dst(g_conn); - disconnect(); - wait_disconnected(); - clear_g_conn(); - - printk("== Directed connect id b ==\n"); - scan_connect_to_first_result(); - wait_connected(); - ASSERT(bt_addr_le_eq(bt_conn_get_dst(g_conn), &id_b), - "Unexpected Peer. Did something resolve incorrectly?"); - - PASS("PASS\n"); -} diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/src/main.c b/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/src/main.c deleted file mode 100644 index d3a8e12185f..00000000000 --- a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/src/main.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bs_bt_utils.h" -#include "bstests.h" - -void central(void); -void peripheral(void); - -static const struct bst_test_instance test_to_add[] = { - { - .test_id = "central", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = central, - }, - { - .test_id = "peripheral", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = peripheral, - }, - BSTEST_END_MARKER, -}; - -static struct bst_test_list *install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_to_add); -}; - -bst_test_install_t test_installers[] = {install, NULL}; - -void main(void) -{ - bst_main(); -} diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/src/peripheral.c b/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/src/peripheral.c deleted file mode 100644 index 7dca9913dd7..00000000000 --- a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/src/peripheral.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bs_bt_utils.h" -#include "zephyr/bluetooth/addr.h" -#include "zephyr/bluetooth/bluetooth.h" -#include "zephyr/bluetooth/conn.h" -#include "zephyr/toolchain/gcc.h" - -#include -#include - -void peripheral(void) -{ - bs_bt_utils_setup(); - - int id_a; - int id_b; - bt_addr_le_t central; - - id_a = bt_id_create(NULL, NULL); - ASSERT(id_a >= 0, "bt_id_create id_a failed (err %d)\n", id_a); - - id_b = bt_id_create(NULL, NULL); - ASSERT(id_b >= 0, "bt_id_create id_b failed (err %d)\n", id_b); - - printk("== Bonding id a ==\n"); - advertise_connectable(id_a, NULL); - wait_connected(); - /* Central should bond here, and trigger a disconnect. */ - wait_disconnected(); - central = *bt_conn_get_dst(g_conn); - clear_g_conn(); - - printk("== Bonding id b ==\n"); - advertise_connectable(id_b, NULL); - wait_connected(); - /* Central should bond here. */ - BUILD_ASSERT(IS_ENABLED(CONFIG_BT_SMP_ALLOW_UNAUTH_OVERWRITE), ""); - BUILD_ASSERT(IS_ENABLED(CONFIG_BT_ID_UNPAIR_MATCHING_BONDS), ""); - TAKE_FLAG(flag_pairing_complete); - ASSERT(bt_addr_le_eq(bt_conn_get_dst(g_conn), ¢ral), - "Test requires that central uses the same identity in both bonds."); - /* Central should disconnect here. */ - wait_disconnected(); - clear_g_conn(); - - printk("== Directed connect id b ==\n"); - advertise_connectable(id_b, ¢ral); - wait_connected(); - /* Central should verify that its bond with id_b works as expected. */ - - PASS("PASS\n"); -} diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/test_scripts/_compile.sh b/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/test_scripts/_compile.sh deleted file mode 100755 index 7792a05565c..00000000000 --- a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/test_scripts/_compile.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -set -eu -bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" - -# Read variable definitions output by _env.sh -source <("${bash_source_dir}/_env.sh") - - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" -: "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" -: "${ZEPHYR_BASE:?ZEPHYR_BASE must be defined}" - -WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_bt_out}" -BOARD="${BOARD:-nrf52_bsim}" -BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" -INCR_BUILD=1 -mkdir -p ${WORK_DIR} -source ${ZEPHYR_BASE}/tests/bluetooth/bsim/compile.source -app="tests/bluetooth/bsim/$test_name" compile diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/test_scripts/_env.sh b/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/test_scripts/_env.sh deleted file mode 100755 index 4f2af986704..00000000000 --- a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/test_scripts/_env.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 -set -eu -bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -test_name="security_bond_overwrite_allowed" -bsim_bin="${BSIM_OUT_PATH}/bin" -verbosity_level=2 -BOARD="${BOARD:-nrf52_bsim}" -simulation_id="$test_name" -central_exe="${bsim_bin}/bs_${BOARD}_tests_bluetooth_bsim_host_${test_name}_prj_conf" -peripheral_exe="${central_exe}" - -function print_var { - # Print a shell-sourceable variable definition. - local var_name="$1" - local var_repr="${!var_name@Q}" - echo "$var_name=$var_repr" -} - -print_var test_name -print_var bsim_bin -print_var verbosity_level -print_var BOARD -print_var simulation_id -print_var central_exe -print_var peripheral_exe diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/test_scripts/run_test.sh b/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/test_scripts/run_test.sh deleted file mode 100755 index fe5fcfdb194..00000000000 --- a/tests/bluetooth/bsim/host/security/bond_overwrite_allowed/test_scripts/run_test.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -set -eu -bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" - -# Read variable definitions output by _env.sh -source <("${bash_source_dir}/_env.sh") - -process_ids="" -exit_code=0 - -function Execute() { - if [ ! -f $1 ]; then - echo -e " \e[91m$(pwd)/$(basename $1) cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 30 $@ & - process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -cd ${BSIM_OUT_PATH}/bin - -Execute "$central_exe" \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central -RealEncryption=1 - -Execute "$peripheral_exe" \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral -RealEncryption=1 - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=60e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/CMakeLists.txt b/tests/bluetooth/bsim/host/security/bond_overwrite_denied/CMakeLists.txt deleted file mode 100644 index 74244443471..00000000000 --- a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set\ - the environment variable BSIM_COMPONENTS_PATH to point to its components \ - folder. More information can be found in\ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_multi_id_bond_overwrite_deny) - -target_sources(app PRIVATE - src/bs_bt_utils.c - src/central.c - src/main.c - src/peripheral.c -) - -zephyr_include_directories( - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ - ) diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/prj.conf b/tests/bluetooth/bsim/host/security/bond_overwrite_denied/prj.conf deleted file mode 100644 index 401bafab2a1..00000000000 --- a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/prj.conf +++ /dev/null @@ -1,14 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_CENTRAL=y - -CONFIG_BT_SMP=y - -CONFIG_ASSERT=y -CONFIG_BT_TESTING=y -CONFIG_BT_DEBUG_LOG=y - -CONFIG_BT_ID_MAX=3 -CONFIG_BT_MAX_PAIRED=2 - -CONFIG_BT_PRIVACY=y diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/src/bs_bt_utils.c b/tests/bluetooth/bsim/host/security/bond_overwrite_denied/src/bs_bt_utils.c deleted file mode 100644 index 0fe1f7d3ac6..00000000000 --- a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/src/bs_bt_utils.c +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bs_bt_utils.h" - -BUILD_ASSERT(CONFIG_BT_MAX_PAIRED >= 2, "CONFIG_BT_MAX_PAIRED is too small."); -BUILD_ASSERT(CONFIG_BT_ID_MAX >= 3, "CONFIG_BT_ID_MAX is too small."); - -#define BS_SECONDS(dur_sec) ((bs_time_t)dur_sec * 1000000) -#define TEST_TIMEOUT_SIMULATED BS_SECONDS(60) - -void test_tick(bs_time_t HW_device_time) -{ - bs_trace_debug_time(0, "Simulation ends now.\n"); - if (bst_result != Passed) { - bst_result = Failed; - bs_trace_error("Test did not pass before simulation ended.\n"); - } -} - -void test_init(void) -{ - bst_ticker_set_next_tick_absolute(TEST_TIMEOUT_SIMULATED); - bst_result = In_progress; -} - -DEFINE_FLAG(flag_is_connected); -struct bt_conn *g_conn; - -void wait_connected(void) -{ - WAIT_FOR_FLAG(flag_is_connected); -} - -void wait_disconnected(void) -{ - WAIT_FOR_FLAG_UNSET(flag_is_connected); -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - UNSET_FLAG(flag_is_connected); -} - -BUILD_ASSERT(CONFIG_BT_MAX_CONN == 1, "This test assumes a single link."); -static void connected(struct bt_conn *conn, uint8_t err) -{ - ASSERT((!g_conn || (conn == g_conn)), "Unexpected new connection."); - - if (!g_conn) { - g_conn = bt_conn_ref(conn); - } - - if (err != 0) { - clear_g_conn(); - return; - } - - SET_FLAG(flag_is_connected); -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - -void clear_g_conn(void) -{ - struct bt_conn *conn; - - conn = g_conn; - g_conn = NULL; - ASSERT(conn, "Test error: No g_conn!\n"); - bt_conn_unref(conn); -} - -/* The following flags are raised by events and lowered by test code. */ -DEFINE_FLAG(flag_pairing_complete); -DEFINE_FLAG(flag_pairing_failed); - -static void pairing_failed(struct bt_conn *conn, enum bt_security_err reason) -{ - SET_FLAG(flag_pairing_failed); -} - -static void pairing_complete(struct bt_conn *conn, bool bonded) -{ - SET_FLAG(flag_pairing_complete); -} - -static struct bt_conn_auth_info_cb bt_conn_auth_info_cb = { - .pairing_failed = pairing_failed, - .pairing_complete = pairing_complete, -}; - -void bs_bt_utils_setup(void) -{ - int err; - - err = bt_enable(NULL); - ASSERT(!err, "bt_enable failed.\n"); - err = bt_conn_auth_info_cb_register(&bt_conn_auth_info_cb); - ASSERT(!err, "bt_conn_auth_info_cb_register failed.\n"); -} - -static void scan_connect_to_first_result__device_found(const bt_addr_le_t *addr, int8_t rssi, - uint8_t type, struct net_buf_simple *ad) -{ - char addr_str[BT_ADDR_LE_STR_LEN]; - int err; - - if (g_conn != NULL) { - return; - } - - /* We're only interested in connectable events */ - if (type != BT_HCI_ADV_IND && type != BT_HCI_ADV_DIRECT_IND) { - FAIL("Unexpected advertisement type."); - } - - bt_addr_le_to_str(addr, addr_str, sizeof(addr_str)); - printk("Got scan result, connecting.. dst %s, RSSI %d\n", addr_str, rssi); - - err = bt_le_scan_stop(); - ASSERT(!err, "Err bt_le_scan_stop %d", err); - - err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, BT_LE_CONN_PARAM_DEFAULT, &g_conn); - ASSERT(!err, "Err bt_conn_le_create %d", err); -} - -void scan_connect_to_first_result(void) -{ - int err; - - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, scan_connect_to_first_result__device_found); - ASSERT(!err, "Err bt_le_scan_start %d", err); -} - -void disconnect(void) -{ - int err; - - err = bt_conn_disconnect(g_conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN); - ASSERT(!err, "Err bt_conn_disconnect %d", err); -} - -void set_security(bt_security_t sec) -{ - int err; - - err = bt_conn_set_security(g_conn, sec); - ASSERT(!err, "Err bt_conn_set_security %d", err); -} - -void advertise_connectable(int id, bt_addr_le_t *directed_dst) -{ - int err; - struct bt_le_adv_param param = {}; - - param.id = id; - param.interval_min = 0x0020; - param.interval_max = 0x4000; - param.options |= BT_LE_ADV_OPT_ONE_TIME; - param.options |= BT_LE_ADV_OPT_CONNECTABLE; - - if (directed_dst) { - param.options |= BT_LE_ADV_OPT_DIR_ADDR_RPA; - param.peer = directed_dst; - } - - err = bt_le_adv_start(¶m, NULL, 0, NULL, 0); - ASSERT(err == 0, "Advertising failed to start (err %d)\n", err); -} diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/src/bs_bt_utils.h b/tests/bluetooth/bsim/host/security/bond_overwrite_denied/src/bs_bt_utils.h deleted file mode 100644 index 1013fad20fe..00000000000 --- a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/src/bs_bt_utils.h +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Common functions and helpers for BSIM GATT tests - * - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bs_tracing.h" -#include "bs_types.h" -#include "bstests.h" -#include "time_machine.h" -#include "zephyr/sys/__assert.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -extern enum bst_result_t bst_result; - -#define DECLARE_FLAG(flag) extern atomic_t flag -#define DEFINE_FLAG(flag) atomic_t flag = (atomic_t) false -#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) true) -#define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t) false) -#define WAIT_FOR_FLAG(flag) \ - while (!(bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } -#define WAIT_FOR_FLAG_UNSET(flag) \ - while ((bool)atomic_get(&flag)) { \ - (void)k_sleep(K_MSEC(1)); \ - } -#define TAKE_FLAG(flag) \ - while (!(bool)atomic_cas(&flag, true, false)) { \ - (void)k_sleep(K_MSEC(1)); \ - } - -#define ASSERT(expr, ...) \ - do { \ - if (!(expr)) { \ - FAIL(__VA_ARGS__); \ - } \ - } while (0) - -#define FAIL(...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, __VA_ARGS__); \ - } while (0) - -void test_tick(bs_time_t HW_device_time); -void test_init(void); - -DECLARE_FLAG(flag_pairing_complete); -DECLARE_FLAG(flag_pairing_failed); - -extern struct bt_conn *g_conn; -void wait_connected(void); -void wait_disconnected(void); -void clear_g_conn(void); -void bs_bt_utils_setup(void); -void scan_connect_to_first_result(void); -void disconnect(void); -void set_security(bt_security_t sec); -void advertise_connectable(int id, bt_addr_le_t *directed_dst); diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/src/central.c b/tests/bluetooth/bsim/host/security/bond_overwrite_denied/src/central.c deleted file mode 100644 index e1e8e0efc4d..00000000000 --- a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/src/central.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bs_bt_utils.h" -#include "zephyr/bluetooth/addr.h" -#include "zephyr/bluetooth/conn.h" - -#include - -#include - -void central(void) -{ - bs_bt_utils_setup(); - - printk("== Bonding id a ==\n"); - scan_connect_to_first_result(); - wait_connected(); - set_security(BT_SECURITY_L2); - TAKE_FLAG(flag_pairing_complete); - disconnect(); - wait_disconnected(); - clear_g_conn(); - - printk("== Bonding id b ==\n"); - scan_connect_to_first_result(); - wait_connected(); - set_security(BT_SECURITY_L2); - wait_disconnected(); - PASS("PASS\n"); -} diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/src/main.c b/tests/bluetooth/bsim/host/security/bond_overwrite_denied/src/main.c deleted file mode 100644 index d3a8e12185f..00000000000 --- a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/src/main.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bs_bt_utils.h" -#include "bstests.h" - -void central(void); -void peripheral(void); - -static const struct bst_test_instance test_to_add[] = { - { - .test_id = "central", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = central, - }, - { - .test_id = "peripheral", - .test_post_init_f = test_init, - .test_tick_f = test_tick, - .test_main_f = peripheral, - }, - BSTEST_END_MARKER, -}; - -static struct bst_test_list *install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_to_add); -}; - -bst_test_install_t test_installers[] = {install, NULL}; - -void main(void) -{ - bst_main(); -} diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/src/peripheral.c b/tests/bluetooth/bsim/host/security/bond_overwrite_denied/src/peripheral.c deleted file mode 100644 index fb3527b7ef2..00000000000 --- a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/src/peripheral.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bs_bt_utils.h" -#include "zephyr/bluetooth/addr.h" -#include "zephyr/bluetooth/bluetooth.h" -#include "zephyr/bluetooth/conn.h" -#include "zephyr/toolchain/gcc.h" - -#include -#include - -void peripheral(void) -{ - bs_bt_utils_setup(); - - int id_a; - int id_b; - bt_addr_le_t central; - - id_a = bt_id_create(NULL, NULL); - ASSERT(id_a >= 0, "bt_id_create id_a failed (err %d)\n", id_a); - - id_b = bt_id_create(NULL, NULL); - ASSERT(id_b >= 0, "bt_id_create id_b failed (err %d)\n", id_b); - - printk("== Bonding id a ==\n"); - advertise_connectable(id_a, NULL); - wait_connected(); - /* Central should bond here, and trigger a disconnect. */ - wait_disconnected(); - central = *bt_conn_get_dst(g_conn); - clear_g_conn(); - - printk("== Bonding id b ==\n"); - advertise_connectable(id_b, NULL); - wait_connected(); - /* Central should bond here. */ - BUILD_ASSERT(!IS_ENABLED(CONFIG_BT_ID_UNPAIR_MATCHING_BONDS), ""); - WAIT_FOR_FLAG(flag_pairing_failed); - PASS("PASS\n"); -} diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/test_scripts/_compile.sh b/tests/bluetooth/bsim/host/security/bond_overwrite_denied/test_scripts/_compile.sh deleted file mode 100755 index 7792a05565c..00000000000 --- a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/test_scripts/_compile.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -set -eu -bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" - -# Read variable definitions output by _env.sh -source <("${bash_source_dir}/_env.sh") - - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" -: "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" -: "${ZEPHYR_BASE:?ZEPHYR_BASE must be defined}" - -WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_bt_out}" -BOARD="${BOARD:-nrf52_bsim}" -BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" -INCR_BUILD=1 -mkdir -p ${WORK_DIR} -source ${ZEPHYR_BASE}/tests/bluetooth/bsim/compile.source -app="tests/bluetooth/bsim/$test_name" compile diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/test_scripts/_env.sh b/tests/bluetooth/bsim/host/security/bond_overwrite_denied/test_scripts/_env.sh deleted file mode 100755 index 3097cb4bc17..00000000000 --- a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/test_scripts/_env.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 -set -eu -bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -test_name="security_bond_overwrite_denied" -bsim_bin="${BSIM_OUT_PATH}/bin" -verbosity_level=2 -BOARD="${BOARD:-nrf52_bsim}" -simulation_id="$test_name" -central_exe="${bsim_bin}/bs_${BOARD}_tests_bluetooth_bsim_host_${test_name}_prj_conf" -peripheral_exe="${central_exe}" - -function print_var { - # Print a shell-sourceable variable definition. - local var_name="$1" - local var_repr="${!var_name@Q}" - echo "$var_name=$var_repr" -} - -print_var test_name -print_var bsim_bin -print_var verbosity_level -print_var BOARD -print_var simulation_id -print_var central_exe -print_var peripheral_exe diff --git a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/test_scripts/run_test.sh b/tests/bluetooth/bsim/host/security/bond_overwrite_denied/test_scripts/run_test.sh deleted file mode 100755 index fe5fcfdb194..00000000000 --- a/tests/bluetooth/bsim/host/security/bond_overwrite_denied/test_scripts/run_test.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -set -eu -bash_source_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" - -# Read variable definitions output by _env.sh -source <("${bash_source_dir}/_env.sh") - -process_ids="" -exit_code=0 - -function Execute() { - if [ ! -f $1 ]; then - echo -e " \e[91m$(pwd)/$(basename $1) cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 30 $@ & - process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -cd ${BSIM_OUT_PATH}/bin - -Execute "$central_exe" \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central -RealEncryption=1 - -Execute "$peripheral_exe" \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral -RealEncryption=1 - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=60e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/ll/advx/CMakeLists.txt b/tests/bluetooth/bsim/ll/advx/CMakeLists.txt deleted file mode 100644 index c776a344702..00000000000 --- a/tests/bluetooth/bsim/ll/advx/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set\ - the environment variable BSIM_COMPONENTS_PATH to point to its components \ - folder. More information can be found in\ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_advx) - -target_sources(app PRIVATE src/main.c) - -zephyr_include_directories( - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ - ${ZEPHYR_BASE}/subsys/bluetooth/controller/include - ) diff --git a/tests/bluetooth/bsim/ll/advx/prj.conf b/tests/bluetooth/bsim/ll/advx/prj.conf deleted file mode 100644 index 5d097026184..00000000000 --- a/tests/bluetooth/bsim/ll/advx/prj.conf +++ /dev/null @@ -1,19 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_DEVICE_NAME="AdvX" -CONFIG_BT_BROADCASTER=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_OBSERVER=y -CONFIG_BT_CENTRAL=y - -CONFIG_BT_EXT_ADV=y -CONFIG_BT_PER_ADV=y -CONFIG_BT_PER_ADV_SYNC=y - -CONFIG_BT_ID_MAX=2 -CONFIG_BT_EXT_ADV_MAX_ADV_SET=2 -CONFIG_BT_PER_ADV_SYNC_MAX=2 - -CONFIG_BT_CTLR_PRIVACY=y -CONFIG_BT_CTLR_ADV_EXT=y -CONFIG_BT_CTLR_ADV_PERIODIC=y -CONFIG_BT_CTLR_SYNC_PERIODIC=y diff --git a/tests/bluetooth/bsim/ll/advx/src/main.c b/tests/bluetooth/bsim/ll/advx/src/main.c deleted file mode 100644 index a78a1769a86..00000000000 --- a/tests/bluetooth/bsim/ll/advx/src/main.c +++ /dev/null @@ -1,1856 +0,0 @@ -/* main.c - Application main entry point */ - -/* - * Copyright (c) 2015-2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include -#include -#include - -#include -#include - -#include "ll.h" - -#include "bs_types.h" -#include "bs_tracing.h" -#include "time_machine.h" -#include "bstests.h" - -#define HANDLE 0x0000 -#define EVT_PROP_SCAN BIT(1) -#define EVT_PROP_ANON BIT(5) -#define EVT_PROP_TXP BIT(6) -#define ADV_INTERVAL 0x20 /* 20 ms advertising interval */ -#define ADV_WAIT_MS 10 /* 10 ms wait loop */ -#define OWN_ADDR_TYPE BT_ADDR_LE_RANDOM_ID -#define PEER_ADDR_TYPE BT_ADDR_LE_RANDOM_ID -#define PEER_ADDR peer_addr -#define ADV_CHAN_MAP 0x07 -#define FILTER_POLICY 0x00 -#define ADV_TX_PWR NULL -#define ADV_SEC_SKIP 0 -#define ADV_PHY_1M BIT(0) -#define ADV_PHY_2M BIT(1) -#define ADV_PHY_CODED BIT(2) -#define ADV_SID 0x0a -#define SCAN_REQ_NOT 0 - -#define AD_OP 0x03 -#define AD_FRAG_PREF 0x00 - -#define ADV_INTERVAL_PERIODIC 0x30 - -#define SCAN_INTERVAL 0x04 -#define SCAN_WINDOW 0x04 - -#define FAIL(...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, __VA_ARGS__); \ - } while (0) - -extern enum bst_result_t bst_result; - -static uint8_t const own_addr_reenable[] = {0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5}; -static uint8_t const own_addr[] = {0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5}; -static uint8_t const peer_addr[] = {0xc6, 0xc7, 0xc8, 0xc9, 0xc1, 0xcb}; - -static const struct bt_data ad[] = { - BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_NO_BREDR), - }; - -static uint8_t adv_data[] = { - 2, BT_DATA_FLAGS, BT_LE_AD_NO_BREDR, - }; - -static uint8_t adv_data1[] = { - 2, BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR), - 7, BT_DATA_NAME_COMPLETE, 'Z', 'e', 'p', 'h', 'y', 'r', - }; - -static uint8_t adv_data2[] = { - 2, BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR), - }; - -static uint8_t sr_data[] = { - 7, BT_DATA_NAME_COMPLETE, 'Z', 'e', 'p', 'h', 'y', 'r', - }; - -static uint8_t per_adv_data1[] = { - 7, BT_DATA_NAME_COMPLETE, 'Z', 'e', 'p', 'h', 'y', 'r', - }; - -static uint8_t per_adv_data2[] = { - 8, BT_DATA_NAME_COMPLETE, 'Z', 'e', 'p', 'h', 'y', 'r', '1', - }; - -static uint8_t per_adv_data3[] = { - 0xFF, 0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF, 0xBF, - }; - -static uint8_t chan_map[] = { 0x1F, 0XF1, 0x1F, 0xF1, 0x1F }; - -static bool volatile is_scanned, is_connected, is_disconnected; -static bool volatile connection_to_test; -static uint8_t adv_data_expected_len; -static uint8_t *adv_data_expected; - -static void connected(struct bt_conn *conn, uint8_t conn_err) -{ - int err; - - printk("Connected.\n"); - - is_connected = true; - - err = bt_conn_disconnect(conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN); - if (err) { - printk("Disconnection failed (err %d).\n", err); - } -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - printk("Disconnected.\n"); - - is_disconnected = true; -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - -static bool volatile is_sent; -static uint8_t volatile num_sent_actual; - -void sent_cb(struct bt_le_ext_adv *adv, struct bt_le_ext_adv_sent_info *info) -{ - printk("%s: num_sent = %u\n", __func__, info->num_sent); - - is_sent = true; - num_sent_actual = info->num_sent; -} - -void connected_cb(struct bt_le_ext_adv *adv, - struct bt_le_ext_adv_connected_info *info) -{ - printk("%s\n", __func__); -} - -void scanned_cb(struct bt_le_ext_adv *adv, - struct bt_le_ext_adv_scanned_info *info) -{ - printk("%s\n", __func__); -} - -struct bt_le_ext_adv_cb adv_callbacks = { - .sent = sent_cb, - .connected = connected_cb, - .scanned = scanned_cb, -}; - -static void test_advx_main(void) -{ - struct bt_le_ext_adv_start_param ext_adv_param; - struct bt_le_ext_adv *adv; - uint8_t num_sent_expected; - uint16_t evt_prop; - uint8_t adv_type; - uint16_t handle; - uint8_t phy_p; - uint8_t phy_s; - int err; - - printk("\n*Extended Advertising test*\n"); - - printk("Bluetooth initializing..."); - err = bt_enable(NULL); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Connectable advertising..."); - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0); - if (err) { - printk("Advertising failed to start (err %d)\n", err); - return; - } - printk("success.\n"); - - printk("Waiting for connection..."); - while (!is_connected) { - k_sleep(K_MSEC(100)); - } - printk("success.\n"); - - printk("Waiting for disconnect..."); - while (!is_disconnected) { - k_sleep(K_MSEC(100)); - } - printk("success.\n"); - - printk("Stop advertising..."); - err = bt_le_adv_stop(); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("AD Data set..."); - handle = 0U; - err = ll_adv_data_set(handle, sizeof(adv_data), adv_data); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Directed advertising, parameter set..."); - err = ll_adv_params_set(handle, 0, 0, BT_HCI_ADV_DIRECT_IND, - OWN_ADDR_TYPE, PEER_ADDR_TYPE, PEER_ADDR, - ADV_CHAN_MAP, FILTER_POLICY, - 0, 0, 0, 0, 0, 0); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Connectable advertising, parameter set..."); - err = ll_adv_params_set(handle, 0, ADV_INTERVAL, BT_HCI_ADV_NONCONN_IND, - OWN_ADDR_TYPE, PEER_ADDR_TYPE, PEER_ADDR, - ADV_CHAN_MAP, FILTER_POLICY, - 0, 0, 0, 0, 0, 0); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Enabling..."); - err = ll_adv_enable(handle, 1, 0, 0); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(100)); - - printk("Disabling..."); - err = ll_adv_enable(handle, 0, 0, 0); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Directed advertising, parameter set..."); - err = ll_adv_params_set(handle, 0, 0, BT_HCI_ADV_DIRECT_IND, - OWN_ADDR_TYPE, PEER_ADDR_TYPE, PEER_ADDR, - ADV_CHAN_MAP, FILTER_POLICY, - 0, 0, 0, 0, 0, 0); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("AD Data set..."); - handle = 0U; - err = ll_adv_data_set(handle, sizeof(adv_data1), adv_data1); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Connectable advertising, parameter set..."); - err = ll_adv_params_set(handle, 0, ADV_INTERVAL, BT_HCI_ADV_NONCONN_IND, - OWN_ADDR_TYPE, PEER_ADDR_TYPE, PEER_ADDR, - ADV_CHAN_MAP, FILTER_POLICY, - 0, 0, 0, 0, 0, 0); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Enabling..."); - err = ll_adv_enable(handle, 1, 0, 0); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(100)); - - printk("Disabling..."); - err = ll_adv_enable(handle, 0, 0, 0); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Create scannable extended advertising set..."); - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_SCAN_NAME, &adv_callbacks, - &adv); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Start scannable advertising..."); - ext_adv_param.timeout = 0; - ext_adv_param.num_events = 0; - err = bt_le_ext_adv_start(adv, &ext_adv_param); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(500)); - - printk("Stopping scannable advertising..."); - err = bt_le_ext_adv_stop(adv); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Removing scannable adv set..."); - err = bt_le_ext_adv_delete(adv); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Create connectable extended advertising set..."); - is_connected = false; - is_disconnected = false; - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CONN_NAME, &adv_callbacks, &adv); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Start advertising..."); - ext_adv_param.timeout = 0; - ext_adv_param.num_events = 0; - err = bt_le_ext_adv_start(adv, &ext_adv_param); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Waiting for connection..."); - while (!is_connected) { - k_sleep(K_MSEC(100)); - } - printk("success.\n"); - - printk("Waiting for disconnect..."); - while (!is_disconnected) { - k_sleep(K_MSEC(100)); - } - printk("success.\n"); - - printk("Removing connectable adv aux set..."); - err = bt_le_ext_adv_delete(adv); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(1000)); - - printk("Starting non-connectable advertising..."); - err = bt_le_adv_start(BT_LE_ADV_NCONN, ad, ARRAY_SIZE(ad), NULL, 0); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(400)); - - printk("Stopping advertising..."); - err = bt_le_adv_stop(); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(1000)); - - printk("Create connectable advertising set..."); - err = bt_le_ext_adv_create(BT_LE_ADV_CONN_NAME, &adv_callbacks, &adv); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Start advertising using extended commands (max_events)..."); - is_sent = false; - num_sent_actual = 0; - num_sent_expected = 3; - ext_adv_param.timeout = 0; - ext_adv_param.num_events = 3; - err = bt_le_ext_adv_start(adv, &ext_adv_param); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Waiting..."); - while (!is_sent) { - k_sleep(K_MSEC(100)); - } - printk("done.\n"); - - if (num_sent_actual != num_sent_expected) { - FAIL("Num sent actual = %u, expected = %u\n", num_sent_actual, - num_sent_expected); - } - - k_sleep(K_MSEC(1000)); - - printk("Start advertising using extended commands (duration)..."); - is_sent = false; - num_sent_actual = 0; - num_sent_expected = 5; - ext_adv_param.timeout = 50; - ext_adv_param.num_events = 0; - err = bt_le_ext_adv_start(adv, &ext_adv_param); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Waiting..."); - while (!is_sent) { - k_sleep(K_MSEC(100)); - } - printk("done.\n"); - - if (num_sent_actual != num_sent_expected) { - FAIL("Num sent actual = %u, expected = %u\n", num_sent_actual, - num_sent_expected); - } - - k_sleep(K_MSEC(1000)); - - printk("Re-enable advertising using extended commands (max_events)..."); - is_sent = false; - num_sent_actual = 0; - num_sent_expected = 3; - ext_adv_param.timeout = 0; - ext_adv_param.num_events = 3; - err = bt_le_ext_adv_start(adv, &ext_adv_param); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(100)); - - printk("Setting advertising random address before re-enabling..."); - handle = 0x0000; - err = ll_adv_aux_random_addr_set(handle, own_addr_reenable); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Re-enabling..."); - handle = 0x0000; - err = ll_adv_enable(handle, 1, - ext_adv_param.timeout, - ext_adv_param.num_events); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Waiting..."); - while (!is_sent) { - k_sleep(K_MSEC(100)); - } - printk("done.\n"); - - if (num_sent_actual != num_sent_expected) { - FAIL("Num sent actual = %u, expected = %u\n", num_sent_actual, - num_sent_expected); - } - - k_sleep(K_MSEC(1000)); - - printk("Re-enable advertising using extended commands (duration)..."); - is_sent = false; - num_sent_actual = 0; - num_sent_expected = 5; /* 5 advertising events with a spacing of (100 ms + - * random_delay of upto 10 ms) transmit in - * the range of 400 to 440 ms - */ - ext_adv_param.timeout = 50; /* Check there is atmost 5 advertising - * events in a timeout of 500 ms - */ - ext_adv_param.num_events = 0; - err = bt_le_ext_adv_start(adv, &ext_adv_param); - if (err) { - goto exit; - } - printk("success.\n"); - - /* Delay 100 ms, and the test should verify that re-enabling still - * results in correct num of events. - */ - k_sleep(K_MSEC(100)); - - printk("Re-enabling..."); - handle = 0x0000; - err = ll_adv_enable(handle, 1, - ext_adv_param.timeout, - ext_adv_param.num_events); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Waiting..."); - while (!is_sent) { - k_sleep(K_MSEC(100)); - } - printk("done.\n"); - - if (num_sent_actual != num_sent_expected) { - FAIL("Num sent actual = %u, expected = %u\n", num_sent_actual, - num_sent_expected); - } - - k_sleep(K_MSEC(1000)); - - printk("Start advertising using extended commands (disable)..."); - ext_adv_param.timeout = 0; - ext_adv_param.num_events = 5; - err = bt_le_ext_adv_start(adv, &ext_adv_param); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(400)); - - printk("Stopping advertising using extended commands..."); - err = bt_le_ext_adv_stop(adv); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(1000)); - - printk("Setting advertising random address..."); - handle = 0x0000; - err = ll_adv_aux_random_addr_set(handle, own_addr); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Starting non-conn non-scan without aux 1M advertising..."); - evt_prop = EVT_PROP_TXP; - adv_type = 0x07; /* Adv. Ext. */ - phy_p = ADV_PHY_1M; - phy_s = ADV_PHY_2M; - err = ll_adv_params_set(handle, evt_prop, ADV_INTERVAL, adv_type, - OWN_ADDR_TYPE, PEER_ADDR_TYPE, PEER_ADDR, - ADV_CHAN_MAP, FILTER_POLICY, ADV_TX_PWR, - phy_p, ADV_SEC_SKIP, phy_s, ADV_SID, - SCAN_REQ_NOT); - if (err) { - goto exit; - } - - printk("enabling..."); - err = ll_adv_enable(handle, 1, 0, 0); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(400)); - - printk("Disabling..."); - err = ll_adv_enable(handle, 0, 0, 0); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(1000)); - - printk("Enabling non-conn non-scan without aux 1M advertising..."); - err = ll_adv_enable(handle, 1, 0, 0); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(400)); - - printk("Adding data, so non-conn non-scan with aux 1M advertising..."); - err = ll_adv_aux_ad_data_set(handle, AD_OP, AD_FRAG_PREF, - sizeof(adv_data), (void *)adv_data); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(400)); - - printk("Update advertising data 1..."); - err = ll_adv_aux_ad_data_set(handle, AD_OP, AD_FRAG_PREF, - sizeof(adv_data1), (void *)adv_data1); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(400)); - - printk("Update advertising data 2..."); - err = ll_adv_aux_ad_data_set(handle, AD_OP, AD_FRAG_PREF, - sizeof(adv_data2), (void *)adv_data2); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(400)); - - printk("Starting directed advertising..."); - const bt_addr_le_t direct_addr = { - .type = BT_ADDR_LE_RANDOM, - .a = { - .val = {0x11, 0x22, 0x33, 0x44, 0x55, 0xC6} - } - }; - const struct bt_le_adv_param adv_param = { - .options = BT_LE_ADV_OPT_CONNECTABLE, - .peer = &direct_addr, - }; - err = bt_le_adv_start(&adv_param, NULL, 0, NULL, 0); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(2000)); - - printk("Disabling..."); - err = ll_adv_enable(handle, 0, 0, 0); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(1000)); - - printk("Add to resolving list..."); - bt_addr_le_t peer_id_addr = { - .type = BT_ADDR_LE_RANDOM, - .a = { - .val = {0xc6, 0xc7, 0xc8, 0xc9, 0xc1, 0xcb} - } - }; - uint8_t pirk[16] = {0x00, }; - uint8_t lirk[16] = {0x01, }; - - err = ll_rl_add(&peer_id_addr, pirk, lirk); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Enable resolving list..."); - err = ll_rl_enable(BT_HCI_ADDR_RES_ENABLE); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Enabling extended..."); - err = ll_adv_enable(handle, 1, 0, 0); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(400)); - - printk("Starting periodic 1M advertising..."); - err = ll_adv_sync_param_set(handle, ADV_INTERVAL_PERIODIC, 0); - if (err) { - goto exit; - } - - printk("enabling periodic..."); - err = ll_adv_sync_enable(handle, BT_HCI_LE_SET_PER_ADV_ENABLE_ENABLE); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(400)); - - printk("Update advertising data 1..."); - err = ll_adv_aux_ad_data_set(handle, AD_OP, AD_FRAG_PREF, - sizeof(adv_data1), (void *)adv_data1); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(400)); - - printk("Update advertising data 2..."); - err = ll_adv_aux_ad_data_set(handle, AD_OP, AD_FRAG_PREF, - sizeof(adv_data2), (void *)adv_data2); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(400)); - - printk("Update periodic advertising data 1..."); - err = ll_adv_sync_ad_data_set(handle, AD_OP, sizeof(per_adv_data1), - (void *)per_adv_data1); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(400)); - - printk("Update periodic advertising data 2..."); - err = ll_adv_sync_ad_data_set(handle, AD_OP, sizeof(per_adv_data2), - (void *)per_adv_data2); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(400)); - - printk("Update periodic advertising data 3..."); - err = ll_adv_sync_ad_data_set(handle, AD_OP, sizeof(per_adv_data3), - (void *)per_adv_data3); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(400)); - - printk("Update periodic advertising back to data 2..."); - err = ll_adv_sync_ad_data_set(handle, AD_OP, sizeof(per_adv_data2), - (void *)per_adv_data2); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(400)); - - printk("Disabling..."); - err = ll_adv_enable(handle, 0, 0, 0); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Periodic Advertising Channel Map Indication..."); - err = ll_chm_update(chan_map); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(400)); - - printk("Disabling periodic..."); - err = ll_adv_sync_enable(handle, 0); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(1000)); - - printk("enabling periodic..."); - err = ll_adv_sync_enable(handle, - (BT_HCI_LE_SET_PER_ADV_ENABLE_ENABLE | - BT_HCI_LE_SET_PER_ADV_ENABLE_ADI)); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Enabling extended..."); - err = ll_adv_enable(handle, 1, 0, 0); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(400)); - - printk("Update periodic advertising data (duplicate filter)..."); - err = ll_adv_sync_ad_data_set(handle, AD_OP, sizeof(per_adv_data3), - (void *)per_adv_data3); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(1000)); - - printk("Disabling periodic..."); - err = ll_adv_sync_enable(handle, 0); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(400)); - - printk("Disabling..."); - err = ll_adv_enable(handle, 0, 0, 0); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(1000)); - - printk("Adding scan response data on non-scannable set..."); - err = ll_adv_aux_sr_data_set(handle, AD_OP, AD_FRAG_PREF, - sizeof(sr_data), (void *)sr_data); - if (err != BT_HCI_ERR_INVALID_PARAM) { - goto exit; - } - printk("success.\n"); - - printk("Removing adv aux set that's created and disabled ..."); - err = ll_adv_aux_set_remove(handle); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Creating new adv set (scannable)..."); - err = ll_adv_params_set(handle, EVT_PROP_SCAN, ADV_INTERVAL, adv_type, - OWN_ADDR_TYPE, PEER_ADDR_TYPE, PEER_ADDR, - ADV_CHAN_MAP, FILTER_POLICY, ADV_TX_PWR, - phy_p, ADV_SEC_SKIP, phy_s, ADV_SID, - SCAN_REQ_NOT); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Adding scan response data..."); - err = ll_adv_aux_sr_data_set(handle, AD_OP, AD_FRAG_PREF, - sizeof(sr_data), (void *)sr_data); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Enabling non-conn scan with scan response data..."); - err = ll_adv_enable(handle, 1, 0, 0); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(400)); - - printk("Disabling..."); - err = ll_adv_enable(handle, 0, 0, 0); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(1000)); - - printk("Removing adv aux set that's created and disabled ..."); - err = ll_adv_aux_set_remove(handle); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Removing adv aux set that's not created ..."); - err = ll_adv_aux_set_remove(handle); - if (err != BT_HCI_ERR_UNKNOWN_ADV_IDENTIFIER) { - goto exit; - } - printk("success.\n"); - - printk("Creating new adv set..."); - err = ll_adv_params_set(handle, evt_prop, ADV_INTERVAL, adv_type, - OWN_ADDR_TYPE, PEER_ADDR_TYPE, PEER_ADDR, - ADV_CHAN_MAP, FILTER_POLICY, ADV_TX_PWR, - phy_p, ADV_SEC_SKIP, phy_s, ADV_SID, - SCAN_REQ_NOT); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Update advertising data 2..."); - err = ll_adv_aux_ad_data_set(handle, AD_OP, AD_FRAG_PREF, - sizeof(adv_data2), (void *)adv_data2); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Enabling adv set..."); - err = ll_adv_enable(handle, 1, 0, 0); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(400)); - - printk("Removing adv aux set that's created and enabled ..."); - err = ll_adv_aux_set_remove(handle); - if (err != BT_HCI_ERR_CMD_DISALLOWED) { - goto exit; - } - printk("success.\n"); - - printk("Disabling adv set..."); - err = ll_adv_enable(handle, 0, 0, 0); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Removing adv aux set that's created and disabled ..."); - err = ll_adv_aux_set_remove(handle); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Creating new adv set..."); - err = ll_adv_params_set(handle, evt_prop, ADV_INTERVAL, adv_type, - OWN_ADDR_TYPE, PEER_ADDR_TYPE, PEER_ADDR, - ADV_CHAN_MAP, FILTER_POLICY, ADV_TX_PWR, - phy_p, ADV_SEC_SKIP, phy_s, ADV_SID, - SCAN_REQ_NOT); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Starting periodic 1M advertising..."); - err = ll_adv_sync_param_set(handle, ADV_INTERVAL_PERIODIC, 0); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("enabling periodic..."); - err = ll_adv_sync_enable(handle, BT_HCI_LE_SET_PER_ADV_ENABLE_ENABLE); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Trying to remove an adv set with sync enabled ..."); - err = ll_adv_aux_set_remove(handle); - if (err != BT_HCI_ERR_CMD_DISALLOWED) { - goto exit; - } - printk("success.\n"); - - printk("Disabling periodic..."); - err = ll_adv_sync_enable(handle, 0); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Trying to remove an adv set after sync disabled ..."); - err = ll_adv_aux_set_remove(handle); - if (err) { - goto exit; - } - printk("success.\n"); - - uint8_t num_adv_sets; - num_adv_sets = ll_adv_aux_set_count_get(); - - printk("Creating every other adv set ..."); - for (handle = 0; handle < num_adv_sets; handle += 2) { - err = ll_adv_params_set(handle, evt_prop, ADV_INTERVAL, adv_type, - OWN_ADDR_TYPE, PEER_ADDR_TYPE, PEER_ADDR, - ADV_CHAN_MAP, FILTER_POLICY, ADV_TX_PWR, - phy_p, ADV_SEC_SKIP, phy_s, ADV_SID, - SCAN_REQ_NOT); - if (err) { - goto exit; - } - } - printk("success.\n"); - - printk("Clearing all adv sets..."); - err = ll_adv_aux_set_clear(); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Trying to remove adv sets ..."); - for (handle = 0; handle < num_adv_sets; ++handle) { - err = ll_adv_aux_set_remove(handle); - if (err != BT_HCI_ERR_UNKNOWN_ADV_IDENTIFIER) { - goto exit; - } - } - printk("success.\n"); - - printk("Creating one adv set ..."); - handle = 0; - err = ll_adv_params_set(handle, evt_prop, ADV_INTERVAL, adv_type, - OWN_ADDR_TYPE, PEER_ADDR_TYPE, PEER_ADDR, - ADV_CHAN_MAP, FILTER_POLICY, ADV_TX_PWR, - phy_p, ADV_SEC_SKIP, phy_s, ADV_SID, - SCAN_REQ_NOT); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Enabling adv set..."); - err = ll_adv_enable(handle, 1, 0, 0); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Clearing all adv sets..."); - err = ll_adv_aux_set_clear(); - if (err != BT_HCI_ERR_CMD_DISALLOWED) { - goto exit; - } - printk("success.\n"); - - PASS("AdvX tests Passed\n"); - bs_trace_silent_exit(0); - - return; - -exit: - printk("failed (%d)\n", err); - - bst_result = Failed; - bs_trace_silent_exit(0); -} - - -static bool is_reenable_addr; - -static void scan_cb(const bt_addr_le_t *addr, int8_t rssi, uint8_t adv_type, - struct net_buf_simple *buf) -{ - char le_addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(addr, le_addr, sizeof(le_addr)); - printk("%s: type = 0x%x, addr = %s\n", __func__, adv_type, le_addr); - - if (!is_reenable_addr && - !memcmp(own_addr_reenable, addr->a.val, - sizeof(own_addr_reenable))) { - is_reenable_addr = true; - } - - if (connection_to_test) { - struct bt_conn *conn; - int err; - - connection_to_test = false; - - err = bt_le_scan_stop(); - if (err) { - printk("Stop LE scan failed (err %d)\n", err); - return; - } - - err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, - BT_LE_CONN_PARAM_DEFAULT, - &conn); - if (err) { - printk("Create conn failed (err %d)\n", err); - } else { - bt_conn_unref(conn); - } - } else if (!is_scanned) { - char addr_str[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(addr, addr_str, sizeof(addr_str)); - printk("Device found: %s, type: %u, AD len: %u, RSSI %d\n", - addr_str, adv_type, buf->len, rssi); - - if ((buf->len == adv_data_expected_len) && - !memcmp(buf->data, adv_data_expected, - adv_data_expected_len)) { - is_scanned = true; - } - } -} - -static const char *phy2str(uint8_t phy) -{ - switch (phy) { - case 0: return "No packets"; - case BT_GAP_LE_PHY_1M: return "LE 1M"; - case BT_GAP_LE_PHY_2M: return "LE 2M"; - case BT_GAP_LE_PHY_CODED: return "LE Coded"; - default: return "Unknown"; - } -} - -#define NAME_LEN 30 - -static bool data_cb(struct bt_data *data, void *user_data) -{ - char *name = user_data; - - switch (data->type) { - case BT_DATA_NAME_SHORTENED: - case BT_DATA_NAME_COMPLETE: - memcpy(name, data->data, MIN(data->data_len, NAME_LEN - 1)); - return false; - default: - return true; - } -} - -static bool is_scannable; -static bool is_scan_rsp; -static bool is_periodic; -static uint8_t per_sid; -static bt_addr_le_t per_addr; -static uint8_t per_adv_evt_cnt_actual; - -static void scan_recv(const struct bt_le_scan_recv_info *info, - struct net_buf_simple *buf) -{ - char le_addr[BT_ADDR_LE_STR_LEN]; - char name[NAME_LEN]; - - (void)memset(name, 0, sizeof(name)); - - bt_data_parse(buf, data_cb, name); - - bt_addr_le_to_str(info->addr, le_addr, sizeof(le_addr)); - printk("[DEVICE]: %s, AD evt type %u, Tx Pwr: %i, RSSI %i %s " - "C:%u S:%u D:%u SR:%u E:%u Prim: %s, Secn: %s, " - "Interval: 0x%04x (%u ms), SID: %u\n", - le_addr, info->adv_type, info->tx_power, info->rssi, name, - (info->adv_props & BT_GAP_ADV_PROP_CONNECTABLE) != 0, - (info->adv_props & BT_GAP_ADV_PROP_SCANNABLE) != 0, - (info->adv_props & BT_GAP_ADV_PROP_DIRECTED) != 0, - (info->adv_props & BT_GAP_ADV_PROP_SCAN_RESPONSE) != 0, - (info->adv_props & BT_GAP_ADV_PROP_EXT_ADV) != 0, - phy2str(info->primary_phy), phy2str(info->secondary_phy), - info->interval, info->interval * 5 / 4, info->sid); - - if (!is_scannable && - ((info->adv_props & BT_GAP_ADV_PROP_SCANNABLE) != 0)) { - is_scannable = true; - } - - if (!is_scan_rsp && - ((info->adv_props & BT_GAP_ADV_PROP_SCANNABLE) != 0) && - ((info->adv_props & BT_GAP_ADV_PROP_SCAN_RESPONSE) != 0) && - (strlen(name) == strlen(CONFIG_BT_DEVICE_NAME)) && - (!strcmp(name, CONFIG_BT_DEVICE_NAME))) { - is_scan_rsp = true; - } - - if (info->interval) { - if (!is_periodic) { - is_periodic = true; - per_sid = info->sid; - bt_addr_le_copy(&per_addr, info->addr); - } else { - if ((per_sid == info->sid) && - bt_addr_le_eq(&per_addr, info->addr)) { - per_adv_evt_cnt_actual++; - - printk("per_adv_evt_cnt_actual %u\n", - per_adv_evt_cnt_actual); - } - } - } -} - -static bool is_scan_timeout; - -static void scan_timeout(void) -{ - is_scan_timeout = true; -} - -static struct bt_le_scan_cb scan_callbacks = { - .recv = scan_recv, - .timeout = scan_timeout, -}; - -static bool volatile is_sync; -static bool volatile is_sync_report; -static bool volatile is_sync_lost; -static uint8_t volatile sync_report_len; -static uint8_t sync_report_data[251]; - -static void -per_adv_sync_sync_cb(struct bt_le_per_adv_sync *sync, - struct bt_le_per_adv_sync_synced_info *info) -{ - char le_addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(info->addr, le_addr, sizeof(le_addr)); - - printk("PER_ADV_SYNC[%u]: [DEVICE]: %s synced, " - "Interval 0x%04x (%u ms), PHY %s\n", - bt_le_per_adv_sync_get_index(sync), le_addr, - info->interval, info->interval * 5 / 4, phy2str(info->phy)); - - is_sync = true; -} - -static void -per_adv_sync_terminated_cb(struct bt_le_per_adv_sync *sync, - const struct bt_le_per_adv_sync_term_info *info) -{ - char le_addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(info->addr, le_addr, sizeof(le_addr)); - - printk("PER_ADV_SYNC[%u]: [DEVICE]: %s sync terminated\n", - bt_le_per_adv_sync_get_index(sync), le_addr); - - is_sync_lost = true; -} - -static void -per_adv_sync_recv_cb(struct bt_le_per_adv_sync *sync, - const struct bt_le_per_adv_sync_recv_info *info, - struct net_buf_simple *buf) -{ - char le_addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(info->addr, le_addr, sizeof(le_addr)); - - printk("PER_ADV_SYNC[%u]: [DEVICE]: %s, tx_power %i, " - "RSSI %i, CTE %u, data length %u\n", - bt_le_per_adv_sync_get_index(sync), le_addr, info->tx_power, - info->rssi, info->cte_type, buf->len); - - if (!is_sync_report) { - is_sync_report = true; - sync_report_len = buf->len; - memcpy(sync_report_data, buf->data, buf->len); - } -} - -static struct bt_le_per_adv_sync_cb sync_cb = { - .synced = per_adv_sync_sync_cb, - .term = per_adv_sync_terminated_cb, - .recv = per_adv_sync_recv_cb -}; - -static void test_scanx_main(void) -{ - struct bt_le_scan_param scan_param = { - .type = BT_HCI_LE_SCAN_ACTIVE, - .options = BT_LE_SCAN_OPT_NONE, - .interval = 0x0004, - .window = 0x0004, - }; - struct bt_le_per_adv_sync_param sync_create_param; - struct bt_le_per_adv_sync *sync = NULL; - uint8_t per_adv_evt_cnt_expected; - uint8_t sync_report_len_prev; - int err; - - printk("\n*Extended Scanning test*\n"); - - printk("Bluetooth initializing..."); - err = bt_enable(NULL); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Scan callbacks register..."); - bt_le_scan_cb_register(&scan_callbacks); - printk("success.\n"); - - printk("Periodic Advertising callbacks register..."); - bt_le_per_adv_sync_cb_register(&sync_cb); - printk("Success.\n"); - - connection_to_test = true; - - printk("Start scanning..."); - is_reenable_addr = false; - err = bt_le_scan_start(&scan_param, scan_cb); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Waiting for connection..."); - while (!is_connected) { - k_sleep(K_MSEC(100)); - } - printk("success.\n"); - - printk("Waiting for disconnect..."); - while (!is_disconnected) { - k_sleep(K_MSEC(100)); - } - printk("success.\n"); - - is_connected = false; - is_disconnected = false; - connection_to_test = false; - - printk("Start scanning..."); - adv_data_expected = adv_data; - adv_data_expected_len = sizeof(adv_data); - err = bt_le_scan_start(&scan_param, scan_cb); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Waiting for advertising report, switch back from directed..."); - while (!is_scanned) { - k_sleep(K_MSEC(100)); - } - printk("success.\n"); - - printk("Waiting for advertising report, data update while directed..."); - adv_data_expected = adv_data1; - adv_data_expected_len = sizeof(adv_data1); - is_scanned = false; - while (!is_scanned) { - k_sleep(K_MSEC(100)); - } - printk("success.\n"); - - printk("Stop scanning..."); - err = bt_le_scan_stop(); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Start scanning..."); - is_scannable = false; - is_scan_rsp = false; - err = bt_le_scan_start(&scan_param, scan_cb); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Waiting for scannable advertising report...\n"); - while (!is_scannable) { - k_sleep(K_MSEC(100)); - } - printk("success.\n"); - - printk("Waiting for scan response advertising report...\n"); - while (!is_scan_rsp) { - k_sleep(K_MSEC(100)); - } - printk("success.\n"); - - /* This wait is to ensure we match with connectable advertising in the - * advertiser's timeline. - */ - k_sleep(K_MSEC(500)); - - connection_to_test = true; - - printk("Waiting for connection..."); - while (!is_connected) { - k_sleep(K_MSEC(100)); - } - printk("success.\n"); - - printk("Waiting for disconnect..."); - while (!is_disconnected) { - k_sleep(K_MSEC(100)); - } - printk("success.\n"); - - printk("Start scanning for a duration..."); - is_scan_timeout = false; - scan_param.interval = 0x08; - scan_param.timeout = 100; - err = bt_le_scan_start(&scan_param, scan_cb); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(scan_param.timeout * 10 + 10)); - - printk("Checking for scan timeout..."); - if (!is_scan_timeout) { - err = -EIO; - goto exit; - } - printk("done.\n"); - - printk("Start continuous scanning for a duration..."); - is_scan_timeout = false; - scan_param.interval = 0x04; - err = bt_le_scan_start(&scan_param, scan_cb); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(scan_param.timeout * 10 + 10)); - - printk("Checking for scan timeout..."); - if (!is_scan_timeout) { - err = -EIO; - goto exit; - } - printk("done.\n"); - - scan_param.timeout = 0; - - k_sleep(K_MSEC(2000)); - - printk("Start scanning for Periodic Advertisements..."); - is_periodic = false; - is_reenable_addr = false; - per_adv_evt_cnt_actual = 0; - per_adv_evt_cnt_expected = 3; - err = bt_le_scan_start(&scan_param, scan_cb); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Verify address update due to re-enable of advertising..."); - while (!is_reenable_addr) { - k_sleep(K_MSEC(30)); - } - printk("success.\n"); - - printk("Waiting..."); - while (!is_periodic || - (per_adv_evt_cnt_actual != per_adv_evt_cnt_expected)) { - k_sleep(K_MSEC(ADV_WAIT_MS)); - } - printk("done.\n"); - - printk("Stop scanning..."); - err = bt_le_scan_stop(); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Creating Periodic Advertising Sync 0..."); - bt_addr_le_copy(&sync_create_param.addr, &per_addr); - sync_create_param.options = 0; - sync_create_param.sid = 0xf; - sync_create_param.skip = 0; - sync_create_param.timeout = 0xa; - err = bt_le_per_adv_sync_create(&sync_create_param, &sync); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Check duplicate Periodic Advertising Sync create before sync " - "established event..."); - err = bt_le_per_adv_sync_create(&sync_create_param, &sync); - if (!err) { - goto exit; - } - printk("success.\n"); - - printk("Start scanning..."); - err = bt_le_scan_start(&scan_param, scan_cb); - if (err) { - goto exit; - } - printk("success.\n"); - - k_sleep(K_MSEC(400)); - - printk("Canceling Periodic Advertising Sync 0 while scanning..."); - err = bt_le_per_adv_sync_delete(sync); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Stop scanning..."); - err = bt_le_scan_stop(); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Creating Periodic Advertising Sync 1..."); - bt_addr_le_copy(&sync_create_param.addr, &per_addr); - sync_create_param.options = 0; - sync_create_param.sid = 0xf; - sync_create_param.skip = 0; - sync_create_param.timeout = 0xa; - err = bt_le_per_adv_sync_create(&sync_create_param, &sync); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Canceling Periodic Advertising Sync 1 without scanning..."); - err = bt_le_per_adv_sync_delete(sync); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Creating Periodic Advertising Sync 2..."); - is_sync = false; - bt_addr_le_copy(&sync_create_param.addr, &per_addr); - sync_create_param.options = 0; - sync_create_param.sid = per_sid; - sync_create_param.skip = 0; - sync_create_param.timeout = 0xa; - err = bt_le_per_adv_sync_create(&sync_create_param, &sync); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Start scanning..."); - err = bt_le_scan_start(&scan_param, scan_cb); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Waiting for sync..."); - while (!is_sync) { - k_sleep(K_MSEC(100)); - } - printk("done.\n"); - - printk("Check duplicate Periodic Advertising Sync create after sync " - "established event..."); - err = bt_le_per_adv_sync_create(&sync_create_param, &sync); - if (!err) { - goto exit; - } - printk("success.\n"); - - printk("Deleting Periodic Advertising Sync 2..."); - err = bt_le_per_adv_sync_delete(sync); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Stop scanning..."); - err = bt_le_scan_stop(); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Creating Periodic Advertising Sync 3, test sync lost..."); - is_sync = false; - is_sync_report = false; - sync_report_len = 0; - is_sync_lost = false; - bt_addr_le_copy(&sync_create_param.addr, &per_addr); - sync_create_param.options = 0; - sync_create_param.sid = per_sid; - sync_create_param.skip = 0; - sync_create_param.timeout = 0xa; - err = bt_le_per_adv_sync_create(&sync_create_param, &sync); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Start scanning..."); - err = bt_le_scan_start(&scan_param, scan_cb); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Waiting for sync..."); - while (!is_sync) { - k_sleep(K_MSEC(100)); - } - printk("done.\n"); - - printk("Stop scanning..."); - err = bt_le_scan_stop(); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Waiting for Periodic Advertising Report of 0 bytes..."); - while (!is_sync_report) { - k_sleep(K_MSEC(100)); - } - printk("done.\n"); - - if (sync_report_len != 0) { - FAIL("Incorrect Periodic Advertising Report data."); - } - - printk("Waiting for Periodic Advertising Report of %u bytes...", - sizeof(per_adv_data1)); - sync_report_len_prev = sync_report_len; - while (!is_sync_report || (sync_report_len == sync_report_len_prev)) { - is_sync_report = false; - k_sleep(K_MSEC(100)); - } - printk("done.\n"); - - if ((sync_report_len != sizeof(per_adv_data1)) || - memcmp(sync_report_data, per_adv_data1, sizeof(per_adv_data1))) { - FAIL("Incorrect Periodic Advertising Report data."); - } - - printk("Waiting for Periodic Advertising Report of %u bytes...", - sizeof(per_adv_data2)); - sync_report_len_prev = sync_report_len; - while (!is_sync_report || (sync_report_len == sync_report_len_prev)) { - is_sync_report = false; - k_sleep(K_MSEC(100)); - } - printk("done.\n"); - - if ((sync_report_len != sizeof(per_adv_data2)) || - memcmp(sync_report_data, per_adv_data2, sizeof(per_adv_data2))) { - FAIL("Incorrect Periodic Advertising Report data."); - } - - printk("Waiting for Periodic Advertising Report of %u bytes...", - sizeof(per_adv_data3)); - sync_report_len_prev = sync_report_len; - while (!is_sync_report || (sync_report_len == sync_report_len_prev)) { - is_sync_report = false; - k_sleep(K_MSEC(100)); - } - printk("done.\n"); - - if ((sync_report_len != sizeof(per_adv_data3)) || - memcmp(sync_report_data, per_adv_data3, sizeof(per_adv_data3))) { - FAIL("Incorrect Periodic Advertising Report data."); - } - - printk("Waiting for Periodic Advertising Report of %u bytes...", - sizeof(per_adv_data2)); - sync_report_len_prev = sync_report_len; - while (!is_sync_report || (sync_report_len == sync_report_len_prev)) { - is_sync_report = false; - k_sleep(K_MSEC(100)); - } - printk("done.\n"); - - if ((sync_report_len != sizeof(per_adv_data2)) || - memcmp(sync_report_data, per_adv_data2, sizeof(per_adv_data2))) { - FAIL("Incorrect Periodic Advertising Report data."); - } - - printk("Waiting for sync loss..."); - while (!is_sync_lost) { - k_sleep(K_MSEC(100)); - } - printk("done.\n"); - - printk("Add to resolving list..."); - bt_addr_le_t peer_id_addr = { - .type = BT_ADDR_LE_RANDOM, - .a = { - .val = {0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5} - } - }; - uint8_t pirk[16] = {0x01, }; - uint8_t lirk[16] = {0x00, }; - - err = ll_rl_add(&peer_id_addr, pirk, lirk); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Enable resolving list..."); - err = ll_rl_enable(BT_HCI_ADDR_RES_ENABLE); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Add device to periodic advertising list..."); - err = bt_le_per_adv_list_add(&peer_id_addr, per_sid); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Creating Periodic Advertising Sync 4 after sync lost..."); - is_sync = false; - is_sync_report = false; - bt_addr_le_copy(&sync_create_param.addr, &per_addr); - sync_create_param.options = BT_LE_PER_ADV_SYNC_OPT_USE_PER_ADV_LIST | - BT_LE_PER_ADV_SYNC_OPT_FILTER_DUPLICATE; - sync_create_param.sid = per_sid; - sync_create_param.skip = 0; - sync_create_param.timeout = 0xa; - err = bt_le_per_adv_sync_create(&sync_create_param, &sync); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Start scanning..."); - err = bt_le_scan_start(&scan_param, scan_cb); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Waiting for sync..."); - while (!is_sync) { - k_sleep(K_MSEC(100)); - } - printk("done.\n"); - - printk("Stop scanning..."); - err = bt_le_scan_stop(); - if (err) { - goto exit; - } - printk("success.\n"); - - printk("Waiting for Periodic Advertising Report of %u bytes...", - sizeof(per_adv_data3)); - sync_report_len_prev = sync_report_len; - while (!is_sync_report || (sync_report_len == sync_report_len_prev)) { - is_sync_report = false; - k_sleep(K_MSEC(100)); - } - printk("done.\n"); - - if ((sync_report_len != sizeof(per_adv_data3)) || - memcmp(sync_report_data, per_adv_data3, sizeof(per_adv_data3))) { - FAIL("Incorrect Periodic Advertising Report data (%u != %u).", - sync_report_len, sizeof(per_adv_data3)); - } - - printk("Wait for no duplicate Periodic Advertising Report" - " is generated..."); - is_sync_report = false; - k_sleep(K_MSEC(400)); - if (is_sync_report) { - goto exit; - } - printk("success\n"); - - printk("Deleting Periodic Advertising Sync 4..."); - err = bt_le_per_adv_sync_delete(sync); - if (err) { - goto exit; - } - printk("success.\n"); - - PASS("ScanX tests Passed\n"); - - return; - -exit: - printk("failed (%d)\n", err); - - bst_result = Failed; - bs_trace_silent_exit(0); -} - -static void test_advx_init(void) -{ - bst_ticker_set_next_tick_absolute(30e6); - bst_result = In_progress; -} - -static void test_advx_tick(bs_time_t HW_device_time) -{ - bst_result = Failed; - bs_trace_error_line("Test advx/scanx finished.\n"); -} - -static const struct bst_test_instance test_def[] = { - { - .test_id = "advx", - .test_descr = "Extended Advertising", - .test_post_init_f = test_advx_init, - .test_tick_f = test_advx_tick, - .test_main_f = test_advx_main - }, - { - .test_id = "scanx", - .test_descr = "Extended scanning", - .test_post_init_f = test_advx_init, - .test_tick_f = test_advx_tick, - .test_main_f = test_scanx_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_advx_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_def); -} - -bst_test_install_t test_installers[] = { - test_advx_install, - NULL -}; - -void main(void) -{ - bst_main(); -} diff --git a/tests/bluetooth/bsim/ll/advx/tests_scripts/basic_advx.sh b/tests/bluetooth/bsim/ll/advx/tests_scripts/basic_advx.sh deleted file mode 100755 index 5379d8bf700..00000000000 --- a/tests/bluetooth/bsim/ll/advx/tests_scripts/basic_advx.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2018 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -# Basic connection test: a central connects to a peripheral and expects a -# notification, using the split controller (ULL LLL) -simulation_id="basic_advx" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 120 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_ll_advx_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=advx - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_ll_advx_prj_conf\ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=scanx - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=60e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/ll/compile.sh b/tests/bluetooth/bsim/ll/compile.sh deleted file mode 100755 index ede4c74895e..00000000000 --- a/tests/bluetooth/bsim/ll/compile.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -# Compile all the applications needed by the bsim tests - -#set -x #uncomment this line for debugging -set -ue - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" -: "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" -: "${ZEPHYR_BASE:?ZEPHYR_BASE must be set to point to the zephyr root\ - directory}" - -WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_out}" -BOARD="${BOARD:-nrf52_bsim}" -BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" - -mkdir -p ${WORK_DIR} - -source ${ZEPHYR_BASE}/tests/bluetooth/bsim/compile.source - -app=tests/bluetooth/bsim/ll/advx compile - -app=tests/bluetooth/bsim/ll/conn conf_file=prj_split.conf compile -app=tests/bluetooth/bsim/ll/conn conf_file=prj_split_privacy.conf compile -app=tests/bluetooth/bsim/ll/conn conf_file=prj_split_low_lat.conf compile - -app=tests/bluetooth/bsim/ll/iso compile -app=tests/bluetooth/bsim/ll/iso conf_file=prj_vs_dp.conf compile - -app=tests/bluetooth/bsim/ll/edtt/hci_test_app \ - conf_file=prj_dut_llcp.conf compile -app=tests/bluetooth/bsim/ll/edtt/hci_test_app \ - conf_file=prj_tst_llcp.conf compile -app=tests/bluetooth/bsim/ll/edtt/hci_test_app \ - conf_file=prj_dut.conf compile -app=tests/bluetooth/bsim/ll/edtt/hci_test_app \ - conf_file=prj_tst.conf compile -app=tests/bluetooth/bsim/ll/edtt/gatt_test_app \ - conf_file=prj.conf compile -app=tests/bluetooth/bsim/ll/edtt/gatt_test_app \ - conf_file=prj_llcp.conf compile - -wait_for_background_jobs diff --git a/tests/bluetooth/bsim/ll/conn/CMakeLists.txt b/tests/bluetooth/bsim/ll/conn/CMakeLists.txt deleted file mode 100644 index 3bab6789565..00000000000 --- a/tests/bluetooth/bsim/ll/conn/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set\ - the environment variable BSIM_COMPONENTS_PATH to point to its components \ - folder. More information can be found in\ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_app) - -target_sources(app PRIVATE - src/main.c - src/test_empty.c - src/test_connect1.c - src/test_connect2.c -) - -zephyr_include_directories( - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ - ${ZEPHYR_BASE}/samples/bluetooth -) diff --git a/tests/bluetooth/bsim/ll/conn/README.txt b/tests/bluetooth/bsim/ll/conn/README.txt deleted file mode 100644 index 4d14ee4a621..00000000000 --- a/tests/bluetooth/bsim/ll/conn/README.txt +++ /dev/null @@ -1,5 +0,0 @@ -Zephyr test application which uses the simulated boards test hooks. -Can be compiled targeting the *_bsim boards. - -This application will, based on the command line arguments, select one of -testcases which are compiled with it. diff --git a/tests/bluetooth/bsim/ll/conn/prj_split.conf b/tests/bluetooth/bsim/ll/conn/prj_split.conf deleted file mode 100644 index 0110eabfd48..00000000000 --- a/tests/bluetooth/bsim/ll/conn/prj_split.conf +++ /dev/null @@ -1,18 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_DEBUG_LOG=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_PRIVACY=y -CONFIG_BT_SMP=y -CONFIG_BT_SIGNING=y -CONFIG_BT_BAS=y -CONFIG_BT_HRS=y -CONFIG_BT_ATT_PREPARE_COUNT=2 -CONFIG_BT_GATT_CLIENT=y -CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y -CONFIG_BT_TINYCRYPT_ECC=y -CONFIG_BT_DEVICE_NAME="bsim_test_split" -CONFIG_BT_L2CAP_TX_BUF_COUNT=6 - -CONFIG_BT_LL_SW_SPLIT=y -CONFIG_BT_CTLR_PRIVACY=n diff --git a/tests/bluetooth/bsim/ll/conn/prj_split_low_lat.conf b/tests/bluetooth/bsim/ll/conn/prj_split_low_lat.conf deleted file mode 100644 index 8b00d30da4f..00000000000 --- a/tests/bluetooth/bsim/ll/conn/prj_split_low_lat.conf +++ /dev/null @@ -1,21 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_DEBUG_LOG=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_PRIVACY=y -CONFIG_BT_SMP=y -CONFIG_BT_SIGNING=y -CONFIG_BT_BAS=y -CONFIG_BT_HRS=y -CONFIG_BT_ATT_PREPARE_COUNT=2 -CONFIG_BT_GATT_CLIENT=y -CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y -CONFIG_BT_TINYCRYPT_ECC=y -CONFIG_BT_DEVICE_NAME="bsim_test_split" -CONFIG_BT_L2CAP_TX_BUF_COUNT=6 - -CONFIG_BT_LL_SW_SPLIT=y -CONFIG_BT_CTLR_PRIVACY=n -CONFIG_BT_CTLR_ADVANCED_FEATURES=y -CONFIG_BT_CTLR_LOW_LAT=y -CONFIG_BT_TICKER_LOW_LAT=y diff --git a/tests/bluetooth/bsim/ll/conn/prj_split_privacy.conf b/tests/bluetooth/bsim/ll/conn/prj_split_privacy.conf deleted file mode 100644 index 5074c0b5ac5..00000000000 --- a/tests/bluetooth/bsim/ll/conn/prj_split_privacy.conf +++ /dev/null @@ -1,17 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_DEBUG_LOG=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_PRIVACY=y -CONFIG_BT_SMP=y -CONFIG_BT_SIGNING=y -CONFIG_BT_BAS=y -CONFIG_BT_HRS=y -CONFIG_BT_ATT_PREPARE_COUNT=2 -CONFIG_BT_GATT_CLIENT=y -CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y -CONFIG_BT_TINYCRYPT_ECC=y -CONFIG_BT_DEVICE_NAME="bsim_test_split" -CONFIG_BT_L2CAP_TX_BUF_COUNT=6 - -CONFIG_BT_LL_SW_SPLIT=y diff --git a/tests/bluetooth/bsim/ll/conn/src/main.c b/tests/bluetooth/bsim/ll/conn/src/main.c deleted file mode 100644 index 28689aaf17e..00000000000 --- a/tests/bluetooth/bsim/ll/conn/src/main.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2018 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bstests.h" - -extern struct bst_test_list *test_empty_install(struct bst_test_list *tests); -extern struct bst_test_list *test_connect1_install(struct bst_test_list *tests); -extern struct bst_test_list *test_connect2_install(struct bst_test_list *tests); - -bst_test_install_t test_installers[] = { - test_empty_install, - test_connect1_install, - test_connect2_install, - NULL -}; - -void main(void) -{ - bst_main(); -} diff --git a/tests/bluetooth/bsim/ll/conn/src/test_connect1.c b/tests/bluetooth/bsim/ll/conn/src/test_connect1.c deleted file mode 100644 index 6916ae6ea8a..00000000000 --- a/tests/bluetooth/bsim/ll/conn/src/test_connect1.c +++ /dev/null @@ -1,417 +0,0 @@ -/* - * Copyright (c) 2015-2016 Intel Corporation - * Copyright (c) 2017-2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include - -#include "bs_types.h" -#include "bs_tracing.h" -#include "time_machine.h" -#include "bstests.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -static struct bt_conn *default_conn; - -static struct bt_uuid_16 uuid = BT_UUID_INIT_16(0); -static struct bt_gatt_discover_params discover_params; -static struct bt_gatt_subscribe_params subscribe_params; - -#define UPDATE_PARAM_INTERVAL_MIN 25 -#define UPDATE_PARAM_INTERVAL_MAX 45 -#define UPDATE_PARAM_LATENCY 1 -#define UPDATE_PARAM_TIMEOUT 250 - -static struct bt_le_conn_param update_params = { - .interval_min = UPDATE_PARAM_INTERVAL_MIN, - .interval_max = UPDATE_PARAM_INTERVAL_MAX, - .latency = UPDATE_PARAM_LATENCY, - .timeout = UPDATE_PARAM_TIMEOUT, -}; - -static bool encrypt_link; - -/* - * Basic connection test: - * We expect to find a connectable peripheral to which we will - * connect. - * - * After connecting, we update connection parameters and channel - * map, and expect to receive 2 notifications. - * If we do, the test case passes. - * If we do not in 5 seconds, the testcase is considered failed - * - * The thread code is mostly a copy of the central_hr sample device - */ - -#define WAIT_TIME 6 /*seconds*/ -extern enum bst_result_t bst_result; - -#define FAIL(...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, __VA_ARGS__); \ - } while (0) - -static void test_con1_init(void) -{ - bst_ticker_set_next_tick_absolute(WAIT_TIME*1e6); - bst_result = In_progress; -} - -static void test_con_encrypted_init(void) -{ - encrypt_link = true; - test_con1_init(); -} - -static void test_con1_tick(bs_time_t HW_device_time) -{ - /* - * If in WAIT_TIME seconds the testcase did not already pass - * (and finish) we consider it failed - */ - if (bst_result != Passed) { - FAIL("test_connect1 failed (not passed after %i seconds)\n", - WAIT_TIME); - } -} - -static uint8_t notify_func(struct bt_conn *conn, - struct bt_gatt_subscribe_params *params, - const void *data, uint16_t length) -{ - static int notify_count; - if (!data) { - printk("[UNSUBSCRIBED]\n"); - params->value_handle = 0U; - return BT_GATT_ITER_STOP; - } - - printk("[NOTIFICATION] data %p length %u\n", data, length); - - if (notify_count++ >= 1) { /* We consider it passed */ - int err; - - /* Disconnect before actually passing */ - err = bt_conn_disconnect(default_conn, - BT_HCI_ERR_REMOTE_USER_TERM_CONN); - if (err) { - FAIL("Disconnection failed (err %d)\n", err); - return BT_GATT_ITER_STOP; - } - - if (bst_result != Failed) { - PASS("Testcase passed\n"); - } - bs_trace_silent_exit(0); - } - - return BT_GATT_ITER_CONTINUE; -} - -static uint8_t discover_func(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - struct bt_gatt_discover_params *params) -{ - int err; - - if (!attr) { - printk("Discover complete\n"); - memset(params, 0, sizeof(*params)); - return BT_GATT_ITER_STOP; - } - - printk("[ATTRIBUTE] handle %u\n", attr->handle); - - if (!bt_uuid_cmp(discover_params.uuid, BT_UUID_HRS)) { - memcpy(&uuid, BT_UUID_HRS_MEASUREMENT, sizeof(uuid)); - discover_params.uuid = &uuid.uuid; - discover_params.start_handle = attr->handle + 1; - discover_params.type = BT_GATT_DISCOVER_CHARACTERISTIC; - - err = bt_gatt_discover(conn, &discover_params); - if (err) { - FAIL("Discover failed (err %d)\n", err); - } - } else if (!bt_uuid_cmp(discover_params.uuid, - BT_UUID_HRS_MEASUREMENT)) { - memcpy(&uuid, BT_UUID_GATT_CCC, sizeof(uuid)); - discover_params.uuid = &uuid.uuid; - discover_params.start_handle = attr->handle + 2; - discover_params.type = BT_GATT_DISCOVER_DESCRIPTOR; - subscribe_params.value_handle = attr->handle + 1; - - err = bt_gatt_discover(conn, &discover_params); - if (err) { - FAIL("Discover failed (err %d)\n", err); - } - } else { - subscribe_params.notify = notify_func; - subscribe_params.value = BT_GATT_CCC_NOTIFY; - subscribe_params.ccc_handle = attr->handle; - - err = bt_gatt_subscribe(conn, &subscribe_params); - if (err && err != -EALREADY) { - FAIL("Subscribe failed (err %d)\n", err); - } else { - printk("[SUBSCRIBED]\n"); - } - - return BT_GATT_ITER_STOP; - } - - return BT_GATT_ITER_STOP; -} - -static void update_conn(struct bt_conn *conn, bool bonded) -{ - int err; - - if (encrypt_link != bonded) { - FAIL("Unexpected bonding status\n"); - return; - } - - printk("Updating connection (bonded: %d)\n", bonded); - - err = bt_conn_le_param_update(conn, &update_params); - if (err) { - FAIL("Parameter update failed (err %d)\n", err); - return; - } -} - -static struct bt_conn_auth_info_cb auth_cb_success = { - .pairing_complete = update_conn, -}; - -static void connected(struct bt_conn *conn, uint8_t conn_err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - int err; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - if (conn_err) { - FAIL("Failed to connect to %s (%u)\n", addr, conn_err); - return; - } - - printk("Connected: %s\n", addr); - - if (conn != default_conn) { - return; - } - - if (encrypt_link) { - k_sleep(K_MSEC(500)); - bt_conn_auth_info_cb_register(&auth_cb_success); - err = bt_conn_set_security(conn, BT_SECURITY_L2); - if (err) { - FAIL("bt_conn_set_security failed (err %d)\n", err); - return; - } - } else { - update_conn(conn, false); - } -} - -static void params_updated(struct bt_conn *conn, uint16_t interval, - uint16_t latency, uint16_t timeout) -{ - uint8_t chm[5] = { 0x11, 0x22, 0x33, 0x44, 0x00 }; - int err; - - if (interval != UPDATE_PARAM_INTERVAL_MAX || - latency != UPDATE_PARAM_LATENCY || - timeout != UPDATE_PARAM_TIMEOUT) { - FAIL("Unexpected connection parameters " - "(interval: %d, latency: %d, timeout: %d)\n", - interval, latency, timeout); - return; - } - - printk("Connection parameters updated " - "(interval: %d, latency: %d, timeout: %d)\n", - interval, latency, timeout); - - err = bt_le_set_chan_map(chm); - if (err) { - FAIL("Channel map update failed (err %d)\n", err); - return; - } - - memcpy(&uuid, BT_UUID_HRS, sizeof(uuid)); - discover_params.uuid = &uuid.uuid; - discover_params.func = discover_func; - discover_params.start_handle = BT_ATT_FIRST_ATTRIBUTE_HANDLE; - discover_params.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE; - discover_params.type = BT_GATT_DISCOVER_PRIMARY; - - err = bt_gatt_discover(conn, &discover_params); - if (err) { - FAIL("Discover failed(err %d)\n", err); - return; - } -} - -static bool eir_found(struct bt_data *data, void *user_data) -{ - bt_addr_le_t *addr = user_data; - int i; - - printk("[AD]: %u data_len %u\n", data->type, data->data_len); - - switch (data->type) { - case BT_DATA_UUID16_SOME: - case BT_DATA_UUID16_ALL: - if (data->data_len % sizeof(uint16_t) != 0U) { - FAIL("AD malformed\n"); - return true; - } - - for (i = 0; i < data->data_len; i += sizeof(uint16_t)) { - struct bt_uuid *uuid; - struct bt_le_conn_param *param; - uint16_t u16; - int err; - - memcpy(&u16, &data->data[i], sizeof(u16)); - uuid = BT_UUID_DECLARE_16(sys_le16_to_cpu(u16)); - if (bt_uuid_cmp(uuid, BT_UUID_HRS)) { - continue; - } - - err = bt_le_scan_stop(); - if (err) { - FAIL("Stop LE scan failed (err %d)\n", err); - continue; - } - - param = BT_LE_CONN_PARAM_DEFAULT; - err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, - param, &default_conn); - if (err) { - printk("Create conn failed (err %d)\n", err); - } - - return false; - } - } - - return true; -} - -static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type, - struct net_buf_simple *ad) -{ - char dev[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(addr, dev, sizeof(dev)); - printk("[DEVICE]: %s, AD evt type %u, AD data len %u, RSSI %i\n", - dev, type, ad->len, rssi); - - /* We're only interested in connectable events */ - if (type == BT_GAP_ADV_TYPE_ADV_IND || - type == BT_GAP_ADV_TYPE_ADV_DIRECT_IND) { - bt_data_parse(ad, eir_found, (void *)addr); - } -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - char addr[BT_ADDR_LE_STR_LEN]; - int err; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - printk("Disconnected: %s (reason 0x%02x)\n", addr, reason); - - if (default_conn != conn) { - return; - } - - bt_conn_unref(default_conn); - default_conn = NULL; - - /* This demo doesn't require active scan */ - err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found); - if (err) { - FAIL("Scanning failed to start (err %d)\n", err); - } -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, - .le_param_updated = params_updated, -}; - -static void test_con1_main(void) -{ - int err; - - err = bt_enable(NULL); - - if (err) { - FAIL("Bluetooth init failed (err %d)\n", err); - return; - } - - printk("Bluetooth initialized\n"); - - err = bt_le_scan_start(BT_LE_SCAN_ACTIVE, device_found); - - if (err) { - FAIL("Scanning failed to start (err %d)\n", err); - return; - } - - printk("Scanning successfully started\n"); -} - -static const struct bst_test_instance test_connect[] = { - { - .test_id = "central", - .test_descr = "Basic connection test. It expects that a " - "peripheral device can be found. The test will " - "pass if it can connect to it, and receive a " - "notification in less than 5 seconds.", - .test_post_init_f = test_con1_init, - .test_tick_f = test_con1_tick, - .test_main_f = test_con1_main - }, - { - .test_id = "central_encrypted", - .test_descr = "Same as central but with an encrypted link", - .test_post_init_f = test_con_encrypted_init, - .test_tick_f = test_con1_tick, - .test_main_f = test_con1_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_connect1_install(struct bst_test_list *tests) -{ - tests = bst_add_tests(tests, test_connect); - return tests; -} diff --git a/tests/bluetooth/bsim/ll/conn/src/test_connect2.c b/tests/bluetooth/bsim/ll/conn/src/test_connect2.c deleted file mode 100644 index e013b914754..00000000000 --- a/tests/bluetooth/bsim/ll/conn/src/test_connect2.c +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright (c) 2015-2016 Intel Corporation - * Copyright (c) 2017-2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include - -#include "bs_types.h" -#include "bs_tracing.h" -#include "time_machine.h" -#include "bstests.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -static struct bt_conn *default_conn; - -/* - * Basic connection test: - * We expect a central to connect to us. - * - * The thread code is mostly a copy of the peripheral_hr sample device - */ - -#define WAIT_TIME 5 /*seconds*/ -extern enum bst_result_t bst_result; - -#define FAIL(...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, __VA_ARGS__); \ - } while (0) - -static void test_con2_init(void) -{ - bst_ticker_set_next_tick_absolute(WAIT_TIME*1e6); - bst_result = In_progress; -} - -static void test_con2_tick(bs_time_t HW_device_time) -{ - /* - * If in WAIT_TIME seconds the testcase did not already pass - * (and finish) we consider it failed - */ - if (bst_result != Passed) { - FAIL("test_connect2 failed (not passed after %i seconds)\n", - WAIT_TIME); - } -} - -static const struct bt_data ad[] = { - BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), - BT_DATA_BYTES(BT_DATA_UUID16_ALL, - BT_UUID_16_ENCODE(BT_UUID_HRS_VAL), - BT_UUID_16_ENCODE(BT_UUID_BAS_VAL), - BT_UUID_16_ENCODE(BT_UUID_CTS_VAL)), -}; - -static void connected(struct bt_conn *conn, uint8_t err) -{ - if (err) { - FAIL("Connection failed (err 0x%02x)\n", err); - } else { - default_conn = bt_conn_ref(conn); - printk("Connected\n"); - } -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - printk("Disconnected (reason 0x%02x)\n", reason); - - if (default_conn) { - bt_conn_unref(default_conn); - default_conn = NULL; - } -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, -}; - -static void bt_ready(void) -{ - int err; - - printk("Bluetooth initialized\n"); - - err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0); - if (err) { - FAIL("Advertising failed to start (err %d)\n", err); - return; - } - - printk("Advertising successfully started\n"); -} - -static void bas_notify(void) -{ - uint8_t battery_level = bt_bas_get_battery_level(); - - battery_level--; - - if (!battery_level) { - battery_level = 100U; - } - - bt_bas_set_battery_level(battery_level); -} - -static void hrs_notify(void) -{ - static uint8_t heartrate = 90U; - - /* Heartrate measurements simulation */ - heartrate++; - if (heartrate == 160U) { - heartrate = 90U; - } - - bt_hrs_notify(heartrate); -} - -static void test_con2_main(void) -{ - static int notify_count; - int err; - - err = bt_enable(NULL); - if (err) { - FAIL("Bluetooth init failed (err %d)\n", err); - return; - } - - bt_ready(); - - /* Implement notification. At the moment there is no suitable way - * of starting delayed work so we do it here - */ - while (1) { - k_sleep(K_SECONDS(1)); - - /* Heartrate measurements simulation */ - hrs_notify(); - - /* Battery level simulation */ - bas_notify(); - - if (notify_count++ == 1) { /* We consider it passed */ - PASS("Testcase passed\n"); - } - } -} - -static const struct bst_test_instance test_connect[] = { - { - .test_id = "peripheral", - .test_descr = "Basic connection test. It expects that a " - "central device can be found. The test will " - "pass if notifications can be sent without " - "crash.", - .test_post_init_f = test_con2_init, - .test_tick_f = test_con2_tick, - .test_main_f = test_con2_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_connect2_install(struct bst_test_list *tests) -{ - tests = bst_add_tests(tests, test_connect); - return tests; -} diff --git a/tests/bluetooth/bsim/ll/conn/src/test_empty.c b/tests/bluetooth/bsim/ll/conn/src/test_empty.c deleted file mode 100644 index 1d03cbaff4d..00000000000 --- a/tests/bluetooth/bsim/ll/conn/src/test_empty.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2018 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include -#include "bs_types.h" -#include "bs_tracing.h" -#include "time_machine.h" -#include "bstests.h" - -/* - * This is just a demo of the test framework facilities - */ - -extern enum bst_result_t bst_result; - -static void test_empty_init(void) -{ - bst_ticker_set_next_tick_absolute(500e3); - bst_result = In_progress; -} - -static void test_empty_tick(bs_time_t HW_device_time) -{ - - bst_result = Failed; - bs_trace_error_line("test: empty demo test finished " - "(failed as it should be)\n"); - -} - -static void test_empty_thread(void *p1, void *p2, void *p3) -{ - int i = 0; - - while (1) { - printk("A silly demo thread. Iteration %i\n", i++); - k_sleep(K_MSEC(100)); - } -} - -static K_THREAD_STACK_DEFINE(stack_te, - CONFIG_ARCH_POSIX_RECOMMENDED_STACK_SIZE); -static struct k_thread test_thread_thread; - -static void test_main(void) -{ - - bs_trace_raw_time(3, "Empty test main called\n"); - - k_thread_create(&test_thread_thread, stack_te, - CONFIG_ARCH_POSIX_RECOMMENDED_STACK_SIZE, - test_empty_thread, NULL, NULL, NULL, - 0, 0, K_NO_WAIT); -} - -static const struct bst_test_instance test_def[] = { - { - .test_id = "empty", - .test_descr = "demo empty test (it just fails after 500ms)", - .test_post_init_f = test_empty_init, - .test_tick_f = test_empty_tick, - .test_main_f = test_main - }, - BSTEST_END_MARKER -}; - -struct bst_test_list *test_empty_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_def); -} diff --git a/tests/bluetooth/bsim/ll/conn/tests_scripts/basic_conn_encrypted_split.sh b/tests/bluetooth/bsim/ll/conn/tests_scripts/basic_conn_encrypted_split.sh deleted file mode 100755 index 460d46a8e4f..00000000000 --- a/tests/bluetooth/bsim/ll/conn/tests_scripts/basic_conn_encrypted_split.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2018 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -# Basic connection test: a central connects to a peripheral and expects a -# notification -simulation_id="basic_conn_encr_split" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 5 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_ll_conn_prj_split_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=1 \ - -testid=peripheral -rs=23 - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_ll_conn_prj_split_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -RealEncryption=1 \ - -testid=central_encrypted -rs=6 - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=20e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/ll/conn/tests_scripts/basic_conn_encrypted_split_privacy.sh b/tests/bluetooth/bsim/ll/conn/tests_scripts/basic_conn_encrypted_split_privacy.sh deleted file mode 100755 index 09a4e14e070..00000000000 --- a/tests/bluetooth/bsim/ll/conn/tests_scripts/basic_conn_encrypted_split_privacy.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2018 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -# Basic connection test: a central connects to a peripheral and expects a -# notification -simulation_id="basic_conn_encr_split_privacy" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 5 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute \ - ./bs_${BOARD}_tests_bluetooth_bsim_ll_conn_prj_split_privacy_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=1 \ - -testid=peripheral -rs=23 - -Execute \ - ./bs_${BOARD}_tests_bluetooth_bsim_ll_conn_prj_split_privacy_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -RealEncryption=1 \ - -testid=central_encrypted -rs=6 - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=20e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/ll/conn/tests_scripts/basic_conn_split.sh b/tests/bluetooth/bsim/ll/conn/tests_scripts/basic_conn_split.sh deleted file mode 100755 index bd70e2c4767..00000000000 --- a/tests/bluetooth/bsim/ll/conn/tests_scripts/basic_conn_split.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2018 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -# Basic connection test: a central connects to a peripheral and expects a -# notification, using the split controller (ULL LLL) -simulation_id="basic_conn_split" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 5 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_ll_conn_prj_split_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=0 \ - -testid=peripheral -rs=23 - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_ll_conn_prj_split_conf\ - -v=${verbosity_level} -s=${simulation_id} -d=1 -RealEncryption=0 \ - -testid=central -rs=6 - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=20e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/ll/conn/tests_scripts/basic_conn_split_low_lat.sh b/tests/bluetooth/bsim/ll/conn/tests_scripts/basic_conn_split_low_lat.sh deleted file mode 100755 index f4ce0fc9b23..00000000000 --- a/tests/bluetooth/bsim/ll/conn/tests_scripts/basic_conn_split_low_lat.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2018 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -# Basic connection test: a central connects to a peripheral and expects a -# notification, using the split controller (ULL LLL) in Low Latency Variant -simulation_id="basic_conn_split_low_lat" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 5 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute \ - ./bs_${BOARD}_tests_bluetooth_bsim_ll_conn_prj_split_low_lat_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -RealEncryption=0 \ - -testid=peripheral -rs=23 - -Execute \ - ./bs_${BOARD}_tests_bluetooth_bsim_ll_conn_prj_split_low_lat_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -RealEncryption=0 \ - -testid=central -rs=6 - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=20e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/ll/edtt/README.txt b/tests/bluetooth/bsim/ll/edtt/README.txt deleted file mode 100644 index dfb31709fc7..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/README.txt +++ /dev/null @@ -1,63 +0,0 @@ -Intro -##### - -This is the embedded side of the BLE conformance tests which are part of the -EDTT (Embedded Device Test Tool). - -Much more info about the tool can be found in https://github.com/EDTTool/EDTT -and in its `doc/` folder. - -In very short, there is 2 applications in this folder: -1.) A controller only build of the BLE stack, where the HCI, and a few extra - interfaces are exposed to the EDTT. -2.) An application which implements the test GATT services specified by BT SIG - in GATT_Test_Databases.xlsm, with an EDTT interface which allows the EDTT - tests to switch between theses. - -The first application is used for LL and HCI conformance tests of the -controller. -The second application for GATT tests. - -These 2 particular applications are meant to be used in a simulated environment, -for regression, either as part of a CI system, or in workstation during -development. -This is due to this particular application only containing an EDTT transport -driver for simulated targets, meant to connect to the `bsim` EDTT transport -driver thru the EDTT bridge. - -How to use it -############# - -Assuming you have already -`installed BabbleSim `_. - -Add to your environment the variable EDTT_PATH pointing to the -EDTT folder. You can do this by adding it to your `~/.bashrc`, `~/.zephyrrc`, -or similar something like: -``` -export EDTT_PATH=${ZEPHYR_BASE}/../tools/edtt/ -``` -(if you add it to your .bashrc you probably won't be able to refer to -ZEPHYR_BASE) - -To run these sets of tests you need to compile both of these applications as any -other Zephyr app, targeting the nrf52_bsim. -To compile both in an automated way you can just use the `compile.sh` (see -below). - -To run the tests you can either run one of the provided scripts, or run by -hand the BabbleSim 2G4 Phy, EDTT bridge, EDTT and needed simulated devices. -The shortest path is to use the provided scripts. - -In short the whole process being: -``` -cd ${ZEPHYR_BASE} && source zephyr-env.sh -#Compile all apps: -WORK_DIR=${ZEPHYR_BASE}/bsim_bt_out tests/bluetooth/bsim/compile.sh - -#run all tests -RESULTS_FILE=${ZEPHYR_BASE}/banana.xml SEARCH_PATH=tests/bluetooth/bsim/ll/edtt/ tests/bluetooth/bsim/run_parallel.sh - -#or just run one set: -tests/bluetooth/bsim/ll/edtt/tests_scripts/hci.sh -``` diff --git a/tests/bluetooth/bsim/ll/edtt/common/commands.h b/tests/bluetooth/bsim/ll/edtt/common/commands.h deleted file mode 100644 index 6eead52afd4..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/common/commands.h +++ /dev/null @@ -1,286 +0,0 @@ -/* - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -#ifndef EDDT_APP_COMMANDS_H -#define EDDT_APP_COMMANDS_H - -enum commands_t { - CMD_NOTHING = 0, - CMD_ECHO_REQ, - CMD_ECHO_RSP, - CMD_INQUIRE_REQ, - CMD_INQUIRE_RSP, - CMD_DISCONNECT_REQ, - CMD_DISCONNECT_RSP, - CMD_READ_REMOTE_VERSION_INFORMATION_REQ, - CMD_READ_REMOTE_VERSION_INFORMATION_RSP, - CMD_SET_EVENT_MASK_REQ, - CMD_SET_EVENT_MASK_RSP, - CMD_RESET_REQ, - CMD_RESET_RSP, - CMD_READ_TRANSMIT_POWER_LEVEL_REQ, - CMD_READ_TRANSMIT_POWER_LEVEL_RSP, - CMD_SET_CONTROLLER_TO_HOST_FLOW_CONTROL_REQ, - CMD_SET_CONTROLLER_TO_HOST_FLOW_CONTROL_RSP, - CMD_HOST_BUFFER_SIZE_REQ, - CMD_HOST_BUFFER_SIZE_RSP, - CMD_HOST_NUMBER_OF_COMPLETED_PACKETS_REQ, - CMD_HOST_NUMBER_OF_COMPLETED_PACKETS_RSP, - CMD_SET_EVENT_MASK_PAGE_2_REQ, - CMD_SET_EVENT_MASK_PAGE_2_RSP, - CMD_WRITE_LE_HOST_SUPPORT_REQ, - CMD_WRITE_LE_HOST_SUPPORT_RSP, - CMD_READ_AUTHENTICATED_PAYLOAD_TIMEOUT_REQ, - CMD_READ_AUTHENTICATED_PAYLOAD_TIMEOUT_RSP, - CMD_WRITE_AUTHENTICATED_PAYLOAD_TIMEOUT_REQ, - CMD_WRITE_AUTHENTICATED_PAYLOAD_TIMEOUT_RSP, - CMD_READ_LOCAL_VERSION_INFORMATION_REQ, - CMD_READ_LOCAL_VERSION_INFORMATION_RSP, - CMD_READ_LOCAL_SUPPORTED_COMMANDS_REQ, - CMD_READ_LOCAL_SUPPORTED_COMMANDS_RSP, - CMD_READ_LOCAL_SUPPORTED_FEATURES_REQ, - CMD_READ_LOCAL_SUPPORTED_FEATURES_RSP, - CMD_READ_BUFFER_SIZE_REQ, - CMD_READ_BUFFER_SIZE_RSP, - CMD_READ_BD_ADDR_REQ, - CMD_READ_BD_ADDR_RSP, - CMD_READ_RSSI_REQ, - CMD_READ_RSSI_RSP, - CMD_LE_SET_EVENT_MASK_REQ, - CMD_LE_SET_EVENT_MASK_RSP, - CMD_LE_READ_BUFFER_SIZE_REQ, - CMD_LE_READ_BUFFER_SIZE_RSP, - CMD_LE_READ_LOCAL_SUPPORTED_FEATURES_REQ, - CMD_LE_READ_LOCAL_SUPPORTED_FEATURES_RSP, - CMD_LE_SET_RANDOM_ADDRESS_REQ, - CMD_LE_SET_RANDOM_ADDRESS_RSP, - CMD_LE_SET_ADVERTISING_PARAMETERS_REQ, - CMD_LE_SET_ADVERTISING_PARAMETERS_RSP, - CMD_LE_READ_ADVERTISING_CHANNEL_TX_POWER_REQ, - CMD_LE_READ_ADVERTISING_CHANNEL_TX_POWER_RSP, - CMD_LE_SET_ADVERTISING_DATA_REQ, - CMD_LE_SET_ADVERTISING_DATA_RSP, - CMD_LE_SET_SCAN_RESPONSE_DATA_REQ, - CMD_LE_SET_SCAN_RESPONSE_DATA_RSP, - CMD_LE_SET_ADVERTISING_ENABLE_REQ, - CMD_LE_SET_ADVERTISING_ENABLE_RSP, - CMD_LE_SET_SCAN_PARAMETERS_REQ, - CMD_LE_SET_SCAN_PARAMETERS_RSP, - CMD_LE_SET_SCAN_ENABLE_REQ, - CMD_LE_SET_SCAN_ENABLE_RSP, - CMD_LE_CREATE_CONNECTION_REQ, - CMD_LE_CREATE_CONNECTION_RSP, - CMD_LE_CREATE_CONNECTION_CANCEL_REQ, - CMD_LE_CREATE_CONNECTION_CANCEL_RSP, - CMD_LE_READ_FILTER_ACCEPT_LIST_SIZE_REQ, - CMD_LE_READ_FILTER_ACCEPT_LIST_SIZE_RSP, - CMD_LE_CLEAR_FILTER_ACCEPT_LIST_REQ, - CMD_LE_CLEAR_FILTER_ACCEPT_LIST_RSP, - CMD_LE_ADD_DEVICE_TO_FILTER_ACCEPT_LIST_REQ, - CMD_LE_ADD_DEVICE_TO_FILTER_ACCEPT_LIST_RSP, - CMD_LE_REMOVE_DEVICE_FROM_FILTER_ACCEPT_LIST_REQ, - CMD_LE_REMOVE_DEVICE_FROM_FILTER_ACCEPT_LIST_RSP, - CMD_LE_CONNECTION_UPDATE_REQ, - CMD_LE_CONNECTION_UPDATE_RSP, - CMD_LE_SET_HOST_CHANNEL_CLASSIFICATION_REQ, - CMD_LE_SET_HOST_CHANNEL_CLASSIFICATION_RSP, - CMD_LE_READ_CHANNEL_MAP_REQ, - CMD_LE_READ_CHANNEL_MAP_RSP, - CMD_LE_READ_REMOTE_FEATURES_REQ, - CMD_LE_READ_REMOTE_FEATURES_RSP, - CMD_LE_ENCRYPT_REQ, - CMD_LE_ENCRYPT_RSP, - CMD_LE_RAND_REQ, - CMD_LE_RAND_RSP, - CMD_LE_START_ENCRYPTION_REQ, - CMD_LE_START_ENCRYPTION_RSP, - CMD_LE_LONG_TERM_KEY_REQUEST_REPLY_REQ, - CMD_LE_LONG_TERM_KEY_REQUEST_REPLY_RSP, - CMD_LE_LONG_TERM_KEY_REQUEST_NEGATIVE_REPLY_REQ, - CMD_LE_LONG_TERM_KEY_REQUEST_NEGATIVE_REPLY_RSP, - CMD_LE_READ_SUPPORTED_STATES_REQ, - CMD_LE_READ_SUPPORTED_STATES_RSP, - CMD_LE_RECEIVER_TEST_REQ, - CMD_LE_RECEIVER_TEST_RSP, - CMD_LE_TRANSMITTER_TEST_REQ, - CMD_LE_TRANSMITTER_TEST_RSP, - CMD_LE_TEST_END_REQ, - CMD_LE_TEST_END_RSP, - CMD_LE_REMOTE_CONNECTION_PARAMETER_REQUEST_REPLY_REQ, - CMD_LE_REMOTE_CONNECTION_PARAMETER_REQUEST_REPLY_RSP, - CMD_LE_REMOTE_CONNECTION_PARAMETER_REQUEST_NEGATIVE_REPLY_REQ, - CMD_LE_REMOTE_CONNECTION_PARAMETER_REQUEST_NEGATIVE_REPLY_RSP, - CMD_LE_SET_DATA_LENGTH_REQ, - CMD_LE_SET_DATA_LENGTH_RSP, - CMD_LE_READ_SUGGESTED_DEFAULT_DATA_LENGTH_REQ, - CMD_LE_READ_SUGGESTED_DEFAULT_DATA_LENGTH_RSP, - CMD_LE_WRITE_SUGGESTED_DEFAULT_DATA_LENGTH_REQ, - CMD_LE_WRITE_SUGGESTED_DEFAULT_DATA_LENGTH_RSP, - CMD_LE_READ_LOCAL_P_256_PUBLIC_KEY_COMMAND_REQ, - CMD_LE_READ_LOCAL_P_256_PUBLIC_KEY_COMMAND_RSP, - CMD_LE_GENERATE_DHKEY_COMMAND_REQ, - CMD_LE_GENERATE_DHKEY_COMMAND_RSP, - CMD_LE_ADD_DEVICE_TO_RESOLVING_LIST_REQ, - CMD_LE_ADD_DEVICE_TO_RESOLVING_LIST_RSP, - CMD_LE_REMOVE_DEVICE_FROM_RESOLVING_LIST_REQ, - CMD_LE_REMOVE_DEVICE_FROM_RESOLVING_LIST_RSP, - CMD_LE_CLEAR_RESOLVING_LIST_REQ, - CMD_LE_CLEAR_RESOLVING_LIST_RSP, - CMD_LE_READ_RESOLVING_LIST_SIZE_REQ, - CMD_LE_READ_RESOLVING_LIST_SIZE_RSP, - CMD_LE_READ_PEER_RESOLVABLE_ADDRESS_REQ, - CMD_LE_READ_PEER_RESOLVABLE_ADDRESS_RSP, - CMD_LE_READ_LOCAL_RESOLVABLE_ADDRESS_REQ, - CMD_LE_READ_LOCAL_RESOLVABLE_ADDRESS_RSP, - CMD_LE_SET_ADDRESS_RESOLUTION_ENABLE_REQ, - CMD_LE_SET_ADDRESS_RESOLUTION_ENABLE_RSP, - CMD_LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT_REQ, - CMD_LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT_RSP, - CMD_LE_READ_MAXIMUM_DATA_LENGTH_REQ, - CMD_LE_READ_MAXIMUM_DATA_LENGTH_RSP, - CMD_LE_READ_PHY_REQ, - CMD_LE_READ_PHY_RSP, - CMD_LE_SET_DEFAULT_PHY_REQ, - CMD_LE_SET_DEFAULT_PHY_RSP, - CMD_LE_SET_PHY_REQ, - CMD_LE_SET_PHY_RSP, - CMD_LE_ENHANCED_RECEIVER_TEST_REQ, - CMD_LE_ENHANCED_RECEIVER_TEST_RSP, - CMD_LE_ENHANCED_TRANSMITTER_TEST_REQ, - CMD_LE_ENHANCED_TRANSMITTER_TEST_RSP, - CMD_LE_SET_EXTENDED_ADVERTISING_PARAMETERS_REQ, - CMD_LE_SET_EXTENDED_ADVERTISING_PARAMETERS_RSP, - CMD_LE_SET_EXTENDED_ADVERTISING_DATA_REQ, - CMD_LE_SET_EXTENDED_ADVERTISING_DATA_RSP, - CMD_LE_SET_EXTENDED_SCAN_RESPONSE_DATA_REQ, - CMD_LE_SET_EXTENDED_SCAN_RESPONSE_DATA_RSP, - CMD_LE_SET_EXTENDED_ADVERTISING_ENABLE_REQ, - CMD_LE_SET_EXTENDED_ADVERTISING_ENABLE_RSP, - CMD_LE_READ_MAXIMUM_ADVERTISING_DATA_LENGTH_REQ, - CMD_LE_READ_MAXIMUM_ADVERTISING_DATA_LENGTH_RSP, - CMD_LE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS_REQ, - CMD_LE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS_RSP, - CMD_LE_REMOVE_ADVERTISING_SET_REQ, - CMD_LE_REMOVE_ADVERTISING_SET_RSP, - CMD_LE_CLEAR_ADVERTISING_SETS_REQ, - CMD_LE_CLEAR_ADVERTISING_SETS_RSP, - CMD_LE_SET_PERIODIC_ADVERTISING_PARAMETERS_REQ, - CMD_LE_SET_PERIODIC_ADVERTISING_PARAMETERS_RSP, - CMD_LE_SET_PERIODIC_ADVERTISING_DATA_REQ, - CMD_LE_SET_PERIODIC_ADVERTISING_DATA_RSP, - CMD_LE_SET_PERIODIC_ADVERTISING_ENABLE_REQ, - CMD_LE_SET_PERIODIC_ADVERTISING_ENABLE_RSP, - CMD_LE_SET_EXTENDED_SCAN_PARAMETERS_REQ, - CMD_LE_SET_EXTENDED_SCAN_PARAMETERS_RSP, - CMD_LE_SET_EXTENDED_SCAN_ENABLE_REQ, - CMD_LE_SET_EXTENDED_SCAN_ENABLE_RSP, - CMD_LE_EXTENDED_CREATE_CONNECTION_REQ, - CMD_LE_EXTENDED_CREATE_CONNECTION_RSP, - CMD_LE_PERIODIC_ADVERTISING_CREATE_SYNC_REQ, - CMD_LE_PERIODIC_ADVERTISING_CREATE_SYNC_RSP, - CMD_LE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL_REQ, - CMD_LE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL_RSP, - CMD_LE_PERIODIC_ADVERTISING_TERMINATE_SYNC_REQ, - CMD_LE_PERIODIC_ADVERTISING_TERMINATE_SYNC_RSP, - CMD_LE_ADD_DEVICE_TO_PERIODIC_ADVERTISER_LIST_REQ, - CMD_LE_ADD_DEVICE_TO_PERIODIC_ADVERTISER_LIST_RSP, - CMD_LE_REMOVE_DEVICE_FROM_PERIODIC_ADVERTISER_LIST_REQ, - CMD_LE_REMOVE_DEVICE_FROM_PERIODIC_ADVERTISER_LIST_RSP, - CMD_LE_CLEAR_PERIODIC_ADVERTISER_LIST_REQ, - CMD_LE_CLEAR_PERIODIC_ADVERTISER_LIST_RSP, - CMD_LE_READ_PERIODIC_ADVERTISER_LIST_SIZE_REQ, - CMD_LE_READ_PERIODIC_ADVERTISER_LIST_SIZE_RSP, - CMD_LE_READ_TRANSMIT_POWER_REQ, - CMD_LE_READ_TRANSMIT_POWER_RSP, - CMD_LE_READ_RF_PATH_COMPENSATION_REQ, - CMD_LE_READ_RF_PATH_COMPENSATION_RSP, - CMD_LE_WRITE_RF_PATH_COMPENSATION_REQ, - CMD_LE_WRITE_RF_PATH_COMPENSATION_RSP, - CMD_LE_SET_PRIVACY_MODE_REQ, - CMD_LE_SET_PRIVACY_MODE_RSP, - CMD_WRITE_BD_ADDR_REQ, - CMD_WRITE_BD_ADDR_RSP, - CMD_FLUSH_EVENTS_REQ, - CMD_FLUSH_EVENTS_RSP, - CMD_HAS_EVENT_REQ, - CMD_HAS_EVENT_RSP, - CMD_GET_EVENT_REQ, - CMD_GET_EVENT_RSP, - CMD_LE_FLUSH_DATA_REQ, - CMD_LE_FLUSH_DATA_RSP, - CMD_LE_DATA_READY_REQ, - CMD_LE_DATA_READY_RSP, - CMD_LE_DATA_WRITE_REQ, - CMD_LE_DATA_WRITE_RSP, - CMD_LE_DATA_READ_REQ, - CMD_LE_DATA_READ_RSP, - CMD_GATT_SERVICE_SET_REQ, - CMD_GATT_SERVICE_SET_RSP, - CMD_GATT_SERVICE_NOTIFY_REQ, - CMD_GATT_SERVICE_NOTIFY_RSP, - CMD_GATT_SERVICE_INDICATE_REQ, - CMD_GATT_SERVICE_INDICATE_RSP, - CMD_GAP_ADVERTISING_MODE_REQ, - CMD_GAP_ADVERTISING_MODE_RSP, - CMD_GAP_ADVERTISING_DATA_REQ, - CMD_GAP_ADVERTISING_DATA_RSP, - CMD_GAP_SCANNING_MODE_REQ, - CMD_GAP_SCANNING_MODE_RSP, - CMD_READ_STATIC_ADDRESSES_REQ, - CMD_READ_STATIC_ADDRESSES_RSP, - CMD_READ_KEY_HIERARCHY_ROOTS_REQ, - CMD_READ_KEY_HIERARCHY_ROOTS_RSP, - CMD_GAP_READ_IRK_REQ, - CMD_GAP_READ_IRK_RSP, - CMD_GAP_ROLE_REQ, - CMD_GAP_ROLE_RSP, - CMD_LE_FLUSH_ISO_DATA_REQ, - CMD_LE_FLUSH_ISO_DATA_RSP, - CMD_LE_ISO_DATA_READY_REQ, - CMD_LE_ISO_DATA_READY_RSP, - CMD_LE_ISO_DATA_WRITE_REQ, - CMD_LE_ISO_DATA_WRITE_RSP, - CMD_LE_ISO_DATA_READ_REQ, - CMD_LE_ISO_DATA_READ_RSP, - CMD_LE_SET_CIG_PARAMETERS_REQ, - CMD_LE_SET_CIG_PARAMETERS_RSP, - CMD_LE_SET_CIG_PARAMETERS_TEST_REQ, - CMD_LE_SET_CIG_PARAMETERS_TEST_RSP, - CMD_LE_CREATE_CIS_REQ, - CMD_LE_CREATE_CIS_RSP, - CMD_LE_REMOVE_CIG_REQ, - CMD_LE_REMOVE_CIG_RSP, - CMD_LE_ACCEPT_CIS_REQUEST_REQ, - CMD_LE_ACCEPT_CIS_REQUEST_RSP, - CMD_LE_REJECT_CIS_REQUEST_REQ, - CMD_LE_REJECT_CIS_REQUEST_RSP, - CMD_LE_SETUP_ISO_DATA_PATH_REQ, - CMD_LE_SETUP_ISO_DATA_PATH_RSP, - CMD_LE_REMOVE_ISO_DATA_PATH_REQ, - CMD_LE_REMOVE_ISO_DATA_PATH_RSP, - CMD_LE_SET_HOST_FEATURE_REQ, - CMD_LE_SET_HOST_FEATURE_RSP, - CMD_GET_IXIT_VALUE_REQ, - CMD_GET_IXIT_VALUE_RSP, - CMD_HCI_LE_ISO_TRANSMIT_TEST_REQ, - CMD_HCI_LE_ISO_TRANSMIT_TEST_RSP, - CMD_HCI_LE_ISO_RECEIVE_TEST_REQ, - CMD_HCI_LE_ISO_RECEIVE_TEST_RSP, - CMD_HCI_LE_ISO_READ_TEST_COUNTERS_REQ, - CMD_HCI_LE_ISO_READ_TEST_COUNTERS_RSP, - CMD_HCI_LE_ISO_TEST_END_REQ, - CMD_HCI_LE_ISO_TEST_END_RSP -}; - -enum profile_t { - PROFILE_ID_GAP, - PROFILE_ID_GATT, - PROFILE_ID_HCI, - PROFILE_ID_L2CAP, - PROFILE_ID_LL, - PROFILE_ID_SM, -}; - -#endif /* EDDT_APP_COMMANDS_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/common/edtt_driver.h b/tests/bluetooth/bsim/ll/edtt/common/edtt_driver.h deleted file mode 100644 index 04b94c80294..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/common/edtt_driver.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ - - -#ifndef EDTT_DRIVER_H -#define EDTT_DRIVER_H - -#include -#include -#include "zephyr/types.h" - -#define EDTTT_NONBLOCK 0 -#define EDTTT_BLOCK 1 - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Generic EDTT interface - */ -bool edtt_start(void); -void edtt_stop(void); -int edtt_read(uint8_t *ptr, size_t size, int flags); -int edtt_write(uint8_t *ptr, size_t size, int flags); - -#if defined(CONFIG_ARCH_POSIX) -/** - * Exclusive functions for the BabbleSim driver - */ -void enable_edtt_mode(void); -void set_edtt_autoshutdown(bool mode); -#endif /* CONFIG_ARCH_POSIX */ - -#ifdef __cplusplus -} -#endif - -#endif /* EDTT_DRIVER_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/common/edtt_driver_bsim.c b/tests/bluetooth/bsim/ll/edtt/common/edtt_driver_bsim.c deleted file mode 100644 index 4f28a8bd0a5..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/common/edtt_driver_bsim.c +++ /dev/null @@ -1,269 +0,0 @@ -/* - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "edtt_driver.h" -#include -#include "soc.h" - -#include "bs_tracing.h" -#include "bs_utils.h" -#include "bs_oswrap.h" -#include "bs_pc_base_fifo_user.h" - -/* Recheck if something arrived from the EDTT every 5ms */ -#define EDTT_IF_RECHECK_DELTA 5 /* ms */ - -/* We want the runs to be deterministic => we want to resync with the Phy - * before we retry any read so the bridge device may also run - */ -#define EDTT_SIMU_RESYNC_TIME_WITH_EDTT \ - (EDTT_IF_RECHECK_DELTA * MSEC_PER_SEC - 1) - -int edtt_mode_enabled; - -/* In this mode, when the EDTTool closes the FIFO we automatically terminate - * this simulated device. If false, we just continue running - */ -static int edtt_autoshutdown; - -#define TO_DEVICE 0 -#define TO_BRIDGE 1 -static int fifo[2] = { -1, -1 }; -static char *fifo_path[2] = {NULL, NULL}; - -extern unsigned int global_device_nbr; - -static void edttd_clean_up(void); -static void edptd_create_fifo_if(void); -static int fifo_low_level_read(uint8_t *bufptr, int size); - -bool edtt_start(void) -{ - if (edtt_mode_enabled == false) { - /* otherwise we don't try to open the EDTT interface */ - return true; - } - - edptd_create_fifo_if(); - - extern void tm_set_phy_max_resync_offset(uint64_t offset_in_us); - tm_set_phy_max_resync_offset(EDTT_SIMU_RESYNC_TIME_WITH_EDTT); - return true; -} - -void edtt_stop(void) -{ - if (edtt_mode_enabled == false) { - /* otherwise we don't try to open the EDTT interface */ - return; - } - - bs_trace_raw(9, "EDTTT: %s called\n", __func__); - edttd_clean_up(); - edtt_mode_enabled = false; -} - -#if defined(NATIVE_TASK) -NATIVE_TASK(edtt_stop, ON_EXIT, 1); -#endif - -/** - * Attempt to read size bytes thru the EDTT IF into the buffer <*ptr> - * can be set to EDTTT_BLOCK or EDTTT_NONBLOCK - * - * If set to EDTTT_BLOCK it will block the calling thread until - * bytes have been read or the interface has been closed. - * If set to EDTTT_NONBLOCK it returns as soon as there is no more data to be - * read - * - * Returns the amount of read bytes, or -1 on error - */ -int edtt_read(uint8_t *ptr, size_t size, int flags) -{ - if (edtt_mode_enabled == false) { - return -1; - } - - bs_trace_raw_time(8, "EDTT: Asked to read %i bytes\n", size); - int read = 0; - - while (size > 0) { - int received_bytes; - - received_bytes = fifo_low_level_read(ptr, size); - if (received_bytes < 0) { - return -1; - } else if (received_bytes > 0) { - size -= received_bytes; - ptr += received_bytes; - read += received_bytes; - } else { - if (flags & EDTTT_BLOCK) { - bs_trace_raw_time(9, "EDTT: No enough data yet," - "sleeping for %i ms\n", - EDTT_IF_RECHECK_DELTA); - k_sleep(K_MSEC(EDTT_IF_RECHECK_DELTA)); - } else { - bs_trace_raw_time(9, "EDTT: No enough data yet," - "returning\n"); - break; - } - } - } - - return read; -} - -/** - * Write bytes from toward the EDTTool - * - * is ignored in this driver, all writes to the tool are - * instantaneous - */ -int edtt_write(uint8_t *ptr, size_t size, int flags) -{ - if (edtt_mode_enabled == false) { - return -1; - } - bs_trace_raw_time(9, "EDTT: Asked to write %i bytes\n", size); - - if (write(fifo[TO_BRIDGE], ptr, size) != size) { - if (errno == EPIPE) { - bs_trace_error_line("EDTT IF suddenly closed by other " - "end\n"); - } - if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) { - bs_trace_error_line("EDTT IF to bridge filled up (FIFO " - "size needs to be increased)\n"); - } - bs_trace_error_line("EDTT IF: Unexpected error on write\n"); - } - return size; -} - -/* - * Applications may want to enable the EDTT interface only in some - * cases. By default it is not enabled in this driver. This function - * must be called once before starting it to do so - */ -void enable_edtt_mode(void) -{ - edtt_mode_enabled = true; -} - -/** - * Automatically terminate this device execution once the EDTTool disconnects - */ -void set_edtt_autoshutdown(bool Mode) -{ - edtt_autoshutdown = Mode; -} - -static void edptd_create_fifo_if(void) -{ - int flags; - - bs_trace_raw_time(9, "Bringing EDTT IF up (waiting for other side)\n"); - - if (pb_com_path == NULL) { - bs_trace_error_line("Not connected to Phy." - "EDTT IF cannot be brought up\n"); - } - - /* At this point we have connected to the Phy so the COM folder does - * already exist - * also SIGPIPE is already ignored - */ - - fifo_path[TO_DEVICE] = (char *)bs_calloc(pb_com_path_length + 30, - sizeof(char)); - fifo_path[TO_BRIDGE] = (char *)bs_calloc(pb_com_path_length + 30, - sizeof(char)); - sprintf(fifo_path[TO_DEVICE], "%s/Device%i.PTTin", - pb_com_path, global_device_nbr); - sprintf(fifo_path[TO_BRIDGE], "%s/Device%i.PTTout", - pb_com_path, global_device_nbr); - - if ((pb_create_fifo_if_not_there(fifo_path[TO_DEVICE]) != 0) - || (pb_create_fifo_if_not_there(fifo_path[TO_BRIDGE]) != 0)) { - bs_trace_error_line("Couldn't create FIFOs for EDTT IF\n"); - } - - /* we block here until the bridge opens its end */ - fifo[TO_BRIDGE] = open(fifo_path[TO_BRIDGE], O_WRONLY); - if (fifo[TO_BRIDGE] == -1) { - bs_trace_error_line("Couldn't create FIFOs for EDTT IF\n"); - } - - flags = fcntl(fifo[TO_BRIDGE], F_GETFL); - flags |= O_NONBLOCK; - fcntl(fifo[TO_BRIDGE], F_SETFL, flags); - - /* we will block here until the bridge opens its end */ - fifo[TO_DEVICE] = open(fifo_path[TO_DEVICE], O_RDONLY); - if (fifo[TO_DEVICE] == -1) { - bs_trace_error_line("Couldn't create FIFOs for EDTT IF\n"); - } - - flags = fcntl(fifo[TO_DEVICE], F_GETFL); - flags |= O_NONBLOCK; - fcntl(fifo[TO_DEVICE], F_SETFL, flags); -} - -static void edttd_clean_up(void) -{ - for (int dir = TO_DEVICE ; dir <= TO_BRIDGE ; dir++) { - if (fifo_path[dir]) { - if (fifo[dir] != -1) { - close(fifo[dir]); - remove(fifo_path[dir]); - fifo[dir] = -1; - } - free(fifo_path[dir]); - fifo_path[dir] = NULL; - } - } - if (pb_com_path != NULL) { - rmdir(pb_com_path); - } -} - -static int fifo_low_level_read(uint8_t *bufptr, int size) -{ - int received_bytes = read(fifo[TO_DEVICE], bufptr, size); - - if ((received_bytes == -1) && (errno == EAGAIN)) { - return 0; - } else if (received_bytes == EOF || received_bytes == 0) { - /*The FIFO was closed by the bridge*/ - if (edtt_autoshutdown) { - bs_trace_raw_time(3, "EDTT: FIFO closed " - "(ptt_autoshutdown==true) =>" - " Terminate\n"); - edttd_clean_up(); - bs_trace_exit_line("\n"); - } else { - bs_trace_raw_time(3, "EDTT: FIFO closed " - "(ptt_autoshutdown==false) => We close " - "the FIFOs and move on\n"); - edttd_clean_up(); - edtt_mode_enabled = false; - return -1; - } - } else if (received_bytes == -1) { - bs_trace_error_line("EDTT: Unexpected error\n"); - } - - return received_bytes; -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/CMakeLists.txt b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/CMakeLists.txt deleted file mode 100644 index 555b47afed9..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# Copyright (c) 2019 Oticon A/S - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set\ - the environment variable BSIM_COMPONENTS_PATH to point to its components \ - folder. More information can be found in\ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(peripheral_test) - -FILE(GLOB app_sources src/*.c) -FILE(GLOB gatt_sources src/gatt/*.c) -target_sources(app PRIVATE - ${app_sources} - ../common/edtt_driver_bsim.c - ${gatt_sources} -) - -zephyr_library_include_directories(${ZEPHYR_BASE}/samples/bluetooth - ../common/ - src/ - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ -) diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/prj.conf b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/prj.conf deleted file mode 100644 index 62a3902ab2e..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/prj.conf +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (c) 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -CONFIG_BT=y -CONFIG_BT_SMP=y -CONFIG_BT_SIGNING=y -CONFIG_BT_TINYCRYPT_ECC=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_ATT_PREPARE_COUNT=2 -CONFIG_BT_PRIVACY=y -CONFIG_BT_DEVICE_NAME="Test Database" -CONFIG_BT_DEVICE_APPEARANCE=833 -CONFIG_BT_GATT_DYNAMIC_DB=y - -CONFIG_BT_CTLR=y -CONFIG_BT_LL_SW_SPLIT=y - -CONFIG_BT_HCI_ACL_FLOW_CONTROL=y -CONFIG_BT_BUF_ACL_RX_SIZE=516 -CONFIG_BT_L2CAP_TX_MTU=512 -CONFIG_BT_DEBUG_LOG=y - -# NOTE: In order to get ACL_FLOW_CONTROL to work it is imperative that -# BT_CTRL_RX_BUFFERS is increased from its default value of 1. -CONFIG_BT_CTLR_RX_BUFFERS=3 - -# To make DEVICE Name writable... -CONFIG_BT_DEVICE_NAME_DYNAMIC=y - -CONFIG_BT_LL_SW_LLCP_LEGACY=y diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/prj_llcp.conf b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/prj_llcp.conf deleted file mode 100644 index baf28e68ff1..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/prj_llcp.conf +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (c) 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -CONFIG_BT=y -CONFIG_BT_SMP=y -CONFIG_BT_SIGNING=y -CONFIG_BT_TINYCRYPT_ECC=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_ATT_PREPARE_COUNT=2 -CONFIG_BT_PRIVACY=y -CONFIG_BT_DEVICE_NAME="Test Database" -CONFIG_BT_DEVICE_APPEARANCE=833 -CONFIG_BT_GATT_DYNAMIC_DB=y - -CONFIG_BT_CTLR=y -CONFIG_BT_LL_SW_SPLIT=y - -CONFIG_BT_HCI_ACL_FLOW_CONTROL=y -CONFIG_BT_BUF_ACL_RX_SIZE=516 -CONFIG_BT_L2CAP_TX_MTU=512 -CONFIG_BT_DEBUG_LOG=y - -# NOTE: In order to get ACL_FLOW_CONTROL to work it is imperative that -# BT_CTRL_RX_BUFFERS is increased from its default value of 1. -CONFIG_BT_CTLR_RX_BUFFERS=3 - -# To make DEVICE Name writable... -CONFIG_BT_DEVICE_NAME_DYNAMIC=y - -CONFIG_BT_LL_SW_LLCP=y diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/gatt_macs.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/gatt_macs.h deleted file mode 100644 index 5c837ad110a..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/gatt_macs.h +++ /dev/null @@ -1,238 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief GATT Macros - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Qualification_Test_Databases.xlsm' Sheet: 'Large Database 1' - * - * Feel free to change it - but be aware that your changes might be - * overwritten at the next generation... - */ - -#ifndef GATT_MACS_H -#define GATT_MACS_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -/** - * @brief Attribute Declaration Macro. - * - * Helper macro to declare an attribute. - * - * @param _uuid Attribute uuid. - * @param _perm Attribute access permissions. - * @param _read Attribute read callback. - * @param _write Attribute write callback. - * @param _value Attribute value. - * @param _handle Attribute handle. - */ -#define BT_GATT_H_ATTRIBUTE(_uuid, _perm, _read, _write, _value, _handle) \ - { \ - .uuid = _uuid, \ - .perm = _perm, \ - .read = _read, \ - .write = _write, \ - .user_data = _value, \ - .handle = _handle \ - } - -/** - * @brief Characteristic and Value Declaration Macro. - * - * Helper macro to declare a characteristic attribute along with its attribute - * value. - * - * @param _uuid Characteristic attribute uuid. - * @param _props Characteristic attribute properties. - * @param _perm Characteristic attribute access permissions. - * @param _read Characteristic attribute read callback. - * @param _write Characteristic attribute write callback. - * @param _value Characteristic attribute value. - * @param _handle Characteristic attribute handle. - */ -#define BT_GATT_H_CHARACTERISTIC(_uuid, _props, _perm, _read, _write, _value,\ - _handle) \ - BT_GATT_H_ATTRIBUTE(BT_UUID_GATT_CHRC, \ - BT_GATT_PERM_READ, \ - bt_gatt_attr_read_chrc, \ - NULL, \ - (&(struct bt_gatt_chrc) {.uuid = _uuid, \ - .properties = _props \ - }), \ - _handle), \ - BT_GATT_H_ATTRIBUTE(_uuid, _perm, _read, _write, _value, _handle + 1) - -/** - * @brief Primary Service Declaration Macro. - * - * Helper macro to declare a primary service attribute. - * - * @param _service Service attribute value. - * @param _handle Service attribute handle. - */ -#define BT_GATT_H_PRIMARY_SERVICE(_service, _handle) \ - BT_GATT_H_ATTRIBUTE(BT_UUID_GATT_PRIMARY, \ - BT_GATT_PERM_READ, \ - bt_gatt_attr_read_service, \ - NULL, \ - _service, \ - _handle) - -/** - * @brief Secondary Service Declaration Macro. - * - * Helper macro to declare a secondary service attribute. - * - * @param _service Service attribute value. - * @param _handle Service attribute handle. - */ -#define BT_GATT_H_SECONDARY_SERVICE(_service, _handle) \ - BT_GATT_H_ATTRIBUTE(BT_UUID_GATT_SECONDARY, \ - BT_GATT_PERM_READ, \ - bt_gatt_attr_read_service, \ - NULL, \ - _service, \ - _handle) - -/** - * @brief Include Service Declaration Macro. - * - * Helper macro to declare database internal include service attribute. - * - * @param _service_incl The first service attribute of service to include. - * @param _handle Service attribute handle. - */ -#define BT_GATT_H_INCLUDE_SERVICE(_service_incl, _handle) \ - BT_GATT_H_ATTRIBUTE(BT_UUID_GATT_INCLUDE, \ - BT_GATT_PERM_READ, \ - bt_gatt_attr_read_included, \ - NULL, \ - _service_incl, \ - _handle) - -/** - * @brief Descriptor Declaration Macro. - * - * Helper macro to declare a descriptor attribute. - * - * @param _uuid Descriptor attribute uuid. - * @param _perm Descriptor attribute access permissions. - * @param _read Descriptor attribute read callback. - * @param _write Descriptor attribute write callback. - * @param _value Descriptor attribute value. - * @param _handle Descriptor attribute handle. - */ -#define BT_GATT_H_DESCRIPTOR(_uuid, _perm, _read, _write, _value, _handle) \ - BT_GATT_H_ATTRIBUTE(_uuid, _perm, _read, _write, _value, _handle) - -/** - * @brief Managed Client Characteristic Configuration Declaration Macro. - * - * Helper macro to declare a Managed CCC attribute. - * - * @param _ccc CCC attribute user data, shall point to a _bt_gatt_ccc. - * @param _perm CCC access permissions. - * @param _handle Descriptor attribute handle. - */ -#define BT_GATT_H_MANAGED(_ccc, _perm, _handle) \ - BT_GATT_H_ATTRIBUTE(BT_UUID_GATT_CCC, _perm,\ - bt_gatt_attr_read_ccc, bt_gatt_attr_write_ccc, _ccc, _handle) - -/** - * @brief Client Characteristic Configuration Change Declaration Macro. - * - * Helper macro to declare a CCC attribute. - * - * @param _cfg Initial configuration. - * @param _cfg_changed Configuration changed callback. - * @param _handle Descriptor attribute handle. - */ -/* #undef BT_GATT_H_CCC - * #define BT_GATT_H_CCC(_cfg, _cfg_changed, _handle) \ - * BT_GATT_H_DESCRIPTOR(BT_UUID_GATT_CCC, \ - * BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, \ - * bt_gatt_attr_read_ccc, \ - * bt_gatt_attr_write_ccc, \ - * (&(struct _bt_gatt_ccc) { \ - * .cfg = _cfg, \ - * .cfg_len = ARRAY_SIZE(_cfg), \ - * .cfg_changed = _cfg_changed \ - * } ), \ - * _handle) - */ -/** - * @brief Client Characteristic Configuration Change Declaration Macro. - * - * Helper macro to declare a CCC attribute. - * - * @param _cfg Initial configuration. - * @param _cfg_changed Configuration changed callback. - * @param _handle Descriptor attribute handle. - */ -#define BT_GATT_H_CCC(_cfg, _cfg_changed, _handle) \ - BT_GATT_H_MANAGED((&(struct _bt_gatt_ccc) \ - BT_GATT_CCC_INITIALIZER(_cfg_changed, NULL, NULL)),\ - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, _handle) - -/** - * @brief Characteristic Extended Properties Declaration Macro. - * - * Helper macro to declare a CEP attribute. - * - * @param _value Descriptor attribute value. - * @param _handle Descriptor attribute handle. - */ -#define BT_GATT_H_CEP(_value, _handle) \ - BT_GATT_H_DESCRIPTOR(BT_UUID_GATT_CEP, \ - BT_GATT_PERM_READ, \ - bt_gatt_attr_read_cep, \ - NULL, \ - (void *)_value, \ - _handle) - -/** - * @brief Characteristic User Format Descriptor Declaration Macro. - * - * Helper macro to declare a CUD attribute. - * - * @param _value User description NULL-terminated C string. - * @param _perm Descriptor attribute access permissions. - * @param _handle Descriptor attribute handle. - */ -#define BT_GATT_H_CUD(_value, _perm, _handle) \ - BT_GATT_H_DESCRIPTOR(BT_UUID_GATT_CUD, \ - _perm, \ - bt_gatt_attr_read_cud, \ - NULL, \ - (void *)_value, \ - _handle) - -/** - * @brief Characteristic Presentation Format Descriptor Declaration Macro. - * - * Helper macro to declare a CPF attribute. - * - * @param _value Descriptor attribute value. - * @param _handle Descriptor attribute handle. - */ -#define BT_GATT_H_CPF(_value, _handle) \ - BT_GATT_H_DESCRIPTOR(BT_UUID_GATT_CPF, \ - BT_GATT_PERM_READ, \ - bt_gatt_attr_read_cpf, \ - NULL, \ - (void *)_value, \ - _handle) - -#ifdef __cplusplus -} -#endif - -#endif /* GATT_MACS_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_1.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_1.c deleted file mode 100644 index db89ef97784..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_1.c +++ /dev/null @@ -1,262 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service A - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 1' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -extern struct bt_gatt_attr service_d_1_attrs[]; - -/** - * @brief UUID for the Service A - */ -#define BT_UUID_SERVICE_A BT_UUID_DECLARE_16(0xa00a) - -/** - * @brief UUID for the Value V1 Characteristic - */ -#define BT_UUID_VALUE_V1 BT_UUID_DECLARE_16(0xb001) - -/** - * @brief UUID for the Value V2 Characteristic - */ -#define BT_UUID_VALUE_V2 BT_UUID_DECLARE_16(0xb002) - -/** - * @brief UUID for the Value V3 Characteristic - */ -#define BT_UUID_VALUE_V3 BT_UUID_DECLARE_16(0xb003) - -static uint8_t value_v1_value = 0x01; -static uint8_t value_v2_value[] = { - '1', '1', '1', '1', '1', '2', '2', '2', '2', '2', '3', '3', '3', - '3', '3', '4', '4', '4', '4', '4', '5', '5', '5', '5', '5', '6', - '6', '6', '6', '6', '7', '7', '7', '7', '7', '8', '8', '8', '8', - '8', '9', '9', '9', '9', '9', '0', '0', '0', '0', '0', '1', '1', - '1', '1', '1', '2', '2', '2', '2', '2', '3', '3', '3', '3', '3', - '4', '4', '4', '4', '4', '5', '5', '5', '5', '5', '6', '6', '6', - '6', '6', '7', '7', '7', '7', '7', '8', '8', '8', '8', '8', '9', - '9', '9', '9', '9', '0', '0', '0', '0', '0', '1', '1', '1', '1', - '1', '2', '2', '2', '2', '2', '3', '3', '3', '3', '3', '4', '4', - '4', '4', '4', '5', '5', '5', '5', '5', '6', '6', '6', '6', '6', - '7', '7', '7', '7', '7', '8', '8', '8', '8', '8', '9', '9', '9', - '9', '9', '0', '0', '0', '0', '0', '1', '1', '1', '1', '1', '2', - '2', '2', '2', '2', '3', '3', '3', '3', '3', '4', '4', '4', '4', - '4', '5', '5', '5', '5', '5', '6', '6', '6', '6', '6', '7', '7', - '7', '7', '7', '8', '8', '8', '8', '8', '9', '9', '9', '9', '9', - '0', '0', '0', '0', '0', '1', '1', '1', '1', '1', '2', '2', '2', - '2', '2', '3', '3', '3', '3', '3', '4', '4', '4', '4', '4', '5', - '5', '5', '5', '5', '6', '6', '6', '6', '6', '7', '7', '7', '7', - '7', '8', '8', '8', '8', '8', '9', '9', '9', '9', '9', '0', '0', - '0', '0', '0', '1', '1', '1', '1', '1', '2', '2', '2', '2', '2', - '3', '3', '3', '3', '3', '4', '4', '4', '4', '4', '5', '5', '5', - '5', '5', '6', '6', '6', '6', '6', '7', '7', '7', '7', '7', '8', - '8', '8', '8', '8', '9', '9', '9', '9', '9', '0', '0', '0', '0', - '0', '1', '1', '1', '1', '1', '2', '2', '2', '2', '2', '3', '3', - '3', '3', '3', '4', '4', '4', '4', '4', '5', '5', '5', '5', '5', - '6', '6', '6', '6', '6', '7', '7', '7', '7', '7', '8', '8', '8', - '8', '8', '9', '9', '9', '9', '9', '0', '0', '0', '0', '0', '1', - '1', '1', '1', '1', '2', '2', '2', '2', '2', '3', '3', '3', '3', - '3', '4', '4', '4', '4', '4', '5', '5', '5', '5', '5', '6', '6', - '6', '6', '6', '7', '7', '7', '7', '7', '8', '8', '8', '8', '8', - '9', '9', '9', '9', '9', '0', '0', '0', '0', '0', '1', '1', '1', - '1', '1', '2', '2', '2', '2', '2', '3', '3', '3', '3', '3', '4', - '4', '4', '4', '4', '5', '5', '5', '5', '5', '6', '6', '6', '6', - '6', '7', '7', '7', '7', '7', '8', '8', '8', '8', '8', '9', '9', - '9', '9', '9', '0', '0', '0', '0', '0', '1', '1', '1', '1', '1', - '2', '2', '2', '2', '2', '3', '3', '3', '3', '3', '4', '4', '4', - '4', '4', '5', '5', '5', '5', '5', '6', '6', '6', '6', '6', '7', - '7', '7', '7', '7', '8', '8', '8', '8', '8', '9', '9', '9', '9', - '9', '0', '0', '0', '0', '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', '0', '1', '2', '\0' -}; -static uint8_t value_v2_1_value[] = { - '1', '1', '1', '1', '1', '2', '2', '2', '2', '2', '3', '3', '3', - '3', '3', '4', '4', '4', '4', '4', '5', '5', '5', '5', '5', '6', - '6', '6', '6', '6', '7', '7', '7', '7', '7', '8', '8', '8', '8', - '8', '9', '9', '9', '9', '9', '0', '0', '0', '0', '0', '\0' -}; -static uint8_t value_v3_value = 0x03; - -/** - * @brief Attribute read call back for the Value V1 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v1(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v1_value)); -} - -/** - * @brief Attribute read call back for the Value V2 string attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_str_value(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const char *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - strlen(value)); -} - -/** - * @brief Attribute write call back for the Value V2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v2(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - char *value = attr->user_data; - - if (offset >= sizeof(value_v2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute write call back for the Value V2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v2_1(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - char *value = attr->user_data; - - if (offset >= sizeof(value_v2_1_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v2_1_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute write call back for the Value V3 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v3(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(value_v3_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v3_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -static struct bt_gatt_attr service_a_1_attrs[] = { - BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_A, 0x20), - BT_GATT_H_INCLUDE_SERVICE(service_d_1_attrs, 0x21), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V1, - BT_GATT_CHRC_READ, - BT_GATT_PERM_READ_ENCRYPT, - read_value_v1, NULL, &value_v1_value, 0x22), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_str_value, write_value_v2, &value_v2_value, 0x24), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2, - BT_GATT_CHRC_WRITE, - BT_GATT_PERM_WRITE, - NULL, write_value_v2_1, &value_v2_1_value, 0x26), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V3, - BT_GATT_CHRC_WRITE, - BT_GATT_PERM_WRITE, - NULL, write_value_v3, &value_v3_value, 0x28) -}; - -static struct bt_gatt_service service_a_1_svc = - BT_GATT_SERVICE(service_a_1_attrs); - -/** - * @brief Register the Service A and all its Characteristics... - */ -void service_a_1_init(void) -{ - bt_gatt_service_register(&service_a_1_svc); -} - -/** - * @brief Un-Register the Service A and all its Characteristics... - */ -void service_a_1_remove(void) -{ - bt_gatt_service_unregister(&service_a_1_svc); -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_1.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_1.h deleted file mode 100644 index fb86e31783d..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_1.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service A - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 1' - */ -#ifndef SERVICE_A_1_H -#define SERVICE_A_1_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_a_1_init(void); -void service_a_1_remove(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_A_1_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_2.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_2.c deleted file mode 100644 index 831d3e49bb5..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_2.c +++ /dev/null @@ -1,188 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service A - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 2' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -extern struct bt_gatt_attr service_d_2_attrs[]; -extern struct bt_gatt_attr service_c_1_2_attrs[]; - -/** - * @brief UUID for the Service A - */ -#define BT_UUID_SERVICE_A BT_UUID_DECLARE_16(0xa00a) - -/** - * @brief UUID for the Value V1 Characteristic - */ -#define BT_UUID_VALUE_V1 BT_UUID_DECLARE_16(0xb001) - -/** - * @brief UUID for the Value V2 Characteristic - */ -#define BT_UUID_VALUE_V2 BT_UUID_DECLARE_16(0xb002) - -/** - * @brief UUID for the Value V3 Characteristic - */ -#define BT_UUID_VALUE_V3 BT_UUID_DECLARE_16(0xb003) - -static uint8_t value_v1_value = 0x01; -static uint8_t value_v2_value[] = { - '1', '1', '1', '1', '1', '2', '2', '2', '2', '2', '3', '3', '3', - '3', '3', '4', '4', '4', '4', '4', '5', '5', '5', '5', '5', '6', - '6', '6', '6', '6', '7', '7', '7', '7', '7', '8', '8', '8', '8', - '8', '9', '9', '9', '9', '9', '0', '0', '0', '0', '0', '\0' -}; -static uint8_t value_v3_value = 0x03; - -/** - * @brief Attribute read call back for the Value V1 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v1(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v1_value)); -} - -/** - * @brief Attribute read call back for the Value V2 string attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_str_value(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const char *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - strlen(value)); -} - -/** - * @brief Attribute write call back for the Value V2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v2(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - char *value = attr->user_data; - - if (offset >= sizeof(value_v2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute write call back for the Value V3 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v3(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(value_v3_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v3_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -static struct bt_gatt_attr service_a_2_attrs[] = { - BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_A, 0x60), - BT_GATT_H_INCLUDE_SERVICE(service_d_2_attrs, 0x61), - BT_GATT_H_INCLUDE_SERVICE(service_c_1_2_attrs, 0x62), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V1, - BT_GATT_CHRC_READ, - BT_GATT_PERM_READ, - read_value_v1, NULL, &value_v1_value, 0x63), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_str_value, write_value_v2, &value_v2_value, 0x65), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V3, - BT_GATT_CHRC_WRITE, - BT_GATT_PERM_WRITE, - NULL, write_value_v3, &value_v3_value, 0x67) -}; - -static struct bt_gatt_service service_a_2_svc = - BT_GATT_SERVICE(service_a_2_attrs); - -/** - * @brief Register the Service A and all its Characteristics... - */ -void service_a_2_init(void) -{ - bt_gatt_service_register(&service_a_2_svc); -} - -/** - * @brief Un-Register the Service A and all its Characteristics... - */ -void service_a_2_remove(void) -{ - bt_gatt_service_unregister(&service_a_2_svc); -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_2.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_2.h deleted file mode 100644 index 5149a21e3ce..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_2.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service A - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 2' - */ -#ifndef SERVICE_A_2_H -#define SERVICE_A_2_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_a_2_init(void); -void service_a_2_remove(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_A_2_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_3.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_3.c deleted file mode 100644 index 2fb226df6a9..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_3.c +++ /dev/null @@ -1,188 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service A - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 3' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -extern struct bt_gatt_attr service_d_3_attrs[]; -extern struct bt_gatt_attr service_c_1_3_attrs[]; - -/** - * @brief UUID for the Service A - */ -#define BT_UUID_SERVICE_A BT_UUID_DECLARE_16(0xa00a) - -/** - * @brief UUID for the Value V1 Characteristic - */ -#define BT_UUID_VALUE_V1 BT_UUID_DECLARE_16(0xb001) - -/** - * @brief UUID for the Value V2 Characteristic - */ -#define BT_UUID_VALUE_V2 BT_UUID_DECLARE_16(0xb002) - -/** - * @brief UUID for the Value V3 Characteristic - */ -#define BT_UUID_VALUE_V3 BT_UUID_DECLARE_16(0xb003) - -static uint8_t value_v1_value = 0x01; -static uint8_t value_v2_value[] = { - '1', '1', '1', '1', '1', '2', '2', '2', '2', '2', '3', '3', '3', - '3', '3', '4', '4', '4', '4', '4', '5', '5', '5', '5', '5', '6', - '6', '6', '6', '6', '7', '7', '7', '7', '7', '8', '8', '8', '8', - '8', '9', '9', '9', '9', '9', '0', '0', '0', '0', '0', '\0' -}; -static uint8_t value_v3_value = 0x03; - -/** - * @brief Attribute read call back for the Value V1 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v1(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v1_value)); -} - -/** - * @brief Attribute read call back for the Value V2 string attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_str_value(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const char *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - strlen(value)); -} - -/** - * @brief Attribute write call back for the Value V2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v2(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - char *value = attr->user_data; - - if (offset >= sizeof(value_v2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute write call back for the Value V3 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v3(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(value_v3_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v3_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -static struct bt_gatt_attr service_a_3_attrs[] = { - BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_A, 0x70), - BT_GATT_H_INCLUDE_SERVICE(service_d_3_attrs, 0x71), - BT_GATT_H_INCLUDE_SERVICE(service_c_1_3_attrs, 0x72), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V1, - BT_GATT_CHRC_READ, - BT_GATT_PERM_READ, - read_value_v1, NULL, &value_v1_value, 0x73), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_str_value, write_value_v2, &value_v2_value, 0x75), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V3, - BT_GATT_CHRC_WRITE, - BT_GATT_PERM_WRITE, - NULL, write_value_v3, &value_v3_value, 0x77) -}; - -static struct bt_gatt_service service_a_3_svc = - BT_GATT_SERVICE(service_a_3_attrs); - -/** - * @brief Register the Service A and all its Characteristics... - */ -void service_a_3_init(void) -{ - bt_gatt_service_register(&service_a_3_svc); -} - -/** - * @brief Un-Register the Service A and all its Characteristics... - */ -void service_a_3_remove(void) -{ - bt_gatt_service_unregister(&service_a_3_svc); -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_3.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_3.h deleted file mode 100644 index 74546538728..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_a_3.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service A - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 3' - */ -#ifndef SERVICE_A_3_H -#define SERVICE_A_3_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_a_3_init(void); -void service_a_3_remove(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_A_3_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_1.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_1.c deleted file mode 100644 index cc34a404864..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_1.c +++ /dev/null @@ -1,312 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.1 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 1' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -/** - * @brief UUID for the Service B.1 - */ -#define BT_UUID_SERVICE_B_1 BT_UUID_DECLARE_16(0xa00b) - -/** - * @brief UUID for the Value V4 Characteristic - */ -#define BT_UUID_VALUE_V4 BT_UUID_DECLARE_16(0xb004) - -/** - * @brief UUID for the Long descriptor V2D1 Characteristic - */ -#define BT_UUID_LONG_DES_V2D1 BT_UUID_DECLARE_16(0xb012) - -static uint8_t value_v4_value = 0x04; -static uint8_t value_v4_1_value = 0x04; -static uint16_t server_cha_con_value; -static uint8_t value_v4_2_value = 0x04; -static uint8_t long_des_v2d1_value[] = { - 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x12, - 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, - 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x11, 0x22, 0x33, - 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x11, 0x22, 0x33 -}; -static uint8_t value_v4_3_value[] = { - 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x12, - 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, - 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x11, 0x22, 0x33, - 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x11, 0x22, 0x33 -}; -static uint8_t long_des_v2d1_1_value[] = { - 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x12, - 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, - 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x11, 0x22, 0x33, - 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x11, 0x22, 0x33 -}; - -/** - * @brief Attribute read call back for the Value V4 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v4(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v4_value)); -} - -/** - * @brief Attribute write call back for the Value V4 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v4(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(value_v4_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v4_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute read call back for the Value V4 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v4_1(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v4_1_value)); -} - -/** - * @brief Attribute write call back for the Value V4 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v4_1(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(value_v4_1_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v4_1_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute read call back for the Server Characteristic Configuration - * attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_server_cha_con(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint16_t *value = attr->user_data; - uint16_t server_cha_con_conv = sys_cpu_to_le16(*value); - - return bt_gatt_attr_read(conn, attr, buf, len, offset, - &server_cha_con_conv, - sizeof(server_cha_con_conv)); -} - -/** - * @brief Attribute write call back for the Server Characteristic Configuration - * attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_server_cha_con(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - uint16_t *value = attr->user_data; - uint16_t server_cha_con_conv = sys_cpu_to_le16(*value); - - if (offset >= sizeof(server_cha_con_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(server_cha_con_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy((uint8_t *)&server_cha_con_conv + offset, buf, len); - - *value = sys_le16_to_cpu(server_cha_con_conv); - - return len; -} - -/** - * @brief Attribute read call back for the Value V4 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v4_3(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v4_3_value)); -} - -/** - * @brief Attribute read call back for the Long descriptor V2D1 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_long_des_v2d1_1(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(long_des_v2d1_1_value)); -} - -#define BT_GATT_CHRC_NONE 0 - -static struct bt_gatt_attr service_b_1_1_attrs[] = { - BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_B_1, 0x60), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V4, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE_AUTHEN, - read_value_v4, write_value_v4, &value_v4_value, 0x61), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V4, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_value_v4_1, write_value_v4_1, &value_v4_1_value, 0x63), - BT_GATT_H_DESCRIPTOR(BT_UUID_GATT_SCC, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_server_cha_con, write_server_cha_con, - &server_cha_con_value, 0x65), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V4, - BT_GATT_CHRC_NONE, - BT_GATT_PERM_NONE, - NULL, NULL, &value_v4_2_value, 0x66), - BT_GATT_H_DESCRIPTOR(BT_UUID_LONG_DES_V2D1, - BT_GATT_PERM_NONE, - NULL, NULL, &long_des_v2d1_value, 0x68), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V4, - BT_GATT_CHRC_READ, - BT_GATT_PERM_READ, - read_value_v4_3, NULL, &value_v4_3_value, 0x69), - BT_GATT_H_DESCRIPTOR(BT_UUID_LONG_DES_V2D1, - BT_GATT_PERM_READ, - read_long_des_v2d1_1, NULL, &long_des_v2d1_1_value, 0x6B) -}; - -static struct bt_gatt_service service_b_1_1_svc = - BT_GATT_SERVICE(service_b_1_1_attrs); - -/** - * @brief Register the Service B.1 and all its Characteristics... - */ -void service_b_1_1_init(void) -{ - bt_gatt_service_register(&service_b_1_1_svc); -} - -/** - * @brief Un-Register the Service B.1 and all its Characteristics... - */ -void service_b_1_1_remove(void) -{ - bt_gatt_service_unregister(&service_b_1_1_svc); -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_1.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_1.h deleted file mode 100644 index 3e5385a61ac..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_1.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.1 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 1' - */ -#ifndef SERVICE_B_1_1_H -#define SERVICE_B_1_1_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_b_1_1_init(void); -void service_b_1_1_remove(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_B_1_1_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_2.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_2.c deleted file mode 100644 index f73fb657d9e..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_2.c +++ /dev/null @@ -1,107 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.1 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 2' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -/** - * @brief UUID for the Service B.1 - */ -#define BT_UUID_SERVICE_B_1 BT_UUID_DECLARE_16(0xa00b) - -/** - * @brief UUID for the Value V4 Characteristic - */ -#define BT_UUID_VALUE_V4 BT_UUID_DECLARE_16(0xb004) - -static uint8_t value_v4_value = 0x04; - -/** - * @brief Attribute read call back for the Value V4 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v4(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v4_value)); -} - -/** - * @brief Attribute write call back for the Value V4 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v4(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(value_v4_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v4_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -struct bt_gatt_attr service_b_1_2_attrs[] = { - BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_B_1, 0x50), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V4, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_value_v4, write_value_v4, &value_v4_value, 0x51) -}; - -static struct bt_gatt_service service_b_1_2_svc = - BT_GATT_SERVICE(service_b_1_2_attrs); - -/** - * @brief Register the Service B.1 and all its Characteristics... - */ -void service_b_1_2_init(void) -{ - bt_gatt_service_register(&service_b_1_2_svc); -} - -/** - * @brief Un-Register the Service B.1 and all its Characteristics... - */ -void service_b_1_2_remove(void) -{ - bt_gatt_service_unregister(&service_b_1_2_svc); -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_2.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_2.h deleted file mode 100644 index 6c07da5b044..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_2.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.1 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 2' - */ -#ifndef SERVICE_B_1_2_H -#define SERVICE_B_1_2_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_b_1_2_init(void); -void service_b_1_2_remove(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_B_1_2_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_3.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_3.c deleted file mode 100644 index 0b397f15e0a..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_3.c +++ /dev/null @@ -1,107 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.1 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 3' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -/** - * @brief UUID for the Service B.1 - */ -#define BT_UUID_SERVICE_B_1 BT_UUID_DECLARE_16(0xa00b) - -/** - * @brief UUID for the Value V4 Characteristic - */ -#define BT_UUID_VALUE_V4 BT_UUID_DECLARE_16(0xb004) - -static uint8_t value_v4_value = 0x04; - -/** - * @brief Attribute read call back for the Value V4 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v4(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v4_value)); -} - -/** - * @brief Attribute write call back for the Value V4 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v4(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(value_v4_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v4_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -static struct bt_gatt_attr service_b_1_3_attrs[] = { - BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_B_1, 0x10), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V4, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_value_v4, write_value_v4, &value_v4_value, 0x11) -}; - -static struct bt_gatt_service service_b_1_3_svc = - BT_GATT_SERVICE(service_b_1_3_attrs); - -/** - * @brief Register the Service B.1 and all its Characteristics... - */ -void service_b_1_3_init(void) -{ - bt_gatt_service_register(&service_b_1_3_svc); -} - -/** - * @brief Un-Register the Service B.1 and all its Characteristics... - */ -void service_b_1_3_remove(void) -{ - bt_gatt_service_unregister(&service_b_1_3_svc); -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_3.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_3.h deleted file mode 100644 index 94bbb22d889..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_1_3.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.1 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 3' - */ -#ifndef SERVICE_B_1_3_H -#define SERVICE_B_1_3_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_b_1_3_init(void); -void service_b_1_3_remove(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_B_1_3_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_1.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_1.c deleted file mode 100644 index 5cafbbd59a0..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_1.c +++ /dev/null @@ -1,165 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.2 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 1' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -/** - * @brief UUID for the Service B.2 - */ -#define BT_UUID_SERVICE_B_2 BT_UUID_DECLARE_16(0xa00b) - -/** - * @brief UUID for the Value V5 Characteristic - */ -#define BT_UUID_VALUE_V5 BT_UUID_DECLARE_16(0xb005) - -/** - * @brief UUID for the Descriptor V5D4 (128-bit UUID) Characteristic - */ -#define BT_UUID_DES_V5D4__128_BIT_UUID BT_UUID_DECLARE_128( \ - 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \ - 0x00, 0x00, 0x00, 0x00, 0xd4, 0xd5, 0x00, 0x00) - -static uint8_t value_v5_value = 0x05; -static struct bt_gatt_cep cha_ext_pro_value = { 0x0003 }; -static uint8_t cha_user_des_value[] = { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', - 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - '\0' -}; -static const struct bt_gatt_cpf cha_format_value = { - 0x04, 0x00, 0x3001, 0x01, 0x3111 -}; -static uint8_t des_v5d4__128_bit_uuid_value = 0x44; -static bool bAuthorized; - -/** - * @brief Attribute read call back for the Value V5 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v5(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v5_value)); -} - -/** - * @brief Attribute write call back for the Value V5 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v5(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(value_v5_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v5_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - if (!bAuthorized) - return BT_GATT_ERR(BT_ATT_ERR_AUTHORIZATION); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute read call back for the Descriptor V5D4 (128-bit UUID) - * attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_des_v5d4__128_bit_uuid(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(des_v5d4__128_bit_uuid_value)); -} - -static struct bt_gatt_attr service_b_2_1_attrs[] = { - BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_B_2, 0x70), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V5, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE | BT_GATT_CHRC_EXT_PROP, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_value_v5, write_value_v5, &value_v5_value, 0x71), - BT_GATT_H_CEP(&cha_ext_pro_value, 0x73), - BT_GATT_H_CUD(cha_user_des_value, BT_GATT_PERM_READ, 0x74), - BT_GATT_H_CPF(&cha_format_value, 0x75), - BT_GATT_H_DESCRIPTOR(BT_UUID_DES_V5D4__128_BIT_UUID, - BT_GATT_PERM_READ, - read_des_v5d4__128_bit_uuid, NULL, - &des_v5d4__128_bit_uuid_value, 0x76) -}; - -static struct bt_gatt_service service_b_2_1_svc = - BT_GATT_SERVICE(service_b_2_1_attrs); - -/** - * @brief Register the Service B.2 and all its Characteristics... - */ -void service_b_2_1_init(void) -{ - bt_gatt_service_register(&service_b_2_1_svc); -} - -/** - * @brief Un-Register the Service B.2 and all its Characteristics... - */ -void service_b_2_1_remove(void) -{ - bt_gatt_service_unregister(&service_b_2_1_svc); -} - -/** - * @brief Set authorization for Characteristics and Descriptors in Service B.2. - */ -void service_b_2_1_authorize(bool authorized) -{ - bAuthorized = authorized; -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_1.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_1.h deleted file mode 100644 index 3bc184efc2d..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_1.h +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.2 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 1' - */ -#ifndef SERVICE_B_2_1_H -#define SERVICE_B_2_1_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_b_2_1_authorize(bool); -void service_b_2_1_init(void); -void service_b_2_1_remove(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_B_2_1_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_2.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_2.c deleted file mode 100644 index 7cc44c047db..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_2.c +++ /dev/null @@ -1,154 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.2 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 2' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -/** - * @brief UUID for the Service B.2 - */ -#define BT_UUID_SERVICE_B_2 BT_UUID_DECLARE_16(0xa00b) - -/** - * @brief UUID for the Value V5 Characteristic - */ -#define BT_UUID_VALUE_V5 BT_UUID_DECLARE_16(0xb005) - -/** - * @brief UUID for the Descriptor V5D4 (128-bit UUID) Characteristic - */ -#define BT_UUID_DES_V5D4__128_BIT_UUID BT_UUID_DECLARE_128( \ - 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \ - 0x00, 0x00, 0x00, 0x00, 0xd4, 0xd5, 0x00, 0x00) - -static uint8_t value_v5_value = 0x05; -static uint8_t des_v5d4__128_bit_uuid_value = 0x44; -static struct bt_gatt_cep cha_ext_pro_value = { 0x0003 }; -static uint8_t cha_user_des_value[] = { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', - 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - '\0' -}; -static const struct bt_gatt_cpf cha_format_value = { - 0x04, 0x00, 0x3001, 0x01, 0x3111 -}; - -/** - * @brief Attribute read call back for the Value V5 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v5(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v5_value)); -} - -/** - * @brief Attribute write call back for the Value V5 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v5(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(value_v5_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v5_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute read call back for the Descriptor V5D4 (128-bit UUID) - * attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_des_v5d4__128_bit_uuid(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(des_v5d4__128_bit_uuid_value)); -} - -static struct bt_gatt_attr service_b_2_2_attrs[] = { - BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_B_2, 0x90), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V5, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE | BT_GATT_CHRC_EXT_PROP, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_value_v5, write_value_v5, &value_v5_value, 0x91), - BT_GATT_H_DESCRIPTOR(BT_UUID_DES_V5D4__128_BIT_UUID, - BT_GATT_PERM_READ, - read_des_v5d4__128_bit_uuid, NULL, - &des_v5d4__128_bit_uuid_value, 0x93), - BT_GATT_H_CEP(&cha_ext_pro_value, 0x94), - BT_GATT_H_CUD(cha_user_des_value, BT_GATT_PERM_READ, 0x95), - BT_GATT_H_CPF(&cha_format_value, 0x96) -}; - -static struct bt_gatt_service service_b_2_2_svc = - BT_GATT_SERVICE(service_b_2_2_attrs); - -/** - * @brief Register the Service B.2 and all its Characteristics... - */ -void service_b_2_2_init(void) -{ - bt_gatt_service_register(&service_b_2_2_svc); -} - -/** - * @brief Un-Register the Service B.2 and all its Characteristics... - */ -void service_b_2_2_remove(void) -{ - bt_gatt_service_unregister(&service_b_2_2_svc); -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_2.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_2.h deleted file mode 100644 index 70c4b0dc506..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_2.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.2 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 2' - */ -#ifndef SERVICE_B_2_2_H -#define SERVICE_B_2_2_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_b_2_2_init(void); -void service_b_2_2_remove(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_B_2_2_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_3.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_3.c deleted file mode 100644 index bb73a58fa80..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_3.c +++ /dev/null @@ -1,154 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.2 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 3' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -/** - * @brief UUID for the Service B.2 - */ -#define BT_UUID_SERVICE_B_2 BT_UUID_DECLARE_16(0xa00b) - -/** - * @brief UUID for the Value V5 Characteristic - */ -#define BT_UUID_VALUE_V5 BT_UUID_DECLARE_16(0xb005) - -/** - * @brief UUID for the Descriptor V5D4 (128-bit UUID) Characteristic - */ -#define BT_UUID_DES_V5D4__128_BIT_UUID BT_UUID_DECLARE_128( \ - 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \ - 0x00, 0x00, 0x00, 0x00, 0xd4, 0xd5, 0x00, 0x00) - -static uint8_t value_v5_value = 0x05; -static uint8_t cha_user_des_value[] = { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', - 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - '\0' -}; -static struct bt_gatt_cep cha_ext_pro_value = { 0x0003 }; -static uint8_t des_v5d4__128_bit_uuid_value = 0x44; -static const struct bt_gatt_cpf cha_format_value = { - 0x04, 0x00, 0x3001, 0x01, 0x3111 -}; - -/** - * @brief Attribute read call back for the Value V5 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v5(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v5_value)); -} - -/** - * @brief Attribute write call back for the Value V5 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v5(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(value_v5_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v5_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute read call back for the Descriptor V5D4 (128-bit UUID) - * attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_des_v5d4__128_bit_uuid(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(des_v5d4__128_bit_uuid_value)); -} - -static struct bt_gatt_attr service_b_2_3_attrs[] = { - BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_B_2, 0x90), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V5, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE | BT_GATT_CHRC_EXT_PROP, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_value_v5, write_value_v5, &value_v5_value, 0x91), - BT_GATT_H_CUD(cha_user_des_value, BT_GATT_PERM_READ, 0x93), - BT_GATT_H_CEP(&cha_ext_pro_value, 0x94), - BT_GATT_H_DESCRIPTOR(BT_UUID_DES_V5D4__128_BIT_UUID, - BT_GATT_PERM_READ, - read_des_v5d4__128_bit_uuid, NULL, - &des_v5d4__128_bit_uuid_value, 0x95), - BT_GATT_H_CPF(&cha_format_value, 0x96) -}; - -static struct bt_gatt_service service_b_2_3_svc = - BT_GATT_SERVICE(service_b_2_3_attrs); - -/** - * @brief Register the Service B.2 and all its Characteristics... - */ -void service_b_2_3_init(void) -{ - bt_gatt_service_register(&service_b_2_3_svc); -} - -/** - * @brief Un-Register the Service B.2 and all its Characteristics... - */ -void service_b_2_3_remove(void) -{ - bt_gatt_service_unregister(&service_b_2_3_svc); -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_3.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_3.h deleted file mode 100644 index 8e908afdb7f..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_2_3.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.2 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 3' - */ -#ifndef SERVICE_B_2_3_H -#define SERVICE_B_2_3_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_b_2_3_init(void); -void service_b_2_3_remove(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_B_2_3_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_1.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_1.c deleted file mode 100644 index f7420612818..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_1.c +++ /dev/null @@ -1,135 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.3 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 1' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -/** - * @brief UUID for the Service B.3 - */ -#define BT_UUID_SERVICE_B_3 BT_UUID_DECLARE_16(0xa00b) - -/** - * @brief UUID for the Value V6 Characteristic - */ -#define BT_UUID_VALUE_V6 BT_UUID_DECLARE_16(0xb006) - -static uint8_t value_v6_value = 0x06; -static bool value_v6_ntf_active; - -/** - * @brief Attribute read call back for the Value V6 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v6(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v6_value)); -} - -/** - * @brief Attribute write call back for the Value V6 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v6(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(value_v6_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v6_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Descriptor configuration change call back for the Value V6 attribute - * - * @param attr The attribute whose descriptor configuration has changed - * @param value The new value of the descriptor configuration - */ -static void value_v6_ccc_cfg_changed(const struct bt_gatt_attr *attr, - uint16_t value) -{ - value_v6_ntf_active = value == BT_GATT_CCC_NOTIFY; -} - -static struct bt_gatt_attr service_b_3_1_attrs[] = { - BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_B_3, 0x50), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V6, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE_WITHOUT_RESP | - BT_GATT_CHRC_WRITE | BT_GATT_CHRC_NOTIFY, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_value_v6, write_value_v6, &value_v6_value, 0x51), - BT_GATT_H_CCC(value_v6_ccc_cfg, value_v6_ccc_cfg_changed, 0x53) -}; - -static struct bt_gatt_service service_b_3_1_svc = - BT_GATT_SERVICE(service_b_3_1_attrs); - -/** - * @brief Register the Service B.3 and all its Characteristics... - */ -void service_b_3_1_init(void) -{ - bt_gatt_service_register(&service_b_3_1_svc); -} - -/** - * @brief Un-Register the Service B.3 and all its Characteristics... - */ -void service_b_3_1_remove(void) -{ - bt_gatt_service_unregister(&service_b_3_1_svc); -} - -/** - * @brief Generate notification for 'Value V6' attribute, if notifications are - * enabled. - */ -void service_b_3_1_value_v6_notify(void) -{ - if (!value_v6_ntf_active) - return; - - bt_gatt_notify(NULL, &service_b_3_1_attrs[1], &value_v6_value, - sizeof(value_v6_value)); -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_1.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_1.h deleted file mode 100644 index d15575b15a0..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_1.h +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.3 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 1' - */ -#ifndef SERVICE_B_3_1_H -#define SERVICE_B_3_1_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_b_3_1_init(void); -void service_b_3_1_remove(void); -void service_b_3_1_value_v6_notify(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_B_3_1_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_2.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_2.c deleted file mode 100644 index 95020b8fbf0..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_2.c +++ /dev/null @@ -1,176 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.3 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 2' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -/** - * @brief UUID for the Service B.3 - */ -#define BT_UUID_SERVICE_B_3 BT_UUID_DECLARE_16(0xa00b) - -/** - * @brief UUID for the Value V6 Characteristic - */ -#define BT_UUID_VALUE_V6 BT_UUID_DECLARE_16(0xb006) - -static uint8_t value_v6_value = 0x06; -static struct bt_gatt_indicate_params ind_params; -static bool value_v6_ntf_active; -static bool value_v6_ind_active; - -/** - * @brief Attribute read call back for the Value V6 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v6(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v6_value)); -} - -/** - * @brief Attribute write call back for the Value V6 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v6(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(value_v6_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v6_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Descriptor configuration change call back for the Value V6 attribute - * - * @param attr The attribute whose descriptor configuration has changed - * @param value The new value of the descriptor configuration - */ -static void value_v6_ccc_cfg_changed(const struct bt_gatt_attr *attr, - uint16_t value) -{ - value_v6_ntf_active = value == BT_GATT_CCC_NOTIFY; - value_v6_ind_active = value == BT_GATT_CCC_INDICATE; -} - -static struct bt_gatt_attr service_b_3_2_attrs[] = { - BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_B_3, 0x70), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V6, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE_WITHOUT_RESP | - BT_GATT_CHRC_WRITE | BT_GATT_CHRC_NOTIFY | - BT_GATT_CHRC_INDICATE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_value_v6, write_value_v6, &value_v6_value, 0x71), - BT_GATT_H_CCC(value_v6_ccc_cfg, value_v6_ccc_cfg_changed, 0x73) -}; - -static struct bt_gatt_service service_b_3_2_svc = - BT_GATT_SERVICE(service_b_3_2_attrs); - -/** - * @brief Register the Service B.3 and all its Characteristics... - */ -void service_b_3_2_init(void) -{ - bt_gatt_service_register(&service_b_3_2_svc); -} - -/** - * @brief Un-Register the Service B.3 and all its Characteristics... - */ -void service_b_3_2_remove(void) -{ - bt_gatt_service_unregister(&service_b_3_2_svc); -} - -/** - * @brief Generate notification for 'Value V6' attribute, if notifications are - * enabled. - */ -void service_b_3_2_value_v6_notify(void) -{ - if (!value_v6_ntf_active) - return; - - bt_gatt_notify(NULL, &service_b_3_2_attrs[1], &value_v6_value, - sizeof(value_v6_value)); -} - -/** - * @brief Indication call back for 'Value V6' attribute - * - * @param conn The connection for which the indication was generated - * @param attr The attribute that generated the indication - * @param err The error code from the indicate attempt, 0 if no error or - * BT_GATT_ERR() with a specific ATT error code. - */ -static void value_v6_indicate_cb(struct bt_conn *conn, - struct bt_gatt_indicate_params *params, - uint8_t err) -{ - printk("Indication for attribute 'Value V6' %s\n", - (err) ? "failed" : "succeded"); -} - -/** - * @brief Generate indication for 'Value V6' attribute, if indications are - * enabled. - */ -void service_b_3_2_value_v6_indicate(void) -{ - if (!value_v6_ind_active) - return; - /* - * NOTE: Zephyr doesn't automatically bump up the attribute pointer for - * indications as it does for notifications. - */ - ind_params.attr = &service_b_3_2_attrs[2]; - ind_params.func = value_v6_indicate_cb; - ind_params.destroy = NULL; - ind_params.data = &value_v6_value; - ind_params.len = sizeof(value_v6_value); - - bt_gatt_indicate(NULL, &ind_params); -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_2.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_2.h deleted file mode 100644 index 2f36b6609ca..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_2.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.3 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 2' - */ -#ifndef SERVICE_B_3_2_H -#define SERVICE_B_3_2_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_b_3_2_init(void); -void service_b_3_2_remove(void); -void service_b_3_2_value_v6_notify(void); -void service_b_3_2_value_v6_indicate(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_B_3_2_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_3.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_3.c deleted file mode 100644 index 3a8fe5ba903..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_3.c +++ /dev/null @@ -1,176 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.3 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 3' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -/** - * @brief UUID for the Service B.3 - */ -#define BT_UUID_SERVICE_B_3 BT_UUID_DECLARE_16(0xa00b) - -/** - * @brief UUID for the Value V6 Characteristic - */ -#define BT_UUID_VALUE_V6 BT_UUID_DECLARE_16(0xb006) - -static uint8_t value_v6_value = 0x06; -static struct bt_gatt_indicate_params ind_params; -static bool value_v6_ntf_active; -static bool value_v6_ind_active; - -/** - * @brief Attribute read call back for the Value V6 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v6(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v6_value)); -} - -/** - * @brief Attribute write call back for the Value V6 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v6(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(value_v6_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v6_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Descriptor configuration change call back for the Value V6 attribute - * - * @param attr The attribute whose descriptor configuration has changed - * @param value The new value of the descriptor configuration - */ -static void value_v6_ccc_cfg_changed(const struct bt_gatt_attr *attr, - uint16_t value) -{ - value_v6_ntf_active = value == BT_GATT_CCC_NOTIFY; - value_v6_ind_active = value == BT_GATT_CCC_INDICATE; -} - -static struct bt_gatt_attr service_b_3_3_attrs[] = { - BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_B_3, 0x50), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V6, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE_WITHOUT_RESP | - BT_GATT_CHRC_WRITE | BT_GATT_CHRC_NOTIFY | - BT_GATT_CHRC_INDICATE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_value_v6, write_value_v6, &value_v6_value, 0x51), - BT_GATT_H_CCC(value_v6_ccc_cfg, value_v6_ccc_cfg_changed, 0x53) -}; - -static struct bt_gatt_service service_b_3_3_svc = - BT_GATT_SERVICE(service_b_3_3_attrs); - -/** - * @brief Register the Service B.3 and all its Characteristics... - */ -void service_b_3_3_init(void) -{ - bt_gatt_service_register(&service_b_3_3_svc); -} - -/** - * @brief Un-Register the Service B.3 and all its Characteristics... - */ -void service_b_3_3_remove(void) -{ - bt_gatt_service_unregister(&service_b_3_3_svc); -} - -/** - * @brief Generate notification for 'Value V6' attribute, if notifications are - * enabled. - */ -void service_b_3_3_value_v6_notify(void) -{ - if (!value_v6_ntf_active) - return; - - bt_gatt_notify(NULL, &service_b_3_3_attrs[1], &value_v6_value, - sizeof(value_v6_value)); -} - -/** - * @brief Indication call back for 'Value V6' attribute - * - * @param conn The connection for which the indication was generated - * @param attr The attribute that generated the indication - * @param err The error code from the indicate attempt, 0 if no error or - * BT_GATT_ERR() with a specific ATT error code. - */ -static void value_v6_indicate_cb(struct bt_conn *conn, - struct bt_gatt_indicate_params *params, - uint8_t err) -{ - printk("Indication for attribute 'Value V6' %s\n", - (err) ? "failed" : "succeeded"); -} - -/** - * @brief Generate indication for 'Value V6' attribute, if indications are - * enabled. - */ -void service_b_3_3_value_v6_indicate(void) -{ - if (!value_v6_ind_active) - return; - /* - * NOTE: Zephyr doesn't automatically bump up the attribute pointer for - * indications as it does for notifications. - */ - ind_params.attr = &service_b_3_3_attrs[2]; - ind_params.func = value_v6_indicate_cb; - ind_params.destroy = NULL; - ind_params.data = &value_v6_value; - ind_params.len = sizeof(value_v6_value); - - bt_gatt_indicate(NULL, &ind_params); -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_3.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_3.h deleted file mode 100644 index 48eed9a6d72..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_3_3.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.3 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 3' - */ -#ifndef SERVICE_B_3_3_H -#define SERVICE_B_3_3_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_b_3_3_init(void); -void service_b_3_3_remove(void); -void service_b_3_3_value_v6_notify(void); -void service_b_3_3_value_v6_indicate(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_B_3_3_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_1.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_1.c deleted file mode 100644 index 51c3ee4a2e7..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_1.c +++ /dev/null @@ -1,85 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.4 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 1' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -/** - * @brief UUID for the Service B.4 - */ -#define BT_UUID_SERVICE_B_4 BT_UUID_DECLARE_16(0xa00b) - -/** - * @brief UUID for the Value V7 Characteristic - */ -#define BT_UUID_VALUE_V7 BT_UUID_DECLARE_16(0xb007) - -static uint8_t value_v7_value = 0x07; - -/** - * @brief Attribute write call back for the Value V7 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v7(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(value_v7_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v7_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -static struct bt_gatt_attr service_b_4_1_attrs[] = { - BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_B_4, 0x30), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V7, - BT_GATT_CHRC_WRITE, - BT_GATT_PERM_WRITE, - NULL, write_value_v7, &value_v7_value, 0x31) -}; - -static struct bt_gatt_service service_b_4_1_svc = - BT_GATT_SERVICE(service_b_4_1_attrs); - -/** - * @brief Register the Service B.4 and all its Characteristics... - */ -void service_b_4_1_init(void) -{ - bt_gatt_service_register(&service_b_4_1_svc); -} - -/** - * @brief Un-Register the Service B.4 and all its Characteristics... - */ -void service_b_4_1_remove(void) -{ - bt_gatt_service_unregister(&service_b_4_1_svc); -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_1.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_1.h deleted file mode 100644 index 5376641348d..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_1.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.4 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 1' - */ -#ifndef SERVICE_B_4_1_H -#define SERVICE_B_4_1_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_b_4_1_init(void); -void service_b_4_1_remove(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_B_4_1_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_2.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_2.c deleted file mode 100644 index 96b7dc4ad94..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_2.c +++ /dev/null @@ -1,85 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.4 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 2' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -/** - * @brief UUID for the Service B.4 - */ -#define BT_UUID_SERVICE_B_4 BT_UUID_DECLARE_16(0xa00b) - -/** - * @brief UUID for the Value V7 Characteristic - */ -#define BT_UUID_VALUE_V7 BT_UUID_DECLARE_16(0xb007) - -static uint8_t value_v7_value = 0x07; - -/** - * @brief Attribute write call back for the Value V7 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v7(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(value_v7_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v7_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -static struct bt_gatt_attr service_b_4_2_attrs[] = { - BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_B_4, 0x30), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V7, - BT_GATT_CHRC_WRITE, - BT_GATT_PERM_WRITE, - NULL, write_value_v7, &value_v7_value, 0x31) -}; - -static struct bt_gatt_service service_b_4_2_svc = - BT_GATT_SERVICE(service_b_4_2_attrs); - -/** - * @brief Register the Service B.4 and all its Characteristics... - */ -void service_b_4_2_init(void) -{ - bt_gatt_service_register(&service_b_4_2_svc); -} - -/** - * @brief Un-Register the Service B.4 and all its Characteristics... - */ -void service_b_4_2_remove(void) -{ - bt_gatt_service_unregister(&service_b_4_2_svc); -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_2.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_2.h deleted file mode 100644 index 3990e96e4ee..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_2.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.4 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 2' - */ -#ifndef SERVICE_B_4_2_H -#define SERVICE_B_4_2_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_b_4_2_init(void); -void service_b_4_2_remove(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_B_4_2_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_3.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_3.c deleted file mode 100644 index 8e5df398c6d..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_3.c +++ /dev/null @@ -1,85 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.4 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 3' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -/** - * @brief UUID for the Service B.4 - */ -#define BT_UUID_SERVICE_B_4 BT_UUID_DECLARE_16(0xa00b) - -/** - * @brief UUID for the Value V7 Characteristic - */ -#define BT_UUID_VALUE_V7 BT_UUID_DECLARE_16(0xb007) - -static uint8_t value_v7_value = 0x07; - -/** - * @brief Attribute write call back for the Value V7 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v7(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(value_v7_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v7_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -static struct bt_gatt_attr service_b_4_3_attrs[] = { - BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_B_4, 0x40), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V7, - BT_GATT_CHRC_WRITE, - BT_GATT_PERM_WRITE, - NULL, write_value_v7, &value_v7_value, 0x41) -}; - -static struct bt_gatt_service service_b_4_3_svc = - BT_GATT_SERVICE(service_b_4_3_attrs); - -/** - * @brief Register the Service B.4 and all its Characteristics... - */ -void service_b_4_3_init(void) -{ - bt_gatt_service_register(&service_b_4_3_svc); -} - -/** - * @brief Un-Register the Service B.4 and all its Characteristics... - */ -void service_b_4_3_remove(void) -{ - bt_gatt_service_unregister(&service_b_4_3_svc); -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_3.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_3.h deleted file mode 100644 index bcfa123fb7d..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_4_3.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.4 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 3' - */ -#ifndef SERVICE_B_4_3_H -#define SERVICE_B_4_3_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_b_4_3_init(void); -void service_b_4_3_remove(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_B_4_3_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_1.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_1.c deleted file mode 100644 index 2c3334d530a..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_1.c +++ /dev/null @@ -1,301 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.5 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 1' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -/** - * @brief UUID for the Service B.5 - */ -#define BT_UUID_SERVICE_B_5 BT_UUID_DECLARE_16(0xa00b) - -/** - * @brief UUID for the Value V8 Characteristic - */ -#define BT_UUID_VALUE_V8 BT_UUID_DECLARE_16(0xb008) - -/** - * @brief UUID for the Descriptor V8D1 Characteristic - */ -#define BT_UUID_DES_V8D1 BT_UUID_DECLARE_16(0xb015) - -/** - * @brief UUID for the Descriptor V8D2 Characteristic - */ -#define BT_UUID_DES_V8D2 BT_UUID_DECLARE_16(0xb016) - -/** - * @brief UUID for the Descriptor V8D3 Characteristic - */ -#define BT_UUID_DES_V8D3 BT_UUID_DECLARE_16(0xb017) - -static uint8_t value_v8_value = 0x08; -static uint8_t des_v8d1_value = 0x01; -static uint8_t des_v8d2_value = 0x02; -static uint8_t des_v8d3_value = 0x03; -static bool bAuthorized; - -/** - * @brief Attribute read call back for the Value V8 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v8(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v8_value)); -} - -/** - * @brief Attribute write call back for the Value V8 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v8(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(value_v8_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v8_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute read call back for the Descriptor V8D1 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_des_v8d1(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(des_v8d1_value)); -} - -/** - * @brief Attribute write call back for the Descriptor V8D1 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_des_v8d1(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(des_v8d1_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(des_v8d1_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute read call back for the Descriptor V8D2 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_des_v8d2(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - if (!bAuthorized) - return BT_GATT_ERR(BT_ATT_ERR_AUTHORIZATION); - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(des_v8d2_value)); -} - -/** - * @brief Attribute write call back for the Descriptor V8D2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_des_v8d2(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(des_v8d2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(des_v8d2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - if (!bAuthorized) - return BT_GATT_ERR(BT_ATT_ERR_AUTHORIZATION); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute read call back for the Descriptor V8D3 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_des_v8d3(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(des_v8d3_value)); -} - -/** - * @brief Attribute write call back for the Descriptor V8D3 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_des_v8d3(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(des_v8d3_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(des_v8d3_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -struct bt_gatt_attr service_b_5_1_attrs[] = { - BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_B_5, 0x80), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V8, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE_ENCRYPT, - read_value_v8, write_value_v8, &value_v8_value, 0x81), - BT_GATT_H_DESCRIPTOR(BT_UUID_DES_V8D1, - BT_GATT_PERM_READ_AUTHEN | BT_GATT_PERM_WRITE_AUTHEN, - read_des_v8d1, write_des_v8d1, &des_v8d1_value, 0x83), - BT_GATT_H_DESCRIPTOR(BT_UUID_DES_V8D2, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_des_v8d2, write_des_v8d2, &des_v8d2_value, 0x84), - BT_GATT_H_DESCRIPTOR(BT_UUID_DES_V8D3, - BT_GATT_PERM_READ_ENCRYPT | BT_GATT_PERM_WRITE_ENCRYPT, - read_des_v8d3, write_des_v8d3, &des_v8d3_value, 0x85) -}; - -static struct bt_gatt_service service_b_5_1_svc = - BT_GATT_SERVICE(service_b_5_1_attrs); - -/** - * @brief Register the Service B.5 and all its Characteristics... - */ -void service_b_5_1_init(void) -{ - bt_gatt_service_register(&service_b_5_1_svc); -} - -/** - * @brief Un-Register the Service B.5 and all its Characteristics... - */ -void service_b_5_1_remove(void) -{ - bt_gatt_service_unregister(&service_b_5_1_svc); -} - -/** - * @brief Set authorization for Characteristics and Descriptors in Service B.5. - */ -void service_b_5_1_authorize(bool authorized) -{ - bAuthorized = authorized; -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_1.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_1.h deleted file mode 100644 index c6ad58856fa..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_1.h +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.5 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 1' - */ -#ifndef SERVICE_B_5_1_H -#define SERVICE_B_5_1_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_b_5_1_authorize(bool); -void service_b_5_1_init(void); -void service_b_5_1_remove(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_B_5_1_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_2.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_2.c deleted file mode 100644 index 404c4f46553..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_2.c +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.5 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 2' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -/** - * @brief UUID for the Service B.5 - */ -#define BT_UUID_SERVICE_B_5 BT_UUID_DECLARE_16(0xa00b) - -/** - * @brief UUID for the Value V8 Characteristic - */ -#define BT_UUID_VALUE_V8 BT_UUID_DECLARE_16(0xb008) - -static uint8_t value_v8_value = 0x08; - -/** - * @brief Attribute read call back for the Value V8 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v8(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v8_value)); -} - -static struct bt_gatt_attr service_b_5_2_attrs[] = { - BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_B_5, 0xA0), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V8, - BT_GATT_CHRC_READ, - BT_GATT_PERM_READ, - read_value_v8, NULL, &value_v8_value, 0xA1) -}; - -static struct bt_gatt_service service_b_5_2_svc = - BT_GATT_SERVICE(service_b_5_2_attrs); - -/** - * @brief Register the Service B.5 and all its Characteristics... - */ -void service_b_5_2_init(void) -{ - bt_gatt_service_register(&service_b_5_2_svc); -} - -/** - * @brief Un-Register the Service B.5 and all its Characteristics... - */ -void service_b_5_2_remove(void) -{ - bt_gatt_service_unregister(&service_b_5_2_svc); -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_2.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_2.h deleted file mode 100644 index 0b62aee8244..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_2.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.5 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 2' - */ -#ifndef SERVICE_B_5_2_H -#define SERVICE_B_5_2_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_b_5_2_init(void); -void service_b_5_2_remove(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_B_5_2_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_3.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_3.c deleted file mode 100644 index 27b14e662aa..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_3.c +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.5 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 3' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -/** - * @brief UUID for the Service B.5 - */ -#define BT_UUID_SERVICE_B_5 BT_UUID_DECLARE_16(0xa00b) - -/** - * @brief UUID for the Value V8 Characteristic - */ -#define BT_UUID_VALUE_V8 BT_UUID_DECLARE_16(0xb008) - -static uint8_t value_v8_value = 0x08; - -/** - * @brief Attribute read call back for the Value V8 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v8(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v8_value)); -} - -static struct bt_gatt_attr service_b_5_3_attrs[] = { - BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_B_5, 0x30), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V8, - BT_GATT_CHRC_READ, - BT_GATT_PERM_READ, - read_value_v8, NULL, &value_v8_value, 0x31) -}; - -static struct bt_gatt_service service_b_5_3_svc = - BT_GATT_SERVICE(service_b_5_3_attrs); - -/** - * @brief Register the Service B.5 and all its Characteristics... - */ -void service_b_5_3_init(void) -{ - bt_gatt_service_register(&service_b_5_3_svc); -} - -/** - * @brief Un-Register the Service B.5 and all its Characteristics... - */ -void service_b_5_3_remove(void) -{ - bt_gatt_service_unregister(&service_b_5_3_svc); -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_3.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_3.h deleted file mode 100644 index 3dd459e76b4..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_b_5_3.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service B.5 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 3' - */ -#ifndef SERVICE_B_5_3_H -#define SERVICE_B_5_3_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_b_5_3_init(void); -void service_b_5_3_remove(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_B_5_3_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_1.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_1.c deleted file mode 100644 index b9668a9fa8e..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_1.c +++ /dev/null @@ -1,227 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service C.1 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 1' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -extern struct bt_gatt_attr service_d_1_attrs[]; - -/** - * @brief UUID for the Service C.1 - */ -#define BT_UUID_SERVICE_C_1 BT_UUID_DECLARE_128( \ - 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \ - 0x00, 0x00, 0x00, 0x00, 0x0c, 0xa0, 0x00, 0x00) - -/** - * @brief UUID for the Value V9 (128-bit UUID) Characteristic - */ -#define BT_UUID_VALUE_V9__128_BIT_UUID BT_UUID_DECLARE_128( \ - 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \ - 0x00, 0x00, 0x00, 0x00, 0x09, 0xb0, 0x00, 0x00) - -/** - * @brief UUID for the Descriptor V9D2 (128-bit UUID) Characteristic - */ -#define BT_UUID_DES_V9D2__128_BIT_UUID BT_UUID_DECLARE_128( \ - 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \ - 0x00, 0x00, 0x00, 0x00, 0xd2, 0xd9, 0x00, 0x00) - -/** - * @brief UUID for the Descriptor V9D3 (128-bit UUID) Characteristic - */ -#define BT_UUID_DES_V9D3__128_BIT_UUID BT_UUID_DECLARE_128( \ - 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \ - 0x00, 0x00, 0x00, 0x00, 0xd3, 0xd9, 0x00, 0x00) - -static uint8_t value_v9__128_bit_uuid_value = 0x09; -static struct bt_gatt_cep cha_ext_pro_value = { 0x0001 }; -static uint8_t des_v9d2__128_bit_uuid_value = 0x22; -static uint8_t des_v9d3__128_bit_uuid_value = 0x33; - -/** - * @brief Attribute read call back for the Value V9 (128-bit UUID) attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v9__128_bit_uuid(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v9__128_bit_uuid_value)); -} - -/** - * @brief Attribute write call back for the Value V9 (128-bit UUID) attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v9__128_bit_uuid(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, - uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(value_v9__128_bit_uuid_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v9__128_bit_uuid_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute read call back for the Descriptor V9D2 (128-bit UUID) - * attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_des_v9d2__128_bit_uuid(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(des_v9d2__128_bit_uuid_value)); -} - -/** - * @brief Attribute write call back for the Descriptor V9D2 (128-bit UUID) - * attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_des_v9d2__128_bit_uuid(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, - uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(des_v9d2__128_bit_uuid_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(des_v9d2__128_bit_uuid_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute write call back for the Descriptor V9D3 (128-bit UUID) - * attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_des_v9d3__128_bit_uuid(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, - uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(des_v9d3__128_bit_uuid_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(des_v9d3__128_bit_uuid_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -static struct bt_gatt_attr service_c_1_1_attrs[] = { - BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_C_1, 0x90), - BT_GATT_H_INCLUDE_SERVICE(service_d_1_attrs, 0x91), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V9__128_BIT_UUID, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE | BT_GATT_CHRC_EXT_PROP, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_value_v9__128_bit_uuid, write_value_v9__128_bit_uuid, - &value_v9__128_bit_uuid_value, 0x92), - BT_GATT_H_CEP(&cha_ext_pro_value, 0x94), - BT_GATT_H_DESCRIPTOR(BT_UUID_DES_V9D2__128_BIT_UUID, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_des_v9d2__128_bit_uuid, write_des_v9d2__128_bit_uuid, - &des_v9d2__128_bit_uuid_value, 0x95), - BT_GATT_H_DESCRIPTOR(BT_UUID_DES_V9D3__128_BIT_UUID, - BT_GATT_PERM_WRITE, - NULL, write_des_v9d3__128_bit_uuid, - &des_v9d3__128_bit_uuid_value, 0x96) -}; - -static struct bt_gatt_service service_c_1_1_svc = - BT_GATT_SERVICE(service_c_1_1_attrs); - -/** - * @brief Register the Service C.1 and all its Characteristics... - */ -void service_c_1_1_init(void) -{ - bt_gatt_service_register(&service_c_1_1_svc); -} - -/** - * @brief Un-Register the Service C.1 and all its Characteristics... - */ -void service_c_1_1_remove(void) -{ - bt_gatt_service_unregister(&service_c_1_1_svc); -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_1.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_1.h deleted file mode 100644 index a6370bfcb28..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_1.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service C.1 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 1' - */ -#ifndef SERVICE_C_1_1_H -#define SERVICE_C_1_1_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_c_1_1_init(void); -void service_c_1_1_remove(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_C_1_1_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_2.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_2.c deleted file mode 100644 index c148ee2a7a5..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_2.c +++ /dev/null @@ -1,227 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service C.1 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 2' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -extern struct bt_gatt_attr service_d_2_attrs[]; - -/** - * @brief UUID for the Service C.1 - */ -#define BT_UUID_SERVICE_C_1 BT_UUID_DECLARE_128( \ - 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \ - 0x00, 0x00, 0x00, 0x00, 0x0c, 0xa0, 0x00, 0x00) - -/** - * @brief UUID for the Value V9 (128-bit UUID) Characteristic - */ -#define BT_UUID_VALUE_V9__128_BIT_UUID BT_UUID_DECLARE_128( \ - 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \ - 0x00, 0x00, 0x00, 0x00, 0x09, 0xb0, 0x00, 0x00) - -/** - * @brief UUID for the Descriptor V9D2 (128-bit UUID) Characteristic - */ -#define BT_UUID_DES_V9D2__128_BIT_UUID BT_UUID_DECLARE_128( \ - 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \ - 0x00, 0x00, 0x00, 0x00, 0xd2, 0xd9, 0x00, 0x00) - -/** - * @brief UUID for the Descriptor V9D3 (128-bit UUID) Characteristic - */ -#define BT_UUID_DES_V9D3__128_BIT_UUID BT_UUID_DECLARE_128( \ - 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \ - 0x00, 0x00, 0x00, 0x00, 0xd3, 0xd9, 0x00, 0x00) - -static uint8_t value_v9__128_bit_uuid_value = 0x09; -static uint8_t des_v9d2__128_bit_uuid_value = 0x22; -static uint8_t des_v9d3__128_bit_uuid_value = 0x33; -static struct bt_gatt_cep cha_ext_pro_value = { 0x0001 }; - -/** - * @brief Attribute read call back for the Value V9 (128-bit UUID) attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v9__128_bit_uuid(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v9__128_bit_uuid_value)); -} - -/** - * @brief Attribute write call back for the Value V9 (128-bit UUID) attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v9__128_bit_uuid(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, - uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(value_v9__128_bit_uuid_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v9__128_bit_uuid_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute read call back for the Descriptor V9D2 (128-bit UUID) - * attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_des_v9d2__128_bit_uuid(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(des_v9d2__128_bit_uuid_value)); -} - -/** - * @brief Attribute write call back for the Descriptor V9D2 (128-bit UUID) - * attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_des_v9d2__128_bit_uuid(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, - uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(des_v9d2__128_bit_uuid_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(des_v9d2__128_bit_uuid_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute write call back for the Descriptor V9D3 (128-bit UUID) - * attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_des_v9d3__128_bit_uuid(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, - uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(des_v9d3__128_bit_uuid_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(des_v9d3__128_bit_uuid_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -struct bt_gatt_attr service_c_1_2_attrs[] = { - BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_C_1, 0x20), - BT_GATT_H_INCLUDE_SERVICE(service_d_2_attrs, 0x21), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V9__128_BIT_UUID, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE | BT_GATT_CHRC_EXT_PROP, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_value_v9__128_bit_uuid, write_value_v9__128_bit_uuid, - &value_v9__128_bit_uuid_value, 0x22), - BT_GATT_H_DESCRIPTOR(BT_UUID_DES_V9D2__128_BIT_UUID, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_des_v9d2__128_bit_uuid, write_des_v9d2__128_bit_uuid, - &des_v9d2__128_bit_uuid_value, 0x24), - BT_GATT_H_DESCRIPTOR(BT_UUID_DES_V9D3__128_BIT_UUID, - BT_GATT_PERM_WRITE, - NULL, write_des_v9d3__128_bit_uuid, - &des_v9d3__128_bit_uuid_value, 0x25), - BT_GATT_H_CEP(&cha_ext_pro_value, 0x26) -}; - -static struct bt_gatt_service service_c_1_2_svc = - BT_GATT_SERVICE(service_c_1_2_attrs); - -/** - * @brief Register the Service C.1 and all its Characteristics... - */ -void service_c_1_2_init(void) -{ - bt_gatt_service_register(&service_c_1_2_svc); -} - -/** - * @brief Un-Register the Service C.1 and all its Characteristics... - */ -void service_c_1_2_remove(void) -{ - bt_gatt_service_unregister(&service_c_1_2_svc); -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_2.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_2.h deleted file mode 100644 index ffb04502817..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_2.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service C.1 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 2' - */ -#ifndef SERVICE_C_1_2_H -#define SERVICE_C_1_2_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_c_1_2_init(void); -void service_c_1_2_remove(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_C_1_2_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_3.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_3.c deleted file mode 100644 index 04d8b06c0e5..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_3.c +++ /dev/null @@ -1,224 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service C.1 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 3' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -/** - * @brief UUID for the Service C.1 - */ -#define BT_UUID_SERVICE_C_1 BT_UUID_DECLARE_128( \ - 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \ - 0x00, 0x00, 0x00, 0x00, 0x0c, 0xa0, 0x00, 0x00) - -/** - * @brief UUID for the Value V9 (128-bit UUID) Characteristic - */ -#define BT_UUID_VALUE_V9__128_BIT_UUID BT_UUID_DECLARE_128( \ - 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \ - 0x00, 0x00, 0x00, 0x00, 0x09, 0xb0, 0x00, 0x00) - -/** - * @brief UUID for the Descriptor V9D2 (128-bit UUID) Characteristic - */ -#define BT_UUID_DES_V9D2__128_BIT_UUID BT_UUID_DECLARE_128( \ - 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \ - 0x00, 0x00, 0x00, 0x00, 0xd2, 0xd9, 0x00, 0x00) - -/** - * @brief UUID for the Descriptor V9D3 (128-bit UUID) Characteristic - */ -#define BT_UUID_DES_V9D3__128_BIT_UUID BT_UUID_DECLARE_128( \ - 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \ - 0x00, 0x00, 0x00, 0x00, 0xd3, 0xd9, 0x00, 0x00) - -static uint8_t value_v9__128_bit_uuid_value = 0x09; -static uint8_t des_v9d2__128_bit_uuid_value = 0x22; -static struct bt_gatt_cep cha_ext_pro_value = { 0x0001 }; -static uint8_t des_v9d3__128_bit_uuid_value = 0x33; - -/** - * @brief Attribute read call back for the Value V9 (128-bit UUID) attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v9__128_bit_uuid(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v9__128_bit_uuid_value)); -} - -/** - * @brief Attribute write call back for the Value V9 (128-bit UUID) attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v9__128_bit_uuid(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, - uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(value_v9__128_bit_uuid_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v9__128_bit_uuid_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute read call back for the Descriptor V9D2 (128-bit UUID) - * attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_des_v9d2__128_bit_uuid(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(des_v9d2__128_bit_uuid_value)); -} - -/** - * @brief Attribute write call back for the Descriptor V9D2 (128-bit UUID) - * attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_des_v9d2__128_bit_uuid(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, - uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(des_v9d2__128_bit_uuid_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(des_v9d2__128_bit_uuid_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute write call back for the Descriptor V9D3 (128-bit UUID) - * attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_des_v9d3__128_bit_uuid(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, - uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(des_v9d3__128_bit_uuid_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(des_v9d3__128_bit_uuid_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -struct bt_gatt_attr service_c_1_3_attrs[] = { - BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_C_1, 0x80), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V9__128_BIT_UUID, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE | BT_GATT_CHRC_EXT_PROP, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_value_v9__128_bit_uuid, write_value_v9__128_bit_uuid, - &value_v9__128_bit_uuid_value, 0x81), - BT_GATT_H_DESCRIPTOR(BT_UUID_DES_V9D2__128_BIT_UUID, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_des_v9d2__128_bit_uuid, write_des_v9d2__128_bit_uuid, - &des_v9d2__128_bit_uuid_value, 0x83), - BT_GATT_H_CEP(&cha_ext_pro_value, 0x84), - BT_GATT_H_DESCRIPTOR(BT_UUID_DES_V9D3__128_BIT_UUID, - BT_GATT_PERM_WRITE, - NULL, write_des_v9d3__128_bit_uuid, - &des_v9d3__128_bit_uuid_value, 0x85) -}; - -static struct bt_gatt_service service_c_1_3_svc = - BT_GATT_SERVICE(service_c_1_3_attrs); - -/** - * @brief Register the Service C.1 and all its Characteristics... - */ -void service_c_1_3_init(void) -{ - bt_gatt_service_register(&service_c_1_3_svc); -} - -/** - * @brief Un-Register the Service C.1 and all its Characteristics... - */ -void service_c_1_3_remove(void) -{ - bt_gatt_service_unregister(&service_c_1_3_svc); -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_3.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_3.h deleted file mode 100644 index 5e73b78630b..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_1_3.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service C.1 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 3' - */ -#ifndef SERVICE_C_1_3_H -#define SERVICE_C_1_3_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_c_1_3_init(void); -void service_c_1_3_remove(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_C_1_3_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_1.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_1.c deleted file mode 100644 index 60af803288e..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_1.c +++ /dev/null @@ -1,1137 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service C.2 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 1' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -/** - * @brief UUID for the Service C.2 - */ -#define BT_UUID_SERVICE_C_2 BT_UUID_DECLARE_128( \ - 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \ - 0x00, 0x00, 0x00, 0x00, 0x0c, 0xa0, 0x00, 0x00) - -/** - * @brief UUID for the Value V10 Characteristic - */ -#define BT_UUID_VALUE_V10 BT_UUID_DECLARE_16(0xb00a) - -/** - * @brief UUID for the Value V2 Characteristic - */ -#define BT_UUID_VALUE_V2 BT_UUID_DECLARE_16(0xb002) - -/** - * @brief UUID for the Long descriptor V2D1 Characteristic - */ -#define BT_UUID_LONG_DES_V2D1 BT_UUID_DECLARE_16(0xb012) - -/** - * @brief UUID for the Long descriptor V2D2 Characteristic - */ -#define BT_UUID_LONG_DES_V2D2 BT_UUID_DECLARE_16(0xb013) - -/** - * @brief UUID for the Long descriptor V2D3 Characteristic - */ -#define BT_UUID_LONG_DES_V2D3 BT_UUID_DECLARE_16(0xb014) - -static uint8_t value_v10_value = 0x0A; -static uint8_t value_v2_value[] = { - '1', '1', '1', '1', '1', '2', '2', '2', '2', '2', '3', '3', '3', - '3', '3', '4', '4', '4', '4', '4', '5', '\0' -}; -static uint8_t long_des_v2d1_value[] = { - 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x12, - 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x11 -}; -static uint8_t value_v2_1_value[] = { - '2', '2', '2', '2', '2', '3', '3', '3', '3', '3', '4', '4', '4', - '4', '4', '5', '5', '5', '5', '5', '6', '6', '\0' -}; -static uint8_t long_des_v2d2_value[] = { - 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x12, - 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x11, 0x22 -}; -static uint8_t value_v2_2_value[] = { - '3', '3', '3', '3', '3', '4', '4', '4', '4', '4', '5', '5', '5', - '5', '5', '6', '6', '6', '6', '6', '7', '7', '7', '\0' -}; -static uint8_t long_des_v2d3_value[] = { - 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x12, - 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x11, 0x22, - 0x33 -}; -static uint8_t value_v2_3_value[] = { - 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x12, - 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, - 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x11, 0x22, 0x33, - 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x11, 0x22, 0x33 -}; -static uint8_t long_des_v2d1_1_value[] = { - 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x12, - 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, - 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x11, 0x22, 0x33, - 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x11, 0x22, 0x33 -}; -static uint8_t value_v2_4_value[] = { - 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x12, - 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, - 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x11, 0x22, 0x33, - 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x11, 0x22, 0x33, 0x44 -}; -static uint8_t long_des_v2d2_1_value[] = { - 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x12, - 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, - 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x11, 0x22, 0x33, - 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x11, 0x22, 0x33, 0x44 -}; -static uint8_t value_v2_5_value[] = { - 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x12, - 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, - 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x11, 0x22, 0x33, - 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x11, 0x22, 0x33, 0x44, - 0x55 -}; -static uint8_t long_des_v2d3_1_value[] = { - 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x12, - 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, - 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x11, 0x22, 0x33, - 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x11, 0x22, 0x33, 0x44, - 0x55 -}; -static uint8_t value_v2_6_value[] = { - '1', '1', '1', '1', '1', '2', '2', '2', '2', '2', '3', '3', '3', - '3', '3', '4', '4', '4', '4', '4', '5', '5', '5', '5', '5', '6', - '6', '6', '6', '6', '7', '7', '7', '7', '7', '8', '8', '8', '8', - '8', '9', '9', '9', '\0' -}; -static uint8_t long_des_v2d1_2_value[] = { - 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x12, - 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, - 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x11, 0x22, 0x33, - 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x11, 0x22, 0x33 -}; -static uint8_t value_v2_7_value[] = { - '2', '2', '2', '2', '2', '3', '3', '3', '3', '3', '4', '4', '4', - '4', '4', '5', '5', '5', '5', '5', '6', '6', '6', '6', '6', '7', - '7', '7', '7', '7', '8', '8', '8', '8', '8', '9', '9', '9', '9', - '9', '0', '0', '0', '0', '\0' -}; -static uint8_t long_des_v2d2_2_value[] = { - 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x12, - 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, - 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x11, 0x22, 0x33, - 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x11, 0x22, 0x33, 0x44 -}; -static uint8_t value_v2_8_value[] = { - '3', '3', '3', '3', '3', '4', '4', '4', '4', '4', '5', '5', '5', - '5', '5', '6', '6', '6', '6', '6', '7', '7', '7', '7', '7', '8', - '8', '8', '8', '8', '9', '9', '9', '9', '9', '0', '0', '0', '0', - '0', '1', '1', '1', '1', '1', '\0' -}; -static uint8_t long_des_v2d3_2_value[] = { - 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x12, - 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, - 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x11, 0x22, 0x33, - 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x11, 0x22, 0x33, 0x44, - 0x55 -}; -static bool bAuthorized; - -/** - * @brief Attribute read call back for the Value V10 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v10(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v10_value)); -} - -/** - * @brief Attribute read call back for the Value V2 string attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_str_value(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const char *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - strlen(value)); -} - -/** - * @brief Attribute write call back for the Value V2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v2(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - char *value = attr->user_data; - - if (offset >= sizeof(value_v2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute read call back for the Long descriptor V2D1 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_long_des_v2d1(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(long_des_v2d1_value)); -} - -/** - * @brief Attribute write call back for the Long descriptor V2D1 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_long_des_v2d1(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(long_des_v2d1_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(long_des_v2d1_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute write call back for the Value V2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v2_1(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - char *value = attr->user_data; - - if (offset >= sizeof(value_v2_1_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v2_1_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute read call back for the Long descriptor V2D2 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_long_des_v2d2(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(long_des_v2d2_value)); -} - -/** - * @brief Attribute write call back for the Long descriptor V2D2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_long_des_v2d2(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(long_des_v2d2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(long_des_v2d2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute write call back for the Value V2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v2_2(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - char *value = attr->user_data; - - if (offset >= sizeof(value_v2_2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v2_2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute read call back for the Long descriptor V2D3 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_long_des_v2d3(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(long_des_v2d3_value)); -} - -/** - * @brief Attribute write call back for the Long descriptor V2D3 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_long_des_v2d3(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(long_des_v2d3_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(long_des_v2d3_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute read call back for the Value V2 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v2_3(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v2_3_value)); -} - -/** - * @brief Attribute write call back for the Value V2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v2_3(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(value_v2_3_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v2_3_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute read call back for the Long descriptor V2D1 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_long_des_v2d1_1(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(long_des_v2d1_1_value)); -} - -/** - * @brief Attribute write call back for the Long descriptor V2D1 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_long_des_v2d1_1(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(long_des_v2d1_1_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(long_des_v2d1_1_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute read call back for the Value V2 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v2_4(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v2_4_value)); -} - -/** - * @brief Attribute write call back for the Value V2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v2_4(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(value_v2_4_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v2_4_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute read call back for the Long descriptor V2D2 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_long_des_v2d2_1(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(long_des_v2d2_1_value)); -} - -/** - * @brief Attribute write call back for the Long descriptor V2D2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_long_des_v2d2_1(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(long_des_v2d2_1_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(long_des_v2d2_1_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute read call back for the Value V2 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v2_5(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v2_5_value)); -} - -/** - * @brief Attribute write call back for the Value V2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v2_5(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(value_v2_5_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v2_5_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute read call back for the Long descriptor V2D3 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_long_des_v2d3_1(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(long_des_v2d3_1_value)); -} - -/** - * @brief Attribute write call back for the Long descriptor V2D3 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_long_des_v2d3_1(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(long_des_v2d3_1_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(long_des_v2d3_1_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute write call back for the Value V2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v2_6(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - char *value = attr->user_data; - - if (offset >= sizeof(value_v2_6_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v2_6_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute read call back for the Long descriptor V2D1 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_long_des_v2d1_2(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(long_des_v2d1_2_value)); -} - -/** - * @brief Attribute write call back for the Long descriptor V2D1 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_long_des_v2d1_2(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(long_des_v2d1_2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(long_des_v2d1_2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute read call back for the Value V2 string attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_str_auth_value(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const char *value = attr->user_data; - - if (!bAuthorized) - return BT_GATT_ERR(BT_ATT_ERR_AUTHORIZATION); - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - strlen(value)); -} - -/** - * @brief Attribute write call back for the Value V2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v2_7(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - char *value = attr->user_data; - - if (offset >= sizeof(value_v2_7_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v2_7_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - if (!bAuthorized) - return BT_GATT_ERR(BT_ATT_ERR_AUTHORIZATION); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute read call back for the Long descriptor V2D2 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_long_des_v2d2_2(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - if (!bAuthorized) - return BT_GATT_ERR(BT_ATT_ERR_AUTHORIZATION); - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(long_des_v2d2_2_value)); -} - -/** - * @brief Attribute write call back for the Long descriptor V2D2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_long_des_v2d2_2(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(long_des_v2d2_2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(long_des_v2d2_2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - if (!bAuthorized) - return BT_GATT_ERR(BT_ATT_ERR_AUTHORIZATION); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute write call back for the Value V2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v2_8(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - char *value = attr->user_data; - - if (offset >= sizeof(value_v2_8_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v2_8_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute read call back for the Long descriptor V2D3 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_long_des_v2d3_2(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(long_des_v2d3_2_value)); -} - -/** - * @brief Attribute write call back for the Long descriptor V2D3 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_long_des_v2d3_2(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(long_des_v2d3_2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(long_des_v2d3_2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -static struct bt_gatt_attr service_c_2_1_attrs[] = { - BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_C_2, 0xC0), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V10, - BT_GATT_CHRC_READ, - BT_GATT_PERM_READ, - read_value_v10, NULL, &value_v10_value, 0xC1), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_str_value, write_value_v2, &value_v2_value, 0xC3), - BT_GATT_H_DESCRIPTOR(BT_UUID_LONG_DES_V2D1, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_long_des_v2d1, write_long_des_v2d1, &long_des_v2d1_value, - 0xC5), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_str_value, write_value_v2_1, &value_v2_1_value, 0xC6), - BT_GATT_H_DESCRIPTOR(BT_UUID_LONG_DES_V2D2, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_long_des_v2d2, write_long_des_v2d2, &long_des_v2d2_value, - 0xC8), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_str_value, write_value_v2_2, &value_v2_2_value, 0xC9), - BT_GATT_H_DESCRIPTOR(BT_UUID_LONG_DES_V2D3, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_long_des_v2d3, write_long_des_v2d3, &long_des_v2d3_value, - 0xCB), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_value_v2_3, write_value_v2_3, &value_v2_3_value, 0xCC), - BT_GATT_H_DESCRIPTOR(BT_UUID_LONG_DES_V2D1, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_long_des_v2d1_1, write_long_des_v2d1_1, - &long_des_v2d1_1_value, 0xCE), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_value_v2_4, write_value_v2_4, &value_v2_4_value, 0xCF), - BT_GATT_H_DESCRIPTOR(BT_UUID_LONG_DES_V2D2, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_long_des_v2d2_1, write_long_des_v2d2_1, - &long_des_v2d2_1_value, 0xD1), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_value_v2_5, write_value_v2_5, &value_v2_5_value, 0xD2), - BT_GATT_H_DESCRIPTOR(BT_UUID_LONG_DES_V2D3, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_long_des_v2d3_1, write_long_des_v2d3_1, - &long_des_v2d3_1_value, 0xD4), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ_AUTHEN | BT_GATT_PERM_WRITE_AUTHEN, - read_str_value, write_value_v2_6, &value_v2_6_value, 0xD5), - BT_GATT_H_DESCRIPTOR(BT_UUID_LONG_DES_V2D1, - BT_GATT_PERM_READ_AUTHEN | BT_GATT_PERM_WRITE_AUTHEN, - read_long_des_v2d1_2, write_long_des_v2d1_2, - &long_des_v2d1_2_value, 0xD7), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_str_auth_value, write_value_v2_7, &value_v2_7_value, 0xD8), - BT_GATT_H_DESCRIPTOR(BT_UUID_LONG_DES_V2D2, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_long_des_v2d2_2, write_long_des_v2d2_2, - &long_des_v2d2_2_value, 0xDA), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ_ENCRYPT | BT_GATT_PERM_WRITE_ENCRYPT, - read_str_value, write_value_v2_8, &value_v2_8_value, 0xDB), - BT_GATT_H_DESCRIPTOR(BT_UUID_LONG_DES_V2D3, - BT_GATT_PERM_READ_ENCRYPT | BT_GATT_PERM_WRITE_ENCRYPT, - read_long_des_v2d3_2, write_long_des_v2d3_2, - &long_des_v2d3_2_value, 0xDD) -}; - -static struct bt_gatt_service service_c_2_1_svc = - BT_GATT_SERVICE(service_c_2_1_attrs); - -/** - * @brief Register the Service C.2 and all its Characteristics... - */ -void service_c_2_1_init(void) -{ - bt_gatt_service_register(&service_c_2_1_svc); -} - -/** - * @brief Un-Register the Service C.2 and all its Characteristics... - */ -void service_c_2_1_remove(void) -{ - bt_gatt_service_unregister(&service_c_2_1_svc); -} - -/** - * @brief Set authorization for Characteristics and Descriptors in Service C.2. - */ -void service_c_2_1_authorize(bool authorized) -{ - bAuthorized = authorized; -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_1.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_1.h deleted file mode 100644 index 9c94bd7cb69..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_1.h +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service C.2 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 1' - */ -#ifndef SERVICE_C_2_1_H -#define SERVICE_C_2_1_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_c_2_1_authorize(bool); -void service_c_2_1_init(void); -void service_c_2_1_remove(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_C_2_1_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_2.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_2.c deleted file mode 100644 index f3e1c10aafb..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_2.c +++ /dev/null @@ -1,340 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service C.2 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 2' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -/** - * @brief UUID for the Service C.2 - */ -#define BT_UUID_SERVICE_C_2 BT_UUID_DECLARE_128( \ - 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \ - 0x00, 0x00, 0x00, 0x00, 0x0c, 0xa0, 0x00, 0x00) - -/** - * @brief UUID for the Value V10 Characteristic - */ -#define BT_UUID_VALUE_V10 BT_UUID_DECLARE_16(0xb00a) - -/** - * @brief UUID for the Value V2 Characteristic - */ -#define BT_UUID_VALUE_V2 BT_UUID_DECLARE_16(0xb002) - -static uint8_t value_v10_value = 0x0A; -static uint8_t value_v2_value[] = { - '1', '1', '1', '1', '1', '2', '2', '2', '2', '2', '3', '3', '3', - '3', '3', '4', '4', '4', '4', '4', '5', '\0' -}; -static uint8_t value_v2_1_value[] = { - '2', '2', '2', '2', '2', '3', '3', '3', '3', '3', '4', '4', '4', - '4', '4', '5', '5', '5', '5', '5', '6', '6', '\0' -}; -static uint8_t value_v2_2_value[] = { - '3', '3', '3', '3', '3', '4', '4', '4', '4', '4', '5', '5', '5', - '5', '5', '6', '6', '6', '6', '6', '7', '7', '7', '\0' -}; -static uint8_t value_v2_3_value[] = { - '1', '1', '1', '1', '1', '2', '2', '2', '2', '2', '3', '3', '3', - '3', '3', '4', '4', '4', '4', '4', '5', '5', '5', '5', '5', '6', - '6', '6', '6', '6', '7', '7', '7', '7', '7', '8', '8', '8', '8', - '8', '9', '9', '9', '\0' -}; -static uint8_t value_v2_4_value[] = { - '2', '2', '2', '2', '2', '3', '3', '3', '3', '3', '4', '4', '4', - '4', '4', '5', '5', '5', '5', '5', '6', '6', '6', '6', '6', '7', - '7', '7', '7', '7', '8', '8', '8', '8', '8', '9', '9', '9', '9', - '9', '0', '0', '0', '0', '\0' -}; -static uint8_t value_v2_5_value[] = { - '3', '3', '3', '3', '3', '4', '4', '4', '4', '4', '5', '5', '5', - '5', '5', '6', '6', '6', '6', '6', '7', '7', '7', '7', '7', '8', - '8', '8', '8', '8', '9', '9', '9', '9', '9', '0', '0', '0', '0', - '0', '1', '1', '1', '1', '1', '\0' -}; - -/** - * @brief Attribute read call back for the Value V10 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v10(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v10_value)); -} - -/** - * @brief Attribute read call back for the Value V2 string attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_str_value(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const char *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - strlen(value)); -} - -/** - * @brief Attribute write call back for the Value V2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v2(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - char *value = attr->user_data; - - if (offset >= sizeof(value_v2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute write call back for the Value V2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v2_1(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - char *value = attr->user_data; - - if (offset >= sizeof(value_v2_1_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v2_1_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute write call back for the Value V2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v2_2(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - char *value = attr->user_data; - - if (offset >= sizeof(value_v2_2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v2_2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute write call back for the Value V2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v2_3(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - char *value = attr->user_data; - - if (offset >= sizeof(value_v2_3_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v2_3_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute write call back for the Value V2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v2_4(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - char *value = attr->user_data; - - if (offset >= sizeof(value_v2_4_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v2_4_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute write call back for the Value V2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v2_5(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - char *value = attr->user_data; - - if (offset >= sizeof(value_v2_5_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v2_5_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -static struct bt_gatt_attr service_c_2_2_attrs[] = { - BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_C_2, 0x10), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V10, - BT_GATT_CHRC_READ, - BT_GATT_PERM_READ, - read_value_v10, NULL, &value_v10_value, 0x11), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_str_value, write_value_v2, &value_v2_value, 0x13), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_str_value, write_value_v2_1, &value_v2_1_value, 0x15), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_str_value, write_value_v2_2, &value_v2_2_value, 0x17), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_str_value, write_value_v2_3, &value_v2_3_value, 0x19), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_str_value, write_value_v2_4, &value_v2_4_value, 0x1B), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_str_value, write_value_v2_5, &value_v2_5_value, 0x1D) -}; - -static struct bt_gatt_service service_c_2_2_svc = - BT_GATT_SERVICE(service_c_2_2_attrs); - -/** - * @brief Register the Service C.2 and all its Characteristics... - */ -void service_c_2_2_init(void) -{ - bt_gatt_service_register(&service_c_2_2_svc); -} - -/** - * @brief Un-Register the Service C.2 and all its Characteristics... - */ -void service_c_2_2_remove(void) -{ - bt_gatt_service_unregister(&service_c_2_2_svc); -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_2.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_2.h deleted file mode 100644 index a8a1eadf1ba..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_2.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service C.2 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 2' - */ -#ifndef SERVICE_C_2_2_H -#define SERVICE_C_2_2_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_c_2_2_init(void); -void service_c_2_2_remove(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_C_2_2_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_3.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_3.c deleted file mode 100644 index 0040c2e2374..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_3.c +++ /dev/null @@ -1,340 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service C.2 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 3' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -/** - * @brief UUID for the Service C.2 - */ -#define BT_UUID_SERVICE_C_2 BT_UUID_DECLARE_128( \ - 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \ - 0x00, 0x00, 0x00, 0x00, 0x0c, 0xa0, 0x00, 0x00) - -/** - * @brief UUID for the Value V10 Characteristic - */ -#define BT_UUID_VALUE_V10 BT_UUID_DECLARE_16(0xb00a) - -/** - * @brief UUID for the Value V2 Characteristic - */ -#define BT_UUID_VALUE_V2 BT_UUID_DECLARE_16(0xb002) - -static uint8_t value_v10_value = 0x0A; -static uint8_t value_v2_value[] = { - '1', '1', '1', '1', '1', '2', '2', '2', '2', '2', '3', '3', '3', - '3', '3', '4', '4', '4', '4', '4', '5', '\0' -}; -static uint8_t value_v2_1_value[] = { - '2', '2', '2', '2', '2', '3', '3', '3', '3', '3', '4', '4', '4', - '4', '4', '5', '5', '5', '5', '5', '6', '6', '\0' -}; -static uint8_t value_v2_2_value[] = { - '3', '3', '3', '3', '3', '4', '4', '4', '4', '4', '5', '5', '5', - '5', '5', '6', '6', '6', '6', '6', '7', '7', '7', '\0' -}; -static uint8_t value_v2_3_value[] = { - '1', '1', '1', '1', '1', '2', '2', '2', '2', '2', '3', '3', '3', - '3', '3', '4', '4', '4', '4', '4', '5', '5', '5', '5', '5', '6', - '6', '6', '6', '6', '7', '7', '7', '7', '7', '8', '8', '8', '8', - '8', '9', '9', '9', '\0' -}; -static uint8_t value_v2_4_value[] = { - '2', '2', '2', '2', '2', '3', '3', '3', '3', '3', '4', '4', '4', - '4', '4', '5', '5', '5', '5', '5', '6', '6', '6', '6', '6', '7', - '7', '7', '7', '7', '8', '8', '8', '8', '8', '9', '9', '9', '9', - '9', '0', '0', '0', '0', '\0' -}; -static uint8_t value_v2_5_value[] = { - '3', '3', '3', '3', '3', '4', '4', '4', '4', '4', '5', '5', '5', - '5', '5', '6', '6', '6', '6', '6', '7', '7', '7', '7', '7', '8', - '8', '8', '8', '8', '9', '9', '9', '9', '9', '0', '0', '0', '0', - '0', '1', '1', '1', '1', '1', '\0' -}; - -/** - * @brief Attribute read call back for the Value V10 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v10(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v10_value)); -} - -/** - * @brief Attribute read call back for the Value V2 string attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_str_value(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const char *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - strlen(value)); -} - -/** - * @brief Attribute write call back for the Value V2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v2(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - char *value = attr->user_data; - - if (offset >= sizeof(value_v2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute write call back for the Value V2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v2_1(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - char *value = attr->user_data; - - if (offset >= sizeof(value_v2_1_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v2_1_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute write call back for the Value V2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v2_2(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - char *value = attr->user_data; - - if (offset >= sizeof(value_v2_2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v2_2_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute write call back for the Value V2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v2_3(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - char *value = attr->user_data; - - if (offset >= sizeof(value_v2_3_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v2_3_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute write call back for the Value V2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v2_4(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - char *value = attr->user_data; - - if (offset >= sizeof(value_v2_4_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v2_4_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute write call back for the Value V2 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v2_5(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, uint16_t offset, - uint8_t flags) -{ - char *value = attr->user_data; - - if (offset >= sizeof(value_v2_5_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v2_5_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -static struct bt_gatt_attr service_c_2_3_attrs[] = { - BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_C_2, 0xA0), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V10, - BT_GATT_CHRC_READ, - BT_GATT_PERM_READ, - read_value_v10, NULL, &value_v10_value, 0xA1), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_str_value, write_value_v2, &value_v2_value, 0xA3), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_str_value, write_value_v2_1, &value_v2_1_value, 0xA5), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_str_value, write_value_v2_2, &value_v2_2_value, 0xA7), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_str_value, write_value_v2_3, &value_v2_3_value, 0xA9), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_str_value, write_value_v2_4, &value_v2_4_value, 0xAB), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V2, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_str_value, write_value_v2_5, &value_v2_5_value, 0xAD) -}; - -static struct bt_gatt_service service_c_2_3_svc = - BT_GATT_SERVICE(service_c_2_3_attrs); - -/** - * @brief Register the Service C.2 and all its Characteristics... - */ -void service_c_2_3_init(void) -{ - bt_gatt_service_register(&service_c_2_3_svc); -} - -/** - * @brief Un-Register the Service C.2 and all its Characteristics... - */ -void service_c_2_3_remove(void) -{ - bt_gatt_service_unregister(&service_c_2_3_svc); -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_3.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_3.h deleted file mode 100644 index 28f551380c5..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_c_2_3.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service C.2 - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 3' - */ -#ifndef SERVICE_C_2_3_H -#define SERVICE_C_2_3_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_c_2_3_init(void); -void service_c_2_3_remove(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_C_2_3_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_1.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_1.c deleted file mode 100644 index 82c9fbeb5bf..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_1.c +++ /dev/null @@ -1,128 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service D - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 1' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -extern struct bt_gatt_attr service_b_5_1_attrs[]; - -/** - * @brief UUID for the Service D - */ -#define BT_UUID_SERVICE_D BT_UUID_DECLARE_16(0xa00d) - -/** - * @brief UUID for the Value V12 Characteristic - */ -#define BT_UUID_VALUE_V12 BT_UUID_DECLARE_16(0xb00c) - -/** - * @brief UUID for the Value V11 (128-bit UUID) Characteristic - */ -#define BT_UUID_VALUE_V11__128_BIT_UUID BT_UUID_DECLARE_128( \ - 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \ - 0x00, 0x00, 0x00, 0x00, 0x0b, 0xb0, 0x00, 0x00) - -static uint8_t value_v12_value = 0x0C; -static uint8_t value_v11__128_bit_uuid_value = 0x0B; -static bool bAuthorized; - -/** - * @brief Attribute read call back for the Value V12 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v12(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v12_value)); -} - -/** - * @brief Attribute read call back for the Value V11 (128-bit UUID) attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v11__128_bit_uuid(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - if (!bAuthorized) - return BT_GATT_ERR(BT_ATT_ERR_AUTHORIZATION); - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v11__128_bit_uuid_value)); -} - -struct bt_gatt_attr service_d_1_attrs[] = { - BT_GATT_H_SECONDARY_SERVICE(BT_UUID_SERVICE_D, 0x10), - BT_GATT_H_INCLUDE_SERVICE(service_b_5_1_attrs, 0x11), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V12, - BT_GATT_CHRC_READ, - BT_GATT_PERM_READ_AUTHEN, - read_value_v12, NULL, &value_v12_value, 0x12), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V11__128_BIT_UUID, - BT_GATT_CHRC_READ, - BT_GATT_PERM_READ, - read_value_v11__128_bit_uuid, NULL, - &value_v11__128_bit_uuid_value, 0x14) -}; - -static struct bt_gatt_service service_d_1_svc = - BT_GATT_SERVICE(service_d_1_attrs); - -/** - * @brief Register the Service D and all its Characteristics... - */ -void service_d_1_init(void) -{ - bt_gatt_service_register(&service_d_1_svc); -} - -/** - * @brief Un-Register the Service D and all its Characteristics... - */ -void service_d_1_remove(void) -{ - bt_gatt_service_unregister(&service_d_1_svc); -} - -/** - * @brief Set authorization for Characteristics and Descriptors in Service D. - */ -void service_d_1_authorize(bool authorized) -{ - bAuthorized = authorized; -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_1.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_1.h deleted file mode 100644 index 22b33439edd..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_1.h +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service D - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 1' - */ -#ifndef SERVICE_D_1_H -#define SERVICE_D_1_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_d_1_authorize(bool); -void service_d_1_init(void); -void service_d_1_remove(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_D_1_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_2.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_2.c deleted file mode 100644 index 0664d6f9fe6..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_2.c +++ /dev/null @@ -1,116 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service D - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 2' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -extern struct bt_gatt_attr service_b_1_2_attrs[]; - -/** - * @brief UUID for the Service D - */ -#define BT_UUID_SERVICE_D BT_UUID_DECLARE_16(0xa00d) - -/** - * @brief UUID for the Value V11 (128-bit UUID) Characteristic - */ -#define BT_UUID_VALUE_V11__128_BIT_UUID BT_UUID_DECLARE_128( \ - 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \ - 0x00, 0x00, 0x00, 0x00, 0x0b, 0xb0, 0x00, 0x00) - -/** - * @brief UUID for the Value V12 Characteristic - */ -#define BT_UUID_VALUE_V12 BT_UUID_DECLARE_16(0xb00c) - -static uint8_t value_v11__128_bit_uuid_value = 0x0B; -static uint8_t value_v12_value = 0x0C; - -/** - * @brief Attribute read call back for the Value V11 (128-bit UUID) attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v11__128_bit_uuid(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v11__128_bit_uuid_value)); -} - -/** - * @brief Attribute read call back for the Value V12 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v12(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v12_value)); -} - -struct bt_gatt_attr service_d_2_attrs[] = { - BT_GATT_H_SECONDARY_SERVICE(BT_UUID_SERVICE_D, 0x40), - BT_GATT_H_INCLUDE_SERVICE(service_b_1_2_attrs, 0x41), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V11__128_BIT_UUID, - BT_GATT_CHRC_READ, - BT_GATT_PERM_READ, - read_value_v11__128_bit_uuid, NULL, - &value_v11__128_bit_uuid_value, 0x42), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V12, - BT_GATT_CHRC_READ, - BT_GATT_PERM_READ, - read_value_v12, NULL, &value_v12_value, 0x44) -}; - -static struct bt_gatt_service service_d_2_svc = - BT_GATT_SERVICE(service_d_2_attrs); - -/** - * @brief Register the Service D and all its Characteristics... - */ -void service_d_2_init(void) -{ - bt_gatt_service_register(&service_d_2_svc); -} - -/** - * @brief Un-Register the Service D and all its Characteristics... - */ -void service_d_2_remove(void) -{ - bt_gatt_service_unregister(&service_d_2_svc); -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_2.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_2.h deleted file mode 100644 index 03411de41e2..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_2.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service D - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 2' - */ -#ifndef SERVICE_D_2_H -#define SERVICE_D_2_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_d_2_init(void); -void service_d_2_remove(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_D_2_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_3.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_3.c deleted file mode 100644 index 0939dc3f4a7..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_3.c +++ /dev/null @@ -1,116 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service D - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 3' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -extern struct bt_gatt_attr service_c_1_3_attrs[]; - -/** - * @brief UUID for the Service D - */ -#define BT_UUID_SERVICE_D BT_UUID_DECLARE_16(0xa00d) - -/** - * @brief UUID for the Value V12 Characteristic - */ -#define BT_UUID_VALUE_V12 BT_UUID_DECLARE_16(0xb00c) - -/** - * @brief UUID for the Value V11 (128-bit UUID) Characteristic - */ -#define BT_UUID_VALUE_V11__128_BIT_UUID BT_UUID_DECLARE_128( \ - 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, \ - 0x00, 0x00, 0x00, 0x00, 0x0b, 0xb0, 0x00, 0x00) - -static uint8_t value_v12_value = 0x0C; -static uint8_t value_v11__128_bit_uuid_value = 0x0B; - -/** - * @brief Attribute read call back for the Value V12 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v12(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v12_value)); -} - -/** - * @brief Attribute read call back for the Value V11 (128-bit UUID) attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v11__128_bit_uuid(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v11__128_bit_uuid_value)); -} - -struct bt_gatt_attr service_d_3_attrs[] = { - BT_GATT_H_SECONDARY_SERVICE(BT_UUID_SERVICE_D, 0x20), - BT_GATT_H_INCLUDE_SERVICE(service_c_1_3_attrs, 0x21), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V12, - BT_GATT_CHRC_READ, - BT_GATT_PERM_READ, - read_value_v12, NULL, &value_v12_value, 0x22), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V11__128_BIT_UUID, - BT_GATT_CHRC_READ, - BT_GATT_PERM_READ, - read_value_v11__128_bit_uuid, NULL, - &value_v11__128_bit_uuid_value, 0x24) -}; - -static struct bt_gatt_service service_d_3_svc = - BT_GATT_SERVICE(service_d_3_attrs); - -/** - * @brief Register the Service D and all its Characteristics... - */ -void service_d_3_init(void) -{ - bt_gatt_service_register(&service_d_3_svc); -} - -/** - * @brief Un-Register the Service D and all its Characteristics... - */ -void service_d_3_remove(void) -{ - bt_gatt_service_unregister(&service_d_3_svc); -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_3.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_3.h deleted file mode 100644 index a9c46a7675c..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_d_3.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service D - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 3' - */ -#ifndef SERVICE_D_3_H -#define SERVICE_D_3_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_d_3_init(void); -void service_d_3_remove(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_D_3_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_e_2.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_e_2.c deleted file mode 100644 index f915455bea7..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_e_2.c +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service E - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 2' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -/** - * @brief UUID for the Service E - */ -#define BT_UUID_SERVICE_E BT_UUID_DECLARE_16(0xa00e) - -/** - * @brief UUID for the Value V13 Characteristic - */ -#define BT_UUID_VALUE_V13 BT_UUID_DECLARE_16(0xb00d) - -static uint8_t value_v13_value = 0x0D; - -/** - * @brief Attribute read call back for the Value V13 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v13(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v13_value)); -} - -static struct bt_gatt_attr service_e_2_attrs[] = { - BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_E, 0xFFFD), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V13, - BT_GATT_CHRC_READ, - BT_GATT_PERM_READ, - read_value_v13, NULL, &value_v13_value, 0xFFFE) -}; - -static struct bt_gatt_service service_e_2_svc = - BT_GATT_SERVICE(service_e_2_attrs); - -/** - * @brief Register the Service E and all its Characteristics... - */ -void service_e_2_init(void) -{ - bt_gatt_service_register(&service_e_2_svc); -} - -/** - * @brief Un-Register the Service E and all its Characteristics... - */ -void service_e_2_remove(void) -{ - bt_gatt_service_unregister(&service_e_2_svc); -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_e_2.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_e_2.h deleted file mode 100644 index bd79630cc15..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_e_2.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service E - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 2' - */ -#ifndef SERVICE_E_2_H -#define SERVICE_E_2_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_e_2_init(void); -void service_e_2_remove(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_E_2_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_e_3.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_e_3.c deleted file mode 100644 index 87101f404d3..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_e_3.c +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service E - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 3' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -/** - * @brief UUID for the Service E - */ -#define BT_UUID_SERVICE_E BT_UUID_DECLARE_16(0xa00e) - -static struct bt_gatt_attr service_e_3_attrs[] = { - BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_E, 0xFFFF) -}; - -static struct bt_gatt_service service_e_3_svc = - BT_GATT_SERVICE(service_e_3_attrs); - -/** - * @brief Register the Service E and all its Characteristics... - */ -void service_e_3_init(void) -{ - bt_gatt_service_register(&service_e_3_svc); -} - -/** - * @brief Un-Register the Service E and all its Characteristics... - */ -void service_e_3_remove(void) -{ - bt_gatt_service_unregister(&service_e_3_svc); -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_e_3.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_e_3.h deleted file mode 100644 index 2507dd790be..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_e_3.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service E - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 3' - */ -#ifndef SERVICE_E_3_H -#define SERVICE_E_3_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_e_3_init(void); -void service_e_3_remove(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_E_3_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_f_1.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_f_1.c deleted file mode 100644 index 4bdb61c760a..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_f_1.c +++ /dev/null @@ -1,400 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service F - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 1' - */ -#include -#include - -#include - -#include "gatt_macs.h" - -/** - * @brief UUID for the Service F - */ -#define BT_UUID_SERVICE_F BT_UUID_DECLARE_16(0xa00f) - -/** - * @brief UUID for the Value V14 Characteristic - */ -#define BT_UUID_VALUE_V14 BT_UUID_DECLARE_16(0xb00e) - -/** - * @brief UUID for the Value V15 Characteristic - */ -#define BT_UUID_VALUE_V15 BT_UUID_DECLARE_16(0xb00f) - -/** - * @brief UUID for the Value V6 Characteristic - */ -#define BT_UUID_VALUE_V6 BT_UUID_DECLARE_16(0xb006) - -/** - * @brief UUID for the Value V7 Characteristic - */ -#define BT_UUID_VALUE_V7 BT_UUID_DECLARE_16(0xb007) - -/** - * @brief UUID for the Value V16 Characteristic - */ -#define BT_UUID_VALUE_V16 BT_UUID_DECLARE_16(0xb010) - -/** - * @brief UUID for the Aggregate Format Characteristic - */ -#define BT_UUID_AGG_FORMAT BT_UUID_DECLARE_16(0x2905) - -/** - * @brief UUID for the Value V17 Characteristic - */ -#define BT_UUID_VALUE_V17 BT_UUID_DECLARE_16(0xb011) - -static uint8_t value_v14_value[] = { - 'L', 'e', 'n', 'g', 't', 'h', ' ', 'i', 's', ' ', '\0' -}; -static const struct bt_gatt_cpf cha_format_value = { - 0x19, 0x00, 0x3000, 0x01, 0x0000 -}; -static uint8_t value_v15_value = 0x65; -static const struct bt_gatt_cpf cha_format_1_value = { - 0x04, 0x00, 0x2701, 0x01, 0x0001 -}; -static uint16_t value_v6_value = 0x1234; -static const struct bt_gatt_cpf cha_format_2_value = { - 0x06, 0x00, 0x2710, 0x01, 0x0002 -}; -static uint32_t value_v7_value = 0x01020304; -static const struct bt_gatt_cpf cha_format_3_value = { - 0x08, 0x00, 0x2717, 0x01, 0x0003 -}; -static struct __packed value_v16_t { - uint8_t field_a; - uint16_t field_b; - uint32_t field_c; -} value_v16_value = { 0x65, 0x1234, 0x01020304 }; -static struct __packed agg_format_t { - uint16_t field_a; - uint16_t field_b; - uint16_t field_c; -} agg_format_value = { 0x00A6, 0x00A9, 0x00AC }; -static uint8_t value_v17_value = 0x12; - -/** - * @brief Attribute read call back for the Value V14 string attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_str_value(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const char *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - strlen(value)); -} - -/** - * @brief Attribute read call back for the Value V15 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v15(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v15_value)); -} - -/** - * @brief Attribute write call back for the Value V15 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v15(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - uint8_t *value = attr->user_data; - - if (offset >= sizeof(value_v15_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v15_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy(value + offset, buf, len); - - return len; -} - -/** - * @brief Attribute read call back for the Value V6 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v6(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint16_t *value = attr->user_data; - uint16_t value_v6_conv = sys_cpu_to_le16(*value); - - return bt_gatt_attr_read(conn, attr, buf, len, offset, &value_v6_conv, - sizeof(value_v6_conv)); -} - -/** - * @brief Attribute write call back for the Value V6 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v6(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - uint16_t *value = attr->user_data; - uint16_t value_v6_conv = sys_cpu_to_le16(*value); - - if (offset >= sizeof(value_v6_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v6_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy((uint8_t *)&value_v6_conv + offset, buf, len); - - *value = sys_le16_to_cpu(value_v6_conv); - - return len; -} - -/** - * @brief Attribute read call back for the Value V7 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v7(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint32_t *value = attr->user_data; - uint32_t value_v7_conv = sys_cpu_to_le32(*value); - - return bt_gatt_attr_read(conn, attr, buf, len, offset, &value_v7_conv, - sizeof(value_v7_conv)); -} - -/** - * @brief Attribute write call back for the Value V7 attribute - * - * @param conn The connection that is requesting to write - * @param attr The attribute that's being written - * @param buf Buffer with the data to write - * @param len Number of bytes in the buffer - * @param offset Offset to start writing from - * @param flags Flags (BT_GATT_WRITE_*) - * - * @return Number of bytes written, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t write_value_v7(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - uint16_t len, uint16_t offset, uint8_t flags) -{ - uint32_t *value = attr->user_data; - uint32_t value_v7_conv = sys_cpu_to_le32(*value); - - if (offset >= sizeof(value_v7_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - if (offset + len > sizeof(value_v7_value)) - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - - memcpy((uint8_t *)&value_v7_conv + offset, buf, len); - - *value = sys_le32_to_cpu(value_v7_conv); - - return len; -} - -/** - * @brief Attribute read call back for the Value V16 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v16(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const struct value_v16_t *value = attr->user_data; - struct value_v16_t value_v16_conv; - - value_v16_conv.field_a = value->field_a; - value_v16_conv.field_b = sys_cpu_to_le16(value->field_b); - value_v16_conv.field_c = sys_cpu_to_le32(value->field_c); - - return bt_gatt_attr_read(conn, attr, buf, len, offset, &value_v16_conv, - sizeof(value_v16_conv)); -} - -/** - * @brief Attribute read call back for the Aggregate Format attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_agg_format(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const struct agg_format_t *value = attr->user_data; - struct agg_format_t agg_format_conv; - - agg_format_conv.field_a = sys_cpu_to_le16(value->field_a); - agg_format_conv.field_b = sys_cpu_to_le16(value->field_b); - agg_format_conv.field_c = sys_cpu_to_le16(value->field_c); - - return bt_gatt_attr_read(conn, attr, buf, len, offset, &agg_format_conv, - sizeof(agg_format_conv)); -} - -/** - * @brief Attribute read call back for the Value V17 attribute - * - * @param conn The connection that is requesting to read - * @param attr The attribute that's being read - * @param buf Buffer to place the read result in - * @param len Length of data to read - * @param offset Offset to start reading from - * - * @return Number of bytes read, or in case of an error - BT_GATT_ERR() - * with a specific ATT error code. - */ -static ssize_t read_value_v17(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - uint16_t len, uint16_t offset) -{ - const uint8_t *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(value_v17_value)); -} - -static struct bt_gatt_attr service_f_1_attrs[] = { - BT_GATT_H_PRIMARY_SERVICE(BT_UUID_SERVICE_F, 0xA0), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V14, - BT_GATT_CHRC_READ, - BT_GATT_PERM_READ, - read_str_value, NULL, &value_v14_value, 0xA1), - BT_GATT_H_CPF(&cha_format_value, 0xA3), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V15, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_value_v15, write_value_v15, &value_v15_value, 0xA4), - BT_GATT_H_CPF(&cha_format_1_value, 0xA6), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V6, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_value_v6, write_value_v6, &value_v6_value, 0xA7), - BT_GATT_H_CPF(&cha_format_2_value, 0xA9), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V7, - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_value_v7, write_value_v7, &value_v7_value, 0xAA), - BT_GATT_H_CPF(&cha_format_3_value, 0xAC), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V16, - BT_GATT_CHRC_READ, - BT_GATT_PERM_READ, - read_value_v16, NULL, &value_v16_value, 0xAD), - BT_GATT_H_DESCRIPTOR(BT_UUID_AGG_FORMAT, - BT_GATT_PERM_READ, - read_agg_format, NULL, &agg_format_value, 0xAF), - BT_GATT_H_CHARACTERISTIC(BT_UUID_VALUE_V17, - BT_GATT_CHRC_READ | BT_GATT_CHRC_AUTH, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, - read_value_v17, NULL, &value_v17_value, 0xB0) -}; - -static struct bt_gatt_service service_f_1_svc = - BT_GATT_SERVICE(service_f_1_attrs); - -/** - * @brief Register the Service F and all its Characteristics... - */ -void service_f_1_init(void) -{ - bt_gatt_service_register(&service_f_1_svc); -} - -/** - * @brief Un-Register the Service F and all its Characteristics... - */ -void service_f_1_remove(void) -{ - bt_gatt_service_unregister(&service_f_1_svc); -} diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_f_1.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_f_1.h deleted file mode 100644 index fd9fae9dc45..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/service_f_1.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -/** - * @brief Service F - * - * This code is auto-generated from the Excel Workbook - * 'GATT_Test_Databases.xlsm' Sheet: 'Large Database 1' - */ -#ifndef SERVICE_F_1_H -#define SERVICE_F_1_H - -#ifdef __cplusplus -extern "C" { -#endif - -void service_f_1_init(void); -void service_f_1_remove(void); - -#ifdef __cplusplus -} -#endif -#endif /* SERVICE_F_1_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/services.h b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/services.h deleted file mode 100644 index b49702a5777..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/gatt/services.h +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ -#ifndef GATT_TEST_APP_GATT_SERVICES_H -#define GATT_TEST_APP_GATT_SERVICES_H - -#include "service_a_1.h" -#include "service_a_2.h" -#include "service_a_3.h" -#include "service_b_1_1.h" -#include "service_b_1_2.h" -#include "service_b_1_3.h" -#include "service_b_2_1.h" -#include "service_b_2_2.h" -#include "service_b_2_3.h" -#include "service_b_3_1.h" -#include "service_b_3_2.h" -#include "service_b_3_3.h" -#include "service_b_4_1.h" -#include "service_b_4_2.h" -#include "service_b_4_3.h" -#include "service_b_5_1.h" -#include "service_b_5_2.h" -#include "service_b_5_3.h" -#include "service_c_1_1.h" -#include "service_c_1_2.h" -#include "service_c_1_3.h" -#include "service_c_2_1.h" -#include "service_c_2_2.h" -#include "service_c_2_3.h" -#include "service_d_1.h" -#include "service_d_2.h" -#include "service_d_3.h" -#include "service_e_2.h" -#include "service_e_3.h" -#include "service_f_1.h" - -#endif /* GATT_TEST_APP_GATT_SERVICES_H */ diff --git a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/main.c b/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/main.c deleted file mode 100644 index 0beee2a33e8..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/gatt_test_app/src/main.c +++ /dev/null @@ -1,377 +0,0 @@ -/* - * Copyright (c) 2015-2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include - -#include "edtt_driver.h" -#include "bs_tracing.h" -#include "commands.h" - -#define DEVICE_NAME CONFIG_BT_DEVICE_NAME -#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1) - -static const struct bt_data ad[] = { - BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), - BT_DATA_BYTES(BT_DATA_UUID16_ALL, - BT_UUID_16_ENCODE(BT_UUID_HRS_VAL), - BT_UUID_16_ENCODE(BT_UUID_BAS_VAL), - BT_UUID_16_ENCODE(BT_UUID_CTS_VAL)), - BT_DATA_BYTES(BT_DATA_UUID128_ALL, - 0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12, - 0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x12), -}; - -static const struct bt_data sd[] = { - BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN), -}; - -static int service_set; - -static void connected(struct bt_conn *conn, uint8_t err) -{ - if (err) { - printk("Connection failed (err %u)\n", err); - } else { - printk("Connected\n"); - } -} - -static void disconnected(struct bt_conn *conn, uint8_t reason) -{ - printk("Disconnected (reason 0x%02x)\n", reason); -} - -static void security_changed(struct bt_conn *conn, bt_security_t level, - enum bt_security_err err) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - printk("Security changed: %s level %u\n", addr, level); -} - -BT_CONN_CB_DEFINE(conn_callbacks) = { - .connected = connected, - .disconnected = disconnected, - .security_changed = security_changed, -}; - -static void service_setup(int set) -{ - if (set == service_set) { - printk("Ignored request to change GATT services set to #%d - " - "already selected!\n", set); - return; - } - switch (service_set) { - case 0: - break; - case 1: - service_c_2_1_remove(); - service_f_1_remove(); - service_c_1_1_remove(); - service_b_5_1_remove(); - service_b_2_1_remove(); - service_b_1_1_remove(); - service_b_3_1_remove(); - service_b_4_1_remove(); - service_a_1_remove(); - service_d_1_remove(); - break; - case 2: - service_e_2_remove(); - service_b_5_2_remove(); - service_b_2_2_remove(); - service_b_3_2_remove(); - service_a_2_remove(); - service_b_1_2_remove(); - service_d_2_remove(); - service_b_4_2_remove(); - service_c_1_2_remove(); - service_c_2_2_remove(); - break; - case 3: - service_e_3_remove(); - service_c_2_3_remove(); - service_b_2_3_remove(); - service_c_1_3_remove(); - service_a_3_remove(); - service_b_3_3_remove(); - service_b_4_3_remove(); - service_b_5_3_remove(); - service_d_3_remove(); - service_b_1_3_remove(); - break; - default: - break; - } - - switch (set) { - case 0: - break; - case 1: - service_d_1_init(); - service_a_1_init(); - service_b_4_1_init(); - service_b_3_1_init(); - service_b_1_1_init(); - service_b_2_1_init(); - service_b_5_1_init(); - service_c_1_1_init(); - service_f_1_init(); - service_c_2_1_init(); - break; - case 2: - service_c_2_2_init(); - service_c_1_2_init(); - service_b_4_2_init(); - service_d_2_init(); - service_b_1_2_init(); - service_a_2_init(); - service_b_3_2_init(); - service_b_2_2_init(); - service_b_5_2_init(); - service_e_2_init(); - break; - case 3: - service_b_1_3_init(); - service_d_3_init(); - service_b_5_3_init(); - service_b_4_3_init(); - service_b_3_3_init(); - service_a_3_init(); - service_c_1_3_init(); - service_b_2_3_init(); - service_c_2_3_init(); - service_e_3_init(); - break; - default: - break; - } - service_set = set; - printk("Switched to GATT services set to #%d\n", set); -} - -static void service_notify(void) -{ - switch (service_set) { - case 0: - break; - case 1: - service_b_3_1_value_v6_notify(); - break; - case 2: - service_b_3_2_value_v6_notify(); - break; - case 3: - service_b_3_3_value_v6_notify(); - break; - default: - break; - } -} - -static void service_indicate(void) -{ - switch (service_set) { - case 0: - break; - case 1: - break; - case 2: - service_b_3_2_value_v6_indicate(); - break; - case 3: - service_b_3_3_value_v6_indicate(); - break; - default: - break; - } -} - -static void bt_ready(int err) -{ - if (err) { - printk("Bluetooth init failed (err %d)\n", err); - return; - } - - printk("Bluetooth initialized\n"); - - service_setup(1); - - printk("GATT Services initialized\n"); - - if (IS_ENABLED(CONFIG_SETTINGS)) { - settings_load(); - } - - err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), sd, - ARRAY_SIZE(sd)); - if (err) { - printk("Advertising failed to start (err %d)\n", err); - return; - } - - printk("Advertising successfully started\n"); -} - -static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - printk("Passkey for %s: %06u\n", addr, passkey); -} - -static void auth_cancel(struct bt_conn *conn) -{ - char addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); - - printk("Pairing cancelled: %s\n", addr); -} - -static struct bt_conn_auth_cb auth_cb_display = { - .passkey_display = auth_passkey_display, - .passkey_entry = NULL, - .cancel = auth_cancel, -}; - -/** - * @brief Clean out excess bytes from the input buffer - */ -static void read_excess_bytes(uint16_t size) -{ - if (size > 0) { - uint8_t buffer[size]; - - edtt_read((uint8_t *)buffer, size, EDTTT_BLOCK); - printk("command size wrong! (%u extra bytes removed)", size); - } -} - -/** - * @brief Switch GATT Service Set - */ -static void switch_service_set(uint16_t size) -{ - uint16_t response = sys_cpu_to_le16(CMD_GATT_SERVICE_SET_RSP); - uint8_t set; - - if (size > 0) { - edtt_read((uint8_t *)&set, sizeof(set), EDTTT_BLOCK); - service_setup((int)set); - size -= sizeof(set); - } - read_excess_bytes(size); - size = 0; - - edtt_write((uint8_t *)&response, sizeof(response), EDTTT_BLOCK); - edtt_write((uint8_t *)&size, sizeof(size), EDTTT_BLOCK); -} - -/** - * @brief Send Notifications from GATT Service Set - */ -static void handle_service_notify(uint16_t size) -{ - uint16_t response = sys_cpu_to_le16(CMD_GATT_SERVICE_NOTIFY_RSP); - - service_notify(); - read_excess_bytes(size); - size = 0; - - edtt_write((uint8_t *)&response, sizeof(response), EDTTT_BLOCK); - edtt_write((uint8_t *)&size, sizeof(size), EDTTT_BLOCK); -} - -/** - * @brief Send Indications from GATT Service Set - */ -static void handle_service_indicate(uint16_t size) -{ - uint16_t response = sys_cpu_to_le16(CMD_GATT_SERVICE_INDICATE_RSP); - - service_indicate(); - read_excess_bytes(size); - size = 0; - - edtt_write((uint8_t *)&response, sizeof(response), EDTTT_BLOCK); - edtt_write((uint8_t *)&size, sizeof(size), EDTTT_BLOCK); -} - -void main(void) -{ - int err; - uint16_t command; - uint16_t size; - - err = bt_enable(bt_ready); - if (err) { - printk("Bluetooth init failed (err %d)\n", err); - return; - } - - bt_conn_auth_cb_register(&auth_cb_display); - - /** - * Initialize and start EDTT system - */ -#if defined(CONFIG_ARCH_POSIX) - enable_edtt_mode(); - set_edtt_autoshutdown(true); -#endif - edtt_start(); - - /* Implement notification. At the moment there is no suitable way - * of starting delayed work so we do it here - */ - while (1) { - /** - * Wait for a command to arrive - then read and execute command - */ - edtt_read((uint8_t *)&command, sizeof(command), EDTTT_BLOCK); - command = sys_le16_to_cpu(command); - edtt_read((uint8_t *)&size, sizeof(size), EDTTT_BLOCK); - size = sys_le16_to_cpu(size); - bs_trace_raw_time(4, "command 0x%04X received (size %u)\n", - command, size); - - switch (command) { - case CMD_GATT_SERVICE_SET_REQ: - switch_service_set(size); - break; - case CMD_GATT_SERVICE_NOTIFY_REQ: - handle_service_notify(size); - break; - case CMD_GATT_SERVICE_INDICATE_REQ: - handle_service_indicate(size); - break; - default: - break; - } - } -} diff --git a/tests/bluetooth/bsim/ll/edtt/hci_test_app/CMakeLists.txt b/tests/bluetooth/bsim/ll/edtt/hci_test_app/CMakeLists.txt deleted file mode 100644 index 4e160cc85c6..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/hci_test_app/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# Copyright (c) 2019 Oticon A/S - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set\ - the environment variable BSIM_COMPONENTS_PATH to point to its components \ - folder. More information can be found in\ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(hci_test_app) - -target_sources(app PRIVATE - src/main.c - ../common/edtt_driver_bsim.c -) - -zephyr_library_include_directories( - ${ZEPHYR_BASE}/samples/bluetooth - ${ZEPHYR_BASE}/subsys/bluetooth - ../common/ - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ -) diff --git a/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_dut.conf b/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_dut.conf deleted file mode 100644 index fc351db200e..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_dut.conf +++ /dev/null @@ -1,44 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -CONFIG_BT=y -CONFIG_BT_HCI_RAW=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_BROADCASTER=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_OBSERVER=y -CONFIG_BT_DEBUG_LOG=y -CONFIG_BT_ECC=y -CONFIG_BT_TINYCRYPT_ECC=y - -# BUF_CMD_TX_SIZE must be 255 because of HCI/GEV/BV-01-C -CONFIG_BT_BUF_ACL_RX_SIZE=60 -CONFIG_BT_BUF_ACL_TX_SIZE=60 -CONFIG_BT_BUF_CMD_TX_SIZE=255 - -## -## Enabling BT_CTRL_DTM_HCI requires BT_LL_SW_SPLIT which requires BT_CTRL -## -CONFIG_BT_CTLR=y - -CONFIG_BT_LL_SW_SPLIT=y -CONFIG_BT_CTLR_CRYPTO=y -CONFIG_BT_CTLR_LE_ENC=y -CONFIG_BT_CTLR_PRIVACY=y -CONFIG_BT_CTLR_FILTER_ACCEPT_LIST=y -CONFIG_BT_CTLR_DTM_HCI=y -CONFIG_BT_CTLR_DATA_LENGTH_MAX=60 - -CONFIG_BT_LL_SW_LLCP_LEGACY=y - -# Enable extended advertising -CONFIG_BT_EXT_ADV=y -CONFIG_BT_CTLR_ADV_EXT=y -CONFIG_BT_EXT_ADV_MAX_ADV_SET=2 -CONFIG_BT_CTLR_ADVANCED_FEATURES=y -CONFIG_BT_CTLR_ADV_DATA_CHAIN=y -CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=1650 -CONFIG_BT_CTLR_ADV_DATA_BUF_MAX=2 -CONFIG_BT_EXT_SCAN_BUF_SIZE=1650 -CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=1650 -CONFIG_BT_BUF_EVT_RX_COUNT=16 -CONFIG_BT_CTLR_RX_BUFFERS=9 diff --git a/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_dut_llcp.conf b/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_dut_llcp.conf deleted file mode 100644 index 6c5b2c2c3c2..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_dut_llcp.conf +++ /dev/null @@ -1,47 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -CONFIG_BT=y -CONFIG_BT_HCI_RAW=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_BROADCASTER=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_OBSERVER=y -CONFIG_BT_DEBUG_LOG=y -CONFIG_BT_ECC=y -CONFIG_BT_TINYCRYPT_ECC=y - -# BUF_CMD_TX_SIZE must be 255 because of HCI/GEV/BV-01-C -CONFIG_BT_BUF_ACL_RX_SIZE=60 -CONFIG_BT_BUF_ACL_TX_SIZE=60 -CONFIG_BT_BUF_CMD_TX_SIZE=255 - -## -## Enabling BT_CTRL_DTM_HCI requires BT_LL_SW_SPLIT which requires BT_CTRL -## -CONFIG_BT_CTLR=y - -CONFIG_BT_LL_SW_SPLIT=y -CONFIG_BT_CTLR_CRYPTO=y -CONFIG_BT_CTLR_LE_ENC=y -CONFIG_BT_CTLR_PRIVACY=y -CONFIG_BT_CTLR_FILTER_ACCEPT_LIST=y -CONFIG_BT_CTLR_DTM_HCI=y -CONFIG_BT_CTLR_DATA_LENGTH_MAX=60 - -CONFIG_BT_LL_SW_LLCP=y -CONFIG_BT_CTLR_ADVANCED_FEATURES=y -# LLCP Refactored controller does not support Advanced Scheduling yet -CONFIG_BT_CTLR_SCHED_ADVANCED=n - -# Enable extended advertising -CONFIG_BT_EXT_ADV=y -CONFIG_BT_CTLR_ADV_EXT=y -CONFIG_BT_EXT_ADV_MAX_ADV_SET=2 -CONFIG_BT_CTLR_ADVANCED_FEATURES=y -CONFIG_BT_CTLR_ADV_DATA_CHAIN=y -CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=1650 -CONFIG_BT_CTLR_ADV_DATA_BUF_MAX=2 -CONFIG_BT_EXT_SCAN_BUF_SIZE=1650 -CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=1650 -CONFIG_BT_BUF_EVT_RX_COUNT=16 -CONFIG_BT_CTLR_RX_BUFFERS=9 diff --git a/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_tst.conf b/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_tst.conf deleted file mode 100644 index 276796a7363..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_tst.conf +++ /dev/null @@ -1,44 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -CONFIG_BT=y -CONFIG_BT_HCI_RAW=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_DEBUG_LOG=y -CONFIG_BT_ECC=y -CONFIG_BT_TINYCRYPT_ECC=y - -# BUF_CMD_TX_SIZE must be 255 because of HCI/GEV/BV-01-C -CONFIG_BT_BUF_ACL_RX_SIZE=60 -CONFIG_BT_BUF_ACL_TX_SIZE=60 -CONFIG_BT_BUF_CMD_TX_SIZE=255 - -## -## Enabling BT_CTRL_DTM_HCI requires BT_LL_SW which requires BT_CTRL -## -CONFIG_BT_CTLR=y - -CONFIG_BT_LL_SW_SPLIT=y -CONFIG_BT_CTLR_CRYPTO=y -CONFIG_BT_CTLR_LE_ENC=y -CONFIG_BT_CTLR_PRIVACY=y -CONFIG_BT_CTLR_FILTER_ACCEPT_LIST=y -CONFIG_BT_CTLR_DTM_HCI=y -CONFIG_BT_CTLR_DATA_LENGTH_MAX=60 - -CONFIG_BT_LL_SW_LLCP_LEGACY=y -CONFIG_BT_CTLR_ADVANCED_FEATURES=y -CONFIG_BT_CTLR_PARAM_CHECK=n - -# Enable extended advertising -CONFIG_BT_EXT_ADV=y -CONFIG_BT_CTLR_ADV_EXT=y -CONFIG_BT_EXT_ADV_MAX_ADV_SET=2 -CONFIG_BT_CTLR_ADVANCED_FEATURES=y -CONFIG_BT_CTLR_ADV_DATA_CHAIN=y -CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=1650 -CONFIG_BT_CTLR_ADV_DATA_BUF_MAX=2 -CONFIG_BT_EXT_SCAN_BUF_SIZE=1650 -CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=1650 -CONFIG_BT_BUF_EVT_RX_COUNT=16 -CONFIG_BT_CTLR_RX_BUFFERS=9 diff --git a/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_tst_llcp.conf b/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_tst_llcp.conf deleted file mode 100644 index 80fff108da7..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/hci_test_app/prj_tst_llcp.conf +++ /dev/null @@ -1,45 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -CONFIG_BT=y -CONFIG_BT_HCI_RAW=y -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_DEBUG_LOG=y -CONFIG_BT_ECC=y -CONFIG_BT_TINYCRYPT_ECC=y - -# BUF_CMD_TX_SIZE must be 255 because of HCI/GEV/BV-01-C -CONFIG_BT_BUF_ACL_RX_SIZE=60 -CONFIG_BT_BUF_ACL_TX_SIZE=60 -CONFIG_BT_BUF_CMD_TX_SIZE=255 - -## -## Enabling BT_CTRL_DTM_HCI requires BT_LL_SW_SPLIT which requires BT_CTRL -## -CONFIG_BT_CTLR=y - -CONFIG_BT_LL_SW_SPLIT=y -CONFIG_BT_CTLR_CRYPTO=y -CONFIG_BT_CTLR_LE_ENC=y -CONFIG_BT_CTLR_PRIVACY=y -CONFIG_BT_CTLR_FILTER_ACCEPT_LIST=y -CONFIG_BT_CTLR_DTM_HCI=y -CONFIG_BT_CTLR_DATA_LENGTH_MAX=60 - -CONFIG_BT_LL_SW_LLCP=y -CONFIG_BT_CTLR_ADVANCED_FEATURES=y -# LLCP Refactored controller does not support Advanced Scheduling yet -CONFIG_BT_CTLR_SCHED_ADVANCED=n - -# Enable extended advertising -CONFIG_BT_EXT_ADV=y -CONFIG_BT_CTLR_ADV_EXT=y -CONFIG_BT_EXT_ADV_MAX_ADV_SET=2 -CONFIG_BT_CTLR_ADVANCED_FEATURES=y -CONFIG_BT_CTLR_ADV_DATA_CHAIN=y -CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=1650 -CONFIG_BT_CTLR_ADV_DATA_BUF_MAX=2 -CONFIG_BT_EXT_SCAN_BUF_SIZE=1650 -CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=1650 -CONFIG_BT_BUF_EVT_RX_COUNT=16 -CONFIG_BT_CTLR_RX_BUFFERS=9 diff --git a/tests/bluetooth/bsim/ll/edtt/hci_test_app/src/main.c b/tests/bluetooth/bsim/ll/edtt/hci_test_app/src/main.c deleted file mode 100644 index e7af59850cd..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/hci_test_app/src/main.c +++ /dev/null @@ -1,868 +0,0 @@ -/* - * Copyright (c) 2019 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * @brief HCI interface application - */ - -#include - -#include - -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include "edtt_driver.h" -#include "bs_tracing.h" -#include "commands.h" - -#if defined(CONFIG_BT_HCI_CORE_LOG_LEVEL_DBG) -#define LOG_LEVEL LOG_LEVEL_DBG -#else -#define LOG_LEVEL CONFIG_BT_LOG_LEVEL -#endif - -#include -LOG_MODULE_REGISTER(hci_test_app); - -static uint16_t waiting_opcode; -static enum commands_t waiting_response; -static uint8_t m_events; - -struct EdttIxit { - uint8_t refMajor; - uint8_t refMinor; - uint16_t len; - uint8_t *pVal; -}; - -/*! \brief Implementation eXtra Information for Test (IXIT) definitions */ -#if defined(CONFIG_BT_CTLR_CONN_ISO_STREAMS_MAX_NSE) -const uint8_t TSPX_max_cis_nse = CONFIG_BT_CTLR_CONN_ISO_STREAMS_MAX_NSE; -#endif - -/*! \brief Persistent LL IXIT values. */ -static struct EdttIxit llIxits[] = { -#if defined(CONFIG_BT_CTLR_CONN_ISO_STREAMS_MAX_NSE) - {7, 14, 1, &TSPX_max_cis_nse}, -#endif -}; - -/** - * @brief Clean out excess bytes from the input buffer - */ -static void read_excess_bytes(uint16_t size) -{ - if (size > 0) { - uint8_t buffer[size]; - - edtt_read((uint8_t *)buffer, size, EDTTT_BLOCK); - LOG_ERR("command size wrong! (%u extra bytes removed)", size); - } -} - -/** - * @brief Provide an error response when an HCI command send failed - */ -static void error_response(int error) -{ - uint16_t response = sys_cpu_to_le16(waiting_response); - int le_error = sys_cpu_to_le32(error); - uint16_t size = sys_cpu_to_le16(sizeof(le_error)); - - edtt_write((uint8_t *)&response, sizeof(response), EDTTT_BLOCK); - edtt_write((uint8_t *)&size, sizeof(size), EDTTT_BLOCK); - edtt_write((uint8_t *)&le_error, sizeof(le_error), EDTTT_BLOCK); - waiting_response = CMD_NOTHING; - waiting_opcode = 0; -} - -/** - * @brief Allocate buffer for HCI command and fill in opCode for the command - */ -static struct net_buf *hci_cmd_create(uint16_t opcode, uint8_t param_len) -{ - struct bt_hci_cmd_hdr *hdr; - struct net_buf *buf; - - buf = bt_buf_get_tx(BT_BUF_CMD, K_FOREVER, NULL, 0); - __ASSERT_NO_MSG(buf); - - hdr = net_buf_add(buf, sizeof(*hdr)); - hdr->opcode = sys_cpu_to_le16(opcode); - hdr->param_len = param_len; - - return buf; -} - -/** - * @brief Allocate buffer for ACL Data Package and fill in Header - */ -static struct net_buf *acl_data_create(struct bt_hci_acl_hdr *le_hdr) -{ - struct net_buf *buf; - struct bt_hci_acl_hdr *hdr; - - buf = bt_buf_get_tx(BT_BUF_ACL_OUT, K_FOREVER, NULL, 0); - __ASSERT_NO_MSG(buf); - - hdr = net_buf_add(buf, sizeof(*hdr)); - *hdr = *le_hdr; - - return buf; -} - -#if defined(CONFIG_BT_ISO) -/** - * @brief Allocate buffer for ISO Data Package and fill in Header - */ -static struct net_buf *iso_data_create(struct bt_hci_iso_hdr *le_hdr) -{ - struct net_buf *buf; - struct bt_hci_iso_hdr *hdr; - - buf = bt_buf_get_tx(BT_BUF_ISO_OUT, K_FOREVER, NULL, 0); - __ASSERT_NO_MSG(buf); - - hdr = net_buf_add(buf, sizeof(*hdr)); - *hdr = *le_hdr; - - return buf; -} -#endif /* defined(CONFIG_BT_ISO) */ - -/** - * @brief Allocate buffer for HCI command, fill in parameters and send the - * command... - */ -static int send_hci_command(uint16_t opcode, uint8_t param_len, uint16_t response) -{ - struct net_buf *buf; - void *cp; - int err = 0; - - waiting_response = response; - buf = hci_cmd_create(waiting_opcode = opcode, param_len); - if (buf) { - if (param_len) { - cp = net_buf_add(buf, param_len); - edtt_read((uint8_t *)cp, param_len, EDTTT_BLOCK); - } - err = bt_send(buf); - if (err) { - LOG_ERR("Failed to send HCI command %d (err %d)", - opcode, err); - error_response(err); - } - } else { - LOG_ERR("Failed to create buffer for HCI command 0x%04x", - opcode); - error_response(-1); - } - return err; -} - -/** - * @brief Echo function - echo input received... - */ -static void echo(uint16_t size) -{ - uint16_t response = sys_cpu_to_le16(CMD_ECHO_RSP); - uint16_t le_size = sys_cpu_to_le16(size); - - edtt_write((uint8_t *)&response, sizeof(response), EDTTT_BLOCK); - edtt_write((uint8_t *)&le_size, sizeof(le_size), EDTTT_BLOCK); - - if (size > 0) { - uint8_t buff[size]; - - edtt_read(buff, size, EDTTT_BLOCK); - edtt_write(buff, size, EDTTT_BLOCK); - } -} - -NET_BUF_POOL_FIXED_DEFINE(event_pool, 32, BT_BUF_RX_SIZE + 4, 4, NULL); -static K_FIFO_DEFINE(event_queue); -static K_FIFO_DEFINE(rx_queue); -NET_BUF_POOL_FIXED_DEFINE(data_pool, CONFIG_BT_CTLR_RX_BUFFERS + 14, - BT_BUF_ACL_SIZE(CONFIG_BT_BUF_ACL_TX_SIZE) + 4, 4, NULL); -static K_FIFO_DEFINE(data_queue); -#if defined(CONFIG_BT_ISO) -NET_BUF_POOL_FIXED_DEFINE(iso_data_pool, CONFIG_BT_ISO_RX_BUF_COUNT + 14, - BT_ISO_SDU_BUF_SIZE(CONFIG_BT_ISO_RX_MTU) + - sizeof(uint32_t), 8, NULL); -static K_FIFO_DEFINE(iso_data_queue); -#endif /* CONFIG_BT_ISO */ - -/** - * @brief Handle Command Complete HCI event... - */ -static void command_complete(struct net_buf *buf) -{ - struct bt_hci_evt_cmd_complete *evt = (void *)buf->data; - uint16_t opcode = sys_le16_to_cpu(evt->opcode); - uint16_t response = sys_cpu_to_le16(waiting_response); - struct net_buf_simple_state state; - uint16_t size; - - net_buf_simple_save(&buf->b, &state); - - net_buf_pull(buf, sizeof(*evt)); - size = sys_cpu_to_le16(buf->len); - - if (opcode == waiting_opcode) { - LOG_DBG("Command complete for 0x%04x", waiting_opcode); - - edtt_write((uint8_t *)&response, sizeof(response), EDTTT_BLOCK); - edtt_write((uint8_t *)&size, sizeof(size), EDTTT_BLOCK); - edtt_write((uint8_t *)buf->data, buf->len, EDTTT_BLOCK); - waiting_opcode = 0; - } else { - LOG_WRN("Not waiting for 0x(%04x) command status," - " expected 0x(%04x)", opcode, waiting_opcode); - } - - net_buf_simple_restore(&buf->b, &state); -} - -/** - * @brief Handle Command Status HCI event... - */ -static void command_status(struct net_buf *buf) -{ - struct bt_hci_evt_cmd_status *evt = (void *)buf->data; - uint16_t opcode = sys_le16_to_cpu(evt->opcode); - uint16_t response = sys_cpu_to_le16(waiting_response); - struct net_buf_simple_state state; - uint8_t status = evt->status; - uint16_t size; - - net_buf_simple_save(&buf->b, &state); - - net_buf_pull(buf, sizeof(*evt)); - size = sys_cpu_to_le16(buf->len) + 1; - - if (opcode == waiting_opcode) { - LOG_DBG("Command status for 0x%04x", waiting_opcode); - - edtt_write((uint8_t *)&response, sizeof(response), EDTTT_BLOCK); - edtt_write((uint8_t *)&size, sizeof(size), EDTTT_BLOCK); - edtt_write((uint8_t *)&status, sizeof(status), EDTTT_BLOCK); - edtt_write((uint8_t *)buf->data, buf->len, EDTTT_BLOCK); - waiting_opcode = 0; - } else { - LOG_WRN("Not waiting for 0x(%04x) command status," - " expected 0x(%04x)", opcode, waiting_opcode); - } - - net_buf_simple_restore(&buf->b, &state); -} - -/** - * @brief Remove an event from the event queue - */ -static void discard_event(void) -{ - struct net_buf *buf = net_buf_get(&event_queue, K_FOREVER); - - net_buf_unref(buf); - m_events--; -} - -/** - * @brief Allocate and store an event in the event queue - */ -static struct net_buf *queue_event(struct net_buf *buf) -{ - struct net_buf *evt; - - evt = net_buf_alloc(&event_pool, K_NO_WAIT); - if (evt) { - bt_buf_set_type(evt, BT_BUF_EVT); - net_buf_add_le32(evt, sys_cpu_to_le32(k_uptime_get())); - net_buf_add_mem(evt, buf->data, buf->len); - net_buf_put(&event_queue, evt); - m_events++; - } - return evt; -} - -/** - * @brief Thread to service events and ACL/ISO data packets from the HCI input queue - */ -static void service_events(void *p1, void *p2, void *p3) -{ - struct net_buf *buf, *evt; - - while (1) { - buf = net_buf_get(&rx_queue, K_FOREVER); - if (bt_buf_get_type(buf) == BT_BUF_EVT) { - - evt = queue_event(buf); - if (!evt) { - bs_trace_raw_time(4, - "Failed to allocated buffer " - "for event!\n"); - LOG_WRN("No event in queue"); - } - - struct bt_hci_evt_hdr *hdr = (void *)buf->data; - - net_buf_pull(buf, sizeof(*hdr)); - - switch (hdr->evt) { - case BT_HCI_EVT_CMD_COMPLETE: - if (!evt) { - discard_event(); - evt = queue_event(buf); - } - command_complete(buf); - break; - case BT_HCI_EVT_CMD_STATUS: - if (!evt) { - discard_event(); - evt = queue_event(buf); - } - command_status(buf); - break; - default: - break; - } - } else if (bt_buf_get_type(buf) == BT_BUF_ACL_IN) { - struct net_buf *data; - - data = net_buf_alloc(&data_pool, K_NO_WAIT); - if (data) { - bt_buf_set_type(data, BT_BUF_ACL_IN); - net_buf_add_le32(data, - sys_cpu_to_le32(k_uptime_get())); - net_buf_add_mem(data, buf->data, buf->len); - net_buf_put(&data_queue, data); - } -#if defined(CONFIG_BT_ISO) - } else if (bt_buf_get_type(buf) == BT_BUF_ISO_IN) { - struct net_buf *data; - - data = net_buf_alloc(&iso_data_pool, K_NO_WAIT); - if (data) { - bt_buf_set_type(data, BT_BUF_ISO_IN); - net_buf_add_le32(data, - sys_cpu_to_le32(k_uptime_get())); - net_buf_add_mem(data, buf->data, buf->len); - net_buf_put(&iso_data_queue, data); - } -#endif /* CONFIG_BT_ISO */ - } - net_buf_unref(buf); - - k_yield(); - } -} - -/** - * @brief Flush all HCI events from the input-copy queue - */ -static void flush_events(uint16_t size) -{ - uint16_t response = sys_cpu_to_le16(CMD_FLUSH_EVENTS_RSP); - struct net_buf *buf; - - while ((buf = net_buf_get(&event_queue, K_NO_WAIT))) { - net_buf_unref(buf); - m_events--; - } - read_excess_bytes(size); - size = 0; - - edtt_write((uint8_t *)&response, sizeof(response), EDTTT_BLOCK); - edtt_write((uint8_t *)&size, sizeof(size), EDTTT_BLOCK); -} - -/** - * @brief Get next available HCI event from the input-copy queue - */ -static void get_event(uint16_t size) -{ - uint16_t response = sys_cpu_to_le16(CMD_GET_EVENT_RSP); - struct net_buf *buf; - - read_excess_bytes(size); - size = 0; - - edtt_write((uint8_t *)&response, sizeof(response), EDTTT_BLOCK); - buf = net_buf_get(&event_queue, K_FOREVER); - if (buf) { - size = sys_cpu_to_le16(buf->len); - edtt_write((uint8_t *)&size, sizeof(size), EDTTT_BLOCK); - edtt_write((uint8_t *)buf->data, buf->len, EDTTT_BLOCK); - net_buf_unref(buf); - m_events--; - } else { - edtt_write((uint8_t *)&size, sizeof(size), EDTTT_BLOCK); - } -} - -/** - * @brief Get next available HCI events from the input-copy queue - */ -static void get_events(uint16_t size) -{ - uint16_t response = sys_cpu_to_le16(CMD_GET_EVENT_RSP); - struct net_buf *buf; - uint8_t count = m_events; - - read_excess_bytes(size); - size = 0; - - edtt_write((uint8_t *)&response, sizeof(response), EDTTT_BLOCK); - edtt_write((uint8_t *)&count, sizeof(count), EDTTT_BLOCK); - while (count--) { - buf = net_buf_get(&event_queue, K_FOREVER); - size = sys_cpu_to_le16(buf->len); - edtt_write((uint8_t *)&size, sizeof(size), EDTTT_BLOCK); - edtt_write((uint8_t *)buf->data, buf->len, EDTTT_BLOCK); - net_buf_unref(buf); - m_events--; - } -} - -/** - * @brief Check whether an HCI event is available in the input-copy queue - */ -static void has_event(uint16_t size) -{ - struct has_event_resp { - uint16_t response; - uint16_t size; - uint8_t count; - } __packed; - struct has_event_resp le_response = { - .response = sys_cpu_to_le16(CMD_HAS_EVENT_RSP), - .size = sys_cpu_to_le16(1), - .count = m_events - }; - - if (size > 0) { - read_excess_bytes(size); - } - edtt_write((uint8_t *)&le_response, sizeof(le_response), EDTTT_BLOCK); -} - -/** - * @brief Flush all ACL Data Packages from the input-copy queue - */ -static void le_flush_data(uint16_t size) -{ - uint16_t response = sys_cpu_to_le16(CMD_LE_FLUSH_DATA_RSP); - struct net_buf *buf; - - while ((buf = net_buf_get(&data_queue, K_NO_WAIT))) { - net_buf_unref(buf); - } - read_excess_bytes(size); - size = 0; - - edtt_write((uint8_t *)&response, sizeof(response), EDTTT_BLOCK); - edtt_write((uint8_t *)&size, sizeof(size), EDTTT_BLOCK); -} - -/** - * @brief Check whether an ACL Data Package is available in the input-copy queue - */ -static void le_data_ready(uint16_t size) -{ - struct has_data_resp { - uint16_t response; - uint16_t size; - uint8_t empty; - } __packed; - struct has_data_resp le_response = { - .response = sys_cpu_to_le16(CMD_LE_DATA_READY_RSP), - .size = sys_cpu_to_le16(1), - .empty = 0 - }; - - if (size > 0) { - read_excess_bytes(size); - } - if (k_fifo_is_empty(&data_queue)) { - le_response.empty = 1; - } - edtt_write((uint8_t *)&le_response, sizeof(le_response), EDTTT_BLOCK); -} - -/** - * @brief Get next available HCI Data Package from the input-copy queue - */ -static void le_data_read(uint16_t size) -{ - uint16_t response = sys_cpu_to_le16(CMD_LE_DATA_READ_RSP); - struct net_buf *buf; - - read_excess_bytes(size); - size = 0; - - edtt_write((uint8_t *)&response, sizeof(response), EDTTT_BLOCK); - buf = net_buf_get(&data_queue, K_FOREVER); - if (buf) { - size = sys_cpu_to_le16(buf->len); - edtt_write((uint8_t *)&size, sizeof(size), EDTTT_BLOCK); - edtt_write((uint8_t *)buf->data, buf->len, EDTTT_BLOCK); - net_buf_unref(buf); - } else { - edtt_write((uint8_t *)&size, sizeof(size), EDTTT_BLOCK); - } -} - -/** - * @brief Write ACL Data Package to the Controller... - */ -static void le_data_write(uint16_t size) -{ - struct data_write_resp { - uint16_t code; - uint16_t size; - uint8_t status; - } __packed; - struct data_write_resp response = { - .code = sys_cpu_to_le16(CMD_LE_DATA_WRITE_RSP), - .size = sys_cpu_to_le16(1), - .status = 0 - }; - struct net_buf *buf; - struct bt_hci_acl_hdr hdr; - int err; - - if (size >= sizeof(hdr)) { - edtt_read((uint8_t *)&hdr, sizeof(hdr), EDTTT_BLOCK); - size -= sizeof(hdr); - buf = acl_data_create(&hdr); - if (buf) { - uint16_t hdr_length = sys_le16_to_cpu(hdr.len); - uint8_t *pdata = net_buf_add(buf, hdr_length); - - if (size >= hdr_length) { - edtt_read(pdata, hdr_length, EDTTT_BLOCK); - size -= hdr_length; - } - err = bt_send(buf); - if (err) { - LOG_ERR("Failed to send ACL Data (err %d)", - err); - } - } else { - err = -2; /* Failed to allocate data buffer */ - LOG_ERR("Failed to create buffer for ACL Data."); - } - } else { - /* Size too small for header (handle and data length) */ - err = -3; - } - read_excess_bytes(size); - - response.status = sys_cpu_to_le32(err); - edtt_write((uint8_t *)&response, sizeof(response), EDTTT_BLOCK); -} - -#if defined(CONFIG_BT_ISO) -/** - * @brief Flush all ISO Data Packages from the input-copy queue - */ -static void le_flush_iso_data(uint16_t size) -{ - uint16_t response = sys_cpu_to_le16(CMD_LE_FLUSH_ISO_DATA_RSP); - struct net_buf *buf; - - while ((buf = net_buf_get(&iso_data_queue, K_NO_WAIT))) { - net_buf_unref(buf); - } - read_excess_bytes(size); - size = 0; - - edtt_write((uint8_t *)&response, sizeof(response), EDTTT_BLOCK); - edtt_write((uint8_t *)&size, sizeof(size), EDTTT_BLOCK); -} - -/** - * @brief Check whether an ISO Data Package is available in the input-copy queue - */ -static void le_iso_data_ready(uint16_t size) -{ - struct has_iso_data_resp { - uint16_t response; - uint16_t size; - uint8_t empty; - } __packed; - struct has_iso_data_resp le_response = { - .response = sys_cpu_to_le16(CMD_LE_ISO_DATA_READY_RSP), - .size = sys_cpu_to_le16(1), - .empty = 0 - }; - - if (size > 0) { - read_excess_bytes(size); - } - if (k_fifo_is_empty(&iso_data_queue)) { - le_response.empty = 1; - } - edtt_write((uint8_t *)&le_response, sizeof(le_response), EDTTT_BLOCK); -} - -/** - * @brief Get next available ISO Data Package from the input-copy queue - */ -static void le_iso_data_read(uint16_t size) -{ - uint16_t response = sys_cpu_to_le16(CMD_LE_ISO_DATA_READ_RSP); - struct net_buf *buf; - - read_excess_bytes(size); - size = 0; - - edtt_write((uint8_t *)&response, sizeof(response), EDTTT_BLOCK); - buf = net_buf_get(&iso_data_queue, K_FOREVER); - if (buf) { - size = sys_cpu_to_le16(buf->len); - edtt_write((uint8_t *)&size, sizeof(size), EDTTT_BLOCK); - edtt_write((uint8_t *)buf->data, buf->len, EDTTT_BLOCK); - net_buf_unref(buf); - } else { - edtt_write((uint8_t *)&size, sizeof(size), EDTTT_BLOCK); - } -} - -/** - * @brief Write ISO Data Package to the Controller... - */ -static void le_iso_data_write(uint16_t size) -{ - struct iso_data_write_resp { - uint16_t code; - uint16_t size; - uint8_t status; - } __packed; - struct iso_data_write_resp response = { - .code = sys_cpu_to_le16(CMD_LE_ISO_DATA_WRITE_RSP), - .size = sys_cpu_to_le16(1), - .status = 0 - }; - struct net_buf *buf; - struct bt_hci_iso_hdr hdr; - int err; - - if (size >= sizeof(hdr)) { - edtt_read((uint8_t *)&hdr, sizeof(hdr), EDTTT_BLOCK); - size -= sizeof(hdr); - buf = iso_data_create(&hdr); - if (buf) { - uint16_t hdr_length = sys_le16_to_cpu(hdr.len); - uint8_t *pdata = net_buf_add(buf, hdr_length); - - if (size >= hdr_length) { - edtt_read(pdata, hdr_length, EDTTT_BLOCK); - size -= hdr_length; - } - err = bt_send(buf); - if (err) { - LOG_ERR("Failed to send ISO Data (err %d)", - err); - } - } else { - err = -2; /* Failed to allocate data buffer */ - LOG_ERR("Failed to create buffer for ISO Data."); - } - } else { - /* Size too small for header (handle and data length) */ - err = -3; - } - read_excess_bytes(size); - - response.status = sys_cpu_to_le32(err); - edtt_write((uint8_t *)&response, sizeof(response), EDTTT_BLOCK); -} -#endif /* CONFIG_BT_ISO */ - -/** - * @brief Read 'Implementation eXtra Information for Test' value - */ -static void le_ixit_value_read(uint16_t size) -{ - uint8_t profileId; - uint8_t refMajor; - uint8_t refMinor; - struct EdttIxit *pIxitArray; - int ixitArraySize; - struct EdttIxit *pIxitElement = NULL; - - /* - * CMD_GET_IXIT_VALUE_REQ payload layout - * - * ... - * [ 4] PROFILE_ID[0] - * [ 5] IXIT_Reference_Major - * [ 6] IXIT_Reference_Minor - */ - edtt_read((uint8_t *)&profileId, sizeof(profileId), EDTTT_BLOCK); - edtt_read((uint8_t *)&refMajor, sizeof(refMajor), EDTTT_BLOCK); - edtt_read((uint8_t *)&refMinor, sizeof(refMinor), EDTTT_BLOCK); - - switch (profileId) { - case PROFILE_ID_LL: - pIxitArray = llIxits; - ixitArraySize = ARRAY_SIZE(llIxits); - break; - default: - pIxitArray = NULL; - ixitArraySize = 0; - } - for (int i = 0; i < ixitArraySize; i++) { - if (pIxitArray[i].refMajor == refMajor && pIxitArray[i].refMinor == refMinor) { - pIxitElement = &pIxitArray[i]; - break; - } - } - - struct ixit_value_get_resp { - uint16_t code; - uint16_t size; - uint8_t data[]; - } __packed; - struct ixit_value_get_resp response = { - .code = sys_cpu_to_le16(CMD_GET_IXIT_VALUE_RSP), - .size = sys_cpu_to_le16(pIxitElement ? pIxitElement->len : 0), - }; - edtt_write((uint8_t *)&response, sizeof(response), EDTTT_BLOCK); - if (pIxitElement) { - edtt_write(pIxitElement->pVal, pIxitElement->len, EDTTT_BLOCK); - } -} - -static K_THREAD_STACK_DEFINE(service_events_stack, - CONFIG_BT_HCI_TX_STACK_SIZE); -static struct k_thread service_events_data; - -/** - * @brief Zephyr application main entry... - */ -void main(void) -{ - int err; - uint16_t command; - uint16_t size; - uint16_t opcode; - /** - * Initialize HCI command opcode and response variables... - */ - waiting_opcode = 0; - waiting_response = CMD_NOTHING; - m_events = 0; - /** - * Initialize Bluetooth stack in raw mode... - */ - err = bt_enable_raw(&rx_queue); - if (err) { - LOG_ERR("Bluetooth initialization failed (err %d)", err); - return; - } - /** - * Initialize and start EDTT system... - */ -#if defined(CONFIG_ARCH_POSIX) - enable_edtt_mode(); - set_edtt_autoshutdown(true); -#endif - edtt_start(); - /** - * Initialize and start thread to service HCI events and ACL data... - */ - k_thread_create(&service_events_data, service_events_stack, - K_THREAD_STACK_SIZEOF(service_events_stack), - service_events, NULL, NULL, NULL, K_PRIO_COOP(7), - 0, K_NO_WAIT); - - while (1) { - /** - * Wait for a command to arrive - then read and execute command - */ - edtt_read((uint8_t *)&command, sizeof(command), EDTTT_BLOCK); - command = sys_le16_to_cpu(command); - edtt_read((uint8_t *)&size, sizeof(size), EDTTT_BLOCK); - size = sys_le16_to_cpu(size); - bs_trace_raw_time(4, "command 0x%04X received (size %u) " - "events=%u\n", - command, size, m_events); - - switch (command) { - case CMD_ECHO_REQ: - echo(size); - break; - case CMD_FLUSH_EVENTS_REQ: - flush_events(size); - break; - case CMD_HAS_EVENT_REQ: - has_event(size); - break; - case CMD_GET_EVENT_REQ: - { - uint8_t multiple; - - edtt_read((uint8_t *)&multiple, sizeof(multiple), - EDTTT_BLOCK); - if (multiple) - get_events(--size); - else - get_event(--size); - } - break; - case CMD_LE_FLUSH_DATA_REQ: - le_flush_data(size); - break; - case CMD_LE_DATA_READY_REQ: - le_data_ready(size); - break; - case CMD_LE_DATA_WRITE_REQ: - le_data_write(size); - break; - case CMD_LE_DATA_READ_REQ: - le_data_read(size); - break; -#if defined(CONFIG_BT_ISO) - case CMD_LE_FLUSH_ISO_DATA_REQ: - le_flush_iso_data(size); - break; - case CMD_LE_ISO_DATA_READY_REQ: - le_iso_data_ready(size); - break; - case CMD_LE_ISO_DATA_WRITE_REQ: - le_iso_data_write(size); - break; - case CMD_LE_ISO_DATA_READ_REQ: - le_iso_data_read(size); - break; -#endif /* CONFIG_BT_ISO */ - - case CMD_GET_IXIT_VALUE_REQ: - le_ixit_value_read(size); - break; - - default: - if (size >= 2) { - edtt_read((uint8_t *)&opcode, sizeof(opcode), - EDTTT_BLOCK); - send_hci_command(sys_le16_to_cpu(opcode), - size - 2, command + 1); - } - } - } -} diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/_controller_tests_inner.sh b/tests/bluetooth/bsim/ll/edtt/tests_scripts/_controller_tests_inner.sh deleted file mode 100755 index 440f2039b08..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/_controller_tests_inner.sh +++ /dev/null @@ -1,117 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -# -# ENVIRONMENT CONFIGURATION -# ========================= -# -# This script can be configured with a number of environment variables. -# Values in [] are the default unless overridden. -# -# PROJECT CONFIGURATION -# --------------------- -# PRJ_CONF: Default bsim device configuration [prj_dut_conf] -# PRJ_CONF_1: bsim device 1 configuration [PRJ_CONF] -# PRJ_CONF_2: bsim device 2 configuration [PRJ_CONF] -# -# VERBOSITY -# --------- -# VERBOSITY_LEVEL: Global verbosity [2] -# VERBOSITY_LEVEL_EDTT: EDTT verbosity [VERBOSITY_LEVEL] -# VERBOSITY_LEVEL_BRIDGE: EDTT bridge verbosity [VERBOSITY_LEVEL] -# VERBOSITY_LEVEL_PHY: bsim phy verbosity [VERBOSITY_LEVEL] -# VERBOSITY_LEVEL_DEVS: Global bsim device verbosity [VERBOSITY_LEVEL] -# VERBOSITY_LEVEL_DEV1: bsim device 1 verbosity [VERBOSITY_LEVEL_DEVS] -# VERBOSITY_LEVEL_DEV1: bsim device 2 verbosity [VERBOSITY_LEVEL_DEVS] -# -# RR DEBUG SUPPORT -# ---------------- -# RR: Default run bsim device under rr [0] -# 0: disables; any other value enables. -# RR_1: Run bsim device 1 under rr [RR] -# RR_2: Run bsim device 2 under rr [RR] -# - - -# Common part of the test scripts for some of the EDTT tests -# in which 2 controller only builds of the stack are run against each other -VERBOSITY_LEVEL=${VERBOSITY_LEVEL:-2} -VERBOSITY_LEVEL_EDTT=${VERBOSITY_LEVEL_EDTT:-${VERBOSITY_LEVEL}} -VERBOSITY_LEVEL_BRIDGE=${VERBOSITY_LEVEL_BRIDGE:-${VERBOSITY_LEVEL}} -VERBOSITY_LEVEL_PHY=${VERBOSITY_LEVEL_PHY:-${VERBOSITY_LEVEL}} -VERBOSITY_LEVEL_DEVS=${VERBOSITY_LEVEL_DEVS:-${VERBOSITY_LEVEL}} -VERBOSITY_LEVEL_DEV1=${VERBOSITY_LEVEL_1:-${VERBOSITY_LEVEL_DEVS}} -VERBOSITY_LEVEL_DEV2=${VERBOSITY_LEVEL_2:-${VERBOSITY_LEVEL_DEVS}} - -PROCESS_IDS=""; EXIT_CODE=0 - -function Execute(){ - local rr= - if [ "rr" = "$1" ]; then - local devno=$2 - shift 2 - local exe=$(basename $1) - local out=/tmp/rr/$$-${SIMULATION_ID}-${exe}-d_${devno} - rm -rf ${out} - rr="rr record -o ${out}" - fi - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 300 ${rr} $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" -: "${EDTT_PATH:?EDTT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -#Give a default value to PRJ_CONF_x if it does not have one yet: -PRJ_CONF="${PRJ_CONF:-prj_dut_conf}" -PRJ_CONF_1="${PRJ_CONF_1:-${PRJ_CONF}}" -PRJ_CONF_2="${PRJ_CONF_2:-${PRJ_CONF}}" - -#Give default value to RR_x if it does not have one yet: -RR="${RR:-0}" -RR_1="${RR_1:-${RR}}" -RR_2="${RR_2:-${RR}}" - -#Check if rr was requested and is available -if [ "${RR_1}" != "0" -o "${RR_2}" != "0" ]; then - if [ ! -x "$(command -v rr)" ]; then - echo 'error: rr cannot be found in $PATH.' >&2 - exit 1 - fi - - #Set RR_ARGS_x based on RR_x - [ "${RR_1}" != "0" ] && RR_ARGS_1="rr 1" - [ "${RR_2}" != "0" ] && RR_ARGS_2="rr 2" -fi - -cd ${EDTT_PATH} - -Execute ./src/edttool.py -s=${SIMULATION_ID} -d=2 --transport bsim \ - -T $TEST_MODULE -C $TEST_FILE -v=${VERBOSITY_LEVEL_EDTT} -S -l --low-level-device-nbr=3 \ - -D=2 -devs 0 1 -RxWait=2.5e3 - -cd ${BSIM_OUT_PATH}/bin - -Execute \ - ${RR_ARGS_1} ./bs_${BOARD}_tests_bluetooth_bsim_ll_edtt_hci_test_app_${PRJ_CONF_1}\ - -s=${SIMULATION_ID} -d=0 -v=${VERBOSITY_LEVEL_DEV1} -RealEncryption=1 - -Execute \ - ${RR_ARGS_2} ./bs_${BOARD}_tests_bluetooth_bsim_ll_edtt_hci_test_app_${PRJ_CONF_2}\ - -s=${SIMULATION_ID} -d=1 -v=${VERBOSITY_LEVEL_DEV2} -RealEncryption=1 - -Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL_PHY} -s=${SIMULATION_ID} \ - -D=4 -sim_length=3600e6 -dump_imm $@ - -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done -exit $EXIT_CODE #the last exit code != 0 diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gap.llcp.sh b/tests/bluetooth/bsim/ll/edtt/tests_scripts/gap.llcp.sh deleted file mode 100755 index 4717d83664f..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gap.llcp.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -# GAP regression tests based on the EDTTool -CWD="$(cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P)" - -export SIMULATION_ID="edtt_gap_llcp" -export TEST_FILE=${CWD}"/gap.llcp.test_list" -export TEST_MODULE="gap_verification" -export PRJ_CONF_1="prj_dut_llcp_conf" -export PRJ_CONF_2="prj_tst_llcp_conf" - -${CWD}/_controller_tests_inner.sh diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gap.llcp.test_list b/tests/bluetooth/bsim/ll/edtt/tests_scripts/gap.llcp.test_list deleted file mode 100644 index aede979d650..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gap.llcp.test_list +++ /dev/null @@ -1,57 +0,0 @@ -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -GAP/ADV/BV-01-C -GAP/ADV/BV-02-C -GAP/ADV/BV-03-C -GAP/ADV/BV-04-C -GAP/ADV/BV-05-C -GAP/ADV/BV-08-C -GAP/ADV/BV-09-C -GAP/ADV/BV-10-C -GAP/ADV/BV-11-C -GAP/ADV/BV-12-C -GAP/ADV/BV-13-C -GAP/ADV/BV-14-C -GAP/ADV/BV-15-C -GAP/ADV/BV-16-C -GAP/ADV/BV-17-C -GAP/CONN/ACEP/BV-01-C -GAP/CONN/ACEP/BV-03-C -GAP/CONN/ACEP/BV-04-C -GAP/CONN/DCON/BV-01-C -GAP/CONN/GCEP/BV-01-C -GAP/CONN/GCEP/BV-02-C -GAP/CONN/GCEP/BV-05-C -GAP/CONN/GCEP/BV-06-C -GAP/CONN/CPUP/BV-01-C -GAP/CONN/CPUP/BV-02-C -#GAP/CONN/CPUP/BV-03-C # This test implementation is not valid, and will fail with refactored LLCP -GAP/CONN/CPUP/BV-04-C -#GAP/CONN/CPUP/BV-05-C # This test implementation is not valid, and will fail with refactored LLCP -GAP/CONN/CPUP/BV-06-C -GAP/CONN/NCON/BV-01-C -GAP/CONN/NCON/BV-02-C -GAP/CONN/NCON/BV-03-C -GAP/CONN/UCON/BV-01-C -GAP/CONN/UCON/BV-02-C -GAP/CONN/UCON/BV-03-C -GAP/DISC/GENM/BV-01-C -GAP/DISC/GENM/BV-02-C -GAP/DISC/GENM/BV-03-C -GAP/DISC/GENM/BV-04-C -GAP/DISC/GENP/BV-01-C -GAP/DISC/GENP/BV-02-C -GAP/DISC/GENP/BV-04-C -GAP/DISC/GENP/BV-05-C -GAP/DISC/LIMM/BV-01-C -GAP/DISC/LIMM/BV-02-C -GAP/DISC/LIMM/BV-03-C -GAP/DISC/LIMM/BV-04-C -GAP/DISC/LIMP/BV-01-C -GAP/DISC/LIMP/BV-02-C -GAP/DISC/LIMP/BV-04-C -GAP/DISC/LIMP/BV-05-C -GAP/DISC/NONM/BV-01-C -GAP/DISC/NONM/BV-02-C -GAP/DISC/RPA/BV-01-C diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gap.sh b/tests/bluetooth/bsim/ll/edtt/tests_scripts/gap.sh deleted file mode 100755 index 96b3a056fc3..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gap.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -# GAP regression tests based on the EDTTool -CWD="$(cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P)" - -export SIMULATION_ID="edtt_gap" -export TEST_FILE=${CWD}"/gap.test_list" -export TEST_MODULE="gap_verification" -export PRJ_CONF_1="prj_dut_conf" -export PRJ_CONF_2="prj_tst_conf" - -${CWD}/_controller_tests_inner.sh diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gap.test_list b/tests/bluetooth/bsim/ll/edtt/tests_scripts/gap.test_list deleted file mode 100644 index 19ed590e4d7..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gap.test_list +++ /dev/null @@ -1,57 +0,0 @@ -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -GAP/ADV/BV-01-C -GAP/ADV/BV-02-C -GAP/ADV/BV-03-C -GAP/ADV/BV-04-C -GAP/ADV/BV-05-C -GAP/ADV/BV-08-C -GAP/ADV/BV-09-C -GAP/ADV/BV-10-C -GAP/ADV/BV-11-C -GAP/ADV/BV-12-C -GAP/ADV/BV-13-C -GAP/ADV/BV-14-C -GAP/ADV/BV-15-C -GAP/ADV/BV-16-C -GAP/ADV/BV-17-C -GAP/CONN/ACEP/BV-01-C -GAP/CONN/ACEP/BV-03-C -GAP/CONN/ACEP/BV-04-C -GAP/CONN/DCON/BV-01-C -GAP/CONN/GCEP/BV-01-C -GAP/CONN/GCEP/BV-02-C -GAP/CONN/GCEP/BV-05-C -GAP/CONN/GCEP/BV-06-C -GAP/CONN/CPUP/BV-01-C -GAP/CONN/CPUP/BV-02-C -GAP/CONN/CPUP/BV-03-C -GAP/CONN/CPUP/BV-04-C -GAP/CONN/CPUP/BV-05-C -GAP/CONN/CPUP/BV-06-C -GAP/CONN/NCON/BV-01-C -GAP/CONN/NCON/BV-02-C -GAP/CONN/NCON/BV-03-C -GAP/CONN/UCON/BV-01-C -GAP/CONN/UCON/BV-02-C -GAP/CONN/UCON/BV-03-C -GAP/DISC/GENM/BV-01-C -GAP/DISC/GENM/BV-02-C -GAP/DISC/GENM/BV-03-C -GAP/DISC/GENM/BV-04-C -GAP/DISC/GENP/BV-01-C -GAP/DISC/GENP/BV-02-C -GAP/DISC/GENP/BV-04-C -GAP/DISC/GENP/BV-05-C -GAP/DISC/LIMM/BV-01-C -GAP/DISC/LIMM/BV-02-C -GAP/DISC/LIMM/BV-03-C -GAP/DISC/LIMM/BV-04-C -GAP/DISC/LIMP/BV-01-C -GAP/DISC/LIMP/BV-02-C -GAP/DISC/LIMP/BV-04-C -GAP/DISC/LIMP/BV-05-C -GAP/DISC/NONM/BV-01-C -GAP/DISC/NONM/BV-02-C -GAP/DISC/RPA/BV-01-C diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gatt.llcp.sh b/tests/bluetooth/bsim/ll/edtt/tests_scripts/gatt.llcp.sh deleted file mode 100755 index 382e56a5241..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gatt.llcp.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -# GATT regression tests based on the EDTTool -SIMULATION_ID="edtt_gatt_llcp" -VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 -CWD="$(cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P)" - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 300 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" -: "${EDTT_PATH:?EDTT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${EDTT_PATH} - -Execute ./src/edttool.py -s=${SIMULATION_ID} -d=0 --transport bsim \ - -T gatt_verification -C "${CWD}/gatt.llcp.test_list" -v=${VERBOSITY_LEVEL} \ - -D=2 -devs 1 2 -RxWait=2.5e3 - -cd ${BSIM_OUT_PATH}/bin - -Execute \ - ./bs_${BOARD}_tests_bluetooth_bsim_ll_edtt_hci_test_app_prj_tst_llcp_conf\ - -s=${SIMULATION_ID} -d=1 -v=${VERBOSITY_LEVEL} -RealEncryption=1 - -Execute \ - ./bs_${BOARD}_tests_bluetooth_bsim_ll_edtt_gatt_test_app_prj_llcp_conf\ - -s=${SIMULATION_ID} -d=2 -v=${VERBOSITY_LEVEL} -RealEncryption=1 - -Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ - -D=3 -sim_length=3600e6 $@ - -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done -exit $EXIT_CODE #the last exit code != 0 diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gatt.llcp.test_list b/tests/bluetooth/bsim/ll/edtt/tests_scripts/gatt.llcp.test_list deleted file mode 100644 index ad5062aea97..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gatt.llcp.test_list +++ /dev/null @@ -1,72 +0,0 @@ -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -GAP/GAT/BV-01-C -GAP/GAT/BV-04-C -GAP/IDLE/NAMP/BV-01-C -GATT/SR/GAC/BV-01-C -GATT/SR/GAD/BV-01-C -GATT/SR/GAD/BV-02-C -GATT/SR/GAD/BV-03-C -GATT/SR/GAD/BV-04-C -GATT/SR/GAD/BV-05-C -GATT/SR/GAD/BV-06-C -GATT/SR/GAR/BV-01-C -GATT/SR/GAR/BI-01-C -GATT/SR/GAR/BI-02-C -GATT/SR/GAR/BI-03-C -GATT/SR/GAR/BI-04-C -GATT/SR/GAR/BV-03-C -GATT/SR/GAR/BI-06-C -GATT/SR/GAR/BI-07-C -GATT/SR/GAR/BI-09-C -GATT/SR/GAR/BI-10-C -GATT/SR/GAR/BI-11-C -GATT/SR/GAR/BV-04-C -GATT/SR/GAR/BI-12-C -GATT/SR/GAR/BI-13-C -GATT/SR/GAR/BI-14-C -GATT/SR/GAR/BI-15-C -GATT/SR/GAR/BI-16-C -GATT/SR/GAR/BI-17-C -GATT/SR/GAR/BV-05-C -GATT/SR/GAR/BI-18-C -GATT/SR/GAR/BI-19-C -GATT/SR/GAR/BI-20-C -GATT/SR/GAR/BI-21-C -GATT/SR/GAR/BI-22-C -GATT/SR/GAR/BV-06-C -GATT/SR/GAR/BV-07-C -GATT/SR/GAW/BV-01-C -GATT/SR/GAW/BV-03-C -GATT/SR/GAW/BI-02-C -GATT/SR/GAW/BI-03-C -GATT/SR/GAW/BI-04-C -GATT/SR/GAW/BI-05-C -GATT/SR/GAW/BI-06-C -GATT/SR/GAW/BV-05-C -GATT/SR/GAW/BI-07-C -GATT/SR/GAW/BI-08-C -GATT/SR/GAW/BI-09-C -GATT/SR/GAW/BI-11-C -GATT/SR/GAW/BI-12-C -GATT/SR/GAW/BI-13-C -GATT/SR/GAW/BV-08-C -GATT/SR/GAW/BV-09-C -GATT/SR/GAW/BV-11-C -GATT/SR/GAW/BI-32-C -GATT/SR/GAW/BI-33-C -GATT/SR/GAN/BV-01-C -GATT/SR/GAI/BV-01-C -GATT/SR/GAS/BV-01-C -GATT/SR/UNS/BI-01-C -GATT/SR/UNS/BI-02-C -GATT/SR/GPA/BV-01-C -GATT/SR/GPA/BV-02-C -GATT/SR/GPA/BV-03-C -GATT/SR/GPA/BV-04-C -GATT/SR/GPA/BV-05-C -GATT/SR/GPA/BV-06-C -GATT/SR/GPA/BV-07-C -GATT/SR/GPA/BV-08-C -GATT/SR/GPA/BV-12-C diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gatt.sh b/tests/bluetooth/bsim/ll/edtt/tests_scripts/gatt.sh deleted file mode 100755 index d8ba683a15d..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gatt.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -# GATT regression tests based on the EDTTool -SIMULATION_ID="edtt_gatt" -VERBOSITY_LEVEL=2 -PROCESS_IDS=""; EXIT_CODE=0 -CWD="$(cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P)" - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 300 $@ & PROCESS_IDS="$PROCESS_IDS $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" -: "${EDTT_PATH:?EDTT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${EDTT_PATH} - -Execute ./src/edttool.py -s=${SIMULATION_ID} -d=0 --transport bsim \ - -T gatt_verification -C "${CWD}/gatt.test_list" -v=${VERBOSITY_LEVEL} \ - -D=2 -devs 1 2 -RxWait=2.5e3 - -cd ${BSIM_OUT_PATH}/bin - -Execute \ - ./bs_${BOARD}_tests_bluetooth_bsim_ll_edtt_hci_test_app_prj_tst_conf\ - -s=${SIMULATION_ID} -d=1 -v=${VERBOSITY_LEVEL} -RealEncryption=1 - -Execute \ - ./bs_${BOARD}_tests_bluetooth_bsim_ll_edtt_gatt_test_app_prj_conf\ - -s=${SIMULATION_ID} -d=2 -v=${VERBOSITY_LEVEL} -RealEncryption=1 - -Execute ./bs_2G4_phy_v1 -v=${VERBOSITY_LEVEL} -s=${SIMULATION_ID} \ - -D=3 -sim_length=3600e6 $@ - -for PROCESS_ID in $PROCESS_IDS; do - wait $PROCESS_ID || let "EXIT_CODE=$?" -done -exit $EXIT_CODE #the last exit code != 0 diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gatt.test_list b/tests/bluetooth/bsim/ll/edtt/tests_scripts/gatt.test_list deleted file mode 100644 index ad5062aea97..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/gatt.test_list +++ /dev/null @@ -1,72 +0,0 @@ -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -GAP/GAT/BV-01-C -GAP/GAT/BV-04-C -GAP/IDLE/NAMP/BV-01-C -GATT/SR/GAC/BV-01-C -GATT/SR/GAD/BV-01-C -GATT/SR/GAD/BV-02-C -GATT/SR/GAD/BV-03-C -GATT/SR/GAD/BV-04-C -GATT/SR/GAD/BV-05-C -GATT/SR/GAD/BV-06-C -GATT/SR/GAR/BV-01-C -GATT/SR/GAR/BI-01-C -GATT/SR/GAR/BI-02-C -GATT/SR/GAR/BI-03-C -GATT/SR/GAR/BI-04-C -GATT/SR/GAR/BV-03-C -GATT/SR/GAR/BI-06-C -GATT/SR/GAR/BI-07-C -GATT/SR/GAR/BI-09-C -GATT/SR/GAR/BI-10-C -GATT/SR/GAR/BI-11-C -GATT/SR/GAR/BV-04-C -GATT/SR/GAR/BI-12-C -GATT/SR/GAR/BI-13-C -GATT/SR/GAR/BI-14-C -GATT/SR/GAR/BI-15-C -GATT/SR/GAR/BI-16-C -GATT/SR/GAR/BI-17-C -GATT/SR/GAR/BV-05-C -GATT/SR/GAR/BI-18-C -GATT/SR/GAR/BI-19-C -GATT/SR/GAR/BI-20-C -GATT/SR/GAR/BI-21-C -GATT/SR/GAR/BI-22-C -GATT/SR/GAR/BV-06-C -GATT/SR/GAR/BV-07-C -GATT/SR/GAW/BV-01-C -GATT/SR/GAW/BV-03-C -GATT/SR/GAW/BI-02-C -GATT/SR/GAW/BI-03-C -GATT/SR/GAW/BI-04-C -GATT/SR/GAW/BI-05-C -GATT/SR/GAW/BI-06-C -GATT/SR/GAW/BV-05-C -GATT/SR/GAW/BI-07-C -GATT/SR/GAW/BI-08-C -GATT/SR/GAW/BI-09-C -GATT/SR/GAW/BI-11-C -GATT/SR/GAW/BI-12-C -GATT/SR/GAW/BI-13-C -GATT/SR/GAW/BV-08-C -GATT/SR/GAW/BV-09-C -GATT/SR/GAW/BV-11-C -GATT/SR/GAW/BI-32-C -GATT/SR/GAW/BI-33-C -GATT/SR/GAN/BV-01-C -GATT/SR/GAI/BV-01-C -GATT/SR/GAS/BV-01-C -GATT/SR/UNS/BI-01-C -GATT/SR/UNS/BI-02-C -GATT/SR/GPA/BV-01-C -GATT/SR/GPA/BV-02-C -GATT/SR/GPA/BV-03-C -GATT/SR/GPA/BV-04-C -GATT/SR/GPA/BV-05-C -GATT/SR/GPA/BV-06-C -GATT/SR/GPA/BV-07-C -GATT/SR/GPA/BV-08-C -GATT/SR/GPA/BV-12-C diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/hci.llcp.sh b/tests/bluetooth/bsim/ll/edtt/tests_scripts/hci.llcp.sh deleted file mode 100755 index 8e23c68486c..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/hci.llcp.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -# HCI regression tests based on the EDTTool -CWD="$(cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P)" - -export SIMULATION_ID="edtt_hci_llcp" -export TEST_FILE=${CWD}"/hci.llcp.test_list" -export TEST_MODULE="hci_verification" -export PRJ_CONF_1="prj_dut_llcp_conf" -export PRJ_CONF_2="prj_tst_llcp_conf" - -${CWD}/_controller_tests_inner.sh diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/hci.llcp.test_list b/tests/bluetooth/bsim/ll/edtt/tests_scripts/hci.llcp.test_list deleted file mode 100644 index 0ede0ac6aff..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/hci.llcp.test_list +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -HCI/CCO/BV-07-C -HCI/CCO/BV-09-C # [Handling LE Set Data Length Command] -HCI/CCO/BV-10-C -HCI/CCO/BV-11-C -HCI/CCO/BV-12-C -HCI/CCO/BV-13-C -HCI/CCO/BV-14-C -HCI/CCO/BV-15-C -HCI/CCO/BV-18-C -HCI/CFC/BV-02-C -HCI/CIN/BV-01-C -HCI/CIN/BV-03-C -HCI/CIN/BV-04-C -HCI/CIN/BV-06-C -HCI/CIN/BV-09-C -HCI/CM/BV-01-C # [Handling LE Read Peer Resolvable Address Command] -HCI/CM/BV-02-C # [Handling LE Read Local Resolvable Address Command] -HCI/CM/BV-03-C # [Handling LE Read PHY Command] -HCI/DDI/BI-02-C -HCI/DDI/BV-03-C -HCI/DDI/BI-63-C -HCI/DDI/BI-65-C -HCI/DDI/BV-04-C -HCI/DSU/BV-02-C -HCI/DSU/BV-03-C # [Reset Command received in Slave Role] -HCI/DSU/BV-04-C -HCI/DSU/BV-05-C -HCI/DSU/BV-06-C # [Reset Command received in Master Role] -#HCI/GEV/BV-01-C # Test fails since it assumes extended advertising is not supported -HCI/HFC/BV-04-C # [Events enabled by LE Set Event Mask Command] diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/hci.sh b/tests/bluetooth/bsim/ll/edtt/tests_scripts/hci.sh deleted file mode 100755 index dbeb16c6154..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/hci.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -# HCI regression tests based on the EDTTool -CWD="$(cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P)" - -export SIMULATION_ID="edtt_hci" -export TEST_FILE=${CWD}"/hci.test_list" -export TEST_MODULE="hci_verification" -export PRJ_CONF_1="prj_dut_conf" -export PRJ_CONF_2="prj_tst_conf" - -${CWD}/_controller_tests_inner.sh diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/hci.test_list b/tests/bluetooth/bsim/ll/edtt/tests_scripts/hci.test_list deleted file mode 100644 index b2e31882104..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/hci.test_list +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -HCI/CCO/BV-07-C -HCI/CCO/BV-09-C -HCI/CCO/BV-10-C -HCI/CCO/BV-11-C -HCI/CCO/BV-12-C -HCI/CCO/BV-13-C -HCI/CCO/BV-14-C -HCI/CCO/BV-15-C -HCI/CCO/BV-18-C -HCI/CFC/BV-02-C -HCI/CIN/BV-01-C -HCI/CIN/BV-03-C -HCI/CIN/BV-04-C -HCI/CIN/BV-06-C -HCI/CIN/BV-09-C -HCI/CM/BV-01-C -HCI/CM/BV-02-C -HCI/CM/BV-03-C -HCI/DDI/BI-02-C -HCI/DDI/BV-03-C -HCI/DDI/BV-04-C -HCI/DDI/BI-63-C -HCI/DDI/BI-65-C -HCI/DSU/BV-02-C -HCI/DSU/BV-03-C -HCI/DSU/BV-04-C -HCI/DSU/BV-05-C -HCI/DSU/BV-06-C -#HCI/GEV/BV-01-C # Test fails since it assumes extended advertising is not supported -HCI/HFC/BV-04-C diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.1.llcp.sh b/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.1.llcp.sh deleted file mode 100755 index 43a8b326f60..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.1.llcp.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -# LL regression tests based on the EDTTool (part 1) - -CWD="$(cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P)" - -export SIMULATION_ID="edtt_ll_set1_llcp" -export TEST_FILE=${CWD}"/ll.set1.llcp.test_list" -export TEST_MODULE="ll_verification" -export PRJ_CONF_1="prj_dut_llcp_conf" -export PRJ_CONF_2="prj_tst_llcp_conf" - -${CWD}/_controller_tests_inner.sh diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.1.sh b/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.1.sh deleted file mode 100755 index 43ccb419415..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.1.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -# LL regression tests based on the EDTTool (part 1) - -CWD="$(cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P)" - -export SIMULATION_ID="edtt_ll_set1" -export TEST_FILE=${CWD}"/ll.set1.test_list" -export TEST_MODULE="ll_verification" -export PRJ_CONF_1="prj_dut_conf" -export PRJ_CONF_2="prj_tst_conf" - -${CWD}/_controller_tests_inner.sh diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.2.llcp.sh b/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.2.llcp.sh deleted file mode 100755 index 3eb627179b0..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.2.llcp.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -# LL regression tests based on the EDTTool (part 2) - -CWD="$(cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P)" - -export SIMULATION_ID="edtt_ll_set2_llcp" -export TEST_FILE=${CWD}"/ll.set2.llcp.test_list" -export TEST_MODULE="ll_verification" -export PRJ_CONF_1="prj_dut_llcp_conf" -export PRJ_CONF_2="prj_tst_llcp_conf" - -${CWD}/_controller_tests_inner.sh diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.2.sh b/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.2.sh deleted file mode 100755 index f99ec00e969..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.2.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -# LL regression tests based on the EDTTool (part 2) - -CWD="$(cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P)" - -export SIMULATION_ID="edtt_ll_set2" -export TEST_FILE=${CWD}"/ll.set2.test_list" -export TEST_MODULE="ll_verification" -export PRJ_CONF_1="prj_dut_conf" -export PRJ_CONF_2="prj_tst_conf" - -${CWD}/_controller_tests_inner.sh diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.set1.llcp.test_list b/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.set1.llcp.test_list deleted file mode 100644 index c8437fda6af..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.set1.llcp.test_list +++ /dev/null @@ -1,69 +0,0 @@ -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -LL/CON/ADV/BV-01-C -LL/CON/ADV/BV-04-C -LL/CON/ADV/BV-05-C -LL/CON/ADV/BV-06-C -LL/CON/ADV/BV-09-C -LL/CON/ADV/BV-10-C -#LL/CON/ADV/BV-12-C # Fails due to https://github.com/zephyrproject-rtos/zephyr/issues/54531 -LL/CON/ADV/BV-14-C -#LL/CON/ADV/BV-15-C # Fails due to https://github.com/zephyrproject-rtos/zephyr/issues/54531 -LL/CON/INI/BV-01-C -LL/CON/INI/BV-02-C -LL/CON/INI/BV-06-C -LL/CON/INI/BV-07-C -LL/CON/INI/BV-08-C -LL/CON/INI/BV-09-C -LL/CON/INI/BV-10-C -LL/CON/INI/BV-11-C -LL/CON/INI/BV-12-C -LL/CON/INI/BV-16-C -LL/CON/INI/BV-17-C -LL/CON/INI/BV-18-C -LL/CON/INI/BV-19-C -LL/CON/INI/BV-20-C -LL/CON/INI/BV-21-C -LL/CON/INI/BV-23-C -LL/CON/INI/BV-24-C -#LL/CON/CEN/BI-06-C # This test implementation is not valid, and will fail with refactored LLCP -LL/CON/CEN/BV-03-C -LL/CON/CEN/BV-04-C -LL/CON/CEN/BV-05-C -LL/CON/CEN/BV-07-C -LL/CON/CEN/BV-08-C -LL/CON/CEN/BV-09-C -LL/CON/CEN/BV-13-C -LL/CON/CEN/BV-20-C -LL/CON/CEN/BV-21-C -LL/CON/CEN/BV-23-C -LL/CON/CEN/BV-24-C -LL/CON/CEN/BV-25-C -#LL/CON/CEN/BV-26-C # This test case is not valid, and will fail with refactored LLCP -LL/CON/CEN/BV-27-C -LL/CON/CEN/BV-29-C -LL/CON/CEN/BV-30-C -LL/CON/CEN/BV-34-C -LL/CON/CEN/BV-35-C -LL/CON/CEN/BV-41-C -LL/CON/CEN/BV-43-C -LL/CON/CEN/BV-73-C -#LL/CON/CEN/BV-74-C # Needs testcase implementation update -#LL/CON/CEN/BV-76-C # Needs testcase implementation update -#LL/CON/CEN/BV-77-C # Needs testcase implementation update -#LL/CON/PER/BI-08-C # This test implementation is not valid, and will fail with refactored LLCP -LL/CON/PER/BV-04-C -LL/CON/PER/BV-05-C -LL/CON/PER/BV-06-C -LL/CON/PER/BV-10-C -LL/CON/PER/BV-11-C -LL/CON/PER/BV-12-C -LL/CON/PER/BV-14-C -LL/CON/PER/BV-19-C -LL/CON/PER/BV-20-C -LL/CON/PER/BV-22-C -LL/CON/PER/BV-24-C -LL/CON/PER/BV-25-C -LL/CON/PER/BV-26-C -LL/CON/PER/BV-27-C diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.set1.test_list b/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.set1.test_list deleted file mode 100644 index 5784eb0b063..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.set1.test_list +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -LL/CON/ADV/BV-01-C -LL/CON/ADV/BV-04-C -LL/CON/ADV/BV-05-C -LL/CON/ADV/BV-06-C -LL/CON/ADV/BV-09-C -LL/CON/ADV/BV-10-C -LL/CON/ADV/BV-12-C -LL/CON/ADV/BV-14-C -LL/CON/ADV/BV-15-C -LL/CON/INI/BV-01-C -LL/CON/INI/BV-02-C -LL/CON/INI/BV-06-C -LL/CON/INI/BV-07-C -LL/CON/INI/BV-08-C -LL/CON/INI/BV-09-C -LL/CON/INI/BV-10-C -LL/CON/INI/BV-11-C -LL/CON/INI/BV-12-C -LL/CON/INI/BV-16-C -LL/CON/INI/BV-17-C -LL/CON/INI/BV-18-C -LL/CON/INI/BV-19-C -LL/CON/INI/BV-20-C -LL/CON/INI/BV-21-C -LL/CON/INI/BV-23-C -LL/CON/INI/BV-24-C -LL/CON/CEN/BI-06-C -LL/CON/CEN/BV-03-C -LL/CON/CEN/BV-04-C -LL/CON/CEN/BV-05-C -LL/CON/CEN/BV-07-C -LL/CON/CEN/BV-08-C -LL/CON/CEN/BV-09-C -LL/CON/CEN/BV-13-C -LL/CON/CEN/BV-20-C -LL/CON/CEN/BV-21-C -LL/CON/CEN/BV-23-C -LL/CON/CEN/BV-24-C -LL/CON/CEN/BV-25-C -#LL/CON/CEN/BV-26-C # This test case is not valid, and will fail with CPR cache -LL/CON/CEN/BV-27-C -LL/CON/CEN/BV-29-C -LL/CON/CEN/BV-30-C -LL/CON/CEN/BV-34-C -LL/CON/CEN/BV-35-C -LL/CON/CEN/BV-41-C -LL/CON/CEN/BV-43-C -## With updated EDTT, this now fails due to error in legacy DLE handling. Fixed in refactored LLCP -#LL/CON/CEN/BV-73-C -#LL/CON/CEN/BV-74-C # Needs testcase implementation update -## With updated EDTT, this now fails due to error in legacy DLE handling. Fixed in refactored LLCP -#LL/CON/CEN/BV-76-C -#LL/CON/CEN/BV-77-C # Needs testcase implementation update -LL/CON/PER/BI-08-C -LL/CON/PER/BV-04-C -LL/CON/PER/BV-05-C -LL/CON/PER/BV-06-C -LL/CON/PER/BV-10-C -LL/CON/PER/BV-11-C -LL/CON/PER/BV-12-C -LL/CON/PER/BV-14-C -LL/CON/PER/BV-19-C -LL/CON/PER/BV-20-C -LL/CON/PER/BV-22-C -LL/CON/PER/BV-24-C -LL/CON/PER/BV-25-C -LL/CON/PER/BV-26-C -LL/CON/PER/BV-27-C diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.set2.llcp.test_list b/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.set2.llcp.test_list deleted file mode 100644 index 5453c6c0630..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.set2.llcp.test_list +++ /dev/null @@ -1,75 +0,0 @@ -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -LL/CON/PER/BV-29-C -LL/CON/PER/BV-33-C -LL/CON/PER/BV-34-C -LL/CON/PER/BV-40-C -LL/CON/PER/BV-42-C -#LL/CON/PER/BV-77-C # Needs testcase implementation update -#LL/CON/PER/BV-78-C # Needs testcase implementation update -#LL/CON/PER/BV-80-C # Needs testcase implementation update -#LL/CON/PER/BV-81-C # Needs testcase implementation update -LL/DDI/ADV/BI-05-C -LL/DDI/ADV/BI-06-C -LL/DDI/ADV/BV-01-C -LL/DDI/ADV/BV-02-C -LL/DDI/ADV/BV-03-C -LL/DDI/ADV/BV-04-C -LL/DDI/ADV/BV-05-C -LL/DDI/ADV/BV-06-C -LL/DDI/ADV/BV-07-C -LL/DDI/ADV/BV-08-C -LL/DDI/ADV/BV-09-C -LL/DDI/ADV/BV-11-C -LL/DDI/ADV/BV-15-C -LL/DDI/ADV/BV-16-C -LL/DDI/ADV/BV-17-C -LL/DDI/ADV/BV-18-C -LL/DDI/ADV/BV-19-C -LL/DDI/ADV/BV-20-C -LL/DDI/ADV/BV-22-C -#LL/DDI/ADV/BV-27-C # Fails due to https://github.com/zephyrproject-rtos/zephyr/issues/53137 -LL/DDI/ADV/BV-28-C -#LL/DDI/ADV/BV-45-C # Fails due to https://github.com/zephyrproject-rtos/zephyr/issues/53137 -#LL/DDI/ADV/BV-47-C # Fails due to https://github.com/zephyrproject-rtos/zephyr/issues/53137 -#LL/DDI/ADV/BV-49-C # Fails due to https://github.com/zephyrproject-rtos/zephyr/issues/53137 -#LL/DDI/ADV/BV-52-C # Fails due to https://github.com/zephyrproject-rtos/zephyr/issues/53137 -LL/DDI/SCN/BV-01-C -LL/DDI/SCN/BV-02-C -LL/DDI/SCN/BV-03-C -LL/DDI/SCN/BV-04-C -LL/DDI/SCN/BV-05-C -LL/DDI/SCN/BV-10-C -LL/DDI/SCN/BV-11-C -LL/DDI/SCN/BV-12-C -LL/DDI/SCN/BV-13-C -LL/DDI/SCN/BV-14-C -LL/DDI/SCN/BV-15-C -LL/DDI/SCN/BV-16-C -LL/DDI/SCN/BV-17-C -LL/DDI/SCN/BV-18-C -LL/DDI/SCN/BV-26-C -LL/DDI/SCN/BV-28-C -LL/SEC/ADV/BV-02-C -LL/SEC/ADV/BV-03-C -LL/SEC/ADV/BV-04-C -LL/SEC/ADV/BV-05-C -LL/SEC/ADV/BV-06-C -LL/SEC/ADV/BV-08-C -LL/SEC/ADV/BV-09-C -LL/SEC/ADV/BV-10-C -LL/SEC/ADV/BV-11-C -LL/SEC/ADV/BV-12-C -LL/SEC/ADV/BV-13-C -LL/SEC/ADV/BV-14-C -LL/SEC/ADV/BV-15-C -LL/SEC/ADV/BV-16-C -LL/SEC/ADV/BV-17-C -LL/SEC/ADV/BV-18-C -LL/SEC/ADV/BV-20-C -LL/SEC/SCN/BV-01-C -LL/TIM/ADV/BV-03-C -LL/TIM/ADV/BV-04-C -LL/TIM/ADV/BV-05-C -LL/TIM/ADV/BV-07-C diff --git a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.set2.test_list b/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.set2.test_list deleted file mode 100644 index 5453c6c0630..00000000000 --- a/tests/bluetooth/bsim/ll/edtt/tests_scripts/ll.set2.test_list +++ /dev/null @@ -1,75 +0,0 @@ -# Copyright 2019 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -LL/CON/PER/BV-29-C -LL/CON/PER/BV-33-C -LL/CON/PER/BV-34-C -LL/CON/PER/BV-40-C -LL/CON/PER/BV-42-C -#LL/CON/PER/BV-77-C # Needs testcase implementation update -#LL/CON/PER/BV-78-C # Needs testcase implementation update -#LL/CON/PER/BV-80-C # Needs testcase implementation update -#LL/CON/PER/BV-81-C # Needs testcase implementation update -LL/DDI/ADV/BI-05-C -LL/DDI/ADV/BI-06-C -LL/DDI/ADV/BV-01-C -LL/DDI/ADV/BV-02-C -LL/DDI/ADV/BV-03-C -LL/DDI/ADV/BV-04-C -LL/DDI/ADV/BV-05-C -LL/DDI/ADV/BV-06-C -LL/DDI/ADV/BV-07-C -LL/DDI/ADV/BV-08-C -LL/DDI/ADV/BV-09-C -LL/DDI/ADV/BV-11-C -LL/DDI/ADV/BV-15-C -LL/DDI/ADV/BV-16-C -LL/DDI/ADV/BV-17-C -LL/DDI/ADV/BV-18-C -LL/DDI/ADV/BV-19-C -LL/DDI/ADV/BV-20-C -LL/DDI/ADV/BV-22-C -#LL/DDI/ADV/BV-27-C # Fails due to https://github.com/zephyrproject-rtos/zephyr/issues/53137 -LL/DDI/ADV/BV-28-C -#LL/DDI/ADV/BV-45-C # Fails due to https://github.com/zephyrproject-rtos/zephyr/issues/53137 -#LL/DDI/ADV/BV-47-C # Fails due to https://github.com/zephyrproject-rtos/zephyr/issues/53137 -#LL/DDI/ADV/BV-49-C # Fails due to https://github.com/zephyrproject-rtos/zephyr/issues/53137 -#LL/DDI/ADV/BV-52-C # Fails due to https://github.com/zephyrproject-rtos/zephyr/issues/53137 -LL/DDI/SCN/BV-01-C -LL/DDI/SCN/BV-02-C -LL/DDI/SCN/BV-03-C -LL/DDI/SCN/BV-04-C -LL/DDI/SCN/BV-05-C -LL/DDI/SCN/BV-10-C -LL/DDI/SCN/BV-11-C -LL/DDI/SCN/BV-12-C -LL/DDI/SCN/BV-13-C -LL/DDI/SCN/BV-14-C -LL/DDI/SCN/BV-15-C -LL/DDI/SCN/BV-16-C -LL/DDI/SCN/BV-17-C -LL/DDI/SCN/BV-18-C -LL/DDI/SCN/BV-26-C -LL/DDI/SCN/BV-28-C -LL/SEC/ADV/BV-02-C -LL/SEC/ADV/BV-03-C -LL/SEC/ADV/BV-04-C -LL/SEC/ADV/BV-05-C -LL/SEC/ADV/BV-06-C -LL/SEC/ADV/BV-08-C -LL/SEC/ADV/BV-09-C -LL/SEC/ADV/BV-10-C -LL/SEC/ADV/BV-11-C -LL/SEC/ADV/BV-12-C -LL/SEC/ADV/BV-13-C -LL/SEC/ADV/BV-14-C -LL/SEC/ADV/BV-15-C -LL/SEC/ADV/BV-16-C -LL/SEC/ADV/BV-17-C -LL/SEC/ADV/BV-18-C -LL/SEC/ADV/BV-20-C -LL/SEC/SCN/BV-01-C -LL/TIM/ADV/BV-03-C -LL/TIM/ADV/BV-04-C -LL/TIM/ADV/BV-05-C -LL/TIM/ADV/BV-07-C diff --git a/tests/bluetooth/bsim/ll/iso/CMakeLists.txt b/tests/bluetooth/bsim/ll/iso/CMakeLists.txt deleted file mode 100644 index 684b07d7724..00000000000 --- a/tests/bluetooth/bsim/ll/iso/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set\ - the environment variable BSIM_COMPONENTS_PATH to point to its components \ - folder. More information can be found in\ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_iso) - -target_sources(app PRIVATE src/main.c) - -zephyr_include_directories( - ${ZEPHYR_BASE} - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ - ${ZEPHYR_BASE}/subsys/bluetooth/controller/include - ) diff --git a/tests/bluetooth/bsim/ll/iso/prj.conf b/tests/bluetooth/bsim/ll/iso/prj.conf deleted file mode 100644 index 54a83d9f316..00000000000 --- a/tests/bluetooth/bsim/ll/iso/prj.conf +++ /dev/null @@ -1,22 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_DEVICE_NAME="ISO" -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_EXT_ADV=y -CONFIG_BT_PER_ADV=y -CONFIG_BT_PER_ADV_SYNC=y -CONFIG_BT_ISO_BROADCASTER=y -CONFIG_BT_ISO_SYNC_RECEIVER=y - -CONFIG_BT_ISO_TX_MTU=502 -CONFIG_BT_ISO_RX_MTU=502 - -CONFIG_BT_CTLR_ADV_EXT=y -CONFIG_BT_CTLR_ADV_ISO=y -CONFIG_BT_CTLR_SYNC_ISO=y - -CONFIG_BT_CTLR_ISO_TX_BUFFER_SIZE=251 -CONFIG_BT_CTLR_ADV_ISO_PDU_LEN_MAX=251 -CONFIG_BT_CTLR_SYNC_ISO_PDU_LEN_MAX=251 - -CONFIG_BT_CTLR_TEST=y diff --git a/tests/bluetooth/bsim/ll/iso/prj_vs_dp.conf b/tests/bluetooth/bsim/ll/iso/prj_vs_dp.conf deleted file mode 100644 index 9cf785bc925..00000000000 --- a/tests/bluetooth/bsim/ll/iso/prj_vs_dp.conf +++ /dev/null @@ -1,24 +0,0 @@ -CONFIG_BT=y -CONFIG_BT_DEVICE_NAME="ISO" -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_CENTRAL=y -CONFIG_BT_EXT_ADV=y -CONFIG_BT_PER_ADV=y -CONFIG_BT_PER_ADV_SYNC=y -CONFIG_BT_ISO_BROADCASTER=y -CONFIG_BT_ISO_SYNC_RECEIVER=y - -CONFIG_BT_ISO_TX_MTU=502 -CONFIG_BT_ISO_RX_MTU=502 - -CONFIG_BT_CTLR_ADV_EXT=y -CONFIG_BT_CTLR_ADV_ISO=y -CONFIG_BT_CTLR_SYNC_ISO=y - -CONFIG_BT_CTLR_ISO_TX_BUFFER_SIZE=251 -CONFIG_BT_CTLR_ADV_ISO_PDU_LEN_MAX=251 -CONFIG_BT_CTLR_SYNC_ISO_PDU_LEN_MAX=251 - -CONFIG_BT_CTLR_ISO_VENDOR_DATA_PATH=y - -CONFIG_BT_CTLR_TEST=y diff --git a/tests/bluetooth/bsim/ll/iso/src/main.c b/tests/bluetooth/bsim/ll/iso/src/main.c deleted file mode 100644 index 188cf621a00..00000000000 --- a/tests/bluetooth/bsim/ll/iso/src/main.c +++ /dev/null @@ -1,1009 +0,0 @@ -/* main.c - Application main entry point */ - -/* - * Copyright (c) 2020 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include -#include -#include - -#include -#include -#include - -#include "subsys/bluetooth/host/hci_core.h" -#include "subsys/bluetooth/controller/include/ll.h" -#include "subsys/bluetooth/controller/util/memq.h" -#include "subsys/bluetooth/controller/ll_sw/lll.h" - -/* For VS data path */ -#include "subsys/bluetooth/controller/ll_sw/isoal.h" -#include "subsys/bluetooth/controller/ll_sw/ull_iso_types.h" - -#include "bs_types.h" -#include "bs_tracing.h" -#include "time_machine.h" -#include "bstests.h" - -#define FAIL(...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(__VA_ARGS__); \ - } while (0) - -#define PASS(...) \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, __VA_ARGS__); \ - } while (0) - -extern enum bst_result_t bst_result; - -static uint8_t mfg_data1[] = { 0xff, 0xff, 0x01, 0x02, 0x03, 0x04 }; -static uint8_t mfg_data2[] = { 0xff, 0xff, 0x05 }; - -static const struct bt_data per_ad_data1[] = { - BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data1, 6), -}; - -static const struct bt_data per_ad_data2[] = { - BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data2, 3), -}; - -static uint8_t chan_map[] = { 0x1F, 0XF1, 0x1F, 0xF1, 0x1F }; - -static bool volatile is_iso_connected; -static bool volatile deleting_pa_sync; -static void iso_connected(struct bt_iso_chan *chan); -static void iso_disconnected(struct bt_iso_chan *chan, uint8_t reason); -static void iso_recv(struct bt_iso_chan *chan, - const struct bt_iso_recv_info *info, struct net_buf *buf); - -static struct bt_iso_chan_ops iso_ops = { - .connected = iso_connected, - .disconnected = iso_disconnected, - .recv = iso_recv, -}; - -static struct bt_iso_chan_path iso_path_rx = { - .pid = BT_HCI_DATAPATH_ID_HCI -}; - -static struct bt_iso_chan_qos bis_iso_qos; -static struct bt_iso_chan_io_qos iso_tx_qos; -static struct bt_iso_chan_io_qos iso_rx_qos = { - .path = &iso_path_rx -}; - -static struct bt_iso_chan bis_iso_chan = { - .ops = &iso_ops, - .qos = &bis_iso_qos, -}; - -#define BIS_ISO_CHAN_COUNT 1 -static struct bt_iso_chan *bis_channels[BIS_ISO_CHAN_COUNT] = { &bis_iso_chan }; -static uint16_t seq_num; - -NET_BUF_POOL_FIXED_DEFINE(bis_tx_pool, BIS_ISO_CHAN_COUNT, - BT_ISO_SDU_BUF_SIZE(CONFIG_BT_ISO_TX_MTU), 8, NULL); - -#if defined(CONFIG_BT_CTLR_ISO_VENDOR_DATA_PATH) -static uint8_t test_rx_buffer[CONFIG_BT_CTLR_SYNC_ISO_PDU_LEN_MAX]; -static bool is_iso_vs_emitted; - -static isoal_status_t test_sink_sdu_alloc(const struct isoal_sink *sink_ctx, - const struct isoal_pdu_rx *valid_pdu, - struct isoal_sdu_buffer *sdu_buffer) -{ - sdu_buffer->dbuf = test_rx_buffer; - sdu_buffer->size = sizeof(test_rx_buffer); - - return ISOAL_STATUS_OK; -} - - -static isoal_status_t test_sink_sdu_emit(const struct isoal_sink *sink_ctx, - const struct isoal_emitted_sdu_frag *sdu_frag, - const struct isoal_emitted_sdu *sdu) -{ - printk("Vendor sink SDU fragment size %u / %u, seq_num %u, ts %u\n", - sdu_frag->sdu_frag_size, sdu->total_sdu_size, sdu_frag->sdu.seqn, - sdu_frag->sdu.timestamp); - is_iso_vs_emitted = true; - - return ISOAL_STATUS_OK; -} - -static isoal_status_t test_sink_sdu_write(void *dbuf, - const uint8_t *pdu_payload, - const size_t consume_len) -{ - memcpy(dbuf, pdu_payload, consume_len); - - return ISOAL_STATUS_OK; -} - - -bool ll_data_path_sink_create(uint16_t handle, struct ll_iso_datapath *datapath, - isoal_sink_sdu_alloc_cb *sdu_alloc, - isoal_sink_sdu_emit_cb *sdu_emit, - isoal_sink_sdu_write_cb *sdu_write) -{ - ARG_UNUSED(handle); - ARG_UNUSED(datapath); - - *sdu_alloc = test_sink_sdu_alloc; - *sdu_emit = test_sink_sdu_emit; - *sdu_write = test_sink_sdu_write; - - printk("VS data path sink created\n"); - return true; -} -#endif /* CONFIG_BT_CTLR_ISO_VENDOR_DATA_PATH */ - -static void test_iso_main(void) -{ - struct bt_le_ext_adv *adv; - int err; - - printk("\n*ISO broadcast test*\n"); - - printk("Bluetooth initializing..."); - err = bt_enable(NULL); - if (err) { - FAIL("Could not init BT: %d\n", err); - return; - } - printk("success.\n"); - - printk("Create advertising set..."); - err = bt_le_ext_adv_create(BT_LE_EXT_ADV_NCONN_NAME, NULL, &adv); - if (err) { - FAIL("Failed to create advertising set (err %d)\n", err); - return; - } - printk("success.\n"); - - printk("Setting Periodic Advertising parameters..."); - err = bt_le_per_adv_set_param(adv, BT_LE_PER_ADV_DEFAULT); - if (err) { - FAIL("Failed to set periodic advertising parameters (err %d)\n", - err); - return; - } - printk("success.\n"); - - printk("Enable Periodic Advertising..."); - err = bt_le_per_adv_start(adv); - if (err) { - FAIL("Failed to enable periodic advertising (err %d)\n", err); - return; - } - printk("success.\n"); - - printk("Start extended advertising..."); - err = bt_le_ext_adv_start(adv, BT_LE_EXT_ADV_START_DEFAULT); - if (err) { - printk("Failed to start extended advertising (err %d)\n", err); - return; - } - printk("success.\n"); - - -#if TEST_LL_INTERFACE - printk("Creating BIG..."); - uint16_t max_sdu = CONFIG_BT_CTLR_ADV_ISO_PDU_LEN_MAX; - uint8_t bcode[BT_ISO_BROADCAST_CODE_SIZE] = { 0 }; - uint32_t sdu_interval = 10000; /* us */ - uint16_t max_latency = 10; /* ms */ - uint8_t encryption = 0; - uint8_t big_handle = 0; - uint8_t bis_count = 1; /* TODO: Add support for multiple BIS per BIG */ - uint8_t phy = BIT(1); - uint8_t packing = 0; - uint8_t framing = 0; - uint8_t adv_handle; - uint8_t rtn = 0; - - /* Assume that index == handle */ - adv_handle = bt_le_ext_adv_get_index(adv); - - err = ll_big_create(big_handle, adv_handle, bis_count, sdu_interval, - max_sdu, max_latency, rtn, phy, packing, framing, - encryption, bcode); - if (err) { - FAIL("Could not create BIG: %d\n", err); - return; - } - printk("success.\n"); -#endif - - printk("Creating BIG...\n"); - struct bt_iso_big_create_param big_create_param; - struct bt_iso_big *big; - - big_create_param.bis_channels = bis_channels; - big_create_param.num_bis = BIS_ISO_CHAN_COUNT; - big_create_param.encryption = false; - big_create_param.interval = 10000; /* us */ - big_create_param.latency = 10; /* milliseconds */ - big_create_param.packing = 0; /* 0 - sequential; 1 - interleaved */ - big_create_param.framing = 0; /* 0 - unframed; 1 - framed */ - iso_tx_qos.sdu = 502; /* bytes */ - iso_tx_qos.rtn = 2; - iso_tx_qos.phy = BT_GAP_LE_PHY_2M; - bis_iso_qos.tx = &iso_tx_qos; - bis_iso_qos.rx = NULL; - err = bt_iso_big_create(adv, &big_create_param, &big); - if (err) { - FAIL("Could not create BIG: %d\n", err); - return; - } - printk("success.\n"); - - printk("Wait for ISO connected callback..."); - while (!is_iso_connected) { - k_sleep(K_MSEC(100)); - } - printk("ISO connected\n"); - - uint32_t iso_send_count = 0; - uint8_t iso_data[sizeof(iso_send_count)] = { 0 }; - struct net_buf *buf; - - buf = net_buf_alloc(&bis_tx_pool, K_FOREVER); - net_buf_reserve(buf, BT_ISO_CHAN_SEND_RESERVE); - sys_put_le32(++iso_send_count, iso_data); - net_buf_add_mem(buf, iso_data, sizeof(iso_data)); - err = bt_iso_chan_send(&bis_iso_chan, buf, seq_num++, BT_ISO_TIMESTAMP_NONE); - if (err < 0) { - net_buf_unref(buf); - FAIL("Unable to broadcast data (%d)", err); - return; - } - printk("Sending value %u\n", iso_send_count); - - k_sleep(K_MSEC(5000)); - - printk("Update periodic advertising data 1..."); - err = bt_le_per_adv_set_data(adv, per_ad_data1, - ARRAY_SIZE(per_ad_data1)); - if (err) { - FAIL("Failed to update periodic advertising data 1 (%d).\n", - err); - } - printk("success.\n"); - - k_sleep(K_MSEC(2500)); - - printk("Periodic Advertising and ISO Channel Map Update..."); - err = ll_chm_update(chan_map); - if (err) { - FAIL("Channel Map Update failed.\n"); - } - printk("success.\n"); - - k_sleep(K_MSEC(2500)); - - printk("Update periodic advertising data 2..."); - err = bt_le_per_adv_set_data(adv, per_ad_data2, - ARRAY_SIZE(per_ad_data2)); - if (err) { - FAIL("Failed to update periodic advertising data 2 (%d).\n", - err); - } - printk("success.\n"); - - k_sleep(K_MSEC(5000)); - -#if TEST_LL_INTERFACE - printk("Terminating BIG..."); - err = ll_big_terminate(big_handle, BT_HCI_ERR_LOCALHOST_TERM_CONN); - if (err) { - FAIL("Could not terminate BIG: %d\n", err); - return; - } - printk("success.\n"); -#endif - - printk("Terminating BIG...\n"); - err = bt_iso_big_terminate(big); - if (err) { - FAIL("Could not terminate BIG: %d\n", err); - return; - } - printk("success.\n"); - - k_sleep(K_MSEC(10000)); - - printk("Stop Periodic Advertising..."); - err = bt_le_per_adv_stop(adv); - if (err) { - FAIL("Failed to stop periodic advertising (err %d)\n", err); - return; - } - printk("success.\n"); - - - PASS("ISO tests Passed\n"); - - return; -} - -static const char *phy2str(uint8_t phy) -{ - switch (phy) { - case 0: return "No packets"; - case BT_GAP_LE_PHY_1M: return "LE 1M"; - case BT_GAP_LE_PHY_2M: return "LE 2M"; - case BT_GAP_LE_PHY_CODED: return "LE Coded"; - default: return "Unknown"; - } -} - -static void iso_recv(struct bt_iso_chan *chan, - const struct bt_iso_recv_info *info, struct net_buf *buf) -{ - printk("Incoming data channel %p len %u, flags %u, seq_num %u, ts %u\n", - chan, buf->len, info->flags, info->seq_num, info->ts); -} - -static void iso_connected(struct bt_iso_chan *chan) -{ - printk("ISO Channel %p connected\n", chan); - - seq_num = 0U; - is_iso_connected = true; -} - -static uint8_t volatile is_iso_disconnected; - -static void iso_disconnected(struct bt_iso_chan *chan, uint8_t reason) -{ - printk("ISO Channel %p disconnected with reason 0x%02x\n", chan, reason); - - is_iso_disconnected = reason; -} - -static bool volatile is_sync; - -static void pa_sync_cb(struct bt_le_per_adv_sync *sync, - struct bt_le_per_adv_sync_synced_info *info) -{ - char le_addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(info->addr, le_addr, sizeof(le_addr)); - - printk("PER_ADV_SYNC[%u]: [DEVICE]: %s synced, " - "Interval 0x%04x (%u ms), PHY %s\n", - bt_le_per_adv_sync_get_index(sync), le_addr, - info->interval, info->interval * 5 / 4, phy2str(info->phy)); - - is_sync = true; -} - -static void pa_terminated_cb(struct bt_le_per_adv_sync *sync, - const struct bt_le_per_adv_sync_term_info *info) -{ - char le_addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(info->addr, le_addr, sizeof(le_addr)); - - printk("PER_ADV_SYNC[%u]: [DEVICE]: %s sync terminated\n", - bt_le_per_adv_sync_get_index(sync), le_addr); - - if (!deleting_pa_sync) { - FAIL("PA terminated unexpectedly\n"); - } else { - deleting_pa_sync = false; - } -} - -static bool volatile is_sync_recv; - -static void pa_recv_cb(struct bt_le_per_adv_sync *sync, - const struct bt_le_per_adv_sync_recv_info *info, - struct net_buf_simple *buf) -{ - char le_addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(info->addr, le_addr, sizeof(le_addr)); - - printk("PER_ADV_SYNC[%u]: [DEVICE]: %s, tx_power %i, " - "RSSI %i, CTE %u, data length %u\n", - bt_le_per_adv_sync_get_index(sync), le_addr, info->tx_power, - info->rssi, info->cte_type, buf->len); - - is_sync_recv = true; -} - -static void -pa_state_changed_cb(struct bt_le_per_adv_sync *sync, - const struct bt_le_per_adv_sync_state_info *info) -{ - printk("PER_ADV_SYNC[%u]: state changed, receive %s.\n", - bt_le_per_adv_sync_get_index(sync), - info->recv_enabled ? "enabled" : "disabled"); -} - -static bool volatile is_big_info; - -static void pa_biginfo_cb(struct bt_le_per_adv_sync *sync, - const struct bt_iso_biginfo *biginfo) -{ - char le_addr[BT_ADDR_LE_STR_LEN]; - - bt_addr_le_to_str(biginfo->addr, le_addr, sizeof(le_addr)); - printk("BIG INFO[%u]: [DEVICE]: %s, sid 0x%02x, " - "num_bis %u, nse %u, interval 0x%04x (%u ms), " - "bn %u, pto %u, irc %u, max_pdu %u, " - "sdu_interval %u us, max_sdu %u, phy %s, " - "%s framing, %sencrypted\n", - bt_le_per_adv_sync_get_index(sync), le_addr, biginfo->sid, - biginfo->num_bis, biginfo->sub_evt_count, - biginfo->iso_interval, - (biginfo->iso_interval * 5 / 4), - biginfo->burst_number, biginfo->offset, - biginfo->rep_count, biginfo->max_pdu, biginfo->sdu_interval, - biginfo->max_sdu, phy2str(biginfo->phy), - biginfo->framing ? "with" : "without", - biginfo->encryption ? "" : "not "); - - if (!is_big_info) { - is_big_info = true; - } -} - -static struct bt_le_per_adv_sync_cb sync_cb = { - .synced = pa_sync_cb, - .term = pa_terminated_cb, - .recv = pa_recv_cb, - .state_changed = pa_state_changed_cb, - .biginfo = pa_biginfo_cb, -}; - -#define NAME_LEN 30 - -static bool data_cb(struct bt_data *data, void *user_data) -{ - char *name = user_data; - - switch (data->type) { - case BT_DATA_NAME_SHORTENED: - case BT_DATA_NAME_COMPLETE: - memcpy(name, data->data, MIN(data->data_len, NAME_LEN - 1)); - return false; - default: - return true; - } -} - -static bool volatile is_periodic; -static bt_addr_le_t per_addr; -static uint8_t per_sid; - -static void scan_recv(const struct bt_le_scan_recv_info *info, - struct net_buf_simple *buf) -{ - char le_addr[BT_ADDR_LE_STR_LEN]; - char name[NAME_LEN]; - - (void)memset(name, 0, sizeof(name)); - - bt_data_parse(buf, data_cb, name); - - bt_addr_le_to_str(info->addr, le_addr, sizeof(le_addr)); - printk("[DEVICE]: %s, AD evt type %u, Tx Pwr: %i, RSSI %i %s " - "C:%u S:%u D:%u SR:%u E:%u Prim: %s, Secn: %s, " - "Interval: 0x%04x (%u ms), SID: %u\n", - le_addr, info->adv_type, info->tx_power, info->rssi, name, - (info->adv_props & BT_GAP_ADV_PROP_CONNECTABLE) != 0, - (info->adv_props & BT_GAP_ADV_PROP_SCANNABLE) != 0, - (info->adv_props & BT_GAP_ADV_PROP_DIRECTED) != 0, - (info->adv_props & BT_GAP_ADV_PROP_SCAN_RESPONSE) != 0, - (info->adv_props & BT_GAP_ADV_PROP_EXT_ADV) != 0, - phy2str(info->primary_phy), phy2str(info->secondary_phy), - info->interval, info->interval * 5 / 4, info->sid); - - if (info->interval) { - if (!is_periodic) { - is_periodic = true; - per_sid = info->sid; - bt_addr_le_copy(&per_addr, info->addr); - } - } -} - -static struct bt_le_scan_cb scan_callbacks = { - .recv = scan_recv, -}; - -static void test_iso_recv_main(void) -{ - struct bt_le_scan_param scan_param = { - .type = BT_HCI_LE_SCAN_ACTIVE, - .options = BT_LE_SCAN_OPT_NONE, - .interval = 0x0004, - .window = 0x0004, - }; - struct bt_le_per_adv_sync_param sync_create_param; - struct bt_le_per_adv_sync *sync = NULL; - int err; - - printk("\n*ISO broadcast test*\n"); - - printk("Bluetooth initializing..."); - err = bt_enable(NULL); - if (err) { - FAIL("Could not init BT: %d\n", err); - return; - } - printk("success.\n"); - - printk("Scan callbacks register..."); - bt_le_scan_cb_register(&scan_callbacks); - printk("success.\n"); - - printk("Periodic Advertising callbacks register..."); - bt_le_per_adv_sync_cb_register(&sync_cb); - printk("Success.\n"); - - printk("Start scanning..."); - is_periodic = false; - err = bt_le_scan_start(&scan_param, NULL); - if (err) { - FAIL("Could not start scan: %d\n", err); - return; - } - printk("success.\n"); - - while (!is_periodic) { - k_sleep(K_MSEC(100)); - } - printk("Periodic Advertising found (SID: %u)\n", per_sid); - - printk("Creating Periodic Advertising Sync..."); - is_sync = false; - bt_addr_le_copy(&sync_create_param.addr, &per_addr); - sync_create_param.options = - BT_LE_PER_ADV_SYNC_OPT_REPORTING_INITIALLY_DISABLED; - sync_create_param.sid = per_sid; - sync_create_param.skip = 0; - sync_create_param.timeout = 0xa; - err = bt_le_per_adv_sync_create(&sync_create_param, &sync); - if (err) { - FAIL("Could not create sync: %d\n", err); - return; - } - printk("success.\n"); - - /* TODO: Enable when advertiser is added */ - printk("Waiting for sync..."); - while (!is_sync) { - k_sleep(K_MSEC(100)); - } - - printk("Stop scanning..."); - err = bt_le_scan_stop(); - if (err) { - FAIL("Could not stop scan: %d\n", err); - return; - } - printk("success.\n"); - - printk("Wait for BIG Info Advertising Report..."); - is_big_info = false; - while (!is_big_info) { - k_sleep(K_MSEC(100)); - } - printk("success.\n"); - -#if TEST_LL_INTERFACE - printk("Creating BIG Sync..."); - uint8_t bcode[BT_ISO_BROADCAST_CODE_SIZE] = { 0 }; - uint16_t sync_timeout = 10; - uint8_t big_handle = 0; - uint8_t bis_handle = 0; - uint8_t encryption = 0; - uint8_t bis_count = 1; /* TODO: Add support for multiple BIS per BIG */ - uint8_t mse = 0; - - err = ll_big_sync_create(big_handle, sync->handle, encryption, bcode, - mse, sync_timeout, bis_count, &bis_handle); - if (err) { - FAIL("Could not create BIG sync: %d\n", err); - return; - } - printk("success.\n"); - - k_sleep(K_MSEC(5000)); - - printk("Deleting Periodic Advertising Sync..."); - deleting_pa_sync = true; - err = bt_le_per_adv_sync_delete(sync); - if (err) { - FAIL("Failed to delete periodic advertising sync (err %d)\n", - err); - return; - } - printk("success.\n"); - - printk("Terminating BIG Sync..."); - struct node_rx_hdr *node_rx = NULL; - err = ll_big_sync_terminate(big_handle, (void **)&node_rx); - if (err) { - FAIL("Could not terminate BIG sync: %d\n", err); - return; - } - printk("success.\n"); - - if (node_rx) { - FAIL("Generated Node Rx for synchronized BIG.\n"); - } - - k_sleep(K_MSEC(5000)); - - printk("Creating BIG Sync after terminate..."); - err = ll_big_sync_create(big_handle, sync->handle, encryption, bcode, - mse, sync_timeout, bis_count, &bis_handle); - if (err) { - FAIL("Could not create BIG sync: %d\n", err); - return; - } - printk("success.\n"); - - printk("Terminating BIG Sync..."); - node_rx = NULL; - err = ll_big_sync_terminate(big_handle, (void **)&node_rx); - if (err) { - FAIL("Could not terminate BIG sync: %d\n", err); - return; - } - printk("success.\n"); - - if (node_rx) { - node_rx->next = NULL; - ll_rx_mem_release((void **)&node_rx); - } -#else - struct bt_iso_big_sync_param big_param = { 0, }; - struct bt_iso_big *big; - - printk("ISO BIG create sync..."); - is_iso_connected = false; - bis_iso_qos.tx = NULL; - bis_iso_qos.rx = &iso_rx_qos; - big_param.bis_channels = bis_channels; - big_param.num_bis = BIS_ISO_CHAN_COUNT; - big_param.bis_bitfield = BIT(1); /* BIS 1 selected */ - big_param.mse = 1; - big_param.sync_timeout = 100; /* 1000 ms */ - big_param.encryption = false; - iso_path_rx.pid = BT_HCI_DATAPATH_ID_HCI; - memset(big_param.bcode, 0, sizeof(big_param.bcode)); - err = bt_iso_big_sync(sync, &big_param, &big); - if (err) { - FAIL("Could not create BIG sync: %d\n", err); - return; - } - printk("success.\n"); - - printk("Wait for ISO connected callback..."); - while (!is_iso_connected) { - k_sleep(K_MSEC(100)); - } - - printk("ISO terminate BIG..."); - is_iso_disconnected = 0U; - err = bt_iso_big_terminate(big); - if (err) { - FAIL("Could not terminate BIG sync: %d\n", err); - return; - } - printk("success.\n"); - - printk("Waiting for ISO disconnected callback...\n"); - while (!is_iso_disconnected) { - k_sleep(K_MSEC(100)); - } - printk("disconnected.\n"); - - if (is_iso_disconnected != BT_HCI_ERR_LOCALHOST_TERM_CONN) { - FAIL("Local Host Terminate Failed.\n"); - } - - printk("ISO BIG create sync (test remote disconnect)..."); - is_iso_connected = false; - is_iso_disconnected = 0U; - err = bt_iso_big_sync(sync, &big_param, &big); - if (err) { - FAIL("Could not create BIG sync: %d\n", err); - return; - } - printk("success.\n"); - - printk("Wait for ISO connected callback..."); - while (!is_iso_connected) { - k_sleep(K_MSEC(100)); - } - printk("connected.\n"); - - printk("Waiting for ISO disconnected callback...\n"); - while (!is_iso_disconnected) { - k_sleep(K_MSEC(100)); - } - printk("disconnected.\n"); - - if (is_iso_disconnected != BT_HCI_ERR_REMOTE_USER_TERM_CONN) { - FAIL("Remote Host Terminate Failed.\n"); - } - - printk("Periodic sync receive enable...\n"); - err = bt_le_per_adv_sync_recv_enable(sync); - if (err) { - printk("failed (err %d)\n", err); - return; - } - printk("receive enabled.\n"); - - uint8_t check_countdown = 3; - - printk("Waiting for remote BIG terminate by checking for missing " - "%u BIG Info report...\n", check_countdown); - do { - is_sync_recv = false; - is_big_info = false; - while (!is_sync_recv) { - k_sleep(K_MSEC(100)); - } - - k_sleep(K_MSEC(100)); - - if (!is_big_info) { - if (!--check_countdown) { - break; - } - } - } while (1); - printk("success.\n"); - - printk("Deleting Periodic Advertising Sync..."); - deleting_pa_sync = true; - err = bt_le_per_adv_sync_delete(sync); - if (err) { - FAIL("Failed to delete periodic advertising sync (err %d)\n", - err); - return; - } - printk("success.\n"); -#endif - - PASS("ISO recv test Passed\n"); - - return; -} - -#if defined(CONFIG_BT_CTLR_ISO_VENDOR_DATA_PATH) -static void test_iso_recv_vs_dp_main(void) -{ - struct bt_le_scan_param scan_param = { - .type = BT_HCI_LE_SCAN_ACTIVE, - .options = BT_LE_SCAN_OPT_NONE, - .interval = 0x0004, - .window = 0x0004, - }; - struct bt_le_per_adv_sync_param sync_create_param; - struct bt_le_per_adv_sync *sync = NULL; - int err; - - printk("Bluetooth initializing... "); - err = bt_enable(NULL); - if (err) { - FAIL("Could not init BT: %d\n", err); - return; - } - printk("success.\n"); - - printk("Scan callbacks register... "); - bt_le_scan_cb_register(&scan_callbacks); - printk("success.\n"); - - printk("Periodic Advertising callbacks register... "); - bt_le_per_adv_sync_cb_register(&sync_cb); - printk("success.\n"); - - printk("Configure vendor data path... "); - err = bt_configure_data_path(BT_HCI_DATAPATH_DIR_CTLR_TO_HOST, - BT_HCI_DATAPATH_ID_VS, 0U, NULL); - if (err) { - FAIL("Failed (err %d)\n", err); - return; - } - - printk("success.\n"); - printk("Start scanning... "); - is_periodic = false; - err = bt_le_scan_start(&scan_param, NULL); - if (err) { - FAIL("Could not start scan: %d\n", err); - return; - } - printk("success.\n"); - - while (!is_periodic) { - k_sleep(K_MSEC(100)); - } - printk("Periodic Advertising found (SID: %u)\n", per_sid); - - printk("Creating Periodic Advertising Sync... "); - is_sync = false; - - bt_addr_le_copy(&sync_create_param.addr, &per_addr); - sync_create_param.options = - BT_LE_PER_ADV_SYNC_OPT_REPORTING_INITIALLY_DISABLED; - sync_create_param.sid = per_sid; - sync_create_param.skip = 0; - sync_create_param.timeout = 0xa; - - err = bt_le_per_adv_sync_create(&sync_create_param, &sync); - if (err) { - FAIL("Could not create sync: %d\n", err); - return; - } - printk("success.\n"); - - /* TODO: Enable when advertiser is added */ - printk("Waiting for sync...\n"); - while (!is_sync) { - k_sleep(K_MSEC(100)); - } - printk("success.\n"); - - printk("Stop scanning... "); - err = bt_le_scan_stop(); - if (err) { - FAIL("Could not stop scan: %d\n", err); - return; - } - printk("success.\n"); - - printk("Wait for BIG Info Advertising Report...\n"); - is_big_info = false; - while (!is_big_info) { - k_sleep(K_MSEC(100)); - } - printk("success.\n"); - - struct bt_iso_big_sync_param big_param = { 0, }; - struct bt_iso_big *big; - - printk("ISO BIG create sync... "); - is_iso_connected = false; - bis_iso_qos.tx = NULL; - bis_iso_qos.rx = &iso_rx_qos; - big_param.bis_channels = bis_channels; - big_param.num_bis = BIS_ISO_CHAN_COUNT; - big_param.bis_bitfield = BIT(1); /* BIS 1 selected */ - big_param.mse = 1; - big_param.sync_timeout = 100; /* 1000 ms */ - big_param.encryption = false; - memset(big_param.bcode, 0, sizeof(big_param.bcode)); - - is_iso_connected = false; - is_iso_disconnected = 0U; - is_iso_vs_emitted = false; - iso_path_rx.pid = BT_HCI_DATAPATH_ID_VS; - - err = bt_iso_big_sync(sync, &big_param, &big); - if (err) { - FAIL("Could not create BIG sync: %d\n", err); - return; - } - printk("success.\n"); - - printk("Wait for ISO connected callback... "); - while (!is_iso_connected) { - k_sleep(K_MSEC(100)); - } - - /* Allow some SDUs to be received */ - k_sleep(K_MSEC(100)); - - printk("ISO terminate BIG... "); - is_iso_disconnected = 0U; - err = bt_iso_big_terminate(big); - if (err) { - FAIL("Could not terminate BIG sync: %d\n", err); - return; - } - printk("success.\n"); - - printk("Waiting for ISO disconnected callback...\n"); - while (!is_iso_disconnected) { - k_sleep(K_MSEC(100)); - } - printk("disconnected.\n"); - - if (is_iso_disconnected != BT_HCI_ERR_LOCALHOST_TERM_CONN) { - FAIL("Local Host Terminate Failed.\n"); - } - - if (!is_iso_vs_emitted) { - FAIL("Emitting of VS SDUs failed.\n"); - } - - printk("success.\n"); - - printk("Deleting Periodic Advertising Sync... "); - deleting_pa_sync = true; - err = bt_le_per_adv_sync_delete(sync); - if (err) { - FAIL("Failed to delete periodic advertising sync (err %d)\n", - err); - return; - } - printk("success.\n"); - - PASS("ISO recv VS test Passed\n"); -} -#endif /* CONFIG_BT_CTLR_ISO_VENDOR_DATA_PATH */ - -static void test_iso_init(void) -{ - bst_ticker_set_next_tick_absolute(60e6); - bst_result = In_progress; -} - -static void test_iso_tick(bs_time_t HW_device_time) -{ - if (bst_result != Passed) { - FAIL("test failed (not passed after seconds)\n"); - } -} - -static const struct bst_test_instance test_def[] = { - { - .test_id = "broadcast", - .test_descr = "ISO broadcast", - .test_post_init_f = test_iso_init, - .test_tick_f = test_iso_tick, - .test_main_f = test_iso_main - }, - { - .test_id = "receive", - .test_descr = "ISO receive", - .test_post_init_f = test_iso_init, - .test_tick_f = test_iso_tick, - .test_main_f = test_iso_recv_main - }, -#if defined(CONFIG_BT_CTLR_ISO_VENDOR_DATA_PATH) - { - .test_id = "receive_vs_dp", - .test_descr = "ISO receive VS", - .test_post_init_f = test_iso_init, - .test_tick_f = test_iso_tick, - .test_main_f = test_iso_recv_vs_dp_main - }, -#endif /* CONFIG_BT_CTLR_ISO_VENDOR_DATA_PATH */ - BSTEST_END_MARKER -}; - -struct bst_test_list *test_iso_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_def); -} - -bst_test_install_t test_installers[] = { - test_iso_install, - NULL -}; - -void main(void) -{ - bst_main(); -} diff --git a/tests/bluetooth/bsim/ll/iso/tests_scripts/broadcast_iso.sh b/tests/bluetooth/bsim/ll/iso/tests_scripts/broadcast_iso.sh deleted file mode 100755 index 4a576327cc1..00000000000 --- a/tests/bluetooth/bsim/ll/iso/tests_scripts/broadcast_iso.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2020 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -# Basic ISO broadcast test: a broadcaster transmits a BIS and a receiver listens -# to the BIS. -simulation_id="broadcast_iso" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 30 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_ll_iso_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=receive - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_ll_iso_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=broadcast - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=30e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/ll/iso/tests_scripts/broadcast_iso_vs_dp.sh b/tests/bluetooth/bsim/ll/iso/tests_scripts/broadcast_iso_vs_dp.sh deleted file mode 100755 index 6d7a98cf123..00000000000 --- a/tests/bluetooth/bsim/ll/iso/tests_scripts/broadcast_iso_vs_dp.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2020 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -# Basic ISO broadcast test: a broadcaster transmits a BIS and a receiver listens -# to the BIS, and recevied SDUs are emitted via vendor data path implementation. -simulation_id="broadcast_iso_vs_dp" -verbosity_level=2 -process_ids=""; exit_code=0 - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 30 $@ & process_ids="$process_ids $!" -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" - -cd ${BSIM_OUT_PATH}/bin - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_ll_iso_prj_vs_dp_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=receive_vs_dp - -Execute ./bs_${BOARD}_tests_bluetooth_bsim_ll_iso_prj_conf \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=broadcast - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=30e6 $@ - -for process_id in $process_ids; do - wait $process_id || let "exit_code=$?" -done -exit $exit_code #the last exit code != 0 diff --git a/tests/bluetooth/bsim/mesh/CMakeLists.txt b/tests/bluetooth/bsim/mesh/CMakeLists.txt deleted file mode 100644 index efa0003e0d9..00000000000 --- a/tests/bluetooth/bsim/mesh/CMakeLists.txt +++ /dev/null @@ -1,82 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -cmake_minimum_required(VERSION 3.20.0) - -if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH}) - message(FATAL_ERROR "This test requires the BabbleSim simulator. Please set\ - the environment variable BSIM_COMPONENTS_PATH to point to its components \ - folder. More information can be found in\ - https://babblesim.github.io/folder_structure_and_env.html") -endif() - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(bsim_test_mesh) - -target_sources(app PRIVATE - src/main.c - src/mesh_test.c -) - -if(CONFIG_BT_MESH_V1d1) - target_sources(app PRIVATE - src/dfu_blob_common.c - ) -endif() - -if(CONFIG_SETTINGS) - - target_sources(app PRIVATE - src/settings_test_backend.c - src/test_persistence.c - src/test_replay_cache.c - src/test_provision.c - ) - - if(CONFIG_BT_MESH_V1d1) - target_sources(app PRIVATE - src/test_dfu.c - ) - endif() - -elseif(CONFIG_BT_MESH_GATT_PROXY) - - target_sources(app PRIVATE - src/test_advertiser.c - ) - -elseif(CONFIG_BT_CTLR_LOW_LAT) - - target_sources(app PRIVATE - src/test_friendship.c - src/test_transport.c - ) - -else() - - target_sources(app PRIVATE - src/test_transport.c - src/test_friendship.c - src/test_provision.c - src/test_beacon.c - src/test_scanner.c - src/test_heartbeat.c - src/test_access.c - src/test_iv_index.c - src/test_advertiser.c - ) - - if(CONFIG_BT_MESH_V1d1) - target_sources(app PRIVATE - src/test_blob.c - src/test_op_agg.c - src/test_sar.c - src/test_lcd.c - ) - endif() - -endif() - -zephyr_include_directories( - $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/ - $ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/ -) diff --git a/tests/bluetooth/bsim/mesh/README.rst b/tests/bluetooth/bsim/mesh/README.rst deleted file mode 100644 index f2c44759f2c..00000000000 --- a/tests/bluetooth/bsim/mesh/README.rst +++ /dev/null @@ -1,118 +0,0 @@ -Bluetooth mesh BabbleSim tests -############################## - -This directory contains a set of high level system tests for the Bluetooth mesh -subsystem. The tests run on the BabbleSim simulator, using the BabbleSim test -framework. - -Tests are organized into bash scripts under the test_scripts folder. Each -subfolder of test_scripts contains tests for a specific module in the Bluetooth -mesh subsystem, and each folder has a corresponding test_.c under the -src/ directory containing the necessary test harnesses to execute the tests. - -There's only a single test application for all the Bluetooth mesh BabbleSim -tests. The test application is built from this directory, and includes all test -harnesses in every build. The overlying bsim test framework selects the harness -to use at runtime, using the test identifiers passed in the test scripts. - -Running the tests -***************** - -The Bluetooth mesh tests have no extra requirements, and can be run using the -procedure described in the parent folder. - -To only run the mesh tests, set ``SEARCH_PATH`` to point to this folder before -calling ``run_parallel.sh`` - -Debugging the tests -=================== - -Individual test harnesses can be run outside of ``RunTest()`` by setting the -``$SKIP`` array environment variable before calling ``RunTest``. This causes -``RunTest`` to skip starting processes for each application in the ``$SKIPPED`` -array, so that they can be started independently in gdb, valgrind or some other -external tool. - -When running test applications independently, make sure to assign the original -device number with -dXXX to the process. - -Example: To debug the ``transport_tx_seg_block`` test harness in the transport -seg_block test, change transport/seg_block.sh to - -..code-block:: - - SKIP=(transport_tx_seg_block) - RunTest mesh_transport_seg_block \ - transport_tx_seg_block \ - transport_rx_seg_block - -Then separately, call - -...code-block:: - - gdb bs_nrf52_bsim_tests_bluetooth_bsim_mesh_prj_conf \ - -s=mesh_transport_seg_block -d=0 -RealEncryption=1 \ - -testid=transport_tx_seg_block - -Framework -********* - -The Bluetooth mesh BabbleSim tests mainly operate on the test framework for the -BabbleSim platform, but with some mesh specific additions: - -mesh_test.sh -============= - -All test scripts in the Bluetooth mesh BabbleSim test suite follow a common -pattern for running a single test across N devices with different test -harnesses. ``mesh_test.sh`` is sourced in each test script, and its ``RunTest`` -function is called once in each script with the following parameters: - -..code-block:: - - RunTest ... - -``RunTest`` starts one mesh application for each selected harness, before -starting the BabbleSim phy process. - -mesh_test.c -=========== - -Common target side mesh behavior is collected in mesh_test.c and mesh_test.h. -This includes ``PASS``/``FAIL`` macros and some common mesh actions, such as -mesh initialization, as well as message sending and receiving. - -The mesh_test module is never called from the framework, so each test harness -is free to call the parts that are appropriate for its implementation. -All utility functions can be replaced by custom behavior in each harness if the -generic implementation does not fit with the harness requirements. - -Adding tests -************ - -Each test needs a separate test script and one or more test harnesses that -execute the test on target. - -Test scripts should be organized by submodules under the test_scripts -directory, and each test case needs a separate test script with a single test -run. - -Each test harness is defined by a ``struct bst_test_instance` structure, that -is presented to the test runner through an ``install`` function called from the -test application's main function. The harness contains a set of callback -functions that allows starting the test behavior. - -Each mesh test harness should call the ``bt_mesh_test_cfg`` function from its -``test_init_f`` callback to set up the test timeout and mesh metadata. The test -will run until the mesh_test module's ``FAIL`` macro is called, or until the -test times out. At the test timeout, the test will pass if the ``PASS()`` macro -has been called - otherwise, it will fail. - -..note:: - - The Bluetooth stack must be initialized in the ``test_main_f`` function of - the harness, as the previous callbacks are all executed in hardware threads. - -The Bluetooth mesh tests include the entire Bluetooth host and controller -subsystems, so timing requirements should generally be kept fairly liberal to -avoid regressions on changes in the underlying layers. diff --git a/tests/bluetooth/bsim/mesh/_mesh_test.sh b/tests/bluetooth/bsim/mesh/_mesh_test.sh deleted file mode 100755 index 811c8fe9b56..00000000000 --- a/tests/bluetooth/bsim/mesh/_mesh_test.sh +++ /dev/null @@ -1,101 +0,0 @@ -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -process_ids=(); exit_code=0 - -trap ctrl_c INT - -function ctrl_c() { - echo "Aborted by CTRL-C" - conf=${conf:-prj_conf} - - for process_id in ${process_ids[@]}; do - kill -15 $process_id - done -} - -function Execute(){ - if [ ! -f $1 ]; then - echo -e " \e[91m`pwd`/`basename $1` cannot be found (did you forget to\ - compile it?)\e[39m" - exit 1 - fi - timeout 300 $@ & process_ids+=( $! ) -} - -function Skip(){ - for i in "${SKIP[@]}" ; do - if [ "$i" == "$1" ] ; then - return 0 - fi - done - - return 1 -} - -function RunTest(){ - verbosity_level=${verbosity_level:-2} - extra_devs=${EXTRA_DEVS:-0} - - cd ${BSIM_OUT_PATH}/bin - - idx=0 - - s_id=$1 - shift 1 - - testids=() - for testid in $@ ; do - if [ "$testid" == "--" ]; then - shift 1 - break - fi - - testids+=( $testid ) - shift 1 - done - - test_options=$@ - - for testid in ${testids[@]} ; do - if Skip $testid; then - echo "Skipping $testid (device #$idx)" - let idx=idx+1 - continue - fi - - echo "Starting $testid as device #$idx" - conf=${conf:-prj_conf} - - if [ ${overlay} ]; then - exe_name=./bs_${BOARD}_tests_bluetooth_bsim_mesh_${conf}_${overlay} - else - exe_name=./bs_${BOARD}_tests_bluetooth_bsim_mesh_${conf} - fi - - Execute \ - ${exe_name} \ - -v=${verbosity_level} -s=$s_id -d=$idx -RealEncryption=1 \ - -testid=$testid ${test_options} - let idx=idx+1 - done - - count=$(expr $idx + $extra_devs) - - echo "Starting phy with $count devices" - - Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=$s_id -D=$count -argschannel -at=35 - - for process_id in ${process_ids[@]}; do - wait $process_id || let "exit_code=$?" - done - - if [ "$exit_code" != "0" ] ; then - exit $exit_code #the last exit code != 0 - fi -} - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" - -#Give a default value to BOARD if it does not have one yet: -BOARD="${BOARD:-nrf52_bsim}" diff --git a/tests/bluetooth/bsim/mesh/compile.sh b/tests/bluetooth/bsim/mesh/compile.sh deleted file mode 100755 index d1c2df42c02..00000000000 --- a/tests/bluetooth/bsim/mesh/compile.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -# Compile all the applications needed by the bsim tests - -#set -x #uncomment this line for debugging -set -ue - -: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" -: "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" -: "${ZEPHYR_BASE:?ZEPHYR_BASE must be set to point to the zephyr root\ - directory}" - -WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_out}" -BOARD="${BOARD:-nrf52_bsim}" -BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" - -mkdir -p ${WORK_DIR} - -source ${ZEPHYR_BASE}/tests/bluetooth/bsim/compile.source - -app=tests/bluetooth/bsim/mesh compile -app=tests/bluetooth/bsim/mesh conf_overlay=overlay_low_lat.conf compile -app=tests/bluetooth/bsim/mesh conf_overlay=overlay_pst.conf compile -app=tests/bluetooth/bsim/mesh conf_overlay=overlay_gatt.conf compile -app=tests/bluetooth/bsim/mesh conf_file=prj_mesh1d1.conf compile -app=tests/bluetooth/bsim/mesh \ - conf_file=prj_mesh1d1.conf conf_overlay=overlay_pst.conf compile -app=tests/bluetooth/bsim/mesh \ - conf_file=prj_mesh1d1.conf conf_overlay=overlay_gatt.conf compile -app=tests/bluetooth/bsim/mesh \ - conf_file=prj_mesh1d1.conf conf_overlay=overlay_low_lat.conf compile - -wait_for_background_jobs diff --git a/tests/bluetooth/bsim/mesh/overlay_gatt.conf b/tests/bluetooth/bsim/mesh/overlay_gatt.conf deleted file mode 100644 index b2c1bba7fbf..00000000000 --- a/tests/bluetooth/bsim/mesh/overlay_gatt.conf +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_MESH_GATT_PROXY=y -CONFIG_BT_MESH_PB_GATT=y - -CONFIG_BT_MESH_LOW_POWER=n -CONFIG_BT_MESH_FRIEND=n -CONFIG_BT_MESH_IV_UPDATE_TEST=n diff --git a/tests/bluetooth/bsim/mesh/overlay_low_lat.conf b/tests/bluetooth/bsim/mesh/overlay_low_lat.conf deleted file mode 100644 index 4310590d1e8..00000000000 --- a/tests/bluetooth/bsim/mesh/overlay_low_lat.conf +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG_BT_EXT_ADV=n -CONFIG_BT_CTLR_ADVANCED_FEATURES=y -CONFIG_BT_CTLR_LOW_LAT=y -CONFIG_BT_TICKER_LOW_LAT=y diff --git a/tests/bluetooth/bsim/mesh/overlay_pst.conf b/tests/bluetooth/bsim/mesh/overlay_pst.conf deleted file mode 100644 index 87fa5b6c40e..00000000000 --- a/tests/bluetooth/bsim/mesh/overlay_pst.conf +++ /dev/null @@ -1,17 +0,0 @@ -CONFIG_SETTINGS=y -CONFIG_SETTINGS_CUSTOM=y -CONFIG_BT_SETTINGS=y -CONFIG_BT_MESH_SETTINGS_LOG_LEVEL_DBG=y - -CONFIG_BT_PERIPHERAL=y -CONFIG_BT_MESH_GATT_PROXY=y -CONFIG_BT_MESH_PB_GATT=y - -CONFIG_BT_MESH_MODEL_GROUP_COUNT=2 -CONFIG_BT_MESH_CDB_NODE_COUNT=3 -CONFIG_BT_MESH_CDB_SUBNET_COUNT=2 -CONFIG_BT_MESH_SUBNET_COUNT=2 -CONFIG_BT_MESH_SEQ_STORE_RATE=1 -CONFIG_BT_MESH_RPL_STORE_TIMEOUT=1 -CONFIG_BT_MESH_STORE_TIMEOUT=1 -CONFIG_BT_MESH_TX_SEG_RETRANS_COUNT=1 diff --git a/tests/bluetooth/bsim/mesh/prj.conf b/tests/bluetooth/bsim/mesh/prj.conf deleted file mode 100644 index 3679e0301d5..00000000000 --- a/tests/bluetooth/bsim/mesh/prj.conf +++ /dev/null @@ -1,47 +0,0 @@ -CONFIG_LOG_MODE_IMMEDIATE=y -CONFIG_ASSERT=y -CONFIG_SYS_CLOCK_TICKS_PER_SEC=32768 - -# Bluetooth configuration -CONFIG_BT=y -CONFIG_BT_DEBUG_LOG=y -CONFIG_BT_PRIVACY=n -CONFIG_BT_COMPANY_ID=0x0059 -CONFIG_BT_DEVICE_NAME="Mesh test" -CONFIG_BT_LL_SW_SPLIT=y -CONFIG_BT_OBSERVER=y -CONFIG_BT_BROADCASTER=y -CONFIG_BT_TINYCRYPT_ECC=y - -# Disable unused Bluetooth features -CONFIG_BT_CTLR_DUP_FILTER_LEN=0 -CONFIG_BT_CTLR_PRIVACY=n - -# Bluetooth mesh configuration -CONFIG_BT_MESH=y -CONFIG_BT_MESH_LOG_LEVEL_DBG=y -CONFIG_BT_MESH_RELAY=y -CONFIG_BT_MESH_ADV_BUF_COUNT=32 -CONFIG_BT_MESH_TX_SEG_MAX=32 -CONFIG_BT_MESH_RX_SEG_MAX=32 -CONFIG_BT_MESH_TX_SEG_MSG_COUNT=10 -CONFIG_BT_MESH_RX_SEG_MSG_COUNT=10 -CONFIG_BT_MESH_CFG_CLI=y -CONFIG_BT_MESH_MODEL_GROUP_COUNT=3 -CONFIG_BT_MESH_LOW_POWER=y -CONFIG_BT_MESH_LPN_AUTO=n -CONFIG_BT_MESH_FRIEND=y -CONFIG_BT_MESH_FRIEND_ENABLED=n -CONFIG_BT_MESH_FRIEND_LPN_COUNT=5 -CONFIG_BT_MESH_APP_KEY_COUNT=2 -CONFIG_BT_MESH_MODEL_KEY_COUNT=2 -CONFIG_BT_MESH_LABEL_COUNT=2 -CONFIG_BT_MESH_IV_UPDATE_TEST=y -CONFIG_BT_MESH_PB_ADV=y -CONFIG_BT_MESH_PROVISIONER=y -CONFIG_BT_MESH_PROV_DEVICE=y -CONFIG_BT_MESH_CDB=y -CONFIG_BT_MESH_CDB_NODE_COUNT=4 -CONFIG_BT_MESH_PROV_OOB_PUBLIC_KEY=y -CONFIG_BT_MESH_MODEL_EXTENSIONS=y -CONFIG_BT_MESH_SUBNET_COUNT=5 diff --git a/tests/bluetooth/bsim/mesh/prj_mesh1d1.conf b/tests/bluetooth/bsim/mesh/prj_mesh1d1.conf deleted file mode 100644 index 0ab9bfea131..00000000000 --- a/tests/bluetooth/bsim/mesh/prj_mesh1d1.conf +++ /dev/null @@ -1,65 +0,0 @@ -CONFIG_LOG_MODE_IMMEDIATE=y -CONFIG_ASSERT=y -CONFIG_SYS_CLOCK_TICKS_PER_SEC=32768 - -# Bluetooth configuration -CONFIG_BT=y -CONFIG_BT_DEBUG_LOG=y -CONFIG_BT_PRIVACY=n -CONFIG_BT_COMPANY_ID=0x0059 -CONFIG_BT_DEVICE_NAME="Mesh test" -CONFIG_BT_LL_SW_SPLIT=y -CONFIG_BT_OBSERVER=y -CONFIG_BT_BROADCASTER=y -CONFIG_BT_TINYCRYPT_ECC=y - -# Disable unused Bluetooth features -CONFIG_BT_CTLR_DUP_FILTER_LEN=0 -CONFIG_BT_CTLR_PRIVACY=n - -# Bluetooth mesh configuration -CONFIG_BT_MESH=y -CONFIG_BT_MESH_V1d1=y -CONFIG_BT_MESH_LOG_LEVEL_DBG=y -CONFIG_BT_MESH_RELAY=y -CONFIG_BT_MESH_ADV_BUF_COUNT=64 -CONFIG_BT_MESH_TX_SEG_MAX=32 -CONFIG_BT_MESH_RX_SEG_MAX=32 -CONFIG_BT_MESH_TX_SEG_MSG_COUNT=10 -CONFIG_BT_MESH_RX_SEG_MSG_COUNT=10 -CONFIG_BT_MESH_CFG_CLI=y -CONFIG_BT_MESH_MODEL_GROUP_COUNT=3 -CONFIG_BT_MESH_LOW_POWER=y -CONFIG_BT_MESH_LPN_AUTO=n -CONFIG_BT_MESH_FRIEND=y -CONFIG_BT_MESH_FRIEND_ENABLED=n -CONFIG_BT_MESH_FRIEND_LPN_COUNT=5 -CONFIG_BT_MESH_APP_KEY_COUNT=2 -CONFIG_BT_MESH_MODEL_KEY_COUNT=2 -CONFIG_BT_MESH_LABEL_COUNT=2 -CONFIG_BT_MESH_IV_UPDATE_TEST=y -CONFIG_BT_MESH_PB_ADV=y -CONFIG_BT_MESH_PROVISIONER=y -CONFIG_BT_MESH_PROV_DEVICE=y -CONFIG_BT_MESH_CDB=y -CONFIG_BT_MESH_CDB_NODE_COUNT=4 -CONFIG_BT_MESH_PROV_OOB_PUBLIC_KEY=y -CONFIG_BT_MESH_MODEL_EXTENSIONS=y -CONFIG_BT_MESH_SUBNET_COUNT=5 -CONFIG_BT_MESH_SAR_CFG_CLI=y -CONFIG_BT_MESH_SAR_CFG_SRV=y -CONFIG_BT_MESH_BLOB_SRV=y -CONFIG_BT_MESH_BLOB_CLI=y -CONFIG_BT_MESH_BLOB_BLOCK_SIZE_MIN=256 -CONFIG_BT_MESH_RPR_CLI=y -CONFIG_BT_MESH_RPR_SRV=y -CONFIG_BT_MESH_OP_AGG_CLI=y -CONFIG_BT_MESH_OP_AGG_SRV=y -CONFIG_BT_MESH_LARGE_COMP_DATA_CLI=y -CONFIG_BT_MESH_LARGE_COMP_DATA_SRV=y -CONFIG_BT_MESH_DFU_SRV=y -CONFIG_BT_MESH_DFU_CLI=y -CONFIG_BT_MESH_DFD_SRV=y - -# Needed for RPR tests due to huge amount of retransmitted messages -CONFIG_BT_MESH_MSG_CACHE_SIZE=64 diff --git a/tests/bluetooth/bsim/mesh/src/dfu_blob_common.c b/tests/bluetooth/bsim/mesh/src/dfu_blob_common.c deleted file mode 100644 index f8083094980..00000000000 --- a/tests/bluetooth/bsim/mesh/src/dfu_blob_common.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "dfu_blob_common.h" -#include -#include "mesh_test.h" - -static struct { - uint16_t addrs[6]; - int rem_cnt; -} lost_targets; - -bool lost_target_find_and_remove(uint16_t addr) -{ - for (int i = 0; i < ARRAY_SIZE(lost_targets.addrs); i++) { - if (addr == lost_targets.addrs[i]) { - lost_targets.addrs[i] = 0; - ASSERT_TRUE(lost_targets.rem_cnt > 0); - lost_targets.rem_cnt--; - return true; - } - } - - return false; -} - -void lost_target_add(uint16_t addr) -{ - if (lost_targets.rem_cnt >= ARRAY_SIZE(lost_targets.addrs)) { - FAIL("No more room in lost target list"); - return; - } - - lost_targets.addrs[lost_targets.rem_cnt] = addr; - lost_targets.rem_cnt++; -} - -int lost_targets_rem(void) -{ - return lost_targets.rem_cnt; -} - -void common_sar_conf(uint16_t addr) -{ - int err; - - /* Reconfigure SAR Transmitter state to change compile-time configuration to default - * configuration. - */ - struct bt_mesh_sar_tx tx_set = { - .seg_int_step = 1, - .unicast_retrans_count = 2, - .unicast_retrans_without_prog_count = 2, - .unicast_retrans_int_step = 7, - .unicast_retrans_int_inc = 1, - .multicast_retrans_count = 2, - .multicast_retrans_int = 3, - }; - struct bt_mesh_sar_tx tx_rsp; - - err = bt_mesh_sar_cfg_cli_transmitter_set(0, addr, &tx_set, &tx_rsp); - if (err) { - FAIL("Failed to configure SAR Transmitter state (err %d)", err); - } - - /* Reconfigure SAR Receiver state so that the transport layer doesn't generate SegAcks too - * frequently. - */ - struct bt_mesh_sar_rx rx_set = { - .seg_thresh = 0x1f, - .ack_delay_inc = 7, - .discard_timeout = 1, - .rx_seg_int_step = 0xf, - .ack_retrans_count = 1, - }; - struct bt_mesh_sar_rx rx_rsp; - - err = bt_mesh_sar_cfg_cli_receiver_set(0, addr, &rx_set, &rx_rsp); - if (err) { - FAIL("Failed to configure SAR Receiver state (err %d)", err); - } -} diff --git a/tests/bluetooth/bsim/mesh/src/dfu_blob_common.h b/tests/bluetooth/bsim/mesh/src/dfu_blob_common.h deleted file mode 100644 index 1f410ce32c4..00000000000 --- a/tests/bluetooth/bsim/mesh/src/dfu_blob_common.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -bool lost_target_find_and_remove(uint16_t addr); -void lost_target_add(uint16_t addr); -int lost_targets_rem(void); - -void common_sar_conf(uint16_t addr); diff --git a/tests/bluetooth/bsim/mesh/src/main.c b/tests/bluetooth/bsim/mesh/src/main.c deleted file mode 100644 index a402879843d..00000000000 --- a/tests/bluetooth/bsim/mesh/src/main.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2021 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "bstests.h" -#include "mesh_test.h" - -#if defined(CONFIG_SETTINGS) -extern struct bst_test_list *test_persistence_install(struct bst_test_list *tests); -extern struct bst_test_list *test_rpc_install(struct bst_test_list *tests); -extern struct bst_test_list *test_provision_pst_install(struct bst_test_list *tests); -#if defined(CONFIG_BT_MESH_V1d1) -extern struct bst_test_list *test_dfu_install(struct bst_test_list *test); -#endif /* defined(CONFIG_BT_MESH_V1d1) */ -#elif defined(CONFIG_BT_MESH_GATT_PROXY) -extern struct bst_test_list *test_adv_install(struct bst_test_list *test); -#elif defined(CONFIG_BT_CTLR_LOW_LAT) -extern struct bst_test_list *test_transport_install(struct bst_test_list *tests); -extern struct bst_test_list *test_friendship_install(struct bst_test_list *tests); -#else -extern struct bst_test_list *test_transport_install(struct bst_test_list *tests); -extern struct bst_test_list *test_friendship_install(struct bst_test_list *tests); -extern struct bst_test_list *test_provision_install(struct bst_test_list *tests); -extern struct bst_test_list *test_beacon_install(struct bst_test_list *tests); -extern struct bst_test_list *test_scanner_install(struct bst_test_list *test); -extern struct bst_test_list *test_heartbeat_install(struct bst_test_list *test); -extern struct bst_test_list *test_access_install(struct bst_test_list *test); -extern struct bst_test_list *test_ivi_install(struct bst_test_list *test); -extern struct bst_test_list *test_adv_install(struct bst_test_list *test); -#if defined(CONFIG_BT_MESH_V1d1) -extern struct bst_test_list *test_blob_install(struct bst_test_list *test); -extern struct bst_test_list *test_op_agg_install(struct bst_test_list *test); -extern struct bst_test_list *test_sar_install(struct bst_test_list *test); -extern struct bst_test_list *test_lcd_install(struct bst_test_list *test); -#endif /* defined(CONFIG_BT_MESH_V1d1) */ -#endif - -bst_test_install_t test_installers[] = { -#if defined(CONFIG_SETTINGS) - test_persistence_install, - test_rpc_install, -#if defined(CONFIG_BT_MESH_V1d1) - test_provision_pst_install, - test_dfu_install, -#endif /* defined(CONFIG_BT_MESH_V1d1) */ -#elif defined(CONFIG_BT_MESH_GATT_PROXY) - test_adv_install, -#elif defined(CONFIG_BT_CTLR_LOW_LAT) - test_transport_install, - test_friendship_install, -#else - test_transport_install, - test_friendship_install, - test_provision_install, - test_beacon_install, - test_scanner_install, - test_heartbeat_install, - test_access_install, - test_ivi_install, - test_adv_install, -#if defined(CONFIG_BT_MESH_V1d1) - test_blob_install, - test_op_agg_install, - test_sar_install, - test_lcd_install, -#endif /* defined(CONFIG_BT_MESH_V1d1) */ -#endif - NULL -}; - -void main(void) -{ - bst_main(); -} diff --git a/tests/bluetooth/bsim/mesh/src/mesh_test.c b/tests/bluetooth/bsim/mesh/src/mesh_test.c deleted file mode 100644 index 61eec7538c6..00000000000 --- a/tests/bluetooth/bsim/mesh/src/mesh_test.c +++ /dev/null @@ -1,534 +0,0 @@ -/* - * Copyright (c) 2021 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include "mesh_test.h" -#include "argparse.h" -#include - -#define LOG_MODULE_NAME mesh_test - -#include -LOG_MODULE_REGISTER(LOG_MODULE_NAME); - -/* Max number of messages that can be pending on RX at the same time */ -#define RECV_QUEUE_SIZE 32 - -const struct bt_mesh_test_cfg *cfg; - -K_MEM_SLAB_DEFINE_STATIC(msg_pool, sizeof(struct bt_mesh_test_msg), - RECV_QUEUE_SIZE, 4); -static K_QUEUE_DEFINE(recv); -struct bt_mesh_test_stats test_stats; -struct bt_mesh_msg_ctx test_send_ctx; -static void (*ra_cb)(uint8_t *, size_t); - -static int msg_rx(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) -{ - size_t len = buf->len + BT_MESH_MODEL_OP_LEN(TEST_MSG_OP_1); - static uint8_t prev_seq; - struct bt_mesh_test_msg *msg; - uint8_t seq = 0; - - if (buf->len) { - seq = net_buf_simple_pull_u8(buf); - if (prev_seq == seq) { - FAIL("Received same message twice"); - return -EINVAL; - } - - prev_seq = seq; - } - - LOG_INF("Received packet 0x%02x:", seq); - LOG_INF("\tlen: %d bytes", len); - LOG_INF("\tsrc: 0x%04x", ctx->addr); - LOG_INF("\tdst: 0x%04x", ctx->recv_dst); - LOG_INF("\tttl: %u", ctx->recv_ttl); - LOG_INF("\trssi: %d", ctx->recv_rssi); - - for (int i = 1; buf->len; i++) { - if (net_buf_simple_pull_u8(buf) != (i & 0xff)) { - FAIL("Invalid message content (byte %u)", i); - return -EINVAL; - } - } - - test_stats.received++; - - if (k_mem_slab_alloc(&msg_pool, (void **)&msg, K_NO_WAIT)) { - test_stats.recv_overflow++; - return -EOVERFLOW; - } - - msg->len = len; - msg->seq = seq; - msg->ctx = *ctx; - - k_queue_append(&recv, msg); - - return 0; -} - -static int ra_rx(struct bt_mesh_model *mod, struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) -{ - LOG_INF("\tlen: %d bytes", buf->len); - LOG_INF("\tsrc: 0x%04x", ctx->addr); - LOG_INF("\tdst: 0x%04x", ctx->recv_dst); - LOG_INF("\tttl: %u", ctx->recv_ttl); - LOG_INF("\trssi: %d", ctx->recv_rssi); - - if (ra_cb) { - ra_cb(net_buf_simple_pull_mem(buf, buf->len), buf->len); - } - - return 0; -} - -static const struct bt_mesh_model_op model_op[] = { - { TEST_MSG_OP_1, 0, msg_rx }, - { TEST_MSG_OP_2, 0, ra_rx }, - BT_MESH_MODEL_OP_END -}; - -int __weak test_model_pub_update(struct bt_mesh_model *mod) -{ - return -1; -} - -int __weak test_model_settings_set(struct bt_mesh_model *model, - const char *name, size_t len_rd, - settings_read_cb read_cb, void *cb_arg) -{ - return -1; -} - -void __weak test_model_reset(struct bt_mesh_model *model) -{ - /* No-op. */ -} - -static const struct bt_mesh_model_cb test_model_cb = { - .settings_set = test_model_settings_set, - .reset = test_model_reset, -}; - -static struct bt_mesh_model_pub pub = { - .msg = NET_BUF_SIMPLE(BT_MESH_TX_SDU_MAX), - .update = test_model_pub_update, -}; - -static const struct bt_mesh_model_op vnd_model_op[] = { - BT_MESH_MODEL_OP_END, -}; - -int __weak test_vnd_model_pub_update(struct bt_mesh_model *mod) -{ - return -1; -} - -int __weak test_vnd_model_settings_set(struct bt_mesh_model *model, - const char *name, size_t len_rd, - settings_read_cb read_cb, void *cb_arg) -{ - return -1; -} - -void __weak test_vnd_model_reset(struct bt_mesh_model *model) -{ - /* No-op. */ -} - -static const struct bt_mesh_model_cb test_vnd_model_cb = { - .settings_set = test_vnd_model_settings_set, - .reset = test_vnd_model_reset, -}; - -static struct bt_mesh_model_pub vnd_pub = { - .msg = NET_BUF_SIMPLE(BT_MESH_TX_SDU_MAX), - .update = test_vnd_model_pub_update, -}; - -static struct bt_mesh_cfg_cli cfg_cli; - -static struct bt_mesh_health_srv health_srv; -static struct bt_mesh_model_pub health_pub = { - .msg = NET_BUF_SIMPLE(BT_MESH_TX_SDU_MAX), -}; - -#if defined(CONFIG_BT_MESH_SAR_CFG) -static struct bt_mesh_sar_cfg_cli sar_cfg_cli; -#endif - -static struct bt_mesh_model models[] = { - BT_MESH_MODEL_CFG_SRV, - BT_MESH_MODEL_CFG_CLI(&cfg_cli), - BT_MESH_MODEL_CB(TEST_MOD_ID, model_op, &pub, NULL, &test_model_cb), - BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub), -#if defined(CONFIG_BT_MESH_SAR_CFG) - BT_MESH_MODEL_SAR_CFG_SRV, - BT_MESH_MODEL_SAR_CFG_CLI(&sar_cfg_cli), -#endif -}; - -struct bt_mesh_model *test_model = &models[2]; - -static struct bt_mesh_model vnd_models[] = { - BT_MESH_MODEL_VND_CB(TEST_VND_COMPANY_ID, TEST_VND_MOD_ID, vnd_model_op, &vnd_pub, - NULL, &test_vnd_model_cb), -}; - -struct bt_mesh_model *test_vnd_model = &vnd_models[0]; - -static struct bt_mesh_elem elems[] = { - BT_MESH_ELEM(0, models, vnd_models), -}; - -const struct bt_mesh_comp comp = { - .elem = elems, - .elem_count = ARRAY_SIZE(elems), -}; - -const uint8_t test_net_key[16] = { 1, 2, 3 }; -const uint8_t test_app_key[16] = { 4, 5, 6 }; -const uint8_t test_va_uuid[16] = "Mesh Label UUID"; - -static void bt_mesh_device_provision_and_configure(void) -{ - uint8_t status; - int err; - - err = bt_mesh_provision(test_net_key, 0, 0, 0, cfg->addr, cfg->dev_key); - if (err == -EALREADY) { - LOG_INF("Using stored settings"); - return; - } else if (err) { - FAIL("Provisioning failed (err %d)", err); - return; - } - - /* Self configure */ - - err = bt_mesh_cfg_cli_app_key_add(0, cfg->addr, 0, 0, test_app_key, &status); - if (err || status) { - FAIL("AppKey add failed (err %d, status %u)", err, status); - return; - } - - err = bt_mesh_cfg_cli_mod_app_bind(0, cfg->addr, cfg->addr, 0, TEST_MOD_ID, &status); - if (err || status) { - FAIL("Mod app bind failed (err %d, status %u)", err, status); - return; - } - - err = bt_mesh_cfg_cli_net_transmit_set(0, cfg->addr, BT_MESH_TRANSMIT(2, 20), &status); - if (err || status != BT_MESH_TRANSMIT(2, 20)) { - FAIL("Net transmit set failed (err %d, status %u)", err, - status); - return; - } -} - -void bt_mesh_device_setup(const struct bt_mesh_prov *prov, const struct bt_mesh_comp *comp) -{ - int err; - - err = bt_enable(NULL); - if (err) { - FAIL("Bluetooth init failed (err %d)", err); - return; - } - - LOG_INF("Bluetooth initialized"); - - err = bt_mesh_init(prov, comp); - if (err) { - FAIL("Initializing mesh failed (err %d)", err); - return; - } - - if (IS_ENABLED(CONFIG_BT_SETTINGS)) { - LOG_INF("Loading stored settings"); - settings_load(); - } - - LOG_INF("Mesh initialized"); -} - -void bt_mesh_test_setup(void) -{ - static struct bt_mesh_prov prov; - - net_buf_simple_init(pub.msg, 0); - net_buf_simple_init(vnd_pub.msg, 0); - - bt_mesh_device_setup(&prov, &comp); - bt_mesh_device_provision_and_configure(); -} - -void bt_mesh_test_timeout(bs_time_t HW_device_time) -{ - if (bst_result != Passed) { - FAIL("Test timeout (not passed after %i seconds)", - HW_device_time / USEC_PER_SEC); - } - - bs_trace_silent_exit(0); -} - -void bt_mesh_test_cfg_set(const struct bt_mesh_test_cfg *my_cfg, int wait_time) -{ - bst_ticker_set_next_tick_absolute(wait_time * USEC_PER_SEC); - bst_result = In_progress; - cfg = my_cfg; - - /* Ensure those test devices will not drift more than - * 100ms for each other in emulated time - */ - tm_set_phy_max_resync_offset(100000); -} - -static struct bt_mesh_test_msg *blocking_recv(k_timeout_t timeout) -{ - if (K_TIMEOUT_EQ(timeout, K_NO_WAIT)) { - return 0; - } - - return k_queue_get(&recv, timeout); -} - -int bt_mesh_test_recv(uint16_t len, uint16_t dst, k_timeout_t timeout) -{ - struct bt_mesh_test_msg *msg = blocking_recv(timeout); - - if (!msg) { - return -ETIMEDOUT; - } - - if (len != msg->len) { - LOG_ERR("Recv: Invalid message length (%u, expected %u)", msg->len, len); - return -EINVAL; - } - - if (dst != BT_MESH_ADDR_UNASSIGNED && dst != msg->ctx.recv_dst) { - LOG_ERR("Recv: Invalid dst 0x%04x, expected 0x%04x", msg->ctx.recv_dst, dst); - return -EINVAL; - } - - k_mem_slab_free(&msg_pool, (void **)&msg); - - return 0; -} - -int bt_mesh_test_recv_msg(struct bt_mesh_test_msg *msg, k_timeout_t timeout) -{ - struct bt_mesh_test_msg *queued = blocking_recv(timeout); - - if (!queued) { - return -ETIMEDOUT; - } - - *msg = *queued; - - k_mem_slab_free(&msg_pool, (void **)&queued); - - return 0; -} - -int bt_mesh_test_recv_clear(void) -{ - struct bt_mesh_test_msg *queued; - int count = 0; - - while ((queued = k_queue_get(&recv, K_NO_WAIT))) { - k_mem_slab_free(&msg_pool, (void **)&queued); - count++; - } - - return count; -} - -struct sync_send_ctx { - struct k_sem sem; - int err; -}; - -static void tx_started(uint16_t dur, int err, void *data) -{ - struct sync_send_ctx *send_ctx = data; - - if (err) { - LOG_ERR("Couldn't start sending (err: %d)", err); - - send_ctx->err = err; - k_sem_give(&send_ctx->sem); - - return; - } - - LOG_INF("Sending started"); -} - -static void tx_ended(int err, void *data) -{ - struct sync_send_ctx *send_ctx = data; - - send_ctx->err = err; - - if (err) { - LOG_ERR("Send failed (%d)", err); - } else { - LOG_INF("Sending ended"); - } - - k_sem_give(&send_ctx->sem); -} - -int bt_mesh_test_send_async(uint16_t addr, size_t len, - enum bt_mesh_test_send_flags flags, - const struct bt_mesh_send_cb *send_cb, - void *cb_data) -{ - const size_t mic_len = - (flags & LONG_MIC) ? BT_MESH_MIC_LONG : BT_MESH_MIC_SHORT; - static uint8_t count = 1; - int err; - - test_send_ctx.addr = addr; - test_send_ctx.send_rel = (flags & FORCE_SEGMENTATION); - test_send_ctx.send_ttl = BT_MESH_TTL_DEFAULT; - - BT_MESH_MODEL_BUF_DEFINE(buf, TEST_MSG_OP_1, BT_MESH_TX_SDU_MAX); - bt_mesh_model_msg_init(&buf, TEST_MSG_OP_1); - - if (len > BT_MESH_MODEL_OP_LEN(TEST_MSG_OP_1)) { - net_buf_simple_add_u8(&buf, count); - } - - /* Subtract the length of the opcode and the sequence ID */ - for (int i = 1; i < len - BT_MESH_MODEL_OP_LEN(TEST_MSG_OP_1); i++) { - net_buf_simple_add_u8(&buf, i); - } - - if (net_buf_simple_tailroom(&buf) < mic_len) { - LOG_ERR("No room for MIC of len %u in %u byte buffer", mic_len, - buf.len); - return -EINVAL; - } - - /* Seal the buffer to prevent accidentally long MICs: */ - buf.size = buf.len + mic_len; - - LOG_INF("Sending packet 0x%02x: %u %s to 0x%04x force seg: %u...", - count, buf.len, (buf.len == 1 ? "byte" : "bytes"), addr, - (flags & FORCE_SEGMENTATION)); - - err = bt_mesh_model_send(test_model, &test_send_ctx, &buf, send_cb, - cb_data); - if (err) { - LOG_ERR("bt_mesh_model_send failed (err: %d)", err); - return err; - } - - count++; - test_stats.sent++; - return 0; -} - -int bt_mesh_test_send(uint16_t addr, size_t len, - enum bt_mesh_test_send_flags flags, k_timeout_t timeout) -{ - if (K_TIMEOUT_EQ(timeout, K_NO_WAIT)) { - return bt_mesh_test_send_async(addr, len, flags, NULL, NULL); - } - - static const struct bt_mesh_send_cb send_cb = { - .start = tx_started, - .end = tx_ended, - }; - int64_t uptime = k_uptime_get(); - struct sync_send_ctx send_ctx; - int err; - - k_sem_init(&send_ctx.sem, 0, 1); - err = bt_mesh_test_send_async(addr, len, flags, &send_cb, &send_ctx); - if (err) { - return err; - } - - err = k_sem_take(&send_ctx.sem, timeout); - if (err) { - LOG_ERR("Send timed out"); - return err; - } - - if (send_ctx.err) { - return send_ctx.err; - } - - LOG_INF("Sending completed (%lld ms)", k_uptime_delta(&uptime)); - - return 0; -} - -int bt_mesh_test_send_ra(uint16_t addr, uint8_t *data, size_t len, - const struct bt_mesh_send_cb *send_cb, - void *cb_data) -{ - int err; - - test_send_ctx.addr = addr; - test_send_ctx.send_rel = 0; - test_send_ctx.send_ttl = BT_MESH_TTL_DEFAULT; - - BT_MESH_MODEL_BUF_DEFINE(buf, TEST_MSG_OP_2, BT_MESH_TX_SDU_MAX); - bt_mesh_model_msg_init(&buf, TEST_MSG_OP_2); - - net_buf_simple_add_mem(&buf, data, len); - - err = bt_mesh_model_send(test_model, &test_send_ctx, &buf, send_cb, cb_data); - if (err) { - LOG_ERR("bt_mesh_model_send failed (err: %d)", err); - return err; - } - - return 0; -} - -void bt_mesh_test_ra_cb_setup(void (*cb)(uint8_t *, size_t)) -{ - ra_cb = cb; -} - -uint16_t bt_mesh_test_own_addr_get(uint16_t start_addr) -{ - return start_addr + get_device_nbr(); -} - -#if defined(CONFIG_BT_MESH_SAR_CFG) -void bt_mesh_test_sar_conf_set(struct bt_mesh_sar_tx *tx_set, struct bt_mesh_sar_rx *rx_set) -{ - int err; - - if (tx_set) { - struct bt_mesh_sar_tx tx_rsp; - - err = bt_mesh_sar_cfg_cli_transmitter_set(0, cfg->addr, tx_set, &tx_rsp); - if (err) { - FAIL("Failed to configure SAR Transmitter state (err %d)", err); - } - } - - if (rx_set) { - struct bt_mesh_sar_rx rx_rsp; - - err = bt_mesh_sar_cfg_cli_receiver_set(0, cfg->addr, rx_set, &rx_rsp); - if (err) { - FAIL("Failed to configure SAR Receiver state (err %d)", err); - } - } -} -#endif /* defined(CONFIG_BT_MESH_SAR_CFG) */ diff --git a/tests/bluetooth/bsim/mesh/src/mesh_test.h b/tests/bluetooth/bsim/mesh/src/mesh_test.h deleted file mode 100644 index a4db379a175..00000000000 --- a/tests/bluetooth/bsim/mesh/src/mesh_test.h +++ /dev/null @@ -1,165 +0,0 @@ -/** @file - * @brief Common functionality for Bluetooth mesh BabbleSim tests. - */ - -/* - * Copyright (c) 2021 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ -#ifndef ZEPHYR_TESTS_BLUETOOTH_BSIM_BT_BSIM_TEST_MESH_MESH_TEST_H_ -#define ZEPHYR_TESTS_BLUETOOTH_BSIM_BT_BSIM_TEST_MESH_MESH_TEST_H_ -#include - -#include "bs_types.h" -#include "bs_tracing.h" -#include "time_machine.h" -#include "bstests.h" - -#include -#include -#include -#include - -#include -#include - -#define TEST_MOD_ID 0x8888 -#define TEST_MSG_OP_1 BT_MESH_MODEL_OP_1(0x0f) -#define TEST_MSG_OP_2 BT_MESH_MODEL_OP_1(0x10) - -#define TEST_VND_COMPANY_ID 0x1234 -#define TEST_VND_MOD_ID 0x5678 - -#define MODEL_LIST(...) ((struct bt_mesh_model[]){ __VA_ARGS__ }) - -#define FAIL(msg, ...) \ - do { \ - bst_result = Failed; \ - bs_trace_error_time_line(msg "\n", ##__VA_ARGS__); \ - } while (0) - -#define PASS() \ - do { \ - bst_result = Passed; \ - bs_trace_info_time(1, "%s PASSED\n", __func__); \ - } while (0) - -#define ASSERT_OK(cond) \ - do { \ - int _err = (cond); \ - if (_err) { \ - bst_result = Failed; \ - bs_trace_error_time_line( \ - #cond " failed with error %d\n", _err); \ - } \ - } while (0) - -#define ASSERT_OK_MSG(cond, fmt, ...) \ - do { \ - int _err = (cond); \ - if (_err) { \ - bst_result = Failed; \ - bs_trace_error_time_line( \ - #cond " failed with error %d\n" fmt, _err, \ - ##__VA_ARGS__); \ - } \ - } while (0) - -#define ASSERT_TRUE(cond, ...) \ - do { \ - if (!(cond)) { \ - bst_result = Failed; \ - bs_trace_error_time_line( \ - #cond " is false.", ##__VA_ARGS__); \ - } \ - } while (0) - -#define ASSERT_FALSE(cond, ...) \ - do { \ - if (cond) { \ - bst_result = Failed; \ - bs_trace_error_time_line( \ - #cond " is true.", ##__VA_ARGS__); \ - } \ - } while (0) - -#define ASSERT_EQUAL(expected, got) \ - do { \ - if ((expected) != (got)) { \ - bst_result = Failed; \ - bs_trace_error_time_line( \ - #expected " not equal to " #got ": %d != %d\n",\ - (expected), (got)); \ - } \ - } while (0) - - -struct bt_mesh_test_cfg { - uint16_t addr; - uint8_t dev_key[16]; -}; - -enum bt_mesh_test_send_flags { - FORCE_SEGMENTATION = BIT(0), - LONG_MIC = BIT(1), -}; - -struct bt_mesh_test_stats { - uint32_t received; - uint32_t sent; - uint32_t recv_overflow; -}; - -struct bt_mesh_test_msg { - sys_snode_t _node; - size_t len; - uint8_t seq; - struct bt_mesh_msg_ctx ctx; -}; - -struct bt_mesh_test_sync_ctx { - uint32_t *dev_nmbr; - uint32_t *chan_nmbr; - uint32_t *chan_id; - uint16_t cnt; -}; - -extern enum bst_result_t bst_result; -extern const struct bt_mesh_test_cfg *cfg; -extern struct bt_mesh_model *test_model; -extern struct bt_mesh_model *test_vnd_model; -extern const uint8_t test_net_key[16]; -extern const uint8_t test_app_key[16]; -extern const uint8_t test_va_uuid[16]; -extern struct bt_mesh_test_stats test_stats; -extern struct bt_mesh_msg_ctx test_send_ctx; - -void bt_mesh_test_cfg_set(const struct bt_mesh_test_cfg *cfg, int wait_time); -void bt_mesh_test_setup(void); -void bt_mesh_test_timeout(bs_time_t HW_device_time); - -void bt_mesh_device_setup(const struct bt_mesh_prov *prov, const struct bt_mesh_comp *comp); - -int bt_mesh_test_recv(uint16_t len, uint16_t dst, k_timeout_t timeout); -int bt_mesh_test_recv_msg(struct bt_mesh_test_msg *msg, k_timeout_t timeout); -int bt_mesh_test_recv_clear(void); - -int bt_mesh_test_send(uint16_t addr, size_t len, - enum bt_mesh_test_send_flags flags, k_timeout_t timeout); -int bt_mesh_test_send_async(uint16_t addr, size_t len, - enum bt_mesh_test_send_flags flags, - const struct bt_mesh_send_cb *send_cb, - void *cb_data); -int bt_mesh_test_send_ra(uint16_t addr, uint8_t *data, size_t len, - const struct bt_mesh_send_cb *send_cb, - void *cb_data); -void bt_mesh_test_ra_cb_setup(void (*cb)(uint8_t *, size_t)); - -uint16_t bt_mesh_test_own_addr_get(uint16_t start_addr); - -#if defined(CONFIG_BT_MESH_SAR_CFG) -void bt_mesh_test_sar_conf_set(struct bt_mesh_sar_tx *tx_set, struct bt_mesh_sar_rx *rx_set); -#endif - -#endif /* ZEPHYR_TESTS_BLUETOOTH_BSIM_BT_BSIM_TEST_MESH_MESH_TEST_H_ */ diff --git a/tests/bluetooth/bsim/mesh/src/settings_test_backend.c b/tests/bluetooth/bsim/mesh/src/settings_test_backend.c deleted file mode 100644 index 1b1e7739876..00000000000 --- a/tests/bluetooth/bsim/mesh/src/settings_test_backend.c +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright (c) 2021 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "settings_test_backend.h" - -#include -#include - -#include -#include "zephyr/types.h" -#include "errno.h" - -#include -#include "argparse.h" - -#define LOG_MODULE_NAME settings_test_backend -#include -LOG_MODULE_REGISTER(LOG_MODULE_NAME); - -#define SETTINGS_FILE setting_file -#define SETTINGS_FILE_TMP setting_file_tmp - -#define ENTRY_LEN_SIZE (4) -#define ENTRY_NAME_MAX_LEN (SETTINGS_MAX_NAME_LEN + SETTINGS_EXTRA_LEN) -#define ENTRY_VAL_MAX_LEN (SETTINGS_MAX_VAL_LEN * 2) -#define READ_LEN_MAX (ENTRY_VAL_MAX_LEN + ENTRY_NAME_MAX_LEN + 2) - -struct line_read_ctx { - int len; - const uint8_t *val; -}; - -static char setting_file[50]; -static char setting_file_tmp[sizeof(setting_file) + 1]; - -static int entry_check_and_copy(FILE *fin, FILE *fout, const char *name) -{ - char line[READ_LEN_MAX + 1]; - char name_tmp[strlen(name) + 2]; - - snprintk(name_tmp, sizeof(name_tmp), "%s=", name); - - while (fgets(line, sizeof(line), fin) == line) { - if (strstr(line, name_tmp) != NULL) { - return 0; - } - - if (fputs(line, fout) < 0) { - return -1; - } - }; - - return 0; -} - -static ssize_t settings_line_read_cb(void *cb_arg, void *data, size_t len) -{ - struct line_read_ctx *valctx = (struct line_read_ctx *)cb_arg; - - if ((valctx->len / 2) > len) { - return -ENOBUFS; - } - - uint8_t *n = (uint8_t *) data; - len = valctx->len / 2; - - for (int i = 0; i < len; i++, n++) { - if (sscanf(&valctx->val[i * 2], "%2hhx", n) != 1) { - return 0; - }; - } - - return len; -} - -static int settings_custom_load(struct settings_store *cs, const struct settings_load_arg *arg) -{ - FILE *fp = fopen(SETTINGS_FILE, "r+"); - - if (fp == NULL) { - LOG_WRN("Settings file is missing"); - return -1; - } - - if (fseek(fp, 0, SEEK_SET) < 0) { - return -1; - } - - int vallen; - char line[READ_LEN_MAX + 1]; - - while (fgets(line, sizeof(line), fp) == line) { - /* check for matching subtree */ - if (arg->subtree != NULL && !strstr(line, arg->subtree)) { - continue; - } - - char *pos = strchr(line, '='); - - if (pos <= line) { - return -1; - } - - vallen = strlen(line) - (pos - line) - 2; - LOG_INF("loading entry: %s", line); - - struct line_read_ctx valctx; - - valctx.len = vallen; - valctx.val = pos + 1; - int err = settings_call_set_handler(line, vallen / 2, settings_line_read_cb, - &valctx, arg); - - if (err < 0) { - return err; - } - }; - - return fclose(fp); -} - -/* Entries are saved to optimize readability of the settings file for test development and - * debugging purposes. Format: - * =\n - */ -static int settings_custom_save(struct settings_store *cs, const char *name, - const char *value, size_t val_len) -{ - FILE *fcur = fopen(SETTINGS_FILE, "r+"); - FILE *fnew = NULL; - - if (fcur == NULL) { - fcur = fopen(SETTINGS_FILE, "w"); - } else { - fnew = fopen(SETTINGS_FILE_TMP, "w"); - if (fnew == NULL) { - LOG_ERR("Failed to create temporary file %s", SETTINGS_FILE_TMP); - return -1; - } - } - - if (fcur == NULL) { - LOG_ERR("Failed to create settings file: %s", SETTINGS_FILE); - return -1; - } - - if (strlen(name) > ENTRY_NAME_MAX_LEN || val_len > SETTINGS_MAX_VAL_LEN) { - return -1; - } - - if (fnew != NULL) { - if (entry_check_and_copy(fcur, fnew, name) < 0) { - return -1; - } - } - - if (val_len) { - char bufvname[ENTRY_NAME_MAX_LEN + ENTRY_LEN_SIZE + 3]; - - snprintk(bufvname, sizeof(bufvname), "%s=", name); - if (fputs(bufvname, fnew != NULL ? fnew : fcur) < 0) { - return -1; - } - - char bufval[ENTRY_VAL_MAX_LEN + 2] = {}; - size_t valcnt = 0; - - while (valcnt < (val_len * 2)) { - valcnt += snprintk(&bufval[valcnt], 3, "%02x", - (uint8_t)value[valcnt / 2]); - }; - - /* helps in making settings file readable */ - bufval[valcnt++] = '\n'; - bufval[valcnt] = 0; - - if (fputs(bufval, fnew != NULL ? fnew : fcur) < 0) { - return -1; - } - } - - if (fnew != NULL) { - entry_check_and_copy(fcur, fnew, name); - } - - fclose(fcur); - - if (fnew != NULL) { - fclose(fnew); - - remove(SETTINGS_FILE); - rename(SETTINGS_FILE_TMP, SETTINGS_FILE); - } - - return 0; -} - -/* custom backend interface */ -static struct settings_store_itf settings_custom_itf = { - .csi_load = settings_custom_load, - .csi_save = settings_custom_save, -}; - -/* custom backend node */ -static struct settings_store settings_custom_store = { - .cs_itf = &settings_custom_itf -}; - -int settings_backend_init(void) -{ - snprintf(setting_file, sizeof(setting_file), "%s_%d.log", get_simid(), get_device_nbr()); - snprintf(setting_file_tmp, sizeof(setting_file_tmp), "~%s", setting_file); - - LOG_INF("file path: %s", SETTINGS_FILE); - - /* register custom backend */ - settings_dst_register(&settings_custom_store); - settings_src_register(&settings_custom_store); - return 0; -} - -void settings_test_backend_clear(void) -{ - snprintf(setting_file, sizeof(setting_file), "%s_%d.log", get_simid(), get_device_nbr()); - - if (remove(setting_file)) { - LOG_INF("error deleting file: %s", setting_file); - } -} diff --git a/tests/bluetooth/bsim/mesh/src/settings_test_backend.h b/tests/bluetooth/bsim/mesh/src/settings_test_backend.h deleted file mode 100644 index 41537dbb91d..00000000000 --- a/tests/bluetooth/bsim/mesh/src/settings_test_backend.h +++ /dev/null @@ -1,17 +0,0 @@ -/** @file - * @brief Settings test backend headers - */ - -/* - * Copyright (c) 2021 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ -#ifndef ZEPHYR_TESTS_BLUETOOTH_BSIM_BT_BSIM_TEST_MESH_SETTINGS_TEST_BACKEND_H_ -#define ZEPHYR_TESTS_BLUETOOTH_BSIM_BT_BSIM_TEST_MESH_SETTINGS_TEST_BACKEND_H_ - -int settings_backend_init(void); - -void settings_test_backend_clear(void); - -#endif /* ZEPHYR_TESTS_BLUETOOTH_BSIM_BT_BSIM_TEST_MESH_SETTINGS_TEST_BACKEND_H_ */ diff --git a/tests/bluetooth/bsim/mesh/src/test_access.c b/tests/bluetooth/bsim/mesh/src/test_access.c deleted file mode 100644 index 56fce393388..00000000000 --- a/tests/bluetooth/bsim/mesh/src/test_access.c +++ /dev/null @@ -1,851 +0,0 @@ -/* - * Copyright (c) 2021 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include "mesh_test.h" -#include "mesh/net.h" -#include "mesh/access.h" -#include "mesh/foundation.h" - -#define LOG_MODULE_NAME test_access - -#include -LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL_INF); - -#define GROUP_ADDR 0xc000 -#define UNICAST_ADDR1 0x0001 -#define UNICAST_ADDR2 0x0006 -#define WAIT_TIME 10 /*seconds*/ - -#define TEST_MODEL_ID_1 0x2a2a -#define TEST_MODEL_ID_2 0x2b2b -#define TEST_MODEL_ID_3 0x2c2c -#define TEST_MODEL_ID_4 0x2d2d -#define TEST_MODEL_ID_5 0x2e2e - -#define TEST_MESSAGE_OP_1 BT_MESH_MODEL_OP_1(0x11) -#define TEST_MESSAGE_OP_2 BT_MESH_MODEL_OP_1(0x12) -#define TEST_MESSAGE_OP_3 BT_MESH_MODEL_OP_1(0x13) -#define TEST_MESSAGE_OP_4 BT_MESH_MODEL_OP_1(0x14) -#define TEST_MESSAGE_OP_5 BT_MESH_MODEL_OP_1(0x15) -#define TEST_MESSAGE_OP_F BT_MESH_MODEL_OP_1(0x1F) - -#define PUB_PERIOD_COUNT 3 -#define RX_JITTER_MAX (10 + CONFIG_BT_MESH_NETWORK_TRANSMIT_COUNT * \ - (CONFIG_BT_MESH_NETWORK_TRANSMIT_INTERVAL + 10)) - -static int model1_init(struct bt_mesh_model *model); -static int model2_init(struct bt_mesh_model *model); -static int model3_init(struct bt_mesh_model *model); -static int model4_init(struct bt_mesh_model *model); -static int model5_init(struct bt_mesh_model *model); -static int test_msg_handler(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf); -static int test_msg_ne_handler(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf); - -struct k_poll_signal model_pub_signal; - -static uint8_t dev_key[16] = { 0xdd }; -static uint8_t app_key[16] = { 0xaa }; -static uint8_t net_key[16] = { 0xcc }; -static struct bt_mesh_prov prov; - -/* Test vector for periodic publication tests. */ -static const struct { - uint8_t period; - uint8_t div; - int32_t period_ms; -} test_period[] = { - { BT_MESH_PUB_PERIOD_100MS(5), 0, 500 }, - { BT_MESH_PUB_PERIOD_SEC(2), 0, 2000 }, - { BT_MESH_PUB_PERIOD_10SEC(1), 0, 10000 }, - { BT_MESH_PUB_PERIOD_SEC(3), 1, 1500 }, - { BT_MESH_PUB_PERIOD_10SEC(3), 3, 3750 }, -}; - -/* Test vector for publication retransmissions tests. */ -static const uint8_t test_transmit[] = { - BT_MESH_PUB_TRANSMIT(4, 50), - BT_MESH_PUB_TRANSMIT(3, 100), - BT_MESH_PUB_TRANSMIT(2, 200), -}; - -/* Test vector for canceling a message publication. */ -static const struct { - uint8_t period; - uint8_t transmit; - uint8_t msgs; - int32_t sleep; - int32_t duration; -} test_cancel[] = { - /* Test canceling periodic publication. */ - { - BT_MESH_PUB_PERIOD_SEC(2), 0, 2, - 2000 /* period */ + 100 /* margin */, - 3 /* messages */ * 2000 /* period */ - }, - /* Test canceling publication retransmission. */ - { - BT_MESH_PUB_PERIOD_SEC(3), BT_MESH_PUB_TRANSMIT(3, 200), 3, - 200 /* retransmission interval */ + 50 /* margin */, - 3000 /* one period */ - }, -}; - -static struct k_sem publish_sem; -static bool publish_allow; - -static int model1_update(struct bt_mesh_model *model) -{ - model->pub->msg->data[1]++; - - LOG_DBG("New pub: n: %d t: %d", model->pub->msg->data[1], k_uptime_get_32()); - - return publish_allow ? k_sem_give(&publish_sem), 0 : -1; -} - -static int test_msgf_handler(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) -{ - static uint8_t prev_num; - uint8_t num = net_buf_simple_pull_u8(buf); - - LOG_DBG("Recv msg: n: %d t: %u", num, k_uptime_get_32()); - - /* Ensure that payload changes. */ - ASSERT_TRUE(prev_num != num); - prev_num = num; - - k_sem_give(&publish_sem); - return 0; -} - -static struct bt_mesh_model_pub model_pub1 = { - .msg = NET_BUF_SIMPLE(BT_MESH_TX_SDU_MAX), - .update = model1_update, -}; - -static const struct bt_mesh_model_cb test_model1_cb = { - .init = model1_init, -}; - -static const struct bt_mesh_model_cb test_model2_cb = { - .init = model2_init, -}; - -static const struct bt_mesh_model_cb test_model3_cb = { - .init = model3_init, -}; - -static const struct bt_mesh_model_cb test_model4_cb = { - .init = model4_init, -}; - -static const struct bt_mesh_model_cb test_model5_cb = { - .init = model5_init, -}; - -static const struct bt_mesh_model_op model_op1[] = { - { TEST_MESSAGE_OP_1, 0, test_msg_handler }, - { TEST_MESSAGE_OP_F, 0, test_msgf_handler }, - BT_MESH_MODEL_OP_END -}; - -static const struct bt_mesh_model_op model_op2[] = { - { TEST_MESSAGE_OP_2, 0, test_msg_handler }, - BT_MESH_MODEL_OP_END -}; - -static const struct bt_mesh_model_op model_op3[] = { - { TEST_MESSAGE_OP_3, 0, test_msg_handler }, - BT_MESH_MODEL_OP_END -}; - -static const struct bt_mesh_model_op model_op4[] = { - { TEST_MESSAGE_OP_4, 0, test_msg_handler }, - BT_MESH_MODEL_OP_END -}; - -static const struct bt_mesh_model_op model_op5[] = { - { TEST_MESSAGE_OP_5, 0, test_msg_handler }, - BT_MESH_MODEL_OP_END -}; - -static const struct bt_mesh_model_op model_ne_op1[] = { - { TEST_MESSAGE_OP_1, 0, test_msg_ne_handler }, - BT_MESH_MODEL_OP_END -}; - -static const struct bt_mesh_model_op model_ne_op2[] = { - { TEST_MESSAGE_OP_2, 0, test_msg_ne_handler }, - BT_MESH_MODEL_OP_END -}; - -static const struct bt_mesh_model_op model_ne_op3[] = { - { TEST_MESSAGE_OP_3, 0, test_msg_ne_handler }, - BT_MESH_MODEL_OP_END -}; - -static const struct bt_mesh_model_op model_ne_op4[] = { - { TEST_MESSAGE_OP_4, 0, test_msg_ne_handler }, - BT_MESH_MODEL_OP_END -}; - -static const struct bt_mesh_model_op model_ne_op5[] = { - { TEST_MESSAGE_OP_5, 0, test_msg_ne_handler }, - BT_MESH_MODEL_OP_END -}; - -static struct bt_mesh_cfg_cli cfg_cli; - -/* do not change model sequence. it will break pointer arithmetic. */ -static struct bt_mesh_model models[] = { - BT_MESH_MODEL_CFG_SRV, - BT_MESH_MODEL_CFG_CLI(&cfg_cli), - BT_MESH_MODEL_CB(TEST_MODEL_ID_1, model_op1, &model_pub1, NULL, &test_model1_cb), - BT_MESH_MODEL_CB(TEST_MODEL_ID_2, model_op2, NULL, NULL, &test_model2_cb), - BT_MESH_MODEL_CB(TEST_MODEL_ID_3, model_op3, NULL, NULL, &test_model3_cb), - BT_MESH_MODEL_CB(TEST_MODEL_ID_4, model_op4, NULL, NULL, &test_model4_cb), - BT_MESH_MODEL_CB(TEST_MODEL_ID_5, model_op5, NULL, NULL, &test_model5_cb), -}; - -/* do not change model sequence. it will break pointer arithmetic. */ -static struct bt_mesh_model models_ne[] = { - BT_MESH_MODEL_CB(TEST_MODEL_ID_1, model_ne_op1, NULL, NULL, &test_model1_cb), - BT_MESH_MODEL_CB(TEST_MODEL_ID_2, model_ne_op2, NULL, NULL, &test_model2_cb), - BT_MESH_MODEL_CB(TEST_MODEL_ID_3, model_ne_op3, NULL, NULL, &test_model3_cb), - BT_MESH_MODEL_CB(TEST_MODEL_ID_4, model_ne_op4, NULL, NULL, &test_model4_cb), - BT_MESH_MODEL_CB(TEST_MODEL_ID_5, model_ne_op5, NULL, NULL, &test_model5_cb), -}; - -static struct bt_mesh_model vnd_models[] = {}; - -static struct bt_mesh_elem elems[] = { - BT_MESH_ELEM(0, models, vnd_models), - BT_MESH_ELEM(1, models_ne, vnd_models), -}; - -const struct bt_mesh_comp local_comp = { - .elem = elems, - .elem_count = ARRAY_SIZE(elems), -}; -/* extension dependency (basic models are on top) - * - * element idx0 element idx1 - * - * m1 m2 mne2 mne1 - * / \ / | / \ - * / \ / | / \ - * m5 m3------->mne3 mne5 - * | | - * m4 mne4 - */ - -static int model1_init(struct bt_mesh_model *model) -{ - return 0; -} - -static int model2_init(struct bt_mesh_model *model) -{ - return 0; -} - -static int model3_init(struct bt_mesh_model *model) -{ - ASSERT_OK(bt_mesh_model_extend(model, model - 2)); - ASSERT_OK(bt_mesh_model_extend(model, model - 1)); - - if (model->elem_idx == 0) { - ASSERT_OK(bt_mesh_model_extend(&models_ne[2], model)); - } - - return 0; -} - -static int model4_init(struct bt_mesh_model *model) -{ - ASSERT_OK(bt_mesh_model_extend(model, model - 1)); - - return 0; -} - -static int model5_init(struct bt_mesh_model *model) -{ - ASSERT_OK(bt_mesh_model_extend(model, model - 4)); - - return 0; -} - -static int test_msg_handler(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) -{ - LOG_DBG("msg rx model id: %u", model->id); - k_poll_signal_raise(&model_pub_signal, model->id); - - return 0; -} - -static int test_msg_ne_handler(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) -{ - FAIL("Model %#4x on neighbor element received msg", model->id); - - return 0; -} - -static void provision(uint16_t addr) -{ - int err; - - err = bt_mesh_provision(net_key, 0, 0, 0, addr, dev_key); - if (err) { - FAIL("Provisioning failed (err %d)", err); - return; - } -} - -static void common_configure(uint16_t addr) -{ - uint8_t status; - int err; - uint16_t model_ids[] = {TEST_MODEL_ID_1, TEST_MODEL_ID_2, - TEST_MODEL_ID_3, TEST_MODEL_ID_4, TEST_MODEL_ID_5}; - - err = bt_mesh_cfg_cli_app_key_add(0, addr, 0, 0, app_key, &status); - if (err || status) { - 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) { - FAIL("Model %#4x bind failed (err %d, status %u)", - model_ids[i], err, status); - return; - } - - err = bt_mesh_cfg_cli_mod_app_bind(0, addr, addr + 1, 0, model_ids[i], &status); - if (err || status) { - FAIL("Model %#4x bind failed (err %d, status %u)", - model_ids[i], err, status); - return; - } - } - - err = bt_mesh_cfg_cli_net_transmit_set(0, addr, BT_MESH_TRANSMIT(2, 20), &status); - if (err || status != BT_MESH_TRANSMIT(2, 20)) { - FAIL("Net transmit set failed (err %d, status %u)", err, - status); - return; - } -} - -static void subscription_configure(uint16_t addr) -{ - uint8_t status; - int err; - - err = bt_mesh_cfg_cli_mod_sub_add(0, addr, addr, GROUP_ADDR, TEST_MODEL_ID_2, &status); - - if (err || status) { - FAIL("Model %#4x subscription configuration failed (err %d, status %u)", - TEST_MODEL_ID_2, err, status); - return; - } -} - -static void test_tx_ext_model(void) -{ - bt_mesh_test_cfg_set(NULL, WAIT_TIME); - bt_mesh_device_setup(&prov, &local_comp); - provision(UNICAST_ADDR1); - common_configure(UNICAST_ADDR1); - - struct bt_mesh_msg_ctx ctx = { - .net_idx = 0, - .app_idx = 0, - .addr = GROUP_ADDR, - .send_rel = false, - .send_ttl = BT_MESH_TTL_DEFAULT, - }; - BT_MESH_MODEL_BUF_DEFINE(msg, TEST_MESSAGE_OP_1, 0); - - bt_mesh_model_msg_init(&msg, TEST_MESSAGE_OP_1); - bt_mesh_model_send(&models[2], &ctx, &msg, NULL, NULL); - - bt_mesh_model_msg_init(&msg, TEST_MESSAGE_OP_2); - bt_mesh_model_send(&models[3], &ctx, &msg, NULL, NULL); - - bt_mesh_model_msg_init(&msg, TEST_MESSAGE_OP_3); - bt_mesh_model_send(&models[4], &ctx, &msg, NULL, NULL); - - bt_mesh_model_msg_init(&msg, TEST_MESSAGE_OP_4); - bt_mesh_model_send(&models[5], &ctx, &msg, NULL, NULL); - - bt_mesh_model_msg_init(&msg, TEST_MESSAGE_OP_5); - bt_mesh_model_send(&models[6], &ctx, &msg, NULL, NULL); - - PASS(); -} - -static void test_sub_ext_model(void) -{ - k_poll_signal_init(&model_pub_signal); - - struct k_poll_event events[1] = { - K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL, - K_POLL_MODE_NOTIFY_ONLY, &model_pub_signal) - }; - - bt_mesh_test_cfg_set(NULL, WAIT_TIME); - bt_mesh_device_setup(&prov, &local_comp); - provision(UNICAST_ADDR2); - common_configure(UNICAST_ADDR2); - subscription_configure(UNICAST_ADDR2); - - bool m1_fired = false; - bool m2_fired = false; - bool m3_fired = false; - bool m4_fired = false; - bool m5_fired = false; - - while (!m1_fired || !m2_fired || !m3_fired || !m4_fired || !m5_fired) { - ASSERT_OK(k_poll(events, 1, K_SECONDS(3))); - - switch (model_pub_signal.result) { - case TEST_MODEL_ID_1: - ASSERT_FALSE(m1_fired); - m1_fired = true; - break; - case TEST_MODEL_ID_2: - ASSERT_FALSE(m2_fired); - m2_fired = true; - break; - case TEST_MODEL_ID_3: - ASSERT_FALSE(m3_fired); - m3_fired = true; - break; - case TEST_MODEL_ID_4: - ASSERT_FALSE(m4_fired); - m4_fired = true; - break; - case TEST_MODEL_ID_5: - ASSERT_FALSE(m5_fired); - m5_fired = true; - break; - default: - FAIL(); - break; - } - - events[0].signal->signaled = 0; - events[0].state = K_POLL_STATE_NOT_READY; - } - - - PASS(); -} - -static void test_sub_capacity_ext_model(void) -{ - bt_mesh_test_cfg_set(NULL, WAIT_TIME); - bt_mesh_device_setup(&prov, &local_comp); - provision(UNICAST_ADDR2); - common_configure(UNICAST_ADDR2); - - uint8_t status; - int i; - - /* Models in the extension linked list use the subscription list capacity of - * each other to the full extent. If a model cannot put a subscription address in - * its own subscription list it looks for the closest empty cell in model - * in the extension linked list. - */ - for (i = 0; i < 5 * CONFIG_BT_MESH_MODEL_GROUP_COUNT; i++) { - ASSERT_OK_MSG(bt_mesh_cfg_cli_mod_sub_add(0, UNICAST_ADDR2, UNICAST_ADDR2, - GROUP_ADDR + i, TEST_MODEL_ID_2, &status), - "Can't deliver subscription on address %#4x", GROUP_ADDR + i); - - ASSERT_EQUAL(STATUS_SUCCESS, status); - } - - uint16_t model_ids[] = {TEST_MODEL_ID_1, TEST_MODEL_ID_2, - TEST_MODEL_ID_3, TEST_MODEL_ID_4, TEST_MODEL_ID_5}; - - for (int j = 0; j < ARRAY_SIZE(model_ids); j++) { - ASSERT_OK_MSG(bt_mesh_cfg_cli_mod_sub_add(0, UNICAST_ADDR2, UNICAST_ADDR2, - GROUP_ADDR + i, model_ids[j], &status), - "Can't deliver subscription on address %#4x", GROUP_ADDR + i); - - ASSERT_EQUAL(STATUS_INSUFF_RESOURCES, status); - } - - PASS(); -} - -static void pub_param_set(uint8_t period, uint8_t transmit) -{ - struct bt_mesh_cfg_cli_mod_pub pub_params = { - .addr = UNICAST_ADDR2, - .uuid = NULL, - .cred_flag = false, - .app_idx = 0, - .ttl = 5, - .period = period, - .transmit = transmit, - }; - uint8_t status; - int err; - - err = bt_mesh_cfg_cli_mod_pub_set(0, UNICAST_ADDR1, UNICAST_ADDR1, TEST_MODEL_ID_1, - &pub_params, &status); - if (err || status) { - FAIL("Mod pub set failed (err %d, status %u)", err, status); - } -} - -static void msgf_publish(void) -{ - struct bt_mesh_model *model = &models[2]; - - bt_mesh_model_msg_init(model->pub->msg, TEST_MESSAGE_OP_F); - net_buf_simple_add_u8(model->pub->msg, 1); - bt_mesh_model_publish(model); -} - -static void pub_jitter_check(int32_t interval, uint8_t count) -{ - int64_t timestamp = k_uptime_get(); - int32_t jitter = 0; - int err; - - for (size_t j = 0; j < count; j++) { - /* Every new publication will release semaphore in the update handler and the time - * between two consecutive publications will be measured. - */ - err = k_sem_take(&publish_sem, K_SECONDS(20)); - if (err) { - FAIL("Send timed out"); - } - - int32_t time_delta = k_uptime_delta(×tamp); - int32_t pub_delta = llabs(time_delta - interval); - - jitter = MAX(pub_delta, jitter); - - LOG_DBG("Send time: %d delta: %d jitter: %d", (int32_t)timestamp, time_delta, - jitter); - } - - LOG_INF("Send jitter: %d", jitter); - ASSERT_TRUE(jitter <= 10); -} - -static void recv_jitter_check(int32_t interval, uint8_t count) -{ - int64_t timestamp; - uint32_t jitter = 0; - int err; - - /* The measurement starts by the first received message. */ - err = k_sem_take(&publish_sem, K_SECONDS(20)); - if (err) { - FAIL("Recv timed out"); - } - - timestamp = k_uptime_get(); - - for (size_t j = 0; j < count; j++) { - /* Every new received message will release semaphore in the message handler and - * the time between two consecutive publications will be measured. - */ - err = k_sem_take(&publish_sem, K_SECONDS(20)); - if (err) { - FAIL("Recv timed out"); - } - - int32_t time_delta = k_uptime_delta(×tamp); - int32_t pub_delta = llabs(time_delta - interval); - - jitter = MAX(pub_delta, jitter); - - LOG_DBG("Recv time: %d delta: %d jitter: %d", (int32_t)timestamp, time_delta, - jitter); - } - - LOG_INF("Recv jitter: %d", jitter); - ASSERT_TRUE(jitter <= RX_JITTER_MAX); -} - -/* Test publish period states by publishing a message and checking interval between update handler - * calls. - */ -static void test_tx_period(void) -{ - struct bt_mesh_model *model = &models[2]; - - bt_mesh_test_cfg_set(NULL, 60); - bt_mesh_device_setup(&prov, &local_comp); - provision(UNICAST_ADDR1); - common_configure(UNICAST_ADDR1); - - k_sem_init(&publish_sem, 0, 1); - - for (size_t i = 0; i < ARRAY_SIZE(test_period); i++) { - pub_param_set(test_period[i].period, 0); - - model->pub->fast_period = test_period[i].div > 0; - model->pub->period_div = test_period[i].div; - - LOG_INF("Publication period: %d", test_period[i].period_ms); - - /* Start publishing messages and measure jitter. */ - msgf_publish(); - publish_allow = true; - pub_jitter_check(test_period[i].period_ms, PUB_PERIOD_COUNT); - - /* Disable periodic publication before the next test iteration. */ - publish_allow = false; - - /* Let the receiver hit the first semaphore. */ - k_sleep(K_SECONDS(1)); - } - - PASS(); -} - -/* Receive a periodically published message and check publication period by measuring interval - * between message handler calls. - */ -static void test_rx_period(void) -{ - bt_mesh_test_cfg_set(NULL, 60); - bt_mesh_device_setup(&prov, &local_comp); - provision(UNICAST_ADDR2); - common_configure(UNICAST_ADDR2); - - k_sem_init(&publish_sem, 0, 1); - - for (size_t i = 0; i < ARRAY_SIZE(test_period); i++) { - recv_jitter_check(test_period[i].period_ms, PUB_PERIOD_COUNT); - } - - PASS(); -} - -/* Test publish retransmit interval and count states by publishing a message and checking interval - * between update handler calls. - */ -static void test_tx_transmit(void) -{ - struct bt_mesh_model *model = &models[2]; - uint8_t status; - int err; - - bt_mesh_test_cfg_set(NULL, 60); - bt_mesh_device_setup(&prov, &local_comp); - provision(UNICAST_ADDR1); - common_configure(UNICAST_ADDR1); - - k_sem_init(&publish_sem, 0, 1); - - /* Network retransmissions has to be disabled so that the legacy advertiser sleeps for the - * least possible time, which is 50ms. This will let the access layer publish a message - * with 50ms retransmission interval. - */ - err = bt_mesh_cfg_cli_net_transmit_set(0, UNICAST_ADDR1, - BT_MESH_TRANSMIT(0, CONFIG_BT_MESH_NETWORK_TRANSMIT_INTERVAL), - &status); - if (err || status != BT_MESH_TRANSMIT(0, CONFIG_BT_MESH_NETWORK_TRANSMIT_INTERVAL)) { - FAIL("Net transmit set failed (err %d, status %u)", err, - status); - } - - publish_allow = true; - model->pub->retr_update = true; - - for (size_t i = 0; i < ARRAY_SIZE(test_transmit); i++) { - pub_param_set(0, test_transmit[i]); - - int32_t interval = BT_MESH_PUB_TRANSMIT_INT(test_transmit[i]); - int count = BT_MESH_PUB_TRANSMIT_COUNT(test_transmit[i]); - - LOG_INF("Retransmission interval: %d, count: %d", interval, count); - - /* Start publishing messages and measure jitter. */ - msgf_publish(); - pub_jitter_check(interval, count); - - /* Let the receiver hit the first semaphore. */ - k_sleep(K_SECONDS(1)); - } - - PASS(); -} - -/* Receive a published message and check retransmission interval by measuring interval between - * message handler calls. - */ -static void test_rx_transmit(void) -{ - bt_mesh_test_cfg_set(NULL, 60); - bt_mesh_device_setup(&prov, &local_comp); - provision(UNICAST_ADDR2); - common_configure(UNICAST_ADDR2); - - k_sem_init(&publish_sem, 0, 1); - - for (size_t i = 0; i < ARRAY_SIZE(test_transmit); i++) { - int32_t interval = BT_MESH_PUB_TRANSMIT_INT(test_transmit[i]); - int count = BT_MESH_PUB_TRANSMIT_COUNT(test_transmit[i]); - - recv_jitter_check(interval, count); - } - - PASS(); -} - -/* Cancel one of messages to be published and check that the next one is published when next period - * starts. - */ -static void test_tx_cancel(void) -{ - struct bt_mesh_model *model = &models[2]; - int err; - - bt_mesh_test_cfg_set(NULL, 20); - bt_mesh_device_setup(&prov, &local_comp); - provision(UNICAST_ADDR1); - common_configure(UNICAST_ADDR1); - - k_sem_init(&publish_sem, 0, 1); - - model->pub->retr_update = true; - - for (size_t i = 0; i < ARRAY_SIZE(test_cancel); i++) { - pub_param_set(test_cancel[i].period, test_cancel[i].transmit); - - msgf_publish(); - publish_allow = true; - int64_t timestamp = k_uptime_get(); - - /* Send few messages except one that is to be cancelled. */ - for (size_t j = 0; j < test_cancel[i].msgs - 1; j++) { - err = k_sem_take(&publish_sem, K_SECONDS(20)); - if (err) { - FAIL("Send timed out"); - } - } - - /* Cancel the next publication. */ - publish_allow = false; - k_sleep(K_MSEC(test_cancel[i].sleep)); - - /* Reenable publication a wait for a next message to be published. */ - publish_allow = true; - err = k_sem_take(&publish_sem, K_SECONDS(20)); - if (err) { - FAIL("Send timed out"); - } - - /* Disable periodic publication before the next test iteration. */ - publish_allow = false; - - /* If the canceled message is also sent, the semaphore will be released earlier than - * expected. - */ - int32_t time_delta = k_uptime_delta(×tamp); - int32_t jitter = llabs(time_delta - test_cancel[i].duration); - - LOG_DBG("Send time: %d delta: %d", (int32_t)timestamp, time_delta); - LOG_INF("Send jitter: %d", jitter); - ASSERT_TRUE(jitter <= 10); - - /* Let the receiver hit the first semaphore. */ - k_sleep(K_SECONDS(1)); - } - - PASS(); -} - -/* Receive all published messages and ensure that cancelled message is not received. */ -static void test_rx_cancel(void) -{ - bt_mesh_test_cfg_set(NULL, 20); - bt_mesh_device_setup(&prov, &local_comp); - provision(UNICAST_ADDR2); - common_configure(UNICAST_ADDR2); - - k_sem_init(&publish_sem, 0, 1); - - for (size_t i = 0; i < ARRAY_SIZE(test_cancel); i++) { - int64_t timestamp; - int err; - - /* Wait for the first published message. */ - err = k_sem_take(&publish_sem, K_SECONDS(20)); - if (err) { - FAIL("Recv timed out"); - } - - timestamp = k_uptime_get(); - - /* Wait for the rest messages to be published (incl. the next after cancelled one). - */ - for (size_t j = 0; j < test_cancel[i].msgs; j++) { - err = k_sem_take(&publish_sem, K_SECONDS(20)); - if (err) { - FAIL("Recv timed out"); - } - } - - /* If the canceled message is received, the semaphore will be released earlier than - * expected. - */ - int32_t time_delta = k_uptime_delta(×tamp); - int32_t jitter = llabs(time_delta - test_cancel[i].duration); - - LOG_DBG("Recv time: %d delta: %d", (int32_t)timestamp, time_delta); - LOG_INF("Recv jitter: %d", jitter); - ASSERT_TRUE(jitter <= RX_JITTER_MAX); - } - - PASS(); -} - -#define TEST_CASE(role, name, description) \ - { \ - .test_id = "access_" #role "_" #name, \ - .test_descr = description, \ - .test_tick_f = bt_mesh_test_timeout, \ - .test_main_f = test_##role##_##name, \ - } - -static const struct bst_test_instance test_access[] = { - TEST_CASE(tx, ext_model, "Access: tx data of extended models"), - TEST_CASE(sub, ext_model, "Access: data subscription of extended models"), - TEST_CASE(sub_capacity, ext_model, "Access: subscription capacity of extended models"), - TEST_CASE(tx, period, "Access: Publish a message periodically"), - TEST_CASE(rx, period, "Access: Receive periodically published message"), - TEST_CASE(tx, transmit, "Access: Publish and retransmit message"), - TEST_CASE(rx, transmit, "Access: Receive retransmitted messages"), - TEST_CASE(tx, cancel, "Access: Cancel a message during publication"), - TEST_CASE(rx, cancel, "Access: Receive published messages except cancelled"), - - BSTEST_END_MARKER -}; - -struct bst_test_list *test_access_install(struct bst_test_list *tests) -{ - tests = bst_add_tests(tests, test_access); - return tests; -} diff --git a/tests/bluetooth/bsim/mesh/src/test_advertiser.c b/tests/bluetooth/bsim/mesh/src/test_advertiser.c deleted file mode 100644 index dd12a6befc3..00000000000 --- a/tests/bluetooth/bsim/mesh/src/test_advertiser.c +++ /dev/null @@ -1,715 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include "mesh_test.h" -#include "mesh/adv.h" -#include "mesh/net.h" -#include "mesh/mesh.h" -#include "mesh/foundation.h" - -#define LOG_MODULE_NAME test_adv - -#include -LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL_INF); - -#define WAIT_TIME 60 /*seconds*/ - -enum bt_mesh_gatt_service { - MESH_SERVICE_PROVISIONING, - MESH_SERVICE_PROXY, -}; - -struct bt_mesh_test_adv { - uint8_t retr; /* number of retransmits of adv frame */ - int64_t interval; /* interval of transmitted frames */ -}; - -struct bt_mesh_test_gatt { - uint8_t transmits; /* number of frame (pb gatt or proxy beacon) transmits */ - int64_t interval; /* interval of transmitted frames */ - enum bt_mesh_gatt_service service; -}; - -extern const struct bt_mesh_comp comp; - -static uint8_t test_prov_uuid[16] = { 0x6c, 0x69, 0x6e, 0x67, 0x61, 0xaa }; - -static const struct bt_mesh_test_cfg adv_cfg = { - .addr = 0x0001, - .dev_key = { 0x01 }, -}; - -static struct bt_mesh_send_cb send_cb; -static struct bt_mesh_test_adv xmit_param; -static const char txt_msg[] = "adv test"; -static const char cb_msg[] = "cb test"; -static int64_t tx_timestamp; -static int seq_checker; -static struct bt_mesh_test_gatt gatt_param; -static int num_adv_sent; -static uint8_t previous_checker = 0xff; - -static K_SEM_DEFINE(observer_sem, 0, 1); - -static void test_tx_init(void) -{ - bt_mesh_test_cfg_set(NULL, WAIT_TIME); -} - -static void test_rx_init(void) -{ - bt_mesh_test_cfg_set(NULL, WAIT_TIME); -} - -static void bt_init(void) -{ - ASSERT_OK_MSG(bt_enable(NULL), "Bluetooth init failed"); - LOG_INF("Bluetooth initialized"); -} - -static void adv_init(void) -{ - bt_mesh_adv_init(); - ASSERT_OK_MSG(bt_mesh_adv_enable(), "Mesh adv init failed"); -} - -static void allocate_all_array(struct net_buf **buf, size_t num_buf, uint8_t xmit) -{ - for (int i = 0; i < num_buf; i++) { - *buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, - xmit, K_NO_WAIT); - - ASSERT_FALSE(!*buf, "Out of buffers"); - buf++; - } -} - -static void verify_adv_queue_overflow(void) -{ - struct net_buf *dummy_buf; - - /* Verity Queue overflow */ - dummy_buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, - BT_MESH_TRANSMIT(2, 20), K_NO_WAIT); - ASSERT_TRUE(!dummy_buf, "Unexpected extra buffer"); -} - -static bool check_delta_time(uint8_t transmit, uint64_t interval) -{ - static int cnt; - static int64_t timestamp; - - if (cnt) { - int64_t delta = k_uptime_delta(×tamp); - - LOG_INF("rx: cnt(%d) delta(%dms)", cnt, delta); - - ASSERT_TRUE(delta >= interval && - delta < (interval + 15)); - } else { - timestamp = k_uptime_get(); - - LOG_INF("rx: cnt(%d) delta(0ms)", cnt); - } - - cnt++; - - if (cnt >= transmit) { - cnt = 0; - timestamp = 0; - return true; - } - - return false; -} - -static void single_start_cb(uint16_t duration, int err, void *cb_data) -{ - int64_t delta; - - delta = k_uptime_delta(&tx_timestamp); - LOG_INF("tx start: +%d ms", delta); - ASSERT_TRUE(duration >= 90 && duration <= 200); - ASSERT_EQUAL(0, err); - ASSERT_EQUAL(cb_msg, cb_data); - ASSERT_EQUAL(0, seq_checker & 1); - seq_checker++; -} - -static void single_end_cb(int err, void *cb_data) -{ - int64_t delta; - - delta = k_uptime_delta(&tx_timestamp); - LOG_INF("tx end: +%d ms", delta); - ASSERT_EQUAL(0, err); - ASSERT_EQUAL(cb_msg, cb_data); - ASSERT_EQUAL(1, seq_checker & 1); - seq_checker++; - k_sem_give(&observer_sem); -} - -static void realloc_end_cb(int err, void *cb_data) -{ - struct net_buf *buf = (struct net_buf *)cb_data; - - ASSERT_EQUAL(0, err); - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, - BT_MESH_TRANSMIT(2, 20), K_NO_WAIT); - ASSERT_FALSE(!buf, "Out of buffers"); - - k_sem_give(&observer_sem); -} - -static void seq_start_cb(uint16_t duration, int err, void *cb_data) -{ - ASSERT_EQUAL(0, err); - ASSERT_EQUAL(seq_checker, (intptr_t)cb_data); -} - -static void seq_end_cb(int err, void *cb_data) -{ - ASSERT_EQUAL(0, err); - ASSERT_EQUAL(seq_checker, (intptr_t)cb_data); - seq_checker++; - - if (seq_checker == CONFIG_BT_MESH_ADV_BUF_COUNT) { - k_sem_give(&observer_sem); - } -} - -static void parse_mesh_gatt_preamble(struct net_buf_simple *buf) -{ - ASSERT_EQUAL(0x0201, net_buf_simple_pull_be16(buf)); - /* flags */ - (void)net_buf_simple_pull_u8(buf); - ASSERT_EQUAL(0x0303, net_buf_simple_pull_be16(buf)); -} - -static void parse_mesh_pb_gatt_service(struct net_buf_simple *buf) -{ - /* Figure 7.1: PB-GATT Advertising Data */ - /* mesh provisioning service */ - ASSERT_EQUAL(0x2718, net_buf_simple_pull_be16(buf)); - ASSERT_EQUAL(0x1516, net_buf_simple_pull_be16(buf)); - /* mesh provisioning service */ - ASSERT_EQUAL(0x2718, net_buf_simple_pull_be16(buf)); -} - -static void parse_mesh_proxy_service(struct net_buf_simple *buf) -{ - /* Figure 7.2: Advertising with Network ID (Identification Type 0x00) */ - /* mesh proxy service */ - ASSERT_EQUAL(0x2818, net_buf_simple_pull_be16(buf)); - ASSERT_EQUAL(0x0c16, net_buf_simple_pull_be16(buf)); - /* mesh proxy service */ - ASSERT_EQUAL(0x2818, net_buf_simple_pull_be16(buf)); - /* network ID */ - ASSERT_EQUAL(0x00, net_buf_simple_pull_u8(buf)); -} - -static void gatt_scan_cb(const bt_addr_le_t *addr, int8_t rssi, - uint8_t adv_type, struct net_buf_simple *buf) -{ - if (adv_type != BT_GAP_ADV_TYPE_ADV_IND) { - return; - } - - parse_mesh_gatt_preamble(buf); - - if (gatt_param.service == MESH_SERVICE_PROVISIONING) { - parse_mesh_pb_gatt_service(buf); - } else { - parse_mesh_proxy_service(buf); - } - - LOG_INF("rx: %s", txt_msg); - - if (check_delta_time(gatt_param.transmits, gatt_param.interval)) { - LOG_INF("rx completed. stop observer."); - k_sem_give(&observer_sem); - } -} - -static void rx_gatt_beacons(void) -{ - struct bt_le_scan_param scan_param = { - .type = BT_HCI_LE_SCAN_PASSIVE, - .options = BT_LE_SCAN_OPT_NONE, - .interval = BT_MESH_ADV_SCAN_UNIT(1000), - .window = BT_MESH_ADV_SCAN_UNIT(1000) - }; - int err; - - err = bt_le_scan_start(&scan_param, gatt_scan_cb); - ASSERT_FALSE(err && err != -EALREADY, "starting scan failed (err %d)", err); - - err = k_sem_take(&observer_sem, K_SECONDS(20)); - ASSERT_OK(err); - - err = bt_le_scan_stop(); - ASSERT_FALSE(err && err != -EALREADY, "stopping scan failed (err %d)", err); -} - -static void xmit_scan_cb(const bt_addr_le_t *addr, int8_t rssi, uint8_t adv_type, - struct net_buf_simple *buf) -{ - uint8_t length; - - if (adv_type != BT_GAP_ADV_TYPE_ADV_NONCONN_IND) { - return; - } - - length = net_buf_simple_pull_u8(buf); - ASSERT_EQUAL(buf->len, length); - ASSERT_EQUAL(length, sizeof(uint8_t) + sizeof(txt_msg)); - ASSERT_EQUAL(BT_DATA_MESH_MESSAGE, net_buf_simple_pull_u8(buf)); - - char *data = net_buf_simple_pull_mem(buf, sizeof(txt_msg)); - - LOG_INF("rx: %s", txt_msg); - ASSERT_EQUAL(0, memcmp(txt_msg, data, sizeof(txt_msg))); - - /* Add 1 initial transmit to the retransmit. */ - if (check_delta_time(xmit_param.retr + 1, xmit_param.interval)) { - LOG_INF("rx completed. stop observer."); - k_sem_give(&observer_sem); - } -} - -static void rx_xmit_adv(void) -{ - struct bt_le_scan_param scan_param = { - .type = BT_HCI_LE_SCAN_PASSIVE, - .options = BT_LE_SCAN_OPT_NONE, - .interval = BT_MESH_ADV_SCAN_UNIT(1000), - .window = BT_MESH_ADV_SCAN_UNIT(1000) - }; - int err; - - err = bt_le_scan_start(&scan_param, xmit_scan_cb); - ASSERT_FALSE(err && err != -EALREADY, "starting scan failed (err %d)", err); - - err = k_sem_take(&observer_sem, K_SECONDS(20)); - ASSERT_OK(err); - - err = bt_le_scan_stop(); - ASSERT_FALSE(err && err != -EALREADY, "stopping scan failed (err %d)", err); -} - -static void send_order_start_cb(uint16_t duration, int err, void *user_data) -{ - struct net_buf *buf = (struct net_buf *)user_data; - - ASSERT_OK_MSG(err, "Failed adv start cb err (%d)", err); - ASSERT_EQUAL(2, buf->len); - - uint8_t current = buf->data[0]; - uint8_t previous = buf->data[1]; - - LOG_INF("tx start: current(%d) previous(%d)", current, previous); - - ASSERT_EQUAL(previous_checker, previous); - previous_checker = current; -} - -static void send_order_end_cb(int err, void *user_data) -{ - struct net_buf *buf = (struct net_buf *)user_data; - - ASSERT_OK_MSG(err, "Failed adv start cb err (%d)", err); - ASSERT_TRUE(!buf->data, "Data not cleared!"); - seq_checker++; - LOG_INF("tx end: seq(%d)", seq_checker); - - if (seq_checker == num_adv_sent) { - seq_checker = 0; - previous_checker = 0xff; - k_sem_give(&observer_sem); - } -} - -static void receive_order_scan_cb(const bt_addr_le_t *addr, int8_t rssi, uint8_t adv_type, - struct net_buf_simple *buf) -{ - uint8_t length; - uint8_t current; - uint8_t previous; - - length = net_buf_simple_pull_u8(buf); - ASSERT_EQUAL(buf->len, length); - ASSERT_EQUAL(BT_DATA_MESH_MESSAGE, net_buf_simple_pull_u8(buf)); - current = net_buf_simple_pull_u8(buf); - previous = net_buf_simple_pull_u8(buf); - LOG_INF("rx: current(%d) previous(%d)", current, previous); - ASSERT_EQUAL(previous_checker, previous); - - /* Add 1 initial transmit to the retransmit. */ - if (check_delta_time(xmit_param.retr + 1, xmit_param.interval)) { - previous_checker = current; - k_sem_give(&observer_sem); - } -} - -static void receive_order(int expect_adv) -{ - struct bt_le_scan_param scan_param = { - .type = BT_HCI_LE_SCAN_PASSIVE, - .options = BT_LE_SCAN_OPT_NONE, - .interval = BT_MESH_ADV_SCAN_UNIT(1000), - .window = BT_MESH_ADV_SCAN_UNIT(1000) - }; - int err; - - err = bt_le_scan_start(&scan_param, receive_order_scan_cb); - ASSERT_FALSE(err && err != -EALREADY, "starting scan failed (err %d)", err); - - previous_checker = 0xff; - for (int i = 0; i < expect_adv; i++) { - err = k_sem_take(&observer_sem, K_SECONDS(10)); - ASSERT_OK_MSG(err, "Didn't receive adv in time"); - } - - err = bt_le_scan_stop(); - ASSERT_FALSE(err && err != -EALREADY, "stopping scan failed (err %d)", err); -} - -static void send_adv_buf(struct net_buf *buf, uint8_t curr, uint8_t prev) -{ - send_cb.start = send_order_start_cb; - send_cb.end = send_order_end_cb; - - (void)net_buf_add_u8(buf, curr); - (void)net_buf_add_u8(buf, prev); - - bt_mesh_adv_send(buf, &send_cb, buf); - net_buf_unref(buf); -} - -static void send_adv_array(struct net_buf **buf, size_t num_buf, bool reverse) -{ - uint8_t previous; - int i; - - num_adv_sent = num_buf; - previous = 0xff; - if (!reverse) { - i = 0; - } else { - i = num_buf - 1; - } - while ((!reverse && i < num_buf) || (reverse && i >= 0)) { - send_adv_buf(*buf, (uint8_t)i, previous); - previous = (uint8_t)i; - if (!reverse) { - buf++; - i++; - } else { - buf--; - i--; - } - } -} - -static void test_tx_cb_single(void) -{ - struct net_buf *buf; - int err; - - bt_init(); - adv_init(); - - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, - BT_MESH_TRANSMIT(2, 20), K_NO_WAIT); - ASSERT_FALSE(!buf, "Out of buffers"); - - send_cb.start = single_start_cb; - send_cb.end = single_end_cb; - - net_buf_add_mem(buf, txt_msg, sizeof(txt_msg)); - seq_checker = 0; - tx_timestamp = k_uptime_get(); - bt_mesh_adv_send(buf, &send_cb, (void *)cb_msg); - net_buf_unref(buf); - - err = k_sem_take(&observer_sem, K_SECONDS(1)); - ASSERT_OK_MSG(err, "Didn't call end tx cb."); - - PASS(); -} - -static void test_rx_xmit(void) -{ - xmit_param.retr = 2; - xmit_param.interval = 20; - - bt_init(); - rx_xmit_adv(); - - PASS(); -} - -static void test_tx_cb_multi(void) -{ - struct net_buf *buf[CONFIG_BT_MESH_ADV_BUF_COUNT]; - int err; - - bt_init(); - adv_init(); - - /* Allocate all network buffers. */ - allocate_all_array(buf, ARRAY_SIZE(buf), BT_MESH_TRANSMIT(2, 20)); - - /* Start single adv to reallocate one network buffer in callback. - * Check that the buffer is freed before cb is triggered. - */ - send_cb.start = NULL; - send_cb.end = realloc_end_cb; - net_buf_add_mem(buf[0], txt_msg, sizeof(txt_msg)); - - bt_mesh_adv_send(buf[0], &send_cb, buf[0]); - net_buf_unref(buf[0]); - - err = k_sem_take(&observer_sem, K_SECONDS(1)); - ASSERT_OK_MSG(err, "Didn't call the end tx cb that reallocates buffer one more time."); - - /* Start multi advs to check that all buffers are sent and cbs are triggered. */ - send_cb.start = seq_start_cb; - send_cb.end = seq_end_cb; - seq_checker = 0; - - for (int i = 0; i < CONFIG_BT_MESH_ADV_BUF_COUNT; i++) { - net_buf_add_le32(buf[i], i); - bt_mesh_adv_send(buf[i], &send_cb, (void *)(intptr_t)i); - net_buf_unref(buf[i]); - } - - err = k_sem_take(&observer_sem, K_SECONDS(10)); - ASSERT_OK_MSG(err, "Didn't call the last end tx cb."); - - PASS(); -} - -static void test_tx_proxy_mixin(void) -{ - static struct bt_mesh_prov prov = { - .uuid = test_prov_uuid, - }; - uint8_t status; - int err; - - /* Initialize mesh stack and enable pb gatt bearer to emit beacons. */ - bt_mesh_device_setup(&prov, &comp); - err = bt_mesh_prov_enable(BT_MESH_PROV_GATT); - ASSERT_OK_MSG(err, "Failed to enable GATT provisioner"); - - /* Let the tester to measure an interval between advertisements. - * The node should advertise pb gatt service with 100 msec interval. - */ - k_sleep(K_MSEC(1800)); - - LOG_INF("Provision device under test"); - /* Provision dut and start gatt proxy beacons. */ - bt_mesh_provision(test_net_key, 0, 0, 0, adv_cfg.addr, adv_cfg.dev_key); - /* Disable secured network beacons to exclude influence of them on proxy beaconing. */ - ASSERT_OK(bt_mesh_cfg_cli_beacon_set(0, adv_cfg.addr, BT_MESH_BEACON_DISABLED, &status)); - ASSERT_EQUAL(BT_MESH_BEACON_DISABLED, status); - - /* Let the tester to measure an interval between advertisements. - * The node should advertise proxy service with 1 second interval. - */ - k_sleep(K_MSEC(6000)); - - /* Send a mesh message while advertising proxy service. - * Advertising the proxy service should be resumed after - * finishing advertising the message. - */ - struct net_buf *buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, - BT_MESH_TRANSMIT(5, 20), K_NO_WAIT); - net_buf_add_mem(buf, txt_msg, sizeof(txt_msg)); - bt_mesh_adv_send(buf, NULL, NULL); - k_sleep(K_MSEC(150)); - - /* Let the tester to measure an interval between advertisements again. */ - k_sleep(K_MSEC(6000)); - - PASS(); -} - -static void test_rx_proxy_mixin(void) -{ - /* (total transmit duration) / (transmit interval) */ - gatt_param.transmits = 1500 / 100; - gatt_param.interval = 100; - gatt_param.service = MESH_SERVICE_PROVISIONING; - - bt_init(); - - /* Scan pb gatt beacons. */ - rx_gatt_beacons(); - - /* Delay to provision dut */ - k_sleep(K_MSEC(1000)); - - /* Scan proxy beacons. */ - /* (total transmit duration) / (transmit interval) */ - gatt_param.transmits = 5000 / 1000; - gatt_param.interval = 1000; - gatt_param.service = MESH_SERVICE_PROXY; - rx_gatt_beacons(); - - /* Scan adv data. */ - xmit_param.retr = 5; - xmit_param.interval = 20; - rx_xmit_adv(); - - /* Scan proxy beacons again. */ - rx_gatt_beacons(); - - PASS(); -} - -static void test_tx_send_order(void) -{ - struct net_buf *buf[CONFIG_BT_MESH_ADV_BUF_COUNT]; - uint8_t xmit = BT_MESH_TRANSMIT(2, 20); - - bt_init(); - adv_init(); - - /* Verify sending order */ - allocate_all_array(buf, ARRAY_SIZE(buf), xmit); - verify_adv_queue_overflow(); - send_adv_array(&buf[0], ARRAY_SIZE(buf), false); - - /* Wait for no message receive window to end. */ - ASSERT_OK_MSG(k_sem_take(&observer_sem, K_SECONDS(10)), - "Didn't call the last end tx cb."); - - /* Verify buffer allocation/deallocation after sending */ - allocate_all_array(buf, ARRAY_SIZE(buf), xmit); - verify_adv_queue_overflow(); - for (int i = 0; i < CONFIG_BT_MESH_ADV_BUF_COUNT; i++) { - net_buf_unref(buf[i]); - buf[i] = NULL; - } - /* Check that it possible to add just one net buf. */ - allocate_all_array(buf, 1, xmit); - - PASS(); -} - -static void test_tx_reverse_order(void) -{ - struct net_buf *buf[CONFIG_BT_MESH_ADV_BUF_COUNT]; - uint8_t xmit = BT_MESH_TRANSMIT(2, 20); - - bt_init(); - adv_init(); - - /* Verify reversed sending order */ - allocate_all_array(buf, ARRAY_SIZE(buf), xmit); - - send_adv_array(&buf[CONFIG_BT_MESH_ADV_BUF_COUNT - 1], ARRAY_SIZE(buf), true); - - /* Wait for no message receive window to end. */ - ASSERT_OK_MSG(k_sem_take(&observer_sem, K_SECONDS(10)), - "Didn't call the last end tx cb."); - - PASS(); -} - -static void test_tx_random_order(void) -{ - struct net_buf *buf[3]; - uint8_t xmit = BT_MESH_TRANSMIT(0, 20); - - bt_init(); - adv_init(); - - /* Verify random order calls */ - num_adv_sent = ARRAY_SIZE(buf); - previous_checker = 0xff; - buf[0] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, - xmit, K_NO_WAIT); - ASSERT_FALSE(!buf[0], "Out of buffers"); - buf[1] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, - xmit, K_NO_WAIT); - ASSERT_FALSE(!buf[1], "Out of buffers"); - - send_adv_buf(buf[0], 0, 0xff); - - buf[2] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, - xmit, K_NO_WAIT); - ASSERT_FALSE(!buf[2], "Out of buffers"); - - send_adv_buf(buf[2], 2, 0); - - send_adv_buf(buf[1], 1, 2); - - /* Wait for no message receive window to end. */ - ASSERT_OK_MSG(k_sem_take(&observer_sem, K_SECONDS(10)), - "Didn't call the last end tx cb."); - - PASS(); -} - -static void test_rx_receive_order(void) -{ - bt_init(); - - xmit_param.retr = 2; - xmit_param.interval = 20; - - receive_order(CONFIG_BT_MESH_ADV_BUF_COUNT); - - PASS(); -} - -static void test_rx_random_order(void) -{ - bt_init(); - - xmit_param.retr = 0; - xmit_param.interval = 20; - - receive_order(3); - - PASS(); -} - -#define TEST_CASE(role, name, description) \ - { \ - .test_id = "adv_" #role "_" #name, \ - .test_descr = description, \ - .test_pre_init_f = test_##role##_init, \ - .test_tick_f = bt_mesh_test_timeout, \ - .test_main_f = test_##role##_##name, \ - } - -static const struct bst_test_instance test_adv[] = { - TEST_CASE(tx, cb_single, "ADV: tx cb parameter checker"), - TEST_CASE(tx, cb_multi, "ADV: tx cb sequence checker"), - TEST_CASE(tx, proxy_mixin, "ADV: proxy mix-in gatt adv"), - TEST_CASE(tx, send_order, "ADV: tx send order"), - TEST_CASE(tx, reverse_order, "ADV: tx reversed order"), - TEST_CASE(tx, random_order, "ADV: tx random order"), - - TEST_CASE(rx, xmit, "ADV: xmit checker"), - TEST_CASE(rx, proxy_mixin, "ADV: proxy mix-in scanner"), - TEST_CASE(rx, receive_order, "ADV: rx receive order"), - TEST_CASE(rx, random_order, "ADV: rx random order"), - - BSTEST_END_MARKER -}; - -struct bst_test_list *test_adv_install(struct bst_test_list *tests) -{ - tests = bst_add_tests(tests, test_adv); - return tests; -} diff --git a/tests/bluetooth/bsim/mesh/src/test_beacon.c b/tests/bluetooth/bsim/mesh/src/test_beacon.c deleted file mode 100644 index a08c7e6559f..00000000000 --- a/tests/bluetooth/bsim/mesh/src/test_beacon.c +++ /dev/null @@ -1,937 +0,0 @@ -/* - * Copyright (c) 2021 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include -#include -#include "mesh_test.h" -#include "mesh/adv.h" -#include "mesh/net.h" -#include "mesh/beacon.h" -#include "mesh/mesh.h" -#include "mesh/foundation.h" -#include "mesh/crypto.h" - -#define LOG_MODULE_NAME test_beacon - -#include -LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL_INF); - -#define GROUP_ADDR 0xc000 -#define WAIT_TIME 60 /*seconds*/ -#define MULT_NETKEYS_WAIT_TIME 350 /*seconds*/ -#define BEACON_INTERVAL_WAIT_TIME 750 /*seconds*/ -#define BEACON_INTERVAL 10 /*seconds*/ - -#define BEACON_TYPE_SECURE 0x01 - -static uint8_t test_net_key_secondary[16] = { 0xca, 0x11, 0xab, 0x1e }; -static struct { - uint8_t primary[16]; - uint8_t secondary[16]; -} net_key_pairs[] = { - { "\x01\x02", "\x03\x04" }, - { "\x11\x12", "\x13\x14" }, - { "\x21\x22", "\x23\x24" }, - { "\x31\x32", "\x33\x34" }, -}; - -extern enum bst_result_t bst_result; - -static const struct bt_mesh_test_cfg tx_cfg = { - .addr = 0x0001, - .dev_key = { 0x01 }, -}; -static const struct bt_mesh_test_cfg rx_cfg = { - .addr = 0x0002, - .dev_key = { 0x02 }, -}; - -static void test_tx_init(void) -{ - bt_mesh_test_cfg_set(&tx_cfg, WAIT_TIME); -} - -static void test_rx_init(void) -{ - bt_mesh_test_cfg_set(&rx_cfg, WAIT_TIME); -} - -static void ivu_log(void) -{ - LOG_DBG("ivi: %i", bt_mesh.iv_index); - LOG_DBG("flags:"); - - if (atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_INITIATOR)) { - LOG_DBG("IVU initiator"); - } - - if (atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS)) { - LOG_DBG("IVU in progress"); - } - - if (atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_PENDING)) { - LOG_DBG("IVU pending"); - } - - if (atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_TEST)) { - LOG_DBG("IVU in test mode"); - } -} - -static void test_tx_on_iv_update(void) -{ - bt_mesh_test_setup(); - ASSERT_TRUE(!atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_INITIATOR)); - ASSERT_TRUE(!atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS)); - ASSERT_TRUE(!atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_PENDING)); - ASSERT_TRUE(!atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_TEST)); - ASSERT_TRUE(bt_mesh.iv_index == 0); - - /* shift beaconing time line to avoid boundary cases. */ - k_sleep(K_SECONDS(1)); - - bt_mesh_iv_update_test(true); - ASSERT_TRUE(atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_TEST)); - - ASSERT_TRUE(bt_mesh_iv_update()); - ASSERT_TRUE(atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS)); - ASSERT_TRUE(bt_mesh.iv_index == 1); - - k_sleep(K_SECONDS(BEACON_INTERVAL)); - - ASSERT_TRUE(!bt_mesh_iv_update()); - ASSERT_TRUE(!atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS)); - ASSERT_TRUE(bt_mesh.iv_index == 1); - - k_sleep(K_SECONDS(BEACON_INTERVAL)); - - ASSERT_TRUE(bt_mesh_iv_update()); - ASSERT_TRUE(atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS)); - ASSERT_TRUE(bt_mesh.iv_index == 2); - - k_sleep(K_SECONDS(BEACON_INTERVAL)); - - PASS(); -} - -static void test_rx_on_iv_update(void) -{ - bt_mesh_test_setup(); - /* disable beaconing from Rx device to prevent - * the time line adaptation due to observation algorithm. - */ - bt_mesh_beacon_disable(); - ASSERT_TRUE(!atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_INITIATOR)); - ASSERT_TRUE(!atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS)); - ASSERT_TRUE(!atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_PENDING)); - ASSERT_TRUE(!atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_TEST)); - ASSERT_TRUE(bt_mesh.iv_index == 0); - - /* shift beaconing time line to avoid boundary cases. */ - k_sleep(K_SECONDS(1)); - - bt_mesh_iv_update_test(true); - ASSERT_TRUE(atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_TEST)); - ivu_log(); - - k_sleep(K_SECONDS(BEACON_INTERVAL)); - - ASSERT_TRUE(atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS)); - ASSERT_TRUE(bt_mesh.iv_index == 1); - ivu_log(); - - k_sleep(K_SECONDS(BEACON_INTERVAL)); - - ASSERT_TRUE(!atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS)); - ASSERT_TRUE(bt_mesh.iv_index == 1); - ivu_log(); - - k_sleep(K_SECONDS(BEACON_INTERVAL)); - - ASSERT_TRUE(atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS)); - ASSERT_TRUE(bt_mesh.iv_index == 2); - ivu_log(); - - PASS(); -} - -static void test_tx_on_key_refresh(void) -{ - const uint8_t new_key[16] = {0x01}; - uint8_t phase; - uint8_t status; - - bt_mesh_test_setup(); - - status = bt_mesh_subnet_kr_phase_get(BT_MESH_KEY_PRIMARY, &phase); - ASSERT_TRUE(status == STATUS_SUCCESS); - ASSERT_TRUE(phase == BT_MESH_KR_NORMAL); - - /* shift beaconing time line to avoid boundary cases. */ - k_sleep(K_SECONDS(1)); - - status = bt_mesh_subnet_update(BT_MESH_KEY_PRIMARY, new_key); - ASSERT_TRUE(status == STATUS_SUCCESS); - status = bt_mesh_subnet_kr_phase_get(BT_MESH_KEY_PRIMARY, &phase); - ASSERT_TRUE(status == STATUS_SUCCESS); - ASSERT_TRUE(phase == BT_MESH_KR_PHASE_1); - - k_sleep(K_SECONDS(BEACON_INTERVAL)); - - phase = BT_MESH_KR_PHASE_2; - status = bt_mesh_subnet_kr_phase_set(BT_MESH_KEY_PRIMARY, &phase); - ASSERT_TRUE(status == STATUS_SUCCESS); - status = bt_mesh_subnet_kr_phase_get(BT_MESH_KEY_PRIMARY, &phase); - ASSERT_TRUE(status == STATUS_SUCCESS); - ASSERT_TRUE(phase == BT_MESH_KR_PHASE_2); - - k_sleep(K_SECONDS(BEACON_INTERVAL)); - - phase = BT_MESH_KR_PHASE_3; - status = bt_mesh_subnet_kr_phase_set(BT_MESH_KEY_PRIMARY, &phase); - ASSERT_TRUE(status == STATUS_SUCCESS); - status = bt_mesh_subnet_kr_phase_get(BT_MESH_KEY_PRIMARY, &phase); - ASSERT_TRUE(status == STATUS_SUCCESS); - ASSERT_TRUE(phase == BT_MESH_KR_NORMAL); - - k_sleep(K_SECONDS(BEACON_INTERVAL)); - - PASS(); -} - -static void test_rx_on_key_refresh(void) -{ - const uint8_t new_key[16] = {0x01}; - uint8_t phase; - uint8_t status; - - bt_mesh_test_setup(); - /* disable beaconing from Rx device to prevent - * the time line adaptation due to observation algorithm. - */ - bt_mesh_beacon_disable(); - - status = bt_mesh_subnet_kr_phase_get(BT_MESH_KEY_PRIMARY, &phase); - ASSERT_TRUE(status == STATUS_SUCCESS); - ASSERT_TRUE(phase == BT_MESH_KR_NORMAL); - - /* shift beaconing time line to avoid boundary cases. */ - k_sleep(K_SECONDS(1)); - - status = bt_mesh_subnet_update(BT_MESH_KEY_PRIMARY, new_key); - ASSERT_TRUE(status == STATUS_SUCCESS); - status = bt_mesh_subnet_kr_phase_get(BT_MESH_KEY_PRIMARY, &phase); - ASSERT_TRUE(status == STATUS_SUCCESS); - ASSERT_TRUE(phase == BT_MESH_KR_PHASE_1); - - k_sleep(K_SECONDS(BEACON_INTERVAL)); - - status = bt_mesh_subnet_kr_phase_get(BT_MESH_KEY_PRIMARY, &phase); - ASSERT_TRUE(status == STATUS_SUCCESS); - ASSERT_TRUE(phase == BT_MESH_KR_PHASE_1); - - k_sleep(K_SECONDS(BEACON_INTERVAL)); - - status = bt_mesh_subnet_kr_phase_get(BT_MESH_KEY_PRIMARY, &phase); - ASSERT_TRUE(status == STATUS_SUCCESS); - ASSERT_TRUE(phase == BT_MESH_KR_PHASE_2); - - k_sleep(K_SECONDS(BEACON_INTERVAL)); - - status = bt_mesh_subnet_kr_phase_get(BT_MESH_KEY_PRIMARY, &phase); - ASSERT_TRUE(status == STATUS_SUCCESS); - ASSERT_TRUE(phase == BT_MESH_KR_NORMAL); - - PASS(); -} - -static struct k_sem observer_sem; -static struct { - uint8_t flags; - uint32_t iv_index; - bool (*process_cb)(const uint8_t *net_id, void *ctx); - void *user_ctx; -} beacon; - -static void beacon_scan_cb(const bt_addr_le_t *addr, int8_t rssi, uint8_t adv_type, - struct net_buf_simple *buf) -{ - const uint8_t *net_id; - uint8_t length; - - ASSERT_EQUAL(BT_GAP_ADV_TYPE_ADV_NONCONN_IND, adv_type); - - length = net_buf_simple_pull_u8(buf); - ASSERT_EQUAL(buf->len, length); - ASSERT_EQUAL(BT_DATA_MESH_BEACON, net_buf_simple_pull_u8(buf)); - ASSERT_EQUAL(BEACON_TYPE_SECURE, net_buf_simple_pull_u8(buf)); - - beacon.flags = net_buf_simple_pull_u8(buf); - net_id = net_buf_simple_pull_mem(buf, 8); - beacon.iv_index = net_buf_simple_pull_be32(buf); - - if (!beacon.process_cb || beacon.process_cb(net_id, beacon.user_ctx)) { - k_sem_give(&observer_sem); - } -} - -/* Listens to beacons for one beacon interval (10 seconds). */ -static bool wait_for_beacon(bool (*process_cb)(const uint8_t *net_id, void *ctx), void *ctx) -{ - struct bt_le_scan_param scan_param = { - .type = BT_HCI_LE_SCAN_PASSIVE, - .options = BT_LE_SCAN_OPT_NONE, - .interval = BT_MESH_ADV_SCAN_UNIT(1000), - .window = BT_MESH_ADV_SCAN_UNIT(1000) - }; - bool received = false; - int err; - - beacon.process_cb = process_cb; - beacon.user_ctx = ctx; - - err = bt_le_scan_start(&scan_param, beacon_scan_cb); - if (err && err != -EALREADY) { - FAIL("starting scan failed (err %d)", err); - } - - /* Listen to beacons ONLY for one beacon interval. - * Tests start quite often the waiting for the next beacon after - * transmission or receiving the previous one. If start waiting timer - * for BEACON_INTERVAL interval then timer expiration and receiving of - * the beacon happen about the same time. That is possible unstable behavior - * or failing some tests. To avoid this it is worth to add 1 second to - * waiting time (BEACON_INTERVAL + 1) to guarantee that beacon comes - * before timer expiration. - */ - err = k_sem_take(&observer_sem, K_SECONDS(BEACON_INTERVAL + 1)); - if (!err) { - received = true; - } else { - LOG_WRN("Didn't receive SNB in time (err: %d)", err); - } - - err = bt_le_scan_stop(); - if (err && err != -EALREADY) { - FAIL("stopping scan failed (err %d)", err); - } - - /* Sleep a little to get to the next beacon interval. Otherwise, calling this function - * again will catch the old beacon. This happens due to a known bug in legacy advertiser, - * which transmits advertisements longer than should. - */ - if (received && IS_ENABLED(CONFIG_BT_MESH_ADV_LEGACY)) { - k_sleep(K_SECONDS(1)); - } - - return received; -} - -static void send_beacon(struct net_buf_simple *buf) -{ - struct bt_data ad; - int err; - - ad.type = BT_DATA_MESH_BEACON; - ad.data = buf->data; - ad.data_len = buf->len; - - err = bt_le_adv_start(BT_LE_ADV_NCONN, &ad, 1, NULL, 0); - if (err) { - FAIL("Advertising failed to start (err %d)\n", err); - } - - LOG_INF("Advertising started\n"); - - k_sleep(K_MSEC(100)); - - err = bt_le_adv_stop(); - if (err) { - FAIL("Unable to stop advertising"); - } -} - -static void beacon_create(struct net_buf_simple *buf, const uint8_t *net_key, uint8_t flags, - uint32_t iv_index) -{ - uint8_t beacon_key[16]; - uint8_t net_id[8]; - uint8_t auth[8]; - int err; - - err = bt_mesh_k3(net_key, net_id); - if (err) { - FAIL("Unable to generate Net ID"); - } - - err = bt_mesh_beacon_key(net_key, beacon_key); - if (err) { - FAIL("Unable to generate beacon key"); - } - - err = bt_mesh_beacon_auth(beacon_key, flags, net_id, iv_index, auth); - if (err) { - FAIL("Unable to generate auth value"); - } - - net_buf_simple_reset(buf); - net_buf_simple_add_u8(buf, BEACON_TYPE_SECURE); - net_buf_simple_add_u8(buf, flags); - net_buf_simple_add_mem(buf, net_id, 8); - net_buf_simple_add_be32(buf, iv_index); - net_buf_simple_add_mem(buf, auth, 8); -} - -/* Test reception of invalid beacons. */ -static void test_tx_invalid(void) -{ - NET_BUF_SIMPLE_DEFINE(buf, 22); - int err; - - bt_mesh_test_cfg_set(&tx_cfg, 130); - k_sem_init(&observer_sem, 0, 1); - - err = bt_enable(NULL); - if (err) { - FAIL("Bluetooth init failed (err %d)", err); - return; - } - - LOG_INF("Bluetooth initialized"); - - /* Let the rx node send the first beacon. */ - k_sleep(K_SECONDS(5)); - - /* Create a valid beacon with IV Update Flag set to 1 and new IV Index. */ - beacon_create(&buf, test_net_key, 0x02, 0x0001); - - /* Corrupt Flags. The node shall ignore the beacon and continue sending beacons regularly.*/ - buf.data[1] ^= 0xFF; - send_beacon(&buf); - buf.data[1] ^= 0xFF; - /* Ensure that interval is not affected. */ - ASSERT_TRUE(wait_for_beacon(NULL, NULL)); - ASSERT_TRUE(wait_for_beacon(NULL, NULL)); - ASSERT_EQUAL(0x00, beacon.flags); - ASSERT_EQUAL(0x0000, beacon.iv_index); - - /* Corrupt Network ID. The node shall ignore the beacon and continue sending beacons - * regularly. - */ - buf.data[2] ^= 0xFF; - send_beacon(&buf); - buf.data[2] ^= 0xFF; - /* Ensure that interval is not affected. */ - ASSERT_TRUE(wait_for_beacon(NULL, NULL)); - ASSERT_TRUE(wait_for_beacon(NULL, NULL)); - ASSERT_EQUAL(0x00, beacon.flags); - ASSERT_EQUAL(0x0000, beacon.iv_index); - - /* Corrupt IV Index. The node shall ignore the beacon and continue sending beacons - * regularly. - */ - buf.data[10] ^= 0xFF; - send_beacon(&buf); - buf.data[10] ^= 0xFF; - /* Ensure that interval is not affected. */ - ASSERT_TRUE(wait_for_beacon(NULL, NULL)); - ASSERT_TRUE(wait_for_beacon(NULL, NULL)); - ASSERT_EQUAL(0x00, beacon.flags); - ASSERT_EQUAL(0x0000, beacon.iv_index); - - /* Corrupt Authentication value. The node shall ignore the beacon and continue sending - * beacons regularly. - */ - buf.data[14] ^= 0xFF; - send_beacon(&buf); - buf.data[14] ^= 0xFF; - /* Ensure that interval is not affected. */ - ASSERT_TRUE(wait_for_beacon(NULL, NULL)); - ASSERT_TRUE(wait_for_beacon(NULL, NULL)); - ASSERT_EQUAL(0x00, beacon.flags); - ASSERT_EQUAL(0x0000, beacon.iv_index); - - /* Now the beacon payload is valid and it shall trigger IV Update on the node. It shall also - * increase the beacon interval. - */ - send_beacon(&buf); - /* The beacon interval shall be changed and the node shall skip transmission of the next - * beacon. - */ - ASSERT_FALSE(wait_for_beacon(NULL, NULL)); - ASSERT_TRUE(wait_for_beacon(NULL, NULL)); - ASSERT_EQUAL(0x02, beacon.flags); - ASSERT_EQUAL(0x0001, beacon.iv_index); - - PASS(); -} - -/* Test reception of invalid beacons. */ -static void test_rx_invalid(void) -{ - bt_mesh_test_cfg_set(&rx_cfg, 130); - bt_mesh_test_setup(); - bt_mesh_iv_update_test(true); - - k_sleep(K_SECONDS(10)); - - for (size_t i = 0; i < 4; i++) { - ASSERT_FALSE(atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS)); - ASSERT_EQUAL(0, bt_mesh.iv_index); - - k_sleep(K_SECONDS((BEACON_INTERVAL + 1) * 2)); - } - - /* Only the last beacon shall change IV Update state. */ - ASSERT_TRUE(atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS)); - ASSERT_EQUAL(1, bt_mesh.iv_index); - - PASS(); -} - -/* Test beacons reception with Key Refresh and IV Update on primary subnet. */ -static void test_tx_kr_old_key(void) -{ - NET_BUF_SIMPLE_DEFINE(buf, 22); - int err; - - bt_mesh_test_cfg_set(&tx_cfg, 170); - k_sem_init(&observer_sem, 0, 1); - - err = bt_enable(NULL); - if (err) { - FAIL("Bluetooth init failed (err %d)", err); - return; - } - - LOG_INF("Bluetooth initialized"); - - /* Let the rx node send the first beacon. */ - k_sleep(K_SECONDS(5)); - - /* The node has added a new Net Key. */ - - /* Send a beacon with Key Refresh flag set to 1, but secured with the old Net Key. The - * beacon shall not change Key Refresh phase, but should still be processed. The beacon - * interval shall be increased. - */ - beacon_create(&buf, test_net_key, 0x01, 0x0000); - send_beacon(&buf); - ASSERT_FALSE(wait_for_beacon(NULL, NULL)); - ASSERT_TRUE(wait_for_beacon(NULL, NULL)); - ASSERT_EQUAL(0x00, beacon.flags); - ASSERT_EQUAL(0x0000, beacon.iv_index); - - /* The old Net Key can still initiate IV Index update. */ - beacon_create(&buf, test_net_key, 0x02, 0x0001); - send_beacon(&buf); - ASSERT_FALSE(wait_for_beacon(NULL, NULL)); - ASSERT_TRUE(wait_for_beacon(NULL, NULL)); - ASSERT_EQUAL(0x02, beacon.flags); - ASSERT_EQUAL(0x0001, beacon.iv_index); - - /* Send beacon with Key Refresh flag set to 1, IV Update flag set to 1, but secured with - * the new Net Key. The node shall set Key Refresh phase to 2. The beacon interval shall - * be increased. - */ - beacon_create(&buf, test_net_key_secondary, 0x03, 0x0001); - send_beacon(&buf); - ASSERT_FALSE(wait_for_beacon(NULL, NULL)); - ASSERT_TRUE(wait_for_beacon(NULL, NULL)); - ASSERT_EQUAL(0x03, beacon.flags); - ASSERT_EQUAL(0x0001, beacon.iv_index); - - /* Send beacon with Key Refresh flag set to 1, IV Update flag set to 0, but secured with - * the old Net Key. The beacon shall be rejected. The beacon interval shall not be changed. - */ - beacon_create(&buf, test_net_key, 0x01, 0x0001); - send_beacon(&buf); - ASSERT_TRUE(wait_for_beacon(NULL, NULL)); - ASSERT_TRUE(wait_for_beacon(NULL, NULL)); - ASSERT_EQUAL(0x03, beacon.flags); - ASSERT_EQUAL(0x0001, beacon.iv_index); - - /* Try the same with the new Net Key. Now the node shall change Key Refresh phase to 0. The - * beacon interval shall be increased. - */ - beacon_create(&buf, test_net_key_secondary, 0x02, 0x0001); - send_beacon(&buf); - ASSERT_FALSE(wait_for_beacon(NULL, NULL)); - ASSERT_TRUE(wait_for_beacon(NULL, NULL)); - ASSERT_EQUAL(0x02, beacon.flags); - ASSERT_EQUAL(0x0001, beacon.iv_index); - - /* Send beacon with IV Update flag set to 0 and secured with the old Net Key. The beacon - * shall be ignored. The beacon interval shall not be changed. - */ - beacon_create(&buf, test_net_key, 0x00, 0x0001); - send_beacon(&buf); - ASSERT_TRUE(wait_for_beacon(NULL, NULL)); - ASSERT_TRUE(wait_for_beacon(NULL, NULL)); - ASSERT_EQUAL(0x02, beacon.flags); - ASSERT_EQUAL(0x0001, beacon.iv_index); - - /* Do the same, but secure beacon with the new Net Key. Now the node shall change IV Update - * flag to 0. The beacon interval shall be increased. - */ - beacon_create(&buf, test_net_key_secondary, 0x00, 0x0001); - send_beacon(&buf); - ASSERT_FALSE(wait_for_beacon(NULL, NULL)); - ASSERT_TRUE(wait_for_beacon(NULL, NULL)); - ASSERT_EQUAL(0x00, beacon.flags); - ASSERT_EQUAL(0x0001, beacon.iv_index); - - PASS(); -} - -/* Test beacons reception with Key Refresh and IV Update on primary subnet. */ -static void test_rx_kr_old_key(void) -{ - uint8_t phase; - uint8_t status; - int err; - - bt_mesh_test_cfg_set(&rx_cfg, 170); - bt_mesh_test_setup(); - bt_mesh_iv_update_test(true); - - err = bt_mesh_cfg_cli_net_key_update(0, cfg->addr, 0, test_net_key_secondary, &status); - if (err || status) { - FAIL("Net Key update failed (err %d, status %u)", err, status); - } - - static struct { - uint8_t phase; - bool ivu; - uint32_t ivi; - } test_vector[] = { - /* Old Net Key, attempt to change Key Refresh phase to 2. */ - { .phase = BT_MESH_KR_PHASE_1, .ivu = false, .ivi = 0 }, - /* Old Net Key, changing IV Update state. */ - { .phase = BT_MESH_KR_PHASE_1, .ivu = true, .ivi = 1 }, - /* New Net Key, changing Key Refresh phase. */ - { .phase = BT_MESH_KR_PHASE_2, .ivu = true, .ivi = 1 }, - /* Old Net Key, attempt to change IV Update state. */ - { .phase = BT_MESH_KR_PHASE_2, .ivu = true, .ivi = 1 }, - /* New Net Key, changing Key Refresh phase to 0. */ - { .phase = BT_MESH_KR_NORMAL, .ivu = true, .ivi = 1 }, - /* Old Net Key, attempt to change IV Update state to Idle.*/ - { .phase = BT_MESH_KR_NORMAL, .ivu = true, .ivi = 1 }, - /* Net Net Key, changing IV Update state to Idle. */ - { .phase = BT_MESH_KR_NORMAL, .ivu = false, .ivi = 1 }, - }; - - k_sleep(K_SECONDS(8)); - - for (size_t i = 0; i < ARRAY_SIZE(test_vector); i++) { - status = bt_mesh_subnet_kr_phase_get(0, &phase); - if (status != STATUS_SUCCESS) { - FAIL("Unable to populate Key Refresh phase (status: %d)", status); - } - - ASSERT_EQUAL(test_vector[i].phase, phase); - ASSERT_EQUAL(test_vector[i].ivu, atomic_test_bit(bt_mesh.flags, - BT_MESH_IVU_IN_PROGRESS)); - ASSERT_EQUAL(test_vector[i].ivi, bt_mesh.iv_index); - - k_sleep(K_SECONDS((BEACON_INTERVAL + 1) * 2)); - } - - PASS(); -} - -static bool beacon_confirm_by_subnet(const uint8_t *net_id, void *ctx) -{ - const uint8_t *expected_net_id = ctx; - - return !memcmp(expected_net_id, net_id, 8); -} - -static bool beacon_confirm_all_subnets(const uint8_t *net_id, void *ctx) -{ - static uint32_t counter; - int err; - - for (size_t i = 0; i < ARRAY_SIZE(net_key_pairs); i++) { - uint8_t expected_net_id[8]; - - err = bt_mesh_k3(net_key_pairs[i].secondary, expected_net_id); - if (err) { - FAIL("Unable to generate Net ID"); - } - - if (!memcmp(expected_net_id, net_id, 8)) { - LOG_INF("Received beacon for Net Key Idx %d", (i + 1)); - counter |= 1 << i; - - ASSERT_EQUAL(0x00, beacon.flags); - ASSERT_EQUAL(0x0000, beacon.iv_index); - } - } - - if (counter == BIT_MASK(ARRAY_SIZE(net_key_pairs))) { - counter = 0; - return true; - } else { - return false; - } -} - -/* Test beacons rejection with multiple Net Keys. */ -static void test_tx_multiple_netkeys(void) -{ - NET_BUF_SIMPLE_DEFINE(buf, 22); - int err; - - bt_mesh_test_cfg_set(&tx_cfg, MULT_NETKEYS_WAIT_TIME); - k_sem_init(&observer_sem, 0, 1); - - err = bt_enable(NULL); - if (err) { - FAIL("Bluetooth init failed (err %d)", err); - return; - } - - LOG_INF("Bluetooth initialized"); - - /* Let the rx node send the first beacon. */ - k_sleep(K_SECONDS(5)); - - /* The node has added new Net Keys. */ - - for (size_t i = 0; i < ARRAY_SIZE(net_key_pairs); i++) { - uint8_t net_id_secondary[8]; - - err = bt_mesh_k3(net_key_pairs[i].secondary, net_id_secondary); - if (err) { - FAIL("Unable to generate Net ID"); - } - - /* Send beacon with Key Refresh flag set to 1, but secured with the old Net Key. - * The beacon shall be processed, but shall not change Key Refresh phase. - */ - beacon_create(&buf, net_key_pairs[i].primary, 0x01, 0x0000); - send_beacon(&buf); - ASSERT_FALSE(wait_for_beacon(beacon_confirm_by_subnet, &buf.data[2])); - ASSERT_TRUE(wait_for_beacon(beacon_confirm_by_subnet, &buf.data[2])); - ASSERT_EQUAL(0x00, beacon.flags); - ASSERT_EQUAL(0x0000, beacon.iv_index); - - /* Do the same, but secure beacon with the new Net Key. The node shall set Key - * Refresh phase to 2. - */ - beacon_create(&buf, net_key_pairs[i].secondary, 0x01, 0x0000); - send_beacon(&buf); - ASSERT_FALSE(wait_for_beacon(beacon_confirm_by_subnet, net_id_secondary)); - ASSERT_TRUE(wait_for_beacon(beacon_confirm_by_subnet, net_id_secondary)); - ASSERT_EQUAL(0x01, beacon.flags); - ASSERT_EQUAL(0x0000, beacon.iv_index); - - /* Send beacon with Key Refresh flag set to 0, but secured with the old Net Key. - * The beacon shall be rejected. The beacon interval shall not be changed. - */ - beacon_create(&buf, net_key_pairs[i].primary, 0x00, 0x0000); - send_beacon(&buf); - ASSERT_TRUE(wait_for_beacon(beacon_confirm_by_subnet, net_id_secondary)); - ASSERT_TRUE(wait_for_beacon(beacon_confirm_by_subnet, net_id_secondary)); - ASSERT_EQUAL(0x01, beacon.flags); - ASSERT_EQUAL(0x0000, beacon.iv_index); - - /* Do the same with the new Net Key. Now the node shall change Key Refresh phase - * to 0. The beacon interval shall be increased. - */ - beacon_create(&buf, net_key_pairs[i].secondary, 0x00, 0x0000); - send_beacon(&buf); - ASSERT_FALSE(wait_for_beacon(beacon_confirm_by_subnet, net_id_secondary)); - ASSERT_TRUE(wait_for_beacon(beacon_confirm_by_subnet, net_id_secondary)); - ASSERT_EQUAL(0x00, beacon.flags); - ASSERT_EQUAL(0x0000, beacon.iv_index); - } - - /* Create a valid beacon secured with unknown Net Key. The node shall ignore the beacon and - * continue sending beacons regularly. - */ - uint8_t unknown_net_key[16] = { 0xde, 0xad, 0xbe, 0xef }; - - beacon_create(&buf, unknown_net_key, 0x00, 0x0000); - send_beacon(&buf); - /* Ensure that interval is not affected. */ - ASSERT_TRUE(wait_for_beacon(beacon_confirm_all_subnets, NULL)); - ASSERT_TRUE(wait_for_beacon(beacon_confirm_all_subnets, NULL)); - - PASS(); -} - -/* Test beacons rejection with multiple Net Keys. */ -static void test_rx_multiple_netkeys(void) -{ - uint8_t phase; - uint8_t status; - int err; - - bt_mesh_test_cfg_set(&rx_cfg, MULT_NETKEYS_WAIT_TIME); - bt_mesh_test_setup(); - bt_mesh_iv_update_test(true); - - /* Add new Net Keys and switch Key Refresh phase to 1 so that beacons can trigger Key - * Refresh procedure. - */ - for (size_t i = 0; i < ARRAY_SIZE(net_key_pairs); i++) { - err = bt_mesh_cfg_cli_net_key_add(0, cfg->addr, i + 1, net_key_pairs[i].primary, - &status); - if (err || status) { - FAIL("Net Key add failed (err %d, status %u)", err, status); - } - - err = bt_mesh_cfg_cli_net_key_update(0, cfg->addr, i + 1, - net_key_pairs[i].secondary, &status); - if (err || status) { - FAIL("Net Key update failed (err %d, status %u)", err, status); - } - } - - for (size_t i = 0; i < ARRAY_SIZE(net_key_pairs); i++) { - /* Tx device shall change Key Refresh phase to 2. */ - k_sleep(K_SECONDS(40)); - - status = bt_mesh_subnet_kr_phase_get(i + 1, &phase); - if (status != STATUS_SUCCESS) { - FAIL("Unable to populate Key Refresh phase (status: %d)", status); - } - - ASSERT_EQUAL(BT_MESH_KR_PHASE_2, phase); - - /* Tx device shall change Key Refresh phase to 0. */ - k_sleep(K_SECONDS(40)); - - status = bt_mesh_subnet_kr_phase_get(i + 1, &phase); - if (status != STATUS_SUCCESS) { - FAIL("Unable to populate Key Refresh phase (status: %d)", status); - } - - ASSERT_EQUAL(BT_MESH_KR_NORMAL, phase); - } - - PASS(); - -} - -static struct k_work_delayable beacon_timer; - -static void secure_beacon_send(struct k_work *work) -{ - NET_BUF_SIMPLE_DEFINE(buf, 22); - beacon_create(&buf, test_net_key, 0, 0); - send_beacon(&buf); - /** - * Sending SNB(secure network beacon) faster to guarantee - * at least one beacon is received by tx node in 10s period. - */ - k_work_schedule(&beacon_timer, K_SECONDS(2)); -} - -static void test_tx_secure_beacon_interval(void) -{ - bt_mesh_test_cfg_set(&tx_cfg, BEACON_INTERVAL_WAIT_TIME); - k_sleep(K_SECONDS(2)); - bt_mesh_test_setup(); - PASS(); -} - -static void test_rx_secure_beacon_interval(void) -{ - NET_BUF_SIMPLE_DEFINE(buf, 22); - int err; - int64_t beacon_recv_time; - int64_t delta; - - bt_mesh_test_cfg_set(&rx_cfg, BEACON_INTERVAL_WAIT_TIME); - k_sem_init(&observer_sem, 0, 1); - k_work_init_delayable(&beacon_timer, secure_beacon_send); - - err = bt_enable(NULL); - if (err) { - FAIL("Bluetooth init failed (err %d)", err); - } - - beacon_create(&buf, test_net_key, 0, 0); - k_sleep(K_SECONDS(5)); - /*wait provisioned tx node to send the first beacon*/ - ASSERT_TRUE(wait_for_beacon(NULL, NULL)); - k_sleep(K_SECONDS(2)); - - /** - * Sending 2 SNB 20ms apart by only sending for even values of loop variable. - * And verify that tx node adapts to 20s SNB interval after sending enough - * beacons in for loop. - */ - for (size_t i = 1; i < 5; i++) { - if (i % 2) { - send_beacon(&buf); - ASSERT_FALSE(wait_for_beacon(NULL, NULL)); - } else { - ASSERT_TRUE(wait_for_beacon(NULL, NULL)); - } - } - - /** - * Verify that tx node keeps the 20s SNB interval until adapts itself and - * sends SNB in 10s again. - */ - ASSERT_FALSE(wait_for_beacon(NULL, NULL)); - ASSERT_TRUE(wait_for_beacon(NULL, NULL)); - ASSERT_TRUE(wait_for_beacon(NULL, NULL)); - beacon_recv_time = k_uptime_get(); - /* Start sending SNB */ - k_work_schedule(&beacon_timer, K_NO_WAIT); - - /** - * Send SNB so that the tx node stays silent and eventually sends - * an SNB after 600s, which is the maximum time for SNB interval. - * Sending beacon with 2sec interval. - */ - delta = 0; - for (size_t i = 0; i < 60; i++) { - if (wait_for_beacon(NULL, NULL)) { - delta = k_uptime_delta(&beacon_recv_time); - break; - } - } - - ASSERT_TRUE(delta >= (600 * MSEC_PER_SEC)); - PASS(); -} - -#define TEST_CASE(role, name, description) \ - { \ - .test_id = "beacon_" #role "_" #name, \ - .test_descr = description, \ - .test_pre_init_f = test_##role##_init, \ - .test_tick_f = bt_mesh_test_timeout, \ - .test_main_f = test_##role##_##name, \ - } - -static const struct bst_test_instance test_beacon[] = { - TEST_CASE(tx, on_iv_update, "Beacon: send on IV update"), - TEST_CASE(tx, on_key_refresh, "Beacon: send on key refresh"), - TEST_CASE(tx, invalid, "Beacon: send invalid beacon"), - TEST_CASE(tx, kr_old_key, "Beacon: send old Net Key"), - TEST_CASE(tx, multiple_netkeys, "Beacon: multiple Net Keys"), - TEST_CASE(tx, secure_beacon_interval, "Beacon: send secure beacons"), - - TEST_CASE(rx, on_iv_update, "Beacon: receive with IV update flag"), - TEST_CASE(rx, on_key_refresh, "Beacon: receive with key refresh flag"), - TEST_CASE(rx, invalid, "Beacon: receive invalid beacon"), - TEST_CASE(rx, kr_old_key, "Beacon: receive old Net Key"), - TEST_CASE(rx, multiple_netkeys, "Beacon: multiple Net Keys"), - TEST_CASE(rx, secure_beacon_interval, "Beacon: receive and send secure beacons"), - BSTEST_END_MARKER -}; - -struct bst_test_list *test_beacon_install(struct bst_test_list *tests) -{ - tests = bst_add_tests(tests, test_beacon); - return tests; -} diff --git a/tests/bluetooth/bsim/mesh/src/test_blob.c b/tests/bluetooth/bsim/mesh/src/test_blob.c deleted file mode 100644 index 9e299e71771..00000000000 --- a/tests/bluetooth/bsim/mesh/src/test_blob.c +++ /dev/null @@ -1,1417 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include "mesh_test.h" -#include "dfu_blob_common.h" -#include "mesh/blob.h" -#include "argparse.h" -#include "mesh/adv.h" - -#define LOG_MODULE_NAME test_blob - -#include -LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL_INF); - -#define BLOB_GROUP_ADDR 0xc000 -#define BLOB_CLI_ADDR 0x0001 -#define SYNC_CHAN 0 -#define CLI_DEV 0 -#define SRV1_DEV 1 -#define IMPOSTER_MODEL_ID 0xe000 - -static bool is_pull_mode; -static enum { - BLOCK_GET_FAIL = 0, - XFER_GET_FAIL = 1 -} msg_fail_type; - -static void test_args_parse(int argc, char *argv[]) -{ - bs_args_struct_t args_struct[] = { - { - .dest = &is_pull_mode, - .type = 'b', - .name = "{0, 1}", - .option = "use-pull-mode", - .descript = "Set transfer type to pull mode" - }, - { - .dest = &msg_fail_type, - .type = 'i', - .name = "{0, 1}", - .option = "msg-fail-type", - .descript = "Message type to fail on" - }, - }; - - bs_args_parse_all_cmd_line(argc, argv, args_struct); -} - -static int blob_io_open(const struct bt_mesh_blob_io *io, - const struct bt_mesh_blob_xfer *xfer, - enum bt_mesh_blob_io_mode mode) -{ - return 0; -} - -static struct k_sem first_block_wr_sem; -static uint16_t partial_block; -ATOMIC_DEFINE(block_bitfield, 8); - -static int blob_chunk_wr(const struct bt_mesh_blob_io *io, - const struct bt_mesh_blob_xfer *xfer, - const struct bt_mesh_blob_block *block, - const struct bt_mesh_blob_chunk *chunk) -{ - partial_block += chunk->size; - ASSERT_TRUE(partial_block <= block->size, "Received block is too large"); - - - if (partial_block == block->size) { - partial_block = 0; - ASSERT_FALSE(atomic_test_and_set_bit(block_bitfield, block->number), - "Received duplicate block"); - } - - if (atomic_test_bit(block_bitfield, 0)) { - k_sem_give(&first_block_wr_sem); - } - - return 0; -} - -static int blob_chunk_rd(const struct bt_mesh_blob_io *io, - const struct bt_mesh_blob_xfer *xfer, - const struct bt_mesh_blob_block *block, - const struct bt_mesh_blob_chunk *chunk) -{ - memset(chunk->data, 0, chunk->size); - - return 0; -} - -static const struct bt_mesh_blob_io blob_io = { - .open = blob_io_open, - .rd = blob_chunk_rd, - .wr = blob_chunk_wr, -}; - -static uint8_t dev_key[16] = { 0xdd }; -static uint8_t app_key[16] = { 0xaa }; -static uint8_t net_key[16] = { 0xcc }; -static struct bt_mesh_prov prov; - -static struct { - struct bt_mesh_blob_cli_inputs inputs; - struct bt_mesh_blob_target targets[5]; - struct bt_mesh_blob_target_pull pull[5]; - uint8_t target_count; - struct bt_mesh_blob_xfer xfer; -} blob_cli_xfer; - -static struct k_sem blob_caps_sem; - -static void blob_cli_caps(struct bt_mesh_blob_cli *b, const struct bt_mesh_blob_cli_caps *caps) -{ - k_sem_give(&blob_caps_sem); - if (caps) { - ASSERT_EQUAL(caps->mtu_size, BT_MESH_RX_SDU_MAX - BT_MESH_MIC_SHORT); - ASSERT_EQUAL(caps->modes, BT_MESH_BLOB_XFER_MODE_ALL); - ASSERT_EQUAL(caps->max_size, CONFIG_BT_MESH_BLOB_SIZE_MAX); - ASSERT_EQUAL(caps->min_block_size_log, BLOB_BLOCK_SIZE_LOG_MIN); - ASSERT_EQUAL(caps->max_block_size_log, BLOB_BLOCK_SIZE_LOG_MAX); - ASSERT_EQUAL(caps->max_chunk_size, BLOB_CHUNK_SIZE_MAX(BT_MESH_RX_SDU_MAX)); - ASSERT_EQUAL(caps->max_chunks, CONFIG_BT_MESH_BLOB_CHUNK_COUNT_MAX); - } -} - -static struct k_sem lost_target_sem; - -static void blob_cli_lost_target(struct bt_mesh_blob_cli *b, struct bt_mesh_blob_target *blobt, - enum bt_mesh_blob_status reason) -{ - ASSERT_FALSE(reason == BT_MESH_BLOB_SUCCESS); - ASSERT_TRUE(lost_target_find_and_remove(blobt->addr)); - - if (!lost_targets_rem()) { - k_sem_give(&lost_target_sem); - } -} - -static struct k_sem blob_cli_suspend_sem; - -static void blob_cli_suspended(struct bt_mesh_blob_cli *b) -{ - k_sem_give(&blob_cli_suspend_sem); -} - -static struct k_sem blob_cli_end_sem; -static bool cli_end_success; - -static void blob_cli_end(struct bt_mesh_blob_cli *b, const struct bt_mesh_blob_xfer *xfer, - bool success) -{ - cli_end_success = success; - k_sem_give(&blob_cli_end_sem); -} - -static struct k_sem blob_srv_suspend_sem; - -static void blob_srv_suspended(struct bt_mesh_blob_srv *b) -{ - k_sem_give(&blob_srv_suspend_sem); -} - -static struct k_sem blob_srv_end_sem; - -static void blob_srv_end(struct bt_mesh_blob_srv *b, uint64_t id, bool success) -{ - k_sem_give(&blob_srv_end_sem); -} - -static int blob_srv_recover(struct bt_mesh_blob_srv *b, struct bt_mesh_blob_xfer *xfer, - const struct bt_mesh_blob_io **io) -{ - return 0; -} - -static int blob_srv_start(struct bt_mesh_blob_srv *srv, struct bt_mesh_msg_ctx *ctx, - struct bt_mesh_blob_xfer *xfer) -{ - return 0; -} - -static void blob_srv_resume(struct bt_mesh_blob_srv *srv) -{ -} - -static const struct bt_mesh_blob_srv_cb blob_srv_cb = { - .suspended = blob_srv_suspended, - .end = blob_srv_end, - .recover = blob_srv_recover, - .start = blob_srv_start, - .resume = blob_srv_resume, -}; -static const struct bt_mesh_blob_cli_cb blob_cli_handlers = { - .caps = blob_cli_caps, - .lost_target = blob_cli_lost_target, - .suspended = blob_cli_suspended, - .end = blob_cli_end, -}; -static struct bt_mesh_blob_srv blob_srv = { .cb = &blob_srv_cb }; -static struct bt_mesh_blob_cli blob_cli = { .cb = &blob_cli_handlers }; -static struct bt_mesh_cfg_cli cfg_cli; -static struct bt_mesh_sar_cfg_cli sar_cfg_cli; - -static const struct bt_mesh_comp srv_comp = { - .elem = - (struct bt_mesh_elem[]){ - BT_MESH_ELEM(1, - MODEL_LIST(BT_MESH_MODEL_CFG_SRV, - BT_MESH_MODEL_CFG_CLI(&cfg_cli), - BT_MESH_MODEL_SAR_CFG_SRV, - BT_MESH_MODEL_SAR_CFG_CLI(&sar_cfg_cli), - BT_MESH_MODEL_BLOB_SRV(&blob_srv)), - BT_MESH_MODEL_NONE), - }, - .elem_count = 1, -}; - -static const struct bt_mesh_comp cli_comp = { - .elem = - (struct bt_mesh_elem[]){ - BT_MESH_ELEM(1, - MODEL_LIST(BT_MESH_MODEL_CFG_SRV, - BT_MESH_MODEL_CFG_CLI(&cfg_cli), - BT_MESH_MODEL_SAR_CFG_SRV, - BT_MESH_MODEL_SAR_CFG_CLI(&sar_cfg_cli), - BT_MESH_MODEL_BLOB_CLI(&blob_cli)), - BT_MESH_MODEL_NONE), - }, - .elem_count = 1, -}; - -static struct k_sem info_get_sem; - -static int mock_handle_info_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) -{ - k_sem_give(&info_get_sem); - return 0; -} - -static const struct bt_mesh_model_op model_op1[] = { - { BT_MESH_BLOB_OP_INFO_GET, 0, mock_handle_info_get }, - BT_MESH_MODEL_OP_END -}; - -static const struct bt_mesh_comp none_rsp_srv_comp = { - .elem = - (struct bt_mesh_elem[]){ - BT_MESH_ELEM(1, - MODEL_LIST(BT_MESH_MODEL_CFG_SRV, - BT_MESH_MODEL_CFG_CLI(&cfg_cli), - BT_MESH_MODEL_SAR_CFG_SRV, - BT_MESH_MODEL_SAR_CFG_CLI(&sar_cfg_cli), - BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_BLOB_SRV, - model_op1, NULL, NULL, NULL)), - BT_MESH_MODEL_NONE), - }, - .elem_count = 1, -}; - -static void provision(uint16_t addr) -{ - int err; - - err = bt_mesh_provision(net_key, 0, 0, 0, addr, dev_key); - if (err) { - FAIL("Provisioning failed (err %d)", err); - return; - } -} - -static void common_configure(uint16_t addr) -{ - uint8_t status; - int err; - - err = bt_mesh_cfg_cli_app_key_add(0, addr, 0, 0, app_key, &status); - if (err || status) { - FAIL("AppKey add failed (err %d, status %u)", err, status); - return; - } -} - -static void blob_srv_prov_and_conf(uint16_t addr) -{ - uint8_t status; - int err; - - provision(addr); - common_configure(addr); - - err = bt_mesh_cfg_cli_mod_app_bind(0, addr, addr, 0, BT_MESH_MODEL_ID_BLOB_SRV, &status); - if (err || status) { - FAIL("Model %#4x bind failed (err %d, status %u)", BT_MESH_MODEL_ID_BLOB_SRV, err, - status); - return; - } - - err = bt_mesh_cfg_cli_mod_sub_add(0, addr, addr, BLOB_GROUP_ADDR, BT_MESH_MODEL_ID_BLOB_SRV, - &status); - if (err || status) { - FAIL("Model %#4x sub add failed (err %d, status %u)", BT_MESH_MODEL_ID_BLOB_SRV, - err, status); - return; - } - - common_sar_conf(addr); -} - -static void blob_cli_prov_and_conf(uint16_t addr) -{ - uint8_t status; - int err; - - provision(addr); - common_configure(addr); - - err = bt_mesh_cfg_cli_mod_app_bind(0, addr, addr, 0, BT_MESH_MODEL_ID_BLOB_CLI, &status); - if (err || status) { - FAIL("Model %#4x bind failed (err %d, status %u)", BT_MESH_MODEL_ID_BLOB_CLI, err, - status); - return; - } - - common_sar_conf(addr); -} - -static void blob_cli_inputs_prepare(uint16_t group) -{ - blob_cli_xfer.inputs.ttl = BT_MESH_TTL_DEFAULT; - blob_cli_xfer.inputs.group = group; - blob_cli_xfer.inputs.app_idx = 0; - sys_slist_init(&blob_cli_xfer.inputs.targets); - - for (int i = 0; i < blob_cli_xfer.target_count; ++i) { - /* Reset target context. */ - uint16_t addr = blob_cli_xfer.targets[i].addr; - - memset(&blob_cli_xfer.targets[i], 0, sizeof(struct bt_mesh_blob_target)); - blob_cli_xfer.targets[i].addr = addr; - blob_cli_xfer.targets[i].pull = &blob_cli_xfer.pull[i]; - - sys_slist_append(&blob_cli_xfer.inputs.targets, &blob_cli_xfer.targets[i].n); - } -} - -static struct bt_mesh_blob_target *target_srv_add(uint16_t addr, bool expect_lost) -{ - if (expect_lost) { - lost_target_add(addr); - } - - ASSERT_TRUE(blob_cli_xfer.target_count < ARRAY_SIZE(blob_cli_xfer.targets)); - struct bt_mesh_blob_target *t = &blob_cli_xfer.targets[blob_cli_xfer.target_count]; - - t->addr = addr; - blob_cli_xfer.target_count++; - return t; -} - -static void cli_caps_common_procedure(bool lost_targets) -{ - int err; - - bt_mesh_test_cfg_set(NULL, 60); - bt_mesh_device_setup(&prov, &cli_comp); - blob_cli_prov_and_conf(BLOB_CLI_ADDR); - - blob_cli_inputs_prepare(BLOB_GROUP_ADDR); - k_sem_init(&blob_caps_sem, 0, 1); - k_sem_init(&lost_target_sem, 0, 1); - - err = bt_mesh_blob_cli_caps_get(&blob_cli, &blob_cli_xfer.inputs); - if (err) { - FAIL("Boundary check start failed (err: %d)", err); - } - - if (lost_targets) { - if (k_sem_take(&lost_target_sem, K_SECONDS(60))) { - FAIL("Lost targets CB did not trigger for all expected lost targets"); - } - } - - if (k_sem_take(&blob_caps_sem, K_SECONDS(60))) { - FAIL("Caps CB did not trigger at the end of caps procedure"); - } -} - -static void test_cli_caps_all_rsp(void) -{ - struct bt_mesh_blob_target *srv1 = target_srv_add(BLOB_CLI_ADDR + 1, false); - struct bt_mesh_blob_target *srv2 = target_srv_add(BLOB_CLI_ADDR + 2, false); - - cli_caps_common_procedure(false); - - ASSERT_TRUE(srv1->acked); - ASSERT_FALSE(srv1->timedout); - ASSERT_TRUE(srv2->acked); - ASSERT_FALSE(srv2->timedout); - - PASS(); -} - -static void test_cli_caps_partial_rsp(void) -{ - struct bt_mesh_blob_target *srv1 = target_srv_add(BLOB_CLI_ADDR + 1, false); - struct bt_mesh_blob_target *srv2 = target_srv_add(BLOB_CLI_ADDR + 2, true); - - cli_caps_common_procedure(true); - - ASSERT_TRUE(srv1->acked); - ASSERT_FALSE(srv1->timedout); - ASSERT_FALSE(srv2->acked); - ASSERT_TRUE(srv2->timedout); - - PASS(); -} - -static void test_cli_caps_no_rsp(void) -{ - struct bt_mesh_blob_target *srv1 = target_srv_add(BLOB_CLI_ADDR + 1, true); - struct bt_mesh_blob_target *srv2 = target_srv_add(BLOB_CLI_ADDR + 2, true); - - cli_caps_common_procedure(true); - - ASSERT_FALSE(srv1->acked); - ASSERT_TRUE(srv1->timedout); - ASSERT_FALSE(srv2->acked); - ASSERT_TRUE(srv2->timedout); - - PASS(); -} - -static void test_cli_caps_cancelled(void) -{ - int err; - - bt_mesh_test_cfg_set(NULL, 300); - bt_mesh_device_setup(&prov, &cli_comp); - blob_cli_prov_and_conf(BLOB_CLI_ADDR); - - struct bt_mesh_blob_target *srv1 = target_srv_add(BLOB_CLI_ADDR + 1, false); - struct bt_mesh_blob_target *srv2 = target_srv_add(BLOB_CLI_ADDR + 2, true); - - blob_cli_inputs_prepare(BLOB_GROUP_ADDR); - - k_sem_init(&blob_caps_sem, 0, 1); - k_sem_init(&lost_target_sem, 0, 1); - - /* Start first caps procedure */ - err = bt_mesh_blob_cli_caps_get(&blob_cli, &blob_cli_xfer.inputs); - if (err) { - FAIL("Boundary check start failed (err: %d)", err); - } - - /* Let first caps procedure run for a little while */ - k_sleep(K_SECONDS(15)); - - /* Cancel first caps procedure */ - bt_mesh_blob_cli_cancel(&blob_cli); - ASSERT_EQUAL(blob_cli.state, BT_MESH_BLOB_CLI_STATE_NONE); - - /* Wait and assure that caps procedure is canceled */ - if (!k_sem_take(&blob_caps_sem, K_SECONDS(60))) { - FAIL("Caps CB triggered unexpectedly"); - } - - /* Expect that the responsive srv responded, while the */ - /* unresponsive srv has not yet timed out due to cancel call */ - ASSERT_TRUE(srv1->acked); - ASSERT_FALSE(srv1->timedout); - ASSERT_FALSE(srv2->acked); - ASSERT_FALSE(srv2->timedout); - - /* Start second caps procedure and verify that it completes as expected*/ - blob_cli_inputs_prepare(BLOB_GROUP_ADDR); - err = bt_mesh_blob_cli_caps_get(&blob_cli, &blob_cli_xfer.inputs); - if (err) { - FAIL("Boundary check start failed (err: %d)", err); - } - - if (k_sem_take(&blob_caps_sem, K_SECONDS(60))) { - FAIL("Caps CB did not trigger at the end of second caps procedure"); - } - - if (k_sem_take(&lost_target_sem, K_NO_WAIT)) { - FAIL("Lost targets CB did not trigger for all expeted lost targets"); - } - - ASSERT_TRUE(srv1->acked); - ASSERT_FALSE(srv1->timedout); - ASSERT_FALSE(srv2->acked); - ASSERT_TRUE(srv2->timedout); - - PASS(); -} - -static void test_srv_caps_standard(void) -{ - bt_mesh_test_cfg_set(NULL, 140); - bt_mesh_device_setup(&prov, &srv_comp); - blob_srv_prov_and_conf(bt_mesh_test_own_addr_get(BLOB_CLI_ADDR)); - - PASS(); -} - -static void test_srv_caps_no_rsp(void) -{ - bt_mesh_test_cfg_set(NULL, 60); - bt_mesh_device_setup(&prov, &none_rsp_srv_comp); - blob_srv_prov_and_conf(bt_mesh_test_own_addr_get(BLOB_CLI_ADDR)); - - k_sem_init(&info_get_sem, 0, 1); - - /* Checks that the client performs correct amount of retransmit attempts */ - for (size_t j = 0; j < CONFIG_BT_MESH_BLOB_CLI_BLOCK_RETRIES; j++) { - int err = k_sem_take(&info_get_sem, K_SECONDS(15)); - - if (err) { - FAIL("Failed to receive expected number of info get messages from cli" - "(expected: %d, got %d)", CONFIG_BT_MESH_BLOB_CLI_BLOCK_RETRIES, j); - } - } - - PASS(); -} - -static struct k_sem blob_broad_send_sem; -static bool broadcast_tx_complete_auto; - -static void broadcast_send(struct bt_mesh_blob_cli *b, uint16_t dst) -{ - ASSERT_EQUAL(BLOB_GROUP_ADDR, dst); - k_sem_give(&blob_broad_send_sem); - if (broadcast_tx_complete_auto) { - /* Mocks completion of transmission to trigger retransmit timer */ - blob_cli_broadcast_tx_complete(&blob_cli); - } -} - -static struct k_sem blob_broad_next_sem; - -static void broadcast_next(struct bt_mesh_blob_cli *b) -{ - k_sem_give(&blob_broad_next_sem); -} - -static void test_cli_broadcast_basic(void) -{ - bt_mesh_test_cfg_set(NULL, 300); - bt_mesh_device_setup(&prov, &cli_comp); - blob_cli_prov_and_conf(BLOB_CLI_ADDR); - - struct bt_mesh_blob_target *srv1 = target_srv_add(BLOB_CLI_ADDR + 1, false); - struct bt_mesh_blob_target *srv2 = target_srv_add(BLOB_CLI_ADDR + 2, false); - - struct blob_cli_broadcast_ctx tx = { - .send = broadcast_send, - .next = broadcast_next, - .acked = true, - .optional = false, - }; - - broadcast_tx_complete_auto = false; - k_sem_init(&blob_broad_send_sem, 0, 1); - k_sem_init(&blob_broad_next_sem, 0, 1); - - blob_cli.inputs = &blob_cli_xfer.inputs; - blob_cli_inputs_prepare(BLOB_GROUP_ADDR); - - /* Call broadcast and expect send CB to trigger */ - blob_cli_broadcast(&blob_cli, &tx); - if (k_sem_take(&blob_broad_send_sem, K_SECONDS(15))) { - FAIL("Broadcast did not trigger send CB"); - } - - ASSERT_FALSE(srv1->acked); - ASSERT_FALSE(srv2->acked); - - /* Run tx complete with two missing responses */ - blob_cli_broadcast_tx_complete(&blob_cli); - if (k_sem_take(&blob_broad_send_sem, K_SECONDS(15))) { - FAIL("Tx_complete did not trigger send CB after timeout"); - } - - ASSERT_FALSE(srv1->acked); - ASSERT_FALSE(srv2->acked); - - /* Mock rsp from first target server */ - /* Run tx complete with one missing response */ - blob_cli_broadcast_rsp(&blob_cli, srv1); - blob_cli_broadcast_tx_complete(&blob_cli); - if (k_sem_take(&blob_broad_send_sem, K_SECONDS(15))) { - FAIL("Tx_complete did not trigger send CB after timeout"); - } - - ASSERT_TRUE(srv1->acked); - ASSERT_FALSE(srv2->acked); - - /* Mock rsp from second target server */ - /* Run tx complete with response from all targets */ - blob_cli_broadcast_tx_complete(&blob_cli); - blob_cli_broadcast_rsp(&blob_cli, srv2); - if (k_sem_take(&blob_broad_next_sem, K_SECONDS(15))) { - FAIL("Tx_complete did not trigger next CB after timeout"); - } - - ASSERT_TRUE(srv1->acked); - ASSERT_TRUE(srv2->acked); - - /* Verify that a single broadcast call triggers a single send CB */ - k_sem_init(&blob_broad_send_sem, 0, 2); - (void)target_srv_add(BLOB_CLI_ADDR + 3, false); - - blob_cli_inputs_prepare(BLOB_GROUP_ADDR); - - blob_cli_broadcast(&blob_cli, &tx); - k_sleep(K_SECONDS(80)); - - ASSERT_EQUAL(k_sem_count_get(&blob_broad_send_sem), 1); - - PASS(); -} - -static void test_cli_broadcast_trans(void) -{ - bt_mesh_test_cfg_set(NULL, 150); - bt_mesh_device_setup(&prov, &cli_comp); - blob_cli_prov_and_conf(BLOB_CLI_ADDR); - - struct bt_mesh_blob_target *srv1 = target_srv_add(BLOB_CLI_ADDR + 1, true); - - struct blob_cli_broadcast_ctx tx = { - .send = broadcast_send, - .next = broadcast_next, - .acked = true, - .optional = false - }; - - broadcast_tx_complete_auto = true; - k_sem_init(&blob_broad_send_sem, 0, 1); - k_sem_init(&blob_broad_next_sem, 0, 1); - k_sem_init(&lost_target_sem, 0, 1); - - blob_cli.inputs = &blob_cli_xfer.inputs; - - /* Run acked broadcast */ - blob_cli_inputs_prepare(BLOB_GROUP_ADDR); - - blob_cli_broadcast(&blob_cli, &tx); - - /* Checks that the client performs correct amount of retransmit attempts */ - for (size_t j = 0; j < CONFIG_BT_MESH_BLOB_CLI_BLOCK_RETRIES; j++) { - if (k_sem_take(&blob_broad_send_sem, K_SECONDS(15))) { - FAIL("Wrong number of attempted transmissions from blob cli" - "(expected: %d, got %d)", - CONFIG_BT_MESH_BLOB_CLI_BLOCK_RETRIES, j); - } - } - - if (k_sem_take(&blob_broad_next_sem, K_SECONDS(15))) { - FAIL("Broadcast did not trigger next CB after retransmisson ran out of attempts"); - } - - if (k_sem_take(&lost_target_sem, K_NO_WAIT)) { - FAIL("Lost targets CB did not trigger for all expected lost targets"); - } - - ASSERT_TRUE(srv1->timedout); - - /* Re-run with unacked broadcast */ - tx.acked = false; - blob_cli_inputs_prepare(BLOB_GROUP_ADDR); - - /* Call broadcast and expect send CB to trigger once*/ - blob_cli_broadcast(&blob_cli, &tx); - if (k_sem_take(&blob_broad_send_sem, K_NO_WAIT)) { - FAIL("Broadcast did not trigger send CB"); - } - - if (k_sem_take(&blob_broad_next_sem, K_NO_WAIT)) { - FAIL("Broadcast did not trigger next CB"); - } - - /* Lost target CB should not trigger for unacked broadcast */ - if (!k_sem_take(&lost_target_sem, K_NO_WAIT)) { - FAIL("Lost targets CB triggered unexpectedly"); - } - - ASSERT_FALSE(srv1->timedout); - - /* Re-run with optional flag */ - tx.acked = true; - tx.optional = true; - blob_cli_inputs_prepare(BLOB_GROUP_ADDR); - - blob_cli_broadcast(&blob_cli, &tx); - - for (size_t j = 0; j < CONFIG_BT_MESH_BLOB_CLI_BLOCK_RETRIES; j++) { - if (k_sem_take(&blob_broad_send_sem, K_SECONDS(15))) { - FAIL("Wrong number of attempted transmissions from blob cli" - "(expected: %d, got %d)", - CONFIG_BT_MESH_BLOB_CLI_BLOCK_RETRIES, j); - } - } - - if (k_sem_take(&blob_broad_next_sem, K_SECONDS(15))) { - FAIL("Broadcast did not trigger next CB"); - } - - /* Lost target CB should not trigger for optional broadcast */ - if (!k_sem_take(&lost_target_sem, K_NO_WAIT)) { - FAIL("Lost targets CB triggered unexpectedly"); - } - - ASSERT_FALSE(srv1->timedout); - - PASS(); -} - -static uint16_t dst_addr_last; -static struct k_sem blob_broad_send_uni_sem; - -static void broadcast_uni_send(struct bt_mesh_blob_cli *b, uint16_t dst) -{ - dst_addr_last = dst; - k_sem_give(&blob_broad_send_uni_sem); - if (broadcast_tx_complete_auto) { - /* Mocks completion of transmission to trigger retransmit timer */ - blob_cli_broadcast_tx_complete(&blob_cli); - } -} - -static void test_cli_broadcast_unicast_seq(void) -{ - bt_mesh_test_cfg_set(NULL, 60); - bt_mesh_device_setup(&prov, &cli_comp); - blob_cli_prov_and_conf(BLOB_CLI_ADDR); - - struct bt_mesh_blob_target *srv1 = target_srv_add(BLOB_CLI_ADDR + 1, false); - struct bt_mesh_blob_target *srv2 = target_srv_add(BLOB_CLI_ADDR + 2, false); - - struct blob_cli_broadcast_ctx tx = { - .send = broadcast_uni_send, - .next = broadcast_next, - .acked = true, - .optional = false, - }; - - k_sem_init(&blob_broad_send_uni_sem, 0, 1); - k_sem_init(&blob_broad_next_sem, 0, 1); - - blob_cli.inputs = &blob_cli_xfer.inputs; - broadcast_tx_complete_auto = false; - - /** Two responsive targets. Checks that: - * - Send CB alternates between targets - * - Don't retransmit to responded targets - * - Next CB is called as soon as all have responded - * (Test assumes at least 5 transmission attempts) - */ - BUILD_ASSERT(CONFIG_BT_MESH_BLOB_CLI_BLOCK_RETRIES >= 5); - - blob_cli_inputs_prepare(BT_MESH_ADDR_UNASSIGNED); - blob_cli_broadcast(&blob_cli, &tx); - - for (size_t i = 0; i < 2; i++) { - if (k_sem_take(&blob_broad_send_uni_sem, K_SECONDS(10))) { - FAIL("Broadcast did not trigger send CB"); - } - - ASSERT_EQUAL(BLOB_CLI_ADDR + 1, dst_addr_last); - blob_cli_broadcast_tx_complete(&blob_cli); - if (k_sem_take(&blob_broad_send_uni_sem, K_SECONDS(10))) { - FAIL("Tx complete did not trigger send CB"); - } - - ASSERT_EQUAL(BLOB_CLI_ADDR + 2, dst_addr_last); - blob_cli_broadcast_tx_complete(&blob_cli); - } - - blob_cli_broadcast_rsp(&blob_cli, srv1); - for (size_t i = 0; i < 2; i++) { - if (k_sem_take(&blob_broad_send_uni_sem, K_SECONDS(10))) { - FAIL("Tx complete did not trigger send CB"); - } - - ASSERT_EQUAL(BLOB_CLI_ADDR + 2, dst_addr_last); - blob_cli_broadcast_tx_complete(&blob_cli); - } - - blob_cli_broadcast_rsp(&blob_cli, srv2); - if (!k_sem_take(&blob_broad_send_uni_sem, K_SECONDS(10))) { - FAIL("Unexpected send CB"); - } - - if (k_sem_take(&blob_broad_next_sem, K_NO_WAIT)) { - FAIL("Broadcast did not trigger next CB"); - } - - PASS(); -} - -static void test_cli_broadcast_unicast(void) -{ - bt_mesh_test_cfg_set(NULL, 120); - bt_mesh_device_setup(&prov, &cli_comp); - blob_cli_prov_and_conf(BLOB_CLI_ADDR); - - (void)target_srv_add(BLOB_CLI_ADDR + 1, true); - (void)target_srv_add(BLOB_CLI_ADDR + 2, true); - - struct blob_cli_broadcast_ctx tx = { - .send = broadcast_uni_send, - .next = broadcast_next, - .acked = true, - .optional = false, - }; - - k_sem_init(&blob_broad_send_uni_sem, 0, 1); - k_sem_init(&blob_broad_next_sem, 0, 1); - k_sem_init(&lost_target_sem, 0, 1); - - blob_cli.inputs = &blob_cli_xfer.inputs; - broadcast_tx_complete_auto = true; - - /** 1. Two non-responsive targets. Checks that: - * - Next CB is called after all retransmit attempts expires - * - All lost targets is registered - */ - blob_cli_inputs_prepare(BT_MESH_ADDR_UNASSIGNED); - blob_cli_broadcast(&blob_cli, &tx); - - if (k_sem_take(&blob_broad_next_sem, K_SECONDS(60))) { - FAIL("Broadcast did not trigger next CB"); - } - - if (k_sem_take(&lost_target_sem, K_NO_WAIT)) { - FAIL("Lost targets CB did not trigger for all expected lost targets"); - } - - /** 2. Two non-responsive targets re-run. Checks that: - * - Already lost targets does not attempt new transmission - * (Next CB called immediately) - */ - blob_cli_broadcast(&blob_cli, &tx); - if (k_sem_take(&blob_broad_next_sem, K_NO_WAIT)) { - FAIL("Broadcast did not trigger immediate next CB"); - } - - /** 3. Two non-responsive targets (Abort after first attempt). Checks that: - * - First transmission calls send CB - * - After abort is called, neither send or next CB is called - */ - k_sem_init(&blob_broad_send_uni_sem, 0, 1); - blob_cli_inputs_prepare(BT_MESH_ADDR_UNASSIGNED); - blob_cli_broadcast(&blob_cli, &tx); - if (k_sem_take(&blob_broad_send_uni_sem, K_NO_WAIT)) { - FAIL("Broadcast did not trigger send CB"); - } - - blob_cli_broadcast_abort(&blob_cli); - if (!k_sem_take(&blob_broad_send_uni_sem, K_SECONDS(60))) { - FAIL("Unexpected send CB"); - } - - if (!k_sem_take(&blob_broad_next_sem, K_NO_WAIT)) { - FAIL("Unexpected next CB"); - } - - PASS(); -} - -static void test_cli_trans_complete(void) -{ - int err; - - bt_mesh_test_cfg_set(NULL, 400); - bt_mesh_device_setup(&prov, &cli_comp); - blob_cli_prov_and_conf(BLOB_CLI_ADDR); - - (void)target_srv_add(BLOB_CLI_ADDR + 1, false); - (void)target_srv_add(BLOB_CLI_ADDR + 2, false); - (void)target_srv_add(BLOB_CLI_ADDR + 3, false); - (void)target_srv_add(BLOB_CLI_ADDR + 4, false); - - k_sem_init(&blob_caps_sem, 0, 1); - k_sem_init(&lost_target_sem, 0, 1); - k_sem_init(&blob_cli_end_sem, 0, 1); - k_sem_init(&blob_cli_suspend_sem, 0, 1); - - LOG_INF("Running transfer in %s", is_pull_mode ? "Pull mode" : "Push mode"); - - blob_cli_inputs_prepare(BLOB_GROUP_ADDR); - blob_cli_xfer.xfer.mode = - is_pull_mode ? BT_MESH_BLOB_XFER_MODE_PULL : BT_MESH_BLOB_XFER_MODE_PUSH; - blob_cli_xfer.xfer.size = CONFIG_BT_MESH_BLOB_BLOCK_SIZE_MAX * 2; - blob_cli_xfer.xfer.id = 1; - blob_cli_xfer.xfer.block_size_log = 12; - blob_cli_xfer.xfer.chunk_size = 377; - blob_cli_xfer.inputs.timeout_base = 10; - - err = bt_mesh_blob_cli_send(&blob_cli, &blob_cli_xfer.inputs, - &blob_cli_xfer.xfer, &blob_io); - if (err) { - FAIL("BLOB send failed (err: %d)", err); - } - - if (k_sem_take(&blob_cli_end_sem, K_SECONDS(380))) { - FAIL("End CB did not trigger as expected for the cli"); - } - - ASSERT_TRUE(blob_cli.state == BT_MESH_BLOB_CLI_STATE_NONE); - - PASS(); -} - -static void test_srv_trans_complete(void) -{ - bt_mesh_test_cfg_set(NULL, 400); - bt_mesh_device_setup(&prov, &srv_comp); - blob_srv_prov_and_conf(bt_mesh_test_own_addr_get(BLOB_CLI_ADDR)); - - k_sem_init(&first_block_wr_sem, 0, 1); - k_sem_init(&blob_srv_end_sem, 0, 1); - k_sem_init(&blob_srv_suspend_sem, 0, 1); - - bt_mesh_blob_srv_recv(&blob_srv, 1, &blob_io, 0, 10); - - if (k_sem_take(&blob_srv_end_sem, K_SECONDS(380))) { - FAIL("End CB did not trigger as expected for the srv"); - } - - ASSERT_TRUE(blob_srv.phase == BT_MESH_BLOB_XFER_PHASE_COMPLETE); - - /* Check that all blocks is received */ - ASSERT_TRUE(atomic_test_bit(block_bitfield, 0)); - ASSERT_TRUE(atomic_test_bit(block_bitfield, 1)); - - /* Check that a third block was not received */ - ASSERT_FALSE(atomic_test_bit(block_bitfield, 2)); - - PASS(); -} - -static void test_cli_trans_resume(void) -{ - int err; - - bt_mesh_test_cfg_set(NULL, 800); - bt_mesh_device_setup(&prov, &cli_comp); - blob_cli_prov_and_conf(BLOB_CLI_ADDR); - - (void)target_srv_add(BLOB_CLI_ADDR + 1, true); - - k_sem_init(&blob_caps_sem, 0, 1); - k_sem_init(&lost_target_sem, 0, 1); - k_sem_init(&blob_cli_end_sem, 0, 1); - k_sem_init(&blob_cli_suspend_sem, 0, 1); - - LOG_INF("Running transfer in %s", is_pull_mode ? "Pull mode" : "Push mode"); - - /** Test resumption of suspended BLOB transfer (Push). - * Client initiates transfer with two blocks. After - * first block completes the server will be suspended. - * At this point the client will attempt to resume the - * transfer. - */ - blob_cli_inputs_prepare(BLOB_GROUP_ADDR); - blob_cli_xfer.xfer.mode = - is_pull_mode ? BT_MESH_BLOB_XFER_MODE_PULL : BT_MESH_BLOB_XFER_MODE_PUSH; - blob_cli_xfer.xfer.size = CONFIG_BT_MESH_BLOB_BLOCK_SIZE_MAX * 2; - blob_cli_xfer.xfer.id = 1; - blob_cli_xfer.xfer.block_size_log = 12; - blob_cli_xfer.xfer.chunk_size = 377; - blob_cli_xfer.inputs.timeout_base = 10; - - err = bt_mesh_blob_cli_send(&blob_cli, &blob_cli_xfer.inputs, - &blob_cli_xfer.xfer, &blob_io); - if (err) { - FAIL("BLOB send failed (err: %d)", err); - } - - if (k_sem_take(&blob_cli_suspend_sem, K_SECONDS(500))) { - FAIL("Suspend CB did not trigger as expected for the cli"); - } - - if (k_sem_take(&lost_target_sem, K_NO_WAIT)) { - FAIL("Lost targets CB did not trigger for the target srv"); - } - - ASSERT_TRUE(blob_cli.state == BT_MESH_BLOB_CLI_STATE_SUSPENDED); - - /* Initiate resumption of BLOB transfer */ - err = bt_mesh_blob_cli_resume(&blob_cli); - if (err) { - FAIL("BLOB resume failed (err: %d)", err); - } - - if (k_sem_take(&blob_cli_end_sem, K_SECONDS(780))) { - FAIL("End CB did not trigger as expected for the cli"); - } - - ASSERT_TRUE(blob_cli.state == BT_MESH_BLOB_CLI_STATE_NONE); - - PASS(); -} - -static void test_srv_trans_resume(void) -{ - bt_mesh_test_cfg_set(NULL, 800); - bt_mesh_device_setup(&prov, &srv_comp); - blob_srv_prov_and_conf(bt_mesh_test_own_addr_get(BLOB_CLI_ADDR)); - - k_sem_init(&first_block_wr_sem, 0, 1); - k_sem_init(&blob_srv_end_sem, 0, 1); - k_sem_init(&blob_srv_suspend_sem, 0, 1); - - /** Wait for a first blob block to be received, then simulate radio - * disruption to cause suspension of the blob srv. Re-enable the radio - * as soon as the server is suspended and wait to receive the second - * block. - */ - bt_mesh_blob_srv_recv(&blob_srv, 1, &blob_io, 0, 10); - - /* Let server receive a couple of chunks from second block before disruption */ - for (int i = 0; i < 3; i++) { - if (k_sem_take(&first_block_wr_sem, K_SECONDS(180))) { - FAIL("Server did not receive the first BLOB block"); - } - } - - bt_mesh_scan_disable(); - partial_block = 0; - if (k_sem_take(&blob_srv_suspend_sem, K_SECONDS(140))) { - FAIL("Suspend CB did not trigger as expected for the srv"); - } - - ASSERT_TRUE(blob_srv.phase == BT_MESH_BLOB_XFER_PHASE_SUSPENDED); - - /* Wait for BLOB client to suspend. Measured experimentally. */ - k_sleep(K_SECONDS(140)); - - bt_mesh_scan_enable(); - - if (k_sem_take(&blob_srv_end_sem, K_SECONDS(780))) { - FAIL("End CB did not trigger as expected for the srv"); - } - - ASSERT_TRUE(blob_srv.phase == BT_MESH_BLOB_XFER_PHASE_COMPLETE); - - /* Check that all blocks is received */ - ASSERT_TRUE(atomic_test_bit(block_bitfield, 0)); - ASSERT_TRUE(atomic_test_bit(block_bitfield, 1)); - - /* Check that a third block was not received */ - ASSERT_FALSE(atomic_test_bit(block_bitfield, 2)); - - PASS(); -} - -static void test_cli_trans_persistency_pull(void) -{ - int err; - - bt_mesh_test_cfg_set(NULL, 240); - bt_mesh_device_setup(&prov, &cli_comp); - blob_cli_prov_and_conf(BLOB_CLI_ADDR); - - (void)target_srv_add(BLOB_CLI_ADDR + 1, true); - (void)target_srv_add(BLOB_CLI_ADDR + 2, false); - - k_sem_init(&blob_caps_sem, 0, 1); - k_sem_init(&lost_target_sem, 0, 1); - k_sem_init(&blob_cli_end_sem, 0, 1); - k_sem_init(&blob_cli_suspend_sem, 0, 1); - - blob_cli_inputs_prepare(0); - blob_cli_xfer.xfer.mode = BT_MESH_BLOB_XFER_MODE_PULL; - blob_cli_xfer.xfer.size = CONFIG_BT_MESH_BLOB_BLOCK_SIZE_MIN * 3; - blob_cli_xfer.xfer.id = 1; - blob_cli_xfer.xfer.block_size_log = 8; - blob_cli_xfer.xfer.chunk_size = 36; - blob_cli_xfer.inputs.timeout_base = 10; - - err = bt_mesh_blob_cli_send(&blob_cli, &blob_cli_xfer.inputs, - &blob_cli_xfer.xfer, &blob_io); - if (err) { - FAIL("BLOB send failed (err: %d)", err); - } - - if (k_sem_take(&blob_cli_end_sem, K_SECONDS(230))) { - FAIL("End CB did not trigger as expected for the cli"); - } - - ASSERT_TRUE(blob_cli.state == BT_MESH_BLOB_CLI_STATE_NONE); - - PASS(); -} - -static void test_srv_trans_persistency_pull(void) -{ - bt_mesh_test_cfg_set(NULL, 240); - bt_mesh_device_setup(&prov, &srv_comp); - blob_srv_prov_and_conf(bt_mesh_test_own_addr_get(BLOB_CLI_ADDR)); - - k_sem_init(&first_block_wr_sem, 0, 1); - k_sem_init(&blob_srv_end_sem, 0, 1); - k_sem_init(&blob_srv_suspend_sem, 0, 1); - - bt_mesh_blob_srv_recv(&blob_srv, 1, &blob_io, 0, 10); - - /* Target with address 0x0002 (the first one) will disappear after receiving the first - * block. Target with address 0x0003 (the second one) will stay alive. - */ - if (bt_mesh_test_own_addr_get(BLOB_CLI_ADDR) == 0x0002) { - /* Let the first target receive a couple of chunks from second block before - * disruption. - */ - for (int i = 0; i < 3; i++) { - if (k_sem_take(&first_block_wr_sem, K_SECONDS(100))) { - FAIL("Server did not receive the first BLOB block"); - } - } - - bt_mesh_scan_disable(); - bt_mesh_blob_srv_cancel(&blob_srv); - PASS(); - return; - } - - if (k_sem_take(&blob_srv_end_sem, K_SECONDS(230))) { - FAIL("End CB did not trigger as expected for the srv"); - } - - ASSERT_TRUE(blob_srv.phase == BT_MESH_BLOB_XFER_PHASE_COMPLETE); - - /* Check that all blocks is received */ - ASSERT_TRUE(atomic_test_bit(block_bitfield, 0)); - ASSERT_TRUE(atomic_test_bit(block_bitfield, 1)); - ASSERT_TRUE(atomic_test_bit(block_bitfield, 2)); - - /* Check that a third block was not received */ - ASSERT_FALSE(atomic_test_bit(block_bitfield, 3)); - - PASS(); -} - -/* Makes device unresponsive after I/O is opened */ -static int fail_on_io_open(const struct bt_mesh_blob_io *io, - const struct bt_mesh_blob_xfer *xfer, - enum bt_mesh_blob_io_mode mode) -{ - bt_mesh_scan_disable(); - return 0; -} - -/* Makes device unresponsive after receiving block start msg */ -static int fail_on_block_start(const struct bt_mesh_blob_io *io, - const struct bt_mesh_blob_xfer *xfer, - const struct bt_mesh_blob_block *block) -{ - bt_mesh_scan_disable(); - return 0; -} - -static void cli_common_fail_on_init(void) -{ - bt_mesh_test_cfg_set(NULL, 800); - bt_mesh_device_setup(&prov, &cli_comp); - blob_cli_prov_and_conf(BLOB_CLI_ADDR); - - k_sem_init(&blob_caps_sem, 0, 1); - k_sem_init(&lost_target_sem, 0, 1); - k_sem_init(&blob_cli_end_sem, 0, 1); - k_sem_init(&blob_cli_suspend_sem, 0, 1); - - blob_cli_inputs_prepare(BLOB_GROUP_ADDR); - blob_cli_xfer.xfer.mode = BT_MESH_BLOB_XFER_MODE_PUSH; - blob_cli_xfer.xfer.size = CONFIG_BT_MESH_BLOB_BLOCK_SIZE_MAX * 1; - blob_cli_xfer.xfer.id = 1; - blob_cli_xfer.xfer.block_size_log = 12; - blob_cli_xfer.xfer.chunk_size = 377; - blob_cli_xfer.inputs.timeout_base = 10; -} - -static void test_cli_fail_on_persistency(void) -{ - int err; - - /** Test that Push mode BLOB transfer persists as long as at - * least one target is still active. During the test multiple - * servers will become unresponsive at different phases of the - * transfer: - * - Srv 0x0002 will not respond to Block start msg. - * - Srv 0x0003 will not respond to Block get msg. - * - Srv 0x0004 will not respond to Xfer get msg. - * - Srv 0x0005 is responsive all the way - * - Srv 0x0006 is a non-existing unresponsive node - */ - (void)target_srv_add(BLOB_CLI_ADDR + 1, true); - (void)target_srv_add(BLOB_CLI_ADDR + 2, true); - (void)target_srv_add(BLOB_CLI_ADDR + 3, true); - (void)target_srv_add(BLOB_CLI_ADDR + 4, false); - (void)target_srv_add(BLOB_CLI_ADDR + 5, true); - - cli_common_fail_on_init(); - - err = bt_mesh_blob_cli_send(&blob_cli, &blob_cli_xfer.inputs, - &blob_cli_xfer.xfer, &blob_io); - if (err) { - FAIL("BLOB send failed (err: %d)", err); - } - - if (k_sem_take(&blob_cli_end_sem, K_SECONDS(750))) { - FAIL("End CB did not trigger as expected for the cli"); - } - - ASSERT_TRUE(cli_end_success); - - if (k_sem_take(&lost_target_sem, K_NO_WAIT)) { - FAIL("Lost targets CB did not trigger for all expected lost targets"); - } - - PASS(); -} - -static void common_fail_on_srv_init(const struct bt_mesh_comp *comp) -{ - bt_mesh_test_cfg_set(NULL, 800); - bt_mesh_device_setup(&prov, comp); - blob_srv_prov_and_conf(bt_mesh_test_own_addr_get(BLOB_CLI_ADDR)); - - k_sem_init(&first_block_wr_sem, 0, 1); - k_sem_init(&blob_srv_end_sem, 0, 1); - k_sem_init(&blob_srv_suspend_sem, 0, 1); -} - -static void test_srv_fail_on_block_start(void) -{ - common_fail_on_srv_init(&srv_comp); - - static const struct bt_mesh_blob_io io = { - .open = fail_on_io_open, - .rd = blob_chunk_rd, - .wr = blob_chunk_wr, - }; - - bt_mesh_blob_srv_recv(&blob_srv, 1, &io, 0, 1); - - PASS(); -} - -static void test_srv_fail_on_block_get(void) -{ - common_fail_on_srv_init(&srv_comp); - - static const struct bt_mesh_blob_io io = { - .open = blob_io_open, - .rd = blob_chunk_rd, - .wr = blob_chunk_wr, - .block_start = fail_on_block_start, - }; - - bt_mesh_blob_srv_recv(&blob_srv, 1, &io, 0, 1); - - PASS(); -} - -static int dummy_xfer_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) -{ - return 0; -} - -static const struct bt_mesh_model_op model_op2[] = { - { BT_MESH_BLOB_OP_XFER_GET, 0, dummy_xfer_get }, - BT_MESH_MODEL_OP_END -}; - -/** Composition data for BLOB server where we intercept the - * BT_MESH_BLOB_OP_XFER_GET message handler through an imposter - * model. This is done to emulate a BLOB server that becomes - * unresponsive at the later stage of a BLOB transfer. - */ -static const struct bt_mesh_comp srv_broken_comp = { - .elem = - (struct bt_mesh_elem[]){ - BT_MESH_ELEM(1, - MODEL_LIST(BT_MESH_MODEL_CFG_SRV, - BT_MESH_MODEL_CFG_CLI(&cfg_cli), - BT_MESH_MODEL_SAR_CFG_SRV, - BT_MESH_MODEL_SAR_CFG_CLI(&sar_cfg_cli), - BT_MESH_MODEL_CB(IMPOSTER_MODEL_ID, - model_op2, NULL, NULL, NULL), - BT_MESH_MODEL_BLOB_SRV(&blob_srv)), - BT_MESH_MODEL_NONE), - }, - .elem_count = 1, -}; - -static void test_srv_fail_on_xfer_get(void) -{ - common_fail_on_srv_init(&srv_broken_comp); - - bt_mesh_blob_srv_recv(&blob_srv, 1, &blob_io, 0, 5); - - PASS(); -} - -static void test_srv_fail_on_nothing(void) -{ - common_fail_on_srv_init(&srv_comp); - - bt_mesh_blob_srv_recv(&blob_srv, 1, &blob_io, 0, 5); - - PASS(); -} - -static void test_cli_fail_on_no_rsp(void) -{ - int err; - - /** Test fail conditions upon non-responsive servers - * during push transfer. Depending on the set - * test message type it tests the following: - * - * msg_fail_type = BLOCK_GET_FAIL - BLOB transfer suspends - * when targets does not respond to Block get. - * msg_fail_type = XFER_GET_FAIL - BLOB transfer stops - * when targets does not respond to Xfer get message. - */ - - (void)target_srv_add(BLOB_CLI_ADDR + 1, true); - (void)target_srv_add(BLOB_CLI_ADDR + 2, true); - - cli_common_fail_on_init(); - - err = bt_mesh_blob_cli_send(&blob_cli, &blob_cli_xfer.inputs, - &blob_cli_xfer.xfer, &blob_io); - if (err) { - FAIL("BLOB send failed (err: %d)", err); - } - - switch (msg_fail_type) { - case BLOCK_GET_FAIL: - if (k_sem_take(&blob_cli_suspend_sem, K_SECONDS(750))) { - FAIL("Suspend CB did not trigger as expected for the cli"); - } - - break; - - case XFER_GET_FAIL: - if (k_sem_take(&blob_cli_end_sem, K_SECONDS(750))) { - FAIL("End CB did not trigger as expected for the cli"); - } - - ASSERT_FALSE(cli_end_success); - break; - - default: - FAIL("Did not recognize the message type of the test"); - } - - if (k_sem_take(&lost_target_sem, K_NO_WAIT)) { - FAIL("Lost targets CB did not trigger for all expected lost targets"); - } - - PASS(); -} - -#define TEST_CASE(role, name, description) \ - { \ - .test_id = "blob_" #role "_" #name, \ - .test_descr = description, \ - .test_args_f = test_args_parse, \ - .test_tick_f = bt_mesh_test_timeout, \ - .test_main_f = test_##role##_##name, \ - } - -static const struct bst_test_instance test_blob[] = { - TEST_CASE(cli, caps_all_rsp, "Caps procedure: All responsive targets"), - TEST_CASE(cli, caps_partial_rsp, "Caps procedure: Mixed response from targets"), - TEST_CASE(cli, caps_no_rsp, "Caps procedure: No response from targets"), - TEST_CASE(cli, caps_cancelled, "Caps procedure: Cancel caps"), - TEST_CASE(cli, broadcast_basic, "Test basic broadcast API and CBs "), - TEST_CASE(cli, broadcast_trans, "Test all broadcast transmission types"), - TEST_CASE(cli, broadcast_unicast_seq, "Test broadcast with unicast addr (Sequential)"), - TEST_CASE(cli, broadcast_unicast, "Test broadcast with unicast addr"), - TEST_CASE(cli, trans_complete, "Transfer completes successfully on client (Default: Push)"), - TEST_CASE(cli, trans_resume, "Resume BLOB transfer after srv suspension (Default: Push)"), - TEST_CASE(cli, fail_on_persistency, "BLOB Client doesn't give up BLOB Transfer"), - TEST_CASE(cli, trans_persistency_pull, "Test transfer persistency in Pull mode"), - TEST_CASE(cli, fail_on_no_rsp, "BLOB Client end transfer if no targets rsp to Xfer Get"), - - TEST_CASE(srv, caps_standard, "Standard responsive blob server"), - TEST_CASE(srv, caps_no_rsp, "Non-responsive blob server"), - TEST_CASE(srv, trans_complete, "Transfer completes successfully on server"), - TEST_CASE(srv, trans_resume, "Self suspending server after first received block"), - TEST_CASE(srv, trans_persistency_pull, "Test transfer persistency in Pull mode"), - TEST_CASE(srv, fail_on_block_start, "Server failing right before first block start msg"), - TEST_CASE(srv, fail_on_block_get, "Server failing right before first block get msg"), - TEST_CASE(srv, fail_on_xfer_get, "Server failing right before first xfer get msg"), - TEST_CASE(srv, fail_on_nothing, "Non-failing server"), - - BSTEST_END_MARKER -}; - -struct bst_test_list *test_blob_install(struct bst_test_list *tests) -{ - tests = bst_add_tests(tests, test_blob); - return tests; -} diff --git a/tests/bluetooth/bsim/mesh/src/test_dfu.c b/tests/bluetooth/bsim/mesh/src/test_dfu.c deleted file mode 100644 index fd22b32f467..00000000000 --- a/tests/bluetooth/bsim/mesh/src/test_dfu.c +++ /dev/null @@ -1,1020 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include "mesh_test.h" -#include "settings_test_backend.h" -#include "mesh/dfd_srv_internal.h" -#include "mesh/dfu_slot.h" -#include "mesh/adv.h" -#include "mesh/dfu.h" -#include "mesh/blob.h" -#include "argparse.h" -#include "dfu_blob_common.h" - -#define LOG_MODULE_NAME test_dfu - -#include -LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL_INF); - -#define WAIT_TIME 420 /* seconds */ -#define DFU_TIMEOUT 400 /* seconds */ -#define DIST_ADDR 0x0001 -#define TARGET_ADDR 0x0100 -#define IMPOSTER_MODEL_ID 0xe000 - -struct bind_params { - uint16_t model_id; - uint16_t addr; -}; - -static uint8_t dev_key[16] = { 0xdd }; - -static struct k_sem dfu_dist_ended; -static struct k_sem dfu_ended; - -static struct bt_mesh_prov prov; - -static enum bt_mesh_dfu_effect dfu_target_effect; -static uint32_t target_fw_ver_curr = 0xDEADBEEF; -static uint32_t target_fw_ver_new; -static struct bt_mesh_dfu_img dfu_imgs[] = { { - .fwid = &target_fw_ver_curr, - .fwid_len = sizeof(target_fw_ver_curr), -} }; - -static struct bt_mesh_cfg_cli cfg_cli; -static struct bt_mesh_sar_cfg_cli sar_cfg_cli; - -static int dfu_targets_cnt; -static bool dfu_fail_confirm; - -static void test_args_parse(int argc, char *argv[]) -{ - bs_args_struct_t args_struct[] = { - { - .dest = &dfu_targets_cnt, - .type = 'i', - .name = "{targets}", - .option = "targets", - .descript = "Number of targets to upgrade" - }, - { - .dest = &dfu_fail_confirm, - .type = 'b', - .name = "{0, 1}", - .option = "fail-confirm", - .descript = "Request target to fail confirm step" - }, - }; - - bs_args_parse_all_cmd_line(argc, argv, args_struct); -} - -static int dummy_blob_chunk_wr(const struct bt_mesh_blob_io *io, - const struct bt_mesh_blob_xfer *xfer, - const struct bt_mesh_blob_block *block, - const struct bt_mesh_blob_chunk *chunk) -{ - return 0; -} - -static int dummy_blob_chunk_rd(const struct bt_mesh_blob_io *io, - const struct bt_mesh_blob_xfer *xfer, - const struct bt_mesh_blob_block *block, - const struct bt_mesh_blob_chunk *chunk) -{ - memset(chunk->data, 0, chunk->size); - - return 0; -} - -static const struct bt_mesh_blob_io dummy_blob_io = { - .rd = dummy_blob_chunk_rd, - .wr = dummy_blob_chunk_wr, -}; - -static int dist_fw_recv(struct bt_mesh_dfd_srv *srv, - const struct bt_mesh_dfu_slot *slot, - const struct bt_mesh_blob_io **io) -{ - *io = &dummy_blob_io; - - return 0; -} - -static void dist_fw_del(struct bt_mesh_dfd_srv *srv, - const struct bt_mesh_dfu_slot *slot) -{ -} - -static int dist_fw_send(struct bt_mesh_dfd_srv *srv, - const struct bt_mesh_dfu_slot *slot, - const struct bt_mesh_blob_io **io) -{ - *io = &dummy_blob_io; - - return 0; -} - -static void dist_phase_changed(struct bt_mesh_dfd_srv *srv, enum bt_mesh_dfd_phase phase) -{ - static enum bt_mesh_dfd_phase prev_phase; - - if (phase == BT_MESH_DFD_PHASE_COMPLETED || - phase == BT_MESH_DFD_PHASE_FAILED) { - if (phase == BT_MESH_DFD_PHASE_FAILED) { - ASSERT_EQUAL(BT_MESH_DFD_PHASE_APPLYING_UPDATE, prev_phase); - } - - k_sem_give(&dfu_dist_ended); - } - - prev_phase = phase; -} - -static struct bt_mesh_dfd_srv_cb dfd_srv_cb = { - .recv = dist_fw_recv, - .del = dist_fw_del, - .send = dist_fw_send, - .phase = dist_phase_changed, -}; - -struct bt_mesh_dfd_srv dfd_srv = BT_MESH_DFD_SRV_INIT(&dfd_srv_cb); - -static struct k_sem dfu_metadata_check_sem; -static bool dfu_metadata_fail = true; - -static int target_metadata_check(struct bt_mesh_dfu_srv *srv, - const struct bt_mesh_dfu_img *img, - struct net_buf_simple *metadata_raw, - enum bt_mesh_dfu_effect *effect) -{ - *effect = dfu_target_effect; - - memcpy(&target_fw_ver_new, net_buf_simple_pull_mem(metadata_raw, sizeof(target_fw_ver_new)), - sizeof(target_fw_ver_new)); - - k_sem_give(&dfu_metadata_check_sem); - - return dfu_metadata_fail ? 0 : -1; -} - -static bool expect_dfu_start = true; - -static int target_dfu_start(struct bt_mesh_dfu_srv *srv, - const struct bt_mesh_dfu_img *img, - struct net_buf_simple *metadata, - const struct bt_mesh_blob_io **io) -{ - ASSERT_TRUE(expect_dfu_start); - - *io = &dummy_blob_io; - - return 0; -} - -static struct k_sem dfu_verify_sem; -static bool dfu_verify_fail; -static bool expect_dfu_xfer_end = true; - -static void target_dfu_transfer_end(struct bt_mesh_dfu_srv *srv, const struct bt_mesh_dfu_img *img, - bool success) -{ - ASSERT_TRUE(expect_dfu_xfer_end); - ASSERT_TRUE(success); - - if (dfu_verify_fail) { - bt_mesh_dfu_srv_rejected(srv); - } else { - bt_mesh_dfu_srv_verified(srv); - } - - k_sem_give(&dfu_verify_sem); -} - -static int target_dfu_recover(struct bt_mesh_dfu_srv *srv, - const struct bt_mesh_dfu_img *img, - const struct bt_mesh_blob_io **io) -{ - FAIL("Not supported"); - - return 0; -} - -static bool expect_dfu_apply = true; - -static int target_dfu_apply(struct bt_mesh_dfu_srv *srv, const struct bt_mesh_dfu_img *img) -{ - ASSERT_TRUE(expect_dfu_apply); - - bt_mesh_dfu_srv_applied(srv); - - k_sem_give(&dfu_ended); - - if (dfu_fail_confirm) { - /* To fail the confirm step, don't change fw version for devices that should boot - * up provisioned. Change fw version for devices that should boot up unprovisioned. - */ - if (dfu_target_effect == BT_MESH_DFU_EFFECT_UNPROV) { - target_fw_ver_curr = target_fw_ver_new; - } - } else { - if (dfu_target_effect == BT_MESH_DFU_EFFECT_UNPROV) { - bt_mesh_reset(); - } - - target_fw_ver_curr = target_fw_ver_new; - } - - return 0; -} - -static const struct bt_mesh_dfu_srv_cb dfu_handlers = { - .check = target_metadata_check, - .start = target_dfu_start, - .end = target_dfu_transfer_end, - .apply = target_dfu_apply, - .recover = target_dfu_recover, -}; - -static struct bt_mesh_dfu_srv dfu_srv = BT_MESH_DFU_SRV_INIT(&dfu_handlers, dfu_imgs, - ARRAY_SIZE(dfu_imgs)); - -static const struct bt_mesh_comp dist_comp = { - .elem = - (struct bt_mesh_elem[]){ - BT_MESH_ELEM(1, - MODEL_LIST(BT_MESH_MODEL_CFG_SRV, - BT_MESH_MODEL_CFG_CLI(&cfg_cli), - BT_MESH_MODEL_SAR_CFG_SRV, - BT_MESH_MODEL_SAR_CFG_CLI(&sar_cfg_cli), - BT_MESH_MODEL_DFD_SRV(&dfd_srv)), - BT_MESH_MODEL_NONE), - }, - .elem_count = 1, -}; - -static const struct bt_mesh_comp dist_comp_self_update = { - .elem = - (struct bt_mesh_elem[]){ - BT_MESH_ELEM(1, - MODEL_LIST(BT_MESH_MODEL_CFG_SRV, - BT_MESH_MODEL_CFG_CLI(&cfg_cli), - BT_MESH_MODEL_SAR_CFG_SRV, - BT_MESH_MODEL_SAR_CFG_CLI(&sar_cfg_cli), - BT_MESH_MODEL_DFD_SRV(&dfd_srv)), - BT_MESH_MODEL_NONE), - BT_MESH_ELEM(2, - MODEL_LIST(BT_MESH_MODEL_DFU_SRV(&dfu_srv)), - BT_MESH_MODEL_NONE), - }, - .elem_count = 2, -}; - -static const struct bt_mesh_comp target_comp = { - .elem = - (struct bt_mesh_elem[]){ - BT_MESH_ELEM(1, - MODEL_LIST(BT_MESH_MODEL_CFG_SRV, - BT_MESH_MODEL_CFG_CLI(&cfg_cli), - BT_MESH_MODEL_SAR_CFG_SRV, - BT_MESH_MODEL_SAR_CFG_CLI(&sar_cfg_cli), - BT_MESH_MODEL_DFU_SRV(&dfu_srv)), - BT_MESH_MODEL_NONE), - }, - .elem_count = 1, -}; - -static void provision(uint16_t addr) -{ - int err; - - err = bt_mesh_provision(test_net_key, 0, 0, 0, addr, dev_key); - if (err) { - FAIL("Provisioning failed (err %d)", err); - return; - } -} - -static void common_configure(uint16_t addr) -{ - uint8_t status; - int err; - - err = bt_mesh_cfg_cli_app_key_add(0, addr, 0, 0, test_app_key, &status); - if (err || status) { - FAIL("AppKey add failed (err %d, status %u)", err, status); - return; - } -} - -static void common_app_bind(uint16_t addr, struct bind_params *params, size_t num) -{ - uint8_t status; - int err; - - for (size_t i = 0; i < num; i++) { - err = bt_mesh_cfg_cli_mod_app_bind(0, addr, params[i].addr, 0, params[i].model_id, - &status); - if (err || status) { - FAIL("Model %#4x bind failed (err %d, status %u)", params[i].model_id, - err, status); - return; - } - } -} - -static void dist_prov_and_conf(uint16_t addr) -{ - provision(addr); - common_configure(addr); - - struct bind_params bind_params[] = { - { BT_MESH_MODEL_ID_BLOB_CLI, addr }, - { BT_MESH_MODEL_ID_DFU_CLI, addr }, - }; - - common_app_bind(addr, &bind_params[0], ARRAY_SIZE(bind_params)); - common_sar_conf(addr); -} - -static void dist_self_update_prov_and_conf(uint16_t addr) -{ - provision(addr); - common_configure(addr); - - struct bind_params bind_params[] = { - { BT_MESH_MODEL_ID_BLOB_CLI, addr }, - { BT_MESH_MODEL_ID_DFU_CLI, addr }, - { BT_MESH_MODEL_ID_BLOB_SRV, addr + 1 }, - { BT_MESH_MODEL_ID_DFU_SRV, addr + 1 }, - }; - - common_app_bind(addr, &bind_params[0], ARRAY_SIZE(bind_params)); - common_sar_conf(addr); -} - -static void target_prov_and_conf(uint16_t addr, struct bind_params *params, size_t len) -{ - settings_test_backend_clear(); - provision(addr); - common_configure(addr); - - common_app_bind(addr, params, len); - common_sar_conf(addr); -} - -static void target_prov_and_conf_default(void) -{ - uint16_t addr = bt_mesh_test_own_addr_get(TARGET_ADDR); - struct bind_params bind_params[] = { - { BT_MESH_MODEL_ID_BLOB_SRV, addr }, - { BT_MESH_MODEL_ID_DFU_SRV, addr }, - }; - - target_prov_and_conf(addr, bind_params, ARRAY_SIZE(bind_params)); -} - -static bool slot_add(const struct bt_mesh_dfu_slot **slot) -{ - const struct bt_mesh_dfu_slot *new_slot; - size_t size = 100; - uint8_t fwid[CONFIG_BT_MESH_DFU_FWID_MAXLEN] = { 0xAA, 0xBB, 0xCC, 0xDD }; - size_t fwid_len = 4; - uint8_t metadata[CONFIG_BT_MESH_DFU_METADATA_MAXLEN] = { 0xAA, 0xBB, 0xCC, 0xDD }; - size_t metadata_len = 4; - const char *uri = ""; - - ASSERT_EQUAL(sizeof(target_fw_ver_new), fwid_len); - - new_slot = bt_mesh_dfu_slot_add(size, fwid, fwid_len, metadata, metadata_len, uri, - strlen(uri)); - if (!new_slot) { - return false; - } - - bt_mesh_dfu_slot_valid_set(new_slot, true); - - if (slot) { - *slot = new_slot; - } - - return true; -} - -static void dist_dfu_start_and_confirm(void) -{ - enum bt_mesh_dfd_status status; - struct bt_mesh_dfd_start_params start_params = { - .app_idx = 0, - .timeout_base = 10, - .slot_idx = 0, - .group = 0, - .xfer_mode = BT_MESH_BLOB_XFER_MODE_PUSH, - .ttl = 2, - .apply = true, - }; - - status = bt_mesh_dfd_srv_start(&dfd_srv, &start_params); - ASSERT_EQUAL(BT_MESH_DFD_SUCCESS, status); - - if (k_sem_take(&dfu_dist_ended, K_SECONDS(DFU_TIMEOUT))) { - FAIL("DFU timed out"); - } - - enum bt_mesh_dfu_status expected_status; - enum bt_mesh_dfu_phase expected_phase; - - if (dfu_fail_confirm) { - ASSERT_EQUAL(BT_MESH_DFD_PHASE_FAILED, dfd_srv.phase); - expected_status = BT_MESH_DFU_ERR_INTERNAL; - expected_phase = BT_MESH_DFU_PHASE_APPLY_FAIL; - } else { - ASSERT_EQUAL(BT_MESH_DFD_PHASE_COMPLETED, dfd_srv.phase); - expected_status = BT_MESH_DFU_SUCCESS; - expected_phase = BT_MESH_DFU_PHASE_APPLY_SUCCESS; - } - - for (int i = 0; i < dfu_targets_cnt; i++) { - ASSERT_EQUAL(expected_status, dfd_srv.targets[i].status); - - if (dfd_srv.targets[i].effect == BT_MESH_DFU_EFFECT_UNPROV) { - /* If device should unprovision itself after the update, the phase won't - * change. If phase changes, DFU failed. - */ - if (dfu_fail_confirm) { - ASSERT_EQUAL(BT_MESH_DFU_PHASE_APPLY_FAIL, - dfd_srv.targets[i].phase); - } else { - ASSERT_EQUAL(BT_MESH_DFU_PHASE_APPLYING, dfd_srv.targets[i].phase); - } - } else { - ASSERT_EQUAL(expected_phase, dfd_srv.targets[i].phase); - } - } -} - -static void test_dist_dfu(void) -{ - enum bt_mesh_dfd_status status; - - settings_test_backend_clear(); - bt_mesh_test_cfg_set(NULL, WAIT_TIME); - bt_mesh_device_setup(&prov, &dist_comp); - dist_prov_and_conf(DIST_ADDR); - - ASSERT_TRUE(slot_add(NULL)); - - ASSERT_TRUE(dfu_targets_cnt > 0); - - for (int i = 0; i < dfu_targets_cnt; i++) { - status = bt_mesh_dfd_srv_receiver_add(&dfd_srv, TARGET_ADDR + 1 + i, 0); - ASSERT_EQUAL(BT_MESH_DFD_SUCCESS, status); - } - - dist_dfu_start_and_confirm(); - - PASS(); -} - -static void test_dist_dfu_self_update(void) -{ - enum bt_mesh_dfd_status status; - - ASSERT_TRUE(dfu_targets_cnt > 0); - - settings_test_backend_clear(); - bt_mesh_test_cfg_set(NULL, WAIT_TIME); - bt_mesh_device_setup(&prov, &dist_comp_self_update); - dist_self_update_prov_and_conf(DIST_ADDR); - - ASSERT_TRUE(slot_add(NULL)); - - status = bt_mesh_dfd_srv_receiver_add(&dfd_srv, DIST_ADDR + 1, 0); - ASSERT_EQUAL(BT_MESH_DFD_SUCCESS, status); - dfu_target_effect = BT_MESH_DFU_EFFECT_NONE; - - for (int i = 1; i < dfu_targets_cnt; i++) { - status = bt_mesh_dfd_srv_receiver_add(&dfd_srv, TARGET_ADDR + i, 0); - ASSERT_EQUAL(BT_MESH_DFD_SUCCESS, status); - } - - dist_dfu_start_and_confirm(); - - /* Check that DFU finished on distributor. */ - if (k_sem_take(&dfu_ended, K_SECONDS(DFU_TIMEOUT))) { - FAIL("firmware was not applied"); - } - - PASS(); -} - -static void target_test_effect(enum bt_mesh_dfu_effect effect) -{ - dfu_target_effect = effect; - - settings_test_backend_clear(); - bt_mesh_test_cfg_set(NULL, WAIT_TIME); - bt_mesh_device_setup(&prov, &target_comp); - target_prov_and_conf_default(); - - if (k_sem_take(&dfu_ended, K_SECONDS(DFU_TIMEOUT))) { - FAIL("Firmware was not applied"); - } -} - -static void test_target_dfu_no_change(void) -{ - target_test_effect(BT_MESH_DFU_EFFECT_NONE); - - PASS(); -} - -static void test_target_dfu_new_comp_no_rpr(void) -{ - target_test_effect(BT_MESH_DFU_EFFECT_COMP_CHANGE_NO_RPR); - - PASS(); -} - -static void test_target_dfu_new_comp_rpr(void) -{ - target_test_effect(BT_MESH_DFU_EFFECT_COMP_CHANGE); - - PASS(); -} - -static void test_target_dfu_unprov(void) -{ - target_test_effect(BT_MESH_DFU_EFFECT_UNPROV); - - PASS(); -} - -static struct { - struct bt_mesh_blob_cli_inputs inputs; - struct bt_mesh_dfu_target targets[7]; - uint8_t target_count; - struct bt_mesh_dfu_cli_xfer xfer; -} dfu_cli_xfer; - -static void dfu_cli_inputs_prepare(uint16_t group) -{ - dfu_cli_xfer.inputs.ttl = BT_MESH_TTL_DEFAULT; - dfu_cli_xfer.inputs.group = group; - dfu_cli_xfer.inputs.app_idx = 0; - dfu_cli_xfer.inputs.timeout_base = 1; - sys_slist_init(&dfu_cli_xfer.inputs.targets); - - for (int i = 0; i < dfu_cli_xfer.target_count; ++i) { - /* Reset target context. */ - uint16_t addr = dfu_cli_xfer.targets[i].blob.addr; - - memset(&dfu_cli_xfer.targets[i], 0, sizeof(struct bt_mesh_dfu_target)); - dfu_cli_xfer.targets[i].blob.addr = addr; - - sys_slist_append(&dfu_cli_xfer.inputs.targets, &dfu_cli_xfer.targets[i].blob.n); - } -} - -static struct bt_mesh_blob_target *target_srv_add(uint16_t addr, bool expect_lost) -{ - if (expect_lost) { - lost_target_add(addr); - } - - ASSERT_TRUE(dfu_cli_xfer.target_count < ARRAY_SIZE(dfu_cli_xfer.targets)); - struct bt_mesh_blob_target *t = &dfu_cli_xfer.targets[dfu_cli_xfer.target_count].blob; - - t->addr = addr; - dfu_cli_xfer.target_count++; - return t; -} - -static void dfu_cli_suspended(struct bt_mesh_dfu_cli *cli) -{ - FAIL("Unexpected call"); -} - -static void dfu_cli_ended(struct bt_mesh_dfu_cli *cli, enum bt_mesh_dfu_status reason) -{ - ASSERT_EQUAL(BT_MESH_DFU_SUCCESS, reason); - k_sem_give(&dfu_ended); -} - -static struct k_sem dfu_cli_applied_sem; - -static void dfu_cli_applied(struct bt_mesh_dfu_cli *cli) -{ - k_sem_give(&dfu_cli_applied_sem); -} - -static struct k_sem dfu_cli_confirmed_sem; - -static void dfu_cli_confirmed(struct bt_mesh_dfu_cli *cli) -{ - k_sem_give(&dfu_cli_confirmed_sem); -} - -static struct k_sem lost_target_sem; - -static void dfu_cli_lost_target(struct bt_mesh_dfu_cli *cli, struct bt_mesh_dfu_target *target) -{ - ASSERT_FALSE(target->status == BT_MESH_DFU_SUCCESS); - ASSERT_TRUE(lost_target_find_and_remove(target->blob.addr)); - - if (!lost_targets_rem()) { - k_sem_give(&lost_target_sem); - } -} - -static struct bt_mesh_dfu_cli_cb dfu_cli_cb = { - .suspended = dfu_cli_suspended, - .ended = dfu_cli_ended, - .applied = dfu_cli_applied, - .confirmed = dfu_cli_confirmed, - .lost_target = dfu_cli_lost_target, -}; - -static struct bt_mesh_dfu_cli dfu_cli = BT_MESH_DFU_CLI_INIT(&dfu_cli_cb); - -static const struct bt_mesh_comp cli_comp = { - .elem = - (struct bt_mesh_elem[]){ - BT_MESH_ELEM(1, - MODEL_LIST(BT_MESH_MODEL_CFG_SRV, - BT_MESH_MODEL_CFG_CLI(&cfg_cli), - BT_MESH_MODEL_SAR_CFG_SRV, - BT_MESH_MODEL_SAR_CFG_CLI(&sar_cfg_cli), - BT_MESH_MODEL_DFU_CLI(&dfu_cli)), - BT_MESH_MODEL_NONE), - }, - .elem_count = 1, -}; - -static void cli_common_fail_on_init(void) -{ - const struct bt_mesh_dfu_slot *slot; - - settings_test_backend_clear(); - bt_mesh_test_cfg_set(NULL, 300); - bt_mesh_device_setup(&prov, &cli_comp); - dist_prov_and_conf(DIST_ADDR); - - ASSERT_TRUE(slot_add(&slot)); - - dfu_cli_inputs_prepare(0); - dfu_cli_xfer.xfer.mode = BT_MESH_BLOB_XFER_MODE_PUSH; - dfu_cli_xfer.xfer.slot = slot; -} - -static void test_cli_fail_on_persistency(void) -{ - int err; - - /** Test that DFU transfer persists as long as at least one target is still active. During - * the test multiple servers will become unresponsive at different phases of the transfer: - * - Srv 0x0002 will reject firmware by metadata. - * - Srv 0x0003 will not respond to BLOB Information Get msg (Retrieve Caps proc). - * - Srv 0x0004 will not respond to Firmware Update Get msg after BLOB Transfer. - * - Srv 0x0005 will fail firmware verification. - * - Srv 0x0006 will not respond to Firmware Update Apply msg. - * - Srv 0x0007 is responsive all the way. - * - Srv 0x0008 is a non-existing unresponsive node that will not respond to Firmware - * Update Start msg, which is the first message sent by DFU Client. - */ - (void)target_srv_add(TARGET_ADDR + 1, true); - (void)target_srv_add(TARGET_ADDR + 2, true); - (void)target_srv_add(TARGET_ADDR + 3, true); - (void)target_srv_add(TARGET_ADDR + 4, true); - (void)target_srv_add(TARGET_ADDR + 5, true); - (void)target_srv_add(TARGET_ADDR + 6, false); - (void)target_srv_add(TARGET_ADDR + 7, true); - - cli_common_fail_on_init(); - - err = bt_mesh_dfu_cli_send(&dfu_cli, &dfu_cli_xfer.inputs, &dummy_blob_io, - &dfu_cli_xfer.xfer); - if (err) { - FAIL("DFU Client send failed (err: %d)", err); - } - - if (k_sem_take(&dfu_ended, K_SECONDS(200))) { - FAIL("Firmware transfer failed"); - } - - /* This is non-existing unresponsive target that didn't reply on Firmware Update Start - * message. - */ - ASSERT_EQUAL(BT_MESH_DFU_ERR_INTERNAL, dfu_cli_xfer.targets[6].status); - ASSERT_EQUAL(BT_MESH_DFU_PHASE_UNKNOWN, dfu_cli_xfer.targets[6].phase); - /* This target rejected metadata. */ - ASSERT_EQUAL(BT_MESH_DFU_ERR_METADATA, dfu_cli_xfer.targets[0].status); - ASSERT_EQUAL(BT_MESH_DFU_PHASE_IDLE, dfu_cli_xfer.targets[0].phase); - /* This target shouldn't respond on BLOB Information Get message from Retrieve Caps - * procedure. - */ - ASSERT_EQUAL(BT_MESH_DFU_ERR_INTERNAL, dfu_cli_xfer.targets[1].status); - ASSERT_EQUAL(BT_MESH_DFU_PHASE_TRANSFER_ACTIVE, dfu_cli_xfer.targets[1].phase); - /* This target shouldn't respond on Firmware Update Get msg. */ - ASSERT_EQUAL(BT_MESH_DFU_ERR_INTERNAL, dfu_cli_xfer.targets[2].status); - ASSERT_EQUAL(BT_MESH_DFU_PHASE_TRANSFER_ACTIVE, dfu_cli_xfer.targets[2].phase); - /* This target failed firmware verification. */ - ASSERT_EQUAL(BT_MESH_DFU_ERR_WRONG_PHASE, dfu_cli_xfer.targets[3].status); - ASSERT_EQUAL(BT_MESH_DFU_PHASE_VERIFY_FAIL, dfu_cli_xfer.targets[3].phase); - /* The next two targets should be OK. */ - ASSERT_EQUAL(BT_MESH_DFU_SUCCESS, dfu_cli_xfer.targets[4].status); - ASSERT_EQUAL(BT_MESH_DFU_PHASE_VERIFY_OK, dfu_cli_xfer.targets[4].phase); - ASSERT_EQUAL(BT_MESH_DFU_SUCCESS, dfu_cli_xfer.targets[5].status); - ASSERT_EQUAL(BT_MESH_DFU_PHASE_VERIFY_OK, dfu_cli_xfer.targets[5].phase); - - err = bt_mesh_dfu_cli_apply(&dfu_cli); - if (err) { - FAIL("DFU Client apply failed (err: %d)", err); - } - - if (k_sem_take(&dfu_cli_applied_sem, K_SECONDS(200))) { - FAIL("Failed to apply firmware"); - } - - /* This target shouldn't respond on Firmware Update Apply message. */ - ASSERT_EQUAL(BT_MESH_DFU_ERR_INTERNAL, dfu_cli_xfer.targets[4].status); - ASSERT_EQUAL(BT_MESH_DFU_PHASE_VERIFY_OK, dfu_cli_xfer.targets[4].phase); - - err = bt_mesh_dfu_cli_confirm(&dfu_cli); - if (err) { - FAIL("DFU Client confirm failed (err: %d)", err); - } - - if (k_sem_take(&dfu_cli_confirmed_sem, K_SECONDS(200))) { - FAIL("Failed to confirm firmware"); - } - - /* This target should complete DFU successfully. */ - ASSERT_EQUAL(BT_MESH_DFU_SUCCESS, dfu_cli_xfer.targets[5].status); - ASSERT_EQUAL(BT_MESH_DFU_PHASE_APPLY_SUCCESS, dfu_cli_xfer.targets[5].phase); - - if (k_sem_take(&lost_target_sem, K_NO_WAIT)) { - FAIL("Lost targets CB did not trigger for all expected lost targets"); - } - - PASS(); -} - -static struct k_sem caps_get_sem; - -static int mock_handle_caps_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) -{ - LOG_WRN("Rejecting BLOB Information Get message"); - k_sem_give(&caps_get_sem); - - return 0; -} - -static const struct bt_mesh_model_op model_caps_op1[] = { - { BT_MESH_BLOB_OP_INFO_GET, 0, mock_handle_caps_get }, - BT_MESH_MODEL_OP_END -}; - -static const struct bt_mesh_comp srv_caps_broken_comp = { - .elem = - (struct bt_mesh_elem[]){ - BT_MESH_ELEM(1, - MODEL_LIST(BT_MESH_MODEL_CFG_SRV, - BT_MESH_MODEL_CFG_CLI(&cfg_cli), - BT_MESH_MODEL_SAR_CFG_SRV, - BT_MESH_MODEL_SAR_CFG_CLI(&sar_cfg_cli), - BT_MESH_MODEL_CB(IMPOSTER_MODEL_ID, - model_caps_op1, NULL, NULL, NULL), - BT_MESH_MODEL_DFU_SRV(&dfu_srv)), - BT_MESH_MODEL_NONE), - }, - .elem_count = 1, -}; - -static struct k_sem update_get_sem; - -static int mock_handle_update_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) -{ - LOG_WRN("Rejecting Firmware Update Get message"); - k_sem_give(&update_get_sem); - - return 0; -} - -static const struct bt_mesh_model_op model_update_get_op1[] = { - { BT_MESH_DFU_OP_UPDATE_GET, 0, mock_handle_update_get }, - BT_MESH_MODEL_OP_END -}; - -static const struct bt_mesh_comp srv_update_get_broken_comp = { - .elem = - (struct bt_mesh_elem[]){ - BT_MESH_ELEM(1, - MODEL_LIST(BT_MESH_MODEL_CFG_SRV, - BT_MESH_MODEL_CFG_CLI(&cfg_cli), - BT_MESH_MODEL_SAR_CFG_SRV, - BT_MESH_MODEL_SAR_CFG_CLI(&sar_cfg_cli), - BT_MESH_MODEL_CB(IMPOSTER_MODEL_ID, - model_update_get_op1, NULL, NULL, - NULL), - BT_MESH_MODEL_DFU_SRV(&dfu_srv)), - BT_MESH_MODEL_NONE), - }, - .elem_count = 1, -}; - -static struct k_sem update_apply_sem; - -static int mock_handle_update_apply(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) -{ - LOG_WRN("Rejecting Firmware Update Apply message"); - k_sem_give(&update_apply_sem); - - return 0; -} - -static const struct bt_mesh_model_op model_update_apply_op1[] = { - { BT_MESH_DFU_OP_UPDATE_APPLY, 0, mock_handle_update_apply }, - BT_MESH_MODEL_OP_END -}; - -static const struct bt_mesh_comp srv_update_apply_broken_comp = { - .elem = - (struct bt_mesh_elem[]){ - BT_MESH_ELEM(1, - MODEL_LIST(BT_MESH_MODEL_CFG_SRV, - BT_MESH_MODEL_CFG_CLI(&cfg_cli), - BT_MESH_MODEL_SAR_CFG_SRV, - BT_MESH_MODEL_SAR_CFG_CLI(&sar_cfg_cli), - BT_MESH_MODEL_CB(IMPOSTER_MODEL_ID, - model_update_apply_op1, NULL, - NULL, NULL), - BT_MESH_MODEL_DFU_SRV(&dfu_srv)), - BT_MESH_MODEL_NONE), - }, - .elem_count = 1, -}; - -static void target_prov_and_conf_with_imposer(void) -{ - uint16_t addr = bt_mesh_test_own_addr_get(TARGET_ADDR); - struct bind_params bind_params[] = { - { BT_MESH_MODEL_ID_BLOB_SRV, addr }, - { BT_MESH_MODEL_ID_DFU_SRV, addr }, - { IMPOSTER_MODEL_ID, addr }, - }; - - target_prov_and_conf(addr, bind_params, ARRAY_SIZE(bind_params)); -} - -static void common_fail_on_target_init(const struct bt_mesh_comp *comp) -{ - settings_test_backend_clear(); - bt_mesh_test_cfg_set(NULL, 300); - bt_mesh_device_setup(&prov, comp); - - dfu_target_effect = BT_MESH_DFU_EFFECT_NONE; -} - -static void test_target_fail_on_metadata(void) -{ - dfu_metadata_fail = false; - expect_dfu_start = false; - - common_fail_on_target_init(&target_comp); - target_prov_and_conf_default(); - - if (k_sem_take(&dfu_metadata_check_sem, K_SECONDS(200))) { - FAIL("Metadata check CB wasn't called"); - } - - PASS(); -} - -static void test_target_fail_on_caps_get(void) -{ - expect_dfu_xfer_end = false; - - common_fail_on_target_init(&srv_caps_broken_comp); - target_prov_and_conf_with_imposer(); - - if (k_sem_take(&caps_get_sem, K_SECONDS(200))) { - FAIL("BLOB Info Get msg handler wasn't called"); - } - - PASS(); -} - -static void test_target_fail_on_update_get(void) -{ - expect_dfu_apply = false; - - common_fail_on_target_init(&srv_update_get_broken_comp); - target_prov_and_conf_with_imposer(); - - if (k_sem_take(&dfu_verify_sem, K_SECONDS(200))) { - FAIL("Transfer end CB wasn't triggered"); - } - - if (k_sem_take(&update_get_sem, K_SECONDS(200))) { - FAIL("Firmware Update Get msg handler wasn't called"); - } - - PASS(); -} - -static void test_target_fail_on_verify(void) -{ - dfu_verify_fail = true; - expect_dfu_apply = false; - - common_fail_on_target_init(&target_comp); - target_prov_and_conf_default(); - - if (k_sem_take(&dfu_verify_sem, K_SECONDS(200))) { - FAIL("Transfer end CB wasn't triggered"); - } - - PASS(); -} - -static void test_target_fail_on_apply(void) -{ - expect_dfu_apply = false; - - common_fail_on_target_init(&srv_update_apply_broken_comp); - target_prov_and_conf_with_imposer(); - - if (k_sem_take(&update_apply_sem, K_SECONDS(200))) { - FAIL("Firmware Update Apply msg handler wasn't called"); - } - - PASS(); -} - -static void test_target_fail_on_nothing(void) -{ - common_fail_on_target_init(&target_comp); - target_prov_and_conf_default(); - - if (k_sem_take(&dfu_ended, K_SECONDS(200))) { - FAIL("DFU failed"); - } - - PASS(); -} - -static void test_pre_init(void) -{ - k_sem_init(&dfu_dist_ended, 0, 1); - k_sem_init(&dfu_ended, 0, 1); - k_sem_init(&caps_get_sem, 0, 1); - k_sem_init(&update_get_sem, 0, 1); - k_sem_init(&update_apply_sem, 0, 1); - k_sem_init(&dfu_metadata_check_sem, 0, 1); - k_sem_init(&dfu_verify_sem, 0, 1); - k_sem_init(&dfu_cli_applied_sem, 0, 1); - k_sem_init(&dfu_cli_confirmed_sem, 0, 1); - k_sem_init(&lost_target_sem, 0, 1); -} - -#define TEST_CASE(role, name, description) \ - { \ - .test_id = "dfu_" #role "_" #name, \ - .test_descr = description, \ - .test_pre_init_f = test_pre_init, \ - .test_args_f = test_args_parse, \ - .test_tick_f = bt_mesh_test_timeout, \ - .test_main_f = test_##role##_##name, \ - } - -static const struct bst_test_instance test_dfu[] = { - TEST_CASE(dist, dfu, "Distributor performs DFU"), - TEST_CASE(dist, dfu_self_update, "Distributor performs DFU with self update"), - TEST_CASE(cli, fail_on_persistency, "DFU Client doesn't give up DFU Transfer"), - - TEST_CASE(target, dfu_no_change, "Target node, Comp Data stays unchanged"), - TEST_CASE(target, dfu_new_comp_no_rpr, "Target node, Comp Data changes, no RPR"), - TEST_CASE(target, dfu_new_comp_rpr, "Target node, Comp Data changes, has RPR"), - TEST_CASE(target, dfu_unprov, "Target node, Comp Data changes, unprovisioned"), - TEST_CASE(target, fail_on_metadata, "Server rejects metadata"), - TEST_CASE(target, fail_on_caps_get, "Server failing on Retrieve Capabilities procedure"), - TEST_CASE(target, fail_on_update_get, "Server failing on Fw Update Get msg"), - TEST_CASE(target, fail_on_verify, "Server rejects fw at Refresh step"), - TEST_CASE(target, fail_on_apply, "Server failing on Fw Update Apply msg"), - TEST_CASE(target, fail_on_nothing, "Non-failing server"), - - BSTEST_END_MARKER -}; - -struct bst_test_list *test_dfu_install(struct bst_test_list *tests) -{ - tests = bst_add_tests(tests, test_dfu); - return tests; -} diff --git a/tests/bluetooth/bsim/mesh/src/test_friendship.c b/tests/bluetooth/bsim/mesh/src/test_friendship.c deleted file mode 100644 index e537fd108a0..00000000000 --- a/tests/bluetooth/bsim/mesh/src/test_friendship.c +++ /dev/null @@ -1,1021 +0,0 @@ -/* - * Copyright (c) 2021 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include "mesh_test.h" -#include "mesh/net.h" -#include "mesh/transport.h" -#include -#include "argparse.h" - -#define LOG_MODULE_NAME test_friendship - -#include -LOG_MODULE_REGISTER(LOG_MODULE_NAME); - -/* - * Friendship tests: - * Tests both the friend and the low power role in various scenarios. - */ - -#define GROUP_ADDR 0xc000 -#define WAIT_TIME 60 /*seconds*/ -#define LPN_ADDR_START 0x0003 -#define POLL_TIMEOUT_MS (100 * CONFIG_BT_MESH_LPN_POLL_TIMEOUT) - -extern enum bst_result_t bst_result; - -enum test_flags { - LPN_ESTABLISHED, - LPN_TERMINATED, - LPN_POLLED, - FRIEND_ESTABLISHED, - FRIEND_TERMINATED, - FRIEND_POLLED, - - TEST_FLAGS, -}; - -static ATOMIC_DEFINE(state, TEST_FLAGS); -static struct k_sem events[TEST_FLAGS]; - -static const struct bt_mesh_test_cfg friend_cfg = { - .addr = 0x0001, - .dev_key = { 0x01 }, -}; -static const struct bt_mesh_test_cfg other_cfg = { - .addr = 0x0002, - .dev_key = { 0x02 }, -}; -static struct bt_mesh_test_cfg lpn_cfg; -static uint16_t friend_lpn_addr; - -static void test_common_init(const struct bt_mesh_test_cfg *cfg) -{ - for (int i = 0; i < ARRAY_SIZE(events); i++) { - k_sem_init(&events[i], 0, 1); - } - - bt_mesh_test_cfg_set(cfg, WAIT_TIME); -} - -static void test_friend_init(void) -{ - test_common_init(&friend_cfg); -} - -static void test_lpn_init(void) -{ - /* As there may be multiple LPN devices, we'll set the address and - * devkey based on the device number, which is guaranteed to be unique - * for each device in the simulation. - */ - lpn_cfg.addr = LPN_ADDR_START + get_device_nbr(); - lpn_cfg.dev_key[0] = get_device_nbr(); - test_common_init(&lpn_cfg); -} - -static void test_other_init(void) -{ - test_common_init(&other_cfg); -} - -static void evt_signal(enum test_flags evt) -{ - atomic_set_bit(state, evt); - k_sem_give(&events[evt]); -} - -static int evt_wait(enum test_flags evt, k_timeout_t timeout) -{ - return k_sem_take(&events[evt], timeout); -} - -static void evt_clear(enum test_flags evt) -{ - atomic_clear_bit(state, evt); - k_sem_reset(&events[evt]); -} - -static void friend_established(uint16_t net_idx, uint16_t lpn_addr, - uint8_t recv_delay, uint32_t polltimeout) -{ - LOG_INF("Friend: established with 0x%04x", lpn_addr); - friend_lpn_addr = lpn_addr; - evt_signal(FRIEND_ESTABLISHED); -} - -static void friend_terminated(uint16_t net_idx, uint16_t lpn_addr) -{ - LOG_INF("Friend: terminated with 0x%04x", lpn_addr); - evt_signal(FRIEND_TERMINATED); -} - -static void friend_polled(uint16_t net_idx, uint16_t lpn_addr) -{ - LOG_INF("Friend: Poll from 0x%04x", lpn_addr); - evt_signal(FRIEND_POLLED); -} - -BT_MESH_FRIEND_CB_DEFINE(friend) = { - .established = friend_established, - .terminated = friend_terminated, - .polled = friend_polled, -}; - -static void lpn_established(uint16_t net_idx, uint16_t friend_addr, - uint8_t queue_size, uint8_t recv_window) -{ - LOG_INF("LPN: established with 0x%04x", friend_addr); - evt_signal(LPN_ESTABLISHED); -} - -static void lpn_terminated(uint16_t net_idx, uint16_t friend_addr) -{ - LOG_INF("LPN: terminated with 0x%04x", friend_addr); - evt_signal(LPN_TERMINATED); -} - -static void lpn_polled(uint16_t net_idx, uint16_t friend_addr, bool retry) -{ - LOG_INF("LPN: Polling 0x%04x (%s)", friend_addr, - retry ? "retry" : "initial"); - evt_signal(LPN_POLLED); -} - -BT_MESH_LPN_CB_DEFINE(lpn) = { - .established = lpn_established, - .polled = lpn_polled, - .terminated = lpn_terminated, -}; - -static void friend_wait_for_polls(int polls) -{ - /* Let LPN poll to get the sent message */ - ASSERT_OK_MSG(evt_wait(FRIEND_POLLED, K_SECONDS(30)), "LPN never polled"); - - while (--polls) { - /* Wait for LPN to poll until the "no more data" message. - * At this point, the message has been delivered. - */ - ASSERT_OK_MSG(evt_wait(FRIEND_POLLED, K_SECONDS(2)), - "LPN missing %d polls", polls); - } - - if (evt_wait(FRIEND_POLLED, K_SECONDS(2)) != -EAGAIN) { - FAIL("Unexpected extra poll"); - return; - } -} - -/* Friend test functions */ - -/** Initialize as a friend and wait for the friendship to be established. - */ -static void test_friend_est(void) -{ - bt_mesh_test_setup(); - - bt_mesh_friend_set(BT_MESH_FEATURE_ENABLED); - - ASSERT_OK_MSG(evt_wait(FRIEND_ESTABLISHED, K_SECONDS(5)), - "Friendship not established"); - - PASS(); -} - -/** Initialize as a friend, and wait for multiple friendships to be established - * concurrently. - * - * Verify that all friendships survive the first poll timeout. - */ -static void test_friend_est_multi(void) -{ - int err; - - bt_mesh_test_setup(); - - k_sem_init(&events[FRIEND_ESTABLISHED], 0, - CONFIG_BT_MESH_FRIEND_LPN_COUNT); - - bt_mesh_friend_set(BT_MESH_FEATURE_ENABLED); - - for (int i = 0; i < CONFIG_BT_MESH_FRIEND_LPN_COUNT; i++) { - ASSERT_OK_MSG(evt_wait(FRIEND_ESTABLISHED, K_SECONDS(5)), - "Friendship %d not established", i); - } - - /* Wait for all friends to do at least one poll without terminating */ - err = evt_wait(FRIEND_TERMINATED, - K_MSEC(POLL_TIMEOUT_MS + 5 * MSEC_PER_SEC)); - if (!err) { - FAIL("One or more friendships terminated"); - } - - PASS(); -} - -/** As a friend, send messages to the LPN. - * - * Verifies unsegmented, segmented and multiple packet sending and receiving. - */ -static void test_friend_msg(void) -{ - bt_mesh_test_setup(); - - bt_mesh_friend_set(BT_MESH_FEATURE_ENABLED); - - ASSERT_OK_MSG(evt_wait(FRIEND_ESTABLISHED, K_SECONDS(5)), - "Friendship not established"); - /* LPN polls on establishment. Clear the poll state */ - evt_clear(FRIEND_POLLED); - - k_sleep(K_SECONDS(1)); - - /* Send unsegmented message from friend to LPN: */ - LOG_INF("Sending unsegmented message"); - ASSERT_OK_MSG(bt_mesh_test_send(friend_lpn_addr, 5, 0, K_SECONDS(1)), - "Unseg send failed"); - - /* Wait for LPN to poll for message and the "no more messages" msg */ - friend_wait_for_polls(2); - - /* Send segmented message */ - ASSERT_OK_MSG(bt_mesh_test_send(friend_lpn_addr, 13, 0, K_SECONDS(1)), - "Unseg send failed"); - - /* Two segments require 2 polls plus the "no more messages" msg */ - friend_wait_for_polls(3); - - /* Send two unsegmented messages before the next poll. - * This tests the friend role's re-encryption mechanism for the second - * message, as sending the first message through the network layer - * increases the seqnum by one, creating an inconsistency between the - * transport and network parts of the second packet. - * Ensures coverage for the regression reported in #32033. - */ - ASSERT_OK_MSG(bt_mesh_test_send(friend_lpn_addr, BT_MESH_SDU_UNSEG_MAX, 0, K_SECONDS(1)), - "Unseg send failed"); - ASSERT_OK_MSG(bt_mesh_test_send(friend_lpn_addr, BT_MESH_SDU_UNSEG_MAX, 0, K_SECONDS(1)), - "Unseg send failed"); - - /* Two messages require 2 polls plus the "no more messages" msg */ - friend_wait_for_polls(3); - - ASSERT_OK_MSG(bt_mesh_test_recv(5, cfg->addr, K_SECONDS(10)), - "Receive from LPN failed"); - - /* Receive a segmented message from the LPN. LPN should poll for the ack - * after sending the segments. - */ - ASSERT_OK(bt_mesh_test_recv(15, cfg->addr, K_SECONDS(10))); - /* 4 polls (2 if legacy transport layer is used): - * - The first one triggered manually by transport when sending segmented message; - * - 2 for each SegAck (SegAcks are sent faster than Friend Poll messages); - * - The last one with MD == 0; - */ - friend_wait_for_polls(IS_ENABLED(CONFIG_BT_MESH_V1d1) ? 4 : 2); - - PASS(); -} - -/** As a friend, overflow the message queue for the LPN with own packets. - * - * Verify that the LPN doesn't terminate the friendship during the poll for - * messages. - */ -static void test_friend_overflow(void) -{ - bt_mesh_test_setup(); - - bt_mesh_friend_set(BT_MESH_FEATURE_ENABLED); - - ASSERT_OK_MSG(evt_wait(FRIEND_ESTABLISHED, K_SECONDS(5)), - "Friendship not established"); - evt_clear(FRIEND_POLLED); - - k_sleep(K_SECONDS(3)); - - LOG_INF("Testing overflow with only unsegmented messages..."); - - /* Fill the queue */ - for (int i = 0; i < CONFIG_BT_MESH_FRIEND_QUEUE_SIZE; i++) { - bt_mesh_test_send(friend_lpn_addr, 5, 0, K_NO_WAIT); - } - - /* Add one more message, which should overflow the queue and cause the - * first message to be discarded. - */ - bt_mesh_test_send(friend_lpn_addr, 5, 0, K_NO_WAIT); - - ASSERT_OK_MSG(evt_wait(FRIEND_POLLED, K_SECONDS(35)), - "Friend never polled"); - - /* LPN verifies that no more messages are in Friend Queue. */ - k_sleep(K_SECONDS(10)); - - LOG_INF("Testing overflow with unsegmented message preempting segmented one..."); - - /* Make room in the Friend Queue for only one unsegmented message. */ - bt_mesh_test_send(friend_lpn_addr, - BT_MESH_SDU_UNSEG_MAX * - (CONFIG_BT_MESH_FRIEND_QUEUE_SIZE - 1), - 0, K_SECONDS(1)), - bt_mesh_test_send(friend_lpn_addr, 5, 0, K_NO_WAIT); - /* This message should preempt the segmented one. */ - bt_mesh_test_send(friend_lpn_addr, 5, 0, K_NO_WAIT); - - ASSERT_OK_MSG(evt_wait(FRIEND_POLLED, K_SECONDS(35)), - "Friend never polled"); - - /* LPN verifies that there are no more messages in the Friend Queue. */ - k_sleep(K_SECONDS(10)); - - LOG_INF("Testing overflow with segmented message preempting another segmented..."); - - /* Make space in the Friend Queue for only 2 unsegmented messages so the next unsgemented - * message won't preempt this segmented message. - */ - bt_mesh_test_send(friend_lpn_addr, - BT_MESH_SDU_UNSEG_MAX * - (CONFIG_BT_MESH_FRIEND_QUEUE_SIZE - 2), - 0, K_SECONDS(1)); - bt_mesh_test_send(friend_lpn_addr, 5, 0, K_NO_WAIT); - /* This segmented message should preempt the previous segmented message. */ - bt_mesh_test_send(friend_lpn_addr, - BT_MESH_SDU_UNSEG_MAX * - (CONFIG_BT_MESH_FRIEND_QUEUE_SIZE - 2), - 0, K_SECONDS(1)); - /* This message should fit in Friend Queue as well. */ - bt_mesh_test_send(friend_lpn_addr, 5, 0, K_NO_WAIT); - - ASSERT_OK_MSG(evt_wait(FRIEND_POLLED, K_SECONDS(35)), - "Friend never polled"); - - if (atomic_test_bit(state, FRIEND_TERMINATED)) { - FAIL("Friendship terminated unexpectedly"); - } - - PASS(); -} - -/** Establish a friendship, wait for communication between the LPN and a mesh - * device to finish, then send group and virtual addr messages to the LPN. - * Let the LPN add another group message, then send to that as well. - */ -static void test_friend_group(void) -{ - uint16_t virtual_addr; - - bt_mesh_test_setup(); - - bt_mesh_friend_set(BT_MESH_FEATURE_ENABLED); - - ASSERT_OK_MSG(evt_wait(FRIEND_ESTABLISHED, K_SECONDS(5)), - "Friendship not established"); - evt_clear(FRIEND_POLLED); - - ASSERT_OK(bt_mesh_va_add(test_va_uuid, &virtual_addr)); - - /* The other mesh device will send its messages in the first poll */ - ASSERT_OK(evt_wait(FRIEND_POLLED, K_SECONDS(10))); - - k_sleep(K_SECONDS(2)); - - evt_clear(FRIEND_POLLED); - - /* Send a group message to the LPN */ - ASSERT_OK_MSG(bt_mesh_test_send(GROUP_ADDR, 5, 0, K_SECONDS(1)), - "Failed to send to LPN"); - /* Send a virtual message to the LPN */ - ASSERT_OK_MSG(bt_mesh_test_send(virtual_addr, 5, 0, K_SECONDS(1)), - "Failed to send to LPN"); - - /* Wait for the LPN to poll for each message, then for adding the - * group address: - */ - friend_wait_for_polls(3); - - /* Send a group message to an address the LPN added after the friendship - * was established. - */ - ASSERT_OK_MSG(bt_mesh_test_send(GROUP_ADDR + 1, 5, 0, K_SECONDS(1)), - "Failed to send to LPN"); - - evt_wait(FRIEND_POLLED, K_SECONDS(10)); - - PASS(); -} - - -/* Friend no-establish test functions */ - -/** Initialize as a friend and no friendships to be established. - */ -static void test_friend_no_est(void) -{ - bt_mesh_test_setup(); - bt_mesh_friend_set(BT_MESH_FEATURE_ENABLED); - - if (!evt_wait(FRIEND_ESTABLISHED, K_SECONDS(30))) { - FAIL("Friendship established unexpectedly"); - } - - PASS(); -} - -/* LPN test functions */ - -/** Enable the LPN role, and verify that the friendship is established. - * - * Verify that the friendship survives the first poll timeout. - */ -static void test_lpn_est(void) -{ - bt_mesh_test_setup(); - - /* This test is used to establish friendship with single lpn as well as - * with many lpn devices. If legacy advertiser is used friendship with - * many lpn devices is established normally due to bad precision of advertiser. - * If extended advertiser is used simultaneous lpn running causes the situation - * when Friend Request from several devices collide in emulated radio channel. - * This shift of start moment helps to avoid Friend Request collisions. - */ - k_sleep(K_MSEC(10 * get_device_nbr())); - - bt_mesh_lpn_set(true); - - ASSERT_OK_MSG(evt_wait(LPN_ESTABLISHED, K_SECONDS(5)), - "LPN not established"); - if (!evt_wait(LPN_TERMINATED, - K_MSEC(POLL_TIMEOUT_MS + 5 * MSEC_PER_SEC))) { - FAIL("Friendship terminated unexpectedly"); - } - - PASS(); -} - -/** As an LPN, exchange messages with the friend node. - * - * Verifies sending and receiving of unsegmented, segmented and multiple - * messages to and from the connected friend node. - */ -static void test_lpn_msg_frnd(void) -{ - bt_mesh_test_setup(); - - bt_mesh_lpn_set(true); - - ASSERT_OK_MSG(evt_wait(LPN_ESTABLISHED, K_SECONDS(5)), "LPN not established"); - /* LPN polls on establishment. Clear the poll state */ - evt_clear(LPN_POLLED); - - /* Give friend time to prepare the message */ - k_sleep(K_SECONDS(3)); - - /* Receive unsegmented message */ - ASSERT_OK_MSG(bt_mesh_lpn_poll(), "Poll failed"); - ASSERT_OK_MSG(bt_mesh_test_recv(5, cfg->addr, K_SECONDS(1)), "Failed to receive message"); - - /* Give friend time to prepare the message */ - k_sleep(K_SECONDS(3)); - - /* Receive segmented message */ - ASSERT_OK_MSG(bt_mesh_lpn_poll(), "Poll failed"); - ASSERT_OK_MSG(bt_mesh_test_recv(13, cfg->addr, K_SECONDS(2)), "Failed to receive message"); - - /* Give friend time to prepare the messages */ - k_sleep(K_SECONDS(3)); - - /* Receive two unsegmented messages */ - ASSERT_OK_MSG(bt_mesh_lpn_poll(), "Poll failed"); - ASSERT_OK_MSG(bt_mesh_test_recv(BT_MESH_SDU_UNSEG_MAX, cfg->addr, K_SECONDS(2)), - "Failed to receive message"); - ASSERT_OK_MSG(bt_mesh_test_recv(BT_MESH_SDU_UNSEG_MAX, cfg->addr, K_SECONDS(2)), - "Failed to receive message"); - - k_sleep(K_SECONDS(3)); - - /* Send an unsegmented message to the friend. - * Should not be affected by the LPN mode at all. - */ - ASSERT_OK_MSG(bt_mesh_test_send(friend_cfg.addr, 5, 0, K_MSEC(500)), - "Send to friend failed"); - - k_sleep(K_SECONDS(5)); - - /* Send a segmented message to the friend. Should trigger a poll for the - * ack. - */ - ASSERT_OK_MSG(bt_mesh_test_send(friend_cfg.addr, 15, 0, K_SECONDS(5)), - "Send to friend failed"); - - PASS(); -} - -/** As an LPN, exchange messages with a third party mesh node while in a - * friendship. - * - * Verifies sending and receiving of unsegmented and segmented messages to and - * from the third party node. - */ -static void test_lpn_msg_mesh(void) -{ - bt_mesh_test_setup(); - - bt_mesh_lpn_set(true); - - ASSERT_OK_MSG(evt_wait(LPN_ESTABLISHED, K_SECONDS(2)), "LPN not established"); - /* LPN polls on establishment. Clear the poll state */ - evt_clear(LPN_POLLED); - - /* Send an unsegmented message to a third mesh node. - * Should not be affected by the LPN mode at all. - */ - ASSERT_OK_MSG(bt_mesh_test_send(other_cfg.addr, 5, 0, K_MSEC(500)), - "Send to mesh failed"); - - /* Receive an unsegmented message back */ - k_sleep(K_SECONDS(1)); - ASSERT_OK(bt_mesh_lpn_poll()); - ASSERT_OK(bt_mesh_test_recv(5, cfg->addr, K_SECONDS(2))); - - k_sleep(K_SECONDS(1)); - - /* Send a segmented message to the mesh node. - * Should trigger a poll for the ack. - */ - ASSERT_OK_MSG(bt_mesh_test_send(other_cfg.addr, 15, 0, K_SECONDS(5)), - "Send to other failed"); - - /* Receive a segmented message back */ - k_sleep(K_SECONDS(1)); - ASSERT_OK(bt_mesh_lpn_poll()); - ASSERT_OK(bt_mesh_test_recv(15, cfg->addr, K_SECONDS(5))); - - /* Send an unsegmented message with friend credentials to a third mesh - * node. The friend shall relay it. - */ - test_model->pub->addr = other_cfg.addr; - test_model->pub->cred = true; /* Use friend credentials */ - test_model->pub->ttl = BT_MESH_TTL_DEFAULT; - - net_buf_simple_reset(test_model->pub->msg); - bt_mesh_model_msg_init(test_model->pub->msg, TEST_MSG_OP_1); - ASSERT_OK(bt_mesh_model_publish(test_model)); - - PASS(); -} - -/** As an LPN, establish and terminate a friendship with the same friend - * multiple times in a row to ensure that both parties are able to recover. - */ -static void test_lpn_re_est(void) -{ - bt_mesh_test_setup(); - - for (int i = 0; i < 4; i++) { - bt_mesh_lpn_set(true); - ASSERT_OK_MSG(evt_wait(LPN_ESTABLISHED, K_SECONDS(2)), - "LPN not established"); - - bt_mesh_lpn_set(false); - ASSERT_OK_MSG(evt_wait(LPN_TERMINATED, K_SECONDS(5)), - "LPN never terminated friendship"); - - k_sleep(K_SECONDS(2)); - } - - PASS(); -} - -/** Establish a friendship as an LPN, and verify that the friendship survives - * the first poll timeout without terminating - */ -static void test_lpn_poll(void) -{ - bt_mesh_test_setup(); - - bt_mesh_lpn_set(true); - ASSERT_OK_MSG(evt_wait(LPN_ESTABLISHED, K_SECONDS(5)), "LPN not established"); - evt_clear(LPN_POLLED); - - ASSERT_OK_MSG(evt_wait(LPN_POLLED, K_MSEC(POLL_TIMEOUT_MS)), - "LPN failed to poll before the timeout"); - - k_sleep(K_SECONDS(10)); - if (atomic_test_bit(state, LPN_TERMINATED)) { - FAIL("LPN terminated."); - } - - PASS(); -} - -/** Receive packets from a friend that overflowed its queue. Verify that the - * first packet is discarded because of the overflow. - */ -static void test_lpn_overflow(void) -{ - struct bt_mesh_test_msg msg; - int exp_seq; - int err; - - bt_mesh_test_setup(); - - bt_mesh_lpn_set(true); - ASSERT_OK_MSG(evt_wait(LPN_ESTABLISHED, K_SECONDS(5)), "LPN not established"); - evt_clear(LPN_POLLED); - - k_sleep(K_SECONDS(5)); - ASSERT_OK_MSG(bt_mesh_lpn_poll(), "Poll failed"); - - LOG_INF("Testing overflow with only unsegmented messages..."); - - for (int i = 0; i < CONFIG_BT_MESH_FRIEND_QUEUE_SIZE; i++) { - ASSERT_OK_MSG(bt_mesh_test_recv_msg(&msg, K_SECONDS(2)), - "Receive %d failed", i); - - if (msg.len != 5) { - FAIL("Message %d: Invalid length %d", i, msg.len); - } - - if (msg.ctx.recv_dst != cfg->addr) { - FAIL("Message %d: Invalid dst 0x%04x", i, - msg.ctx.recv_dst); - } - - /* The first message (with seq=1) should have been discarded by - * the friend, so the first message should have seq=2: - */ - if (msg.seq != i + 2) { - FAIL("Message %d: Invalid seq 0x%02x", i, msg.seq); - } - } - - /* Not expecting any more messages from friend */ - err = bt_mesh_test_recv_msg(&msg, K_SECONDS(10)); - if (!err) { - FAIL("Unexpected additional message 0x%02x from 0x%04x", - msg.seq, msg.ctx.addr); - } - - LOG_INF("Testing overflow with unsegmented message preempting segmented one..."); - - ASSERT_OK_MSG(bt_mesh_lpn_poll(), "Poll failed"); - - /* Last seq from the previous step. */ - exp_seq = CONFIG_BT_MESH_FRIEND_QUEUE_SIZE + 1; - - exp_seq += 2; /* Skipping the first message in Friend Queue. */ - ASSERT_OK_MSG(bt_mesh_test_recv_msg(&msg, K_SECONDS(2)), - "Receive first unseg msg failed"); - ASSERT_EQUAL(5, msg.len); - ASSERT_EQUAL(cfg->addr, msg.ctx.recv_dst); - ASSERT_EQUAL(exp_seq, msg.seq); - - exp_seq++; - ASSERT_OK_MSG(bt_mesh_test_recv_msg(&msg, K_SECONDS(2)), - "Receive the second unseg msg failed"); - ASSERT_EQUAL(5, msg.len); - ASSERT_EQUAL(cfg->addr, msg.ctx.recv_dst); - ASSERT_EQUAL(exp_seq, msg.seq); - - /* Not expecting any more messages from friend */ - err = bt_mesh_test_recv_msg(&msg, K_SECONDS(10)); - if (!err) { - FAIL("Unexpected additional message 0x%02x from 0x%04x", - msg.seq, msg.ctx.addr); - } - - LOG_INF("Testing overflow with segmented message preempting another segmented..."); - - ASSERT_OK_MSG(bt_mesh_lpn_poll(), "Poll failed"); - - exp_seq += 2; /* Skipping the first message in Friend Queue. */ - ASSERT_OK_MSG(bt_mesh_test_recv_msg(&msg, K_SECONDS(2)), - "Receive the first unseg msg failed"); - ASSERT_EQUAL(5, msg.len); - ASSERT_EQUAL(cfg->addr, msg.ctx.recv_dst); - ASSERT_EQUAL(exp_seq, msg.seq); - - exp_seq++; - ASSERT_OK_MSG(bt_mesh_test_recv_msg(&msg, K_SECONDS(20)), - "Receive the seg msg failed"); - ASSERT_EQUAL(BT_MESH_SDU_UNSEG_MAX * (CONFIG_BT_MESH_FRIEND_QUEUE_SIZE - 2), - msg.len); - ASSERT_EQUAL(cfg->addr, msg.ctx.recv_dst); - ASSERT_EQUAL(exp_seq, msg.seq); - - ASSERT_OK_MSG(bt_mesh_test_recv_msg(&msg, K_SECONDS(2)), - "Receive the second unseg msg failed"); - ASSERT_EQUAL(5, msg.len); - ASSERT_EQUAL(cfg->addr, msg.ctx.recv_dst); - - /* Not expecting any more messages from friend */ - err = bt_mesh_test_recv_msg(&msg, K_SECONDS(10)); - if (!err) { - FAIL("Unexpected additional message 0x%02x from 0x%04x", - msg.seq, msg.ctx.addr); - } - - PASS(); -} - -/** As an LPN, receive packets on group and virtual addresses from mesh device - * and friend. Then, add a second group address (while the friendship is - * established), and receive on that as well. - */ -static void test_lpn_group(void) -{ - struct bt_mesh_test_msg msg; - uint16_t vaddr; - uint8_t status = 0; - int err; - - bt_mesh_test_setup(); - - err = bt_mesh_cfg_cli_mod_sub_add(0, cfg->addr, cfg->addr, GROUP_ADDR, - TEST_MOD_ID, &status); - if (err || status) { - FAIL("Group addr add failed with err %d status 0x%x", err, - status); - } - - err = bt_mesh_cfg_cli_mod_sub_va_add(0, cfg->addr, cfg->addr, test_va_uuid, - TEST_MOD_ID, &vaddr, &status); - if (err || status) { - FAIL("VA addr add failed with err %d status 0x%x", err, status); - } - - bt_mesh_lpn_set(true); - ASSERT_OK_MSG(evt_wait(LPN_ESTABLISHED, K_SECONDS(5)), "LPN not established"); - evt_clear(LPN_POLLED); - - /* Send a message to the other mesh device to indicate that the - * friendship has been established. Give the other device a time to - * start up first. - */ - k_sleep(K_MSEC(10)); - ASSERT_OK(bt_mesh_test_send(other_cfg.addr, 5, 0, K_SECONDS(1))); - - k_sleep(K_SECONDS(5)); - ASSERT_OK_MSG(bt_mesh_lpn_poll(), "Poll failed"); - - /* From other device */ - ASSERT_OK(bt_mesh_test_recv_msg(&msg, K_SECONDS(1))); - if (msg.ctx.recv_dst != GROUP_ADDR || msg.ctx.addr != other_cfg.addr) { - FAIL("Unexpected message: 0x%04x -> 0x%04x", msg.ctx.addr, - msg.ctx.recv_dst); - } - - ASSERT_OK(bt_mesh_test_recv_msg(&msg, K_SECONDS(1))); - if (msg.ctx.recv_dst != vaddr || msg.ctx.addr != other_cfg.addr) { - FAIL("Unexpected message: 0x%04x -> 0x%04x", msg.ctx.addr, - msg.ctx.recv_dst); - } - - k_sleep(K_SECONDS(5)); - ASSERT_OK_MSG(bt_mesh_lpn_poll(), "Poll failed"); - - /* From friend */ - ASSERT_OK(bt_mesh_test_recv_msg(&msg, K_SECONDS(1))); - if (msg.ctx.recv_dst != GROUP_ADDR || msg.ctx.addr != friend_cfg.addr) { - FAIL("Unexpected message: 0x%04x -> 0x%04x", msg.ctx.addr, - msg.ctx.recv_dst); - } - - ASSERT_OK(bt_mesh_test_recv_msg(&msg, K_SECONDS(1))); - if (msg.ctx.recv_dst != vaddr || msg.ctx.addr != friend_cfg.addr) { - FAIL("Unexpected message: 0x%04x -> 0x%04x", msg.ctx.addr, - msg.ctx.recv_dst); - } - - k_sleep(K_SECONDS(1)); - - LOG_INF("Adding second group addr"); - - /* Add a new group addr, then receive on it to ensure that the friend - * has added it to the subscription list. - */ - err = bt_mesh_cfg_cli_mod_sub_add(0, cfg->addr, cfg->addr, GROUP_ADDR + 1, - TEST_MOD_ID, &status); - if (err || status) { - FAIL("Group addr add failed with err %d status 0x%x", err, - status); - } - - k_sleep(K_SECONDS(5)); - ASSERT_OK_MSG(bt_mesh_lpn_poll(), "Poll failed"); - - /* From friend on second group address */ - ASSERT_OK(bt_mesh_test_recv_msg(&msg, K_SECONDS(1))); - if (msg.ctx.recv_dst != GROUP_ADDR + 1 || - msg.ctx.addr != friend_cfg.addr) { - FAIL("Unexpected message: 0x%04x -> 0x%04x", msg.ctx.addr, - msg.ctx.recv_dst); - } - - PASS(); -} - -/** As an LPN, send packets to own address to ensure that this is handled by - * loopback mechanism, and ignored by friend. - * - * Adds test coverage for regression in #30657. - */ -static void test_lpn_loopback(void) -{ - struct bt_mesh_test_msg msg; - uint16_t vaddr; - uint8_t status = 0; - int err; - - bt_mesh_test_setup(); - - err = bt_mesh_cfg_cli_mod_sub_add(0, cfg->addr, cfg->addr, GROUP_ADDR, - TEST_MOD_ID, &status); - if (err || status) { - FAIL("Group addr add failed with err %d status 0x%x", err, - status); - } - - err = bt_mesh_cfg_cli_mod_sub_va_add(0, cfg->addr, cfg->addr, test_va_uuid, - TEST_MOD_ID, &vaddr, &status); - if (err || status) { - FAIL("VA addr add failed with err %d status 0x%x", err, status); - } - - bt_mesh_lpn_set(true); - ASSERT_OK_MSG(evt_wait(LPN_ESTABLISHED, K_SECONDS(5)), - "LPN not established"); - evt_clear(LPN_POLLED); - - k_sleep(K_SECONDS(1)); - - /* Loopback on unicast, shouldn't even leave the device */ - ASSERT_OK(bt_mesh_test_send_async(cfg->addr, 5, 0, NULL, NULL)); - ASSERT_OK(bt_mesh_test_recv(5, cfg->addr, K_SECONDS(1))); - - /* Loopback on group address, should not come back from the friend */ - ASSERT_OK(bt_mesh_test_send_async(GROUP_ADDR, 5, 0, NULL, NULL)); - ASSERT_OK(bt_mesh_test_recv(5, GROUP_ADDR, K_SECONDS(1))); - - ASSERT_OK_MSG(bt_mesh_lpn_poll(), "Poll failed"); - err = bt_mesh_test_recv_msg(&msg, K_SECONDS(2)); - if (err != -ETIMEDOUT) { - FAIL("Unexpected receive status: %d", err); - } - - /* Loopback on virtual address, should not come back from the friend */ - ASSERT_OK(bt_mesh_test_send_async(vaddr, 5, 0, NULL, NULL)); - ASSERT_OK(bt_mesh_test_recv(5, vaddr, K_SECONDS(1))); - - k_sleep(K_SECONDS(2)); - - /* Poll the friend and make sure we don't receive any messages: */ - ASSERT_OK_MSG(bt_mesh_lpn_poll(), "Poll failed"); - err = bt_mesh_test_recv_msg(&msg, K_SECONDS(5)); - if (err != -ETIMEDOUT) { - FAIL("Unexpected receive status: %d", err); - } - - PASS(); -} - -/* Mesh device test functions */ - -/** Without engaging in a friendship, communicate with an LPN through a friend - * node. - */ -static void test_other_msg(void) -{ - bt_mesh_test_setup(); - - /* Receive an unsegmented message from the LPN. */ - ASSERT_OK_MSG(bt_mesh_test_recv(5, cfg->addr, K_SECONDS(4)), - "Failed to receive from LPN"); - - /* Send an unsegmented message to the LPN */ - ASSERT_OK_MSG(bt_mesh_test_send(LPN_ADDR_START, 5, FORCE_SEGMENTATION, K_FOREVER), - "Failed to send to LPN"); - - /* Receive a segmented message from the LPN. */ - ASSERT_OK_MSG(bt_mesh_test_recv(15, cfg->addr, K_SECONDS(10)), - "Failed to receive from LPN"); - - /* Send a segmented message to the friend. Should trigger a poll for the - * ack. - */ - ASSERT_OK_MSG(bt_mesh_test_send(LPN_ADDR_START, 15, FORCE_SEGMENTATION, K_FOREVER), - "Send to LPN failed"); - - /* Receive an unsegmented message from the LPN, originally sent with - * friend credentials. - */ - ASSERT_OK_MSG(bt_mesh_test_recv(1, cfg->addr, K_SECONDS(10)), - "Failed to receive from LPN"); - - PASS(); -} - -/** Without engaging in a friendship, send group and virtual addr messages to - * the LPN. - */ -static void test_other_group(void) -{ - uint16_t virtual_addr; - - bt_mesh_test_setup(); - - ASSERT_OK(bt_mesh_va_add(test_va_uuid, &virtual_addr)); - - /* Wait for LPN to send us a message after establishing the friendship */ - ASSERT_OK(bt_mesh_test_recv(5, cfg->addr, K_SECONDS(1))); - - /* Send a group message to the LPN */ - ASSERT_OK_MSG(bt_mesh_test_send(GROUP_ADDR, 5, 0, K_SECONDS(1)), - "Failed to send to LPN"); - /* Send a virtual message to the LPN */ - ASSERT_OK_MSG(bt_mesh_test_send(virtual_addr, 5, 0, K_SECONDS(1)), - "Failed to send to LPN"); - - PASS(); -} - -/** LPN disable test. - * - * Check that toggling lpn_set() results in correct disabled state - */ -static void test_lpn_disable(void) -{ - bt_mesh_test_setup(); - - bt_mesh_lpn_set(true); - bt_mesh_lpn_set(false); - - if (!evt_wait(LPN_POLLED, K_SECONDS(30))) { - FAIL("LPN connection polled unexpectedly"); - } - - PASS(); -} - -/** LPN terminate cb test. - * - * Check that terminate cb is not triggered when there is no established - * connection. - */ -static void test_lpn_term_cb_check(void) -{ - bt_mesh_test_setup(); - - bt_mesh_lpn_set(true); - ASSERT_OK_MSG(evt_wait(LPN_POLLED, K_MSEC(1000)), "Friend never polled"); - bt_mesh_lpn_set(false); - - if (!evt_wait(LPN_TERMINATED, K_SECONDS(30))) { - FAIL("LPN terminate CB triggered unexpectedly"); - } - - PASS(); -} - -#define TEST_CASE(role, name, description) \ - { \ - .test_id = "friendship_" #role "_" #name, \ - .test_descr = description, \ - .test_post_init_f = test_##role##_init, \ - .test_tick_f = bt_mesh_test_timeout, \ - .test_main_f = test_##role##_##name, \ - } - -static const struct bst_test_instance test_connect[] = { - TEST_CASE(friend, est, "Friend: establish friendship"), - TEST_CASE(friend, est_multi, "Friend: establish multiple friendships"), - TEST_CASE(friend, msg, "Friend: message exchange"), - TEST_CASE(friend, overflow, "Friend: message queue overflow"), - TEST_CASE(friend, group, "Friend: send to group addrs"), - TEST_CASE(friend, no_est, "Friend: do not establish friendship"), - - TEST_CASE(lpn, est, "LPN: establish friendship"), - TEST_CASE(lpn, msg_frnd, "LPN: message exchange with friend"), - TEST_CASE(lpn, msg_mesh, "LPN: message exchange with mesh"), - TEST_CASE(lpn, re_est, "LPN: re-establish friendship"), - TEST_CASE(lpn, poll, "LPN: poll before timeout"), - TEST_CASE(lpn, overflow, "LPN: message queue overflow"), - TEST_CASE(lpn, group, "LPN: receive on group addrs"), - TEST_CASE(lpn, loopback, "LPN: send to loopback addrs"), - TEST_CASE(lpn, disable, "LPN: disable LPN"), - TEST_CASE(lpn, term_cb_check, "LPN: no terminate cb trigger"), - - TEST_CASE(other, msg, "Other mesh device: message exchange"), - TEST_CASE(other, group, "Other mesh device: send to group addrs"), - BSTEST_END_MARKER -}; - -struct bst_test_list *test_friendship_install(struct bst_test_list *tests) -{ - tests = bst_add_tests(tests, test_connect); - return tests; -} diff --git a/tests/bluetooth/bsim/mesh/src/test_heartbeat.c b/tests/bluetooth/bsim/mesh/src/test_heartbeat.c deleted file mode 100644 index 00be5683e20..00000000000 --- a/tests/bluetooth/bsim/mesh/src/test_heartbeat.c +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright (c) 2021 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include "mesh_test.h" -#include "argparse.h" -#include "mesh/net.h" -#include "mesh/heartbeat.h" -#include "mesh/lpn.h" - -#define LOG_MODULE_NAME test_heartbeat - -#include -LOG_MODULE_REGISTER(LOG_MODULE_NAME); - -#define WAIT_TIME 60 /*seconds*/ -#define SUBSCRIBER_ADDR 0x00fe -#define SUBSCRIBE_PERIOD_SEC 30 -#define PUBLISHER_ADDR_START 0x0001 -#define PUBLISH_PERIOD_SEC 1 -#define PUBLISH_MSG_CNT 10 -#define PUBLISH_TTL 0 -#define EXPECTED_HB_HOPS 0x01 - -static uint16_t pub_addr = BT_MESH_ADDR_UNASSIGNED; - -static const struct bt_mesh_test_cfg subscribe_cfg = { - .addr = SUBSCRIBER_ADDR, - .dev_key = { 0xff }, -}; -static struct bt_mesh_test_cfg pub_cfg; -static int pub_cnt; -struct k_sem sem; - -static void test_publish_init(void) -{ - pub_cfg.addr = PUBLISHER_ADDR_START + get_device_nbr(); - pub_cfg.dev_key[0] = get_device_nbr(); - bt_mesh_test_cfg_set(&pub_cfg, WAIT_TIME); -} - -static void test_subscribe_init(void) -{ - bt_mesh_test_cfg_set(&subscribe_cfg, WAIT_TIME); -} - -static struct sub_context { - uint8_t count; - uint8_t min_hops; - uint8_t max_hops; -} sub_ctx = { - .count = 0, - .min_hops = 0xFF, - .max_hops = 0, -}; - -static void sub_hb_recv_cb(const struct bt_mesh_hb_sub *sub, uint8_t hops, uint16_t feat) -{ - LOG_INF("Heartbeat received from addr: 0x%04x", sub->src); - - ASSERT_EQUAL(PUBLISHER_ADDR_START, sub->src); - ASSERT_EQUAL(pub_addr, sub->dst); - ASSERT_EQUAL(SUBSCRIBE_PERIOD_SEC, sub->period); - ASSERT_TRUE(sub->remaining <= SUBSCRIBE_PERIOD_SEC); - ASSERT_EQUAL(sub_ctx.count + 1, sub->count); - ASSERT_EQUAL(hops, EXPECTED_HB_HOPS); - - uint16_t feature = 0; - - if (bt_mesh_relay_get() == BT_MESH_RELAY_ENABLED) { - feature |= BT_MESH_FEAT_RELAY; - } - - if (bt_mesh_gatt_proxy_get() == BT_MESH_GATT_PROXY_ENABLED) { - feature |= BT_MESH_FEAT_PROXY; - } - - if (bt_mesh_friend_get() == BT_MESH_FRIEND_ENABLED) { - feature |= BT_MESH_FEAT_FRIEND; - } - - if (bt_mesh_lpn_established()) { - feature |= BT_MESH_FEAT_LOW_POWER; - } - - ASSERT_EQUAL(feature, feat); - - sub_ctx.count++; - sub_ctx.min_hops = MIN(sub_ctx.min_hops, sub->min_hops); - sub_ctx.max_hops = MAX(sub_ctx.max_hops, sub->max_hops); -} - -static void sub_hb_end_cb(const struct bt_mesh_hb_sub *sub) -{ - LOG_INF("Heartbeat subscription has ended"); - ASSERT_EQUAL(PUBLISHER_ADDR_START, sub->src); - ASSERT_EQUAL(pub_addr, sub->dst); - ASSERT_EQUAL(SUBSCRIBE_PERIOD_SEC, sub->period); - ASSERT_EQUAL(0, sub->remaining); - ASSERT_EQUAL(PUBLISH_MSG_CNT, sub->count); - ASSERT_EQUAL(sub_ctx.count, sub->count); - ASSERT_EQUAL(sub_ctx.min_hops, sub->min_hops); - ASSERT_EQUAL(sub_ctx.max_hops, sub->max_hops); - PASS(); -} - -static void pub_hb_sent_cb(const struct bt_mesh_hb_pub *pub) -{ - LOG_INF("Heartbeat publication has ended"); - - pub_cnt--; - - ASSERT_EQUAL(pub_addr, pub->dst); - ASSERT_EQUAL(pub_cnt, pub->count); - ASSERT_EQUAL(PUBLISH_PERIOD_SEC, pub->period); - ASSERT_EQUAL(0, pub->net_idx); - ASSERT_EQUAL(PUBLISH_TTL, pub->ttl); - ASSERT_EQUAL(BT_MESH_FEAT_SUPPORTED, pub->feat); - - if (pub_cnt == 0) { - k_sem_give(&sem); - } - - if (pub_cnt < 0) { - LOG_ERR("Published more times than expected"); - FAIL(); - } -} - -BT_MESH_HB_CB_DEFINE(hb_cb) = { - .recv = sub_hb_recv_cb, - .sub_end = sub_hb_end_cb, - .pub_sent = pub_hb_sent_cb -}; - -static void publish_common(void) -{ - bt_mesh_test_setup(); - struct bt_mesh_hb_pub new_pub = { - .dst = pub_addr, - .count = PUBLISH_MSG_CNT, - .period = PUBLISH_PERIOD_SEC, - .net_idx = 0, - .ttl = PUBLISH_TTL, - .feat = BT_MESH_FEAT_SUPPORTED - }; - - pub_cnt = PUBLISH_MSG_CNT; - bt_mesh_hb_pub_set(&new_pub); -} - -static void publish_process(void) -{ - k_sem_init(&sem, 0, 1); - publish_common(); - /* +1 to avoid boundary time rally */ - if (k_sem_take(&sem, K_SECONDS(PUBLISH_PERIOD_SEC * (PUBLISH_MSG_CNT + 1)))) { - LOG_ERR("Publishing timed out"); - FAIL(); - } -} - -static void test_publish_unicast(void) -{ - pub_addr = SUBSCRIBER_ADDR; - publish_process(); - - PASS(); -} - -static void test_publish_all(void) -{ - pub_addr = BT_MESH_ADDR_ALL_NODES; - publish_process(); - - PASS(); -} - -static void subscribe_commmon(void) -{ - bt_mesh_test_setup(); - bt_mesh_hb_sub_set(PUBLISHER_ADDR_START, pub_addr, SUBSCRIBE_PERIOD_SEC); -} - -static void test_subscribe_unicast(void) -{ - pub_addr = SUBSCRIBER_ADDR; - subscribe_commmon(); -} - -static void test_subscribe_all(void) -{ - pub_addr = BT_MESH_ADDR_ALL_NODES; - subscribe_commmon(); -} - -#define TEST_CASE(role, name, description) \ - { \ - .test_id = "heartbeat_" #role "_" #name, \ - .test_descr = description, \ - .test_post_init_f = test_##role##_init, \ - .test_tick_f = bt_mesh_test_timeout, \ - .test_main_f = test_##role##_##name, \ - } - -static const struct bst_test_instance test_connect[] = { - TEST_CASE(publish, unicast, "Heartbeat: Publish heartbeat to unicast"), - TEST_CASE(subscribe, unicast, "Heartbeat: Subscribe to heartbeat from unicast"), - TEST_CASE(publish, all, "Heartbeat: Publish heartbeat to all nodes"), - TEST_CASE(subscribe, all, "Heartbeat: Subscribe to heartbeat all nodes"), - BSTEST_END_MARKER -}; - -struct bst_test_list *test_heartbeat_install(struct bst_test_list *tests) -{ - tests = bst_add_tests(tests, test_connect); - return tests; -} diff --git a/tests/bluetooth/bsim/mesh/src/test_iv_index.c b/tests/bluetooth/bsim/mesh/src/test_iv_index.c deleted file mode 100644 index 8c0dde73071..00000000000 --- a/tests/bluetooth/bsim/mesh/src/test_iv_index.c +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "mesh_test.h" -#include "mesh/net.h" - -#define LOG_MODULE_NAME test_ivi - -#include -LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL_INF); - -#define WAIT_TIME 60 /*seconds*/ -#define TEST_IV_IDX 100 -#define BCN_IV_IN_PROGRESS true -#define BCN_IV_IN_IDLE false - -extern struct bt_mesh_net bt_mesh; - -static const struct bt_mesh_test_cfg ivu_cfg = { - .addr = 0x0001, - .dev_key = { 0x01 }, -}; - -static void async_send_end(int err, void *data) -{ - struct k_sem *sem = data; - - if (sem) { - k_sem_give(sem); - } -} - -static const struct bt_mesh_send_cb async_send_cb = { - .end = async_send_end, -}; - -static void test_ivu_init(void) -{ - bt_mesh_test_cfg_set(&ivu_cfg, WAIT_TIME); -} - -static void emulate_recovery_timeout(void) -{ - k_work_cancel_delayable(&bt_mesh.ivu_timer); - bt_mesh.ivu_duration = 2 * BT_MESH_IVU_MIN_HOURS; -} - -static void test_ivu_recovery(void) -{ - bt_mesh_test_setup(); - - bt_mesh.iv_index = TEST_IV_IDX; - - atomic_set_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS); - - /* Already in IV Update in Progress state */ - ASSERT_FALSE(bt_mesh_net_iv_update(TEST_IV_IDX, BCN_IV_IN_PROGRESS)); - - /* Out of sync */ - ASSERT_FALSE(bt_mesh_net_iv_update(TEST_IV_IDX - 1, BCN_IV_IN_IDLE)); - ASSERT_FALSE(bt_mesh_net_iv_update(TEST_IV_IDX + 43, BCN_IV_IN_IDLE)); - - /* Start recovery */ - ASSERT_TRUE(bt_mesh_net_iv_update(TEST_IV_IDX + 2, BCN_IV_IN_IDLE)); - ASSERT_EQUAL(TEST_IV_IDX + 2, bt_mesh.iv_index); - ASSERT_FALSE(atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS)); - - /* Start recovery before minimum delay */ - ASSERT_FALSE(bt_mesh_net_iv_update(TEST_IV_IDX + 4, BCN_IV_IN_IDLE)); - - emulate_recovery_timeout(); - bt_mesh.iv_index = TEST_IV_IDX; - - atomic_clear_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS); - - /* Already in IV normal mode */ - ASSERT_FALSE(bt_mesh_net_iv_update(TEST_IV_IDX, BCN_IV_IN_IDLE)); - - /* Out of sync */ - ASSERT_FALSE(bt_mesh_net_iv_update(TEST_IV_IDX - 1, BCN_IV_IN_IDLE)); - ASSERT_FALSE(bt_mesh_net_iv_update(TEST_IV_IDX + 43, BCN_IV_IN_IDLE)); - - /* Start recovery */ - ASSERT_TRUE(bt_mesh_net_iv_update(TEST_IV_IDX + 1, BCN_IV_IN_IDLE)); - ASSERT_EQUAL(TEST_IV_IDX + 1, bt_mesh.iv_index); - ASSERT_FALSE(atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS)); - - /* Start recovery before minimum delay */ - ASSERT_FALSE(bt_mesh_net_iv_update(TEST_IV_IDX + 4, BCN_IV_IN_IDLE)); - - PASS(); -} - -static void test_ivu_normal(void) -{ - bt_mesh_test_setup(); - bt_mesh.iv_index = TEST_IV_IDX; - bt_mesh.seq = 100; - atomic_set_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS); - - /* update before minimum duration */ - ASSERT_FALSE(bt_mesh_net_iv_update(TEST_IV_IDX, BCN_IV_IN_IDLE)); - /* moving back into the normal mode */ - bt_mesh.ivu_duration = BT_MESH_IVU_MIN_HOURS; - ASSERT_TRUE(bt_mesh_net_iv_update(TEST_IV_IDX, BCN_IV_IN_IDLE)); - ASSERT_FALSE(atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS)); - ASSERT_EQUAL(TEST_IV_IDX, bt_mesh.iv_index); - ASSERT_EQUAL(0, bt_mesh.seq); - - bt_mesh.seq = 100; - /* update before minimum duration */ - ASSERT_FALSE(bt_mesh_net_iv_update(TEST_IV_IDX + 1, BCN_IV_IN_PROGRESS)); - /* moving into the IV update mode */ - bt_mesh.ivu_duration = BT_MESH_IVU_MIN_HOURS; - ASSERT_TRUE(bt_mesh_net_iv_update(TEST_IV_IDX + 1, BCN_IV_IN_PROGRESS)); - ASSERT_TRUE(atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS)); - ASSERT_EQUAL(TEST_IV_IDX + 1, bt_mesh.iv_index); - ASSERT_EQUAL(100, bt_mesh.seq); - - PASS(); -} - -static void test_ivu_deferring(void) -{ - struct k_sem sem; - - k_sem_init(&sem, 0, 1); - bt_mesh_test_setup(); - bt_mesh.iv_index = TEST_IV_IDX; - atomic_set_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS); - bt_mesh.ivu_duration = BT_MESH_IVU_MIN_HOURS; - - ASSERT_OK(bt_mesh_test_send_async(0x0002, 20, FORCE_SEGMENTATION, &async_send_cb, &sem)); - ASSERT_FALSE(bt_mesh_net_iv_update(TEST_IV_IDX, BCN_IV_IN_IDLE)); - ASSERT_TRUE(atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS)); - - ASSERT_OK(k_sem_take(&sem, K_SECONDS(10))); - ASSERT_FALSE(atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS)); - - PASS(); -} - -#define TEST_CASE(role, name, description) \ - { \ - .test_id = "ivi_" #role "_" #name, \ - .test_descr = description, \ - .test_pre_init_f = test_##role##_init, \ - .test_tick_f = bt_mesh_test_timeout, \ - .test_main_f = test_##role##_##name, \ - } - -static const struct bst_test_instance test_ivi[] = { - TEST_CASE(ivu, recovery, "IVI: IV recovery procedure"), - TEST_CASE(ivu, normal, "IVI: IV update procedure"), - TEST_CASE(ivu, deferring, "IVI: deferring of the IV update procedure"), - - BSTEST_END_MARKER -}; - -struct bst_test_list *test_ivi_install(struct bst_test_list *tests) -{ - tests = bst_add_tests(tests, test_ivi); - return tests; -} diff --git a/tests/bluetooth/bsim/mesh/src/test_lcd.c b/tests/bluetooth/bsim/mesh/src/test_lcd.c deleted file mode 100644 index 7797a185474..00000000000 --- a/tests/bluetooth/bsim/mesh/src/test_lcd.c +++ /dev/null @@ -1,411 +0,0 @@ -/* - * Copyright (c) 2023 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - * - * Large Composition Data test - */ - -#include "mesh_test.h" - -#include -#include - -#include - -#include -#include - -LOG_MODULE_REGISTER(test_lcd, LOG_LEVEL_INF); - -#define CLI_ADDR 0x7728 -#define SRV_ADDR 0x18f8 -#define WAIT_TIME 60 /* seconds */ - -/* Length of additional status fields (offset, page and total size) */ -#define LCD_STATUS_FIELDS_LEN 5 -#define DUMMY_2_BYTE_OP BT_MESH_MODEL_OP_2(0xff, 0xff) -#define BT_MESH_LCD_PAYLOAD_MAX \ - (BT_MESH_TX_SDU_MAX - BT_MESH_MODEL_OP_LEN(DUMMY_2_BYTE_OP) - \ - BT_MESH_MIC_SHORT) /* 378 bytes */ - -#define TEST_MODEL_CNT_CB(_dummy_op, _metadata) \ -{ \ - .id = 0x1234, \ - .pub = NULL, \ - .keys = NULL, \ - .keys_cnt = 0, \ - .groups = NULL, \ - .groups_cnt = 0, \ - .op = _dummy_op, \ - .cb = NULL, \ - .user_data = NULL, \ - .metadata = _metadata, \ -} - -const struct bt_mesh_model_op dummy_op[] = { - { 0xfeed, BT_MESH_LEN_MIN(1), NULL }, - { 0xface, BT_MESH_LEN_MIN(1), NULL }, - BT_MESH_MODEL_OP_END, -}; - -static struct bt_mesh_models_metadata_entry *dummy_meta_entry[] = {}; - -/* Empty elements to create large composition/meta data */ -#define DUMMY_ELEM(i, _) BT_MESH_ELEM((i) + 2, \ - MODEL_LIST(TEST_MODEL_CNT_CB(dummy_op, dummy_meta_entry)), BT_MESH_MODEL_NONE) - -static const struct bt_mesh_test_cfg cli_cfg = { - .addr = CLI_ADDR, - .dev_key = {0xaa}, -}; - -static const struct bt_mesh_test_cfg srv_cfg = { - .addr = SRV_ADDR, - .dev_key = {0xab}, -}; - -static struct bt_mesh_prov prov; -static struct bt_mesh_cfg_cli cfg_cli; - -/* Creates enough composition data to send a max SDU comp status message + 1 byte */ -static struct bt_mesh_elem elements_1[] = { - BT_MESH_ELEM(1, - MODEL_LIST(BT_MESH_MODEL_CFG_SRV, - BT_MESH_MODEL_CFG_CLI(&cfg_cli), - BT_MESH_MODEL_LARGE_COMP_DATA_CLI, - BT_MESH_MODEL_LARGE_COMP_DATA_SRV), - BT_MESH_MODEL_NONE), - LISTIFY(88, DUMMY_ELEM, (,)), -}; - -/* Creates enough metadata to send a max SDU metadata status message + 1 byte */ -static struct bt_mesh_elem elements_2[] = { - BT_MESH_ELEM(1, - MODEL_LIST(BT_MESH_MODEL_CFG_SRV, - BT_MESH_MODEL_CFG_CLI(&cfg_cli), - BT_MESH_MODEL_LARGE_COMP_DATA_CLI, - BT_MESH_MODEL_LARGE_COMP_DATA_SRV), - BT_MESH_MODEL_NONE), - LISTIFY(186, DUMMY_ELEM, (,)), -}; - -static const struct bt_mesh_comp comp_1 = { - .cid = TEST_VND_COMPANY_ID, - .vid = 0xabba, - .pid = 0xdead, - .elem = elements_1, - .elem_count = ARRAY_SIZE(elements_1), -}; - -static const struct bt_mesh_comp comp_2 = { - .cid = TEST_VND_COMPANY_ID, - .elem = elements_2, - .elem_count = ARRAY_SIZE(elements_2), -}; - -static void prov_and_conf(struct bt_mesh_test_cfg cfg) -{ - uint8_t status; - - ASSERT_OK(bt_mesh_provision(test_net_key, 0, 0, 0, cfg.addr, cfg.dev_key)); - - /* Check device key by adding appkey. */ - ASSERT_OK(bt_mesh_cfg_cli_app_key_add(0, cfg.addr, 0, 0, test_app_key, &status)); - ASSERT_OK(status); -} - -/* Since nodes self-provision in this test and the LCD model uses device keys for crypto, the - * server node must be added to the client CDB manually. - */ -static void target_node_alloc(struct bt_mesh_comp comp, struct bt_mesh_test_cfg cfg) -{ - struct bt_mesh_cdb_node *node; - - node = bt_mesh_cdb_node_alloc(test_va_uuid, cfg.addr, comp.elem_count, 0); - ASSERT_TRUE(node); - memcpy(node->dev_key, cfg.dev_key, 16); -} - -/* Assert equality between local data and merged sample data */ -static void merge_and_compare_assert(struct net_buf_simple *sample1, struct net_buf_simple *sample2, - struct net_buf_simple *local_data) -{ - uint8_t merged_data[sample1->len + sample2->len]; - - memcpy(&merged_data[0], sample1->data, sample1->len); - memcpy(&merged_data[sample1->len], sample2->data, sample2->len); - ASSERT_TRUE(memcmp(local_data->data, merged_data, ARRAY_SIZE(merged_data)) == 0); -} - -/* Assert that the received status fields are equal to local values. Buffer state is saved. - */ -static void verify_status_fields(struct net_buf_simple *srv_rsp, uint8_t page_local, - uint16_t offset_local, uint16_t total_size_local) -{ - uint8_t byte_value[LCD_STATUS_FIELDS_LEN]; - - byte_value[0] = page_local; - memcpy(&byte_value[1], &offset_local, 2); - memcpy(&byte_value[3], &total_size_local, 2); - - ASSERT_TRUE(memcmp(srv_rsp->data, byte_value, LCD_STATUS_FIELDS_LEN) == 0); -} - -/* Compare response data with local data. - * Note: - * * srv_rsp: Status field data (5 bytes) is removed form buffer. - * * local_data: state is preserved. - * * prev_len: Set to NULL if irrelevant. Used for split and merge testing. - */ -static void rsp_equals_local_data_assert(uint16_t addr, struct net_buf_simple *srv_rsp, - struct net_buf_simple *local_data, uint8_t page, - uint16_t offset, uint16_t total_size, uint16_t *prev_len) -{ - struct net_buf_simple_state local_state = {0}; - - /* Check that status field data matches local values. */ - verify_status_fields(srv_rsp, page, offset, total_size); - /* Remove field data bytes before comparing comp data */ - net_buf_simple_pull_mem(srv_rsp, LCD_STATUS_FIELDS_LEN); - - net_buf_simple_save(local_data, &local_state); - - if (prev_len != NULL) { - size_t len = *prev_len; - - net_buf_simple_pull_mem(local_data, len); - } - - /* Check that local and rsp data are equal */ - ASSERT_TRUE(memcmp(srv_rsp->data, local_data->data, srv_rsp->len) == 0); - - net_buf_simple_restore(local_data, &local_state); -} - -static void test_srv_init(void) -{ - bt_mesh_test_cfg_set(&srv_cfg, WAIT_TIME); -} - -static void test_cli_init(void) -{ - bt_mesh_test_cfg_set(&cli_cfg, WAIT_TIME); -} - -static void test_cli_max_sdu_comp_data_request(void) -{ - int err; - uint8_t page = 0; - uint16_t offset, total_size; - - NET_BUF_SIMPLE_DEFINE(local_comp, 500); - NET_BUF_SIMPLE_DEFINE(srv_rsp, 500); - net_buf_simple_init(&local_comp, 0); - net_buf_simple_init(&srv_rsp, 0); - - bt_mesh_device_setup(&prov, &comp_1); - prov_and_conf(cli_cfg); - target_node_alloc(comp_1, srv_cfg); - - /* Note: an offset of 3 is necessary with the status data to be exactly - * 380 bytes of access payload. - */ - offset = 3; - - /* Get local data */ - err = bt_mesh_comp_data_get_page_0(&local_comp, offset); - /* Operation is successful even if all data cannot fit in the buffer (-E2BIG) */ - if (err && err != -E2BIG) { - FAIL("CLIENT: Failed to get comp data Page 0: %d", err); - } - total_size = bt_mesh_comp_page_0_size(); - - /* Get server composition data and check integrity */ - ASSERT_OK(bt_mesh_large_comp_data_get(0, SRV_ADDR, page, offset, &srv_rsp)); - ASSERT_EQUAL(srv_rsp.len, BT_MESH_LCD_PAYLOAD_MAX); - rsp_equals_local_data_assert(SRV_ADDR, &srv_rsp, &local_comp, page, offset, total_size, - NULL); - - PASS(); -} - -static void test_cli_split_comp_data_request(void) -{ - int err; - uint8_t page = 0; - uint16_t offset, total_size, prev_len = 0; - - NET_BUF_SIMPLE_DEFINE(local_comp, 200); - NET_BUF_SIMPLE_DEFINE(srv_rsp_1, 64); - NET_BUF_SIMPLE_DEFINE(srv_rsp_2, 64); - net_buf_simple_init(&local_comp, 0); - net_buf_simple_init(&srv_rsp_1, 0); - net_buf_simple_init(&srv_rsp_2, 0); - - bt_mesh_device_setup(&prov, &comp_1); - prov_and_conf(cli_cfg); - target_node_alloc(comp_1, srv_cfg); - - offset = 0; - - /* Get local data */ - err = bt_mesh_comp_data_get_page_0(&local_comp, offset); - /* Operation is successful even if all data cannot fit in the buffer (-E2BIG) */ - if (err && err != -E2BIG) { - FAIL("CLIENT: Failed to get comp data Page 0: %d", err); - } - total_size = bt_mesh_comp_page_0_size(); - - /* Get first server composition data sample and verify data */ - ASSERT_OK(bt_mesh_large_comp_data_get(0, SRV_ADDR, page, offset, &srv_rsp_1)); - rsp_equals_local_data_assert(SRV_ADDR, &srv_rsp_1, &local_comp, page, offset, total_size, - &prev_len); - - prev_len = srv_rsp_1.len; - offset += prev_len; - - /* Get next server composition data sample */ - ASSERT_OK(bt_mesh_large_comp_data_get(0, SRV_ADDR, page, offset, &srv_rsp_2)); - rsp_equals_local_data_assert(SRV_ADDR, &srv_rsp_2, &local_comp, page, offset, total_size, - &prev_len); - - /* Check data integrity of merged sample data */ - merge_and_compare_assert(&srv_rsp_1, &srv_rsp_2, &local_comp); - - PASS(); -} - -static void test_cli_max_sdu_metadata_request(void) -{ - int err; - uint8_t page = 0; - uint16_t offset, total_size; - - NET_BUF_SIMPLE_DEFINE(local_metadata, 500); - NET_BUF_SIMPLE_DEFINE(srv_rsp, 500); - net_buf_simple_init(&local_metadata, 0); - net_buf_simple_init(&srv_rsp, 0); - - bt_mesh_device_setup(&prov, &comp_2); - prov_and_conf(cli_cfg); - target_node_alloc(comp_2, srv_cfg); - - /* Note: an offset of 4 is necessary for the status data to be exactly - * 380 bytes of access payload. - */ - offset = 4; - - /* Get local data */ - err = bt_mesh_metadata_get_page_0(&local_metadata, offset); - /* Operation is successful even if all data cannot fit in the buffer (-E2BIG) */ - if (err && err != -E2BIG) { - FAIL("CLIENT: Failed to get Models Metadata Page 0: %d", err); - } - total_size = bt_mesh_metadata_page_0_size(); - - /* Get server metadata and check integrity */ - ASSERT_OK(bt_mesh_models_metadata_get(0, SRV_ADDR, page, offset, &srv_rsp)); - ASSERT_EQUAL(srv_rsp.len, BT_MESH_LCD_PAYLOAD_MAX); - rsp_equals_local_data_assert(SRV_ADDR, &srv_rsp, &local_metadata, page, offset, total_size, - NULL); - - PASS(); -} - -static void test_cli_split_metadata_request(void) -{ - uint8_t page = 0; - uint16_t offset, total_size, prev_len = 0; - - NET_BUF_SIMPLE_DEFINE(local_metadata, 500); - NET_BUF_SIMPLE_DEFINE(srv_rsp_1, 64); - NET_BUF_SIMPLE_DEFINE(srv_rsp_2, 64); - net_buf_simple_init(&local_metadata, 0); - net_buf_simple_init(&srv_rsp_1, 0); - net_buf_simple_init(&srv_rsp_2, 0); - - bt_mesh_device_setup(&prov, &comp_2); - prov_and_conf(cli_cfg); - target_node_alloc(comp_2, srv_cfg); - - offset = 0; - - /* Get local data */ - int err = bt_mesh_metadata_get_page_0(&local_metadata, offset); - /* Operation is successful even if not all metadata could fit in the buffer (-E2BIG) */ - if (err && err != -E2BIG) { - FAIL("CLIENT: Failed to get Models Metadata Page 0: %d", err); - } - total_size = bt_mesh_metadata_page_0_size(); - - /* Get first server composition data sample and check integrity */ - ASSERT_OK(bt_mesh_models_metadata_get(0, SRV_ADDR, page, offset, &srv_rsp_1)); - rsp_equals_local_data_assert(SRV_ADDR, &srv_rsp_1, &local_metadata, page, offset, - total_size, &prev_len); - - prev_len = srv_rsp_1.len; - offset += prev_len; - - /* Get next server composition data sample and check integrity */ - ASSERT_OK(bt_mesh_models_metadata_get(0, SRV_ADDR, page, offset, &srv_rsp_2)); - rsp_equals_local_data_assert(SRV_ADDR, &srv_rsp_2, &local_metadata, page, offset, - total_size, &prev_len); - - /* Check data integrity of merged sample data */ - merge_and_compare_assert(&srv_rsp_1, &srv_rsp_2, &local_metadata); - - PASS(); -} - -static void test_srv_comp_data_status_respond(void) -{ - bt_mesh_device_setup(&prov, &comp_1); - prov_and_conf(srv_cfg); - - /* No server callback available. Wait 10 sec for message to be recived */ - k_sleep(K_SECONDS(10)); - - PASS(); -} - -static void test_srv_metadata_status_respond(void) -{ - bt_mesh_device_setup(&prov, &comp_2); - prov_and_conf(srv_cfg); - - if (atomic_test_bit(bt_mesh.flags, BT_MESH_METADATA_DIRTY)) { - FAIL("Metadata is dirty. Test is not suited for this purpose."); - } - - /* No server callback available. Wait 10 sec for message to be recived */ - k_sleep(K_SECONDS(10)); - - PASS(); -} - -#define TEST_CASE(role, name, description) \ - { \ - .test_id = "lcd_" #role "_" #name, \ - .test_descr = description, \ - .test_tick_f = bt_mesh_test_timeout, \ - .test_post_init_f = test_##role##_init, \ - .test_main_f = test_##role##_##name, \ - } - -static const struct bst_test_instance test_lcd[] = { - TEST_CASE(cli, max_sdu_comp_data_request, "Request comp data with max SDU length"), - TEST_CASE(cli, split_comp_data_request, "Request continuous comp data in two samples."), - TEST_CASE(cli, max_sdu_metadata_request, "Request metadata with max SDU length"), - TEST_CASE(cli, split_metadata_request, "Request continuous metadata in two samples."), - - TEST_CASE(srv, comp_data_status_respond, "Process incoming GET LCD messages."), - TEST_CASE(srv, metadata_status_respond, "Process incoming GET metadata messages."), - - BSTEST_END_MARKER}; - -struct bst_test_list *test_lcd_install(struct bst_test_list *tests) -{ - tests = bst_add_tests(tests, test_lcd); - return tests; -} diff --git a/tests/bluetooth/bsim/mesh/src/test_op_agg.c b/tests/bluetooth/bsim/mesh/src/test_op_agg.c deleted file mode 100644 index 6d1c0c7e5f1..00000000000 --- a/tests/bluetooth/bsim/mesh/src/test_op_agg.c +++ /dev/null @@ -1,245 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - * - * Opcode aggregator test - */ - -#include "mesh_test.h" - -#include - -#include - -LOG_MODULE_REGISTER(test_op_agg, LOG_LEVEL_INF); - -#define CLI_ADDR 0x7728 -#define SRV_ADDR 0x18f8 -#define WAIT_TIME 15 /* seconds */ -#define SEM_TIMEOUT K_SECONDS(10) - -#define BT_MESH_DUMMY_VND_MOD_GET_OP BT_MESH_MODEL_OP_3(0xDC, TEST_VND_COMPANY_ID) -#define BT_MESH_DUMMY_VND_MOD_STATUS_OP BT_MESH_MODEL_OP_3(0xCD, TEST_VND_COMPANY_ID) - -#define BT_MESH_DUMMY_VND_MOD_MSG_MINLEN 7 -#define BT_MESH_DUMMY_VND_MOD_MSG_MAXLEN 8 - -/* The 34 messages make up the aggregated message sequence, expecting a 380 byte status response. */ -#define TEST_SEND_ITR 34 - -/* Spec: 4.3.9.4: Table 4.273 defines the structure of the OPCODES_AGGREGATOR_STATUS message. */ -#define OPCODES_AGG_STATUS_MSG_BASE_STRUCTURE_LEN 5 -/* SPEC: 4.3.9.1: Length_format + Length_Short.*/ -#define OPCODES_AGG_ITEM_SHORT_FORMAT_LEN 1 -/* SPEC: 4.3.9.1: The structure of an Aggregator Item field is defined in Table 4.270 */ -#define OPCODES_STATUS_ITEM_LEN(param_len) \ - (OPCODES_AGG_ITEM_SHORT_FORMAT_LEN + \ - BT_MESH_MODEL_OP_LEN(BT_MESH_DUMMY_VND_MOD_STATUS_OP) + param_len) -/* Spec: 4.3.9.3 OPCODES_AGGREGATOR_STATUS. The test initiates 33+1 get/status message iterations.*/ -#define OP_AGG_STATUS_ACCESS_PAYLOAD \ - (OPCODES_AGG_STATUS_MSG_BASE_STRUCTURE_LEN + \ - (OPCODES_STATUS_ITEM_LEN(BT_MESH_DUMMY_VND_MOD_MSG_MINLEN) * (TEST_SEND_ITR - 1)) + \ - OPCODES_STATUS_ITEM_LEN(BT_MESH_DUMMY_VND_MOD_MSG_MAXLEN)) - -/* Ensure that a 380-byte opcode aggregator get/status access payload is being sent. */ -BUILD_ASSERT(OP_AGG_STATUS_ACCESS_PAYLOAD == (BT_MESH_TX_SDU_MAX - BT_MESH_MIC_SHORT)); - -static int status_rcvd_count; -static int get_rcvd_count; -static struct k_sem cli_suspend_sem; -static struct k_sem srv_suspend_sem; -static const uint8_t dev_key[16] = {0xaa}; -static uint8_t cli_sent_array[TEST_SEND_ITR], cli_rcvd_array[TEST_SEND_ITR]; - -static struct bt_mesh_msg_ctx test_ctx = { - .net_idx = 0, - .app_idx = 0, - .addr = SRV_ADDR, -}; - -static struct bt_mesh_prov prov; -static struct bt_mesh_cfg_cli cfg_cli; - -static int get_handler(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) -{ - uint8_t seq = net_buf_simple_pull_u8(buf); - - get_rcvd_count++; - - BT_MESH_MODEL_BUF_DEFINE(msg, BT_MESH_DUMMY_VND_MOD_STATUS_OP, - BT_MESH_DUMMY_VND_MOD_MSG_MAXLEN); - bt_mesh_model_msg_init(&msg, BT_MESH_DUMMY_VND_MOD_STATUS_OP); - - net_buf_simple_add_u8(&msg, seq); - memset(net_buf_simple_add(&msg, BT_MESH_DUMMY_VND_MOD_MSG_MINLEN - 1), 0, - BT_MESH_DUMMY_VND_MOD_MSG_MINLEN); - - /* Last message: One additional byte is added to fill the available access payload.*/ - if (get_rcvd_count >= TEST_SEND_ITR) { - net_buf_simple_add(&msg, 1); - k_sem_give(&srv_suspend_sem); - } - - return bt_mesh_model_send(model, ctx, &msg, NULL, NULL); -} - -static int status_handler(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) -{ - uint8_t seq = net_buf_simple_pull_u8(buf); - - status_rcvd_count++; - cli_rcvd_array[status_rcvd_count - 1] = seq; - - if (status_rcvd_count >= TEST_SEND_ITR) { - k_sem_give(&cli_suspend_sem); - } - - return 0; -} - -static int dummy_vnd_mod_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, uint8_t seq) -{ - BT_MESH_MODEL_BUF_DEFINE(msg, BT_MESH_DUMMY_VND_MOD_GET_OP, - BT_MESH_DUMMY_VND_MOD_MSG_MAXLEN); - - bt_mesh_model_msg_init(&msg, BT_MESH_DUMMY_VND_MOD_GET_OP); - - net_buf_simple_add_u8(&msg, seq); - memset(net_buf_simple_add(&msg, BT_MESH_DUMMY_VND_MOD_MSG_MINLEN - 1), 0, - BT_MESH_DUMMY_VND_MOD_MSG_MINLEN); - - /* Last message: One additional byte is added to fill the available access payload.*/ - if (seq >= TEST_SEND_ITR - 1) { - net_buf_simple_add(&msg, 1); - } - - return bt_mesh_model_send(model, ctx, &msg, NULL, NULL); -} - -const struct bt_mesh_model_op _dummy_vnd_mod_op[] = { - {BT_MESH_DUMMY_VND_MOD_GET_OP, BT_MESH_DUMMY_VND_MOD_MSG_MINLEN, get_handler}, - {BT_MESH_DUMMY_VND_MOD_STATUS_OP, BT_MESH_DUMMY_VND_MOD_MSG_MINLEN, status_handler}, - BT_MESH_MODEL_OP_END, -}; - -static struct bt_mesh_model dummy_vnd_model = { - .op = _dummy_vnd_mod_op, - .vnd.id = TEST_VND_MOD_ID, - .vnd.company = TEST_VND_COMPANY_ID, -}; - -static struct bt_mesh_elem elements[] = {BT_MESH_ELEM( - 0, - MODEL_LIST(BT_MESH_MODEL_CFG_SRV, BT_MESH_MODEL_CFG_CLI(&cfg_cli), BT_MESH_MODEL_OP_AGG_SRV, - BT_MESH_MODEL_OP_AGG_CLI), - MODEL_LIST(BT_MESH_MODEL_VND_CB(TEST_VND_COMPANY_ID, TEST_VND_MOD_ID, _dummy_vnd_mod_op, - NULL, &dummy_vnd_model, NULL)))}; - -static const struct bt_mesh_comp comp = { - .cid = TEST_VND_COMPANY_ID, - .elem = elements, - .elem_count = ARRAY_SIZE(elements), -}; - -static void op_agg_test_prov_and_conf(uint16_t addr) -{ - uint8_t status; - int err; - - ASSERT_OK(bt_mesh_provision(test_net_key, 0, 0, 0, addr, dev_key)); - - err = bt_mesh_cfg_cli_app_key_add(0, addr, 0, 0, test_app_key, &status); - if (err || status) { - FAIL("AppKey add failed (err %d, status %u)", err, status); - } - - err = bt_mesh_cfg_cli_mod_app_bind(0, addr, addr, 0, BT_MESH_MODEL_ID_OP_AGG_CLI, - &status); - if (err || status) { - FAIL("Failed to bind OP_AGG_CLI to application (err %d, status %u)", err, status); - } - err = bt_mesh_cfg_cli_mod_app_bind(0, addr, addr, 0, BT_MESH_MODEL_ID_OP_AGG_SRV, - &status); - if (err || status) { - FAIL("Failed to bind OP_AGG_SRV to application (err %d, status %u)", err, status); - } - err = bt_mesh_cfg_cli_mod_app_bind_vnd(0, addr, addr, 0, TEST_VND_MOD_ID, - TEST_VND_COMPANY_ID, &status); - if (err || status) { - FAIL("Failed to bind OP_AGG_TEST_MOD to application (err %d, status %u)", err, - status); - } -} - -static void test_cli_max_len_sequence_msg_send(void) -{ - uint8_t seq; - - bt_mesh_test_cfg_set(NULL, WAIT_TIME); - bt_mesh_device_setup(&prov, &comp); - op_agg_test_prov_and_conf(CLI_ADDR); - - ASSERT_OK(k_sem_init(&cli_suspend_sem, 0, 1)); - ASSERT_OK(bt_mesh_op_agg_cli_seq_start(0, 0, SRV_ADDR, SRV_ADDR)); - - for (int i = 0; i < TEST_SEND_ITR; i++) { - seq = cli_sent_array[i] = i; - ASSERT_OK(dummy_vnd_mod_get(&dummy_vnd_model, &test_ctx, seq)); - } - - ASSERT_OK(bt_mesh_op_agg_cli_seq_send()); - - /* Wait for all expected STATUS messages to be received */ - if (k_sem_take(&cli_suspend_sem, SEM_TIMEOUT)) { - FAIL("Client suspension timed out. Status-messages received: %d", - status_rcvd_count); - } - - if (memcmp(cli_sent_array, cli_rcvd_array, ARRAY_SIZE(cli_rcvd_array))) { - FAIL("Message arrays (sent / rcvd) are not equal."); - } - - PASS(); -} - -static void test_srv_max_len_status_msg_send(void) -{ - bt_mesh_test_cfg_set(NULL, WAIT_TIME); - bt_mesh_device_setup(&prov, &comp); - op_agg_test_prov_and_conf(SRV_ADDR); - - ASSERT_OK(k_sem_init(&srv_suspend_sem, 0, 1)); - - /* Wait for all expected GET messages to be received */ - if (k_sem_take(&srv_suspend_sem, SEM_TIMEOUT)) { - FAIL("Server suspension timed out. Get-messages received: %d", get_rcvd_count); - } - - PASS(); -} - -#define TEST_CASE(role, name, description) \ - { \ - .test_id = "op_agg_" #role "_" #name, \ - .test_descr = description, \ - .test_tick_f = bt_mesh_test_timeout, \ - .test_main_f = test_##role##_##name, \ - } - -static const struct bst_test_instance test_op_agg[] = { - TEST_CASE(cli, max_len_sequence_msg_send, - "OpAggCli composes a sequence request list, expecting a 380 Byte status message " - "in return."), - TEST_CASE(srv, max_len_status_msg_send, - "OpAggSrv will respond with a 380 Byte status message. "), - - BSTEST_END_MARKER}; - -struct bst_test_list *test_op_agg_install(struct bst_test_list *tests) -{ - tests = bst_add_tests(tests, test_op_agg); - return tests; -} diff --git a/tests/bluetooth/bsim/mesh/src/test_persistence.c b/tests/bluetooth/bsim/mesh/src/test_persistence.c deleted file mode 100644 index db780cb4598..00000000000 --- a/tests/bluetooth/bsim/mesh/src/test_persistence.c +++ /dev/null @@ -1,1018 +0,0 @@ -/* - * Copyright (c) 2021 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mesh_test.h" -#include "settings_test_backend.h" -#include -#include -#include "mesh/net.h" -#include "mesh/app_keys.h" -#include "mesh/crypto.h" -#include - -#define LOG_MODULE_NAME test_persistence - -#include -LOG_MODULE_REGISTER(LOG_MODULE_NAME); - -#define WAIT_TIME 60 /*seconds*/ - -static bool provisioner_ready; - -extern const struct bt_mesh_comp comp; - -struct test_va_t { - uint16_t addr; - uint8_t uuid[16]; -}; - -struct test_appkey_t { - uint8_t idx; - uint8_t key[16]; -}; - -#define TEST_PROV_ADDR 0x0001 -#define TEST_ADDR 0x0123 -static uint8_t test_prov_uuid[16] = { 0x6c, 0x69, 0x6e, 0x67, 0x61, 0xaa }; -static uint8_t test_dev_uuid[16] = { 0x6c, 0x69, 0x6e, 0x67, 0x61, 0x6f }; -static int test_ividx = 0x123456; -static uint8_t test_flags; -static uint8_t test_netkey_idx = 0x77; -static uint8_t test_netkey[16] = { 0xaa }; -static uint8_t test_devkey[16] = { 0xdd }; -static uint8_t test_prov_devkey[16] = { 0x11 }; - -#define TEST_GROUP_0 0xc001 -#define TEST_GROUP_1 0xfab3 - -#define TEST_VA_0_ADDR 0xb6f0 -#define TEST_VA_0_UUID (uint8_t[16]) { 0xca, 0xcd, 0x13, 0xbd, 0x54, 0xfe, 0x43, 0xed, \ - 0x12, 0x3d, 0xa3, 0xe3, 0xb9, 0x03, 0x70, 0xaa } -#define TEST_VA_1_ADDR 0x8700 -#define TEST_VA_1_UUID (uint8_t[16]) { 0xdf, 0xca, 0xa3, 0x54, 0x23, 0xfa, 0x33, 0xed, \ - 0x1a, 0xbe, 0xa0, 0xaa, 0xbd, 0xfa, 0x0f, 0xaf } - -#define TEST_APPKEY_0_IDX 0x12 -#define TEST_APPKEY_0_KEY { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, \ - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f } -#define TEST_APPKEY_1_IDX 0x43 -#define TEST_APPKEY_1_KEY { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, \ - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f } - -#define TEST_MOD_PUB_PARAMS { \ - .addr = TEST_ADDR, \ - .uuid = NULL, \ - .app_idx = TEST_APPKEY_0_IDX, \ - .cred_flag = true, \ - .ttl = 5, \ - .period = BT_MESH_PUB_PERIOD_10SEC(2), \ - .transmit = BT_MESH_TRANSMIT(2, 20), \ - } - -#define TEST_VND_MOD_PUB_PARAMS { \ - .addr = TEST_VA_0_ADDR, \ - .uuid = TEST_VA_0_UUID, \ - .app_idx = TEST_APPKEY_1_IDX, \ - .cred_flag = true, \ - .ttl = 5, \ - .period = BT_MESH_PUB_PERIOD_10SEC(1), \ - .transmit = BT_MESH_TRANSMIT(2, 20), \ - } - -#define DISABLED_MOD_PUB_PARAMS { \ - .addr = 0, \ - .uuid = NULL, \ - .app_idx = 0, \ - .cred_flag = false, \ - .ttl = 0, \ - .period = 0, \ - .transmit = 0, \ - } - -#define TEST_MOD_DATA_NAME "tmdata" -static uint8_t test_mod_data[] = { 0xfa, 0xff, 0xf4, 0x43 }; -#define TEST_VND_MOD_DATA_NAME "vtmdata" -static uint8_t vnd_test_mod_data[] = { 0xad, 0xdf, 0x14, 0x53, 0x54, 0x1f }; - -struct access_cfg { - struct bt_mesh_cfg_cli_mod_pub pub_params; - - size_t appkeys_count; - uint16_t appkeys[CONFIG_BT_MESH_MODEL_KEY_COUNT]; - - size_t subs_count; - uint16_t subs[CONFIG_BT_MESH_MODEL_GROUP_COUNT]; - - size_t mod_data_len; -}; -static const struct access_cfg (*current_access_cfg)[2]; -enum { - CONFIGURED, - NEW_SUBS, - NOT_CONFIGURED, -}; -static const struct access_cfg access_cfgs[][2] = { - [CONFIGURED] = { - /* SIG model. */ - { - .pub_params = TEST_MOD_PUB_PARAMS, - .appkeys_count = 2, .appkeys = { TEST_APPKEY_0_IDX, TEST_APPKEY_1_IDX }, - .subs_count = 2, .subs = { TEST_GROUP_0, TEST_VA_0_ADDR }, - .mod_data_len = sizeof(test_mod_data), - }, - - /* Vendor model. */ - { - .pub_params = TEST_VND_MOD_PUB_PARAMS, - .appkeys_count = 2, .appkeys = { TEST_APPKEY_0_IDX, TEST_APPKEY_1_IDX }, - .subs_count = 2, .subs = { TEST_GROUP_0, TEST_VA_0_ADDR }, - .mod_data_len = sizeof(vnd_test_mod_data), - }, - }, - - [NEW_SUBS] = { - /* SIG model. */ - { - .pub_params = TEST_MOD_PUB_PARAMS, - .appkeys_count = 2, .appkeys = { TEST_APPKEY_0_IDX, TEST_APPKEY_1_IDX }, - .subs_count = 1, .subs = { TEST_GROUP_0 }, - .mod_data_len = sizeof(test_mod_data), - }, - - /* Vendor model. */ - { - .pub_params = TEST_VND_MOD_PUB_PARAMS, - .appkeys_count = 2, .appkeys = { TEST_APPKEY_0_IDX, TEST_APPKEY_1_IDX }, - .subs_count = 1, .subs = { TEST_VA_0_ADDR }, - .mod_data_len = sizeof(vnd_test_mod_data), - }, - }, - - [NOT_CONFIGURED] = { - /* SIG model. */ - { - .pub_params = DISABLED_MOD_PUB_PARAMS, - .appkeys_count = 0, .appkeys = {}, - .subs_count = 0, .subs = {}, - .mod_data_len = 0, - }, - - /* Vendor model. */ - { - .pub_params = DISABLED_MOD_PUB_PARAMS, - .appkeys_count = 0, .appkeys = {}, - .subs_count = 0, .subs = {}, - .mod_data_len = 0, - }, - }, -}; - -static const struct stack_cfg { - uint8_t beacon; - uint8_t ttl; - uint8_t gatt_proxy; - uint8_t friend; - uint8_t net_transmit; - struct { - enum bt_mesh_feat_state state; - uint8_t transmit; - } relay; -} stack_cfgs[] = { - { - .beacon = 1, - .ttl = 12, - .gatt_proxy = 1, - .friend = 1, - .net_transmit = BT_MESH_TRANSMIT(3, 20), - .relay = { .state = BT_MESH_FEATURE_ENABLED, .transmit = BT_MESH_TRANSMIT(2, 20) }, - }, - { - .beacon = 0, - .ttl = 0, - .gatt_proxy = 0, - .friend = 0, - .net_transmit = BT_MESH_TRANSMIT(1, 30), - .relay = { .state = BT_MESH_FEATURE_ENABLED, .transmit = BT_MESH_TRANSMIT(1, 10) }, - }, -}; -static const struct stack_cfg *current_stack_cfg; - -static bool clear_settings; - -static void test_args_parse(int argc, char *argv[]) -{ - char *access_cfg_str = NULL; - int32_t stack_cfg = -1; - - bs_args_struct_t args_struct[] = { - { - .dest = &access_cfg_str, - .type = 's', - .name = "{configured, new-subs, not-configured}", - .option = "access-cfg", - .descript = "" - }, - { - .dest = &stack_cfg, - .type = 'i', - .name = "{0, 1}", - .option = "stack-cfg", - .descript = "" - }, - { - .dest = &clear_settings, - .type = 'b', - .name = "{0, 1}", - .option = "clear-settings", - .descript = "", - }, - }; - - bs_args_parse_all_cmd_line(argc, argv, args_struct); - - if (access_cfg_str != NULL) { - if (!strcmp(access_cfg_str, "configured")) { - current_access_cfg = &access_cfgs[CONFIGURED]; - } else if (!strcmp(access_cfg_str, "new-subs")) { - current_access_cfg = &access_cfgs[NEW_SUBS]; - } else if (!strcmp(access_cfg_str, "not-configured")) { - current_access_cfg = &access_cfgs[NOT_CONFIGURED]; - } - } - - if (stack_cfg >= 0 && stack_cfg < ARRAY_SIZE(stack_cfgs)) { - current_stack_cfg = &stack_cfgs[stack_cfg]; - } -} - -static struct k_sem prov_sem; - -static void prov_complete(uint16_t net_idx, uint16_t addr) -{ - LOG_INF("Device provisioning is complete, addr: %d", addr); - k_sem_give(&prov_sem); -} - -static void device_reset(void) -{ - LOG_INF("Device is reset"); - k_sem_give(&prov_sem); -} - -static void unprovisioned_beacon(uint8_t uuid[16], bt_mesh_prov_oob_info_t oob_info, - uint32_t *uri_hash) -{ - static bool once; - - /* Subnet may not be ready yet when provisioner receives a beacon. */ - if (!provisioner_ready) { - LOG_INF("Provisioner is not ready yet"); - return; - } - - if (once) { - return; - } - - once = !once; - - ASSERT_OK(bt_mesh_provision_adv(uuid, test_netkey_idx, TEST_ADDR, 0)); -} - -static void prov_node_added(uint16_t net_idx, uint8_t uuid[16], uint16_t addr, uint8_t num_elem) -{ - LOG_INF("Device 0x%04x provisioned", addr); - k_sem_give(&prov_sem); -} - -static void check_mod_pub_params(const struct bt_mesh_cfg_cli_mod_pub *expected, - const struct bt_mesh_cfg_cli_mod_pub *got) -{ - ASSERT_EQUAL(expected->addr, got->addr); - ASSERT_EQUAL(expected->app_idx, got->app_idx); - ASSERT_EQUAL(expected->cred_flag, got->cred_flag); - ASSERT_EQUAL(expected->ttl, got->ttl); - ASSERT_EQUAL(expected->period, got->period); - ASSERT_EQUAL(expected->transmit, got->transmit); -} - -int test_model_settings_set(struct bt_mesh_model *model, - const char *name, size_t len_rd, - settings_read_cb read_cb, void *cb_arg) -{ - uint8_t data[sizeof(test_mod_data)]; - ssize_t result; - - ASSERT_TRUE(name != NULL); - if (strncmp(name, TEST_MOD_DATA_NAME, strlen(TEST_MOD_DATA_NAME))) { - FAIL("Invalid entry name: [%s]", name); - } - - settings_name_next(name, &name); - ASSERT_TRUE(name == NULL); - - ASSERT_TRUE(current_access_cfg != NULL); - result = read_cb(cb_arg, &data, sizeof(data)); - ASSERT_EQUAL((*current_access_cfg)[0].mod_data_len, result); - - if (memcmp(data, test_mod_data, (*current_access_cfg)[0].mod_data_len)) { - FAIL("Incorrect data restored"); - } - - return 0; -} - -void test_model_reset(struct bt_mesh_model *model) -{ - ASSERT_OK(bt_mesh_model_data_store(test_model, false, TEST_MOD_DATA_NAME, NULL, 0)); -} - -int test_vnd_model_settings_set(struct bt_mesh_model *model, - const char *name, size_t len_rd, - settings_read_cb read_cb, void *cb_arg) -{ - uint8_t data[sizeof(vnd_test_mod_data)]; - ssize_t result; - - ASSERT_TRUE(name != NULL); - if (strncmp(name, TEST_VND_MOD_DATA_NAME, strlen(TEST_VND_MOD_DATA_NAME))) { - FAIL("Invalid entry name: %s", name); - } - - settings_name_next(name, &name); - ASSERT_TRUE(name == NULL); - - ASSERT_TRUE(current_access_cfg != NULL); - result = read_cb(cb_arg, &data, sizeof(data)); - ASSERT_EQUAL((*current_access_cfg)[1].mod_data_len, result); - - if (memcmp(data, vnd_test_mod_data, (*current_access_cfg)[1].mod_data_len)) { - FAIL("Incorrect data restored"); - } - - return 0; -} - -void test_vnd_model_reset(struct bt_mesh_model *model) -{ - ASSERT_OK(bt_mesh_model_data_store(test_vnd_model, true, TEST_VND_MOD_DATA_NAME, NULL, 0)); -} - -static void device_setup(void) -{ - static struct bt_mesh_prov prov = { - .uuid = test_dev_uuid, - .complete = prov_complete, - .reset = device_reset, - }; - - k_sem_init(&prov_sem, 0, 1); - - bt_mesh_device_setup(&prov, &comp); -} - -static int device_setup_and_self_provision(void) -{ - device_setup(); - - return bt_mesh_provision(test_netkey, test_netkey_idx, test_flags, test_ividx, TEST_ADDR, - test_devkey); -} - -static void provisioner_setup(void) -{ - static struct bt_mesh_prov prov = { - .uuid = test_prov_uuid, - .unprovisioned_beacon = unprovisioned_beacon, - .node_added = prov_node_added, - }; - uint8_t primary_netkey[16] = { 0xad, 0xde, 0xfa, 0x32 }; - struct bt_mesh_cdb_subnet *subnet; - uint8_t status; - int err; - - k_sem_init(&prov_sem, 0, 1); - - bt_mesh_device_setup(&prov, &comp); - - ASSERT_OK(bt_mesh_cdb_create(primary_netkey)); - ASSERT_OK(bt_mesh_provision(primary_netkey, 0, test_flags, test_ividx, TEST_PROV_ADDR, - test_prov_devkey)); - - /* Adding a subnet for test_netkey as it is not primary. */ - subnet = bt_mesh_cdb_subnet_alloc(test_netkey_idx); - ASSERT_TRUE(subnet != NULL); - memcpy(subnet->keys[0].net_key, test_netkey, 16); - bt_mesh_cdb_subnet_store(subnet); - - err = bt_mesh_cfg_cli_net_key_add(0, TEST_PROV_ADDR, test_netkey_idx, test_netkey, &status); - if (err || status) { - FAIL("Failed to add test_netkey (err: %d, status: %d)", err, status); - } - - provisioner_ready = true; -} - -static void test_provisioning_data_save(void) -{ - settings_test_backend_clear(); - bt_mesh_test_cfg_set(NULL, WAIT_TIME); - - if (device_setup_and_self_provision()) { - FAIL("Mesh setup failed. Settings should not be loaded."); - } - - k_sleep(K_SECONDS(CONFIG_BT_MESH_STORE_TIMEOUT)); - - PASS(); -} - -static void test_provisioning_data_load(void) -{ - /* In this test stack should boot as provisioned */ - bt_mesh_test_cfg_set(NULL, WAIT_TIME); - - if (device_setup_and_self_provision() != -EALREADY) { - FAIL("Device should boot up as already provisioned"); - } - - /* verify: */ - /* explicitly verify that the keys resolves for a given addr and net_idx */ - struct bt_mesh_msg_ctx ctx; - struct bt_mesh_net_tx tx = { .ctx = &ctx }; - const uint8_t *dkey; - uint8_t aid; - - tx.ctx->addr = TEST_ADDR; - tx.ctx->net_idx = test_netkey_idx; - tx.ctx->app_idx = BT_MESH_KEY_DEV_REMOTE; /* to resolve devkey */ - - int err = bt_mesh_keys_resolve(tx.ctx, &tx.sub, &dkey, &aid); - - if (err) { - FAIL("Failed to resolve keys"); - } - - if (memcmp(dkey, test_devkey, sizeof(test_devkey))) { - FAIL("Resolved dev_key does not match"); - } - - if (memcmp(tx.sub->keys[0].net, test_netkey, sizeof(test_netkey))) { - FAIL("Resolved net_key does not match"); - } - - if (tx.sub->kr_phase != ((test_flags & 1) << 1)) { - FAIL("Incorrect KR phase loaded"); - } - - /* send TTL Get to verify Tx/Rx path works with loaded config */ - uint8_t ttl; - - err = bt_mesh_cfg_cli_ttl_get(test_netkey_idx, TEST_ADDR, &ttl); - if (err) { - FAIL("Failed to read ttl value"); - } - - /* verify IV index state */ - if (bt_mesh.iv_index != test_ividx || - bt_mesh.ivu_duration != 0 || - atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS)) { - FAIL("IV loading verification failed"); - } - - k_sleep(K_SECONDS(CONFIG_BT_MESH_STORE_TIMEOUT)); - - PASS(); -} - -static void node_configure(void) -{ - int err; - uint8_t status; - uint16_t va; - struct bt_mesh_cfg_cli_mod_pub pub_params; - - struct test_appkey_t test_appkeys[] = { - { .idx = TEST_APPKEY_0_IDX, .key = TEST_APPKEY_0_KEY }, - { .idx = TEST_APPKEY_1_IDX, .key = TEST_APPKEY_1_KEY }, - }; - - for (size_t i = 0; i < ARRAY_SIZE(test_appkeys); i++) { - err = bt_mesh_cfg_cli_app_key_add(test_netkey_idx, TEST_ADDR, test_netkey_idx, - test_appkeys[i].idx, test_appkeys[i].key, &status); - if (err || status) { - FAIL("AppKey add failed (err %d, status %u, i %d)", err, status, i); - } - } - - /* SIG model. */ - for (size_t i = 0; i < ARRAY_SIZE(test_appkeys); i++) { - err = bt_mesh_cfg_cli_mod_app_bind(test_netkey_idx, TEST_ADDR, TEST_ADDR, - test_appkeys[i].idx, TEST_MOD_ID, &status); - if (err || status) { - FAIL("Mod app bind failed (err %d, status %u, i %d)", err, status, i); - } - } - - err = bt_mesh_cfg_cli_mod_sub_add(test_netkey_idx, TEST_ADDR, TEST_ADDR, TEST_GROUP_0, - TEST_MOD_ID, &status); - if (err || status) { - FAIL("Mod sub add failed (err %d, status %u)", err, status); - } - - err = bt_mesh_cfg_cli_mod_sub_va_add(test_netkey_idx, TEST_ADDR, TEST_ADDR, TEST_VA_0_UUID, - TEST_MOD_ID, &va, &status); - if (err || status) { - FAIL("Mod sub add failed (err %d, status %u)", err, status); - } - ASSERT_EQUAL(TEST_VA_0_ADDR, va); - - memcpy(&pub_params, &(struct bt_mesh_cfg_cli_mod_pub)TEST_MOD_PUB_PARAMS, - sizeof(struct bt_mesh_cfg_cli_mod_pub)); - err = bt_mesh_cfg_cli_mod_pub_set(test_netkey_idx, TEST_ADDR, TEST_ADDR, TEST_MOD_ID, - &pub_params, &status); - if (err || status) { - FAIL("Mod pub set failed (err %d, status %u)", err, status); - } - - err = bt_mesh_model_data_store(test_model, false, TEST_MOD_DATA_NAME, test_mod_data, - sizeof(test_mod_data)); - if (err) { - FAIL("Mod data store failed (err %d)", err); - } - - /* Vendor model. */ - for (size_t i = 0; i < ARRAY_SIZE(test_appkeys); i++) { - err = bt_mesh_cfg_cli_mod_app_bind_vnd(test_netkey_idx, TEST_ADDR, TEST_ADDR, - test_appkeys[i].idx, TEST_VND_MOD_ID, - TEST_VND_COMPANY_ID, &status); - if (err || status) { - FAIL("Mod app bind failed (err %d, status %u, i %d)", err, status, i); - } - } - - err = bt_mesh_cfg_cli_mod_sub_add_vnd(test_netkey_idx, TEST_ADDR, TEST_ADDR, - TEST_GROUP_0, TEST_VND_MOD_ID, - TEST_VND_COMPANY_ID, &status); - if (err || status) { - FAIL("Mod sub add failed (err %d, status %u)", err, status); - } - - err = bt_mesh_cfg_cli_mod_sub_va_add_vnd(test_netkey_idx, TEST_ADDR, TEST_ADDR, - TEST_VA_0_UUID, TEST_VND_MOD_ID, - TEST_VND_COMPANY_ID, &va, &status); - if (err || status) { - FAIL("Mod sub add failed (err %d, status %u)", err, status); - } - - ASSERT_EQUAL(TEST_VA_0_ADDR, va); - - memcpy(&pub_params, &(struct bt_mesh_cfg_cli_mod_pub)TEST_VND_MOD_PUB_PARAMS, - sizeof(struct bt_mesh_cfg_cli_mod_pub)); - err = bt_mesh_cfg_cli_mod_pub_set_vnd(test_netkey_idx, TEST_ADDR, TEST_ADDR, - TEST_VND_MOD_ID, TEST_VND_COMPANY_ID, &pub_params, - &status); - if (err || status) { - FAIL("Mod pub set failed (err %d, status %u)", err, status); - } - - err = bt_mesh_model_data_store(test_vnd_model, true, TEST_VND_MOD_DATA_NAME, - vnd_test_mod_data, sizeof(vnd_test_mod_data)); - if (err) { - FAIL("Vnd mod data store failed (err %d)", err); - return; - } -} - -static void test_access_data_save(void) -{ - settings_test_backend_clear(); - bt_mesh_test_cfg_set(NULL, WAIT_TIME); - - if (device_setup_and_self_provision()) { - FAIL("Mesh setup failed. Settings should not be loaded."); - } - - node_configure(); - - k_sleep(K_SECONDS(CONFIG_BT_MESH_STORE_TIMEOUT)); - - PASS(); -} - -static void node_configuration_check(const struct access_cfg (*cfg)[2]) -{ - uint16_t appkeys[CONFIG_BT_MESH_MODEL_KEY_COUNT + 1]; - size_t appkeys_count = ARRAY_SIZE(appkeys); - uint16_t subs[CONFIG_BT_MESH_MODEL_GROUP_COUNT + 1]; - size_t subs_count = ARRAY_SIZE(subs); - uint8_t status; - int err; - - for (size_t m = 0; m < 2; m++) { - bool vnd = m == 1; - - if (!vnd) { - err = bt_mesh_cfg_cli_mod_app_get(test_netkey_idx, TEST_ADDR, TEST_ADDR, - TEST_MOD_ID, &status, appkeys, - &appkeys_count); - } else { - err = bt_mesh_cfg_cli_mod_app_get_vnd(test_netkey_idx, TEST_ADDR, TEST_ADDR, - TEST_VND_MOD_ID, TEST_VND_COMPANY_ID, - &status, appkeys, &appkeys_count); - } - if (err || status) { - FAIL("Mod app get failed (err %d, status %u)", err, status); - } - - ASSERT_EQUAL((*cfg)[m].appkeys_count, appkeys_count); - for (size_t i = 0; i < appkeys_count; i++) { - ASSERT_EQUAL((*cfg)[m].appkeys[i], appkeys[i]); - } - - if (!vnd) { - err = bt_mesh_cfg_cli_mod_sub_get(test_netkey_idx, TEST_ADDR, TEST_ADDR, - TEST_MOD_ID, &status, subs, &subs_count); - } else { - err = bt_mesh_cfg_cli_mod_sub_get_vnd(test_netkey_idx, TEST_ADDR, TEST_ADDR, - TEST_VND_MOD_ID, TEST_VND_COMPANY_ID, - &status, subs, &subs_count); - } - if (err || status) { - FAIL("Mod sub get failed (err %d, status %u)", err, status); - } - - ASSERT_EQUAL((*cfg)[m].subs_count, subs_count); - for (size_t i = 0; i < subs_count; i++) { - ASSERT_EQUAL((*cfg)[m].subs[i], subs[i]); - } - - struct bt_mesh_cfg_cli_mod_pub pub_params = {}; - - if (!vnd) { - err = bt_mesh_cfg_cli_mod_pub_get(test_netkey_idx, TEST_ADDR, TEST_ADDR, - TEST_MOD_ID, &pub_params, &status); - } else { - err = bt_mesh_cfg_cli_mod_pub_get_vnd(test_netkey_idx, TEST_ADDR, TEST_ADDR, - TEST_VND_MOD_ID, TEST_VND_COMPANY_ID, - &pub_params, &status); - } - if (err || status) { - FAIL("Mod pub get failed (err %d, status %u)", err, status); - } - - check_mod_pub_params(&(*cfg)[m].pub_params, &pub_params); - } -} - -static void test_access_data_load(void) -{ - ASSERT_TRUE(current_access_cfg != NULL); - - /* In this test stack should boot as provisioned */ - bt_mesh_test_cfg_set(NULL, WAIT_TIME); - - if (device_setup_and_self_provision() != -EALREADY) { - FAIL("Device should boot up as already provisioned"); - } - - node_configuration_check(current_access_cfg); - - PASS(); -} - -static void test_access_sub_overwrite(void) -{ - uint16_t va; - uint8_t status; - int err; - - /* In this test stack should boot as provisioned */ - bt_mesh_test_cfg_set(NULL, WAIT_TIME); - - if (device_setup_and_self_provision() != -EALREADY) { - FAIL("Device should boot up as already provisioned"); - } - - err = bt_mesh_cfg_cli_mod_sub_overwrite(test_netkey_idx, TEST_ADDR, TEST_ADDR, - TEST_GROUP_0, TEST_MOD_ID, &status); - if (err || status) { - FAIL("Mod sub overwrite failed (err %d, status %u)", err, status); - } - - err = bt_mesh_cfg_cli_mod_sub_va_overwrite_vnd(test_netkey_idx, TEST_ADDR, TEST_ADDR, - TEST_VA_0_UUID, TEST_VND_MOD_ID, - TEST_VND_COMPANY_ID, &va, &status); - if (err || status) { - FAIL("Mod sub va overwrite failed (err %d, status %u)", err, status); - } - ASSERT_EQUAL(TEST_VA_0_ADDR, va); - - k_sleep(K_SECONDS(CONFIG_BT_MESH_STORE_TIMEOUT)); - - PASS(); -} - -static void test_access_data_remove(void) -{ - int err; - uint8_t status; - struct bt_mesh_cfg_cli_mod_pub pub_params; - - /* In this test stack should boot as provisioned */ - bt_mesh_test_cfg_set(NULL, WAIT_TIME); - - if (device_setup_and_self_provision() != -EALREADY) { - FAIL("Device should boot up as already provisioned"); - } - - struct test_appkey_t test_appkeys[] = { - { .idx = TEST_APPKEY_0_IDX, .key = TEST_APPKEY_0_KEY }, - { .idx = TEST_APPKEY_1_IDX, .key = TEST_APPKEY_1_KEY }, - }; - - /* SIG Model. */ - for (size_t i = 0; i < ARRAY_SIZE(test_appkeys); i++) { - err = bt_mesh_cfg_cli_mod_app_unbind(test_netkey_idx, TEST_ADDR, TEST_ADDR, - test_appkeys[i].idx, TEST_MOD_ID, &status); - if (err || status) { - FAIL("Mod app bind failed (err %d, status %u, i %d)", err, status, i); - } - } - - err = bt_mesh_cfg_cli_mod_sub_del_all(test_netkey_idx, TEST_ADDR, TEST_ADDR, TEST_MOD_ID, - &status); - if (err || status) { - FAIL("Mod sub del all failed (err %d, status %u)", err, status); - } - - memcpy(&pub_params, &(struct bt_mesh_cfg_cli_mod_pub)TEST_MOD_PUB_PARAMS, - sizeof(struct bt_mesh_cfg_cli_mod_pub)); - pub_params.addr = BT_MESH_ADDR_UNASSIGNED; - err = bt_mesh_cfg_cli_mod_pub_set(test_netkey_idx, TEST_ADDR, TEST_ADDR, TEST_MOD_ID, - &pub_params, &status); - if (err || status) { - FAIL("Mod pub set failed (err %d, status %u)", err, status); - } - - err = bt_mesh_model_data_store(test_model, false, TEST_MOD_DATA_NAME, NULL, 0); - if (err) { - FAIL("Mod data erase failed (err %d)", err); - } - - /* Vendor model. */ - for (size_t i = 0; i < ARRAY_SIZE(test_appkeys); i++) { - err = bt_mesh_cfg_cli_mod_app_unbind_vnd(test_netkey_idx, TEST_ADDR, TEST_ADDR, - test_appkeys[i].idx, TEST_VND_MOD_ID, - TEST_VND_COMPANY_ID, &status); - if (err || status) { - FAIL("Mod app bind failed (err %d, status %u, i %d)", err, status, i); - } - } - - err = bt_mesh_cfg_cli_mod_sub_del_all_vnd(test_netkey_idx, TEST_ADDR, TEST_ADDR, - TEST_VND_MOD_ID, TEST_VND_COMPANY_ID, - &status); - if (err || status) { - FAIL("Mod sub del all failed (err %d, status %u)", err, status); - } - - memcpy(&pub_params, &(struct bt_mesh_cfg_cli_mod_pub)TEST_VND_MOD_PUB_PARAMS, - sizeof(struct bt_mesh_cfg_cli_mod_pub)); - pub_params.addr = BT_MESH_ADDR_UNASSIGNED; - pub_params.uuid = NULL; - err = bt_mesh_cfg_cli_mod_pub_set_vnd(test_netkey_idx, TEST_ADDR, TEST_ADDR, - TEST_VND_MOD_ID, TEST_VND_COMPANY_ID, &pub_params, - &status); - if (err || status) { - FAIL("Mod pub set failed (err %d, status %u)", err, status); - } - - err = bt_mesh_model_data_store(test_vnd_model, true, TEST_VND_MOD_DATA_NAME, NULL, 0); - if (err) { - FAIL("Vnd mod data erase failed (err %d)", err); - return; - } - - k_sleep(K_SECONDS(CONFIG_BT_MESH_STORE_TIMEOUT)); - - PASS(); -} - -static void test_cfg_save(void) -{ - uint8_t transmit; - uint8_t status; - int err; - - ASSERT_TRUE(current_stack_cfg != NULL); - - settings_test_backend_clear(); - bt_mesh_test_cfg_set(NULL, WAIT_TIME); - - if (device_setup_and_self_provision()) { - FAIL("Mesh setup failed. Settings should not be loaded."); - } - - err = bt_mesh_cfg_cli_beacon_set(test_netkey_idx, TEST_ADDR, - current_stack_cfg->beacon, &status); - if (err || status != current_stack_cfg->beacon) { - FAIL("Beacon set failed (err %d, status %u)", err, status); - } - - err = bt_mesh_cfg_cli_ttl_set(test_netkey_idx, TEST_ADDR, - current_stack_cfg->ttl, &status); - if (err || status != current_stack_cfg->ttl) { - FAIL("TTL set failed (err %d, status %u)", err, status); - } - - err = bt_mesh_cfg_cli_gatt_proxy_set(test_netkey_idx, TEST_ADDR, - current_stack_cfg->gatt_proxy, &status); - if (err || status != current_stack_cfg->gatt_proxy) { - FAIL("GATT Proxy set failed (err %d, status %u)", err, status); - } - - err = bt_mesh_cfg_cli_friend_set(test_netkey_idx, TEST_ADDR, - current_stack_cfg->friend, &status); - if (err || status != current_stack_cfg->friend) { - FAIL("Friend set failed (err %d, status %u)", err, status); - } - - err = bt_mesh_cfg_cli_net_transmit_set(test_netkey_idx, TEST_ADDR, - current_stack_cfg->net_transmit, - &transmit); - if (err || transmit != current_stack_cfg->net_transmit) { - FAIL("Net transmit set failed (err %d, transmit %x)", err, transmit); - } - - err = bt_mesh_cfg_cli_relay_set(test_netkey_idx, TEST_ADDR, - current_stack_cfg->relay.state, - current_stack_cfg->relay.transmit, - &status, &transmit); - if (err || status != current_stack_cfg->relay.state || - transmit != current_stack_cfg->relay.transmit) { - FAIL("Relay set failed (err %d, status %u, transmit %x)", err, status, - current_stack_cfg->relay.transmit); - } - - k_sleep(K_SECONDS(CONFIG_BT_MESH_STORE_TIMEOUT)); - - PASS(); -} - -static void test_cfg_load(void) -{ - uint8_t transmit; - uint8_t status; - int err; - - ASSERT_TRUE(current_stack_cfg != NULL); - - /* In this test stack should boot as provisioned */ - bt_mesh_test_cfg_set(NULL, WAIT_TIME); - - if (device_setup_and_self_provision() != -EALREADY) { - FAIL("Device should boot up as already provisioned"); - } - - err = bt_mesh_cfg_cli_beacon_get(test_netkey_idx, TEST_ADDR, &status); - if (err || status != current_stack_cfg->beacon) { - FAIL("Beacon get failed (err %d, status %u)", err, status); - } - - err = bt_mesh_cfg_cli_ttl_get(test_netkey_idx, TEST_ADDR, &status); - if (err || status != current_stack_cfg->ttl) { - FAIL("TTL get failed (err %d, status %u)", err, status); - } - - err = bt_mesh_cfg_cli_gatt_proxy_get(test_netkey_idx, TEST_ADDR, &status); - if (err || status != current_stack_cfg->gatt_proxy) { - FAIL("GATT Proxy get failed (err %d, status %u)", err, status); - } - - err = bt_mesh_cfg_cli_friend_get(test_netkey_idx, TEST_ADDR, &status); - if (err || status != current_stack_cfg->friend) { - FAIL("Friend get failed (err %d, status %u)", err, status); - } - - err = bt_mesh_cfg_cli_net_transmit_get(test_netkey_idx, TEST_ADDR, &status); - if (err || status != current_stack_cfg->net_transmit) { - FAIL("Net transmit get failed (err %d, status %u)", err, status); - } - - err = bt_mesh_cfg_cli_relay_get(test_netkey_idx, TEST_ADDR, &status, &transmit); - if (err || status != current_stack_cfg->relay.state || - transmit != current_stack_cfg->relay.transmit) { - FAIL("Relay get failed (err %d, state %u, transmit %x)", err, status, transmit); - } - - PASS(); -} - -static int mesh_settings_load_cb(const char *key, size_t len, settings_read_cb read_cb, - void *cb_arg, void *param) -{ - ASSERT_TRUE(len == 0); - - return 0; -} - -/** @brief Test reprovisioning with persistent storage, device side. - * - * Wait for being provisioned and configured, then wait for the node reset and store settings. - */ -static void test_reprovisioning_device(void) -{ - if (clear_settings) { - settings_test_backend_clear(); - } - - bt_mesh_test_cfg_set(NULL, WAIT_TIME); - - device_setup(); - - ASSERT_FALSE(bt_mesh_is_provisioned()); - - ASSERT_OK(bt_mesh_prov_enable(BT_MESH_PROV_ADV)); - - LOG_INF("Waiting for being provisioned..."); - ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(40))); - - LOG_INF("Waiting for the node reset..."); - ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(40))); - - k_sleep(K_SECONDS(CONFIG_BT_MESH_STORE_TIMEOUT)); - - /* Check that all mesh settings were removed. */ - settings_load_subtree_direct("bt/mesh", mesh_settings_load_cb, NULL); - - PASS(); -} - -/** @brief Test reprovisioning with persistent storage, provisioner side. - * - * Verify that a device can clear its data from persistent storage after node reset. - */ -static void test_reprovisioning_provisioner(void) -{ - int err; - bool status; - - settings_test_backend_clear(); - bt_mesh_test_cfg_set(NULL, WAIT_TIME); - - provisioner_setup(); - - LOG_INF("Provisioning a remote device..."); - ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(40))); - - /* Verify that the remote device is not configured. */ - node_configuration_check(&access_cfgs[NOT_CONFIGURED]); - - /* Configure the remote device. */ - node_configure(); - - /* Let the remote device store configuration. */ - k_sleep(K_SECONDS(CONFIG_BT_MESH_STORE_TIMEOUT * 2)); - - err = bt_mesh_cfg_cli_node_reset(test_netkey_idx, TEST_ADDR, &status); - if (err || !status) { - FAIL("Reset failed (err %d, status: %d)", err, status); - } - - /* Let the remote device store configuration. */ - k_sleep(K_SECONDS(CONFIG_BT_MESH_STORE_TIMEOUT * 2)); - - PASS(); -} - -#define TEST_CASE(role, name, description) \ - { \ - .test_id = "persistence_" #role "_" #name, \ - .test_args_f = test_args_parse, \ - .test_descr = description, \ - .test_tick_f = bt_mesh_test_timeout, \ - .test_main_f = test_##role##_##name, \ - } - -static const struct bst_test_instance test_persistence[] = { - TEST_CASE(provisioning, data_save, "Save provisioning data"), - TEST_CASE(provisioning, data_load, "Load previously saved data and verify"), - TEST_CASE(access, data_save, "Save access data"), - TEST_CASE(access, data_load, "Load previously saved access data and verify"), - TEST_CASE(access, sub_overwrite, "Overwrite Subscription List and store"), - TEST_CASE(access, data_remove, "Remove stored access data"), - TEST_CASE(cfg, save, "Save mesh configuration"), - TEST_CASE(cfg, load, "Load previously stored mesh configuration and verify"), - TEST_CASE(reprovisioning, device, "Reprovisioning test, device role"), - TEST_CASE(reprovisioning, provisioner, "Reprovisioning test, provisioner role"), - BSTEST_END_MARKER -}; - -struct bst_test_list *test_persistence_install(struct bst_test_list *tests) -{ - return bst_add_tests(tests, test_persistence); -} diff --git a/tests/bluetooth/bsim/mesh/src/test_provision.c b/tests/bluetooth/bsim/mesh/src/test_provision.c deleted file mode 100644 index 336d1873959..00000000000 --- a/tests/bluetooth/bsim/mesh/src/test_provision.c +++ /dev/null @@ -1,1277 +0,0 @@ -/* - * Copyright (c) 2021 Lingao Meng - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include - -#include "mesh_test.h" -#include "mesh/access.h" -#include "mesh/net.h" -#include "argparse.h" -#include "settings_test_backend.h" -#include -#include - -#include -#include -#include - -#include - -#define LOG_MODULE_NAME mesh_prov - -#include -LOG_MODULE_REGISTER(LOG_MODULE_NAME); - -/* - * Provision layer tests: - * Tests both the provisioner and device role in various scenarios. - */ - -#define PROV_MULTI_COUNT 3 -#define PROV_REPROV_COUNT 3 -#define WAIT_TIME 120 /*seconds*/ -#define IS_RPR_PRESENT (CONFIG_BT_MESH_RPR_SRV && CONFIG_BT_MESH_RPR_CLI) - -enum test_flags { - IS_PROVISIONER, - - TEST_FLAGS, -}; - -static uint8_t static_key1[] = {0x6E, 0x6F, 0x72, 0x64, 0x69, 0x63, 0x5F, - 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x5F, 0x31}; -static uint8_t static_key2[] = {0x6E, 0x6F, 0x72, 0x64, 0x69, 0x63, 0x5F}; - -static uint8_t private_key_be[64]; -static uint8_t public_key_be[64]; - -static struct oob_auth_test_vector_s { - const uint8_t *static_val; - uint8_t static_val_len; - uint8_t output_size; - uint16_t output_actions; - uint8_t input_size; - uint16_t input_actions; -} oob_auth_test_vector[] = { - {NULL, 0, 0, 0, 0, 0}, - {static_key1, sizeof(static_key1), 0, 0, 0, 0}, - {static_key2, sizeof(static_key2), 0, 0, 0, 0}, - {NULL, 0, 3, BT_MESH_BLINK, 0, 0}, - {NULL, 0, 5, BT_MESH_BEEP, 0, 0}, - {NULL, 0, 6, BT_MESH_VIBRATE, 0, 0}, - {NULL, 0, 7, BT_MESH_DISPLAY_NUMBER, 0, 0}, - {NULL, 0, 8, BT_MESH_DISPLAY_STRING, 0, 0}, - {NULL, 0, 0, 0, 4, BT_MESH_PUSH}, - {NULL, 0, 0, 0, 5, BT_MESH_TWIST}, - {NULL, 0, 0, 0, 8, BT_MESH_ENTER_NUMBER}, - {NULL, 0, 0, 0, 7, BT_MESH_ENTER_STRING}, -}; - -static ATOMIC_DEFINE(test_flags, TEST_FLAGS); - -extern const struct bt_mesh_comp comp; -extern const uint8_t test_net_key[16]; -extern const uint8_t test_app_key[16]; - -/* Timeout semaphore */ -static struct k_sem prov_sem; -static uint16_t prov_addr = 0x0002; -static uint16_t current_dev_addr; -static const uint8_t dev_key[16] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; -static uint8_t dev_uuid[16] = { 0x6c, 0x69, 0x6e, 0x67, 0x61, 0x6f }; -static uint8_t *uuid_to_provision; -static struct k_sem reprov_sem; - -#if IS_RPR_PRESENT -/* Remote Provisioning models related variables. */ -static uint8_t *uuid_to_provision_remote; -static void rpr_scan_report(struct bt_mesh_rpr_cli *cli, const struct bt_mesh_rpr_node *srv, - struct bt_mesh_rpr_unprov *unprov, struct net_buf_simple *adv_data); - -static struct bt_mesh_rpr_cli rpr_cli = { - .scan_report = rpr_scan_report, -}; - -static const struct bt_mesh_comp rpr_cli_comp = { - .elem = - (struct bt_mesh_elem[]){ - BT_MESH_ELEM(1, - MODEL_LIST(BT_MESH_MODEL_CFG_SRV, - BT_MESH_MODEL_CFG_CLI(&(struct bt_mesh_cfg_cli){}), - BT_MESH_MODEL_RPR_CLI(&rpr_cli)), - BT_MESH_MODEL_NONE), - }, - .elem_count = 1, -}; - -static const struct bt_mesh_comp rpr_srv_comp = { - .elem = - (struct bt_mesh_elem[]){ - BT_MESH_ELEM(1, - MODEL_LIST(BT_MESH_MODEL_CFG_SRV, - BT_MESH_MODEL_RPR_SRV), - BT_MESH_MODEL_NONE), - }, - .elem_count = 1, -}; - -static const struct bt_mesh_comp rpr_srv_comp_2_elem = { - .elem = - (struct bt_mesh_elem[]){ - BT_MESH_ELEM(1, - MODEL_LIST(BT_MESH_MODEL_CFG_SRV, - BT_MESH_MODEL_RPR_SRV), - BT_MESH_MODEL_NONE), - BT_MESH_ELEM(2, - MODEL_LIST(BT_MESH_MODEL_CB(TEST_MOD_ID, BT_MESH_MODEL_NO_OPS, - NULL, NULL, NULL)), - BT_MESH_MODEL_NONE), - }, - .elem_count = 2, -}; -#endif /* IS_RPR_PRESENT */ - -/* Delayed work to avoid requesting OOB info before generation of this. */ -static struct k_work_delayable oob_timer; -static void delayed_input(struct k_work *work); - -static uint *oob_channel_id; -static bool is_oob_auth; - -static void test_device_init(void) -{ - /* Ensure that the UUID is unique: */ - dev_uuid[6] = '0' + get_device_nbr(); - - bt_mesh_test_cfg_set(NULL, WAIT_TIME); - k_work_init_delayable(&oob_timer, delayed_input); -} - -static void test_provisioner_init(void) -{ - atomic_set_bit(test_flags, IS_PROVISIONER); - bt_mesh_test_cfg_set(NULL, WAIT_TIME); - k_work_init_delayable(&oob_timer, delayed_input); -} - -static void test_terminate(void) -{ - if (oob_channel_id) { - bs_clean_back_channels(); - } -} - -static void unprovisioned_beacon(uint8_t uuid[16], - bt_mesh_prov_oob_info_t oob_info, - uint32_t *uri_hash) -{ - if (!atomic_test_bit(test_flags, IS_PROVISIONER)) { - return; - } - - if (uuid_to_provision && memcmp(uuid, uuid_to_provision, 16)) { - return; - } - - bt_mesh_provision_adv(uuid, 0, prov_addr, 0); -} - -static void prov_complete(uint16_t net_idx, uint16_t addr) -{ - if (!atomic_test_bit(test_flags, IS_PROVISIONER)) { - k_sem_give(&prov_sem); - } -} - -static void prov_node_added(uint16_t net_idx, uint8_t uuid[16], uint16_t addr, - uint8_t num_elem) -{ - LOG_INF("Device 0x%04x provisioned", prov_addr); - current_dev_addr = prov_addr++; - k_sem_give(&prov_sem); -} - -static void prov_reprovisioned(uint16_t addr) -{ - LOG_INF("Device reprovisioned. New address: 0x%04x", addr); - k_sem_give(&reprov_sem); -} - -static void prov_reset(void) -{ - ASSERT_OK(bt_mesh_prov_enable(BT_MESH_PROV_ADV)); -} - -static bt_mesh_input_action_t gact; -static uint8_t gsize; -static int input(bt_mesh_input_action_t act, uint8_t size) -{ - /* The test system requests the input OOB data earlier than - * the output OOB is generated. Need to release context here - * to allow output OOB creation. OOB will be inserted later - * after the delay. - */ - gact = act; - gsize = size; - - k_work_reschedule(&oob_timer, K_SECONDS(1)); - - return 0; -} - -static void delayed_input(struct k_work *work) -{ - char oob_str[16]; - uint32_t oob_number; - int size = bs_bc_is_msg_received(*oob_channel_id); - - if (size <= 0) { - FAIL("OOB data is not gotten"); - } - - switch (gact) { - case BT_MESH_PUSH: - case BT_MESH_TWIST: - case BT_MESH_ENTER_NUMBER: - ASSERT_TRUE(size == sizeof(uint32_t)); - bs_bc_receive_msg(*oob_channel_id, (uint8_t *)&oob_number, size); - ASSERT_OK(bt_mesh_input_number(oob_number)); - break; - case BT_MESH_ENTER_STRING: - bs_bc_receive_msg(*oob_channel_id, (uint8_t *)oob_str, size); - ASSERT_OK(bt_mesh_input_string(oob_str)); - break; - default: - FAIL("Unknown input action %u (size %u) requested!", gact, gsize); - } -} - -static void prov_input_complete(void) -{ - LOG_INF("Input OOB data completed"); -} - -static int output_number(bt_mesh_output_action_t action, uint32_t number); -static int output_string(const char *str); -static void capabilities(const struct bt_mesh_dev_capabilities *cap); -static struct bt_mesh_prov prov = { - .uuid = dev_uuid, - .unprovisioned_beacon = unprovisioned_beacon, - .complete = prov_complete, - .reprovisioned = prov_reprovisioned, - .node_added = prov_node_added, - .output_number = output_number, - .output_string = output_string, - .input = input, - .input_complete = prov_input_complete, - .capabilities = capabilities, - .reset = prov_reset, -}; - -static int output_number(bt_mesh_output_action_t action, uint32_t number) -{ - LOG_INF("OOB Number: %u", number); - - bs_bc_send_msg(*oob_channel_id, (uint8_t *)&number, sizeof(uint32_t)); - return 0; -} - -static int output_string(const char *str) -{ - LOG_INF("OOB String: %s", str); - - bs_bc_send_msg(*oob_channel_id, (uint8_t *)str, strlen(str) + 1); - return 0; -} - -static void capabilities(const struct bt_mesh_dev_capabilities *cap) -{ - if (cap->oob_type & BT_MESH_STATIC_OOB_AVAILABLE) { - LOG_INF("Static OOB authentication"); - ASSERT_OK(bt_mesh_auth_method_set_static(prov.static_val, prov.static_val_len)); - } else if (cap->output_actions) { - LOG_INF("Output OOB authentication"); - ASSERT_OK(bt_mesh_auth_method_set_output(prov.output_actions, prov.output_size)); - } else if (cap->input_actions) { - LOG_INF("Input OOB authentication"); - ASSERT_OK(bt_mesh_auth_method_set_input(prov.input_actions, prov.input_size)); - } else if (!is_oob_auth) { - bt_mesh_auth_method_set_none(); - } else { - FAIL("No OOB in capability frame"); - } -} - -static void oob_auth_set(int test_step) -{ - struct oob_auth_test_vector_s dummy = {0}; - - ASSERT_TRUE(test_step < ARRAY_SIZE(oob_auth_test_vector)); - - if (memcmp(&oob_auth_test_vector[test_step], &dummy, - sizeof(struct oob_auth_test_vector_s))) { - is_oob_auth = true; - } else { - is_oob_auth = false; - } - - prov.static_val = oob_auth_test_vector[test_step].static_val; - prov.static_val_len = oob_auth_test_vector[test_step].static_val_len; - prov.output_size = oob_auth_test_vector[test_step].output_size; - prov.output_actions = oob_auth_test_vector[test_step].output_actions; - prov.input_size = oob_auth_test_vector[test_step].input_size; - prov.input_actions = oob_auth_test_vector[test_step].input_actions; -} - -static void oob_device(bool use_oob_pk) -{ - int err = 0; - - k_sem_init(&prov_sem, 0, 1); - - oob_channel_id = bs_open_back_channel(get_device_nbr(), - (uint[]){(get_device_nbr() + 1) % 2}, (uint[]){0}, 1); - if (!oob_channel_id) { - FAIL("Can't open OOB interface (err %d)\n", err); - } - - bt_mesh_device_setup(&prov, &comp); - - if (use_oob_pk) { - ASSERT_TRUE(uECC_make_key(public_key_be, private_key_be, uECC_secp256r1())); - prov.public_key_be = public_key_be; - prov.private_key_be = private_key_be; - bs_bc_send_msg(*oob_channel_id, public_key_be, 64); - LOG_HEXDUMP_INF(public_key_be, 64, "OOB Public Key:"); - } - - for (int i = 0; i < ARRAY_SIZE(oob_auth_test_vector); i++) { - oob_auth_set(i); - - ASSERT_OK(bt_mesh_prov_enable(BT_MESH_PROV_ADV)); - - /* Keep a long timeout so the prov multi case has time to finish: */ - ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(40))); - - /* Delay to complete procedure with Provisioning Complete PDU frame. - * Device shall start later provisioner was able to set OOB public key. - */ - k_sleep(K_SECONDS(2)); - - bt_mesh_reset(); - } -} - -static void oob_provisioner(bool read_oob_pk, bool use_oob_pk) -{ - int err = 0; - - k_sem_init(&prov_sem, 0, 1); - - oob_channel_id = bs_open_back_channel(get_device_nbr(), - (uint[]){(get_device_nbr() + 1) % 2}, (uint[]){0}, 1); - if (!oob_channel_id) { - FAIL("Can't open OOB interface (err %d)\n", err); - } - - bt_mesh_device_setup(&prov, &comp); - - if (read_oob_pk) { - /* Delay to complete procedure public key generation on provisioning device. */ - k_sleep(K_SECONDS(1)); - - int size = bs_bc_is_msg_received(*oob_channel_id); - - if (size <= 0) { - FAIL("OOB public key is not gotten"); - } - - bs_bc_receive_msg(*oob_channel_id, public_key_be, 64); - LOG_HEXDUMP_INF(public_key_be, 64, "OOB Public Key:"); - } - - ASSERT_OK(bt_mesh_cdb_create(test_net_key)); - - ASSERT_OK(bt_mesh_provision(test_net_key, 0, 0, 0, 0x0001, dev_key)); - - for (int i = 0; i < ARRAY_SIZE(oob_auth_test_vector); i++) { - oob_auth_set(i); - - if (use_oob_pk) { - ASSERT_OK(bt_mesh_prov_remote_pub_key_set(public_key_be)); - } - - ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(40))); - - bt_mesh_cdb_node_del(bt_mesh_cdb_node_get(prov_addr - 1), true); - - /* Delay to complete procedure with cleaning of the public key. - * This is important that the provisioner started the new cycle loop - * earlier than device to get OOB public key before capabilities frame. - */ - k_sleep(K_SECONDS(1)); - } - - bt_mesh_reset(); -} - -/** Configures the health server on a node at current_dev_addr address and sends node reset. - */ -static void node_configure_and_reset(void) -{ - uint8_t status; - size_t subs_count = 1; - uint16_t sub; - struct bt_mesh_cfg_cli_mod_pub healthpub = { 0 }; - struct bt_mesh_cdb_node *node; - - /* Check that publication and subscription are reset after last iteration */ - ASSERT_OK(bt_mesh_cfg_cli_mod_sub_get(0, current_dev_addr, current_dev_addr, - BT_MESH_MODEL_ID_HEALTH_SRV, &status, &sub, - &subs_count)); - ASSERT_EQUAL(0, status); - ASSERT_TRUE(subs_count == 0); - - ASSERT_OK(bt_mesh_cfg_cli_mod_pub_get(0, current_dev_addr, current_dev_addr, - BT_MESH_MODEL_ID_HEALTH_SRV, &healthpub, - &status)); - ASSERT_EQUAL(0, status); - ASSERT_TRUE(healthpub.addr == BT_MESH_ADDR_UNASSIGNED, "Pub not cleared"); - - /* Set pub and sub to check that they are reset */ - healthpub.addr = 0xc001; - healthpub.app_idx = 0; - healthpub.cred_flag = false; - healthpub.ttl = 10; - healthpub.period = BT_MESH_PUB_PERIOD_10SEC(1); - healthpub.transmit = BT_MESH_TRANSMIT(3, 100); - - ASSERT_OK(bt_mesh_cfg_cli_app_key_add(0, current_dev_addr, 0, 0, test_app_key, - &status)); - ASSERT_EQUAL(0, status); - - k_sleep(K_SECONDS(1)); - - ASSERT_OK(bt_mesh_cfg_cli_mod_app_bind(0, current_dev_addr, current_dev_addr, 0x0, - BT_MESH_MODEL_ID_HEALTH_SRV, &status)); - ASSERT_EQUAL(0, status); - - k_sleep(K_SECONDS(1)); - - ASSERT_OK(bt_mesh_cfg_cli_mod_sub_add(0, current_dev_addr, current_dev_addr, 0xc000, - BT_MESH_MODEL_ID_HEALTH_SRV, &status)); - ASSERT_EQUAL(0, status); - - k_sleep(K_SECONDS(1)); - - ASSERT_OK(bt_mesh_cfg_cli_mod_pub_set(0, current_dev_addr, current_dev_addr, - BT_MESH_MODEL_ID_HEALTH_SRV, &healthpub, - &status)); - ASSERT_EQUAL(0, status); - - k_sleep(K_SECONDS(1)); - - ASSERT_OK(bt_mesh_cfg_cli_node_reset(0, current_dev_addr, (bool *)&status)); - - node = bt_mesh_cdb_node_get(current_dev_addr); - bt_mesh_cdb_node_del(node, true); -} - -/** @brief Verify that this device pb-adv provision. - */ -static void test_device_pb_adv_no_oob(void) -{ - k_sem_init(&prov_sem, 0, 1); - - bt_mesh_device_setup(&prov, &comp); - - ASSERT_OK(bt_mesh_prov_enable(BT_MESH_PROV_ADV)); - - LOG_INF("Mesh initialized\n"); - - /* Keep a long timeout so the prov multi case has time to finish: */ - ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(40))); - - PASS(); -} - -/** @brief Verify that this device can be reprovisioned after resets - */ -static void test_device_pb_adv_reprovision(void) -{ - k_sem_init(&prov_sem, 0, 1); - - bt_mesh_device_setup(&prov, &comp); - - ASSERT_OK(bt_mesh_prov_enable(BT_MESH_PROV_ADV)); - - LOG_INF("Mesh initialized\n"); - - for (int i = 0; i < PROV_REPROV_COUNT; i++) { - /* Keep a long timeout so the prov multi case has time to finish: */ - LOG_INF("Dev prov loop #%d, waiting for prov ...\n", i); - ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(20))); - } - - PASS(); -} - -/** @brief Verify that this provisioner pb-adv provision. - */ -static void test_provisioner_pb_adv_no_oob(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)); - - ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(5))); - - PASS(); -} - -static void test_device_pb_adv_oob_auth(void) -{ - oob_device(false); - - PASS(); -} - -static void test_provisioner_pb_adv_oob_auth(void) -{ - oob_provisioner(false, false); - - PASS(); -} - -static void test_device_pb_adv_oob_public_key(void) -{ - oob_device(true); - - PASS(); -} - -static void test_provisioner_pb_adv_oob_public_key(void) -{ - oob_provisioner(true, true); - - PASS(); -} - -static void test_provisioner_pb_adv_oob_auth_no_oob_public_key(void) -{ - oob_provisioner(true, false); - - PASS(); -} - -/** @brief Verify that the provisioner can provision multiple devices in a row - */ -static void test_provisioner_pb_adv_multi(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)); - - for (int i = 0; i < PROV_MULTI_COUNT; i++) { - ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(20))); - } - - PASS(); -} - -/** @brief Verify that when the IV Update flag is set to zero at the - * time of provisioning, internal IV update counter is also zero. - */ -static void test_provisioner_iv_update_flag_zero(void) -{ - uint8_t flags = 0x00; - - bt_mesh_device_setup(&prov, &comp); - - ASSERT_OK(bt_mesh_provision(test_net_key, 0, flags, 0, 0x0001, dev_key)); - - if (bt_mesh.ivu_duration != 0) { - FAIL("IV Update duration counter is not 0 when IV Update flag is zero"); - } - - PASS(); -} - -/** @brief Verify that when the IV Update flag is set to one at the - * time of provisioning, internal IV update counter is set to 96 hours. - */ -static void test_provisioner_iv_update_flag_one(void) -{ - uint8_t flags = 0x02; /* IV Update flag bit set to 1 */ - - bt_mesh_device_setup(&prov, &comp); - - ASSERT_OK(bt_mesh_provision(test_net_key, 0, flags, 0, 0x0001, dev_key)); - - if (bt_mesh.ivu_duration != 96) { - FAIL("IV Update duration counter is not 96 when IV Update flag is one"); - } - - bt_mesh_reset(); - - if (bt_mesh.ivu_duration != 0) { - FAIL("IV Update duration counter is not reset to 0"); - } - - PASS(); -} - -/** @brief Verify that the provisioner can provision a device multiple times after resets - */ -static void test_provisioner_pb_adv_reprovision(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)); - - for (int i = 0; i < PROV_REPROV_COUNT; i++) { - LOG_INF("Provisioner prov loop #%d, waiting for prov ...\n", i); - ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(20))); - - node_configure_and_reset(); - } - - PASS(); -} - -#if IS_RPR_PRESENT -static int provision_adv(uint8_t dev_idx, uint16_t *addr) -{ - static uint8_t uuid[16]; - int err; - - memcpy(uuid, dev_uuid, 16); - uuid[6] = '0' + dev_idx; - uuid_to_provision = uuid; - - LOG_INF("Waiting for a device with RPR Server to be provisioned over PB-Adv..."); - err = k_sem_take(&prov_sem, K_SECONDS(10)); - *addr = current_dev_addr; - - return err; -} - -static int provision_remote(struct bt_mesh_rpr_node *srv, uint8_t dev_idx, uint16_t *addr) -{ - static uint8_t uuid[16]; - struct bt_mesh_rpr_scan_status scan_status; - int err; - - memcpy(uuid, dev_uuid, 16); - uuid[6] = '0' + dev_idx; - uuid_to_provision_remote = uuid; - - LOG_INF("Starting scanning for an unprov device..."); - ASSERT_OK(bt_mesh_rpr_scan_start(&rpr_cli, srv, NULL, 5, 1, &scan_status)); - ASSERT_EQUAL(BT_MESH_RPR_SUCCESS, scan_status.status); - ASSERT_EQUAL(BT_MESH_RPR_SCAN_MULTI, scan_status.scan); - ASSERT_EQUAL(1, scan_status.max_devs); - ASSERT_EQUAL(5, scan_status.timeout); - - err = k_sem_take(&prov_sem, K_SECONDS(20)); - *addr = current_dev_addr; - - return err; -} - -static void rpr_scan_report(struct bt_mesh_rpr_cli *cli, const struct bt_mesh_rpr_node *srv, - struct bt_mesh_rpr_unprov *unprov, struct net_buf_simple *adv_data) -{ - if (!uuid_to_provision_remote || memcmp(uuid_to_provision_remote, unprov->uuid, 16)) { - return; - } - - LOG_INF("Remote device discovered. Provisioning..."); - ASSERT_OK(bt_mesh_provision_remote(cli, srv, unprov->uuid, 0, prov_addr)); -} - -static void prov_node_added_rpr(uint16_t net_idx, uint8_t uuid[16], uint16_t addr, - uint8_t num_elem) -{ - LOG_INF("Device 0x%04x reprovisioned", addr); - k_sem_give(&reprov_sem); -} - -static void provisioner_pb_remote_client_setup(void) -{ - k_sem_init(&prov_sem, 0, 1); - k_sem_init(&reprov_sem, 0, 1); - - bt_mesh_device_setup(&prov, &rpr_cli_comp); - - ASSERT_OK(bt_mesh_cdb_create(test_net_key)); - ASSERT_OK(bt_mesh_provision(test_net_key, 0, 0, 0, 0x0001, dev_key)); -} - -static void device_pb_remote_server_setup(const struct bt_mesh_comp *comp, bool pb_adv_prov) -{ - k_sem_init(&prov_sem, 0, 1); - k_sem_init(&reprov_sem, 0, 1); - - bt_mesh_device_setup(&prov, comp); - - if (pb_adv_prov) { - ASSERT_OK(bt_mesh_prov_enable(BT_MESH_PROV_ADV)); - - LOG_INF("Waiting for being provisioned..."); - ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(20))); - } else { - ASSERT_TRUE(bt_mesh_is_provisioned()); - } - - LOG_INF("Enabling PB-Remote server"); - ASSERT_OK(bt_mesh_prov_enable(BT_MESH_PROV_REMOTE)); -} - -static void device_pb_remote_server_setup_unproved(const struct bt_mesh_comp *comp) -{ - device_pb_remote_server_setup(comp, true); -} - -static void device_pb_remote_server_setup_proved(const struct bt_mesh_comp *comp) -{ - device_pb_remote_server_setup(comp, false); -} - -/** @brief Verify that the provisioner can provision a device multiple times after resets using - * PB-Remote and RPR models. - */ -static void test_provisioner_pb_remote_client_reprovision(void) -{ - uint16_t pb_remote_server_addr; - - provisioner_pb_remote_client_setup(); - - /* Provision the 2nd device over PB-Adv. */ - ASSERT_OK(provision_adv(1, &pb_remote_server_addr)); - - for (int i = 0; i < PROV_REPROV_COUNT; i++) { - struct bt_mesh_rpr_node srv = { - .addr = pb_remote_server_addr, - .net_idx = 0, - .ttl = 3, - }; - - LOG_INF("Provisioner prov loop #%d, waiting for prov ...\n", i); - ASSERT_OK(provision_remote(&srv, 2, &srv.addr)); - - node_configure_and_reset(); - } - - PASS(); -} - -/** @brief Verify robustness of NPPI procedures on a RPR Client by running Device Key Refresh, - * Node Composition Refresh and Node Address Refresh procedures. - */ -static void test_provisioner_pb_remote_client_nppi_robustness(void) -{ - NET_BUF_SIMPLE_DEFINE(dev_comp, BT_MESH_RX_SDU_MAX); - NET_BUF_SIMPLE_DEFINE(new_dev_comp, BT_MESH_RX_SDU_MAX); - uint8_t page; - uint16_t pb_remote_server_addr; - uint8_t status; - struct bt_mesh_cdb_node *node; - uint8_t prev_node_dev_key[16]; - - provisioner_pb_remote_client_setup(); - - /* Provision the 2nd device over PB-Adv. */ - ASSERT_OK(provision_adv(1, &pb_remote_server_addr)); - - /* Provision a remote device with RPR Server. */ - struct bt_mesh_rpr_node srv = { - .addr = pb_remote_server_addr, - .net_idx = 0, - .ttl = 3, - }; - - ASSERT_OK(provision_remote(&srv, 2, &srv.addr)); - - /* Check device key by adding appkey. */ - ASSERT_OK(bt_mesh_cfg_cli_app_key_add(0, current_dev_addr, 0, 0, test_app_key, &status)); - ASSERT_OK(status); - - /* Swap callback to catch when device reprovisioned. */ - prov.node_added = prov_node_added_rpr; - - /* Store initial Composition Data Page 0. */ - ASSERT_OK(bt_mesh_cfg_cli_comp_data_get(0, current_dev_addr, 0, &page, &dev_comp)); - - node = bt_mesh_cdb_node_get(current_dev_addr); - ASSERT_TRUE(node); - memcpy(prev_node_dev_key, node->dev_key, 16); - - LOG_INF("Testing DevKey refresh..."); - for (int i = 0; i < PROV_REPROV_COUNT; i++) { - LOG_INF("Refreshing device key #%d...\n", i); - bt_mesh_reprovision_remote(&rpr_cli, &srv, current_dev_addr, false); - - ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(20))); - - /* Check that CDB has updated Device Key for the node. */ - ASSERT_TRUE(memcmp(prev_node_dev_key, node->dev_key, 16)); - memcpy(prev_node_dev_key, node->dev_key, 16); - - /* Check device key by adding appkey. */ - ASSERT_OK(bt_mesh_cfg_cli_app_key_add(0, current_dev_addr, 0, 0, test_app_key, - &status)); - ASSERT_OK(status); - - /* Let RPR Server verify Device Key. */ - k_sleep(K_SECONDS(2)); - } - - LOG_INF("Testing Composition Data refresh..."); - for (int i = 0; i < PROV_REPROV_COUNT; i++) { - LOG_INF("Changing Composition Data #%d...\n", i); - bt_mesh_reprovision_remote(&rpr_cli, &srv, current_dev_addr, true); - - ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(20))); - - /* Check that CDB has updated Device Key for the node. */ - ASSERT_TRUE(memcmp(prev_node_dev_key, node->dev_key, 16)); - memcpy(prev_node_dev_key, node->dev_key, 16); - - /* Check that Composition Data Page 128 is now Page 0. */ - net_buf_simple_reset(&new_dev_comp); - ASSERT_OK(bt_mesh_cfg_cli_comp_data_get(0, current_dev_addr, 0, &page, - &new_dev_comp)); - ASSERT_EQUAL(0, page); - ASSERT_EQUAL(dev_comp.len, new_dev_comp.len); - if (memcmp(dev_comp.data, new_dev_comp.data, dev_comp.len)) { - FAIL("Wrong composition data page 0"); - } - - /* Let RPR Server verify Device Key. */ - k_sleep(K_SECONDS(2)); - } - - LOG_INF("Testing address refresh..."); - for (int i = 0; i < PROV_REPROV_COUNT; i++) { - LOG_INF("Changing address #%d...\n", i); - bt_mesh_reprovision_remote(&rpr_cli, &srv, current_dev_addr + 1, false); - - ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(20))); - - current_dev_addr++; - srv.addr++; - - /* Check that device doesn't respond to old address with old and new device key. */ - struct bt_mesh_cdb_node *prev_node; - - prev_node = bt_mesh_cdb_node_alloc((uint8_t[16]) {}, current_dev_addr - 1, 1, 0); - ASSERT_TRUE(node); - memcpy(prev_node->dev_key, prev_node_dev_key, 16); - ASSERT_EQUAL(-ETIMEDOUT, bt_mesh_cfg_cli_app_key_add(0, current_dev_addr - 1, 0, 0, - test_app_key, &status)); - memcpy(prev_node->dev_key, node->dev_key, 16); - ASSERT_EQUAL(-ETIMEDOUT, bt_mesh_cfg_cli_app_key_add(0, current_dev_addr - 1, 0, 0, - test_app_key, &status)); - bt_mesh_cdb_node_del(prev_node, false); - - /* Check that CDB has updated Device Key for the node. */ - ASSERT_TRUE(memcmp(prev_node_dev_key, node->dev_key, 16)); - memcpy(prev_node_dev_key, node->dev_key, 16); - - /* Check new device address by adding appkey. */ - ASSERT_OK(bt_mesh_cfg_cli_app_key_add(0, current_dev_addr, 0, 0, test_app_key, - &status)); - ASSERT_OK(status); - - /* Let RPR Server verify Device Key. */ - k_sleep(K_SECONDS(2)); - } - - PASS(); -} - -/** @brief A device running a Remote Provisioning server that is used to provision unprovisioned - * devices over PB-Remote. Always starts unprovisioned. - */ -static void test_device_pb_remote_server_unproved(void) -{ -#if defined(CONFIG_BT_SETTINGS) - settings_test_backend_clear(); -#endif - - device_pb_remote_server_setup_unproved(&rpr_srv_comp); - - PASS(); -} - -/** @brief A device running a Remote Provisioning server that is used to provision unprovisioned - * devices over PB-Remote. Starts provisioned. - */ -static void test_device_pb_remote_server_proved(void) -{ - device_pb_remote_server_setup_proved(&rpr_srv_comp); - - PASS(); -} - -/** @brief Verify robustness of NPPI procedures on a RPR Server by running Device Key Refresh, - * Node Composition Refresh and Node Address Refresh procedures multiple times each. - */ -static void test_device_pb_remote_server_nppi_robustness(void) -{ - uint8_t prev_dev_key[16]; - - k_sem_init(&prov_sem, 0, 1); - k_sem_init(&reprov_sem, 0, 1); - - bt_mesh_device_setup(&prov, &rpr_srv_comp); - - ASSERT_OK(bt_mesh_prov_enable(BT_MESH_PROV_ADV)); - - LOG_INF("Mesh initialized\n"); - - ASSERT_OK(k_sem_take(&prov_sem, K_SECONDS(20))); - const uint16_t initial_addr = bt_mesh_primary_addr(); - - memcpy(prev_dev_key, bt_mesh.dev_key, 16); - - LOG_INF("Enabling PB-Remote server"); - ASSERT_OK(bt_mesh_prov_enable(BT_MESH_PROV_REMOTE)); - - /* Test Device Key Refresh procedure robustness. */ - for (int i = 0; i < PROV_REPROV_COUNT; i++) { - LOG_INF("Devkey refresh loop #%d, waiting for being reprov ...\n", i); - ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(30))); - ASSERT_EQUAL(initial_addr, bt_mesh_primary_addr()); - - /* Let Configuration Client activate the new Device Key and verify that it has - * been changed. - */ - k_sleep(K_SECONDS(2)); - ASSERT_TRUE(memcmp(prev_dev_key, bt_mesh.dev_key, 16)); - memcpy(prev_dev_key, bt_mesh.dev_key, 16); - } - - /* Test Node Composition Refresh procedure robustness. */ - for (int i = 0; i < PROV_REPROV_COUNT; i++) { - /* The RPR Server won't let to run Node Composition Refresh procedure without first - * setting the BT_MESH_COMP_DIRTY flag. The flag is set on a boot if there is a - * "bt/mesh/cmp" entry in settings. The entry is added by the - * `bt_mesh_comp_change_prepare() call. The test suite is not compiled - * with CONFIG_BT_SETTINGS, so the flag will never be set. Since the purpose of the - * test is to check RPR Server behavior, but not the actual swap of the Composition - * Data, the flag is toggled directly from the test. - */ - atomic_set_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY); - - LOG_INF("Composition data refresh loop #%d, waiting for being reprov ...\n", i); - ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(30))); - - /* Drop the flag manually as CONFIG_BT_SETTINGS is not enabled. */ - atomic_clear_bit(bt_mesh.flags, BT_MESH_COMP_DIRTY); - - ASSERT_EQUAL(initial_addr, bt_mesh_primary_addr()); - - /* Let Configuration Client activate the new Device Key and verify that it has - * been changed. - */ - k_sleep(K_SECONDS(2)); - ASSERT_TRUE(memcmp(prev_dev_key, bt_mesh.dev_key, 16)); - memcpy(prev_dev_key, bt_mesh.dev_key, 16); - } - - /* Node Address Refresh robustness. */ - for (int i = 0; i < PROV_REPROV_COUNT; i++) { - LOG_INF("Address refresh loop #%d, waiting for being reprov ...\n", i); - ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(30))); - ASSERT_EQUAL(initial_addr + 1 + i, bt_mesh_primary_addr()); - - /* Let Configuration Client activate the new Device Key and verify that it has - * been changed. - */ - k_sleep(K_SECONDS(2)); - ASSERT_TRUE(memcmp(prev_dev_key, bt_mesh.dev_key, 16)); - memcpy(prev_dev_key, bt_mesh.dev_key, 16); - } - - PASS(); -} - -/** @brief Test Node Composition Refresh procedure on Remote Provisioning client: - * - provision a device over PB-Adv, - * - provision a remote device over PB-Remote. - */ -static void test_provisioner_pb_remote_client_ncrp_provision(void) -{ - uint16_t pb_remote_server_addr; - uint8_t status; - - settings_test_backend_clear(); - provisioner_pb_remote_client_setup(); - - /* Provision the 2nd device over PB-Adv. */ - ASSERT_OK(provision_adv(1, &pb_remote_server_addr)); - - /* Provision the 3rd device over PB-Remote. */ - struct bt_mesh_rpr_node srv = { - .addr = pb_remote_server_addr, - .net_idx = 0, - .ttl = 3, - }; - - ASSERT_OK(provision_remote(&srv, 2, &srv.addr)); - - /* Check device key by adding appkey. */ - ASSERT_OK(bt_mesh_cfg_cli_app_key_add(0, pb_remote_server_addr, 0, 0, test_app_key, - &status)); - ASSERT_OK(status); - - PASS(); -} - -/** @brief Test Node Composition Refresh procedure on Remote Provisioning client: - * - initiate Node Composition Refresh procedure on a 3rd device. - */ -static void test_provisioner_pb_remote_client_ncrp(void) -{ - NET_BUF_SIMPLE_DEFINE(dev_comp_p0, BT_MESH_RX_SDU_MAX); - NET_BUF_SIMPLE_DEFINE(dev_comp_p128, BT_MESH_RX_SDU_MAX); - uint16_t pb_remote_server_addr = 0x0003; - uint8_t page; - - k_sem_init(&prov_sem, 0, 1); - k_sem_init(&reprov_sem, 0, 1); - - bt_mesh_device_setup(&prov, &rpr_cli_comp); - - /* Store Composition Data Page 0 and 128. */ - ASSERT_OK(bt_mesh_cfg_cli_comp_data_get(0, pb_remote_server_addr, 0, &page, &dev_comp_p0)); - ASSERT_EQUAL(0, page); - ASSERT_OK(bt_mesh_cfg_cli_comp_data_get(0, pb_remote_server_addr, 128, &page, - &dev_comp_p128)); - ASSERT_EQUAL(128, page); - ASSERT_TRUE(dev_comp_p0.len != dev_comp_p128.len); - - LOG_INF("Start Node Composition Refresh procedure...\n"); - struct bt_mesh_rpr_node srv = { - .addr = pb_remote_server_addr, - .net_idx = 0, - .ttl = 3, - }; - - /* Swap callback to catch when device reprovisioned. */ - prov.node_added = prov_node_added_rpr; - - ASSERT_OK(bt_mesh_reprovision_remote(&rpr_cli, &srv, pb_remote_server_addr, true)); - ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(20))); - - /* Check that Composition Data Page 128 is now Page 0. */ - net_buf_simple_reset(&dev_comp_p0); - ASSERT_OK(bt_mesh_cfg_cli_comp_data_get(0, pb_remote_server_addr, 0, &page, &dev_comp_p0)); - ASSERT_EQUAL(0, page); - ASSERT_EQUAL(dev_comp_p0.len, dev_comp_p128.len); - if (memcmp(dev_comp_p0.data, dev_comp_p128.data, dev_comp_p0.len)) { - FAIL("Wrong composition data page 0"); - } - - net_buf_simple_reset(&dev_comp_p128); - ASSERT_OK(bt_mesh_cfg_cli_comp_data_get(0, pb_remote_server_addr, 128, &page, - &dev_comp_p128)); - ASSERT_EQUAL(0, page); - ASSERT_EQUAL(dev_comp_p0.len, dev_comp_p128.len); - if (memcmp(dev_comp_p0.data, dev_comp_p128.data, dev_comp_p0.len)) { - FAIL("Wrong composition data page 128"); - } - - PASS(); -} - -/** @brief Test Node Composition Refresh procedure on Remote Provisioning client: - * - verify that Composition Data Page 0 is updated after reboot. - */ -static void test_provisioner_pb_remote_client_ncrp_second_time(void) -{ - NET_BUF_SIMPLE_DEFINE(dev_comp_p0, BT_MESH_RX_SDU_MAX); - NET_BUF_SIMPLE_DEFINE(dev_comp_p128, BT_MESH_RX_SDU_MAX); - uint16_t pb_remote_server_addr = 0x0003; - uint8_t page; - int err; - - k_sem_init(&prov_sem, 0, 1); - k_sem_init(&reprov_sem, 0, 1); - - bt_mesh_device_setup(&prov, &rpr_cli_comp); - - /* Check Composition Data Page 0 and 128. */ - ASSERT_OK(bt_mesh_cfg_cli_comp_data_get(0, pb_remote_server_addr, 0, &page, &dev_comp_p0)); - ASSERT_EQUAL(0, page); - ASSERT_OK(bt_mesh_cfg_cli_comp_data_get(0, pb_remote_server_addr, 128, &page, - &dev_comp_p128)); - ASSERT_EQUAL(0, page); - ASSERT_TRUE(dev_comp_p0.len == dev_comp_p128.len); - - LOG_INF("Start Node Composition Refresh procedure...\n"); - struct bt_mesh_rpr_node srv = { - .addr = pb_remote_server_addr, - .net_idx = 0, - .ttl = 3, - }; - - /* Swap callback to catch when device reprovisioned. */ - prov.node_added = prov_node_added_rpr; - - ASSERT_OK(bt_mesh_reprovision_remote(&rpr_cli, &srv, pb_remote_server_addr, true)); - err = k_sem_take(&reprov_sem, K_SECONDS(20)); - ASSERT_EQUAL(-EAGAIN, err); - - PASS(); -} - -/** @brief Test Node Composition Refresh procedure on Remote Provisioning server: - * - wait for being provisioned over PB-Adv, - * - prepare Composition Data Page 128. - */ -static void test_device_pb_remote_server_ncrp_prepare(void) -{ - settings_test_backend_clear(); - device_pb_remote_server_setup_unproved(&rpr_srv_comp); - - LOG_INF("Preparing for Composition Data change"); - bt_mesh_comp_change_prepare(); - - PASS(); -} - -/** @brief Test Node Composition Refresh procedure on Remote Provisioning server: - * - start device with new Composition Data - * - wait for being re-provisioned. - */ -static void test_device_pb_remote_server_ncrp(void) -{ - device_pb_remote_server_setup_proved(&rpr_srv_comp_2_elem); - - LOG_INF("Waiting for being re-provisioned."); - ASSERT_OK(k_sem_take(&reprov_sem, K_SECONDS(30))); - - PASS(); -} - -/** @brief Test Node Composition Refresh procedure on Remote Provisioning server: - * - verify that Composition Data Page 128 is erased after being re-provisioned and rebooted. - */ -static void test_device_pb_remote_server_ncrp_second_time(void) -{ - int err; - - device_pb_remote_server_setup_proved(&rpr_srv_comp_2_elem); - - LOG_INF("Wait to verify that node is not re-provisioned..."); - err = k_sem_take(&reprov_sem, K_SECONDS(30)); - ASSERT_EQUAL(-EAGAIN, err); - - PASS(); -} -#endif /* IS_RPR_PRESENT */ - -#define TEST_CASE(role, name, description) \ - { \ - .test_id = "prov_" #role "_" #name, .test_descr = description, \ - .test_post_init_f = test_##role##_init, \ - .test_tick_f = bt_mesh_test_timeout, \ - .test_main_f = test_##role##_##name, \ - .test_delete_f = test_terminate \ - } - -static const struct bst_test_instance test_connect[] = { - TEST_CASE(device, pb_adv_no_oob, - "Device: pb-adv provisioning use no-oob method"), - TEST_CASE(device, pb_adv_oob_auth, - "Device: pb-adv provisioning use oob authentication"), - TEST_CASE(device, pb_adv_oob_public_key, - "Device: pb-adv provisioning use oob public key"), - TEST_CASE(device, pb_adv_reprovision, - "Device: pb-adv provisioning, reprovision"), -#if IS_RPR_PRESENT - TEST_CASE(device, pb_remote_server_unproved, - "Device: used for remote provisioning, starts unprovisioned"), - TEST_CASE(device, pb_remote_server_nppi_robustness, - "Device: pb-remote reprovisioning, NPPI robustness"), -#endif - - TEST_CASE(provisioner, pb_adv_no_oob, - "Provisioner: pb-adv provisioning use no-oob method"), - TEST_CASE(provisioner, pb_adv_multi, - "Provisioner: pb-adv provisioning multiple devices"), - TEST_CASE(provisioner, iv_update_flag_zero, - "Provisioner: effect on ivu_duration when IV Update flag is set to zero"), - TEST_CASE(provisioner, iv_update_flag_one, - "Provisioner: effect on ivu_duration when IV Update flag is set to one"), - TEST_CASE(provisioner, pb_adv_oob_auth, - "Provisioner: pb-adv provisioning use oob authentication"), - TEST_CASE(provisioner, pb_adv_oob_public_key, - "Provisioner: pb-adv provisioning use oob public key"), - TEST_CASE(provisioner, pb_adv_oob_auth_no_oob_public_key, - "Provisioner: pb-adv provisioning use oob authentication, ignore oob public key"), - TEST_CASE(provisioner, pb_adv_reprovision, - "Provisioner: pb-adv provisioning, resetting and reprovisioning multiple times."), -#if IS_RPR_PRESENT - TEST_CASE(provisioner, pb_remote_client_reprovision, - "Provisioner: pb-remote provisioning, resetting and reprov-ing multiple times."), - TEST_CASE(provisioner, pb_remote_client_nppi_robustness, - "Provisioner: pb-remote provisioning, NPPI robustness."), -#endif - - BSTEST_END_MARKER -}; - -struct bst_test_list *test_provision_install(struct bst_test_list *tests) -{ - tests = bst_add_tests(tests, test_connect); - return tests; -} - -#if IS_RPR_PRESENT -static const struct bst_test_instance test_connect_pst[] = { - TEST_CASE(device, pb_remote_server_unproved, - "Device: used for remote provisioning, starts unprovisioned"), - TEST_CASE(device, pb_remote_server_proved, - "Device: used for remote provisioning, starts provisioned"), - - TEST_CASE(device, pb_remote_server_ncrp_prepare, - "Device: NCRP test, prepares for Composition Data change."), - TEST_CASE(device, pb_remote_server_ncrp, - "Device: NCRP test, Composition Data change."), - TEST_CASE(device, pb_remote_server_ncrp_second_time, - "Device: NCRP test, Composition Data change after reboot."), - - TEST_CASE(provisioner, pb_remote_client_ncrp_provision, - "Provisioner: NCRP test, devices provisioning."), - TEST_CASE(provisioner, pb_remote_client_ncrp, - "Provisioner: NCRP test, initiates Node Composition Refresh procedure."), - TEST_CASE(provisioner, pb_remote_client_ncrp_second_time, - "Provisioner: NCRP test, initiates NCR procedure the second time."), - - BSTEST_END_MARKER -}; - -struct bst_test_list *test_provision_pst_install(struct bst_test_list *tests) -{ - tests = bst_add_tests(tests, test_connect_pst); - return tests; -} -#endif /* IS_RPR_PRESENT */ diff --git a/tests/bluetooth/bsim/mesh/src/test_replay_cache.c b/tests/bluetooth/bsim/mesh/src/test_replay_cache.c deleted file mode 100644 index 512d16505ca..00000000000 --- a/tests/bluetooth/bsim/mesh/src/test_replay_cache.c +++ /dev/null @@ -1,480 +0,0 @@ -/* - * Copyright (c) 2021 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include "mesh_test.h" -#include "settings_test_backend.h" -#include "mesh/mesh.h" -#include "mesh/net.h" -#include "mesh/rpl.h" -#include "mesh/transport.h" - -#define LOG_MODULE_NAME test_rpc - -#include -LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL_INF); - -#define WAIT_TIME 60 /*seconds*/ -#define TEST_DATA_WAITING_TIME 5 /* seconds */ -#define TEST_DATA_SIZE 20 - -static const struct bt_mesh_test_cfg tx_cfg = { - .addr = 0x0001, - .dev_key = { 0x01 }, -}; -static const struct bt_mesh_test_cfg rx_cfg = { - .addr = 0x0002, - .dev_key = { 0x02 }, -}; - -static uint8_t test_data[TEST_DATA_SIZE]; -static uint8_t rx_cnt; -static bool is_tx_succeeded; - -static void test_tx_init(void) -{ - bt_mesh_test_cfg_set(&tx_cfg, WAIT_TIME); -} - -static void test_rx_init(void) -{ - bt_mesh_test_cfg_set(&rx_cfg, WAIT_TIME); -} - -static void tx_started(uint16_t dur, int err, void *data) -{ - if (err) { - FAIL("Couldn't start sending (err: %d)", err); - } - - LOG_INF("Sending started"); -} - -static void tx_ended(int err, void *data) -{ - struct k_sem *sem = data; - - if (err) { - is_tx_succeeded = false; - LOG_INF("Sending failed (%d)", err); - } else { - is_tx_succeeded = true; - LOG_INF("Sending succeeded"); - } - - k_sem_give(sem); -} - -static void rx_ended(uint8_t *data, size_t len) -{ - memset(test_data, rx_cnt++, sizeof(test_data)); - - if (memcmp(test_data, data, len)) { - FAIL("Unexpected rx data"); - } - - LOG_INF("Receiving succeeded"); -} - -static void tx_sar_conf(void) -{ -#ifdef CONFIG_BT_MESH_V1d1 - /* Reconfigure SAR Transmitter state so that the transport layer doesn't - * retransmit. - */ - struct bt_mesh_sar_tx tx_set = { - .seg_int_step = CONFIG_BT_MESH_SAR_TX_SEG_INT_STEP, - .unicast_retrans_count = 0, - .unicast_retrans_without_prog_count = 0, - .unicast_retrans_int_step = CONFIG_BT_MESH_SAR_TX_UNICAST_RETRANS_INT_STEP, - .unicast_retrans_int_inc = CONFIG_BT_MESH_SAR_TX_UNICAST_RETRANS_INT_INC, - .multicast_retrans_count = CONFIG_BT_MESH_SAR_TX_MULTICAST_RETRANS_COUNT, - .multicast_retrans_int = CONFIG_BT_MESH_SAR_TX_MULTICAST_RETRANS_INT, - }; - -#if defined(CONFIG_BT_MESH_SAR_CFG) - bt_mesh_test_sar_conf_set(&tx_set, NULL); -#else - bt_mesh.sar_tx = tx_set; -#endif -#endif -} - -static void rx_sar_conf(void) -{ -#ifdef CONFIG_BT_MESH_V1d1 - /* Reconfigure SAR Receiver state so that the transport layer does - * generate Segmented Acks as rarely as possible. - */ - struct bt_mesh_sar_rx rx_set = { - .seg_thresh = 0x1f, - .ack_delay_inc = 0x7, - .discard_timeout = CONFIG_BT_MESH_SAR_RX_DISCARD_TIMEOUT, - .rx_seg_int_step = 0xf, - .ack_retrans_count = CONFIG_BT_MESH_SAR_RX_ACK_RETRANS_COUNT, - }; - -#if defined(CONFIG_BT_MESH_SAR_CFG) - bt_mesh_test_sar_conf_set(NULL, &rx_set); -#else - bt_mesh.sar_rx = rx_set; -#endif -#endif -} - -static void test_tx_immediate_replay_attack(void) -{ - settings_test_backend_clear(); - bt_mesh_test_setup(); - tx_sar_conf(); - - static const struct bt_mesh_send_cb send_cb = { - .start = tx_started, - .end = tx_ended, - }; - struct k_sem sem; - - k_sem_init(&sem, 0, 1); - - uint32_t seq = bt_mesh.seq; - - for (int i = 0; i < 3; i++) { - is_tx_succeeded = false; - - memset(test_data, i, sizeof(test_data)); - ASSERT_OK(bt_mesh_test_send_ra(rx_cfg.addr, test_data, - sizeof(test_data), &send_cb, &sem)); - - if (k_sem_take(&sem, K_SECONDS(TEST_DATA_WAITING_TIME))) { - LOG_ERR("Send timed out"); - } - - ASSERT_TRUE(is_tx_succeeded); - } - - bt_mesh.seq = seq; - - for (int i = 0; i < 3; i++) { - is_tx_succeeded = true; - - memset(test_data, i, sizeof(test_data)); - ASSERT_OK(bt_mesh_test_send_ra(rx_cfg.addr, test_data, - sizeof(test_data), &send_cb, &sem)); - - if (k_sem_take(&sem, K_SECONDS(TEST_DATA_WAITING_TIME))) { - LOG_ERR("Send timed out"); - } - - ASSERT_TRUE(!is_tx_succeeded); - } - - PASS(); -} - -static void test_rx_immediate_replay_attack(void) -{ - settings_test_backend_clear(); - bt_mesh_test_setup(); - rx_sar_conf(); - bt_mesh_test_ra_cb_setup(rx_ended); - - k_sleep(K_SECONDS(6 * TEST_DATA_WAITING_TIME)); - - ASSERT_TRUE(rx_cnt == 3, "Device didn't receive expected data"); - - PASS(); -} - -static void test_tx_power_replay_attack(void) -{ - settings_test_backend_clear(); - bt_mesh_test_setup(); - tx_sar_conf(); - - static const struct bt_mesh_send_cb send_cb = { - .start = tx_started, - .end = tx_ended, - }; - struct k_sem sem; - - k_sem_init(&sem, 0, 1); - - for (int i = 0; i < 3; i++) { - is_tx_succeeded = true; - - memset(test_data, i, sizeof(test_data)); - ASSERT_OK(bt_mesh_test_send_ra(rx_cfg.addr, test_data, - sizeof(test_data), &send_cb, &sem)); - - if (k_sem_take(&sem, K_SECONDS(TEST_DATA_WAITING_TIME))) { - LOG_ERR("Send timed out"); - } - - ASSERT_TRUE(!is_tx_succeeded); - } - - for (int i = 0; i < 3; i++) { - is_tx_succeeded = false; - - memset(test_data, i, sizeof(test_data)); - ASSERT_OK(bt_mesh_test_send_ra(rx_cfg.addr, test_data, - sizeof(test_data), &send_cb, &sem)); - - if (k_sem_take(&sem, K_SECONDS(TEST_DATA_WAITING_TIME))) { - LOG_ERR("Send timed out"); - } - - ASSERT_TRUE(is_tx_succeeded); - } - - PASS(); -} - -static void test_rx_power_replay_attack(void) -{ - bt_mesh_test_setup(); - rx_sar_conf(); - bt_mesh_test_ra_cb_setup(rx_ended); - - k_sleep(K_SECONDS(6 * TEST_DATA_WAITING_TIME)); - - ASSERT_TRUE(rx_cnt == 3, "Device didn't receive expected data"); - - PASS(); -} - -static void send_end_cb(int err, void *cb_data) -{ - struct k_sem *sem = cb_data; - - ASSERT_EQUAL(err, 0); - k_sem_give(sem); -} - -static bool msg_send(uint16_t src, uint16_t dst) -{ - struct bt_mesh_send_cb cb = { - .end = send_end_cb, - }; - struct bt_mesh_msg_ctx ctx = { - .net_idx = 0, - .app_idx = 0, - .addr = dst, - .send_rel = false, - .send_ttl = BT_MESH_TTL_DEFAULT, - }; - struct bt_mesh_net_tx tx = { - .ctx = &ctx, - .src = src, - }; - struct k_sem sem; - int err; - - k_sem_init(&sem, 0, 1); - BT_MESH_MODEL_BUF_DEFINE(msg, TEST_MSG_OP_1, 0); - - bt_mesh_model_msg_init(&msg, TEST_MSG_OP_1); - - err = bt_mesh_trans_send(&tx, &msg, &cb, &sem); - if (err) { - LOG_ERR("Failed to send message (err %d)", err); - return false; - } - - err = k_sem_take(&sem, K_SECONDS(10)); - if (err) { - LOG_ERR("Send timed out (err %d)", err); - return false; - } - - return true; -} - -static bool msg_recv(uint16_t expected_addr) -{ - struct bt_mesh_test_msg msg; - int err; - - err = bt_mesh_test_recv_msg(&msg, K_SECONDS(10)); - if (err) { - LOG_ERR("Failed to receive message from %u (err %d)", expected_addr, err); - return false; - } - - LOG_DBG("Received msg from %u", msg.ctx.addr); - ASSERT_EQUAL(expected_addr, msg.ctx.addr); - - return true; -} - -static bool ivi_update_toggle(void) -{ - bool res; - - bt_mesh_iv_update_test(true); - res = bt_mesh_iv_update(); - bt_mesh_iv_update_test(false); - - return res; -} - -static void test_rx_rpl_frag(void) -{ - settings_test_backend_clear(); - bt_mesh_test_setup(); - - k_sleep(K_SECONDS(10)); - - /* Wait 3 messages from different sources. */ - for (int i = 0; i < 3; i++) { - ASSERT_TRUE(msg_recv(100 + i)); - } - - /* Ask tx node to proceed to next test step. */ - ASSERT_TRUE(msg_send(rx_cfg.addr, tx_cfg.addr)); - - /* Start IVI Update. This will set old_iv for all entries in RPL to 1. */ - ASSERT_TRUE(ivi_update_toggle()); - - /* Receive messages from even nodes with new IVI. RPL entry with odd address will stay - * with old IVI. - */ - ASSERT_TRUE(msg_recv(100)); - ASSERT_TRUE(msg_recv(102)); - - /* Ask tx node to proceed to next test step. */ - ASSERT_TRUE(msg_send(rx_cfg.addr, tx_cfg.addr)); - - /* Complete IVI Update. */ - ASSERT_FALSE(ivi_update_toggle()); - - /* Bump SeqNum in RPL for even addresses. */ - ASSERT_TRUE(msg_recv(100)); - ASSERT_TRUE(msg_recv(102)); - - /* Start IVI Update again. */ - /* RPL entry with odd address should be removed causing fragmentation in RPL. old_iv flag - * for even entries will be set to 1. - */ - ASSERT_TRUE(ivi_update_toggle()); - - /* Ask tx node to proceed to next test step. */ - ASSERT_TRUE(msg_send(rx_cfg.addr, tx_cfg.addr)); - - /* Complete IVI Update. */ - ASSERT_FALSE(ivi_update_toggle()); - - /* Odd address entry should have been removed keeping even addresses accessible. */ - struct bt_mesh_rpl *rpl = NULL; - struct bt_mesh_net_rx rx = { - .old_iv = 1, - .seq = 0, - .ctx.addr = 100, - .local_match = 1, - }; - ASSERT_TRUE(bt_mesh_rpl_check(&rx, &rpl)); - rx.ctx.addr = 101; - ASSERT_FALSE(bt_mesh_rpl_check(&rx, &rpl)); - rx.ctx.addr = 102; - ASSERT_TRUE(bt_mesh_rpl_check(&rx, &rpl)); - - /* Let the settings store RPL. */ - k_sleep(K_SECONDS(CONFIG_BT_MESH_RPL_STORE_TIMEOUT)); - - PASS(); -} - -static void test_tx_rpl_frag(void) -{ - settings_test_backend_clear(); - bt_mesh_test_setup(); - - k_sleep(K_SECONDS(10)); - - /* Send message for 3 different addresses. */ - for (size_t i = 0; i < 3; i++) { - ASSERT_TRUE(msg_send(100 + i, rx_cfg.addr)); - } - - k_sleep(K_SECONDS(3)); - - /* Wait for the rx node. */ - ASSERT_TRUE(msg_recv(rx_cfg.addr)); - - /* Start IVI Update. */ - ASSERT_TRUE(ivi_update_toggle()); - - /* Send msg from elem 1 and 3 with new IVI. 2nd elem should have old IVI. */ - ASSERT_TRUE(msg_send(100, rx_cfg.addr)); - ASSERT_TRUE(msg_send(102, rx_cfg.addr)); - - /* Wait for the rx node. */ - ASSERT_TRUE(msg_recv(rx_cfg.addr)); - - /* Complete IVI Update. */ - ASSERT_FALSE(ivi_update_toggle()); - - /* Send message from even addresses with new IVI keeping odd address with old IVI. */ - ASSERT_TRUE(msg_send(100, rx_cfg.addr)); - ASSERT_TRUE(msg_send(102, rx_cfg.addr)); - - /* Start IVI Update again to be in sync with rx node. */ - ASSERT_TRUE(ivi_update_toggle()); - - /* Wait for rx node. */ - ASSERT_TRUE(msg_recv(rx_cfg.addr)); - - /* Complete IVI Update. */ - ASSERT_FALSE(ivi_update_toggle()); - - PASS(); -} - -static void test_rx_reboot_after_defrag(void) -{ - bt_mesh_test_setup(); - - /* Test that RPL entries are restored correctly after defrag and reboot. */ - struct bt_mesh_rpl *rpl = NULL; - struct bt_mesh_net_rx rx = { - .old_iv = 1, - .seq = 0, - .ctx.addr = 100, - .local_match = 1, - }; - ASSERT_TRUE(bt_mesh_rpl_check(&rx, &rpl)); - rx.ctx.addr = 101; - ASSERT_FALSE(bt_mesh_rpl_check(&rx, &rpl)); - rx.ctx.addr = 102; - ASSERT_TRUE(bt_mesh_rpl_check(&rx, &rpl)); - - PASS(); -} - -#define TEST_CASE(role, name, description) \ - { \ - .test_id = "rpc_" #role "_" #name, \ - .test_descr = description, \ - .test_post_init_f = test_##role##_init, \ - .test_tick_f = bt_mesh_test_timeout, \ - .test_main_f = test_##role##_##name, \ - } - -static const struct bst_test_instance test_rpc[] = { - TEST_CASE(tx, immediate_replay_attack, "RPC: perform replay attack immediately"), - TEST_CASE(tx, power_replay_attack, "RPC: perform replay attack after power cycle"), - TEST_CASE(tx, rpl_frag, "RPC: Send messages after double IVI Update"), - - TEST_CASE(rx, immediate_replay_attack, "RPC: device under immediate attack"), - TEST_CASE(rx, power_replay_attack, "RPC: device under power cycle reply attack"), - TEST_CASE(rx, rpl_frag, "RPC: Test RPL fragmentation after double IVI Update"), - TEST_CASE(rx, reboot_after_defrag, "RPC: Test PRL after defrag and reboot"), - BSTEST_END_MARKER -}; - -struct bst_test_list *test_rpc_install(struct bst_test_list *tests) -{ - tests = bst_add_tests(tests, test_rpc); - return tests; -} diff --git a/tests/bluetooth/bsim/mesh/src/test_sar.c b/tests/bluetooth/bsim/mesh/src/test_sar.c deleted file mode 100644 index 5b35f0173aa..00000000000 --- a/tests/bluetooth/bsim/mesh/src/test_sar.c +++ /dev/null @@ -1,287 +0,0 @@ -/* - * Copyright (c) 2022 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - * - * SAR stress test - */ - -#include "mesh_test.h" - -#include - -#include - -LOG_MODULE_REGISTER(test_sar, LOG_LEVEL_INF); - -#define CLI_ADDR 0x7728 -#define SRV_ADDR 0x18f8 -#define WAIT_TIME 60 /* seconds */ -#define SEM_TIMEOUT K_SECONDS(25) -#define RAND_SEED 1 - -#define DUMMY_VND_MOD_GET_OP BT_MESH_MODEL_OP_3(0xDC, TEST_VND_COMPANY_ID) -#define DUMMY_VND_MOD_STATUS_OP BT_MESH_MODEL_OP_3(0xCD, TEST_VND_COMPANY_ID) - -#define MAX_SDU_MSG_LEN \ - BT_MESH_TX_SDU_MAX - BT_MESH_MIC_SHORT - BT_MESH_MODEL_OP_LEN(DUMMY_VND_MOD_GET_OP) - -static struct k_sem inst_suspend_sem; -static const uint8_t dev_key[16] = {0xaa}; - -static uint8_t dummy_msg[MAX_SDU_MSG_LEN] = {0}; - -static struct bt_mesh_msg_ctx test_ctx = { - .net_idx = 0, - .app_idx = 0, - .addr = SRV_ADDR, -}; - -/* Segment Interval Step for both Transmitter and Receiver Configuration states must be at least 1, - * or else network buffers run out. - */ -static struct bt_mesh_sar_tx test_sar_tx = { - .seg_int_step = 1, - .unicast_retrans_count = 15, - .unicast_retrans_without_prog_count = 15, - .unicast_retrans_int_step = 0, - .unicast_retrans_int_inc = 0, -}; - -static struct bt_mesh_sar_rx test_sar_rx = { - .seg_thresh = 0, - .ack_delay_inc = 0, - .discard_timeout = 15, - .rx_seg_int_step = 1, - .ack_retrans_count = 3, -}; - -static struct bt_mesh_sar_tx test_sar_slow_tx = { - .seg_int_step = 15, - .unicast_retrans_count = CONFIG_BT_MESH_SAR_TX_UNICAST_RETRANS_COUNT, - .unicast_retrans_without_prog_count = - CONFIG_BT_MESH_SAR_TX_UNICAST_RETRANS_WITHOUT_PROG_COUNT, - .unicast_retrans_int_step = 15, - .unicast_retrans_int_inc = 15, -}; - -static struct bt_mesh_sar_rx test_sar_slow_rx = { - .seg_thresh = 0x1f, - .ack_delay_inc = 7, - .discard_timeout = CONFIG_BT_MESH_SAR_RX_DISCARD_TIMEOUT, - .rx_seg_int_step = 15, - .ack_retrans_count = CONFIG_BT_MESH_SAR_RX_ACK_RETRANS_COUNT, -}; - -static struct bt_mesh_prov prov; -static struct bt_mesh_cfg_cli cfg_cli; -static struct bt_mesh_sar_cfg_cli sar_cli; - -/* Assert that buffer length and data corresponds with test dummy message. - * Buffer state is saved. - */ -static void data_integrity_check(struct net_buf_simple *buf) -{ - struct net_buf_simple_state state = {0}; - - ASSERT_EQUAL(buf->len, MAX_SDU_MSG_LEN); - net_buf_simple_save(buf, &state); - - /* Note: Using ASSERT_TRUE since ASSERT_EQUAL would call cond twise if not true. */ - ASSERT_TRUE(memcmp(net_buf_simple_pull_mem(buf, MAX_SDU_MSG_LEN), dummy_msg, - MAX_SDU_MSG_LEN) == 0); - net_buf_simple_restore(buf, &state); -} - -static int get_handler(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) -{ - data_integrity_check(buf); - BT_MESH_MODEL_BUF_DEFINE(msg, DUMMY_VND_MOD_STATUS_OP, MAX_SDU_MSG_LEN); - bt_mesh_model_msg_init(&msg, DUMMY_VND_MOD_STATUS_OP); - net_buf_simple_add_mem(&msg, buf->data, buf->len); - - k_sem_give(&inst_suspend_sem); - - return bt_mesh_model_send(model, ctx, &msg, NULL, NULL); -} - -static int status_handler(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) -{ - data_integrity_check(buf); - k_sem_give(&inst_suspend_sem); - return 0; -} - -static int dummy_vnd_mod_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, - uint8_t msg[]) -{ - BT_MESH_MODEL_BUF_DEFINE(buf, DUMMY_VND_MOD_GET_OP, MAX_SDU_MSG_LEN); - - bt_mesh_model_msg_init(&buf, DUMMY_VND_MOD_GET_OP); - net_buf_simple_add_mem(&buf, msg, MAX_SDU_MSG_LEN); - - return bt_mesh_model_send(model, ctx, &buf, NULL, NULL); -} - -static const struct bt_mesh_model_op _dummy_vnd_mod_op[] = { - {DUMMY_VND_MOD_GET_OP, MAX_SDU_MSG_LEN, get_handler}, - {DUMMY_VND_MOD_STATUS_OP, MAX_SDU_MSG_LEN, status_handler}, - BT_MESH_MODEL_OP_END, -}; - -uint16_t dummy_keys[CONFIG_BT_MESH_MODEL_KEY_COUNT] = { 0 }; - -static struct bt_mesh_model dummy_vnd_mod = { - .op = _dummy_vnd_mod_op, - .keys = dummy_keys, - .keys_cnt = CONFIG_BT_MESH_MODEL_KEY_COUNT, - .vnd.id = TEST_VND_MOD_ID, - .vnd.company = TEST_VND_COMPANY_ID, -}; - -static struct bt_mesh_elem elements[] = {BT_MESH_ELEM( - 0, - MODEL_LIST(BT_MESH_MODEL_CFG_SRV, - BT_MESH_MODEL_CFG_CLI(&cfg_cli), - BT_MESH_MODEL_SAR_CFG_CLI(&sar_cli), - BT_MESH_MODEL_SAR_CFG_SRV), - MODEL_LIST(BT_MESH_MODEL_VND_CB(TEST_VND_COMPANY_ID, TEST_VND_MOD_ID, _dummy_vnd_mod_op, - NULL, &dummy_vnd_mod, NULL)))}; - -static const struct bt_mesh_comp comp = { - .cid = TEST_VND_COMPANY_ID, - .elem = elements, - .elem_count = ARRAY_SIZE(elements), -}; - -static void prov_and_conf(uint16_t addr, - struct bt_mesh_sar_rx *sar_rx_config, - struct bt_mesh_sar_tx *sar_tx_config) -{ - int err; - uint8_t status; - struct bt_mesh_sar_tx tx_rsp; - struct bt_mesh_sar_rx rx_rsp; - - ASSERT_OK(bt_mesh_provision(test_net_key, 0, 0, 0, addr, dev_key)); - - err = bt_mesh_cfg_cli_app_key_add(0, addr, 0, 0, test_app_key, &status); - if (err || status) { - FAIL("AppKey add failed (err %d, status %u)", err, status); - } - - err = bt_mesh_cfg_cli_mod_app_bind_vnd(0, addr, addr, 0, TEST_VND_MOD_ID, - TEST_VND_COMPANY_ID, &status); - if (err || status) { - FAIL("Failed to bind Dummy vnd model to application (err %d, status %u)", err, - status); - } - - ASSERT_OK(bt_mesh_sar_cfg_cli_transmitter_set(0, addr, sar_tx_config, &tx_rsp)); - ASSERT_OK(bt_mesh_sar_cfg_cli_receiver_set(0, addr, sar_rx_config, &rx_rsp)); -} - -static void array_random_fill(uint8_t array[], uint16_t len, int seed) -{ - /* Ensures that the same random numbers are used for both client and server instances. */ - srand(seed); - for (uint16_t i = 0; i < len; i++) { - array[i] = rand() % 100; - } -} - -static void cli_max_len_sdu_send(struct bt_mesh_sar_rx *sar_rx_config, - struct bt_mesh_sar_tx *sar_tx_config) -{ - bt_mesh_test_cfg_set(NULL, WAIT_TIME); - bt_mesh_device_setup(&prov, &comp); - prov_and_conf(CLI_ADDR, sar_rx_config, sar_tx_config); - - ASSERT_OK(k_sem_init(&inst_suspend_sem, 0, 1)); - array_random_fill(dummy_msg, ARRAY_SIZE(dummy_msg), RAND_SEED); - - for (int i = 0; i < 2; i++) { - ASSERT_OK(dummy_vnd_mod_get(&dummy_vnd_mod, &test_ctx, dummy_msg)); - /* Wait for message response */ - if (k_sem_take(&inst_suspend_sem, SEM_TIMEOUT)) { - FAIL("Client suspension timed out."); - } - k_sem_reset(&inst_suspend_sem); - } - - PASS(); -} - -static void srv_max_len_sdu_receive(struct bt_mesh_sar_rx *sar_rx_config, - struct bt_mesh_sar_tx *sar_tx_config) -{ - bt_mesh_test_cfg_set(NULL, WAIT_TIME); - bt_mesh_device_setup(&prov, &comp); - prov_and_conf(SRV_ADDR, sar_rx_config, sar_tx_config); - - ASSERT_OK(k_sem_init(&inst_suspend_sem, 0, 1)); - array_random_fill(dummy_msg, ARRAY_SIZE(dummy_msg), RAND_SEED); - - /* Wait for message to be received */ - if (k_sem_take(&inst_suspend_sem, SEM_TIMEOUT)) { - FAIL("Server suspension timed out."); - } - - PASS(); -} - -static void test_cli_max_len_sdu_send(void) -{ - cli_max_len_sdu_send(&test_sar_rx, &test_sar_tx); - - PASS(); -} - -static void test_srv_max_len_sdu_receive(void) -{ - srv_max_len_sdu_receive(&test_sar_rx, &test_sar_tx); - - PASS(); -} - -static void test_cli_max_len_sdu_slow_send(void) -{ - cli_max_len_sdu_send(&test_sar_slow_rx, &test_sar_slow_tx); - - PASS(); -} - -static void test_srv_max_len_sdu_slow_receive(void) -{ - srv_max_len_sdu_receive(&test_sar_slow_rx, &test_sar_slow_tx); - - PASS(); -} - -#define TEST_CASE(role, name, description) \ - { \ - .test_id = "sar_" #role "_" #name, \ - .test_descr = description, \ - .test_tick_f = bt_mesh_test_timeout, \ - .test_main_f = test_##role##_##name, \ - } - -static const struct bst_test_instance test_sar[] = { - TEST_CASE(cli, max_len_sdu_send, - "Send a 32-segment message with pre-defined test SAR configurations"), - TEST_CASE(srv, max_len_sdu_receive, - "Receive a 32-segment message with pre-defined test SAR configurations."), - TEST_CASE(cli, max_len_sdu_slow_send, - "Send a 32-segment message with SAR configured with slowest timings."), - TEST_CASE(srv, max_len_sdu_slow_receive, - "Receive a 32-segment message with with SAR configured with slowest timings."), - - BSTEST_END_MARKER}; - -struct bst_test_list *test_sar_install(struct bst_test_list *tests) -{ - tests = bst_add_tests(tests, test_sar); - return tests; -} diff --git a/tests/bluetooth/bsim/mesh/src/test_scanner.c b/tests/bluetooth/bsim/mesh/src/test_scanner.c deleted file mode 100644 index aaccd84cec4..00000000000 --- a/tests/bluetooth/bsim/mesh/src/test_scanner.c +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright (c) 2021 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include -#include "mesh_test.h" -#include "mesh/net.h" -#include "mesh/adv.h" -#include "mesh/mesh.h" -#include "mesh/foundation.h" - -#define LOG_MODULE_NAME test_scanner - -#include -LOG_MODULE_REGISTER(LOG_MODULE_NAME); - -#define WAIT_TIME 60 /*seconds*/ -#define ADV_INT_FAST_MS 20 -#define ADV_DURATION 120 - -extern enum bst_result_t bst_result; - -/* Create a valid message */ -static const uint8_t valid_message[28] = { - 0x0d, 0x10, 0xca, 0x54, 0xd0, - 0x00, 0x24, 0x00, 0xaa, 0x8c, - 0xcc, 0x6b, 0x6a, 0xc8, 0x51, - 0x69, 0x16, 0x4d, 0xf6, 0x9b, - 0xce, 0xbd, 0xc7, 0xa3, 0xf0, - 0x28, 0xdf, 0xae -}; - -static const struct bt_mesh_test_cfg tx_cfg = { - .addr = 0x0001, - .dev_key = { 0x01 }, -}; -static const struct bt_mesh_test_cfg rx_cfg = { - .addr = 0x0002, - .dev_key = { 0x02 }, -}; - -static void test_tx_init(void) -{ - bt_mesh_test_cfg_set(&tx_cfg, WAIT_TIME); -} - -static void test_rx_init(void) -{ - bt_mesh_test_cfg_set(&rx_cfg, WAIT_TIME); -} - -/* Setup the tx device by enabling Bluetooth, but no scanner is needed. */ -static void test_tx_device_setup(void) -{ - int err; - - err = bt_enable(NULL); - if (err) { - FAIL("Bluetooth init failed (err %d)", err); - return; - } - - LOG_INF("Bluetooth initialized"); -} - -/** Bypassing setting up transmission, and will try to send the raw data that is - * provided to the function. - */ -static void test_tx_send_ad_type_msg(uint8_t type, const uint8_t *data, uint8_t len) -{ - struct bt_le_adv_param param = {}; - uint16_t duration, adv_int; - struct bt_data ad; - int err; - - adv_int = ADV_INT_FAST_MS; - duration = ADV_DURATION; - - ad.type = type; - ad.data_len = len; - ad.data = data; - - param.id = BT_ID_DEFAULT; - param.interval_min = BT_MESH_ADV_SCAN_UNIT(adv_int); - param.interval_max = param.interval_min; - - LOG_DBG("ad.type %u len %u", ad.type, ad.data_len); - LOG_HEXDUMP_DBG(ad.data, ad.data_len, "ad.data"); - - uint64_t st = k_uptime_get(); - - err = bt_le_adv_start(¶m, &ad, 1, NULL, 0); - if (err) { - FAIL("Advertising failed: err %d", err); - return; - } - LOG_DBG("Advertising started. Sleeping %u ms", duration); - - k_sleep(K_MSEC(duration)); - err = bt_le_adv_stop(); - if (err) { - FAIL("Stopping advertising failed: err %d", err); - return; - } - LOG_DBG("Advertising stopped (%u ms)", (uint32_t) k_uptime_delta(&st)); -} - -/** Test sending message with not supported ad type for mesh. - * - * First message send message with an ad data type not supported by mesh, and - * verify that the receiver is disregarding message. Then send the same message - * with correct ad type to verify that the message is received. - */ -static void test_tx_invalid_ad_type(void) -{ - test_tx_device_setup(); - - LOG_DBG("TX Invalid AD Type"); - - k_sleep(K_SECONDS(1)); - - /* Send message with invalid ad type. */ - test_tx_send_ad_type_msg(BT_DATA_BIG_INFO, valid_message, - ARRAY_SIZE(valid_message)); - - /* Wait for no message receive window to end. */ - k_sleep(K_SECONDS(10)); - - /* Send message with valid ad type to verify message. */ - test_tx_send_ad_type_msg(BT_DATA_MESH_MESSAGE, valid_message, - ARRAY_SIZE(valid_message)); - - PASS(); -} - -/** Test sending message with invalid/valid ad type and wrong packet length. - * - * Send messages with wrong packet length, and verify that the receiver is - * disregarding message. Then send the same message with correct packet length - * to verify that the message is received. - */ -static void test_tx_wrong_packet_length(void) -{ - test_tx_device_setup(); - - LOG_DBG("TX wrong packet length"); - - k_sleep(K_SECONDS(1)); - - /* Send message with to long data length. */ - test_tx_send_ad_type_msg(BT_DATA_MESH_MESSAGE, valid_message, - ARRAY_SIZE(valid_message)+1); - /* Send message with to short data length. */ - test_tx_send_ad_type_msg(BT_DATA_MESH_MESSAGE, valid_message, - ARRAY_SIZE(valid_message)-1); - /* Send message with invalid ad type and wrong data length. */ - test_tx_send_ad_type_msg(BT_DATA_BIG_INFO, valid_message, - ARRAY_SIZE(valid_message)+1); - - /* Wait for no message receive window to end. */ - k_sleep(K_SECONDS(10)); - - /* Send message with valid ad type to verify message. */ - test_tx_send_ad_type_msg(BT_DATA_MESH_MESSAGE, valid_message, - ARRAY_SIZE(valid_message)); - - PASS(); -} - -/** Test receiving message with invalid ad type or packet length for mesh. */ -static void test_rx_invalid_packet(void) -{ - struct bt_mesh_test_msg msg; - int err; - - bt_mesh_test_setup(); - - LOG_DBG("RX Invalid packet"); - - /* Wait to check that no valid messages is received. */ - err = bt_mesh_test_recv_msg(&msg, K_SECONDS(10)); - if (!err) { - FAIL("Unexpected rx from 0x%04x", msg.ctx.addr); - } - - /* Verify that test data is received correct. */ - err = bt_mesh_test_recv(10, cfg->addr, K_SECONDS(10)); - ASSERT_OK_MSG(err, "Failed receiving with valid ad_type"); - - PASS(); -} - -#define TEST_CASE(role, name, description) \ - { \ - .test_id = "scanner_" #role "_" #name, \ - .test_descr = description, \ - .test_post_init_f = test_##role##_init, \ - .test_tick_f = bt_mesh_test_timeout, \ - .test_main_f = test_##role##_##name, \ - } - -static const struct bst_test_instance test_scanner[] = { - TEST_CASE(tx, invalid_ad_type, "Scanner: Invalid AD Type"), - TEST_CASE(tx, wrong_packet_length, "Scanner: Wrong data length"), - - TEST_CASE(rx, invalid_packet, "Scanner: Invalid packet"), - BSTEST_END_MARKER -}; - -struct bst_test_list *test_scanner_install(struct bst_test_list *tests) -{ - tests = bst_add_tests(tests, test_scanner); - return tests; -} diff --git a/tests/bluetooth/bsim/mesh/src/test_transport.c b/tests/bluetooth/bsim/mesh/src/test_transport.c deleted file mode 100644 index 548c408b70b..00000000000 --- a/tests/bluetooth/bsim/mesh/src/test_transport.c +++ /dev/null @@ -1,554 +0,0 @@ -/* - * Copyright (c) 2021 Nordic Semiconductor - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include "mesh_test.h" -#include "mesh/net.h" -#include "mesh/transport.h" -#include - -/* - * Transport layer tests: - * This file contains tests for sending and receiving messages end-to-end in - * all permutations. Covers: - * - Address resolution - * - Segmented messages - * - Single segment - * - Max length - * - Groups - * - Virtual addresses - * - Loopback - * - * Tests are divided into senders and receivers. - */ - -void assert_post_action(const char *file, unsigned int line) -{ - FAIL("Asserted at %s:%u", file, line); -} - -#define GROUP_ADDR 0xc000 -#define WAIT_TIME 70 /*seconds*/ -#define SYNC_CHAN 0 -#define CLI_DEV 0 -#define SRV1_DEV 1 - -extern enum bst_result_t bst_result; - -static const struct bt_mesh_test_cfg tx_cfg = { - .addr = 0x0001, - .dev_key = { 0x01 }, -}; -static const struct bt_mesh_test_cfg rx_cfg = { - .addr = 0x0002, - .dev_key = { 0x02 }, -}; - -static int expected_send_err; - -static void test_tx_init(void) -{ - bt_mesh_test_cfg_set(&tx_cfg, WAIT_TIME); -} - -static void test_rx_init(void) -{ - bt_mesh_test_cfg_set(&rx_cfg, WAIT_TIME); -} - -static void async_send_end(int err, void *data) -{ - struct k_sem *sem = data; - - if (err != expected_send_err) { - FAIL("Async send failed: got %d, expected", err, expected_send_err); - } - - if (sem) { - k_sem_give(sem); - } -} - -static void rx_sar_conf(void) -{ -#ifdef CONFIG_BT_MESH_V1d1 - /* Reconfigure SAR Receiver state so that the transport layer does - * generate Segmented Acks as rarely as possible. - */ - struct bt_mesh_sar_rx rx_set = { - .seg_thresh = 0x1f, - .ack_delay_inc = CONFIG_BT_MESH_SAR_RX_ACK_DELAY_INC, - .discard_timeout = CONFIG_BT_MESH_SAR_RX_DISCARD_TIMEOUT, - .rx_seg_int_step = CONFIG_BT_MESH_SAR_RX_SEG_INT_STEP, - .ack_retrans_count = CONFIG_BT_MESH_SAR_RX_ACK_RETRANS_COUNT, - }; - -#if defined(CONFIG_BT_MESH_SAR_CFG) - bt_mesh_test_sar_conf_set(NULL, &rx_set); -#else - bt_mesh.sar_rx = rx_set; -#endif -#endif -} - -static const struct bt_mesh_send_cb async_send_cb = { - .end = async_send_end, -}; - -/** Test vector containing various permutations of transport messages. */ -static const struct { - uint16_t len; - enum bt_mesh_test_send_flags flags; -} test_vector[] = { - {.len = 1, .flags = 0}, - {.len = 1, .flags = FORCE_SEGMENTATION}, - {.len = BT_MESH_APP_SEG_SDU_MAX, .flags = 0}, - {.len = BT_MESH_APP_SEG_SDU_MAX, .flags = FORCE_SEGMENTATION}, - - /* segmented */ - {.len = BT_MESH_APP_SEG_SDU_MAX + 1, .flags = 0}, - {.len = 256, .flags = LONG_MIC}, - {.len = BT_MESH_TX_SDU_MAX - BT_MESH_MIC_SHORT, .flags = 0}, -}; - -/** Test sending of unicast messages using the test vector. - */ -static void test_tx_unicast(void) -{ - int err; - - bt_mesh_test_setup(); - - for (int i = 0; i < ARRAY_SIZE(test_vector); i++) { - err = bt_mesh_test_send(rx_cfg.addr, test_vector[i].len, - test_vector[i].flags, K_SECONDS(10)); - ASSERT_OK_MSG(err, "Failed sending vector %d", i); - } - - PASS(); -} - -/** Test sending of group messages using the test vector. - */ -static void test_tx_group(void) -{ - int err; - - bt_mesh_test_setup(); - - for (int i = 0; i < ARRAY_SIZE(test_vector); i++) { - err = bt_mesh_test_send(GROUP_ADDR, test_vector[i].len, - test_vector[i].flags, K_SECONDS(20)); - ASSERT_OK_MSG(err, "Failed sending vector %d", i); - } - - PASS(); -} - -/** Test sending of virtual address messages using the test vector. - */ -static void test_tx_va(void) -{ - uint16_t virtual_addr; - int err; - - bt_mesh_test_setup(); - - err = bt_mesh_va_add(test_va_uuid, &virtual_addr); - ASSERT_OK_MSG(err, "Virtual addr add failed (err %d)", err); - - /* Wait for the receiver to subscribe on address. */ - k_sleep(K_SECONDS(1)); - - for (int i = 0; i < ARRAY_SIZE(test_vector); i++) { - err = bt_mesh_test_send(virtual_addr, test_vector[i].len, - test_vector[i].flags, K_SECONDS(20)); - ASSERT_OK_MSG(err, "Failed sending vector %d", i); - } - - PASS(); -} - -/** Test sending of messages to own unicast address using the test vector. - */ -static void test_tx_loopback(void) -{ - int err; - - bt_mesh_test_setup(); - - for (int i = 0; i < ARRAY_SIZE(test_vector); i++) { - bt_mesh_test_recv(test_vector[i].len, cfg->addr, K_NO_WAIT); - err = bt_mesh_test_send(cfg->addr, test_vector[i].len, - test_vector[i].flags, - K_SECONDS(20)); - ASSERT_OK_MSG(err, "Failed sending vector %d", i); - - if (test_stats.received != i + 1) { - FAIL("Didn't receive message %d", i); - } - } - - PASS(); -} - -/** Test sending of messages with an app key that's unknown to the receiver. - * - * The sender should be able to send the message successfully, but the receiver - * should fail the decryption step and ignore the packet. - */ -static void test_tx_unknown_app(void) -{ - uint8_t app_key[16] = { 0xba, 0xd0, 0x11, 0x22}; - uint8_t status = 0; - - bt_mesh_test_setup(); - - ASSERT_OK_MSG(bt_mesh_cfg_cli_app_key_add(0, cfg->addr, 0, 1, app_key, &status), - "Failed adding additional appkey"); - if (status) { - FAIL("App key add status: 0x%02x", status); - } - - ASSERT_OK_MSG(bt_mesh_cfg_cli_mod_app_bind(0, cfg->addr, cfg->addr, 1, - TEST_MOD_ID, &status), - "Failed binding additional appkey"); - if (status) { - FAIL("App key add status: 0x%02x", status); - } - - test_send_ctx.app_idx = 1; - - ASSERT_OK_MSG(bt_mesh_test_send(rx_cfg.addr, 5, 0, K_SECONDS(1)), - "Failed sending unsegmented"); - - ASSERT_OK_MSG(bt_mesh_test_send(rx_cfg.addr, 25, 0, K_SECONDS(1)), - "Failed sending segmented"); - - PASS(); -} - -/** Test sending of messages using the test vector. - * - * Messages are sent to a group address that both the sender and receiver - * subscribes to, verifying that the loopback and advertiser paths both work - * when used in combination. - */ -static void test_tx_loopback_group(void) -{ - uint8_t status; - int err; - - bt_mesh_test_setup(); - - err = bt_mesh_cfg_cli_mod_sub_add(0, cfg->addr, cfg->addr, GROUP_ADDR, - TEST_MOD_ID, &status); - ASSERT_OK_MSG(err || status, "Mod sub add failed (err %d, status %u)", - err, status); - - for (int i = 0; i < ARRAY_SIZE(test_vector); i++) { - err = bt_mesh_test_send(GROUP_ADDR, test_vector[i].len, - test_vector[i].flags, - K_SECONDS(20)); - - ASSERT_OK_MSG(err, "Failed sending vector %d", i); - - k_sleep(K_SECONDS(1)); - ASSERT_OK_MSG(bt_mesh_test_recv(test_vector[i].len, GROUP_ADDR, - K_SECONDS(1)), - "Failed receiving loopback %d", i); - - if (test_stats.received != i + 1) { - FAIL("Didn't receive message %d", i); - } - } - - PASS(); -} - -/** Start sending multiple segmented messages to the same destination at the - * same time. - * - * The second message should be blocked until the first is finished, but - * should still succeed. - */ -static void test_tx_seg_block(void) -{ - bt_mesh_test_setup(); - - - ASSERT_OK(bt_mesh_test_send(rx_cfg.addr, 20, 0, K_NO_WAIT)); - - /* Send some more to the same address before the first is finished. */ - ASSERT_OK(bt_mesh_test_send(rx_cfg.addr, 20, 0, K_NO_WAIT)); - ASSERT_OK(bt_mesh_test_send(rx_cfg.addr, 20, 0, K_SECONDS(10))); - - if (test_stats.sent != 3) { - FAIL("Not all messages completed (%u/3)", test_stats.sent); - } - - PASS(); -} - -/** Start sending multiple segmented messages to the same destination at the - * same time. - * - * The second message should be blocked until the first is finished, but - * should still succeed. - */ -static void test_tx_seg_concurrent(void) -{ - struct k_sem sem; - - k_sem_init(&sem, 0, 1); - bt_mesh_test_setup(); - - ASSERT_OK(bt_mesh_test_send_async(rx_cfg.addr, 20, 0, &async_send_cb, &sem)); - - /* Send some more to the same address before the first is finished. */ - ASSERT_OK(bt_mesh_test_send(GROUP_ADDR, 20, 0, K_SECONDS(10))); - - /* Ensure that the first message finishes as well */ - ASSERT_OK(k_sem_take(&sem, K_SECONDS(1))); - - PASS(); -} - -/** Start sending a segmented message, then before it's finished, start an IV - * update. - * After the first one finishes, the IV update state shall be active. - * Send another message, then end the IV update state before it's finished. - * The IV index should change when this message finishes. - * - * The IV update should not interfere with the segmented message, and the - */ -static void test_tx_seg_ivu(void) -{ - struct k_sem sem; - uint32_t iv_index; - - k_sem_init(&sem, 0, 1); - - bt_mesh_test_setup(); - - /* Enable IV update test mode to override IV update timers */ - bt_mesh_iv_update_test(true); - - iv_index = BT_MESH_NET_IVI_TX; - - ASSERT_OK(bt_mesh_test_send_async(rx_cfg.addr, 255, 0, &async_send_cb, - &sem)); - /* Start IV update */ - bt_mesh_iv_update(); - - if (iv_index != BT_MESH_NET_IVI_TX) { - FAIL("Should not change TX IV index before IV update ends"); - } - - k_sem_take(&sem, K_SECONDS(20)); - - ASSERT_OK(bt_mesh_test_send_async(rx_cfg.addr, 255, 0, &async_send_cb, - &sem)); - - /* End IV update */ - bt_mesh_iv_update(); - - if (iv_index != BT_MESH_NET_IVI_TX) { - FAIL("Should not change TX IV index until message finishes"); - } - - k_sem_take(&sem, K_SECONDS(20)); - - if (iv_index + 1 != BT_MESH_NET_IVI_TX) { - FAIL("Should have changed TX IV index when the message was completed"); - } - - PASS(); -} - -/** Send a segmented message to an unknown unicast address, expect it to fail - * and return -ETIMEDOUT in the send end callback. - */ -static void test_tx_seg_fail(void) -{ - struct k_sem sem; - - k_sem_init(&sem, 0, 1); - bt_mesh_test_setup(); - - expected_send_err = -ETIMEDOUT; - ASSERT_OK(bt_mesh_test_send_async(0x0fff, 20, 0, &async_send_cb, &sem)); - ASSERT_OK(k_sem_take(&sem, K_SECONDS(10))); - - PASS(); -} - -/* Receiver test functions */ - -/** @brief Receive unicast messages using the test vector. - */ -static void test_rx_unicast(void) -{ - int err; - - bt_mesh_test_setup(); - rx_sar_conf(); - - for (int i = 0; i < ARRAY_SIZE(test_vector); i++) { - err = bt_mesh_test_recv(test_vector[i].len, cfg->addr, - K_SECONDS(10)); - ASSERT_OK_MSG(err, "Failed receiving vector %d", i); - } - - PASS(); -} - -/** @brief Receive group messages using the test vector. - */ -static void test_rx_group(void) -{ - uint8_t status; - int err; - - bt_mesh_test_setup(); - - err = bt_mesh_cfg_cli_mod_sub_add(0, cfg->addr, cfg->addr, GROUP_ADDR, - TEST_MOD_ID, &status); - ASSERT_OK_MSG(err || status, "Mod sub add failed (err %d, status %u)", err, status); - - for (int i = 0; i < ARRAY_SIZE(test_vector); i++) { - err = bt_mesh_test_recv(test_vector[i].len, GROUP_ADDR, - K_SECONDS(20)); - ASSERT_OK_MSG(err, "Failed receiving vector %d", i); - } - - PASS(); -} - -/** @brief Receive virtual address messages using the test vector. - */ -static void test_rx_va(void) -{ - uint16_t virtual_addr; - uint8_t status; - int err; - - bt_mesh_test_setup(); - - err = bt_mesh_cfg_cli_mod_sub_va_add(0, cfg->addr, cfg->addr, test_va_uuid, - TEST_MOD_ID, &virtual_addr, &status); - ASSERT_OK_MSG(err || status, "Sub add failed (err %d, status %u)", err, status); - - for (int i = 0; i < ARRAY_SIZE(test_vector); i++) { - err = bt_mesh_test_recv(test_vector[i].len, virtual_addr, - K_SECONDS(20)); - ASSERT_OK_MSG(err, "Failed receiving vector %d", i); - } - - PASS(); -} - -/** @brief Verify that this device doesn't receive any messages. - */ -static void test_rx_none(void) -{ - struct bt_mesh_test_msg msg; - int err; - - bt_mesh_test_setup(); - - err = bt_mesh_test_recv_msg(&msg, K_SECONDS(60)); - if (!err) { - FAIL("Unexpected rx from 0x%04x", msg.ctx.addr); - } - - PASS(); -} - -/** @brief Verify that this device doesn't receive any messages. - */ -static void test_rx_seg_block(void) -{ - bt_mesh_test_setup(); - - ASSERT_OK_MSG(bt_mesh_test_recv(20, cfg->addr, K_SECONDS(2)), "RX fail"); - ASSERT_OK_MSG(bt_mesh_test_recv(20, cfg->addr, K_SECONDS(2)), "RX fail"); - ASSERT_OK_MSG(bt_mesh_test_recv(20, cfg->addr, K_SECONDS(2)), "RX fail"); - - PASS(); -} - -/** @brief Verify that this device doesn't receive any messages. - */ -static void test_rx_seg_concurrent(void) -{ - uint8_t status; - int err; - - bt_mesh_test_setup(); - - /* Subscribe to group addr */ - err = bt_mesh_cfg_cli_mod_sub_add(0, cfg->addr, cfg->addr, GROUP_ADDR, - TEST_MOD_ID, &status); - ASSERT_OK_MSG(err || status, "Mod sub add failed (err %d, status %u)", err, status); - - /* Receive both messages from the sender. - * Note: The receive order is technically irrelevant, but the test_recv - * function fails if the order is wrong. - */ - ASSERT_OK_MSG(bt_mesh_test_recv(20, cfg->addr, K_SECONDS(2)), "RX fail"); - ASSERT_OK_MSG(bt_mesh_test_recv(20, GROUP_ADDR, K_SECONDS(2)), "RX fail"); - - PASS(); -} - -/** @brief Verify that this device doesn't receive any messages. - */ -static void test_rx_seg_ivu(void) -{ - bt_mesh_test_setup(); - rx_sar_conf(); - - ASSERT_OK_MSG(bt_mesh_test_recv(255, cfg->addr, K_SECONDS(5)), "RX fail"); - ASSERT_OK_MSG(bt_mesh_test_recv(255, cfg->addr, K_SECONDS(5)), "RX fail"); - - PASS(); -} - -#define TEST_CASE(role, name, description) \ - { \ - .test_id = "transport_" #role "_" #name, \ - .test_descr = description, \ - .test_post_init_f = test_##role##_init, \ - .test_tick_f = bt_mesh_test_timeout, \ - .test_main_f = test_##role##_##name, \ - } - -static const struct bst_test_instance test_connect[] = { - TEST_CASE(tx, unicast, "Transport: send to unicast addr"), - TEST_CASE(tx, group, "Transport: send to group addr"), - TEST_CASE(tx, va, "Transport: send to virtual addr"), - TEST_CASE(tx, loopback, "Transport: send loopback"), - TEST_CASE(tx, loopback_group, "Transport: send loopback and group"), - TEST_CASE(tx, unknown_app, "Transport: send with unknown app key"), - TEST_CASE(tx, seg_block, "Transport: send blocked segmented"), - TEST_CASE(tx, seg_concurrent, "Transport: send concurrent segmented"), - TEST_CASE(tx, seg_ivu, "Transport: send segmented during IV update"), - TEST_CASE(tx, seg_fail, "Transport: send segmented to unused addr"), - - TEST_CASE(rx, unicast, "Transport: receive on unicast addr"), - TEST_CASE(rx, group, "Transport: receive on group addr"), - TEST_CASE(rx, va, "Transport: receive on virtual addr"), - TEST_CASE(rx, none, "Transport: receive no messages"), - TEST_CASE(rx, seg_block, "Transport: receive blocked segmented"), - TEST_CASE(rx, seg_concurrent, "Transport: receive concurrent segmented"), - TEST_CASE(rx, seg_ivu, "Transport: receive segmented during IV update"), - BSTEST_END_MARKER -}; - -struct bst_test_list *test_transport_install(struct bst_test_list *tests) -{ - tests = bst_add_tests(tests, test_connect); - return tests; -} diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/access/access_cancel.sh b/tests/bluetooth/bsim/mesh/tests_scripts/access/access_cancel.sh deleted file mode 100755 index 9b2e5bf3f9a..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/access/access_cancel.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -RunTest mesh_access_publication_cancel \ - access_tx_cancel access_rx_cancel - -conf=prj_mesh1d1_conf -RunTest mesh_access_publication_cancel_1d1 \ - access_tx_cancel access_rx_cancel diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/access/access_ext_sub.sh b/tests/bluetooth/bsim/mesh/tests_scripts/access/access_ext_sub.sh deleted file mode 100755 index c05df1745db..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/access/access_ext_sub.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -RunTest mesh_access_extended_model_subs \ - access_tx_ext_model access_sub_ext_model - -conf=prj_mesh1d1_conf -RunTest mesh_access_extended_model_subs_1d1 \ - access_tx_ext_model access_sub_ext_model diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/access/access_ext_sub_cap.sh b/tests/bluetooth/bsim/mesh/tests_scripts/access/access_ext_sub_cap.sh deleted file mode 100755 index 4f52a419fbf..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/access/access_ext_sub_cap.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -RunTest mesh_access_extended_model_subs_cap access_sub_capacity_ext_model - -conf=prj_mesh1d1_conf -RunTest mesh_access_extended_model_subs_cap_1d1 access_sub_capacity_ext_model diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/access/access_period.sh b/tests/bluetooth/bsim/mesh/tests_scripts/access/access_period.sh deleted file mode 100755 index 15e26a0095a..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/access/access_period.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -RunTest mesh_access_per_pub \ - access_tx_period access_rx_period - -conf=prj_mesh1d1_conf -RunTest mesh_access_per_pub_1d1 \ - access_tx_period access_rx_period diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/access/access_transmit.sh b/tests/bluetooth/bsim/mesh/tests_scripts/access/access_transmit.sh deleted file mode 100755 index a3d7803648f..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/access/access_transmit.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -RunTest mesh_access_pub_retr \ - access_tx_transmit access_rx_transmit - -conf=prj_mesh1d1_conf -RunTest mesh_access_pub_retr_1d1 \ - access_tx_transmit access_rx_transmit diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/advertiser/proxy_mixin.sh b/tests/bluetooth/bsim/mesh/tests_scripts/advertiser/proxy_mixin.sh deleted file mode 100755 index a0240274c0c..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/advertiser/proxy_mixin.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test scenario: -# Initialize the mesh stack, but do not provision the device. -# Start the provisioning procedure using bt_mesh_prov_enable(BT_MESH_PROV_GATT). -# With a separate scanner device, observe PB-GATT beacons being sent -# at approximately 100ms intervals. -# Provision the device using bt_mesh_provision(). -# With a separate scanner device, observe GATT Proxy beacons being sent -# at approximately 1s intervals. -# Allocate an advertiser buffer using bt_mesh_adv_buf_create(). -# With the separate scanner, observe that the GATT Proxy beacons are not interrupted. -# Set the allocated buffer's xmit parameters to BT_MESH_TRANSMIT(5, 20). -# Submit the advertiser buffer using bt_mesh_adv_send(). -# With the separate scanner, observe that the submitted buffer is transmitted -# at least 6 times. Then, observe GATT Proxy beacons resuming. -overlay=overlay_gatt_conf -RunTest mesh_adv_proxy_mixin adv_tx_proxy_mixin adv_rx_proxy_mixin - -conf=prj_mesh1d1_conf -overlay=overlay_gatt_conf -RunTest mesh_adv_proxy_mixin_1d1 adv_tx_proxy_mixin adv_rx_proxy_mixin diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/advertiser/random_order.sh b/tests/bluetooth/bsim/mesh/tests_scripts/advertiser/random_order.sh deleted file mode 100755 index 7cf6e2ff491..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/advertiser/random_order.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# test buffer management by filling buffers and sending them in random order. -RunTest mesh_adv_random_order adv_tx_random_order adv_rx_random_order - -conf=prj_mesh1d1_conf -RunTest mesh_adv_random_order_1d1 adv_tx_random_order adv_rx_random_order diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/advertiser/reverse_order.sh b/tests/bluetooth/bsim/mesh/tests_scripts/advertiser/reverse_order.sh deleted file mode 100755 index f335a3e7311..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/advertiser/reverse_order.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# test buffer management by filling all the buffer and sending them in reversed order. -RunTest mesh_adv_reverse_order adv_tx_reverse_order adv_rx_receive_order - -conf=prj_mesh1d1_conf -RunTest mesh_adv_reverse_order_1d1 adv_tx_reverse_order adv_rx_receive_order diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/advertiser/send_order.sh b/tests/bluetooth/bsim/mesh/tests_scripts/advertiser/send_order.sh deleted file mode 100755 index 29db6c9b2ab..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/advertiser/send_order.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# test buffer management by filling all the buffer and sending them all in order. -RunTest mesh_adv_send_order adv_tx_send_order adv_rx_receive_order - -conf=prj_mesh1d1_conf -RunTest mesh_adv_send_order_1d1 adv_tx_send_order adv_rx_receive_order diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/advertiser/tx_cb_multi.sh b/tests/bluetooth/bsim/mesh/tests_scripts/advertiser/tx_cb_multi.sh deleted file mode 100755 index d5df191742a..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/advertiser/tx_cb_multi.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# test tx callbacks sequence for multiple advs -RunTest mesh_adv_tx_cb_multi adv_tx_cb_multi - -conf=prj_mesh1d1_conf -RunTest mesh_adv_tx_cb_multi_1d1 adv_tx_cb_multi diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/advertiser/tx_cb_single.sh b/tests/bluetooth/bsim/mesh/tests_scripts/advertiser/tx_cb_single.sh deleted file mode 100755 index 21f73a6d2d7..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/advertiser/tx_cb_single.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# test tx callbacks parameters and xmit sequence for single adv -RunTest mesh_adv_tx_cb_single adv_tx_cb_single adv_rx_xmit - -conf=prj_mesh1d1_conf -RunTest mesh_adv_tx_cb_single_1d1 adv_tx_cb_single adv_rx_xmit diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/beacon/beacon_interval.sh b/tests/bluetooth/bsim/mesh/tests_scripts/beacon/beacon_interval.sh deleted file mode 100755 index c99b01e2d6b..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/beacon/beacon_interval.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Precondition: -# setup two device, tx node provisioned node, rx node is not provisioned and only has -# the network creentials. -# Verify: -# tx node is able to adapt observed beacon interval and able to send at least one -# SNB in 600s. And veify tx node doesnn't send SNB faster than 10s. -# Procedure: -# 1- rx node waits for the tx node to send the first SNB, -# rx node sends two SNBs with 20ms period, verifies that tx node only sends SNB 10s later, -# after rx node sends out beacon. rx node skips the 3rd SNB and verifies that tx nodes keeps -# sending SNB # in 20ms until it adapts again and starts to send in 10s. -# 2- rx node sends SNBs with 4s period for 600s and verifies that tx node doesn't send any -# SNB until 600s elapses. - -RunTest mesh_beacon_interval \ - beacon_tx_secure_beacon_interval \ - beacon_rx_secure_beacon_interval - -conf=prj_mesh1d1_conf -RunTest mesh_beacon_interval_1d1 \ - beacon_tx_secure_beacon_interval \ - beacon_rx_secure_beacon_interval diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/beacon/invalid.sh b/tests/bluetooth/bsim/mesh/tests_scripts/beacon/invalid.sh deleted file mode 100755 index 3cf7991a6dd..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/beacon/invalid.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -RunTest mesh_beacon_invalid \ - beacon_tx_invalid \ - beacon_rx_invalid - -conf=prj_mesh1d1_conf -RunTest mesh_beacon_invalid_1d1 \ - beacon_tx_invalid \ - beacon_rx_invalid diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/beacon/iv_update.sh b/tests/bluetooth/bsim/mesh/tests_scripts/beacon/iv_update.sh deleted file mode 100755 index 617059ea0b4..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/beacon/iv_update.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -RunTest mesh_beacon_on_iv_update \ - beacon_tx_on_iv_update \ - beacon_rx_on_iv_update - -conf=prj_mesh1d1_conf -RunTest mesh_beacon_on_iv_update_1d1 \ - beacon_tx_on_iv_update \ - beacon_rx_on_iv_update diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/beacon/key_refresh.sh b/tests/bluetooth/bsim/mesh/tests_scripts/beacon/key_refresh.sh deleted file mode 100755 index b63a77ce3c6..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/beacon/key_refresh.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -RunTest mesh_beacon_on_key_refresh \ - beacon_tx_on_key_refresh \ - beacon_rx_on_key_refresh - -conf=prj_mesh1d1_conf -RunTest mesh_beacon_on_key_refresh_1d1 \ - beacon_tx_on_key_refresh \ - beacon_rx_on_key_refresh diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/beacon/kr_old_key.sh b/tests/bluetooth/bsim/mesh/tests_scripts/beacon/kr_old_key.sh deleted file mode 100755 index 3a8935906b1..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/beacon/kr_old_key.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -RunTest mesh_beacon_kr_old_key \ - beacon_tx_kr_old_key \ - beacon_rx_kr_old_key - -conf=prj_mesh1d1_conf -RunTest mesh_beacon_kr_old_key_1d1 \ - beacon_tx_kr_old_key \ - beacon_rx_kr_old_key diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/beacon/multiple_netkeys.sh b/tests/bluetooth/bsim/mesh/tests_scripts/beacon/multiple_netkeys.sh deleted file mode 100755 index dc3b5b15cb2..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/beacon/multiple_netkeys.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -RunTest mesh_beacon_multiple_netkeys \ - beacon_tx_multiple_netkeys \ - beacon_rx_multiple_netkeys - -conf=prj_mesh1d1_conf -RunTest mesh_beacon_multiple_netkeys_1d1 \ - beacon_tx_multiple_netkeys \ - beacon_rx_multiple_netkeys diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_broadcast.sh b/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_broadcast.sh deleted file mode 100755 index 451580ca84c..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_broadcast.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -conf=prj_mesh1d1_conf -RunTest blob_broadcast_basic \ - blob_cli_broadcast_basic - -conf=prj_mesh1d1_conf -RunTest blob_broadcast_trans \ - blob_cli_broadcast_trans - -conf=prj_mesh1d1_conf -RunTest blob_broadcast_unicast_seq \ - blob_cli_broadcast_unicast_seq - -conf=prj_mesh1d1_conf -RunTest blob_broadcast_unicast \ - blob_cli_broadcast_unicast diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_caps.sh b/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_caps.sh deleted file mode 100755 index 07937bc71d9..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_caps.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# The test instance sequence must stay as it is due to addressing scheme -conf=prj_mesh1d1_conf -RunTest blob_caps_all_rsp \ - blob_cli_caps_all_rsp blob_srv_caps_standard blob_srv_caps_standard - -# The test instance sequence must stay as it is due to addressing scheme -conf=prj_mesh1d1_conf -RunTest blob_caps_partial_rsp \ - blob_cli_caps_partial_rsp blob_srv_caps_standard blob_srv_caps_no_rsp - -# The test instance sequence must stay as it is due to addressing scheme -conf=prj_mesh1d1_conf -RunTest blob_caps_no_rsp \ - blob_cli_caps_no_rsp blob_srv_caps_no_rsp blob_srv_caps_no_rsp - -# The test instance seqence must stay as it is due to addressing scheme -conf=prj_mesh1d1_conf -RunTest blob_caps_cancelled \ - blob_cli_caps_cancelled blob_srv_caps_standard diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_no_rsp.sh b/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_no_rsp.sh deleted file mode 100755 index f849cc64b4e..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_no_rsp.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -conf=prj_mesh1d1_conf -RunTest blob_no_rsp_block_get \ - blob_cli_fail_on_no_rsp \ - blob_srv_fail_on_block_get \ - blob_srv_fail_on_block_get -- -argstest msg-fail-type=0 - -conf=prj_mesh1d1_conf -RunTest blob_no_rsp_xfer_get \ - blob_cli_fail_on_no_rsp \ - blob_srv_fail_on_xfer_get \ - blob_srv_fail_on_xfer_get -- -argstest msg-fail-type=1 diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_persistent_transfer.sh b/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_persistent_transfer.sh deleted file mode 100755 index 5801182664e..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_persistent_transfer.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# The test instance sequence must stay as it is due to addressing scheme -conf=prj_mesh1d1_conf -RunTest blob_fail \ - blob_cli_fail_on_persistency \ - blob_srv_fail_on_block_start\ - blob_srv_fail_on_block_get \ - blob_srv_fail_on_xfer_get \ - blob_srv_fail_on_nothing diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_persistent_transfer_pull.sh b/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_persistent_transfer_pull.sh deleted file mode 100755 index 92adfd69959..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_persistent_transfer_pull.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test that BLOB Client continues BLOB Transfer after one target timed out while sending chunks. -conf=prj_mesh1d1_conf -RunTest blob_pst_pull \ - blob_cli_trans_persistency_pull \ - blob_srv_trans_persistency_pull \ - blob_srv_trans_persistency_pull diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_trans_complete_pull.sh b/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_trans_complete_pull.sh deleted file mode 100755 index 7d926d1e4c1..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_trans_complete_pull.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test that BLOB Transfer completes successfully in Pull mode -conf=prj_mesh1d1_conf -RunTest blob_success_pull blob_cli_trans_complete \ - blob_srv_trans_complete blob_srv_trans_complete \ - blob_srv_trans_complete blob_srv_trans_complete \ - -- -argstest use-pull-mode=1 diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_trans_complete_push.sh b/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_trans_complete_push.sh deleted file mode 100755 index e2323f45824..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_trans_complete_push.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test that BLOB Transfer completes successfully in Push mode -conf=prj_mesh1d1_conf -RunTest blob_success_push blob_cli_trans_complete \ - blob_srv_trans_complete blob_srv_trans_complete \ - blob_srv_trans_complete blob_srv_trans_complete diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_trans_resume_pull.sh b/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_trans_resume_pull.sh deleted file mode 100755 index 1df0cd4328e..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_trans_resume_pull.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test that BLOB Client can resume a suspended BLOB Transfer in Pull mode -conf=prj_mesh1d1_conf -RunTest blob_resume_pull blob_cli_trans_resume blob_srv_trans_resume -- -argstest use-pull-mode=1 diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_trans_resume_push.sh b/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_trans_resume_push.sh deleted file mode 100755 index 8de3af64a79..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/blob_mdls/blob_cli_trans_resume_push.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test that BLOB Client can resume a suspended BLOB Transfer in Push mode -conf=prj_mesh1d1_conf -RunTest blob_resume_push blob_cli_trans_resume blob_srv_trans_resume diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_cli_persistent_transfer.sh b/tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_cli_persistent_transfer.sh deleted file mode 100755 index e21298bace8..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_cli_persistent_transfer.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# The test instance sequence must stay as it is due to addressing scheme -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest dfu_persistency \ - dfu_cli_fail_on_persistency \ - dfu_target_fail_on_metadata \ - dfu_target_fail_on_caps_get \ - dfu_target_fail_on_update_get \ - dfu_target_fail_on_verify \ - dfu_target_fail_on_apply \ - dfu_target_fail_on_nothing diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_dist_self_update.sh b/tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_dist_self_update.sh deleted file mode 100755 index c53714ef661..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_dist_self_update.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest dfu_self_update dfu_dist_dfu_self_update -- -argstest targets=1 diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_dist_self_update_mult_targets.sh b/tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_dist_self_update_mult_targets.sh deleted file mode 100755 index f9421b2c004..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_dist_self_update_mult_targets.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest dfu_self_update_no_change \ - dfu_dist_dfu_self_update dfu_target_dfu_no_change -- -argstest targets=2 diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_mixed.sh b/tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_mixed.sh deleted file mode 100755 index 246c73d45ef..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_mixed.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test DFU with all variants of firmware effect -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest dfu_mixed dfu_dist_dfu dfu_target_dfu_unprov dfu_target_dfu_no_change \ - dfu_target_dfu_new_comp_rpr dfu_target_dfu_new_comp_no_rpr -- -argstest targets=4 diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_mixed_fail.sh b/tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_mixed_fail.sh deleted file mode 100755 index c6fe9aa68e4..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/dfu/dfu_mixed_fail.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test that confirm step fails with all variants of firmware effect -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest dfu_mixed_fail dfu_dist_dfu dfu_target_dfu_unprov dfu_target_dfu_no_change \ - dfu_target_dfu_new_comp_rpr dfu_target_dfu_new_comp_no_rpr -- -argstest targets=4 \ - fail-confirm=1 diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/establish.sh b/tests/bluetooth/bsim/mesh/tests_scripts/friendship/establish.sh deleted file mode 100755 index 77d9ba276da..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/establish.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Establish a single friendship, wait for first poll timeout -RunTest mesh_friendship_est \ - friendship_friend_est \ - friendship_lpn_est - -conf=prj_mesh1d1_conf -RunTest mesh_friendship_est_1d1 \ - friendship_friend_est \ - friendship_lpn_est diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/establish_multi.sh b/tests/bluetooth/bsim/mesh/tests_scripts/friendship/establish_multi.sh deleted file mode 100755 index 0241e667c7b..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/establish_multi.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Establish multiple different friendships concurrently. -# Note: The number of LPNs must match CONFIG_BT_MESH_FRIEND_LPN_COUNT. -RunTest mesh_friendship_est_multi \ - friendship_friend_est_multi \ - friendship_lpn_est \ - friendship_lpn_est \ - friendship_lpn_est \ - friendship_lpn_est \ - friendship_lpn_est - -conf=prj_mesh1d1_conf -RunTest mesh_friendship_est_multi_1d1 \ - friendship_friend_est_multi \ - friendship_lpn_est \ - friendship_lpn_est \ - friendship_lpn_est \ - friendship_lpn_est \ - friendship_lpn_est diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/lpn_disable.sh b/tests/bluetooth/bsim/mesh/tests_scripts/friendship/lpn_disable.sh deleted file mode 100755 index 2b1c5fd6395..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/lpn_disable.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Check that disabling LPN gives correct behaviour. -# -# In this test the lpn node will enable the lpn feature, and then immediately -# disables it again. Then we check that that the lpn node is actually in a -# disabled state. This test ensures that a lpn disable call is not overwritten -# by a subsequent lpn enable call, since the enable call is associated with -# internal callback structures that might produce incorrect internal state -# of the LPN module -RunTest mesh_lpn_disable_check \ - friendship_friend_no_est \ - friendship_lpn_disable - -conf=prj_mesh1d1_conf -RunTest mesh_lpn_disable_check_1d1 \ - friendship_friend_no_est \ - friendship_lpn_disable diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/lpn_loopback.sh b/tests/bluetooth/bsim/mesh/tests_scripts/friendship/lpn_loopback.sh deleted file mode 100755 index 4eed9149f32..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/lpn_loopback.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test LPN sending packets to a group and virtual address it subscribes to -RunTest mesh_friendship_lpn_loopback \ - friendship_lpn_loopback \ - friendship_friend_est - -conf=prj_mesh1d1_conf -RunTest mesh_friendship_lpn_loopback_1d1 \ - friendship_lpn_loopback \ - friendship_friend_est diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/lpn_terminate_cb.sh b/tests/bluetooth/bsim/mesh/tests_scripts/friendship/lpn_terminate_cb.sh deleted file mode 100755 index a98d6a7f143..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/lpn_terminate_cb.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Check that the LPN terminate callback does not trigger when there is no established -# connection. -# -# This covers a corner case scenario where the LPN has received a friend offer, but has -# not yet established a connection. In this case the LPN terminate callback should not -# be triggered if the LPN is disabled, which is monitored by this test. -RunTest mesh_lpn_terminate_cb_check \ - friendship_friend_est \ - friendship_lpn_term_cb_check - -conf=prj_mesh1d1_conf -RunTest mesh_lpn_terminate_cb_check_1d1 \ - friendship_friend_est \ - friendship_lpn_term_cb_check diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/msg_frnd.sh b/tests/bluetooth/bsim/mesh/tests_scripts/friendship/msg_frnd.sh deleted file mode 100755 index 1cc636cf7be..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/msg_frnd.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Send messages from the friend to the LPN -RunTest mesh_friendship_msg_frnd \ - friendship_friend_msg \ - friendship_lpn_msg_frnd - -conf=prj_mesh1d1_conf -RunTest mesh_friendship_msg_frnd_1d1 \ - friendship_friend_msg \ - friendship_lpn_msg_frnd diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/msg_group.sh b/tests/bluetooth/bsim/mesh/tests_scripts/friendship/msg_group.sh deleted file mode 100755 index 849345467e8..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/msg_group.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test receives on group and virtual addresses in the LPN -RunTest mesh_friendship_msg_group \ - friendship_lpn_group \ - friendship_other_group \ - friendship_friend_group - -conf=prj_mesh1d1_conf -RunTest mesh_friendship_msg_group_1d1 \ - friendship_lpn_group \ - friendship_other_group \ - friendship_friend_group diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/msg_mesh.sh b/tests/bluetooth/bsim/mesh/tests_scripts/friendship/msg_mesh.sh deleted file mode 100755 index 0276d8e046a..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/msg_mesh.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test communication between the LPN and a third mesh device -RunTest mesh_friendship_msg_mesh \ - friendship_lpn_msg_mesh \ - friendship_other_msg \ - friendship_friend_est - -conf=prj_mesh1d1_conf -RunTest mesh_friendship_msg_mesh_1d1 \ - friendship_lpn_msg_mesh \ - friendship_other_msg \ - friendship_friend_est diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/msg_mesh_low_lat.sh b/tests/bluetooth/bsim/mesh/tests_scripts/friendship/msg_mesh_low_lat.sh deleted file mode 100755 index 5d4c61a5ddd..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/msg_mesh_low_lat.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test communication between the LPN and a third mesh device -overlay=overlay_low_lat_conf -RunTest mesh_friendship_msg_mesh_low_lat \ - friendship_lpn_msg_mesh \ - friendship_other_msg \ - friendship_friend_est - -conf=prj_mesh1d1_conf -overlay=overlay_low_lat_conf -RunTest mesh_friendship_msg_mesh_low_lat_1d1 \ - friendship_lpn_msg_mesh \ - friendship_other_msg \ - friendship_friend_est diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/overflow.sh b/tests/bluetooth/bsim/mesh/tests_scripts/friendship/overflow.sh deleted file mode 100755 index 78027ebf49f..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/overflow.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test friend queue overflow -RunTest mesh_friendship_overflow \ - friendship_friend_overflow \ - friendship_lpn_overflow - -conf=prj_mesh1d1_conf -RunTest mesh_friendship_overflow_1d1 \ - friendship_friend_overflow \ - friendship_lpn_overflow diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/poll.sh b/tests/bluetooth/bsim/mesh/tests_scripts/friendship/poll.sh deleted file mode 100755 index b91a5db9659..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/poll.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test poll timeout -RunTest mesh_friendship_poll \ - friendship_friend_est \ - friendship_lpn_poll - -conf=prj_mesh1d1_conf -RunTest mesh_friendship_poll_1d1 \ - friendship_friend_est \ - friendship_lpn_poll diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/re-establish.sh b/tests/bluetooth/bsim/mesh/tests_scripts/friendship/re-establish.sh deleted file mode 100755 index e0e35ef573d..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/friendship/re-establish.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test friendship re-establishment -RunTest mesh_friendship_re_est \ - friendship_friend_est \ - friendship_lpn_re_est - -conf=prj_mesh1d1_conf -RunTest mesh_friendship_re_est_1d1 \ - friendship_friend_est \ - friendship_lpn_re_est diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/heartbeat/sub_cb_api_all.sh b/tests/bluetooth/bsim/mesh/tests_scripts/heartbeat/sub_cb_api_all.sh deleted file mode 100755 index 0e621188afd..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/heartbeat/sub_cb_api_all.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Run all nodes heartbeat subscription to a device -RunTest mesh_heartbeat_sub_cb_api_all \ - heartbeat_publish_all \ - heartbeat_publish_all \ - heartbeat_subscribe_all - -conf=prj_mesh1d1_conf -RunTest mesh_heartbeat_sub_cb_api_all_1d1 \ - heartbeat_publish_all \ - heartbeat_publish_all \ - heartbeat_subscribe_all diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/heartbeat/sub_cb_api_unicast.sh b/tests/bluetooth/bsim/mesh/tests_scripts/heartbeat/sub_cb_api_unicast.sh deleted file mode 100755 index b08114b4d43..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/heartbeat/sub_cb_api_unicast.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Run unicast heartbeat subscription to a device -RunTest mesh_heartbeat_sub_cb_api_unicast \ - heartbeat_publish_unicast \ - heartbeat_publish_unicast \ - heartbeat_subscribe_unicast - -conf=prj_mesh1d1_conf -RunTest mesh_heartbeat_sub_cb_api_unicast_1d1 \ - heartbeat_publish_unicast \ - heartbeat_publish_unicast \ - heartbeat_subscribe_unicast diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/iv_index/iv_deferring.sh b/tests/bluetooth/bsim/mesh/tests_scripts/iv_index/iv_deferring.sh deleted file mode 100755 index 5d206ab9631..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/iv_index/iv_deferring.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# test deferring of the IV index update procedure -RunTest mesh_ivi_deferring ivi_ivu_deferring - -conf=prj_mesh1d1_conf -RunTest mesh_ivi_deferring_1d1 ivi_ivu_deferring diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/iv_index/iv_recovery.sh b/tests/bluetooth/bsim/mesh/tests_scripts/iv_index/iv_recovery.sh deleted file mode 100755 index bd4121583da..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/iv_index/iv_recovery.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# test IV index recovery procedure -RunTest mesh_ivi_recovery ivi_ivu_recovery - -conf=prj_mesh1d1_conf -RunTest mesh_ivi_recovery_1d1 ivi_ivu_recovery diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/iv_index/iv_update.sh b/tests/bluetooth/bsim/mesh/tests_scripts/iv_index/iv_update.sh deleted file mode 100755 index 931888479b9..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/iv_index/iv_update.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# test IV index update procedure -RunTest mesh_ivi_update ivi_ivu_normal - -conf=prj_mesh1d1_conf -RunTest mesh_ivi_update_1d1 ivi_ivu_normal diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/large_comp_data/get_comp_data_max_sdu.sh b/tests/bluetooth/bsim/mesh/tests_scripts/large_comp_data/get_comp_data_max_sdu.sh deleted file mode 100755 index a5b55e5ef6d..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/large_comp_data/get_comp_data_max_sdu.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2023 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test that the large composition data (LCD) server model is able to transmit -# access messages with a total size of 380-bytes (including opcode). -# -# Test procedure: -# 0. Provisioning and setup. Server and client has same comp data. -# 1. Client requests a max SDU from server's composition data. -# 2. Client fetch its local comp data. -# 3. When server status arrive, remove status field data and compare received -# comp data with local comp data and assure that the received message length -# is 378 bytes (380 bytes access payload). -conf=prj_mesh1d1_conf -RunTest mesh_lcd_test_max_access_payload \ - lcd_cli_max_sdu_comp_data_request lcd_srv_comp_data_status_respond diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/large_comp_data/get_comp_data_split.sh b/tests/bluetooth/bsim/mesh/tests_scripts/large_comp_data/get_comp_data_split.sh deleted file mode 100755 index 8c938d1047f..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/large_comp_data/get_comp_data_split.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2023 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test that the LCD server model is able to split the -# composition data when the total size exceeds the maximum access message size. -# -# Test procedure: -# 0. Provisioning and setup. Server and client has same comp data. -# 1. Client requests a sample exceeding the maximum avaialble payload from the -# server's composition data. -# 2. Client fetch its local comp data. -# 3. When server status arrive, remove status field data and compare received -# comp data with corresponding bytes in local comp data. -# 4. Client requests the next sample from server's composition data. -# 5. When server status arrive, remove status field data and compare received -# comp data with correspending bytes in local comp data. -# 6. Client merges the two samples and checks that the collected data is -# correctly merged, continuous, and matches its local comp data. -conf=prj_mesh1d1_conf -RunTest mesh_lcd_test_split_comp_data \ - lcd_cli_split_comp_data_request lcd_srv_comp_data_status_respond diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/large_comp_data/get_metadata_max_sdu.sh b/tests/bluetooth/bsim/mesh/tests_scripts/large_comp_data/get_metadata_max_sdu.sh deleted file mode 100755 index 3b6e90cfd9c..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/large_comp_data/get_metadata_max_sdu.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2023 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test that the large composition data (LCD) server model is able to transmit -# access messages with a total size of 380-bytes (including opcode). -# -# Test procedure: -# 0. Provisioning and setup. Server and client has same comp data. -# 1. Client requests a max SDU metadata status message from server. -# 2. Client fetch its local metadata. -# 3. When server status arrive, assure that the received message length -# is 378 bytes (380 bytes access payload). -# 4. Remove status field data and compare received metadata with -# local metadata data. -conf=prj_mesh1d1_conf -RunTest mesh_lcd_test_max_metadata_access_payload \ - lcd_cli_max_sdu_metadata_request lcd_srv_metadata_status_respond diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/large_comp_data/get_metadata_split.sh b/tests/bluetooth/bsim/mesh/tests_scripts/large_comp_data/get_metadata_split.sh deleted file mode 100755 index 9e8dfc1457c..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/large_comp_data/get_metadata_split.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2023 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test that the the LCD server model is able to split the -# metadata when the total size exceeds the maximum access message size. -# -# Test procedure: -# 0. Provisioning and setup. Server and client has same comp data. -# 1. Client requests the first X bytes from server's metadata. -# 2. Client fetches its local metadata. -# 3. When the server status arrive, remove status field data and compare -# received metadata with corresponding bytes in local data. -# 4. Client requests the next X bytes from server's metadata. -# 5. When the server status arrive, remove status field data and compare -# received metadata with corresponding bytes in local data. -# 6. Client merges the two samples and checks that the collected data is -# correctly merged, continuous, and matches its local metadata. -conf=prj_mesh1d1_conf -RunTest mesh_lcd_test_split_metadata \ - lcd_cli_split_metadata_request lcd_srv_metadata_status_respond diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/op_agg/full_status_msg_list.sh b/tests/bluetooth/bsim/mesh/tests_scripts/op_agg/full_status_msg_list.sh deleted file mode 100755 index ac1f92f1244..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/op_agg/full_status_msg_list.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test that the OPcode aggregator (op agg) SIG model is able to send and receive a 380-byte -# access payload message and that the status item messages are received in the correct order. -# Spec 3.7.2: "With a 32-bit TransMIC field, the maximum size of the Access message is 380 octets." -# Spec 4.4.19.2: "When an Access message or an empty item is added to the message results list, -# it shall be located at the same index as the corresponding Access message from -# the message request list." - -# Test procedure: -# 1. Initialize and configure op agg client and server instances. -# 2. The client configures op agg context. -# 3. The client sends X vendor model messages, making up an op agg sequence message of 380 bytes. -# 4. The client sends the sequence message with the previously configured context, -# expecting an op agg status message of 380 bytes in return. -# 5. The server keeps track of the number of received messages and pass when X messages have been -# received. -# 6. The client keeps track of the number of received status messages. When X messages have been -# received, the client pass if the sequence of received status messages corresponds to the order -# in which the messages were sent, or the test fails. -conf=prj_mesh1d1_conf -RunTest mesh_op_agg_test_max_access_payload \ - op_agg_cli_max_len_sequence_msg_send op_agg_srv_max_len_status_msg_send diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/persistence/access.sh b/tests/bluetooth/bsim/mesh/tests_scripts/persistence/access.sh deleted file mode 100755 index a3860a35367..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/persistence/access.sh +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Note: -# Tests must be added in pairs and in sequence. -# First test: saves data; second test: verifies it. - -overlay=overlay_pst_conf -RunTest mesh_pst_access_data_check persistence_access_data_save - -overlay=overlay_pst_conf -RunTest mesh_pst_access_data_check persistence_access_data_load --\ - -argstest access-cfg=configured - -overlay=overlay_pst_conf -RunTest mesh_pst_access_data_check persistence_access_sub_overwrite --\ - -argstest access-cfg=configured - -overlay=overlay_pst_conf -RunTest mesh_pst_access_data_check persistence_access_data_load --\ - -argstest access-cfg=new-subs - -overlay=overlay_pst_conf -RunTest mesh_pst_access_data_check persistence_access_data_remove --\ - -argstest access-cfg=new-subs - -overlay=overlay_pst_conf -RunTest mesh_pst_access_data_check persistence_access_data_load --\ - -argstest access-cfg=not-configured - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest mesh_pst_access_data_check_1d1 persistence_access_data_save - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest mesh_pst_access_data_check_1d1 persistence_access_data_load --\ - -argstest access-cfg=configured - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest mesh_pst_access_data_check_1d1 persistence_access_sub_overwrite --\ - -argstest access-cfg=configured - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest mesh_pst_access_data_check_1d1 persistence_access_data_load --\ - -argstest access-cfg=new-subs - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest mesh_pst_access_data_check_1d1 persistence_access_data_remove --\ - -argstest access-cfg=new-subs - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest mesh_pst_access_data_check_1d1 persistence_access_data_load --\ - -argstest access-cfg=not-configured diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/persistence/cfg.sh b/tests/bluetooth/bsim/mesh/tests_scripts/persistence/cfg.sh deleted file mode 100755 index 641c4c086d7..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/persistence/cfg.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Note: -# Tests must be added in pairs and in sequence. -# First test: saves data; second test: verifies it. - -overlay=overlay_pst_conf -RunTest mesh_pst_cfg_check persistence_cfg_save -- -argstest stack-cfg=0 - -overlay=overlay_pst_conf -RunTest mesh_pst_cfg_check persistence_cfg_load -- -argstest stack-cfg=0 - -overlay=overlay_pst_conf -RunTest mesh_pst_cfg_check persistence_cfg_save -- -argstest stack-cfg=1 - -overlay=overlay_pst_conf -RunTest mesh_pst_cfg_check persistence_cfg_load -- -argstest stack-cfg=1 - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest mesh_pst_cfg_check_1d1 persistence_cfg_save -- -argstest stack-cfg=0 - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest mesh_pst_cfg_check_1d1 persistence_cfg_load -- -argstest stack-cfg=0 - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest mesh_pst_cfg_check_1d1 persistence_cfg_save -- -argstest stack-cfg=1 - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest mesh_pst_cfg_check_1d1 persistence_cfg_load -- -argstest stack-cfg=1 diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/persistence/provisioning.sh b/tests/bluetooth/bsim/mesh/tests_scripts/persistence/provisioning.sh deleted file mode 100755 index 4ee4e2367cb..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/persistence/provisioning.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Note: -# Tests must be added in pairs and in sequence. -# First test: saves data; second test: verifies it. - -# SKIP=(persistence_provisioning_data_save) -overlay=overlay_pst_conf -RunTest mesh_pst_prov_data_check persistence_provisioning_data_save - -# SKIP=(persistence_provisioning_data_load) -overlay=overlay_pst_conf -RunTest mesh_pst_prov_data_check persistence_provisioning_data_load - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest mesh_pst_prov_data_check_1d1 persistence_provisioning_data_save - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest mesh_pst_prov_data_check_1d1 persistence_provisioning_data_load diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/persistence/reprovisioning.sh b/tests/bluetooth/bsim/mesh/tests_scripts/persistence/reprovisioning.sh deleted file mode 100755 index 2e294cc2926..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/persistence/reprovisioning.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Note: -# Tests must be added in pairs and in sequence. -# First test: saves data; second test: verifies it. - -# Provision, configure and reset a device -overlay=overlay_pst_conf -RunTest mesh_pst_repr persistence_reprovisioning_device \ - persistence_reprovisioning_provisioner -- -argstest clear-settings=1 - -# Repeat the test -overlay=overlay_pst_conf -RunTest mesh_pst_repr persistence_reprovisioning_device \ - persistence_reprovisioning_provisioner - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest mesh_pst_repr_1d1 persistence_reprovisioning_device \ - persistence_reprovisioning_provisioner -- -argstest clear-settings=1 - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest mesh_pst_repr_1d1 persistence_reprovisioning_device \ - persistence_reprovisioning_provisioner diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/provision/iv_update_flag.sh b/tests/bluetooth/bsim/mesh/tests_scripts/provision/iv_update_flag.sh deleted file mode 100755 index 855a12e3e39..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/provision/iv_update_flag.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Lingao Meng -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -RunTest mesh_provision_iv_update_zero_duration prov_provisioner_iv_update_flag_zero - -RunTest mesh_provision_iv_update_one_duration prov_provisioner_iv_update_flag_one diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/provision/ivu_flag_one_duration.sh b/tests/bluetooth/bsim/mesh/tests_scripts/provision/ivu_flag_one_duration.sh deleted file mode 100755 index 1fd78fd21b6..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/provision/ivu_flag_one_duration.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Lingao Meng -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -RunTest mesh_prov_iv_update_one_duration prov_provisioner_iv_update_flag_one - -conf=prj_mesh1d1_conf -RunTest mesh_prov_iv_update_one_duration_1d1 prov_provisioner_iv_update_flag_one diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/provision/ivu_flag_zero_duration.sh b/tests/bluetooth/bsim/mesh/tests_scripts/provision/ivu_flag_zero_duration.sh deleted file mode 100755 index b9f10d09ce6..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/provision/ivu_flag_zero_duration.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Lingao Meng -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -RunTest mesh_prov_iv_update_zero_duration prov_provisioner_iv_update_flag_zero - -conf=prj_mesh1d1_conf -RunTest mesh_prov_iv_update_zero_duration_1d1 prov_provisioner_iv_update_flag_zero diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_multi.sh b/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_multi.sh deleted file mode 100755 index fc504016b1a..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_multi.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Provision 3 devices in succession: -# Note that the number of devices must match the -# PROV_MULTI_COUNT define in test_provision.c -RunTest mesh_prov_pb_adv_multi \ - prov_provisioner_pb_adv_multi \ - prov_device_pb_adv_no_oob \ - prov_device_pb_adv_no_oob \ - prov_device_pb_adv_no_oob - -conf=prj_mesh1d1_conf -RunTest mesh_prov_pb_adv_multi_1d1 \ - prov_provisioner_pb_adv_multi \ - prov_device_pb_adv_no_oob \ - prov_device_pb_adv_no_oob \ - prov_device_pb_adv_no_oob diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_no_oob.sh b/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_no_oob.sh deleted file mode 100755 index 893f9dfb589..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_no_oob.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Lingao Meng -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -RunTest mesh_prov_pb_adv_on_oob \ - prov_device_pb_adv_no_oob \ - prov_provisioner_pb_adv_no_oob - -conf=prj_mesh1d1_conf -RunTest mesh_prov_pb_adv_on_oob_1d1 \ - prov_device_pb_adv_no_oob \ - prov_provisioner_pb_adv_no_oob diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_oob_auth_ib_pk.sh b/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_oob_auth_ib_pk.sh deleted file mode 100755 index 1d66b6615d0..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_oob_auth_ib_pk.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -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_pb_adv_oob_auth prov_provisioner_pb_adv_oob_auth - -conf=prj_mesh1d1_conf -RunTest mesh_prov_pb_adv_oob_auth_1d1 \ - prov_device_pb_adv_oob_auth prov_provisioner_pb_adv_oob_auth diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_oob_auth_ignore_oob_pk.sh b/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_oob_auth_ignore_oob_pk.sh deleted file mode 100755 index 782794281ba..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_oob_auth_ignore_oob_pk.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test provisioning with OOB authentication, with device OOB public key -# but provisioner doesn't have OOB public key -RunTest mesh_prov_pb_adv_device_w_oob_pk_prvnr_wt_pk \ - prov_device_pb_adv_oob_public_key prov_provisioner_pb_adv_oob_auth_no_oob_public_key - -conf=prj_mesh1d1_conf -RunTest mesh_prov_pb_adv_device_w_oob_pk_prvnr_wt_pk_1d1 \ - prov_device_pb_adv_oob_public_key prov_provisioner_pb_adv_oob_auth_no_oob_public_key diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_oob_auth_oob_pk.sh b/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_oob_auth_oob_pk.sh deleted file mode 100755 index 2dcae7fb9ee..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_oob_auth_oob_pk.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -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_pb_adv_oob_public_key prov_provisioner_pb_adv_oob_public_key - -conf=prj_mesh1d1_conf -RunTest mesh_prov_pb_adv_oob_public_key_1d1 \ - prov_device_pb_adv_oob_public_key prov_provisioner_pb_adv_oob_public_key diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_reprovision.sh b/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_reprovision.sh deleted file mode 100755 index 193bd34a28c..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_adv_reprovision.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -RunTest mesh_prov_pb_adv_repr \ - prov_device_pb_adv_reprovision \ - prov_provisioner_pb_adv_reprovision - -conf=prj_mesh1d1_conf -RunTest mesh_prov_pb_adv_repr_1d1 \ - prov_device_pb_adv_reprovision \ - prov_provisioner_pb_adv_reprovision diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_remote_nppi_robustness.sh b/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_remote_nppi_robustness.sh deleted file mode 100755 index 52ca990fd97..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_remote_nppi_robustness.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test robustness of NPPI procedures by running them multiple times each. Test procedure: -# 1. Provisioner provisions the second device (prov_device_pb_remote_server) with RPR server through -# PB-Adv -# 2. RPR client starts to scan for the third device (prov_device_pb_remote_server_nppi_robustness) -# through RPR (5 second timeout) and provisions it -# 3. Execute device key refresh procedure 3 times for the third device. -# 4. Execute composition refresh procedure 3 times for the third device. -# 5. Execute address refresh procedure 3 times for the third device. -# (Step 3-5 is executed without sending a node reset message) -conf=prj_mesh1d1_conf -RunTest mesh_prov_pb_remote_nppi_robustness \ - prov_provisioner_pb_remote_client_nppi_robustness \ - prov_device_pb_remote_server_unproved \ - prov_device_pb_remote_server_nppi_robustness diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_remote_pst_ncrp.sh b/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_remote_pst_ncrp.sh deleted file mode 100755 index 9f73a6ed4e9..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_remote_pst_ncrp.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test Node Composition Refresh procedure with persistence storage: -# 1. Prepare for Composition Data change. -# PB-Remote client (1st device): -# - provision the 2nd device over PB-Adv -# - provision the 3rd device over PB-Remote -# PB-Remote server (2nd device): -# - wait for being provisioned -# - run PB-Remote bearer -# PB-Remote server (3rd device): -# - wait for being provisioned -# - call bt_mesh_comp_change_prepare() to prepare for Composition Data change -# 2. Verify Node Composition Refresh procedure. -# PB-Remote client (1st device): -# - check that Composition Data pages 0 (old comp data) and 128 (new comp data) are different -# - run Node Composition Refresh procedure on the 3rd device -# - verify Composition Data pages 0 (new comp data) and 128 (same as page 0) -# PB-Remote server (3rd device): -# - start with a new Composition Data -# 3. Verify that old settings are removed on the 3rd device after Composition Data change. -# PB-Remote client (1st device): -# - run Node Composition Refresh procedure again and expect it to fail -# PB-Remote server (3rd device): -# - verify that the device is not re-provisioned again. - -# Step 1 -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest mesh_prov_pst_pb_remote_ncrp \ - prov_provisioner_pb_remote_client_ncrp_provision \ - prov_device_pb_remote_server_unproved \ - prov_device_pb_remote_server_ncrp_prepare - -# Step 2 -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest mesh_prov_pst_pb_remote_ncrp \ - prov_provisioner_pb_remote_client_ncrp \ - prov_device_pb_remote_server_proved \ - prov_device_pb_remote_server_ncrp - -# Step 3 -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest mesh_prov_pst_pb_remote_ncrp \ - prov_provisioner_pb_remote_client_ncrp_second_time \ - prov_device_pb_remote_server_proved \ - prov_device_pb_remote_server_ncrp_second_time diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_remote_reprovision.sh b/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_remote_reprovision.sh deleted file mode 100755 index c4f1d8a167f..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/provision/pb_remote_reprovision.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test a node re-provisioning through Remote Provisioning models. Procedure: -# 1. A provisioner with the RPR client provisions itself; -# 2. The provisioner provisions a device with the RPR server; -# 3. The provisioner starts scanning for an unprovisioned device through the node with RPR server; -# 4. The provisioner finds an unprovisioned device and provisions it; -# 5. The provisioner configures the health server on the recently provisioned device and sends Node -# Reset; -# 6. Repeat steps 3-5 multiple times. -conf=prj_mesh1d1_conf -RunTest mesh_prov_pb_remote_reprovision \ - prov_provisioner_pb_remote_client_reprovision \ - prov_device_pb_remote_server_unproved \ - prov_device_pb_adv_reprovision diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/replay_cache/replay_attack.sh b/tests/bluetooth/bsim/mesh/tests_scripts/replay_cache/replay_attack.sh deleted file mode 100755 index 2ca843e4b3a..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/replay_cache/replay_attack.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -overlay=overlay_pst_conf -RunTest mesh_replay_attack \ - rpc_tx_immediate_replay_attack \ - rpc_rx_immediate_replay_attack - -overlay=overlay_pst_conf -RunTest mesh_replay_attack \ - rpc_tx_power_replay_attack \ - rpc_rx_power_replay_attack - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest mesh_replay_attack_1d1 \ - rpc_tx_immediate_replay_attack \ - rpc_rx_immediate_replay_attack - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest mesh_replay_attack_1d1 \ - rpc_tx_power_replay_attack \ - rpc_rx_power_replay_attack diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/replay_cache/rpl_frag.sh b/tests/bluetooth/bsim/mesh/tests_scripts/replay_cache/rpl_frag.sh deleted file mode 100755 index 3618e8ac778..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/replay_cache/rpl_frag.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test fragmentation of RPL: -# 1. Send a message from 3 different consecutive nodes starting from address 100; -# 2. Toggle IV index update; -# 3. Send a new message from even addresses. This should update IVI index of RPL for these nodes. -# The RPL entry odd address should stay unchanged; -# 4. Complete IVI Update; -# 5. Repeate steps 2 - 4 to remove RPL entry with odd address from RPL and cause fragmentation; -overlay=overlay_pst_conf -RunTest mesh_replay_fragmentation rpc_rx_rpl_frag rpc_tx_rpl_frag - -# Simulate reboot and test that RPL entries are restored correctly after defragmentation -overlay=overlay_pst_conf -RunTest mesh_replay_fragmentation rpc_rx_reboot_after_defrag - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest mesh_replay_fragmentation_1d1 rpc_rx_rpl_frag rpc_tx_rpl_frag - -conf=prj_mesh1d1_conf -overlay=overlay_pst_conf -RunTest mesh_replay_fragmentation_1d1 rpc_rx_reboot_after_defrag diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/sar/slow_transfer_test.sh b/tests/bluetooth/bsim/mesh/tests_scripts/sar/slow_transfer_test.sh deleted file mode 100755 index 47ee7205455..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/sar/slow_transfer_test.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2023 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test that a maximum length SDU can be processed with SAR, -# even with transmitter and receiver configured with longest possible -# intervals and default retransmission counts. -# Test procedure: -# 1. Initialize Client and Server instances. -# 2. Bind "dummy" vendor model to both instances. -# 3. Configure SAR transmitter and receiver states. -# 4. The Client sends a Get-message with a maximum length SDU, targeting the server. -# 5. The Server responds with a maximum length SDU Status-message. -# 6. The test passes when the Client successfully receives the Status response. -conf=prj_mesh1d1_conf -RunTest sar_slow_test \ - sar_cli_max_len_sdu_slow_send sar_srv_max_len_sdu_slow_receive diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/sar/stress_test.sh b/tests/bluetooth/bsim/mesh/tests_scripts/sar/stress_test.sh deleted file mode 100755 index 685661777ed..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/sar/stress_test.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -# Test that a maximum length SDU can be processed with SAR, -# even with "stressed" transmitter and receiver configurations. -# Test procedure: -# 1. Initialize Client and Server instances. -# 2. Bind "dummy" vendor model to both instances. -# 3. Configure SAR transmitter and receiver states. -# 4. The Client sends a Get-message with a maximum length SDU, targeting the server. -# 5. The Server responds with a maximum length SDU Status-message. -# 6. The test passes when the Client successfully receives the Status response. -conf=prj_mesh1d1_conf -RunTest sar_test \ - sar_cli_max_len_sdu_send sar_srv_max_len_sdu_receive diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/scanner/invalid_ad_type.sh b/tests/bluetooth/bsim/mesh/tests_scripts/scanner/invalid_ad_type.sh deleted file mode 100755 index 6f88c9d8261..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/scanner/invalid_ad_type.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -RunTest mesh_scanner_invalid_ad_type \ - scanner_tx_invalid_ad_type \ - scanner_rx_invalid_packet - -conf=prj_mesh1d1_conf -RunTest mesh_scanner_invalid_ad_type_1d1 \ - scanner_tx_invalid_ad_type \ - scanner_rx_invalid_packet diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/scanner/wrong_packet_length.sh b/tests/bluetooth/bsim/mesh/tests_scripts/scanner/wrong_packet_length.sh deleted file mode 100755 index 1bcf8b73f12..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/scanner/wrong_packet_length.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -RunTest mesh_scanner_wrong_packet_length \ - scanner_tx_wrong_packet_length \ - scanner_rx_invalid_packet - -conf=prj_mesh1d1_conf -RunTest mesh_scanner_wrong_packet_length_1d1 \ - scanner_tx_wrong_packet_length \ - scanner_rx_invalid_packet diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/transport/group.sh b/tests/bluetooth/bsim/mesh/tests_scripts/transport/group.sh deleted file mode 100755 index d407eaaa5c7..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/transport/group.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -RunTest mesh_transport_group transport_tx_group transport_rx_group - -conf=prj_mesh1d1_conf -RunTest mesh_transport_group_1d1 transport_tx_group transport_rx_group diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/transport/loopback.sh b/tests/bluetooth/bsim/mesh/tests_scripts/transport/loopback.sh deleted file mode 100755 index 3ea550574e6..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/transport/loopback.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -RunTest transport_loopback transport_tx_loopback transport_rx_none - -conf=prj_mesh1d1_conf -RunTest transport_loopback_1d1 transport_tx_loopback transport_rx_none diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/transport/loopback_group.sh b/tests/bluetooth/bsim/mesh/tests_scripts/transport/loopback_group.sh deleted file mode 100755 index 270139d83ea..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/transport/loopback_group.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -RunTest mesh_transport_loopback_group transport_tx_loopback_group transport_rx_group - -conf=prj_mesh1d1_conf -RunTest mesh_transport_loopback_group_1d1 transport_tx_loopback_group transport_rx_group diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/transport/loopback_group_low_lat.sh b/tests/bluetooth/bsim/mesh/tests_scripts/transport/loopback_group_low_lat.sh deleted file mode 100755 index 777470fed71..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/transport/loopback_group_low_lat.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -overlay=overlay_low_lat_conf -RunTest mesh_transport_loopback_group_low_lat transport_tx_loopback_group transport_rx_group - -conf=prj_mesh1d1_conf -overlay=overlay_low_lat_conf -RunTest mesh_transport_loopback_group_low_lat_1d1 transport_tx_loopback_group transport_rx_group diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/transport/seg_block.sh b/tests/bluetooth/bsim/mesh/tests_scripts/transport/seg_block.sh deleted file mode 100755 index 7db73841720..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/transport/seg_block.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -RunTest mesh_transport_seg_block transport_tx_seg_block transport_rx_seg_block - -conf=prj_mesh1d1_conf -RunTest mesh_transport_seg_block_1d1 transport_tx_seg_block transport_rx_seg_block diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/transport/seg_concurrent.sh b/tests/bluetooth/bsim/mesh/tests_scripts/transport/seg_concurrent.sh deleted file mode 100755 index 81b1e571b17..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/transport/seg_concurrent.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -RunTest mesh_transport_seg_concurrent transport_tx_seg_concurrent transport_rx_seg_concurrent - -conf=prj_mesh1d1_conf -RunTest mesh_transport_seg_concurrent_1d1 transport_tx_seg_concurrent transport_rx_seg_concurrent diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/transport/seg_fail.sh b/tests/bluetooth/bsim/mesh/tests_scripts/transport/seg_fail.sh deleted file mode 100755 index 8a1816b1ec5..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/transport/seg_fail.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -RunTest mesh_transport_seg_fail transport_tx_seg_fail - -conf=prj_mesh1d1_conf -RunTest mesh_transport_seg_fail_1d1 transport_tx_seg_fail diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/transport/seg_ivu.sh b/tests/bluetooth/bsim/mesh/tests_scripts/transport/seg_ivu.sh deleted file mode 100755 index 0fe822d40cf..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/transport/seg_ivu.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -RunTest mesh_transport_seg_ivu transport_tx_seg_ivu transport_rx_seg_ivu - -conf=prj_mesh1d1_conf -RunTest mesh_transport_seg_ivu_1d1 transport_tx_seg_ivu transport_rx_seg_ivu diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/transport/unicast.sh b/tests/bluetooth/bsim/mesh/tests_scripts/transport/unicast.sh deleted file mode 100755 index 4f7c33d81a8..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/transport/unicast.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -RunTest mesh_transport_unicast transport_tx_unicast transport_rx_unicast - -conf=prj_mesh1d1_conf -RunTest mesh_transport_unicast_1d1 transport_tx_unicast transport_rx_unicast diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/transport/unicast_low_lat.sh b/tests/bluetooth/bsim/mesh/tests_scripts/transport/unicast_low_lat.sh deleted file mode 100755 index ab61e1df2f1..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/transport/unicast_low_lat.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -overlay=overlay_low_lat_conf -RunTest mesh_transport_unicast_low_lat transport_tx_unicast transport_rx_unicast - -conf=prj_mesh1d1_conf -overlay=overlay_low_lat_conf -RunTest mesh_transport_unicast_low_lat_1d1 transport_tx_unicast transport_rx_unicast diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/transport/unknown_app.sh b/tests/bluetooth/bsim/mesh/tests_scripts/transport/unknown_app.sh deleted file mode 100755 index 03ff31e290a..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/transport/unknown_app.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -RunTest mesh_transport_unknown_app transport_tx_unknown_app transport_rx_none - -conf=prj_mesh1d1_conf -RunTest mesh_transport_unknown_app_1d1 transport_tx_unknown_app transport_rx_none diff --git a/tests/bluetooth/bsim/mesh/tests_scripts/transport/va.sh b/tests/bluetooth/bsim/mesh/tests_scripts/transport/va.sh deleted file mode 100755 index 6dd9e3ba85a..00000000000 --- a/tests/bluetooth/bsim/mesh/tests_scripts/transport/va.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2021 Nordic Semiconductor -# SPDX-License-Identifier: Apache-2.0 - -source $(dirname "${BASH_SOURCE[0]}")/../../_mesh_test.sh - -RunTest mesh_transport_va transport_tx_va transport_rx_va - -conf=prj_mesh1d1_conf -RunTest mesh_transport_va_1d1 transport_tx_va transport_rx_va diff --git a/tests/bluetooth/bsim/run_parallel.sh b/tests/bluetooth/bsim/run_parallel.sh deleted file mode 100755 index 05872d8e0f5..00000000000 --- a/tests/bluetooth/bsim/run_parallel.sh +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2018 Oticon A/S -# SPDX-License-Identifier: Apache-2.0 - -# Syntax run_parallel.sh [-h] [options] - -set -u - -start=$SECONDS - -function display_help(){ - echo "run_parallel.sh [-help] [options]" - echo " Execute all cases which do not start with an _ (underscore)" - echo " [options] will be passed directly to the scripts" - echo " The results will be saved to \${RESULTS_FILE}, by default" - echo " ../RunResults.xml" - echo " Testcases are searched for in \${SEARCH_PATH}, by default this folder" -} - -# Parse command line -if [ $# -ge 1 ]; then - if grep -Eiq "(\?|-\?|-h|help|-help|--help)" <<< $1 ; then - display_help - exit 0 - fi -fi - -err=0 -i=0 - -SEARCH_PATH="${SEARCH_PATH:-.}" - -#All the testcases we want to run: -all_cases=`find ${SEARCH_PATH} -name "*.sh" | \ - grep -Ev "(/_|run_parallel|compile.sh)"` -#we dont run ourselves - -RESULTS_FILE="${RESULTS_FILE:-`pwd`/../RunResults.xml}" -tmp_res_file=tmp.xml - -all_cases_a=( $all_cases ) -n_cases=$((${#all_cases_a[@]})) -touch ${RESULTS_FILE} -echo "Attempting to run ${n_cases} cases (logging to \ - `realpath ${RESULTS_FILE}`)" - -chmod +x $all_cases - -export CLEAN_XML="sed -E -e 's/&/\&/g' -e 's//\>/g' \ - -e 's/\"/"/g'" - -echo -n "" > $tmp_res_file - -if [ `command -v parallel` ]; then - parallel ' - echo "" - {} $@ &> {#}.log - if [ $? -ne 0 ]; then - (>&2 echo -e "\e[91m{} FAILED\e[39m") - (>&2 cat {#}.log) - echo "" - cat {#}.log | eval $CLEAN_XML - echo "" - rm {#}.log - echo "" - exit 1 - else - (>&2 echo -e "{} PASSED") - rm {#}.log - echo "" - fi - ' ::: $all_cases >> $tmp_res_file ; err=$? -else #fallback in case parallel is not installed - for case in $all_cases; do - echo "" >> $tmp_res_file - $case $@ &> $i.log - if [ $? -ne 0 ]; then - echo -e "\e[91m$case FAILED\e[39m" - cat $i.log - echo "" >> $tmp_res_file - cat $i.log | eval $CLEAN_XML >> $tmp_res_file - echo "" >> $tmp_res_file - let "err++" - else - echo -e "$case PASSED" - fi - echo "" >> $tmp_res_file - rm $i.log - let i=i+1 - done -fi -echo -e "\n\n" >> $tmp_res_file -dur=$(($SECONDS - $start)) -echo -e "\n" \ - | cat - $tmp_res_file > $RESULTS_FILE -rm $tmp_res_file - -exit $err diff --git a/tests/bluetooth/bsim/sh_common.source b/tests/bluetooth/bsim/sh_common.source deleted file mode 100644 index 25c59d3f3c5..00000000000 --- a/tests/bluetooth/bsim/sh_common.source +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright 2023 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -_process_ids=""; - -function run_in_background(){ - $@ & _process_ids="$_process_ids $!" -} - -function wait_for_background_jobs(){ - exit_code=0 - for process_id in $_process_ids; do - wait $process_id || let "exit_code=$?" - done - exit $exit_code #the last exit code != 0 -} diff --git a/tests/drivers/counter/counter_basic_api/boards/esp32.conf b/tests/drivers/counter/counter_basic_api/boards/esp32.conf deleted file mode 100644 index bb1f1de1e69..00000000000 --- a/tests/drivers/counter/counter_basic_api/boards/esp32.conf +++ /dev/null @@ -1 +0,0 @@ -CONFIG_COUNTER_TMR_ESP32=y diff --git a/tests/drivers/counter/counter_basic_api/boards/nrf51dk_nrf51422.conf b/tests/drivers/counter/counter_basic_api/boards/nrf51dk_nrf51422.conf deleted file mode 100644 index 25d7ba83ed0..00000000000 --- a/tests/drivers/counter/counter_basic_api/boards/nrf51dk_nrf51422.conf +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG_COUNTER_TIMER0=y -CONFIG_COUNTER_TIMER1=y -CONFIG_COUNTER_TIMER2=y -CONFIG_COUNTER_RTC0=y diff --git a/tests/drivers/counter/counter_basic_api/boards/nrf52833dk_nrf52833.conf b/tests/drivers/counter/counter_basic_api/boards/nrf52833dk_nrf52833.conf deleted file mode 100644 index bd6b714b18a..00000000000 --- a/tests/drivers/counter/counter_basic_api/boards/nrf52833dk_nrf52833.conf +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG_COUNTER_TIMER0=y -CONFIG_COUNTER_TIMER1=y -CONFIG_COUNTER_TIMER2=y -CONFIG_COUNTER_TIMER3=y -CONFIG_COUNTER_TIMER4=y -CONFIG_COUNTER_RTC0=y -CONFIG_COUNTER_RTC2=y diff --git a/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52811.conf b/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52811.conf deleted file mode 100644 index 25d7ba83ed0..00000000000 --- a/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52811.conf +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG_COUNTER_TIMER0=y -CONFIG_COUNTER_TIMER1=y -CONFIG_COUNTER_TIMER2=y -CONFIG_COUNTER_RTC0=y diff --git a/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52840.conf b/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52840.conf deleted file mode 100644 index bd6b714b18a..00000000000 --- a/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52840.conf +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG_COUNTER_TIMER0=y -CONFIG_COUNTER_TIMER1=y -CONFIG_COUNTER_TIMER2=y -CONFIG_COUNTER_TIMER3=y -CONFIG_COUNTER_TIMER4=y -CONFIG_COUNTER_RTC0=y -CONFIG_COUNTER_RTC2=y diff --git a/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52840_zli.conf b/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52840_zli.conf deleted file mode 100644 index 39ddf4af3a2..00000000000 --- a/tests/drivers/counter/counter_basic_api/boards/nrf52840dk_nrf52840_zli.conf +++ /dev/null @@ -1,14 +0,0 @@ -CONFIG_COUNTER_TIMER0=y -CONFIG_COUNTER_TIMER0_ZLI=y -CONFIG_COUNTER_TIMER1=y -CONFIG_COUNTER_TIMER1_ZLI=y -CONFIG_COUNTER_TIMER2=y -CONFIG_COUNTER_TIMER2_ZLI=y -CONFIG_COUNTER_TIMER3=y -CONFIG_COUNTER_TIMER3_ZLI=y -CONFIG_COUNTER_TIMER4=y -CONFIG_COUNTER_TIMER4_ZLI=y -CONFIG_COUNTER_RTC0=y -CONFIG_COUNTER_RTC0_ZLI=y -CONFIG_COUNTER_RTC2=y -CONFIG_COUNTER_RTC2_ZLI=y diff --git a/tests/drivers/counter/counter_basic_api/boards/nrf52dk_nrf52810.conf b/tests/drivers/counter/counter_basic_api/boards/nrf52dk_nrf52810.conf deleted file mode 100644 index 25d7ba83ed0..00000000000 --- a/tests/drivers/counter/counter_basic_api/boards/nrf52dk_nrf52810.conf +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG_COUNTER_TIMER0=y -CONFIG_COUNTER_TIMER1=y -CONFIG_COUNTER_TIMER2=y -CONFIG_COUNTER_RTC0=y diff --git a/tests/drivers/counter/counter_basic_api/boards/nrf52dk_nrf52832.conf b/tests/drivers/counter/counter_basic_api/boards/nrf52dk_nrf52832.conf deleted file mode 100644 index bd6b714b18a..00000000000 --- a/tests/drivers/counter/counter_basic_api/boards/nrf52dk_nrf52832.conf +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG_COUNTER_TIMER0=y -CONFIG_COUNTER_TIMER1=y -CONFIG_COUNTER_TIMER2=y -CONFIG_COUNTER_TIMER3=y -CONFIG_COUNTER_TIMER4=y -CONFIG_COUNTER_RTC0=y -CONFIG_COUNTER_RTC2=y diff --git a/tests/drivers/counter/counter_basic_api/boards/nrf9160dk_nrf9160.conf b/tests/drivers/counter/counter_basic_api/boards/nrf9160dk_nrf9160.conf deleted file mode 100644 index 25d7ba83ed0..00000000000 --- a/tests/drivers/counter/counter_basic_api/boards/nrf9160dk_nrf9160.conf +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG_COUNTER_TIMER0=y -CONFIG_COUNTER_TIMER1=y -CONFIG_COUNTER_TIMER2=y -CONFIG_COUNTER_RTC0=y diff --git a/tests/drivers/counter/counter_nrf_rtc/fixed_top/boards/nrf52840dk_nrf52840.conf b/tests/drivers/counter/counter_nrf_rtc/fixed_top/boards/nrf52840dk_nrf52840.conf deleted file mode 100644 index 796a77839c3..00000000000 --- a/tests/drivers/counter/counter_nrf_rtc/fixed_top/boards/nrf52840dk_nrf52840.conf +++ /dev/null @@ -1,2 +0,0 @@ -CONFIG_COUNTER_RTC0=y -CONFIG_COUNTER_RTC2=y diff --git a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf52840dk_nrf52840.conf b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf52840dk_nrf52840.conf deleted file mode 100644 index b77788bd0e5..00000000000 --- a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf52840dk_nrf52840.conf +++ /dev/null @@ -1,2 +0,0 @@ -CONFIG_COUNTER=y -CONFIG_COUNTER_TIMER0=y diff --git a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf5340dk_nrf5340_cpuapp.conf b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf5340dk_nrf5340_cpuapp.conf deleted file mode 100644 index b77788bd0e5..00000000000 --- a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf5340dk_nrf5340_cpuapp.conf +++ /dev/null @@ -1,2 +0,0 @@ -CONFIG_COUNTER=y -CONFIG_COUNTER_TIMER0=y diff --git a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf9160dk_nrf9160.conf b/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf9160dk_nrf9160.conf deleted file mode 100644 index b77788bd0e5..00000000000 --- a/tests/drivers/uart/uart_mix_fifo_poll/boards/nrf9160dk_nrf9160.conf +++ /dev/null @@ -1,2 +0,0 @@ -CONFIG_COUNTER=y -CONFIG_COUNTER_TIMER0=y diff --git a/tests/ztest/busy_sim/boards/nrf52840dk_nrf52840.conf b/tests/ztest/busy_sim/boards/nrf52840dk_nrf52840.conf deleted file mode 100644 index 36f0e7aeaec..00000000000 --- a/tests/ztest/busy_sim/boards/nrf52840dk_nrf52840.conf +++ /dev/null @@ -1 +0,0 @@ -CONFIG_COUNTER_TIMER0=y