1 /** 2 * @file 3 * @brief Header for Bluetooth BAP. 4 * 5 * Copyright (c) 2020 Bose Corporation 6 * Copyright (c) 2021-2024 Nordic Semiconductor ASA 7 * 8 * SPDX-License-Identifier: Apache-2.0 9 */ 10 11 #ifndef ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_BAP_ 12 #define ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_BAP_ 13 14 /** 15 * @brief Bluetooth Basic Audio Profile (BAP) 16 * @defgroup bt_bap Bluetooth Basic Audio Profile 17 * 18 * @since 3.0 19 * @version 0.8.0 20 * 21 * @ingroup bluetooth 22 * @{ 23 * 24 * The Basic Audio Profile (BAP) allows for both unicast and broadcast Audio Stream control. 25 */ 26 27 #include <stdbool.h> 28 #include <stddef.h> 29 #include <stdint.h> 30 31 #include <zephyr/bluetooth/audio/audio.h> 32 #include <zephyr/bluetooth/addr.h> 33 #include <zephyr/bluetooth/bluetooth.h> 34 #include <zephyr/bluetooth/conn.h> 35 #include <zephyr/bluetooth/gap.h> 36 #include <zephyr/bluetooth/iso.h> 37 #include <zephyr/net_buf.h> 38 #include <zephyr/sys/slist.h> 39 #include <zephyr/sys/util_macro.h> 40 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 45 /** Maximum number of subgroups supported in the BAP Scan Delegator API */ 46 #define BT_BAP_BASS_MAX_SUBGROUPS \ 47 COND_CODE_1(CONFIG_BT_AUDIO, (CONFIG_BT_BAP_BASS_MAX_SUBGROUPS), (0)) 48 49 /** Maximum size of BASE excluding service data header */ 50 #define BT_BASE_MAX_SIZE (UINT8_MAX - 1 /* type */ - BT_UUID_SIZE_16) 51 52 /** An invalid Broadcast ID */ 53 #define BT_BAP_INVALID_BROADCAST_ID 0xFFFFFFFFU 54 55 /** 56 * @brief Recommended connectable advertising parameters 57 * 58 * If connection has not been established after 30 seconds, the device should switch to 59 * @ref BT_BAP_ADV_PARAM_CONN_REDUCED 60 * 61 * Defined by Table 8.1 in BAP 1.0.2 62 */ 63 #define BT_BAP_ADV_PARAM_CONN_QUICK \ 64 BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONN | BT_LE_ADV_OPT_EXT_ADV, BT_GAP_MS_TO_ADV_INTERVAL(20), \ 65 BT_GAP_MS_TO_ADV_INTERVAL(30), NULL) 66 67 /** 68 * @brief Reduced connectable advertising parameters 69 * 70 * Defined by Table 8.1 in BAP 1.0.2 71 */ 72 #define BT_BAP_ADV_PARAM_CONN_REDUCED \ 73 BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONN | BT_LE_ADV_OPT_EXT_ADV, \ 74 BT_GAP_MS_TO_ADV_INTERVAL(150), BT_GAP_MS_TO_ADV_INTERVAL(150), NULL) 75 76 /** 77 * @brief Recommended connection parameters for initial connection request for 7.5 ms SDU interval 78 * 79 * Once service discovery has completed and a stream is setup, it is recommended to switch to 80 * @ref BT_BAP_CONN_PARAM_RELAXED 81 * 82 * Defined by Table 8.3 in BAP 1.0.2 83 */ 84 #define BT_BAP_CONN_PARAM_SHORT_7_5 \ 85 BT_LE_CONN_PARAM(BT_GAP_US_TO_CONN_INTERVAL(7500), BT_GAP_MS_TO_CONN_INTERVAL(30), 0, \ 86 BT_GAP_MS_TO_CONN_TIMEOUT(4000)) 87 88 /** 89 * @brief Recommended connection parameters for initial connection request for 10 ms SDU interval 90 * 91 * Once service discovery has completed and a stream is setup, it is recommended to switch to 92 * @ref BT_BAP_CONN_PARAM_RELAXED 93 * 94 * Defined by Table 8.3 in BAP 1.0.2 95 */ 96 #define BT_BAP_CONN_PARAM_SHORT_10 \ 97 BT_LE_CONN_PARAM(BT_GAP_MS_TO_CONN_INTERVAL(10), BT_GAP_MS_TO_CONN_INTERVAL(30), 0, \ 98 BT_GAP_MS_TO_CONN_TIMEOUT(4000)) 99 100 /** 101 * @brief Recommended connection parameters for coexistence of ACL and ISO 102 * 103 * Defined by Table 8.3 in BAP 1.0.2 104 */ 105 #define BT_BAP_CONN_PARAM_RELAXED \ 106 BT_LE_CONN_PARAM(BT_GAP_MS_TO_CONN_INTERVAL(50), BT_GAP_MS_TO_CONN_INTERVAL(70), 0, \ 107 BT_GAP_MS_TO_CONN_TIMEOUT(4000)) 108 109 /** 110 * @brief Fast advertising parameters for broadcast audio 111 * 112 * This is suitable for both 7.5 ms and 10 ms SDU intervals, but prioritizes lower time to 113 * synchronize over coexistence with ISO and power consumption. 114 */ 115 #define BT_BAP_ADV_PARAM_BROADCAST_FAST \ 116 BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV, BT_GAP_MS_TO_ADV_INTERVAL(60), \ 117 BT_GAP_MS_TO_ADV_INTERVAL(60), NULL) 118 119 /** 120 * @brief Slow advertising parameters for broadcast audio 121 * 122 * This is suitable for both 7.5 ms and 10 ms SDU intervals, but prioritizes coexistence with ISO 123 * and power consumption over lower time to synchronize. 124 */ 125 #define BT_BAP_ADV_PARAM_BROADCAST_SLOW \ 126 BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV, BT_GAP_MS_TO_ADV_INTERVAL(150), \ 127 BT_GAP_MS_TO_ADV_INTERVAL(150), NULL) 128 129 /** 130 * @brief Fast advertising parameters for broadcast audio 131 * 132 * This is suitable for both 7.5 ms and 10 ms SDU intervals, but prioritizes lower time to 133 * synchronize over coexistence with ISO and power consumption. 134 */ 135 #define BT_BAP_PER_ADV_PARAM_BROADCAST_FAST \ 136 BT_LE_PER_ADV_PARAM(BT_GAP_MS_TO_PER_ADV_INTERVAL(60), BT_GAP_MS_TO_PER_ADV_INTERVAL(60), \ 137 BT_LE_PER_ADV_OPT_NONE) 138 139 /** 140 * @brief Slow advertising parameters for broadcast audio 141 * 142 * This is suitable for both 7.5 ms and 10 ms SDU intervals, but prioritizes coexistence with ISO 143 * and power consumption over lower time to synchronize. 144 */ 145 #define BT_BAP_PER_ADV_PARAM_BROADCAST_SLOW \ 146 BT_LE_PER_ADV_PARAM(BT_GAP_MS_TO_PER_ADV_INTERVAL(150), \ 147 BT_GAP_MS_TO_PER_ADV_INTERVAL(150), BT_LE_PER_ADV_OPT_NONE) 148 149 /** 150 * @brief Check if a BAP BASS BIS_Sync bitfield is valid 151 * 152 * Valid options are either a bitmask of valid BIS indices, including none (0x00000000) 153 * or @ref BT_BAP_BIS_SYNC_NO_PREF (0xFFFFFFFF). 154 * 155 * @param _bis_bitfield BIS_Sync bitfield (uint32) 156 */ 157 #define BT_BAP_BASS_VALID_BIT_BITFIELD(_bis_bitfield) \ 158 ((_bis_bitfield) == 0U || (_bis_bitfield) == BT_BAP_BIS_SYNC_NO_PREF || \ 159 BT_ISO_VALID_BIS_BITFIELD(_bis_bitfield)) 160 161 /** 162 * @brief Helper to declare elements of bt_bap_qos_cfg 163 * 164 * @param _interval SDU interval (usec) 165 * @param _framing Framing 166 * @param _phy Target PHY 167 * @param _sdu Maximum SDU Size 168 * @param _rtn Retransmission number 169 * @param _latency Maximum Transport Latency (msec) 170 * @param _pd Presentation Delay (usec) 171 */ 172 #define BT_BAP_QOS_CFG(_interval, _framing, _phy, _sdu, _rtn, _latency, _pd) \ 173 ((struct bt_bap_qos_cfg){ \ 174 .interval = _interval, \ 175 .framing = _framing, \ 176 .phy = _phy, \ 177 .sdu = _sdu, \ 178 .rtn = _rtn, \ 179 IF_ENABLED(UTIL_OR(IS_ENABLED(CONFIG_BT_BAP_BROADCAST_SOURCE), \ 180 IS_ENABLED(CONFIG_BT_BAP_UNICAST)), \ 181 (.latency = _latency,)) \ 182 .pd = _pd, \ 183 }) 184 185 /** @brief QoS Framing */ 186 enum bt_bap_qos_cfg_framing { 187 /** Packets may be framed or unframed */ 188 BT_BAP_QOS_CFG_FRAMING_UNFRAMED = 0x00, 189 /** Packets are always framed */ 190 BT_BAP_QOS_CFG_FRAMING_FRAMED = 0x01, 191 }; 192 193 /** @brief QoS Preferred PHY */ 194 enum { 195 /** LE 1M PHY */ 196 BT_BAP_QOS_CFG_1M = BIT(0), 197 /** LE 2M PHY */ 198 BT_BAP_QOS_CFG_2M = BIT(1), 199 /** LE Coded PHY */ 200 BT_BAP_QOS_CFG_CODED = BIT(2), 201 }; 202 203 /** 204 * @brief Helper to declare Input Unframed bt_bap_qos_cfg 205 * 206 * @param _interval SDU interval (usec) 207 * @param _sdu Maximum SDU Size 208 * @param _rtn Retransmission number 209 * @param _latency Maximum Transport Latency (msec) 210 * @param _pd Presentation Delay (usec) 211 */ 212 #define BT_BAP_QOS_CFG_UNFRAMED(_interval, _sdu, _rtn, _latency, _pd) \ 213 BT_BAP_QOS_CFG(_interval, BT_BAP_QOS_CFG_FRAMING_UNFRAMED, BT_BAP_QOS_CFG_2M, _sdu, _rtn, \ 214 _latency, _pd) 215 216 /** 217 * @brief Helper to declare Input Framed bt_bap_qos_cfg 218 * 219 * @param _interval SDU interval (usec) 220 * @param _sdu Maximum SDU Size 221 * @param _rtn Retransmission number 222 * @param _latency Maximum Transport Latency (msec) 223 * @param _pd Presentation Delay (usec) 224 */ 225 #define BT_BAP_QOS_CFG_FRAMED(_interval, _sdu, _rtn, _latency, _pd) \ 226 BT_BAP_QOS_CFG(_interval, BT_BAP_QOS_CFG_FRAMING_FRAMED, BT_BAP_QOS_CFG_2M, _sdu, _rtn, \ 227 _latency, _pd) 228 229 /** @brief QoS configuration structure. */ 230 struct bt_bap_qos_cfg { 231 /** 232 * @brief Presentation Delay in microseconds 233 * 234 * This value can be changed up and until bt_bap_stream_qos() has been called. 235 * Once a stream has been QoS configured, modifying this field does not modify the value. 236 * It is however possible to modify this field and call bt_bap_stream_qos() again to update 237 * the value, assuming that the stream is in the correct state. 238 * 239 * Value range 0 to @ref BT_AUDIO_PD_MAX. 240 */ 241 uint32_t pd; 242 243 /** 244 * @brief Connected Isochronous Group (CIG) parameters 245 * 246 * The fields in this struct affect the value sent to the controller via HCI 247 * when creating the CIG. Once the group has been created with 248 * bt_bap_unicast_group_create(), modifying these fields will not affect the group. 249 */ 250 struct { 251 /** QoS Framing */ 252 enum bt_bap_qos_cfg_framing framing; 253 254 /** 255 * @brief PHY 256 * 257 * Allowed values are @ref BT_BAP_QOS_CFG_1M, @ref BT_BAP_QOS_CFG_2M and 258 * @ref BT_BAP_QOS_CFG_CODED. 259 */ 260 uint8_t phy; 261 262 /** 263 * @brief Retransmission Number 264 * 265 * This a recommendation to the controller, and the actual retransmission number 266 * may be different than this. 267 */ 268 uint8_t rtn; 269 270 /** 271 * @brief Maximum SDU size 272 * 273 * Value range @ref BT_ISO_MIN_SDU to @ref BT_ISO_MAX_SDU. 274 */ 275 uint16_t sdu; 276 277 #if defined(CONFIG_BT_BAP_BROADCAST_SOURCE) || defined(CONFIG_BT_BAP_UNICAST) || \ 278 defined(__DOXYGEN__) 279 /** 280 * @brief Maximum Transport Latency 281 * 282 * Not used for the @kconfig{CONFIG_BT_BAP_BROADCAST_SINK} role. 283 */ 284 uint16_t latency; 285 #endif /* CONFIG_BT_BAP_BROADCAST_SOURCE || CONFIG_BT_BAP_UNICAST */ 286 287 /** 288 * @brief SDU Interval 289 * 290 * Value range @ref BT_ISO_SDU_INTERVAL_MIN to @ref BT_ISO_SDU_INTERVAL_MAX 291 */ 292 uint32_t interval; 293 294 #if defined(CONFIG_BT_ISO_TEST_PARAMS) || defined(__DOXYGEN__) 295 /** 296 * @brief Maximum PDU size 297 * 298 * Maximum size, in octets, of the payload from link layer to link layer. 299 * 300 * Value range @ref BT_ISO_CONNECTED_PDU_MIN to @ref BT_ISO_PDU_MAX for 301 * connected ISO. 302 * 303 * Value range @ref BT_ISO_BROADCAST_PDU_MIN to @ref BT_ISO_PDU_MAX for 304 * broadcast ISO. 305 */ 306 uint16_t max_pdu; 307 308 /** 309 * @brief Burst number 310 * 311 * Value range @ref BT_ISO_BN_MIN to @ref BT_ISO_BN_MAX. 312 */ 313 uint8_t burst_number; 314 315 /** 316 * @brief Number of subevents 317 * 318 * Maximum number of subevents in each CIS or BIS event. 319 * 320 * Value range @ref BT_ISO_NSE_MIN to @ref BT_ISO_NSE_MAX. 321 */ 322 uint8_t num_subevents; 323 #endif /* CONFIG_BT_ISO_TEST_PARAMS */ 324 }; 325 }; 326 327 /** 328 * @brief Helper to declare elements of @ref bt_bap_qos_cfg_pref 329 * 330 * @param _unframed_supported Unframed PDUs supported 331 * @param _phy Preferred Target PHY 332 * @param _rtn Preferred Retransmission number 333 * @param _latency Preferred Maximum Transport Latency (msec) 334 * @param _pd_min Minimum Presentation Delay (usec) 335 * @param _pd_max Maximum Presentation Delay (usec) 336 * @param _pref_pd_min Preferred Minimum Presentation Delay (usec) 337 * @param _pref_pd_max Preferred Maximum Presentation Delay (usec) 338 */ 339 #define BT_BAP_QOS_CFG_PREF(_unframed_supported, _phy, _rtn, _latency, _pd_min, _pd_max, \ 340 _pref_pd_min, _pref_pd_max) \ 341 { \ 342 .unframed_supported = _unframed_supported, .phy = _phy, .rtn = _rtn, \ 343 .latency = _latency, .pd_min = _pd_min, .pd_max = _pd_max, \ 344 .pref_pd_min = _pref_pd_min, .pref_pd_max = _pref_pd_max, \ 345 } 346 347 /** @brief Audio Stream Quality of Service Preference structure. */ 348 struct bt_bap_qos_cfg_pref { 349 /** 350 * @brief Unframed PDUs supported 351 * 352 * Unlike the other fields, this is not a preference but whether 353 * the codec supports unframed ISOAL PDUs. 354 */ 355 bool unframed_supported; 356 357 /** 358 * @brief Preferred PHY bitfield 359 * 360 * Bitfield consisting of one or more of @ref BT_GAP_LE_PHY_1M, @ref BT_GAP_LE_PHY_2M and 361 * @ref BT_GAP_LE_PHY_CODED. 362 */ 363 uint8_t phy; 364 365 /** 366 * @brief Preferred Retransmission Number 367 * 368 * @ref BT_AUDIO_RTN_PREF_NONE indicates no preference. 369 */ 370 uint8_t rtn; 371 372 /** 373 * Preferred Transport Latency 374 * 375 * Value range @ref BT_ISO_LATENCY_MIN to @ref BT_ISO_LATENCY_MAX 376 */ 377 uint16_t latency; 378 379 /** 380 * @brief Minimum Presentation Delay in microseconds 381 * 382 * Unlike the other fields, this is not a preference but a minimum requirement. 383 * 384 * Value range 0 to @ref BT_AUDIO_PD_MAX 385 */ 386 uint32_t pd_min; 387 388 /** 389 * @brief Maximum Presentation Delay in microseconds 390 * 391 * Unlike the other fields, this is not a preference but a maximum requirement. 392 * 393 * Value range @ref bt_bap_qos_cfg_pref.pd_min to @ref BT_AUDIO_PD_MAX 394 */ 395 uint32_t pd_max; 396 397 /** 398 * @brief Preferred minimum Presentation Delay in microseconds 399 * 400 * Value range @ref bt_bap_qos_cfg_pref.pd_min to @ref bt_bap_qos_cfg_pref.pd_max, or 401 * @ref BT_AUDIO_PD_PREF_NONE to indicate no preference. 402 */ 403 uint32_t pref_pd_min; 404 405 /** 406 * @brief Preferred maximum Presentation Delay in microseconds 407 * 408 * Value range @ref bt_bap_qos_cfg_pref.pd_min to @ref bt_bap_qos_cfg_pref.pd_max, 409 * and higher than or equal to @ref bt_bap_qos_cfg_pref.pref_pd_min, or 410 * @ref BT_AUDIO_PD_PREF_NONE to indicate no preference. 411 */ 412 uint32_t pref_pd_max; 413 }; 414 415 /** Periodic advertising state reported by the Scan Delegator */ 416 enum bt_bap_pa_state { 417 /** The periodic advertising has not been synchronized */ 418 BT_BAP_PA_STATE_NOT_SYNCED = 0x00, 419 420 /** Waiting for SyncInfo from Broadcast Assistant */ 421 BT_BAP_PA_STATE_INFO_REQ = 0x01, 422 423 /** Synchronized to periodic advertising */ 424 BT_BAP_PA_STATE_SYNCED = 0x02, 425 426 /** Failed to synchronized to periodic advertising */ 427 BT_BAP_PA_STATE_FAILED = 0x03, 428 429 /** No periodic advertising sync transfer receiver from Broadcast Assistant */ 430 BT_BAP_PA_STATE_NO_PAST = 0x04, 431 }; 432 433 /** Broadcast Isochronous Group encryption state reported by the Scan Delegator */ 434 enum bt_bap_big_enc_state { 435 /** The Broadcast Isochronous Group not encrypted */ 436 BT_BAP_BIG_ENC_STATE_NO_ENC = 0x00, 437 438 /** The Broadcast Isochronous Group broadcast code requested */ 439 BT_BAP_BIG_ENC_STATE_BCODE_REQ = 0x01, 440 441 /** The Broadcast Isochronous Group decrypted */ 442 BT_BAP_BIG_ENC_STATE_DEC = 0x02, 443 444 /** The Broadcast Isochronous Group bad broadcast code */ 445 BT_BAP_BIG_ENC_STATE_BAD_CODE = 0x03, 446 }; 447 448 /** Broadcast Audio Scan Service (BASS) specific ATT error codes */ 449 enum bt_bap_bass_att_err { 450 /** Opcode not supported */ 451 BT_BAP_BASS_ERR_OPCODE_NOT_SUPPORTED = 0x80, 452 453 /** Invalid source ID supplied */ 454 BT_BAP_BASS_ERR_INVALID_SRC_ID = 0x81, 455 }; 456 457 /** Value indicating that the periodic advertising interval is unknown */ 458 #define BT_BAP_PA_INTERVAL_UNKNOWN 0xFFFF 459 460 /** 461 * @brief Broadcast Assistant no BIS sync preference 462 * 463 * Value indicating that the Broadcast Assistant has no preference to which BIS 464 * the Scan Delegator syncs to 465 */ 466 #define BT_BAP_BIS_SYNC_NO_PREF 0xFFFFFFFF 467 /** BIS sync value indicating that the BIG sync has failed for any reason */ 468 #define BT_BAP_BIS_SYNC_FAILED 0xFFFFFFFF 469 470 /** Endpoint states */ 471 enum bt_bap_ep_state { 472 /** Audio Stream Endpoint Idle state */ 473 BT_BAP_EP_STATE_IDLE = 0x00, 474 475 /** Audio Stream Endpoint Codec Configured state */ 476 BT_BAP_EP_STATE_CODEC_CONFIGURED = 0x01, 477 478 /** Audio Stream Endpoint QoS Configured state */ 479 BT_BAP_EP_STATE_QOS_CONFIGURED = 0x02, 480 481 /** Audio Stream Endpoint Enabling state */ 482 BT_BAP_EP_STATE_ENABLING = 0x03, 483 484 /** Audio Stream Endpoint Streaming state */ 485 BT_BAP_EP_STATE_STREAMING = 0x04, 486 487 /** Audio Stream Endpoint Disabling state */ 488 BT_BAP_EP_STATE_DISABLING = 0x05, 489 490 /** Audio Stream Endpoint Streaming state */ 491 BT_BAP_EP_STATE_RELEASING = 0x06, 492 }; 493 494 /** 495 * @brief Response Status Code 496 * 497 * These are sent by the server to the client when a stream operation is 498 * requested. 499 */ 500 enum bt_bap_ascs_rsp_code { 501 /** Server completed operation successfully */ 502 BT_BAP_ASCS_RSP_CODE_SUCCESS = 0x00, 503 /** Server did not support operation by client */ 504 BT_BAP_ASCS_RSP_CODE_NOT_SUPPORTED = 0x01, 505 /** Server rejected due to invalid operation length */ 506 BT_BAP_ASCS_RSP_CODE_INVALID_LENGTH = 0x02, 507 /** Invalid ASE ID */ 508 BT_BAP_ASCS_RSP_CODE_INVALID_ASE = 0x03, 509 /** Invalid ASE state */ 510 BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE = 0x04, 511 /** Invalid operation for direction */ 512 BT_BAP_ASCS_RSP_CODE_INVALID_DIR = 0x05, 513 /** Capabilities not supported by server */ 514 BT_BAP_ASCS_RSP_CODE_CAP_UNSUPPORTED = 0x06, 515 /** Configuration parameters not supported by server */ 516 BT_BAP_ASCS_RSP_CODE_CONF_UNSUPPORTED = 0x07, 517 /** Configuration parameters rejected by server */ 518 BT_BAP_ASCS_RSP_CODE_CONF_REJECTED = 0x08, 519 /** Invalid Configuration parameters */ 520 BT_BAP_ASCS_RSP_CODE_CONF_INVALID = 0x09, 521 /** Unsupported metadata */ 522 BT_BAP_ASCS_RSP_CODE_METADATA_UNSUPPORTED = 0x0a, 523 /** Metadata rejected by server */ 524 BT_BAP_ASCS_RSP_CODE_METADATA_REJECTED = 0x0b, 525 /** Invalid metadata */ 526 BT_BAP_ASCS_RSP_CODE_METADATA_INVALID = 0x0c, 527 /** Server has insufficient resources */ 528 BT_BAP_ASCS_RSP_CODE_NO_MEM = 0x0d, 529 /** Unspecified error */ 530 BT_BAP_ASCS_RSP_CODE_UNSPECIFIED = 0x0e, 531 }; 532 533 /** 534 * @brief Response Reasons 535 * 536 * These are used if the @ref bt_bap_ascs_rsp_code value is 537 * @ref BT_BAP_ASCS_RSP_CODE_CONF_UNSUPPORTED, @ref BT_BAP_ASCS_RSP_CODE_CONF_REJECTED or 538 * @ref BT_BAP_ASCS_RSP_CODE_CONF_INVALID. 539 */ 540 enum bt_bap_ascs_reason { 541 /** No reason */ 542 BT_BAP_ASCS_REASON_NONE = 0x00, 543 /** Codec ID */ 544 BT_BAP_ASCS_REASON_CODEC = 0x01, 545 /** Codec configuration */ 546 BT_BAP_ASCS_REASON_CODEC_DATA = 0x02, 547 /** SDU interval */ 548 BT_BAP_ASCS_REASON_INTERVAL = 0x03, 549 /** Framing */ 550 BT_BAP_ASCS_REASON_FRAMING = 0x04, 551 /** PHY */ 552 BT_BAP_ASCS_REASON_PHY = 0x05, 553 /** Maximum SDU size*/ 554 BT_BAP_ASCS_REASON_SDU = 0x06, 555 /** RTN */ 556 BT_BAP_ASCS_REASON_RTN = 0x07, 557 /** Max transport latency */ 558 BT_BAP_ASCS_REASON_LATENCY = 0x08, 559 /** Presendation delay */ 560 BT_BAP_ASCS_REASON_PD = 0x09, 561 /** Invalid CIS mapping */ 562 BT_BAP_ASCS_REASON_CIS = 0x0a, 563 }; 564 565 /** @brief Structure storing values of fields of ASE Control Point notification. */ 566 struct bt_bap_ascs_rsp { 567 /** 568 * @brief Value of the Response Code field. 569 * 570 * The following response codes are accepted: 571 * - @ref BT_BAP_ASCS_RSP_CODE_SUCCESS 572 * - @ref BT_BAP_ASCS_RSP_CODE_CAP_UNSUPPORTED 573 * - @ref BT_BAP_ASCS_RSP_CODE_CONF_UNSUPPORTED 574 * - @ref BT_BAP_ASCS_RSP_CODE_CONF_REJECTED 575 * - @ref BT_BAP_ASCS_RSP_CODE_METADATA_UNSUPPORTED 576 * - @ref BT_BAP_ASCS_RSP_CODE_METADATA_REJECTED 577 * - @ref BT_BAP_ASCS_RSP_CODE_NO_MEM 578 * - @ref BT_BAP_ASCS_RSP_CODE_UNSPECIFIED 579 */ 580 enum bt_bap_ascs_rsp_code code; 581 582 /** 583 * @brief Value of the Reason field. 584 * 585 * The meaning of this value depend on the Response Code field. 586 */ 587 union { 588 /** 589 * @brief Response reason 590 * 591 * If the Response Code is one of the following: 592 * - @ref BT_BAP_ASCS_RSP_CODE_CONF_UNSUPPORTED 593 * - @ref BT_BAP_ASCS_RSP_CODE_CONF_REJECTED 594 * all values from @ref bt_bap_ascs_reason can be used. 595 * 596 * If the Response Code is one of the following: 597 * - @ref BT_BAP_ASCS_RSP_CODE_SUCCESS 598 * - @ref BT_BAP_ASCS_RSP_CODE_CAP_UNSUPPORTED 599 * - @ref BT_BAP_ASCS_RSP_CODE_NO_MEM 600 * - @ref BT_BAP_ASCS_RSP_CODE_UNSPECIFIED 601 * only value @ref BT_BAP_ASCS_REASON_NONE shall be used. 602 */ 603 enum bt_bap_ascs_reason reason; 604 605 /** 606 * @brief Response metadata type 607 * 608 * If the Response Code is one of the following: 609 * - @ref BT_BAP_ASCS_RSP_CODE_METADATA_UNSUPPORTED 610 * - @ref BT_BAP_ASCS_RSP_CODE_METADATA_REJECTED 611 * the value of the Metadata Type shall be used. 612 */ 613 enum bt_audio_metadata_type metadata_type; 614 }; 615 }; 616 617 /** 618 * @brief Macro used to initialise the object storing values of ASE Control Point notification. 619 * 620 * @param c Response Code field 621 * @param r Reason field - @ref bt_bap_ascs_reason or @ref bt_audio_metadata_type (see notes in 622 * @ref bt_bap_ascs_rsp). 623 */ 624 #define BT_BAP_ASCS_RSP(c, r) (struct bt_bap_ascs_rsp) { .code = c, .reason = r } 625 626 /** @brief Abstract Audio Broadcast Source structure. */ 627 struct bt_bap_broadcast_source; 628 629 /** @brief Abstract Audio Broadcast Sink structure. */ 630 struct bt_bap_broadcast_sink; 631 632 /** @brief Abstract Audio Unicast Group structure. */ 633 struct bt_bap_unicast_group; 634 635 /** @brief Abstract Audio Endpoint structure. */ 636 struct bt_bap_ep; 637 638 /** Struct to hold subgroup specific information for the receive state */ 639 struct bt_bap_bass_subgroup { 640 /** BIS synced bitfield */ 641 uint32_t bis_sync; 642 643 /** Length of the metadata */ 644 uint8_t metadata_len; 645 646 #if defined(CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE) || defined(__DOXYGEN__) 647 /** The metadata */ 648 uint8_t metadata[CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE]; 649 #endif /* CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE */ 650 }; 651 652 /** Represents the Broadcast Audio Scan Service receive state */ 653 struct bt_bap_scan_delegator_recv_state { 654 /** The source ID */ 655 uint8_t src_id; 656 657 /** The Bluetooth address */ 658 bt_addr_le_t addr; 659 660 /** The advertising set ID*/ 661 uint8_t adv_sid; 662 663 /** The periodic adverting sync state */ 664 enum bt_bap_pa_state pa_sync_state; 665 666 /** The broadcast isochronous group encryption state */ 667 enum bt_bap_big_enc_state encrypt_state; 668 669 /** The 24-bit broadcast ID */ 670 uint32_t broadcast_id; 671 672 /** 673 * @brief The bad broadcast code 674 * 675 * Only valid if encrypt_state is @ref BT_BAP_BIG_ENC_STATE_BCODE_REQ 676 */ 677 uint8_t bad_code[BT_ISO_BROADCAST_CODE_SIZE]; 678 679 /** Number of subgroups */ 680 uint8_t num_subgroups; 681 682 /** Subgroup specific information 683 * 684 * If the @ref bt_bap_bass_subgroup.bis_sync value is @ref BT_BAP_BIS_SYNC_FAILED then it 685 * indicates that the BIG sync failed. 686 */ 687 struct bt_bap_bass_subgroup subgroups[BT_BAP_BASS_MAX_SUBGROUPS]; 688 }; 689 690 /** 691 * @brief Struct to hold the Basic Audio Profile Scan Delegator callbacks 692 * 693 * These can be registered for usage with bt_bap_scan_delegator_register(). 694 */ 695 struct bt_bap_scan_delegator_cb { 696 /** 697 * @brief Receive state updated 698 * 699 * @param conn Pointer to the connection to a remote device if 700 * the change was caused by it, otherwise NULL. 701 * @param recv_state Pointer to the receive state that was updated. 702 * 703 * @return 0 in case of success or negative value in case of error. 704 */ 705 void (*recv_state_updated)(struct bt_conn *conn, 706 const struct bt_bap_scan_delegator_recv_state *recv_state); 707 708 /** 709 * @brief Periodic advertising sync request 710 * 711 * Request from peer device to synchronize with the periodic advertiser 712 * denoted by the @p recv_state. To notify the Broadcast Assistant about 713 * any pending sync 714 * 715 * @param conn Pointer to the connection requesting the 716 * periodic advertising sync. 717 * @param recv_state Pointer to the receive state that is being 718 * requested for periodic advertising sync. 719 * @param past_avail True if periodic advertising sync transfer is available. 720 * @param pa_interval The periodic advertising interval. 721 * 722 * @return 0 in case of accept, or other value to reject. 723 */ 724 int (*pa_sync_req)(struct bt_conn *conn, 725 const struct bt_bap_scan_delegator_recv_state *recv_state, 726 bool past_avail, uint16_t pa_interval); 727 728 /** 729 * @brief Periodic advertising sync termination request 730 * 731 * Request from peer device to terminate the periodic advertiser sync 732 * denoted by the @p recv_state. 733 * 734 * @param conn Pointer to the connection requesting the periodic 735 * advertising sync termination. 736 * @param recv_state Pointer to the receive state that is being 737 * requested for periodic advertising sync. 738 * 739 * @return 0 in case of success or negative value in case of error. 740 */ 741 int (*pa_sync_term_req)(struct bt_conn *conn, 742 const struct bt_bap_scan_delegator_recv_state *recv_state); 743 744 /** 745 * @brief Broadcast code received 746 * 747 * Broadcast code received from a broadcast assistant 748 * 749 * @param conn Pointer to the connection providing the 750 * broadcast code. 751 * @param recv_state Pointer to the receive state the broadcast code 752 * is being provided for. 753 * @param broadcast_code The 16-octet broadcast code 754 */ 755 void (*broadcast_code)(struct bt_conn *conn, 756 const struct bt_bap_scan_delegator_recv_state *recv_state, 757 const uint8_t broadcast_code[BT_ISO_BROADCAST_CODE_SIZE]); 758 /** 759 * @brief Broadcast Isochronous Stream synchronize request 760 * 761 * Request from Broadcast Assistant device to modify the Broadcast 762 * Isochronous Stream states. The request shall be fulfilled with 763 * accordance to the @p bis_sync_req within reasonable time. The 764 * Broadcast Assistant may also request fewer, or none, indexes to 765 * be synchronized. 766 * 767 * @param[in] conn Pointer to the connection of the 768 * Broadcast Assistant requesting the sync. 769 * @param[in] recv_state Pointer to the receive state that is being 770 * requested for the sync. 771 * @param[in] bis_sync_req Array of bitfields of which BIS indexes 772 * that is requested to sync for each subgroup 773 * by the Broadcast Assistant. A value of 0 774 * indicates a request to terminate the BIG 775 * sync. 776 * 777 * @return 0 in case of accept, or other value to reject. 778 */ 779 int (*bis_sync_req)(struct bt_conn *conn, 780 const struct bt_bap_scan_delegator_recv_state *recv_state, 781 const uint32_t bis_sync_req[BT_BAP_BASS_MAX_SUBGROUPS]); 782 /** 783 * @brief Broadcast Assistant scanning state callback 784 * 785 * Callback triggered when a Broadcast Assistant notifies the Scan Delegator about the 786 * assistants scanning state. 787 * 788 * @param conn Pointer to the connection that initiated the scan. 789 * @param is_scanning true if scanning started, false if scanning stopped. 790 */ 791 void (*scanning_state)(struct bt_conn *conn, bool is_scanning); 792 }; 793 794 /** Structure holding information of audio stream endpoint */ 795 struct bt_bap_ep_info { 796 /** The ID of the endpoint */ 797 uint8_t id; 798 799 /** The state of the endpoint */ 800 enum bt_bap_ep_state state; 801 802 /** Capabilities type */ 803 enum bt_audio_dir dir; 804 805 /** The isochronous channel associated with the endpoint. */ 806 struct bt_iso_chan *iso_chan; 807 808 /** @brief True if the stream associated with the endpoint is able to send data */ 809 bool can_send; 810 811 /** @brief True if the stream associated with the endpoint is able to receive data */ 812 bool can_recv; 813 814 /** Pointer to paired endpoint if the endpoint is part of a bidirectional CIS, 815 * otherwise NULL 816 */ 817 struct bt_bap_ep *paired_ep; 818 819 /** Pointer to the preferred QoS settings associated with the endpoint */ 820 const struct bt_bap_qos_cfg_pref *qos_pref; 821 }; 822 823 /** 824 * @brief Return structure holding information of audio stream endpoint 825 * 826 * @param ep The audio stream endpoint object. 827 * @param info The structure object to be filled with the info. 828 * 829 * @retval 0 in case of success 830 * @retval -EINVAL if @p ep or @p info are NULL 831 */ 832 int bt_bap_ep_get_info(const struct bt_bap_ep *ep, struct bt_bap_ep_info *info); 833 834 /** 835 * @brief Basic Audio Profile stream structure. 836 * 837 * Streams represents a stream configuration of a Remote Endpoint and a Local Capability. 838 * 839 * @note Streams are unidirectional but can be paired with other streams to use a bidirectional 840 * connected isochronous stream. 841 */ 842 struct bt_bap_stream { 843 /** Connection reference */ 844 struct bt_conn *conn; 845 846 /** Endpoint reference */ 847 struct bt_bap_ep *ep; 848 849 /** Codec Configuration */ 850 struct bt_audio_codec_cfg *codec_cfg; 851 852 /** QoS Configuration */ 853 struct bt_bap_qos_cfg *qos; 854 855 /** Audio stream operations */ 856 struct bt_bap_stream_ops *ops; 857 858 /** Stream user data */ 859 void *user_data; 860 861 #if defined(CONFIG_BT_BAP_UNICAST_CLIENT) || defined(__DOXYGEN__) 862 /** @cond INTERNAL_HIDDEN */ 863 /** 864 * @brief Audio ISO reference 865 * 866 * This is only used for Unicast Client streams, and is handled internally. 867 */ 868 struct bt_bap_iso *bap_iso; 869 #endif /* CONFIG_BT_BAP_UNICAST_CLIENT */ 870 871 /** Unicast or Broadcast group - Used internally */ 872 void *group; 873 874 #if defined(CONFIG_BT_BAP_DEBUG_STREAM_SEQ_NUM) || defined(__DOXYGEN__) 875 /** Previously sent sequence number */ 876 uint16_t _prev_seq_num; 877 #endif /* CONFIG_BT_BAP_DEBUG_STREAM_SEQ_NUM */ 878 879 /** Internally used list node */ 880 sys_snode_t _node; 881 /** @endcond */ 882 }; 883 884 /** @brief Stream operation. */ 885 struct bt_bap_stream_ops { 886 #if defined(CONFIG_BT_BAP_UNICAST) || defined(__DOXYGEN__) 887 /** 888 * @brief Stream configured callback 889 * 890 * Configured callback is called whenever an Audio Stream has been configured. 891 * 892 * @param stream Stream object that has been configured. 893 * @param pref Remote QoS preferences. 894 */ 895 void (*configured)(struct bt_bap_stream *stream, const struct bt_bap_qos_cfg_pref *pref); 896 897 /** 898 * @brief Stream QoS set callback 899 * 900 * QoS set callback is called whenever an Audio Stream Quality of Service has been set or 901 * updated. 902 * 903 * @param stream Stream object that had its QoS updated. 904 */ 905 void (*qos_set)(struct bt_bap_stream *stream); 906 907 /** 908 * @brief Stream enabled callback 909 * 910 * Enabled callback is called whenever an Audio Stream has been enabled. 911 * 912 * @param stream Stream object that has been enabled. 913 */ 914 void (*enabled)(struct bt_bap_stream *stream); 915 916 /** 917 * @brief Stream metadata updated callback 918 * 919 * Metadata Updated callback is called whenever an Audio Stream's metadata has been 920 * updated. 921 * 922 * @param stream Stream object that had its metadata updated. 923 */ 924 void (*metadata_updated)(struct bt_bap_stream *stream); 925 926 /** 927 * @brief Stream disabled callback 928 * 929 * Disabled callback is called whenever an Audio Stream has been disabled. 930 * 931 * @param stream Stream object that has been disabled. 932 */ 933 void (*disabled)(struct bt_bap_stream *stream); 934 935 /** 936 * @brief Stream released callback 937 * 938 * Released callback is called whenever a Audio Stream has been released and can be 939 * deallocated. 940 * 941 * @param stream Stream object that has been released. 942 */ 943 void (*released)(struct bt_bap_stream *stream); 944 #endif /* CONFIG_BT_BAP_UNICAST */ 945 946 /** 947 * @brief Stream started callback 948 * 949 * Started callback is called whenever an Audio Stream has been started 950 * and will be usable for streaming. 951 * 952 * @param stream Stream object that has been started. 953 */ 954 void (*started)(struct bt_bap_stream *stream); 955 956 /** 957 * @brief Stream stopped callback 958 * 959 * Stopped callback is called whenever an Audio Stream has been stopped. 960 * 961 * @param stream Stream object that has been stopped. 962 * @param reason BT_HCI_ERR_* reason for the disconnection. 963 */ 964 void (*stopped)(struct bt_bap_stream *stream, uint8_t reason); 965 966 #if defined(CONFIG_BT_AUDIO_RX) || defined(__DOXYGEN__) 967 /** 968 * @brief Stream audio HCI receive callback. 969 * 970 * This callback is only used if the ISO data path is HCI. 971 * 972 * @param stream Stream object. 973 * @param info Pointer to the metadata for the buffer. The lifetime of the pointer is 974 * linked to the lifetime of the net_buf. Metadata such as sequence number and 975 * timestamp can be provided by the bluetooth controller. 976 * @param buf Buffer containing incoming audio data. 977 */ 978 void (*recv)(struct bt_bap_stream *stream, const struct bt_iso_recv_info *info, 979 struct net_buf *buf); 980 #endif /* CONFIG_BT_AUDIO_RX */ 981 982 #if defined(CONFIG_BT_AUDIO_TX) || defined(__DOXYGEN__) 983 /** 984 * @brief Stream audio HCI sent callback 985 * 986 * This callback will be called once the controller marks the SDU 987 * as completed. When the controller does so is implementation 988 * dependent. It could be after the SDU is enqueued for transmission, 989 * or after it is sent on air or flushed. 990 * 991 * This callback is only used if the ISO data path is HCI. 992 * 993 * @param stream Stream object. 994 */ 995 void (*sent)(struct bt_bap_stream *stream); 996 #endif /* CONFIG_BT_AUDIO_TX */ 997 998 /** 999 * @brief Isochronous channel connected callback 1000 * 1001 * If this callback is provided it will be called whenever the isochronous channel for the 1002 * stream has been connected. This does not mean that the stream is ready to be used, which 1003 * is indicated by the @ref bt_bap_stream_ops.started callback. 1004 * 1005 * If the stream shares an isochronous channel with another stream, then this callback may 1006 * still be called, without the stream going into the started state. 1007 * 1008 * @param stream Stream object. 1009 */ 1010 void (*connected)(struct bt_bap_stream *stream); 1011 1012 /** 1013 * @brief Isochronous channel disconnected callback 1014 * 1015 * If this callback is provided it will be called whenever the isochronous channel is 1016 * disconnected, including when a connection gets rejected. 1017 * 1018 * If the stream shares an isochronous channel with another stream, then this callback may 1019 * not be called, even if the stream is leaving the streaming state. 1020 * 1021 * @param stream Stream object. 1022 * @param reason BT_HCI_ERR_* reason for the disconnection. 1023 */ 1024 void (*disconnected)(struct bt_bap_stream *stream, uint8_t reason); 1025 }; 1026 1027 /** Structure for registering Unicast Server */ 1028 struct bt_bap_unicast_server_register_param { 1029 /** 1030 * @brief Sink Count to register. 1031 * 1032 * Should be in range 0 to @kconfig{CONFIG_BT_ASCS_MAX_ASE_SNK_COUNT} 1033 */ 1034 uint8_t snk_cnt; 1035 1036 /** @brief Source Count to register. 1037 * 1038 * Should be in range 0 to @kconfig{CONFIG_BT_ASCS_MAX_ASE_SRC_COUNT} 1039 */ 1040 uint8_t src_cnt; 1041 }; 1042 1043 /** 1044 * @brief Register Audio callbacks for a stream. 1045 * 1046 * Register Audio callbacks for a stream. 1047 * 1048 * @param stream Stream object. 1049 * @param ops Stream operations structure. 1050 */ 1051 void bt_bap_stream_cb_register(struct bt_bap_stream *stream, struct bt_bap_stream_ops *ops); 1052 1053 /** 1054 * @brief Configure Audio Stream 1055 * 1056 * This procedure is used by a client to configure a new stream using the 1057 * remote endpoint, local capability and codec configuration. 1058 * 1059 * @param conn Connection object 1060 * @param stream Stream object being configured 1061 * @param ep Remote Audio Endpoint being configured 1062 * @param codec_cfg Codec configuration 1063 * 1064 * @return Allocated Audio Stream object or NULL in case of error. 1065 */ 1066 int bt_bap_stream_config(struct bt_conn *conn, struct bt_bap_stream *stream, struct bt_bap_ep *ep, 1067 struct bt_audio_codec_cfg *codec_cfg); 1068 1069 /** 1070 * @brief Reconfigure Audio Stream 1071 * 1072 * This procedure is used by a unicast client or unicast server to reconfigure 1073 * a stream to use a different local codec configuration. 1074 * 1075 * This can only be done for unicast streams. 1076 * 1077 * @param stream Stream object being reconfigured 1078 * @param codec_cfg Codec configuration 1079 * 1080 * @return 0 in case of success or negative value in case of error. 1081 */ 1082 int bt_bap_stream_reconfig(struct bt_bap_stream *stream, struct bt_audio_codec_cfg *codec_cfg); 1083 1084 /** 1085 * @brief Configure Audio Stream QoS 1086 * 1087 * This procedure is used by a client to configure the Quality of Service of streams in a unicast 1088 * group. All streams in the group for the specified @p conn will have the Quality of Service 1089 * configured. This shall only be used to configure unicast streams. 1090 * 1091 * @param conn Connection object 1092 * @param group Unicast group object 1093 * 1094 * @return 0 in case of success or negative value in case of error. 1095 */ 1096 int bt_bap_stream_qos(struct bt_conn *conn, struct bt_bap_unicast_group *group); 1097 1098 /** 1099 * @brief Enable Audio Stream 1100 * 1101 * This procedure is used by a client to enable a stream. 1102 * 1103 * This shall only be called for unicast streams, as broadcast streams will always be enabled once 1104 * created. 1105 * 1106 * @param stream Stream object 1107 * @param meta Metadata 1108 * @param meta_len Metadata length 1109 * 1110 * @return 0 in case of success or negative value in case of error. 1111 */ 1112 int bt_bap_stream_enable(struct bt_bap_stream *stream, const uint8_t meta[], size_t meta_len); 1113 1114 /** 1115 * @brief Change Audio Stream Metadata 1116 * 1117 * This procedure is used by a unicast client or unicast server to change the metadata of a stream. 1118 * 1119 * @param stream Stream object 1120 * @param meta Metadata 1121 * @param meta_len Metadata length 1122 * 1123 * @return 0 in case of success or negative value in case of error. 1124 */ 1125 int bt_bap_stream_metadata(struct bt_bap_stream *stream, const uint8_t meta[], size_t meta_len); 1126 1127 /** 1128 * @brief Disable Audio Stream 1129 * 1130 * This procedure is used by a unicast client or unicast server to disable a stream. 1131 * 1132 * This shall only be called for unicast streams, as broadcast streams will 1133 * always be enabled once created. 1134 * 1135 * @param stream Stream object 1136 * 1137 * @return 0 in case of success or negative value in case of error. 1138 */ 1139 int bt_bap_stream_disable(struct bt_bap_stream *stream); 1140 1141 /** 1142 * @brief Connect unicast audio stream 1143 * 1144 * This procedure is used by a unicast client to connect the connected isochronous stream (CIS) 1145 * associated with the audio stream. If two audio streams share a CIS, then this only needs to be 1146 * done once for those streams. This can only be done for streams in the QoS configured or enabled 1147 * states. 1148 * 1149 * The bt_bap_stream_ops.connected() callback will be called on the streams once this has finished. 1150 * 1151 * This shall only be called for unicast streams, and only as the unicast client 1152 * (@kconfig{CONFIG_BT_BAP_UNICAST_CLIENT}). 1153 * 1154 * @param stream Stream object 1155 * 1156 * @retval 0 in case of success 1157 * @retval -EINVAL if the stream, endpoint, ISO channel or connection is NULL 1158 * @retval -EBADMSG if the stream or ISO channel is in an invalid state for connection 1159 * @retval -EOPNOTSUPP if the role of the stream is not @ref BT_HCI_ROLE_CENTRAL 1160 * @retval -EALREADY if the ISO channel is already connecting or connected 1161 * @retval -EBUSY if another ISO channel is connecting 1162 * @retval -ENOEXEC if otherwise rejected by the ISO layer 1163 */ 1164 int bt_bap_stream_connect(struct bt_bap_stream *stream); 1165 1166 /** 1167 * @brief Start Audio Stream 1168 * 1169 * This procedure is used by a unicast client or unicast server to make a stream start streaming. 1170 * 1171 * For the unicast client, this will send the receiver start ready command to the unicast server for 1172 * @ref BT_AUDIO_DIR_SOURCE ASEs. The CIS is required to be connected first by 1173 * bt_bap_stream_connect() before the command can be sent. 1174 * 1175 * For the unicast server, this will execute the receiver start ready command on the unicast server 1176 * for @ref BT_AUDIO_DIR_SINK ASEs. If the CIS is not connected yet, the stream will go into the 1177 * streaming state as soon as the CIS is connected. 1178 * 1179 * This shall only be called for unicast streams. 1180 * 1181 * Broadcast sinks will always be started once synchronized, and broadcast 1182 * source streams shall be started with bt_bap_broadcast_source_start(). 1183 * 1184 * @param stream Stream object 1185 * 1186 * @return 0 in case of success or negative value in case of error. 1187 */ 1188 int bt_bap_stream_start(struct bt_bap_stream *stream); 1189 1190 /** 1191 * @brief Stop Audio Stream 1192 * 1193 * This procedure is used by a client to make a stream stop streaming. 1194 * 1195 * This shall only be called for unicast streams. 1196 * Broadcast sinks cannot be stopped. 1197 * Broadcast sources shall be stopped with bt_bap_broadcast_source_stop(). 1198 * 1199 * @param stream Stream object 1200 * 1201 * @retval 0 Success 1202 * @retval -EINVAL The @p stream does not have an endpoint or a connection, of the stream's 1203 * connection's role is not @p BT_HCI_ROLE_CENTRAL 1204 * @retval -EBADMSG The state of the @p stream endpoint is not @ref BT_BAP_EP_STATE_DISABLING 1205 * @retval -EALREADY The CIS state of the @p is not in a connected state, and thus is already 1206 * stopping 1207 * @retval -EBUSY The @p stream is busy with another operation 1208 * @retval -ENOTCONN The @p stream ACL connection is not connected 1209 * @retval -ENOMEM No memory to send request 1210 * @retval -ENOEXEC The request was rejected by GATT 1211 * @return 0 in case of success or negative value in case of error. 1212 */ 1213 int bt_bap_stream_stop(struct bt_bap_stream *stream); 1214 1215 /** 1216 * @brief Release Audio Stream 1217 * 1218 * This procedure is used by a unicast client or unicast server to release a unicast stream. 1219 * 1220 * Broadcast sink streams cannot be released, but can be deleted by bt_bap_broadcast_sink_delete(). 1221 * Broadcast source streams cannot be released, but can be deleted by 1222 * bt_bap_broadcast_source_delete(). 1223 * 1224 * @param stream Stream object 1225 * 1226 * @return 0 in case of success or negative value in case of error. 1227 */ 1228 int bt_bap_stream_release(struct bt_bap_stream *stream); 1229 1230 /** 1231 * @brief Send data to Audio stream without timestamp 1232 * 1233 * Send data from buffer to the stream. 1234 * 1235 * @note Support for sending must be supported, determined by @kconfig{CONFIG_BT_AUDIO_TX}. 1236 * 1237 * @param stream Stream object. 1238 * @param buf Buffer containing data to be sent. 1239 * @param seq_num Packet Sequence number. This value shall be incremented for each call to this 1240 * function and at least once per SDU interval for a specific channel. 1241 * 1242 * @return Bytes sent in case of success or negative value in case of error. 1243 */ 1244 int bt_bap_stream_send(struct bt_bap_stream *stream, struct net_buf *buf, uint16_t seq_num); 1245 1246 /** 1247 * @brief Send data to Audio stream with timestamp 1248 * 1249 * Send data from buffer to the stream. 1250 * 1251 * @note Support for sending must be supported, determined by @kconfig{CONFIG_BT_AUDIO_TX}. 1252 * 1253 * @param stream Stream object. 1254 * @param buf Buffer containing data to be sent. 1255 * @param seq_num Packet Sequence number. This value shall be incremented for each call to this 1256 * function and at least once per SDU interval for a specific channel. 1257 * @param ts Timestamp of the SDU in microseconds (us). This value can be used to transmit 1258 * multiple SDUs in the same SDU interval in a CIG or BIG. 1259 * 1260 * @return Bytes sent in case of success or negative value in case of error. 1261 */ 1262 int bt_bap_stream_send_ts(struct bt_bap_stream *stream, struct net_buf *buf, uint16_t seq_num, 1263 uint32_t ts); 1264 1265 /** 1266 * @brief Get ISO transmission timing info for a Basic Audio Profile stream 1267 * 1268 * Reads timing information for transmitted ISO packet on an ISO channel. 1269 * The HCI_LE_Read_ISO_TX_Sync HCI command is used to retrieve this information from the controller. 1270 * 1271 * @note An SDU must have already been successfully transmitted on the ISO channel 1272 * for this function to return successfully. 1273 * Support for sending must be supported, determined by @kconfig{CONFIG_BT_AUDIO_TX}. 1274 * 1275 * @param[in] stream Stream object. 1276 * @param[out] info Transmit info object. 1277 * 1278 * @retval 0 on success 1279 * @retval -EINVAL if the stream is invalid, if the stream is not configured for sending or if it is 1280 * not connected with a isochronous stream 1281 * @retval Any return value from bt_iso_chan_get_tx_sync() 1282 */ 1283 int bt_bap_stream_get_tx_sync(struct bt_bap_stream *stream, struct bt_iso_tx_info *info); 1284 1285 /** 1286 * @defgroup bt_bap_unicast_server BAP Unicast Server APIs 1287 * @ingroup bt_bap 1288 * @{ 1289 */ 1290 1291 /** Unicast Server callback structure */ 1292 struct bt_bap_unicast_server_cb { 1293 /** 1294 * @brief Endpoint config request callback 1295 * 1296 * Config callback is called whenever an endpoint is requested to be 1297 * configured 1298 * 1299 * @param[in] conn Connection object. 1300 * @param[in] ep Local Audio Endpoint being configured. 1301 * @param[in] dir Direction of the endpoint. 1302 * @param[in] codec_cfg Codec configuration. 1303 * @param[out] stream Pointer to stream that will be configured for the endpoint. 1304 * @param[out] pref Pointer to a QoS preference object that shall be populated with 1305 * values. Invalid values will reject the codec configuration request. 1306 * @param[out] rsp Object for the ASE operation response. Only used if the return 1307 * value is non-zero. 1308 * 1309 * @return 0 in case of success or negative value in case of error. 1310 */ 1311 int (*config)(struct bt_conn *conn, const struct bt_bap_ep *ep, enum bt_audio_dir dir, 1312 const struct bt_audio_codec_cfg *codec_cfg, struct bt_bap_stream **stream, 1313 struct bt_bap_qos_cfg_pref *const pref, struct bt_bap_ascs_rsp *rsp); 1314 1315 /** 1316 * @brief Stream reconfig request callback 1317 * 1318 * Reconfig callback is called whenever an Audio Stream needs to be 1319 * reconfigured with different codec configuration. 1320 * 1321 * @param[in] stream Stream object being reconfigured. 1322 * @param[in] dir Direction of the endpoint. 1323 * @param[in] codec_cfg Codec configuration. 1324 * @param[out] pref Pointer to a QoS preference object that shall be populated with 1325 * values. Invalid values will reject the codec configuration request. 1326 * @param[out] rsp Object for the ASE operation response. Only used if the return 1327 * value is non-zero. 1328 * 1329 * @return 0 in case of success or negative value in case of error. 1330 */ 1331 int (*reconfig)(struct bt_bap_stream *stream, enum bt_audio_dir dir, 1332 const struct bt_audio_codec_cfg *codec_cfg, 1333 struct bt_bap_qos_cfg_pref *const pref, struct bt_bap_ascs_rsp *rsp); 1334 1335 /** 1336 * @brief Stream QoS request callback 1337 * 1338 * QoS callback is called whenever an Audio Stream Quality of 1339 * Service needs to be configured. 1340 * 1341 * @param[in] stream Stream object being reconfigured. 1342 * @param[in] qos Quality of Service configuration. 1343 * @param[out] rsp Object for the ASE operation response. Only used if the return 1344 * value is non-zero. 1345 * 1346 * @return 0 in case of success or negative value in case of error. 1347 */ 1348 int (*qos)(struct bt_bap_stream *stream, const struct bt_bap_qos_cfg *qos, 1349 struct bt_bap_ascs_rsp *rsp); 1350 1351 /** 1352 * @brief Stream Enable request callback 1353 * 1354 * Enable callback is called whenever an Audio Stream is requested to be enabled to stream. 1355 * 1356 * @param[in] stream Stream object being enabled. 1357 * @param[in] meta Metadata entries. 1358 * @param[in] meta_len Length of metadata. 1359 * @param[out] rsp Object for the ASE operation response. Only used if the return 1360 * value is non-zero. 1361 * 1362 * @return 0 in case of success or negative value in case of error. 1363 */ 1364 int (*enable)(struct bt_bap_stream *stream, const uint8_t meta[], size_t meta_len, 1365 struct bt_bap_ascs_rsp *rsp); 1366 1367 /** 1368 * @brief Stream Start request callback 1369 * 1370 * Start callback is called whenever an Audio Stream is requested to start streaming. 1371 * 1372 * @param[in] stream Stream object. 1373 * @param[out] rsp Object for the ASE operation response. Only used if the return 1374 * value is non-zero. 1375 * 1376 * @return 0 in case of success or negative value in case of error. 1377 */ 1378 int (*start)(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp); 1379 1380 /** 1381 * @brief Stream Metadata update request callback 1382 * 1383 * Metadata callback is called whenever an Audio Stream is requested to update its metadata. 1384 * 1385 * @param[in] stream Stream object. 1386 * @param[in] meta Metadata entries. 1387 * @param[in] meta_len Length of metadata. 1388 * @param[out] rsp Object for the ASE operation response. Only used if the return 1389 * value is non-zero. 1390 * 1391 * @return 0 in case of success or negative value in case of error. 1392 */ 1393 int (*metadata)(struct bt_bap_stream *stream, const uint8_t meta[], size_t meta_len, 1394 struct bt_bap_ascs_rsp *rsp); 1395 1396 /** 1397 * @brief Stream Disable request callback 1398 * 1399 * Disable callback is called whenever an Audio Stream is requested to disable the stream. 1400 * 1401 * @param[in] stream Stream object being disabled. 1402 * @param[out] rsp Object for the ASE operation response. Only used if the return 1403 * value is non-zero. 1404 * 1405 * @return 0 in case of success or negative value in case of error. 1406 */ 1407 int (*disable)(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp); 1408 1409 /** 1410 * @brief Stream Stop callback 1411 * 1412 * Stop callback is called whenever an Audio Stream is requested to stop streaming. 1413 * 1414 * @param[in] stream Stream object. 1415 * @param[out] rsp Object for the ASE operation response. Only used if the return 1416 * value is non-zero. 1417 * 1418 * @return 0 in case of success or negative value in case of error. 1419 */ 1420 int (*stop)(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp); 1421 1422 /** 1423 * @brief Stream release callback 1424 * 1425 * Release callback is called whenever a new Audio Stream needs to be released and thus 1426 * deallocated. 1427 * 1428 * @param[in] stream Stream object. 1429 * @param[out] rsp Object for the ASE operation response. Only used if the return 1430 * value is non-zero. 1431 * 1432 * @return 0 in case of success or negative value in case of error. 1433 */ 1434 int (*release)(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp); 1435 }; 1436 1437 /** 1438 * @brief Register the Unicast Server. 1439 * 1440 * Register the Unicast Server. Only a single Unicast Server can be registered at any one time. 1441 * This will register ASCS in the GATT database. 1442 * 1443 * @param param Registration parameters for ascs. 1444 * 1445 * @return 0 in case of success, negative error code otherwise. 1446 */ 1447 int bt_bap_unicast_server_register(const struct bt_bap_unicast_server_register_param *param); 1448 1449 /** 1450 * @brief Unregister the Unicast Server. 1451 * 1452 * Unregister the Unicast Server. 1453 * This will unregister ASCS in the GATT database. 1454 * Before calling this function, any callbacks registered through 1455 * bt_bap_unicast_server_register_cb() needs to be unregistered with 1456 * bt_bap_unicast_server_unregister_cb(). 1457 * 1458 * Calling this function will issue an release operation on any ASE 1459 * in a non-idle state. 1460 * 1461 * @return 0 in case of success, negative error code otherwise. 1462 */ 1463 int bt_bap_unicast_server_unregister(void); 1464 1465 /** 1466 * @brief Register unicast server callbacks. 1467 * 1468 * Only one callback structure can be registered, and attempting to 1469 * registering more than one will result in an error. 1470 * Prior to calling this function the Unicast Server needs to be 1471 * registered with bt_bap_unicast_server_register(). 1472 * 1473 * @param cb Unicast server callback structure. 1474 * 1475 * @return 0 in case of success or negative value in case of error. 1476 */ 1477 int bt_bap_unicast_server_register_cb(const struct bt_bap_unicast_server_cb *cb); 1478 1479 /** 1480 * @brief Unregister unicast server callbacks. 1481 * 1482 * May only unregister a callback structure that has previously been 1483 * registered by bt_bap_unicast_server_register_cb(). 1484 * 1485 * Calling this function will issue an release operation on any ASE 1486 * in a non-idle state. 1487 * 1488 * @param cb Unicast server callback structure. 1489 * 1490 * @return 0 in case of success or negative value in case of error. 1491 */ 1492 int bt_bap_unicast_server_unregister_cb(const struct bt_bap_unicast_server_cb *cb); 1493 1494 /** 1495 * @typedef bt_bap_ep_func_t 1496 * @brief The callback function called for each endpoint. 1497 * 1498 * @param ep The structure object with endpoint info. 1499 * @param user_data Data to pass to the function. 1500 */ 1501 typedef void (*bt_bap_ep_func_t)(struct bt_bap_ep *ep, void *user_data); 1502 1503 /** 1504 * @brief Iterate through all endpoints of the given connection. 1505 * 1506 * @param conn Connection object 1507 * @param func Function to call for each endpoint. 1508 * @param user_data Data to pass to the callback function. 1509 */ 1510 void bt_bap_unicast_server_foreach_ep(struct bt_conn *conn, bt_bap_ep_func_t func, void *user_data); 1511 1512 /** 1513 * @brief Initialize and configure a new ASE. 1514 * 1515 * @param conn Connection object 1516 * @param stream Configured stream object to be attached to the ASE 1517 * @param codec_cfg Codec configuration 1518 * @param qos_pref Audio Stream Quality of Service Preference 1519 * 1520 * @return 0 in case of success or negative value in case of error. 1521 */ 1522 int bt_bap_unicast_server_config_ase(struct bt_conn *conn, struct bt_bap_stream *stream, 1523 struct bt_audio_codec_cfg *codec_cfg, 1524 const struct bt_bap_qos_cfg_pref *qos_pref); 1525 1526 /** @} */ /* End of group bt_bap_unicast_server */ 1527 1528 /** 1529 * @defgroup bt_bap_unicast_client BAP Unicast Client APIs 1530 * @ingroup bt_bap 1531 * @{ 1532 */ 1533 1534 /** Parameter struct for each stream in the unicast group */ 1535 struct bt_bap_unicast_group_stream_param { 1536 /** Pointer to a stream object. */ 1537 struct bt_bap_stream *stream; 1538 1539 /** The QoS settings for the stream object. */ 1540 struct bt_bap_qos_cfg *qos; 1541 }; 1542 1543 /** 1544 * @brief Parameter struct for the unicast group functions 1545 * 1546 * Parameter struct for the bt_bap_unicast_group_create() and 1547 * bt_bap_unicast_group_add_streams() functions. 1548 */ 1549 struct bt_bap_unicast_group_stream_pair_param { 1550 /** Pointer to a receiving stream parameters. */ 1551 struct bt_bap_unicast_group_stream_param *rx_param; 1552 1553 /** Pointer to a transmitting stream parameters. */ 1554 struct bt_bap_unicast_group_stream_param *tx_param; 1555 }; 1556 1557 /** Parameters for the creating unicast groups with bt_bap_unicast_group_create() */ 1558 struct bt_bap_unicast_group_param { 1559 /** The number of parameters in @p params */ 1560 size_t params_count; 1561 1562 /** Array of stream parameters */ 1563 struct bt_bap_unicast_group_stream_pair_param *params; 1564 1565 /** 1566 * @brief Unicast Group packing mode. 1567 * 1568 * @ref BT_ISO_PACKING_SEQUENTIAL or @ref BT_ISO_PACKING_INTERLEAVED. 1569 * 1570 * @note This is a recommendation to the controller, which the controller may ignore. 1571 */ 1572 uint8_t packing; 1573 1574 #if defined(CONFIG_BT_ISO_TEST_PARAMS) || defined(__DOXYGEN__) 1575 /** 1576 * @brief Central to Peripheral flush timeout 1577 * 1578 * The flush timeout in multiples of ISO_Interval for each payload sent 1579 * from the Central to Peripheral. 1580 * 1581 * Value range from @ref BT_ISO_FT_MIN to @ref BT_ISO_FT_MAX 1582 */ 1583 uint8_t c_to_p_ft; 1584 1585 /** 1586 * @brief Peripheral to Central flush timeout 1587 * 1588 * The flush timeout in multiples of ISO_Interval for each payload sent 1589 * from the Peripheral to Central. 1590 * 1591 * Value range from @ref BT_ISO_FT_MIN to @ref BT_ISO_FT_MAX. 1592 */ 1593 uint8_t p_to_c_ft; 1594 1595 /** 1596 * @brief ISO interval 1597 * 1598 * Time between consecutive CIS anchor points. 1599 * 1600 * Value range from @ref BT_ISO_ISO_INTERVAL_MIN to @ref BT_ISO_ISO_INTERVAL_MAX. 1601 */ 1602 uint16_t iso_interval; 1603 #endif /* CONFIG_BT_ISO_TEST_PARAMS */ 1604 }; 1605 1606 /** 1607 * @brief Create unicast group. 1608 * 1609 * Create a new audio unicast group with one or more audio streams as a unicast client. 1610 * All streams shall share the same framing. 1611 * All streams in the same direction shall share the same interval and latency (see 1612 * @ref bt_bap_qos_cfg). 1613 * 1614 * @param[in] param The unicast group create parameters. 1615 * @param[out] unicast_group Pointer to the unicast group created. 1616 * 1617 * @return Zero on success or (negative) error code otherwise. 1618 */ 1619 int bt_bap_unicast_group_create(struct bt_bap_unicast_group_param *param, 1620 struct bt_bap_unicast_group **unicast_group); 1621 1622 /** 1623 * @brief Reconfigure unicast group. 1624 * 1625 * Reconfigure a unicast group with one or more audio streams as a unicast client. 1626 * All streams shall share the same framing. 1627 * All streams in the same direction shall share the same interval and latency (see 1628 * @ref bt_bap_qos_cfg). 1629 * All streams in @p param shall already belong to @p unicast_group. 1630 * Use bt_bap_unicast_group_add_streams() to add additional streams. 1631 * 1632 * @param unicast_group Pointer to the unicast group created. 1633 * @param param The unicast group reconfigure parameters. 1634 * 1635 * @return Zero on success or (negative) error code otherwise. 1636 */ 1637 int bt_bap_unicast_group_reconfig(struct bt_bap_unicast_group *unicast_group, 1638 const struct bt_bap_unicast_group_param *param); 1639 1640 /** 1641 * @brief Add streams to a unicast group as a unicast client 1642 * 1643 * This function can be used to add additional streams to a bt_bap_unicast_group. 1644 * 1645 * This can be called at any time before any of the streams in the group has been started 1646 * (see bt_bap_stream_ops.started()). 1647 * This can also be called after the streams have been stopped (see bt_bap_stream_ops.stopped()). 1648 * 1649 * Once a stream has been added to a unicast group, it cannot be removed. To remove a stream from a 1650 * group, the group must be deleted with bt_bap_unicast_group_delete(), but this will require all 1651 * streams in the group to be released first. 1652 * 1653 * @param unicast_group Pointer to the unicast group 1654 * @param params Array of stream parameters with streams being added to the group. 1655 * @param num_param Number of parameters in @p params. 1656 * 1657 * @return 0 in case of success or negative value in case of error. 1658 */ 1659 int bt_bap_unicast_group_add_streams(struct bt_bap_unicast_group *unicast_group, 1660 struct bt_bap_unicast_group_stream_pair_param params[], 1661 size_t num_param); 1662 1663 /** 1664 * @brief Delete audio unicast group. 1665 * 1666 * Delete a audio unicast group as a client. All streams in the group shall 1667 * be in the idle or configured state. 1668 * 1669 * @param unicast_group Pointer to the unicast group to delete 1670 * 1671 * @return Zero on success or (negative) error code otherwise. 1672 */ 1673 int bt_bap_unicast_group_delete(struct bt_bap_unicast_group *unicast_group); 1674 1675 /** Unicast Client callback structure */ 1676 struct bt_bap_unicast_client_cb { 1677 /** 1678 * @brief Remote Unicast Server Audio Locations 1679 * 1680 * This callback is called whenever the audio locations is read from 1681 * the server or otherwise notified to the client. 1682 * 1683 * @param conn Connection to the remote unicast server. 1684 * @param dir Direction of the location. 1685 * @param loc The location bitfield value. 1686 * 1687 * @return 0 in case of success or negative value in case of error. 1688 */ 1689 void (*location)(struct bt_conn *conn, enum bt_audio_dir dir, enum bt_audio_location loc); 1690 1691 /** 1692 * @brief Remote Unicast Server Available Contexts 1693 * 1694 * This callback is called whenever the available contexts are read 1695 * from the server or otherwise notified to the client. 1696 * 1697 * @param conn Connection to the remote unicast server. 1698 * @param snk_ctx The sink context bitfield value. 1699 * @param src_ctx The source context bitfield value. 1700 * 1701 * @return 0 in case of success or negative value in case of error. 1702 */ 1703 void (*available_contexts)(struct bt_conn *conn, enum bt_audio_context snk_ctx, 1704 enum bt_audio_context src_ctx); 1705 1706 /** 1707 * @brief Callback function for bt_bap_stream_config() and bt_bap_stream_reconfig(). 1708 * 1709 * Called when the codec configure operation is completed on the server. 1710 * 1711 * @param stream Stream the operation was performed on. 1712 * @param rsp_code Response code. 1713 * @param reason Reason code. 1714 */ 1715 void (*config)(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, 1716 enum bt_bap_ascs_reason reason); 1717 1718 /** 1719 * @brief Callback function for bt_bap_stream_qos(). 1720 * 1721 * Called when the QoS configure operation is completed on the server. 1722 * This will be called for each stream in the group that was being QoS 1723 * configured. 1724 * 1725 * @param stream Stream the operation was performed on. May be NULL if there is no stream 1726 * associated with the ASE ID sent by the server. 1727 * @param rsp_code Response code. 1728 * @param reason Reason code. 1729 */ 1730 void (*qos)(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, 1731 enum bt_bap_ascs_reason reason); 1732 1733 /** 1734 * @brief Callback function for bt_bap_stream_enable(). 1735 * 1736 * Called when the enable operation is completed on the server. 1737 * 1738 * @param stream Stream the operation was performed on. May be NULL if there is no stream 1739 * associated with the ASE ID sent by the server. 1740 * @param rsp_code Response code. 1741 * @param reason Reason code. 1742 */ 1743 void (*enable)(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, 1744 enum bt_bap_ascs_reason reason); 1745 1746 /** 1747 * @brief Callback function for bt_bap_stream_start(). 1748 * 1749 * Called when the start operation is completed on the server. This will 1750 * only be called if the stream supplied to bt_bap_stream_start() is 1751 * for a @ref BT_AUDIO_DIR_SOURCE endpoint. 1752 * 1753 * @param stream Stream the operation was performed on. May be NULL if there is no stream 1754 * associated with the ASE ID sent by the server. 1755 * @param rsp_code Response code. 1756 * @param reason Reason code. 1757 */ 1758 void (*start)(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, 1759 enum bt_bap_ascs_reason reason); 1760 1761 /** 1762 * @brief Callback function for bt_bap_stream_stop(). 1763 * 1764 * Called when the stop operation is completed on the server. This will 1765 * only be called if the stream supplied to bt_bap_stream_stop() is 1766 * for a @ref BT_AUDIO_DIR_SOURCE endpoint. 1767 * 1768 * @param stream Stream the operation was performed on. May be NULL if there is no stream 1769 * associated with the ASE ID sent by the server. 1770 * @param rsp_code Response code. 1771 * @param reason Reason code. 1772 */ 1773 void (*stop)(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, 1774 enum bt_bap_ascs_reason reason); 1775 1776 /** 1777 * @brief Callback function for bt_bap_stream_disable(). 1778 * 1779 * Called when the disable operation is completed on the server. 1780 * 1781 * @param stream Stream the operation was performed on. May be NULL if there is no stream 1782 * associated with the ASE ID sent by the server. 1783 * @param rsp_code Response code. 1784 * @param reason Reason code. 1785 */ 1786 void (*disable)(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, 1787 enum bt_bap_ascs_reason reason); 1788 1789 /** 1790 * @brief Callback function for bt_bap_stream_metadata(). 1791 * 1792 * Called when the metadata operation is completed on the server. 1793 * 1794 * @param stream Stream the operation was performed on. May be NULL if there is no stream 1795 * associated with the ASE ID sent by the server. 1796 * @param rsp_code Response code. 1797 * @param reason Reason code. 1798 */ 1799 void (*metadata)(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, 1800 enum bt_bap_ascs_reason reason); 1801 1802 /** 1803 * @brief Callback function for bt_bap_stream_release(). 1804 * 1805 * Called when the release operation is completed on the server. 1806 * 1807 * @param stream Stream the operation was performed on. May be NULL if there is no stream 1808 * associated with the ASE ID sent by the server. 1809 * @param rsp_code Response code. 1810 * @param reason Reason code. 1811 */ 1812 void (*release)(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, 1813 enum bt_bap_ascs_reason reason); 1814 1815 /** 1816 * @brief Remote Published Audio Capability (PAC) record discovered 1817 * 1818 * Called when a PAC record has been discovered as part of the discovery procedure. 1819 * 1820 * The @p codec is only valid while in the callback, so the values must be stored by the 1821 * receiver if future use is wanted. 1822 * 1823 * @param conn Connection to the remote unicast server. 1824 * @param dir The type of remote endpoints and capabilities discovered. 1825 * @param codec_cap Remote capabilities. 1826 * 1827 * If discovery procedure has complete both @p codec and @p ep are set to NULL. 1828 */ 1829 void (*pac_record)(struct bt_conn *conn, enum bt_audio_dir dir, 1830 const struct bt_audio_codec_cap *codec_cap); 1831 1832 /** 1833 * @brief Remote Audio Stream Endpoint (ASE) discovered 1834 * 1835 * Called when an ASE has been discovered as part of the discovery procedure. 1836 * 1837 * @param conn Connection to the remote unicast server. 1838 * @param dir The type of remote endpoints and capabilities discovered. 1839 * @param ep Remote endpoint. 1840 * 1841 * If discovery procedure has complete both @p codec and @p ep are set to NULL. 1842 */ 1843 void (*endpoint)(struct bt_conn *conn, enum bt_audio_dir dir, struct bt_bap_ep *ep); 1844 1845 /** 1846 * @brief BAP discovery callback function. 1847 * 1848 * If discovery procedure has completed @p ep is set to NULL and @p err is 0. 1849 * 1850 * @param conn Connection to the remote unicast server. 1851 * @param err Error value. 0 on success, GATT error on positive value or errno on 1852 * negative value. 1853 * @param dir The type of remote endpoints and capabilities discovered. 1854 * 1855 * If discovery procedure has complete both @p codec and @p ep are set to NULL. 1856 */ 1857 void (*discover)(struct bt_conn *conn, int err, enum bt_audio_dir dir); 1858 1859 /** @cond INTERNAL_HIDDEN */ 1860 /** Internally used field for list handling */ 1861 sys_snode_t _node; 1862 /** @endcond */ 1863 }; 1864 1865 /** 1866 * @brief Register unicast client callbacks. 1867 * 1868 * Only one callback structure can be registered, and attempting to 1869 * registering more than one will result in an error. 1870 * 1871 * @param cb Unicast client callback structure. 1872 * 1873 * @retval 0 Success 1874 * @retval -EINVAL @p cb is NULL. 1875 * @retval -EEXIST @p cb is already registered. 1876 */ 1877 int bt_bap_unicast_client_register_cb(struct bt_bap_unicast_client_cb *cb); 1878 1879 /** 1880 * @brief Discover remote capabilities and endpoints 1881 * 1882 * This procedure is used by a client to discover remote capabilities and 1883 * endpoints and notifies via params callback. 1884 * 1885 * @param conn Connection object 1886 * @param dir The type of remote endpoints and capabilities to discover. 1887 */ 1888 int bt_bap_unicast_client_discover(struct bt_conn *conn, enum bt_audio_dir dir); 1889 1890 /** @} */ /* End of group bt_bap_unicast_client */ 1891 /** 1892 * @brief BAP Broadcast APIs 1893 * @defgroup bt_bap_broadcast BAP Broadcast APIs 1894 * @ingroup bt_bap 1895 * @{ 1896 */ 1897 1898 /** @brief Abstract Broadcast Audio Source Endpoint (BASE) subgroup structure. */ 1899 struct bt_bap_base_subgroup; 1900 /** @brief Abstract Broadcast Audio Source Endpoint (BASE) structure. */ 1901 struct bt_bap_base; 1902 1903 /** Codec ID structure for a Broadcast Audio Source Endpoint (BASE) */ 1904 struct bt_bap_base_codec_id { 1905 /** Codec ID */ 1906 uint8_t id; 1907 /** Codec Company ID */ 1908 uint16_t cid; 1909 /** Codec Company Vendor ID */ 1910 uint16_t vid; 1911 }; 1912 1913 /** BIS structure for each BIS in a Broadcast Audio Source Endpoint (BASE) subgroup */ 1914 struct bt_bap_base_subgroup_bis { 1915 /** Unique index of the BIS */ 1916 uint8_t index; 1917 /** Codec Specific Data length. */ 1918 uint8_t data_len; 1919 /** Codec Specific Data */ 1920 uint8_t *data; 1921 }; 1922 1923 /** 1924 * @brief Generate a pointer to a BASE from periodic advertising data 1925 * 1926 * @param ad The periodic advertising data 1927 * 1928 * @retval NULL if the data does not contain a BASE 1929 * @retval Pointer to a bt_bap_base structure 1930 */ 1931 const struct bt_bap_base *bt_bap_base_get_base_from_ad(const struct bt_data *ad); 1932 1933 /** 1934 * @brief Get the size of a BASE 1935 * 1936 * @param base The BASE pointer 1937 * 1938 * @retval -EINVAL if arguments are invalid 1939 * @retval The size of the BASE 1940 */ 1941 int bt_bap_base_get_size(const struct bt_bap_base *base); 1942 1943 /** 1944 * @brief Get the presentation delay value of a BASE 1945 * 1946 * @param base The BASE pointer 1947 * 1948 * @retval -EINVAL if arguments are invalid 1949 * @retval The 24-bit presentation delay value 1950 */ 1951 int bt_bap_base_get_pres_delay(const struct bt_bap_base *base); 1952 1953 /** 1954 * @brief Get the subgroup count of a BASE 1955 * 1956 * @param base The BASE pointer 1957 * 1958 * @retval -EINVAL if arguments are invalid 1959 * @retval The 8-bit subgroup count value 1960 */ 1961 int bt_bap_base_get_subgroup_count(const struct bt_bap_base *base); 1962 1963 /** 1964 * @brief Get all BIS indexes of a BASE 1965 * 1966 * @param[in] base The BASE pointer 1967 * @param[out] bis_indexes 32-bit BIS index bitfield that will be populated 1968 * 1969 * @retval -EINVAL if arguments are invalid 1970 * @retval 0 on success 1971 */ 1972 int bt_bap_base_get_bis_indexes(const struct bt_bap_base *base, uint32_t *bis_indexes); 1973 1974 /** 1975 * @brief Iterate on all subgroups in the BASE 1976 * 1977 * @param base The BASE pointer 1978 * @param func Callback function. Return true to continue iterating, or false to stop. 1979 * @param user_data Userdata supplied to @p func 1980 * 1981 * @retval -EINVAL if arguments are invalid 1982 * @retval -ECANCELED if iterating over the subgroups stopped prematurely by @p func 1983 * @retval 0 if all subgroups were iterated 1984 */ 1985 int bt_bap_base_foreach_subgroup(const struct bt_bap_base *base, 1986 bool (*func)(const struct bt_bap_base_subgroup *subgroup, 1987 void *user_data), 1988 void *user_data); 1989 1990 /** 1991 * @brief Get the codec ID of a subgroup 1992 * 1993 * @param[in] subgroup The subgroup pointer 1994 * @param[out] codec_id Pointer to the struct where the results are placed 1995 * 1996 * @retval -EINVAL if arguments are invalid 1997 * @retval 0 on success 1998 */ 1999 int bt_bap_base_get_subgroup_codec_id(const struct bt_bap_base_subgroup *subgroup, 2000 struct bt_bap_base_codec_id *codec_id); 2001 2002 /** 2003 * @brief Get the codec configuration data of a subgroup 2004 * 2005 * @param[in] subgroup The subgroup pointer 2006 * @param[out] data Pointer that will point to the resulting codec configuration data 2007 * 2008 * @retval -EINVAL if arguments are invalid 2009 * @retval 0 on success 2010 */ 2011 int bt_bap_base_get_subgroup_codec_data(const struct bt_bap_base_subgroup *subgroup, 2012 uint8_t **data); 2013 2014 /** 2015 * @brief Get the codec metadata of a subgroup 2016 * 2017 * @param[in] subgroup The subgroup pointer 2018 * @param[out] meta Pointer that will point to the resulting codec metadata 2019 * 2020 * @retval -EINVAL if arguments are invalid 2021 * @retval 0 on success 2022 */ 2023 int bt_bap_base_get_subgroup_codec_meta(const struct bt_bap_base_subgroup *subgroup, 2024 uint8_t **meta); 2025 2026 /** 2027 * @brief Store subgroup codec data in a @ref bt_audio_codec_cfg 2028 * 2029 * @param[in] subgroup The subgroup pointer 2030 * @param[out] codec_cfg Pointer to the struct where the results are placed 2031 * 2032 * @retval -EINVAL if arguments are invalid 2033 * @retval -ENOMEM if the @p codec_cfg cannot store the @p subgroup codec data 2034 * @retval 0 on success 2035 */ 2036 int bt_bap_base_subgroup_codec_to_codec_cfg(const struct bt_bap_base_subgroup *subgroup, 2037 struct bt_audio_codec_cfg *codec_cfg); 2038 2039 /** 2040 * @brief Get the BIS count of a subgroup 2041 * 2042 * @param subgroup The subgroup pointer 2043 * 2044 * @retval -EINVAL if arguments are invalid 2045 * @retval The 8-bit BIS count value 2046 */ 2047 int bt_bap_base_get_subgroup_bis_count(const struct bt_bap_base_subgroup *subgroup); 2048 2049 /** 2050 * @brief Get all BIS indexes of a subgroup 2051 * 2052 * @param[in] subgroup The subgroup pointer 2053 * @param[out] bis_indexes 32-bit BIS index bitfield that will be populated 2054 * 2055 * @retval -EINVAL if arguments are invalid 2056 * @retval 0 on success 2057 */ 2058 int bt_bap_base_subgroup_get_bis_indexes(const struct bt_bap_base_subgroup *subgroup, 2059 uint32_t *bis_indexes); 2060 2061 /** 2062 * @brief Iterate on all BIS in the subgroup 2063 * 2064 * @param subgroup The subgroup pointer 2065 * @param func Callback function. Return true to continue iterating, or false to stop. 2066 * @param user_data Userdata supplied to @p func 2067 * 2068 * @retval -EINVAL if arguments are invalid 2069 * @retval -ECANCELED if iterating over the subgroups stopped prematurely by @p func 2070 * @retval 0 if all BIS were iterated 2071 */ 2072 int bt_bap_base_subgroup_foreach_bis(const struct bt_bap_base_subgroup *subgroup, 2073 bool (*func)(const struct bt_bap_base_subgroup_bis *bis, 2074 void *user_data), 2075 void *user_data); 2076 2077 /** 2078 * @brief Store BIS codec configuration data in a @ref bt_audio_codec_cfg 2079 * 2080 * This only sets the @ref bt_audio_codec_cfg data and @ref bt_audio_codec_cfg data_len, but is 2081 * useful to use the BIS codec configuration data with the bt_audio_codec_cfg_* functions. 2082 * 2083 * @param[in] bis The BIS pointer 2084 * @param[out] codec_cfg Pointer to the struct where the results are placed 2085 * 2086 * @retval -EINVAL if arguments are invalid 2087 * @retval -ENOMEM if the @p codec_cfg cannot store the @p subgroup codec data 2088 * @retval 0 on success 2089 */ 2090 int bt_bap_base_subgroup_bis_codec_to_codec_cfg(const struct bt_bap_base_subgroup_bis *bis, 2091 struct bt_audio_codec_cfg *codec_cfg); 2092 2093 /** @} */ /* End of group bt_bap_broadcast */ 2094 2095 /** 2096 * @brief BAP Broadcast Source APIs 2097 * @defgroup bt_bap_broadcast_source BAP Broadcast Source APIs 2098 * @ingroup bt_bap_broadcast 2099 * @{ 2100 */ 2101 2102 /** 2103 * @brief Struct to hold the Broadcast Source callbacks 2104 * 2105 * These can be registered for usage with bt_bap_broadcast_source_register_cb(). 2106 */ 2107 struct bt_bap_broadcast_source_cb { 2108 /** 2109 * @brief The Broadcast Source has started and all of the streams are ready for audio data 2110 * 2111 * @param source The started Broadcast Source 2112 */ 2113 void (*started)(struct bt_bap_broadcast_source *source); 2114 2115 /** 2116 * @brief The Broadcast Source has stopped and none of the streams are ready for audio data 2117 * 2118 * @param source The stopped Broadcast Source 2119 * @param reason The reason why the Broadcast Source stopped (see the BT_HCI_ERR_* values) 2120 */ 2121 void (*stopped)(struct bt_bap_broadcast_source *source, uint8_t reason); 2122 2123 /** @cond INTERNAL_HIDDEN */ 2124 /** Internally used field for list handling */ 2125 sys_snode_t _node; 2126 /** @endcond */ 2127 }; 2128 2129 /** 2130 * @brief Registers callbacks for Broadcast Sources 2131 * 2132 * @param cb Pointer to the callback structure. 2133 * 2134 * @retval 0 on success 2135 * @retval -EINVAL if @p cb is NULL 2136 * @retval -EEXIST if @p cb is already registered 2137 */ 2138 int bt_bap_broadcast_source_register_cb(struct bt_bap_broadcast_source_cb *cb); 2139 2140 /** 2141 * @brief Unregisters callbacks for Broadcast Sources 2142 * 2143 * @param cb Pointer to the callback structure. 2144 * 2145 * @retval 0 on success 2146 * @retval -EINVAL if @p cb is NULL 2147 * @retval -ENOENT if @p cb is not registered 2148 */ 2149 int bt_bap_broadcast_source_unregister_cb(struct bt_bap_broadcast_source_cb *cb); 2150 2151 /** Broadcast Source stream parameters */ 2152 struct bt_bap_broadcast_source_stream_param { 2153 /** Audio stream */ 2154 struct bt_bap_stream *stream; 2155 2156 #if CONFIG_BT_AUDIO_CODEC_CFG_MAX_DATA_SIZE > 0 || defined(__DOXYGEN__) 2157 /** 2158 * @brief The number of elements in the @p data array. 2159 * 2160 * The BIS specific data may be omitted and this set to 0. 2161 */ 2162 size_t data_len; 2163 2164 /** BIS Codec Specific Configuration */ 2165 uint8_t *data; 2166 #endif /* CONFIG_BT_AUDIO_CODEC_CFG_MAX_DATA_SIZE > 0 */ 2167 }; 2168 2169 /** Broadcast Source subgroup parameters*/ 2170 struct bt_bap_broadcast_source_subgroup_param { 2171 /** The number of parameters in @p stream_params */ 2172 size_t params_count; 2173 2174 /** Array of stream parameters */ 2175 struct bt_bap_broadcast_source_stream_param *params; 2176 2177 /** Subgroup Codec configuration. */ 2178 struct bt_audio_codec_cfg *codec_cfg; 2179 }; 2180 2181 /** Broadcast Source create parameters */ 2182 struct bt_bap_broadcast_source_param { 2183 /** The number of parameters in @p subgroup_params */ 2184 size_t params_count; 2185 2186 /** Array of stream parameters */ 2187 struct bt_bap_broadcast_source_subgroup_param *params; 2188 2189 /** Quality of Service configuration. */ 2190 struct bt_bap_qos_cfg *qos; 2191 2192 /** 2193 * @brief Broadcast Source packing mode. 2194 * 2195 * @ref BT_ISO_PACKING_SEQUENTIAL or @ref BT_ISO_PACKING_INTERLEAVED. 2196 * 2197 * @note This is a recommendation to the controller, which the controller may ignore. 2198 */ 2199 uint8_t packing; 2200 2201 /** Whether or not to encrypt the streams. */ 2202 bool encryption; 2203 2204 /** 2205 * @brief Broadcast code 2206 * 2207 * If the value is a string or a the value is less than 16 octets, 2208 * the remaining octets shall be 0. 2209 * 2210 * Example: 2211 * The string "Broadcast Code" shall be 2212 * [42 72 6F 61 64 63 61 73 74 20 43 6F 64 65 00 00] 2213 */ 2214 uint8_t broadcast_code[BT_ISO_BROADCAST_CODE_SIZE]; 2215 2216 #if defined(CONFIG_BT_ISO_TEST_PARAMS) || defined(__DOXYGEN__) 2217 /** 2218 * @brief Immediate Repetition Count 2219 * 2220 * The number of times the scheduled payloads are transmitted in a given event. 2221 * 2222 * Value range from @ref BT_ISO_IRC_MIN to @ref BT_ISO_IRC_MAX. 2223 */ 2224 uint8_t irc; 2225 2226 /** 2227 * @brief Pre-transmission offset 2228 * 2229 * Offset used for pre-transmissions. 2230 * 2231 * Value range from @ref BT_ISO_PTO_MIN to @ref BT_ISO_PTO_MAX. 2232 */ 2233 uint8_t pto; 2234 2235 /** 2236 * @brief ISO interval 2237 * 2238 * Time between consecutive BIS anchor points. 2239 * 2240 * Value range from @ref BT_ISO_ISO_INTERVAL_MIN to @ref BT_ISO_ISO_INTERVAL_MAX. 2241 */ 2242 uint16_t iso_interval; 2243 #endif /* CONFIG_BT_ISO_TEST_PARAMS */ 2244 }; 2245 2246 /** 2247 * @brief Create audio broadcast source. 2248 * 2249 * Create a new audio broadcast source with one or more audio streams. 2250 * 2251 * The broadcast source will be visible for scanners once this has been called, 2252 * and the device will advertise audio announcements. 2253 * 2254 * No audio data can be sent until bt_bap_broadcast_source_start() has been called and no audio 2255 * information (BIGInfo) will be visible to scanners (see @ref bt_le_per_adv_sync_cb). 2256 * 2257 * @param[in] param Pointer to parameters used to create the broadcast source. 2258 * @param[out] source Pointer to the broadcast source created 2259 * 2260 * @return Zero on success or (negative) error code otherwise. 2261 */ 2262 int bt_bap_broadcast_source_create(struct bt_bap_broadcast_source_param *param, 2263 struct bt_bap_broadcast_source **source); 2264 2265 /** 2266 * @brief Reconfigure audio broadcast source. 2267 * 2268 * Reconfigure an audio broadcast source with a new codec and codec quality of 2269 * service parameters. This can only be done when the source is stopped. 2270 * 2271 * Since this may modify the Broadcast Audio Source Endpoint (BASE), 2272 * bt_bap_broadcast_source_get_base() should be called after this to get the new BASE information. 2273 * 2274 * If the @p param.params_count is smaller than the number of subgroups that have been created in 2275 * the Broadcast Source, only the first @p param.params_count subgroups are updated. If a stream 2276 * exist in a subgroup not part of @p param, then that stream is left as is (i.e. it is not removed; 2277 * the only way to remove a stream from a Broadcast Source is to recreate the Broadcast Source). 2278 * 2279 * @param source Pointer to the broadcast source 2280 * @param param Pointer to parameters used to reconfigure the broadcast source. 2281 * 2282 * @return Zero on success or (negative) error code otherwise. 2283 */ 2284 int bt_bap_broadcast_source_reconfig(struct bt_bap_broadcast_source *source, 2285 struct bt_bap_broadcast_source_param *param); 2286 2287 /** 2288 * @brief Modify the metadata of an audio broadcast source. 2289 * 2290 * Modify the metadata an audio broadcast source. This can only be done when the source is started. 2291 * To update the metadata in the stopped state, use bt_bap_broadcast_source_reconfig(). 2292 * 2293 * @param source Pointer to the broadcast source. 2294 * @param meta Metadata. 2295 * @param meta_len Length of metadata. 2296 * 2297 * @return Zero on success or (negative) error code otherwise. 2298 */ 2299 int bt_bap_broadcast_source_update_metadata(struct bt_bap_broadcast_source *source, 2300 const uint8_t meta[], size_t meta_len); 2301 2302 /** 2303 * @brief Start audio broadcast source. 2304 * 2305 * Start an audio broadcast source with one or more audio streams. 2306 * The broadcast source will start advertising BIGInfo, and audio data can be streamed. 2307 * 2308 * @param source Pointer to the broadcast source 2309 * @param adv Pointer to an extended advertising set with periodic advertising configured. 2310 * 2311 * @return Zero on success or (negative) error code otherwise. 2312 */ 2313 int bt_bap_broadcast_source_start(struct bt_bap_broadcast_source *source, 2314 struct bt_le_ext_adv *adv); 2315 2316 /** 2317 * @brief Stop audio broadcast source. 2318 * 2319 * Stop an audio broadcast source. 2320 * The broadcast source will stop advertising BIGInfo, and audio data can no longer be streamed. 2321 * 2322 * @param source Pointer to the broadcast source 2323 * 2324 * @return Zero on success or (negative) error code otherwise. 2325 */ 2326 int bt_bap_broadcast_source_stop(struct bt_bap_broadcast_source *source); 2327 2328 /** 2329 * @brief Delete audio broadcast source. 2330 * 2331 * Delete an audio broadcast source. 2332 * The broadcast source will stop advertising entirely, and the source can no longer be used. 2333 * 2334 * @param source Pointer to the broadcast source 2335 * 2336 * @return Zero on success or (negative) error code otherwise. 2337 */ 2338 int bt_bap_broadcast_source_delete(struct bt_bap_broadcast_source *source); 2339 2340 /** 2341 * @brief Get the Broadcast Audio Stream Endpoint of a broadcast source 2342 * 2343 * This will encode the BASE of a broadcast source into a buffer, that can be used for 2344 * advertisement. The encoded BASE will thus be encoded as little-endian. The BASE shall be put into 2345 * the periodic advertising data (see bt_le_per_adv_set_data()). 2346 * 2347 * See table 3.15 in the Basic Audio Profile v1.0.1 for the structure. 2348 * 2349 * @param source Pointer to the broadcast source. 2350 * @param base_buf Pointer to a buffer where the BASE will be inserted. 2351 * 2352 * @return Zero on success or (negative) error code otherwise. 2353 */ 2354 int bt_bap_broadcast_source_get_base(struct bt_bap_broadcast_source *source, 2355 struct net_buf_simple *base_buf); 2356 2357 /** @} */ /* End of bt_bap_broadcast_source */ 2358 2359 /** 2360 * @brief BAP Broadcast Sink APIs 2361 * @defgroup bt_bap_broadcast_sink BAP Broadcast Sink APIs 2362 * @ingroup bt_bap_broadcast 2363 * @{ 2364 */ 2365 2366 /** Broadcast Audio Sink callback structure */ 2367 struct bt_bap_broadcast_sink_cb { 2368 /** 2369 * @brief Broadcast Audio Source Endpoint (BASE) received 2370 * 2371 * Callback for when we receive a BASE from a broadcaster after 2372 * syncing to the broadcaster's periodic advertising. 2373 * 2374 * @param sink Pointer to the sink structure. 2375 * @param base Broadcast Audio Source Endpoint (BASE). 2376 * @param base_size Size of the @p base 2377 */ 2378 void (*base_recv)(struct bt_bap_broadcast_sink *sink, const struct bt_bap_base *base, 2379 size_t base_size); 2380 2381 /** 2382 * @brief Broadcast sink is syncable 2383 * 2384 * Called whenever a broadcast sink is not synchronized to audio, but the audio is 2385 * synchronizable. This is inferred when a BIGInfo report is received. 2386 * 2387 * Once this callback has been called, it is possible to call 2388 * bt_bap_broadcast_sink_sync() to synchronize to the audio stream(s). 2389 * 2390 * @param sink Pointer to the sink structure. 2391 * @param biginfo The BIGInfo report. 2392 */ 2393 void (*syncable)(struct bt_bap_broadcast_sink *sink, const struct bt_iso_biginfo *biginfo); 2394 2395 /** 2396 * @brief The Broadcast Sink has started and audio data may be received from all of the 2397 * streams 2398 * 2399 * @param sink The started Broadcast Sink 2400 */ 2401 void (*started)(struct bt_bap_broadcast_sink *sink); 2402 2403 /** 2404 * @brief The Broadcast Sink has stopped and none of the streams will receive audio data 2405 * 2406 * @param sink The stopped Broadcast Sink 2407 * @param reason The reason why the Broadcast Sink stopped (see the BT_HCI_ERR_* values) 2408 */ 2409 void (*stopped)(struct bt_bap_broadcast_sink *sink, uint8_t reason); 2410 2411 /** @cond INTERNAL_HIDDEN */ 2412 /** Internally used list node */ 2413 sys_snode_t _node; 2414 /** @endcond */ 2415 }; 2416 2417 /** 2418 * @brief Register Broadcast sink callbacks 2419 * 2420 * It is possible to register multiple struct of callbacks, but a single struct can only be 2421 * registered once. 2422 * Registering the same callback multiple times is undefined behavior and may break the stack. 2423 2424 * @param cb Broadcast sink callback structure. 2425 * 2426 * @retval 0 on success 2427 * @retval -EINVAL if @p cb is NULL 2428 * @retval -EALREADY if @p cb was already registered 2429 */ 2430 int bt_bap_broadcast_sink_register_cb(struct bt_bap_broadcast_sink_cb *cb); 2431 2432 /** 2433 * @brief Create a Broadcast Sink from a periodic advertising sync 2434 * 2435 * This should only be done after verifying that the periodic advertising sync 2436 * is from a Broadcast Source. 2437 * 2438 * The created Broadcast Sink will need to be supplied to 2439 * bt_bap_broadcast_sink_sync() in order to synchronize to the broadcast audio. 2440 * 2441 * bt_bap_broadcast_sink_cb.pa_synced() will be called with the Broadcast 2442 * Sink object created if this is successful. 2443 * 2444 * @param pa_sync Pointer to the periodic advertising sync object. 2445 * @param broadcast_id 24-bit broadcast ID. 2446 * @param[out] sink Pointer to the Broadcast Sink created. 2447 * 2448 * @return 0 in case of success or errno value in case of error. 2449 */ 2450 int bt_bap_broadcast_sink_create(struct bt_le_per_adv_sync *pa_sync, uint32_t broadcast_id, 2451 struct bt_bap_broadcast_sink **sink); 2452 2453 /** 2454 * @brief Sync to a broadcaster's audio 2455 * 2456 * @param sink Pointer to the sink object from the base_recv callback. 2457 * @param indexes_bitfield Bitfield of the BIS index to sync to. To sync to e.g. BIS index 1 and 2458 * 2, this should have the value of BIT(1) | BIT(2). 2459 * @param streams Stream object pointers to be used for the receiver. If multiple BIS 2460 * indexes shall be synchronized, multiple streams shall be provided. 2461 * @param broadcast_code The 16-octet broadcast code. Shall be supplied if the broadcast is 2462 * encrypted (see @ref bt_bap_broadcast_sink_cb.syncable). 2463 * If the value is a string or a the value is less 2464 * than 16 octets, the remaining octets shall be 0. 2465 * 2466 * Example: 2467 * The string "Broadcast Code" shall be 2468 * [42 72 6F 61 64 63 61 73 74 20 43 6F 64 65 00 00] 2469 * 2470 * @return 0 in case of success or negative value in case of error. 2471 */ 2472 int bt_bap_broadcast_sink_sync(struct bt_bap_broadcast_sink *sink, uint32_t indexes_bitfield, 2473 struct bt_bap_stream *streams[], 2474 const uint8_t broadcast_code[BT_ISO_BROADCAST_CODE_SIZE]); 2475 2476 /** 2477 * @brief Stop audio broadcast sink. 2478 * 2479 * Stop an audio broadcast sink. 2480 * The broadcast sink will stop receiving BIGInfo, and audio data can no longer be streamed. 2481 * 2482 * @param sink Pointer to the broadcast sink 2483 * 2484 * @return Zero on success or (negative) error code otherwise. 2485 */ 2486 int bt_bap_broadcast_sink_stop(struct bt_bap_broadcast_sink *sink); 2487 2488 /** 2489 * @brief Release a broadcast sink 2490 * 2491 * Once a broadcast sink has been allocated after the pa_synced callback, it can be deleted using 2492 * this function. If the sink has synchronized to any broadcast audio streams, these must first be 2493 * stopped using bt_bap_stream_stop. 2494 * 2495 * @param sink Pointer to the sink object to delete. 2496 * 2497 * @return 0 in case of success or negative value in case of error. 2498 */ 2499 int bt_bap_broadcast_sink_delete(struct bt_bap_broadcast_sink *sink); 2500 2501 /** @} */ /* End of group bt_bap_broadcast_sink */ 2502 2503 /** 2504 * @brief Register the Basic Audio Profile Scan Delegator and BASS. 2505 * 2506 * Register the scan deligator and Broadcast Audio Scan Service (BASS) 2507 * dynamically at runtime. 2508 * 2509 * Only one set of callbacks can be registered at any one time, and calling this function multiple 2510 * times will override any previously registered callbacks. 2511 * 2512 * @param cb Pointer to the callback struct 2513 * 2514 * @return 0 in case of success or negative value in case of error. 2515 */ 2516 int bt_bap_scan_delegator_register(struct bt_bap_scan_delegator_cb *cb); 2517 2518 /** 2519 * @brief unregister the Basic Audio Profile Scan Delegator and BASS. 2520 * 2521 * Unregister the scan deligator and Broadcast Audio Scan Service (BASS) 2522 * dynamically at runtime. 2523 * 2524 * @return 0 in case of success or negative value in case of error. 2525 */ 2526 int bt_bap_scan_delegator_unregister(void); 2527 2528 /** 2529 * @brief Set the periodic advertising sync state to syncing 2530 * 2531 * Set the periodic advertising sync state for a receive state to syncing, 2532 * notifying Broadcast Assistants. 2533 * 2534 * @param src_id The source id used to identify the receive state. 2535 * @param pa_state The Periodic Advertising sync state to set. 2536 * BT_BAP_PA_STATE_NOT_SYNCED and BT_BAP_PA_STATE_SYNCED is 2537 * not necessary to provide, as they are handled internally. 2538 * 2539 * @return int Error value. 0 on success, errno on fail. 2540 */ 2541 int bt_bap_scan_delegator_set_pa_state(uint8_t src_id, 2542 enum bt_bap_pa_state pa_state); 2543 2544 /** 2545 * @brief Set the sync state of a receive state in the server 2546 * 2547 * @param src_id The source id used to identify the receive state. 2548 * @param bis_synced Array of bitfields to set the BIS sync state for each 2549 * subgroup. 2550 * @return int Error value. 0 on success, ERRNO on fail. 2551 */ 2552 int bt_bap_scan_delegator_set_bis_sync_state(uint8_t src_id, 2553 uint32_t bis_synced[BT_BAP_BASS_MAX_SUBGROUPS]); 2554 2555 /** Parameters for bt_bap_scan_delegator_add_src() */ 2556 struct bt_bap_scan_delegator_add_src_param { 2557 /** Periodic Advertiser Address */ 2558 bt_addr_le_t addr; 2559 2560 /** Advertiser SID */ 2561 uint8_t sid; 2562 2563 /** The broadcast isochronous group encryption state */ 2564 enum bt_bap_big_enc_state encrypt_state; 2565 2566 /** The 24-bit broadcast ID */ 2567 uint32_t broadcast_id; 2568 2569 /** Number of subgroups */ 2570 uint8_t num_subgroups; 2571 2572 /** Subgroup specific information */ 2573 struct bt_bap_bass_subgroup subgroups[BT_BAP_BASS_MAX_SUBGROUPS]; 2574 }; 2575 2576 /** 2577 * @brief Add a receive state source locally 2578 * 2579 * This will notify any connected clients about the new source. This allows them 2580 * to modify and even remove it. 2581 * 2582 * If @kconfig{CONFIG_BT_BAP_BROADCAST_SINK} is enabled, any Broadcast Sink 2583 * sources are autonomously added. 2584 * 2585 * @param param The parameters for adding the new source 2586 * 2587 * @return int errno on failure, or source ID on success. 2588 */ 2589 int bt_bap_scan_delegator_add_src(const struct bt_bap_scan_delegator_add_src_param *param); 2590 2591 /** Parameters for bt_bap_scan_delegator_mod_src() */ 2592 struct bt_bap_scan_delegator_mod_src_param { 2593 /** The periodic adverting sync */ 2594 uint8_t src_id; 2595 2596 /** The broadcast isochronous group encryption state */ 2597 enum bt_bap_big_enc_state encrypt_state; 2598 2599 /** The 24-bit broadcast ID */ 2600 uint32_t broadcast_id; 2601 2602 /** Number of subgroups */ 2603 uint8_t num_subgroups; 2604 2605 /** 2606 * @brief Subgroup specific information 2607 * 2608 * If a subgroup's metadata_len is set to 0, the existing metadata 2609 * for the subgroup will remain unchanged 2610 */ 2611 struct bt_bap_bass_subgroup subgroups[BT_BAP_BASS_MAX_SUBGROUPS]; 2612 }; 2613 2614 /** 2615 * @brief Add a receive state source locally 2616 * 2617 * This will notify any connected clients about the new source. This allows them 2618 * to modify and even remove it. 2619 * 2620 * If @kconfig{CONFIG_BT_BAP_BROADCAST_SINK} is enabled, any Broadcast Sink 2621 * sources are autonomously modified. 2622 * 2623 * @param param The parameters for adding the new source 2624 * 2625 * @return int errno on failure, or source ID on success. 2626 */ 2627 int bt_bap_scan_delegator_mod_src(const struct bt_bap_scan_delegator_mod_src_param *param); 2628 2629 /** 2630 * @brief Remove a receive state source 2631 * 2632 * This will remove the receive state. If the receive state periodic advertising 2633 * is synced, bt_bap_scan_delegator_cb.pa_sync_term_req() will be called. 2634 * 2635 * If @kconfig{CONFIG_BT_BAP_BROADCAST_SINK} is enabled, any Broadcast Sink 2636 * sources are autonomously removed. 2637 * 2638 * @param src_id The source ID to remove 2639 * 2640 * @return int Error value. 0 on success, errno on fail. 2641 */ 2642 int bt_bap_scan_delegator_rem_src(uint8_t src_id); 2643 2644 /** Callback function for Scan Delegator receive state search functions 2645 * 2646 * @param recv_state The receive state. 2647 * @param user_data User data. 2648 * 2649 * @retval true to stop iterating. If this is used in the context of 2650 * bt_bap_scan_delegator_find_state(), the recv_state will be returned by 2651 * bt_bap_scan_delegator_find_state() 2652 * @retval false to continue iterating 2653 */ 2654 typedef bool (*bt_bap_scan_delegator_state_func_t)( 2655 const struct bt_bap_scan_delegator_recv_state *recv_state, void *user_data); 2656 2657 /** 2658 * @brief Iterate through all existing receive states 2659 * 2660 * @param func The callback function 2661 * @param user_data User specified data that sent to the callback function 2662 */ 2663 void bt_bap_scan_delegator_foreach_state(bt_bap_scan_delegator_state_func_t func, 2664 void *user_data); 2665 2666 /** 2667 * @brief Find and return a receive state based on a compare function 2668 * 2669 * @param func The compare callback function 2670 * @param user_data User specified data that sent to the callback function 2671 * 2672 * @return The first receive state where the @p func returned true, or NULL 2673 */ 2674 const struct bt_bap_scan_delegator_recv_state *bt_bap_scan_delegator_find_state( 2675 bt_bap_scan_delegator_state_func_t func, void *user_data); 2676 2677 /******************************** CLIENT API ********************************/ 2678 2679 /** 2680 * @brief Callback function for writes. 2681 * 2682 * @param conn The connection to the peer device. 2683 * @param err Error value. 0 on success, GATT error on fail. 2684 */ 2685 typedef void (*bt_bap_broadcast_assistant_write_cb)(struct bt_conn *conn, 2686 int err); 2687 2688 /** 2689 * @brief Struct to hold the Basic Audio Profile Broadcast Assistant callbacks 2690 * 2691 * These can be registered for usage with bt_bap_broadcast_assistant_register_cb(). 2692 */ 2693 struct bt_bap_broadcast_assistant_cb { 2694 /** 2695 * @brief Callback function for bt_bap_broadcast_assistant_discover. 2696 * 2697 * @param conn The connection that was used to discover 2698 * Broadcast Audio Scan Service. 2699 * @param err Error value. 0 on success, 2700 * GATT error or ERRNO on fail. 2701 * @param recv_state_count Number of receive states on the server. 2702 */ 2703 void (*discover)(struct bt_conn *conn, int err, 2704 uint8_t recv_state_count); 2705 2706 /** 2707 * @brief Callback function for Broadcast Audio Scan Service client scan results 2708 * 2709 * Called when the scanner finds an advertiser that advertises the 2710 * BT_UUID_BROADCAST_AUDIO UUID. 2711 * 2712 * @param info Advertiser information. 2713 * @param broadcast_id 24-bit broadcast ID. 2714 */ 2715 void (*scan)(const struct bt_le_scan_recv_info *info, 2716 uint32_t broadcast_id); 2717 2718 /** 2719 * @brief Callback function for when a receive state is read or updated 2720 * 2721 * Called whenever a receive state is read or updated. 2722 * 2723 * @param conn The connection to the Broadcast Audio Scan Service server. 2724 * @param err Error value. 0 on success, GATT error on fail. 2725 * @param state The receive state or NULL if the receive state is empty. 2726 */ 2727 void (*recv_state)(struct bt_conn *conn, int err, 2728 const struct bt_bap_scan_delegator_recv_state *state); 2729 2730 /** 2731 * @brief Callback function for when a receive state is removed. 2732 * 2733 * @param conn The connection to the Broadcast Audio Scan Service server. 2734 * @param src_id The receive state. 2735 */ 2736 void (*recv_state_removed)(struct bt_conn *conn, uint8_t src_id); 2737 2738 /** 2739 * @brief Callback function for bt_bap_broadcast_assistant_scan_start(). 2740 * 2741 * @param conn The connection to the peer device. 2742 * @param err Error value. 0 on success, GATT error on fail. 2743 */ 2744 void (*scan_start)(struct bt_conn *conn, int err); 2745 2746 /** 2747 * @brief Callback function for bt_bap_broadcast_assistant_scan_stop(). 2748 * 2749 * @param conn The connection to the peer device. 2750 * @param err Error value. 0 on success, GATT error on fail. 2751 */ 2752 void (*scan_stop)(struct bt_conn *conn, int err); 2753 2754 /** 2755 * @brief Callback function for bt_bap_broadcast_assistant_add_src(). 2756 * 2757 * @param conn The connection to the peer device. 2758 * @param err Error value. 0 on success, GATT error on fail. 2759 */ 2760 void (*add_src)(struct bt_conn *conn, int err); 2761 2762 /** 2763 * @brief Callback function for bt_bap_broadcast_assistant_mod_src(). 2764 * 2765 * @param conn The connection to the peer device. 2766 * @param err Error value. 0 on success, GATT error on fail. 2767 */ 2768 void (*mod_src)(struct bt_conn *conn, int err); 2769 2770 /** 2771 * @brief Callback function for bt_bap_broadcast_assistant_set_broadcast_code(). 2772 * 2773 * @param conn The connection to the peer device. 2774 * @param err Error value. 0 on success, GATT error on fail. 2775 */ 2776 void (*broadcast_code)(struct bt_conn *conn, int err); 2777 2778 /** 2779 * @brief Callback function for bt_bap_broadcast_assistant_rem_src(). 2780 * 2781 * @param conn The connection to the peer device. 2782 * @param err Error value. 0 on success, GATT error on fail. 2783 */ 2784 void (*rem_src)(struct bt_conn *conn, int err); 2785 2786 /** @cond INTERNAL_HIDDEN */ 2787 /** Internally used list node */ 2788 sys_snode_t _node; 2789 /** @endcond */ 2790 }; 2791 2792 /** 2793 * @brief Discover Broadcast Audio Scan Service on the server. 2794 * 2795 * Warning: Only one connection can be active at any time; discovering for a 2796 * new connection, will delete all previous data. 2797 * 2798 * @param conn The connection 2799 * 2800 * @retval 0 Success 2801 * @retval -EINVAL @p conn is NULL 2802 * @retval -EBUSY Another operation is already in progress for this @p conn 2803 * @retval -ENOTCONN @p conn is not connected 2804 * @retval -ENOMEM Could not allocated memory for the request 2805 * @retval -ENOEXEC Unexpected GATT error 2806 */ 2807 int bt_bap_broadcast_assistant_discover(struct bt_conn *conn); 2808 2809 /** 2810 * @brief Scan start for BISes for a remote server. 2811 * 2812 * This will let the Broadcast Audio Scan Service server know that this device 2813 * is actively scanning for broadcast sources. 2814 * The function can optionally also start scanning, if the caller does not want 2815 * to start scanning itself. 2816 * 2817 * Scan results, if @p start_scan is true, is sent to the 2818 * bt_bap_broadcast_assistant_scan_cb callback. 2819 * 2820 * @param conn Connection to the Broadcast Audio Scan Service server. 2821 * Used to let the server know that we are scanning. 2822 * @param start_scan Start scanning if true. If false, the application should 2823 * enable scan itself. 2824 2825 * @retval 0 Success 2826 * @retval -EINVAL @p conn is NULL of if @p conn has not done discovery 2827 * @retval -EBUSY Another operation is already in progress for this @p conn 2828 * @retval -EAGAIN Bluetooth has not been enabled. 2829 * @retval -ENOTCONN @p conn is not connected 2830 * @retval -ENOMEM Could not allocated memory for the request 2831 * @retval -ENOEXEC Unexpected scan or GATT error 2832 */ 2833 int bt_bap_broadcast_assistant_scan_start(struct bt_conn *conn, 2834 bool start_scan); 2835 2836 /** 2837 * @brief Stop remote scanning for BISes for a server. 2838 * 2839 * @param conn Connection to the server. 2840 2841 * @retval 0 Success 2842 * @retval -EINVAL @p conn is NULL of if @p conn has not done discovery 2843 * @retval -EBUSY Another operation is already in progress for this @p conn 2844 * @retval -EAGAIN Bluetooth has not been enabled. 2845 * @retval -ENOTCONN @p conn is not connected 2846 * @retval -ENOMEM Could not allocated memory for the request 2847 * @retval -ENOEXEC Unexpected scan or GATT error 2848 */ 2849 int bt_bap_broadcast_assistant_scan_stop(struct bt_conn *conn); 2850 2851 /** 2852 * @brief Registers the callbacks used by Broadcast Audio Scan Service client. 2853 * 2854 * @param cb The callback structure. 2855 * 2856 * @retval 0 on success 2857 * @retval -EINVAL if @p cb is NULL 2858 * @retval -EALREADY if @p cb was already registered 2859 */ 2860 int bt_bap_broadcast_assistant_register_cb(struct bt_bap_broadcast_assistant_cb *cb); 2861 2862 /** 2863 * @brief Unregisters the callbacks used by the Broadcast Audio Scan Service client. 2864 * 2865 * @param cb The callback structure. 2866 * 2867 * @retval 0 on success 2868 * @retval -EINVAL if @p cb is NULL 2869 * @retval -EALREADY if @p cb was not registered 2870 */ 2871 int bt_bap_broadcast_assistant_unregister_cb(struct bt_bap_broadcast_assistant_cb *cb); 2872 2873 2874 /** Parameters for adding a source to a Broadcast Audio Scan Service server */ 2875 struct bt_bap_broadcast_assistant_add_src_param { 2876 /** Address of the advertiser. */ 2877 bt_addr_le_t addr; 2878 2879 /** SID of the advertising set. */ 2880 uint8_t adv_sid; 2881 2882 /** Whether to sync to periodic advertisements. */ 2883 bool pa_sync; 2884 2885 /** 24-bit broadcast ID */ 2886 uint32_t broadcast_id; 2887 2888 /** 2889 * @brief Periodic advertising interval in milliseconds. 2890 * 2891 * BT_BAP_PA_INTERVAL_UNKNOWN if unknown. 2892 */ 2893 uint16_t pa_interval; 2894 2895 /** Number of subgroups */ 2896 uint8_t num_subgroups; 2897 2898 /** Pointer to array of subgroups 2899 * 2900 * The @ref bt_bap_bass_subgroup.bis_sync value can be set to BT_BAP_BIS_SYNC_NO_PREF to 2901 * let the broadcast sink decide which BIS to synchronize to. 2902 */ 2903 struct bt_bap_bass_subgroup *subgroups; 2904 }; 2905 2906 /** 2907 * @brief Add a source on the server. 2908 * 2909 * @param conn Connection to the server. 2910 * @param param Parameter struct. 2911 * 2912 * @retval 0 Success 2913 * @retval -EINVAL @p conn is NULL or %p conn has not done discovery or if @p param is invalid 2914 * @retval -EBUSY Another operation is already in progress for this @p conn 2915 * @retval -ENOTCONN @p conn is not connected 2916 * @retval -ENOMEM Could not allocated memory for the request 2917 * @retval -ENOEXEC Unexpected scan or GATT error 2918 */ 2919 int bt_bap_broadcast_assistant_add_src( 2920 struct bt_conn *conn, const struct bt_bap_broadcast_assistant_add_src_param *param); 2921 2922 /** Parameters for modifying a source */ 2923 struct bt_bap_broadcast_assistant_mod_src_param { 2924 /** Source ID of the receive state. */ 2925 uint8_t src_id; 2926 2927 /** Whether to sync to periodic advertisements. */ 2928 bool pa_sync; 2929 2930 /** 2931 * @brief Periodic advertising interval. 2932 * 2933 * BT_BAP_PA_INTERVAL_UNKNOWN if unknown. 2934 */ 2935 uint16_t pa_interval; 2936 2937 /** Number of subgroups */ 2938 uint8_t num_subgroups; 2939 2940 /** Pointer to array of subgroups */ 2941 struct bt_bap_bass_subgroup *subgroups; 2942 }; 2943 2944 /** 2945 * @brief Modify a source on the server. 2946 * 2947 * @param conn Connection to the server. 2948 * @param param Parameter struct. 2949 * 2950 * @retval 0 Success 2951 * @retval -EINVAL @p conn is NULL or %p conn has not done discovery or if @p param is invalid 2952 * @retval -EBUSY Another operation is already in progress for this @p conn 2953 * @retval -ENOTCONN @p conn is not connected 2954 * @retval -ENOMEM Could not allocated memory for the request 2955 * @retval -ENOEXEC Unexpected scan or GATT error 2956 */ 2957 int bt_bap_broadcast_assistant_mod_src( 2958 struct bt_conn *conn, const struct bt_bap_broadcast_assistant_mod_src_param *param); 2959 2960 /** 2961 * @brief Set a broadcast code to the specified receive state. 2962 * 2963 * @param conn Connection to the server. 2964 * @param src_id Source ID of the receive state. 2965 * @param broadcast_code The broadcast code. 2966 * 2967 * @retval 0 Success 2968 * @retval -EINVAL @p conn is NULL or %p conn has not done discovery or @p src_id is invalid 2969 * @retval -EBUSY Another operation is already in progress for this @p conn 2970 * @retval -ENOTCONN @p conn is not connected 2971 * @retval -ENOMEM Could not allocated memory for the request 2972 * @retval -ENOEXEC Unexpected scan or GATT error 2973 */ 2974 int bt_bap_broadcast_assistant_set_broadcast_code( 2975 struct bt_conn *conn, uint8_t src_id, 2976 const uint8_t broadcast_code[BT_ISO_BROADCAST_CODE_SIZE]); 2977 2978 /** 2979 * @brief Remove a source from the server. 2980 * 2981 * @param conn Connection to the server. 2982 * @param src_id Source ID of the receive state. 2983 * 2984 * @retval 0 Success 2985 * @retval -EINVAL @p conn is NULL or %p conn has not done discovery or @p src_id is invalid 2986 * @retval -EBUSY Another operation is already in progress for this @p conn 2987 * @retval -ENOTCONN @p conn is not connected 2988 * @retval -ENOMEM Could not allocated memory for the request 2989 * @retval -ENOEXEC Unexpected scan or GATT error 2990 */ 2991 int bt_bap_broadcast_assistant_rem_src(struct bt_conn *conn, uint8_t src_id); 2992 2993 /** 2994 * @brief Read the specified receive state from the server. 2995 * 2996 * @param conn Connection to the server. 2997 * @param idx The index of the receive start (0 up to the value from 2998 * bt_bap_broadcast_assistant_discover_cb) 2999 * 3000 * @retval 0 Success 3001 * @retval -EINVAL @p conn is NULL or %p conn has not done discovery or @p src_id is invalid 3002 * @retval -EBUSY Another operation is already in progress for this @p conn 3003 * @retval -ENOTCONN @p conn is not connected 3004 * @retval -ENOMEM Could not allocated memory for the request 3005 * @retval -ENOEXEC Unexpected scan or GATT error 3006 */ 3007 int bt_bap_broadcast_assistant_read_recv_state(struct bt_conn *conn, uint8_t idx); 3008 3009 /** @} */ /* end of bt_bap */ 3010 3011 #ifdef __cplusplus 3012 } 3013 #endif 3014 3015 #endif /* ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_BAP_ */ 3016