Skip to content

Commit 781074c

Browse files
lylezhu2012kartben
authored andcommitted
Bluetooth: HFP_HF: Improve SCO accept
Find HF object according to conn object index directly. Signed-off-by: Lyle Zhu <[email protected]>
1 parent 3723ba1 commit 781074c

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

subsys/bluetooth/host/classic/hfp_hf.c

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4037,35 +4037,27 @@ static void hfp_hf_sco_disconnected(struct bt_sco_chan *chan, uint8_t reason)
40374037
static int bt_hfp_hf_sco_accept(const struct bt_sco_accept_info *info,
40384038
struct bt_sco_chan **chan)
40394039
{
4040-
int i;
40414040
static struct bt_sco_chan_ops ops = {
40424041
.connected = hfp_hf_sco_connected,
40434042
.disconnected = hfp_hf_sco_disconnected,
40444043
};
4044+
size_t index;
4045+
struct bt_hfp_hf *hf;
40454046

40464047
LOG_DBG("conn %p", info->acl);
40474048

4048-
for (i = 0; i < ARRAY_SIZE(bt_hfp_hf_pool); i++) {
4049-
struct bt_hfp_hf *hf = &bt_hfp_hf_pool[i];
4050-
4051-
if (NULL == hf->rfcomm_dlc.session) {
4052-
continue;
4053-
}
4054-
4055-
if (info->acl != hf->rfcomm_dlc.session->br_chan.chan.conn) {
4056-
continue;
4057-
}
4058-
4059-
hf->chan.ops = &ops;
4060-
4061-
*chan = &hf->chan;
4062-
4063-
return 0;
4049+
index = (size_t)bt_conn_index(info->acl);
4050+
hf = &bt_hfp_hf_pool[index];
4051+
if (hf->acl != info->acl) {
4052+
LOG_ERR("ACL %p of HF is unaligned with SCO's %p", hf->acl, info->acl);
4053+
return -EINVAL;
40644054
}
40654055

4066-
LOG_ERR("Unable to establish HF connection (%p)", info->acl);
4056+
hf->chan.ops = &ops;
40674057

4068-
return -ENOMEM;
4058+
*chan = &hf->chan;
4059+
4060+
return 0;
40694061
}
40704062

40714063
static void hfp_hf_init(void)

0 commit comments

Comments
 (0)