Skip to content

Commit 02171da

Browse files
iulia-tanasescuVudentz
authored andcommitted
Bluetooth: ISO: Add hcon for listening bis sk
This creates a hcon instance at bis listen, before the PA sync procedure is started. Signed-off-by: Iulia Tanasescu <[email protected]> Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 6e62ebf commit 02171da

File tree

3 files changed

+60
-19
lines changed

3 files changed

+60
-19
lines changed

include/net/bluetooth/hci_core.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
BlueZ - Bluetooth protocol stack for Linux
33
Copyright (c) 2000-2001, 2010, Code Aurora Forum. All rights reserved.
4-
Copyright 2023 NXP
4+
Copyright 2023-2024 NXP
55
66
Written 2000,2001 by Maxim Krasnyansky <[email protected]>
77
@@ -1528,8 +1528,8 @@ struct hci_conn *hci_connect_cis(struct hci_dev *hdev, bdaddr_t *dst,
15281528
struct hci_conn *hci_connect_bis(struct hci_dev *hdev, bdaddr_t *dst,
15291529
__u8 dst_type, struct bt_iso_qos *qos,
15301530
__u8 data_len, __u8 *data);
1531-
int hci_pa_create_sync(struct hci_dev *hdev, bdaddr_t *dst, __u8 dst_type,
1532-
__u8 sid, struct bt_iso_qos *qos);
1531+
struct hci_conn *hci_pa_create_sync(struct hci_dev *hdev, bdaddr_t *dst,
1532+
__u8 dst_type, __u8 sid, struct bt_iso_qos *qos);
15331533
int hci_le_big_create_sync(struct hci_dev *hdev, struct hci_conn *hcon,
15341534
struct bt_iso_qos *qos,
15351535
__u16 sync_handle, __u8 num_bis, __u8 bis[]);

net/bluetooth/hci_conn.c

+26-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
BlueZ - Bluetooth protocol stack for Linux
33
Copyright (c) 2000-2001, 2010, Code Aurora Forum. All rights reserved.
4-
Copyright 2023 NXP
4+
Copyright 2023-2024 NXP
55
66
Written 2000,2001 by Maxim Krasnyansky <[email protected]>
77
@@ -2057,18 +2057,31 @@ static int create_pa_sync(struct hci_dev *hdev, void *data)
20572057
return hci_update_passive_scan_sync(hdev);
20582058
}
20592059

2060-
int hci_pa_create_sync(struct hci_dev *hdev, bdaddr_t *dst, __u8 dst_type,
2061-
__u8 sid, struct bt_iso_qos *qos)
2060+
struct hci_conn *hci_pa_create_sync(struct hci_dev *hdev, bdaddr_t *dst,
2061+
__u8 dst_type, __u8 sid,
2062+
struct bt_iso_qos *qos)
20622063
{
20632064
struct hci_cp_le_pa_create_sync *cp;
2065+
struct hci_conn *conn;
2066+
int err;
20642067

20652068
if (hci_dev_test_and_set_flag(hdev, HCI_PA_SYNC))
2066-
return -EBUSY;
2069+
return ERR_PTR(-EBUSY);
2070+
2071+
conn = hci_conn_add_unset(hdev, ISO_LINK, dst, HCI_ROLE_SLAVE);
2072+
if (!conn)
2073+
return ERR_PTR(-ENOMEM);
2074+
2075+
conn->iso_qos = *qos;
2076+
conn->state = BT_LISTEN;
2077+
2078+
hci_conn_hold(conn);
20672079

20682080
cp = kzalloc(sizeof(*cp), GFP_KERNEL);
20692081
if (!cp) {
20702082
hci_dev_clear_flag(hdev, HCI_PA_SYNC);
2071-
return -ENOMEM;
2083+
hci_conn_drop(conn);
2084+
return ERR_PTR(-ENOMEM);
20722085
}
20732086

20742087
cp->options = qos->bcast.options;
@@ -2080,7 +2093,14 @@ int hci_pa_create_sync(struct hci_dev *hdev, bdaddr_t *dst, __u8 dst_type,
20802093
cp->sync_cte_type = qos->bcast.sync_cte_type;
20812094

20822095
/* Queue start pa_create_sync and scan */
2083-
return hci_cmd_sync_queue(hdev, create_pa_sync, cp, create_pa_complete);
2096+
err = hci_cmd_sync_queue(hdev, create_pa_sync, cp, create_pa_complete);
2097+
if (err < 0) {
2098+
hci_conn_drop(conn);
2099+
kfree(cp);
2100+
return ERR_PTR(err);
2101+
}
2102+
2103+
return conn;
20842104
}
20852105

20862106
int hci_le_big_create_sync(struct hci_dev *hdev, struct hci_conn *hcon,

net/bluetooth/iso.c

+31-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* BlueZ - Bluetooth protocol stack for Linux
44
*
55
* Copyright (C) 2022 Intel Corporation
6-
* Copyright 2023 NXP
6+
* Copyright 2023-2024 NXP
77
*/
88

99
#include <linux/module.h>
@@ -690,11 +690,8 @@ static void iso_sock_cleanup_listen(struct sock *parent)
690690
iso_sock_kill(sk);
691691
}
692692

693-
/* If listening socket stands for a PA sync connection,
694-
* properly disconnect the hcon and socket.
695-
*/
696-
if (iso_pi(parent)->conn && iso_pi(parent)->conn->hcon &&
697-
test_bit(HCI_CONN_PA_SYNC, &iso_pi(parent)->conn->hcon->flags)) {
693+
/* If listening socket has a hcon, properly disconnect it */
694+
if (iso_pi(parent)->conn && iso_pi(parent)->conn->hcon) {
698695
iso_sock_disconn(parent);
699696
return;
700697
}
@@ -1076,6 +1073,8 @@ static int iso_listen_bis(struct sock *sk)
10761073
{
10771074
struct hci_dev *hdev;
10781075
int err = 0;
1076+
struct iso_conn *conn;
1077+
struct hci_conn *hcon;
10791078

10801079
BT_DBG("%pMR -> %pMR (SID 0x%2.2x)", &iso_pi(sk)->src,
10811080
&iso_pi(sk)->dst, iso_pi(sk)->bc_sid);
@@ -1096,18 +1095,40 @@ static int iso_listen_bis(struct sock *sk)
10961095
if (!hdev)
10971096
return -EHOSTUNREACH;
10981097

1098+
hci_dev_lock(hdev);
1099+
10991100
/* Fail if user set invalid QoS */
11001101
if (iso_pi(sk)->qos_user_set && !check_bcast_qos(&iso_pi(sk)->qos)) {
11011102
iso_pi(sk)->qos = default_qos;
1102-
return -EINVAL;
1103+
err = -EINVAL;
1104+
goto unlock;
11031105
}
11041106

1105-
err = hci_pa_create_sync(hdev, &iso_pi(sk)->dst,
1106-
le_addr_type(iso_pi(sk)->dst_type),
1107-
iso_pi(sk)->bc_sid, &iso_pi(sk)->qos);
1107+
hcon = hci_pa_create_sync(hdev, &iso_pi(sk)->dst,
1108+
le_addr_type(iso_pi(sk)->dst_type),
1109+
iso_pi(sk)->bc_sid, &iso_pi(sk)->qos);
1110+
if (IS_ERR(hcon)) {
1111+
err = PTR_ERR(hcon);
1112+
goto unlock;
1113+
}
1114+
1115+
conn = iso_conn_add(hcon);
1116+
if (!conn) {
1117+
hci_conn_drop(hcon);
1118+
err = -ENOMEM;
1119+
goto unlock;
1120+
}
1121+
1122+
err = iso_chan_add(conn, sk, NULL);
1123+
if (err) {
1124+
hci_conn_drop(hcon);
1125+
goto unlock;
1126+
}
11081127

11091128
hci_dev_put(hdev);
11101129

1130+
unlock:
1131+
hci_dev_unlock(hdev);
11111132
return err;
11121133
}
11131134

0 commit comments

Comments
 (0)