|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 Nordic Semiconductor ASA |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | +#include <stddef.h> |
| 7 | +#include <stdint.h> |
| 8 | + |
| 9 | +#include <zephyr/bluetooth/addr.h> |
| 10 | +#include <zephyr/bluetooth/audio/audio.h> |
| 11 | +#include <zephyr/bluetooth/audio/lc3.h> |
| 12 | +#include <zephyr/bluetooth/audio/pbp.h> |
| 13 | +#include <zephyr/bluetooth/hci_types.h> |
| 14 | +#include <zephyr/bluetooth/iso.h> |
| 15 | +#include <zephyr/kernel.h> |
| 16 | +#include <zephyr/logging/log.h> |
| 17 | +#include <zephyr/net_buf.h> |
| 18 | +#include <zephyr/sys/util.h> |
| 19 | +#include <zephyr/sys/util_macro.h> |
| 20 | + |
| 21 | +#include "babblekit/testcase.h" |
| 22 | +#include "bstests.h" |
| 23 | + |
| 24 | +#include "btp/btp.h" |
| 25 | +#include "bsim_btp.h" |
| 26 | + |
| 27 | +LOG_MODULE_REGISTER(bsim_pbp_source, CONFIG_BSIM_BTTESTER_LOG_LEVEL); |
| 28 | + |
| 29 | +static void test_pbp_source(void) |
| 30 | +{ |
| 31 | + const uint8_t metadata[] = BT_AUDIO_CODEC_CFG_LC3_META(BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED); |
| 32 | + const uint8_t cc_data_16_2_1[] = BT_AUDIO_CODEC_CFG_LC3_DATA( |
| 33 | + BT_AUDIO_CODEC_CFG_FREQ_16KHZ, BT_AUDIO_CODEC_CFG_DURATION_10, |
| 34 | + BT_AUDIO_LOCATION_FRONT_LEFT, 40U, 1U); |
| 35 | + const enum bt_pbp_announcement_feature features = |
| 36 | + BT_PBP_ANNOUNCEMENT_FEATURE_STANDARD_QUALITY; |
| 37 | + const uint8_t coding_format = BT_HCI_CODING_FORMAT_LC3; |
| 38 | + const uint8_t framing = BT_ISO_FRAMING_UNFRAMED; |
| 39 | + const char *broadcast_name = "broadcast_name"; |
| 40 | + const uint32_t presentation_delay = 40000U; |
| 41 | + const uint32_t broadcast_id = 0x123456U; |
| 42 | + const uint32_t sdu_interval = 10000U; |
| 43 | + const uint16_t max_latency = 10U; |
| 44 | + const uint8_t subgroup_id = 0U; |
| 45 | + const uint16_t max_sdu = 40U; |
| 46 | + const uint8_t source_id = 0U; |
| 47 | + const uint16_t vid = 0x0000U; /* shall be 0x0000 for LC3 */ |
| 48 | + const uint16_t cid = 0x0000U; /* shall be 0x0000 for LC3 */ |
| 49 | + const uint8_t flags = 0U; |
| 50 | + const uint8_t rtn = 2U; |
| 51 | + |
| 52 | + bsim_btp_uart_init(); |
| 53 | + |
| 54 | + bsim_btp_wait_for_evt(BTP_SERVICE_ID_CORE, BTP_CORE_EV_IUT_READY, NULL); |
| 55 | + |
| 56 | + bsim_btp_core_register(BTP_SERVICE_ID_GAP); |
| 57 | + bsim_btp_core_register(BTP_SERVICE_ID_BAP); /* required to start the TX thread */ |
| 58 | + bsim_btp_core_register(BTP_SERVICE_ID_CAP); |
| 59 | + bsim_btp_core_register(BTP_SERVICE_ID_PBP); |
| 60 | + |
| 61 | + bsim_btp_cap_broadcast_source_setup_stream(source_id, subgroup_id, coding_format, vid, cid, |
| 62 | + 0, NULL, 0, NULL); |
| 63 | + bsim_btp_cap_broadcast_source_setup_subgroup( |
| 64 | + source_id, subgroup_id, coding_format, vid, cid, ARRAY_SIZE(cc_data_16_2_1), |
| 65 | + cc_data_16_2_1, ARRAY_SIZE(metadata), metadata); |
| 66 | + bsim_btp_cap_broadcast_source_setup(source_id, broadcast_id, sdu_interval, framing, max_sdu, |
| 67 | + rtn, max_latency, presentation_delay, flags); |
| 68 | + |
| 69 | + bsim_btp_pbp_set_public_broadcast_announcement((uint8_t)features); |
| 70 | + bsim_btp_pbp_set_broadcast_name(broadcast_name); |
| 71 | + |
| 72 | + bsim_btp_cap_broadcast_adv_start(source_id); |
| 73 | + bsim_btp_cap_broadcast_source_start(source_id); |
| 74 | + |
| 75 | + TEST_PASS("PASSED\n"); |
| 76 | +} |
| 77 | + |
| 78 | +static const struct bst_test_instance test_sample[] = { |
| 79 | + { |
| 80 | + .test_id = "pbp_source", |
| 81 | + .test_descr = "Smoketest for the PBP central BT Tester behavior", |
| 82 | + .test_main_f = test_pbp_source, |
| 83 | + }, |
| 84 | + BSTEST_END_MARKER, |
| 85 | +}; |
| 86 | + |
| 87 | +struct bst_test_list *test_pbp_source_install(struct bst_test_list *tests) |
| 88 | +{ |
| 89 | + return bst_add_tests(tests, test_sample); |
| 90 | +} |
0 commit comments