Skip to content

Commit 4844dab

Browse files
Thalleyfabiobaltieri
authored andcommitted
Samples: Bluetooth: Add encrypted broadcast audio source
Add support for supplying a broadcast code to the broadcast audio sample, which will, if non-empty, encrypt the broadcast. Signed-off-by: Emil Gydesen <[email protected]>
1 parent f7e64c8 commit 4844dab

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

samples/bluetooth/broadcast_audio_source/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,11 @@ config USE_USB_AUDIO_INPUT
3838
select USB_DEVICE_AUDIO
3939
select RING_BUFFER
4040

41+
config BROADCAST_CODE
42+
string "The broadcast code (if any) to use for encrypted broadcast"
43+
default ""
44+
help
45+
Setting a non-empty string for this option will encrypt the broadcast using this
46+
string as the broadcast code. The length of the string shall be between 1 and 16 octets.
47+
4148
source "Kconfig.zephyr"

samples/bluetooth/broadcast_audio_source/src/main.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include <zephyr/bluetooth/audio/bap.h>
1010
#include <zephyr/bluetooth/audio/bap_lc3_preset.h>
1111

12+
BUILD_ASSERT(strlen(CONFIG_BROADCAST_CODE) <= BT_AUDIO_BROADCAST_CODE_SIZE,
13+
"Invalid broadcast code");
14+
1215
/* Zephyr Controller works best while Extended Advertising interval to be a multiple
1316
* of the ISO Interval minus 10 ms (max. advertising random delay). This is
1417
* required to place the AUX_ADV_IND PDUs in a non-overlapping interval with the
@@ -384,7 +387,7 @@ static int setup_broadcast_source(struct bt_bap_broadcast_source **source)
384387
stream_params[CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT];
385388
struct bt_bap_broadcast_source_subgroup_param
386389
subgroup_param[CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT];
387-
struct bt_bap_broadcast_source_param create_param;
390+
struct bt_bap_broadcast_source_param create_param = {0};
388391
const size_t streams_per_subgroup = ARRAY_SIZE(stream_params) / ARRAY_SIZE(subgroup_param);
389392
uint8_t left[] = {BT_AUDIO_CODEC_DATA(BT_AUDIO_CODEC_CFG_CHAN_ALLOC,
390393
BT_BYTES_LIST_LE32(BT_AUDIO_LOCATION_FRONT_LEFT))};
@@ -408,9 +411,14 @@ static int setup_broadcast_source(struct bt_bap_broadcast_source **source)
408411
create_param.params_count = ARRAY_SIZE(subgroup_param);
409412
create_param.params = subgroup_param;
410413
create_param.qos = &preset_active.qos;
411-
create_param.encryption = false;
414+
create_param.encryption = strlen(CONFIG_BROADCAST_CODE) > 0;
412415
create_param.packing = BT_ISO_PACKING_SEQUENTIAL;
413416

417+
if (create_param.encryption) {
418+
memcpy(create_param.broadcast_code, CONFIG_BROADCAST_CODE,
419+
strlen(CONFIG_BROADCAST_CODE));
420+
}
421+
414422
printk("Creating broadcast source with %zu subgroups with %zu streams\n",
415423
ARRAY_SIZE(subgroup_param),
416424
ARRAY_SIZE(subgroup_param) * streams_per_subgroup);

0 commit comments

Comments
 (0)