Bluetooth: CAP: shell: add command for broadcast reception start
A shell command has been added for the new CAP procedure 'broadcast_reception_start' Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
This commit is contained in:
parent
518a712db0
commit
b5ecb21447
4 changed files with 213 additions and 2 deletions
|
@ -436,3 +436,18 @@ and index 1 gets the second offset, etc.:
|
|||
AICS inst 0x20014188 state gain 15, mute 0, mode 0
|
||||
Gain set for inst 0x20014188
|
||||
Microphone gain change completed
|
||||
|
||||
Starting a broadcast reception
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
uart:~$ bt connect <device A>
|
||||
Connected: <device A>
|
||||
uart:~$ bap_init
|
||||
uart:~$ cap_commander discover
|
||||
discovery completed with CSIS
|
||||
uart:~$ bap_broadcast_assistant discover
|
||||
BASS discover done with 1 recv states
|
||||
uart:~$ cap_commander broadcast_reception_start <device B> 0 4
|
||||
Starting broadcast reception on 1 connection(s)
|
||||
|
|
|
@ -25,6 +25,9 @@
|
|||
#define SHELL_PRINT_INDENT_LEVEL_SIZE 2
|
||||
#define MAX_CODEC_FRAMES_PER_SDU 4U
|
||||
|
||||
/* BIS sync is a 32-bit bitfield where BIT(0) is not allowed */
|
||||
#define VALID_BIS_SYNC(_bis_sync) ((bis_sync & BIT(0)) == 0U && bis_sync < UINT32_MAX)
|
||||
|
||||
extern struct bt_csip_set_member_svc_inst *svc_inst;
|
||||
|
||||
ssize_t audio_ad_data_add(struct bt_data *data, const size_t data_size, const bool discoverable,
|
||||
|
|
|
@ -25,8 +25,6 @@
|
|||
#include "audio.h"
|
||||
|
||||
#define INVALID_BROADCAST_ID 0xFFFFFFFFU
|
||||
/* BIS sync is a 32-bit bitfield where BIT(0) is not allowed */
|
||||
#define VALID_BIS_SYNC(_bis_sync) ((bis_sync & BIT(0)) == 0U && bis_sync < UINT32_MAX)
|
||||
|
||||
static uint8_t received_base[UINT8_MAX];
|
||||
static uint8_t received_base_size;
|
||||
|
|
|
@ -87,6 +87,18 @@ static void cap_microphone_gain_changed_cb(struct bt_conn *conn, int err)
|
|||
#endif /* CONFIG_BT_MICP_MIC_CTLR_AICS */
|
||||
#endif /* CONFIG_BT_MICP_MIC_CTLR */
|
||||
|
||||
#if defined(CONFIG_BT_BAP_BROADCAST_ASSISTANT)
|
||||
static void cap_broadcast_reception_start_cb(struct bt_conn *conn, int err)
|
||||
{
|
||||
if (err != 0) {
|
||||
shell_error(ctx_shell, "Broadcast reception start failed (%d)", err);
|
||||
return;
|
||||
}
|
||||
|
||||
shell_print(ctx_shell, "Broadcast reception start completed");
|
||||
}
|
||||
#endif
|
||||
|
||||
static struct bt_cap_commander_cb cbs = {
|
||||
.discovery_complete = cap_discover_cb,
|
||||
#if defined(CONFIG_BT_VCP_VOL_CTLR)
|
||||
|
@ -102,6 +114,9 @@ static struct bt_cap_commander_cb cbs = {
|
|||
.microphone_gain_changed = cap_microphone_gain_changed_cb,
|
||||
#endif /* CONFIG_BT_MICP_MIC_CTLR_AICS */
|
||||
#endif /* CONFIG_BT_MICP_MIC_CTLR */
|
||||
#if defined(CONFIG_BT_BAP_BROADCAST_ASSISTANT)
|
||||
.broadcast_reception_start = cap_broadcast_reception_start_cb,
|
||||
#endif /* CONFIG_BT_BAP_BROADCAST_ASSISTANT */
|
||||
};
|
||||
|
||||
static int cmd_cap_commander_cancel(const struct shell *sh, size_t argc, char *argv[])
|
||||
|
@ -472,6 +487,177 @@ static int cmd_cap_commander_change_microphone_gain(const struct shell *sh, size
|
|||
#endif /* CONFIG_BT_MICP_MIC_CTLR_AICS */
|
||||
#endif /* CONFIG_BT_MICP_MIC_CTLR */
|
||||
|
||||
#if defined(CONFIG_BT_BAP_BROADCAST_ASSISTANT)
|
||||
static int cmd_cap_commander_broadcast_reception_start(const struct shell *sh, size_t argc,
|
||||
char *argv[])
|
||||
{
|
||||
struct bt_cap_commander_broadcast_reception_start_member_param
|
||||
member_params[CONFIG_BT_MAX_CONN] = {0};
|
||||
|
||||
struct bt_cap_commander_broadcast_reception_start_param param = {
|
||||
.type = BT_CAP_SET_TYPE_AD_HOC,
|
||||
.param = member_params,
|
||||
};
|
||||
|
||||
struct bt_cap_commander_broadcast_reception_start_member_param *member_param =
|
||||
&member_params[0];
|
||||
struct bt_bap_bass_subgroup subgroup = {0};
|
||||
|
||||
struct bt_conn *connected_conns[CONFIG_BT_MAX_CONN] = {0};
|
||||
size_t conn_cnt = 0U;
|
||||
unsigned long broadcast_id;
|
||||
unsigned long adv_sid;
|
||||
|
||||
int err = 0;
|
||||
|
||||
if (default_conn == NULL) {
|
||||
shell_error(sh, "Not connected");
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
/* TODO: Add support for coordinated sets */
|
||||
|
||||
/* Populate the array of connected connections */
|
||||
bt_conn_foreach(BT_CONN_TYPE_LE, populate_connected_conns, (void *)connected_conns);
|
||||
for (size_t i = 0; i < ARRAY_SIZE(connected_conns); i++) {
|
||||
struct bt_conn *conn = connected_conns[i];
|
||||
|
||||
if (conn == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
conn_cnt++;
|
||||
}
|
||||
|
||||
err = bt_addr_le_from_str(argv[1], argv[2], &member_param->addr);
|
||||
if (err) {
|
||||
shell_error(sh, "Invalid peer address (err %d)", err);
|
||||
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
adv_sid = shell_strtoul(argv[3], 0, &err);
|
||||
if (err != 0) {
|
||||
shell_error(sh, "Could not parse adv_sid: %d", err);
|
||||
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
if (adv_sid > BT_GAP_SID_MAX) {
|
||||
shell_error(sh, "Invalid adv_sid: %lu", adv_sid);
|
||||
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
member_param->adv_sid = adv_sid;
|
||||
|
||||
broadcast_id = shell_strtoul(argv[4], 0, &err);
|
||||
if (err != 0) {
|
||||
shell_error(sh, "Could not parse broadcast_id: %d", err);
|
||||
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
if (broadcast_id > BT_AUDIO_BROADCAST_ID_MAX) {
|
||||
shell_error(sh, "Invalid broadcast_id: %lu", broadcast_id);
|
||||
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
member_param->broadcast_id = broadcast_id;
|
||||
|
||||
if (argc > 5) {
|
||||
unsigned long pa_interval;
|
||||
|
||||
pa_interval = shell_strtoul(argv[5], 0, &err);
|
||||
if (err) {
|
||||
shell_error(sh, "Could not parse pa_interval: %d", err);
|
||||
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
if (!IN_RANGE(pa_interval, BT_GAP_PER_ADV_MIN_INTERVAL,
|
||||
BT_GAP_PER_ADV_MAX_INTERVAL)) {
|
||||
shell_error(sh, "Invalid pa_interval: %lu", pa_interval);
|
||||
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
member_param->pa_interval = pa_interval;
|
||||
} else {
|
||||
member_param->pa_interval = BT_BAP_PA_INTERVAL_UNKNOWN;
|
||||
}
|
||||
|
||||
/* TODO: Support multiple subgroups */
|
||||
if (argc > 6) {
|
||||
unsigned long bis_sync;
|
||||
|
||||
bis_sync = shell_strtoul(argv[6], 0, &err);
|
||||
if (err) {
|
||||
shell_error(sh, "Could not parse bis_sync: %d", err);
|
||||
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
if (!VALID_BIS_SYNC(bis_sync)) {
|
||||
shell_error(sh, "Invalid bis_sync: %lu", bis_sync);
|
||||
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
subgroup.bis_sync = bis_sync;
|
||||
} else {
|
||||
subgroup.bis_sync = BT_BAP_BIS_SYNC_NO_PREF;
|
||||
}
|
||||
|
||||
if (argc > 7) {
|
||||
size_t metadata_len;
|
||||
|
||||
metadata_len = hex2bin(argv[7], strlen(argv[7]), subgroup.metadata,
|
||||
sizeof(subgroup.metadata));
|
||||
|
||||
if (metadata_len == 0U) {
|
||||
shell_error(sh, "Could not parse metadata");
|
||||
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
/* sizeof(subgroup.metadata) can always fit in uint8_t */
|
||||
|
||||
subgroup.metadata_len = metadata_len;
|
||||
}
|
||||
|
||||
member_param->num_subgroups = 1;
|
||||
memcpy(member_param->subgroups, &subgroup, sizeof(struct bt_bap_bass_subgroup));
|
||||
|
||||
member_param->member.member = connected_conns[0];
|
||||
|
||||
/* each connection has its own member_params field
|
||||
* here we use the same values for all connections, so we copy
|
||||
* the parameters
|
||||
*/
|
||||
for (size_t i = 1U; i < conn_cnt; i++) {
|
||||
memcpy(&member_params[i], member_param, sizeof(*member_param));
|
||||
|
||||
/* the member value is different for each, so we can not just copy this value */
|
||||
member_params[i].member.member = connected_conns[i];
|
||||
}
|
||||
|
||||
param.count = conn_cnt;
|
||||
|
||||
shell_print(sh, "Starting broadcast reception on %zu connection(s)", param.count);
|
||||
|
||||
err = bt_cap_commander_broadcast_reception_start(¶m);
|
||||
if (err != 0) {
|
||||
shell_print(sh, "Failed to start broadcast reception: %d", err);
|
||||
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_BT_BAP_BROADCAST_ASSISTANT */
|
||||
|
||||
static int cmd_cap_commander(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
if (argc > 1) {
|
||||
|
@ -510,6 +696,15 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
|
|||
cmd_cap_commander_change_microphone_gain, 2, CONFIG_BT_MAX_CONN - 1),
|
||||
#endif /* CONFIG_BT_MICP_MIC_CTLR_AICS */
|
||||
#endif /* CONFIG_BT_MICP_MIC_CTLR */
|
||||
#if defined(CONFIG_BT_BAP_BROADCAST_ASSISTANT)
|
||||
SHELL_CMD_ARG(broadcast_reception_start, NULL,
|
||||
"Start broadcast reception "
|
||||
"with source <address: XX:XX:XX:XX:XX:XX> "
|
||||
"<type: public/random> <adv_sid> "
|
||||
"<broadcast_id> [<pa_interval>] [<sync_bis>] "
|
||||
"[<metadata>]",
|
||||
cmd_cap_commander_broadcast_reception_start, 5, 3),
|
||||
#endif /* CONFIG_BT_BAP_BROADCAST_ASSISTANT */
|
||||
SHELL_SUBCMD_SET_END);
|
||||
|
||||
SHELL_CMD_ARG_REGISTER(cap_commander, &cap_commander_cmds, "Bluetooth CAP commander shell commands",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue