Skip to content

Commit 6c83b9b

Browse files
lylezhu2012nashif
authored andcommitted
Bluetooth: Classic: HFP_HF: Register SCO connect callback
There is an issue that the SCO connect cannot be un-referenced by HFP HF when the SCO connection is broken if the SCO connect is not created by HFP HF. Register SCO connect change callback. And un-reference the SCO connect in SCO disconnected callback. Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
1 parent 3d8dfd7 commit 6c83b9b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

subsys/bluetooth/host/classic/hfp_hf.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4474,6 +4474,31 @@ static int bt_hfp_hf_sco_accept(const struct bt_sco_accept_info *info,
44744474
return 0;
44754475
}
44764476

4477+
static void hf_sco_connected(struct bt_conn *conn, uint8_t err)
4478+
{
4479+
ARG_UNUSED(conn);
4480+
ARG_UNUSED(err);
4481+
}
4482+
4483+
static void hf_sco_disconnected(struct bt_conn *conn, uint8_t reason)
4484+
{
4485+
ARG_UNUSED(reason);
4486+
4487+
__ASSERT(conn != NULL, "Invalid SCO conn");
4488+
4489+
ARRAY_FOR_EACH(bt_hfp_hf_pool, i) {
4490+
if (bt_hfp_hf_pool[i].sco_conn == conn) {
4491+
bt_conn_unref(bt_hfp_hf_pool[i].sco_conn);
4492+
bt_hfp_hf_pool[i].sco_conn = NULL;
4493+
}
4494+
}
4495+
}
4496+
4497+
static struct bt_sco_conn_cb hf_sco_conn_cb = {
4498+
.connected = hf_sco_connected,
4499+
.disconnected = hf_sco_disconnected
4500+
};
4501+
44774502
static void hfp_hf_init(void)
44784503
{
44794504
static struct bt_rfcomm_server chan = {
@@ -4491,6 +4516,8 @@ static void hfp_hf_init(void)
44914516
bt_sco_server_register(&sco_server);
44924517

44934518
bt_sdp_register_service(&hfp_rec);
4519+
4520+
bt_sco_conn_cb_register(&hf_sco_conn_cb);
44944521
}
44954522

44964523
int bt_hfp_hf_register(struct bt_hfp_hf_cb *cb)

0 commit comments

Comments
 (0)