Skip to content

Commit 5704b83

Browse files
Thalleycarlescufi
authored andcommitted
Bluetooth: Audio: Shell: Add location to cmd_config
Add support for setting the location value (BT_CODEC_CONFIG_LC3_CHAN_ALLOC) in the codec configuration. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 5391279 commit 5704b83

File tree

2 files changed

+66
-8
lines changed
  • doc/connectivity/bluetooth/api/shell
  • subsys/bluetooth/shell

2 files changed

+66
-8
lines changed

doc/connectivity/bluetooth/api/shell/bap.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Commands
2828
stop_broadcast_sink :Stops broadcast sink
2929
term_broadcast_sink :
3030
discover :[dir: sink, source]
31-
config :<direction: sink, source> <index> [preset]
31+
config :<direction: sink, source> <index> [loc <loc_bits>] [preset <preset_name>]
3232
stream_qos :interval [framing] [latency] [pd] [sdu] [phy] [rtn]
3333
qos :Send QoS configure for Unicast Group
3434
enable :[context]
@@ -286,7 +286,7 @@ or in case it is omitted the default preset is used.
286286

287287
.. code-block:: console
288288
289-
uart:~$ bap config <direction: sink, source> <index> [preset]
289+
uart:~$ bap config <direction: sink, source> <index> [loc <loc_bits>] [preset <preset_name>]
290290
uart:~$ bap config sink 0
291291
ASE Codec Config: conn 0x8173800 ep 0x81754e0 cap 0x816a360
292292
codec 0x06 cid 0x0000 vid 0x0000 count 3

subsys/bluetooth/shell/bap.c

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,7 @@ static int cmd_discover(const struct shell *sh, size_t argc, char *argv[])
896896

897897
static int cmd_config(const struct shell *sh, size_t argc, char *argv[])
898898
{
899+
enum bt_audio_location location = BT_AUDIO_LOCATION_PROHIBITED;
899900
const struct named_lc3_preset *named_preset;
900901
struct unicast_stream *uni_stream;
901902
struct bt_bap_ep *ep = NULL;
@@ -949,11 +950,49 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[])
949950
return -ENOEXEC;
950951
}
951952

952-
if (argc > 3) {
953-
named_preset = get_named_preset(true, argv[3]);
954-
if (named_preset == NULL) {
955-
shell_error(sh, "Unable to parse named_preset %s", argv[3]);
956-
return -ENOEXEC;
953+
for (size_t i = 3U; i < argc; i++) {
954+
const char *arg = argv[i];
955+
956+
/* argc needs to be larger than `i` to parse the argument value */
957+
if (argc <= i) {
958+
shell_help(sh);
959+
960+
return SHELL_CMD_HELP_PRINTED;
961+
}
962+
963+
if (strcmp(arg, "loc") == 0) {
964+
unsigned long loc_bits;
965+
966+
arg = argv[++i];
967+
loc_bits = shell_strtoul(arg, 0, &err);
968+
if (err != 0) {
969+
shell_error(sh, "Could not parse loc_bits: %d", err);
970+
971+
return -ENOEXEC;
972+
}
973+
974+
if (loc_bits == BT_AUDIO_LOCATION_PROHIBITED ||
975+
loc_bits > BT_AUDIO_LOCATION_ANY) {
976+
shell_error(sh, "Invalid loc_bits: %lu", loc_bits);
977+
978+
return -ENOEXEC;
979+
}
980+
981+
location = (enum bt_audio_location)loc_bits;
982+
} else if (strcmp(arg, "preset") == 0) {
983+
if (argc > i) {
984+
arg = argv[++i];
985+
986+
named_preset = get_named_preset(true, arg);
987+
if (named_preset == NULL) {
988+
shell_error(sh, "Unable to parse named_preset %s", arg);
989+
return -ENOEXEC;
990+
}
991+
} else {
992+
shell_help(sh);
993+
994+
return SHELL_CMD_HELP_PRINTED;
995+
}
957996
}
958997
}
959998

@@ -973,6 +1012,23 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[])
9731012
data->data.data = data->value;
9741013
}
9751014

1015+
/* If location has been modifed, we update the location in the codec configuration */
1016+
if (location != BT_AUDIO_LOCATION_PROHIBITED) {
1017+
for (size_t i = 0U; i < uni_stream->codec.data_count; i++) {
1018+
struct bt_codec_data *data = &uni_stream->codec.data[i];
1019+
1020+
/* Overwrite the location value */
1021+
if (data->data.type == BT_CODEC_CONFIG_LC3_CHAN_ALLOC) {
1022+
const uint32_t loc_32 = location;
1023+
1024+
sys_put_le32(loc_32, data->value);
1025+
1026+
shell_print(sh, "Setting location to 0x%08X", location);
1027+
break;
1028+
}
1029+
}
1030+
}
1031+
9761032
if (default_stream->ep == ep) {
9771033
err = bt_bap_stream_reconfig(default_stream, &uni_stream->codec);
9781034
if (err != 0) {
@@ -2366,7 +2422,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
23662422
#if defined(CONFIG_BT_BAP_UNICAST)
23672423
#if defined(CONFIG_BT_BAP_UNICAST_CLIENT)
23682424
SHELL_CMD_ARG(discover, NULL, "[dir: sink, source]", cmd_discover, 1, 1),
2369-
SHELL_CMD_ARG(config, NULL, "<direction: sink, source> <index> [preset]", cmd_config, 3, 1),
2425+
SHELL_CMD_ARG(config, NULL,
2426+
"<direction: sink, source> <index> [loc <loc_bits>] [preset <preset_name>]",
2427+
cmd_config, 3, 4),
23702428
SHELL_CMD_ARG(stream_qos, NULL, "interval [framing] [latency] [pd] [sdu] [phy] [rtn]",
23712429
cmd_stream_qos, 2, 6),
23722430
SHELL_CMD_ARG(qos, NULL, "Send QoS configure for Unicast Group", cmd_qos, 1, 0),

0 commit comments

Comments
 (0)