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
|
@ -735,6 +735,12 @@ int bt_audio_broadcast_source_create(struct bt_audio_broadcast_source_create_par
|
|||
source->qos = qos;
|
||||
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);
|
||||
|
||||
*out_source = source;
|
||||
|
@ -883,6 +889,11 @@ int bt_audio_broadcast_source_start(struct bt_audio_broadcast_source *source,
|
|||
param.packing = source->packing;
|
||||
param.interval = source->qos->interval;
|
||||
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);
|
||||
if (err != 0) {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/bluetooth/audio/bap.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/types.h>
|
||||
|
||||
|
@ -75,6 +76,7 @@ struct bt_audio_broadcast_stream_data {
|
|||
struct bt_audio_broadcast_source {
|
||||
uint8_t stream_count;
|
||||
uint8_t packing;
|
||||
bool encryption;
|
||||
uint32_t broadcast_id; /* 24 bit */
|
||||
|
||||
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 */
|
||||
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 */
|
||||
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
|
||||
stream_params[ARRAY_SIZE(broadcast_source_streams)];
|
||||
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;
|
||||
int err;
|
||||
|
||||
|
@ -1545,12 +1545,51 @@ static int cmd_create_broadcast(const struct shell *sh, size_t argc,
|
|||
|
||||
named_preset = default_preset;
|
||||
|
||||
if (argc > 1) {
|
||||
named_preset = set_preset(false, 1, &argv[1]);
|
||||
if (named_preset == NULL) {
|
||||
shell_error(sh, "Unable to parse named_preset %s",
|
||||
argv[1]);
|
||||
return -ENOEXEC;
|
||||
for (size_t i = 1U; i < argc; i++) {
|
||||
char *arg = argv[i];
|
||||
|
||||
if (strcmp(arg, "enc") == 0) {
|
||||
if (argc > i) {
|
||||
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)
|
||||
SHELL_CMD_ARG(select_broadcast, NULL, "<stream>",
|
||||
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),
|
||||
SHELL_CMD_ARG(start_broadcast, NULL, "", cmd_start_broadcast, 1, 0),
|
||||
SHELL_CMD_ARG(stop_broadcast, NULL, "", cmd_stop_broadcast, 1, 0),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue