@@ -896,6 +896,7 @@ static int cmd_discover(const struct shell *sh, size_t argc, char *argv[])
896
896
897
897
static int cmd_config (const struct shell * sh , size_t argc , char * argv [])
898
898
{
899
+ enum bt_audio_location location = BT_AUDIO_LOCATION_PROHIBITED ;
899
900
const struct named_lc3_preset * named_preset ;
900
901
struct unicast_stream * uni_stream ;
901
902
struct bt_bap_ep * ep = NULL ;
@@ -949,11 +950,49 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[])
949
950
return - ENOEXEC ;
950
951
}
951
952
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
+ }
957
996
}
958
997
}
959
998
@@ -973,6 +1012,23 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[])
973
1012
data -> data .data = data -> value ;
974
1013
}
975
1014
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
+
976
1032
if (default_stream -> ep == ep ) {
977
1033
err = bt_bap_stream_reconfig (default_stream , & uni_stream -> codec );
978
1034
if (err != 0 ) {
@@ -2366,7 +2422,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
2366
2422
#if defined(CONFIG_BT_BAP_UNICAST )
2367
2423
#if defined(CONFIG_BT_BAP_UNICAST_CLIENT )
2368
2424
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 ),
2370
2428
SHELL_CMD_ARG (stream_qos , NULL , "interval [framing] [latency] [pd] [sdu] [phy] [rtn]" ,
2371
2429
cmd_stream_qos , 2 , 6 ),
2372
2430
SHELL_CMD_ARG (qos , NULL , "Send QoS configure for Unicast Group" , cmd_qos , 1 , 0 ),
0 commit comments