Skip to content

Commit 3f7224a

Browse files
lylezhu2012kartben
authored andcommitted
Bluetooth: Classic: HFP_AG: Update the callback sco_disconnected()
Change the arguments of HFP AG callback `sco_disconnected()` to SCO conn and disconnection reason. Signed-off-by: Lyle Zhu <[email protected]>
1 parent 4f2dc5f commit 3f7224a

File tree

5 files changed

+47
-16
lines changed

5 files changed

+47
-16
lines changed

doc/releases/migration-guide-4.2.rst

+7
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,13 @@ Bluetooth Host
227227
each role may be different. Any existing uses/checks for ``BT_ISO_CHAN_TYPE_CONNECTED``
228228
can be replaced with an ``||`` of the two. (:github:`75549`)
229229

230+
Bluetooth Classic
231+
=================
232+
233+
* The parameters of HFP AG callback ``sco_disconnected`` of the struct :c:struct:`bt_hfp_ag_cb`
234+
have been changed to SCO connection object ``struct bt_conn *sco_conn`` and the disconnection
235+
reason of the SCO connection ``uint8_t reason``.
236+
230237
Networking
231238
**********
232239

include/zephyr/bluetooth/classic/hfp_ag.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ struct bt_hfp_ag_cb {
111111
* If this callback is provided it will be called whenever the
112112
* SCO/eSCO connection gets disconnected.
113113
*
114-
* @param ag HFP AG object.
115-
* @param sco_conn SCO/eSCO Connection object.
114+
* @param conn SCO/eSCO Connection object.
115+
* @param reason BT_HCI_ERR_* reason for the disconnection.
116116
*/
117-
void (*sco_disconnected)(struct bt_hfp_ag *ag);
117+
void (*sco_disconnected)(struct bt_conn *sco_conn, uint8_t reason);
118118

119119
/** HF memory dialing request Callback
120120
*

samples/bluetooth/handsfree_ag/src/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ static void ag_sco_connected(struct bt_hfp_ag *ag, struct bt_conn *sco_conn)
6363
printk("HFP AG SCO connected!\n");
6464
}
6565

66-
static void ag_sco_disconnected(struct bt_hfp_ag *ag)
66+
static void ag_sco_disconnected(struct bt_conn *sco_conn, uint8_t reason)
6767
{
68-
printk("HFP AG SCO disconnected!\n");
68+
printk("HFP AG SCO disconnected %u!\n", reason);
6969
}
7070

7171
static void ag_ringing(struct bt_hfp_ag_call *call, bool in_band)

subsys/bluetooth/host/classic/hfp_ag.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2029,8 +2029,8 @@ static void hfp_ag_sco_disconnected(struct bt_sco_chan *chan, uint8_t reason)
20292029

20302030
call = get_call_with_flag(ag, BT_HFP_AG_CALL_OPEN_SCO, true);
20312031

2032-
if ((bt_ag) && bt_ag->sco_disconnected) {
2033-
bt_ag->sco_disconnected(ag);
2032+
if ((bt_ag != NULL) && bt_ag->sco_disconnected) {
2033+
bt_ag->sco_disconnected(chan->sco, reason);
20342034
}
20352035

20362036
if (!call) {

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

+33-9
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,26 @@ static void hf_disconnected(struct bt_hfp_hf *hf)
7373

7474
static void hf_sco_connected(struct bt_hfp_hf *hf, struct bt_conn *sco_conn)
7575
{
76-
bt_shell_print("HF SCO connected");
77-
hf_sco_conn = sco_conn;
76+
bt_shell_print("HF SCO connected %p", sco_conn);
77+
78+
if (hf_sco_conn != NULL) {
79+
bt_shell_warn("HF SCO conn %p exists", hf_sco_conn);
80+
return;
81+
}
82+
83+
hf_sco_conn = bt_conn_ref(sco_conn);
7884
}
7985

8086
static void hf_sco_disconnected(struct bt_conn *sco_conn, uint8_t reason)
8187
{
82-
bt_shell_print("HF SCO disconnected");
83-
hf_sco_conn = NULL;
88+
bt_shell_print("HF SCO disconnected %p (reason %u)", sco_conn, reason);
89+
90+
if (hf_sco_conn == sco_conn) {
91+
bt_conn_unref(hf_sco_conn);
92+
hf_sco_conn = NULL;
93+
} else {
94+
bt_shell_warn("Unknown SCO disconnected (%p != %p)", hf_sco_conn, sco_conn);
95+
}
8496
}
8597

8698
void hf_service(struct bt_hfp_hf *hf, uint32_t value)
@@ -998,14 +1010,26 @@ static void ag_disconnected(struct bt_hfp_ag *ag)
9981010

9991011
static void ag_sco_connected(struct bt_hfp_ag *ag, struct bt_conn *sco_conn)
10001012
{
1001-
bt_shell_print("ag sco connected");
1002-
hfp_ag_sco_conn = sco_conn;
1013+
bt_shell_print("AG SCO connected %p", sco_conn);
1014+
1015+
if (hfp_ag_sco_conn != NULL) {
1016+
bt_shell_warn("AG SCO conn %p exists", hfp_ag_sco_conn);
1017+
return;
1018+
}
1019+
1020+
hfp_ag_sco_conn = bt_conn_ref(sco_conn);
10031021
}
10041022

1005-
static void ag_sco_disconnected(struct bt_hfp_ag *ag)
1023+
static void ag_sco_disconnected(struct bt_conn *sco_conn, uint8_t reason)
10061024
{
1007-
bt_shell_print("ag sco disconnected");
1008-
hfp_ag_sco_conn = NULL;
1025+
bt_shell_print("AG SCO disconnected %p (reason %u)", sco_conn, reason);
1026+
1027+
if (hfp_ag_sco_conn == sco_conn) {
1028+
bt_conn_unref(hfp_ag_sco_conn);
1029+
hfp_ag_sco_conn = NULL;
1030+
} else {
1031+
bt_shell_warn("Unknown SCO disconnected (%p != %p)", hfp_ag_sco_conn, sco_conn);
1032+
}
10091033
}
10101034

10111035
static int ag_memory_dial(struct bt_hfp_ag *ag, const char *location, char **number)

0 commit comments

Comments
 (0)