Skip to contentSkip to conversation

Bluetooth: hci_conn: Add support for linking multiple hcon

PATCH Superseded Luiz Augusto von Dentz 3 participants 6 messages Apr 13, 2023 – Apr 14, 2023

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH v2 1/3 Bluetooth: hci_conn: Add support for linking multiple hcon

From: Luiz Augusto von Dentz <[email protected]>

Since it is required for some configurations to have multiple CIS with the same peer which is now covered by iso-tester in the following test cases:

ISO AC 6(i) - Success
ISO AC 7(i) - Success
ISO AC 8(i) - Success
ISO AC 9(i) - Success
ISO AC 11(i) - Success

---
 include/net/bluetooth/hci_core.h |  14 ++-
 net/bluetooth/hci_conn.c         | 157 ++++++++++++++++++++++---------
 net/bluetooth/hci_event.c        |  94 +++++++++---------
 net/bluetooth/iso.c              |   8 +-
 4 files changed, 174 insertions(+), 99 deletions(-)
include/net/bluetooth/hci_core.h +12 -2
index 827e67159523..4fe1e71cb9d8 100644
@@ -770,7 +770,10 @@ struct hci_conn {
 	void		*iso_data;
 	struct amp_mgr	*amp_mgr;
 
-	struct hci_conn	*link;
+	struct list_head link_list;
+	struct hci_conn	*parent;
+	struct hci_link *link;
+
 	struct bt_codec codec;
 
 	void (*connect_cfm_cb)	(struct hci_conn *conn, u8 status);
@@ -780,6 +783,11 @@ struct hci_conn {
 	void (*cleanup)(struct hci_conn *conn);
 };
 
+struct hci_link {
+	struct list_head list;
+	struct hci_conn *conn;
+};
+
 struct hci_chan {
 	struct list_head list;
 	__u16 handle;
@@ -1383,12 +1391,14 @@ static inline void hci_conn_put(struct hci_conn *conn)
 	put_device(&conn->dev);
 }
 
-static inline void hci_conn_hold(struct hci_conn *conn)
+static inline struct hci_conn *hci_conn_hold(struct hci_conn *conn)
 {
 	BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt));
 
 	atomic_inc(&conn->refcnt);
 	cancel_delayed_work(&conn->disc_work);
+
+	return conn;
 }
 
 static inline void hci_conn_drop(struct hci_conn *conn)
net/bluetooth/hci_conn.c +114 -43

286 lines not on this page · raw message

net/bluetooth/hci_event.c +42 -52

153 lines not on this page · raw message

net/bluetooth/iso.c +6 -2
index 74117df03a3f..34d55a85d8f6 100644
@@ -1657,8 +1657,12 @@ static void iso_connect_cfm(struct hci_conn *hcon, __u8 status)
 
 		/* Check if LE link has failed */
 		if (status) {
-			if (hcon->link)
-				iso_conn_del(hcon->link, bt_to_errno(status));
+			struct hci_link *link, *t;
+
+			list_for_each_entry_safe(link, t, &hcon->link_list,
+						 list)
+				iso_conn_del(link->conn, bt_to_errno(status));
+
 			return;
 		}
 
Signature · 1 line
2.39.2
author maintainer
#1 lore raw

PATCH v2 2/3 Bluetooth: hci_conn: Fix not matching by CIS ID

From: Luiz Augusto von Dentz <[email protected]>

This fixes only matching CIS by address which prevents creating new hcon if upper layer is requesting a specific CIS ID.

---
 include/net/bluetooth/hci_core.h | 7 ++++++-
 net/bluetooth/hci_conn.c         | 2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)
include/net/bluetooth/hci_core.h +6 -1
index 4fe1e71cb9d8..6f5e8594ff2d 100644
@@ -1180,7 +1180,8 @@ static inline struct hci_conn *hci_conn_hash_lookup_le(struct hci_dev *hdev,
 
 static inline struct hci_conn *hci_conn_hash_lookup_cis(struct hci_dev *hdev,
 							bdaddr_t *ba,
-							__u8 ba_type)
+							__u8 ba_type,
+							__u8 id)
 {
 	struct hci_conn_hash *h = &hdev->conn_hash;
 	struct hci_conn  *c;
@@ -1191,6 +1192,10 @@ static inline struct hci_conn *hci_conn_hash_lookup_cis(struct hci_dev *hdev,
 		if (c->type != ISO_LINK)
 			continue;
 
+		/* Match CIS ID if set */
+		if (id != BT_ISO_QOS_CIS_UNSET && id != c->iso_qos.ucast.cis)
+			continue;
+
 		if (ba_type == c->dst_type && !bacmp(&c->dst, ba)) {
 			rcu_read_unlock();
 			return c;
net/bluetooth/hci_conn.c +1 -1
index 204164ee5f9a..b9ecfc782be9 100644
@@ -1842,7 +1842,7 @@ struct hci_conn *hci_bind_cis(struct hci_dev *hdev, bdaddr_t *dst,
 {
 	struct hci_conn *cis;
 
-	cis = hci_conn_hash_lookup_cis(hdev, dst, dst_type);
+	cis = hci_conn_hash_lookup_cis(hdev, dst, dst_type, qos->ucast.cis);
 	if (!cis) {
 		cis = hci_conn_add(hdev, ISO_LINK, dst, HCI_ROLE_MASTER);
 		if (!cis)
Signature · 1 line
2.39.2
#2 lore raw

Re: [PATCH v2 2/3] Bluetooth: hci_conn: Fix not matching by CIS ID

Hi Luiz,

to, 2023-04-13 kello 11:31 -0700, Luiz Augusto von Dentz kirjoitti:

Quoted 26 lines

From: Luiz Augusto von Dentz <[email protected]>

This fixes only matching CIS by address which prevents creating new hcon if upper layer is requesting a specific CIS ID.

---
 include/net/bluetooth/hci_core.h | 7 ++++++-
 net/bluetooth/hci_conn.c         | 2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)
include/net/bluetooth/hci_core.h +2 -1
index 4fe1e71cb9d8..6f5e8594ff2d 100644
@@ -1180,7 +1180,8 @@ static inline struct hci_conn *hci_conn_hash_lookup_le(struct hci_dev *hdev,
 
 static inline struct hci_conn *hci_conn_hash_lookup_cis(struct hci_dev *hdev,
 							bdaddr_t *ba,
-							__u8 ba_type)
+							__u8 ba_type,
+							__u8 id)
 {
 	struct hci_conn_hash *h = &hdev->conn_hash;
 	struct hci_conn  *c;

include/net/bluetooth/hci_core.h static inline struct hci_conn *hci_conn_hash_lookup_cis(struct hci_dev *hdev, · line 1198

Quoted 7 lines
include/net/bluetooth/hci_core.h +4 -0
@@ -1191,6 +1192,10 @@ static inline struct hci_conn *hci_conn_hash_lookup_cis(struct hci_dev *hdev,
 		if (c->type != ISO_LINK)
 			continue;
 
+		/* Match CIS ID if set */
+		if (id != BT_ISO_QOS_CIS_UNSET && id != c->iso_qos.ucast.cis)
+			continue;
+

Should this also check the CIG ID?

Core v5.3 4.E Sec. 5.3: "The CIS_ID has a separate number space for each CIG_ID.", and I didn't manage to find restriction that you couldn't have the same peripheral in multiple CIG.

Quoted 16 lines
include/net/bluetooth/hci_core.h +0 -0
 		if (ba_type == c->dst_type && !bacmp(&c->dst, ba)) {
 			rcu_read_unlock();
 			return c;
net/bluetooth/hci_conn.c +1 -1
index 204164ee5f9a..b9ecfc782be9 100644
@@ -1842,7 +1842,7 @@ struct hci_conn *hci_bind_cis(struct hci_dev *hdev, bdaddr_t *dst,
 {
 	struct hci_conn *cis;
 
-	cis = hci_conn_hash_lookup_cis(hdev, dst, dst_type);
+	cis = hci_conn_hash_lookup_cis(hdev, dst, dst_type, qos->ucast.cis);
 	if (!cis) {
 		cis = hci_conn_add(hdev, ISO_LINK, dst, HCI_ROLE_MASTER);
 		if (!cis)
Signature · 1 line
Pauli Virtanen
author maintainer
#3 lore raw

Re: [PATCH v2 2/3] Bluetooth: hci_conn: Fix not matching by CIS ID

Hi Pauli,

Quoted 40 lines · Pauli Virtanen

Hi Luiz,

to, 2023-04-13 kello 11:31 -0700, Luiz Augusto von Dentz kirjoitti:

Quoted 26 lines

From: Luiz Augusto von Dentz <[email protected]>

This fixes only matching CIS by address which prevents creating new hcon if upper layer is requesting a specific CIS ID.

---
 include/net/bluetooth/hci_core.h | 7 ++++++-
 net/bluetooth/hci_conn.c         | 2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)
include/net/bluetooth/hci_core.h +2 -1
index 4fe1e71cb9d8..6f5e8594ff2d 100644
@@ -1180,7 +1180,8 @@ static inline struct hci_conn *hci_conn_hash_lookup_le(struct hci_dev *hdev,
 
 static inline struct hci_conn *hci_conn_hash_lookup_cis(struct hci_dev *hdev,
                                                      bdaddr_t *ba,
-                                                     __u8 ba_type)
+                                                     __u8 ba_type,
+                                                     __u8 id)
 {
      struct hci_conn_hash *h = &hdev->conn_hash;
      struct hci_conn  *c;

include/net/bluetooth/hci_core.h static inline struct hci_conn *hci_conn_hash_lookup_cis(struct hci_dev *hdev, · line 1198

Quoted 7 lines
include/net/bluetooth/hci_core.h +4 -0
@@ -1191,6 +1192,10 @@ static inline struct hci_conn *hci_conn_hash_lookup_cis(struct hci_dev *hdev,
              if (c->type != ISO_LINK)
                      continue;
 
+             /* Match CIS ID if set */
+             if (id != BT_ISO_QOS_CIS_UNSET && id != c->iso_qos.ucast.cis)
+                     continue;
+

Should this also check the CIG ID?

Quoted 3 lines

Core v5.3 4.E Sec. 5.3: "The CIS_ID has a separate number space for each CIG_ID.", and I didn't manage to find restriction that you couldn't have the same peripheral in multiple CIG.

That is a good point, it seems the BAP Audio Configurations are limited to just one CIG but in theory there could be multiple if they don't need to be synchronized, I will fix that to check both CIG and CIS.

Quoted 19 lines
Quoted 8 lines
include/net/bluetooth/hci_core.h +0 -0
              if (ba_type == c->dst_type && !bacmp(&c->dst, ba)) {
                      rcu_read_unlock();
                      return c;
net/bluetooth/hci_conn.c +0 -0
index 204164ee5f9a..b9ecfc782be9 100644

net/bluetooth/hci_conn.c struct hci_conn *hci_bind_cis(struct hci_dev *hdev, bdaddr_t *dst, · line 1848

Quoted 8 lines
net/bluetooth/hci_conn.c +1 -1
@@ -1842,7 +1842,7 @@ struct hci_conn *hci_bind_cis(struct hci_dev *hdev, bdaddr_t *dst,
 {
      struct hci_conn *cis;
 
-     cis = hci_conn_hash_lookup_cis(hdev, dst, dst_type);
+     cis = hci_conn_hash_lookup_cis(hdev, dst, dst_type, qos->ucast.cis);
      if (!cis) {
              cis = hci_conn_add(hdev, ISO_LINK, dst, HCI_ROLE_MASTER);
              if (!cis)

--
Pauli Virtanen

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

PATCH v2 3/3 Bluetooth: hci_conn: Fix not waiting for HCI_EVT_LE_CIS_ESTABLISHED

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

When submitting HCI_OP_LE_CREATE_CIS the code shall wait for HCI_EVT_LE_CIS_ESTABLISHED thus enforcing the serialization of HCI_OP_LE_CREATE_CIS as the Core spec does not allow to send them in parallel:

BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 4, Part E page 2566:

If the Host issues this command before all the HCI_LE_CIS_Established events from the previous use of the command have been generated, the Controller shall return the error code Command Disallowed (0x0C).

---
 include/net/bluetooth/hci_sync.h |  2 +
 net/bluetooth/hci_conn.c         | 58 +---------------------------
 net/bluetooth/hci_sync.c         | 65 ++++++++++++++++++++++++++++++++
 3 files changed, 68 insertions(+), 57 deletions(-)
include/net/bluetooth/hci_sync.h +2 -0
index 17f5a4c32f36..f61b249787fc 100644
@@ -122,6 +122,8 @@ int hci_abort_conn_sync(struct hci_dev *hdev, struct hci_conn *conn, u8 reason);
 
 int hci_le_create_conn_sync(struct hci_dev *hdev, struct hci_conn *conn);
 
+int hci_le_create_cis_sync(struct hci_dev *hdev, struct hci_conn *conn);
+
 int hci_le_remove_cig_sync(struct hci_dev *hdev, u8 handle);
 
 int hci_le_terminate_big_sync(struct hci_dev *hdev, u8 handle, u8 reason);
net/bluetooth/hci_conn.c +1 -57

64 lines not on this page · raw message

net/bluetooth/hci_sync.c +65 -0

71 lines not on this page · raw message

Signature · 1 line
2.39.2
#5 lore raw
In reply to Luiz Augusto von Dentz

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=739574

---Test result---

Test Summary:

CheckPatch                    PASS      3.03 seconds
GitLint                       PASS      0.83 seconds
SubjectPrefix                 PASS      0.28 seconds
BuildKernel                   PASS      32.27 seconds
CheckAllWarning               PASS      35.41 seconds
CheckSparse                   WARNING   40.34 seconds
CheckSmatch                   WARNING   110.67 seconds
BuildKernel32                 PASS      31.57 seconds
TestRunnerSetup               PASS      448.56 seconds
TestRunner_l2cap-tester       PASS      17.25 seconds
TestRunner_iso-tester         PASS      17.84 seconds
TestRunner_bnep-tester        PASS      5.62 seconds
TestRunner_mgmt-tester        PASS      116.98 seconds
TestRunner_rfcomm-tester      PASS      8.96 seconds
TestRunner_sco-tester         PASS      8.31 seconds
TestRunner_ioctl-tester       PASS      9.59 seconds
TestRunner_mesh-tester        PASS      7.06 seconds
TestRunner_smp-tester         PASS      8.13 seconds
TestRunner_userchan-tester    PASS      5.81 seconds
IncrementalBuild              PASS      82.75 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