1 /** @file 2 * @brief Header for Bluetooth BAP. 3 * 4 * Copyright (c) 2020 Bose Corporation 5 * Copyright (c) 2021-2023 Nordic Semiconductor ASA 6 * 7 * SPDX-License-Identifier: Apache-2.0 8 */ 9 10 #ifndef ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_BAP_ 11 #define ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_BAP_ 12 13 /** 14 * @brief Bluetooth Basic Audio Profile (BAP) 15 * @defgroup bt_bap Bluetooth Basic Audio Profile 16 * @ingroup bluetooth 17 * @{ 18 */ 19 20 #include <zephyr/bluetooth/conn.h> 21 #include <zephyr/bluetooth/audio/audio.h> 22 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 /** Periodic advertising state reported by the Scan Delegator */ 29 enum bt_bap_pa_state { 30 /** The periodic advertising has not been synchronized */ 31 BT_BAP_PA_STATE_NOT_SYNCED = 0x00, 32 33 /** Waiting for SyncInfo from Broadcast Assistant */ 34 BT_BAP_PA_STATE_INFO_REQ = 0x01, 35 36 /** Synchronized to periodic advertising */ 37 BT_BAP_PA_STATE_SYNCED = 0x02, 38 39 /** Failed to synchronized to periodic advertising */ 40 BT_BAP_PA_STATE_FAILED = 0x03, 41 42 /** No periodic advertising sync transfer receiver from Broadcast Assistant */ 43 BT_BAP_PA_STATE_NO_PAST = 0x04, 44 }; 45 46 /** Broadcast Isochronous Group encryption state reported by the Scan Delegator */ 47 enum bt_bap_big_enc_state { 48 /** The Broadcast Isochronous Group not encrypted */ 49 BT_BAP_BIG_ENC_STATE_NO_ENC = 0x00, 50 51 /** The Broadcast Isochronous Group broadcast code requested */ 52 BT_BAP_BIG_ENC_STATE_BCODE_REQ = 0x01, 53 54 /** The Broadcast Isochronous Group decrypted */ 55 BT_BAP_BIG_ENC_STATE_DEC = 0x02, 56 57 /** The Broadcast Isochronous Group bad broadcast code */ 58 BT_BAP_BIG_ENC_STATE_BAD_CODE = 0x03, 59 }; 60 61 /** Broadcast Audio Scan Service (BASS) specific ATT error codes */ 62 enum bt_bap_bass_att_err { 63 /** Opcode not supported */ 64 BT_BAP_BASS_ERR_OPCODE_NOT_SUPPORTED = 0x80, 65 66 /** Invalid source ID supplied */ 67 BT_BAP_BASS_ERR_INVALID_SRC_ID = 0x81, 68 }; 69 70 /** Value indicating that the periodic advertising interval is unknown */ 71 #define BT_BAP_PA_INTERVAL_UNKNOWN 0xFFFF 72 73 /** @brief Broadcast Assistant no BIS sync preference 74 * 75 * Value indicating that the Broadcast Assistant has no preference to which BIS 76 * the Scan Delegator syncs to 77 */ 78 #define BT_BAP_BIS_SYNC_NO_PREF 0xFFFFFFFF 79 80 /** Endpoint states */ 81 enum bt_bap_ep_state { 82 /** Audio Stream Endpoint Idle state */ 83 BT_BAP_EP_STATE_IDLE = 0x00, 84 85 /** Audio Stream Endpoint Codec Configured state */ 86 BT_BAP_EP_STATE_CODEC_CONFIGURED = 0x01, 87 88 /** Audio Stream Endpoint QoS Configured state */ 89 BT_BAP_EP_STATE_QOS_CONFIGURED = 0x02, 90 91 /** Audio Stream Endpoint Enabling state */ 92 BT_BAP_EP_STATE_ENABLING = 0x03, 93 94 /** Audio Stream Endpoint Streaming state */ 95 BT_BAP_EP_STATE_STREAMING = 0x04, 96 97 /** Audio Stream Endpoint Disabling state */ 98 BT_BAP_EP_STATE_DISABLING = 0x05, 99 100 /** Audio Stream Endpoint Streaming state */ 101 BT_BAP_EP_STATE_RELEASING = 0x06, 102 }; 103 104 /** 105 * @brief Response Status Code 106 * 107 * These are sent by the server to the client when a stream operation is 108 * requested. 109 */ 110 enum bt_bap_ascs_rsp_code { 111 /** Server completed operation successfully */ 112 BT_BAP_ASCS_RSP_CODE_SUCCESS = 0x00, 113 /** Server did not support operation by client */ 114 BT_BAP_ASCS_RSP_CODE_NOT_SUPPORTED = 0x01, 115 /** Server rejected due to invalid operation length */ 116 BT_BAP_ASCS_RSP_CODE_INVALID_LENGTH = 0x02, 117 /** Invalid ASE ID */ 118 BT_BAP_ASCS_RSP_CODE_INVALID_ASE = 0x03, 119 /** Invalid ASE state */ 120 BT_BAP_ASCS_RSP_CODE_INVALID_ASE_STATE = 0x04, 121 /** Invalid operation for direction */ 122 BT_BAP_ASCS_RSP_CODE_INVALID_DIR = 0x05, 123 /** Capabilities not supported by server */ 124 BT_BAP_ASCS_RSP_CODE_CAP_UNSUPPORTED = 0x06, 125 /** Configuration parameters not supported by server */ 126 BT_BAP_ASCS_RSP_CODE_CONF_UNSUPPORTED = 0x07, 127 /** Configuration parameters rejected by server */ 128 BT_BAP_ASCS_RSP_CODE_CONF_REJECTED = 0x08, 129 /** Invalid Configuration parameters */ 130 BT_BAP_ASCS_RSP_CODE_CONF_INVALID = 0x09, 131 /** Unsupported metadata */ 132 BT_BAP_ASCS_RSP_CODE_METADATA_UNSUPPORTED = 0x0a, 133 /** Metadata rejected by server */ 134 BT_BAP_ASCS_RSP_CODE_METADATA_REJECTED = 0x0b, 135 /** Invalid metadata */ 136 BT_BAP_ASCS_RSP_CODE_METADATA_INVALID = 0x0c, 137 /** Server has insufficient resources */ 138 BT_BAP_ASCS_RSP_CODE_NO_MEM = 0x0d, 139 /** Unspecified error */ 140 BT_BAP_ASCS_RSP_CODE_UNSPECIFIED = 0x0e, 141 }; 142 143 /** 144 * @brief Response Reasons 145 * 146 * These are used if the @ref bt_bap_ascs_rsp_code value is 147 * @ref BT_BAP_ASCS_RSP_CODE_CONF_UNSUPPORTED, @ref BT_BAP_ASCS_RSP_CODE_CONF_REJECTED or 148 * @ref BT_BAP_ASCS_RSP_CODE_CONF_INVALID. 149 */ 150 enum bt_bap_ascs_reason { 151 /** No reason */ 152 BT_BAP_ASCS_REASON_NONE = 0x00, 153 /** Codec ID */ 154 BT_BAP_ASCS_REASON_CODEC = 0x01, 155 /** Codec configuration */ 156 BT_BAP_ASCS_REASON_CODEC_DATA = 0x02, 157 /** SDU interval */ 158 BT_BAP_ASCS_REASON_INTERVAL = 0x03, 159 /** Framing */ 160 BT_BAP_ASCS_REASON_FRAMING = 0x04, 161 /** PHY */ 162 BT_BAP_ASCS_REASON_PHY = 0x05, 163 /** Maximum SDU size*/ 164 BT_BAP_ASCS_REASON_SDU = 0x06, 165 /** RTN */ 166 BT_BAP_ASCS_REASON_RTN = 0x07, 167 /** Max transport latency */ 168 BT_BAP_ASCS_REASON_LATENCY = 0x08, 169 /** Presendation delay */ 170 BT_BAP_ASCS_REASON_PD = 0x09, 171 /** Invalid CIS mapping */ 172 BT_BAP_ASCS_REASON_CIS = 0x0a, 173 }; 174 175 /** @brief Structure storing values of fields of ASE Control Point notification. */ 176 struct bt_bap_ascs_rsp { 177 /** 178 * @brief Value of the Response Code field. 179 * 180 * The following response codes are accepted: 181 * - @ref BT_BAP_ASCS_RSP_CODE_SUCCESS 182 * - @ref BT_BAP_ASCS_RSP_CODE_CAP_UNSUPPORTED 183 * - @ref BT_BAP_ASCS_RSP_CODE_CONF_UNSUPPORTED 184 * - @ref BT_BAP_ASCS_RSP_CODE_CONF_REJECTED 185 * - @ref BT_BAP_ASCS_RSP_CODE_METADATA_UNSUPPORTED 186 * - @ref BT_BAP_ASCS_RSP_CODE_METADATA_REJECTED 187 * - @ref BT_BAP_ASCS_RSP_CODE_NO_MEM 188 * - @ref BT_BAP_ASCS_RSP_CODE_UNSPECIFIED 189 */ 190 enum bt_bap_ascs_rsp_code code; 191 192 /** 193 * @brief Value of the Reason field. 194 * 195 * The meaning of this value depend on the Response Code field. 196 */ 197 union { 198 /** 199 * @brief Response reason 200 * 201 * If the Response Code is one of the following: 202 * - @ref BT_BAP_ASCS_RSP_CODE_CONF_UNSUPPORTED 203 * - @ref BT_BAP_ASCS_RSP_CODE_CONF_REJECTED 204 * all values from @ref bt_bap_ascs_reason can be used. 205 * 206 * If the Response Code is one of the following: 207 * - @ref BT_BAP_ASCS_RSP_CODE_SUCCESS 208 * - @ref BT_BAP_ASCS_RSP_CODE_CAP_UNSUPPORTED 209 * - @ref BT_BAP_ASCS_RSP_CODE_NO_MEM 210 * - @ref BT_BAP_ASCS_RSP_CODE_UNSPECIFIED 211 * only value @ref BT_BAP_ASCS_REASON_NONE shall be used. 212 */ 213 enum bt_bap_ascs_reason reason; 214 215 /** 216 * @brief Response metadata type 217 * 218 * If the Response Code is one of the following: 219 * - @ref BT_BAP_ASCS_RSP_CODE_METADATA_UNSUPPORTED 220 * - @ref BT_BAP_ASCS_RSP_CODE_METADATA_REJECTED 221 * the value of the Metadata Type shall be used. 222 */ 223 enum bt_audio_metadata_type metadata_type; 224 }; 225 }; 226 227 /** 228 * @brief Macro used to initialise the object storing values of ASE Control Point notification. 229 * 230 * @param c Response Code field 231 * @param r Reason field - @ref bt_bap_ascs_reason or @ref bt_audio_metadata_type (see notes in 232 * @ref bt_bap_ascs_rsp). 233 */ 234 #define BT_BAP_ASCS_RSP(c, r) (struct bt_bap_ascs_rsp) { .code = c, .reason = r } 235 236 /** @brief Abstract Audio Broadcast Source structure. */ 237 struct bt_bap_broadcast_source; 238 239 /** @brief Abstract Audio Broadcast Sink structure. */ 240 struct bt_bap_broadcast_sink; 241 242 /** @brief Abstract Audio Unicast Group structure. */ 243 struct bt_bap_unicast_group; 244 245 /** @brief Abstract Audio Endpoint structure. */ 246 struct bt_bap_ep; 247 248 /** Struct to hold subgroup specific information for the receive state */ 249 struct bt_bap_bass_subgroup { 250 /** BIS synced bitfield */ 251 uint32_t bis_sync; 252 253 /** Length of the metadata */ 254 uint8_t metadata_len; 255 256 #if defined(CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE) 257 /** The metadata */ 258 uint8_t metadata[CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE]; 259 #endif /* CONFIG_BT_AUDIO_CODEC_CFG_MAX_METADATA_SIZE */ 260 }; 261 262 /** Represents the Broadcast Audio Scan Service receive state */ 263 struct bt_bap_scan_delegator_recv_state { 264 /** The source ID */ 265 uint8_t src_id; 266 267 /** The Bluetooth address */ 268 bt_addr_le_t addr; 269 270 /** The advertising set ID*/ 271 uint8_t adv_sid; 272 273 /** The periodic adverting sync state */ 274 enum bt_bap_pa_state pa_sync_state; 275 276 /** The broadcast isochronous group encryption state */ 277 enum bt_bap_big_enc_state encrypt_state; 278 279 /** The 24-bit broadcast ID */ 280 uint32_t broadcast_id; 281 282 /** @brief The bad broadcast code 283 * 284 * Only valid if encrypt_state is @ref BT_BAP_BIG_ENC_STATE_BCODE_REQ 285 */ 286 uint8_t bad_code[BT_AUDIO_BROADCAST_CODE_SIZE]; 287 288 /** Number of subgroups */ 289 uint8_t num_subgroups; 290 291 /** Subgroup specific information */ 292 struct bt_bap_bass_subgroup subgroups[CONFIG_BT_BAP_BASS_MAX_SUBGROUPS]; 293 }; 294 295 struct bt_bap_scan_delegator_cb { 296 /** 297 * @brief Receive state updated 298 * 299 * @param conn Pointer to the connection to a remote device if 300 * the change was caused by it, otherwise NULL. 301 * @param recv_state Pointer to the receive state that was updated. 302 * 303 * @return 0 in case of success or negative value in case of error. 304 */ 305 void (*recv_state_updated)(struct bt_conn *conn, 306 const struct bt_bap_scan_delegator_recv_state *recv_state); 307 308 /** 309 * @brief Periodic advertising sync request 310 * 311 * Request from peer device to synchronize with the periodic advertiser 312 * denoted by the @p recv_state. To notify the Broadcast Assistant about 313 * any pending sync 314 * 315 * @param[in] conn Pointer to the connection requesting the 316 * periodic advertising sync. 317 * @param[in] recv_state Pointer to the receive state that is being 318 * requested for periodic advertising sync. 319 * @param[in] past_avail True if periodic advertising sync transfer is 320 * available. 321 * @param[in] pa_interval The periodic advertising interval. 322 * @param[out] past_sync Set to true if syncing via periodic 323 * advertising sync transfer, false otherwise. 324 * If @p past_avail is false, this value is 325 * ignored. 326 * 327 * @return 0 in case of accept, or other value to reject. 328 */ 329 int (*pa_sync_req)(struct bt_conn *conn, 330 const struct bt_bap_scan_delegator_recv_state *recv_state, 331 bool past_avail, uint16_t pa_interval); 332 333 /** 334 * @brief Periodic advertising sync termination request 335 * 336 * Request from peer device to terminate the periodic advertiser sync 337 * denoted by the @p recv_state. 338 * 339 * @param conn Pointer to the connection requesting the periodic 340 * advertising sync termination. 341 * @param recv_state Pointer to the receive state that is being 342 * requested for periodic advertising sync. 343 * 344 * @return 0 in case of success or negative value in case of error. 345 */ 346 int (*pa_sync_term_req)(struct bt_conn *conn, 347 const struct bt_bap_scan_delegator_recv_state *recv_state); 348 349 /** 350 * @brief Broadcast code received 351 * 352 * Broadcast code received from a broadcast assistant 353 * 354 * @param conn Pointer to the connection providing the 355 * broadcast code. 356 * @param recv_state Pointer to the receive state the broadcast code 357 * is being provided for. 358 * @param broadcast_code The 16-octet broadcast code 359 */ 360 void (*broadcast_code)(struct bt_conn *conn, 361 const struct bt_bap_scan_delegator_recv_state *recv_state, 362 const uint8_t broadcast_code[BT_AUDIO_BROADCAST_CODE_SIZE]); 363 /** 364 * @brief Broadcast Isochronous Stream synchronize request 365 * 366 * Request from Broadcast Assistant device to modify the Broadcast 367 * Isochronous Stream states. The request shall be fulfilled with 368 * accordance to the @p bis_sync_req within reasonable time. The 369 * Broadcast Assistant may also request fewer, or none, indexes to 370 * be synchronized. 371 * 372 * @param[in] conn Pointer to the connection of the 373 * Broadcast Assistant requesting the sync. 374 * @param[in] recv_state Pointer to the receive state that is being 375 * requested for the sync. 376 * @param[in] bis_sync_req Array of bitfields of which BIS indexes 377 * that is requested to sync for each subgroup 378 * by the Broadcast Assistant. A value of 0 379 * indicates a request to terminate the BIG 380 * sync. 381 * 382 * @return 0 in case of accept, or other value to reject. 383 */ 384 int (*bis_sync_req)(struct bt_conn *conn, 385 const struct bt_bap_scan_delegator_recv_state *recv_state, 386 const uint32_t bis_sync_req[CONFIG_BT_BAP_BASS_MAX_SUBGROUPS]); 387 }; 388 389 /** Structure holding information of audio stream endpoint */ 390 struct bt_bap_ep_info { 391 /** The ID of the endpoint */ 392 uint8_t id; 393 394 /** The state of the endpoint */ 395 enum bt_bap_ep_state state; 396 397 /** Capabilities type */ 398 enum bt_audio_dir dir; 399 400 /** @brief True if the stream associated with the endpoint is able to send data */ 401 bool can_send; 402 403 /** Pointer to paired endpoint if the endpoint is part of a bidirectional CIS, 404 * otherwise NULL 405 */ 406 struct bt_bap_ep *paired_ep; 407 }; 408 409 /** 410 * @brief Return structure holding information of audio stream endpoint 411 * 412 * @param ep The audio stream endpoint object. 413 * @param info The structure object to be filled with the info. 414 * 415 * @return 0 in case of success or negative value in case of error. 416 */ 417 int bt_bap_ep_get_info(const struct bt_bap_ep *ep, struct bt_bap_ep_info *info); 418 419 /** 420 * @brief Basic Audio Profile stream structure. 421 * 422 * Streams represents a stream configuration of a Remote Endpoint and a Local Capability. 423 * 424 * @note Streams are unidirectional but can be paired with other streams to use a bidirectional 425 * connected isochronous stream. 426 */ 427 struct bt_bap_stream { 428 /** Connection reference */ 429 struct bt_conn *conn; 430 431 /** Endpoint reference */ 432 struct bt_bap_ep *ep; 433 434 /** Codec Configuration */ 435 struct bt_audio_codec_cfg *codec_cfg; 436 437 /** QoS Configuration */ 438 struct bt_audio_codec_qos *qos; 439 440 /** Audio stream operations */ 441 struct bt_bap_stream_ops *ops; 442 443 #if defined(CONFIG_BT_BAP_UNICAST_CLIENT) 444 /** 445 * @brief Audio ISO reference 446 * 447 * This is only used for Unicast Client streams, and is handled internally. 448 */ 449 struct bt_bap_iso *bap_iso; 450 #endif /* CONFIG_BT_BAP_UNICAST_CLIENT */ 451 452 /** Unicast or Broadcast group - Used internally */ 453 void *group; 454 455 /** Stream user data */ 456 void *user_data; 457 458 #if defined(CONFIG_BT_BAP_DEBUG_STREAM_SEQ_NUM) 459 uint16_t _prev_seq_num; 460 #endif /* CONFIG_BT_BAP_DEBUG_STREAM_SEQ_NUM */ 461 462 /* Internally used list node */ 463 sys_snode_t _node; 464 }; 465 466 /** @brief Stream operation. */ 467 struct bt_bap_stream_ops { 468 #if defined(CONFIG_BT_BAP_UNICAST) 469 /** 470 * @brief Stream configured callback 471 * 472 * Configured callback is called whenever an Audio Stream has been configured. 473 * 474 * @param stream Stream object that has been configured. 475 * @param pref Remote QoS preferences. 476 */ 477 void (*configured)(struct bt_bap_stream *stream, 478 const struct bt_audio_codec_qos_pref *pref); 479 480 /** 481 * @brief Stream QoS set callback 482 * 483 * QoS set callback is called whenever an Audio Stream Quality of Service has been set or 484 * updated. 485 * 486 * @param stream Stream object that had its QoS updated. 487 */ 488 void (*qos_set)(struct bt_bap_stream *stream); 489 490 /** 491 * @brief Stream enabled callback 492 * 493 * Enabled callback is called whenever an Audio Stream has been enabled. 494 * 495 * @param stream Stream object that has been enabled. 496 */ 497 void (*enabled)(struct bt_bap_stream *stream); 498 499 /** 500 * @brief Stream metadata updated callback 501 * 502 * Metadata Updated callback is called whenever an Audio Stream's metadata has been 503 * updated. 504 * 505 * @param stream Stream object that had its metadata updated. 506 */ 507 void (*metadata_updated)(struct bt_bap_stream *stream); 508 509 /** 510 * @brief Stream disabled callback 511 * 512 * Disabled callback is called whenever an Audio Stream has been disabled. 513 * 514 * @param stream Stream object that has been disabled. 515 */ 516 void (*disabled)(struct bt_bap_stream *stream); 517 518 /** 519 * @brief Stream released callback 520 * 521 * Released callback is called whenever a Audio Stream has been released and can be 522 * deallocated. 523 * 524 * @param stream Stream object that has been released. 525 */ 526 void (*released)(struct bt_bap_stream *stream); 527 #endif /* CONFIG_BT_BAP_UNICAST */ 528 529 /** 530 * @brief Stream started callback 531 * 532 * Started callback is called whenever an Audio Stream has been started 533 * and will be usable for streaming. 534 * 535 * @param stream Stream object that has been started. 536 */ 537 void (*started)(struct bt_bap_stream *stream); 538 539 /** 540 * @brief Stream stopped callback 541 * 542 * Stopped callback is called whenever an Audio Stream has been stopped. 543 * 544 * @param stream Stream object that has been stopped. 545 * @param reason BT_HCI_ERR_* reason for the disconnection. 546 */ 547 void (*stopped)(struct bt_bap_stream *stream, uint8_t reason); 548 549 #if defined(CONFIG_BT_AUDIO_RX) 550 /** 551 * @brief Stream audio HCI receive callback. 552 * 553 * This callback is only used if the ISO data path is HCI. 554 * 555 * @param stream Stream object. 556 * @param info Pointer to the metadata for the buffer. The lifetime of the pointer is 557 * linked to the lifetime of the net_buf. Metadata such as sequence number and 558 * timestamp can be provided by the bluetooth controller. 559 * @param buf Buffer containing incoming audio data. 560 */ 561 void (*recv)(struct bt_bap_stream *stream, const struct bt_iso_recv_info *info, 562 struct net_buf *buf); 563 #endif /* CONFIG_BT_AUDIO_RX */ 564 565 #if defined(CONFIG_BT_AUDIO_TX) 566 /** 567 * @brief Stream audio HCI sent callback 568 * 569 * This callback will be called once the controller marks the SDU 570 * as completed. When the controller does so is implementation 571 * dependent. It could be after the SDU is enqueued for transmission, 572 * or after it is sent on air or flushed. 573 * 574 * This callback is only used if the ISO data path is HCI. 575 * 576 * @param stream Stream object. 577 */ 578 void (*sent)(struct bt_bap_stream *stream); 579 #endif /* CONFIG_BT_AUDIO_TX */ 580 581 /** 582 * @brief Isochronous channel connected callback 583 * 584 * If this callback is provided it will be called whenever the isochronous channel for the 585 * stream has been connected. This does not mean that the stream is ready to be used, which 586 * is indicated by the @ref bt_bap_stream_ops.started callback. 587 * 588 * If the stream shares an isochronous channel with another stream, then this callback may 589 * still be called, without the stream going into the started state. 590 * 591 * @param stream Stream object. 592 */ 593 void (*connected)(struct bt_bap_stream *stream); 594 595 /** 596 * @brief Isochronous channel disconnected callback 597 * 598 * If this callback is provided it will be called whenever the isochronous channel is 599 * disconnected, including when a connection gets rejected. 600 * 601 * If the stream shares an isochronous channel with another stream, then this callback may 602 * not be called, even if the stream is leaving the streaming state. 603 * 604 * @param stream Stream object. 605 * @param reason BT_HCI_ERR_* reason for the disconnection. 606 */ 607 void (*disconnected)(struct bt_bap_stream *stream, uint8_t reason); 608 }; 609 610 /** 611 * @brief Register Audio callbacks for a stream. 612 * 613 * Register Audio callbacks for a stream. 614 * 615 * @param stream Stream object. 616 * @param ops Stream operations structure. 617 */ 618 void bt_bap_stream_cb_register(struct bt_bap_stream *stream, struct bt_bap_stream_ops *ops); 619 620 /** 621 * @brief Configure Audio Stream 622 * 623 * This procedure is used by a client to configure a new stream using the 624 * remote endpoint, local capability and codec configuration. 625 * 626 * @param conn Connection object 627 * @param stream Stream object being configured 628 * @param ep Remote Audio Endpoint being configured 629 * @param codec_cfg Codec configuration 630 * 631 * @return Allocated Audio Stream object or NULL in case of error. 632 */ 633 int bt_bap_stream_config(struct bt_conn *conn, struct bt_bap_stream *stream, struct bt_bap_ep *ep, 634 struct bt_audio_codec_cfg *codec_cfg); 635 636 /** 637 * @brief Reconfigure Audio Stream 638 * 639 * This procedure is used by a unicast client or unicast server to reconfigure 640 * a stream to use a different local codec configuration. 641 * 642 * This can only be done for unicast streams. 643 * 644 * @param stream Stream object being reconfigured 645 * @param codec_cfg Codec configuration 646 * 647 * @return 0 in case of success or negative value in case of error. 648 */ 649 int bt_bap_stream_reconfig(struct bt_bap_stream *stream, struct bt_audio_codec_cfg *codec_cfg); 650 651 /** 652 * @brief Configure Audio Stream QoS 653 * 654 * This procedure is used by a client to configure the Quality of Service of streams in a unicast 655 * group. All streams in the group for the specified @p conn will have the Quality of Service 656 * configured. This shall only be used to configure unicast streams. 657 * 658 * @param conn Connection object 659 * @param group Unicast group object 660 * 661 * @return 0 in case of success or negative value in case of error. 662 */ 663 int bt_bap_stream_qos(struct bt_conn *conn, struct bt_bap_unicast_group *group); 664 665 /** 666 * @brief Enable Audio Stream 667 * 668 * This procedure is used by a client to enable a stream. 669 * 670 * This shall only be called for unicast streams, as broadcast streams will always be enabled once 671 * created. 672 * 673 * @param stream Stream object 674 * @param meta Metadata 675 * @param meta_len Metadata length 676 * 677 * @return 0 in case of success or negative value in case of error. 678 */ 679 int bt_bap_stream_enable(struct bt_bap_stream *stream, const uint8_t meta[], size_t meta_len); 680 681 /** 682 * @brief Change Audio Stream Metadata 683 * 684 * This procedure is used by a unicast client or unicast server to change the metadata of a stream. 685 * 686 * @param stream Stream object 687 * @param meta Metadata 688 * @param meta_len Metadata length 689 * 690 * @return 0 in case of success or negative value in case of error. 691 */ 692 int bt_bap_stream_metadata(struct bt_bap_stream *stream, const uint8_t meta[], size_t meta_len); 693 694 /** 695 * @brief Disable Audio Stream 696 * 697 * This procedure is used by a unicast client or unicast server to disable a stream. 698 * 699 * This shall only be called for unicast streams, as broadcast streams will 700 * always be enabled once created. 701 * 702 * @param stream Stream object 703 * 704 * @return 0 in case of success or negative value in case of error. 705 */ 706 int bt_bap_stream_disable(struct bt_bap_stream *stream); 707 708 /** 709 * @brief Start Audio Stream 710 * 711 * This procedure is used by a unicast client or unicast server to make a stream start streaming. 712 * 713 * For the unicast client, this will connect the CIS for the stream before 714 * sending the start command. 715 * 716 * For the unicast server, this will put a @ref BT_AUDIO_DIR_SINK stream into the streaming state if 717 * the CIS is connected (initialized by the unicast client). If the CIS is not connected yet, the 718 * stream will go into the streaming state as soon as the CIS is connected. 719 * @ref BT_AUDIO_DIR_SOURCE streams will go into the streaming state when the unicast client sends 720 * the Receiver Start Ready operation, which will trigger the @ref bt_bap_unicast_server_cb.start() 721 * callback. 722 * 723 * This shall only be called for unicast streams. 724 * 725 * Broadcast sinks will always be started once synchronized, and broadcast 726 * source streams shall be started with bt_bap_broadcast_source_start(). 727 * 728 * @param stream Stream object 729 * 730 * @return 0 in case of success or negative value in case of error. 731 */ 732 int bt_bap_stream_start(struct bt_bap_stream *stream); 733 734 /** 735 * @brief Stop Audio Stream 736 * 737 * This procedure is used by a client to make a stream stop streaming. 738 * 739 * This shall only be called for unicast streams. 740 * Broadcast sinks cannot be stopped. 741 * Broadcast sources shall be stopped with bt_bap_broadcast_source_stop(). 742 * 743 * @param stream Stream object 744 * 745 * @return 0 in case of success or negative value in case of error. 746 */ 747 int bt_bap_stream_stop(struct bt_bap_stream *stream); 748 749 /** 750 * @brief Release Audio Stream 751 * 752 * This procedure is used by a unicast client or unicast server to release a unicast stream. 753 * 754 * Broadcast sink streams cannot be released, but can be deleted by bt_bap_broadcast_sink_delete(). 755 * Broadcast source streams cannot be released, but can be deleted by 756 * bt_bap_broadcast_source_delete(). 757 * 758 * @param stream Stream object 759 * 760 * @return 0 in case of success or negative value in case of error. 761 */ 762 int bt_bap_stream_release(struct bt_bap_stream *stream); 763 764 /** 765 * @brief Send data to Audio stream without timestamp 766 * 767 * Send data from buffer to the stream. 768 * 769 * @note Support for sending must be supported, determined by @kconfig{CONFIG_BT_AUDIO_TX}. 770 * 771 * @param stream Stream object. 772 * @param buf Buffer containing data to be sent. 773 * @param seq_num Packet Sequence number. This value shall be incremented for each call to this 774 * function and at least once per SDU interval for a specific channel. 775 * 776 * @return Bytes sent in case of success or negative value in case of error. 777 */ 778 int bt_bap_stream_send(struct bt_bap_stream *stream, struct net_buf *buf, uint16_t seq_num); 779 780 /** 781 * @brief Send data to Audio stream with timestamp 782 * 783 * Send data from buffer to the stream. 784 * 785 * @note Support for sending must be supported, determined by @kconfig{CONFIG_BT_AUDIO_TX}. 786 * 787 * @param stream Stream object. 788 * @param buf Buffer containing data to be sent. 789 * @param seq_num Packet Sequence number. This value shall be incremented for each call to this 790 * function and at least once per SDU interval for a specific channel. 791 * @param ts Timestamp of the SDU in microseconds (us). This value can be used to transmit 792 * multiple SDUs in the same SDU interval in a CIG or BIG. 793 * 794 * @return Bytes sent in case of success or negative value in case of error. 795 */ 796 int bt_bap_stream_send_ts(struct bt_bap_stream *stream, struct net_buf *buf, uint16_t seq_num, 797 uint32_t ts); 798 799 /** 800 * @brief Get ISO transmission timing info for a Basic Audio Profile stream 801 * 802 * Reads timing information for transmitted ISO packet on an ISO channel. 803 * The HCI_LE_Read_ISO_TX_Sync HCI command is used to retrieve this information from the controller. 804 * 805 * @note An SDU must have already been successfully transmitted on the ISO channel 806 * for this function to return successfully. 807 * Support for sending must be supported, determined by @kconfig{CONFIG_BT_AUDIO_TX}. 808 * 809 * @param[in] stream Stream object. 810 * @param[out] info Transmit info object. 811 * 812 * @retval 0 on success 813 * @retval -EINVAL if the stream is invalid, if the stream is not configured for sending or if it is 814 * not connected with a isochronous stream 815 * @retval Any return value from bt_iso_chan_get_tx_sync() 816 */ 817 int bt_bap_stream_get_tx_sync(struct bt_bap_stream *stream, struct bt_iso_tx_info *info); 818 819 /** 820 * @defgroup bt_bap_unicast_server BAP Unicast Server APIs 821 * @ingroup bt_bap 822 * @{ 823 */ 824 825 /** Unicast Server callback structure */ 826 struct bt_bap_unicast_server_cb { 827 /** 828 * @brief Endpoint config request callback 829 * 830 * Config callback is called whenever an endpoint is requested to be 831 * configured 832 * 833 * @param[in] conn Connection object. 834 * @param[in] ep Local Audio Endpoint being configured. 835 * @param[in] dir Direction of the endpoint. 836 * @param[in] codec_cfg Codec configuration. 837 * @param[out] stream Pointer to stream that will be configured for the endpoint. 838 * @param[out] pref Pointer to a QoS preference object that shall be populated with 839 * values. Invalid values will reject the codec configuration request. 840 * @param[out] rsp Object for the ASE operation response. Only used if the return 841 * value is non-zero. 842 * 843 * @return 0 in case of success or negative value in case of error. 844 */ 845 int (*config)(struct bt_conn *conn, const struct bt_bap_ep *ep, enum bt_audio_dir dir, 846 const struct bt_audio_codec_cfg *codec_cfg, struct bt_bap_stream **stream, 847 struct bt_audio_codec_qos_pref *const pref, struct bt_bap_ascs_rsp *rsp); 848 849 /** 850 * @brief Stream reconfig request callback 851 * 852 * Reconfig callback is called whenever an Audio Stream needs to be 853 * reconfigured with different codec configuration. 854 * 855 * @param[in] stream Stream object being reconfigured. 856 * @param[in] dir Direction of the endpoint. 857 * @param[in] codec_cfg Codec configuration. 858 * @param[out] pref Pointer to a QoS preference object that shall be populated with 859 * values. Invalid values will reject the codec configuration request. 860 * @param[out] rsp Object for the ASE operation response. Only used if the return 861 * value is non-zero. 862 * 863 * @return 0 in case of success or negative value in case of error. 864 */ 865 int (*reconfig)(struct bt_bap_stream *stream, enum bt_audio_dir dir, 866 const struct bt_audio_codec_cfg *codec_cfg, 867 struct bt_audio_codec_qos_pref *const pref, struct bt_bap_ascs_rsp *rsp); 868 869 /** 870 * @brief Stream QoS request callback 871 * 872 * QoS callback is called whenever an Audio Stream Quality of 873 * Service needs to be configured. 874 * 875 * @param[in] stream Stream object being reconfigured. 876 * @param[in] qos Quality of Service configuration. 877 * @param[out] rsp Object for the ASE operation response. Only used if the return 878 * value is non-zero. 879 * 880 * @return 0 in case of success or negative value in case of error. 881 */ 882 int (*qos)(struct bt_bap_stream *stream, const struct bt_audio_codec_qos *qos, 883 struct bt_bap_ascs_rsp *rsp); 884 885 /** 886 * @brief Stream Enable request callback 887 * 888 * Enable callback is called whenever an Audio Stream is requested to be enabled to stream. 889 * 890 * @param[in] stream Stream object being enabled. 891 * @param[in] meta Metadata entries. 892 * @param[in] meta_len Length of metadata. 893 * @param[out] rsp Object for the ASE operation response. Only used if the return 894 * value is non-zero. 895 * 896 * @return 0 in case of success or negative value in case of error. 897 */ 898 int (*enable)(struct bt_bap_stream *stream, const uint8_t meta[], size_t meta_len, 899 struct bt_bap_ascs_rsp *rsp); 900 901 /** 902 * @brief Stream Start request callback 903 * 904 * Start callback is called whenever an Audio Stream is requested to start streaming. 905 * 906 * @param[in] stream Stream object. 907 * @param[out] rsp Object for the ASE operation response. Only used if the return 908 * value is non-zero. 909 * 910 * @return 0 in case of success or negative value in case of error. 911 */ 912 int (*start)(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp); 913 914 /** 915 * @brief Stream Metadata update request callback 916 * 917 * Metadata callback is called whenever an Audio Stream is requested to update its metadata. 918 * 919 * @param[in] stream Stream object. 920 * @param[in] meta Metadata entries. 921 * @param[in] meta_len Length of metadata. 922 * @param[out] rsp Object for the ASE operation response. Only used if the return 923 * value is non-zero. 924 * 925 * @return 0 in case of success or negative value in case of error. 926 */ 927 int (*metadata)(struct bt_bap_stream *stream, const uint8_t meta[], size_t meta_len, 928 struct bt_bap_ascs_rsp *rsp); 929 930 /** 931 * @brief Stream Disable request callback 932 * 933 * Disable callback is called whenever an Audio Stream is requested to disable the stream. 934 * 935 * @param[in] stream Stream object being disabled. 936 * @param[out] rsp Object for the ASE operation response. Only used if the return 937 * value is non-zero. 938 * 939 * @return 0 in case of success or negative value in case of error. 940 */ 941 int (*disable)(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp); 942 943 /** 944 * @brief Stream Stop callback 945 * 946 * Stop callback is called whenever an Audio Stream is requested to stop streaming. 947 * 948 * @param[in] stream Stream object. 949 * @param[out] rsp Object for the ASE operation response. Only used if the return 950 * value is non-zero. 951 * 952 * @return 0 in case of success or negative value in case of error. 953 */ 954 int (*stop)(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp); 955 956 /** 957 * @brief Stream release callback 958 * 959 * Release callback is called whenever a new Audio Stream needs to be released and thus 960 * deallocated. 961 * 962 * @param[in] stream Stream object. 963 * @param[out] rsp Object for the ASE operation response. Only used if the return 964 * value is non-zero. 965 * 966 * @return 0 in case of success or negative value in case of error. 967 */ 968 int (*release)(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp); 969 }; 970 971 /** 972 * @brief Register unicast server callbacks. 973 * 974 * Only one callback structure can be registered, and attempting to 975 * registering more than one will result in an error. 976 * 977 * @param cb Unicast server callback structure. 978 * 979 * @return 0 in case of success or negative value in case of error. 980 */ 981 int bt_bap_unicast_server_register_cb(const struct bt_bap_unicast_server_cb *cb); 982 983 /** 984 * @brief Unregister unicast server callbacks. 985 * 986 * May only unregister a callback structure that has previously been 987 * registered by bt_bap_unicast_server_register_cb(). 988 * 989 * @param cb Unicast server callback structure. 990 * 991 * @return 0 in case of success or negative value in case of error. 992 */ 993 int bt_bap_unicast_server_unregister_cb(const struct bt_bap_unicast_server_cb *cb); 994 995 /** 996 * @typedef bt_bap_ep_func_t 997 * @brief The callback function called for each endpoint. 998 * 999 * @param ep The structure object with endpoint info. 1000 * @param user_data Data to pass to the function. 1001 */ 1002 typedef void (*bt_bap_ep_func_t)(struct bt_bap_ep *ep, void *user_data); 1003 1004 /** 1005 * @brief Iterate through all endpoints of the given connection. 1006 * 1007 * @param conn Connection object 1008 * @param func Function to call for each endpoint. 1009 * @param user_data Data to pass to the callback function. 1010 */ 1011 void bt_bap_unicast_server_foreach_ep(struct bt_conn *conn, bt_bap_ep_func_t func, void *user_data); 1012 1013 /** 1014 * @brief Initialize and configure a new ASE. 1015 * 1016 * @param conn Connection object 1017 * @param stream Configured stream object to be attached to the ASE 1018 * @param codec_cfg Codec configuration 1019 * @param qos_pref Audio Stream Quality of Service Preference 1020 * 1021 * @return 0 in case of success or negative value in case of error. 1022 */ 1023 int bt_bap_unicast_server_config_ase(struct bt_conn *conn, struct bt_bap_stream *stream, 1024 struct bt_audio_codec_cfg *codec_cfg, 1025 const struct bt_audio_codec_qos_pref *qos_pref); 1026 1027 /** @} */ /* End of group bt_bap_unicast_server */ 1028 1029 /** 1030 * @defgroup bt_bap_unicast_client BAP Unicast Client APIs 1031 * @ingroup bt_bap 1032 * @{ 1033 */ 1034 1035 /** Parameter struct for each stream in the unicast group */ 1036 struct bt_bap_unicast_group_stream_param { 1037 /** Pointer to a stream object. */ 1038 struct bt_bap_stream *stream; 1039 1040 /** The QoS settings for the stream object. */ 1041 struct bt_audio_codec_qos *qos; 1042 }; 1043 1044 /** @brief Parameter struct for the unicast group functions 1045 * 1046 * Parameter struct for the bt_bap_unicast_group_create() and 1047 * bt_bap_unicast_group_add_streams() functions. 1048 */ 1049 struct bt_bap_unicast_group_stream_pair_param { 1050 /** Pointer to a receiving stream parameters. */ 1051 struct bt_bap_unicast_group_stream_param *rx_param; 1052 1053 /** Pointer to a transmiting stream parameters. */ 1054 struct bt_bap_unicast_group_stream_param *tx_param; 1055 }; 1056 1057 struct bt_bap_unicast_group_param { 1058 /** The number of parameters in @p params */ 1059 size_t params_count; 1060 1061 /** Array of stream parameters */ 1062 struct bt_bap_unicast_group_stream_pair_param *params; 1063 1064 /** @brief Unicast Group packing mode. 1065 * 1066 * @ref BT_ISO_PACKING_SEQUENTIAL or @ref BT_ISO_PACKING_INTERLEAVED. 1067 * 1068 * @note This is a recommendation to the controller, which the controller may ignore. 1069 */ 1070 uint8_t packing; 1071 1072 #if defined(CONFIG_BT_ISO_TEST_PARAMS) 1073 /** @brief Central to Peripheral flush timeout 1074 * 1075 * The flush timeout in multiples of ISO_Interval for each payload sent 1076 * from the Central to Peripheral. 1077 * 1078 * Value range from @ref BT_ISO_FT_MIN to @ref BT_ISO_FT_MAX 1079 */ 1080 uint8_t c_to_p_ft; 1081 1082 /** @brief Peripheral to Central flush timeout 1083 * 1084 * The flush timeout in multiples of ISO_Interval for each payload sent 1085 * from the Peripheral to Central. 1086 * 1087 * Value range from @ref BT_ISO_FT_MIN to @ref BT_ISO_FT_MAX. 1088 */ 1089 uint8_t p_to_c_ft; 1090 1091 /** @brief ISO interval 1092 * 1093 * Time between consecutive CIS anchor points. 1094 * 1095 * Value range from @ref BT_ISO_ISO_INTERVAL_MIN to 1096 * @ref BT_ISO_ISO_INTERVAL_MAX. 1097 */ 1098 uint16_t iso_interval; 1099 #endif /* CONFIG_BT_ISO_TEST_PARAMS */ 1100 }; 1101 1102 /** 1103 * @brief Create audio unicast group. 1104 * 1105 * Create a new audio unicast group with one or more audio streams as a unicast client. Streams in 1106 * a unicast group shall share the same interval, framing and latency (see @ref bt_audio_codec_qos). 1107 * 1108 * @param[in] param The unicast group create parameters. 1109 * @param[out] unicast_group Pointer to the unicast group created. 1110 * 1111 * @return Zero on success or (negative) error code otherwise. 1112 */ 1113 int bt_bap_unicast_group_create(struct bt_bap_unicast_group_param *param, 1114 struct bt_bap_unicast_group **unicast_group); 1115 1116 /** 1117 * @brief Add streams to a unicast group as a unicast client 1118 * 1119 * This function can be used to add additional streams to a bt_bap_unicast_group. 1120 * 1121 * This can be called at any time before any of the streams in the group has been started 1122 * (see bt_bap_stream_ops.started()). 1123 * This can also be called after the streams have been stopped (see bt_bap_stream_ops.stopped()). 1124 * 1125 * Once a stream has been added to a unicast group, it cannot be removed. To remove a stream from a 1126 * group, the group must be deleted with bt_bap_unicast_group_delete(), but this will require all 1127 * streams in the group to be released first. 1128 * 1129 * @param unicast_group Pointer to the unicast group 1130 * @param params Array of stream parameters with streams being added to the group. 1131 * @param num_param Number of paramers in @p params. 1132 * 1133 * @return 0 in case of success or negative value in case of error. 1134 */ 1135 int bt_bap_unicast_group_add_streams(struct bt_bap_unicast_group *unicast_group, 1136 struct bt_bap_unicast_group_stream_pair_param params[], 1137 size_t num_param); 1138 1139 /** 1140 * @brief Delete audio unicast group. 1141 * 1142 * Delete a audio unicast group as a client. All streams in the group shall 1143 * be in the idle or configured state. 1144 * 1145 * @param unicast_group Pointer to the unicast group to delete 1146 * 1147 * @return Zero on success or (negative) error code otherwise. 1148 */ 1149 int bt_bap_unicast_group_delete(struct bt_bap_unicast_group *unicast_group); 1150 1151 /** Unicast Client callback structure */ 1152 struct bt_bap_unicast_client_cb { 1153 /** 1154 * @brief Remote Unicast Server Audio Locations 1155 * 1156 * This callback is called whenever the audio locations is read from 1157 * the server or otherwise notified to the client. 1158 * 1159 * @param conn Connection to the remote unicast server. 1160 * @param dir Direction of the location. 1161 * @param loc The location bitfield value. 1162 * 1163 * @return 0 in case of success or negative value in case of error. 1164 */ 1165 void (*location)(struct bt_conn *conn, enum bt_audio_dir dir, enum bt_audio_location loc); 1166 1167 /** 1168 * @brief Remote Unicast Server Available Contexts 1169 * 1170 * This callback is called whenever the available contexts are read 1171 * from the server or otherwise notified to the client. 1172 * 1173 * @param conn Connection to the remote unicast server. 1174 * @param snk_ctx The sink context bitfield value. 1175 * @param src_ctx The source context bitfield value. 1176 * 1177 * @return 0 in case of success or negative value in case of error. 1178 */ 1179 void (*available_contexts)(struct bt_conn *conn, enum bt_audio_context snk_ctx, 1180 enum bt_audio_context src_ctx); 1181 1182 /** 1183 * @brief Callback function for bt_bap_stream_config() and bt_bap_stream_reconfig(). 1184 * 1185 * Called when the codec configure operation is completed on the server. 1186 * 1187 * @param stream Stream the operation was performed on. 1188 * @param rsp_code Response code. 1189 * @param reason Reason code. 1190 */ 1191 void (*config)(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, 1192 enum bt_bap_ascs_reason reason); 1193 1194 /** 1195 * @brief Callback function for bt_bap_stream_qos(). 1196 * 1197 * Called when the QoS configure operation is completed on the server. 1198 * This will be called for each stream in the group that was being QoS 1199 * configured. 1200 * 1201 * @param stream Stream the operation was performed on. May be NULL if there is no stream 1202 * associated with the ASE ID sent by the server. 1203 * @param rsp_code Response code. 1204 * @param reason Reason code. 1205 */ 1206 void (*qos)(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, 1207 enum bt_bap_ascs_reason reason); 1208 1209 /** 1210 * @brief Callback function for bt_bap_stream_enable(). 1211 * 1212 * Called when the enable operation is completed on the server. 1213 * 1214 * @param stream Stream the operation was performed on. May be NULL if there is no stream 1215 * associated with the ASE ID sent by the server. 1216 * @param rsp_code Response code. 1217 * @param reason Reason code. 1218 */ 1219 void (*enable)(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, 1220 enum bt_bap_ascs_reason reason); 1221 1222 /** 1223 * @brief Callback function for bt_bap_stream_start(). 1224 * 1225 * Called when the start operation is completed on the server. This will 1226 * only be called if the stream supplied to bt_bap_stream_start() is 1227 * for a @ref BT_AUDIO_DIR_SOURCE endpoint. 1228 * 1229 * @param stream Stream the operation was performed on. May be NULL if there is no stream 1230 * associated with the ASE ID sent by the server. 1231 * @param rsp_code Response code. 1232 * @param reason Reason code. 1233 */ 1234 void (*start)(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, 1235 enum bt_bap_ascs_reason reason); 1236 1237 /** 1238 * @brief Callback function for bt_bap_stream_stop(). 1239 * 1240 * Called when the stop operation is completed on the server. This will 1241 * only be called if the stream supplied to bt_bap_stream_stop() is 1242 * for a @ref BT_AUDIO_DIR_SOURCE endpoint. 1243 * 1244 * @param stream Stream the operation was performed on. May be NULL if there is no stream 1245 * associated with the ASE ID sent by the server. 1246 * @param rsp_code Response code. 1247 * @param reason Reason code. 1248 */ 1249 void (*stop)(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, 1250 enum bt_bap_ascs_reason reason); 1251 1252 /** 1253 * @brief Callback function for bt_bap_stream_disable(). 1254 * 1255 * Called when the disable operation is completed on the server. 1256 * 1257 * @param stream Stream the operation was performed on. May be NULL if there is no stream 1258 * associated with the ASE ID sent by the server. 1259 * @param rsp_code Response code. 1260 * @param reason Reason code. 1261 */ 1262 void (*disable)(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, 1263 enum bt_bap_ascs_reason reason); 1264 1265 /** 1266 * @brief Callback function for bt_bap_stream_metadata(). 1267 * 1268 * Called when the metadata operation is completed on the server. 1269 * 1270 * @param stream Stream the operation was performed on. May be NULL if there is no stream 1271 * associated with the ASE ID sent by the server. 1272 * @param rsp_code Response code. 1273 * @param reason Reason code. 1274 */ 1275 void (*metadata)(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, 1276 enum bt_bap_ascs_reason reason); 1277 1278 /** 1279 * @brief Callback function for bt_bap_stream_release(). 1280 * 1281 * Called when the release operation is completed on the server. 1282 * 1283 * @param stream Stream the operation was performed on. May be NULL if there is no stream 1284 * associated with the ASE ID sent by the server. 1285 * @param rsp_code Response code. 1286 * @param reason Reason code. 1287 */ 1288 void (*release)(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code, 1289 enum bt_bap_ascs_reason reason); 1290 1291 /** 1292 * @brief Remote Published Audio Capability (PAC) record discovered 1293 * 1294 * Called when a PAC record has been discovered as part of the discovery procedure. 1295 * 1296 * The @p codec is only valid while in the callback, so the values must be stored by the 1297 * receiver if future use is wanted. 1298 * 1299 * @param conn Connection to the remote unicast server. 1300 * @param dir The type of remote endpoints and capabilities discovered. 1301 * @param codec_cap Remote capabilities. 1302 * 1303 * If discovery procedure has complete both @p codec and @p ep are set to NULL. 1304 */ 1305 void (*pac_record)(struct bt_conn *conn, enum bt_audio_dir dir, 1306 const struct bt_audio_codec_cap *codec_cap); 1307 1308 /** 1309 * @brief Remote Audio Stream Endoint (ASE) discovered 1310 * 1311 * Called when an ASE has been discovered as part of the discovery procedure. 1312 * 1313 * @param conn Connection to the remote unicast server. 1314 * @param dir The type of remote endpoints and capabilities discovered. 1315 * @param ep Remote endpoint. 1316 * 1317 * If discovery procedure has complete both @p codec and @p ep are set to NULL. 1318 */ 1319 void (*endpoint)(struct bt_conn *conn, enum bt_audio_dir dir, struct bt_bap_ep *ep); 1320 1321 /** 1322 * @brief BAP discovery callback function. 1323 * 1324 * If discovery procedure has completed @p ep is set to NULL and @p err is 0. 1325 * 1326 * @param conn Connection to the remote unicast server. 1327 * @param err Error value. 0 on success, GATT error on positive value or errno on 1328 * negative value. 1329 * @param dir The type of remote endpoints and capabilities discovered. 1330 * 1331 * If discovery procedure has complete both @p codec and @p ep are set to NULL. 1332 */ 1333 void (*discover)(struct bt_conn *conn, int err, enum bt_audio_dir dir); 1334 }; 1335 1336 /** 1337 * @brief Register unicast client callbacks. 1338 * 1339 * Only one callback structure can be registered, and attempting to 1340 * registering more than one will result in an error. 1341 * 1342 * @param cb Unicast client callback structure. 1343 * 1344 * @return 0 in case of success or negative value in case of error. 1345 */ 1346 int bt_bap_unicast_client_register_cb(const struct bt_bap_unicast_client_cb *cb); 1347 1348 /** 1349 * @brief Discover remote capabilities and endpoints 1350 * 1351 * This procedure is used by a client to discover remote capabilities and 1352 * endpoints and notifies via params callback. 1353 * 1354 * @param conn Connection object 1355 * @param dir The type of remote endpoints and capabilities to discover. 1356 */ 1357 int bt_bap_unicast_client_discover(struct bt_conn *conn, enum bt_audio_dir dir); 1358 1359 /** @} */ /* End of group bt_bap_unicast_client */ 1360 /** 1361 * @brief BAP Broadcast APIs 1362 * @defgroup bt_bap_broadcast BAP Broadcast APIs 1363 * @ingroup bt_bap 1364 * @{ 1365 */ 1366 1367 /** @brief Abstract Broadcast Audio Source Endpoint (BASE) subgroup structure. */ 1368 struct bt_bap_base_subgroup; 1369 /** @brief Abstract Broadcast Audio Source Endpoint (BASE) structure. */ 1370 struct bt_bap_base; 1371 1372 /** Codec ID structure for a Broadcast Audio Source Endpoint (BASE) */ 1373 struct bt_bap_base_codec_id { 1374 /** Codec ID */ 1375 uint8_t id; 1376 /** Codec Company ID */ 1377 uint16_t cid; 1378 /** Codec Company Vendor ID */ 1379 uint16_t vid; 1380 }; 1381 1382 /** BIS structure for each BIS in a Broadcast Audio Source Endpoint (BASE) subgroup */ 1383 struct bt_bap_base_subgroup_bis { 1384 /* Unique index of the BIS */ 1385 uint8_t index; 1386 /** Codec Specific Data length. */ 1387 uint8_t data_len; 1388 /** Codec Specific Data */ 1389 uint8_t *data; 1390 }; 1391 1392 /** 1393 * @brief Generate a pointer to a BASE from periodic advertising data 1394 * 1395 * @param ad The periodic advertising data 1396 * 1397 * @retval NULL if the data does not contain a BASE 1398 * @retval Pointer to a bt_bap_base structure 1399 */ 1400 const struct bt_bap_base *bt_bap_base_get_base_from_ad(const struct bt_data *ad); 1401 1402 /** 1403 * @brief Get the presentation delay value of a BASE 1404 * 1405 * @param base The BASE pointer 1406 * 1407 * @retval -EINVAL if arguments are invalid 1408 * @retval The 24-bit presentation delay value 1409 */ 1410 int bt_bap_base_get_pres_delay(const struct bt_bap_base *base); 1411 1412 /** 1413 * @brief Get the subgroup count of a BASE 1414 * 1415 * @param base The BASE pointer 1416 * 1417 * @retval -EINVAL if arguments are invalid 1418 * @retval The 8-bit subgroup count value 1419 */ 1420 int bt_bap_base_get_subgroup_count(const struct bt_bap_base *base); 1421 1422 /** 1423 * @brief Get all BIS indexes of a BASE 1424 * 1425 * @param[in] base The BASE pointer 1426 * @param[out] bis_indexes 32-bit BIS index bitfield that will be populated 1427 * 1428 * @retval -EINVAL if arguments are invalid 1429 * @retval 0 on success 1430 */ 1431 int bt_bap_base_get_bis_indexes(const struct bt_bap_base *base, uint32_t *bis_indexes); 1432 1433 /** 1434 * @brief Iterate on all subgroups in the BASE 1435 * 1436 * @param base The BASE pointer 1437 * @param func Callback function. Return true to continue iterating, or false to stop. 1438 * @param user_data Userdata supplied to @p func 1439 * 1440 * @retval -EINVAL if arguments are invalid 1441 * @retval -ECANCELED if iterating over the subgroups stopped prematurely by @p func 1442 * @retval 0 if all subgroups were iterated 1443 */ 1444 int bt_bap_base_foreach_subgroup(const struct bt_bap_base *base, 1445 bool (*func)(const struct bt_bap_base_subgroup *subgroup, 1446 void *user_data), 1447 void *user_data); 1448 1449 /** 1450 * @brief Get the codec ID of a subgroup 1451 * 1452 * @param[in] subgroup The subgroup pointer 1453 * @param[out] codec_id Pointer to the struct where the results are placed 1454 * 1455 * @retval -EINVAL if arguments are invalid 1456 * @retval 0 on success 1457 */ 1458 int bt_bap_base_get_subgroup_codec_id(const struct bt_bap_base_subgroup *subgroup, 1459 struct bt_bap_base_codec_id *codec_id); 1460 1461 /** 1462 * @brief Get the codec configuration data of a subgroup 1463 * 1464 * @param[in] subgroup The subgroup pointer 1465 * @param[out] data Pointer that will point to the resulting codec configuration data 1466 * 1467 * @retval -EINVAL if arguments are invalid 1468 * @retval 0 on success 1469 */ 1470 int bt_bap_base_get_subgroup_codec_data(const struct bt_bap_base_subgroup *subgroup, 1471 uint8_t **data); 1472 1473 /** 1474 * @brief Get the codec metadata of a subgroup 1475 * 1476 * @param[in] subgroup The subgroup pointer 1477 * @param[out] meta Pointer that will point to the resulting codec metadata 1478 * 1479 * @retval -EINVAL if arguments are invalid 1480 * @retval 0 on success 1481 */ 1482 int bt_bap_base_get_subgroup_codec_meta(const struct bt_bap_base_subgroup *subgroup, 1483 uint8_t **meta); 1484 1485 /** 1486 * @brief Store subgroup codec data in a @ref bt_audio_codec_cfg 1487 * 1488 * @param[in] subgroup The subgroup pointer 1489 * @param[out] codec_cfg Pointer to the struct where the results are placed 1490 * 1491 * @retval -EINVAL if arguments are invalid 1492 * @retval -ENOMEM if the @p codec_cfg cannot store the @p subgroup codec data 1493 * @retval 0 on success 1494 */ 1495 int bt_bap_base_subgroup_codec_to_codec_cfg(const struct bt_bap_base_subgroup *subgroup, 1496 struct bt_audio_codec_cfg *codec_cfg); 1497 1498 /** 1499 * @brief Get the BIS count of a subgroup 1500 * 1501 * @param subgroup The subgroup pointer 1502 * 1503 * @retval -EINVAL if arguments are invalid 1504 * @retval The 8-bit BIS count value 1505 */ 1506 int bt_bap_base_get_subgroup_bis_count(const struct bt_bap_base_subgroup *subgroup); 1507 1508 /** 1509 * @brief Iterate on all BIS in the subgroup 1510 * 1511 * @param subgroup The subgroup pointer 1512 * @param func Callback function. Return true to continue iterating, or false to stop. 1513 * @param user_data Userdata supplied to @p func 1514 * 1515 * @retval -EINVAL if arguments are invalid 1516 * @retval -ECANCELED if iterating over the subgroups stopped prematurely by @p func 1517 * @retval 0 if all BIS were iterated 1518 */ 1519 int bt_bap_base_subgroup_foreach_bis(const struct bt_bap_base_subgroup *subgroup, 1520 bool (*func)(const struct bt_bap_base_subgroup_bis *bis, 1521 void *user_data), 1522 void *user_data); 1523 1524 /** 1525 * @brief Store BIS codec configuration data in a @ref bt_audio_codec_cfg 1526 * 1527 * This only sets the @ref bt_audio_codec_cfg data and @ref bt_audio_codec_cfg data_len, but is 1528 * useful to use the BIS codec configuration data with the bt_audio_codec_cfg_* functions. 1529 * 1530 * @param[in] bis The BIS pointer 1531 * @param[out] codec_cfg Pointer to the struct where the results are placed 1532 * 1533 * @retval -EINVAL if arguments are invalid 1534 * @retval -ENOMEM if the @p codec_cfg cannot store the @p subgroup codec data 1535 * @retval 0 on success 1536 */ 1537 int bt_bap_base_subgroup_bis_codec_to_codec_cfg(const struct bt_bap_base_subgroup_bis *bis, 1538 struct bt_audio_codec_cfg *codec_cfg); 1539 1540 /** @} */ /* End of group bt_bap_broadcast */ 1541 1542 /** 1543 * @brief BAP Broadcast Source APIs 1544 * @defgroup bt_bap_broadcast_source BAP Broadcast Source APIs 1545 * @ingroup bt_bap_broadcast 1546 * @{ 1547 */ 1548 1549 /** Broadcast Source stream parameters */ 1550 struct bt_bap_broadcast_source_stream_param { 1551 /** Audio stream */ 1552 struct bt_bap_stream *stream; 1553 1554 #if CONFIG_BT_AUDIO_CODEC_CFG_MAX_DATA_SIZE > 0 1555 /** 1556 * @brief The number of elements in the @p data array. 1557 * 1558 * The BIS specific data may be omitted and this set to 0. 1559 */ 1560 size_t data_len; 1561 1562 /** BIS Codec Specific Configuration */ 1563 uint8_t *data; 1564 #endif /* CONFIG_BT_AUDIO_CODEC_CFG_MAX_DATA_SIZE > 0 */ 1565 }; 1566 1567 /** Broadcast Source subgroup parameters*/ 1568 struct bt_bap_broadcast_source_subgroup_param { 1569 /** The number of parameters in @p stream_params */ 1570 size_t params_count; 1571 1572 /** Array of stream parameters */ 1573 struct bt_bap_broadcast_source_stream_param *params; 1574 1575 /** Subgroup Codec configuration. */ 1576 struct bt_audio_codec_cfg *codec_cfg; 1577 }; 1578 1579 /** Broadcast Source create parameters */ 1580 struct bt_bap_broadcast_source_param { 1581 /** The number of parameters in @p subgroup_params */ 1582 size_t params_count; 1583 1584 /** Array of stream parameters */ 1585 struct bt_bap_broadcast_source_subgroup_param *params; 1586 1587 /** Quality of Service configuration. */ 1588 struct bt_audio_codec_qos *qos; 1589 1590 /** 1591 * @brief Broadcast Source packing mode. 1592 * 1593 * @ref BT_ISO_PACKING_SEQUENTIAL or @ref BT_ISO_PACKING_INTERLEAVED. 1594 * 1595 * @note This is a recommendation to the controller, which the controller may ignore. 1596 */ 1597 uint8_t packing; 1598 1599 /** Whether or not to encrypt the streams. */ 1600 bool encryption; 1601 1602 /** 1603 * @brief Broadcast code 1604 * 1605 * If the value is a string or a the value is less than 16 octets, 1606 * the remaining octets shall be 0. 1607 * 1608 * Example: 1609 * The string "Broadcast Code" shall be 1610 * [42 72 6F 61 64 63 61 73 74 20 43 6F 64 65 00 00] 1611 */ 1612 uint8_t broadcast_code[BT_AUDIO_BROADCAST_CODE_SIZE]; 1613 1614 #if defined(CONFIG_BT_ISO_TEST_PARAMS) 1615 /** @brief Immediate Repetition Count 1616 * 1617 * The number of times the scheduled payloads are transmitted in a 1618 * given event. 1619 * 1620 * Value range from @ref BT_ISO_MIN_IRC to @ref BT_ISO_MAX_IRC. 1621 */ 1622 uint8_t irc; 1623 1624 /** @brief Pre-transmission offset 1625 * 1626 * Offset used for pre-transmissions. 1627 * 1628 * Value range from @ref BT_ISO_MIN_PTO to @ref BT_ISO_MAX_PTO. 1629 */ 1630 uint8_t pto; 1631 1632 /** @brief ISO interval 1633 * 1634 * Time between consecutive BIS anchor points. 1635 * 1636 * Value range from @ref BT_ISO_ISO_INTERVAL_MIN to 1637 * @ref BT_ISO_ISO_INTERVAL_MAX. 1638 */ 1639 uint16_t iso_interval; 1640 #endif /* CONFIG_BT_ISO_TEST_PARAMS */ 1641 }; 1642 1643 /** 1644 * @brief Create audio broadcast source. 1645 * 1646 * Create a new audio broadcast source with one or more audio streams. 1647 * 1648 * The broadcast source will be visible for scanners once this has been called, 1649 * and the device will advertise audio announcements. 1650 * 1651 * No audio data can be sent until bt_bap_broadcast_source_start() has been called and no audio 1652 * information (BIGInfo) will be visible to scanners (see @ref bt_le_per_adv_sync_cb). 1653 * 1654 * @param[in] param Pointer to parameters used to create the broadcast source. 1655 * @param[out] source Pointer to the broadcast source created 1656 * 1657 * @return Zero on success or (negative) error code otherwise. 1658 */ 1659 int bt_bap_broadcast_source_create(struct bt_bap_broadcast_source_param *param, 1660 struct bt_bap_broadcast_source **source); 1661 1662 /** 1663 * @brief Reconfigure audio broadcast source. 1664 * 1665 * Reconfigure an audio broadcast source with a new codec and codec quality of 1666 * service parameters. This can only be done when the source is stopped. 1667 * 1668 * Since this may modify the Broadcast Audio Source Endpoint (BASE), 1669 * bt_bap_broadcast_source_get_base() should be called after this to get the new BASE information. 1670 * 1671 * If the @p param.params_count is smaller than the number of subgroups that have been created in 1672 * the Broadcast Source, only the first @p param.params_count subgroups are updated. If a stream 1673 * exist in a subgroup not part of @p param, then that stream is left as is (i.e. it is not removed; 1674 * the only way to remove a stream from a Broadcast Source is to recreate the Broadcast Source). 1675 * 1676 * @param source Pointer to the broadcast source 1677 * @param param Pointer to parameters used to reconfigure the broadcast source. 1678 * 1679 * @return Zero on success or (negative) error code otherwise. 1680 */ 1681 int bt_bap_broadcast_source_reconfig(struct bt_bap_broadcast_source *source, 1682 struct bt_bap_broadcast_source_param *param); 1683 1684 /** 1685 * @brief Modify the metadata of an audio broadcast source. 1686 * 1687 * Modify the metadata an audio broadcast source. This can only be done when the source is started. 1688 * To update the metadata in the stopped state, use bt_bap_broadcast_source_reconfig(). 1689 * 1690 * @param source Pointer to the broadcast source. 1691 * @param meta Metadata. 1692 * @param meta_len Length of metadata. 1693 * 1694 * @return Zero on success or (negative) error code otherwise. 1695 */ 1696 int bt_bap_broadcast_source_update_metadata(struct bt_bap_broadcast_source *source, 1697 const uint8_t meta[], size_t meta_len); 1698 1699 /** 1700 * @brief Start audio broadcast source. 1701 * 1702 * Start an audio broadcast source with one or more audio streams. 1703 * The broadcast source will start advertising BIGInfo, and audio data can be streamed. 1704 * 1705 * @param source Pointer to the broadcast source 1706 * @param adv Pointer to an extended advertising set with periodic advertising configured. 1707 * 1708 * @return Zero on success or (negative) error code otherwise. 1709 */ 1710 int bt_bap_broadcast_source_start(struct bt_bap_broadcast_source *source, 1711 struct bt_le_ext_adv *adv); 1712 1713 /** 1714 * @brief Stop audio broadcast source. 1715 * 1716 * Stop an audio broadcast source. 1717 * The broadcast source will stop advertising BIGInfo, and audio data can no longer be streamed. 1718 * 1719 * @param source Pointer to the broadcast source 1720 * 1721 * @return Zero on success or (negative) error code otherwise. 1722 */ 1723 int bt_bap_broadcast_source_stop(struct bt_bap_broadcast_source *source); 1724 1725 /** 1726 * @brief Delete audio broadcast source. 1727 * 1728 * Delete an audio broadcast source. 1729 * The broadcast source will stop advertising entirely, and the source can no longer be used. 1730 * 1731 * @param source Pointer to the broadcast source 1732 * 1733 * @return Zero on success or (negative) error code otherwise. 1734 */ 1735 int bt_bap_broadcast_source_delete(struct bt_bap_broadcast_source *source); 1736 1737 /** 1738 * @brief Get the broadcast ID of a broadcast source 1739 * 1740 * This will return the 3-octet broadcast ID that should be advertised in the 1741 * extended advertising data with @ref BT_UUID_BROADCAST_AUDIO_VAL as @ref BT_DATA_SVC_DATA16. 1742 * 1743 * See table 3.14 in the Basic Audio Profile v1.0.1 for the structure. 1744 * 1745 * @param[in] source Pointer to the broadcast source. 1746 * @param[out] broadcast_id Pointer to the 3-octet broadcast ID. 1747 * 1748 * @return Zero on success or (negative) error code otherwise. 1749 */ 1750 int bt_bap_broadcast_source_get_id(struct bt_bap_broadcast_source *source, 1751 uint32_t *const broadcast_id); 1752 1753 /** 1754 * @brief Get the Broadcast Audio Stream Endpoint of a broadcast source 1755 * 1756 * This will encode the BASE of a broadcast source into a buffer, that can be used for 1757 * advertisement. The encoded BASE will thus be encoded as little-endian. The BASE shall be put into 1758 * the periodic advertising data (see bt_le_per_adv_set_data()). 1759 * 1760 * See table 3.15 in the Basic Audio Profile v1.0.1 for the structure. 1761 * 1762 * @param source Pointer to the broadcast source. 1763 * @param base_buf Pointer to a buffer where the BASE will be inserted. 1764 * 1765 * @return Zero on success or (negative) error code otherwise. 1766 */ 1767 int bt_bap_broadcast_source_get_base(struct bt_bap_broadcast_source *source, 1768 struct net_buf_simple *base_buf); 1769 1770 /** @} */ /* End of bt_bap_broadcast_source */ 1771 1772 /** 1773 * @brief BAP Broadcast Sink APIs 1774 * @defgroup bt_bap_broadcast_sink BAP Broadcast Sink APIs 1775 * @ingroup bt_bap_broadcast 1776 * @{ 1777 */ 1778 1779 /** Broadcast Audio Sink callback structure */ 1780 struct bt_bap_broadcast_sink_cb { 1781 /** @brief Broadcast Audio Source Endpoint (BASE) received 1782 * 1783 * Callback for when we receive a BASE from a broadcaster after 1784 * syncing to the broadcaster's periodic advertising. 1785 * 1786 * @param sink Pointer to the sink structure. 1787 * @param base Broadcast Audio Source Endpoint (BASE). 1788 * @param base_size Size of the @p base 1789 */ 1790 void (*base_recv)(struct bt_bap_broadcast_sink *sink, const struct bt_bap_base *base, 1791 size_t base_size); 1792 1793 /** @brief Broadcast sink is syncable 1794 * 1795 * Called whenever a broadcast sink is not synchronized to audio, but the audio is 1796 * synchronizable. This is inferred when a BIGInfo report is received. 1797 * 1798 * Once this callback has been called, it is possible to call 1799 * bt_bap_broadcast_sink_sync() to synchronize to the audio stream(s). 1800 * 1801 * @param sink Pointer to the sink structure. 1802 * @param encrypted Whether or not the broadcast is encrypted 1803 */ 1804 void (*syncable)(struct bt_bap_broadcast_sink *sink, bool encrypted); 1805 1806 /* Internally used list node */ 1807 sys_snode_t _node; 1808 }; 1809 1810 /** @brief Register Broadcast sink callbacks 1811 * * 1812 * @param cb Broadcast sink callback structure. 1813 */ 1814 int bt_bap_broadcast_sink_register_cb(struct bt_bap_broadcast_sink_cb *cb); 1815 1816 /** @brief Create a Broadcast Sink from a periodic advertising sync 1817 * 1818 * This should only be done after verifying that the periodic advertising sync 1819 * is from a Broadcast Source. 1820 * 1821 * The created Broadcast Sink will need to be supplied to 1822 * bt_bap_broadcast_sink_sync() in order to synchronize to the broadcast 1823 * audio. 1824 * 1825 * bt_bap_broadcast_sink_cb.pa_synced() will be called with the Broadcast 1826 * Sink object created if this is successful. 1827 * 1828 * @param pa_sync Pointer to the periodic advertising sync object. 1829 * @param broadcast_id 24-bit broadcast ID. 1830 * @param[out] sink Pointer to the Broadcast Sink created. 1831 * 1832 * @return 0 in case of success or errno value in case of error. 1833 */ 1834 int bt_bap_broadcast_sink_create(struct bt_le_per_adv_sync *pa_sync, uint32_t broadcast_id, 1835 struct bt_bap_broadcast_sink **sink); 1836 1837 /** @brief Sync to a broadcaster's audio 1838 * 1839 * @param sink Pointer to the sink object from the base_recv callback. 1840 * @param indexes_bitfield Bitfield of the BIS index to sync to. To sync to e.g. BIS index 1 and 1841 * 2, this should have the value of BIT(1) | BIT(2). 1842 * @param streams Stream object pointers to be used for the receiver. If multiple BIS 1843 * indexes shall be synchronized, multiple streams shall be provided. 1844 * @param broadcast_code The 16-octet broadcast code. Shall be supplied if the broadcast is 1845 * encrypted (see @ref bt_bap_broadcast_sink_cb.syncable). 1846 * If the value is a string or a the value is less 1847 * than 16 octets, the remaining octets shall be 0. 1848 * 1849 * Example: 1850 * The string "Broadcast Code" shall be 1851 * [42 72 6F 61 64 63 61 73 74 20 43 6F 64 65 00 00] 1852 * 1853 * @return 0 in case of success or negative value in case of error. 1854 */ 1855 int bt_bap_broadcast_sink_sync(struct bt_bap_broadcast_sink *sink, uint32_t indexes_bitfield, 1856 struct bt_bap_stream *streams[], const uint8_t broadcast_code[16]); 1857 1858 /** @brief Stop audio broadcast sink. 1859 * 1860 * Stop an audio broadcast sink. 1861 * The broadcast sink will stop receiving BIGInfo, and audio data can no longer be streamed. 1862 * 1863 * @param sink Pointer to the broadcast sink 1864 * 1865 * @return Zero on success or (negative) error code otherwise. 1866 */ 1867 int bt_bap_broadcast_sink_stop(struct bt_bap_broadcast_sink *sink); 1868 1869 /** @brief Release a broadcast sink 1870 * 1871 * Once a broadcast sink has been allocated after the pa_synced callback, it can be deleted using 1872 * this function. If the sink has synchronized to any broadcast audio streams, these must first be 1873 * stopped using bt_bap_stream_stop. 1874 * 1875 * @param sink Pointer to the sink object to delete. 1876 * 1877 * @return 0 in case of success or negative value in case of error. 1878 */ 1879 int bt_bap_broadcast_sink_delete(struct bt_bap_broadcast_sink *sink); 1880 1881 /** @} */ /* End of group bt_bap_broadcast_sink */ 1882 1883 /** 1884 * @brief Register the callbacks for the Basic Audio Profile Scan Delegator 1885 * 1886 * @param cb Pointer to the callback struct 1887 */ 1888 void bt_bap_scan_delegator_register_cb(struct bt_bap_scan_delegator_cb *cb); 1889 1890 /** 1891 * @brief Set the periodic advertising sync state to syncing 1892 * 1893 * Set the periodic advertising sync state for a receive state to syncing, 1894 * notifying Broadcast Assistants. 1895 * 1896 * @param src_id The source id used to identify the receive state. 1897 * @param pa_state The Periodic Advertising sync state to set. 1898 * BT_BAP_PA_STATE_NOT_SYNCED and BT_BAP_PA_STATE_SYNCED is 1899 * not necessary to provide, as they are handled internally. 1900 * 1901 * @return int Error value. 0 on success, errno on fail. 1902 */ 1903 int bt_bap_scan_delegator_set_pa_state(uint8_t src_id, 1904 enum bt_bap_pa_state pa_state); 1905 1906 /** 1907 * @brief Set the sync state of a receive state in the server 1908 * 1909 * @param src_id The source id used to identify the receive state. 1910 * @param bis_synced Array of bitfields to set the BIS sync state for each 1911 * subgroup. 1912 * @return int Error value. 0 on success, ERRNO on fail. 1913 */ 1914 int bt_bap_scan_delegator_set_bis_sync_state( 1915 uint8_t src_id, 1916 uint32_t bis_synced[CONFIG_BT_BAP_BASS_MAX_SUBGROUPS]); 1917 1918 struct bt_bap_scan_delegator_add_src_param { 1919 /** The periodic adverting sync */ 1920 struct bt_le_per_adv_sync *pa_sync; 1921 1922 /** The broadcast isochronous group encryption state */ 1923 enum bt_bap_big_enc_state encrypt_state; 1924 1925 /** The 24-bit broadcast ID */ 1926 uint32_t broadcast_id; 1927 1928 /** Number of subgroups */ 1929 uint8_t num_subgroups; 1930 1931 /** Subgroup specific information */ 1932 struct bt_bap_bass_subgroup subgroups[CONFIG_BT_BAP_BASS_MAX_SUBGROUPS]; 1933 }; 1934 1935 /** 1936 * @brief Add a receive state source locally 1937 * 1938 * This will notify any connected clients about the new source. This allows them 1939 * to modify and even remove it. 1940 * 1941 * If @kconfig{CONFIG_BT_BAP_BROADCAST_SINK} is enabled, any Broadcast Sink 1942 * sources are autonomously added. 1943 * 1944 * @param param The parameters for adding the new source 1945 * 1946 * @return int errno on failure, or source ID on success. 1947 */ 1948 int bt_bap_scan_delegator_add_src(const struct bt_bap_scan_delegator_add_src_param *param); 1949 1950 struct bt_bap_scan_delegator_mod_src_param { 1951 /** The periodic adverting sync */ 1952 uint8_t src_id; 1953 1954 /** The broadcast isochronous group encryption state */ 1955 enum bt_bap_big_enc_state encrypt_state; 1956 1957 /** The 24-bit broadcast ID */ 1958 uint32_t broadcast_id; 1959 1960 /** Number of subgroups */ 1961 uint8_t num_subgroups; 1962 1963 /** 1964 * @brief Subgroup specific information 1965 * 1966 * If a subgroup's metadata_len is set to 0, the existing metadata 1967 * for the subgroup will remain unchanged 1968 */ 1969 struct bt_bap_bass_subgroup subgroups[CONFIG_BT_BAP_BASS_MAX_SUBGROUPS]; 1970 }; 1971 1972 /** 1973 * @brief Add a receive state source locally 1974 * 1975 * This will notify any connected clients about the new source. This allows them 1976 * to modify and even remove it. 1977 * 1978 * If @kconfig{CONFIG_BT_BAP_BROADCAST_SINK} is enabled, any Broadcast Sink 1979 * sources are autonomously modifed. 1980 * 1981 * @param param The parameters for adding the new source 1982 * 1983 * @return int errno on failure, or source ID on success. 1984 */ 1985 int bt_bap_scan_delegator_mod_src(const struct bt_bap_scan_delegator_mod_src_param *param); 1986 1987 /** 1988 * @brief Remove a receive state source 1989 * 1990 * This will remove the receive state. If the receive state periodic advertising 1991 * is synced, bt_bap_scan_delegator_cb.pa_sync_term_req() will be called. 1992 * 1993 * If @kconfig{CONFIG_BT_BAP_BROADCAST_SINK} is enabled, any Broadcast Sink 1994 * sources are autonomously removed. 1995 * 1996 * @param src_id The source ID to remove 1997 * 1998 * @return int Error value. 0 on success, errno on fail. 1999 */ 2000 int bt_bap_scan_delegator_rem_src(uint8_t src_id); 2001 2002 /** Callback function for Scan Delegator receive state search functions 2003 * 2004 * @param recv_state The receive state. 2005 * @param user_data User data. 2006 * 2007 * @retval true to stop iterating. If this is used in the context of 2008 * bt_bap_scan_delegator_find_state(), the recv_state will be returned by 2009 * bt_bap_scan_delegator_find_state() 2010 * @retval false to continue iterating 2011 */ 2012 typedef bool (*bt_bap_scan_delegator_state_func_t)( 2013 const struct bt_bap_scan_delegator_recv_state *recv_state, void *user_data); 2014 2015 /** @brief Iterate through all existing receive states 2016 * 2017 * @param func The callback function 2018 * @param user_data User specified data that sent to the callback function 2019 */ 2020 void bt_bap_scan_delegator_foreach_state(bt_bap_scan_delegator_state_func_t func, 2021 void *user_data); 2022 2023 /** @brief Find and return a receive state based on a compare function 2024 * 2025 * @param func The compare callback function 2026 * @param user_data User specified data that sent to the callback function 2027 * 2028 * @return The first receive state where the @p func returned true, or NULL 2029 */ 2030 const struct bt_bap_scan_delegator_recv_state *bt_bap_scan_delegator_find_state( 2031 bt_bap_scan_delegator_state_func_t func, void *user_data); 2032 2033 /******************************** CLIENT API ********************************/ 2034 2035 /** 2036 * @brief Callback function for writes. 2037 * 2038 * @param conn The connection to the peer device. 2039 * @param err Error value. 0 on success, GATT error on fail. 2040 */ 2041 typedef void (*bt_bap_broadcast_assistant_write_cb)(struct bt_conn *conn, 2042 int err); 2043 2044 struct bt_bap_broadcast_assistant_cb { 2045 /** 2046 * @brief Callback function for bt_bap_broadcast_assistant_discover. 2047 * 2048 * @param conn The connection that was used to discover 2049 * Broadcast Audio Scan Service. 2050 * @param err Error value. 0 on success, 2051 * GATT error or ERRNO on fail. 2052 * @param recv_state_count Number of receive states on the server. 2053 */ 2054 void (*discover)(struct bt_conn *conn, int err, 2055 uint8_t recv_state_count); 2056 2057 /** 2058 * @brief Callback function for Broadcast Audio Scan Service client scan results 2059 * 2060 * Called when the scanner finds an advertiser that advertises the 2061 * BT_UUID_BROADCAST_AUDIO UUID. 2062 * 2063 * @param info Advertiser information. 2064 * @param broadcast_id 24-bit broadcast ID. 2065 */ 2066 void (*scan)(const struct bt_le_scan_recv_info *info, 2067 uint32_t broadcast_id); 2068 2069 /** 2070 * @brief Callback function for when a receive state is read or updated 2071 * 2072 * Called whenever a receive state is read or updated. 2073 * 2074 * @param conn The connection to the Broadcast Audio Scan Service server. 2075 * @param err Error value. 0 on success, GATT error on fail. 2076 * @param state The receive state or NULL if the receive state is empty. 2077 */ 2078 void (*recv_state)(struct bt_conn *conn, int err, 2079 const struct bt_bap_scan_delegator_recv_state *state); 2080 2081 /** 2082 * @brief Callback function for when a receive state is removed. 2083 * 2084 * @param conn The connection to the Broadcast Audio Scan Service server. 2085 * @param err Error value. 0 on success, GATT error on fail. 2086 * @param src_id The receive state. 2087 */ 2088 void (*recv_state_removed)(struct bt_conn *conn, int err, 2089 uint8_t src_id); 2090 2091 /** 2092 * @brief Callback function for bt_bap_broadcast_assistant_scan_start(). 2093 * 2094 * @param conn The connection to the peer device. 2095 * @param err Error value. 0 on success, GATT error on fail. 2096 */ 2097 void (*scan_start)(struct bt_conn *conn, int err); 2098 2099 /** 2100 * @brief Callback function for bt_bap_broadcast_assistant_scan_stop(). 2101 * 2102 * @param conn The connection to the peer device. 2103 * @param err Error value. 0 on success, GATT error on fail. 2104 */ 2105 void (*scan_stop)(struct bt_conn *conn, int err); 2106 2107 /** 2108 * @brief Callback function for bt_bap_broadcast_assistant_add_src(). 2109 * 2110 * @param conn The connection to the peer device. 2111 * @param err Error value. 0 on success, GATT error on fail. 2112 */ 2113 void (*add_src)(struct bt_conn *conn, int err); 2114 2115 /** 2116 * @brief Callback function for bt_bap_broadcast_assistant_mod_src(). 2117 * 2118 * @param conn The connection to the peer device. 2119 * @param err Error value. 0 on success, GATT error on fail. 2120 */ 2121 void (*mod_src)(struct bt_conn *conn, int err); 2122 2123 /** 2124 * @brief Callback function for bt_bap_broadcast_assistant_broadcast_code(). 2125 * 2126 * @param conn The connection to the peer device. 2127 * @param err Error value. 0 on success, GATT error on fail. 2128 */ 2129 void (*broadcast_code)(struct bt_conn *conn, int err); 2130 2131 /** 2132 * @brief Callback function for bt_bap_broadcast_assistant_rem_src(). 2133 * 2134 * @param conn The connection to the peer device. 2135 * @param err Error value. 0 on success, GATT error on fail. 2136 */ 2137 void (*rem_src)(struct bt_conn *conn, int err); 2138 }; 2139 2140 /** 2141 * @brief Discover Broadcast Audio Scan Service on the server. 2142 * 2143 * Warning: Only one connection can be active at any time; discovering for a 2144 * new connection, will delete all previous data. 2145 * 2146 * @param conn The connection 2147 * @return int Error value. 0 on success, GATT error or ERRNO on fail. 2148 */ 2149 int bt_bap_broadcast_assistant_discover(struct bt_conn *conn); 2150 2151 /** 2152 * @brief Scan start for BISes for a remote server. 2153 * 2154 * This will let the Broadcast Audio Scan Service server know that this device 2155 * is actively scanning for broadcast sources. 2156 * The function can optionally also start scanning, if the caller does not want 2157 * to start scanning itself. 2158 * 2159 * Scan results, if @p start_scan is true, is sent to the 2160 * bt_bap_broadcast_assistant_scan_cb callback. 2161 * 2162 * @param conn Connection to the Broadcast Audio Scan Service server. 2163 * Used to let the server know that we are scanning. 2164 * @param start_scan Start scanning if true. If false, the application should 2165 * enable scan itself. 2166 * @return int Error value. 0 on success, GATT error or ERRNO on fail. 2167 */ 2168 int bt_bap_broadcast_assistant_scan_start(struct bt_conn *conn, 2169 bool start_scan); 2170 2171 /** 2172 * @brief Stop remote scanning for BISes for a server. 2173 * 2174 * @param conn Connection to the server. 2175 * @return int Error value. 0 on success, GATT error or ERRNO on fail. 2176 */ 2177 int bt_bap_broadcast_assistant_scan_stop(struct bt_conn *conn); 2178 2179 /** 2180 * @brief Registers the callbacks used by Broadcast Audio Scan Service client. 2181 */ 2182 void bt_bap_broadcast_assistant_register_cb(struct bt_bap_broadcast_assistant_cb *cb); 2183 2184 /** Parameters for adding a source to a Broadcast Audio Scan Service server */ 2185 struct bt_bap_broadcast_assistant_add_src_param { 2186 /** Address of the advertiser. */ 2187 bt_addr_le_t addr; 2188 2189 /** SID of the advertising set. */ 2190 uint8_t adv_sid; 2191 2192 /** Whether to sync to periodic advertisements. */ 2193 bool pa_sync; 2194 2195 /** 24-bit broadcast ID */ 2196 uint32_t broadcast_id; 2197 2198 /** 2199 * @brief Periodic advertising interval in milliseconds. 2200 * 2201 * BT_BAP_PA_INTERVAL_UNKNOWN if unknown. 2202 */ 2203 uint16_t pa_interval; 2204 2205 /** Number of subgroups */ 2206 uint8_t num_subgroups; 2207 2208 /** Pointer to array of subgroups */ 2209 struct bt_bap_bass_subgroup *subgroups; 2210 }; 2211 2212 /** 2213 * @brief Add a source on the server. 2214 * 2215 * @param conn Connection to the server. 2216 * @param param Parameter struct. 2217 * 2218 * @return Error value. 0 on success, GATT error or ERRNO on fail. 2219 */ 2220 int bt_bap_broadcast_assistant_add_src( 2221 struct bt_conn *conn, const struct bt_bap_broadcast_assistant_add_src_param *param); 2222 2223 /** Parameters for modifying a source */ 2224 struct bt_bap_broadcast_assistant_mod_src_param { 2225 /** Source ID of the receive state. */ 2226 uint8_t src_id; 2227 2228 /** Whether to sync to periodic advertisements. */ 2229 bool pa_sync; 2230 2231 /** 2232 * @brief Periodic advertising interval. 2233 * 2234 * BT_BAP_PA_INTERVAL_UNKNOWN if unknown. 2235 */ 2236 uint16_t pa_interval; 2237 2238 /** Number of subgroups */ 2239 uint8_t num_subgroups; 2240 2241 /** Pointer to array of subgroups */ 2242 struct bt_bap_bass_subgroup *subgroups; 2243 }; 2244 2245 /** @brief Modify a source on the server. 2246 * 2247 * @param conn Connection to the server. 2248 * @param param Parameter struct. 2249 * 2250 * @return Error value. 0 on success, GATT error or ERRNO on fail. 2251 */ 2252 int bt_bap_broadcast_assistant_mod_src( 2253 struct bt_conn *conn, const struct bt_bap_broadcast_assistant_mod_src_param *param); 2254 2255 /** @brief Set a broadcast code to the specified receive state. 2256 * 2257 * @param conn Connection to the server. 2258 * @param src_id Source ID of the receive state. 2259 * @param broadcast_code The broadcast code. 2260 * 2261 * @return Error value. 0 on success, GATT error or ERRNO on fail. 2262 */ 2263 int bt_bap_broadcast_assistant_set_broadcast_code( 2264 struct bt_conn *conn, uint8_t src_id, 2265 const uint8_t broadcast_code[BT_AUDIO_BROADCAST_CODE_SIZE]); 2266 2267 /** @brief Remove a source from the server. 2268 * 2269 * @param conn Connection to the server. 2270 * @param src_id Source ID of the receive state. 2271 * 2272 * @return Error value. 0 on success, GATT error or ERRNO on fail. 2273 */ 2274 int bt_bap_broadcast_assistant_rem_src(struct bt_conn *conn, uint8_t src_id); 2275 2276 /** @brief Read the specified receive state from the server. 2277 * 2278 * @param conn Connection to the server. 2279 * @param idx The index of the receive start (0 up to the value from 2280 * bt_bap_broadcast_assistant_discover_cb) 2281 * 2282 * @return Error value. 0 on success, GATT error or ERRNO on fail. 2283 */ 2284 int bt_bap_broadcast_assistant_read_recv_state(struct bt_conn *conn, 2285 uint8_t idx); 2286 2287 /** @} */ /* end of bt_bap */ 2288 2289 #ifdef __cplusplus 2290 } 2291 #endif 2292 2293 #endif /* ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_BAP_ */ 2294