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/kernel.h>
11 #include <zephyr/logging/log.h>
12 #include <zephyr/net_buf.h>
13 #include <zephyr/sys/util_macro.h>
14
15 #include "babblekit/testcase.h"
16 #include "bstests.h"
17
18 #include "btp/btp.h"
19 #include "bsim_btp.h"
20
21 LOG_MODULE_REGISTER(bsim_hap_central, CONFIG_BSIM_BTTESTER_LOG_LEVEL);
22
test_hap_central(void)23 static void test_hap_central(void)
24 {
25 char addr_str[BT_ADDR_LE_STR_LEN];
26 bt_addr_le_t remote_addr;
27
28 bsim_btp_uart_init();
29
30 bsim_btp_wait_for_evt(BTP_SERVICE_ID_CORE, BTP_CORE_EV_IUT_READY, NULL);
31
32 bsim_btp_core_register(BTP_SERVICE_ID_GAP);
33 bsim_btp_core_register(BTP_SERVICE_ID_HAP);
34
35 bsim_btp_gap_start_discovery(BTP_GAP_DISCOVERY_FLAG_LE);
36 bsim_btp_wait_for_gap_device_found(&remote_addr);
37 bt_addr_le_to_str(&remote_addr, addr_str, sizeof(addr_str));
38 LOG_INF("Found remote device %s", addr_str);
39
40 bsim_btp_gap_stop_discovery();
41 bsim_btp_gap_connect(&remote_addr, BTP_GAP_ADDR_TYPE_IDENTITY);
42 bsim_btp_wait_for_gap_device_connected(NULL);
43 LOG_INF("Device %s connected", addr_str);
44
45 bsim_btp_gap_pair(&remote_addr);
46 bsim_btp_wait_for_gap_sec_level_changed(NULL, NULL);
47
48 bsim_btp_hauc_init();
49 bsim_btp_hauc_discover(&remote_addr);
50 bsim_btp_wait_for_hauc_discovery_complete(NULL);
51
52 bsim_btp_gap_disconnect(&remote_addr);
53 bsim_btp_wait_for_gap_device_disconnected(NULL);
54 LOG_INF("Device %s disconnected", addr_str);
55
56 TEST_PASS("PASSED\n");
57 }
58
59 static const struct bst_test_instance test_sample[] = {
60 {
61 .test_id = "hap_central",
62 .test_descr = "Smoketest for the HAP central BT Tester behavior",
63 .test_main_f = test_hap_central,
64 },
65 BSTEST_END_MARKER,
66 };
67
test_hap_central_install(struct bst_test_list * tests)68 struct bst_test_list *test_hap_central_install(struct bst_test_list *tests)
69 {
70 return bst_add_tests(tests, test_sample);
71 }
72