Bluetooth: Audio: Add support for encrypted broadcast
Add support for adding a broadcast code to the broadcast source. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
parent
9b1b68657c
commit
8d86fa0125
6 changed files with 72 additions and 8 deletions
|
@ -17,6 +17,7 @@
|
||||||
#include <zephyr/bluetooth/hci.h>
|
#include <zephyr/bluetooth/hci.h>
|
||||||
#include <zephyr/bluetooth/iso.h>
|
#include <zephyr/bluetooth/iso.h>
|
||||||
#include <zephyr/bluetooth/gatt.h>
|
#include <zephyr/bluetooth/gatt.h>
|
||||||
|
#include <zephyr/bluetooth/audio/bap.h>
|
||||||
#include <zephyr/bluetooth/audio/lc3.h>
|
#include <zephyr/bluetooth/audio/lc3.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2085,6 +2086,12 @@ struct bt_audio_broadcast_source_create_param {
|
||||||
* controller may ignore.
|
* controller may ignore.
|
||||||
*/
|
*/
|
||||||
uint8_t packing;
|
uint8_t packing;
|
||||||
|
|
||||||
|
/** Whether or not to encrypt the streams. */
|
||||||
|
bool encryption;
|
||||||
|
|
||||||
|
/** @brief Broadcast code */
|
||||||
|
uint8_t broadcast_code[BT_BAP_BROADCAST_CODE_SIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @brief Create audio broadcast source.
|
/** @brief Create audio broadcast source.
|
||||||
|
|
|
@ -113,6 +113,7 @@ static int setup_broadcast_source(struct bt_audio_broadcast_source **source)
|
||||||
create_param.params_count = ARRAY_SIZE(subgroup_param);
|
create_param.params_count = ARRAY_SIZE(subgroup_param);
|
||||||
create_param.params = subgroup_param;
|
create_param.params = subgroup_param;
|
||||||
create_param.qos = &preset_16_2_1.qos;
|
create_param.qos = &preset_16_2_1.qos;
|
||||||
|
create_param.encryption = false;
|
||||||
|
|
||||||
printk("Creating broadcast source with %zu subgroups with %zu streams\n",
|
printk("Creating broadcast source with %zu subgroups with %zu streams\n",
|
||||||
ARRAY_SIZE(subgroup_param),
|
ARRAY_SIZE(subgroup_param),
|
||||||
|
|
|
@ -735,6 +735,12 @@ int bt_audio_broadcast_source_create(struct bt_audio_broadcast_source_create_par
|
||||||
source->qos = qos;
|
source->qos = qos;
|
||||||
source->packing = param->packing;
|
source->packing = param->packing;
|
||||||
|
|
||||||
|
source->encryption = param->encryption;
|
||||||
|
if (source->encryption) {
|
||||||
|
(void)memcpy(source->broadcast_code, param->broadcast_code,
|
||||||
|
sizeof(source->broadcast_code));
|
||||||
|
}
|
||||||
|
|
||||||
LOG_DBG("Broadcasting with ID 0x%6X", source->broadcast_id);
|
LOG_DBG("Broadcasting with ID 0x%6X", source->broadcast_id);
|
||||||
|
|
||||||
*out_source = source;
|
*out_source = source;
|
||||||
|
@ -883,6 +889,11 @@ int bt_audio_broadcast_source_start(struct bt_audio_broadcast_source *source,
|
||||||
param.packing = source->packing;
|
param.packing = source->packing;
|
||||||
param.interval = source->qos->interval;
|
param.interval = source->qos->interval;
|
||||||
param.latency = source->qos->latency;
|
param.latency = source->qos->latency;
|
||||||
|
param.encryption = source->encryption;
|
||||||
|
if (param.encryption) {
|
||||||
|
(void)memcpy(param.bcode, source->broadcast_code,
|
||||||
|
sizeof(param.bcode));
|
||||||
|
}
|
||||||
|
|
||||||
err = bt_iso_big_create(adv, ¶m, &source->big);
|
err = bt_iso_big_create(adv, ¶m, &source->big);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <zephyr/bluetooth/audio/bap.h>
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
#include <zephyr/types.h>
|
#include <zephyr/types.h>
|
||||||
|
|
||||||
|
@ -75,6 +76,7 @@ struct bt_audio_broadcast_stream_data {
|
||||||
struct bt_audio_broadcast_source {
|
struct bt_audio_broadcast_source {
|
||||||
uint8_t stream_count;
|
uint8_t stream_count;
|
||||||
uint8_t packing;
|
uint8_t packing;
|
||||||
|
bool encryption;
|
||||||
uint32_t broadcast_id; /* 24 bit */
|
uint32_t broadcast_id; /* 24 bit */
|
||||||
|
|
||||||
struct bt_iso_big *big;
|
struct bt_iso_big *big;
|
||||||
|
@ -83,6 +85,8 @@ struct bt_audio_broadcast_source {
|
||||||
/* The codec specific configured data for each stream in the subgroup */
|
/* The codec specific configured data for each stream in the subgroup */
|
||||||
struct bt_audio_broadcast_stream_data stream_data[BROADCAST_STREAM_CNT];
|
struct bt_audio_broadcast_stream_data stream_data[BROADCAST_STREAM_CNT];
|
||||||
|
|
||||||
|
uint8_t broadcast_code[BT_BAP_BROADCAST_CODE_SIZE];
|
||||||
|
|
||||||
/* The subgroups containing the streams used to create the broadcast source */
|
/* The subgroups containing the streams used to create the broadcast source */
|
||||||
sys_slist_t subgroups;
|
sys_slist_t subgroups;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1534,7 +1534,7 @@ static int cmd_create_broadcast(const struct shell *sh, size_t argc,
|
||||||
struct bt_audio_broadcast_source_stream_param
|
struct bt_audio_broadcast_source_stream_param
|
||||||
stream_params[ARRAY_SIZE(broadcast_source_streams)];
|
stream_params[ARRAY_SIZE(broadcast_source_streams)];
|
||||||
struct bt_audio_broadcast_source_subgroup_param subgroup_param;
|
struct bt_audio_broadcast_source_subgroup_param subgroup_param;
|
||||||
struct bt_audio_broadcast_source_create_param create_param;
|
struct bt_audio_broadcast_source_create_param create_param = { 0 };
|
||||||
struct named_lc3_preset *named_preset;
|
struct named_lc3_preset *named_preset;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
@ -1545,12 +1545,51 @@ static int cmd_create_broadcast(const struct shell *sh, size_t argc,
|
||||||
|
|
||||||
named_preset = default_preset;
|
named_preset = default_preset;
|
||||||
|
|
||||||
if (argc > 1) {
|
for (size_t i = 1U; i < argc; i++) {
|
||||||
named_preset = set_preset(false, 1, &argv[1]);
|
char *arg = argv[i];
|
||||||
if (named_preset == NULL) {
|
|
||||||
shell_error(sh, "Unable to parse named_preset %s",
|
if (strcmp(arg, "enc") == 0) {
|
||||||
argv[1]);
|
if (argc > i) {
|
||||||
return -ENOEXEC;
|
size_t bcode_len;
|
||||||
|
|
||||||
|
i++;
|
||||||
|
arg = argv[i];
|
||||||
|
|
||||||
|
bcode_len = hex2bin(arg, strlen(arg),
|
||||||
|
create_param.broadcast_code,
|
||||||
|
sizeof(create_param.broadcast_code));
|
||||||
|
|
||||||
|
if (bcode_len != sizeof(create_param.broadcast_code)) {
|
||||||
|
shell_error(sh, "Invalid Broadcast Code Length: %zu",
|
||||||
|
bcode_len);
|
||||||
|
|
||||||
|
return -ENOEXEC;
|
||||||
|
}
|
||||||
|
|
||||||
|
create_param.encryption = true;
|
||||||
|
} else {
|
||||||
|
shell_help(sh);
|
||||||
|
|
||||||
|
return SHELL_CMD_HELP_PRINTED;
|
||||||
|
}
|
||||||
|
} else if (strcmp(arg, "preset") == 0) {
|
||||||
|
if (argc > i) {
|
||||||
|
|
||||||
|
i++;
|
||||||
|
arg = argv[i];
|
||||||
|
|
||||||
|
named_preset = set_preset(false, 1, &arg);
|
||||||
|
if (named_preset == NULL) {
|
||||||
|
shell_error(sh, "Unable to parse named_preset %s",
|
||||||
|
arg);
|
||||||
|
|
||||||
|
return -ENOEXEC;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
shell_help(sh);
|
||||||
|
|
||||||
|
return SHELL_CMD_HELP_PRINTED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1955,7 +1994,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE(audio_cmds,
|
||||||
#if defined(CONFIG_BT_AUDIO_BROADCAST_SOURCE)
|
#if defined(CONFIG_BT_AUDIO_BROADCAST_SOURCE)
|
||||||
SHELL_CMD_ARG(select_broadcast, NULL, "<stream>",
|
SHELL_CMD_ARG(select_broadcast, NULL, "<stream>",
|
||||||
cmd_select_broadcast_source, 2, 0),
|
cmd_select_broadcast_source, 2, 0),
|
||||||
SHELL_CMD_ARG(create_broadcast, NULL, "[codec] [preset]",
|
SHELL_CMD_ARG(create_broadcast, NULL,
|
||||||
|
"[preset <preset_name>] [enc <broadcast_code>]",
|
||||||
cmd_create_broadcast, 1, 2),
|
cmd_create_broadcast, 1, 2),
|
||||||
SHELL_CMD_ARG(start_broadcast, NULL, "", cmd_start_broadcast, 1, 0),
|
SHELL_CMD_ARG(start_broadcast, NULL, "", cmd_start_broadcast, 1, 0),
|
||||||
SHELL_CMD_ARG(stop_broadcast, NULL, "", cmd_stop_broadcast, 1, 0),
|
SHELL_CMD_ARG(stop_broadcast, NULL, "", cmd_stop_broadcast, 1, 0),
|
||||||
|
|
|
@ -128,6 +128,7 @@ static int setup_broadcast_source(struct bt_audio_broadcast_source **source)
|
||||||
create_param.params = subgroup_params;
|
create_param.params = subgroup_params;
|
||||||
create_param.qos = &preset_16_2_2.qos;
|
create_param.qos = &preset_16_2_2.qos;
|
||||||
create_param.packing = BT_ISO_PACKING_SEQUENTIAL;
|
create_param.packing = BT_ISO_PACKING_SEQUENTIAL;
|
||||||
|
create_param.encryption = false;
|
||||||
|
|
||||||
printk("Creating broadcast source with %zu subgroups and %zu streams\n",
|
printk("Creating broadcast source with %zu subgroups and %zu streams\n",
|
||||||
ARRAY_SIZE(subgroup_params), ARRAY_SIZE(stream_params));
|
ARRAY_SIZE(subgroup_params), ARRAY_SIZE(stream_params));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue