Skip to contentSkip to conversation

Bluetooth: ISO: Allow binding a PA sync socket

PATCH Applied Iulia Tanasescu 3 participants 4 messages Oct 24, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover Bluetooth: ISO: Allow binding a PA sync socket

A Broadcast Sink has no way to know how many BISes are available for sync or their indexes, before establishing PA sync and reading the base struct.

PA sync is established by calling listen with DEFER_SETUP and accepting a PA sync socket.

This patch makes it possible to bind a PA sync socket to a number of BISes before issuing the BIG Create Sync command.

This patch version fixes review comments.

Iulia Tanasescu (1):
Bluetooth: ISO: Allow binding a PA sync socket

 net/bluetooth/iso.c | 67 +++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 62 insertions(+), 5 deletions(-)

base-commit: 2fddfadb0478a11952d4a3d543273f28d2c23c03

Signature · 1 line
2.39.2
#1 lore raw

PATCH v3 1/1 Bluetooth: ISO: Allow binding a PA sync socket

This makes it possible to bind a PA sync socket to a number of BISes before issuing the BIG Create Sync command.

---
 net/bluetooth/iso.c | 67 +++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 62 insertions(+), 5 deletions(-)
net/bluetooth/iso.c +62 -5
index 07b80e97aead..e01b6abe36fb 100644
@@ -792,27 +792,75 @@ static int iso_sock_bind_bc(struct socket *sock, struct sockaddr *addr,
 	BT_DBG("sk %p bc_sid %u bc_num_bis %u", sk, sa->iso_bc->bc_sid,
 	       sa->iso_bc->bc_num_bis);
 
-	if (addr_len > sizeof(*sa) + sizeof(*sa->iso_bc))
+	if (addr_len != sizeof(*sa) + sizeof(*sa->iso_bc))
 		return -EINVAL;
 
 	bacpy(&iso_pi(sk)->dst, &sa->iso_bc->bc_bdaddr);
+
+	/* Check if the address type is of LE type */
+	if (!bdaddr_type_is_le(sa->iso_bc->bc_bdaddr_type))
+		return -EINVAL;
+
 	iso_pi(sk)->dst_type = sa->iso_bc->bc_bdaddr_type;
 	iso_pi(sk)->sync_handle = -1;
+
+	if (sa->iso_bc->bc_sid > 0x0f)
+		return -EINVAL;
+
 	iso_pi(sk)->bc_sid = sa->iso_bc->bc_sid;
+
+	if (sa->iso_bc->bc_num_bis > ISO_MAX_NUM_BIS)
+		return -EINVAL;
+
 	iso_pi(sk)->bc_num_bis = sa->iso_bc->bc_num_bis;
 
-	for (i = 0; i < iso_pi(sk)->bc_num_bis; i++) {
+	for (i = 0; i < iso_pi(sk)->bc_num_bis; i++)
 		if (sa->iso_bc->bc_bis[i] < 0x01 ||
 		    sa->iso_bc->bc_bis[i] > 0x1f)
 			return -EINVAL;
 
-		memcpy(iso_pi(sk)->bc_bis, sa->iso_bc->bc_bis,
-		       iso_pi(sk)->bc_num_bis);
-	}
+	memcpy(iso_pi(sk)->bc_bis, sa->iso_bc->bc_bis,
+	       iso_pi(sk)->bc_num_bis);
 
 	return 0;
 }
 
+static int iso_sock_bind_pa_sk(struct sock *sk, struct sockaddr_iso *sa,
+			       int addr_len)
+{
+	int err = 0;
+
+	if (sk->sk_type != SOCK_SEQPACKET) {
+		err = -EINVAL;
+		goto done;
+	}
+
+	if (addr_len != sizeof(*sa) + sizeof(*sa->iso_bc)) {
+		err = -EINVAL;
+		goto done;
+	}
+
+	if (sa->iso_bc->bc_num_bis > ISO_MAX_NUM_BIS) {
+		err = -EINVAL;
+		goto done;
+	}
+
+	iso_pi(sk)->bc_num_bis = sa->iso_bc->bc_num_bis;
+
+	for (int i = 0; i < iso_pi(sk)->bc_num_bis; i++)
+		if (sa->iso_bc->bc_bis[i] < 0x01 ||
+		    sa->iso_bc->bc_bis[i] > 0x1f) {
+			err = -EINVAL;
+			goto done;
+		}
+
+	memcpy(iso_pi(sk)->bc_bis, sa->iso_bc->bc_bis,
+	       iso_pi(sk)->bc_num_bis);
+
+done:
+	return err;
+}
+
 static int iso_sock_bind(struct socket *sock, struct sockaddr *addr,
 			 int addr_len)
 {
@@ -828,6 +876,15 @@ static int iso_sock_bind(struct socket *sock, struct sockaddr *addr,
 
 	lock_sock(sk);
 
+	/* Allow the user to bind a PA sync socket to a number
+	 * of BISes to sync to.
+	 */
+	if (sk->sk_state == BT_CONNECT2 &&
+	    test_bit(BT_SK_PA_SYNC, &iso_pi(sk)->flags)) {
+		err = iso_sock_bind_pa_sk(sk, sa, addr_len);
+		goto done;
+	}
+
 	if (sk->sk_state != BT_OPEN) {
 		err = -EBADFD;
 		goto done;
Signature · 1 line
2.39.2
#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=795975

---Test result---

Test Summary:

CheckPatch                    PASS      0.72 seconds
GitLint                       PASS      0.32 seconds
SubjectPrefix                 PASS      0.11 seconds
BuildKernel                   PASS      34.16 seconds
CheckAllWarning               PASS      37.40 seconds
CheckSparse                   PASS      43.43 seconds
CheckSmatch                   PASS      115.73 seconds
BuildKernel32                 PASS      32.94 seconds
TestRunnerSetup               PASS      515.77 seconds
TestRunner_l2cap-tester       PASS      31.09 seconds
TestRunner_iso-tester         PASS      51.02 seconds
TestRunner_bnep-tester        PASS      10.45 seconds
TestRunner_mgmt-tester        PASS      213.20 seconds
TestRunner_rfcomm-tester      PASS      16.04 seconds
TestRunner_sco-tester         PASS      19.47 seconds
TestRunner_ioctl-tester       PASS      18.69 seconds
TestRunner_mesh-tester        PASS      13.23 seconds
TestRunner_smp-tester         PASS      14.29 seconds
TestRunner_userchan-tester    PASS      11.09 seconds
IncrementalBuild              PASS      31.23 seconds

---
Regards,
Linux Bluetooth

#3 lore raw
In reply to Iulia Tanasescu
This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 8 lines · On Tue, 24 Oct 2023 13:57:34 +0300 you wrote:

A Broadcast Sink has no way to know how many BISes are available for sync or their indexes, before establishing PA sync and reading the base struct.

PA sync is established by calling listen with DEFER_SETUP and accepting a PA sync socket.

[...]

Here is the summary with links:
- [v3,1/1] Bluetooth: ISO: Allow binding a PA sync socket

    https://git.kernel.org/bluetooth/bluetooth-next/c/0783375f2c56

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html