1 /*
2 * Copyright 2023 NXP
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #ifdef CONFIG_BT_TMAP
8
9 #include <stdint.h>
10 #include <stddef.h>
11 #include <errno.h>
12 #include <zephyr/types.h>
13
14 #include <zephyr/bluetooth/bluetooth.h>
15 #include <zephyr/bluetooth/hci.h>
16 #include <zephyr/bluetooth/conn.h>
17 #include <zephyr/bluetooth/uuid.h>
18 #include <zephyr/bluetooth/gatt.h>
19
20 #include <zephyr/bluetooth/audio/tmap.h>
21
22 #include "common.h"
23
24 extern enum bst_result_t bst_result;
25
26 static uint8_t tmap_addata[] = {
27 BT_UUID_16_ENCODE(BT_UUID_TMAS_VAL), /* TMAS UUID */
28 (BT_TMAP_ROLE_UMR | BT_TMAP_ROLE_CT), 0x00, /* TMAP Role */
29 };
30
31 static const struct bt_data ad_tmas[] = {
32 BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
33 BT_DATA_BYTES(BT_DATA_GAP_APPEARANCE, 0x09, 0x41), /* Appearance - Earbud */
34 BT_DATA(BT_DATA_SVC_DATA16, tmap_addata, ARRAY_SIZE(tmap_addata)),
35 };
36
test_main(void)37 static void test_main(void)
38 {
39 int err;
40 struct bt_le_ext_adv *adv;
41
42 err = bt_enable(NULL);
43 if (err != 0) {
44 FAIL("Bluetooth init failed (err %d)\n", err);
45 return;
46 }
47
48 printk("Bluetooth initialized\n");
49 /* Initialize TMAP */
50 err = bt_tmap_register(BT_TMAP_ROLE_CT | BT_TMAP_ROLE_UMR);
51 if (err != 0) {
52 return;
53 }
54 printk("TMAP initialized. Start advertising...\n");
55 /* Create a connectable extended advertising set */
56 err = bt_le_ext_adv_create(BT_LE_EXT_ADV_CONN_NAME, NULL, &adv);
57 if (err) {
58 printk("Failed to create advertising set (err %d)\n", err);
59 return;
60 }
61
62 err = bt_le_ext_adv_set_data(adv, ad_tmas, ARRAY_SIZE(ad_tmas), NULL, 0);
63 if (err) {
64 printk("Failed to set advertising data (err %d)\n", err);
65 return;
66 }
67
68 err = bt_le_ext_adv_start(adv, BT_LE_EXT_ADV_START_DEFAULT);
69 if (err) {
70 printk("Failed to start advertising set (err %d)\n", err);
71 return;
72 }
73
74 printk("Advertising successfully started\n");
75 WAIT_FOR_FLAG(flag_connected);
76 printk("Connected!\n");
77
78 PASS("TMAP test passed\n");
79 }
80
81 static const struct bst_test_instance test_tmas[] = {
82 {
83 .test_id = "tmap_server",
84 .test_post_init_f = test_init,
85 .test_tick_f = test_tick,
86 .test_main_f = test_main,
87
88 },
89 BSTEST_END_MARKER
90 };
91
test_tmap_server_install(struct bst_test_list * tests)92 struct bst_test_list *test_tmap_server_install(struct bst_test_list *tests)
93 {
94 return bst_add_tests(tests, test_tmas);
95 }
96 #else
test_tmap_server_install(struct bst_test_list * tests)97 struct bst_test_list *test_tmap_server_install(struct bst_test_list *tests)
98 {
99 return tests;
100 }
101 #endif /* CONFIG_BT_TMAP */
102