1 /**
2  * @file
3  * @brief Bluetooth Audio handling
4  */
5 
6 /*
7  * Copyright (c) 2020 Intel Corporation
8  * Copyright (c) 2020-2024 Nordic Semiconductor ASA
9  *
10  * SPDX-License-Identifier: Apache-2.0
11  */
12 #ifndef ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_AUDIO_H_
13 #define ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_AUDIO_H_
14 
15 /**
16  * @brief Bluetooth Audio
17  * @defgroup bt_audio Bluetooth Audio
18  * @ingroup bluetooth
19  * @{
20  */
21 
22 #include <stdbool.h>
23 #include <stddef.h>
24 #include <stdint.h>
25 
26 #include <zephyr/autoconf.h>
27 #include <zephyr/bluetooth/audio/lc3.h>
28 #include <zephyr/bluetooth/bluetooth.h>
29 #include <zephyr/bluetooth/buf.h>
30 #include <zephyr/bluetooth/conn.h>
31 #include <zephyr/bluetooth/gatt.h>
32 #include <zephyr/bluetooth/hci.h>
33 #include <zephyr/bluetooth/iso.h>
34 #include <zephyr/sys/atomic.h>
35 #include <zephyr/sys/util.h>
36 #include <zephyr/sys/util_macro.h>
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 /** Size of the broadcast ID in octets */
43 #define BT_AUDIO_BROADCAST_ID_SIZE               3
44 /** Maximum broadcast ID value */
45 #define BT_AUDIO_BROADCAST_ID_MAX                0xFFFFFFU
46 /** Indicates that the server have no preference for the presentation delay */
47 #define BT_AUDIO_PD_PREF_NONE                    0x000000U
48 /** Maximum presentation delay in microseconds */
49 #define BT_AUDIO_PD_MAX                          0xFFFFFFU
50 /** Maximum size of the broadcast code in octets */
51 #define BT_AUDIO_BROADCAST_CODE_SIZE             16
52 
53 /** The minimum size of a Broadcast Name as defined by Bluetooth Assigned Numbers */
54 #define BT_AUDIO_BROADCAST_NAME_LEN_MIN          4
55 /** The maximum size of a Broadcast Name as defined by Bluetooth Assigned Numbers */
56 #define BT_AUDIO_BROADCAST_NAME_LEN_MAX          128
57 
58 /** Size of the stream language value, e.g. "eng" */
59 #define BT_AUDIO_LANG_SIZE 3
60 
61 /**
62  * @brief Codec capability types
63  *
64  * Used to build and parse codec capabilities as specified in the PAC specification.
65  * Source is assigned numbers for Generic Audio, bluetooth.com.
66  */
67 enum bt_audio_codec_cap_type {
68 	/** Supported sampling frequencies */
69 	BT_AUDIO_CODEC_CAP_TYPE_FREQ = 0x01,
70 
71 	/** Supported frame durations */
72 	BT_AUDIO_CODEC_CAP_TYPE_DURATION = 0x02,
73 
74 	/** Supported audio channel counts */
75 	BT_AUDIO_CODEC_CAP_TYPE_CHAN_COUNT = 0x03,
76 
77 	/** Supported octets per codec frame */
78 	BT_AUDIO_CODEC_CAP_TYPE_FRAME_LEN = 0x04,
79 
80 	/** Supported maximum codec frames per SDU  */
81 	BT_AUDIO_CODEC_CAP_TYPE_FRAME_COUNT = 0x05,
82 };
83 
84 /** @brief Supported frequencies bitfield */
85 enum bt_audio_codec_cap_freq {
86 	/** 8 Khz sampling frequency */
87 	BT_AUDIO_CODEC_CAP_FREQ_8KHZ = BIT(0),
88 
89 	/** 11.025 Khz sampling frequency */
90 	BT_AUDIO_CODEC_CAP_FREQ_11KHZ = BIT(1),
91 
92 	/** 16 Khz sampling frequency */
93 	BT_AUDIO_CODEC_CAP_FREQ_16KHZ = BIT(2),
94 
95 	/** 22.05 Khz sampling frequency */
96 	BT_AUDIO_CODEC_CAP_FREQ_22KHZ = BIT(3),
97 
98 	/** 24 Khz sampling frequency */
99 	BT_AUDIO_CODEC_CAP_FREQ_24KHZ = BIT(4),
100 
101 	/** 32 Khz sampling frequency */
102 	BT_AUDIO_CODEC_CAP_FREQ_32KHZ = BIT(5),
103 
104 	/** 44.1 Khz sampling frequency */
105 	BT_AUDIO_CODEC_CAP_FREQ_44KHZ = BIT(6),
106 
107 	/** 48 Khz sampling frequency */
108 	BT_AUDIO_CODEC_CAP_FREQ_48KHZ = BIT(7),
109 
110 	/** 88.2 Khz sampling frequency */
111 	BT_AUDIO_CODEC_CAP_FREQ_88KHZ = BIT(8),
112 
113 	/** 96 Khz sampling frequency */
114 	BT_AUDIO_CODEC_CAP_FREQ_96KHZ = BIT(9),
115 
116 	/** 176.4 Khz sampling frequency */
117 	BT_AUDIO_CODEC_CAP_FREQ_176KHZ = BIT(10),
118 
119 	/** 192 Khz sampling frequency */
120 	BT_AUDIO_CODEC_CAP_FREQ_192KHZ = BIT(11),
121 
122 	/** 384 Khz sampling frequency */
123 	BT_AUDIO_CODEC_CAP_FREQ_384KHZ = BIT(12),
124 
125 	/** Any frequency capability */
126 	BT_AUDIO_CODEC_CAP_FREQ_ANY =
127 		(BT_AUDIO_CODEC_CAP_FREQ_8KHZ | BT_AUDIO_CODEC_CAP_FREQ_11KHZ |
128 		 BT_AUDIO_CODEC_CAP_FREQ_16KHZ | BT_AUDIO_CODEC_CAP_FREQ_22KHZ |
129 		 BT_AUDIO_CODEC_CAP_FREQ_24KHZ | BT_AUDIO_CODEC_CAP_FREQ_32KHZ |
130 		 BT_AUDIO_CODEC_CAP_FREQ_44KHZ | BT_AUDIO_CODEC_CAP_FREQ_48KHZ |
131 		 BT_AUDIO_CODEC_CAP_FREQ_88KHZ | BT_AUDIO_CODEC_CAP_FREQ_96KHZ |
132 		 BT_AUDIO_CODEC_CAP_FREQ_176KHZ | BT_AUDIO_CODEC_CAP_FREQ_192KHZ |
133 		 BT_AUDIO_CODEC_CAP_FREQ_384KHZ),
134 };
135 
136 /** @brief Supported frame durations bitfield */
137 enum bt_audio_codec_cap_frame_dur {
138 	/** 7.5 msec frame duration capability */
139 	BT_AUDIO_CODEC_CAP_DURATION_7_5 = BIT(0),
140 
141 	/** 10 msec frame duration capability */
142 	BT_AUDIO_CODEC_CAP_DURATION_10 = BIT(1),
143 
144 	/** Any frame duration capability */
145 	BT_AUDIO_CODEC_CAP_DURATION_ANY =
146 		(BT_AUDIO_CODEC_CAP_DURATION_7_5 | BT_AUDIO_CODEC_CAP_DURATION_10),
147 
148 	/**
149 	 * @brief 7.5 msec preferred frame duration capability.
150 	 *
151 	 * This shall only be set if @ref BT_AUDIO_CODEC_CAP_DURATION_7_5 is also set, and if @ref
152 	 * BT_AUDIO_CODEC_CAP_DURATION_PREFER_10 is not set.
153 	 */
154 	BT_AUDIO_CODEC_CAP_DURATION_PREFER_7_5 = BIT(4),
155 
156 	/**
157 	 * @brief 10 msec preferred frame duration capability
158 	 *
159 	 * This shall only be set if @ref BT_AUDIO_CODEC_CAP_DURATION_10 is also set, and if @ref
160 	 * BT_AUDIO_CODEC_CAP_DURATION_PREFER_7_5 is not set.
161 	 */
162 	BT_AUDIO_CODEC_CAP_DURATION_PREFER_10 = BIT(5),
163 };
164 
165 /** Supported audio capabilities channel count bitfield */
166 enum bt_audio_codec_cap_chan_count {
167 	/** Supporting 1 channel */
168 	BT_AUDIO_CODEC_CAP_CHAN_COUNT_1 = BIT(0),
169 
170 	/** Supporting 2 channel */
171 	BT_AUDIO_CODEC_CAP_CHAN_COUNT_2 = BIT(1),
172 
173 	/** Supporting 3 channel */
174 	BT_AUDIO_CODEC_CAP_CHAN_COUNT_3 = BIT(2),
175 
176 	/** Supporting 4 channel */
177 	BT_AUDIO_CODEC_CAP_CHAN_COUNT_4 = BIT(3),
178 
179 	/** Supporting 5 channel */
180 	BT_AUDIO_CODEC_CAP_CHAN_COUNT_5 = BIT(4),
181 
182 	/** Supporting 6 channel */
183 	BT_AUDIO_CODEC_CAP_CHAN_COUNT_6 = BIT(5),
184 
185 	/** Supporting 7 channel */
186 	BT_AUDIO_CODEC_CAP_CHAN_COUNT_7 = BIT(6),
187 
188 	/** Supporting 8 channel */
189 	BT_AUDIO_CODEC_CAP_CHAN_COUNT_8 = BIT(7),
190 
191 	/** Supporting all channels */
192 	BT_AUDIO_CODEC_CAP_CHAN_COUNT_ANY =
193 		(BT_AUDIO_CODEC_CAP_CHAN_COUNT_1 | BT_AUDIO_CODEC_CAP_CHAN_COUNT_2 |
194 		 BT_AUDIO_CODEC_CAP_CHAN_COUNT_3 | BT_AUDIO_CODEC_CAP_CHAN_COUNT_4 |
195 		 BT_AUDIO_CODEC_CAP_CHAN_COUNT_5 | BT_AUDIO_CODEC_CAP_CHAN_COUNT_6 |
196 		 BT_AUDIO_CODEC_CAP_CHAN_COUNT_7 | BT_AUDIO_CODEC_CAP_CHAN_COUNT_8),
197 };
198 
199 /** Minimum supported channel counts */
200 #define BT_AUDIO_CODEC_CAP_CHAN_COUNT_MIN 1
201 /** Maximum supported channel counts */
202 #define BT_AUDIO_CODEC_CAP_CHAN_COUNT_MAX 8
203 
204 /**
205  * @brief Channel count support capability
206  *
207  * Macro accepts variable number of channel counts.
208  * The allowed channel counts are defined by specification and have to be in range from
209  * @ref BT_AUDIO_CODEC_CAP_CHAN_COUNT_MIN to @ref BT_AUDIO_CODEC_CAP_CHAN_COUNT_MAX inclusive.
210  *
211  * Example to support 1 and 3 channels:
212  *   BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(1, 3)
213  */
214 #define BT_AUDIO_CODEC_CAP_CHAN_COUNT_SUPPORT(...)                                                 \
215 	((enum bt_audio_codec_cap_chan_count)((FOR_EACH(BIT, (|), __VA_ARGS__)) >> 1))
216 
217 /** struct to hold minimum and maximum supported codec frame sizes */
218 struct bt_audio_codec_octets_per_codec_frame {
219 	/** Minimum number of octets supported per codec frame */
220 	uint16_t min;
221 	/** Maximum number of octets supported per codec frame */
222 	uint16_t max;
223 };
224 
225 /**
226  * @brief Codec configuration types
227  *
228  * Used to build and parse codec configurations as specified in the ASCS and BAP specifications.
229  * Source is assigned numbers for Generic Audio, bluetooth.com.
230  */
231 enum bt_audio_codec_cfg_type {
232 	/** Sampling frequency */
233 	BT_AUDIO_CODEC_CFG_FREQ = 0x01,
234 
235 	/** Frame duration */
236 	BT_AUDIO_CODEC_CFG_DURATION = 0x02,
237 
238 	/** Audio channel allocation */
239 	BT_AUDIO_CODEC_CFG_CHAN_ALLOC = 0x03,
240 
241 	/** Octets per codec frame */
242 	BT_AUDIO_CODEC_CFG_FRAME_LEN = 0x04,
243 
244 	/** Codec frame blocks per SDU */
245 	BT_AUDIO_CODEC_CFG_FRAME_BLKS_PER_SDU = 0x05,
246 };
247 
248 /** Codec configuration sampling freqency */
249 enum bt_audio_codec_cfg_freq {
250 	/** 8 Khz codec sampling frequency */
251 	BT_AUDIO_CODEC_CFG_FREQ_8KHZ = 0x01,
252 
253 	/** 11.025 Khz codec sampling frequency */
254 	BT_AUDIO_CODEC_CFG_FREQ_11KHZ = 0x02,
255 
256 	/** 16 Khz codec sampling frequency */
257 	BT_AUDIO_CODEC_CFG_FREQ_16KHZ = 0x03,
258 
259 	/** 22.05 Khz codec sampling frequency */
260 	BT_AUDIO_CODEC_CFG_FREQ_22KHZ = 0x04,
261 
262 	/** 24 Khz codec sampling frequency */
263 	BT_AUDIO_CODEC_CFG_FREQ_24KHZ = 0x05,
264 
265 	/** 32 Khz codec sampling frequency */
266 	BT_AUDIO_CODEC_CFG_FREQ_32KHZ = 0x06,
267 
268 	/** 44.1 Khz codec sampling frequency */
269 	BT_AUDIO_CODEC_CFG_FREQ_44KHZ = 0x07,
270 
271 	/** 48 Khz codec sampling frequency */
272 	BT_AUDIO_CODEC_CFG_FREQ_48KHZ = 0x08,
273 
274 	/** 88.2 Khz codec sampling frequency */
275 	BT_AUDIO_CODEC_CFG_FREQ_88KHZ = 0x09,
276 
277 	/** 96 Khz codec sampling frequency */
278 	BT_AUDIO_CODEC_CFG_FREQ_96KHZ = 0x0a,
279 
280 	/** 176.4 Khz codec sampling frequency */
281 	BT_AUDIO_CODEC_CFG_FREQ_176KHZ = 0x0b,
282 
283 	/** 192 Khz codec sampling frequency */
284 	BT_AUDIO_CODEC_CFG_FREQ_192KHZ = 0x0c,
285 
286 	/** 384 Khz codec sampling frequency */
287 	BT_AUDIO_CODEC_CFG_FREQ_384KHZ = 0x0d,
288 };
289 
290 /** Codec configuration frame duration */
291 enum bt_audio_codec_cfg_frame_dur {
292 	/** 7.5 msec Frame Duration configuration */
293 	BT_AUDIO_CODEC_CFG_DURATION_7_5 = 0x00,
294 
295 	/** 10 msec Frame Duration configuration */
296 	BT_AUDIO_CODEC_CFG_DURATION_10 = 0x01,
297 };
298 
299 /**
300  * @brief Audio Context Type for Generic Audio
301  *
302  * These values are defined by the Generic Audio Assigned Numbers, bluetooth.com
303  */
304 enum bt_audio_context {
305 	/** Prohibited */
306 	BT_AUDIO_CONTEXT_TYPE_PROHIBITED = 0,
307 	/**
308 	 * Identifies audio where the use case context does not match any other defined value,
309 	 * or where the context is unknown or cannot be determined.
310 	 */
311 	BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED = BIT(0),
312 	/**
313 	 * Conversation between humans, for example, in telephony or video calls, including
314 	 * traditional cellular as well as VoIP and Push-to-Talk
315 	 */
316 	BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL = BIT(1),
317 	/** Media, for example, music playback, radio, podcast or movie soundtrack, or tv audio */
318 	BT_AUDIO_CONTEXT_TYPE_MEDIA = BIT(2),
319 	/**
320 	 * Audio associated with video gaming, for example gaming media; gaming effects; music
321 	 * and in-game voice chat between participants; or a mix of all the above
322 	 */
323 	BT_AUDIO_CONTEXT_TYPE_GAME = BIT(3),
324 	/** Instructional audio, for example, in navigation, announcements, or user guidance */
325 	BT_AUDIO_CONTEXT_TYPE_INSTRUCTIONAL = BIT(4),
326 	/** Man-machine communication, for example, with voice recognition or virtual assistants */
327 	BT_AUDIO_CONTEXT_TYPE_VOICE_ASSISTANTS = BIT(5),
328 	/**
329 	 * Live audio, for example, from a microphone where audio is perceived both through a
330 	 * direct acoustic path and through an LE Audio Stream
331 	 */
332 	BT_AUDIO_CONTEXT_TYPE_LIVE = BIT(6),
333 	/**
334 	 * Sound effects including keyboard and touch feedback; menu and user interface sounds;
335 	 * and other system sounds
336 	 */
337 	BT_AUDIO_CONTEXT_TYPE_SOUND_EFFECTS = BIT(7),
338 	/**
339 	 * Notification and reminder sounds; attention-seeking audio, for example,
340 	 * in beeps signaling the arrival of a message
341 	 */
342 	BT_AUDIO_CONTEXT_TYPE_NOTIFICATIONS = BIT(8),
343 	/**
344 	 * Alerts the user to an incoming call, for example, an incoming telephony or video call,
345 	 * including traditional cellular as well as VoIP and Push-to-Talk
346 	 */
347 	BT_AUDIO_CONTEXT_TYPE_RINGTONE = BIT(9),
348 	/**
349 	 * Alarms and timers; immediate alerts, for example, in a critical battery alarm,
350 	 * timer expiry or alarm clock, toaster, cooker, kettle, microwave, etc.
351 	 */
352 	BT_AUDIO_CONTEXT_TYPE_ALERTS = BIT(10),
353 	/** Emergency alarm Emergency sounds, for example, fire alarms or other urgent alerts */
354 	BT_AUDIO_CONTEXT_TYPE_EMERGENCY_ALARM = BIT(11),
355 };
356 
357 /**
358  * Any known context.
359  */
360 #define BT_AUDIO_CONTEXT_TYPE_ANY	 (BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED | \
361 					  BT_AUDIO_CONTEXT_TYPE_CONVERSATIONAL | \
362 					  BT_AUDIO_CONTEXT_TYPE_MEDIA | \
363 					  BT_AUDIO_CONTEXT_TYPE_GAME | \
364 					  BT_AUDIO_CONTEXT_TYPE_INSTRUCTIONAL | \
365 					  BT_AUDIO_CONTEXT_TYPE_VOICE_ASSISTANTS | \
366 					  BT_AUDIO_CONTEXT_TYPE_LIVE | \
367 					  BT_AUDIO_CONTEXT_TYPE_SOUND_EFFECTS | \
368 					  BT_AUDIO_CONTEXT_TYPE_NOTIFICATIONS | \
369 					  BT_AUDIO_CONTEXT_TYPE_RINGTONE | \
370 					  BT_AUDIO_CONTEXT_TYPE_ALERTS | \
371 					  BT_AUDIO_CONTEXT_TYPE_EMERGENCY_ALARM)
372 
373 /**
374  * @brief Parental rating defined by the Generic Audio assigned numbers (bluetooth.com).
375  *
376  * The numbering scheme is aligned with Annex F of EN 300 707 v1.2.1 which
377  * defined parental rating for viewing.
378  */
379 enum bt_audio_parental_rating {
380 	/** No rating */
381 	BT_AUDIO_PARENTAL_RATING_NO_RATING        = 0x00,
382 	/** For all ages */
383 	BT_AUDIO_PARENTAL_RATING_AGE_ANY          = 0x01,
384 	/** Recommended for listeners of age 5 and above */
385 	BT_AUDIO_PARENTAL_RATING_AGE_5_OR_ABOVE   = 0x02,
386 	/** Recommended for listeners of age 6 and above */
387 	BT_AUDIO_PARENTAL_RATING_AGE_6_OR_ABOVE   = 0x03,
388 	/** Recommended for listeners of age 7 and above */
389 	BT_AUDIO_PARENTAL_RATING_AGE_7_OR_ABOVE   = 0x04,
390 	/** Recommended for listeners of age 8 and above */
391 	BT_AUDIO_PARENTAL_RATING_AGE_8_OR_ABOVE   = 0x05,
392 	/** Recommended for listeners of age 9 and above */
393 	BT_AUDIO_PARENTAL_RATING_AGE_9_OR_ABOVE   = 0x06,
394 	/** Recommended for listeners of age 10 and above */
395 	BT_AUDIO_PARENTAL_RATING_AGE_10_OR_ABOVE  = 0x07,
396 	/** Recommended for listeners of age 11 and above */
397 	BT_AUDIO_PARENTAL_RATING_AGE_11_OR_ABOVE  = 0x08,
398 	/** Recommended for listeners of age 12 and above */
399 	BT_AUDIO_PARENTAL_RATING_AGE_12_OR_ABOVE  = 0x09,
400 	/** Recommended for listeners of age 13 and above */
401 	BT_AUDIO_PARENTAL_RATING_AGE_13_OR_ABOVE  = 0x0A,
402 	/** Recommended for listeners of age 14 and above */
403 	BT_AUDIO_PARENTAL_RATING_AGE_14_OR_ABOVE  = 0x0B,
404 	/** Recommended for listeners of age 15 and above */
405 	BT_AUDIO_PARENTAL_RATING_AGE_15_OR_ABOVE  = 0x0C,
406 	/** Recommended for listeners of age 16 and above */
407 	BT_AUDIO_PARENTAL_RATING_AGE_16_OR_ABOVE  = 0x0D,
408 	/** Recommended for listeners of age 17 and above */
409 	BT_AUDIO_PARENTAL_RATING_AGE_17_OR_ABOVE  = 0x0E,
410 	/** Recommended for listeners of age 18 and above */
411 	BT_AUDIO_PARENTAL_RATING_AGE_18_OR_ABOVE  = 0x0F
412 };
413 
414 /** @brief Audio Active State defined by the Generic Audio assigned numbers (bluetooth.com). */
415 enum bt_audio_active_state {
416 	/** No audio data is being transmitted */
417 	BT_AUDIO_ACTIVE_STATE_DISABLED       = 0x00,
418 	/** Audio data is being transmitted */
419 	BT_AUDIO_ACTIVE_STATE_ENABLED        = 0x01,
420 };
421 
422 /**
423  * @brief Codec metadata type IDs
424  *
425  * Metadata types defined by the Generic Audio assigned numbers (bluetooth.com).
426  */
427 enum bt_audio_metadata_type {
428 	/**
429 	 * @brief Preferred audio context.
430 	 *
431 	 * Bitfield of preferred audio contexts.
432 	 *
433 	 * If 0, the context type is not a preferred use case for this codec
434 	 * configuration.
435 	 *
436 	 * See the BT_AUDIO_CONTEXT_* for valid values.
437 	 */
438 	BT_AUDIO_METADATA_TYPE_PREF_CONTEXT        = 0x01,
439 
440 	/**
441 	 * @brief Streaming audio context.
442 	 *
443 	 * Bitfield of streaming audio contexts.
444 	 *
445 	 * If 0, the context type is not a preferred use case for this codec
446 	 * configuration.
447 	 *
448 	 * See the BT_AUDIO_CONTEXT_* for valid values.
449 	 */
450 	BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT      = 0x02,
451 
452 	/** UTF-8 encoded title or summary of stream content */
453 	BT_AUDIO_METADATA_TYPE_PROGRAM_INFO        = 0x03,
454 
455 	/**
456 	 * @brief Language
457 	 *
458 	 * 3 octet lower case language code defined by ISO 639-3
459 	 * Possible values can be found at https://iso639-3.sil.org/code_tables/639/data
460 	 */
461 	BT_AUDIO_METADATA_TYPE_LANG                = 0x04,
462 
463 	/** Array of 8-bit CCID values */
464 	BT_AUDIO_METADATA_TYPE_CCID_LIST           = 0x05,
465 
466 	/**
467 	 * @brief Parental rating
468 	 *
469 	 * See @ref bt_audio_parental_rating for valid values.
470 	 */
471 	BT_AUDIO_METADATA_TYPE_PARENTAL_RATING     = 0x06,
472 
473 	/** UTF-8 encoded URI for additional Program information */
474 	BT_AUDIO_METADATA_TYPE_PROGRAM_INFO_URI    = 0x07,
475 
476 	/**
477 	 * @brief Audio active state
478 	 *
479 	 * See @ref bt_audio_active_state for valid values.
480 	 */
481 	BT_AUDIO_METADATA_TYPE_AUDIO_STATE         = 0x08,
482 
483 	/** Broadcast Audio Immediate Rendering flag  */
484 	BT_AUDIO_METADATA_TYPE_BROADCAST_IMMEDIATE = 0x09,
485 
486 	/** Extended metadata */
487 	BT_AUDIO_METADATA_TYPE_EXTENDED            = 0xFE,
488 
489 	/** Vendor specific metadata */
490 	BT_AUDIO_METADATA_TYPE_VENDOR              = 0xFF,
491 };
492 
493 /**
494  * @brief Helper to check whether metadata type is known by the stack.
495  *
496  * @note @p _type is evaluated thrice.
497  */
498 #define BT_AUDIO_METADATA_TYPE_IS_KNOWN(_type)                                                     \
499 	(IN_RANGE((_type), BT_AUDIO_METADATA_TYPE_PREF_CONTEXT,                                    \
500 		  BT_AUDIO_METADATA_TYPE_BROADCAST_IMMEDIATE) ||                                   \
501 	 (_type) == BT_AUDIO_METADATA_TYPE_EXTENDED || (_type) == BT_AUDIO_METADATA_TYPE_VENDOR)
502 
503 /**
504  * @name Unicast Announcement Type
505  * @{
506  */
507 /** Unicast Server is connectable and is requesting a connection. */
508 #define BT_AUDIO_UNICAST_ANNOUNCEMENT_GENERAL    0x00
509 /** Unicast Server is connectable but is not requesting a connection. */
510 #define BT_AUDIO_UNICAST_ANNOUNCEMENT_TARGETED   0x01
511 /** @} */
512 
513 /**
514  * @brief Helper to declare elements of bt_audio_codec_cap arrays
515  *
516  * This macro is mainly for creating an array of struct bt_audio_codec_cap data arrays.
517  *
518  * @param _type Type of advertising data field
519  * @param _bytes Variable number of single-byte parameters
520  */
521 #define BT_AUDIO_CODEC_DATA(_type, _bytes...)                                                      \
522 	(sizeof((uint8_t)_type) + sizeof((uint8_t[]){_bytes})), (_type), _bytes
523 
524 /**
525  * @brief Helper to declare @ref bt_audio_codec_cfg
526  *
527  * @param _id Codec ID
528  * @param _cid Company ID
529  * @param _vid Vendor ID
530  * @param _data Codec Specific Data in LVT format
531  * @param _meta Codec Specific Metadata in LVT format
532  */
533 #define BT_AUDIO_CODEC_CFG(_id, _cid, _vid, _data, _meta)                                          \
534 	((struct bt_audio_codec_cfg){                                                              \
535 		/* Use HCI data path as default, can be overwritten by application */              \
536 		.path_id = BT_ISO_DATA_PATH_HCI,                                                   \
537 		.ctlr_transcode = false,                                                           \
538 		.id = _id,                                                                         \
539 		.cid = _cid,                                                                       \
540 		.vid = _vid,                                                                       \
541 		.data_len = sizeof((uint8_t[])_data),                                              \
542 		.data = _data,                                                                     \
543 		.meta_len = sizeof((uint8_t[])_meta),                                              \
544 		.meta = _meta,                                                                     \
545 	})
546 
547 /**
548  * @brief Helper to declare @ref bt_audio_codec_cap structure
549  *
550  * @param _id Codec ID
551  * @param _cid Company ID
552  * @param _vid Vendor ID
553  * @param _data Codec Specific Data in LVT format
554  * @param _meta Codec Specific Metadata in LVT format
555  */
556 #define BT_AUDIO_CODEC_CAP(_id, _cid, _vid, _data, _meta)                                          \
557 	((struct bt_audio_codec_cap){                                                              \
558 		/* Use HCI data path as default, can be overwritten by application */              \
559 		.path_id = BT_ISO_DATA_PATH_HCI,                                                   \
560 		.ctlr_transcode = false,                                                           \
561 		.id = (_id),                                                                       \
562 		.cid = (_cid),                                                                     \
563 		.vid = (_vid),                                                                     \
564 		.data_len = sizeof((uint8_t[])_data),                                              \
565 		.data = _data,                                                                     \
566 		.meta_len = sizeof((uint8_t[])_meta),                                              \
567 		.meta = _meta,                                                                     \
568 	})
569 
570 /**
571  * @brief Location values for BT Audio.
572  *
573  * These values are defined by the Generic Audio Assigned Numbers, bluetooth.com
574  */
575 enum bt_audio_location {
576 	/** Mono Audio (no specified Audio Location) */
577 	BT_AUDIO_LOCATION_MONO_AUDIO = 0,
578 	/** Front Left */
579 	BT_AUDIO_LOCATION_FRONT_LEFT = BIT(0),
580 	/** Front Right */
581 	BT_AUDIO_LOCATION_FRONT_RIGHT = BIT(1),
582 	/** Front Center */
583 	BT_AUDIO_LOCATION_FRONT_CENTER = BIT(2),
584 	/** Low Frequency Effects 1 */
585 	BT_AUDIO_LOCATION_LOW_FREQ_EFFECTS_1 = BIT(3),
586 	/** Back Left */
587 	BT_AUDIO_LOCATION_BACK_LEFT = BIT(4),
588 	/** Back Right */
589 	BT_AUDIO_LOCATION_BACK_RIGHT = BIT(5),
590 	/** Front Left of Center */
591 	BT_AUDIO_LOCATION_FRONT_LEFT_OF_CENTER = BIT(6),
592 	/** Front Right of Center */
593 	BT_AUDIO_LOCATION_FRONT_RIGHT_OF_CENTER = BIT(7),
594 	/** Back Center */
595 	BT_AUDIO_LOCATION_BACK_CENTER = BIT(8),
596 	/** Low Frequency Effects 2 */
597 	BT_AUDIO_LOCATION_LOW_FREQ_EFFECTS_2 = BIT(9),
598 	/** Side Left */
599 	BT_AUDIO_LOCATION_SIDE_LEFT = BIT(10),
600 	/** Side Right */
601 	BT_AUDIO_LOCATION_SIDE_RIGHT = BIT(11),
602 	/** Top Front Left */
603 	BT_AUDIO_LOCATION_TOP_FRONT_LEFT = BIT(12),
604 	/** Top Front Right */
605 	BT_AUDIO_LOCATION_TOP_FRONT_RIGHT = BIT(13),
606 	/** Top Front Center */
607 	BT_AUDIO_LOCATION_TOP_FRONT_CENTER = BIT(14),
608 	/** Top Center */
609 	BT_AUDIO_LOCATION_TOP_CENTER = BIT(15),
610 	/** Top Back Left */
611 	BT_AUDIO_LOCATION_TOP_BACK_LEFT = BIT(16),
612 	/** Top Back Right */
613 	BT_AUDIO_LOCATION_TOP_BACK_RIGHT = BIT(17),
614 	/** Top Side Left */
615 	BT_AUDIO_LOCATION_TOP_SIDE_LEFT = BIT(18),
616 	/** Top Side Right */
617 	BT_AUDIO_LOCATION_TOP_SIDE_RIGHT = BIT(19),
618 	/** Top Back Center */
619 	BT_AUDIO_LOCATION_TOP_BACK_CENTER = BIT(20),
620 	/** Bottom Front Center */
621 	BT_AUDIO_LOCATION_BOTTOM_FRONT_CENTER = BIT(21),
622 	/** Bottom Front Left */
623 	BT_AUDIO_LOCATION_BOTTOM_FRONT_LEFT = BIT(22),
624 	/** Bottom Front Right */
625 	BT_AUDIO_LOCATION_BOTTOM_FRONT_RIGHT = BIT(23),
626 	/** Front Left Wide */
627 	BT_AUDIO_LOCATION_FRONT_LEFT_WIDE = BIT(24),
628 	/** Front Right Wide */
629 	BT_AUDIO_LOCATION_FRONT_RIGHT_WIDE = BIT(25),
630 	/** Left Surround */
631 	BT_AUDIO_LOCATION_LEFT_SURROUND = BIT(26),
632 	/** Right Surround */
633 	BT_AUDIO_LOCATION_RIGHT_SURROUND = BIT(27),
634 };
635 
636 /**
637  * Any known location.
638  */
639 #define BT_AUDIO_LOCATION_ANY (BT_AUDIO_LOCATION_FRONT_LEFT | \
640 			       BT_AUDIO_LOCATION_FRONT_RIGHT | \
641 			       BT_AUDIO_LOCATION_FRONT_CENTER | \
642 			       BT_AUDIO_LOCATION_LOW_FREQ_EFFECTS_1 | \
643 			       BT_AUDIO_LOCATION_BACK_LEFT | \
644 			       BT_AUDIO_LOCATION_BACK_RIGHT | \
645 			       BT_AUDIO_LOCATION_FRONT_LEFT_OF_CENTER | \
646 			       BT_AUDIO_LOCATION_FRONT_RIGHT_OF_CENTER | \
647 			       BT_AUDIO_LOCATION_BACK_CENTER | \
648 			       BT_AUDIO_LOCATION_LOW_FREQ_EFFECTS_2 | \
649 			       BT_AUDIO_LOCATION_SIDE_LEFT | \
650 			       BT_AUDIO_LOCATION_SIDE_RIGHT | \
651 			       BT_AUDIO_LOCATION_TOP_FRONT_LEFT | \
652 			       BT_AUDIO_LOCATION_TOP_FRONT_RIGHT | \
653 			       BT_AUDIO_LOCATION_TOP_FRONT_CENTER | \
654 			       BT_AUDIO_LOCATION_TOP_CENTER | \
655 			       BT_AUDIO_LOCATION_TOP_BACK_LEFT | \
656 			       BT_AUDIO_LOCATION_TOP_BACK_RIGHT | \
657 			       BT_AUDIO_LOCATION_TOP_SIDE_LEFT | \
658 			       BT_AUDIO_LOCATION_TOP_SIDE_RIGHT | \
659 			       BT_AUDIO_LOCATION_TOP_BACK_CENTER | \
660 			       BT_AUDIO_LOCATION_BOTTOM_FRONT_CENTER | \
661 			       BT_AUDIO_LOCATION_BOTTOM_FRONT_LEFT | \
662 			       BT_AUDIO_LOCATION_BOTTOM_FRONT_RIGHT | \
663 			       BT_AUDIO_LOCATION_FRONT_LEFT_WIDE | \
664 			       BT_AUDIO_LOCATION_FRONT_RIGHT_WIDE | \
665 			       BT_AUDIO_LOCATION_LEFT_SURROUND | \
666 			       BT_AUDIO_LOCATION_RIGHT_SURROUND)
667 
668 /** @brief Codec capability structure. */
669 struct bt_audio_codec_cap {
670 	/** Data path ID
671 	 *
672 	 * @ref BT_ISO_DATA_PATH_HCI for HCI path, or any other value for
673 	 * vendor specific ID.
674 	 */
675 	uint8_t path_id;
676 	/** Whether or not the local controller should transcode
677 	 *
678 	 * This effectively sets the coding format for the ISO data path to @ref
679 	 * BT_HCI_CODING_FORMAT_TRANSPARENT if false, else uses the @ref bt_audio_codec_cfg.id.
680 	 */
681 	bool ctlr_transcode;
682 	/** Codec ID */
683 	uint8_t id;
684 	/** Codec Company ID */
685 	uint16_t cid;
686 	/** Codec Company Vendor ID */
687 	uint16_t vid;
688 #if CONFIG_BT_AUDIO_CODEC_CAP_MAX_DATA_SIZE > 0 || defined(__DOXYGEN__)
689 	/** Codec Specific Capabilities Data count */
690 	size_t data_len;
691 	/** Codec Specific Capabilities Data */
692 	uint8_t data[CONFIG_BT_AUDIO_CODEC_CAP_MAX_DATA_SIZE];
693 #endif /* CONFIG_BT_AUDIO_CODEC_CAP_MAX_DATA_SIZE > 0 */
694 #if defined(CONFIG_BT_AUDIO_CODEC_CAP_MAX_METADATA_SIZE) || defined(__DOXYGEN__)
695 	/** Codec Specific Capabilities Metadata count */
696 	size_t meta_len;
697 	/** Codec Specific Capabilities Metadata */
698 	uint8_t meta[CONFIG_BT_AUDIO_CODEC_CAP_MAX_METADATA_SIZE];
699 #endif /* CONFIG_BT_AUDIO_CODEC_CAP_MAX_METADATA_SIZE */
700 };
701 
702 /** @brief Codec specific configuration structure. */
703 struct bt_audio_codec_cfg {
704 	/** Data path ID
705 	 *
706 	 * @ref BT_ISO_DATA_PATH_HCI for HCI path, or any other value for
707 	 * vendor specific ID.
708 	 */
709 	uint8_t path_id;
710 	/** Whether or not the local controller should transcode
711 	 *
712 	 * This effectively sets the coding format for the ISO data path to @ref
713 	 * BT_HCI_CODING_FORMAT_TRANSPARENT if false, else uses the @ref bt_audio_codec_cfg.id.
714 	 */
715 	bool ctlr_transcode;
716 	/** Codec ID */
717 	uint8_t  id;
718 	/** Codec Company ID */
719 	uint16_t cid;
720 	/** Codec Company Vendor ID */
721 	uint16_t vid;
722 #if CONFIG_BT_AUDIO_CODEC_CFG_MAX_DATA_SIZE > 0 || defined(__DOXYGEN__)
723 	/** Codec Specific Capabilities Data count */
724 	size_t data_len;
725 	/** Codec Specific Capabilities Data */
726 	uint8_t data[CONFIG_BT_AUDIO_CODEC_CFG_MAX_DATA_SIZE];
727 #endif /* CONFIG_BT_AUDIO_CODEC_CFG_MAX_DATA_SIZE > 0 */
728 #if CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE > 0 || defined(__DOXYGEN__)
729 	/** Codec Specific Capabilities Metadata count */
730 	size_t meta_len;
731 	/** Codec Specific Capabilities Metadata */
732 	uint8_t meta[CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE];
733 #endif /* CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE > 0 */
734 };
735 
736 /**
737  * @brief Helper for parsing length-type-value data.
738  *
739  * @param ltv       Length-type-value (LTV) encoded data.
740  * @param size      Size of the @p ltv data.
741  * @param func      Callback function which will be called for each element
742  *                  that's found in the data. The callback should return
743  *                  true to continue parsing, or false to stop parsing.
744  * @param user_data User data to be passed to the callback.
745  *
746  * @retval 0 if all entries were parsed.
747  * @retval -EINVAL if the data is incorrectly encoded
748  * @retval -ECANCELED if parsing was prematurely cancelled by the callback
749  */
750 int bt_audio_data_parse(const uint8_t ltv[], size_t size,
751 			bool (*func)(struct bt_data *data, void *user_data), void *user_data);
752 
753 /**
754  * @brief Function to get the number of channels from the channel allocation
755  *
756  * @param chan_allocation The channel allocation
757  *
758  * @return The number of channels
759  */
760 uint8_t bt_audio_get_chan_count(enum bt_audio_location chan_allocation);
761 
762 /** @brief Audio direction from the perspective of the BAP Unicast Server / BAP Broadcast Sink */
763 enum bt_audio_dir {
764 	/**
765 	 * @brief Audio direction sink
766 	 *
767 	 * For a BAP Unicast Client or Broadcast Source this is considered outgoing audio (TX).
768 	 * For a BAP Unicast Server or Broadcast Sink this is considered incoming audio (RX).
769 	 */
770 	BT_AUDIO_DIR_SINK = 0x01,
771 	/**
772 	 * @brief Audio direction source
773 	 *
774 	 * For a BAP Unicast Client or Broadcast Source this is considered incoming audio (RX).
775 	 * For a BAP Unicast Server or Broadcast Sink this is considered outgoing audio (TX).
776 	 */
777 	BT_AUDIO_DIR_SOURCE = 0x02,
778 };
779 
780 /**
781  * @brief Helper to declare elements of bt_audio_codec_qos
782  *
783  * @param _interval SDU interval (usec)
784  * @param _framing Framing
785  * @param _phy Target PHY
786  * @param _sdu Maximum SDU Size
787  * @param _rtn Retransmission number
788  * @param _latency Maximum Transport Latency (msec)
789  * @param _pd Presentation Delay (usec)
790  */
791 #define BT_AUDIO_CODEC_QOS(_interval, _framing, _phy, _sdu, _rtn, _latency, _pd)                   \
792 	((struct bt_audio_codec_qos){                                                              \
793 		.interval = _interval,                                                             \
794 		.framing = _framing,                                                               \
795 		.phy = _phy,                                                                       \
796 		.sdu = _sdu,                                                                       \
797 		.rtn = _rtn,                                                                       \
798 		IF_ENABLED(UTIL_OR(IS_ENABLED(CONFIG_BT_BAP_BROADCAST_SOURCE),                     \
799 				   IS_ENABLED(CONFIG_BT_BAP_UNICAST)),                             \
800 			   (.latency = _latency,))                                                 \
801 		.pd = _pd,                                                                         \
802 	})
803 
804 /** @brief Codec QoS Framing */
805 enum bt_audio_codec_qos_framing {
806 	/** Packets may be framed or unframed */
807 	BT_AUDIO_CODEC_QOS_FRAMING_UNFRAMED = 0x00,
808 	/** Packets are always framed */
809 	BT_AUDIO_CODEC_QOS_FRAMING_FRAMED = 0x01,
810 };
811 
812 /** @brief Codec QoS Preferred PHY */
813 enum {
814 	/** LE 1M PHY */
815 	BT_AUDIO_CODEC_QOS_1M = BIT(0),
816 	/** LE 2M PHY */
817 	BT_AUDIO_CODEC_QOS_2M = BIT(1),
818 	/** LE Coded PHY */
819 	BT_AUDIO_CODEC_QOS_CODED = BIT(2),
820 };
821 
822 /**
823  * @brief Helper to declare Input Unframed bt_audio_codec_qos
824  *
825  * @param _interval SDU interval (usec)
826  * @param _sdu Maximum SDU Size
827  * @param _rtn Retransmission number
828  * @param _latency Maximum Transport Latency (msec)
829  * @param _pd Presentation Delay (usec)
830  */
831 #define BT_AUDIO_CODEC_QOS_UNFRAMED(_interval, _sdu, _rtn, _latency, _pd)                          \
832 	BT_AUDIO_CODEC_QOS(_interval, BT_AUDIO_CODEC_QOS_FRAMING_UNFRAMED, BT_AUDIO_CODEC_QOS_2M,  \
833 			   _sdu, _rtn, _latency, _pd)
834 
835 /**
836  * @brief Helper to declare Input Framed bt_audio_codec_qos
837  *
838  * @param _interval SDU interval (usec)
839  * @param _sdu Maximum SDU Size
840  * @param _rtn Retransmission number
841  * @param _latency Maximum Transport Latency (msec)
842  * @param _pd Presentation Delay (usec)
843  */
844 #define BT_AUDIO_CODEC_QOS_FRAMED(_interval, _sdu, _rtn, _latency, _pd)                            \
845 	BT_AUDIO_CODEC_QOS(_interval, BT_AUDIO_CODEC_QOS_FRAMING_FRAMED, BT_AUDIO_CODEC_QOS_2M,    \
846 			   _sdu, _rtn, _latency, _pd)
847 
848 /** @brief Codec QoS structure. */
849 struct bt_audio_codec_qos {
850 	/**
851 	 * @brief Presentation Delay in microseconds
852 	 *
853 	 * This value can be changed up and until bt_bap_stream_qos() has been called.
854 	 * Once a stream has been QoS configured, modifying this field does not modify the value.
855 	 * It is however possible to modify this field and call bt_bap_stream_qos() again to update
856 	 * the value, assuming that the stream is in the correct state.
857 	 *
858 	 * Value range 0 to @ref BT_AUDIO_PD_MAX.
859 	 */
860 	uint32_t pd;
861 
862 	/**
863 	 * @brief Connected Isochronous Group (CIG) parameters
864 	 *
865 	 * The fields in this struct affect the value sent to the controller via HCI
866 	 * when creating the CIG. Once the group has been created with
867 	 * bt_bap_unicast_group_create(), modifying these fields will not affect the group.
868 	 */
869 	struct {
870 		/** QoS Framing */
871 		enum bt_audio_codec_qos_framing framing;
872 
873 		/**
874 		 * @brief PHY
875 		 *
876 		 * Allowed values are @ref BT_AUDIO_CODEC_QOS_1M, @ref BT_AUDIO_CODEC_QOS_2M and
877 		 * @ref BT_AUDIO_CODEC_QOS_CODED.
878 		 */
879 		uint8_t phy;
880 
881 		/**
882 		 * @brief Retransmission Number
883 		 *
884 		 * This a recommendation to the controller, and the actual retransmission number
885 		 * may be different than this.
886 		 */
887 		uint8_t rtn;
888 
889 		/**
890 		 * @brief Maximum SDU size
891 		 *
892 		 * Value range @ref BT_ISO_MIN_SDU to @ref BT_ISO_MAX_SDU.
893 		 */
894 		uint16_t sdu;
895 
896 #if defined(CONFIG_BT_BAP_BROADCAST_SOURCE) || defined(CONFIG_BT_BAP_UNICAST) ||                   \
897 	defined(__DOXYGEN__)
898 		/**
899 		 * @brief Maximum Transport Latency
900 		 *
901 		 * Not used for the @kconfig{CONFIG_BT_BAP_BROADCAST_SINK} role.
902 		 */
903 		uint16_t latency;
904 #endif /*  CONFIG_BT_BAP_BROADCAST_SOURCE || CONFIG_BT_BAP_UNICAST */
905 
906 		/**
907 		 * @brief SDU Interval
908 		 *
909 		 * Value range @ref BT_ISO_SDU_INTERVAL_MIN to @ref BT_ISO_SDU_INTERVAL_MAX
910 		 */
911 		uint32_t interval;
912 
913 #if defined(CONFIG_BT_ISO_TEST_PARAMS) || defined(__DOXYGEN__)
914 		/**
915 		 * @brief Maximum PDU size
916 		 *
917 		 * Maximum size, in octets, of the payload from link layer to link layer.
918 		 *
919 		 *  Value range @ref BT_ISO_CONNECTED_PDU_MIN to @ref BT_ISO_PDU_MAX for
920 		 *  connected ISO.
921 		 *
922 		 *  Value range @ref BT_ISO_BROADCAST_PDU_MIN to @ref BT_ISO_PDU_MAX for
923 		 *  broadcast ISO.
924 		 */
925 		uint16_t max_pdu;
926 
927 		/**
928 		 * @brief Burst number
929 		 *
930 		 * Value range @ref BT_ISO_BN_MIN to @ref BT_ISO_BN_MAX.
931 		 */
932 		uint8_t burst_number;
933 
934 		/**
935 		 * @brief Number of subevents
936 		 *
937 		 * Maximum number of subevents in each CIS or BIS event.
938 		 *
939 		 * Value range @ref BT_ISO_NSE_MIN to @ref BT_ISO_NSE_MAX.
940 		 */
941 		uint8_t num_subevents;
942 #endif /* CONFIG_BT_ISO_TEST_PARAMS */
943 	};
944 };
945 
946 /**
947  * @brief Helper to declare elements of @ref bt_audio_codec_qos_pref
948  *
949  * @param _unframed_supported Unframed PDUs supported
950  * @param _phy Preferred Target PHY
951  * @param _rtn Preferred Retransmission number
952  * @param _latency Preferred Maximum Transport Latency (msec)
953  * @param _pd_min Minimum Presentation Delay (usec)
954  * @param _pd_max Maximum Presentation Delay (usec)
955  * @param _pref_pd_min Preferred Minimum Presentation Delay (usec)
956  * @param _pref_pd_max Preferred Maximum Presentation Delay (usec)
957  */
958 #define BT_AUDIO_CODEC_QOS_PREF(_unframed_supported, _phy, _rtn, _latency, _pd_min, _pd_max,       \
959 				_pref_pd_min, _pref_pd_max)                                        \
960 	{                                                                                          \
961 		.unframed_supported = _unframed_supported,                                         \
962 		.phy = _phy,                                                                       \
963 		.rtn = _rtn,                                                                       \
964 		.latency = _latency,                                                               \
965 		.pd_min = _pd_min,                                                                 \
966 		.pd_max = _pd_max,                                                                 \
967 		.pref_pd_min = _pref_pd_min,                                                       \
968 		.pref_pd_max = _pref_pd_max,                                                       \
969 	}
970 
971 /** @brief Audio Stream Quality of Service Preference structure. */
972 struct bt_audio_codec_qos_pref {
973 	/**
974 	 * @brief Unframed PDUs supported
975 	 *
976 	 *  Unlike the other fields, this is not a preference but whether
977 	 *  the codec supports unframed ISOAL PDUs.
978 	 */
979 	bool unframed_supported;
980 
981 	/** Preferred PHY */
982 	uint8_t phy;
983 
984 	/** Preferred Retransmission Number */
985 	uint8_t rtn;
986 
987 	/** Preferred Transport Latency */
988 	uint16_t latency;
989 
990 	/**
991 	 * @brief Minimum Presentation Delay in microseconds
992 	 *
993 	 * Unlike the other fields, this is not a preference but a minimum requirement.
994 	 *
995 	 * Value range 0 to @ref BT_AUDIO_PD_MAX, or @ref BT_AUDIO_PD_PREF_NONE
996 	 * to indicate no preference.
997 	 */
998 	uint32_t pd_min;
999 
1000 	/**
1001 	 * @brief Maximum Presentation Delay
1002 	 *
1003 	 * Unlike the other fields, this is not a preference but a maximum requirement.
1004 	 *
1005 	 * Value range 0 to @ref BT_AUDIO_PD_MAX, or @ref BT_AUDIO_PD_PREF_NONE
1006 	 * to indicate no preference.
1007 	 */
1008 	uint32_t pd_max;
1009 
1010 	/**
1011 	 * @brief Preferred minimum Presentation Delay
1012 	 *
1013 	 * Value range 0 to @ref BT_AUDIO_PD_MAX.
1014 	 */
1015 	uint32_t pref_pd_min;
1016 
1017 	/**
1018 	 * @brief Preferred maximum Presentation Delay
1019 	 *
1020 	 * Value range 0 to @ref BT_AUDIO_PD_MAX.
1021 	 */
1022 	uint32_t pref_pd_max;
1023 };
1024 
1025 /**
1026  * @brief Audio codec Config APIs
1027  * @defgroup bt_audio_codec_cfg Codec config parsing APIs
1028  *
1029  * Functions to parse codec config data when formatted as LTV wrapped into @ref bt_audio_codec_cfg.
1030  *
1031  * @{
1032  */
1033 
1034 /**
1035  * @brief Convert assigned numbers frequency to frequency value.
1036  *
1037  * @param freq The assigned numbers frequency to convert.
1038  *
1039  * @retval -EINVAL if arguments are invalid.
1040  * @retval The converted frequency value in Hz.
1041  */
1042 int bt_audio_codec_cfg_freq_to_freq_hz(enum bt_audio_codec_cfg_freq freq);
1043 
1044 /**
1045  * @brief Convert frequency value to assigned numbers frequency.
1046  *
1047  * @param freq_hz The frequency value to convert.
1048  *
1049  * @retval -EINVAL if arguments are invalid.
1050  * @retval The assigned numbers frequency (@ref bt_audio_codec_cfg_freq).
1051  */
1052 int bt_audio_codec_cfg_freq_hz_to_freq(uint32_t freq_hz);
1053 
1054 /**
1055  * @brief Extract the frequency from a codec configuration.
1056  *
1057  * @param codec_cfg The codec configuration to extract data from.
1058  *
1059  * @retval A @ref bt_audio_codec_cfg_freq value
1060  * @retval -EINVAL if arguments are invalid
1061  * @retval -ENODATA if not found
1062  * @retval -EBADMSG if found value has invalid size or value
1063  */
1064 int bt_audio_codec_cfg_get_freq(const struct bt_audio_codec_cfg *codec_cfg);
1065 
1066 /**
1067  * @brief Set the frequency of a codec configuration.
1068  *
1069  * @param codec_cfg The codec configuration to set data for.
1070  * @param freq      The assigned numbers frequency to set.
1071  *
1072  * @retval The data_len of @p codec_cfg on success
1073  * @retval -EINVAL if arguments are invalid
1074  * @retval -ENOMEM if the new value could not set or added due to memory
1075  */
1076 int bt_audio_codec_cfg_set_freq(struct bt_audio_codec_cfg *codec_cfg,
1077 				enum bt_audio_codec_cfg_freq freq);
1078 
1079 /**
1080  * @brief Convert assigned numbers frame duration to duration in microseconds.
1081  *
1082  * @param frame_dur The assigned numbers frame duration to convert.
1083  *
1084  * @retval -EINVAL if arguments are invalid.
1085  * @retval The converted frame duration value in microseconds.
1086  */
1087 int bt_audio_codec_cfg_frame_dur_to_frame_dur_us(enum bt_audio_codec_cfg_frame_dur frame_dur);
1088 
1089 /**
1090  * @brief Convert frame duration in microseconds to assigned numbers frame duration.
1091  *
1092  * @param frame_dur_us The frame duration in microseconds to convert.
1093  *
1094  * @retval -EINVAL if arguments are invalid.
1095  * @retval The assigned numbers frame duration (@ref bt_audio_codec_cfg_frame_dur).
1096  */
1097 int bt_audio_codec_cfg_frame_dur_us_to_frame_dur(uint32_t frame_dur_us);
1098 
1099 /**
1100  * @brief Extract frame duration from BT codec config
1101  *
1102  * @param codec_cfg The codec configuration to extract data from.
1103  *
1104  * @retval A @ref bt_audio_codec_cfg_frame_dur value
1105  * @retval -EINVAL if arguments are invalid
1106  * @retval -ENODATA if not found
1107  * @retval -EBADMSG if found value has invalid size or value
1108  */
1109 int bt_audio_codec_cfg_get_frame_dur(const struct bt_audio_codec_cfg *codec_cfg);
1110 
1111 /**
1112  * @brief Set the frame duration of a codec configuration.
1113  *
1114  * @param codec_cfg  The codec configuration to set data for.
1115  * @param frame_dur  The assigned numbers frame duration to set.
1116  *
1117  * @retval The data_len of @p codec_cfg on success
1118  * @retval -EINVAL if arguments are invalid
1119  * @retval -ENOMEM if the new value could not set or added due to memory
1120  */
1121 int bt_audio_codec_cfg_set_frame_dur(struct bt_audio_codec_cfg *codec_cfg,
1122 				     enum bt_audio_codec_cfg_frame_dur frame_dur);
1123 
1124 /**
1125  * @brief Extract channel allocation from BT codec config
1126  *
1127  * The value returned is a bit field representing one or more audio locations as
1128  * specified by @ref bt_audio_location
1129  * Shall match one or more of the bits set in BT_PAC_SNK_LOC/BT_PAC_SRC_LOC.
1130  *
1131  * Up to the configured @ref BT_AUDIO_CODEC_CAP_TYPE_CHAN_COUNT number of channels can be present.
1132  *
1133  * @param codec_cfg The codec configuration to extract data from.
1134  * @param chan_allocation Pointer to the variable to store the extracted value in.
1135  * @param fallback_to_default If true this function will provide the default value of
1136  *        @ref BT_AUDIO_LOCATION_MONO_AUDIO if the type is not found when @p codec_cfg.id is @ref
1137  *        BT_HCI_CODING_FORMAT_LC3.
1138  *
1139  * @retval 0 if value is found and stored in the pointer provided
1140  * @retval -EINVAL if arguments are invalid
1141  * @retval -ENODATA if not found
1142  * @retval -EBADMSG if found value has invalid size or value
1143  */
1144 int bt_audio_codec_cfg_get_chan_allocation(const struct bt_audio_codec_cfg *codec_cfg,
1145 					   enum bt_audio_location *chan_allocation,
1146 					   bool fallback_to_default);
1147 
1148 /**
1149  * @brief Set the channel allocation of a codec configuration.
1150  *
1151  * @param codec_cfg       The codec configuration to set data for.
1152  * @param chan_allocation The channel allocation to set.
1153  *
1154  * @retval The data_len of @p codec_cfg on success
1155  * @retval -EINVAL if arguments are invalid
1156  * @retval -ENOMEM if the new value could not set or added due to memory
1157  */
1158 int bt_audio_codec_cfg_set_chan_allocation(struct bt_audio_codec_cfg *codec_cfg,
1159 					   enum bt_audio_location chan_allocation);
1160 
1161 /**
1162  * @brief Extract frame size in octets from BT codec config
1163  *
1164  * The overall SDU size will be octets_per_frame * blocks_per_sdu.
1165  *
1166  * The Bluetooth specifications are not clear about this value - it does not state that
1167  * the codec shall use this SDU size only. A codec like LC3 supports variable bit-rate
1168  * (per SDU) hence it might be allowed for an encoder to reduce the frame size below this
1169  * value.
1170  * Hence it is recommended to use the received SDU size and divide by
1171  * blocks_per_sdu rather than relying on this octets_per_sdu value to be fixed.
1172  *
1173  * @param codec_cfg The codec configuration to extract data from.
1174  *
1175  * @retval Frame length in octets
1176  * @retval -EINVAL if arguments are invalid
1177  * @retval -ENODATA if not found
1178  * @retval -EBADMSG if found value has invalid size or value
1179  */
1180 int bt_audio_codec_cfg_get_octets_per_frame(const struct bt_audio_codec_cfg *codec_cfg);
1181 
1182 /**
1183  * @brief Set the octets per codec frame of a codec configuration.
1184  *
1185  * @param codec_cfg        The codec configuration to set data for.
1186  * @param octets_per_frame The octets per codec frame to set.
1187  *
1188  * @retval The data_len of @p codec_cfg on success
1189  * @retval -EINVAL if arguments are invalid
1190  * @retval -ENOMEM if the new value could not set or added due to memory
1191  */
1192 int bt_audio_codec_cfg_set_octets_per_frame(struct bt_audio_codec_cfg *codec_cfg,
1193 					    uint16_t octets_per_frame);
1194 
1195 /**
1196  * @brief Extract number of audio frame blocks in each SDU from BT codec config
1197  *
1198  * The overall SDU size will be octets_per_frame * frame_blocks_per_sdu * number-of-channels.
1199  *
1200  * If this value is not present a default value of 1 shall be used.
1201  *
1202  * A frame block is one or more frames that represents data for the same period of time but
1203  * for different channels. If the stream have two audio channels and this value is two
1204  * there will be four frames in the SDU.
1205  *
1206  * @param codec_cfg The codec configuration to extract data from.
1207  * @param fallback_to_default If true this function will return the default value of 1
1208  *         if the type is not found when @p codec_cfg.id is @ref BT_HCI_CODING_FORMAT_LC3.
1209  *
1210  * @retval The count of codec frame blocks in each SDU.
1211  * @retval -EINVAL if arguments are invalid
1212  * @retval -ENODATA if not found
1213  * @retval -EBADMSG if found value has invalid size or value
1214  */
1215 int bt_audio_codec_cfg_get_frame_blocks_per_sdu(const struct bt_audio_codec_cfg *codec_cfg,
1216 						bool fallback_to_default);
1217 
1218 /**
1219  * @brief Set the frame blocks per SDU of a codec configuration.
1220  *
1221  * @param codec_cfg    The codec configuration to set data for.
1222  * @param frame_blocks The frame blocks per SDU to set.
1223  *
1224  * @retval The data_len of @p codec_cfg on success
1225  * @retval -EINVAL if arguments are invalid
1226  * @retval -ENOMEM if the new value could not set or added due to memory
1227  */
1228 int bt_audio_codec_cfg_set_frame_blocks_per_sdu(struct bt_audio_codec_cfg *codec_cfg,
1229 						uint8_t frame_blocks);
1230 
1231 /**
1232  * @brief Lookup a specific codec configuration value
1233  *
1234  * @param[in] codec_cfg The codec data to search in.
1235  * @param[in] type The type id to look for
1236  * @param[out] data Pointer to the data-pointer to update when item is found
1237  *
1238  * @retval Length of found @p data (may be 0)
1239  * @retval -EINVAL if arguments are invalid
1240  * @retval -ENODATA if not found
1241  */
1242 int bt_audio_codec_cfg_get_val(const struct bt_audio_codec_cfg *codec_cfg,
1243 			       enum bt_audio_codec_cfg_type type, const uint8_t **data);
1244 
1245 /**
1246  * @brief Set or add a specific codec configuration value
1247  *
1248  * @param codec_cfg  The codec data to set the value in.
1249  * @param type       The type id to set
1250  * @param data       Pointer to the data-pointer to set
1251  * @param data_len   Length of @p data
1252  *
1253  * @retval The data_len of @p codec_cfg on success
1254  * @retval -EINVAL if arguments are invalid
1255  * @retval -ENOMEM if the new value could not set or added due to memory
1256  */
1257 int bt_audio_codec_cfg_set_val(struct bt_audio_codec_cfg *codec_cfg,
1258 			       enum bt_audio_codec_cfg_type type, const uint8_t *data,
1259 			       size_t data_len);
1260 
1261 /**
1262  * @brief Unset a specific codec configuration value
1263  *
1264  * The type and the value will be removed from the codec configuration.
1265  *
1266  * @param codec_cfg  The codec data to set the value in.
1267  * @param type       The type id to unset.
1268  *
1269  * @retval The data_len of @p codec_cfg on success
1270  * @retval -EINVAL if arguments are invalid
1271  */
1272 int bt_audio_codec_cfg_unset_val(struct bt_audio_codec_cfg *codec_cfg,
1273 				 enum bt_audio_codec_cfg_type type);
1274 
1275 /**
1276  * @brief Lookup a specific metadata value based on type
1277  *
1278  *
1279  * @param[in]  codec_cfg The codec data to search in.
1280  * @param[in]  type      The type id to look for
1281  * @param[out] data      Pointer to the data-pointer to update when item is found
1282  *
1283  * @retval Length of found @p data (may be 0)
1284  * @retval -EINVAL if arguments are invalid
1285  * @retval -ENODATA if not found
1286  */
1287 int bt_audio_codec_cfg_meta_get_val(const struct bt_audio_codec_cfg *codec_cfg, uint8_t type,
1288 				    const uint8_t **data);
1289 
1290 /**
1291  * @brief Set or add a specific codec configuration metadata value.
1292  *
1293  * @param codec_cfg  The codec configuration to set the value in.
1294  * @param type       The type id to set.
1295  * @param data       Pointer to the data-pointer to set.
1296  * @param data_len   Length of @p data.
1297  *
1298  * @retval The meta_len of @p codec_cfg on success
1299  * @retval -EINVAL if arguments are invalid
1300  * @retval -ENOMEM if the new value could not set or added due to memory
1301  */
1302 int bt_audio_codec_cfg_meta_set_val(struct bt_audio_codec_cfg *codec_cfg,
1303 				    enum bt_audio_metadata_type type, const uint8_t *data,
1304 				    size_t data_len);
1305 
1306 /**
1307  * @brief Unset a specific codec configuration metadata value
1308  *
1309  * The type and the value will be removed from the codec configuration metadata.
1310  *
1311  * @param codec_cfg  The codec data to set the value in.
1312  * @param type       The type id to unset.
1313  *
1314  * @retval The meta_len of @p codec_cfg on success
1315  * @retval -EINVAL if arguments are invalid
1316  */
1317 int bt_audio_codec_cfg_meta_unset_val(struct bt_audio_codec_cfg *codec_cfg,
1318 				      enum bt_audio_metadata_type type);
1319 /**
1320  * @brief Extract preferred contexts
1321  *
1322  * See @ref BT_AUDIO_METADATA_TYPE_PREF_CONTEXT for more information about this value.
1323  *
1324  * @param codec_cfg The codec data to search in.
1325  * @param fallback_to_default If true this function will provide the default value of
1326  *        @ref BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED if the type is not found when @p codec_cfg.id is
1327  *        @ref BT_HCI_CODING_FORMAT_LC3.
1328  *
1329  * @retval The preferred context type if positive or 0
1330  * @retval -EINVAL if arguments are invalid
1331  * @retval -ENODATA if not found
1332  * @retval -EBADMSG if found value has invalid size
1333  */
1334 int bt_audio_codec_cfg_meta_get_pref_context(const struct bt_audio_codec_cfg *codec_cfg,
1335 					     bool fallback_to_default);
1336 
1337 /**
1338  * @brief Set the preferred context of a codec configuration metadata.
1339  *
1340  * @param codec_cfg The codec configuration to set data for.
1341  * @param ctx       The preferred context to set.
1342  *
1343  * @retval The data_len of @p codec_cfg on success
1344  * @retval -EINVAL if arguments are invalid
1345  * @retval -ENOMEM if the new value could not set or added due to memory
1346  */
1347 int bt_audio_codec_cfg_meta_set_pref_context(struct bt_audio_codec_cfg *codec_cfg,
1348 					     enum bt_audio_context ctx);
1349 
1350 /**
1351  * @brief Extract stream contexts
1352  *
1353  * See @ref BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT for more information about this value.
1354  *
1355  * @param codec_cfg The codec data to search in.
1356  *
1357  * @retval The stream context type if positive or 0
1358  * @retval -EINVAL if arguments are invalid
1359  * @retval -ENODATA if not found
1360  * @retval -EBADMSG if found value has invalid size
1361  */
1362 int bt_audio_codec_cfg_meta_get_stream_context(const struct bt_audio_codec_cfg *codec_cfg);
1363 
1364 /**
1365  * @brief Set the stream context of a codec configuration metadata.
1366  *
1367  * @param codec_cfg The codec configuration to set data for.
1368  * @param ctx       The stream context to set.
1369  *
1370  * @retval The data_len of @p codec_cfg on success
1371  * @retval -EINVAL if arguments are invalid
1372  * @retval -ENOMEM if the new value could not set or added due to memory
1373  */
1374 int bt_audio_codec_cfg_meta_set_stream_context(struct bt_audio_codec_cfg *codec_cfg,
1375 					       enum bt_audio_context ctx);
1376 
1377 /**
1378  * @brief Extract program info
1379  *
1380  * See @ref BT_AUDIO_METADATA_TYPE_PROGRAM_INFO for more information about this value.
1381  *
1382  * @param[in]  codec_cfg    The codec data to search in.
1383  * @param[out] program_info Pointer to the UTF-8 formatted program info.
1384  *
1385  * @retval The length of the @p program_info (may be 0)
1386  * @retval -EINVAL if arguments are invalid
1387  * @retval -ENODATA if not found
1388  */
1389 int bt_audio_codec_cfg_meta_get_program_info(const struct bt_audio_codec_cfg *codec_cfg,
1390 					     const uint8_t **program_info);
1391 
1392 /**
1393  * @brief Set the program info of a codec configuration metadata.
1394  *
1395  * @param codec_cfg        The codec configuration to set data for.
1396  * @param program_info     The program info to set.
1397  * @param program_info_len The length of @p program_info.
1398  *
1399  * @retval The data_len of @p codec_cfg on success
1400  * @retval -EINVAL if arguments are invalid
1401  * @retval -ENOMEM if the new value could not set or added due to memory
1402  */
1403 int bt_audio_codec_cfg_meta_set_program_info(struct bt_audio_codec_cfg *codec_cfg,
1404 					     const uint8_t *program_info, size_t program_info_len);
1405 
1406 /**
1407  * @brief Extract language
1408  *
1409  * See @ref BT_AUDIO_METADATA_TYPE_LANG for more information about this value.
1410  *
1411  * @param[in]  codec_cfg The codec data to search in.
1412  * @param[out] lang      Pointer to the language bytes (of length BT_AUDIO_LANG_SIZE)
1413  *
1414  * @retval The language if positive or 0
1415  * @retval -EINVAL if arguments are invalid
1416  * @retval -ENODATA if not found
1417  * @retval -EBADMSG if found value has invalid size
1418  */
1419 int bt_audio_codec_cfg_meta_get_lang(const struct bt_audio_codec_cfg *codec_cfg,
1420 				     const uint8_t **lang);
1421 
1422 /**
1423  * @brief Set the language of a codec configuration metadata.
1424  *
1425  * @param codec_cfg   The codec configuration to set data for.
1426  * @param lang        The 24-bit language to set.
1427  *
1428  * @retval The data_len of @p codec_cfg on success
1429  * @retval -EINVAL if arguments are invalid
1430  * @retval -ENOMEM if the new value could not set or added due to memory
1431  */
1432 int bt_audio_codec_cfg_meta_set_lang(struct bt_audio_codec_cfg *codec_cfg,
1433 				     const uint8_t lang[BT_AUDIO_LANG_SIZE]);
1434 
1435 /**
1436  * @brief Extract CCID list
1437  *
1438  * See @ref BT_AUDIO_METADATA_TYPE_CCID_LIST for more information about this value.
1439  *
1440  * @param[in]  codec_cfg The codec data to search in.
1441  * @param[out] ccid_list Pointer to the array containing 8-bit CCIDs.
1442  *
1443  * @retval The length of the @p ccid_list (may be 0)
1444  * @retval -EINVAL if arguments are invalid
1445  * @retval -ENODATA if not found
1446  */
1447 int bt_audio_codec_cfg_meta_get_ccid_list(const struct bt_audio_codec_cfg *codec_cfg,
1448 					  const uint8_t **ccid_list);
1449 
1450 /**
1451  * @brief Set the CCID list of a codec configuration metadata.
1452  *
1453  * @param codec_cfg     The codec configuration to set data for.
1454  * @param ccid_list     The program info to set.
1455  * @param ccid_list_len The length of @p ccid_list.
1456  *
1457  * @retval The data_len of @p codec_cfg on success
1458  * @retval -EINVAL if arguments are invalid
1459  * @retval -ENOMEM if the new value could not set or added due to memory
1460  */
1461 int bt_audio_codec_cfg_meta_set_ccid_list(struct bt_audio_codec_cfg *codec_cfg,
1462 					  const uint8_t *ccid_list, size_t ccid_list_len);
1463 
1464 /**
1465  * @brief Extract parental rating
1466  *
1467  * See @ref BT_AUDIO_METADATA_TYPE_PARENTAL_RATING for more information about this value.
1468  *
1469  * @param codec_cfg The codec data to search in.
1470  *
1471  * @retval The parental rating if positive or 0
1472  * @retval -EINVAL if arguments are invalid
1473  * @retval -ENODATA if not found
1474  * @retval -EBADMSG if found value has invalid size
1475  */
1476 int bt_audio_codec_cfg_meta_get_parental_rating(const struct bt_audio_codec_cfg *codec_cfg);
1477 
1478 /**
1479  * @brief Set the parental rating of a codec configuration metadata.
1480  *
1481  * @param codec_cfg       The codec configuration to set data for.
1482  * @param parental_rating The parental rating to set.
1483  *
1484  * @retval The data_len of @p codec_cfg on success
1485  * @retval -EINVAL if arguments are invalid
1486  * @retval -ENOMEM if the new value could not set or added due to memory
1487  */
1488 int bt_audio_codec_cfg_meta_set_parental_rating(struct bt_audio_codec_cfg *codec_cfg,
1489 						enum bt_audio_parental_rating parental_rating);
1490 
1491 /**
1492  * @brief Extract program info URI
1493  *
1494  * See @ref BT_AUDIO_METADATA_TYPE_PROGRAM_INFO_URI for more information about this value.
1495  *
1496  * @param[in]  codec_cfg The codec data to search in.
1497  * @param[out] program_info_uri Pointer to the UTF-8 formatted program info URI.
1498  *
1499  * @retval The length of the @p ccid_list (may be 0)
1500  * @retval -EINVAL if arguments are invalid
1501  * @retval -ENODATA if not found
1502  */
1503 int bt_audio_codec_cfg_meta_get_program_info_uri(const struct bt_audio_codec_cfg *codec_cfg,
1504 						 const uint8_t **program_info_uri);
1505 
1506 /**
1507  * @brief Set the program info URI of a codec configuration metadata.
1508  *
1509  * @param codec_cfg            The codec configuration to set data for.
1510  * @param program_info_uri     The program info URI to set.
1511  * @param program_info_uri_len The length of @p program_info_uri.
1512  *
1513  * @retval The data_len of @p codec_cfg on success
1514  * @retval -EINVAL if arguments are invalid
1515  * @retval -ENOMEM if the new value could not set or added due to memory
1516  */
1517 int bt_audio_codec_cfg_meta_set_program_info_uri(struct bt_audio_codec_cfg *codec_cfg,
1518 						 const uint8_t *program_info_uri,
1519 						 size_t program_info_uri_len);
1520 
1521 /**
1522  * @brief Extract audio active state
1523  *
1524  * See @ref BT_AUDIO_METADATA_TYPE_AUDIO_STATE for more information about this value.
1525  *
1526  * @param codec_cfg The codec data to search in.
1527  *
1528  * @retval The preferred context type if positive or 0
1529  * @retval -EINVAL if arguments are invalid
1530  * @retval -ENODATA if not found
1531  * @retval -EBADMSG if found value has invalid size
1532  */
1533 int bt_audio_codec_cfg_meta_get_audio_active_state(const struct bt_audio_codec_cfg *codec_cfg);
1534 
1535 /**
1536  * @brief Set the audio active state of a codec configuration metadata.
1537  *
1538  * @param codec_cfg The codec configuration to set data for.
1539  * @param state     The audio active state to set.
1540  *
1541  * @retval The data_len of @p codec_cfg on success
1542  * @retval -EINVAL if arguments are invalid
1543  * @retval -ENOMEM if the new value could not set or added due to memory
1544  */
1545 int bt_audio_codec_cfg_meta_set_audio_active_state(struct bt_audio_codec_cfg *codec_cfg,
1546 						   enum bt_audio_active_state state);
1547 
1548 /**
1549  * @brief Extract broadcast audio immediate rendering flag
1550  *
1551  * See @ref BT_AUDIO_METADATA_TYPE_BROADCAST_IMMEDIATE for more information about this value.
1552  *
1553  * @param codec_cfg The codec data to search in.
1554  *
1555  * @retval 0 if the flag was found
1556  * @retval -EINVAL if arguments are invalid
1557  * @retval -ENODATA if not the flag was not found
1558  */
1559 int bt_audio_codec_cfg_meta_get_bcast_audio_immediate_rend_flag(
1560 	const struct bt_audio_codec_cfg *codec_cfg);
1561 
1562 /**
1563  * @brief Set the broadcast audio immediate rendering flag of a codec configuration metadata.
1564  *
1565  * @param codec_cfg The codec configuration to set data for.
1566  *
1567  * @retval The data_len of @p codec_cfg on success
1568  * @retval -EINVAL if arguments are invalid
1569  * @retval -ENOMEM if the new value could not set or added due to memory
1570  */
1571 int bt_audio_codec_cfg_meta_set_bcast_audio_immediate_rend_flag(
1572 	struct bt_audio_codec_cfg *codec_cfg);
1573 
1574 /**
1575  * @brief Extract extended metadata
1576  *
1577  * See @ref BT_AUDIO_METADATA_TYPE_EXTENDED for more information about this value.
1578  *
1579  * @param[in]  codec_cfg     The codec data to search in.
1580  * @param[out] extended_meta Pointer to the extended metadata.
1581  *
1582  * @retval The length of the @p ccid_list (may be 0)
1583  * @retval -EINVAL if arguments are invalid
1584  * @retval -ENODATA if not found
1585  */
1586 int bt_audio_codec_cfg_meta_get_extended(const struct bt_audio_codec_cfg *codec_cfg,
1587 					 const uint8_t **extended_meta);
1588 
1589 /**
1590  * @brief Set the extended metadata of a codec configuration metadata.
1591  *
1592  * @param codec_cfg         The codec configuration to set data for.
1593  * @param extended_meta     The extended metadata to set.
1594  * @param extended_meta_len The length of @p extended_meta.
1595  *
1596  * @retval The data_len of @p codec_cfg on success
1597  * @retval -EINVAL if arguments are invalid
1598  * @retval -ENOMEM if the new value could not set or added due to memory
1599  */
1600 int bt_audio_codec_cfg_meta_set_extended(struct bt_audio_codec_cfg *codec_cfg,
1601 					 const uint8_t *extended_meta, size_t extended_meta_len);
1602 
1603 /**
1604  * @brief Extract vendor specific metadata
1605  *
1606  * See @ref BT_AUDIO_METADATA_TYPE_VENDOR for more information about this value.
1607  *
1608  * @param[in]  codec_cfg   The codec data to search in.
1609  * @param[out] vendor_meta Pointer to the vendor specific metadata.
1610  *
1611  * @retval The length of the @p ccid_list (may be 0)
1612  * @retval -EINVAL if arguments are invalid
1613  * @retval -ENODATA if not found
1614  */
1615 int bt_audio_codec_cfg_meta_get_vendor(const struct bt_audio_codec_cfg *codec_cfg,
1616 				       const uint8_t **vendor_meta);
1617 
1618 /**
1619  * @brief Set the vendor specific metadata of a codec configuration metadata.
1620  *
1621  * @param codec_cfg       The codec configuration to set data for.
1622  * @param vendor_meta     The vendor specific metadata to set.
1623  * @param vendor_meta_len The length of @p vendor_meta.
1624  *
1625  * @retval The data_len of @p codec_cfg on success
1626  * @retval -EINVAL if arguments are invalid
1627  * @retval -ENOMEM if the new value could not set or added due to memory
1628  */
1629 int bt_audio_codec_cfg_meta_set_vendor(struct bt_audio_codec_cfg *codec_cfg,
1630 				       const uint8_t *vendor_meta, size_t vendor_meta_len);
1631 /** @} */ /* End of bt_audio_codec_cfg */
1632 
1633 /**
1634  * @brief Audio codec capabilities APIs
1635  * @defgroup bt_audio_codec_cap Codec capability parsing APIs
1636  *
1637  * Functions to parse codec capability data when formatted as LTV wrapped into @ref
1638  * bt_audio_codec_cap.
1639  *
1640  * @{
1641  */
1642 
1643 /**
1644  * @brief Lookup a specific value based on type
1645  *
1646  * @param[in]  codec_cap The codec data to search in.
1647  * @param[in]  type The type id to look for
1648  * @param[out] data Pointer to the data-pointer to update when item is found
1649  *
1650  * @retval Length of found @p data (may be 0)
1651  * @retval -EINVAL if arguments are invalid
1652  * @retval -ENODATA if not found
1653  */
1654 int bt_audio_codec_cap_get_val(const struct bt_audio_codec_cap *codec_cap,
1655 			       enum bt_audio_codec_cap_type type, const uint8_t **data);
1656 
1657 /**
1658  * @brief Set or add a specific codec capability value
1659  *
1660  * @param codec_cap  The codec data to set the value in.
1661  * @param type       The type id to set
1662  * @param data       Pointer to the data-pointer to set
1663  * @param data_len   Length of @p data
1664  *
1665  * @retval The data_len of @p codec_cap on success
1666  * @retval -EINVAL if arguments are invalid
1667  * @retval -ENOMEM if the new value could not set or added due to memory
1668  */
1669 int bt_audio_codec_cap_set_val(struct bt_audio_codec_cap *codec_cap,
1670 			       enum bt_audio_codec_cap_type type, const uint8_t *data,
1671 			       size_t data_len);
1672 
1673 /**
1674  * @brief Unset a specific codec capability value
1675  *
1676  * The type and the value will be removed from the codec capability.
1677  *
1678  * @param codec_cap  The codec data to set the value in.
1679  * @param type       The type id to unset.
1680  *
1681  * @retval The data_len of @p codec_cap on success
1682  * @retval -EINVAL if arguments are invalid
1683  */
1684 int bt_audio_codec_cap_unset_val(struct bt_audio_codec_cap *codec_cap,
1685 				 enum bt_audio_codec_cap_type type);
1686 
1687 /**
1688  * @brief Extract the frequency from a codec capability.
1689  *
1690  * @param codec_cap The codec capabilities to extract data from.
1691  *
1692  * @retval Bitfield of supported frequencies (@ref bt_audio_codec_cap_freq) if 0 or positive
1693  * @retval -EINVAL if arguments are invalid
1694  * @retval -ENODATA if not found
1695  * @retval -EBADMSG if found value has invalid size or value
1696  */
1697 int bt_audio_codec_cap_get_freq(const struct bt_audio_codec_cap *codec_cap);
1698 
1699 /**
1700  * @brief Set the supported frequencies of a codec capability.
1701  *
1702  * @param codec_cap The codec capabilities to set data for.
1703  * @param freq      The supported frequencies to set.
1704  *
1705  * @retval The data_len of @p codec_cap on success
1706  * @retval -EINVAL if arguments are invalid
1707  * @retval -ENOMEM if the new value could not set or added due to memory
1708  */
1709 int bt_audio_codec_cap_set_freq(struct bt_audio_codec_cap *codec_cap,
1710 				enum bt_audio_codec_cap_freq freq);
1711 
1712 /**
1713  * @brief Extract the frequency from a codec capability.
1714  *
1715  * @param codec_cap The codec capabilities to extract data from.
1716  *
1717  * @retval Bitfield of supported frame durations if 0 or positive
1718  * @retval -EINVAL if arguments are invalid
1719  * @retval -ENODATA if not found
1720  * @retval -EBADMSG if found value has invalid size or value
1721  */
1722 int bt_audio_codec_cap_get_frame_dur(const struct bt_audio_codec_cap *codec_cap);
1723 
1724 /**
1725  * @brief Set the frame duration of a codec capability.
1726  *
1727  * @param codec_cap The codec capabilities to set data for.
1728  * @param frame_dur The frame duration to set.
1729  *
1730  * @retval The data_len of @p codec_cap on success
1731  * @retval -EINVAL if arguments are invalid
1732  * @retval -ENOMEM if the new value could not set or added due to memory
1733  */
1734 int bt_audio_codec_cap_set_frame_dur(struct bt_audio_codec_cap *codec_cap,
1735 				     enum bt_audio_codec_cap_frame_dur frame_dur);
1736 
1737 /**
1738  * @brief Extract the frequency from a codec capability.
1739  *
1740  * @param codec_cap The codec capabilities to extract data from.
1741  * @param fallback_to_default If true this function will provide the default value of 1
1742  *        if the type is not found when @p codec_cap.id is @ref BT_HCI_CODING_FORMAT_LC3.
1743  *
1744  * @retval Number of supported channel counts if 0 or positive
1745  * @retval -EINVAL if arguments are invalid
1746  * @retval -ENODATA if not found
1747  * @retval -EBADMSG if found value has invalid size or value
1748  */
1749 int bt_audio_codec_cap_get_supported_audio_chan_counts(const struct bt_audio_codec_cap *codec_cap,
1750 						       bool fallback_to_default);
1751 
1752 /**
1753  * @brief Set the channel count of a codec capability.
1754  *
1755  * @param codec_cap The codec capabilities to set data for.
1756  * @param chan_count The channel count frequency to set.
1757  *
1758  * @retval The data_len of @p codec_cap on success
1759  * @retval -EINVAL if arguments are invalid
1760  * @retval -ENOMEM if the new value could not set or added due to memory
1761  */
1762 int bt_audio_codec_cap_set_supported_audio_chan_counts(
1763 	struct bt_audio_codec_cap *codec_cap, enum bt_audio_codec_cap_chan_count chan_count);
1764 
1765 /**
1766  * @brief Extract the supported octets per codec frame from a codec capability.
1767  *
1768  * @param[in]  codec_cap   The codec capabilities to extract data from.
1769  * @param[out] codec_frame Struct to place the resulting values in
1770  *
1771  * @retval 0 on success
1772  * @retval -EINVAL if arguments are invalid
1773  * @retval -ENODATA if not found
1774  * @retval -EBADMSG if found value has invalid size or value
1775  */
1776 int bt_audio_codec_cap_get_octets_per_frame(
1777 	const struct bt_audio_codec_cap *codec_cap,
1778 	struct bt_audio_codec_octets_per_codec_frame *codec_frame);
1779 
1780 /**
1781  * @brief Set the octets per codec frame of a codec capability.
1782  *
1783  * @param codec_cap   The codec capabilities to set data for.
1784  * @param codec_frame The octets per codec frame to set.
1785  *
1786  * @retval The data_len of @p codec_cap on success
1787  * @retval -EINVAL if arguments are invalid
1788  * @retval -ENOMEM if the new value could not set or added due to memory
1789  */
1790 int bt_audio_codec_cap_set_octets_per_frame(
1791 	struct bt_audio_codec_cap *codec_cap,
1792 	const struct bt_audio_codec_octets_per_codec_frame *codec_frame);
1793 
1794 /**
1795  * @brief Extract the maximum codec frames per SDU from a codec capability.
1796  *
1797  * @param codec_cap The codec capabilities to extract data from.
1798  * @param fallback_to_default If true this function will provide the default value of 1
1799  *        if the type is not found when @p codec_cap.id is @ref BT_HCI_CODING_FORMAT_LC3.
1800  *
1801  * @retval Maximum number of codec frames per SDU supported
1802  * @retval -EINVAL if arguments are invalid
1803  * @retval -ENODATA if not found
1804  * @retval -EBADMSG if found value has invalid size or value
1805  */
1806 int bt_audio_codec_cap_get_max_codec_frames_per_sdu(const struct bt_audio_codec_cap *codec_cap,
1807 						    bool fallback_to_default);
1808 
1809 /**
1810  * @brief Set the maximum codec frames per SDU of a codec capability.
1811  *
1812  * @param codec_cap            The codec capabilities to set data for.
1813  * @param codec_frames_per_sdu The maximum codec frames per SDU to set.
1814  *
1815  * @retval The data_len of @p codec_cap on success
1816  * @retval -EINVAL if arguments are invalid
1817  * @retval -ENOMEM if the new value could not set or added due to memory
1818  */
1819 int bt_audio_codec_cap_set_max_codec_frames_per_sdu(struct bt_audio_codec_cap *codec_cap,
1820 						    uint8_t codec_frames_per_sdu);
1821 
1822 /**
1823  * @brief Lookup a specific metadata value based on type
1824  *
1825  * @param[in]  codec_cap The codec data to search in.
1826  * @param[in]  type      The type id to look for
1827  * @param[out] data      Pointer to the data-pointer to update when item is found
1828  *
1829  * @retval Length of found @p data (may be 0)
1830  * @retval -EINVAL if arguments are invalid
1831  * @retval -ENODATA if not found
1832  */
1833 int bt_audio_codec_cap_meta_get_val(const struct bt_audio_codec_cap *codec_cap, uint8_t type,
1834 				    const uint8_t **data);
1835 
1836 /**
1837  * @brief Set or add a specific codec capability metadata value.
1838  *
1839  * @param codec_cap  The codec capability to set the value in.
1840  * @param type       The type id to set.
1841  * @param data       Pointer to the data-pointer to set.
1842  * @param data_len   Length of @p data.
1843  *
1844  * @retval The meta_len of @p codec_cap on success
1845  * @retval -EINVAL if arguments are invalid
1846  * @retval -ENOMEM if the new value could not set or added due to memory
1847  */
1848 int bt_audio_codec_cap_meta_set_val(struct bt_audio_codec_cap *codec_cap,
1849 				    enum bt_audio_metadata_type type, const uint8_t *data,
1850 				    size_t data_len);
1851 
1852 /**
1853  * @brief Unset a specific codec capability metadata value
1854  *
1855  * The type and the value will be removed from the codec capability metadata.
1856  *
1857  * @param codec_cap  The codec data to set the value in.
1858  * @param type       The type id to unset.
1859  *
1860  * @retval The meta_len of @p codec_cap on success
1861  * @retval -EINVAL if arguments are invalid
1862  */
1863 int bt_audio_codec_cap_meta_unset_val(struct bt_audio_codec_cap *codec_cap,
1864 				      enum bt_audio_metadata_type type);
1865 
1866 /**
1867  * @brief Extract preferred contexts
1868  *
1869  * See @ref BT_AUDIO_METADATA_TYPE_PREF_CONTEXT for more information about this value.
1870  *
1871  * @param codec_cap The codec data to search in.
1872  *
1873  * @retval The preferred context type if positive or 0
1874  * @retval -EINVAL if arguments are invalid
1875  * @retval -ENODATA if not found
1876  * @retval -EBADMSG if found value has invalid size
1877  */
1878 int bt_audio_codec_cap_meta_get_pref_context(const struct bt_audio_codec_cap *codec_cap);
1879 
1880 /**
1881  * @brief Set the preferred context of a codec capability metadata.
1882  *
1883  * @param codec_cap The codec capability to set data for.
1884  * @param ctx       The preferred context to set.
1885  *
1886  * @retval The data_len of @p codec_cap on success
1887  * @retval -EINVAL if arguments are invalid
1888  * @retval -ENOMEM if the new value could not set or added due to memory
1889  */
1890 int bt_audio_codec_cap_meta_set_pref_context(struct bt_audio_codec_cap *codec_cap,
1891 					     enum bt_audio_context ctx);
1892 
1893 /**
1894  * @brief Extract stream contexts
1895  *
1896  * See @ref BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT for more information about this value.
1897  *
1898  * @param codec_cap The codec data to search in.
1899  *
1900  * @retval The stream context type if positive or 0
1901  * @retval -EINVAL if arguments are invalid
1902  * @retval -ENODATA if not found
1903  * @retval -EBADMSG if found value has invalid size
1904  */
1905 int bt_audio_codec_cap_meta_get_stream_context(const struct bt_audio_codec_cap *codec_cap);
1906 
1907 /**
1908  * @brief Set the stream context of a codec capability metadata.
1909  *
1910  * @param codec_cap The codec capability to set data for.
1911  * @param ctx       The stream context to set.
1912  *
1913  * @retval The data_len of @p codec_cap on success
1914  * @retval -EINVAL if arguments are invalid
1915  * @retval -ENOMEM if the new value could not set or added due to memory
1916  */
1917 int bt_audio_codec_cap_meta_set_stream_context(struct bt_audio_codec_cap *codec_cap,
1918 					       enum bt_audio_context ctx);
1919 
1920 /**
1921  * @brief Extract program info
1922  *
1923  * See @ref BT_AUDIO_METADATA_TYPE_PROGRAM_INFO for more information about this value.
1924  *
1925  * @param[in]  codec_cap    The codec data to search in.
1926  * @param[out] program_info Pointer to the UTF-8 formatted program info.
1927  *
1928  * @retval The length of the @p program_info (may be 0)
1929  * @retval -EINVAL if arguments are invalid
1930  * @retval -ENODATA if not found
1931  */
1932 int bt_audio_codec_cap_meta_get_program_info(const struct bt_audio_codec_cap *codec_cap,
1933 					     const uint8_t **program_info);
1934 
1935 /**
1936  * @brief Set the program info of a codec capability metadata.
1937  *
1938  * @param codec_cap        The codec capability to set data for.
1939  * @param program_info     The program info to set.
1940  * @param program_info_len The length of @p program_info.
1941  *
1942  * @retval The data_len of @p codec_cap on success
1943  * @retval -EINVAL if arguments are invalid
1944  * @retval -ENOMEM if the new value could not set or added due to memory
1945  */
1946 int bt_audio_codec_cap_meta_set_program_info(struct bt_audio_codec_cap *codec_cap,
1947 					     const uint8_t *program_info, size_t program_info_len);
1948 
1949 /**
1950  * @brief Extract language
1951  *
1952  * See @ref BT_AUDIO_METADATA_TYPE_LANG for more information about this value.
1953  *
1954  * @param[in]  codec_cap The codec data to search in.
1955  * @param[out] lang      Pointer to the language bytes (of length BT_AUDIO_LANG_SIZE)
1956  *
1957  * @retval 0 On success
1958  * @retval -EINVAL if arguments are invalid
1959  * @retval -ENODATA if not found
1960  * @retval -EBADMSG if found value has invalid size
1961  */
1962 int bt_audio_codec_cap_meta_get_lang(const struct bt_audio_codec_cap *codec_cap,
1963 				     const uint8_t **lang);
1964 
1965 /**
1966  * @brief Set the language of a codec capability metadata.
1967  *
1968  * @param codec_cap   The codec capability to set data for.
1969  * @param lang        The 24-bit language to set.
1970  *
1971  * @retval The data_len of @p codec_cap on success
1972  * @retval -EINVAL if arguments are invalid
1973  * @retval -ENOMEM if the new value could not set or added due to memory
1974  */
1975 int bt_audio_codec_cap_meta_set_lang(struct bt_audio_codec_cap *codec_cap,
1976 				     const uint8_t lang[BT_AUDIO_LANG_SIZE]);
1977 
1978 /**
1979  * @brief Extract CCID list
1980  *
1981  * See @ref BT_AUDIO_METADATA_TYPE_CCID_LIST for more information about this value.
1982  *
1983  * @param[in]  codec_cap The codec data to search in.
1984  * @param[out] ccid_list Pointer to the array containing 8-bit CCIDs.
1985  *
1986  * @retval The length of the @p ccid_list (may be 0)
1987  * @retval -EINVAL if arguments are invalid
1988  * @retval -ENODATA if not found
1989  */
1990 int bt_audio_codec_cap_meta_get_ccid_list(const struct bt_audio_codec_cap *codec_cap,
1991 					  const uint8_t **ccid_list);
1992 
1993 /**
1994  * @brief Set the CCID list of a codec capability metadata.
1995  *
1996  * @param codec_cap     The codec capability to set data for.
1997  * @param ccid_list     The program info to set.
1998  * @param ccid_list_len The length of @p ccid_list.
1999  *
2000  * @retval The data_len of @p codec_cap on success
2001  * @retval -EINVAL if arguments are invalid
2002  * @retval -ENOMEM if the new value could not set or added due to memory
2003  */
2004 int bt_audio_codec_cap_meta_set_ccid_list(struct bt_audio_codec_cap *codec_cap,
2005 					  const uint8_t *ccid_list, size_t ccid_list_len);
2006 
2007 /**
2008  * @brief Extract parental rating
2009  *
2010  * See @ref BT_AUDIO_METADATA_TYPE_PARENTAL_RATING for more information about this value.
2011  *
2012  * @param codec_cap The codec data to search in.
2013  *
2014  * @retval The parental rating if positive or 0
2015  * @retval -EINVAL if arguments are invalid
2016  * @retval -ENODATA if not found
2017  * @retval -EBADMSG if found value has invalid size
2018  */
2019 int bt_audio_codec_cap_meta_get_parental_rating(const struct bt_audio_codec_cap *codec_cap);
2020 
2021 /**
2022  * @brief Set the parental rating of a codec capability metadata.
2023  *
2024  * @param codec_cap       The codec capability to set data for.
2025  * @param parental_rating The parental rating to set.
2026  *
2027  * @retval The data_len of @p codec_cap on success
2028  * @retval -EINVAL if arguments are invalid
2029  * @retval -ENOMEM if the new value could not set or added due to memory
2030  */
2031 int bt_audio_codec_cap_meta_set_parental_rating(struct bt_audio_codec_cap *codec_cap,
2032 						enum bt_audio_parental_rating parental_rating);
2033 
2034 /**
2035  * @brief Extract program info URI
2036  *
2037  * See @ref BT_AUDIO_METADATA_TYPE_PROGRAM_INFO_URI for more information about this value.
2038  *
2039  * @param[in]  codec_cap        The codec data to search in.
2040  * @param[out] program_info_uri Pointer to the UTF-8 formatted program info URI.
2041  *
2042  * @retval The length of the @p ccid_list (may be 0)
2043  * @retval -EINVAL if arguments are invalid
2044  * @retval -ENODATA if not found
2045  */
2046 int bt_audio_codec_cap_meta_get_program_info_uri(const struct bt_audio_codec_cap *codec_cap,
2047 						 const uint8_t **program_info_uri);
2048 
2049 /**
2050  * @brief Set the program info URI of a codec capability metadata.
2051  *
2052  * @param codec_cap            The codec capability to set data for.
2053  * @param program_info_uri     The program info URI to set.
2054  * @param program_info_uri_len The length of @p program_info_uri.
2055  *
2056  * @retval The data_len of @p codec_cap on success
2057  * @retval -EINVAL if arguments are invalid
2058  * @retval -ENOMEM if the new value could not set or added due to memory
2059  */
2060 int bt_audio_codec_cap_meta_set_program_info_uri(struct bt_audio_codec_cap *codec_cap,
2061 						 const uint8_t *program_info_uri,
2062 						 size_t program_info_uri_len);
2063 
2064 /**
2065  * @brief Extract audio active state
2066  *
2067  * See @ref BT_AUDIO_METADATA_TYPE_AUDIO_STATE for more information about this value.
2068  *
2069  * @param codec_cap The codec data to search in.
2070  *
2071  * @retval The preferred context type if positive or 0
2072  * @retval -EINVAL if arguments are invalid
2073  * @retval -ENODATA if not found
2074  * @retval -EBADMSG if found value has invalid size
2075  */
2076 int bt_audio_codec_cap_meta_get_audio_active_state(const struct bt_audio_codec_cap *codec_cap);
2077 
2078 /**
2079  * @brief Set the audio active state of a codec capability metadata.
2080  *
2081  * @param codec_cap The codec capability to set data for.
2082  * @param state     The audio active state to set.
2083  *
2084  * @retval The data_len of @p codec_cap on success
2085  * @retval -EINVAL if arguments are invalid
2086  * @retval -ENOMEM if the new value could not set or added due to memory
2087  */
2088 int bt_audio_codec_cap_meta_set_audio_active_state(struct bt_audio_codec_cap *codec_cap,
2089 						   enum bt_audio_active_state state);
2090 
2091 /**
2092  * @brief Extract broadcast audio immediate rendering flag
2093  *
2094  * See @ref BT_AUDIO_METADATA_TYPE_BROADCAST_IMMEDIATE for more information about this value.
2095  *
2096  * @param codec_cap The codec data to search in.
2097  *
2098  * @retval 0 if the flag was found
2099  * @retval -EINVAL if arguments are invalid
2100  * @retval -ENODATA if not the flag was not found
2101  */
2102 int bt_audio_codec_cap_meta_get_bcast_audio_immediate_rend_flag(
2103 	const struct bt_audio_codec_cap *codec_cap);
2104 
2105 /**
2106  * @brief Set the broadcast audio immediate rendering flag of a codec capability metadata.
2107  *
2108  * @param codec_cap The codec capability to set data for.
2109  *
2110  * @retval The data_len of @p codec_cap on success
2111  * @retval -EINVAL if arguments are invalid
2112  * @retval -ENOMEM if the new value could not set or added due to memory
2113  */
2114 int bt_audio_codec_cap_meta_set_bcast_audio_immediate_rend_flag(
2115 	struct bt_audio_codec_cap *codec_cap);
2116 
2117 /**
2118  * @brief Extract extended metadata
2119  *
2120  * See @ref BT_AUDIO_METADATA_TYPE_EXTENDED for more information about this value.
2121  *
2122  * @param[in]  codec_cap     The codec data to search in.
2123  * @param[out] extended_meta Pointer to the extended metadata.
2124  *
2125  * @retval The length of the @p ccid_list (may be 0)
2126  * @retval -EINVAL if arguments are invalid
2127  * @retval -ENODATA if not found
2128  */
2129 int bt_audio_codec_cap_meta_get_extended(const struct bt_audio_codec_cap *codec_cap,
2130 					 const uint8_t **extended_meta);
2131 
2132 /**
2133  * @brief Set the extended metadata of a codec capability metadata.
2134  *
2135  * @param codec_cap         The codec capability to set data for.
2136  * @param extended_meta     The extended metadata to set.
2137  * @param extended_meta_len The length of @p extended_meta.
2138  *
2139  * @retval The data_len of @p codec_cap on success
2140  * @retval -EINVAL if arguments are invalid
2141  * @retval -ENOMEM if the new value could not set or added due to memory
2142  */
2143 int bt_audio_codec_cap_meta_set_extended(struct bt_audio_codec_cap *codec_cap,
2144 					 const uint8_t *extended_meta, size_t extended_meta_len);
2145 
2146 /**
2147  * @brief Extract vendor specific metadata
2148  *
2149  * See @ref BT_AUDIO_METADATA_TYPE_VENDOR for more information about this value.
2150  *
2151  * @param[in]  codec_cap   The codec data to search in.
2152  * @param[out] vendor_meta Pointer to the vendor specific metadata.
2153  *
2154  * @retval The length of the @p ccid_list (may be 0)
2155  * @retval -EINVAL if arguments are invalid
2156  * @retval -ENODATA if not found
2157  */
2158 int bt_audio_codec_cap_meta_get_vendor(const struct bt_audio_codec_cap *codec_cap,
2159 				       const uint8_t **vendor_meta);
2160 
2161 /**
2162  * @brief Set the vendor specific metadata of a codec capability metadata.
2163  *
2164  * @param codec_cap       The codec capability to set data for.
2165  * @param vendor_meta     The vendor specific metadata to set.
2166  * @param vendor_meta_len The length of @p vendor_meta.
2167  *
2168  * @retval The data_len of @p codec_cap on success
2169  * @retval -EINVAL if arguments are invalid
2170  * @retval -ENOMEM if the new value could not set or added due to memory
2171  */
2172 int bt_audio_codec_cap_meta_set_vendor(struct bt_audio_codec_cap *codec_cap,
2173 				       const uint8_t *vendor_meta, size_t vendor_meta_len);
2174 
2175 /** @} */ /* End of bt_audio_codec_cap */
2176 
2177 #ifdef __cplusplus
2178 }
2179 #endif
2180 
2181 /** @} */ /* end of bt_audio */
2182 
2183 #endif /* ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_H_ */
2184