Skip to content

Commit ff41c71

Browse files
lylezhu2012kartben
authored andcommitted
Bluetooth: Class: Shell: HFP_HF: Add auto_select_codec command
Add shell command `auto_select_codec` to select codec automatically when codec negotiation callback is notified. Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
1 parent aaef7eb commit ff41c71

File tree

1 file changed

+27
-0
lines changed
  • subsys/bluetooth/host/classic/shell

1 file changed

+27
-0
lines changed

subsys/bluetooth/host/classic/shell/hfp.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ struct bt_conn *hf_conn;
3636
struct bt_hfp_hf *hfp_hf;
3737
struct bt_conn *hf_sco_conn;
3838
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 */
3942

4043
static void hf_add_a_call(struct bt_hfp_hf_call *call)
4144
{
@@ -217,6 +220,16 @@ static void hf_operator(struct bt_hfp_hf *hf, uint8_t mode, uint8_t format, char
217220
static void hf_codec_negotiate(struct bt_hfp_hf *hf, uint8_t id)
218221
{
219222
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+
}
220233
}
221234
#endif /* CONFIG_BT_HFP_HF_CODEC_NEG */
222235

@@ -471,6 +484,19 @@ static int cmd_select_codec(const struct shell *sh, size_t argc, char **argv)
471484
return err;
472485
}
473486

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+
474500
static int cmd_set_codecs(const struct shell *sh, size_t argc, char **argv)
475501
{
476502
int err;
@@ -925,6 +951,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(hf_cmds,
925951
SHELL_CMD_ARG(operator, NULL, HELP_NONE, cmd_operator, 1, 0),
926952
#if defined(CONFIG_BT_HFP_HF_CODEC_NEG)
927953
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),
928955
SHELL_CMD_ARG(select_codec, NULL, "Codec ID", cmd_select_codec, 2, 0),
929956
SHELL_CMD_ARG(set_codecs, NULL, "Codec ID Map", cmd_set_codecs, 2, 0),
930957
#endif /* CONFIG_BT_HFP_HF_CODEC_NEG */

0 commit comments

Comments
 (0)