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/has.h>
11 #include <zephyr/bluetooth/gap.h>
12 #include <zephyr/bluetooth/hci_types.h>
13 #include <zephyr/logging/log.h>
14 #include <zephyr/sys/util_macro.h>
15
16 #include "babblekit/testcase.h"
17 #include "bstests.h"
18
19 #include "btp/btp.h"
20 #include "bsim_btp.h"
21
22 LOG_MODULE_REGISTER(bsim_hap_peripheral, CONFIG_BSIM_BTTESTER_LOG_LEVEL);
23
test_hap_peripheral(void)24 static void test_hap_peripheral(void)
25 {
26 char addr_str[BT_ADDR_LE_STR_LEN];
27 bt_addr_le_t remote_addr;
28
29 bsim_btp_uart_init();
30
31 bsim_btp_wait_for_evt(BTP_SERVICE_ID_CORE, BTP_CORE_EV_IUT_READY, NULL);
32
33 bsim_btp_core_register(BTP_SERVICE_ID_GAP);
34 bsim_btp_core_register(BTP_SERVICE_ID_HAS);
35
36 bsim_btp_gap_set_discoverable(BTP_GAP_GENERAL_DISCOVERABLE);
37 bsim_btp_gap_start_advertising(0U, 0U, NULL, BT_HCI_OWN_ADDR_PUBLIC);
38 bsim_btp_wait_for_gap_device_connected(&remote_addr);
39 bt_addr_le_to_str(&remote_addr, addr_str, sizeof(addr_str));
40 LOG_INF("Device %s connected", addr_str);
41 bsim_btp_wait_for_gap_device_disconnected(NULL);
42 LOG_INF("Device %s disconnected", addr_str);
43
44 TEST_PASS("PASSED\n");
45 }
46
47 static const struct bst_test_instance test_sample[] = {
48 {
49 .test_id = "hap_peripheral",
50 .test_descr = "Smoketest for the HAP peripheral BT Tester behavior",
51 .test_main_f = test_hap_peripheral,
52 },
53 BSTEST_END_MARKER,
54 };
55
test_hap_peripheral_install(struct bst_test_list * tests)56 struct bst_test_list *test_hap_peripheral_install(struct bst_test_list *tests)
57 {
58 return bst_add_tests(tests, test_sample);
59 }
60