Skip to contentSkip to conversation

Bluetooth: ISO: Notify user space about failed bis connections

PATCH Superseded Iulia Tanasescu 3 participants 6 messages Jun 28, 2023 – Jun 30, 2023

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Bluetooth: ISO: Notify user space about failed bis connections

This patch makes it possible for the user to be informed if BIG sync has failed.

There are situations when certain procedures must be started in this case, like it is, for example, when a BASS Server fails to synchronize to a Broadcast source, as a result of a BASS Client writing the Add Source opcode to the control point characteristic. The BASS server should be able to detect if the sync was unsuccessful and it should send an appropriate GATT notification to the BASS client.

Currently, only successful bis connections are notified to the user, using the listen and accept socket procedures. This patch proposes an implementation so that unsuccessful bis connections are also added in the accept list of a listening socket. The connection error is marked by setting the sk_err field and generating POLLERR on the child socket. This way, the user can detect if an incoming connection is successful or not.

From the previous patch version, the BT_BIG_SYNC_FAILED state has been replaced with the HCI_CONN_BIG_SYNC_FAILED flag.

The le_bis_cleanup work has also been removed, to avoid potential issues. Instead, failed bis connections are simply cleaned up by removing them from the hash list and calling the bis cleanup callback.

Iulia Tanasescu (1):
Bluetooth: ISO: Notify user space about failed bis connections

 include/net/bluetooth/hci_core.h | 25 ++++++++++++++++
 net/bluetooth/hci_conn.c         | 50 +++++++++++++++++---------------
 net/bluetooth/hci_event.c        | 21 +++++++++++---
 net/bluetooth/iso.c              | 37 ++++++++++++++++-------
 4 files changed, 95 insertions(+), 38 deletions(-)

base-commit: e63d8ed98082395ca509163f386f5b04f53872b3

Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/1 Bluetooth: ISO: Notify user space about failed bis connections

Some use cases require the user to be informed if BIG synchronization fails. This commit makes it so that even if the BIG sync established event arrives with error status, a new hconn is added for each BIS, and the iso layer is notified about the failed connections.

Unsuccesful bis connections will be marked using the HCI_CONN_BIG_SYNC_FAILED flag. From the iso layer, the POLLERR event is triggered on the newly allocated bis sockets, before adding them to the accept list of the parent socket.

From user space, a new fd for each failed bis connection will be obtained by calling accept. The user should check for the POLLERR event on the new socket, to determine if the connection was successful or not.

The HCI_CONN_BIG_SYNC flag has been added to mark whether the BIG sync has been successfully established. This flag is checked at bis cleanup, so the HCI LE BIG Terminate Sync command is only issued if needed.

The BT_SK_BIG_SYNC flag indicates if BIG create sync has been called for a listening socket, to avoid issuing the command everytime a BIGInfo advertising report is received.

---
 include/net/bluetooth/hci_core.h | 25 ++++++++++++++++
 net/bluetooth/hci_conn.c         | 50 +++++++++++++++++---------------
 net/bluetooth/hci_event.c        | 21 +++++++++++---
 net/bluetooth/iso.c              | 37 ++++++++++++++++-------
 4 files changed, 95 insertions(+), 38 deletions(-)
include/net/bluetooth/hci_core.h +25 -0
index 05a9b3ab3f56..f068a578ff59 100644
@@ -978,6 +978,8 @@ enum {
 	HCI_CONN_PER_ADV,
 	HCI_CONN_BIG_CREATED,
 	HCI_CONN_CREATE_CIS,
+	HCI_CONN_BIG_SYNC,
+	HCI_CONN_BIG_SYNC_FAILED,
 };
 
 static inline bool hci_conn_ssp_enabled(struct hci_conn *conn)
@@ -1288,6 +1290,29 @@ static inline struct hci_conn *hci_conn_hash_lookup_big(struct hci_dev *hdev,
 	return NULL;
 }
 
+static inline struct hci_conn *hci_conn_hash_lookup_big_any_dst(struct hci_dev *hdev,
+							__u8 handle)
+{
+	struct hci_conn_hash *h = &hdev->conn_hash;
+	struct hci_conn  *c;
+
+	rcu_read_lock();
+
+	list_for_each_entry_rcu(c, &h->list, list) {
+		if (c->type != ISO_LINK)
+			continue;
+
+		if (handle == c->iso_qos.bcast.big) {
+			rcu_read_unlock();
+			return c;
+		}
+	}
+
+	rcu_read_unlock();
+
+	return NULL;
+}
+
 static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev,
 							__u8 type, __u16 state)
 {
net/bluetooth/hci_conn.c +27 -23

95 lines not on this page · raw message

net/bluetooth/hci_event.c +17 -4
index 77cbf13037b3..30d0a6631e17 100644
@@ -7039,9 +7039,6 @@ static void hci_le_big_sync_established_evt(struct hci_dev *hdev, void *data,
 				flex_array_size(ev, bis, ev->num_bis)))
 		return;
 
-	if (ev->status)
-		return;
-
 	hci_dev_lock(hdev);
 
 	for (i = 0; i < ev->num_bis; i++) {
@@ -7065,9 +7062,25 @@ static void hci_le_big_sync_established_evt(struct hci_dev *hdev, void *data,
 		bis->iso_qos.bcast.in.latency = le16_to_cpu(ev->interval) * 125 / 100;
 		bis->iso_qos.bcast.in.sdu = le16_to_cpu(ev->max_pdu);
 
-		hci_iso_setup_path(bis);
+		if (!ev->status) {
+			set_bit(HCI_CONN_BIG_SYNC, &bis->flags);
+			hci_iso_setup_path(bis);
+		}
 	}
 
+	/* In case BIG sync failed, notify each failed connection to
+	 * the user after all hci connections have been added
+	 */
+	if (ev->status)
+		for (i = 0; i < ev->num_bis; i++) {
+			u16 handle = le16_to_cpu(ev->bis[i]);
+
+			bis = hci_conn_hash_lookup_handle(hdev, handle);
+
+			set_bit(HCI_CONN_BIG_SYNC_FAILED, &bis->flags);
+			hci_connect_cfm(bis, ev->status);
+		}
+
 	hci_dev_unlock(hdev);
 }
 
net/bluetooth/iso.c +26 -11
index 84d238d0639a..e0386b12ea4e 100644
@@ -48,6 +48,11 @@ static void iso_sock_kill(struct sock *sk);
 #define EIR_SERVICE_DATA_LENGTH 4
 #define BASE_MAX_LENGTH (HCI_MAX_PER_AD_LENGTH - EIR_SERVICE_DATA_LENGTH)
 
+/* iso_pinfo flags values */
+enum {
+	BT_SK_BIG_SYNC,
+};
+
 struct iso_pinfo {
 	struct bt_sock		bt;
 	bdaddr_t		src;
@@ -58,7 +63,7 @@ struct iso_pinfo {
 	__u8			bc_num_bis;
 	__u8			bc_bis[ISO_MAX_NUM_BIS];
 	__u16			sync_handle;
-	__u32			flags;
+	unsigned long		flags;
 	struct bt_iso_qos	qos;
 	bool			qos_user_set;
 	__u8			base_len;
@@ -1569,6 +1574,12 @@ static void iso_conn_ready(struct iso_conn *conn)
 		hci_conn_hold(hcon);
 		iso_chan_add(conn, sk, parent);
 
+		if (ev && ((struct hci_evt_le_big_sync_estabilished *)ev)->status) {
+			/* Trigger error signal on child socket */
+			sk->sk_err = ECONNREFUSED;
+			sk->sk_error_report(sk);
+		}
+
 		if (test_bit(BT_SK_DEFER_SETUP, &bt_sk(parent)->flags))
 			sk->sk_state = BT_CONNECT2;
 		else
@@ -1637,15 +1648,19 @@ int iso_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags)
 			if (ev2->num_bis < iso_pi(sk)->bc_num_bis)
 				iso_pi(sk)->bc_num_bis = ev2->num_bis;
 
-			err = hci_le_big_create_sync(hdev,
-						     &iso_pi(sk)->qos,
-						     iso_pi(sk)->sync_handle,
-						     iso_pi(sk)->bc_num_bis,
-						     iso_pi(sk)->bc_bis);
-			if (err) {
-				bt_dev_err(hdev, "hci_le_big_create_sync: %d",
-					   err);
-				sk = NULL;
+			if (!test_bit(BT_SK_BIG_SYNC, &iso_pi(sk)->flags)) {
+				set_bit(BT_SK_BIG_SYNC, &iso_pi(sk)->flags);
+
+				err = hci_le_big_create_sync(hdev,
+							     &iso_pi(sk)->qos,
+							     iso_pi(sk)->sync_handle,
+							     iso_pi(sk)->bc_num_bis,
+							     iso_pi(sk)->bc_bis);
+				if (err) {
+					bt_dev_err(hdev, "hci_le_big_create_sync: %d",
+						   err);
+					sk = NULL;
+				}
 			}
 		}
 	} else {
@@ -1688,7 +1703,7 @@ static void iso_connect_cfm(struct hci_conn *hcon, __u8 status)
 
 	BT_DBG("hcon %p bdaddr %pMR status %d", hcon, &hcon->dst, status);
 
-	if (!status) {
+	if (!status || test_bit(HCI_CONN_BIG_SYNC_FAILED, &hcon->flags)) {
 		struct iso_conn *conn;
 
 		conn = iso_conn_add(hcon);
Signature · 1 line
2.34.1
#2 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=760969

---Test result---

Test Summary:

CheckPatch                    PASS      1.21 seconds
GitLint                       PASS      0.32 seconds
SubjectPrefix                 PASS      0.10 seconds
BuildKernel                   PASS      32.73 seconds
CheckAllWarning               PASS      35.07 seconds
CheckSparse                   WARNING   40.47 seconds
CheckSmatch                   WARNING   112.29 seconds
BuildKernel32                 PASS      31.48 seconds
TestRunnerSetup               PASS      442.17 seconds
TestRunner_l2cap-tester       PASS      16.56 seconds
TestRunner_iso-tester         PASS      22.42 seconds
TestRunner_bnep-tester        PASS      5.25 seconds
TestRunner_mgmt-tester        PASS      126.41 seconds
TestRunner_rfcomm-tester      PASS      8.51 seconds
TestRunner_sco-tester         PASS      7.83 seconds
TestRunner_ioctl-tester       PASS      9.02 seconds
TestRunner_mesh-tester        PASS      6.71 seconds
TestRunner_smp-tester         PASS      7.78 seconds
TestRunner_userchan-tester    PASS      5.50 seconds
IncrementalBuild              PASS      29.58 seconds

Details
##############################
Test: CheckSparse - WARNING
Desc: Run sparse tool with linux kernel
Output:
net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):
##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:
net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):

---
Regards,
Linux Bluetooth

#3 lore raw
In reply to Iulia Tanasescu

Hi Iulia,

Quoted 85 lines · Iulia Tanasescu

Some use cases require the user to be informed if BIG synchronization fails. This commit makes it so that even if the BIG sync established event arrives with error status, a new hconn is added for each BIS, and the iso layer is notified about the failed connections.

Unsuccesful bis connections will be marked using the HCI_CONN_BIG_SYNC_FAILED flag. From the iso layer, the POLLERR event is triggered on the newly allocated bis sockets, before adding them to the accept list of the parent socket.

From user space, a new fd for each failed bis connection will be obtained by calling accept. The user should check for the POLLERR event on the new socket, to determine if the connection was successful or not.

The HCI_CONN_BIG_SYNC flag has been added to mark whether the BIG sync has been successfully established. This flag is checked at bis cleanup, so the HCI LE BIG Terminate Sync command is only issued if needed.

The BT_SK_BIG_SYNC flag indicates if BIG create sync has been called for a listening socket, to avoid issuing the command everytime a BIGInfo advertising report is received.

---
 include/net/bluetooth/hci_core.h | 25 ++++++++++++++++
 net/bluetooth/hci_conn.c         | 50 +++++++++++++++++---------------
 net/bluetooth/hci_event.c        | 21 +++++++++++---
 net/bluetooth/iso.c              | 37 ++++++++++++++++-------
 4 files changed, 95 insertions(+), 38 deletions(-)
include/net/bluetooth/hci_core.h +25 -0
index 05a9b3ab3f56..f068a578ff59 100644
@@ -978,6 +978,8 @@ enum {
        HCI_CONN_PER_ADV,
        HCI_CONN_BIG_CREATED,
        HCI_CONN_CREATE_CIS,
+       HCI_CONN_BIG_SYNC,
+       HCI_CONN_BIG_SYNC_FAILED,
 };
 
 static inline bool hci_conn_ssp_enabled(struct hci_conn *conn)
@@ -1288,6 +1290,29 @@ static inline struct hci_conn *hci_conn_hash_lookup_big(struct hci_dev *hdev,
        return NULL;
 }
 
+static inline struct hci_conn *hci_conn_hash_lookup_big_any_dst(struct hci_dev *hdev,
+                                                       __u8 handle)
+{
+       struct hci_conn_hash *h = &hdev->conn_hash;
+       struct hci_conn  *c;
+
+       rcu_read_lock();
+
+       list_for_each_entry_rcu(c, &h->list, list) {
+               if (c->type != ISO_LINK)
+                       continue;
+
+               if (handle == c->iso_qos.bcast.big) {
+                       rcu_read_unlock();
+                       return c;
+               }
+       }
+
+       rcu_read_unlock();
+
+       return NULL;
+}
+
 static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev,
                                                        __u8 type, __u16 state)
 {
net/bluetooth/hci_conn.c +2 -0
index 47e7aa4d63a9..491ca8e876f0 100644
@@ -686,6 +686,19 @@ static void hci_conn_timeout(struct work_struct *work)
                return;
        }
 
+       /* Cleanup bises that failed to be established */
+       if (test_and_clear_bit(HCI_CONN_BIG_SYNC_FAILED, &conn->flags)) {

net/bluetooth/hci_conn.c static void hci_conn_timeout(struct work_struct *work) · line 700

Quoted 10 lines
net/bluetooth/hci_conn.c +10 -0
+               conn->state = BT_CLOSED;
+               hci_disconn_cfm(conn, hci_proto_disconn_ind(conn));
+               hci_conn_hash_del(conn->hdev, conn);
+
+               if (conn->cleanup)
+                       conn->cleanup(conn);
+
+               hci_conn_put(conn);
+               return;
+       }

I will be pushing some changes to how hci_abort_conn works, the code above shall probably be done inside the likes of hci_conn_failed though but first we need to add support for BIS into hci_abort_conn_sync.

Quoted 167 lines
net/bluetooth/hci_conn.c +14 -23
        hci_abort_conn(conn, hci_proto_disconn_ind(conn));
 }
 
@@ -793,6 +806,7 @@ struct iso_list_data {
        int count;
        struct iso_cig_params pdu;
        bool big_term;
+       bool big_sync_term;
 };
 
 static void bis_list(struct hci_conn *conn, void *data)
@@ -810,17 +824,6 @@ static void bis_list(struct hci_conn *conn, void *data)
        d->count++;
 }
 
-static void find_bis(struct hci_conn *conn, void *data)
-{
-       struct iso_list_data *d = data;
-
-       /* Ignore unicast */
-       if (bacmp(&conn->dst, BDADDR_ANY))
-               return;
-
-       d->count++;
-}
-
 static int terminate_big_sync(struct hci_dev *hdev, void *data)
 {
        struct iso_list_data *d = data;
@@ -873,31 +876,26 @@ static int big_terminate_sync(struct hci_dev *hdev, void *data)
        bt_dev_dbg(hdev, "big 0x%2.2x sync_handle 0x%4.4x", d->big,
                   d->sync_handle);
 
-       /* Check if ISO connection is a BIS and terminate BIG if there are
-        * no other connections using it.
-        */
-       hci_conn_hash_list_state(hdev, find_bis, ISO_LINK, BT_CONNECTED, d);
-       if (d->count)
-               return 0;
-
-       hci_le_big_terminate_sync(hdev, d->big);
+       if (d->big_sync_term)
+               hci_le_big_terminate_sync(hdev, d->big);
 
        return hci_le_pa_terminate_sync(hdev, d->sync_handle);
 }
 
-static int hci_le_big_terminate(struct hci_dev *hdev, u8 big, u16 sync_handle)
+static int hci_le_big_terminate(struct hci_dev *hdev, u8 big, struct hci_conn *conn)
 {
        struct iso_list_data *d;
        int ret;
 
-       bt_dev_dbg(hdev, "big 0x%2.2x sync_handle 0x%4.4x", big, sync_handle);
+       bt_dev_dbg(hdev, "big 0x%2.2x sync_handle 0x%4.4x", big, conn->sync_handle);
 
        d = kzalloc(sizeof(*d), GFP_KERNEL);
        if (!d)
                return -ENOMEM;
 
        d->big = big;
-       d->sync_handle = sync_handle;
+       d->sync_handle = conn->sync_handle;
+       d->big_sync_term = test_and_clear_bit(HCI_CONN_BIG_SYNC, &conn->flags);
 
        ret = hci_cmd_sync_queue(hdev, big_terminate_sync, d,
                                 terminate_big_destroy);
@@ -933,8 +931,14 @@ static void bis_cleanup(struct hci_conn *conn)
 
                hci_le_terminate_big(hdev, conn);
        } else {
+               bis = hci_conn_hash_lookup_big_any_dst(hdev,
+                                                      conn->iso_qos.bcast.big);
+
+               if (bis)
+                       return;
+
                hci_le_big_terminate(hdev, conn->iso_qos.bcast.big,
-                                    conn->sync_handle);
+                                    conn);
        }
 }
 
net/bluetooth/hci_event.c +17 -4
index 77cbf13037b3..30d0a6631e17 100644
@@ -7039,9 +7039,6 @@ static void hci_le_big_sync_established_evt(struct hci_dev *hdev, void *data,
                                flex_array_size(ev, bis, ev->num_bis)))
                return;
 
-       if (ev->status)
-               return;
-
        hci_dev_lock(hdev);
 
        for (i = 0; i < ev->num_bis; i++) {
@@ -7065,9 +7062,25 @@ static void hci_le_big_sync_established_evt(struct hci_dev *hdev, void *data,
                bis->iso_qos.bcast.in.latency = le16_to_cpu(ev->interval) * 125 / 100;
                bis->iso_qos.bcast.in.sdu = le16_to_cpu(ev->max_pdu);
 
-               hci_iso_setup_path(bis);
+               if (!ev->status) {
+                       set_bit(HCI_CONN_BIG_SYNC, &bis->flags);
+                       hci_iso_setup_path(bis);
+               }
        }
 
+       /* In case BIG sync failed, notify each failed connection to
+        * the user after all hci connections have been added
+        */
+       if (ev->status)
+               for (i = 0; i < ev->num_bis; i++) {
+                       u16 handle = le16_to_cpu(ev->bis[i]);
+
+                       bis = hci_conn_hash_lookup_handle(hdev, handle);
+
+                       set_bit(HCI_CONN_BIG_SYNC_FAILED, &bis->flags);
+                       hci_connect_cfm(bis, ev->status);
+               }
+
        hci_dev_unlock(hdev);
 }
 
net/bluetooth/iso.c +12 -2
index 84d238d0639a..e0386b12ea4e 100644
@@ -48,6 +48,11 @@ static void iso_sock_kill(struct sock *sk);
 #define EIR_SERVICE_DATA_LENGTH 4
 #define BASE_MAX_LENGTH (HCI_MAX_PER_AD_LENGTH - EIR_SERVICE_DATA_LENGTH)
 
+/* iso_pinfo flags values */
+enum {
+       BT_SK_BIG_SYNC,
+};
+
 struct iso_pinfo {
        struct bt_sock          bt;
        bdaddr_t                src;
@@ -58,7 +63,7 @@ struct iso_pinfo {
        __u8                    bc_num_bis;
        __u8                    bc_bis[ISO_MAX_NUM_BIS];
        __u16                   sync_handle;
-       __u32                   flags;
+       unsigned long           flags;
        struct bt_iso_qos       qos;
        bool                    qos_user_set;
        __u8                    base_len;
@@ -1569,6 +1574,12 @@ static void iso_conn_ready(struct iso_conn *conn)
                hci_conn_hold(hcon);
                iso_chan_add(conn, sk, parent);
 
+               if (ev && ((struct hci_evt_le_big_sync_estabilished *)ev)->status) {
+                       /* Trigger error signal on child socket */
+                       sk->sk_err = ECONNREFUSED;
+                       sk->sk_error_report(sk);
+               }
+
                if (test_bit(BT_SK_DEFER_SETUP, &bt_sk(parent)->flags))
                        sk->sk_state = BT_CONNECT2;
                else
@@ -1637,15 +1648,19 @@ int iso_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags)
                        if (ev2->num_bis < iso_pi(sk)->bc_num_bis)
                                iso_pi(sk)->bc_num_bis = ev2->num_bis;
 
-                       err = hci_le_big_create_sync(hdev,

net/bluetooth/iso.c int iso_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags) · line 1652

Quoted 10 lines
net/bluetooth/iso.c +2 -8
-                                                    &iso_pi(sk)->qos,
-                                                    iso_pi(sk)->sync_handle,
-                                                    iso_pi(sk)->bc_num_bis,
-                                                    iso_pi(sk)->bc_bis);
-                       if (err) {
-                               bt_dev_err(hdev, "hci_le_big_create_sync: %d",
-                                          err);
-                               sk = NULL;
+                       if (!test_bit(BT_SK_BIG_SYNC, &iso_pi(sk)->flags)) {
+                               set_bit(BT_SK_BIG_SYNC, &iso_pi(sk)->flags);

You can probably use test_and_set_bit instead above.

Quoted 15 lines
net/bluetooth/iso.c +11 -0
+
+                               err = hci_le_big_create_sync(hdev,
+                                                            &iso_pi(sk)->qos,
+                                                            iso_pi(sk)->sync_handle,
+                                                            iso_pi(sk)->bc_num_bis,
+                                                            iso_pi(sk)->bc_bis);
+                               if (err) {
+                                       bt_dev_err(hdev, "hci_le_big_create_sync: %d",
+                                                  err);
+                                       sk = NULL;
+                               }
                        }
                }
        } else {

net/bluetooth/iso.c static void iso_connect_cfm(struct hci_conn *hcon, __u8 status) · line 1706

Quoted 5 lines
net/bluetooth/iso.c +1 -1
@@ -1688,7 +1703,7 @@ static void iso_connect_cfm(struct hci_conn *hcon, __u8 status)
 
        BT_DBG("hcon %p bdaddr %pMR status %d", hcon, &hcon->dst, status);
 
-       if (!status) {
+       if (!status || test_bit(HCI_CONN_BIG_SYNC_FAILED, &hcon->flags)) {

Shouldn't it be !test_bit above?

Quoted 6 lines
net/bluetooth/iso.c +0 -1
                struct iso_conn *conn;
 
                conn = iso_conn_add(hcon);
--

2.34.1

Signature · 1 line
Luiz Augusto von Dentz
#4 lore raw

Hi Luiz,

Quoted 104 lines

-----Original Message-----
From: Luiz Augusto von Dentz <[email protected]>
Sent: Thursday, June 29, 2023 9:58 PM
To: Iulia Tanasescu <[email protected]>
Cc: [email protected]; Claudia Cristina Draghicescu <[email protected]>; Mihai-Octavian Urzica <mihai- [email protected]>; Silviu Florian Barbulescu <[email protected]>; Vlad Pruteanu <[email protected]>; Andrei Istodorescu <[email protected]>
Subject: Re: [PATCH v2 1/1] Bluetooth: ISO: Notify user space about failed bis connections

Hi Iulia,

Quoted 11 lines · Iulia Tanasescu

Some use cases require the user to be informed if BIG synchronization fails. This commit makes it so that even if the BIG sync established event arrives with error status, a new hconn is added for each BIS, and the iso layer is notified about the failed connections.

Unsuccesful bis connections will be marked using the HCI_CONN_BIG_SYNC_FAILED flag. From the iso layer, the POLLERR event is triggered on the newly allocated bis sockets, before adding them to the accept list of the parent socket.

Quoted 6 lines

From user space, a new fd for each failed bis connection will be obtained by calling accept. The user should check for the POLLERR event on the new socket, to determine if the connection was successful or not.

The HCI_CONN_BIG_SYNC flag has been added to mark whether the BIG

sync

Quoted 2 lines

has been successfully established. This flag is checked at bis cleanup, so the HCI LE BIG Terminate Sync command is only issued if

needed.

Quoted 19 lines

The BT_SK_BIG_SYNC flag indicates if BIG create sync has been called for a listening socket, to avoid issuing the command everytime a BIGInfo advertising report is received.

---
 include/net/bluetooth/hci_core.h | 25 ++++++++++++++++
 net/bluetooth/hci_conn.c         | 50 +++++++++++++++++---------------
 net/bluetooth/hci_event.c        | 21 +++++++++++---
 net/bluetooth/iso.c              | 37 ++++++++++++++++-------
 4 files changed, 95 insertions(+), 38 deletions(-)
include/net/bluetooth/hci_core.h +0 -0
index 05a9b3ab3f56..f068a578ff59 100644

include/net/bluetooth/hci_core.h enum {

Quoted 9 lines
include/net/bluetooth/hci_core.h +2 -1
@@ -978,6 +978,8 @@ enum {
        HCI_CONN_PER_ADV,
        HCI_CONN_BIG_CREATED,
        HCI_CONN_CREATE_CIS,
+       HCI_CONN_BIG_SYNC,
+       HCI_CONN_BIG_SYNC_FAILED,
 };
 
 static inline bool hci_conn_ssp_enabled(struct hci_conn *conn) @@
-1288,6 +1290,29 @@ static inline struct hci_conn

*hci_conn_hash_lookup_big(struct hci_dev *hdev,

Quoted 4 lines
        return NULL;

}

+static inline struct hci_conn *hci_conn_hash_lookup_big_any_dst(struct

hci_dev *hdev,

Quoted 12 lines
include/net/bluetooth/hci_core.h +12 -0
+                                                       __u8 handle) {
+       struct hci_conn_hash *h = &hdev->conn_hash;
+       struct hci_conn  *c;
+
+       rcu_read_lock();
+
+       list_for_each_entry_rcu(c, &h->list, list) {
+               if (c->type != ISO_LINK)
+                       continue;
+
+               if (handle == c->iso_qos.bcast.big) {
+                       rcu_read_unlock();

include/net/bluetooth/hci_core.h static inline struct hci_conn *hci_conn_hash_lookup_big(struct hci_dev *hdev,

Quoted 10 lines
include/net/bluetooth/hci_core.h +9 -0
+                       return c;
+               }
+       }
+
+       rcu_read_unlock();
+
+       return NULL;
+}
+
 static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev

*hdev,

net/bluetooth/hci_conn.c static void hci_conn_timeout(struct work_struct

Quoted 6 lines
                                                        __u8 type,

__u16 state) { diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 47e7aa4d63a9..491ca8e876f0 100644

net/bluetooth/hci_conn.c +0 -0
@@ -686,6 +686,19 @@ static void hci_conn_timeout(struct work_struct

*work)

Quoted 3 lines
net/bluetooth/hci_conn.c +0 -0
                return;
        }
 
Quoted 16 lines

net/bluetooth/hci_conn.c static void hci_conn_timeout(struct work_struct *work) · line 700

Quoted 12 lines
net/bluetooth/hci_conn.c +12 -0
+       /* Cleanup bises that failed to be established */
+       if (test_and_clear_bit(HCI_CONN_BIG_SYNC_FAILED, &conn->flags)) {
+               conn->state = BT_CLOSED;
+               hci_disconn_cfm(conn, hci_proto_disconn_ind(conn));
+               hci_conn_hash_del(conn->hdev, conn);
+
+               if (conn->cleanup)
+                       conn->cleanup(conn);
+
+               hci_conn_put(conn);
+               return;
+       }

I will be pushing some changes to how hci_abort_conn works, the code above shall probably be done inside the likes of hci_conn_failed though but first we need to add support for BIS into hci_abort_conn_sync.

Thank you, I submitted a new patch version with these updates.

Quoted 190 lines
Quoted 31 lines
net/bluetooth/hci_conn.c +2 -10
        hci_abort_conn(conn, hci_proto_disconn_ind(conn));  }
 
@@ -793,6 +806,7 @@ struct iso_list_data {
        int count;
        struct iso_cig_params pdu;
        bool big_term;
+       bool big_sync_term;
 };
 
 static void bis_list(struct hci_conn *conn, void *data) @@ -810,17
+824,6 @@ static void bis_list(struct hci_conn *conn, void *data)
        d->count++;
 }
 
-static void find_bis(struct hci_conn *conn, void *data) -{
-       struct iso_list_data *d = data;
-
-       /* Ignore unicast */
-       if (bacmp(&conn->dst, BDADDR_ANY))
-               return;
-
-       d->count++;
-}
-
 static int terminate_big_sync(struct hci_dev *hdev, void *data)  {
        struct iso_list_data *d = data; @@ -873,31 +876,26 @@ static

int big_terminate_sync(struct hci_dev *hdev, void *data)

        bt_dev_dbg(hdev, "big 0x%2.2x sync_handle 0x%4.4x", d->big,
                   d->sync_handle);

net/bluetooth/hci_conn.c static int big_terminate_sync(struct hci_dev *hdev, void *data)

Quoted 4 lines
net/bluetooth/hci_conn.c +0 -4
-       /* Check if ISO connection is a BIS and terminate BIG if there are
-        * no other connections using it.
-        */
-       hci_conn_hash_list_state(hdev, find_bis, ISO_LINK, BT_CONNECTED,

d);

Quoted 11 lines
net/bluetooth/hci_conn.c +2 -5
-       if (d->count)
-               return 0;
-
-       hci_le_big_terminate_sync(hdev, d->big);
+       if (d->big_sync_term)
+               hci_le_big_terminate_sync(hdev, d->big);
 
        return hci_le_pa_terminate_sync(hdev, d->sync_handle);  }
 
-static int hci_le_big_terminate(struct hci_dev *hdev, u8 big, u16

sync_handle)

net/bluetooth/hci_conn.c static int big_terminate_sync(struct hci_dev *hdev, void *data)

Quoted 7 lines
net/bluetooth/hci_conn.c +2 -1
+static int hci_le_big_terminate(struct hci_dev *hdev, u8 big, struct
+hci_conn *conn)
 {
        struct iso_list_data *d;
        int ret;
 
-       bt_dev_dbg(hdev, "big 0x%2.2x sync_handle 0x%4.4x", big,

sync_handle);

net/bluetooth/hci_event.c static void

Quoted 37 lines
net/bluetooth/hci_conn.c +14 -2
+       bt_dev_dbg(hdev, "big 0x%2.2x sync_handle 0x%4.4x", big,
+ conn->sync_handle);
 
        d = kzalloc(sizeof(*d), GFP_KERNEL);
        if (!d)
                return -ENOMEM;
 
        d->big = big;
-       d->sync_handle = sync_handle;
+       d->sync_handle = conn->sync_handle;
+       d->big_sync_term = test_and_clear_bit(HCI_CONN_BIG_SYNC,
+ &conn->flags);
 
        ret = hci_cmd_sync_queue(hdev, big_terminate_sync, d,
                                 terminate_big_destroy); @@ -933,8
+931,14 @@ static void bis_cleanup(struct hci_conn *conn)
 
                hci_le_terminate_big(hdev, conn);
        } else {
+               bis = hci_conn_hash_lookup_big_any_dst(hdev,
+
+ conn->iso_qos.bcast.big);
+
+               if (bis)
+                       return;
+
                hci_le_big_terminate(hdev, conn->iso_qos.bcast.big,
-                                    conn->sync_handle);
+                                    conn);
        }
 }
net/bluetooth/hci_event.c +0 -0
index 77cbf13037b3..30d0a6631e17 100644
@@ -7039,9 +7039,6 @@ static void

hci_le_big_sync_established_evt(struct hci_dev *hdev, void *data,

Quoted 10 lines
net/bluetooth/hci_event.c +0 -3
                                flex_array_size(ev, bis, ev->num_bis)))
                return;
 
-       if (ev->status)
-               return;
-
        hci_dev_lock(hdev);
 
        for (i = 0; i < ev->num_bis; i++) { @@ -7065,9 +7062,25 @@

static void hci_le_big_sync_established_evt(struct hci_dev *hdev, void

*data,

Quoted 1 line
                bis->iso_qos.bcast.in.latency = le16_to_cpu(ev->interval) * 125 /

100;

net/bluetooth/iso.c static void iso_conn_ready(struct iso_conn

Quoted 52 lines
                bis->iso_qos.bcast.in.sdu = le16_to_cpu(ev->max_pdu);
net/bluetooth/hci_event.c +18 -1
-               hci_iso_setup_path(bis);
+               if (!ev->status) {
+                       set_bit(HCI_CONN_BIG_SYNC, &bis->flags);
+                       hci_iso_setup_path(bis);
+               }
        }
 
+       /* In case BIG sync failed, notify each failed connection to
+        * the user after all hci connections have been added
+        */
+       if (ev->status)
+               for (i = 0; i < ev->num_bis; i++) {
+                       u16 handle = le16_to_cpu(ev->bis[i]);
+
+                       bis = hci_conn_hash_lookup_handle(hdev,
+ handle);
+
+                       set_bit(HCI_CONN_BIG_SYNC_FAILED, &bis->flags);
+                       hci_connect_cfm(bis, ev->status);
+               }
+
        hci_dev_unlock(hdev);
 }
net/bluetooth/iso.c index renamed from net/bluetooth/iso.c +0 -0

84d238d0639a..e0386b12ea4e 100644

net/bluetooth/iso.c +6 -1
@@ -48,6 +48,11 @@ static void iso_sock_kill(struct sock *sk);
 #define EIR_SERVICE_DATA_LENGTH 4  #define BASE_MAX_LENGTH
 (HCI_MAX_PER_AD_LENGTH - EIR_SERVICE_DATA_LENGTH)
 
+/* iso_pinfo flags values */
+enum {
+       BT_SK_BIG_SYNC,
+};
+
 struct iso_pinfo {
        struct bt_sock          bt;
        bdaddr_t                src;
@@ -58,7 +63,7 @@ struct iso_pinfo {
        __u8                    bc_num_bis;
        __u8                    bc_bis[ISO_MAX_NUM_BIS];
        __u16                   sync_handle;
-       __u32                   flags;
+       unsigned long           flags;
        struct bt_iso_qos       qos;
        bool                    qos_user_set;
        __u8                    base_len;
@@ -1569,6 +1574,12 @@ static void iso_conn_ready(struct iso_conn

*conn)

net/bluetooth/iso.c static void iso_conn_ready(struct iso_conn *conn)

Quoted 4 lines
net/bluetooth/iso.c +1 -0
                hci_conn_hold(hcon);
                iso_chan_add(conn, sk, parent);
 
+               if (ev && ((struct hci_evt_le_big_sync_estabilished *)ev)->status)

{

net/bluetooth/iso.c int iso_connect_ind(struct hci_dev *hdev,

Quoted 9 lines
net/bluetooth/iso.c +5 -0
+                       /* Trigger error signal on child socket */
+                       sk->sk_err = ECONNREFUSED;
+                       sk->sk_error_report(sk);
+               }
+
                if (test_bit(BT_SK_DEFER_SETUP, &bt_sk(parent)->flags))
                        sk->sk_state = BT_CONNECT2;
                else
@@ -1637,15 +1648,19 @@ int iso_connect_ind(struct hci_dev *hdev,

bdaddr_t *bdaddr, __u8 *flags)

Quoted 5 lines
net/bluetooth/iso.c +0 -2
                        if (ev2->num_bis < iso_pi(sk)->bc_num_bis)
                                iso_pi(sk)->bc_num_bis = ev2->num_bis;
 
-                       err = hci_le_big_create_sync(hdev,
-                                                    &iso_pi(sk)->qos,

net/bluetooth/iso.c int iso_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags)

Quoted 10 lines
net/bluetooth/iso.c +3 -7
-                                                    iso_pi(sk)->sync_handle,
-                                                    iso_pi(sk)->bc_num_bis,
-                                                    iso_pi(sk)->bc_bis);
-                       if (err) {
-                               bt_dev_err(hdev, "hci_le_big_create_sync: %d",
-                                          err);
-                               sk = NULL;
+                       if (!test_bit(BT_SK_BIG_SYNC, &iso_pi(sk)->flags)) {
+                               set_bit(BT_SK_BIG_SYNC,
+ &iso_pi(sk)->flags);
Quoted 1 line

You can probably use test_and_set_bit instead above.

I updated this as well.

Quoted 18 lines
Quoted 18 lines
net/bluetooth/iso.c +11 -0
+
+                               err = hci_le_big_create_sync(hdev,
+                                                            &iso_pi(sk)->qos,
+                                                            iso_pi(sk)->sync_handle,
+                                                            iso_pi(sk)->bc_num_bis,
+                                                            iso_pi(sk)->bc_bis);
+                               if (err) {
+                                       bt_dev_err(hdev, "hci_le_big_create_sync: %d",
+                                                  err);
+                                       sk = NULL;
+                               }
                        }
                }
        } else {
@@ -1688,7 +1703,7 @@ static void iso_connect_cfm(struct hci_conn
 *hcon, __u8 status)
 
Quoted 8 lines

net/bluetooth/iso.c static void iso_connect_cfm(struct hci_conn · line 1709

Quoted 6 lines
net/bluetooth/iso.c +2 -1
        BT_DBG("hcon %p bdaddr %pMR status %d", hcon, &hcon->dst,
 status);
 
-       if (!status) {
+       if (!status || test_bit(HCI_CONN_BIG_SYNC_FAILED,
+ &hcon->flags)) {

Shouldn't it be !test_bit above?

Here, if HCI_CONN_BIG_SYNC_FAILED is set, I want to reach iso_conn_ready, like it would be for the success case, so the failed bis connection will be added in the accept queue of the listening socket and it will be woken up in userspace, so the check should be positive.

Quoted 11 lines
Quoted 7 lines
                struct iso_conn *conn;

                conn = iso_conn_add(hcon);

--
2.34.1

--
Luiz Augusto von Dentz

Regards,
Iulia

#5 lore raw

Hi Iulia,

Quoted 347 lines · Iulia Tanasescu

Hi Luiz,

Quoted 104 lines

-----Original Message-----
From: Luiz Augusto von Dentz <[email protected]>
Sent: Thursday, June 29, 2023 9:58 PM
To: Iulia Tanasescu <[email protected]>
Cc: [email protected]; Claudia Cristina Draghicescu <[email protected]>; Mihai-Octavian Urzica <mihai- [email protected]>; Silviu Florian Barbulescu <[email protected]>; Vlad Pruteanu <[email protected]>; Andrei Istodorescu <[email protected]>
Subject: Re: [PATCH v2 1/1] Bluetooth: ISO: Notify user space about failed bis connections

Hi Iulia,

Quoted 11 lines · Iulia Tanasescu

Some use cases require the user to be informed if BIG synchronization fails. This commit makes it so that even if the BIG sync established event arrives with error status, a new hconn is added for each BIS, and the iso layer is notified about the failed connections.

Unsuccesful bis connections will be marked using the HCI_CONN_BIG_SYNC_FAILED flag. From the iso layer, the POLLERR event is triggered on the newly allocated bis sockets, before adding them to the accept list of the parent socket.

Quoted 6 lines

From user space, a new fd for each failed bis connection will be obtained by calling accept. The user should check for the POLLERR event on the new socket, to determine if the connection was successful or not.

The HCI_CONN_BIG_SYNC flag has been added to mark whether the BIG

sync

Quoted 2 lines

has been successfully established. This flag is checked at bis cleanup, so the HCI LE BIG Terminate Sync command is only issued if

needed.

Quoted 19 lines

The BT_SK_BIG_SYNC flag indicates if BIG create sync has been called for a listening socket, to avoid issuing the command everytime a BIGInfo advertising report is received.

---
 include/net/bluetooth/hci_core.h | 25 ++++++++++++++++
 net/bluetooth/hci_conn.c         | 50 +++++++++++++++++---------------
 net/bluetooth/hci_event.c        | 21 +++++++++++---
 net/bluetooth/iso.c              | 37 ++++++++++++++++-------
 4 files changed, 95 insertions(+), 38 deletions(-)
include/net/bluetooth/hci_core.h +0 -0
index 05a9b3ab3f56..f068a578ff59 100644

include/net/bluetooth/hci_core.h enum {

Quoted 9 lines
include/net/bluetooth/hci_core.h +2 -1
@@ -978,6 +978,8 @@ enum {
        HCI_CONN_PER_ADV,
        HCI_CONN_BIG_CREATED,
        HCI_CONN_CREATE_CIS,
+       HCI_CONN_BIG_SYNC,
+       HCI_CONN_BIG_SYNC_FAILED,
 };
 
 static inline bool hci_conn_ssp_enabled(struct hci_conn *conn) @@
-1288,6 +1290,29 @@ static inline struct hci_conn

*hci_conn_hash_lookup_big(struct hci_dev *hdev,

Quoted 4 lines
        return NULL;

}

+static inline struct hci_conn *hci_conn_hash_lookup_big_any_dst(struct

hci_dev *hdev,

Quoted 12 lines
include/net/bluetooth/hci_core.h +12 -0
+                                                       __u8 handle) {
+       struct hci_conn_hash *h = &hdev->conn_hash;
+       struct hci_conn  *c;
+
+       rcu_read_lock();
+
+       list_for_each_entry_rcu(c, &h->list, list) {
+               if (c->type != ISO_LINK)
+                       continue;
+
+               if (handle == c->iso_qos.bcast.big) {
+                       rcu_read_unlock();

include/net/bluetooth/hci_core.h static inline struct hci_conn *hci_conn_hash_lookup_big(struct hci_dev *hdev,

Quoted 10 lines
include/net/bluetooth/hci_core.h +9 -0
+                       return c;
+               }
+       }
+
+       rcu_read_unlock();
+
+       return NULL;
+}
+
 static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev

*hdev,

net/bluetooth/hci_conn.c static void hci_conn_timeout(struct work_struct

Quoted 6 lines
                                                        __u8 type,

__u16 state) { diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 47e7aa4d63a9..491ca8e876f0 100644

net/bluetooth/hci_conn.c +0 -0
@@ -686,6 +686,19 @@ static void hci_conn_timeout(struct work_struct

*work)

Quoted 3 lines
net/bluetooth/hci_conn.c +0 -0
                return;
        }
 
Quoted 16 lines

net/bluetooth/hci_conn.c static void hci_conn_timeout(struct work_struct *work) · line 700

Quoted 12 lines
net/bluetooth/hci_conn.c +12 -0
+       /* Cleanup bises that failed to be established */
+       if (test_and_clear_bit(HCI_CONN_BIG_SYNC_FAILED, &conn->flags)) {
+               conn->state = BT_CLOSED;
+               hci_disconn_cfm(conn, hci_proto_disconn_ind(conn));
+               hci_conn_hash_del(conn->hdev, conn);
+
+               if (conn->cleanup)
+                       conn->cleanup(conn);
+
+               hci_conn_put(conn);
+               return;
+       }

I will be pushing some changes to how hci_abort_conn works, the code above shall probably be done inside the likes of hci_conn_failed though but first we need to add support for BIS into hci_abort_conn_sync.

Thank you, I submitted a new patch version with these updates.

Quoted 190 lines
Quoted 31 lines
net/bluetooth/hci_conn.c +2 -10
        hci_abort_conn(conn, hci_proto_disconn_ind(conn));  }
 
@@ -793,6 +806,7 @@ struct iso_list_data {
        int count;
        struct iso_cig_params pdu;
        bool big_term;
+       bool big_sync_term;
 };
 
 static void bis_list(struct hci_conn *conn, void *data) @@ -810,17
+824,6 @@ static void bis_list(struct hci_conn *conn, void *data)
        d->count++;
 }
 
-static void find_bis(struct hci_conn *conn, void *data) -{
-       struct iso_list_data *d = data;
-
-       /* Ignore unicast */
-       if (bacmp(&conn->dst, BDADDR_ANY))
-               return;
-
-       d->count++;
-}
-
 static int terminate_big_sync(struct hci_dev *hdev, void *data)  {
        struct iso_list_data *d = data; @@ -873,31 +876,26 @@ static

int big_terminate_sync(struct hci_dev *hdev, void *data)

        bt_dev_dbg(hdev, "big 0x%2.2x sync_handle 0x%4.4x", d->big,
                   d->sync_handle);

net/bluetooth/hci_conn.c static int big_terminate_sync(struct hci_dev *hdev, void *data)

Quoted 4 lines
net/bluetooth/hci_conn.c +0 -4
-       /* Check if ISO connection is a BIS and terminate BIG if there are
-        * no other connections using it.
-        */
-       hci_conn_hash_list_state(hdev, find_bis, ISO_LINK, BT_CONNECTED,

d);

Quoted 11 lines
net/bluetooth/hci_conn.c +2 -5
-       if (d->count)
-               return 0;
-
-       hci_le_big_terminate_sync(hdev, d->big);
+       if (d->big_sync_term)
+               hci_le_big_terminate_sync(hdev, d->big);
 
        return hci_le_pa_terminate_sync(hdev, d->sync_handle);  }
 
-static int hci_le_big_terminate(struct hci_dev *hdev, u8 big, u16

sync_handle)

net/bluetooth/hci_conn.c static int big_terminate_sync(struct hci_dev *hdev, void *data)

Quoted 7 lines
net/bluetooth/hci_conn.c +2 -1
+static int hci_le_big_terminate(struct hci_dev *hdev, u8 big, struct
+hci_conn *conn)
 {
        struct iso_list_data *d;
        int ret;
 
-       bt_dev_dbg(hdev, "big 0x%2.2x sync_handle 0x%4.4x", big,

sync_handle);

net/bluetooth/hci_event.c static void

Quoted 37 lines
net/bluetooth/hci_conn.c +14 -2
+       bt_dev_dbg(hdev, "big 0x%2.2x sync_handle 0x%4.4x", big,
+ conn->sync_handle);
 
        d = kzalloc(sizeof(*d), GFP_KERNEL);
        if (!d)
                return -ENOMEM;
 
        d->big = big;
-       d->sync_handle = sync_handle;
+       d->sync_handle = conn->sync_handle;
+       d->big_sync_term = test_and_clear_bit(HCI_CONN_BIG_SYNC,
+ &conn->flags);
 
        ret = hci_cmd_sync_queue(hdev, big_terminate_sync, d,
                                 terminate_big_destroy); @@ -933,8
+931,14 @@ static void bis_cleanup(struct hci_conn *conn)
 
                hci_le_terminate_big(hdev, conn);
        } else {
+               bis = hci_conn_hash_lookup_big_any_dst(hdev,
+
+ conn->iso_qos.bcast.big);
+
+               if (bis)
+                       return;
+
                hci_le_big_terminate(hdev, conn->iso_qos.bcast.big,
-                                    conn->sync_handle);
+                                    conn);
        }
 }
net/bluetooth/hci_event.c +0 -0
index 77cbf13037b3..30d0a6631e17 100644
@@ -7039,9 +7039,6 @@ static void

hci_le_big_sync_established_evt(struct hci_dev *hdev, void *data,

Quoted 10 lines
net/bluetooth/hci_event.c +0 -3
                                flex_array_size(ev, bis, ev->num_bis)))
                return;
 
-       if (ev->status)
-               return;
-
        hci_dev_lock(hdev);
 
        for (i = 0; i < ev->num_bis; i++) { @@ -7065,9 +7062,25 @@

static void hci_le_big_sync_established_evt(struct hci_dev *hdev, void

*data,

Quoted 1 line
                bis->iso_qos.bcast.in.latency = le16_to_cpu(ev->interval) * 125 /

100;

net/bluetooth/iso.c static void iso_conn_ready(struct iso_conn

Quoted 52 lines
                bis->iso_qos.bcast.in.sdu = le16_to_cpu(ev->max_pdu);
net/bluetooth/hci_event.c +18 -1
-               hci_iso_setup_path(bis);
+               if (!ev->status) {
+                       set_bit(HCI_CONN_BIG_SYNC, &bis->flags);
+                       hci_iso_setup_path(bis);
+               }
        }
 
+       /* In case BIG sync failed, notify each failed connection to
+        * the user after all hci connections have been added
+        */
+       if (ev->status)
+               for (i = 0; i < ev->num_bis; i++) {
+                       u16 handle = le16_to_cpu(ev->bis[i]);
+
+                       bis = hci_conn_hash_lookup_handle(hdev,
+ handle);
+
+                       set_bit(HCI_CONN_BIG_SYNC_FAILED, &bis->flags);
+                       hci_connect_cfm(bis, ev->status);
+               }
+
        hci_dev_unlock(hdev);
 }
net/bluetooth/iso.c index renamed from net/bluetooth/iso.c +0 -0

84d238d0639a..e0386b12ea4e 100644

net/bluetooth/iso.c +6 -1
@@ -48,6 +48,11 @@ static void iso_sock_kill(struct sock *sk);
 #define EIR_SERVICE_DATA_LENGTH 4  #define BASE_MAX_LENGTH
 (HCI_MAX_PER_AD_LENGTH - EIR_SERVICE_DATA_LENGTH)
 
+/* iso_pinfo flags values */
+enum {
+       BT_SK_BIG_SYNC,
+};
+
 struct iso_pinfo {
        struct bt_sock          bt;
        bdaddr_t                src;
@@ -58,7 +63,7 @@ struct iso_pinfo {
        __u8                    bc_num_bis;
        __u8                    bc_bis[ISO_MAX_NUM_BIS];
        __u16                   sync_handle;
-       __u32                   flags;
+       unsigned long           flags;
        struct bt_iso_qos       qos;
        bool                    qos_user_set;
        __u8                    base_len;
@@ -1569,6 +1574,12 @@ static void iso_conn_ready(struct iso_conn

*conn)

net/bluetooth/iso.c static void iso_conn_ready(struct iso_conn *conn)

Quoted 4 lines
net/bluetooth/iso.c +1 -0
                hci_conn_hold(hcon);
                iso_chan_add(conn, sk, parent);
 
+               if (ev && ((struct hci_evt_le_big_sync_estabilished *)ev)->status)

{

net/bluetooth/iso.c int iso_connect_ind(struct hci_dev *hdev,

Quoted 9 lines
net/bluetooth/iso.c +5 -0
+                       /* Trigger error signal on child socket */
+                       sk->sk_err = ECONNREFUSED;
+                       sk->sk_error_report(sk);
+               }
+
                if (test_bit(BT_SK_DEFER_SETUP, &bt_sk(parent)->flags))
                        sk->sk_state = BT_CONNECT2;
                else
@@ -1637,15 +1648,19 @@ int iso_connect_ind(struct hci_dev *hdev,

bdaddr_t *bdaddr, __u8 *flags)

Quoted 5 lines
net/bluetooth/iso.c +0 -2
                        if (ev2->num_bis < iso_pi(sk)->bc_num_bis)
                                iso_pi(sk)->bc_num_bis = ev2->num_bis;
 
-                       err = hci_le_big_create_sync(hdev,
-                                                    &iso_pi(sk)->qos,

net/bluetooth/iso.c int iso_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags)

Quoted 10 lines
net/bluetooth/iso.c +3 -7
-                                                    iso_pi(sk)->sync_handle,
-                                                    iso_pi(sk)->bc_num_bis,
-                                                    iso_pi(sk)->bc_bis);
-                       if (err) {
-                               bt_dev_err(hdev, "hci_le_big_create_sync: %d",
-                                          err);
-                               sk = NULL;
+                       if (!test_bit(BT_SK_BIG_SYNC, &iso_pi(sk)->flags)) {
+                               set_bit(BT_SK_BIG_SYNC,
+ &iso_pi(sk)->flags);
Quoted 1 line

You can probably use test_and_set_bit instead above.

I updated this as well.

Quoted 18 lines
Quoted 18 lines
net/bluetooth/iso.c +11 -0
+
+                               err = hci_le_big_create_sync(hdev,
+                                                            &iso_pi(sk)->qos,
+                                                            iso_pi(sk)->sync_handle,
+                                                            iso_pi(sk)->bc_num_bis,
+                                                            iso_pi(sk)->bc_bis);
+                               if (err) {
+                                       bt_dev_err(hdev, "hci_le_big_create_sync: %d",
+                                                  err);
+                                       sk = NULL;
+                               }
                        }
                }
        } else {
@@ -1688,7 +1703,7 @@ static void iso_connect_cfm(struct hci_conn
 *hcon, __u8 status)
 
Quoted 8 lines

net/bluetooth/iso.c static void iso_connect_cfm(struct hci_conn · line 1709

Quoted 6 lines
net/bluetooth/iso.c +2 -1
        BT_DBG("hcon %p bdaddr %pMR status %d", hcon, &hcon->dst,
 status);
 
-       if (!status) {
+       if (!status || test_bit(HCI_CONN_BIG_SYNC_FAILED,
+ &hcon->flags)) {

Shouldn't it be !test_bit above?

Quoted 4 lines

Here, if HCI_CONN_BIG_SYNC_FAILED is set, I want to reach iso_conn_ready, like it would be for the success case, so the failed bis connection will be added in the accept queue of the listening socket and it will be woken up in userspace, so the check should be positive.

Make sure you add a comment explaining this, since someone else may think this is a bug as well.

Quoted 15 lines
Quoted 11 lines
Quoted 7 lines
                struct iso_conn *conn;

                conn = iso_conn_add(hcon);

--
2.34.1

--
Luiz Augusto von Dentz

Regards,
Iulia

Signature · 1 line
Luiz Augusto von Dentz