@@ -36,6 +36,9 @@ struct bt_conn *hf_conn;
36
36
struct bt_hfp_hf * hfp_hf ;
37
37
struct bt_conn * hf_sco_conn ;
38
38
static struct bt_hfp_hf_call * hfp_hf_call [CONFIG_BT_HFP_HF_MAX_CALLS ];
39
+ #if defined(CONFIG_BT_HFP_HF_CODEC_NEG )
40
+ static bool hf_auto_select_codec ;
41
+ #endif /* CONFIG_BT_HFP_HF_CODEC_NEG */
39
42
40
43
static void hf_add_a_call (struct bt_hfp_hf_call * call )
41
44
{
@@ -217,6 +220,16 @@ static void hf_operator(struct bt_hfp_hf *hf, uint8_t mode, uint8_t format, char
217
220
static void hf_codec_negotiate (struct bt_hfp_hf * hf , uint8_t id )
218
221
{
219
222
bt_shell_print ("codec negotiation: %d" , id );
223
+ if (hf_auto_select_codec ) {
224
+ int err ;
225
+
226
+ err = bt_hfp_hf_select_codec (hfp_hf , id );
227
+ if (err ) {
228
+ bt_shell_error ("Failed to select codec id: %d" , err );
229
+ } else {
230
+ bt_shell_print ("codec auto selected: id %d" , id );
231
+ }
232
+ }
220
233
}
221
234
#endif /* CONFIG_BT_HFP_HF_CODEC_NEG */
222
235
@@ -471,6 +484,19 @@ static int cmd_select_codec(const struct shell *sh, size_t argc, char **argv)
471
484
return err ;
472
485
}
473
486
487
+ static int cmd_auto_select_codec (const struct shell * sh , size_t argc , char * * argv )
488
+ {
489
+ int err = 0 ;
490
+
491
+ hf_auto_select_codec = shell_strtobool (argv [1 ], 0 , & err );
492
+ if (err != 0 ) {
493
+ shell_help (sh );
494
+ return SHELL_CMD_HELP_PRINTED ;
495
+ }
496
+
497
+ return 0 ;
498
+ }
499
+
474
500
static int cmd_set_codecs (const struct shell * sh , size_t argc , char * * argv )
475
501
{
476
502
int err ;
@@ -925,6 +951,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(hf_cmds,
925
951
SHELL_CMD_ARG (operator , NULL , HELP_NONE , cmd_operator , 1 , 0 ),
926
952
#if defined(CONFIG_BT_HFP_HF_CODEC_NEG )
927
953
SHELL_CMD_ARG (audio_connect , NULL , HELP_NONE , cmd_audio_connect , 1 , 0 ),
954
+ SHELL_CMD_ARG (auto_select_codec , NULL , "<enable/disable>" , cmd_auto_select_codec , 2 , 0 ),
928
955
SHELL_CMD_ARG (select_codec , NULL , "Codec ID" , cmd_select_codec , 2 , 0 ),
929
956
SHELL_CMD_ARG (set_codecs , NULL , "Codec ID Map" , cmd_set_codecs , 2 , 0 ),
930
957
#endif /* CONFIG_BT_HFP_HF_CODEC_NEG */
0 commit comments