Skip to content

Commit f970b06

Browse files
fredrikdanebjeraescolar
authored andcommitted
Bluetooth: audio: Add possibility to use static broadcast id
Removed the generation of broadcast id inside the stack. It is now up to the application to generate this by itself. The CAP sample has been modified to allow either a static broadcast, or a random one. All of this is handled in the application. Signed-off-by: Fredrik Danebjer <[email protected]>
1 parent 7e72d46 commit f970b06

File tree

25 files changed

+112
-232
lines changed

25 files changed

+112
-232
lines changed

doc/releases/migration-guide-4.0.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,13 @@ Bluetooth Audio
388388
do a search-and-replace for ``bt_audio_codec_qos`` to ``bt_bap_qos_cfg`` and
389389
``BT_AUDIO_CODEC_QOS`` to ``BT_BAP_QOS_CFG``. (:github:`76633`)
390390

391+
* The generation of broadcast ID inside of zephyr stack has been removed, it is now up the
392+
application to generate a broadcast ID. This means that the application can now fully decide
393+
whether to use a static or random broadcast ID. Reusing and statically defining a broadcast ID was
394+
added to the Basic Audio Profile in version 1.0.2, which is the basis for this change. All
395+
instances of :c:func:`bt_cap_initiator_broadcast_get_id` and
396+
:c:func:`bt_bap_broadcast_source_get_id` has been removed(:github:`80228`)
397+
391398
Bluetooth Classic
392399
=================
393400

include/zephyr/bluetooth/audio/bap.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,22 +2184,6 @@ int bt_bap_broadcast_source_stop(struct bt_bap_broadcast_source *source);
21842184
*/
21852185
int bt_bap_broadcast_source_delete(struct bt_bap_broadcast_source *source);
21862186

2187-
/**
2188-
* @brief Get the broadcast ID of a broadcast source
2189-
*
2190-
* This will return the 3-octet broadcast ID that should be advertised in the
2191-
* extended advertising data with @ref BT_UUID_BROADCAST_AUDIO_VAL as @ref BT_DATA_SVC_DATA16.
2192-
*
2193-
* See table 3.14 in the Basic Audio Profile v1.0.1 for the structure.
2194-
*
2195-
* @param[in] source Pointer to the broadcast source.
2196-
* @param[out] broadcast_id Pointer to the 3-octet broadcast ID.
2197-
*
2198-
* @return Zero on success or (negative) error code otherwise.
2199-
*/
2200-
int bt_bap_broadcast_source_get_id(struct bt_bap_broadcast_source *source,
2201-
uint32_t *const broadcast_id);
2202-
22032187
/**
22042188
* @brief Get the Broadcast Audio Stream Endpoint of a broadcast source
22052189
*

include/zephyr/bluetooth/audio/cap.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -603,23 +603,6 @@ int bt_cap_initiator_broadcast_audio_stop(struct bt_cap_broadcast_source *broadc
603603
*/
604604
int bt_cap_initiator_broadcast_audio_delete(struct bt_cap_broadcast_source *broadcast_source);
605605

606-
/**
607-
* @brief Get the broadcast ID of a Common Audio Profile broadcast source
608-
*
609-
* This will return the 3-octet broadcast ID that should be advertised in the
610-
* extended advertising data with @ref BT_UUID_BROADCAST_AUDIO_VAL as
611-
* @ref BT_DATA_SVC_DATA16.
612-
*
613-
* See table 3.14 in the Basic Audio Profile v1.0.1 for the structure.
614-
*
615-
* @param[in] broadcast_source Pointer to the broadcast source.
616-
* @param[out] broadcast_id Pointer to the 3-octet broadcast ID.
617-
*
618-
* @return int 0 if on success, errno on error.
619-
*/
620-
int bt_cap_initiator_broadcast_get_id(const struct bt_cap_broadcast_source *broadcast_source,
621-
uint32_t *const broadcast_id);
622-
623606
/**
624607
* @brief Get the Broadcast Audio Stream Endpoint of a Common Audio Profile broadcast source
625608
*

samples/bluetooth/bap_broadcast_source/Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,18 @@ config BROADCAST_CODE
4545
Setting a non-empty string for this option will encrypt the broadcast using this
4646
string as the broadcast code. The length of the string shall be between 1 and 16 octets.
4747

48+
config STATIC_BROADCAST_ID
49+
bool "Use static broadcast ID"
50+
default y
51+
help
52+
Enabling this option will make the application use static broadcast ID, as opposed to a
53+
randomly generated one.
54+
55+
config BROADCAST_ID
56+
hex "The static broadcast ID to use"
57+
range 0x000000 0xFFFFFF
58+
depends on STATIC_BROADCAST_ID
59+
help
60+
This is the 3-octet broadcast ID advertised if static broadcast IDs are enabled.
61+
4862
source "Kconfig.zephyr"

samples/bluetooth/bap_broadcast_source/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ CONFIG_BT_ISO_TX_BUF_COUNT=6
1414
CONFIG_BT_ISO_TX_MTU=60
1515

1616
CONFIG_BT_DEVICE_NAME="Broadcast Audio Source"
17+
CONFIG_BROADCAST_ID=0x123456

samples/bluetooth/bap_broadcast_source/src/main.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,11 +518,15 @@ int main(void)
518518
return 0;
519519
}
520520

521-
err = bt_bap_broadcast_source_get_id(broadcast_source, &broadcast_id);
522-
if (err != 0) {
523-
printk("Unable to get broadcast ID: %d\n", err);
524-
return 0;
521+
#if defined(CONFIG_STATIC_BROADCAST_ID)
522+
broadcast_id = CONFIG_BROADCAST_ID;
523+
#else
524+
err = bt_rand(&broadcast_id, BT_AUDIO_BROADCAST_ID_SIZE);
525+
if (err) {
526+
printk("Unable to generate broadcast ID: %d\n", err);
527+
return err;
525528
}
529+
#endif /* CONFIG_STATIC_BROADCAST_ID */
526530

527531
/* Setup extended advertising data */
528532
net_buf_simple_add_le16(&ad_buf, BT_UUID_BROADCAST_AUDIO_VAL);

samples/bluetooth/cap_initiator/Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,18 @@ config SAMPLE_BROADCAST
2626
help
2727
If set to true, the sample will start advertising syncable audio streams
2828

29+
config STATIC_BROADCAST_ID
30+
bool "Use static broadcast ID"
31+
default y
32+
help
33+
Enabling this option will make the application use static broadcast ID, as opposed to a
34+
randomly generated one.
35+
36+
config BROADCAST_ID
37+
hex "The static broadcast ID to use"
38+
range 0x000000 0xFFFFFF
39+
depends on STATIC_BROADCAST_ID
40+
help
41+
This is the 3-octet broadcast ID advertised if static broadcast IDs are enabled.
42+
2943
source "Kconfig.zephyr"

samples/bluetooth/cap_initiator/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ CONFIG_BT_BAP_BROADCAST_SOURCE=y
2323
# Broadcast sources values if enabled by CONFIG_SAMPLE_BROADCAST
2424
CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT=2
2525
CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT=1
26+
CONFIG_BROADCAST_ID=0x123456

samples/bluetooth/cap_initiator/src/cap_initiator_broadcast.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,15 @@ static int setup_extended_adv_data(struct bt_cap_broadcast_source *source,
133133
uint32_t broadcast_id;
134134
int err;
135135

136-
err = bt_cap_initiator_broadcast_get_id(source, &broadcast_id);
137-
if (err != 0) {
138-
LOG_ERR("Unable to get broadcast ID: %d", err);
136+
#if defined(CONFIG_STATIC_BROADCAST_ID)
137+
broadcast_id = CONFIG_BROADCAST_ID;
138+
#else
139+
err = bt_rand(&broadcast_id, BT_AUDIO_BROADCAST_ID_SIZE);
140+
if (err) {
141+
printk("Unable to generate broadcast ID: %d\n", err);
139142
return err;
140143
}
144+
#endif /* CONFIG_STATIC_BROADCAST_ID */
141145

142146
/* Setup extended advertising data */
143147
net_buf_simple_add_le16(&ad_buf, BT_UUID_BROADCAST_AUDIO_VAL);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright (c) 2024 Demant A/S
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
mainmenu "Bluetooth: PBP Broadcast Audio Source"
5+
6+
config STATIC_BROADCAST_ID
7+
bool "Use static broadcast ID"
8+
default y
9+
help
10+
Enabling this option will make the application use static broadcast ID, as opposed to a
11+
randomly generated one.
12+
13+
config BROADCAST_ID
14+
hex "The static broadcast ID to use"
15+
range 0x000000 0xFFFFFF
16+
depends on STATIC_BROADCAST_ID
17+
help
18+
This is the 3-octet broadcast ID advertised if static broadcast IDs are enabled.
19+
20+
source "Kconfig.zephyr"

0 commit comments

Comments
 (0)