diff mbox series

[1/2] Bluetooth: hci_event: drop only unbound CIS if Set CIG Parameters fails

Message ID 5af5d6830d65173124aa525dd01b2718548ffb65.1691251325.git.pav@iki.fi
State Accepted
Commit f5669a036ae664335685859676b0cfb9bc0b16f3
Headers show
Series [1/2] Bluetooth: hci_event: drop only unbound CIS if Set CIG Parameters fails | expand

Commit Message

Pauli Virtanen Aug. 5, 2023, 4:08 p.m. UTC
When user tries to connect a new CIS when its CIG is not configurable,
that connection shall fail, but pre-existing connections shall not be
affected.  However, currently hci_cc_le_set_cig_params deletes all CIS
of the CIG on error so it doesn't work, even though controller shall not
change CIG/CIS configuration if the command fails.

Fix by failing on command error only the connections that are not yet
bound, so that we keep the previous CIS configuration like the
controller does.

Fixes: 26afbd826ee3 ("Bluetooth: Add initial implementation of CIS connections")
Signed-off-by: Pauli Virtanen <pav@iki.fi>
---
 net/bluetooth/hci_event.c | 29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)

Comments

patchwork-bot+bluetooth@kernel.org Aug. 7, 2023, 11:50 p.m. UTC | #1
Hello:

This series was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Sat,  5 Aug 2023 19:08:41 +0300 you wrote:
> When user tries to connect a new CIS when its CIG is not configurable,
> that connection shall fail, but pre-existing connections shall not be
> affected.  However, currently hci_cc_le_set_cig_params deletes all CIS
> of the CIG on error so it doesn't work, even though controller shall not
> change CIG/CIS configuration if the command fails.
> 
> Fix by failing on command error only the connections that are not yet
> bound, so that we keep the previous CIS configuration like the
> controller does.
> 
> [...]

Here is the summary with links:
  - [1/2] Bluetooth: hci_event: drop only unbound CIS if Set CIG Parameters fails
    https://git.kernel.org/bluetooth/bluetooth-next/c/f5669a036ae6
  - [2/2] Bluetooth: hci_conn: avoid checking uninitialized CIG/CIS ids
    https://git.kernel.org/bluetooth/bluetooth-next/c/6130cdd83d40

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 218da9b0fe8f..559b6080706c 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -3799,6 +3799,22 @@  static u8 hci_cc_le_read_buffer_size_v2(struct hci_dev *hdev, void *data,
 	return rp->status;
 }
 
+static void hci_unbound_cis_failed(struct hci_dev *hdev, u8 cig, u8 status)
+{
+	struct hci_conn *conn, *tmp;
+
+	lockdep_assert_held(&hdev->lock);
+
+	list_for_each_entry_safe(conn, tmp, &hdev->conn_hash.list, list) {
+		if (conn->type != ISO_LINK || !bacmp(&conn->dst, BDADDR_ANY) ||
+		    conn->state == BT_OPEN || conn->iso_qos.ucast.cig != cig)
+			continue;
+
+		if (HCI_CONN_HANDLE_UNSET(conn->handle))
+			hci_conn_failed(conn, status);
+	}
+}
+
 static u8 hci_cc_le_set_cig_params(struct hci_dev *hdev, void *data,
 				   struct sk_buff *skb)
 {
@@ -3820,12 +3836,15 @@  static u8 hci_cc_le_set_cig_params(struct hci_dev *hdev, void *data,
 
 	hci_dev_lock(hdev);
 
+	/* BLUETOOTH CORE SPECIFICATION Version 5.4 | Vol 4, Part E page 2554
+	 *
+	 * If the Status return parameter is non-zero, then the state of the CIG
+	 * and its CIS configurations shall not be changed by the command. If
+	 * the CIG did not already exist, it shall not be created.
+	 */
 	if (status) {
-		while ((conn = hci_conn_hash_lookup_cig(hdev, rp->cig_id))) {
-			conn->state = BT_CLOSED;
-			hci_connect_cfm(conn, status);
-			hci_conn_del(conn);
-		}
+		/* Keep current configuration, fail only the unbound CIS */
+		hci_unbound_cis_failed(hdev, rp->cig_id, status);
 		goto unlock;
 	}