2023-10-16 15:46:04

by Iulia Tanasescu

[permalink] [raw]
Subject: [PATCH 0/1] 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.

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

net/bluetooth/iso.c | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)


base-commit: 8fa4c368ba691e6d92bc7a71279ed4ce5f1a6a1d
--
2.39.2


2023-10-16 15:46:08

by Iulia Tanasescu

[permalink] [raw]
Subject: [PATCH 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.

Signed-off-by: Iulia Tanasescu <[email protected]>
---
net/bluetooth/iso.c | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)

diff --git a/net/bluetooth/iso.c b/net/bluetooth/iso.c
index 07b80e97aead..6938ff4accb3 100644
--- a/net/bluetooth/iso.c
+++ b/net/bluetooth/iso.c
@@ -813,6 +813,40 @@ static int iso_sock_bind_bc(struct socket *sock, struct sockaddr *addr,
return 0;
}

+static int iso_sock_bind_pa_sk(struct sock *sk, struct sockaddr_iso *sa,
+ int addr_len)
+{
+ int err = 0;
+
+ lock_sock(sk);
+
+ if (sk->sk_type != SOCK_SEQPACKET) {
+ err = -EINVAL;
+ goto done;
+ }
+
+ if (addr_len <= sizeof(*sa)) {
+ 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:
+ release_sock(sk);
+ return err;
+}
+
static int iso_sock_bind(struct socket *sock, struct sockaddr *addr,
int addr_len)
{
@@ -826,6 +860,13 @@ static int iso_sock_bind(struct socket *sock, struct sockaddr *addr,
addr->sa_family != AF_BLUETOOTH)
return -EINVAL;

+ /* 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))
+ return iso_sock_bind_pa_sk(sk, sa, addr_len);
+
lock_sock(sk);

if (sk->sk_state != BT_OPEN) {
--
2.39.2

2023-10-16 16:31:02

by Pauli Virtanen

[permalink] [raw]
Subject: Re: [PATCH 1/1] Bluetooth: ISO: Allow binding a PA sync socket

Hi,

ma, 2023-10-16 kello 18:45 +0300, Iulia Tanasescu kirjoitti:
> This makes it possible to bind a PA sync socket to a number of BISes
> before issuing the BIG Create Sync command.
>
> Signed-off-by: Iulia Tanasescu <[email protected]>
> ---
> net/bluetooth/iso.c | 41 +++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 41 insertions(+)
>
> diff --git a/net/bluetooth/iso.c b/net/bluetooth/iso.c
> index 07b80e97aead..6938ff4accb3 100644
> --- a/net/bluetooth/iso.c
> +++ b/net/bluetooth/iso.c
> @@ -813,6 +813,40 @@ static int iso_sock_bind_bc(struct socket *sock, struct sockaddr *addr,
> return 0;
> }
>
> +static int iso_sock_bind_pa_sk(struct sock *sk, struct sockaddr_iso *sa,
> + int addr_len)
> +{
> + int err = 0;
> +
> + lock_sock(sk);
> +
> + if (sk->sk_type != SOCK_SEQPACKET) {
> + err = -EINVAL;
> + goto done;
> + }
> +
> + if (addr_len <= sizeof(*sa)) {
> + 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:
> + release_sock(sk);
> + return err;
> +}
> +
> static int iso_sock_bind(struct socket *sock, struct sockaddr *addr,
> int addr_len)
> {
> @@ -826,6 +860,13 @@ static int iso_sock_bind(struct socket *sock, struct sockaddr *addr,
> addr->sa_family != AF_BLUETOOTH)
> return -EINVAL;
>
> + /* 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))
> + return iso_sock_bind_pa_sk(sk, sa, addr_len);
> +
> lock_sock(sk);

If there's no reason not to, could we do instead

lock_sock(sk);

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;
}

so that we don't race between branching on sk->sk_state and then taking
the lock. iso_sock_bind_pa_sk wouldn't also need to do locking then.

>
> if (sk->sk_state != BT_OPEN) {

--
Pauli Virtanen

2023-10-16 16:49:28

by bluez.test.bot

[permalink] [raw]
Subject: RE: Bluetooth: ISO: Allow binding a PA sync socket

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

---Test result---

Test Summary:
CheckPatch PASS 0.72 seconds
GitLint PASS 0.34 seconds
SubjectPrefix PASS 0.12 seconds
BuildKernel PASS 34.15 seconds
CheckAllWarning PASS 37.29 seconds
CheckSparse PASS 43.06 seconds
CheckSmatch PASS 118.74 seconds
BuildKernel32 PASS 32.85 seconds
TestRunnerSetup PASS 514.29 seconds
TestRunner_l2cap-tester PASS 29.83 seconds
TestRunner_iso-tester PASS 52.79 seconds
TestRunner_bnep-tester PASS 9.81 seconds
TestRunner_mgmt-tester PASS 212.32 seconds
TestRunner_rfcomm-tester PASS 15.15 seconds
TestRunner_sco-tester PASS 18.70 seconds
TestRunner_ioctl-tester PASS 16.92 seconds
TestRunner_mesh-tester PASS 12.56 seconds
TestRunner_smp-tester PASS 13.44 seconds
TestRunner_userchan-tester PASS 10.31 seconds
IncrementalBuild PASS 30.85 seconds



---
Regards,
Linux Bluetooth