Skip to content

Commit 918b91b

Browse files
lylezhu2012kartben
authored andcommitted
Bluetooth: Classic: Shell: HFP: Clear all calls if SLC is broken
If the SLC is broken, all saved calls should be cleared. Clear all calls in the callback `hf_disconnected()` and `ag_disconnected()`. Signed-off-by: Lyle Zhu <[email protected]>
1 parent 03ca91f commit 918b91b

File tree

1 file changed

+32
-12
lines changed
  • subsys/bluetooth/host/classic/shell

1 file changed

+32
-12
lines changed

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

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,33 @@ static struct bt_hfp_hf_call *hfp_hf_call[CONFIG_BT_HFP_HF_MAX_CALLS];
3939

4040
static void hf_add_a_call(struct bt_hfp_hf_call *call)
4141
{
42-
for (size_t index = 0; index < ARRAY_SIZE(hfp_hf_call); index++) {
43-
if (!hfp_hf_call[index]) {
44-
hfp_hf_call[index] = call;
42+
ARRAY_FOR_EACH(hfp_hf_call, i) {
43+
if (!hfp_hf_call[i]) {
44+
hfp_hf_call[i] = call;
4545
return;
4646
}
4747
}
4848
}
4949

5050
static void hf_remove_a_call(struct bt_hfp_hf_call *call)
5151
{
52-
for (size_t index = 0; index < ARRAY_SIZE(hfp_hf_call); index++) {
53-
if (call == hfp_hf_call[index]) {
54-
hfp_hf_call[index] = NULL;
52+
ARRAY_FOR_EACH(hfp_hf_call, i) {
53+
if (call == hfp_hf_call[i]) {
54+
hfp_hf_call[i] = NULL;
5555
return;
5656
}
5757
}
5858
}
5959

60+
static void hf_remove_calls(void)
61+
{
62+
ARRAY_FOR_EACH(hfp_hf_call, i) {
63+
if (hfp_hf_call[i] != NULL) {
64+
hfp_hf_call[i] = NULL;
65+
}
66+
}
67+
}
68+
6069
static void hf_connected(struct bt_conn *conn, struct bt_hfp_hf *hf)
6170
{
6271
hf_conn = conn;
@@ -68,6 +77,7 @@ static void hf_disconnected(struct bt_hfp_hf *hf)
6877
{
6978
hf_conn = NULL;
7079
hfp_hf = NULL;
80+
hf_remove_calls();
7181
bt_shell_print("HF disconnected");
7282
}
7383

@@ -976,24 +986,33 @@ static struct bt_hfp_ag_call *hfp_ag_call[CONFIG_BT_HFP_AG_MAX_CALLS];
976986

977987
static void ag_add_a_call(struct bt_hfp_ag_call *call)
978988
{
979-
for (size_t index = 0; index < ARRAY_SIZE(hfp_ag_call); index++) {
980-
if (!hfp_ag_call[index]) {
981-
hfp_ag_call[index] = call;
989+
ARRAY_FOR_EACH(hfp_ag_call, i) {
990+
if (!hfp_ag_call[i]) {
991+
hfp_ag_call[i] = call;
982992
return;
983993
}
984994
}
985995
}
986996

987997
static void ag_remove_a_call(struct bt_hfp_ag_call *call)
988998
{
989-
for (size_t index = 0; index < ARRAY_SIZE(hfp_ag_call); index++) {
990-
if (call == hfp_ag_call[index]) {
991-
hfp_ag_call[index] = NULL;
999+
ARRAY_FOR_EACH(hfp_ag_call, i) {
1000+
if (call == hfp_ag_call[i]) {
1001+
hfp_ag_call[i] = NULL;
9921002
return;
9931003
}
9941004
}
9951005
}
9961006

1007+
static void ag_remove_calls(void)
1008+
{
1009+
ARRAY_FOR_EACH(hfp_ag_call, i) {
1010+
if (hfp_ag_call[i] != NULL) {
1011+
hfp_ag_call[i] = NULL;
1012+
}
1013+
}
1014+
}
1015+
9971016
static void ag_connected(struct bt_conn *conn, struct bt_hfp_ag *ag)
9981017
{
9991018
if (conn != default_conn) {
@@ -1005,6 +1024,7 @@ static void ag_connected(struct bt_conn *conn, struct bt_hfp_ag *ag)
10051024

10061025
static void ag_disconnected(struct bt_hfp_ag *ag)
10071026
{
1027+
ag_remove_calls();
10081028
bt_shell_print("AG disconnected");
10091029
}
10101030

0 commit comments

Comments
 (0)