1 /* @file
2  * @brief Internal APIs for BAP ISO handling
3  *
4  * Copyright (c) 2022 Codecoup
5  * Copyright (c) 2023-2024 Nordic Semiconductor ASA
6  *
7  * SPDX-License-Identifier: Apache-2.0
8  */
9 
10 #include <stdbool.h>
11 #include <stdint.h>
12 
13 #include <zephyr/autoconf.h>
14 #include <zephyr/bluetooth/audio/audio.h>
15 #include <zephyr/bluetooth/audio/bap.h>
16 #include <zephyr/bluetooth/iso.h>
17 #include <zephyr/sys/atomic_types.h>
18 
19 struct bt_bap_iso_dir {
20 	struct bt_bap_stream *stream;
21 	struct bt_bap_ep *ep;
22 	struct bt_iso_chan_io_qos qos;
23 	uint8_t cc[CONFIG_BT_AUDIO_CODEC_CFG_MAX_DATA_SIZE];
24 };
25 
26 struct bt_bap_iso {
27 	struct bt_iso_chan chan;
28 	struct bt_iso_chan_qos qos;
29 
30 	struct bt_bap_iso_dir rx;
31 	struct bt_bap_iso_dir tx;
32 
33 	/* Must be at the end so that everything else in the structure can be
34 	 * memset to zero without affecting the ref.
35 	 */
36 	atomic_t ref;
37 };
38 
39 typedef bool (*bt_bap_iso_func_t)(struct bt_bap_iso *iso, void *user_data);
40 
41 struct bt_bap_iso *bt_bap_iso_new(void);
42 struct bt_bap_iso *bt_bap_iso_ref(struct bt_bap_iso *iso);
43 void bt_bap_iso_unref(struct bt_bap_iso *iso);
44 void bt_bap_iso_foreach(bt_bap_iso_func_t func, void *user_data);
45 struct bt_bap_iso *bt_bap_iso_find(bt_bap_iso_func_t func, void *user_data);
46 void bt_bap_iso_init(struct bt_bap_iso *iso, struct bt_iso_chan_ops *ops);
47 void bt_bap_iso_bind_ep(struct bt_bap_iso *iso, struct bt_bap_ep *ep);
48 void bt_bap_setup_iso_data_path(struct bt_bap_stream *stream);
49 void bt_bap_remove_iso_data_path(struct bt_bap_stream *stream);
50 void bt_bap_iso_unbind_ep(struct bt_bap_iso *iso, struct bt_bap_ep *ep);
51 struct bt_bap_ep *bt_bap_iso_get_ep(bool unicast_client, struct bt_bap_iso *iso,
52 				    enum bt_audio_dir dir);
53 
54 struct bt_bap_ep *bt_bap_iso_get_paired_ep(const struct bt_bap_ep *ep);
55 /* Unicast client-only functions*/
56 void bt_bap_iso_bind_stream(struct bt_bap_iso *bap_iso, struct bt_bap_stream *stream,
57 			    enum bt_audio_dir dir);
58 void bt_bap_iso_unbind_stream(struct bt_bap_stream *stream, enum bt_audio_dir dir);
59 struct bt_bap_stream *bt_bap_iso_get_stream(struct bt_bap_iso *iso, enum bt_audio_dir dir);
60