1 /*
2  * Copyright 2023 NXP
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #include <stddef.h>
7 #include <stdint.h>
8 
9 #include <zephyr/autoconf.h>
10 #include <zephyr/bluetooth/audio/bap.h>
11 #include <zephyr/bluetooth/audio/tmap.h>
12 #include <zephyr/bluetooth/bluetooth.h>
13 #include <zephyr/bluetooth/gap.h>
14 #include <zephyr/bluetooth/hci.h>
15 #include <zephyr/bluetooth/conn.h>
16 #include <zephyr/bluetooth/uuid.h>
17 #include <zephyr/bluetooth/gatt.h>
18 #include <zephyr/sys/printk.h>
19 #include <zephyr/sys/util.h>
20 #include <zephyr/types.h>
21 
22 #include "bstests.h"
23 #include "common.h"
24 
25 #ifdef CONFIG_BT_TMAP
26 extern enum bst_result_t bst_result;
27 
test_main(void)28 static void test_main(void)
29 {
30 	int err;
31 	struct bt_le_ext_adv *ext_adv;
32 
33 	err = bt_enable(NULL);
34 	if (err != 0) {
35 		FAIL("Bluetooth init failed (err %d)\n", err);
36 		return;
37 	}
38 
39 	printk("Bluetooth initialized\n");
40 	/* Initialize TMAP */
41 	err = bt_tmap_register(TMAP_ROLE_SUPPORTED);
42 	if (err != 0) {
43 		FAIL("Failed to register TMAP (err %d)\n", err);
44 		return;
45 	}
46 	printk("TMAP initialized. Start advertising...\n");
47 	setup_connectable_adv(&ext_adv);
48 
49 	WAIT_FOR_FLAG(flag_connected);
50 	printk("Connected!\n");
51 
52 	PASS("TMAP test passed\n");
53 }
54 
55 static const struct bst_test_instance test_tmas[] = {
56 	{
57 		.test_id = "tmap_server",
58 		.test_pre_init_f = test_init,
59 		.test_tick_f = test_tick,
60 		.test_main_f = test_main,
61 
62 	},
63 	BSTEST_END_MARKER
64 };
65 
test_tmap_server_install(struct bst_test_list * tests)66 struct bst_test_list *test_tmap_server_install(struct bst_test_list *tests)
67 {
68 	return bst_add_tests(tests, test_tmas);
69 }
70 #else
test_tmap_server_install(struct bst_test_list * tests)71 struct bst_test_list *test_tmap_server_install(struct bst_test_list *tests)
72 {
73 	return tests;
74 }
75 #endif /* CONFIG_BT_TMAP */
76