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/gap.h>
11 #include <zephyr/bluetooth/hci_types.h>
12 #include <zephyr/logging/log.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_gap_peripheral, CONFIG_BSIM_BTTESTER_LOG_LEVEL);
22 
test_gap_peripheral(void)23 static void test_gap_peripheral(void)
24 {
25 	char addr_str[BT_ADDR_LE_STR_LEN];
26 	bt_addr_le_t remote_addr;
27 	bt_addr_le_t ev_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_gap_set_discoverable(BTP_GAP_GENERAL_DISCOVERABLE);
35 	bsim_btp_gap_start_advertising(0U, 0U, NULL, BT_HCI_OWN_ADDR_PUBLIC);
36 
37 	bsim_btp_wait_for_gap_device_connected(&remote_addr);
38 	bt_addr_le_to_str(&remote_addr, addr_str, sizeof(addr_str));
39 	LOG_INF("Device %s connected", addr_str);
40 
41 	bsim_btp_wait_for_gap_device_disconnected(&ev_addr);
42 	TEST_ASSERT(bt_addr_le_eq(&remote_addr, &ev_addr));
43 	LOG_INF("Device %s disconnected", addr_str);
44 
45 	TEST_PASS("PASSED\n");
46 }
47 
48 static const struct bst_test_instance test_sample[] = {
49 	{
50 		.test_id = "gap_peripheral",
51 		.test_descr = "Smoketest for the GAP peripheral BT Tester behavior",
52 		.test_main_f = test_gap_peripheral,
53 	},
54 	BSTEST_END_MARKER,
55 };
56 
test_gap_peripheral_install(struct bst_test_list * tests)57 struct bst_test_list *test_gap_peripheral_install(struct bst_test_list *tests)
58 {
59 	return bst_add_tests(tests, test_sample);
60 }
61