1 /* @file
2  * @brief Internal APIs for BAP ISO handling
3  *
4  * Copyright (c) 2022 Codecoup
5  * Copyright (c) 2023 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_path path;
23 	struct bt_iso_chan_io_qos qos;
24 	uint8_t cc[CONFIG_BT_AUDIO_CODEC_CFG_MAX_DATA_SIZE];
25 };
26 
27 struct bt_bap_iso {
28 	struct bt_iso_chan chan;
29 	struct bt_iso_chan_qos qos;
30 
31 	struct bt_bap_iso_dir rx;
32 	struct bt_bap_iso_dir tx;
33 
34 	/* Must be at the end so that everything else in the structure can be
35 	 * memset to zero without affecting the ref.
36 	 */
37 	atomic_t ref;
38 };
39 
40 typedef bool (*bt_bap_iso_func_t)(struct bt_bap_iso *iso, void *user_data);
41 
42 struct bt_bap_iso *bt_bap_iso_new(void);
43 struct bt_bap_iso *bt_bap_iso_ref(struct bt_bap_iso *iso);
44 void bt_bap_iso_unref(struct bt_bap_iso *iso);
45 void bt_bap_iso_foreach(bt_bap_iso_func_t func, void *user_data);
46 struct bt_bap_iso *bt_bap_iso_find(bt_bap_iso_func_t func, void *user_data);
47 void bt_bap_iso_init(struct bt_bap_iso *iso, struct bt_iso_chan_ops *ops);
48 void bt_bap_iso_bind_ep(struct bt_bap_iso *iso, struct bt_bap_ep *ep);
49 void bt_bap_iso_configure_data_path(struct bt_bap_ep *ep, struct bt_audio_codec_cfg *codec_cfg);
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_iso *bap_iso, struct bt_bap_stream *stream,
59 			      enum bt_audio_dir dir);
60 struct bt_bap_stream *bt_bap_iso_get_stream(struct bt_bap_iso *iso, enum bt_audio_dir dir);
61